shithub: sms

Download patch

ref: 8c38c2248ef182ff9a1b8e5dd196eb4371d60848
parent: d883d929716c2da951ecb3aa6a91af471ad94508
author: Jean-André Santoni <jean.andre.santoni@gmail.com>
date: Sat Jul 13 10:36:43 EDT 2024

Implement read vdp

--- a/fns.h
+++ b/fns.h
@@ -13,4 +13,7 @@
 void vdpdata(uint8_t);
 void vdpstep(void);
 uint8_t vdpstatus(void);
+uint8_t vdpdataport(void);
+uint8_t vdphcounter(void);
+uint8_t vdpvcounter(void);
 void cramwrite(uint16_t, uint16_t);
--- a/mem.c
+++ b/mem.c
@@ -119,14 +119,14 @@
 		return 0xff;
 	else if (port >= 0x40 && port < 0x80)
 		if ((port & 0x01) == 0x00)
-			return 0xff; // vdp v counter
+			return vdpvcounter();
 		else
-			return 0xff; // vdp h counter
+			return vdphcounter();
 	else if ((port >= 0x80) && (port < 0xC0))
 		if ((port & 0x01) == 0x00)
-			return 0xff; // vdp data port
+			return vdpdataport();
 		else
-			return vdpstatus(); // vdp status flag
+			return vdpstatus();
 	else
 		if ((port & 0x01) == 0x00)
 			return 0xff; // port dc
--- a/vdp.c
+++ b/vdp.c
@@ -10,6 +10,7 @@
 uint8_t vdpbuf;
 uint8_t vdpstat = 0;
 int vdpx = 0, vdpy, vdpyy, frame, intla;
+int first = 0;
 uint16_t hctr;
 static int xmax, xdisp;
 static int sx, snx, col, pri, lum;
@@ -332,8 +333,16 @@
 vdpctrl(uint8_t v)
 {
 	printf("    vdp write to control port %x\n", v);
+
+	if(first){
+	    first = 0;
+        vdpaddr = (vdpaddr & 0xFF00) | v;
+        return;
+	}
+
 	vdpcode = (v >> 6) & 0x03;
 	vdpaddr = (vdpaddr & 0x00ff) | ((v & 0x3f) << 8);
+	first = 1;
 
 	switch(vdpcode){
 		case 0:
@@ -358,13 +367,40 @@
 }
 
 uint8_t
+vdpdataport(void)
+{
+    uint8_t v = vdpbuf;
+    vdpbuf = vram[vdpaddr];
+    vdpaddr++;
+    vdpaddr &= 0x3fff;
+    printf("    vdp read from data port %x\n", v);
+    first = 1;
+    return v;
+}
+
+uint8_t
 vdpstatus(void)
 {
     uint8_t v = vdpstat | 0x1f;
     vdpstat = 0;
     z80irq = 0;
-    printf("    vdp status %x\n", v);
+    printf("    vdp read status flags %x\n", v);
+    first = 1;
     return v;
+}
+
+uint8_t
+vdphcounter(void)
+{
+    printf("    vdp read hcounter %x\n", vdpx);
+    return vdpx;
+}
+
+uint8_t
+vdpvcounter(void)
+{
+    printf("    vdp read vcounter %x\n", vdpy);
+    return vdpy;
 }
 
 void
--