3 ms·
If it was CPU emulator, it would update all the flags everytime performing any ALU operation (I have seen this approach in one source-to-source compiler). Actua
by gabonator 5y ago
If it was CPU emulator, it would update all the flags everytime performing any ALU operation (I have seen this approach in one source-to-source compiler). Actually, there is not much you can do: If the instruction stores SP into DS:123, it converts the instruction into simple assignment *((WORD*)&memory[ds*16+123]) = sp. All the ALU operations are directly calculated using the target instruction set, the flags register is updated only when necessary. Nor the memory is emulated, it directly accessess the memory buffer (in the video there are just extra range checks, even the *16 operation can be optimized replacing ds/es with memory pointers). Only thing that is emulated is the EGA adapter.
- tralarpa 5y agoThanks for the explanation. Very nice project. I guess self-modifying code does not work with this technique, does it? (I don't know much about DOS games and how common self-modifying code was on PCs). Concerning access to video memory: I saw that you treat them "manually" in some cases. I am wondering whether you could avoid that by using virtual memory. You could mark the pages as invalid and when an instruction tries to access them, you catch it and replace the memory[...] access instruction by a call to memoryVideoGet. The JIT-Compiler of the Amiga emulator uses a similar technique for indirect accesses to hardware registers.
- gabonator 5y agoGood point. In the set of games (10 in total, release date up to 1991) I was porting I found only one that used this nasty technique. And it was just rewriting only single byte of code (something like rewriting nop instruction into return). So very simple case so far. Of course using cicoparser doesn't mean that you get working code without any manual work. You will always need to fix some issues by hand. Virtual memory does not solve anything in this case. Writing to EGA video ram means that you want to display some pixels. But the write operation goes through some extra logic which decides what to do with the byte being written (extra rotation, masking...) and by reading the same addrees you are not guaranteed to get the same value back. EGA control registers handle this process and you simply need to emulate this behaviour somehow.
- habibur 5y agoRight. From a birds eye view it might more look like assembly. But look closer and you see it summarizes a bunch of idiomatic assemblies into C code. And it will improve over time if the developers continue to give it effort.