-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathwasm4.go
More file actions
139 lines (111 loc) · 7.1 KB
/
wasm4.go
File metadata and controls
139 lines (111 loc) · 7.1 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//
// WASM-4: https://wasm4.org/docs
package w4
import "unsafe"
// ┌───────────────────────────────────────────────────────────────────────────┐
// │ │
// │ Platform Constants │
// │ │
// └───────────────────────────────────────────────────────────────────────────┘
const SCREEN_SIZE int = 160
// ┌───────────────────────────────────────────────────────────────────────────┐
// │ │
// │ Memory Addresses │
// │ │
// └───────────────────────────────────────────────────────────────────────────┘
var PALETTE = (*[4]uint32)(unsafe.Pointer(uintptr(0x04)))
var DRAW_COLORS = (*uint16)(unsafe.Pointer(uintptr(0x14)))
var GAMEPAD1 = (*uint8)(unsafe.Pointer(uintptr(0x16)))
var GAMEPAD2 = (*uint8)(unsafe.Pointer(uintptr(0x17)))
var GAMEPAD3 = (*uint8)(unsafe.Pointer(uintptr(0x18)))
var GAMEPAD4 = (*uint8)(unsafe.Pointer(uintptr(0x19)))
var MOUSE_X = (*int16)(unsafe.Pointer(uintptr(0x1a)))
var MOUSE_Y = (*int16)(unsafe.Pointer(uintptr(0x1c)))
var MOUSE_BUTTONS = (*uint8)(unsafe.Pointer(uintptr(0x1e)))
var SYSTEM_FLAGS = (*uint8)(unsafe.Pointer(uintptr(0x1f)));
var START_TIME = (*uint64)(unsafe.Pointer(uintptr(0x20)));
var FRAMEBUFFER = (*[6400]uint8)(unsafe.Pointer(uintptr(0xa0)))
const BUTTON_1 byte = 1
const BUTTON_2 byte = 2
const BUTTON_LEFT byte = 16
const BUTTON_RIGHT byte = 32
const BUTTON_UP byte = 64
const BUTTON_DOWN byte = 128
const MOUSE_LEFT byte = 1
const MOUSE_RIGHT byte = 2
const MOUSE_MIDDLE byte = 4
const SYSTEM_PRESERVE_FRAMEBUFFER byte = 1
const SYSTEM_HIDE_GAMEPAD_OVERLAY byte = 2
// ┌───────────────────────────────────────────────────────────────────────────┐
// │ │
// │ Drawing Functions │
// │ │
// └───────────────────────────────────────────────────────────────────────────┘
/** Copies pixels to the framebuffer. */
//go:export blit
func Blit(sprite *byte, x int, y int, width uint, height uint, flags uint)
/** Copies a subregion within a larger sprite atlas to the framebuffer. */
//go:export blitSub
func BlitSub(sprite *byte, x int, y int, width uint, height uint,
srcX uint, srcY uint, stride int, flags uint)
const BLIT_2BPP = 1
const BLIT_1BPP = 0
const BLIT_FLIP_X = 2
const BLIT_FLIP_Y = 4
const BLIT_ROTATE = 8
/** Draws a line between two points. */
//go:export line
func Line(x1 int, y1 int, x2 int, y2 int)
/** Draws a horizontal line. */
//go:export hline
func HLine(x int, y int, len uint)
/** Draws a vertical line. */
//go:export vline
func VLine(x int, y int, len uint)
/** Draws an oval (or circle). */
//go:export oval
func Oval(x int, y int, width uint, height uint)
/** Draws a rectangle. */
//go:export rect
func Rect(x int, y int, width uint, height uint)
/** Draws text using the built-in system font. */
//go:export textUtf8
func Text(text string, x int, y int)
// ┌───────────────────────────────────────────────────────────────────────────┐
// │ │
// │ Sound Functions │
// │ │
// └───────────────────────────────────────────────────────────────────────────┘
/** Plays a sound tone. */
//go:export tone
func Tone(frequency uint, duration uint, volume uint, flags uint)
const TONE_PULSE1 = 0
const TONE_PULSE2 = 1
const TONE_TRIANGLE = 2
const TONE_NOISE = 3
const TONE_MODE1 = 0
const TONE_MODE2 = 4
const TONE_MODE3 = 8
const TONE_MODE4 = 12
// ┌───────────────────────────────────────────────────────────────────────────┐
// │ │
// │ Storage Functions │
// │ │
// └───────────────────────────────────────────────────────────────────────────┘
/** Reads up to `size` bytes from persistent storage into the pointer `destPtr`. */
//go:export diskr
func DiskR(ptr unsafe.Pointer, count uint) uint
/** Writes up to `size` bytes from the pointer `srcPtr` into persistent storage. */
//go:export diskw
func DiskW(src unsafe.Pointer, count uint) uint
// ┌───────────────────────────────────────────────────────────────────────────┐
// │ │
// │ Other Functions │
// │ │
// └───────────────────────────────────────────────────────────────────────────┘
/** Prints a message to the debug console. */
//go:export traceUtf8
func Trace(str string)
// TinyGo requires a main function, so provide one
//go:linkname main main.main
func main() {}