MEGA65 / m65dbg

An enhanced remote serial debugger/monitor for the mega65 project
GNU General Public License v3.0
13 stars 16 forks source link

Building m65dbg on WSL v2 issue #29

Closed pchnl closed 2 weeks ago

pchnl commented 2 weeks ago

Thanks for this great debugger tool.

If I understand it correctly, there is a windows exe available and it "works" on Xemu but it is not suitable for a COM connection to a physical MEGA65 because you can only connect via a UNIX socket, UNIX device or TCP/IP, not a Windows COM device. Correct me if I misunderstood this.

If it all possible I don't want to install Cygwin (just afraid it wil cause a conflict with something else). I have however WSL v2 installed and using that should not be a problem. I am running plain Ubuntu 24.04 LTS.

When I follow the instructions in the document I get a lot of compile-warnings and at the end the linker complains about 'strlwr' being non-existent : /home/x/mega65/m65dbg/commands.c:2400:(.text+0x635e): undefined reference to `strlwr'

I do not understand the makefile. It seems to contain pieces from macOS (homebrew), windows (cp m65dbg.exe) and of course Linux.

Do you know where strlwr function is comming from? Some sites suggest it is not a standard function, only found in some older Microsoft C compilers...(https://www.geeksforgeeks.org/strlwr-function-in-c/). Am I using the wrong C compiler (13.2.0 on ubuntu)?

I am obviously doing something stupid. Any help would be great.

Thanks, -Peter-

...
screen_shot.c:523:11: warning: variable ‘char_background_colour’ set but not used [-Wunused-but-set-variable]
  523 |       int char_background_colour;
      |           ^~~~~~~~~~~~~~~~~~~~~~
gcc -I/usr/include/readline -L/usr/lib/x86_64-linux-gnu -I/usr/include -c -Wall -g -std=c99 m65.c -o m65.o
gcc -I/usr/include/readline -L/usr/lib/x86_64-linux-gnu -I/usr/include -c -Wall -g -std=c99 mega65_ftp.c -o mega65_ftp.o
mega65_ftp.c: In function ‘show_mbrinfo’:
mega65_ftp.c:1886:33: warning: suggest parentheses around ‘+’ inside ‘<<’ [-Wparentheses]
 1886 |     int c = sector[pt_ofs+0x03] + (sector[pt_ofs+0x02] & 0xC0) << 2;
      |             ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mega65_ftp.c:1890:29: warning: suggest parentheses around ‘+’ inside ‘<<’ [-Wparentheses]
 1890 |     c = sector[pt_ofs+0x07] + (sector[pt_ofs+0x06] & 0xC0) << 2;
      |         ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mega65_ftp.c: At top level:
mega65_ftp.c:140:12: warning: ‘mode_report’ defined but not used [-Wunused-variable]
  140 | static int mode_report=0;
      |            ^~~~~~~~~~~
mega65_ftp.c:130:12: warning: ‘halt’ defined but not used [-Wunused-variable]
  130 | static int halt=0;
      |            ^~~~
mega65_ftp.c:128:12: warning: ‘not_already_loaded’ defined but not used [-Wunused-variable]
  128 | static int not_already_loaded=1;
      |            ^~~~~~~~~~~~~~~~~~
mega65_ftp.c:126:12: warning: ‘osk_enable’ defined but not used [-Wunused-variable]
  126 | static int osk_enable=0;
      |            ^~~~~~~~~~
gcc -I/usr/include/readline -L/usr/lib/x86_64-linux-gnu -I/usr/include -c -Wall -g -std=c99 ftphelper.c -o ftphelper.o
gcc -I/usr/include/readline -L/usr/lib/x86_64-linux-gnu -I/usr/include main.o serial.o commands.o gs4510.o screen_shot.o m65.o mega65_ftp.o ftphelper.o -lreadline -lpng -lm -o m65dbg
/usr/bin/ld: commands.o: in function `cmdHelp':
/home/x/mega65/m65dbg/commands.c:2400:(.text+0x635e): undefined reference to `strlwr'
collect2: error: ld returned 1 exit status
make: *** [Makefile:17: m65dbg] Error 1
pchnl commented 2 weeks ago

For other people experiencing this problem, add a file misc.c to the project as follow:

#include <string.h>
#include<ctype.h>

char *strlwr(char *str)
{
  unsigned char *p = (unsigned char *)str;

  while (*p) {
     *p = tolower((unsigned char)*p);
      p++;
  }

  return str;
}

Add a misc.h as follow:

#ifndef MISC_H
#define MISC_H

char *strlwr(char *str);

#endif // MISC_H

And finally patch the make file to contain this:

SOURCES=main.c serial.c commands.c gs4510.c screen_shot.c m65.c mega65_ftp.c ftphelper.c misc.c 

Now the program should compile.

Something else I found out is that the Windows WSL v2 does not work. That subsystem does not have access to USB devices. This rules windows out as a suitable OS (until m65dbg gets support for windows COM ports). What worked for me was Mint v22 in VMWARE 17.6.1 (both are free for personal use but VMWARE WS is difficult to obtain on the internet). Ensure the MEGA65 serial connection USB is connected to the VM, not the host. /dev/ttyUSB0 did not work, /dev/ttyUSB1 does work.

Finally, Ubuntu and Mint are not 100% compatible with Broadcom VMWARE (due to new Linux kernels). Older Ubuntu en Mint is OK, Ubuntu 24.04 LTS does not work in VMWARE and Mint 22 only works with graphics hardware acceleration turned OFF.

Phew!

Connection

pchnl commented 2 weeks ago

Done

gurcei commented 2 weeks ago

Thanks for your efforts on this, and glad you got it working :)

If I understand it correctly, there is a windows exe available and it "works" on Xemu but it is not suitable for a COM connection to a physical MEGA65 because you can only connect via a UNIX socket, UNIX device or TCP/IP, not a Windows COM device. Correct me if I misunderstood this.

For m65dbg in cygwin, it can be used with real com ports too, to talk to real hardware (not just unix sockets or tcp for xemu).

As a convenience for windows users, these days, I try to share a windows-cygwin.zip bundled with a minimal set of cygwin .dll's to support it. You're welcome to give this a try if you like:

The gotchya for accessing windows com ports in cygwin is that you have to specify them in the "/dev/ttySx" form, and not COMy as is usually done in windows. E.g.:

...and so on.

When I follow the instructions in the document I get a lot of compile-warnings and at the end the linker complains about 'strlwr' being non-existent : /home/x/mega65/m65dbg/commands.c:2400:(.text+0x635e): undefined reference to `strlwr'

