BartmanAbyss / vscode-amiga-debug

One-stop Visual Studio Code Extension to compile, debug and profile Amiga C/C++ programs compiled by the bundled gcc 12.2 with the bundled WinUAE/FS-UAE.
GNU General Public License v3.0
316 stars 39 forks source link

New CPU cycle count implementation with improved accuracy #179

Closed grahambates closed 1 year ago

grahambates commented 1 year ago

I noticed that quite a few cycle counts are calculated incorrectly when compared to the Yacht reference document. I'm well aware how hard it is to get these right from my work on my 68kcounter library and VS Code extension.

I started thinking about whether it would be possible to make use of my implementation from that project, given it's been through several iterations of user feedback and has pretty comprehensive tests. However this implementation is based on parsing source code, rather than assembled bytes. To use it as-is would require converting the bytes back to source only to parse it again, which seems pretty inefficient and I found it was introducing other inaccuracies. Instead I took the approach of parsing the code into structured data using m68kdecode, which is my TypeScript port of the Rust library of the same name by deplinenoise. This gives us the operator and operand types needed to look up the timings. I modified my timing tables from 68kcounter to use the new types and identifiers and imported them into this project, replacing the existing cycle calculation logic.

I've ported the full suite of test cases, which should cover every possible case combination of operator and operands according to the Yacht document. Hopefully this should give some guarantees of correctness!

I've also added a hover state to the cycle decorations to give a detailed view of the calculation, including DMA cycles and labels for each of the possble cases:

image