ref: 96bb44290d4c7f3d6719cfcb877954c4cedc7976
dir: /sms.c/
#include <u.h>
#include <libc.h>
#include <thread.h>
#include <draw.h>
#include <keyboard.h>
#include "../eui.h"
#include "dat.h"
#include "fns.h"
int t = 0;
u32int r[16];
extern u16int pc, curpc, sp;
u32int irq;
u8int *rom = nil;
u8int *mem = nil;
u8int *pic = nil;
int vdpclock = 0;
int psgclock = 0;
static void
loadrom(char *file)
{
int fd;
fd = open(file, OREAD);
if(fd < 0)
sysfatal("open: %r");
pic = malloc(320 * 224 * 4);
rom = malloc(0x40000);
//memcpy(rom, data, 0x40000);
if(readn(fd, rom, 0x40000) < 0x40000)
sysfatal("read: %r");
mem = malloc(0xC000+0x8000);
memcpy(mem, rom, 0xC000);
pc = 0;
psginit(RATE, PSGCLOCK);
vdpmode();
}
void
usage(void)
{
fprint(2, "usage: %s [-a] [-x scale] rom\n", argv0);
exits("usage");
}
void
process_inputs()
{
/*for(int p = 0; p < 2; p++)
{
keys[p] = 0xff;
for(int id = 0; id < RETRO_DEVICE_ID_JOYPAD_X; id++)
if(input_state_cb(p, RETRO_DEVICE_JOYPAD, 0, id))
keys[p] = keys[p] & ~retro_bind[id];
}
portDC = (keys[0] & 0x3f) + ((keys[1] << 6) & 0xc0);
portDD = ((keys[1] >> 2) & 0x0f) | 0xf0;*/
}
void
threadmain(int argc, char **argv)
{
int t;
ARGBEGIN{
case 'a':
initaudio();
break;
case 'x':
fixscale = strtol(EARGF(usage()), nil, 0);
break;
default:
usage();
} ARGEND;
if(argc < 1)
usage();
loadrom(*argv);
initemu(320, 224, 4, XRGB32, 1, nil);
regkey("a", 'c', 1<<4);
regkey("b", 'x', 1<<5);
regkey("start", '\n', 1<<6);
regkey("up", Kup, 0x0);
regkey("down", Kdown, 1<<1);
regkey("left", Kleft, 1<<2);
regkey("right", Kright, 1<<3);
z80reset();
vdpmode();
//ymreset();
for(;;){
//process_inputs();
t = z80step();
vdpclock -= t * Z80DIV;
//total += t;
while(vdpclock < 0){
vdpstep();
vdpclock += 8;
}
/*if(total > 702240){
flush();
total = 0;
vdpx = 0;
vdpy = 0;
}*/
}
}
void
flush(void)
{
flushmouse(1);
flushscreen();
//flushaudio(audioout);
}