Viewing Issue Advanced Details
ID Category [?] Severity [?] Reproducibility Date Submitted Last Update
09174 Core Minor Always 16 days ago 15 days ago
Tester Peer View Status Public Platform MAME (Self-compiled)
Assigned To Peer Resolution Fixed OS Windows 10/11 (64-bit)
Status [?] Resolved Driver
Version 0.277 Fixed in Version 0.278GIT Build 64-bit
Fixed in Git Commit 35b7abd Github Pull Request #
Summary 09174: CPU Hitachi HD6309: cycle counts of branch-instructions of hd6309 cpu in native-mode are incorrect
Description The cycle counts of the relative-branch-instructions of the hd6309 CPU in native-mode are the same as in emulation-mode. The only exceptions are the BRA and LBRA instructions. All others have the same cycle counts.

However, the code in devices/cpu/m6809/base6x09.lst gives all branch instructions in native-mode one cycle less than in emulation-mode.
Steps To Reproduce Just check the code in devices/cpu/m6809/base6x09.lst and compare their timing to the cycles counts listed in "Motorola 6809 and Hitachi 6309 Programming Reference" by Darren Atkinson.
Additional Information I have a real Vectrex console with a real Hitachi hd6309 CPU inside, running a customized 6309 BIOS in native-mode, with all cycle-dependent routines adapted to the 6309 native-mode timing.

I have compiled a custom mame version, which uses the hd6309 CPU inside vextrec.cpp, and which loads my custom 6309 BIOS file. This shows the simulation mismatch to my real system. Fixing the cycle-counts in devices/cpu/m6809/base6x09.lst leads to my mame version correctly emulating the behavior of the real console.
Github Commit
Flags Verified with Code
Regression Version
Affected Sets / Systems CPU Hitachi HD6309
Attached Files
zip file icon base6x09.zip (2,544 bytes) 15 days ago Uploaded by Peer
zip file icon vectrex.zip (6,621 bytes) 15 days ago Uploaded by Peer
custom 6309 native mode BIOS for the Vectrex
Relationships
There are no relationship linked to this issue.
Notes
7
User avatar
No.23289
hap
Developer
16 days ago
edited on: 16 days ago
Could you attach your modified base6x09.lst file?
(package it in a .zip if the website doesn't accept the file type)

And if you're willing to share it, the custom Vectrex BIOS too.
User avatar
No.23290
Peer
Tester
15 days ago
edited on: 15 days ago
Sure, and sorry for not thinking of this right away.

You will find my patch in line 493. Note that this patch fixes the cycle count for all short relative branches but BRA and LBRA, that is still to do. Also see my comment in line 507 regarding the long branches, those are also still to do.

I will attach my custom Vectrex 6309 BIOS next.
User avatar
No.23291
Peer
Tester
15 days ago
edited on: 15 days ago
The vectrex.zip is to be put into the "roms" folder of mame and contains the file "exec_rom.bin", which is my 6309 native-mode BIOS version. It will say so on the boot screen of the Vectrex, and it will switch the 6309 to native mode automatically. Note that mame will complain about the checksum.

If you want to try one of the Vectrex cartridges, use e.g. Scramble. That game will run visibly faster in 6309 native-mode compared to the regular 6809 (the scrolling is faster, and the game thus a bit harder).

Please let me know if you have further questions or if I can be of more help.
User avatar
No.23292
hap
Developer
15 days ago
edited on: 15 days ago
Ok, it's fixed. The docs are a bit confusing, until I realized that unconditional long branch opcode is 1 byte less than the conditional ones.

So:
short branch: always 3 cycles
u. long branch: 5 cycles on 6809, 4 cycles on native 6309
c. long branch: 5 cycles, +1 cycle if branch is taken on 6809
User avatar
No.23293
Peer
Tester
15 days ago
edited on: 15 days ago
Yes, the docs are a bit confusing. Regarding the long branches, just to be sure, from the docs I concluce that LBRN is always 5 cycles, be it 6809, or 6309 emulation-mode, or 6309 native-mode. Does that match your interpretation and your fix?
User avatar
No.23294
hap
Developer
15 days ago
Yes, 'long branch never' is a 4-byte opcode and is always 5 cycles.
User avatar
No.23295
Peer
Tester
15 days ago
Cool, thanks!