CharPad Tutorial Example

The purpose of this CharPad tutorial for C64 is to help you utilize a map for your Commodore 64 system built into CharPad 2.0 and above and see it loaded onto your screen. CharPad was created by Subchrist Software as far back as 2003. The example in this article covers the 2.0 releases.

In addition to using the built in maps that come with CharPad, you can also create your own directly from scratch since it has built in painting tools that can be used to fill a grid (known as a tile) with character patterns. The tiles which can be any selected size from 1×2 up to even 10 x 10 on the lastest versions. This CharPad tutorial for C64 covers how to utilize a 4×4 tileset to design a map for your project or game.

Getting Started

To load an existing map into CharPad you can use the menu controls that consist of File, View, Edit, Tools, and Help.

CharPad has its own menu controls ranging from File, View, Edit, Tools, and Help. We will explore these soon, but first let’s load an existing map into the tool’s memory. Click on the File menu and select Open Project. Once a Windows dialog box appears, you can search through a folder that should show the name ‘CharPad 2.0’ or something similiar and then click into the folder called Examples/Examples Rips. Depending on the version you downloaded you should see a similiar screenshot as seen below.

CharPad 2.0 Example

For our example, we will open the folder called Examples – Rips and then open the folder called Robocop to see that tileset. I have selected the file ‘Robocop L2.ctm’. Once you are successful with this part of the CharPad tutorial for C64 you should see a similar looking image below.

The following PDFs below contain all the code for the scrolling map example for the CharPad tutorial for C64 example. You can also download each document individually.

Main.asmĀ 

Game_Interrupts.asm

Game_Macros.asm

Game_Routines.asm

Player_Routines.asm

Screen_Memory.asm

Scrolling.asm

Start_Level.asm

VIC_Registers.asm

Click the button below to download all the files in a complete project that can be run inside of the CBM Prg Studio editor and your output will appear in the VICE C64 emulator once you compile and run the program for the CharPad tutorial for C64.

Here is a screenshot of the output of the Project 2 CharPad example obtained when clicking on the button to download it. It is currently setup to read any 4×4 map, but with the right modifications made it could read other maps of different sizes (such as a 2×2) as well. This project can be loaded into an emulator such as VICE C64 or even from an original Commodore 64 system.

The Character set utilizes all of the individual characters on your screen to make up the display you see (also known as redefined characters).

The Character Set Attributes are known as the “color data” (materials) that are used to fill the color of the characters seen on the map. They can also be used to setup specific collisions ranging in numbers from 0-7 and using letters from A-F. An example would be when a sprite bumps up against a wall. A collision could track that wall and prevent access through it.

The Tileset is used to append a set of characters together that can be placed individually on a map (such as a 4×4 tile). An important tip is to “reuse” tiles since the character set only consist of 255 characters in quantity.

The Map is created with the tilesets placed side by side using the character set data to reproduce an environment a sprite can move around in.

Below is a list of a similar video where I demonstrate several ways to access the character data and embed it into a project.

Character SetĀ 

Character Set Attributes

Tile Set

Map

Each of these binary files can be generated by going to the menu section and selecting File/Import/Export/Raw Binary File, and then you would be sure to save all of the following as listed below:

  • Export Character Set
  • Export Character Set Attributes
  • Export Tile Set
  • Export Map

The following folder directory is an example of the project download that are accessed directly in the project using the ‘incbin’ statement.

In order to make sure that the binary data can be saved, it is important to go to the menu Tools/Compress Data. This is to reduce any duplicate character data that exists. When the character data exceeds 255, the export data saves will not work properly since the data has breached the limits of low byte data bytes between 0 through 255.

Below is a screenshot of the Tools menu.

Finally here is a complete overview of what each particular subroutine does in the CharPad map scrolling project.

Project Breakdown Disassembly

Main.asm

Lines:
93-151: Setup bank memory and character set pointers
157-166: Screen multicolors
172-172: Parameters to adjust scrolling

Map Position

183-185:
Draw the first map display on the screen when the program first starts up

204-207: Point to Screen 1

Main Loop

