cheatsheets devlog projects search

uxn-day-5.md

Uxn - Day 5

2023-01-07 3

A shorter day today going over the mouse and writing subroutines.

https://compudanzas.net/uxn_tutorial_day_5.html

Learning to use the mouse was fun, definitely getting to the end of the tutorial as we are now on the last few opcodes.

The next article looks the most interesting with a game being built and then on day 7 is file IO.

b998b4dd0d6fb1e7d5e3ab0cac844eae

The final code for day 5:

( day 5 )

( devices )
|00 @System  [ &vector $2 &pad $6  &r $2 &g $2 &b $2 ]
|20 @Screen  [ &vector $2 &width $2 &height $2 &pad  $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ]
|90 @Mouse   [ &vector $2 &x $2 &y $2 &state $1 &pad $3 &scrollx $2 &scrolly $2 ]

( macros )
%RTN { JMP2r }

( zero page )
|0000
@pointer &x $2 &y $2c

( main )
|0100
    #2ce9 .System/r DEO2
    #01c0 .System/g DEO2
    #2ce5 .System/b DEO2

    ;pointer_icn .Screen/addr DEO2

    ;on-mouse .Mouse/vector DEO2
BRK

@on-mouse 
    ;draw-pointer JSR2

    ,&pressed JCN

    BRK

    &pressed
        ;flower .Screen/addr DEO2
        #4a .Screen/sprite DEO
BRK

@draw-pointer 
    .pointer/x LDZ2 .Screen/x DEO2
    .pointer/y LDZ2 .Screen/y DEO2

    #00 .Screen/sprite DEO

    .Mouse/x DEI2 DUP2 .pointer/x STZ2 .Screen/x DEO2
    .Mouse/y DEI2 DUP2 .pointer/y STZ2 .Screen/y DEO2

    ;pointer_icn .Screen/addr DEO2
    #01 .Screen/sprite DEO

    .Mouse/state DEI 
RTN

@flower 9942 2499 9924 4299
@pointer_icn [ 80c0 e0f0 f8e0 1000 ]