Everything

FOPEN


Opens a file.

[Function Code (R1 Register)]

[Parameter Block (R2 Register)]

[Parameters]

Parameter

Description

Execution result (output)

0: Terminated normally

-1: Error

File number (output)

Number that is used for access to files after the open process

Open mode (input)

0x00: "r"

0x01: "w"

0x02: "a"

0x03: "r+"

0x04: "w+"

0x05: "a+"

0x10: "rb"

0x11: "wb"

0x12: "ab"

0x13: "r+b"

0x14: "w+b"

0x15: "a+b"

The content of each mode is as follows:

"r": Opens for read.

"w": Opens a blank file for write.

"a": Opens for write from the end of a file.

"r+": Opens for read and write.

"w+": Reads a blank file and opens it for write.

"a+": Opens additionally for read.

"b": Opens in binary mode.

Beginning address of file name (input)

Beginning address of the area that contains the file name

[Detailed Description]

-

When a file is opened by [FOPEN], a file number is returned.
This file number is used in subsequent operations to input or output to the file, as well as to close the file.

-

Up to 256 files can be opened at a time.

[Example]

_fileopen:
        MOV.L       R2,R5         ; Set the value of R2 (open mode) in R5.
        MOV.L       #PARM,R2      ; Set the address of the parameter block in R2.
        MOV.L       R1,4h:5[R2]   ; Set the value of R1 (first address of the 
                                  ; filename) in R2 + 4 bytes.
        MOV.B       R5,2h:5[R2]   ; Set the value of R5 in R2 + 2 bytes (open mode).
        MOV.L       #01250000h,R1 ; Set the function code of FOPEN in R1.
        MOV.L       #SIM_IO,R5    ; Set the address of the system call in R5.
        JSR         R5            ; System call
        NOP
        MOV.L       #PARM,R2      ; Set the address of the parameter block in R3.
        MOV.B       1h:5[R2],R1   ; Set the value of R2 + 1 byte (file number) in R1.
        MOV.B       R1,[R3]       ; Set the value of R1 in the location pointed to 
                                  ; by R3 (file number pointer).
        MOV.B       [R2],R1   ; Set the first byte of R2 (result of execution) in R1.
        RTS                   ; Return to the address where the function was called.
 
         .SECTION  B,DATA,ALIGN=4
PARM:       .BLKL   2             ; Parameter block area