-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnibbles.asm
More file actions
1632 lines (1383 loc) · 78.6 KB
/
nibbles.asm
File metadata and controls
1632 lines (1383 loc) · 78.6 KB
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
;=============================================================================
; File: nibbles.asm
; Author: Joshua Bellamy-Henn
; © 2015 Psidox
;
; Description: Remake of Nibbles game for the Motorola 68000.
;
; How to Play: Use W,S,A,D keys or (keypad 8,4,5,6) to change direction, objective
; is to grow the snake as long as possible by eating food placed in
; random locations around the arena. Don't run into your own trail
; or into wall you will die!!!
;
;=============================================================================
CHAR_CR EQU $0D
DUART EQU $600000
MR1A EQU 1
SRA EQU 3
RBA EQU 7 ; Receiver buffer register (data in)
TBA EQU 7 ; Transmitter buffer register (data out)
RxRDY EQU 0 ; Reciver ready bit
TxRDY EQU 2 ; Transmitter ready bit
DIR_LEFT EQU 0
DIR_RIGHT EQU 1
DIR_UP EQU 2
DIR_DOWN EQU 3
WALL_LIFE EQU $FFFE ; Wall Special Time
FOOD_LIFE EQU $FFFF ; Food Special Time
FOOD_GROWTH EQU 15 ; How long snake will grow after eating food
SNK_START_LIFE EQU 5 ; Life of single segment of the snake
SNK_SPEED_EASY EQU $0000E000
SNK_SPEED_MEDIUM EQU $0000AFFF
SNK_SPEED_HARD EQU $00007FFF
SNK_SPEED_INSANE EQU $00004000
SNK_SCR_SIZE EQU 1716 ; x*y = 78*22
ARENA_X EQU 78
ARENA_Y EQU 23
START_X EQU 38
START_Y EQU 10
ORG $4000
NIBBLES ;initialize values that retain value between games
MOVE.B #1,DIFFICULTY
intro ;initialize values that will reset at start of each game
MOVE.B #0,LEVEL ; player starts at level 0 (aka level 1) initially
MOVE.B #0,SCORE ; Reset Score
MOVE.B #0,FOOD_NUM ; Reset Score
MOVE.B #5,LIVES ; Set starting lives
MOVEA.L #STR_SPLASH_SCR,A1 ; draw splash screen
BSR _DISPSTR
BSR _SELECT_DIFF ; Let user select difficulty
loadlevel
;initialize values that will reset at start of each level / life
MOVE.W #SNK_START_LIFE, SNK_LIFE
MOVE.B #START_X,POS_X ; Set starting X
MOVE.B #START_Y,POS_Y ; Set starting Y
MOVE.L #0,TIMER ; Init Timer to 0
MOVE.W #0,RAND_MEM ; Random Memory Location
MOVE.B #4,DIRECTION ; No direction
MOVE.B #4,LAST_DIR ; No last direction
MOVE.B #0,MOVING
MOVE.L #0,TIMER
MOVE.B #0,FOOD_AVAIL
MOVE.B #0,DELAY_DECAY
MOVEA.L #STR_ARENA_SCR,A1 ; draw arena
BSR _DISPSTR
BSR _CLEARMEM ; Clear Arena Memory
CLR.L D1
MOVE.B LEVEL, D1 ;
CMP.B #22,D1 ; Check if player finished the game
BEQ gamecompletescr ;
MULU #SNK_SCR_SIZE,D1 ;offset=level*SNK_SCR_SIZE
ADD.L #STR_LEVEL1,D1 ;level=STR_LEVEL1+offset
MOVEA.L D1,A2
BSR _LOADMEM ; Load Level 1
BSR _DISPSCORE ; Display Score
MOVE.B LEVEL, D4 ; Display Level
ADDI.B #1,D4
MOVE.B #45,D1
MOVE.B #24,D2
BSR _GOTOXY
MOVE.L #STR_COL_YELLOW,A1 ; Set color
BSR _DISPSTR
BSR _DISPNUM10
MOVE.B LIVES, D4 ; Display Lives
MOVE.B #29,D1
MOVE.B #24,D2
BSR _GOTOXY
MOVE.L #STR_COL_YELLOW,A1 ; Set color
BSR _DISPSTR
BSR _DISPNUM10
MOVE.B POS_X,D1
MOVE.B POS_Y,D2
ADDI.B #1,D1
ADDI.B #1,D2
BSR _GOTOXY ; goto worm starting point
start
TRAP #15 ; check if we have a character waiting for us
DC.W 4
BEQ movesnk; if not, move on
BSR _SGETCH ; else, get the character
; check for WASD
CMP.B #'w',D0 ; check if up arrow was pressed
BEQ key_up
CMP.B #'s',D0 ; check if down arrow was pressed
BEQ key_down
CMP.B #'a',D0 ; check if left arrow was pressed
BEQ key_left
CMP.B #'d',D0 ; check if right arrow was pressed
BEQ key_right
; check for KEYPAD
CMP.B #'8',D0 ; check if up arrow was pressed
BEQ key_up
CMP.B #'5',D0 ; check if down arrow was pressed
BEQ key_down
CMP.B #'4',D0 ; check if left arrow was pressed
BEQ key_left
CMP.B #'6',D0 ; check if right arrow was pressed
BEQ key_right
BRA movesnk; if no key was pressed that means anything move on
key_up
CMP.B #DIR_DOWN, LAST_DIR ; don't let the snake move in oppose direction,
BEQ movesnk ; since this = instant death
MOVE.B #1, MOVING ; indicate we're moving if we haven't already
MOVE.B #DIR_UP, DIRECTION ; set movement direction up
BRA movesnk
key_down
CMP.B #DIR_UP, LAST_DIR ; don't let the snake move in oppose direction,
BEQ movesnk ; since this = instant death
MOVE.B #1, MOVING ; indicate we're moving if we haven't already
MOVE.B #DIR_DOWN, DIRECTION ; set movement direction down
BRA movesnk
key_left
CMP.B #DIR_RIGHT, LAST_DIR ; don't let the snake move in oppose direction,
BEQ movesnk ; since this = instant death
MOVE.B #1, MOVING ; indicate we're moving if we haven't already
MOVE.B #DIR_LEFT, DIRECTION ; set movement direction left
BRA movesnk
key_right
CMP.B #DIR_LEFT, LAST_DIR ; don't let the snake move in oppose direction,
BEQ movesnk ; since this = instant death
MOVE.B #1, MOVING ; indicate we're moving if we haven't already
MOVE.B #DIR_RIGHT, DIRECTION ; set movement direction right
BRA movesnk
movesnk CMP.B #0, MOVING ; check if snake is moving
BEQ incrand ; if not, only thing to do is increase random counter, and repeat
MOVE.L TIMER,D0
ADDI.L #1, D0
MOVE.L D0, TIMER
CMP.L SNK_SPEED,D0 ; Compare Timer with movement speed
BNE incrand ; if timer is not up, restart
; else, timer is up, move the snake
MOVE.B DIRECTION, LAST_DIR
CMP.B #DIR_UP, DIRECTION
BEQ mv_up
CMP.B #DIR_DOWN, DIRECTION
BEQ mv_down
CMP.B #DIR_LEFT, DIRECTION
BEQ mv_left
CMP.B #DIR_RIGHT, DIRECTION
BEQ mv_right
mv_up
SUBI.B #1, POS_Y ; move snake up
MOVE.L #0, TIMER ; reset timer
BRA draw_snk
mv_down
ADDI.B #1, POS_Y ; move snake down
MOVE.L #0, TIMER ; reset timer
BRA draw_snk
mv_left
SUBI.B #1, POS_X ; move snake left
MOVE.L #0, TIMER ; reset timer
BRA draw_snk
mv_right
ADDI.B #1, POS_X ; move snake right
MOVE.L #0, TIMER ; reset timer
BRA draw_snk
draw_snk
CMP.B #$FF,POS_X ; check if we have colided with the wall
BEQ gameover
CMP.B #78,POS_X
BEQ gameover
CMP.B #$FF,POS_Y
BEQ gameover
CMP.B #23,POS_Y
BEQ gameover
BSR _DECAYSNK ; decay snake
BSR _DRAWSNK ; draw new snake location
CMP.B #0, FOOD_AVAIL
BEQ setfood ; if not, set food in free spot
incrand
BSR _INCRAND ; inc random x,y
BRA start ; While game is in session
setfood
BSR _DRAWFOOD
CMP.B #$0A,FOOD_NUM ;check what the food number is
BNE start ;if less than 9, continue as normal
;else player just leveled up
MOVE.B #0,FOOD_NUM ;reset food num
ADDI.B #1,LEVEL ;increase level
BRA loadlevel ;load new level
gameover
CMP.B #0,LIVES ;check to see if we have any lives left
BEQ gameoverscr ;if not, goto game over screen
SUBI.B #1,LIVES ;else, subtract 1 from lives and restart current level
BRA loadlevel
gameoverscr
MOVE #STR_GAME_OVER_SCR,A1
BSR _DISPSTR
BSR _SELECT_GAMEOVER ; game over menu
BRA intro ; loop to start if user selected play again
gamecompletescr
MOVE #STR_GAME_COMPLETE_SCR,A1
BSR _DISPSTR
TRAP #11 ; end game
DC.W 0
; << End of Main >>
***************************************************************
; Function _INCRND
; Purpose Increment Random X,Y position
***************************************************************
_INCRAND
ADDI.W #1,RAND_MEM
CMP.W #SNK_SCR_SIZE,RAND_MEM
BNE incdone
MOVE.W #$0,RAND_MEM
incdone
RTS
***************************************************************
; Function _DRAWFOOD
; Purpose Draw new food segment on the screen and in memory
***************************************************************
_DRAWFOOD
MOVEM.L D0-D2/A0-A1,-(SP)
MOVE.L #SNK_SCR,A0 ; load base address
findfoodspot
BSR _INCRAND
MOVE.W RAND_MEM,D2
MOVE.W RAND_MEM,D0
MULU #2,D0
CMP.W #0,$00(A0,D0.W) ; check to see if this spot is clear
BNE findfoodspot ; if not, find a new spot
DIVU #ARENA_X,D2 ; y = offset/x_max
MOVE.L D2,D1 ; x = remainder
LSR.L #8,D1
LSR.L #8,D1
ADDI.B #1,D1
ADDI.B #1,D2
BSR _GOTOXY ; goto snake segment
MOVE.L #STR_COL_YELLOW,A1
BSR _DISPSTR
MOVE.B FOOD_NUM,D0
ADDI.B #$30,D0
BSR _SPUTCH
BSR _MARKFOOD ; mark current position in memory
MOVE.B #1,FOOD_AVAIL ; indicate food is set
MOVEM.L (SP)+,D0-D2/A0-A1
RTS
***************************************************************
; Function _DRAWSNK
; Purpose Draw new snake segment on the screen and in memory
***************************************************************
_DRAWSNK
MOVEM.L D0-D1/A1,-(SP)
MOVE.B POS_X,D1
MOVE.B POS_Y,D2
ADDI.B #1,D1
ADDI.B #1,D2
BSR _GOTOXY ; goto snake segment
MOVE.L #STR_SNK_SEG,A1
BSR _DISPSTR
MOVE.L #STR_REV,A1
BSR _DISPSTR ; go back a char to hide cursor
BSR _MARKSNK ; mark current position in memory
MOVEM.L (SP)+,D0-D1/A1
RTS
***************************************************************
; Function _CLRSNK
; Purpose Clear snake segment on the screen
***************************************************************
_CLRSNK
MOVEM.L D0-D3,-(SP)
ADDI.B #1,D1
ADDI.B #1,D2
BSR _GOTOXY ; goto snake segment
MOVE.B #$20,D0 ; $20 = space
BSR _SPUTCH ; clear snake tile
MOVEM.L (SP)+,D0-D3
RTS
***************************************************************
; Function _MARKFOOD
; Purpose Marks food position in memory
***************************************************************
_MARKFOOD
MOVEM.L D0/A0,-(SP)
MOVE.L #SNK_SCR,A0 ; load base address
MOVE.W RAND_MEM,D0 ; load random memory offset
MULU #2,D0 ; x2 for word size
MOVE.W #FOOD_LIFE,$00(A0,D0.W) ; mark spot = base+offset <- food
MOVEM.L (SP)+,D0/A0
RTS
***************************************************************
; Function _MARKSNK
; Purpose Marks snake position in memory
; memory location = base + x + (y*78)
; memory location = SNK_SCR + POS_X + (POS_Y*78)
***************************************************************
_MARKSNK
MOVEM.L D0-D2/A0,-(SP)
MOVE.L #SNK_SCR,A0 ; load base address
CLR.L D0
CLR.L D1
MOVE.B POS_Y,D0
MULU #ARENA_X,D0 ; offset = y*78
MOVE.B POS_X,D1
ADD.W D1,D0 ; offset = offset + x
MULU #2,D0 ; x2 for word size
MOVE.W $00(A0,D0.W),D2
CMP.W #FOOD_LIFE,D2 ; check if we're moving onto food
BEQ markfood ; if not set, snake segement life
CMP.W #0,D2 ; check if we're moving onto snake tail or a wall
BEQ marksnk ; if not, mark snake here
BRA gameover ; else, we ran into tail. game over
markfood
ADDI.B #FOOD_GROWTH,DELAY_DECAY ; else delay snake decay by DELAY_DECAY (aka eaten food)
ADDI.B #1,SCORE
ADD.B #1,FOOD_NUM ; add one to food number
MOVE.B #0,FOOD_AVAIL ; set no food available
BSR _DISPSCORE ; update score
marksnk
CMP.B #0,DELAY_DECAY ; check to see if snake is growing
BEQ marknog ; if not, set normal life
ADD.W #1,SNK_LIFE
MOVE.W SNK_LIFE,D1 ; add 1 to snake life
MOVE.W D1,$00(A0,D0.W) ; mark spot = base+offset <- snake life
MOVEM.L (SP)+,D0-D2/A0
RTS
marknog MOVE.W SNK_LIFE,$00(A0,D0.W) ; mark spot = base+offset <- snake life
MOVEM.L (SP)+,D0-D2/A0
RTS
***************************************************************
; Function _DECAYSNK
; Purpose Decay entire snake in memory
***************************************************************
_DECAYSNK
MOVEM.L D0-D5/A0,-(SP)
CMP.B #0,DELAY_DECAY ; Check if snake is growing
BNE decaydelay ; if so, don't decay
MOVE.L #SNK_SCR,A0 ; load base address
CLR.L D0
CLR.L D1
MOVE.L #0,D1 ; current x (relative memory array)
MOVE.L #0,D2 ; current y (relative memory array)
nextseg
MOVE.L D2,D0 ; y -> d0
MULU #ARENA_X,D0 ; offset = y*78
ADD.W D1,D0 ; offset = offset + x
MOVE.W D0,D5 ; calc mem location
MULU #2,D5 ; x2 for word size
CMP.W #SNK_SCR_SIZE,D0 ; check to see if we're done
BNE checkseg
BRA decaydelay
checkseg
MOVE.W $00(A0,D5.W),D4 ; move current life of segment x,y into D4
CMP.W #FOOD_LIFE,D4 ; check if food exists here
BEQ incseg ; it does, don't decay it
CMP.W #0,D4 ; if snake segment exists here
BNE decayseg ; decay segment here
BRA incseg ; else no segment here, jump to inc segment code
decayseg
SUBI.W #1,D4 ; Decay snake life by 1
MOVE.W D4,$00(A0,D5.W) ; Update segment in memory
CMP.W #0,D4 ; check if life turned to 0
BNE incseg ; if not 0 our segment still alive, jump to inc segment code
BSR _CLRSNK ; else segment just died, update the screen (delete segment)
incseg
ADDI.B #1,D1 ; add 1 to x
CMP.B #ARENA_X,D1 ; check to see if x is greater than max length (78)
BEQ incy
BRA nextseg ; if not start checking next segment
incy MOVE.B #0,D1 ; x = 1
ADDI.B #1,D2 ; add 1 to y
BRA nextseg ; check next segment
decaydelay
CMP.B #0,DELAY_DECAY
BEQ donedecay
SUBI.B #1,DELAY_DECAY
CMP.B #0,DELAY_DECAY ; we have just ended a decay period
BNE donedecay
donedecay
MOVEM.L (SP)+,D0-D5/A0
RTS
***************************************************************
; Function _LOADMEM
; Purpose Clear a bitmap to the snake space in memory (load level)
; Param A2 - Bitmap in memory
***************************************************************
_LOADMEM
MOVEM.L D0-D2/A0,-(SP)
MOVE.L #0,D0
MOVE.L #SNK_SCR,A0 ; load base address
loadnextmem
MOVE.W D0,D1
MULU #2,D1 ; x2 for word size
MOVE.B $00(A2,D0.W),D2
CMP.B #'w',D2 ;check if segment is a wall
BEQ loadwallseg
BRA loadinc
loadwallseg
MOVE.W #WALL_LIFE,$00(A0,D1.W) ; move current life of segment x,y into D4
MOVE.L D0,D2
DIVU #ARENA_X,D2 ; y = offset/x_max
MOVE.L D2,D1 ; x = remainder
LSR.L #8,D1
LSR.L #8,D1
ADDI.B #1,D1
ADDI.B #1,D2
BSR _GOTOXY ; goto snake segment
MOVE.L #STR_WALL,A1
BSR _DISPSTR
loadinc
ADDI.W #1,D0
CMP.W #SNK_SCR_SIZE,D0
BNE loadnextmem
MOVEM.L (SP)+,D0-D2/A0
RTS
***************************************************************
; Function _CLEARMEM
; Purpose Clear entire snake space in memory
***************************************************************
_CLEARMEM
MOVEM.L D0-D1/A0,-(SP)
MOVE.L #0,D0
MOVE.L #SNK_SCR,A0 ; load base address
clearnextmem
MOVE.W D0,D1
MULU #2,D1 ; x2 for word size
MOVE.W #$0000,$00(A0,D1.W) ; move current life of segment x,y into D4
ADDI.W #1,D0
CMP.W #SNK_SCR_SIZE,D0
BNE clearnextmem
MOVEM.L (SP)+,D0-D1/A0
RTS
***************************************************************
; Function _DISPSCORE
; Purpose Display a score to the screen
***************************************************************
_DISPSCORE
MOVEM.L D0-D4/A1,-(SP)
MOVE #13,D1 ; x Goto word "Score:" on the screen
MOVE #24,D2 ; y
BSR _GOTOXY
MOVE.L #STR_COL_YELLOW,A1
BSR _DISPSTR
MOVE.B SCORE,D4
BSR _DISPNUM10
MOVEM.L (SP)+,D0-D4/A1
RTS
***************************************************************
; Function _DISPNUM10
; Purpose Display a number to the screen in BASE 10
***************************************************************
_DISPNUM10
MOVEM.L D0-D4/A1,-(SP)
CLR.B D3
CMP.B #0,D4 ; if it's zero to start with, we don't need to count
BEQ scoreskipten
scorecnt ; count by 10 algorithm
ADDI.B #1,D3 ; add 1 to base 10 counter
SUBI.B #1,D4 ; decrement actual counter
MOVE.B D3,D0
ANDI.B #$0F,D0 ; check if we have 10 in 1's column
CMP.B #$0A,D0
BEQ scoreaddten ; if so, add 1 to 10's column, clear 1's
BRA scoredonecnt ; else see if we're done
scoreaddten
ADDI.B #$10,D3 ; Add 1 to tens
ANDI.B #$F0,D3 ; Clears ones
scoredonecnt
CMP.B #0,D4 ; if not done,
BNE scorecnt ; start count algoritm again
MOVE.B D3,D0 ; display 10's digit
LSR.B #4,D0
CMP.B #$0,D0 ; if 10's digit is a 0, don't output it
BEQ scoreskipten
ADDI.B #$30,D0
BSR _SPUTCH
scoreskipten
MOVE.B D3,D0 ; display 1's digit
ANDI #$0F,D0
ADDI.B #$30,D0
BSR _SPUTCH
MOVEM.L (SP)+,D0-D4/A1
RTS
***************************************************************
; Function _DISPSTR
; Purpose Display a string in memory to the screen
***************************************************************
_DISPSTR
MOVEM.L D0,-(SP)
nextch
MOVE.B (A1)+,D0 ; get character from pointer
CMP.B #$0,D0 ; see if it's null
BEQ donech ; if so, we're done
BSR _SPUTCH ; else display it
BRA nextch
donech
MOVEM.L (SP)+,D0
RTS
***************************************************************
; Function _GOTOXY
; Purpose Goto position on the screen specified by D1(x),D2(y)
***************************************************************
_GOTOXY
MOVEM.L D0-D4,-(SP)
MOVE.B D2,D4 ; setup y for count
CLR.W D3
MOVEA.L #STR_ESC,A1
BSR _DISPSTR ; send ANSI escape sequence
BRA gotocnt
gotocnty
MOVE.B #$FF,D2
MOVE.B D1,D4 ; setup x for count
CLR.W D3
MOVE.B #';',D0
BSR _SPUTCH
gotocnt ; count by 10 algorithm
ADDI.B #1,D3 ; add 1 to base 10 counter
SUBI.B #1,D4 ; decrement actual counter
MOVE.B D3,D0
ANDI.B #$0F,D0 ; check if we have 10 in 1's column
CMP.B #$0A,D0
BEQ gotoaddten ; if so, add 1 to 10's column, clear 1's
BRA gotodonecnt ; else see if we're done
gotoaddten
ADDI.B #$10,D3 ; Add 1 to tens
ANDI.B #$F0,D3 ; Clears ones
gotodonecnt
CMP.B #0,D4 ; if not done,
BNE gotocnt ; start count algoritm again
MOVE.B D3,D0 ; display 10's digit
LSR.B #4,D0
CMP #$0,D0 ; if 10's digit is a 0, don't output it
BEQ gotoskipten
ADDI.B #$30,D0
BSR _SPUTCH
gotoskipten
MOVE.B D3,D0 ; display 1's digit
ANDI #$0F,D0
ADDI.B #$30,D0
BSR _SPUTCH
CMP.B #$FF,D2 ; check to see if we already counted Y
BNE gotocnty ; if not, start counting
MOVE.B #'H',D0 ; Finish ANSI control in form <ESC>[Yn:XnH
BSR _SPUTCH
MOVEM.L (SP)+,D0-D4
RTS
***************************************************************
; Function _SELECT_DIFF
; Purpose Select Difficulty
***************************************************************
_SELECT_DIFF
MOVEM.L D0-D3,-(SP)
; Select Difficulty
draw_select
MOVE.B #8,D1
MOVE.B #14,D2
CMP.B #0,DIFFICULTY ;
BEQ draw_easy_select
CMP.B #1,DIFFICULTY ;
BEQ draw_medium_select
CMP.B #2,DIFFICULTY ;
BEQ draw_hard_select
CMP.B #3,DIFFICULTY ;
BEQ draw_insane_select
draw_easy_select ; Draw EASY selected
MOVE.L #SNK_SPEED_EASY,SNK_SPEED ; set snake speed for this option
BSR _GOTOXY
MOVEA.L #STR_SEASY,A1 ; draw selected
BSR _DISPSTR
ADDI.B #1,D2 ; add 1 to y
BSR _GOTOXY
MOVEA.L #STR_MEDIUM,A1 ; draw unselected
BSR _DISPSTR
ADDI.B #1,D2 ; add 1 to y
BSR _GOTOXY
MOVEA.L #STR_HARD,A1 ; draw unselected
BSR _DISPSTR
ADDI.B #1,D2 ; add 1 to y
BSR _GOTOXY
MOVEA.L #STR_INSANE,A1 ; draw unselected
BSR _DISPSTR
BRA get_select
draw_medium_select
MOVE.L #SNK_SPEED_MEDIUM,SNK_SPEED ; set snake speed for this option
BSR _GOTOXY
MOVEA.L #STR_EASY,A1
BSR _DISPSTR
ADDI.B #1,D2 ; add 1 to y
BSR _GOTOXY
MOVEA.L #STR_SMEDIUM,A1
BSR _DISPSTR
ADDI.B #1,D2 ; add 1 to y
BSR _GOTOXY
MOVEA.L #STR_HARD,A1
BSR _DISPSTR
ADDI.B #1,D2 ; add 1 to y
BSR _GOTOXY
MOVEA.L #STR_INSANE,A1
BSR _DISPSTR
BRA get_select
draw_hard_select
MOVE.L #SNK_SPEED_HARD,SNK_SPEED ; set snake speed for this option
BSR _GOTOXY
MOVEA.L #STR_EASY,A1
BSR _DISPSTR
ADDI.B #1,D2
BSR _GOTOXY ; add 1 to y
MOVEA.L #STR_MEDIUM,A1
BSR _DISPSTR
ADDI.B #1,D2 ; add 1 to y
BSR _GOTOXY
MOVEA.L #STR_SHARD,A1
BSR _DISPSTR
ADDI.B #1,D2 ; add 1 to y
BSR _GOTOXY
MOVEA.L #STR_INSANE,A1
BSR _DISPSTR
BRA get_select
draw_insane_select
MOVE.L #SNK_SPEED_INSANE,SNK_SPEED ; set snake speed for this option
BSR _GOTOXY
MOVEA.L #STR_EASY,A1 ; draw splash screen
BSR _DISPSTR
ADDI.B #1,D2 ; add 1 to y
BSR _GOTOXY
MOVEA.L #STR_MEDIUM,A1 ; draw splash screen
BSR _DISPSTR
ADDI.B #1,D2 ; add 1 to y
BSR _GOTOXY
MOVEA.L #STR_HARD,A1 ; draw splash screen
BSR _DISPSTR
ADDI.B #1,D2 ; add 1 to y
BSR _GOTOXY
MOVEA.L #STR_SINSANE,A1 ; draw splash screen
BSR _DISPSTR
BRA get_select
get_select
MOVE.B #0,D1
MOVE.B #0,D2
BSR _SGETCH ; else, get the character
CMP.B #'s',D0 ; check if down arrow was pressed
BEQ select_key_down
CMP.B #'w',D0 ; check if left arrow was pressed
BEQ select_key_up
CMP.B #$0D,D0 ; check if enter key was pressed
BNE draw_select
MOVEM.L (SP)+,D0-D3
RTS
select_key_down
CMP.B #3,DIFFICULTY ; check to see if we're at bottom of menu
BEQ draw_select ; if so, don't go down any more
ADDI.B #1,DIFFICULTY
BRA draw_select
select_key_up
CMP.B #0,DIFFICULTY ; check to see if we're at top of menu
BEQ draw_select ; if so, don't go up any more
SUBI.B #1,DIFFICULTY
BRA draw_select
***************************************************************
; Function _SELECT_GAMEOVER
; Purpose Game over selection screen
***************************************************************
_SELECT_GAMEOVER
MOVEM.L D0-D3,-(SP)
; Select Play Again or End Game
MOVE.B #0,D3 ; set default select to Medium
gg_draw_select
CMP #0,D3
BEQ gg_draw_yes_select
CMP #1,D3
BEQ gg_draw_no_select
gg_draw_yes_select ; Draw EASY selected
MOVE.B #23,D1
MOVE.B #19,D2
BSR _GOTOXY
MOVEA.L #STR_GG_SYES,A1 ; draw Yes option selected screen
BSR _DISPSTR
MOVE.B #44,D1
MOVE.B #19,D2
BSR _GOTOXY
MOVEA.L #STR_GG_NO,A1 ; draw No option deselected screen
BSR _DISPSTR
BRA gg_get_select
gg_draw_no_select
MOVE.B #23,D1
MOVE.B #19,D2
BSR _GOTOXY
MOVEA.L #STR_GG_YES,A1 ; draw Yes option deselected screen
BSR _DISPSTR
MOVE.B #44,D1
MOVE.B #19,D2
BSR _GOTOXY
MOVEA.L #STR_GG_SNO,A1 ; draw No option selected screen
BSR _DISPSTR
gg_get_select
MOVE.B #0,D1
MOVE.B #0,D2
BSR _GOTOXY
BSR _SGETCH ; else, get the character
CMP.B #'a',D0 ; check if down arrow was pressed
BEQ gg_select_key_left
CMP.B #'d',D0 ; check if left arrow was pressed
BEQ gg_select_key_right
CMP.B #$0D,D0 ; check if enter key was pressed
BNE gg_get_select ; if not, get another key
CMP.B #0,D3 ; see if we're done
BEQ gg_done_select
TRAP #11 ; end game
DC.W 0
gg_done_select
MOVEM.L (SP)+,D0-D3
RTS
gg_select_key_left
CMP.B #0,D3 ; check to see if we're at top of menu
BEQ gg_select_key_right ; if so, don't go up any more
SUBI.B #1,D3
BRA gg_draw_select
gg_select_key_right
CMP.B #1,D3 ; check to see if we're at bottom of menu
BEQ gg_select_key_left ; if so, don't go down any more
ADDI.B #1,D3
BRA gg_draw_select
***** Subroutine for receiving a character - simulator *****
_SGETCH
TRAP #15
DC.W 3
RTS
**** Subroutine for sending character - simulator *****
_SPUTCH
TRAP #15
DC.W 1
RTS
***** Subroutine for receiving a character - trainer board *****
_GETCH
MOVEM.L D1/A0,-(SP)
LEA DUART,A0
IP_POLL
MOVE.B SRA(A0),D1
BTST #RxRDY,D1
BEQ IP_POLL
MOVE.B RBA(A0),D0
MOVEM.L (SP)+,D1/A0
RTS
***** Subroutine for sending character - trainer board *****
_PUTCH
MOVEM.L D1/A0,-(SP)
LEA DUART,A0
OP_POLL
MOVE.B SRA(A0),D1
BTST #TxRDY,D1
BEQ OP_POLL
MOVE.B D0,TBA(A0)
MOVEM.L (SP)+,D1/A0
RTS
LIVES DC.B $00
LEVEL DC.B $00
FOOD_NUM DC.B $00
SNK_SPEED DC.L $00000000
SNK_LIFE DC.W $00
DELAY_DECAY DC.B $00
FOOD_AVAIL DC.B $00
RAND_MEM DC.W $0000
SCORE DC.B $00
DIFFICULTY DC.B $00
POS_X DC.B $00
POS_Y DC.B $00
LAST_DIR DC.B $0F
DIRECTION DS.B 1
MOVING DS.B 1
TIMER DS.L 1
SNK_SCR DS.W SNK_SCR_SIZE ; x*y = 78*22
STR_EASY DC.B '[37;40m [32;40mEASY[37;40m',0
STR_MEDIUM DC.B '[32;40mMEDIUM[37;40m',0
STR_HARD DC.B '[37;40m [32;40mHARD[37;40m',0
STR_INSANE DC.B '[32;40mINSANE[37;40m',0
STR_SEASY DC.B '[37;40m [30;42mEASY[37;40m',0
STR_SMEDIUM DC.B '[30;42mMEDIUM[37;40m',0
STR_SHARD DC.B '[37;40m [30;42mHARD[37;40m',0
STR_SINSANE DC.B '[30;42mINSANE[37;40m',0
STR_GG_YES DC.B '[34;40mPLAY AGAIN[37;40m',0
STR_GG_SYES DC.B '[30;44mPLAY AGAIN[37;40m',0
STR_GG_NO DC.B '[34;40mNO, THANKS[37;40m',0
STR_GG_SNO DC.B '[30;44mNO, THANKS[37;40m',0
STR_ESC DC.B $1B,'[',0