-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnbird2.asm
1823 lines (1258 loc) · 43.6 KB
/
nbird2.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
;Author : John McManus - john@appyappster.com
;Resources: Sprites scraped from internet and used UDGeedNext,
; http://chuntey.arjunnair.in, code snips from Jonathan Cauldwell
;0.1 - JMcManus - 30/09/2017 -rebuild from scratch
;
;Loading background - Russ McNulty code :)
M_GETSETDRV equ $89
F_OPEN equ $9a
F_CLOSE equ $9b
F_READ equ $9d
F_WRITE equ $9e
F_SEEK equ $9f
F_GET_DIR equ $a8
F_SET_DIR equ $a9
FA_READ equ $01
FA_APPEND equ $06
FA_OVERWRITE equ $0C
ESXDOS macro command
rst 8
db command
endm
PIPE1SPRITESTART equ 10
PIPE2SPRITESTART equ 18
PIPE3SPRITESTART equ 26
PIPE4SPRITESTART equ 34
PIPE5SPRITESTART equ 42
BIRDANI1 equ 50
BIRDANI2 equ 51
SCOREID1 equ 52
SCOREID2 equ 53
PIPECAPSTART equ 0
SCORE1X equ 142
SCORE2X equ 150
SCOREY equ 38
BIRDX equ 64
org 32768
START
call setupScreen
call loadGameBackground
call drawpavement
call showLayer2
call initPipeSprites
call initEndPipeSprites
call loadBird1
call loadBird2
ld hl, No1
call loadScore1
ld hl, No1
call loadScore2
;call initiliseSprites
; ret
call showScore
call makeAllSpritesVisible
;ret
ld hl, capID
ld a, PIPECAPSTART
ld (hl), a
ld ix, pipe1Data
call drawPipe
ld ix, pipe2Data
call drawPipe
ld ix, pipe3Data
call drawPipe
ld ix, pipe4Data
call drawPipe
ld ix, pipe5Data
call drawPipe
ld hl,playerScore
ld (hl), 0
ld hl, No3
call loadScore2
mainloop:
; call animatebird
call wait
call checkCollision
jr mainloop
wait ld hl,pretim ; previous time setting
ld a,(23672) ; current timer setting.
sub (hl) ; difference between the two.
cp 6 ; have two frames elapsed yet?
jr nc,wait0 ; yes, no more delay.
ret
wait0 ld a,(23672) ; current timer.
ld (hl),a ; store this setting.
call decBirdY
call scrollPipes
call animatebird
call flap
call updateScore
call scrollL2
ret
endGameLoop:
;lwait for keypress
jr endGameLoop
startGameLoop:
;wait for key press
jr startGameLoop
checkCollision:
;ld bc,0x303B ; Bits 7-2: Reserved, always 0. Bit 1: max sprites per line flag. Bit 0: Collision flag
; in a,(c)
; cp 1
; jp z, endGameSeq
ret
endGameSeq:
jp endGameSeq
decBirdY
ld a, (bird_y)
inc a
ld (bird_y), a
cp 197
jp z, endGame ; hit the bottom
inc a
ld (bird_y), a
cp 197
jp z, endGame ; hit the bottom
inc a
ld (bird_y), a
cp 197
jp z, endGame ; hit the bottom
inc a
ld (bird_y), a
cp 197
jp z, endGame ; hit the bottom
inc a
ld (bird_y), a
cp 197
jp z, endGame ; hit the bottom
ret
endGame
jp endGameLoop
scrollL2:
;ret
ld bc, $243B ; select the scroll register
ld a,22
out (c),a ; select layer 2 "X" scroll
ld a,(ScrollIndex)
inc a
;inc a
ld (ScrollIndex),a
ld bc, $253B
out (c),a
ret
scrollPipes:
ld hl, capID
ld a, PIPECAPSTART
ld (hl), a
ld ix, pipe1Data
call movePipe2
ld ix, pipe1Data
call movePipe2
ld ix, pipe2Data
call movePipe2
ld ix, pipe2Data
call movePipe2
ld ix, pipe3Data
call movePipe2
ld ix, pipe3Data
call movePipe2
ld ix, pipe4Data
call movePipe2
ld ix, pipe4Data
call movePipe2
ld ix, pipe5Data
call movePipe2
ld ix, pipe5Data
call movePipe2
ld ix, pipe1Data
call drawPipe
ld ix, pipe2Data
call drawPipe
ld ix, pipe3Data
call drawPipe
ld ix, pipe4Data
call drawPipe
ld ix, pipe5Data
call drawPipe
ret
;--------------------ROUTINES------
movePipe:
;ix hold pointer to database.
;pipe1Data db 0, 32 , 4 , 2 , 10 ; position 2 bytes, top length, gap, start spriteid
ld a,(ix+1)
dec a
cp 16
jp nz, notOffScreen
ld a, 1
ld (ix), a
ld a, 32
notOffScreen:
ld (ix+1), a
ret
movePipe2:
;ix hold pointer to database.
;pipe1Data db 0, 32 , 4 , 2 , 10 ; position 2 bytes, top length, gap, start spriteid
ld a,(ix)
cp 0
jp z, check16
ld a,(ix+1)
dec a
cp 255
jp nz, saveX
ld (ix+1), a
ld a,0
ld (ix), a
jp endMovePipe2
saveX:
ld (ix+1), a
jp endMovePipe2
check16:
ld a,(ix+1)
dec a
cp 48
jp nz, skip1
ld hl,playerScore
inc (hl)
skip1:
cp 16
jp nz, notOffScreen2
ld a,1
ld (ix+0), a
ld a,32
ld (ix+1), a
jp endMovePipe2
notOffScreen2:
ld (ix+1), a
endMovePipe2:
ret
updateScore:
;ld hl, No1
;call loadScore1
;ld hl, No1
;call loadScore2
ld a,(playerScore)
cp 0
jp z, zero
ld a,(playerScore)
cp 1
jp z, one
ld a,(playerScore)
cp 2
jp z, two
ld a,(playerScore)
cp 3
jp z, three
ld a,(playerScore)
cp 4
jp z, four
ld a,(playerScore)
cp 5
jp z, five
ld a,(playerScore)
cp 6
jp z, six
ld a,(playerScore)
cp 7
jp z, seven
ld a,(playerScore)
cp 8
jp z, eight
ld a,(playerScore)
cp 9
jp z, nine
ld hl, No2
call loadScore2
jp endScore2
; not 0-9
jp xone
zero:
ld hl, No1
call loadScore2
jp endScore2
one:
ld hl, No2
call loadScore2
jp endScore2
two:
ld hl, No3
call loadScore2
jp endScore2
three:
ld hl, No4
call loadScore2
jp endScore2
four:
ld hl, No5
call loadScore2
jp endScore2
five:
ld hl, No6
call loadScore2
jp endScore2
six:
ld hl, No7
call loadScore2
jp endScore2
seven:
ld hl, No8
call loadScore2
jp endScore2
eight:
ld hl, No9
call loadScore2
jp endScore2
nine:
ld hl, No10
call loadScore2
jp endScore2
xzero:
ld hl, No1
call loadScore1
jp endScore2
xone:
ld hl, No2
call loadScore1
jp endScore2
xtwo:
ld hl, No3
call loadScore1
jp endScore2
xthree:
ld hl, No4
call loadScore1
jp endScore2
xfour:
ld hl, No5
call loadScore1
jp endScore2
xfive:
ld hl, No6
call loadScore1
jp endScore2
xsix:
ld hl, No7
call loadScore1
jp endScore2
xseven:
ld hl, No8
call loadScore1
jp endScore2
xeight:
ld hl, No9
call loadScore1
jp endScore2
xnine:
ld hl, No10
call loadScore1
jp endScore2
endScore2:
call showScore
ret
drawPipe:
;ix hold pointer to database.
;pipe1Data db 0, 32 , 4 , 2 , 10 ; position 2 bytes, top length, gap, start spriteid
;local variables
;seed data
ld hl, pipeYPos
ld (hl), 32 ; pipe y position - always starts at 32
ld hl, pipeXPos ;
ld a, (ix)
ld (hl), a ; save xpos from databased
ld hl, pipeXPos+1 ;
ld a, (ix+1)
ld (hl), a ; save xpos from databased
ld a,(ix+2)
ld (pipeTopTileCount), a ; counter for top column
ld a,(ix+3)
ld (pipeGap), a ; counter for gap
ld a , (ix+4)
ld (pipeSpriteToUse), a
topPipeLoop:
ld a, (pipeSpriteToUse)
ld bc, $303b
out (c), a ;
ld bc, $57
ld a, (pipeXPos+1) ; xpos >>> 32 on boarder ->> ;; need to make this 32bit
out (c), a
ld a, (pipeYPos) ; ypos ? --- 32 upper ->>>
out (c), a
ld a, 0 ; 7-4 is palette offset, bit 3 is X mirror, bit 2 is Y mirror, bit 1 is rotate flag and bit 0 is X MSB.
; 8 flip x 4 flipy 2 rotate 1 msb
ld a,(pipeXPos) ; if x is on right of screen
out (c), a
ld a, (pipeSpriteToUse)
xor 128
;ld a, 137 ; spite visible pattern 0 ??? ;;128 = 0
out (c), a
ld a, (pipeYPos)
add a,16
ld (pipeYPos), a ; add 16
ld hl, pipeSpriteToUse
inc (hl) ; used next sprite
ld a, (pipeTopTileCount)
dec a
ld (pipeTopTileCount), a
jp nz, topPipeLoop
;; put a cap on it
ld a, (capID)
ld hl, capID
inc (hl)
push af
ld bc, $303b
out (c), a ;
ld bc, $57
ld a, (pipeXPos+1) ; xpos >>> 32 on boarder ->>
out (c), a
ld a, (pipeYPos) ; ypos ? --- 32 upper ->>>
out (c), a
ld a, 4 ; 7-4 is palette offset, bit 3 is X mirror, bit 2 is Y mirror, bit 1 is rotate flag and bit 0 is X MSB.
; 8 flip x 4 flipy 2 rotate 1 msb
ld a,(pipeXPos) ; if x is on right of screen
xor 4
out (c), a
pop af
xor 128
;ld a, 137 ; spite visible pattern 0 ??? ;;128 = 0
out (c), a
ld a, (pipeYPos)
add a,16
ld (pipeYPos), a ; add 16
incGap:
ld a, (pipeYPos)
add a,16
ld (pipeYPos), a ; add 16
ld a, (pipeGap)
dec a
ld (pipeGap), a
jp nz, incGap
;; put a cap on it
ld a, (capID)
ld hl, capID
inc (hl)
push af
ld bc, $303b
out (c), a ;
ld bc, $57
ld a, (pipeXPos+1) ; xpos >>> 32 on boarder ->>
out (c), a
ld a, (pipeYPos) ; ypos ? --- 32 upper ->>>
out (c), a
ld a, 0 ; 7-4 is palette offset, bit 3 is X mirror, bit 2 is Y mirror, bit 1 is rotate flag and bit 0 is X MSB.
; 8 flip x 4 flipy 2 rotate 1 msb
ld a,(pipeXPos) ; if x is on right of screen
out (c), a
pop af
xor 128
;ld a, 137 ; spite visible pattern 0 ??? ;;128 = 0
out (c), a
ld a, (pipeYPos)
add a,16
ld (pipeYPos), a ; add 16
pipeBottomLoop:
sub 208
jp z , donepipe
;ld hl, pipeSpriteToUse
;inc (hl) ; used next sprite
ld a, (pipeSpriteToUse)
; ld a, 11
push af
ld bc, $303b
out (c), a ;
ld bc, $57
ld a, (pipeXPos+1) ; xpos >>> 32 on boarder ->>
out (c), a
ld a, (pipeYPos) ; ypos ? --- 32 upper ->>>
out (c), a
ld a, 0 ; 7-4 is palette offset, bit 3 is X mirror, bit 2 is Y mirror, bit 1 is rotate flag and bit 0 is X MSB.
; 8 flip x 4 flipy 2 rotate 1 msb
ld a,(pipeXPos) ; if x is on right of screen
xor 4
out (c), a
pop af
xor 128
;ld a, 137 ; spite visible pattern 0 ??? ;;128 = 0
out (c), a
ld a, (pipeYPos)
add a,16
ld (pipeYPos), a ; add 16
ld hl, pipeSpriteToUse
inc (hl) ; used next sprite
jp pipeBottomLoop
donepipe:
ret
setupScreen:
ld a, 56
ld (23693),a
call 3503
ld a, 5 ;(2=red, 5 =cyan )
call 8859
ret
loadGameBackground:
ld a, '*' ; use current drive
ld b, FA_READ ; set mode
ld ix, bmp ; filename in ix
ESXDOS F_OPEN
ret c ; return if failed
ld (handle), a ; store handle
ld l, 0 ; seek from start of file
ld bc, 0
ld de, 1078 ; 54 byte header and 1024 palette
ESXDOS F_SEEK
ld a, 3 ; enable write bit and make visible
writeLoop:
push af ; store bitmask
ld bc, $123b ; set port for writing
out (c), a
ld a, (handle) ; restore handle
ld ix, $0 ; read 16k into addr 0
ld bc, $4000
ESXDOS F_READ
pop af ; restore bit mask
add a, 64 ; next page
jr nc, writeLoop
ESXDOS F_CLOSE ; close file
ld bc, $123b ; reset write bit
ld a, 2 ; but keep visible
out (c), a
ret
bmp: db "nbirdbg.bmp"
;bmp: db "bgnew.bmp"
handle: db 0
ret
;column sprite
; 5columns
;total length top to botton 192
;192 /16 = 12
; nothing on bottom row 11
; smallest gap of 11- 2 = 9
; pipe - end = 9 -2 = 7 sprites per colum max, 5 columns = 5 * 7 = 35
; sprite 10-44
; 10 pipe end - sprite 50-59
showSpritex:
push af
ld bc, $303b
out (c), a ;
ld bc, $57
ld a, 128 ; xpos >>> 32 on boarder ->>
out (c), a
ld a, 96 ; ypos ? --- 32 upper ->>>
out (c), a
ld a, 0 ; 7-4 is palette offset, bit 3 is X mirror, bit 2 is Y mirror, bit 1 is rotate flag and bit 0 is X MSB.
; 8 flip x 4 flipy 2 rotate 1 msb
out (c), a
pop af
xor 128
;ld a, 137 ; spite visible pattern 0 ??? ;;128 = 0
out (c), a
ret
;;;column databases
;;load ix with data start for column
showSprite:
push af
;ld a,9
ld bc, $303b
out (c), a ; select sprite 3
ld bc, $57
ld a, (bird_x) ; xpos >>> 32 on boarder ->>
out (c), a
ld a, (bird_y) ; ypos ? --- 32 upper ->>>
out (c), a
ld a, 0 ; 7-4 is palette offset, bit 3 is X mirror, bit 2 is Y mirror, bit 1 is rotate flag and bit 0 is X MSB.
; 8 flip x 4 flipy 2 rotate 1 msb
out (c), a
pop af
xor 128
;ld a, 137 ; spite visible pattern 0 ??? ;;128 = 0
out (c), a
ret
pipeSpriteCount db 40
initPipeSprites:
;ld hl, Pipe
;ld a, 10
ld hl, Pipe
ld a, 10
;loadSpriteData:
ld bc, $303b
out (c), a ;
nextsprite:
ld hl, Pipe
ld de, 256
ld bc, $5b
load_sprite_data_loop:
outi ;reads (hl) and sends to port (c) e.g load the sprite into sprite engine thingy
inc b ; inc a a outi is decrementing it.
dec de
ld a,d
or e
jr nz, load_sprite_data_loop
ld a,(pipeSpriteCount)
dec a
ld (pipeSpriteCount), a
jr nz, nextsprite
ret
pipeEndSpriteCount db 10
initEndPipeSprites:
;ld hl, Pipe
;ld a, 10
ld hl, PipeEnd
ld a, PIPECAPSTART
; loadSpriteData:
ld bc, $303b
out (c), a ;
nextsprite2:
ld hl, PipeEnd
ld de, 256
ld bc, $5b
load_spriteEnd_data_loop:
outi ;reads (hl) and sends to port (c) e.g load the sprite into sprite engine thingy
inc b ; inc a a outi is decrementing it.
dec de
ld a,d
or e
jr nz, load_spriteEnd_data_loop
ld a,(pipeEndSpriteCount)
dec a
ld (pipeEndSpriteCount), a
jr nz, nextsprite2
ret
loadScore1:
ld a, SCOREID1
;ld hl,No1
ld bc, $303b
out (c), a ;
ld de, 256
ld bc, $5b
load_score_loopx1:
outi ;reads (hl) and sends to port (c) e.g load the sprite into sprite engine thingy
inc b ; inc a a outi is decrementing it.
dec de
ld a,d
or e
jr nz, load_score_loopx1
ret
loadScore2:
ld a, SCOREID2
;ld hl,No2
ld bc, $303b
out (c), a ;
ld de, 256
ld bc, $5b
load_score_loopx2:
outi ;reads (hl) and sends to port (c) e.g load the sprite into sprite engine thingy
inc b ; inc a a outi is decrementing it.
dec de
ld a,d
or e
jr nz, load_score_loopx2
ret
showScore:
ld a, SCOREID1