Page 1 of 1

Optimize my text adventure code?

Posted: Tue Jul 12, 2022 1:54 pm
by HarryP2
Hi! I want some ideas on how I can optimize my AdvSkelVic65 program. I recently gained .03k by converting the Look command's exits list to a look, but then, I broke the code and had to revert to an earlier state. I also could squeeze each byte of text to seven bits. I already have a function that prints tokens. How else can I optimize AdvSkelVic65? You can find it at https://sourceforge.net/projects/cc65extra/files/game/.

Re: Optimize my text adventure code?

Posted: Thu Jul 14, 2022 7:18 am
by HarryP2
The latest problem was that I had a memory area in zp that infiltrated the area used by the kernal. I fixed that and did some rearranging, not just moving code out of the stub, and now, I have 2.29k, .04k less than before the optimization. :) I want 2.2k. Any ideas?

Improving AdvSkelVic65?

Posted: Tue Jul 26, 2022 2:00 pm
by HarryP2
Hi! Any thoughts on how I can improve AdvSkelVic65 and AdvSkel65? I really enjoy those programs and want to optimize and improve them. :)

Re: Optimize my text adventure code?

Posted: Mon Aug 22, 2022 5:56 pm
by JonBrawn
HarryP2 wrote: Thu Jul 14, 2022 7:18 amI want 2.2k. Any ideas?
What language are you using?

Re: Optimize my text adventure code?

Posted: Tue Aug 23, 2022 6:25 am
by HarryP2
I'm using cc65.

Re: Optimize my text adventure code?

Posted: Tue Aug 23, 2022 7:21 pm
by JonBrawn
Cc65 is great. However, it won't produce the super-fast optimal code you've been talking about writing. This doesn't mean that you shouldn't use it, though - the approach I'd recommend is to use VICE configured for the maximum amount of memory, write your program in pure C, debug it, and get it working fully in C. Once you've got it working and debugged, then add '-l listing.txt' to the cl65 command line and study the assembler it's produced. You might be horrified at the number of JSR calls that it produces and the hoops it has to jump through to do even what are seemingly trivial things. Now you start optimizing. Some things are no-brainers - get rid of printf() and instead use the library routing that comes with cc65 that just outputs a string to the screen, which I believe you've already embarked on. Are all of your strings 256 bytes or fewer? If so, write your own strcmp() and strcpy() routines that only need a single loop, and write the replacement routines in assembler, not C. There'll be a lot of code to handle passing values to functions - mostly as 16-bit entities - so start to optimize these to only pass 8 bits unless you need to pass 16 bits (pointers are 16 bits, though, so they need to be left alone, or restructure the code to pass by value). Try not to use malloc() - dynamic memory allocation in a resource-limited environment is a great source of hard-to-find bugs. Keep throwing out things that you don't need the full functionality of and replace them with your assembler versions that are tuned to what your program is doing. Keep going until it fits in the memory budget that you are targeting. Save frequently. Make backups. Invest in a couple of cases of Jolt Cola.

Re: Optimize my text adventure code?

Posted: Wed Aug 24, 2022 5:12 am
by HarryP2
I've been doing everything you mentioned except the Jolt Cola remark. :) I've also been using CBMSimpleIO to output text, as it is more efficient than cc65's console I/O library. I have some of my optimizations for cc65 at https://sourceforge.net/projects/cc65extra/files/. I ask you to take a look at my source code in the games/ folder. The files are AdvSkelVic65.zip and AdvSkel65.zip. Thank you for the help, though. :)