changeset 2411:efd2242c2c23

Fix silly TMS9918A bug, make CRAM viewer sorta useful in TMS9918A modes, make mode4 address map externally viewable for debugger
author Michael Pavone <pavone@retrodev.com>
date Thu, 04 Jan 2024 22:13:46 -0800
parents f1574b22d5d9
children ed7b4d869989
files vdp.c vdp.h
diffstat 2 files changed, 33 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/vdp.c	Thu Jan 04 22:12:03 2024 -0800
+++ b/vdp.c	Thu Jan 04 22:13:46 2024 -0800
@@ -60,7 +60,7 @@
 	ACTIVE
 };
 
-static uint16_t mode4_address_map[0x4000];
+uint16_t mode4_address_map[0x4000];
 static uint32_t planar_to_chunky[256];
 static uint8_t levels[] = {0, 27, 49, 71, 87, 103, 119, 130, 146, 157, 174, 190, 206, 228, 255};
 
@@ -2030,7 +2030,7 @@
 						*(fb++) = context->colors[i];
 					}
 				}
-			} else {
+			} else if (context->type == VDP_GENESIS || (context->regs[REG_MODE_1] & BIT_MODE_4)) {
 				for (int i = MODE4_OFFSET; i < MODE4_OFFSET+32; i++)
 				{
 					for (int x = 0; x < 16; x++)
@@ -2038,6 +2038,34 @@
 						*(fb++) = context->colors[i];
 					}
 				}
+			} else if (context->type != VDP_GENESIS) {
+				uint16_t address = context->regs[REG_COLOR_TABLE] << 6;
+				for (int i = 0; i < 32; i++, address++)
+				{
+					uint8_t entry = context->vdpmem[mode4_address_map[address] ^ 1];
+					uint8_t fg = entry >> 4, bg = entry & 0xF;
+					uint32_t fg_full, bg_full;
+					if (context->type == VDP_GAMEGEAR) {
+						//Game Gear uses CRAM entries 16-31 for TMS9918A modes
+						fg_full = context->colors[fg + 16 + MODE4_OFFSET];
+						bg_full = context->colors[bg + 16 + MODE4_OFFSET];
+					} else {
+						fg <<= 1;
+						fg = (fg & 0xE) | (fg << 1 & 0x20);
+						fg_full = context->color_map[fg | FBUF_TMS];
+						bg <<= 1;
+						bg = (bg & 0xE) | (bg << 1 & 0x20);
+						bg_full = context->color_map[bg | FBUF_TMS];
+					}
+					for (int x = 0; x < 8; x++)
+					{
+						*(fb++) = fg_full;
+					}
+					for (int x = 0; x < 8; x++)
+					{
+						*(fb++) = bg_full;
+					}
+				}
 			}
 		}
 		if (
@@ -3636,7 +3664,7 @@
 		return;
 	}
 	uint16_t address = context->regs[REG_COLOR_TABLE] << 6;
-	if (context->regs[REG_MODE_2] & BIT_M3) {
+	if (context->regs[REG_MODE_1] & BIT_M3) {
 		//Graphics II
 		uint16_t upper_vcounter_mask;
 		uint16_t pattern_name_mask;
--- a/vdp.h	Thu Jan 04 22:12:03 2024 -0800
+++ b/vdp.h	Thu Jan 04 22:13:46 2024 -0800
@@ -320,4 +320,6 @@
 uint16_t vdp_status(vdp_context *context);
 void vdp_reg_write(vdp_context *context, uint16_t reg, uint16_t value);
 
+extern uint16_t mode4_address_map[0x4000];
+
 #endif //VDP_H_