Last active
December 23, 2022 07:47
-
-
Save milnak/51a0dc403a328b8f6311b863e7ad7f3d to your computer and use it in GitHub Desktop.
Parse HTML TR to PowerShell PSCustomObject
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
| # TODO: Should also capture Cycle notes, e.g. | |
| # <td height="26">5 (+1 if page crossed)</td> | |
| $uri = 'https://www.nesdev.org/obelisk-6502-guide/reference.html' | |
| $content = (Invoke-WebRequest -Uri $uri).Content | |
| $regex = '(?s)' | |
| # <tr> | |
| $regex += '<tr>.*?' | |
| # <td width="30%" height="24"><a href="addressing.html#IMP">Implied</a></td> | |
| $regex += '<td.*?><a href="addressing.html#.+?">(?<AddressingMode>.*?)</a>.*?</td>.*?' | |
| # <td width="15%" height="24"> | |
| $regex += '<td.*?>.*?' | |
| # <p><center>$98</center></td> | |
| $regex += '<p.*?>.*?(<center>)?\$(?<Opcode>[0-9a-fA-F]{2})(</center>)?.*?</td>.*?' | |
| # <td width="15%" height="24"> | |
| $regex += '<td.*?>.*?' | |
| # <p><center>1</center></td> | |
| $regex += '<p.*?>.*?(<center>)?(?<Bytes>\d+)(</center>)?.*?</td>.*?' | |
| # <td><center>4 (+1 if page crossed)</center></td> | |
| $regex += '<td.*?>.*?(<center>)?(?<Cycles>\d+)(</center>)?.*?</td>.*?' | |
| # </tr> | |
| $regex += '</tr>' | |
| $opcodes = ($content | Select-String $regex -AllMatches).Matches | ForEach-Object { | |
| [PSCustomObject]@{ | |
| AddressingMode = $_.Groups['AddressingMode'].Value -replace '\(','' -replace '\)','' -replace ',','' -replace ' ','' -replace "`r`n",'' | |
| Opcode = $_.Groups['Opcode'].Value | |
| Bytes = $_.Groups['Bytes'].Value | |
| Cycles = $_.Groups['Cycles'].Value | |
| } | |
| } | Sort-Object Opcode | |
| '// Opcode, AddressingMode, Bytes, Cycles' | |
| $opcodes | ForEach-Object { | |
| ' {{ 0x{0}, AddressingMode::{1,-11}, {2,5}, {3,6} }},' -f $_.Opcode, $_.AddressingMode, $_.Bytes, $_.Cycles | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment