English Amiga Board


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

 
 
Thread Tools
Old 14 January 2021, 15:50   #21
Akira
Black Lives Matter

Akira's Avatar
 
Join Date: May 2001
Location: New York
Posts: 19,475
Quote:
Originally Posted by idrougge View Post
Unfortunately you can’t specify that something must be INCBINed into chip memory, so the data must be copied.
But no one is incbin'ing data here, the module is loaded using LoadModule or as a Bank.
Could you just redirect a sound object to this data, with a pointer, then?
I guess if the sound data is in Fast RAM, that would be a problem.
Akira is offline  
Old 14 January 2021, 17:28   #22
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 5,103
Ah yeah, if you load it as a bank you can specify which memory type you want. I assume LoadModule would automatically load it into chip RAM so it can be played, but might be worth checking, just in case.
Daedalus is offline  
Old 14 January 2021, 18:35   #23
Akira
Black Lives Matter

Akira's Avatar
 
Join Date: May 2001
Location: New York
Posts: 19,475
I meant here's nothing wrong with using Fast RAM if you have it, but I am aiming for the absolute lowest denominator.

I guess memory management will be something I have to get into at some point, scary.
Akira is offline  
Old 18 January 2021, 19:03   #24
Akira
Black Lives Matter

Akira's Avatar
 
Join Date: May 2001
Location: New York
Posts: 19,475
Quote:
Originally Posted by Daedalus View Post
If you're just loading the file and interpreting it yourself, there's no need to load it with a dedicated library. Alternatively, if you do use e.g. LoadModule, you can get the location of the Blitz object (which then contains the module address) with the Addr Module(0) function.
I don't fully understand how to use this.
There's a page in Amigacoding defining the Blitz objects, and the module object's _mt_data sub-item would have the module data.

How would I traverse through this data, for example with some "For" statement reading every byte straight?

I'm sorry if this is super newbie, but I am not sure I understand how to refer to t he module object loaded in memory exactly. For the time being, finding it in RAM and reading the module's name (which is at offset 0 and is 20 bytes long) would be enough for me to understand how to do the rest.

[edit] Well this is getting complicated fast... I don't think I can have a pointer inside a newtype definition, can I? I really don't know how to create a copy of the actual sample data, there's no variable that can hold that that I can think of, so the best choice here would be to point at the sample data already in memory thanks to LoadModule, but I wanted to create an array of sample objects where the actual sample data was one of the elements. I guess I cannot.

SoundData pushes a byte of info at a time into a sound object, so I guess I would have to make consecutive SoundData calls until "sample length" is reached, starting from the sample address in memory.
It would be easier if I could, somehow, just redirect the sound data part of a sound object to the memory location where there's already sound data, but I don't know how I could do that, feel like it has to do with the sound data type, but don't really know how I can access it, as I said before.

My mind is getting really mushy with all this

[edit 2] aghhh i am in tears haha. Sorry EAb to use you as my rubber ducky debug

So having this in mind:
Code:
 _data.l             ;00: NULL if no sound present, else pointer to sound data
 _period.w           ;04: period of sound
 _length.w           ;06: length, in words, of sound data
 _loop.l             ;08: repeat to loop position of sound
 _looplength.w       ;12: length of looping section, in words
 _pad.b[2]           ;14:
The Sound object already has a pointer to sound data and not actual sound data. So if I could change that to point instead to wherever LoadModule has put the sample, I should be done.

Assuming I am dealing with a sound that Initialized as Sound 1, how can I access this _data parameter of that sound object when I have no variable name for it? this is the part that confuses me.

Last edited by Akira; 18 January 2021 at 23:31.
Akira is offline  
Old 19 January 2021, 14:48   #25
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 5,103
Quote:
Originally Posted by Akira View Post
I don't fully understand how to use this.
There's a page in Amigacoding defining the Blitz objects, and the module object's _mt_data sub-item would have the module data.
Yep, that value should be the address of the start of the module data in memory, or else 0 if the data wasn't loaded. It's very important to check that it's not 0 before trying to do anything with the data.

