Improved graphics

- Added multicolor graphic mode with custom charset, for text and tiles
- Added some debug options in Makefile

NOTE: code is functioning and correct, but really needs a big cleanup a
logical reorganization!
This commit is contained in:
giomba 2018-09-10 15:41:12 +02:00
parent 0932566285
commit 70b041cf14
5 changed files with 199 additions and 20 deletions

4
.gitignore vendored
View File

@ -1 +1,3 @@
snake.prg *.prg
*.out
symbols.txt

View File

@ -1,5 +1,8 @@
64: 64:
dasm snake.asm -DSYSTEM=64 -osnake.prg dasm snake.asm -DSYSTEM=64 -DDEBUG=0 -osnake.prg
debug:
dasm snake.asm -DSYSTEM=64 -DDEBUG=1 -ssymbols.txt -osnake.prg
16: 16:
dasm snake.asm -DSYSTEM=16 -osnake.prg dasm snake.asm -DSYSTEM=16 -osnake.prg

148
multicolor.asm Normal file
View File

@ -0,0 +1,148 @@
processor 6502
multicolor SUBROUTINE
; Prepare data struct for MultiColor mode
; ----------------------------------------------------------------------
multicolorInit:
; Deactivate interrupt
; This is needed to avoid calls from I/O while dealing with bank
; switching (I/O addresses are the same)
sei
; Put char ROM in CPU address space
; It becomes visible at $d000
; This overrides I/O
; lda $1
; and #$fb
; sta $1
; Copy ROM original content from $d000 to $3800
; ldx #0
;.copyLoop:
; lda $d000,x
; sta $3800,x
; lda $d100,x
; sta $3900,x
; lda $d200,x
; sta $3a00,x
; lda $d300,x
; sta $3b00,x
; lda $d400,x
; sta $3c00,x
; lda $d500,x
; sta $3d00,x
; lda $d600,x
; sta $3e00,x
; lda $d700,x
; sta $3f00,x
; inx
; bne .copyLoop
; Copy The GGS Font and
; make higher half the inverse of lower one
ldx #$00
.tggsCopy
dex
lda .tggsFont,x
sta $3800,x
eor #$ff
sta $3c00,x
lda .tggsFont + $100,x
sta $3900,x
eor #$ff
sta $3d00,x
lda .tggsFont + $200,x
sta $3a00,x
eor #$ff
sta $3e00,x
lda .tggsFont + $300,x
sta $3b00,x
eor #$ff
sta $3f00,x
cpx #$0
bne .tggsCopy
; Edit character definitions in RAM (using previous defined table)
ldx #$8
.editLoop:
dex
lda .multicolorSnakeTile,x
sta $3800 + SNAKE_TILE * 8,x
lda .multicolorFoodTile,x
sta $3800 + FOOD_TILE * 8,x
; lda .multicolorOtherTile,x
; sta $3800 + SOME_TILE * 8,x
; ...
cpx #$0
bne .editLoop
; Put ROM away from CPU address space, and re-enable I/O
; lda $1
; ora #$4
; sta $1
; Set foreground color in [8-F] to all locations to enable multicolor mode for every single char
; ldx #0
; lda #$d
;colorLoop:
; sta $d800,x
; sta $d900,x
; sta $da00,x
; sta $db00,x
; inx
; bne colorLoop
; Tell VIC-II to read characters from $3800 = 0xe * 0x400
lda $d018
ora #$0e
sta $d018
; Re-enable interrupts and return
cli
rts
; Activate multicolor mode
; ----------------------------------------------------------------------
multicolorOn:
; Set colors
lda #9
sta $d021 ; 00 is brown
lda #2
sta $d022 ; 01 is red
lda #13
sta $d023 ; 10 is green
; and of course
; 11 is the colour specified in color RAM
lda $d016
ora #$10
sta $d016
rts
; Deactivate multicolor mode
; ----------------------------------------------------------------------
multicolorOff:
lda $d016
and #$ef
sta $d016
rts
; Costants
; ----------------------------------------------------------------------
.multicolorCommodoreTile:
BYTE #$00,#$30,#$cc,#$ca,#$c0,#$c5,#$cc,#$30
.multicolorSnakeTile:
BYTE #$00,#$28,#$ab,#$ab,#$ab,#$ab,#$28,#$00
.multicolorFoodTile:
BYTE #%00010101
BYTE #%10010101
BYTE #%10010101
BYTE #%10010101
BYTE #%10101000
BYTE #%00100000
BYTE #%00100000
BYTE #%10000000
.tggsFont
INCBIN "tggs.font"

View File

