Home » Archimedes archive » Acorn User » AU 1996-02.adf » Regulars » C/c/shell
C/c/shell
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-02.adf » Regulars |
Filename: | C/c/shell |
Read OK: | ✔ |
File size: | 0DB8 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 - February 1996 */ #include <stdio.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; /* Function prototyping */ int main(void); void wimpmsg(int, unsigned char[]); unsigned long int btow(unsigned char[], int); /* Program functions */ int main(void) { int task_handle; unsigned char pollblock[257]; /* essentially a byte array large enough for our polling block */ int pollresult; _kernel_swi_regs regs_in, regs_out; char appname[] = "Example"; 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 */ 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 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 pollblock[], 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 = pollblock[index--]; for(loop = 0; loop < 3; loop++) { result = result << 8; /* this shifts the bits in result left by 8 spaces */ result += pollblock[index--]; } return (result); }
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 46 65 62 72 75 61 72 79 20 31 |ser - February 1| 000000b0 39 39 36 20 2a 2f 0a 0a 23 69 6e 63 6c 75 64 65 |996 */..#include| 000000c0 20 3c 73 74 64 69 6f 2e 68 3e 0a 23 69 6e 63 6c | <stdio.h>.#incl| 000000d0 75 64 65 20 22 73 77 69 73 2e 68 22 0a 23 69 6e |ude "swis.h".#in| 000000e0 63 6c 75 64 65 20 22 6b 65 72 6e 65 6c 2e 68 22 |clude "kernel.h"| 000000f0 0a 0a 2f 2a 20 57 65 20 61 6c 73 6f 20 64 65 66 |../* We also def| 00000100 69 6e 65 20 61 20 70 6f 6c 6c 20 6d 61 73 6b 20 |ine a poll mask | 00000110 68 65 72 65 20 74 6f 20 74 65 6c 6c 20 74 68 65 |here to tell the| 00000120 20 57 49 4d 50 20 61 62 6f 75 74 20 61 6e 79 20 | WIMP about any | 00000130 65 76 65 6e 74 73 20 77 65 27 72 65 20 6e 6f 74 |events we're not| 00000140 0a 20 20 20 69 6e 74 65 72 65 72 65 73 74 65 64 |. intererested| 00000150 20 69 6e 20 2a 2f 0a 0a 23 64 65 66 69 6e 65 20 | in */..#define | 00000160 50 4f 4c 4c 5f 4d 41 53 4b 20 31 0a 0a 2f 2a 20 |POLL_MASK 1../* | 00000170 49 66 20 77 65 20 73 65 74 20 51 55 49 54 5f 46 |If we set QUIT_F| 00000180 4c 41 47 20 75 70 20 61 73 20 61 20 67 6c 6f 62 |LAG up as a glob| 00000190 61 6c 20 76 61 72 69 61 62 6c 65 2c 20 69 74 20 |al variable, it | 000001a0 6d 65 61 6e 73 20 74 68 61 74 20 77 65 20 63 61 |means that we ca| 000001b0 6e 20 63 68 61 6e 67 65 20 69 74 0a 20 20 20 61 |n change it. a| 000001c0 6e 79 77 68 65 72 65 20 77 69 74 68 69 6e 20 74 |nywhere within t| 000001d0 68 65 20 70 72 6f 67 72 61 6d 20 61 6e 64 20 73 |he program and s| 000001e0 68 75 74 20 74 68 69 6e 67 73 20 64 6f 77 6e 20 |hut things down | 000001f0 6e 65 78 74 20 74 69 6d 65 20 77 65 20 65 6e 64 |next time we end| 00000200 20 74 68 65 0a 20 20 20 70 6f 6c 6c 69 6e 67 20 | the. polling | 00000210 6c 6f 6f 70 20 2a 2f 0a 0a 69 6e 74 20 51 55 49 |loop */..int QUI| 00000220 54 5f 46 4c 41 47 20 3d 20 30 3b 0a 0a 2f 2a 20 |T_FLAG = 0;../* | 00000230 46 75 6e 63 74 69 6f 6e 20 70 72 6f 74 6f 74 79 |Function prototy| 00000240 70 69 6e 67 20 2a 2f 0a 0a 69 6e 74 20 6d 61 69 |ping */..int mai| 00000250 6e 28 76 6f 69 64 29 3b 0a 76 6f 69 64 20 20 20 |n(void);.void | 00000260 20 77 69 6d 70 6d 73 67 28 69 6e 74 2c 20 75 6e | wimpmsg(int, un| 00000270 73 69 67 6e 65 64 20 63 68 61 72 5b 5d 29 3b 0a |signed char[]);.| 00000280 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 20 69 6e |unsigned long in| 00000290 74 20 20 20 62 74 6f 77 28 75 6e 73 69 67 6e 65 |t btow(unsigne| 000002a0 64 20 63 68 61 72 5b 5d 2c 20 69 6e 74 29 3b 0a |d char[], int);.| 000002b0 0a 2f 2a 20 50 72 6f 67 72 61 6d 20 66 75 6e 63 |./* Program func| 000002c0 74 69 6f 6e 73 20 2a 2f 0a 0a 69 6e 74 0a 6d 61 |tions */..int.ma| 000002d0 69 6e 28 76 6f 69 64 29 20 7b 0a 20 20 20 20 69 |in(void) {. i| 000002e0 6e 74 20 74 61 73 6b 5f 68 61 6e 64 6c 65 3b 0a |nt task_handle;.| 000002f0 20 20 20 20 75 6e 73 69 67 6e 65 64 20 63 68 61 | unsigned cha| 00000300 72 20 20 20 70 6f 6c 6c 62 6c 6f 63 6b 5b 32 35 |r pollblock[25| 00000310 37 5d 3b 0a 20 20 20 20 2f 2a 20 65 73 73 65 6e |7];. /* essen| 00000320 74 69 61 6c 6c 79 20 61 20 62 79 74 65 20 61 72 |tially a byte ar| 00000330 72 61 79 20 6c 61 72 67 65 20 65 6e 6f 75 67 68 |ray large enough| 00000340 20 66 6f 72 20 6f 75 72 20 70 6f 6c 6c 69 6e 67 | for our polling| 00000350 20 62 6c 6f 63 6b 20 2a 2f 0a 0a 20 20 20 20 69 | block */.. i| 00000360 6e 74 20 70 6f 6c 6c 72 65 73 75 6c 74 3b 0a 20 |nt pollresult;. | 00000370 20 20 20 5f 6b 65 72 6e 65 6c 5f 73 77 69 5f 72 | _kernel_swi_r| 00000380 65 67 73 20 20 20 20 72 65 67 73 5f 69 6e 2c 20 |egs regs_in, | 00000390 72 65 67 73 5f 6f 75 74 3b 0a 20 20 20 20 63 68 |regs_out;. ch| 000003a0 61 72 20 61 70 70 6e 61 6d 65 5b 5d 20 3d 20 22 |ar appname[] = "| 000003b0 45 78 61 6d 70 6c 65 22 3b 0a 20 20 20 20 6c 6f |Example";. lo| 000003c0 6e 67 20 69 6e 74 20 20 20 20 6d 73 67 6c 69 73 |ng int msglis| 000003d0 74 5b 31 5d 20 3d 20 7b 30 7d 3b 0a 0a 20 20 20 |t[1] = {0};.. | 000003e0 20 2f 2a 20 4e 6f 77 20 74 6f 20 69 6e 69 74 69 | /* Now to initi| 000003f0 61 6c 69 73 65 20 6f 75 72 73 65 6c 76 65 73 20 |alise ourselves | 00000400 61 73 20 61 20 74 61 73 6b 20 2a 2f 0a 20 20 20 |as a task */. | 00000410 20 72 65 67 73 5f 69 6e 2e 72 5b 30 5d 20 3d 20 | regs_in.r[0] = | 00000420 33 31 30 3b 0a 20 20 20 20 72 65 67 73 5f 69 6e |310;. regs_in| 00000430 2e 72 5b 31 5d 20 3d 20 2a 28 69 6e 74 20 2a 29 |.r[1] = *(int *)| 00000440 22 54 41 53 4b 22 3b 0a 20 20 20 20 72 65 67 73 |"TASK";. regs| 00000450 5f 69 6e 2e 72 5b 32 5d 20 3d 20 28 69 6e 74 29 |_in.r[2] = (int)| 00000460 20 61 70 70 6e 61 6d 65 3b 0a 20 20 20 20 72 65 | appname;. re| 00000470 67 73 5f 69 6e 2e 72 5b 33 5d 20 3d 20 28 69 6e |gs_in.r[3] = (in| 00000480 74 29 20 6d 73 67 6c 69 73 74 3b 0a 20 20 20 20 |t) msglist;. | 00000490 2f 2a 20 57 65 20 6e 65 65 64 20 74 6f 20 73 75 |/* We need to su| 000004a0 70 70 6c 79 20 6f 75 72 20 63 68 6f 73 65 6e 20 |pply our chosen | 000004b0 52 49 53 43 20 4f 53 20 76 65 72 73 69 6f 6e 20 |RISC OS version | 000004c0 6e 75 6d 62 65 72 2c 20 74 68 65 20 22 54 41 53 |number, the "TAS| 000004d0 4b 22 0a 20 20 20 20 20 20 20 69 64 65 6e 74 69 |K". identi| 000004e0 66 69 65 72 20 74 6f 20 70 72 6f 76 65 20 77 65 |fier to prove we| 000004f0 27 72 65 20 61 20 6d 75 6c 74 69 74 61 73 6b 69 |'re a multitaski| 00000500 6e 67 20 61 70 70 6c 69 63 61 74 69 6f 6e 2c 20 |ng application, | 00000510 61 20 70 6f 69 6e 74 65 72 20 74 6f 0a 20 20 20 |a pointer to. | 00000520 20 20 20 20 6f 75 72 20 61 70 70 6c 69 63 61 74 | our applicat| 00000530 69 6f 6e 20 6e 61 6d 65 20 61 6e 64 20 61 20 70 |ion name and a p| 00000540 6f 69 6e 74 65 72 20 74 6f 20 61 20 6d 65 73 73 |ointer to a mess| 00000550 61 67 65 20 6c 69 73 74 20 2d 20 63 6f 6e 76 65 |age list - conve| 00000560 72 74 65 64 20 74 6f 0a 20 20 20 20 20 20 20 69 |rted to. i| 00000570 6e 74 65 67 65 72 20 66 6f 72 6d 61 74 20 61 73 |nteger format as| 00000580 20 6e 65 63 65 73 73 61 72 79 20 2a 2f 0a 0a 20 | necessary */.. | 00000590 20 20 20 2f 2a 20 6e 6f 77 20 74 6f 20 70 65 72 | /* now to per| 000005a0 66 6f 72 6d 20 74 68 65 20 61 63 74 75 61 6c 20 |form the actual | 000005b0 53 57 49 20 63 61 6c 6c 20 2a 2f 0a 20 20 20 20 |SWI call */. | 000005c0 5f 6b 65 72 6e 65 6c 5f 73 77 69 28 57 69 6d 70 |_kernel_swi(Wimp| 000005d0 5f 49 6e 69 74 69 61 6c 69 73 65 2c 20 26 72 65 |_Initialise, &re| 000005e0 67 73 5f 69 6e 2c 20 26 72 65 67 73 5f 6f 75 74 |gs_in, ®s_out| 000005f0 29 3b 0a 20 20 20 20 74 61 73 6b 5f 68 61 6e 64 |);. task_hand| 00000600 6c 65 20 3d 20 72 65 67 73 5f 6f 75 74 2e 72 5b |le = regs_out.r[| 00000610 31 5d 3b 20 2f 2a 20 64 65 74 65 72 6d 69 6e 65 |1]; /* determine| 00000620 20 6f 75 72 20 74 61 73 6b 20 68 61 6e 64 6c 65 | our task handle| 00000630 20 66 6f 72 20 6c 61 74 65 72 20 75 73 65 20 2a | for later use *| 00000640 2f 0a 0a 20 20 20 20 64 6f 20 7b 0a 20 20 20 20 |/.. do {. | 00000650 20 20 20 20 72 65 67 73 5f 69 6e 2e 72 5b 30 5d | regs_in.r[0]| 00000660 20 3d 20 50 4f 4c 4c 5f 4d 41 53 4b 3b 0a 20 20 | = POLL_MASK;. | 00000670 20 20 20 20 20 20 72 65 67 73 5f 69 6e 2e 72 5b | regs_in.r[| 00000680 31 5d 20 3d 20 28 69 6e 74 29 20 70 6f 6c 6c 62 |1] = (int) pollb| 00000690 6c 6f 63 6b 3b 20 2f 2a 20 61 20 70 6f 69 6e 74 |lock; /* a point| 000006a0 65 72 20 74 6f 20 6f 75 72 20 64 61 74 61 20 62 |er to our data b| 000006b0 6c 6f 63 6b 20 2a 2f 0a 0a 20 20 20 20 20 20 20 |lock */.. | 000006c0 20 5f 6b 65 72 6e 65 6c 5f 73 77 69 28 57 69 6d | _kernel_swi(Wim| 000006d0 70 5f 50 6f 6c 6c 2c 20 26 72 65 67 73 5f 69 6e |p_Poll, ®s_in| 000006e0 2c 20 26 72 65 67 73 5f 6f 75 74 29 3b 0a 20 20 |, ®s_out);. | 000006f0 20 20 20 20 20 20 70 6f 6c 6c 72 65 73 75 6c 74 | pollresult| 00000700 20 3d 20 72 65 67 73 5f 6f 75 74 2e 72 5b 30 5d | = regs_out.r[0]| 00000710 3b 20 2f 2a 20 64 65 74 65 72 6d 69 6e 65 20 74 |; /* determine t| 00000720 68 65 20 65 76 65 6e 74 20 63 6f 64 65 20 2a 2f |he event code */| 00000730 0a 20 20 20 20 20 20 20 20 73 77 69 74 63 68 20 |. switch | 00000740 28 70 6f 6c 6c 72 65 73 75 6c 74 29 20 7b 0a 20 |(pollresult) {. | 00000750 20 20 20 20 20 20 20 20 20 20 20 63 61 73 65 20 | case | 00000760 31 37 3a 0a 20 20 20 20 20 20 20 20 20 20 20 20 |17:. | 00000770 63 61 73 65 20 31 38 3a 0a 20 20 20 20 20 20 20 |case 18:. | 00000780 20 20 20 20 20 63 61 73 65 20 31 39 3a 20 77 69 | case 19: wi| 00000790 6d 70 6d 73 67 28 70 6f 6c 6c 72 65 73 75 6c 74 |mpmsg(pollresult| 000007a0 2c 20 70 6f 6c 6c 62 6c 6f 63 6b 29 3b 0a 20 20 |, pollblock);. | 000007b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 62 72 | br| 000007c0 65 61 6b 3b 0a 20 20 20 20 20 20 20 20 20 20 20 |eak;. | 000007d0 20 2f 2a 20 54 68 65 20 61 62 6f 76 65 20 73 65 | /* The above se| 000007e0 63 74 69 6f 6e 20 6c 69 73 74 65 6e 73 20 66 6f |ction listens fo| 000007f0 72 20 65 76 65 6e 74 20 63 6f 64 65 73 20 31 37 |r event codes 17| 00000800 2c 20 31 38 20 61 6e 64 20 31 39 20 2d 20 74 68 |, 18 and 19 - th| 00000810 65 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 |e. | 00000820 20 6f 6e 65 73 20 77 68 69 63 68 20 69 6e 64 69 | ones which indi| 00000830 63 61 74 65 20 77 65 27 72 65 20 62 65 69 6e 67 |cate we're being| 00000840 20 73 65 6e 74 20 61 20 6d 65 73 73 61 67 65 20 | sent a message | 00000850 2a 2f 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 |*/. }. | 00000860 20 7d 20 77 68 69 6c 65 20 28 51 55 49 54 5f 46 | } while (QUIT_F| 00000870 4c 41 47 20 3d 3d 20 30 29 3b 0a 20 20 20 20 2f |LAG == 0);. /| 00000880 2a 20 49 66 20 51 55 49 54 5f 46 4c 41 47 20 63 |* If QUIT_FLAG c| 00000890 68 61 6e 67 65 73 20 74 6f 20 61 6e 79 74 68 69 |hanges to anythi| 000008a0 6e 67 20 62 75 74 20 30 2c 20 77 65 20 73 74 6f |ng but 0, we sto| 000008b0 70 20 67 6f 69 6e 67 20 72 6f 75 6e 64 20 74 68 |p going round th| 000008c0 65 20 70 6f 6c 6c 69 6e 67 0a 20 20 20 20 20 20 |e polling. | 000008d0 20 6c 6f 6f 70 20 61 6e 64 20 73 68 75 74 20 64 | loop and shut d| 000008e0 6f 77 6e 20 2a 2f 0a 0a 0a 20 20 20 20 72 65 67 |own */... reg| 000008f0 73 5f 69 6e 2e 72 5b 30 5d 20 3d 20 74 61 73 6b |s_in.r[0] = task| 00000900 5f 68 61 6e 64 6c 65 3b 0a 20 20 20 20 72 65 67 |_handle;. reg| 00000910 73 5f 69 6e 2e 72 5b 31 5d 20 3d 20 2a 28 69 6e |s_in.r[1] = *(in| 00000920 74 20 2a 29 22 54 41 53 4b 22 3b 0a 20 20 20 20 |t *)"TASK";. | 00000930 5f 6b 65 72 6e 65 6c 5f 73 77 69 28 57 69 6d 70 |_kernel_swi(Wimp| 00000940 5f 43 6c 6f 73 65 44 6f 77 6e 2c 20 26 72 65 67 |_CloseDown, ®| 00000950 73 5f 69 6e 2c 20 26 72 65 67 73 5f 6f 75 74 29 |s_in, ®s_out)| 00000960 3b 0a 20 20 20 20 2f 2a 20 41 6e 64 20 74 68 61 |;. /* And tha| 00000970 74 27 73 20 69 74 20 2d 20 77 65 27 76 65 20 74 |t's it - we've t| 00000980 6f 6c 64 20 74 68 65 20 57 49 4d 50 20 74 68 61 |old the WIMP tha| 00000990 74 20 77 65 27 76 65 20 66 69 6e 69 73 68 65 64 |t we've finished| 000009a0 2c 20 61 6e 64 20 6e 6f 77 20 74 68 65 0a 20 20 |, and now the. | 000009b0 20 20 20 20 20 70 72 6f 67 72 61 6d 20 74 65 72 | program ter| 000009c0 6d 69 6e 61 74 65 73 2e 20 2a 2f 0a 7d 0a 0a 76 |minates. */.}..v| 000009d0 6f 69 64 0a 77 69 6d 70 6d 73 67 28 69 6e 74 20 |oid.wimpmsg(int | 000009e0 72 65 73 75 6c 74 2c 20 75 6e 73 69 67 6e 65 64 |result, unsigned| 000009f0 20 63 68 61 72 20 70 6f 6c 6c 62 6c 6f 63 6b 5b | char pollblock[| 00000a00 5d 29 0a 7b 0a 20 20 20 20 75 6e 73 69 67 6e 65 |]).{. unsigne| 00000a10 64 20 6c 6f 6e 67 20 69 6e 74 20 20 20 6d 65 73 |d long int mes| 00000a20 73 61 67 65 5f 61 63 74 69 6f 6e 3b 0a 0a 20 20 |sage_action;.. | 00000a30 20 20 2f 2a 20 54 68 65 20 6e 65 78 74 20 6c 69 | /* The next li| 00000a40 6e 65 20 74 61 6b 65 73 20 62 79 74 65 73 20 31 |ne takes bytes 1| 00000a50 36 20 74 6f 20 31 39 20 6f 66 20 74 68 65 20 70 |6 to 19 of the p| 00000a60 6f 6c 6c 69 6e 67 20 62 6c 6f 63 6b 20 61 6e 64 |olling block and| 00000a70 20 66 6f 72 6d 73 20 74 68 65 6d 0a 20 20 20 20 | forms them. | 00000a80 20 20 20 69 6e 74 6f 20 61 20 77 6f 72 64 20 68 | into a word h| 00000a90 6f 6c 64 69 6e 67 20 74 68 65 20 6d 65 73 73 61 |olding the messa| 00000aa0 67 65 20 61 63 74 69 6f 6e 20 6e 75 6d 62 65 72 |ge action number| 00000ab0 20 2a 2f 0a 20 20 20 20 6d 65 73 73 61 67 65 5f | */. message_| 00000ac0 61 63 74 69 6f 6e 20 3d 20 62 74 6f 77 28 70 6f |action = btow(po| 00000ad0 6c 6c 62 6c 6f 63 6b 2c 20 31 36 29 3b 0a 20 20 |llblock, 16);. | 00000ae0 20 20 0a 20 20 20 20 73 77 69 74 63 68 20 28 6d | . switch (m| 00000af0 65 73 73 61 67 65 5f 61 63 74 69 6f 6e 29 20 7b |essage_action) {| 00000b00 0a 20 20 20 20 20 20 20 20 63 61 73 65 20 30 3a |. case 0:| 00000b10 20 51 55 49 54 5f 46 4c 41 47 20 3d 20 31 3b 20 | QUIT_FLAG = 1; | 00000b20 2f 2a 20 4d 65 73 73 61 67 65 5f 51 75 69 74 20 |/* Message_Quit | 00000b30 2d 20 74 69 6d 65 20 74 6f 20 67 6f 20 2a 2f 0a |- time to go */.| 00000b40 20 20 20 20 20 20 20 20 20 20 20 20 62 72 65 61 | brea| 00000b50 6b 3b 0a 20 20 20 20 20 20 20 20 2f 2a 20 4d 6f |k;. /* Mo| 00000b60 72 65 20 6d 65 73 73 61 67 65 20 61 63 74 69 6f |re message actio| 00000b70 6e 73 20 63 61 6e 20 62 65 20 61 64 64 65 64 20 |ns can be added | 00000b80 68 65 72 65 20 2a 2f 0a 20 20 20 20 7d 0a 7d 0a |here */. }.}.| 00000b90 0a 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 20 69 |.unsigned long i| 00000ba0 6e 74 0a 62 74 6f 77 28 75 6e 73 69 67 6e 65 64 |nt.btow(unsigned| 00000bb0 20 63 68 61 72 20 70 6f 6c 6c 62 6c 6f 63 6b 5b | char pollblock[| 00000bc0 5d 2c 20 69 6e 74 20 69 6e 64 65 78 29 0a 7b 0a |], int index).{.| 00000bd0 20 20 20 20 75 6e 73 69 67 6e 65 64 20 6c 6f 6e | unsigned lon| 00000be0 67 20 69 6e 74 20 20 20 72 65 73 75 6c 74 20 3d |g int result =| 00000bf0 20 30 3b 0a 20 20 20 20 69 6e 74 20 6c 6f 6f 70 | 0;. int loop| 00000c00 3b 0a 0a 20 20 20 20 2f 2a 20 54 68 69 73 20 72 |;.. /* This r| 00000c10 6f 75 74 69 6e 65 20 74 61 6b 65 73 20 61 20 64 |outine takes a d| 00000c20 61 74 61 20 62 6c 6f 63 6b 20 61 6e 64 20 61 20 |ata block and a | 00000c30 73 74 61 72 74 69 6e 67 20 62 79 74 65 2c 20 61 |starting byte, a| 00000c40 6e 64 20 63 6f 6e 76 65 72 74 73 20 74 68 65 0a |nd converts the.| 00000c50 20 20 20 20 20 20 20 6e 65 78 74 20 66 6f 75 72 | next four| 00000c60 20 62 79 74 65 73 20 69 6e 74 6f 20 61 20 77 6f | bytes into a wo| 00000c70 72 64 20 2d 20 77 65 20 68 61 76 65 20 74 6f 20 |rd - we have to | 00000c80 73 74 61 72 74 20 61 74 20 74 68 65 20 6d 6f 73 |start at the mos| 00000c90 74 20 73 69 67 6e 69 66 69 63 61 6e 74 0a 20 20 |t significant. | 00000ca0 20 20 20 20 20 62 79 74 65 20 61 6e 64 20 77 6f | byte and wo| 00000cb0 72 6b 20 62 61 63 6b 77 61 72 64 73 20 2a 2f 0a |rk backwards */.| 00000cc0 0a 20 20 20 20 69 6e 64 65 78 20 2b 3d 20 33 3b |. index += 3;| 00000cd0 0a 20 20 20 20 72 65 73 75 6c 74 20 3d 20 70 6f |. result = po| 00000ce0 6c 6c 62 6c 6f 63 6b 5b 69 6e 64 65 78 2d 2d 5d |llblock[index--]| 00000cf0 3b 0a 20 20 20 20 66 6f 72 28 6c 6f 6f 70 20 3d |;. for(loop =| 00000d00 20 30 3b 20 6c 6f 6f 70 20 3c 20 33 3b 20 6c 6f | 0; loop < 3; lo| 00000d10 6f 70 2b 2b 29 20 7b 0a 20 20 20 20 20 20 20 20 |op++) {. | 00000d20 72 65 73 75 6c 74 20 3d 20 72 65 73 75 6c 74 20 |result = result | 00000d30 3c 3c 20 38 3b 0a 20 20 20 20 20 20 20 20 2f 2a |<< 8;. /*| 00000d40 20 74 68 69 73 20 73 68 69 66 74 73 20 74 68 65 | this shifts the| 00000d50 20 62 69 74 73 20 69 6e 20 72 65 73 75 6c 74 20 | bits in result | 00000d60 6c 65 66 74 20 62 79 20 38 20 73 70 61 63 65 73 |left by 8 spaces| 00000d70 20 2a 2f 0a 20 20 20 20 20 20 20 20 72 65 73 75 | */. resu| 00000d80 6c 74 20 2b 3d 20 70 6f 6c 6c 62 6c 6f 63 6b 5b |lt += pollblock[| 00000d90 69 6e 64 65 78 2d 2d 5d 3b 0a 20 20 20 20 7d 0a |index--];. }.| 00000da0 0a 20 20 20 20 72 65 74 75 72 6e 20 28 72 65 73 |. return (res| 00000db0 75 6c 74 29 3b 0a 7d 0a |ult);.}.| 00000db8