andreas-jonsson / virtualxt

Portable, lightweight PC/XT emulator written in C.
https://virtualxt.org
Other
72 stars 17 forks source link

Arstech ISA2USB passthrough : ArsInit() function fails while starting VirtualXT #68

Closed stormyordos closed 7 months ago

stormyordos commented 9 months ago

Being a proud new owner of the latest version of the Ars Technologies gadget, the USB2ISA-R (the single ISA slot version), I was very excited to try your implementation of their API in VirtualXT.

Unfortunately, after setting the 'arstech_isa' parameter in the configuration file to my version of the libarsusb4.so library, I am greeted by this log message when starting VirtualXT through flatpak:

[isa.c] ERROR: Could not initialize Arstech USB library!
vxt_system_initialize() failed with error user error

For reference, the USB2ISA-R is correctly recognized by the "arsenum3" Enumerator application from Ars: image

and the device properly appears in my list of USB devices on Linux:

image

My system is a Linux OpenSuSE Tumbleweed, with a recent kernel:

> uname -a

Linux <SYSTEM NAME> 6.6.2-1-default #1 SMP PREEMPT_DYNAMIC Mon Nov 20 11:22:36 UTC 2023 (263a855) x86_64 x86_64 x86_64 GNU/Linux

Could it be because calling the Ars API functions requires more privileges than the flatpak package is allowed to have?

andreas-jonsson commented 9 months ago

There could definitely be an issue with the flatpak version. I recommend building it from source for this purpose. I was told there was also a new driver/software version for the boards. I have not tested that.

Sad to say, but the software quality of the ISA2USB is just awful.

But I will dust mine of and guide you through the process if you want. :) I start by verifying it on my side that (if) it works. Then we can take it from there.

stormyordos commented 9 months ago

Thanks for your quick answer!

so, having built the emulator from the premake files, it still crashes at the same place but I'm making progress. Since it's easier to strace the actual executable without the flatpak fluff around, I found this interesting error message before the crash:

openat(AT_FDCWD, "/home/stormy/.local/share/virtualxt/VirtualXT-SDL2-0.12.0-testing//config.ini", O_RDONLY) = 17
fstat(17, {st_mode=S_IFREG|0644, st_size=734, ...}) = 0
read(17, "[modules]\nchipset=xt\nbios=0xFE00"..., 4096) = 734
read(17, "", 4096)                      = 0
close(17)                               = 0
openat(AT_FDCWD, "/home/stormy/arstech", O_RDWR) = -1 ENOENT (No such file or directory)
write(1, "[isa.c] ERROR: Could not initial"..., 57[isa.c] ERROR: Could not initialize Arstech USB library!
) = 57
write(1, "vxt_system_initialize() failed w"..., 53vxt_system_initialize() failed with error user error
) = 53

it seems as though whatever the string in the arstech_isa entry from the config file may be, the program still looks for a very specific "~/arstech" file. As an experiment, I copied the libarsusb4.so file to ~/, renaming it "arstech" in the process.

Sure enough, it loads the arstech_isa peripheral correctly and then proceeds with booting freedos:

Loaded modules:
- chipset = xt
- bios = 0xFE000,GLABIOS.ROM
- uart = 0x3F8,4
- uart = 0x2F8,3
- cga
- disk
- bios = 0xE0000,vxtx.bin
- rtc = 0x240
- bios = 0xC8000,GLaTICK_0.8.4_AT.ROM
- adlib
- rifs
- ctrl
- joystick = 0x201
- ems = lotech_ems
- mouse = 0x3F8
- arstech_isa = /home/stormy/arstech-utils/libarsusb4.so
Installed pirepherals:
1 - RAM
2 - PIC (Intel 8259)
3 - DMA (Intel 8237)
4 - PIT (Intel 8253)
5 - PPI (Intel 8255)
6 - ROM
7 - UART (National Semiconductor 8250)
8 - UART (National Semiconductor 8250)
9 - CGA Compatible Device
10 - Disk Controller
11 - ROM
12 - RTC (Motorola MC146818)
13 - ROM
14 - AdLib Music Synthesizer
15 - RIFS Server
16 - Emulator Control
17 - Gameport Joystick(s)
18 - Lo-tech 2MB EMS Board
19 - Microsoft Serial Mouse
20 - ISA Passthrough (Arstech USB)
Harddrive image: /home/stormy/Desktop/Linux/virtualxt/build/bin//../..//boot/freedos_hd.img
[ppi.c] Turbo mode on!
Segmentation fault (core dumped)

