1+ local exports = {}
2+
3+ local cpu = nil
4+ local paused = false
5+
6+ local breakpointaddr = nil -- 0x8000
7+ local breakpoint_hit = false
8+
9+ function exports .startplugin ()
10+ print (" Plugin ZXBS loaded!" )
11+
12+ -- emu.register_start(function()
13+ emu .add_machine_reset_notifier (function ()
14+ cpu = manager .machine .devices [" :maincpu" ]
15+ print (" " )
16+ print (" CPU detected" )
17+
18+ if breakpointaddr then
19+ if cpu .debug then
20+ local id = cpu .debug :bpset (breakpointaddr , " " , " " )
21+ print (" Breakpoint set " .. id )
22+ else
23+ print (" DEBUG NO AVAILABLE" )
24+ end
25+ end
26+
27+ emu .register_periodic (timer )
28+ end )
29+ end
30+
31+
32+ function timer ()
33+ if not cpu or not cpu .debug then
34+ return
35+ end
36+
37+ local current_pc = cpu .state [" PC" ].value
38+ if current_pc == breakpointaddr and breakpoint_hit == false then
39+ emu .pause ()
40+ breakpoint_hit = true
41+ show_registers ()
42+ end
43+
44+ -- if breakpoint_hit == true and current_pc != breakpointaddr then
45+ -- breakpoint_hit = false
46+ -- end
47+ end
48+
49+
50+ function timer2 ()
51+ local cmd = get_command ()
52+
53+ if cmd == " PAUSE" then
54+ emu .pause ()
55+ show_registers ()
56+ else
57+ if cmd == nil then
58+ return
59+ end
60+ print (" UNKNOW COMMAD" )
61+ print (cmd )
62+ end
63+ end
64+
65+
66+ function get_command ()
67+ local f = io.open (" zxbs.tmp" ," r" )
68+ if not f then
69+ return nil
70+ end
71+ local content = f :read (" *a" )
72+ f :close ()
73+ os.remove (" zxbs.tmp" )
74+ return content
75+ end
76+
77+
78+ function show_registers ()
79+ local pc = cpu .state [" PC" ].value
80+ local af = cpu .state [" AF" ].value
81+ local bc = cpu .state [" BC" ].value
82+ local de = cpu .state [" DE" ].value
83+ local hl = cpu .state [" HL" ].value
84+ print (string.format (" BREAKPOINT PC:%04X AF:%04X BC:%04X DE:%04X HL:%04X" ,pc , af , bc , de , hl ))
85+ end
86+
87+ return exports
0 commit comments