-
Notifications
You must be signed in to change notification settings - Fork 2
/
emu_8080.lua
executable file
·59 lines (47 loc) · 1.14 KB
/
emu_8080.lua
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
#!/usr/bin/env lua
-- 8080 Emulator: Example usage.
local arg = arg or {...}
local fname = arg[1]
if not fname then
error("Need filename")
end
local f, err = io.open(fname, "rb")
if err then error(err) end
local memsz = 0x10000
-- Load bitops
local bitops = require("bitops")
-- Load 8080 CPU
local l8080 = require("8080")
-- Install bitops
l8080.set_bit32(bitops)
local memlib = require("memlib")
-- Memory: ROM, RAM and peripherals.
local t = f:read(memsz)
local rom = memlib.new("rostring", t, memsz)
f:close()
local mem = memlib.new("rwoverlay", rom, memsz)
-- Address handlers/Peripherals
--local addr_handlers = {}
--local comp = memlib.compose(mem, addr_handlers)
local function get(inst, i)
return mem:get(i)
end
local function set(inst, i, v)
return mem:set(i, v)
end
local function iog(inst, i)
if i == 0 then return string.byte(io.read(1)) end
return 0
end
local function ios(inst, i, v)
if i == 0 then
print(string.char(v))
end
end
local inst = l8080.new(get, set, iog, ios)
local fmt = string.format
while true do
local pc = inst.PC
local n, c = inst:run()
print(fmt("0x%04x: %s -> 0x%04x (%i cycles)", pc, n, inst.PC, c))
end