QDOS Internals

Anything you never knew you wanted to know about the Sinclair QL.

User Tools

Site Tools


Table of Contents


This trap loads a file into memory.

Call ParametersReturn Parameters
D0.B$48D0.LError code.
D1.L D1.LCorrupted.
D2.LLength of file. D2.LPreserved.
A0.LChannel ID. A0.LPreserved.
A1.LAddress for load.A1.L1 past the location of the last byte.


ERR_NOChannel not open.


  • All registers not shown above are not used on entry and are preserved on exit.
  • The space to which the file is loaded would normally have been allocated by Trap #1 MT_ALCHP/SMS_ACHP.
  • D3.W should always be set to -1 for a successful load.
  • The loading is done by "random access" not serially as with IO_FSTRG/IOB_FMUL. Perhaps for this reason it appears that if D2.L is set to a number not equal to the file length the whole file is nevertheless loaded.


The example shows how to load a file called WIN1_FILE. There are two error exits, error and error1. The first does not have to tidy the stack; the second does.

fl      dc.w    fl_e-2          ; Length of filename
        dc.b    "win1_file"     ; Name
fl_e    ds.b    0               ; Label at end of name
        ds.w    0               ; Set to even byte

load_f  moveq   #0,d3           ; OPEN
        lea     fl,a0           ; Filename to A0
        moveq   #-1,d1          ; This job
        moveq   #IO_OPEN,d0
        trap    #2              ; Open the file
        tst.l   d0              ; OK? . .
        bne     error ---->     ; . . no!
        movea.l a0,a5           ; Keep the ID in A5
; A0 now has the file ID.
; We now look at the header to get the length of the file.
        lea     -64(a7),a7      ; Space for the header.
        moveq   #64,d2          ; Length of space for header.
        movea.l a7,a1           ; Address for header.
        moveq   #-1,d3          ; Timeout.
        moveq   #FS_HEADR,d0
        trap    #3              ; Read the header.
        tst.l   d0              ; OK? . .
        bne     error1 ---->    ; . . no!
; The header is now on the stack.
        move.l  (a7),d1         ; File's length.
        moveq   #-1,d2          ; This job
        moveq   #MT_ALCHP,d0
        trap    #1              ; Get the space.
        tst.l   d0              ; OK? . .
        bne     error1 ---->    ; . . no!
; Now A0 points to the allocated space and A5 to the file's ID
; We will now load the file.
        move.l  (a7),d2         ; File's length
        lea     64(a7),a7       ; Tidy the stack
        moveq   #-1,d3          ; Timeout.
        movea.l a0,a1           ; Address for loading.
        movea.l a5,a0           ; Replace the ID
        moveq   #FS_LOAD,d0
        trap    #3              ; Load the file.
        tst.l   d0              ; OK? . .
        bne     error ---->     ; . . no!
        moveq   #IO_CLOSE,d0
        tst.l   d0              ; OK? . .
        bne     error ---->     ; . . no!

; There should be no error here, but it it JUST possible that
; someone else has closed the file before our attempt to do so!
; The file is now loaded.                  
qdosmsq/traps/trap_3/load.txt · Last modified: 2009/02/21 17:38 by george.gwilt