C64Nano icon indicating copy to clipboard operation
C64Nano copied to clipboard

TheC64 + tang_nano_20k_c64: How to send the menu open command?

Open vanfanel opened this issue 9 months ago • 54 comments

Hi there!

I don't know it someone had tried before, but I connected the TheC64 keyboard to the TangNano20k+misteryshield20k, and it woks perfectly well. (TheC64 is a full size C64 replica running an small GNU/Linux system with the VICE emulator on top: https://www.c64-wiki.com/wiki/THEC64)

Image

...So my dream of gutting a TangNano20k+misteryshield20k inside TheC64 is near. However, since the C64 has no F12 key, there's no way to enter the core menu.

Is there a couple of pins somewhere on the TangNano20k or on the misteryshield20k that I can use to attack a switch to them so I can enter the core menu with that?

Thanks!

vanfanel avatar Apr 07 '25 18:04 vanfanel

Hi @vanfanel , the F12 key is something special in the Fpga companion fw. you will need a customization in that. never tried before but you can transfer the two tn20k button state into the fw. hope my c64 is doing that already and ifnot will add.that. bigger part is to modify fw that one of the two received buttons is equivalent to F12. All maybe possible. btw one of the buttons is already in use to swap joyports and other one if i recall unused. sorry for the short answer but rather busy at the moment.

vossstef avatar Apr 08 '25 17:04 vossstef

Hi @vanfanel , the F12 key is something special in the Fpga companion fw. you will need a customization in that. never tried before but you can transfer the two tn20k button state into the fw. hope my c64 is doing that already and ifnot will add.that. bigger part is to modify fw that one of the two received buttons is equivalent to F12. All maybe possible. btw one of the buttons is already in use to swap joyports and other one if i recall unused. sorry for the short answer but rather busy at the moment.

Many thanks for the response! Not in a hurry at all, don't worry :) Isn't it possible to use a couple of pins on the companion board? It has 8 pins (which I don't know what they do, to be honest, and I can't find any information on what they do).

vanfanel avatar Apr 08 '25 17:04 vanfanel

@vanfanel , you could also use one of the spare FPGA pins that i don't use for the DS2 interface for a Key F12 button. But the issue of forwarding the pin press into the firmware will remain. There is some work to do...

vossstef avatar Apr 08 '25 20:04 vossstef

Does that keyboard have a different key you could re-purpose? Maybe some rarely used one? Or a long press on restore or the like? That could be done inside the FPGA Companion firmware and would not need any special support on FPGA side.

harbaum avatar Apr 09 '25 13:04 harbaum

Does that keyboard have a different key you could re-purpose? Maybe some rarely used one? Or a long press on restore or the like? That could be done inside the FPGA Companion firmware and would not need any special support on FPGA side.

The keyboard doesn't have any special keys I know of, other than being a plain C64 keyboard. But a key that has not much use on a C64 is the "pound" key, which on GNU/Linux produces scancode 0x27, according to XEV:

KeyPress event, serial 39, synthetic NO, window 0x1600001,
    root 0x400, subw 0x0, time 83083999, (-627,102), root:(244,550),
    state 0x10, keycode 20 (keysym 0x27, apostrophe), same_screen YES,
    XLookupString gives 1 bytes: (27) "'"
    XmbLookupString gives 1 bytes: (27) "'"
    XFilterEvent returns: False

I think the key should be remapped to the "pound" symbol before being used for menu toggling however? (It has a "pound" symbol on it)

vanfanel avatar Apr 09 '25 13:04 vanfanel

Hi @vanfanel , please consider to make use of this tiny extra Keyboard for the F12 Key topic . Some users found that helpful for A2600. https://github.com/vossstef/A2600Nano/issues/7

vossstef avatar Apr 09 '25 17:04 vossstef

Ah ... yes, of course.

And one could actually make a little firmware for a pico (or pico zero) that implements a hid keyboard with just F12, the cursor keys and the return key as a 'mistery menu controller'. This would be super cheap but also flexible.

harbaum avatar Apr 09 '25 17:04 harbaum

Thanks for thinking this alongside me, guys! But the solution may be a tad easier. On GNU/Linux, as I said, the "pound" key sends keycode 20 (keysym 0x27, apostrophe) right now. Ok, I just have to remap that to F12, and presto! It has to work like that! So.. where is the keyboard mapping file? I guess that's part of the companion programming, right?

vanfanel avatar Apr 10 '25 08:04 vanfanel

@vanfanel , for the C64 the mapping is already (ST and Amiga too) part of the core nowadays. I think the special F12 handling is part of the compansion fw as not forwarded (pressed to core).