Quote:
How would I traverse through this data, for example with some "For" statement reading every byte straight?
Basically, yes. I'm not particularly familiar with the format, so it's about writing code to go through the data as necessary to find the part you need. Most likely the file format will contain offsets to particular data chunks, so you can jump to the locations directly instead of trawling through every byte along the way.

Quote:
I'm sorry if this is super newbie, but I am not sure I understand how to refer to t he module object loaded in memory exactly. For the time being, finding it in RAM and reading the module's name (which is at offset 0 and is 20 bytes long) would be enough for me to understand how to do the rest.
You need to set up a suitable Newtype and assign it to point at the address of the module. So something like:

Code:
*moduleData.module = Addr Module(0)
Then you can access the fields of the Newtype to get the addresses. To read a string from memory if it's null terminated, you can use Peek$():

Code:
offset.l = 0
If moduleData
  NPrint Peek$(*moduleData\_mt_data + offset)
End If
If it's a fixed length however, it might be better to use a loop:
Code:
offset.l = 0
name$ = ""
If moduleData
  If peek.l(*moduleData\_length) > 20
  For i.l = 1 to 20
    name$ + Peek.b(*moduleData\_mt_data + offset + i)
  Next i
  NPrint name$
  End If
End If
This should give you the title - the first 20 characters located at offset 0.

Quote:
[edit] Well this is getting complicated fast... I don't think I can have a pointer inside a newtype definition, can I?
You can, but it's treated as a long value rather than an actual pointer type, so to access it you need to do Peek/Poking or maybe assign a pointer to the address if needed.

Quote:
I really don't know how to create a copy of the actual sample data, there's no variable that can hold that that I can think of, so the best choice here would be to point at the sample data already in memory thanks to LoadModule, but I wanted to create an array of sample objects where the actual sample data was one of the elements. I guess I cannot.
Actually copying data is simply a matter of reading a byte, then writing it to a new location. The more important part though is ensuring that you're actually supposed to write to that location, and that's usually done by allocating memory, either through the standard alloc routines or the Blitz InitBank command.

Quote:
SoundData pushes a byte of info at a time into a sound object, so I guess I would have to make consecutive SoundData calls until "sample length" is reached, starting from the sample address in memory.
That's a perfectly reasonable approach, basically doing the same as above.

Quote:
It would be easier if I could, somehow, just redirect the sound data part of a sound object to the memory location where there's already sound data, but I don't know how I could do that, feel like it has to do with the sound data type, but don't really know how I can access it, as I said before.
You're on the right track here:
So having this in mind:
Code:
 _data.l             ;00: NULL if no sound present, else pointer to sound data
 _period.w           ;04: period of sound
 _length.w           ;06: length, in words, of sound data
 _loop.l             ;08: repeat to loop position of sound
 _looplength.w       ;12: length of looping section, in words
 _pad.b[2]           ;14:
The Sound object already has a pointer to sound data and not actual sound data. So if I could change that to point instead to wherever LoadModule has put the sample, I should be done.

Assuming I am dealing with a sound that Initialized as Sound 1, how can I access this _data parameter of that sound object when I have no variable name for it? this is the part that confuses me.[/QUOTE]
You create a sound Newtype pointer to the Sound object, and then the fields will point to the values you want:

Code:
*mySound.sound = Addr Sound(1) ; mySound is now a pointer to that object
If *mySound ; Make sure it exists
  *mySound\_data = address_of_new_data.l
End If
Never skip the check to make sure it exists. If, for any reason the sound object doesn't exist (didn't load, not enough free chip RAM to initialise etc.), you'll most likely get an instant guru when you try to modify it.
Daedalus is offline  
Old 19 January 2021, 16:13   #26
Akira
Black Lives Matter

Akira's Avatar
 
Join Date: May 2001
Location: New York
Posts: 19,475
Man you're a godsend, thanks for helping out with this!
Let's skip to the part that seems relevant as a solution, after all my mumbling.

Quote:
Originally Posted by Daedalus View Post
You create a sound Newtype pointer to the Sound object, and then the fields will point to the values you want:

