This is a small utility library for designing hi-res and multi-color bitmap
routines for the Commodore 64 on a DOS box (or "pee sea"). It simply
simulates access to screen/color/bitmap ram, the multi-color bit of $d016,
and the background color ($d021), while allowing you to use your favorite
high-level language (BASIC or C). I use this program while translating
programs from pseudocode to assembly, slowly changing portions of the program
to assemblyish (by using atomic instructions on variables named areg, xreg,
and yreg). This way, I can write and edit assemblyish code while being
able to use a VIC-II bitmap screen and the built-in debugging functions of
the IDE.
The file FONT.C64 should be included with this program as well, as it
includes the font data for the font routines. Everything will work fine
without it, but the BASIC version will leave a 0-byte FONT.C64 file in your
directory.
This software is free and public domain. Feel free to use it as is, change
the code to suit your program, or port it to another language (and go ahead
and distribute the ported version if you want to).
Main Subroutines:
- vicinit
Sets up the 320x200 VGA screen and a rough estimate of the 64's palette,
initializes scrn, bitmap, colr, backg, and mcm to standard 64 bootup
values, loads the fonts into memory, and sets up the squish array. Simply
change the "SCREEN 13" command to "SCREEN 12" in order to use 640x480
mode, if you want to display stuff onscreen without disturbing the 320x200
VicSim area. The aspect ratio will be a little skewed, though.
- gfxpoke memloc, byte
Stores 8 bits of byte into the bitmap array and updates the byte on the
screen. Standard calling method usually looks something like
"gfxpoke mem, bitmap(mem) OR bits".
- scrnpoke memloc, byte
Stores 8 bits of byte into the scrn array and updates the 8x8 block on the
screen.
- colrpoke memloc, byte
Stores 4 bits of byte into the colr array and updates the 8x8 block on the
screen.
- refresh
Redraws the entire screen. When many changes to the screen are made, it is
faster to store values straight into the bitmap/scrn/colr arrays and then
call this function, as opposed to using gfxpoke/scrnpoke/colrpoke for each
memory access.
Helper Functions and Subroutines:
- fontcopy upper, char, x, y
Copies a character from the 64's default font onto the specified character
block (0,0 to 39,24). Upper should be non-zero to read from the uppercase
font; zero will result in using the lowercase font. This uses gfxpoke, so
results are immediately onscreen.
- fontcopyl upper, char, x, y
- fontcopyr upper, char, x, y
Like fontcopy, but draws a squished version of the specified character
into either the left or right nybble. The other nybble is unharmed.
- charcopy a(), x, y
Copies the first eight bytes out of the specified array. x and y work as
in fontcopy. For the C version, send an unsigned char pointer (#defined
as "byte" in vicsim.h) for the character data.
- block(x, y)
Returns the memory location of the first byte in the 8x8 block specified.
x and y range from 0-39 and 0-24 respectively.
- byte(x, y)
Returns the memory location of the byte which contains the bit specified.
x and y range from 0-319 and 0-199 respectively.
- mbyte(x, y)
Works like the above routine, but for multicolor mode. x and y range from
0-159 and 0-199 respectively.
Cheater Subroutines: ;)
- set x, y
- clr x, y
Sets or clears a bit. Uses gfxpoke, so results appear immediately. x and
y range from 0-319 and 0-199 respectively.
- mset x, y, bits
Works like the above routine, but in multicolor, so x ranges from 0-159.
bits should be 0, 1, 2, or 3, regardless of the x position in the block.
Global variables:
- scrn(0 to 999)
- bitmap(0 to 7999)
- colr(0 to 999)
- backg
These are pretty self-explanatory. Remember to call refresh if you change
these directly.
- mcm
Set to non-zero for multi-color mode, zero for hi-res. Then call refresh.
- squish(0 to 255)
Given an 8-bit byte, this returns a graphically shrunk version of the
original byte in both nybbles. AND this with $f0 or $0f to get a 4-pixel
wide representation of the original, depending on which nybble you need to
access. Handy for displaying 8x8 fonts as 4x8 fonts.
- lfont(0 to 2047)
- ufont(0 to 2047)
These are where the fonts are located, in standard C64 format. Upon
startup, these are loaded from the file FONT.C64.