ZodiacMentor

KAPE GPU commands

Apr 6th, 2022
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.55 KB | None | 0 0
  1. CMD FIFO - implemented in hardware as an abstraction layer between the CPU bus and the KAPE GPU.
  2.  
  3. The CPU sends commands through the FIFO and sees it as a normal IO in address-space, and sending bytes to this address
  4. is then read by the GPU from the FIFO and ingested here. After a reset event - either hardware or software - the GPU needs around 100 ms
  5. before it can start accepting commands. This is about 6-7 frames (at 61,7 fps).
  6.  
  7. The command list:
  8. 0x00 Send single character as textmode. 1 parameter. The next character is interpreted as a text character, and respects
  9. some special characters like enter and bs
  10. - 1 byte The character to draw on cursor position. The color will be set as the current draw color bg/fg
  11. 0x01 Set draw color for text. 1 parameter. The next character is interpreted as the draw color.
  12. - 1 byte 0bFFFFBBBB
  13. - F The 4-bit foreground color
  14. - B The 4-bit background color
  15. 0x02 Enter Terminal mode. Terminal mode is 32x24 textmode. Future communications are interpreted as characters to be output
  16. to the char location. Char location is incremented. Upon entering, the foreground and background color are reset to
  17. Light Gray, and cursor position is set to 0,0. Cursor is shown and blinking. Screen is cleared to space. While in terminal
  18. mode, sending an ESC(27 or 0x1b) accepts a terminal command.
  19. See Terminal Commands for terminal commands.
  20.  
  21. 0x10 Set single index to character or pattern table at coordinates. 3 parameters.
  22. - 1 byte 0b***XXXXX
  23. - X The X position, from 0 - 31 (5 bits)
  24. - 1 byte 0b***YYYYY
  25. - Y The Y position, from 0 - 23 (5 bits, clamped to 23)
  26. - 1 byte Index to set at position X,Y
  27.  
  28. 0x20 Set sprite data. 4 parameters
  29. - 1 byte 0bA*YYYXXX
  30. - A Active (processed and active in drawing loops, not necessary drawn)
  31. - Y 3 bit value for the Hotspot Y (pixel considered as the origin, ie. offset for drawing algorithms)
  32. - X 3 bit value for the Hotspot X
  33. - 1 byte X position
  34. - 1 byte Y position (wrapped around from 192)
  35. - 1 byte Tile index - uses the same tilemap as the background rendering
  36. 0x21 Set sprite active. 1 parameter
  37. - 1 byte Sprite index to activate
  38. 0x22 Set sprite not active. 1 parameter
  39. - 1 byte Sprite index to deactivate
  40. 0x23 Set sprite draw. 1 parameter
  41. - 1 byte Sprite index to activate
  42. 0x24 Set sprite active. 1 parameter
  43. - 1 byte Sprite index to activate
  44. 0x25 Set sprite tile index. 2 parameters
  45. - 1 byte Sprite index to set the tile index of
  46. - 1 byte Tile index to set to the sprite
  47. 0x26 Set sprite X. 2 parameters
  48. - 1 byte Sprite Index
  49. - 1 byte Sprite X coord
  50. 0x27 Set sprite Y. 2 parameters
  51. - 1 byte Sprite Index
  52. - 1 byte Sprite Y coord
  53. 0x30 Set sprite alpha color. 2 parameters
  54. - 1 byte Sprite Index
  55. - 1 byte 0b****AAAA
  56. - A The Alpha color that's not drawn
  57. 0x31 Set sprite X and Y coords. 3 parameters
  58. - 1 byte Sprite Index
  59. - 1 byte Sprite X coord
  60. - 1 byte Sprite Y coord
  61.  
  62. 0x40 Switch to text mode (draw from chargen table)
  63. 0x41 Switch to graphics mode (draw from pattern table, sprites supported)
  64. 0x42 Switch to combined mode (draw from both, use a bitmask to select which one to use)
  65. 0x43 Switch to lores mode (128x96 pixelbuffer, resides in pattern table, no sprites)
  66.  
  67. 0x4A Clear screen. 1 paramater. Fills either tilemap/text framebuffer or 128x96 bytes of pattern table, depending on the mode.
  68. - 1 byte Byte to set to all memory.
  69.  
  70. 0x4B Flush frame to FB FIFO. No parameters.
  71. In Lores mode, the current framebuffer is sent to the FIFO only with the flush command.
  72. This is due to the fact that the CMDQ is only 2K in size, and thus to send a full frame to the FIFO you need a bit over 3 frames
  73. to do it. This way, you can use the internal buffer as a double-buffer, and only update the screen when done. Prevents screen tearing
  74. and provides possibility to update frames smoothly at ~25 FPS.
  75.  
  76. 0x4C Draw a pixel. 3 parameters
  77. - 1 byte X position. Moduloed w/ SCR_LORES_WIDTH (128)
  78. - 1 byte Y position. Moduloed w/ SCR_LORES_HEIGHT (96)
  79. - 1 byte Color. Anded with a 0xf to prevent overflow.
  80.  
  81. 0x4D Draw a line. 5 paramaters
  82. - 1 byte X1 position. Moduloed w/ SCR_LORES_WIDTH (128)
  83. - 1 byte Y1 position. Moduloed w/ SCR_LORES_HEIGHT (96)
  84. - 1 byte X2 position. Moduloed w/ SCR_LORES_WIDTH (128)
  85. - 1 byte Y2 position. Moduloed w/ SCR_LORES_HEIGHT (96)
  86. - 1 byte Color. Anded with a 0xf to prevent overflow.
  87.  
  88. 0x50 Set combined mode bitmask for coordinate. 2 parameters.
  89. - 1 byte 0bB**XXXXX
  90. - B The bit the bitmask will be set to. 1 draw from pattern table (graphics). 0 draw from chargen (text)
  91. - X The X position, from 0 - 31 (5 bits)
  92. - 1 byte 0b***YYYYY
  93. - Y The Y position, from 0 - 23 (5 bits but clamped to 23)
  94.  
  95. 0x80 Send pattern table data for single element. 1 parameter + 32 bytes of data (4 bits per pixel)
  96. - 1 byte The pattern table index to insert the data to
  97. - 32 bytes The pattern table data arranged as a sequential array of packed pixels, where one byte holds two pixels.
  98.  
  99. 0xfe Direct Framebuffer mode. Intended for Lores mode for piping data directly to the framebuffer. NB: GPU soft reset
  100. can't be activated in this mode! Reset signal needs to be manually sent to GPU through the ~RESET line.
  101.  
  102. 0xff Reset GPU. Once received, uses watchdog to simulate a hardware reset. Resets device.
  103. In case the last command has not finished, to properly FORCE a reset from a stuck state, we need to send
  104. as many + 1 reset commands as the longest fifo command queue, which is the send pattern table data at 33 bytes.
  105. So to do a FORCE RESET, send 34 reset commands to the CMD Fifo
  106.  
  107.  
  108. Terminal commands. In Terminal mode, send ESC and command with parameters. Terminal mode accepts some control characters, like
  109.  
  110. 0x0A LF Line Feed. Goes row down, scrolls if too low.
  111. 0x0D CR Carriage Return. Cursor moved horizontally to Column 0
  112. 0x1B ESC Escape. The next character describes a command. See the following list.
  113. 0x08 BS Backspace. Delete character on the left (wrap around to higher row) and replace with space
  114.  
  115. 0x01 Set draw color for text. 1 parameter. Binary version. High nibble is foreground color, low nibble is background color
  116. - 1 byte 0bFFFFBBBB
  117. - F Foreground color nibble
  118. - B Background color nibble
  119.  
  120. 0x63 'c' Set draw color for text. 2 parameter. The next 2 chars '0-9'|'A-F' are interpreted as foreground and background colors
  121. - 1 byte Foreground color '0-9'|'A-F'
  122. - 1 byte Background color '0-9'|'A-F'
  123.  
  124. 0x02 Set draw decoration. 1 parameter. Next character decides Bold, Italics, Underline font, Blinking
  125. - 1 byte 0b000SEUIB
  126. - B Bold
  127. - I Italics
  128. - U Underline
  129. - E Effect (Blinking)
  130. - S Strike-through
  131.  
  132. 0x03 Set Cursor Position. 2 parameters.
  133. - 1 byte Cursor Column. Mod 32
  134. - 1 byte Cursor Row. Mod 24
  135.  
  136. 0x04 Set Cursor Column. 1 parameter
  137. - 1 byte Cursor Column. Mod 32
  138.  
  139. 0x05 Set Cursor Row. 1 paramater
  140. - 1 byte Cursor Row. Mod 24
  141.  
  142. 0xff Exit out of Terminal Mode. The next character sent is interpreted as a normal GPU command.
  143.  
  144.  
Advertisement
Add Comment
Please, Sign In to add comment