diff --git a/Platform/Apple/tools/PackPartitions/src/org/demo/PackPartitions.groovy b/Platform/Apple/tools/PackPartitions/src/org/demo/PackPartitions.groovy index 0580a4ee..22ccd54b 100644 --- a/Platform/Apple/tools/PackPartitions/src/org/demo/PackPartitions.groovy +++ b/Platform/Apple/tools/PackPartitions/src/org/demo/PackPartitions.groovy @@ -1523,6 +1523,7 @@ class PackPartitions compileModule("gameloop", "src/plasma/") compileModule("combat", "src/plasma/") compileModule("party", "src/plasma/") + compileModule("diskops", "src/plasma/") compileModule("gen_globalScripts", "src/plasma/") compileModule("gen_enemies", "src/plasma/") compileModule("gen_items", "src/plasma/") diff --git a/Platform/Apple/virtual/src/plasma/diskops.pla b/Platform/Apple/virtual/src/plasma/diskops.pla new file mode 100644 index 00000000..2ba777d8 --- /dev/null +++ b/Platform/Apple/virtual/src/plasma/diskops.pla @@ -0,0 +1,45 @@ +/////////////////////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2015 The 8-Bit Bunch. Licensed under the Apache License, Version 1.1 +// (the "License"); you may not use this file except in compliance with the License. +// You may obtain a copy of the License at . +// Unless required by applicable law or agreed to in writing, software distributed under +// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF +// ANY KIND, either express or implied. See the License for the specific language +// governing permissions and limitations under the License. +/////////////////////////////////////////////////////////////////////////////////////////////////// + +// Functions we import from the main game loop. If you find there are some over there that aren't +// yet exported, modify this header then add the mechanics at the top of gameloop.pla. +include "gamelib.plh" + +// Definition of constants for functions exported by this module +include "diskops.plh" + +// This pointer is the root of all heap-tracked (and garbage collected) objects. +// See playtype.plh for definitions of all the datastructures and how they interconnect. +word global + +// Exported functions go here. First a predef for each one, then a table with function pointers +// in the same order as the constants are defined in the the header. +predef _saveGame, _loadGame +word[] funcTbl = @_saveGame, @_loadGame + +// Other global variables here + +/////////////////////////////////////////////////////////////////////////////////////////////////// +def _saveGame() + displayStr("Save game\n") + getUpperKey() +end + +/////////////////////////////////////////////////////////////////////////////////////////////////// +def _loadGame() + displayStr("Load game\n") + getUpperKey() +end + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// Boilerplate module initialization code +global = getGlobals() +return @funcTbl +done diff --git a/Platform/Apple/virtual/src/plasma/diskops.plh b/Platform/Apple/virtual/src/plasma/diskops.plh new file mode 100644 index 00000000..0b7b5935 --- /dev/null +++ b/Platform/Apple/virtual/src/plasma/diskops.plh @@ -0,0 +1,13 @@ +/////////////////////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016 The 8-Bit Bunch. Licensed under the Apache License, Version 1.1 +// (the "License"); you may not use this file except in compliance with the License. +// You may obtain a copy of the License at . +// Unless required by applicable law or agreed to in writing, software distributed under +// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF +// ANY KIND, either express or implied. See the License for the specific language +// governing permissions and limitations under the License. +/////////////////////////////////////////////////////////////////////////////////////////////////// + +// Each module-exported function needs its own constant, 0..n +const diskops_saveGame = 0 +const diskops_loadGame = 2 diff --git a/Platform/Apple/virtual/src/plasma/gameloop.pla b/Platform/Apple/virtual/src/plasma/gameloop.pla index 4cd81044..b41f15c0 100644 --- a/Platform/Apple/virtual/src/plasma/gameloop.pla +++ b/Platform/Apple/virtual/src/plasma/gameloop.pla @@ -42,6 +42,7 @@ include "gen_globalScripts.plh" include "gen_players.plh" include "combat.plh" include "party.plh" +include "diskops.plh" /////////////////////////////////////////////////////////////////////////////////////////////////// // Data structures @@ -73,7 +74,7 @@ byte portraitNum = 0 word triggerOriginX, triggerOriginY word triggerTbl -word cmdTbl[64] +word cmdTbl[96] // ASCII $00..$5F byte frameLoaded = 0 // Queue setMap / teleport, since otherwise script might be replaced while executing @@ -1082,15 +1083,6 @@ def nextGround() setGround((groundNum + 1) % 18) end -/////////////////////////////////////////////////////////////////////////////////////////////////// -// Establish a keystroke -> command association in the command table -def initCmd(key, func) - if key >= $60 - key = key - $20 - fin - cmdTbl[key-$20] = func -end - /////////////////////////////////////////////////////////////////////////////////////////////////// // Load the Frame Image, and lock it. def loadFrameImg() @@ -1553,8 +1545,7 @@ def kbdLoop() brk() fin key = getUpperKey() - key = key - $20 - if key >= 0 and key < $40 + if key >= 0 and key < $60 func = cmdTbl[key] if func; func(); fin fin @@ -1960,58 +1951,72 @@ def testCombat fin end +/////////////////////////////////////////////////////////////////////////////////////////////////// +def saveGame + loadEngine(MODULE_DISKOPS)=>diskops_saveGame() + restoreMapPos() +end + +/////////////////////////////////////////////////////////////////////////////////////////////////// +def loadGame + loadEngine(MODULE_DISKOPS)=>diskops_loadGame() + restoreMapPos() +end + /////////////////////////////////////////////////////////////////////////////////////////////////// // Set up the command table for 3D mode def initCmds() // Clear the command table byte i - for i = 0 to 63 + for i = 0 to 95 cmdTbl[i] = 0 next // Commands common to both 2D and 3D - initCmd('T', @kbdTeleport) - initCmd('P', @showPos) - initCmd('/', @nextPortrait) - initCmd('?', @prevPortrait) - initCmd('!', @testCombat) - initCmd('1', @showPlayer1) - initCmd('2', @showPlayer2) - initCmd('3', @showPlayer3) + cmdTbl['T'] = @kbdTeleport + cmdTbl['P'] = @showPos + cmdTbl['/'] = @nextPortrait + cmdTbl['?'] = @prevPortrait + cmdTbl['!'] = @testCombat + cmdTbl['1'] = @showPlayer1 + cmdTbl['2'] = @showPlayer2 + cmdTbl['3'] = @showPlayer3 + cmdTbl[$13] = @saveGame // ctrl-S + cmdTbl[$0c] = @loadGame // ctrl-L // Commands handled differently in 3D vs 2D if mapIs3D - initCmd('W', @moveForward) - initCmd('A', @rotateLeft) - initCmd('D', @rotateRight) - initCmd('S', @moveBackward) - initCmd('X', @moveBackward) - initCmd('Z', @strafeLeft) - initCmd('C', @strafeRight) + cmdTbl['W'] = @moveForward + cmdTbl['A'] = @rotateLeft + cmdTbl['D'] = @rotateRight + cmdTbl['S'] = @moveBackward + cmdTbl['X'] = @moveBackward + cmdTbl['Z'] = @strafeLeft + cmdTbl['C'] = @strafeRight - initCmd('I', @moveForward) - initCmd('J', @rotateLeft) - initCmd('L', @rotateRight) - initCmd('K', @moveBackward) - initCmd(',', @moveBackward) - initCmd('M', @strafeLeft) - initCmd('.', @strafeRight) + cmdTbl['I'] = @moveForward + cmdTbl['J'] = @rotateLeft + cmdTbl['L'] = @rotateRight + cmdTbl['K'] = @moveBackward + cmdTbl[','] = @moveBackward + cmdTbl['M'] = @strafeLeft + cmdTbl['.'] = @strafeRight - initCmd('Y', @nextSky) - initCmd('G', @nextGround) + cmdTbl['Y'] = @nextSky + cmdTbl['G'] = @nextGround else - initCmd('W', @moveNorth) - initCmd('D', @moveEast) - initCmd('S', @moveSouth) - initCmd('X', @moveSouth) - initCmd('A', @moveWest) + cmdTbl['W'] = @moveNorth + cmdTbl['D'] = @moveEast + cmdTbl['S'] = @moveSouth + cmdTbl['X'] = @moveSouth + cmdTbl['A'] = @moveWest - initCmd('I', @moveNorth) - initCmd('J', @moveWest) - initCmd('L', @moveEast) - initCmd('K', @moveSouth) - initCmd(',', @moveSouth) + cmdTbl['I'] = @moveNorth + cmdTbl['J'] = @moveWest + cmdTbl['L'] = @moveEast + cmdTbl['K'] = @moveSouth + cmdTbl[','] = @moveSouth fin end