Skip to content

Commit 7d97d7d

Browse files
author
none
committed
pep8, pycodestyle, requirements
1 parent db4aeb1 commit 7d97d7d

13 files changed

+271
-227
lines changed

TODO

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
Things to investigate / fix:
2+
3+
Tiny68k:
4+
☐ I2C realtime clock device
25

device.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ def map_registers(self, registers):
5656
if (regaddr in device._register_to_device):
5757
other = device._register_to_device[regaddr]
5858
if self != other:
59-
raise RuntimeError(
60-
'register at {} already assigned to {}'.format(regaddr, other._name))
59+
raise RuntimeError('register at {} already assigned to {}'.format(regaddr, other._name))
6160
device._register_to_device[regaddr] = self
6261
self._register_name_map[registers[reg]] = reg
6362

@@ -169,7 +168,7 @@ def cb_int(self, interrupt):
169168
dev._name, vector))
170169
return vector
171170
self.trace('no interrupting device')
172-
except:
171+
except Exception:
173172
self._emu.fatal_exception(sys.exc_info())
174173

175174
return M68K_IRQ_SPURIOUS
@@ -201,8 +200,7 @@ def cb_access(self, mode, width, address, value):
201200

202201
else:
203202
if self._trace_io:
204-
label = "{}:{}".format(
205-
dev._name, dev.get_register_name(offset).split('/')[-1])
203+
label = "{}:{}".format(dev._name, dev.get_register_name(offset).split('/')[-1])
206204
if width == device.WIDTH_8:
207205
str = '{} <- 0x{:02x}'.format(label, value)
208206
elif width == device.WIDTH_16:
@@ -223,8 +221,7 @@ def cb_access(self, mode, width, address, value):
223221
def add_device(self, args, dev, address=None, interrupt=None):
224222
if address is not None:
225223
if address < self._device_base:
226-
raise RuntimeError(
227-
'device cannot be registered at 0x{:x} (outside device space)'.format(address))
224+
raise RuntimeError('device cannot be registered at 0x{:x} (outside device space)'.format(address))
228225
mem_set_device(address)
229226
new_dev = dev(args=args, address=address, interrupt=interrupt)
230227
device._devices.append(new_dev)

deviceConsole.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def tick(self):
6666
for str in self._vt_screen.display:
6767
try:
6868
self._win.addstr(row, 0, str)
69-
except:
69+
except Exception:
7070
# XXX curses gets upset adding the last line - ignore it
7171
pass
7272
row += 1

deviceCF.py devices/CompactFlash.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class CompactFlash(device):
77
"""
8-
CompactFlash emulation
8+
Memory-mapped CompactFlash emulation.
99
1010
Reference: XT13/2008D
1111
"""
@@ -25,14 +25,14 @@ class CompactFlash(device):
2525
REG_COMMAND = 0x0f
2626

2727
_registers = {
28-
'DATA16' : 0x00,
29-
'DATA8' : 0x01,
28+
'DATA16': 0x00,
29+
'DATA8': 0x01,
3030
'ERROR/FEATURE': 0x03,
31-
'SECTOR_COUNT' : 0x05,
31+
'SECTOR_COUNT': 0x05,
3232
'SECTOR_NUMBER': 0x07,
33-
'CYLINDER_LOW' : 0x09,
33+
'CYLINDER_LOW': 0x09,
3434
'CYLINDER_HIGH': 0x0b,
35-
'DRIVE/HEAD' : 0x0d,
35+
'DRIVE/HEAD': 0x0d,
3636
'STATUS/COMMAND': 0x0f
3737
}
3838

deviceDUART.py devices/MC68681.py

+40-35
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ def _clock_scale_factor(self):
263263
return (self._parent.cycle_rate / 3.6) * self._prescale
264264

265265

266-
class DUART(device):
266+
class MC68681(device):
267+
"""
268+
Emulation of the MC68681 DUART / timer device.
269+
"""
267270