Hehe, apologies for all the compiler warnings, didn't get time to clean them up. If you have the appetite for it, happy to get a PR with warning cleanup, but no urgency there, it's something I might get to in time myself.

I've got no idea why I used strlwr(), probably some past googling I did to look for some existing function to do the job, saw that was available and used it, not realising its availability elsewhere :)

Hmm, I see the strlwr() is only used once in the program, inside cmdHelp() for printing of help information for the "help" command, so I'm happy to just borrow your strlwr() implementation and drop it into the codebase if that will give future developers less grief, so happy to leave this ticket open to assure I get around to doing at least that :)

I do not understand the makefile. It seems to contain pieces from macOS (homebrew), windows (cp m65dbg.exe) and of course Linux.

Hehe, yeah, it kind of captures the history of the project a little bit, starting out in cygwin, then wanting to get it working in other environments afterwards :)

Something else I found out is that the Windows WSL v2 does not work. That subsystem does not have access to USB devices. This rules windows out as a suitable OS (until m65dbg gets support for windows COM ports).

Hmm, I haven't tried WSL2 specifically with m65dbg (or maybe I did but long ago and it's a foggy memory now), but I seem to recall hearing htat WSL2 does have access to windows usb devices (I recall it being missing in WSL1, or maybe even in earlier versions of WSL2, but was added to more recent versions of WSL2?).

So I'm still 'hopeful' that m65dbg will work in WSL2 if needbe, by folks that want to purse that path, but again, it'll need to use those linux-style device names (/dev/ttySx), and not the windows style (COMy).

gurcei commented 2 weeks ago

Ok, I've pushed in your strlwr() replacement logic straight into 'command.c', so hopefully this is sorted now, I'll close the ticket.