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
|
2003-12-03 10:15:33 +00:00
|
|
|
Loop: and __filetab + _FILE::f_flags,y ; load flags
|
2002-03-24 13:26:18 +00:00
|
|
|
beq Found ; jump if closed
|
2003-12-03 10:15:33 +00:00
|
|
|
.repeat .sizeof(_FILE)
|
2002-03-24 13:26:18 +00:00
|
|
|
iny
|
|
|
|
.endrepeat
|
2003-12-03 10:15:33 +00:00
|
|
|
cpy #(FOPEN_MAX * .sizeof(_FILE)) ; Done?
|
2002-03-24 13:26:18 +00:00
|
|
|
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
|
|
|
|
|
|
|
|