, 19 tweets, 7 min read
My Authors
Read all threads
Shortly after the release of Total Replay v2, @a2_qkumba and I embarked on a month-long refactoring binge, which eventually (d)evolved into the most ridiculous game of 6502 code golf you've ever seen.

1/
My first major refactor was to create the global variable gGameToLaunch and keep it updated. Previously, pressing RETURN would invoke a context-specific routine that figured out which game was showing on the screen, then launch it.
This commit <github.com/a2-4am/4cade/c…> creates gGameToLaunch and modifies routines throughout Total Replay to keep it up to date. Whenever we load a new screenshot — whether in search mode or browse mode or attract mode — we update that single variable.
Next, I consolidated the drawing routines that draw text on top of loaded screenshots. This was partly out of necessity, because we added a global cheat mode, which draws common UI elements across modes. The first such commit was <github.com/a2-4am/4cade/c…>, with follow-ups.
Then qkumba got the refactoring itch and started rewriting everything to be smaller AND faster, which I'm pretty sure is a violation of some Computer Science-y principle. Example: <github.com/a2-4am/4cade/c…>
The next major step was moving the game launch logic out of the main program and into game-specific "prelaunch" files. The main program is very memory-constrained — it lives in the 16K language card — but it resides on a 32MB disk image, so we traded disk space for memory.
This led to the creation of the PRELAUNCH system, which underpins every major new feature in Total Replay v3.

The PRELAUNCH/ directory contains an executable file for EVERY GAME. Makefile and assembler magic allows us to have a "standard" file, then customize it per-game.
Each game's prelauncher runs from a common address, sets up the machine into a known state, then possibly does additional game-specific setup. This is how game-specific cheats are injected without storing 2 copies of every game.
Each game's prelauncher also knows how and where the game can be accelerated and decelerated, and it calls the appropriate functions to speed up loading. (Many games decompress themselves on launch, which is slow at 1 MHz.)
Total Replay v4 will extend this PRELAUNCH system to do amazing things like auto-detect your Mockingboard sound card and auto-configure supporting games to use it.
Having reorganized the entire code base, consolidated routines, and moved code to main memory or to external files, we then started rewriting code that already worked, with an eye on shaving as many bytes as possible. And this is where the story goes from good to great.
This long commit <github.com/a2-4am/4cade/c…> rewrote branch statements and moved entire routines so some code could fall through to other code and unrelated routines could share an RTS. It saved 8 bytes.
This commit <github.com/a2-4am/4cade/c…> simplified the keyboard handling in the Help screen by reusing some code from the Credits screen. It saved 6 bytes.
This commit <github.com/a2-4am/4cade/c…> moved multiple routines around so they could fall through to other routines, even those in other files. (I commented everything to make the dependencies clear.) It saved 12 bytes.
Total Replay persistent data starts at $D000 and grows upwards (as we add new games), while code is moved as high as possible and thus grows downwards (as we add new features).

v2 code started at $EC37 (up to $FFFF).

Despite all the new features, v3 code starts at $ECEC.

/fin
Missing some Tweet in this thread? You can try to force a refresh.

Enjoying this thread?

Keep Current with 4am

Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!