rfancella

WinVice-SDL.ahk

Jun 27th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.08 KB | None | 0 0
  1. MEmu = WinVICE-SDL
  2. MEmuV = v2.4
  3. MURL = http://vice-emu.sourceforge.net/
  4. MAuthor = djvj,wahoobrian,brolly
  5. MVersion = 2.0.2
  6. MCRC = BA37ED39
  7. iCRC = DAA4D1EA
  8. MID = 635038268966170754
  9. MSystem = "Commodore 64","Commodore 16 & Plus4","Commodore VIC-20"
  10. ;----------------------------------------------------------------------------
  11. ; Notes:
  12. ; Roms must be unzipped.
  13. ; You can turn off the exit confirmation box by unchecking Settings->Confirm on exit
  14. ; Turn on saving settings by checking Settings->Save settings on exit, this will create the vice.ini file this module needs.
  15. ;
  16. ; If you want to use the StartTape and StopTape hotkeys make sure you edit the files C64\win_shortcuts.vsc or VIC20\win_shortcuts.vsc
  17. ; (paths relative to the emulator install folder) and assign Alt+F7 as the StartTape shortcut and Alt+F8 as the StopTape shortcut, like this:
  18. ; ALT 0x76 IDM_DATASETTE_CONTROL_START F7
  19. ; ALT 0x77 IDM_DATASETTE_CONTROL_STOP F8
  20. ;
  21. ; WinVICE uses different executables for each machine so make sure you setup your emulators properly:
  22. ; x64.exe - Commodore 64
  23. ; xplus4.exe - Commodore 16 & Plus/4
  24. ; xvic.exe - Commodore VIC-20
  25. ;----------------------------------------------------------------------------
  26. StartModule()
  27. BezelGUI()
  28. FadeInStart()
  29.  
  30. mType := Object("Commodore 64","C64","Commodore 16 & Plus4","PLUS4","Commodore VIC-20","VIC20") ;ident should be the section names used in VICE.ini
  31. ident := mType[systemName] ; search object for the systemName identifier
  32.  
  33. IfExist, % modulePath . "\" . systemName . ".ini" ; use a custom systemName ini if it exists
  34. settingsFile := modulePath . "\" . systemName . ".ini"
  35. Else
  36. settingsFile := modulePath . "\" . moduleName . ".ini"
  37.  
  38. Fullscreen := IniReadCheck(settingsFile, "Settings", "Fullscreen","true",,1) ; If true, the module governs if the emulator launches fullscreen or not. Set to false when troubleshooting a module for launching problems.
  39. WarpKey := IniReadCheck(settingsFile, "Settings", "WarpKey","F9",,1) ; toggle warp speed
  40. JoySwapKey := IniReadCheck(settingsFile, "Settings", "JoySwapKey","F10",,1) ; swap joystick port
  41. StartTapeKey := IniReadCheck(settingsFile, "Settings", "StartTapeKey","F7",,1) ; starts tape
  42. StopTapeKey := IniReadCheck(settingsFile, "Settings", "StopTapeKey","F8",,1) ; stops tape
  43.  
  44. bezelTopOffset := IniReadCheck(settingsFile, "Settings", "bezelTopOffset",16,,1)
  45. bezelBottomOffset := IniReadCheck(settingsFile, "Settings", "bezelBottomOffset",46,,1)
  46. bezelLeftOffset := IniReadCheck(settingsFile, "Settings", "bezelLeftOffset",7,,1)
  47. bezelRightOffset := IniReadCheck(settingsFile, "Settings", "bezelRightOffset",7,,1)
  48.  
  49. SelectGameMode := IniReadCheck(settingsFile, "Settings", "SelectGameMode","1",,1) ; 1 = Uses a loop to detect the Edit Box has the romname and path in it. This doesn't work on all PCs, so if you get stuck at the open rom window, use mode 2. 2 = Uses a simple Ctrl+v to paste the romname and path, then press Enter to load the game.
  50. ; DiskSwapKey = F11 ; swaps disk or tape - Do not need this key anymore with multigame support
  51.  
  52. UsePaddles := IniReadCheck(settingsFile, romName, "UsePaddles", "false",,1)
  53. AutostartPrgMode := IniReadCheck(settingsFile, romName, "AutostartPrgMode", "2",,1)
  54. RequiresReset := IniReadCheck(settingsFile, romName, "RequiresReset", "false",,1)
  55.  
  56. 7z(romPath, romName, romExtension, 7zExtractPath)
  57.  
  58. viceINI := CheckFile(emuPath . "\sdl-vice.ini")
  59. IniRead, currentFullScreen, %viceINI%, %ident%, VICIIFullscreen
  60. IniRead, currentAutostartPrgMode, %viceINI%, %ident%, AutostartPrgMode
  61.  
  62. BezelStart()
  63.  
  64. ; Setting Fullscreen setting in ini if it doesn't match what user wants above
  65. If ( Fullscreen != "true" And currentFullScreen = 1 )
  66. IniWrite, 0, %viceINI%, %ident%, VICIIFullscreen
  67. Else If ( Fullscreen = "true" And currentFullScreen = 0 )
  68. IniWrite, 1, %viceINI%, %ident%, VICIIFullscreen
  69.  
  70. If ( currentAutostartPrgMode != AutostartPrgMode )
  71. IniWrite, %AutostartPrgMode%, %viceINI%, %ident%, AutostartPrgMode
  72.  
  73. WarpKey := xHotKeyVarEdit(WarpKey,"WarpKey","~","Add")
  74. JoySwapKey := xHotKeyVarEdit(JoySwapKey,"JoySwapKey","~","Add")
  75. StartTapeKey := xHotKeyVarEdit(StartTapeKey,"StartTapeKey","~","Add")
  76. StopTapeKey := xHotKeyVarEdit(StopTapeKey,"StopTapeKey","~","Add")
  77. xHotKeywrapper(WarpKey,"Warp")
  78. xHotKeywrapper(JoySwapKey,"JoySwap")
  79. xHotKeywrapper(StartTapeKey,"StartTape")
  80. xHotKeywrapper(StopTapeKey,"StopTape")
  81.  
  82. If romName contains (USA),(Canada)
  83. DefaultVideoMode = NTSC
  84. Else
  85. DefaultVideoMode = PAL
  86.  
  87. VideoMode := IniReadCheck(settingsFile, romName, "VideoMode", DefaultVideoMode,,1)
  88.  
  89. params := ""
  90.  
  91. ; Setting video mode depending on rom, default NTSC
  92. if (VideoMode = "NTSC") {
  93. params := params . " -ntsc"
  94. ;IniWrite, -2, %viceINI%, %ident%, MachineVideoStandard ;NTSC
  95. } else {
  96. params := params . " -pal"
  97. ;IniWrite, -1, %viceINI%, %ident%, MachineVideoStandard ;PAL
  98. }
  99.  
  100. ;Enable/Disable paddles as needed, leave these checks in-place because mouse CLI and Ini options aren't supported in VICE 1.22 and this way it will also work with it.
  101. IniRead, currentUsePaddles, %viceINI%, %ident%, Mouse
  102. If ( UsePaddles = "true" And currentUsePaddles != 1)
  103. params := params . " -mouse -mousetype 3"
  104. If ( UsePaddles = "false" And currentUsePaddles = 1)
  105. params := params . " +mouse"
  106.  
  107. If (ident = "C64") {
  108. If romExtension not in .d64,.d71,.d80,.d81,.d82,.g64,.g41,.x64,.t64,.tap,.crt
  109. ScriptError("Your rom has an extension of " . romExtension . ", only these extensions are supported:`nd64,d71,d80,d81,d82,g64,g41,x64,t64,tap,crt")
  110.  
  111. If ( romExtension = ".crt" ) {
  112. IniWrite, %romPath%\%romName%%romExtension%, %viceINI%, C64, CartridgeFile
  113. IniWrite, 0, %viceINI%, C64, CartridgeType
  114. } Else {
  115. IniWrite, -1, %viceINI%, C64, CartridgeType
  116. }
  117.  
  118. ; Hotkey, ~%DiskSwapKey%, MultiGame
  119.  
  120. If romExtension in .d64,.d71,.d80,.d81,.d82,.g64,.g41,.x64,.prg
  121. Run(executable . " " . params . " """ . romPath . "\" . romName . romExtension . """", emuPath)
  122. Else If romExtension in .t64,.tap
  123. Run(executable . " " . params . " """ . romPath . "\" . romName . romExtension . """", emuPath)
  124. Else If romExtension = .crt
  125. Run(executable . " " . params . " -cartcrt """ . romPath . "\" . romName . romExtension . """", emuPath)
  126.  
  127. if (RequiresReset = "true")
  128. {
  129. WinWaitActive("ahk_class VICE")
  130. Sleep, 1000 ; increase if command is not appearing in the emu window or some just some letters
  131. Send !r
  132. }
  133. }
  134. Else If (ident = "PLUS4") {
  135. If romExtension not in .prg,.d64,.t64,.tap,.crt,.g64,.bin
  136. ScriptError("Your rom has an extension of " . romExtension . ", only these extensions are supported:`nprg,d64,t64,tap,crt,g64,bin")
  137.  
  138. SendCommandDelay := IniReadCheck(settingsFile, "Settings", "SendCommandDelay", "1500",,1)
  139. Model := IniReadCheck(settingsFile, romName, "Model", "Commodore Plus/4",,1)
  140.  
  141. ; Setting model
  142. If (Model = "Commodore Plus/4") { ;Commodore Plus/4
  143. IniWrite, "3plus1lo", %viceINI%, %ident%, FunctionLowName
  144. IniWrite, "3plus1hi", %viceINI%, %ident%, FunctionHighName
  145. IniWrite, 64, %viceINI%, %ident%, RamSize
  146. IniWrite, 1, %viceINI%, %ident%, Acia1Enable
  147. }
  148. Else { ;Commodore 16
  149. IniWrite, "", %viceINI%, %ident%, FunctionLowName
  150. IniWrite, "", %viceINI%, %ident%, FunctionHighName
  151. IniWrite, 16, %viceINI%, %ident%, RamSize
  152. IniWrite, 0, %viceINI%, %ident%, Acia1Enable
  153. }
  154.  
  155. Command := IniReadCheck(settingsFile, romName, "Command", "",,1)
  156. StringLower, Command, Command ;Command MUST be in lower case so let's force it
  157.  
  158. If romExtension in .d64,.g64,.prg
  159. Run(executable . " " . params . " """ . romPath . "\" . romName . romExtension . """", emuPath)
  160. Else If romExtension in .t64,.tap
  161. Run(executable . " " . params . " """ . romPath . "\" . romName . romExtension . """", emuPath)
  162. Else If romExtension in .crt,.bin
  163. Run(executable . " " . params . " -cart """ . romPath . "\" . romName . romExtension . """", emuPath)
  164.  
  165. if (RequiresReset = "true")
  166. {
  167. WinWaitActive("ahk_class VICE")
  168. Sleep, 1000 ; increase if command is not appearing in the emu window or some just some letters
  169. Send !r
  170. }
  171.  
  172. if %Command%
  173. {
  174. WinWaitActive("ahk_class VICE")
  175. Sleep, %SendCommandDelay% ; increase if command is not appearing in the emu window or some just some letters
  176.  
  177. If romExtension in .t64,.tap
  178. {
  179. ;Tape loading time will vary greatly so we can't type this automatically, user must do it using a hotkey
  180. RunTapeKey := IniReadCheck(settingsFile, romname, "RunTapeKey","Ctrl&F12",,1) ; run tape key
  181. RunTapeKey := xHotKeyVarEdit(RunTapeKey,"RunTapeKey","~","Add")
  182. xHotKeywrapper(RunTapeKey,"RunTape")
  183. }
  184. Else
  185. {
  186. SetKeyDelay, 50
  187. Loop, parse, Command
  188. Send, {%A_LoopField% down}{%A_LoopField% up}
  189. Send, {ENTER down}{ENTER up}
  190. }
  191. }
  192. }
  193. Else If (ident = "VIC20") {
  194. If romExtension not in .prg,.d64,.t64,.tap,.crt
  195. ScriptError("Your rom has an extension of " . romExtension . ", only these extensions are supported:`nprg,d64,t64,tap,crt")
  196.  
  197. SendCommandDelay := IniReadCheck(settingsFile, "Settings", "SendCommandDelay", "1500",,1)
  198.  
  199. CartAddress := IniReadCheck(settingsFile, romName, "CartLoadingAddress", "X000",,1)
  200. MemoryExpansion := IniReadCheck(settingsFile, romName, "MemoryExpansion", "none",,1)
  201. Command := IniReadCheck(settingsFile, romName, "Command", "",,1)
  202. RequiresReset := IniReadCheck(settingsFile, romName, "RequiresReset", "false",,1)
  203.  
  204. StringLower, Command, Command ;Command MUST be in lower case so let's force it
  205.  
  206. If ( romExtension = ".crt" ) {
  207. ;Sleep, 100 ;Without this romtable comes empty (thread related?)
  208. RomTableCheck() ; make sure romTable is created already so the next line can calculate correctly
  209.  
  210. ;MultiPart carts can only be run if the MultiGame feature is enabled
  211. If romName contains (Part
  212. {
  213. If (mgEnabled = "false")
  214. ScriptError("You cannot run multipart games with MultiGame disabled")
  215. }
  216.  
  217. romCount = % romtable.MaxIndex()
  218.  
  219. If (romCount > 1) {
  220. ;multipart carts - need to build custom CLI parameters to invoke multipart cartridges. Multipart cartridges are loaded in more than one
  221. ; memory address, so we interrogate each part, and determine its loading address, and build the CLI parameters.
  222. ; Once all the cartridge parts have been processed, the emulator with the custom CLI parameters are invoked.
  223. ;
  224. ; Using Lunaar Leeper as an example, it has two parts, one loaded in $2000, and one in $A000
  225. ; "xvic.exe -cart2 "D:\Games\Commodore VIC-20\Lunar Leeper (USA) (Part 1).crt" -cartA "D:\Games\Commodore VIC-20\Lunar Leeper (USA) (Part 2).crt"
  226.  
  227. multipartCLI = %executable% %params%
  228.  
  229. for index, element in romtable {
  230. currentCart := romtable[A_Index,1]
  231. SplitPath, currentCart,,,, OutFileName
  232. currentCartAddress := IniReadCheck(settingsFile, OutFileName, "CartLoadingAddress", "X000",,1)
  233.  
  234. If (currentCartAddress = "A000")
  235. cartSlot := "-cartA"
  236. Else If (currentCartAddress = "B000")
  237. cartSlot := "-cartB"
  238. Else If (currentCartAddress = "2000")
  239. cartSlot := "-cart2"
  240. Else If (currentCartAddress = "4000")
  241. cartSlot := "-cart4"
  242. Else If (currentCartAddress = "6000")
  243. cartSlot := "-cart6"
  244. Else
  245. ScriptError("Invalid Cart Address Specified: " . CartAddress)
  246.  
  247. multipartCLI = %multipartCLI% %cartSlot% "%currentCart%"
  248. }
  249. Run(multipartCLI, emuPath)
  250. }
  251. Else {
  252. ;singlepart carts - unlike multipart carts, we can directly run the emulator with a single CLI parameter
  253.  
  254. If (CartAddress = "A000")
  255. cartSlot := "-cartA"
  256. Else If (CartAddress = "B000")
  257. cartSlot := "-cartB"
  258. Else If (CartAddress = "2000")
  259. cartSlot := "-cart2"
  260. Else If (CartAddress = "4000")
  261. cartSlot := "-cart4"
  262. Else If (CartAddress = "6000")
  263. cartSlot := "-cart6"
  264. Else
  265. ScriptError("Invalid Cart Address Specified: " . CartAddress)
  266.  
  267. Run(executable . " " . params . " " . cartSlot . " """ . romPath . "\" . romName . romExtension . """", emuPath)
  268. }
  269. }
  270. Else {
  271. ;for non cartridges, update the vice.ini with the proper memory expansion values (if needed) prior to calling the emulator.
  272. varBlock0 = 0
  273. varBlock1 = 0
  274. varBlock2 = 0
  275. varBlock3 = 0
  276. varBlock5 = 0
  277.  
  278. If (MemoryExpansion = "3k") {
  279. varBlock0 = 1
  280. } Else If (MemoryExpansion = "8k") {
  281. varBlock1 = 1
  282. } Else If (MemoryExpansion = "16k") {
  283. varBlock1 = 1
  284. varBlock2 = 1
  285. } Else If (MemoryExpansion = "24k") {
  286. varBlock1 = 1
  287. varBlock2 = 1
  288. varBlock3 = 1
  289. } Else If (MemoryExpansion = "all") {
  290. varBlock0 = 1
  291. varBlock1 = 1
  292. varBlock2 = 1
  293. varBlock3 = 1
  294. varBlock5 = 1
  295. } Else If (MemoryExpansion = "3,5") {
  296. varBlock3 = 1
  297. varBlock5 = 1
  298. } Else If (MemoryExpansion = "5") {
  299. varBlock5 = 1
  300. } Else If (MemoryExpansion = "1,5") {
  301. varBlock1 = 1
  302. varBlock5 = 1
  303. } Else If (MemoryExpansion = "1,2,5") {
  304. varBlock1 = 1
  305. varBlock2 = 1
  306. varBlock5 = 1
  307. }
  308. IniWrite, %varBlock0%, %viceINI%, VIC20, RAMBlock0
  309. IniWrite, %varBlock1%, %viceINI%, VIC20, RAMBlock1
  310. IniWrite, %varBlock2%, %viceINI%, VIC20, RAMBlock2
  311. IniWrite, %varBlock3%, %viceINI%, VIC20, RAMBlock3
  312. IniWrite, %varBlock5%, %viceINI%, VIC20, RAMBlock5
  313.  
  314. Run(executable . " " . params . " """ . romPath . "\" . romName . romExtension . """" , emuPath )
  315. }
  316.  
  317. if (RequiresReset = "true")
  318. {
  319. WinWaitActive("ahk_class VICE")
  320. Sleep, 1000 ; increase if command is not appearing in the emu window or some just some letters
  321. Send !r
  322. }
  323.  
  324. if %Command% {
  325. WinWaitActive("ahk_class VICE")
  326. Sleep, %SendCommandDelay% ; increase if command is not appearing in the emu window or some just some letters
  327. SetKeyDelay, 50
  328. Loop, parse, Command
  329. Send, {%A_LoopField% down}{%A_LoopField% up}
  330. Send, {ENTER down}{ENTER up}
  331. }
  332. }
  333.  
  334. WinWait("ahk_class VICE")
  335. WinWaitActive("ahk_class VICE")
  336.  
  337. BezelDraw()
  338. FadeInExit()
  339. Process("WaitClose", executable)
  340. 7zCleanUp()
  341. FadeOutExit()
  342. ExitModule()
  343.  
  344. JoySwap:
  345. Send !j
  346. Return
  347.  
  348. Warp:
  349. Send !w
  350. Return
  351.  
  352. StartTape:
  353. Send !{F7}
  354. Return
  355.  
  356. StopTape:
  357. Send !{F8}
  358. Return
  359.  
  360. RunTape:
  361. SetKeyDelay, 50
  362. Loop, parse, Command
  363. Send, {%A_LoopField% down}{%A_LoopField% up}
  364. Send, {ENTER down}{ENTER up}
  365. Return
  366.  
  367. HaltEmu:
  368. If (Fullscreen = "true")
  369. Send !{Enter}
  370. Return
  371.  
  372. MultiGame:
  373. Log("MultiGame Label was run!")
  374.  
  375. If romExtension in .d64,.d71,.d80,.d81,.d82,.g64,.g41,.x64,.prg
  376. { Send !8 ; swaps a Disk
  377. wvTitle:="Attach disk image ahk_class #32770"
  378. } Else If romExtension in .t64,.tap
  379. { Send !t ; swaps a Tape
  380. wvTitle:="Attach tape image ahk_class #32770"
  381. } Else
  382. {
  383. ScriptError(romExtension . " is an invalid multi-game extension")
  384. }
  385.  
  386. WinWait(wvTitle)
  387. WinWaitActive(wvTitle)
  388. If ( SelectGameMode = 1 ) {
  389. Loop {
  390. ControlGetText, edit1Text, Edit1, %wvTitle%
  391. If ( edit1Text = selectedRom )
  392. Break
  393. Sleep, 100
  394. ControlSetText, Edit1, %selectedRom%, %wvTitle%
  395. }
  396. ControlSend, Button1, {Enter}, ahk_class #32770 ; Select Open
  397. } Else If ( SelectGameMode = 2 ) {
  398. Clipboard := selectedRom
  399. Send, ^v{Enter}
  400. } Else
  401. ScriptError("You did not choose a valid SelectGameMode.`nOpen the module and set the mode at the top.")
  402. Log("Module - WinWaitActive`, ahk_class VICE`, `, 5")
  403. WinWaitActive("ahk_class VICE",,5)
  404. WinActivate, ahk_class VICE
  405. Return
  406.  
  407. RestoreEmu:
  408. If (Fullscreen = "true")
  409. Send !{Enter}
  410. Return
  411.  
  412. CloseProcess:
  413. FadeOutStart()
  414. BezelExit()
  415. WinClose("ahk_class VICE")
  416. Return
Advertisement
Add Comment
Please, Sign In to add comment