forked from aliaagheisX/Cheeese
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphics.asm
More file actions
603 lines (522 loc) · 21.7 KB
/
graphics.asm
File metadata and controls
603 lines (522 loc) · 21.7 KB
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
PUBLIC DrawBoard, DrawSquareBord,DrawSquareBordSm, MvePlayerFromGraphics
PUBLIC DrawHighlightedMvs, ClrHighlightedMvs, MvePieceToGraphics, MvePieceFromGraphics
PUBLIC DrawPlayers
PUBLIC killedPeicePos ,killedPeiceRow, killedPeiceCol
EXTRN color:BYTE
EXTRN board:BYTE
EXTRN Bpawn:BYTE
EXTRN validateMoves:BYTE
EXTRN highlightPeiceMvs:BYTE
EXTRN playerCells:BYTE
EXTRN playerCols:BYTE
EXTRN playerRows:BYTE
EXTRN highlightColor:BYTE
EXTRN PlayerPos:WORD
EXTRN PlayerSelectedPos:WORD
EXTRN PlayerSelectedCell:BYTE
EXTRN PlayerSelectedRow:BYTE
EXTRN PlayerGameNumber:WORD
.286
.MODEL SMALL
.data
;__________Messages________;
Knightkill db 'A Knight has been killed$'
Clearcheckmes db ' $'
Pawnnkill db 'A Pawn has been killed$'
Queenkill db 'A Queen has been killed$'
Kingkill db 'A King has been killed$'
Rookkill db 'A Rook has been killed$'
Bishopkill db 'A Bishop has been killed$'
varkilled db ?
;------- peices -----------;
emptyCell equ 0
pawn equ 1
rook equ 2
knight equ 3
bishop equ 4
queen equ 5
king equ 6
;-------- peice colors -----;
black equ 8
white equ 0
boardWidth equ 23
imageWidth equ 23
imageWidthSm equ 7
emptyCell equ 0
killedPeicePos dw 20664 ;23*8
killedPeiceRow db 0 ;23*8
killedPeiceCol db 0 ;23*8
.CODE
DrawGrid PROC FAR
pusha
mov si, 0
mov di, 0
mov cx, 8
;___ draw rank by rank ____;
lr: push cx
mov cx, boardWidth
;___ draw line by line ____;
lh: push cx
mov cx, 8
;___ draw square line ___;
lw:
push cx
mov al, color[si];color
mov cx, boardWidth ;width
REP STOSB ;draw a width of square
XOR si, 1 ;toggle color for next square
pop cx
loop lw
add di, 320-8*boardWidth
pop cx
loop lh
XOR si, 1 ;toggle color for next square
pop cx
loop lr
popa
RET
DrawGrid ENDP
DrawImg PROC FAR ;al = peice di = startPoint
cmp ax, emptyCell ;check if empty cell
jne DrawImglabel ;if not start drawing
RET ;else return
DrawImglabel: pusha
lea bx, Bpawn;bx = offset of first image in mem
mov dx, ax;dx=peice
and ax, 7;peice type
shl ax, 1;2*p
sub ax, 1;2*p-1
and dx, 8;peice color
shr dx, 3;peice color/8
sub ax, dx;(2*p-1)-pc/8
mov dx, boardWidth*boardWidth;23*23
mul dx;ax = ((2*p-1)-pc/8)*23*23
add bx, ax;bx = offset of image that should drawn
mov cx, imageWidth
;======= start loop row by row =======;
lp1: push cx
mov cx, imageWidth
;======= start loop col by col =======;
lp2: mov al, [bx]
cmp al, 4 ;skip if color is transparent = [4]
je skip
mov es:[di], al ;draw color of pixel
skip: inc di;update cursor
inc bx;update pixel of img
loop lp2
add di, 320-imageWidth;return to first col next row
pop cx
loop lp1
popa
RET
DrawImg ENDP
DrawSquareBordSm PROC FAR ;di = start position, al = highlight color
pusha
;=========== draw first row ==========;
add di, 320+1
mov cx, boardWidth-2
REP STOSB
;=========== draw columns ==========;
add di, 320-boardWidth+2 ;to return di to first col next row
mov cx, boardWidth-4 ;number of pixels of one column to draw
DWSQ3: STOSB ;draw pixel in first col
add di, boardWidth-4 ;update pos for nxt col
STOSB ;draw pixel in sec col
add di, 320-boardWidth+2 ;update di to first col next row
loop DWSQ3
;=========== draw last row ==========;
mov cx, boardWidth-2
REP STOSB
popa
RET
DrawSquareBordSm ENDP
DrawSquareBord PROC FAR ;di = start position, al = highlight color
pusha
;=========== draw first row ==========;
mov cx, boardWidth
REP STOSB
;=========== draw columns ==========;
add di, 320-boardWidth ;to return di to first col next row
mov cx, boardWidth-2 ;number of pixels of one column to draw
DWSQ1: STOSB ;draw pixel in first col
add di, boardWidth-2 ;update pos for nxt col
STOSB ;draw pixel in sec col
add di, 320-boardWidth ;update di to first col next row
loop DWSQ1
;=========== draw last row ==========;
mov cx, boardWidth
REP STOSB
popa
RET
DrawSquareBord ENDP
DrawPlayers PROC FAR
push ax
push di
push si
mov si, PlayerGameNumber
shl si, 1
mov di, PlayerPos[si]
mov al, 4
CALL DrawSquareBord
pop si
pop di
pop ax
RET
DrawPlayers ENDP
DrawBoard PROC FAR ;inialize first with all peices
CALL DrawGrid
pusha
mov ah,6 ; function 6
mov al,15 ; scroll by 1 line
mov bh,3h ; normal video attribute
mov ch,8 ; upper left row after you:
mov cl,23 ; upper left col
mov dh,22 ; lower right row
mov dl,39 ; lower right col
int 10h
popa
pusha
mov si, 0 ;initial cell
mov di, 0 ;initial position
mov cx, 2
;========= loop on pair rows =========;
DrawBoardLoop1: push cx
;========= loop on row in the pair of rows =========;
mov cx, 2
DrawBoardLoop2: push cx
mov cx, 8
;========= loop for all cells in row =========;
DrawBoardLoop3:
mov ah, 0
mov al, board[si]
CALL DrawImg
inc si ;to next cell
add di, boardWidth ;to next position in row
loop DrawBoardLoop3
add di, 320*boardWidth-boardWidth*8 ;for next row and return to next col
pop cx
loop DrawBoardLoop2
mov si, 48 ;cell of before last row, first col
mov di, boardWidth*320*6 ;position of before last row, first col
pop cx
loop DrawBoardLoop1
popa
CALL DrawPlayers
RET
DrawBoard ENDP
DrawSquare PROC FAR ;di = start position, al = highlight color
pusha
;=========== draw row by row ==========;
mov cx, boardWidth ;number of rows of one cell
DWSquareL: push cx ;store cx
mov cx, boardWidth ;width of one row
REP STOSB ;draw col
add di, 320-boardWidth ;update di to first col next row
pop cx
loop DWSquareL
popa
RET
DrawSquare ENDP
GetCellColor PROC FAR;bl=cell number, bh=row ===> al = color of cell
push bx
add bl, bh
and bl, 1
mov bh, 0
mov al, color[bx]
pop bx
RET
ENDP GetCellColor
MvePlayerFromGraphics PROC FAR;si=player number ====> al = color of cell player on, di = player pos
push bx
mov bl, playerCells[si] ;bl = playerCell
cmp validateMoves[bx], 1;chk if one of valid moves
jl clearSquare ;if not => clearSquare=> get color of cell
mov al, 0 ;else al = highligh move color
jmp startMvePlayerFrom ;and start draing
;=========== get color of cell that player stand on =====;
clearSquare: add bl, playerRows[si] ;bl= row + cell
and bl, 1 ;if odd => cell color index 1
mov bh, 0 ;if even=> cell color index 0
mov al, color[bx] ;load color
;=========== get color of cell that player stand on =====;
startMvePlayerFrom: pop bx
shl si, 1 ;2*si
mov di, PlayerPos[si]
CALL DrawSquareBord
shr si, 1 ;si/2
RET
MvePlayerFromGraphics ENDP
MvePieceFromGraphics PROC FAR ;si = playerNumber, bx=cell ===> al = cell color, di = pos **bl = cell
mov bl, PlayerSelectedCell[si];bl = cell
mov bh, PlayerSelectedRow[si] ;bh = row
shl si, 1 ;
mov di, PlayerSelectedPos[si] ;di = position
shr si, 1 ;
CALL GetCellColor ;al = cell color
CALL DrawSquare ;clear cell
RET
MvePieceFromGraphics ENDP ;si = playerNumber, bx=cell ===> al = cell color, di = pos **bl = cell
DisplayMessage Proc far ;bx --> input(to cell)
pusha
mov bh, 0;pg number
mov dh, 24;row
mov dl, 00
mov ah, 2
int 10h
; lea si , Kingkill
; mov si,0
;------------------Clearing status--------------------;
pusha
mov di,0
printclear:
mov al,Clearcheckmes[di]
mov ah, 09h
mov bh, 0
mov bl, 0fh
mov cx, 1
int 10h
inc dl
mov bh, 0;pg number
mov dh, 24;row
mov ah, 2
int 10h
inc di
cmp Clearcheckmes[di],'$'
jnz printclear
popa
;----------------------------------------------;
mov bh, 0;pg number
mov dh, 24;row
mov dl, 00
mov ah, 2
int 10h
mov cl,board[bx]
mov ch,00
and cl,00000111b
cmp cx,pawn
jnz crook
pusha
mov di,0
printP:
mov al,Pawnnkill[di]
mov ah, 09h
mov bh, 0
mov bl, 0fh
mov cx, 1
int 10h
inc dl
mov bh, 0;pg number
mov dh, 24;row
mov ah, 2
int 10h
inc di
cmp Pawnnkill[di],'$'
jnz printP
popa
jmp Ex
crook:
cmp cx,rook
jnz cKing
pusha
mov di,0
printRo:
mov al,Rookkill[di]
mov ah, 09h
mov bh, 0
mov bl, 0fh
mov cx, 1
int 10h
inc dl
mov bh, 0;pg number
mov dh, 24;row
mov ah, 2
int 10h
inc di
cmp Rookkill[di],'$'
jnz printRo
popa
jmp Ex
cKing:
cmp cx,king
jnz cKnight
pusha
mov di,0
printK:
mov al,Kingkill[di]
mov ah, 09h
mov bh, 0
mov bl, 0fh
mov cx, 1
int 10h
inc dl
mov bh, 0;pg number
mov dh, 24;row
mov ah, 2
int 10h
inc di
cmp Kingkill[di],'$'
jnz printK
popa
jmp Ex
cKnight:
cmp cx,knight
jnz cQueen
pusha
mov di,0
printKn:
mov al,Knightkill[di]
mov ah, 09h
mov bh, 0
mov bl, 0fh
mov cx, 1
int 10h
inc dl
mov bh, 0;pg number
mov dh, 24;row
mov ah, 2
int 10h
inc di
cmp Knightkill[di],'$'
jnz printKn
popa
jmp Ex
cQueen:
cmp cx,Queen
jnz cBishop
pusha
mov di,0
printQ:
mov al,Queenkill[di]
mov ah, 09h
mov bh, 0
mov bl, 0fh
mov cx, 1
int 10h
inc dl
mov bh, 0;pg number
mov dh, 24;row
mov ah, 2
int 10h
inc di
cmp Queenkill[di],'$'
jnz printQ
popa
jmp Ex
cBishop:
cmp cx,bishop
jnz Ex
pusha
mov di,0
printB:
mov al,Bishopkill[di]
mov ah, 09h
mov bh, 0
mov bl, 0fh
mov cx, 1
int 10h
inc dl
mov bh, 0;pg number
mov dh, 24;row
mov ah, 2
int 10h
inc di
cmp Bishopkill[di],'$'
jnz printB
popa
Ex:
popa
ret
DisplayMessage EndP
MvePieceToGraphics PROC FAR;si = playerNumber, al = peice =====> di = pos, bx = cell
shl si, 1 ;
mov di, PlayerPos[si] ;di = position
shr si, 1 ;
mov bh, 0
mov bl, playerCells[si] ;bx = bl = cell
cmp board[bx], emptyCell ;chk if empty
je stMvPc ;if empty skip clear part
;START clear square
pusha
mov al, board[bx]
mov di, killedPeicePos
CALL DrawImg ;di = position , al = peice
add killedPeicePos, 23
add killedPeiceCol, 1
cmp killedPeiceCol, 6
jne skpUpdateRow
mov killedPeiceCol, 0
add killedPeicePos, 320*23;to go down row of peices
sub killedPeicePos, 23*6;to return to first col
skpUpdateRow: popa
Call DisplayMessage
mov bh, playerRows[si] ;bh = row
push ax ;store al
CALL GetCellColor ;al = cell color
CALL DrawSquare ;clear cell
pop ax ;store al = peice
mov bh, 0 ;bx = cell
stMvPc: CALL DrawImg ;move peice graphically
RET
MvePieceToGraphics ENDP
DrawHighlightedMvs PROC FAR ;si = player number
pusha
mov bx, 0 ;cell
mov di, 0 ;position
;======== loop row by row ==========;
mov cx, 8 ;row
DrawHIGH1: push cx
mov cx, 8
;======== loop col by col ==========;
DrawHIGH2:
mov ah, 0
mov al, validateMoves[bx] ;al = valid move state of cell
cmp ax, si ;check that's one of player valid mvs
jne DontDrawMve ;if not skip
mov al, 0 ;al = highlightcolor
CALL DrawSquareBord ;Draw
DontDrawMve: inc bx ;update cell number
add di, boardWidth ;update position to nxt col
loop DrawHIGH2
add di, 320*boardWidth-boardWidth*8 ;update position to nxt row first col
pop cx
loop DrawHIGH1
popa
RET
DrawHighlightedMvs ENDP
ClrHighlightedMvs PROC FAR ;si = player number
pusha
mov bx, 0 ;cell
mov di, 0 ;position
mov dx, 0 ;color of cell
;======== loop row by row ==========;
mov cx, 8 ;row
ClrHIGH1: push cx
mov cx, 8
;======== loop col by col ==========;
ClrHIGH2:
mov ah, 0
mov al, validateMoves[bx] ;al = valid move state of cell
cmp ax, si ;check that's one of player valid mvs
jne DontClrMve ;if not skip
mov validateMoves[bx], 0 ;else Clear Cell by move zero and clear graphically
;== Clear Cell by Draw it's color on Border ==;
push bx ;store bx
mov bx, dx ;bx = index of cell color
mov al, color[bx] ;al = highlightcolor
CALL DrawSquareBord ;Draw
pop bx ;return bx
;== Clear Cell by Draw it's color on Border ==;
DontClrMve: inc bx ;update cell number
add di, boardWidth ;update position to nxt col
xor dx, 1 ;toggle cell color
loop ClrHIGH2
add di, 320*boardWidth-boardWidth*8 ;update position to nxt row first col
xor dx, 1 ;toggle cell color
pop cx
loop ClrHIGH1
;======== return player cells ======;
CALL DrawPlayers
popa
RET
ClrHighlightedMvs ENDP
END