Jump to content
Tuts 4 You

Chiptune_player_libraries


Ufo-Pu55y

Recommended Posts

Ufo-Pu55y
mfmplayer=modified/ripped MiniFMOD
Ya, I've read about it, too :)

I like mfmplayer more, coz I can read out pattern+position with one call -

with MiniFMOD I need two calls.

Anyway I didn't understand a s* in the C++ source for MiniFMOD... I mean how to initialize :(

So I went over to convert the MASM-Init of MFMPlayer into C++.

That's, what I've got so far:

unsigned long	nMusicSize;
LPVOID pMusic;
HRSRC rec;
HGLOBAL handle;
void *nMusicData;
// Initialize MiniFMOD
rec = FindResource(NULL, MAKEINTRESOURCE(ID_Chiptune), RT_RCDATA);
nMusicSize = SizeofResource(NULL, rec);
handle = LoadResource(NULL, rec);
nMusicData = LockResource(handle);
pMusic = GlobalAlloc(GPTR, nMusicSize+(sizeof nMusicSize));

Which is taken from:

hInstance					HINSTANCE	?
nMusicSize DWORD ?
pMusic LPVOID ?
; Initialize MFMPLAYER:
invoke FindResource, hInstance, ID_Chiptune, RT_RCDATA
push eax
invoke SizeofResource, hInstance, eax
mov nMusicSize, eax
pop eax
invoke LoadResource, hInstance, eax
invoke LockResource, eax
mov esi, eax
mov eax, nMusicSize
add eax, SIZEOF nMusicSize
invoke GlobalAlloc, GPTR, eax
mov pMusic, eax
mov ecx, nMusicSize
mov dword ptr [eax], ecx
add eax, SIZEOF nMusicSize
mov edi, eax
rep movsb

But I've really got no clue, how to convert the last 5 MASM lines into C++ :(

I mean how to pump the nMusicData into the allocated memory.

Please, could somebody help me out ? :cc_surrender:

It's for a good purpose...

Edited by Ufo-Pu55y
Link to comment

first learn basics of c++ then convert, all you need is pointers and type casting, copy you can do 2 ways, move bytes with for or use memcpy. when you declare char *mymusic you need to put in 1st 4 bytes size of xm, then 4 bytes later copy xm.

Link to comment
Ufo-Pu55y
Ah, thanks, yamraaj !!! I'm still trying everything what comes on my way !

But it's again (as always) kinda long winded approach with sh!tloads of .Cs and .Hs...

Actually converting my whole MASM source into C++ was like a fingersnip, until

I went to include mfmplayer/minifmod. But the init of it turned into hell for me... :confused:

I didn't intend to go C++1337 - I just thought, that my tutorial would be more useful,

if it comes with C++ sources, too... for the ones not familiar with MASM.

I'm still yearning for a solid C++ coder, who could kick my a*

and just tell me how to f* get the XM into the allocated memory :dunno:

Without any theory - just a handful of concrete lines of code...

I'm already going nut with all these stars and parenthesis...

Greets

Edited by Ufo-Pu55y
Link to comment

Yeh, I think pointers are one of the biggest problems beginners encounter when learning C++...

But once you got used to it (try coding some app that manipulates code or the PE header) it's easy...

Link to comment

pointers are easy, real mess is type casting, something defined as char and you need to write word,byte,dword also alone calculate displacement, and according to type, try to find on next how to write dword to char type at position 3.

none of tuts explain how to do it and its simplest thing in asm. thats why i prefer asm, fast, complex, small and only limitation is cpu and knowledge not syntax

Link to comment
Ufo-Pu55y
pointers are easy, real mess is type casting, something defined as char and you need to write word,byte,dword also alone calculate displacement, and according to type, try to find on next how to write dword to char type at position 3.

none of tuts explain how to do it and its simplest thing in asm. thats why i prefer asm, fast, complex, small and only limitation is cpu and knowledge not syntax

You're mentioning exactly the problem, which I had the last hours :crazy:

I had to write a 'long' into an array of 'chars'. I was reading my a* off in google and ebooks,

but NOTHING about that... :sick:

On the other side, it's ok, I always wanted to know some C++.

For example I didn't expect that I can even XOR or SHL/SHR in C++.

So I went like this:

