2000-05-28 13:40:48 +00:00
|
|
|
;
|
2005-04-12 09:12:48 +00:00
|
|
|
; Oliver Schmidt, 12.01.2005
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
2005-04-12 09:12:48 +00:00
|
|
|
; int __fastcall__ read (int fd, void* buf, unsigned count);
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.constructor initprompt
|
|
|
|
.export _read
|
|
|
|
.import rwprolog, rwcommon
|
|
|
|
.import RDKEY, COUT
|
2005-04-12 09:12:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "zeropage.inc"
|
|
|
|
.include "errno.inc"
|
|
|
|
.include "fcntl.inc"
|
|
|
|
.include "mli.inc"
|
|
|
|
.include "filedes.inc"
|
|
|
|
.include "apple2.inc"
|
2005-04-12 09:12:48 +00:00
|
|
|
|
2016-03-06 20:26:22 +00:00
|
|
|
.segment "ONCE"
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
initprompt:
|
2020-12-19 18:54:12 +00:00
|
|
|
; Set prompt <> ']' and currently executed Applesoft
|
|
|
|
; line number hibyte <> $FF to let DOS 3.3 (at $A65E)
|
|
|
|
; know that we're not in Applesoft immediate mode and
|
|
|
|
; thus keep it from scanning our device I/O for DOS
|
|
|
|
; commands.
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #$80 ; Same value used at $D52C
|
|
|
|
sta PROMPT
|
2020-12-19 18:54:12 +00:00
|
|
|
sta CURLIN+1 ; Any value <> $FF will do
|
2005-04-12 09:12:48 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
.code
|
|
|
|
|
|
|
|
_read:
|
|
|
|
; Get parameters
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr rwprolog
|
|
|
|
bcs errno
|
|
|
|
tax ; Save fd
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Check for read access
|
2013-05-09 11:56:54 +00:00
|
|
|
lda fdtab + FD::FLAGS,y
|
|
|
|
and #O_RDONLY
|
|
|
|
beq einval
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Check for device
|
2013-05-09 11:56:54 +00:00
|
|
|
txa ; Restore fd
|
|
|
|
bmi device
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Do read
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #READ_CALL
|
|
|
|
jmp rwcommon
|
2005-04-12 09:12:48 +00:00
|
|
|
|
2010-06-15 21:44:18 +00:00
|
|
|
; Device succeeds always
|
2013-05-09 11:56:54 +00:00
|
|
|
device: lda #$00
|
2022-08-28 19:52:53 +00:00
|
|
|
sta ___oserror
|
2010-06-15 21:44:18 +00:00
|
|
|
|
|
|
|
; Set counter to zero
|
2013-05-09 11:56:54 +00:00
|
|
|
sta ptr3
|
|
|
|
sta ptr3+1
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Check for zero count
|
2013-05-09 11:56:54 +00:00
|
|
|
lda ptr2
|
|
|
|
ora ptr2+1
|
|
|
|
beq check
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Read from device and echo to device
|
2013-05-09 11:56:54 +00:00
|
|
|
next: jsr RDKEY
|
|
|
|
jsr COUT
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Clear hi bit and check for '\r'
|
2013-05-09 11:56:54 +00:00
|
|
|
and #$7F
|
|
|
|
cmp #$0D
|
|
|
|
bne :+
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Replace with '\n' and set count to zero
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #$0A
|
|
|
|
ldy #$00
|
|
|
|
sty ptr2
|
|
|
|
sty ptr2+1
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Put char into buf
|
2013-05-09 11:56:54 +00:00
|
|
|
: ldy #$00
|
|
|
|
sta (ptr1),y
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Increment pointer
|
2013-05-09 11:56:54 +00:00
|
|
|
inc ptr1
|
|
|
|
bne :+
|
|
|
|
inc ptr1+1
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Increment counter
|
2013-05-09 11:56:54 +00:00
|
|
|
: inc ptr3
|
|
|
|
bne check
|
|
|
|
inc ptr3+1
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Check for counter less than count
|
2013-05-09 11:56:54 +00:00
|
|
|
check: lda ptr3
|
|
|
|
cmp ptr2
|
|
|
|
bcc next
|
|
|
|
ldx ptr3+1
|
|
|
|
cpx ptr2+1
|
|
|
|
bcc next
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2005-04-12 09:12:48 +00:00
|
|
|
; Return success, AX already set
|
|
|
|
rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2005-04-12 09:12:48 +00:00
|
|
|
; Load errno code
|
2013-05-09 11:56:54 +00:00
|
|
|
einval: lda #EINVAL
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2010-06-15 20:38:05 +00:00
|
|
|
; Set __errno
|
2022-08-28 19:52:53 +00:00
|
|
|
errno: jmp ___directerrno
|