vgax.c 1.6 KB

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