aboutsummaryrefslogtreecommitdiff
path: root/examples/matrix2.s
blob: 04da5fedfd868d8805a88cae3014d7e457b190fb (plain)
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
269
270
271
272
273
274
275
276
;you may need to fix colors if your emulator does
;some other scheme, search 0xF200 and 0x0200 and
;change those values.
;
;you can also adjust display_width and display_height
;if your emulator differs from 32x12.
;
; ~enjoy~
;
;(ps, feel free to create an optimized version)

:entrypoint
  set a, 12345 ;change me!
  jsr srand
  jsr clear_screen
  jsr init_leading
  jsr init_tail_length
  jsr init_speed
  set pc, main ;never returns

:display_width
  dat 32 ;max 32
:display_height 
  dat 16 ;max 16

:main
  set push, x
  set push, y
  set push, z
  set i, 0
  
:main_loop_start
  set x, 0
  add i, 1
  mod i, 40
  set pc, main_loop

:main_next
  add x, 1
  ife x, [display_width]
    set pc, main_loop_start

:main_loop
  set a, i
  mod a, [speed+x]
  ifn a, 0
    set pc, main_next

  ;clear tail
  set y, [leading+x]
  sub y, [tail_length+x]
  ifg y, 0x7FFF
    add y, [display_height]
  set c, 0x0020
  set b, y
  set a, x
  jsr set_vram
  
  ;unhighlight last character
  set y, [leading+x]
  sub y, 1
  ifg y, 0x7FFF
    add y, [display_height]
  set b, y
  set a, x
  jsr get_vram
  set c, a
  and c, 0x00FF
  bor c, 0xF200
  set b, y
  set a, x
  jsr set_vram
  
  ;draw leading
  jsr get_character
  set c, a
  bor c, 0x0200
  set b, [leading+x]
  set a, x
  jsr set_vram
  
  ;move ahead
  set a, [leading+x]
  add a, 1
  mod a, [display_height]
  set [leading+x], a

  set pc, main_next

:get_vram
  mul b, [display_width]
  add a, b
  add a, 0x8000
  set a, [a]
  set pc, pop

:set_vram
  mul b, [display_width]
  add a, b
  add a, 0x8000
  set [a], c
  set pc, pop

:leading
  dat 0, 0, 0, 0, 0, 0, 0, 0
  dat 0, 0, 0, 0, 0, 0, 0, 0
  dat 0, 0, 0, 0, 0, 0, 0, 0
  dat 0, 0, 0, 0, 0, 0, 0, 0
:leading_end

:tail_length
  dat 0, 0, 0, 0, 0, 0, 0, 0
  dat 0, 0, 0, 0, 0, 0, 0, 0
  dat 0, 0, 0, 0, 0, 0, 0, 0
  dat 0, 0, 0, 0, 0, 0, 0, 0
:tail_length_end

:speed
  dat 0, 0, 0, 0, 0, 0, 0, 0
  dat 0, 0, 0, 0, 0, 0, 0, 0
  dat 0, 0, 0, 0, 0, 0, 0, 0
  dat 0, 0, 0, 0, 0, 0, 0, 0
:speed_end

:init_leading
  set push, i
  set push, y
  set y, [display_height]
  set i, leading
:init_leading_loop
  jsr rand
  mod a, y
  set [i], a
  add i, 1
  ifn i, leading_end
    set pc, init_leading_loop
  set y, pop
  set i, pop
  set pc, pop

:init_tail_length
  set push, i
  set push, y
  set y, [display_height]
  div y, 3
  set i, tail_length
:init_tail_length_loop
  jsr rand
  mod a, y
  add a, 2
  set [i], a
  add i, 1
  ifn i, tail_length_end
    set pc, init_tail_length_loop
  set y, pop
  set i, pop
  set pc, pop

:init_speed
  set push, i
  set i, speed
:init_speed_loop
  jsr rand
  mod a, 35
  add a, 5
  set [i], a
  add i, 1
  ifn i, speed_end
    set pc, init_speed_loop
  set i, pop
  set pc, pop

:srand
  set [rand_seed], a
  set pc, pop

:rand
	set a, [rand_seed]
	mul a, 0x7C4D
	add a, 0x3619
	set b, rand_seed
	set [b], a
	set pc, pop
:rand_seed
	dat 0x5555

:get_character
  jsr rand
  mod a, 10
  set b, [get_character_table+a]
  set pc, b
:get_character_table
  dat get_character_number
  dat get_character_number
  dat get_character_number
  dat get_character_lower
  dat get_character_lower
  dat get_character_upper
  dat get_character_upper
  dat get_character_special_1
  dat get_character_special_2
  dat get_character_special_3
:get_character_number
  jsr rand
  mod a, 10
  add a, 0x30
  set pc, pop
:get_character_lower
  jsr rand
  mod a, 27
  add a, 0x61
  set pc, pop
:get_character_upper
  jsr rand
  mod a, 27
  add a, 0x41
  set pc, pop
:get_character_special_1
  jsr rand
  mod a, 0x0F
  add a, 0x21
  set pc, pop
:get_character_special_2
  jsr rand
  mod a, 0x05
  add a, 0x5B
  set pc, pop
:get_character_special_3
  jsr rand
  mod a, 0x04
  add a, 0x7B
  set pc, pop

:clear_screen
	set push, j
	set j, sp
	set sp, 0x8200
:clear_screen_loop
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  set push, 0x20
  ifn 0x8000, sp
    set pc, clear_screen_loop
  set sp, j
  set j, pop
  set pc, pop