My question is what would you consider a good design?hlide said:I was speaking about the way all the source file is coded : very long functions and no design pattern. I don't mean your code is unefficient but very hard to maintain or to be understandable by the others. I had to maintain similar codes in work which were coded by electronics engineers who coded similarly. It was always a nightmare to try to change something deeply and most time you need to rewrite from the scratch, so I understand Notaz's feeling about the difficulty to bring a change without breaking something. But take it easy, that you could code a working recompiler this way is pretty amazing indeed.
For example, if you look at gpSP, it is a very similar layout, very long functions in a handful of source files. The original mupen64plus recompiler has many short functions. They are easy to find, but there is a lot of code duplication. PCSX is the same, lots of code duplication. Daedalus has many short functions in a dozen different source files, and I found it difficult to read because it is so scattered.
A major problem with cpu emulators is that you have a lot of functions that are similar but not exactly the same. Inexperienced developers tend to cut-and-paste a lot of duplicate code. I tried to factor out things into subroutines, although I still ended up with some bits of duplicate code that were hard to factor out. Strmnnrmn and Exophase primarily used macros.
Which approach do you consider best, and why?
It is doable. Move the stuff that sets the return address above the call to ds_assemble, but after the REG_PREFETCH bit. Then make sure it doesn't load the old value of r31. Under "// Load the delay slot registers if necessary" addnotaz said:Sure, just hlide and Exophase kind of implied it should be doable without too much effort and I wanted to show why I chose to fall back to interpreter this time.
if(rt1==0||rs1[i+1]!=rt1) for the first case, and
if(rt1==0||rs2[i+1]!=rt1) for the second.
Then test it to make sure everything works correctly
You can do the constant propagation thing too if you want, but make sure you don't overwrite r31 with the original value if it's already been set with the result of the add instruction, which will happen in load_consts().
Last edited by a moderator: