Added periodic heap checking. Fixed big bug when rolling large number of dice. Added some mechanics of trade/split/join items.

This commit is contained in:
Martin Haye 2017-08-30 10:33:01 -07:00
parent acc78864bf
commit 288c8bbfbe
6 changed files with 66 additions and 17 deletions

View File

@ -747,15 +747,8 @@ gcHash_chk: !zone
rts
.corrup jmp heapCorrupt
!if DEBUG = 0 {
debugOnly:
jsr inlineFatal : !text "DebugOnly",0
}
; Verify integrity of memory manager structures
memCheck: !zone
!if DEBUG = 0 { jmp debugOnly }
!if DEBUG {
jsr heapCheck ; heap check (if there is one)
ldx #0 ; check main bank
jsr .chk
@ -811,7 +804,6 @@ heapCheck: !zone
cmp heapEndPg ; or >= than end of heap
bcc .tscan
; fall through to heapCorrupt...
} ; if DEBUG
heapCorrupt:
+prWord pTmp

View File

@ -886,12 +886,13 @@ def collectLootAndXP()#2
pItem=>w_count = rollDiceWithLuck(pItem=>r_lootAmount, global=>p_players->b_luck)
fin
if addItem(global=>p_players, pItem)
displayStr("You find ")
if pItem->t_type == TYPE_FANCY_ITEM and pItem=>w_count > 1
isPlural = TRUE
displayf2("You find %d %s! ", pItem=>w_count, pItem=>s_name)
displayf2("%d %s! ", pItem=>w_count, pItem=>s_name)
else
isPlural = FALSE
displayf2("You find %s%s! ", anOrA(pItem=>s_name), pItem=>s_name)
displayf2("%s%s! ", anOrA(pItem=>s_name), pItem=>s_name)
fin
fin
lootedItem = TRUE

View File

@ -226,6 +226,9 @@ end
///////////////////////////////////////////////////////////////////////////////////////////////////
def saveInternal()#0
// 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
@ -257,6 +260,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
return TRUE
end

View File

@ -1276,7 +1276,7 @@ end
///////////////////////////////////////////////////////////////////////////////////////////////////
export def rollDiceWithLuck(encoded, luck)#1
byte i, nDice, dieSize, add, droll, result
nDice = encoded >> 12
nDice = (encoded >> 12) & $F // must mask off replicated hi-bits
dieSize = (encoded >> 8) & $F
add = encoded & $F
result = add
@ -1291,8 +1291,7 @@ export def rollDiceWithLuck(encoded, luck)#1
droll = min(droll, (rand16() % dieSize) + 1)
fin
fin
add = (rand16() % dieSize) + 1
result = result + add
result = result + droll
next
return result
end
@ -2452,6 +2451,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)
if (result == -99)

View File

@ -374,10 +374,21 @@ def showItemMenu(item)#0
clearMenuRect()
type = item->t_type
if type == TYPE_ARMOR or type == TYPE_WEAPON
rawDisplayStr("E)quip/unequip, ")
fin
if type == TYPE_PLAIN_ITEM or type == TYPE_FANCY_ITEM
if !(item->b_flags & ITEM_FLAG_EQUIP)
rawDisplayStr("un-")
fin
rawDisplayStr("E)quip")
elsif type == TYPE_PLAIN_ITEM or type == TYPE_FANCY_ITEM
rawDisplayStr("U)se, ")
if type == TYPE_FANCY_ITEM and item=>w_count > 1
rawDisplayStr("S)plit, ")
fin
if type == TYPE_FANCY_ITEM and item=>w_count > 0
rawDisplayStr("J)oin, ")
fin
fin
if global=>p_players=>p_nextObj
rawDisplayStr("T)rade, ")
fin
rawDisplayStr("D)rop or [Esc]")
end
@ -404,6 +415,24 @@ def doEquip(player, item)#0
calcPlayerArmor(player)
end
// Trade an item to another player/npc
def doTrade(player, item)#1
fatal("not yet: trade")
return 0
end
// Split a stack of stackables
def doSplit(player, item)#1
fatal("not yet: split")
return 0
end
// Join a stack of stackables
def doJoin(player, item)#1
fatal("not yet: join")
return 0
end
// Select an item and use it. Returns item if it needs to be processed by outer loop, else NULL
def doUse(player, item)#1
word pMod, oldVal, newVal
@ -505,6 +534,24 @@ def interactWithItem(player, item)#1
beep
fin
break
// Trade an item
is 'T'
if global=>p_players=>p_nextObj
return doTrade(player, item)
fin
break
// Split a stack
is 'S'
if item->t_type == TYPE_FANCY_ITEM and item=>w_count > 1
return doSplit(player, item)
fin
break
// Join stacks
is 'J'
if item->t_type == TYPE_FANCY_ITEM and item=>w_count > 0
return doJoin(player, item)
fin
break
// Destroy an item
is 'D'
if doDestroy(player, item); return NULL; fin
@ -624,6 +671,8 @@ 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)
return NULL
otherwise
if sel == 'X' and mode <> 'I'
@ -656,7 +705,7 @@ def _showPlayerSheet(player_num)#1 // funcTbl functions always have to return a
fin
wend
until 0
return NULL
return NULL // never reached
end
///////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -83,6 +83,7 @@ def displayBuyPage(pItemTbl, markupRatio, pageNum, nPages)#1
word pFunc, pItem
displayBuyTitle(pageNum, nPages)
mmgr(CHECK_MEM, 0)
mmgr(HEAP_COLLECT, 0)
pFunc = pItemTbl + ((pageNum*PAGE_SIZE) << 1)
@ -246,6 +247,7 @@ def _buyFromStore(storeCode, profitPercent)#1
loop
unloadExtraModules()
mmgr(CHECK_MEM, 0)
return mmgr(HEAP_COLLECT, 0)
end
@ -367,6 +369,7 @@ def _sellToStore(profitPercent)#1
loop
unloadExtraModules()
mmgr(CHECK_MEM, 0)
return mmgr(HEAP_COLLECT, 0)
end