Skip to navigation

Elite on the BBC Micro and NES

Loader: Elite loader (Part 1 of 3)

[BBC Micro disc version, Loader 3]

Name: Elite loader (Part 1 of 3) [Show more] Type: Subroutine Category: Loader Summary: Set up the split screen mode, move code around, set up the sound envelopes and configure the system
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
.ENTRY JSR PROT1 \ Call PROT1 to calculate checksums into CHKSM LDA #144 \ Call OSBYTE with A = 144, X = 255 and Y = 0 to move LDX #255 \ the screen down one line and turn screen interlace on JSR OSB LDA #LO(B%) \ Set the low byte of ZP(1 0) to point to the VDU code STA ZP \ table at B% LDA #HI(B%) \ Set the high byte of ZP(1 0) to point to the VDU code STA ZP+1 \ table at B% LDY #0 \ We are now going to send the N% VDU bytes in the table \ at B% to OSWRCH to set up the special mode 4 screen \ that forms the basis for the split-screen mode .loop1 LDA (ZP),Y \ Pass the Y-th byte of the B% table to OSWRCH JSR OSWRCH INY \ Increment the loop counter CPY #N% \ Loop back for the next byte until we have done them BNE loop1 \ all (the number of bytes was set in N% above) JSR PLL1 \ Call PLL1 to draw Saturn LDA #16 \ Call OSBYTE with A = 16 and X = 3 to set the ADC to LDX #3 \ sample 3 channels from the joystick/Bitstik JSR OSBYTE LDA #&60 \ Store an RTS instruction in location &0232 STA &0232 LDA #&02 \ Point the NETV vector to &0232, which we just filled STA NETV+1 \ with an RTS LDA #&32 STA NETV LDA #190 \ Call OSBYTE with A = 190, X = 8 and Y = 0 to set the LDX #8 \ ADC conversion type to 8 bits, for the joystick JSR OSB LDA #200 \ Call OSBYTE with A = 200, X = 0 and Y = 0 to enable LDX #0 \ the ESCAPE key and disable memory clearing if the JSR OSB \ BREAK key is pressed LDA #13 \ Call OSBYTE with A = 13, X = 0 and Y = 0 to disable LDX #0 \ the "output buffer empty" event JSR OSB LDA #225 \ Call OSBYTE with A = 225, X = 128 and Y = 0 to set LDX #128 \ the function keys to return ASCII codes for SHIFT-fn JSR OSB \ keys (i.e. add 128) LDA #12 \ Set A = 12 and X = 0 to pretend that this is an LDX #0 \ innocent call to OSBYTE to reset the keyboard delay \ and auto-repeat rate to the default, when in reality \ the OSB address in the next instruction gets modified \ to point to OSBmod .OSBjsr JSR OSB \ This JSR gets modified by code inserted into PLL1 so \ that it points to OSBmod instead of OSB, so this \ actually calls OSBmod to calculate some checksums LDA #13 \ Call OSBYTE with A = 13, X = 2 and Y = 0 to disable LDX #2 \ the "character entering buffer" event JSR OSB LDA #4 \ Call OSBYTE with A = 4, X = 1 and Y = 0 to disable LDX #1 \ cursor editing, so the cursor keys return ASCII values JSR OSB \ and can therefore be used in-game LDA #9 \ Call OSBYTE with A = 9, X = 0 and Y = 0 to disable LDX #0 \ flashing colours JSR OSB JSR PROT3 \ Call PROT3 to do more checks on the CHKSM checksum LDA #&00 \ Set the following: STA ZP \ LDA #&11 \ ZP(1 0) = &1100 STA ZP+1 \ P(1 0) = TVT1code LDA #LO(TVT1code) STA P LDA #HI(TVT1code) STA P+1 JSR MVPG \ Call MVPG to move and decrypt a page of memory from \ TVT1code to &1100-&11FF LDA #&00 \ Set the following: STA ZP \ LDA #&78 \ ZP(1 0) = &7800 STA ZP+1 \ P(1 0) = DIALS LDA #LO(DIALS) \ X = 8 STA P LDA #HI(DIALS) STA P+1 LDX #8 JSR MVBL \ Call MVBL to move and decrypt 8 pages of memory from \ DIALS to &7800-&7FFF SEI \ Disable interrupts while we set up our interrupt \ handler to support the split-screen mode LDA VIA+&44 \ Read the 6522 System VIA T1C-L timer 1 low-order STA &0001 \ counter (SHEILA &44), which decrements one million \ times a second and will therefore be pretty random, \ and store it in location &0001, which is among the \ main game code's random seeds (so this seeds the \ random number generator for the main game) LDA #%00111001 \ Set 6522 System VIA interrupt enable register IER STA VIA+&4E \ (SHEILA &4E) bits 0 and 3-5 (i.e. disable the Timer1, \ CB1, CB2 and CA2 interrupts from the System VIA) LDA #%01111111 \ Set 6522 User VIA interrupt enable register IER STA VIA+&6E \ (SHEILA &6E) bits 0-7 (i.e. disable all hardware \ interrupts from the User VIA) LDA IRQ1V \ Copy the current IRQ1V vector address into VEC(1 0) STA VEC LDA IRQ1V+1 STA VEC+1 LDA #LO(IRQ1) \ Set the IRQ1V vector to IRQ1, so IRQ1 is now the STA IRQ1V \ interrupt handler LDA #HI(IRQ1) STA IRQ1V+1 LDA #VSCAN \ Set 6522 System VIA T1C-L timer 1 high-order counter STA VIA+&45 \ (SHEILA &45) to VSCAN (57) to start the T1 counter \ counting down from 14622 at a rate of 1 MHz CLI \ Re-enable interrupts LDA #&00 \ Set the following: STA ZP \ LDA #&61 \ ZP(1 0) = &6100 STA ZP+1 \ P(1 0) = ASOFT LDA #LO(ASOFT) STA P LDA #HI(ASOFT) STA P+1 JSR MVPG \ Call MVPG to move and decrypt a page of memory from \ ASOFT to &6100-&61FF LDA #&63 \ Set the following: STA ZP+1 \ LDA #LO(ELITE) \ ZP(1 0) = &6300 STA P \ P(1 0) = ELITE LDA #HI(ELITE) STA P+1 JSR MVPG \ Call MVPG to move and decrypt a page of memory from \ ELITE to &6300-&63FF LDA #&76 \ Set the following: STA ZP+1 \ LDA #LO(CpASOFT) \ ZP(1 0) = &7600 STA P \ P(1 0) = CpASOFT LDA #HI(CpASOFT) STA P+1 JSR MVPG \ Call MVPG to move and decrypt a page of memory from \ CpASOFT to &7600-&76FF LDA #&00 \ Set the following: STA ZP \ LDA #&04 \ ZP(1 0) = &0400 STA ZP+1 \ P(1 0) = WORDS LDA #LO(WORDS) \ X = 4 STA P LDA #HI(WORDS) STA P+1 LDX #4 JSR MVBL \ Call MVBL to move and decrypt 4 pages of memory from \ WORDS to &0400-&07FF LDX #35 \ We now want to copy the disc catalogue routine from \ CATDcode to CATD, so set a counter in X for the 36 \ bytes to copy .loop2 LDA CATDcode,X \ Copy the X-th byte of CATDcode to the X-th byte of STA CATD,X \ CATD DEX \ Decrement the loop counter BPL loop2 \ Loop back to copy the next byte until they are all \ done LDA &76 \ Set the drive number in the CATD routine to the STA CATBLOCK \ contents of &76, which gets set in ELITE3 FNE 0 \ Set up sound envelopes 0-3 using the FNE macro FNE 1 FNE 2 FNE 3 LDX #LO(MESS1) \ Set (Y X) to point to MESS1 ("DIR E") LDY #HI(MESS1) JSR OSCLI \ Call OSCLI to run the OS command in MESS1, which \ changes the disc directory to E LDA #LO(LOAD) \ Set the following: STA ZP \ LDA #HI(LOAD) \ ZP(1 0) = LOAD STA ZP+1 \ P(1 0) = LOADcode LDA #LO(LOADcode) STA P LDA #HI(LOADcode) STA P+1 LDY #0 \ We now want to move and decrypt one page of memory \ from LOADcode to LOAD, so set Y as a byte counter .loop3 LDA (P),Y \ Fetch the Y-th byte of the P(1 0) memory block EOR #&18 \ Decrypt it by EOR'ing with &18 STA (ZP),Y \ Store the decrypted result in the Y-th byte of the \ ZP(1 0) memory block DEY \ Decrement the byte counter BNE loop3 \ Loop back to copy the next byte until we have done a \ whole page of 256 bytes JMP LOAD \ Jump to the start of the routine we just decrypted