#[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 91 .else 92 addw #\1,<__sp,<__ptr ; 13,26 93 lda [__ptr] 94 .endif 95 tax 96 __extw 97 sax 98 clc 99 adc <__temp 100 sax 101 adc <__temp+1 102 .endm 103 104 ; ldub_s 105 ; 106 .macro __ldub_s 107 .if (\1 < 256) 108 ; short index (bytes : 9, cycles : 13/17) 109 ldy #\1 110 lda [__sp],Y 111 tax 112 cla 113 .else 114 ; long index (bytes : 20, cycles : 37/41) 115 addw #\1,<__sp,<__ptr ; 13,26 116 lda [__ptr] 117 tax 118 cla 119 .endif 120 .endm 121 122 ; addub_s 123 ; 124 .macro __addub_s 125 .if (\1 < 256) 126 ; short index (bytes : 9, cycles : 13/17) 127 ldy #\1 128 sax 129 clc 130 adc [__sp],Y 131 sax 132 adc #0 133 .else 134 ; long index (bytes : 20, cycles : 37/41) 135 sta <__temp 136 addw #\1,<__sp,<__ptr ; 13,26 137 txa 138 clc 139 adc [__ptr] 140 tax 141 lda <__temp 142 adc #0 143 .endif 144 .endm 145 146 ; ldb_p 147 ; 148 .macro __ldb_p 149 ; (bytes : 11, cycles : 19/23) 150 stx <__ptr 151 sta <__ptr+1 152 lda [__ptr] 153 tax 154 cla 155 bpl .x_\@ ; signed 156 dec A 157 .x_\@: 158 .endm 159 160 ; addbi_p 161 .macro __addbi_p 162 stx <__ptr 163 sta <__ptr+1 164 lda [__ptr] 165 clc 166 adc #\1 167 sta [__ptr] 168 tax 169 cla 170 .endm 171 172 ; ldub_p 173 ; 174 .macro __ldub_p 175 ; (bytes : 11, cycles : 19/23) 176 stx <__ptr 177 sta <__ptr+1 178 lda [__ptr] 179 tax 180 cla 181 .endm 182 183 ; ldw_s 184 ; 185 .macro __ldw_s 186 .if (\1 < 255) 187 ; short index (bytes : 7/8, cycles : 18/20) 188 .if (\1 = 0) 189 lda [__sp] 190 tax 191 ldy #1 192 lda [__sp],Y 193 .else 194 ldy #\1 195 lda [__sp],Y 196 tax 197 iny 198 lda [__sp],Y 199 .endif 200 .else 201 ; long index (bytes : 20, cycles : 44) 202 addw #\1,<__sp,<__ptr ; 13,26 203 lda [__ptr] 204 tax 205 ldy #1 206 lda [__ptr],Y 207 .endif 208 .endm 209 210 ; stbi_s 211 ; 212 .macro __stbi_s 213 .if (\2 < 256) 214 ; short index (bytes : 8/ 9, cycles : 15) 215 lda #LOW(\1) 216 ldy #\2 217 sta [__sp],Y 218 tax 219 cla 220 .else 221 ; long index (bytes : 19/20, cycles : 39) 222 223 addw #\2,<__sp,<__ptr ; 13,26 224 lda #LOW(\1) 225 sta [__ptr] 226 tax 227 cla 228 .endif 229 .endm 230 231 ; stwi_s 232 ; 233 .macro __stwi_s 234 .if (\2 < 255) 235 ; short index (bytes : 12, cycles : 24) 236 lda #LOW(\1) 237 ldy #\2 238 sta [__sp],Y 239 tax 240 lda #HIGH(\1) 241 iny 242 sta [__sp],Y 243 .else 244 ; long index (bytes : 24, cycles : 48) 245 addw #\2,<__sp,<__ptr ; 13,26 246 lda #LOW(\1) 247 sta [__ptr] 248 tax 249 lda #HIGH(\1) 250 ldy #1 251 sta [__ptr],Y 252 .endif 253 .endm 254 255 ; stb_s 256 ; 257 .macro __stb_s 258 .if (\1 < 255) 259 ; short index (bytes : 6, cycles : 13) 260 sax 261 ldy #\1 262 sta [__sp],Y 263 sax 264 .else 265 ; long index (bytes : 18, cycles : 42) 266 pha 267 addw #\1,<__sp,<__ptr ; 13,26 268 txa 269 sta [__ptr] 270 pla 271 .endif 272 .endm 273 274 ; stw_s 275 ; 276 .macro __stw_s 277 .if (\1 < 255) 278 ; short index (bytes : 9, cycles : 22) 279 sax 280 ldy #\1 281 sta [__sp],Y 282 sax 283 iny 284 sta [__sp],Y 285 .else 286 ; long index (bytes : 22, cycles : 51) 287 pha 288 addw #\1,<__sp,<__ptr ; 13,26 289 txa 290 sta [__ptr] 291 pla 292 ldy #1 293 sta [__ptr],Y 294 .endif 295 .endm 296 297 ; addw_s 298 ; 299 .macro __addw_s 300 .if (\1 < 255) 301 ; short index (bytes : 10, cycles : 24) 302 ldy #\1 303 clc 304 sax 305 adc [__sp],Y 306 sax 307 iny 308 adc [__sp],Y 309 .else 310 ; long index (bytes : 24, cycles : 55) 311 pha ; 1, 3 312 addw #\1,<__sp,<__ptr ; 13,26 313 pla ; 1, 4 314 clc 315 sax 316 adc [__ptr] 317 sax 318 ldy #1 319 adc [__ptr],Y 320 .endif 321 .endm 322 323 ; XXX: the semantics of this are ridiculous: It assumes the value of 324 ; the incremented variable to be in AX, the memory location to 325 ; be incremented and the previous value retained in AX, making it 326 ; necessary to spill A. 327 ; incw_s 328 ; 329 .macro __incw_s 330 ; (bytes : 16, cycles : 24/40) 331 pha 332 ldy #\1 333 txa 334 inc A 335 sta [__sp],Y 336 bne .x_\@ 337 iny 338 lda [__sp],Y 339 inc A 340 sta [__sp],Y 341 .x_\@: 342 pla 343 .endm 344 345 ; incb_s 346 ; 347 .macro __incb_s 348 pha 349 ldy #\1 350 txa 351 inc A 352 sta [__sp],Y 353 pla 354 .endm 355 356 ; ldd_i 357 ; 358 .macro __ldd_i 359 stw #(\1) & 0xFFFF,<\2 360 stw #(\1) >> 16,<\3 361 ldx #low(\2) 362 lda #high(\2) 363 .endm 364 365 ; ldd_b 366 ; 367 .macro __ldd_b 368 lda \1 369 sta <\2 370 stz <\2+1 371 stwz <\3 372 ldx #low(\2) 373 lda #high(\2) 374 .endm 375 376 ; ldd_w 377 ; 378 .macro __ldd_w 379 stw \1,<\2 380 stwz <\3 381 ldx #low(\2) 382 lda #high(\2) 383 .endm 384 385 ; ldd_s_b 386 ; 387 .macro __ldd_s_b 388 __ldb_s \1 389 stx <\2 390 sta <\2+1 391 stwz <\3 392 ldx #low(\2) 393 lda #high(\2) 394 .endm 395 396 ; ldd_s_w 397 ; 398 .macro __ldd_s_w 399 __ldw_s \1 400 stx <\2 401 sta <\2+1 402 stwz <\3 403 ldx #low(\2) 404 lda #high(\2) 405 .endm 406 #[2] startup.asm 22 .endif ; HUC 23 #[3] standard.inc 24 .include "standard.inc" ; HUCARD 1 ; 2 ; STANDARD.INC - MagicKit standard include file 3 ; #[4] equ.inc 4 .include "equ.inc" 1 ; 2 ; EQU.INC - MagicKit Standard Equates 3 ; 4 5 6 ; -------- 7 ; This block defines standard system variables 8 ; in zero-page. 9 ; 10 11 20F3 vdc_crl = $20F3 ; VDC control register (copy of) 12 20F4 vdc_crh = $20F4 ; 13 20F5 irq_m = $20F5 ; interrupt control mask (copy of) 14 20F6 vdc_sr = $20F6 ; VDC status register (copy of) 15 20F7 vdc_reg = $20F7 ; VDC register index (copy of) 16 17 ; old aliases (for compatibility only, don't use them) 18 0000 .ifndef HUC 22 .endif 23 24 25 ; -------- 26 ; This block defines standard parameter-passing 27 ; areas (in zero-page) for subroutines. 28 ; 29 30 20EC __bp = $20EC ; base pointer 31 20EE __si = $20EE ; source address 32 20F0 __di = $20F0 ; destination address 33 20F8 __ax = $20F8 34 20F8 __al = $20F8 35 20F9 __ah = $20F9 36 20FA __bx = $20FA 37 20FA __bl = $20FA 38 20FB __bh = $20FB 39 20FC __cx = $20FC 40 20FC __cl = $20FC 41 20FD __ch = $20FD 42 20FE __dx = $20FE 43 20FE __dl = $20FE 44 20FF __dh = $20FF 45 46 0001 .ifdef DEPRECATED 47 ; aliases for old assembler code 48 20EC _bp = __bp 49 20EE _si = __si 50 20F0 _di = __di 51 20F8 _ax = __ax 52 20F8 _al = __al 53 20F9 _ah = __ah 54 20FA _bx = __bx 55 20FA _bl = __bl 56 20FB _bh = __bh 57 20FC _cx = __cx 58 20FC _cl = __cl 59 20FD _ch = __ch 60 20FE _dx = __dx 61 20FE _dl = __dl 62 20FF _dh = __dh 63 .endif 64 65 66 ; -------- 67 ; This block defines names for standard 68 ; devices and equipment on the PC-Engine. 69 ; (they should be self-explanatory...) 70 ; 71 72 ; ---- 73 ; VDC (Video Display Controller) 74 75 0000 videoport .equ $0000 76 77 0000 video_reg .equ videoport 78 0000 video_reg_l .equ video_reg 79 0001 video_reg_h .equ video_reg+1 80 81 0002 video_data .equ videoport+2 82 0002 video_data_l .equ video_data 83 0003 video_data_h .equ video_data+1 84 85 86 0000 .ifdef _SGX 119 .endif ; _SGX 120 121 122 0000 .ifdef _AC 170 .endif ; _AC 171 172 173 ; ---- 174 ; VCE (Video Color Encoder) 175 176 0400 colorport .equ $0400 177 0400 color_ctrl .equ colorport 178 179 0402 color_reg .equ colorport+2 180 0402 color_reg_l .equ color_reg 181 0403 color_reg_h .equ color_reg+1 182 183 0404 color_data .equ colorport+4 184 0404 color_data_l .equ color_data 185 0405 color_data_h .equ color_data+1 186 187 0001 .ifdef HUC 188 0402 _color_reg .equ colorport+2 189 0404 _color_data .equ colorport+4 190 .endif 191 192 193 ; ---- 194 ; PSG (Programmable Sound Generator) 195 196 0800 psgport .equ $0800 197 0800 psg_ch .equ psgport 198 0801 psg_mainvol .equ psgport+1 199 0802 psg_freqlo .equ psgport+2 200 0803 psg_freqhi .equ psgport+3 201 0804 psg_ctrl .equ psgport+4 202 0805 psg_pan .equ psgport+5 203 0806 psg_wavebuf .equ psgport+6 204 0807 psg_noise .equ psgport+7 205 0808 psg_lfofreq .equ psgport+8 206 0809 psg_lfoctrl .equ psgport+9 207 208 209 ; ---- 210 ; TIMER 211 212 0C00 timerport .equ $0C00 213 0C00 timer_cnt .equ timerport 214 0C01 timer_ctrl .equ timerport+1 215 216 217 ; ---- 218 ; I/O port 219 220 1000 joyport .equ $1000 221 222 223 ; ---- 224 ; IRQ ports 225 226 1400 irqport .equ $1400 227 1402 irq_disable .equ irqport+2 228 1403 irq_status .equ irqport+3 229 230 231 ; ---- 232 ; CDROM/Expansion ports 233 234 1800 cd_port .equ $1800 235 236 1803 bram_lock .equ cd_port+3 ; a read access here will do it 237 1807 bram_unlock .equ cd_port+7 ; actually, bit #$80 of this byte 238 239 240 ; ---- 241 ; Arcade Card ports 242 243 1A00 ac_port .equ $1A00 244 1A00 ac_data1 .equ ac_port 245 1A01 ac_data1_alt .equ ac_port+1 246 1A02 ac_base1_l .equ ac_port+2 247 1A03 ac_base1_m .equ ac_port+3 248 1A04 ac_base1_h .equ ac_port+4 249 1A05 ac_offset1_l .equ ac_port+5 250 1A06 ac_offset1_m .equ ac_port+6 251 1A09 ac_cntrol1 .equ ac_port+9 252 1A0A ac_addoffset1 .equ ac_port+$0A 253 254 1AE0 ac_shftreg .equ $1AE0 ; actually, probably rotate register 255 1AE0 ac_shftreg_0 .equ ac_shftreg 256 1AE1 ac_shftreg_1 .equ ac_shftreg+1 257 1AE2 ac_shftreg_2 .equ ac_shftreg+2 258 1AE3 ac_shftreg_3 .equ ac_shftreg+3 259 1AE4 ac_shft_bits .equ ac_shftreg+4 ; positive = shift left 260 261 1AFD ac_identbase .equ $1AFD 262 1AFD ac_identver_l .equ ac_identbase 263 1AFE ac_identver_h .equ ac_identbase+1 264 1AFF ac_identflag .equ ac_identbase+2 265 266 0051 AC_IDENT .equ $51 ; if ac_identflag = AC_IDENT, then AC in use 267 268 269 ; -------- 270 ; This block defines names for macro 271 ; argument types (\?x). 272 ; 273 274 0000 ARG_NONE .equ 0 275 0001 ARG_REG .equ 1 276 0002 ARG_IMMED .equ 2 277 0003 ARG_ABS .equ 3 278 0003 ARG_ABSOLUTE .equ 3 279 0004 ARG_INDIRECT .equ 4 280 0005 ARG_STRING .equ 5 281 0006 ARG_LABEL .equ 6 #[3] standard.inc #[4] macro.inc 5 .include "macro.inc" 1 ; 2 ; macro.inc - MagicKit standard macro definitions 3 ; 4 5 map .macro ; map a memory bank into 6 lda #bank(\1) ; addressable memory 7 tam #page(\1) 8 .endm 9 10 ; 11 ; MAPLIBFUNC - Re-map a library function into $A000-space if it's 12 ; not in library bank #1 13 ; 14 maplibfunc .macro 15 tay 16 tma #page(\1) 17 pha 18 lda #bank(\1) 19 tam #page(\1) 20 tya 21 jsr \1 22 tay 23 pla 24 tam #page(\1) 25 tya 26 .endm 27 28 29 0000 .ifdef HAVE_LIB3 47 .endif ; HAVE_LIB3 48 49 ; 50 ; STWZ - store a word-sized zero value at stated memory location 51 ; 52 stwz .macro 53 stz LOW_BYTE \1 54 stz HIGH_BYTE \1 55 .endm 56 57 ; 58 ; STW - store a word-sized value at stated memory location 59 ; 60 stw .macro 61 lda LOW_BYTE \1 62 sta LOW_BYTE \2 63 lda HIGH_BYTE \1 64 sta HIGH_BYTE \2 65 .endm 66 67 stb .macro 68 lda \1 69 sta \2 70 .endm 71 72 ; 73 ; ADDW - add word-sized value to value at stated memory location, 74 ; storing result back into stated memory location (or into 75 ; another destination memory location - third arg) 76 ; 77 addw .macro 78 .if (\# = 3) 79 ; 3-arg mode 80 ; 81 clc 82 lda LOW_BYTE \2 83 adc LOW_BYTE \1 84 sta LOW_BYTE \3 85 lda HIGH_BYTE \2 86 adc HIGH_BYTE \1 87 sta HIGH_BYTE \3 88 .else 89 ; 2-arg mode 90 ; 91 clc 92 lda LOW_BYTE \2 93 adc LOW_BYTE \1 94 sta LOW_BYTE \2 95 lda HIGH_BYTE \2 96 adc HIGH_BYTE \1 97 sta HIGH_BYTE \2 98 .endif 99 .endm 100 101 ; 102 ; ADCW - add word-sized value plus carry to value at stated memory location, 103 ; storing result back into stated memory location 104 ; 105 adcw .macro 106 lda LOW_BYTE \2 107 adc LOW_BYTE \1 108 sta LOW_BYTE \2 109 lda HIGH_BYTE \2 110 adc HIGH_BYTE \1 111 sta HIGH_BYTE \2 112 .endm 113 114 ; 115 ; SUBW - substract word-sized value from value at stated memory location, 116 ; storing result back into stated memory location 117 ; 118 subw .macro 119 sec 120 lda LOW_BYTE \2 121 sbc LOW_BYTE \1 122 sta LOW_BYTE \2 123 lda HIGH_BYTE \2 124 sbc HIGH_BYTE \1 125 sta HIGH_BYTE \2 126 .endm 127 128 ; 129 ; SBCW - substract word-sized value plus carry from value at stated memory 130 ; location, storing result back into stated memory location 131 ; 132 sbcw .macro 133 lda LOW_BYTE \2 134 sbc LOW_BYTE \1 135 sta LOW_BYTE \2 136 lda HIGH_BYTE \2 137 sbc HIGH_BYTE \1 138 sta HIGH_BYTE \2 139 .endm 140 141 cmpw .macro 142 lda HIGH_BYTE \2 143 cmp HIGH_BYTE \1 144 bne .x_\@ 145 lda LOW_BYTE \2 146 cmp LOW_BYTE \1 147 .x_\@: 148 .endm 149 150 tstw .macro ; test if the word-sized 151 lda \1 ; value at stated memory 152 ora \1+1 ; location is zero 153 .endm 154 155 incw .macro ; increment a word-sized 156 inc \1 ; value at stated memory 157 bne .x_\@ ; location 158 inc \1+1 159 .x_\@: 160 .endm 161 162 decw .macro ; decrement a word-sized 163 sec ; value at stated memory 164 lda \1 ; location 165 sbc #1 166 sta \1 167 lda \1+1 168 sbc #0 169 sta \1+1 170 .endm 171 172 rolw .macro ; rotate word-sized value 173 rol \1 ; (at stated memory location) 174 rol \1+1 175 .endm 176 177 aslw .macro ; arithmetic shift-left 178 asl \1 ; word-sized value (at stated 179 rol \1+1 ; memory location) 180 .endm 181 182 lsrw .macro ; logical shift-right word-sized 183 lsr \1+1 ; value (at stated memory 184 ror \1 ; location) 185 .endm 186 187 rorw .macro ; rotate right word-sized value 188 ror \1+1 ; (at stated memory location) 189 ror \1 190 .endm 191 192 negw .macro ; negate word-sized value 193 cla ; (at stated memory location) 194 sub \1 ; 2's complement 195 sta \1 196 cla 197 sbc \1+1 198 sta \1+1 199 .endm 200 201 neg .macro ; negate byte-sized value 202 eor #$FF ; in register A 203 inc A ; 2's complement 204 .endm 205 206 add .macro ; add byte-sized value to 207 .if (\# = 2) ; register A (handle carry 208 lda \2 ; flag) 209 clc 210 adc \1 211 sta \2 212 .else 213 clc 214 adc \1 215 .endif 216 .endm 217 218 sub .macro ; subtract byte-sized value 219 .if (\# = 2) ; from register A (handle 220 lda \2 ; carry flag) 221 sec 222 sbc \1 223 sta \2 224 .else 225 sec 226 sbc \1 227 .endif 228 .endm 229 230 blo .macro ; branch if 'lower' 231 bcc \1 232 .endm 233 234 bhs .macro ; branch if 'higher or same' 235 bcs \1 236 .endm 237 238 bhi .macro ; branch if 'higher' 239 beq .x_\@ 240 bcs \1 241 .x_\@: 242 .endm 243 244 ;------------------------------- 245 246 ; 247 ; Long branch macros 248 ; 249 250 lbne .macro 251 beq .x_\@ 252 jmp \1 253 .x_\@ 254 .endm 255 256 lbeq .macro 257 bne .x_\@ 258 jmp \1 259 .x_\@ 260 .endm 261 262 lbpl .macro 263 bmi .x_\@ 264 jmp \1 265 .x_\@ 266 .endm 267 268 lbmi .macro 269 bpl .x_\@ 270 jmp \1 271 .x_\@ 272 .endm 273 274 lbcc .macro 275 bcs .x_\@ 276 jmp \1 277 .x_\@ 278 .endm 279 280 lbcs .macro 281 bcc .x_\@ 282 jmp \1 283 .x_\@ 284 .endm 285 286 lblo .macro 287 bcs .x_\@ 288 jmp \1 289 .x_\@ 290 .endm 291 292 lbhs .macro 293 bcc .x_\@ 294 jmp \1 295 .x_\@ 296 .endm 297 298 299 ;------------------------------- 300 301 ; 302 ; These macros are the same as the macros 303 ; without an underscore; the difference 304 ; is these macros preserve the state of 305 ; the registers they use (at the expense 306 ; of speed) 307 ; 308 309 _stw .macro 310 pha 311 stw \1,\2 312 pla 313 .endm 314 315 _addw .macro 316 pha 317 addw \1,\2 318 pla 319 .endm 320 321 _adcw .macro 322 pha 323 adcw \1,\2 324 pla 325 .endm 326 327 _subw .macro 328 pha 329 subw \1,\2 330 pla 331 .endm 332 333 _sbcw .macro 334 pha 335 sbcw \1,\2 336 pla 337 .endm 338 339 _cmpw .macro 340 pha 341 cmpw \1,\2 342 pla 343 .endm 344 345 _tstw .macro 346 pha 347 tstw \1 348 pla 349 .endm 350 351 _incw .macro 352 incw \1 353 .endm 354 355 _decw .macro 356 pha 357 decw \1 358 pla 359 .endm #[3] standard.inc #[4] func.inc 6 .include "func.inc" 1 ; 2 ; FUNC.INC - MagicKit Standard Functions 3 ; 4 ; 5 6 ; ---- 7 ; BATVAL - create a value for the BAT map 8 ; 9 ; parameters: 10 ; \1 = palette (0-15) 11 ; \2 = VRAM address of tile 12 BATVAL .func (\1<<12)|(\2>>4) 13 14 ; ---- 15 ; CHAR - create a BAT value for a character defined 16 ; using '.defchar' (uses default palette) 17 ; 18 ; parameters: 19 ; \1 = name of character 20 ; 21 CHAR .func (PAL(\1)<<12|VRAM(\1)>>4) 22 23 ; ---- 24 ; SPR_VRAM - return shifted value of sprite-pattern VRAM address 25 ; 26 ; parameters: 27 ; \1 = VRAM address of sprite 28 ; 29 SPR_VRAM .func (VRAM(\1)>>5) #[3] standard.inc #[4] library.inc 7 .include "library.inc" 1 ; 2 ; LIBRARY.INC - MagicKit include-interface to LIBRARY.ASM 3 ; 4 5 ; 6 ; These MACROs are just simple one-line setups to the 7 ; back-end library subroutines. They simply setup 8 ; calling parameters, and call the subroutine 9 ; 10 11 12 ; set video memory read and write address: 13 ; 14 ; setvraddr(addr) 15 ; ---- 16 ; addr, new address in VRAM to read at 17 ; 18 .macro setvraddr 19 stw #\1,<__di 20 jsr set_read 21 .endm 22 23 ; setvwaddr(addr) 24 ; ---- 25 ; addr, new address in VRAM to write at 26 ; 27 .macro setvwaddr 28 stw #\1,<__di 29 jsr set_write 30 .endm 31 32 ; set_bgpal(index, data [, nb]) 33 ; ---- 34 ; index, sub-palette index (0-15) 35 ; data, color data memory address 36 ; nb, number of sub-palette to load (optional, one by default) 37 38 .macro set_bgpal 39 lda \1 40 sta <__al 41 .if (\?2 = ARG_LABEL) 42 stb #BANK(\2),<__bl 43 .else 44 stb #$FE,<__bl 45 .endif 46 stw #\2,<__si 47 .if \?3 48 lda \3 49 .else 50 lda #1 51 .endif 52 sta <__cl 53 jsr load_palette 54 .endm 55 56 ; set_sprpal(index, data [, nb]) 57 ; ---- 58 ; index, sub-palette index (0-15) 59 ; data, palette data memory address 60 ; nb, number of sub-palette to update (optional, one by default) 61 62 .macro set_sprpal 63 lda \1 64 add #16 65 sta <__al 66 .if (\?2 = ARG_LABEL) 67 stb #BANK(\2),<__bl 68 .else 69 stb #$FE,<__bl 70 .endif 71 stw #\2,<__si 72 .if \?3 73 lda \3 74 .else 75 lda #1 76 .endif 77 sta <__cl 78 jsr load_palette 79 .endm 80 81 ; setcolor(index, r, g, b) 82 ; ---- 83 ; index, color index 84 ; r, red (0-7) 85 ; g, green (0-7) 86 ; b, blue (0-7) 87 88 .macro setcolor 89 stw \1,color_reg 90 stw #(((\3) << 6) + ((\2) << 3) + (\4)),color_data 91 .endm 92 93 ; vload([vram,] data, size) 94 ; ---- 95 ; vram, VRAM base address 96 ; data, video data memory address 97 ; size, number of words to copy 98 99 .macro vload 100 .if (\# = 3) 101 stw #\1,<__di 102 .if (\?2 = ARG_LABEL) 103 stb #BANK(\2),<__bl 104 .else 105 stb #$FE,<__bl 106 .endif 107 stw #\2,<__si 108 stw \3,<__cx 109 .else 110 stw #VRAM(\1),<__di 111 stb #BANK(\1),<__bl 112 stw #\1,<__si 113 stw #\2,<__cx 114 .endif 115 jsr load_vram 116 .endm 117 118 ; batcpy(vram, bat, w, h) 119 ; ---- 120 ; vram, VRAM base address 121 ; bat, BAT address in memory 122 ; w, nb of column to copy 123 ; h, nb of row 124 125 .macro batcpy 126 .if (\# = 5) 127 .fail "batcpy syntax has changed, update your code!" 128 .endif 129 stw \1,<__di 130 .if (\?2 = ARG_LABEL) 131 stb #BANK(\2),<__bl 132 .else 133 stb #$FE,<__bl 134 .endif 135 stw #\2,<__si 136 lda \3 137 sta <__cl 138 lda \4 139 sta <__ch 140 jsr load_bat 141 .endm 142 143 ; setmap(map, tile, ctable, w ,h) 144 ; ---- 145 ; map, map base address 146 ; tile, tile vram address 147 ; ctable, tile palette table address 148 ; w, map width 149 ; h, map height 150 151 .macro setmap 152 stw #BANK(\1),mapbank 153 stw #\1,mapaddr 154 stw #(\2)>>4,maptilebase 155 stw #\3,mapctable 156 stb #BANK(\3),mapctablebank 157 stw \4,mapwidth 158 stw \5,mapheight 159 .endm 160 161 ; mapcpy(vram, x, y, w, h) 162 ; ---- 163 ; vram, VRAM base address 164 ; x, x start coordinate in the map 165 ; y, y start coordinate 166 ; w, nb of column to copy 167 ; h, nb of row 168 169 .macro mapcpy 170 stw #\1,<__di 171 lda \2 172 sta <__cl 173 lda \3 174 sta <__ch 175 lda \4 176 sta <__dl 177 lda \5 178 sta <__dh 179 jsr load_map 180 .endm 181 182 ; fntcpy(vram, font, color, bg, nb) 183 ; ---- 184 ; vram, VRAM base address 185 ; font, font address in memory 186 ; color, character color 187 ; bg, bg color 188 ; nb, nb of char. to copy 189 190 .macro fntcpy 191 stw #\1,<__di 192 stb #BANK(\2),<__bl 193 stw #\2,<__si 194 lda \3 195 sta <__al 196 lda \4 197 sta <__ah 198 lda \4 199 sta <__cl 200 jsr load_font 201 .endm 202 203 ; scroll(num, x, y, top, bottom, cr) 204 ; ---- 205 ; num, scroll number (0-3) 206 ; x, BAT x position 207 ; y, BAT y position 208 ; top, screen window top 209 ; bottom, screen window bottom 210 ; cr, screen window display control (bg/sp) 211 212 .macro scroll 213 lda \1 214 tax 215 lda LOW_BYTE \2 216 sta scroll_xl,X 217 lda HIGH_BYTE \2 218 sta scroll_xh,X 219 lda LOW_BYTE \3 220 sta scroll_yl,X 221 lda HIGH_BYTE \3 222 sta scroll_yh,X 223 lda \4 224 sta scroll_top,X 225 lda \5 226 sta scroll_bottom,X 227 lda \6 228 ora #$01 229 sta scroll_cr,X 230 .endm 231 232 ; scroll_disable(num) 233 ; ---- 234 ; num, scroll number (0-3) 235 236 .macro scroll_disable 237 lda \1 238 tax 239 lda scroll_cr,X 240 and #$fe 241 sta scroll_cr,X 242 .endm 243 244 ; setxres (xres) 245 ; ---- 246 ; xres, horizontal display resolution 247 248 .macro setxres 249 stw #\1,<__ax 250 jsr set_xres 251 .endm 252 #[3] standard.inc #[4] sprites.inc 8 .include "sprites.inc" 1 ; 2 ; SPRITES.INC - MagicKit sprite MACRO definitions 3 ; 4 5 6 ; load_sprites(vram_addr, spr_bank, #nb_group) 7 ; ---- 8 ; vram_addr, destination address in VRAM 9 ; spr_bank, sprite bank address 10 ; nb_group, number of 32x64 patterns to copy 11 12 .macro load_sprites 13 ; put the VRAM address in di 14 stw #\1,<__di 15 16 ; put the sprite bank address in si/bl 17 stw #\2,<__si 18 stb #BANK(\2),<__bl 19 20 ; get the number of patterns to copy, multiply it by $200 - 21 ; the size in words of a 32x64 pattern (remember that 22 ; 'load_vram' need a size in words), and put it in cx 23 lda \3 24 asl a 25 stz <__cx 26 sta <__cx+1 27 28 ; call the 'load_vram' function 29 jsr load_vram 30 .endm 31 32 33 ; spr_set(#sprite, satb) 34 ; ---- 35 ; sprite, the sprite number (0-63) 36 ; satb, the address of the SATB in RAM 37 38 .macro spr_set 39 ; multiply the sprite number by 8 (the size of a SATB entry) 40 ; and put the result in si 41 stz <__si+1 42 lda \1 43 asl a 44 asl a 45 asl a 46 rol <__si+1 47 sta <__si 48 49 ; add the satb address to si 50 addw #\2,<__si 51 .endm 52 53 54 ; spr_x(#x [,offset]) 55 ; ---- 56 ; x, the new x coordinate 57 58 .macro spr_x 59 ldy #2 60 .if (\# = 2) 61 lda LOW_BYTE \1 62 clc 63 adc LOW_BYTE \2 64 sta [__si],Y 65 lda HIGH_BYTE \1 66 adc HIGH_BYTE \2 67 .else 68 lda LOW_BYTE \1 69 sta [__si],Y 70 lda HIGH_BYTE \1 71 .endif 72 iny 73 sta [__si],Y 74 .endm 75 76 77 ; spr_y(#y [,offset]) 78 ; ---- 79 ; y, the new y coordinate 80 81 .macro spr_y 82 .if (\# = 2) 83 lda LOW_BYTE \1 84 clc 85 adc LOW_BYTE \2 86 sta [__si] 87 lda HIGH_BYTE \1 88 adc HIGH_BYTE \2 89 .else 90 lda LOW_BYTE \1 91 sta [__si] 92 lda HIGH_BYTE \1 93 .endif 94 ldy #1 95 sta [__si],Y 96 .endm 97 98 99 ; spr_pattern(#addr) 100 ; ---- 101 ; addr, address of the sprite pattern in VRAM 102 103 .macro spr_pattern 104 ldy #4 105 .if (\?1 = ARG_IMMED) 106 lda #LOW((\1) >> 5) 107 sta [__si],Y 108 lda #HIGH((\1) >> 5) 109 .else 110 lda \1 111 sta [__si],Y 112 lda \1+1 113 .endif 114 iny 115 sta [__si],Y 116 .endm 117 118 119 ; spr_ctrl(#mask, #flag) 120 ; ---- 121 ; mask, mask of the bits to change 122 ; flag, new bit value 123 124 .macro spr_ctrl 125 ldy #7 126 lda \1 127 eor #$FF 128 and [__si],Y 129 ora \2 130 sta [__si],Y 131 .endm 132 133 134 ; spr_pri(#flag) 135 ; ---- 136 ; flag, new priority (1 = in foreground, 0 = in background) 137 138 .macro spr_pri 139 ldy #6 140 lda [__si],Y 141 and #$7F 142 ldx \1 143 beq .x\@ 144 ora #$80 145 .x\@: 146 sta [__si],Y 147 .endm 148 149 150 ; spr_pal(#index) 151 ; ---- 152 ; index, palette index (0-15) 153 154 .macro spr_pal 155 ldy #6 156 lda [__si],Y 157 and #$F0 158 ora \1 159 sta [__si],Y 160 .endm 161 162 163 ; init_satb(addr) 164 ; ---- 165 ; addr, the address of the local RAM SATB 166 167 .macro init_satb 168 stz \1 169 tii \1,\1+1,511 170 .endm 171 172 173 ; update_satb(satb[, addr] [,nb_sprite]) 174 ; ---- 175 ; satb, the address of the local RAM SATB 176 ; addr, the address where to copy the SATB in VRAM ($7F00 by default) 177 ; nb_sprite, number of sprite entry to copy (64 by default) 178 179 .macro update_satb 180 stw #\1,<__si 181 stb #BANK(\1),<__bl 182 183 .if (\?2) 184 stw #\2,<__di 185 .else 186 stw #$7F00,<__di 187 .endif 188 189 .if (\?3) 190 stw #(\3)*4,<__cx 191 .else 192 stw #$100,<__cx 193 .endif 194 195 jsr load_vram 196 .endm 197 198 199 ; ---- 200 0008 FLIP_X_MASK .equ $08 201 0080 FLIP_Y_MASK .equ $80 202 0088 FLIP_MASK .equ $88 203 0031 SIZE_MASK .equ $31 204 205 0000 NO_FLIP .equ 0 206 0000 NO_FLIP_X .equ 0 207 0000 NO_FLIP_Y .equ 0 208 0008 FLIP_X .equ $08 209 0080 FLIP_Y .equ $80 210 0000 SIZE_16x16 .equ 0 211 0010 SIZE_16x32 .equ $10 212 0030 SIZE_16x64 .equ $30 213 0001 SIZE_32x16 .equ $01 214 0011 SIZE_32x32 .equ $11 215 0031 SIZE_32x64 .equ $31 216 #[3] standard.inc #[4] vdc.inc 9 .include "vdc.inc" 1 ; 2 ; VDC.INC - MagicKit PC-Engine video MACRO definitions 3 ; 4 5 6 ; 7 ; VREG - set up video register to be read/written 8 ; 9 10 .macro vreg 11 lda \1 12 sta 79 --:2245 scr_w: .ds 1 80 --:2246 scr_h: .ds 1 81 82 2284 .org $2284 83 --:2284 soft_reset: .ds 2 ; soft reset jump loc (run+select) 84 85 ; include sound driver variables 86 #[3] sound.inc 87 .include "sound.inc" 1 ; 2 ; SOUND.INC - Included by STARTUP.ASM to customize the sound driver. 3 ; 4 ; A customized sound driver for HuCard or CDROM usage can create a 5 ; version of this file, and then have startup.asm use the new 6 ; definitions just by including the new sound driver's path 7 ; in the PCE_INCLUDE environment variable BEFORE the standard 8 ; "huc/include/pce" path. 9 ; 10 ; This default version is comptabile with the CDROM System Card usage. 11 ; 12 13 ;--------------------------------------------------------------------------- 14 ; tell startup.asm that we need the SOUND_BANK and to include sound.asm 15 16 0000 NEED_SOUND_BANK = 0 17 0000 NEED_SOUND_CODE = 0 18 19 ;--------------------------------------------------------------------------------------- 20 ; This macro is invoked in HuC startup.asm after the RAM is cleared, and just before 21 ; interrupts are enabled. 22 23 __sound_init .macro 24 .endm 25 26 ;--------------------------------------------------------------------------------------- 27 ; This macro is invoked in HuC startup.asm inside the vsync handler code. 28 29 __sound_vsync .macro 30 .endm 31 32 ;--------------------------------------------------------------------------------------- 33 ; This macro is invoked in HuC startup.asm inside the timer handler code. 34 ; 35 ; N.B. HuC startup.asm only invokes this if NOT building for CDROM!!! 36 ; 37 38 __sound_timer .macro 39 .endm 40 41 ;--------------------------------------------------------------------------------------- 42 ; this is the location to start allocating HuC's internal variables. 43 44 2680 .org $2680 #[2] startup.asm 88 89 ; sound.inc sets the starting location for these HuC variables 90 ; 91 ; this is normally $2680, but can be lower if a custom 92 ; sound driver is used that doesn't need all of the 93 ; standard System Card allocation of sound RAM. 94 95 --:2680 vsync_cnt: .ds 1 ; counter for 'wait_vsync' routine 96 97 --:2681 joybuf: .ds 5 ; 'delta' pad values collector 98 --:2686 joyhook: .ds 2 ; 'read_joypad' routine hook 99 --:2688 joycallback: .ds 6 ; joypad enhanced callback support 100 --:268E disp_cr: .ds 1 ; display control 101 ; HuCard: 1 = on, 0 = off 102 ; CD-ROM: 2 = on, 1 = off, 0 = no change 103 --:268F clock_hh .ds 1 ; system clock, hours since startup (0-255) 104 --:2690 clock_mm .ds 1 ; system clock, minutes since startup (0-59) 105 --:2691 clock_ss .ds 1 ; system clock, seconds since startup (0-59) 106 --:2692 clock_tt .ds 1 ; system clock, ticks (1/60th sec) since startup (0-59) 107 108 --:2693 joy6: .ds 5 ; second byte for 6-button joysticks 109 --:2698 joytrg6: .ds 5 110 --:269D joyold6: .ds 5 111 --:26A2 joybuf6: .ds 5 112 113 --:26A7 joytmp: .ds 5 114 --:26AC joytmp6: .ds 5 115 116 --:26B1 color_queue_r: .ds 1 ; ring buffer index for read 117 --:26B2 color_queue_w: .ds 1 ; ring buffer index for write 118 --:26B3 color_index: .ds 8 ; ring buffer - palette index 119 --:26BB color_count: .ds 8 ; ring buffer - palette count 120 --:26C3 color_bank: .ds 8 ; ring buffer - data bank 121 --:26CB color_addr_l: .ds 8 ; ring buffer - data addr lo 122 --:26D3 color_addr_h: .ds 8 ; ring buffer - data addr hi 123 --:26DB color_tia: .ds 8 ; self-modifying RAM tia function 124 125 0000 .if (CDROM) 134 .endif ; (CDROM) 135 136 ; ---- 137 ; setup flexible boundaries for startup code 138 ; and user program's "main". 139 ; 140 0000 .rsset 0 141 0000 START_BANK .rs 0 142 0000 LIB1_BANK .rs 1 143 0001 LIB2_BANK .rs 1 144 0000 .ifdef HAVE_LIB3 146 .endif 147 148 0000 .if (NEED_SOUND_BANK) 150 .endif ; defined in sound.inc if needed 151 152 0001 .ifdef HUC 153 0001 FONT_BANK .equ LIB2_BANK 154 0002 CONST_BANK .rs 1 155 0003 DATA_BANK .rs 1 156 .else ; HUC 159 .endif ; HUC 160 161 ; [ STARTUP CODE ] 162 163 ; Let's prepare the secondary library banks first, for use later. 164 ; The reason, as you will see, is because code for a given function 165 ; which sits together in a file, may have things in zero-page, 166 ; bss, LIB1_BANK (ie. START_BANK), and LIB2_BANK. 167 ; 168 ; The assembler must know beforehand what address etc. to use as a basis. 169 ; 170 171 0000 .ifdef _PAD 175 .endif 176 177 E000 .data 178 0001 .bank LIB2_BANK,"Base Library 2/Font" 179 6000 .org $6000 #[3] font.inc 180 .include "font.inc" 1 ; 8x8 monochrome font(s) 2 3 01:6000 font_1: 4 01:6000 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ;SPACE 01:6003 00 00 00 01:6006 00 00 5 01:6008 CC CC CC .db $cc,$cc,$cc,$88,$88,$00,$cc,$00 ;! 01:600B 88 88 00 01:600E CC 00 6 01:6010 6C 6C D8 .db $6c,$6c,$d8,$00,$00,$00,$00,$00 ;" 01:6013 00 00 00 01:6016 00 00 7 01:6018 6C FE 6C .db $6c,$fe,$6c,$6c,$6c,$fe,$6c,$00 ;# 01:601B 6C 6C FE 01:601E 6C 00 8 01:6020 10 38 40 .db $10,$38,$40,$38,$04,$38,$10,$00 ;$ 01:6023 38 04 38 01:6026 10 00 9 01:6028 42 A4 48 .db $42,$a4,$48,$10,$24,$4a,$84,$00 ;% 01:602B 10 24 4A 01:602E 84 00 10 01:6030 20 50 20 .db $20,$50,$20,$54,$88,$94,$62,$00 ;& 01:6033 54 88 94 01:6036 62 00 11 01:6038 18 30 60 .db $18,$30,$60,$00,$00,$00,$00,$00 ;' 01:603B 00 00 00 01:603E 00 00 12 01:6040 18 30 60 .db $18,$30,$60,$60,$60,$30,$18,$00 ;( 01:6043 60 60 30 01:6046 18 00 13 01:6048 30 18 0C .db $30,$18,$0c,$0c,$0c,$18,$30,$00 ;) 01:604B 0C 0C 18 01:604E 30 00 14 01:6050 54 38 7C .db $54,$38,$7c,$38,$54,$00,$00,$00 ;* 01:6053 38 54 00 01:6056 00 00 15 01:6058 00 10 10 .db $00,$10,$10,$7c,$10,$10,$00,$00 ;+ 01:605B 7C 10 10 01:605E 00 00 16 01:6060 00 00 00 .db $00,$00,$00,$18,$18,$08,$10,$00 ;, 01:6063 18 18 08 01:6066 10 00 17 01:6068 00 00 00 .db $00,$00,$00,$78,$00,$00,$00,$00 ;- 01:606B 78 00 00 01:606E 00 00 18 01:6070 00 00 00 .db $00,$00,$00,$00,$60,$60,$00,$00 ;. 01:6073 00 60 60 01:6076 00 00 19 01:6078 06 0C 18 .db $06,$0c,$18,$30,$60,$c0,$00,$00 ;/ 01:607B 30 60 C0 01:607E 00 00 20 21 01:6080 38 4C C6 .db $38,$4c,$c6,$c6,$c6,$64,$38,$00 ;0 01:6083 C6 C6 64 01:6086 38 00 22 01:6088 18 78 18 .db $18,$78,$18,$18,$18,$18,$7e,$00 ;1 01:608B 18 18 18 01:608E 7E 00 23 01:6090 7C C6 0E .db $7c,$c6,$0e,$3c,$78,$e0,$fe,$00 ;2 01:6093 3C 78 E0 01:6096 FE 00 24 01:6098 FE 0C 18 .db $fe,$0c,$18,$7c,$06,$c6,$7c,$00 ;3 01:609B 7C 06 C6 01:609E 7C 00 25 01:60A0 3C 6C CC .db $3c,$6c,$cc,$cc,$cc,$fe,$0c,$00 ;4 01:60A3 CC CC FE 01:60A6 0C 00 26 01:60A8 FE C0 FC .db $fe,$c0,$fc,$06,$06,$c6,$7c,$00 ;5 01:60AB 06 06 C6 01:60AE 7C 00 27 01:60B0 3C 60 C0 .db $3c,$60,$c0,$fc,$c6,$c6,$7c,$00 ;6 01:60B3 FC C6 C6 01:60B6 7C 00 28 01:60B8 FE C6 0C .db $fe,$c6,$0c,$18,$30,$30,$30,$00 ;7 01:60BB 18 30 30 01:60BE 30 00 29 01:60C0 7C C6 C6 .db $7c,$c6,$c6,$7c,$c6,$c6,$7c,$00 ;8 01:60C3 7C C6 C6 01:60C6 7C 00 30 01:60C8 7C C6 C6 .db $7c,$c6,$c6,$7e,$06,$0c,$78,$00 ;9 01:60CB 7E 06 0C 01:60CE 78 00 31 01:60D0 00 18 18 .db $00,$18,$18,$00,$18,$18,$00,$00 ;: 01:60D3 00 18 18 01:60D6 00 00 32 01:60D8 00 18 18 .db $00,$18,$18,$00,$18,$18,$30,$00 ;; 01:60DB 00 18 18 01:60DE 30 00 33 01:60E0 0C 18 30 .db $0c,$18,$30,$60,$30,$18,$0c,$00 ;< 01:60E3 60 30 18 01:60E6 0C 00 34 01:60E8 00 00 7C .db $00,$00,$7c,$00,$7c,$00,$00,$00 ;= 01:60EB 00 7C 00 01:60EE 00 00 35 01:60F0 60 30 18 .db $60,$30,$18,$0c,$18,$30,$60,$00 ;> 01:60F3 0C 18 30 01:60F6 60 00 36 01:60F8 7C C6 9E .db $7c,$c6,$9e,$38,$20,$00,$30,$00 ;? 01:60FB 38 20 00 01:60FE 30 00 37 38 01:6100 3C 42 9A .db $3c,$42,$9a,$aa,$aa,$5c,$00,$00 ;@ 01:6103 AA AA 5C 01:6106 00 00 39 01:6108 38 6C C6 .db $38,$6c,$c6,$c6,$fe,$c6,$c6,$00 ;A 01:610B C6 FE C6 01:610E C6 00 40 01:6110 FC C6 C6 .db $fc,$c6,$c6,$fc,$c6,$c6,$fc,$00 ;B 01:6113 FC C6 C6 01:6116 FC 00 41 01:6118 3C 66 C0 .db $3c,$66,$c0,$c0,$c0,$66,$3c,$00 ;C 01:611B C0 C0 66 01:611E 3C 00 42 01:6120 F8 CC C6 .db $f8,$cc,$c6,$c6,$c6,$cc,$f8,$00 ;D 01:6123 C6 C6 CC 01:6126 F8 00 43 01:6128 FE C0 C0 .db $fe,$c0,$c0,$fc,$c0,$c0,$fe,$00 ;E 01:612B FC C0 C0 01:612E FE 00 44 01:6130 FE C0 C0 .db $fe,$c0,$c0,$fc,$c0,$c0,$c0,$00 ;F 01:6133 FC C0 C0 01:6136 C0 00 45 01:6138 3C 66 C0 .db $3c,$66,$c0,$ce,$c6,$66,$3e,$00 ;G 01:613B CE C6 66 01:613E 3E 00 46 01:6140 C6 C6 C6 .db $c6,$c6,$c6,$fe,$c6,$c6,$c6,$00 ;H 01:6143 FE C6 C6 01:6146 C6 00 47 01:6148 7E 18 18 .db $7e,$18,$18,$18,$18,$18,$7e,$00 ;I 01:614B 18 18 18 01:614E 7E 00 48 01:6150 06 06 06 .db $06,$06,$06,$06,$06,$c6,$7c,$00 ;J 01:6153 06 06 C6 01:6156 7C 00 49 01:6158 C6 CC D8 .db $c6,$cc,$d8,$f0,$d8,$cc,$c6,$00 ;K 01:615B F0 D8 CC 01:615E C6 00 50 01:6160 C0 C0 C0 .db $c0,$c0,$c0,$c0,$c0,$c0,$fe,$00 ;L 01:6163 C0 C0 C0 01:6166 FE 00 51 01:6168 82 C6 EE .db $82,$c6,$ee,$fe,$d6,$c6,$c6,$00 ;M 01:616B FE D6 C6 01:616E C6 00 52 01:6170 86 C6 E6 .db $86,$c6,$e6,$f6,$de,$ce,$c6,$00 ;N 01:6173 F6 DE CE 01:6176 C6 00 53 01:6178 7C C6 C6 .db $7c,$c6,$c6,$c6,$c6,$c6,$7c,$00 ;O 01:617B C6 C6 C6 01:617E 7C 00 54 55 01:6180 FC C6 C6 .db $fc,$c6,$c6,$c6,$fc,$c0,$c0,$00 ;P 01:6183 C6 FC C0 01:6186 C0 00 56 01:6188 7C C6 C6 .db $7c,$c6,$c6,$c6,$de,$cc,$76,$00 ;Q 01:618B C6 DE CC 01:618E 76 00 57 01:6190 FC C6 C6 .db $fc,$c6,$c6,$fc,$d8,$cc,$c6,$00 ;R 01:6193 FC D8 CC 01:6196 C6 00 58 01:6198 7C C6 F0 .db $7c,$c6,$f0,$7c,$1e,$c6,$7c,$00 ;S 01:619B 7C 1E C6 01:619E 7C 00 59 01:61A0 7E 18 18 .db $7e,$18,$18,$18,$18,$18,$18,$00 ;T 01:61A3 18 18 18 01:61A6 18 00 60 01:61A8 C6 C6 C6 .db $c6,$c6,$c6,$c6,$c6,$c6,$7c,$00 ;U 01:61AB C6 C6 C6 01:61AE 7C 00 61 01:61B0 C6 C6 C6 .db $c6,$c6,$c6,$c6,$c6,$6c,$38,$00 ;V 01:61B3 C6 C6 6C 01:61B6 38 00 62 01:61B8 C6 C6 C6 .db $c6,$c6,$c6,$d6,$fe,$ee,$c6,$00 ;W 01:61BB D6 FE EE 01:61BE C6 00 63 01:61C0 C6 EE 7C .db $c6,$ee,$7c,$38,$7c,$ee,$c6,$00 ;X 01:61C3 38 7C EE 01:61C6 C6 00 64 01:61C8 66 66 66 .db $66,$66,$66,$3c,$18,$18,$18,$00 ;Y 01:61CB 3C 18 18 01:61CE 18 00 65 01:61D0 FE 0E 1C .db $fe,$0e,$1c,$38,$70,$e0,$fe,$00 ;Z 01:61D3 38 70 E0 01:61D6 FE 00 66 01:61D8 78 60 60 .db $78,$60,$60,$60,$60,$60,$78,$00 ;[ 01:61DB 60 60 60 01:61DE 78 00 67 01:61E0 C0 60 30 .db $c0,$60,$30,$18,$0c,$06,$00,$00 ;\ 01:61E3 18 0C 06 01:61E6 00 00 68 01:61E8 3C 0C 0C .db $3c,$0c,$0c,$0c,$0c,$0c,$3c,$00 ;] 01:61EB 0C 0C 0C 01:61EE 3C 00 69 01:61F0 10 28 44 .db $10,$28,$44,$00,$00,$00,$00,$00 ;^ 01:61F3 00 00 00 01:61F6 00 00 70 01:61F8 00 00 00 .db $00,$00,$00,$00,$00,$00,$fe,$00 ;_ 01:61FB 00 00 00 01:61FE FE 00 71 72 01:6200 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ; 01:6203 00 00 00 01:6206 00 00 73 01:6208 00 00 3C .db $00,$00,$3c,$06,$7e,$c6,$7e,$00 ;a 01:620B 06 7E C6 01:620E 7E 00 74 01:6210 C0 C0 FC .db $c0,$c0,$fc,$c6,$c6,$c6,$fc,$00 ;b 01:6213 C6 C6 C6 01:6216 FC 00 75 01:6218 00 00 7C .db $00,$00,$7c,$c6,$c0,$c6,$7c,$00 ;c 01:621B C6 C0 C6 01:621E 7C 00 76 01:6220 06 06 7E .db $06,$06,$7e,$c6,$c6,$c6,$7e,$00 ;d 01:6223 C6 C6 C6 01:6226 7E 00 77 01:6228 00 00 7C .db $00,$00,$7c,$c6,$fc,$c0,$7e,$00 ;e 01:622B C6 FC C0 01:622E 7E 00 78 01:6230 3E 60 60 .db $3e,$60,$60,$f8,$60,$60,$60,$00 ;f 01:6233 F8 60 60 01:6236 60 00 79 01:6238 00 00 7C .db $00,$00,$7c,$c6,$c6,$7e,$06,$7c ;g 01:623B C6 C6 7E 01:623E 06 7C 80 01:6240 C0 C0 FC .db $c0,$c0,$fc,$c6,$c6,$c6,$c6,$00 ;h 01:6243 C6 C6 C6 01:6246 C6 00 81 01:6248 18 00 18 .db $18,$00,$18,$18,$18,$18,$18,$00 ;i 01:624B 18 18 18 01:624E 18 00 82 01:6250 0C 0C 00 .db $0c,$0c,$00,$0c,$0c,$0c,$0c,$78 ;j 01:6253 0C 0C 0C 01:6256 0C 78 83 01:6258 C0 C0 D8 .db $c0,$c0,$d8,$f0,$e0,$f0,$d8,$00 ;k 01:625B F0 E0 F0 01:625E D8 00 84 01:6260 70 30 30 .db $70,$30,$30,$30,$30,$30,$78,$00 ;l 01:6263 30 30 30 01:6266 78 00 85 01:6268 00 00 7C .db $00,$00,$7c,$d6,$d6,$d6,$d6,$00 ;m 01:626B D6 D6 D6 01:626E D6 00 86 01:6270 00 00 7C .db $00,$00,$7c,$66,$66,$66,$66,$00 ;n 01:6273 66 66 66 01:6276 66 00 87 01:6278 00 00 3C .db $00,$00,$3c,$66,$66,$66,$3c,$00 ;o 01:627B 66 66 66 01:627E 3C 00 88 89 01:6280 00 00 7C .db $00,$00,$7c,$66,$66,$7c,$60,$60 ;p 01:6283 66 66 7C 01:6286 60 60 90 01:6288 00 00 3E .db $00,$00,$3e,$66,$66,$3e,$06,$06 ;q 01:628B 66 66 3E 01:628E 06 06 91 01:6290 00 00 D8 .db $00,$00,$d8,$fc,$e0,$c0,$c0,$00 ;r 01:6293 FC E0 C0 01:6296 C0 00 92 01:6298 00 00 3C .db $00,$00,$3c,$60,$38,$0c,$78,$00 ;s 01:629B 60 38 0C 01:629E 78 00 93 01:62A0 30 30 78 .db $30,$30,$78,$30,$30,$30,$1c,$00 ;t 01:62A3 30 30 30 01:62A6 1C 00 94 01:62A8 00 00 66 .db $00,$00,$66,$66,$66,$66,$3e,$00 ;u 01:62AB 66 66 66 01:62AE 3E 00 95 01:62B0 00 00 C6 .db $00,$00,$c6,$c6,$6c,$38,$10,$00 ;v 01:62B3 C6 6C 38 01:62B6 10 00 96 01:62B8 00 00 C6 .db $00,$00,$c6,$d6,$d6,$d6,$6c,$00 ;w 01:62BB D6 D6 D6 01:62BE 6C 00 97 01:62C0 00 00 C6 .db $00,$00,$c6,$6c,$10,$6c,$c6,$00 ;x 01:62C3 6C 10 6C 01:62C6 C6 00 98 01:62C8 00 00 66 .db $00,$00,$66,$66,$66,$3e,$06,$3c ;y 01:62CB 66 66 3E 01:62CE 06 3C 99 01:62D0 00 00 FE .db $00,$00,$fe,$0c,$38,$60,$fe,$00 ;z 01:62D3 0C 38 60 01:62D6 FE 00 100 01:62D8 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ; 01:62DB 00 00 00 01:62DE 00 00 101 01:62E0 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ; 01:62E3 00 00 00 01:62E6 00 00 102 01:62E8 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ; 01:62EB 00 00 00 01:62EE 00 00 103 01:62F0 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ; 01:62F3 00 00 00 01:62F6 00 00 104 01:62F8 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ; 01:62FB 00 00 00 01:62FE 00 00 105 106 01:6300 font_2: 107 01:6300 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ;SPACE 01:6303 00 00 00 01:6306 00 00 108 01:6308 04 0C 0C .db $04,$0c,$0c,$08,$08,$00,$10,$00 ;! 01:630B 08 08 00 01:630E 10 00 109 01:6310 36 12 24 .db $36,$12,$24,$00,$00,$00,$00,$00 ;" 01:6313 00 00 00 01:6316 00 00 110 01:6318 12 3F 12 .db $12,$3f,$12,$22,$24,$7e,$24,$00 ;# 01:631B 22 24 7E 01:631E 24 00 111 01:6320 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ;$ 01:6323 00 00 00 01:6326 00 00 112 01:6328 00 31 32 .db $00,$31,$32,$04,$18,$26,$46,$00 ;% 01:632B 04 18 26 01:632E 46 00 113 01:6330 08 14 14 .db $08,$14,$14,$38,$4a,$44,$3a,$00 ;& 01:6333 38 4A 44 01:6336 3A 00 114 01:6338 18 08 10 .db $18,$08,$10,$00,$00,$00,$00,$00 ;' 01:633B 00 00 00 01:633E 00 00 115 01:6340 0C 10 20 .db $0c,$10,$20,$20,$20,$10,$08,$00 ;( 01:6343 20 20 10 01:6346 08 00 116 01:6348 10 08 04 .db $10,$08,$04,$04,$04,$08,$30,$00 ;) 01:634B 04 04 08 01:634E 30 00 117 01:6350 00 08 2A .db $00,$08,$2a,$1c,$1c,$2a,$08,$00 ;* 01:6353 1C 1C 2A 01:6356 08 00 118 01:6358 00 08 08 .db $00,$08,$08,$3e,$08,$08,$00,$00 ;+ 01:635B 3E 08 08 01:635E 00 00 119 01:6360 00 00 00 .db $00,$00,$00,$00,$60,$60,$20,$40 ;, 01:6363 00 60 60 01:6366 20 40 120 01:6368 00 00 00 .db $00,$00,$00,$1e,$00,$00,$00,$00 ;- 01:636B 1E 00 00 01:636E 00 00 121 01:6370 00 00 00 .db $00,$00,$00,$00,$00,$60,$60,$00 ;. 01:6373 00 00 60 01:6376 60 00 122 01:6378 00 02 04 .db $00,$02,$04,$08,$10,$20,$40,$00 ;/ 01:637B 08 10 20 01:637E 40 00 123 124 01:6380 1C 22 22 .db $1c,$22,$22,$42,$42,$44,$38,$00 ;0 01:6383 42 42 44 01:6386 38 00 125 01:6388 0C 1C 04 .db $0c,$1c,$04,$08,$08,$08,$3c,$00 ;1 01:638B 08 08 08 01:638E 3C 00 126 01:6390 1C 22 02 .db $1c,$22,$02,$0c,$30,$40,$7c,$00 ;2 01:6393 0C 30 40 01:6396 7C 00 127 01:6398 1C 22 02 .db $1c,$22,$02,$0c,$02,$44,$38,$00 ;3 01:639B 0C 02 44 01:639E 38 00 128 01:63A0 0E 12 24 .db $0e,$12,$24,$44,$7f,$08,$08,$00 ;4 01:63A3 44 7F 08 01:63A6 08 00 129 01:63A8 1F 10 20 .db $1f,$10,$20,$3c,$02,$42,$3c,$00 ;5 01:63AB 3C 02 42 01:63AE 3C 00 130 01:63B0 1E 21 20 .db $1e,$21,$20,$7c,$42,$42,$3c,$00 ;6 01:63B3 7C 42 42 01:63B6 3C 00 131 01:63B8 3E 22 44 .db $3e,$22,$44,$04,$08,$08,$10,$00 ;7 01:63BB 04 08 08 01:63BE 10 00 132 01:63C0 1C 22 22 .db $1c,$22,$22,$3c,$42,$42,$3c,$00 ;8 01:63C3 3C 42 42 01:63C6 3C 00 133 01:63C8 1C 22 22 .db $1c,$22,$22,$1e,$02,$44,$38,$00 ;9 01:63CB 1E 02 44 01:63CE 38 00 134 01:63D0 00 00 08 .db $00,$00,$08,$00,$00,$00,$10,$00 ;: 01:63D3 00 00 00 01:63D6 10 00 135 01:63D8 00 00 08 .db $00,$00,$08,$00,$00,$00,$10,$20 ;; 01:63DB 00 00 00 01:63DE 10 20 136 01:63E0 00 04 08 .db $00,$04,$08,$10,$10,$08,$04,$00 ;< 01:63E3 10 10 08 01:63E6 04 00 137 01:63E8 00 00 00 .db $00,$00,$00,$1e,$00,$1e,$00,$00 ;= 01:63EB 1E 00 1E 01:63EE 00 00 138 01:63F0 00 10 08 .db $00,$10,$08,$04,$04,$08,$10,$00 ;> 01:63F3 04 04 08 01:63F6 10 00 139 01:63F8 1C 22 02 .db $1c,$22,$02,$04,$08,$00,$10,$00 ;? 01:63FB 04 08 00 01:63FE 10 00 140 141 01:6400 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ;@ 01:6403 00 00 00 01:6406 00 00 142 01:6408 0E 12 12 .db $0e,$12,$12,$22,$3e,$42,$42,$00 ;A 01:640B 22 3E 42 01:640E 42 00 143 01:6410 1C 12 22 .db $1c,$12,$22,$3c,$22,$42,$7c,$00 ;B 01:6413 3C 22 42 01:6416 7C 00 144 01:6418 1C 22 22 .db $1c,$22,$22,$40,$40,$44,$38,$00 ;C 01:641B 40 40 44 01:641E 38 00 145 01:6420 18 14 22 .db $18,$14,$22,$22,$42,$44,$f8,$00 ;D 01:6423 22 42 44 01:6426 F8 00 146 01:6428 1E 10 20 .db $1e,$10,$20,$3c,$20,$40,$7c,$00 ;E 01:642B 3C 20 40 01:642E 7C 00 147 01:6430 1E 10 20 .db $1e,$10,$20,$3c,$20,$40,$40,$00 ;F 01:6433 3C 20 40 01:6436 40 00 148 01:6438 1C 22 20 .db $1c,$22,$20,$40,$47,$44,$38,$00 ;G 01:643B 40 47 44 01:643E 38 00 149 01:6440 11 11 22 .db $11,$11,$22,$3e,$22,$44,$44,$00 ;H 01:6443 3E 22 44 01:6446 44 00 150 01:6448 1E 08 08 .db $1e,$08,$08,$10,$10,$20,$f0,$00 ;I 01:644B 10 10 20 01:644E F0 00 151 01:6450 1E 04 04 .db $1e,$04,$04,$08,$88,$90,$60,$00 ;J 01:6453 08 88 90 01:6456 60 00 152 01:6458 10 12 24 .db $10,$12,$24,$38,$28,$44,$44,$00 ;K 01:645B 38 28 44 01:645E 44 00 153 01:6460 10 10 20 .db $10,$10,$20,$20,$20,$40,$7c,$00 ;L 01:6463 20 20 40 01:6466 7C 00 154 01:6468 21 27 5A .db $21,$27,$5a,$52,$42,$84,$84,$00 ;M 01:646B 52 42 84 01:646E 84 00 155 01:6470 21 21 52 .db $21,$21,$52,$52,$4a,$84,$84,$00 ;N 01:6473 52 4A 84 01:6476 84 00 156 01:6478 1C 22 22 .db $1c,$22,$22,$42,$42,$44,$38,$00 ;O 01:647B 42 42 44 01:647E 38 00 157 158 01:6480 1C 12 22 .db $1c,$12,$22,$3c,$20,$40,$40,$00 ;P 01:6483 3C 20 40 01:6486 40 00 159 01:6488 1C 22 22 .db $1c,$22,$22,$42,$4a,$44,$34,$02 ;Q 01:648B 42 4A 44 01:648E 34 02 160 01:6490 1C 12 22 .db $1c,$12,$22,$3c,$28,$48,$46,$00 ;R 01:6493 3C 28 48 01:6496 46 00 161 01:6498 1C 22 20 .db $1c,$22,$20,$18,$04,$44,$38,$00 ;S 01:649B 18 04 44 01:649E 38 00 162 01:64A0 3E 08 10 .db $3e,$08,$10,$10,$10,$20,$20,$00 ;T 01:64A3 10 10 20 01:64A6 20 00 163 01:64A8 22 22 42 .db $22,$22,$42,$44,$44,$44,$38,$00 ;U 01:64AB 44 44 44 01:64AE 38 00 164 01:64B0 42 44 44 .db $42,$44,$44,$48,$50,$50,$60,$00 ;V 01:64B3 48 50 50 01:64B6 60 00 165 01:64B8 41 41 42 .db $41,$41,$42,$52,$52,$6c,$44,$00 ;W 01:64BB 52 52 6C 01:64BE 44 00 166 01:64C0 22 24 18 .db $22,$24,$18,$18,$28,$44,$44,$00 ;X 01:64C3 18 28 44 01:64C6 44 00 167 01:64C8 42 42 24 .db $42,$42,$24,$18,$10,$20,$20,$00 ;Y 01:64CB 18 10 20 01:64CE 20 00 168 01:64D0 3E 02 04 .db $3e,$02,$04,$18,$20,$40,$7c,$00 ;Z 01:64D3 18 20 40 01:64D6 7C 00 169 01:64D8 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ;[ 01:64DB 00 00 00 01:64DE 00 00 170 01:64E0 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ;\ 01:64E3 00 00 00 01:64E6 00 00 171 01:64E8 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ;] 01:64EB 00 00 00 01:64EE 00 00 172 01:64F0 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ;^ 01:64F3 00 00 00 01:64F6 00 00 173 01:64F8 00 00 00 .db $00,$00,$00,$00,$00,$00,$3e,$00 ;_ 01:64FB 00 00 00 01:64FE 3E 00 174 175 01:6500 00 10 18 .db $00,$10,$18,$18,$00,$00,$00,$00 ; 01:6503 18 00 00 01:6506 00 00 176 01:6508 00 1C 02 .db $00,$1c,$02,$3c,$44,$48,$34,$00 ;a 01:650B 3C 44 48 01:650E 34 00 177 01:6510 00 08 08 .db $00,$08,$08,$1c,$12,$22,$3c,$00 ;b 01:6513 1C 12 22 01:6516 3C 00 178 01:6518 00 00 1C .db $00,$00,$1c,$22,$40,$40,$38,$00 ;c 01:651B 22 40 40 01:651E 38 00 179 01:6520 00 02 02 .db $00,$02,$02,$3c,$44,$48,$38,$00 ;d 01:6523 3C 44 48 01:6526 38 00 180 01:6528 00 00 1C .db $00,$00,$1c,$22,$7e,$40,$38,$00 ;e 01:652B 22 7E 40 01:652E 38 00 181 01:6530 00 06 08 .db $00,$06,$08,$3c,$10,$20,$20,$00 ;f 01:6533 3C 10 20 01:6536 20 00 182 01:6538 00 00 3A .db $00,$00,$3a,$44,$44,$38,$08,$70 ;g 01:653B 44 44 38 01:653E 08 70 183 01:6540 00 08 08 .db $00,$08,$08,$1c,$12,$22,$24,$00 ;h 01:6543 1C 12 22 01:6546 24 00 184 01:6548 00 04 00 .db $00,$04,$00,$08,$08,$10,$10,$00 ;i 01:654B 08 08 10 01:654E 10 00 185 01:6550 00 02 00 .db $00,$02,$00,$04,$44,$48,$38,$00 ;j 01:6553 04 44 48 01:6556 38 00 186 01:6558 00 10 12 .db $00,$10,$12,$24,$38,$48,$46,$00 ;k 01:655B 24 38 48 01:655E 46 00 187 01:6560 00 0C 04 .db $00,$0c,$04,$08,$08,$10,$10,$00 ;l 01:6563 08 08 10 01:6566 10 00 188 01:6568 00 00 2A .db $00,$00,$2a,$15,$25,$29,$4a,$00 ;m 01:656B 15 25 29 01:656E 4A 00 189 01:6570 00 00 2C .db $00,$00,$2c,$12,$12,$24,$26,$00 ;n 01:6573 12 12 24 01:6576 26 00 190 01:6578 00 00 0C .db $00,$00,$0c,$12,$22,$24,$18,$00 ;o 01:657B 12 22 24 01:657E 18 00 191 192 01:6580 00 0E 09 .db $00,$0e,$09,$11,$1e,$20,$20,$00 ;p 01:6583 11 1E 20 01:6586 20 00 193 01:6588 00 1E 22 .db $00,$1e,$22,$24,$1c,$08,$08,$00 ;q 01:658B 24 1C 08 01:658E 08 00 194 01:6590 00 00 2C .db $00,$00,$2c,$12,$10,$20,$20,$00 ;r 01:6593 12 10 20 01:6596 20 00 195 01:6598 00 00 1C .db $00,$00,$1c,$22,$18,$44,$38,$00 ;s 01:659B 22 18 44 01:659E 38 00 196 01:65A0 00 08 3C .db $00,$08,$3c,$10,$20,$20,$18,$00 ;t 01:65A3 10 20 20 01:65A6 18 00 197 01:65A8 00 00 22 .db $00,$00,$22,$42,$44,$48,$34,$00 ;u 01:65AB 42 44 48 01:65AE 34 00 198 01:65B0 00 00 22 .db $00,$00,$22,$24,$28,$28,$10,$00 ;v 01:65B3 24 28 28 01:65B6 10 00 199 01:65B8 00 00 21 .db $00,$00,$21,$41,$49,$5a,$2c,$00 ;w 01:65BB 41 49 5A 01:65BE 2C 00 200 01:65C0 00 00 11 .db $00,$00,$11,$0a,$0c,$14,$22,$00 ;x 01:65C3 0A 0C 14 01:65C6 22 00 201 01:65C8 00 00 11 .db $00,$00,$11,$21,$22,$1e,$04,$38 ;y 01:65CB 21 22 1E 01:65CE 04 38 202 01:65D0 00 00 3E .db $00,$00,$3e,$04,$18,$20,$7c,$00 ;z 01:65D3 04 18 20 01:65D6 7C 00 203 01:65D8 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ; 01:65DB 00 00 00 01:65DE 00 00 204 01:65E0 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ; 01:65E3 00 00 00 01:65E6 00 00 205 01:65E8 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ; 01:65EB 00 00 00 01:65EE 00 00 206 01:65F0 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ; 01:65F3 00 00 00 01:65F6 00 00 207 01:65F8 00 00 00 .db $00,$00,$00,$00,$00,$00,$00,$00 ; 01:65FB 00 00 00 01:65FE 00 00 #[2] startup.asm 181 E000 .code 182 0001 .bank LIB2_BANK 183 A600 .org $A600 184 185 0000 .ifdef HAVE_LIB3 189 .endif 190 191 6600 .data 192 0002 .bank CONST_BANK,"Constants" 193 4000 .org $4000 194 195 4000 .data 196 0003 .bank DATA_BANK,"User Program" 197 6000 .org $6000 198 199 ; 200 ; place overlay array here 201 ; 100 entries, stored as 100 202 ; lo-bytes of the starting 203 ; sector num, followed by 100 204 ; hi-bytes for a 128MB range 205 ; all files are contiguous, so 206 ; the # sectors is calculated 207 ; 208 03:6000 ovlarray: .ds 200 209 210 211 A600 .code 212 0000 .bank START_BANK,"Base Library 1" 213 214 ; A little introduction to the boot sequence: 215 ; 216 ; A HuCard has its origin at bank 0, and is mapped at $E000 217 ; It needs to grab the interrupt vectors at $FFF6 and implement 218 ; implement handlers for them 219 ; 220 ; A CDROM will load at bank $80 ($68 for SCD), and the initial 221 ; loader will be mapped at $4000. The current MagicKit sequence 222 ; also maps $C000 to this same bank. However, the initial boot 223 ; sequence will execute at $4070, proceeding to load additional 224 ; code and data, and then jump to a post-boot section called 225 ; 'init_go'. This is the point at which the loader explicitly 226 ; relinquishes the $4000 segment. It should be noted that there 227 ; are library subroutines loaded as part of this initial segment, 228 ; and those routines are located in the $C000 range as well. 229 ; 230 ; Sectors are loaded, up to and including the first "DATA_BANK", 231 ; where the overlay array is stored - so that the CDROM error 232 ; overlay can be located and executed in the event of a CDROM 233 ; system version mismatch (ie. playing SCD games on CDROM) 234 ; 235 ; A second entry point is defined for overlays that are not 236 ; being booted (ie. they are loaded and executed from another 237 ; overlay). This entry point is at $4000, after the segments 238 ; have all found their natural loading spots (ie. segment $68 239 ; for Super CDROMs). This entry point maps the necessary 240 ; segments and resets the stack, without clearing memory or 241 ; performing other setup chores, and then maps and executes 242 ; _main() to run the module. The user has no choice regarding 243 ; this function, although he can pass values through the global 244 ; variables which main() can use to decide what to do next. 245 ; 246 ; An additional "Hook" area has now been defined at $402F, 247 ; which is used at initial load time, in case a SCD overlay 248 ; program is run on plain CDROM hardware, and the author 249 ; wishes to override the default text error message by 250 ; loading and executing a plain CDROM program instead 251 ; 252 ; ---- 253 ; interrupt vectors 254 255 0001 .if !(CDROM) 256 FFF6 .org $FFF6 257 258 00:FFF6 23 E1 .dw irq2 259 00:FFF8 2A E1 .dw irq1 260 00:FFFA B8 E2 .dw timer 261 00:FFFC C5 E2 .dw nmi 262 00:FFFE 10 E0 .dw reset 263 .endif ; !(CDROM) 264 265 ; ---- 266 ; develo startup code 267 268 0000 .if (DEVELO) 278 .endif ; (DEVELO) 279 280 281 ; ---- 282 ; reset 283 ; ---- 284 ; things start here 285 ; ---- 286 287 ; ---- 288 ; CDROM re-map library bank 289 ; 290 ; 291 ; overlay entry point 292 ; 293 ; assume MMR0, MMR1, MMR6, MMR7 are set. 294 ; set others & reset stack pointer 295 ; 296 0000 .if (CDROM) 409 .else ; (ie. if HuCard...) 410 411 E010 .org $E010 412 00:E010 reset: 413 00:E010 78 sei ; disable interrupts 414 00:E011 D4 csh ; select the 7.16 MHz clock 415 00:E012 D8 cld ; clear the decimal flag 416 00:E013 A2 FF ldx #$FF ; initialize the stack pointer 417 00:E015 9A txs 418 00:E016 A9 FF lda #$FF ; map the I/O bank in the first page 419 00:E018 53 01 tam #0 420 00:E01A A9 F8 lda #$F8 ; and the RAM bank in the second page 421 00:E01C 53 02 tam #1 422 00:E01E 9C 00 20 stz $2000 ; clear all the RAM 423 00:E021 73 00 20 tii $2000,$2001,$1FFF 00:E024 01 20 FF 00:E027 1F 424 425 .endif ; (CDROM) 426 427 ; ---- 428 ; initialize the hardware 429 430 0000 .if (CDROM) 435 .else 436 00:E028 9C 01 0C stz timer_ctrl ; init timer 437 .endif ; (CDROM) 438 439 00:E02B 20 A8 E4 jsr init_psg ; init sound 440 00:E02E 20 3E E4 jsr init_vdc ; init video 441 0000 .ifdef _SGX 443 .endif 444 00:E031 A9 1F lda #$1F ; init joypad 445 00:E033 8D 27 22 sta joyena 446 447 ; ---- 448 ; initialize the sound driver 449 450 __sound_init 451 452 ; ---- 453 ; initialize interrupt vectors 454 455 0000 .if (CDROM) 460 .else 461 00:E036 A2 04 ldx #4 ; user vector table 462 00:E038 C2 cly 463 00:E039 A9 22 .l2: lda #LOW(rti) 464 00:E03B 99 00 22 sta user_jmptbl,Y 465 00:E03E C8 iny 466 00:E03F A9 E1 lda #HIGH(rti) 467 00:E041 99 00 22 sta user_jmptbl,Y 468 00:E044 C8 iny 469 00:E045 CA dex 470 00:E046 D0 F1 bne .l2 471 472 stw #reset,soft_reset ; soft reset 00:E048 A9 10 lda LOW_BYTE #reset 00:E04A 8D 84 22 sta LOW_BYTE soft_reset 00:E04D A9 E0 lda HIGH_BYTE #reset 00:E04F 8D 85 22 sta HIGH_BYTE soft_reset 473 stw #rts,vsync_hook ; user vsync routine 00:E052 A9 21 lda LOW_BYTE #rts 00:E054 8D 08 22 sta LOW_BYTE vsync_hook 00:E057 A9 E1 lda HIGH_BYTE #rts 00:E059 8D 09 22 sta HIGH_BYTE vsync_hook 474 stw #rts,hsync_hook ; user hsync routine 00:E05C A9 21 lda LOW_BYTE #rts 00:E05E 8D 0A 22 sta LOW_BYTE hsync_hook 00:E061 A9 E1 lda HIGH_BYTE #rts 00:E063 8D 0B 22 sta HIGH_BYTE hsync_hook 475 476 00:E066 A9 01 lda #$01 ; enable interrupts 477 00:E068 8D 02 14 sta irq_disable 478 00:E06B 9C 03 14 stz irq_status 479 00:E06E 58 cli 480 481 ; ---- 482 ; enable display and VSYNC interrupt 483 484 vreg #5 00:E06F A9 05 lda #5 00:E071 85 F7 sta $f400 236 00:E74A C9 F4 cmp #$f4 237 blo .l1 00:E74C 90 04 bcc .l1 238 00:E74E A9 E0 lda #$e0 239 00:E750 85 0E sta = 0) 00:E78B 90 02 bcc .x00139 ; 4(2) 00:E78D E6 01 inc <__stack +1 ; 0(6) 00:E78F .x00139: .else .endif 00:E78F 98 tya ; 2 => 20(24) / 26 .endif .endif 41 00:E790 A2 01 ldx #1 42 00:E792 62 cla 43 00:E793 60 rts 44 45 00:E794 eq_endno: 46 __addmi 2,__stack 0000 .if (2 = 1) .else 0000 .if (2 = -1) .else 00:E794 A8 tay ; 2 00:E795 18 clc ; 2 00:E796 A5 00 lda <__stack ; 4 00:E798 69 02 adc #low(2) ; 2 00:E79A 85 00 sta <__stack ; 4 0001 .if (2 < 256) & (2 >= 0) 00:E79C 90 02 bcc .x00140 ; 4(2) 00:E79E E6 01 inc <__stack+1 ; 0(6) 00:E7A0 .x00140: .else .endif 00:E7A0 98 tya ; 2 => 20(24) / 26 .endif .endif 47 00:E7A1 82 clx 48 00:E7A2 62 cla 49 00:E7A3 60 rts 50 51 00:E7A4 eqb: 52 00:E7A4 8A txa 53 00:E7A5 D2 00 cmp [__stack] 54 00:E7A7 D0 EB bne eq_endno 55 00:E7A9 80 D8 bra eq_endyes 56 57 ; streamlined version - uses zp ( <__temp ) instead of stack 58 ; returns A:X = 0 if false, 1 if true 59 60 00:E7AB eqzp: 61 00:E7AB C5 03 cmp <__temp+1 62 00:E7AD D0 09 bne .x_ne 63 00:E7AF 22 sax 64 00:E7B0 C5 02 cmp <__temp 65 00:E7B2 D0 04 bne .x_ne 66 00:E7B4 62 cla 67 00:E7B5 A2 01 ldx #1 ; ensure Z flag not set 68 00:E7B7 60 rts 69 00:E7B8 .x_ne: 70 00:E7B8 62 cla 71 00:E7B9 82 clx 72 00:E7BA 60 rts 73 74 00:E7BB eqbzp: 75 00:E7BB 8A txa 76 00:E7BC C5 02 cmp <__temp 77 00:E7BE 62 cla 78 00:E7BF D0 03 bne .x_ne 79 00:E7C1 A2 01 ldx #1 80 00:E7C3 60 rts 81 00:E7C4 .x_ne: 82 00:E7C4 82 clx 83 00:E7C5 60 rts 84 85 ; ---- 86 ; lt 87 ; ---- 88 ; compare two words 89 ; ---- 90 ; IN : First word on the C stack 91 ; Another word in A:X 92 ; ---- 93 ; OUT : word A:X is non nul if pushed word is strictly lower than 94 ; the word in A:X else nul 95 ; ---- 96 97 00:E7C6 ltb: ; XXX: missing optimized byte version 98 00:E7C6 lt: ; signed version 99 00:E7C6 A0 01 ldy #1 100 00:E7C8 C9 80 cmp #$80 101 00:E7CA B0 0A bcs lt_primary_minus 102 103 ; if here, the A:X value is positive 104 105 00:E7CC 85 02 sta <__temp 106 00:E7CE B1 00 lda [__stack], Y 107 00:E7D0 30 71 bmi cmp_ok ; stack value is negative, so reply OK 108 109 00:E7D2 A5 02 lda <__temp ; stack value is also positive, so just go for the unsigned version 110 00:E7D4 80 1B bra ult_y1 111 112 00:E7D6 lt_primary_minus: 113 114 ; if here, the A:X value is negative 115 116 00:E7D6 85 02 sta <__temp 117 00:E7D8 B1 00 lda [__stack], Y 118 00:E7DA 30 11 bmi getA_ult ; stack value is also negative, so restore A val from 119 ; __temp and call ult 120 121 00:E7DC cmp_false: 122 __addmi 2,__stack 0000 .if (2 = 1) .else 0000 .if (2 = -1) .else 00:E7DC A8 tay ; 2 00:E7DD 18 clc ; 2 00:E7DE A5 00 lda <__stack ; 4 00:E7E0 69 02 adc #low(2) ; 2 00:E7E2 85 00 sta <__stack ; 4 0001 .if (2 < 256) & (2 >= 0) 00:E7E4 90 02 bcc .x00141 ; 4(2) 00:E7E6 E6 01 inc <__stack+1 ; 0(6) 00:E7E8 .x00141: .else .endif 00:E7E8 98 tya ; 2 => 20(24) / 26 .endif .endif 123 00:E7E9 A2 00 ldx #0 124 00:E7EB 62 cla 125 00:E7EC 60 rts 126 127 00:E7ED getA_ult: 128 00:E7ED A5 02 lda <__temp 129 130 00:E7EF ult: ; unsigned version 131 00:E7EF A0 01 ldy #1 ; false by default 132 133 00:E7F1 ult_y1: ; same thing but Y is assumed to be equal to 1 134 135 00:E7F1 D1 00 cmp [__stack],Y 136 00:E7F3 F0 04 beq .lt_must_test_lobyte 137 00:E7F5 B0 4C bcs cmp_ok 138 00:E7F7 80 07 bra .lt_end ; hibyte of the reg var < hibyte of the pushed var 139 140 00:E7F9 .lt_must_test_lobyte: 141 00:E7F9 22 sax 142 00:E7FA D2 00 cmp [__stack] 143 00:E7FC F0 02 beq .lt_end 144 00:E7FE B0 43 bcs cmp_ok ; set result to true 145 ; lobyte of the reg var < lobyte of the pushed var 146 147 00:E800 .lt_end: 148 00:E800 98 tya ; __addmi does not preserve Y 149 __addmi 2,__stack 0000 .if (2 = 1) .else 0000 .if (2 = -1) .else 00:E801 A8 tay ; 2 00:E802 18 clc ; 2 00:E803 A5 00 lda <__stack ; 4 00:E805 69 02 adc #low(2) ; 2 00:E807 85 00 sta <__stack ; 4 0001 .if (2 < 256) & (2 >= 0) 00:E809 90 02 bcc .x00142 ; 4(2) 00:E80B E6 01 inc <__stack+1 ; 0(6) 00:E80D .x00142: .else .endif 00:E80D 98 tya ; 2 => 20(24) / 26 .endif .endif 150 ; if Y was 1, return A=X=0 -> false 151 00:E80E 49 FF eor #$ff ; if Y was 0, return A=0, X=1 -> true 152 00:E810 1A inc a 153 00:E811 1A inc a 154 00:E812 AA tax 155 00:E813 62 cla 156 00:E814 60 rts 157 158 00:E815 ublt: ; unsigned version 159 00:E815 8A txa 160 00:E816 D2 00 cmp [__stack] 161 00:E818 F0 02 beq .lt_end 162 00:E81A B0 27 bcs cmp_ok ; set result to true 163 ; lobyte of the reg var < lobyte of the pushed var 164 165 00:E81C .lt_end: 166 __addmi 2,__stack 0000 .if (2 = 1) .else 0000 .if (2 = -1) .else 00:E81C A8 tay ; 2 00:E81D 18 clc ; 2 00:E81E A5 00 lda <__stack ; 4 00:E820 69 02 adc #low(2) ; 2 00:E822 85 00 sta <__stack ; 4 0001 .if (2 < 256) & (2 >= 0) 00:E824 90 02 bcc .x00143 ; 4(2) 00:E826 E6 01 inc <__stack+1 ; 0(6) 00:E828 .x00143: .else .endif 00:E828 98 tya ; 2 => 20(24) / 26 .endif .endif 167 00:E829 A2 00 ldx #0 168 00:E82B 62 cla 169 00:E82C 60 rts 170 171 172 173 ; ---- 174 ; gt 175 ; ---- 176 ; compare two words 177 ; ---- 178 ; IN : First word on the C stack 179 ; Another word in A:X 180 ; ---- 181 ; OUT : word A:X is non nul if pushed word is strictly greater than 182 ; the word in A:X else nul 183 ; ---- 184 185 00:E82D gtb: ; XXX: missing optimized byte version 186 00:E82D gt: ; signed version of > 187 00:E82D A0 01 ldy #1 188 00:E82F C9 80 cmp #$80 189 00:E831 B0 0A bcs .gt_primary_minus 190 191 ; if here, the A:X value is positive 192 193 00:E833 85 02 sta <__temp 194 00:E835 B1 00 lda [__stack], Y 195 00:E837 30 A3 bmi cmp_false ; stack value is negative, so reply False 196 197 00:E839 A5 02 lda <__temp ; stack value is also positive, so just go for the unsigned version 198 00:E83B 80 1B bra ugt_y1 ; we spare one instruction, since we already have Y=1 199 200 00:E83D .gt_primary_minus: 201 202 ; if here, the A:X value is negative 203 204 00:E83D 85 02 sta <__temp 205 00:E83F B1 00 lda [__stack], Y 206 00:E841 30 11 bmi getA_ugt ; stack value is also negative, so restore A val from 207 ; __temp and call ugt 208 209 00:E843 cmp_ok: 210 __addmi 2,__stack 0000 .if (2 = 1) .else 0000 .if (2 = -1) .else 00:E843 A8 tay ; 2 00:E844 18 clc ; 2 00:E845 A5 00 lda <__stack ; 4 00:E847 69 02 adc #low(2) ; 2 00:E849 85 00 sta <__stack ; 4 0001 .if (2 < 256) & (2 >= 0) 00:E84B 90 02 bcc .x00144 ; 4(2) 00:E84D E6 01 inc <__stack+1 ; 0(6) 00:E84F .x00144: .else .endif 00:E84F 98 tya ; 2 => 20(24) / 26 .endif .endif 211 00:E850 A2 01 ldx #1 212 00:E852 62 cla 213 00:E853 60 rts 214 215 00:E854 getA_ugt: ; we grab back the value of A before entering the unsigned 216 ; version of > 217 00:E854 A5 02 lda <__temp 218 219 00:E856 ugt: ; unsigned version of > 220 221 00:E856 A0 01 ldy #1 222 223 00:E858 ugt_y1: ; unsigned version of >, assuming Y = 1 224 225 00:E858 D1 00 cmp [__stack],Y 226 00:E85A F0 05 beq .gt_must_test_lobyte 227 00:E85C B0 09 bcs .gt_end ; hibyte of the reg var >= hibyte of the pushed var 228 00:E85E C2 cly 229 00:E85F 80 06 bra .gt_end 230 231 00:E861 .gt_must_test_lobyte 232 00:E861 22 sax 233 00:E862 D2 00 cmp [__stack] 234 00:E864 B0 01 bcs .gt_end ; lobyte of the reg var >= lobyte of the pushed var 235 00:E866 C2 cly 236 237 00:E867 .gt_end: 238 00:E867 98 tya 239 __addmi 2,__stack 0000 .if (2 = 1) .else 0000 .if (2 = -1) .else 00:E868 A8 tay ; 2 00:E869 18 clc ; 2 00:E86A A5 00 lda <__stack ; 4 00:E86C 69 02 adc #low(2) ; 2 00:E86E 85 00 sta <__stack ; 4 0001 .if (2 < 256) & (2 >= 0) 00:E870 90 02 bcc .x00145 ; 4(2) 00:E872 E6 01 inc <__stack+1 ; 0(6) 00:E874 .x00145: .else .endif 00:E874 98 tya ; 2 => 20(24) / 26 .endif .endif 240 00:E875 49 FF eor #$ff 241 00:E877 1A inc a 242 00:E878 1A inc a 243 00:E879 AA tax 244 00:E87A 62 cla 245 00:E87B 60 rts 246 247 00:E87C ubgt: ; unsigned byte version of > 248 00:E87C 8A txa 249 00:E87D D2 00 cmp [__stack] 250 00:E87F 90 10 bcc .gt_true 251 __addmi 2,__stack 0000 .if (2 = 1) .else 0000 .if (2 = -1) .else 00:E881 A8 tay ; 2 00:E882 18 clc ; 2 00:E883 A5 00 lda <__stack ; 4 00:E885 69 02 adc #low(2) ; 2 00:E887 85 00 sta <__stack ; 4 0001 .if (2 < 256) & (2 >= 0) 00:E889 90 02 bcc .x00146 ; 4(2) 00:E88B E6 01 inc <__stack+1 ; 0(6) 00:E88D .x00146: .else .endif 00:E88D 98 tya ; 2 => 20(24) / 26 .endif .endif 252 00:E88E 82 clx 253 00:E88F 62 cla 254 00:E890 60 rts 255 00:E891 .gt_true: 256 __addmi 2,__stack 0000 .if (2 = 1) .else 0000 .if (2 = -1) .else 00:E891 A8 tay ; 2 00:E892 18 clc ; 2 00:E893 A5 00 lda <__stack ; 4 00:E895 69 02 adc #low(2) ; 2 00:E897 85 00 sta <__stack ; 4 0001 .if (2 < 256) & (2 >= 0) 00:E899 90 02 bcc .x00147 ; 4(2) 00:E89B E6 01 inc <__stack+1 ; 0(6) 00:E89D .x00147: .else .endif 00:E89D 98 tya ; 2 => 20(24) / 26 .endif .endif 257 00:E89E A2 01 ldx #1 258 00:E8A0 62 cla 259 00:E8A1 60 rts 260 261 262 ; ---- 263 ; zero page versions of lt/gt/ult/ugt: 264 ; ---- 265 266 00:E8A2 ltbzp: 267 00:E8A2 ltzp: ; signed, zero page 268 00:E8A2 85 04 sta <__temp+2 269 00:E8A4 45 03 eor <__temp+1 270 00:E8A6 10 0B bpl .geta_ult 271 00:E8A8 A5 04 lda <__temp+2 272 00:E8AA 10 03 bpl .true 273 00:E8AC 82 .false: clx 274 00:E8AD 62 cla 275 00:E8AE 60 rts 276 00:E8AF A2 01 .true: ldx #1 277 00:E8B1 62 cla 278 00:E8B2 60 rts 279 00:E8B3 .geta_ult: 280 00:E8B3 A5 04 lda <__temp+2 ; and fall through to unsigned test 281 282 00:E8B5 C5 03 ultzp: cmp <__temp+1 283 00:E8B7 F0 06 beq .test_lo 284 00:E8B9 90 0B bcc .false 285 00:E8BB A2 01 .true: ldx #1 286 00:E8BD 62 cla 287 00:E8BE 60 rts 288 00:E8BF .test_lo: 289 00:E8BF 22 sax 290 00:E8C0 C5 02 cmp <__temp 291 00:E8C2 F0 02 beq .false 292 00:E8C4 B0 F5 bcs .true 293 00:E8C6 82 .false: clx 294 00:E8C7 62 cla 295 00:E8C8 60 rts 296 297 00:E8C9 ubltzp: 298 00:E8C9 8A txa 299 00:E8CA C5 02 cmp <__temp 300 00:E8CC 62 cla 301 00:E8CD F0 05 beq .false 302 00:E8CF 90 03 bcc .false 303 00:E8D1 A2 01 ldx #1 304 00:E8D3 60 rts 305 00:E8D4 82 .false: clx 306 00:E8D5 60 rts 307 308 ; ---- 309 00:E8D6 gtbzp: 310 00:E8D6 gtzp: ; signed, zero page 311 00:E8D6 85 04 sta <__temp+2 312 00:E8D8 45 03 eor <__temp+1 313 00:E8DA 10 0B bpl .geta_ugt 314 00:E8DC A5 04 lda <__temp+2 315 00:E8DE 10 04 bpl .false 316 00:E8E0 A2 01 .true: ldx #1 317 00:E8E2 62 cla 318 00:E8E3 60 rts 319 00:E8E4 82 .false: clx 320 00:E8E5 62 cla 321 00:E8E6 60 rts 322 00:E8E7 .geta_ugt: 323 00:E8E7 A5 04 lda <__temp+2 ; and fall through to unsigned test 324 325 00:E8E9 ugtzp: 326 00:E8E9 C5 03 cmp <__temp+1 327 00:E8EB F0 06 beq .test_lo 328 00:E8ED B0 0B bcs .false 329 00:E8EF A2 01 .true: ldx #1 330 00:E8F1 62 cla 331 00:E8F2 60 rts 332 00:E8F3 .test_lo: 333 00:E8F3 22 sax 334 00:E8F4 C5 02 cmp <__temp 335 00:E8F6 F0 02 beq .false 336 00:E8F8 90 F5 bcc .true 337 00:E8FA 82 .false: clx 338 00:E8FB 62 cla 339 00:E8FC 60 rts 340 341 00:E8FD ubgtzp: 342 00:E8FD 8A txa 343 00:E8FE C5 02 cmp <__temp 344 00:E900 62 cla 345 00:E901 F0 05 beq .false 346 00:E903 B0 03 bcs .false 347 00:E905 A2 01 ldx #1 348 00:E907 60 rts 349 00:E908 82 .false: clx 350 00:E909 60 rts 351 352 353 ; ---- 354 ; ge 355 ; ---- 356 ; compare two signed words 357 ; ---- 358 ; IN : First word on the C stack 359 ; Another word in A:X 360 ; ---- 361 ; OUT : word A:X is non nul if pushed word is greater or egal to 362 ; the word in A:X else nul 363 ; ---- 364 365 ; XXX: can these be optimized? 366 00:E90A ge: ; signed version of > 367 00:E90A 20 C6 E7 jsr lt 368 00:E90D 22 sax 369 00:E90E 3A dec a 370 00:E90F 3A dec a 371 00:E910 49 FF eor #$ff 372 00:E912 22 sax 373 00:E913 60 rts 374 375 00:E914 geb: ; signed byte version of > 376 00:E914 20 C6 E7 jsr ltb 377 00:E917 22 sax 378 00:E918 3A dec a 379 00:E919 3A dec a 380 00:E91A 49 FF eor #$ff 381 00:E91C 22 sax 382 00:E91D 60 rts 383 384 00:E91E 20 A2 E8 gezp: jsr ltzp 385 00:E921 22 sax 386 00:E922 3A dec a 387 00:E923 3A dec a 388 00:E924 49 FF eor #$ff 389 00:E926 22 sax 390 00:E927 60 rts 391 392 00:E928 20 A2 E8 gebzp: jsr ltbzp 393 00:E92B 22 sax 394 00:E92C 3A dec a 395 00:E92D 3A dec a 396 00:E92E 49 FF eor #$ff 397 00:E930 22 sax 398 00:E931 60 rts 399 400 ; ---- 401 ; uge 402 ; ---- 403 ; compare two unsigned signed words 404 ; ---- 405 ; IN : First word on the C stack 406 ; Another word in A:X 407 ; ---- 408 ; OUT : word A:X is non nul if pushed word is greater or egal to 409 ; the word in A:X else nul 410 ; ---- 411 412 ; XXX: can these be optimized? 413 00:E932 uge: ; unsigned version of > 414 00:E932 20 EF E7 jsr ult 415 00:E935 22 sax 416 00:E936 3A dec a 417 00:E937 3A dec a 418 00:E938 49 FF eor #$ff 419 00:E93A 22 sax 420 00:E93B 60 rts 421 422 00:E93C ubge: ; unsigned byte version of > 423 00:E93C 20 15 E8 jsr ublt 424 00:E93F 22 sax 425 00:E940 3A dec a 426 00:E941 3A dec a 427 00:E942 49 FF eor #$ff 428 00:E944 22 sax 429 00:E945 60 rts 430 431 00:E946 20 B5 E8 ugezp: jsr ultzp 432 00:E949 22 sax 433 00:E94A 3A dec a 434 00:E94B 3A dec a 435 00:E94C 49 FF eor #$ff 436 00:E94E 22 sax 437 00:E94F 60 rts 438 439 00:E950 20 C9 E8 ubgezp: jsr ubltzp 440 00:E953 22 sax 441 00:E954 3A dec a 442 00:E955 3A dec a 443 00:E956 49 FF eor #$ff 444 00:E958 22 sax 445 00:E959 60 rts 446 447 ; ---- 448 ; ne 449 ; ---- 450 ; compare two words 451 ; ---- 452 ; IN : First word on the C stack 453 ; Another word in A:X 454 ; ---- 455 ; OUT : word A:X is non null if pushed word is different from 456 ; the word in A:X else null 457 ; ---- 458 ; REMARK : signed compatible 459 ; ---- 460 461 ; previous version called 'eq' as subroutine and returned 462 ; opposite value; should be fully implemented for speed 463 ; since '!=' is such a common operator 464 00:E95A ne: 465 00:E95A 22 sax 466 00:E95B D2 00 cmp [__stack] 467 00:E95D D0 17 bne .ne_endne 468 469 00:E95F A0 01 ldy #1 470 00:E961 22 sax 471 00:E962 D1 00 cmp [__stack],Y 472 00:E964 D0 10 bne .ne_endne 473 474 00:E966 .ne_endeq: 475 __addmi 2,__stack 0000 .if (2 = 1) .else 0000 .if (2 = -1) .else 00:E966 A8 tay ; 2 00:E967 18 clc ; 2 00:E968 A5 00 lda <__stack ; 4 00:E96A 69 02 adc #low(2) ; 2 00:E96C 85 00 sta <__stack ; 4 0001 .if (2 < 256) & (2 >= 0) 00:E96E 90 02 bcc .x00148 ; 4(2) 00:E970 E6 01 inc <__stack+1 ; 0(6) 00:E972 .x00148: .else .endif 00:E972 98 tya ; 2 => 20(24) / 26 .endif .endif 476 00:E973 82 clx 477 00:E974 62 cla 478 00:E975 60 rts 479 480 00:E976 .ne_endne: 481 __addmi 2,__stack 0000 .if (2 = 1) .else 0000 .if (2 = -1) .else 00:E976 A8 tay ; 2 00:E977 18 clc ; 2 00:E978 A5 00 lda <__stack ; 4 00:E97A 69 02 adc #low(2) ; 2 00:E97C 85 00 sta <__stack ; 4 0001 .if (2 < 256) & (2 >= 0) 00:E97E 90 02 bcc .x00149 ; 4(2) 00:E980 E6 01 inc <__stack+1 ; 0(6) 00:E982 .x00149: .else .endif 00:E982 98 tya ; 2 => 20(24) / 26 .endif .endif 482 00:E983 A2 01 ldx #1 483 00:E985 62 cla 484 00:E986 60 rts 485 486 00:E987 neb: 487 00:E987 8A txa 488 00:E988 D2 00 cmp [__stack] 489 00:E98A D0 10 bne .ne_endne 490 491 00:E98C .ne_endeq: 492 __addmi 2,__stack 0000 .if (2 = 1) .else 0000 .if (2 = -1) .else 00:E98C A8 tay ; 2 00:E98D 18 clc ; 2 00:E98E A5 00 lda <__stack ; 4 00:E990 69 02 adc #low(2) ; 2 00:E992 85 00 sta <__stack ; 4 0001 .if (2 < 256) & (2 >= 0) 00:E994 90 02 bcc .x00150 ; 4(2) 00:E996 E6 01 inc <__stack+1 ; 0(6) 00:E998 .x00150: .else .endif 00:E998 98 tya ; 2 => 20(24) / 26 .endif .endif 493 00:E999 82 clx 494 00:E99A 62 cla 495 00:E99B 60 rts 496 497 00:E99C .ne_endne: 498 __addmi 2,__stack 0000 .if (2 = 1) .else 0000 .if (2 = -1) .else 00:E99C A8 tay ; 2 00:E99D 18 clc ; 2 00:E99E A5 00 lda <__stack ; 4 00:E9A0 69 02 adc #low(2) ; 2 00:E9A2 85 00 sta <__stack ; 4 0001 .if (2 < 256) & (2 >= 0) 00:E9A4 90 02 bcc .x00151 ; 4(2) 00:E9A6 E6 01 inc <__stack+1 ; 0(6) 00:E9A8 .x00151: .else .endif 00:E9A8 98 tya ; 2 => 20(24) / 26 .endif .endif 499 00:E9A9 A2 01 ldx #1 500 00:E9AB 62 cla 501 00:E9AC 60 rts 502 503 ; streamlined version - uses zp ( <__temp ) instead of stack 504 ; returns A:X = 0 if false, 1 if true 505 506 00:E9AD nezp: 507 00:E9AD C5 03 cmp <__temp+1 508 00:E9AF D0 08 bne .x_ne 509 00:E9B1 22 sax 510 00:E9B2 C5 02 cmp <__temp 511 00:E9B4 D0 03 bne .x_ne 512 00:E9B6 62 cla 513 00:E9B7 82 clx 514 00:E9B8 60 rts 515 00:E9B9 .x_ne: 516 00:E9B9 62 cla 517 00:E9BA A2 01 ldx #1 ; ensure Z flag not set 518 00:E9BC 60 rts 519 520 00:E9BD nebzp: 521 00:E9BD 8A txa 522 00:E9BE C5 02 cmp <__temp 523 00:E9C0 62 cla 524 00:E9C1 D0 02 bne .x_ne 525 00:E9C3 82 clx 526 00:E9C4 60 rts 527 00:E9C5 .x_ne: 528 00:E9C5 A2 01 ldx #1 ; ensure Z flag not set 529 00:E9C7 60 rts 530 531 ; ---- 532 ; le 533 ; ---- 534 ; compare two signed words 535 ; ---- 536 ; IN : First word on the C stack 537 ; Another word in A:X 538 ; ---- 539 ; OUT : word A:X is non nul if pushed word is lower or egal to 540 ; the word in A:X else nul 541 ; ---- 542 543 ; XXX: can these be optimized? 544 00:E9C8 le: ; signed version 545 00:E9C8 20 2D E8 jsr gt 546 00:E9CB 22 sax 547 00:E9CC 49 FF eor #$ff 548 00:E9CE 1A inc a 549 00:E9CF 1A inc a 550 00:E9D0 22 sax 551 00:E9D1 60 rts 552 553 00:E9D2 leb: ; signed version 554 00:E9D2 20 2D E8 jsr gtb 555 00:E9D5 22 sax 556 00:E9D6 49 FF eor #$ff 557 00:E9D8 1A inc a ; assuming that A=1 if true 558 00:E9D9 1A inc a 559 00:E9DA 22 sax 560 00:E9DB 60 rts 561 562 00:E9DC 20 D6 E8 lezp: jsr gtzp 563 00:E9DF 22 sax 564 00:E9E0 49 FF eor #$ff 565 00:E9E2 1A inc a 566 00:E9E3 1A inc a 567 00:E9E4 22 sax 568 00:E9E5 60 rts 569 570 00:E9E6 20 D6 E8 lebzp: jsr gtbzp 571 00:E9E9 22 sax 572 00:E9EA 49 FF eor #$ff 573 00:E9EC 1A inc a 574 00:E9ED 1A inc a 575 00:E9EE 22 sax 576 00:E9EF 60 rts 577 578 ; ---- 579 ; ule 580 ; ---- 581 ; compare two unsigned words 582 ; ---- 583 ; IN : First word on the C stack 584 ; Another word in A:X 585 ; ---- 586 ; OUT : word A:X is non nul if pushed word is lower or egal to 587 ; the word in A:X else nul 588 ; ---- 589 590 ; XXX: can these be optimized? 591 00:E9F0 ule: ; unsigned version 592 00:E9F0 20 56 E8 jsr ugt 593 00:E9F3 22 sax 594 00:E9F4 49 FF eor #$ff 595 00:E9F6 1A inc A ; assuming that A=1 if true 596 00:E9F7 1A inc a 597 00:E9F8 22 sax 598 00:E9F9 60 rts 599 600 00:E9FA uble: ; unsigned byte version 601 00:E9FA 20 7C E8 jsr ubgt 602 00:E9FD 22 sax 603 00:E9FE 49 FF eor #$ff 604 00:EA00 1A inc A ; assuming that A=255 if true 605 00:EA01 1A inc a 606 00:EA02 22 sax 607 00:EA03 60 rts 608 609 00:EA04 20 E9 E8 ulezp: jsr ugtzp 610 00:EA07 22 sax 611 00:EA08 49 FF eor #$ff 612 00:EA0A 1A inc a 613 00:EA0B 1A inc a 614 00:EA0C 22 sax 615 00:EA0D 60 rts 616 617 00:EA0E 20 FD E8 ublezp: jsr ubgtzp 618 00:EA11 22 sax 619 00:EA12 49 FF eor #$ff 620 00:EA14 1A inc a 621 00:EA15 1A inc a 622 00:EA16 22 sax 623 00:EA17 60 rts 624 625 ; ---- 626 ; asl 627 ; ---- 628 ; shift the pushed word left by the register word 629 ; ---- 630 ; IN : First word on the C stack 631 ; Another word in A:X 632 ; ---- 633 ; OUT : Register word egals the previous pushed value 634 ; shifted left by A:X 635 ; ---- 636 ; REMARK : only the lower byte of the right operand is taken in account 637 ; signed compatible 638 ; ---- 639 00:EA18 asl: 640 00:EA18 86 02 stx <__temp 641 __ldwp __stack 00:EA1A B2 00 lda [__stack] 00:EA1C AA tax 00:EA1D A0 01 ldy #1 00:EA1F B1 00 lda [__stack],Y 642 00:EA21 A4 02 ldy <__temp 643 00:EA23 F0 0C beq .asl_end 644 00:EA25 85 02 sta <__temp 645 00:EA27 22 sax 646 647 00:EA28 .asl_begin 648 00:EA28 0A asl a 649 00:EA29 26 02 rol <__temp 650 00:EA2B 88 dey 651 00:EA2C D0 FA bne .asl_begin 652 653 00:EA2E 22 sax 654 00:EA2F A5 02 lda <__temp 655 656 00:EA31 .asl_end 657 __addmi 2,__stack 0000 .if (2 = 1) .else 0000 .if (2 = -1) .else 00:EA31 A8 tay ; 2 00:EA32 18 clc ; 2 00:EA33 A5 00 lda <__stack ; 4 00:EA35 69 02 adc #low(2) ; 2 00:EA37 85 00 sta <__stack ; 4 0001 .if (2 < 256) & (2 >= 0) 00:EA39 90 02 bcc .x00153 ; 4(2) 00:EA3B E6 01 inc <__stack+1 ; 0(6) 00:EA3D .x00153: .else .endif 00:EA3D 98 tya ; 2 => 20(24) / 26 .endif .endif 658 00:EA3E 60 rts 659 660 00:EA3F aslzp: 661 00:EA3F F0 0C beq .asl_end 662 00:EA41 85 02 sta <__temp 663 00:EA43 22 sax 664 665 00:EA44 .asl_begin 666 00:EA44 0A asl a 667 00:EA45 26 02 rol <__temp 668 00:EA47 88 dey 669 00:EA48 D0 FA bne .asl_begin 670 671 00:EA4A 22 sax 672 00:EA4B A5 02 lda <__temp 673 00:EA4D .asl_end 674 00:EA4D 60 rts 675 676 677 ; ---- 678 ; asr 679 ; ---- 680 ; shift the pushed word right by the register word 681 ; ---- 682 ; IN : First word on the C stack 683 ; Another word in A:X 684 ; ---- 685 ; OUT : Register word egals the previous pushed value 686 ; shifted right by A:X 687 ; ---- 688 ; REMARK : only the lower byte of the right operand is taken in account 689 ; signed compatible 690 ; ---- 691 00:EA4E asr: 692 00:EA4E 86 02 stx <__temp 693 __ldwp __stack 00:EA50 B2 00 lda [__stack] 00:EA52 AA tax 00:EA53 A0 01 ldy #1 00:EA55 B1 00 lda [__stack],Y 694 00:EA57 A4 02 ldy <__temp 695 00:EA59 F0 0E beq .asr_end 696 00:EA5B 85 02 sta <__temp 697 00:EA5D 22 sax 698 699 00:EA5E .asr_begin 700 00:EA5E E0 80 cpx #$80 701 00:EA60 66 02 ror <__temp 702 00:EA62 6A ror a 703 704 00:EA63 88 dey 705 00:EA64 D0 F8 bne .asr_begin 706 707 00:EA66 22 sax 708 00:EA67 A5 02 lda <__temp 709 710 00:EA69 .asr_end 711 __addmi 2,__stack 0000 .if (2 = 1) .else 0000 .if (2 = -1) .else 00:EA69 A8 tay ; 2 00:EA6A 18 clc ; 2 00:EA6B A5 00 lda <__stack ; 4 00:EA6D 69 02 adc #low(2) ; 2 00:EA6F 85 00 sta <__stack ; 4 0001 .if (2 < 256) & (2 >= 0) 00:EA71 90 02 bcc .x00155 ; 4(2) 00:EA73 E6 01 inc <__stack+1 ; 0(6) 00:EA75 .x00155: .else .endif 00:EA75 98 tya ; 2 => 20(24) / 26 .endif .endif 712 00:EA76 60 rts 713 714 00:EA77 asrzp: 715 00:EA77 F0 0E beq .asr_end 716 00:EA79 85 02 sta <__temp 717 00:EA7B 22 sax 718 719 00:EA7C .asr_begin 720 00:EA7C E0 80 cpx #$80 721 00:EA7E 66 02 ror <__temp 722 00:EA80 6A ror a 723 00:EA81 88 dey 724 00:EA82 D0 F8 bne .asr_begin 725 726 00:EA84 22 sax 727 00:EA85 A5 02 lda <__temp 728 00:EA87 .asr_end 729 00:EA87 60 rts 730 731 00:EA88 lsr: 732 00:EA88 86 02 stx <__temp 733 __ldwp __stack 00:EA8A B2 00 lda [__stack] 00:EA8C AA tax 00:EA8D A0 01 ldy #1 00:EA8F B1 00 lda [__stack],Y 734 00:EA91 A4 02 ldy <__temp 735 00:EA93 F0 0C beq .lsr_end 736 00:EA95 85 02 sta <__temp 737 00:EA97 22 sax 738 739 00:EA98 .lsr_begin 740 00:EA98 46 02 lsr <__temp 741 00:EA9A 6A ror a 742 00:EA9B 88 dey 743 00:EA9C D0 FA bne .lsr_begin 744 745 00:EA9E 22 sax 746 00:EA9F A5 02 lda <__temp 747 748 00:EAA1 .lsr_end 749 __addmi 2,__stack 0000 .if (2 = 1) .else 0000 .if (2 = -1) .else 00:EAA1 A8 tay ; 2 00:EAA2 18 clc ; 2 00:EAA3 A5 00 lda <__stack ; 4 00:EAA5 69 02 adc #low(2) ; 2 00:EAA7 85 00 sta <__stack ; 4 0001 .if (2 < 256) & (2 >= 0) 00:EAA9 90 02 bcc .x00157 ; 4(2) 00:EAAB E6 01 inc <__stack+1 ; 0(6) 00:EAAD .x00157: .else .endif 00:EAAD 98 tya ; 2 => 20(24) / 26 .endif .endif 750 00:EAAE 60 rts 751 752 00:EAAF lsrzp: 753 00:EAAF F0 0C beq .lsr_end 754 00:EAB1 85 02 sta <__temp 755 00:EAB3 22 sax 756 757 00:EAB4 .lsr_begin 758 00:EAB4 46 02 lsr <__temp 759 00:EAB6 6A ror a 760 00:EAB7 88 dey 761 00:EAB8 D0 FA bne .lsr_begin 762 763 00:EABA 22 sax 764 00:EABB A5 02 lda <__temp 765 00:EABD .lsr_end 766 00:EABD 60 rts 767 768 ; ---- 769 ; smul 770 ; ---- 771 ; multiply two SIGNED words 772 ; ---- 773 ; IN : First word on the C stack 774 ; Another word in A:X 775 ; ---- 776 ; OUT : Register word egals the previous pushed value 777 ; multiplied by A:X 778 ; ---- 779 780 00:EABE smul: 781 00:EABE 64 0F stz <__sign ; until we call umul, sign keeps the sign parity 782 ; of operand 783 00:EAC0 C9 80 cmp #$80 784 00:EAC2 90 0D bcc smul_no_invert_primary 785 786 __negw 00:EAC4 22 sax 00:EAC5 49 FF eor #$FF 00:EAC7 18 clc 00:EAC8 69 01 adc #1 00:EACA 22 sax 00:EACB 49 FF eor #$FF 00:EACD 69 00 adc #0 787 788 00:EACF E6 0F inc <__sign ; sign ++ 789 790 00:EAD1 smul_no_invert_primary: 791 00:EAD1 85 02 sta <__temp 792 00:EAD3 A0 01 ldy #1 793 00:EAD5 B1 00 lda [__stack],Y 794 00:EAD7 C9 80 cmp #$80 795 00:EAD9 90 1B bcc smul_no_invert_secondary 796 797 00:EADB E6 0F inc <__sign ; this time, no optimisation possible, IMHO :) 798 ; are you sure? :)) 799 00:EADD 86 03 stx <__temp+1 800 801 00:EADF B2 00 lda [__stack] 802 00:EAE1 AA tax 803 00:EAE2 B1 00 lda [__stack],Y ; we assumed Y = 1 since we set it at the 804 ; beginning of smul_no_invert_primary 805 __negw 00:EAE4 22 sax 00:EAE5 49 FF eor #$FF 00:EAE7 18 clc 00:EAE8 69 01 adc #1 00:EAEA 22 sax 00:EAEB 49 FF eor #$FF 00:EAED 69 00 adc #0 806 00:EAEF 91 00 sta [__stack],Y 807 00:EAF1 22 sax 808 00:EAF2 92 00 sta [__stack] 809 810 00:EAF4 A6 03 ldx <__temp+1 811 812 00:EAF6 smul_no_invert_secondary: 813 00:EAF6 A5 0F lda <__sign 814 00:EAF8 48 pha 815 00:EAF9 A5 02 lda <__temp ; saved at the beginning of smul_no_invert_primary 816 ; where we're sure we passed 817 818 00:EAFB 20 13 EB jsr umul 819 820 00:EAFE 42 say 821 00:EAFF 68 pla 822 00:EB00 29 01 and #$01 823 00:EB02 F0 0D beq smul_end 824 825 00:EB04 42 say 826 __negw 00:EB05 22 sax 00:EB06 49 FF eor #$FF 00:EB08 18 clc 00:EB09 69 01 adc #1 00:EB0B 22 sax 00:EB0C 49 FF eor #$FF 00:EB0E 69 00 adc #0 827 00:EB10 60 rts 828 829 00:EB11 smul_end: 830 00:EB11 42 say 831 00:EB12 60 rts 832 833 834 ; ---- 835 ; umul 836 ; ---- 837 ; multiply two UNSIGNED words 838 ; ---- 839 ; IN : First word on the C stack 840 ; Another word in A:X 841 ; ---- 842 ; OUT : Register word egals the previous pushed value 843 ; multiplied by A:X 844 ; ---- 845 846 00:EB13 umul: 847 __stw <__temp+2 ; bx 00:EB13 86 04 stx <__temp+2 00:EB15 85 05 sta <__temp+2+1 848 __ldwp __stack 00:EB17 B2 00 lda [__stack] 00:EB19 AA tax 00:EB1A A0 01 ldy #1 00:EB1C B1 00 lda [__stack],Y 849 __stw <__temp ; ax 00:EB1E 86 02 stx <__temp 00:EB20 85 03 sta <__temp+1 850 00:EB22 20 37 EB jsr umul16 851 __addmi 2,__stack 0000 .if (2 = 1) .else 0000 .if (2 = -1) .else 00:EB25 A8 tay ; 2 00:EB26 18 clc ; 2 00:EB27 A5 00 lda <__stack ; 4 00:EB29 69 02 adc #low(2) ; 2 00:EB2B 85 00 sta <__stack ; 4 0001 .if (2 < 256) & (2 >= 0) 00:EB2D 90 02 bcc .x00164 ; 4(2) 00:EB2F E6 01 inc <__stack+1 ; 0(6) 00:EB31 .x00164: .else .endif 00:EB31 98 tya ; 2 => 20(24) / 26 .endif .endif 852 __ldw <__ptr 0000 .if (1 = 2) .else 00:EB32 A6 06 ldx <__ptr 00:EB34 A5 07 lda <__ptr+1 .endif 853 00:EB36 60 rts 854 855 00:EB37 umul16: 856 00:EB37 A5 05 lda <__temp+3 857 00:EB39 05 03 ora <__temp+1 858 00:EB3B F0 21 beq umul8 859 860 stwz <__ptr 00:EB3D 64 06 stz LOW_BYTE <__ptr 00:EB3F 64 07 stz HIGH_BYTE <__ptr 861 00:EB41 A0 10 ldy #16 862 863 .l1: aslw <__ptr 00:EB43 06 06 asl <__ptr ; word-sized value (at stated 00:EB45 26 07 rol <__ptr+1 ; memory location) 864 aslw <__temp+2 00:EB47 06 04 asl <__temp+2 ; word-sized value (at stated 00:EB49 26 05 rol <__temp+2+1 ; memory location) 865 00:EB4B 90 0D bcc .l2 866 addw <__temp,<__ptr 0000 .if (2 = 3) .else ; 2-arg mode ; 00:EB4D 18 clc 00:EB4E A5 06 lda LOW_BYTE <__ptr 00:EB50 65 02 adc LOW_BYTE <__temp 00:EB52 85 06 sta LOW_BYTE <__ptr 00:EB54 A5 07 lda HIGH_BYTE <__ptr 00:EB56 65 03 adc HIGH_BYTE <__temp 00:EB58 85 07 sta HIGH_BYTE <__ptr .endif 867 00:EB5A 88 .l2: dey 868 00:EB5B D0 E6 bne .l1 869 870 00:EB5D 60 rts 871 872 00:EB5E umul8: 873 00:EB5E A5 04 lda <__temp+2 874 00:EB60 85 07 sta <__ptr+1 875 00:EB62 62 cla 876 00:EB63 A0 08 ldy #8 877 878 00:EB65 0A .l1: asl A 879 00:EB66 26 07 rol <__ptr+1 880 00:EB68 90 07 bcc .l2 881 add <__temp 0000 .if (1 = 2) ; register A (handle carry .else 00:EB6A 18 clc 00:EB6B 65 02 adc <__temp .endif 882 00:EB6D 90 02 bcc .l2 883 00:EB6F E6 07 inc <__ptr+1 884 00:EB71 88 .l2: dey 885 00:EB72 D0 F1 bne .l1 886 887 00:EB74 85 06 sta <__ptr 888 00:EB76 60 rts 889 890 891 ; ---- 892 ; sdiv 893 ; ---- 894 ; divide two SIGNED words 895 ; ---- 896 ; IN : First word on the C stack 897 ; Another word in A:X 898 ; ---- 899 ; OUT : Register word egals the previous pushed value 900 ; divided by A:X 901 ; ---- 902 903 00:EB77 sdiv: 904 00:EB77 64 0F stz <__sign ; until we call udiv, sign keeps the sign parity 905 ; of operand 906 00:EB79 C9 80 cmp #$80 907 00:EB7B 90 0D bcc sdiv_no_invert_primary 908 909 __negw 00:EB7D 22 sax 00:EB7E 49 FF eor #$FF 00:EB80 18 clc 00:EB81 69 01 adc #1 00:EB83 22 sax 00:EB84 49 FF eor #$FF 00:EB86 69 00 adc #0 910 911 00:EB88 E6 0F inc <__sign ; sign ++ 912 913 00:EB8A sdiv_no_invert_primary: 914 00:EB8A 85 02 sta <__temp 915 00:EB8C A0 01 ldy #1 916 00:EB8E B1 00 lda [__stack],Y 917 00:EB90 C9 80 cmp #$80 918 00:EB92 90 1B bcc sdiv_no_invert_secondary 919 920 00:EB94 E6 0F inc <__sign 921 922 00:EB96 86 03 stx <__temp+1 923 924 00:EB98 B2 00 lda [__stack] 925 00:EB9A AA tax 926 00:EB9B B1 00 lda [__stack],Y ; we assumed Y = 1 since we set it at the beginning of 927 ; sdiv_no_invert_primary 928 __negw 00:EB9D 22 sax 00:EB9E 49 FF eor #$FF 00:EBA0 18 clc 00:EBA1 69 01 adc #1 00:EBA3 22 sax 00:EBA4 49 FF eor #$FF 00:EBA6 69 00 adc #0 929 00:EBA8 91 00 sta [__stack],Y 930 00:EBAA 22 sax 931 00:EBAB 92 00 sta [__stack] 932 933 00:EBAD A6 03 ldx <__temp+1 934 935 00:EBAF sdiv_no_invert_secondary: 936 00:EBAF A5 0F lda <__sign 937 00:EBB1 48 pha 938 00:EBB2 A5 02 lda <__temp ; saved at the beginning of sdiv_no_invert_primary 939 ; where we're sure we passed 940 00:EBB4 20 CC EB jsr udiv 941 942 00:EBB7 42 say 943 00:EBB8 68 pla 944 00:EBB9 29 01 and #$01 945 00:EBBB F0 0D beq sdiv_end 946 947 00:EBBD 42 say 948 __negw 00:EBBE 22 sax 00:EBBF 49 FF eor #$FF 00:EBC1 18 clc 00:EBC2 69 01 adc #1 00:EBC4 22 sax 00:EBC5 49 FF eor #$FF 00:EBC7 69 00 adc #0 949 00:EBC9 60 rts 950 951 00:EBCA sdiv_end: 952 00:EBCA 42 say 953 00:EBCB 60 rts 954 955 956 ; ---- 957 ; udiv 958 ; ---- 959 ; divide two UNSIGNED words 960 ; ---- 961 ; IN : First word on the C stack 962 ; Another word in A:X 963 ; ---- 964 ; OUT : Register word egals the previous pushed value 965 ; divided by A:X 966 ; ---- 967 968 00:EBCC udiv: 969 __stw <__ptr 00:EBCC 86 06 stx <__ptr 00:EBCE 85 07 sta <__ptr+1 970 __ldwp __stack 00:EBD0 B2 00 lda [__stack] 00:EBD2 AA tax 00:EBD3 A0 01 ldy #1 00:EBD5 B1 00 lda [__stack],Y 971 __stw <__temp 00:EBD7 86 02 stx <__temp 00:EBD9 85 03 sta <__temp+1 972 973 00:EBDB A9 00 lda #0 974 00:EBDD 85 11 sta <__remain+1 975 00:EBDF A0 10 ldy #16 976 00:EBE1 06 02 .sdiv_begin: asl <__temp 977 00:EBE3 26 03 rol <__temp+1 978 00:EBE5 2A rol a 979 00:EBE6 26 11 rol <__remain+1 980 00:EBE8 48 pha 981 00:EBE9 C5 06 cmp <__ptr 982 00:EBEB A5 11 lda <__remain+1 983 00:EBED E5 07 sbc <__ptr+1 984 00:EBEF 90 08 bcc .sdiv_end 985 00:EBF1 85 11 sta <__remain+1 986 00:EBF3 68 pla 987 00:EBF4 E5 06 sbc <__ptr 988 00:EBF6 48 pha 989 00:EBF7 E6 02 inc <__temp 990 00:EBF9 68 .sdiv_end: pla 991 00:EBFA 88 dey 992 00:EBFB D0 E4 bne .sdiv_begin 993 00:EBFD 85 10 sta <__remain 994 995 __addmi 2,__stack 0000 .if (2 = 1) .else 0000 .if (2 = -1) .else 00:EBFF A8 tay ; 2 00:EC00 18 clc ; 2 00:EC01 A5 00 lda <__stack ; 4 00:EC03 69 02 adc #low(2) ; 2 00:EC05 85 00 sta <__stack ; 4 0001 .if (2 < 256) & (2 >= 0) 00:EC07 90 02 bcc .x00177 ; 4(2) 00:EC09 E6 01 inc <__stack+1 ; 0(6) 00:EC0B .x00177: .else .endif 00:EC0B 98 tya ; 2 => 20(24) / 26 .endif .endif 996 __ldw <__temp 0000 .if (1 = 2) .else 00:EC0C A6 02 ldx <__temp 00:EC0E A5 03 lda <__temp+1 .endif 997 998 00:EC10 60 rts 999 1000 1001 ; ---- 1002 ; smod 1003 ; ---- 1004 ; give the integer remainder of the two words 1005 ; ---- 1006 ; IN : First word on the C stack 1007 ; Another word in A:X 1008 ; ---- 1009 ; OUT : Register word egals the remainder of the division of the 1010 ; pushed value by A:X 1011 ; ---- 1012 1013 00:EC11 smod: 1014 00:EC11 64 0F stz <__sign 1015 __stw <__ptr 00:EC13 86 06 stx <__ptr 00:EC15 85 07 sta <__ptr+1 1016 __ldwp __stack 00:EC17 B2 00 lda [__stack] 00:EC19 AA tax 00:EC1A A0 01 ldy #1 00:EC1C B1 00 lda [__stack],Y 1017 00:EC1E C9 80 cmp #$80 1018 00:EC20 90 15 bcc .skip1 1019 00:EC22 E6 0F inc <__sign 1020 __negw 00:EC24 22 sax 00:EC25 49 FF eor #$FF 00:EC27 18 clc 00:EC28 69 01 adc #1 00:EC2A 22 sax 00:EC2B 49 FF eor #$FF 00:EC2D 69 00 adc #0 1021 __stwp __stack 00:EC2F 22 sax 00:EC30 92 00 sta [__stack] 00:EC32 22 sax 00:EC33 A0 01 ldy #1 00:EC35 91 00 sta [__stack],Y 1022 .skip1: __ldw <__ptr 0000 .if (1 = 2) .else 00:EC37 A6 06 ldx <__ptr 00:EC39 A5 07 lda <__ptr+1 .endif 1023 00:EC3B C9 80 cmp #$80 1024 00:EC3D 90 0B bcc .skip2 1025 __negw 00:EC3F 22 sax 00:EC40 49 FF eor #$FF 00:EC42 18 clc 00:EC43 69 01 adc #1 00:EC45 22 sax 00:EC46 49 FF eor #$FF 00:EC48 69 00 adc #0 1026 00:EC4A 20 5D EC .skip2: jsr umod 1027 00:EC4D A4 0F ldy <__sign 1028 00:EC4F F0 0B beq .noinv 1029 __negw 00:EC51 22 sax 00:EC52 49 FF eor #$FF 00:EC54 18 clc 00:EC55 69 01 adc #1 00:EC57 22 sax 00:EC58 49 FF eor #$FF 00:EC5A 69 00 adc #0 1030 00:EC5C 60 .noinv: rts 1031 1032 00:EC5D umod: 1033 __stw <__ptr 00:EC5D 86 06 stx <__ptr 00:EC5F 85 07 sta <__ptr+1 1034 __ldwp __stack 00:EC61 B2 00 lda [__stack] 00:EC63 AA tax 00:EC64 A0 01 ldy #1 00:EC66 B1 00 lda [__stack],Y 1035 __stw <__temp 00:EC68 86 02 stx <__temp 00:EC6A 85 03 sta <__temp+1 1036 1037 00:EC6C A9 00 lda #0 1038 00:EC6E 85 11 sta <__remain+1 1039 00:EC70 A0 10 ldy #16 1040 00:EC72 06 02 .umod_begin: asl <__temp 1041 00:EC74 26 03 rol <__temp+1 1042 00:EC76 2A rol a 1043 00:EC77 26 11 rol <__remain+1 1044 00:EC79 48 pha 1045 00:EC7A C5 06 cmp <__ptr 1046 00:EC7C A5 11 lda <__remain+1 1047 00:EC7E E5 07 sbc <__ptr+1 1048 00:EC80 90 08 bcc .umod_end 1049 00:EC82 85 11 sta <__remain+1 1050 00:EC84 68 pla 1051 00:EC85 E5 06 sbc <__ptr 1052 00:EC87 48 pha 1053 00:EC88 E6 02 inc <__temp 1054 00:EC8A 68 .umod_end: pla 1055 00:EC8B 88 dey 1056 00:EC8C D0 E4 bne .umod_begin 1057 00:EC8E 85 10 sta <__remain 1058 1059 __addmi 2,__stack 0000 .if (2 = 1) .else 0000 .if (2 = -1) .else 00:EC90 A8 tay ; 2 00:EC91 18 clc ; 2 00:EC92 A5 00 lda <__stack ; 4 00:EC94 69 02 adc #low(2) ; 2 00:EC96 85 00 sta <__stack ; 4 0001 .if (2 < 256) & (2 >= 0) 00:EC98 90 02 bcc .x00189 ; 4(2) 00:EC9A E6 01 inc <__stack+1 ; 0(6) 00:EC9C .x00189: .else .endif 00:EC9C 98 tya ; 2 => 20(24) / 26 .endif .endif 1060 __ldw <__remain 0000 .if (1 = 2) .else 00:EC9D A6 10 ldx <__remain 00:EC9F A5 11 lda <__remain+1 .endif 1061 1062 00:ECA1 60 rts 1063 1064 ; ---- 1065 ; ___case 1066 ; ---- 1067 ; implement a switch instruction in C 1068 ; ---- 1069 ; IN : primary register (A:X) contain the discriminant value 1070 ; i.e. the one that will be checked against those indicated in the 1071 ; various case instructions 1072 ; On the stack, a pointer is passed 1073 ; This is a pointer toward an array 1074 ; Each item of this array is a 4 bytes long structure 1075 ; The structure is the following : 1076 ; WORD value_to_check 1077 ; WORD label_to_jump_to 1078 ; We have to parse the whole array in order to compare the primary 1079 ; register with all the 'value_to_check' field. If we ever find that 1080 ; the primary register is egal to such a value, we must jump to the 1081 ; corresponding 'label_to_jump_to'. 1082 ; The default value (which also means that we reached the end of the 1083 ; array) can be recognized with its 'label_to_jump_to' field set to 0. 1084 ; Then the 'value_to_check' field become the default label we have to 1085 ; use for the rest of the execution. 1086 ; ---- 1087 ; OUT : The execution goes to another place 1088 ; ---- 1089 ; REMARK : Also use remain variable as a temporary value 1090 ; ---- 1091 1092 00:ECA2 ___case: 1093 __stw <__remain ; store the value to check to 00:ECA2 86 10 stx <__remain 00:ECA4 85 11 sta <__remain +1 1094 __ldwp __stack 00:ECA6 B2 00 lda [__stack] 00:ECA8 AA tax 00:ECA9 A0 01 ldy #1 00:ECAB B1 00 lda [__stack],Y 1095 __stw <__ptr ; __ptr contain the address of the array 00:ECAD 86 06 stx <__ptr 00:ECAF 85 07 sta <__ptr +1 1096 1097 __addmi 2,__stack 0000 .if (2 = 1) .else 0000 .if (2 = -1) .else 00:ECB1 A8 tay ; 2 00:ECB2 18 clc ; 2 00:ECB3 A5 00 lda <__stack ; 4 00:ECB5 69 02 adc #low(2) ; 2 00:ECB7 85 00 sta <__stack ; 4 0001 .if (2 < 256) & (2 >= 0) 00:ECB9 90 02 bcc .x00194 ; 4(2) 00:ECBB E6 01 inc <__stack+1 ; 0(6) 00:ECBD .x00194: .else .endif 00:ECBD 98 tya ; 2 => 20(24) / 26 .endif .endif 1098 1099 00:ECBE C2 cly 1100 00:ECBF 80 02 bra .begin_case 1101 1102 00:ECC1 .next_case_lo: 1103 00:ECC1 C8 iny 1104 00:ECC2 .next_case_hi: 1105 00:ECC2 C8 iny 1106 00:ECC3 .begin_case: 1107 00:ECC3 C8 iny ; skip func lo-byte 1108 00:ECC4 B1 06 lda [__ptr],y ; test func hi-byte 1109 00:ECC6 F0 1C beq .case_default 1110 00:ECC8 C8 iny 1111 00:ECC9 B1 06 lda [__ptr],y 1112 00:ECCB C5 10 cmp <__remain+0 1113 00:ECCD D0 F2 bne .next_case_lo 1114 00:ECCF C8 iny 1115 00:ECD0 B1 06 lda [__ptr],y 1116 00:ECD2 C5 11 cmp <__remain+1 1117 00:ECD4 D0 EC bne .next_case_hi 1118 00:ECD6 88 dey ; found match 1119 00:ECD7 88 dey 1120 00:ECD8 .case_vector: 1121 00:ECD8 B1 06 lda [__ptr],y ; read func hi-byte 1122 00:ECDA 85 03 sta <__temp+1 1123 00:ECDC 88 dey 1124 00:ECDD B1 06 lda [__ptr],y ; read func lo-byte 1125 00:ECDF 85 02 sta <__temp+0 1126 00:ECE1 6C 02 20 jmp [__temp] 1127 00:ECE4 .case_default: 1128 00:ECE4 C8 iny 1129 00:ECE5 C8 iny 1130 00:ECE6 80 F0 bra .case_vector 1131 1132 1133 ; ---- 1134 ; hook 1135 ; ---- 1136 ; indirect call to sub-routine 1137 ; ---- 1138 ; IN : sub-routine addr in __ptr 1139 ; ---- 1140 1141 00:ECE8 hook: 1142 00:ECE8 6C 06 20 jmp [__ptr] 1143 1144 ; ---- 1145 ; setvdc 1146 ; ---- 1147 ; set a vdc register 1148 ; ---- 1149 ; IN : - reg index on the C stack 1150 ; - value in A:X 1151 ; ---- 1152 1153 00:ECEB A8 setvdc: tay 1154 00:ECEC B2 00 lda [__sp] 1155 00:ECEE 4A lsr a 1156 00:ECEF C9 09 cmp #$09 1157 00:ECF1 F0 19 beq .l3 1158 1159 00:ECF3 85 F7 .l1: sta = 0) 00:ED06 90 02 bcc .x00195 ; 4(2) 00:ED08 E6 01 inc <__sp+1 ; 0(6) 00:ED0A .x00195: .else .endif 00:ED0A 98 tya ; 2 => 20(24) / 26 .endif .endif 1164 00:ED0B 60 rts 1165 ; -- reg $09 1166 00:ED0C 8A .l3: txa 1167 00:ED0D 29 70 and #$70 1168 00:ED0F 4A lsr A 1169 00:ED10 4A lsr A 1170 00:ED11 4A lsr A 1171 00:ED12 4A lsr A 1172 00:ED13 20 62 E4 jsr set_bat_size 1173 00:ED16 80 E6 bra .l2 1174 1175 ; ---- 1176 ; getvdc 1177 ; ---- 1178 ; get vdc register content 1179 ; ---- 1180 ; IN : reg index in A:X 1181 ; ---- 1182 ; OUT: vdc register in A:X 1183 ; ---- 1184 1185 00:ED18 E0 04 getvdc: cpx #4 1186 00:ED1A D0 0E bne .l1 1187 00:ED1C A9 02 lda #2 1188 00:ED1E 85 F7 sta = 0) 00:F565 90 02 bcc .x00308 ; 4(2) 00:F567 E6 01 inc <__sp+1 ; 0(6) 00:F569 .x00308: .else .endif 00:F569 98 tya ; 2 => 20(24) / 26 .endif .endif 1326 00:F56A 60 rts 1327 1328 ; scroll_disable(char num) 1329 ; ---- 1330 ; disable screen scrolling for a scroll region 1331 ; ---- 1332 1333 00:F56B _scroll_disable: 1334 00:F56B BD 2A 27 lda scroll_cr,X 1335 00:F56E 29 FE and #$fe 1336 00:F570 9D 2A 27 sta scroll_cr,X 1337 00:F573 60 rts 1338 1339 ; set_screen_size(char size) 1340 ; ---- 1341 ; set screen virtual size 1342 ; ---- 1343 1344 00:F574 _set_screen_size: 1345 00:F574 8A txa 1346 00:F575 4C 62 E4 jmp set_bat_size 1347 1348 ; set_xres(int xres) 1349 ; ---- 1350 ; set horizontal display resolution 1351 ; ---- 1352 1353 00:F578 _set_xres.1: 1354 00:F578 A9 04 lda #XRES_SOFT 1355 00:F57A 85 FC sta <__cl 1356 00:F57C _set_xres.2: 1357 00:F57C 20 50 E4 jsr set_xres 1358 00:F57F A6 F8 ldx <__al 1359 00:F581 A5 F9 lda <__ah 1360 00:F583 60 rts 1361 1362 1363 ; ------------------------ 1364 ; Graphics functions 1365 ; ------------------------ 1366 1367 ; readvram 1368 ; ---- 1369 ; leftover from asm library 1370 ; needed for 'a = vram[n]' 1371 ; semantic 1372 ; ---- 1373 00:F584 readvram: 1374 00:F584 A0 01 ldy #1 1375 00:F586 84 F7 sty cx 1589 1590 stw <__bp,line_curry ; swap coordinates 01:ACEB A5 EC lda LOW_BYTE <__bp 01:ACED 8D 80 29 sta LOW_BYTE line_curry 01:ACF0 A5 ED lda HIGH_BYTE <__bp 01:ACF2 8D 81 29 sta HIGH_BYTE line_curry 1591 stw <__cx,<__bp 01:ACF5 A5 FC lda LOW_BYTE <__cx 01:ACF7 85 EC sta LOW_BYTE <__bp 01:ACF9 A5 FD lda HIGH_BYTE <__cx 01:ACFB 85 ED sta HIGH_BYTE <__bp 1592 stw <__si,line_currx 01:ACFD A5 EE lda LOW_BYTE <__si 01:ACFF 8D 7E 29 sta LOW_BYTE line_currx 01:AD02 A5 EF lda HIGH_BYTE <__si 01:AD04 8D 7F 29 sta HIGH_BYTE line_currx 1593 stw <__bx,<__si 01:AD07 A5 FA lda LOW_BYTE <__bx 01:AD09 85 EE sta LOW_BYTE <__si 01:AD0B A5 FB lda HIGH_BYTE <__bx 01:AD0D 85 EF sta HIGH_BYTE <__si 1594 1595 01:AD0F 80 14 bra .l2 1596 1597 .l1: stw <__bx,line_currx 01:AD11 A5 FA lda LOW_BYTE <__bx 01:AD13 8D 7E 29 sta LOW_BYTE line_currx 01:AD16 A5 FB lda HIGH_BYTE <__bx 01:AD18 8D 7F 29 sta HIGH_BYTE line_currx 1598 stw <__cx,line_curry 01:AD1B A5 FC lda LOW_BYTE <__cx 01:AD1D 8D 80 29 sta LOW_BYTE line_curry 01:AD20 A5 FD lda HIGH_BYTE <__cx 01:AD22 8D 81 29 sta HIGH_BYTE line_curry 1599 1600 ; now: 1601 ; line_currx and line_curry are start point 1602 ; <__si and <__bp are end point 1603 ; <__bx and <__cx are 'dont care' 1604 1605 01:AD25 .l2: 1606 01:AD25 A5 EC lda LOW_BYTE <__bp 1607 sub LOW_BYTE line_curry 0000 .if (1 = 2) ; from register A (handle .else 01:AD27 38 sec 01:AD28 ED 80 29 sbc LOW_BYTE line_curry .endif 1608 01:AD2B 8D 84 29 sta LOW_BYTE line_deltay 1609 01:AD2E A5 ED lda HIGH_BYTE <__bp 1610 01:AD30 ED 81 29 sbc HIGH_BYTE line_curry 1611 01:AD33 8D 85 29 sta HIGH_BYTE line_deltay 1612 1613 01:AD36 A5 EE lda LOW_BYTE <__si 1614 sub LOW_BYTE line_currx 0000 .if (1 = 2) ; from register A (handle .else 01:AD38 38 sec 01:AD39 ED 7E 29 sbc LOW_BYTE line_currx .endif 1615 01:AD3C 8D 82 29 sta LOW_BYTE line_deltax 1616 01:AD3F A5 EF lda HIGH_BYTE <__si 1617 01:AD41 ED 7F 29 sbc HIGH_BYTE line_currx 1618 01:AD44 8D 83 29 sta HIGH_BYTE line_deltax 1619 1620 01:AD47 9C 8A 29 stz line_xdir ; 0 = positive 1621 1622 01:AD4A AD 83 29 lda HIGH_BYTE line_deltax 1623 01:AD4D 10 14 bpl .l3 1624 1625 01:AD4F A9 01 lda #1 1626 01:AD51 8D 8A 29 sta line_xdir ; 1 = negative 1627 negw line_deltax 01:AD54 62 cla ; (at stated memory location) sub line_deltax ; 2's complement 0000 .if (1 = 2) ; from register A (handle .else 01:AD55 38 sec 01:AD56 ED 82 29 sbc line_deltax .endif 01:AD59 8D 82 29 sta line_deltax 01:AD5C 62 cla 01:AD5D ED 83 29 sbc line_deltax+1 01:AD60 8D 83 29 sta line_deltax+1 1628 1629 ; now: 1630 ; line_deltay is difference from end to start (positive) 1631 ; line_deltax is difference from end to start (positive) 1632 ; line_xdir shows whether to apply deltax positive or negative 1633 1634 1635 01:AD63 .l3: 1636 cmpw line_deltax,line_deltay 01:AD63 AD 85 29 lda HIGH_BYTE line_deltay 01:AD66 CD 83 29 cmp HIGH_BYTE line_deltax 01:AD69 D0 06 bne .x_00346 01:AD6B AD 84 29 lda LOW_BYTE line_deltay 01:AD6E CD 82 29 cmp LOW_BYTE line_deltax 01:AD71 .x_00346: 1637 lbhs .ybiglp ; jump if deltay > |deltax| 01:AD71 90 03 bcc .x_00347 01:AD73 4C 6F AE jmp .ybiglp 01:AD76 .x_00347 1638 1639 01:AD76 .xbiglp: 1640 __ldw line_deltay 0000 .if (1 = 2) .else 01:AD76 AE 84 29 ldx line_deltay 01:AD79 AD 85 29 lda line_deltay+1 .endif 1641 __aslw 01:AD7C 22 sax 01:AD7D 0A asl A 01:AD7E 22 sax 01:AD7F 2A rol A 1642 __stw line_adjust 01:AD80 8E 88 29 stx line_adjust 01:AD83 8D 89 29 sta line_adjust+1 1643 __stw line_error 01:AD86 8E 86 29 stx line_error 01:AD89 8D 87 29 sta line_error+1 1644 1645 subw line_deltax,line_adjust 01:AD8C 38 sec 01:AD8D AD 88 29 lda LOW_BYTE line_adjust 01:AD90 ED 82 29 sbc LOW_BYTE line_deltax 01:AD93 8D 88 29 sta LOW_BYTE line_adjust 01:AD96 AD 89 29 lda HIGH_BYTE line_adjust 01:AD99 ED 83 29 sbc HIGH_BYTE line_deltax 01:AD9C 8D 89 29 sta HIGH_BYTE line_adjust 1646 subw line_deltax,line_adjust 01:AD9F 38 sec 01:ADA0 AD 88 29 lda LOW_BYTE line_adjust 01:ADA3 ED 82 29 sbc LOW_BYTE line_deltax 01:ADA6 8D 88 29 sta LOW_BYTE line_adjust 01:ADA9 AD 89 29 lda HIGH_BYTE line_adjust 01:ADAC ED 83 29 sbc HIGH_BYTE line_deltax 01:ADAF 8D 89 29 sta HIGH_BYTE line_adjust 1647 1648 subw line_deltax,line_error 01:ADB2 38 sec 01:ADB3 AD 86 29 lda LOW_BYTE line_error 01:ADB6 ED 82 29 sbc LOW_BYTE line_deltax 01:ADB9 8D 86 29 sta LOW_BYTE line_error 01:ADBC AD 87 29 lda HIGH_BYTE line_error 01:ADBF ED 83 29 sbc HIGH_BYTE line_deltax 01:ADC2 8D 87 29 sta HIGH_BYTE line_error 1649 1650 incw line_deltax ; used as counter - get both endpoints 01:ADC5 EE 82 29 inc line_deltax ; value at stated memory 01:ADC8 D0 03 bne .x_00355 ; location 01:ADCA EE 83 29 inc line_deltax +1 01:ADCD .x_00355: 1651 1652 01:ADCD .xlp1: 1653 stw line_currx,<__bx ; draw pixel 01:ADCD AD 7E 29 lda LOW_BYTE line_currx 01:ADD0 85 FA sta LOW_BYTE <__bx 01:ADD2 AD 7F 29 lda HIGH_BYTE line_currx 01:ADD5 85 FB sta HIGH_BYTE <__bx 1654 stw line_curry,<__cx 01:ADD7 AD 80 29 lda LOW_BYTE line_curry 01:ADDA 85 FC sta LOW_BYTE <__cx 01:ADDC AD 81 29 lda HIGH_BYTE line_curry 01:ADDF 85 FD sta HIGH_BYTE <__cx 1655 01:ADE1 AE 8B 29 ldx line_color 1656 01:ADE4 62 cla 1657 01:ADE5 20 66 AF jsr lib2_gfx_plot.3 1658 1659 decw line_deltax ; dec counter 01:ADE8 38 sec ; value at stated memory 01:ADE9 AD 82 29 lda line_deltax ; location 01:ADEC E9 01 sbc #1 01:ADEE 8D 82 29 sta line_deltax 01:ADF1 AD 83 29 lda line_deltax +1 01:ADF4 E9 00 sbc #0 01:ADF6 8D 83 29 sta line_deltax +1 1660 tstw line_deltax 01:ADF9 AD 82 29 lda line_deltax ; value at stated memory 01:ADFC 0D 83 29 ora line_deltax+1 ; location is zero 1661 lbeq .out 01:ADFF D0 03 bne .x_00360 01:AE01 4C 65 AF jmp .out 01:AE04 .x_00360 1662 1663 01:AE04 AD 8A 29 lda line_xdir ; adjust currx 1664 01:AE07 F0 13 beq .xlppos 1665 1666 decw line_currx 01:AE09 38 sec ; value at stated memory 01:AE0A AD 7E 29 lda line_currx ; location 01:AE0D E9 01 sbc #1 01:AE0F 8D 7E 29 sta line_currx 01:AE12 AD 7F 29 lda line_currx+1 01:AE15 E9 00 sbc #0 01:AE17 8D 7F 29 sta line_currx+1 1667 01:AE1A 80 08 bra .xlp2 1668 1669 .xlppos: incw line_currx 01:AE1C EE 7E 29 inc line_currx ; value at stated memory 01:AE1F D0 03 bne .x_00362 ; location 01:AE21 EE 7F 29 inc line_currx+1 01:AE24 .x_00362: 1670 1671 01:AE24 .xlp2: 1672 01:AE24 AD 87 29 lda HIGH_BYTE line_error 1673 01:AE27 30 1D bmi .xlp3 1674 1675 addw line_adjust,line_error 0000 .if (2 = 3) .else ; 2-arg mode ; 01:AE29 18 clc 01:AE2A AD 86 29 lda LOW_BYTE line_error 01:AE2D 6D 88 29 adc LOW_BYTE line_adjust 01:AE30 8D 86 29 sta LOW_BYTE line_error 01:AE33 AD 87 29 lda HIGH_BYTE line_error 01:AE36 6D 89 29 adc HIGH_BYTE line_adjust 01:AE39 8D 87 29 sta HIGH_BYTE line_error .endif 1676 incw line_curry 01:AE3C EE 80 29 inc line_curry ; value at stated memory 01:AE3F D0 03 bne .x_00364 ; location 01:AE41 EE 81 29 inc line_curry+1 01:AE44 .x_00364: 1677 01:AE44 80 87 bra .xlp1 1678 01:AE46 .xlp3: 1679 addw line_deltay,line_error 0000 .if (2 = 3) .else ; 2-arg mode ; 01:AE46 18 clc 01:AE47 AD 86 29 lda LOW_BYTE line_error 01:AE4A 6D 84 29 adc LOW_BYTE line_deltay 01:AE4D 8D 86 29 sta LOW_BYTE line_error 01:AE50 AD 87 29 lda HIGH_BYTE line_error 01:AE53 6D 85 29 adc HIGH_BYTE line_deltay 01:AE56 8D 87 29 sta HIGH_BYTE line_error .endif 1680 addw line_deltay,line_error 0000 .if (2 = 3) .else ; 2-arg mode ; 01:AE59 18 clc 01:AE5A AD 86 29 lda LOW_BYTE line_error 01:AE5D 6D 84 29 adc LOW_BYTE line_deltay 01:AE60 8D 86 29 sta LOW_BYTE line_error 01:AE63 AD 87 29 lda HIGH_BYTE line_error 01:AE66 6D 85 29 adc HIGH_BYTE line_deltay 01:AE69 8D 87 29 sta HIGH_BYTE line_error .endif 1681 01:AE6C 4C CD AD jmp .xlp1 1682 1683 01:AE6F .ybiglp: 1684 __ldw line_deltax 0000 .if (1 = 2) .else 01:AE6F AE 82 29 ldx line_deltax 01:AE72 AD 83 29 lda line_deltax+1 .endif 1685 __aslw 01:AE75 22 sax 01:AE76 0A asl A 01:AE77 22 sax 01:AE78 2A rol A 1686 __stw line_adjust 01:AE79 8E 88 29 stx line_adjust 01:AE7C 8D 89 29 sta line_adjust+1 1687 __stw line_error 01:AE7F 8E 86 29 stx line_error 01:AE82 8D 87 29 sta line_error+1 1688 1689 subw line_deltay,line_adjust 01:AE85 38 sec 01:AE86 AD 88 29 lda LOW_BYTE line_adjust 01:AE89 ED 84 29 sbc LOW_BYTE line_deltay 01:AE8C 8D 88 29 sta LOW_BYTE line_adjust 01:AE8F AD 89 29 lda HIGH_BYTE line_adjust 01:AE92 ED 85 29 sbc HIGH_BYTE line_deltay 01:AE95 8D 89 29 sta HIGH_BYTE line_adjust 1690 subw line_deltay,line_adjust 01:AE98 38 sec 01:AE99 AD 88 29 lda LOW_BYTE line_adjust 01:AE9C ED 84 29 sbc LOW_BYTE line_deltay 01:AE9F 8D 88 29 sta LOW_BYTE line_adjust 01:AEA2 AD 89 29 lda HIGH_BYTE line_adjust 01:AEA5 ED 85 29 sbc HIGH_BYTE line_deltay 01:AEA8 8D 89 29 sta HIGH_BYTE line_adjust 1691 1692 subw line_deltay,line_error 01:AEAB 38 sec 01:AEAC AD 86 29 lda LOW_BYTE line_error 01:AEAF ED 84 29 sbc LOW_BYTE line_deltay 01:AEB2 8D 86 29 sta LOW_BYTE line_error 01:AEB5 AD 87 29 lda HIGH_BYTE line_error 01:AEB8 ED 85 29 sbc HIGH_BYTE line_deltay 01:AEBB 8D 87 29 sta HIGH_BYTE line_error 1693 1694 incw line_deltay ; used as counter - get both endpoints 01:AEBE EE 84 29 inc line_deltay ; value at stated memory 01:AEC1 D0 03 bne .x_00374 ; location 01:AEC3 EE 85 29 inc line_deltay +1 01:AEC6 .x_00374: 1695 1696 01:AEC6 .ylp1: 1697 stw line_currx,<__bx ; draw pixel 01:AEC6 AD 7E 29 lda LOW_BYTE line_currx 01:AEC9 85 FA sta LOW_BYTE <__bx 01:AECB AD 7F 29 lda HIGH_BYTE line_currx 01:AECE 85 FB sta HIGH_BYTE <__bx 1698 stw line_curry,<__cx 01:AED0 AD 80 29 lda LOW_BYTE line_curry 01:AED3 85 FC sta LOW_BYTE <__cx 01:AED5 AD 81 29 lda HIGH_BYTE line_curry 01:AED8 85 FD sta HIGH_BYTE <__cx 1699 01:AEDA AE 8B 29 ldx line_color 1700 01:AEDD 62 cla 1701 01:AEDE 20 66 AF jsr lib2_gfx_plot.3 1702 1703 decw line_deltay ; dec counter 01:AEE1 38 sec ; value at stated memory 01:AEE2 AD 84 29 lda line_deltay ; location 01:AEE5 E9 01 sbc #1 01:AEE7 8D 84 29 sta line_deltay 01:AEEA AD 85 29 lda line_deltay +1 01:AEED E9 00 sbc #0 01:AEEF 8D 85 29 sta line_deltay +1 1704 tstw line_deltay 01:AEF2 AD 84 29 lda line_deltay ; value at stated memory 01:AEF5 0D 85 29 ora line_deltay+1 ; location is zero 1705 01:AEF8 F0 6B beq .out 1706 1707 incw line_curry 01:AEFA EE 80 29 inc line_curry ; value at stated memory 01:AEFD D0 03 bne .x_00379 ; location 01:AEFF EE 81 29 inc line_curry+1 01:AF02 .x_00379: 1708 1709 01:AF02 AD 87 29 lda HIGH_BYTE line_error 1710 01:AF05 30 35 bmi .ylp2 1711 1712 addw line_adjust,line_error 0000 .if (2 = 3) .else ; 2-arg mode ; 01:AF07 18 clc 01:AF08 AD 86 29 lda LOW_BYTE line_error 01:AF0B 6D 88 29 adc LOW_BYTE line_adjust 01:AF0E 8D 86 29 sta LOW_BYTE line_error 01:AF11 AD 87 29 lda HIGH_BYTE line_error 01:AF14 6D 89 29 adc HIGH_BYTE line_adjust 01:AF17 8D 87 29 sta HIGH_BYTE line_error .endif 1713 01:AF1A AD 8A 29 lda line_xdir 1714 01:AF1D F0 13 beq .ylppos 1715 1716 decw line_currx 01:AF1F 38 sec ; value at stated memory 01:AF20 AD 7E 29 lda line_currx ; location 01:AF23 E9 01 sbc #1 01:AF25 8D 7E 29 sta line_currx 01:AF28 AD 7F 29 lda line_currx+1 01:AF2B E9 00 sbc #0 01:AF2D 8D 7F 29 sta line_currx+1 1717 01:AF30 80 94 bra .ylp1 1718 1719 01:AF32 .ylppos: 1720 incw line_currx 01:AF32 EE 7E 29 inc line_currx ; value at stated memory 01:AF35 D0 03 bne .x_00382 ; location 01:AF37 EE 7F 29 inc line_currx+1 01:AF3A .x_00382: 1721 01:AF3A 80 8A bra .ylp1 1722 1723 01:AF3C .ylp2: 1724 addw line_deltax,line_error 0000 .if (2 = 3) .else ; 2-arg mode ; 01:AF3C 18 clc 01:AF3D AD 86 29 lda LOW_BYTE line_error 01:AF40 6D 82 29 adc LOW_BYTE line_deltax 01:AF43 8D 86 29 sta LOW_BYTE line_error 01:AF46 AD 87 29 lda HIGH_BYTE line_error 01:AF49 6D 83 29 adc HIGH_BYTE line_deltax 01:AF4C 8D 87 29 sta HIGH_BYTE line_error .endif 1725 addw line_deltax,line_error 0000 .if (2 = 3) .else ; 2-arg mode ; 01:AF4F 18 clc 01:AF50 AD 86 29 lda LOW_BYTE line_error 01:AF53 6D 82 29 adc LOW_BYTE line_deltax 01:AF56 8D 86 29 sta LOW_BYTE line_error 01:AF59 AD 87 29 lda HIGH_BYTE line_error 01:AF5C 6D 83 29 adc HIGH_BYTE line_deltax 01:AF5F 8D 87 29 sta HIGH_BYTE line_error .endif 1726 01:AF62 4C C6 AE jmp .ylp1 1727 1728 01:AF65 .out: 1729 01:AF65 60 rts 1730 1731 1732 ; gfx_plot(int x [__bx], int y [__cx], char color [reg acc]) 1733 ; ---- 1734 ; Plot a point at location (x,y) in color 1735 ; ---- 1736 1737 01:AF66 lib2_gfx_plot.3: 1738 01:AF66 86 FE stx <__dl ; color 1739 01:AF68 20 77 B0 jsr gfx_getaddr 1740 1741 ; same as vm_rawread - save 21 cycles by inlining 1742 ; 1743 vreg #1 ; video read register 01:AF6B A9 01 lda #1 01:AF6D 85 F7 sta 14 cycles by inlining 1763 ; 1764 01:AFA0 DA phx 1765 01:AFA1 AA tax 1766 vreg #0 ; video write register 01:AFA2 A9 00 lda #0 01:AFA4 85 F7 sta 14 cycles by inlining 1798 ; 1799 01:B001 DA phx 1800 01:B002 AA tax 1801 vreg #0 ; video write register 01:B003 A9 00 lda #0 01:B005 85 F7 sta ); 124 ;void __fastcall satb_update(unsigned char max); 125 ;void __fastcall vreg(unsigned char reg); 126 ;void __fastcall vreg(unsigned char reg<__al>, unsigned int data); 127 ;void __fastcall spr_hide(unsigned char num); 128 ;void __fastcall spr_show(unsigned char num); 129 ;void __fastcall set_map_pals(char far *pal<__bl:__si>); 130 ;void set_map_tile_type(unsigned char); 131 ;void set_map_tile_base(unsigned int vaddr); 132 ;unsigned char mem_mapdatabank(unsigned char new_bank); 133 ;unsigned int mem_mapdatabanks(unsigned int new_banks); 134 ;void timer_set(unsigned char cnt); 135 ;void timer_start(void); 136 ;void timer_stop(void); 137 ;unsigned char timer_get(void); 138 ;void irq_enable(unsigned char irq); 139 ;void irq_disable(unsigned char irq); 140 ;#define STATUS_LINE 3 141 ; char glb_bal; 142 ; char chn_bal; 143 ; char ctrl; 144 ;#asm 145 00:FB76 _beepsetup: 146 00:FB76 A9 02 lda #2 147 00:FB78 8D 00 08 sta psg_ch 148 00:FB7B A9 FF lda #$FF 149 00:FB7D 8D 01 08 sta psg_mainvol 150 00:FB80 A9 1C lda #$1C ; 4KHz 151 00:FB82 8D 02 08 sta psg_freqlo 152 00:FB85 9C 03 08 stz psg_freqhi 153 00:FB88 A9 00 lda #$0 154 00:FB8A 8D 04 08 sta psg_ctrl 155 00:FB8D A9 1F lda #$1F 156 00:FB8F A2 10 ldx #16 157 00:FB91 .loop: 158 00:FB91 8D 06 08 sta psg_wavebuf 159 00:FB94 CA dex 160 00:FB95 D0 FA bne .loop 161 00:FB97 A9 00 lda #$0 162 00:FB99 A2 10 ldx #16 163 00:FB9B .loop1: 164 00:FB9B 8D 06 08 sta psg_wavebuf 165 00:FB9E CA dex 166 00:FB9F D0 FA bne .loop1 167 00:FBA1 A9 FF lda #$FF 168 00:FBA3 8D 05 08 sta psg_pan 169 00:FBA6 A9 9F lda #$9f 170 00:FBA8 8D 04 08 sta psg_ctrl 171 00:FBAB 60 rts 172 00:FBAC _beepoff: 173 00:FBAC A9 00 lda #$0 174 00:FBAE 8D 04 08 sta psg_ctrl 175 00:FBB1 60 rts 176 00:FBB2 _beepon: 177 00:FBB2 A9 9F lda #$9f 178 00:FBB4 8D 04 08 sta psg_ctrl 179 00:FBB7 60 rts 180 ;char a; 181 ;main() 182 ;{ 183 04:4000 .proc _main 184 ; set_color(0,0); 185 __ldwi 0 04:A000 A2 00 ldx #low(0) 04:A002 A9 00 lda #high(0) 186 __stw color_reg 04:A004 8E 02 04 stx color_reg 04:A007 8D 03 04 sta color_reg+1 187 __ldwi 0 04:A00A A2 00 ldx #low(0) 04:A00C A9 00 lda #high(0) 188 __stw color_data 04:A00E 8E 04 04 stx color_data 04:A011 8D 05 04 sta color_data+1 189 ; set_color(1,511); 190 __ldwi 1 04:A014 A2 01 ldx #low(1) 04:A016 A9 00 lda #high(1) 191 __stw color_reg 04:A018 8E 02 04 stx color_reg 04:A01B 8D 03 04 sta color_reg+1 192 __ldwi 511 04:A01E A2 FF ldx #low(511) 04:A020 A9 01 lda #high(511) 193 __stw color_data 04:A022 8E 04 04 stx color_data 04:A025 8D 05 04 sta color_data+1 194 ; beepsetup(); 195 04:A028 20 76 FB call _beepsetup 196 ; beepoff(); 197 04:A02B 20 AC FB call _beepoff 198 ; while (1) { 199 04:A02E LL2: 200 201 __ldwi 1 04:A02E A2 01 ldx #low(1) 04:A030 A9 00 lda #high(1) 202 __tstw ; pha 04:A032 86 02 stx <__temp 04:A034 05 02 ora <__temp 04:A036 62 cla 04:A037 82 clx 04:A038 F0 01 beq .x_00548 04:A03A E8 inx 04:A03B .x_00548: ; pla 203 __lbeq LL3 04:A03B E0 00 cpx #0 04:A03D D0 03 bne .x00549 04:A03F 4C F8 A1 jmp LL3 04:A042 .x00549 204 ; vsync(0); 205 __ldwi 0 04:A042 A2 00 ldx #low(0) 04:A044 A9 00 lda #high(0) 206 04:A046 20 55 EF call _vsync.1 207 ; a = joy(0); 208 __ldwi 0 04:A049 A2 00 ldx #low(0) 04:A04B A9 00 lda #high(0) 209 04:A04D 20 53 F9 call _joy 210 04:A050 8E 94 29 stx _a 211 ; if (a & JOY_DOWN) { 212 __ldub _a 0000 .if (1 = 2) .else 04:A053 AE 94 29 ldx _a 04:A056 62 cla .endif 213 __andwi 64 04:A057 22 sax 04:A058 29 40 and #low(64) 04:A05A 22 sax 04:A05B 29 00 and #high(64) 214 __tstw ; pha 04:A05D 86 02 stx <__temp 04:A05F 05 02 ora <__temp 04:A061 62 cla 04:A062 82 clx 04:A063 F0 01 beq .x_00554 04:A065 E8 inx 04:A066 .x_00554: ; pla 215 __lbeq LL4 04:A066 E0 00 cpx #0 04:A068 D0 03 bne .x00555 04:A06A 4C 95 A0 jmp LL4 04:A06D .x00555 216 ; put_string("D", 1, STATUS_LINE); 217 __ldwi LL0+0 04:A06D A2 00 ldx #low(LL0+0) 04:A06F A9 40 lda #high(LL0+0) 218 __stw __si 04:A071 8E EE 20 stx __si 04:A074 8D EF 20 sta __si+1 219 __ldwi 1 04:A077 A2 01 ldx #low(1) 04:A079 A9 00 lda #high(1) 220 04:A07B 8E FA 20 stx __bl 221 __ldwi 3 04:A07E A2 03 ldx #low(3) 04:A080 A9 00 lda #high(3) 222 04:A082 20 23 EF call _put_string.3 223 ; ctrl = (ctrl & 0x80); 224 __ldub _ctrl 0000 .if (1 = 2) .else 04:A085 AE 93 29 ldx _ctrl 04:A088 62 cla .endif 225 __andwi 128 04:A089 22 sax 04:A08A 29 80 and #low(128) 04:A08C 22 sax 04:A08D 29 00 and #high(128) 226 04:A08F 8E 93 29 stx _ctrl 227 ; } else { 228 __lbra LL5 04:A092 4C C0 A0 jmp LL5 229 04:A095 LL4: 230 231 ; put_string(" ", 1, STATUS_LINE); 232 __ldwi LL0+2 04:A095 A2 02 ldx #low(LL0+2) 04:A097 A9 40 lda #high(LL0+2) 233 __stw __si 04:A099 8E EE 20 stx __si 04:A09C 8D EF 20 sta __si+1 234 __ldwi 1 04:A09F A2 01 ldx #low(1) 04:A0A1 A9 00 lda #high(1) 235 04:A0A3 8E FA 20 stx __bl 236 __ldwi 3 04:A0A6 A2 03 ldx #low(3) 04:A0A8 A9 00 lda #high(3) 237 04:A0AA 20 23 EF call _put_string.3 238 ; ctrl = (ctrl & 0x80) | 0x1f; 239 __ldub _ctrl 0000 .if (1 = 2) .else 04:A0AD AE 93 29 ldx _ctrl 04:A0B0 62 cla .endif 240 __andwi 128 04:A0B1 22 sax 04:A0B2 29 80 and #low(128) 04:A0B4 22 sax 04:A0B5 29 00 and #high(128) 241 __orwi 31 04:A0B7 22 sax 04:A0B8 09 1F ora #low(31) 04:A0BA 22 sax 04:A0BB 09 00 ora #high(31) 242 04:A0BD 8E 93 29 stx _ctrl 243 ; } 244 04:A0C0 LL5: 245 246 ; if (a & JOY_SEL) { 247 __ldub _a 0000 .if (1 = 2) .else 04:A0C0 AE 94 29 ldx _a 04:A0C3 62 cla .endif 248 __andwi 4 04:A0C4 22 sax 04:A0C5 29 04 and #low(4) 04:A0C7 22 sax 04:A0C8 29 00 and #high(4) 249 __tstw ; pha 04:A0CA 86 02 stx <__temp 04:A0CC 05 02 ora <__temp 04:A0CE 62 cla 04:A0CF 82 clx 04:A0D0 F0 01 beq .x_00572 04:A0D2 E8 inx 04:A0D3 .x_00572: ; pla 250 __lbeq LL6 04:A0D3 E0 00 cpx #0 04:A0D5 D0 03 bne .x00573 04:A0D7 4C 02 A1 jmp LL6 04:A0DA .x00573 251 ; put_string("S", 2, STATUS_LINE); 252 __ldwi LL0+4 04:A0DA A2 04 ldx #low(LL0+4) 04:A0DC A9 40 lda #high(LL0+4) 253 __stw __si 04:A0DE 8E EE 20 stx __si 04:A0E1 8D EF 20 sta __si+1 254 __ldwi 2 04:A0E4 A2 02 ldx #low(2) 04:A0E6 A9 00 lda #high(2) 255 04:A0E8 8E FA 20 stx __bl 256 __ldwi 3 04:A0EB A2 03 ldx #low(3) 04:A0ED A9 00 lda #high(3) 257 04:A0EF 20 23 EF call _put_string.3 258 ; ctrl = (ctrl & 0x1f); 259 __ldub _ctrl 0000 .if (1 = 2) .else 04:A0F2 AE 93 29 ldx _ctrl 04:A0F5 62 cla .endif 260 __andwi 31 04:A0F6 22 sax 04:A0F7 29 1F and #low(31) 04:A0F9 22 sax 04:A0FA 29 00 and #high(31) 261 04:A0FC 8E 93 29 stx _ctrl 262 ; } else { 263 __lbra LL7 04:A0FF 4C 2D A1 jmp LL7 264 04:A102 LL6: 265 266 ; put_string(" ", 2, STATUS_LINE); 267 __ldwi LL0+6 04:A102 A2 06 ldx #low(LL0+6) 04:A104 A9 40 lda #high(LL0+6) 268 __stw __si 04:A106 8E EE 20 stx __si 04:A109 8D EF 20 sta __si+1 269 __ldwi 2 04:A10C A2 02 ldx #low(2) 04:A10E A9 00 lda #high(2) 270 04:A110 8E FA 20 stx __bl 271 __ldwi 3 04:A113 A2 03 ldx #low(3) 04:A115 A9 00 lda #high(3) 272 04:A117 20 23 EF call _put_string.3 273 ; ctrl = (ctrl & 0x1f) | 0x80; 274 __ldub _ctrl 0000 .if (1 = 2) .else 04:A11A AE 93 29 ldx _ctrl 04:A11D 62 cla .endif 275 __andwi 31 04:A11E 22 sax 04:A11F 29 1F and #low(31) 04:A121 22 sax 04:A122 29 00 and #high(31) 276 __orwi 128 04:A124 22 sax 04:A125 09 80 ora #low(128) 04:A127 22 sax 04:A128 09 00 ora #high(128) 277 04:A12A 8E 93 29 stx _ctrl 278 ; } 279 04:A12D LL7: 280 281 ; if (a & JOY_II) { 282 __ldub _a 0000 .if (1 = 2) .else 04:A12D AE 94 29 ldx _a 04:A130 62 cla .endif 283 __andwi 2 04:A131 22 sax 04:A132 29 02 and #low(2) 04:A134 22 sax 04:A135 29 00 and #high(2) 284 __tstw ; pha 04:A137 86 02 stx <__temp 04:A139 05 02 ora <__temp 04:A13B 62 cla 04:A13C 82 clx 04:A13D F0 01 beq .x_00590 04:A13F E8 inx 04:A140 .x_00590: ; pla 285 __lbeq LL8 04:A140 E0 00 cpx #0 04:A142 D0 03 bne .x00591 04:A144 4C 69 A1 jmp LL8 04:A147 .x00591 286 ; put_string("2", 3, STATUS_LINE); 287 __ldwi LL0+8 04:A147 A2 08 ldx #low(LL0+8) 04:A149 A9 40 lda #high(LL0+8) 288 __stw __si 04:A14B 8E EE 20 stx __si 04:A14E 8D EF 20 sta __si+1 289 __ldwi 3 04:A151 A2 03 ldx #low(3) 04:A153 A9 00 lda #high(3) 290 04:A155 8E FA 20 stx __bl 291 __ldwi 3 04:A158 A2 03 ldx #low(3) 04:A15A A9 00 lda #high(3) 292 04:A15C 20 23 EF call _put_string.3 293 ; glb_bal = 0; 294 __ldwi 0 04:A15F A2 00 ldx #low(0) 04:A161 A9 00 lda #high(0) 295 04:A163 8E 91 29 stx _glb_bal 296 ; } else { 297 __lbra LL9 04:A166 4C 88 A1 jmp LL9 298 04:A169 LL8: 299 300 ; put_string(" ", 3, STATUS_LINE); 301 __ldwi LL0+10 04:A169 A2 0A ldx #low(LL0+10) 04:A16B A9 40 lda #high(LL0+10) 302 __stw __si 04:A16D 8E EE 20 stx __si 04:A170 8D EF 20 sta __si+1 303 __ldwi 3 04:A173 A2 03 ldx #low(3) 04:A175 A9 00 lda #high(3) 304 04:A177 8E FA 20 stx __bl 305 __ldwi 3 04:A17A A2 03 ldx #low(3) 04:A17C A9 00 lda #high(3) 306 04:A17E 20 23 EF call _put_string.3 307 ; glb_bal = 255; 308 __ldwi 255 04:A181 A2 FF ldx #low(255) 04:A183 A9 00 lda #high(255) 309 04:A185 8E 91 29 stx _glb_bal 310 ; } 311 04:A188 LL9: 312 313 ; if (a & JOY_I) { 314 __ldub _a 0000 .if (1 = 2) .else 04:A188 AE 94 29 ldx _a 04:A18B 62 cla .endif 315 __andwi 1 04:A18C 22 sax 04:A18D 29 01 and #low(1) 04:A18F 22 sax 04:A190 29 00 and #high(1) 316 __tstw ; pha 04:A192 86 02 stx <__temp 04:A194 05 02 ora <__temp 04:A196 62 cla 04:A197 82 clx 04:A198 F0 01 beq .x_00605 04:A19A E8 inx 04:A19B .x_00605: ; pla 317 __lbeq LL10 04:A19B E0 00 cpx #0 04:A19D D0 03 bne .x00606 04:A19F 4C C4 A1 jmp LL10 04:A1A2 .x00606 318 ; put_string("1", 4, STATUS_LINE); 319 __ldwi LL0+12 04:A1A2 A2 0C ldx #low(LL0+12) 04:A1A4 A9 40 lda #high(LL0+12) 320 __stw __si 04:A1A6 8E EE 20 stx __si 04:A1A9 8D EF 20 sta __si+1 321 __ldwi 4 04:A1AC A2 04 ldx #low(4) 04:A1AE A9 00 lda #high(4) 322 04:A1B0 8E FA 20 stx __bl 323 __ldwi 3 04:A1B3 A2 03 ldx #low(3) 04:A1B5 A9 00 lda #high(3) 324 04:A1B7 20 23 EF call _put_string.3 325 ; chn_bal = 0; 326 __ldwi 0 04:A1BA A2 00 ldx #low(0) 04:A1BC A9 00 lda #high(0) 327 04:A1BE 8E 92 29 stx _chn_bal 328 ; } else { 329 __lbra LL11 04:A1C1 4C E3 A1 jmp LL11 330 04:A1C4 LL10: 331 332 ; put_string(" ", 4, STATUS_LINE); 333 __ldwi LL0+14 04:A1C4 A2 0E ldx #low(LL0+14) 04:A1C6 A9 40 lda #high(LL0+14) 334 __stw __si 04:A1C8 8E EE 20 stx __si 04:A1CB 8D EF 20 sta __si+1 335 __ldwi 4 04:A1CE A2 04 ldx #low(4) 04:A1D0 A9 00 lda #high(4) 336 04:A1D2 8E FA 20 stx __bl 337 __ldwi 3 04:A1D5 A2 03 ldx #low(3) 04:A1D7 A9 00 lda #high(3) 338 04:A1D9 20 23 EF call _put_string.3 339 ; chn_bal = 255; 340 __ldwi 255 04:A1DC A2 FF ldx #low(255) 04:A1DE A9 00 lda #high(255) 341 04:A1E0 8E 92 29 stx _chn_bal 342 ; } 343 04:A1E3 LL11: 344 345 ;#asm 346 04:A1E3 AD 91 29 lda _glb_bal 347 04:A1E6 8D 01 08 sta psg_mainvol 348 04:A1E9 AD 92 29 lda _chn_bal 349 04:A1EC 8D 05 08 sta psg_pan 350 04:A1EF AD 93 29 lda _ctrl 351 04:A1F2 8D 04 08 sta psg_ctrl 352 ; } 353 __lbra LL2 04:A1F5 4C 2E A0 jmp LL2 354 04:A1F8 LL3: 355 356 ; return; 357 __lbra LL1 04:A1F8 4C FB A1 jmp LL1 358 ;} 359 04:A1FB LL1: 360 361 04:A1FB 60 rts 362 .endp 363 364 60C8 .data 365 0002 .bank CONST_BANK 366 02:4000 LL0: 367 02:4000 44 00 20 .db 68,0,32,0,83,0,32,0 02:4003 00 53 00 02:4006 20 00 368 02:4008 32 00 20 .db 50,0,32,0,49,0,32,0 02:400B 00 31 00 02:400E 20 00 369 370 2991 .bss 371 --:2991 _glb_bal: .ds 1 372 --:2992 _chn_bal: .ds 1 373 --:2993 _ctrl: .ds 1 374 --:2994 _a: .ds 1 375 376 377 ;0 error(s) in compilation 378 ; literal pool:16 379 ; constant pool:0 380 ; global pool:31 381 ; Macro pool:81 382 --:2995 huc_rodata: 383 --:2995 __huc_rodata: 384 --:2995 huc_rodata_end: 385 --:2995 __huc_rodata_end: 386 --:2995 huc_data: 387 --:2995 __huc_data: 388 --:2995 huc_data_end: 389 --:2995 __huc_data_end: 390 --:2995 __heap_start: