In this message I'd like a propose a method to semi-systematically improve the correctness of PCSX2 (but which also applies to any other emulator of a user-programmable system).
The idea is to run a special program (compiled for the PS2) on a devkit or modded PS2 that runs a game on the console and allows to examine the state of the game and the operations it performs.
Using such a program (which I'll call a "monitor"), an emulator developer would run the same game on both a PC using the emulator and on the PS2 using the monitor for a certain number of "steps" (corresponding to CPU instructions) . The state of the emulated hardware and the real hardware are then compared (over some kind of connection between the PC and the PS2): if they are the same, the emulator is correct and otherwise an emulator bug has been exposed.
By either comparing regularly during the execution or comparing at the end and varying the number of steps like in a binary search, it would then be possible to determine the exact point of the divergence between the emulator and the real hardware: the code emulating the operation in question can then be analyzed and fixed.
The practical implementation of all this is actually more difficult than it may seem at first glance: first of all, the presence of the monitor will alter the PS2 environment (most visibly, it will significantly slow down the game), so several parts of the PS2 may need to be virtualized (e.g. timers, instruction counters and whatever facility is used to communicate with the PC, if the game also uses it) so that the game doesn't malfunction due to the alterations; furthermore, the game must be prevented from taking actions that would cripple the monitor (such as writing to a RAM region used by the monitor), which must be also virtualized.
Furthermore, some hardware components behave non-deterministically: to accommodate this, the effects seen on the PS2 need to be recorded and communicated to the emulator, which must use them (an obvious example of this is the CD/DVD drive, whose response time is certainly not constant).
Finally, the PS2 is a multiprocessor system: handling this requires to run a monitor on each processor, and synchronize them all so that instructions are interleaved in a predictable way; alternatively, auxiliary processors could be emulated on the main one, which would however require prior perfect emulation of their instruction set, since one would not be able to "just run" the instructions (along with register save/restore around them).
Fortunately official developers probably perform something similar to the process discussed here to debug their games, which means that games are probably at least partially resistant to being run under debugger-like programs; furthermore, the hardware may have debugging capabilities built-in, which would ease the monitor implementation or even allow to observe and single-step games externally without a monitor; such capabilities may however only be present on devkit PS2 consoles or boards.
Summing up, while the implementation of all this is likely time consuming, it should provide an almost straightforward way to improve the emulator and make specific games work.
The idea is to run a special program (compiled for the PS2) on a devkit or modded PS2 that runs a game on the console and allows to examine the state of the game and the operations it performs.
Using such a program (which I'll call a "monitor"), an emulator developer would run the same game on both a PC using the emulator and on the PS2 using the monitor for a certain number of "steps" (corresponding to CPU instructions) . The state of the emulated hardware and the real hardware are then compared (over some kind of connection between the PC and the PS2): if they are the same, the emulator is correct and otherwise an emulator bug has been exposed.
By either comparing regularly during the execution or comparing at the end and varying the number of steps like in a binary search, it would then be possible to determine the exact point of the divergence between the emulator and the real hardware: the code emulating the operation in question can then be analyzed and fixed.
The practical implementation of all this is actually more difficult than it may seem at first glance: first of all, the presence of the monitor will alter the PS2 environment (most visibly, it will significantly slow down the game), so several parts of the PS2 may need to be virtualized (e.g. timers, instruction counters and whatever facility is used to communicate with the PC, if the game also uses it) so that the game doesn't malfunction due to the alterations; furthermore, the game must be prevented from taking actions that would cripple the monitor (such as writing to a RAM region used by the monitor), which must be also virtualized.
Furthermore, some hardware components behave non-deterministically: to accommodate this, the effects seen on the PS2 need to be recorded and communicated to the emulator, which must use them (an obvious example of this is the CD/DVD drive, whose response time is certainly not constant).
Finally, the PS2 is a multiprocessor system: handling this requires to run a monitor on each processor, and synchronize them all so that instructions are interleaved in a predictable way; alternatively, auxiliary processors could be emulated on the main one, which would however require prior perfect emulation of their instruction set, since one would not be able to "just run" the instructions (along with register save/restore around them).
Fortunately official developers probably perform something similar to the process discussed here to debug their games, which means that games are probably at least partially resistant to being run under debugger-like programs; furthermore, the hardware may have debugging capabilities built-in, which would ease the monitor implementation or even allow to observe and single-step games externally without a monitor; such capabilities may however only be present on devkit PS2 consoles or boards.
Summing up, while the implementation of all this is likely time consuming, it should provide an almost straightforward way to improve the emulator and make specific games work.