Code extract from Lancelot loader file

bbc micro/electron/atom/risc os coding queries and routines
Post Reply
User avatar
KenLowe
Posts: 4675
Joined: Mon Oct 18, 2004 5:35 pm
Location: UK
Contact:

Code extract from Lancelot loader file

Post by KenLowe »

What is this bit of code (extracted from Lancelot loader) doing??? I believe it's doing something with extended vectors, but I'm getting very confused!

Code: Select all

.everything_but_OS01_Electron
    sei                                                               ; 1225: 78          x
    lda l0dc2                                                         ; 1226: ad c2 0d    ...
    sta l0093                                                         ; 1229: 85 93       ..
    lda lffb7                                                         ; 122b: ad b7 ff    ...
    sta l0070                                                         ; 122e: 85 70       .p
    lda lffb8                                                         ; 1230: ad b8 ff    ...
    sta l0071                                                         ; 1233: 85 71       .q
    ldy lffb6                                                         ; 1235: ac b6 ff    ...
    dey                                                               ; 1238: 88          .
    bpl c123d                                                         ; 1239: 10 02       ..
    ldy #&35 ; '5'                                                    ; 123b: a0 35       .5
; &123d referenced 3 times by &1239, &1247, &124b
.c123d
    lda (l0070),y                                                     ; 123d: b1 70       .p
    sta userv,y                                                       ; 123f: 99 00 02    ...
    dey                                                               ; 1242: 88          .
    bmi c124d                                                         ; 1243: 30 08       0.
    cpy #&1f                                                          ; 1245: c0 1f       ..
    bne c123d                                                         ; 1247: d0 f4       ..
    ldy #&11                                                          ; 1249: a0 11       ..
    bne c123d                                                         ; 124b: d0 f0       ..
; &124d referenced 1 time by &1243
.c124d
    lda #0                                                            ; 124d: a9 00       ..
    ldy #&0f                                                          ; 124f: a0 0f       ..
; &1251 referenced 1 time by &125c
.loop_c1251
    cpy l0093                                                         ; 1251: c4 93       ..
    beq c125b                                                         ; 1253: f0 06       ..
    sta l02a1,y                                                       ; 1255: 99 a1 02    ...
    sta l0df0,y                                                       ; 1258: 99 f0 0d    ...
; &125b referenced 1 time by &1253
.c125b
    dey                                                               ; 125b: 88          .
    bpl loop_c1251                                                    ; 125c: 10 f3       ..
    cli                                                               ; 125e: 58          X
User avatar
Rich Talbot-Watkins
Posts: 2054
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca
Contact:

Re: Code extract from Lancelot loader file

Post by Rich Talbot-Watkins »

It's resetting all the vectors back to their OS default handlers.

&FFB6 contains the size of the default vector table, and &FFB7/&FFB8 contains a pointer to the table in the OS.

Normally I've seen this in the context of a protection system trying to ensure that you haven't installed a backdoor to protect against memory clear on Break or something like that. But it might also be because the game itself wants to ensure that there are no patched vectors because it's about to take over all the RAM and trash the extended vector table.

Haven't looked in detail, but it looks as if it might be skipping resetting the filing system vectors, so that the default tape filing system handlers don't get installed. It's also clearing out the paged ROM tables at the end; no idea why it would be doing that. I'd guess that disk filing system operations wouldn't work well if the private workspace pointers (&DF0) are cleared, so no idea there.
User avatar
KenLowe
Posts: 4675
Joined: Mon Oct 18, 2004 5:35 pm
Location: UK
Contact:

Re: Code extract from Lancelot loader file

Post by KenLowe »

Thanks for that detail. I don't think there's any particular protection here.

I'm trying to see if I can get this game running from Econet. It's designed to be run from either DFS or ADFS, so I was hoping the the switch to NFS would be fairly straight forward, but I'm running into a couple of issues; hence the reason for doing a bit of loader disassembly.

Do you know what the purpose of copying &DC2 into &93 would be at the very start of the code snippet? This is being checked later on in the code.

Edit: Ah, does &DC2 contain the ROM bank number of the current file system? That might make sense with some of the later code where it is attempting to write to every ROM bank except the for the bank number stored in &93. I think this is where the code is trying to establish which banks contain available RAM.
Rich Talbot-Watkins wrote: Mon Mar 04, 2024 5:12 pm Haven't looked in detail, but it looks as if it might be skipping resetting the filing system vectors, so that the default tape filing system handlers don't get installed. It's also clearing out the paged ROM tables at the end; no idea why it would be doing that. I'd guess that disk filing system operations wouldn't work well if the private workspace pointers (&DF0) are cleared, so no idea there.
I think it's clearing out all paged ROM tables other than the current active file system. It's trying to take control of all available RAM. If a RAM bank is writable (other than the current file system), it's claiming it - even if there's a valid ROM image in it.
User avatar
Rich Talbot-Watkins
Posts: 2054
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca
Contact:

Re: Code extract from Lancelot loader file

Post by Rich Talbot-Watkins »

KenLowe wrote: Mon Mar 04, 2024 5:37 pm Edit: Ah, does &DC2 contain the ROM bank number of the current file system? That might make sense with some of the later code where it is attempting to write to every ROM bank except the for the bank number stored in &93. I think this is where the code is trying to establish which banks contain available RAM.
Yes, I would think that's one of the filing system extended vectors, specifically the ROM bank entry. So yeah, it'd make sense to zero out everything except that bank.

I think it's probably just trying to "unplug" any paged ROM that isn't the current filing system. Some ROMs like Disc Doctor were known to interfere with certain games, so maybe this is just a way of disabling everything that it can.
Post Reply

Return to “programming”