OpenCores
URL https://opencores.org/ocsvn/diogenes/diogenes/trunk

Subversion Repositories diogenes

[/] [diogenes/] [trunk/] [examples/] [snake4.asm] - Blame information for rev 224

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 224 fellnhofer
@ l7: stack
2
@ l6: push_function
3
@ l0: return address of leavfuction (push pop im speziell)
4
 
5
  stio l0, [l0]
6
 
7
  LDL l0, :start
8
  LDL l6, :push
9
 
10
  ldi l7, 0x03
11
  jump 
12
  lsi l7, 0xfE
13
 
14
 
15
push:
16
  st  h7, [l7]
17
  adi l7, -1
18
  st  h1, [l7]
19
  adi l7, -1
20
  st  h2, [l7]
21
  adi l7, -1
22
  st  h3, [l7]
23
  adi l7, -1
24
  st  h4, [l7]
25
  adi l7, -1
26
  st  h5, [l7]
27
  adi l7, -1
28
  st  h6, [l7]
29
  adi l7, -1
30
  st  h0, [l7]
31
  jump 
32
  adi l7, -1
33
 
34
pop:
35
  adi l7, 1
36
  ld  h0, [l7]
37
  adi l7, 1
38
  ld  h6, [l7]
39
  adi l7, 1
40
  ld  h5, [l7]
41
  adi l7, 1
42
  ld  h4, [l7]
43
  adi l7, 1
44
  ld  h3, [l7]
45
  adi l7, 1
46
  ld  h2, [l7]
47
  adi l7, 1
48
  ld  h1, [l7]
49
  adi l7, 1
50
  ld  h7, [l7]
51
  nop
52
  nop
53
  jump 
54
  nop
55
 
56
 
57
start:
58
 
59
@ initialize vmem
60
  LDL   h4, :set_tile
61
  ldi   l3, 59     @ max y
62
hloop:
63
  ldi   l2, 79     @ max x
64
pixloop:
65
  call  h0, 

66
 ldi   l1, 0x5b
67
 
68
  brnz  l2, :pixloop
69
  adi   l2, -1
70
  brnz  l3, :hloop
71
  adi   l3, -1
72
 
73
 
74
@ draw "3D" borders
75
 ldi h6, 55
76
 ldi h7, 0xc1
77
 lsi h7, 0x02
78
 LDL h3, :border
79
 call h0, 

80
 ldi h4, 55
81
 
82
 ldi h6, 6
83
 ldi h7, 0xc1
84
 lsi h7, 0x3C
85
 call h0, 

86
 ldi h4, 17
87
 
88
 ldi h7, 0xc5
89
 call h0, 

90
 lsi h7, 0x3C
91
 
92
 ldi h7, 0xc9
93
 call h0, 

94
 lsi h7, 0x3C
95
 
96
 ldi h7, 0xcd
97
 call h0, 

98
 lsi h7, 0x3C
99
 
100
 ldi h6, 17
101
 ldi h7, 0xd4
102
 call h0, 

103
 lsi h7, 0x3C
104
 
105
@ draw static text
106
 ldi l0, 0xcA
107
 lsi l0, 0x44
108
 ldi l1, 0x57 @ X
109
 stio l1, [l0]
110
 ldi l0, 0xcE
111
 lsi l0, 0x44
112
 ldi l1, 0x58 @ Y
113
 stio l1, [l0]
114
 
115
@ LEVEL
116
 ldi l0, 0xc2
117
 lsi l0, 0x42
118
 ldi l1, 0x47
119
 stio l1, [l0]
120
 adi l0, 1
121
 ldi l1, 0x3c
122
 stio l1, [l0]
123
 adi l0, 1
124
 ldi l1, 0x55
125
 stio l1, [l0]
126
 adi l0, 1
127
 ldi l1, 0x3c
128
 stio l1, [l0]
129
 adi l0, 1
130
 ldi l1, 0x47
131
 stio l1, [l0]
132
 
133
@ LEVEL
134
 ldi l0, 0xc6
135
 lsi l0, 0x42
136
 ldi l1, 0x38
137
 stio l1, [l0]
138
 adi l0, 1
139
 ldi l1, 0x4b
140
 stio l1, [l0]
141
 adi l0, 1
142
 stio l1, [l0]
143
 adi l0, 1
144
 ldi l1, 0x47
145
 stio l1, [l0]
146
 adi l0, 1
147
 ldi l1, 0x3c
148
 stio l1, [l0]
149
 adi l0, 1
150
 ldi l1, 0xec
151
 stio l1, [l0]
