-
Notifications
You must be signed in to change notification settings - Fork 9
Commands
The graphics processor firmware uses two I/O ports for commands and data.
- Port 40H is used to send commands.
- Port 41H is used to send data bytes.
The following commands are implemented in the current firmware.
00H - Set Video Mode
Resets the video card and sets mode 1 (320x240). No additional data is required.
XOR A
OUT (40H),A
06H - Set tiles bitmap pointer
Sets the logical address of the bitmap area used to draw tiles on screen. Tile index 0 is located at that memory address, tile index 1 is located 64 bytes after, etc. each tile is 64 bytes.
The low order byte and the high address byte of the 16 bit address needs to be sent to the data port. The address is the logical offset from the start of the tile bitmap area.
LD A,06H
OUT (40H),A
LD A,00H ; Low order byte
OUT (41H),A
LD A,00H ; High order byte
OUT (41H),A
07H - Set sprites bitmap pointer
Sets the logical address of the bitmap area used to draw sprites on screen. Sprite tile index 0 is located at that memory address, tile index 1 is located 64 bytes after, etc. each tile is 64 bytes.
The low order byte and the high address byte of the 16 bit address needs to be sent to the data port. The address is the logical offset from the start of the tile bitmap area.
LD A,07H
OUT (40H),A
LD A,00H ; Low order byte
OUT (41H),A
LD A,00H ; High order byte
OUT (41H),A
0CH - Write to sprites data area
Starts writing to the sprites data area. Each sprite is composed of 4 bytes that defines the x and y position, the tile index to draw, the size and other flags.
The first byte sent to the data port is the sprite index to write, with 00H as the first sprite and 1FH as the last (up to 32 sprites can be displayed on screen). Subsequent bytes are the sprite definition bytes.
LD A,0CH
OUT (40H),A
LD A,00H ; First sprite index
OUT (41H),A
LD A,00H ; X
OUT (41H),A
LD A,00H ; Y
OUT (41H),A
LD A,00H ; Tile index
OUT (41H),A
LD A,00H ; Flags
OUT (41H),A
The write pointer automatically increments with each write so it is not necessary to send a new command to update all sprites. The pointer wraps to the first index position after the last byte of the last sprite is written.
0DH - Write to tiles map area
Starts writing to the on screen tile map area.
The first two bytes sent to the data port are the low order and high order bytes of a 16 bit address offset from the beginning of the tile map area, with 0000H corresponding to the top-left tile and 04AFH corresponding to the bottom-right tile. Subsequent bytes are the tile indexes to display on screen.
LD A,0DH
OUT (40H),A
LD A,00H ; Low order byte
OUT (41H),A
LD A,00H ; High order byte
OUT (41H),A
LD A,01H ; Tile indexes
OUT (41H),A
LD A,02H
OUT (41H),A
The write pointer automtically increments after each write and wraps to the beginning after the last tile index is written.
0EH - Write to tiles bitmap area
Starts writing to the memory area that holds the bitmap data of each tile or sprite. Bitmaps are 8x8 bytes so each tile takes 64 bytes of memory. The bitmap memory are can hold up to 480 tiles.
The first two bytes sent to the data port are the low order and high order bytes of a 16 bit address offset from the beginning of the tiles bitmap area, with 0000H corresponding to tile index 0, 0040H to tile index 1, etc.
LD A,0EH
OUT (40H),A
LD A,00H ; Low order byte
OUT (41H),A
LD A,00H ; High order byte
OUT (41H),A
LD A,C0H ; RGB colors
OUT (41H),A
LD A,30H
OUT (41H),A
The write pointer automticallt increments after each write and wraps to the beginning after the last pixel of the last bitmap is written.
The actual index pointers can be set with commands 06H for tiles and 07H for sprites.
Port 43H is used to synchronize the program execution to the display frame frequency. Writing to this I/O port (any value) causes the WAIT line of the Z80 processor to be pulled low to halt the instruction execution until the end of the current frame, then it is released and the program execution is resumed.
OUT (43H),A