]> 4ch.mooo.com Git - 16.git/commitdiff
void update_state_from_vga_() might have the bug in it
authorsparky4 <sparky4@cock.li>
Fri, 3 Jun 2016 18:12:39 +0000 (13:12 -0500)
committersparky4 <sparky4@cock.li>
Fri, 3 Jun 2016 18:12:39 +0000 (13:12 -0500)
src/lib/modex16.c
src/lib/modex16.h

index aa41005367dc6d269e36e5afa5f89fc51191b9da..429d5fb60fb374af9f8b75f56c6280baaf58bdb8 100755 (executable)
@@ -1178,3 +1178,130 @@ void modexprintmeminfo(video_t *v)
                printf("\n");\r
        }\r
 }\r
+\r
+void update_state_from_vga_() {\r
+       unsigned char c;\r
+\r
+       vga_state.vga_pos_x = 0;\r
+       vga_state.vga_pos_y = 0;\r
+       vga_state.vga_stride = 80;\r
+       vga_state.vga_height = 25;\r
+       vga_state.vga_width = 80;\r
+       vga_state.vga_9wide = 0;\r
+\r
+       if (vga_state.vga_flags & VGA_IS_VGA) { /* VGA only. EGA cards DO have the misc. output reg but it's write-only */\r
+               /* update state from H/W which I/O port */\r
+               c = inp(0x3CC);\r
+               if (c & 1) {\r
+                       vga_state.vga_base_3x0 = 0x3D0;\r
+               }\r
+               else {\r
+                       vga_state.vga_base_3x0 = 0x3B0;\r
+               }\r
+\r
+               /* now ask the graphics controller where/how VGA memory is mapped */\r
+               c = vga_read_GC(6);\r
+               /* bit 0 = alpha disable (if set, graphics) */\r
+               vga_state.vga_alpha_mode = ((c & 1) == 0);\r
+               /* bits 2-3 memory map select */\r
+               update_state_vga_memory_map_select((c>>2)&3);\r
+\r
+               /* read the sequencer: are we in 8 or 9 dot mode? */\r
+               c = vga_read_sequencer(0x1);\r
+               vga_state.vga_9wide = (c & 1) == 0;\r
+\r
+               /* read from the CRTC controller the stride, width, and height */\r
+               vga_state.vga_stride = vga_read_CRTC(0x13) * 2; /* "offset" register */\r
+               if (vga_state.vga_alpha_mode) {\r
+                       vga_state.vga_width = vga_state.vga_stride;\r
+                       vga_sync_hw_cursor();\r
+                       /* TODO: read vertical blank values and calculate active area, then divide by scan line height, to get alpha height */\r
+                       /* TODO: read horizontal blank values to calculate active area, then visible width */\r
+               }\r
+               else {\r
+                       /* TODO: similar semantics for graphics mode */\r
+               }\r
+       }\r
+       else if (vga_state.vga_flags & VGA_IS_EGA) {\r
+               /* Well the EGA has similar registers BUT they aren't readable. So we have to\r
+                * guess based on other information handed to us */\r
+\r
+               /* reading the misc. output register doesn't work, use BIOS data area */\r
+               c = *((unsigned char far*)MK_FP(0x40,0x63));\r
+               if ((c&0xF0) == 0xD0)\r
+                       vga_state.vga_base_3x0 = 0x3D0;\r
+               else if ((c&0xF0) == 0xB0)\r
+                       vga_state.vga_base_3x0 = 0x3B0;\r
+               else {\r
+                       vga_state.vga_base_3x0 = 0x3D0;\r
+               }\r
+\r
+               /* reading from the graphics controller (0x3CE) doesn't work, deduce from BIOS mode */\r
+               c = int10_getmode();\r
+               switch (c) {\r
+                       case 0: case 1: case 2: case 3: case 7:\r
+                               vga_state.vga_alpha_mode = 1;\r
+\r
+ /* the best we can do is assume B0000 if CRTC is at 3Bx or B8000 if at 3Dx even though it's possible to map at B8000 and 3Bx */\r
+                               if (vga_state.vga_base_3x0 == 0x3B0)\r
+                                       update_state_vga_memory_map_select(2);\r
+                               else\r
+                                       update_state_vga_memory_map_select(3);\r
+                               break;\r
+                       case 4: case 5: case 6:\r
+                               vga_state.vga_alpha_mode = 0;\r
+                               update_state_vga_memory_map_select(3);\r
+                               break;\r
+                       case 13: case 14: case 15: case 16: case 17: case 18: default:\r
+                               vga_state.vga_alpha_mode = 0;\r
+                               update_state_vga_memory_map_select(1);\r
+                               break;\r
+               }\r
+\r
+               /* read from the CRTC controller the stride, width, and height */\r
+               vga_state.vga_stride = vga_read_CRTC(0x13) * 2; /* "offset" register */\r
+               if (vga_state.vga_alpha_mode) {\r
+                       vga_state.vga_width = vga_state.vga_stride;\r
+                       vga_sync_hw_cursor();\r
+                       /* TODO: read vertical blank values and calculate active area, then divide by scan line height, to get alpha height */\r
+                       /* TODO: read horizontal blank values to calculate active area, then visible width */\r
+               }\r
+               else {\r
+                       /* TODO: similar semantics for graphics mode */\r
+               }\r
+       }\r
+       else if (vga_state.vga_flags & VGA_IS_CGA) {\r
+               vga_state.vga_base_3x0 = 0x3D0; /* always at 0x3Dx */\r
+\r
+               /* TODO: If Tandy, detect state */\r
+\r
+               /* read the status register to determine the state of the CGA... oh wait... we can't.\r
+                * fine. deduce it from the BIOS video mode. */\r
+               c = int10_getmode();\r
+               switch (c) {\r
+                       case 0: case 1: case 2: case 3: case 7:\r
+                               vga_state.vga_alpha_mode = 1;\r
+                               break;\r
+                       default:\r
+                               vga_state.vga_alpha_mode = 0;\r
+                               break;\r
+               }\r
+\r
+               if (c <= 1) {\r
+                       vga_state.vga_stride = 40;\r
+                       vga_state.vga_width = 40;\r
+               }\r
+\r
+               update_state_vga_memory_map_select(3); /* 0xB8000 */\r
+       }\r
+       else if (vga_state.vga_flags & VGA_IS_MDA) {\r
+               vga_state.vga_base_3x0 = 0x3B0; /* always at 0x3Bx */\r
+               vga_state.vga_alpha_mode = 1; /* stock MDA doesn't have graphics */\r
+\r
+               /* Hercules MDA: It would be nice to be able to read bit 2 of the display control,\r
+                *               except that the port is write-only. Thanks >:( */\r
+               update_state_vga_memory_map_select(2); /* 0xB0000 */\r
+       }\r
+\r
+       vga_state.vga_draw_stride_limit = vga_state.vga_draw_stride = vga_state.vga_stride;\r
+}\r
index 0b30850dc0ba5ed260dc9ef06d13b6ec30a68368..9ce226e1fccf726c1a4ccf137890bc6dd179fc0e 100755 (executable)
@@ -186,5 +186,6 @@ void modexcls(page_t *page, byte color, byte *Where);
 void modexWaitBorder();
 void bios_cls();
 void modexprintmeminfo(video_t *v);
+void update_state_from_vga_();
 
 #endif