-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootCheckers.asm
311 lines (264 loc) · 5.96 KB
/
bootCheckers.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
cpu 8086
; TODO: Kings
; TODO: Prevent Jumping your own pieces
; TODO: Validate Move
; TODO: Determine Winner
BOARD: equ 0x0300
Player1_PiecesLeft equ 0x0340
Player2_PiecesLeft equ 0x0341
MoveBuffer equ 0x0342 ; 7 bytes
org 0x7c00
; Code
Start:
mov di,0 ; Set Di=0 so game always starts Red turn
; mov bx,Player1_PiecesLeft
; mov byte [bx],12
; mov bx,Player2_PiecesLeft
; mov byte [bx],12
; Fill the board with blank spaces
mov cl,64
mov bx,BOARD
mov al,' '
ClearBoard:
mov [bx],al
inc bx
loop ClearBoard
; Setup Checker Pieces
mov bx,BOARD
mov dl,2
mov al,'B'
SetupPlayer:
mov cl,3
SetupRow:
push cx
mov cl,4
SetupSquare:
mov [bx],al
add bx,2
loop SetupSquare
pop cx
cmp cx,3
je AdjustSquare
cmp dx,2
je DecSquare
jmp IncSquare
AdjustSquare:
cmp dx,2
je IncSquare
DecSquare:
sub bx,2
IncSquare:
inc bx
loop SetupRow
add bx,18
mov al,'R'
dec dx
jne SetupPlayer
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Start Game Logic
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
StartTurn:
call clear_screen ; Clear the screen
DrawBoard:
mov bx,Title ; Print the title at the top of the board
call print_string
call newline ; Make some space between the title
call newline ; and the board
mov bx,BOARD ; Draw the board and pieces
mov al,'1'
mov cl,8
DrawBoardLoop:
call display_letter
push ax
mov al,' '
call display_letter
call drawRow
pop ax
inc ax
loop DrawBoardLoop
mov bx,ColIdx
call print_string
call newline
call newline
xor di,1
je BlackTurn
mov bx,RedMov
jmp RedTurn
BlackTurn:
mov bx,BlkMov
RedTurn:
call print_string ; End Drawing the board
ReadMove: ; Let the user type in the move to be
mov bx,MoveBuffer ; performed
ReadNextKey:
mov ah,0x00 ; Load AH with code for keyboard read
int 0x16 ; Call the BIOS for reading keyboard
cmp al,113
jne SkipReset
jmp Start
SkipReset:
cmp al,8
jne SkipBackSpace
cmp bx,MoveBuffer
je ReadNextKey
mov byte [bx],al
call display_letter
mov al,' '
call display_letter
mov al,8
call display_letter
dec bx
jmp ReadNextKey
SkipBackSpace:
cmp al,13
je EndRead
mov byte [bx],al
call display_letter
inc bx
jmp ReadNextKey
EndRead: ; End reading move
DoMove: ; Perform the move entered if it is a
xor bx,bx ; valid move
mov al,[MoveBuffer+2]
sub al,0x31
mov cl, 0x08
mul cx
mov bl,[MoveBuffer]
sub bl,0x31
add bl,al
add bx,BOARD
mov byte cl,[bx]
mov si,bx
;;
xor bx,bx
mov al,[MoveBuffer+6]
sub al,0x31
mov dl,0x08
mul dx
mov bl,[MoveBuffer+4]
sub bl,0x31
add bl,al
add bx,BOARD
xor di,1
jne SkipRedMove
cmp cl,'R'
jne StartTurn
jmp SkipBlackMove
SkipRedMove:
cmp cl,'B'
jne StartTurn
SkipBlackMove:
xor di,1
mov dx,[bx]
cmp dl,0x20
je ContinueTurn
xor di,1
jmp StartTurn
ContinueTurn:
mov byte [bx],cl
mov byte [si],' ' ; End performing move
CheckJump: ; See if a jump was performed
mov al,[MoveBuffer+6]
sub al,[MoveBuffer+2]
cmp al,1
je NoJumpPerformed
cmp al,-1
je NoJumpPerformed
mov cl,-1
cmp al, 2
jne VerticalJumpDirectionSet
mov cl,1
VerticalJumpDirectionSet:
mov al,[MoveBuffer+2]
sub al,0x31
add al,cl
mov cl, 0x08
mul cx
mov bl,al
;;
mov al,[MoveBuffer+4]
sub al,[MoveBuffer]
mov cl,-1
cmp al, 2
jne HorizontalJumpDirectionSet
mov cl,1
HorizontalJumpDirectionSet:
mov al,[MoveBuffer]
sub al,0x31
add al,cl
and bx,0x00FF
add bl,al
add bx,BOARD
mov byte [bx],' ' ; End Checking for a Junp
NoJumpPerformed:
jmp StartTurn ; Next turn
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Sub-Routines
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
drawRow:
push cx
mov cl,8
drawRowLoop:
call drawSquare
loop drawRowLoop
call newline
pop cx
ret
drawSquare:
mov al,[bx]
call display_letter
inc bx
mov al,' '
call display_letter
ret
display_letter:
push ax
push bx
mov ah,0x0e ; Load AH with code for terminal output
mov bx,0x000f ; Load BH page zero and BL color (graphic mode)
int 0x10 ; Call the BIOS for displaying one letter
pop bx
pop ax
ret
newline:
push ax
mov al,13
call display_letter
mov al,10
call display_letter
pop ax
ret
print_string:
push ax
push bx
print_string_loop:
mov al,[bx]
test al,al
je end
push bx
mov ah,0x0e ; Load AH with code for terminal output
mov bx,0x000f ; Load BH page zero and BL color (graphic mode)
int 0x10 ; Call the BIOS for displaying one letter
pop bx
inc bx
jmp print_string_loop
end:
pop bx
pop ax
ret
clear_screen:
push ax
mov ah, 0x00
mov al, 0x03 ; text mode 80x25 16 colours
int 0x10
pop ax
ret
; Data
Title: db " Checkers",0
ColIdx: db " 1 2 3 4 5 6 7 8",0
RedMov: db "Red Move?",0
BlkMov: db "Black Move?",0
times 510-($-$$) db 0x4f
db 0x55,0xaa