CPC X-Ray 0.9.0 (beta) - a CPC emulator for code analysis (AI-coded)

Hi all,

as some might recall I am still working on a complete disassembly and commentation of the Vortext F1-X Module Rom (V 2.11-X). It is not an easy task without an running CPU really executing code. So I now used some 3 days to create my own tool with the help of Claude.

I’d like to introduce CPC X-Ray, an open-source tool (GPL-3.0) I have been building to take apart CPC code: ROMs, programs, anything that runs on a 464, 664 or 6128.

What it is for

CPC X-Ray is an analysis tool that happens to contain an emulator, not the other way round. Its job is to help you disassemble and understand existing code and turn it into a commented sjasmplus source that assembles back to the original bytes - checked byte for byte. It runs the real firmware, BASIC, AMSDOS and expansion ROMs and lets you watch everything the code does:

  • Breakpoints of ten types - PC, M1, memory read/write/access, I/O in/out, ROM select, interrupt - with ranges, port masks and paging conditions
  • An instruction trace with call depth and changed registers, so after a stop you can go back and see how the code got there
  • A bus trace of every access (M1, read, write, I/O), explained: which firmware variable was touched, what was pushed to the stack, what a port write does
  • Memory views coloured by the firmware and AMSDOS variables, the paging, the stack, firmware names for all three machines
  • An analysis of a ROM or RAM range: code vs. data, code copied to RAM and run there, RST calls with inline data - which becomes the source
  • Decoding of scrambled ROMs (the Vortex X-module scheme, where opcode fetches and data reads are decoded differently)

It also has an MCP server, so Claude Code (Anthropic’s AI coding assistant) can drive the whole machine: boot it, type, set breakpoints, step, read memory and traces and run the analysis. In practice you work through a ROM together - it watches what the code really does at run time and helps you name routines and variables and write the comments.

What it is not

It is not a general-purpose emulator, and it is not trying to compete with WinAPE, ACE, CPCEC and friends - use those to play games and run demos. CPC X-Ray deliberately cuts corners wherever they don’t matter for code analysis:

  • The Z80 is instruction-level: every bus access in the right order with the right signals, and it passes ZEXALL and the 1.6 M SingleStepTests - but there are no T-states inside an instruction
  • The CRTC is just its registers, with no raster timing; interrupt and VSYNC follow a simplified model
  • No sound, no cassette, no printer; the PPI/PSG are only what the keyboard and VSYNC need
  • It runs at about real time - slower with the analysis and traces switched on

The firmware, BASIC, AMSDOS and disk access all work. Raster tricks, mid-line splits and anything that relies on exact cycle timing do not, and that won’t change - it’s a design decision, not a to-do list.

Getting it

Release 0.9.0 (beta) has a Python package and ready-made programs for Windows and Linux; the standard Amstrad ROMs are included:

The code is complete for what I planned for 1.0; what it needs now is real-world use. Feedback, bug reports and ideas are very welcome - here or on the GitHub issue tracker.

Okay use it for what it is - but do not think it is any competition to any other emulator, as it has not implemented a lot of the hardware - not even the CRTC or gatearray.

For instance the screen is not rendered by the Gatearray it is rendered by a renderer that just reads the screen ram and puts it into a normal RGB frame so that it can be displayed.

8 Likes

Ah, and if anyone asks - it will 100% not run any demo :wink:

2 Likes

Great idea! Hope you keep developing it!

I have update it to version v0.9.4

Fixed a lot of logical errors and bugs…

