-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsonar.s
268 lines (200 loc) · 4.9 KB
/
sonar.s
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
; Sonar
;
; 256 bytes intro for ZX Spectrum by Tomasz Slanina ( dox/joker )
; 4th place ( 256b oldskool, Lovebyte 2k23)
;
; https://github.com/tslanina
COLOR_STANDARD equ 4 + 64
COLOR_MISSILE equ 2 + 64
org $f800
db 0, %00010000 ; a period
db 1, %00000001 ; a period (coarse)
.mixer:
db 7, %00111110 ; mixer
db 8, %00011111 ; amp a
db 12, %00111111 ; env period
db 13, 0 ; env shape (one shot)
start:
di ; +2a/+3 fix (mem clear affects system variables (bank))
ld ix,$5800+4 ; missile start pos
ld hl,$5800
.clrloop:
ld [hl],COLOR_STANDARD
inc hl
bit 7,h
jr z,.clrloop ; clear/fill
.restart:
xor a
out [254],a ; black border
ld sp,$8400+2 ; top of point buffer
ld d,a
ld e,a ; de = 0,0 = start point
.setdir:
ld a,1 ; generate table with point coords (x,y) in RAM
xor l
ld l,a
cpl
ld h,a ;hl = dx dy
ld a,r ; a little bit of pseudo random ... the 'formula' of point gen can be simplified/optmized/whatever .. but it works, so ;)
xor %1010
and %1111
inc a
ld b,a
.deloop:
dec b
jr z,.setdir
push de ; save coords
ld a,d
xor e
cpl
ld d,a
; -x, y
push de ; save coords
push hl ; dx dy on stack ( in the table in fact ...)
add hl,de
ex de,hl ; x+dx, y+dy ; move to next point
ld hl,0 ; check the sp
add hl,sp
bit 7,h ; stack below $8000 ; >$400/2 points generated, enough ;)
pop hl
jr nz,.deloop
ld h,$84 ; end of point table
ld b,h
.rotate:
push bc
push hl
ld a,b
and %11111
jr nz,.nopix
ld [ix],COLOR_STANDARD
ld bc,33 ; next line + next cell
add ix,bc
ld a,ixl
cp $6f ; center of screen = hit
jr nz,.notend
ld a,-15
ld [.nextmod+1],a ; end = no loop
ld a, %00110111 ; tune -> noise
ld [.mixer+1],a
.notend :
ld de,$f800 ; audio data
.beep:
ld bc,255*256+253
ld a,[de]
inc e
out (c),a
ld b,191
ld a,[de]
out (c),a
inc e
or a
jr nz,.beep
.nopix:
ld [ix],COLOR_MISSILE
push ix
pop de
ld a,d ; attribute -> pixel
and 3
rlca
rlca
rlca
or $40
ld d,a
ld a,%00111100 ; misssile gfx
ld [de],a
inc d
ld [de],a
inc d
ld [de],a
inc d
ld [de],a
; main loop : get point coords form table -> put on screen -> rotate -> update table
.pointloop:
ld e,[hl] ; next point from the tab
dec hl
ld d,[hl]
push de
push hl
;x,y (0,0 @ center of screen) to speccy screen coords
ld a,e
add a,128
ld e,a
srl a
srl a
sub e
cpl
ld e,a
ld a,d
add a,128
ld d,a
ld a,3
and d
ld b,a
inc b
ld a,e
rra
scf
rra
or a
rra
ld l,a
xor e
and 248
xor e
ld h,a
ld a,d
xor l
and 7
xor d
rrca
rrca
rrca
ld l,a
ld a,7 ; 3 bit wide pixel at start
.pixrot:
rrca
rrca
djnz .pixrot
or [hl]
ld [hl],a ; draw on screen
pop hl
pop de; back to table with x,y (hl) and pixel coords (de)
; basically a very simplified point rotation sin/cos formula, fixed angle, low precision, errors accumulate witch each iteration and points move off-center (tbh it's the clou of the effect ;)
ld a,e
sra a
sra a
sra a
sub d
cpl
ld[hl],a ;new x calced
ld a,d
sra a
sra a
sra a
add a,e
;end of rotate
inc hl
ld [hl],a ;new y calced
dec hl
dec hl
bit 7, h
jp nz, .pointloop
; process whole scren (clar-like)
ld h,$3f; hl = $3fff
.process:
srl [hl]
inc hl
sla [hl]
inc hl
ld a,h
cp $58
jr nz,.process
.nextmod:
jr .next ; modified later
.next:
pop hl
pop bc
dec b
jp nz, .rotate
jp .restart ; generate new points
end start