Skip to content

Commit 62807e5

Browse files
committed
refined lua-common.lua
1 parent 30bbf51 commit 62807e5

File tree

1 file changed

+50
-78
lines changed

1 file changed

+50
-78
lines changed

emulator/lua-common.lua

Lines changed: 50 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,52 @@
1+
function help()
2+
print([[
3+
The supported functions are:
4+
printf() Print with format.
5+
ins() Log all register values to the screen.
6+
break_at(addr,fn) Set breakpoint. If input not specified, break at current address. Second argument (optional) is a function that is executed whenever this breakpoint hits.
7+
unbreak_at(addr) Delete breakpoint. If input not specified, delete breakpoint at current address. Have no effect if there is no breakpoint at specified position.
8+
cont() Continue program execution.
9+
pst()/pst(rad) Print 48 or rad bytes of the stack before and after SP.
10+
emu:set_paused(-) Pause/unpause emulator.
11+
emu:tick() Execute one command.
12+
emu:shutdown() Shutdown the emulator.
13+
cpu.xxx Get register value.
14+
cpu.bt Current stack trace.
15+
code[-] Access code. (By bytes)
16+
data[-] Access data. (By bytes)
17+
data:watch(addr,fn) Set write watchpoint.
18+
data:rwatch(addr,fn) Set read watchpoint.
19+
help() Print this help message.
20+
addposttick(fn) Add a function as post-tick handler. (wrapper over emu:post_tick)
21+
rmposttick(fn) Remove a post-tick handler. If called without argument, delete the most-recently added handler.
22+
er(x) Value of register ERx.
23+
24+
GDB-style functions:
25+
(the long functions are intended to be used in code, the short functions are intended to be used interactively so they prints debug info/etc.)
26+
p(...) Shorthand for `print`.
27+
pn(addr) Print calculator number at address
28+
ps/gets(addr) Print/get calculator string (0-terminated) at address
29+
pi/geti(addr) Print/get 2-byte unsigned integer at address
30+
h() help()
31+
n()/nexti() Go to next instruction.
32+
c() cont
33+
s() emu:tick()
34+
tr(filename) Start tracing (record all executed instructions)
35+
trs() Stop tracing.
36+
q() emu:shutdown()
37+
b(addr,fn) break/pause (breakpoint set with b should not be deleted with unbreak_at)
38+
ib() info breakpoints/watchpoints
39+
del(num) Delete breakpoint or watchpoint.
40+
bt() print(cpu.bt)
41+
rwa(offset,fn) Set read watchpoint at location (watchpoints set with rwa(-,-) should be deleted with del(-))
42+
wa(offset,fn) Set watchpoint at location (watchpoints set with wa(-,-) should be deleted with del(-))
43+
u0/until0() Run until address is hit and sp is <= original sp. Not as fully-functional as gdb's `until` command, so `u0`.
44+
ppc() Print current PC address.
45+
calll(addr,before,after) Call log.
46+
nrop() Next "ROP instruction".
47+
]])
48+
end
49+
150
local hwid = emu:model().hardware_id
251
local stack_end = hwid == 3 and 0x8e00 or 0xf000
352
local screen_nrow = hwid == 3 and 32 or 64
@@ -38,7 +87,6 @@ function rmposttick(fn)
3887
end
3988
print('Posttick handler not found')
4089
end
41-
4290
if not next(posttickfns) then
4391
emu:post_tick(nil)
4492
end
@@ -60,12 +108,10 @@ function break_at(addr, commands)
60108
else
61109
commands = function() end
62110
end
63-
64111
if not next(break_targets) then
65112
-- if break_targets is initially empty and later non-empty
66113
addposttick(break_posttick)
67114
end
68-
69115
break_targets[addr] = commands
70116
end
71117

@@ -74,7 +120,6 @@ function unbreak_at(addr)
74120
addr = get_real_pc()
75121
end
76122
break_targets[addr] = nil
77-
78123
if not next(break_targets) then
79124
rmposttick(break_posttick)
80125
end
@@ -104,76 +149,6 @@ function ins()
104149
printf("%02X %02X %02X %02X | ELVL %01X | %02X %01X:%04X", cpu.r12, cpu.r13, cpu.r14, cpu.r15, cpu.psw & 3, cpu.epsw3, cpu.ecsr3, cpu.elr3)
105150
end
106151

