From: | Gunther Nikl |
Date: | 10 Sep 2001 at 16:11:29 |
Subject: | [amiga-c] Re: VB int problem (was Re: Help needed with random crashing problem) |
Hello Paul,
> > It would have been helpful to know which type your variables have.
>
> struct Custom *cust = (APTR)0xdff000;
All (?) customchip register have word-width (16bits). Thus your write
of potgo is 16bits wide.
> UWORD mojo = 0;
> UWORD intvolume;
I would suggest to make these ULONGs since in my experience modern
compiler deal much better with 32bit quantities (at least GCC)
> UWORD tempvol;
Same here and it should be local to your interrupt function.
> UBYTE db = 0;
ULONG if global. If you collect your interrupt data in a structure then
things are a little bit different. In that case you could use UBYTE for
db but pay attention to alignment issues. 32bit quantities are best
alignet at 32bit. If you use smaller types you should group them to
together to always get a multiple of 4. Use padding if that the only
way to achieve the alignment.
> >> tempvol = mojo * 0.8;
>
> > This looks like floating point math. This is a bad idea to use in an
> > interrupt.
>
> You arn't the first to say that, so I'm going to try without floating
> point math. I thought it would be okay because I set the compiler to use
> the 68882 FPU instead of the math libraries.
You don't know which FPU registers the compiler is going to use for the
calculation. The RKM says exactly which registers are srcatch registers
for interrupts but AFAIK FPU registers are not mentioned at all. Thus
you shouldn't changed the value of any FPU register. I could imagine
that FP0/FP1 are treated as scratch with your compiler and floats are
slow (compared with ints on 68k ;-)
You should replace your calculation with: tempvol = (mojo * 8) / 10;
BTW, no need to use shifts. Your compiler should know best when to use
which instructions.
> > Furthermore, you should pass a pointer to a structure with all data
> > your function needs (don't forget SysBase!) to avoid accessing global
> > data. Then you could get rid of __saveds.
>
> That's a good idea. I used that technique for my MHI interrupt which was
> all assembler.
Why didn't you do the same in C? Its easy ;-)
> > BTW, you shouldn't use the VERTB interrupt in the first place. Did you
> > consider using a PA_SOFTINT port together with the timer.device? This
> > will give you constant timing on every amiga.
>
> I didn't think of that. It sounds like a better way to do things though.
If you need a working example how to use such ports I recommend a
program of my own :-)
AmiNet:util/misc/FrontPub.lha
> I just thought that the VERTB interrupt would be a simple and easy way
> to get timing on my fixed system. I didn't worry too much about
> compatability beyond the A1200 030 I am using, TBH.
Its not only compatibility but the timing of VERTB depends on the used
screenmode. I think you know that .-)
Gunther
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Secure your servers with 128-bit SSL encryption! Grab your copy of VeriSign's FREE Guide: "Securing Your Web Site for Business." Get it Now!
http://us.click.yahoo.com/n7RbFC/zhwCAA/yigFAA/dpFolB/TM
---------------------------------------------------------------------~->
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/