Home » Archimedes archive » Archimedes World » AW-1992-09.adf » AWSept92 » !AWSept92/Goodies/Work/c/wimp

!AWSept92/Goodies/Work/c/wimp

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Archimedes World » AW-1992-09.adf » AWSept92
Filename: !AWSept92/Goodies/Work/c/wimp
Read OK:
File size: 0990 bytes
Load address: 0000
Exec address: 0000
File contents
/*********************************************************************/
/*                                                                   */
/*  Wimp Routine Library.          Access to Wimp SWI calls          */
/*                                                                   */
/*  Archimedes World 1992                                            */
/*                                                                   */
/*  Written By John Skingley.                                        */
/*                                                                   */
/*********************************************************************/


#include "h.global"
#include "h.swi"
#include "h.swiwimp"
#include "h.wimp"

static swi_error *Error        = NULL;
static int        Event[64]    = { 0 };
static int        Reason       = 0;
static int        Mask         = 1;    /* Mask null events by default */
static int        Task         = 0;    /* This task's handle.         */


int WimpTask( void )
{
    return Task;
}


void WimpSetMask( int reason, int state )
{
/*  Sets or unsets mask bit for given reason code. */

    int newmask = 1 << reason;

    if ( state )
        Mask |=  newmask;
    else
        Mask &= ~newmask;
}


int WimpGetMask( void )
{
    return Mask;
}


int WimpErrorNumber( void )
{
/*  Returns last error number, or zero.  */

    if ( Error )
        return Error->number;
    else
        return 0;
}


char *WimpErrorMessage( void )
{
/*  Returns last error message string, or NULL.  */

    if ( Error )
        return Error->message;
    else
        return NULL;
}


int WimpReasonCode( void )
{
/*  Returns the reason code for the latest event. */

    return Reason;
}


int *WimpEvent( void )
{
/*  Returns a pointer to the latest event data. */

    return Event;
}


int WimpPoll( void )
{
/*  Calls wimp polling routine, fills in event data. */

    int  regs[10];

    regs[0] = 0;
    regs[1] = (int) Event;

    Error  = Swi( Wimp_Poll, regs );
    Reason = regs[0];

    return Reason;
}


void WimpInitialise( char *name )
{
/*  Register task with the WIMP. */

    int regs[10];

    regs[0] = 200;
    regs[1] = 0x4B534154;  /* Magic number = 'TASK' */
    regs[2] = (int) name;

    Error = Swi( Wimp_Initialise, regs );

    Task = regs[1];
}


void WimpCloseDown( void )
{
    int regs[10];

    regs[0] = Task;
    regs[1] = 0x4B534154;

    Error = Swi( Wimp_CloseDown, regs );
}


