vgact65545.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. static void
  14. ct65545page(VGAscr*, int page)
  15. {
  16. outb(0x3D6, 0x10);
  17. outb(0x3D7, page<<6);
  18. }
  19. static void
  20. ct65545disable(VGAscr*)
  21. {
  22. outl(0xA3D0, 0);
  23. }
  24. static void
  25. ct65545enable(VGAscr* scr)
  26. {
  27. ulong storage;
  28. /*
  29. * Find a place for the cursor data in display memory.
  30. * Must be on a 1024-byte boundary.
  31. */
  32. storage = ROUND(scr->gscreen->width*BY2WD*scr->gscreen->r.max.y, 1024);
  33. outl(0xB3D0, storage);
  34. scr->storage = storage;
  35. /*
  36. * Set the colours.
  37. * Enable the cursor.
  38. */
  39. outl(0xA7D0, 0xFFFF0000);
  40. outl(0xA3D0, 2);
  41. }
  42. static void
  43. ct65545initcursor(VGAscr* scr, int xo, int yo, int index)
  44. {
  45. uchar *mem;
  46. uint and, clr, set, xor;
  47. int i, x, y;
  48. mem = scr->vaddr;
  49. mem += scr->storage + index*1024;
  50. for(y = yo; y < 16; y++){
  51. clr = (scr->clr[2*y]<<8)|scr->clr[2*y+1];
  52. set = (scr->set[2*y]<<8)|scr->set[2*y+1];
  53. if(xo){
  54. clr <<= xo;
  55. set <<= xo;
  56. }
  57. and = 0;
  58. xor = 0;
  59. for(i = 0; i < 16; i++){
  60. if(set & (1<<i)){
  61. /* nothing to do */
  62. }
  63. else if(clr & (1<<i))
  64. xor |= 1<<i;
  65. else
  66. and |= 1<<i;
  67. }
  68. *mem++ = and>>8;
  69. *mem++ = xor>>8;
  70. *mem++ = and;
  71. *mem++ = xor;
  72. for(x = 16; x < 64; x += 8){
  73. *mem++ = 0xFF;
  74. *mem++ = 0x00;
  75. }
  76. }
  77. while(y < 64+yo){
  78. for(x = 0; x < 64; x += 8){
  79. *mem++ = 0xFF;
  80. *mem++ = 0x00;
  81. }
  82. y++;
  83. }
  84. }
  85. static void
  86. ct65545load(VGAscr* scr, Cursor* curs)
  87. {
  88. memmove(&scr->Cursor, curs, sizeof(Cursor));
  89. ct65545initcursor(scr, 0, 0, 0);
  90. }
  91. static int
  92. ct65545move(VGAscr* scr, Point p)
  93. {
  94. int index, x, xo, y, yo;
  95. index = 0;
  96. if((x = p.x+scr->offset.x) < 0){
  97. xo = -x;
  98. x = 0;
  99. }
  100. else
  101. xo = 0;
  102. if((y = p.y+scr->offset.y) < 0){
  103. yo = -y;
  104. y = 0;
  105. }
  106. else
  107. yo = 0;
  108. if(xo || yo){
  109. ct65545initcursor(scr, xo, yo, 1);
  110. index = 1;
  111. }
  112. outl(0xB3D0, scr->storage + index*1024);
  113. outl(0xAFD0, (y<<16)|x);
  114. return 0;
  115. }
  116. VGAdev vgact65545dev = {
  117. "ct65540", /* BUG: really 65545 */
  118. 0,
  119. 0,
  120. ct65545page,
  121. 0,
  122. };
  123. VGAcur vgact65545cur = {
  124. "ct65545hwgc",
  125. ct65545enable,
  126. ct65545disable,
  127. ct65545load,
  128. ct65545move,
  129. };