Trap #2 Codes
D0Description
$01IO_OPEN / IOA_OPENOpen a file
$02IO_CLOSE / IOA_CLOSClose a file
$03IO_FORMT / IOA_FRMTFormat a medium
$04IO_DELET / IOA_DELFDelete a file



IO_OPEN / IOA_OPEN - Open a file.
TRAP #2
D0 = $01
Call ParametersReturn Parameters
D1.L Job id of job to own the file.
-1 = current job.
D1.L Preserved
D3.L Open type code where :

0 = OPEN
1 = OPEN_IN
2 = OPEN_NEW
3 = OPEN_OVER (Not on microdrives)
4 = OPEN_DIR

Or the ID for an already opened PIPE file.
D3.L Preserved
A0 Pointer to file name in QDOS format. A0.L Channel ID for opened file.
Errors returned in D0.L :

ERR_NJ - Invalid job id
ERR_OM - Out of memory
ERR_NO - channel not open
ERR_NF - File or device not found
ERR_EX - File already exists
ERR_IU - File in use
ERR_BN - Bad file or device name.
Notes :

All registers not shown above are not used on entry and are preserved on exit, except :

D2.L is supposed to be preserved but according to an article in December 1986 QL World, this may not always be the case.
A1.L is corrupted if TRAP #4 was called prior to this trap call.

Example

The following shows the use of this call to open a file :

        moveq   #io_open,d0       ; Trap code
        moveq   #-1,d1            ; The current job will own the file
        moveq   #0,d3             ; SuperBasic OPEN mode
        lea     name,a0           ; Pointer to name of file
        trap    #2                ; Open the file
        tst.l   d0                ; Test for errors
        bne.s   <Error handler>   ; Oops, an error occurred
        <do stuff here with channel id in A0.L>
        :
        :
name    dc.w    4                 ; Length of filename
        dc.b    "CON_"            ; Bytes of actual filename

Back to top

IO_CLOSE / IOA_CLOS - Close a file.
TRAP #2
D0 = $02
Call ParametersReturn Parameters
A0.L Channel id to close. A0.L Corrupted.
Errors returned in D0.L :

ERR_NO - Channel not open.
Notes :

All registers not shown above are not used on entry and are preserved on exit.
Usually, the ERR_NO return in D0 is ignored and no action is taken.

Example

The following shows the use of this call to close a file :

        moveq   #io_close,d0      ; Trap code
        trap    #2                ; Open the file
        <Ignore errors in D0, if any, and carry on.>
        :
        :	

Back to top

IO_FORMT / IOA_FRMT - Format a medium.
TRAP #2
D0 = $03
Call ParametersReturn Parameters
D1 Unused D1.W Number of good sectors.
D2 Unused D2.W Total number of sectors, including bad ones.
A0.L Pointer to medium name A0.L Corrupted
Errors returned in D0.L :

ERR_OM - Out of memory
ERR_FF - Format failed
ERR_NF - File or device not found
ERR_IU - File in use
Notes :

All registers not shown above are not used on entry and are preserved on exit.
The medium name is allowed to be 10 characters in length after the device name.
In recent years, with the introduction of hard drives, the return values in D1 and D2 may need to be multiplied.

Example

The following shows the use of this call to format a medium :

        moveq   #io_formt,d0      ; Trap code
        lea     name,a0           ; Pointer to name of medium
        trap    #2                ; Do the format
        tst.l   d0                ; Test for errors
        bne.s   <Error handler>   ; The format has failed.
        <Carry on here - the format worked.>
        :
        :
name    dc.w    12                ; Length of filename
        dc.b    "FLP1_Backups"    ; Bytes of actual filename

Back to top

IO_DELET / IOA_DELF - Delete a file.
TRAP #2
D0 = $04
Call ParametersReturn Parameters
D1.L Job id of the job deleting the file D1.L Corrupted
D3 Unused D3.L Corrupted
A0.L Pointer to file name A0.L Corrupted
Errors returned in D0.L :

ERR_OM - Out of memory
ERR_NO - channel not open
ERR_NF - File or device not found
ERR_BN - Bad file or device name.
Notes :

All registers not shown above are not used on entry and are preserved on exit.

Example

The following shows the use of this call to delete a file :

        moveq   #io_delet,d0      ; Trap code
        moveq   #-1,d1            ; This job will delete the file
        lea     name,a0           ; Pointer to the filename
        trap    #2                ; Delete the file
        tst.l   d0                ; Test for errors
        bne.s   <Error handler>   ; The deletion has failed.
        <Carry on here - the deletion worked.>
        :
        :
name    dc.w    14                ; Length of filename
        dc.b    "FLP1_scrap_txt"    ; Bytes of actual filename

Back to top