From 2f8de46d0e0cf228984762c42fb1b9183154998a Mon Sep 17 00:00:00 2001 From: Martin Haye Date: Thu, 12 Jan 2017 09:08:05 -0800 Subject: [PATCH] Moved more of expander into aux LC to take advantage of space freed up by ProRWTS. Now expander is loaded at startup and remains locked in memory, rather than swapping in and out. --- Platform/Apple/virtual/src/include/mem.i | 26 ++++----- .../Apple/virtual/src/plasma/gameloop.pla | 55 ++++++++++++++++--- Platform/Apple/virtual/src/raycast/expand.s | 6 +- .../Apple/virtual/src/raycast/expand_split.i | 25 ++++++--- Platform/Apple/virtual/src/raycast/render.s | 37 ------------- 5 files changed, 81 insertions(+), 68 deletions(-) diff --git a/Platform/Apple/virtual/src/include/mem.i b/Platform/Apple/virtual/src/include/mem.i index dc0796e8..d396817d 100644 --- a/Platform/Apple/virtual/src/include/mem.i +++ b/Platform/Apple/virtual/src/include/mem.i @@ -46,13 +46,13 @@ ; ; MAIN 64K MEMORY ; ::::::::::::::: -; 0000.01FF 6502 zero page and stack +; 0000.01FF 6502 zero page and stack (main) ; 0200.03FF input buffer, misc vecs ; 0400.07FF text screen (used for debugging) -; 0800.0Dxx memory manager part 1 -; 0Exx.0Fxx PLASMA locals storage -; 10xx.18xx gameloop asm, data and stubs -; 19xx.1FFF (free) +; 0800.0Cxx memory manager part 1 +; 0Cxx.0Exx PLASMA locals storage (length $200) +; 0Exx.17xx gameloop asm, data and stubs +; 17xx.1FFF (free) ; 2000.3FFF hi-res page 1 ; 4000.5FFF hi-res page 2 / ; memory manager work space @@ -70,18 +70,18 @@ ; ; AUX 64K MEMORY ; :::::::::::::: -; 0000.01FF 6502 zero page and stack +; 0000.01FF 6502 zero page and stack (aux) ; 0200.03FF (currently unused) -; 0400.07FF (unused, but screen holes overwritten by hard-disk C7xx ROM) -; 0800.2xxx expander part 1 (if 3D map is running) -; 3000.9xxx (free) -; Axxx.BFFF gameloop PLASMA code (loaded as high as possible) +; 0400.07FF (unused, but screen holes overwritten by hard drive C7xx ROM) +; 0800.0D7A texture expander part 1 (used by 3D renderer) +; 0D7B.9xxx (free) +; A0xx.BFFF gameloop PLASMA code (loaded as high as possible) ; C000.CFFF I/O ; (bank 1) D000.DAFF ProRWTS runtime ; (bank 1) DB00.DFFF (unused) -; (bank 2) D000.DFFF expander part 2 -; E000.FFF9 (free) -; FFFA.FFFF 6502 vectors +; (bank 2) D000.DFFF texture expander part 2 +; E000.FFF9 texture expander part 3 +; FFFA.FFFF 6502 vectors ; ; ---------------------------- ; Segment table format in memory: diff --git a/Platform/Apple/virtual/src/plasma/gameloop.pla b/Platform/Apple/virtual/src/plasma/gameloop.pla index f808c617..862898be 100644 --- a/Platform/Apple/virtual/src/plasma/gameloop.pla +++ b/Platform/Apple/virtual/src/plasma/gameloop.pla @@ -297,6 +297,29 @@ asm readAuxByte // params: ptr; ret: char jmp $10 end +/////////////////////////////////////////////////////////////////////////////////////////////////// +asm splitExpander // param: expandVec; returns: remaining lo-aux size + +asmPlasm 1 + + ; 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 + /////////////////////////////////////////////////////////////////////////////////////////////////// // String building for display with the font engine. Includes plurality processing to handily // handle things like "Dirt bag(s)" and "his/their" @@ -1158,6 +1181,9 @@ export def loadFrameImg(img) // Load the image data into aux mem if img auxMmgr(START_LOAD, 1) // partition 1 is where full screen images live + if img == 1 + auxMmgr(SET_MEM_TARGET, $4000) // well above where expander loads at startup + fin curFullscreenImg = auxMmgr(QUEUE_LOAD, img<<8 | RES_TYPE_SCREEN) auxMmgr(FINISH_LOAD, 0) @@ -1376,8 +1402,6 @@ def initMap(x, y, dir) mmgr(SET_MEM_TARGET, displayEngine) if mapIs3D mmgr(QUEUE_LOAD, CODE_RENDER<<8 | RES_TYPE_CODE) - auxMmgr(SET_MEM_TARGET, expandVec) - auxMmgr(QUEUE_LOAD, CODE_EXPAND<<8 | RES_TYPE_CODE) else mmgr(QUEUE_LOAD, CODE_TILE_ENGINE<<8 | RES_TYPE_CODE) fin @@ -2305,7 +2329,7 @@ end /////////////////////////////////////////////////////////////////////////////////////////////////// // Load and display the title screen. def loadTitle() - word pEngine, pFont + word pEngine, pFont, expanderSize puts("Loading game.\n") @@ -2320,7 +2344,7 @@ def loadTitle() ^$C07E=0 // disable double-hi-res ^$C05F // disable double-hi-res - // Allocate and permanently lock mem for the font engine and its font + // Allocate and permanently lock mem for the font engine and its font (up in LC ram) mmgr(SET_MEM_TARGET, fontEngine) mmgr(REQUEST_MEMORY, fontEngineLen) mmgr(LOCK_MEMORY, fontEngine) @@ -2332,18 +2356,33 @@ def loadTitle() // Load them into lo mem pEngine = mmgr(QUEUE_LOAD, CODE_FONT_ENGINE<<8 | RES_TYPE_CODE) pFont = mmgr(QUEUE_LOAD, 1<<8 | RES_TYPE_FONT) + + // 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) + mmgr(FINISH_LOAD, 0) - // Relocate them to their final spots + // Relocate font engine and font data to their final spots up in the language card memcpy(pEngine, fontEngine, fontEngineLen) memcpy(pFont, fontData, fontDataLen) - // And free up the low mem + // Tell the font engine where to find its font + setFont(fontData) + + // And free up the font low mem mmgr(FREE_MEMORY, pEngine) mmgr(FREE_MEMORY, pFont) - // Tell the font engine where to find its font - setFont(fontData) + // 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) end /////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Platform/Apple/virtual/src/raycast/expand.s b/Platform/Apple/virtual/src/raycast/expand.s index 53ddbb14..be8335ef 100644 --- a/Platform/Apple/virtual/src/raycast/expand.s +++ b/Platform/Apple/virtual/src/raycast/expand.s @@ -851,6 +851,9 @@ e_t96rooto: sta 97*BLIT_STRIDE + blitRoll,x + bvc e_98to +!source "expand_split.i" +!pseudopc $D000 { +reloc_dst = * e_32tooro: bmi + sta 32*BLIT_STRIDE + blitRoll,x @@ -5776,8 +5779,6 @@ expand_102: + rts -!source "expand_split.i" -!pseudopc $D000 { ; Produce 104 rows from 64 rows expand_104: jsr selectMip0 @@ -7374,5 +7375,6 @@ e_t64oroo: sta 66*BLIT_STRIDE + blitRoll,x sta 67*BLIT_STRIDE + blitRoll,x + rts +lc_end = * } ; end of pseudopc expand_end = * diff --git a/Platform/Apple/virtual/src/raycast/expand_split.i b/Platform/Apple/virtual/src/raycast/expand_split.i index a70d7b85..d3973e1d 100644 --- a/Platform/Apple/virtual/src/raycast/expand_split.i +++ b/Platform/Apple/virtual/src/raycast/expand_split.i @@ -9,18 +9,20 @@ ;**************************************************************************************** expand_split: - ; relocate the last $1000 bytes of the expander to the hard-to-get area of + ; relocate the last $2FFA bytes of the expander to the hard-to-get area of ; aux langauge card. - lda #to_reloc + lda #>reloc_src sta tmp+1 - lda #expand_104 + lda #>reloc_dst sta pTmp+1 ldy #0 - ldx #$10 + ldx #$2F - lda (tmp),y sta (pTmp),y iny @@ -29,6 +31,11 @@ expand_split: inc pTmp+1 dex bne - +- lda (tmp),y ; last pg only partial + sta (pTmp),y + iny + cpy #$FA + bne - ; restore vector to first expander now that we've split and relocated lda #(expand_split-expand_vec) + ldy #>(expand_split-expand_vec) + sta clrAuxZP + sta clrAuxWr rts -to_reloc = * +reloc_src = * diff --git a/Platform/Apple/virtual/src/raycast/render.s b/Platform/Apple/virtual/src/raycast/render.s index 6174fb1e..b22671c1 100644 --- a/Platform/Apple/virtual/src/raycast/render.s +++ b/Platform/Apple/virtual/src/raycast/render.s @@ -2163,8 +2163,6 @@ pl_initMap: !zone ldx #<(tableEnd-tableStart) ldy #>(tableEnd-tableStart) jsr mainLoader - ; If expander hasn't been split and relocated yet, do so now - jsr splitExpander ; Proceed with loading lda #1 ; non-zero to init scripts also jsr loadTextures @@ -2179,41 +2177,6 @@ pl_initMap: !zone jsr graphInit jmp renderFrame -;------------------------------------------------------------------------------- -; Split part of the expander off into a hard-to-use area in the aux LC. -; NOTE: It's safe to do this more than once, and is in fact necessary in case -; the expander gets reloaded without the main engine being reloaded. It's safe -; to call expand_0 since it's just an RTS. -splitExpander: - jsr setExpansionCaller - sei ; prevent interrupts while in aux mem - sta setAuxZP - sta setAuxWr - lda setLcRW+lcBank2 ; reloc to bank 2 in aux mem (unused by anything else) - lda setLcRW+lcBank2 ; second access to make it read/write - jsr callExpander ; was copied from .callIt to $100 at init time - sta clrAuxWr - sta clrAuxZP - cli ; interrupts ok after we get back from aux - pha ; save new seg length - txa - pha - ; Now truncate the main segment of the expander, freeing up the - ; split space for textures and other resources. - lda #FREE_MEMORY - jsr .memexp - lda #SET_MEM_TARGET - jsr .memexp - pla - tay - pla - tax - lda #REQUEST_MEMORY - jmp auxLoader -.memexp ldx #expandVec - jmp auxLoader - ; Following are log/pow lookup tables. For speed, align them on a page boundary. !align 255,0