2017-12-06 20:36:14 +00:00
|
|
|
#include <criterion/criterion.h>
|
|
|
|
|
|
|
|
#include "apple2.h"
|
2018-01-07 19:43:09 +00:00
|
|
|
#include "mos6502.enums.h"
|
2017-12-16 04:22:40 +00:00
|
|
|
#include "option.h"
|
2017-12-06 20:36:14 +00:00
|
|
|
|
2017-12-06 21:21:39 +00:00
|
|
|
static apple2 *mach;
|
2017-12-06 20:36:14 +00:00
|
|
|
|
2017-12-06 21:21:39 +00:00
|
|
|
void
|
|
|
|
setup()
|
|
|
|
{
|
2017-12-24 21:07:24 +00:00
|
|
|
mach = apple2_create(700, 480);
|
2017-12-06 21:21:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
teardown()
|
|
|
|
{
|
|
|
|
apple2_free(mach);
|
|
|
|
}
|
|
|
|
|
|
|
|
TestSuite(apple2, .init = setup, .fini = teardown);
|
|
|
|
|
2018-01-07 19:43:09 +00:00
|
|
|
/* Test(apple2, free) */
|
|
|
|
/* Test(apple2, run_loop) */
|
|
|
|
|
2017-12-06 21:21:39 +00:00
|
|
|
Test(apple2, create)
|
|
|
|
{
|
2017-12-06 20:36:14 +00:00
|
|
|
cr_assert_neq(mach, NULL);
|
|
|
|
cr_assert_neq(mach->cpu, NULL);
|
2017-12-16 04:22:40 +00:00
|
|
|
|
|
|
|
cr_assert_neq(mach->drive1, NULL);
|
|
|
|
cr_assert_neq(mach->drive2, NULL);
|
2017-12-06 20:36:14 +00:00
|
|
|
}
|
2017-12-06 21:21:39 +00:00
|
|
|
|
2017-12-26 23:03:32 +00:00
|
|
|
Test(apple2, is_double_video)
|
|
|
|
{
|
|
|
|
for (int i = 0; i <= VIDEO_DOUBLE_HIRES; i++) {
|
|
|
|
mach->video_mode = i;
|
|
|
|
switch (i) {
|
|
|
|
case VIDEO_40COL_TEXT:
|
|
|
|
cr_assert_eq(apple2_is_double_video(mach), false);
|
|
|
|
break;
|
|
|
|
case VIDEO_LORES:
|
|
|
|
cr_assert_eq(apple2_is_double_video(mach), false);
|
|
|
|
break;
|
|
|
|
case VIDEO_HIRES:
|
|
|
|
cr_assert_eq(apple2_is_double_video(mach), false);
|
|
|
|
break;
|
|
|
|
case VIDEO_80COL_TEXT:
|
|
|
|
cr_assert_eq(apple2_is_double_video(mach), true);
|
|
|
|
break;
|
|
|
|
case VIDEO_DOUBLE_LORES:
|
|
|
|
cr_assert_eq(apple2_is_double_video(mach), true);
|
|
|
|
break;
|
|
|
|
case VIDEO_DOUBLE_HIRES:
|
|
|
|
cr_assert_eq(apple2_is_double_video(mach), true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Test(apple2, boot)
|
|
|
|
{
|
|
|
|
// A boot without any disks is technically ok... in full emulation,
|
|
|
|
// you'd just see a screen that prints out something like "Apple
|
|
|
|
// ][e" at the bottom.
|
|
|
|
cr_assert_eq(apple2_boot(mach), OK);
|
|
|
|
|
|
|
|
// And, as you may guess, it's ok to reboot the machine.
|
|
|
|
option_read_file(1, "../data/zero.img");
|
|
|
|
cr_assert_eq(apple2_boot(mach), OK);
|
|
|
|
|
|
|
|
option_read_file(2, "../data/bad.img");
|
|
|
|
cr_assert_neq(apple2_boot(mach), OK);
|
|
|
|
}
|
|
|
|
|
2017-12-06 21:21:39 +00:00
|
|
|
Test(apple2, press_key)
|
|
|
|
{
|
|
|
|
apple2_press_key(mach, 123);
|
|
|
|
cr_assert_eq(vm_segment_get(mach->memory, 0xC000), 123 | 0x80);
|
|
|
|
cr_assert_eq(vm_segment_get(mach->memory, 0xC010), 0x80);
|
|
|
|
}
|
|
|
|
|
|
|
|
Test(apple2, clear_strobe)
|
|
|
|
{
|
|
|
|
apple2_press_key(mach, 123);
|
|
|
|
cr_assert_eq(vm_segment_get(mach->memory, 0xC000), 123 | 0x80);
|
|
|
|
apple2_clear_strobe(mach);
|
|
|
|
cr_assert_eq(vm_segment_get(mach->memory, 0xC000), 123);
|
|
|
|
}
|
|
|
|
|
2017-12-26 23:03:32 +00:00
|
|
|
/*
|
|
|
|
* This also tests the press_key function (as does the clear_strobe
|
|
|
|
* test, in its own way).
|
|
|
|
*/
|
2017-12-06 21:21:39 +00:00
|
|
|
Test(apple2, release_key)
|
|
|
|
{
|
|
|
|
apple2_press_key(mach, 123);
|
|
|
|
cr_assert_eq(vm_segment_get(mach->memory, 0xC010), 0x80);
|
|
|
|
apple2_release_key(mach);
|
|
|
|
cr_assert_eq(vm_segment_get(mach->memory, 0xC010), 0);
|
|
|
|
}
|
2017-12-16 04:22:40 +00:00
|
|
|
|
2017-12-26 23:03:32 +00:00
|
|
|
Test(apple2, set_color)
|
2017-12-16 04:22:40 +00:00
|
|
|
{
|
2017-12-26 23:03:32 +00:00
|
|
|
apple2_set_color(mach, COLOR_AMBER);
|
|
|
|
cr_assert_eq(mach->color_mode, COLOR_AMBER);
|
|
|
|
apple2_set_color(mach, COLOR_FULL);
|
|
|
|
cr_assert_eq(mach->color_mode, COLOR_FULL);
|
|
|
|
}
|
2017-12-16 04:22:40 +00:00
|
|
|
|
2017-12-26 23:03:32 +00:00
|
|
|
Test(apple2, set_video)
|
|
|
|
{
|
|
|
|
apple2_set_video(mach, VIDEO_DOUBLE_HIRES);
|
|
|
|
cr_assert_eq(mach->video_mode, VIDEO_DOUBLE_HIRES);
|
|
|
|
apple2_set_video(mach, VIDEO_LORES);
|
|
|
|
cr_assert_eq(mach->video_mode, VIDEO_LORES);
|
2017-12-16 04:22:40 +00:00
|
|
|
}
|
2018-01-07 19:43:09 +00:00
|
|
|
|
|
|
|
Test(apple2, set_memory)
|
|
|
|
{
|
|
|
|
apple2_set_memory(mach, MEMORY_BANK_RAM1);
|
|
|
|
cr_assert_eq(mach->memory_mode, MEMORY_BANK_RAM1);
|
|
|
|
apple2_set_memory(mach, MEMORY_BANK_RAM2);
|
|
|
|
cr_assert_eq(mach->memory_mode, MEMORY_BANK_RAM2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Test(apple2, reset)
|
|
|
|
{
|
|
|
|
apple2_set_memory(mach, MEMORY_BANK_ROM);
|
2018-01-08 23:10:26 +00:00
|
|
|
vm_segment_set(mach->rom, 0x2FFC, 0x34);
|
|
|
|
vm_segment_set(mach->rom, 0x2FFD, 0x12);
|
2018-01-07 19:43:09 +00:00
|
|
|
apple2_reset(mach);
|
|
|
|
|
|
|
|
cr_assert_eq(mach->cpu->PC, 0x1234);
|
|
|
|
cr_assert_eq(mach->cpu->P, MOS_INTERRUPT);
|
|
|
|
cr_assert_eq(mach->cpu->S, 0);
|
|
|
|
}
|