Briley Witch RPG Diary – 25/10/2017

I’ve been busy recently coding my C64 RPG, adding more graphics, but I did hit a snag the other day when I ran out of background characters for the village area!


Well, not to be defeated, I came up with a solution… and I thought I’d detail it here as I’m pleased with the results…


Character Swapping

Being an 8-bit computer, the C64 has a 256 character charset. Since I need a font for all the in-game text, plus other special characters for window borders and the like, I’m reserving 96 characters at the top of my charset for the font and any associated graphics/special characters.


That leaves 160 chars for the background graphics, but it’s this area that ran out the other day.


Now, since the village charset has both inside and outdoor graphics (as you can go inside houses), it occurred to me there are certain chars that are not visible based on the player’s location.


So the solution to my problem was quite simple: if I used up another 512 bytes of RAM, I could store an alternate 64 char block, and depending on whether the player was inside or outdoors, do a RAM swap between the first 64 characters of my charset with the alternate set. All I needed was a flag (CharacterBank) to store the state of the current swap, and use that to trigger a swap or not.


I added another flag (Inside) to store the current state of the player, whether they are inside or not; this flag is modified by the doorway system, and used when there’s a screen transition. Thus, if CharacterBank doesn’t equal Inside, the characters are swapped and CharacterBank is toggled. I also have to swap the character colour attribute table, but that’s a trivial issue and is done in addition to the character swap.


Editor Changes

Due to the need for an extra bank of characters, I had to make some changes to my C64 graphics editor. The idea of adding extra charsets and having to swap between them (as well as adding the ability of copying characters from one charset to another and all the ensuing mayhem due to changes to the undo/redo system) was pretty horrifying.


Wasn’t just the charsets, but the blocks too. I’d have a situation where the map editor could looked messed up for either the inside or the outside depending on what charset the editor was using. I did think to use separate files, but that wasn’t appealing..


So, I needed another solution.


Remember, I said earlier the background charset uses 160 out of 256 chars. Well, that leaves 96 unused. I only needed 64, so I changed the editor to use what I call Banked Character Mode. Basically, the top 64 chars are reserved for the 2nd char bank, and thus the 2nd partial charset. In terms of editing, I allow the charset editor to edit any character, including swapping/copy/paste, and every other editing function. KISS for the win! The following image shows the charset layout, including the (hashed) unused area.


[image error]Showing the 64 banked characters at the end of the charset.

Now I have a map editor where I can not only view the outdoor blocks properly, but also the inside blocks! I do have to take care with what characters are used where (can’t use outdoor chars on the inside and vice versa), but that’s a minor issue compared with making everything work.


On export, the two charsets are exported as separate files, the normal 160 char block, plus the additional 64 banked characters. I also fix the block-set on export, remapping any chars in the 192-255 range to the 0-63 range.


Banked Character Mode also exports the character colour table as a full 256 byte table, the top 64 entries being the colour attributes for the banked charset. My C64 engine reserves 256 bytes of RAM for this table, so I don’t lose any more RAM. As I’ve already said swapping entries in the table is trivial.


So, that’s it! I can now use more characters for both inside houses, and outdoors! Okay, so I lose 512 bytes of RAM, but I think it’s worth the sacrifice, don’t you?


As a side note, thinking of releasing my tools (and associated 6502 code) one day to the world…


 •  0 comments  •  flag
Share on Twitter
Published on October 25, 2017 05:45
No comments have been added yet.