~vesto/uxn-shenanigans

d51d5842957fc92253b1323028e9a95cd7537cec — Steve Gattuso 1 year, 7 months ago
initial commit with working x-loop
3 files changed, 109 insertions(+), 0 deletions(-)

A .gitignore
A hex-grid.tal
A mouse-cursor.tal
A  => .gitignore +1 -0
@@ 1,1 @@
*.rom

A  => hex-grid.tal +55 -0
@@ 1,55 @@
( devices )
|00 @System  [ &vector $2 &pad $6 &r $2 &g $2 &b $2 &debug $1 ]
|10 @Console [ &vector $2 &read $1 &pad $6 &write $1 ]
|20 @Screen  [ &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ]
|80 @Controller [ &vector $2 &button $1 &key $1 ]
|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 ]

%RTN { JMP2r }
%EMIT { .Console/write DEO }
%DEBUG { #01 .System/debug DEO }

( main program )
|0100
  ( set system colors )
  #2c39 .System/r DEO2
  #01c0 .System/g DEO2
  #2ce5 .System/b DEO2

  .Screen/width DEI2 #0000
  &loop-x
    DUP2 #0000 #c5 ;draw-hex JSR2  ( push y and color onto the stack, draw it )
    #000c ADD2  ( increment our x counter )
    GTH2k  ( check to see if the width is greater than our x, jump if not )
    ,&loop-x JCN
  POP2 POP2

  ( #0000 #0000 #c5 ;draw-hex JSR2 )
BRK

@draw-hex ( x^ y^ color -- )
  STH
  ( set x/y coords and stash the color )
  .Screen/y DEO2 .Screen/x DEO2

  ;hex-sprite/tl .Screen/addr DEO2
  STHrk .Screen/sprite DEO

  .Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
  ;hex-sprite/tr .Screen/addr DEO2
  STHrk .Screen/sprite DEO

  .Screen/y DEI2 #0008 ADD2 .Screen/y DEO2
  ;hex-sprite/br .Screen/addr DEO2
  STHrk .Screen/sprite DEO

  .Screen/x DEI2 #0008 SUB2 .Screen/x DEO2
  ;hex-sprite/bl .Screen/addr DEO2
  STHr .Screen/sprite DEO
RTN

@hex-sprite
  &tl [ 0001 0618 6040 4040 0000 0000 0000 0000 ]
  &tr [ 0000 c030 0c04 0404 0000 0000 0000 0000 ]
  &bl [ 4040 4040 6018 0601 0000 0000 0000 0000 ]
  &br [ 0404 0404 0c30 c000 0000 0000 0000 0000 ]

A  => mouse-cursor.tal +53 -0
@@ 1,53 @@
( hello-screen.tal )
( devices )

|00 @System  [ &vector $2 &pad $6 &r $2 &g $2 &b $2 &debug $1 ]
|10 @Console [ &vector $2 &read $1 &pad $6 &write $1 ]
|20 @Screen  [ &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ]
|80 @Controller [ &vector $2 &button $1 &key $1 ]
|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 ]

|0000
  @cursor [ &x $2 &y $2 ]

( macros )
%DRAW-PX { #41 .Screen/pixel DEO } ( -- )
%DRAW-SPR { .Screen/addr DEO2 } ( vec mod -- )
%INC-X { .Screen/x DEI2 INC2 .Screen/x DEO2 } ( -- )
%INC-Y { .Screen/y DEI2 INC2 .Screen/y DEO2 } ( -- )
%RTN { JMP2r }
%EMIT { .Console/write DEO }
%DEBUG { #01 .System/debug DEO }

( main program )
|0100
  ( set system colors )
  #2c39 .System/r DEO2
  #01c0 .System/g DEO2
  #2ce5 .System/b DEO2

  ;on-mouse .Mouse/vector DEO2
BRK

@on-mouse
  ( clear the old cursor )
  #40 .cursor/x LDZ2 .cursor/y LDZ2 ;draw-mouse JSR2

  ( draw the new cursor )
  #c5 .Mouse/x DEI2 .Mouse/y DEI2 ;draw-mouse JSR2

  ( store the coords of the mouse )
  .Mouse/x DEI2 .cursor/x STZ2
  .Mouse/y DEI2 .cursor/y STZ2
BRK

@draw-mouse ( color x y -- )
  ( set x/y coords and stash the color )
  .Screen/y DEO2 .Screen/x DEO2
  STH

  ;cursor-sprite .Screen/addr DEO2
  STHr .Screen/sprite DEO
RTN

@cursor-sprite fcfc f0f8 dcce 0703