simias / rustation

Playstation emulator in the Rust programing language
Other
552 stars 21 forks source link

Emulate GTE register access latency #5

Open simias opened 8 years ago

simias commented 8 years ago

There appears to be a 2 cycle latency when storing a value to a GTE register with the ctc2 instruction. For instance the following code puts 0x456 (the value of $t1) in $a1 even though there are two other ctc2 instructions in between:

    li    $t0, 0x123
    li    $t1, 0x456
    li    $t2, 0x789
    li    $t3, 0xabc

    ctc2  $t0, $26
    ctc2  $t1, $26
    ctc2  $t2, $26
    ctc2  $t3, $26

    cfc2  $a1, $26

I have to see if this also concerns the GTE command: what happens if you run an instruction immediately after setting a register?

simias commented 8 years ago

I've also noticed a strange behaviour of cfc2/mfc2 in my test code on the console: sometimes it appears to return bogus values (for instance zero when the register is non-zero). I also noticed that the BIOS code often (always?) uses two identical mfc2 calls in a row to load a value. I'm guessing that a single read is not trustworthy?

The issue appears pseudo-random in my tests, maybe a subtle timing issue.