2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 17.06.1998
|
|
|
|
;
|
|
|
|
; int _fdesc (void);
|
|
|
|
; /* Find a free descriptor slot */
|
|
|
|
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export __fdesc
|
|
|
|
.import return0
|
2002-03-24 13:26:18 +00:00
|
|
|
|
2003-05-03 08:49:51 +00:00
|
|
|
.include "stdio.inc"
|
2002-03-24 13:26:18 +00:00
|
|
|
.include "_file.inc"
|
|
|
|
|
|
|
|
.proc __fdesc
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #0
|
2002-03-24 13:26:18 +00:00
|
|
|
lda #_FOPEN
|
2013-05-09 11:56:54 +00:00
|
|
|
Loop: and __filetab + _FILE::f_flags,y ; load flags
|
|
|
|
beq Found ; jump if closed
|
2003-12-03 10:15:33 +00:00
|
|
|
.repeat .sizeof(_FILE)
|
2013-05-09 11:56:54 +00:00
|
|
|
iny
|
2002-03-24 13:26:18 +00:00
|
|
|
.endrepeat
|
2013-05-09 11:56:54 +00:00
|
|
|
cpy #(FOPEN_MAX * .sizeof(_FILE)) ; Done?
|
|
|
|
bne Loop
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; File table is full
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jmp return0
|
2002-03-24 13:26:18 +00:00
|
|
|
|
|
|
|
; 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
|
|
|
|
|
|
|
|