Now using resource index... not right, but using it.

This commit is contained in:
Martin Haye 2017-02-06 10:01:00 -08:00
parent 421614f605
commit eb2710865f
4 changed files with 56 additions and 18 deletions

View File

@ -1404,6 +1404,7 @@ class A2PackPartitions
def blks = calcFileBlks(spaceUsed + portraitSpace + len)
if (blks <= availBlks) {
mapChunks[key] = chunk
chunk.buf.partNum = 1
portraitSpace += len
}
}
@ -1504,6 +1505,8 @@ class A2PackPartitions
tmp.put((byte) portraits.size())
portraits.each { k, v -> tmp.put((byte) (v.buf.partNum ? v.buf.partNum : 0)) }
println "resource indx: ${unwrapByteBuffer(tmp)}"
code["resourceIndex"].buf = compress(unwrapByteBuffer(tmp))
def chunk = [type:TYPE_CODE, num:code["resourceIndex"].num,
name:"resourceIndex", buf:code["resourceIndex"].buf]
@ -1887,7 +1890,7 @@ class A2PackPartitions
code.each { k,v -> addResourceDep("map", "<root>", "code", k) }
// Special module added after the fact
code["resourceIndex"] = [num:1, buf:null] // filled in later
code["resourceIndex"] = [num:code.size()+1, buf:null] // filled in later
compileModule("gameloop", "src/plasma/")
compileModule("combat", "src/plasma/")

View File

@ -83,6 +83,8 @@ byte heapLocked = FALSE
byte allowZoneInit = FALSE
word curEngine = NULL
word pIntimate = NULL
word pResourceIndex = NULL
byte curMapPartition = 0
// Queue setMap / teleport / start_encounter, since otherwise script might be replaced while executing
byte q_mapIs3D = 0
@ -172,7 +174,7 @@ end
///////////////////////////////////////////////////////////////////////////////////////////////////
// API to call rendering engine (same API for raycaster and tile engine)
asm initDisplay // params: mapNum, pMapData, x, y, dir
+asmPlasm 5
+asmPlasm 6
jmp $6000
end
export asm flipToPage1 // no params
@ -1131,6 +1133,29 @@ export def rollDice(encoded)
return result
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Look up the partition for a resource.
// sectioNum: 1=map2d, 2=map3d, 3=portrait
def lookupResourcePart(sectionNum, resourceNum)
word ptr
byte n
// Skip to the requested section
printf3("sect=%d rsrc=%d idx=$%x\n", sectionNum, resourceNum, pResourceIndex)
ptr = pResourceIndex
while sectionNum > 1
ptr = ptr + readAuxByte(ptr) + 1
sectionNum--
loop
// And grab the number from that section's table
n = readAuxByte(ptr)
if resourceNum > n; fatal("lkupFail1"); fin
n = readAuxByte(ptr + resourceNum)
if n > 20; fatal("lkupFail2"); fin
return n
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Set the sky color (relevant to 3D display only)
export def setSky(num)
@ -1409,12 +1434,9 @@ def initMap(x, y, dir)
renderLoaded = TRUE
// Load the map
mmgr(START_LOAD, 2) // partition 2 is where maps live
if mapIs3D
pMap = mmgr(QUEUE_LOAD, mapNum<<8 | RES_TYPE_3D_MAP)
else
pMap = mmgr(QUEUE_LOAD, mapNum<<8 | RES_TYPE_2D_MAP)
fin
curMapPartition = lookupResourcePart(mapIs3D+1, mapNum)
mmgr(START_LOAD, curMapPartition)
pMap = mmgr(QUEUE_LOAD, mapNum<<8 | (RES_TYPE_2D_MAP+mapIs3D))
mmgr(FINISH_LOAD, 0)
// Clear all the windows to the background color (hi-bit set)
@ -1434,7 +1456,7 @@ def initMap(x, y, dir)
// init the script module, if any, which will end up calling us back at the setScriptInfo
triggerTbl = NULL
setWindow2()
initDisplay(mapNum, pMap, x, y, dir)
initDisplay(curMapPartition, mapNum, pMap, x, y, dir)
texturesLoaded = TRUE
needRender = FALSE
textDrawn = FALSE
@ -1885,7 +1907,7 @@ export def setPortrait(portraitNum)
restoreCursor()
// Load the portrait image and display it
mmgr(START_LOAD, 2) // portraits are in partition 2
mmgr(START_LOAD, lookupResourcePart(3, portraitNum))
curPortrait = auxMmgr(QUEUE_LOAD, portraitNum<<8 | RES_TYPE_PORTRAIT)
mmgr(FINISH_LOAD, 0)
anyAnims = TRUE // for now; might get cleared if we discover otherwise on advance
@ -2363,6 +2385,9 @@ def loadTitle()
auxMmgr(SET_MEM_TARGET, expandVec)
auxMmgr(QUEUE_LOAD, CODE_EXPAND<<8 | RES_TYPE_CODE)
// Also grab the resource index (put it in aux)
pResourceIndex = auxMmgr(QUEUE_LOAD, CODE_RESOURCE_INDEX<<8 | RES_TYPE_CODE)
mmgr(FINISH_LOAD, 0)
// Relocate font engine and font data to their final spots up in the language card

