1
0
mirror of https://github.com/rkujawa/rk65c02.git synced 2024-12-04 19:50:19 +00:00

Simplify ROM loading by providing utility function.

This commit is contained in:
Radosław Kujawa 2018-04-10 10:12:27 +02:00
parent 96f955e8c1
commit ed4b2786b6
3 changed files with 28 additions and 5 deletions

View File

@ -12,13 +12,10 @@ int main(void)
{
uint8_t a, b, c;
uint8_t min;
bus_t bus;
rk65c02emu_t e;
bus = bus_init_with_default_devs();
e = rk65c02_init(&bus);
bus_load_file(e.bus, load_addr, "min3.rom");
e = rk65c02_load_rom("min3.rom", load_addr, NULL);
e.regs.SP = 0xFF;
e.regs.PC = load_addr;
@ -29,6 +26,7 @@ int main(void)
stack_push(&e, c);
rk65c02_start(&e);
min = stack_pop(&e);
printf("Min is: %d\n", min);
}

View File

@ -18,6 +18,30 @@
void rk65c02_exec(rk65c02emu_t *);
/**
* \brief Prep the emulator, load code from file, pass bus config optionally.
* \param path Path to ROM file to be loaded.
* \param load_addr Address on the bus where ROM should be loaded.
* \param b Pre-existing bus configuration, pass NULL if default requested.
*/
rk65c02emu_t
rk65c02_load_rom(const char *path, uint16_t load_addr, bus_t *b)
{
rk65c02emu_t e;
if (b == NULL) {
b = GC_MALLOC(sizeof(bus_t));
*b = bus_init_with_default_devs();
}
/* XXX: normal error handling instead of assert would be preferred */
assert(bus_load_file(b, load_addr, path));
e = rk65c02_init(b);
return e;
}
/*
* Prepare the emulator for use, set initial CPU state.
*/

View File

@ -84,6 +84,7 @@ void rk65c02_dump_regs(reg_state_t);
void rk65c02_dump_stack(rk65c02emu_t *, uint8_t);
void rk65c02_irq(rk65c02emu_t *);
void rk65c02_panic(rk65c02emu_t *, const char*, ...);
rk65c02emu_t rk65c02_load_rom(const char *, uint16_t, bus_t *);
#endif