uxn-client/xrxs.tal (raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 |
( utility macros ) %INC-X { .Screen/x DEI2 #0008 ADD2 .Screen/x DEO2 } ( -- ) %INC-Y { .Screen/y DEI2 #0008 ADD2 .Screen/y DEO2 } ( -- ) %CENTER-X { .Screen/width DEI2 #01 SFT2 } %CENTER-Y { .Screen/height DEI2 #01 SFT2 } %MOD { DIVk MUL SUB } %MOD2 { DIV2k MUL2 SUB2 } %2** { #10 SFT2 } %2// { #01 SFT2 } %8** { #30 SFT2 } %8// { #03 SFT2 } %TOS { #00 SWP } %TOB { SWP POP } %NEXT-TILE { DUP2 #0010 ADD2 } %GET-USABLE-HEIGHT { .Screen/height DEI2 #0050 SUB2 #03 SFT2 SWP POP } %RTN { JMP2r } ( devices ) |00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 ] |10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ] |20 @Screen [ &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] |30 @Audio0 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] |40 @Audio1 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] |50 @Audio2 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] |60 @Audio3 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] |80 @Controller [ &vector $2 &button $1 &key $1 ] |90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ] |a0 @File [ &vector $2 &success $2 &offset-hs $2 &offset-ls $2 &name $2 &length $2 &load $2 &save $2 ] |b0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ] ( variables ) |0000 @state $1 @ticker $1 @anim-speed $1 @logo-coords [ &x $2 &y $2 ] @list-len $2 @list-offset $1 @list-elem-offset $1 @list-top $1 @list-height $1 @select-index $1 @ncarts $1 @btn-state $1 @sb-len $1 @sb-pos $1 @sb-step $1 @cart-len $1 ( program ) |0100 @init ( -> ) ( steppewnolf-dark theme ) #02c1 .System/r DEO2 #02cd .System/g DEO2 #02cb .System/b DEO2 #0200 .Screen/width DEO2 #0110 .Screen/height DEO2 ( initialize state ) #00 .ticker STZ #00 .state STZ #00 .select-index STZ #20 .anim-speed STZ #ff .btn-state STZ GET-USABLE-HEIGHT .list-height STZ ;carts-file .File/name DEO2 #2000 .File/length DEO2 ;list-buf .File/load DEO2 .File/success DEI2 .list-len STZ2 CENTER-X .logo-coords/x STZ2 CENTER-Y .logo-coords/y STZ2 ;on-frame .Screen/vector DEO2 BRK @on-frame ( -> ) .ticker LDZ #01 ADD DUP .anim-speed LDZ EQU ,&next-render JCN .ticker STZ BRK &next-render POP #00 .ticker STZ .state LDZ ( draw uxn logo ) DUP #00 NEQ ,&state1 JCN ;draw-uxn-logo JSR2 INC .state STZ BRK ( draw first syllable of xrxs logo ) &state1 DUP #01 NEQ ,&state2 JCN ;draw-xrxs-logo-xr JSR2 INC .state STZ BRK ( draw second syllable of xrxs logo ) &state2 DUP #02 NEQ ,&state3 JCN ;draw-xrxs-logo-xs JSR2 INC .state STZ BRK ( clear screen ) &state3 ;clear-screen JSR2 ( move shove logo into top-left corner ) DUP #03 NEQ ,&state4 JCN #04 .anim-speed STZ ;scoot-logos JSR2 ;draw-uxn-logo JSR2 ;draw-xrxs-logo-xr JSR2 ;draw-xrxs-logo-xs JSR2 .logo-coords/x LDZ2 #0020 GTH2 ,&keep-state JCN INC .state STZ ;get-select-idx-by-mouse .Mouse/vector DEO2 ;get-select-idx-by-key .Controller/vector DEO2 BRK &keep-state POP BRK ( render the cartridge list interface ) &state4 DUP #04 NEQ ,&state5 JCN ;draw-gray-borders JSR2 ;draw-bl-scanlines JSR2 ;draw-tl-scanlines JSR2 ;draw-tr-scanlines JSR2 ;draw-br-scanlines JSR2 ;draw-uxn-logo JSR2 ;draw-xrxs-logo-xr JSR2 ;draw-xrxs-logo-xs JSR2 [ ;title-loadCart CENTER-X OVR2 ;strlen JSR2 #20 SFT2 SUB2 #0010 #02 ] ;draw-string JSR2 ;render-cart-list JSR2 ;draw-scrollbar JSR2 ;draw-pointer JSR2 POP BRK ( confirm the selected cartridge ) &state5 DUP #05 NEQ ,&state6 JCN ;draw-gray-borders JSR2 ;draw-bl-scanlines JSR2 ;draw-tl-scanlines JSR2 ;draw-tr-scanlines JSR2 ;draw-br-scanlines JSR2 ;draw-uxn-logo JSR2 ;draw-xrxs-logo-xr JSR2 ;draw-xrxs-logo-xs JSR2 [ ;title-confirmCart CENTER-X OVR2 ;strlen JSR2 #20 SFT2 SUB2 #0010 #02 ] ;draw-string JSR2 ;render-cart-list JSR2 ;draw-scrollbar JSR2 ;draw-confirm-buttons JSR2 ;draw-pointer JSR2 POP BRK &state6 [ ;load-cmd CENTER-X OVR2 ;strlen JSR2 #20 SFT2 SUB2 CENTER-Y #0004 SUB #02 ] ;draw-string JSR2 POP BRK @clear-screen ( -> ) .Screen/width DEI2 #0000 &whilex EQU2k ,&endx JCN DUP2 ,&x STR2 .Screen/height DEI2 #0000 &whiley EQU2k ,&endy JCN DUP2 ,&y STR2 ,&x LDR2 .Screen/x DEO2 ,&y LDR2 .Screen/y DEO2 ;blank .Screen/addr DEO2 #10 .Screen/sprite DEO #40 .Screen/sprite DEO #0008 ADD2 ,&whiley JMP &endy POP2 POP2 #0008 ADD2 ,&whilex JMP &endx POP2 POP2 RTN &x $2 &y $2 @scoot-logos ( -> ) .logo-coords/x LDZ2 #0021 LTH2 ,&no-scoot-x JCN .logo-coords/x LDZ2 #01 SFT2 .logo-coords/x STZ2 &no-scoot-x .logo-coords/y LDZ2 #0021 LTH2 ,&no-scoot-y JCN .logo-coords/y LDZ2 #01 SFT2 .logo-coords/y STZ2 &no-scoot-y RTN @draw-uxn-logo ( -> ) .logo-coords/x LDZ2 #0020 SUB2 .Screen/x DEO2 .logo-coords/y LDZ2 #0010 SUB2 .Screen/y DEO2 #0100 #0000 &while EQU2k ,&end JCN DUP2 ;uxn-logo ADD2 .Screen/addr DEO2 #c1 .Screen/sprite DEO INC-X NEXT-TILE #0030 AND2 #0000 NEQ2 ,&no-inc-y JCN .logo-coords/x LDZ2 #0020 SUB2 .Screen/x DEO2 INC-Y &no-inc-y #0010 ADD2 ,&while JMP &end POP2 POP2 RTN @draw-xrxs-logo-xr ( -> ) .logo-coords/x LDZ2 .Screen/x DEO2 .logo-coords/y LDZ2 #0010 SUB2 .Screen/y DEO2 #0080 #0000 &while EQU2k ,&end JCN DUP2 ;xrxs-logo ADD2 .Screen/addr DEO2 #c1 .Screen/sprite DEO INC-X NEXT-TILE #0030 AND2 #0000 NEQ2 ,&no-inc-y JCN .logo-coords/x LDZ2 .Screen/x DEO2 INC-Y &no-inc-y #0010 ADD2 ,&while JMP &end POP2 POP2 RTN @draw-xrxs-logo-xs ( -> ) .logo-coords/x LDZ2 .Screen/x DEO2 .logo-coords/y LDZ2 .Screen/y DEO2 #0100 #0080 &while EQU2k ,&end JCN DUP2 ;xrxs-logo ADD2 .Screen/addr DEO2 #c1 .Screen/sprite DEO INC-X NEXT-TILE #0030 AND2 #0000 NEQ2 ,&no-inc-y JCN .logo-coords/x LDZ2 .Screen/x DEO2 INC-Y &no-inc-y #0010 ADD2 ,&while JMP &end POP2 POP2 RTN @draw-gray-borders ( -> ) ;blank .Screen/addr DEO2 #0028 #0000 &whilemtop EQU2k ,&endmtop JCN DUP2 .Screen/y DEO2 .Screen/width DEI2 #0000 &whiletop EQU2k ,&endtop JCN DUP2 .Screen/x DEO2 #84 .Screen/sprite DEO #0008 ADD2 ,&whiletop JMP &endtop POP2 POP2 #0008 ADD2 ,&whilemtop JMP &endmtop POP2 POP2 #0040 #0000 &whilemleft EQU2k ,&endmleft JCN DUP2 .Screen/x DEO2 .Screen/height DEI2 #0028 SUB2 #0028 &whileleft EQU2k ,&endleft JCN DUP2 .Screen/y DEO2 #84 .Screen/sprite DEO #0008 ADD2 ,&whileleft JMP &endleft POP2 POP2 #0008 ADD2 ,&whilemleft JMP &endmleft POP2 POP2 .Screen/width DEI2 DUP2 #0040 SUB2 &whilemright EQU2k ,&endmright JCN DUP2 .Screen/x DEO2 .Screen/height DEI2 #0028 SUB2 #0028 &whileright EQU2k ,&endright JCN DUP2 .Screen/y DEO2 #84 .Screen/sprite DEO #0008 ADD2 ,&whileright JMP &endright POP2 POP2 #0008 ADD2 ,&whilemright JMP &endmright POP2 POP2 .Screen/height DEI2 DUP2 #0028 SUB2 &whilembottom EQU2k ,&endmbottom JCN DUP2 .Screen/y DEO2 .Screen/width DEI2 #0000 &whilebottom EQU2k ,&endbottom JCN DUP2 .Screen/x DEO2 #84 .Screen/sprite DEO #0008 ADD2 ,&whilebottom JMP &endbottom POP2 POP2 #0008 ADD2 ,&whilembottom JMP &endmbottom POP2 POP2 RTN ( come up with a more elegant way to draw these ) @draw-bl-scanlines ( -> ) CENTER-Y ,&y STR2 #0008 ,&x STR2 &whileld ,&y LDR2 CENTER-Y SUB2 #04 SFT2 DUP2 ADD2 #0008 ADD2 ,&x STR2 .Screen/height DEI2 #0028 SUB2 ,&y LDR2 LTH2 ,&endld JCN &dlscan #0040 ,&x LDR2 EQU2 ,&enddlscan JCN ,&x LDR2 .Screen/x DEO2 ,&y LDR2 .Screen/y DEO2 #03 .Screen/pixel DEO ,&x LDR2 #0001 ADD2 ,&x STR2 ,&dlscan JMP &enddlscan ,&y LDR2 #0004 ADD2 ,&y STR2 ,&whileld JMP &endld RTN &x $2 &y $2 @draw-tl-scanlines #0028 ,&y STR2 #0008 ,&x STR2 &whilelu CENTER-Y ,&y LDR2 SUB2 #04 SFT2 DUP2 ADD2 #0008 ADD2 ,&x STR2 CENTER-Y ,&y LDR2 LTH2 ,&endlu JCN &ulscan #0040 ,&x LDR2 EQU2 ,&endulscan JCN ,&x LDR2 .Screen/x DEO2 ,&y LDR2 .Screen/y DEO2 #03 .Screen/pixel DEO ,&x LDR2 #0001 ADD2 ,&x STR2 ,&ulscan JMP &endulscan ,&y LDR2 #0004 ADD2 ,&y STR2 ,&whilelu JMP &endlu RTN &x $2 &y $2 @draw-br-scanlines ( -> ) CENTER-Y ,&y STR2 .Screen/width DEI2 #0008 SUB2 ,&x STR2 &whilerd .Screen/width DEI2 #0040 SUB2 ,&x STR2 .Screen/height DEI2 #0028 SUB2 ,&y LDR2 LTH2 ,&endrd JCN &drscan .Screen/width DEI2 #0008 SUB2 ,&y LDR2 CENTER-Y SUB2 #04 SFT2 DUP2 ADD2 SUB2 ,&x LDR2 EQU2 ,&enddrscan JCN ,&x LDR2 .Screen/x DEO2 ,&y LDR2 .Screen/y DEO2 #03 .Screen/pixel DEO ,&x LDR2 #0001 ADD2 ,&x STR2 ,&drscan JMP &enddrscan ,&y LDR2 #0004 ADD2 ,&y STR2 ,&whilerd JMP &endrd RTN &x $2 &y $2 @draw-tr-scanlines #0028 ,&y STR2 .Screen/width DEI2 #0008 SUB2 ,&x STR2 &whileru .Screen/width DEI2 #0040 SUB2 ,&x STR2 CENTER-Y ,&y LDR2 LTH2 ,&endru JCN &urscan .Screen/width DEI2 #0008 SUB2 CENTER-Y ,&y LDR2 SUB2 #04 SFT2 DUP2 ADD2 SUB2 ,&x LDR2 EQU2 ,&endurscan JCN ,&x LDR2 .Screen/x DEO2 ,&y LDR2 .Screen/y DEO2 #03 .Screen/pixel DEO ,&x LDR2 #0001 ADD2 ,&x STR2 ,&urscan JMP &endurscan ,&y LDR2 #0004 ADD2 ,&y STR2 ,&whileru JMP &endru RTN &x $2 &y $2 @draw-pointer ( -> ) ;cursor .Screen/addr DEO2 .Mouse/x DEI2 .Screen/x DEO2 .Mouse/y DEI2 .Screen/y DEO2 #4a .Screen/sprite DEO RTN @draw-string ( addr x y color -- ) STH ( save color ) .Screen/y DEO2 ( set y ) .Screen/x DEO2 ( set x ) ( now the string address is at the top of the stack ) &loop LDAk DUP #00 NEQ #20 MUL SUB TOS 8** ;font ADD2 .Screen/addr DEO2 STHkr .Screen/sprite DEO INC-X INC2 LDAk #00 NEQ ,&loop JCN POP2 POPr RTN @strlen ( addr -- len ) DUP2 &loop INC2 LDAk ,&loop JCN SWP2 SUB2 RTN @store-char ( char -- char ) #00 .list-elem-offset LDZ ;word ADD2 STA .list-elem-offset LDZ INC .list-elem-offset STZ RTN @shouldnt-draw-word ( -- flag ) .list-offset LDZ .list-top LDZ LTH ,&no JCN .list-offset LDZ .list-top LDZ .list-height LDZ ADD #01 SUB GTH ,&no JCN #00 RTN &no #01 RTN @finish-line ( -> ) ;get-entry-color JSR2 #02 EQU ,&end JCN &while .Screen/x DEI2 .Screen/width DEI2 #0048 SUB2 EQU2 ,&end JCN #0c .Screen/sprite DEO INC-X ,&while JMP &end RTN @draw-cart-name ( -> ) ;get-entry-color JSR2 #0c NEQ ,&no-store-cart JCN ;store-cart JSR2 &no-store-cart [ ;word .Screen/x DEI2 .Screen/y DEI2 ;get-entry-color JSR2 ] ;draw-string JSR2 ;finish-line JSR2 RTN @render-cart-list ( -> ) #0040 .Screen/x DEO2 #0028 .Screen/y DEO2 #00 .list-offset STZ .list-len LDZ2 #0000 &while EQU2k ,&end JCN ( get a character from the list ) DUP2 ;list-buf ADD2 LDA ( if null byte, terminate loop ) DUP #00 EQU ,&end JCN ( if not newline, store the character and increment the offsets ) DUP #0a EQU ,&inc-line JCN ;store-char JSR2 ,&continue JMP ( continue looping ) ( if newline, print the word, increment x, reset y ) ( clear the word and word offsets, increment the buffer offset ) &inc-line #00 .list-elem-offset LDZ ;word ADD2 STA ( if the word isn't in the scroll window, don't draw it ) ;shouldnt-draw-word JSR2 ,&no-draw JCN ;draw-cart-name JSR2 #0040 .Screen/x DEO2 INC-Y &no-draw .list-offset LDZ INC .list-offset STZ #20 #00 &word_clr EQUk ,&end-clr JCN #00 OVR SWP DUP ROT ;word ADD2 STA INC ,&word_clr JMP &end-clr POP2 #00 .list-elem-offset STZ &continue INC2 ,&while JMP &end .list-offset LDZ #01 SUB .ncarts STZ POP2 POP2 RTN @store-cart ( -> ) #20 #00 &while EQUk ,&end JCN DUP TOS ;word ADD2 LDA SWP DUP TOS ;cart ADD2 ROT STH STA STHr INC ,&while JMP &end POP2 RTN RTN @get-entry-color ( -- colorByte ) .list-offset LDZ .select-index LDZ NEQ ,&normal JCN ( selected ) #0c RTN &normal #02 RTN @draw-scrollbar ( -> ) .Screen/width DEI2 #0048 SUB2 .Screen/x DEO2 #0028 .Screen/y DEO2 ( draw the trough no matter what ) ;scrollbar-trough .Screen/addr DEO2 .list-height LDZ #00 &while-trough EQUk ,&end-trough JCN #81 .Screen/sprite DEO INC-Y INC ,&while-trough JMP &end-trough POP2 ( stop here if there is no overflow ) .ncarts LDZ .list-height LDZ LTH ,&no-handle JCN ,&draw-handle JMP &no-handle RTN ( if there are more carts than will fit in the view area, draw the handle ) &draw-handle #0028 .Screen/y DEO2 ( store the number of carts per tile of the scrollbar ) .ncarts LDZ .list-height LDZ DIV .sb-step STZ ( set the length of the scrollbar ) .list-height LDZ .ncarts LDZ .list-height LDZ SUB .sb-step LDZ DIV SUB .sb-len STZ ;scrollbar .Screen/addr DEO2 #0028 .sb-pos LDZ #30 SFT TOS ADD2 .Screen/y DEO2 .sb-len LDZ #00 &while-handle EQUk ,&end-handle JCN .Screen/y DEI2 .Screen/height DEI2 #0028 SUB2 EQU2 ,&end-handle JCN #81 .Screen/sprite DEO INC INC-Y ,&while-handle JMP &end-handle POP2 RTN @get-select-idx-by-mouse ( -> ) .Mouse/wheel DEI #00 EQU ,&no-scroll JCN .Mouse/wheel DEI #01 NEQ ,&scroll-down JCN ( scroll-up ) ;try-scroll-up-mouse JSR2 ,&no-scroll JMP &scroll-down ;try-scroll-down-mouse JSR2 &no-scroll .Mouse/x DEI2 #0040 LTH2 ,&done JCN .Mouse/x DEI2 .Screen/width DEI2 #0048 SUB2 GTH2 ,&done JCN .Mouse/y DEI2 #0028 LTH2 ,&done JCN .Mouse/y DEI2 .Screen/height DEI2 #0028 SUB2 GTH2 ,&done JCN .Mouse/y DEI2 #0028 SUB2 8// TOB .list-top LDZ ADD .select-index STZ .Mouse/state DEI #00 EQU ,&no-click JCN .select-index LDZ .ncarts LDZ GTH ,&no-click JCN .state LDZ INC .state STZ ;set-button-state-by-key .Controller/vector DEO2 ;set-button-state-by-mouse .Mouse/vector DEO2 &no-click BRK &done #ff .select-index STZ BRK @try-scroll-up-mouse ( -> ) .ncarts LDZ .list-height LDZ LTH ,&no-scroll-up JCN .list-top LDZ #00 EQU ,&no-scroll-up JCN .list-top LDZ #01 SUB .list-top STZ ;update-sb-pos JSR2 &no-scroll-up RTN @try-scroll-down-mouse ( -> ) .ncarts LDZ .list-height LDZ LTH ,&no-scroll-down JCN .list-top LDZ .list-height LDZ ADD .ncarts LDZ #01 ADD EQU ,&no-scroll-down JCN .list-top LDZ INC .list-top STZ ;update-sb-pos JSR2 &no-scroll-down RTN @try-scroll-up ( -> ) .select-index LDZ DUP .list-top LDZ NEQ ,&no-scroll-up JCN .list-top LDZ #00 EQU ,&no-scroll-up JCN .list-top LDZ #01 SUB .list-top STZ ;update-sb-pos JSR2 &no-scroll-up RTN @try-scroll-down ( -> ) .select-index LDZ DUP .list-top LDZ .list-height LDZ ADD #01 SUB NEQ ,&no-scroll-down JCN .list-top LDZ .list-height LDZ ADD .ncarts LDZ #01 ADD EQU ,&no-scroll-down JCN .list-top LDZ INC .list-top STZ ;update-sb-pos JSR2 &no-scroll-down RTN @update-sb-pos ( -> ) .list-top LDZ .sb-step LDZ DIV .sb-pos STZ RTN @get-select-idx-by-key ( -> ) .Controller/button DEI DUP #10 NEQ ,&no-up JCN ;try-scroll-up JSR2 DUP #00 EQU ,&no-dec JCN #01 SUB .select-index STZ ,&no-up JMP &no-dec POP &no-up DUP #20 NEQ ,&no-down JCN ;try-scroll-down JSR2 DUP .ncarts LDZ EQU ,&no-inc JCN INC .select-index STZ ,&no-down JMP &no-inc POP &no-down DUP #01 NEQ ,&no-a-btn JCN .state LDZ INC .state STZ #00 .btn-state STZ ;set-button-state-by-key .Controller/vector DEO2 ;set-button-state-by-mouse .Mouse/vector DEO2 &no-a-btn POP BRK @set-button-state-by-key ( -> ) .Controller/button DEI #00 NEQ ,&action JCN BRK &action .btn-state LDZ #ff EQU ,&from-null JCN .btn-state LDZ #00 EQU ,&from-no JCN ( from yes ) .Controller/button DEI #10 MOD #00 NEQ ,&check-action JCN #00 .btn-state STZ BRK &from-no .Controller/button DEI #10 MOD #00 NEQ ,&check-action JCN #01 .btn-state STZ BRK &from-null .Controller/button DEI #10 MOD #00 NEQ ,&check-action JCN #00 .btn-state STZ BRK &check-action .Controller/button DEI #00 EQU ,&no-action JCN ( check A button ) .Controller/button DEI #01 NEQ ,&check-b-button JCN ( A on yes ) .btn-state LDZ #01 NEQ ,&a-on-no JCN ;capture-input JSR2 ;load-cart JSR2 BRK &a-on-no .btn-state LDZ #00 NEQ ,&no-action JCN ;get-select-idx-by-mouse .Mouse/vector DEO2 ;get-select-idx-by-key .Controller/vector DEO2 #04 .state STZ BRK &check-b-button .Controller/button DEI #02 NEQ ,&no-action JCN ;get-select-idx-by-mouse .Mouse/vector DEO2 ;get-select-idx-by-key .Controller/vector DEO2 #04 .state STZ &no-action BRK @set-button-state-by-mouse ( -> ) ( if not in the vertical range of the buttons, quit early ) .Mouse/y DEI2 .Screen/height DEI2 #001c SUB2 LTH2 ,¬-no JCN .Mouse/y DEI2 .Screen/height DEI2 #000c SUB2 GTH2 ,¬-no JCN .Mouse/x DEI2 CENTER-X #0030 SUB2 LTH2 ,¬-yes JCN .Mouse/x DEI2 CENTER-X GTH2 ,¬-yes JCN #01 .btn-state STZ ,&check-click JMP ¬-yes .Mouse/x DEI2 CENTER-X LTH2 ,¬-no JCN .Mouse/x DEI2 CENTER-X #0030 ADD2 GTH2 ,¬-no JCN #00 .btn-state STZ ,&check-click JMP ¬-no #ff .btn-state STZ BRK &check-click .Mouse/state DEI #00 EQU ,&no-click JCN .btn-state LDZ #00 NEQ ,&state-load JCN ;get-select-idx-by-mouse .Mouse/vector DEO2 ;get-select-idx-by-key .Controller/vector DEO2 #04 .state STZ BRK &state-load ;capture-input JSR2 ;load-cart JSR2 &no-click BRK @button-color ( bit -- sprite ) ,&get-color-yes JCN ( get color no ) .btn-state LDZ #ff EQU ,&no-inactive JCN .btn-state LDZ #01 EQU ,&no-inactive JCN ( active ) ;no-btn-active RTN &no-inactive ;no-btn RTN &get-color-yes .btn-state LDZ #ff EQU ,&yes-inactive JCN .btn-state LDZ #00 EQU ,&yes-inactive JCN ( active ) ;yes-btn-active RTN &yes-inactive ;yes-btn RTN @draw-confirm-buttons ( -> ) ( yes ) .Screen/height DEI2 #001c SUB2 .Screen/y DEO2 CENTER-X #0030 SUB2 .Screen/x DEO2 #00c0 #0000 &while-yes EQU2k ,&end-yes JCN DUP2 [ #01 ;button-color JSR2 ] ADD2 .Screen/addr DEO2 #81 .Screen/sprite DEO INC-X NEXT-TILE #0060 NEQ2 ,&no-inc-y JCN CENTER-X #0030 SUB2 .Screen/x DEO2 INC-Y &no-inc-y #0010 ADD2 ,&while-yes JMP &end-yes POP2 POP2 ( no ) .Screen/height DEI2 #001c SUB2 .Screen/y DEO2 CENTER-X .Screen/x DEO2 #00c0 #0000 &while-no EQU2k ,&end-no JCN DUP2 [ #00 ;button-color JSR2 ] ADD2 .Screen/addr DEO2 #81 .Screen/sprite DEO INC-X NEXT-TILE #0060 NEQ2 ,&no-inc-y-no JCN CENTER-X .Screen/x DEO2 INC-Y &no-inc-y-no #0010 ADD2 ,&while-no JMP &end-no POP2 POP2 RTN @load-cart ( -> ) .state LDZ INC .state STZ ( send it! ) #0020 .File/length DEO2 #0001 .File/offset-ls DEO2 ;ctl-file .File/name DEO2 ;load-cmd .File/save DEO2 ;slot-file ;load-rom JSR2 RTN @load-rom ( filename* -- ) ( Attempts to load the ROM from filename* and executes it. If the file exists and has non-zero length, this function does not return, because the new ROM is executing in its place. The screen and both stacks are cleared and all the device vectors are written to zero as a convenience. All other device bytes are left untouched, so they could introduce a device state to the next ROM that it's not expecting. ) .File/name DEO2 #0000 .File/offset-hs DEO2 #0000 .File/offset-ls DEO2 ( return if file can't be found, or zero length ) #0001 .File/length DEO2 ;&tmp .File/load DEO2 .File/success DEI2 ORA JMP JMP2r ( clear wst ) #ab &wst-loop POP .System/wst STH DEIr STHr ,&wst-loop JCN ( clear rst ) LITr ab &rst-loop POPr .System/rst DEI ,&rst-loop JCN ( clear screen ) #01 .Screen/auto DEO #0000 .Screen/y DEO2 .Screen/width DEI2 #0007 ADD2 #03 SFT2 #ffff MUL2 STH2 &screen-yloop #0000 .Screen/x DEO2 STH2kr &screen-xloop-bg #00 .Screen/sprite DEO INC2 ORAk ,&screen-xloop-bg JCN POP2 #0000 .Screen/x DEO2 STH2kr &screen-xloop-fg #40 .Screen/sprite DEO INC2 ORAk ,&screen-xloop-fg JCN POP2 .Screen/y DEI2 #0008 ADD2 DUP2 .Screen/y DEO2 .Screen/height DEI2 LTH2 ,&screen-yloop JCN POP2r #00 .Screen/auto DEO ( reset device vectors ) LIT2r 0000 #00 &device-vector-loop DUP2r STHk DEO2r #10 ADD DUP ,&device-vector-loop JCN POP POP2r ( copy the zero-page-loader into f0-ff ) ;&zero-page-loader LITr f0 ©-loop LDAk STHkr STZ INC2 INCr STHkr ,©-loop JCN POP2 ( leave 00 on return stack ) ( prepare the stack for the zero-page-loader ) ( the more we prepare here in advance, the less we'll have to overwrite ) STHkr #00fe ( arguments for STZ2 at ff ) STHkr ( argument for JMP at fe (carry on) ) DUPk #fcfe ( arguments for STZ2 at fd and JMP (repeat) ) OVR2 #fafe ( arguments for STZ2 at fd and JMP (repeat) ) OVR2 #f8fe ( arguments for STZ2 at fd and JMP (repeat) ) OVR2 #f6fe ( arguments for STZ2 at fd and JMP (repeat) ) OVR2 #f401 ( arguments for STZ2 at fd, plus an extra 01 ) STHkr ( first argument for ADD2 ) .File/success ( argument for DEI2 ) #0100 .File/load ( arguments for DEO2 ) #ff00 .File/length DEO2 #00f0 JMP2 &zero-page-loader ( f0 ) DEO2 ( f1 ) DEI2 ( f2 ) ADD2 ( f3 ) &loop DUPr ( f4 ) STH2k ( f5 ) STAr ( f6 ) INC2 ( f7 ) NEQ2k ( f8 ) ,&loop ( f9 ) ( fa ) JCN ( fb ) POPr ( fc ) POP2 ( fd ) STZ2 ( deletes f4-fd through looping ) ( fe ) JMP ( ff ) STZ2 ( deletes fe-ff ) &tmp $1 @capture-input ( -> ) ;no-instr .Mouse/vector DEO2 ;no-instr .Controller/vector DEO2 RTN @no-instr BRK ( constants ) @carts-file "n/carts 00 @slot-file "n/slot 00 @ctl-file "n/ctl 00 @title-loadCart "Select 20 "A 20 "Cartridge 00 @title-confirmCart "Load 20 "This 20 "Cartridge? 00 @load-cmd "load 20 @cart $32 ( sprites ) @blank $16 @uxn-logo [ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 09 1b 3f 1e 18 18 18 00 00 00 00 00 00 00 00 00 e0 f0 38 1c 0c 0c 0c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 18 18 18 18 18 18 18 3e 00 00 00 00 00 00 00 00 0c 0c 0c 0c 0c 0c 1e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 78 30 30 30 30 30 30 00 00 00 00 00 00 00 00 7c 18 18 18 18 18 18 18 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 30 30 38 1c 0f 07 00 00 00 00 00 00 00 00 00 18 18 38 78 fc d8 90 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ] @xrxs-logo [ 00 00 00 00 00 00 00 00 00 60 70 38 1c 0e 07 03 00 00 00 00 00 00 00 00 00 00 06 0c 18 30 60 c0 00 00 00 00 00 00 00 00 00 01 63 36 1c 0c 0c 0c 00 00 00 00 00 00 00 00 00 e0 f0 1c 0c 00 00 00 00 00 00 00 00 00 00 00 03 06 0c 18 30 60 00 00 00 00 00 00 00 00 00 00 c0 e0 70 38 1c 0e 06 00 00 00 00 00 00 00 00 00 0c 0c 0c 0c 0c 1c 3e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 60 70 38 1c 0e 07 03 00 00 00 00 00 00 00 00 00 00 06 0c 18 30 60 c0 00 00 00 00 00 00 00 00 00 03 07 0e 18 18 18 1f 00 00 00 00 00 00 00 00 00 c0 f0 78 08 00 00 e0 00 00 00 00 00 00 00 00 03 06 0c 18 30 60 00 00 00 00 00 00 00 00 00 00 c0 e0 70 38 1c 0e 06 00 00 00 00 00 00 00 00 00 07 00 00 10 1e 0f 03 00 00 00 00 00 00 00 00 00 f8 18 18 18 70 e0 c0 00 ] @yes-btn [ ff f8 f0 e0 e0 e1 e2 e2 00 07 08 10 10 11 12 12 ff 00 00 00 e0 10 08 08 00 ff 00 00 e0 10 08 08 ff 00 00 00 00 00 00 00 00 ff 00 00 82 82 44 38 ff 00 00 00 00 00 00 00 00 ff 00 00 fe 80 80 f8 ff 00 00 00 00 00 00 00 00 ff 00 00 7c 82 80 7c ff 3f 1f 0f 0f 0f 0f 0f 00 c0 20 10 10 10 10 10 e2 e1 e0 e0 e0 f0 f8 ff 12 11 10 10 10 08 07 00 08 10 e0 00 00 00 00 ff 08 10 e0 00 00 00 ff 00 00 00 00 00 00 00 00 ff 10 10 10 00 00 00 ff 00 00 00 00 00 00 00 00 ff 80 80 fe 00 00 00 ff 00 00 00 00 00 00 00 00 ff 02 82 7c 00 00 00 ff 00 0f 0f 0f 0f 0f 1f 3f ff 10 10 10 10 10 20 c0 00 ] @no-btn [ ff f8 f0 e0 e2 e1 e0 e0 00 07 08 10 12 11 10 10 ff 00 00 00 08 10 a0 40 00 ff 00 00 08 10 a0 40 ff 00 00 00 00 00 00 00 00 ff 00 00 08 0c 0a 09 ff 00 00 00 00 00 00 00 00 ff 00 00 27 28 28 28 ff 00 00 00 00 00 00 00 00 ff 00 00 c0 20 20 20 ff 3f 1f 0f 0f 0f 0f 0f 00 c0 20 10 10 10 10 10 e0 e1 e2 e0 e0 f0 f8 ff 10 11 12 10 10 08 07 00 a0 10 08 00 00 00 00 ff a0 10 08 00 00 00 ff 00 00 00 00 00 00 00 00 ff 08 08 08 00 00 00 ff 00 00 00 00 00 00 00 00 ff a8 68 27 00 00 00 ff 00 00 00 00 00 00 00 00 ff 20 20 c0 00 00 00 ff 00 0f 0f 0f 0f 0f 1f 3f ff 10 10 10 10 10 20 c0 00 ] @yes-btn-active [ ff ff f8 f0 f0 f1 f2 f2 00 07 08 10 10 11 12 12 ff ff 00 00 e0 10 08 08 00 ff 00 00 e0 10 08 08 ff ff 00 00 00 00 00 00 00 ff 00 00 82 82 44 38 ff ff 00 00 00 00 00 00 00 ff 00 00 fe 80 80 f8 ff ff 00 00 00 00 00 00 00 ff 00 00 7c 82 80 7c ff ff 3f 1f 1f 1f 1f 1f 00 c0 20 10 10 10 10 10 f2 f1 f0 f0 f0 f8 ff ff 12 11 10 10 10 08 07 00 08 10 e0 00 00 00 ff ff 08 10 e0 00 00 00 ff 00 00 00 00 00 00 00 ff ff 10 10 10 00 00 00 ff 00 00 00 00 00 00 00 ff ff 80 80 fe 00 00 00 ff 00 00 00 00 00 00 00 ff ff 02 82 7c 00 00 00 ff 00 1f 1f 1f 1f 1f 3f ff ff 10 10 10 10 10 20 c0 00 ] @no-btn-active [ ff ff f8 f0 f2 f1 f0 f0 00 07 08 10 12 11 10 10 ff ff 00 00 08 10 a0 40 00 ff 00 00 08 10 a0 40 ff ff 00 00 00 00 00 00 00 ff 00 00 08 0c 0a 09 ff ff 00 00 00 00 00 00 00 ff 00 00 27 28 28 28 ff ff 00 00 00 00 00 00 00 ff 00 00 c0 20 20 20 ff ff 3f 1f 1f 1f 1f 1f 00 c0 20 10 10 10 10 10 f0 f1 f2 f0 f0 f8 ff ff 10 11 12 10 10 08 07 00 a0 10 08 00 00 00 ff ff a0 10 08 00 00 00 ff 00 00 00 00 00 00 00 ff ff 08 08 08 00 00 00 ff 00 00 00 00 00 00 00 ff ff a8 68 27 00 00 00 ff 00 00 00 00 00 00 00 ff ff 20 20 c0 00 00 00 ff 00 1f 1f 1f 1f 1f 3f ff ff 10 10 10 10 10 20 c0 00 ] @scrollbar [ ff ff ff ff ff ff ff ff 3c 3c 3c 3c 3c 3c 3c 3c ] @scrollbar-trough [ c3 c3 c3 c3 c3 c3 c3 c3 28 14 28 14 28 14 28 14 ] @cursor [ 80c0 e0f0 f8e0 1000 ] @font [ 00 00 00 00 00 00 00 00 00 18 18 18 08 00 08 00 00 14 14 00 00 00 00 00 00 24 7e 24 24 7e 24 00 00 10 3c 50 38 14 78 10 00 00 44 08 10 20 44 00 00 18 20 32 2c 24 1a 00 00 18 10 20 00 00 00 00 00 04 08 08 08 08 04 00 00 20 10 10 10 10 20 00 00 00 44 28 10 28 44 00 00 00 10 10 7c 10 10 00 00 00 00 00 00 0c 08 10 00 00 00 00 3e 00 00 00 00 00 00 00 00 0c 0c 00 00 02 04 08 10 20 40 00 00 38 44 54 54 44 38 00 00 30 10 10 10 10 38 00 00 38 44 04 38 40 7c 00 00 38 44 18 04 44 38 00 00 08 18 28 48 7c 08 00 00 7c 40 78 04 44 38 00 00 38 40 78 44 44 38 00 00 7c 04 08 10 10 10 00 00 38 44 38 44 44 38 00 00 38 44 44 3c 04 38 00 00 18 18 00 00 18 18 00 00 18 18 00 00 18 10 20 00 00 08 10 20 10 08 00 00 00 00 3e 00 3e 00 00 00 00 10 08 04 08 10 00 00 38 44 1c 10 00 10 00 00 38 44 5c 58 40 3c 00 00 10 28 44 7c 44 44 00 00 78 44 78 44 44 78 00 00 38 44 40 40 44 38 00 00 78 44 44 44 44 78 00 00 7c 40 7c 40 40 7c 00 00 7c 40 7c 40 40 40 00 00 38 44 40 4c 44 3c 00 00 44 44 7c 44 44 44 00 00 7c 10 10 10 10 7c 00 00 7c 08 08 48 48 30 00 00 44 48 70 48 44 44 00 00 40 40 40 40 40 7c 00 00 44 6c 7c 54 44 44 00 00 44 64 74 5c 4c 44 00 00 38 44 44 44 44 38 00 00 78 44 44 78 40 40 00 00 38 44 44 4c 4c 3e 00 00 78 44 44 78 44 44 00 00 3c 40 38 04 04 78 00 00 7c 10 10 10 10 10 00 00 44 44 44 44 44 3c 00 00 44 44 28 28 10 10 00 00 44 44 44 54 6c 44 00 00 44 44 38 38 44 44 00 00 44 44 28 10 10 10 00 00 7c 04 18 30 40 7c 00 00 3c 30 30 30 30 3c 00 00 40 20 10 08 04 02 00 00 3c 0c 0c 0c 0c 3c 00 00 10 38 6c 00 00 00 00 00 00 00 00 00 00 7e 00 00 18 08 04 00 00 00 00 00 00 38 04 3c 44 3c 00 00 40 40 78 44 44 78 00 00 00 38 44 40 44 38 00 00 04 04 3c 44 44 3c 00 00 00 38 44 7c 40 3c 00 00 1c 20 78 20 20 20 00 00 00 3c 44 3c 04 44 38 00 40 40 78 44 44 44 00 00 30 00 70 10 10 18 00 00 0c 00 3c 04 04 44 38 00 00 44 48 70 48 44 00 00 70 10 10 10 10 1c 00 00 00 44 6c 7c 54 44 00 00 00 78 44 44 44 44 00 00 00 38 44 44 44 38 00 00 00 78 44 44 78 40 40 00 00 3c 44 44 3d 06 04 00 00 4c 50 60 40 40 00 00 00 3c 40 38 04 78 00 00 20 78 20 20 24 38 00 00 00 44 44 44 44 3c 00 00 00 44 44 28 28 10 00 00 00 44 44 54 7c 28 00 00 00 44 28 10 28 44 00 00 00 44 44 3c 04 78 00 00 00 7c 04 38 40 7c 00 00 1e 10 10 10 00 00 00 00 10 10 10 10 10 10 00 00 00 00 08 08 08 78 00 00 00 00 32 4c 00 00 00 3c 42 99 a1 a1 99 42 3c ] ( big data ) @word [ #0000 #0000 #0000 #0000 #0000 #0000 #0000 #0000 #0000 #0000 #0000 #0000 #0000 #0000 #0000 #0000 ] @list-buf $8192 |