c64-programmers_reference_guide-03-programming_graphics.pdf

(6872 KB) Pobierz
GRAPHICS OVERVIEW
All of the graphics abilities of the Commodore 64 come from the 6567
Video Interface Chip (also known as the VIC-II chip). This chip gives a
variety of graphics modes, including a 40 column by 25 line text display,
a 320 by 200 dot high resolution display, and SPRITES, small movable
objects which make writing games simple. And if this weren't enough,
many of the graphics modes can be mixed on the same screen. It is
possible, for example, to define the top half of the screen to be in high
resolution mode, while the bottom half is in text mode. And SPRITESwill
combine with anything! More on sprites later. First the other graphics
modes.
The VIC-II chip has the following graphics display modes:
A)
CHARACTER DISPLAYMODES
1) Standard Character Mode
a) ROM characters
b) RAM programmable characters
2) Multi-Color Character Mode
a) ROM characters
b) RAM programmable characters
3) Extended Background Color Mode
a) ROM characters
b) RAM programmable characters
B)
BIT MAP MODES
1) Standard Bit Map Mode
2) Multi-Color Bit Map Mode
C) SPRITES
1) Standard Sprites
2) Multi-Color Sprites
100
PROGRAMMING GRAPHICS
GRAPHICS LOCATIONS
Some general information first. There are 1000 possible locations on
the Commodore 64 screen. Normally, the screen starts at location 1024
($0400 in HEXadecimal notation) and goes to location 2023. Each of
these locations is 8 bits wide. This means that it can hold any integer
number from 0 to 255. Connected with screen memory is a group of
1000 locations called COLOR MEMORY or COLOR RAM. These start at
location 55296 ($D800 in HEX) and go up to 56295. Each of the color
RAM locations is 4 bits wide, which means that it can hold any integer
number from 0 to 15. Since there are 16 possible colors that the Com-
modore 64 can use, this works out well.
In addition, there are 256 different characters that can be displayed
at any time. For normal screen display, each of the 1000 locations in
screen memory contains a code number which tells the VIC-II chip which
character to display at that screen location.
The various graphics modes are selected by the 47 CONTROL regis-
ters in the VIC-II chip. Many of the graphics functions can be controlled
by POKEing the correct value into one of the registers. The VIC-II dhip is
located starting at 53248 ($DOOO HEX)through 53294 ($D02E in HEX).
in
VIDEO BANK SELECTION
The VIC-II chip can access ("see") 16K of memory at a time. Since
there is 64K of memory in the Commodore 64, you want to be able to
have the VIC-II chip see all of it. There is a way. There are 4 possible
BANKS (or sections) of 16K of memory. All that is needed is some means
of controlling which 16K bank the VIC-II chip looks at. In that way, the
chip can "see" the entire 64K of memory. The BANK
SELECT
bits that
allow you access to all the different sections of memory are located in
the 6526 COMPLEX INTERFACEADAPTERCHIP #2 (CIA #2). The POKE
and PEEK BASIC statements (or their machine language versions) are
used to select a bank by controlling bits 0 and 1 of PORT A of CIA#2
(location 56576 (or $DDOOHEX». These 2 bits must be set to outputs by
setting bits 0 and 1 of location 56578 ($DD02.HEX) to change banks. The
following example shows this:
POKE 56578,PEEK(56578)OR 3 :REM MAKE SURE BITS 0 AND 1 ARE
SET TO OUTPUTS
POKE 56576,(PEEK(56576)AND 252)OR A:REM CHANGE BANKS
"A" should have one of the following values:
PROGRAMMING GRAPHICS
101
VALUE
OF A
0
1
2
3
BITS
BANK
STARTING
LOCATION
49152
32768
16384
0
VIC-II CHIP
RANGE
($COOO-$FFFF)*
($8000-$BFFF)
($4000- $7FFF)*
($0000-$3FFF)
(DEFAULT VALUE)
00
01
10
11
3
2
1
0
This 16K bank concept is part
of
everything
You should always be aware
that the VIC-II chip does.
of which bank
the VIC-II
chip is pointing
at, since this will affect where character
data patterns
come from,
where the screen is, where sprites come from, etc. When you turn on the
power of your Commodore 64, bits 0 and 1 of location
56576 are
auto-
matically set to BANK 0
($0000-$3FFF)
for all display information.
.NOTE: The Commodore
1 and 3. (See character
64 character
set is not available
to the VIC-II chip in BANKS
memory section.)
SCREEN MEMORY
The
location
control register
to control
which
that part of the
screen memory.
used:
of screen
memory
can be changed
easily
by a POKE to
53272 ($DOI8 HEX). However, this register is also
used
character
set is used, so be careful to avoid disturbing
control register. The
UPPER 4
bits control the location of
To move the screen, the following statement
should be
POKE53272,(PEEK(53272)AND15)ORA
102
PROGRAMMING GRAPHICS
Where" A" has one of the following values:
LOCATION*
A
0
16
32
48
64
80
96
112
128
144
160
176
192
208
224
240
'Remember
BITS
OOOOXXXX
DECIMAL
0
1024
2048
3072
4096
5120
6144
7168
8192
9216
10240
11264
12288
13312
14336
15360
HEX
$0000
$0400
$0800
$OCOO
$1000
$1400
$1800
$lCOO
$2000
$2400
$2800
$2COO
$3000
$3400
$3800
$3COO.
0001 XXXX
0010XXXX
0011XXXX
0100XXXX
0101XXXX
0110XXXX
0111XXXX
1000XXXX
1001XXXX
1010XXXX
1011XXXX
1100XXXX
1101XXXX
1110XXXX
1111 XXXX
(DEFAULT)
that the BANK ADDRESS of the VIC-II chip must be added
= address/256,
e.g.,
1024/256=
in.
You must also tell the KERNAL'Sscreen editor where the screen is as follows: POKE
648, page (where page
4, so POKE 648,4).
COLOR MEMORY
Color memory can NOT move. It is always located at locations
55296
($D800)
through
56295 ($DBE7).
Screen memory (the
1000
locations
starting at 1024) and color memory are used differently in the different
graphics modes. A picture created in one mode will often look com-
pletely different when displayed in another graphics mode.
CHARACTER MEMORY
Exactly where the VIC-II gets it character information is important to
graphic programming. Normally, the chip gets the shapes of the char-
acters you want to be displayed from the
CHARACTERGENERATOR
ROM. In this chip are stored the
patterns
which make up the various
letters, numbers, punctuation symbols, and the other things that you see
PROGRAMMING GRAPHICS
103
Zgłoś jeśli naruszono regulamin