English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 09 October 2020, 22:00   #1
LastManStanding
Registered User

 
Join Date: Oct 2020
Location: Isbergues / France
Posts: 5
VBL interrupts (VBCC)

Hi guys,

It's been a long time since I did not code for Amiga.
Back into business, I'm making some sort of template for intros, a few years ago I did that in assembly, I'm porting that to C, so far I have bitplanes / copperlist / module replay working, BUT... I'm struggling with VBL interrupts, I always get crashes, and don't find if I do a mistake in setting up the vector, or in the callback function.
I do that "the exact same way" I did in assembly, maybe my keywords are incorrect, maybe I mess with pointers, maybe I'm missing a point... I've reviewed my code 100 times, searched everywhere on Internet, found some (rare) infos, some sources, but I did not find an exact sample / information on that topic : setting up VBL interrupts with VBCC.

My code works, until I put into action the interrupt handler; when I uncomment that part, it crashes quite quickly (guru meditation on some chipmem address). I'm nearly sure the issue is there (maybe at exit ?). When I add some delay (loop), it crashes a little later.

Here is the handler; I presume the __amigainterrupt keyword makes the function putting registers on stack and rte stuff (did not find a lot of info on that on the vbcc docs).

Code:
void __amigainterrupt interruptHandler() {
        ...
	custom.intreq=0x4020; custom.intreq=0x4020;
}
and here you can find the complete code (interrupt handler "registered" in line 102).

Maybe someone has some valuable information or advice to give to me ?
Thanks to information gathered on this forum I already got the ptreplay library working :-)
LastManStanding is offline  
Old 09 October 2020, 22:28   #2
mcgeezer
Registered User

 
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,104
Here's my Level 3 Interrupt handler in assembler.

I don't know C but maybe it will help you.

Code:
; Blitter, Copper and Vertical Blanking Interupt Routine
Level3IntHandler: 
	movem.l	d0-d7/a0-a6,-(a7)
	lea	CHIPBASE,a5
	move.w	INTREQR(a5),d0			
	btst	#INTB_BLIT,d0			
	bne.s	.blitter
	btst	#INTB_VERTB,d0			
	bne.s	.vertb 
	btst	#INTB_COPER,d0			
	bne.s	.copper 
	bra	.exit 

.blitter:
; Do stuff here when Blit done
	move.w	#(INTF_INTEN!INTF_BLIT),INTREQ(a5)   		
	move.w	#(INTF_INTEN!INTF_BLIT),INTREQ(a5)   		
	bra.s	.exit

.vertb:	
; Do stuff here in VBL
	move.w	#(INTF_INTEN!INTF_VERTB),INTREQ(a5)   		
	move.w	#(INTF_INTEN!INTF_VERTB),INTREQ(a5)   		
	bra.s	.exit 

.copper:
; Do stuff here on Copper Int.
	move.w	#(INTF_INTEN!INTF_COPER),INTREQ(a5)   		
	move.w	#(INTF_INTEN!INTF_COPER),INTREQ(a5)   		
		
.exit: 
	movem.l	(a7)+,d0-d7/a0-a6
	rte
mcgeezer is online now  
Old 09 October 2020, 22:45   #3
robinsonb5
Registered User
 
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 888
Try __interrupt instead. I think __amigainterrupt is for when you're writing a system-legal interrupt handler and registering it via the OS; you're bypassing the OS, so __interrupt is appropriate in your case.
robinsonb5 is offline  
Old 09 October 2020, 22:46   #4
Hedeon
PPC Hacker

 
Join Date: Mar 2012
Location: Leiden / The Netherlands
Posts: 1,344
If I RTM then__amigainterrupt uses rts and __interrupt rte
Hedeon is offline  
Old 09 October 2020, 23:19   #5
LastManStanding
Registered User

 
Join Date: Oct 2020
Location: Isbergues / France
Posts: 5
Thanks guys, I'm advancing : indeed, with __interrupt, it does not crash any longer, it "just" hangs; I suppose I have another detail that is wrong. I still investigate, thanks to your help I can go one step further.
LastManStanding is offline  
Old 12 October 2020, 17:58   #6
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,769
Quote:
Originally Posted by LastManStanding View Post
Thanks guys, I'm advancing : indeed, with __interrupt, it does not crash any longer, it "just" hangs;
What is your test system? Does it have a 68010 or greater? Then do not forget to read the VBR register before you change the vector.

When testing it with UAE you could simply break into the debugger and look where it hangs. Or you can insert a breakpoint into your interrupt handler. For example:
Code:
  __asm("\tdc.w\t$cf4f");
Then do
fi cf4f
in the UAE debugger and continue tracing through your handler and see what happens. You may also check the assembler output vbcc generates, when compiling with -S.

BTW, bit 14 in INTREQ has no meaning.
phx is offline  
Old 12 October 2020, 18:26   #7
LastManStanding
Registered User

 
Join Date: Oct 2020
Location: Isbergues / France
Posts: 5
Quote:
Originally Posted by phx View Post
What is your test system? Does it have a 68010 or greater? Then do not forget to read the VBR register before you change the vector.
The test system is a 68000, and 68040. The assembly version worked well on these two configs.

