vgax.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 Lock vgaxlock; /* access to index registers */
  14. int
  15. vgaxi(long port, uchar index)
  16. {
  17. uchar data;
  18. ilock(&vgaxlock);
  19. switch(port){
  20. case Seqx:
  21. case Crtx:
  22. case Grx:
  23. outb(port, index);
  24. data = inb(port+1);
  25. break;
  26. case Attrx:
  27. /*
  28. * Allow processor access to the colour
  29. * palette registers. Writes to Attrx must
  30. * be preceded by a read from Status1 to
  31. * initialise the register to point to the
  32. * index register and not the data register.
  33. * Processor access is allowed by turning
  34. * off bit 0x20.
  35. */
  36. inb(Status1);
  37. if(index < 0x10){
  38. outb(Attrx, index);
  39. data = inb(Attrx+1);
  40. inb(Status1);
  41. outb(Attrx, 0x20|index);
  42. }
  43. else{
  44. outb(Attrx, 0x20|index);
  45. data = inb(Attrx+1);
  46. }
  47. break;
  48. default:
  49. iunlock(&vgaxlock);
  50. return -1;
  51. }
  52. iunlock(&vgaxlock);
  53. return data & 0xFF;
  54. }
  55. int
  56. vgaxo(long port, uchar index, uchar data)
  57. {
  58. ilock(&vgaxlock);
  59. switch(port){
  60. case Seqx:
  61. case Crtx:
  62. case Grx:
  63. /*
  64. * We could use an outport here, but some chips
  65. * (e.g. 86C928) have trouble with that for some
  66. * registers.
  67. */
  68. outb(port, index);
  69. outb(port+1, data);
  70. break;
  71. case Attrx:
  72. inb(Status1);
  73. if(index < 0x10){
  74. outb(Attrx, index);
  75. outb(Attrx, data);
  76. inb(Status1);
  77. outb(Attrx, 0x20|index);
  78. }
  79. else{
  80. outb(Attrx, 0x20|index);
  81. outb(Attrx, data);
  82. }
  83. break;
  84. default:
  85. iunlock(&vgaxlock);
  86. return -1;
  87. }
  88. iunlock(&vgaxlock);
  89. return 0;
  90. }