--- nono/m680x0/testea.cpp 2026/04/29 17:04:28 1.1 +++ nono/m680x0/testea.cpp 2026/04/29 17:05:26 1.1.1.4 @@ -1,17 +1,25 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // -#include "m68030ea.cpp" +#include "mpu680x0.h" -uint16 g_fetch[5]; -int g_fetch_ptr; +class MPU680x0Test : public MPU680x0Device +{ + public: + void test_ea_ix(); + void test_ea_ix2(); +}; + +static uint16 g_fetch[5]; +static int g_fetch_ptr; // ダミーのフェッチルーチン // グローバル変数 g_fetch[] で指定された値を順に返す uint32 -m68030_fetch_16(m68kcpu *cpu) +MPU680x0Device::fetch_2() { uint16 data; @@ -23,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 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, ...) +MPU680x0Device::write_data(busaddr laddr, uint32 data) +{ +} + +void +panic_func(const char *func, const char *fmt, ...) { va_list ap; printf("panic: %s:", func); @@ -53,13 +68,13 @@ panic(const char *func, const char *fmt, abort(); } -m68kcpu *cpu; -int tested; -int failed; +static MPU680x0Test *cpu; +static int tested; +static int failed; // 拡張 EA の全組み合わせを試す網羅テスト void -test_ea_ix() +MPU680x0Test::test_ea_ix() { uint32 ea; struct { @@ -74,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; @@ -109,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); @@ -134,12 +149,12 @@ test_ea_ix() } } -const char *scalestr[] = { +static const char *scalestr[] = { "", "*2", "*4", "*8" }; // 拡張 EA Full format の指定パターンのテストを生成する。 -void +static void make_ea_ix_full(int wl, int scale, int bs, int is, int bdsz, int iis) { uint32 data; @@ -251,7 +266,7 @@ make_ea_ix_full(int wl, int scale, int b } // 拡張 EA 全パターンのテストを生成する。 -void +static void make_ea_ix() { // Brief format @@ -293,7 +308,7 @@ make_ea_ix() // 符号拡張のテスト。 // 符号拡張が起きるのは xn.W, bd.W, od.W の3か所。 void -test_ea_ix2() +MPU680x0Test::test_ea_ix2() { struct { uint16 ext; // 拡張ワード @@ -306,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 @@ -315,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); @@ -340,7 +355,7 @@ main(int ac, char *av[]) // 本当はコンストラクタを呼ぶべきだが、そうすると必要なオブジェクトが // 芋づる式に増えて正しく解決するのは面倒。ここのテストではとりあえず // 存在しててアクセスできればいい程度なのでこれで誤魔化してある。 - cpu = (m68kcpu *)calloc(sizeof(*cpu), 1); + cpu = (MPU680x0Test *)calloc(sizeof(*cpu), 1); // 引数が何かあればテストパターン生成、なければテスト。 // XXX そのうち整備する。 @@ -350,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)