ref: f0ed9ed9f0799ee4993ee916994811dc9257191a
parent: 7c25ae8a34ad4b15e83c07477b5bd9e59fac3c5f
author: aiju <devnull@localhost>
date: Fri Jun 13 14:06:44 EDT 2014
games/md: vdp window fix, added ym2612 timers
--- a/sys/src/games/md/dat.h
+++ b/sys/src/games/md/dat.h
@@ -22,7 +22,7 @@
extern u16int vdpstat;
extern int vdpx, vdpy;
-extern u8int ym[512];
+extern u8int ym[512], ymstat;
enum {
MODE1 = 0x00,
--- a/sys/src/games/md/mem.c
+++ b/sys/src/games/md/mem.c
@@ -328,7 +328,7 @@
case 1:
return zram[a & 0x1fff];
case 2:
- return 0;
+ return ymstat;
case 3:
if(a >= 0x7f00){
v = memread(0xc00000 | a & 0x7e);
--- a/sys/src/games/md/vdp.c
+++ b/sys/src/games/md/vdp.c
@@ -144,7 +144,8 @@
}
if(rwin > lwin){
p = pctxt + 2;
- p->tx = p->ty = 0;
+ p->tx = lwin >> 3 & pctxt[2].w - 1;
+ p->tnx = lwin & 7;
p->tny = vdpy & 7;
p->ty = vdpy >> 3 & pctxt[2].h - 1;
tile(p);
@@ -306,7 +307,10 @@
pri = 0;
planes();
sprites();
- pixeldraw(vdpx, vdpy, cramc[col]);
+ if((reg[MODE2] & 0x40) != 0 && (vdpx >= 8 || (reg[MODE1] & 0x20) == 0))
+ pixeldraw(vdpx, vdpy, cramc[col]);
+ else
+ pixeldraw(vdpx, vdpy, 0);
}else
pixeldraw(vdpx, vdpy, 0xcccccc);
if(++vdpx >= xmax){
--- a/sys/src/games/md/ym.c
+++ b/sys/src/games/md/ym.c
@@ -35,7 +35,10 @@
u8int st, alg, en, fbs;
float samp;
} fms[6];
+u8int ymstat;
static u32int cyc;
+static u16int tima;
+static u8int timb;
static short sbuf[2 * 2000], *sbufp;
static int fd;
@@ -42,6 +45,32 @@
static int sint[256], expt[256];
static void
+timers(void)
+{
+ u8int m;
+ static u8int bdiv;
+
+ m = ym[0x27];
+ if((m & 1) != 0){
+ tima = (tima + 1) & 0x3ff;
+ if(tima == 0 && (m & 4) != 0){
+ ymstat |= 2;
+ tima = ym[0x24] | ym[0x25] << 8 & 0x300;
+ }
+ }
+ if(++bdiv == 8){
+ bdiv = 0;
+ if((m & 2) != 0){
+ timb++;
+ if(timb == 0 && (m & 8) != 0){
+ ymstat |= 1;
+ timb = ym[0x26];
+ }
+ }
+ }
+}
+
+static void
calcfreq(int n)
{
int i, fr;
@@ -129,6 +158,10 @@
ch = c + (a & 3);
switch(a){
case MODE:
+ if((v & 0x10) != 0)
+ ymstat &= ~2;
+ if((v & 0x20) != 0)
+ ymstat &= ~1;
calcfreq(2);
calcfreq(5);
break;
@@ -359,6 +392,7 @@
if(++ymcyc == 3){
cyc++;
ymcyc = 0;
+ timers();
}
}
ymop = 0;