-
Notifications
You must be signed in to change notification settings - Fork 0
/
ems.s
2870 lines (2797 loc) · 41.6 KB
/
ems.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
;
; File generated by cc65 v 2.19 - Git b993d8833
;
.fopt compiler,"cc65 v 2.19 - Git b993d8833"
.setcpu "6502"
.smart on
.autoimport on
.case on
.debuginfo off
.importzp sp, sreg, regsave, regbank
.importzp tmp1, tmp2, tmp3, tmp4, ptr1, ptr2, ptr3, ptr4
.macpack longbranch
.forceimport __STARTUP__
.import _pal_bg
.import _pal_spr
.import _ppu_wait_nmi
.import _ppu_off
.import _ppu_on_all
.import _ppu_system
.import _oam_clear
.import _oam_spr
.import _sfx_play
.import _pad_poll
.import _rand8
.import _vram_adr
.import _vram_put
.import _get_pad_new
.import _get_cpu_status
.export _pad1
.export _pad1Next
.export _accumulator
.export _x
.export _p
.export _p_temp
.export _mouse_speed
.export _temp
.export _flags
.export _albert_palette
.export _palSprites
.export _palette
.export _i
.export _j
.export _spr
.export _menuIndexH
.export _menuIndexV
.export _page
.export _cursorX
.export _cursorY
.export _cpu_status
.export _can_jump
.export _mario_vel_y
.export _mario_pos_y
.export _eval_pos
.export _put_str
.export _draw_cursor_data
.export _draw_accumulator
.export _draw_cpu_status
.export _draw_albert
.export _draw_mario
.export _update_mario
.export _handleMenuInput
.export _hover
.export _main
.segment "DATA"
_pad1:
.byte $00
_pad1Next:
.byte $00
_accumulator:
.word $0000
_x:
.byte $00
_p:
.byte $00
_p_temp:
.byte $00
_mouse_speed:
.byte $02
_temp:
.byte $00
_flags:
.byte $4E
.byte $56
.byte $31
.byte $42
.byte $44
.byte $49
.byte $5A
.byte $43
_albert_palette:
.byte $00
_j:
.byte $00
_spr:
.byte $00
_menuIndexH:
.byte $00
_menuIndexV:
.byte $00
_page:
.byte $00
_cursorX:
.byte $80
_cursorY:
.byte $78
_cpu_status:
.byte $00
_can_jump:
.byte $00
_mario_vel_y:
.byte $00
_mario_pos_y:
.byte $78
.segment "RODATA"
_palSprites:
.byte $0F
.byte $09
.byte $26
.byte $11
.byte $0F
.byte $27
.byte $18
.byte $05
.byte $0F
.byte $15
.byte $25
.byte $19
.byte $0F
.byte $19
.byte $29
.byte $38
_palette:
.byte $0F
.byte $00
.byte $10
.byte $30
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
S0002:
.byte $4D,$75,$73,$65,$75,$6D,$20,$45,$6D,$75,$6C,$61,$74,$69,$6F,$6E
.byte $20,$53,$79,$73,$74,$65,$6D,$73,$00
S0004:
.byte $41,$75,$74,$68,$6F,$72,$3A,$20,$42,$65,$74,$6F,$20,$50,$65,$72
.byte $65,$7A,$00
S000B:
.byte $20,$20,$20,$20,$20,$20,$20,$2A,$20,$2F,$20,$43,$00
S0009:
.byte $20,$20,$20,$35,$20,$36,$20,$37,$20,$38,$20,$39,$00
S0008:
.byte $58,$3A,$20,$30,$20,$31,$20,$32,$20,$33,$20,$34,$00
S0003:
.byte $56,$69,$64,$65,$6F,$20,$6D,$6F,$64,$65,$3A,$00
S000A:
.byte $41,$20,$20,$20,$58,$3A,$20,$2B,$20,$2D,$00
S000D:
.byte $50,$4F,$53,$20,$58,$3A,$20,$00
S000E:
.byte $50,$4F,$53,$20,$59,$3A,$20,$00
S0005:
.byte $4E,$54,$53,$43,$00
S0006:
.byte $50,$41,$4C,$00
S000C:
.byte $50,$3A,$20,$00
S0007:
.byte $41,$3A,$20,$00
.segment "BSS"
_ball_x:
.res 8,$00
_ball_y:
.res 8,$00
_ball_dx:
.res 8,$00
_ball_dy:
.res 8,$00
_i:
.res 1,$00
; ---------------------------------------------------------------
; unsigned char __near__ eval_pos (void)
; ---------------------------------------------------------------
.segment "CODE"
.proc _eval_pos: near
.segment "CODE"
;
; if((cursorX > 30 && cursorX < 101) && (cursorY > 134 && cursorY < 150)){
;
ldx #$00
lda _cursorX
cmp #$1F
lda #$00
ldx #$00
rol a
jeq L0003
ldx #$00
lda _cursorX
cmp #$65
jsr boolult
jne L0004
L0003: ldx #$00
lda #$00
jeq L0005
L0004: ldx #$00
lda #$01
L0005: jeq L0006
ldx #$00
lda _cursorY
cmp #$87
lda #$00
ldx #$00
rol a
jeq L0007
ldx #$00
lda _cursorY
cmp #$96
jsr boolult
jne L0008
L0007: ldx #$00
lda #$00
jeq L0009
L0008: ldx #$00
lda #$01
L0009: jne L000A
L0006: ldx #$00
lda #$00
jeq L000B
L000A: ldx #$00
lda #$01
L000B: jeq L0021
;
; if(cursorY < 143){
;
ldx #$00
lda _cursorY
cmp #$8F
jsr boolult
jeq L000C
;
; if(cursorX > 30 && cursorX < 38) return (unsigned char)0;
;
ldx #$00
lda _cursorX
cmp #$1F
lda #$00
ldx #$00
rol a
jeq L000E
ldx #$00
lda _cursorX
cmp #$26
jsr boolult
jne L000F
L000E: ldx #$00
lda #$00
jeq L0010
L000F: ldx #$00
lda #$01
L0010: jeq L000D
ldx #$00
lda #$00
jmp L006A
;
; if(cursorX > 46 && cursorX < 54) return (unsigned char)1;
;
L000D: ldx #$00
lda _cursorX
cmp #$2F
lda #$00
ldx #$00
rol a
jeq L0012
ldx #$00
lda _cursorX
cmp #$36
jsr boolult
jne L0013
L0012: ldx #$00
lda #$00
jeq L0014
L0013: ldx #$00
lda #$01
L0014: jeq L0011
ldx #$00
lda #$01
jmp L006A
;
; if(cursorX > 62 && cursorX < 70) return (unsigned char)2;
;
L0011: ldx #$00
lda _cursorX
cmp #$3F
lda #$00
ldx #$00
rol a
jeq L0016
ldx #$00
lda _cursorX
cmp #$46
jsr boolult
jne L0017
L0016: ldx #$00
lda #$00
jeq L0018
L0017: ldx #$00
lda #$01
L0018: jeq L0015
ldx #$00
lda #$02
jmp L006A
;
; if(cursorX > 78 && cursorX < 86) return (unsigned char)3;
;
L0015: ldx #$00
lda _cursorX
cmp #$4F
lda #$00
ldx #$00
rol a
jeq L001A
ldx #$00
lda _cursorX
cmp #$56
jsr boolult
jne L001B
L001A: ldx #$00
lda #$00
jeq L001C
L001B: ldx #$00
lda #$01
L001C: jeq L0019
ldx #$00
lda #$03
jmp L006A
;
; if(cursorX > 94 && cursorX < 102) return (unsigned char)4;
;
L0019: ldx #$00
lda _cursorX
cmp #$5F
lda #$00
ldx #$00
rol a
jeq L001E
ldx #$00
lda _cursorX
cmp #$66
jsr boolult
jne L001F
L001E: ldx #$00
lda #$00
jeq L0020
L001F: ldx #$00
lda #$01
L0020: jeq L001D
ldx #$00
lda #$04
jmp L006A
;
; return 255;
;
L001D: ldx #$00
lda #$FF
jmp L006A
;
; else{
;
jmp L0021
;
; if(cursorX > 30 && cursorX < 38) return (unsigned char)5;
;
L000C: ldx #$00
lda _cursorX
cmp #$1F
lda #$00
ldx #$00
rol a
jeq L0023
ldx #$00
lda _cursorX
cmp #$26
jsr boolult
jne L0024
L0023: ldx #$00
lda #$00
jeq L0025
L0024: ldx #$00
lda #$01
L0025: jeq L0022
ldx #$00
lda #$05
jmp L006A
;
; if(cursorX > 46 && cursorX < 54) return (unsigned char)6;
;
L0022: ldx #$00
lda _cursorX
cmp #$2F
lda #$00
ldx #$00
rol a
jeq L0027
ldx #$00
lda _cursorX
cmp #$36
jsr boolult
jne L0028
L0027: ldx #$00
lda #$00
jeq L0029
L0028: ldx #$00
lda #$01
L0029: jeq L0026
ldx #$00
lda #$06
jmp L006A
;
; if(cursorX > 62 && cursorX < 70) return (unsigned char)7;
;
L0026: ldx #$00
lda _cursorX
cmp #$3F
lda #$00
ldx #$00
rol a
jeq L002B
ldx #$00
lda _cursorX
cmp #$46
jsr boolult
jne L002C
L002B: ldx #$00
lda #$00
jeq L002D
L002C: ldx #$00
lda #$01
L002D: jeq L002A
ldx #$00
lda #$07
jmp L006A
;
; if(cursorX > 78 && cursorX < 86) return (unsigned char)8;
;
L002A: ldx #$00
lda _cursorX
cmp #$4F
lda #$00
ldx #$00
rol a
jeq L002F
ldx #$00
lda _cursorX
cmp #$56
jsr boolult
jne L0030
L002F: ldx #$00
lda #$00
jeq L0031
L0030: ldx #$00
lda #$01
L0031: jeq L002E
ldx #$00
lda #$08
jmp L006A
;
; if(cursorX > 94 && cursorX < 102) return (unsigned char)9;
;
L002E: ldx #$00
lda _cursorX
cmp #$5F
lda #$00
ldx #$00
rol a
jeq L0033
ldx #$00
lda _cursorX
cmp #$66
jsr boolult
jne L0034
L0033: ldx #$00
lda #$00
jeq L0035
L0034: ldx #$00
lda #$01
L0035: jeq L0032
ldx #$00
lda #$09
jmp L006A
;
; return 255;
;
L0032: ldx #$00
lda #$FF
jmp L006A
;
; if((cursorX > 63 && cursorX < 102) && (cursorY > 158 && cursorY < 174)){
;
L0021: ldx #$00
lda _cursorX
cmp #$40
lda #$00
ldx #$00
rol a
jeq L0037
ldx #$00
lda _cursorX
cmp #$66
jsr boolult
jne L0038
L0037: ldx #$00
lda #$00
jeq L0039
L0038: ldx #$00
lda #$01
L0039: jeq L003A
ldx #$00
lda _cursorY
cmp #$9F
lda #$00
ldx #$00
rol a
jeq L003B
ldx #$00
lda _cursorY
cmp #$AE
jsr boolult
jne L003C
L003B: ldx #$00
lda #$00
jeq L003D
L003C: ldx #$00
lda #$01
L003D: jne L003E
L003A: ldx #$00
lda #$00
jeq L003F
L003E: ldx #$00
lda #$01
L003F: jeq L0049
;
; if(cursorY < 166){
;
ldx #$00
lda _cursorY
cmp #$A6
jsr boolult
jeq L0040
;
; if(cursorX > 63 && cursorX < 70) return (unsigned char) 0x0B;
;
ldx #$00
lda _cursorX
cmp #$40
lda #$00
ldx #$00
rol a
jeq L0042
ldx #$00
lda _cursorX
cmp #$46
jsr boolult
jne L0043
L0042: ldx #$00
lda #$00
jeq L0044
L0043: ldx #$00
lda #$01
L0044: jeq L0041
ldx #$00
lda #$0B
jmp L006A
;
; if(cursorX > 79 && cursorX < 87) return (unsigned char) 0x0D;
;
L0041: ldx #$00
lda _cursorX
cmp #$50
lda #$00
ldx #$00
rol a
jeq L0046
ldx #$00
lda _cursorX
cmp #$57
jsr boolult
jne L0047
L0046: ldx #$00
lda #$00
jeq L0048
L0047: ldx #$00
lda #$01
L0048: jeq L0045
ldx #$00
lda #$0D
jmp L006A
;
; return 255;
;
L0045: ldx #$00
lda #$FF
jmp L006A
;
; else{
;
jmp L0049
;
; if(cursorX > 63 && cursorX < 70) return 0x0A;
;
L0040: ldx #$00
lda _cursorX
cmp #$40
lda #$00
ldx #$00
rol a
jeq L004B
ldx #$00
lda _cursorX
cmp #$46
jsr boolult
jne L004C
L004B: ldx #$00
lda #$00
jeq L004D
L004C: ldx #$00
lda #$01
L004D: jeq L004A
ldx #$00
lda #$0A
jmp L006A
;
; if(cursorX > 79 && cursorX < 87) return 0x0F;
;
L004A: ldx #$00
lda _cursorX
cmp #$50
lda #$00
ldx #$00
rol a
jeq L004F
ldx #$00
lda _cursorX
cmp #$57
jsr boolult
jne L0050
L004F: ldx #$00
lda #$00
jeq L0051
L0050: ldx #$00
lda #$01
L0051: jeq L004E
ldx #$00
lda #$0F
jmp L006A
;
; if(cursorX > 95 && cursorX < 104) return 'C';
;
L004E: ldx #$00
lda _cursorX
cmp #$60
lda #$00
ldx #$00
rol a
jeq L0053
ldx #$00
lda _cursorX
cmp #$68
jsr boolult
jne L0054
L0053: ldx #$00
lda #$00
jeq L0055
L0054: ldx #$00
lda #$01
L0055: jeq L0052
ldx #$00
lda #$43
jmp L006A
;
; return 255;
;
L0052: ldx #$00
lda #$FF
jmp L006A
;
; if((cursorX > 207 && cursorX < 255) && (cursorY > 15 && cursorY < 73)) return 32;
;
L0049: ldx #$00
lda _cursorX
cmp #$D0
lda #$00
ldx #$00
rol a
jeq L0057
ldx #$00
lda _cursorX
cmp #$FF
jsr boolult
jne L0058
L0057: ldx #$00
lda #$00
jeq L0059
L0058: ldx #$00
lda #$01
L0059: jeq L005A
ldx #$00
lda _cursorY
cmp #$10
lda #$00
ldx #$00
rol a
jeq L005B
ldx #$00
lda _cursorY
cmp #$49
jsr boolult
jne L005C
L005B: ldx #$00
lda #$00
jeq L005D
L005C: ldx #$00
lda #$01
L005D: jne L005E
L005A: ldx #$00
lda #$00
jeq L005F
L005E: ldx #$00
lda #$01
L005F: jeq L0056
ldx #$00
lda #$20
jmp L006A
;
; if((cursorX > 141 && cursorX < 155) && (cursorY > 119 && cursorY < 136)) return 33;
;
L0056: ldx #$00
lda _cursorX
cmp #$8E
lda #$00
ldx #$00
rol a
jeq L0061
ldx #$00
lda _cursorX
cmp #$9B
jsr boolult
jne L0062
L0061: ldx #$00
lda #$00
jeq L0063
L0062: ldx #$00
lda #$01
L0063: jeq L0064
ldx #$00
lda _cursorY
cmp #$78
lda #$00
ldx #$00
rol a
jeq L0065
ldx #$00
lda _cursorY
cmp #$88
jsr boolult
jne L0066
L0065: ldx #$00
lda #$00
jeq L0067
L0066: ldx #$00
lda #$01
L0067: jne L0068
L0064: ldx #$00
lda #$00
jeq L0069
L0068: ldx #$00
lda #$01
L0069: jeq L0060
ldx #$00
lda #$21
jmp L006A
;
; else return (unsigned char)255;
;
jmp L006A
L0060: ldx #$00
lda #$FF
jmp L006A
;
; }
;
L006A: rts
.endproc
; ---------------------------------------------------------------
; void __near__ put_str (unsigned int adr, const char *str)
; ---------------------------------------------------------------
.segment "CODE"
.proc _put_str: near
.segment "CODE"
;
; void put_str(unsigned int adr, const char* str){
;
jsr pushax
;
; vram_adr(adr);
;
ldy #$03
jsr ldaxysp
jsr _vram_adr
;
; while(1){
;
jmp L0004
;
; if(!*str)break;
;
L0002: ldy #$01
jsr ldaxysp
ldy #$00
jsr ldauidx
jsr bnega
jeq L0005
jmp L0003
;
; vram_put((*str++));
;
L0005: ldy #$01
jsr ldaxysp
ldy #$00
jsr ldauidx
pha
ldy #$00
ldx #$00
lda #$01
jsr addeqysp
pla
jsr _vram_put
;
; while(1){
;
L0004: jmp L0002
;
; }
;
L0003: jsr incsp4
rts
.endproc
; ---------------------------------------------------------------
; void __near__ draw_cursor_data (void)
; ---------------------------------------------------------------
.segment "CODE"
.proc _draw_cursor_data: near
.segment "CODE"
;
; oam_spr(80, 215,((cursorX % 10) + 0x30), 0x0);
;
ldx #$00
lda #$50
jsr pusha
ldx #$00
lda #$D7
jsr pusha
ldx #$00
lda _cursorX
jsr pushax
ldx #$00
lda #$0A
jsr tosumodax
ldy #$30
jsr incaxy
ldx #$00
jsr pusha
ldx #$00
lda #$00
jsr _oam_spr
;
; oam_spr(72, 215, (((cursorX / 10) % 10) + 0x30), 0x0);
;
ldx #$00
lda #$48
jsr pusha
ldx #$00
lda #$D7
jsr pusha
ldx #$00
lda _cursorX
jsr pushax
ldx #$00
lda #$0A
jsr tosudivax
jsr pushax
ldx #$00
lda #$0A
jsr tosmodax
ldy #$30
jsr incaxy
ldx #$00
jsr pusha
ldx #$00
lda #$00
jsr _oam_spr
;
; oam_spr(64, 215, (((cursorX / 100) % 10) + 0x30), 0x0);
;
ldx #$00
lda #$40
jsr pusha
ldx #$00
lda #$D7
jsr pusha
ldx #$00
lda _cursorX
jsr pushax
ldx #$00
lda #$64
jsr tosudivax
jsr pushax
ldx #$00
lda #$0A
jsr tosmodax
ldy #$30
jsr incaxy
ldx #$00
jsr pusha
ldx #$00
lda #$00
jsr _oam_spr
;
; oam_spr(80, 223,((cursorY % 10) + 0x30), 0x0);
;
ldx #$00
lda #$50
jsr pusha
ldx #$00
lda #$DF
jsr pusha
ldx #$00
lda _cursorY
jsr pushax
ldx #$00
lda #$0A
jsr tosumodax
ldy #$30
jsr incaxy
ldx #$00
jsr pusha
ldx #$00
lda #$00
jsr _oam_spr
;
; oam_spr(72, 223, (((cursorY / 10) % 10) + 0x30), 0x0);
;
ldx #$00
lda #$48
jsr pusha
ldx #$00
lda #$DF
jsr pusha
ldx #$00
lda _cursorY
jsr pushax
ldx #$00
lda #$0A
jsr tosudivax
jsr pushax
ldx #$00
lda #$0A
jsr tosmodax
ldy #$30
jsr incaxy
ldx #$00