45 lines
1.1 KiB
Odin
45 lines
1.1 KiB
Odin
package sim_8086
|
|
|
|
import "core:os"
|
|
import "core:fmt"
|
|
import "core:math"
|
|
import "core:strings"
|
|
import "core:strconv"
|
|
|
|
extract_expected_cpu_state :: proc(filename: string) -> (Cpu, bool) {
|
|
cpu: Cpu
|
|
|
|
data,ok := os.read_entire_file(filename)
|
|
if !ok {
|
|
return cpu, false
|
|
}
|
|
defer delete(data)
|
|
|
|
content := string(data)
|
|
lines := strings.split(content, "\n")
|
|
defer delete(lines)
|
|
|
|
for line in lines {
|
|
space_count := 0
|
|
for c,i in line {
|
|
if space_count == 0 && c != ' ' {
|
|
break
|
|
} else if c == ' ' {
|
|
space_count += 1
|
|
} else {
|
|
if line[i:i+5] != "flags" {
|
|
reg_name := line[i:i+2]
|
|
reg_value := get_cpu_register_by_name(&cpu, reg_name)
|
|
hex_string := line[i+6:i+10]
|
|
if hex_num,ok := strconv.parse_int(hex_string, 16); ok {
|
|
reg_value^.full = u16(hex_num)
|
|
}
|
|
}
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
return cpu, true
|
|
}
|