--- nono/m680x0/testea.cpp 2026/04/29 17:04:34 1.1.1.2 +++ nono/m680x0/testea.cpp 2026/04/29 17:05:26 1.1.1.4 @@ -4,7 +4,14 @@ // Licensed under nono-license.txt // -#include "m68030ea.cpp" +#include "mpu680x0.h" + +class MPU680x0Test : public MPU680x0Device +{ + public: + void test_ea_ix(); + void test_ea_ix2(); +}; static uint16 g_fetch[5]; static int g_fetch_ptr; @@ -12,7 +19,7 @@ static int g_fetch_ptr; // ダミーのフェッチルーチン // グローバル変数 g_fetch[] で指定された値を順に返す uint32 -m68030_fetch_16(m68kcpu *cpu) +MPU680x0Device::fetch_2() { uint16 data; @@ -24,27 +31,34 @@ m68030_fetch_16(m68kcpu *cpu) } uint32 -m68030_fetch_32(m68kcpu *cpu) +MPU680x0Device::fetch_4() { uint32 data; - data = m68030_fetch_16(cpu) << 16; - data |= m68030_fetch_16(cpu); + data = fetch_2() << 16; + data |= fetch_2(); return data; } -uint32 m68030_read_8(m68kcpu *cpu, uint32 ea) { return 0; } -uint32 m68030_read_16(m68kcpu *cpu, uint32 ea) { return 0; } + // ダミーリード // アドレスを2倍にして返す。 // メモリ間接の post index、pre index を演算だけで判別するため。 -uint32 m68030_read_32(m68kcpu *cpu, uint32 ea) { - return ea << 1; +uint32 +MPU680x0Device::read_data(busaddr laddr) +{ + if (laddr.GetSize() == 4) { + return laddr.Addr() << 1; + } + return 0; +} + +void +MPU680x0Device::write_data(busaddr laddr, uint32 data) +{ } -void m68030_write_8(m68kcpu *cpu, uint32 ea, uint32 data) { } -void m68030_write_16(m68kcpu *cpu, uint32 ea, uint32 data) { } -void m68030_write_32(m68kcpu *cpu, uint32 ea, uint32 data) { } + void -panic(const char *func, const char *fmt, ...) +panic_func(const char *func, const char *fmt, ...) { va_list ap; printf("panic: %s:", func); @@ -54,13 +68,13 @@ panic(const char *func, const char *fmt, abort(); } -static m68kcpu *cpu; +static MPU680x0Test *cpu; static int tested; static int failed; // 拡張 EA の全組み合わせを試す網羅テスト -static void -test_ea_ix() +void +MPU680x0Test::test_ea_ix() { uint32 ea; struct { @@ -75,7 +89,7 @@ test_ea_ix() }; uint32 An = 0x00010000; - RegD(1) = 0x00100010; + cpu->reg.D[1] = 0x00100010; for (int i = 0; i < countof(table); i++) { g_fetch_ptr = 0; @@ -110,7 +124,7 @@ test_ea_ix() tested++; printf("test_ea_ix[0x%04x] %-20s ", table[i].ext, table[i].name); - ea = internal_ea_ix(cpu, An); + ea = internal_ea_ix(An); if (table[i].exp_pc != g_fetch_ptr) { printf("FAILED! pc expects %d but %d\n", table[i].exp_pc, g_fetch_ptr); @@ -293,8 +307,8 @@ make_ea_ix() // 符号拡張のテスト。 // 符号拡張が起きるのは xn.W, bd.W, od.W の3か所。 -static void -test_ea_ix2() +void +MPU680x0Test::test_ea_ix2() { struct { uint16 ext; // 拡張ワード @@ -307,7 +321,7 @@ test_ea_ix2() }; uint32 An = 0x00011110; - RegD(1) = 0x0000fff0; // -0x0010.W + cpu->reg.D[1] = 0x0000fff0; // -0x0010.W for (int i = 0; i < countof(table); i++) { g_fetch[0] = table[i].ext; g_fetch[1] = 0xff00; // -0x0100.W @@ -316,7 +330,7 @@ test_ea_ix2() tested++; printf("test_ea_ix2[0x%04x] %-20s ", table[i].ext, table[i].name); - uint32 ea = internal_ea_ix(cpu, An); + uint32 ea = internal_ea_ix(An); if (table[i].exp_ea != ea) { printf("FAILED! ea expects %08x but %08x\n", table[i].exp_ea, ea); @@ -341,7 +355,7 @@ main(int ac, char *av[]) // 本当はコンストラクタを呼ぶべきだが、そうすると必要なオブジェクトが // 芋づる式に増えて正しく解決するのは面倒。ここのテストではとりあえず // 存在しててアクセスできればいい程度なのでこれで誤魔化してある。 - cpu = (m68kcpu *)calloc(sizeof(*cpu), 1); + cpu = (MPU680x0Test *)calloc(sizeof(*cpu), 1); // 引数が何かあればテストパターン生成、なければテスト。 // XXX そのうち整備する。 @@ -351,8 +365,8 @@ main(int ac, char *av[]) tested = 0; failed = 0; - test_ea_ix(); - test_ea_ix2(); + cpu->test_ea_ix(); + cpu->test_ea_ix2(); printf("RESULT: %d tested, %d success", tested, tested - failed); if (failed > 0)