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.

128 Zeilen
6.7KB

  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 border colour (the M3.1 direction indicator); it counts space_ready hits.
  10. Scenarios: no key, right, left (right SHIFT), down, up (left SHIFT), down-right,
  11. up-left, and SPACE held from frame 60 on (must regenerate exactly once).
  12. Exit codes: 0 = pass, 1 = fail, 2 = a tool is missing.
  13. .EXAMPLE
  14. pwsh -File tools/check-keys.ps1
  15. #>
  16. [CmdletBinding()]
  17. param([switch]$NoBuild, [int]$TimeoutSeconds = 180)
  18. . (Join-Path $PSScriptRoot 'lib.ps1')
  19. function Get-Label([hashtable]$Target, [string]$Symbol) {
  20. foreach ($line in Get-Content -LiteralPath (Get-RepoPath $Target.build.labels)) {
  21. $parts = $line -split '\s+'
  22. if ($parts.Count -ge 3 -and $parts[2].TrimStart('.') -eq $Symbol) { return [Convert]::ToInt32($parts[1], 16) }
  23. }
  24. throw "Symbol '$Symbol' not found in $($Target.build.labels)."
  25. }
  26. try {
  27. $project = Get-ProjectConfig
  28. $target = Get-ProjectTargets $project 'c64'
  29. if (-not $NoBuild) { Invoke-TargetBuild $project $target @{} }
  30. $emu = Get-ToolPath $project $target.emulator.binary
  31. } catch [MissingToolException] {
  32. Write-Host $_.Exception.Message -ForegroundColor Yellow
  33. exit 2
  34. }
  35. $hooks = @{}
  36. foreach ($s in 'key_row_cursor', 'key_row_lshift', 'key_row_rshift', 'key_row_space', 'keys_read', 'space_ready', 'scroll_dx') {
  37. $hooks[$s] = Get-Label $target $s
  38. }
  39. # Row bits are active low. Cursor column: RIGHT = bit 2, DOWN = bit 7.
  40. # Left SHIFT = bit 7 of its column, right SHIFT and SPACE = bit 4 of theirs.
  41. # Border colours from src/keys.inc direction_colors.
  42. $scenarios = @(
  43. @{ name = 'no key'; cursor = 'ff'; lshift = 'ff'; rshift = 'ff'; dx = 0; dy = 0; border = 9 }
  44. @{ name = 'CRSR RIGHT'; cursor = 'fb'; lshift = 'ff'; rshift = 'ff'; dx = 1; dy = 0; border = 13 }
  45. @{ name = 'right SHIFT+CRSR RIGHT'; cursor = 'fb'; lshift = 'ff'; rshift = 'ef'; dx = -1; dy = 0; border = 3 }
  46. @{ name = 'CRSR DOWN'; cursor = '7f'; lshift = 'ff'; rshift = 'ff'; dx = 0; dy = 1; border = 7 }
  47. @{ name = 'left SHIFT+CRSR DOWN'; cursor = '7f'; lshift = '7f'; rshift = 'ff'; dx = 0; dy = -1; border = 1 }
  48. @{ name = 'CRSR RIGHT+DOWN'; cursor = '7b'; lshift = 'ff'; rshift = 'ff'; dx = 1; dy = 1; border = 8 }
  49. @{ name = 'left SHIFT+RIGHT+DOWN'; cursor = '7b'; lshift = '7f'; rshift = 'ff'; dx = -1; dy = -1; border = 14 }
  50. @{ name = 'SPACE held'; cursor = 'ff'; lshift = 'ff'; rshift = 'ff'; space = 'ef'; spaceAfter = 60; dx = 0; dy = 0; border = 9; regenerations = 1 }
  51. )
  52. $root = Get-RepoPath 'build/check-keys'
  53. if (Test-Path -LiteralPath $root) { Remove-Item -LiteralPath $root -Recurse -Force }
  54. $failed = 0
  55. $index = 0
  56. foreach ($sc in $scenarios) {
  57. $index++
  58. $dir = Join-Path $root ("{0:d2}" -f $index)
  59. New-Item -ItemType Directory -Force -Path $dir | Out-Null
  60. $mon = [System.Collections.Generic.List[string]]::new()
  61. $mon.Add('logname "monitor.log"'); $mon.Add('log on')
  62. $n = 0
  63. $add = {
  64. param($addr, $cmd)
  65. $script:n++
  66. $mon.Add(('trace exec ${0:x4}' -f $addr)); $mon.Add(('command {0} "{1}"' -f $script:n, $cmd))
  67. }
  68. & $add $hooks.key_row_cursor "r a = $($sc.cursor)"
  69. & $add $hooks.key_row_lshift "r a = $($sc.lshift)"
  70. & $add $hooks.key_row_rshift "r a = $($sc.rshift)"
  71. if ($sc.space) {
  72. & $add $hooks.key_row_space "r a = $($sc.space)"
  73. $mon.Add(('ignore {0} {1}' -f $n, $sc.spaceAfter))
  74. } else {
  75. & $add $hooks.key_row_space 'r a = ff'
  76. }
  77. & $add $hooks.keys_read ('m {0:x4} {1:x4}' -f $hooks.scroll_dx, ($hooks.scroll_dx + 1))
  78. & $add $hooks.keys_read 'm d020 d020'
  79. $spaceCheckpoint = $n + 1
  80. & $add $hooks.space_ready 'm d020 d020'
  81. Set-Content -LiteralPath (Join-Path $dir 'monitor.txt') -Value $mon
  82. Set-Content -LiteralPath (Join-Path $dir 'vicerc') -Value ''
  83. $cycles = if ($sc.space) { 20000000 } else { 6000000 }
  84. $vargs = @('-config', 'vicerc', '-default', '-sounddev', 'dummy', '-warp', '-minimized') + (Get-VideoArgs $target)
  85. $vargs += @('-limitcycles', [string]$cycles, '-moncommands', 'monitor.txt', '-autostartprgmode', '1', '-autostart', (Get-AutostartFile $target))
  86. $quoted = $vargs | ForEach-Object { if ($_ -match '[\s"]') { '"' + $_ + '"' } else { $_ } }
  87. $p = Start-Process -FilePath $emu -ArgumentList $quoted -WorkingDirectory $dir -PassThru `
  88. -RedirectStandardOutput (Join-Path $dir 'vice.log') -RedirectStandardError (Join-Path $dir 'vice.err')
  89. if (-not $p.WaitForExit($TimeoutSeconds * 1000)) { $p.Kill($true) }
  90. $log = Join-Path $dir 'monitor.log'
  91. $scroll = $null; $border = $null; $frames = 0; $regenerations = 0
  92. if (Test-Path -LiteralPath $log) {
  93. foreach ($line in Get-Content -LiteralPath $log) {
  94. if ($line -match ('^#{0} \(Trace' -f $spaceCheckpoint)) { $regenerations++ }
  95. elseif ($line -match ('^>C:{0:x4}\s+([0-9a-f]{{2}}) ([0-9a-f]{{2}})' -f $hooks.scroll_dx)) {
  96. $scroll = @([Convert]::ToByte($Matches[1], 16), [Convert]::ToByte($Matches[2], 16)) | ForEach-Object { if ($_ -ge 128) { $_ - 256 } else { [int]$_ } }; $frames++
  97. } elseif ($line -match '^>C:d020\s+([0-9a-f]{2})') { $border = [Convert]::ToByte($Matches[1], 16) -band 0x0F }
  98. }
  99. }
  100. $problems = @()
  101. if ($frames -lt 30) { $problems += "only $frames frames reached keys_read" }
  102. elseif ($scroll[0] -ne $sc.dx -or $scroll[1] -ne $sc.dy) { $problems += "scroll ($($scroll[0]),$($scroll[1])), expected ($($sc.dx),$($sc.dy))" }
  103. if ($null -ne $border -and $border -ne $sc.border) { $problems += "border colour $border, expected $($sc.border)" }
  104. $wantRegen = if ($sc.regenerations) { $sc.regenerations } else { 0 }
  105. if ($regenerations -ne $wantRegen) { $problems += "$regenerations regenerations, expected $wantRegen" }
  106. if ($problems.Count -gt 0) {
  107. $failed++
  108. Write-Host (" FAIL {0}: {1}" -f $sc.name, ($problems -join '; ')) -ForegroundColor Red
  109. } else {
  110. $extra = if ($sc.space) { ", $regenerations regeneration while held" } else { '' }
  111. Write-Host (" ok {0}: scroll ({1},{2}), border {3}, {4} frames{5}" -f $sc.name, $scroll[0], $scroll[1], $border, $frames, $extra)
  112. }
  113. }
  114. if ($failed -gt 0) { Write-Host "[FAIL] $failed of $($scenarios.Count) key scenarios" -ForegroundColor Red; exit 1 }
  115. Write-Host "[PASS] all $($scenarios.Count) key scenarios decode correctly" -ForegroundColor Green
  116. exit 0

Powered by TurnKey Linux.