152
 
153
 
154
 
155
@ Andreas
156
 ldi l0, 0xD5
157
 lsi l0, 0x3e
158
 ldi l1, 0x38 @ A
159
 stio l1, [l0]
160
 adi l0, 1
161
 ldi l1, 0x49
162
 stio l1, [l0]
163
 adi l0, 1
164
 ldi l1, 0x3b
165
 stio l1, [l0]
166
  adi l0, 1
167
 ldi l1, 0x4d
168
 stio l1, [l0]
169
  adi l0, 1
170
 ldi l1, 0x3c
171
 stio l1, [l0]
172
  adi l0, 1
173
 ldi l1, 0x38
174
 stio l1, [l0]
175
  adi l0, 1
176
 ldi l1, 0x4e
177
 stio l1, [l0]
178
 
179
 
180
@ David
181
 ldi l0, 0xD8
182
 lsi l0, 0x3e
183
 ldi l1, 0x3B @ D
184
 stio l1, [l0]
185
 adi l0, 1
186
 ldi l1, 0x38
187
 stio l1, [l0]
188
 adi l0, 1
189
 ldi l1, 0x55
190
 stio l1, [l0]
191
  adi l0, 1
192
 ldi l1, 0x44
193
 stio l1, [l0]
194
  adi l0, 1
195
 ldi l1, 0x3b
196
 stio l1, [l0]
197
 
198
@ Fellnhofer
199
 ldi l0, 0xD5
200
 lsi l0, 0xc1
201
 ldi l1, 0x3D
202
 stio l1, [l0]
203
 adi l0, 1
204
 ldi l1, 0x3c
205
 stio l1, [l0]
206
 adi l0, 1
207
 ldi l1, 0x47
208
 stio l1, [l0]
209
  adi l0, 1
210
 stio l1, [l0]
211
  adi l0, 1
212
 ldi l1, 0x49
213
 stio l1, [l0]
214
  adi l0, 1
215
 ldi l1, 0x3f
216
 stio l1, [l0]
217
  adi l0, 1
218
 ldi l1, 0x4a
219
 stio l1, [l0]
220
  adi l0, 1
221
 ldi l1, 0x3d
222
 stio l1, [l0]
223
  adi l0, 1
224
 ldi l1, 0x3c
225
 stio l1, [l0]
226
  adi l0, 1
227
 ldi l1, 0x4d
228
 stio l1, [l0]
229
 
230
@ Rigler
231
 ldi l0, 0xD8
232
 lsi l0, 0xc1
233
 ldi l1, 0x4d
234
 stio l1, [l0]
235
 adi l0, 1
236
 ldi l1, 0x44
237
 stio l1, [l0]
238
 adi l0, 1
239
 ldi l1, 0x3e
240
 stio l1, [l0]
241
  adi l0, 1
242
 ldi l1, 0x47
243
 stio l1, [l0]
244
  adi l0, 1
245
 ldi l1, 0x3c
246
 stio l1, [l0]
247
  adi l0, 1
248
 ldi l1, 0x4d
249
 stio l1, [l0]
250
 
251
@ &
252
 ldi l0, 0xD7
253
 lsi l0, 0x44
254
 ldi l1, 0x5c
255
 stio l1, [l0]
256
 
257
 
258
@ Diogenes
259
 ldi l0, 0xDB
260
 lsi l0, 0x3e
261
 ldi l1, 0x3b
262
 stio l1, [l0]
263
 adi l0, 1
264
 ldi l1, 0x44
265
 stio l1, [l0]
266
 adi l0, 1
267
 ldi l1, 0x4a
268
 stio l1, [l0]
269
  adi l0, 1
270
 ldi l1, 0x3e
271
 stio l1, [l0]
272
  adi l0, 1
273
 ldi l1, 0x3c
274
 stio l1, [l0]
275
  adi l0, 1
276
 ldi l1, 0x49
277
 stio l1, [l0]
278
  adi l0, 1
279
 ldi l1, 0x3c
280
 stio l1, [l0]
281
  adi l0, 1
282
 ldi l1, 0x4e
283
 stio l1, [l0]
284
 adi l0, 2
285
 ldi l1, 0x66
286
 stio l1, [l0]
287
  adi l0, 1
288
   ldi l1, 0x64
289
 stio l1, [l0]
290
  adi l0, 1
291
   ldi l1, 0x64
292
 stio l1, [l0]
293
  adi l0, 1
294
   ldi l1, 0x6c
295
 stio l1, [l0]
296
  adi l0, 1
297
 
298
 
299
 
