2014-08-21 15:17:50 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2016-07-12 15:09:55 +00:00
|
|
|
// Copyright (C) 2015 The 8-Bit Bunch. Licensed under the Apache License, Version 1.1
|
2015-09-10 16:22:07 +00:00
|
|
|
// (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>.
|
2016-07-12 15:09:55 +00:00
|
|
|
// 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
|
2015-09-10 16:22:07 +00:00
|
|
|
// governing permissions and limitations under the License.
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-08-21 15:17:50 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Fixed memory locations
|
2015-08-28 15:24:21 +00:00
|
|
|
const seed = $4E // Incremented continuously by keyboard read routine
|
2015-04-05 16:52:38 +00:00
|
|
|
const displayEngine = $6000 // main mem (raycaster and tile engine at same location)
|
2017-01-08 00:43:27 +00:00
|
|
|
const expandVec = $800 // aux mem (only for raycaster)
|
2017-01-05 22:27:44 +00:00
|
|
|
const fontEngine = $EC00 // main mem LC
|
|
|
|
const fontEngineLen = $F00 // really a bit less, but this leaves space for debug code
|
|
|
|
const fontData = $FB00 // main mem LC
|
|
|
|
const fontDataLen = $4FA // really only $474, but we need to fill all gaps
|
2014-07-06 21:40:35 +00:00
|
|
|
|
2015-01-07 22:48:04 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Other constants
|
2017-06-30 15:11:34 +00:00
|
|
|
const CHAR_WND_HEALTH_X = 112
|
2015-12-17 17:19:49 +00:00
|
|
|
|
2015-12-23 23:42:37 +00:00
|
|
|
const ANIM_PAUSE_MAX = 300
|
2015-11-05 17:09:45 +00:00
|
|
|
|
2016-07-04 16:31:33 +00:00
|
|
|
// Max gold
|
|
|
|
const GOLD_MAX = 20000
|
|
|
|
|
2016-07-03 20:39:00 +00:00
|
|
|
include "globalDefs.plh"
|
2015-10-01 15:34:49 +00:00
|
|
|
include "playtype.plh"
|
2015-12-09 15:35:02 +00:00
|
|
|
include "gen_images.plh"
|
2015-12-10 17:43:21 +00:00
|
|
|
include "gen_modules.plh"
|
2016-01-01 15:53:57 +00:00
|
|
|
include "gen_enemies.plh"
|
2016-06-17 00:42:18 +00:00
|
|
|
include "gen_players.plh"
|
2016-09-24 18:10:17 +00:00
|
|
|
include "gen_items.plh"
|
2016-03-31 17:01:04 +00:00
|
|
|
include "combat.plh"
|
2016-06-01 16:03:14 +00:00
|
|
|
include "party.plh"
|
2017-03-04 16:20:01 +00:00
|
|
|
include "store.plh"
|
2016-06-19 15:38:40 +00:00
|
|
|
include "diskops.plh"
|
2016-11-07 15:58:46 +00:00
|
|
|
include "intimate.plh"
|
2017-02-19 18:08:03 +00:00
|
|
|
include "godmode.plh"
|
2016-07-03 14:33:12 +00:00
|
|
|
|
2015-12-29 19:22:14 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Data structures
|
|
|
|
include "playtype.pla"
|
2015-08-28 15:24:21 +00:00
|
|
|
|
2017-01-22 16:44:10 +00:00
|
|
|
export word global // the global heap object, from which all live objects must be reachable
|
2015-09-02 16:55:21 +00:00
|
|
|
|
2014-08-21 15:17:50 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-01-10 21:17:56 +00:00
|
|
|
// Predefined functions, for circular calls or out-of-order calls
|
2017-06-10 14:32:31 +00:00
|
|
|
predef setWindow2()#0
|
|
|
|
predef initCmds()#0
|
|
|
|
predef nextAnimFrame()#0
|
|
|
|
predef checkEncounter(x, y, force)#0
|
2017-06-10 15:56:23 +00:00
|
|
|
predef doCombat(mapCode, backUpOnFlee)#1
|
2017-06-10 14:32:31 +00:00
|
|
|
predef clearPortrait()#0
|
|
|
|
predef showMapName(mapName)#0
|
|
|
|
predef doRender()#0
|
|
|
|
predef playerDeath()#0
|
|
|
|
predef startGame(ask)#0
|
|
|
|
predef showAnimFrame()#0
|
|
|
|
predef finalWin()#0
|
|
|
|
predef showParty()#0
|
2015-01-18 16:59:56 +00:00
|
|
|
|
2014-08-21 15:17:50 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Global variables
|
2017-02-19 18:08:03 +00:00
|
|
|
export byte mapNum = -1
|
2017-07-08 23:36:08 +00:00
|
|
|
export byte mapIs3D = 0
|
2015-08-21 14:59:03 +00:00
|
|
|
word mapNameHash = 0
|
2015-07-01 17:04:19 +00:00
|
|
|
word totalMapWidth
|
|
|
|
word totalMapHeight
|
2015-08-21 14:59:03 +00:00
|
|
|
|
2015-12-23 23:42:37 +00:00
|
|
|
byte needRender = FALSE
|
2016-07-16 12:39:22 +00:00
|
|
|
byte needShowParty = FALSE
|
2015-12-29 16:59:13 +00:00
|
|
|
byte renderLoaded = FALSE
|
2016-09-08 15:30:08 +00:00
|
|
|
byte texturesLoaded = FALSE
|
2015-12-23 23:42:37 +00:00
|
|
|
byte textDrawn = FALSE
|
2017-08-02 17:20:22 +00:00
|
|
|
byte textClearCountdown = 0
|
2015-12-23 23:42:37 +00:00
|
|
|
byte isPlural = FALSE
|
2017-08-10 17:51:20 +00:00
|
|
|
byte inScript = FALSE
|
2015-12-23 23:42:37 +00:00
|
|
|
|
2017-02-19 18:08:03 +00:00
|
|
|
export word skyNum = 9
|
|
|
|
export word groundNum = 10
|
|
|
|
export byte portraitNum = 1
|
2015-08-21 14:59:03 +00:00
|
|
|
|
2015-05-21 14:19:22 +00:00
|
|
|
word triggerOriginX, triggerOriginY
|
2015-02-27 13:33:11 +00:00
|
|
|
word triggerTbl
|
2015-08-21 14:59:03 +00:00
|
|
|
|
2016-06-19 15:38:40 +00:00
|
|
|
word cmdTbl[96] // ASCII $00..$5F
|
2015-05-07 16:12:52 +00:00
|
|
|
byte frameLoaded = 0
|
2016-06-24 15:46:40 +00:00
|
|
|
byte heapLocked = FALSE
|
2016-07-14 20:52:23 +00:00
|
|
|
byte allowZoneInit = FALSE
|
2016-09-22 14:32:54 +00:00
|
|
|
word curEngine = NULL
|
2016-11-07 15:58:46 +00:00
|
|
|
word pIntimate = NULL
|
2017-02-06 18:01:00 +00:00
|
|
|
word pResourceIndex = NULL
|
2017-08-04 15:15:40 +00:00
|
|
|
word pGlobalTileset = NULL
|
2017-02-06 18:01:00 +00:00
|
|
|
byte curMapPartition = 0
|
2017-02-20 14:43:47 +00:00
|
|
|
export word pGodModule = NULL
|
2014-07-06 23:02:52 +00:00
|
|
|
|
2016-06-29 14:42:58 +00:00
|
|
|
// Queue setMap / teleport / start_encounter, since otherwise script might be replaced while executing
|
2016-03-24 16:45:07 +00:00
|
|
|
byte q_mapIs3D = 0
|
|
|
|
byte q_mapNum = 1
|
|
|
|
word q_x = 0
|
|
|
|
word q_y = 0
|
|
|
|
byte q_dir = 0
|
2015-08-21 14:59:03 +00:00
|
|
|
|
2016-09-15 18:08:43 +00:00
|
|
|
// Script tracking
|
|
|
|
const MAX_MAP_SCRIPTS = 4
|
|
|
|
byte nMapScripts = 0
|
|
|
|
word mapScripts[MAX_MAP_SCRIPTS]
|
|
|
|
|
2015-11-05 17:09:45 +00:00
|
|
|
// For decimal conversion and display tabbing
|
|
|
|
byte decimalBuf[7]
|
2017-04-02 16:25:11 +00:00
|
|
|
byte fontPosBuf[4]
|
2015-11-05 17:09:45 +00:00
|
|
|
byte tabBuf[5]
|
|
|
|
|
2015-12-17 17:19:49 +00:00
|
|
|
// Animation tracking
|
2016-10-23 17:42:11 +00:00
|
|
|
word curPortrait = NULL
|
2017-04-03 15:22:32 +00:00
|
|
|
byte curPortraitNum = 0
|
2016-10-23 17:42:11 +00:00
|
|
|
word curFullscreenImg = NULL
|
2015-12-23 23:42:37 +00:00
|
|
|
byte animDirCt
|
2016-10-22 15:46:37 +00:00
|
|
|
byte anyAnims = TRUE
|
2015-12-17 17:19:49 +00:00
|
|
|
word animPauseCt
|
2015-12-09 18:16:05 +00:00
|
|
|
|
2016-07-07 21:22:48 +00:00
|
|
|
// Shared string constants
|
2017-06-24 18:43:16 +00:00
|
|
|
export byte[] S_INTELLIGENCE = "Intelligence"
|
|
|
|
export byte[] S_STRENGTH = "Strength"
|
|
|
|
export byte[] S_AGILITY = "Agility"
|
|
|
|
export byte[] S_STAMINA = "Stamina"
|
|
|
|
export byte[] S_CHARISMA = "Charisma"
|
|
|
|
export byte[] S_SPIRIT = "Spirit"
|
|
|
|
export byte[] S_LUCK = "Luck"
|
|
|
|
export byte[] S_HEALTH = "Health"
|
|
|
|
export byte[] S_MAX_HEALTH = "Max health"
|
|
|
|
export byte[] S_AIMING = "Aiming"
|
|
|
|
export byte[] S_HAND_TO_HAND = "Hand to hand"
|
|
|
|
export byte[] S_DODGING = "Dodging"
|
|
|
|
export byte[] S_GOLD = "Gold"
|
|
|
|
export byte[] S_XP = "XP"
|
|
|
|
export byte[] S_SP = "SP"
|
|
|
|
export byte[] S_ENTER = "Enter"
|
|
|
|
export byte[] S_LEAVE = "Leave"
|
|
|
|
export byte[] S_USE = "Use"
|
2017-07-15 18:41:29 +00:00
|
|
|
export byte[] S_HIS = "his"
|
|
|
|
export byte[] S_HER = "her"
|
|
|
|
export byte[] S_THEIR = "their"
|
2016-07-07 21:22:48 +00:00
|
|
|
|
2014-08-21 15:17:50 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Definitions used by assembly code
|
2016-07-03 20:39:00 +00:00
|
|
|
asm _defs
|
2015-02-27 13:33:11 +00:00
|
|
|
|
2015-03-05 17:34:42 +00:00
|
|
|
; Use hi-bit ASCII for Apple II
|
|
|
|
!convtab "../../include/hiBitAscii.ct"
|
|
|
|
|
2015-02-27 13:33:11 +00:00
|
|
|
; Headers
|
2014-07-06 21:40:35 +00:00
|
|
|
!source "../../include/global.i"
|
|
|
|
!source "../../include/plasma.i"
|
|
|
|
!source "../../include/mem.i"
|
|
|
|
!source "../../include/fontEngine.i"
|
2015-02-27 13:33:11 +00:00
|
|
|
|
|
|
|
; Optional debug printing support
|
2015-06-06 16:37:04 +00:00
|
|
|
DEBUG = 0
|
2015-02-27 13:33:11 +00:00
|
|
|
|
|
|
|
; General use
|
|
|
|
tmp = $2
|
|
|
|
pTmp = $4
|
2015-11-19 16:27:04 +00:00
|
|
|
ysav = $34
|
2015-11-11 16:55:16 +00:00
|
|
|
ysav1 = $35
|
2015-02-27 13:33:11 +00:00
|
|
|
|
2015-08-21 15:57:15 +00:00
|
|
|
; 16-bit random number seed - incremented by ROM kbd routine
|
|
|
|
seed = $4E
|
2015-12-17 17:19:49 +00:00
|
|
|
magic = $2227 ; there are 2048 magic values that work; this one caught my eye. - MH
|
2015-08-21 15:57:15 +00:00
|
|
|
|
2015-12-29 16:59:13 +00:00
|
|
|
; 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.
|
2015-04-20 15:32:02 +00:00
|
|
|
|
2015-03-25 18:51:29 +00:00
|
|
|
end
|
|
|
|
|
2016-05-10 05:13:22 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Temporary hack: after scriptDisplayStr is called, generated code calls this to clear the PLASMA
|
|
|
|
// string pool. That way, many long strings can be used in a single function.
|
2017-06-11 17:15:20 +00:00
|
|
|
export asm tossStrings()#0
|
2016-07-07 21:22:48 +00:00
|
|
|
lda framePtr
|
|
|
|
sta outerFramePtr
|
|
|
|
lda framePtr+1
|
|
|
|
sta outerFramePtr+1
|
|
|
|
rts
|
2016-05-10 05:13:22 +00:00
|
|
|
end
|
|
|
|
|
2015-04-09 17:31:36 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// API to call rendering engine (same API for raycaster and tile engine)
|
2017-06-10 15:56:23 +00:00
|
|
|
asm initDisplay(mapPartition, mapNum, pMapData, x, y, dir)#0
|
2017-06-10 14:21:58 +00:00
|
|
|
+asmPlasmNoRet 6
|
2016-07-07 21:22:48 +00:00
|
|
|
jmp $6000
|
2015-04-09 17:31:36 +00:00
|
|
|
end
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm flipToPage1()#0
|
2017-06-10 14:21:58 +00:00
|
|
|
+asmPlasmNoRet 0
|
2016-07-07 21:22:48 +00:00
|
|
|
jmp $6003
|
2015-04-09 17:31:36 +00:00
|
|
|
end
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm getPos(px, py)#0
|
2017-06-10 14:21:58 +00:00
|
|
|
+asmPlasmNoRet 2
|
2016-07-07 21:22:48 +00:00
|
|
|
jmp $6006
|
2015-04-09 17:31:36 +00:00
|
|
|
end
|
2017-06-10 15:56:23 +00:00
|
|
|
asm setPos(x, y)#0
|
2017-06-10 14:21:58 +00:00
|
|
|
+asmPlasmNoRet 2
|
2016-07-07 21:22:48 +00:00
|
|
|
jmp $6009
|
2015-04-09 17:31:36 +00:00
|
|
|
end
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm getDir()#1 // returns: dir (0-15)
|
2017-06-10 14:21:58 +00:00
|
|
|
+asmPlasmRet 0
|
2016-07-07 21:22:48 +00:00
|
|
|
jmp $600C
|
2015-04-09 17:31:36 +00:00
|
|
|
end
|
2017-06-10 15:56:23 +00:00
|
|
|
asm setDir(dir)#0
|
2017-06-10 14:32:31 +00:00
|
|
|
+asmPlasmNoRet 1
|
2016-07-07 21:22:48 +00:00
|
|
|
jmp $600F
|
2015-04-09 17:31:36 +00:00
|
|
|
end
|
2017-06-10 15:56:23 +00:00
|
|
|
asm advance()#1 // returns: 0 if same pos, 1 if new pos, 2 if new pos and scripted
|
2017-06-10 14:21:58 +00:00
|
|
|
+asmPlasmRet 0
|
2016-07-07 21:22:48 +00:00
|
|
|
jmp $6012
|
2015-04-09 17:31:36 +00:00
|
|
|
end
|
2017-06-10 15:56:23 +00:00
|
|
|
asm setColor(slot, color)#0 // params: slot (0=sky/1=ground), color (0-17)
|
|
|
|
+asmPlasmNoRet 2
|
2016-07-07 21:22:48 +00:00
|
|
|
jmp $6015
|
2015-04-09 17:31:36 +00:00
|
|
|
end
|
2017-06-10 15:56:23 +00:00
|
|
|
asm render()#0
|
|
|
|
+asmPlasmNoRet 0
|
2016-07-07 21:22:48 +00:00
|
|
|
jmp $6018
|
2015-05-07 17:17:38 +00:00
|
|
|
end
|
2017-06-10 15:56:23 +00:00
|
|
|
asm texControl(doLoad)#0
|
|
|
|
+asmPlasmNoRet 1
|
2016-07-07 21:22:48 +00:00
|
|
|
jmp $601B
|
2015-12-28 18:20:28 +00:00
|
|
|
end
|
2017-06-10 15:56:23 +00:00
|
|
|
asm getMapScript()#1
|
2017-06-10 14:21:58 +00:00
|
|
|
+asmPlasmRet 0
|
2016-07-07 21:22:48 +00:00
|
|
|
jmp $601E
|
2015-12-17 17:19:49 +00:00
|
|
|
end
|
2017-06-10 15:56:23 +00:00
|
|
|
asm setAvatar(tileNum)#0 // tile number (in the global tileset)
|
|
|
|
+asmPlasmNoRet 1
|
2016-07-11 00:18:03 +00:00
|
|
|
jmp $6021
|
|
|
|
end
|
2017-06-10 15:56:23 +00:00
|
|
|
asm swapTile(fromX, fromY, toX, toY)#0
|
|
|
|
+asmPlasmNoRet 4
|
2016-11-01 16:25:36 +00:00
|
|
|
jmp $6024
|
|
|
|
end
|
2015-12-17 17:19:49 +00:00
|
|
|
|
2017-01-05 22:27:44 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
// Memory copy - Non-overlapping regions only!
|
|
|
|
export asm memcpy(pSrc, pDst, len)#0
|
|
|
|
+asmPlasmNoRet 3
|
2017-01-05 22:27:44 +00:00
|
|
|
lda evalStkL+2,x ; source ptr
|
|
|
|
sta tmp
|
|
|
|
lda evalStkH+2,x
|
|
|
|
sta tmp+1
|
|
|
|
lda evalStkL+1,x ; dest ptr
|
|
|
|
sta pTmp
|
|
|
|
lda evalStkH+1,x
|
|
|
|
sta pTmp+1
|
|
|
|
lda evalStkH,x ; len hi
|
|
|
|
pha
|
|
|
|
lda evalStkL,x ; len lo
|
|
|
|
tax
|
|
|
|
ldy #0
|
|
|
|
.pglup:
|
|
|
|
pla
|
|
|
|
sec
|
|
|
|
sbc #1
|
|
|
|
bcc .part
|
|
|
|
pha
|
|
|
|
- lda (tmp),y
|
|
|
|
sta (pTmp),y
|
|
|
|
iny
|
|
|
|
bne -
|
|
|
|
inc tmp+1
|
|
|
|
inc pTmp+1
|
|
|
|
bne .pglup ; always taken
|
|
|
|
.part:
|
|
|
|
cpx #0
|
|
|
|
beq .done
|
|
|
|
- lda (tmp),y
|
|
|
|
sta (pTmp),y
|
|
|
|
iny
|
|
|
|
dex
|
|
|
|
bne -
|
|
|
|
.done
|
|
|
|
rts
|
|
|
|
end
|
|
|
|
|
2017-03-22 16:46:17 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm memset(pDst, val, len)#0
|
|
|
|
+asmPlasmNoRet 3
|
2017-03-22 16:46:17 +00:00
|
|
|
ldy #0
|
|
|
|
lda evalStkL+2,x ; dest ptr
|
|
|
|
sta pTmp
|
|
|
|
lda evalStkH+2,x
|
|
|
|
sta pTmp+1
|
|
|
|
lda evalStkL+1,x ; value
|
|
|
|
sta tmp
|
|
|
|
lda evalStkL,x ; len lo
|
|
|
|
pha
|
|
|
|
lda evalStkH,x ; len hi
|
|
|
|
tax
|
|
|
|
beq +
|
|
|
|
lda tmp
|
|
|
|
- sta (pTmp),y
|
|
|
|
iny
|
|
|
|
bne -
|
|
|
|
inc pTmp+1
|
|
|
|
dex
|
|
|
|
bne -
|
|
|
|
+ pla
|
|
|
|
beq +
|
|
|
|
tax
|
|
|
|
lda tmp
|
|
|
|
- sta (pTmp),y
|
|
|
|
iny
|
|
|
|
dex
|
|
|
|
bne -
|
|
|
|
+ rts
|
|
|
|
end
|
|
|
|
|
2015-12-17 17:19:49 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
asm readAuxByte(ptr)#1
|
2017-06-10 14:21:58 +00:00
|
|
|
+asmPlasmRet 1
|
2016-07-07 21:22:48 +00:00
|
|
|
|
|
|
|
; Create the following subroutine, used to copy one char from aux to main:
|
|
|
|
;0010- 8D 03 C0 STA $C003
|
|
|
|
;0013- AD XX XX LDA $XXXX
|
|
|
|
;0016- 8D 02 C0 STA $C002
|
|
|
|
;0019- 60 RTS
|
|
|
|
|
|
|
|
sta $14
|
|
|
|
sty $15
|
|
|
|
lda #$8D
|
|
|
|
sta $10
|
|
|
|
sta $16
|
|
|
|
ldx #2
|
|
|
|
stx $17
|
|
|
|
inx
|
|
|
|
stx $11
|
|
|
|
lda #$C0
|
|
|
|
sta $12
|
|
|
|
sta $18
|
|
|
|
lda #$AD
|
|
|
|
sta $13
|
|
|
|
lda #$60
|
|
|
|
sta $19
|
|
|
|
|
|
|
|
; And call the routine
|
|
|
|
ldy #0
|
|
|
|
jmp $10
|
2015-12-17 17:19:49 +00:00
|
|
|
end
|
|
|
|
|
2017-01-12 17:08:05 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
asm splitExpander(expandVec)#1 // param: expandVec; returns: remaining lo-aux size
|
2017-06-10 14:21:58 +00:00
|
|
|
+asmPlasmRet 1
|
2017-01-12 17:08:05 +00:00
|
|
|
|
|
|
|
; assumes readAuxByte has just been called, which puts a little routine at $10.
|
|
|
|
; Adjust that routine to call expander instead of reading a byte.
|
|
|
|
sta $1B
|
|
|
|
sty $1C
|
|
|
|
lda #$6C
|
|
|
|
sta $1A
|
|
|
|
lda #$20
|
|
|
|
sta $13
|
|
|
|
|
|
|
|
lda #$60
|
|
|
|
sta 2
|
|
|
|
jsr 2
|
|
|
|
|
|
|
|
sei ; prevent interrupts while in aux mem
|
|
|
|
jsr $10
|
|
|
|
cli
|
|
|
|
rts
|
|
|
|
end
|
|
|
|
|
2015-11-11 16:55:16 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2016-07-12 15:09:55 +00:00
|
|
|
// String building for display with the font engine. Includes plurality processing to handily
|
2015-11-19 16:27:04 +00:00
|
|
|
// handle things like "Dirt bag(s)" and "his/their"
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm buildString(pFunc)#0
|
|
|
|
+asmPlasmNoRet 1
|
2016-07-07 21:22:48 +00:00
|
|
|
sta cswl
|
|
|
|
sty cswh
|
|
|
|
lda #0
|
|
|
|
sta inbuf
|
|
|
|
rts
|
2015-11-11 16:55:16 +00:00
|
|
|
end
|
|
|
|
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm addToString()#0
|
2016-07-07 21:22:48 +00:00
|
|
|
sty ysav1
|
|
|
|
inc inbuf
|
|
|
|
ldy inbuf
|
|
|
|
sta inbuf,y
|
|
|
|
ldy ysav1
|
|
|
|
rts
|
2015-11-11 16:55:16 +00:00
|
|
|
end
|
|
|
|
|
2017-05-24 14:47:47 +00:00
|
|
|
// Complete string building (including plural processing), and return pointer
|
|
|
|
// to the string (in the input buffer)
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm finishString(isPlural)#1
|
2015-11-19 16:27:04 +00:00
|
|
|
!zone {
|
2017-06-10 14:21:58 +00:00
|
|
|
+asmPlasmRet 1
|
2016-07-07 21:22:48 +00:00
|
|
|
sta tmp ; save isPlural flag
|
2016-08-08 14:47:01 +00:00
|
|
|
lda #$F0 ; put the cout vector back to default
|
|
|
|
sta cswl
|
|
|
|
lda #$FD
|
2016-08-13 02:18:31 +00:00
|
|
|
sta cswh
|
2016-08-08 14:47:01 +00:00
|
|
|
bit fixedRTS; V flag for prev-is-punctuation
|
2016-07-07 21:22:48 +00:00
|
|
|
ldy #1 ; dest offset in Y
|
|
|
|
ldx #1 ; source offset in X
|
|
|
|
cpx inbuf
|
|
|
|
beq + ; only process if string has at least 1 char
|
|
|
|
bcs .done
|
|
|
|
+ sty tmp+1 ; offset of last punctuation
|
|
|
|
.fetch
|
|
|
|
lda inbuf,x
|
|
|
|
cmp #"("
|
|
|
|
bne .notpar
|
|
|
|
bvs .notpar ; skip paren processing right punctuation
|
|
|
|
lda tmp ; check isPlural flag
|
|
|
|
bne .plurpr
|
|
|
|
- lda inbuf,x ; it's singular, so skip everything in parens
|
|
|
|
cmp #")"
|
|
|
|
beq .next
|
|
|
|
inx
|
|
|
|
cpx inbuf
|
|
|
|
bne -
|
|
|
|
beq .done ; handle missing trailing paren
|
|
|
|
.plurpr
|
|
|
|
inx ; it's plural, so copy everything within the parens
|
|
|
|
lda inbuf,x ; copy characters
|
|
|
|
cpx inbuf ; handle missing trailing paren
|
2017-03-23 15:00:49 +00:00
|
|
|
beq +
|
|
|
|
bcs .store
|
|
|
|
+ cmp #")" ; go until we reach ending paren
|
2016-07-07 21:22:48 +00:00
|
|
|
beq .next
|
|
|
|
sta inbuf,y
|
|
|
|
iny
|
|
|
|
bne .plurpr ; always taken
|
|
|
|
|
|
|
|
.notpar
|
|
|
|
cmp #"/"
|
|
|
|
bne .notsl
|
|
|
|
bvs .notsl ; skip slash processing right after punctuation
|
|
|
|
lda tmp ; check isPlural flag
|
|
|
|
bne .plursl
|
|
|
|
- inx ; loop that skips plural form
|
|
|
|
cpx inbuf
|
|
|
|
beq +
|
|
|
|
bcs .done ; handle end of string
|
|
|
|
+ lda inbuf,x
|
|
|
|
cmp #"A" ; eat letters (and stop when we hit punctuation)
|
|
|
|
bcs -
|
|
|
|
bcc .store ; copy the ending punctuation and continue normal processing
|
|
|
|
.plursl
|
|
|
|
ldy tmp+1 ; erase singular form by backing up to prev punc
|
|
|
|
iny ; plus 1 to retain prev punc
|
|
|
|
bne .next ; resume regular copying of the plural form
|
|
|
|
|
|
|
|
.notsl
|
|
|
|
cmp #"A" ; if <= ASCII "A", consider it punctuation
|
|
|
|
bcc +
|
|
|
|
clv ; clear last-is-punc flag
|
|
|
|
bvc .store ; always taken
|
2016-08-08 14:47:01 +00:00
|
|
|
+ bit fixedRTS; set prev-is-punc flag
|
2016-07-07 21:22:48 +00:00
|
|
|
sty tmp+1 ; save dest offset of last punctuation
|
|
|
|
|
|
|
|
.store
|
|
|
|
sta inbuf,y ; save to dest
|
|
|
|
iny
|
|
|
|
|
|
|
|
.next
|
|
|
|
inx
|
|
|
|
cpx inbuf ; compare src offset to length
|
|
|
|
bcc .fetch ; loop while less than
|
|
|
|
beq .fetch ; or equal
|
|
|
|
|
|
|
|
.done
|
|
|
|
dey
|
|
|
|
sty inbuf ; save new length
|
2017-05-24 14:47:47 +00:00
|
|
|
lda #<inbuf ; return pointer to string
|
2016-07-07 21:22:48 +00:00
|
|
|
ldy #>inbuf
|
|
|
|
rts
|
2015-11-19 16:27:04 +00:00
|
|
|
}
|
2015-11-11 16:55:16 +00:00
|
|
|
end
|
|
|
|
|
2015-05-27 15:13:09 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-08-04 15:15:40 +00:00
|
|
|
asm blit(isAux, srcData, dstScreenPtr, nLines, lineSize)#0
|
|
|
|
+asmPlasmNoRet 5
|
2016-10-11 16:03:57 +00:00
|
|
|
|
|
|
|
; Save line size
|
|
|
|
sta ysav
|
|
|
|
|
|
|
|
; Save nLines
|
|
|
|
lda evalStkL+1,x
|
|
|
|
pha
|
2016-07-07 21:22:48 +00:00
|
|
|
|
|
|
|
; Save the dest pointer
|
2016-10-11 16:03:57 +00:00
|
|
|
lda evalStkL+2,x
|
2016-07-07 21:22:48 +00:00
|
|
|
sta pTmp
|
2016-10-11 16:03:57 +00:00
|
|
|
lda evalStkH+2,x
|
|
|
|
sta pTmp+1
|
2016-07-07 21:22:48 +00:00
|
|
|
|
|
|
|
; Save the source pointer
|
2016-10-11 16:03:57 +00:00
|
|
|
lda evalStkL+3,x
|
2016-07-07 21:22:48 +00:00
|
|
|
sta tmp
|
2016-10-11 16:03:57 +00:00
|
|
|
lda evalStkH+3,x
|
2016-07-07 21:22:48 +00:00
|
|
|
sta tmp+1
|
|
|
|
|
2017-08-04 15:15:40 +00:00
|
|
|
; Save aux/main flag
|
|
|
|
lda evalStkL+4,x
|
|
|
|
lsr ; to carry bit
|
|
|
|
bcc +
|
|
|
|
; If reading from aux, create the following subroutine:
|
2016-07-07 21:22:48 +00:00
|
|
|
; 0010- 8D 03 C0 STA $C003
|
|
|
|
; 0013- B1 02 LDA ($02),Y
|
|
|
|
; 0015- 91 04 STA ($04),Y
|
|
|
|
; 0017- 88 DEY
|
|
|
|
; 0018- 10 F9 BPL $0013
|
|
|
|
; 001A- 8D 02 C0 STA $C002
|
|
|
|
; 001D- 60 RTS
|
|
|
|
lda #$8D
|
|
|
|
sta $10
|
|
|
|
sta $1A
|
|
|
|
ldx #2
|
|
|
|
stx $14
|
|
|
|
stx $1B
|
|
|
|
inx
|
|
|
|
stx $11
|
|
|
|
lda #$C0
|
|
|
|
sta $12
|
|
|
|
sta $1C
|
|
|
|
lda #$B1
|
|
|
|
sta $13
|
|
|
|
lda #$91
|
|
|
|
sta $15
|
|
|
|
inx
|
|
|
|
stx $16
|
|
|
|
lda #$88
|
|
|
|
sta $17
|
|
|
|
lda #$10
|
|
|
|
sta $18
|
|
|
|
lda #$F9
|
|
|
|
sta $19
|
|
|
|
lda #$60
|
|
|
|
sta $1D
|
2017-08-04 15:15:40 +00:00
|
|
|
+ pla ; get line count
|
2016-10-11 16:03:57 +00:00
|
|
|
tax
|
2017-08-04 15:15:40 +00:00
|
|
|
--
|
|
|
|
ldy ysav ; get byte count
|
2016-10-11 16:03:57 +00:00
|
|
|
dey
|
2017-08-04 15:15:40 +00:00
|
|
|
bcc +
|
|
|
|
jsr $10 ; copy pixel bytes (aux version)
|
|
|
|
bcs ++
|
|
|
|
+
|
|
|
|
- lda (tmp),y
|
|
|
|
sta (pTmp),y
|
|
|
|
dey
|
|
|
|
bpl -
|
|
|
|
++
|
|
|
|
php
|
2017-03-22 16:46:17 +00:00
|
|
|
lda tmp ; advance to next row of data
|
2016-07-07 21:22:48 +00:00
|
|
|
clc
|
2016-10-11 16:03:57 +00:00
|
|
|
adc ysav
|
2016-07-07 21:22:48 +00:00
|
|
|
sta tmp
|
|
|
|
bcc +
|
|
|
|
inc tmp+1
|
2017-03-22 16:46:17 +00:00
|
|
|
+ jsr NextScreenLine ; and next screen line
|
2017-08-04 15:15:40 +00:00
|
|
|
plp
|
2017-03-22 16:46:17 +00:00
|
|
|
dex
|
2017-08-04 15:15:40 +00:00
|
|
|
bne -- ; Loop until we've done all rows.
|
2017-03-22 16:46:17 +00:00
|
|
|
rts
|
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
asm vline(dstScreenPtr, val, nLines)#0
|
|
|
|
+asmPlasmNoRet 3
|
2017-03-22 16:46:17 +00:00
|
|
|
|
|
|
|
; Save number of lines
|
|
|
|
pha
|
|
|
|
|
|
|
|
; Save value
|
|
|
|
lda evalStkL+1,x
|
|
|
|
sta tmp
|
|
|
|
|
|
|
|
; Save the dest pointer
|
|
|
|
lda evalStkL+2,x
|
2016-07-07 21:22:48 +00:00
|
|
|
sta pTmp
|
2017-03-22 16:46:17 +00:00
|
|
|
lda evalStkH+2,x
|
|
|
|
sta pTmp+1
|
|
|
|
|
|
|
|
pla ; line count
|
|
|
|
tax
|
|
|
|
- ldy #0
|
|
|
|
lda tmp
|
|
|
|
sta (pTmp),y
|
|
|
|
jsr NextScreenLine
|
2016-07-07 21:22:48 +00:00
|
|
|
dex
|
2017-03-22 16:46:17 +00:00
|
|
|
bne -
|
2016-07-07 21:22:48 +00:00
|
|
|
rts
|
2015-05-27 15:13:09 +00:00
|
|
|
end
|
|
|
|
|
2015-04-20 15:32:02 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Simply retrieve the X register. Used to double-check that we're not leaking PLASMA eval
|
|
|
|
// stack entries.
|
2017-06-10 15:56:23 +00:00
|
|
|
asm getXReg()#1
|
2017-06-10 14:21:58 +00:00
|
|
|
+asmPlasmRet 0
|
2016-07-07 21:22:48 +00:00
|
|
|
txa
|
|
|
|
ldy #0
|
|
|
|
rts
|
2015-04-20 15:32:02 +00:00
|
|
|
end
|
|
|
|
|
2015-06-30 16:27:10 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
// Calculate 16-bit hash of a buffer.
|
|
|
|
export asm hashBuffer(ptr, len)#1
|
2017-06-10 14:21:58 +00:00
|
|
|
+asmPlasmRet 2
|
2016-08-05 16:27:11 +00:00
|
|
|
lda evalStkL+1,x ; first arg is buffer pointer
|
2016-07-07 21:22:48 +00:00
|
|
|
sta pTmp
|
2016-08-05 16:27:11 +00:00
|
|
|
lda evalStkH+1,x
|
|
|
|
sta pTmp+1
|
|
|
|
lda evalStkL,x ; second arg is length
|
|
|
|
tax
|
2016-07-07 21:22:48 +00:00
|
|
|
ldy #0
|
|
|
|
sty tmp+1
|
2016-08-05 16:27:11 +00:00
|
|
|
tya
|
|
|
|
clc
|
|
|
|
- adc (pTmp),y
|
|
|
|
ror
|
|
|
|
ror tmp+1
|
|
|
|
ror
|
|
|
|
ror tmp+1
|
|
|
|
ror
|
|
|
|
ror tmp+1
|
2016-07-07 21:22:48 +00:00
|
|
|
iny
|
|
|
|
dex
|
|
|
|
bne -
|
|
|
|
ldy tmp+1
|
|
|
|
rts
|
2015-06-30 16:27:10 +00:00
|
|
|
end
|
|
|
|
|
2014-08-21 15:17:50 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2016-03-22 15:22:26 +00:00
|
|
|
// Print a string to the current character output vector
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm puts(str)#0
|
2017-06-10 14:21:58 +00:00
|
|
|
+asmPlasmNoRet 1
|
2016-07-07 21:22:48 +00:00
|
|
|
sta pTmp
|
2017-06-02 15:25:29 +00:00
|
|
|
lda #'!'
|
|
|
|
ldx #1
|
2016-07-07 21:22:48 +00:00
|
|
|
sty pTmp+1
|
2017-06-02 15:25:29 +00:00
|
|
|
beq + ; safety: print '!' instead of null string
|
2016-07-07 21:22:48 +00:00
|
|
|
ldy #0
|
|
|
|
lda (pTmp),y
|
|
|
|
tax
|
2017-07-16 19:34:24 +00:00
|
|
|
beq ++ ; handle empty string
|
2016-07-07 21:22:48 +00:00
|
|
|
iny
|
|
|
|
- lda (pTmp),y
|
2017-06-02 15:25:29 +00:00
|
|
|
+ ora #$80
|
2016-08-08 14:47:01 +00:00
|
|
|
+safeCout
|
2016-07-07 21:22:48 +00:00
|
|
|
iny
|
|
|
|
dex
|
|
|
|
bne -
|
2017-07-16 19:34:24 +00:00
|
|
|
++ rts
|
2014-07-06 14:40:57 +00:00
|
|
|
end
|
|
|
|
|
2015-09-05 18:01:45 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Get a character from the keyboard
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm rdkey()#1
|
2017-06-10 14:21:58 +00:00
|
|
|
+asmPlasmRet 0
|
2016-08-08 15:09:46 +00:00
|
|
|
+safeRdkey
|
2016-08-08 14:47:01 +00:00
|
|
|
ldy #0
|
|
|
|
rts
|
2015-09-05 18:01:45 +00:00
|
|
|
end
|
|
|
|
|
2014-08-21 15:17:50 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-03-05 17:34:42 +00:00
|
|
|
// Print part of a string, until we hit the end or a '%' code. Return how far we got, or -1 for end.
|
2017-06-10 15:56:23 +00:00
|
|
|
asm partialPrintf(str, pos)#1
|
2015-04-20 15:32:02 +00:00
|
|
|
!zone {
|
2017-06-10 14:21:58 +00:00
|
|
|
+asmPlasmRet 2
|
2016-07-07 21:22:48 +00:00
|
|
|
lda evalStkL+1,x ; get string pointer
|
|
|
|
sta pTmp
|
|
|
|
lda evalStkH+1,x
|
|
|
|
sta pTmp+1
|
|
|
|
ldy #0
|
|
|
|
lda (pTmp),y ; get length byte
|
|
|
|
sec
|
|
|
|
sbc evalStkL,x ; minus offset
|
|
|
|
sta tmp ; to count of characters left to print
|
|
|
|
bcc .eos ; avoid overrunning
|
|
|
|
beq .eos
|
|
|
|
lda evalStkL,x ; get desired offset into string
|
|
|
|
tay
|
|
|
|
iny ; increment past length byte
|
|
|
|
- lda (pTmp),y
|
|
|
|
ora #$80
|
|
|
|
cmp #'%' ; stop if we hit % code
|
|
|
|
beq +
|
2016-08-08 14:47:01 +00:00
|
|
|
+safeCout
|
2016-07-07 21:22:48 +00:00
|
|
|
iny
|
|
|
|
dec tmp ; otherwise go until end of string
|
|
|
|
bne -
|
|
|
|
.eos
|
|
|
|
ldy #$FF ; if we hit end of string, return -1
|
|
|
|
tya
|
|
|
|
rts
|
|
|
|
+ dey ; adjust back for length byte
|
|
|
|
tya ; that's the lo byte of return
|
|
|
|
ldy #0 ; hi byte of return is zero
|
|
|
|
rts
|
2015-04-20 15:32:02 +00:00
|
|
|
}
|
2015-03-05 17:34:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Print a 16-bit hex value
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm printHex(num)#0
|
|
|
|
+asmPlasmNoRet 1
|
2016-08-22 15:08:22 +00:00
|
|
|
pha
|
|
|
|
tya
|
|
|
|
+safePrbyte
|
|
|
|
pla
|
|
|
|
jmp _safePrbyte
|
2015-03-05 17:34:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Print a single character
|
2017-06-10 15:56:23 +00:00
|
|
|
asm printChar(ch)#0
|
|
|
|
+asmPlasmNoRet 1
|
2016-07-07 21:22:48 +00:00
|
|
|
ora #$80
|
2016-08-08 14:47:01 +00:00
|
|
|
jmp _safeCout
|
2014-06-25 15:47:28 +00:00
|
|
|
end
|
2014-07-03 23:56:26 +00:00
|
|
|
|
2015-01-10 21:17:56 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Print a carriage return
|
2017-06-10 15:56:23 +00:00
|
|
|
asm crout()#0
|
|
|
|
+asmPlasmNoRet 0
|
2016-08-08 14:47:01 +00:00
|
|
|
lda #$8D
|
|
|
|
jmp _safeCout
|
2014-07-06 23:02:52 +00:00
|
|
|
end
|
|
|
|
|
2015-01-10 21:17:56 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Ring the bell
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm beep()#0
|
|
|
|
+asmPlasmNoRet 0
|
2016-08-08 15:09:46 +00:00
|
|
|
+safeBell
|
|
|
|
rts
|
2014-07-19 22:55:27 +00:00
|
|
|
end
|
|
|
|
|
2015-05-03 16:25:57 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Read a string from the keyboard, turn it into a PLASMA string and return a pointer to the string.
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm readStr()#1
|
2017-06-10 14:21:58 +00:00
|
|
|
+asmPlasmRet 0
|
2016-08-08 15:09:46 +00:00
|
|
|
bit setROM
|
2016-08-08 14:47:01 +00:00
|
|
|
jsr ROM_getln1
|
2016-08-08 15:09:46 +00:00
|
|
|
bit setLcRW+lcBank2
|
2016-07-07 21:22:48 +00:00
|
|
|
txa
|
|
|
|
pha
|
|
|
|
beq +
|
|
|
|
- lda inbuf-1,x
|
|
|
|
and #$7F
|
|
|
|
sta inbuf,x
|
|
|
|
dex
|
|
|
|
bne -
|
|
|
|
+ pla
|
|
|
|
sta inbuf,x
|
|
|
|
lda #<inbuf
|
|
|
|
ldy #>inbuf
|
|
|
|
rts
|
2015-05-03 16:25:57 +00:00
|
|
|
end
|
|
|
|
|
2014-08-21 15:17:50 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-01-10 21:17:56 +00:00
|
|
|
// Send a command to the memory manager
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm mmgr(cmd, wordParam)#1
|
2017-06-10 14:21:58 +00:00
|
|
|
+asmPlasmRet 2
|
2016-07-07 21:22:48 +00:00
|
|
|
lda evalStkL+1,x ; command code
|
|
|
|
pha
|
|
|
|
ldy evalStkH,x ; address (or other param)... hi byte in Y
|
|
|
|
lda evalStkL,x
|
|
|
|
tax ; ...lo byte in X
|
|
|
|
pla
|
|
|
|
jsr mainLoader ; ret value in X=lo/Y=hi
|
|
|
|
txa ; to A=lo/Y=hi for asmPlasm
|
|
|
|
rts
|
2015-08-19 14:22:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
// Aux version of memory manager command
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm auxMmgr(cmd, wordParam)#1
|
2017-06-10 14:21:58 +00:00
|
|
|
+asmPlasmRet 2
|
2016-07-07 21:22:48 +00:00
|
|
|
lda evalStkL+1,x ; command code
|
|
|
|
pha
|
|
|
|
ldy evalStkH,x ; address (or other param)
|
|
|
|
lda evalStkL,x
|
|
|
|
tax
|
|
|
|
pla
|
|
|
|
jsr auxLoader ; ret value in X=lo/Y=hi
|
|
|
|
txa ; to A=lo/Y=hi for asmPlasm
|
|
|
|
rts
|
2014-07-06 21:40:35 +00:00
|
|
|
end
|
|
|
|
|
2014-08-21 15:17:50 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Jump straight to the system monitor
|
2017-06-10 15:56:23 +00:00
|
|
|
asm goMon()#0
|
2016-07-07 21:22:48 +00:00
|
|
|
jmp $FF69
|
2014-07-03 23:56:26 +00:00
|
|
|
end
|
|
|
|
|
2015-03-03 17:03:22 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-04-05 16:52:38 +00:00
|
|
|
// Execute a monitor breakpoint
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm brk()#0
|
2016-07-07 21:22:48 +00:00
|
|
|
bit setText
|
|
|
|
bit page1
|
|
|
|
brk
|
2015-03-03 17:03:22 +00:00
|
|
|
end
|
|
|
|
|
2015-06-07 22:50:06 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Set up the font engine
|
2017-06-10 15:56:23 +00:00
|
|
|
asm setFont(pFont)#0
|
|
|
|
+asmPlasmNoRet 1
|
2015-06-07 22:50:06 +00:00
|
|
|
jmp SetFont
|
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-11-30 16:02:32 +00:00
|
|
|
// Use the font engine to clear the current text window.
|
|
|
|
// Parameters: top, bottom, left, right
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm setWindow(top, bottom, left, right)#0
|
|
|
|
+asmPlasmNoRet 4
|
2015-06-07 22:50:06 +00:00
|
|
|
jmp SetWindow
|
|
|
|
end
|
|
|
|
|
2015-12-05 23:01:44 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-07-08 23:36:08 +00:00
|
|
|
// Get the cursor position - returns X, Y
|
|
|
|
export asm getCursor()#2
|
|
|
|
bit setLcRW+lcBank2
|
|
|
|
jmp GetCursor
|
2015-12-05 23:01:44 +00:00
|
|
|
end
|
|
|
|
|
2016-03-22 15:22:26 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Read a keyboard string up to 40 chars using the Font Engine. Returns a zero-terminated string
|
|
|
|
// in the input buffer at $200, with the length stored in $2FF.
|
2017-06-10 15:56:23 +00:00
|
|
|
asm rawGetStr()#1
|
2017-06-10 14:21:58 +00:00
|
|
|
+asmPlasmRet 0
|
2016-03-22 15:22:26 +00:00
|
|
|
jmp GetStr
|
|
|
|
end
|
|
|
|
|
2014-08-21 15:17:50 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Use the font engine to clear the current text window
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm clearWindow()#0
|
|
|
|
+asmPlasmNoRet 0
|
2015-06-07 22:50:06 +00:00
|
|
|
jmp ClearWindow
|
2014-07-09 02:11:03 +00:00
|
|
|
end
|
|
|
|
|
2015-06-11 18:02:02 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Use the font engine to copy the current text window to hi-res page 2
|
2017-06-10 15:56:23 +00:00
|
|
|
asm copyWindow()#0
|
|
|
|
+asmPlasmNoRet 0
|
2015-06-11 18:02:02 +00:00
|
|
|
jmp CopyWindow
|
|
|
|
end
|
|
|
|
|
2015-06-08 15:07:04 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Display a character using the font engine.
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm displayChar(ch)#0
|
|
|
|
+asmPlasmNoRet 1
|
2015-06-08 15:07:04 +00:00
|
|
|
jmp DisplayChar
|
|
|
|
end
|
|
|
|
|
2015-05-27 15:13:09 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-06-07 20:40:04 +00:00
|
|
|
// Display a string using the font engine.
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm displayStr(str)#0
|
|
|
|
+asmPlasmNoRet 1
|
2015-06-07 22:50:06 +00:00
|
|
|
jmp DisplayStr
|
2014-07-08 16:39:31 +00:00
|
|
|
end
|
|
|
|
|
2015-11-05 17:09:45 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Calculate string width using the font engine.
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm calcWidth(pStr)#1
|
2017-06-10 14:21:58 +00:00
|
|
|
+asmPlasmRet 1
|
2015-11-05 17:09:45 +00:00
|
|
|
jmp CalcWidth
|
|
|
|
end
|
|
|
|
|
2017-03-22 16:46:17 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Get the address of the given hi-res screen line
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm getScreenLine(n)#1
|
2017-06-10 14:21:58 +00:00
|
|
|
+asmPlasmRet 1
|
2017-03-22 16:46:17 +00:00
|
|
|
jmp GetScreenLine
|
|
|
|
end
|
|
|
|
|
2015-07-11 15:58:00 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-07-14 15:41:10 +00:00
|
|
|
// Display a string using the font engine but not its parser. Also, interpret "^A" as ctrl chars.
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm rawDisplayStr(pStr)#0
|
|
|
|
+asmPlasmNoRet 1
|
2015-07-11 15:58:00 +00:00
|
|
|
sta pTmp
|
|
|
|
sty pTmp+1
|
|
|
|
ldy #0
|
|
|
|
lda (pTmp),y
|
|
|
|
sta tmp
|
|
|
|
- cpy tmp
|
|
|
|
bcc +
|
|
|
|
rts
|
|
|
|
+ iny
|
|
|
|
lda (pTmp),y
|
|
|
|
ora #$80
|
|
|
|
cmp #"^"
|
|
|
|
bne +
|
|
|
|
iny
|
|
|
|
lda (pTmp),y
|
2017-07-14 15:41:10 +00:00
|
|
|
cmp #"^"
|
|
|
|
beq +
|
2015-07-11 15:58:00 +00:00
|
|
|
and #$1F
|
|
|
|
ora #$80
|
|
|
|
+ sty tmp+1
|
|
|
|
jsr DisplayChar
|
|
|
|
ldy tmp+1
|
|
|
|
bne -
|
|
|
|
end
|
|
|
|
|
2015-08-21 15:57:15 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Random number generator
|
|
|
|
// Adapted from http://codebase64.org/doku.php?id=base:small_fast_16-bit_prng
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm rand16()#1
|
2017-06-10 14:21:58 +00:00
|
|
|
+asmPlasmRet 0
|
2015-08-21 15:57:15 +00:00
|
|
|
|
|
|
|
lda seed
|
|
|
|
beq .lowZero ; $0000 and $8000 are special values to test for
|
2016-07-12 15:09:55 +00:00
|
|
|
|
2015-08-21 15:57:15 +00:00
|
|
|
; Do a normal shift
|
|
|
|
asl seed
|
|
|
|
lda seed+1
|
|
|
|
rol
|
|
|
|
bcc .noEor
|
2016-07-12 15:09:55 +00:00
|
|
|
|
2015-08-21 15:57:15 +00:00
|
|
|
.doEor:
|
2015-11-30 16:49:46 +00:00
|
|
|
; high byte is in A
|
2015-08-21 15:57:15 +00:00
|
|
|
eor #>magic
|
|
|
|
sta seed+1
|
|
|
|
tay ; for asmPlasm, return hi byte in Y, lo byte in A
|
|
|
|
lda seed
|
|
|
|
eor #<magic
|
|
|
|
sta seed
|
|
|
|
rts
|
2016-07-12 15:09:55 +00:00
|
|
|
|
2015-08-21 15:57:15 +00:00
|
|
|
.lowZero:
|
|
|
|
lda seed+1
|
|
|
|
beq .doEor ; High byte is also zero, so apply the EOR
|
|
|
|
; For speed, you could store 'magic' into 'seed' directly
|
|
|
|
; instead of running the EORs
|
2016-07-12 15:09:55 +00:00
|
|
|
|
2015-08-21 15:57:15 +00:00
|
|
|
; wasn't zero, check for $8000
|
|
|
|
asl
|
|
|
|
beq .noEor ; if $00 is left after the shift, then it was $80
|
|
|
|
bcs .doEor ; else, do the EOR based on the carry bit as usual
|
2016-07-12 15:09:55 +00:00
|
|
|
|
2015-08-21 15:57:15 +00:00
|
|
|
.noEor:
|
|
|
|
sta seed+1
|
|
|
|
tay ; for asmPlasm, return hi byte in Y, lo byte in A
|
|
|
|
lda seed
|
|
|
|
rts
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2016-09-24 18:10:17 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Clear the text-mode screen, and put the text cursor at the top of it.
|
2017-06-10 15:56:23 +00:00
|
|
|
export asm textHome()#0
|
|
|
|
+asmPlasmNoRet 0
|
2016-09-24 18:10:17 +00:00
|
|
|
+safeHome
|
|
|
|
rts
|
|
|
|
end
|
|
|
|
|
2017-06-24 18:43:16 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Compare two strings for equality, ignoring case.
|
|
|
|
export asm streqi(a, b)#1
|
|
|
|
+asmPlasmRet 2
|
|
|
|
sta tmp
|
|
|
|
sty tmp+1
|
|
|
|
lda evalStkL+1,x
|
|
|
|
sta pTmp
|
|
|
|
lda evalStkH+1,x
|
|
|
|
sta pTmp+1
|
|
|
|
ldy #0
|
|
|
|
lda (tmp),y
|
|
|
|
cmp (pTmp),y
|
|
|
|
beq + ; if lengths not equal, strings can't be equal
|
|
|
|
--
|
|
|
|
lda #0
|
|
|
|
tay
|
|
|
|
rts
|
|
|
|
+ tax ; count up to (verified same) length of the strings
|
|
|
|
- iny
|
|
|
|
lda (tmp),y
|
|
|
|
cmp #('z'&$7F)+1 ; convert to upper case
|
|
|
|
bcs +
|
|
|
|
cmp #'a'&$7F
|
|
|
|
bcc +
|
|
|
|
sbc #$20
|
|
|
|
+ sta ysav
|
|
|
|
lda (pTmp),y
|
|
|
|
cmp #('z'&$7F)+1 ; convert to upper case
|
|
|
|
bcs +
|
|
|
|
cmp #'a'&$7F
|
|
|
|
bcc +
|
|
|
|
sbc #$20
|
|
|
|
+ cmp ysav
|
|
|
|
bne -- ; abort on inequality
|
|
|
|
dex
|
|
|
|
bne -
|
|
|
|
ldy #0 ; okay, they're equal. Return non-zero (A is guaranteed to be a character already)
|
|
|
|
rts
|
|
|
|
end
|
|
|
|
|
2017-06-30 15:11:34 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Multiply 16 bit number by 8-bit ratio, and drop lower 8 bits of result. In effect this scales
|
|
|
|
// num by the approximate ratio 0=0% .. 128=50% .. 255=99%
|
|
|
|
asm mulRatio(num, ratio)#1
|
|
|
|
+asmPlasmRet 2
|
|
|
|
.ratio = evalStkL
|
|
|
|
.numL = evalStkL+1
|
|
|
|
.numH = evalStkH+1
|
|
|
|
.numHH = tmp
|
|
|
|
.accLL = tmp+1
|
|
|
|
.accL = pTmp
|
|
|
|
.accH = pTmp+1
|
|
|
|
lda .ratio,x ; save ratio
|
|
|
|
ldy #0
|
|
|
|
sty .numHH ; zero what will become upper 8 bits of num
|
|
|
|
sty .accLL ; clear accumulation area
|
|
|
|
sty .accL
|
|
|
|
sty .accH
|
|
|
|
ldy #8 ; loop over 8 bits of ratio
|
|
|
|
- lsr ; get next bit
|
|
|
|
bcc + ; skip add if clear
|
|
|
|
pha
|
|
|
|
clc
|
|
|
|
lda .numL,x ; 24-bit add
|
|
|
|
adc .accLL
|
|
|
|
sta .accLL
|
|
|
|
lda .numH,x
|
|
|
|
adc .accL
|
|
|
|
sta .accL
|
|
|
|
lda .numHH
|
|
|
|
adc .accH
|
|
|
|
sta .accH
|
|
|
|
pla
|
|
|
|
+ asl .numL,x ; shift number up
|
|
|
|
rol .numH,x
|
|
|
|
rol .numHH
|
|
|
|
dey ; and loop again
|
|
|
|
bne -
|
|
|
|
ldy .accH ; final result in Y/A
|
|
|
|
lda .accL
|
|
|
|
rts
|
|
|
|
end
|
|
|
|
|
2014-08-21 15:17:50 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// General methods
|
2014-07-06 23:45:27 +00:00
|
|
|
|
2015-01-10 21:17:56 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Fatal error: print message and stop the system.
|
2017-06-10 15:56:23 +00:00
|
|
|
// Doesn't really return a value, but can be handy for chaining.
|
|
|
|
export def fatal(msg)#1
|
|
|
|
return mmgr(FATAL_ERROR, msg)
|
2014-07-19 22:55:27 +00:00
|
|
|
end
|
|
|
|
|
2015-12-05 23:01:44 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-12-17 14:48:30 +00:00
|
|
|
// Return the max of two signed 16-bit numbers
|
2017-06-10 15:56:23 +00:00
|
|
|
export def max(a, b)#1
|
|
|
|
if a < b; return b; fin
|
|
|
|
return a
|
2015-12-05 23:01:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-12-17 14:48:30 +00:00
|
|
|
// Return the min of two signed 16-bit numbers
|
2017-06-10 15:56:23 +00:00
|
|
|
export def min(a, b)#1
|
|
|
|
if a < b; return a; fin
|
|
|
|
return b
|
2015-12-05 23:01:44 +00:00
|
|
|
end
|
|
|
|
|
2016-03-29 22:17:42 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Return the absolute value of a number
|
2017-07-07 17:18:43 +00:00
|
|
|
export def abs(n)#1
|
2017-06-10 15:56:23 +00:00
|
|
|
if n < 0; return -n; fin
|
|
|
|
return n
|
2016-03-29 22:17:42 +00:00
|
|
|
end
|
|
|
|
|
2017-05-24 14:47:47 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Convert a lower-case character to upper-case (or return unchanged if it's not lower-case)
|
2017-06-10 15:56:23 +00:00
|
|
|
export def charToUpper(c)#1
|
2017-05-24 14:47:47 +00:00
|
|
|
if c >= 'a' and c <= 'z'
|
|
|
|
return c - $20
|
|
|
|
fin
|
|
|
|
return c
|
|
|
|
end
|
|
|
|
|
2016-03-22 15:22:26 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Read a string from the keyboard using the font manager, and intern it to the heap.
|
2017-06-10 15:56:23 +00:00
|
|
|
export def getStringResponse()#1
|
2016-03-22 15:22:26 +00:00
|
|
|
word p
|
|
|
|
rawGetStr()
|
|
|
|
rawDisplayStr("\n") // so Outlaw user doesn't have to remember to make a newline
|
|
|
|
for p = ($1FF + ^$2FF) downto $200
|
|
|
|
p->1 = (^p & $7F)
|
|
|
|
next
|
|
|
|
^$200 = ^$2FF
|
|
|
|
return mmgr(HEAP_INTERN, $200)
|
|
|
|
end
|
|
|
|
|
2015-12-23 23:42:37 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Setter functions for library use
|
2017-06-10 15:56:23 +00:00
|
|
|
export def setPlural(flg)#0
|
2015-12-23 23:42:37 +00:00
|
|
|
isPlural = flg
|
|
|
|
end
|
|
|
|
|
2015-03-25 14:40:46 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-01-15 17:10:43 +00:00
|
|
|
// Convert signed decimal to string in decimalBuf (@decimalBuf returned)
|
2017-06-10 15:56:23 +00:00
|
|
|
def convertDec(n)#1
|
2015-05-03 16:25:57 +00:00
|
|
|
word n0
|
2015-11-05 17:09:45 +00:00
|
|
|
word p
|
|
|
|
p = @decimalBuf + 1
|
|
|
|
if n < 0; ^p = '-'; p=p+1; n = -n; fin
|
2015-05-03 16:25:57 +00:00
|
|
|
n0 = n
|
2015-11-05 17:09:45 +00:00
|
|
|
if n0 > 9999; ^p = '0' + n/10000; p=p+1; n = n%10000; fin
|
|
|
|
if n0 > 999; ^p = '0' + n/1000; p=p+1; n = n%1000; fin
|
|
|
|
if n0 > 99; ^p = '0' + n/100; p=p+1; n = n%100; fin
|
|
|
|
if n0 > 9; ^p = '0' + n/10; p=p+1; n = n%10; fin
|
|
|
|
^p = '0' + n; p=p+1
|
|
|
|
decimalBuf[0] = p - @decimalBuf - 1 // record final length of string
|
|
|
|
return @decimalBuf
|
2015-03-25 14:40:46 +00:00
|
|
|
end
|
|
|
|
|
2017-03-25 14:23:10 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Convert byte to 3-char string in decimalBuf, suitable for font engine, e.g. ^T065
|
2017-04-02 16:25:11 +00:00
|
|
|
// (@fontPosBuf returned so as to not disturb decimalBuf)
|
2017-06-10 15:56:23 +00:00
|
|
|
def convert3Dec(n)#1
|
2017-04-02 16:25:11 +00:00
|
|
|
fontPosBuf[0] = 3
|
|
|
|
fontPosBuf[1] = '0' + (n / 100); n = n%100
|
|
|
|
fontPosBuf[2] = '0' + (n / 10); n = n%10
|
|
|
|
fontPosBuf[3] = '0' + n
|
|
|
|
return @fontPosBuf
|
2017-03-25 14:23:10 +00:00
|
|
|
end
|
|
|
|
|
2015-03-05 17:34:42 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-12-29 16:59:13 +00:00
|
|
|
// Print a formatted string a'la C printf, with up to three parameters.
|
2017-06-09 14:14:53 +00:00
|
|
|
export def printf3(str, arg1, arg2, arg3)#0
|
2015-03-05 17:34:42 +00:00
|
|
|
word pos
|
|
|
|
word curArg
|
|
|
|
word p
|
2017-06-02 15:25:29 +00:00
|
|
|
if !str
|
|
|
|
printChar('!') // Safety valve for NULL string pointer
|
|
|
|
return
|
|
|
|
fin
|
2015-03-05 17:34:42 +00:00
|
|
|
pos = 0
|
|
|
|
curArg = @arg1
|
|
|
|
while TRUE
|
|
|
|
pos = partialPrintf(str, pos)
|
|
|
|
if pos < 0
|
|
|
|
break
|
|
|
|
fin
|
|
|
|
p = str + pos + 2
|
|
|
|
when ^p
|
2017-03-25 14:23:10 +00:00
|
|
|
is 'd' // %d = decimal
|
2015-11-05 17:09:45 +00:00
|
|
|
puts(convertDec(*curArg)); break
|
2017-03-25 14:23:10 +00:00
|
|
|
is 's' // %s = string
|
2015-03-25 14:40:46 +00:00
|
|
|
puts(*curArg); break
|
2017-03-25 14:23:10 +00:00
|
|
|
is 'D' // %D = 3-char decimal suitable for font engine ctrl codes
|
|
|
|
puts(convert3Dec(*curArg)); break
|
|
|
|
is 'c' // %c = character
|
|
|
|
printChar(*curArg); break
|
|
|
|
is 'x' // %x = hex with '$'
|
2015-09-02 16:55:21 +00:00
|
|
|
printHex(*curArg); break
|
2017-03-25 14:23:10 +00:00
|
|
|
is '%' // %% = perfect
|
2015-03-25 14:40:46 +00:00
|
|
|
printChar('%'); break
|
2015-03-05 17:34:42 +00:00
|
|
|
otherwise
|
2015-03-25 14:40:46 +00:00
|
|
|
printHex(^p); fatal("Unknown % code")
|
2015-03-05 17:34:42 +00:00
|
|
|
wend
|
|
|
|
curArg = curArg + 2
|
|
|
|
pos = pos + 2
|
|
|
|
loop
|
|
|
|
end
|
|
|
|
|
2017-06-09 14:14:53 +00:00
|
|
|
export def printf1(str, arg1)#0; printf3(str, arg1, 0, 0); end
|
|
|
|
export def printf2(str, arg1, arg2)#0; printf3(str, arg1, arg2, 0); end
|
2015-03-25 14:40:46 +00:00
|
|
|
|
2015-11-11 16:55:16 +00:00
|
|
|
// Like printf, but displays text using font engine
|
2017-06-09 14:14:53 +00:00
|
|
|
export def displayf3(str, arg1, arg2, arg3)#0
|
2015-11-11 16:55:16 +00:00
|
|
|
buildString(@addToString)
|
2015-12-29 16:59:13 +00:00
|
|
|
printf3(str, arg1, arg2, arg3)
|
2015-11-19 16:27:04 +00:00
|
|
|
displayStr(finishString(isPlural))
|
2015-11-11 16:55:16 +00:00
|
|
|
end
|
|
|
|
|
2017-06-09 14:14:53 +00:00
|
|
|
export def displayf1(str, arg1)#0; displayf3(str, arg1, 0, 0); end
|
|
|
|
export def displayf2(str, arg1, arg2)#0; displayf3(str, arg1, arg2, 0); end
|
2015-11-11 16:55:16 +00:00
|
|
|
|
2017-05-24 14:47:47 +00:00
|
|
|
// Like printf, but buffers string in $200
|
2017-06-10 15:56:23 +00:00
|
|
|
export def sprintf3(str, arg1, arg2, arg3)#1
|
2017-03-23 14:07:36 +00:00
|
|
|
buildString(@addToString)
|
|
|
|
printf3(str, arg1, arg2, arg3)
|
2017-05-24 14:47:47 +00:00
|
|
|
return finishString(isPlural)
|
2017-03-23 14:07:36 +00:00
|
|
|
end
|
|
|
|
|
2017-05-24 14:47:47 +00:00
|
|
|
export def sprintf1(str, arg1); return sprintf3(str, arg1, 0, 0); end
|
|
|
|
export def sprintf2(str, arg1, arg2); return sprintf3(str, arg1, arg2, 0); end
|
|
|
|
|
|
|
|
// Like printf, but displays text using font engine
|
2017-06-09 14:14:53 +00:00
|
|
|
export def rawDisplayf1(str, arg1)#0; rawDisplayStr(sprintf3(str, arg1, 0, 0)); end
|
|
|
|
export def rawDisplayf2(str, arg1, arg2)#0; rawDisplayStr(sprintf3(str, arg1, arg2, 0)); end
|
|
|
|
export def rawDisplayf3(str, arg1, arg2, arg3)#0; rawDisplayStr(sprintf3(str, arg1, arg2, arg3)); end
|
2017-03-23 14:07:36 +00:00
|
|
|
|
2017-07-08 23:36:08 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Set the cursor position in the font engine
|
|
|
|
export def setCursor(x, y)#0
|
|
|
|
rawDisplayf2("^V%D^T%D", y, x)
|
|
|
|
end
|
|
|
|
|
2015-05-03 16:25:57 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def parseDec(str)#1
|
2015-05-03 16:25:57 +00:00
|
|
|
word n
|
|
|
|
word pend
|
|
|
|
word p
|
|
|
|
byte neg
|
|
|
|
neg = FALSE
|
|
|
|
n = 0
|
|
|
|
p = str + 1
|
|
|
|
pend = p + ^str
|
|
|
|
while p < pend
|
|
|
|
if p == (str+1) and ^p == '-'
|
|
|
|
neg = TRUE
|
|
|
|
elsif ^p >= '0' and ^p <= '9'
|
|
|
|
n = (n*10) + (^p - '0')
|
|
|
|
else
|
|
|
|
break
|
|
|
|
fin
|
|
|
|
p = p+1
|
|
|
|
loop
|
|
|
|
|
|
|
|
if neg; return -n; fin
|
|
|
|
return n
|
|
|
|
end
|
|
|
|
|
2015-07-04 17:02:49 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def parseDecWithDefault(str, default)#1
|
2015-07-04 17:02:49 +00:00
|
|
|
if ^str == 0
|
|
|
|
return default
|
|
|
|
fin
|
|
|
|
return parseDec(str)
|
|
|
|
end
|
|
|
|
|
2015-01-10 21:17:56 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Get a keystroke and convert it to upper case
|
2017-06-10 15:56:23 +00:00
|
|
|
export def getUpperKey()#1
|
2014-07-22 01:28:39 +00:00
|
|
|
byte key
|
2015-12-17 17:19:49 +00:00
|
|
|
while ^kbd < 128
|
|
|
|
*seed = *seed + 1
|
|
|
|
animPauseCt = animPauseCt - 1
|
|
|
|
if animPauseCt < 0
|
2016-10-23 17:42:11 +00:00
|
|
|
if anyAnims
|
2015-12-17 17:19:49 +00:00
|
|
|
nextAnimFrame()
|
|
|
|
fin
|
|
|
|
animPauseCt = ANIM_PAUSE_MAX
|
|
|
|
fin
|
|
|
|
loop
|
|
|
|
key = ^kbd
|
|
|
|
^kbdStrobe
|
2016-03-22 15:22:26 +00:00
|
|
|
return charToUpper(key & $7F)
|
2014-07-22 01:28:39 +00:00
|
|
|
end
|
|
|
|
|
2016-12-13 17:07:36 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Read a single char from the keyboard, and intern it (as a string) to the heap.
|
2017-06-10 15:56:23 +00:00
|
|
|
export def getCharResponse()#1
|
2017-02-24 16:49:12 +00:00
|
|
|
if needShowParty; showParty(); fin
|
2016-12-13 17:07:36 +00:00
|
|
|
^$200 = 1
|
|
|
|
^$201 = getUpperKey()
|
|
|
|
return mmgr(HEAP_INTERN, $200)
|
|
|
|
end
|
|
|
|
|
2016-04-28 15:20:28 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Pause for a specified count period, advancing the animation periodically.
|
2017-06-10 15:56:23 +00:00
|
|
|
export def pause(count)#0
|
2016-04-28 15:20:28 +00:00
|
|
|
while count >= 0
|
|
|
|
animPauseCt = animPauseCt - 1
|
|
|
|
if animPauseCt < 0
|
2016-10-23 17:42:11 +00:00
|
|
|
if anyAnims
|
2016-04-28 15:20:28 +00:00
|
|
|
nextAnimFrame()
|
|
|
|
fin
|
|
|
|
animPauseCt = ANIM_PAUSE_MAX
|
|
|
|
fin
|
|
|
|
count--
|
|
|
|
loop
|
|
|
|
end
|
|
|
|
|
2017-06-30 15:11:34 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Calculate markup on a price, where ratio is an 8.8 fixed-point number. Some approx ratios:
|
|
|
|
// $0000 = 0%
|
|
|
|
// $0026 = 15%
|
|
|
|
// $0080 = 50%
|
|
|
|
// $0100 = 100%
|
|
|
|
// $0180 = 150%
|
|
|
|
export def addRatio(start, ratio)#1
|
|
|
|
word markup
|
|
|
|
markup = 0
|
|
|
|
while ratio > 255
|
|
|
|
markup = markup + start
|
|
|
|
ratio = ratio - 256
|
|
|
|
loop
|
|
|
|
return markup + mulRatio(start, ratio)
|
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
export def percentToRatio(pct)#1
|
|
|
|
return addRatio(pct, 656) // Scale 0..100 to 0..255
|
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
export def addPercent(start, pct)#1
|
|
|
|
return addRatio(start, percentToRatio(pct))
|
|
|
|
end
|
|
|
|
|
2015-12-09 18:16:05 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def encodeDice(nDice, dieSize, add)#1 // ndice=0..15, dieSize=0..15, add=0..255
|
2015-12-09 18:16:05 +00:00
|
|
|
return (nDice << 12) | (dieSize << 8) | add
|
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-07-15 18:41:29 +00:00
|
|
|
export def rollDiceWithLuck(encoded, luck)#1
|
|
|
|
byte i, nDice, dieSize, add, droll, result
|
2015-12-09 18:16:05 +00:00
|
|
|
nDice = encoded >> 12
|
|
|
|
dieSize = (encoded >> 8) & $F
|
|
|
|
add = encoded & $F
|
|
|
|
result = add
|
|
|
|
for i = 1 to nDice
|
2017-07-15 18:41:29 +00:00
|
|
|
droll = (rand16() % dieSize) + 1
|
|
|
|
if luck > 0
|
|
|
|
if (rand16() % 100) < (luck * 2)
|
|
|
|
droll = max(droll, (rand16() % dieSize) + 1)
|
|
|
|
fin
|
|
|
|
elsif luck < 0
|
|
|
|
if (rand16() % 100) < (luck * -2)
|
|
|
|
droll = min(droll, (rand16() % dieSize) + 1)
|
|
|
|
fin
|
|
|
|
fin
|
2015-12-09 18:16:05 +00:00
|
|
|
add = (rand16() % dieSize) + 1
|
|
|
|
result = result + add
|
|
|
|
next
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
2017-07-15 18:41:29 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
export def rollDice(encoded)#1
|
|
|
|
return rollDiceWithLuck(encoded, 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
export def rollPercentileWithLuck(luck)#1
|
|
|
|
byte result
|
|
|
|
result = rand16() % 100
|
|
|
|
if luck > 0
|
|
|
|
if (rand16() % 100) < (luck * 2)
|
|
|
|
result = max(result, rand16() % 100)
|
|
|
|
fin
|
|
|
|
elsif luck < 0
|
|
|
|
if (rand16() % 100) < (luck * -2)
|
|
|
|
result = min(result, rand16() % 100)
|
|
|
|
fin
|
|
|
|
fin
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
2017-02-06 18:01:00 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Look up the partition for a resource.
|
|
|
|
// sectioNum: 1=map2d, 2=map3d, 3=portrait
|
2017-06-10 15:56:23 +00:00
|
|
|
def lookupResourcePart(sectionNum, resourceNum)#1
|
2017-02-06 18:01:00 +00:00
|
|
|
word ptr
|
|
|
|
byte n
|
|
|
|
|
|
|
|
// Skip to the requested section
|
|
|
|
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)
|
2017-04-10 15:35:27 +00:00
|
|
|
// 255 is special code for map that is replicated on every data disk
|
|
|
|
if n == 255
|
|
|
|
if curMapPartition > 0; return curMapPartition; fin
|
|
|
|
return 2
|
|
|
|
fin
|
2017-02-17 17:26:57 +00:00
|
|
|
if n < 1 or n > 20; fatal("lkupFail2"); fin
|
2017-02-06 18:01:00 +00:00
|
|
|
return n
|
|
|
|
end
|
|
|
|
|
2015-01-10 21:17:56 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Set the sky color (relevant to 3D display only)
|
2017-06-10 14:21:58 +00:00
|
|
|
export def setSky(num)#0
|
2016-07-19 13:21:34 +00:00
|
|
|
// hack for end-game screen
|
|
|
|
if num == 99
|
2016-10-23 17:42:11 +00:00
|
|
|
finalWin()
|
2016-07-19 13:21:34 +00:00
|
|
|
fin
|
2014-07-23 19:50:16 +00:00
|
|
|
skyNum = num
|
2015-03-31 19:02:48 +00:00
|
|
|
setColor(0, skyNum)
|
2015-05-27 15:13:09 +00:00
|
|
|
needRender = TRUE
|
2014-07-23 19:50:16 +00:00
|
|
|
end
|
|
|
|
|
2015-01-10 21:17:56 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Set the ground color (relevant to 3D display only)
|
2017-06-10 14:21:58 +00:00
|
|
|
export def setGround(num)#0
|
2014-07-23 19:50:16 +00:00
|
|
|
groundNum = num
|
2015-03-31 19:02:48 +00:00
|
|
|
setColor(1, groundNum)
|
2015-05-27 15:13:09 +00:00
|
|
|
needRender = TRUE
|
2014-07-23 19:50:16 +00:00
|
|
|
end
|
|
|
|
|
2015-01-10 21:17:56 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Load the Frame Image, and lock it.
|
2017-06-10 15:56:23 +00:00
|
|
|
export def loadFrameImg(img)#0
|
2016-10-11 16:03:57 +00:00
|
|
|
// Skip redundant reload
|
|
|
|
if frameLoaded == img; return; fin
|
|
|
|
|
2016-10-23 17:42:11 +00:00
|
|
|
// Free prev img and/or portrait (if any)
|
|
|
|
clearPortrait()
|
|
|
|
|
2016-10-24 14:08:37 +00:00
|
|
|
// Make room in aux mem by throwing out textures
|
|
|
|
if renderLoaded
|
|
|
|
flipToPage1()
|
|
|
|
texControl(0)
|
|
|
|
fin
|
|
|
|
|
2016-10-23 17:42:11 +00:00
|
|
|
// Load the image data into aux mem
|
2016-11-07 15:58:46 +00:00
|
|
|
if img
|
|
|
|
auxMmgr(START_LOAD, 1) // partition 1 is where full screen images live
|
2017-01-12 17:08:05 +00:00
|
|
|
if img == 1
|
|
|
|
auxMmgr(SET_MEM_TARGET, $4000) // well above where expander loads at startup
|
|
|
|
fin
|
2016-11-07 15:58:46 +00:00
|
|
|
curFullscreenImg = auxMmgr(QUEUE_LOAD, img<<8 | RES_TYPE_SCREEN)
|
|
|
|
auxMmgr(FINISH_LOAD, 0)
|
2016-10-23 17:42:11 +00:00
|
|
|
|
2016-11-07 15:58:46 +00:00
|
|
|
anyAnims = TRUE // for now; might get cleared if we discover otherwise on advance
|
|
|
|
animDirCt = 1
|
|
|
|
animPauseCt = ANIM_PAUSE_MAX
|
2016-10-11 16:03:57 +00:00
|
|
|
|
2016-11-07 15:58:46 +00:00
|
|
|
// And show the first frame of the screen image
|
|
|
|
showAnimFrame()
|
|
|
|
else
|
|
|
|
curFullscreenImg = NULL
|
|
|
|
anyAnims = FALSE
|
|
|
|
fin
|
|
|
|
|
|
|
|
frameLoaded = img
|
2016-10-11 16:03:57 +00:00
|
|
|
|
2016-10-23 17:42:11 +00:00
|
|
|
// Do not render over the image
|
|
|
|
needRender = FALSE
|
2015-01-10 21:17:56 +00:00
|
|
|
end
|
|
|
|
|
2015-06-01 17:38:22 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Window for the map name bar
|
2017-06-10 14:32:31 +00:00
|
|
|
export def setWindow1()#0
|
2017-04-10 17:01:36 +00:00
|
|
|
setWindow(8, 17, 35, 119) // Top, Bottom, Left, Right
|
2016-06-09 14:39:09 +00:00
|
|
|
mapNameHash = 0 // on the assumption that it's being set because somebody's going to print there
|
2015-06-01 17:38:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Window for the large upper right bar
|
2017-06-10 14:32:31 +00:00
|
|
|
export def setWindow2()#0
|
2016-07-11 00:33:48 +00:00
|
|
|
setWindow(24, 132, 154, 267) // Top, Bottom, Left, Right
|
2017-07-08 23:36:08 +00:00
|
|
|
displayChar('N'-$40) // Set normal mode - clear all special modes (like underline, etc.)
|
2015-06-01 17:38:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Window for the mid-size lower right bar
|
2017-06-10 14:32:31 +00:00
|
|
|
export def setWindow3()#0
|
2016-07-11 00:33:48 +00:00
|
|
|
setWindow(144, 180, 154, 267) // Top, Bottom, Left, Right
|
2015-06-01 17:38:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Window for the map area (used for clearing it)
|
2017-06-10 15:56:23 +00:00
|
|
|
export def setMapWindow()#0
|
2016-06-29 14:42:58 +00:00
|
|
|
if frameLoaded == 3 // don't check mapIs3D, since we might be in an engine
|
2015-11-30 16:02:32 +00:00
|
|
|
setWindow(24, 153, 14, 140) // Top, Bottom, Left, Right
|
2015-06-01 17:38:22 +00:00
|
|
|
else
|
2015-11-30 16:02:32 +00:00
|
|
|
setWindow(24, 169, 14, 140) // Top, Bottom, Left, Right
|
2015-06-01 17:38:22 +00:00
|
|
|
fin
|
|
|
|
end
|
2016-11-07 15:58:46 +00:00
|
|
|
|
2017-08-02 17:20:22 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
def clearTextWindow()#0
|
|
|
|
setWindow2(); clearWindow()
|
|
|
|
if mapIs3D and texturesLoaded; copyWindow(); fin
|
|
|
|
textDrawn = FALSE
|
|
|
|
textClearCountdown = 0
|
|
|
|
end
|
|
|
|
|
2017-03-22 16:46:17 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
def hline(addr, startByte, midByte, midSize, endByte)#0
|
2017-03-22 16:46:17 +00:00
|
|
|
^addr = startByte
|
|
|
|
memset(addr+1, midByte, midSize)
|
|
|
|
^(addr+midSize+1) = endByte
|
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Window that covers the entire inner area (destroys frame image, so be sure to loadMainFrame
|
|
|
|
// afterwards)
|
2017-06-10 15:56:23 +00:00
|
|
|
export def setBigWindow()#0
|
2017-05-24 14:47:47 +00:00
|
|
|
// Draw border (if not already drawn)
|
|
|
|
if frameLoaded
|
2017-05-25 14:50:51 +00:00
|
|
|
hline(getScreenLine(BIGWIN_TOP-4)+1, 0, 0, 36, 0)
|
|
|
|
hline(getScreenLine(BIGWIN_TOP-3)+1, $F8, $FF, 36, $8F)
|
|
|
|
hline(getScreenLine(BIGWIN_TOP-2)+1, $FC, $FF, 36, $9F)
|
|
|
|
hline(getScreenLine(BIGWIN_TOP-1)+1, $8C, 0, 36, $98)
|
|
|
|
vline(getScreenLine(BIGWIN_TOP)+1, $8C, 174)
|
|
|
|
vline(getScreenLine(BIGWIN_TOP)+38, $98, 174)
|
|
|
|
hline(getScreenLine(BIGWIN_BOTTOM-1)+1, $8C, 0, 36, $98)
|
|
|
|
hline(getScreenLine(BIGWIN_BOTTOM)+1, $FC, $FF, 36, $9F)
|
|
|
|
hline(getScreenLine(BIGWIN_BOTTOM+1)+1, $F8, $FF, 36, $8F)
|
|
|
|
hline(getScreenLine(BIGWIN_BOTTOM+2)+1, 0, 0, 36, 0)
|
2017-05-24 14:47:47 +00:00
|
|
|
frameLoaded = 0 // since we just destroyed it
|
|
|
|
fin
|
2017-05-25 14:50:51 +00:00
|
|
|
setWindow(BIGWIN_TOP, BIGWIN_BOTTOM, BIGWIN_LEFT, BIGWIN_RIGHT)
|
2017-03-22 16:46:17 +00:00
|
|
|
end
|
|
|
|
|
2016-11-07 15:58:46 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def rightJustifyStr(str, rightX)#0
|
2017-05-24 14:47:47 +00:00
|
|
|
word space
|
|
|
|
space = rightX - calcWidth(str)
|
|
|
|
if (space > 0)
|
|
|
|
rawDisplayStr("^T") // do not use printf variants, since it might overwrite str
|
|
|
|
rawDisplayStr(convert3Dec(space))
|
|
|
|
fin
|
|
|
|
rawDisplayStr(str)
|
2015-11-05 17:09:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def rightJustifyNum(num, rightX)#0
|
2015-11-05 17:09:45 +00:00
|
|
|
rightJustifyStr(convertDec(num), rightX)
|
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Display the party data on the screen
|
2017-06-10 14:32:31 +00:00
|
|
|
export def showParty()#0
|
2017-07-08 23:36:08 +00:00
|
|
|
word p, cursX, cursY
|
2015-12-05 23:01:44 +00:00
|
|
|
|
2017-07-08 23:36:08 +00:00
|
|
|
cursX, cursY = getCursor()
|
2015-06-01 17:38:22 +00:00
|
|
|
setWindow3()
|
2015-12-05 23:01:44 +00:00
|
|
|
clearWindow()
|
2015-11-05 17:09:45 +00:00
|
|
|
|
2017-06-14 16:22:05 +00:00
|
|
|
// Display header (or LEVEL UP message)
|
|
|
|
p = global=>p_players
|
2017-06-30 16:30:29 +00:00
|
|
|
while p
|
|
|
|
if p->b_skillPoints; break; fin
|
2017-06-14 16:22:05 +00:00
|
|
|
p = p=>p_nextObj
|
|
|
|
loop
|
|
|
|
if p
|
2017-07-08 23:36:08 +00:00
|
|
|
rawDisplayStr("^Y^I LEVEL U)P ^N\n")
|
2017-06-14 16:22:05 +00:00
|
|
|
else
|
2017-06-30 15:11:34 +00:00
|
|
|
rawDisplayStr("^LName")
|
|
|
|
rightJustifyStr(@S_HEALTH, CHAR_WND_HEALTH_X) // begin underline mode
|
|
|
|
rawDisplayStr("^N\n")
|
2017-06-14 16:22:05 +00:00
|
|
|
fin
|
2015-11-05 17:09:45 +00:00
|
|
|
|
2017-03-25 14:23:10 +00:00
|
|
|
// Display each character's name and health
|
2015-11-05 17:09:45 +00:00
|
|
|
p = global=>p_players
|
|
|
|
while p
|
2017-03-25 14:23:10 +00:00
|
|
|
if p <> global=>p_players; displayChar('\n'); fin
|
2017-06-24 20:28:28 +00:00
|
|
|
if p->b_skillPoints; rawDisplayStr("^I"); fin // inverse for chars needing lvl-up
|
2017-06-30 15:11:34 +00:00
|
|
|
rawDisplayf1("%s^N", p=>s_name)
|
|
|
|
rightJustifyStr(sprintf2("%d/%d", p=>w_health, p=>w_maxHealth), CHAR_WND_HEALTH_X)
|
2015-11-05 17:09:45 +00:00
|
|
|
p = p=>p_nextObj
|
|
|
|
loop
|
|
|
|
|
|
|
|
// Finish up
|
2017-08-02 17:20:22 +00:00
|
|
|
if mapIs3D and texturesLoaded; copyWindow(); fin
|
2015-06-03 16:12:15 +00:00
|
|
|
setWindow2()
|
2017-07-08 23:36:08 +00:00
|
|
|
setCursor(cursX, cursY)
|
2016-07-16 12:39:22 +00:00
|
|
|
needShowParty = FALSE
|
2015-06-01 17:38:22 +00:00
|
|
|
end
|
|
|
|
|
2016-09-15 18:08:43 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
def getArgCount(pFunc)#1
|
2016-09-15 18:08:43 +00:00
|
|
|
word pBytecode
|
|
|
|
|
|
|
|
// skip over JMP to plasma interp, get addr in aux mem
|
2016-09-20 13:15:49 +00:00
|
|
|
pBytecode = pFunc=>3
|
|
|
|
|
2016-09-15 18:08:43 +00:00
|
|
|
// Check if the function starts with ENTER op
|
|
|
|
if readAuxByte(pBytecode) == $58
|
|
|
|
return readAuxByte(pBytecode+2)
|
|
|
|
fin
|
|
|
|
|
|
|
|
// Zero-arg functions sometimes omit ENTER altogether.
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Send an event to the scripts on the current map square
|
2017-06-10 15:56:23 +00:00
|
|
|
export def scriptEvent(event, param)#0
|
2016-09-20 13:15:49 +00:00
|
|
|
byte i, argCount
|
2016-09-15 18:08:43 +00:00
|
|
|
word script
|
|
|
|
if !nMapScripts; return; fin
|
|
|
|
|
2017-08-10 17:51:20 +00:00
|
|
|
if inScript; return; fin // avoid doing scripted events inside other scripts
|
|
|
|
inScript = TRUE
|
|
|
|
|
2016-09-15 18:08:43 +00:00
|
|
|
setWindow2()
|
|
|
|
|
2017-08-02 17:20:22 +00:00
|
|
|
textDrawn = FALSE
|
2016-09-15 18:08:43 +00:00
|
|
|
for i = 0 to nMapScripts-1
|
|
|
|
script = mapScripts[i]
|
2016-09-20 13:15:49 +00:00
|
|
|
argCount = getArgCount(script)
|
|
|
|
if argCount == 0 and event == @S_ENTER // zero-param scripts are assumed to be strictly 'enter' handlers
|
2016-09-15 18:08:43 +00:00
|
|
|
script()
|
2016-09-20 13:15:49 +00:00
|
|
|
elsif argCount == 1
|
|
|
|
script(event)
|
|
|
|
elsif argCount == 2
|
|
|
|
script(event, param)
|
2016-09-15 18:08:43 +00:00
|
|
|
fin
|
|
|
|
next
|
2017-08-10 17:51:20 +00:00
|
|
|
|
|
|
|
inScript = FALSE
|
2016-09-15 18:08:43 +00:00
|
|
|
|
2017-08-02 17:20:22 +00:00
|
|
|
if textDrawn
|
|
|
|
textClearCountdown = 3
|
|
|
|
if mapIs3D and texturesLoaded; copyWindow(); fin
|
|
|
|
fin
|
2016-09-15 18:08:43 +00:00
|
|
|
clearPortrait()
|
|
|
|
if needShowParty; showParty(); fin
|
|
|
|
if global=>p_players=>w_health == 0; playerDeath(); fin
|
2017-08-02 17:20:22 +00:00
|
|
|
|
2016-09-15 18:08:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Check for script(s) attached to the given location, and establish the array of map scripts.
|
|
|
|
// Does not call any of them -- that's the job of scriptEvent().
|
2017-06-10 15:56:23 +00:00
|
|
|
def scanScripts(x, y)#0
|
2016-09-15 18:08:43 +00:00
|
|
|
word p
|
|
|
|
word script
|
|
|
|
word pNext
|
|
|
|
|
|
|
|
nMapScripts = 0
|
|
|
|
x = x - triggerOriginX
|
|
|
|
y = y - triggerOriginY
|
|
|
|
p = triggerTbl
|
|
|
|
while p
|
|
|
|
if ^p == $FF
|
|
|
|
break
|
|
|
|
fin
|
|
|
|
pNext = p + p->1
|
|
|
|
if ^p == y
|
|
|
|
p = p + 2
|
|
|
|
while p < pNext
|
|
|
|
if x == ^p
|
|
|
|
if nMapScripts == MAX_MAP_SCRIPTS; fatal("maxScpts"); fin
|
|
|
|
mapScripts[nMapScripts] = p=>1
|
|
|
|
nMapScripts++
|
|
|
|
fin
|
|
|
|
p = p + 3
|
|
|
|
loop
|
|
|
|
fin
|
|
|
|
p = pNext
|
|
|
|
loop
|
|
|
|
end
|
|
|
|
|
2016-10-24 14:08:37 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def loadMainFrameImg()#0
|
2016-10-24 14:08:37 +00:00
|
|
|
loadFrameImg(mapIs3D+2)
|
2016-10-24 15:20:52 +00:00
|
|
|
if curFullscreenImg
|
|
|
|
auxMmgr(FREE_MEMORY, curFullscreenImg)
|
|
|
|
curFullscreenImg = NULL
|
|
|
|
fin
|
2016-10-24 14:08:37 +00:00
|
|
|
end
|
|
|
|
|
2017-08-04 15:15:40 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
def showCompassDir(dir)#0
|
|
|
|
word tile
|
|
|
|
word screenAdr
|
2017-08-04 15:30:08 +00:00
|
|
|
if dir < 2; tile = COMPASS_EAST
|
|
|
|
elsif dir < 6; tile = COMPASS_SOUTH
|
|
|
|
elsif dir < 10; tile = COMPASS_WEST
|
|
|
|
elsif dir < 14; tile = COMPASS_NORTH
|
|
|
|
else tile = COMPASS_EAST; fin
|
2017-08-04 15:15:40 +00:00
|
|
|
tile = pGlobalTileset + (tile<<5)
|
|
|
|
screenAdr = getScreenLine(168)+4
|
|
|
|
blit(0, tile, screenAdr, 16, 2)
|
|
|
|
blit(0, tile, screenAdr+$2000, 16, 2)
|
|
|
|
end
|
|
|
|
|
2015-01-10 21:17:56 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-12-28 17:13:18 +00:00
|
|
|
// Load code and data, set up everything to display a 2D or 3D map
|
2017-06-10 15:56:23 +00:00
|
|
|
def initMap(x, y, dir)#0
|
2015-08-21 14:59:03 +00:00
|
|
|
word pMap
|
|
|
|
|
2014-08-21 15:17:50 +00:00
|
|
|
// Reset memory (our module will stay since memory manager locked it upon load)
|
2015-08-19 14:22:20 +00:00
|
|
|
mmgr(RESET_MEMORY, 0)
|
2014-07-06 23:45:27 +00:00
|
|
|
|
2016-10-13 16:26:51 +00:00
|
|
|
// Load the frame image, then raycaster or tile engine
|
2016-10-24 14:08:37 +00:00
|
|
|
loadMainFrameImg()
|
2017-03-29 16:36:14 +00:00
|
|
|
mmgr(START_LOAD, 1)
|
2015-08-19 14:22:20 +00:00
|
|
|
mmgr(SET_MEM_TARGET, displayEngine)
|
2015-04-05 16:52:38 +00:00
|
|
|
if mapIs3D
|
2015-12-10 17:43:21 +00:00
|
|
|
mmgr(QUEUE_LOAD, CODE_RENDER<<8 | RES_TYPE_CODE)
|
2015-04-05 16:52:38 +00:00
|
|
|
else
|
2015-12-10 17:43:21 +00:00
|
|
|
mmgr(QUEUE_LOAD, CODE_TILE_ENGINE<<8 | RES_TYPE_CODE)
|
2015-04-05 16:52:38 +00:00
|
|
|
fin
|
2017-02-19 18:08:03 +00:00
|
|
|
if global->b_godmode
|
|
|
|
pGodModule = mmgr(QUEUE_LOAD, MOD_GODMODE<<8 | RES_TYPE_MODULE)
|
|
|
|
fin
|
2016-09-08 15:39:41 +00:00
|
|
|
mmgr(FINISH_LOAD, 0)
|
2015-12-29 16:59:13 +00:00
|
|
|
renderLoaded = TRUE
|
2016-06-18 23:31:21 +00:00
|
|
|
|
2017-02-19 18:08:03 +00:00
|
|
|
// Grab the function table for the godMode module (if enabled)
|
|
|
|
if global->b_godmode; pGodModule = pGodModule(); fin
|
|
|
|
|
|
|
|
// Set up the command table
|
|
|
|
initCmds()
|
|
|
|
|
2016-06-18 23:31:21 +00:00
|
|
|
// Load the map
|
2017-02-06 18:01:00 +00:00
|
|
|
curMapPartition = lookupResourcePart(mapIs3D+1, mapNum)
|
|
|
|
mmgr(START_LOAD, curMapPartition)
|
|
|
|
pMap = mmgr(QUEUE_LOAD, mapNum<<8 | (RES_TYPE_2D_MAP+mapIs3D))
|
2017-08-04 15:15:40 +00:00
|
|
|
pGlobalTileset = mmgr(QUEUE_LOAD, 1<<8 | RES_TYPE_TILESET) // even in 3d, need tiles for compass/clock/etc.
|
2016-09-08 15:39:41 +00:00
|
|
|
mmgr(FINISH_LOAD, 0)
|
2014-07-22 01:28:39 +00:00
|
|
|
|
2016-05-19 07:31:28 +00:00
|
|
|
// Clear all the windows to the background color (hi-bit set)
|
2017-08-02 17:20:22 +00:00
|
|
|
// except window3 because showParty does it for us
|
|
|
|
setWindow1(); clearWindow()
|
|
|
|
setWindow2(); clearWindow()
|
2016-05-19 07:31:28 +00:00
|
|
|
|
2016-03-31 17:01:04 +00:00
|
|
|
// Clear the list of encounter zones from any previous maps
|
2016-07-14 20:52:23 +00:00
|
|
|
if allowZoneInit
|
|
|
|
global=>p_encounterZones = NULL
|
|
|
|
fin
|
2016-03-29 22:17:42 +00:00
|
|
|
|
2015-04-09 17:31:36 +00:00
|
|
|
// Start up the display engine with map data and starting position. This will also load and
|
2015-04-20 15:32:02 +00:00
|
|
|
// init the script module, if any, which will end up calling us back at the setScriptInfo
|
2015-02-27 13:33:11 +00:00
|
|
|
triggerTbl = NULL
|
2015-05-07 16:12:52 +00:00
|
|
|
setWindow2()
|
2017-02-06 18:01:00 +00:00
|
|
|
initDisplay(curMapPartition, mapNum, pMap, x, y, dir)
|
2016-09-08 15:30:08 +00:00
|
|
|
texturesLoaded = TRUE
|
2015-05-15 15:19:18 +00:00
|
|
|
needRender = FALSE
|
2016-06-19 14:42:11 +00:00
|
|
|
textDrawn = FALSE
|
2017-08-02 17:20:22 +00:00
|
|
|
textClearCountdown = 0
|
2016-09-22 15:04:24 +00:00
|
|
|
curEngine = NULL
|
2017-04-03 15:22:32 +00:00
|
|
|
curPortrait = NULL
|
|
|
|
curPortraitNum = 0
|
2016-10-23 17:42:11 +00:00
|
|
|
curFullscreenImg = NULL
|
2016-07-14 21:01:54 +00:00
|
|
|
if global->b_curAvatar <> 0 and !mapIs3D
|
|
|
|
setAvatar(global->b_curAvatar)
|
|
|
|
doRender()
|
2016-07-15 05:24:09 +00:00
|
|
|
fin
|
2017-08-04 15:15:40 +00:00
|
|
|
if mapIs3D; showCompassDir(dir); fin
|
2015-01-10 21:17:56 +00:00
|
|
|
|
2016-10-24 15:20:52 +00:00
|
|
|
// Assume there might be animations until we learn otherwise
|
|
|
|
anyAnims = TRUE // for now; might get cleared if we discover otherwise on advance
|
|
|
|
animDirCt = 1
|
|
|
|
animPauseCt = ANIM_PAUSE_MAX
|
|
|
|
|
2016-09-15 18:08:43 +00:00
|
|
|
// Populate script handlers for the current square, so that leave handlers will trigger right.
|
|
|
|
scanScripts(x, y)
|
|
|
|
|
2015-11-05 17:09:45 +00:00
|
|
|
// Display the party characters
|
|
|
|
showParty()
|
2014-07-08 16:39:31 +00:00
|
|
|
end
|
|
|
|
|
2016-07-14 20:52:23 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def scriptSetAvatar(avatarTileNum)#0
|
2016-07-14 21:01:54 +00:00
|
|
|
global->b_curAvatar = avatarTileNum
|
2016-07-28 16:46:38 +00:00
|
|
|
if renderLoaded; setAvatar(avatarTileNum); fin
|
2016-07-14 20:52:23 +00:00
|
|
|
end
|
|
|
|
|
2016-09-08 15:30:08 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def unloadTextures()#0
|
2016-09-08 15:30:08 +00:00
|
|
|
if renderLoaded and texturesLoaded
|
2016-09-15 18:08:43 +00:00
|
|
|
flipToPage1()
|
2016-09-08 15:30:08 +00:00
|
|
|
texControl(0)
|
|
|
|
texturesLoaded = FALSE
|
|
|
|
fin
|
|
|
|
end
|
|
|
|
|
2015-12-17 17:19:49 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-12-28 17:13:18 +00:00
|
|
|
// Display a portrait drawing (typically called from scripts)
|
2017-06-10 14:32:31 +00:00
|
|
|
export def clearPortrait()#0
|
2015-12-17 17:19:49 +00:00
|
|
|
if curPortrait
|
|
|
|
auxMmgr(FREE_MEMORY, curPortrait)
|
2016-10-23 17:42:11 +00:00
|
|
|
curPortrait = NULL
|
2017-04-03 15:22:32 +00:00
|
|
|
curPortraitNum = 0
|
2016-10-23 17:42:11 +00:00
|
|
|
fin
|
|
|
|
if curFullscreenImg
|
|
|
|
auxMmgr(FREE_MEMORY, curFullscreenImg)
|
|
|
|
curFullscreenImg = NULL
|
2016-10-24 14:08:37 +00:00
|
|
|
loadMainFrameImg()
|
2015-12-17 17:19:49 +00:00
|
|
|
fin
|
2016-10-24 14:08:37 +00:00
|
|
|
needRender = TRUE
|
2015-12-28 17:13:18 +00:00
|
|
|
end
|
2015-12-17 17:19:49 +00:00
|
|
|
|
2015-12-28 17:13:18 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Perform rendering, copy if necessary, clear appropriate flags
|
2017-06-10 14:32:31 +00:00
|
|
|
def doRender()#0
|
2015-12-28 17:13:18 +00:00
|
|
|
if curPortrait; clearPortrait(); fin
|
2016-09-08 15:30:08 +00:00
|
|
|
if !texturesLoaded
|
|
|
|
if mapIs3D
|
|
|
|
flipToPage1()
|
|
|
|
texControl(1)
|
|
|
|
fin
|
|
|
|
texturesLoaded = TRUE
|
|
|
|
fin
|
2016-10-26 15:04:29 +00:00
|
|
|
render()
|
2015-12-17 17:19:49 +00:00
|
|
|
needRender = FALSE
|
|
|
|
end
|
|
|
|
|
2015-01-10 21:17:56 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-08-10 17:51:20 +00:00
|
|
|
def moveInternal(facingDir, moveDir, beepOK)#1
|
2015-04-09 17:31:36 +00:00
|
|
|
byte val
|
2016-03-29 22:17:42 +00:00
|
|
|
word x, y
|
2017-08-10 17:51:20 +00:00
|
|
|
|
|
|
|
setDir(moveDir)
|
2015-04-09 17:31:36 +00:00
|
|
|
val = advance()
|
2017-08-10 17:51:20 +00:00
|
|
|
setDir(facingDir)
|
2015-05-15 15:19:18 +00:00
|
|
|
|
|
|
|
// If not blocked, render at the new position.
|
2016-07-04 01:20:07 +00:00
|
|
|
if val == 0
|
2017-08-10 17:51:20 +00:00
|
|
|
if beepOK and !inScript; beep(); fin // don't beep for scripted moves
|
2016-07-04 01:20:07 +00:00
|
|
|
else
|
2015-06-01 02:03:38 +00:00
|
|
|
if !mapIs3D
|
2015-12-17 17:19:49 +00:00
|
|
|
doRender()
|
2015-06-01 02:03:38 +00:00
|
|
|
else
|
|
|
|
needRender = TRUE
|
|
|
|
fin
|
2015-05-15 15:19:18 +00:00
|
|
|
fin
|
|
|
|
|
2017-08-10 17:51:20 +00:00
|
|
|
// If we're on a new map tile, run leave handlers from old tile.
|
|
|
|
if val >= 2
|
|
|
|
scriptEvent(@S_LEAVE, NULL)
|
|
|
|
nMapScripts = 0
|
|
|
|
fin
|
2017-08-10 16:56:46 +00:00
|
|
|
|
2017-08-10 17:51:20 +00:00
|
|
|
// If there are script(s) on the new tile, run them.
|
|
|
|
if val == 3
|
|
|
|
getPos(@x, @y)
|
|
|
|
scanScripts(x, y)
|
|
|
|
if nMapScripts
|
|
|
|
scriptEvent(@S_ENTER, NULL)
|
|
|
|
elsif global=>p_encounterZones
|
2016-09-15 18:08:43 +00:00
|
|
|
checkEncounter(x, y, FALSE)
|
2016-03-29 22:17:42 +00:00
|
|
|
fin
|
2017-08-10 17:51:20 +00:00
|
|
|
elsif val >= 2 and global=>p_encounterZones
|
|
|
|
getPos(@x, @y)
|
|
|
|
checkEncounter(x, y, FALSE)
|
2014-07-06 23:09:10 +00:00
|
|
|
fin
|
2017-08-10 17:51:20 +00:00
|
|
|
return val
|
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Advance one step forward (works for either 3D or 2D maps)
|
|
|
|
def moveForward()#1
|
|
|
|
byte dir
|
|
|
|
dir = getDir()
|
|
|
|
moveInternal(dir, dir, TRUE)
|
2014-07-06 23:09:10 +00:00
|
|
|
end
|
|
|
|
|
2015-01-10 21:17:56 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-08-04 15:15:40 +00:00
|
|
|
// Adjust player's direction plus or minus n increments; returns new dir
|
2017-06-11 15:25:15 +00:00
|
|
|
def adjustDir(n)#1
|
2017-08-04 15:15:40 +00:00
|
|
|
byte dir
|
|
|
|
dir = (getDir() + n) & 15
|
|
|
|
setDir(dir)
|
|
|
|
return dir
|
2014-07-06 23:02:52 +00:00
|
|
|
end
|
|
|
|
|
2015-01-10 21:17:56 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2016-06-30 16:31:29 +00:00
|
|
|
// Move backward one step (3D mode). Also actually works in 2D mode.
|
2017-06-11 15:25:15 +00:00
|
|
|
def moveBackward()#1
|
2017-08-10 17:51:20 +00:00
|
|
|
byte facingDir, moveDir
|
|
|
|
facingDir = getDir()
|
|
|
|
moveDir = (facingDir + 8) & 15
|
|
|
|
moveInternal(facingDir, moveDir, TRUE)
|
|
|
|
return 0
|
2014-07-06 23:02:52 +00:00
|
|
|
end
|
|
|
|
|
2016-07-01 23:32:57 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2016-09-22 17:55:34 +00:00
|
|
|
// Move backward two steps (3D mode), or one step (2D mode). This is often used when exiting a
|
2016-09-22 15:13:17 +00:00
|
|
|
// building or fleeing combat, so we don't want to generate any random encounters.
|
2017-06-11 15:25:15 +00:00
|
|
|
export def moveWayBackward()#1
|
2017-08-10 17:51:20 +00:00
|
|
|
byte facingDir, moveDir
|
|
|
|
facingDir = getDir()
|
|
|
|
moveDir = (facingDir + 8) & 15
|
|
|
|
moveInternal(facingDir, moveDir, FALSE)
|
2016-07-01 23:32:57 +00:00
|
|
|
if mapIs3D
|
2017-08-10 17:51:20 +00:00
|
|
|
moveInternal(facingDir, moveDir, FALSE)
|
2016-07-01 23:32:57 +00:00
|
|
|
fin
|
2017-08-10 17:51:20 +00:00
|
|
|
return 0
|
2016-07-01 23:32:57 +00:00
|
|
|
end
|
|
|
|
|
2015-01-10 21:17:56 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Turn left (3D mode)
|
2017-06-11 15:25:15 +00:00
|
|
|
def rotateLeft()#1
|
2015-05-15 15:19:18 +00:00
|
|
|
needRender = TRUE
|
2017-08-04 15:15:40 +00:00
|
|
|
showCompassDir(adjustDir(-1))
|
|
|
|
return 0
|
2014-07-06 23:02:52 +00:00
|
|
|
end
|
|
|
|
|
2015-01-10 21:17:56 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Rotate to the right (3D mode)
|
2017-06-11 15:25:15 +00:00
|
|
|
def rotateRight()#1
|
2015-05-15 15:19:18 +00:00
|
|
|
needRender = TRUE
|
2017-08-04 15:15:40 +00:00
|
|
|
showCompassDir(adjustDir(1))
|
|
|
|
return 0
|
2014-07-06 23:09:10 +00:00
|
|
|
end
|
|
|
|
|
2015-01-10 21:17:56 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Sidestep to the right (3D mode)
|
2017-06-11 15:25:15 +00:00
|
|
|
def strafeRight()#1
|
2017-08-10 17:51:20 +00:00
|
|
|
byte facingDir, moveDir
|
|
|
|
facingDir = getDir()
|
|
|
|
moveDir = (facingDir + 4) & 15
|
|
|
|
return moveInternal(facingDir, moveDir, FALSE)
|
2014-07-06 23:09:10 +00:00
|
|
|
end
|
|
|
|
|
2015-01-10 21:17:56 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Sidestep to the left (3D mode)
|
2017-06-11 15:25:15 +00:00
|
|
|
def strafeLeft()#1
|
2017-08-10 17:51:20 +00:00
|
|
|
byte facingDir, moveDir
|
|
|
|
facingDir = getDir()
|
|
|
|
moveDir = (facingDir - 4) & 15
|
|
|
|
return moveInternal(facingDir, moveDir, FALSE)
|
2014-07-06 23:02:52 +00:00
|
|
|
end
|
|
|
|
|
2015-01-18 16:59:56 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-11 15:25:15 +00:00
|
|
|
def moveNorth()#1
|
2015-07-01 17:04:19 +00:00
|
|
|
word x, y
|
|
|
|
getPos(@x, @y)
|
|
|
|
if y > 4
|
|
|
|
setDir(0)
|
|
|
|
moveForward()
|
|
|
|
else
|
|
|
|
beep()
|
|
|
|
fin
|
2017-06-11 15:25:15 +00:00
|
|
|
return 0
|
2015-01-18 16:59:56 +00:00
|
|
|
end
|
|
|
|
|
2017-06-11 15:25:15 +00:00
|
|
|
def moveEast()#1
|
2015-07-01 17:04:19 +00:00
|
|
|
word x, y
|
|
|
|
getPos(@x, @y)
|
|
|
|
if x < totalMapWidth-5
|
|
|
|
setDir(4)
|
|
|
|
moveForward()
|
|
|
|
else
|
|
|
|
beep()
|
|
|
|
fin
|
2017-06-11 15:25:15 +00:00
|
|
|
return 0
|
2015-01-18 16:59:56 +00:00
|
|
|
end
|
|
|
|
|
2017-06-11 15:25:15 +00:00
|
|
|
def moveSouth()#1
|
2015-07-01 17:04:19 +00:00
|
|
|
word x, y
|
|
|
|
getPos(@x, @y)
|
|
|
|
if y < totalMapHeight-5
|
|
|
|
setDir(8)
|
|
|
|
moveForward()
|
|
|
|
else
|
|
|
|
beep()
|
|
|
|
fin
|
2017-06-11 15:25:15 +00:00
|
|
|
return 0
|
2015-01-18 16:59:56 +00:00
|
|
|
end
|
|
|
|
|
2017-06-11 15:25:15 +00:00
|
|
|
def moveWest()#1
|
2015-07-01 17:04:19 +00:00
|
|
|
word x, y
|
|
|
|
getPos(@x, @y)
|
|
|
|
if x > 4
|
|
|
|
setDir(12)
|
|
|
|
moveForward()
|
|
|
|
else
|
|
|
|
beep()
|
|
|
|
fin
|
2017-06-11 15:25:15 +00:00
|
|
|
return 0
|
2015-03-25 14:40:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-05-20 16:47:35 +00:00
|
|
|
// Switch to a new map (2D or 3D) and establish position on it
|
2017-06-10 15:56:23 +00:00
|
|
|
export def setMap(is3D, num, x, y, dir)#0
|
2015-05-20 16:47:35 +00:00
|
|
|
if is3D == mapIs3D and num == mapNum
|
|
|
|
setPos(x, y)
|
|
|
|
setDir(dir)
|
|
|
|
needRender = TRUE
|
|
|
|
else
|
2015-05-27 15:13:09 +00:00
|
|
|
flipToPage1()
|
2016-06-20 15:49:01 +00:00
|
|
|
showMapName("Traveling...")
|
2016-07-12 15:09:55 +00:00
|
|
|
setMapWindow(); clearWindow()
|
2015-05-20 16:47:35 +00:00
|
|
|
mapIs3D = is3D
|
|
|
|
mapNum = num
|
2016-07-14 20:52:23 +00:00
|
|
|
allowZoneInit = TRUE
|
2015-05-20 16:47:35 +00:00
|
|
|
initMap(x, y, dir)
|
2016-07-14 20:52:23 +00:00
|
|
|
allowZoneInit = FALSE
|
2015-05-20 16:47:35 +00:00
|
|
|
fin
|
2016-09-15 18:08:43 +00:00
|
|
|
// Don't send enter event, because we often land on an "Exit to wilderness?" script
|
|
|
|
//NO:scriptEvent(S_ENTER, NULL)
|
2014-07-20 13:02:10 +00:00
|
|
|
end
|
|
|
|
|
2015-05-20 16:47:35 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 14:21:58 +00:00
|
|
|
export def queue_setMap(is3D, num, x, y, dir)#0
|
2015-05-20 16:47:35 +00:00
|
|
|
q_mapIs3D = is3D
|
|
|
|
q_mapNum = num
|
|
|
|
q_x = x
|
|
|
|
q_y = y
|
|
|
|
q_dir = dir
|
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 14:21:58 +00:00
|
|
|
export def queue_teleport(x, y, dir)#0
|
2015-05-20 16:47:35 +00:00
|
|
|
queue_setMap(mapIs3D, mapNum, x, y, dir)
|
2015-05-03 16:25:57 +00:00
|
|
|
end
|
|
|
|
|
2015-01-10 21:17:56 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Get a key and dispatch it to a command. Then do it again, forever.
|
2017-06-10 15:56:23 +00:00
|
|
|
def kbdLoop()#0
|
2014-07-06 23:02:52 +00:00
|
|
|
word key, func
|
2015-04-20 15:32:02 +00:00
|
|
|
byte xreg, tmp
|
|
|
|
xreg = getXReg()
|
2014-07-06 23:02:52 +00:00
|
|
|
while TRUE
|
2017-01-15 17:10:43 +00:00
|
|
|
// If the asm routines all work correctly, by the time we get to the top of this loop
|
|
|
|
// the X register should always have the same value.
|
2015-04-20 15:32:02 +00:00
|
|
|
tmp = getXReg()
|
|
|
|
if tmp <> xreg
|
2017-01-15 17:10:43 +00:00
|
|
|
printHex(xreg<<8 | tmp)
|
|
|
|
fatal("xRegChg")
|
2015-04-20 15:32:02 +00:00
|
|
|
fin
|
2014-07-19 22:55:27 +00:00
|
|
|
key = getUpperKey()
|
2016-06-19 15:38:40 +00:00
|
|
|
if key >= 0 and key < $60
|
2014-07-19 22:55:27 +00:00
|
|
|
func = cmdTbl[key]
|
2017-08-02 17:20:22 +00:00
|
|
|
if func
|
|
|
|
if textClearCountdown
|
|
|
|
textClearCountdown--
|
|
|
|
if !textClearCountdown; clearTextWindow(); fin
|
|
|
|
fin
|
|
|
|
func()
|
|
|
|
fin
|
2014-07-06 23:02:52 +00:00
|
|
|
fin
|
2015-05-20 16:47:35 +00:00
|
|
|
if q_mapNum
|
|
|
|
setMap(q_mapIs3D, q_mapNum, q_x, q_y, q_dir)
|
|
|
|
q_mapNum = 0
|
|
|
|
fin
|
2015-05-15 15:19:18 +00:00
|
|
|
if needRender
|
2015-12-17 17:19:49 +00:00
|
|
|
doRender()
|
2015-05-15 15:19:18 +00:00
|
|
|
fin
|
2014-07-06 23:02:52 +00:00
|
|
|
loop
|
|
|
|
end
|
|
|
|
|
2016-08-05 16:27:11 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
def hashString(str)#1
|
2016-08-05 16:27:11 +00:00
|
|
|
return hashBuffer(str+1, ^str)
|
|
|
|
end
|
|
|
|
|
2015-12-09 15:35:02 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 14:32:31 +00:00
|
|
|
export def showMapName(mapName)#0
|
2015-12-09 15:35:02 +00:00
|
|
|
word newNameHash
|
|
|
|
|
|
|
|
newNameHash = hashString(mapName)
|
|
|
|
if newNameHash <> mapNameHash
|
|
|
|
setWindow1()
|
|
|
|
clearWindow()
|
|
|
|
displayChar('Y'-$40) // center mode
|
|
|
|
displayStr(mapName)
|
|
|
|
displayChar('N'-$40) // normal mode
|
2016-10-31 15:04:22 +00:00
|
|
|
if mapIs3D and texturesLoaded; copyWindow(); fin
|
2015-12-09 15:35:02 +00:00
|
|
|
mapNameHash = newNameHash
|
|
|
|
fin
|
|
|
|
end
|
|
|
|
|
2015-01-10 21:17:56 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-07-01 17:04:19 +00:00
|
|
|
// Set initial info for the scripts on this map: the name of the map, its trigger table, and the
|
|
|
|
// maximum extent (width, height). This is called by the init function for the scripts.
|
2017-06-10 14:21:58 +00:00
|
|
|
export def setScriptInfo(mapName, trigTbl, wdt, hgt)#0
|
2015-04-20 15:32:02 +00:00
|
|
|
|
2015-05-21 14:19:22 +00:00
|
|
|
// Grab the trigger table origins (used so the table can be more compact)
|
|
|
|
triggerOriginX = trigTbl=>0
|
|
|
|
triggerOriginY = trigTbl=>2
|
|
|
|
|
2015-04-20 15:32:02 +00:00
|
|
|
// Record the trigger table pointer
|
2015-05-21 14:19:22 +00:00
|
|
|
triggerTbl = trigTbl + 4
|
2015-04-20 15:32:02 +00:00
|
|
|
|
2015-07-01 17:04:19 +00:00
|
|
|
// Record the maximum width and height
|
|
|
|
totalMapWidth = wdt
|
|
|
|
totalMapHeight = hgt
|
|
|
|
|
2015-04-20 15:32:02 +00:00
|
|
|
// Display map name
|
2016-09-22 14:32:54 +00:00
|
|
|
global=>s_mapName = mmgr(HEAP_INTERN, mapName)
|
2015-12-09 15:35:02 +00:00
|
|
|
showMapName(mapName)
|
2015-04-20 15:32:02 +00:00
|
|
|
|
2016-04-26 13:39:44 +00:00
|
|
|
// Get ready for new encounter zones
|
2016-07-14 20:52:23 +00:00
|
|
|
if allowZoneInit
|
|
|
|
global=>p_encounterZones = NULL
|
|
|
|
fin
|
2016-04-26 13:39:44 +00:00
|
|
|
|
2015-05-15 15:19:18 +00:00
|
|
|
// Back to the main text window.
|
2015-04-20 15:32:02 +00:00
|
|
|
setWindow2()
|
2015-02-27 13:33:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Called by scripts to display a string. We set the flag noting that something has been
|
|
|
|
// displayed, then use an assembly routine to do the work.
|
2017-01-22 17:23:29 +00:00
|
|
|
// Also, clear the keyboard strobe, so the player has time to read the text.
|
2017-06-10 14:21:58 +00:00
|
|
|
export def scriptDisplayStr(str)#0
|
2016-11-07 15:58:46 +00:00
|
|
|
if pIntimate
|
|
|
|
pIntimate=>intimate_displayStr(str)
|
|
|
|
else
|
2017-08-02 17:20:22 +00:00
|
|
|
if textClearCountdown; clearTextWindow(); fin
|
2017-07-08 23:36:08 +00:00
|
|
|
if renderLoaded; flipToPage1(); fin
|
2016-11-07 15:58:46 +00:00
|
|
|
displayStr(str)
|
2017-08-02 17:20:22 +00:00
|
|
|
textDrawn = TRUE
|
2016-11-07 15:58:46 +00:00
|
|
|
fin
|
2016-07-09 00:50:45 +00:00
|
|
|
// No: tossString() // Doesn't work here, because we need to toss strings in the *parent's* frame
|
2014-07-08 23:02:10 +00:00
|
|
|
end
|
|
|
|
|
2017-06-10 14:21:58 +00:00
|
|
|
export def scriptDisplayStrNL(str)#0
|
2015-07-04 17:02:49 +00:00
|
|
|
scriptDisplayStr(str)
|
|
|
|
displayStr("\n")
|
|
|
|
end
|
|
|
|
|
2016-11-01 16:25:36 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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.
|
2017-06-10 15:56:23 +00:00
|
|
|
export def scriptSwapTile(fromX, fromY, toX, toY)#0
|
2016-11-01 16:25:36 +00:00
|
|
|
needRender = TRUE
|
|
|
|
swapTile(fromX, fromY, toX, toY)
|
|
|
|
end
|
|
|
|
|
2015-01-10 21:17:56 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Get a key, and don't return until it's Y or N (or lower-case of those). Returns 1 for Y.
|
2017-06-10 15:56:23 +00:00
|
|
|
export def getYN()#1
|
2014-07-19 22:55:27 +00:00
|
|
|
byte key
|
|
|
|
while TRUE
|
|
|
|
key = getUpperKey()
|
|
|
|
if key == 'Y'
|
|
|
|
return 1
|
|
|
|
elsif key == 'N'
|
2017-08-02 17:20:22 +00:00
|
|
|
clearTextWindow()
|
2017-06-10 15:56:23 +00:00
|
|
|
break
|
2014-07-19 22:55:27 +00:00
|
|
|
fin
|
|
|
|
beep()
|
|
|
|
loop
|
2017-06-10 15:56:23 +00:00
|
|
|
return 0
|
2014-07-19 22:55:27 +00:00
|
|
|
end
|
|
|
|
|
2015-12-17 17:19:49 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Show the current animation frame
|
2017-06-10 14:32:31 +00:00
|
|
|
def showAnimFrame()#0
|
2016-10-23 17:42:11 +00:00
|
|
|
if curPortrait
|
|
|
|
// Blit portrait to the appropriate area on the screen
|
|
|
|
if frameLoaded == 3 // 3D-mode frame? Note: don't check mapIs3D, because we might be in an engine
|
2017-08-04 15:15:40 +00:00
|
|
|
blit(1, curPortrait + 2, getScreenLine(24)+2, 128, 18) // start at 3rd text line
|
2016-10-23 17:42:11 +00:00
|
|
|
else
|
2017-08-04 15:15:40 +00:00
|
|
|
blit(1, curPortrait + 2, getScreenLine(32)+2, 128, 18) // start at 4th text line
|
2016-10-23 17:42:11 +00:00
|
|
|
fin
|
|
|
|
needRender = FALSE // suppress display of map for this frame
|
|
|
|
elsif curFullscreenImg
|
2017-08-04 15:15:40 +00:00
|
|
|
blit(1, curFullscreenImg + 2, getScreenLine(0), 192, 40) // the +2 is to skip anim hdr offset
|
2016-10-23 17:42:11 +00:00
|
|
|
needRender = FALSE // suppress display of map for this frame
|
2016-10-24 15:20:52 +00:00
|
|
|
elsif mapIs3D
|
|
|
|
render()
|
2015-12-17 17:19:49 +00:00
|
|
|
fin
|
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Advance to next frame of current animation, if any
|
2017-06-10 14:32:31 +00:00
|
|
|
def nextAnimFrame()#0
|
2016-10-23 16:09:43 +00:00
|
|
|
word flags
|
2016-10-23 17:42:11 +00:00
|
|
|
if !anyAnims; return; fin
|
2015-12-17 17:19:49 +00:00
|
|
|
|
2015-12-23 23:42:37 +00:00
|
|
|
// Choose a new direction based on the flags. Do this the first time, and once every 3-7 frames.
|
|
|
|
animDirCt = animDirCt - 1
|
2016-10-22 15:46:37 +00:00
|
|
|
if animDirCt <= 0
|
2015-12-23 23:42:37 +00:00
|
|
|
animDirCt = (rand16() % 5) + 3
|
2015-12-17 17:19:49 +00:00
|
|
|
fin
|
|
|
|
|
2016-11-08 16:39:18 +00:00
|
|
|
// Advance animations.
|
2016-10-22 15:46:37 +00:00
|
|
|
// First part is whether to switch directions on fwd/back anims.
|
|
|
|
// Second part is how many frames to advance random anims.
|
2016-10-26 14:38:07 +00:00
|
|
|
flags = auxMmgr(ADVANCE_ANIMS, ((animDirCt==1) & 1) | (((rand16() % 10)+1)<<8))
|
2016-10-23 16:09:43 +00:00
|
|
|
if (flags >> 8)
|
|
|
|
// An animation was changed -- display it
|
2015-12-17 17:19:49 +00:00
|
|
|
showAnimFrame()
|
2016-10-23 16:09:43 +00:00
|
|
|
elsif (flags & $FF) == 0
|
|
|
|
// No animations in memory; turn off future checking
|
2016-10-22 15:46:37 +00:00
|
|
|
anyAnims = FALSE
|
2015-12-17 17:19:49 +00:00
|
|
|
fin
|
|
|
|
|
|
|
|
// Reset the animation pause
|
|
|
|
animPauseCt = ANIM_PAUSE_MAX
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-05-27 15:13:09 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-05-28 15:14:01 +00:00
|
|
|
// Display a portrait drawing (typically called from scripts)
|
2017-06-10 15:56:23 +00:00
|
|
|
export def setPortrait(portraitNum)#0
|
2015-05-27 15:13:09 +00:00
|
|
|
word srcData
|
2017-07-08 23:36:08 +00:00
|
|
|
byte part, cx, cy, cursX, cursY
|
2015-05-27 15:13:09 +00:00
|
|
|
|
2015-12-28 17:13:18 +00:00
|
|
|
clearPortrait()
|
2016-06-03 16:18:25 +00:00
|
|
|
|
2015-05-28 15:14:01 +00:00
|
|
|
// We're going to switch windows. Save the cursor pos in the text window.
|
2017-07-08 23:36:08 +00:00
|
|
|
cursX, cursY = getCursor()
|
2015-05-27 15:13:09 +00:00
|
|
|
|
2015-12-29 16:59:13 +00:00
|
|
|
// Make room by unloading the textures (only if renderer is loaded)
|
2016-09-08 15:30:08 +00:00
|
|
|
unloadTextures()
|
2015-12-28 18:20:28 +00:00
|
|
|
|
2015-05-28 15:14:01 +00:00
|
|
|
// Now clear out the map area
|
2015-05-27 15:13:09 +00:00
|
|
|
setMapWindow()
|
|
|
|
clearWindow()
|
|
|
|
|
2015-05-28 15:14:01 +00:00
|
|
|
// Restore the cursor position
|
|
|
|
setWindow2()
|
2017-07-08 23:36:08 +00:00
|
|
|
setCursor(cursX, cursY)
|
2015-05-28 15:14:01 +00:00
|
|
|
|
|
|
|
// Load the portrait image and display it
|
2017-02-20 15:42:23 +00:00
|
|
|
part = lookupResourcePart(3, portraitNum)
|
|
|
|
if part > 1; part = curMapPartition; fin // Look on disk 1 or current disk only
|
|
|
|
mmgr(START_LOAD, part)
|
2015-12-17 17:19:49 +00:00
|
|
|
curPortrait = auxMmgr(QUEUE_LOAD, portraitNum<<8 | RES_TYPE_PORTRAIT)
|
2017-04-03 15:22:32 +00:00
|
|
|
curPortraitNum = portraitNum
|
2016-09-08 15:39:41 +00:00
|
|
|
mmgr(FINISH_LOAD, 0)
|
2016-10-22 15:46:37 +00:00
|
|
|
anyAnims = TRUE // for now; might get cleared if we discover otherwise on advance
|
2015-12-23 23:42:37 +00:00
|
|
|
animDirCt = 1
|
2015-12-17 17:19:49 +00:00
|
|
|
animPauseCt = ANIM_PAUSE_MAX
|
2015-05-27 15:13:09 +00:00
|
|
|
|
2015-12-17 17:19:49 +00:00
|
|
|
// And show the first frame
|
|
|
|
showAnimFrame()
|
2015-12-28 18:20:28 +00:00
|
|
|
|
|
|
|
// Do not render over the portrait
|
|
|
|
needRender = FALSE
|
2015-05-28 15:14:01 +00:00
|
|
|
end
|
2015-05-27 15:13:09 +00:00
|
|
|
|
2015-11-11 16:55:16 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def countList(p)#1
|
2015-12-05 23:01:44 +00:00
|
|
|
byte n
|
2015-11-11 16:55:16 +00:00
|
|
|
n = 0
|
|
|
|
while p
|
2016-07-15 21:29:32 +00:00
|
|
|
n++
|
2015-11-11 16:55:16 +00:00
|
|
|
p = p=>p_nextObj
|
|
|
|
loop
|
|
|
|
return n
|
|
|
|
end
|
|
|
|
|
2015-12-05 19:13:35 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def countListFiltered(p, offset, filterFunc)#1
|
2015-12-05 23:01:44 +00:00
|
|
|
byte n
|
2015-12-05 19:13:35 +00:00
|
|
|
n = 0
|
|
|
|
while p
|
|
|
|
if filterFunc(p)
|
2016-07-15 21:29:32 +00:00
|
|
|
n++
|
2015-12-05 19:13:35 +00:00
|
|
|
fin
|
|
|
|
p = *(p + offset)
|
|
|
|
loop
|
|
|
|
return n
|
|
|
|
end
|
|
|
|
|
2017-03-25 14:23:10 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Find the end of a null-terminated array
|
2017-06-10 15:56:23 +00:00
|
|
|
export def countArray(arr)#1
|
2017-03-25 14:23:10 +00:00
|
|
|
byte count
|
|
|
|
for count = 0 to 127
|
2017-06-10 15:56:23 +00:00
|
|
|
if !*arr; break; fin
|
2017-03-25 14:23:10 +00:00
|
|
|
arr = arr + 2
|
|
|
|
next
|
2017-06-10 15:56:23 +00:00
|
|
|
return count
|
2017-03-25 14:23:10 +00:00
|
|
|
end
|
|
|
|
|
2015-12-05 23:01:44 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def randomFromListFiltered(p, offset, filterFunc)#1
|
2015-12-05 23:01:44 +00:00
|
|
|
byte n
|
|
|
|
n = rand16() % countListFiltered(p, offset, filterFunc)
|
|
|
|
while p
|
|
|
|
if filterFunc(p)
|
|
|
|
if n == 0; return p; fin
|
2017-06-30 15:11:34 +00:00
|
|
|
n--
|
2015-12-05 23:01:44 +00:00
|
|
|
fin
|
|
|
|
p = *(p + offset)
|
|
|
|
loop
|
|
|
|
return NULL
|
|
|
|
end
|
|
|
|
|
2015-11-11 16:55:16 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-12-29 16:59:13 +00:00
|
|
|
// Call like this: addToList(@player=>p_items, itemToAdd)
|
2017-06-09 14:14:53 +00:00
|
|
|
export def addToList(addTo, p)#0
|
2015-12-09 15:35:02 +00:00
|
|
|
// Get to the end of the list
|
|
|
|
while *addTo
|
|
|
|
addTo = (*addTo) + p_nextObj
|
|
|
|
loop
|
2015-11-11 16:55:16 +00:00
|
|
|
p=>p_nextObj = *addTo
|
|
|
|
*addTo = p
|
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2016-06-19 15:15:51 +00:00
|
|
|
// Call like this: removeFromList(@player=>items, itemToRemove)
|
2017-06-10 15:56:23 +00:00
|
|
|
export def removeFromList(pList, toRemove)#0
|
2015-11-11 16:55:16 +00:00
|
|
|
word p
|
|
|
|
|
|
|
|
p = *pList
|
|
|
|
while p and p <> toRemove
|
|
|
|
pList = p + p_nextObj
|
|
|
|
p = *pList
|
|
|
|
loop
|
|
|
|
|
|
|
|
if p
|
|
|
|
*pList = p=>p_nextObj
|
|
|
|
p=>p_nextObj = NULL
|
|
|
|
else
|
|
|
|
fatal("InvalUnlink")
|
|
|
|
fin
|
|
|
|
end
|
|
|
|
|
2015-11-29 17:21:03 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
def saveMapPos()#0
|
2016-06-01 16:03:14 +00:00
|
|
|
global->b_mapIs3D = mapIs3D
|
|
|
|
global->b_mapNum = mapNum
|
|
|
|
getPos(@global=>w_mapX, @global=>w_mapY)
|
|
|
|
global->b_mapDir = getDir()
|
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
def restoreMapPos()#0
|
2016-06-01 16:03:14 +00:00
|
|
|
mapIs3D = global->b_mapIs3D
|
|
|
|
mapNum = global->b_mapNum
|
2016-07-12 15:09:55 +00:00
|
|
|
initMap(global=>w_mapX, global=>w_mapY, global->b_mapDir)
|
2016-06-01 16:03:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
def loadEngine(moduleNum)#1
|
2016-09-22 14:32:54 +00:00
|
|
|
if curEngine; fatal("dblEng"); fin
|
|
|
|
clearPortrait()
|
2017-04-10 14:27:10 +00:00
|
|
|
unloadTextures()
|
2016-06-01 16:03:14 +00:00
|
|
|
flipToPage1()
|
2016-06-19 14:42:11 +00:00
|
|
|
mmgr(START_LOAD, 1) // code is in partition 1
|
2016-09-22 14:32:54 +00:00
|
|
|
curEngine = mmgr(QUEUE_LOAD, moduleNum<<8 | RES_TYPE_MODULE)
|
2017-06-02 15:25:29 +00:00
|
|
|
// For combat module, pre-load some global funcs
|
|
|
|
if moduleNum == MOD_COMBAT
|
|
|
|
mmgr(QUEUE_LOAD, GS_COMBAT_INTRO<<8 | RES_TYPE_MODULE)
|
|
|
|
mmgr(QUEUE_LOAD, GS_COMBAT_PROMPT<<8 | RES_TYPE_MODULE)
|
|
|
|
mmgr(QUEUE_LOAD, GS_ENEMY_INTRO<<8 | RES_TYPE_MODULE)
|
|
|
|
fin
|
2016-09-08 15:39:41 +00:00
|
|
|
mmgr(FINISH_LOAD, 0)
|
2016-09-22 14:32:54 +00:00
|
|
|
return curEngine() // return function table
|
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
def returnFromEngine(render)#0
|
2016-09-22 14:32:54 +00:00
|
|
|
if curEngine
|
|
|
|
mmgr(FREE_MEMORY, curEngine)
|
|
|
|
curEngine = NULL
|
2017-03-22 16:46:17 +00:00
|
|
|
loadMainFrameImg()
|
2016-09-22 14:32:54 +00:00
|
|
|
clearPortrait()
|
2017-07-16 19:34:24 +00:00
|
|
|
if renderLoaded; texControl(1); texturesLoaded = TRUE; fin
|
2016-09-22 14:32:54 +00:00
|
|
|
mapNameHash = 0; showMapName(global=>s_mapName)
|
2017-08-02 17:20:22 +00:00
|
|
|
clearTextWindow()
|
2017-04-10 14:27:10 +00:00
|
|
|
if render; doRender(); fin
|
2016-09-22 14:32:54 +00:00
|
|
|
showParty()
|
2016-09-22 17:55:34 +00:00
|
|
|
setWindow2() // in case we're mid-script
|
2016-09-22 14:32:54 +00:00
|
|
|
fin
|
2016-06-19 14:42:11 +00:00
|
|
|
end
|
2015-12-09 15:35:02 +00:00
|
|
|
|
2016-06-19 14:42:11 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def callGlobalFunc(moduleNum, arg1, arg2, arg3)#1
|
2016-12-08 15:05:28 +00:00
|
|
|
word pModule, pFunc, ret
|
|
|
|
|
|
|
|
// First load the module
|
2016-12-06 17:38:24 +00:00
|
|
|
flipToPage1()
|
|
|
|
mmgr(START_LOAD, 1) // code is in partition 1
|
2016-12-08 15:05:28 +00:00
|
|
|
pModule = mmgr(QUEUE_LOAD, moduleNum<<8 | RES_TYPE_MODULE)
|
2016-12-06 17:38:24 +00:00
|
|
|
mmgr(FINISH_LOAD, 0)
|
|
|
|
|
2016-12-08 15:05:28 +00:00
|
|
|
// Call the function, passing it the number of args it expects
|
|
|
|
pFunc = pModule()
|
|
|
|
when getArgCount(pFunc)
|
|
|
|
is 0; ret = pFunc(); break
|
|
|
|
is 1; ret = pFunc(arg1); break
|
|
|
|
is 2; ret = pFunc(arg1, arg2); break
|
|
|
|
is 3; ret = pFunc(arg1, arg2, arg3); break
|
|
|
|
otherwise fatal("maxGlobParams")
|
|
|
|
wend
|
|
|
|
|
|
|
|
// Unload the module and we're done.
|
2016-12-06 17:38:24 +00:00
|
|
|
mmgr(FREE_MEMORY, pModule)
|
2016-12-08 15:05:28 +00:00
|
|
|
return ret
|
2016-12-06 17:38:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2016-06-19 14:42:11 +00:00
|
|
|
// Load the Party engine and show data for the given player
|
2017-06-11 15:25:15 +00:00
|
|
|
def showPlayerSheet(num)#1
|
2016-11-04 15:27:22 +00:00
|
|
|
word pItemToUse
|
2017-06-24 18:43:16 +00:00
|
|
|
if num+1 > countList(global=>p_players); beep; return 0; fin
|
2016-12-08 15:05:28 +00:00
|
|
|
pItemToUse = loadEngine(MOD_PARTY)=>party_showPlayerSheet(num)
|
2017-04-10 14:27:10 +00:00
|
|
|
returnFromEngine(TRUE)
|
2016-11-04 15:27:22 +00:00
|
|
|
// General 'use' handled here in case it triggers graphical effects
|
|
|
|
if pItemToUse
|
|
|
|
scriptEvent(@S_USE, pItemToUse=>s_name)
|
|
|
|
fin
|
2017-06-11 15:25:15 +00:00
|
|
|
return 0
|
2015-12-09 15:35:02 +00:00
|
|
|
end
|
|
|
|
|
2017-06-11 15:25:15 +00:00
|
|
|
def showPlayer1()#1
|
|
|
|
return showPlayerSheet(0)
|
2015-12-09 15:35:02 +00:00
|
|
|
end
|
2017-06-11 15:25:15 +00:00
|
|
|
def showPlayer2()#1
|
|
|
|
return showPlayerSheet(1)
|
2015-12-09 15:35:02 +00:00
|
|
|
end
|
2017-06-11 15:25:15 +00:00
|
|
|
def showPlayer3()#1
|
|
|
|
return showPlayerSheet(2)
|
2015-12-09 18:16:05 +00:00
|
|
|
end
|
|
|
|
|
2017-07-08 23:36:08 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Level up the first character that's applicable
|
|
|
|
def levelUp()#1
|
|
|
|
word player
|
|
|
|
byte n
|
|
|
|
player = global=>p_players
|
|
|
|
n = 0
|
|
|
|
while player
|
|
|
|
if player->b_skillPoints
|
|
|
|
showPlayerSheet(n)
|
|
|
|
return 0
|
|
|
|
fin
|
|
|
|
player = player=>p_nextObj
|
|
|
|
loop
|
|
|
|
beep
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2016-03-29 22:17:42 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-09 14:14:53 +00:00
|
|
|
export def addEncounterZone(code, x, y, dist, chance)#0
|
2016-07-14 20:52:23 +00:00
|
|
|
word p
|
|
|
|
if allowZoneInit
|
|
|
|
p = mmgr(HEAP_ALLOC, TYPE_ENCOUNTER_ZONE)
|
|
|
|
p=>s_name = mmgr(HEAP_INTERN, code)
|
|
|
|
p=>w_encX = x
|
|
|
|
p=>w_encY = y
|
|
|
|
p=>w_encMaxDist = dist
|
|
|
|
p=>w_encChance = chance
|
|
|
|
addToList(@global=>p_encounterZones, p)
|
|
|
|
fin
|
2016-03-29 22:17:42 +00:00
|
|
|
end
|
|
|
|
|
2016-07-11 00:18:03 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def clearEncounterZones()#0
|
2016-07-11 00:18:03 +00:00
|
|
|
global=>p_encounterZones = NULL
|
|
|
|
end
|
|
|
|
|
2016-02-15 22:43:25 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2016-06-30 15:36:46 +00:00
|
|
|
// Called by user-defined map scripts to initiate a combat encounter.
|
2017-06-10 15:56:23 +00:00
|
|
|
export def scriptCombat(mapCode)#1
|
2016-09-22 17:55:34 +00:00
|
|
|
return doCombat(mapCode, TRUE)
|
2016-06-29 14:42:58 +00:00
|
|
|
end
|
|
|
|
|
2016-07-18 23:47:49 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 14:32:31 +00:00
|
|
|
def playerDeath()#0
|
2017-06-02 15:38:31 +00:00
|
|
|
callGlobalFunc(GS_DEATH, 0, 0, 0)
|
2016-07-18 23:47:49 +00:00
|
|
|
startGame(FALSE) // don't ask, just load
|
|
|
|
end
|
|
|
|
|
2016-06-29 14:42:58 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
def doCombat(mapCode, backUpOnFlee)#1
|
2016-06-30 15:36:46 +00:00
|
|
|
word result
|
2016-06-19 14:42:11 +00:00
|
|
|
// Handled in a separate module. Clear enemies out of the heap when finished.
|
2016-12-08 15:05:28 +00:00
|
|
|
result = loadEngine(MOD_COMBAT)=>combat_zoneEncounter(mapCode)
|
2015-12-10 17:43:21 +00:00
|
|
|
global=>p_enemyGroups = NULL
|
|
|
|
mmgr(HEAP_COLLECT, 0)
|
2016-07-18 23:47:49 +00:00
|
|
|
|
|
|
|
if (result == -99)
|
|
|
|
playerDeath()
|
2017-06-10 14:32:31 +00:00
|
|
|
return 0
|
2016-07-18 23:47:49 +00:00
|
|
|
fin
|
2017-04-10 14:27:10 +00:00
|
|
|
returnFromEngine(TRUE)
|
2016-06-30 16:31:29 +00:00
|
|
|
|
|
|
|
// If the party fled the combat instead of winning, back up to previous square.
|
2016-09-22 17:55:34 +00:00
|
|
|
if !result and backUpOnFlee
|
2016-07-01 23:32:57 +00:00
|
|
|
moveWayBackward()
|
2016-06-30 16:31:29 +00:00
|
|
|
fin
|
2016-06-30 15:36:46 +00:00
|
|
|
return result
|
2015-12-09 15:35:02 +00:00
|
|
|
end
|
|
|
|
|
2016-03-31 17:01:04 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Check for a random encounter at this position
|
2017-06-10 14:32:31 +00:00
|
|
|
export def checkEncounter(x, y, force)#0
|
2016-03-31 17:01:04 +00:00
|
|
|
word p
|
|
|
|
word p_bestZone, bestDist
|
|
|
|
word d
|
|
|
|
|
2017-08-10 17:51:20 +00:00
|
|
|
// Don't check for encounter during scripted move
|
|
|
|
if inScript; return; fin
|
|
|
|
|
2016-03-31 17:01:04 +00:00
|
|
|
// Find the zone that's closest, but not too far.
|
|
|
|
bestDist = INT_MAX
|
|
|
|
p_bestZone = NULL
|
|
|
|
p = global=>p_encounterZones
|
|
|
|
while p
|
|
|
|
d = min(abs(x - p=>w_encX), abs(y - p=>w_encY))
|
|
|
|
if d < bestDist and (p=>w_encMaxDist == 0 or d < p=>w_encMaxDist))
|
|
|
|
p_bestZone = p
|
|
|
|
bestDist = d
|
|
|
|
fin
|
|
|
|
p = p=>p_nextObj
|
|
|
|
loop
|
|
|
|
|
|
|
|
// Roll for an encounter in the zone.
|
|
|
|
d = rand16() % 1000
|
2017-07-11 15:56:14 +00:00
|
|
|
if p_bestZone
|
|
|
|
if (d < p_bestZone=>w_encChance or force)
|
|
|
|
// Encounter!
|
|
|
|
doCombat(p_bestZone=>s_name, !force)
|
|
|
|
fin
|
2016-03-31 17:01:04 +00:00
|
|
|
fin
|
|
|
|
end
|
|
|
|
|
2016-06-19 15:38:40 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-11 15:25:15 +00:00
|
|
|
def saveGame()#1
|
2016-09-22 15:04:24 +00:00
|
|
|
saveMapPos()
|
2016-12-08 15:05:28 +00:00
|
|
|
loadEngine(MOD_DISKOPS)=>diskops_saveGame()
|
2017-04-10 14:27:10 +00:00
|
|
|
returnFromEngine(TRUE)
|
2017-06-11 15:25:15 +00:00
|
|
|
return 0
|
2016-06-19 15:38:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-11 15:25:15 +00:00
|
|
|
def loadGame()#1
|
2016-12-08 15:05:28 +00:00
|
|
|
loadEngine(MOD_DISKOPS)=>diskops_loadGame()
|
2016-06-19 15:38:40 +00:00
|
|
|
restoreMapPos()
|
2017-06-11 15:25:15 +00:00
|
|
|
return 0
|
2016-06-19 15:38:40 +00:00
|
|
|
end
|
|
|
|
|
2016-07-02 00:19:12 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-11 15:25:15 +00:00
|
|
|
def help()#1
|
2016-12-05 17:23:00 +00:00
|
|
|
flipToPage1()
|
|
|
|
setMapWindow(); clearWindow()
|
2017-06-02 15:25:29 +00:00
|
|
|
loadEngine(GS_HELP)()
|
2017-04-10 14:27:10 +00:00
|
|
|
returnFromEngine(TRUE)
|
2017-06-11 15:25:15 +00:00
|
|
|
return 0
|
2016-07-02 00:19:12 +00:00
|
|
|
end
|
2016-07-16 17:27:28 +00:00
|
|
|
|
2016-07-02 00:19:12 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-16 18:31:42 +00:00
|
|
|
def toggleGodMode()#1
|
2017-02-19 18:08:03 +00:00
|
|
|
while ^kbd < 128; loop
|
|
|
|
if ^kbd == $8F // ctrl-O
|
|
|
|
^kbdStrobe
|
|
|
|
while ^kbd < 128; loop
|
|
|
|
if ^kbd == $84 // ctrl-D
|
|
|
|
^kbdStrobe
|
2017-06-16 18:31:42 +00:00
|
|
|
global->b_godmode = !global->b_godmode
|
2017-08-02 17:20:22 +00:00
|
|
|
clearTextWindow()
|
2017-07-11 15:56:14 +00:00
|
|
|
displayf1("gm:%d\n", global->b_godmode & 1)
|
|
|
|
beep; beep
|
2017-08-02 17:20:22 +00:00
|
|
|
clearTextWindow()
|
2017-02-19 18:08:03 +00:00
|
|
|
saveMapPos(); restoreMapPos() // reload everything, including god module
|
|
|
|
fin
|
2016-07-16 17:27:28 +00:00
|
|
|
fin
|
2017-06-24 18:43:16 +00:00
|
|
|
return 0
|
2016-07-16 17:27:28 +00:00
|
|
|
end
|
2017-02-19 18:08:03 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 14:32:31 +00:00
|
|
|
export def finalWin()#0
|
2017-02-19 18:08:03 +00:00
|
|
|
flipToPage1()
|
|
|
|
loadFrameImg(4) // total hack
|
|
|
|
while 1 // 1 infinite loop
|
|
|
|
getUpperKey()
|
|
|
|
loop
|
2016-07-16 17:46:41 +00:00
|
|
|
end
|
2017-02-19 18:08:03 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def setCmd(key, func)#0
|
2017-02-19 18:08:03 +00:00
|
|
|
cmdTbl[key] = func
|
2016-07-16 17:27:28 +00:00
|
|
|
end
|
2016-07-02 00:19:12 +00:00
|
|
|
|
2015-01-10 21:17:56 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Set up the command table for 3D mode
|
2017-06-10 14:32:31 +00:00
|
|
|
def initCmds()#0
|
2015-04-05 16:52:38 +00:00
|
|
|
|
|
|
|
// Clear the command table
|
|
|
|
byte i
|
2016-06-19 15:38:40 +00:00
|
|
|
for i = 0 to 95
|
2015-04-05 16:52:38 +00:00
|
|
|
cmdTbl[i] = 0
|
|
|
|
next
|
|
|
|
|
2015-05-03 16:25:57 +00:00
|
|
|
// Commands common to both 2D and 3D
|
2016-06-19 15:38:40 +00:00
|
|
|
cmdTbl['1'] = @showPlayer1
|
|
|
|
cmdTbl['2'] = @showPlayer2
|
|
|
|
cmdTbl['3'] = @showPlayer3
|
2017-07-08 23:36:08 +00:00
|
|
|
cmdTbl['U'] = @levelUp
|
2016-06-19 15:38:40 +00:00
|
|
|
cmdTbl[$13] = @saveGame // ctrl-S
|
|
|
|
cmdTbl[$0c] = @loadGame // ctrl-L
|
2016-07-02 00:19:12 +00:00
|
|
|
cmdTbl['?'] = @help
|
2017-07-11 15:56:14 +00:00
|
|
|
cmdTbl[$07] = @toggleGodMode // ctrl-G
|
2016-07-16 17:46:41 +00:00
|
|
|
if global->b_godmode
|
2017-02-19 18:08:03 +00:00
|
|
|
pGodModule=>godmode_setCheatCmds()
|
2016-07-16 17:46:41 +00:00
|
|
|
fin
|
2015-05-03 16:25:57 +00:00
|
|
|
|
|
|
|
// Commands handled differently in 3D vs 2D
|
2015-04-05 16:52:38 +00:00
|
|
|
if mapIs3D
|
2016-06-19 15:38:40 +00:00
|
|
|
cmdTbl['W'] = @moveForward
|
|
|
|
cmdTbl['A'] = @rotateLeft
|
|
|
|
cmdTbl['D'] = @rotateRight
|
|
|
|
cmdTbl['S'] = @moveBackward
|
|
|
|
cmdTbl['X'] = @moveBackward
|
|
|
|
cmdTbl['Z'] = @strafeLeft
|
|
|
|
cmdTbl['C'] = @strafeRight
|
|
|
|
|
|
|
|
cmdTbl['I'] = @moveForward
|
|
|
|
cmdTbl['J'] = @rotateLeft
|
|
|
|
cmdTbl['L'] = @rotateRight
|
|
|
|
cmdTbl['K'] = @moveBackward
|
|
|
|
cmdTbl[','] = @moveBackward
|
|
|
|
cmdTbl['M'] = @strafeLeft
|
|
|
|
cmdTbl['.'] = @strafeRight
|
2017-05-24 15:51:06 +00:00
|
|
|
|
|
|
|
cmdTbl[11] = @moveForward // up-arrow
|
|
|
|
cmdTbl[8] = @rotateLeft // left-arrow
|
|
|
|
cmdTbl[21] = @rotateRight // right-arrow
|
|
|
|
cmdTbl[10] = @moveBackward // down-arrow
|
2015-04-05 16:52:38 +00:00
|
|
|
else
|
2016-06-19 15:38:40 +00:00
|
|
|
cmdTbl['W'] = @moveNorth
|
|
|
|
cmdTbl['D'] = @moveEast
|
|
|
|
cmdTbl['S'] = @moveSouth
|
|
|
|
cmdTbl['X'] = @moveSouth
|
|
|
|
cmdTbl['A'] = @moveWest
|
|
|
|
|
|
|
|
cmdTbl['I'] = @moveNorth
|
|
|
|
cmdTbl['J'] = @moveWest
|
|
|
|
cmdTbl['L'] = @moveEast
|
|
|
|
cmdTbl['K'] = @moveSouth
|
|
|
|
cmdTbl[','] = @moveSouth
|
2017-05-24 15:51:06 +00:00
|
|
|
|
|
|
|
cmdTbl[11] = @moveNorth // up-arrow
|
|
|
|
cmdTbl[8] = @moveWest // left-arrow
|
|
|
|
cmdTbl[21] = @moveEast // right-arrow
|
|
|
|
cmdTbl[10] = @moveSouth // down-arrow
|
2015-04-09 17:31:36 +00:00
|
|
|
fin
|
2015-01-10 21:17:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Load and display the title screen.
|
2017-06-10 15:56:23 +00:00
|
|
|
def loadTitle()#0
|
2017-01-12 17:08:05 +00:00
|
|
|
word pEngine, pFont, expanderSize
|
2015-12-10 17:43:21 +00:00
|
|
|
|
2016-06-16 14:13:39 +00:00
|
|
|
puts("Loading game.\n")
|
2015-01-10 21:17:56 +00:00
|
|
|
|
2017-01-12 17:08:05 +00:00
|
|
|
// Allocate and permanently lock mem for the font engine and its font (up in LC ram)
|
2017-03-22 16:46:17 +00:00
|
|
|
mmgr(START_LOAD, 1) // partition 1 is where code lives
|
2015-12-10 17:43:21 +00:00
|
|
|
mmgr(SET_MEM_TARGET, fontEngine)
|
2017-01-05 22:27:44 +00:00
|
|
|
mmgr(REQUEST_MEMORY, fontEngineLen)
|
2015-12-10 17:43:21 +00:00
|
|
|
mmgr(LOCK_MEMORY, fontEngine)
|
|
|
|
|
2017-01-05 22:27:44 +00:00
|
|
|
mmgr(SET_MEM_TARGET, fontData)
|
|
|
|
mmgr(REQUEST_MEMORY, fontDataLen)
|
|
|
|
mmgr(LOCK_MEMORY, fontData)
|
|
|
|
|
|
|
|
// Load them into lo mem
|
2017-03-22 16:46:17 +00:00
|
|
|
pEngine = mmgr(QUEUE_LOAD, CODE_FONT_ENGINE<<8 | RES_TYPE_CODE)
|
|
|
|
pFont = mmgr(QUEUE_LOAD, 1<<8 | RES_TYPE_FONT)
|
|
|
|
mmgr(FINISH_LOAD, 0)
|
|
|
|
|
|
|
|
// Relocate font engine and font data to their final spots up in the language card
|
|
|
|
memcpy(pEngine, fontEngine, fontEngineLen)
|
|
|
|
memcpy(pFont, fontData, fontDataLen)
|
|
|
|
|
|
|
|
// Load the title screen and show it.
|
|
|
|
loadFrameImg(1) // title screen is fixed at #1
|
|
|
|
^$C050 // graphics
|
|
|
|
^$C057 // hi-res
|
|
|
|
^$C054 // page 1
|
|
|
|
^$C052 // full screen
|
|
|
|
// Hack for real (not emulated) IIc: sometimes displays only lo-bit graphics
|
|
|
|
// unless we do this. *HUGE* thanks to Brendan Robert for the fix!
|
|
|
|
^$C07E=0 // disable double-hi-res
|
|
|
|
^$C05F // disable double-hi-res
|
2017-01-12 17:08:05 +00:00
|
|
|
|
|
|
|
// While we're loading, let's get the expander into aux RAM.
|
|
|
|
auxMmgr(SET_MEM_TARGET, expandVec)
|
|
|
|
auxMmgr(QUEUE_LOAD, CODE_EXPAND<<8 | RES_TYPE_CODE)
|
|
|
|
|
2017-02-06 18:01:00 +00:00
|
|
|
// Also grab the resource index (put it in aux)
|
|
|
|
pResourceIndex = auxMmgr(QUEUE_LOAD, CODE_RESOURCE_INDEX<<8 | RES_TYPE_CODE)
|
2017-02-17 17:01:35 +00:00
|
|
|
auxMmgr(LOCK_MEMORY, pResourceIndex)
|
2017-02-06 18:01:00 +00:00
|
|
|
|
2016-09-08 15:39:41 +00:00
|
|
|
mmgr(FINISH_LOAD, 0)
|
2015-12-10 17:43:21 +00:00
|
|
|
|
2017-01-12 17:08:05 +00:00
|
|
|
// Tell the font engine where to find its font
|
|
|
|
setFont(fontData)
|
|
|
|
|
|
|
|
// And free up the font low mem
|
2017-01-05 22:27:44 +00:00
|
|
|
mmgr(FREE_MEMORY, pEngine)
|
|
|
|
mmgr(FREE_MEMORY, pFont)
|
2015-12-10 17:43:21 +00:00
|
|
|
|
2017-01-12 17:08:05 +00:00
|
|
|
// Split the expander (relocating most of it to aux LC ram)
|
|
|
|
readAuxByte($1A) // sets up aux routine
|
|
|
|
expanderSize = splitExpander(expandVec)
|
|
|
|
|
|
|
|
// Lock in the part of the expander that remains in low aux mem.
|
|
|
|
auxMmgr(FREE_MEMORY, expandVec)
|
|
|
|
auxMmgr(SET_MEM_TARGET, expandVec)
|
|
|
|
auxMmgr(REQUEST_MEMORY, expanderSize)
|
|
|
|
auxMmgr(LOCK_MEMORY, expandVec)
|
2015-01-10 21:17:56 +00:00
|
|
|
end
|
|
|
|
|
2015-09-19 20:27:57 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2016-06-24 12:58:30 +00:00
|
|
|
// Set up the small-object heap. Set loadedSize to zero on initial, or non-zero for loaded game.
|
2017-06-10 15:56:23 +00:00
|
|
|
export def initHeap(loadedSize)#0
|
2015-12-29 19:22:14 +00:00
|
|
|
byte i
|
2016-08-05 16:27:11 +00:00
|
|
|
word typeHash
|
2015-12-29 19:22:14 +00:00
|
|
|
|
2016-06-24 15:46:40 +00:00
|
|
|
if !heapLocked
|
|
|
|
mmgr(SET_MEM_TARGET, HEAP_BOTTOM)
|
|
|
|
mmgr(REQUEST_MEMORY, HEAP_SIZE)
|
|
|
|
mmgr(LOCK_MEMORY, HEAP_BOTTOM)
|
|
|
|
heapLocked = TRUE
|
|
|
|
fin
|
|
|
|
|
2016-06-24 12:58:30 +00:00
|
|
|
if loadedSize <> 0
|
|
|
|
mmgr(SET_MEM_TARGET, HEAP_BOTTOM + loadedSize)
|
|
|
|
fin
|
|
|
|
mmgr(HEAP_SET, HEAP_BOTTOM)
|
2015-12-29 19:22:14 +00:00
|
|
|
i = 0
|
|
|
|
while typeTbls[i]
|
|
|
|
mmgr(HEAP_ADD_TYPE, typeTbls[i])
|
|
|
|
i = i+1
|
|
|
|
loop
|
2016-08-13 02:39:36 +00:00
|
|
|
typeHash = hashBuffer(@typeTbl_Global, @typeTbls - @typeTbl_Global) ^ HEAP_BOTTOM
|
2016-06-24 13:12:45 +00:00
|
|
|
if loadedSize <> 0
|
|
|
|
global = HEAP_BOTTOM
|
2016-08-05 16:27:11 +00:00
|
|
|
if global=>w_typeHash <> typeHash
|
|
|
|
fatal("Incompatible saved game")
|
|
|
|
fin
|
2016-06-24 13:12:45 +00:00
|
|
|
else
|
|
|
|
global = mmgr(HEAP_ALLOC, TYPE_GLOBAL)
|
2016-08-05 16:27:11 +00:00
|
|
|
global=>w_typeHash = typeHash
|
2016-06-24 13:12:45 +00:00
|
|
|
fin
|
2015-09-19 20:27:57 +00:00
|
|
|
end
|
|
|
|
|
2016-06-12 15:52:24 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-03-04 16:20:01 +00:00
|
|
|
// Return a random entry from an array which is terminated by a zero entry
|
2017-06-10 15:56:23 +00:00
|
|
|
export def randomFromArray(arr)#1
|
2017-03-04 16:20:01 +00:00
|
|
|
byte siz
|
|
|
|
siz = 0
|
|
|
|
while *((siz << 1) + arr)
|
|
|
|
siz++
|
|
|
|
loop
|
2016-06-12 15:52:24 +00:00
|
|
|
return *(((rand16() % siz) << 1) + arr)
|
|
|
|
end
|
|
|
|
|
2016-06-11 17:58:33 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2016-06-19 15:04:43 +00:00
|
|
|
// Constructor: create a modifier given its name and value
|
2017-06-10 15:56:23 +00:00
|
|
|
export def makeModifier(name, value)#1
|
2016-06-12 15:52:24 +00:00
|
|
|
word p; p = mmgr(HEAP_ALLOC, TYPE_MODIFIER)
|
2016-06-12 20:12:14 +00:00
|
|
|
p=>s_name = mmgr(HEAP_INTERN, name)
|
|
|
|
p=>w_modValue = value
|
2016-06-11 17:58:33 +00:00
|
|
|
return p
|
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2016-06-19 15:04:43 +00:00
|
|
|
// Recalculate player's armor score based on their currently equipped armor
|
2017-06-10 15:56:23 +00:00
|
|
|
export def calcPlayerArmor(player)#0
|
2016-06-17 00:42:18 +00:00
|
|
|
word pItem
|
|
|
|
player->b_armor = 0
|
|
|
|
pItem = player=>p_items
|
|
|
|
while pItem
|
2016-07-12 15:09:55 +00:00
|
|
|
if pItem->t_type == TYPE_ARMOR and pItem->b_flags & ITEM_FLAG_EQUIP
|
2016-06-17 00:42:18 +00:00
|
|
|
player->b_armor = player->b_armor + pItem->b_armorValue
|
|
|
|
fin
|
|
|
|
pItem = pItem=>p_nextObj
|
|
|
|
loop
|
|
|
|
end
|
|
|
|
|
2016-07-04 16:31:33 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
// Add gold, return the amount
|
|
|
|
export def addGold(amount)#1
|
2016-07-04 16:31:33 +00:00
|
|
|
if global=>w_gold + amount > GOLD_MAX
|
|
|
|
amount = GOLD_MAX - global=>w_gold
|
|
|
|
fin
|
2016-07-04 17:56:55 +00:00
|
|
|
global=>w_gold = global=>w_gold + amount
|
2016-07-04 16:31:33 +00:00
|
|
|
return amount
|
|
|
|
end
|
|
|
|
|
2017-06-10 15:56:23 +00:00
|
|
|
// Pay out gold, return the amount
|
|
|
|
export def payGold(amount)#1
|
2016-07-04 16:31:33 +00:00
|
|
|
if amount > global=>w_gold
|
2016-07-04 17:56:55 +00:00
|
|
|
return 0
|
2016-07-04 16:31:33 +00:00
|
|
|
fin
|
|
|
|
global=>w_gold = global=>w_gold - amount
|
2016-07-04 17:56:55 +00:00
|
|
|
return amount
|
2016-07-04 16:31:33 +00:00
|
|
|
end
|
|
|
|
|
2016-07-07 23:15:31 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def scanForNamedObj(p_obj, name)#1
|
2016-07-07 23:15:31 +00:00
|
|
|
while p_obj
|
|
|
|
if streqi(p_obj=>s_name, name); return p_obj; fin
|
|
|
|
p_obj = p_obj=>p_nextObj
|
|
|
|
loop
|
|
|
|
return NULL
|
|
|
|
end
|
|
|
|
|
2017-02-20 14:43:47 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
// Add to a list if named obj not already in it; returns TRUE if really added.
|
|
|
|
export def addUnique(pList, p_thing)#1
|
2017-02-20 14:43:47 +00:00
|
|
|
if !scanForNamedObj(*pList, p_thing=>s_name)
|
|
|
|
addToList(pList, p_thing)
|
2017-03-29 16:36:14 +00:00
|
|
|
return TRUE
|
2017-02-20 14:43:47 +00:00
|
|
|
fin
|
2017-03-29 16:36:14 +00:00
|
|
|
return FALSE
|
2017-02-20 14:43:47 +00:00
|
|
|
end
|
|
|
|
|
2016-07-07 20:59:07 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def createAndAddUnique(moduleID, creationFuncNum, pList)#1
|
2016-08-17 15:09:14 +00:00
|
|
|
word p_module, funcTbl, func, p_thing
|
2016-07-12 15:09:55 +00:00
|
|
|
|
2016-09-15 18:08:43 +00:00
|
|
|
// Unload textures to make room for the module (also flips to page 1 if needed)
|
2016-09-08 15:30:08 +00:00
|
|
|
unloadTextures()
|
2016-08-31 15:17:02 +00:00
|
|
|
|
2016-08-17 15:09:14 +00:00
|
|
|
// Load the module that is capable of creating the thing
|
2016-07-07 20:59:07 +00:00
|
|
|
mmgr(START_LOAD, 1) // code is in partition 1
|
2016-08-17 15:09:14 +00:00
|
|
|
p_module = mmgr(QUEUE_LOAD, moduleID<<8 | RES_TYPE_MODULE)
|
2016-09-08 15:39:41 +00:00
|
|
|
mmgr(FINISH_LOAD, 0)
|
2016-07-07 20:59:07 +00:00
|
|
|
|
2016-08-17 15:09:14 +00:00
|
|
|
// Figure out which creation function to call there, and create the thing
|
2016-07-07 20:59:07 +00:00
|
|
|
funcTbl = p_module()
|
2016-08-17 15:09:14 +00:00
|
|
|
func = *(funcTbl + creationFuncNum)
|
2017-02-20 14:43:47 +00:00
|
|
|
p_thing = func() // full
|
2016-08-17 15:09:14 +00:00
|
|
|
|
2016-08-22 15:08:22 +00:00
|
|
|
// Avoid adding duplicate things.
|
2017-02-20 14:43:47 +00:00
|
|
|
addUnique(pList, p_thing)
|
2016-07-07 20:59:07 +00:00
|
|
|
|
2016-08-17 15:09:14 +00:00
|
|
|
// Finished with the module now.
|
2016-07-07 23:15:31 +00:00
|
|
|
mmgr(FREE_MEMORY, p_module)
|
2016-09-08 16:34:02 +00:00
|
|
|
return p_thing
|
2016-07-07 20:59:07 +00:00
|
|
|
end
|
|
|
|
|
2016-07-07 23:15:31 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def giveItemToPlayer(p_player, itemFuncNum)#0
|
2017-02-20 14:43:47 +00:00
|
|
|
createAndAddUnique(MOD_GEN_ITEMS, itemFuncNum, @p_player=>p_items)
|
2016-08-17 15:09:14 +00:00
|
|
|
end
|
|
|
|
|
2017-06-24 20:28:28 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Add XP to every player in the party, leveling them up as appropriate
|
|
|
|
export def addXP(val)#1
|
|
|
|
word player, n
|
|
|
|
if val < 0; return 0; fin
|
|
|
|
player = global=>p_players
|
|
|
|
while player
|
|
|
|
player=>w_curXP = player=>w_curXP + val
|
|
|
|
// Enforce cap on number of points to stay well within limit of 15 bits
|
|
|
|
if player=>w_curXP < 0 or player=>w_curXP > 29999
|
|
|
|
player=>w_curXP = 29999
|
|
|
|
fin
|
|
|
|
while player=>w_curXP >= player=>w_nextXP
|
2017-07-08 23:36:08 +00:00
|
|
|
// Level up!
|
|
|
|
player->b_level++
|
|
|
|
player->b_skillPoints = player->b_skillPoints + callGlobalFunc(GS_LEVEL_S_P, player->b_level, 0, 0)
|
|
|
|
player=>w_maxHealth = player=>w_maxHealth + player->b_stamina + rollDice($2600) // stam + 2d6
|
|
|
|
player=>w_health = player=>w_maxHealth // let's make leveling up an extra nice thing
|
|
|
|
needShowParty = TRUE
|
2017-06-24 20:28:28 +00:00
|
|
|
|
|
|
|
// Check XP for next level, and enforce level cap if any
|
|
|
|
n = callGlobalFunc(GS_LEVEL_X_P, player->b_level + 1, 0, 0)
|
2017-06-25 14:11:58 +00:00
|
|
|
if n > w_nextXP and n <= 30000
|
|
|
|
player=>w_nextXP = n
|
|
|
|
else
|
|
|
|
player=>w_nextXP = 30000 // level cap reached
|
|
|
|
break
|
2017-06-24 20:28:28 +00:00
|
|
|
fin
|
|
|
|
loop
|
|
|
|
player = player=>p_nextObj
|
|
|
|
loop
|
|
|
|
return val
|
|
|
|
end
|
|
|
|
|
2017-07-08 23:36:08 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Initialize XP (and skill pts) for newly created character
|
|
|
|
export def initPlayerXP(player)#0
|
|
|
|
player->b_skillPoints = callGlobalFunc(GS_LEVEL_S_P, player->b_level, 0, 0)
|
|
|
|
player=>w_curXP = callGlobalFunc(GS_LEVEL_X_P, player->b_level, 0, 0)
|
|
|
|
player=>w_nextXP = callGlobalFunc(GS_LEVEL_X_P, player->b_level + 1, 0, 0)
|
|
|
|
end
|
|
|
|
|
2017-07-11 15:56:14 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Arm newly created player (or NPC) with first weapon and all armor.
|
|
|
|
export def girdPlayer(player)#0
|
|
|
|
word pItem
|
|
|
|
byte weaponFound
|
|
|
|
weaponFound = FALSE
|
|
|
|
pItem = player=>p_items
|
|
|
|
while pItem
|
|
|
|
if pItem->t_type == TYPE_WEAPON
|
|
|
|
if !weaponFound
|
|
|
|
pItem->b_flags = pItem->b_flags | ITEM_FLAG_EQUIP
|
|
|
|
weaponFound = TRUE
|
|
|
|
fin
|
|
|
|
elsif pItem->t_type == TYPE_ARMOR
|
|
|
|
pItem->b_flags = pItem->b_flags | ITEM_FLAG_EQUIP
|
|
|
|
fin
|
|
|
|
pItem = pItem=>p_nextObj
|
|
|
|
loop
|
|
|
|
calcPlayerArmor(player)
|
|
|
|
end
|
|
|
|
|
2016-08-17 15:09:14 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-09 14:14:53 +00:00
|
|
|
export def addPlayerToParty(playerFuncNum)#0
|
2016-09-08 16:34:02 +00:00
|
|
|
word p
|
2016-11-10 16:40:50 +00:00
|
|
|
if countList(global=>p_players) == MAX_PARTY
|
|
|
|
displayStr("Party too large.")
|
|
|
|
return
|
|
|
|
fin
|
2016-12-08 15:05:28 +00:00
|
|
|
p = createAndAddUnique(MOD_GEN_PLAYERS, playerFuncNum, @global=>p_players)
|
2016-09-08 16:34:02 +00:00
|
|
|
p->b_playerFlags = p->b_playerFlags | PLAYER_FLAG_NPC
|
2017-06-24 20:28:28 +00:00
|
|
|
addXP(0) // to set initial skill pts
|
2016-08-22 15:08:22 +00:00
|
|
|
needShowParty = TRUE
|
2016-08-17 15:09:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def removeNamed(name, pList)#0
|
2016-08-17 15:09:14 +00:00
|
|
|
word p_thing
|
|
|
|
p_thing = scanForNamedObj(*pList, name)
|
|
|
|
if p_thing
|
|
|
|
removeFromList(pList, p_thing)
|
2016-07-07 20:59:07 +00:00
|
|
|
else
|
2016-08-17 15:09:14 +00:00
|
|
|
printf1("Warning: couldn't find '%s' to remove.\n", name)
|
2016-07-07 20:59:07 +00:00
|
|
|
fin
|
|
|
|
end
|
|
|
|
|
2016-08-17 15:09:14 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def takeItemFromPlayer(p_player, itemName)#0
|
2017-02-20 14:43:47 +00:00
|
|
|
removeNamed(itemName, @p_player=>p_items) // default to first player
|
2016-08-17 15:09:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def removePlayerFromParty(playerName)#0
|
2016-08-17 15:09:14 +00:00
|
|
|
removeNamed(playerName, @global=>p_players)
|
2016-08-22 15:08:22 +00:00
|
|
|
needShowParty = TRUE
|
2016-08-17 15:09:14 +00:00
|
|
|
end
|
|
|
|
|
2016-07-07 23:15:31 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def playerHasItem(itemName)#1
|
2016-07-11 00:33:48 +00:00
|
|
|
return scanForNamedObj(global=>p_players=>p_items, itemName) <> NULL
|
2016-07-07 20:59:07 +00:00
|
|
|
end
|
|
|
|
|
2016-08-17 15:09:14 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def partyHasPlayer(playerName)#1
|
2016-08-17 15:09:14 +00:00
|
|
|
return scanForNamedObj(global=>p_players, playerName) <> NULL
|
|
|
|
end
|
|
|
|
|
2016-07-07 23:15:31 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def getStat(player, statName)#1
|
2017-08-06 18:23:40 +00:00
|
|
|
word pSkill
|
2016-07-07 21:22:48 +00:00
|
|
|
when statName
|
2016-07-08 00:02:44 +00:00
|
|
|
is @S_INTELLIGENCE; return player->b_intelligence
|
2016-07-07 23:15:31 +00:00
|
|
|
is @S_STRENGTH; return player->b_strength
|
2016-07-08 00:02:44 +00:00
|
|
|
is @S_AGILITY; return player->b_agility
|
|
|
|
is @S_STAMINA; return player->b_stamina
|
|
|
|
is @S_CHARISMA; return player->b_charisma
|
|
|
|
is @S_SPIRIT; return player->b_spirit
|
|
|
|
is @S_LUCK; return player->b_luck
|
|
|
|
is @S_HEALTH; return player=>w_health
|
|
|
|
is @S_MAX_HEALTH; return player=>w_maxHealth
|
|
|
|
is @S_AIMING; return player->b_aiming
|
|
|
|
is @S_HAND_TO_HAND; return player->b_handToHand
|
|
|
|
is @S_DODGING; return player->b_dodging
|
|
|
|
is @S_GOLD; return global=>w_gold
|
2017-06-14 16:22:05 +00:00
|
|
|
is @S_XP; return player=>w_curXP
|
|
|
|
is @S_SP; return player->b_skillPoints
|
2016-07-07 21:22:48 +00:00
|
|
|
wend
|
2017-08-06 18:23:40 +00:00
|
|
|
pSkill = player=>p_skills
|
|
|
|
while pSkill
|
|
|
|
if streqi(statName, pSkill=>s_name); return pSkill=>w_modValue; fin
|
|
|
|
pSkill = pSkill=>p_nextObj
|
|
|
|
loop
|
2017-06-10 15:56:23 +00:00
|
|
|
puts(statName); return fatal("Unknown stat")
|
2016-07-07 20:59:07 +00:00
|
|
|
end
|
|
|
|
|
2017-07-15 18:41:29 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Return an appropriate pronoun for the given gender (M/F/N...)
|
|
|
|
export def hisHerTheir(gender)#1
|
|
|
|
if gender == 'M'; return @S_HIS; fin
|
|
|
|
if gender == 'F'; return @S_HER; fin
|
|
|
|
return @S_THEIR
|
|
|
|
end
|
|
|
|
|
2016-07-07 23:15:31 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
def clampByte(val)#1
|
2016-07-07 23:15:31 +00:00
|
|
|
return max(0, min(255, val))
|
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 14:32:31 +00:00
|
|
|
export def setStat(player, statName, val)#0
|
2017-08-06 18:23:40 +00:00
|
|
|
word pSkill
|
2016-07-07 23:15:31 +00:00
|
|
|
when statName
|
2016-07-08 00:02:44 +00:00
|
|
|
is @S_INTELLIGENCE; player->b_intelligence = clampByte(val); break
|
|
|
|
is @S_STRENGTH; player->b_strength = clampByte(val); break
|
|
|
|
is @S_AGILITY; player->b_agility = clampByte(val); break
|
|
|
|
is @S_STAMINA; player->b_stamina = clampByte(val); break
|
|
|
|
is @S_CHARISMA; player->b_charisma = clampByte(val); break
|
|
|
|
is @S_SPIRIT; player->b_spirit = clampByte(val); break
|
|
|
|
is @S_LUCK; player->b_luck = clampByte(val); break
|
2016-07-16 12:39:22 +00:00
|
|
|
is @S_HEALTH; player=>w_health = max(0, min(player=>w_maxHealth, val)); needShowParty = TRUE; break
|
2016-07-08 00:02:44 +00:00
|
|
|
is @S_MAX_HEALTH; player=>w_maxHealth = max(0, val); break
|
|
|
|
is @S_AIMING; player->b_aiming = clampByte(val); break
|
|
|
|
is @S_HAND_TO_HAND; player->b_handToHand = clampByte(val); break
|
|
|
|
is @S_DODGING; player->b_dodging = clampByte(val); break
|
2016-07-16 12:39:22 +00:00
|
|
|
is @S_GOLD; global=>w_gold = max(0, val); needShowParty = TRUE; break
|
2017-08-06 18:23:40 +00:00
|
|
|
is @S_XP; player=>w_curXP = max(player=>w_curXP, val); needShowParty = TRUE; break
|
|
|
|
is @S_SP; player->b_skillPoints = max(0, val); needShowParty = TRUE; break
|
2016-07-07 23:15:31 +00:00
|
|
|
otherwise
|
2017-08-06 18:23:40 +00:00
|
|
|
pSkill = player=>p_skills
|
|
|
|
while pSkill
|
|
|
|
if streqi(statName, pSkill=>s_name)
|
|
|
|
pSkill=>w_modValue = max(0, val)
|
|
|
|
return
|
|
|
|
fin
|
|
|
|
pSkill = pSkill=>p_nextObj
|
|
|
|
loop
|
2016-07-07 23:15:31 +00:00
|
|
|
puts(statName); fatal("Unknown stat")
|
|
|
|
wend
|
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def setGameFlag(flagName, val)#0
|
2016-07-07 23:15:31 +00:00
|
|
|
word p_flag
|
|
|
|
p_flag = scanForNamedObj(global=>p_gameFlags, flagName)
|
|
|
|
if p_flag
|
|
|
|
if val == 0 // setting flag to zero removes it
|
|
|
|
removeFromList(@global=>p_gameFlags, p_flag)
|
|
|
|
else
|
|
|
|
p_flag=>w_modValue = val
|
|
|
|
fin
|
|
|
|
elsif val <> 0
|
|
|
|
addToList(@global=>p_gameFlags, makeModifier(flagName, val))
|
|
|
|
fin
|
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def getGameFlag(flagName)#1
|
2016-07-07 23:15:31 +00:00
|
|
|
word p_flag
|
|
|
|
p_flag = scanForNamedObj(global=>p_gameFlags, flagName)
|
|
|
|
if p_flag
|
|
|
|
return p_flag=>w_modValue
|
|
|
|
fin
|
2017-06-10 15:56:23 +00:00
|
|
|
return 0
|
2016-07-07 23:15:31 +00:00
|
|
|
end
|
|
|
|
|
2016-11-07 15:58:46 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def setIntimateMode(enable)#0
|
2016-11-07 15:58:46 +00:00
|
|
|
if enable
|
2016-12-08 15:05:28 +00:00
|
|
|
pIntimate = loadEngine(MOD_INTIMATE)
|
2016-11-07 15:58:46 +00:00
|
|
|
pIntimate=>intimate_setMode(enable)
|
|
|
|
else
|
|
|
|
pIntimate=>intimate_setMode(enable)
|
2017-04-10 14:27:10 +00:00
|
|
|
returnFromEngine(TRUE)
|
2016-11-07 15:58:46 +00:00
|
|
|
pIntimate = NULL
|
|
|
|
fin
|
|
|
|
end
|
|
|
|
|
2016-11-10 16:40:50 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def benchPlayer()#0
|
2016-12-08 15:05:28 +00:00
|
|
|
loadEngine(MOD_PARTY)=>party_benchPlayer()
|
2017-04-10 14:27:10 +00:00
|
|
|
returnFromEngine(TRUE)
|
2016-11-10 16:40:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def unbenchPlayer()#0
|
2016-12-08 15:05:28 +00:00
|
|
|
loadEngine(MOD_PARTY)=>party_unbenchPlayer()
|
2017-04-10 14:27:10 +00:00
|
|
|
returnFromEngine(TRUE)
|
2016-11-10 16:40:50 +00:00
|
|
|
end
|
|
|
|
|
2017-03-04 16:20:01 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 15:56:23 +00:00
|
|
|
export def buySell(storeCode, profitRatio)#0
|
2017-04-10 14:27:10 +00:00
|
|
|
word portrait
|
2017-04-03 15:22:32 +00:00
|
|
|
portrait = curPortraitNum
|
|
|
|
if storeCode
|
2017-04-10 14:27:10 +00:00
|
|
|
loadEngine(MOD_STORE)=>store_buyFromStore(storeCode, profitRatio)
|
2017-04-03 15:22:32 +00:00
|
|
|
else
|
2017-04-10 14:27:10 +00:00
|
|
|
loadEngine(MOD_STORE)=>store_sellToStore(profitRatio)
|
2017-04-03 15:22:32 +00:00
|
|
|
fin
|
2017-04-10 14:27:10 +00:00
|
|
|
returnFromEngine(FALSE) // no render, we're mid-script
|
2017-04-03 15:22:32 +00:00
|
|
|
if portrait; setPortrait(portrait); fin
|
2017-03-04 16:20:01 +00:00
|
|
|
end
|
|
|
|
|
2015-12-29 19:22:14 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-06-10 14:32:31 +00:00
|
|
|
def startGame(ask)#0
|
2016-06-24 12:58:30 +00:00
|
|
|
word p_module
|
2016-03-24 16:45:07 +00:00
|
|
|
|
2016-06-24 12:58:30 +00:00
|
|
|
// Create a new game or load an existing one
|
|
|
|
mmgr(START_LOAD, 1) // code is in partition 1
|
2016-12-08 15:05:28 +00:00
|
|
|
p_module = mmgr(QUEUE_LOAD, MOD_DISKOPS<<8 | RES_TYPE_MODULE)
|
2016-09-08 15:39:41 +00:00
|
|
|
mmgr(FINISH_LOAD, 0)
|
2016-07-18 23:47:49 +00:00
|
|
|
if p_module()=>diskops_newOrLoadGame(ask)
|
2016-06-24 12:58:30 +00:00
|
|
|
mapIs3D = q_mapIs3D
|
|
|
|
mapNum = q_mapNum
|
|
|
|
q_mapNum = 0
|
2016-07-14 20:52:23 +00:00
|
|
|
allowZoneInit = TRUE
|
2016-06-24 12:58:30 +00:00
|
|
|
initMap(q_x, q_y, q_dir)
|
2016-07-14 20:52:23 +00:00
|
|
|
allowZoneInit = FALSE
|
2016-06-24 12:58:30 +00:00
|
|
|
else
|
2016-06-24 14:16:08 +00:00
|
|
|
q_mapNum = 0
|
2016-06-24 12:58:30 +00:00
|
|
|
restoreMapPos()
|
|
|
|
fin
|
2016-07-08 02:01:56 +00:00
|
|
|
crout()
|
2015-12-29 19:22:14 +00:00
|
|
|
end
|
|
|
|
|
2014-08-21 15:17:50 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Main code.
|
|
|
|
//
|
2017-08-10 16:56:46 +00:00
|
|
|
^$25 = 23
|
2015-01-07 22:48:04 +00:00
|
|
|
loadTitle()
|
2016-07-18 23:47:49 +00:00
|
|
|
startGame(TRUE) // ask whether new or load
|
2014-07-06 23:02:52 +00:00
|
|
|
kbdLoop()
|
|
|
|
|
2016-07-12 15:09:55 +00:00
|
|
|
done
|