-
Notifications
You must be signed in to change notification settings - Fork 22
/
draw.asm
142 lines (128 loc) · 2.35 KB
/
draw.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
ScrBase: DW 0
PlayerTile: INCBIN "player.dat"
Tiles: INCBIN "wall.dat"
INCBIN "target.dat"
INCBIN "box.dat"
BOX_TILE EQU 2
DrawBoard: PUSHA
MOV SI, 0 ; index into board
MOV CH, 0 ; row
MOV WORD [ScrBase], 0
.drawRow: MOV CL, 0 ; col
.rowLoop: MOV AL, [Board + SI] ; get tile
CMP AL, 0 ; is tile 0?
JZ .nextTile
DEC AL
.drawTile: CALL DrawTile
.nextTile: ADD WORD [ScrBase], 16
INC SI
INC CL
CMP CL, BOARD_WIDTH
JNZ .rowLoop
ADD WORD [ScrBase], 320 * 16 - 16 * BOARD_WIDTH
INC CH
CMP CH, BOARD_HEIGHT
JNZ .drawRow
POPA
RET
DrawBoxes: PUSH CX
PUSH SI
MOV CX, [BoxCnt]
MOV SI, 0
.boxLoop MOV AX, [Boxes + SI]
CALL DrawBox
ADD SI, 2
DEC CX
JNZ .boxLoop
POP CX
POP SI
RET
EraseBoxes: PUSH CX
PUSH SI
MOV CX, [BoxCnt]
MOV SI, 0
.boxLoop MOV AX, [Boxes + SI]
CALL EraseBox
ADD SI, 2
DEC CX
JNZ .boxLoop
POP CX
POP SI
RET
; AL contains box row, AH contains box col
DrawBox: CALL SetScrBase
MOV AL, BOX_TILE
JMP DrawTile
EraseBox: CALL SetScrBase
JMP EraseTile
; AL contains row, AH contains col
SetScrBase: PUSH BX
SHL AH, 4 ; offset = col * 16
MOV BL, AH ; backup col offset
XOR BH, BH
MOV AH, 10 ; offset = row * 10
MUL AH
SHL AX, 9 ; offset *= 32 * 16
ADD AX, BX ; add col offset
MOV [ScrBase], AX
POP BX
RET
; AL = Tile #
DrawTile: PUSH SI
PUSH DI
SHL AX, 8 ; get tile index
ADD AX, Tiles ; get pointer
MOV SI, AX
MOV DI, [ScrBase]
CALL BlitTile
POP DI
POP SI
RET
EraseTile: PUSH DI
PUSH CX
PUSH DX
MOV DI, [ScrBase]
XOR AX, AX ; clear AX
CLD ; increment
MOV CH, 0 ; clear hi-counter
MOV DL, 0x10 ; 16 rows
.row: MOV CL, 0x08 ; 8 word writes
REP STOSW ; write 0000
DEC DL ; next row?
JZ .done
ADD DI, 304 ; next row
JMP .row
.done: POP DX
POP CX
POP DI
RET
ErasePlayer: MOV AX, [PlayerScrBase]
MOV [ScrBase], AX
MOV AL, [UnderTile]
AND AL, AL
JZ EraseTile
DEC AL
JMP DrawTile
DrawPlayer: PUSH SI
PUSH DI
MOV SI, PlayerTile
MOV DI, [PlayerScrBase]
CALL BlitTile
POP DI
POP SI
RET
; SI = Tile*, DI = Dest*
BlitTile: PUSH CX
PUSH DX
CLD ; increment
MOV CH, 0 ; clear hi-counter
MOV DL, 0x10 ; 16 rows
.row: MOV CL, 0x08 ; 8 word copies
REP MOVSW
DEC DL
JZ .done
ADD DI, 304 ; move to next row
JMP .row
.done: POP DX
POP CX
RET