Added code to display % heap memory in use.

This commit is contained in:
Martin Haye 2017-09-11 11:16:10 -07:00
parent 3e54dcf80c
commit ea25619c78
9 changed files with 120 additions and 37 deletions

View File

@ -1588,7 +1588,7 @@ class A2PackPartitions
def hourCode = (char) (97 + hour) // 'a'=0, 'b'=1, etc.
def engineCode = String.format("%d%c%02d%c", yearCode, monthCode, day, hourCode)
def offset = (int) ((scenarioStamp - engineStamp) / (1000 * 60 * 60))
def offset = Math.max(-99, Math.min(99, (int) ((scenarioStamp - engineStamp) / (1000 * 60 * 60))))
return String.format("%s%s%d", engineCode, offset < 0 ? "-" : ".", Math.abs(offset))
}

View File

@ -107,6 +107,9 @@ SetFont JMP DoSetFont ;API call address
;Set the window boundaries (byte-oriented bounds)
SetWindow JMP SetWnd ;API call address
;Set the window boundaries (byte-oriented bounds)
GetWindow JMP GetWnd ;API call address
;Clear the window
ClearWindow JMP ClrHome ;API call address
@ -613,6 +616,29 @@ SetWnd LDA evalStkL+SW_TOP,X ;get top coord
STA WrdWdth
RTS
;Routine: Get the cursor position (relative to the current window)
GetWnd DEX
LDY #0
LDA CursY ; top
STA evalStkL,X
TYA
STA evalStkH,X
DEX ; bottom
STA evalStkH,X
LDA CursYb ; bottom
STA evalStkL,X
DEX
LDA CursXl ; left
STA evalStkL,X
LDA CursXh
STA evalStkH,X
DEX
LDA CursXrl ; right
STA evalStkL,X
LDA CursXrh
STA evalStkH,X
RTS
;Routine: Scroll screen up 1 character line
;This routine scrolls a window defined by
;Left, Right, Top, Bottom - Margin parameters.

View File

@ -37,7 +37,8 @@ fontEngine = $EC00
fontEngineLen = $F00 ; maximum (allows for some debug code)
SetFont = fontEngine
SetWindow = SetFont+3
ClearWindow = SetWindow+3
GetWindow = SetWindow+3
ClearWindow = GetWindow+3
CopyWindow = ClearWindow+3
DisplayChar = CopyWindow+3
DisplayStr = DisplayChar+3

View File

@ -225,11 +225,9 @@ end
///////////////////////////////////////////////////////////////////////////////////////////////////
def _saveGame()#1
// Never save corrupted heap
mmgr(CHECK_MEM, 0)
// Perform garbage collection and record the size of the heap so we can restore it correctly
global=>w_heapSize = mmgr(HEAP_COLLECT, 0) - HEAP_BOTTOM
// (also does a CHECK_MEM to be sure we never save corrupted heap)
heapCollect()
// Copy data to main memory, and write it out.
memcpy(HEAP_BOTTOM, LOAD_SAVE_BUF, HEAP_SIZE) // LC to low mem
@ -253,7 +251,7 @@ def loadInternal()#1
fin
memcpy(LOAD_SAVE_BUF, HEAP_BOTTOM, HEAP_SIZE) // low mem to LC
initHeap(p_loaded=>w_heapSize)
mmgr(CHECK_MEM, 0) // make sure heap is valid
heapCollect() // make sure heap is valid, and record final size
return TRUE
end
@ -412,6 +410,7 @@ def newGame()#0
if global=>p_players->b_skillPoints
partyModule()=>party_showPlayerSheet(0)
fin
heapCollect()
end
///////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -61,6 +61,7 @@ import gamelib
predef getYN()#1
predef girdPlayer(player)#0
predef giveItemToPlayer(p_player, itemFuncNum)#0
predef heapCollect()#0
predef hisHerTheir(c_gender)#1
predef initHeap(loadedSize)#0
predef initPlayerXP(player)#0

View File

