Thread: [Lapetus-cvs] lapetus/tests/regtest smpc.c,1.1,1.2
Status: Inactive
Brought to you by:
cyberwarriorx
From: Theo B. <cyb...@us...> - 2008-02-17 15:57:28
|
Update of /cvsroot/lapetus/lapetus/tests/regtest In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv32224 Modified Files: smpc.c Log Message: -Added peripheral tester. Mostly complete except for oreg overflow handling isn't completely tested. Also only standard pad's buttons are handled. Index: smpc.c =================================================================== RCS file: /cvsroot/lapetus/lapetus/tests/regtest/smpc.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- smpc.c 17 Feb 2008 00:36:28 -0000 1.1 +++ smpc.c 17 Feb 2008 15:57:23 -0000 1.2 @@ -19,6 +19,7 @@ #include <lapetus.h> #include <stdio.h> +#include <string.h> #include "intfac.h" #include "tests.h" #include "smpc.h" @@ -94,47 +95,141 @@ ////////////////////////////////////////////////////////////////////////////// +char *padstring[16] = { +"", +"", +"", +"L", +"Z", +"Y", +"X", +"R", +"B", +"C", +"A", +"START", +"UP", +"DOWN", +"LEFT", +"RIGHT" +}; + +////////////////////////////////////////////////////////////////////////////// + +u8 PerFetchContinue() +{ + // Issue a continue + SMPC_REG_IREG(0) = 0x80; + + // Wait till command is finished + while(SMPC_REG_SF & 0x1) {} + return 0; +} + +////////////////////////////////////////////////////////////////////////////// + +u8 GetOREG(u8 *oregcounter) +{ + u8 ret; + + if (oregcounter[0] >= 32) + oregcounter[0] = PerFetchContinue(); + + ret = SMPC_REG_OREG(oregcounter[0]); + oregcounter[0]++; + return ret; +} + +////////////////////////////////////////////////////////////////////////////// + +int endtest; + +u8 disppaddata(u8 oregcounter, int x, int y, u8 id) +{ + int i; + u16 data; + + data = GetOREG(&oregcounter) << 8; + data |= GetOREG(&oregcounter); + + if (!(data & 0x0F00)) + endtest = 1; + + for (i = 0; i < 16; i++) + { + if (!(data & (1 << i))) + { + VdpPrintf(&testdispfont, x, y, 0xF, "%s ", padstring[i]); + x += (strlen(padstring[i])+1) * 8; + } + } + + for (i = 0; i < ((352 - x) >> 3); i++) + VdpPrintf(&testdispfont, x+(i << 3), y, 0xF, " "); + + return oregcounter; +} + +////////////////////////////////////////////////////////////////////////////// + +u8 dispnothing(u8 oregcounter, int x, int y, u8 id) +{ + int i; + for (i = 0; i < ((352 - x) >> 3); i++) + VdpPrintf(&testdispfont, x+(i << 3), y, 0xF, " "); + + if (id == 0xFF) + return oregcounter; + else + return (oregcounter+(id & 0xF)); +} + +////////////////////////////////////////////////////////////////////////////// + typedef struct { u8 id; char *name; -// u8 (*func)(int xoffset, int yoffset); + u8 (*dispdata)(u8 oregcounter, int xoffset, int yoffset, u8 id); } perinfo_struct; perinfo_struct perinfo[] = { - { 0x02, "Standard Pad", }, - { 0x13, "Racing Wheel", }, - { 0x15, "Analog Pad", }, - { 0x23, "Saturn Mouse", }, - { 0x25, "Gun", }, - { 0x34, "Keyboard", }, - { 0xE1, "Megadrive 3 button", }, - { 0xE2, "Megadrive 6 button", }, - { 0xE3, "Shuttle Mouse", }, - { 0xFF, "Nothing", } + { 0x02, "Standard Pad", disppaddata }, + { 0x13, "Racing Wheel", dispnothing }, + { 0x15, "Analog Pad", dispnothing }, + { 0x23, "Saturn Mouse", dispnothing }, + { 0x25, "Gun", dispnothing }, + { 0x34, "Keyboard", dispnothing }, + { 0xE1, "Megadrive 3 button", dispnothing }, + { 0xE2, "Megadrive 6 button", dispnothing }, + { 0xE3, "Shuttle Mouse", dispnothing }, + { 0xFF, "Nothing", dispnothing } }; +////////////////////////////////////////////////////////////////////////////// + u8 perparse(char *portname, int yoffset, u8 oregcounter) { int i; - u8 perid = SMPC_REG_OREG(oregcounter); - oregcounter++; + u8 perid = GetOREG(&oregcounter); for (i = 0; i < (sizeof(perinfo) / sizeof(perinfo_struct)); i++) { if (perid == perinfo[i].id) { - VdpPrintf(&testdispfont, 0 * 8, yoffset, 0xF, "Port %s: %s ", portname, perinfo[i].name); - // parse button presses here + char text[50]; - if (perid == 0xFF) - return oregcounter; - return (oregcounter+(perid & 0xF)); + sprintf(text, "Port %s: %s", portname, perinfo[i].name); + VdpPrintf(&testdispfont, 0 * 8, yoffset, 0xF, "%s ", text); + + // Display peripheral data + oregcounter = perinfo[i].dispdata(oregcounter, (strlen(text)+1) * 8, yoffset, perid); + return oregcounter; } } - VdpPrintf(&testdispfont, 0 * 8, yoffset, 0xF, "Port %s: Unknown", portname); + VdpPrintf(&testdispfont, 0 * 8, yoffset, 0xF, "Port %s: Unknown(%02X)", portname, perid); return oregcounter; } @@ -144,7 +239,7 @@ { InterruptSetLevelMask(0xF); - InitLapetus(RES_320x224); + InitLapetus(RES_352x240); VdpRBG0Init(&testdispsettings); VdpSetDefaultPalette(); @@ -156,8 +251,10 @@ testdispfont.transparent = 0; - VdpPrintf(&testdispfont, 0 * 8, 1 * 8, 0xF, "Multitap test"); - VdpPrintf(&testdispfont, 0 * 8, 2 * 8, 0xF, "(to exit, press A+B+C on first pad)"); + VdpPrintf(&testdispfont, 0 * 8, 1 * 8, 0xF, "Peripheral test"); + VdpPrintf(&testdispfont, 0 * 8, 2 * 8, 0xF, "(to exit, press A+B+C+START on any pad)"); + + endtest = 0; for (;;) { @@ -177,22 +274,36 @@ // Wait till command is finished while(SMPC_REG_SF & 0x1) {} +#if 0 + for (i = 0; i < 16; i++) + VdpPrintf(&testdispfont, 0 * 8, (4+i) * 8, 0xF, "OREG %02d: %02X", i, SMPC_REG_OREG(i)); + + for (i = 0; i < 16; i++) + VdpPrintf(&testdispfont, 16 * 8, (4+i) * 8, 0xF, "OREG %02d: %02X", i+16, SMPC_REG_OREG(i+16)); +#endif + // Grab oreg's for (i = 0; i < 2; i++) { - portcon = SMPC_REG_OREG(oregcounter); - oregcounter++; + portcon = GetOREG(&oregcounter); if (portcon != 0x16) { - VdpPrintf(&testdispfont, 0 * 8, (4+(8*i)) * 8, 0xF, "Port %d: Multi-tap not connected", i+1); + if (portcon == 0xF1) + { + char text[3]; + sprintf(text, "%d", i+1); + oregcounter = perparse(text, (4+(8*i)) * 8, oregcounter); + } + else if (portcon == 0xF0) + VdpPrintf(&testdispfont, 0 * 8, (4+(8*i)) * 8, 0xF, "Port %d: Nothing ", i+1); for (i2 = 0; i2 < 6; i2++) VdpPrintf(&testdispfont, 0 * 8, (4+(8*i)+1+i2) * 8, 0xF, " "); } else { - VdpPrintf(&testdispfont, 0 * 8, (4+(8*i)) * 8, 0xF, "Port %d: Multi-tap connected ", i+1); + VdpPrintf(&testdispfont, 0 * 8, (4+(8*i)) * 8, 0xF, "Port %d: Multi-tap ", i+1); for (i2 = 0; i2 < (portcon & 0x0F); i2++) { @@ -202,9 +313,16 @@ } } } + + if (endtest) + break; } + testdispfont.transparent = 1; + + // Re-enable Lapetus's peripheral handler + BIOS_ChangeSCUInterruptMask(~(MASK_VBLANKOUT | MASK_SYSTEMMANAGER), 0); } ////////////////////////////////////////////////////////////////////////////// |