300
@ initialize snake
301
  ldi   h3, 0x10
302
  lsi   h3, 0x10
303
  ldi   h1, 8
304
 
305
  @ first apple
306
  ldi   h6, 16
307
  lsi   h6, 40
308
 
309
  @ intitially nothing to grow
310
  ldi   h7, 0
311
 
312
l0:
313
  st    h3, [h1]
314
  brnz  h1, :l0
315
  adi   h1, -1
316
 
317
  ldi   h1, 8     @ head != tail to avoid early gameover
318
  adi   h3, 1
319
  st    h3, [h1]
320
 
321
  ldi   h1, 7
322
  ldi   h2, 0
323
 
324
  LDL   h3, :delay
325
  LDL   h5, :update
326
 
327
  ldi   l0, 0x00       @ loop expects key input in r0
328
loop:
329
  @ldi   l0, 0x00        @simulator: 0x81
330
  @ldio  l0, [l0]
331
  ldi   l1, 0x01
332
  and   l2, l0, l1     @ select bit for right
333
  sub   h2, h2, l2     @ add bit to direction
334
  shi   l0, -1         @ shift input
335
  and   l2, l0, l1
336
  add   h2, h2, l2     @ add bit to direction
337
 
338
  stio  h2, [l0]
339
 
340
  @shi   l0, -6         @ shift input
341
  @and   h4, l0, l1
342
 
343
 
344
@ check for game over
345
  adi  l1, h1, 1
346
  ld   l1, [l1]
347
  ldi   l0, 0xff
348
  lsi   l0, 0xff
349
  and  l1, l1, l0
350
  mov  l2, h1
351
  adi  l2, -2
352
 
353
collcheck:
354
  ld   l4, [l2]
355
  nop
356
  and  l4, l4, l0
357
  xor  l4, l4, l1
358
  brnz l4, :nocoll
359
  nop
360
 
361
@ GAME OVER
362
 ldi l0, 0xce
363
 lsi l0, 0x19
364
 ldi l1, 0x3e
365
 stio l1, [l0]
366
 adi l0, 1
367
 ldi l1, 0x38
368
 stio l1, [l0]
369
 adi l0, 1
370
 ldi l1, 0x48
371
 stio l1, [l0]
372
  adi l0, 1
373
 ldi l1, 0x3c
374
 stio l1, [l0]
375
  adi l0, 2
376
 ldi l1, 0x4a
377
 stio l1, [l0]
378
  adi l0, 1
379
 ldi l1, 0x55
380
 stio l1, [l0]
381
  adi l0, 1
382
 ldi l1, 0x3c
383
 stio l1, [l0]
384
 adi l0, 1
385
 ldi l1, 0x4d
386
 stio l1, [l0]
387
 
388
 
389
no_key_pressed:
390
 call  h0, 

@ call delay

391
 ldi   l1, 30
392
 brz   l0, :no_key_pressed
393
 nop
394
 
395
 LDL   l0, :start
396
 jump  
397
 nop
398
 
399
nocoll:
400
  brnz l2, :collcheck
401
  adi  l2, -1
402
 
403
 
404
 
405
 
406
@ check for apple
407
  adi   l1, h1, 1
408
  ld    l1, [l1]
409
  ldi   l0, 0xff
410
  lsi   l0, 0xff
411
  xor   l1, l1, h6
412
  and   l1, l1, l0
413
  brnz  l1, :no_apple
414
  nop
415
  adi   h7, 8       @ grow by 8 for each apple
416
 
417
 
418
  @ FIXME: use random values
419
  ldi   l4, 53
420
  add   l0, h6, l4
421
  shi   h0, l0, -2
422
  add   l0, l0, h1
423
 
424
rand1:
425
  sub   l0, l0, l4
426
  cmpl  l1, l0, l4
427
  brz   l1, :rand1
428
  nop
429
 
430
rand2:
431
  sub   h0, h0, l4
432
  cmpl  l1, h0, l4
433
  brz   l1, :rand2
434
  nop
435
 
436
  adi   h0, 3
437
  adi   l0, 3
438
 
439
  mov   h6, l0
440
  shi   h6, 8
441
  or    h6, h6, h0
442
 
443
 
444
no_apple:
445
  ldi   l0, 0
446
  cmpl  h4, l0, h7
447
  sub   h7, h7, h4
448
 
449
 
450
@ draw apple
451
  ldi l0, 0xff
452
  and l2, h6, l0
453
  mov l3, h6
454
  shi l3, -8
455
  LDL l0, :set_tile
456
  call h0, 
