vgax.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "u.h"
  10. #include "../port/lib.h"
  11. #include "mem.h"
  12. #include "dat.h"
  13. #include "fns.h"
  14. #include "io.h"
  15. #include "../port/error.h"
  16. #define Image IMAGE
  17. #include <draw.h>
  18. #include <memdraw.h>
  19. #include <cursor.h>
  20. #include "screen.h"
  21. static Lock vgaxlock; /* access to index registers */
  22. int
  23. vgaxi(int32_t port, unsigned char index)
  24. {
  25. unsigned char data;
  26. ilock(&vgaxlock);
  27. switch(port){
  28. case Seqx:
  29. case Crtx:
  30. case Grx:
  31. outb(port, index);
  32. data = inb(port + 1);
  33. break;
  34. case Attrx:
  35. /*
  36. * Allow processor access to the colour
  37. * palette registers. Writes to Attrx must
  38. * be preceded by a read from Status1 to
  39. * initialise the register to point to the
  40. * index register and not the data register.
  41. * Processor access is allowed by turning
  42. * off bit 0x20.
  43. */
  44. inb(Status1);
  45. if(index < 0x10){
  46. outb(Attrx, index);
  47. data = inb(Attrx + 1);
  48. inb(Status1);
  49. outb(Attrx, 0x20 | index);
  50. } else {
  51. outb(Attrx, 0x20 | index);
  52. data = inb(Attrx + 1);
  53. }
  54. break;
  55. default:
  56. iunlock(&vgaxlock);
  57. return -1;
  58. }
  59. iunlock(&vgaxlock);
  60. return data & 0xFF;
  61. }
  62. int
  63. vgaxo(int32_t port, unsigned char index, unsigned char data)
  64. {
  65. ilock(&vgaxlock);
  66. switch(port){
  67. case Seqx:
  68. case Crtx:
  69. case Grx:
  70. /*
  71. * We could use an outport here, but some chips
  72. * (e.g. 86C928) have trouble with that for some
  73. * registers.
  74. */
  75. outb(port, index);
  76. outb(port + 1, data);
  77. break;
  78. case Attrx:
  79. inb(Status1);
  80. if(index < 0x10){
  81. outb(Attrx, index);
  82. outb(Attrx, data);
  83. inb(Status1);
  84. outb(Attrx, 0x20 | index);
  85. } else {
  86. outb(Attrx, 0x20 | index);
  87. outb(Attrx, data);
  88. }
  89. break;
  90. default:
  91. iunlock(&vgaxlock);
  92. return -1;
  93. }
  94. iunlock(&vgaxlock);
  95. return 0;
  96. }