-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWORM247.ASM
175 lines (149 loc) · 3.92 KB
/
WORM247.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
MAX_DIR equ 16
FP equ 6 ; Fixed Point constants
FP1 equ 64 ; Fixed Point constants ( FP1 == 1 << FP )
KEY_LEFT equ 1 ; ah
KEY_RIGHT equ 2 ; ah
KEY_THRUST equ 1 ; al
KEY_QUIT equ 32 ; ah
LEN_START equ 20
LEN_SIDE equ 32
LEN_BOT equ 23
LEN_LOOK equ 23
N_POINT equ 3
COL equ 15
BLIT_BUFFER equ 1
.MODEL TINY
HELLO SEGMENT ;Set up code and data section
ASSUME CS:HELLO,DS:HELLO ;Tell assembler about conditions at entry
ORG 100H ;A .COM program begins with 100H byte prefix
MAIN: ;Control must start here
.286
mov ax,0013h ; Videomode 13h 320*200*256
int 10h
Menu:
mov bx, 0A000h
mov es, bx
mov ax, score ; Print score
shr ax, 5
mov bh, 10
div bh
add ax, '0'*256+'0'
mov word ptr [score_str+6], ax
WLoop:
inc bp
inc cx
call DrawLine
mov dx, offset score_str
mov ah, 9
int 21h
mov ah, 1
int 16h
jz WLoop
mov ah, 0
int 16h
cmp al, 27
je TheEnd
mov ax,0013h ; Videomode 13h 320*200*256, clear screen
int 10h
; xor ax, ax
mov score, ax
mov di, 160*FP1+16 ; di = Ship X
mov si, 100*FP1 ; si = Ship Y
mov bp, di ; bp = Ship dir
;===========
MainLoop:
;===========
inc score
pusha ; Draw ship
mov ch, byte ptr [score+1]
inc ch
mov dl, LEN_START
call DrawLine
add bp, 7*4
mov dl, LEN_SIDE
call DrawLine
add bp, 5*4
mov dl, LEN_BOT
call DrawLine
add bp, 5*4
mov dl, LEN_SIDE
call DrawLine
popa
mov dx, 03DAh ; Wait vertical blank
LoopVbl:
in al, dx
test al, 8
je LoopVbl
mov ah, 012h ; Read keyboard
int 16h
test ah, KEY_RIGHT ; Turn right
jz KeyNotRight
dec bp ; ship_dir
KeyNotRight:
test ah, KEY_LEFT ; Turn left
jz KeyNotLeft
inc bp ; ship_dir
KeyNotLeft:
mov dl,1 ; Thrust, move ship forward
call SinCos
pusha
mov cx, LEN_LOOK
ColLoop: ; Check collision
mov dl, 1
call SinCos
loop ColLoop
call CalcPixel
test byte ptr es:[bx+di], 255
popa
jz MainLoop
jmp Menu
;
; Loppusiivoukset
;
TheEnd:
mov ax,0003 ; Back to textmode
int 10h
ret ;Return to system
;-------------------
DrawLine PROC NEAR
;-------------------
; di = x * FP1
; si = y * FP1
; ch = len
; cl = color
; bp = dir
DLLoop:
pusha
call CalcPixel
mov byte ptr es:[bx+di], ch ; put_pixel(di+(x>>FP), si+(y>>FP), cl)
popa
SinCos PROC NEAR
push bp
sar bp, 2
and bp, MAX_DIR-1
mov al, byte ptr [sint+bp] ; x += sint[dir]
cbw
add di, ax
mov al, byte ptr [sint+MAX_DIR/4+bp] ; y += cost[dir]
cbw
add si, ax
pop bp
dec dl
jnz DLLoop
ret
SinCos ENDP
DrawLine ENDP
CalcPixel PROC NEAR
sar si, FP
imul bx, si, 320
sar di, FP
ret
CalcPixel ENDP
sint db 0, 24, 45, 59, 64, 59, 45, 24
db 0,-23,-44,-58,-63,-58,-44,-23
db 0, 24, 45, 59
score_str db "Score " ; 00", 13, '$'
score dw 0
db 13, '$'
HELLO ENDS ;End of code and data section
END MAIN ;Terminate assembler and specify entry point