View Single Post
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  
 
Page generated in 0.04561 seconds with 11 queries