shithub: sms

Download patch

ref: d883d929716c2da951ecb3aa6a91af471ad94508
parent: 73a7877779639b957f662355b1aaea68160cc63c
author: Jean-André Santoni <jean.andre.santoni@gmail.com>
date: Sat Jul 13 08:28:18 EDT 2024

Start implementing vdp status getter

--- a/dat.h
+++ b/dat.h
@@ -15,7 +15,6 @@
 
 extern uint16_t vram[32768], vsram[40];
 extern uint32_t cramc[64];
-extern uint16_t vdpstat;
 extern int vdpx, vdpy, frame, intla;
 
 enum {
@@ -44,9 +43,9 @@
 	IE1     = 0x10,
 	DMAEN   = 0x10,
 	SHI     = 0x08,
-	
+
 	WIDE    = 0x01,
-	
+
 	STATDMA = 0x02,
 	STATHBL = 0x04,
 	STATVBL = 0x08,
@@ -60,7 +59,7 @@
 	BUSREQ = 1,
 	BUSACK = 2,
 	RESET  = 4,
-	
+
 	INTVBL = 1,
 	INTHOR = 2,
 };
--- a/fns.h
+++ b/fns.h
@@ -12,4 +12,5 @@
 void vdpctrl(uint8_t);
 void vdpdata(uint8_t);
 void vdpstep(void);
+uint8_t vdpstatus(void);
 void cramwrite(uint16_t, uint16_t);
--- a/mem.c
+++ b/mem.c
@@ -27,11 +27,8 @@
 void
 cramwrite(uint16_t a, uint16_t v)
 {
-	uint32_t w;
-
 	cram[a & 0x1f] = v;
-	w = v << 12 & 0xe00000 | v << 8 & 0xe000 | v << 4 & 0xe0;
-	cramc[a & 0x1f] = w;
+	cramc[a & 0x1f] = v << 12 & 0xe00000 | v << 8 & 0xe000 | v << 4 & 0xe0;
 
 	printf("cramwrite %x %x\n", a, v);
 	for(int i=0;i<64;i++)
@@ -129,7 +126,7 @@
 		if ((port & 0x01) == 0x00)
 			return 0xff; // vdp data port
 		else
-			return 0x1f; // vdp status flag
+			return vdpstatus(); // vdp status flag
 	else
 		if ((port & 0x01) == 0x00)
 			return 0xff; // port dc
--- a/vdp.c
+++ b/vdp.c
@@ -1,3 +1,4 @@
+#include <stdint.h>
 #include <stdio.h>
 #include "dat.h"
 #include "fns.h"
@@ -7,7 +8,7 @@
 uint8_t vdpcode;
 uint8_t vdpaddr;
 uint8_t vdpbuf;
-uint16_t vdpstat = 0x3400;
+uint8_t vdpstat = 0;
 int vdpx = 0, vdpy, vdpyy, frame, intla;
 uint16_t hctr;
 static int xmax, xdisp;
@@ -354,6 +355,16 @@
 	}
 	vdpaddr++;
 	vdpaddr &= 0x3fff;
+}
+
+uint8_t
+vdpstatus(void)
+{
+    uint8_t v = vdpstat | 0x1f;
+    vdpstat = 0;
+    z80irq = 0;
+    printf("    vdp status %x\n", v);
+    return v;
 }
 
 void
--