268271
# assuming the device is mapped to the low byte
269272

@@ -289,11 +292,11 @@ class DUART(device):
289292
REG_OPRCLR = 0x1f
290293

291294
_registers = {
292-
'MRA' : 0x01,
293-
'SRA/CSRA' : 0x03,
294-
'CRA' : 0x05,
295-
'RBA/TBA' : 0x07,
296-
'IPCR/ACR' : 0x09,
295+
'MRA': 0x01,
296+
'SRA/CSRA': 0x03,
297+
'CRA': 0x05,
298+
'RBA/TBA': 0x07,
299+
'IPCR/ACR': 0x09,
297300
'ISR/IMR': 0x0b,
298301
'CUR/CTUR': 0x0d,
299302
'CLR/CTLR': 0x0f,
@@ -307,9 +310,11 @@ class DUART(device):
307310
}
308311

309312
def __init__(self, args, address, interrupt):
310-
super(DUART, self).__init__(args=args, name='DUART', address=address,
311-
interrupt=interrupt)
312-
self.map_registers(DUART._registers)
313+
super(MC68681, self).__init__(args=args,
314+
name='MC68681',
315+
address=address,
316+
interrupt=interrupt)
317+
self.map_registers(MC68681._registers)
313318

314319
self._a = Channel(self)
315320
self._b = Channel(self)
@@ -320,36 +325,36 @@ def __init__(self, args, address, interrupt):
320325
device.root_device.register_console_input_driver(self._a)
321326

322327
def read(self, width, offset):
323-
regsel = offset & DUART.REG_SELMASK
324-
if regsel == DUART.REG_SEL_A:
325-
value = self._a.read(offset - DUART.REG_SEL_A)
328+
regsel = offset & MC68681.REG_SELMASK
329+
if regsel == MC68681.REG_SEL_A:
330+
value = self._a.read(offset - MC68681.REG_SEL_A)
326331

327-
elif regsel == DUART.REG_SEL_B:
328-
value = self._b.read(offset - DUART.REG_SEL_B)
332+
elif regsel == MC68681.REG_SEL_B:
333+
value = self._b.read(offset - MC68681.REG_SEL_B)
329334

330-
elif offset == DUART.REG_IPCR:
335+
elif offset == MC68681.REG_IPCR:
331336
value = 0x03 # CTSA/CTSB are always asserted
332337

333-
elif offset == DUART.REG_ISR:
338+
elif offset == MC68681.REG_ISR:
334339
value = self._isr
335340

336-
elif offset == DUART.REG_CUR:
341+
elif offset == MC68681.REG_CUR:
337342
value = self._counter.get_count() >> 8
338343

339-
elif offset == DUART.REG_CLR:
344+
elif offset == MC68681.REG_CLR:
340345
value = self._counter.get_count() & 0xff
341346

342-
elif offset == DUART.REG_IVR:
347+
elif offset == MC68681.REG_IVR:
343348
value = self._ivr
344349

345-
elif offset == DUART.REG_IPR:
350+
elif offset == MC68681.REG_IPR:
346351
value = 0x03 # CTSA/CTSB are always asserted
347352

348-
elif offset == DUART.REG_STARTCC:
353+
elif offset == MC68681.REG_STARTCC:
349354
self._counter.start()
350355
value = 0xff
351356

352-
elif offset == DUART.REG_STOPCC:
357+
elif offset == MC68681.REG_STOPCC:
353358
self._counter.stop()
354359
value = 0xff
355360

@@ -360,34 +365,34 @@ def read(self, width, offset):
360365
return value
361366

362367
def write(self, width, offset, value):
363-
regsel = offset & DUART.REG_SELMASK
364-
if regsel == DUART.REG_SEL_A:
365-
self._a.write(offset - DUART.REG_SEL_A, value)
368+
regsel = offset & MC68681.REG_SELMASK
369+
if regsel == MC68681.REG_SEL_A:
370+
self._a.write(offset - MC68681.REG_SEL_A, value)
366371

