Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPU speed #21

Open
dirkwhoffmann opened this issue Mar 9, 2019 · 2 comments
Open

CPU speed #21

dirkwhoffmann opened this issue Mar 9, 2019 · 2 comments

Comments

@dirkwhoffmann
Copy link

I've noticed that the CPU is running way too fast. In the main loop, a single CPU instruction is called for each DMA cycle. This means that each CPU instruction has a mean execution time of 2 CPU cycles.

I've tried to make it a little more accurate by changing it to:

 for(int cpuCycles =0;cpuCycles<200;++cpuCycles){
        
            cpuClock += cpu_execute();
            do {
                dma_execute();
                dmaClock += 2;
            } while (dmaClock < cpuClock);
    }

cpu_executes has been changed to return the number of performed CPU cycles (which is given back by the Musashi CPU). cpuClock and dmaClock are two long variables initialised with 0.

Unfortunately, the emulator does not work with this changed configuration.

It processes 106 frames and then aborts with

Bus error: 10
@h5n1xp
Copy link
Owner

h5n1xp commented Mar 9, 2019

I'm really glad you've had a look at this!

The cpuCycles for() loop was originally two nested loops, an inner one for the DMA and and outer one for the CPU... to address this very timing concern you have spotted. But I too had difficulty getting it to work. The only way to make it work was to have a 1:1 CPU:DMA execution cycle. No idea why.

My local code also has a chip address space lock out for the CPU, so the CPU has to wait if the DMA is using the memory cycle... again it doesn't work, so I've disabled it for now.

If you look at main.c you will see just before the main loop, there are a few commented out functions, these are to run the CPU in a separate thread from the DMA. Again it doesn't work yet, I think the issues is something to do with timing synchronisation.

@h5n1xp
Copy link
Owner

h5n1xp commented Mar 11, 2019

This is actually quite an important issue.

One of my hopes for Omega is that I can be used as a sort of “compatibility library”. As @mithrendal already alluded to, I want the CPU emulation and chipset emulation completely independent, so it can run as a “device driver” for operating systems running in non Amiga hardware...

I spent a few hours on this last night, but didn’t make much progress.

-edit- sorry for the random thread comments/closing/opening... Github is not very iPhone friendly 😄

@h5n1xp h5n1xp closed this as completed Mar 11, 2019
@h5n1xp h5n1xp reopened this Mar 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants