vgatvp3026.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. * TVP3026 Viewpoint Video Interface Pallette.
  15. * Assumes hooked up to an S3 Vision968.
  16. */
  17. enum {
  18. Index = 0x00, /* Index */
  19. Data = 0x0A, /* Data */
  20. CaddrW = 0x04, /* Colour Write Address */
  21. Cdata = 0x05, /* Colour Data */
  22. Cctl = 0x09, /* Direct Cursor Control */
  23. Cram = 0x0B, /* Cursor Ram Data */
  24. Cxlsb = 0x0C, /* Cursor X LSB */
  25. Cxmsb = 0x0D, /* Cursor X MSB */
  26. Cylsb = 0x0E, /* Cursor Y LSB */
  27. Cymsb = 0x0F, /* Cursor Y MSB */
  28. Icctl = 0x06, /* Indirect Cursor Control */
  29. };
  30. /*
  31. * Lower 2-bits of indirect DAC register
  32. * addressing.
  33. */
  34. static ushort dacxreg[4] = {
  35. PaddrW, Pdata, Pixmask, PaddrR
  36. };
  37. static uchar
  38. tvp3026io(uchar reg, uchar data)
  39. {
  40. uchar crt55;
  41. crt55 = vgaxi(Crtx, 0x55) & 0xFC;
  42. vgaxo(Crtx, 0x55, crt55|((reg>>2) & 0x03));
  43. vgao(dacxreg[reg & 0x03], data);
  44. return crt55;
  45. }
  46. static void
  47. tvp3026o(uchar reg, uchar data)
  48. {
  49. uchar crt55;
  50. crt55 = tvp3026io(reg, data);
  51. vgaxo(Crtx, 0x55, crt55);
  52. }
  53. void
  54. tvp3026xo(uchar index, uchar data)
  55. {
  56. uchar crt55;
  57. crt55 = tvp3026io(Index, index);
  58. vgaxo(Crtx, 0x55, crt55|((Data>>2) & 0x03));
  59. vgao(dacxreg[Data & 0x03], data);
  60. vgaxo(Crtx, 0x55, crt55);
  61. }
  62. static void
  63. tvp3026disable(VGAscr*)
  64. {
  65. tvp3026xo(Icctl, 0x90);
  66. tvp3026o(Cctl, 0x00);
  67. }
  68. static void
  69. tvp3026enable(VGAscr*)
  70. {
  71. /*
  72. * Make sure cursor is off and direct control enabled.
  73. */
  74. tvp3026xo(Icctl, 0x90);
  75. tvp3026o(Cctl, 0x00);
  76. /*
  77. * Overscan colour,
  78. * cursor colour 1 (white),
  79. * cursor colour 2, 3 (black).
  80. */
  81. tvp3026o(CaddrW, 0x00);
  82. tvp3026o(Cdata, Pwhite); tvp3026o(Cdata, Pwhite); tvp3026o(Cdata, Pwhite);
  83. tvp3026o(Cdata, Pwhite); tvp3026o(Cdata, Pwhite); tvp3026o(Cdata, Pwhite);
  84. tvp3026o(Cdata, Pblack); tvp3026o(Cdata, Pblack); tvp3026o(Cdata, Pblack);
  85. tvp3026o(Cdata, Pblack); tvp3026o(Cdata, Pblack); tvp3026o(Cdata, Pblack);
  86. /*
  87. * Enable the cursor in 3-colour mode.
  88. */
  89. tvp3026o(Cctl, 0x01);
  90. }
  91. static void
  92. tvp3026load(VGAscr* scr, Cursor* curs)
  93. {
  94. int x, y;
  95. /*
  96. * Make sure cursor is off by initialising the cursor
  97. * control to defaults.
  98. * Write to the indirect control register to make sure
  99. * direct register is enabled and upper 2 bits of cursor
  100. * RAM address are 0.
  101. * The LSBs of the cursor RAM address are in PaddrW.
  102. */
  103. tvp3026xo(Icctl, 0x90);
  104. tvp3026o(Cctl, 0x00);
  105. vgao(PaddrW, 0x00);
  106. /*
  107. * Initialise the 64x64 cursor RAM array. There are 2 planes,
  108. * p0 and p1. Data is written 8 pixels per byte, with p0 in the
  109. * first 512 bytes of the array and p1 in the second.
  110. * The cursor is set in 3-colour mode which gives the following
  111. * truth table:
  112. * p1 p0 colour
  113. * 0 0 transparent
  114. * 0 1 cursor colour 0
  115. * 1 0 cursor colour 1
  116. * 1 1 cursor colour 2
  117. * Put the cursor into the top-left of the 64x64 array.
  118. * The 0,0 cursor point is bottom-right, so positioning will
  119. * have to take that into account.
  120. */
  121. for(y = 0; y < 64; y++){
  122. for(x = 0; x < 64/8; x++){
  123. if(x < 16/8 && y < 16)
  124. tvp3026o(Cram, curs->clr[x+y*2]);
  125. else
  126. tvp3026o(Cram, 0x00);
  127. }
  128. }
  129. for(y = 0; y < 64; y++){
  130. for(x = 0; x < 64/8; x++){
  131. if(x < 16/8 && y < 16)
  132. tvp3026o(Cram, curs->set[x+y*2]);
  133. else
  134. tvp3026o(Cram, 0x00);
  135. }
  136. }
  137. /*
  138. * Initialise the cursor hotpoint
  139. * and enable the cursor in 3-colour mode.
  140. */
  141. scr->offset.x = 64+curs->offset.x;
  142. scr->offset.y = 64+curs->offset.y;
  143. tvp3026o(Cctl, 0x01);
  144. }
  145. static int
  146. tvp3026move(VGAscr* scr, Point p)
  147. {
  148. int x, y;
  149. x = p.x+scr->offset.x;
  150. y = p.y+scr->offset.y;
  151. tvp3026o(Cxlsb, x & 0xFF);
  152. tvp3026o(Cxmsb, (x>>8) & 0x0F);
  153. tvp3026o(Cylsb, y & 0xFF);
  154. tvp3026o(Cymsb, (y>>8) & 0x0F);
  155. return 0;
  156. }
  157. VGAcur vgatvp3026cur = {
  158. "tvp3026hwgc",
  159. tvp3026enable,
  160. tvp3026disable,
  161. tvp3026load,
  162. tvp3026move,
  163. };