2013-12-24 10:18:04 +00:00
|
|
|
;
|
2014-08-22 21:19:58 +00:00
|
|
|
; 2014-08-22, Greg King
|
2013-12-24 10:18:04 +00:00
|
|
|
;
|
|
|
|
; int read (int fd, void* buf, unsigned count);
|
|
|
|
;
|
|
|
|
; This function is a hack! It lets us get text from the stdin console.
|
|
|
|
;
|
|
|
|
|
|
|
|
.export _read
|
2013-12-24 20:26:05 +00:00
|
|
|
.constructor initstdin
|
2013-12-24 10:18:04 +00:00
|
|
|
|
2018-05-20 13:30:18 +00:00
|
|
|
.import popax, popptr1
|
2013-12-24 10:18:04 +00:00
|
|
|
.importzp ptr1, ptr2, ptr3
|
2014-08-22 21:19:58 +00:00
|
|
|
.forceimport disable_caps
|
2013-12-24 10:18:04 +00:00
|
|
|
|
|
|
|
.macpack generic
|
|
|
|
.include "atmos.inc"
|
|
|
|
|
|
|
|
.proc _read
|
|
|
|
|
|
|
|
sta ptr3
|
|
|
|
stx ptr3+1 ; save count as result
|
2020-11-01 21:59:07 +00:00
|
|
|
|
|
|
|
inx
|
|
|
|
stx ptr2+1
|
|
|
|
tax
|
|
|
|
inx
|
|
|
|
stx ptr2 ; save count with each byte incremented separately
|
2013-12-24 10:18:04 +00:00
|
|
|
|
2018-05-20 13:30:18 +00:00
|
|
|
jsr popptr1 ; get buf
|
2013-12-24 10:18:04 +00:00
|
|
|
jsr popax ; get fd and discard
|
|
|
|
|
2020-11-01 21:59:07 +00:00
|
|
|
L1: dec ptr2
|
2013-12-24 10:18:04 +00:00
|
|
|
bnz L2
|
2020-11-01 21:59:07 +00:00
|
|
|
dec ptr2+1
|
2013-12-24 10:18:04 +00:00
|
|
|
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
|
|
|
|
|
2013-12-24 20:26:05 +00:00
|
|
|
|
|
|
|
;--------------------------------------------------------------------------
|
|
|
|
; initstdin: Reset the stdin console.
|
|
|
|
|
2016-03-06 20:26:22 +00:00
|
|
|
.segment "ONCE"
|
2013-12-24 20:26:05 +00:00
|
|
|
|
|
|
|
initstdin:
|
|
|
|
ldx #<-1
|
|
|
|
stx text_count
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
|
|
;--------------------------------------------------------------------------
|
|
|
|
|
2016-03-16 15:28:32 +00:00
|
|
|
.segment "INIT"
|
2013-12-24 10:18:04 +00:00
|
|
|
|
|
|
|
text_count:
|
2013-12-24 20:26:05 +00:00
|
|
|
.res 1
|