///////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2016 The 8-Bit Bunch. Licensed under the Apache License, Version 1.1
// (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at <http://www.apache.org/licenses/LICENSE-1.1>.
// Unless required by applicable law or agreed to in writing, software distributed under
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
// ANY KIND, either express or implied. See the License for the specific language
// governing permissions and limitations under the License.
///////////////////////////////////////////////////////////////////////////////////////////////////

import gamelib

  //////////// Shared library routines ////////////
  // Let's try to keep these predef's in lexical order
  predef abs(n)#1
  predef addEncounterZone(code, x, y, dist, chance)#0
  predef addGold(amount)#1
  predef addPlayerToParty(playerFuncNum, displayFunc)#0
  predef addPercent(start, pct)#1
  predef addRatio(start, ratio)#1
  predef addToList(addTo, p)#0
  predef adjustPartyStat(statName, val)#0
  predef auxMmgr(cmd, wordParam)#1
  predef beep()#0
  predef benchPlayer()#0
  predef blit(isAux, srcData, dstScreenPtr, nLines, lineSize)#0
  predef buildString()#0
  predef buySell(storeCode, profitRatio)#0
  predef calcPlayerArmor(player)#0
  predef calcWidth(pStr)#1
  predef callGlobalFunc(moduleNum, arg1, arg2, arg3)#1
  predef callProRWTS(cmdPlusOpenFlg, filename, addr, size)#1
  predef charToUpper(c)#1
  predef checkEncounter(x, y, force)#0
  predef clampByte(val)#1
  predef clearEncounterZones()#0
  predef clearPortrait()#0
  predef clearWindow()#0
  predef centerStr(str, windowWidth)#0
  predef copyWindow(flip)#0
  predef countList(p)#1
  predef createItem(itemNum)#1
  predef createStruct(moduleID, creationFuncNum)#1
  predef crout()#0
  predef diskLimitChk(is3d, mapNum)#1
  predef displayChar(chr)#0
  predef displayf1(fmt, arg1)#0
  predef displayf2(fmt, arg1, arg2)#0
  predef displayf3(fmt, arg1, arg2, arg3)#0
  predef displayStory(num)#0
  predef displayStr(str)#0
  predef encodeDice(nDice, dieSize, add)#1
  predef equipItem(item)#0
  predef fatal(msg)#1
  predef finishString(isPlural)#1
  predef flipToPage1()#0
  predef first(p, sel)#1
  predef forEach(p, do)#0
  predef forSome(p, sel, do)#0
  predef fullAddItem(pItem, doit)#1
  predef genSound(dnnoise, dnvelo, dndelay, upnoise, upvelo, updelay, dur)#0
  predef getCharResponse()#1
  predef getCursor()#2
  predef getDir()#1
  predef getGameFlag(flagName)#1
  predef getPos(px, py)#0
  predef getScreenLine(n)#1
  predef getStat(player, statName)#1
  predef getStatInContext(statName)#1
  predef getStringResponse()#1
  predef getUpperKey()#1
  predef getYN()#1
  predef girdPlayer(player)#0
  predef giveItemToParty(pItem, displayFunc)#0
  predef heapCollect()#0
  predef hisHerTheir(c_gender)#1
  predef index(p, num)#1
  predef initHeap(loadedSize)#0
  predef initPlayerXP(player)#0
  predef loadFrameImg(img)#0
  predef loadMainFrameImg()#0
  predef lookupResourcePart(sectionNum, resourceNum)#1
  predef makeModifier(name, value)#1
  predef max(a, b)#1
  predef memcpy(pSrc, pDst, len, auxWr)#0
  predef memset(pDst, val, len)#0
  predef min(a, b)#1
  predef mmgr(cmd, wordParam)#1
  predef moveInternal(facingDir, moveDir, beepOK, shouldAdvTime)#1
  predef moveWayBackward()#1
  predef parseDec(str)#1
  predef partyHasPlayer(playerName)#1
  predef partyHasItem(itemName)#1
  predef pause(count)#1
  predef payGold(amount)#1
  predef percentToRatio(pct)#1
  predef printChar(ch)#0
  predef printf1(fmt, arg1)#0
  predef printf2(fmt, arg1, arg2)#0
  predef printf3(fmt, arg1, arg2, arg3)#0
  predef printHex(num)#0
  predef printMem()#1
  predef promptAnyKey(clearAfter)#0
  predef puts(str)#0
  predef queue_setMap(is3D, num, x, y, dir)#0
  predef queue_teleport(x, y, dir)#0
  predef rand16()#1
  predef rawDisplayf1(fmt, arg1)#0
  predef rawDisplayf2(fmt, arg1, arg2)#0
  predef rawDisplayf3(fmt, arg1, arg2, arg3)#0
  predef rawDisplayStr(str)#0
  predef rdkey()#1
  predef readAuxByte(ptr)#1
  predef recordKey()#1
  predef removeFromList(pList, toRemove)#0
  predef removeNamed(name, pList)#1
  predef removePlayerFromParty(playerName)#0
  predef rightJustifyNum(num, rightX)#0
  predef rightJustifyStr(str, rightX)#0
  predef rollDice(encoded)#1
  predef roomInPack(p_player)#1
  predef rwGame(cmd)#0
  predef scanForNamedObj(p_obj, name)#1
  predef scriptCombat(mapCode)#1
  predef scriptCopyTile(fromX, fromY, toX, toY)#0
  predef scriptDisplayStr(str)#0
  predef scriptEvent(event, param)#0
  predef scriptSetAvatar(avatarTileNum)#0
  predef select(p, sel, num)#1
  predef setCursor(x, y)#0
  predef setDir(dir)#0
  predef setGameFlag(flagName, val)#0
  predef setGround(num)#0
  predef setMap(is3D, num, x, y, dir)#0
  predef setStoryMode(enable)#0
  predef soundPlayEmu(numAndFlgs)#0
  predef useMapWindow()#0
  predef setBigWindow()#0
  predef setPortrait(portraitNum)#0
  predef setScriptInfo(mapName, moduleNum, timeFunc, trigTbl, wdt, hgt)#0
  predef setSky(num)#0
  predef setStat(player, statName, val)#0
  predef setWindow(top, bottom, left, right)#0
  predef setWindow1()#0
  predef setWindow2()#0
  predef setWindow3()#0
  predef showMapName(mapName)#0
  predef showParty()#0
  predef sprintf1(fmt, arg1)#1
  predef sprintf2(fmt, arg1, arg2)#1
  predef sprintf3(fmt, arg1, arg2, arg3)#1
  predef streqi(a, b)#1
  predef sum(p, sel, func)#1
  predef takeItemFromParty(itemName)#0
  predef textHome()#0
  predef unbenchPlayer()#0

  // This pointer is the root of all heap-tracked (and garbage collected) objects.
  // See playtype.plh for definitions of all the datastructures and how they interconnect.
  word global

  // Other global variables
  byte mapNum
  byte mapIs3D
  word skyNum
  word groundNum
  byte portraitNum
  word typeHash
  byte isPlural
  word ctx
  word totalMapWidth
  word totalMapHeight
  word pCurMap
  byte curMapPartition
  word pResourceIndex
  word pGlobalTileset
  byte isFloppyVer
  byte isJace
  byte recordMode
  word recordSeed
  byte prevClockColor, prevClockHour, prevClockMinute
  byte nextSignificantMinute
  byte lampFrame
  word lampDir
  byte needRender
  byte diskLimit
  byte curHeapPct
  word playerUsing


  /////////// Shared string constants //////////////

  // First: attributes
  byte[] S_INTELLIGENCE, S_STRENGTH, S_AGILITY, S_STAMINA, S_CHARISMA, S_SPIRIT, S_LUCK
  byte[] S_HEALTH, S_MAX_HEALTH, S_AIMING, S_HAND_TO_HAND, S_DODGING, S_GOLD, S_TIME, S_XP, S_SP
  byte[] S_BANK_BAL

  // Next: common events
  byte[] S_ENTER, S_LEAVE, S_USE

  // Next: other useful strings
  byte[] S_HIS, S_HER, S_THEIR

  // Load/save filename
  byte[] S_GAME1_FILENAME
end
