Don't remember

This commit is contained in:
Bill Chatfield 2019-05-02 21:26:12 -04:00
parent 36e58cde89
commit 7377bf0f90
2 changed files with 97 additions and 41 deletions

138
more.s
View File

@ -12,8 +12,13 @@
* accumulator (A) is less than the parameter: A < Param * accumulator (A) is less than the parameter: A < Param
* BGE - Branch if Accum >= Param is BCS * BGE - Branch if Accum >= Param is BCS
PROMPT equ $33
BUFF equ $200
* System subroutines stored in ROM * System subroutines stored in Monitor ROM
GETLN equ $fd6a ; Reads a line of input, with prompt from $33
GETLNZ equ $fd67 ; Reads a line of input, CR first
GETLN1 equ $fd6f ; Reads a line of input, no prompt
CROUT equ $fd8e ; Outputs a carriage return CROUT equ $fd8e ; Outputs a carriage return
PRBYTE equ $fdda ; Outputs a byte PRBYTE equ $fdda ; Outputs a byte
COUT equ $fded ; Outputs a character COUT equ $fded ; Outputs a character
@ -29,9 +34,10 @@ CLOSE equ $cc
* Constants * Constants
EOF equ $4c ; End of file EOF equ $4c ; End of file
ADDR equ $06 PTR equ $06
MAX_EC equ $5a ; The largest error code MAX_EC equ $5a ; The largest error code
CR equ $0d ; Carriage return CR equ $0d ; Carriage return
BUF_SIZ equ $00ff
WRITE_CHAR mac WRITE_CHAR mac
@ -65,21 +71,22 @@ finish pla ; Restore Y by pulling stack into A
WRITE_STR mac WRITE_STR mac
tya ; Preserve Y tya ; Preserve Y
pha pha
lda ]1 ; Length byte lda ]1 ; Length byte
sta len sta len
ldy #1 ; Prepare loop index ldy #1 ; Prepare loop index
nextch cpy len ; Check if beyond end of string nextChar tya
bcc writech ; Y is Less than cmp len ; Check if beyond end of string
beq writech ; Or equal to len bcc writeChar ; Y is Less than
beq writeChar ; or equal to len
jmp finish jmp finish
writech lda ]1,y ; Load a character writeChar lda ]1,y ; Load a character
jsr COUT jsr COUT
iny iny
jmp nextch jmp nextChar
len db 0 len db 0
finish pla ; Restore Y finish pla ; Restore Y
tay tay
eom eom
@ -89,6 +96,44 @@ COPY_BYTE mac
sta ]2 sta ]2
eom eom
* Copies a line out of BUFF into ]1.
* Length is in X as is done by GETLN.
COPY_BUFF mac
tya ; Preserve Y register
pha ; by pushing it on the stack
txa ; Transfer X to A for compare
cmp #$ff ; Check if string is too long
bne startCopy ; If not, get started
dex ; If so, shrink to fit with length byte
startCopy stx ]1 ; Store length to target string
ldy #0 ; Initialize loop index
nextChar tya ; Move current position to A
cmp ]1 ; Compare current position with length
beq endCopyLine ; Quit if we've reached the end
lda BUFF,y ; Load current character
iny ; BUFF and ]1 are off by 1 because of len byte
sta ]1,y ; Store character into target string
jmp nextChar ; Continue with next character
endCopyLine pla ; Restore Y by pulling value from stack
tay ; and transferring to Y
eom
WRITE_BUFF mac
tya
pha
stx len
ldy #0
nextByte tya
cmp len
beq done
lda BUFF,y
jsr COUT
iny
jmp nextByte
done pla
tay
eom
* Starting at $9000 because: * Starting at $9000 because:
* $800 overwrites Applesoft * $800 overwrites Applesoft
* $803 is where Applesoft programs start * $803 is where Applesoft programs start
@ -97,17 +142,21 @@ COPY_BYTE mac
mainProgram mainProgram
org $8000 org $8000
lda #<fileName getFileNam
sta oPathPtr WRITE_ASC prompt
lda #>fileName COPY_BYTE #"?";PROMPT
sta oPathPtr+1 jsr GETLN1
WRITE_ASC buffText
WRITE_BUFF
jsr CROUT
COPY_BUFF fileName
openFile jsr MLI openFile jsr MLI
db OPEN db OPEN
da openParams da openParams
bne openErrorHandler bne openErrorHandler
readFile pmc COPY_BYTE,fileNum;readNum readFile COPY_BYTE fileNum;readNum
readNext jsr MLI readNext jsr MLI
db READ db READ
da readParams da readParams
@ -121,15 +170,18 @@ writeScreen
sty lineCount sty lineCount
sty charCount sty charCount
nextChar lda readIoBuf,y nextChar lda readIoBuf,y
inc charCount
ora #$80
jsr COUT jsr COUT
cmp $0d cmp $0d
bne continue bne continue
inc lineCount inc lineCount
continue inc charCount continue cpy #<BUF_SIZ
beq readNext
iny iny
jmp nextChar jmp nextChar
closeFile pmc COPY_BYTE,fileNum;closeNum closeFile COPY_BYTE fileNum;closeNum
jsr MLI jsr MLI
db CLOSE db CLOSE
dw closeParams dw closeParams
@ -137,19 +189,19 @@ closeFile pmc COPY_BYTE,fileNum;closeNum
jmp endMain jmp endMain
openErrorHandler openErrorHandler
sta errorCode sta errorCode
pmc WRITE_ASC,openFailureText WRITE_ASC openFailureText
jmp errorHandler jmp errorHandler
readErrorHandler readErrorHandler
sta errorCode sta errorCode
pmc WRITE_ASC,readFailureText WRITE_ASC readFailureText
jmp errorHandler jmp errorHandler
closeErrorHandler closeErrorHandler
sta errorCode sta errorCode
pmc WRITE_ASC,closeFailureText WRITE_ASC closeFailureText
errorHandler errorHandler
pmc WRITE_STR,fileName WRITE_STR fileName
pmc WRITE_CHAR,":" WRITE_CHAR ":"
pmc WRITE_CHAR," " WRITE_CHAR " "
lda errorCode lda errorCode
cmp #MAX_EC ; Compare by A - MAX_EC cmp #MAX_EC ; Compare by A - MAX_EC
bcs unknownError ; Branch if A >= MAX_EC bcs unknownError ; Branch if A >= MAX_EC
@ -158,51 +210,55 @@ errorHandler
adc errorCode ; Double for indexing addresses adc errorCode ; Double for indexing addresses
tax tax
lda errorMessages,x lda errorMessages,x
sta ADDR sta PTR
inx inx
lda errorMessages,x lda errorMessages,x
sta ADDR+1 sta PTR+1
bne writeError bne writeError
lda ADDR lda PTR
bne writeError bne writeError
unknownError unknownError
pmc WRITE_ASC,unknownErrorCodeText WRITE_ASC unknownErrorCodeText
pmc WRITE_CHAR,"$" WRITE_CHAR "$"
pmc WRITE_BYTE,errorCode WRITE_BYTE errorCode
jsr CROUT jsr CROUT
jmp endMain jmp endMain
writeError writeError
pmc WRITE_ASC,(ADDR) WRITE_ASC (PTR)
pmc WRITE_CHAR," " WRITE_CHAR " "
pmc WRITE_ASC,errorCodeText WRITE_ASC errorCodeText
pmc WRITE_CHAR,"$" WRITE_CHAR "$"
pmc WRITE_BYTE,errorCode WRITE_BYTE errorCode
pmc WRITE_CHAR,")" WRITE_CHAR ")"
jsr CROUT jsr CROUT
endMain endMain
COPY_BYTE #"]";PROMPT ; Restore normal prompt
rts rts
* DAT-uh * DAT-uh
openParams db 3 ; Parameter count openParams db 3 ; Parameter count
oPathPtr ds 2 ; Input param - file to open oPathPtr da fileName ; Input param - file to open
oBufPtr da openIoBuf ; Input param - I/O buffer oBufPtr da openIoBuf ; Input param - I/O buffer
fileNum ds 1 ; Output param - file ref num fileNum ds 1 ; Output param - file ref num
readParams db 4 readParams db 4
readNum ds 1 readNum ds 1
da readIoBuf da readIoBuf
reqCount dw 512 reqCount dw BUF_SIZ
transCount ds 2 transCount ds 2
closeParams db 1 ; Parameter count closeParams db 1 ; Parameter count
closeNum db 0 ; Input param - ref num to close closeNum db 0 ; Input param - ref num to close
fileName db 4 fileName ds $ff ; String starting with length byte
asc "BLAH"
charCount ds 2 charCount ds 2
lineCount ds 1
len ds 1
buffText asc "BUFF=",00
prompt asc "ENTER FILE NAME: ",00
errorCode db 0 errorCode db 0
openFailureText asc "FAILED TO OPEN FILE ",00 openFailureText asc "FAILED TO OPEN FILE ",00
readFailureText asc "FAILED TO READ FILE ",00 readFailureText asc "FAILED TO READ FILE ",00
@ -342,5 +398,5 @@ filler ds \,$00
* Must start on page boundary * Must start on page boundary
* *
openIoBuf ds 1024 openIoBuf ds 1024
readIoBuf ds 512 readIoBuf ds BUF_SIZ

Binary file not shown.