gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

ASM > Using the soundregisters with asm

#130686 - deepak - Wed Jun 06, 2007 5:26 pm

Hi, Ive been trying to get some sound of my gba, I can't get any sound(probably It's not that hard but It's also hard to figure out what's wrong when you haven't been doing this for that long) and I'm quite sure I would need more code to do it, however; This is how I thaugt it would be written:

Code:

tone:
   mov r0, #0x4000000
   add r0, r0, #80
   mov r1, #10
   str r1, [r0]
   b tone


And also I think someone should ad a newbie section for these kind of questions, in the asm section I meen, I know there is one but it's hard to sort out everything regarding everything else since C++ is as popular as it is.
//Robert[/code]

#130692 - Lick - Wed Jun 06, 2007 6:41 pm

I don't think that register works that way. Try looking on GBATek to see how those sound registers work and perhaps look at the C equivalent of your assembly to see what procedures you're missing.
_________________
http://licklick.wordpress.com

#130703 - tepples - Wed Jun 06, 2007 9:28 pm

If you can't understand GBATEK on the first reading, you could try also reading The Audio Advance.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#130740 - deepak - Thu Jun 07, 2007 10:09 am

Hm... I'm gona look in to it some more, I've programed some basic on the c64, however it seems that this would differ a bit. The problem I see is that it's really hard to get some examplecode width sound, built in asm, everything seems to be written in C/C++. It might seem stupid but this is how I learn. //Robert

#130741 - keldon - Thu Jun 07, 2007 10:21 am

How much ASM and coding experience do you have?

#130751 - Cearn - Thu Jun 07, 2007 1:42 pm

How the hardware works does not depend on the language you use. For example:
Code:
// soundtest in C. Warning: magic numbers to keep line-count low.
int soundtest()
{
    REG_SOUNDCNT_X= 0x0080;       // Main sound turn on!
    REG_SOUNDCNT_L= 0x11FF;     // snd1 on left/right, Vol=15
    REG_SOUNDCNT_H= 0x0002;     // DMG ratio to 100%

    REG_SOUND1CNT_H= 0xF780;    // Vol=15; Tstep=7, 1/2 duty
    REG_SOUND1CNT_X= 0x8123;    // Play sound at rate=0x123

    while(1);
}

and
Code:
@ soundtest in ARM asm for GNU assembler. Again, magic numbers :\
    .text
    .arm
    .align  2
    .global soundtest
soundtest:
    mov     r0, #0x04000000

    @ Main sound turn on!
    mov     r3, #0x0080
    strh    r3, [r0, #0x84]
    @ snd1 on left/right, Vol=15
    ldr     r3,=0x11FF
    strh    r3, [r0, #0x80]
    @ DMG ratio to 100%
    mov     r3, #0x0002
    strh    r3, [r0, #0x82]

    @ Vol=15; Tstep=7, 1/2 duty
    ldr     r3,=0xF780
    strh    r3, [r0, #0x62]
    @ Play sound at rate=0x123
    ldr     r3,=0x8123
    strh    r3, [r0, #0x64]

.Lloop:
    b       .Lloop
are functionally equivalent. All that really matters is that certain bits are set in certain registers. The tutorial and demo code usually use C because that's easier to read than assembly.

Read GBATek, Belogic, tonc and/or Deku's Modplayer tutorial to learn how the the GBA sound hardware works, then use your language of choice to do it.

#130755 - deepak - Thu Jun 07, 2007 2:52 pm

Ah, I see, well I kinda figured that out, that it wasn't too much of a difference I mean.

Not a lot, I made something move around and sound on the nes some time ago but that was quite easy. Also I'm for the moment in to GbaGuys tutorial at patatersoft, all cred to this guy however he is, It's really good.

Thx for all, now I will code and not bother you for some time. Have been thinking of doing some kind of sprite library, kinda like the midi-interface but for sounds, for the gba.
//Robert