rom4x/rom5x/Rakefile

169 lines
4.1 KiB
Ruby
Raw Normal View History

rom_url = 'https://mirrors.apple2.org.za/Apple%20II%20Documentation%20Project/Computers/Apple%20II/Apple%20IIc%20plus/ROM%20Images/Apple%20IIc%20plus%20ROM%2005%20-%20342-0625-A%20-%201988.bin'
source_rom = 'iic+_rom5.bin'
source_rom_sha256 = '5a62070f6a0b07784681d4df4bf2ce88b2809bec0cbaa65fcb963e804ed60374'
dest_rom = 'iic+_rom5x.bin'
distzip = 'iic+_rom5x.zip'
2017-01-29 23:38:12 +00:00
rom_base = 0xc000
source_files = Rake::FileList.new('*.s')
desc "Default: clean and build it"
task :default => [:clean, :assemble, :build_rom] do
sh "ls -l #{dest_rom}"
end
task :zip => [:clean, :assemble, :build_zip] do
sh "ls -l #{dest_rom}"
end
2017-01-29 23:38:12 +00:00
desc "Clean object files"
task :clean do
sh "rm -f #{dest_rom}"
2017-03-11 08:19:40 +00:00
sh "rm -f sf512_#{dest_rom}"
2017-03-19 03:00:43 +00:00
sh "rm -f *.o"
sh "rm -f *.lst"
sh "rm -f *.b"
sh "rm -f accel5x"
sh "rm -f POOF1 *.po"
sh "rm -f rom.sha256"
sh "rm -f make_rom.sh"
sh "rm -f #{distzip}"
end
desc 'Obtain ROM'
rule source_rom do
require 'open-uri'
puts "Downloading ROM..."
File.open(source_rom, "wb") do |romfile|
open(rom_url) do |wwwfile|
romfile.write(wwwfile.read)
end
end
end
desc "Verify ROM Checksum"
task :checksum_rom => source_rom do
require 'digest'
sha256 = Digest::SHA256.file source_rom
fail "ROM checksum failed" unless sha256.hexdigest == source_rom_sha256
puts "Source ROM appears correct!"
2017-01-29 23:38:12 +00:00
end
desc "Assemble all source files"
2017-03-19 03:00:43 +00:00
task :assemble => source_files.ext('.b')
2017-01-29 23:38:12 +00:00
2017-03-19 03:00:43 +00:00
rule ".o" => ".s" do |t|
sh "ca65 -l #{t.name}.lst #{t.source}"
end
rule ".b" => ".o" do |t|
sh "ld65 -t none -o #{t.name} #{t.source}"
2017-01-29 23:38:12 +00:00
end
desc "Build ROM"
task :build_rom => [:assemble, :checksum_rom] do
2017-01-29 23:38:12 +00:00
puts "Building ROM image..."
2017-03-19 03:00:43 +00:00
obj_files = Rake::FileList.new('*.b')
2017-01-29 23:38:12 +00:00
rom = File.read(source_rom)
obj_files.each do |t|
if t =~ /B(\h)_(\h{4})/
bnum = $1.to_i(16)
badd = $2.to_i(16)
addr = bnum * 16384 + badd - rom_base
fc = File.read(t)
fl = fc.bytes.count
puts "Loading #{t} into bank #{bnum} @ $#{badd.to_s(16)}, file addr $#{addr.to_s(16)}, len $#{fl.to_s(16)} (#{fl})"
nzc = 0
2017-01-29 23:38:12 +00:00
fc.each_byte do |b|
2017-03-17 03:07:36 +00:00
nzc += 1 if rom.getbyte(addr) != 0 && rom.getbyte(addr) != b
2017-01-29 23:38:12 +00:00
rom.setbyte(addr, b)
addr += 1
end
puts "\tNote: patched over #{nzc} nonzero bytes!" if nzc > 0
2017-01-29 23:38:12 +00:00
else
puts "I dont know where to load #{t}"
end
end
File.write(dest_rom, rom)
puts "ROM image done: #{dest_rom}"
end
desc "Build SST27SF512 Image"
task :sf512 => [:build_rom] do
sh "cat #{dest_rom} #{dest_rom} > sf512_#{dest_rom}"
end
desc "Build accel5x test binary"
task :accel5x do
sh "ca65 -D testaccel -o accel5x.o -l accel5x.lst B1_FD00_accel5x.s"
sh "ld65 -t none -o accel5x accel5x.o"
end
desc "Build accel5x test binary into accel5x.po disk image"
task :"accel5x.po" => [:accel5x] do
sh "to_pro -140 accel5x"
sh "mv -f POOF1 accel5x.po"
end
desc "Build disributable ZIP"
task :build_zip => [:build_rom] do
require 'digest'
require 'date'
sha256 = Digest::SHA256.file dest_rom
shafile = <<EOF
#{source_rom_sha256} #{source_rom}
#{sha256.hexdigest} #{dest_rom}
EOF
dd_cmds = []
puts "Building distributable ZIP..."
obj_files = Rake::FileList.new('*.b')
obj_files.each do |t|
if t =~ /B(\h)_(\h{4})/
bnum = $1.to_i(16)
badd = $2.to_i(16)
addr = bnum * 16384 + badd - rom_base
dd_cmds << "dd if=#{t} of=#{dest_rom} bs=1 seek=#{addr} conv=notrunc"
sh "zip #{distzip} #{t}"
end
end
puts "Creating maker script..."
script = <<EOF
#!/bin/bash
set -e
BDATE="#{DateTime.now.to_s}"
ROM_URL="#{rom_url}"
echo ${BDATE}
if [ -e `which curl` ]; then
curl -s "${ROM_URL}" > #{source_rom}
elif [ -e `which wget` ]; then
wget -O #{source_rom} "${ROM_URL}"
else
echo "Can't download source ROM image!"
fi
cp #{source_rom} #{dest_rom}
#{dd_cmds.join("\n")}
if [ -e `which shasum` ]; then
shasum -a 256 -c rom.sha256
elif [ -e "sha256sum" ]; then
sha256sum -c rom.sha256
else
echo "Please check the .bin files against rom.sha256"
fi
echo "#{dest_rom} created!"
EOF
File.write('rom.sha256', shafile)
File.write('make_rom.sh', script)
sh "zip #{distzip} rom.sha256 make_rom.sh"
end