30 December 2021, 09:39 | #1 |
Prototron
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 411
|
Separate title screen from main game
Hi folks,
I'm in the final stages of doing my ASM written game demo and I'm trying to clean things up. At the moment I have a title screen which is just a loop displaying the bitmap logo graphic and bitmap font text, and this loop is the first thing in the program. It then jumps to the main game init and then finally the main loop when I push a button on the gamepad. The problem is that it's all run from essentially the same program, and obviously I don't want nor need the title screen code or its assets taking up memory when the main game starts. So, I want to find a way to separate them both, but unfortunately I can't seem to think of a way to do this. None of the tutorials I've watched cover things like this either. I'm defining spaces for assets so that stuff can be loaded in from disk later on, but even if I clear the spaces which hold the title screen graphics, won't that space still be defined and reserved, and ergo - unusable? As usual, there's next to no information on this out there, so I really don't know what to do. Is it possible to have it in a completely different include file, but using its own sections for code and data? Again, how would this effectively be disposed on and re-loaded when needed? So many questions! Any info would be great, thanks. |
30 December 2021, 10:19 | #2 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,039
|
One way to do it... Put your title screen code+data into separate sections (eg. section 1 title code, section 2 title data, section 3 main code, section 4 main data, etc).
When the title loop is done, unlink sections 3+ from the segment list and create a new process with section 3 as the start segment and simply return via rts, the OS will then deallocate first 2 sections. There is one more thing you have to do before you exit your main code, instead of the final rts you have to jump to UnloadSegment() to free the rest of your sections because the segment list passed to CreateProcess() is not freed automatically. |
30 December 2021, 11:19 | #3 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,215
|
Sounds like a perfect example for what overlayed segments are good for. It requires special linking and an overload loader, and some knowledge, but with that, only the required segments are in memory and the Os loader will only pull in what is needed.
http://aminet.net/docs/misc/Overlay.lha |
30 December 2021, 12:53 | #4 |
Prototron
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 411
|
Great info, thanks!
I had never heard of segment lists before, so that's helpful to explore. Is it just for OS use? I'm turning the OS off in the init, so would that make a difference? |
30 December 2021, 13:23 | #5 |
Registered User
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
|
Yes, I feel your pain a bit here.
The way I've done it is I simply keep a track of all of my memory allocations and their sizes, I can also tag them. I then have a routine which can deallocate all the allocations within the same program or just some of them by tag. Geezer |
30 December 2021, 14:06 | #6 | |
Prototron
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 411
|
Quote:
How do you actually de-allocate a reserved block of memory though? I've looked for something like uds.b (un-define space) or anything which will just remove the memory reservation, but once its defined it seems to stay there. |
|
30 December 2021, 14:21 | #7 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,039
|
It's how OS is tracking sections so they can be freed when a program exits. It's public/documented knowledge, and quite simple to do (~10 lines of code). For example:
Code:
_LVOCreateProc EQU -138 _LVOUnLoadSeg EQU -156 SECTION LoaderCode,CODE Loader jsr WaitLMB ; OPEN DOS LIBRARY HERE (i'm too lazy :) ) move.l a6,DosBase ; RELEVANT BEGIN lea LastLoaderSection-4,a0 move.l #ProcName,d1 moveq #0,d2 ; priority move.l (a0),d3 ; seglist bptr clr.l (a0) ; unlink main sections move.l #4096,d4 ; stack size jsr _LVOCreateProc(a6) ; RELEVANT END moveq #0,d0 rts SECTION LoaderData,DATA LastLoaderSection ProcName DC.B 'fubar',0 EVEN DS.B 64*1024 SECTION MainCode,CODE FirstMainSection bsr.b WaitLMB move.l DosBase,a6 ; RELEVANT BEGIN move.l #FirstMainSection-4,d1 lsr.l #2,d1 ; convert to bptr jmp _LVOUnLoadSeg(a6) ; program exit ; RELEVANT END WaitLMB .W1 btst #6,$bfe001 bne.b .W1 .W2 btst #6,$bfe001 beq.b .W2 rts SECTION MainData,DATA DosBase DC.L 0 DS.B 256*1024 Last edited by a/b; 30 December 2021 at 17:43. Reason: missed 2 lines with new syntax |
30 December 2021, 15:36 | #8 | |
Registered User
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
|
Quote:
Use WinUAE's TM command to track your memory allocations. |
|
30 December 2021, 20:56 | #9 |
Prototron
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 411
|
Excellent! Thanks for the advice guys. Plenty to chew on here.
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to assign two separate game directories | amigappc | project.ClassicWB | 2 | 24 December 2015 14:49 |
OS 3.5 main installation crashes at license screen | LeftyFPB | support.Other | 2 | 13 February 2015 05:53 |
Cannon Fodder 1 & 2 - both game wont start past title screen? | Ford Grunt | support.Games | 35 | 12 August 2011 15:44 |
Title screen music required, can anyone help? | CaptainNow | request.Music | 5 | 15 July 2011 20:45 |
|
|