00000000  2f 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |/***************|
00000010  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
00000040  2a 2a 2a 2a 2a 2a 2f 0a  2f 2a 20 20 20 20 20 20  |******/./*      |
00000050  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000080  20 20 20 20 20 20 20 20  20 20 20 20 20 2a 2f 0a  |             */.|
00000090  2f 2a 20 20 57 69 6d 70  20 52 6f 75 74 69 6e 65  |/*  Wimp Routine|
000000a0  20 4c 69 62 72 61 72 79  2e 20 20 20 20 20 20 20  | Library.       |
000000b0  20 20 20 41 63 63 65 73  73 20 74 6f 20 57 69 6d  |   Access to Wim|
000000c0  70 20 53 57 49 20 63 61  6c 6c 73 20 20 20 20 20  |p SWI calls     |
000000d0  20 20 20 20 20 2a 2f 0a  2f 2a 20 20 20 20 20 20  |     */./*      |
000000e0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000110  20 20 20 20 20 20 20 20  20 20 20 20 20 2a 2f 0a  |             */.|
00000120  2f 2a 20 20 41 72 63 68  69 6d 65 64 65 73 20 57  |/*  Archimedes W|
00000130  6f 72 6c 64 20 31 39 39  32 20 20 20 20 20 20 20  |orld 1992       |
00000140  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000160  20 20 20 20 20 2a 2f 0a  2f 2a 20 20 20 20 20 20  |     */./*      |
00000170  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000001a0  20 20 20 20 20 20 20 20  20 20 20 20 20 2a 2f 0a  |             */.|
000001b0  2f 2a 20 20 57 72 69 74  74 65 6e 20 42 79 20 4a  |/*  Written By J|
000001c0  6f 68 6e 20 53 6b 69 6e  67 6c 65 79 2e 20 20 20  |ohn Skingley.   |
000001d0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000001f0  20 20 20 20 20 2a 2f 0a  2f 2a 20 20 20 20 20 20  |     */./*      |
00000200  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000230  20 20 20 20 20 20 20 20  20 20 20 20 20 2a 2f 0a  |             */.|
00000240  2f 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |/***************|
00000250  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
00000280  2a 2a 2a 2a 2a 2a 2f 0a  0a 0a 23 69 6e 63 6c 75  |******/...#inclu|
00000290  64 65 20 22 68 2e 67 6c  6f 62 61 6c 22 0a 23 69  |de "h.global".#i|
000002a0  6e 63 6c 75 64 65 20 22  68 2e 73 77 69 22 0a 23  |nclude "h.swi".#|
000002b0  69 6e 63 6c 75 64 65 20  22 68 2e 73 77 69 77 69  |include "h.swiwi|
000002c0  6d 70 22 0a 23 69 6e 63  6c 75 64 65 20 22 68 2e  |mp".#include "h.|
000002d0  77 69 6d 70 22 0a 0a 73  74 61 74 69 63 20 73 77  |wimp"..static sw|
000002e0  69 5f 65 72 72 6f 72 20  2a 45 72 72 6f 72 20 20  |i_error *Error  |
000002f0  20 20 20 20 20 20 3d 20  4e 55 4c 4c 3b 0a 73 74  |      = NULL;.st|
00000300  61 74 69 63 20 69 6e 74  20 20 20 20 20 20 20 20  |atic int        |
00000310  45 76 65 6e 74 5b 36 34  5d 20 20 20 20 3d 20 7b  |Event[64]    = {|
00000320  20 30 20 7d 3b 0a 73 74  61 74 69 63 20 69 6e 74  | 0 };.static int|
00000330  20 20 20 20 20 20 20 20  52 65 61 73 6f 6e 20 20  |        Reason  |
00000340  20 20 20 20 20 3d 20 30  3b 0a 73 74 61 74 69 63  |     = 0;.static|
00000350  20 69 6e 74 20 20 20 20  20 20 20 20 4d 61 73 6b  | int        Mask|
00000360  20 20 20 20 20 20 20 20  20 3d 20 31 3b 20 20 20  |         = 1;   |
00000370  20 2f 2a 20 4d 61 73 6b  20 6e 75 6c 6c 20 65 76  | /* Mask null ev|
00000380  65 6e 74 73 20 62 79 20  64 65 66 61 75 6c 74 20  |ents by default |
00000390  2a 2f 0a 73 74 61 74 69  63 20 69 6e 74 20 20 20  |*/.static int   |
000003a0  20 20 20 20 20 54 61 73  6b 20 20 20 20 20 20 20  |     Task       |
000003b0  20 20 3d 20 30 3b 20 20  20 20 2f 2a 20 54 68 69  |  = 0;    /* Thi|
000003c0  73 20 74 61 73 6b 27 73  20 68 61 6e 64 6c 65 2e  |s task's handle.|
000003d0  20 20 20 20 20 20 20 20  20 2a 2f 0a 0a 0a 69 6e  |         */...in|
000003e0  74 20 57 69 6d 70 54 61  73 6b 28 20 76 6f 69 64  |t WimpTask( void|
000003f0  20 29 0a 7b 0a 20 20 20  20 72 65 74 75 72 6e 20  | ).{.    return |
00000400  54 61 73 6b 3b 0a 7d 0a  0a 0a 76 6f 69 64 20 57  |Task;.}...void W|
00000410  69 6d 70 53 65 74 4d 61  73 6b 28 20 69 6e 74 20  |impSetMask( int |
00000420  72 65 61 73 6f 6e 2c 20  69 6e 74 20 73 74 61 74  |reason, int stat|
00000430  65 20 29 0a 7b 0a 2f 2a  20 20 53 65 74 73 20 6f  |e ).{./*  Sets o|
00000440  72 20 75 6e 73 65 74 73  20 6d 61 73 6b 20 62 69  |r unsets mask bi|
00000450  74 20 66 6f 72 20 67 69  76 65 6e 20 72 65 61 73  |t for given reas|
00000460  6f 6e 20 63 6f 64 65 2e  20 2a 2f 0a 0a 20 20 20  |on code. */..   |
00000470  20 69 6e 74 20 6e 65 77  6d 61 73 6b 20 3d 20 31  | int newmask = 1|
00000480  20 3c 3c 20 72 65 61 73  6f 6e 3b 0a 0a 20 20 20  | << reason;..   |
00000490  20 69 66 20 28 20 73 74  61 74 65 20 29 0a 20 20  | if ( state ).  |
000004a0  20 20 20 20 20 20 4d 61  73 6b 20 7c 3d 20 20 6e  |      Mask |=  n|
000004b0  65 77 6d 61 73 6b 3b 0a  20 20 20 20 65 6c 73 65  |ewmask;.    else|
000004c0  0a 20 20 20 20 20 20 20  20 4d 61 73 6b 20 26 3d  |.        Mask &=|
000004d0  20 7e 6e 65 77 6d 61 73  6b 3b 0a 7d 0a 0a 0a 69  | ~newmask;.}...i|
000004e0  6e 74 20 57 69 6d 70 47  65 74 4d 61 73 6b 28 20  |nt WimpGetMask( |
000004f0  76 6f 69 64 20 29 0a 7b  0a 20 20 20 20 72 65 74  |void ).{.    ret|
00000500  75 72 6e 20 4d 61 73 6b  3b 0a 7d 0a 0a 0a 69 6e  |urn Mask;.}...in|
00000510  74 20 57 69 6d 70 45 72  72 6f 72 4e 75 6d 62 65  |t WimpErrorNumbe|
00000520  72 28 20 76 6f 69 64 20  29 0a 7b 0a 2f 2a 20 20  |r( void ).{./*  |
00000530  52 65 74 75 72 6e 73 20  6c 61 73 74 20 65 72 72  |Returns last err|
00000540  6f 72 20 6e 75 6d 62 65  72 2c 20 6f 72 20 7a 65  |or number, or ze|
00000550  72 6f 2e 20 20 2a 2f 0a  0a 20 20 20 20 69 66 20  |ro.  */..    if |
00000560  28 20 45 72 72 6f 72 20  29 0a 20 20 20 20 20 20  |( Error ).      |
00000570  20 20 72 65 74 75 72 6e  20 45 72 72 6f 72 2d 3e  |  return Error->|
00000580  6e 75 6d 62 65 72 3b 0a  20 20 20 20 65 6c 73 65  |number;.    else|
00000590  0a 20 20 20 20 20 20 20  20 72 65 74 75 72 6e 20  |.        return |
000005a0  30 3b 0a 7d 0a 0a 0a 63  68 61 72 20 2a 57 69 6d  |0;.}...char *Wim|
000005b0  70 45 72 72 6f 72 4d 65  73 73 61 67 65 28 20 76  |pErrorMessage( v|
000005c0  6f 69 64 20 29 0a 7b 0a  2f 2a 20 20 52 65 74 75  |oid ).{./*  Retu|
000005d0  72 6e 73 20 6c 61 73 74  20 65 72 72 6f 72 20 6d  |rns last error m|
000005e0  65 73 73 61 67 65 20 73  74 72 69 6e 67 2c 20 6f  |essage string, o|
000005f0  72 20 4e 55 4c 4c 2e 20  20 2a 2f 0a 0a 20 20 20  |r NULL.  */..   |
00000600  20 69 66 20 28 20 45 72  72 6f 72 20 29 0a 20 20  | if ( Error ).  |
00000610  20 20 20 20 20 20 72 65  74 75 72 6e 20 45 72 72  |      return Err|
00000620  6f 72 2d 3e 6d 65 73 73  61 67 65 3b 0a 20 20 20  |or->message;.   |
00000630  20 65 6c 73 65 0a 20 20  20 20 20 20 20 20 72 65  | else.        re|
00000640  74 75 72 6e 20 4e 55 4c  4c 3b 0a 7d 0a 0a 0a 69  |turn NULL;.}...i|
00000650  6e 74 20 57 69 6d 70 52  65 61 73 6f 6e 43 6f 64  |nt WimpReasonCod|
00000660  65 28 20 76 6f 69 64 20  29 0a 7b 0a 2f 2a 20 20  |e( void ).{./*  |
00000670  52 65 74 75 72 6e 73 20  74 68 65 20 72 65 61 73  |Returns the reas|
00000680  6f 6e 20 63 6f 64 65 20  66 6f 72 20 74 68 65 20  |on code for the |
00000690  6c 61 74 65 73 74 20 65  76 65 6e 74 2e 20 2a 2f  |latest event. */|
000006a0  0a 0a 20 20 20 20 72 65  74 75 72 6e 20 52 65 61  |..    return Rea|
000006b0  73 6f 6e 3b 0a 7d 0a 0a  0a 69 6e 74 20 2a 57 69  |son;.}...int *Wi|
000006c0  6d 70 45 76 65 6e 74 28  20 76 6f 69 64 20 29 0a  |mpEvent( void ).|
000006d0  7b 0a 2f 2a 20 20 52 65  74 75 72 6e 73 20 61 20  |{./*  Returns a |
000006e0  70 6f 69 6e 74 65 72 20  74 6f 20 74 68 65 20 6c  |pointer to the l|
000006f0  61 74 65 73 74 20 65 76  65 6e 74 20 64 61 74 61  |atest event data|
00000700  2e 20 2a 2f 0a 0a 20 20  20 20 72 65 74 75 72 6e  |. */..    return|
00000710  20 45 76 65 6e 74 3b 0a  7d 0a 0a 0a 69 6e 74 20  | Event;.}...int |
00000720  57 69 6d 70 50 6f 6c 6c  28 20 76 6f 69 64 20 29  |WimpPoll( void )|
00000730  0a 7b 0a 2f 2a 20 20 43  61 6c 6c 73 20 77 69 6d  |.{./*  Calls wim|
00000740  70 20 70 6f 6c 6c 69 6e  67 20 72 6f 75 74 69 6e  |p polling routin|
00000750  65 2c 20 66 69 6c 6c 73  20 69 6e 20 65 76 65 6e  |e, fills in even|
00000760  74 20 64 61 74 61 2e 20  2a 2f 0a 0a 20 20 20 20  |t data. */..    |
00000770  69 6e 74 20 20 72 65 67  73 5b 31 30 5d 3b 0a 0a  |int  regs[10];..|
00000780  20 20 20 20 72 65 67 73  5b 30 5d 20 3d 20 30 3b  |    regs[0] = 0;|
00000790  0a 20 20 20 20 72 65 67  73 5b 31 5d 20 3d 20 28  |.    regs[1] = (|
000007a0  69 6e 74 29 20 45 76 65  6e 74 3b 0a 0a 20 20 20  |int) Event;..   |
000007b0  20 45 72 72 6f 72 20 20  3d 20 53 77 69 28 20 57  | Error  = Swi( W|
000007c0  69 6d 70 5f 50 6f 6c 6c  2c 20 72 65 67 73 20 29  |imp_Poll, regs )|
000007d0  3b 0a 20 20 20 20 52 65  61 73 6f 6e 20 3d 20 72  |;.    Reason = r|
000007e0  65 67 73 5b 30 5d 3b 0a  0a 20 20 20 20 72 65 74  |egs[0];..    ret|
000007f0  75 72 6e 20 52 65 61 73  6f 6e 3b 0a 7d 0a 0a 0a  |urn Reason;.}...|
00000800  76 6f 69 64 20 57 69 6d  70 49 6e 69 74 69 61 6c  |void WimpInitial|
00000810  69 73 65 28 20 63 68 61  72 20 2a 6e 61 6d 65 20  |ise( char *name |
00000820  29 0a 7b 0a 2f 2a 20 20  52 65 67 69 73 74 65 72  |).{./*  Register|
00000830  20 74 61 73 6b 20 77 69  74 68 20 74 68 65 20 57  | task with the W|
00000840  49 4d 50 2e 20 2a 2f 0a  0a 20 20 20 20 69 6e 74  |IMP. */..    int|
00000850  20 72 65 67 73 5b 31 30  5d 3b 0a 0a 20 20 20 20  | regs[10];..    |
00000860  72 65 67 73 5b 30 5d 20  3d 20 32 30 30 3b 0a 20  |regs[0] = 200;. |
00000870  20 20 20 72 65 67 73 5b  31 5d 20 3d 20 30 78 34  |   regs[1] = 0x4|
00000880  42 35 33 34 31 35 34 3b  20 20 2f 2a 20 4d 61 67  |B534154;  /* Mag|
00000890  69 63 20 6e 75 6d 62 65  72 20 3d 20 27 54 41 53  |ic number = 'TAS|
000008a0  4b 27 20 2a 2f 0a 20 20  20 20 72 65 67 73 5b 32  |K' */.    regs[2|
000008b0  5d 20 3d 20 28 69 6e 74  29 20 6e 61 6d 65 3b 0a  |] = (int) name;.|
000008c0  0a 20 20 20 20 45 72 72  6f 72 20 3d 20 53 77 69  |.    Error = Swi|
000008d0  28 20 57 69 6d 70 5f 49  6e 69 74 69 61 6c 69 73  |( Wimp_Initialis|
000008e0  65 2c 20 72 65 67 73 20  29 3b 0a 0a 20 20 20 20  |e, regs );..    |
000008f0  54 61 73 6b 20 3d 20 72  65 67 73 5b 31 5d 3b 0a  |Task = regs[1];.|
00000900  7d 0a 0a 0a 76 6f 69 64  20 57 69 6d 70 43 6c 6f  |}...void WimpClo|
00000910  73 65 44 6f 77 6e 28 20  76 6f 69 64 20 29 0a 7b  |seDown( void ).{|
00000920  0a 20 20 20 20 69 6e 74  20 72 65 67 73 5b 31 30  |.    int regs[10|
00000930  5d 3b 0a 0a 20 20 20 20  72 65 67 73 5b 30 5d 20  |];..    regs[0] |
00000940  3d 20 54 61 73 6b 3b 0a  20 20 20 20 72 65 67 73  |= Task;.    regs|
00000950  5b 31 5d 20 3d 20 30 78  34 42 35 33 34 31 35 34  |[1] = 0x4B534154|
00000960  3b 0a 0a 20 20 20 20 45  72 72 6f 72 20 3d 20 53  |;..    Error = S|
00000970  77 69 28 20 57 69 6d 70  5f 43 6c 6f 73 65 44 6f  |wi( Wimp_CloseDo|
00000980  77 6e 2c 20 72 65 67 73  20 29 3b 0a 7d 0a 0a 0a  |wn, regs );.}...|
00000990