216-218:
Execute WaitFrame (manages timing), UpdateScroll(handles all the scrolling, PlayerStateIdle(Main loop where joystick controls the map)

=========================================================
Game_Interrupts.asm (Lines):

5-54:InitRasterIRQ
Turns off the interrupts and sets a raster line for the first interrupt

63-114:IrqTopScreen
First Interrupt (controls the screen backbuffer switching and initializes the horizonal/vertical scroll settings, and calls the joystick.

124-162:IrqGlitchCatcher
Creates Score screen (at bottom)

168-197: IrqScoreBoard
Manages the scrolling bits

=========================================================
Game_Macros.asm

Essentially manages loading/copying of zeropage pointers

=========================================================

Game_Routines.asm

WaitFrame (Lines):

10-19: Manage the raster timing for the project

30-66: Joystick control and data saves exist here

CopyChars (Lines):

86-116: Used to copy character set to memory

==========================================================

Player_Routines.asm

JoystickReady: Lines:

16-33
Manages flags to control if the screen scrolls or not

MovePlayerRight
43-71: Controls the screen movement to the right

MovePlayerLeft
79-104: Controls the screen movement to the left

MovePlayerDown:
113-124: Controls the screen movement down

MovePlayerUp:
133-143: Controls the screen movement up

PlayerStateIdle
152-206: Main entry for the joystick control (main loop)

PlayerStateWalkRight
215-240: Joystick scrolls screen to the right

PlayerStateWalkLeft
249-270: Joystick scrolls screen to the left

PlayerStateWalkUp
277-286: Joystick scrolls screen up

PlayerStateWalkDown
294-304: Joystick scrolls screen down

========================================================
Screen_Memory.asm

SwapScreens

12-24: Pointer to the current screen (main or backbuffer)

GetScreenLineAddress:
49-51: Screen selector that can point to (main scree, backbuffer or score screen)

FetchBufferLineAddress:
53-81
Read the address in memory for the screen (used for collision detection and other things)

=========================================================
Scrolling.asm
32-129: Manages screen movement in all directions (right, left, up, down, and checks if the screen has stopped scrolling).

ScrollUp
141-192: All functions calls for Scrolling Up and tasks exist here.

ScrollDown
201-253: All function calls for Scrolling Down and tasks exist here

ScrollLeft
261-315: All function calls for Scrolling Left and tasks exist here

ScrollRight
324-378: All function calls for Scrolling Right and tasks exist here

ShiftCharsUp
386-544: Moves the pixels (characters) up on the screen

ShiftCharsDown
553-709: Moves the pixels (characters) down the screen

ShiftCharsLeft
720-857: Moves the pixels (characters) left on the screen

ColorShiftLeft
865-927: Moves the color ram data left on the screen

ShiftCharsRight
937-1078: Moves the pixels (characters) right on the screen

ColorShiftRight
1087-1150: Moves the color ram data right on the screen

ColorShiftUp
1157-1220: Moves the color ram data up on the screen

ColorShiftDown
1226-1290: Moves the color ram data down the screen

DrawUpBuffer
1298-1336: Draws the characters at the top of the screen

DrawDownBuffer
1351-1392: Draws the characters at the bottom of the screen

DrawUpColor
1400-1416: Draws the colors (in the VERTICAL_COLOR_BUFFER at the top of the screen)

DrawDownColor
1425-1444: Draws the colors (in the VERTICAL_COLOR_BUFFER) at the bottom of the screen

DrawLeftBuffer
1452-1548
Draws the horizontal buffer to the backbuffer (used for screen swapping)

DrawLeftColor
1554-1599: Draws the contents of the left buffer to the backbuffer (using the HORIZONTAL_COLOR_BUFFER)

DrawRightBuffer
1607-1703: Draws the the contents of the right buffer to the backbuffer (using the HORIZONTAL_BUFFER)

DrawRightColor
1709-1754: Draws the contents of the right colors to the backbuffer (using the HORIZONTAL_COLOR_BUFFER)

CopyVerticalBuffer
1766-1918: Copy data from the VERTICAL_BUFFER to the VERTICAL_COLOR_BUFFER)

CopyRightBuffer
1933-2031: Copy data from the HORIZONTAL_BUFFER and VERTICAL_BUFFER for edge drawing

CopyLeftBuffer
2064-2165: Copy data needed for the left buffer

========================================================
Start_Level.asm

LoadLevel
22-69: Reads the character set and map into pointers

DrawMap
90-138: Draws the map data to the screen

DrawTile
156-259: Places the 4×4 tiles on the screen

=======================================================
VIC_Registers.asm

All VIC registers and color data are found here

Feel free to use the form below if you get stuck on anything or having a question. We are here to help!