System core solutions
Posted: Mon Aug 04, 2003 12:27 pm
While playing Day of the Tentacle on SCUMM-VM (Dos no worky on Xp) , I realized how the games seem to run normal while actually being emulated.
1) When created a machine, you can stick to real opcodes or virtual opcodes.
Real opcodes are more like mov, add, etc.
Virtual opcodes are more like: drawpixel, hidemouse
An opcode is a single instruction which can make a bigger instruction.
Emulating a bunch of real opcodes to draw a pixel will be naturally time consuming. Virtual opcodes are faster and simpler.
2)To Intrepret or Recompile?
This mostly matters on what you picked on question 1.
Recompiling runs fast, but takes too long (At load times). Also, if the program jumps to a variable, the recompiler doesn't know what to convert that variable to. That is why you need to recompile everytime a byte in the program's execution path is changed. The solution may be to disable programs writing to themselves. That is a nono mostly. Recompiling is great if you are using real opcodes.
Intrepreting real opcodes IS SLOOOOOOOWWWWW, but it is less buggy. Intrepreting virtual opcodes is faster, but you have to use asm to do it correctly.
3)Better Intrepretation core:
(A made up language to prevent people from copy-pasting. Make em do something ;D )
word offset;
byte program[10];
....
//Load program
....
jump(0x100040+program[offset] *3) //Jump instruction is 3 bytes (I think :/ )
//Means, get current opcode, multiply it by 10, and jump there
0x100040:
jmp executeop0;
0x100043:
jmp executeop1;
This way is fast. If you used an if/switch, it would waste instructions using compare.
1) When created a machine, you can stick to real opcodes or virtual opcodes.
Real opcodes are more like mov, add, etc.
Virtual opcodes are more like: drawpixel, hidemouse
An opcode is a single instruction which can make a bigger instruction.
Emulating a bunch of real opcodes to draw a pixel will be naturally time consuming. Virtual opcodes are faster and simpler.
2)To Intrepret or Recompile?
This mostly matters on what you picked on question 1.
Recompiling runs fast, but takes too long (At load times). Also, if the program jumps to a variable, the recompiler doesn't know what to convert that variable to. That is why you need to recompile everytime a byte in the program's execution path is changed. The solution may be to disable programs writing to themselves. That is a nono mostly. Recompiling is great if you are using real opcodes.
Intrepreting real opcodes IS SLOOOOOOOWWWWW, but it is less buggy. Intrepreting virtual opcodes is faster, but you have to use asm to do it correctly.
3)Better Intrepretation core:
(A made up language to prevent people from copy-pasting. Make em do something ;D )
word offset;
byte program[10];
....
//Load program
....
jump(0x100040+program[offset] *3) //Jump instruction is 3 bytes (I think :/ )
//Means, get current opcode, multiply it by 10, and jump there
0x100040:
jmp executeop0;
0x100043:
jmp executeop1;
This way is fast. If you used an if/switch, it would waste instructions using compare.