Add support for microcode definition
This commit is contained in:
parent
fef6fa0ecb
commit
e2025ec55d
30
weaver.kt
30
weaver.kt
@ -129,15 +129,31 @@ fun main(args: Array<String>){
|
|||||||
}
|
}
|
||||||
|
|
||||||
val weaveData = weaveFile.readText().replace("\r", "").split("\n").toTypedArray()
|
val weaveData = weaveFile.readText().replace("\r", "").split("\n").toTypedArray()
|
||||||
var subtract = 0
|
var index = 0
|
||||||
for(index in weaveData.indices)
|
var weaveUCode = false
|
||||||
if(weaveData[index].length == 0 || weaveData[index].startsWith("#")) ++subtract
|
for(rawValue in weaveData){
|
||||||
else if((index - subtract) > state.programMemory.size) error("Program memory out of bounds! Did you pass too much data?")
|
val value = rawValue.replace(" ", "").replace("\t", "")
|
||||||
else if(weaveData[index].length != 4) error("Cannot weave data of bad length: ${weaveData[index]}")
|
|
||||||
|
if(value.length == 0 || value.startsWith("#")) continue
|
||||||
|
else if((weaveUCode && index >= state.microMemory.size) || (!weaveUCode && index >= state.programMemory.size)) error("Program memory out of bounds! Did you pass too much data?")
|
||||||
|
else if(value.startsWith("@")){
|
||||||
|
if(value == "@u"){
|
||||||
|
weaveUCode = true
|
||||||
|
index = 0
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(value.startsWith("@0x")) index = Integer.parseInt(value.substring(3), 16)
|
||||||
|
else index = Integer.parseInt(value.substring(1), 10)
|
||||||
|
--index
|
||||||
|
}
|
||||||
|
else if((weaveUCode && value.length != 7) || (!weaveUCode && value.length != 4)) error("Cannot weave data of bad length: $value")
|
||||||
else try{
|
else try{
|
||||||
state.programMemory[index - subtract] = Integer.parseInt(weaveData[index], 16).toShort()
|
if(weaveUCode) state.microMemory[index] = Integer.parseInt(value, 16)
|
||||||
|
else state.programMemory[index] = Integer.parseInt(value, 16).toShort()
|
||||||
}catch(e: NumberFormatException){
|
}catch(e: NumberFormatException){
|
||||||
error("Cannot weave non-hex data: ${weaveData[index]}")
|
error("Cannot weave non-hex data: $value")
|
||||||
|
}
|
||||||
|
++index
|
||||||
}
|
}
|
||||||
|
|
||||||
val outputFile = if(args.size == 3) File(args[2]) else File(args[1])
|
val outputFile = if(args.size == 3) File(args[2]) else File(args[1])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user