passport/src/mli.a

287 lines
9.7 KiB
Plaintext
Raw Permalink Normal View History

2017-01-08 03:35:35 +00:00
; MLI command codes
CMD_CREATE = $C0 ; create new file
CMD_DESTROY = $C1 ; delete a file
2017-05-16 16:14:20 +00:00
CMD_GETFILEINFO = $C4 ; get file (or volume) info
CMD_ONLINE = $C5 ; check online volume(s)
2021-04-08 14:55:52 +00:00
;CMD_SETPREFIX = $C6 ; change default pathname prefix
2017-01-08 03:35:35 +00:00
CMD_OPEN = $C8 ; open a file
2021-04-08 14:55:52 +00:00
;CMD_NEWLINE = $C9 ; set line-by-line read mode
2017-01-08 03:35:35 +00:00
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
2017-06-23 03:50:39 +00:00
CMD_SETEOF = $D0 ; set file size
2017-01-08 03:35:35 +00:00
; MLI parameter counts
PC_CREATE = $07
PC_DESTROY = $01
2017-05-16 16:14:20 +00:00
PC_GETFILEINFO = $0A
PC_ONLINE = $02
2021-04-08 14:55:52 +00:00
;PC_SETPREFIX = $01
2017-01-08 03:35:35 +00:00
PC_OPEN = $03
2021-04-08 14:55:52 +00:00
;PC_NEWLINE = $03
2017-01-08 03:35:35 +00:00
PC_READ = $04
PC_WRITE = $04
PC_CLOSE = $01
PC_SETMARK = $02
2017-06-23 03:50:39 +00:00
PC_SETEOF = $02
2017-01-08 03:35:35 +00:00
; MLI constants
FULL_ACCESS = $C3
2021-04-14 01:09:55 +00:00
2017-01-08 03:35:35 +00:00
; MLI error codes
2021-04-20 03:48:41 +00:00
MLI_IOERR = $27
MLI_NODEV = $28
MLI_WRITEPROT = $2B
2017-01-08 03:35:35 +00:00
ERR_FNF = $46
ERR_EOF = $4C
2021-04-14 01:09:55 +00:00
ERR_EXIST = $47
2017-01-08 03:35:35 +00:00
;-------------------------------
; open file via ProDOS MLI
;
; in: ProDOS is in memory
; caller has filled @mliparam with address of
2021-06-19 04:59:28 +00:00
; 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
2021-06-19 04:59:28 +00:00
; file reference number
; preserves X
; ProDOS is in memory
;-------------------------------
2017-01-08 03:35:35 +00:00
OpenFile
lda #CMD_OPEN ; MLI command
ldy #PC_OPEN ; number of parameters for 'open' command
jsr mli
bcs +
2017-01-08 03:35:35 +00:00
lda refnum ; caller should save file reference number
; as this memory location may be
; overwritten by later MLI calls
+ rts
2017-01-08 03:35:35 +00:00
;-------------------------------
; read an open file via ProDOS MLI
;
2021-06-19 04:59:28 +00:00
; in: ProDOS is in memory
; A = file reference number
; caller has filled @mliparam with address of
2017-01-08 03:35:35 +00:00
; data buffer and maximum data length
2021-06-19 04:59:28 +00:00
; out: if C set, read failed and A contains error code
; if C clear, read succeeded and A contains the same
2017-01-08 03:35:35 +00:00
; file reference number that was passed in
2021-06-19 04:59:28 +00:00
; preserves X
; ProDOS is in memory
2017-01-08 03:35:35 +00:00
;-------------------------------
ReadFile
sta mliparam+1 ; store file reference number
lda #CMD_READ ; MLI read command
ldy #PC_READ ; number of parameters for 'read' command
2021-06-18 01:23:50 +00:00
JsrMLIAndReturnPlus1
2017-01-08 03:35:35 +00:00
jsr mli
bcs +
2017-01-08 03:35:35 +00:00
lda mliparam+1 ; if no error, return file reference number
+ rts
2017-01-08 03:35:35 +00:00
;-------------------------------
; change file position in an open file via ProDOS MLI
;
2021-06-19 04:59:28 +00:00
; in: A = file reference number
; caller has filled @mliparam+2/+3/+4 with
2017-01-08 03:35:35 +00:00
; new file position
2021-06-19 04:59:28 +00:00
; out: if C set, set_mark call failed and A contains error code
; if C clear, set_mark call succeeded and A contains
2017-01-08 03:35:35 +00:00
; the same file reference number that was passed in
2021-06-19 04:59:28 +00:00
; preserves X
2017-01-08 03:35:35 +00:00
;-------------------------------
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
2021-07-11 00:53:57 +00:00
bne JsrMLIAndReturnPlus1 ; always branches
2017-01-08 03:35:35 +00:00
;-------------------------------
; write to an open file via ProDOS MLI
;
2021-06-19 04:59:28 +00:00
; in: A = file reference number
; caller has filled @mliparam with address of
2017-01-08 03:35:35 +00:00
; data buffer and data length
2021-06-19 04:59:28 +00:00
; out: if C set, write failed and A contains error code
; if C clear, write succeeded and A contains the same
2017-01-08 03:35:35 +00:00
; file reference number that was passed in
2021-06-19 04:59:28 +00:00
; preserves X
2017-01-08 03:35:35 +00:00
;-------------------------------
WriteFile
sta mliparam+1 ; store file reference number
lda #CMD_WRITE ; MLI write command
ldy #PC_WRITE ; number of parameters for 'write' command
2021-07-11 00:53:57 +00:00
bne JsrMLIAndReturnPlus1 ; always branches
2017-01-08 03:35:35 +00:00
2017-06-23 03:50:39 +00:00
;-------------------------------
; set file size in an open file via ProDOS MLI
;
2021-06-19 04:59:28 +00:00
; in: A = file reference number
; caller has filled @mliparam+2/+3/+4 with
2017-06-23 03:50:39 +00:00
; new file size
2021-06-19 04:59:28 +00:00
; out: if C set, set_eof call failed and A contains error code
; if C clear, set_eof call succeeded and A contains
2017-06-23 03:50:39 +00:00
; the same file reference number that was passed in
2021-06-19 04:59:28 +00:00
; preserves X
2017-06-23 03:50:39 +00:00
;-------------------------------
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
2021-07-11 00:53:57 +00:00
bne JsrMLIAndReturnPlus1 ; always branches
2017-06-23 03:50:39 +00:00
2017-05-16 16:14:20 +00:00
;-------------------------------
; get volume name of disk in specific slot+drive
2021-06-19 04:59:28 +00:00
;
; 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
2017-05-16 16:14:20 +00:00
;-------------------------------
GetVolumeName
sta mliparam+1
lda #<OnlineReturn
sta mliparam+2
lda #>OnlineReturn
sta mliparam+3
2021-06-18 00:52:42 +00:00
; /!\ execution falls through here
2017-05-16 16:14:20 +00:00
;-------------------------------
; check if volume is online
2021-06-19 04:59:28 +00:00
;
; in: caller has filled @mliparam with unit number
; out: if error, C set and A contains error code
; if success, C clear
; preserves X
2017-05-16 16:14:20 +00:00
;-------------------------------
Online
lda #CMD_ONLINE
ldy #PC_ONLINE
2021-07-11 00:53:57 +00:00
bne mli ; always branches
2017-05-16 16:14:20 +00:00
2017-06-23 03:50:39 +00:00
;-------------------------------
; query volume information
2021-06-19 04:59:28 +00:00
;
; 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)
2021-06-19 04:59:28 +00:00
; clobbers X/Y
2017-06-23 03:50:39 +00:00
;-------------------------------
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
2021-06-18 01:27:39 +00:00
; /!\ execution falls through here
2021-04-14 01:09:55 +00:00
GetFileInfo
2017-06-23 03:50:39 +00:00
lda #CMD_GETFILEINFO
ldy #PC_GETFILEINFO
2021-06-18 01:27:39 +00:00
; /!\ execution falls through here
2017-06-23 03:50:39 +00:00
2017-01-08 03:35:35 +00:00
;-------------------------------
; 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
2021-06-18 01:31:03 +00:00
;-------------------------------
; 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
2021-06-19 04:59:28 +00:00
; preserves X
2021-06-18 01:31:03 +00:00
; 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
2021-06-19 04:59:28 +00:00
; preserves X
2021-06-18 01:31:03 +00:00
; ProDOS is in memory
;-------------------------------
DeleteFile
lda #CMD_DESTROY ; MLI destroy command
ldy #PC_DESTROY ; number of parameters for 'destroy' command
bne mli ; always branches
;-------------------------------
2021-06-19 00:26:26 +00:00
; CreateDir/CreateBinFile/CreateTxtFile
2021-06-18 01:31:03 +00:00
;
; 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
2021-06-19 04:59:28 +00:00
; preserves X
2021-06-18 01:31:03 +00:00
;-------------------------------
CreateDir
lda #$0D
ldy #$0F
2021-06-19 00:26:26 +00:00
bne + ; always branches
CreateBinFile
ldy #$06
!byte $2C
CreateTxtFile
ldy #$04
lda #$01
2021-07-11 00:53:57 +00:00
+ pha ; storage type (directory or file)
2021-06-18 01:31:03 +00:00
sty mliparam+4 ; file type (directory or binary)
lda #FULL_ACCESS
sta mliparam+3 ; access bits (full access)
lda #0
2021-07-11 00:53:57 +00:00
ldy #6
- sta mliparam+5,y ; aux type (none) + creation datetime (current)
dey
bpl -
pla
sta mliparam+7 ; storage type (directory or file)
2021-06-18 01:31:03 +00:00
lda #CMD_CREATE ; MLI create command
ldy #PC_CREATE ; number of parameters for 'create' command
bne mli ; always branches