View File

@ -83,6 +83,7 @@ plasmaStk: !byte 0
nTextures: !byte 0
scripts: !word 0 ; pointer to loaded scripts module
shadow_pTex: !word 0 ; backup of pTmp space on aux (because it gets overwritten by expander)
mapPartition: !byte 0 ; mem mgr partition of map and resources
skyColorEven: !byte $20
skyColorOdd: !byte $22
@ -1673,7 +1674,7 @@ pl_texControl: !zone {
tax
beq .unload
lda #START_LOAD
ldx #2 ; textures are on disk 2
ldx mapPartition
jsr mainLoader
lda #0 ; don't re-init scripts
jmp loadTextures
@ -2143,8 +2144,11 @@ pl_initMap: !zone
; Figure out PLASMA stack for calling script init
txa
clc
adc #5 ; 5 params
adc #6 ; 6 params
sta plasmaStk ; save PLASMA's eval stack pos, without our params
; Record partition number of the map and textures
lda evalStkL+5,x
sta mapPartition
; Record the address of the map
lda evalStkL+3,x
sta mapHeader

View File

@ -49,7 +49,8 @@ MAX_MAP_ID=254 ; This means that the total map area can be as big as 5588x5842
REL_X=$50 ; Will always be in the range 0-43
REL_Y=$51 ; Will always be in the range 0-45
; Map quadrant data pointers (Maybe move these to screen holes in 2078-207f? There might be no advantage to using ZP for these)
; Map quadrant data pointers
; (Maybe move these to screen holes in 2078-207f? There might be no advantage to using ZP for these)
NW_MAP_LOC=$52
NE_MAP_LOC=$54
SW_MAP_LOC=$56
@ -62,7 +63,7 @@ GLOBAL_TILESET_LOC=$98
; Map section IDs (255 = not loaded)
NOT_LOADED=$FF
NW_MAP_ID=$5A
NE_MAP_ID=$5B
NE_MAP_ID=$5B
SW_MAP_ID=$5C
SE_MAP_ID=$5D
@ -101,7 +102,8 @@ AVATAR_DIR = $A8 ; direction (0-15, though only 0,4,8,12 are valid)
PLASMA_X = $A9 ; save for PLASMA's X reg
SCRIPTS_ID = $AA ; Module number of scripts
PLAYER_TILE = $AB ; Tile number to show for player avatar
next_zp = $AC
MAP_PARTITION = $AC ; Mem-mgr partition number for this map and its resources
next_zp = $AD
;----------------------------------------------------------------------
; Here are the entry points for PLASMA code. Identical API for 2D and 3D.
@ -122,7 +124,7 @@ next_zp = $AC
;----------------------------------------------------------------------
; >> START LOADING MAP SECTIONS
START_MAP_LOAD
LDX #2 ; currently 2d maps are in partition 2
LDX MAP_PARTITION
LDA #START_LOAD
JMP mainLoader
!macro startLoad {
@ -945,13 +947,17 @@ FinishCalc
;----------------------------------------------------------------------
; >> pl_initMap
; params: mapNum, pMapData, x, y, dir
; params: partNum, mapNum, pMapData, x, y, dir
pl_initMap: !zone
TXA
CLC
ADC #5
ADC #6
STA PLASMA_X ; save PLASMA's eval stack pos, without our params on it
; Store partition number for later use
LDA evalStkL+5,X
STA MAP_PARTITION
; PLASMA code has already loaded the Northwest-most map section. Record its ID and address.
LDA evalStkL+4,X
STA INDEX_MAP_ID