vgahiqvideo.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. enum {
  14. Xrx = 0x3D6, /* Configuration Extensions Index */
  15. };
  16. static uchar
  17. hiqvideoxi(long port, uchar index)
  18. {
  19. uchar data;
  20. outb(port, index);
  21. data = inb(port+1);
  22. return data;
  23. }
  24. static void
  25. hiqvideoxo(long port, uchar index, uchar data)
  26. {
  27. outb(port, index);
  28. outb(port+1, data);
  29. }
  30. static void
  31. hiqvideolinear(VGAscr*, int, int)
  32. {
  33. }
  34. static void
  35. hiqvideoenable(VGAscr* scr)
  36. {
  37. Pcidev *p;
  38. int vmsize;
  39. /*
  40. * Only once, can't be disabled for now.
  41. */
  42. if(scr->mmio)
  43. return;
  44. if(p = pcimatch(nil, 0x102C, 0)){
  45. switch(p->did){
  46. case 0x00C0: /* 69000 HiQVideo */
  47. vmsize = 2*1024*1024;
  48. break;
  49. case 0x00E0: /* 65550 HiQV32 */
  50. case 0x00E4: /* 65554 HiQV32 */
  51. case 0x00E5: /* 65555 HiQV32 */
  52. switch((hiqvideoxi(Xrx, 0x43)>>1) & 0x03){
  53. default:
  54. case 0:
  55. vmsize = 1*1024*1024;
  56. break;
  57. case 1:
  58. vmsize = 2*1024*1024;
  59. break;
  60. }
  61. break;
  62. default:
  63. return;
  64. }
  65. }
  66. else
  67. return;
  68. scr->pci = p;
  69. vgalinearpci(scr);
  70. if(scr->paddr) {
  71. addvgaseg("hiqvideoscreen", scr->paddr, scr->apsize);
  72. }
  73. /*
  74. * Find a place for the cursor data in display memory.
  75. * Must be on a 4096-byte boundary.
  76. * scr->mmio holds the virtual address of the cursor
  77. * storage area in the framebuffer region.
  78. */
  79. scr->storage = vmsize-4096;
  80. scr->mmio = (ulong*)((uchar*)scr->vaddr+scr->storage);
  81. }
  82. static void
  83. hiqvideocurdisable(VGAscr*)
  84. {
  85. hiqvideoxo(Xrx, 0xA0, 0x10);
  86. }
  87. static void
  88. hiqvideocurload(VGAscr* scr, Cursor* curs)
  89. {
  90. uchar *p;
  91. int x, y;
  92. /*
  93. * Disable the cursor.
  94. */
  95. hiqvideocurdisable(scr);
  96. if(scr->mmio == 0)
  97. return;
  98. p = (uchar*)scr->mmio;
  99. for(y = 0; y < 16; y += 2){
  100. *p++ = ~(curs->clr[2*y]|curs->set[2*y]);
  101. *p++ = ~(curs->clr[2*y+1]|curs->set[2*y+1]);
  102. *p++ = 0xFF;
  103. *p++ = 0xFF;
  104. *p++ = ~(curs->clr[2*y+2]|curs->set[2*y+2]);
  105. *p++ = ~(curs->clr[2*y+3]|curs->set[2*y+3]);
  106. *p++ = 0xFF;
  107. *p++ = 0xFF;
  108. *p++ = curs->set[2*y];
  109. *p++ = curs->set[2*y+1];
  110. *p++ = 0x00;
  111. *p++ = 0x00;
  112. *p++ = curs->set[2*y+2];
  113. *p++ = curs->set[2*y+3];
  114. *p++ = 0x00;
  115. *p++ = 0x00;
  116. }
  117. while(y < 32){
  118. for(x = 0; x < 64; x += 8)
  119. *p++ = 0xFF;
  120. for(x = 0; x < 64; x += 8)
  121. *p++ = 0x00;
  122. y += 2;
  123. }
  124. /*
  125. * Save the cursor hotpoint and enable the cursor.
  126. */
  127. scr->offset = curs->offset;
  128. hiqvideoxo(Xrx, 0xA0, 0x11);
  129. }
  130. static int
  131. hiqvideocurmove(VGAscr* scr, Point p)
  132. {
  133. int x, y;
  134. if(scr->mmio == 0)
  135. return 1;
  136. if((x = p.x+scr->offset.x) < 0)
  137. x = 0x8000|(-x & 0x07FF);
  138. if((y = p.y+scr->offset.y) < 0)
  139. y = 0x8000|(-y & 0x07FF);
  140. hiqvideoxo(Xrx, 0xA4, x & 0xFF);
  141. hiqvideoxo(Xrx, 0xA5, (x>>8) & 0xFF);
  142. hiqvideoxo(Xrx, 0xA6, y & 0xFF);
  143. hiqvideoxo(Xrx, 0xA7, (y>>8) & 0xFF);
  144. return 0;
  145. }
  146. static void
  147. hiqvideocurenable(VGAscr* scr)
  148. {
  149. uchar xr80;
  150. hiqvideoenable(scr);
  151. if(scr->mmio == 0)
  152. return;
  153. /*
  154. * Disable the cursor.
  155. */
  156. hiqvideocurdisable(scr);
  157. /*
  158. * Cursor colours.
  159. * Can't call setcolor here as cursor is already locked.
  160. * When done make sure the cursor enable in Xr80 is set.
  161. */
  162. xr80 = hiqvideoxi(Xrx, 0x80);
  163. hiqvideoxo(Xrx, 0x80, xr80|0x01);
  164. vgao(PaddrW, 0x04);
  165. vgao(Pdata, Pwhite);
  166. vgao(Pdata, Pwhite);
  167. vgao(Pdata, Pwhite);
  168. vgao(Pdata, Pblack);
  169. vgao(Pdata, Pblack);
  170. vgao(Pdata, Pblack);
  171. hiqvideoxo(Xrx, 0x80, xr80|0x10);
  172. hiqvideoxo(Xrx, 0xA2, (scr->storage>>12)<<4);
  173. hiqvideoxo(Xrx, 0xA3, (scr->storage>>16) & 0x3F);
  174. /*
  175. * Load, locate and enable the 32x32 cursor.
  176. * Cursor enable in Xr80 better be set already.
  177. */
  178. hiqvideocurload(scr, &arrow);
  179. hiqvideocurmove(scr, ZP);
  180. hiqvideoxo(Xrx, 0xA0, 0x11);
  181. }
  182. VGAdev vgahiqvideodev = {
  183. "hiqvideo",
  184. hiqvideoenable, /* enable */
  185. nil, /* disable */
  186. nil, /* page */
  187. hiqvideolinear, /* linear */
  188. };
  189. VGAcur vgahiqvideocur = {
  190. "hiqvideohwgc",
  191. hiqvideocurenable, /* enable */
  192. hiqvideocurdisable, /* disable */
  193. hiqvideocurload, /* load */
  194. hiqvideocurmove, /* move */
  195. };