User Tools

Site Tools


base:loading_a_file

Loading a file to memory at address stored in file

BASIC code:

LOAD "JUST A FILENAME",8,1

Assembler 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:

Loading a file to memory at a specified address

BASIC code:

LOAD "JUST A FILENAME",8

Assembler 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:
base/loading_a_file.txt · Last modified: 2015-04-17 04:32 by 127.0.0.1