English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 14 January 2021, 18:07   #1
Amiga1992
Registered User
 
Join Date: May 2001
Location: ?
Posts: 19,645
Proper way to load files during runtime?

I am now at the point of my current development where I have to load a file during runtime.
For the time being I am not bothering with fetching directories and building a requester, I just want to load, during runtime, a file that is found in the same path as the executable (a music module file).

Here is how the beef of my program sort of looks like:
Code:
; bunch of other stuff done before like loading and defining shapes

BLITZ 

; Functions I want accessed through Blitz
; GO HERE

; Create Display
CreateDisplay #COPPERLIST_MAIN 

; Draw the elements the first time
DrawBackground {#BITMAP_BACKGROUND}
RefreshScreen {True,True,True,True,True,True}

; Blitz mode stuff
BlitzKeys On
BlitzRepeat 50,20
Filter Off

; ------ MAIN LOOP ------ ;
While Joyb(0)=0 

	; Here goes my main loop code
	; HERE
	; main loop code end
	
	VWait 

Wend
; ---- MAIN LOOP END ---- ;
So now I know that I need to go back to Amiga mode to load, and I will be using QAmiga so whatever I blitted on screen remains as is, but how exactly can I do this? Would this work?

Code:
; ------ MAIN LOOP ------ ;
; ------ MAIN LOOP ------ ;
While Joyb(0)=0 

	; Here goes my main loop code
	
	While timeToLoad = -1
		QAmiga
		MyModuleLoadProcedure{"modulename.mod"}
		timeToLoad = 0
		Blitz
	Wend 
	
	; main loop code end
	
	VWait 

Wend
; ---- MAIN LOOP END ---- ;
Also, since this is Amiga mode, I would have to declare my procedure way up, before I initially declared BLITZ the first time, right?

Anyway, just really confused about the order things need to be in at this point. This is worse than Pascal :P
Amiga1992 is offline  
Old 14 January 2021, 20:36   #2
Master484
Registered User
 
Master484's Avatar
 
Join Date: Nov 2015
Location: Vaasa, Finland
Posts: 525
Quote:
Anyway, just really confused about the order things need to be in at this point. This is worse than Pascal :P
The rules of how the BLITZ and AMIGA directives "work" are indeed super confusing, and I have found out that when you put many of these commands in your code, chances are that the whole program will turn into a big mess with Blitz constantly giving you "command only available in XXX mode" errors. There is probably some kind of logic behind it, but no one knows how it works, and the manual doesn't tell.

Therefore these days I always try to use a simple program structure that looks something like this:

Code:
---Beginning---

A long gosub list for all kinds of startup operations
Also gosubs to graphics loaders are here.

The whole program "runs" from this beginning section, from start until end.

Repeat
 Gosub MAINLOOP
Until (ESC pressed = true)

Goto ProgramEnd ; program ends here

---Starup Gosubs---

Variable initialization, Arrays and Bitmap creations, etc.

---Screen Setup---

BLITZ command is given here
InitCoplist etc.

---MAINLOOP---

This too is just a long gosub list 

---Mainloop Gosubs---

Game logic, Blit routines, etc.

---LOADERS---

QAMIGA command is given here.
All loading operations are put under the QAMIGA.

At the end of the loaders BLITZ is given again.

---Program End--- 
Although this is a structure for a program that only uses Gosubs, and doesn't have any Functions or Statements (I never use those, too modern for my coding style ). But the main idea should still work: put all QAMIGA stuff to the very end, and just jump there and back when needed.
Master484 is offline  
Old 14 January 2021, 23:31   #3
Amiga1992
Registered User
 
Join Date: May 2001
Location: ?
Posts: 19,645
Quote:
Originally Posted by Master484 View Post
Although this is a structure for a program that only uses Gosubs, and doesn't have any Functions or Statements (I never use those, too modern for my coding style ). But the main idea should still work: put all QAMIGA stuff to the very end, and just jump there and back when needed.
Yeah that's my problem with what you just posted, there's no way I would use gosubs, gotos, or anything like that, since I learned to code in a more modern way, so my method is Procedureland all over. Also seems like maybe Blitz, being BASIC, is meant to be used your way, so my approach is proving a bit complicated. But so far I have made it work.
From what I see, your way to make things, makes it a bit more complicated to me order wise, because from all I read, it seems like Blitz likes to do things from the top down, and my method works this way, while yours has all the stuff after the main loop.


Anyway, in my example above, basically, what I am doing, is AMIGAing right before calling a procedure that needs the system to be on, and BLITZing back after the program comes back from it. Or at least I think so.

I included code like that into the thing I am working on, and it did not complain, nor crash, so I am *thinking* it worked, but I need more testing.

Last edited by Amiga1992; 15 January 2021 at 00:23.
Amiga1992 is offline  
Old 14 January 2021, 23:43   #4
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
Yeah, file access commands simply can't be used in Blitz, so if it appears to work, then it does Other commands are more subtle, and the issues arise when they're compiled in one position and executed in the other. Your procedure is most likely defined in Amiga mode at the top of your code, so it will contain the correct code for Amiga-mode use. QAmiga and Blitz either side of the call then just make sure the switch happens before and after, but they could equally be in the procedure itself and then wouldn't be required either side of the call.
Daedalus is offline  
Old 14 January 2021, 23:46   #5
Amiga1992
Registered User
 
Join Date: May 2001
Location: ?
Posts: 19,645
Quote:
Originally Posted by Daedalus View Post
Your procedure is most likely defined in Amiga mode at the top of your code, so it will contain the correct code for Amiga-mode use.
Yeah I learned that the HARD way :P

Now I have a section where I do lots of things in Amiga mode, including procedure declaration, then a bunch of other stuff in Blitz mode, including procedures used during Blitz mode.
Will look nice, hopefully, after I separate it in files and include it, but I don't wanna do that until I am finished because tokenization (wish this wasn't needed, I hate it)

By the way
Quote:
Originally Posted by Daedalus View Post
but they could equally be in the procedure itself and then wouldn't be required either side of the call.
That would make the procedures only work when you call them from an already established BLITZ mode. By leaving the mode switches outside of the procedure, I can call the procedure while I am already in Amiga mode without changing anything, or when I am in Blitz mode by doing the necessary switches.

Last edited by Amiga1992; 14 January 2021 at 23:52.
Amiga1992 is offline  
Old 15 January 2021, 10:22   #6
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
Yeah, that flexibility makes sense, fair enough
Daedalus is offline  
Old 15 January 2021, 16:10   #7
Amiga1992
Registered User
 
Join Date: May 2001
Location: ?
Posts: 19,645
OK so now, how am I supposed to know if the file I want to load fits in memory? I rather work to do this kind of check now than have a nightmare later on.
Amiga1992 is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Proper capitalization of CD files? Pheonix support.Apps 2 13 July 2020 12:27
Where to find proper lha files for my tf328? gjb1985 support.Other 5 25 November 2018 22:48
how much .abk files can I load simultaneously Blackgoat Coders. AMOS 9 22 March 2016 18:45
Cannot load some dms files in WinUAE anthonyhead support.WinUAE 18 31 May 2010 05:40
Save/Load State with HDF-Files Frieshansen support.WinUAE 2 10 March 2007 18:09

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 03:49.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.07597 seconds with 15 queries