This shows you the differences between two versions of the page.
— |
base:loading_a_file [2015-04-17 04:32] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Loading a file to memory at address stored in file ====== | ||
+ | BASIC code: | ||
+ | <code> | ||
+ | LOAD "JUST A FILENAME",8,1 | ||
+ | </code> | ||
+ | Assembler code: | ||
+ | <code> | ||
+ | LDA #fname_end-fname | ||
+ | LDX #<fname | ||
+ | LDY #>fname | ||
+ | JSR $FFBD ; call SETNAM | ||
+ | LDA #$01 | ||
+ | LDX $BA ; last used device number | ||
+ | BNE .skip | ||
+ | LDX #$08 ; default to device 8 | ||
+ | .skip LDY #$01 ; not $01 means: load to address stored in file | ||
+ | JSR $FFBA ; call SETLFS | ||
+ | |||
+ | LDA #$00 ; $00 means: load to memory (not verify) | ||
+ | JSR $FFD5 ; call LOAD | ||
+ | BCS .error ; if carry set, a load error has happened | ||
+ | RTS | ||
+ | .error | ||
+ | ; Accumulator contains BASIC error code | ||
+ | |||
+ | ; most likely errors: | ||
+ | ; A = $05 (DEVICE NOT PRESENT) | ||
+ | ; A = $04 (FILE NOT FOUND) | ||
+ | ; A = $1D (LOAD ERROR) | ||
+ | ; A = $00 (BREAK, RUN/STOP has been pressed during loading) | ||
+ | |||
+ | ... error handling ... | ||
+ | RTS | ||
+ | |||
+ | fname: .TEXT "JUST A FILENAME" | ||
+ | fname_end: | ||
+ | </code> | ||
+ | |||
+ | |||
+ | |||
+ | ====== Loading a file to memory at a specified address====== | ||
+ | BASIC code: | ||
+ | <code> | ||
+ | LOAD "JUST A FILENAME",8 | ||
+ | </code> | ||
+ | Assembler code: | ||
+ | <code> | ||
+ | load_address = $2000 ; just an example | ||
+ | |||
+ | LDA #fname_end-fname | ||
+ | LDX #<fname | ||
+ | LDY #>fname | ||
+ | JSR $FFBD ; call SETNAM | ||
+ | LDA #$01 | ||
+ | LDX $BA ; last used device number | ||
+ | BNE .skip | ||
+ | LDX #$08 ; default to device 8 | ||
+ | .skip LDY #$00 ; $00 means: load to new address | ||
+ | JSR $FFBA ; call SETLFS | ||
+ | |||
+ | LDX #<load_address | ||
+ | LDY #>load_address | ||
+ | LDA #$00 ; $00 means: load to memory (not verify) | ||
+ | JSR $FFD5 ; call LOAD | ||
+ | BCS .error ; if carry set, a load error has happened | ||
+ | RTS | ||
+ | .error | ||
+ | ; Accumulator contains BASIC error code | ||
+ | |||
+ | ; most likely errors: | ||
+ | ; A = $05 (DEVICE NOT PRESENT) | ||
+ | ; A = $04 (FILE NOT FOUND) | ||
+ | ; A = $1D (LOAD ERROR) | ||
+ | ; A = $00 (BREAK, RUN/STOP has been pressed during loading) | ||
+ | |||
+ | ... error handling ... | ||
+ | RTS | ||
+ | |||
+ | fname: .TEXT "JUST A FILENAME" | ||
+ | fname_end: | ||
+ | </code> | ||