passport/src/mli.a
2021-06-19 00:59:28 -04:00

287 lines
9.6 KiB
Plaintext
Executable File

; MLI command codes
CMD_CREATE = $C0 ; create new file
CMD_DESTROY = $C1 ; delete a file
CMD_GETFILEINFO = $C4 ; get file (or volume) info
CMD_ONLINE = $C5 ; check online volume(s)
;CMD_SETPREFIX = $C6 ; change default pathname prefix
CMD_OPEN = $C8 ; open a file
;CMD_NEWLINE = $C9 ; set line-by-line read mode
CMD_READ = $CA ; read an open file
CMD_WRITE = $CB ; write to an open file
CMD_CLOSE = $CC ; close an open file
CMD_SETMARK = $CE ; change position in an open file
CMD_SETEOF = $D0 ; set file size
; MLI parameter counts
PC_CREATE = $07
PC_DESTROY = $01
PC_GETFILEINFO = $0A
PC_ONLINE = $02
;PC_SETPREFIX = $01
PC_OPEN = $03
;PC_NEWLINE = $03
PC_READ = $04
PC_WRITE = $04
PC_CLOSE = $01
PC_SETMARK = $02
PC_SETEOF = $02
; MLI constants
FULL_ACCESS = $C3
; MLI error codes
MLI_IOERR = $27
MLI_NODEV = $28
MLI_WRITEPROT = $2B
ERR_FNF = $46
ERR_EOF = $4C
ERR_EXIST = $47
;-------------------------------
; open file via ProDOS MLI
;
; in: ProDOS is in memory
; caller has filled @mliparam with address of
; pathname, address of data buffer, and maximum
; data length
; out: if C set, open failed and A contains error code
; if C clear, open succeeded and A contains
; file reference number
; preserves X
; ProDOS is in memory
;-------------------------------
OpenFile
lda #CMD_OPEN ; MLI command
ldy #PC_OPEN ; number of parameters for 'open' command
jsr mli
bcs +
lda refnum ; caller should save file reference number
; as this memory location may be
; overwritten by later MLI calls
+ rts
;-------------------------------
; read an open file via ProDOS MLI
;
; in: ProDOS is in memory
; A = file reference number
; caller has filled @mliparam with address of
; data buffer and maximum data length
; out: if C set, read failed and A contains error code
; if C clear, read succeeded and A contains the same
; file reference number that was passed in
; preserves X
; ProDOS is in memory
;-------------------------------
ReadFile
sta mliparam+1 ; store file reference number
lda #CMD_READ ; MLI read command
ldy #PC_READ ; number of parameters for 'read' command
JsrMLIAndReturnPlus1
jsr mli
bcs +
lda mliparam+1 ; if no error, return file reference number
+ rts
;-------------------------------
; change file position in an open file via ProDOS MLI
;
; in: A = file reference number
; caller has filled @mliparam+2/+3/+4 with
; new file position
; out: if C set, set_mark call failed and A contains error code
; if C clear, set_mark call succeeded and A contains
; the same file reference number that was passed in
; preserves X
;-------------------------------
SetMark
sta mliparam+1 ; store file reference number
lda #CMD_SETMARK ; MLI set_mark command
ldy #PC_SETMARK ; number of params for 'set_mark' cmd
bne JsrMLIAndReturnPlus1
;-------------------------------
; write to an open file via ProDOS MLI
;
; in: A = file reference number
; caller has filled @mliparam with address of
; data buffer and data length
; out: if C set, write failed and A contains error code
; if C clear, write succeeded and A contains the same
; file reference number that was passed in
; preserves X
;-------------------------------
WriteFile
sta mliparam+1 ; store file reference number
lda #CMD_WRITE ; MLI write command
ldy #PC_WRITE ; number of parameters for 'write' command
bne JsrMLIAndReturnPlus1
;-------------------------------
; set file size in an open file via ProDOS MLI
;
; in: A = file reference number
; caller has filled @mliparam+2/+3/+4 with
; new file size
; out: if C set, set_eof call failed and A contains error code
; if C clear, set_eof call succeeded and A contains
; the same file reference number that was passed in
; preserves X
;-------------------------------
SetEOF
sta mliparam+1 ; store file reference number
lda #CMD_SETEOF ; MLI set_eof command
ldy #PC_SETEOF ; number of params for 'set_eof' cmd
bne JsrMLIAndReturnPlus1
;-------------------------------
; get volume name of disk in specific slot+drive
;
; in: A = unit number (DSSS0000)
; out: if no disk in drive or any MLI error, C set and A contains error code
; if disk found, C clear and @VolumeName contains volume name
; (up to 15 character name, no leading slash)
; note: lower 4 bits of @OnlineReturn contain length of @VolumeName
; preserves X
;-------------------------------
GetVolumeName
sta mliparam+1
lda #<OnlineReturn
sta mliparam+2
lda #>OnlineReturn
sta mliparam+3
; /!\ execution falls through here
;-------------------------------
; check if volume is online
;
; in: caller has filled @mliparam with unit number
; out: if error, C set and A contains error code
; if success, C clear
; preserves X
;-------------------------------
Online
lda #CMD_ONLINE
ldy #PC_ONLINE
bne mli
;-------------------------------
; query volume information
;
; in: @OnlineReturn+@VolumeName contain the length+name of the volume to query
; (this will be true if you just called GetVolumeName)
; out: if error, C set and A contains error code
; if success, C clear and MLI buffer is filled
; (access, file type, block count, dates and times)
; clobbers X/Y
;-------------------------------
GetVolumeInfo
lda OnlineReturn
and #$0F
tax
inx
stx OnlineReturn
tay
- lda OnlineReturn,y
sta VolumeName,y
dey
bne -
lda #$2F ;'/'
sta VolumeName
lda #<OnlineReturn
sta mliparam+1
lda #>OnlineReturn
sta mliparam+2
; /!\ execution falls through here
GetFileInfo
lda #CMD_GETFILEINFO
ldy #PC_GETFILEINFO
; /!\ execution falls through here
;-------------------------------
; low-level MLI wrapper
; in: A = MLI command code
; Y = number of MLI parameters
; caller has filled @mliparam
; with all relevant parameters
; out: returns immediately after
; calling MLI, so whatever
; state the MLI routine sets,
; the caller will see it
; verbatim
;-------------------------------
mli sta mlicmd ; store command code
sty mliparam ; number of parameters
jsr PRODOSMLI ; call ProDOS
mlicmd !byte 00 ; command number
!word mliparam ; address of parameter table
rts
;-------------------------------
; close an open file
; in: ProDOS is in memory
; A = file reference number
; out: if error, C set and A contains error code
; if success, C clear
; preserves X
; ProDOS is in memory
;-------------------------------
CloseFile
sta mliparam+1 ; store file reference number
lda #CMD_CLOSE ; MLI close command
ldy #PC_CLOSE ; number of parameters for 'close' command
bne mli ; always branches
;-------------------------------
; DeleteFile
; delete a file using ProDOS MLI
;
; in: ProDOS is in memory
; caller has filled @mliparam+1 with address of pathname
; out: if error, C set and A contains error code
; if success, C clear
; preserves X
; ProDOS is in memory
;-------------------------------
DeleteFile
lda #CMD_DESTROY ; MLI destroy command
ldy #PC_DESTROY ; number of parameters for 'destroy' command
bne mli ; always branches
;-------------------------------
; CreateDir/CreateBinFile/CreateTxtFile
;
; create a directory or file via ProDOS MLI
; always sets access bits to $C3 (full access)
; always sets creation to 0 (current date/time)
; in: caller has filled @mliparam+1 with address of pathname
; out: if error, C set and A contains error code
; if success, C clear and A clobbered
; preserves X
;-------------------------------
CreateDir
lda #$0D
ldy #$0F
bne + ; always branches
CreateBinFile
ldy #$06
!byte $2C
CreateTxtFile
ldy #$04
lda #$01
+ sta mliparam+7 ; storage type (directory or file)
sty mliparam+4 ; file type (directory or binary)
lda #FULL_ACCESS
sta mliparam+3 ; access bits (full access)
lda #0
sta mliparam+5 ; aux type (none)
sta mliparam+6
sta mliparam+8 ; creation date (current)
sta mliparam+9
sta mliparam+10 ; creation time (current)
sta mliparam+11
lda #CMD_CREATE ; MLI create command
ldy #PC_CREATE ; number of parameters for 'create' command
bne mli ; always branches