vgatvp3026.c 3.8 KB

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