-
Notifications
You must be signed in to change notification settings - Fork 22
[breaking change] 70 shared resources cc65 api #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
74181b0
9857ede
85d82cc
7e1b1f3
3fac544
05da1b5
485f8f9
7755d42
3672bb4
24e2695
6eb8edf
0ee08bb
7d954db
5f70804
b6d1c7b
95cd1a9
61ab9ea
d987fb8
8174c8f
f230e1a
33eb3ba
6a44500
78931f4
9d8888e
031c0e0
141dd62
8433fff
5c2d089
106c10d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| /** | ||
| * @file shres.h | ||
| * @brief MEGA65 SYSPART Shared Resources Access API | ||
| * | ||
| * This API provides access to shared resources stored in the MEGA65 system | ||
| * partition (SYSPART), including files such as fonts, icons, or other binary | ||
| * assets. | ||
| * | ||
| * Resources are accessed via a special trap instruction and a sector-based | ||
| * directory format. This API allows enumeration, opening, reading, and seeking | ||
| * within those shared resources. | ||
| */ | ||
|
|
||
| #ifndef SHRES_H | ||
| #define SHRES_H | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Allow use from C++ by encapsulating with: #ifdef __cplusplus
// Being compiled by a C++ compiler, inhibit name mangling
extern "C" {
#endif
...
#ifdef __cplusplus
} // End of extern "C"
#endif |
||
| /// Triggers the low-level SYSPART shared resource trap. | ||
| extern void shres_trap(void); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add #ifdef __clang__
__attribute__((leaf))
#endif
in front of function. |
||
|
|
||
| /// Registers used for communicating with the shared resource trap. | ||
| extern unsigned char shres_regs[5]; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be a global variable? With llvm-mos, taking it as an argument for |
||
|
|
||
| /// Flag indicating that the resource is a font. | ||
| #define SHRES_FLAG_FONT 1 | ||
|
|
||
| /// Indicates the font is 16x16 pixels (requires SHRES_FLAG_FONT). | ||
| #define SHRES_FLAG_16x16 2 | ||
|
|
||
| /// Indicates the font supports Unicode (requires SHRES_FLAG_FONT). | ||
| #define SHRES_FLAG_UNICODE 4 | ||
|
|
||
| /// Maximum length of a resource name (not including null terminator). | ||
| #define MAX_RES_NAME_LEN 240 | ||
|
|
||
| /** | ||
| * @struct shared_resource | ||
| * @brief Represents a file or other data resource in the SYSPART directory. | ||
| * | ||
| * This structure includes metadata stored on disk (such as name, flags, and | ||
| * sector info), as well as an in-memory field to track read position for | ||
| * streaming access. | ||
| */ | ||
| struct shared_resource_dirent { | ||
| /// First sector of the resource. | ||
| unsigned long first_sector; | ||
|
|
||
| /// Length of the resource in sectors. | ||
| unsigned long length_in_sectors; | ||
|
|
||
| /// Length of the resource in bytes. | ||
| unsigned long length; | ||
|
|
||
| /// Bitmask of resource flags (e.g., SHRES_FLAG_FONT, SHRES_FLAG_16x16). | ||
| unsigned long flags; | ||
|
|
||
| /// Length of the resource name (as stored in the directory). | ||
| unsigned char name_len; | ||
|
|
||
| /// Null-terminated name of the resource (up to MAX_RES_NAME_LEN). | ||
| char name[MAX_RES_NAME_LEN + 1]; | ||
| }; | ||
|
|
||
| struct shared_resource { | ||
| /// First sector of the resource. | ||
| unsigned long first_sector; | ||
|
|
||
| /// Length of the resource in sectors. | ||
| unsigned long length_in_sectors; | ||
|
|
||
| /// Length of the resource in bytes. | ||
| unsigned long length; | ||
|
|
||
| /// Current read position in bytes (used internally; not stored on disk). | ||
| unsigned long position; | ||
| }; | ||
|
|
||
|
|
||
| /// Type alias for a directory handle (really a sector index). | ||
| #define shared_resource_dir unsigned int | ||
|
|
||
| /** | ||
| * @brief Opens a named shared resource and verifies required flags. | ||
| * | ||
| * @param resource_name The null-terminated name of the resource to open. | ||
| * @param required_flags A bitmask of flags that must be set on the resource. | ||
| * @param file_handle Pointer to a shared_resource structure to populate. | ||
| * @return 0 on success, 1 if not found or error. | ||
| */ | ||
| char shopen(char* resource_name, unsigned long required_flags, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| struct shared_resource* file_handle); | ||
|
|
||
| /** | ||
| * @brief Reads data from an open shared resource file. | ||
| * | ||
| * @param ptr Pointer to the output buffer. | ||
| * @param count Number of bytes to read. | ||
| * @param f Pointer to the shared_resource handle. | ||
| * @return Number of bytes actually read. | ||
| */ | ||
| unsigned int shread( | ||
| unsigned char* ptr, unsigned int count, struct shared_resource* f); | ||
|
|
||
| /** | ||
| * @brief Seeks to a new position in an open shared resource. | ||
| * | ||
| * @param f Pointer to the shared_resource handle. | ||
| * @param offset Byte offset from the origin. | ||
| * @param whence One of SEEK_SET, SEEK_CUR, or SEEK_END. | ||
| * @return 0 on success, 1 if the seek was out of bounds or invalid. | ||
| */ | ||
| char shseek(struct shared_resource* f, long offset, unsigned char whence); | ||
|
|
||
| /** | ||
| * @brief Opens the shared resource directory for iteration. | ||
| * | ||
| * @return A directory handle (starting sector index), or 0xFFFF on failure. | ||
| */ | ||
| shared_resource_dir shdopen(void); | ||
|
|
||
| /** | ||
| * @brief Reads the next matching directory entry. | ||
| * | ||
| * @param required_flags A bitmask of required flags the resource must match. | ||
| * @param directory_handle Pointer to the directory handle returned by | ||
| * shdopen(). | ||
| * @param dirent Pointer to a shared_resource structure to populate. | ||
| * @return | ||
| * - 0 on success (entry read and matches), | ||
| * - 1 if the trap failed, | ||
| * - 2 if end of directory reached (no more entries match). | ||
| */ | ||
| char shdread(unsigned long required_flags, | ||
| shared_resource_dir* directory_handle, | ||
| struct shared_resource_dirent* dirent); | ||
|
|
||
| #endif // SHRES_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
|
|
||
| .setcpu "65C02" | ||
| .export _shres_trap,_shres_regs | ||
|
|
||
| .SEGMENT "CODE" | ||
|
|
||
| .p4510 | ||
|
|
||
| ;; closedir takes file descriptor as argument (appears in A) | ||
| _shres_trap: | ||
| NEG ; Prefix instructions to make LDA -> LDQ | ||
| NEG | ||
| LDA _shres_regs | ||
| STA $D645 | ||
| NOP | ||
| NEG ; Prefix instructions to make STA -> STQ | ||
| NEG | ||
| STA _shres_regs | ||
| PHP | ||
| PLA | ||
| STA _shres_regs+4 | ||
| LDX #$00 | ||
| TAX | ||
| RTS | ||
|
|
||
| _shres_regs: | ||
| .dword 0 ; regs | ||
| .byte 0 ; processor flags |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| .global _shres_trap | ||
| .global _shres_regs | ||
|
|
||
| .section .text | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change to |
||
|
|
||
| ; _shres_trap() | ||
| ; Sends a 32-bit argument in _shres_regs[0..3] to $D645, | ||
| ; then stores 32-bit return result back into _shres_regs[0..3] | ||
| ; and processor flags into _shres_regs[4]. | ||
|
|
||
| _shres_trap: | ||
|
|
||
| phy | ||
| phz | ||
|
|
||
| lda _shres_regs+0 | ||
| ldx _shres_regs+1 | ||
| ldy _shres_regs+2 | ||
| ldz _shres_regs+3 | ||
|
|
||
| sta $D645 ; Store to the MEGA65 SYSPART trap address | ||
| nop ; Delay/stabilize (preserved from original) | ||
|
|
||
|
|
||
| ; Store result back into _shres_regs | ||
| sta _shres_regs+0 | ||
| stx _shres_regs+1 | ||
| sty _shres_regs+2 | ||
| stz _shres_regs+3 | ||
|
|
||
| php | ||
| pla | ||
| sta _shres_regs+4 ; Save status register into 5th byte | ||
| ldx #0 | ||
| txa | ||
|
|
||
| plz | ||
| ply | ||
|
|
||
| rts | ||
|
|
||
| ; Register block: 4 bytes for argument/result, 1 byte for flags | ||
|
|
||
| .section .bss | ||
| _shres_regs: | ||
| .space 5 | ||
|
|
||
|
|
||
| .section .text | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update
tests/test-fileio.cto reflect this breaking change. CI currently fails.