
include print: "./print.dsa"

db success: "Success!"
dw framebuffer: 0x30000
dw stack: 0x10000

_init:
    ldw stack, bpr
    mov bpr, spr

start:
    ldw framebuffer, rg0    // rg0 = display base address
    lli 0, rg1          // rg1 = y (0..240)

y_loop:
    lli 0, rg2          // rg2 = x (0..320)

x_loop:
    // red = x >> 1 (0..159, left to right gradient)
    shr rg2, zero, 1, rg4

    // green = y (0..239, top to bottom gradient)
    mov rg1, rg5

    // blue = constant 128
    lli 0x80, rg6

    // pack as 0xAABBGGRR (LE reads as RGBA)
    // start with red in bits 0-7
    mov rg4, rg7

    // green into bits 8-15
    shl rg5, zero, 8, rg5
    or rg7, rg5, rg7

    // blue into bits 16-23
    shl rg6, zero, 16, rg6
    or rg7, rg6, rg7

    // alpha into bits 24-31
    lli 0xFF, rg6
    shl rg6, zero, 24, rg6
    or rg7, rg6, rg7

    stw rg7, rg0            // write pixel
    addi rg0, 4, rg0        // next pixel

    addi rg2, 1, rg2
    lli 320, rg6
    ilt rg2, rg6, rg6
    jnz rg6, x_loop

    addi rg1, 1, rg1
    lli 240, rg6
    ilt rg1, rg6, rg6
    jnz rg6, y_loop


_end:
    lwi success: rg0
    push rg0
    call print::print
    pop zero
    hlt