457
  ldi l1, 0x06   @ apple
458
 
459
 
460
  @@ display level, apples
461
  LDL   l0, :print_val
462
  ldi l4, 0xc7
463
  mov l5, h1
464
  shi l5, -3
465
  call  h0, 
466
  lsi l4, 0x43
467
 
468
  LDL   l0, :print_val
469
  ldi l4, 0xc3
470
  mov l5, h1
471
  shi l5, -6
472
  call  h0, 
473
  lsi l4, 0x43
474
 
475
 
476
 
477
 
478
  call h0, 
@ call update
479
  mov  l1, h2
480
 
481
  add   h1, h1, h4
482
 
483
  ldi   l1, 10         @ 2^20 steps
484
  mov   l2, h1
485
  shi   l2, -6
486
  shi   l2, 2
487
  call  h0, 

@ call delay

488
  sub   l1, l1, l2
489
 
490
 
491
 
492
  brnz  h5, :loop
493
  nop
494
 
495
 
496
update:
497
  call l0, 
498
  nop
499
 
500
  brz   h4, :no_grow    @ if snake does not grow
501
  mov   l0, h1
502
  adi   l0, 2
503
  adi   h1, 1
504
  ld    l1, [h1]        @ if snake grows
505
  nop
506
  brnz  h4, :cloope
507
  mov   l2, h1
508
 
509
no_grow:
510
  ldi   l0, 0
511
  ld    l1, [l0]
512
 
513
  @ extract tile,y,x  (l1=tile, l2=x, l3=y)
514
  ldi   l4, 0xff
515
  and   l2, l1, l4
516
  shi   l1, -8
517
  and   l3, l1, l4
518
  ldi   l1, 0x1b
519
 
520
  LDL   l0, :set_tile
521
  call  h0, 
522
  nop
523
 
524
  ldi   l0, 0
525
  ldi   l2, 1
526
 
527
cloop:
528
  ld    l1, [l2]      @ src
529
  adi   l2, 1         @ src + 1
530
  st    l1, [l0]      @ dst
531
  cmpl  l3, l0, h1    @ until dst=highest address)
532
  brnz  l3, :cloop
533
  adi   l0, 1         @ dst + 1
534
cloope:
535
 
536
  ldi   l5, 3
537
  and   h2, h2, l5    @ trunc direction
538
 
539
  @ extract tile,y,x  (l1=tile, l2=x, l3=y)
540
  ldi   l4, 0xff
541
  and   l2, l1, l4
542
  shi   l1, -8
543
  and   l3, l1, l4
544
 
545
  shi   l1, -8        @ old direction
546
  shi   l1, 4         @ old direction << 2
547
  or    l1, l1, h2    @  00OO 00NN (old new combination)
548
  adi   l1, 4
549
 
550
  mov   h5, l0
551
  mov   h6, l2
552
  mov   h7, l3
553
 
554
  LDL   l4, :set_tile
555
  call  h0, 
556
  nop
557
  mov   l0, h5
558
  mov   l2, h6
559
  mov   l3, h7
560
 
561
down:
562
  xor   l4, h2, l5
563
  brnz  l4, :up
564
  nop
565
  adi   l3, 1
566
  ldi   l1, 8
567
up:
568
  ldi   l5, 1
569
  xor   l4, h2, l5
570
  brnz  l4, :right
571
  nop
572
  adi   l3, -1
573
  ldi   l1, 9
574
right:
575
  brnz  h2, :left
576
  ldi   l5, 2
577
  adi   l2, 1
578
  ldi   l1, 10
579
left:
580
  xor   l4, h2, l5
581
  brnz  l4, :end_key
582
  nop
583
  adi   l2, -1
584
  ldi   l1, 11
585
end_key:
586
 
587
  @ check for borders and wrap around
588
  ldi h0, 3
589
  cmpl l5, l2, h0
590
  brz l5, :b2
591
  nop
592
  ldi l2, 56
593
b2:
594
  cmpl l5, l3, h0
595
  brz l5, :b3
596
  nop
597
  ldi l3, 56
598
b3:
599
  ldi h0, 56
600
  cmpl l5, h0, l2
601
  brz l5, :b4
602
  nop
603
  ldi l2, 3
604
b4:
605
  cmpl l5, h0, l3
606
  brz l5, :bend
607
  nop
608
  ldi l3, 3
609
bend:
610
 
611
  mov   l4, h2
612
  shi   l4, 8
613
  or    l4, l4, l3
614
  shi   l4, 8
615
  or    l4, l4, l2
616
  st    l4, [l0]       @ write new head
