What I'm trying to do is to follow advice I've found on the net by setting the screen to 22 columns by 11 double height characters, thereby in effect creating a 176x176 pixel bitmap (88x176 if I decide to use multicolor). Every screen position corresponds statically to one character; all screen movement is performed by writing to character memory, not to screen memory.
The problem with my code is that when I try to change the appearance of one character, changes also appear in other parts of the screen, with lines of pixels flickering on and off. If anyone can take the time to look through the code below and tell me what I'm doing wrong, I'd be very grateful. The code is in Power Assembler format, since I use my C128 for cross developing.
Code: Select all
;...---==Space Pig Duel VIC-20==---...
;For 16K expanded VIC. 3K must also be
;present at RAM1-RAM3 ($0400-$0fff).
;Screen is at $0400-$04ff
;Custom characters at $1000
;BASIC starts at $1200. $1200-$13ff can
;be used for a short BASIC program to
;start the main program.
;$0500-$0fff can be used for constants,
;variables, etc.
;Zero page variables
temp1 = $f0
temp2 = $f1
temp3 = $f2
temp4 = $f3
;Constants
screen = $0400
characters = $1000
alt'characters = $0800 ;Use the 2K from $0800 to $0fff to store
;alternative character set (for title screen)
;Variables
player'x'pos = $0500 ;$0500-$07ff can be used for variables
opponent'x'pos = $0504 ;and other data.
player'laser'x'pos = $0508
opponent'laser'x'pos = $050c
player'y'pos = $0501
opponent'y'pos = $0505
player'laser'y'pos = $0509
opponent'laser'y'pos = $050d
player'old'x'pos = $0502
opponent'old'x'pos = $0506
player'laser'old'x'pos = $050a
opponent'laser'old'x'pos = $050e
player'old'y'pos = $0503
opponent'old'y'pos = $0507
player'laser'old'y'pos = $050b
opponent'laser'old'y'pos = $050f
.org $2400
init = *
lda #$00 ;Clear character memory
ldy #$00
- sta characters,y
sta characters+$100,y
sta characters+$200,y
sta characters+$300,y
sta characters+$400,y
sta characters+$500,y
sta characters+$600,y
sta characters+$700,y
sta characters+$800,y
sta characters+$900,y
sta characters+$a00,y
sta characters+$b00,y
sta characters+$c00,y
sta characters+$d00,y
sta characters+$e00,y
sta characters+$f00,y
iny
bne -
lda #$16 ;22 columns
sta $9002
lda #$17 ;11 rows, 16 pixel characters
sta $9003
lda #$9c ;Chars at $1000, screen at $0400
sta $9005
lda #$08 ;Black screen, black border
sta $900f
ldy #$00
lda #$01 ;White characters
- sta $9500,y
sta $9400,y
iny
bne -
;--------------------
;Code to see if this works. Won't be in the game
ldy #$00 ;Fill the screen with characters $00-$FF
- tya
sta screen,y
iny
bne -
lda #$ff ;Make the first row of character $00 white
ldy #$00
sta characters,y
;--------------------
game'loop = *
jsr screen'wait
jsr check'death
jsr random'gen
jsr power'bars
jsr draw'obstacles
jsr obst'explosion1
jsr obst'explosion2
jsr get'joystick
jsr joystick
jsr random'move1
jsr opponent'vertical
jsr opponent'fire
jsr player'laser'move
jsr opponent'laser'move
jsr opponent'collision
jsr player'collision
jsr object'player'col
jsr object'opponent'col
jsr raster'wait
jsr draw'screen
jmp game'loop
screen'wait = *
rts
check'death = *
rts
random'gen = *
rts
power'bars = *
rts
draw'obstacles = *
rts
obst'explosion1 = *
rts
obst'explosion2 = *
rts
get'joystick = *
rts
joystick = *
rts
random'move1 = *
rts
opponent'vertical = *
rts
opponent'fire = *
rts
player'laser'move = *
rts
opponent'laser'move = *
rts
opponent'collision = *
rts
player'collision = *
rts
object'player'col = *
rts
object'opponent'col = *
rts
raster'wait = *
- lda #$00 ;Wait for the raster beam to reach the top
cmp $9004 ;of the screen to prevent flicker
bne -
rts
draw'screen = *
rts
;----------------
;Tables 'n stuff
bitmap'table'lo = *
.byt$ 00, b0, 60, 10, c0, 70, 20, d0, 80
.byt$ 30, e0, 90, 40, f0, a0, 50, 00, b0
.byt$ 60, 10, c0, 70
bitmap'table'hi = *
.byt$ 14, 14, 15, 16, 16, 17, 18, 18, 19
.byt$ 1a, 1a, 1b, 1c, 1c, 1d, 1e, 1f, 1f
.byt$ 20, 21, 21, 22
line'values'tbl = *
.byte 0, 11, 22, 33, 44, 55, 66, 77, 88
.byte 99, 110, 121, 132, 143, 154, 165
.byte 176, 187, 198, 209, 220, 231
line'values'tbl'end = *