1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
;
; 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, popptr1
.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 popptr1 ; get buf
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
;--------------------------------------------------------------------------
.segment "INIT"
text_count:
.res 1
|