Thursday | 28 MAR 2024
[ previous ]
[ next ]

Uxn - Day 6 - Part 1

Title:
Date: 2023-01-08
Tags:  

Day 6!

https://compudanzas.net/uxn_tutorial_day_6.html

I'm going to split this into 3 sections as the tutorial does the same and I think it make it easier to hold in my head if I separate this into 3 parts as well.

The first part of the tutorial deals with drawing the background. This is the simplest step and it involves drawing a tile across the x axis and then duplicating that row on the y axis. This means that there is a loop to draw across the x and then another loop outside of it that loops over the y co-ordinates.

This was fun to implement and I can see now that building larger programs in uxn require you to build subroutines and make sure they clean up after themselves. They should be written such that they don't leave anything on stack that might interfere with other parts of the program.

The code as of the first part of day 6:

( hello-pong.tal )

( devices )
|00 @System  [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|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 ]

( macros )
%RTN { JMP2r }

( main program )
|0100

@setup
    #2ce9 .System/r DEO2
    #01c0 .System/g DEO2
    #2ce5 .System/b DEO2

    ;draw-background JSR2
BRK

@draw-background
    ;tile-background .Screen/addr DEO2

    .Screen/height DEI2 #0010 SUB2 
    #0010

    &loop-y
        DUP2 .Screen/y DEO2

        .Screen/width DEI2
        #0000

        &loop-x
            DUP2 .Screen/x DEO2
            #03 .Screen/sprite DEO
            #0008 ADD2
            GTH2k ,&loop-x JCN
        POP2 POP2

        #0008 ADD2
        GTH2k ,&loop-y JCN
    POP POP
RTN

@tile-background 1122 4488 1122 4488