vgax.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. }
  51. else{
  52. outb(Attrx, 0x20|index);
  53. data = inb(Attrx+1);
  54. }
  55. break;
  56. default:
  57. iunlock(&vgaxlock);
  58. return -1;
  59. }
  60. iunlock(&vgaxlock);
  61. return data & 0xFF;
  62. }
  63. int
  64. vgaxo(int32_t port, unsigned char index, unsigned char data)
  65. {
  66. ilock(&vgaxlock);
  67. switch(port){
  68. case Seqx:
  69. case Crtx:
  70. case Grx:
  71. /*
  72. * We could use an outport here, but some chips
  73. * (e.g. 86C928) have trouble with that for some
  74. * registers.
  75. */
  76. outb(port, index);
  77. outb(port+1, data);
  78. break;
  79. case Attrx:
  80. inb(Status1);
  81. if(index < 0x10){
  82. outb(Attrx, index);
  83. outb(Attrx, data);
  84. inb(Status1);
  85. outb(Attrx, 0x20|index);
  86. }
  87. else{
  88. outb(Attrx, 0x20|index);
  89. outb(Attrx, data);
  90. }
  91. break;
  92. default:
  93. iunlock(&vgaxlock);
  94. return -1;
  95. }
  96. iunlock(&vgaxlock);
  97. return 0;
  98. }