617
 
618
  @@ keep x,y values
619
  mov   h2, l2
620
  mov   h3, l3
621
 
622
  LDL   l0, :set_tile
623
  call  h0, 
624
  nop
625
 
626
  @@ display x,y values
627
  LDL   h4, :print_val
628
 
629
  ldi l4, 0xcb
630
  mov l5, h2
631
  adi l5, -3
632
  call  h0, 

633
  lsi l4, 0x43
634
 
635
  ldi l4, 0xcf
636
  mov l5, h3
637
  adi l5, -3
638
  call  h0, 

639
  lsi l4, 0x43
640
 
641
 
642
 
643
  ldi   l0, 0
644
  ld    l1, [l0]
645
  @ extract tail tile,y,x  (l1=tile, l2=x, l3=y)
646
  ldi   l4, 0xff
647
  and   l2, l1, l4
648
  shi   l1, -8
649
  and   l3, l1, l4
650
  ldi   l0, 1
651
  ld    l1, [l0]
652
  nop
653
  shi   l1, -16        @ old direction
654
  adi   l1, 0x0c
655
 
656
  LDL   l0, :set_tile
657
  call  h0, 
658
  nop
659
 
660
  adi  h6, l6, 17
661
  jump 
662
  nop
663
 
664
 
665
set_stile:
666
  call l0, 
667
  nop
668
 
669
  ldi  l0, 0xff
670
  and  l2, l1, l0
671
  shi  l1, -8
672
  and  l3, l1, l0
673
 
674
  LDL  h4, :set_tile
675
  call h0, 

676
  shi  l1, -8
677
 
678
  adi  h6, l6, 17
679
  jump 
680
  nop
681
 
682
 
683
set_tile:
684
  call l0, 
685
  nop
686
 
687
  ldi   l4, 0xc0   @ vmem starts at 0xc000
688
  shi   l4, 8
689
 
690
  shi   h3, l3, 7
691
  add   l0, l2, h3
692
  add   l0, l0, l4
693
  stio  l1, [l0]
694
 
695
  adi  h6, l6, 17
696
  jump 
697
  nop
698
 
699
delay:
700
  call l0, 
701
  nop
702
  mov   l2, l1
703
  shi   l2, 16
704
  ldi   l4, 0xff
705
  shi   l4, 10
706
  ldi   l1, 0
707
  ldi   l0, 0
708
delay_loop:
709
  ldio  l3, [l1]
710
  ldi   l5, 0x0B              @ filter left, right, switch
711
  and   l3, l3, l5
712
  brz   l3, :goon
713
  nop
714
  brnz  l4, :goon2
715
  adi   l4, -1
716
  mov   l0, l3
717
goon:
718
  ldi   l4, 0xff
719
  shi   l4, 10
720
goon2:
721
  brnz  l2, :delay_loop
722
  adi   l2, -1
723
  adi  h6, l6, 17
724
  jump 
725
  nop
726
 
727
print_val:
728
  call l0, 
729
  nop
730
 
731
ldi h1, 100
732
pre_loop:
733
ldi h0, 0x63
734
add l5,l5,h1
735
count_loop:
736
sub l5,l5,h1
737
cmpl l0, l5, h1
738
brz l0, :count_loop
739
adi h0, 1
740
stio h0, [l4]
741
adi l4, 1
742
ldi l0, 10
743
xor l0,l0,h1
744
brnz l0, :pre_loop
745
ldi h1, 10
746
ldi h0, 0x64
747
add h0, h0, l5
748
stio h0, [l4]
749
 
750
 
751
  adi  h6, l6, 17
752
  jump 
753
  nop
754
 
755
border:
756
  call l0, 
757
  nop
758
 
759
  shi   h6, 7
760
  ldi   h5, 0x17
761
 fory:
762
   mov  l4, h4
763
   adi l5, h5, 2
764
 forx:
765
   add l3, h7, l4
766
   add l3,l3, h6
767
   stio  l5, [l3]
768
   adi l5, h5, 1
769
   brnz l4, :forx
770
   adi l4, -1
771
   stio h5, [l3]
772
   ldi l0,0x1d
773
   xor l0, l0, h5
774
   brz l0, :end_border
775
  ldi h5, 0x1a
776
  ldi l0, 0x80
777
  sub h6,h6,l0
778
  brnz h6, :fory
779
  nop
780
  brnz l0, :fory
781
  ldi h5, 0x1d
782
 
783
end_border:
784
  adi  h6, l6, 17
785
  jump 
786
  nop
787
 
788
 
789
stop
790
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.