tangled
alpha
login
or
join now
jcs.org
/
pce
0
fork
atom
fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
0
fork
atom
overview
issues
pulls
pipelines
spectrum: Add the 'last' command
Hampa Hug
6 months ago
09453d2e
ac1113db
+125
-4
2 changed files
expand all
collapse all
unified
split
src
arch
spectrum
cmd.c
spectrum.h
+118
-3
src/arch/spectrum/cmd.c
···
42
42
{ "g", "", "run" },
43
43
{ "hm", "", "print help on messages" },
44
44
{ "i", "port", "input a byte from a port" },
45
45
+
{ "last", "on|off", "start/stop recording pc values" },
46
46
+
{ "last", "[cnt [idx]]", "print last pc values [80 0]" },
45
47
{ "n", "[0|1]", "execute to next instruction" },
46
48
{ "o", "port val", "output a byte to a port" },
47
49
{ "p", "[cnt]", "execute cnt instructions, skip calls [1]" },
···
52
54
{ "xl", "fname", "load a snapshot" },
53
55
{ "xs", "fname", "save a snapshot" }
54
56
};
57
57
+
58
58
+
59
59
+
void spec_last_set (spectrum_t *sim, unsigned pc);
55
60
56
61
57
62
static
···
437
442
pce_stop();
438
443
}
439
444
445
445
+
static
446
446
+
int spec_hook_exec (void *ext)
447
447
+
{
448
448
+
spectrum_t *sim = ext;
449
449
+
450
450
+
spec_last_set (sim, e8080_get_pc (sim->cpu));
451
451
+
452
452
+
return (0);
453
453
+
}
440
454
441
455
static
442
456
int spec_hook_undef (void *ext, unsigned op)
443
457
{
444
444
-
spectrum_t *sim;
445
445
-
446
446
-
sim = ext;
458
458
+
spectrum_t *sim = ext;
447
459
448
460
pce_log (MSG_DEB,
449
461
"%04X: undefined operation [%02X %02X %02X %02X]\n",
···
465
477
return (0);
466
478
}
467
479
480
480
+
void spec_last_enable (spectrum_t *sim, int enable)
481
481
+
{
482
482
+
unsigned i;
483
483
+
484
484
+
enable = (enable != 0);
485
485
+
486
486
+
if (sim->last_enabled == enable) {
487
487
+
return;
488
488
+
}
489
489
+
490
490
+
sim->last_enabled = enable;
491
491
+
sim->last_idx = 0;
492
492
+
493
493
+
for (i = 0; i < SPEC_LAST_CNT; i++) {
494
494
+
sim->last[i] = 0;
495
495
+
}
496
496
+
497
497
+
if (sim->last_enabled) {
498
498
+
e8080_set_hook_exec_fct (sim->cpu, sim, spec_hook_exec);
499
499
+
}
500
500
+
else {
501
501
+
e8080_set_hook_exec_fct (sim->cpu, NULL, NULL);
502
502
+
}
503
503
+
}
504
504
+
505
505
+
unsigned spec_last_get (spectrum_t *sim, unsigned idx)
506
506
+
{
507
507
+
if (sim->last_enabled == 0) {
508
508
+
return (0);
509
509
+
}
510
510
+
511
511
+
if (idx == 0) {
512
512
+
return (e8080_get_pc (sim->cpu));
513
513
+
}
514
514
+
515
515
+
if (idx > SPEC_LAST_CNT) {
516
516
+
return (0);
517
517
+
}
518
518
+
519
519
+
idx = (sim->last_idx + SPEC_LAST_CNT - (idx - 1)) % SPEC_LAST_CNT;
520
520
+
521
521
+
return (sim->last[idx]);
522
522
+
}
523
523
+
524
524
+
void spec_last_set (spectrum_t *sim, unsigned pc)
525
525
+
{
526
526
+
if (sim->last[sim->last_idx] == pc) {
527
527
+
return;
528
528
+
}
529
529
+
530
530
+
sim->last_idx = (sim->last_idx + 1) % SPEC_LAST_CNT;
531
531
+
sim->last[sim->last_idx] = pc;
532
532
+
}
468
533
469
534
static
470
535
void spec_cmd_c (cmd_t *cmd, spectrum_t *sim)
···
573
638
}
574
639
575
640
cmd_match_end (cmd);
641
641
+
}
642
642
+
643
643
+
static
644
644
+
void spec_cmd_last (cmd_t *cmd, spectrum_t *sim)
645
645
+
{
646
646
+
unsigned i, j, k;
647
647
+
unsigned col, pc;
648
648
+
unsigned short idx, cnt;
649
649
+
650
650
+
if (cmd_match (cmd, "on")) {
651
651
+
spec_last_enable (sim, 1);
652
652
+
cmd_match_end (cmd);
653
653
+
return;
654
654
+
}
655
655
+
656
656
+
if (cmd_match (cmd, "off")) {
657
657
+
spec_last_enable (sim, 0);
658
658
+
cmd_match_end (cmd);
659
659
+
return;
660
660
+
}
661
661
+
662
662
+
if (sim->last_enabled == 0) {
663
663
+
return;
664
664
+
}
665
665
+
666
666
+
col = 8;
667
667
+
cnt = 128;
668
668
+
idx = 0;
669
669
+
670
670
+
cmd_match_uint16 (cmd, &cnt);
671
671
+
cmd_match_uint16 (cmd, &idx);
672
672
+
673
673
+
if (!cmd_match_end (cmd)) {
674
674
+
return;
675
675
+
}
676
676
+
677
677
+
cnt = (cnt + col - 1) / col;
678
678
+
679
679
+
for (i = cnt; i > 0; i--) {
680
680
+
for (j = col; j > 0; j--) {
681
681
+
k = idx + (j - 1) * cnt + i - 1;
682
682
+
pc = spec_last_get (sim, k);
683
683
+
pce_printf (" %04X", pc);
684
684
+
}
685
685
+
pce_putc ('\n');
686
686
+
}
576
687
}
577
688
578
689
static
···
941
1052
else if (cmd_match (cmd, "i")) {
942
1053
spec_cmd_i (cmd, sim);
943
1054
}
1055
1055
+
else if (cmd_match (cmd, "last")) {
1056
1056
+
spec_cmd_last (cmd, sim);
1057
1057
+
}
944
1058
else if (cmd_match (cmd, "n")) {
945
1059
spec_cmd_n (cmd, sim);
946
1060
}
···
977
1091
mon_cmd_add (mon, par_cmd, sizeof (par_cmd) / sizeof (par_cmd[0]));
978
1092
mon_cmd_add_bp (mon);
979
1093
1094
1094
+
e8080_set_hook_exec_fct (sim->cpu, NULL, NULL);
980
1095
e8080_set_hook_undef_fct (sim->cpu, sim, spec_hook_undef);
981
1096
e8080_set_hook_rst_fct (sim->cpu, sim, spec_hook_rst);
982
1097
}
+7
-1
src/arch/spectrum/spectrum.h
···
5
5
/*****************************************************************************
6
6
* File name: src/arch/spectrum/spectrum.h *
7
7
* Created: 2021-11-28 by Hampa Hug <hampa@hampa.ch> *
8
8
-
* Copyright: (C) 2021-2024 Hampa Hug <hampa@hampa.ch> *
8
8
+
* Copyright: (C) 2021-2025 Hampa Hug <hampa@hampa.ch> *
9
9
*****************************************************************************/
10
10
11
11
/*****************************************************************************
···
49
49
50
50
#define SPEC_MODEL_16 1
51
51
#define SPEC_MODEL_48 2
52
52
+
53
53
+
#define SPEC_LAST_CNT 256
52
54
53
55
54
56
/*****************************************************************************
···
92
94
unsigned speed;
93
95
94
96
unsigned brk;
97
97
+
98
98
+
char last_enabled;
99
99
+
unsigned last_idx;
100
100
+
unsigned short last[SPEC_LAST_CNT];
95
101
} spectrum_t;
96
102
97
103