Closed est77 closed 7 months ago
Could you provide a sample project/sample code? I will admit wholly that the PC Engine CD relocator is only loosely tested.
My current code is quite messy, since I am experimenting still.
I first tried this:
extern uint8_t cd_error_elfsector_count;
and not defining the variable anywhere. This maps the variable to address 0x0 and access is done using lda $0000. When pce-mkcd relocs the symbol the $0000 address is replaced with the value of the symbol (not its address). The code ends up reading some random PCE hardware register, usually returning 0. I tried other variants of this idea, but I couldn't make it work.
Then I tried declaring and defining the variable myself. In this case, the symbol reference does not end up in the elf file and pce-mkcd does not patch it.
Do you have a simple example of how to make it work?
Then I tried declaring and defining the variable myself. In this case, the symbol reference does not end up in the elf file and pce-mkcd does not patch it.
Correct; it's not an unresolved external symbol, so it's not preserved for relocation with pce-mkcd.
extern uint8_t __cd_error_elf__sector_count;
This is the correct semantics, and yes, you're supposed to treat &__cd_error_elf__sector_count
as the actual variable. So referencing __cd_error_elf__sector_count
will point to an invalid address, while doing something like (uint8_t) &__cd_error_elf__sector_count
will return the value you seek.
That worked. I missed the address of part.
Thanks!
Is there any example PCE CD project?
I am having a hard time trying to get the pce-mkcd relocations to work correctly. I tried different things but I usually end up with some code like this in elf files:
0180407b <_GLOBAL__sub_I_main.cpp>: 180407b: ae 00 00 ldx $0 ; 0x1800000 <__heap_start+0x87dd30> 180407e: 8e 00 40 stx $4000 ; 0x1804000
1804081: 60 rts
And after running mkcd, I get this:
=> Relocating "cd_error_elfsector_count" @ 0180407C => 1
0180407b <_GLOBAL__sub_I_main.cpp>: 180407b: ae 01 00 ldx $100 180407e: 8e 00 40 stx $4000 1804081: 60 rts
And the symbol is initialized with the contents of some random hardware register.
Thanks.