🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.micro.atari16
Article #1026

Re: Sorry, but these guys.... (FLAME)

#1026
From: eric
Date: Tue, 27 May 1986 16:18
57 lines
2445 bytes

Your program would work fine in a system with no other interrupts, however
that is not the case on the ST.  There are a number of interrupts that occur
on a regular basis (vertical retrace, keyboard etc.)  It is quite likely that
your timer will go off while one of these routines is being serviced.  It is
also quite likely that one of these routines is using D7.

What you need to do is establish a different mechanism for communicating
between the interrupt routine and the main program.  The easiest method is 
to declare some space in the interrupt procedure, preceeding it with a label,
and use PC relative addressing to access it.  If you save A4 in the space
then you can directly access C global variables from your interrupt procedure.

The following listing includes these modifications to your original program.
========================================================
#include <stdio.h>
#include <osbind.h>

extern int my_timer_code ();
long count;

asm {
    my_timer_code:
        move.l  A4, -(A7)   
        move.l  save_a4(PC), A4     /* Restore A4 */
        addq.l  #1, count(A4)       /* Just count interrupts */
        move.b  #0xDF,0xFFFA0F      /* Clear ISRA Timer A bit */
        move.l  (A7)+, A4
        rte

    save_a4:
        dc.l    0
    }


main()
{
    register int i;
    int (*my_interrupt_handler) ();
 
    asm {   /* Save A4 for use in interrupt routine */
        lea     save_a4(PC), A0
        move.l  A4, (A0)
    }
    my_interrupt_handler = my_timer_code; /* point to my interrupt */

    Xbtimer (0,1,100,my_interrupt_handler);  /* Enable timer A, prescale 4
                                                for 100 counts (100us ?) */ 

    for (i = 0; i < 30000; i++)
        ;

    Xbtimer (0,0,0,0L);
    
    printf ("Timer timed out %ld times.\n", count); 
}
Technical Details
Message-ID: <3100002@megamax>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!ihnp4!inuxc!pur-ee!uiucdcs!convex!megamax!eric
References: <429@elmgate.uucp>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!ihnp4!inuxc!pur-ee!uiucdcs!convex!megamax!eric
From: eric@megamax
Newsgroups: net.micro.atari16
Subject: Re: Sorry, but these guys.... (FLAME)
Message-ID: <3100002@megamax>
Date: Tue, 27-May-86 12:18:00 EDT
Article-I.D.: megamax.3100002
Posted: Tue May 27 12:18:00 1986
Date-Received: Fri, 30-May-86 08:33:54 EDT
References: <429@elmgate.uucp>
Lines: 57
Nf-ID: #R:elmgate.uucp:429:megamax:3100002:000:1815
Nf-From: megamax!eric    May 27 11:18:00 1986