-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjogo_new.asm
2715 lines (2440 loc) · 55.5 KB
/
jogo_new.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
pixel: var #1
offsetX: var #1
offsetY: var #1
offsetZ: var #1
color1: var #1
color2: var #1
cbrown: var #1
static cbrown, #256
cblue: var #1
static cblue, #1024
teal: var #1
static teal, #1536
mapSize: var #1
static mapSize, #11
map: var #121
static map + #0, #1
static map + #1, #1
static map + #2, #1
static map + #3, #1
static map + #4, #0
static map + #5, #1
static map + #6, #1
static map + #7, #1
static map + #8, #1
static map + #9, #1
static map + #10, #1
static map + #11, #1
static map + #12, #0
static map + #13, #0
static map + #14, #0
static map + #15, #0
static map + #16, #1
static map + #17, #0
static map + #18, #0
static map + #19, #0
static map + #20, #0
static map + #21, #1
static map + #22, #1
static map + #23, #0
static map + #24, #1
static map + #25, #1
static map + #26, #1
static map + #27, #1
static map + #28, #0
static map + #29, #1
static map + #30, #1
static map + #31, #0
static map + #32, #1
static map + #33, #1
static map + #34, #1
static map + #35, #1
static map + #36, #0
static map + #37, #0
static map + #38, #0
static map + #39, #0
static map + #40, #1
static map + #41, #0
static map + #42, #0
static map + #43, #0
static map + #44, #0
static map + #45, #0
static map + #46, #1
static map + #47, #1
static map + #48, #1
static map + #49, #1
static map + #50, #1
static map + #51, #1
static map + #52, #1
static map + #53, #1
static map + #54, #1
static map + #55, #0
static map + #56, #1
static map + #57, #0
static map + #58, #0
static map + #59, #0
static map + #60, #1
static map + #61, #0
static map + #62, #0
static map + #63, #0
static map + #64, #1
static map + #65, #0
static map + #66, #0
static map + #67, #1
static map + #68, #1
static map + #69, #1
static map + #70, #1
static map + #71, #1
static map + #72, #1
static map + #73, #1
static map + #74, #1
static map + #75, #1
static map + #76, #0
static map + #77, #0
static map + #78, #0
static map + #79, #1
static map + #80, #0
static map + #81, #0
static map + #82, #0
static map + #83, #0
static map + #84, #0
static map + #85, #0
static map + #86, #0
static map + #87, #0
static map + #88, #0
static map + #89, #0
static map + #90, #1
static map + #91, #0
static map + #92, #1
static map + #93, #1
static map + #94, #1
static map + #95, #1
static map + #96, #1
static map + #97, #1
static map + #98, #0
static map + #99, #0
static map + #100, #0
static map + #101, #1
static map + #102, #1
static map + #103, #1
static map + #104, #0
static map + #105, #0
static map + #106, #1
static map + #107, #0
static map + #108, #0
static map + #109, #0
static map + #110, #0
static map + #111, #0
static map + #112, #0
static map + #113, #1
static map + #114, #1
static map + #115, #0
static map + #116, #0
static map + #117, #1
static map + #118, #0
static map + #119, #0
static map + #120, #0
pos: var #1
direction: var #1
posVictory: var #1
colorVictory1: var #1
static colorVictory1, #2816
colorVictory2: var #1
static colorVictory1, #1792
viewDist: var #1
static viewDist, #13
width: var #1
static width, #40
height: var #1
static height, #30
luz: var #4
static luz + #0, #123
static luz + #1, #124
static luz + #2, #125
static luz + #3, #126
products: var #12
square: var #12
squareSide: var #12
static squareSide + #0, #0
static squareSide + #1, #80
static squareSide + #2, #0
static squareSide + #3, #0
static squareSide + #4, #80
static squareSide + #5, #100
static squareSide + #6, #0
static squareSide + #7, #0
static squareSide + #8, #100
static squareSide + #9, #0
static squareSide + #10, #0
static squareSide + #11, #0
squareFront: var #12
static squareFront + #0, #100
static squareFront + #1, #80
static squareFront + #2, #100
static squareFront + #3, #100
static squareFront + #4, #0
static squareFront + #5, #100
static squareFront + #6, #0
static squareFront + #7, #0
static squareFront + #8, #100
static squareFront + #9, #0
static squareFront + #10, #80
static squareFront + #11, #100
squareBottom: var #12
static squareBottom + #0, #100
static squareBottom + #1, #0
static squareBottom + #2, #100
static squareBottom + #3, #0
static squareBottom + #4, #0
static squareBottom + #5, #100
static squareBottom + #6, #0
static squareBottom + #7, #0
static squareBottom + #8, #0
static squareBottom + #9, #100
static squareBottom + #10, #0
static squareBottom + #11, #0
screen: var #1200
jmp main
main:
loadn r0, #3
store posVictory, r0
loadn r0, #117
store pos, r0
loadn r0, #11
neg r0, r0
store direction, r0
load r0, cblue
store color1, r0
load r0, teal
store color2, r0
mainLoop:
call BlankScreen
call RenderLabyrinth
call PrintScreen
call CheckVictoryPos
call PlayerControler
jmp mainLoop
halt
Victory:
call printtelaScreen
halt
CheckVictoryPos:
push r0
push r1
load r0, pos
load r1, posVictory
cmp r0, r1
jeq Victory
pop r1
pop r0
rts
PlayerControler:
push r0
push r1
push r2
loadn r2, #255
PlayerControlerLoop:
inchar r0
loadn r1, #119 ; moves with w
cmp r0, r1
ceq PMove
loadn r1, #100
cmp r0, r1
ceq PRotateRight
loadn r1, #97
cmp r0, r1
ceq PRotateLeft
cmp r0, r2
jne PlayerControlerLoop
pop r2
pop r1
pop r0
rts
PRotateLeft: ; rotates the player to the left
push r0
call PRotateRight
load r0, direction
neg r0, r0
store direction, r0
pop r0
rts
PRotateRight: ; rotates the player to the right
push r1
push r2
push r3
load r1, color1
load r2, color2
store color2, r1
store color1, r2
load r1, direction
loadn r3, #0
load r2, mapSize
div r2, r1, r2
cmp r2, r3
jeq PRotateCheck
load r2, mapSize
div r1, r1, r2 ; if mapSize, only divides by mapSize and inverts
neg r1, r1
jmp PRotateCheckEnd
PRotateCheck:
load r2, mapSize
mul r1, r2, r1 ; if 1, evaluates the correct direction
PRotateCheckEnd:
store direction, r1
pop r3
pop r2
pop r1
rts
PMove: ; moves the player in the current direction
push r0
push r1
push r2
push r3
push r4
push r5
push r7
load r0, pos
load r1, direction
load r2, mapSize
mul r2, r2, r2
loadn r4, #0
loadn r5, #0
; checks positions in front
add r0, r0, r1 ; advances one position
cmp r0, r5
jle PMoveUndo
cmp r0, r2
jeg PMoveUndo ; checks uper and lower limits
load r2, mapSize
mod r3, r0, r2
loadn r7, #1
sub r7, r1, r7
cmp r3, r7
jeq PMoveUndo ; checks if it is going through the right side
mod r3, r0, r2
mul r3, r3, r1
load r7, mapSize
dec r7
neg r7, r7
cmp r3, r7
jeq PMoveUndo ; checks if it is going through the left side
loadn r3, #map
add r3, r3, r0
loadi r3, r3
cmp r3, r5
jeq PMoveUndo ; checks if the position is vacant
jmp PMoveEnd
PMoveUndo:
sub r0, r0, r1
PMoveEnd:
store pos, r0
pop r7
pop r5
pop r4
pop r3
pop r2
pop r1
pop r0
rts
RenderLabyrinth:
push r0
push r1
push r2
push r3
push r4
push r5
push r6
push r7
load r0, pos
load r1, direction
load r2, mapSize
mul r2, r2, r2
loadn r4, #0
loadn r5, #0
; checks positions in front
add r0, r0, r1 ; advances one position
cmp r0, r5
jle RenderLabyrinthLoop
cmp r0, r2
jeg RenderLabyrinthLoop ; checks uper and lower limits
load r2, mapSize
mod r3, r0, r2
loadn r7, #1
sub r7, r1, r7
cmp r3, r7
jeq RenderLabyrinthLoop ; checks if it is going through the right side
mod r3, r0, r2
mul r3, r3, r1
load r6, mapSize
dec r6
neg r6, r6
cmp r3, r6
jeq RenderLabyrinthLoop ; checks if it is going through the left side
inc r4
load r2, mapSize
mul r2, r2, r2
add r0, r0, r1 ; advances one more position
cmp r0, r5
jle RenderLabyrinthLoop
cmp r0, r2
jeg RenderLabyrinthLoop ; checks uper and lower limits
load r2, mapSize
mod r3, r0, r2
loadn r7, #1
sub r7, r1, r7
cmp r3, r7
jeq RenderLabyrinthLoop ; checks if it is going through the right side
mod r3, r0, r2
mul r3, r3, r1
load r6, mapSize
dec r6
neg r6, r6
cmp r3, r6
jeq RenderLabyrinthLoop ; checks if it is going through the left side
inc r4
RenderLabyrinthLoop:
loadn r7, #50
neg r7, r7
loadn r6, #100
mul r6, r6, r4
add r7, r7, r6
store offsetZ, r7
loadn r7, #40
neg r7, r7
store offsetY, r7
loadn r7, #0
store offsetX, r7 ; stores offsets for consecutive prints
loadn r7, #luz
inc r7
add r7, r7, r4
loadi r7, r7
store pixel, r7 ; choses lighting to be used
load r0, pos
mul r7, r4, r1
add r0, r0, r7 ; recalculates position in matrix
call RenderBlockPosition ; renders chosen block and restarts the loop with the previous one
dec r4
cmp r4, r5
jeg RenderLabyrinthLoop
pop r7
pop r6
pop r5
pop r4
pop r3
pop r2
pop r1
pop r0
rts
RenderBlockPosition: ; receives position in r0 and direction in r1
push r0
push r1
push r2
push r3
push r4
push r5
push r6
push r7
push r5 ; special check
call RenderCeiling
call RenderGround ; always render ceiling and ground
; checks position in front
load r2, mapSize
mul r2, r2, r2
loadn r5, #0
add r7, r0, r1 ; advances one position
cmp r7, r5
jle RenderBlockPositionFirst
cmp r7, r2
jeg RenderBlockPositionFirst ; checks uper and lower limits
load r2, mapSize
mod r3, r7, r2
loadn r6, #1
sub r6, r1, r6
cmp r3, r6
jeq RenderBlockPositionFirst ; checks if it is going through the right side
mod r3, r7, r2
mul r3, r3, r1
load r6, mapSize
dec r6
neg r6, r6
cmp r3, r6
jeq RenderBlockPositionFirst ; checks if it is going through the left side
loadn r6, #map
add r6, r6, r7
loadi r6, r6
cmp r6, r5
jeq RenderBlockPositionFirst ; checks if the position is vacant
jmp RenderBlockPositionStartSecond
RenderBlockPositionFirst: ; renders screen if one of the checks fail
call RenderFront
;breakp
RenderBlockPositionStartSecond: ; calculates direction to the right
load r2, mapSize
div r2, r1, r2
cmp r2, r5
jeq RenderBlockPositionStartSecondCheck
load r2, mapSize
div r1, r1, r2 ; if 5, only divides by 5 and inverts
neg r1, r1
jmp RenderBlockPositionStartSecondCheckEnd
RenderBlockPositionStartSecondCheck:
load r2, mapSize
mul r1, r2, r1 ; if 1, evaluates the correct direction
RenderBlockPositionStartSecondCheckEnd:
; checks given position
load r2, mapSize
mul r2, r2, r2
loadn r5, #0
add r7, r0, r1 ; advances one position
cmp r7, r5
jle RenderBlockPositionSecond
cmp r7, r2
jeg RenderBlockPositionSecond ; checks uper and lower limits
load r2, mapSize
mod r3, r7, r2
loadn r6, #1
sub r6, r1, r6
cmp r3, r6
jeq RenderBlockPositionSecond ; checks if it is going through the right side
mod r3, r7, r2
mul r3, r3, r1
load r6, mapSize
dec r6
neg r6, r6
cmp r3, r6
jeq RenderBlockPositionSecond ; checks if it is going through the left side
loadn r6, #map
add r6, r6, r7
loadi r6, r6
cmp r6, r5
jeq RenderBlockPositionSecond ; checks if the position is vacant
pop r5
loadn r6, #1
cmp r5, r6
push r5
jeq RenderBlockPositionStartThird
loadn r6, #128
load r7, pixel
mod r7, r7, r6
loadn r6, #126
cmp r6, r7
jeq RenderBlockPositionStartThird ; uses light to check if it must continue
; calls recursivelly to check further
load r7, pixel
inc r7
store pixel, r7
load r6, offsetX ; updates position, light and offset
loadn r7, #100
add r7, r6, r7
store offsetX, r7
mov r7, r0
add r0, r0, r1
push r1
load r1, direction
loadn r5, #1
call RenderBlockPosition ; call new check
loadn r5, #0
pop r1
mov r0, r7
store offsetX, r6 ; returns position, light and offset to original values
load r7, pixel
dec r7
store pixel, r7
jmp RenderBlockPositionStartThird
RenderBlockPositionSecond: ; renders screen if one of the checks fail
call RenderRightWall
RenderBlockPositionStartThird: ; checks wall to the left
neg r1, r1 ; inverts current direction
; checks given position
load r2, mapSize
mul r2, r2, r2
loadn r5, #0
add r7, r0, r1 ; advances one position
cmp r7, r5
jle RenderBlockPositionThird
cmp r7, r2
jeg RenderBlockPositionThird ; checks uper and lower limits
load r2, mapSize
mod r3, r7, r2
loadn r6, #1
sub r6, r1, r6
cmp r3, r6
jeq RenderBlockPositionThird ; checks if it is going through the right side
mod r3, r7, r2
mul r3, r3, r1
load r6, mapSize
dec r6
neg r6, r6
cmp r3, r6
jeq RenderBlockPositionThird ; checks if it is going through the left side
loadn r6, #map
add r6, r6, r7
loadi r6, r6
cmp r6, r5
jeq RenderBlockPositionThird ; checks if the position is vacant
pop r5
loadn r6, #1
cmp r5, r6
push r5
jeq RenderBlockPositionEnd
loadn r6, #128
load r7, pixel
mod r7, r7, r6
loadn r6, #126
cmp r6, r7
jeq RenderBlockPositionEnd ; uses light to check if it must continue
; calls recursivelly to check further
load r7, pixel
inc r7
store pixel, r7
load r6, offsetX ; updates position, light and offset
loadn r7, #100
add r7, r6, r7
neg r7, r7
store offsetX, r7
mov r7, r0
add r0, r0, r1
push r1
load r1, direction
loadn r5, #1
call RenderBlockPosition ; call new check
loadn r5, #0
pop r1
mov r0, r7
store offsetX, r6 ; returns position, light and offset to original values
load r7, pixel
dec r7
store pixel, r7
jmp RenderBlockPositionEnd
RenderBlockPositionThird: ; renders screen if one of the checks fail
call RenderLeftWall
RenderBlockPositionEnd:
pop r5
pop r7
pop r6
pop r5
pop r4
pop r3
pop r2
pop r1
pop r0
rts
RenderRightWall:
push r0
push r1
push r2
push r3
push r4
push r6
push r7
; changes color
load r3, color1
load r4, pixel
add r3, r3, r4
store pixel, r3
load r1, posVictory
cmp r0, r1
jne RenderRightWallNoAlternateColor
load r3, colorVictory1
add r3, r3, r4
store pixel, r3
RenderRightWallNoAlternateColor:
; right side
load r0, offsetX
loadn r1, #50
add r2, r0, r1
store offsetX, r2
loadn r6, #squareSide
loadn r7, #square
call CopySquare
call ApplyOffset
call RenderSquare
store offsetX, r0 ; returns offset to normal
store pixel, r4 ; returns color to normal
pop r7
pop r6
pop r4
pop r3
pop r2
pop r1
pop r0
rts
RenderLeftWall:
push r0
push r1
push r2
push r3
push r4
push r6
push r7
; changes color
load r3, color1
load r4, pixel
add r3, r3, r4
store pixel, r3
load r1, posVictory
cmp r0, r1
jne RenderLeftWallNoAlternateColor
load r3, colorVictory1
add r3, r3, r4
store pixel, r3
RenderLeftWallNoAlternateColor:
; left side
load r0, offsetX
loadn r1, #50
sub r2, r0, r1
store offsetX, r2
loadn r6, #squareSide
loadn r7, #square
call CopySquareReversed
call ApplyOffset
call RenderSquare
store offsetX, r0 ; returns offset to normal
store pixel, r4 ; returns color to normal
pop r7
pop r6
pop r4
pop r3
pop r2
pop r1
pop r0
rts
RenderGround:
push r0
push r1
push r2
push r3
push r4
push r6
push r7
load r4, pixel
load r3, cbrown ; changes color
add r3, r3, r4
store pixel, r3
; ground
load r0, offsetX
loadn r1, #50
sub r2, r0, r1
store offsetX, r2
loadn r6, #squareBottom
loadn r7, #square
call CopySquare
call ApplyOffset
call RenderSquare
store offsetX, r0 ; returns offset to normal
store pixel, r4 ; returns color to normal
pop r7
pop r6
pop r4
pop r3
pop r2
pop r1
pop r0
rts
RenderCeiling:
push r0
push r1
push r2
push r3
push r4
push r5
push r6
push r7
load r4, pixel
load r3, cbrown ; changes color
add r3, r3, r4
store pixel, r3
; ceiling
load r0, offsetX
loadn r1, #50
sub r2, r0, r1
store offsetX, r2
load r5, offsetY
loadn r1, #40
store offsetY, r1
loadn r6, #squareBottom
loadn r7, #square
call CopySquareReversed
call ApplyOffset
call RenderSquare
store offsetX, r0 ; returns offset to normal
store offsetY, r5 ; returns offset to normal
store pixel, r4 ; returns color to normal
pop r7
pop r6
pop r5
pop r4
pop r3
pop r2
pop r1
pop r0
rts
RenderFront:
push r0
push r1
push r2
push r3
push r4
push r5
push r6
push r7
; changes color
load r3, color2
load r4, pixel
add r3, r3, r4
store pixel, r3
load r1, posVictory
cmp r0, r1
jne RenderFrontWallNoAlternateColor
load r3, colorVictory2
add r3, r3, r4
store pixel, r3
RenderFrontWallNoAlternateColor:
; front side
load r0, offsetX
loadn r1, #50
sub r2, r0, r1
store offsetX, r2
; front
loadn r6, #squareFront
loadn r7, #square
call CopySquareReversed
call ApplyOffset
call RenderSquare
store offsetX, r0 ; returns offset to normal
store pixel, r4 ; returns color to normal
pop r7
pop r6
pop r5
pop r4
pop r3
pop r2
pop r1
pop r0
rts
CopySquare: ; receives the static square at r6 and the square to render at r7
push r0
push r1
loadn r0, #12
LoopCopySquare:
loadi r1, r6
storei r7, r1
inc r6
inc r7
dec r0
jnz LoopCopySquare
pop r1
pop r0
rts
CopySquareReversed: ; receives the static square at r6 and the square to render at r7
push r0
push r1
push r2
push r3
loadn r2, #9
add r7, r7, r2
loadn r2, #6
loadn r3, #4
LoopOverCopySquareReversed:
loadn r0, #3
LoopCopySquareReversed:
loadi r1, r6
storei r7, r1
inc r6
inc r7
dec r0
jnz LoopCopySquareReversed
sub r7, r7, r2
dec r3