A.D.A. Amiga Demoscene Archive

        Welcome guest!

  

  

  

log in with SceneID

  

Demos Amiga Demoscene Archive Forum / Coding / What is the correct way to deal with interrupts on amiga?

 

Author Message
rload
Member
#1 - Posted: 3 May 2005 22:41
Reply Quote
I've been having mysterious problems with audio interrupts since my first 4k with sound.. It seems to trigger twice or do other weird stuff. It comes and goes. What is the correct way to write an interrupt handler? What is the correct way to initialize the sound hardware so that I only get one interrupt?

Currently I save regs, clear the INTREQ bits on entering the interrupt and then do stuff and end with rte. The problematic thing is that this double interrupt bug happens only once every lightyear on my own machine. It pops up on other machines though and esp. on UAE..

Anyone have a clue?
dalton
Member
#2 - Posted: 4 May 2005 05:50
Reply Quote
Maybe you could use the amigaos interrupt-handler? I read in the masterpiece "how to code 7" that this is no significant speed loss. You might have to skip forbid/permit then though.

Btw your 4k's work alot better than your demos on my config =)
TheDarkCoder
Member
#3 - Posted: 4 May 2005 08:52
Reply Quote
@rload

we seem to have some kind of telepathic connection!! :-)
As you may remember, months ago I said I was studying carefully the problem of clearing interrupt request. I am about to finish a tutorial on the issue. In few days I'll post it.
Some detail is not yet clear, because of lack of experiments, I really need more tests on 040 CPU boards!!
rload
Member
#4 - Posted: 4 May 2005 12:55
Reply Quote
@Dalton
I've tried to use OS audio interrupts through AddIntServer, but it just crashes all the time. Only thing that seems to work is SetIntVector which is a tad more hardcore, but atleast it doesn't crash.

Looking forward to the "the Dark Coder's interrupt" tutorials :)
TheDarkCoder
Member
#5 - Posted: 4 May 2005 14:20
Reply Quote
@rload

actually the tutorial is on "clearing interrupt request", which is a tricky issue, as you'll see.

Also, you seem to have problems with audio, which is another beast by itself.
Anyway hope it'll help. It is a rather long tutorial, maybe too much :-(
noname
Member
#6 - Posted: 5 May 2005 19:45
Reply Quote
not sure if it helps, but have you tried writing INTREQ twice?
that was the whole fix for p61 to make it work on a4040 and a4060.
rload
Member
#7 - Posted: 5 May 2005 23:23
Reply Quote
yes I've tried that :)
TheDarkCoder
Member
#8 - Posted: 6 May 2005 11:09
Reply Quote
@rload

so I think my tutorial won't help. I think it's an audio related issue
rload
Member
#9 - Posted: 7 May 2005 12:45
Reply Quote
I found some AHI sources that handle audio stuff. I can look through those
TheDarkCoder
Member
#10 - Posted: 9 May 2005 10:10
Reply Quote
@rload post an example on how you use interrupt, maybe I can give a look
rload
Member
#11 - Posted: 11 May 2005 22:38
Reply Quote
lets see..

; Setup audio interrupt for channel 0
move.l 4.w, a6
moveq #AUD0,d0
lea audio_server(pc),a1
jsr _LVOSetIntVector(a6)

; Do some sound channel setup here $dff0a0 and so on

move.w $dff002,d0
bset #15,d0
move.w d0,-(sp) ; save old dmacon
move.w #$7fff, $dff096
move.w #%0000011110000000, $dff09a ; disable audio ints
move.w #%0000011110000000, $dff09c ; clear pending ints
move.w #%1100000010000000, $dff09a ; enable audio int0
move.w #%1000011110001111, $dff096 ; enable audio dma

mainloop
bra mainloop
rts

; The interrupt struct
audio_server
dc.l 0,0
dc.b NT_INTERRUPT, 0
dc.l 0
dc.l 0
dc.l interrupt_routine

; the routine
interrupt_routine
movem.l d0-a6,-(sp)
move.w #%0000000001000000, $dff09c
move.w #%0000000001000000, $dff09c ; double clear thingy

;
; some rewriting of audio channel registers here
;

movem.l (sp)+,d0-a6
rts
rload
Member
#12 - Posted: 11 May 2005 22:39
Reply Quote
do I really have to clear pending ints? anything that can be removed is good :)
TheDarkCoder
Member
#13 - Posted: 12 May 2005 08:53
Reply Quote
If the code you posted was related to any other interrupt, it would be correct.
Audio is a different beast.
One should write a tutorial about using audio on Amiga. I would like to do it, but it is not possible before July!! :-(
So, very quickly, here is an explanation in DMA-mode (non-DMA-mode is different):

1- in the init of your program, before disabeling the audio DMA do the following: kill multitasking (all interrupts), wait for 3 PAL vblank, and only then disable audio DMA

2- now, audio interrupt occurs when the DMA is ready to load a new set of data into audio state machine, NOT when the sound is finished!
so to play just once a sample:

load audio register
turn on DMA
wait for interrupt
load data for next sample (if any)
wait for interrupt
turn off DMA

Strange, isn't it? If you would like to know why it works this way, study carefully the Audio State Machine diagram in the HRM.
If anybody is interested, in a distant future I may write a tutorial... :-)

hope that helps!
Anonymous
Member
#14 - Posted: 12 May 2005 10:35
Reply Quote
in this thread :
http://ada.planet-d.net/forum/index.php?action=vthread&forum=4&topic=4 0

little example of audio interruption
Pezac
Member
#15 - Posted: 12 May 2005 11:15 - Edited
Reply Quote
Hello loady! I was googling around for some info about interrupts and look what I found: a forum discussion about it that was active to date!

I had a different question but I was thinking I could just tell you how I do interrupts as it is now.. Could as well start a new thread about my original question :p

Currently I save regs, clear the INTREQ bits on entering the interrupt and then do stuff and end with rte. The problematic thing is that this double interrupt bug happens only once every lightyear on my own machine. It pops up on other machines though and esp. on UAE..

It's how I do it too, but I write to intreq at the end of the code snippet. So it's:

* save registers
* code
* write to intreq twice
* restore registers
* rte

Does this make any difference at all? Hardware ref doesn't really explain exactly how you should use interrupts.
Anonymous
Member
#16 - Posted: 12 May 2005 15:49
Reply Quote
noname
Member
#17 - Posted: 13 May 2005 18:34
Reply Quote
@rload: i have never done any audio-programming on this level so pardon me if i talk rubbish but shouldn't you quit your interrupt code with "nop" and "rte" rather than "rts" to return from the exception?
rload
Member
#18 - Posted: 13 May 2005 20:49
Reply Quote
I think there is something about exec _LVOSetIntVector system function that makes it right to write rts instead of rte.. It's executed from some system function that does the real rte I think.

 

  Please log in to comment

  

  

  

 

A.D.A. Amiga Demoscene Archive, Version 3.0