Integrated disk image generation into PackPartitions.

This commit is contained in:
Martin Haye 2016-01-24 12:37:11 -08:00
parent f239bd4ac2
commit c445c9808f
6 changed files with 46 additions and 93 deletions

View File

@ -27,6 +27,8 @@ dist.jar=${dist.dir}/PackPartitions.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
file.reference.A2Copy.jar=../A2Copy/dist/A2Copy.jar
file.reference.ac.jar=../A2Copy/dist/lib/ac.jar
file.reference.acme.jar=../ACME/src/acme.jar
file.reference.lz4-1.1.1.jar=/Users/mhaye/LL/repo/Platform/Apple/tools/PackPartitions/lib/lz4-1.1.1.jar
file.reference.plasm.jar=../PLASMA/src/plasm.jar
@ -36,7 +38,9 @@ javac.classpath=\
${file.reference.lz4-1.1.1.jar}:\
${libs.groovy-all.classpath}:\
${file.reference.plasm.jar}:\
${file.reference.acme.jar}
${file.reference.acme.jar}:\
${file.reference.A2Copy.jar}:\
${file.reference.ac.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false

View File

@ -19,6 +19,8 @@ import java.nio.ByteBuffer
import java.nio.channels.Channels
import net.jpountz.lz4.LZ4Factory
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.util.zip.GZIPInputStream
/**
*
@ -60,8 +62,6 @@ class PackPartitions
def debugCompression = false
def javascriptOut = null
def currentContext = []
def nWarnings = 0
@ -527,54 +527,6 @@ class PackPartitions
}
}
/**
* Dump map data to Javascript code, to help in debugging the raycaster. This way,
* the Javascript version can run the same map, and we can compare its results to
* the 6502 results.
*/
def dumpJsMap(rows, texMap)
{
def width = rows[0].size()+2
// Write the map data. First comes the sentinel row.
javascriptOut.println("var map = [")
javascriptOut.print(" [")
(0..<width).each { javascriptOut.print("-1,") }
javascriptOut.println("],")
// Now the real map data
rows.each { row ->
javascriptOut.print(" [-1,")
row.each { tile ->
def b = texMap[tile?.@id]
if ((b & 0x80) == 0)
javascriptOut.format("%2d,", b)
else
javascriptOut.print(" 0,")
}
javascriptOut.println("-1,],")
}
// Finish the map data with another sentinel row
javascriptOut.print(" [")
(0..<width).each { javascriptOut.print("-1,") }
javascriptOut.println("]")
javascriptOut.println("];\n")
// Then write out the sprites
javascriptOut.println("var allSprites = [")
rows.eachWithIndex { row, y ->
row.eachWithIndex { tile, x ->
def b = texMap[tile?.@id]
if ((b & 0x80) != 0) {
// y+1 below to account for initial sentinel row
javascriptOut.format(" {type:%2d, x:%2d.5, y:%2d.5},\n", b & 0x7f, x, y+1)
}
}
}
javascriptOut.println("];\n")
}
def write3DMap(buf, mapName, rows, scriptModule, locationsWithTriggers) // [ref BigBlue1_50]
{
def width = rows[0].size() + 2 // Sentinel $FF at start and end of each row
@ -642,9 +594,6 @@ class PackPartitions
// Sentinel row of $FF at end of map
(0..<width).each { buf.put((byte)0xFF) }
if (javascriptOut)
dumpJsMap(rows, texMap)
}
// The renderer wants bits of the two pixels interleaved in a special way.
@ -1356,7 +1305,7 @@ class PackPartitions
compileModule("gen_enemies", "src/plasma/")
}
def pack(xmlPath, binPath, javascriptPath)
def pack(xmlPath)
{
// Read in code chunks. For now these are hard coded, but I guess they ought to
// be configured in a config file somewhere...?
@ -1471,14 +1420,12 @@ class PackPartitions
printWarning "map name '${map?.@name}' should contain '2D' or '3D'. Skipping."
}
// Ready to start writing the output file.
// Ready to write the output file.
println "Writing output file."
new File("build/root").mkdir()
def binPath = new File("build/root/game.part.0.bin").path
new File(binPath).withOutputStream { stream -> writePartition(stream) }
// Finish up Javacript if necessary
if (javascriptPath)
javascriptOut.close()
// Lastly, print stats
println "Compression saved $compressionSavings bytes."
if (compressionSavings > 0) {
@ -1487,8 +1434,6 @@ class PackPartitions
def savPct = String.format("%.1f", compressionSavings * 100.0 / origSize)
println "Size $origSize -> $endSize ($savPct% savings)"
}
println "Done."
}
def isAlnum(ch)
@ -1699,6 +1644,22 @@ class PackPartitions
}
}
def createImage()
{
// Copy the PLASMA VM file to the output directory
Files.copy(new File("PLVM02.SYSTEM.sys").toPath(), new File("build/root/PLVM02.SYSTEM.sys").toPath())
// Copy the memory manager to the output directory
Files.copy(new File("src/core/build/cmd.sys#2000").toPath(), new File("build/root/cmd.sys#2000").toPath())
// Decompress the base image
Files.copy(new GZIPInputStream(new FileInputStream("data/disks/base.2mg.gz")), new File("build/game.2mg").toPath())
// Now put the files into the image
String[] args = ["-put", "build/game.2mg", "/", "build/root"]
new a2copy.A2Copy().main(args)
}
static void main(String[] args)
{
// Set auto-flushing for stdout
@ -1718,12 +1679,11 @@ class PackPartitions
}
// Check the arguments
if (!(args.size() == 2 || args.size() == 3)) {
println "Usage: convert yourOutlawFile.xml game.part.0.bin [intcastMap.js]"
println " (where intcastMap.js is to aid in debugging the Javascript raycaster)"
println " or: convert yourOutlawFile.xml -dataGen"
if (args.size() != 2) {
println "Usage: packPartitions yourOutlawFile.xml"
System.exit(1);
}
def xmlFile = new File(args[0])
// If there's an existing error file, remote it.
def errorFile = new File("pack_error.txt")
@ -1733,8 +1693,20 @@ class PackPartitions
// Go for it.
def inst = new PackPartitions()
try {
new PackPartitions().dataGen(args[0])
inst.pack(args[0], args[1], args.size() > 2 ? args[2] : null)
// Blow away everything in the build directory, and recreate it
def buildDir = new File("build")
if (buildDir.exists())
buildDir.deleteDir()
buildDir.mkdirs()
// Create PLASMA headers
new PackPartitions().dataGen(xmlFile)
// Pack everything into a binary file
inst.pack(xmlFile)
// And create the final disk image
inst.createImage()
}
catch (Throwable t) {
errorFile.withWriter { out ->

View File

@ -0,0 +1 @@
../tools/PLASMA/src/PLVM02.SYSTEM.sys

View File

@ -33,32 +33,8 @@
<echo>Packing game and code resources.</echo>
<java jar="${pack.dir}/PackPartitions.jar" fork="true" failonerror="true">
<arg value="data/world/world.xml"/>
<arg value="build/game.part.0.bin"/>
<arg value="build"/>
</java>
<!-- Construct a directory to put on the Apple -->
<delete failonerror="false" dir="${build.dir}/root"/>
<mkdir dir="${build.dir}/root"/>
<copy todir="${build.dir}/root">
<fileset dir="${plasma.dir}" includes="PLVM02.SYSTEM*"/>
<fileset dir="${src.dir}/core/build" includes="*.sys*"/>
<fileset dir="./build" includes="game.part*.bin"/>
</copy>
<mkdir dir="${build.dir}/root/"/>
<!-- Make a new base image file -->
<delete failonerror="false" file="${build.dir}/${projName}.2mg"/>
<bunzip2 src="./data/disks/base.2mg.bz2" dest="${build.dir}/${projName}.2mg"/>
<!-- And stuff the directory into it -->
<echo>Adding files to image.</echo>
<java jar="${a2copy.dir}/a2copy.jar" fork="true" failonerror="true">
<arg value="-put"/>
<arg value="${build.dir}/${projName}.2mg"/>
<arg value="/"/>
<arg value="${build.dir}/root"/>
</java>
</target>
</project>

Binary file not shown.