-
Notifications
You must be signed in to change notification settings - Fork 0
/
nibbly.asm
1944 lines (1368 loc) · 25.1 KB
/
nibbly.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
/*
NIBBLY Engine v1.3 by Tebe/Madteam (05.06.2006)
21.11.2009 - NTSC msx fix (msx_stop)
SID2POKEY - $f0..
INFALTE - $e0..
NIBBLY - $80..
Zasady:
- zadaniem jest przejsc 100 poziomow, na kazdym z nich zebrac wszystkie 'kropki' przed uplywem czasu
- limit casu to 2:00 minuty na kazdy poziom, czasu nie mozna zatrzymac
- za kazda zebrana 'kropke' dostajemy 5 punktow
- po zebraniu wszystkich 'kropek' dostajemy 10 punktow za kazda sekunde z czasu ktory nam pozostal
- po kazdych 10.000 punktach dostajemy dodatkowe zycie (maksymalna liczba zyc to 9) <- USUNIETO TA MOZLIWOSC
- na koncu kazdego poziomu pokazywany jest 'kod dostepu' do poziomu, kod dostepu wpisujemy przed gra
*/
*--- GLOBAL CONSTANTS
icl 'nibbly.hea'
icl 'packed.hea'
prg = $3400
prgTitle = $1000
txt_temp = pmg ; $c000 ...
l_adr = pmg+$100
h_adr = l_adr+$100
*--- VARIABLES
src = $80 ;(2)
srcOld = src+2 ;(2)
dst = srcOld+2 ;(2)
_tmp = dst+2 ;(2)
idx = _tmp+2 ;(1)
len = idx+1 ;(1)
byt2 = len+1 ;(2)
bajt = byt2+1 ;(1) tutaj przechowujemy pozycje X ducha dla panelu
gate = bajt+1 ;(1)
posX = gate+1 ;(1)
posY = posX+1 ;(1)
ftmp = posY+1 ;(2)
byt3 = $0100
zpage = $e0 ; 11 bytes
cloc = $14
*--- INTRO
org intro_org
.link 'logo\logo3.obx'
ini intro
*--- INITIALIZE
org prg
.link 'init.obx'
depack_move
icl 'inflate.asm'
ini prg
*--- MAIN PROGRAM
org prg
ant
dta $70,$60,$4e,a(gorny_pasek),$44+$80,a(scr+40)
dta 4+$80,4
dta 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4+$80,4
dta $4e+$80,a(gorny_pasek),$60
dta $4e,a(panel+000),$e,$e,$e,$e,$8e,$e,$e
dta $4f,a(panel+320),$f,$f,$f,$f,$f,$f,$f
dta $4e,a(panel+640),$e,$e,$e,$e,$e,$e,$e
dta $41,a(ant)
gorny_pasek :40 dta $55
;dolny_pasek :40 dta $55
panel
ins 'panel\panel_2.raw',640,320*3
panel_lives = panel+320+2
panel_round = panel+320+35
panel_clock = panel+320+20
panel_punkt = panel+320+6
.local dli
icl 'dli.asm'
.endl
main
lda palntsc
cmp #1
beq _skip
lda #60
sta _palntsc+1
sta DEC_CLOCK._palntsc+1
_skip
jsr setpmcol
jsr save_color
_pal
WAIT #1
sei
mva #0 $d40e
sta $d400
mva #$fe $d301
mva >pmg $d407 ; missiles and players data address
mva #3 $d01d ; enable players and missiles
; lda #$cc ; stala wartosc dla ostatniej pozycji duchow
; sta bajt
lda #1
jsr sid_init
jsr CRC16.MAKECRCTABLE
* --- EKRAN TYTULOWY
INFLATE #nibbly_logo , #fntTit ; -> $d800..$ff00
jsr title_main
* --- GRA
lda:rne $d40b
mva #$00 msx_stop+1
sta _fade+1
mva __color_nr color_nr ; BYTE
mwa #l_tcol2 __l_tcol
mwa #h_tcol2 __h_tcol
mwa #t_satur2 __t_satur
mwa #t_color2 __t_color
INFLATE #nibbly_fnt , #fnt
INFLATE #nibbly_pmg , #pmg+$300
lda <nmi
sta $fffa
sta $fffe
lda >nmi
sta $fffb
sta $ffff
lda #$cc ; stala wartosc dla ostatniej pozycji duchow
sta bajt
mwa #dli.dli0 vdli+1
mva #$c0 $d40e
*---
start
lda #[3^$75] ;9
eor #$75
sta dli.lives ; liczba zyc
lda #0
sta dli.punkt_0 ; punkty 6x0
sta dli.punkt_1
sta dli.punkt_2
sta dli.punkt_3
sta dli.punkt_4
sta dli.punkt_5
restart
WAIT #1
lda #def_joy_delay
sta joy_delay
_palntsc lda #50
sta second
sta notime+1
lda #0
sta dli.clock_1 ; zerujemy zegar 00:00
sta dli.clock_3
sta dli.clock_4
; lda #0 ; usuwamy napis
sta spr0+1
sta spr1+1
sta mis0+1
sta mis1+1
sta _old+1
lda >fnt
sta dli.f0+1
ldy #0 ; ustawiamy robala na pozycji poczatkowej
sty _SRC_TEST._eat+1 ; zerujemy licznik zjedzonych "ziaren"
lda <@start+10*2
sta src
sta srcOLD
sta l_adr,y+
rne
lda >@start+10*2
sta src+1
sta srcOLD+1
sta h_adr,y+
rne
lda #1
sta idx ; pierwszy wolny indeks umozliwiajacy wpis do tablicy RUCH
lda #1
sta len ; poczatkowa dlugosc robala
jsr _LEVEL
_fade lda #0
sne
jsr fade_in
mva #$ff _fade+1
lda #zpusty ; czyscimy pole pod glowa robala
ldy #0
sta (src),y
iny
sta (src),y
ldy #@sw
sta (src),y
iny
sta (src),y
lda #2 ; startujemy zegar
sta dli.clock_1
lda #0
sta zegar+1
jsr _CLR_HEAD ; ustawiamy glowe
lda #$22
sta dli.nap_gti+1
lda #0
sta hsiz+1
lda #$24
sta c7+1
sta dli.nap_col0+1
lda #$38
sta c8+1
sta dli.nap_col1+1
lda #128
sta spr0+1
sta spr1+1
sta posX
lda #128+32
sta posY
jsr _HEAD_UP ; glowa w gore
jmp loop_prv
*--- WELL DONE
welldone
lda #{rts}
sta text._rts ; nie bedzie czekal na FIRE, wyswietlamy napis WELL DONE
SID_RESTART #song2
jsr CRC16.calc
TEXT #0
_loop ; dostajemy punkty za pozostaly czas x2
WAIT #1
lda #1
sta second
jsr DEC_CLOCK
jsr INC_PUNKTY
jsr INC_PUNKTY
lda notime+1
bne _loop
jsr text._rts+1 ; usuwamy napis WELL DONE (omijamy rozkaz RTS)
next
jsr ADD_LEVEL
jsr INC_ROUND
SID_RESTART #song5
jmp restart
ADD_LEVEL
lda _LEVEL.adr ; nastepny level, nastepna runda
clc
adc #lsiz
sta _LEVEL.adr
scc
inc _LEVEL.adr+1
rts
*--- ESCAPE
esc
jsr _SRC_TEST.ouch ; po tym juz nie wroci
*--- LET'S GO
loop_prv
lda #def_joy_delay
sta joy_delay
lda _LEVEL.ile
cmp #1
beq welldone
read_joy
lda $d20f ; ZWIEKSZENIE LEVELU PO NACISNIECIU KLAWISZA
and #4 ;
bne ___nxt ;
lda $d209
cmp #$1c
beq esc
; lda #$ff ;
; sta zegar+1 ;
; jmp next ;
___nxt ;
jsr notime
r_d300 ldy #0
cpy #$0f
beq read_joy
tya
_old cmp #0
bne _ok
dec joy_delay
bne read_joy
_ok
tya
lda l_adr_joy,y
sta _jmp+1
_jmp jmp _joy_nil
*--- PROCEDURY OBSLUGI JOYA MIESZCZA SIE NA 1 STRONIE
*--- ZACZYNAJA SIE OD POCZATKU STRONY PAMIECI
.align
.pages
_joy_nil
lda #1
sta joy_delay
jmp read_joy
_rg .local
lda _old+1
cmp #@left
beq _skp
sta _SRC_TEST._old_restore+1
tya
sta _old+1
_ADD_RUCH
inw src
inw src
jsr _SRC_TEST
_skp
jmp loop_prv
.endl
_lf .local
lda _old+1
cmp #@right
beq _skp
sta _SRC_TEST._old_restore+1
tya
sta _old+1
_ADD_RUCH
dew src
dew src
jsr _SRC_TEST
_skp
jmp loop_prv
.endl
_up .local
lda _old+1
cmp #@down
beq _skp
sta _SRC_TEST._old_restore+1
tya
sta _old+1
_ADD_RUCH
lda src
sec
sbc #@sw*2
sta src
scs
dec src+1
jsr _SRC_TEST
_skp
jmp loop_prv
.endl
_dw .local
lda _old+1
cmp #@up
beq _skp
sta _SRC_TEST._old_restore+1
tya
sta _old+1
_ADD_RUCH
lda src
clc
adc #@sw*2
sta src
scc
inc src+1
jsr _SRC_TEST
_skp
jmp loop_prv
.endl
.endpg
*--- CZYSCIMY PAMIEC PMG DLA GLOWY ROBALA
.proc _CLR_HEAD
lda #0 ; ustawiamy glowe
ldy #144+1
_clr
sta pmg+$400+40-1,y
sta pmg+$500+40-1,y
dey
bne _clr
rts
.endp
*--- PRZESUWAMY GLOWE NA DUCHACH (PM0, PM1)
*--- TUTAJ MAKRA DLA ROZPISANIA PETLI
.macro @@@dw
lda:cmp:req gate
inc _fn+1
inc posY
inc posY
:1
.endm
.macro @@@up
lda:cmp:req gate
inc _fn+1
dec posY
dec posY
:1
.endm
.macro @@@lf
lda:cmp:req gate
inc _fn+1
dec posX
lda posX
sta spr0+1
sta spr1+1
.endm
.macro @@@rg
lda:cmp:req gate
inc _fn+1
inc posx
lda posX
sta spr0+1
sta spr1+1
.endm
*--- TUTAJ WLASCIWA PROCEDURA
.proc _PUT_HEAD
*--- USTALAMY KIERUNEK I WSTAWIAMY ODPOWIEDNI KLOCEK 0..11
lda len
cmp #2
bcc _ok
ldx idx
dex
dex
ldy kier,x ; -2
lda _lsh4,y
inx
ora kier,x ; -1
tay
lda tst_skip,y
beq _ok
; ldy idx
; dey
lda l_adr,x
sta dst
lda h_adr,x
sta dst+1
lda ofset,y
ldy #0
sta (dst),y
iny
ora #1
sta (dst),y
ldy #@sw
clc
adc #1
sta (dst),y
iny
ora #1
sta (dst),y
_ok
*--- _PUT_HEAD
ldy _old+1
lda l_adr_head,y
sta _jmp+1
lda h_adr_head,y
sta _jmp+2
_jmp jmp $FFFF
_dw
@@@dw "jsr _HEAD_DOWN"
@@@dw "jsr _HEAD_DOWN"
@@@dw "jsr _HEAD_DOWN"
@@@dw "jsr _HEAD_DOWN"
@@@dw "jsr _HEAD_DOWN"
@@@dw "jsr _HEAD_DOWN"
@@@dw "jsr _HEAD_DOWN"
@@@dw "jmp _HEAD_DOWN"
_up
@@@up "jsr _HEAD_UP"
@@@up "jsr _HEAD_UP"
@@@up "jsr _HEAD_UP"
@@@up "jsr _HEAD_UP"
@@@up "jsr _HEAD_UP"
@@@up "jsr _HEAD_UP"
@@@up "jsr _HEAD_UP"
@@@up "jmp _HEAD_UP"
_lf
jsr _HEAD_LEFT
@@@lf
@@@lf
@@@lf
@@@lf
@@@lf
@@@lf
@@@lf
@@@lf
rts
_rg
jsr _HEAD_RIGHT
@@@rg
@@@rg
@@@rg
@@@rg
@@@rg
@@@rg
@@@rg
@@@rg
rts
.endp
*--- NOWA POZYCJA ROBALA
.proc _PUT_NIBBLY
lda len
cmp #2
bcs _ok
lda idx ; adres ogona robala
sec
sbc len
tax
lda l_adr,x
sta dst
lda h_adr,x
sta dst+1
lda #zpusty
ldy #0
sta (dst),y
sta (src),y
iny
sta (dst),y
sta (src),y
ldy #@sw
sta (dst),y
sta (src),y
iny
sta (dst),y
sta (src),y
rts
_ok
ldx idx
dex
ldy kier,x ; -1
lda ofset,y ; nowy klocek robala
ldy #0
sta (src),y
iny
ora #1
sta (src),y
ldy #@sw
clc
adc #1
sta (src),y
iny
ora #1
sta (src),y
lda idx ; adres ogona robala
sec
sbc len
tax
lda l_adr,x
sta dst
lda h_adr,x
sta dst+1
; lda <@null ; usuwamy adres ogona robala
; sta l_adr,x
; lda >@null
; sta h_adr,x
inx
lda l_adr,x
sta _tmp
lda h_adr,x
sta _tmp+1
lda #zpusty ; kasujemy ogonek
ldy #0
sta (dst),y
iny
sta (dst),y
ldy #@sw
sta (dst),y
iny
sta (dst),y
ldy kier,x
lda ofset+16,y ; wstawiamy nowy klocek na pozycji przedostatniej ogonka
ldy #0
sta (_tmp),y
iny
ora #1
sta (_tmp),y
ldy #@sw
clc
adc #1
sta (_tmp),y
iny
ora #1
sta (_tmp),y
_skp
rts
.endp
*--- ZWIEKSZENIE PUNKTACJI
.proc INC_PUNKTY
lda dli.punkt_0
cmp #9
beq _skp
ldx #0
lda dli.punkt_5
clc
adc #5
sta dli.punkt_5
cmp #10
bne _skp
stx dli.punkt_5
inc dli.punkt_4
lda dli.punkt_4
cmp #10
bne _skp
stx dli.punkt_4
inc dli.punkt_3
lda dli.punkt_3
cmp #10
bne _skp
stx dli.punkt_3
inc dli.punkt_2
lda dli.punkt_2
cmp #10
bne _skp
stx dli.punkt_2
inc dli.punkt_1
; lda dli.lives
; cmp #9
; scs
; inc dli.lives ; dodatkowe zycie za kazde 10.000 punktow (max 9 zyc)
lda dli.punkt_1
cmp #10
bne _skp
stx dli.punkt_1
inc dli.punkt_0
_skp
rts
.endp
*--- ZWIEKSZENIE NUMERU RUNDY
.proc INC_ROUND
inc lvl_count
lda lvl_count
cmp #lvl_max
bne _sk
mva #$ff msx_stop+1
jsr sid_stop
jsr setpmcol
jsr fade_out
jsr CONGRATULATIONS
jsr reset
pla
pla
jmp _pal
reset
mwa #levels _LEVEL.adr
ldy #0 ; resetujemy numer rundy 001
sty dli.round_0
sty dli.round_1
sty lvl_count ; dodatkowy licznik rund na bajcie
iny
sty dli.round_2
; dec dli.lives
rts
_sk
ldx #0
inc dli.round_2
lda dli.round_2
cmp #10
bne _skp
stx dli.round_2
inc dli.round_1
lda dli.round_1
cmp #10
bne _skp
stx dli.round_1
inc dli.round_0
_skp
jmp setpmcol
lvl_count brk
.endp
*--- MODYFIKACJA CZASU
.proc DEC_CLOCK
lda dli.clock_1
ora dli.clock_3
ora dli.clock_4
sta notime+1
beq _skp
dec second
bne _skp
_palntsc lda #50
sta second
dec dli.clock_4
lda dli.clock_4
bpl _skp
lda #9
sta dli.clock_4
dec dli.clock_3
lda dli.clock_3
bpl _skp
lda #5
sta dli.clock_3
dec dli.clock_1
_skp
rts
.endp
/*******************************************************************************/
/* TEST NOWEJ POZYCJI */
/*******************************************************************************/
.proc _SRC_TEST
ldy #0
lda (src),y
cmp #murek
beq _def
cmp #murek2
beq _def
cmp #ziarno
beq jedzenie
; cmp #$c4
; beq _ok
; cmp #$c8
; beq _ok
; cmp #$cc
; beq _ok
; cmp #$d0
; beq _ok
cmp #chr+$80
bcs ouch
/*
iny
lda (src),y
cmp #murek+1
beq _def
cmp #ziarno+1
beq jedzenie
*/
jsr _PUT_HEAD
jmp _PUT_NIBBLY
_def ; przywracamy poprzednia pozycje glowy robala
mwa srcOld src
dec idx
_old_restore lda #0
sta _old+1
rts
jedzenie
_eat lda #0
clc
adc #ulamek
sta _eat+1
scc
inc len
dec _LEVEL.ile
jsr inc_punkty
jsr _PUT_HEAD
jmp _PUT_NIBBLY
ouch ; zmniejszamy liczbe zyc i jesli osiagnie 0 to GAME OVER
dec dli.lives
lda dli.lives
beq gameover
SID_RESTART #song3