aboutsummaryrefslogtreecommitdiff
path: root/examples/pix.s
diff options
context:
space:
mode:
Diffstat (limited to 'examples/pix.s')
-rw-r--r--examples/pix.s74
1 files changed, 74 insertions, 0 deletions
diff --git a/examples/pix.s b/examples/pix.s
new file mode 100644
index 0000000..785da35
--- /dev/null
+++ b/examples/pix.s
@@ -0,0 +1,74 @@
+; pixel painting API with small demo loop
+; author: twitter @blubdidub
+
+jsr init_pixelmode
+
+set x, 0
+set y, 0
+set c, 0x5
+
+:demo_loop
+ set a, x
+ set b, y
+ jsr setpixel
+ add x, 1
+ ifg 0x20, x
+ set PC, cont
+ set x, 0
+ add y, 1
+ ifg 0x18, y
+ set PC, cont
+ set y, 0
+ add c, 1
+ ifg c, 0xe
+ set c, 0
+:cont
+
+ set j, 0
+:wait_loop
+ add j, 1
+ ifg 30, j
+ set PC, wait_loop
+
+ set pc, demo_loop
+
+; initialize pixel_mode for character 0x00
+:init_pixelmode
+ set [0x8180], 0x0f0f
+ set [0x8181], 0x0f0f
+ set pc, POP
+
+; set pixel to color (24*32 pixels)
+; param A: x position
+; param B: y position
+; param C: color
+:setpixel
+ set PUSH, y
+ set PUSH, i
+ set PUSH, c
+ ; calculate character address
+ set y, b
+ shr y, 1
+ ifn o, 0x0
+ set PC, lower_pixel
+ ; upper pixel
+ mul y, 0x20
+ add y, a
+ set i, [0x8000+y] ; read current val
+ and i, 0x0f00 ; clear upper pixel
+ shl c, 12
+ bor i, c ; set new color
+ set PC, finish_pixel
+:lower_pixel
+ mul y, 0x20
+ add y, a
+ set i, [0x8000+y] ; read current val
+ and i, 0xf000 ; clear lower pixel
+ shl c, 8
+ bor i, c ; set new color
+:finish_pixel
+ set [0x8000+y], i ; set character
+ set c, POP
+ set i, POP
+ set y, POP
+ set PC, POP