xahmol wrote: ↑Mon Jan 27, 2025 9:52 pm
Your statement ‘for a ROM’ makes perfect sense. Then I fully agree.
But that is not saying the functions are weak, they are just not suitable for that purpose…..
Normally calling ROM functions really is the way to go to produce smaller and faster code.
Then again, for writing ROMs where every byte counts, writing in C in CC65 is maybe not the best way for another reason, namely the rather big and ineffcient code the compiler creates even on own functions if not pure assembly.
Maybe especially for ROMs it would be worthwhile to investigate alternatives, especially as lib support is not an issue if you are writing your own functions anyway.
I have to disagree with that ROM-routines would be faster. I've written my own circle/line implementations in pure-C and they seem to be consistently around 30-50% faster. But sure, saves precious RAM to use the ROM.
I think with LOCI we will see many more programs compiled both as tap-files for BASIC ROM and as pure standalone ROM-code. Not sure if one can make a single universal binary with an "intermediary dispatch functionality". But it would require the binary to have to be relocatable., I think.
In my experience the minimal replacement for the ROM-routines aren't that big. I don't have an estimate of how big the Basics interpreter by itself is, but an guestimate would be 16-1k (charset)-2K (graphics/sound)-2K (float math)-1K (printing/screen)==> 11KB. Parsing all tha syntax may be costly. Maybe somebody has looked into the size of the various?
Yes, the codegen of CC65 is quote big, but from my little experience of other 6502 compilers it often generates more compact code (per routine), whereas other compilers seem to generate *super*optimized code but at 50-100% more byte-count!
One way to see the CC65 code is that it's like a byte-code machine where all the interpreter dispatch is replaced by generated JSR, JSR to a "small" kernerl-library of primitives.
I've looked at the design of the OSCAR compiler and it seems to be he right fit, especially if you can control the codegen to generate smaller code for code not run very often, or once.'
As for super optimized handwritten assembly - sure go ahead. I don't do it at first. First I try to figure out functionally, so I think it's fine for initial version to be C of conio etc, and be portable. Compilation can have flag to choose to use BASIC ROM or replace the functionally as appropriate. Eventually, bits and pieces can be replaced by ASM. But it is not my immediate goal. But squeezing everything into 16KB is the main goal.