-
Notifications
You must be signed in to change notification settings - Fork 3
/
functions.go
65 lines (56 loc) · 1.03 KB
/
functions.go
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
/****************************************
DCPU-Bas - QuickBasic DCPU-16 compiler
by M4v3R ([email protected])
Basic functions
****************************************/
package main
import (
"fmt"
)
func FuncStr() {
Next()
MatchString("(")
BoolExpression()
label := NewLabel()
EmitLine("ADD PC, 2")
PostLabel(label)
EmitLine("DAT 0")
EmitLine("DAT 0")
EmitLine(fmt.Sprintf("SET [%s], A", label))
EmitLine(fmt.Sprintf("SET A, %s", label))
EmitLine("BOR A, 0x8000")
}
func FuncChr() {
Next()
MatchString("(")
BoolExpression()
EmitLine("IFG 0xF000, A") // Check if it's not a stack pointer
EmitLine("AND A, 0x7fff")
EmitLine("SET PUSH, [A]")
EmitLine("SET A, POP")
}
func FuncVal() {
Next()
MatchString("(")
BoolExpression()
Call("atoi")
}
func FuncPeek() {
Next()
MatchString("(")
BoolExpression()
EmitLine("SET B, [A]")
EmitLine("SET A, B")
}
func FuncSqr() {
Next()
MatchString("(")
BoolExpression()
Call("sqrt")
}
func FuncLen() {
Next()
MatchString("(")
BoolExpression()
Call("strlen")
}