2003-04-13 22:12:09 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 2003-04-13
|
|
|
|
;
|
|
|
|
; int write (int fd, const void* buf, int count);
|
|
|
|
;
|
|
|
|
; This function is a hack!
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _write
|
|
|
|
.import popax
|
|
|
|
.importzp ptr1, ptr2, ptr3, tmp1
|
2003-04-13 22:12:09 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "atmos.inc"
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
|
|
.proc _write
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
sta ptr3
|
|
|
|
stx ptr3+1 ; save count as result
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
|
|
eor #$FF
|
|
|
|
sta ptr2
|
|
|
|
txa
|
|
|
|
eor #$FF
|
|
|
|
sta ptr2+1 ; Remember -count-1
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr popax ; get buf
|
|
|
|
sta ptr1
|
|
|
|
stx ptr1+1
|
|
|
|
jsr popax ; get fd and discard
|
|
|
|
L1: inc ptr2
|
2003-04-13 22:12:09 +00:00
|
|
|
bne L2
|
|
|
|
inc ptr2+1
|
|
|
|
beq L9
|
|
|
|
L2: ldy #0
|
2013-05-09 11:56:54 +00:00
|
|
|
lda (ptr1),y
|
2003-04-13 22:12:09 +00:00
|
|
|
tax
|
|
|
|
cpx #$0A ; Check for \n
|
|
|
|
bne L3
|
|
|
|
jsr PRINT
|
|
|
|
ldx #$0D
|
|
|
|
L3: jsr PRINT
|
2013-05-09 11:56:54 +00:00
|
|
|
inc ptr1
|
|
|
|
bne L1
|
|
|
|
inc ptr1+1
|
2003-04-13 22:12:09 +00:00
|
|
|
jmp L1
|
|
|
|
|
|
|
|
; No error, return count
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
L9: lda ptr3
|
|
|
|
ldx ptr3+1
|
|
|
|
rts
|
2003-04-13 22:12:09 +00:00
|
|
|
|
|
|
|
.endproc
|
|
|
|
|
|
|
|
|