Proposal for simple I/O

Each device communicates through two words, one command and one data word:

[deviceaddr] command

[deviceaddr+1] data

All connected devices are placed sequentially in some location in memory,

for example if the IO space is 0xd000:

[0xd000] disk drive 0 command

[0xd001] disk drive 0 data

[0xd002] radar sensor 0 command

[0xd003] radar sensor 0 data

[0xd004] laser gun 0 command

[0xd005] laser gun 0 data

[0xd006] laser gun 1 command

[0xd007] laser gun 1 data

On computer startup, or on device attachment, all devices MUST place an unique

device identifier in the command word and possibly some other identifying

information in the data word. This is so the computer software can scan the I/O

address space and find all connected devices.

Communication SHOULD follow a request-respond model. This means that any device

communication is initiated from the computer, which then the device responds

to. The computer sends a request by optionally placing data in the data word,

then placing the desired command in the command word. Note that this order of

operations is important, as the write to the command word triggers the device

to respond.

When a device is done with a request, it MUST write a response code into its

command register to signal that the request is processed. It might optionally

also place additional info in the data word.

To simplify polling, all commands sent from the computer to the device MUST

have their Most Significant Bit set to 0. Likewise, any response from the

device MUST have their MSB set to 1. This means that the command word is

guaranteed to be changed when the device signals it's finished, and the

computer can simply poll the command word to see when it becomes different

from the written command.

In addition to transferring data through the data register, a device might use

Direct Memory Access. This means the device reads and writes directly to the

computer's memory, allowing transfer of large amounts of data at once. The

standard way of doing this should be to place the address of the memory

location to be accessed through DMA into the data word. The size of the

accessed memory is left unspecified, and instead depends on the device and

command used.

DCPU example (reading a sector from the main disk drive):

SET [0xd001], 0x4000 ; set the DMA address to 0x4000

SET [0xd000], 0x1000 ; upper 4 bits = 0001 - READ SECTOR

; lower 12 bits = sector number 0

:loop

IFE [0xd000], 0x1000 ; loop until command has finished

SET PC, loop