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
|
2018-05-20 13:30:18 +00:00
|
|
|
.import popax, popptr1
|
2013-05-09 11:56:54 +00:00
|
|
|
.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
|
|
|
|
2020-11-01 21:59:07 +00:00
|
|
|
inx
|
|
|
|
stx ptr2+1
|
|
|
|
tax
|
|
|
|
inx
|
|
|
|
stx ptr2 ; save count with each byte incremented separately
|
2003-04-13 22:12:09 +00:00
|
|
|
|
2018-05-20 13:30:18 +00:00
|
|
|
jsr popptr1 ; get buf
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr popax ; get fd and discard
|
2020-11-01 21:59:07 +00:00
|
|
|
L1: dec ptr2
|
2003-04-13 22:12:09 +00:00
|
|
|
bne L2
|
2020-11-01 21:59:07 +00:00
|
|
|
dec ptr2+1
|
2003-04-13 22:12:09 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|