Apple2: Add file_set_type() and file_set_auxtype()

MLI wrapper to be able to update existing ProDOS
files' type and auxtype.
This commit is contained in:
Colin Leroy-Mira
2025-08-17 17:28:03 +02:00
committed by Oliver Schmidt
parent 6efe447d14
commit 86bcf32580
7 changed files with 140 additions and 0 deletions

View File

@@ -354,6 +354,8 @@ usage.
<item>allow_lowercase <item>allow_lowercase
<item>beep <item>beep
<item>dir_entry_count <item>dir_entry_count
<item>file_set_auxtype
<item>file_set_type
<item>get_tv <item>get_tv
<item>get_ostype <item>get_ostype
<item>gmtime_dt <item>gmtime_dt

View File

@@ -333,6 +333,8 @@ usage.
<item>_datetime <item>_datetime
<item>beep <item>beep
<item>dir_entry_count <item>dir_entry_count
<item>file_set_auxtype
<item>file_set_type
<item>get_tv <item>get_tv
<item>get_ostype <item>get_ostype
<item>gmtime_dt <item>gmtime_dt

View File

@@ -98,6 +98,8 @@ function.
<item>allow_lowercase <item>allow_lowercase
<item><ref id="beep" name="beep"> <item><ref id="beep" name="beep">
<item><ref id="dir_entry_count" name="dir_entry_count"> <item><ref id="dir_entry_count" name="dir_entry_count">
<item><ref id="file_set_type" name="file_set_type">
<item><ref id="file_set_auxtype" name="file_set_auxtype">
<item><ref id="get_tv" name="get_tv"> <item><ref id="get_tv" name="get_tv">
<item><ref id="get_ostype" name="get_ostype"> <item><ref id="get_ostype" name="get_ostype">
<item><ref id="gmtime_dt" name="gmtime_dt"> <item><ref id="gmtime_dt" name="gmtime_dt">
@@ -114,6 +116,8 @@ function.
<item>_dos_type <item>_dos_type
<item><ref id="beep" name="beep"> <item><ref id="beep" name="beep">
<item><ref id="dir_entry_count" name="dir_entry_count"> <item><ref id="dir_entry_count" name="dir_entry_count">
<item><ref id="file_set_type" name="file_set_type">
<item><ref id="file_set_auxtype" name="file_set_auxtype">
<item><ref id="get_tv" name="get_tv"> <item><ref id="get_tv" name="get_tv">
<item><ref id="get_ostype" name="get_ostype"> <item><ref id="get_ostype" name="get_ostype">
<item><ref id="gmtime_dt" name="gmtime_dt"> <item><ref id="gmtime_dt" name="gmtime_dt">
@@ -4267,6 +4271,48 @@ file may have unpredictable results.
</quote> </quote>
<sect1>file_set_auxtype<label id="file_set_auxtype"><p>
<quote>
<descrip>
<tag/Function/Updates the ProDOS auxiliary type of a file.
<tag/Header/<tt/<ref id="apple2.h" name="apple2.h">/
<tag/Declaration/<tt/int __fastcall__ file_set_auxtype(const char *pathname, unsigned int auxtype);/
<tag/Description/<tt/file_set_auxtype/ is machine dependent and does not exist for
all supported targets. It updates the ProDOS auxiliary
type of the <tt/pathname/ file, and returns 0 on success
or sets <tt/errno/ on error.
<tag/Notes/<itemize>
<item>The function does not exist on all platforms.
<item>See <tt/apple2_filetype.h/ for a list of known auxtypes.
</itemize>
<tag/Availability/cc65 (not all platforms)
<tag/Example/None.
</descrip>
</quote>
<sect1>file_set_type<label id="file_set_type"><p>
<quote>
<descrip>
<tag/Function/Updates the ProDOS type of a file.
<tag/Header/<tt/<ref id="apple2.h" name="apple2.h">/
<tag/Declaration/<tt/int __fastcall__ file_set_type(const char *pathname, unsigned char type);/
<tag/Description/<tt/file_set_type/ is machine dependent and does not exist for
all supported targets. It updates the ProDOS type of the
<tt/pathname/ file, and returns 0 on success or sets
<tt/errno/ on error.
<tag/Notes/<itemize>
<item>The function does not exist on all platforms.
<item>See <tt/apple2_filetype.h/ for a list of known file types.
</itemize>
<tag/Availability/cc65 (not all platforms)
<tag/Example/None.
</descrip>
</quote>
<sect1>free<label id="free"><p> <sect1>free<label id="free"><p>
<quote> <quote>

