mirror of
https://github.com/RyuKojiro/apple1.git
synced 2024-12-22 04:30:05 +00:00
Added code to load and mirror the ROM
git-svn-id: svn+ssh://svn.phoenixbox.net/svn/apple1/trunk@4 64f78de7-aa59-e511-a0e8-0002a5492df0
This commit is contained in:
parent
ac87480ce8
commit
622d6aca9c
@ -8,11 +8,40 @@
|
|||||||
|
|
||||||
#include <v6502/cpu.h>
|
#include <v6502/cpu.h>
|
||||||
#include <v6502/mem.h>
|
#include <v6502/mem.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define ROM_START 0xF000
|
||||||
|
#define ROM_SIZE 0x00FF
|
||||||
|
|
||||||
void fault(void *ctx, const char *e) {
|
void fault(void *ctx, const char *e) {
|
||||||
(*(int *)ctx)++;
|
(*(int *)ctx)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void loadRomFile(v6502_memory *mem, const char *fname, uint16_t address) {
|
||||||
|
FILE *f = fopen(fname, "r");
|
||||||
|
|
||||||
|
if (!f) {
|
||||||
|
fprintf(stderr, "Could not read from \"%s\"!\n", fname);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t byte;
|
||||||
|
uint16_t offset = 0;
|
||||||
|
|
||||||
|
while (fread(&byte, 1, 1, f)) {
|
||||||
|
mem->bytes[address + (offset++)] = byte;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Loaded %u bytes at 0x%x.\n", offset, address);
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t romMirrorCallback(struct _v6502_memory *memory, uint16_t offset, int trap, void *context) {
|
||||||
|
return memory->bytes[offset % ROM_SIZE];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, const char * argv[])
|
int main(int argc, const char * argv[])
|
||||||
{
|
{
|
||||||
int faulted = 0;
|
int faulted = 0;
|
||||||
@ -22,6 +51,14 @@ int main(int argc, const char * argv[])
|
|||||||
cpu->fault_callback = fault;
|
cpu->fault_callback = fault;
|
||||||
cpu->fault_context = &faulted;
|
cpu->fault_context = &faulted;
|
||||||
|
|
||||||
|
// Load Woz Monitor
|
||||||
|
loadRomFile(cpu->memory, "apple1.rom", ROM_START);
|
||||||
|
for (uint16_t start = ROM_START + ROM_SIZE + 1;
|
||||||
|
start < v6502_memoryStartCeiling && start > ROM_START;
|
||||||
|
start += ROM_SIZE + 1) {
|
||||||
|
v6502_map(cpu->memory, start, ROM_SIZE, romMirrorCallback, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
v6502_reset(cpu);
|
v6502_reset(cpu);
|
||||||
|
|
||||||
while (!faulted) {
|
while (!faulted) {
|
||||||
|
Loading…
Reference in New Issue
Block a user