nMusicData = LockResource(handle);
char* MusicMem = 0;
MusicMem = new char[nMusicSize+(sizeof nMusicSize)];
long SizeConv = nMusicSize;
MusicMem[0] = SizeConv;
SizeConv >>= 8;
MusicMem[1] = SizeConv;
SizeConv >>= 8;
MusicMem[2] = SizeConv;
SizeConv >>= 8;
MusicMem[3] = SizeConv;
MusicMem += 4;
memcpy(MusicMem, nMusicData, nMusicSize);
mod = FMUSIC_LoadSong(MusicMem, NULL);

Anyway I've got an exception after calling FMUSIC_LoadSong... :/

(... reading location 0x00000000) ???

Gotta try on

Link to comment

Correct me if Im wrong, wouldnt long to char array be like this:

char Monkey[4];

long Whatever;

char * MonkeyPtr = &Monkey;

*(long *)MonkeyPtr = Whatever;

I believe this one works as well:

*(long *)Monkey = Whatever;

Pointers can be used as arrays too, if im not totally mistaken:

char * Blub = &Somewhere;

Blub[1] is similar to *(Blub+1))

"write dword to char type at position 3"

I think writing dword to dword pointer + 3 is harder :/

DwordPtr+1 is not DwordPtr + 1 byte but DwordPtr + 4 bytes (dword)

Thats like increasing an array (DwordPtr and i++)

Should be like this:

*(DWORD *)((DWORD)DwordPtr+3) = Whatever;

You gotta make the pointer a normal dword, add 3 to it (so it doesnt increase some array index of the pointer) and convert it back to a pointer..

Ugly but it should work :D

Edited by Killboy
Link to comment
Ufo-Pu55y

@Killboy: Thanks for clearing that up :)

But the time of suffering has ended some mins ago...

I've found a link for a template in an ARTeam topic:

_http://jardinezchezjb.free.fr/tools/forumcrack-spaceship-template.zip

I hope it's ok to attach it, too (coz it doesn't look like it lasts very long) :

forumcrack_spaceship_template.zip

1) It uses MiniFMOD, the way I was interested in !!!

2) It has the f* greatest AboutBox, I've ever seen in my life !i!i!i! :thumbsup::thumbsup: :thumbsup:

*taking a bow to jB/FFF* :worthy:

Greets

Link to comment
  • 2 months later...

@UFO-Pu55y:

I am searching also for a way to implement MOD or XM music into my project.

I am using a VB6, and have tried uFMOD but was not able to make it run on my system :(

If you have any ideal or sugestion how to add background music to my VB6 project it would be greately apreciated!

Link to comment
I am using a VB6, and have tried uFMOD but was not able to make it run on my system :(

Um.. did u try it like this ?

VB_ufmod.rar

Greets

Yes, exactly that i tried.

I get msgbox "uFMOD not found" - check txt for info..

I also folowed this instruction:

WARNING!

uFMOD currently supports ONLY Microsoft Visual Basic 6. Neither older releases,

nor .NET are supported!

So, you want to use uFMOD in your VB6 application? You'll need to complete the

following steps:

1. You need to include uF_vb.bas (WINMM version) or DSuF_vb.bas (DirectX) into

your project. Do not rename this file. Do not modify it's contents. Place it

into the main directory of your project. Place ufmod.lib (WINMM version)

or dsufmod.lib (DirectX) into the same location as uF_vb.bas or DSuF_vb.bas.

Copy the DirectSound type library dsound.tlb to the same location when using

the DirectX version.

2. Target type should be EXE.

3. Find the directory where VB6.EXE is installed (i.e. \Program Files\Microsoft

Visual Studio\VB98\). Rename LINK.EXE to LNK.EXE. Copy the included link.exe

file into that directory. Full source code is included. The modified linker

is able to build any application: with or without uFMOD. Though, you may

restore the original linker from LNK.EXE whenever you want to.

I dont know hat i'm doing wrong :(

EDIT: I just noticed that it does not work when you try to run the project, but when it gets compiled as exe - then it runs ok!

Next problem i now have is i dont know how to buidl a valid .RES file?!

(i tried syamtech Resource studio, but it creates unrecognizable .res file)

I also tried to remove mini.res from original example (the one that works when compiled) and replace it with mine .xm file (using visual studio resurce editor), changed name and ID to mach original, but guess what!? - it does not make any sound at all :(

Edited by ChupaChu
Link to comment
  • 3 weeks later...

Vb6 comes with a resource editor, it just needs to be included , you do this by going to add-ins, then add-in manager and choosing the resource editor from there,

Link to comment
  • 7 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...