Last active
December 11, 2024 12:46
-
-
Save francisdb/b30916924d579ba687ed5d2795a533d9 to your computer and use it in GitHub Desktop.
Log PinMAME NVRAM Changes in Visual Pinball
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Copy nvram_log.vbs in your vpinball scripts folder (or next to the table). | |
' put this before any controller / LoadVPM code | |
Const UseVPMNVRAM = true | |
' put this after LoadVPM | |
' Set this to False to disable printing of old bytes | |
Dim printOldBytes: printOldBytes = False | |
' Add the locations you want to skip here | |
Dim skipLocationRanges: skipLocationRanges = Array(Array(0, 50), Array(138, 138)) | |
' Load the NVRAM logger | |
ExecuteGlobal GetTextFile("nvram_log.vbs") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub OnNvCallBackChanged(data) | |
' Delivers an array with for each element an array [location, new_value, old_value] | |
Dim i, startLocation, length, oldBytes, newBytes | |
startLocation = -1 | |
length = 0 | |
oldBytes = "" | |
newBytes = "" | |
For i = 0 To UBound(data) | |
If startLocation = -1 Then | |
startLocation = data(i, 0) | |
length = 1 | |
oldBytes = FormatHex(data(i, 2), 2) | |
newBytes = FormatHex(data(i, 1), 2) | |
ElseIf data(i, 0) = startLocation + length Then | |
length = length + 1 | |
oldBytes = oldBytes & " " & FormatHex(data(i, 2), 2) | |
newBytes = newBytes & " " & FormatHex(data(i, 1), 2) | |
Else | |
PrintNvramChange startLocation, oldBytes, newBytes | |
startLocation = data(i, 0) | |
length = 1 | |
oldBytes = FormatHex(data(i, 2), 2) | |
newBytes = FormatHex(data(i, 1), 2) | |
End If | |
Next | |
PrintNvramChange startLocation, oldBytes, newBytes | |
End Sub | |
Sub PrintNvramChange(startLocation, oldBytes, newBytes) | |
If startLocation <> -1 And Not IsInRange(startLocation, skipLocationRanges) Then | |
If printOldBytes Then | |
debug.print "NVRAM: @ " & Right(" " & startLocation, 6) & " (0x" & FormatHex(startLocation, 4) & ") " & oldBytes & " => " & newBytes | |
Else | |
debug.print "NVRAM: @ " & Right(" " & startLocation, 6) & " (0x" & FormatHex(startLocation, 4) & ") " & newBytes | |
End If | |
End If | |
End Sub | |
Function IsInRange(value, ranges) | |
Dim range | |
For Each range In ranges | |
If value >= range(0) And value <= range(1) Then | |
IsInRange = True | |
Exit Function | |
End If | |
Next | |
IsInRange = False | |
End Function | |
Function FormatHex(value, digits) | |
FormatHex = Right(String(digits, "0") & Hex(value), digits) | |
End Function | |
' For debugging purposes | |
Sub PrintNVRAMRange(startLocation, endLocation) | |
Dim NVRAM : NVRAM = Controller.NVRAM | |
Dim i | |
Dim range: range = "" | |
For i = startLocation To endLocation | |
Dim value : value = NVRAM(i) | |
range = range & " " & FormatHex(value, 2) | |
Next | |
debug.print "NVRAM " & startLocation & "-" & endLocation & " = " & range | |
End Sub | |
NVRAMCallback = GetRef("OnNvCallBackChanged") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2024-12-08 23:33:09.509 INFO [1817193] [DebuggerModule::Print@4272] Script.Print 'NVRAM: @ 103 (0x0067) 1F 0F' | |
2024-12-08 23:33:09.509 INFO [1817193] [DebuggerModule::Print@4272] Script.Print 'NVRAM: @ 107 (0x006B) 0F' | |
2024-12-08 23:33:09.510 INFO [1817193] [DebuggerModule::Print@4272] Script.Print 'NVRAM: @ 72 (0x0048) 0F 0F FF' | |
2024-12-08 23:33:09.510 INFO [1817193] [DebuggerModule::Print@4272] Script.Print 'NVRAM: @ 79 (0x004F) 1F 0F FF FF 0F' | |
2024-12-08 23:33:11.908 INFO [1817193] [DebuggerModule::Print@4272] Script.Print 'NVRAM: @ 58 (0x003A) 0F' | |
2024-12-08 23:33:11.917 INFO [1817193] [DebuggerModule::Print@4272] Script.Print 'NVRAM: @ 51 (0x0033) 0F 0F' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unfortunately this only reports differences and not actual write requests. So if a score is updated you will not get updates for the unchanged digits.