Home » Archimedes archive » Acorn User » AU 1996-03 B.adf » Regulars » WimpC/!WimpC/c/!RunImage
WimpC/!WimpC/c/!RunImage
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 » Acorn User » AU 1996-03 B.adf » Regulars |
Filename: | WimpC/!WimpC/c/!RunImage |
Read OK: | ✔ |
File size: | 1CA2 bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
/* An example program which makes use of the kernel SWI calls - this will compile with Acorn's C as well as Beebug's EasyC */ /* by Steve Mumford for Acorn User - March 1996 */ #include <stdio.h> #include <string.h> #include "swis.h" #include "kernel.h" /* We also define a poll mask here to tell the WIMP about any events we're not intererested in */ #define POLL_MASK 1 /* If we set QUIT_FLAG up as a global variable, it means that we can change it anywhere within the program and shut things down next time we end the polling loop */ int QUIT_FLAG = 0; char appname[] = "WIMPC Example"; /* Function prototyping */ int main(void); void wimpmsg(int, unsigned char[]); unsigned long int btow(unsigned char[], int); void wtob(unsigned long int, unsigned char[], int); void mouseclick(unsigned char[]); int report_error(int, char[], int); /* Program functions */ int main(void) { int task_handle; unsigned char pollblock[257]; /* essentially a byte array large enough for our polling block */ unsigned char iconblock[40]; int ibar_icon_handle; /* A block to hold our icon data, and a variable to store its handle */ int pollresult; _kernel_swi_regs regs_in, regs_out; char ibar_sprname[] = "!wimpc"; /* The above line specifies the name of the sprite in the wimp pool that we are to use on the icon bar */ long int msglist[1] = {0}; /* Now to initialise ourselves as a task */ regs_in.r[0] = 310; regs_in.r[1] = *(int *)"TASK"; regs_in.r[2] = (int) appname; regs_in.r[3] = (int) msglist; /* We need to supply our chosen RISC OS version number, the "TASK" identifier to prove we're a multitasking application, a pointer to our application name and a pointer to a message list - converted to integer format as necessary */ /* now to perform the actual SWI call */ _kernel_swi(Wimp_Initialise, ®s_in, ®s_out); task_handle = regs_out.r[1]; /* determine our task handle for later use */ /* Now, we'll put an icon on the icon bar - we need to have defined an icon block, whose address we pass in R1 */ wtob(-1, iconblock, 0); /* Specify position on the icon bar (the right) */ wtob(0, iconblock, 4); /* These four lines give the bounding box of the */ wtob(0, iconblock, 8); /* icon - min x, min y, max x, max y */ wtob(72, iconblock, 12); wtob(72, iconblock, 16); wtob(12314, iconblock, 20); /* set bits 1, 3, 4, 12, 13 of icon flags - bit 1 - the icon is a sprite; bits 3, 4 centre the sprite in the bounding box; bits 12 and 13 inform the WIMP to let us know when our icon is clicked on, by passing us a Mouse_Click event */ strcpy( (char *) &iconblock[24], ibar_sprname); /* Finally, copy the name of the sprite we are to use into the datablock; this must be terminated with a control character */ regs_in.r[0] = 0; /* set the icon's priority */ regs_in.r[1] = (int) iconblock; _kernel_swi(Wimp_CreateIcon, ®s_in, ®s_out); ibar_icon_handle = regs_out.r[0]; do { regs_in.r[0] = POLL_MASK; regs_in.r[1] = (int) pollblock; /* a pointer to our data block */ _kernel_swi(Wimp_Poll, ®s_in, ®s_out); pollresult = regs_out.r[0]; /* determine the event code */ switch (pollresult) { case 6: mouseclick(pollblock); break; /* If our icon is clicked on, we jump to mouseclick() */ case 17: case 18: case 19: wimpmsg(pollresult, pollblock); break; /* The above section listens for event codes 17, 18 and 19 - the ones which indicate we're being sent a message */ } } while (QUIT_FLAG == 0); /* If QUIT_FLAG changes to anything but 0, we stop going round the polling loop and shut down */ regs_in.r[0] = task_handle; regs_in.r[1] = *(int *)"TASK"; _kernel_swi(Wimp_CloseDown, ®s_in, ®s_out); /* And that's it - we've told the WIMP that we've finished, and now the program terminates. */ } void wimpmsg(int result, unsigned char pollblock[]) { unsigned long int message_action; /* The next line takes bytes 16 to 19 of the polling block and forms them into a word holding the message action number */ message_action = btow(pollblock, 16); switch (message_action) { case 0: QUIT_FLAG = 1; /* Message_Quit - time to go */ break; /* More message actions can be added here */ } } unsigned long int btow(unsigned char block[], int index) { unsigned long int result = 0; int loop; /* This routine takes a data block and a starting byte, and converts the next four bytes into a word - we have to start at the most significant byte and work backwards */ index += 3; result = block[index--]; for(loop = 0; loop < 3; loop++) { result = result << 8; /* this shifts the bits in result left by 8 spaces */ result += block[index--]; } return (result); } void wtob(unsigned long int input, unsigned char block[], int index) { unsigned long int mask = 255; /* The opposite of btow() - this function takes a 32-bit integer, splits it up into 4 bytes, and stores those in 4 consecutive cells of a character array indexed by index. This is done by using a mask to extract the data in sequence, with the & bitwise-and operator */ /* get first byte */ block[index++] = (char) (input & mask); /* shift mask to get second byte, and supply result as byte size */ mask <<= 8; block[index++] = (char) ((input & mask) >> 8); mask <<= 8; block[index++] = (char) ((input & mask) >> 16); mask <<= 8; block[index++] = (char) ((input & mask) >> 24); return; } void mouseclick(unsigned char pollblock[]) { /* We've received a mouse_click event - in more complex systems, we would now decide what had been clicked on, but here all we have to do is prove that we've heard it. */ char message[255]; /* A buffer to hold an 'error' message */ int result, clk; clk = (int) btow(pollblock, 8); strcpy(message, "Mouse click detected (type"); sprintf(message, "%s %d) - do you wish to stop the program?", message, clk); /* The above lines compile an error message using standard string functions */ result = report_error(1, message, 3); /* This calls a function to display an error box on the screen - if the user clicks on OK, the program terminates */ if (result == 1) QUIT_FLAG = 1; } int report_error(int errno, char errmess[], int flags) { unsigned char errorblock[260]; _kernel_swi_regs in, out; /* Set up the standard error block with the error number and message (zero terminated) */ wtob(errno, errorblock, 0); strcpy( (char *) &errorblock[4], errmess); /* R0 - pointer to standard error block R1 - error window flags R2 - pointer to application name for error box title */ in.r[0] = (int) errorblock; in.r[1] = flags; in.r[2] = (int) appname; _kernel_swi(Wimp_ReportError, &in, &out); /* Returns 1 if OK selected, 2 if Cancel selected */ return out.r[1]; }
00000000 2f 2a 20 41 6e 20 65 78 61 6d 70 6c 65 20 70 72 |/* An example pr| 00000010 6f 67 72 61 6d 20 77 68 69 63 68 20 6d 61 6b 65 |ogram which make| 00000020 73 20 75 73 65 20 6f 66 20 74 68 65 20 6b 65 72 |s use of the ker| 00000030 6e 65 6c 20 53 57 49 20 63 61 6c 6c 73 20 2d 0a |nel SWI calls -.| 00000040 20 20 20 74 68 69 73 20 77 69 6c 6c 20 63 6f 6d | this will com| 00000050 70 69 6c 65 20 77 69 74 68 20 41 63 6f 72 6e 27 |pile with Acorn'| 00000060 73 20 43 20 61 73 20 77 65 6c 6c 20 61 73 20 42 |s C as well as B| 00000070 65 65 62 75 67 27 73 20 45 61 73 79 43 20 2a 2f |eebug's EasyC */| 00000080 0a 2f 2a 20 62 79 20 53 74 65 76 65 20 4d 75 6d |./* by Steve Mum| 00000090 66 6f 72 64 20 66 6f 72 20 41 63 6f 72 6e 20 55 |ford for Acorn U| 000000a0 73 65 72 20 2d 20 4d 61 72 63 68 20 31 39 39 36 |ser - March 1996| 000000b0 20 2a 2f 0a 0a 23 69 6e 63 6c 75 64 65 20 3c 73 | */..#include <s| 000000c0 74 64 69 6f 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 |tdio.h>.#include| 000000d0 20 3c 73 74 72 69 6e 67 2e 68 3e 0a 23 69 6e 63 | <string.h>.#inc| 000000e0 6c 75 64 65 20 22 73 77 69 73 2e 68 22 0a 23 69 |lude "swis.h".#i| 000000f0 6e 63 6c 75 64 65 20 22 6b 65 72 6e 65 6c 2e 68 |nclude "kernel.h| 00000100 22 0a 0a 2f 2a 20 57 65 20 61 6c 73 6f 20 64 65 |"../* We also de| 00000110 66 69 6e 65 20 61 20 70 6f 6c 6c 20 6d 61 73 6b |fine a poll mask| 00000120 20 68 65 72 65 20 74 6f 20 74 65 6c 6c 20 74 68 | here to tell th| 00000130 65 20 57 49 4d 50 20 61 62 6f 75 74 20 61 6e 79 |e WIMP about any| 00000140 20 65 76 65 6e 74 73 20 77 65 27 72 65 20 6e 6f | events we're no| 00000150 74 0a 20 20 20 69 6e 74 65 72 65 72 65 73 74 65 |t. interereste| 00000160 64 20 69 6e 20 2a 2f 0a 0a 23 64 65 66 69 6e 65 |d in */..#define| 00000170 20 50 4f 4c 4c 5f 4d 41 53 4b 20 31 0a 0a 2f 2a | POLL_MASK 1../*| 00000180 20 49 66 20 77 65 20 73 65 74 20 51 55 49 54 5f | If we set QUIT_| 00000190 46 4c 41 47 20 75 70 20 61 73 20 61 20 67 6c 6f |FLAG up as a glo| 000001a0 62 61 6c 20 76 61 72 69 61 62 6c 65 2c 20 69 74 |bal variable, it| 000001b0 20 6d 65 61 6e 73 20 74 68 61 74 20 77 65 20 63 | means that we c| 000001c0 61 6e 20 63 68 61 6e 67 65 20 69 74 0a 20 20 20 |an change it. | 000001d0 61 6e 79 77 68 65 72 65 20 77 69 74 68 69 6e 20 |anywhere within | 000001e0 74 68 65 20 70 72 6f 67 72 61 6d 20 61 6e 64 20 |the program and | 000001f0 73 68 75 74 20 74 68 69 6e 67 73 20 64 6f 77 6e |shut things down| 00000200 20 6e 65 78 74 20 74 69 6d 65 20 77 65 20 65 6e | next time we en| 00000210 64 20 74 68 65 0a 20 20 20 70 6f 6c 6c 69 6e 67 |d the. polling| 00000220 20 6c 6f 6f 70 20 2a 2f 0a 0a 69 6e 74 20 51 55 | loop */..int QU| 00000230 49 54 5f 46 4c 41 47 20 3d 20 30 3b 0a 63 68 61 |IT_FLAG = 0;.cha| 00000240 72 20 61 70 70 6e 61 6d 65 5b 5d 20 3d 20 22 57 |r appname[] = "W| 00000250 49 4d 50 43 20 45 78 61 6d 70 6c 65 22 3b 0a 0a |IMPC Example";..| 00000260 2f 2a 20 46 75 6e 63 74 69 6f 6e 20 70 72 6f 74 |/* Function prot| 00000270 6f 74 79 70 69 6e 67 20 2a 2f 0a 0a 69 6e 74 20 |otyping */..int | 00000280 20 20 20 20 20 6d 61 69 6e 28 76 6f 69 64 29 3b | main(void);| 00000290 0a 76 6f 69 64 20 20 20 20 20 77 69 6d 70 6d 73 |.void wimpms| 000002a0 67 28 69 6e 74 2c 20 75 6e 73 69 67 6e 65 64 20 |g(int, unsigned | 000002b0 63 68 61 72 5b 5d 29 3b 0a 75 6e 73 69 67 6e 65 |char[]);.unsigne| 000002c0 64 20 6c 6f 6e 67 20 69 6e 74 20 20 20 62 74 6f |d long int bto| 000002d0 77 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 5b |w(unsigned char[| 000002e0 5d 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 20 20 |], int);.void | 000002f0 20 20 77 74 6f 62 28 75 6e 73 69 67 6e 65 64 20 | wtob(unsigned | 00000300 6c 6f 6e 67 20 69 6e 74 2c 20 75 6e 73 69 67 6e |long int, unsign| 00000310 65 64 20 63 68 61 72 5b 5d 2c 20 69 6e 74 29 3b |ed char[], int);| 00000320 0a 76 6f 69 64 20 20 20 20 20 6d 6f 75 73 65 63 |.void mousec| 00000330 6c 69 63 6b 28 75 6e 73 69 67 6e 65 64 20 63 68 |lick(unsigned ch| 00000340 61 72 5b 5d 29 3b 0a 69 6e 74 20 20 20 20 20 20 |ar[]);.int | 00000350 72 65 70 6f 72 74 5f 65 72 72 6f 72 28 69 6e 74 |report_error(int| 00000360 2c 20 63 68 61 72 5b 5d 2c 20 69 6e 74 29 3b 0a |, char[], int);.| 00000370 0a 2f 2a 20 50 72 6f 67 72 61 6d 20 66 75 6e 63 |./* Program func| 00000380 74 69 6f 6e 73 20 2a 2f 0a 0a 69 6e 74 0a 6d 61 |tions */..int.ma| 00000390 69 6e 28 76 6f 69 64 29 20 7b 0a 20 20 20 20 69 |in(void) {. i| 000003a0 6e 74 20 74 61 73 6b 5f 68 61 6e 64 6c 65 3b 0a |nt task_handle;.| 000003b0 20 20 20 20 75 6e 73 69 67 6e 65 64 20 63 68 61 | unsigned cha| 000003c0 72 20 20 20 70 6f 6c 6c 62 6c 6f 63 6b 5b 32 35 |r pollblock[25| 000003d0 37 5d 3b 0a 20 20 20 20 2f 2a 20 65 73 73 65 6e |7];. /* essen| 000003e0 74 69 61 6c 6c 79 20 61 20 62 79 74 65 20 61 72 |tially a byte ar| 000003f0 72 61 79 20 6c 61 72 67 65 20 65 6e 6f 75 67 68 |ray large enough| 00000400 20 66 6f 72 20 6f 75 72 20 70 6f 6c 6c 69 6e 67 | for our polling| 00000410 20 62 6c 6f 63 6b 20 2a 2f 0a 0a 20 20 20 20 75 | block */.. u| 00000420 6e 73 69 67 6e 65 64 20 63 68 61 72 20 20 69 63 |nsigned char ic| 00000430 6f 6e 62 6c 6f 63 6b 5b 34 30 5d 3b 0a 20 20 20 |onblock[40];. | 00000440 20 69 6e 74 20 69 62 61 72 5f 69 63 6f 6e 5f 68 | int ibar_icon_h| 00000450 61 6e 64 6c 65 3b 0a 20 20 20 20 2f 2a 20 41 20 |andle;. /* A | 00000460 62 6c 6f 63 6b 20 74 6f 20 68 6f 6c 64 20 6f 75 |block to hold ou| 00000470 72 20 69 63 6f 6e 20 64 61 74 61 2c 20 61 6e 64 |r icon data, and| 00000480 20 61 20 76 61 72 69 61 62 6c 65 20 74 6f 20 73 | a variable to s| 00000490 74 6f 72 65 20 69 74 73 20 68 61 6e 64 6c 65 20 |tore its handle | 000004a0 2a 2f 0a 0a 20 20 20 20 69 6e 74 20 70 6f 6c 6c |*/.. int poll| 000004b0 72 65 73 75 6c 74 3b 0a 20 20 20 20 5f 6b 65 72 |result;. _ker| 000004c0 6e 65 6c 5f 73 77 69 5f 72 65 67 73 20 20 20 20 |nel_swi_regs | 000004d0 72 65 67 73 5f 69 6e 2c 20 72 65 67 73 5f 6f 75 |regs_in, regs_ou| 000004e0 74 3b 0a 20 20 20 20 63 68 61 72 20 69 62 61 72 |t;. char ibar| 000004f0 5f 73 70 72 6e 61 6d 65 5b 5d 20 3d 20 22 21 77 |_sprname[] = "!w| 00000500 69 6d 70 63 22 3b 0a 0a 20 20 20 20 2f 2a 20 54 |impc";.. /* T| 00000510 68 65 20 61 62 6f 76 65 20 6c 69 6e 65 20 73 70 |he above line sp| 00000520 65 63 69 66 69 65 73 20 74 68 65 20 6e 61 6d 65 |ecifies the name| 00000530 20 6f 66 20 74 68 65 20 73 70 72 69 74 65 20 69 | of the sprite i| 00000540 6e 20 74 68 65 20 77 69 6d 70 20 70 6f 6f 6c 20 |n the wimp pool | 00000550 74 68 61 74 0a 20 20 20 20 20 20 20 77 65 20 61 |that. we a| 00000560 72 65 20 74 6f 20 75 73 65 20 6f 6e 20 74 68 65 |re to use on the| 00000570 20 69 63 6f 6e 20 62 61 72 20 2a 2f 0a 0a 20 20 | icon bar */.. | 00000580 20 20 6c 6f 6e 67 20 69 6e 74 20 20 20 20 6d 73 | long int ms| 00000590 67 6c 69 73 74 5b 31 5d 20 3d 20 7b 30 7d 3b 0a |glist[1] = {0};.| 000005a0 0a 20 20 20 20 2f 2a 20 4e 6f 77 20 74 6f 20 69 |. /* Now to i| 000005b0 6e 69 74 69 61 6c 69 73 65 20 6f 75 72 73 65 6c |nitialise oursel| 000005c0 76 65 73 20 61 73 20 61 20 74 61 73 6b 20 2a 2f |ves as a task */| 000005d0 0a 20 20 20 20 72 65 67 73 5f 69 6e 2e 72 5b 30 |. regs_in.r[0| 000005e0 5d 20 3d 20 33 31 30 3b 0a 20 20 20 20 72 65 67 |] = 310;. reg| 000005f0 73 5f 69 6e 2e 72 5b 31 5d 20 3d 20 2a 28 69 6e |s_in.r[1] = *(in| 00000600 74 20 2a 29 22 54 41 53 4b 22 3b 0a 20 20 20 20 |t *)"TASK";. | 00000610 72 65 67 73 5f 69 6e 2e 72 5b 32 5d 20 3d 20 28 |regs_in.r[2] = (| 00000620 69 6e 74 29 20 61 70 70 6e 61 6d 65 3b 0a 20 20 |int) appname;. | 00000630 20 20 72 65 67 73 5f 69 6e 2e 72 5b 33 5d 20 3d | regs_in.r[3] =| 00000640 20 28 69 6e 74 29 20 6d 73 67 6c 69 73 74 3b 0a | (int) msglist;.| 00000650 20 20 20 20 2f 2a 20 57 65 20 6e 65 65 64 20 74 | /* We need t| 00000660 6f 20 73 75 70 70 6c 79 20 6f 75 72 20 63 68 6f |o supply our cho| 00000670 73 65 6e 20 52 49 53 43 20 4f 53 20 76 65 72 73 |sen RISC OS vers| 00000680 69 6f 6e 20 6e 75 6d 62 65 72 2c 20 74 68 65 20 |ion number, the | 00000690 22 54 41 53 4b 22 0a 20 20 20 20 20 20 20 69 64 |"TASK". id| 000006a0 65 6e 74 69 66 69 65 72 20 74 6f 20 70 72 6f 76 |entifier to prov| 000006b0 65 20 77 65 27 72 65 20 61 20 6d 75 6c 74 69 74 |e we're a multit| 000006c0 61 73 6b 69 6e 67 20 61 70 70 6c 69 63 61 74 69 |asking applicati| 000006d0 6f 6e 2c 20 61 20 70 6f 69 6e 74 65 72 20 74 6f |on, a pointer to| 000006e0 0a 20 20 20 20 20 20 20 6f 75 72 20 61 70 70 6c |. our appl| 000006f0 69 63 61 74 69 6f 6e 20 6e 61 6d 65 20 61 6e 64 |ication name and| 00000700 20 61 20 70 6f 69 6e 74 65 72 20 74 6f 20 61 20 | a pointer to a | 00000710 6d 65 73 73 61 67 65 20 6c 69 73 74 20 2d 20 63 |message list - c| 00000720 6f 6e 76 65 72 74 65 64 20 74 6f 0a 20 20 20 20 |onverted to. | 00000730 20 20 20 69 6e 74 65 67 65 72 20 66 6f 72 6d 61 | integer forma| 00000740 74 20 61 73 20 6e 65 63 65 73 73 61 72 79 20 2a |t as necessary *| 00000750 2f 0a 0a 20 20 20 20 2f 2a 20 6e 6f 77 20 74 6f |/.. /* now to| 00000760 20 70 65 72 66 6f 72 6d 20 74 68 65 20 61 63 74 | perform the act| 00000770 75 61 6c 20 53 57 49 20 63 61 6c 6c 20 2a 2f 0a |ual SWI call */.| 00000780 20 20 20 20 5f 6b 65 72 6e 65 6c 5f 73 77 69 28 | _kernel_swi(| 00000790 57 69 6d 70 5f 49 6e 69 74 69 61 6c 69 73 65 2c |Wimp_Initialise,| 000007a0 20 26 72 65 67 73 5f 69 6e 2c 20 26 72 65 67 73 | ®s_in, ®s| 000007b0 5f 6f 75 74 29 3b 0a 20 20 20 20 74 61 73 6b 5f |_out);. task_| 000007c0 68 61 6e 64 6c 65 20 3d 20 72 65 67 73 5f 6f 75 |handle = regs_ou| 000007d0 74 2e 72 5b 31 5d 3b 20 2f 2a 20 64 65 74 65 72 |t.r[1]; /* deter| 000007e0 6d 69 6e 65 20 6f 75 72 20 74 61 73 6b 20 68 61 |mine our task ha| 000007f0 6e 64 6c 65 20 66 6f 72 20 6c 61 74 65 72 20 75 |ndle for later u| 00000800 73 65 20 2a 2f 0a 0a 20 20 20 20 2f 2a 20 4e 6f |se */.. /* No| 00000810 77 2c 20 77 65 27 6c 6c 20 70 75 74 20 61 6e 20 |w, we'll put an | 00000820 69 63 6f 6e 20 6f 6e 20 74 68 65 20 69 63 6f 6e |icon on the icon| 00000830 20 62 61 72 20 2d 20 77 65 20 6e 65 65 64 20 74 | bar - we need t| 00000840 6f 20 68 61 76 65 20 64 65 66 69 6e 65 64 20 61 |o have defined a| 00000850 6e 0a 20 20 20 20 20 20 20 69 63 6f 6e 20 62 6c |n. icon bl| 00000860 6f 63 6b 2c 20 77 68 6f 73 65 20 61 64 64 72 65 |ock, whose addre| 00000870 73 73 20 77 65 20 70 61 73 73 20 69 6e 20 52 31 |ss we pass in R1| 00000880 20 2a 2f 0a 0a 20 20 20 20 77 74 6f 62 28 2d 31 | */.. wtob(-1| 00000890 2c 20 69 63 6f 6e 62 6c 6f 63 6b 2c 20 30 29 3b |, iconblock, 0);| 000008a0 20 2f 2a 20 53 70 65 63 69 66 79 20 70 6f 73 69 | /* Specify posi| 000008b0 74 69 6f 6e 20 6f 6e 20 74 68 65 20 69 63 6f 6e |tion on the icon| 000008c0 20 62 61 72 20 28 74 68 65 20 72 69 67 68 74 29 | bar (the right)| 000008d0 20 2a 2f 0a 20 20 20 20 77 74 6f 62 28 30 2c 20 | */. wtob(0, | 000008e0 69 63 6f 6e 62 6c 6f 63 6b 2c 20 34 29 3b 20 2f |iconblock, 4); /| 000008f0 2a 20 54 68 65 73 65 20 66 6f 75 72 20 6c 69 6e |* These four lin| 00000900 65 73 20 67 69 76 65 20 74 68 65 20 62 6f 75 6e |es give the boun| 00000910 64 69 6e 67 20 62 6f 78 20 6f 66 20 74 68 65 20 |ding box of the | 00000920 2a 2f 0a 20 20 20 20 77 74 6f 62 28 30 2c 20 69 |*/. wtob(0, i| 00000930 63 6f 6e 62 6c 6f 63 6b 2c 20 38 29 3b 20 2f 2a |conblock, 8); /*| 00000940 20 69 63 6f 6e 20 2d 20 6d 69 6e 20 78 2c 20 6d | icon - min x, m| 00000950 69 6e 20 79 2c 20 6d 61 78 20 78 2c 20 6d 61 78 |in y, max x, max| 00000960 20 79 20 2a 2f 0a 20 20 20 20 77 74 6f 62 28 37 | y */. wtob(7| 00000970 32 2c 20 69 63 6f 6e 62 6c 6f 63 6b 2c 20 31 32 |2, iconblock, 12| 00000980 29 3b 0a 20 20 20 20 77 74 6f 62 28 37 32 2c 20 |);. wtob(72, | 00000990 69 63 6f 6e 62 6c 6f 63 6b 2c 20 31 36 29 3b 0a |iconblock, 16);.| 000009a0 20 20 20 20 77 74 6f 62 28 31 32 33 31 34 2c 20 | wtob(12314, | 000009b0 69 63 6f 6e 62 6c 6f 63 6b 2c 20 32 30 29 3b 0a |iconblock, 20);.| 000009c0 20 20 20 20 2f 2a 20 73 65 74 20 62 69 74 73 20 | /* set bits | 000009d0 31 2c 20 33 2c 20 34 2c 20 31 32 2c 20 31 33 20 |1, 3, 4, 12, 13 | 000009e0 6f 66 20 69 63 6f 6e 20 66 6c 61 67 73 20 2d 20 |of icon flags - | 000009f0 62 69 74 20 31 20 2d 20 74 68 65 20 69 63 6f 6e |bit 1 - the icon| 00000a00 20 69 73 20 61 20 73 70 72 69 74 65 3b 0a 20 20 | is a sprite;. | 00000a10 20 20 62 69 74 73 20 33 2c 20 34 20 63 65 6e 74 | bits 3, 4 cent| 00000a20 72 65 20 74 68 65 20 73 70 72 69 74 65 20 69 6e |re the sprite in| 00000a30 20 74 68 65 20 62 6f 75 6e 64 69 6e 67 20 62 6f | the bounding bo| 00000a40 78 3b 20 62 69 74 73 20 31 32 20 61 6e 64 20 31 |x; bits 12 and 1| 00000a50 33 20 69 6e 66 6f 72 6d 20 74 68 65 0a 20 20 20 |3 inform the. | 00000a60 20 57 49 4d 50 20 74 6f 20 6c 65 74 20 75 73 20 | WIMP to let us | 00000a70 6b 6e 6f 77 20 77 68 65 6e 20 6f 75 72 20 69 63 |know when our ic| 00000a80 6f 6e 20 69 73 20 63 6c 69 63 6b 65 64 20 6f 6e |on is clicked on| 00000a90 2c 20 62 79 20 70 61 73 73 69 6e 67 20 75 73 20 |, by passing us | 00000aa0 61 0a 20 20 20 20 4d 6f 75 73 65 5f 43 6c 69 63 |a. Mouse_Clic| 00000ab0 6b 20 65 76 65 6e 74 20 2a 2f 0a 0a 20 20 20 20 |k event */.. | 00000ac0 73 74 72 63 70 79 28 20 28 63 68 61 72 20 2a 29 |strcpy( (char *)| 00000ad0 20 26 69 63 6f 6e 62 6c 6f 63 6b 5b 32 34 5d 2c | &iconblock[24],| 00000ae0 20 69 62 61 72 5f 73 70 72 6e 61 6d 65 29 3b 0a | ibar_sprname);.| 00000af0 20 20 20 20 2f 2a 20 46 69 6e 61 6c 6c 79 2c 20 | /* Finally, | 00000b00 63 6f 70 79 20 74 68 65 20 6e 61 6d 65 20 6f 66 |copy the name of| 00000b10 20 74 68 65 20 73 70 72 69 74 65 20 77 65 20 61 | the sprite we a| 00000b20 72 65 20 74 6f 20 75 73 65 20 69 6e 74 6f 20 74 |re to use into t| 00000b30 68 65 20 64 61 74 61 62 6c 6f 63 6b 3b 0a 20 20 |he datablock;. | 00000b40 20 20 74 68 69 73 20 6d 75 73 74 20 62 65 20 74 | this must be t| 00000b50 65 72 6d 69 6e 61 74 65 64 20 77 69 74 68 20 61 |erminated with a| 00000b60 20 63 6f 6e 74 72 6f 6c 20 63 68 61 72 61 63 74 | control charact| 00000b70 65 72 20 2a 2f 0a 0a 20 20 20 20 72 65 67 73 5f |er */.. regs_| 00000b80 69 6e 2e 72 5b 30 5d 20 3d 20 30 3b 20 2f 2a 20 |in.r[0] = 0; /* | 00000b90 73 65 74 20 74 68 65 20 69 63 6f 6e 27 73 20 70 |set the icon's p| 00000ba0 72 69 6f 72 69 74 79 20 2a 2f 0a 20 20 20 20 72 |riority */. r| 00000bb0 65 67 73 5f 69 6e 2e 72 5b 31 5d 20 3d 20 28 69 |egs_in.r[1] = (i| 00000bc0 6e 74 29 20 69 63 6f 6e 62 6c 6f 63 6b 3b 0a 20 |nt) iconblock;. | 00000bd0 20 20 20 5f 6b 65 72 6e 65 6c 5f 73 77 69 28 57 | _kernel_swi(W| 00000be0 69 6d 70 5f 43 72 65 61 74 65 49 63 6f 6e 2c 20 |imp_CreateIcon, | 00000bf0 26 72 65 67 73 5f 69 6e 2c 20 26 72 65 67 73 5f |®s_in, ®s_| 00000c00 6f 75 74 29 3b 0a 20 20 20 20 69 62 61 72 5f 69 |out);. ibar_i| 00000c10 63 6f 6e 5f 68 61 6e 64 6c 65 20 3d 20 72 65 67 |con_handle = reg| 00000c20 73 5f 6f 75 74 2e 72 5b 30 5d 3b 0a 0a 20 20 20 |s_out.r[0];.. | 00000c30 20 64 6f 20 7b 0a 20 20 20 20 20 20 20 20 72 65 | do {. re| 00000c40 67 73 5f 69 6e 2e 72 5b 30 5d 20 3d 20 50 4f 4c |gs_in.r[0] = POL| 00000c50 4c 5f 4d 41 53 4b 3b 0a 20 20 20 20 20 20 20 20 |L_MASK;. | 00000c60 72 65 67 73 5f 69 6e 2e 72 5b 31 5d 20 3d 20 28 |regs_in.r[1] = (| 00000c70 69 6e 74 29 20 70 6f 6c 6c 62 6c 6f 63 6b 3b 20 |int) pollblock; | 00000c80 2f 2a 20 61 20 70 6f 69 6e 74 65 72 20 74 6f 20 |/* a pointer to | 00000c90 6f 75 72 20 64 61 74 61 20 62 6c 6f 63 6b 20 2a |our data block *| 00000ca0 2f 0a 0a 20 20 20 20 20 20 20 20 5f 6b 65 72 6e |/.. _kern| 00000cb0 65 6c 5f 73 77 69 28 57 69 6d 70 5f 50 6f 6c 6c |el_swi(Wimp_Poll| 00000cc0 2c 20 26 72 65 67 73 5f 69 6e 2c 20 26 72 65 67 |, ®s_in, ®| 00000cd0 73 5f 6f 75 74 29 3b 0a 20 20 20 20 20 20 20 20 |s_out);. | 00000ce0 70 6f 6c 6c 72 65 73 75 6c 74 20 3d 20 72 65 67 |pollresult = reg| 00000cf0 73 5f 6f 75 74 2e 72 5b 30 5d 3b 20 2f 2a 20 64 |s_out.r[0]; /* d| 00000d00 65 74 65 72 6d 69 6e 65 20 74 68 65 20 65 76 65 |etermine the eve| 00000d10 6e 74 20 63 6f 64 65 20 2a 2f 0a 20 20 20 20 20 |nt code */. | 00000d20 20 20 20 73 77 69 74 63 68 20 28 70 6f 6c 6c 72 | switch (pollr| 00000d30 65 73 75 6c 74 29 20 7b 0a 20 20 20 20 20 20 20 |esult) {. | 00000d40 20 20 20 20 20 63 61 73 65 20 20 36 3a 20 6d 6f | case 6: mo| 00000d50 75 73 65 63 6c 69 63 6b 28 70 6f 6c 6c 62 6c 6f |useclick(pollblo| 00000d60 63 6b 29 3b 0a 20 20 20 20 20 20 20 20 20 20 20 |ck);. | 00000d70 20 20 20 20 20 20 20 20 20 20 62 72 65 61 6b 3b | break;| 00000d80 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 |. | 00000d90 20 20 20 20 20 20 2f 2a 20 49 66 20 6f 75 72 20 | /* If our | 00000da0 69 63 6f 6e 20 69 73 20 63 6c 69 63 6b 65 64 20 |icon is clicked | 00000db0 6f 6e 2c 20 77 65 20 6a 75 6d 70 20 74 6f 20 6d |on, we jump to m| 00000dc0 6f 75 73 65 63 6c 69 63 6b 28 29 20 2a 2f 0a 20 |ouseclick() */. | 00000dd0 20 20 20 20 20 20 20 20 20 20 20 63 61 73 65 20 | case | 00000de0 31 37 3a 0a 20 20 20 20 20 20 20 20 20 20 20 20 |17:. | 00000df0 63 61 73 65 20 31 38 3a 0a 20 20 20 20 20 20 20 |case 18:. | 00000e00 20 20 20 20 20 63 61 73 65 20 31 39 3a 20 77 69 | case 19: wi| 00000e10 6d 70 6d 73 67 28 70 6f 6c 6c 72 65 73 75 6c 74 |mpmsg(pollresult| 00000e20 2c 20 70 6f 6c 6c 62 6c 6f 63 6b 29 3b 0a 20 20 |, pollblock);. | 00000e30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 62 72 | br| 00000e40 65 61 6b 3b 0a 20 20 20 20 20 20 20 20 20 20 20 |eak;. | 00000e50 20 2f 2a 20 54 68 65 20 61 62 6f 76 65 20 73 65 | /* The above se| 00000e60 63 74 69 6f 6e 20 6c 69 73 74 65 6e 73 20 66 6f |ction listens fo| 00000e70 72 20 65 76 65 6e 74 20 63 6f 64 65 73 20 31 37 |r event codes 17| 00000e80 2c 20 31 38 20 61 6e 64 20 31 39 20 2d 20 74 68 |, 18 and 19 - th| 00000e90 65 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 |e. | 00000ea0 20 6f 6e 65 73 20 77 68 69 63 68 20 69 6e 64 69 | ones which indi| 00000eb0 63 61 74 65 20 77 65 27 72 65 20 62 65 69 6e 67 |cate we're being| 00000ec0 20 73 65 6e 74 20 61 20 6d 65 73 73 61 67 65 20 | sent a message | 00000ed0 2a 2f 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 |*/. }. | 00000ee0 20 7d 20 77 68 69 6c 65 20 28 51 55 49 54 5f 46 | } while (QUIT_F| 00000ef0 4c 41 47 20 3d 3d 20 30 29 3b 0a 20 20 20 20 2f |LAG == 0);. /| 00000f00 2a 20 49 66 20 51 55 49 54 5f 46 4c 41 47 20 63 |* If QUIT_FLAG c| 00000f10 68 61 6e 67 65 73 20 74 6f 20 61 6e 79 74 68 69 |hanges to anythi| 00000f20 6e 67 20 62 75 74 20 30 2c 20 77 65 20 73 74 6f |ng but 0, we sto| 00000f30 70 20 67 6f 69 6e 67 20 72 6f 75 6e 64 20 74 68 |p going round th| 00000f40 65 20 70 6f 6c 6c 69 6e 67 0a 20 20 20 20 20 20 |e polling. | 00000f50 20 6c 6f 6f 70 20 61 6e 64 20 73 68 75 74 20 64 | loop and shut d| 00000f60 6f 77 6e 20 2a 2f 0a 0a 0a 20 20 20 20 72 65 67 |own */... reg| 00000f70 73 5f 69 6e 2e 72 5b 30 5d 20 3d 20 74 61 73 6b |s_in.r[0] = task| 00000f80 5f 68 61 6e 64 6c 65 3b 0a 20 20 20 20 72 65 67 |_handle;. reg| 00000f90 73 5f 69 6e 2e 72 5b 31 5d 20 3d 20 2a 28 69 6e |s_in.r[1] = *(in| 00000fa0 74 20 2a 29 22 54 41 53 4b 22 3b 0a 20 20 20 20 |t *)"TASK";. | 00000fb0 5f 6b 65 72 6e 65 6c 5f 73 77 69 28 57 69 6d 70 |_kernel_swi(Wimp| 00000fc0 5f 43 6c 6f 73 65 44 6f 77 6e 2c 20 26 72 65 67 |_CloseDown, ®| 00000fd0 73 5f 69 6e 2c 20 26 72 65 67 73 5f 6f 75 74 29 |s_in, ®s_out)| 00000fe0 3b 0a 20 20 20 20 2f 2a 20 41 6e 64 20 74 68 61 |;. /* And tha| 00000ff0 74 27 73 20 69 74 20 2d 20 77 65 27 76 65 20 74 |t's it - we've t| 00001000 6f 6c 64 20 74 68 65 20 57 49 4d 50 20 74 68 61 |old the WIMP tha| 00001010 74 20 77 65 27 76 65 20 66 69 6e 69 73 68 65 64 |t we've finished| 00001020 2c 20 61 6e 64 20 6e 6f 77 20 74 68 65 0a 20 20 |, and now the. | 00001030 20 20 20 20 20 70 72 6f 67 72 61 6d 20 74 65 72 | program ter| 00001040 6d 69 6e 61 74 65 73 2e 20 2a 2f 0a 7d 0a 0a 76 |minates. */.}..v| 00001050 6f 69 64 0a 77 69 6d 70 6d 73 67 28 69 6e 74 20 |oid.wimpmsg(int | 00001060 72 65 73 75 6c 74 2c 20 75 6e 73 69 67 6e 65 64 |result, unsigned| 00001070 20 63 68 61 72 20 70 6f 6c 6c 62 6c 6f 63 6b 5b | char pollblock[| 00001080 5d 29 0a 7b 0a 20 20 20 20 75 6e 73 69 67 6e 65 |]).{. unsigne| 00001090 64 20 6c 6f 6e 67 20 69 6e 74 20 20 20 6d 65 73 |d long int mes| 000010a0 73 61 67 65 5f 61 63 74 69 6f 6e 3b 0a 0a 20 20 |sage_action;.. | 000010b0 20 20 2f 2a 20 54 68 65 20 6e 65 78 74 20 6c 69 | /* The next li| 000010c0 6e 65 20 74 61 6b 65 73 20 62 79 74 65 73 20 31 |ne takes bytes 1| 000010d0 36 20 74 6f 20 31 39 20 6f 66 20 74 68 65 20 70 |6 to 19 of the p| 000010e0 6f 6c 6c 69 6e 67 20 62 6c 6f 63 6b 20 61 6e 64 |olling block and| 000010f0 20 66 6f 72 6d 73 20 74 68 65 6d 0a 20 20 20 20 | forms them. | 00001100 20 20 20 69 6e 74 6f 20 61 20 77 6f 72 64 20 68 | into a word h| 00001110 6f 6c 64 69 6e 67 20 74 68 65 20 6d 65 73 73 61 |olding the messa| 00001120 67 65 20 61 63 74 69 6f 6e 20 6e 75 6d 62 65 72 |ge action number| 00001130 20 2a 2f 0a 20 20 20 20 6d 65 73 73 61 67 65 5f | */. message_| 00001140 61 63 74 69 6f 6e 20 3d 20 62 74 6f 77 28 70 6f |action = btow(po| 00001150 6c 6c 62 6c 6f 63 6b 2c 20 31 36 29 3b 0a 20 20 |llblock, 16);. | 00001160 20 20 0a 20 20 20 20 73 77 69 74 63 68 20 28 6d | . switch (m| 00001170 65 73 73 61 67 65 5f 61 63 74 69 6f 6e 29 20 7b |essage_action) {| 00001180 0a 20 20 20 20 20 20 20 20 63 61 73 65 20 30 3a |. case 0:| 00001190 20 51 55 49 54 5f 46 4c 41 47 20 3d 20 31 3b 20 | QUIT_FLAG = 1; | 000011a0 2f 2a 20 4d 65 73 73 61 67 65 5f 51 75 69 74 20 |/* Message_Quit | 000011b0 2d 20 74 69 6d 65 20 74 6f 20 67 6f 20 2a 2f 0a |- time to go */.| 000011c0 20 20 20 20 20 20 20 20 20 20 20 20 62 72 65 61 | brea| 000011d0 6b 3b 0a 20 20 20 20 20 20 20 20 2f 2a 20 4d 6f |k;. /* Mo| 000011e0 72 65 20 6d 65 73 73 61 67 65 20 61 63 74 69 6f |re message actio| 000011f0 6e 73 20 63 61 6e 20 62 65 20 61 64 64 65 64 20 |ns can be added | 00001200 68 65 72 65 20 2a 2f 0a 20 20 20 20 7d 0a 7d 0a |here */. }.}.| 00001210 0a 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 20 69 |.unsigned long i| 00001220 6e 74 0a 62 74 6f 77 28 75 6e 73 69 67 6e 65 64 |nt.btow(unsigned| 00001230 20 63 68 61 72 20 62 6c 6f 63 6b 5b 5d 2c 20 69 | char block[], i| 00001240 6e 74 20 69 6e 64 65 78 29 0a 7b 0a 20 20 20 20 |nt index).{. | 00001250 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 20 69 6e |unsigned long in| 00001260 74 20 20 20 72 65 73 75 6c 74 20 3d 20 30 3b 0a |t result = 0;.| 00001270 20 20 20 20 69 6e 74 20 6c 6f 6f 70 3b 0a 0a 20 | int loop;.. | 00001280 20 20 20 2f 2a 20 54 68 69 73 20 72 6f 75 74 69 | /* This routi| 00001290 6e 65 20 74 61 6b 65 73 20 61 20 64 61 74 61 20 |ne takes a data | 000012a0 62 6c 6f 63 6b 20 61 6e 64 20 61 20 73 74 61 72 |block and a star| 000012b0 74 69 6e 67 20 62 79 74 65 2c 20 61 6e 64 20 63 |ting byte, and c| 000012c0 6f 6e 76 65 72 74 73 20 74 68 65 0a 20 20 20 20 |onverts the. | 000012d0 20 20 20 6e 65 78 74 20 66 6f 75 72 20 62 79 74 | next four byt| 000012e0 65 73 20 69 6e 74 6f 20 61 20 77 6f 72 64 20 2d |es into a word -| 000012f0 20 77 65 20 68 61 76 65 20 74 6f 20 73 74 61 72 | we have to star| 00001300 74 20 61 74 20 74 68 65 20 6d 6f 73 74 20 73 69 |t at the most si| 00001310 67 6e 69 66 69 63 61 6e 74 0a 20 20 20 20 20 20 |gnificant. | 00001320 20 62 79 74 65 20 61 6e 64 20 77 6f 72 6b 20 62 | byte and work b| 00001330 61 63 6b 77 61 72 64 73 20 2a 2f 0a 0a 20 20 20 |ackwards */.. | 00001340 20 69 6e 64 65 78 20 2b 3d 20 33 3b 0a 20 20 20 | index += 3;. | 00001350 20 72 65 73 75 6c 74 20 3d 20 62 6c 6f 63 6b 5b | result = block[| 00001360 69 6e 64 65 78 2d 2d 5d 3b 0a 20 20 20 20 66 6f |index--];. fo| 00001370 72 28 6c 6f 6f 70 20 3d 20 30 3b 20 6c 6f 6f 70 |r(loop = 0; loop| 00001380 20 3c 20 33 3b 20 6c 6f 6f 70 2b 2b 29 20 7b 0a | < 3; loop++) {.| 00001390 20 20 20 20 20 20 20 20 72 65 73 75 6c 74 20 3d | result =| 000013a0 20 72 65 73 75 6c 74 20 3c 3c 20 38 3b 0a 20 20 | result << 8;. | 000013b0 20 20 20 20 20 20 2f 2a 20 74 68 69 73 20 73 68 | /* this sh| 000013c0 69 66 74 73 20 74 68 65 20 62 69 74 73 20 69 6e |ifts the bits in| 000013d0 20 72 65 73 75 6c 74 20 6c 65 66 74 20 62 79 20 | result left by | 000013e0 38 20 73 70 61 63 65 73 20 2a 2f 0a 20 20 20 20 |8 spaces */. | 000013f0 20 20 20 20 72 65 73 75 6c 74 20 2b 3d 20 62 6c | result += bl| 00001400 6f 63 6b 5b 69 6e 64 65 78 2d 2d 5d 3b 0a 20 20 |ock[index--];. | 00001410 20 20 7d 0a 0a 20 20 20 20 72 65 74 75 72 6e 20 | }.. return | 00001420 28 72 65 73 75 6c 74 29 3b 0a 7d 0a 0a 76 6f 69 |(result);.}..voi| 00001430 64 0a 77 74 6f 62 28 75 6e 73 69 67 6e 65 64 20 |d.wtob(unsigned | 00001440 6c 6f 6e 67 20 69 6e 74 20 69 6e 70 75 74 2c 20 |long int input, | 00001450 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20 62 6c |unsigned char bl| 00001460 6f 63 6b 5b 5d 2c 20 69 6e 74 20 69 6e 64 65 78 |ock[], int index| 00001470 29 0a 7b 0a 20 20 20 75 6e 73 69 67 6e 65 64 20 |).{. unsigned | 00001480 6c 6f 6e 67 20 69 6e 74 20 6d 61 73 6b 20 3d 20 |long int mask = | 00001490 32 35 35 3b 0a 0a 20 20 20 2f 2a 20 54 68 65 20 |255;.. /* The | 000014a0 6f 70 70 6f 73 69 74 65 20 6f 66 20 62 74 6f 77 |opposite of btow| 000014b0 28 29 20 2d 20 74 68 69 73 20 66 75 6e 63 74 69 |() - this functi| 000014c0 6f 6e 20 74 61 6b 65 73 20 61 20 33 32 2d 62 69 |on takes a 32-bi| 000014d0 74 20 69 6e 74 65 67 65 72 2c 20 73 70 6c 69 74 |t integer, split| 000014e0 73 0a 20 20 20 20 20 20 69 74 20 75 70 20 69 6e |s. it up in| 000014f0 74 6f 20 34 20 62 79 74 65 73 2c 20 61 6e 64 20 |to 4 bytes, and | 00001500 73 74 6f 72 65 73 20 74 68 6f 73 65 20 69 6e 20 |stores those in | 00001510 34 20 63 6f 6e 73 65 63 75 74 69 76 65 20 63 65 |4 consecutive ce| 00001520 6c 6c 73 20 6f 66 20 61 0a 20 20 20 20 20 20 63 |lls of a. c| 00001530 68 61 72 61 63 74 65 72 20 61 72 72 61 79 20 69 |haracter array i| 00001540 6e 64 65 78 65 64 20 62 79 20 69 6e 64 65 78 2e |ndexed by index.| 00001550 20 54 68 69 73 20 69 73 20 64 6f 6e 65 20 62 79 | This is done by| 00001560 20 75 73 69 6e 67 20 61 20 6d 61 73 6b 20 74 6f | using a mask to| 00001570 0a 20 20 20 20 20 20 65 78 74 72 61 63 74 20 74 |. extract t| 00001580 68 65 20 64 61 74 61 20 69 6e 20 73 65 71 75 65 |he data in seque| 00001590 6e 63 65 2c 20 77 69 74 68 20 74 68 65 20 26 20 |nce, with the & | 000015a0 62 69 74 77 69 73 65 2d 61 6e 64 20 6f 70 65 72 |bitwise-and oper| 000015b0 61 74 6f 72 20 2a 2f 0a 0a 20 20 20 2f 2a 20 67 |ator */.. /* g| 000015c0 65 74 20 66 69 72 73 74 20 62 79 74 65 20 2a 2f |et first byte */| 000015d0 0a 20 20 20 62 6c 6f 63 6b 5b 69 6e 64 65 78 2b |. block[index+| 000015e0 2b 5d 20 3d 20 28 63 68 61 72 29 20 28 69 6e 70 |+] = (char) (inp| 000015f0 75 74 20 26 20 6d 61 73 6b 29 3b 0a 20 20 20 2f |ut & mask);. /| 00001600 2a 20 73 68 69 66 74 20 6d 61 73 6b 20 74 6f 20 |* shift mask to | 00001610 67 65 74 20 73 65 63 6f 6e 64 20 62 79 74 65 2c |get second byte,| 00001620 20 61 6e 64 20 73 75 70 70 6c 79 20 72 65 73 75 | and supply resu| 00001630 6c 74 20 61 73 20 62 79 74 65 20 73 69 7a 65 20 |lt as byte size | 00001640 2a 2f 0a 20 20 20 6d 61 73 6b 20 3c 3c 3d 20 38 |*/. mask <<= 8| 00001650 3b 0a 20 20 20 62 6c 6f 63 6b 5b 69 6e 64 65 78 |;. block[index| 00001660 2b 2b 5d 20 3d 20 28 63 68 61 72 29 20 28 28 69 |++] = (char) ((i| 00001670 6e 70 75 74 20 26 20 6d 61 73 6b 29 20 3e 3e 20 |nput & mask) >> | 00001680 38 29 3b 0a 20 20 20 6d 61 73 6b 20 3c 3c 3d 20 |8);. mask <<= | 00001690 38 3b 0a 20 20 20 62 6c 6f 63 6b 5b 69 6e 64 65 |8;. block[inde| 000016a0 78 2b 2b 5d 20 3d 20 28 63 68 61 72 29 20 28 28 |x++] = (char) ((| 000016b0 69 6e 70 75 74 20 26 20 6d 61 73 6b 29 20 3e 3e |input & mask) >>| 000016c0 20 31 36 29 3b 0a 20 20 20 6d 61 73 6b 20 3c 3c | 16);. mask <<| 000016d0 3d 20 38 3b 0a 20 20 20 62 6c 6f 63 6b 5b 69 6e |= 8;. block[in| 000016e0 64 65 78 2b 2b 5d 20 3d 20 28 63 68 61 72 29 20 |dex++] = (char) | 000016f0 28 28 69 6e 70 75 74 20 26 20 6d 61 73 6b 29 20 |((input & mask) | 00001700 3e 3e 20 32 34 29 3b 0a 0a 20 20 20 72 65 74 75 |>> 24);.. retu| 00001710 72 6e 3b 0a 7d 0a 0a 76 6f 69 64 0a 6d 6f 75 73 |rn;.}..void.mous| 00001720 65 63 6c 69 63 6b 28 75 6e 73 69 67 6e 65 64 20 |eclick(unsigned | 00001730 63 68 61 72 20 70 6f 6c 6c 62 6c 6f 63 6b 5b 5d |char pollblock[]| 00001740 29 0a 7b 0a 20 20 20 2f 2a 20 57 65 27 76 65 20 |).{. /* We've | 00001750 72 65 63 65 69 76 65 64 20 61 20 6d 6f 75 73 65 |received a mouse| 00001760 5f 63 6c 69 63 6b 20 65 76 65 6e 74 20 2d 20 69 |_click event - i| 00001770 6e 20 6d 6f 72 65 20 63 6f 6d 70 6c 65 78 20 73 |n more complex s| 00001780 79 73 74 65 6d 73 2c 20 77 65 20 77 6f 75 6c 64 |ystems, we would| 00001790 0a 20 20 20 20 20 20 6e 6f 77 20 64 65 63 69 64 |. now decid| 000017a0 65 20 77 68 61 74 20 68 61 64 20 62 65 65 6e 20 |e what had been | 000017b0 63 6c 69 63 6b 65 64 20 6f 6e 2c 20 62 75 74 20 |clicked on, but | 000017c0 68 65 72 65 20 61 6c 6c 20 77 65 20 68 61 76 65 |here all we have| 000017d0 20 74 6f 20 64 6f 20 69 73 0a 20 20 20 20 20 20 | to do is. | 000017e0 70 72 6f 76 65 20 74 68 61 74 20 77 65 27 76 65 |prove that we've| 000017f0 20 68 65 61 72 64 20 69 74 2e 20 2a 2f 0a 20 20 | heard it. */. | 00001800 20 63 68 61 72 20 6d 65 73 73 61 67 65 5b 32 35 | char message[25| 00001810 35 5d 3b 0a 20 20 20 2f 2a 20 41 20 62 75 66 66 |5];. /* A buff| 00001820 65 72 20 74 6f 20 68 6f 6c 64 20 61 6e 20 27 65 |er to hold an 'e| 00001830 72 72 6f 72 27 20 6d 65 73 73 61 67 65 20 2a 2f |rror' message */| 00001840 0a 0a 20 20 20 69 6e 74 20 72 65 73 75 6c 74 2c |.. int result,| 00001850 20 63 6c 6b 3b 0a 0a 20 20 20 63 6c 6b 20 3d 20 | clk;.. clk = | 00001860 28 69 6e 74 29 20 62 74 6f 77 28 70 6f 6c 6c 62 |(int) btow(pollb| 00001870 6c 6f 63 6b 2c 20 38 29 3b 0a 20 20 20 73 74 72 |lock, 8);. str| 00001880 63 70 79 28 6d 65 73 73 61 67 65 2c 20 22 4d 6f |cpy(message, "Mo| 00001890 75 73 65 20 63 6c 69 63 6b 20 64 65 74 65 63 74 |use click detect| 000018a0 65 64 20 28 74 79 70 65 22 29 3b 0a 20 20 20 73 |ed (type");. s| 000018b0 70 72 69 6e 74 66 28 6d 65 73 73 61 67 65 2c 20 |printf(message, | 000018c0 22 25 73 20 25 64 29 20 2d 20 64 6f 20 79 6f 75 |"%s %d) - do you| 000018d0 20 77 69 73 68 20 74 6f 20 73 74 6f 70 20 74 68 | wish to stop th| 000018e0 65 20 70 72 6f 67 72 61 6d 3f 22 2c 20 6d 65 73 |e program?", mes| 000018f0 73 61 67 65 2c 20 63 6c 6b 29 3b 0a 0a 20 20 20 |sage, clk);.. | 00001900 2f 2a 20 54 68 65 20 61 62 6f 76 65 20 6c 69 6e |/* The above lin| 00001910 65 73 20 63 6f 6d 70 69 6c 65 20 61 6e 20 65 72 |es compile an er| 00001920 72 6f 72 20 6d 65 73 73 61 67 65 20 75 73 69 6e |ror message usin| 00001930 67 20 73 74 61 6e 64 61 72 64 20 73 74 72 69 6e |g standard strin| 00001940 67 0a 20 20 20 20 20 20 66 75 6e 63 74 69 6f 6e |g. function| 00001950 73 20 2a 2f 0a 0a 20 20 20 72 65 73 75 6c 74 20 |s */.. result | 00001960 3d 20 72 65 70 6f 72 74 5f 65 72 72 6f 72 28 31 |= report_error(1| 00001970 2c 20 6d 65 73 73 61 67 65 2c 20 33 29 3b 0a 20 |, message, 3);. | 00001980 20 20 2f 2a 20 54 68 69 73 20 63 61 6c 6c 73 20 | /* This calls | 00001990 61 20 66 75 6e 63 74 69 6f 6e 20 74 6f 20 64 69 |a function to di| 000019a0 73 70 6c 61 79 20 61 6e 20 65 72 72 6f 72 20 62 |splay an error b| 000019b0 6f 78 20 6f 6e 20 74 68 65 20 73 63 72 65 65 6e |ox on the screen| 000019c0 20 2d 20 69 66 20 74 68 65 0a 20 20 20 20 20 20 | - if the. | 000019d0 75 73 65 72 20 63 6c 69 63 6b 73 20 6f 6e 20 4f |user clicks on O| 000019e0 4b 2c 20 74 68 65 20 70 72 6f 67 72 61 6d 20 74 |K, the program t| 000019f0 65 72 6d 69 6e 61 74 65 73 20 2a 2f 0a 0a 20 20 |erminates */.. | 00001a00 20 69 66 20 28 72 65 73 75 6c 74 20 3d 3d 20 31 | if (result == 1| 00001a10 29 20 51 55 49 54 5f 46 4c 41 47 20 3d 20 31 3b |) QUIT_FLAG = 1;| 00001a20 0a 7d 0a 0a 69 6e 74 0a 72 65 70 6f 72 74 5f 65 |.}..int.report_e| 00001a30 72 72 6f 72 28 69 6e 74 20 65 72 72 6e 6f 2c 20 |rror(int errno, | 00001a40 63 68 61 72 20 65 72 72 6d 65 73 73 5b 5d 2c 20 |char errmess[], | 00001a50 69 6e 74 20 66 6c 61 67 73 29 0a 7b 0a 20 20 20 |int flags).{. | 00001a60 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20 65 72 |unsigned char er| 00001a70 72 6f 72 62 6c 6f 63 6b 5b 32 36 30 5d 3b 0a 20 |rorblock[260];. | 00001a80 20 20 5f 6b 65 72 6e 65 6c 5f 73 77 69 5f 72 65 | _kernel_swi_re| 00001a90 67 73 20 69 6e 2c 20 6f 75 74 3b 0a 0a 20 20 20 |gs in, out;.. | 00001aa0 2f 2a 20 53 65 74 20 75 70 20 74 68 65 20 73 74 |/* Set up the st| 00001ab0 61 6e 64 61 72 64 20 65 72 72 6f 72 20 62 6c 6f |andard error blo| 00001ac0 63 6b 20 77 69 74 68 20 74 68 65 20 65 72 72 6f |ck with the erro| 00001ad0 72 20 6e 75 6d 62 65 72 20 61 6e 64 20 6d 65 73 |r number and mes| 00001ae0 73 61 67 65 0a 20 20 20 20 20 20 28 7a 65 72 6f |sage. (zero| 00001af0 20 74 65 72 6d 69 6e 61 74 65 64 29 20 2a 2f 0a | terminated) */.| 00001b00 20 20 20 77 74 6f 62 28 65 72 72 6e 6f 2c 20 65 | wtob(errno, e| 00001b10 72 72 6f 72 62 6c 6f 63 6b 2c 20 30 29 3b 0a 20 |rrorblock, 0);. | 00001b20 20 20 73 74 72 63 70 79 28 20 28 63 68 61 72 20 | strcpy( (char | 00001b30 2a 29 20 26 65 72 72 6f 72 62 6c 6f 63 6b 5b 34 |*) &errorblock[4| 00001b40 5d 2c 20 65 72 72 6d 65 73 73 29 3b 0a 0a 20 20 |], errmess);.. | 00001b50 20 2f 2a 20 52 30 20 2d 20 70 6f 69 6e 74 65 72 | /* R0 - pointer| 00001b60 20 74 6f 20 73 74 61 6e 64 61 72 64 20 65 72 72 | to standard err| 00001b70 6f 72 20 62 6c 6f 63 6b 0a 20 20 20 20 20 20 52 |or block. R| 00001b80 31 20 2d 20 65 72 72 6f 72 20 77 69 6e 64 6f 77 |1 - error window| 00001b90 20 66 6c 61 67 73 0a 20 20 20 20 20 20 52 32 20 | flags. R2 | 00001ba0 2d 20 70 6f 69 6e 74 65 72 20 74 6f 20 61 70 70 |- pointer to app| 00001bb0 6c 69 63 61 74 69 6f 6e 20 6e 61 6d 65 20 66 6f |lication name fo| 00001bc0 72 20 65 72 72 6f 72 20 62 6f 78 20 74 69 74 6c |r error box titl| 00001bd0 65 20 2a 2f 0a 0a 20 20 20 69 6e 2e 72 5b 30 5d |e */.. in.r[0]| 00001be0 20 3d 20 28 69 6e 74 29 20 65 72 72 6f 72 62 6c | = (int) errorbl| 00001bf0 6f 63 6b 3b 0a 20 20 20 69 6e 2e 72 5b 31 5d 20 |ock;. in.r[1] | 00001c00 3d 20 66 6c 61 67 73 3b 0a 20 20 20 69 6e 2e 72 |= flags;. in.r| 00001c10 5b 32 5d 20 3d 20 28 69 6e 74 29 20 61 70 70 6e |[2] = (int) appn| 00001c20 61 6d 65 3b 0a 0a 20 20 20 5f 6b 65 72 6e 65 6c |ame;.. _kernel| 00001c30 5f 73 77 69 28 57 69 6d 70 5f 52 65 70 6f 72 74 |_swi(Wimp_Report| 00001c40 45 72 72 6f 72 2c 20 26 69 6e 2c 20 26 6f 75 74 |Error, &in, &out| 00001c50 29 3b 0a 0a 20 20 20 2f 2a 20 52 65 74 75 72 6e |);.. /* Return| 00001c60 73 20 31 20 69 66 20 4f 4b 20 73 65 6c 65 63 74 |s 1 if OK select| 00001c70 65 64 2c 20 32 20 69 66 20 43 61 6e 63 65 6c 20 |ed, 2 if Cancel | 00001c80 73 65 6c 65 63 74 65 64 20 2a 2f 0a 20 20 20 72 |selected */. r| 00001c90 65 74 75 72 6e 20 6f 75 74 2e 72 5b 31 5d 3b 0a |eturn out.r[1];.| 00001ca0 7d 0a |}.| 00001ca2