From 15ac1a8086971cb500bd09dd97bf62e111c2be90 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Tue, 13 Sep 2016 04:49:13 -0400 Subject: pokey emulation, plus more labels --- pokeytest/playsnd.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 pokeytest/playsnd.c (limited to 'pokeytest/playsnd.c') diff --git a/pokeytest/playsnd.c b/pokeytest/playsnd.c new file mode 100644 index 0000000..0f76879 --- /dev/null +++ b/pokeytest/playsnd.c @@ -0,0 +1,114 @@ +#include +#include + +#include "pokey.h" + +#define ROM_FILE "../jumpmanjr.rom" +#define ROM_SIZE 0x4000 + +#define PAL_BUF_SIZE 882 +#define NTSC_BUF_SIZE 735 + +unsigned char sndbuf[PAL_BUF_SIZE + 1]; + +unsigned char rom[ROM_SIZE]; + +void usage(void) { + fprintf(stderr, "usage: playsnd [-p] 0xaddr\n"); + exit(1); +} + +void load_rom(void) { + int size; + FILE *f; + + f = fopen(ROM_FILE, "rb"); + if(!f) { + perror(ROM_FILE); + usage(); + } + + size = fread(rom, 1, ROM_SIZE, f); + if(size != ROM_SIZE) { + fprintf(stderr, "file %s should be %d bytes long, not %d\n", + ROM_FILE, ROM_SIZE, size); + usage(); + } + + fprintf(stderr, "loaded ROM %s, %d bytes\n", ROM_FILE, size); +} + +void play_frames(unsigned char count, int buf_size) { + fprintf(stderr, "playing for %d frames\n", count); + while(count--) { + Pokey_process(sndbuf, buf_size); + fwrite(sndbuf, buf_size, 1, stdout); + } +} + +void play_sfx(int addr, int buf_size) { + unsigned char *p = rom + (addr - 0x8000); + + while(1) { + fprintf(stderr, "$%04lx: $%02x\n", (p - rom + 0x8000), *p); + switch(*p) { + case 0: + fprintf(stderr, "opcode 0 (snd_end)\n"); + return; + case 1: + fprintf(stderr, "opcode 1 (snd_audc)\n"); + Update_pokey_sound(audc1, *++p); + play_frames(*++p, buf_size); + ++p; + break; + case 2: + fprintf(stderr, "opcode 2 (snd_jump)\n"); + addr = *++p; + addr |= ( (*++p) << 8); + addr -= 0x8000; + p = rom + addr; + break; + case 3: + fprintf(stderr, "opcode 3 (snd_rest)\n"); + Update_pokey_sound(audc1, 0); + play_frames(*++p, buf_size); + ++p; + break; + default: + fprintf(stderr, "opcode $%02x (snd_note)\n", *p); + Update_pokey_sound(audf1, *p); + play_frames(*++p, buf_size); + ++p; + break; + } + } +} + +int main(int argc, char **argv) { + int buf_size = NTSC_BUF_SIZE; + int addr; + + if(argc < 2 || argc > 3) usage(); + + if(argc == 3) { + buf_size = PAL_BUF_SIZE; + addr = (int)strtol(argv[2], 0, 0); + } else { + addr = (int)strtol(argv[1], 0, 0); + } + + if(addr < 0x8000 || addr > 0xbfff) { + fprintf(stderr, "invalid address, must be 0x8fff thru 0xbfff\n"); + usage(); + } + + load_rom(); + + fprintf(stderr, "playing sfx at $%04x, buf_size %d\n", addr, buf_size); + + Pokey_sound_init(FREQ_17_APPROX, 44100); + play_sfx(addr, buf_size); + + return(0); +} + -- cgit v1.2.3