367-
elif regsel == DUART.REG_SEL_B:
368-
self._b.write(offset - DUART.REG_SEL_B, value)
372+
elif regsel == MC68681.REG_SEL_B:
373+
self._b.write(offset - MC68681.REG_SEL_B, value)
369374

370-
elif offset == DUART.REG_ACR:
375+
elif offset == MC68681.REG_ACR:
371376
self._counter.set_mode(value)
372377

373-
elif offset == DUART.REG_IMR:
378+
elif offset == MC68681.REG_IMR:
374379
self._imr = value
375380
# XXX interrupt status may have changed...
376381

377-
elif offset == DUART.REG_CTUR:
382+
elif offset == MC68681.REG_CTUR:
378383
self._counter.set_reload_high(value)
379384

380-
elif offset == DUART.REG_CTLR:
385+
elif offset == MC68681.REG_CTLR:
381386
self._counter.set_reload_low(value)
382387

383-
elif offset == DUART.REG_IVR:
388+
elif offset == MC68681.REG_IVR:
384389
self._ivr = value
385390

386-
elif offset == DUART.REG_OPCR:
391+
elif offset == MC68681.REG_OPCR:
387392
pass
388-
elif offset == DUART.REG_OPRSET:
393+
elif offset == MC68681.REG_OPRSET:
389394
pass
390-
elif offset == DUART.REG_OPRCLR:
395+
elif offset == MC68681.REG_OPRCLR:
391396
pass
392397
else:
393398
raise RuntimeError('write to 0x{:02x} not handled'.format(offset))

emulator.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def __init__(self, args, memory_size):
137137
def loadImage(self, image_filename):
138138
try:
139139
suffix = image_filename.split('.')[1].lower()
140-
except:
140+
except Exception:
141141
raise RuntimeError(f"image filename '{image_filename}' must have an extension")
142142

143143
if suffix == "elf":
@@ -328,7 +328,7 @@ def cb_trace_memory(self, mode, width, addr, value):
328328
info = '{:#010x}'.format(value)
329329

330330
self.trace(direction, addr, info)
331-
except:
331+
except Exception:
332332
self.fatal_exception(sys.exc_info())
333333

334334
return 0
@@ -353,7 +353,7 @@ def cb_trace_instruction(self):
353353

354354
self.trace('EXECUTE', pc, '{:30} {}'.format(dis, info))
355355
return
356-
except:
356+
except Exception:
357357
self.fatal_exception(sys.exc_info())
358358

359359
def cb_trace_reset(self):
@@ -366,7 +366,7 @@ def cb_trace_reset(self):
366366
# devices must reset
367367
try:
368368
self._root_device.reset()
369-
except:
369+
except Exception:
370370
self.fatal_exception(sys.exc_info())
371371

372372
def cb_trace_jump(self, new_pc, vector):
@@ -383,7 +383,7 @@ def cb_trace_jump(self, new_pc, vector):
383383
ppc = get_reg(M68K_REG_PPC)
384384
self.trace('EXCEPTION', ppc, 'vector {:#x} to {}'.format(
385385
vector, self._image.lineinfo(new_pc)))
386-
except:
386+
except Exception:
387387
self.fatal_exception(sys.exc_info())
388388

389389
def _keyboard_interrupt(self, signal=None, frame=None):
@@ -427,4 +427,4 @@ def fatal_info(self):
427427
else:
428428
result += 'no reason'
429429

430-
return result
430+
return result

imageELF.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def symrange(self, name):
158158
try:
159159
addr = int(name)
160160
size = 1
161-
except:
161+
except Exception:
162162
raise RuntimeError(
163163
'can\'t find a symbol called {} and can\'t convert it to an address'.format(name))
164164

0 commit comments

Comments
 (0)