-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkernel7.asm
1350 lines (1181 loc) · 24.1 KB
/
kernel7.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
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
format binary as 'img'
SCREEN_X = 512
SCREEN_Y = 512
BITS_PER_PIXEL = 32
org $8000
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; NO INTRUCTIONS ABOVE THIS LINE!!! ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov sp, $8000
b main
MAIL_TAGS = $8 ; Mailbox Channel 8: Tags (ARM to VC)
MAIL_READ = $0 ; Mailbox Read Register
MAIL_WRITE = $20 ; Mailbox Write Register
MAIL_BASE = $B880 ; Mailbox Base Address
PERIPHERAL_BASE = $3F000000 ; Peripheral Base Address
GPIO_BASE = $200000 ; GPIO Base Address
GPIO_FSEL0_OUT = $1 ; GPIO Function Select: GPIO Pin X0 Is An Output
GPIO_FSEL1_OUT = $8 ; GPIO Function Select: GPIO Pin X1 Is An Output
GPIO_GPFSEL1 = $4 ; GPIO Function Select 1
GPIO_GPSET0 = $1C ; GPIO Pin Output Set 0
GPIO_GPCLR0 = $28 ; GPIO Pin Output Clear 0
GPIO_GPLEV0 = $34 ; GPIO Pin Level 0
Set_Physical_Display = $00048003 ; Frame Buffer: Set Physical (Display) Width/Height (Response: Width In Pixels, Height In Pixels)
Set_Virtual_Buffer = $00048004 ; Frame Buffer: Set Virtual (Buffer) Width/Height (Response: Width In Pixels, Height In Pixels)
Set_Depth = $00048005 ; Frame Buffer: Set Depth (Response: Bits Per Pixel)
Set_Virtual_Offset = $00048009 ; Frame Buffer: Set Virtual Offset (Response: X In Pixels, Y In Pixels)
Set_Palette = $0004800B ; Frame Buffer: Set Palette (Response: RGBA Palette Values (Index 0 To 255))
Allocate_Buffer = $00040001 ; Frame Buffer: Allocate Buffer (Response: Frame Buffer Base Address In Bytes, Frame Buffer Size In Bytes)
include 'macros.inc'
;include 'rpi.inc'
include 'framebuffer.asm'
include 'gpio.asm'
include 'system.asm'
include 'rand.asm'
include 'sin.asm'
macro wait_busy amount {
local .wait_loop_local
m32 r12, amount
.wait_loop_local:
subs r12, #1
bne .wait_loop_local
}
JOY_R = 0000000000010000b
JOY_L = 0000000000100000b
JOY_X = 0000000001000000b
JOY_A = 0000000010000000b
JOY_RIGHT = 0000000100000000b
JOY_LEFT = 0000001000000000b
JOY_DOWN = 0000010000000000b
JOY_UP = 0000100000000000b
JOY_START = 0001000000000000b
JOY_SELECT = 0010000000000000b
JOY_Y = 0100000000000000b
JOY_B = 1000000000000000b
INPUT:
dw 0
main:
; Set GPIO 10 & 11 (Clock & Latch) Function To Output
m32 r0,PERIPHERAL_BASE + GPIO_BASE
mov r1,GPIO_FSEL0_OUT + GPIO_FSEL1_OUT
str r1,[r0,GPIO_GPFSEL1]
bl init_framebuffer
mov r8, r0
; Enable output to LEDs
mov r0, LED_RED
mov r1, GPIO_FSEL0_OUT
bl set_gpio_function
mov r0, LED_GREEN
mov r1, GPIO_FSEL0_OUT
bl set_gpio_function
mov r0, LED_GREEN
mov r1, #1
bl set_gpio
mov r6, $FF
mov r7, $FF
; Setup asteroids
m32 r2, ASTEROIDS
mov r1, #256
str r1, [r2, #0] ; x
mov r1, #256
str r1, [r2, #4] ; y
mov r1, #12000
str r1, [r2, #8] ; z
mov r1, #8000
str r1, [r2, #48] ; z
mov r1, #6000
str r1, [r2, #88] ; z
mov r1, #10000
str r1, [r2, #128] ; z
bl setup_stars
loop:
;;; Update Input
;;; Input is a (lightly) modified version of Peter Lemon's bare metal raspberry pi project
m32 r0,PERIPHERAL_BASE + GPIO_BASE
mov r1,GPIO_11
str r1,[r0,GPIO_GPSET0] ; Set (Latch) HIGH
wait_busy 32
str r1,[r0,GPIO_GPCLR0] ; Set (Latch) LOW
wait_busy 32
mov r1,0 ; R1 = Input Data
mov r2,15 ; R2 = Input Data Count
LoopInputData:
ldr r3,[r0,GPIO_GPLEV0] ; Get (Data)
tst r3,GPIO_4
moveq r3,1 ; (Data) LOW
orreq r1,r3,lsl r2
mov r3,GPIO_10
str r3,[r0,GPIO_GPSET0]; Set (Clock) HIGH
wait_busy 32
str r3,[r0,GPIO_GPCLR0]; Set (Clock) LOW
wait_busy 32
subs r2,1
bge LoopInputData ; Loop 16bit Data
m32 r0, INPUT
str r1, [r0]
;;; End Update input
mov r3, #0 ; moved this frame flag
push {r6, r7} ; popped in clear line
tst r1, JOY_RIGHT
addne r6, #10
movne r3, #1
tst r1, JOY_LEFT
subne r6, #10
movne r3, #1
tst r1, JOY_DOWN
addne r7, #10
movne r3, #1
tst r1, JOY_UP
subne r7, #10
movne r3, #1
push {r3} ; moved this frame saved for later
tst r1, JOY_Y
beq skip_bullet_check$
push{r4, r5, r9, r10}
m32 r4, SCREEN_X
m32 r5, SCREEN_Y
lsr r4, #1
lsr r5, #1
m32 r9, ASTEROIDS
mov r0, #1
push{r0}
mov r0, #0
push{r0}
push{r0}
push{r0}
detect_collide_one_asteroid$:
ldr r0, [r9, #0] ; x mesh center
lsl r0, #8 ; * 128 focal distance
ldr r1, [r9, #8]
bl div ; x/z
add r0, r4 ; + screenwidth/2
push{r0}
ldr r0, [r9, #4] ; y mesh center
lsl r0, #8 ; * 128 focal distance
ldr r1, [r9, #8]
bl div ; y/z
add r0, r5 ; + screenheight/2
push{r0}
mov r0, r6
mov r1, r7
pop{r3}
pop{r2}
; debug draw line
; push{r0, r1, r2, r3, r4}
; m32 r4, Plot_Line_Data
; str r0, [r4, #0]
; str r1, [r4, #4]
; str r2, [r4, #8]
; str r3, [r4, #12]
; mov r0, r8
; bl plot_line
; pop {r0, r1, r2, r3, r4}
bl distance_squared
push{r0}
ldr r0, [r9, #12] ; w
lsl r0, #8 ; * 128 focal distance
ldr r1, [r9, #8]
bl div ; w/z
mul r0, r0
pop {r1}
cmp r0, r1
blt no_collision$
; clear old asteroid
m32 r2, DRAW_COLOR
mov r1, $0
str r1, [r2]
mov r0, r8
bl draw_asteroids
; halve the asteroid's width
ldr r0, [r9, #12]
lsr r0, #1
str r0, [r9, #12]
cmp r0, $70
bgt no_collision$ ; don't re-randomize if it still has HP
; re-randomize the asteroid
bl rand
mov r1, r0
lsr r1, #1
str r1, [r9, #0] ; x
bl rand
mov r1, r0
lsr r1, #1
str r1, [r9, #4] ; y
mov r1, #8000
str r1, [r9, #8] ; z
mov r1, ASTEROID_START_WIDTH
str r1, [r9, #12] ; z
;rand rot
bl rand
and r0, $10
sub r0, $8
str r0, [r9, #20]
bl rand
and r0, $10
sub r0, $8
str r0, [r9, #28]
bl rand
and r0, $10
sub r0, $8
str r0, [r9, #36]
no_collision$:
add r9, #40
pop{r0}
cmp r0, #0
beq detect_collide_one_asteroid$
pop {r4, r5, r9, r10}
skip_bullet_check$:
m32 r0, DRAW_COLOR
m32 r1, $FF0000
str r1, [r0]
mov r0, r8 ; framebuffer
; clear asteroids
m32 r2, DRAW_COLOR
mov r1, #0
str r1, [r2]
bl draw_asteroids
; update asteroids
m32 r2, ASTEROIDS
mov r3, #1
push{r3}
mov r3, #0
push{r3}
push{r3}
push{r3}
update_one_asteroid$:
; update rotation
ldr r1, [r2, #16]
ldr r3, [r2, #20]
add r1, r3
cmp r3, #0
bgt positive_rotation1$
cmp r1, #0
addlt r1, #360
b store_asteroid_rotation1$
positive_rotation1$:
cmp r1, #360
subge r1, #360
store_asteroid_rotation1$:
str r1, [r2, #16]
ldr r1, [r2, #24]
ldr r3, [r2, #28]
add r1, r3
cmp r3, #0
bgt positive_rotation2$
cmp r1, #0
addlt r1, #360
b store_asteroid_rotation2$
positive_rotation2$:
cmp r1, #360
subge r1, #360
store_asteroid_rotation2$:
str r1, [r2, #24]
ldr r1, [r2, #32]
ldr r3, [r2, #36]
add r1, r3
cmp r3, #0
bgt positive_rotation3$
cmp r1, #0
addlt r1, #360
b store_asteroid_rotation3$
positive_rotation3$:
cmp r1, #360
subge r1, #360
store_asteroid_rotation3$:
str r1, [r2, #32]
; move forwards
ldr r1, [r2, #8]
sub r1, #32
str r1, [r2, #8]
cmp r1, #512
bgt no_death$
m32 r2, DRAW_COLOR
mov r1, $FF
str r1, [r2]
bl draw_asteroids
death_loop$:
bl update_stars
m32 r2, DRAW_COLOR
m32 r1, $ffffff
str r1, [r2]
mov r0, r8
bl draw_stars
b death_loop$
push{r0}
no_death$:
add r2, #40
pop {r3}
cmp r3, #0
beq update_one_asteroid$
;draw asteroids
m32 r2, DRAW_COLOR
mov r1, $00FF00
str r1, [r2]
bl draw_asteroids
m32 r2, DRAW_COLOR
mov r1, $0
str r1, [r2]
mov r0, r8
bl draw_stars
bl update_stars
m32 r2, DRAW_COLOR
m32 r1, $ffffff
str r1, [r2]
mov r0, r8
bl draw_stars
pop {r3}
pop {r4, r5}
cmp r3, #0
beq skip_clear_crosshair$ ; Don't clear lines if we haven't moved
push{r6, r7}
mov r6, r4
mov r7, r5
; Clear over old line
m32 r0, DRAW_COLOR
mov r1, #0
str r1, [r0]
bl draw_cross_hair
pop {r6, r7}
skip_clear_crosshair$:
; Draw crosshair
m32 r2, DRAW_COLOR
m32 r1, $ffffff
str r1, [r2]
mov r0, r8
bl draw_cross_hair
skip_drawing_lines$:
; bl draw_bullet
mov r0, $8000
;bl wait
b loop;;;;;;;;;;;;;;;;;;;;;;; END MAIN LOOP
draw_cross_hair:
push{lr}
m32 r0, Plot_Line_Data
sub r1, r6, #32
str r1, [r0, #0] ; x1
sub r1, r7, #32
str r1, [r0, #4] ; y1
sub r1, r6, #16
str r1, [r0, #8] ; x2
sub r1, r7, #16
str r1, [r0, #12]; y2
mov r0, r8
bl plot_line
m32 r0, Plot_Line_Data
add r1, r6, #32
str r1, [r0, #0] ; x1
sub r1, r7, #32
str r1, [r0, #4] ; y1
add r1, r6, #16
str r1, [r0, #8] ; x2
sub r1, r7, #16
str r1, [r0, #12]; y2
mov r0, r8
bl plot_line
m32 r0, Plot_Line_Data
sub r1, r6, #32
str r1, [r0, #0] ; x1
add r1, r7, #32
str r1, [r0, #4] ; y1
sub r1, r6, #16
str r1, [r0, #8] ; x2
add r1, r7, #16
str r1, [r0, #12]; y2
mov r0, r8
bl plot_line
m32 r0, Plot_Line_Data
add r1, r6, #32
str r1, [r0, #0] ; x1
add r1, r7, #32
str r1, [r0, #4] ; y1
add r1, r6, #16
str r1, [r0, #8] ; x2
add r1, r7, #16
str r1, [r0, #12]; y2
mov r0, r8
bl plot_line
pop {pc}
POINT_BOX_COLLISION_DATA:
; 0, 4, 8,12,16
; px py bx by bw
dw 0, 0, 0, 0, 0
point_box_collision:
push{lr, r4, r5, r6, r7, r8, r9}
mov r0, #0
m32 r4, POINT_BOX_COLLISION_DATA
ldr r5, [r4, #0 ] ; px
ldr r6, [r4, #4 ] ; py
ldr r7, [r4, #8 ] ; bx
ldr r8, [r4, #12] ; by
ldr r9, [r4, #16] ; bw
lsr r9, #1
sub r7, r9
cmp r5, r7 ; px < bx-w
blt point_box_return$
add r7, r9
add r7, r9
cmp r5, r7 ; px > bx+w
bgt point_box_return$
sub r8, r9
cmp r6, r8 ; py < by-w
blt point_box_return$
add r8, r9
add r8, r9
cmp r6, r8 ; py > by+w
bgt point_box_return$
mov r0, #1
point_box_return$:
pop {pc, r4, r5, r6, r7, r8, r9}
;(x1,y1,x2,y2)->(distance_squared)
distance_squared:
sub r0, r2
sub r1, r3
mul r0, r0
mul r1, r1
add r0, r1
bx lr
ASTEROID_START_WIDTH = $1F0
TEMP: dw 0
ASTEROIDS:
; 0 4 8 12 16 20 24 28 32 36
; x, y, z, w, rx, drx ry dry rz drz
dw 0, 0, 0, ASTEROID_START_WIDTH, 0, 4, 0, 6, 0, -8
dw 0, 0, 0, ASTEROID_START_WIDTH, 0, 4, 0, 6, 0, -8
dw 0, 0, 0, ASTEROID_START_WIDTH, 0, 4, 0, 6, 0, -8
dw 0, 0, 0, ASTEROID_START_WIDTH, 0, 4, 0, 6, 0, -8
draw_asteroids:
push{lr, r4, r5, r6, r7, r8, r9, r10, r11, r12}
mov r4, #1
push{r4}
mov r4, #0
push{r4}
push{r4}
push{r4}
; halfwidth = z/2
m32 r11, ASTEROIDS ; r11 = asteroid data
m32 r4, SCREEN_X
lsr r4, #1 ; r4 = half screen width
m32 r9, SCREEN_Y
lsr r9, #1
m32 r8, Plot_Quad_Data ; r8 = Plot_Quad_Data
draw_one_asteroid$:
ldr r10,[r11, #8 ] ; r10 = zdepth
; change draw color based on distance
; push{r0, r1, r2}
; m32 r5, DRAW_COLOR
; ldr r6, [r5]
; mov r0, $FF0000
; mov r1, r10
; bl div
; lsr r0, #7
; cmp r6, #0
; and r6, $FF00
; addne r6, r0
; str r6, [r5]
; pop {r0, r1, r2}
ldr r5, [r11, #12]
lsr r5, #1 ; r5 = halfwidth
ldr r6, [r11, #0] ; r6, r7 = x, y
ldr r7, [r11, #4]
mov r12, #0
draw_ast_quad$:
push{r0, r1, r2}
push{r5}
push{r5}
push{r5}
push{r5}
cmp r12, #0
negne r5
; vert 0
rsb r0, r5, #0
mov r1, r0
pop{r2}
ldr r3, [r11, #32]
bl rotx
ldr r3, [r11, #24]
bl roty
ldr r3, [r11, #16]
bl rotz
push{r1, r2}
;project x to screen
add r0, r6 ; + x mesh center
lsl r0, #8 ; * 128 focal distance
add r1, r2, r10 ; + zdepth
bl div ; x/z
add r0, r4 ; + screenwidth/2
str r0, [r8, #0] ; store final x
pop {r1, r2}
;project y to screen
mov r0, r1
add r0, r7
lsl r0, #8
add r1, r2, r10
bl div
add r0, r9
str r0, [r8, #4] ; store final y
; vert 1
mov r0, r5
rsb r1, r5, #0
pop{r2}
ldr r3, [r11, #32]
bl rotx
ldr r3, [r11, #24]
bl roty
ldr r3, [r11, #16]
bl rotz
push{r1, r2}
;project x to screen
add r0, r6
lsl r0, #8
add r1, r2, r10
bl div
add r0, r4
str r0, [r8, #8] ; store final x
pop {r1, r2}
;project y to screen
mov r0, r1
add r0, r7
lsl r0, #8
add r1, r2, r10
bl div
add r0, r9
str r0, [r8, #12] ; store final y
; vert 2
mov r0, r5
mov r1, r0
pop{r2}
ldr r3, [r11, #32]
bl rotx
ldr r3, [r11, #24]
bl roty
ldr r3, [r11, #16]
bl rotz
push{r1, r2}
;project x to screen
add r0, r6
lsl r0, #8
add r1, r2, r10
bl div
add r0, r4
str r0, [r8, #16] ; store final x
pop {r1, r2}
;project y to screen
mov r0, r1
add r0, r7
lsl r0, #8
add r1, r2, r10
bl div
add r0, r9
str r0, [r8, #20] ; store final y
; vert 3
rsb r0, r5, #0
mov r1, r5
pop{r2}
ldr r3, [r11, #32]
bl rotx
ldr r3, [r11, #24]
bl roty
ldr r3, [r11, #16]
bl rotz
push{r1, r2}
;project x to screen
add r0, r6
lsl r0, #8
add r1, r2, r10
bl div
add r0, r4
str r0, [r8, #24] ; store final x
pop {r1, r2}
;project y to screen
mov r0, r1
add r0, r7
lsl r0, #8
add r1, r2, r10
bl div
add r0, r9
str r0, [r8, #28] ; store final y
pop {r0, r1, r2}
bl plot_quad
cmp r12, #0
mov r12, #1
neg r5
beq draw_ast_quad$
mov r12, #0
draw_ast_quad2$:
push{r0, r1, r2}
push{r5}
neg r5
push{r5}
push{r5}
neg r5
push{r5}
; vert 0
rsb r0, r5, #0
mov r1, r0
pop{r2}
ldr r3, [r11, #32]
bl rotx
ldr r3, [r11, #24]
bl roty
ldr r3, [r11, #16]
bl rotz
push{r1, r2}
;project x to screen
add r0, r6
lsl r0, #8
add r1, r2, r10
bl div
add r0, r4
str r0, [r8, #0] ; store final x
pop {r1, r2}
;project y to screen
mov r0, r1
add r0, r7
lsl r0, #8
add r1, r2, r10
bl div
add r0, r9
str r0, [r8, #4] ; store final y
; vert 1
rsb r0, r5, #0
mov r1, r0
pop{r2}
ldr r3, [r11, #32]
bl rotx
ldr r3, [r11, #24]
bl roty
ldr r3, [r11, #16]
bl rotz
push{r1, r2}
;project x to screen
add r0, r6
lsl r0, #8
add r1, r2, r10
bl div
add r0, r4
str r0, [r8, #8] ; store final x
pop {r1, r2}
;project y to screen
mov r0, r1
add r0, r7
lsl r0, #8
add r1, r2, r10
bl div
add r0, r9
str r0, [r8, #12] ; store final y
; vert 2
rsb r0, r5, #0
mov r1, r5
pop{r2}
ldr r3, [r11, #32]
bl rotx
ldr r3, [r11, #24]
bl roty
ldr r3, [r11, #16]
bl rotz
push{r1, r2}
;project x to screen
add r0, r6
lsl r0, #8
add r1, r2, r10
bl div
add r0, r4
str r0, [r8, #16] ; store final x
pop {r1, r2}
;project y to screen
mov r0, r1
add r0, r7
lsl r0, #8
add r1, r2, r10
bl div
add r0, r9
str r0, [r8, #20] ; store final y
; vert 3
rsb r0, r5, #0
mov r1, r5
pop{r2}
ldr r3, [r11, #32]
bl rotx
ldr r3, [r11, #24]
bl roty
ldr r3, [r11, #16]
bl rotz
push{r1, r2}
;project x to screen
add r0, r6
lsl r0, #8
add r1, r2, r10
bl div
add r0, r4
str r0, [r8, #24] ; store final x
pop {r1, r2}
;project y to screen
mov r0, r1
add r0, r7
lsl r0, #8
add r1, r2, r10
bl div
add r0, r9
str r0, [r8, #28] ; store final y
pop {r0, r1, r2}
bl plot_quad
cmp r12, #0
mov r12, #1
neg r5
beq draw_ast_quad2$
; advance to next asteroid
add r11, #40
pop{r12}
cmp r12, #0
beq draw_one_asteroid$
pop {pc, r4, r5, r6, r7, r8, r9, r10, r11, r12}
Draw_Bullet_Data:
dw 0
draw_bullet:
push{lr, r4, r5}
m32 r4, Draw_Bullet_Data
ldr r4, [r4]
cmp r4, #0
beq return_from_draw_bullet$
m32 r4, Plot_Quad_Data
; vert 0
mov r5, #5
str r5, [r4, #0]
mov r5, #64
str r5, [r4, #4]
; vert 1
mov r5, #64
str r5, [r4, #8]
mov r5, #32
str r5, [r4, #12]
; vert 2
mov r5, #64
str r5, [r4, #16]
mov r5, #128
str r5, [r4, #20]
; vert 3
mov r5, #5
str r5, [r4, #24]
mov r5, #128
str r5, [r4, #28]
bl plot_quad
return_from_draw_bullet$:
pop {pc, r4, r5}
; in {r0: framebuffer
; r1: color}
clear_screen:
mov r4, r0
mov r1, SCREEN_Y
mov r2, r1
draw_row$:
mov r0, SCREEN_X
draw_pixel$:
rept 64 {
str r2, [r4]
add r4, #4
}
sub r0, $40
teq r0, #0
bne draw_pixel$
sub r1, #1
teq r1, #0
bne draw_row$
bx lr
DRAW_COLOR:
dw 0
; (const fb, x, y, const SCREEN_X)
plot:
cmp r1, 0
bxlt lr
cmp r1, r3
bxge lr
cmp r2, 0
bxlt lr
push{r4}
m32 r4, SCREEN_Y
cmp r2, r4
pop {r4}
bxge lr
mul r2, r3
add r1, r2
lsl r1, #2
add r1, r0
m32 r2, DRAW_COLOR
ldr r2, [r2]
str r2, [r1]
bx lr
Plot_Quad_Data:
dw 0, 0, 0, 0
dw 0, 0, 0, 0
plot_quad:
push {lr, r4, r5}
m32 r4, Plot_Line_Data
m32 r5, Plot_Quad_Data
ldr r1, [r5, #0]
str r1, [r4, #0] ; x1
ldr r1, [r5, #4]
str r1, [r4, #4] ; y1
ldr r1, [r5, #8]
str r1, [r4, #8] ; x2
ldr r1, [r5, #12]
str r1, [r4, #12]; y2
bl plot_line
ldr r1, [r5, #8]
str r1, [r4, #0] ; x1
ldr r1, [r5, #12]
str r1, [r4, #4] ; y1
ldr r1, [r5, #16]
str r1, [r4, #8] ; x2
ldr r1, [r5, #20]
str r1, [r4, #12]; y2
bl plot_line
ldr r1, [r5, #16]
str r1, [r4, #0] ; x1
ldr r1, [r5, #20]
str r1, [r4, #4] ; y1
ldr r1, [r5, #24]
str r1, [r4, #8] ; x2
ldr r1, [r5, #28]
str r1, [r4, #12]; y2
bl plot_line
ldr r1, [r5, #24]
str r1, [r4, #0] ; x1
ldr r1, [r5, #28]
str r1, [r4, #4] ; y1
ldr r1, [r5, #0]
str r1, [r4, #8] ; x2
ldr r1, [r5, #4]
str r1, [r4, #12]; y2
bl plot_line
pop {pc, r4, r5}
; X0, Y0, X1, Y1
Plot_Line_Data:
dw 0, 0, 0, 0
; plot line using Bresenham's line algorithm
; (frame_buffer) -> ()
plot_line:
push{lr, r4, r5, r6, r7, r8, r9, r10, r11, r12}
mov r1, Plot_Line_Data
ldr r4, [r1, #0] ; x0
ldr r5, [r1, #4] ; y0
ldr r6, [r1, #8] ; x1
ldr r7, [r1, #12]; y1
; int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;