Can now avoid fixups for gamelib functions, and (with care) use abs addressing there.

This commit is contained in:
Martin Haye 2017-09-19 08:32:25 -07:00
parent 0fc0e6b852
commit 52f42d7fcf
3 changed files with 19 additions and 19 deletions

View File

@ -1216,9 +1216,10 @@ class A2PackPartitions
//println "esdName='$esdName'"
assert esdName != null : "failed to look up esdIndex $esdIndex"
def offset = cache["globalExports"][esdName]
//println "offset=$offset"
//println "external fixup: esdIndex=$esdIndex esdName='$esdName' target=$target offset=$offset"
assert offset != null : "failed to find global export for symbol '$esdName'"
target += offset
// External fixups can only refer to gamelib, which is always set at $1000 in memory.
target += offset + 0x1000
}
else if (invDefs.containsKey(target)) {
target = invDefs[target]
@ -1239,12 +1240,14 @@ class A2PackPartitions
codeBuf[addr] = (byte)(target & 0xFF)
codeBuf[addr+1] = (byte)((target >> 8) & 0xFF)
// And record the fixup
assert addr >= 0 && addr <= 0x3FFF : "code module too big"
newFixup.add((byte)((addr>>8) & 0x3F) |
(inByteCode ? 0x40 : 0) |
((fixupType == 0x91) ? 0x80 : 0))
newFixup.add((byte)(addr & 0xFF))
// And record the fixup (no need to record ext fixups - they're absolute starting at $1000)
if (fixupType != 0x91) {
assert addr >= 0 && addr <= 0x3FFF : "code module too big"
newFixup.add((byte)((addr>>8) & 0x3F) |
(inByteCode ? 0x40 : 0) |
((fixupType == 0x91) ? 0x80 : 0))
newFixup.add((byte)(addr & 0xFF))
}
}
newFixup.add((byte)0xFF)
@ -3883,9 +3886,8 @@ end
if (!text || text == "") // interpret lack of text as a single empty string
chunks = [""]
chunks.eachWithIndex { chunk, idx ->
outIndented((idx == chunks.size()-1 && blk.@type == 'text_println') ? \
'scriptDisplayStrNL(' : 'scriptDisplayStr(')
out << escapeString(chunk) << ")\n"
String str = (idx == chunks.size()-1 && blk.@type == 'text_println') ? chunk+"\\n" : chunk
outIndented("scriptDisplayStr(" + escapeString(str) + ")\n")
// Workaround for strings filling up the frame stack
outIndented("tossStrings()\n")
}

View File

@ -107,7 +107,6 @@ import gamelib
predef scanForNamedObj(p_obj, name)#1
predef scriptCombat(mapCode)#1
predef scriptDisplayStr(str)#0
predef scriptDisplayStrNL(str)#0
predef scriptEvent(event, param)#0
predef scriptSetAvatar(avatarTileNum)#0
predef scriptSwapTile(fromX, fromY, toX, toY)#0

View File

@ -179,8 +179,12 @@ seed = $4E
magic = $2227 ; there are 2048 magic values that work; this one caught my eye. - MH
; NOTE ABOUT ABSOLUTE CODE ADDRESSING (e.g. STA .var, JMP .label, etc.)
; We cannot use it: this code, including variable space, can be loaded *anywhere*.
; So don't JMP to labels, declare any variables as !byte or !word here, etc.
; We cannot use it: this code will be preceded by stubs for the PLASMA routines, hence
; absolute addressing must be done carefully, adding ABS_OFFSET below.
;
; So don't JMP to labels, declare any variables as !byte or !word here, etc. without
; accounting for that.
ABS_OFFSET = (_DEFCNT*5) - 11
end
@ -2209,11 +2213,6 @@ export def scriptDisplayStr(str)#0
// No: tossString() // Doesn't work here, because we need to toss strings in the *parent's* frame
end
export def scriptDisplayStrNL(str)#0
scriptDisplayStr(str)
displayStr("\n")
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Called by scripts to swap a map tile. We set a flag noting we need to re-render, then use an
// assembly routine to do the work.