• 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

Retro Dungeon in C: Putting my CC65 code on a diet

Retro Dungeon in C

I wasn’t too surprised that my game didn’t fit into the 3.5KB available on an unexpanded Vic 20, but I was sad to see it won’t fit into a Commodore 16!

I wasn’t too surprised that my game didn’t fit into the 3.5KB available on an unexpanded Vic 20, but I was sad to see it won’t fit into a Commodore 16!

Fortunately, the target Commodore PET has 32KB, and as the name suggests, the C64 has 64KB.

This means so long as I can keep trimming the fat, I can at least have this game run on a whole bunch of classic systems, and of course anything modern.

image.png

Heck, it would likely run on a smart fridge.

With all that in mind, any future features will have a two steps forward, one step back approach.

For example, today I trimmed some bloat but then added doors. You guessed it, that put me over the 32KB memory again.

Adding the doors involves finding an available space, as with placing the character or enemies, but with some extra logic.

Imagine this is the map before we add doors:

#############
#.......#...#
####........#
#.......#...#
#.......#...#
#############

A door needs to go where there is space above and to the sides, but also needs to go where there is a wall either above and below.

Easy enough? Well, I forgot an element and ended up with cupboards …

#############
#..+....#...#
####........#
#.......#...#
#.......##+##
#############

Being right up against a wall is a pretty useless door. And even adding one space made it a pretty unlikely room.

Who is going to waste a key opening a door to nowhere?

So now my placement code for a vertical door looks like this:

void placeHDoor(void) {
    int row, col;
    unsigned char tile;
    tile = '+';
    do {
        row = (rand() % (PLAYABLE_HEIGHT - 2)) + HUD_TOP + 1;
        col = (rand() % (MAP_WIDTH - 2)) + 1;
    } while (   map[row][col] != '.'   ||
                map[row][col-1] != '.' || map[row][col-2] != '#' ||
                map[row][col+1] != '.' || map[row][col+2] != '#' ||
                map[row-1][col] != '.' || map[row+1][col] != '.' ||
                map[row-2][col] != '.' || map[row+2][col] != '.'     
            );
    map[row][col] = tile;
    map[row][col-1] = '#';
    map[row][col+1] = '#';
}

Currently, using ‘+’ to represent a door, because that is what most rogue-like games use. Eventually I will be able to replace that with more pretty characters, user defined characters, or even graphics.

Adding this logic meant something had to be jettisoned.

Thinking things through, the main reason I had the map centering code was because the map might have to fit into different sized screens.

Eventually I realized I was unlikely to be able to port the game to smaller screens than 40 columns wide while they also have less RAM.

Larger screens than 40 columns aren’t that much of a problem so long as the game looks good at 40 columns, even if the screen is then left aligned.

Removing that code and the associated arrays got me back down within the PET 32KB limits, so a sacrifice but worthwhile!

Category: Retro Gaming News and ReviewsTag: programming, Retro C/C++ Programming
Previous Post:Dungeon Game on Commodore PETDungeon Game with Random Mazes Now Working on Commodore PET
Next Post:Is There Such a Thing as an Easy C Game Engine?Easy C Game Engine

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