mirror of
https://github.com/Ed94/pikuma_ps1.git
synced 2026-06-01 18:41:13 -07:00
warmup
This commit is contained in:
+14
-15
@@ -20,12 +20,12 @@ function main(args)
|
||||
os.exit(1)
|
||||
end
|
||||
|
||||
print(string.format("Input file: %s", args[1]))
|
||||
print(string.format("Output file: %s", args[2]))
|
||||
-- print(string.format("Input file: %s", args[1]))
|
||||
-- print(string.format("Output file: %s", args[2]))
|
||||
|
||||
-- PS1 executables have a maximum size limit of 2MB
|
||||
local max_size = 0x200000
|
||||
print(string.format("\nChecking input file size (max: %d bytes)...", max_size))
|
||||
-- print(string.format("\nChecking input file size (max: %d bytes)...", max_size))
|
||||
|
||||
local infile_size = file_size(args[1])
|
||||
if not infile_size then
|
||||
@@ -33,14 +33,14 @@ function main(args)
|
||||
os.exit(1)
|
||||
end
|
||||
|
||||
print(string.format("Input file size: %d bytes", infile_size))
|
||||
-- print(string.format("Input file size: %d bytes", infile_size))
|
||||
|
||||
if infile_size > max_size then
|
||||
io.stderr:write(string.format("Error: Input file %s longer than %d bytes\n", args[1], max_size))
|
||||
os.exit(1)
|
||||
end
|
||||
|
||||
print("\nOpening files...")
|
||||
-- print("\nOpening files...")
|
||||
local ofile = io.open(args[2], "wb")
|
||||
if not ofile then
|
||||
io.stderr:write("Error: Cannot open output file " .. args[2] .. "\n")
|
||||
@@ -53,16 +53,15 @@ function main(args)
|
||||
os.exit(1)
|
||||
end
|
||||
|
||||
print("Writing PS-X executable header...")
|
||||
|
||||
-- PS1 executables start with "PS-X EXE" magic string
|
||||
-- print("Writing PS-X executable header...")
|
||||
ofile:write("PS-X EXE")
|
||||
|
||||
-- Write entry point address (where the PS1 will jump to start execution)
|
||||
-- 0x80010000 is a standard entry point in PS1 RAM
|
||||
ofile:seek("set", 0x10)
|
||||
ofile:write(string.pack("<I4", 0x80010000))
|
||||
print(" Entry point: 0x80010000")
|
||||
-- print(" Entry point: 0x80010000")
|
||||
|
||||
-- Initial GP/R28 register value (Global Pointer for data addressing)
|
||||
-- 0xFFFFFFFF means it will be set by crt0.S startup code
|
||||
@@ -70,21 +69,21 @@ function main(args)
|
||||
|
||||
-- Destination address in RAM where the executable will be loaded
|
||||
ofile:write(string.pack("<I4", 0x80010000))
|
||||
print(" Load address: 0x80010000")
|
||||
-- print(" Load address: 0x80010000")
|
||||
|
||||
-- Initial stack pointer (SP/R29) and frame pointer (FP/R30)
|
||||
-- 0x801FFF00 points near the top of the 2MB main RAM
|
||||
ofile:seek("set", 0x30)
|
||||
ofile:write(string.pack("<I4", 0x801FFF00))
|
||||
print(" Stack pointer: 0x801FFF00")
|
||||
-- print(" Stack pointer: 0x801FFF00")
|
||||
|
||||
-- PS1 executables have an 0x800 (2048) byte header
|
||||
-- Zero fill the rest of the header
|
||||
ofile:seek("set", 0x800)
|
||||
print(" Header padding complete (2048 bytes)")
|
||||
-- print(" Header padding complete (2048 bytes)")
|
||||
|
||||
-- Copy the actual program binary data after the header
|
||||
print("\nCopying program data...")
|
||||
-- print("\nCopying program data...")
|
||||
local buffer_size = 0x2000 -- 8KB chunks for efficient copying
|
||||
local bytes_copied = 0
|
||||
|
||||
@@ -118,13 +117,13 @@ function main(args)
|
||||
-- This goes at offset 0x1C in the header
|
||||
ofile:seek("set", 0x1C)
|
||||
ofile:write(string.pack("<I4", exe_size - 0x800))
|
||||
print(string.format("\nProgram size field set to: %d bytes", exe_size - 0x800))
|
||||
-- print(string.format("\nProgram size field set to: %d bytes", exe_size - 0x800))
|
||||
|
||||
ifile:close()
|
||||
ofile:close()
|
||||
|
||||
print(string.format("\nSuccess! PS1 executable created: %s", args[2]))
|
||||
print(string.format("Total file size: %d bytes", exe_size))
|
||||
-- print(string.format("\nSuccess! PS1 executable created: %s", args[2]))
|
||||
print(string.format("Total file size: %d bytes\n", exe_size))
|
||||
end
|
||||
|
||||
-- Run main with command line arguments
|
||||
|
||||
+25
-17
@@ -1,28 +1,36 @@
|
||||
$path_root = split-path -Path $PSScriptRoot -Parent
|
||||
$path_build = join-path $path_root 'build'
|
||||
$path_code = join-path $path_root 'code'
|
||||
$path_scripts = join-path $path_root 'scripts'
|
||||
$path_root = split-path -Path $PSScriptRoot -Parent
|
||||
$path_build = join-path $path_root 'build'
|
||||
$path_code = join-path $path_root 'code'
|
||||
$path_scripts = join-path $path_root 'scripts'
|
||||
$path_toolchain = join-path $path_root 'toolchain'
|
||||
|
||||
if ((test-path $path_build) -eq $false) {
|
||||
new-item -itemtype directory -path $path_build
|
||||
}
|
||||
|
||||
$armips = 'armips'
|
||||
$armips = join-path $path_toolchain 'armips/armips.exe'
|
||||
$bin2exe_lua = join-path $path_scripts 'bin2exe.lua'
|
||||
$bin2exe_py = join-path $path_scripts 'bin2exe.py'
|
||||
|
||||
$path_fillmem = join-path $path_code 'fillmem'
|
||||
$src_fillmem = join-path $path_fillmem 'fillmem.s'
|
||||
$bin_fillmem = join-path $path_build 'fillmem.bin'
|
||||
$exe_fillmem = join-path $path_build 'fillmem.exe'
|
||||
function build-program { param(
|
||||
[string]$module,
|
||||
[string]$unit
|
||||
)
|
||||
$path_module = join-path $path_code $module
|
||||
$src = join-path $path_module "$unit.s"
|
||||
$bin = join-path $path_build "$unit.bin"
|
||||
$exe = join-path $path_build "$unit.exe"
|
||||
|
||||
push-location $path_build
|
||||
write-host "Assembling: $src_fillmem`n"
|
||||
& $armips $src_fillmem
|
||||
push-location $path_build
|
||||
write-host "Assembling: $src`n"
|
||||
& $armips $src
|
||||
|
||||
write-host 'Generating executable..'
|
||||
& lua $bin2exe_lua $bin_fillmem $exe_fillmem
|
||||
# & py $bin2exe_py $bin_fillmem $exe_fillmem
|
||||
write-host 'Generating executable..'
|
||||
& lua $bin2exe_lua $bin $exe
|
||||
# & py $bin2exe_py $bin $exe
|
||||
|
||||
write-host 'Done!'
|
||||
pop-location
|
||||
write-host 'Done!'
|
||||
pop-location
|
||||
}
|
||||
# build-program 'fillmem' 'fillmem'
|
||||
build-program 'warmup' 'exercise1'
|
||||
Reference in New Issue
Block a user