Home » Recent acquisitions » Acorn ADFS disks » adfs_ArchimedesWorld_199207.adf » !AWJULY92 » !AWJUL92/Goodies/work/c/wimp

!AWJUL92/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 » Recent acquisitions » Acorn ADFS disks » adfs_ArchimedesWorld_199207.adf » !AWJULY92
Filename: !AWJUL92/Goodies/work/c/wimp
Read OK:
File size: 096A 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.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( 0x400C7, 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( 0x400C0, regs );

    Task = regs[1];
}


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

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

    Error = Swi( 0x400DD, 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 77 69 6d 70 22  |include "h.wimp"|
000002c0  0a 0a 73 74 61 74 69 63  20 73 77 69 5f 65 72 72  |..static swi_err|
000002d0  6f 72 20 2a 45 72 72 6f  72 20 20 20 20 20 20 20  |or *Error       |
000002e0  20 3d 20 4e 55 4c 4c 3b  0a 73 74 61 74 69 63 20  | = NULL;.static |
000002f0  69 6e 74 20 20 20 20 20  20 20 20 45 76 65 6e 74  |int        Event|
00000300  5b 36 34 5d 20 20 20 20  3d 20 7b 20 30 20 7d 3b  |[64]    = { 0 };|
00000310  0a 73 74 61 74 69 63 20  69 6e 74 20 20 20 20 20  |.static int     |
00000320  20 20 20 52 65 61 73 6f  6e 20 20 20 20 20 20 20  |   Reason       |
00000330  3d 20 30 3b 0a 73 74 61  74 69 63 20 69 6e 74 20  |= 0;.static int |
00000340  20 20 20 20 20 20 20 4d  61 73 6b 20 20 20 20 20  |       Mask     |
00000350  20 20 20 20 3d 20 31 3b  20 20 20 20 2f 2a 20 4d  |    = 1;    /* M|
00000360  61 73 6b 20 6e 75 6c 6c  20 65 76 65 6e 74 73 20  |ask null events |
00000370  62 79 20 64 65 66 61 75  6c 74 20 2a 2f 0a 73 74  |by default */.st|
00000380  61 74 69 63 20 69 6e 74  20 20 20 20 20 20 20 20  |atic int        |
00000390  54 61 73 6b 20 20 20 20  20 20 20 20 20 3d 20 30  |Task         = 0|
000003a0  3b 20 20 20 20 2f 2a 20  54 68 69 73 20 74 61 73  |;    /* This tas|
000003b0  6b 27 73 20 68 61 6e 64  6c 65 2e 20 20 20 20 20  |k's handle.     |
000003c0  20 20 20 20 2a 2f 0a 0a  0a 69 6e 74 20 57 69 6d  |    */...int Wim|
000003d0  70 54 61 73 6b 28 20 76  6f 69 64 20 29 0a 7b 0a  |pTask( void ).{.|
000003e0  20 20 20 20 72 65 74 75  72 6e 20 54 61 73 6b 3b  |    return Task;|
000003f0  0a 7d 0a 0a 0a 76 6f 69  64 20 57 69 6d 70 53 65  |.}...void WimpSe|
00000400  74 4d 61 73 6b 28 20 69  6e 74 20 72 65 61 73 6f  |tMask( int reaso|
00000410  6e 2c 20 69 6e 74 20 73  74 61 74 65 20 29 0a 7b  |n, int state ).{|
00000420  0a 2f 2a 20 20 53 65 74  73 20 6f 72 20 75 6e 73  |./*  Sets or uns|
00000430  65 74 73 20 6d 61 73 6b  20 62 69 74 20 66 6f 72  |ets mask bit for|
00000440  20 67 69 76 65 6e 20 72  65 61 73 6f 6e 20 63 6f  | given reason co|
00000450  64 65 2e 20 2a 2f 0a 0a  20 20 20 20 69 6e 74 20  |de. */..    int |
00000460  6e 65 77 6d 61 73 6b 20  3d 20 31 20 3c 3c 20 72  |newmask = 1 << r|
00000470  65 61 73 6f 6e 3b 0a 0a  20 20 20 20 69 66 20 28  |eason;..    if (|
00000480  20 73 74 61 74 65 20 29  0a 20 20 20 20 20 20 20  | state ).       |
00000490  20 4d 61 73 6b 20 7c 3d  20 20 6e 65 77 6d 61 73  | Mask |=  newmas|
000004a0  6b 3b 0a 20 20 20 20 65  6c 73 65 0a 20 20 20 20  |k;.    else.    |
000004b0  20 20 20 20 4d 61 73 6b  20 26 3d 20 7e 6e 65 77  |    Mask &= ~new|
000004c0  6d 61 73 6b 3b 0a 7d 0a  0a 0a 69 6e 74 20 57 69  |mask;.}...int Wi|
000004d0  6d 70 47 65 74 4d 61 73  6b 28 20 76 6f 69 64 20  |mpGetMask( void |
000004e0  29 0a 7b 0a 20 20 20 20  72 65 74 75 72 6e 20 4d  |).{.    return M|
000004f0  61 73 6b 3b 0a 7d 0a 0a  0a 69 6e 74 20 57 69 6d  |ask;.}...int Wim|
00000500  70 45 72 72 6f 72 4e 75  6d 62 65 72 28 20 76 6f  |pErrorNumber( vo|
00000510  69 64 20 29 0a 7b 0a 2f  2a 20 20 52 65 74 75 72  |id ).{./*  Retur|
00000520  6e 73 20 6c 61 73 74 20  65 72 72 6f 72 20 6e 75  |ns last error nu|
00000530  6d 62 65 72 2c 20 6f 72  20 7a 65 72 6f 2e 20 20  |mber, or zero.  |
00000540  2a 2f 0a 0a 20 20 20 20  69 66 20 28 20 45 72 72  |*/..    if ( Err|
00000550  6f 72 20 29 0a 20 20 20  20 20 20 20 20 72 65 74  |or ).        ret|
00000560  75 72 6e 20 45 72 72 6f  72 2d 3e 6e 75 6d 62 65  |urn Error->numbe|
00000570  72 3b 0a 20 20 20 20 65  6c 73 65 0a 20 20 20 20  |r;.    else.    |
00000580  20 20 20 20 72 65 74 75  72 6e 20 30 3b 0a 7d 0a  |    return 0;.}.|
00000590  0a 0a 63 68 61 72 20 2a  57 69 6d 70 45 72 72 6f  |..char *WimpErro|
000005a0  72 4d 65 73 73 61 67 65  28 20 76 6f 69 64 20 29  |rMessage( void )|
000005b0  0a 7b 0a 2f 2a 20 20 52  65 74 75 72 6e 73 20 6c  |.{./*  Returns l|
000005c0  61 73 74 20 65 72 72 6f  72 20 6d 65 73 73 61 67  |ast error messag|
000005d0  65 20 73 74 72 69 6e 67  2c 20 6f 72 20 4e 55 4c  |e string, or NUL|
000005e0  4c 2e 20 20 2a 2f 0a 0a  20 20 20 20 69 66 20 28  |L.  */..    if (|
000005f0  20 45 72 72 6f 72 20 29  0a 20 20 20 20 20 20 20  | Error ).       |
00000600  20 72 65 74 75 72 6e 20  45 72 72 6f 72 2d 3e 6d  | return Error->m|
00000610  65 73 73 61 67 65 3b 0a  20 20 20 20 65 6c 73 65  |essage;.    else|
00000620  0a 20 20 20 20 20 20 20  20 72 65 74 75 72 6e 20  |.        return |
00000630  4e 55 4c 4c 3b 0a 7d 0a  0a 0a 69 6e 74 20 57 69  |NULL;.}...int Wi|
00000640  6d 70 52 65 61 73 6f 6e  43 6f 64 65 28 20 76 6f  |mpReasonCode( vo|
00000650  69 64 20 29 0a 7b 0a 2f  2a 20 20 52 65 74 75 72  |id ).{./*  Retur|
00000660  6e 73 20 74 68 65 20 72  65 61 73 6f 6e 20 63 6f  |ns the reason co|
00000670  64 65 20 66 6f 72 20 74  68 65 20 6c 61 74 65 73  |de for the lates|
00000680  74 20 65 76 65 6e 74 2e  20 2a 2f 0a 0a 20 20 20  |t event. */..   |
00000690  20 72 65 74 75 72 6e 20  52 65 61 73 6f 6e 3b 0a  | return Reason;.|
000006a0  7d 0a 0a 0a 69 6e 74 20  2a 57 69 6d 70 45 76 65  |}...int *WimpEve|
000006b0  6e 74 28 20 76 6f 69 64  20 29 0a 7b 0a 2f 2a 20  |nt( void ).{./* |
000006c0  20 52 65 74 75 72 6e 73  20 61 20 70 6f 69 6e 74  | Returns a point|
000006d0  65 72 20 74 6f 20 74 68  65 20 6c 61 74 65 73 74  |er to the latest|
000006e0  20 65 76 65 6e 74 20 64  61 74 61 2e 20 2a 2f 0a  | event data. */.|
000006f0  0a 20 20 20 20 72 65 74  75 72 6e 20 45 76 65 6e  |.    return Even|
00000700  74 3b 0a 7d 0a 0a 0a 69  6e 74 20 57 69 6d 70 50  |t;.}...int WimpP|
00000710  6f 6c 6c 28 20 76 6f 69  64 20 29 0a 7b 0a 2f 2a  |oll( void ).{./*|
00000720  20 20 43 61 6c 6c 73 20  77 69 6d 70 20 70 6f 6c  |  Calls wimp pol|
00000730  6c 69 6e 67 20 72 6f 75  74 69 6e 65 2c 20 66 69  |ling routine, fi|
00000740  6c 6c 73 20 69 6e 20 65  76 65 6e 74 20 64 61 74  |lls in event dat|
00000750  61 2e 20 2a 2f 0a 0a 20  20 20 20 69 6e 74 20 20  |a. */..    int  |
00000760  72 65 67 73 5b 31 30 5d  3b 0a 0a 20 20 20 20 72  |regs[10];..    r|
00000770  65 67 73 5b 30 5d 20 3d  20 30 3b 0a 20 20 20 20  |egs[0] = 0;.    |
00000780  72 65 67 73 5b 31 5d 20  3d 20 28 69 6e 74 29 20  |regs[1] = (int) |
00000790  45 76 65 6e 74 3b 0a 0a  20 20 20 20 45 72 72 6f  |Event;..    Erro|
000007a0  72 20 20 3d 20 53 77 69  28 20 30 78 34 30 30 43  |r  = Swi( 0x400C|
000007b0  37 2c 20 72 65 67 73 20  29 3b 0a 20 20 20 20 52  |7, regs );.    R|
000007c0  65 61 73 6f 6e 20 3d 20  72 65 67 73 5b 30 5d 3b  |eason = regs[0];|
000007d0  0a 0a 20 20 20 20 72 65  74 75 72 6e 20 52 65 61  |..    return Rea|
000007e0  73 6f 6e 3b 0a 7d 0a 0a  0a 76 6f 69 64 20 57 69  |son;.}...void Wi|
000007f0  6d 70 49 6e 69 74 69 61  6c 69 73 65 28 20 63 68  |mpInitialise( ch|
00000800  61 72 20 2a 6e 61 6d 65  20 29 0a 7b 0a 2f 2a 20  |ar *name ).{./* |
00000810  20 52 65 67 69 73 74 65  72 20 74 61 73 6b 20 77  | Register task w|
00000820  69 74 68 20 74 68 65 20  57 49 4d 50 2e 20 2a 2f  |ith the WIMP. */|
00000830  0a 0a 20 20 20 20 69 6e  74 20 72 65 67 73 5b 31  |..    int regs[1|
00000840  30 5d 3b 0a 0a 20 20 20  20 72 65 67 73 5b 30 5d  |0];..    regs[0]|
00000850  20 3d 20 32 30 30 3b 0a  20 20 20 20 72 65 67 73  | = 200;.    regs|
00000860  5b 31 5d 20 3d 20 30 78  34 42 35 33 34 31 35 34  |[1] = 0x4B534154|
00000870  3b 20 20 2f 2a 20 4d 61  67 69 63 20 6e 75 6d 62  |;  /* Magic numb|
00000880  65 72 20 3d 20 27 54 41  53 4b 27 20 2a 2f 0a 20  |er = 'TASK' */. |
00000890  20 20 20 72 65 67 73 5b  32 5d 20 3d 20 28 69 6e  |   regs[2] = (in|
000008a0  74 29 20 6e 61 6d 65 3b  0a 0a 20 20 20 20 45 72  |t) name;..    Er|
000008b0  72 6f 72 20 3d 20 53 77  69 28 20 30 78 34 30 30  |ror = Swi( 0x400|
000008c0  43 30 2c 20 72 65 67 73  20 29 3b 0a 0a 20 20 20  |C0, regs );..   |
000008d0  20 54 61 73 6b 20 3d 20  72 65 67 73 5b 31 5d 3b  | Task = regs[1];|
000008e0  0a 7d 0a 0a 0a 76 6f 69  64 20 57 69 6d 70 43 6c  |.}...void WimpCl|
000008f0  6f 73 65 44 6f 77 6e 28  20 76 6f 69 64 20 29 0a  |oseDown( void ).|
00000900  7b 0a 20 20 20 20 69 6e  74 20 72 65 67 73 5b 31  |{.    int regs[1|
00000910  30 5d 3b 0a 0a 20 20 20  20 72 65 67 73 5b 30 5d  |0];..    regs[0]|
00000920  20 3d 20 54 61 73 6b 3b  0a 20 20 20 20 72 65 67  | = Task;.    reg|
00000930  73 5b 31 5d 20 3d 20 30  78 34 42 35 33 34 31 35  |s[1] = 0x4B53415|
00000940  34 3b 0a 0a 20 20 20 20  45 72 72 6f 72 20 3d 20  |4;..    Error = |
00000950  53 77 69 28 20 30 78 34  30 30 44 44 2c 20 72 65  |Swi( 0x400DD, re|
00000960  67 73 20 29 3b 0a 7d 0a  0a 0a                    |gs );.}...|
0000096a