107-
function help()
108-
print([[
109-
The supported functions are:
110-
111-
printf() Print with format.
112-
113-
ins() Log all register values to the screen.
114-
115-
break_at(off,fn) Set breakpoint.
116-
If input not specified, break at current address.
117-
Second argument (optional) is a function that is executed whenever
118-
this breakpoint hits.
119-
120-
unbreak_at(off) Delete breakpoint.
121-
If input not specified, delete breakpoint at current address.
122-
Have no effect if there is no breakpoint at specified position.
123-
124-
cont() Continue program execution.
125-
126-
pst()/pst(rad) Print 48 or rad bytes of the stack before and after SP.
127-
128-
emu:set_paused(-) Set emulator state.
129-
emu:tick() Execute one command.
130-
emu:shutdown() Shutdown the emulator.
131-
132-
cpu.xxx Get register value.
133-
cpu.bt Current stack trace.
134-
135-
code[-] Access code.
136-
data[-] Access data. (By bytes)
137-
data:watch(off,fn) Set write watchpoint.
138-
data:rwatch(off,fn) Set read watchpoint.
139-
help() Print this help message.
140-
141-
addposttick(fn) Add a function as post-tick handler. (wrapper over emu:post_tick)
142-
rmposttick(fn) Remove a post-tick handler. If called without argument,
143-
delete the most-recently added handler.
144-
145-
er(x) Value of register ERx.
146-
147-
GDB-style functions:
148-
(the long functions are intended to be used in code, the short functions are intended
149-
to be used interactively so they prints debug info/etc.)
150-
151-
p(...) Shorthand for `print`.
152-
pn(off) Print calculator number at address
153-
ps/gets(off) Print/get calculator string (0-terminated) at address
154-
pi/geti(off) Print/get 2-byte unsigned integer at address
155-
h() help()
156-
n()/nexti() Go to next instruction.
157-
c() cont
158-
s() emu:tick()
159-
tr(filename) Start tracing (record all executed instructions)
160-
trs() Stop tracing.
161-
q() emu:shutdown()
162-
b(off,fn) break/pause (breakpoint set with b should not be deleted with unbreak_at)
163-
del(num) Delete breakpoint or watchpoint
164-
bt() print(cpu.bt)
165-
rwa(offset,fn) Set read watchpoint at location
166-
(watchpoints set with rwa should not be deleted with data:rwatch)
167-
wa(offset,fn) Set watchpoint at location
168-
(watchpoints set with wa should not be deleted with data:watch)
169-
u0/until0() Run until address is hit and sp is <= original sp.
170-
Not as fully-functional as gdb's `until` command, so `u0`.
171-
ppc() Print current PC address.
172-
calll(off,bef,aft) Call log.
173-
nrop() Next "ROP instruction".
174-
]])
175-
end
176-
177152
local function get_real_lr()
178153
return (cpu.lcsr << 16) | cpu.lr
179154
end
@@ -408,8 +383,7 @@ h = help
408383
function u0(addr) until0(addr) ppc() end
409384

410385
function calll(addr, before, after)
411-
-- Call before every time function addr is called and call after every time
412-
-- function addr returns.
386+
-- Call before every time function addr is called and call after every time function addr returns.
413387
before = to_function(before)
414388
after = to_function(after)
415389
b(addr, function()
@@ -552,7 +526,6 @@ end
552526
function prs() -- Print calculator number registers (specific to ES+)
553527
local x = {0x8000, 0x8010, 0x8020, 0x8030, 0x803C, 0x8046, 0x8050}
554528
for i,v in ipairs(x) do x[i]=getrn_str(v) end
555-
556529
printf(' R0: %20s | R1: %20s | R2: %20s',x[1],x[2],x[3])
557530
printf(' R3: %20s | R4: %20s | R5: %20s',x[4],x[5],x[6])
558531
printf(' R6: %20s',x[7])
@@ -576,7 +549,6 @@ end
576549

577550
function pst(radius)
578551
radius = radius or 48
579-
580552
sp = cpu.sp
581553
w = io.write
582554
linecnt = 0

0 commit comments

Comments
 (0)