#include #include #include <6502.h> #include #include "util.h" #define RESULT_COUNT 6 #define TEST_COUNT 6 extern void run_tests(void); static void init(void); static void paint_results(void); static void paint_debug_results(void); static void loop_forever(void); extern volatile uint8_t g_results[RESULT_COUNT]; static const expected_result_t k_expected_results[RESULT_COUNT] = { EXPECT(0x35), EXPECT(0x41), EXPECT(0x69), EXPECT(0x81), EXPECT(0x74, 0x75), EXPECT(0x81), }; static const uint8_t k_test_offsets[TEST_COUNT] = { 0, 1, 2, 3, 4, 5 }; static const uint8_t k_test_counts[TEST_COUNT] = { 1, 1, 1, 1, 1, 1 }; static const char* k_test_names[TEST_COUNT] = { "NOP PM ON", "NOP PM OFF", "LDX PM ON", "LDX PM OFF", "MEM PM ON", "MEM PM OFF" }; void main(void) { run_tests(); init(); paint_results(); paint_debug_results(); loop_forever(); } static void init(void) { tgi_install(tgi_static_stddrv); tgi_init(); CLI(); while (tgi_busy()) { } tgi_clear(); } static void paint_results(void) { char buf[4]; int t; int y = 9; int x = 9; int x_result = 9 * 12; for (t = 0; t < TEST_COUNT; ++t) { uint8_t off = k_test_offsets[t]; uint8_t cnt = k_test_counts[t]; int pass = 1; int fail_index = -1; int i; for (i = 0; i < cnt; ++i) { if (!is_valid_result(g_results[off + i], &k_expected_results[off + i])) { pass = 0; fail_index = i; break; } } tgi_setcolor(COLOR_YELLOW); tgi_outtextxy(x, y, k_test_names[t]); if (pass) { tgi_setcolor(COLOR_LIGHTGREEN); tgi_outtextxy(x + x_result, y, "PASS"); } else { tgi_setcolor(COLOR_RED); if (fail_index + 1 >= 10) { buf[0] = '0' + ((fail_index + 1) / 10); buf[1] = '0' + ((fail_index + 1) % 10); buf[2] = 0; } else { buf[0] = '0' + (fail_index + 1); buf[1] = 0; } tgi_outtextxy(x + x_result, y, buf); } y += 9; } } static void paint_debug_results(void) { char buf[4]; int i; int y = 9 * 9; int x = 0; tgi_setcolor(COLOR_WHITE); for (i = 0; i < RESULT_COUNT; ++i) { hex2(buf, g_results[i]); tgi_outtextxy(x, y, buf); x += 18; if ((i + 1) % 9 == 0) { y += 9; x = 0; } } } static void loop_forever(void) { tgi_updatedisplay(); for (;;) ; }