AppleIIAsm-Collection/disks/disk5_fileio/T.FILEIO.LIB
nathanriggs d1e8429d80 added disk 5, file input and output, rwts routines
This will be the last addition to the library before going through major revisions and then a major demo of libraries so far.
2018-11-16 21:47:02 -05:00

683 lines
16 KiB
Plaintext

*
*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*
* *
* FILE INPUT/OUTPUT LIBRARY *
* *
* AUTHOR: NATHAN RIGGS *
* CONTACT: NATHAN.RIGGS@ *
* OUTLOOK.COM *
* *
* VERSION: 0.1.2 *
* DATE: 30-OCT-2018 *
* ASSEMBLER: MERLIN 8 PRO *
* *
* LICENSE: APACHE 2.0, WHERE *
* APPLICABLE. CODE INSPIRED *
* BY THE WORKS OF OTHERS MAY *
* FALL UNDER A DIFFERENT *
* LICENSE (NOTED IN ROUTINE). *
* *
* *
*------------------------------*
* *
* LIST OF ROUTINES *
* *
* BSAVE : SAVE BINARY FILE *
* BLOAD : LOAD BINARY FILE *
* TMODE : TEXT FILE OPS MODE *
* CMD : EXEC DOS COMMAND *
* TMODE : SET TEXT IO MODE *
* FPRINT : PRINT TO FILE *
* FPSTR : FILE PRINT STRING *
* FINPUT : GET LINE FROM TEXTF *
* *
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*
*
*``````````````````````````````*
* BSAVE :: BINARY SAVE *
*- -*
* SIMPLY DOES A BINARY SAVE *
* WITH THE COMMAND LINE PARAMS *
* SPECIFIED IN THE STRING AT *
* THE GIVEN ADDRESS. *
*- -*
* CLOBBERS: *
* *
* FLAGS: ????---- REG: AXYM *
*- -*
* CYCLES: ??? *
* SIZE: *
*- -*
* USAGE: *
* *
* LDA #>SADDR ; STRING ADDR *
* PHA *
* LDA #<SADDR *
* PHA *
* JSR BSAVE *
*- -*
* ENTRY *
* *
* TOP OF STACK *
* *
* LOW BYTE OF RETURN ADDRESS *
* HI BYTE OF RETURN ADDRESS *
* LO BYTE OF STRING ADDRESS *
* HI BYTE OF STRING ADDRESS *
*- -*
* EXIT *
* *
* TOP OF STACK *
* *
* LOW BYTE OF RETURN ADDRESS *
* HI BYTE OF RETURN ADDRESS *
* *
* Y = UNCHANGED *
* X = UNCHANGED *
* A = CLOBBERED; TRASH *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
BSAVE
*
** GET RETURN ADDRESS
*
PLA
STA RETADR
PLA
STA RETADR+1
*
** GET PARAMETERS
*
PLA
STA ADDR2 ; CMD STRING ADDR
PLA
STA ADDR2+1
*
LDA #$8D
JSR FCOUT
LDA #$84 ; CTRL-D
JSR FCOUT
LDA #$C2 ; B
JSR FCOUT
LDA #$D3 ; S
JSR FCOUT
LDA #$C1 ; A
JSR FCOUT
LDA #$D6 ; V
JSR FCOUT
LDA #$C5 ; E
JSR FCOUT
LDA #$A0 ; [SPACE]
JSR FCOUT
*
** NOW SEND STRING TO COUT
*
LDY #0
LDA (ADDR2),Y
STA :SLEN
LDY #1
:LP
LDA (ADDR2),Y
JSR FCOUT
INY
CPY :SLEN
BCC :LP
BEQ :LP
*
** NOW PRESS RETURN AND PRAY
*
LDA #$8D
JSR FCOUT
*
** RESTORE RETURN ADDRESS
*
LDA RETADR+1
PHA
LDA RETADR
PHA
*
RTS
*
** DATA
*
:SLEN DS 1
*
*``````````````````````````````*
* BLOAD :: BINARY LOAD *
*- -*
* SIMPLY BLOADS INTO MEMORY AS *
* SPECIFIED BY THE STRING *
* PASSED AS A PARAMETER. *
*- -*
* CLOBBERS: *
* *
* FLAGS: ????---- REG: AXYM *
*- -*
* CYCLES: ??? *
* SIZE: *
*- -*
* USAGE: *
* *
* LDA #>SADDR ; STRING ADDR *
* PHA *
* LDA #<SADDR *
* PHA *
* JSR BLOAD *
*- -*
* ENTRY *
* *
* TOP OF STACK *
* *
* LOW BYTE OF RETURN ADDRESS *
* HI BYTE OF RETURN ADDRESS *
* LO BYTE OF STRING ADDRESS *
* HI BYTE OF STRING ADDRESS *
*- -*
* EXIT *
* *
* TOP OF STACK *
* *
* LOW BYTE OF RETURN ADDRESS *
* HI BYTE OF RETURN ADDRESS *
* *
* Y = UNCHANGED *
* X = UNCHANGED *
* A = CLOBBERED; TRSAH *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
BLOAD
*
** GET RETURN ADDRESS
*
PLA
STA RETADR
PLA
STA RETADR+1
*
** GET PARAMETERS
*
PLA
STA ADDR2 ; CMD STRING ADDR
PLA
STA ADDR2+1
*
LDA #$8D
JSR FCOUT
LDA #$84 ; CTRL-D
JSR FCOUT
LDA #$C2 ; B
JSR FCOUT
LDA #$CC ; L
JSR FCOUT
LDA #$CF ; O
JSR FCOUT
LDA #$C1 ; A
JSR FCOUT
LDA #$C4 ; D
JSR FCOUT
LDA #$A0 ; [SPACE]
JSR FCOUT
*
** NOW SEND STRING TO COUT
*
LDY #0
LDA (ADDR2),Y
STA :SLEN
LDY #1
:LP
LDA (ADDR2),Y
JSR FCOUT
INY
CPY :SLEN
BCC :LP
BEQ :LP
*
** NOW PRESS RETURN AND PRAY
*
LDA #$8D
JSR FCOUT
*
** RESTORE RETURN ADDRESS
*
LDA RETADR+1
PHA
LDA RETADR
PHA
*
RTS
*
** DATA
*
:SLEN DS 1
*
*``````````````````````````````*
* TMODE :: TEXT FILE OPS MODE *
*- -*
* THIS ROUTINE FOOLS DOS INTO *
* THINKING IT IS IN NON- *
* IMMEDIATE MODE. THIS IS *
* TO ALLOW FOR READING AND *
* WRITING OF TEXT FILES. *
*- -*
* CLOBBERS: *
* *
* FLAGS: ????---- REG: AXYM *
*- -*
* CYCLES: ??? *
* SIZE: *
*- -*
* USAGE: *
* *
*- -*
* ENTRY *
* *
* TOP OF STACK *
* *
* LOW BYTE OF RETURN ADDRESS *
* HI BYTE OF RETURN ADDRESS *
*- -*
* EXIT *
* *
* TOP OF STACK *
* *
* LOW BYTE OF RETURN ADDRESS *
* HI BYTE OF RETURN ADDRESS *
* *
* Y = UNCHANGED *
* X = UNCHANGED *
* A = CLOBBERED; TRASH *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
TMODE
*
LDA #$40
STA LANG ; LANG = FP
STA CURLIN+1 ; RUNNING PROG
LDA #$06
STA PROMPT ; NOT DIRECT MODE
RTS
*
*``````````````````````````````*
* CMD :: EXECUTE DOS COMMAND *
*- -*
* EXECUTES A DOS COMMAND THAT *
* IS PASSED VIA AN ASC THAT *
* FOLLOWS THE JSR TO THE *
* ROUTINE. *
*- -*
* CLOBBERS: *
* *
* FLAGS: ????---- REG: AXYM *
*- -*
* CYCLES: ??? *
* SIZE: *
*- -*
* USAGE: *
* *
* JSR CMD *
* ASC "CATALOG" *
* HEX 8D00 *
*- -*
* ENTRY *
* *
* TOP OF STACK *
* *
* LOW BYTE OF RETURN ADDRESS *
* HI BYTE OF RETURN ADDRESS *
*- -*
* EXIT *
* *
* TOP OF STACK *
* *
* LOW BYTE OF RETURN ADDRESS *
* HI BYTE OF RETURN ADDRESS *
* *
* Y = CLOBBERED *
* X = UNCHANGED *
* A = UNCHANGED *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
CMD
*
** GET RETURN ADDRESS
*
PLA
STA RETADR
PLA
STA RETADR+1
*
LDA #$8D
JSR FCOUT
LDA #$84 ; CTRL-D
JSR FCOUT
*
** NOW SEND STRING TO COUT
*
LDY #$01 ; POINT TO NEXT INSTR
:LP
LDA (RETADR),Y
BEQ :DONE
JSR FCOUT
INY
BNE :LP
:DONE
CLC ; RESTORE INSTR POINTER
TYA
ADC RETADR
STA RETADR
LDA RETADR+1
ADC #$00
PHA
LDA RETADR
PHA
*
RTS
*
*``````````````````````````````*
* FPRINT : JUST PRINTS TO COUT *
*- -*
* PRINTS A STRING TO A TEXT *
* FILE THAT IS SPECIFIED IN AN *
* ASC THAT FOLLOWS THE JSR TO *
* THE SUBROUTINE. *
*- -*
* CLOBBERS: *
* *
* FLAGS: ????---- REG: AXYM *
*- -*
* CYCLES: ??? *
* SIZE: *
*- -*
* USAGE: *
* *
* JSR CMD *
* ASC "OPEN TEXT1" *
* HEX 8D00 *
* JSR CMD *
* ASC "WRITE TEXT1" *
* HEX 8D00 *
* JSR FPRINT *
* ASC "THIS IS A TEST." *
* HEX 8D00 *
* JSR CMD *
* ASC "CLOSE TEXT1" *
* HEX 8D00 *
*- -*
* ENTRY *
* *
* TOP OF STACK *
* *
* LOW BYTE OF RETURN ADDRESS *
* HI BYTE OF RETURN ADDRESS *
*- -*
* EXIT *
* *
* TOP OF STACK *
* *
* LOW BYTE OF RETURN ADDRESS *
* HI BYTE OF RETURN ADDRESS *
* *
* Y = CLOBBERED *
* X = UNCHANGED *
* A = CLOBBERED *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
FPRINT
*
** GET RETURN ADDRESS
*
PLA
STA RETADR
PLA
STA RETADR+1
*
** NOW SEND STRING TO COUT
*
LDY #$01 ; POINT TO NEXT INSTR
:LP
LDA (RETADR),Y
BEQ :DONE
JSR FCOUT
INY
BNE :LP
:DONE
CLC ; RESTORE INSTR POINTER
TYA
ADC RETADR
STA RETADR
LDA RETADR+1
ADC #$00
PHA
LDA RETADR
PHA
*
RTS
*
*``````````````````````````````*
* FINPUT: READ LINE FROM TFILE *
*- -*
* INPUTS A LINE FROM A TEXT *
* FILE AND STORES IT AS A *
* STRING AT THE SPECIFIED *
* MEMORY LOCATION. *
*- -*
* CLOBBERS: *
* *
* FLAGS: ????---- REG: AXYM *
*- -*
* CYCLES: ??? *
* SIZE: *
*- -*
* USAGE: *
* *
* JSR CMD *
* ASC "OPEN TEXT1" *
* HEX 8D00 *
* JSR CMD *
* ASC "READ TEXT1" *
* HEX 8D00 *
* LDA #>STRLOC ; STRING LOC *
* PHA *
* LDA #<STRLOC *
* PHA *
* JSR FINPUT *
* JSR CMD *
* ASC "CLOSE TEXT1" *
* HEX 8D00 *
*- -*
* ENTRY *
* *
* TOP OF STACK *
* *
* LOW BYTE OF RETURN ADDRESS *
* HI BYTE OF RETURN ADDRESS *
*- -*
* EXIT *
* *
* TOP OF STACK *
* *
* LOW BYTE OF RETURN ADDRESS *
* HI BYTE OF RETURN ADDRESS *
* *
* Y = CLOBBERED *
* X = CLOBBERED *
* A = CLOBBERED *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
FINPUT
*
** SAVE RETURN ADDRESS
*
PLA
STA RETADR
PLA
STA RETADR+1
*
** GET PARAMETERS
*
PLA
STA ADDR1
PLA
STA ADDR1+1
*
LDX #0
JSR FGETLN
STX :SLEN
CPX #0
BEQ :EXIT
*
:INP_CLR
LDY #0
LDA :SLEN
STA (ADDR1),Y ; PUT LENGTH AT START
:LP
LDA $0200,Y ; KEYBOARD BUFFER
INY
STA (ADDR1),Y
CPY :SLEN
BNE :LP
*
:EXIT
*
** RESTORE RETURN ADDRESS
*
LDA RETADR+1
PHA
LDA RETADR
PHA
*
RTS
*
** DATA
*
:SLEN DS 1
*
*``````````````````````````````*
* FPSTR : PRINT STRING TO FILE *
*- -*
* PRINTS THE SPECIFIED STRING *
* AT GIVEN LOCATION TO THE *
* FILE OPEN AND SET TO BE *
* WRITTEN. *
*- -*
* CLOBBERS: *
* *
* FLAGS: ????---- REG: AXYM *
*- -*
* CYCLES: ??? *
* SIZE: *
*- -*
* USAGE: *
* *
*- -*
* ENTRY *
* *
* TOP OF STACK *
* *
* LOW BYTE OF RETURN ADDRESS *
* HI BYTE OF RETURN ADDRESS *
*- -*
* EXIT *
* *
* TOP OF STACK *
* *
* LOW BYTE OF RETURN ADDRESS *
* HI BYTE OF RETURN ADDRESS *
* *
* Y = CLOBBERED *
* X = CLOBBERED *
* A = CLOBBERED *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
FPSTR
*
** SAVE RETURN ADDRESS
*
PLA
STA RETADR
PLA
STA RETADR+1
*
** GET PARAMETERS
*
PLA
STA ADDR1
PLA
STA ADDR1+1
*
LDY #0
LDA (ADDR1),Y
STA :SLEN
:LP
INY
LDA (ADDR1),Y
JSR FCOUT
CPY :SLEN
BNE :LP
:EXIT
*
** RESTORE RETURN ADDRESS
*
LDA RETADR+1
PHA
LDA RETADR
PHA
*
RTS
*
** DATA
*
:SLEN DS 1
*
*``````````````````````````````*
* DISKOP : DISK OPERATION RWTS *
*- -*
* GENERAL PURPOSE ROUTINE FOR *
* READING AND WRITING TO A *
* DISK VIA TRACKS AND SECTORS. *
*- -*
* CLOBBERS: *
* *
* FLAGS: ????---- REG: AXYM *
*- -*
* CYCLES: ??? *
* SIZE: *
*- -*
* USAGE: *
* *
*- -*
* ENTRY *
* *
* TOP OF STACK *
* *
* LOW BYTE OF RETURN ADDRESS *
* HI BYTE OF RETURN ADDRESS *
*- -*
* EXIT *
* *
* TOP OF STACK *
* *
* LOW BYTE OF RETURN ADDRESS *
* HI BYTE OF RETURN ADDRESS *
* *
* Y = CLOBBERED *
* X = CLOBBERED *
* A = CLOBBERED *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
DISKOP
*
:CLEAR
LDA #00
STA IOB_EVOL
*
LDA #>IOB
LDY #<IOB
JSR RWTS
BCC :EXIT
:ERR LDA IOB_ERR
LDX #00
STX $48
:EXIT RTS
*