Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

166 Zeilen
9.3KB

  1. <#
  2. .SYNOPSIS
  3. Check the keyboard matrix decoding of the C64 build headless in VICE.
  4. .DESCRIPTION
  5. VICE's monitor cannot press keys, so each scenario fakes held keys instead:
  6. tracepoints on the instructions that store the port B row bits (key_row_cursor,
  7. key_row_lshift, key_row_rshift, key_row_space in src/keys.inc) run "r a = <bits>",
  8. as if those keys were held down. At keys_read the script logs scroll_dx, scroll_dy and
  9. the frames that reached it; it counts space_ready hits. (The M3.1 border-colour
  10. direction indicator was removed in M3.3, so the border is no longer checked.)
  11. Scenarios: no key, right, left (right SHIFT), down, up (left SHIFT), down-right,
  12. up-left, SPACE held from frame 60 on (must regenerate exactly once), and P held from
  13. frame 60 on (R8: must step to the next person exactly once). In every scenario the
  14. people's scores must be 3-18 and status line 4 (text screen 1 of buffer A) must show
  15. the shown person's number and six scores.
  16. Exit codes: 0 = pass, 1 = fail, 2 = a tool is missing.
  17. .EXAMPLE
  18. pwsh -File tools/check-keys.ps1
  19. #>
  20. [CmdletBinding()]
  21. param([switch]$NoBuild, [int]$TimeoutSeconds = 180)
  22. . (Join-Path $PSScriptRoot 'lib.ps1')
  23. function Get-Label([hashtable]$Target, [string]$Symbol) {
  24. foreach ($line in Get-Content -LiteralPath (Get-RepoPath $Target.build.labels)) {
  25. $parts = $line -split '\s+'
  26. if ($parts.Count -ge 3 -and $parts[2].TrimStart('.') -eq $Symbol) { return [Convert]::ToInt32($parts[1], 16) }
  27. }
  28. throw "Symbol '$Symbol' not found in $($Target.build.labels)."
  29. }
  30. try {
  31. $project = Get-ProjectConfig
  32. $target = Get-ProjectTargets $project 'c64'
  33. if (-not $NoBuild) { Invoke-TargetBuild $project $target @{} }
  34. $emu = Get-ToolPath $project $target.emulator.binary
  35. } catch [MissingToolException] {
  36. Write-Host $_.Exception.Message -ForegroundColor Yellow
  37. exit 2
  38. }
  39. $hooks = @{}
  40. foreach ($s in 'key_row_cursor', 'key_row_lshift', 'key_row_rshift', 'key_row_space', 'key_row_p', 'keys_read', 'space_ready', 'scroll_dx',
  41. 'people_attr', 'shown_person') {
  42. $hooks[$s] = Get-Label $target $s
  43. }
  44. # Row bits are active low. Cursor column: RIGHT = bit 2, DOWN = bit 7.
  45. # Left SHIFT = bit 7 of its column, right SHIFT and SPACE = bit 4 of theirs.
  46. $scenarios = @(
  47. @{ name = 'no key'; cursor = 'ff'; lshift = 'ff'; rshift = 'ff'; dx = 0; dy = 0 }
  48. @{ name = 'CRSR RIGHT'; cursor = 'fb'; lshift = 'ff'; rshift = 'ff'; dx = 1; dy = 0 }
  49. @{ name = 'right SHIFT+CRSR RIGHT'; cursor = 'fb'; lshift = 'ff'; rshift = 'ef'; dx = -1; dy = 0 }
  50. @{ name = 'CRSR DOWN'; cursor = '7f'; lshift = 'ff'; rshift = 'ff'; dx = 0; dy = 1 }
  51. @{ name = 'left SHIFT+CRSR DOWN'; cursor = '7f'; lshift = '7f'; rshift = 'ff'; dx = 0; dy = -1 }
  52. @{ name = 'CRSR RIGHT+DOWN'; cursor = '7b'; lshift = 'ff'; rshift = 'ff'; dx = 1; dy = 1 }
  53. @{ name = 'left SHIFT+RIGHT+DOWN'; cursor = '7b'; lshift = '7f'; rshift = 'ff'; dx = -1; dy = -1 }
  54. @{ name = 'SPACE held'; cursor = 'ff'; lshift = 'ff'; rshift = 'ff'; space = 'ef'; spaceAfter = 60; dx = 0; dy = 0; regenerations = 1 }
  55. @{ name = 'P held'; cursor = 'ff'; lshift = 'ff'; rshift = 'ff'; p = 'fd'; pAfter = 60; dx = 0; dy = 0; person = 1 }
  56. )
  57. $STATUS_LINE4 = 0x4000 + 0x0400 + 23 * 40 # buffer A, text screen 1, row 23 (src/status.inc)
  58. $root = Get-RepoPath 'build/check-keys'
  59. if (Test-Path -LiteralPath $root) { Remove-Item -LiteralPath $root -Recurse -Force }
  60. $failed = 0
  61. $index = 0
  62. foreach ($sc in $scenarios) {
  63. $index++
  64. $dir = Join-Path $root ("{0:d2}" -f $index)
  65. New-Item -ItemType Directory -Force -Path $dir | Out-Null
  66. $mon = [System.Collections.Generic.List[string]]::new()
  67. $mon.Add('logname "monitor.log"'); $mon.Add('log on')
  68. $n = 0
  69. $add = {
  70. param($addr, $cmd)
  71. $script:n++
  72. $mon.Add(('trace exec ${0:x4}' -f $addr)); $mon.Add(('command {0} "{1}"' -f $script:n, $cmd))
  73. }
  74. & $add $hooks.key_row_cursor "r a = $($sc.cursor)"
  75. & $add $hooks.key_row_lshift "r a = $($sc.lshift)"
  76. & $add $hooks.key_row_rshift "r a = $($sc.rshift)"
  77. if ($sc.space) {
  78. & $add $hooks.key_row_space "r a = $($sc.space)"
  79. $mon.Add(('ignore {0} {1}' -f $n, $sc.spaceAfter))
  80. } else {
  81. & $add $hooks.key_row_space 'r a = ff'
  82. }
  83. if ($sc.p) {
  84. & $add $hooks.key_row_p "r a = $($sc.p)"
  85. $mon.Add(('ignore {0} {1}' -f $n, $sc.pAfter))
  86. } else {
  87. & $add $hooks.key_row_p 'r a = ff'
  88. }
  89. & $add $hooks.keys_read ('m {0:x4} {1:x4}' -f $hooks.scroll_dx, ($hooks.scroll_dx + 1))
  90. & $add $hooks.keys_read ('m {0:x4} {1:x4}' -f $hooks.people_attr, ($hooks.people_attr + 95))
  91. & $add $hooks.keys_read ('m {0:x4} {0:x4}' -f $hooks.shown_person)
  92. & $add $hooks.keys_read ('m {0:x4} {1:x4}' -f $STATUS_LINE4, ($STATUS_LINE4 + 39))
  93. $spaceCheckpoint = $n + 1
  94. & $add $hooks.space_ready 'r'
  95. Set-Content -LiteralPath (Join-Path $dir 'monitor.txt') -Value $mon
  96. Set-Content -LiteralPath (Join-Path $dir 'vicerc') -Value ''
  97. $cycles = if ($sc.space) { 26000000 } else { 12000000 }
  98. $vargs = @('-config', 'vicerc', '-default', '-sounddev', 'dummy', '-warp', '-minimized') + (Get-VideoArgs $target)
  99. $vargs += @('-limitcycles', [string]$cycles, '-moncommands', 'monitor.txt', '-autostartprgmode', '1', '-autostart', (Get-AutostartFile $target))
  100. $quoted = $vargs | ForEach-Object { if ($_ -match '[\s"]') { '"' + $_ + '"' } else { $_ } }
  101. $p = Start-Process -FilePath $emu -ArgumentList $quoted -WorkingDirectory $dir -PassThru `
  102. -RedirectStandardOutput (Join-Path $dir 'vice.log') -RedirectStandardError (Join-Path $dir 'vice.err')
  103. if (-not $p.WaitForExit($TimeoutSeconds * 1000)) { $p.Kill($true) }
  104. $log = Join-Path $dir 'monitor.log'
  105. $scroll = $null; $frames = 0; $regenerations = 0
  106. $dumps = @{}; $dumpAddr = -1 # last frame's dumps: address -> bytes (a dump spans several lines)
  107. if (Test-Path -LiteralPath $log) {
  108. foreach ($line in Get-Content -LiteralPath $log) {
  109. if ($line -match '^>C:([0-9a-f]{4})\s+((?:[0-9a-f]{2} )+)') {
  110. $a = [Convert]::ToInt32($Matches[1], 16)
  111. $bytes = @($Matches[2].Trim() -split ' ' | ForEach-Object { [Convert]::ToByte($_, 16) })
  112. if ($a -in $hooks.people_attr, $hooks.shown_person, $STATUS_LINE4) { $dumpAddr = $a; $dumps[$a] = [System.Collections.Generic.List[byte]]::new() }
  113. elseif ($a -ne $hooks.scroll_dx -and $dumpAddr -ge 0 -and $a -eq $dumpAddr + $dumps[$dumpAddr].Count) { }
  114. else { $dumpAddr = -1 }
  115. if ($dumpAddr -ge 0) { $dumps[$dumpAddr].AddRange([byte[]]$bytes) }
  116. }
  117. if ($line -match ('^#{0} \(Trace' -f $spaceCheckpoint)) { $regenerations++ }
  118. elseif ($line -match ('^>C:{0:x4}\s+([0-9a-f]{{2}}) ([0-9a-f]{{2}})' -f $hooks.scroll_dx)) {
  119. $scroll = @([Convert]::ToByte($Matches[1], 16), [Convert]::ToByte($Matches[2], 16)) | ForEach-Object { if ($_ -ge 128) { $_ - 256 } else { [int]$_ } }; $frames++
  120. }
  121. }
  122. }
  123. $problems = @()
  124. if ($frames -lt 30) { $problems += "only $frames frames reached keys_read" }
  125. elseif ($scroll[0] -ne $sc.dx -or $scroll[1] -ne $sc.dy) { $problems += "scroll ($($scroll[0]),$($scroll[1])), expected ($($sc.dx),$($sc.dy))" }
  126. # R8: scores 3-18; status line 4 shows "Pnn" and the six scores of the shown person.
  127. $wantPerson = if ($sc.person) { $sc.person } else { 0 }
  128. if (@($hooks.people_attr, $hooks.shown_person, $STATUS_LINE4) | Where-Object { -not $dumps.ContainsKey($_) -or $dumps[$_].Count -eq 0 }) { $problems += 'scores or status line 4 not logged' }
  129. else {
  130. $attr = $dumps[$hooks.people_attr]; $shown = $dumps[$hooks.shown_person][0]; $line4 = $dumps[$STATUS_LINE4]
  131. $bad = @($attr[0..95] | Where-Object { $_ -lt 3 -or $_ -gt 18 })
  132. if ($bad.Count) { $problems += "$($bad.Count) scores outside 3-18" }
  133. if ($shown -ne $wantPerson) { $problems += "shown person $($shown + 1), expected $($wantPerson + 1)" }
  134. $digits = { param($at) ($line4[$at] - 0x30) * 10 + ($line4[$at + 1] - 0x30) }
  135. if ((& $digits 1) -ne $shown + 1) { $problems += "status shows person $(& $digits 1), expected $($shown + 1)" }
  136. for ($k = 0; $k -lt 6; $k++) {
  137. if ((& $digits (7 + 6 * $k)) -ne $attr[6 * $shown + $k]) { $problems += "status score $($k + 1) shows $(& $digits (7 + 6 * $k)), expected $($attr[6 * $shown + $k])"; break }
  138. }
  139. $scoresText = ($attr[(6 * $shown)..(6 * $shown + 5)] -join ' ')
  140. }
  141. $wantRegen = if ($sc.regenerations) { $sc.regenerations } else { 0 }
  142. if ($regenerations -ne $wantRegen) { $problems += "$regenerations regenerations, expected $wantRegen" }
  143. if ($problems.Count -gt 0) {
  144. $failed++
  145. Write-Host (" FAIL {0}: {1}" -f $sc.name, ($problems -join '; ')) -ForegroundColor Red
  146. } else {
  147. $extra = if ($sc.space) { ", $regenerations regeneration while held" } else { '' }
  148. $extra += ", person $($wantPerson + 1) shown: $scoresText"
  149. Write-Host (" ok {0}: scroll ({1},{2}), {3} frames{4}" -f $sc.name, $scroll[0], $scroll[1], $frames, $extra)
  150. }
  151. }
  152. if ($failed -gt 0) { Write-Host "[FAIL] $failed of $($scenarios.Count) key scenarios" -ForegroundColor Red; exit 1 }
  153. Write-Host "[PASS] all $($scenarios.Count) key scenarios decode correctly" -ForegroundColor Green
  154. exit 0

Powered by TurnKey Linux.