Unexpected ENASLT Behavior

Par NetNomad

Resident (52)

Portrait de NetNomad

03-04-2022, 21:44

Hello! I'm working on a project right now and have ran into some strange behavior using ENASLT on the openMSX Boosted Turbo-R with IDE. I've tried a few machines and I've only been able to replicate it on that machine, and only when paging in primary slot 2, which instead pages in subslot 2:3. While debugging it I put together a terrible graphic on the issue but will also explain here. My calling codee\:

ld hl, #4000
ld a,(SlotId)
call ENASLT

Even though I'm doing it in a DOS environment I'm using the BIOS address (0021) because there are only nops between that and the DOS address (0024), but I have tried using the DOS address directly and it makes no difference (the goal is for the routine that's calling ENASLT to work the same whether you're under the BIOS or DOS). Following the BIOS call in the debugger, the code is identical between the Boosted Turbo-R, Canon V-20, and Panasonic FSA1-GT with two differences. For one, the code is in different places, so the jump values are different. But the other is one single constant. All three ENASLT routines have the same sequence in them towards the middle of the routine:

rrca
rrca
rrca
and #0c
or d
ld e,a
ld d,#00
ld hl,constant
add hl,de
add hl,de

The only difference is that the constant is different across the three machines. I've tried editing it in the debugger and replacing the constant used in the Boosted machine with both the one used on the Canon and the one used on the Panasonic but both lead to the program hanging, they don't even get as far as paging in the right or wrong slot.

I'm totally stumped. I could very well be doing something wrong but it doesn't seem like there's a lot of room to mess up calling ENASLT, as far as I can tell looking at the routine and the wiki here and MAP, only those two registers are used. And watching it in the debugger, the values of every single register except for R are identical up until that constant is loaded on all three machines, even the stack pointer. I also tested a few other machines but I didn't write them down or follow them closely in the debugger, off the top of my head I can tell you ENASLT worked as expected on the CX5MII and Boosted MSX2+. I also confirmed that the Canon V-20 works just as well on the real deal as the emulator.

If I'm not doing something wrong, and if this is only occurring on one machine, it would make sense that this is a bug in the machine. But trying to fix the bug by replacing that one different constant seems to only make things worse. Granted I also don't know that the constant represents in the first place or why it's different between different machines that have ENASLT functioning correctly when the rest of the routine is otherwise essentially identical. But I also know that the Boosted Turbo-R is a pretty popular machine and reading the forum it seems like I'm the first person to encounter this issue, so from that angle is makes more sense that I'm doing something wrong and that this issue is limited to just my program. But what??

If anyone's curious, here's a disk with the misbehaving program on it. Throw an SFG-01 or 05 into slot 2 and you'll get a jingle ENASLT worked as expected and it'll hang if not. This is for a music replayer I am hoping to be done with and share here soon- once it actually works regardless of slot configuration.

Sorry if this explanation is a bit of a mess, but any insight or advice would be very appreciated. This is driving me up the wall. Thank you for reading! :)

!login ou Inscrivez-vous pour poster

Par Grauw

Ascended (10821)

Portrait de Grauw

03-04-2022, 23:00

Two things come to mind;

First, you need to manually enable interrupts after ENASLT.

Second, make sure that you calculate the slot ID correctly. The upper bit that indicates an expanded slot must not be set if the slot is not expanded, otherwise it will corrupt memory, and if the slot is expanded it must be set, otherwise an arbitrary subslot will be selected. The expanded status of each primary slot can be read from EXPTBL.

Par NetNomad

Resident (52)

Portrait de NetNomad

05-04-2022, 05:19

Thank you! In my detection routine, I was just brute forcing all the different valid slot IDs. It turns out the Boosted Turbo-R doesn't even have a primary slot 2 (it has three cartridge slots mapped to 1, 2:0 and 2:1), but my detection routine was passing 2 to RDSLT which was switching to 2:0 i guess and found the detection string, so the program wrote down 2. Then passed that to ENASLT which switched to 2:3 because there is no 2. Now instead of checking all the primary slots and then secondary slots subsequently, it uses EXPTBL to skip right to the subslot needbe and suddenly the problem is all gone! Thank you again!

Par Grauw

Ascended (10821)

Portrait de Grauw

05-04-2022, 20:12

👍