Restore changes to allow ungetc of byte values 0x80 through 0xFF.

These are the stdio.asm changes that were present in the beta source code on Opus ][, but had been reverted in commit e3c0c962d4. As it turns out, the changes to stdio.asm were OK--the issue was simply that the definitions of stdin/stdout/stderr and the associated initialization code in vars.asm had not been updated to account for the new version of the FILE structure. That has now been done, allowing the changes to work properly.

This fixes #7.
This commit is contained in:
Stephen Heumann 2022-06-27 17:56:52 -05:00
parent 7c2fb70c4a
commit 38666ee111
3 changed files with 48 additions and 42 deletions

View File

@ -74,7 +74,7 @@ FILE_end gequ FILE_base+4 end of the file buffer
FILE_size gequ FILE_end+4 size of the file buffer FILE_size gequ FILE_end+4 size of the file buffer
FILE_cnt gequ FILE_size+4 # chars that can be read/written to buffer FILE_cnt gequ FILE_size+4 # chars that can be read/written to buffer
FILE_pbk gequ FILE_cnt+4 put back character FILE_pbk gequ FILE_cnt+4 put back character
FILE_flag gequ FILE_pbk+2 buffer flags FILE_flag gequ FILE_pbk+4 buffer flags
FILE_file gequ FILE_flag+2 GS/OS file ID FILE_file gequ FILE_flag+2 GS/OS file ID
sizeofFILE gequ FILE_file+2 size of the record sizeofFILE gequ FILE_file+2 size of the record

View File

@ -437,14 +437,16 @@ lb0 lda #EOF
lb1 ldy #FILE_pbk if there is a char in the putback buffer lb1 ldy #FILE_pbk if there is a char in the putback buffer
lda [stream],Y lda [stream],Y
and #$0080 bmi lb2
bne lb2 and #$00FF return it
lda [stream],Y return it
and #$00FF
sta c sta c
lda [stream],Y pop the putback buffer ldy #FILE_pbk+2 pop the putback buffer
xba lda [stream],Y
ora #$FF00 tax
lda #$FFFF
sta [stream],Y
ldy #FILE_pbk
txa
sta [stream],Y sta [stream],Y
brl gc9 brl gc9
@ -940,6 +942,8 @@ ar6b sta [fileBuff],Y
ldy #FILE_pbk nothing in the putback buffer ldy #FILE_pbk nothing in the putback buffer
lda #$FFFF lda #$FFFF
sta [fileBuff],Y sta [fileBuff],Y
ldy #FILE_pbk+2
sta [fileBuff],Y
ldy #FILE_file set the file ID ldy #FILE_file set the file ID
lda opRefNum lda opRefNum
sta [fileBuff],Y sta [fileBuff],Y
@ -1228,6 +1232,8 @@ ar6b sta [fileBuff],Y
ldy #FILE_pbk nothing in the putback buffer ldy #FILE_pbk nothing in the putback buffer
lda #$FFFF lda #$FFFF
sta [fileBuff],Y sta [fileBuff],Y
ldy #FILE_pbk+2
sta [fileBuff],Y
ldy #FILE_file set the file ID ldy #FILE_file set the file ID
lda opRefNum lda opRefNum
sta [fileBuff],Y sta [fileBuff],Y
@ -1824,6 +1830,8 @@ lb6 ldy #FILE_flag clear the EOF , READ, WRITE flags
ldy #FILE_pbk nothing in the putback buffer ldy #FILE_pbk nothing in the putback buffer
lda #$FFFF lda #$FFFF
sta [stream],Y sta [stream],Y
ldy #FILE_pbk+2
sta [stream],Y
stz err stz err
rts plb rts plb
@ -1937,12 +1945,15 @@ lb1 move4 gmPosition,pos set the position
lda pos+2 lda pos+2
sbc [stream],Y sbc [stream],Y
sta pos+2 sta pos+2
ldy #FILE_pbk if there is a char in the putback ldy #FILE_pbk dec pos by 1 for each char in the
lda [stream],Y buffer then lda [stream],Y putback buffer then
and #$0080 bmi lb2
bne rts dec4 pos
dec4 pos dec pos by 1 ldy #FILE_pbk+2
ldy #FILE_file set the file's mark lda [stream],Y
bmi lb2
dec4 pos
lb2 ldy #FILE_file set the file's mark
lda [stream],Y lda [stream],Y
sta spRefNum sta spRefNum
move4 pos,spPosition move4 pos,spPosition
@ -2048,7 +2059,7 @@ lb5 div4 wrTransferCount,element_size,count
lb6 plb lb6 plb
creturn 4:count return creturn 4:count return
wr dc i'5' parameter block for OSRead wr dc i'5' parameter block for OSWrite
wrRefNum ds 2 wrRefNum ds 2
wrDataBuffer ds 4 wrDataBuffer ds 4
wrRequestCount ds 4 wrRequestCount ds 4
@ -2084,15 +2095,13 @@ getchar start
; get the char from the keyboard ; get the char from the keyboard
; ;
lda >stdin+4+FILE_pbk if there is a char in the putback lda >stdin+4+FILE_pbk if there is a char in the putback
and #$0080 buffer then bmi lb1 buffer then
bne lb1 and #$00FF save it in X
lda >stdin+4+FILE_pbk save it in x tax
and #$00FF lda >stdin+4+FILE_pbk+2 pop the buffer
tax
lda >stdin+4+FILE_pbk pop the buffer
xba
ora #$FF00
sta >stdin+4+FILE_pbk sta >stdin+4+FILE_pbk
lda #$FFFF
sta >stdin+4+FILE_pbk+2
txa restore the char txa restore the char
bra lb2 bra lb2
@ -3173,21 +3182,18 @@ char equ 1 character to return
lda c error if EOF is pushed lda c error if EOF is pushed
cmp #EOF cmp #EOF
beq rts beq rts
ldy #FILE_pbk+1 error if the buffer is full ldy #FILE_pbk+2 error if the buffer is full
short M
lda [stream],Y lda [stream],Y
bpl rts bpl rts
dey push the old character (if any) ldy #FILE_pbk push the old character (if any)
lda [stream],Y lda [stream],Y
iny ldy #FILE_pbk+2
sta [stream],Y sta [stream],Y
dey ldy #FILE_pbk put back the character
lda c put back the character lda c
and #$00FF
sta [stream],Y sta [stream],Y
sta char sta char
stz char+1
bpl rts
dec char+1
rts long M rts long M
creturn 2:char creturn 2:char
end end

View File

@ -45,12 +45,12 @@ _toolErr entry last error in a tool call (C)
* *
~InitIO start ~InitIO start
ldx #24 set up the file records ldx #sizeofFILE-4-2 set up the file records
lb1 lda stderr+34,X lb1 lda stderr+4+sizeofFILE,X
sta stderr+8,X sta stderr+8,X
lda stdin+34,X lda stdin+4+sizeofFILE,X
sta stdin+8,X sta stdin+8,X
lda stdout+34,X lda stdout+4+sizeofFILE,X
sta stdout+8,X sta stdout+8,X
dex dex
dex dex
@ -77,7 +77,7 @@ lb1 dc a4'0' next file
dc a4'0' end of the file buffer dc a4'0' end of the file buffer
dc i4'0' size of the file buffer dc i4'0' size of the file buffer
dc i4'0' count dc i4'0' count
dc i'EOF' putback buffer dc i'EOF,EOF' putback buffer
dc i'_IONBF+_IOWRT+_IOTEXT' no buffering; allow writes; text file dc i'_IONBF+_IOWRT+_IOTEXT' no buffering; allow writes; text file
dc i'stderrID' error out dc i'stderrID' error out
@ -86,7 +86,7 @@ lb1 dc a4'0' next file
dc a4'0' end of the file buffer dc a4'0' end of the file buffer
dc i4'0' size of the file buffer dc i4'0' size of the file buffer
dc i4'0' count dc i4'0' count
dc i'EOF' putback buffer dc i'EOF,EOF' putback buffer
dc i'_IONBF+_IOWRT+_IOTEXT' no buffering; allow writes; text file dc i'_IONBF+_IOWRT+_IOTEXT' no buffering; allow writes; text file
dc i'stderrID' error out dc i'stderrID' error out
end end
@ -107,7 +107,7 @@ lb1 dc a4'stdout+4' next file
dc a4'0' end of the file buffer dc a4'0' end of the file buffer
dc i4'0' size of the file buffer dc i4'0' size of the file buffer
dc i4'0' count dc i4'0' count
dc i'EOF' putback buffer dc i'EOF,EOF' putback buffer
dc i'_IONBF+_IOREAD+_IOTEXT' no buffering; allow reads; text file dc i'_IONBF+_IOREAD+_IOTEXT' no buffering; allow reads; text file
dc i'stdinID' standard in dc i'stdinID' standard in
@ -116,7 +116,7 @@ lb1 dc a4'stdout+4' next file
dc a4'0' end of the file buffer dc a4'0' end of the file buffer
dc i4'0' size of the file buffer dc i4'0' size of the file buffer
dc i4'0' count dc i4'0' count
dc i'EOF' putback buffer dc i'EOF,EOF' putback buffer
dc i'_IONBF+_IOREAD+_IOTEXT' no buffering; allow reads; text file dc i'_IONBF+_IOREAD+_IOTEXT' no buffering; allow reads; text file
dc i'stdinID' standard in dc i'stdinID' standard in
end end
@ -137,7 +137,7 @@ lb1 dc a4'stderr+4' next file
dc a4'0' end of the file buffer dc a4'0' end of the file buffer
dc i4'0' size of the file buffer dc i4'0' size of the file buffer
dc i4'0' count dc i4'0' count
dc i'EOF' putback buffer dc i'EOF,EOF' putback buffer
dc i'_IONBF+_IOWRT+_IOTEXT' no buffering; allow writes; text file dc i'_IONBF+_IOWRT+_IOTEXT' no buffering; allow writes; text file
dc i'stdoutID' standard out dc i'stdoutID' standard out
@ -146,7 +146,7 @@ lb1 dc a4'stderr+4' next file
dc a4'0' end of the file buffer dc a4'0' end of the file buffer
dc i4'0' size of the file buffer dc i4'0' size of the file buffer
dc i4'0' count dc i4'0' count
dc i'EOF' putback buffer dc i'EOF,EOF' putback buffer
dc i'_IONBF+_IOWRT+_IOTEXT' no buffering; allow writes; text file dc i'_IONBF+_IOWRT+_IOTEXT' no buffering; allow writes; text file
dc i'stdoutID' standard out dc i'stdoutID' standard out
end end