ref: cdfeb3a75e08d3d82a4c1d06a24e6434387eaef2
parent: 4ebcf852deee068e350f8f539adba0f23a5fcf14
author: Jean-André Santoni <jean.andre.santoni@gmail.com>
date: Wed Jul 10 17:47:10 EDT 2024
Start plugging the vdp
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
TARGET := sms_libretro.so
SHARED := -shared
-CFLAGS += -O3 -fPIC
+CFLAGS += -g -O3 -fPIC
OBJ = sms.o z80.o mem.o vdp.o
--- a/fns.h
+++ b/fns.h
@@ -7,5 +7,7 @@
void z80write(uint16_t, uint8_t);
uint8_t z80in(uint8_t);
void z80out(uint8_t, uint8_t);
+void vdpstep(void);
void flush(void);
+void vdpmode(void);
void ymwrite(uint8_t, uint8_t, uint8_t);
--- a/sms.c
+++ b/sms.c
@@ -12,6 +12,7 @@
static retro_environment_t environ_cb;
retro_audio_sample_batch_t audio_cb;
+int t = 0;
uint32_t r[16];
extern uint16_t pc, curpc, sp;
uint32_t asp, irq, stop;
@@ -20,8 +21,10 @@
// uint8_t *prg = NULL;
uint8_t *rom = NULL;
uint8_t *mem = NULL;
-uint32_t pic[256*224] = {0};+uint8_t *pic = NULL;
+int vdpclock = 0;
+
void
loadrom(const uint8_t *data)
{@@ -28,6 +31,7 @@
// memcpy(header, data, sizeof(header));
// prg = malloc(0xC000);
// memcpy(prg, data+sizeof(header), 0xC000);
+ pic = malloc(320 * 224 * 4);
rom = malloc(0x40000);
memcpy(rom, data, 0x40000);
mem = malloc(0xC000+0x8000);
@@ -78,6 +82,7 @@
return false;
loadrom(game->data);
+ vdpmode();
return true;
}
@@ -94,11 +99,18 @@
input_poll_cb();
process_inputs();
- // while(!doflush){+ while(!doflush){ printf("%d ================================\n", counter++);- z80step();
- // }
- video_cb(pic, 256, 224, 256*4);
+ t = z80step() * Z80DIV;
+ vdpclock -= t;
+
+ while(vdpclock < 0){+ vdpstep();
+ vdpclock += 8;
+ }
+ }
+ printf("flush\n");+ video_cb(pic, 320, 224, 320*4);
// audioout();
doflush = 0;
}
--- a/vdp.c
+++ b/vdp.c
@@ -1,3 +1,4 @@
+#include <stdio.h>
#include "dat.h"
#include "fns.h"
@@ -4,7 +5,7 @@
extern uint8_t *pic;
uint16_t vdpstat = 0x3400;
-int vdpx, vdpy, vdpyy, frame, intla;
+int vdpx = 0, vdpy, vdpyy, frame, intla;
uint16_t hctr;
static int xmax, xdisp;
static int sx, snx, col, pri, lum;
@@ -96,6 +97,7 @@
static void
planeinit(void)
{+ printf("planeinit\n"); static int szs[] = {5, 6, 6, 7};int v, a, i;
struct pctxt *p;
@@ -221,6 +223,7 @@
static void
spritesinit(void)
{+ printf("spritesinit\n");uint16_t t, *p, dy, c;
uint32_t v;
int i, ns, np, nt;
--
⑨