-
Notifications
You must be signed in to change notification settings - Fork 0
/
xpmc.go
210 lines (183 loc) · 7.66 KB
/
xpmc.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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
package main
import (
//"flag"
"fmt"
"os"
//"runtime/pprof"
"strings"
"./compiler"
"./defs"
"./targets"
"./timing"
"./utils"
// "./player"
)
var target int
/*var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
var gbc = flag.String("gbc", "", "select GBC target")*/
func showHelp(what string) {
switch what {
case "EN":
fmt.Println("EN:\tArpeggio macro: { num | num}. num is zero or more numbers in\n\tthe range -63-63.\n")
default:
fmt.Println("Usage: xpmc.exe [options] target input [output]\n")
fmt.Println("Options:")
fmt.Println("\t-h\tShow this information")
fmt.Println("\t-v\tVerbose mode")
fmt.Println("\t-w\tTreat warnings as errors")
fmt.Println("\nTarget:")
fmt.Println("\t-at8\tAtari 8-bit")
fmt.Println("\t-c64\tCommodore 64")
fmt.Println("\t-clv\tColecoVision")
fmt.Println("\t-cpc\tAmstrad CPC")
fmt.Println("\t-cps\tCPS-1")
//fmt.Println(1, "\t-gba\tGameboy Advance")
fmt.Println("\t-gbc\tGameboy / Gameboy Color")
fmt.Println("\t-gen\tSEGA Genesis")
fmt.Println("\t-kss\tKSS")
fmt.Println("\t-nes\tNintendo Entertainment System")
fmt.Println("\t-pce\tPC-Engine")
//fmt.Println(1, "\t-nds\tNintendo DS")
//fmt.Println(1, "\t-sat\tSEGA Saturn")
fmt.Println("\t-sgg\tSEGA Game Gear")
fmt.Println("\t-sms\tSEGA Master System")
}
}
/*integer effectsRemoved
effectsRemoved = 0
func removeUnusedEffects(effectMap *effects.EffectMap, effectCmd int)
integer n
n = 1
pos := 0
for pos < effectMap.Len() {
key := effectMap.GetKeyAt(pos)
if !effectMap.IsReferenced(key) {
for i = 1 to length(songs) do
if sequence(songs[i]) then
for j, chn := range songs[i].Channels {
for k = 1 to length(songs[i][j]) do
if songs[i][j][k] == effectCmd {
if (songs[i][j][k + 1] & 0x7F) > pos {
songs[i][j][k + 1] = ((songs[i][j][k + 1] & 0x7F) - 1) | (songs[i][j][k + 1] & 0x80)
}
}
end for
}
end if
end for
tbl[ASSOC_KEY] = substr2(tbl[ASSOC_KEY], 1, n-1) & substr2(tbl[ASSOC_KEY], n+1, length(tbl[ASSOC_KEY]))
tbl[ASSOC_DATA] = substr2(tbl[ASSOC_DATA], 1, n-1) & substr2(tbl[ASSOC_DATA], n+1, length(tbl[ASSOC_DATA]))
tbl[ASSOC_REF] = substr2(tbl[ASSOC_REF], 1, n-1) & substr2(tbl[ASSOC_REF], n+1, length(tbl[ASSOC_REF]))
tbl[ASSOC_EXTRA] = substr2(tbl[ASSOC_EXTRA], 1, n-1) & substr2(tbl[ASSOC_EXTRA], n+1, length(tbl[ASSOC_EXTRA]))
effectsRemoved += 1
} else {
pos += 1
}
}
} */
func main() {
/*flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
//log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}*/
timing.UpdateFreq = 60.0
timing.UseFractionalDelays = true
if timing.UseFractionalDelays {
timing.SupportedLengths = defs.EXTENDED_LENGTHS()
}
utils.OldParsers = utils.NewGenericStack()
utils.Verbose(false)
utils.DebugMode(false)
utils.WarningsAreErrors(false)
target = targets.TARGET_UNKNOWN
comp := &compiler.Compiler{}
for i, arg := range os.Args {
if i >= 1 {
if arg[0] == '-' {
if arg == "-v" || arg == "-verbose" {
utils.Verbose(true);
} else if arg == "-d" || arg == "-debug" {
utils.DebugMode(true);
} else if arg == "-w" {
utils.WarningsAreErrors(true);
} else if arg == "-h" || arg == "-help" {
showHelp("")
return
} else if targets.NameToID(arg[1:]) != targets.TARGET_UNKNOWN {
target = targets.NameToID(arg[1:])
}
} else {
if target == targets.TARGET_UNKNOWN {
fmt.Printf("Error: No target platform specified.\nRun the compiler with the -h option to see a list of targets.")
return
}
comp.Init(target)
inputFileName := arg
lastDot := strings.LastIndexAny(inputFileName, ".")
lastSlash := strings.LastIndexAny(inputFileName, "/\\")
if lastDot >= 0 && lastSlash < 0 {
comp.ShortFileName = inputFileName[:lastDot]
} else {
comp.ShortFileName = inputFileName
inputFileName += ".mml"
}
if i < len(os.Args)-1 {
comp.ShortFileName = os.Args[i + 1]
lastDot = strings.LastIndexAny(os.Args[i + 1], ".")
if lastDot >= 0 {
comp.ShortFileName = os.Args[i+1][:lastDot]
//writeVGM = equal(lower(fileNames[2][n..length(fileNames[2])]), ".vgm")
//writeVGM += equal(lower(fileNames[2][n..length(fileNames[2])]), ".vgz") * 2
//writeWAV = equal(lower(fileNames[2][n..length(fileNames[2])]), ".wav")
}
}
//fmt.Printf("compiler.SFN = " + comp.ShortFileName + "\n")
comp.CompileFile(inputFileName);
// Insert END markers or jumps at the end of the command sequence for each channel
for _, song := range comp.Songs {
for _, chn := range song.Channels {
if chn.IsVirtual() {
continue
}
chn.LoopTicks = chn.Ticks - chn.LoopTicks
if chn.LoopPoint == -1 {
chn.AddCmd([]int{defs.CMD_END})
} else {
if !chn.HasAnyNote {
chn.AddCmd([]int{defs.CMD_END})
} else {
chn.AddCmd([]int{defs.CMD_JMP, chn.LoopPoint & 0xFF, chn.LoopPoint / 0x100})
}
}
}
}
// Compare the total lengths of all channels
ticks := -1
for _, song := range comp.Songs {
for _, chn := range song.Channels {
if chn.IsVirtual() {
continue
}
if chn.HasAnyNote {
if ticks == -1 {
ticks = chn.Ticks
} else if chn.Ticks != ticks {
fmt.Printf("Warning: Mismatch in length between channels in song %d\n", song.Num)
break
}
}
}
}
comp.RemoveUnusedEffects()
comp.CurrSong.Target.Output(targets.OUTPUT_ASSEMBLY)
return
}
}
}
showHelp("")
}