« Oatmeal

Tagged "scripting"

Follow this tag

uxn exit

This evening I sat down on the couch sleepy. We’d just gotten the kids into bed. I hadn’t planned on writing any code but figured I’d round the evening out with some reading.

First I read through the docs and glossary of uf, a forth system for uxn. Then I read through an example program provided by uf.

…with my palette whetted I re-visited some other forth documentation.

Then I put things down and did the dishes. After doing the dishes I found myself back at a keyboard ready to write some code.

My first thought was to re-implement the unix command cat in uxntal. After a bit of noodling I decided to go with echo instead of cat. I banged away at echo for a bit but then remembered the very first program demonstrated in a book I’m currently reading, Programming from the Ground Up, by Jonathan Bartlett. The first sample program there is one that exits. That is about it.

Exiting felt achievable.

Here is a teeny tiny program that prints the string Hello Uxn! and then exits.

( exit )

|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1

|0100 ( -> )

    ( print hello )
    ;hello-txt

    &while
        LDAk .Console/write DEO
        INC2 LDAk ,&while JCN
    POP2

    ( exit )
    #010f DEO

BRK


@hello-txt "Hello 20 "Uxn! $1

It isn’t much, but it is a start.

Some handy resources I poured over over this evenings explorations include:

Also, big thanks to Devine Lu Linvenga, a primary force behind uxn, for pointing me in the right direction and suggesting some optimizations.

I’m not sure if I’ll have it in me to write code every night moving forward, but this was a lot of fun and I still have big dreams for a homespun cat.tal

uxn laboratory

As I look to assembly nights 2 and think of trying my own take on it, I wanna have a cozy space ready to play with uxn.

The setup I’ve landed on is sort of inspired by plan9port.

Prepare the way

  • in home directory, create a u directory
  • in u clone uxn and build it
  • add ~/u/uxn/ to your path as $UXN
  • add $UXN/bin to your path
  • moving forward we’ll put any and all *.rom files into $UXN/bin

Utility scripts

  • create script called u that contains the following
#!/bin/sh

UXN=${UXN:-$HOME/u/uxn}
export UXN

case "$PATH" in
$UXN/bin:*)
    ;;
*)
    PATH=$UXN/bin:$PATH
    export PATH
    ;;
esac

case $# in
[1-9]*)
       exec "$@"
       ;;
esac
  • make u executable with chmod +x and mv it to /usr/local/bin or some similar space

  • in $UXN/bin add the following scripts, make each executable with chmod +x

  • lin, used to lint *.tal files before assembly.

# script name: lin
#!/bin/sh

u uxncli uxnlin.rom $1
  • asm, used to assemble *.tal files into executable *.roms.
# script name: asm
#!/bin/sh

u uxnasm $1 $2
  • run, used to run *.roms in the sdl2 uxn emulator.
# script name: run
#!/bin/sh

u uxnemu $1
  • cli, used to run command line *.roms into stdin/stdout at the shell prompt.
# script name: cli
#!/bin/sh

u uxncli $1
# script name: drif
#!/bin/sh

u uxncli drifblim.rom $1 $2

rom library

  • wget the following roms into $UXN/bin
wget https://rabbits.srht.site/left/left.rom
wget https://rabbits.srht.site/drifblim/drifblim.rom

rock and roll

At this point everything is set and cozy to start exploring!

Do that like so:

  • to lint a *.tal file,
u lin rad.tal
  • to assemble a *.tal file using an assembler that supports macros,
u asm rad.tal rad.rom
  • to assemble a *.tal file using the selfhosted assembler,
u drif rad.tal rad.rom
  • to run a rom in the emulator
u run rad.rom
  • to run a rom at the prompt
u cli rad.rom
  • to edit something using left,
u uxnemu left.rom -s 2 rad.tal

NOTE: the -s 2 bit makes the program run zoomed…I’ve got bad eyesight and have a high DPI screen, you may not need that flag.

Onward!

Now, I’ll be honest — I don’t know if I’ll actually do my own flavor of assembly nights with uxn, but I’m really pleased with this little setup…so, that is a step in the right direction. The other step in the right direction I’ve taken is that I started to read Programming from the Ground Up by Jonathan Bartlett…so far, 2 chapters in, I am enjoying it a lot.