forked from hannenz/zoomania
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zoo_ass.s
executable file
·2160 lines (1884 loc) · 37.3 KB
/
zoo_ass.s
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
;---------------------------------------------------------------------------------------
;zoo mania assembler routines
;04/2004 hannenz
;---------------------------------------------------------------------------------------
;0 ingame 1
;1 ingame 2
;2 title screen
;3 level up
;4 time out
;5 hi score
.macro jeq adr
bne *+5
jmp adr
.endmacro
.macro jne adr
beq *+5
jmp adr
.endmacro
.macro jmi adr
bpl *+5
jmp adr
.endmacro
.macro jpl adr
bmi *+5
jmp adr
.endmacro
.macro jcc adr
bcs *+5
jmp adr
.endmacro
.macro jcs adr
bcc *+5
jmp adr
.endmacro
.macro rotate char
ldy $3002 + char*8
ldx #2
: lda $3001 + char*8,x
sta $3000 + char*8,x
inx
cpx #6
bne :-
sty $3005 + char*8
.endmacro
joy_speed = 4;
.import popax
.import popa
;include data (charsets, sprites, msx)
.export _colortab,_highscore,_matrix
.segment "DAT"
.incbin "zoo.dat",2
_colortab: .byte 1,1,2,5,6,4,7,3
_highscore: .res 160
_matrix: .res 64
.export _bmp_data
.segment "RODATA"
_bmp_data: .incbin "zootitle.pic"
.segment "CODE"
;---------------------------------------------
;void __fastcall__ init_msx(unsigned char);
;---------------------------------------------
.export _init_msx;
_init_msx: jmp $1000
;---------------------------------------------------
;void init_irq(void);
;---------------------------------------------------
;inits the irq running in-game
.export _game_irq
_game_irq: sei
lda #<_interrupt_handler
ldx #>_interrupt_handler
ldy #0
sta $314
stx $315
sty $d012
asl $d019
lda #$18
sta $d016
lda #0
sta $d021
lda #$1b
sta $d011
cli
rts
;---------------------------------------------------
;void __fastcall__ fld(char at _row);
;---------------------------------------------------
;little fld when scrolling out the main menu screen
.export _fld
_fld: sei
asl
asl
asl
clc
adc #$33 ;line*8 + $33, start of fld
sta $d012
sta fld_line+1
lda #255
sec
sbc fld_line+1
sta fld_tmp
lda #$28
jsr _setgfx
ldx #0
stx $d016
stx $d021
stx _fld_done
inx
stx fld+1
lda #<fld
ldx #>fld
sta $314
stx $315
lda #$1b
sta $d011
asl $d019
cli
rts
fld: ldx #1
@loop: lda $d012
cmp $d012
beq *-3
and #7
ora #$10
sta $d011
dex
bne @loop
lda #8
ldx $d012
cpx $d012
beq *-3
sta $d021
asl fld+1
lda fld+1
cmp fld_tmp
bcc @skip
sta _fld_done
lda #0
sta $d020
@skip: asl $d019
lda #<fld1
ldx #>fld1
ldy #255
jmp out1
fld1: lda #$1b
sta $d011
lda #0
sta $d021
jsr $1003
asl $d019
lda #<fld
ldx #>fld
fld_line: ldy #0
jmp out1
;---------------------------------------------------
;void setup_title_irq(void);
;---------------------------------------------------
;setup the irq runnnig in the main menu screen
.export _title_irq
_title_irq: sei
lda #$7f
sta $dc0d
sta $dd0d
lda $dc0d
lda $dd0d
lda #1
sta $d01a
lda #$1b
sta $d011
lda #<title_irq
ldx #>title_irq
ldy #$fa
sta $314
stx $315
sty $d012
asl $d019
lda #<(scroll_text-1)
ldx #>(scroll_text-1)
sta $7a
stx $7b
cli
rts
;---------------------------------------------------------
_inter_irq: sei
lda #<irq_x
ldx #>irq_x
ldy #$c2
sta $314
stx $315
sty $d012
lda #$1b
sta $d011
asl $d019
cli
rts
;---------------------------------------------------
;interrupt handler
;---------------------------------------------------
;in-game irq routine
.export _interrupt_handler
_interrupt_handler: ;jsr __game_interrupt
;jmp $ea31
__game_interrupt: asl $d019 ;acknoledge raster irq
lda count
beq get_joy
lda $d00e ;move cursor
clc
adc _xdir1
sta $d00e
lda $d00f
clc
adc _ydir1
sta $d00f
lda _players
beq @skip
lda $d00c
clc
adc _xdir2
sta $d00c
lda $d00d
clc
adc _ydir2
sta $d00d
@skip: dec count
jmp timer
get_joy: ldy _tt
lda $dc00,y ;get joystick
and #$7f
ldx _demo ;if in demo mode get movement from cue
beq @skip
ldx _cue_max
jsr _getfromcue
jeq timer ;nothing waiting in the cue, then skip
@skip: ldx #0 ;we will need a zero
cmp #126
bne @joy1
lda _ypos1 ;if ypos is 0 then up isn't possible
beq @joy4 ;so skip
dec _ypos1 ;decrease ypos
lda #256 - joy_speed
sta _ydir1 ;load the value to add to the sprite y coordinate
stx _xdir1 ;.x is alwayx 0, no x-movement
jmp @joy5 ;skip the following
@joy1: cmp #125
bne @joy2
lda _ypos1
cmp #7
beq @joy4
inc _ypos1
lda #joy_speed
sta _ydir1
stx _xdir1
jmp @joy5
@joy2: cmp #123
bne @joy3
lda _xpos1
beq @joy4
dec _xpos1
lda #256 - joy_speed
sta _xdir1
stx _ydir1
jmp @joy5
@joy3: cmp #119
bne @joy4
lda _xpos1
cmp #7
beq @joy4
inc _xpos1
lda #joy_speed
sta _xdir1
stx _ydir1
jmp @joy5
@joy4: stx _xdir1 ;no joy input from joy#1, then both dir's are 0
stx _ydir1
jmp get_joy2
@joy5: lda #6 ;counter for sprite movement (6*4 pixels => move 24 pixels)
sta count
get_joy2: lda _players ;only one player?
beq timer ;then skip this...
lda $dc01 ;check joy#2, see above
ldx #0
cmp #254
bne @joy1
lda _ypos2
beq @joy4
dec _ypos2
lda #256 - joy_speed
sta _ydir2
stx _xdir2
jmp @joy5
@joy1: cmp #253
bne @joy2
lda _ypos2
cmp #7
beq @joy4
inc _ypos2
lda #joy_speed
sta _ydir2
stx _xdir2
jmp @joy5
@joy2: cmp #251
bne @joy3
lda _xpos2
beq @joy4
dec _xpos2
lda #256 - joy_speed
sta _xdir2
stx _ydir2
jmp @joy5
@joy3: cmp #247
bne @joy4
lda _xpos2
cmp #7
beq @joy4
inc _xpos2
lda #joy_speed
sta _xdir2
stx _ydir2
jmp @joy5
@joy4: stx _xdir2
stx _ydir2
jmp timer
@joy5: lda #6
sta count
;timer
timer: lda _stop ;if the stop flag
bne joker ;don't do the timer stuff
lda _time1 ;if the timer is decremented to zero yet
ora _time1 + 1
bne do_timer
lda #1
sta _time_out ;set a flag for the main program
bne joker ;and skip the following
do_timer: dec del ;respect timer delay
bne joker
lda _timer_delay
sta del
lda _time1 ;decrease timer...
bne *+5
dec _time1+1
dec _time1
jsr _display_time ;and display the bar
;joker
joker: lda _joker ;is there a joker running...??!
jeq exit ;no, then skip
dec joker_delay ;respect delay value
lda joker_delay
and #7 ;every 8th frame...
bne exit
inc _joker_tmp ;increase the icon to display
lda _joker_tmp
cmp _animals ;if it is larger than possible animals in this level?
bcc @skip
lda #0 ;then reset to zero
sta _joker_tmp
@skip: ldy _joker_y ;claculate screen ram adress to display the joker at
lda ytab_hi,y
sta $f5
lda _joker_x
asl
clc
adc _joker_x ;joker_x * 3 + xoffs
clc
adc ytab_lo,y
bcc *+4
inc $f5
clc
adc #2
sta $f4
bcc *+4
inc $f5 ;$f4/$f5 points to screen ram adress
ldx _joker_tmp
lda _colortab,x ;get proper color for the icon
ora #8
sta @col+1
txa
asl
asl
asl
clc
adc _joker_tmp ;multiply the icon code by 9 to get character code of first 3x3 char
ldx #3 ;count rows to draw
@lp2: ldy #0
@lp1: sta ($f4),y ;draw one character
pha ;do color ram stuff..., remember accu value (character code)
lda $f5 ;(use current lo byte of pointer but alter hibyte to point to color ram)
pha ;remember old hi byte
and #3
ora #$d8 ;let it point to colorram
sta $f5
@col: lda #0 ;plot color
sta ($f4),y
pla ;restore hibyte (screen ram)
sta $f5
pla ;restore accu (char code)
clc
adc #1 ;and increase it
iny
cpy #3 ;3 times in x-dir
bne @lp1 ;then goto next line
pha
lda $f4
clc
adc #$28 ;(add 40 to pointer)
sta $f4
bcc *+4
inc $f5
pla
dex ;and do 3 rows...
bne @lp2
exit: jsr $1003 ;play that funky music :)
dec rotate_delay ;rotate the chars of the timer bar
lda rotate_delay ;each 4th frame
and #3
jne skip_rotate
rotate 254
rotate 253
rotate 252
rotate 251
rotate 250
rotate 249
rotate 248
rotate 247
skip_rotate: jmp $ea31
;draw the timer bar
.export _display_time
_display_time: lda _time_out
bne done
lda _time1
ldx _time1+1
stx aux ;.A still has time1 lo byte
lsr aux ;time1 is max. 319, so max. 1 bit set in Hibyte
ror ;rotate right over 3 bytes (Hi,Lo,Remainder)
ror rem
lsr ;rotate right over 2 Bytes (Lo,Remainder)
ror rem
lsr
ror rem
tax ;time1 / 8
lda rem ;rotate rem right 5 times to get the remainder right
lsr
lsr
lsr
lsr
lsr
clc
adc #$f6 ;screen code of proper 'part' bar character
sta $07c0,x
lda #$fe ;screen code: 'full' bar char
l1: dex
bmi done
sta $07c0,x
jmp l1
done: rts
;---------------------------------------------------------------------------------
;void print2x2_centered (char *string,char color1,char color2,char line);
;---------------------------------------------------------------------------------
.export _print2x2_centered
_print2x2_centered: sta line ;line
jsr popa
sta color2 ;color2
jsr popa
sta color1
jsr popax ;get strinf
sta $fc
stx $fd
ldy line
lda tab_lo,y
sta $fe
lda tab_hi,y
sta $ff
;calc length
ldy #$ff
loop: iny
lda ($fc),y
bne loop
sty aux
lda #20
sec
sbc aux
clc
adc $fe
sta $fe
bcc *+4
inc $ff
ldy #0
sty tmp
loop2: ldy tmp
lda ($fc),y
beq p2x2_done
jsr plot2x2
inc tmp
jmp loop2
p2x2_done: rts
;---------------------------------------------------------------------------------
;void __fastcall__ plot2x2_xy (char c,char x,char y,char color1,char color2);
;---------------------------------------------------------------------------------
.export _plot2x2_xy
_plot2x2_xy: sta color2 ;store 'low' color
jsr popa ;get 'high' color
sta color1 ;store it
jsr popa ;get y
sta line ;store
jsr popa ;get x
ldy line
clc
adc tab_lo,y ;line * 40 + x
sta $fe ;in pointer lo-byte
lda tab_hi,y ;hi-byte
adc #0 ;respect carry from addition of x
sta $ff ;into pointer hi-byte
jsr popa ;get 'character' to plot
plot2x2: ldy #0
ldx #0
jsr _pet2scr ;convert into screen code
asl ;screen code * 4
asl
sta ($fe),y ;store fisrt char
jsr docol ;color it
clc
adc #1 ;increase screen code by 1
iny
sta ($fe),y
jsr docol
clc
adc #1
inx
pha ;remember screen code
lda $fe ;pointer to next line
clc
adc #40
sta $fe
bcc @skip
inc $ff
@skip: pla
ldy #0
sta ($fe),y
jsr docol
iny
clc
adc #1
sta ($fe),y
jsr docol
lda $fe
sec
sbc #38
sta $fe
bcs *+4
dec $ff
rts
docol: pha
lda $ff
pha
and #3
ora #$d8
sta $ff
lda color1,x
sta ($fe),y
pla
sta $ff
pla
rts
;---------------------------------------------
;void __fastcall__ setgfx(unsigned int);
;---------------------------------------------
.export _setgfx
_setgfx: ldx #4
ldy #0
sty d1
asl
rol d1
asl
rol d1
sta tmp
txa
lsr
lsr
ldx #4
loop1: asl tmp
rol
dex
bne loop1
sta $d018
lda $dd00
and #$fc
ora d1
eor #3
sta $dd00
rts
;---------------------------------------------
;void __fastcall__ wait(unsigned char raster);
;---------------------------------------------
.export _wait
_wait: cmp $d012
bne _wait
rts
;---------------------------------------------
;unsigned char random(void);
;---------------------------------------------
.export _random
_random: lda #0
eor $dc04
eor $dc05
eor $dd04
eor $dd05
eor $dd06
eor $dd07
sta _random+1
rts
;---------------------------------------------
;unsigned char __fastcall__ pet2scr(unsigned char);
;---------------------------------------------
.export _pet2scr
_pet2scr: eor #$e0
clc
adc #$20
bpl cont
adc #$40
bpl cont
eor #$a0
cont: rts
;------------------------------------------------
;unsigned char isstop(void)
;------------------------------------------------
.export _isstop
_isstop: lda #$7f
sta $dc00
cmp $dc01
beq no
lda #1
rts
no: lda #0
rts
;----------------------------------------------------
;void wait_for_key_or_joy(void);
;----------------------------------------------------
.export _wait_for_key_or_joy
_wait_for_key_or_joy: lda _demo
bne @exit
lda $dc00
cmp #111
beq @exit
lda $dc01
cmp #239
bne _wait_for_key_or_joy
@exit: rts
;--------------------------------------------------------------
;unsigned char _check_matrix(void);
;--------------------------------------------------------------
.export __check_matrix
__check_matrix:
;first we check horizontally
lda #0
sta cmxi ;count the rows
@loop2: lda #0
sta cmxj ;count the column
@loop1: lda cmxi
ldx cmxj
jsr get_matrix ;.Y has index in _matrix of cmxi/cmxj, .A has value of _matrix,y
cmp _matrix+1,y ;is it the same as its next neighbour?
bne @no ;no then increas x position and try again
cmp _matrix+2,y ;if we are here, two are same and testing the third neighbour
bne @no_2 ;if not equal we can advance by 2 in x dir !
jmp @success ;three equal--> exit success
@no_2: inc cmxj
@no: inc cmxj
lda cmxj
cmp #6 ;we need to test only up to xpos 5
bcc @loop1
inc cmxi ;next row
lda cmxi
cmp #8
bne @loop2 ;all 8 rows checked...?!
;check vertically
lda #0
sta cmxj
@loop4: lda #0
sta cmxi
@loop3: lda cmxi
ldx cmxj
jsr get_matrix
cmp _matrix+8,y
bne @no2
cmp _matrix+16,y
bne @no2
@success:
lda #1
rts
@no2: inc cmxi
lda cmxi
cmp #6
bne @loop3
inc cmxj
lda cmxj
cmp #8
bne @loop4
lda #0
rts
;-----------------------------------------------------------------------
title_irq: ldx #1
lda $d012
cmp $d012
beq *-3
stx $d021
lda #$f0
cmp $d012
bne *-3
dec scroll
dec scroll
lda scroll
and #7
sta $d016
lda $d012
cmp $d012
beq *-3
ldx #7
barlp: lda barcolor_tab,x
ldy $d012
cpy $d012
beq *-3
sta $d021
dex
bpl barlp
lda #$fc
cmp $d012
bne *-3
lda #0
sta $d021
sta $d016
asl $d019
lda #0
sta $dd00
lda #$38
sta $d018
lda $d011
ora #$20
sta $d011
lda #$10
sta $d016
jsr $1003
dec bar_delay
lda bar_delay
@xyz: and #1
sta bar_delay
bne @skip
ldx barcolor_tab ;4
ldy #0 ;2
@loop: lda barcolor_tab+1,y ;4
sta barcolor_tab,y ;4 ;80
iny ;6
cpy #31 ;4
bne @loop ;3
txa ;2
sta barcolor_tab,y ;4 ;99
@skip: lda scroll
and #7
bne out2
ldx #0
gklp: lda $07c1,x
sta $07c0,x
lda $dbc1,x
sta $dbc0,x
inx
cpx #$27
bne gklp
inc $7a
bne *+4
inc $7b
wrap: ldy #0
lda ($7a),y
bne okok
lda #<scroll_text
ldx #>scroll_text
ldy #1
sty _demo
sta $7a
stx $7b
jmp wrap
okok: cmp #$10
bcs okok1
sta $dbc0+39
bcc out2
okok1: jsr _pet2scr
ora #$80
sta $07e7
out2: lda #<title_irq2
ldx #>title_irq2
ldy #$ba - 2
out1: sta $314
stx $315
sty $d012
out3: pla
tay
pla
tax
pla
rti
title_irq2: ldx #1
lda $d012
cmp $d012
beq *-3
stx $d021
ldx #$1b
lda $d012
cmp $d012
beq *-3
stx $d011
dex
stx $d018
ldx #3
lda $d012
cmp $d012
beq *-3
stx $dd00
ldx #8
lda #$bc
cmp $d012
bne *-3
stx $d021
lda #0
sta $d016
asl $d019
lda #<title_irq
ldx #>title_irq
ldy #$f0 - 1
sta $314
stx $315
sty $d012
jmp out1
;---------------------------------------------------------------------------------
;void ass_setpu(void)
;---------------------------------------------------------------------------------
nmi: pha
lda #140
sta _key
pla
rti
.export _ass_setup
_ass_setup:
; jsr $ff8a ;restore Vectors
; jsr $e3bf ;init BASIC-RAM
lda #<nmi
ldx #>nmi
sta $318
stx $319
lda #11
sta $d022
sta $d025
lda #8
sta $d023
sta $d026
ldx #2
stx $d02d
dex
stx $d02e
dex
stx $d020
stx $d021
dex
stx $d01c
lda #39
ldx #50
sta $d00e
stx $d00f
clc