| Load routines

5DF7: After the program 'samcruise' has loaded, this is where it all starts...

| This is the initial loader program for Contact Sam Cruise (as it appears after doing 'POKE 23762,0' to change the INK for the BASIC listing from white to black). Don't be fooled by the 'RANDOMIZE USR 23794': the floating point number stored underneath is actually 5DF7.
Entering the code here from BASIC means that C=0xF7 (the LSB of 5DF7); this value is used later on in the routine at 802F.
5DF7 | JP $5D17 | Jump to where it really starts
And this is where it really starts.
5D17 | DI | Disable interrupts
5D18 | LD B,$31 |
5D1A | LD DE,$FFCF |
5D1D | CALL $5DEF |
And so begins the misdirection.
5DEF | POP HL | HL=5D20
5DF0 | ADD HL,DE | HL=5CEF
5DF1 | PUSH HL |
5DF2 | LD DE,$0007 |
5DF5 | ADD HL,DE | HL=5CF6
5DF6 | RET | Jump to 5CEF
Undo some code obfuscation before continuing.
5CEF | LD A,(HL) | Do some XOR-ing on the 49 bytes from 5CF6 to 5D26
5CF0 | XOR H
5CF1 | XOR L
5CF2 | LD (HL),A
5CF3 | INC HL
5CF4 | DJNZ $5CEF
After the XOR-ing:
5CF6 | EXX |
5CF7 | EX (SP),HL | HL'=2D2B
5CF8 | LD A,H | A=0x2D
5CF9 | AND L | A=0x29
5CFA | ADD A,L | A=0x54
5CFB | ADD A,L | A=0x7F
5CFC | LD H,A | H'=0x7F
5CFD | ADD A,$4E | A=0xCD
5CFF | LD L,A | HL'=7FCD
5D00 | EXX |
5D01 | LD HL,$5BFF | INK 1: PAPER 1
5D04 | LD (HL),$09
5D06 | DEC HL
5D07 | BIT 3,H
5D09 | JR NZ,$5D04
5D0B | LD (HL),$00 | Clear the display file
5D0D | DEC HL
5D0E | BIT 6,H
5D10 | JR NZ,$5D0B
5D12 | INC E | DE=0009
5D13 | INC E
5D14 | CALL $5DEF |
More misdirection.
5DEF | POP HL | HL=5D17
5DF0 | ADD HL,DE | HL=5D20
5DF1 | PUSH HL |
5DF2 | LD DE,$0007 |
5DF5 | ADD HL,DE | HL=5D27
5DF6 | RET | Jump to 5D20
Undo some more code obfuscation before continuing.
5D20 | LD A,(HL) | Do some XOR-ing and RLC-ing on the 217 bytes from 5D27 to 5DFF
5D21 | XOR E
5D22 | RLCA
5D23 | LD (HL),A
5D24 | INC L
5D25 | JR NZ,$5D20
After the XOR-ing and RLC-ing:
5D27 | PUSH HL | HL=5D00
5D28 | EXX |
5D29 | POP DE | DE'=5D00
5D2A | EX DE,HL | DE'=7FCD
5D2B | LD BC,$00FF | Copy 255 bytes from 5D00-5DFE to 7FCD-80CB
5D2E | LDIR
5D30 | LD E,A | E'=0x2F
5D31 | EX DE,HL | HL'=802F
5D32 | JP (HL) | Jump to 802F