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"
|
2018-03-08 02:25:39 +00:00
|
|
|
#include "vm_di.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)
|
|
|
|
{
|
2018-01-16 22:13:50 +00:00
|
|
|
mach->display_mode = DISPLAY_DEFAULT;
|
|
|
|
cr_assert_eq(apple2_is_double_video(mach), false);
|
|
|
|
mach->display_mode = DISPLAY_DHIRES;
|
|
|
|
cr_assert_eq(apple2_is_double_video(mach), true);
|
2017-12-26 23:03:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2018-03-08 02:25:39 +00:00
|
|
|
FILE *stream1, *stream2;
|
|
|
|
|
2017-12-26 23:03:32 +00:00
|
|
|
// And, as you may guess, it's ok to reboot the machine.
|
2018-03-09 22:45:39 +00:00
|
|
|
option_open_file(&stream1, "../data/zero.img", "r");
|
2018-03-08 02:25:39 +00:00
|
|
|
vm_di_set(VM_DISK1, stream1);
|
|
|
|
|
2017-12-26 23:03:32 +00:00
|
|
|
cr_assert_eq(apple2_boot(mach), OK);
|
|
|
|
|
2018-03-09 22:45:39 +00:00
|
|
|
option_open_file(&stream2, "../data/bad.img", "r");
|
2018-03-08 02:25:39 +00:00
|
|
|
vm_di_set(VM_DISK2, stream2);
|
2017-12-26 23:03:32 +00:00
|
|
|
cr_assert_neq(apple2_boot(mach), OK);
|
2018-03-08 02:25:39 +00:00
|
|
|
|
|
|
|
fclose(stream1);
|
|
|
|
fclose(stream2);
|
|
|
|
|
|
|
|
vm_di_set(VM_DISK1, NULL);
|
|
|
|
vm_di_set(VM_DISK2, NULL);
|
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
|
|
|
|
2018-01-16 22:13:50 +00:00
|
|
|
Test(apple2, set_display)
|
2017-12-26 23:03:32 +00:00
|
|
|
{
|
2018-01-16 22:13:50 +00:00
|
|
|
apple2_set_display(mach, DISPLAY_DHIRES);
|
|
|
|
cr_assert_eq(mach->display_mode, DISPLAY_DHIRES);
|
|
|
|
apple2_set_display(mach, DISPLAY_TEXT);
|
|
|
|
cr_assert_eq(mach->display_mode, DISPLAY_TEXT);
|
2017-12-16 04:22:40 +00:00
|
|
|
}
|
2018-01-07 19:43:09 +00:00
|
|
|
|
2018-01-11 01:59:33 +00:00
|
|
|
Test(apple2, set_bank_switch)
|
2018-01-07 19:43:09 +00:00
|
|
|
{
|
2018-01-11 03:50:43 +00:00
|
|
|
apple2_set_bank_switch(mach, 0);
|
2018-01-11 01:59:33 +00:00
|
|
|
cr_assert_eq(mach->bank_switch, 0);
|
2018-01-13 03:04:21 +00:00
|
|
|
apple2_set_bank_switch(mach, BANK_WRITE | BANK_RAM2);
|
|
|
|
cr_assert_eq(mach->bank_switch, BANK_WRITE | BANK_RAM2);
|
2018-01-12 04:35:23 +00:00
|
|
|
|
|
|
|
mos6502_set(mach->cpu, 0x1, 111);
|
|
|
|
mos6502_set(mach->cpu, 0x101, 222);
|
|
|
|
|
2018-01-13 03:04:21 +00:00
|
|
|
apple2_set_bank_switch(mach, BANK_ALTZP);
|
2018-01-12 04:35:23 +00:00
|
|
|
cr_assert_eq(mos6502_get(mach->cpu, 0x1), 111);
|
|
|
|
cr_assert_eq(mos6502_get(mach->cpu, 0x101), 222);
|
|
|
|
|
|
|
|
mos6502_set(mach->cpu, 0x1, 222);
|
|
|
|
mos6502_set(mach->cpu, 0x101, 101);
|
|
|
|
|
2018-01-13 03:04:21 +00:00
|
|
|
apple2_set_bank_switch(mach, BANK_DEFAULT);
|
2018-01-12 04:35:23 +00:00
|
|
|
cr_assert_eq(mos6502_get(mach->cpu, 0x1), 222);
|
|
|
|
cr_assert_eq(mos6502_get(mach->cpu, 0x101), 101);
|
2018-01-07 19:43:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Test(apple2, reset)
|
|
|
|
{
|
2018-01-16 21:46:35 +00:00
|
|
|
vm_segment_set(mach->rom, 0x3FFC, 0x34);
|
|
|
|
vm_segment_set(mach->rom, 0x3FFD, 0x12);
|
2018-01-07 19:43:09 +00:00
|
|
|
apple2_reset(mach);
|
|
|
|
|
|
|
|
cr_assert_eq(mach->cpu->PC, 0x1234);
|
2018-01-23 22:07:21 +00:00
|
|
|
cr_assert_eq(mach->cpu->P, MOS_STATUS_DEFAULT);
|
|
|
|
cr_assert_eq(mach->cpu->S, 0xff);
|
2018-01-07 19:43:09 +00:00
|
|
|
}
|
2018-01-13 06:38:29 +00:00
|
|
|
|
|
|
|
Test(apple2, set_memory_mode)
|
|
|
|
{
|
|
|
|
apple2_set_memory_mode(mach, MEMORY_READ_AUX);
|
|
|
|
cr_assert_eq(mach->memory_mode, MEMORY_READ_AUX);
|
|
|
|
cr_assert_eq(mach->cpu->rmem, mach->aux);
|
|
|
|
cr_assert_eq(mach->cpu->wmem, mach->main);
|
|
|
|
|
|
|
|
apple2_set_memory_mode(mach, MEMORY_WRITE_AUX);
|
|
|
|
cr_assert_eq(mach->memory_mode, MEMORY_WRITE_AUX);
|
|
|
|
cr_assert_eq(mach->cpu->rmem, mach->main);
|
|
|
|
cr_assert_eq(mach->cpu->wmem, mach->aux);
|
|
|
|
}
|
2018-03-07 23:06:50 +00:00
|
|
|
|
|
|
|
Test(apple2, notify_refresh)
|
|
|
|
{
|
|
|
|
cr_assert_eq(mach->screen->dirty, false);
|
|
|
|
apple2_notify_refresh(mach);
|
|
|
|
cr_assert_eq(mach->screen->dirty, true);
|
|
|
|
}
|