vossstef avatar Apr 10 '25 16:04 vossstef

@vanfanel , for the C64 the mapping is already (ST and Amiga too) part of the core nowadays. I think the special F12 handling is part of the compansion fw as not forwarded (pressed to core).

So it's impossible to define keycode 20 (keysym 0x27, apostrophe) as F12 in the core? There are other keys in the TheC64 keyboard that need adjusting too. I may do it if it's possible and you tell me where can it be done :)

vanfanel avatar Apr 10 '25 18:04 vanfanel

@vanfanel , please have a look to hid.c and search for // F12 toggles the OSD state. Therefore F12 must never be forwarded to get an idea

Maybe you compile for your own purposes a modified Version and try it.

vossstef avatar Apr 10 '25 19:04 vossstef

@vanfanel , please have a look to hid.c and search for // F12 toggles the OSD state. Therefore F12 must never be forwarded to get an idea

Maybe you compile for your own purposes a modified Version and try it.

Ah, yes, that's promising. I see this line: https://github.com/harbaum/FPGA-Companion/blob/dc5af8d6a0e69a1a1df5227406d4f1e999a6da47/src/hid.c#L131 ...where it seems that the menu is toggled if the value in the buffer position is 0x45. I understand that 0x45 must be the scancode for F12, right? If I connect the TheC64 keyboard to a GNU/Linux system, the "showkey" command tells me that the "pound" key on the keyboard has scancode 0x0c.

However, after building the latest FPGA-companion core from latest GIT code, it doesn't work with the latest stable tang_nano_20k_c64 release (1.9.1) to complete this experiment.

Can you please point me to the exact commit in https://github.com/harbaum/FPGA-Companion/commits/main/ that corresponds to the FPGA-Companion release 1.2?

NVM: It should be the last one in March 3 here: https://github.com/harbaum/FPGA-Companion/commit/36982cc0bd4342eadc06c8be768e531cf72904fc

vanfanel avatar Apr 11 '25 13:04 vanfanel

@vossstef Well, latest commit from March 3 doesn't build:

/home/manuel/src/bouffalo/bouffalo_sdk/components/usb/cherryusb/class/vendor/net/usbh_asix.c:18:103: error: 'CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE' undeclared here (not in a function); did you mean 'CONFIG_USBHOST_PSC_STACKSIZE'?
   18 | static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_asix_rx_buffer[CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE];
      |                                                                                                       ^~~~~~                             
      |                                                                                                       CONFIG_USBHOST_PSC_STACKSIZE
/home/manuel/src/bouffalo/bouffalo_sdk/components/usb/cherryusb/class/vendor/net/usbh_rtl8152.c:15:106: error: 'CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE' undeclared here (not in a function)
   15 | static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rtl8152_rx_buffer[CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE];
      |                                                                                                          ^~~~~~~~~                             
/home/manuel/src/bouffalo/bouffalo_sdk/components/usb/cherryusb/class/vendor/net/usbh_asix.c:19:103: error: 'CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE' undeclared here (not in a function); did you mean 'CONFIG_USBHOST_PSC_STACKSIZE'?
   19 | static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_asix_tx_buffer[CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE];
      |                                                                                                       ^~~~~~                             
      |                                                                                                       CONFIG_USBHOST_PSC_STACKSIZE
/home/manuel/src/bouffalo/bouffalo_sdk/components/usb/cherryusb/class/vendor/net/usbh_rtl8152.c:16:106: error: 'CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE' undeclared here (not in a function)
   16 | static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rtl8152_tx_buffer[CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE];
      |                                                                                                          ^~~~~~~~~                             
/home/manuel/src/bouffalo/bouffalo_sdk/components/usb/cherryusb/class/vendor/net/usbh_asix.c: In function 'usbh_asix_get_eth_txbuf':
/home/manuel/src/bouffalo/bouffalo_sdk/components/usb/cherryusb/class/vendor/net/usbh_asix.c:765:1: warning: control reaches end of non-void function [-Wreturn-type]
  765 | }
      | ^
At top level:
/home/manuel/src/bouffalo/bouffalo_sdk/components/usb/cherryusb/class/vendor/net/usbh_asix.c:19:86: warning: 'g_asix_tx_buffer' defined but not used [-Wunused-variable]
   19 | static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_asix_tx_buffer[CONFIG_USBHOST_ASIX_ETH_MAX_RX_SIZE];
      |                                                                                      ^~~~~~~~~~~~~~~~
