// ____________________________ // ██▀▀█▀▀██▀▀▀▀▀▀▀█▀▀█ │ ▄▄▄ ▄▄ // ██ ▀ █▄ ▀██▄ ▀ ▄█ ▄▀▀ █ │ ▀█▄ ▄▀██ ▄█▄█ ██▀▄ ██ ▄███ // █ █ █ ▀▀ ▄█ █ █ ▀▄█ █▄ │ ▄▄█▀ ▀▄██ ██ █ ██▀ ▀█▄ ▀█▄▄ // ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀────────┘ ▀▀ // VRAM access timing sample //───────────────────────────────────────────────────────────────────────────── //============================================================================= // INCLUDES //============================================================================= #include "msxgl.h" #include "vdp_reg.h" #include "game/menu.h" #include "fsm.h" #include "test.h" #include "ascii.h" //============================================================================= // DEFINES //============================================================================= //----------------------------------------------------------------------------- // Configuration //----------------------------------------------------------------------------- #define APP_VERSION "1.9" // Version #define TEST_COUNT 128 // VRAM access counter #define REG_EDIT_NUM 10 // Size of the register-edit table // Characters #define CHAR_CTRL 0x09 // Control character #define CHAR_TEST 0x0A // Test character // Working RAM address #define RAM_BUFFER 0xD000 // RAM data buffer address (256 bytes: 0xD000~0xD1FF) #define RAM_FUNC 0xD800 // RAM function address // VRAM address #define ADDR_PNT 0x0000 // Pattern Names Table #define ADDR_PGT 0x0800 // Pattern Generator Table #define ADDR_PCT 0x2000 // Pattern Color Table #define ADDR_SAT 0x1A00 // Sprite Attribute Table #define ADDR_SPT 0x3800 // Sprite Pattern Table #define ADDR_SCT 0x1800 // Sprite Color Table (ADDR_SAT - 0x200) #define ADDR_TEST 0x2000 // Write test VRAM address (1024) //----------------------------------------------------------------------------- // Defines and enums //----------------------------------------------------------------------------- // Library's logo #define MSX_GL "\x01\x02\x03\x04\x05\x06" // Register edit types enum REG_EDIT { REG_EDIT_SET, REG_EDIT_AND, REG_EDIT_OR, //------------------------- REG_EDIT_MAX, }; // Register edit selection actions enum REG_ACTION { REG_ACTION_BIT0, REG_ACTION_BIT1, REG_ACTION_BIT2, REG_ACTION_BIT3, REG_ACTION_BIT4, REG_ACTION_BIT5, REG_ACTION_BIT6, REG_ACTION_BIT7, REG_ACTION_INDEX, REG_ACTION_ACTIVE, REG_ACTION_TYPE, REG_ACTION_REGISTER, REG_ACTION_CLEAR, //------------------------- REG_ACTION_MAX, }; // Menu pages ID enum MENU_IDS { MENU_MAIN = 0, MENU_OPTIONS, MENU_MODES, MENU_TIMINGS, MENU_REGISTERS, //------------------------- MENU_MAX, }; // Command execussion method enum CMD_OPTION { CMD_OFF = 0, CMD_OVERLAP, CMD_SEPERATE, //------------------------- CMD_MAX, }; // VRAM access modes enum ACCESS_MODE { ACCESS_DIRECT = 0, // Direct access to VRAM ACCESS_HMMC, // Indirect access using HMMC command ACCESS_LMMC, // Indirect access using LMMC command //------------------------- ACCESS_MAX, }; // Screen modes enum SCREEN_MODE { MODE_SCREEN0_W40, MODE_SCREEN1, MODE_SCREEN2, MODE_SCREEN3, MODE_SCREEN0_W80, MODE_SCREEN4, MODE_SCREEN5, MODE_SCREEN6, MODE_SCREEN7, MODE_SCREEN8, MODE_SCREEN10, MODE_SCREEN12, //------------------------- MODE_MAX, }; // Target specific macros #if (TARGET_TYPE == TYPE_ROM) #define MAIN() void main() #define LOOP() while (1) #define EXIT() return; #elif (TARGET == TARGET_DOS2) #define MAIN() u8 main(u8 argc, const c8** argv) #define LOOP() while (!Keyboard_IsKeyPressed(KEY_ESC)) #define EXIT() Bios_Exit(0); return 0; #else #define MAIN() void main() #define LOOP() while (!Keyboard_IsKeyPressed(KEY_ESC)) #define EXIT() Bios_Exit(0); #endif //----------------------------------------------------------------------------- // Types and structures //----------------------------------------------------------------------------- // Test function callback typedef void (*cbTest)(u8); // Timing test function information struct TestTime { cbTest FunctionDir; // Test function pointer for direct access cbTest FunctionCmd; // Test function pointer for indirect access through VDP command u8 Time; // I/O access interval u16* Size; // Test function size const c8* Text; // Description }; // Screen mode information struct ScreenMode { const c8* Code; const c8* Scr; const c8* Text; u8 Mode; u16 DY; u16 NX; }; // Register edit information struct RegisterEdit { bool Active; u8 Type; u8 Number; u8 Value; }; //----------------------------------------------------------------------------- // Functions prototype //----------------------------------------------------------------------------- // Menu functions prototypes const c8* MenuAction_Mode(u8 op, i8 value); const c8* MenuAction_Time(u8 op, i8 value); const c8* MenuAction_Count(u8 op, i8 value); const c8* MenuAction_Test(u8 op, i8 value); const c8* MenuAction_Reg(u8 op, i8 value); const c8* MenuAction_Name(u8 op, i8 value); const c8* MenuAction_Sprite(u8 op, i8 value); const c8* MenuAction_Command(u8 op, i8 value); const c8* MenuAction_Access(u8 op, i8 value); void MenuInit_Main(); void MenuInit_Sub(); // State functions prototypes void State_Menu_Begin(); void State_Menu_Update(); void State_Report_Begin(); void State_Report_Update(); // Reset report result u8 Test(u8 mode, u8 time); void TestAll(); void ResetReport(); extern u16 Test_12_length; extern u16 Test_14_length; extern u16 Test_17_length; extern u16 Test_18_length; extern u16 Test_19_length; extern u16 Test_20_length; extern u16 Test_21_length; extern u16 Test_22_length; extern u16 Test_23_length; extern u16 Test_24_length; extern u16 Test_25_length; extern u16 Test_26_length; extern u16 Test_27_length; extern u16 Test_28_length; extern u16 Test_29_length; extern u16 Test_30_length; //============================================================================= // READ-ONLY DATA //============================================================================= // Fonts data #include "font/font_mgl_sample6.h" // Test speed const struct TestTime g_Time[] = { { Test_12, TestCmd_12, 12, &Test_12_length, "12: out(n),a" }, { Test_14, TestCmd_14, 14, &Test_14_length, "14: out(c),a" }, { Test_17, TestCmd_17, 17, &Test_17_length, "17: out(n),a; nop" }, { Test_18, TestCmd_18, 18, &Test_18_length, "18: outi" }, { Test_19, TestCmd_19, 19, &Test_19_length, "19: out(c),a; nop" }, { Test_20, TestCmd_20, 20, &Test_20_length, "20: out(n),a; cp(hl)" }, { Test_21, TestCmd_21, 21, &Test_21_length, "21: out(c),a; inc de" }, { Test_22, TestCmd_22, 22, &Test_22_length, "22: out(c),a; cp(hl)" }, { Test_23, TestCmd_23, 23, &Test_23_length, "23: otir" }, { Test_24, TestCmd_24, 24, &Test_24_length, "24: out(n),a; inc(hl)" }, { Test_25, TestCmd_25, 25, &Test_25_length, "25: outi; inc de" }, { Test_26, TestCmd_26, 26, &Test_26_length, "26: out(n),a; djnz" }, { Test_27, TestCmd_27, 27, &Test_27_length, "27: out(n),a;cp(hl);inc de" }, { Test_28, TestCmd_28, 28, &Test_28_length, "28: out(n),a; cp(hl) x 2" }, { Test_29, TestCmd_29, 29, &Test_29_length, "29: outi; ld i,a" }, { Test_29, TestCmd_29, 30, &Test_30_length, "30: out(c),a; cp(hl) x 2" }, }; // Screen modes const struct ScreenMode g_Mode[MODE_MAX] = { { " T1", "Sc0", "SC0: Text mode 1 (W40)", VDP_MODE_TEXT1, 0, 0 }, { " G1", "Sc1", "SC1: Graphic mode 1", VDP_MODE_GRAPHIC1, 0, 0 }, { " G2", "Sc2", "SC2: Graphic mode 2", VDP_MODE_GRAPHIC2, 0, 0 }, { " MC", "Sc3", "SC3: Multi-color mode", VDP_MODE_MULTICOLOR, 0, 0 }, { " T2", "W80", "SC0: Text mode 2 (W80)", VDP_MODE_TEXT2, 0, 0 }, { " G3", "Sc4", "SC4: Graphic mode 3", VDP_MODE_GRAPHIC3, 0, 0 }, { " G4", "Sc5", "SC5: Graphic mode 4", VDP_MODE_GRAPHIC4, 64, TEST_COUNT * 2 }, { " G5", "Sc6", "SC6: Graphic mode 5", VDP_MODE_GRAPHIC5, 64, TEST_COUNT * 4 }, { " G6", "Sc7", "SC7: Graphic mode 6", VDP_MODE_GRAPHIC6, 32, TEST_COUNT * 2 }, { " G7", "Sc8", "SC8: Graphic mode 7", VDP_MODE_GRAPHIC7, 32, TEST_COUNT }, { "YAE", "S10", "SC10: GM7 + YJK + YAE", VDP_MODE_SCREEN10, 32, TEST_COUNT }, { "YJK", "S12", "SC12: GM7 + YJK", VDP_MODE_SCREEN12, 32, TEST_COUNT }, }; // Menu main page const MenuItem g_MenuMain[] = { { "Mode", MENU_ITEM_ACTION, MenuAction_Mode, 0 }, { "Timing", MENU_ITEM_ACTION, MenuAction_Time, 0 }, { "Count", MENU_ITEM_ACTION, MenuAction_Count, 0 }, { "Options>", MENU_ITEM_GOTO, NULL, MENU_OPTIONS }, { NULL, MENU_ITEM_EMPTY, NULL, 0 }, { "Test", MENU_ITEM_ACTION, MenuAction_Test, 0 }, { "Test All", MENU_ITEM_ACTION, MenuAction_Test, 1 }, { "Report", MENU_ITEM_ACTION, MenuAction_Test, 2 }, { "Reset", MENU_ITEM_ACTION, MenuAction_Test, 3 }, }; // Options menu const MenuItem g_MenuOption[] = { { "Name", MENU_ITEM_ACTION, MenuAction_Name, 0 }, { "Modes>", MENU_ITEM_GOTO, NULL, MENU_MODES }, { "Timings>", MENU_ITEM_GOTO, NULL, MENU_TIMINGS }, { "Screen", MENU_ITEM_BOOL, &g_DisplayScreen, 0 }, { "Sprite", MENU_ITEM_ACTION, MenuAction_Sprite, 0 }, { "Access", MENU_ITEM_ACTION, MenuAction_Access, 0 }, { "Command", MENU_ITEM_ACTION, MenuAction_Command, 0 }, { "Quick", MENU_ITEM_BOOL, &g_QuickMode, 0 }, { "V-Synch", MENU_ITEM_BOOL, &g_WaitVSynch, 0 }, { "From RAM", MENU_ITEM_BOOL, &g_FromRAM, 0 }, { "Waits TS", MENU_ITEM_INT, &g_TimeOffset, 0 }, { "Register>", MENU_ITEM_GOTO, NULL, MENU_REGISTERS }, { NULL, MENU_ITEM_EMPTY, NULL, 0 }, { "Active) return; switch (reg->Type) { case REG_EDIT_SET: VDP_RegWriteBak(reg->Number, reg->Value); break; case REG_EDIT_AND: { u8 value = g_VDP_REGSAV[reg->Number]; value &= reg->Value; VDP_RegWriteBak(reg->Number, value); break; } case REG_EDIT_OR: { u8 value = g_VDP_REGSAV[reg->Number]; value |= reg->Value; VDP_RegWriteBak(reg->Number, value); break; } } } //----------------------------------------------------------------------------- // Get MSX version const c8* GetMSXVersion(u8 ver) { switch (ver) { case 0: // MSX 1 return "TMS9918"; case 1: // MSX 2 return "V9938"; case 2: // MSX 2+ case 3: // MSX turbo R return "V9958"; } return "Unknow"; } //----------------------------------------------------------------------------- // Get VDP version const c8* GetVDPVersion() { switch (g_VDP) { case VDP_VERSION_TMS9918A: return "TMS9918"; case VDP_VERSION_V9938: return "V9938"; case VDP_VERSION_V9958: return "V9958"; } return "Unknow"; } //----------------------------------------------------------------------------- // Get access name const c8* GetAccessName(u8 access) { switch (access) { case ACCESS_DIRECT: return "Direct"; case ACCESS_HMMC: return "HMMC"; case ACCESS_LMMC: return "LMMC"; } return "XXXX"; } //----------------------------------------------------------------------------- // Get next character from user c8 GetCharacter() __NAKED { __asm push ix ld ix, #R_CHGET ld iy, #0x0000 call R_CALSLT pop ix ret __endasm; } //----------------------------------------------------------------------------- // Test a given screen mode with a given test function const c8* GetStringAt(u8 x, u8 y) { Print_SetPosition(x, y); c8* ptr = g_NameBuffer; c8 chr = 0; while (chr != ASCII_RETURN) { chr = GetCharacter(); if ((chr == ASCII_BS) && (ptr > g_NameBuffer)) { Print_Backspace(1); ptr--; } if ((chr == ASCII_SPACE) && (ptr == g_NameBuffer)) continue; if ((chr >= ASCII_SPACE) && (chr <= '~')) { Print_DrawChar(chr); *ptr = chr; ptr++; } } *ptr = 0; return g_NameBuffer; } //----------------------------------------------------------------------------- // Test all screen mode and test function void TestAll() { ResetReport(); for (u8 m = 0; m < g_ModeNum; ++m) { // Filter screen modes // if ((g_Access == ACCESS_LMMC) && (m < MODE_SCREEN8)) // Only valid for GM7 // continue; // else if ((g_Access == ACCESS_HMMC) && (m < MODE_SCREEN5)) // Only valid for bitmap modes // continue; if (!g_SelectModes[m]) continue; for (u8 t = 0; t < numberof(g_Time); ++t) { if (!g_SelectTimes[t]) continue; u8 val = Test(m, t); if (g_QuickMode && (val == 100)) break; } } g_CurResult = &g_ReportAve; FSM_SetState(&State_Report); } //----------------------------------------------------------------------------- // void ResetReport() { Mem_Set(0xFF, g_ReportAve, numberof(g_Time) * numberof(g_Mode)); Mem_Set(0xFF, g_ReportMin, numberof(g_Time) * numberof(g_Mode)); Mem_Set(0xFF, g_ReportMax, numberof(g_Time) * numberof(g_Mode)); } //----------------------------------------------------------------------------- // void Reset() { ResetReport(); SetWriteVRAM(ADDR_TEST); Test_31(' '); } //----------------------------------------------------------------------------- // void DisplayCount() { Print_SetPosition(25, 4); Print_DrawFormat("Count:%sx%i ", g_IterationText[g_IterationCount], TEST_COUNT); } //----------------------------------------------------------------------------- // void DisplayHeader() { Print_Clear(); Print_SetPosition(0, 0); Print_DrawText(MSX_GL" VRAM Access Timing Tester "APP_VERSION); Print_DrawLineH(0, 1, 40); Print_SetPosition(1, 2); Print_DrawFormat("Machine:%s", g_MachineName); // System information (use interslot access for MSX-DOS) u8 biosReadPort = Bios_InterSlotRead(g_MNROM, 0x0006); u8 biosWritePort = Bios_InterSlotRead(g_MNROM, 0x0007); u8 biosVersion = Bios_InterSlotRead(g_MNROM, 0x002B); u8 biosNumber = Bios_InterSlotRead(g_MNROM, 0x002D); // Display BIOS information Print_SetPosition(1, 3); Print_DrawFormat("BIOS: %s %iHz", GetMSXVersion(biosNumber), (biosVersion & 0x80) ? 50 : 60); switch (GET_VRAM_SIZE()) { case 0: Print_DrawText(" 16KB"); break; case 1: Print_DrawText(" 64KB"); break; case 2: Print_DrawText(" 128KB"); break; case 3: Print_DrawText(" 192KB"); break; } Print_DrawFormat(" R/W %2xh/%2xh", biosReadPort, biosWritePort); // Display detected information Print_SetPosition(1, 4); Print_DrawFormat("Detect: %s", GetVDPVersion()); if (g_VDP > VDP_VERSION_TMS9918A) Print_DrawFormat(" %iHz", VDP_GetFrequency() == VDP_FREQ_50HZ ? 50 : 60); DisplayCount(); Print_Return(); } //============================================================================= // MENU ACTIONS //============================================================================= //----------------------------------------------------------------------------- // const c8* MenuAction_Mode(u8 op, i8 value) { value; switch (op) { case MENU_ACTION_SET: case MENU_ACTION_INC: g_CurMode = (g_CurMode + 1) % g_ModeNum; break; case MENU_ACTION_DEC: g_CurMode = (g_CurMode + (g_ModeNum - 1)) % g_ModeNum; break; } return g_Mode[g_CurMode].Text; } //----------------------------------------------------------------------------- // const c8* MenuAction_Time(u8 op, i8 value) { value; switch (op) { case MENU_ACTION_SET: case MENU_ACTION_INC: g_CurTime = (g_CurTime + 1) % numberof(g_Time); break; case MENU_ACTION_DEC: g_CurTime = (g_CurTime + (numberof(g_Time) - 1)) % numberof(g_Time); break; } return g_Time[g_CurTime].Text; } //----------------------------------------------------------------------------- // const c8* MenuAction_Name(u8 op, i8 value) { value; if (op == MENU_ACTION_SET) { Print_DrawCharXAt(12, 6, ' ', 40 - 12); g_MachineName = GetStringAt(12, 6); } return g_MachineName; } //----------------------------------------------------------------------------- // const c8* MenuAction_Sprite(u8 op, i8 value) { value; if (g_VDP == VDP_VERSION_TMS9918A) return "(for MSX2 or above)"; switch (op) { case MENU_ACTION_SET: case MENU_ACTION_INC: case MENU_ACTION_DEC: g_DisplaySprite = !g_DisplaySprite; break; } return g_DisplaySprite ? "\x0C" : "\x0B"; } //----------------------------------------------------------------------------- // const c8* MenuAction_Command(u8 op, i8 value) { value; if (g_VDP == VDP_VERSION_TMS9918A) return "(for MSX2 or above)"; switch (op) { case MENU_ACTION_SET: case MENU_ACTION_INC: g_ExecCommand = (g_ExecCommand + 1) % CMD_MAX; break; case MENU_ACTION_DEC: g_ExecCommand = (g_ExecCommand + CMD_MAX - 1) % CMD_MAX; break; } switch (g_ExecCommand) { case CMD_OVERLAP: g_CommandY = 0; return "Overlap"; case CMD_SEPERATE: g_CommandY = 256; return "Sperate"; case CMD_OFF: return "Off"; } return NULL; } //----------------------------------------------------------------------------- // const c8* MenuAction_Access(u8 op, i8 value) { value; if (g_VDP == VDP_VERSION_TMS9918A) return "(for MSX2 or above)"; switch (op) { case MENU_ACTION_SET: case MENU_ACTION_INC: g_Access = (g_Access + 1) % ACCESS_MAX; break; case MENU_ACTION_DEC: g_Access = (g_Access + ACCESS_MAX - 1) % ACCESS_MAX; break; } switch (g_Access) { case ACCESS_DIRECT: return "Direct"; case ACCESS_HMMC: return "HMMC (Bitmap)"; case ACCESS_LMMC: return "LMMC (GM7)"; } return NULL; } //----------------------------------------------------------------------------- // const c8* MenuAction_Count(u8 op, i8 value) { value; switch (op) { case MENU_ACTION_SET: case MENU_ACTION_INC: g_IterationCount = (g_IterationCount + 1) % numberof(g_IterationText); DisplayCount(); break; case MENU_ACTION_DEC: g_IterationCount = (g_IterationCount + (numberof(g_IterationText) - 1)) % numberof(g_IterationText); DisplayCount(); break; } return g_IterationText[g_IterationCount]; } //----------------------------------------------------------------------------- // const c8* MenuAction_Test(u8 op, i8 value) { if (op == MENU_ACTION_SET) { switch (value) { case 0: // Test current config Test(g_CurMode, g_CurTime); break; case 1: // Test all config TestAll(); break; case 2: // Report g_CurResult = &g_ReportAve; FSM_SetState(&State_Report); break; case 3: // Reset Reset(); break; } } return NULL; } //----------------------------------------------------------------------------- // const c8* MenuAction_Reg(u8 op, i8 value) { struct RegisterEdit* reg = &g_RegEdit[g_RegEditIdx]; switch (value) { case 0: // Bit #0 case 1: // Bit #1 case 2: // Bit #2 case 3: // Bit #3 case 4: // Bit #4 case 5: // Bit #5 case 6: // Bit #6 case 7: // Bit #7 { u8 flag = 1 << value; if ((op == MENU_ACTION_INC) || (op == MENU_ACTION_DEC) || (op == MENU_ACTION_SET)) { if (reg->Value & flag) reg->Value &= ~flag; else reg->Value |= flag; } return (reg->Value & flag) ? "\x0C" : "\x0B"; } case REG_ACTION_INDEX: // Index if ((g_RegEditIdx < REG_EDIT_NUM - 1) && ((op == MENU_ACTION_INC) || (op == MENU_ACTION_SET))) { g_RegEditIdx++; Menu_SetDirty(); } if ((g_RegEditIdx > 0) && (op == MENU_ACTION_DEC)) { g_RegEditIdx--; Menu_SetDirty(); } String_Format(g_StringBuffer, "%i", g_RegEditIdx); return g_StringBuffer; case REG_ACTION_ACTIVE: // Active { if ((op == MENU_ACTION_INC) || (op == MENU_ACTION_DEC) || (op == MENU_ACTION_SET)) reg->Active = !reg->Active; return reg->Active ? "\x0C" : "\x0B"; } case REG_ACTION_TYPE: // Type if ((reg->Type < 2) && ((op == MENU_ACTION_INC) || (op == MENU_ACTION_SET))) reg->Type++; else if ((reg->Type > 0) && (op == MENU_ACTION_DEC)) reg->Type--; switch (reg->Type) { case REG_EDIT_SET: return "SET"; case REG_EDIT_AND: return "AND"; case REG_EDIT_OR: return "OR"; } break; case REG_ACTION_REGISTER: // Register if ((op == MENU_ACTION_INC) || (op == MENU_ACTION_SET)) reg->Number++; if (op == MENU_ACTION_DEC) reg->Number--; String_Format(g_StringBuffer, "%i", reg->Number); return g_StringBuffer; case REG_ACTION_CLEAR: // Clear if (op == MENU_ACTION_SET) { for (u8 i = 0; i < REG_EDIT_NUM; ++i) RegReset(&g_RegEdit[i]); Menu_SetDirty(); } break; } return NULL; } //----------------------------------------------------------------------------- // void MenuInit_Sub() { Print_Clear(); DisplayHeader(); Print_DrawLineH(0, 5, 40); } //----------------------------------------------------------------------------- // void MenuInit_Main() { MenuInit_Sub(); Print_DrawLineH(0, 22, 40); Print_DrawTextAt(0, 23, "T:Test A:TestAll R:Report"); } //============================================================================= // STATES //============================================================================= //----------------------------------------------------------------------------- // void State_Menu_Begin() { // DisplayHeader(); // Print_DrawLineH(0, 5, 40); // Menu Menu_Initialize(g_Menus); Menu_DrawPage(MENU_MAIN); // Print_DrawLineH(0, 16, 40); } //----------------------------------------------------------------------------- // void State_Menu_Update() { Menu_Update(); if (Keyboard_IsKeyPressed(KEY_T)) Test(g_CurMode, g_CurTime); if (Keyboard_IsKeyPressed(KEY_A)) TestAll(); if (Keyboard_IsKeyPressed(KEY_R)) { g_CurResult = &g_ReportAve; FSM_SetState(&State_Report); } } //----------------------------------------------------------------------------- // void State_Report_Begin() { DisplayHeader(); Print_SetPosition(1, 5); Print_DrawFormat("Scr:%c VSyn:%c RAM:%c", g_DisplayScreen ? 0x0C : 0x0B, g_WaitVSynch ? 0x0C : 0x0B, g_FromRAM ? 0x0C : 0x0B); if (g_VDP > VDP_VERSION_TMS9918A) Print_DrawFormat(" Sprt:%c Cmd:%c", g_DisplaySprite ? 0x0C : 0x0B, g_ExecCommand ? 0x0C : 0x0B); Print_DrawFormat(" \x8A%s", GetAccessName(g_Access)); u8 x = 4; u8 y = 7; u8 col = 0; // Table for (u8 t = 0; t < numberof(g_Time); ++t) { if (!g_SelectTimes[t]) // Skip unselected test functions continue; if (++col > 9) break; Print_SetPosition(x, y); Print_DrawFormat("%it", g_Time[t].Time + g_TimeOffset); x += 4; } for (u8 m = 0; m < numberof(g_Mode); ++m) { x = 0; y = 9 + m; Print_SetPosition(x, y); Print_DrawText(g_Mode[m].Code); x += 3; col = 0; for (u8 t = 0; t < numberof(g_Time); ++t) { if (!g_SelectTimes[t]) // Skip unselected test functions continue; if (++col > 9) break; Print_SetPosition(x, y); if ((g_Time[t].Time + g_TimeOffset >= g_ModeLimit[m]) && ((t == 0) || (g_Time[t - 1].Time + g_TimeOffset < g_ModeLimit[m]))) Print_DrawChar(0x16); else Print_DrawChar(0x1D); x += 1; Print_SetPosition(x, y); u8 percentage = (*g_CurResult)[t][m]; if (percentage == 0xFF) Print_DrawText("\x7\x7\x7"); else if (percentage == 100) Print_DrawText("OK"); else { Print_DrawInt(percentage); Print_DrawChar('%'); } x += 3; } Print_SetPosition(x, y); Print_DrawChar(0x1D); } Print_DrawLineH(0, 22, 40); Print_DrawTextAt(1, 23, "F1:Average F2:Min F3:Max R:Return"); } //----------------------------------------------------------------------------- // void State_Report_Update() { if (Keyboard_IsKeyPressed(KEY_F1)) { g_CurResult = &g_ReportAve; State_Report_Begin(); } else if (Keyboard_IsKeyPressed(KEY_F2)) { g_CurResult = &g_ReportMin; State_Report_Begin(); } else if (Keyboard_IsKeyPressed(KEY_F3)) { g_CurResult = &g_ReportMax; State_Report_Begin(); } if (Keyboard_IsKeyPressed(KEY_R)) FSM_SetState(&State_Menu); } //============================================================================= // TEST //============================================================================= //----------------------------------------------------------------------------- // Test a given screen mode with a given test function u8 Test(u8 mode, u8 time) { VDP_SetMode(g_Mode[mode].Mode); // Set selected screen mode VDP_SetColor(COLOR_MERGE(COLOR_LIGHT_RED, COLOR_DARK_RED)); VDP_SetSpritePatternTable(0x3800); VDP_SetSpriteAttributeTable(0x1A00); // MSX 2/2+/turbo R if (g_VDP > VDP_VERSION_TMS9918A) { VDP_RegWrite(14, 0); VDP_EnableSprite(g_DisplaySprite); } VDP_EnableDisplay(g_DisplayScreen); // Apply register modifiers for (u8 i = 0; i < REG_EDIT_NUM; ++i) RegApply(&g_RegEdit[i]); // Init value g_TestTotal = 0; // Max g_TestMin = TEST_COUNT; g_TestMax = 0; u16 itNum = 1 << g_IterationCount; // Compute iteration number cbTest cb; if (g_Access == ACCESS_DIRECT) cb = g_Time[time].FunctionDir; else cb = g_Time[time].FunctionCmd; if (g_FromRAM) { Mem_Copy((const void*)cb, (void*)RAM_FUNC, *g_Time[time].Size); cb = (cbTest)RAM_FUNC; } // Test iteration for (u16 j = 0; j < itNum; ++j) { if ((g_VDP > VDP_VERSION_TMS9918A) && (g_ExecCommand > 0)) { VDP_CommandSTOP(); VDP_CommandLMMV(0, g_CommandY, 256, 256, 0x00, VDP_OP_OR); // zero-OR all the VRAM } // Write reference SetWriteVRAM(ADDR_TEST); Test_31(CHAR_CTRL); if (g_WaitVSynch) Halt(); // Test the given writing function DisableInterrupt(); if (g_Access == ACCESS_DIRECT) SetWriteVRAM(ADDR_TEST); else // HMMC { g_Command.DY = g_Mode[mode].DY; g_Command.NX = g_Mode[mode].NX; g_Command.CMD = (g_Access == ACCESS_HMMC) ? VDP_CMD_HMMC : VDP_CMD_LMMC; SetVDPCommand(&g_Command); } cb(CHAR_TEST); EnableInterrupt(); // Check result u16 addr = ADDR_TEST; u16 count = 0; for (u16 i = 0; i < TEST_COUNT; ++i) if (VDP_Peek_16K(addr++) == CHAR_TEST) count++; // Store total, min and max g_TestTotal += count; if (count < g_TestMin) g_TestMin = count; if (count > g_TestMax) g_TestMax = count; } g_TestTotal = (u16)((u32)g_TestTotal * 100 / TEST_COUNT) >> g_IterationCount; // Scale down the total to get the average g_ReportAve[time][mode] = (u8)g_TestTotal; g_ReportMin[time][mode] = (u8)(g_TestMin * 100 / TEST_COUNT); g_ReportMax[time][mode] = (u8)(g_TestMax * 100 / TEST_COUNT); if (g_VDP == VDP_VERSION_TMS9918A) VDP_DisableSpritesFrom(0); else VDP_EnableSprite(FALSE); VDP_EnableDisplay(TRUE); VDP_SetMode(VDP_MODE_SCREEN0); // Restore Screen mode 0 VDP_SetColor(COLOR_MERGE(COLOR_WHITE, COLOR_BLACK)); Print_SetPosition(30, 23); if (g_TestTotal < 100) Print_DrawFormat("Result=%i%% ", g_TestTotal); else Print_DrawText("Result=OK "); return (u8)g_TestTotal; } //============================================================================= // MAIN LOOP //============================================================================= //----------------------------------------------------------------------------- // Program entry point MAIN() { // Initialize screen g_VDP = VDP_GetVersion(); // must be called before VDP_SetMode VDP_SetMode(VDP_MODE_SCREEN0); VDP_ClearVRAM(); if (g_VDP >= VDP_VERSION_V9958) VDP_RegWriteBak(25, 0); // Reset MSX2+ R#25 register (to work around wrong MSX2+ BIOS for Omega) Bios_SetKeyClick(FALSE); // Initialize VRAM table VDP_SetLayoutTable(ADDR_PNT); VDP_SetPatternTable(ADDR_PGT); VDP_SetColorTable(ADDR_PCT); VDP_SetSpriteAttributeTable(ADDR_SAT); VDP_SetSpritePatternTable(ADDR_SPT); // Initialize font Print_SetTextFont(g_Font_MGL_Sample6, 0); Print_SetColor(COLOR_WHITE, COLOR_BLACK); // Get machine name #if (TARGET == TARGET_DOS2) if (argc > 0) { g_MachineName = argv[0]; } else #endif { Print_DrawText("Machine:\n\n(press \x84 to validate)"); g_MachineName = GetStringAt(9, 0); } // Initialize sprite data VDP_SetSpriteFlag(VDP_SPRITE_SIZE_16 | VDP_SPRITE_SCALE_2); VDP_WriteVRAM_16K((const u8*)g_SpriteAttr, ADDR_SAT, 32 * 4); // Sprite Attribute Table VDP_WriteVRAM_16K(g_Font_MGL_Sample6 + 4, ADDR_SPT, 256 * 8); // Sprite Pattern Table VDP_FillVRAM_16K(COLOR_LIGHT_RED, ADDR_SCT, 0x200); // Sprite Color Table // Initialize variables const bool* defaultTime = NULL; if (g_VDP == VDP_VERSION_TMS9918A) // MSX1 { g_ModeNum = 4; g_ModeLimit = g_ModeLimitMSX1; defaultTime = g_DefaultTestMSX1; } else // MSX2 { if (g_VDP == VDP_VERSION_V9938) // MSX2 { g_ModeNum = 10; g_ModeLimit = g_ModeLimitMSX2; } else // MSX2+ { g_ModeNum = numberof(g_Mode); g_ModeLimit = g_ModeLimitMSX2; } defaultTime = g_DefaultTestMSX2; // Command default parameter g_Command.DX = 0; g_Command.DY = 0; g_Command.NX = 256; g_Command.NY = 1; g_Command.CLR = CHAR_TEST; g_Command.ARG = 0; g_Command.CMD = VDP_CMD_HMMC; } g_CurMode = 0; for (u8 i = 0; i < numberof(g_Time); ++i) g_SelectTimes[i] = defaultTime[i]; g_CurTime = 0; for (u8 i = 0; i < numberof(g_Mode); ++i) g_SelectModes[i] = TRUE; g_RegEditIdx = 0; for (u8 i = 0; i < REG_EDIT_NUM; ++i) RegReset(&g_RegEdit[i]); Reset(); FSM_SetState(&State_Menu); InitializeTest(); u8 count = 0; LOOP() { // Wait V-Blank Halt(); // Update states FSM_Update(); // Sign of life Print_SetPosition(39, 0); Print_DrawChar(176 + (count++ / 2 % 8)); } EXIT(); }