AgonConsole8 / agon-vdp

Official Firmware for the Agon Console8: ESP32 VDP
MIT License
43 stars 17 forks source link

ZDI support broken because of PS2Controller default config #247

Open mikolajmikolajczyk opened 3 months ago

mikolajmikolajczyk commented 3 months ago

In newest Console8 VDP (and classic 1.0.4) ZDI interface is broken.

This is caused by ZDI pins (26 and 27 on VDP) being also used by fabgl::PS2Controller default configuration.

static void begin(PS2Preset preset = PS2Preset::KeyboardPort0_MousePort1, KbdMode keyboardMode = KbdMode::CreateVirtualKeysQueue);

https://github.com/AgonConsole8/vdp-gl/blob/c16101479337e9967aa5c61b06b3fc0447e56f64/src/comdrivers/ps2controller.cpp#L1209

Simple solution I found is to recompile VDP soft with mouse disabled like this:

fabgl::PS2Controller::begin(fabgl::PS2Preset::KeyboardPort0, fabgl::KbdMode::CreateVirtualKeysQueue);

in this line: https://github.com/AgonConsole8/agon-vdp/blob/471dc92cba4df160048d40dc71a397cd3b37fe16/video/agon_ps2.h#L49

I tried to disable mouse to make ZDI work again while agon is working but either I'm missing something or it cannot be done after CPU already started.

I tried these in vdu_sys.h (as test only):

        case VDP_CONSOLEMODE: {         // VDU 23, 0, &FE, n
            fabgl::PS2Controller::end();
            fabgl::PS2Controller::begin(fabgl::PS2Preset::KeyboardPort0, fabgl::KbdMode::CreateVirtualKeysQueue);
            rtc_gpio_deinit(GPIO_NUM_26);
            rtc_gpio_deinit(GPIO_NUM_27);
            auto b = readByte_t();
            setConsoleMode((bool) b);
        }

This works for me on my fork: https://github.com/mikolajmikolajczyk/agon-vdp/pull/2/files

stevesims commented 3 months ago

interesting

a while back I experimented with only starting up the PS/2 mouse support when a "mouse enable" command is received. as noted against #126 this did not work, and would crash the VDP

I suspect the approach you've used here will suffer with essentially the same issues, i.e. you'll have a VDP where you can never use the mouse

attempting to fix the issues inside vdp-gl that prevent fabgl::PS2Controller::begin from being called twice is hard. back in April when I looked into this, I tried to look into that, and didn't manage to spot any reason why it would crash. ideally this would be possible (i.e. to be able to at will enable/disable the mouse port), but for now this isn't a practical possibility

one potential solution to this issue, and #126, is via #36 - i.e. support a persistent configuration option for dictating that the VDP should start up with the mouse port disabled. changing the config to enable the mouse port would require a reboot, but that's probably an acceptable compromise.

for this issue, i.e. allowing ZDI to work, I suspect the better solution may be to just use different GPIO pins on the ESP32. those seem to be configured on lines 12 and 13 of zdi.h. perhaps using pins ESP37 and ESP38? (I've never tried to set up and use ZDI debugging on either of my Agon systems, so I've not worked out how to set this up and test it)

pins ESP26 and ESP27 are defined as the default PS/2 mouse port for fab-gl system boards, so that's the model that Bernado used when designing the Console8, as the Agon hardware design builds on the fab-gl design. this is therefore what the firmware will use for any Agon model to attempt to support a mouse. i don't understand enough about how the ZDI support in the VDP works to know if there's a reason why different ESP pins can't be used