rule110.tal (3086B)
1 ( devices ) 2 3 ( uxnasm rule110.tal rule110.rom && uxnemu rule110.rom ) 4 5 %2* { #10 SFT } %2/ { #01 SFT } %2** { #10 SFT2 } %2// { #01 SFT2 } 6 %4* { #20 SFT } %4/ { #02 SFT } %4** { #20 SFT2 } %4// { #02 SFT2 } 7 %8* { #30 SFT } %8/ { #03 SFT } %8** { #30 SFT2 } %8// { #03 SFT2 } 8 %10* { #40 SFT } %10/ { #04 SFT } %10** { #40 SFT2 } %10// { #04 SFT2 } 9 %20* { #50 SFT } %20/ { #05 SFT } %20** { #50 SFT2 } %20// { #05 SFT2 } 10 11 %2MOD { #01 AND } %2MOD2 { #0001 AND2 } 12 %4MOD { #03 AND } %4MOD2 { #0003 AND2 } 13 %8MOD { #07 AND } %8MOD2 { #0007 AND2 } 14 %10MOD { #0f AND } %10MOD2 { #000f AND2 } 15 16 %ROL2 { DUP2 #0f SFT2 SWP2 #10 SFT2 ADD2 } 17 %ROR2 { DUP2 #f0 SFT2 SWP2 #01 SFT2 ADD2 } 18 19 %DEBUG { ;print-hex/byte JSR2 #0a18 DEO } 20 %DEBUG2 { ;print-hex JSR2 #0a18 DEO } 21 %RTN { JMP2r } 22 23 %WIDTH { #0020 } 24 %STEPS { #30 } 25 26 |00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] 27 |20 @Screen [ &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] 28 |90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ] 29 30 |0000 31 32 @input 33 34 |0100 35 36 ( set system colors ) 37 #0ff7 .System/r DEO2 38 #0f0e .System/g DEO2 39 #0f0c .System/b DEO2 40 41 ;on-mouse .Mouse/vector DEO2 42 43 ( set size ) 44 #0080 .Screen/width DEO2 45 #0180 .Screen/height DEO2 46 47 ( seed ) #0001 ;input STA2 48 49 ,render JSR 50 51 BRK 52 53 @render ( -- ) 54 55 STEPS #00 56 &loop 57 ( update ) 58 DUP 2* LDZ2k 59 ;rule-110 JSR2 60 ROT INC INC STZ2 61 ( draw ) 62 DUP ,draw-line JSR 63 INC GTHk ,&loop JCN 64 POP2 65 66 RTN 67 68 @draw-line ( line -- ) 69 70 STHk #00 SWP 8** .Screen/y DEO2 71 #1000 72 &loop 73 DUP #00 SWP 8** .Screen/x DEO2 74 ( shift ) INCk #10 SWP SUB 75 ( get address ) STHkr 2* LDZ2 76 ( bit ) ROT SFT2 #0001 AND2 77 ( get sprite ) 8** ;cell-icns ADD2 .Screen/addr DEO2 78 #01 STHkr #00 EQU ADD .Screen/sprite DEO 79 INC GTHk ,&loop JCN 80 POP2 81 POPr 82 83 RTN 84 85 @rule-110 ( value* -- value* ) 86 87 #0000 ,&res STR2 88 ROL2 STH2 89 #1000 90 &loop 91 ( get 3-bits ) STH2kr #e000 AND2 #0d SFT2 ;rule ADD2 LDA STH 92 ( get result ) DUP #40 SFT #00 STHr ROT SFT2 93 ( reset ) ROR2 ROR2 ROR2 94 ( save ) ,&res LDR2 ADD2 ,&res STR2 95 STH2r ROR2 STH2 96 INC GTHk ,&loop JCN 97 POP2 98 POP2r 99 100 ,&res LDR2 101 102 RTN 103 &res $2 104 105 @rule 106 00 01 01 01 00 01 01 00 107 108 @on-mouse ( -> ) 109 110 ( clear last cursor ) 111 ;mouse-icn .Screen/addr DEO2 112 ,&x LDR2 .Screen/x DEO2 113 ,&y LDR2 .Screen/y DEO2 114 #40 .Screen/sprite DEO 115 116 ( record pointer positions ) 117 .Mouse/x DEI2 DUP2 ,&x STR2 .Screen/x DEO2 118 .Mouse/y DEI2 DUP2 ,&y STR2 .Screen/y DEO2 119 120 ( colorize on state ) 121 #43 [ .Mouse/state DEI #00 NEQ ] SUB .Screen/sprite DEO 122 123 ( on click ) 124 .Mouse/state DEI #00 NEQ JMP BRK 125 126 ( toggle bit ) 127 .input LDZ2k 128 #0001 .Mouse/x DEI2 8// #000f SWP2 SUB2 NIP #40 SFT SFT2 EOR2 129 ROT STZ2 130 ;render JSR2 131 ( release ) #00 .Mouse/state DEO 132 133 BRK 134 &x $2 &y $2 135 136 @print-hex ( value* -- ) 137 138 SWP ,&byte JSR 139 &byte ( byte -- ) 140 STHk #04 SFT ,&parse JSR #18 DEO 141 STHr #0f AND ,&parse JSR #18 DEO 142 RTN 143 &parse ( byte -- char ) DUP #09 GTH ,&above JCN #30 ADD RTN 144 &above #57 ADD RTN 145 146 RTN 147 148 @mouse-icn 149 80c0 e0f0 f8e0 1000 150 151 @cell-icns 152 7c82 8282 8282 7c00 153 7cfe fefe fefe 7c00 154