-
Notifications
You must be signed in to change notification settings - Fork 0
/
beep.lst
14976 lines (14976 loc) · 585 KB
/
beep.lst
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
#[1] beep.s
5
6 0000 .ifdef _SGX
8 .endif
9 0000 .ifdef _AC
11 .endif
12
13 ; first, set MOUSE to default on:
14 ;
15 0001 SUPPORT_MOUSE .equ 1
16
18
19 0001 .ifdef HUC
#[3] huc.inc
20 .include "huc.inc"
1 ;
2 ; Hu-C internal include file
3 ;
4
5
6 ; variables
7 ; ----
8
9 2000 .zp
10 --:2000 __sp
11 --:2000 __stack .ds 2
12 --:2002 __temp .ds 4
13 --:2006 __ptr .ds 2
14 --:2008 __fbank .ds 1
15 --:2009 __fptr .ds 2
16 0000 .ifdef HAVE_LIB3
18 .endif
19
20 ; macros
21 ; ----
22
23 .macro __farptr
24 ldy #bank(\1)
25 sty \2
26 ldy #low(\1)
27 sty \3
28 ldy #high(\1) & $1F
29 sty \3+1
30 .endm
31
32 .macro __farptr_i
33 sax
34 add #low(\1)
35 .if (\# = 3)
36 sta <\3
37 .else
38 sta <__fptr
39 .endif
40 sax
41 adc #high(\1) & $1F
42 .if (\# = 3)
43 sta <\3+1
44 .else
45 tax
46 .endif
47 rol A
48 rol A
49 rol A
50 rol A
51 and #$F
52 add #bank(\1)
53 .if (\# = 3)
54 sta <\2
55 .endif
56 .endm
57
58 .macro __farptr_get
59 stx <\1
60 ldy #2
61 lda [__ptr],Y
62 sta <\2
63 iny
64 lda [__ptr],Y
65 sta <\2+1
66 .endm
67
68 .macro __fgetb
69 tam #3
70 txa
71 and #$1F
72 ora #$60
73 sta <__fptr+1
74 lda [__fptr]
75 tax
76 bpl .x_\@
77 dec A
78 .x_\@:
79 .endm
80
81 .macro __fgetub
82 tam #3
83 txa
84 and #$1F
85 ora #$60
86 sta <__fptr+1
87 lda [__fptr]
88 tax
89 cla
90 .endm
91
92 __phax .macro
93 pha
94 phx
95 .endm
96 __plax .macro
97 plx
98 pla
99 .endm
100 __plxa .macro
101 pla
102 plx
103 .endm
104
105 __ldb .macro
106 .if (\# = 2)
107 clx
108 lda \1
109 clc
110 adc #low(\2)
111 sax
112 adc #high(\2)
113 .else
114 ldx \1
115 __extw
116 .endif
117 .endm
118
119 __ldby: .macro
120 ldx \1, y
121 __extw
122 .endm
123
124 __ldub .macro
125 .if (\# = 2)
126 clx
127 lda \1
128 clc
129 adc #low(\2)
130 sax
131 .else
132 ldx \1
133 cla
134 .endif
135 .endm
136
137 __ldbp .macro
138 lda [\1]
139 tax
140 __extw
141 .endm
142
143 __ldubp .macro
144 lda [\1]
145 tax
146 cla
147 .endm
148
149 __stbps .macro
150 __phax
151 __ldwp __stack
152 __stw <__ptr
153 __plxa
154 sta [__ptr]
155 sax
156 __addmi 2,__stack
157 .endm
158
159 __ldw .macro
160 .if (\# = 2)
161 lda \1
162 clc
163 adc #low(\2)
164 tax
165 lda \1+1
166 adc #high(\2)
167 .else
168 ldx \1
169 lda \1+1
170 .endif
171 .endm
172
173 __ldwp .macro
174 lda [\1]
175 tax
176 ldy #1
177 lda [\1],Y
178 .endm
179
180 __ldwi .macro
181 ldx #low(\1)
182 lda #high(\1)
183 .endm
184
185 __stw .macro
186 stx \1
187 sta \1+1
188 .endm
189
190 __stwi .macro
191 ldx #low(\2)
192 stx \1
193 lda #high(\2)
194 sta \1 + 1
195 .endm
196
197 __stbi .macro
198 ldx #low(\2)
199 stx \1
200 cla
201 .endm
202
203 __stwz .macro
204 stz \1
205 stz \1 + 1
206 .endm
207
208 __stwp .macro
209 sax
210 sta [\1]
211 sax
212 ldy #1
213 sta [\1],Y
214 .endm
215
216 __stbp .macro
217 sax
218 sta [\1]
219 sax
220 .endm
221
222 __stwps .macro
223 __phax
224 __ldwp __stack
225 __stw <__ptr
226 __plax
227 __stwp __ptr
228 __addmi 2,__stack
229 .endm
230
231 __stwip .macro
232 __stw __ptr
233 lda #low(\1)
234 tax
235 sta [__ptr]
236 lda #high(\1)
237 ldy #1
238 sta [__ptr],Y
239 .endm
240
241 __stbip .macro
242 __stw __ptr
243 lda #low(\1)
244 sta [__ptr]
245 tax
246 cla
247 .endm
248
249 __pushw .macro
250 .ifndef SMALL
251 ldy <__stack
252 bne .x_\@
253 dec <__stack + 1
254 .endif
255 .x_\@: dec <__stack
256 sta [__stack]
257 .ifndef SMALL
258 bne .y_\@
259 dec <__stack + 1
260 .endif
261 .y_\@: dec <__stack
262 sax
263 sta [__stack]
264 sax
265 .endm
266
267 __popw .macro
268 lda [__stack]
269 tax
270 ldy #1
271 lda [__stack],Y
272 __addmi 2,__stack
273 .endm
274
275 __calls .macro
276 pha
277 ldy #\1
278 lda [__stack],Y
279 sta <__ptr
280 .ifndef SMALL
281 incw <__stack
282 .else
283 inc <__stack
284 .endif
285 lda [__stack],Y
286 sta <__ptr+1
287 .ifndef SMALL
288 incw <__stack
289 .else
290 inc <__stack
291 .endif
292 pla
293 jsr hook
294 .endm
295
296 __swapw .macro
297 pha
298 ldy #1
299 lda [__stack],Y
300 sta <__temp
301 lda [__stack]
302 sax
303 sta [__stack]
304 pla
305 sta [__stack],Y
306 lda <__temp
307 .endm
308
309
310 ; TODO : check if we need pha/pla or not
311 __tstw .macro
312 ; pha
313 stx <__temp
314 ora <__temp
315 cla
316 clx
317 beq .x_\@
318 inx
319 .x_\@:
320 ; pla
321 .endm
322
323 __lsrw .macro
324 lsr A
325 sax
326 ror A
327 sax
328 .endm
329
330 __aslw .macro
331 sax
332 asl A
333 sax
334 rol A
335 .endm
336
337 __aslwi .macro
338 .if (\1 = 1)
339 __aslw
340 .else
341 .if (\1 = 2)
342 __aslw
343 __aslw
344 .else
345 .if (\1 = 8)
346 txa
347 clx
348 .else
349 ldy #\1
350 jsr aslzp
351 .endif
352 .endif
353 .endif
354 .endm
355
356 __aslws .macro
357 lda [__stack]
358 asl a
359 sta [__stack]
360 ldy #1
361 lda [__stack],Y
362 rol a
363 sta [__stack],Y
364 .endm
365
366 __asrw .macro
367 cmp #$80
368 ror A
369 sax
370 ror A
371 sax
372 .endm
373
374 __asrwi .macro
375 .if (\1 = 1)
376 __asrw
377 .else
378 .if (\1 = 2)
379 __asrw
380 __asrw
381 .else
382 .if (\1 = 8)
383 tax
384 cmp #$80
385 cla
386 bcc .x_\@
387 dec a
388 .x_\@:
389 .else
390 ldy #\1
391 jsr asrzp
392 .endif
393 .endif
394 .endif
395 .endm
396
397 __lsrwi .macro
398 .if (\1 = 1)
399 __lsrw
400 .else
401 .if (\1 = 2)
402 __lsrw
403 __lsrw
404 .else
405 .if (\1 = 8)
406 tax
407 cla
408 .else
409 ldy #\1
410 jsr lsrzp
411 .endif
412 .endif
413 .endif
414 .endm
415
416 __extw .macro
417 txa ; signed
418 cla
419 bpl .x_\@
420 dec A
421 .x_\@:
422 .endm
423
424 __comw .macro
425 sax
426 eor #$FF
427 sax
428 eor #$FF
429 .endm
430
431 __negw .macro
432 sax
433 eor #$FF
434 clc
435 adc #1
436 sax
437 eor #$FF
438 adc #0
439 .endm
440
441 __boolw .macro
442 stx <__temp
443 ora <__temp
444 clx
445 beq .x\@
446 inx
447 .x\@ cla
448 .endm
449
450 __notw .macro
451 stx <__temp
452 ora <__temp
453 clx
454 bne .x\@
455 inx
456 .x\@ cla
457 .endm
458
459 __addw .macro
460 clc
461 sax
462 adc \1
463 sax
464 adc \1+1
465 .endm
466
467 __addb .macro
468 clc
469 sax
470 adc \1
471 sax
472 ldy \1
473 bpl .x\@
474 dec a
475 .x\@: adc #0
476 .endm
477
478 __addub .macro
479 clc
480 sax
481 adc \1
482 sax
483 adc #0
484 .endm
485
486 __addwi .macro
487 .if (\1 = 1)
488 cpx #$ff
489 inx
490 adc #0
491 .else
492 .if (\1 = 2)
493 cpx #$fe
494 inx
495 inx
496 adc #0
497 .else
498 clc
499 sax
500 adc #low(\1)
501 sax
502 adc #high(\1)
503 .endif
504 .endif
505 .endm
506
507 ; pceas workaround; the regular __addwi doesn't work if the argument is
508 ; symbolic because the code size changes as it is resolved.
509 __addwi_sym .macro
510 clc
511 sax
512 adc #low(\1)
513 sax
514 adc #high(\1)
515 .endm
516
517 __mulwi .macro
518 .if (\1 = 2)
519 __aslw
520 .else
521 .if (\1 = 3)
522 __stw <__temp
523 __aslw
524 __addw <__temp
525 .else
526 .if (\1 = 4)
527 __aslw
528 __aslw
529 .else
530 .if (\1 = 5)
531 __stw <__temp
532 __aslw
533 __aslw
534 __addw <__temp
535 .else
536 .if (\1 = 6)
537 __aslw
538 __stw <__temp
539 __aslw
540 __addw <__temp
541 .else
542 .if (\1 = 7)
543 __stw <__temp
544 __aslw
545 __aslw
546 __aslw
547 __subw <__temp
548 .else
549 .if (\1 = 8)
550 __aslw
551 __aslw
552 __aslw
553 .else
554 .if (\1 = 9)
555 __stw <__temp
556 __aslw
557 __aslw
558 __aslw
559 __addw <__temp
560 .else
561 .if (\1 = 10)
562 __aslw
563 __stw <__temp
564 __aslw
565 __aslw
566 __addw <__temp
567 .else
568 __pushw
569 __ldwi \1
570 jsr umul
571 .endif
572 .endif
573 .endif
574 .endif
575 .endif
576 .endif
577 .endif
578 .endif
579 .endif
580 .endm
581
582 __addbi .macro
583 .if (\1 = 1)
584 inx
585 .else
586 .if (\1 = 2)
587 inx
588 inx
589 .else
590 .if (\1 = 3)
591 inx
592 inx
593 inx
594 .else
595 clc
596 txa
597 adc #low(\1)
598 tax
599 .endif
600 .endif
601 .endif
602 cla
603 .endm
604
605 0000 .ifdef SMALL
642 .else ; SMALL
643
644 __addmi1 .macro ; 10(14)
645 inc <\1 ; 6
646 bne .x\@ ; 4(2)
647 inc <\1+1 ; 0(6)
648 .x\@:
649 .endm
650
651 __submi1 .macro ; 14(18)
652 ldy <\1 ; 4
653 bne .x\@ ; 4(2)
654 dec <\1+1 ; 0(6)
655 .x\@:
656 dec <\1 ; 6
657 .endm
658
659 __addmi .macro
660 .if (\1 = 1)
661 __addmi1 \2
662 .else
663 .if (\1 = -1)
664 __submi1 \2
665 .else
666 tay ; 2
667 clc ; 2
668 lda <\2 ; 4
669 adc #low(\1) ; 2
670 sta <\2 ; 4
671 .if (\1 < 256) & (\1 >= 0)
672 bcc .x\@ ; 4(2)
673 inc <\2+1 ; 0(6)
674 .x\@:
675 .else
676 .if (\1 >= -256) & (\1 < 0)
677 bcs .y\@ ; 4(2)
678 dec <\2+1 ; 0(6)
679 .y\@:
680 .else
681 lda <\2+1 ; 4
682 adc #high(\1) ; 2
683 sta <\2+1 ; 4
684 .endif
685 .endif
686 tya ; 2 => 20(24) / 26
687 .endif
688 .endif
689 .endm
690
691 __addmi_sym .macro
692 tay ; 2
693 clc ; 2
694 lda <\2 ; 4
695 adc #low(\1) ; 2
696 sta <\2 ; 4
697 lda <\2+1 ; 4
698 adc #high(\1) ; 2
699 sta <\2+1 ; 4
700 tya ; 2 => 20(24) / 26
701 .endm
702
703 .endif ; SMALL
704
705 __subw .macro
706 sec
707 sax
708 sbc \1
709 sax
710 sbc \1+1
711 .endm
712
713 __subwi .macro
714 .if (\1 = 1)
715 cpx #1
716 dex
717 sbc #0
718 .else
719 .if (\1 = 2)
720 cpx #2
721 dex
722 dex
723 sbc #0
724 .else
725 sec
726 sax
727 sbc #low(\1)
728 sax
729 sbc #high(\1)
730 .endif
731 .endif
732 .endm
733
734 __submi .macro
735 pha
736 sec
737 lda <\2
738 sbc #low(\1)
739 sta <\2
740 lda <\2+1
741 sbc #high(\1)
742 sta <\2+1
743 pla
744 .endm
745
746 __addws .macro
747 sax
748 clc
749 adc [__stack]
750 sax
751 ldy #1
752 adc [__stack],Y
753 __addmi 2, __stack
754 .endm
755
756 __addbs .macro
757 txa
758 clc
759 adc [__stack]
760 tax
761 cla
762 __addmi 2, __stack
763 .endm
764
765 __subws .macro
766 stx <__temp
767 sta <__temp+1
768 sec
769 lda [__stack]
770 sbc <__temp
771 tax
772 ldy #1
773 lda [__stack],Y
774 sbc <__temp+1
775 __addmi 2, __stack
776 .endm
777
778 __orws .macro
779 sax
780 ora [__stack]
781 sax
782 ldy #1
783 ora [__stack],Y
784 __addmi 2,__stack
785 .endm
786
787 __orwi .macro
788 sax
789 ora #low(\1)
790 sax
791 ora #high(\1)
792 .endm
793
794 __orw .macro
795 sax
796 ora \1
797 sax
798 ora \1+1
799 .endm
800
801 __andws .macro
802 sax
803 and [__stack]
804 sax
805 ldy #1
806 and [__stack],Y
807 __addmi 2,__stack
808 .endm
809
810 __andwi .macro
811 sax
812 and #low(\1)
813 sax
814 and #high(\1)
815 .endm
816
817 __andw .macro
818 sax
819 and \1
820 sax
821 and \1+1
822 .endm
823
824 __eorwi .macro
825 sax
826 eor #low(\1)
827 sax
828 eor #high(\1)
829 .endm
830
831 __eorws .macro
832 sax
833 eor [__stack]
834 sax
835 ldy #1
836 eor [__stack],Y
837 __addmi 2,__stack
838 .endm
839
840 __lbra .macro
841 jmp \1
842 .endm
843
844 __lbran .macro
845 bra \1
846 .endm
847
848 __lbeq .macro
849 cpx #0
850 bne .x\@
851 jmp \1
852 .x\@
853 .endm
854
855 __lbeqn .macro
856 cpx #0
857 beq \1
858 .endm
859
860 __lbne .macro
861 cpx #0
862 beq .x\@
863 jmp \1
864 .x\@
865 .endm
866
867 __lbnen .macro
868 cpx #0
869 bne \1
870 .endm
871
872 __cmpwi_eq .macro
873 cpx #low(\1)
874 clx
875 bne .f\@
876 cmp #high(\1)
877 bne .f\@
878 ldx #1
879 .f\@: cla
880 .endm
881
882 __cmpwi_ne .macro
883 cpx #low(\1)
884 clx
885 bne .t\@
886 cmp #high(\1)
887 beq .f\@
888 .t\@: ldx #1
889 .f\@: cla
890 .endm
891
892 __call .macro
893 call \1
894 .endm
895
896 _set_bgpal .macro
897 set_bgpal \1,\2,\3
898 .endm
899
900 _set_sprpal .macro
901 set_sprpal \1,\2,\3
902 .endm
903
904 _load_background .macro
905 vload $1000,\1,#$4000
906 vsync
907 set_bgpal #0, \2,#16
908 batcpy #$0, \3, \4, \5
909 .endm
910
911 __map_callbank .macro
912 .if (PAGE(\1) = 5) ; user function
913 tay
914 tma #4
915 pha
916 lda #_call_bank
917 tam #4
918 tya
919 .endif
920 .endm
921
922 __unmap_callbank .macro
923 .if (PAGE(\1) = 5) ; user function
924 tay
925 pla
926 tam #4
927 tya
928 .endif
929 .endm
#[2] startup.asm
#[3] huc_opt.inc
21 .include "huc_opt.inc"
1 ;
2 ; Hu-C internal include file
3 ;
4
5 ; optimized macros
6 ; ----
7
8 ; lea_s
9 ;
10 .macro __lea_s
11 ; (bytes : 10, cycles : 16)
12 lda <__sp
13 clc
14 adc #LOW(\1)
15 tax
16 .ifndef SMALL
17 lda <__sp+1
18 adc #HIGH(\1)
19 .else
20 lda #$3f
21 .endif
22 .endm
23
24 ; pea_s
25 ;
26 .macro __pea_s
27 ; (bytes : 25, cycles : 44)
28 .ifndef SMALL
29 lda <__sp
30 sec
31 sbc #2
32 bcs .x_\@
33 dec <__sp+1
34 .x_\@: sta <__sp
35 clc
36 adc #LOW(\1+2)
37 sta [__sp]
38 tax
39 lda <__sp+1
40 adc #HIGH(\1+2)
41 ldy #1
42 sta [__sp],Y
43 .else
44 lda <__sp
45 dec a
46 dec a
47 sta <__sp
48 clc
49 adc #LOW(\1+2)
50 sta [__sp]
51 tax
52 lda #$3f
53 ldy #1
54 sta [__sp],Y
55 .endif
56 .endm
57
58 ; ldb_s
59 ;
60 .macro __ldb_s
61 .if (\1 < 256)
62 ; short index (bytes : 9, cycles : 13/17)
63 ldy #\1
64 lda [__sp],Y
65 tax
66 cla
67 bpl .x_\@ ; signed
68 dec A
69 .x_\@:
70 .else
71 ; long index (bytes : 20, cycles : 37/41)
72 addw #\1,<__sp,<__ptr ; 13,26
73 lda [__ptr]
74 tax
75 cla
76 bpl .x_\@ ; signed
77 dec A
78 .x_\@:
79 .endif
80 .endm
81
82 ; addb_s
83 ;
84 .macro __addb_s
85 ; short index (bytes : 9, cycles : 13/17)
86 stx <__temp
87 sta <__temp+1
88 .if (\1 < 256)
89 ldy #\1
90 lda [__sp],Y