Skip to content

Commit 5d63bc6

Browse files
committed
Add debug adapter for MAME colecovision gdbserver
1 parent 7a2dac8 commit 5d63bc6

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

mame_coleco.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env python3
2+
3+
# packets supported by MAME stub
4+
# https://github.com/mamedev/mame/blob/master/src/osd/modules/debugger/debuggdbstub.cpp
5+
# ! -
6+
# ? get last stop reason
7+
# c continue
8+
# D detach
9+
# g read general registers
10+
# G write general registers
11+
# H set thread for step,continue,others
12+
# i do one clock cycle
13+
# I signal, then cycle step
14+
# k kill process
15+
# m read mem
16+
# M write mem
17+
# p read reg
18+
# P write reg
19+
# q general query
20+
# s single step
21+
# z remove breakpoint
22+
# Z add breakpoint
23+
#
24+
25+
import os
26+
import re
27+
import shutil
28+
import socket
29+
import subprocess
30+
from struct import pack, unpack
31+
32+
from . import rsp
33+
from . import utils
34+
from . import gdblike
35+
from . import DebugAdapter
36+
37+
class DebugAdapterMameColeco(gdblike.DebugAdapterGdbLike):
38+
def __init__(self, **kwargs):
39+
gdblike.DebugAdapterGdbLike.__init__(self, **kwargs)
40+
41+
self.rsp = None
42+
43+
self.module_cache = {}
44+
45+
#--------------------------------------------------------------------------
46+
# API
47+
#--------------------------------------------------------------------------
48+
49+
def exec(self, path, args=[]):
50+
raise NotImplementedError('no execute, connect to listening MAME process')
51+
52+
def connect_continued(self, sock,connection):
53+
self.sock = sock
54+
self.rspConn = connection
55+
56+
self.reg_info_load()
57+
58+
# no pid, not tid
59+
self.tid = 0
60+
self.target_pid_ = 0
61+
62+
def mem_modules(self, cache_ok=True):
63+
raise NotImplementedError('no module list on ColecoVision')
64+
65+
def go(self):
66+
self.reg_cache = {}
67+
(reason, reason_data) = self.go_generic('c')
68+
self.handle_stop(reason, reason_data)
69+
return (reason, reason_data)
70+
71+
def step_into(self):
72+
self.reg_cache = {}
73+
(reason, reason_data) = self.go_generic('s')
74+
self.handle_stop(reason, reason_data)
75+
return (reason, reason_data)
76+
77+
# thread stuff
78+
def thread_list(self):
79+
return [0]
80+
81+
def thread_selected(self):
82+
return 0
83+
84+
def thread_select(self, tid):
85+
if tid != 0:
86+
raise DebugAdapter.GeneralError('mame_coleco has only one implicit thread: 0')
87+
88+
#
89+
def thread_stop_pkt_to_reason(self, pkt_data):
90+
''' callback: given the stop packet data in the form of a "TDICT", return
91+
a (reason, extra_data) tuple '''
92+
# pkt_data eg: {'signal': 5, 'r10': 29625, 'r11': 3}
93+
if pkt_data.get('signal', -1) == 5:
94+
return (DebugAdapter.STOP_REASON.SINGLE_STEP, None)
95+
else:
96+
return (DebugAdapter.STOP_REASON.UNKNOWN, None)
97+

0 commit comments

Comments
 (0)