From b487223783ab3521abb646642fdac27d6352fdba Mon Sep 17 00:00:00 2001 From: Martin Haye Date: Mon, 16 Apr 2018 07:46:54 -0700 Subject: [PATCH] Generating map sizes for diskops checking. --- .../src/org/badvision/A2PackPartitions.groovy | 27 +++++++++++++++++++ Platform/Apple/virtual/src/plasma/diskops.pla | 3 +++ .../Apple/virtual/src/plasma/gameloop.pla | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Platform/Apple/tools/PackPartitions/src/org/badvision/A2PackPartitions.groovy b/Platform/Apple/tools/PackPartitions/src/org/badvision/A2PackPartitions.groovy index 5b1f07e5..9204497e 100644 --- a/Platform/Apple/tools/PackPartitions/src/org/badvision/A2PackPartitions.groovy +++ b/Platform/Apple/tools/PackPartitions/src/org/badvision/A2PackPartitions.groovy @@ -101,6 +101,7 @@ class A2PackPartitions 12: "song"] def mapNames = [:] // map name (and short name also) to map.2dor3d, map.num + def mapSizes = [] // array of [2dOr3D, mapNum, marksSize] def sysCode = [:] // memory manager def code = [:] // code name to code.num, code.buf def maps2D = [:] // map name to map.num, map.buf, map.order, map.width, map.height @@ -2310,12 +2311,19 @@ class A2PackPartitions mapNames[shortName] = ['2D', num2D+1] def rows = parseMap(map, dataIn.tile, true) // quick mode def (width, height, nHorzSections, nVertSections) = calcMapExtent(rows) + (1..(nHorzSections * nVertSections)).each { + int rowBytes = (TILES_PER_ROW+7)/8 + mapSizes << ['2D', it+num2D, 2 + (rowBytes * ROWS_PER_SECTION)] + } num2D += (nHorzSections * nVertSections) maxMapSections = Math.max(maxMapSections, nHorzSections * nVertSections) } else if (map?.@name =~ /\s*3D$/) { mapNames[name] = ['3D', num3D+1] mapNames[shortName] = ['3D', num3D+1] + def rows = parseMap(map, dataIn.tile, true) // quick mode + int rowBytes = (rows[0].size()+7)/8 + mapSizes << ['3D', num3D+1, 2 + (rowBytes * rows.size())] ++num3D } else @@ -3480,6 +3488,24 @@ end } } + def genAllMapSizes() + { + // Make a buffer containing the map sizes, so that diskops code can validate + // the automap marks in a save file. + new File("build/src/plasma/gen_mapsizes.pla.new").withWriter { out -> + out.println("// Generated code - DO NOT MODIFY BY HAND\n") + def totalSize = mapSizes.size() * 2 + assert totalSize < 256 : "too many maps" + out.println("byte[] mapSizes = $totalSize // overall buffer size") + boolean first = true + mapSizes.sort().each { triple -> + out.println(String.format("byte = \$%02X, \$%02X", + (triple[0] == '3D' ? 0x80 : 0) | triple[1], triple[2])) + } + } + replaceIfDiff("build/src/plasma/gen_mapsizes.pla") + } + def replaceIfDiff(oldFile) { def newFile = new File(oldFile + ".new") @@ -3585,6 +3611,7 @@ end genAllItems(dataIn.global.sheets.sheet) genAllEnemies(dataIn.global.sheets.sheet.find { it?.@name.equalsIgnoreCase("enemies") }) genAllPlayers(dataIn.global.sheets.sheet) + genAllMapSizes() // Produce a list of assembly and PLASMA code segments binaryStubsOnly = true diff --git a/Platform/Apple/virtual/src/plasma/diskops.pla b/Platform/Apple/virtual/src/plasma/diskops.pla index 37a07ad7..a74e2109 100644 --- a/Platform/Apple/virtual/src/plasma/diskops.pla +++ b/Platform/Apple/virtual/src/plasma/diskops.pla @@ -48,6 +48,9 @@ word[] funcTbl = @_startup, @_saveGame, @_loadGame, @_newOrLoadGame byte[] game1_filename = "GAME.1.SAVE" byte[] legendos_filename = "LEGENDOS.SYSTEM" +// For checking automap mark sizes +include "gen_mapsizes.pla" + /////////////////////////////////////////////////////////////////////////////////////////////////// // Definitions used by assembly code asm __defs diff --git a/Platform/Apple/virtual/src/plasma/gameloop.pla b/Platform/Apple/virtual/src/plasma/gameloop.pla index cfae6c66..ae62d8af 100644 --- a/Platform/Apple/virtual/src/plasma/gameloop.pla +++ b/Platform/Apple/virtual/src/plasma/gameloop.pla @@ -719,7 +719,7 @@ asm getXReg()#1 end /////////////////////////////////////////////////////////////////////////////////////////////////// -// Calculate 16-bit hash of a buffer. +// Calculate 16-bit hash of a buffer. Note: ignores anything beyond 256 bytes. export asm hashBuffer(ptr, len)#1 +asmPlasmRet 2 lda evalStkL+1,x ; first arg is buffer pointer