New: a RAM comment can have a group without a label (comment_add(address, text, group=...), the Symbols tab’s editor; BF03 - group=vdos ; text in annotations.txt). Where
several programs are copied to the same RAM (VDOS: the HELLO loader and the two |ROMCAT
helpers at &BF00), each copy shows only the comments and comment blocks of its context’s
group, else the ungrouped ones - in the generated source, the CPU tab and the Trace tab.

  • Changed: in the generated source, a RAM copy whose origin has a context no longer takes a
    label of another group: its lines get the label of the context’s group, else the ungrouped
    one, else the generator’s own ram_xxxx_yyyy name (no more rre_skip_name_2 from the other
    |ROMCAT helper). Code outside such copies names RAM addresses as before.
  • symbols_load says in its description that it merges the file into what is loaded.
  • Fixed: a RAM copy of ROM code is no longer forgotten when another program overwrites it. The
    analysis kept only the copies still in RAM, so after running BASIC the source lost the DISP
    blocks of the copies CP/M had made at the same addresses (VDOS: &BE80 and &AC00 beside
    BASIC’s &BE8F), and a leftover fragment could replace a saved copy. Every copy seen is now
    kept with its own execution count and saved; fragments join their copy. Copies lost before
    come back the next time the program that makes them runs.
  • New: comment blocks before and after a line - a routine header above it, a longer explanation
    below it, several lines each - besides the comment at the end of the line. Edit them in the
    Symbols tab or with symbol_add / comment_add over MCP; the CPU tab shows them, the Trace
    tab marks them (¶) and shows them for the selected instruction, and the generated source
    writes them as comment lines (still byte-identical). They are kept in
    project/annotations.txt as before / after lines; older files load unchanged.
  • New: say what an instruction’s operand is - right-click it in the CPU tab, or operand_set
    over MCP: a number (always hex, call #0010 instead of call SIDE_CALL), an address (named),
    or judged by cpcxray again. The decision is kept in project/annotations.txt and holds in
    the disassembly, the trace and the generated source.
  • New: groups for your variables and RAM labels, and code contexts - for programs that use the
    same RAM differently (VDOS and CP/M, for example). Put variables and global labels in groups
    (Symbols tab: Groups panel, or group_add / variable_add(group=) / symbol_add(group=)),
    give code a context (CPU tab: right-click a line’s address - from/to, this routine, whole
    scope; or context_set), and every listing, the trace and the generated source name an
    address by the context of the code that uses it. One RAM address can have a label per group.
    The generated source defines the names in one section per group (still byte-identical). Kept
    in project/annotations.txt (group, context, group=); older files load unchanged.
  • New: symbol_add(..., group=, replaces=<old group>) moves a RAM label to another group in one
    step, with its type, comment and comment blocks (as variable_add(replaces=) does for
    variables); the Symbols tab’s editor uses it.
  • Changed: the firmware’s jumpblock and restart names are fixed - a label of yours on such an
    address is refused (a comment is fine); an older annotation file with one loads without it
    and the Symbols tab’s status says so.

Analysis and source

  • New: the data kind word_data (classify) for words that are numbers - parameters,
    offsets, time constants. They are always written in hex: a parameter &0010 no longer turns
    into defw SIDE_CALL (the name of RST 2), as it did in a word_table, whose words are
    addresses and keep their names. Existing analysis databases stay valid.
  • Fixed: the generated source no longer labels the target of a FAR CALL into another ROM in
    the analysed ROM (VDOS: rst #18 to &C1DC in ROM 7 made a sub_c1dc in ROM 5), nor that of
    a SIDE CALL to another slot; the far address stays defw #C1DC ; ROM 7.

The machine

  • Fixed: BASIC could hang in MC WAIT FLYBACK (for example after a disc LOAD). The 300 Hz
    interrupt now follows the Gate Array’s real line counter (R52): the first interrupt of a frame
    comes 2 scan lines into VSYNC, and the phase is resynchronised every frame, also after an RMR
    bit 4 write or a snapshot load. The Devices tab shows the frame line next to R52. Emulation
    is slightly faster as a side effect.
  • Fixed: no drop-down list in the window could be opened - for example the slot of a new ROM in
    the Project tab’s machine editor, the decoder of a ROM, or the view of the Memory tab
    (cpu, ram, ROMs, raw / decoded ROM). Taking the keyboard back for the CPC closed the list at
    once; now the window leaves the keys alone while a list is open and gives them back to the
    CPC right after the choice.

I have now used it to complete the full decoding and disassembly of the Vortex VDOS 2.11-X rom. All of the bugs I found during that endeavour have been fixed.

So now it is deamed ready.

If anyone want additional features, please let me know.

2 Likes