• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
Retro Game Coders

Retro Game Coders

Retro computer/console game + dev community

  • About
    • Retro Computer Collection
    • Contact
  • Blog
  • Retro Resources
    • Retro Gaming Timeline
    • Online Retro IDE
    • Retro Pixel Art Editor
    • Dungeon Loom Map Editor
    • 6502 Programmer’s Reference
    • Emulators
      • Acorn Electron
      • Amstrad CPC Emulator
      • Online BBC Micro Emulator
      • Commodore PET Emulator
      • Browser C64 Emulator
      • DOSBox/DOS PC emulator
      • Tandy CoCo/Dragon
    • Best Retro YouTube Channels
    • New Retro Books
    • Raspberry Pi Amiga Emulation
    • MiSTer FPGA Tutorial
    • BMC64 C64 Pi
  • Community

Home » Retro Game Coders Blog » Retro Gaming News and Reviews

CC65/CL65 Ram Optimization

Acorn Electron Main Board

Adding more features while coding my Rogue-Like game meant I butted up against memory limitations again.

Adding more features while coding my Rogue-Like game meant I butted up against memory limitations again.

The two features were “field of view” (sometimes called “Fog of War), where you don’t get to see the whole screen at once.

Related to the first new feature is the second which is a spell (currently automatically casts) that reveals the whole screen.

Due to the above, I needed to code a basic “Pythag” routine to see how close the player was to the enemies before making them move or attack. The last time I used that piece of math was back when I built a website for a brewery and they wanted a “find my nearest” restaurant/bar finder!

Now, this tipping me over the RAM limits is not very surprising for two reasons:

  1. I am coding with a target platform that only has 32KB of total RAM.
  2. My code is relatively high-level and has extra overhead for multi-platform retro coding whereas these sorts of games used to utilize highly efficient assembly.

Still, I want to make sure I lose as few neat features as possible, plus I am not close to finished, so can I claw back some bloat from the compiler itself.

Yes!

CCL65 has some command-line parameters that can help us out, but first there is a general rule of thumb with old 8 bit systems.

Join Retro Game Coders Community
Join the Retro Game Coders Community

Check Your zero page and BSS Usage

BSS (Block Started by Symbol) variables, that is global and static variables, take up RAM, so it is best to minimize their use.

Zero-page variables are faster to access but take up even more limited memory (the first page as the name suggests).

Unfortunately, one of my targets is CP/M which prefers global variables.

Consider using fewer global/static variables or tactically placing frequently accessed ones in zeropage.

Now on to the compiler switches.

Optimize for Size (-O flag)

Try using -O or -Os to optimize for space:

cl65 -O
This applies basic optimizations that can help reduce RAM and code size.

Disable Runtime Type Information

If you don’t need runtime type checking, defining this can save RAM:

-DCC65_NO_RUNTIME_TYPE_CHECKS

💬 Questions or comments? Head over to the community to discuss!

Optimize Stack Usage

By default, cc65 places local variables on the stack. If you have functions with large local variables, you might be able to save stack space with:

--static-locals
This moves local variables to a static storage area, which can reduce stack usage but may increase global RAM usage.

Use –codesize to Prioritize Code Over RAM

--codesize 100
This shifts optimization toward reducing code size, which might indirectly help with RAM usage.

Memory Configuration Tweaks (.cfg file)

If you are using a custom memory configuration file (.cfg), you might be able to tweak it to save RAM:

Reduce Heap Size

If you’re not using dynamic memory allocation, reduce or remove the heap section.

Reduce Stack Size

If your program doesn’t use deep recursion or large automatic variables, you can lower the stack size.

Category: Retro Gaming News and ReviewsTag: programming, Retro C/C++ Programming
Previous Post:Easy C Game EngineIs There Such a Thing as an Easy C Game Engine?
Next Post:Rogue-Like Game: Re-code in PyGame?Rogue Game in PyGame

Retro Game Coders

Retro computer/console game + dev programming community by Chris Garrett

  • Bluesky
  • Threads
  • Facebook
  • Instagram
  • YouTube
  • Mastodon

Maker Hacks ・ D6Combat・chrisg.com

© Copyright 2026 Chris Garrett

Privacy ﹒ Terms of Service

Return to top