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 > swi 05

#23431 - MothAttack - Mon Jul 12, 2004 6:11 pm

I'm having trouble with swi 05. Imagine the following very, very simple program (written for clarity, mind you):

Code:
@ load up an interrupt handler
ldr r0, =0x03007ffc
ldr r1, =my_interrupt_handler
str r1, [r0]

@ enable vblank interrupt
ldr r0, =0x04000200
mov r1, #1
strh r1, [r0]

@ enable master interrupt
ldr r0, =0x04000208
mov r1, #1
strh r1, [r0]

swi 0x00050000

<do something noticeable, like plotting a pixel or something>


If I run this, nothing noticeable happens. In fact, my_interrupt_handler never gets called. It seems that the vblank interrupt doesn't occur. If I enable a timer, for example, then my_interrupt_handler will get called. Is there something else I have to do to get vblanks to cause interrupts? Or to get vblanks to occur at all? (Enabling a video mode doesn't help.) Or is this just an emulator problem? (I'm using VisualboyAdvance.)



EDIT:
Oops... Never mind. There is something else I have to do...namely:

Code:
@ enable vblank interrupt in a different place
ldr r0, =0x04000004
mov r1, #8
strh r1, [r0]


So, there you go. Well, I'll leave this post here for others to learn from. (Yeah, that's it...) Any moderators can delete it if they want...

#25428 - [mRg] - Sun Aug 22, 2004 8:17 pm

Could someone post (or link to) a full example of how to use swi 5 in asm so I can replace my current Vblank routine with a nice powersaving one :)

I understand how to set up the interupts (from the exmaple by MothAttack) and why they need to be set up but I am unsure what code needs to be in the interrupt handler.

Am I branching to my main routine or do I just need to pass some data back to say that the interrupt has been handled (I tried the example on gbaguys asm tutorial but its not too clear) if so how do I do that :)

Just reading the FAQ on Devrs do I need to save any registers Im using before I call the SWI or is that for soemthing else?

Sorry to sound a bit thick but any help or examples to clarify this would be greatly received.

TIA

[mRg]

#25439 - Cearn - Sun Aug 22, 2004 10:46 pm

In addition to aknowledging the interrupt in REG_IF, the BIOS routines also require you to set that bit in the BIOS version of that register at location 0x03fffff8. See http://forum.gbadev.org/viewtopic.php?t=1544 for a little more detail. There are a number of similar threads on this all around the forum too. To see how this could be set up in ASM, get libgba from www.devkit.tk.

#25490 - [mRg] - Tue Aug 24, 2004 1:10 am

Magic !

Thats fixed it .. thanks Cearn :)

My code for peoples future reference ...

Code:


@--------------------------------------------------------
@ Interrupt setup
@--------------------------------------------------------   

         ldr r0, =REG_IME                       @ enable master interrupt
         mov r1, #INT_ENABLE
         strh r1, [r0]
         
         ldr r0, =REG_INTADDR                     @ load up an interrupt handler
         ldr r1, =intr_handler
         str r1, [r0]

         ldr r0, =REG_IE                              @ enable vblank
         ldr r1, =INT_VBLANK
         strh r1, [r0]
      
         ldr r0, =REG_DISPSTAT                     @ enable vblank interrupt
         mov r1, #STAT_VBLANK
         strh r1, [r0]

@--------------------------------------------------------
@ Main infinite loop
@--------------------------------------------------------         

infin:
         
         swi 0x50000
         
         b infin                                                  @ BRANCH - infinite loop

@--------------------------------------------------------
@ End main program !
@--------------------------------------------------------

@--------------------------------------------------------
@ Interupt Handler
@--------------------------------------------------------

intr_handler:

         ldr r0, =REG_IME                 @ disable master interrupt
         mov r1, #0
         strh r1, [r0]
       
          ldr r2, =0x03fffff8               @ let the bios know that vblank occurred
 
          ldr r0, =REG_IF                     @ Load in current flag
          ldrh r1, [r0]
          
         cmp r1, #INT_VBLANK               @ Check if its vblank
          streqh r1, [r2]

         ldr r0, =REG_IF                     @ Unset the flag by writing a 1 to that bit
         mov r1, #1
         strh r1, [r0]

         ldr r0, =REG_IME                 @ re-enable master interrupt
         mov r1, #1
         strh r1, [r0]
         
         bx lr



Now i just gotta get this bloody mod player to work :)

#25500 - dagamer34 - Tue Aug 24, 2004 3:44 am

In the future, you should take a look at the FAQ. I actually had to get tepples to add this problem to the FAQ recently. I also had a problem like this.

It makes me wonder, does ANYONE actually look at the FAQ before asking a question? I'll admit that I usually don't... :)
_________________
Little kids and Playstation 2's don't mix. :(

#25515 - [mRg] - Tue Aug 24, 2004 9:08 am

True .. I should have read the FAQ (just found it ! .. I heard people talk of the fabled FAQ before and I thought it was the one that links from the top of the page and had thought 'whats's the use of this for coding ?')

In my defence there wasnt a beginners section last time I was on this board, so it wasnt the first place I looked :?) (no excuse I know .. but ill know for next time !)

Thanks for not flaming me for being a blind l4m0r :?)

[mRg]