mirror of
https://github.com/cc65/cc65.git
synced 2024-09-08 01:54:33 +00:00
65 lines
1.3 KiB
ArmAsm
65 lines
1.3 KiB
ArmAsm
|
;
|
||
|
; Oliver Schmidt, 30.12.2004
|
||
|
;
|
||
|
; File descriptor management for the POSIX I/O routines
|
||
|
;
|
||
|
|
||
|
.include "errno.inc"
|
||
|
.include "fcntl.inc"
|
||
|
.include "filedes.inc"
|
||
|
|
||
|
getfd:
|
||
|
; Check for handle >= 256
|
||
|
cpx #$00
|
||
|
bne error
|
||
|
|
||
|
; Check for handle >= MAX_FDS
|
||
|
cmp #MAX_FDS
|
||
|
bcs error
|
||
|
|
||
|
.if .sizeof(FD) = 4
|
||
|
|
||
|
; Convert handle to fdtab slot
|
||
|
asl
|
||
|
asl
|
||
|
|
||
|
.else
|
||
|
.error "Assertion failed"
|
||
|
.endif
|
||
|
|
||
|
; Check for fdtab slot in use
|
||
|
tay
|
||
|
lda fdtab + FD::REF_NUM,y
|
||
|
beq error
|
||
|
|
||
|
; Return success
|
||
|
clc
|
||
|
rts
|
||
|
|
||
|
; Load errno code and return error
|
||
|
error: lda #EINVAL
|
||
|
sec
|
||
|
rts
|
||
|
|
||
|
.data
|
||
|
|
||
|
fdtab: .if .sizeof(FD) = 4
|
||
|
|
||
|
.byte $80 ; STDIN_FILENO ::REF_NUM
|
||
|
.byte O_RDONLY ; STDIN_FILENO ::FLAGS
|
||
|
.addr $0000 ; STDIN_FILENO ::BUFFER
|
||
|
|
||
|
.byte $80 ; STDOUT_FILENO::REF_NUM
|
||
|
.byte O_WRONLY ; STDOUT_FILENO::FLAGS
|
||
|
.addr $0000 ; STDOUT_FILENO::BUFFER
|
||
|
|
||
|
.byte $80 ; STDERR_FILENO::REF_NUM
|
||
|
.byte O_WRONLY ; STDERR_FILENO::FLAGS
|
||
|
.addr $0000 ; STDERR_FILENO::BUFFER
|
||
|
|
||
|
.else
|
||
|
.error "Assertion failed"
|
||
|
.endif
|
||
|
|
||
|
.res (MAX_FDS - 3) * .sizeof(FD)
|