Code:
*mySound.sound = Addr Sound(1) ; mySound is now a pointer to that object
If *mySound ; Make sure it exists
  *mySound\_data = address_of_new_data.l
End If
Never skip the check to make sure it exists. If, for any reason the sound object doesn't exist (didn't load, not enough free chip RAM to initialise etc.), you'll most likely get an instant guru when you try to modify it.
So that's how you do it!
And if I read you correctly in the other thread, there's something I need to include here to make sure it works?

I feel bad asking all this because it feels like it's buried somewhere in the shit manual and I cannot find it. I searched several pages for the "Addr" command and was not able to find it, for example. Also no explanation on how to create these type of objects, how to work with pointers, etc... just a really bad manual.
Akira is offline  
Old 19 January 2021, 16:27   #27
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 5,103
Quote:
Originally Posted by Akira View Post
So that's how you do it!
And if I read you correctly in the other thread, there's something I need to include here to make sure it works?
Yep, the bb2objtypes.res file needs to be added to the compiler settings (in Blitz 2 you'll need the full path, usually Blitz2:bb2objtypes.res) so you can access the definitions of all the Blitz object structures.

Quote:
I feel bad asking all this because it feels like it's buried somewhere in the shit manual and I cannot find it. I searched several pages for the "Addr" command and was not able to find it, for example. Also no explanation on how to create these type of objects, how to work with pointers, etc... just a really bad manual.
Yeah, it's not great, but you'll find it in the chapter on compiler directives and object handling, alongside Free, Use etc. Pointers are only very briefly covered in the manual, some decent examples would definitely be of help there! It's an area that I want to add some detail about on AmigaCoding... Some day
Daedalus is offline  
Old 19 January 2021, 17:07   #28
Akira
Black Lives Matter

Akira's Avatar
 
Join Date: May 2001
Location: New York
Posts: 19,475
Quote:
Originally Posted by Daedalus View Post
Yeah, it's not great, but you'll find it in the chapter on compiler directives and object handling, alongside Free, Use etc. Pointers are only very briefly covered in the manual, some decent examples would definitely be of help there! It's an area that I want to add some detail about on AmigaCoding... Some day
I downloaded that UBB thing now, the manual looks really good, thanks for that pointer too! And I'll be waiting for your pointer tips on Amigacoding, meanwhile, I'll have to be bothering you here ;P

I need to recollect my thoughts now and put all t his new knowledge to use. As soon as we're talking pointers and stuff, I am far more in my game than I was before, so hopefully I can make this work.

Thanks again to you and idrougge, you will be heavily credited in whatever I make :P
Akira is offline  
Old 19 January 2021, 17:14   #29
Bren McGuire
Registered User

Bren McGuire's Avatar
 
Join Date: Nov 2019
Location: Croydon
Posts: 144
jesus I leave a few days and this thread blew up, thanks to all for the input, I think I can work form this point on in a solution to my problem but I don't really understand pointers and all that, must learn more.
Bren McGuire is offline  
Old 12 February 2021, 00:39   #30
Akira
Black Lives Matter

Akira's Avatar
 
Join Date: May 2001
Location: New York
Posts: 19,475
I'm back on this! Question:

Quote:
Originally Posted by Daedalus View Post
Yep, the bb2objtypes.res file needs to be added to the compiler settings (in Blitz 2 you'll need the full path, usually Blitz2:bb2objtypes.res) so you can access the definitions of all the Blitz object structures.
I cannot find this option. This is all I see:



Also how do I define these newtypes? Do I repeat the structure of what I posted above? Do they have to have the same names as the BB objects?
Attached Thumbnails
Click image for larger version

Name:	013.png
Views:	83
Size:	6.1 KB
ID:	70875  

Last edited by Akira; 12 February 2021 at 00:49.
Akira is offline  
Old 12 February 2021, 10:55   #31
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 5,103
You need to enter Blitzlibs:amigalibs.res in the right hand box at the bottom that's labelled Resident. (Apologies for the incorrect path in my example...)

As for defining the newtypes, the extension of the name (the .sound bit) defines the Newtype, so you have to use that when setting it up. And it's case sensitive, so it has to be exactly as listed, case, underscores and all. Field names (the \_data bit) have to match what's listed too. But the main part of the name can be any valid variable name.
Daedalus is offline  
Old 12 February 2021, 15:58   #32
Akira
Black Lives Matter

Akira's Avatar
 
Join Date: May 2001
Location: New York
Posts: 19,475
Quote:
Originally Posted by Daedalus View Post
You need to enter Blitzlibs:amigalibs.res in the right hand box at the bottom tha's labelled Resident. (Apologies for the incorrect path in my example...).
god damn I didn't even know that was a text field... hate this interface.. thanks again boss! Let's see how this goes.

So to define these object newtypes, should I do something like this, for example, with the sound object:

Code:
NEWTYPE .sound
     _data.l
     _period.w
     _length.w
     _loop.l
     _looplength.w
     _pad.b[2]
End NEWTYPE
?
Akira is offline  
Old 12 February 2021, 17:45   #33
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 5,103
No, you don't need to do that. All those types are already defined in the resident file. You can just used them directly in your code then, from my earlier example:

Code:
*mySound.sound = Addr Sound(1) ; mySound is now a pointer to that object
The pointer mySound points to the .sound structure of that sound object now, and you can access the fields without having to define the Newtype yourself.
Daedalus is offline  
Old 15 February 2021, 16:24   #34
Zener
Registered User
Zener's Avatar
 
Join Date: Jan 2009
Location: Barcelona / Spain
Posts: 318
You can try using XBciatrackerLib library, it has a lot of useful commands

http://aminet.net/package/dev/blitz/CIATrkrLib.lha

It is probably inside your blitz distribution already
Zener is offline  
Old 24 February 2021, 00:00   #35
Akira
Black Lives Matter

Akira's Avatar
 
Join Date: May 2001
Location: New York
Posts: 19,475
Quote:
Originally Posted by Daedalus View Post
You need to enter Blitzlibs:amigalibs.res in the right hand box at the bottom that's labelled Resident. (Apologies for the incorrect path in my example...).
OK I gave all this a try and I am hitting a weird wall.
First, I included what was necessary (which was indeed bb2objtypes.res as your first suggested, not amigalibs.res), and now I am getting a "syntax error", no idea why, on the line highlighted in bold:
Code:
Statement SetName {} 
	SHARED modName
	SHARED modulePointer
	offset.l = 0
	tempString$ = ""
	If modulePointer
		For i.l = 1 to 20
			tempString$ + Peek.b (*modulePointer\_mt_data + offset + i)
		Next i
	End If
	packName=tempString$
End Statement

Statement ModuleLoading {filename.s}
	SHARED modulePointer
	LoadModule #PROTRACKERMOD,filename
	*modulePointer = Addr Module(0)
	SetName {}
End Statement
I skipped the part where you did:
Code:
If peek.l(*moduleData\_length) > 20
because I didn't even understand what it was for. moduleData\_length will always be >20 (unless I am trying to load a turd that isn't a module :P)

Any ideas?

Last edited by Akira; 24 February 2021 at 00:05.
Akira is offline  
Old 24 February 2021, 01:12   #36
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 5,103
Quote:
Originally Posted by Akira View Post
and now I am getting a "syntax error", no idea why, on the line highlighted in bold:
Code:
tempString$ + Peek.b (*modulePointer\_mt_data + offset + i)
Ugh... Might be my fault (again), typing from memory in a hurry. Try something like this instead:
Code:
tempString$ + chr$(Peek.b (*modulePointer\_mt_data + offset + i))
Quote:
I skipped the part where you did:
Code:
If peek.l(*moduleData\_length) > 20
because I didn't even understand what it was for. moduleData\_length will always be >20 (unless I am trying to load a turd that isn't a module :P)
Yeah, it *should* always be greater than 20, but I tend to have lots of safety checks whenever doing anything directly accessing memory, because there's always a chance the file can't be loaded, giving you a length less than 20, and thus accessing memory that doesn't belong to you. I've been caught out by that sort of thing before, but it should work fine regardless.
Daedalus is offline  
Old 24 February 2021, 01:59   #37
Akira
Black Lives Matter

