vgact65545.c 2.2 KB

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