/*****************************************************************************
                                    KK22
                A 22-line desk accessory written in Laser C
                    by Les Kneeling for Screenfull

    The accessory puts "Toggle Keyclick" in the menu bar. Click on the
    message to switch the keyclick off or on depending on the current
    state.

    As Lloyd Patton recommends, I have not checked the menu_id, which is
    returned in msgbuff[4], and is not required because the OS will only
    pass the AC_OPEN message to the correct accessory.

*****************************************************************************/
#include <osbind.h>
extern gl_apid;                         /* External global          */

main()
{
long stack;
int menu_id, event, msgbuff[8];
appl_init();                            /* Initialise ROMS          */
menu_id = menu_register( gl_apid, "  Toggle Keyclick" );
for(;;) {                               /* Accessories run forever  */
    event = evnt_mesag( msgbuff );      /* Look for messages        */
    if( msgbuff[0] == 40 )  {           /* 40 is AC_OPEN            */
        stack = Super(0l);              /* Go to supervisor mode    */
        asm {   move.l #0x484, A0;      /* 0x484 is conterm         */
                move.w #0, D0;          
                bchg D0, (A0);  }       /* flip the bit             */
        Super(stack);                   /* back to user mode        */
        }
    }
}
