1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-16 09:29:32 +00:00
cc65/libsrc/atmos/read.s
Oliver Schmidt 419eb700b5 Renamed INITBSS to INIT and INIT to ONCE.
The way we want to use the INITBSS segment - and especially the fact that it won't have the type bss on all ROM based targets - means that the name INITBSS is misleading. After all INIT is the best name from my perspective as it serves several purposes and therefore needs a rather generic name.

Unfortunately this means that the current INIT segment needs to be renamed too. Looking for a short (ideally 4 letter) name I came up with ONCE as it contains all code (and data) accessed only once during initialization.
2016-03-06 21:27:19 +01:00

87 lines
1.8 KiB
ArmAsm

;
; 2014-08-22, Greg King
;
; int read (int fd, void* buf, unsigned count);
;
; This function is a hack! It lets us get text from the stdin console.
;
.export _read
.constructor initstdin
.import popax
.importzp ptr1, ptr2, ptr3
.forceimport disable_caps
.macpack generic
.include "atmos.inc"
.proc _read
sta ptr3
stx ptr3+1 ; save count as result
eor #$FF
sta ptr2
txa
eor #$FF
sta ptr2+1 ; Remember -count-1
jsr popax ; get buf
sta ptr1
stx ptr1+1
jsr popax ; get fd and discard
L1: inc ptr2
bnz L2
inc ptr2+1
bze L9 ; no more room in buf
; If there are no more characters in BASIC's input buffer, then get a line from
; the console into that buffer.
L2: ldx text_count
bpl L3
jsr GETLINE
ldx #<(0 - 1)
L3: inx
lda BASIC_BUF,x
bnz L4 ; (zero-terminated buffer)
ldx #<-1
lda #$0A ; return newline char. at end of line
L4: stx text_count
ldy #0
sta (ptr1),y
inc ptr1
bnz L1
inc ptr1+1
bnz L1 ; branch always
; No error, return count.
L9: lda ptr3
ldx ptr3+1
rts
.endproc
;--------------------------------------------------------------------------
; initstdin: Reset the stdin console.
.segment "ONCE"
initstdin:
ldx #<-1
stx text_count
rts
;--------------------------------------------------------------------------
.bss
text_count:
.res 1