The SDL window even pops up before, as the last line from the previous log indicates, the whole thing crashes down:

clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=15000000}, 0x7ffd44665300) = 0
recvmsg(5, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="#\203-\1\n\0\0\0\21\0\2\0\355\356&\2\0\0\0\0\r\0\2\0\0\0\0\0\0\0\0\0"..., iov_len=4096}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 216
recvmsg(5, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily unavailable)
recvmsg(5, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily unavailable)
recvmsg(5, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily unavailable)
poll([{fd=12, events=POLLIN}], 1, 0)    = 0 (Timeout)
poll([{fd=11, events=POLLIN|POLLPRI}], 1, 0) = 0 (Timeout)
futex(0x1bc1e90, FUTEX_WAIT_PRIVATE, 2, NULL) = ?
+++ killed by SIGSEGV (core dumped) +++
Segmentation fault (core dumped)
stormyordos commented 9 months ago

Well, changing the port value defined in [arstech_isa] seems to do the trick: changed the default "0x201" to "0x220" (yes, it's a Sound Blaster :) ) and it boots fine...

andreas-jonsson commented 9 months ago

Thank you this is very helpful. :)

I spent a few hours getting the hardware and drivers working. Eventually I got a postcard running. But only when doing static linking. So something else is wrong. At least on my system.

I will spend some more time tomorrow and then get back to you.

andreas-jonsson commented 9 months ago

There is a new branch called arstech. If you build from that with the following premake options I think it sould work. (on Linux at least) premake5 --modules --arstech=arsusb4 --static gmake make sure you have no old object files and your project is clean. (running make clean might not be enough)

libarsusb4.so should be in your lib path when you do this. According to Arstech you should copy it to /usr/lib. Otherwise it will not link.

In the VirtualXT config file the arshtech_isa module line don't take any path as argument now since it is passed to the premake script instead.

The arshtech_isa config block still needs to be synced up with the enumerator. Ports, memory etc.

Run VirtualXT as root. This is needed according to Arstech. If PulseAudio gives you trouble try starting with --mute.

I tested this with a postcard on port 0x80 and it worked. As for the strange loading issue. I think the libarsusb4.so is looking for a file in /rootcalled arstech that the utility installer copies there.

andreas-jonsson commented 9 months ago

Also. I should note that DMA is not supported at all and IRQ's has never been tested. So you will not get full Soundblaster support.

However, I have tested a Soundblaster 16 configured as an Adlib card. That did work at one point. All you need then is IO 388 & 389, no IRQ or DMA. The default boot image includes Monkey Island and Wolf3D demo and they should both support Adlib.

stormyordos commented 9 months ago

Thanks for the detailed step-by-step! I was able to build the arstech branch as you described, and running the new virtualxt with root privileges and muted SDL_Audio seems to work. I've specifically tried setting the port value to 0x388, and when trying to open the Adlib channel it seems it's doing ... something.

Monkey Island works, but with the "--mute" option I couldn't say if it's really using the card. However, an old DOS demo using Adlib (the Future Crew Starport BBS intro), which was working before, now seems to hang up the emulator. It doesn't crash, but it seems deadlocked, showing a futex wait queue loop. Not sure if it has something to do with the configuration in the config file, but I'll try playing with the settings.

andreas-jonsson commented 9 months ago

I've specifically tried setting the port value to 0x388

Did you set it to port=0x388,0x389? You also have to disable the adlib module in the config file. Otherwise they will conflict.

The --mute option just skips the SDL sound device initialization. This setting should be "invisible" to the DOS environment.

I thought that intro was for 32bit CPUs? Can you send me your copy so I can try it out? :)

andreas-jonsson commented 9 months ago

I'll try playing with the settings.

All code for the ISA adapter is here https://github.com/andreas-jonsson/virtualxt/blob/arstech/modules/arstech_isa/isa.c It is only about ~100 lines so it might be easier to hardcode some settings and perhaps add some extra logging if you are doing debugging. :)

Tip! Building with make config=debug_native sdl2-frontend gives you some extra debug info and symbols.

stormyordos commented 9 months ago

I thought that intro was for 32bit CPUs? Can you send me your copy so I can try it out? :)

It's working fine in VirtualXT without the Arstech module port set to 0x388 only (which is interesting in itself), so it's definitely real mode. If you want to try it out: https://files.scene.org/view/demos/groups/future_crew/intros/starprt1.zip

andreas-jonsson commented 7 months ago

Arstech branch is merged