-
Notifications
You must be signed in to change notification settings - Fork 2
/
tuto_day2.cm
119 lines (96 loc) · 2.76 KB
/
tuto_day2.cm
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
(#define System/r 0x08)
(#define System/g 0x0a)
(#define System/b 0x0c)
(#define Screen/x 0x28)
(#define Screen/y 0x2a)
(#define Screen/addr 0x2c)
(#define Screen/pixel 0x2e)
(#define Screen/sprite 0x2f)
(#define DrawPixel (!out 0x41 Screen/pixel))
(:*u16 square = (#0xff81 #0x8181 #0x8181 #0x81ff))
(:*u16 rock = (#0x3c4e #0x9ffd #0xf962 #0x3c00))
(:*u16 character = (#0x3c7e #0x5a7f #0x1b3c #0x5a18))
(:*u16 new-square = (
#0x17f #0x7b73 #0x6343 #0x7fff
#0x007c #0x7c7c #0x7c7c #0x0000
))
(:void addx8 () (local) (!out ((!in16 Screen/x) + #8) Screen/x) (ret))
(:void addy8 () (local) (!out ((!in16 Screen/y) + #8) Screen/y) (ret))
(:void draw-one-pixel () (local)
(!out #8 Screen/x)
(!out #8 Screen/y)
(!out 0x41 Screen/pixel)
(ret))
(:void draw-a-line () (local :u16 i)
(i = #8)
(while (i < #29) (
(!out i Screen/x)
DrawPixel
(i = (i + #1))
))
(ret))
(:void draw-sprites () (local)
(!out #8 Screen/x)
(!out #8 Screen/y)
(!out square Screen/addr)
(!out 0 Screen/sprite) (addx8)
(!out 1 Screen/sprite) (addx8)
(!out 2 Screen/sprite) (addx8)
(!out 3 Screen/sprite) (addy8)
(!out #8 Screen/x)
(!out 4 Screen/sprite) (addx8)
(!out 5 Screen/sprite) (addx8)
(!out 6 Screen/sprite) (addx8)
(!out 7 Screen/sprite) (addy8)
(!out #8 Screen/x)
(!out 8 Screen/sprite) (addx8)
(!out 9 Screen/sprite) (addx8)
(!out 0xa Screen/sprite) (addx8)
(!out 0xb Screen/sprite) (addy8)
(!out #8 Screen/x)
(!out 0xc Screen/sprite) (addx8)
(!out 0xd Screen/sprite) (addx8)
(!out 0xe Screen/sprite) (addx8)
(!out 0xf Screen/sprite)
(ret))
(:void addxc () (local) (!out ((!in16 Screen/x) + #0xc) Screen/x) (ret))
(:void addyc () (local) (!out ((!in16 Screen/y) + #0xc) Screen/y) (ret))
(:void draw-2bpp-sprites () (local)
(!out #8 Screen/x)
(!out #8 Screen/y)
(!out new-square Screen/addr)
(!out 0x80 Screen/sprite) (addxc)
(!out 0x81 Screen/sprite) (addxc)
(!out 0x82 Screen/sprite) (addxc)
(!out 0x83 Screen/sprite) (addyc)
(!out #8 Screen/x)
(!out 0x84 Screen/sprite) (addxc)
(!out 0x85 Screen/sprite) (addxc)
(!out 0x86 Screen/sprite) (addxc)
(!out 0x87 Screen/sprite) (addyc)
(!out #8 Screen/x)
(!out 0x88 Screen/sprite) (addxc)
(!out 0x89 Screen/sprite) (addxc)
(!out 0x8a Screen/sprite) (addxc)
(!out 0x8b Screen/sprite) (addyc)
(!out #8 Screen/x)
(!out 0x8c Screen/sprite) (addxc)
(!out 0x8d Screen/sprite) (addxc)
(!out 0x8e Screen/sprite) (addxc)
(!out 0x8f Screen/sprite)
(ret)
)
(:void main () (local :u16 i)
(!out #0x2ce9 System/r)
(!out #0x01c0 System/g)
(!out #0x2ce5 System/b)
; draw one pixel
; (draw-one-pixel)
; draw a horizontal line 20px long
; (draw-a-line)
; draw square sprites
; (draw-sprites)
; draw 2pp square sprites
(draw-2bpp-sprites)
(ret)
)