aboutsummaryrefslogtreecommitdiff
path: root/examples/pix.s
blob: 785da351668f36f9802275352f5ecffb33338e37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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