-
Notifications
You must be signed in to change notification settings - Fork 0
/
MAIN.asm
2004 lines (1732 loc) · 32.4 KB
/
MAIN.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
;;;;GROUP 29;;;;
;1942606 M. Rasit Ozdemir ;;;;
;2188423 Tahsincan Kose ;;;;
list P=18F8722
#include <p18f8722.inc>
config OSC = HSPLL, FCMEN = OFF, IESO = OFF, PWRT = OFF, BOREN = OFF, WDT = OFF, MCLRE = ON, LPT1OSC = OFF, LVP = OFF, XINST = OFF, DEBUG = OFF
v1 udata 0x21
v1
v2 udata 0x22
v2
v3 udata 0x23
v3
v4 udata 0x24
v4
v5 udata 0x25
v5
v6 udata 0x26
v6
i udata 0x27
i
fruit udata 0x28
fruit
live udata 0x29
live
gameLevel udata 0x2a
gameLevel
v7 udata 0x2b
v7
v8 udata 0x2c
v8
wSaved udata 0x2d
wSaved
pcLathSaved udata 0x2e
pcLatchSaved
statusSaved udata 0x2f
statusSaved
counter udata 0x30
counter
counter2 udata 0x35
counter2
direction udata 0x31
direction
user_location udata 0x32
user_location
blink_state udata 0x33
blink_state
movement_flag udata 0x34
movement_flag
blink_level udata 0x36
blink_level
blink_counter udata 0x37
blink_counter
movement_counter udata 0x38
movement_counter
hit_flag udata 0x39
hit_flag
direction_change udata 0x3a
direction_change
portb_shadow udata 0x3b
portb_shadow
fruitTimeCounter udata 0x3c
fruitTimeCounter
fruit_flag udata 0x3d
fruit_flag
seed udata 0x3e
seed
rowIndex udata 0x3f
rowIndex
columnIndex udata 0x40
columnIndex
score0 udata 0x41
score0
score1 udata 0x42
score1
first_bit udata 0x43
first_bit
fruit_location udata 0x44
fruit_location
fruit_kill_counter udata 0x45
fruit_kill_counter
fruit_kill_flag udata 0x46
fruit_kill_flag
sFlag udata 0x47
sFlag
actualFruit udata 0x48
actualFruit
wSaved2 udata 0x49
wSaved2
pcLathSaved2 udata 0x4a
pcLatchSaved2
statusSaved2 udata 0x4b
statusSaved2
fruit_open udata 0x4c
fruit_open
org 0x00
goto init
org 0x08
call saveRegisters2
btfsc INTCON,2
goto timerISR
call restore_registers2
retfie
org 0x18
call saveRegisters
btfsc INTCON,0
goto portbISR
call restore_registers
retfie
init:
clrf LATA
clrf TRISA
clrf PORTA
clrf LATB
clrf TRISB
clrf PORTB
clrf LATC
clrf TRISC
clrf PORTC
clrf LATD
clrf TRISD
clrf PORTD
clrf LATE
clrf TRISE
clrf PORTE
clrf LATF
clrf TRISF
clrf PORTF
clrf LATG
clrf TRISG
clrf PORTG
MOVLW 0x0F ; CONFIGURE A/D TO DIGITAL.
MOVWF ADCON1
movlw 0x10
movwf TRISA
movlw 0x3f
movwf TRISC
movlw 0x00
movwf TRISH
movwf TRISJ
movlw 0x05
movwf v1
movlw 0x00
movwf v2
movlw 0x01
movwf v3
movlw 0x00
movwf v4
movlw 0x0f
movwf fruit
movlw 0x03
movwf live
movlw 0x03
movwf v5
movwf gameLevel
movwf v7
movlw 0x00
movwf v6
movwf v8
movwf blink_counter
movwf movement_counter
movwf movement_flag
movwf hit_flag
movwf direction_change
movwf fruitTimeCounter
movwf fruit_flag
movwf fruit_kill_counter
movwf fruit_kill_flag
movlw 0XFF
movwf sFlag
lfsr FSR0, 100h ;FSR0 is tail
lfsr FSR1, 100h ;FSR1 is head
main:
call phase1
call phase2
call phase3
goto init
phase3
movlw 0x10
movwf TRISA
clrf INTCON
clrf TMR0
clrf PORTA
clrf PORTC
clrf PORTD
clrf PORTE
clrf PORTF
movff score0,v1
movff score1, v3
movff live, v5
movlw 0xAA
movf live, f
btfsc STATUS,Z
movwf sFlag
movff sFlag, v7
phase3cont
call sevenSeg
btfsc PORTA, 4
goto releasePortA
goto phase3
releasePortA
btfss PORTA,4
return
goto releasePortA
phase2
movff v1, v5
movff v2, v6
movff v3, v7
movff v4, v8
movlw 0x00
movwf TRISA
movwf TRISC
movwf TRISD
movwf TRISE
movwf TRISF
movwf v1
movwf v3
movwf v2
movwf v4
movwf counter
movwf counter2
movwf user_location
movwf score0
movwf score1
movwf fruit_open
movlw 0xad
movwf seed
movff fruit, actualFruit
movf gameLevel, W
sublw 0x00
btfsc STATUS,Z
call blink_level_25
movf gameLevel, W
sublw 0x01
btfsc STATUS,Z
call blink_level_50
movf gameLevel, W
sublw 0x02
btfsc STATUS,Z
call blink_level_100
movf gameLevel, W
sublw 0x03
btfsc STATUS, Z
call blink_level_200
call phase2_initialize
phase2cont
call porta_initialize
call sevenSeg
call user_blink
btfsc movement_flag,0
call movement_function
btfsc fruit_flag,0
call fruit_spawn
movf fruit,f
btfsc STATUS, Z
return
movf live,f
btfsc STATUS, Z
return
goto phase2cont
fruit_spawn
clrf rowIndex
clrf columnIndex
clrf first_bit
bcf fruit_flag,0
btfsc seed,7
bsf first_bit,0
rlncf seed, f
btfsc first_bit,0
bsf seed,0
btfsc first_bit,0
call seedXor
movlw 0x02
btfsc seed,7
addwf rowIndex,f
btfsc seed,6
incf rowIndex
btfsc seed, 1
addwf columnIndex,f
btfsc seed,0
incf columnIndex
call fruit_encoder
movf fruit_location, w
movwf POSTINC1
movf actualFruit, W
sublw 0x00
btfss STATUS, Z
call fruit_adder
btfsc fruit_kill_flag,0
call fruit_killer
return
fruit_adder
call fruit_location_encoder
decf actualFruit
return
fruit_killer
clrf fruit_open
movff INDF0, fruit_location
call fruit_location_encoder_clear
clrf POSTINC0
movf user_location, W
subwf fruit_location, W
btfsc STATUS, Z
bsf fruit_open,0
btfsc fruit_open,0
call arithmetic0_phase2
return
fruit_encoder
movlw 0x00
addwf columnIndex, W
addwf columnIndex, W
addwf columnIndex, W
addwf columnIndex, W
addwf columnIndex, W
addwf rowIndex, W
movwf fruit_location
return
seedXor
movlw 0xb8
xorwf seed,f
return
direction_control
btfsc PORTB, 4
call set_direction_east
btfsc PORTB, 5
call set_direction_west
btfsc PORTB, 6
call set_direction_north
btfsc PORTB, 7
call set_direction_south
bcf direction_change,0
bcf hit_flag,0
return
mapDecoder
movlw 0x00
cpfseq user_location
goto mapDecoder1
btfsc PORTC, 0
call score0_increment
return
mapDecoder1
movlw 0x01
cpfseq user_location
goto mapDecoder2
btfsc PORTC, 1
call score0_increment
return
mapDecoder2
movlw 0x02
cpfseq user_location
goto mapDecoder3
btfsc PORTC, 2
call score0_increment
return
mapDecoder3
movlw 0x03
cpfseq user_location
goto mapDecoder4
btfsc PORTC, 3
call score0_increment
return
mapDecoder4
movlw 0x05
cpfseq user_location
goto mapDecoder5
btfsc PORTD, 0
call score0_increment
return
mapDecoder5
movlw 0x06
cpfseq user_location
goto mapDecoder6
btfsc PORTD, 1
call score0_increment
return
mapDecoder6
movlw 0x07
cpfseq user_location
goto mapDecoder7
btfsc PORTD, 2
call score0_increment
return
mapDecoder7
movlw 0x08
cpfseq user_location
goto mapDecoder8
btfsc PORTD, 3
call score0_increment
return
mapDecoder8
movlw 0x0a
cpfseq user_location
goto mapDecoder9
btfsc PORTE, 0
call score0_increment
return
mapDecoder9
movlw 0x0b
cpfseq user_location
goto mapDecoder10
btfsc PORTE, 1
call score0_increment
return
mapDecoder10
movlw 0x0c
cpfseq user_location
goto mapDecoder11
btfsc PORTE, 2
call score0_increment
return
mapDecoder11
movlw 0x0d
cpfseq user_location
goto mapDecoder12
btfsc PORTE, 3
call score0_increment
return
mapDecoder12
movlw 0x0f
cpfseq user_location
goto mapDecoder13
btfsc PORTF, 0
call score0_increment
return
mapDecoder13
movlw 0x10
cpfseq user_location
goto mapDecoder14
btfsc PORTF, 1
call score0_increment
return
mapDecoder14
movlw 0x11
cpfseq user_location
goto mapDecoder15
btfsc PORTF, 2
call score0_increment
return
mapDecoder15
btfsc PORTF, 3
call score0_increment
return
movement_function
bcf movement_flag,0
movlw 0x03
cpfseq direction ; if direction==south :
goto movement_function2
movlw 0x03
cpfseq user_location
goto s1
bsf hit_flag,0
decf live
return
s1
movlw 0x08
cpfseq user_location
goto s2
bsf hit_flag,0
decf live
return
s2
movlw d'13'
cpfseq user_location
goto s3
bsf hit_flag,0
decf live
return
s3
movlw d'18'
cpfseq user_location
goto s4
bsf hit_flag,0
decf live
return
s4
call user_location_encoder_clear
incf user_location
call mapDecoder
return
movement_function2
movlw 0x02
cpfseq direction ; if direction==north :
goto movement_function3
movlw 0x00
cpfseq user_location
goto n1
bsf hit_flag,0
decf live
return
n1
movlw 0x05
cpfseq user_location
goto n2
bsf hit_flag,0
decf live
return
n2
movlw d'10'
cpfseq user_location
goto n3
bsf hit_flag,0
decf live
return
n3
movlw d'15'
cpfseq user_location
goto n4
bsf hit_flag,0
decf live
return
n4
call user_location_encoder_clear
decf user_location
call mapDecoder
return
movement_function3
movlw 0x01
cpfseq direction ; if direction==west :
goto movement_function4
movlw 0x00
cpfseq user_location
goto w1
bsf hit_flag,0
decf live
return
w1
movlw 0x01
cpfseq user_location
goto w2
bsf hit_flag,0
decf live
return
w2
movlw d'2'
cpfseq user_location
goto w3
bsf hit_flag,0
decf live
return
w3
movlw d'3'
cpfseq user_location
goto w4
bsf hit_flag,0
decf live
return
w4
call user_location_encoder_clear
movlw 0x05
subwf user_location, f
call mapDecoder
return
movement_function4
movlw 0x00
cpfseq direction ; if direction==east :
return
movlw d'15'
cpfseq user_location
goto e1
bsf hit_flag,0
decf live
return
e1
movlw d'16'
cpfseq user_location
goto e2
bsf hit_flag,0
decf live
return
e2
movlw d'17'
cpfseq user_location
goto e3
bsf hit_flag,0
decf live
return
e3
movlw d'18'
cpfseq user_location
goto e4
bsf hit_flag,0
decf live
return
e4
call user_location_encoder_clear
movlw 0x05
addwf user_location, f
call mapDecoder
return
user_blink
btfsc blink_state,0
call user_location_encoder
btfss blink_state,0
call user_location_encoder_clear
return
blink_level_25
movlw d'25'
movwf blink_level
return
blink_level_50
movlw d'50'
movwf blink_level
return
blink_level_100
movlw d'100'
movwf blink_level
return
blink_level_200
movlw d'200'
movwf blink_level
return
user_location_encoder_clear
movlw 0x00
cpfseq user_location
goto user_location_encoder_clear1
bcf PORTC, 0
return
user_location_encoder_clear1
movlw 0x01
cpfseq user_location
goto user_location_encoder_clear2
bcf PORTC, 1
return
user_location_encoder_clear2
movlw 0x02
cpfseq user_location
goto user_location_encoder_clear3
bcf PORTC, 2
return
user_location_encoder_clear3
movlw 0x03
cpfseq user_location
goto user_location_encoder_clear5
bcf PORTC, 3
return
user_location_encoder_clear5
movlw 0x05
cpfseq user_location
goto user_location_encoder_clear6
bcf PORTD, 0
return
user_location_encoder_clear6
movlw 0x06
cpfseq user_location
goto user_location_encoder_clear7
bcf PORTD, 1
return
user_location_encoder_clear7
movlw 0x07
cpfseq user_location
goto user_location_encoder_clear8
bcf PORTD, 2
return
user_location_encoder_clear8
movlw 0x08
cpfseq user_location
goto user_location_encoder_clear10
bcf PORTD, 3
return
user_location_encoder_clear10
movlw 0x0a
cpfseq user_location
goto user_location_encoder_clear11
bcf PORTE, 0
return
user_location_encoder_clear11
movlw 0x0b
cpfseq user_location
goto user_location_encoder_clear12
bcf PORTE, 1
return
user_location_encoder_clear12
movlw 0x0c
cpfseq user_location
goto user_location_encoder_clear13
bcf PORTE, 2
return
user_location_encoder_clear13
movlw 0x0d
cpfseq user_location
goto user_location_encoder_clear15
bcf PORTE, 3
return
user_location_encoder_clear15
movlw 0x0f
cpfseq user_location
goto user_location_encoder_clear16
bcf PORTF, 0
return
user_location_encoder_clear16
movlw 0x10
cpfseq user_location
goto user_location_encoder_clear17
bcf PORTF, 1
return
user_location_encoder_clear17
movlw 0x11
cpfseq user_location
goto user_location_encoder_clear18
bcf PORTF, 2
return
user_location_encoder_clear18
bcf PORTF, 3
return
user_location_encoder
movlw 0x00
cpfseq user_location
goto user_location_encoder1
bsf PORTC, 0
return
user_location_encoder1
movlw 0x01
cpfseq user_location
goto user_location_encoder2
bsf PORTC, 1
return
user_location_encoder2
movlw 0x02
cpfseq user_location
goto user_location_encoder3
bsf PORTC, 2
return
user_location_encoder3
movlw 0x03
cpfseq user_location
goto user_location_encoder5
bsf PORTC, 3
return
user_location_encoder5
movlw 0x05
cpfseq user_location
goto user_location_encoder6
bsf PORTD, 0
return
user_location_encoder6
movlw 0x06
cpfseq user_location
goto user_location_encoder7
bsf PORTD, 1
return
user_location_encoder7
movlw 0x07
cpfseq user_location
goto user_location_encoder8
bsf PORTD, 2
return
user_location_encoder8
movlw 0x08
cpfseq user_location
goto user_location_encoder10
bsf PORTD, 3
return
user_location_encoder10
movlw 0x0a
cpfseq user_location
goto user_location_encoder11
bsf PORTE, 0
return
user_location_encoder11
movlw 0x0b
cpfseq user_location
goto user_location_encoder12
bsf PORTE, 1
return
user_location_encoder12
movlw 0x0c
cpfseq user_location
goto user_location_encoder13
bsf PORTE, 2
return
user_location_encoder13
movlw 0x0d
cpfseq user_location
goto user_location_encoder15
bsf PORTE, 3
return
user_location_encoder15
movlw 0x0f
cpfseq user_location
goto user_location_encoder16
bsf PORTF, 0
return
user_location_encoder16
movlw 0x10
cpfseq user_location
goto user_location_encoder17
bsf PORTF, 1
return
user_location_encoder17
movlw 0x11
cpfseq user_location
goto user_location_encoder18
bsf PORTF, 2
return
user_location_encoder18
bsf PORTF, 3
return
fruit_location_encoder_clear
movlw 0x00
cpfseq fruit_location
goto fruit_location_encoder_clear1
btfsc PORTC,0
bsf fruit_open,0
bcf PORTC, 0
return
fruit_location_encoder_clear1
movlw 0x01
cpfseq fruit_location
goto fruit_location_encoder_clear2
btfsc PORTC,1
bsf fruit_open,0
bcf PORTC, 1
return
fruit_location_encoder_clear2
movlw 0x02
cpfseq fruit_location
goto fruit_location_encoder_clear3
btfsc PORTC,2
bsf fruit_open,0
bcf PORTC, 2
return
fruit_location_encoder_clear3
movlw 0x03
cpfseq fruit_location
goto fruit_location_encoder_clear5
btfsc PORTC,3
bsf fruit_open,0
bcf PORTC, 3
return
fruit_location_encoder_clear5
movlw 0x05
cpfseq fruit_location
goto fruit_location_encoder_clear6
btfsc PORTD,0
bsf fruit_open,0
bcf PORTD, 0
return
fruit_location_encoder_clear6
movlw 0x06
cpfseq fruit_location
goto fruit_location_encoder_clear7
btfsc PORTD,1
bsf fruit_open,0
bcf PORTD, 1
return
fruit_location_encoder_clear7
movlw 0x07
cpfseq fruit_location
goto fruit_location_encoder_clear8
btfsc PORTD,2
bsf fruit_open,0
bcf PORTD, 2
return