-
Notifications
You must be signed in to change notification settings - Fork 1
/
xstars.asm
185 lines (151 loc) · 3.07 KB
/
xstars.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
; (C) May 7, 2001 M. Feliks
include sys.inc
MAX_STARS equ 300
STAR struc
x dw ?
y dw ?
z dw ?
c db ?
clear_me dw ?
ends
.model tiny
.code
.386
org 100h
entrypoint:
call do_startup
mov si, offset stars_table
mov cx, MAX_STARS
is_loop:
push word ptr 160
push word ptr -160
call random
mov word ptr [si].x, ax
push word ptr -100
push word ptr 100
call random
mov word ptr [si].y, ax
push word ptr 100
push word ptr -100
call random
mov word ptr [si].z, ax
push word ptr 255
push word ptr 0
call random
mov byte ptr [si].c, al
add si, type STAR
dec cx
jnz is_loop
; initialize palette
mov dx, 03c8h
xor ax, ax
out dx, al
inc dx
mov cx, 256
ip_loop:
out dx, al
out dx, al
out dx, al
inc ah
mov al, ah
shr al, 2
dec cx
jnz ip_loop
call clear_buffer
main_loop:
push es
mov es, buffer_seg
mov si, offset stars_table
mov cx, MAX_STARS
smp_loop:
mov bx, word ptr [si].z
add bx, 256
mov ax, word ptr [si].x
shl ax, 8
cwd
idiv bx
add ax, 160
push ax
mov ax, word ptr [si].y
shl ax, 8
cwd
idiv bx
add ax, 100
pop bx
or bx, bx
jb smp_reinit
cmp bx, 318
ja smp_reinit
or ax, ax
jb smp_reinit
cmp ax, 198
ja smp_reinit
mov di, ax
shl di, 6
shl ax, 8
add ax, di
add ax, bx
mov di, ax
mov word ptr [si.clear_me], ax
dec word ptr [si].z
mov al, byte ptr [si].c
mov ah, al
stosw
add di, 318
stosw
cmp al, 255
jae smp_new_color
inc al
smp_new_color:
mov byte ptr [si].c, al
jmp smp_next
smp_reinit:
push word ptr 100
push word ptr -100
call random
mov word ptr [si].z, ax
mov byte ptr [si].c, 0
smp_next:
add si, type STAR
dec cx
jnz smp_loop
pop es
call timer_wait
call copy_buffer
push es
mov es, word ptr [buffer_seg]
mov si, offset stars_table
mov cx, MAX_STARS
xor ax, ax
erase_stars:
mov di, word ptr [si.clear_me]
stosw
add di, 320 - 2
stosw
add si, type STAR
loop erase_stars
pop es
mov ah, 6h
mov dl, 0ffh
int 21h
jz main_loop
call do_shutdown
random proc ; +4 min, +6 max
push bp
mov bp, sp
mov bx, random_seed
add bx, 9248h
ror bx, 3
mov random_seed, bx
mov ax, word ptr [bp+6]
sub ax, word ptr [bp+4]
mul bx
mov ax, dx
add ax, word ptr [bp+4] ; ax - random number
pop bp
ret 4
endp
.data?
stars_table STAR MAX_STARS dup(?)
random_seed dw ?
end entrypoint