View File

@@ -294,6 +294,12 @@ unsigned char get_tv (void);
unsigned char get_ostype (void); unsigned char get_ostype (void);
/* Get the machine type. Returns one of the APPLE_xxx codes. */ /* Get the machine type. Returns one of the APPLE_xxx codes. */
int __fastcall__ file_set_type(const char *pathname, unsigned char type);
/* Sets the ProDOS type for the file, returns 0 on success, sets errno on failure */
int __fastcall__ file_set_auxtype(const char *pathname, unsigned int auxtype);
/* Sets the ProDOS auxtype for the file, returns 0 on success, sets errno on failure */
void rebootafterexit (void); void rebootafterexit (void);
/* Reboot machine after program termination has completed. */ /* Reboot machine after program termination has completed. */

View File

@@ -318,5 +318,7 @@
extern unsigned char _filetype; /* Default: PRODOS_T_BIN */ extern unsigned char _filetype; /* Default: PRODOS_T_BIN */
extern unsigned int _auxtype; /* Default: 0 */ extern unsigned int _auxtype; /* Default: 0 */
/* End of apple2_filetype.h */ /* End of apple2_filetype.h */
#endif #endif

View File

@@ -0,0 +1,79 @@
;
; Colin Leroy-Mira, 2025 <colin@colino.net>
;
; int __fastcall__ file_set_type(const char *pathname, unsigned char type);
; int __fastcall__ file_set_auxtype(const char *pathname, unsigned int auxtype);
;
.export _file_set_type, _file_set_auxtype
.import pushname, popname, mli_file_info_direct
.import popa, popax
.include "zeropage.inc"
.include "errno.inc"
.include "mli.inc"
auxtype = tmp1
type = tmp3
mod_flag = tmp4
UPDATE_TYPE = $00
UPDATE_AUXTYPE = $FF
_file_set_type:
sta type
ldy #UPDATE_TYPE
sty mod_flag
beq mli_update
_file_set_auxtype:
sta auxtype
stx auxtype+1
ldy #UPDATE_AUXTYPE
sty mod_flag
mli_update:
; Get pathname
jsr popax
jsr pushname
bne oserr
; ProDOS 8 TechRef, 4.4.4: You should use
; the GET_FILE_INFO call to read a files
; attributes into a parameter list, modify
; them as needed, and then use the same
; parameter list for the SET_FILE_INFO call.
jsr mli_file_info_direct
; Bail if we could not get the information.
bcs cleanup
; Update type if needed
bit mod_flag
bmi :+
lda type
sta mliparam + MLI::INFO::FILE_TYPE
jmp set_info
: ; Otherwise update auxtype
lda auxtype
sta mliparam + MLI::INFO::AUX_TYPE
lda auxtype+1
sta mliparam + MLI::INFO::AUX_TYPE+1
set_info:
; Set file information
lda #SET_INFO_CALL
ldx #SET_INFO_COUNT
jsr callmli
cleanup:
php ; Save return status
jsr popname ; Preserves A
plp
bcs oserr
rts
oserr:
jsr ___mappederrno
sec
rts

View File

@@ -20,6 +20,9 @@ DESTROY_COUNT = 1
RENAME_CALL = $C2 RENAME_CALL = $C2
RENAME_COUNT = 2 RENAME_COUNT = 2
SET_INFO_CALL = $C3
SET_INFO_COUNT = 7
GET_INFO_CALL = $C4 GET_INFO_CALL = $C4
GET_INFO_COUNT = $A GET_INFO_COUNT = $A