Akira's Avatar
 
Join Date: May 2001
Location: New York
Posts: 19,475
Quote:
Originally Posted by Daedalus View Post
Ugh... Might be my fault (again), typing from memory in a hurry. Try something like this instead:
Code:
tempString$ + chr$(Peek.b (*modulePointer\_mt_data + offset + i))
I'm still getting an error here. i'm gonna have a proper look in two days, by reading the damn manual again.
_mt_data is itself a pointer, this looks like a nested pointer, is that even possible? Should I instead do
Code:
modulePointer/_mt_data
without the asterisk?

This looks really complicated :/

Quote:
Yeah, it *should* always be greater than 20, but I tend to have lots of safety checks whenever doing anything directly accessing memory
i'm going to bother with all the safety checks later, will not forget for sure. Checking if the file loaded correctly is indeed a great point but at this moment I don't really need it, that's a whole bag of chips I have to eat later when I include file functions :P


Quote:
Originally Posted by Zener View Post
You can try using XBciatrackerLib library, it has a lot of useful commands

http://aminet.net/package/dev/blitz/CIATrkrLib.lha

It is probably inside your blitz distribution already
I don't want to play a module, so this is useless as is. This would be useful if it had source to look at, but it doesn't have any.
Akira is offline  
Old 24 February 2021, 15:45   #38
Akira
Black Lives Matter

