mirror of
https://github.com/rkujawa/rk65c02.git
synced 2024-06-15 05:29:28 +00:00
Simplify ROM loading by providing utility function.
This commit is contained in:
parent
96f955e8c1
commit
ed4b2786b6
|
@ -12,13 +12,10 @@ int main(void)
|
||||||
{
|
{
|
||||||
uint8_t a, b, c;
|
uint8_t a, b, c;
|
||||||
uint8_t min;
|
uint8_t min;
|
||||||
bus_t bus;
|
|
||||||
rk65c02emu_t e;
|
rk65c02emu_t e;
|
||||||
|
|
||||||
bus = bus_init_with_default_devs();
|
e = rk65c02_load_rom("min3.rom", load_addr, NULL);
|
||||||
e = rk65c02_init(&bus);
|
|
||||||
|
|
||||||
bus_load_file(e.bus, load_addr, "min3.rom");
|
|
||||||
|
|
||||||
e.regs.SP = 0xFF;
|
e.regs.SP = 0xFF;
|
||||||
e.regs.PC = load_addr;
|
e.regs.PC = load_addr;
|
||||||
|
@ -29,6 +26,7 @@ int main(void)
|
||||||
stack_push(&e, c);
|
stack_push(&e, c);
|
||||||
|
|
||||||
rk65c02_start(&e);
|
rk65c02_start(&e);
|
||||||
|
|
||||||
min = stack_pop(&e);
|
min = stack_pop(&e);
|
||||||
printf("Min is: %d\n", min);
|
printf("Min is: %d\n", min);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,30 @@
|
||||||
|
|
||||||
void rk65c02_exec(rk65c02emu_t *);
|
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.
|
* Prepare the emulator for use, set initial CPU state.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -84,6 +84,7 @@ void rk65c02_dump_regs(reg_state_t);
|
||||||
void rk65c02_dump_stack(rk65c02emu_t *, uint8_t);
|
void rk65c02_dump_stack(rk65c02emu_t *, uint8_t);
|
||||||
void rk65c02_irq(rk65c02emu_t *);
|
void rk65c02_irq(rk65c02emu_t *);
|
||||||
void rk65c02_panic(rk65c02emu_t *, const char*, ...);
|
void rk65c02_panic(rk65c02emu_t *, const char*, ...);
|
||||||
|
rk65c02emu_t rk65c02_load_rom(const char *, uint16_t, bus_t *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user