1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-25 17:29:50 +00:00

Apple2: Provide a way to get directory file count

The information is available in the directory key block.
Providing it to the user as soon as opendir() is done
can save them costly code.
This commit is contained in:
Colin Leroy-Mira 2024-11-10 13:38:35 +01:00 committed by Oliver Schmidt
parent 36132a437b
commit 40d9f3eed5
9 changed files with 64 additions and 14 deletions

View File

@ -332,6 +332,7 @@ usage.
<item>_datetime
<item>allow_lowercase
<item>beep
<item>dir_file_count
<item>get_ostype
<item>gmtime_dt
<item>mktime_dt

View File

@ -332,6 +332,7 @@ usage.
<item>_filetype
<item>_datetime
<item>beep
<item>dir_file_count
<item>get_ostype
<item>gmtime_dt
<item>mktime_dt

View File

@ -97,6 +97,7 @@ function.
<item>_dos_type
<item>allow_lowercase
<item><ref id="beep" name="beep">
<item><ref id="dir_file_count" name="dir_file_count">
<item><ref id="get_ostype" name="get_ostype">
<item><ref id="gmtime_dt" name="gmtime_dt">
<item><ref id="mktime_dt" name="mktime_dt">
@ -109,6 +110,7 @@ function.
<itemize>
<item>_dos_type
<item><ref id="beep" name="beep">
<item><ref id="dir_file_count" name="dir_file_count">
<item><ref id="get_ostype" name="get_ostype">
<item><ref id="gmtime_dt" name="gmtime_dt">
<item><ref id="mktime_dt" name="mktime_dt">
@ -3524,6 +3526,25 @@ used in presence of a prototype.
</quote>
<sect1>dir_file_count<label id="dir_file_count"><p>
<quote>
<descrip>
<tag/Function/Returns the number of files in the directory.
<tag/Header/<tt/<ref id="apple2.h" name="apple2.h">/
<tag/Declaration/<tt/unsigned int __fastcall__ dir_file_count(DIR *dir);/
<tag/Description/<tt/dir_file_count/ is machine dependent and does not exist for
all supported targets. If it exists, it returns the number of active
(non-deleted) files in the directory.
<tag/Notes/<itemize>
<item>The function does not exist on all platforms.
</itemize>
<tag/Availability/cc65 (not all platforms)
<tag/Example/None.
</descrip>
</quote>
<sect1>div<label id="div"><p>
<quote>

View File

@ -232,6 +232,11 @@ struct tm* __fastcall__ gmtime_dt (const struct datetime* dt);
time_t __fastcall__ mktime_dt (const struct datetime* dt);
/* Converts a ProDOS date/time structure to a time_t UNIX timestamp */
typedef struct DIR DIR;
unsigned int __fastcall__ dir_file_count(DIR *dir);
/* Returns the number of active files in a ProDOS directory */
#if !defined(__APPLE2ENH__)
unsigned char __fastcall__ allow_lowercase (unsigned char onoff);
/* If onoff is 0, lowercase characters printed to the screen via STDIO and

View File

@ -147,7 +147,5 @@ void __fastcall__ seekdir (DIR* dir, long offs);
void __fastcall__ rewinddir (DIR* dir);
/* End of dirent.h */
#endif

View File

@ -45,6 +45,7 @@ struct DIR {
int fd;
unsigned char entry_length;
unsigned char entries_per_block;
unsigned int file_count;
unsigned char current_entry;
union {
unsigned char bytes[512];

View File

@ -2,8 +2,8 @@
FD .word
ENTRY_LENGTH .byte
ENTRIES_PER_BLOCK .byte
FILE_COUNT .word
CURRENT_ENTRY .byte
.union
BYTES .byte 512
.struct CONTENT

View File

@ -0,0 +1,24 @@
;
; Colin Leroy-Mira <colin@colino.net>, 2024
;
; unsigned int __fastcall__ dir_file_count(DIR *dir);
;
.export _dir_file_count
.importzp ptr1
.include "apple2.inc"
.include "dir.inc"
.proc _dir_file_count
sta ptr1
stx ptr1+1
ldy #DIR::FILE_COUNT + 1
lda (ptr1),y
tax
dey
lda (ptr1),y
rts
.endproc

View File

@ -128,24 +128,23 @@
; Read succeeded, populate dir struct
jsr popptr1 ; Restore our dir pointer
ldy #$24 + DIR::BYTES
lda (ptr1),y ; ENTRIES_PER_BLOCK
pha ; Back it up
; Get file_count to entry_length from block
ldy #$26 + DIR::BYTES
: lda (ptr1),y
pha
dey
lda (ptr1),y ; ENTRY_LENGTH
cpy #$23 + DIR::BYTES - 1
bne :-
; Set entry_length to file_count in struct
ldy #DIR::ENTRY_LENGTH
: pla
sta (ptr1),y
pla
.assert DIR::ENTRIES_PER_BLOCK = DIR::ENTRY_LENGTH + 1, error
iny
sta (ptr1),y
cpy #DIR::CURRENT_ENTRY
bne :-
; Skip directory header entry
.assert DIR::CURRENT_ENTRY = DIR::ENTRIES_PER_BLOCK + 1, error
iny
lda #$01
sta (ptr1),y