Made the directory functions compatible with the Commander X16's DOS.

It's directory listing's last line says, "mb free."
This commit is contained in:
Greg King 2021-02-15 08:50:34 -05:00
parent 43881afca2
commit 98f8064b83
5 changed files with 33 additions and 18 deletions

View File

@ -191,6 +191,8 @@ unsigned char cbm_k_acptr (void);
unsigned char cbm_k_basin (void);
void __fastcall__ cbm_k_bsout (unsigned char C);
unsigned char __fastcall__ cbm_k_chkin (unsigned char FN);
unsigned char cbm_k_chrin (void);
void __fastcall__ cbm_k_chrout (unsigned char C);
void __fastcall__ cbm_k_ciout (unsigned char C);
unsigned char __fastcall__ cbm_k_ckout (unsigned char FN);
void cbm_k_clall (void);
@ -295,7 +297,15 @@ unsigned char __fastcall__ cbm_readdir (unsigned char lfn,
/* Reads one directory line into cbm_dirent structure.
** Returns 0 if reading directory-line was successful.
** Returns non-zero if reading directory failed, or no more file-names to read.
** Returns 2 on last line. Then, l_dirent->size = the number of "blocks free."
** Returns 2 on last line. Then, l_dirent->size = the number of "blocks free",
** "blocks used", or "mb free". Return codes:
** 0 = read file-name
** 1 = couldn't read directory
** 2 = read "blocks free", "blocks used", or "mb free"
** 3 = couldn't find start of file-name
** 4 = couldn't find end of file-name
** 5 = couldn't read file-type
** 6 = premature end of file
*/
void __fastcall__ cbm_closedir (unsigned char lfn);

View File

@ -2,14 +2,16 @@
; Ullrich von Bassewitz, 03.06.1999
;
; unsigned char cbm_k_basin (void);
; unsigned char cbm_k_chrin (void);
;
.include "cbm.inc"
.export _cbm_k_basin
.export _cbm_k_basin, _cbm_k_chrin
_cbm_k_basin:
_cbm_k_chrin:
jsr BASIN
ldx #0 ; Clear high byte
rts

View File

@ -2,10 +2,12 @@
; Ullrich von Bassewitz, 03.06.1999
;
; void __fastcall__ cbm_k_bsout (unsigned char C);
; void __fastcall__ cbm_k_chrout (unsigned char C);
;
.include "cbm.inc"
.export _cbm_k_bsout
.export _cbm_k_bsout, _cbm_k_chrout
_cbm_k_bsout = BSOUT
_cbm_k_bsout := BSOUT
_cbm_k_chrout := CHROUT

View File

@ -6,6 +6,7 @@
/* 2009-10-10 -- Version 0.3 */
/* 2011-04-07 -- Version 0.4, groepaz */
/* 2011-04-14 -- Version 0.5, Greg King */
/* 2021-02-15 -- Version 0.6, Greg King */
/* Tested with floppy-drive and IDE64 devices. */
/* Not tested with messed (buggy) directory listings. */
@ -29,7 +30,7 @@ unsigned char cbm_opendir (unsigned char lfn, unsigned char device, ...)
va_list ap;
const char* name = "$";
/* The name used in cbm_open may optionally be passed */
/* The name used in cbm_open() optionally may be passed */
if (__argsize__ == 4) {
va_start (ap, device);
name = va_arg (ap, const char*);
@ -76,9 +77,10 @@ unsigned char __fastcall__ cbm_readdir (unsigned char lfn, register struct cbm_d
byte = cbm_k_basin();
switch (byte) {
/* "B" BLOCKS FREE. */
/* "B" BLOCKS FREE/USED. */
/* "M" MB FREE. */
case 'b':
case 'm':
/* Read until end; careless callers might call us again. */
while (!cbm_k_readst()) {
cbm_k_basin();
@ -168,7 +170,6 @@ unsigned char __fastcall__ cbm_readdir (unsigned char lfn, register struct cbm_d
}
rv = 0;
goto ret_val;
}
}

View File

@ -1,5 +1,7 @@
/*
** Ullrich von Bassewitz, 2012-05-30. Based on code by Groepaz.
** Based on code by Groepaz.
** 2012-05-30, Ullrich von Bassewitz
** 2021-02-15, Greg King
*/
@ -52,12 +54,14 @@ struct dirent* __fastcall__ readdir (register DIR* dir)
/* Bump the directory offset and include the bytes for line-link and size */
dir->off += count + 4;
/* End of directory is reached if the buffer contains "blocks free". It is
** sufficient here to check for the leading 'b'. buffer will contain at
** least one byte if we come here.
/* End of directory is reached if the buffer contains "blocks free/used" or
** "mb free.". It is sufficient here to check for the leading 'b' and 'm'.
** buffer will contain at least one byte if we come here.
*/
if (buffer[0] == 'b') {
goto exitpoint;
switch (buffer[0]) {
case 'b':
case 'm':
goto exitpoint;
}
/* Parse the buffer for the filename and file type */
@ -67,7 +71,6 @@ struct dirent* __fastcall__ readdir (register DIR* dir)
b = buffer;
while (i < count) {
switch (s) {
case 0:
/* Searching for start of file name */
if (*b == '"') {
@ -127,6 +130,3 @@ struct dirent* __fastcall__ readdir (register DIR* dir)
exitpoint:
return 0;
}