diff --git a/include/apple2.tests.h b/include/apple2.tests.h new file mode 100644 index 0000000..cbc89be --- /dev/null +++ b/include/apple2.tests.h @@ -0,0 +1,23 @@ +#ifndef _APPLE2_TESTS_H_ +#define _APPLE2_TESTS_H_ + +#include "apple2.h" +#include "vm_segment.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); +} + +#endif diff --git a/tests/apple2.kb.c b/tests/apple2.kb.c index e69de29..459bf4e 100644 --- a/tests/apple2.kb.c +++ b/tests/apple2.kb.c @@ -0,0 +1,38 @@ +#include + +#include "apple2.kb.h" +#include "apple2.tests.h" + +TestSuite(apple2_kb, .init = setup, .fini = teardown); + +Test(apple2_kb, map) +{ + int i; + vm_segment *segments[2]; + + segments[0] = mach->main; + segments[1] = mach->aux; + + for (i = 0; i < 2; i++) { + cr_assert_eq(segments[i]->read_table[0xC000], apple2_kb_switch_read); + cr_assert_eq(segments[i]->read_table[0xC010], apple2_kb_switch_read); + } +} + +Test(apple2_kb, switch_read) +{ + // Without strobe + mach->screen->last_key = 'a'; + cr_assert_eq(vm_segment_get(mach->main, 0xC000), 'a'); + + // With strobe + mach->strobe = true; + cr_assert_eq(vm_segment_get(mach->main, 0xC000), 'a' | 0x80); + + mach->screen->key_pressed = true; + cr_assert_eq(vm_segment_get(mach->main, 0xC010), 0x80); + cr_assert_eq(mach->strobe, false); + + mach->screen->key_pressed = false; + cr_assert_eq(vm_segment_get(mach->main, 0xC010), 0x00); +}