Akira's Avatar
 
Join Date: May 2001
Location: New York
Posts: 19,475
Well I kept thinking about this and am really stuck. Manual has been no help.

What I tried
- trying to do
Code:
myModule.module = 0
modulePointer.l = *myModule\_mt_data
(says I can't do myModule.module. Why?)
- removing the * ?

I'm really confused. Seems like I cannot use the pointer, or that I cannot access the pointer inside of a pointer. If there was a way for me to read _mt_data directly I'd have the address where the MOD actually is and that is all I need.

Maybe this method is just pure garbage and I should load the module as a BANK and deal with it my own way.
Akira is offline  
Old 24 February 2021, 15:56   #39
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 5,103
Yeah, you need the * to make it a pointer. Otherwise it's a variable of type module, which contains lots of sub-fields and can't simply hold an integer like 0. The pointer points to a structure, but is in fact just a longword representing the memory location of that structure, meaning you can assign a number to it. This changes where the code thinks that structure is, so assigning 0 would make it think it's at address 0, and is why checking for null pointers is important. It would likely be an instant hard crash to write values to such a struct.

I'll have to sit down and have a play with that code when I have the time, see if I can figure out what needs to be done.
Daedalus is offline  
Old 24 February 2021, 20:54   #40
Akira
Black Lives Matter

Akira's Avatar
 
Join Date: May 2001
Location: New York
Posts: 19,475
Quote:
Originally Posted by Daedalus View Post
Yeah, you need the * to make it a pointer. Otherwise it's a variable of type module, which contains lots of sub-fields and can't simply hold an integer like 0.
Yeah I did that when it was a pointer. My bad.

I still don't understand how to access the pointer inside the pointer. The problem seems to lie within this. And again if I load the module as a bank, I don't have to deal with this bogus "module" type which all it has is the whole module plus its length.

I only need what's inside "_mt_data" in the module object, so I can traverse it with loops.
Akira 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
Protracker file format, number of samples phx Coders. General 21 02 August 2019 23:45
Blitz Basic 2 and Protracker mods Radertified Coders. Blitz Basic 3 13 September 2018 23:55
Can't Create File error using Protracker 2.3d ViLXDRYAD support.Apps 5 09 December 2016 16:44
Protracker 3.xx Load Sample womagrid support.Apps 3 27 May 2016 07:28
Load Cubase made sample in protracker Brick Nash support.Other 4 26 May 2016 19:28

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 02:07.


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