vga_attr.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #include "vDos.h"
  2. #include "inout.h"
  3. #include "vga.h"
  4. #define attr(blah) vga.attr.blah
  5. void VGA_ATTR_SetPalette(Bit8u index, Bit8u val)
  6. {
  7. vga.attr.palette[index] = val;
  8. if (vga.attr.mode_control & 0x80)
  9. val = (val&0xf) | (vga.attr.color_select << 4);
  10. val &= 63;
  11. val |= (vga.attr.color_select & 0xc) << 4;
  12. VGA_DAC_CombineColor(index, val);
  13. }
  14. Bit8u read_p3c0(Bitu /*port*/)
  15. {
  16. Bitu retval = attr(index) & 0x1f;
  17. return retval;
  18. }
  19. void write_p3c0(Bitu /*port*/,Bitu val)
  20. {
  21. if (!vga.attrindex)
  22. {
  23. attr(index) = val & 0x1F;
  24. vga.attrindex = true;
  25. /*
  26. 0-4 Address of data register to write to port 3C0h or read from port 3C1h
  27. */
  28. return;
  29. }
  30. vga.attrindex = false;
  31. // Palette
  32. if (attr(index) < 0x10)
  33. {
  34. VGA_ATTR_SetPalette(attr(index), (Bit8u)val);
  35. /*
  36. 0-5 Index into the 256 color DAC table. May be modified by 3C0h index
  37. 10h and 14h.
  38. */
  39. return;
  40. }
  41. switch (attr(index))
  42. {
  43. case 0x10:
  44. { // Mode control register
  45. Bitu difference = attr(mode_control)^val;
  46. attr(mode_control) = (Bit8u)val;
  47. if (difference & 0x80)
  48. for (Bit8u i = 0; i < 0x10; i++)
  49. VGA_ATTR_SetPalette(i, vga.attr.palette[i]);
  50. if (difference & 0x41)
  51. VGA_DetermineMode();
  52. /*
  53. 0 Graphics mode if set, Alphanumeric mode else.
  54. 1 Monochrome mode if set, color mode else.
  55. 2 9-bit wide characters if set.
  56. The 9th bit of characters C0h-DFh will be the same as
  57. the 8th bit. Otherwise it will be the background color.
  58. 3 If set Attribute bit 7 is blinking, else high intensity.
  59. 5 If set the PEL panning register (3C0h index 13h) is temporarily set
  60. to 0 from when the line compare causes a wrap around until the next
  61. vertical retrace when the register is automatically reloaded with
  62. the old value, else the PEL panning register ignores line compares.
  63. 6 If set pixels are 8 bits wide. Used in 256 color modes.
  64. 7 If set bit 4-5 of the index into the DAC table are taken from port
  65. 3C0h index 14h bit 0-1, else the bits in the palette register are
  66. used.
  67. */
  68. break;
  69. }
  70. case 0x11: // Overscan color register
  71. break;
  72. case 0x12: // Color plane enable register
  73. // Why disable colour planes?
  74. attr(color_plane_enable) = (Bit8u)val;
  75. /*
  76. 0 Bit plane 0 is enabled if set.
  77. 1 Bit plane 1 is enabled if set.
  78. 2 Bit plane 2 is enabled if set.
  79. 3 Bit plane 3 is enabled if set.
  80. 4-5 Video Status MUX. Diagnostics use only.
  81. Two attribute bits appear on bits 4 and 5 of the Input Status
  82. Register 1 (3dAh). 0: Bit 2/0, 1: Bit 5/4, 2: bit 3/1, 3: bit 7/6
  83. */
  84. break;
  85. case 0x13: // Horizontal PEL panning register, we don't do this
  86. attr(horizontal_pel_panning) = val & 0xF;
  87. /*
  88. 0-3 Indicates number of pixels to shift the display left
  89. Value 9bit textmode 256color mode Other modes
  90. 0 1 0 0
  91. 1 2 n/a 1
  92. 2 3 1 2
  93. 3 4 n/a 3
  94. 4 5 2 4
  95. 5 6 n/a 5
  96. 6 7 3 6
  97. 7 8 n/a 7
  98. 8 0 n/a n/a
  99. */
  100. break;
  101. case 0x14: // Color select register
  102. if (attr(color_select) ^ val)
  103. {
  104. attr(color_select) = (Bit8u)val;
  105. for (Bit8u i = 0; i < 0x10; i++)
  106. VGA_ATTR_SetPalette(i, vga.attr.palette[i]);
  107. }
  108. /*
  109. 0-1 If 3C0h index 10h bit 7 is set these 2 bits are used as bits 4-5 of
  110. the index into the DAC table.
  111. 2-3 These 2 bits are used as bit 6-7 of the index into the DAC table
  112. except in 256 color mode.
  113. Note: this register does not affect 256 color modes.
  114. */
  115. break;
  116. }
  117. }
  118. Bit8u read_p3c1(Bitu /*port*/)
  119. {
  120. if (attr(index) < 0x10) // Palette
  121. return attr(palette[attr(index)]);
  122. switch (attr(index))
  123. {
  124. case 0x10: // Mode control register
  125. return attr(mode_control);
  126. // case 0x11: // Overscan color register
  127. // return 0;
  128. case 0x12: // Color plane enable register
  129. return attr(color_plane_enable);
  130. case 0x13: // Horizontal PEL panning register
  131. return attr(horizontal_pel_panning);
  132. case 0x14: // Color select register
  133. return attr(color_select);
  134. }
  135. return 0;
  136. }
  137. void VGA_SetupAttr(void)
  138. {
  139. IO_RegisterWriteHandler(0x3c0, write_p3c0);
  140. IO_RegisterReadHandler(0x3c0, read_p3c0);
  141. IO_RegisterReadHandler(0x3c1, read_p3c1);
  142. }