nocrew / ostis

Atari ST Emulator
GNU Lesser General Public License v2.1
19 stars 4 forks source link

Clocked CPU #105

Open larsbrinkhoff opened 8 years ago

larsbrinkhoff commented 8 years ago

@stefanberndtsson is planning to convert the CPU component into a clocked design.

Would it be possible to jot down a few notes here every now and then to get a feel for what's going to happen?

larsbrinkhoff commented 8 years ago

Would it be possible to have the old implementation in parallel with the new, as a compile-time option?

stefanberndtsson commented 8 years ago

Yes, jotting will be done. :)

As for having a compile option, not so sure. Even the first iteration, which should be fairly kind to the structure still requires changing at least one actual instruction. That would mean pretty much keeping separate compilable instances of cpu_run(), cpu_step_instr(), cpu_do_cycle() and any changed instructions. I'm not sure this is manageable for more than one or two instructions, unless the whole cpu/* is preserved and clocked cpu is done alongside it in a new directory of course.

larsbrinkhoff commented 8 years ago

Yes, I was thinking new directory.

stefanberndtsson commented 8 years ago

Ok, I'll start that way. I won't maintain two different models forever though :)

stefanberndtsson commented 8 years ago

Ok, plans (everything based off the same 8MHz clock):

First iteration

This should take care of the basic bits, and the next code iteration can begin

Second iteration

Third iteration

larsbrinkhoff commented 8 years ago

Thanks; seem like a level-headed approach.

Temporarily handling wait states is easy, if you choose to do that. Share a clock counter between the CPU and MMU. When you want to start a bus cycle, delay until (clock & 3) == 0.

stefanberndtsson commented 8 years ago

Those are not the waitstates I'm refering to. They can be simulated within the cpu. The 2/6-cycle (yes, I know it's not exactly 6c, but dependent on the E-clock) delays from the PSG/ACIA are not something the cpu itself can really predict without too much hacky code. Those could be handled with the split of request/result on the bus.

In the meantime, the devices will simulate the extra cycles just like they do today (by increasing icycle)

larsbrinkhoff commented 8 years ago

Ah, those waitstates.

stefanberndtsson commented 8 years ago

There might be a small addition to the second iteration here.

The instruction sets icycle to however many cycles that needs to pass before entering the instruction again. Normally 0. It also sets a (new) flag to signal that the instruction is done.

This means that the current external waitstate simulation can run as it does now, since that read will just increase the icycle to 2 (or 6 or so), and thereby delaying the instruction a bit. Yes, it will technically be delayed in the wrong way (it will get the result first, then wait), but in the second iteration this is good enough and won't interfere with any existing code.

stefanberndtsson commented 8 years ago

The clocked-cpu branch now contains most of the concepts listed in the first iteration. Movem still does the wrong thing, but it works somewhat at least. The first iteration is not finished yet though.

larsbrinkhoff commented 8 years ago

Helpful hint: Don't run along too far on the branch. I suggest either merging it into master occasionally, or rebasing it to master frequently. I do the latter with my branches.

stefanberndtsson commented 8 years ago

Once I get the debugger bits done, I think I'll just merge it for now, since it doesn't affect the old system anyway. Otherwise I would've rebased a lot.

larsbrinkhoff commented 8 years ago

"68000 Undocumented Behavior Notes" http://web.archive.org/web/20091015132715/http://www.trzy.org/files/68knotes.txt