mirror of
https://github.com/nathanriggs/AppleIIAsm-Collection.git
synced 2024-11-28 03:52:10 +00:00
03636aa196
- various bugfixes - integrated required library - created minified sources - made macros slightly more flexible
674 lines
16 KiB
Plaintext
674 lines
16 KiB
Plaintext
*
|
|
*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*
|
|
* *
|
|
* FILE INPUT/OUTPUT LIBRARY *
|
|
* *
|
|
* AUTHOR: NATHAN RIGGS *
|
|
* CONTACT: NATHAN.RIGGS@ *
|
|
* OUTLOOK.COM *
|
|
* *
|
|
* VERSION: 0.2.0 *
|
|
* DATE: 22-DEC-2018 *
|
|
* ASSEMBLER: MERLIN 8 PRO *
|
|
* OS: DOS 3.3 *
|
|
* LICENSE: APACHE 2.0 *
|
|
* *
|
|
*------------------------------*
|
|
* *
|
|
* LIST OF ROUTINES *
|
|
* *
|
|
* BINSAVE : SAVE BINARY FILE *
|
|
* BINLOAD : LOAD BINARY FILE *
|
|
* TXTMODE : TEXT FILE OPS MODE *
|
|
* DOSCMD : EXEC DOS COMMAND *
|
|
* FPRINT : PRINT TO FILE *
|
|
* FPSTR : FILE PRINT STRING *
|
|
* FINPUT : GET LINE FROM TEXTF *
|
|
* *
|
|
*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*
|
|
*
|
|
*``````````````````````````````*
|
|
* BINSAVE :: 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 BINSAVE *
|
|
*- -*
|
|
* 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 *
|
|
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
|
|
*
|
|
BINSAVE
|
|
*
|
|
** 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
|
|
*
|
|
*``````````````````````````````*
|
|
* BINLOAD :: 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 BINLOAD *
|
|
*- -*
|
|
* 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 *
|
|
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
|
|
*
|
|
BINLOAD
|
|
*
|
|
** 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
|
|
*
|
|
*``````````````````````````````*
|
|
* TXTMODE :: TEXT FILE 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: *
|
|
*- -*
|
|
* 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 *
|
|
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
|
|
*
|
|
TXTMODE
|
|
*
|
|
LDA #$40
|
|
STA LANG ; LANG = FP
|
|
STA CURLIN+1 ; RUNNING PROG
|
|
LDA #$06
|
|
STA PROMPT ; NOT DIRECT MODE
|
|
RTS
|
|
*
|
|
*``````````````````````````````*
|
|
* DOSCMD : 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 DOSCMD *
|
|
* 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 *
|
|
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
|
|
*
|
|
DOSCMD
|
|
*
|
|
** 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
|
|
*
|