-
Notifications
You must be signed in to change notification settings - Fork 0
/
EmptyRomGenerator.ps1
43 lines (36 loc) · 1.75 KB
/
EmptyRomGenerator.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# This script was generated by ChatGPT using the prompt:
# Good afternoon. I need a PowerShell script that will output a text file to represent the contents of an empty ram. The script should take the ROM size in bytes and output a text file with each byte represented in hex. An example would be x"00" . This file will be pasted into VHDL which needs that format to represent a hex value.
# The script should output 4 bytes per line and output the number of bytes specified, each byte set to 00
# Can you update the script to output, in VHDL comment format, the address every 128 bytes, this way users can easily see what address a block text relates to
# Can you add a trailing comma to each line, except for the last line?
param (
[int]$RomSize = 1024,
[string]$OutputFile = "output.txt"
)
# Initialize an empty array to store each line's contents
$lineArray = @()
# Open the output file for writing
$outputStream = [System.IO.StreamWriter] $OutputFile
# Loop through the specified ROM size
for ($i = 1; $i -le $RomSize; $i++) {
# Add a VHDL comment for the address every 128 bytes
if (($i - 1) % 128 -eq 0) {
$addressComment = "-- Address: 0x" + "{0:X4}" -f ($i - 1)
$outputStream.WriteLine($addressComment)
}
# Add the hex byte to the current line array
$lineArray += 'x"00"'
# If the current line has 4 bytes, write it to the file
if ($i % 4 -eq 0) {
$lineText = ($lineArray -join ', ')
# Add trailing comma except for the last line
if ($i -ne $RomSize) {
$lineText += ","
}
$outputStream.WriteLine($lineText)
# Clear the current line array
$lineArray = @()
}
}
# Close the output file
$outputStream.Close()