fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation

spectrum: Add the 'last' command

Hampa Hug 09453d2e ac1113db

+125 -4
+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 + { "last", "on|off", "start/stop recording pc values" }, 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 + 58 + 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 + static 446 + int spec_hook_exec (void *ext) 447 + { 448 + spectrum_t *sim = ext; 449 + 450 + spec_last_set (sim, e8080_get_pc (sim->cpu)); 451 + 452 + return (0); 453 + } 440 454 441 455 static 442 456 int spec_hook_undef (void *ext, unsigned op) 443 457 { 444 - spectrum_t *sim; 445 - 446 - sim = ext; 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 + void spec_last_enable (spectrum_t *sim, int enable) 481 + { 482 + unsigned i; 483 + 484 + enable = (enable != 0); 485 + 486 + if (sim->last_enabled == enable) { 487 + return; 488 + } 489 + 490 + sim->last_enabled = enable; 491 + sim->last_idx = 0; 492 + 493 + for (i = 0; i < SPEC_LAST_CNT; i++) { 494 + sim->last[i] = 0; 495 + } 496 + 497 + if (sim->last_enabled) { 498 + e8080_set_hook_exec_fct (sim->cpu, sim, spec_hook_exec); 499 + } 500 + else { 501 + e8080_set_hook_exec_fct (sim->cpu, NULL, NULL); 502 + } 503 + } 504 + 505 + unsigned spec_last_get (spectrum_t *sim, unsigned idx) 506 + { 507 + if (sim->last_enabled == 0) { 508 + return (0); 509 + } 510 + 511 + if (idx == 0) { 512 + return (e8080_get_pc (sim->cpu)); 513 + } 514 + 515 + if (idx > SPEC_LAST_CNT) { 516 + return (0); 517 + } 518 + 519 + idx = (sim->last_idx + SPEC_LAST_CNT - (idx - 1)) % SPEC_LAST_CNT; 520 + 521 + return (sim->last[idx]); 522 + } 523 + 524 + void spec_last_set (spectrum_t *sim, unsigned pc) 525 + { 526 + if (sim->last[sim->last_idx] == pc) { 527 + return; 528 + } 529 + 530 + sim->last_idx = (sim->last_idx + 1) % SPEC_LAST_CNT; 531 + sim->last[sim->last_idx] = pc; 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 + } 642 + 643 + static 644 + void spec_cmd_last (cmd_t *cmd, spectrum_t *sim) 645 + { 646 + unsigned i, j, k; 647 + unsigned col, pc; 648 + unsigned short idx, cnt; 649 + 650 + if (cmd_match (cmd, "on")) { 651 + spec_last_enable (sim, 1); 652 + cmd_match_end (cmd); 653 + return; 654 + } 655 + 656 + if (cmd_match (cmd, "off")) { 657 + spec_last_enable (sim, 0); 658 + cmd_match_end (cmd); 659 + return; 660 + } 661 + 662 + if (sim->last_enabled == 0) { 663 + return; 664 + } 665 + 666 + col = 8; 667 + cnt = 128; 668 + idx = 0; 669 + 670 + cmd_match_uint16 (cmd, &cnt); 671 + cmd_match_uint16 (cmd, &idx); 672 + 673 + if (!cmd_match_end (cmd)) { 674 + return; 675 + } 676 + 677 + cnt = (cnt + col - 1) / col; 678 + 679 + for (i = cnt; i > 0; i--) { 680 + for (j = col; j > 0; j--) { 681 + k = idx + (j - 1) * cnt + i - 1; 682 + pc = spec_last_get (sim, k); 683 + pce_printf (" %04X", pc); 684 + } 685 + pce_putc ('\n'); 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 + else if (cmd_match (cmd, "last")) { 1056 + spec_cmd_last (cmd, sim); 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 + 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 - * Copyright: (C) 2021-2024 Hampa Hug <hampa@hampa.ch> * 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 + 53 + #define SPEC_LAST_CNT 256 52 54 53 55 54 56 /***************************************************************************** ··· 92 94 unsigned speed; 93 95 94 96 unsigned brk; 97 + 98 + char last_enabled; 99 + unsigned last_idx; 100 + unsigned short last[SPEC_LAST_CNT]; 95 101 } spectrum_t; 96 102 97 103