diff --git a/pat80-emulator/main.c b/pat80-emulator/main.c index b40abf4..901103c 100644 --- a/pat80-emulator/main.c +++ b/pat80-emulator/main.c @@ -1,12 +1,15 @@ +/** + * PAT80 Emulator + * + * Emulates a PAT80. + */ + #include /* Z_NULL */ #include #include #include #include -#define CYCLES_PER_FRAME 69888 -#define CYCLES_AT_INT 24 -#define CYCLES_PER_INT 32 #define ROM_SIZE 0x8000 /* 32 KiB */ #define MEMORY_SIZE 0xFFFF /* 64 KiB */ @@ -20,8 +23,6 @@ typedef struct { zusize cycles; zuint8 memory[65536]; Z80 cpu; - Device* devices; - zusize device_count; } Machine; @@ -145,8 +146,6 @@ void machine_initialize(Machine *self) { self->cpu.hook = Z_NULL; self->cpu.illegal = Z_NULL; self->cpu.options = Z80_MODEL_ZILOG_NMOS; - - /* Create and initialize devices... */ } @@ -169,47 +168,6 @@ void machine_run(Machine *self) { z80_run(&self->cpu, Z80_MAXIMUM_CYCLES); } - -// void machine_run_frame(Machine *self) -// { -// /* CPU cycles before the INT signal */ -// self->cycles += z80_execute(&self->cpu, CYCLES_AT_INT - self->cycles); - -// /* CPU cycles during the INT signal */ -// z80_int(&self->cpu, Z_TRUE); -// self->cycles += z80_run(&self->cpu, (CYCLES_AT_INT + CYCLES_PER_INT) - self->cycles); -// z80_int(&self->cpu, Z_FALSE); - -// /* CPU cycles after the INT signal */ -// self->cycles += z80_execute(&self->cpu, CYCLES_PER_FRAME - self->cycles); - -// self->cycles -= CYCLES_PER_FRAME; -// } - - - - -// TEST IMPLEM DEVICE - -zuint8 device_terminal_read(void *context) { - return 'H'; - //return 0; -} - -void device_terminal_write(void *context, zuint8 value) { - printf("%c", value); -} - -zuint8 device_sound_read(void *context) { - return 0; -} - -void device_sound_write(void *context, zuint8 value) { - printf("sound[%c]\n", value); -} - -// TEST IMPLEM DEVICE - int main(int argc, char *argv[]) { // Parse arguments if (argc < 2) { @@ -221,7 +179,7 @@ int main(int argc, char *argv[]) { // Setup virtual Pat80 computer Z80 pat80Cpu = {}; Machine pat80 = { - /*zusize*/ .cycles = 100000, + /*zusize*/ .cycles = 0, /*Z80*/ .cpu = pat80Cpu }; @@ -238,23 +196,6 @@ int main(int argc, char *argv[]) { fread(&pat80.memory,ROM_SIZE,1,romFile); // load rom from file into memory, up > fclose(romFile); - // Declare system devices - Device patoTerminal = { - .read = *device_terminal_read, - .write = *device_terminal_write, - }; - Device patoSound = { - .read = *device_sound_read, - .write = *device_sound_write, - }; - - Device patoDevices[2] = { - patoTerminal, // Port 0 (0x00 to 0x1F) - patoSound // Port 1 (0x20 to 0x3F) - }; - pat80.devices = patoDevices; - pat80.device_count = 2; - machine_reset(&pat80); machine_run(&pat80); }