mirror of
https://github.com/pevans/erc-c.git
synced 2024-10-31 13:07:14 +00:00
45eb7b5e58
This also adds tests for those functions. We have, furthermore, removed some redundant (and non-externed!) functions from apple2.mem.c which was the old bank switching code that got moved to apple2.bank.c.
80 lines
2.0 KiB
C
80 lines
2.0 KiB
C
#include <criterion/criterion.h>
|
|
|
|
#include "apple2.h"
|
|
#include "apple2.mem.h"
|
|
#include "apple2.bank.h"
|
|
|
|
static apple2 *mach = NULL;
|
|
|
|
static void
|
|
setup()
|
|
{
|
|
mach = apple2_create(100, 100);
|
|
vm_segment_set_map_machine(mach);
|
|
}
|
|
|
|
static void
|
|
teardown()
|
|
{
|
|
apple2_free(mach);
|
|
vm_segment_set_map_machine(NULL);
|
|
}
|
|
|
|
TestSuite(apple2_mem, .init = setup, .fini = teardown);
|
|
|
|
Test(apple2_mem, map)
|
|
{
|
|
size_t addr;
|
|
int i;
|
|
vm_segment *segments[2];
|
|
|
|
segments[0] = mach->main;
|
|
segments[1] = mach->aux;
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
for (addr = 0x0; addr < 0x200; addr++) {
|
|
cr_assert_eq(segments[i]->read_table[addr], apple2_mem_zp_read);
|
|
cr_assert_eq(segments[i]->write_table[addr], apple2_mem_zp_write);
|
|
}
|
|
}
|
|
}
|
|
|
|
Test(apple2_mem, init_peripheral_rom)
|
|
{
|
|
// FIXME: this isn't working, _and_ it's pretty tightly coupled into
|
|
// the create() function. We could use a better way of testing this.
|
|
//cr_assert_eq(apple2_mem_init_disk2_rom(mach), OK);
|
|
}
|
|
|
|
Test(apple2_mem, init_sys_rom)
|
|
{
|
|
// FIXME: same
|
|
//cr_assert_eq(apple2_mem_init_sys_rom(mach), OK);
|
|
}
|
|
|
|
/*
|
|
* You may notice some direct accesses to the memory field; it's needed
|
|
* to get around the mapper functionality we're trying to test! This
|
|
* test also works on both the read/write mapper functionality.
|
|
*
|
|
* Test(apple2_mem, zp_write)
|
|
*/
|
|
Test(apple2_mem, zp_read)
|
|
{
|
|
apple2_set_bank_switch(mach, BANK_DEFAULT);
|
|
mos6502_set(mach->cpu, 0, 123);
|
|
cr_assert_eq(mach->main->memory[0], 123);
|
|
cr_assert_neq(mach->aux->memory[0], 123);
|
|
|
|
// Once we switch to BANK_ALTZP, we should see that the data in main
|
|
// got copied over. That's tested elsewhere, but I put it here just
|
|
// to make sure you have the right mental model when looking at this
|
|
// test code.
|
|
apple2_set_bank_switch(mach, BANK_ALTZP);
|
|
cr_assert_eq(mach->aux->memory[0], 123);
|
|
|
|
mos6502_set(mach->cpu, 0, 234);
|
|
cr_assert_neq(mach->main->memory[0], 234);
|
|
cr_assert_eq(mach->aux->memory[0], 234);
|
|
}
|