Wired CPU

From GMod Wiki

Jump to: navigation, search
Wire Icon.png Wiremod ToolYarin Kaul Icon ArrowSquare32 left.png Back
Information 16x16.png Function:Programmable CPU
link=User:{{{author}}} Primary fire:Creates a CPU/Updates program
Wrench orange.png Secondary fire:No action
Link break.png Reload:No action
Page white text.png Notes:Coded by Black Phoenix

Brief

A programmable CPU

Instructions

Write Assembler program and use Inputs and Outputs to control it

A CPU chip using the default AMD64 model

Inputs

Outputs

Variables

Useful hints

Connect screen to error output if your contraption doesn't work.
Error codes:
0.0 - No error
2.0 - End of program execution/opcode 0
3.0 - Division by zero
4.0 - Unknown opcode
5.0 - Internal error
6.0 - Stack error
7.0 - Memory fault (Read/write violation)
8.0 - External bus error (usually when non-hispeed device is connected to MemBus or IOBus)
9.0 - Page fault (Write access violation)
10.0 - Port Bus fault
11.0 - ROM Error
12.0 - Page error (wrong page id)
13.0 - General Protection Fault

CPU has internal RAM/ROM, which has following parameters: Size - 64KB/65536 values Range - 0..65535

Devices linked to MemBus are connected starting from address 65536. For example for console screen attached to MemBus it would be: Range 1 - 0..65535 (CPU Code & Data) Range 2 - 65536..67584 (Console screen, hi-speed for it is 2048 bytes in size) Reading any value from neither of these ranges can result in error #7.

Reading from negative addresses (-1,-2,etc) redirects read to ports (mov eax,#-1 will read from port0, -2 from port1, etc)

Protected mode is available. While in protected mode CPU no longer signalizes errors using the "Error" output, corresponding interrupts will be called instead, which allows you to handle errors without stopping code.

There are about 100 opcodes available, some of them can be used to make your programs faster. For example, copying data with mcopy operation is faster than same loop in assembly (mcopy is executed instantly). mcopy instruction has limit of max. 32768 bytes per call.

If you want several CPU's to work together you can create some shared memory for all them by attaching their MemBus to same memory unit. Then using "ORG 65536" put compiler into shared area, declare all variables you want, and then go back using "ORG 0" (ORG 65536 and ORG 0 must be before you actual code, for example in DATA area in ZASM).

Example

Original tutorial ZASM asembly programming tutorial

Documentation of CPU

Documentation of high-speed devices

Go here for more Tutorials Wiremod forum: CPU Tutorials Section

In case you don't feel like writing in assembly there is C compiler which turns your code into ZASM assembly.

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox