2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 30.05.1998
|
|
|
|
;
|
|
|
|
; int read (int fd, void* buf, int count);
|
|
|
|
;
|
|
|
|
; THIS IS A HACK!
|
|
|
|
;
|
|
|
|
|
|
|
|
.export _read
|
2004-06-03 15:05:41 +00:00
|
|
|
.import popax, _cputc, RDKEY
|
2000-05-28 13:40:48 +00:00
|
|
|
.importzp ptr1, ptr2, ptr3
|
|
|
|
|
|
|
|
_read: jsr popax ; get count
|
|
|
|
sta ptr2
|
|
|
|
stx ptr2+1 ; save it for later
|
|
|
|
jsr popax ; get buf
|
|
|
|
sta ptr1
|
|
|
|
stx ptr1+1
|
|
|
|
jsr popax ; get fd and discard it
|
2004-03-11 21:54:22 +00:00
|
|
|
lda #$00
|
2000-05-28 13:40:48 +00:00
|
|
|
sta ptr3
|
|
|
|
sta ptr3+1 ; set count
|
|
|
|
|
|
|
|
L1: lda ptr2
|
|
|
|
ora ptr2+1 ; count zero?
|
|
|
|
beq L9
|
|
|
|
jsr RDKEY
|
2004-03-11 21:54:22 +00:00
|
|
|
and #$7F ; clear high bit.
|
2000-05-28 13:40:48 +00:00
|
|
|
pha
|
|
|
|
jsr _cputc
|
|
|
|
pla
|
2004-03-11 21:54:22 +00:00
|
|
|
ldy #$00 ; offset into string
|
2000-05-28 13:40:48 +00:00
|
|
|
sta (ptr1),y ; save char
|
|
|
|
inc ptr1
|
|
|
|
bne L2
|
|
|
|
inc ptr1+1
|
|
|
|
L2: inc ptr3 ; increment count
|
|
|
|
bne L3
|
|
|
|
inc ptr3+1
|
|
|
|
L3: cmp #$0D ; CR?
|
|
|
|
bne L1
|
|
|
|
|
|
|
|
; Done, return the count
|
|
|
|
|
|
|
|
L9: lda ptr3
|
|
|
|
ldx ptr3+1
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
|
|
|