vgargb524.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #include "u.h"
  2. #include "../port/lib.h"
  3. #include "mem.h"
  4. #include "dat.h"
  5. #include "fns.h"
  6. #include "io.h"
  7. #include "../port/error.h"
  8. #define Image IMAGE
  9. #include <draw.h>
  10. #include <memdraw.h>
  11. #include <cursor.h>
  12. #include "screen.h"
  13. /*
  14. * IBM RGB524.
  15. * 170/220MHz High Performance Palette DAC.
  16. *
  17. * Assumes hooked up to an S3 Vision96[48].
  18. */
  19. enum {
  20. IndexLo = 0x00,
  21. IndexHi = 0x01,
  22. Data = 0x02,
  23. IndexCtl = 0x03,
  24. };
  25. enum { /* index registers */
  26. CursorCtl = 0x30,
  27. CursorXLo = 0x31,
  28. CursorXHi = 0x32,
  29. CursorYLo = 0x33,
  30. CursorYHi = 0x34,
  31. CursorHotX = 0x35,
  32. CursorHotY = 0x36,
  33. CursorR1 = 0x40,
  34. CursorG1 = 0x41,
  35. CursorB1 = 0x42,
  36. CursorR2 = 0x43,
  37. CursorG2 = 0x44,
  38. CursorB2 = 0x45,
  39. CursorR3 = 0x46,
  40. CursorG3 = 0x47,
  41. CursorB3 = 0x48,
  42. CursorArray = 0x100,
  43. };
  44. /*
  45. * Lower 2-bits of indirect DAC register
  46. * addressing.
  47. */
  48. static ushort dacxreg[4] = {
  49. PaddrW, Pdata, Pixmask, PaddrR
  50. };
  51. static uchar
  52. rgb524setrs2(void)
  53. {
  54. uchar rs2;
  55. rs2 = vgaxi(Crtx, 0x55);
  56. vgaxo(Crtx, 0x55, (rs2 & 0xFC)|0x01);
  57. return rs2;
  58. }
  59. static void
  60. rgb524xo(int index, uchar data)
  61. {
  62. vgao(dacxreg[IndexLo], index & 0xFF);
  63. vgao(dacxreg[IndexHi], (index>>8) & 0xFF);
  64. vgao(dacxreg[Data], data);
  65. }
  66. static void
  67. rgb524disable(VGAscr*)
  68. {
  69. uchar rs2;
  70. rs2 = rgb524setrs2();
  71. rgb524xo(CursorCtl, 0x00);
  72. vgaxo(Crtx, 0x55, rs2);
  73. }
  74. static void
  75. rgb524enable(VGAscr*)
  76. {
  77. uchar rs2;
  78. rs2 = rgb524setrs2();
  79. /*
  80. * Make sure cursor is off by initialising the cursor
  81. * control to defaults.
  82. */
  83. rgb524xo(CursorCtl, 0x00);
  84. /*
  85. * Cursor colour 1 (white),
  86. * cursor colour 2 (black).
  87. */
  88. rgb524xo(CursorR1, Pwhite); rgb524xo(CursorG1, Pwhite); rgb524xo(CursorB1, Pwhite);
  89. rgb524xo(CursorR2, Pblack); rgb524xo(CursorG2, Pblack); rgb524xo(CursorB2, Pblack);
  90. /*
  91. * Enable the cursor, 32x32, mode 2.
  92. */
  93. rgb524xo(CursorCtl, 0x23);
  94. vgaxo(Crtx, 0x55, rs2);
  95. }
  96. static void
  97. rgb524load(VGAscr*, Cursor* curs)
  98. {
  99. uchar p, p0, p1, rs2;
  100. int x, y;
  101. rs2 = rgb524setrs2();
  102. /*
  103. * Make sure cursor is off by initialising the cursor
  104. * control to defaults.
  105. */
  106. rgb524xo(CursorCtl, 0x00);
  107. /*
  108. * Set auto-increment mode for index-register addressing
  109. * and initialise the cursor array index.
  110. */
  111. vgao(dacxreg[IndexCtl], 0x01);
  112. vgao(dacxreg[IndexLo], CursorArray & 0xFF);
  113. vgao(dacxreg[IndexHi], (CursorArray>>8) & 0xFF);
  114. /*
  115. * Initialise the 32x32 cursor RAM array. There are 2 planes,
  116. * p0 and p1. Data is written 4 pixels per byte, with p1 the
  117. * MS bit of each pixel.
  118. * The cursor is set in X-Windows mode which gives the following
  119. * truth table:
  120. * p1 p0 colour
  121. * 0 0 underlying pixel colour
  122. * 0 1 underlying pixel colour
  123. * 1 0 cursor colour 1
  124. * 1 1 cursor colour 2
  125. * Put the cursor into the top-left of the 32x32 array.
  126. */
  127. for(y = 0; y < 32; y++){
  128. for(x = 0; x < 32/8; x++){
  129. if(x < 16/8 && y < 16){
  130. p0 = curs->clr[x+y*2];
  131. p1 = curs->set[x+y*2];
  132. p = 0x00;
  133. if(p1 & 0x80)
  134. p |= 0xC0;
  135. else if(p0 & 0x80)
  136. p |= 0x80;
  137. if(p1 & 0x40)
  138. p |= 0x30;
  139. else if(p0 & 0x40)
  140. p |= 0x20;
  141. if(p1 & 0x20)
  142. p |= 0x0C;
  143. else if(p0 & 0x20)
  144. p |= 0x08;
  145. if(p1 & 0x10)
  146. p |= 0x03;
  147. else if(p0 & 0x10)
  148. p |= 0x02;
  149. vgao(dacxreg[Data], p);
  150. p = 0x00;
  151. if(p1 & 0x08)
  152. p |= 0xC0;
  153. else if(p0 & 0x08)
  154. p |= 0x80;
  155. if(p1 & 0x04)
  156. p |= 0x30;
  157. else if(p0 & 0x04)
  158. p |= 0x20;
  159. if(p1 & 0x02)
  160. p |= 0x0C;
  161. else if(p0 & 0x02)
  162. p |= 0x08;
  163. if(p1 & 0x01)
  164. p |= 0x03;
  165. else if(p0 & 0x01)
  166. p |= 0x02;
  167. vgao(dacxreg[Data], p);
  168. }
  169. else{
  170. vgao(dacxreg[Data], 0x00);
  171. vgao(dacxreg[Data], 0x00);
  172. }
  173. }
  174. }
  175. /*
  176. * Initialise the cursor hotpoint,
  177. * enable the cursor and restore state.
  178. */
  179. rgb524xo(CursorHotX, -curs->offset.x);
  180. rgb524xo(CursorHotY, -curs->offset.y);
  181. rgb524xo(CursorCtl, 0x23);
  182. vgaxo(Crtx, 0x55, rs2);
  183. }
  184. static int
  185. rgb524move(VGAscr*, Point p)
  186. {
  187. uchar rs2;
  188. rs2 = rgb524setrs2();
  189. rgb524xo(CursorXLo, p.x & 0xFF);
  190. rgb524xo(CursorXHi, (p.x>>8) & 0x0F);
  191. rgb524xo(CursorYLo, p.y & 0xFF);
  192. rgb524xo(CursorYHi, (p.y>>8) & 0x0F);
  193. vgaxo(Crtx, 0x55, rs2);
  194. return 0;
  195. }
  196. VGAcur vgargb524cur = {
  197. "rgb524hwgc",
  198. rgb524enable,
  199. rgb524disable,
  200. rgb524load,
  201. rgb524move,
  202. };