2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 17.06.1998
|
|
|
|
;
|
|
|
|
; int _fdesc (void);
|
|
|
|
; /* Find a free descriptor slot */
|
|
|
|
|
|
|
|
|
|
|
|
.export __fdesc
|
2002-03-24 13:26:18 +00:00
|
|
|
.import return0
|
|
|
|
|
2003-05-03 08:49:51 +00:00
|
|
|
.include "stdio.inc"
|
2002-03-24 13:26:18 +00:00
|
|
|
.include "_file.inc"
|
|
|
|
|
|
|
|
.proc __fdesc
|
|
|
|
|
|
|
|
ldy #0
|
|
|
|
lda #_FOPEN
|
|
|
|
Loop: and __filetab + _FILE_f_flags,y ; load flags
|
|
|
|
beq Found ; jump if closed
|
|
|
|
.repeat ::_FILE_size
|
|
|
|
iny
|
|
|
|
.endrepeat
|
|
|
|
cpy #(FOPEN_MAX * _FILE_size) ; Done?
|
|
|
|
bne Loop
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; File table is full
|
|
|
|
|
2002-03-24 13:26:18 +00:00
|
|
|
jmp return0
|
|
|
|
|
|
|
|
; Free slot found, get address
|
|
|
|
|
|
|
|
Found: tya ; Offset
|
|
|
|
clc
|
|
|
|
adc #<__filetab
|
|
|
|
ldx #>__filetab ; High byte
|
|
|
|
bcc @L1 ; Jump if no overflow
|
|
|
|
inx ; Bump high byte
|
|
|
|
@L1: rts
|
|
|
|
|
|
|
|
.endproc
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|