@ -103,10 +103,10 @@ SCREEN_W = 40
SCREEN_H = 24 SCREEN_H = 24
; Snake features ; Snake features
SNAKE_TILE = 81 SNAKE_TILE = 81
SNAKE_COLOR = 5 SNAKE_COLOR = 13
; Food features ; Food features
FOOD_TILE = 90 FOOD_TILE = 90
FOOD_COLOR = 15 FOOD_COLOR = 11
; Strings ; Strings
gameoverString: gameoverString:
@ -128,10 +128,19 @@ intro2string:
intro3string: intro3string:
BYTE "(C) 2018" BYTE "(C) 2018"
BYTE #0 BYTE #0
colorshade: ; a shade from dark-gray to bright yellow, and vice-versa (40 columns) colorshade: ; a gradient of dark-bright-dark, with only hi-res colors (40 columns)
BYTE #11,#11,#11,#11,#11,#12,#12,#12,#12,#12,#5,#5,#5 BYTE #5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5,#5
BYTE #13,#13,#13,#13,#7,#7,#7,#7,#7,#7 ; BYTE #6,#6,#6
BYTE #13,#13,#13,#13,#5,#5,#5,#12,#12,#12,#12,#12,#11,#11,#11,#11,#11 ; BYTE #2,#2,#2,#2
; BYTE #5,#5,#5,#5
; BYTE #7,#7,#7,#7
; BYTE #3,#3,#3,#3
; BYTE #1,#1,#1,#1
; BYTE #3,#3,#3,#3
; BYTE #7,#7,#7,#7
; BYTE #5,#5,#5,#5
; BYTE #2,#2,#2,#2
; BYTE #6,#6,#6
scoreString: scoreString:
BYTE "POINTS" BYTE "POINTS"
BYTE #0 BYTE #0
@ -184,6 +193,9 @@ start:
lda #0 lda #0
jsr sidtune jsr sidtune
; Initialize MultiColor mode
jsr multicolorInit
; Set status as first-time intro playing ; Set status as first-time intro playing
lda #ST_INTRO0 lda #ST_INTRO0
sta status sta status
@ -224,6 +236,9 @@ endless:
; Full game reset ; Full game reset
; ---------------------------------------------------------------------- ; ----------------------------------------------------------------------
fullreset: fullreset:
; Turn MultiColor mode on
jsr multicolorOn
; Clear screen ; Clear screen
ldx #$ff ldx #$ff
lda #$20 lda #$20
@ -236,11 +251,9 @@ fullresetCLS:
cpx #$ff cpx #$ff
bne fullresetCLS bne fullresetCLS
; Set screen colors ; Set overscan
lda #12 lda #11
sta $d020 ; overscan sta $d020
lda #9
sta $d021 ; center
; Upper bar -- fill with reversed spaces, color yellow ; Upper bar -- fill with reversed spaces, color yellow
ldx #39 ldx #39
upperbarLoop: upperbarLoop:
@ -280,6 +293,8 @@ upperbarLoop:
; Intro reset ; Intro reset
; ---------------------------------------------------------------------- ; ----------------------------------------------------------------------
introreset: introreset:
jsr multicolorOff
; Clear screen ; Clear screen
ldx #$ff ldx #$ff
lda #$20 lda #$20
@ -292,9 +307,7 @@ introresetCLS:
cpx #$ff cpx #$ff
bne introresetCLS bne introresetCLS
; Copy shade colors from costant table to color RAM for 2nd and 4th ; Copy shade colors from costant table to color RAM for 2nd and 4th line of text
; line of text. Soon there will be some text bouncing on these
; lines
ldx #39 ldx #39
introresetColorShade introresetColorShade
lda colorshade,x lda colorshade,x
@ -307,7 +320,6 @@ introresetColorShade
; Set screen colors ; Set screen colors
lda #0 lda #0
sta $d020 ; overscan sta $d020 ; overscan
lda #0
sta $d021 ; center sta $d021 ; center
; Print website ; Print website
@ -349,6 +361,12 @@ irq:
tya tya
pha pha
#if DEBUG = 1
; Change background to visually see the ISR timing
lda #2
sta $d020
#endif
; Check status and call appropriate sub-routine ; Check status and call appropriate sub-routine
; Sort of switch-case ; Sort of switch-case
lda status lda status
@ -377,9 +395,13 @@ checkEndStatus:
jsr sidtune + 3 jsr sidtune + 3
; Increase random value ; Increase random value
ldx random inc random
inx
stx random #if DEBUG = 1
; Change background back again to visally see ISR timing
lda #11
sta $d020
#endif
; Restore registers from stack ; Restore registers from stack
pla pla
@ -949,6 +971,10 @@ printIntroEndCheck:
printIntroEnd: printIntroEnd:
rts rts
; Include
; ______________________________________________________________________
INCLUDE "multicolor.asm"
; ;
; coded during december 2017 ; coded during december 2017
; by giomba -- giomba at glgprograms.it ; by giomba -- giomba at glgprograms.it

BIN
tggs.font Normal file

Binary file not shown.