@ -98,6 +98,7 @@ word pGlobalTileset = NULL
byte curMapPartition = 0
export word pGodModule = NULL
export word typeHash = 0
word curHeapPct = 0
// Queue setMap / teleport / start_encounter, since otherwise script might be replaced while executing
byte q_mapIs3D = 0
@ -797,6 +798,14 @@ export asm setWindow(top, bottom, left, right)#0
jmp SetWindow
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Get the font engine's current text window
// Returns: top, bottom, left, right
export asm getWindow()#4
bit setLcRW+lcBank2
jmp GetWindow
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Get the cursor position - returns X, Y
export asm getCursor()#2
@ -1358,33 +1367,75 @@ export def setGround(num)#0
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def printVersion()#0
word p, len, cv, ch
if !pResourceIndex; return; fin
def printAtBottom(str, textX, botLeft, botRight, strX)#0
byte cv
word origX, origY, origTop, origBottom, origLeft, origRight
// Save text cursor, and print at bottom of text window
cv = ^$25
^$23 = 24 // full height window
^$25 = 22
crout()
^$24 = 25
puts("V")
setWindow(183, 192, 161, 261)
clearWindow()
setWindow(183, 192, 168, 252)
rawDisplayStr("^YV")
p = pResourceIndex
len = readAuxByte(p)
while len
p++
ch = readAuxByte(p)
printChar(ch)
displayChar(ch)
len--
loop
rawDisplayStr("^N")
^$24 = textX
puts(str)
^$23 = 23 // shrink window to protect version num
^$25 = cv-1
crout()
setWindow2()
// Save graphics cursor and window
origX, origY = getCursor()
origTop, origBottom, origLeft, origRight = getWindow()
// Establish new graphics window, clear it, and display the string
setWindow(183, 192, botLeft, botRight)
clearWindow()
rawDisplayStr("^T") // do not use printf variants, since it might overwrite str
rawDisplayStr(convert3Dec(strX))
rawDisplayStr(str)
if mapIs3D and texturesLoaded; copyWindow(); fin
// Restore original graphics cursor and window
setWindow(origTop, origBottom, origLeft, origRight)
setCursor(origX, origY)
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def printHeapPct()#0
word str, len
str = sprintf1("%d%%", curHeapPct)
len = calcWidth(str)
printAtBottom(str, 36, 240, 268, (28-len) >> 1) // center
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def printVersion()#0
word p
byte len
if !pResourceIndex; return; fin
buildString(@addToString)
printChar('V')
p = pResourceIndex
len = readAuxByte(p)
while len
p++; printChar(readAuxByte(p)); len--
loop
p = finishString(FALSE)
len = calcWidth(p)
printAtBottom(p, 25, 154, 154 + len + 8, 3)
printHeapPct()
end
///////////////////////////////////////////////////////////////////////////////////////////////////
export def heapCollect()#0
word pct
mmgr(CHECK_MEM, 0)
global=>w_heapSize = mmgr(HEAP_COLLECT, 0) - HEAP_BOTTOM
pct = min(99, max(0, ((global=>w_heapSize / 10) * 100) / 307))
if pct <> curHeapPct
curHeapPct = pct
printHeapPct()
fin
end
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -2463,8 +2514,7 @@ def doCombat(mapCode, backUpOnFlee)#1
// Handled in a separate module. Clear enemies out of the heap when finished.
result = loadEngine(MOD_COMBAT)=>combat_zoneEncounter(mapCode)
global=>p_enemyGroups = NULL
mmgr(CHECK_MEM, 0)
mmgr(HEAP_COLLECT, 0)
heapCollect()
if (result == -99)
playerDeath()

View File

@ -279,6 +279,7 @@ def selectThing(moduleNum, nThings, nSkip, prompt)#1
mmgr(FREE_MEMORY, pModule)
^$c050
heapCollect()
return nFunc
end

View File

@ -778,8 +778,7 @@ def _showPlayerSheet(player_num)#1 // funcTbl functions always have to return a
fin
break
is $1B // Esc
mmgr(CHECK_MEM, 0)
mmgr(HEAP_COLLECT, 0)
heapCollect()
return NULL
otherwise
if sel == 'X' and mode <> 'I' // switch from stats to inv

View File

@ -107,8 +107,7 @@ def displayBuyPage(pItemTbl, markupRatio, pageNum, nPages)#1
word pFunc, pItem
// Clear stuff from previous page
mmgr(CHECK_MEM, 0)
mmgr(HEAP_COLLECT, 0)
heapCollect()
displayTitle("buying", "Browse", pageNum, nPages)
pFunc = pItemTbl + ((pageNum*PAGE_SIZE) << 1)
@ -255,6 +254,13 @@ def _buyFromStore(storeCode, profitPercent)#1
while TRUE
if redisplay
nItemsOnPage = displayBuyPage(pItemTbl, ratio, pageNum, nPages)
flipToPage1 // FOO
^$c051
mmgr(DEBUG_MEM, 0)
rdkey
auxMmgr(DEBUG_MEM, 0)
rdkey
^$c050
fin
choice = getUpperKey()
redisplay = TRUE
@ -276,8 +282,8 @@ def _buyFromStore(storeCode, profitPercent)#1
loop
unloadExtraModules()
mmgr(CHECK_MEM, 0)
return mmgr(HEAP_COLLECT, 0)
heapCollect()
return 0
end
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -381,8 +387,8 @@ def _sellToStore(profitPercent)#1
loop
unloadExtraModules()
mmgr(CHECK_MEM, 0)
return mmgr(HEAP_COLLECT, 0)
heapCollect()
return 0
end
///////////////////////////////////////////////////////////////////////////////////////////////////