Subversion Repositories pentevo

Rev

Rev 672 | Go to most recent revision | Blame | Compare with Previous | 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   0x50
  49. /** ZX NMI bit flag of configuration register. */
  50. #define SPI_CONFIG_NMI_FLAG 0x02
  51. /** ZX $FE.D6 (tape in) bit flag of configuration register. */
  52. #define SPI_TAPE_FLAG 0x04
  53. /** ZX tapeout mode bit flag of configuration register. */
  54. #define SPI_TAPEOUT_MODE_FLAG 0x08
  55.  
  56. /** ZX all data for wait registers. */
  57. #define SPI_WAIT_DATA  0x40
  58. /** ZX Gluk address register. */
  59. #define SPI_GLUK_ADDR  0x41
  60. /** ZX Kondratiev's rs232 address register. */
  61. #define SPI_RS232_ADDR 0x42
  62.  
  63. /** Send/recv data for spi registers. */
  64. UBYTE zx_spi_send(UBYTE addr, UBYTE data, UBYTE mask);
  65.  
  66.  
  67. /** Pause between (CS|SS) and not(CS|SS). */
  68. #define SHIFT_PAUSE 8
  69. /** Pause between (CS|SS) and not(CS|SS) counter. */
  70. extern volatile UBYTE shift_pause;
  71.  
  72. // real keys bitmap. send order: LSbit first, from [4] to [0]
  73. // [5]..[9] - received data
  74. // [10] - end scan flag
  75. extern UBYTE zx_realkbd[11];
  76.  
  77. /*struct zx {
  78.         UBYTE counters[40];
  79.         UBYTE map[5]; // send order: LSbit first, from [4] to [0]
  80.         UBYTE reset_type;
  81. };*/
  82.  
  83. /** PS/2 keyboard LCTRL key status. */
  84. #define KB_LCTRL_MASK   0x01
  85. /** PS/2 keyboard LCTRL key status. */
  86. #define KB_RCTRL_MASK   0x02
  87. /** PS/2 keyboard LALT key status. */
  88. #define KB_LALT_MASK    0x04
  89. /** PS/2 keyboard LALT key status. */
  90. #define KB_RALT_MASK    0x08
  91. /** PS/2 keyboard LEFT SHIFT key status. */
  92. #define KB_LSHIFT_MASK 0x10
  93. /** PS/2 keyboard RIGHT SHIFT key status. */
  94. #define KB_RSHIFT_MASK 0x20
  95. /** PS/2 keyboard F12 key status. */
  96. #define KB_F12_MASK    0x40
  97. /** PS/2 keyboard CTRL,ALT,DEL mapped status (set = mapped all keys). */
  98. //#define KB_CTRL_ALT_DEL_MAPPED_MASK 0x80
  99. /** PS/2 keyboard control keys status (for additional functons). */
  100. extern volatile UBYTE kb_ctrl_status;
  101. /** PS/2 keyboard control keys mapped to zx keyboard (mapped keys not used in additional functions). */
  102. extern volatile UBYTE kb_ctrl_mapped;
  103.  
  104.  
  105. #define ZX_TASK_INIT 0
  106. #define ZX_TASK_WORK 1
  107.  
  108. /**
  109.  * Interchange via SPI.
  110.  * @param operation [in] - operation type.
  111.  */
  112. void zx_task(UBYTE operation);
  113.  
  114. void zx_init(void);
  115.  
  116. void to_zx(UBYTE scancode, UBYTE was_E0, UBYTE was_release);
  117.  
  118. void update_keys(UBYTE zxcode, UBYTE was_release);
  119.  
  120. /** Clear zx keyboard buffers. */
  121. void zx_clr_kb(void);
  122.  
  123.  
  124. void  zx_fifo_put(UBYTE input);
  125. UBYTE zx_fifo_isfull(void);
  126. UBYTE zx_fifo_isempty(void);
  127. UBYTE zx_fifo_get(void);
  128. UBYTE zx_fifo_copy(void);
  129.  
  130. /**
  131.  * ZX mouse button register.
  132.  * Bits description:
  133.  * 7..4 - wheel code (if present) or 1111 if wheel not present;
  134.  * 3    - always 1;
  135.  * 2    - middle button (0, if pressed);
  136.  * 1    - right button (0, if pressed);
  137.  * 0    - left button (0, if pressed).
  138.  */
  139. extern volatile UBYTE zx_mouse_button;
  140.  
  141. /** ZX mouse X coordinate register. */
  142. extern volatile UBYTE zx_mouse_x;
  143.  
  144. /** ZX mouse Y coordinate register. */
  145. extern volatile UBYTE zx_mouse_y;
  146.  
  147. /**
  148.  * Reset ZX mouse registers to default value.
  149.  * @param enable [in] - 0: values like no mouse connected, other: values like mouse connected
  150.  */
  151. void zx_mouse_reset(UBYTE enable);
  152.  
  153. /** Send values of ZX mouse registers to fpga. */
  154. void zx_mouse_task(void);
  155.  
  156.  
  157. /** Gluk clock ZX port out. */
  158. #define ZXW_GLUK_CLOCK  0x01
  159.  
  160. /** Kondratiev's modem ZX port out. */
  161. #define ZXW_KONDR_RS232 0x02
  162.  
  163. /**
  164.  * Work with WAIT ports.
  165.  * @param status [in] - bit 7 - CPU is 0 -write, 1-read wait port
  166.  *                      bits 6..0 is index of port
  167.  */
  168. void zx_wait_task(UBYTE status);
  169.  
  170. /**
  171.  * Switch mode on ZX.
  172.  * @param mode - mode flag
  173.  */
  174. void zx_mode_switcher(UBYTE mode);
  175.  
  176. /**
  177.  * Set configuration register on zx.
  178.  * @param flags [in] - bit 2: SPI_TAPE_FLAG
  179.  *                     bit 5: not used
  180.  *                     bit 6: not used
  181.  *                     bit 7: not used
  182.  */
  183. void zx_set_config(UBYTE flags);
  184.  
  185. #endif
  186.  
  187.