From c4e88d38730910206af64f2bb61c2acf4b1acfc6 Mon Sep 17 00:00:00 2001 From: Martin Haye Date: Mon, 28 Dec 2015 10:20:28 -0800 Subject: [PATCH] Added texture control, so we can swap out textures in 3D mode to make room for a portrait. --- .../Apple/virtual/src/plasma/gameloop.pla | 36 +++++++++----- Platform/Apple/virtual/src/raycast/render.s | 47 +++++++++++++++++-- Platform/Apple/virtual/src/tile/tile.s | 9 +++- 3 files changed, 77 insertions(+), 15 deletions(-) diff --git a/Platform/Apple/virtual/src/plasma/gameloop.pla b/Platform/Apple/virtual/src/plasma/gameloop.pla index 8b56764c..224ee6c1 100644 --- a/Platform/Apple/virtual/src/plasma/gameloop.pla +++ b/Platform/Apple/virtual/src/plasma/gameloop.pla @@ -60,7 +60,7 @@ byte isPlural = FALSE word skyNum = 9 word groundNum = 10 -byte portraitNum = 1 +byte portraitNum = 0 word triggerOriginX, triggerOriginY word triggerTbl @@ -181,6 +181,10 @@ asm render // no params +asmPlasm 0 jmp $6018 end +asm texControl // params: load (1=load, 0=unload) + +asmPlasm 1 + jmp $601B +end /////////////////////////////////////////////////////////////////////////////////////////////////// asm setAuxCopy @@ -1267,6 +1271,7 @@ def clearPortrait() if curPortrait auxMmgr(FREE_MEMORY, curPortrait) curPortrait = 0 + texControl(1) // 1=load needRender = TRUE fin end @@ -1666,6 +1671,9 @@ def _setPortrait(portraitNum) // We're going to switch windows. Save the cursor pos in the text window. saveCursor() + // Make room by unloading the textures + texControl(0) + // Now clear out the map area setMapWindow() clearWindow() @@ -1686,20 +1694,25 @@ def _setPortrait(portraitNum) // And show the first frame showAnimFrame() -end -/////////////////////////////////////////////////////////////////////////////////////////////////// -// Clear the displayed portrait drawing -def clrPortrait() - doRender() + // Do not render over the portrait + needRender = FALSE end /////////////////////////////////////////////////////////////////////////////////////////////////// // Test out portrait drawing -def testPortrait() - setPortrait(portraitNum) +def nextPortrait() portraitNum = portraitNum + 1 - needRender = FALSE + setPortrait(portraitNum) +end + +/////////////////////////////////////////////////////////////////////////////////////////////////// +// Test out portrait drawing +def prevPortrait() + if portraitNum > 1 + portraitNum = portraitNum - 1 + fin + setPortrait(portraitNum) end /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1883,7 +1896,8 @@ def initCmds() // Commands common to both 2D and 3D initCmd('T', @kbdTeleport) initCmd('P', @showPos) - initCmd('/', @testPortrait) + initCmd('/', @nextPortrait) + initCmd('?', @prevPortrait) initCmd('!', @testCombat) initCmd('1', @showPlayer1) initCmd('2', @showPlayer2) @@ -2011,7 +2025,7 @@ def setCallbacks() // $31E callbacks.30 = $4c - callbacks:31 = @clrPortrait + callbacks:31 = @clearPortrait // $321 callbacks.33 = $4c diff --git a/Platform/Apple/virtual/src/raycast/render.s b/Platform/Apple/virtual/src/raycast/render.s index 9baa08f1..904c6077 100644 --- a/Platform/Apple/virtual/src/raycast/render.s +++ b/Platform/Apple/virtual/src/raycast/render.s @@ -29,6 +29,7 @@ start: jmp pl_advance ; params: none; return: 0 if same, 1 if new map tile, 2 if new and scripted jmp pl_setColor ; params: slot (0=sky/1=ground), color (0-15); return: nothing jmp pl_render ; params: none + jmp pl_texControl ; params: 0=unload textures, 1=load textures ; Conditional assembly flags DOUBLE_BUFFER = 1 ; whether to double-buffer @@ -72,6 +73,7 @@ mapNum: !byte 1 nMapSprites: !byte 0 ; number of sprite entries on map to fix up nextLink: !byte 0 ; next link to allocate plasmaStk: !byte 0 +nTextures: !byte 0 skyColorEven: !byte $20 skyColorOdd: !byte $22 @@ -1562,10 +1564,12 @@ getTileFlags: !zone rts ;------------------------------------------------------------------------------- -; Parse map header, and load the textures into aux mem. Also loads the script -; module and inits it. +; Parse map header, and load the textures into aux mem. Also, loads the script +; module, and if A-reg is nonzero, inits it. loadTextures: !zone !if DEBUG { +prStr : !text "Loading textures.",0 } + ; Save parameter (non-zero: init scripts) + pha ; Scan the map header lda mapHeader sta .get+1 @@ -1603,6 +1607,8 @@ loadTextures: !zone + stx txNum jmp .lup .done: ; end of texture numbers is the list of tile flags + lda txNum + sta nTextures lda .get+1 sta getTileFlags+2 lda .get+2 @@ -1621,17 +1627,51 @@ loadTextures: !zone ldx #0 jsr mainLoader ; finally, init the scripts. + pla + beq .fin !if DEBUG { +prStr : !text "Calling script init ",0 : +prWord .scInit+1 : +crout } ldx plasmaStk .scInit jsr $1111 ; self-modified earlier !if DEBUG { +prStr : !text "Back from script init. ",0 } - rts +.fin rts .get: lda $1111 inc .get+1 bne + inc .get+2 + rts +;------------------------------------------------------------------------------- +; Plasma interface to texture control: 1 to load textures, 0 to unload +pl_texControl: !zone { + cmp #0 + beq .unload + lda #0 ; don't re-init scripts + jmp loadTextures +.unload ldx #0 +- txa + pha + ldy texAddrHi,x + lda texAddrLo,x + + +prStr : !text "tex ",0 + +prX + +prYA + +crout + + tax + lda #FREE_MEMORY + jsr auxLoader + pla + tax + lda #0 + sta texAddrLo,x + sta texAddrHi,x + inx + cpx nTextures + bne - + rts +} + ;------------------------------------------------------------------------------- ; Set up front and back buffers, go to hires mode, and clear for first blit. graphInit: !zone @@ -2033,6 +2073,7 @@ pl_initMap: !zone ldy #>(tableEnd-tableStart) jsr mainLoader ; Proceed with loading + lda #1 ; non-zero to init scripts also jsr loadTextures jsr copyScreen ; Build all the unrolls and tables diff --git a/Platform/Apple/virtual/src/tile/tile.s b/Platform/Apple/virtual/src/tile/tile.s index 310647cb..828ea202 100644 --- a/Platform/Apple/virtual/src/tile/tile.s +++ b/Platform/Apple/virtual/src/tile/tile.s @@ -112,7 +112,8 @@ next_zp = $AB JMP pl_setDir ; params: dir (0-15); return: nothing JMP pl_advance ; params: none; return: 0 if same, 1 if new map tile, 2 if new and scripted JMP pl_setColor ; params: slot (0=sky/1=ground), color (0-15); return: nothing - jmp pl_render ; params: none + JMP pl_render ; params: none + JMP pl_texControl ; params: 1=load, 0=unload ;---------------------------------------------------------------------- ; >> START LOADING MAP SECTIONS @@ -1221,6 +1222,12 @@ pl_setDir: STA AVATAR_DIR RTS +;---------------------------------------------------------------------- +; >> pl_texControl +; No-op, because in 2D there aren't textures +pl_texControl: + rts + ;---------------------------------------------------------------------- INNER_ADVANCE: !zone { LDA AVATAR_DIR