Skip to content

Commit dae10e6

Browse files
committed
Remove 'accel_dec_a' and 'list_accelerators' from LoadTracer.state
1 parent 176e4ae commit dae10e6

File tree

2 files changed

+41
-27
lines changed

2 files changed

+41
-27
lines changed

c/csimulator.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5791,7 +5791,7 @@ static void dec_a(CSimulatorObject* self, void* lookup, int args[]) {
57915791

57925792
unsigned pc = REG(PC);
57935793
if (REG(IFF) == 0) {
5794-
if (self->tracer_state[5] & 1 && PEEK(ADDR(pc + 1)) == 0x20 && PEEK(ADDR(pc + 2)) == 0xFD) {
5794+
if (args[3] && PEEK(ADDR(pc + 1)) == 0x20 && PEEK(ADDR(pc + 2)) == 0xFD) {
57955795
args[0]++;
57965796
unsigned a = REG(A) ? REG(A) : 256;
57975797
LD(A, 0);
@@ -5802,7 +5802,7 @@ static void dec_a(CSimulatorObject* self, void* lookup, int args[]) {
58025802
return;
58035803
}
58045804

5805-
if (self->tracer_state[5] & 2 && PEEK(ADDR(pc + 1)) == 0xC2 && PEEK(ADDR(pc + 2)) == pc % 256 && PEEK(ADDR(pc + 3)) == pc / 256) {
5805+
if (args[4] && PEEK(ADDR(pc + 1)) == 0xC2 && PEEK(ADDR(pc + 2)) == pc % 256 && PEEK(ADDR(pc + 3)) == pc / 256) {
58065806
args[1]++;
58075807
unsigned a = REG(A) ? REG(A) : 256;
58085808
LD(A, 0);
@@ -5904,10 +5904,10 @@ static unsigned read_port(CSimulatorObject* self, unsigned port) {
59045904
if ((port & 0xFF) == 0xFE) {
59055905
unsigned pc = REG(PC);
59065906
if (pc >= self->in_min_addr || (pc >= 0x0562 && pc <= 0x05F1 && self->out7ffd & 0x10)) {
5907-
self->tracer_state[7] = 1; // Signal: custom loader detected
5907+
self->tracer_state[5] = 1; // Signal: custom loader detected
59085908
unsigned long long index = self->tracer_state[1];
5909-
if (self->tracer_state[9] && !self->tracer_state[2]) {
5910-
self->tracer_state[9] = 0; // Signal: data block announced
5909+
if (self->tracer_state[7] && !self->tracer_state[2]) {
5910+
self->tracer_state[7] = 0; // Signal: data block announced
59115911
self->tracer_state[4] = 1; // Signal: tape is running
59125912
TIME = self->tape_edges[index];
59135913
PyObject* blocks_obj = PyObject_GetAttrString(self->tracer, "blocks");
@@ -6062,8 +6062,24 @@ static PyObject* CSimulator_load(CSimulatorObject* self, PyObject* args, PyObjec
60626062
self->opcodes[i] = &opcodes[i];
60636063
}
60646064
#ifndef CONTENTION
6065+
PyObject* list_acc_obj = ok ? PyObject_GetAttrString(self->tracer, "list_accelerators") : NULL;
6066+
int list_accelerators = list_acc_obj ? PyObject_IsTrue(list_acc_obj) > 0 : 0;
6067+
if (list_acc_obj == NULL) {
6068+
ok = 0;
6069+
}
6070+
Py_XDECREF(list_acc_obj);
6071+
6072+
PyObject* accel_dec_a_obj = ok ? PyObject_GetAttrString(self->tracer, "accel_dec_a") : NULL;
6073+
long accel_dec_a = accel_dec_a_obj ? PyLong_AsLong(accel_dec_a_obj) : 0;
6074+
if (accel_dec_a_obj == NULL || (accel_dec_a == -1 && PyErr_Occurred())) {
6075+
ok = 0;
6076+
}
6077+
Py_XDECREF(accel_dec_a_obj);
6078+
60656079
OpcodeFunction dec_a_accelerator = {dec_a, NULL, {0}};
6066-
if (self->tracer_state[5]) {
6080+
if (accel_dec_a) {
6081+
dec_a_accelerator.args[3] = accel_dec_a & 1; // DEC A: JR NZ,$-1
6082+
dec_a_accelerator.args[4] = accel_dec_a & 2; // DEC A: JP NZ,$-1
60676083
self->opcodes[0x3D] = &dec_a_accelerator;
60686084
}
60696085

@@ -6211,7 +6227,7 @@ static PyObject* CSimulator_load(CSimulatorObject* self, PyObject* args, PyObjec
62116227
}
62126228
if (!did_fast_load) {
62136229
if (end_of_tape && stop == 0x10000) {
6214-
if (self->tracer_state[7]) {
6230+
if (self->tracer_state[5]) {
62156231
/* Custom loader was detected */
62166232
rv = PyLong_FromLong(1);
62176233
break;
@@ -6221,7 +6237,7 @@ static PyObject* CSimulator_load(CSimulatorObject* self, PyObject* args, PyObjec
62216237
rv = PyLong_FromLong(2);
62226238
break;
62236239
}
6224-
if (TIME - self->tracer_state[8] > 3500000) {
6240+
if (TIME - self->tracer_state[6] > 3500000) {
62256241
/* Tape ended 1 second ago */
62266242
rv = PyLong_FromLong(3);
62276243
break;
@@ -6235,7 +6251,7 @@ static PyObject* CSimulator_load(CSimulatorObject* self, PyObject* args, PyObjec
62356251
}
62366252

62376253
#ifndef CONTENTION
6238-
if (rv && self->tracer_state[6] && accelerators && accs && num_accs) {
6254+
if (rv && list_accelerators && accelerators && accs && num_accs) {
62396255
PyObject* iter = PyObject_GetIter(accelerators);
62406256
if (iter) {
62416257
PyObject* item;

skoolkit/loadtracer.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,12 @@ def __init__(self, simulator, blocks, config):
196196
self.pause = config['pause']
197197
self.in_min_addr = config['in_min_addr']
198198
self.accelerators = config['accelerators']
199-
accel_dec_a = config['accelerate_dec_a']
200-
if hasattr(simulator, 'opcodes') and accel_dec_a:
201-
dec_a_jr = accel_dec_a & 1
202-
dec_a_jp = accel_dec_a & 2
199+
self.accel_dec_a = config['accelerate_dec_a']
200+
if hasattr(simulator, 'opcodes') and self.accel_dec_a:
201+
dec_a_jr = self.accel_dec_a & 1
202+
dec_a_jp = self.accel_dec_a & 2
203203
simulator.opcodes[0x3D] = partial(self.dec_a, dec_a_jr, dec_a_jp, simulator.registers, simulator.memory)
204-
list_accelerators = config['list_accelerators']
204+
self.list_accelerators = config['list_accelerators']
205205
self.block_index = 0
206206
self.block_data_index = self.blocks[0].start
207207
self.max_index = len(self.edges) - 1
@@ -221,11 +221,9 @@ def __init__(self, simulator, blocks, config):
221221
0, # state[2]: end of tape reached
222222
self.blocks[0].end, # state[3]: index of final edge in current block
223223
0, # state[4]: tape running
224-
accel_dec_a, # state[5]
225-
list_accelerators, # state[6]
226-
0, # state[7]: custom loader detected
227-
0, # state[8]: tape end time
228-
1, # state[9]: data block not yet announced
224+
0, # state[5]: custom loader detected
225+
0, # state[6]: tape end time
226+
1, # state[7]: data block not yet announced
229227
]
230228
if hasattr(simulator, 'load'): # pragma: no cover
231229
self.edges = array.array('Q', self.edges)
@@ -335,15 +333,15 @@ def run(self, border, out7ffd, outfffd, ay, outfe):
335333
else:
336334
if state[2] and stop is None:
337335
# The tape has ended and no stop address is set
338-
if state[7]:
336+
if state[5]:
339337
# Custom loader was detected
340338
stop_cond = 1
341339
break
342340
if pc > 0x3FFF:
343341
# PC in RAM
344342
stop_cond = 2
345343
break
346-
if tstates - self.state[8] > 3500000: # pragma: no cover
344+
if tstates - self.state[6] > 3500000: # pragma: no cover
347345
# Tape ended 1 second ago
348346
stop_cond = 3
349347
break
@@ -403,10 +401,10 @@ def _read_port(self, state, accelerators, memory, registers, port):
403401
if port % 256 == 0xFE:
404402
pc = registers[24]
405403
if pc >= self.in_min_addr or (0x0562 <= pc <= 0x05F1 and self.out7ffd & 0x10):
406-
state[7] = 1 # Signal: custom loader detected
404+
state[5] = 1 # Signal: custom loader detected
407405
index = state[1]
408-
if state[9] and not state[2]:
409-
state[9] = 0 # Signal: data block announced
406+
if state[7] and not state[2]:
407+
state[7] = 0 # Signal: data block announced
410408
state[4] = 1 # Signal: tape is running
411409
registers[T] = self.edges[index]
412410
length = len(self.blocks[self.block_index].data)
@@ -479,14 +477,14 @@ def next_block(self, tstates):
479477
self.keys = block.keys
480478
self.state[3] = self.blocks[self.block_index].end
481479
self.state[4] = int(not self.pause) # Pause tape unless configured not to
482-
self.state[9] = 1 # Signal: data block not yet announced
480+
self.state[7] = 1 # Signal: data block not yet announced
483481

484482
def stop_tape(self, tstates):
485483
self.block_index = len(self.blocks)
486484
self.state[2] += 1 # Signal: end of tape reached
487485
if self.state[2] == 1:
488486
write_line('Tape finished')
489-
self.state[8] = tstates # Set tape end time
487+
self.state[6] = tstates # Set tape end time
490488
self.state[4] = 0 # Signal: tape is not running
491489

492490
def fast_load(self, simulator):
@@ -574,5 +572,5 @@ def fast_load(self, simulator):
574572
registers[E] = de & 0xFF
575573

576574
registers[PC] = 0x05E2
577-
self.state[9] = 0 # Signal: data block announced
575+
self.state[7] = 0 # Signal: data block announced
578576
return True

0 commit comments

Comments
 (0)