Emulator: load ROM into memory
This commit is contained in:
parent
6778f54f11
commit
4bf29638ca
@ -1,12 +1,14 @@
|
||||
#include <Z/constants/pointer.h> /* Z_NULL */
|
||||
#include <Z80.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define CYCLES_PER_FRAME 69888
|
||||
#define CYCLES_AT_INT 24
|
||||
#define CYCLES_PER_INT 32
|
||||
#define ROM_SIZE 0x8000 /* 32 KiB */
|
||||
#define MEMORY_SIZE 0x8000 /* 32 KiB */
|
||||
#define MEMORY_SIZE 0xFFFF /* 64 KiB */
|
||||
|
||||
typedef struct {
|
||||
void* context;
|
||||
@ -108,29 +110,50 @@ void machine_reset(Machine *self)
|
||||
z80_instant_reset(&self->cpu);
|
||||
}
|
||||
|
||||
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);
|
||||
// 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 after the INT signal */
|
||||
self->cycles += z80_execute(&self->cpu, CYCLES_PER_FRAME - 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);
|
||||
|
||||
self->cycles -= CYCLES_PER_FRAME;
|
||||
// /* CPU cycles after the INT signal */
|
||||
// self->cycles += z80_execute(&self->cpu, CYCLES_PER_FRAME - self->cycles);
|
||||
|
||||
// self->cycles -= CYCLES_PER_FRAME;
|
||||
// }
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// Parse arguments
|
||||
if (argc < 2) {
|
||||
printf("Usage: %s [romFile]\n", argv[0]);
|
||||
exit(0);
|
||||
}
|
||||
char* romFilePath = argv[1];
|
||||
|
||||
int main() {
|
||||
// Setup virtual Pat80 computer
|
||||
Z80 pat80Cpu = {};
|
||||
Device pat80Devices[] = {};
|
||||
zuint8 pat80Memory[65536] = {0};
|
||||
|
||||
// Load ROM into memory
|
||||
FILE *romFile;
|
||||
romFile = fopen(romFilePath,"rb");
|
||||
if (romFile == NULL) {
|
||||
printf("Unable to open rom file at %s", romFilePath);
|
||||
exit(1);
|
||||
}
|
||||
fread(pat80Memory,ROM_SIZE,1,romFile); // load rom from file into memory, up to ROM_SIZE
|
||||
fclose(romFile);
|
||||
|
||||
Machine pat80 = {
|
||||
/*zusize*/ .cycles = 0,
|
||||
/*zuint8*/ .memory = *pat80Memory,
|
||||
@ -142,4 +165,5 @@ int main() {
|
||||
machine_initialize(&pat80);
|
||||
machine_power(&pat80, Z_TRUE);
|
||||
machine_reset(&pat80);
|
||||
machine_run(&pat80);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user