-
Notifications
You must be signed in to change notification settings - Fork 2
/
routines.asm
277 lines (242 loc) · 5.24 KB
/
routines.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#importonce
#import "board.asm"
*=* "Routines"
/*
Turn on and position all 8 sprites. We spread them out every 24 pixels and
place them on the first row. The multiplexer is responsible for moving them
to subsequent rows.
*/
SetupSprites:
stb #$ff:vic.SPENA
ldx #$00
stx counter
lda #PIECE_WIDTH
storex:
sta vic.SP0X,x
clc
adc #PIECE_WIDTH
inx
inx
cpx #$10
bne storex
rts
/*
Disable all sprites
*/
DisableSprites:
stb #$00:vic.SPENA
rts
/*
Turn on the custom characters
*/
SetupCharacters:
stb #$1d:vic.VMCSB
stb #$35:$01
rts
/*
Clear the screen
*/
ClearScreen:
ldx #$ff
lda #$20
clrloop:
sta $0400,x
sta $0500,x
sta $0600,x
sta $0700,x
dex
bne clrloop
rts
/*
Set up the chess board
*/
SetupScreen:
jsr ClearScreen
lda #$00
sta vic.BGCOL0
sta vic.EXTCOL
stb #$17:vic.VMCSB
ldx #$00
!loop:
lda Board,x
sta vic.CLRRAM,x
lda Board+$0100,x
sta vic.CLRRAM+$0100,x
lda Board+$0200,x
sta vic.CLRRAM+$0200,x
lda Board+$0300,x
sta vic.CLRRAM+$0300,x
lda #$e0
sta $0400,x
sta $0500,x
sta $0600,x
sta $0700,x
inx
bne !loop-
ldx #$00
ldy #$00
!loop:
stb Columns, y:$07c1, x
inx
inx
inx
iny
cpy #$09
bne !loop-
stb #'8':ScreenAddress(ScreenPos($18, $01))
stb #'7':ScreenAddress(ScreenPos($18, $04))
stb #'6':ScreenAddress(ScreenPos($18, $07))
stb #'5':ScreenAddress(ScreenPos($18, $0a))
stb #'4':ScreenAddress(ScreenPos($18, $0d))
stb #'3':ScreenAddress(ScreenPos($18, $10))
stb #'2':ScreenAddress(ScreenPos($18, $13))
stb #'1':ScreenAddress(ScreenPos($18, $16))
// Display the title
CopyMemory(TitleRow1Start, ScreenAddress(Title1Pos), TitleRow1End - TitleRow1Start)
CopyMemory(TitleRow1ColorStart, ColorAddress(Title1Pos), TitleRow1ColorEnd - TitleRow1ColorStart)
CopyMemory(TitleRow2Start, ScreenAddress(Title2Pos), TitleRow2End - TitleRow2Start)
CopyMemory(TitleRow2ColorStart, ColorAddress(Title2Pos), TitleRow2ColorEnd - TitleRow2ColorStart)
// Display the copyright
CopyMemory(CopyrightStart, ScreenAddress(CopyrightPos), CopyrightEnd - CopyrightStart)
FillMemory(ColorAddress(CopyrightPos), CopyrightEnd - CopyrightStart, WHITE)
jmp StartMenu
/*
Print out a byte as 2 digits. This assumes that the byte is stored as BCD
with the upper nybble containing the 10s value and the lower nybble containing
the 1s value. The digits are written to the location pointed at by printvector
*/
PrintByte:
tya
pha
lda num1
pha
and #$f0 // Get the upper nybble first
lsr
lsr
lsr
lsr
adc #$30
ldy #$00
sta (printvector),y
iny
pla
and #$0f // Get the lower nybble
adc #$30
sta (printvector),y
pla
tay
rts
/*
Display the "Thinking" message with an indeterminate progress bar. This is shown
when the computer is determining its best move.
*/
ShowThinking:
FillMemory(ScreenAddress(InteractionLinePos), $0e, $20)
CopyMemory(ThinkingStart, ScreenAddress(ThinkingPos), ThinkingEnd - ThinkingStart)
FillMemory(ColorAddress(ThinkingPos), ThinkingEnd - ThinkingStart, WHITE)
Enable(spinnerenabled)
Disable(showcursor)
rts
/*
Hide the "Thinking" message when the computer is ready to move
*/
HideThinking:
FillMemory(ColorAddress(ThinkingPos), ThinkingEnd - ThinkingStart, BLACK)
Disable(spinnerenabled)
rts
/*
Update the counts of captured pieces for the current player
*/
UpdateCaptureCounts:
StoreWord(printvector, ScreenAddress(CapturedCountStart))
ldy #$00
jeq currentplayer:#WHITES_TURN:!whitecaptured+
!blackcaptured:
StoreWord(capturedvector, blackcaptured)
jmp !print+
!whitecaptured:
StoreWord(capturedvector, whitecaptured)
!print:
stb (capturedvector), y:num1
jsr PrintByte
lda printvector
clc
adc #$28
sta printvector
iny
cpy #$05
bne !print-
rts
/*
Calculate the board offset for the movefrom coordinate
*/
ComputeMoveFromOffset:
lda movefrom + $01
mult8
clc
adc movefrom
sta movefromindex
rts
/*
Calculate the board offset for the moveto coordinate
*/
ComputeMoveToOffset:
lda moveto + $01
mult8
clc
adc moveto
sta movetoindex
rts
/*
Clear the error line
*/
ClearError:
FillMemory(ColorAddress(ErrorPos), $0e, BLACK)
rts
/*
Reset the input for whatever position is being displayed
*/
ResetInput:
ldy #$00 // Reset the cursor position
sty cursorxpos
lda #$20 // Put space characters in both coordinate locations
sta (inputlocationvector), y
iny
sta (inputlocationvector), y
rts
/*
Reset everything for the current player
*/
ResetPlayer:
lda #$00 // Clear out movefrom and moveto
sta movefrom
sta movefrom + $01
sta moveto
sta moveto + $01
lda #BIT8
sta movefromindex // Reset movefromindex and movetoindex
sta movetoindex
lda #$00
sta movetoisvalid
sta movefromisvalid
rts
/*
Swap the board and swap players. This is called after a player has
made a move.
*/
ChangePlayers:
lda currentplayer
eor #%00000001 // Swap the players
sta currentplayer
clf playclockrunning // Turn off the play clock while we swap
jsr UpdateCaptureCounts
jsr ResetPlayer
jsr UpdateCurrentPlayer
jne numplayers:#ONE_PLAYER:!twoplayers+
jsr ShowThinking
jmp !return+
!twoplayers:
jsr DisplayMoveFromPrompt
!return:
sef playclockrunning // Turn the play clock back on
rts