Factoring out import code.

This commit is contained in:
Martin Haye 2022-01-14 08:42:37 -08:00
parent f21eb21c00
commit 89db793516
4 changed files with 111 additions and 40 deletions

View File

@ -2460,6 +2460,7 @@ class A2PackPartitions
compileModule("party", "src/plasma/")
compileModule("store", "src/plasma/")
compileModule("diskops", "src/plasma/")
compileModule("import", "src/plasma/")
compileModule("godmode", "src/plasma/")
compileModule("util3d", "src/plasma/")
compileModule("automap", "src/plasma/")

View File

@ -14,6 +14,7 @@ include "playtype.plh"
include "diskops.plh"
include "party.plh"
include "sndseq.plh"
include "import.plh"
include "gen_images.plh"
include "gen_modules.plh"
include "gen_players.plh"
@ -39,6 +40,8 @@ word[] funcTbl = @_startup, @_loadGame, @_newOrLoadGame
byte[] legendos_filename = "LEGENDOS.SYSTEM"
word pImportModule
// For checking automap mark sizes
include "gen_mapsizes.pla"
@ -288,6 +291,9 @@ def _startup()#1
// Also the automap marking queue/flush code.
pMarks = mmgr(QUEUE_LOAD, CODE_MARKS<<8 | RES_TYPE_CODE)
// We may need to import a game, so let's load that module now.
pImportModule = mmgr(QUEUE_LOAD, MOD_IMPORT<<8 | RES_TYPE_MODULE)
// And the global funcs we'll need for the title screen
mmgr(QUEUE_LOAD, GS_DISK_LIMIT<<8 | RES_TYPE_MODULE)
mmgr(QUEUE_LOAD, GS_COPYRIGHT<<8 | RES_TYPE_MODULE)
@ -430,24 +436,6 @@ end
def gameExists()#1
word p_loaded
// See if there's a Nox game in drive 2.
^$c051
puts("Insert nox\n")
rdkey()
if callProRWTS(RWTS_READ | RWTS_OPENDIR, "NA", LOAD_SAVE_BUF, 512) == 0
puts("op1 ok")
rdkey()
if callProRWTS(RWTS_READ | RWTS_READDIR, "DATA.SAVE.GAME1", LOAD_SAVE_BUF, 512) == 0
puts("op2 ok")
else
puts("f2")
fin
else
puts("f1")
fin
rdkey
^$c050
// Load first part of save game into mem... 1 block should be plenty to verify it's real.
if callProRWTS(RWTS_READ | RWTS_OPENDIR, @S_GAME1_FILENAME, LOAD_SAVE_BUF, 512) == 0
// If heap size is reasonable and type hash matches, chances are high that it's a real save game.
@ -507,27 +495,6 @@ def reinsert()#0
loop
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def importGame()#1
textHome
^$c053
^$25 = 20
puts("\n Insert disk for import")
pressAnyKey()
if gameExists()
loadInternal()
^$25 = 20
puts("\n Game imported.")
reinsert()
memcpy(HEAP_BOTTOM, LOAD_SAVE_BUF, HEAP_SIZE, 0) // LC to low mem
rwGame(RWTS_WRITE)
return TRUE
fin
puts("\n Not found.")
reinsert()
return FALSE
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def isNameChar(ch)
when ch
@ -742,7 +709,7 @@ def _newOrLoadGame(ask)#1
break
is 'I'
clearWindow
if importGame()
if pImportModule()=>import_getGame()
ret = 0
else
displayMenu(existing)

View File

@ -0,0 +1,91 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2022 The 8-Bit Bunch. Licensed under the Apache License, Version 1.1
// (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at <http://www.apache.org/licenses/LICENSE-1.1>.
// Unless required by applicable law or agreed to in writing, software distributed under
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
// ANY KIND, either express or implied. See the License for the specific language
// governing permissions and limitations under the License.
///////////////////////////////////////////////////////////////////////////////////////////////////
include "gamelib.plh"
include "globalDefs.plh"
include "playtype.plh"
include "diskops.plh"
// 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 _getGame()#1
word[] funcTbl = @_getGame
///////////////////////////////////////////////////////////////////////////////////////////////////
// Definitions used by assembly code
asm __defs
; Use hi-bit ASCII for Apple II
!convtab "../../include/hiBitAscii.ct"
; Headers
!source "../../include/global.i"
!source "../../include/plasma.i"
!source "../../include/mem.i"
!source "../../include/prorwts.i"
; General use
tmp = $2
pTmp = $4
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Set up the font engine
asm fooFunc(param)#0
+asmPlasmNoRet 1
rts
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Load and display the title screen, set up everything in memory
def _getGame()#1
// See if there's a Nox game in drive 2.
^$c051
puts("Insert nox\n")
rdkey()
if callProRWTS(RWTS_READ | RWTS_OPENDIR, "NA", LOAD_SAVE_BUF, 512) == 0
puts("op1 ok")
rdkey()
if callProRWTS(RWTS_READ | RWTS_READDIR, "DATA.SAVE.GAME1", LOAD_SAVE_BUF, 512) == 0
puts("op2 ok")
else
puts("f2")
fin
else
puts("f1")
fin
rdkey
^$c050
// Old code
//textHome
//^$c053
//^$25 = 20
//puts("\n Insert disk for import")
//pressAnyKey()
//if gameExists()
// loadInternal()
// ^$25 = 20
// puts("\n Game imported.")
// reinsert()
// memcpy(HEAP_BOTTOM, LOAD_SAVE_BUF, HEAP_SIZE, 0) // LC to low mem
// rwGame(RWTS_WRITE)
// return TRUE
//fin
//puts("\n Not found.")
//reinsert()
return FALSE
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Boilerplate module initialization code
return @funcTbl
done

View File

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