I/O Specification

The DCPU does not have built-in I/O hardware, but 0x10code provides standard peripherals for interacting with users.

Display

The display is that weird little grey box you see to the right of your code. How do you write stuff to it?

In a nutshell, 0x10code implements a standard LEM1802 display. In order to write to the display, first map the display to an appropriate location in memory, then write to that memory location.

When you write to one of these cells, you do it in the following bit format: HRGB HRGB B CCCCCCC where the first set of HRGB is the color of the text, the next HRGB is the color of the background (with H being 'highlight', making the colors brighter), B is whether or not to blink the cell, and C is the ASCII character value.

The color of the border of the display may also be set by calling a hardware interrupt. The interrupt key is SET_BORDER_COLOR, which is the number 3 on the LEM1802. The interrupt value in the same HRGB color format as cells. Example to set the border to red: SET A, 3; SET B, 1; HWI <address of display>

Fonts

You can even set the font used when writing to the display. This could come in handy for making game sprites, tiles, interfaces, etc.

The pixels for a character are stored in two words, <base> + (v * 2), and <base> + (v * 2) + 1, where v is the character's ASCII value and <base> is the location in memory where the font is mapped. These two words store the pixels in the format aaaaaaaabbbbbbbb ccccccccdddddddd, where a is the leftmost column, b is the next, c is the third, and d is the rightmost, and each bit defines whether or not a pixel is visible. The columns are stored going from top-to-bottom.

Input

You can also get keyboard input. The system may seem confusing at first, but once you get the hang of it, you will be able to make some sweet games, or maybe a text editor.

The keyboard is a generic keyboard and is largely interrupt-driven.

The future

We will certainly be adding more I/O as Notch announces it, or as we figure it out. For instance, disk storage will be here shortly. Also, by the time the real game comes out, we will know how to control the systems of your ship (weapons, engines, communication, etc.). Until then, work with what you have, and show us something awesome!

DCPU16 Quick Reference

Basic Opcodes

  • SET a, b sets a to b
  • ADD a, b sets a to a+b, sets O to 0x0001 if there's an overflow, 0x0 otherwise
  • SUB a, b sets a to a-b, sets O to 0xffff if there's an underflow, 0x0 otherwise
  • MUL a, b sets a to a*b, sets O to ((a*b)>>16)&0xffff
  • DIV a, b sets a to a/b, sets O to ((a<<16)/b)&0xffff. if b==0, sets a and O to 0 instead.
  • MOD a, b sets a to a%b. if b==0, sets a to 0 instead.
  • SHL a, b sets a to a<>b)&0xffff
  • SHR a, b sets a to a>>b, sets O to ((a<<16)>>b)&0xffff
  • AND a, b sets a to a&b
  • BOR a, b sets a to a|b
  • XOR a, b sets a to a^b
  • IFE a, b performs next instruction only if a==b
  • IFN a, b performs next instruction only if a!=b
  • IFG a, b performs next instruction only if a>b
  • IFB a, b performs next instruction only if (a&b)!=0

Non-basic Opcodes

  • JSR a pushes the address of the next instruction to the stack, then sets PC to a
  • BRK stops execution (non-standard)

Registers

  • A, B, C, X, Y, Z, I, J

Other Values

  • POP / [SP++]
  • PEEK / [SP]
  • PUSH / [--SP]
  • SP, PC, O

© Matt Bell (mappum) 2012 - DCPU16 code - Site code - Report bugs