uxnwithrosia

some uxn practice with friends :)
Log | Files | Refs

draw-with-keyboard.tal (1912B)


      1 ( draw-with-keyboard.tal )
      2 ( devices )
      3 |00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
      4 |20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite ]
      5 |80 @Controller [ &vector $2 &button $1 &key $1 ]
      6 
      7 ( main program )
      8 |0100
      9       ( set system colors )
     10       #2ce9 .System/r DEO2
     11       #01c0 .System/g DEO2
     12       #2ce5 .System/b DEO2
     13 
     14       ( assign controller vector )
     15       ;on-controller .Controller/vector DEO2
     16 
     17       ( set initial x,y coordinates )
     18       #0008 .Screen/x DEO2
     19       #0008 .Screen/y DEO2
     20       ( set sprite address )
     21       ;square .Screen/addr DEO2
     22 BRK
     23 
     24 @on-controller ( -> )
     25       .Controller/button DEI DUP ( read and duplicate button byte )
     26       #01 AND ( isolate bit 0, corresponding to Ctrl )
     27       ,&fill JCN ( if the bit is not 0, jump to fill, otherwise continue )
     28 
     29       &outline
     30         #01 .Screen/sprite DEO ( draw outline )
     31         ,&check-arrows JMP ( continue to check-arrows )
     32 
     33       &fill
     34         #04 .Screen/sprite DEO ( draw filled )
     35 
     36       &check-arrows
     37         ( use button byte from the stack )
     38         DUP #10 AND ( isolate bit 4, corresponding to Up )
     39         ,&up JCN ( jump if not 0 )
     40         DUP #20 AND ( isolate bit 5, corresponding to Down )
     41         ,&down JCN ( jump if not 0 )
     42         DUP #40 AND ( isolate bit 6, corresponding to Left )
     43         ,&left JCN ( jump if not 0 )
     44         DUP #80 AND ( isolate bit 7, corresponding to Right )
     45         ,&right JCN ( jump if not 0 )
     46 
     47         POP BRK
     48 
     49       &up
     50        .Screen/y DEI2 #0008 SUB2 .Screen/y DEO2 ( decrement y )
     51        POP
     52       BRK
     53       &down
     54        .Screen/y DEI2 #0008 ADD2 .Screen/y DEO2 ( increment y )
     55        POP
     56       BRK
     57       &left
     58        .Screen/x DEI2 #0008 SUB2 .Screen/x DEO2 ( decrement x )
     59        POP
     60       BRK
     61       &right
     62        .Screen/x DEI2 #0008 ADD2 .Screen/x DEO2 ( increment x )
     63        POP
     64       BRK
     65 BRK
     66 ( sprite )
     67 @square ff81 8181 8181 81ff