Optimize my text adventure code?

You need an actual VIC.

Moderator: Moderators

Post Reply
HarryP2
Vic 20 Dabbler
Posts: 85
Joined: Sat Sep 26, 2015 8:40 am
Location: New York, U.S.A.

Optimize my text adventure code?

Post 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/.
HarryP2
Vic 20 Dabbler
Posts: 85
Joined: Sat Sep 26, 2015 8:40 am
Location: New York, U.S.A.

Re: Optimize my text adventure code?

Post 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?
HarryP2
Vic 20 Dabbler
Posts: 85
Joined: Sat Sep 26, 2015 8:40 am
Location: New York, U.S.A.

Improving AdvSkelVic65?

Post 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. :)
User avatar
JonBrawn
Vic 20 Devotee
Posts: 225
Joined: Sat Sep 11, 2021 10:47 pm
Website: http://youtube.com/@vicenary
Location: Austin TX USA
Occupation: CPU design engineer

Re: Optimize my text adventure code?

Post by JonBrawn »

HarryP2 wrote: Thu Jul 14, 2022 7:18 amI want 2.2k. Any ideas?
What language are you using?
Working on FPGA replacement for 6560/6561
https://youtube.com/@vicenary
HarryP2
Vic 20 Dabbler
Posts: 85
Joined: Sat Sep 26, 2015 8:40 am
Location: New York, U.S.A.

Re: Optimize my text adventure code?

Post by HarryP2 »

I'm using cc65.
User avatar
JonBrawn
Vic 20 Devotee
Posts: 225
Joined: Sat Sep 11, 2021 10:47 pm
Website: http://youtube.com/@vicenary
Location: Austin TX USA
Occupation: CPU design engineer

Re: Optimize my text adventure code?

Post 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.
Working on FPGA replacement for 6560/6561
https://youtube.com/@vicenary
HarryP2
Vic 20 Dabbler
Posts: 85
Joined: Sat Sep 26, 2015 8:40 am
Location: New York, U.S.A.

Re: Optimize my text adventure code?

Post 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. :)
Post Reply