2005-04-12 09:12:48 +00:00
|
|
|
;
|
|
|
|
; Oliver Schmidt, 12.01.2005
|
|
|
|
;
|
|
|
|
; int __fastcall__ write (int fd, const void* buf, unsigned count);
|
|
|
|
;
|
2003-04-13 21:51:01 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _write
|
|
|
|
.import rwprolog, rwcommon, rwepilog
|
|
|
|
.import 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"
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
_write:
|
|
|
|
; 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 write access
|
2013-05-09 11:56:54 +00:00
|
|
|
lda fdtab + FD::FLAGS,y
|
|
|
|
and #O_WRONLY
|
|
|
|
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
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
; Check for append flag
|
|
|
|
lda fdtab + FD::FLAGS,y
|
|
|
|
and #O_APPEND
|
|
|
|
beq write
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Set fd
|
2013-05-09 11:56:54 +00:00
|
|
|
stx mliparam + MLI::EOF::REF_NUM
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Get file size
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #GET_EOF_CALL
|
|
|
|
ldx #EOF_COUNT
|
|
|
|
jsr callmli
|
|
|
|
bcs oserr
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; REF_NUM already set
|
2005-04-20 16:52:18 +00:00
|
|
|
.assert MLI::MARK::REF_NUM = MLI::EOF::REF_NUM, error
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; POSITION already set
|
2005-04-20 16:52:18 +00:00
|
|
|
.assert MLI::MARK::POSITION = MLI::EOF::EOF, error
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Set file pointer
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #SET_MARK_CALL
|
|
|
|
ldx #MARK_COUNT
|
|
|
|
jsr callmli
|
|
|
|
bcs oserr
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Do write
|
2013-05-09 11:56:54 +00:00
|
|
|
write: lda fdtab + FD::REF_NUM,y
|
|
|
|
ldy #WRITE_CALL
|
|
|
|
jmp rwcommon
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Save count for epilog
|
2013-05-09 11:56:54 +00:00
|
|
|
device: ldx ptr2
|
|
|
|
lda ptr2+1
|
|
|
|
stx mliparam + MLI::RW::TRANS_COUNT
|
|
|
|
sta mliparam + MLI::RW::TRANS_COUNT+1
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Check for zero count
|
2013-05-09 11:56:54 +00:00
|
|
|
ora ptr2
|
|
|
|
beq done
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Get char from buf
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #$00
|
|
|
|
next: lda (ptr1),y
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Replace '\n' with '\r'
|
2013-05-09 11:56:54 +00:00
|
|
|
cmp #$0A
|
|
|
|
bne :+
|
|
|
|
lda #$0D
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Set hi bit and write to device
|
2013-05-09 11:56:54 +00:00
|
|
|
: ora #$80
|
|
|
|
.ifndef __APPLE2ENH__
|
|
|
|
cmp #$E0 ; Test for lowercase
|
|
|
|
bcc output
|
|
|
|
and #$DF ; Convert to uppercase
|
2005-04-12 09:12:48 +00:00
|
|
|
.endif
|
2013-05-09 11:56:54 +00:00
|
|
|
output: jsr COUT ; Preserves X and Y
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Increment pointer
|
|
|
|
iny
|
2013-05-09 11:56:54 +00:00
|
|
|
bne :+
|
|
|
|
inc ptr1+1
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Decrement count
|
|
|
|
: dex
|
2013-05-09 11:56:54 +00:00
|
|
|
bne next
|
|
|
|
dec ptr2+1
|
|
|
|
bpl next
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Return success
|
2013-05-09 11:56:54 +00:00
|
|
|
done: lda #$00
|
|
|
|
jmp rwepilog
|
2005-04-12 09:12:48 +00:00
|
|
|
|
|
|
|
; Load errno code
|
2013-05-09 11:56:54 +00:00
|
|
|
einval: lda #EINVAL
|
2005-04-12 09:12:48 +00:00
|
|
|
|
2010-06-15 20:38:05 +00:00
|
|
|
; Set __errno
|
2013-05-09 11:56:54 +00:00
|
|
|
errno: jmp __directerrno
|
2005-04-12 09:12:48 +00:00
|
|
|
|
2010-06-15 20:38:05 +00:00
|
|
|
; Set __oserror
|
2013-05-09 11:56:54 +00:00
|
|
|
oserr: jmp __mappederrno
|
2005-04-20 16:52:18 +00:00
|
|
|
|