vgargb524.c 4.1 KB

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