/home/manuel/src/bouffalo/bouffalo_sdk/components/usb/cherryusb/class/vendor/net/usbh_asix.c:18:86: warning: 'g_asix_rx_buffer' defined but not used [-Wunused-variable]
   18 | static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_asix_rx_buffer[CONFIG_USBHOST_ASIX_ETH_MAX_TX_SIZE];
      |                                                                                      ^~~~~~~~~~~~~~~~
/home/manuel/src/bouffalo/bouffalo_sdk/components/usb/cherryusb/class/vendor/net/usbh_rtl8152.c: In function 'usbh_rtl8152_get_eth_txbuf':
/home/manuel/src/bouffalo/bouffalo_sdk/components/usb/cherryusb/class/vendor/net/usbh_rtl8152.c:2232:1: warning: control reaches end of non-void function [-Wreturn-type]
 2232 | }
      | ^
make[3]: *** [build_out/components/usb/cherryusb/CMakeFiles/cherryusb.dir/build.make:202: build_out/components/usb/cherryusb/CMakeFiles/cherryusb.dir/class/vendor/net/usbh_asix.c.o] Error 1
make[3]: *** Waiting for unfinished jobs....
At top level:
/home/manuel/src/bouffalo/bouffalo_sdk/components/usb/cherryusb/class/vendor/net/usbh_rtl8152.c:16:86: warning: 'g_rtl8152_tx_buffer' defined but not used [-Wunused-variable]
   16 | static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rtl8152_tx_buffer[CONFIG_USBHOST_RTL8152_ETH_MAX_TX_SIZE];
      |                                                                                      ^~~~~~~~~~~~~~~~~~~
/home/manuel/src/bouffalo/bouffalo_sdk/components/usb/cherryusb/class/vendor/net/usbh_rtl8152.c:15:86: warning: 'g_rtl8152_rx_buffer' defined but not used [-Wunused-variable]
   15 | static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rtl8152_rx_buffer[CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE];
      |                                                                                      ^~~~~~~~~~~~~~~~~~~
