News for hackers. Stuff that matters.
Re:Cooperative Threading by axilmar on Wednesday November 13, 2019 @08:24AM (#21523679)
Do we really need all this complexity? how about if having, let's say, N chips to emulate, do a simple loop and call 'emulate' for each of the chips?

    for(EmulatedChip &chip : chips) {
        chip.emulate(time);
    }
Why would the above not be suitable for emulation?
Re:Cooperative Threading by boomlinde on Wednesday November 13, 2019 @11:20AM (#21525845)
That model is unsuitable for a system where chips are interconnected. Your model breaks down once chip x needs to produce something on a bus for chip y on cycle z. Of course, then you could emulate with time = 1 cycle, but at that point you are stuck implementing a state machine either way.

If you just have a bunch of chips operating separately without the need for synchronous communication your model works, but that's unrealistic.

Re:Cooperative Threading by joppy on Wednesday November 13, 2019 @08:31AM (#21523731)
I think this approach is the "state machine" approach given in the article. The added complexity in moving to a coroutines/co-operative threading model is balanced by the drastic code reduction, pointed out in the article by "Yes, it's really that dramatic of a difference".
Re:Cooperative Threading by fwsgonzo on Wednesday November 13, 2019 @11:55AM (#21526272)
Yes, you inevitably end up implementing a state machine like that.
Re:Cooperative Threading by byuu on Wednesday November 13, 2019 @10:17PM (#21532463)
I consider it something of a trap in fact.

You start writing a new emulator for the first time, dispatching entire instructions in one go, and so you don't even really need a state machine at all.

Then you start trying to get the timing better with opcode-cycle granularity, and in comes a separate state machine for every instruction.

Then you realize you need clock-cycle granularity to fix certain edge-case games (eg emulating the effects that occur during bus accesses), and suddenly the prospect of a state machine for every cycle of every instruction becomes overwhelming.

You would then be realistically stuck with the choice to either stop improving your accuracy, or rewriting things cooperatively.

Since I'm focusing byuu.net articles toward aspiring emulator developers, I thought it would be an important topic to cover.