After lots of searches and tries, I finally understood the issue. I can't mix this way of using hardware VBL interrupts with the use of the ptreplay.library; each one works separately, but once I activate both, program hangs. I guess the replay library does not like killing so many IRQs so brutally.

So, I followed the OS way to implement the VBL interrupt (with the Interrupt struct and AddIntServer function), came back to __amigainterrupt for the callback, and everything is OK now.

In the future, I plan to be more system-friendly for the graphics stuff, too.
LastManStanding is offline  
Old 12 October 2020, 18:38   #8
ross
Defendit numerus

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 50
Posts: 2,982
Quote:
Originally Posted by phx View Post
BTW, bit 14 in INTREQ has no meaning.
Eheh, this is true of how Graeme used it.
But can be used to trigger an IRQ6 free from EXTER/CIAB bothering.
I happened to use it profitably
ross is offline  
Old 12 October 2020, 23:04   #9
LastManStanding
Registered User

 
Join Date: Oct 2020
Location: Isbergues / France
Posts: 5
Quote:
Originally Posted by phx View Post
BTW, bit 14 in INTREQ has no meaning.
Indeed, I misread the docs by the time I wrote that value (the 0x4020 originates from a code I wrote nearly 10 years ago). Nevertheless it worked.

I changed my code adequately (and changed it to use values from intbits.h).
LastManStanding is offline  
Old 13 October 2020, 00:12   #10
mcgeezer
Registered User

 
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,104
Indeed i just read the HRM and it states it has no effect. Will change code, thanks for ponting it out.
mcgeezer is online now  
Old 13 October 2020, 00:41   #11
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,769
Quote:
Originally Posted by ross View Post
But can be used to trigger an IRQ6 free from EXTER/CIAB bothering.
Oh. Interesting. I wasn't aware of that feature. Why does it work?

Quote:
I happened to use it profitably
Can you give an example? I rarely wanted to trigger a level 6 interrupt by software until today...
phx is offline  
Old 13 October 2020, 01:34   #12
ross
Defendit numerus

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 50
Posts: 2,982
Quote:
Originally Posted by phx View Post
Oh. Interesting. I wasn't aware of that feature. Why does it work?
No idea. Undocumented

Quote:
Can you give an example? I rarely wanted to trigger a level 6 interrupt by software until today...
Basically I needed to use it as an advanced/super VBI.
I had a routine inside IRQ3 that could even span more than one frame, but really floating and unpredictable (so I couldn't use VBI as reliable counter and handler for 25/30FPS display).
I couldn't use IRQ4 for obvious reasons and I have a IRQ5 free to interrupt IRQ3 asynchronously (unrelated to VBI).
So I put as the first instruction in copper list the trigger for INTEN/IRQ6 that manages the counter, then I have a normal EXTER/CIA for the module player.

Could I have done differently? Of course.
But codewise is really simple, fast and reliable .

Last edited by ross; 13 October 2020 at 02:44. Reason: example
ross is offline  
Old 14 October 2020, 02:01   #13
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,769
Oh, I see. You need a "frame-interrupt" which cannot be VBI, as you might need more time than that. So the copper interrupt, causing a level-6 via INTEN, marks the start of that frame.

Although I didn't understand in which context the frame rendering code is running, as your INTEN-level-6 just increments a counter? And then... causes a level-5 interrupt? Strange.

BTW, how can you differentiate an interrupt caused by INTEN from an EXTER one? Will the INTEN-bit be set in INTREQR? Or EXTER is not set?
phx is offline  
Old 14 October 2020, 11:19   #14
ross
Defendit numerus

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 50
Posts: 2,982
Quote:
Originally Posted by phx View Post
Oh, I see. You need a "frame-interrupt" which cannot be VBI, as you might need more time than that. So the copper interrupt, causing a level-6 via INTEN, marks the start of that frame.


Quote:
Although I didn't understand in which context the frame rendering code is running, as your INTEN-level-6 just increments a counter? And then... causes a level-5 interrupt? Strange.
The context of the rendering code is IRQ3, it handle double buffer based on what IRQ6 setup and use strict multiplexed blitter / CPU for the clear and poly fill operations. It can span more than one frame without extensive checks because is arbitrated by INTEN.

IRQ5 is simply a free high priority one for CPU-assisted Copper sync operations (I could have used it instead of the super-VBI, but not without slow checks!).

Quote:
BTW, how can you differentiate an interrupt caused by INTEN from an EXTER one? Will the INTEN-bit be set in INTREQR? Or EXTER is not set?
Yes, the interesting thing is that INTEN is set in INTREQR

ross is offline  
Old 14 October 2020, 13:14   #15
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,769
I think I got it. Thanks!
phx is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
flickering when writing to video memory during VBL jotd Coders. Asm / Hardware 13 28 September 2019 10:49
Damn Interrupts mcgeezer Coders. Asm / Hardware 10 24 March 2019 17:50
CIA interrupts... bloodline Coders. System 6 18 January 2018 11:33
Interrupts and Multitasking: Examples? tygre Coders. General 13 22 December 2015 05:56
Linking VBL interrups under the system Photon Coders. General 1 09 March 2006 17:51

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 19:53.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Page generated in 0.18169 seconds with 13 queries