[ 51%] Building C object CMakeFiles/app.dir/home/manuel/src/bouffalo/FPGA-Companion/src/u8g2/csrc/u8x8_cad.c.o
make[3]: *** [build_out/components/usb/cherryusb/CMakeFiles/cherryusb.dir/build.make:216: build_out/components/usb/cherryusb/CMakeFiles/cherryusb.dir/class/vendor/net/usbh_rtl8152.c.o] Error 1
make[2]: *** [CMakeFiles/Makefile2:727: build_out/components/usb/cherryusb/CMakeFiles/cherryusb.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs....
[ 51%] Building C object CMakeFiles/app.dir/home/manuel/src/bouffalo/FPGA-Companion/src/u8g2/csrc/u8x8_capture.c.o
[ 51%] Building C object CMakeFiles/app.dir/home/manuel/src/bouffalo/FPGA-Companion/src/u8g2/csrc/u8x8_d_a2printer.c.o
[ 52%] Building C object CMakeFiles/app.dir/home/manuel/src/bouffalo/FPGA-Companion/src/u8g2/csrc/u8x8_d_gp1247ai.c.o
[ 52%] Building C object CMakeFiles/app.dir/home/manuel/src/bouffalo/FPGA-Companion/src/u8g2/csrc/u8x8_d_gp1287ai.c.o
/home/manuel/src/bouffalo/FPGA-Companion/src/bl616/mcu_hw.c: In function 'usbh_update':
/home/manuel/src/bouffalo/FPGA-Companion/src/bl616/mcu_hw.c:151:96: error: 'struct usbh_hid' has no member named 'report_desc'
  151 |       usb_debugf("report descriptor: %p", usb->hid_info[i].class->report_desc);
      |                                                                                                ^ 
/home/manuel/src/bouffalo/FPGA-Companion/src/bl616/mcu_hw.c:153:57: error: 'struct usbh_hid' has no member named 'report_desc'
  153 |       if(!parse_report_descriptor(usb->hid_info[i].class->report_desc, 128, &usb->hid_info[i].report, NULL)) {
      |                                                         ^~
/home/manuel/src/bouffalo/FPGA-Companion/src/bl616/mcu_hw.c: In function 'usb_host':
/home/manuel/src/bouffalo/FPGA-Companion/src/bl616/mcu_hw.c:459:3: error: too few arguments to function 'usbh_initialize'
  459 |   usbh_initialize();
      |   ^~~~~~~~~~~~~~~
In file included from /home/manuel/src/bouffalo/FPGA-Companion/src/bl616/mcu_hw.c:8:
/home/manuel/src/bouffalo/bouffalo_sdk/components/usb/cherryusb/core/usbh_core.h:276:5: note: declared here
  276 | int usbh_initialize(uint8_t busid, uintptr_t reg_base);
      |     ^~~~~~~~~~~~~~~

Can you please point me to a GIT code commit that builds and works with latest stable tang_nano_20k_c64 release (1.9.1)?

vanfanel avatar Apr 11 '25 13:04 vanfanel

@vanfanel , i am doing very big changes to both SDK and FPGA-companion bl616 section at the moment to add WIFI functions and i tested now almost daily againt an unpublised SDK locally stored.

Hopefully the build instruction over here: https://github.com/harbaum/FPGA-Companion/tree/main/src/bl616 are good enough to understand what to do. You need to use again harbaums SDK repo location if you cloned some weeks ago.

My latest code uses usbh_hid_get_report_descriptor(usb->hid_info[i].class, report_desc[i], 128); and that means native Cherry 1.4.3 is needed. Your SDK need to be latest version out of the harbaum repo location as it includes additions i did for latest native USB stack.

Following SDK's will not work anymore !

https://github.com/CherryUSB/bouffalo_sdk https://github.com/vossstef/bouffalo_sdk.git https://github.com/bouffalolab/bouffalo_sdk

only this one: https://github.com/harbaum/bouffalo_sdk

vossstef avatar Apr 11 '25 13:04 vossstef

@vossstef I am using: https://github.com/bouffalolab/toolchain_gcc_t-head_linux.git https://github.com/harbaum/bouffalo_sdk.git to build: https://github.com/harbaum/FPGA-Companion.git

Latest GIT code in https://github.com/harbaum/FPGA-Companion.git DOES build correctly, but does not work with the latest core in https://github.com/vossstef/tang_nano_20k_c64/releases

What I need is a version of the source in https://github.com/harbaum/FPGA-Companion.git that works with the latest release in https://github.com/vossstef/tang_nano_20k_c64/releases

vanfanel avatar Apr 11 '25 13:04 vanfanel

@vanfanel, lately i included in my C64 the XML settings, keyboard mapping and a 6551 UART plus changes in hid and sysctrl to align with Till's ST and WIFI modem interface needs. I think you need to compile the VHDL/Verilog and flash your TN20k.
Exactly that setting i am using also at the moment. Will test later on that the stored bl616 code compiles and work with https://github.com/harbaum/bouffalo_sdk as mentioned i am using even newer SDK

vossstef avatar Apr 11 '25 14:04 vossstef

@vossstef When you have time (I know you are busy with all those improvements!) I could use a version of the core that goes with the current Companion firmware, so please upload the core build you use and I will use that for now.

vanfanel avatar Apr 11 '25 15:04 vanfanel

I am considering to add a setting to the ini file stored on SD card which will allow to change the menu hotkey on a per core basis. Something similar was needed for the original mist when the acorn Archimedes core came which actually has a real F12 key and needs that itself.

I am currently porting misterynano to the efinix Trion T20 fpga and do the menu key config and a few other small things after that.

harbaum avatar Apr 11 '25 15:04 harbaum

I am considering to add a setting to the ini file stored on SD card which will allow to change the menu hotkey on a per core basis. Something similar was needed for the original mist when the acorn Archimedes core came which actually has a real F12 key and needs that itself.

I am currently porting misterynano to the efinix Trion T20 fpga and do the menu key config and a few other small things after that.

That would be an ideal solution, of course! :)

vanfanel avatar Apr 11 '25 15:04 vanfanel

@vossstef When you have time (I know you are busy with all those improvements!) I could use a version of the core that goes with the current Companion firmware, so please upload the core build you use and I will use that for now.

@vanfanel what Build env do you use? Windows or Linux ?

vossstef avatar Apr 11 '25 16:04 vossstef

@vossstef I use Linux only (I wouldn't touch a Windows machine if my life depended on it).

vanfanel avatar Apr 11 '25 16:04 vanfanel

@vanfanel, i just did a build on fedora 41 and build is working like a charm. SDK from Till's repo and of course the FPGA-companion. No build failures. Please check the details if your build fails. Of course the bl616 binary WIFI is not functional with that SDK but no problem for well known "normal" old functions.

vossstef avatar Apr 11 '25 20:04 vossstef

@vossstef, as I said, the build is OK, but the latest GIT code for the Companion doesn't work with the latest core release. I think there is some idiomatic barrier here... :)

vanfanel avatar Apr 11 '25 20:04 vanfanel

@vanfanel , i did FPGA companion build and C64 core build under Linux Fedora 41 and flashed both µC and TN20k. The core is working fine and no issues apart from known buggy WIFI.

vossstef avatar Apr 11 '25 21:04 vossstef

@vossstef Ok! Can you please upload the core build that you have working with current Companion GIT sources?

vanfanel avatar Apr 11 '25 22:04 vanfanel

@vanfanel i dropped my build over here (Fedora 41)

https://github.com/harbaum/FPGA-Companion/releases/tag/v1.2.1

and the C64 core https://github.com/vossstef/tang_nano_20k_c64/releases/tag/v1.9.2

Did only a very brief check and USB hub, xbox360 controller, the RII key combo and WIFI working fine.

vossstef avatar Apr 12 '25 06:04 vossstef

@vossstef

Thanks, that version of the core does work with the current companion code!

I changed 0x45 in https://github.com/harbaum/FPGA-Companion/blob/dc5af8d6a0e69a1a1df5227406d4f1e999a6da47/src/hid.c#L131 for 0x53 which corresponds to the scancode of the "TheC64" labeled key on the keyboard, and also tried 0x0c which is the scancode for the "pound" key, then rebuilt the companion and re-flashed it. However, none of these scancodes work for activating the menu... Which leads me to ask: what kind of scancodes are you using in https://github.com/harbaum/FPGA-Companion/blob/dc5af8d6a0e69a1a1df5227406d4f1e999a6da47/src/hid.c#L131, please? I find the scancodes by running showkey --scancodes on GNU/Linux, but maybe that's not the intended method...

vanfanel avatar Apr 12 '25 09:04 vanfanel

@vossstef

Thanks, that version of the core does work with the current companion code!

I changed 0x45 in https://github.com/harbaum/FPGA-Companion/blob/dc5af8d6a0e69a1a1df5227406d4f1e999a6da47/src/hid.c#L131 for 0x53 which corresponds to the scancode of the "TheC64" labeled key on the keyboard, and also tried 0x0c which is the scancode for the "pound" key, then rebuilt the companion and re-flashed it. However, none of these scancodes work for activating the menu... Which leads me to ask: what kind of scancodes are you using in https://github.com/harbaum/FPGA-Companion/blob/dc5af8d6a0e69a1a1df5227406d4f1e999a6da47/src/hid.c#L131, please? I find the scancodes by running showkey --scancodes on GNU/Linux, but maybe that's not the intended method...

@harbaum can you pls. advise about the Scancodes and how to replace the F12 by 'Pound' code

vossstef avatar Apr 12 '25 11:04 vossstef

These USB HID codes like these:

https://gist.github.com/MightyPork/6da26e382a7ad91b5496ee55fdc73db2

But I cannot tell you what those special keys deliver. Which key e.g. detects your PC if you press the C64 pound key?

harbaum avatar Apr 12 '25 13:04 harbaum

These USB HID codes like these:

https://gist.github.com/MightyPork/6da26e382a7ad91b5496ee55fdc73db2

But I cannot tell you what those special keys deliver. Which key e.g. detects your PC if you press the C64 pound key?

When connected to a GNU/Linux desktop PC, the pound key produces the single quote character (this one --> ' ) and according to showkeys --scancodes it produces the 0x0c scancode.

In the file you pointed (thanks for that!) I guess it should be: #define KEY_APOSTROPHE 0x34 // Keyboard ' and "

So I used 0x34 in the comparason here: https://github.com/harbaum/FPGA-Companion/blob/dc5af8d6a0e69a1a1df5227406d4f1e999a6da47/src/hid.c#L131 ...and now I can bring the menu using the "arrow up" key (the key that's just left to "Restore") on the TheC64 keyboard.

On the other hand, when connected to the TangNano+Companion, the pound key produces "-" (minus) on the C64 screen. According to https://gist.github.com/MightyPork/6da26e382a7ad91b5496ee55fdc73db2, that's 0x2d. So I put 0x2d in https://github.com/harbaum/FPGA-Companion/blob/dc5af8d6a0e69a1a1df5227406d4f1e999a6da47/src/hid.c#L131, and now I have the menu working on the TheC64 keyboard on the TangNano20K C64 core!! :)

However, an small issue remains: some keys in the TheC64 keyboard don't correspond to the symbols they produce on screen. Most keys are right, but there are like 5 that are wrong. For example, "*" on the keyboard prints ":" on screen. How can I adjust that on the companion code or the core's code, please?

vanfanel avatar Apr 12 '25 15:04 vanfanel