-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmain.asm
213 lines (164 loc) · 3.93 KB
/
main.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
------------------------------------
Tetris for 6502. (c) WdW 2015/16/17
------------------------------------
*/
#import "kernal.asm"
// get music data
.var music = LoadSid("audio.sid")
// game modes
.const MODE_ATTRACT = 1
.const MODE_SELECTLEVEL = 2
.const MODE_PLAY = 3
.const MODE_GAMEOVER = 4
.const MODE_ENTERNAME = 5
// display debug info or not
.const DEBUG = true
:BasicUpstart2(START)
// ------------------------------------------------
.pc = $5000 "maincode"
// import game source files
.import source "sound.asm"
.import source "blocks.asm"
.import source "input.asm"
.import source "screens.asm"
.import source "lines.asm"
.import source "scores.asm"
.import source "random.asm"
.import source "play.asm"
.import source "hi-scores.asm"
.import source "attract.asm"
.import source "entername.asm"
.import source "gameover.asm"
.import source "levelselect.asm"
.import source "controlled_input.asm"
.import source "file_load.asm"
.import source "file_save.asm"
START:
// initial setup
// set the used video bank to bank 0 ($0000-$3fff)
// bits 0-1 control bank selection
lda $dd00 // get data port register A
ora #$00000011 // select bank 0
sta $dd00 // and set register
// select the memory in bank 0 where our character set data resides
// in the selected video bank. this is controlled by bits 1-3
lda $d018 // get chip memory control register
// 1110 = 14, so 14*1024=14336 ($3800 in hex)
ora #%00001110 // use char set at $3800
sta $d018 // set register
jsr SetupRandom // set the rnd seed
jsr ClearScreen // clear the screen and set colors
jsr RESET_HISCORE_TABLE
// load the hiscores
jsr LOAD_FILE
// setup interrupt to play the sound
lda #SND_MUSIC_TITLE
jsr music.init
jsr SETUP_MUSIC_IRQ
// initial setup done
// select mode and call mode entry routine
lda #MODE_ATTRACT
sta gameMode
jsr StartAttractMode
// --------------------------------------------------
loopstart:
lda $d012 // get raster line position
cmp #208 // wait for bottom of play area
bne loopstart
.if (DEBUG) {
lda LIGHT_GREY
sta $d020
}
jsr GetInput
jsr COLOR_CHANGES
!checkMode:
// determine game mode and update accordingly
lda gameMode
cmp #MODE_ATTRACT
bne !nextmode+
jsr UpdateAttractMode
jmp loopend
!nextmode:
cmp #MODE_SELECTLEVEL
bne !nextmode+
jsr UpdateLevelSelectMode
jmp loopend
!nextmode:
cmp #MODE_PLAY
bne !nextmode+
jsr UpdatePlayMode
jmp loopend
!nextmode:
cmp #MODE_GAMEOVER
bne !nextmode+
jsr UpdateGameOverMode
jmp loopend
!nextmode:
cmp #MODE_ENTERNAME
bne loopend
jsr UpdateEnterNameMode
loopend:
.if (DEBUG) {
lda screenColor
sta $d020
}
jmp loopstart
// ------------------------------------------
COLOR_CHANGES:
lda inputResult
cmp #NOINPUT
beq !exit+
cmp #CHANGEBACKGROUND
bne !skip+
inc screenColor
lda screenColor
sta $d020
sta $d021
rts
!skip:
cmp #CHANGECOLOUR
bne !exit+
dec charColor
bpl !skip+
lda #15
sta charColor
!skip:
jsr SET_CHAR_COLOR
!exit:
rts
// ------------------------------------------
screenColor:
.byte DARK_GRAY
charColor:
.byte LIGHT_GREEN
gameMode:
.byte 0
pauseFlag:
.byte 0 // value is 1 when game is paused
// ------------------------------------------
// import the game screen data files
// it is pure data, so no need to skip meta data
// from char pad while importing
.pc = $4000 "screen data"
playscreen:
.import binary "tetris_playscreen.raw"
gameoverText:
.import binary "tetris_gameover.raw"
pauseText:
.import binary "tetris_paused.raw"
titleScreenData:
.import binary "tetris_titlescreen.bin"
keysScreenData:
.import binary "tetris_keys.raw"
creditsScreenData:
.import binary "tetris_credits.bin"
selectScreenData:
.import binary "tetris_select_and_high.raw"
// character set
.pc = $3800 "character set"
.import binary "tetris_chars2.raw"
// fill memory with music data
// music.location = $1000
.pc = music.location "Music"
.fill music.size, music.getData(i)