vgatvp3020.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. * TVP3020 Viewpoint Video Interface Pallette.
  14. * Assumes hooked up to an S3 86C928.
  15. */
  16. enum {
  17. Index = 0x06, /* Index register */
  18. Data = 0x07, /* Data register */
  19. };
  20. /*
  21. * Lower 2-bits of indirect DAC register
  22. * addressing.
  23. */
  24. static ushort dacxreg[4] = {
  25. PaddrW, Pdata, Pixmask, PaddrR
  26. };
  27. static uchar
  28. tvp3020io(uchar reg, uchar data)
  29. {
  30. uchar crt55;
  31. crt55 = vgaxi(Crtx, 0x55) & 0xFC;
  32. vgaxo(Crtx, 0x55, crt55|((reg>>2) & 0x03));
  33. vgao(dacxreg[reg & 0x03], data);
  34. return crt55;
  35. }
  36. static void
  37. tvp3020xo(uchar index, uchar data)
  38. {
  39. uchar crt55;
  40. crt55 = tvp3020io(Index, index);
  41. vgao(dacxreg[Data & 0x03], data);
  42. vgaxo(Crtx, 0x55, crt55);
  43. }
  44. static void
  45. tvp3020disable(VGAscr*)
  46. {
  47. uchar r;
  48. /*
  49. * Disable
  50. * cursor;
  51. * cursor control enable for Bt485 DAC (!);
  52. * the hardware cursor external operation mode.
  53. */
  54. tvp3020xo(0x06, 0x10); /* Cursor Control Register */
  55. r = vgaxi(Crtx, 0x45) & ~0x20;
  56. vgaxo(Crtx, 0x45, r);
  57. r = vgaxi(Crtx, 0x55) & ~0x20;
  58. vgaxo(Crtx, 0x55, r);
  59. }
  60. static void
  61. tvp3020enable(VGAscr*)
  62. {
  63. uchar r;
  64. /*
  65. * Make sure cursor is off by initialising the cursor
  66. * control to defaults + X-Windows cursor mode.
  67. */
  68. tvp3020xo(0x06, 0x10); /* Cursor Control Register */
  69. /*
  70. * Overscan colour,
  71. * cursor colour 1 (white),
  72. * cursor colour 2 (black).
  73. */
  74. tvp3020xo(0x20, Pwhite); tvp3020xo(0x21, Pwhite); tvp3020xo(0x22, Pwhite);
  75. tvp3020xo(0x23, Pwhite); tvp3020xo(0x24, Pwhite); tvp3020xo(0x25, Pwhite);
  76. tvp3020xo(0x26, Pblack); tvp3020xo(0x27, Pblack); tvp3020xo(0x28, Pblack);
  77. /*
  78. * Finally, enable
  79. * the hardware cursor external operation mode;
  80. * cursor control enable for Bt485 DAC (!).
  81. */
  82. r = vgaxi(Crtx, 0x55)|0x20;
  83. vgaxo(Crtx, 0x55, r);
  84. r = vgaxi(Crtx, 0x45)|0x20;
  85. vgaxo(Crtx, 0x45, r);
  86. }
  87. static void
  88. tvp3020load(VGAscr*, Cursor* curs)
  89. {
  90. uchar p, p0, p1;
  91. int x, y;
  92. /*
  93. * Make sure cursor is off by initialising the cursor
  94. * control to defaults + X-Windows cursor mode.
  95. */
  96. tvp3020xo(0x06, 0x10); /* Cursor Control Register */
  97. /*
  98. * Initialise the cursor RAM LS and MS address
  99. * (LS must be first).
  100. */
  101. tvp3020xo(0x08, 0x00); /* Cursor RAM LS Address */
  102. tvp3020xo(0x09, 0x00); /* Cursor RAM MS Address */
  103. /*
  104. * Initialise the 64x64 cursor RAM array. There are 2 planes,
  105. * p0 and p1. Data is written 4 pixels per byte, with p1 the
  106. * MS bit of each pixel.
  107. * The cursor is set in X-Windows mode which gives the following
  108. * truth table:
  109. * p1 p0 colour
  110. * 0 0 underlying pixel colour
  111. * 0 1 underlying pixel colour
  112. * 1 0 cursor colour 1
  113. * 1 1 cursor colour 2
  114. * Put the cursor into the top-left of the 64x64 array.
  115. */
  116. for(y = 0; y < 64; y++){
  117. for(x = 0; x < 64/8; x++){
  118. if(x < 16/8 && y < 16){
  119. p0 = curs->clr[x+y*2];
  120. p1 = curs->set[x+y*2];
  121. p = 0x00;
  122. if(p1 & 0x10)
  123. p |= 0x03;
  124. else if(p0 & 0x10)
  125. p |= 0x02;
  126. if(p1 & 0x20)
  127. p |= 0x0C;
  128. else if(p0 & 0x20)
  129. p |= 0x08;
  130. if(p1 & 0x40)
  131. p |= 0x30;
  132. else if(p0 & 0x40)
  133. p |= 0x20;
  134. if(p1 & 0x80)
  135. p |= 0xC0;
  136. else if(p0 & 0x80)
  137. p |= 0x80;
  138. tvp3020xo(0x0A, p); /* Cursor RAM Data */
  139. p = 0x00;
  140. if(p1 & 0x01)
  141. p |= 0x03;
  142. else if(p0 & 0x01)
  143. p |= 0x02;
  144. if(p1 & 0x02)
  145. p |= 0x0C;
  146. else if(p0 & 0x02)
  147. p |= 0x08;
  148. if(p1 & 0x04)
  149. p |= 0x30;
  150. else if(p0 & 0x04)
  151. p |= 0x20;
  152. if(p1 & 0x08)
  153. p |= 0xC0;
  154. else if(p0 & 0x08)
  155. p |= 0x80;
  156. tvp3020xo(0x0A, p); /* Cursor RAM Data */
  157. }
  158. else{
  159. tvp3020xo(0x0A, 0x00); /* Cursor RAM Data */
  160. tvp3020xo(0x0A, 0x00);
  161. }
  162. }
  163. }
  164. /*
  165. * Initialise the cursor hotpoint
  166. * and enable the cursor.
  167. */
  168. tvp3020xo(0x04, -curs->offset.x); /* Sprite Origin X */
  169. tvp3020xo(0x05, -curs->offset.y); /* Sprite Origin Y */
  170. tvp3020xo(0x06, 0x40|0x10); /* Cursor Control Register */
  171. }
  172. static int
  173. tvp3020move(VGAscr*, Point p)
  174. {
  175. tvp3020xo(0x00, p.x & 0xFF); /* Cursor Position X LSB */
  176. tvp3020xo(0x01, (p.x>>8) & 0x0F); /* Cursor Position X MSB */
  177. tvp3020xo(0x02, p.y & 0xFF); /* Cursor Position Y LSB */
  178. tvp3020xo(0x03, (p.y>>8) & 0x0F); /* Cursor Position Y MSB */
  179. return 0;
  180. }
  181. VGAcur vgatvp3020cur = {
  182. "tvp3020hwgc",
  183. tvp3020enable,
  184. tvp3020disable,
  185. tvp3020load,
  186. tvp3020move,
  187. };