Skip to content

Conversation

@gardners
Copy link
Contributor

@gardners gardners commented Jun 14, 2025

Checklist

Thanks a lot for your contribution!
Please tick off the following:

  • Tests run successfully (i.e. make test)
    • [ N/A --- but tested empirically with software from megaphone telephony work ] using the CC65 compiler
    • [ N/A --- LLVM build succeeds ] using the LLVM/Clang compiler
  • [ X ] Doxygen style tags are used for public API
  • Source code is properly formatted; run e.g. clang-format -i <file>
  • [ X ] I agree to the License of this repository

@mlund mlund added the enhancement New feature or request label Jun 18, 2025
@mlund
Copy link
Collaborator

mlund commented Jun 18, 2025

I think Makefile_cc65 should also be updated. It also would be great with a small test in tests/ to assert the behavior on both compiler platforms. I also think that clang-format should be applied.

extern void shres_trap(void);

/// Registers used for communicating with the shared resource trap.
extern unsigned char shres_regs[5];
Copy link
Collaborator

@mlund mlund Jun 18, 2025

Choose a reason for hiding this comment

The 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 shres_trap() is usually better as the compiler has more optimization opportunities, e.g. use registers and reduced memory. I would prefer shres_trap() to use inline asm with llvm-mos, again for possible compiler optimization of arguments and return values (if any). I'm a little rusty but would be happy to look into this after the merge. It would be helpful with a test file in tests/ for that purpose.

* @param f Pointer to an open shared_resource structure.
* @param offset Byte offset to seek.
* @param whence One of SEEK_SET, SEEK_CUR, or SEEK_END.
* @return 0 on success, 1 if seek was out of bounds or f is NULL.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

char -> bool

* @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,
Copy link
Collaborator

@mlund mlund Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

char -> bool by including <stdbool.h> (should be available on both cc65 and clang)

@mlund
Copy link
Collaborator

mlund commented Jun 18, 2025

closes #70

* @param file_handle Pointer to the shared_resource struct to populate.
* @return 0 on success, 1 if the resource was not found or an error occurred.
*/
char shopen(char* resource_name, unsigned long required_flags,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

char -> bool

@mlund
Copy link
Collaborator

mlund commented Aug 23, 2025

Ping @gardners

* (auto-increments).
* @param dirent Pointer to a shared_resource struct to populate.
* @return
* - 0 on success (matching entry read),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add something like

#define SHDREAD_OK 0
#define SHDREAD_TRAP_FAIL 1
#define SHDREAD_END 2

to the header which would make calling code more expressive.


#ifndef SHRES_H
#define SHRES_H

Copy link
Collaborator

Choose a reason for hiding this comment

The 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

#define SHRES_H

/// Triggers the low-level SYSPART shared resource trap.
extern void shres_trap(void);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add

#ifdef __clang__
__attribute__((leaf))
#endif
in front of function.

.global _shres_trap
.global _shres_regs

.section .text
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to .section .text.shres_trap,"ax",@progbits

src/shres.c Outdated

// Verify magic string in sector 0
for (i = 0; magic_string[i]; i++) {
if (lpeek(0xffd6e00L + i) != magic_string[i]) {
Copy link
Collaborator

@mlund mlund Aug 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a named address - this seems to be "SD Card controller sector buffer"(?).

sdcard_busy_wait();

// Select SD card buffer, not FDC buffer
POKE(0xD689L,PEEK(0xD689L)|0x80);
Copy link
Collaborator

@mlund mlund Aug 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 0xD689 without L? The POKE/PEEK macros only handle 16-bit addresses as opposed to lpeek/lpoke

#endif
uint8_t
chdirroot(void);
chdirroot(uint8_t partition);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update tests/test-fileio.c to reflect this breaking change. CI currently fails.

@mlund mlund changed the title 70 shared resources cc65 api [breaking change] 70 shared resources cc65 api Aug 31, 2025
@mlund mlund added the breaking A breaking change that is not backwards compatible label Aug 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking A breaking change that is not backwards compatible enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants