Advertisement
gocha

TAS Emulator Implementation Roadmap

Feb 4th, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. == EmuLua Implementation Roadmap ==
  2.  
  3. 1. Embed Lua engine + emulator-independent functions
  4. * Add LuaBitOp functions
  5. * Add print, tostring, addressof, copytable
  6. * Add emu.persistglobalvariables
  7. 2. Add very basic functions
  8. * Add emu.atframeboundary, emu.emulating
  9. * Add emu.framecount, emu.lagcount, emu.lagged (they should always return a raw value, with no timing hack)
  10. * Add emu.registerbefore (it must be called at the beginning of frame boundary)
  11. * Add emu.registerafter (it must be called at the end of frame boundary)
  12. * Add emu.registerstart
  13. * Add emu.registerexit (it must work on both closing a script and closing an emulator)
  14. * Add gui.register
  15. 3. Add very basic memory functions
  16. * Add memory.[read|write][byte|word|dword][signed], memory.readbyterange
  17. * They must be "sync-free" memory I/O functions (which doesn't count up cycle-count).
  18. 4. Add Lua GUI function (90% of the code can be copied from other TAS emulator)
  19. 5. Add joypad.get[up|down], input.get
  20. * If your emulator is not smart enough, you need to separate input buffer to intermediate/final.
  21. * joypad.get should return intermediate input rather than final input. (due to support of round-trip I/O)
  22. * The emulator needs a coordinate conversion function among the GUI and the game screen, for mouse support.
  23. 6. Add savestate functions
  24. * Add movie.rerecordcounting
  25. * Add movie.readonly, movie.setreadonly
  26. * Add savestate.save, savestate.load
  27. * Add savestate.registersave, savestate.registerload
  28. * Add savestate.savescriptdata, savestate.loadscriptdata
  29. 7. Add advanced memory functions
  30. * Add memory.registerread, memory.registerwrite, memory.registerexec
  31. * Add memory.getregister, memory.setregister
  32. * Add memory.isvalid
  33. 8. Add movie functions
  34. * Add movie.active, movie.recording, movie.playing, movie.finished, movie.mode
  35. * Add movie.name, movie.length, movie.rerecordcount, movie.setrerecordcount
  36. * Add movie.play, movie.replay, movie.stop
  37. 9. Add other functions
  38. * Add emu.loadrom
  39. * Add emu.openscript
  40. * Add emu.frameadvance
  41. * Add emu.speedmode
  42. * Add emu.emulateframe[fast|invisible], emu.wait, emu.redraw
  43. * Add joypad.peek[up|down]
  44. * Add input.registerhotkey
  45. * Add cheat functions
  46. * Add sound functions
  47. * Add peripheral support
  48.  
  49. == Emulator I/O Diagram ==
  50.  
  51. function Main()
  52. {
  53. while (true)
  54. {
  55. // it can be processed on WM_KEYDOWN, as for Windows
  56. Joypad.IntermediateInput = ReadUserInput();
  57.  
  58. FrameAdvance();
  59. }
  60. }
  61.  
  62. function FrameAdvance()
  63. {
  64. // Frame Advance cannot be nested.
  65. assert(Emulator.AtFrameBoundary);
  66.  
  67. StartFrameBoundary();
  68. EmurateFrame();
  69. EndFrameBoundary();
  70. }
  71.  
  72. function StartFrameBoundary()
  73. {
  74. if (Movie.Playing()) {
  75. // Movie.ReadInput() returns the next movie input.
  76. // Movie reset should be done in Movie.ReadInput(),
  77. // unless the emulator has sub-frame precision.
  78. Joypad.IntermediateInput = Movie.ReadInput();
  79. }
  80.  
  81. // Reset joypad-read flag.
  82. Emulator.Lagged = false;
  83.  
  84. // Callback must not be invoked before ReadMovie(),
  85. // or, script cannot get any input from movie.
  86. Lua.InvokeCallback(CALLBACK_REGISTERBEFORE);
  87.  
  88. // Determine final joypad state.
  89. Joypad.FinalInput = Joypad.IntermediateInput;
  90.  
  91. // Movie.WriteInput() can be done in EndFrameBoundary() instead.
  92. if (Movie.Recording()) {
  93. Movie.WriteInput(Joypad.FinalInput);
  94. }
  95.  
  96. // Timing to apply cheats is somewhat debatable.
  97. // Doing it after Lua callback allows to apply new cheats which are added by Lua.
  98. // On the other hand, doing it before the callback allows Lua to read modified memory value.
  99. // Maybe we should call it twice? It sounds a bit too redundant.
  100. Cheat.ApplyCheats();
  101.  
  102. // Enter to emulation core.
  103. Emulator.AtFrameBoundary = false;
  104. }
  105.  
  106. function EndFrameBoundary()
  107. {
  108. // Exit from emulation core.
  109. Emulator.AtFrameBoundary = true;
  110.  
  111. // Increment frame counter
  112. Emulator.FrameCount++;
  113. if (Emulator.Lagged) {
  114. Emulator.LagCount++;
  115. }
  116.  
  117. // Invoke Lua callback.
  118. Lua.InvokeCallback(CALLBACK_REGISTERAFTER);
  119.  
  120. // Update HUD after everything has been done.
  121. GUI.UpdateHUD();
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement