Subversion Repositories pentevo

Rev

Blame | Last modification | View Log | Download | RSS feed | ?url?

  1. #ifndef ZX_H
  2. #define ZX_H
  3.  
  4. /**
  5.  * @file
  6.  * @brief Interchange with FPGA registers (ZX ports) via SPI.
  7.  * @author http://www.nedopc.com
  8.  *
  9.  * Interchange with ZX ports:
  10.  * - keyboard port (nowait);
  11.  * - mouse port (nowait);
  12.  * - kempstone joystick (nowait);
  13.  * - gluk clock (wait).
  14.  *
  15.  * Configure internal FPGA registers (set modes):
  16.  * - vga/tv mode;
  17.  * - reset CPU.
  18.  */
  19.  
  20. // key code is 7 bits, 8th bit is press/release (1=press,0=release)
  21. //
  22. // ACHTUNG!!!! DO NOT CHANGE THESE DEFINES, OTHERWISE MUCH OF CODE WILL BREAK!!!!
  23. //
  24. #define PRESS_BIT  7
  25. #define PRESS_MASK 128
  26. #define KEY_MASK   127
  27.  
  28.  
  29. /** ZX keyboard data. */
  30. #define SPI_KBD_DAT   0x10
  31. /** ZX keyboard stop bit. */
  32. #define SPI_KBD_STB   0x11
  33.  
  34. /** ZX mouse X coordinate register. */
  35. #define SPI_MOUSE_X   0x20
  36. /** ZX mouse Y coordinate register. */
  37. #define SPI_MOUSE_Y   0x21
  38. /** ZX mouse Y coordinate register. */
  39. #define SPI_MOUSE_BTN 0x22
  40.  
  41. /** Kempston joystick register. */
  42. #define SPI_KEMPSTON_JOYSTICK 0x23
  43.  
  44. /** ZX reset register. */
  45. #define SPI_RST_REG   0x30
  46.  
  47. /** ZX configuration register. */
  48. #define SPI_CONFIG_REG   0x80
  49. /** ZX NMI bit flag of configuration register. */
  50. #define SPI_CONFIG_NMI_FLAG 0x02
  51. /** ZX TURBO bit flag of configuration register. */
  52. #define SPI_CONFIG_TURBO_FLAG 0x08
  53. /** ZX NOTURBO bit flag of configuration register. */
  54. #define SPI_CONFIG_NOTURBO_FLAG 0x10
  55. /** ZX $FE.D6 (tape in) bit flag of configuration register. */
  56. #define SPI_TAPE_FLAG 0x04
  57.  
  58. /** ZX all data for wait registers. */
  59. #define SPI_WAIT_DATA  0x40
  60. /** ZX Gluk address register. */
  61. #define SPI_GLUK_ADDR  0x41
  62. /** ZX Kondratiev's rs232 address register. */
  63. #define SPI_RS232_ADDR 0x42
  64.  
  65. /** Send/recv data for spi registers. */
  66. UBYTE zx_spi_send(UBYTE addr, UBYTE data, UBYTE mask);
  67.  
  68.  
  69. /** Pause between (CS|SS) and not(CS|SS). */
  70. #define SHIFT_PAUSE 8
  71. /** Pause between (CS|SS) and not(CS|SS) counter. */
  72. extern volatile UBYTE shift_pause;
  73.  
  74. // real keys bitmap. send order: LSbit first, from [4] to [0]
  75. // [5]..[9] - received data
  76. // [10] - end scan flag
  77. extern UBYTE zx_realkbd[11];
  78.  
  79. /*struct zx {
  80.         UBYTE counters[40];
  81.         UBYTE map[5]; // send order: LSbit first, from [4] to [0]
  82.         UBYTE reset_type;
  83. };*/
  84.  
  85. /** PS/2 keyboard CTRL key status. */
  86. #define KB_CTRL_MASK   0x01
  87. /** PS/2 keyboard ALT key status. */
  88. #define KB_ALT_MASK    0x02
  89. /** PS/2 keyboard LEFT SHIFT key status. */
  90. #define KB_LSHIFT_MASK 0x04
  91. /** PS/2 keyboard RIGHT SHIFT key status. */
  92. #define KB_RSHIFT_MASK 0x08
  93. /** PS/2 keyboard F12 key status. */
  94. #define KB_F12_MASK    0x10
  95. /** PS/2 keyboard CTRL,ALT,DEL mapped status (set = mapped all keys). */
  96. #define KB_CTRL_ALT_DEL_MAPPED_MASK 0x80
  97. /** PS/2 keyboard control keys status (for additional functons). */
  98. extern volatile UBYTE kb_status;
  99.  
  100.  
  101. #define ZX_TASK_INIT 0
  102. #define ZX_TASK_WORK 1
  103.  
  104. /**
  105.  * Interchange via SPI.
  106.  * @param operation [in] - operation type.
  107.  */
  108. void zx_task(UBYTE operation);
  109.  
  110. void zx_init(void);
  111.  
  112. void to_zx(UBYTE scancode, UBYTE was_E0, UBYTE was_release);
  113.  
  114. void update_keys(UBYTE zxcode, UBYTE was_release);
  115.  
  116. /** Clear zx keyboard buffers. */
  117. void zx_clr_kb(void);
  118.  
  119.  
  120. void  zx_fifo_put(UBYTE input);
  121. UBYTE zx_fifo_isfull(void);
  122. UBYTE zx_fifo_isempty(void);
  123. UBYTE zx_fifo_get(void);
  124. UBYTE zx_fifo_copy(void);
  125.  
  126. /**
  127.  * ZX mouse button register.
  128.  * Bits description:
  129.  * 7..4 - wheel code (if present) or 1111 if wheel not present;
  130.  * 3    - always 1;
  131.  * 2    - middle button (0, if pressed);
  132.  * 1    - right button (0, if pressed);
  133.  * 0    - left button (0, if pressed).
  134.  */
  135. extern volatile UBYTE zx_mouse_button;
  136.  
  137. /** ZX mouse X coordinate register. */
  138. extern volatile UBYTE zx_mouse_x;
  139.  
  140. /** ZX mouse Y coordinate register. */
  141. extern volatile UBYTE zx_mouse_y;
  142.  
  143. /**
  144.  * Reset ZX mouse registers to default value.
  145.  * @param enable [in] - 0: values like no mouse connected, other: values like mouse connected
  146.  */
  147. void zx_mouse_reset(UBYTE enable);
  148.  
  149. /** Send values of ZX mouse registers to fpga. */
  150. void zx_mouse_task(void);
  151.  
  152.  
  153. /** Gluk clock ZX port out. */
  154. #define ZXW_GLUK_CLOCK  0x01
  155.  
  156. /** Kondratiev's modem ZX port out. */
  157. #define ZXW_KONDR_RS232 0x02
  158.  
  159. /**
  160.  * Work with WAIT ports.
  161.  * @param status [in] - bit 7 - CPU is 0 -write, 1-read wait port
  162.  *                              bits 6..0 is index of port
  163.  */
  164. void zx_wait_task(UBYTE status);
  165.  
  166. /** Switch vga mode on ZX */
  167. void zx_vga_switcher(void);
  168.  
  169. /**
  170.  * Set configuration register on zx.
  171.  * @param flags [in] - bit 0: not used (depend from MODE_VGA on modes_register)
  172.  *                             bit 1: NMI
  173.  */
  174. void zx_set_config(UBYTE flags);
  175.  
  176. #endif
  177.  
  178.