-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathwkcn2.asm
216 lines (179 loc) · 2.61 KB
/
wkcn2.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
;Running Ball
;Jackie Wu (Wu Kan)
;14348134
;wkcn@live.cn
;totalDelay = outDelay * inDelay
org 100H
outDelay equ 38000
inDelay equ 1100
;80 x 25
SCREEN_X equ 80
SCREEN_Y equ 25
;Ball in this Rect
MIN_X equ 0
MIN_Y equ 0
MAX_X equ 40
MAX_Y equ 13
;set data segment
;mov ax,07c0h
mov ax,cs
mov ds,ax
;text window
;25 * 80
mov ax,0B800h
mov es,ax
%macro SINGLE 4
;pos dw 0000h ;from 0,0
;vel dw 0101h ;v = (1,1)
;char db '*'
;color db 07H
mov ax, [%1]
mov [pos], ax
mov ax, [%2]
mov [vel], ax
mov al, [%3]
mov [char], al
mov al, [%4]
mov [color], al
call PLAY
mov ax, [pos]
mov [%1], ax
mov ax, [vel]
mov [%2], ax
mov ax, [char]
mov [%3], ax
mov ax, [color]
mov [%4], ax
%endmacro
START:
call DELAY
;call PLAY
SINGLE pos1,vel1,char1,color1
;SINGLE pos2,vel2,char2,color2
;SINGLE pos3,vel3,char3,color3
call SHOWNAME
jmp START
PLAY:
call SETPOINTER
;不清除
;call ELIMINATE
call UPDATEPOS
call SETPOINTER
call SHOW
ret
SHOWNAME:
mov cx,[msgLen]
mov si,message
mov di, (1*80 + 1) * 2
mov dl,[msgColor]
printChar:
mov al,[si]
inc si
and dl,0Fh
mov ah,dl
add dl,1
mov [es:di],ax
add di,2
loop printChar
inc byte[msgColor]
ret
DELAY:
mov cx, outDelay
LOOP1:
mov ax, inDelay
LOOP2:
dec ax
jg LOOP2
loop LOOP1
ret
UPDATEPOS:
;parameter: pos, vel
mov ax,[pos]
mov bx,[vel]
;update x
add ah,bh
cmp ah,MIN_X
ja XNZ
;if x <= MIN_X
mov bh,1
XNZ:
CMP ah,MAX_X-1
jb XNF
;if x >= MAX_X-1
mov bh,-1
XNF:
;update y
add al,bl
cmp al,MIN_Y
ja YNZ
;if y <= MIN_Y
mov bl,1
YNZ:
CMP al,MAX_Y-1
jb YNF
;if y >= MAX_Y-1
mov bl,-1
YNF:
mov [pos],ax
mov [vel],bx
;update color and char
mov al, [char]
inc al
cmp al,'Z'
jna LESSZ
mov al,'A'
LESSZ:
mov [char],al
inc byte[color]
ret
SETPOINTER:
;parameter pos, char
mov ax, 0
mov bx, [pos] ; bx = (x,y)
mov al, bl
mov cx, SCREEN_X
mul cx ; ax *= SCREEN_X namely ax = y * SCREEN_X
mov cx, 0
mov cl, bh
add ax, cx ; ax += x
mov cx, 2
mul cx
mov bx, ax
ret
SHOW:
;new
mov al, [char]
mov ah, [color]
and ah, 0Fh ; 去背景色
mov [es:bx],ax
ret
ELIMINATE:
;clean
mov ax, 0
mov [es:bx],ax
ret
DATA:
message db "WuKan's Program 2"
msgLen dw $-message
msgColor db 00h
outCount dw outDelay
inCount dw inDelay
pos dw 0000h ;from 0,0
vel dw 0101h ;v = (1,1)
char db '*'
color db 03H
;elements
pos1 dw 0000h
vel1 dw 0101h
char1 db 'A'
color1 db 03H ;green
pos2 dw 1003h
vel2 dw 01FFh
char2 db 'A'
color2 db 0CFH ;twinkle red and light white
pos3 dw 2019h
vel3 dw 0FFFFh
char3 db '@'
color3 db 0EH ;yello
times 510-($-$$) db 0
dw 0xaa55