Home » Archimedes archive » Acorn User » AU 1997-10 A.adf » Extras » Apple][e/PD/BOB/ARMBOB/doc/Tutorial/04
Apple][e/PD/BOB/ARMBOB/doc/Tutorial/04
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 1997-10 A.adf » Extras |
Filename: | Apple][e/PD/BOB/ARMBOB/doc/Tutorial/04 |
Read OK: | ✔ |
File size: | 167B bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
ArmBob v.1.02 Tutorial 4 GCW 06/06/94 Wimp programming ---------------- The example !Exec is provided, as a minimal framework to start with. It uses no classes. When double-clicked !Exec should put its icon on the iconbar. Its iconbar menu has two items - Info and Quit. If an object is dragged onto its iconbar icon, the file !Exec.exec will be obeyed, with the object's pathname as argument. Clicking Select or Adjust on the iconbar icon will open an Edit window on !Exec.exec. A directory !Exec.Lib is provided for tools to be used by !Exec. An example provided in !Exec.Lib is Templread, a template disassembler. It expects a template file as argument, and when run opens an editable window on Bob source code defining the template's windows. A window called, say xyz, is defined by the data in a buffer called xyz_buf. !Exec is an application whose !RunImage file has filetype BobProj. Shift-double-click it to see its contents. Bob:h.wimp.templates Library file: load templates, get window handles Bob:h.wimp.ev_process Library file: main loop for wimp programs <Exec$dir>.main Main program Two library files are specified, and the textfile main. Main contains the function main - the entry point into the program. The first line (apart from comments) is @b = @(newstring(500)); which creates a fixed buffer, 500 bytes long, at the address @b. Note the convention of using @ as the first letter to remind ourselves that @b is an address. Then handler = newvector(20); handler[Mouse_Click] = do_Mouse_Click; handler[Menu_Selection] = do_Menu_Selection; handler[User_Message] = handler[User_Message_Recorded] = do_Message; creates a vector of handlers to respond to the window manager. We only need to respond to four reason codes: Mouse_Click Menu_Selection User_Message User_Message_Recorded The handler's components for these reason codes are set to functions appearing later in the file Main. The rest are nil by default. A generic handler function takes three arguments - the first, the address of a message buffer - the second is a user-parameter, that can be used for passing in data, and the third a pointer to a mask word to tell the window manager which events our task is not interested in receiving. In this example, the user-parameter has the value nil. The handler function must return FALSE if it is to cause the program to terminate, and TRUE otherwise. The statement in (mesg_list= newstring(8)) put { Message_DataLoad; 0; } creates a two-word buffer called mesg-list, containing the messages we want !Exec to receive. The 'in .. put { .. ; ... ;}' structure is convenient for filling buffers with words and strings. We start !Exec as a wimp task with wimp_init(310,"Exec",mesg_list); The Info box item of the menu is defined in a template file. The lines (wind = newvector(1))[0] = "info"; info = templates("<Exec$Dir>.Templates",wind)[0]; load the template and get the window-handle 'info' of this box. The templates function, defined in Bob:h.wimp.templates takes two arguments, the first, a string, the pathname of the template file, the second a vector of window names. It returns a vector of corresponding window handles. The vector 'wind' is defined as a 1-component vector. The lines icon = make_icon(); menu = make_menu(); should be self-explanatory. The function main finishes with the statement that does all the work (maskptr = newvector(1))[0] = &1933; event_process(maskptr,@b,handler,nil); The function event_process is defined in Bob:h.ev_process. event_process(maskptr,buffer,action,user) { local r, respond, go_on; r = newvector(8); go_on = TRUE; while(go_on) { r[0] = maskptr[0]; r[1] = buffer; swi("Wimp_Poll",r); go_on = (typeof(respond = action[r[0]]) == BYTECODE)?respond(buffer,user,maskptr):TRUE; } wimp_closedown(); } This function polls the wimp, and, if the component of the vector 'action' (which MUST have at least 20 components) given by the returned reason-code is a function, that function is called. If the function returns FALSE, execution falls through to wimp_closedown and the function main terminates. The event_process function provides a way of modularizing wimp programs. It is the possibility of having vectors of functions which enables ArmBob to gain in expressiveness over Basic. Now let us look at the handler functions. The most interesting is do_Message(a,user,maskptr) { switch(�(a+16)) { case Message_Quit: return FALSE; // i.e. do not continue break; case Message_DataLoad: if (�(a+20)==-2 && �(a+24)==icon) act(a,user_process); return TRUE; break; default: return TRUE; break; } } The first argument a is the address of the message buffer. The � operator fetches the integer stored at its argument. If a DataLoad message is received because something has been dragged to the iconbar icon, then act(a,user_process) is called. The function act gets the pathname and filetype of the object dragged, acknowledges the DataLoad message, and passes the pathname and filetype to its second argument. act(a,f) { local filename, filetype; filename = $(a+44); filetype = �(a+40); ��(a+16,Message_DataLoadAck); ��(a+12,�(a+8)); r[0] = User_Message_Acknowledge; r[1] = a; r[2] = 0; swi("Wimp_SendMessage",r); f(filename,filetype); } The $ function returns the string (terminated by an ASCII code less than 32) stored at an address. The �� function may be used for poking 4-byte words into positions in buffers. Note how the function f, the action to be taken, is passed as a parameter.
00000000 41 72 6d 42 6f 62 20 76 2e 31 2e 30 32 20 54 75 |ArmBob v.1.02 Tu| 00000010 74 6f 72 69 61 6c 20 34 20 20 20 20 20 20 20 20 |torial 4 | 00000020 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00000030 20 20 20 20 20 20 20 47 43 57 20 30 36 2f 30 36 | GCW 06/06| 00000040 2f 39 34 0a 0a 57 69 6d 70 20 70 72 6f 67 72 61 |/94..Wimp progra| 00000050 6d 6d 69 6e 67 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d |mming.----------| 00000060 2d 2d 2d 2d 2d 2d 0a 54 68 65 20 65 78 61 6d 70 |------.The examp| 00000070 6c 65 20 21 45 78 65 63 20 69 73 20 70 72 6f 76 |le !Exec is prov| 00000080 69 64 65 64 2c 20 61 73 20 61 20 6d 69 6e 69 6d |ided, as a minim| 00000090 61 6c 20 66 72 61 6d 65 77 6f 72 6b 20 74 6f 20 |al framework to | 000000a0 73 74 61 72 74 0a 77 69 74 68 2e 20 49 74 20 75 |start.with. It u| 000000b0 73 65 73 20 6e 6f 20 63 6c 61 73 73 65 73 2e 20 |ses no classes. | 000000c0 57 68 65 6e 20 64 6f 75 62 6c 65 2d 63 6c 69 63 |When double-clic| 000000d0 6b 65 64 20 21 45 78 65 63 20 73 68 6f 75 6c 64 |ked !Exec should| 000000e0 20 70 75 74 0a 69 74 73 20 69 63 6f 6e 20 6f 6e | put.its icon on| 000000f0 20 74 68 65 20 69 63 6f 6e 62 61 72 2e 20 49 74 | the iconbar. It| 00000100 73 20 69 63 6f 6e 62 61 72 20 6d 65 6e 75 20 68 |s iconbar menu h| 00000110 61 73 20 74 77 6f 20 69 74 65 6d 73 20 2d 20 49 |as two items - I| 00000120 6e 66 6f 20 61 6e 64 0a 51 75 69 74 2e 20 49 66 |nfo and.Quit. If| 00000130 20 61 6e 20 6f 62 6a 65 63 74 20 69 73 20 64 72 | an object is dr| 00000140 61 67 67 65 64 20 6f 6e 74 6f 20 69 74 73 20 69 |agged onto its i| 00000150 63 6f 6e 62 61 72 20 69 63 6f 6e 2c 20 74 68 65 |conbar icon, the| 00000160 20 66 69 6c 65 0a 21 45 78 65 63 2e 65 78 65 63 | file.!Exec.exec| 00000170 20 77 69 6c 6c 20 62 65 20 6f 62 65 79 65 64 2c | will be obeyed,| 00000180 20 77 69 74 68 20 74 68 65 20 6f 62 6a 65 63 74 | with the object| 00000190 27 73 20 70 61 74 68 6e 61 6d 65 20 61 73 20 61 |'s pathname as a| 000001a0 72 67 75 6d 65 6e 74 2e 0a 43 6c 69 63 6b 69 6e |rgument..Clickin| 000001b0 67 20 53 65 6c 65 63 74 20 6f 72 20 41 64 6a 75 |g Select or Adju| 000001c0 73 74 20 6f 6e 20 74 68 65 20 69 63 6f 6e 62 61 |st on the iconba| 000001d0 72 20 69 63 6f 6e 20 77 69 6c 6c 20 6f 70 65 6e |r icon will open| 000001e0 20 61 6e 20 45 64 69 74 0a 77 69 6e 64 6f 77 20 | an Edit.window | 000001f0 6f 6e 20 21 45 78 65 63 2e 65 78 65 63 2e 20 41 |on !Exec.exec. A| 00000200 20 64 69 72 65 63 74 6f 72 79 20 21 45 78 65 63 | directory !Exec| 00000210 2e 4c 69 62 20 69 73 20 70 72 6f 76 69 64 65 64 |.Lib is provided| 00000220 20 66 6f 72 20 74 6f 6f 6c 73 0a 74 6f 20 62 65 | for tools.to be| 00000230 20 75 73 65 64 20 62 79 20 21 45 78 65 63 2e 20 | used by !Exec. | 00000240 41 6e 20 65 78 61 6d 70 6c 65 20 70 72 6f 76 69 |An example provi| 00000250 64 65 64 20 69 6e 20 21 45 78 65 63 2e 4c 69 62 |ded in !Exec.Lib| 00000260 20 69 73 20 54 65 6d 70 6c 72 65 61 64 2c 0a 61 | is Templread,.a| 00000270 20 74 65 6d 70 6c 61 74 65 20 64 69 73 61 73 73 | template disass| 00000280 65 6d 62 6c 65 72 2e 20 49 74 20 65 78 70 65 63 |embler. It expec| 00000290 74 73 20 61 20 74 65 6d 70 6c 61 74 65 20 66 69 |ts a template fi| 000002a0 6c 65 20 61 73 20 61 72 67 75 6d 65 6e 74 2c 20 |le as argument, | 000002b0 0a 61 6e 64 20 77 68 65 6e 20 72 75 6e 20 6f 70 |.and when run op| 000002c0 65 6e 73 20 61 6e 20 65 64 69 74 61 62 6c 65 20 |ens an editable | 000002d0 77 69 6e 64 6f 77 20 6f 6e 20 42 6f 62 20 73 6f |window on Bob so| 000002e0 75 72 63 65 20 63 6f 64 65 20 64 65 66 69 6e 69 |urce code defini| 000002f0 6e 67 20 0a 74 68 65 20 74 65 6d 70 6c 61 74 65 |ng .the template| 00000300 27 73 20 77 69 6e 64 6f 77 73 2e 20 41 20 77 69 |'s windows. A wi| 00000310 6e 64 6f 77 20 63 61 6c 6c 65 64 2c 20 73 61 79 |ndow called, say| 00000320 20 78 79 7a 2c 20 69 73 20 64 65 66 69 6e 65 64 | xyz, is defined| 00000330 20 62 79 20 74 68 65 20 0a 64 61 74 61 20 69 6e | by the .data in| 00000340 20 61 20 62 75 66 66 65 72 20 63 61 6c 6c 65 64 | a buffer called| 00000350 20 78 79 7a 5f 62 75 66 2e 0a 0a 21 45 78 65 63 | xyz_buf...!Exec| 00000360 20 69 73 20 61 6e 20 61 70 70 6c 69 63 61 74 69 | is an applicati| 00000370 6f 6e 20 77 68 6f 73 65 20 21 52 75 6e 49 6d 61 |on whose !RunIma| 00000380 67 65 20 66 69 6c 65 20 68 61 73 20 66 69 6c 65 |ge file has file| 00000390 74 79 70 65 20 42 6f 62 50 72 6f 6a 2e 0a 53 68 |type BobProj..Sh| 000003a0 69 66 74 2d 64 6f 75 62 6c 65 2d 63 6c 69 63 6b |ift-double-click| 000003b0 20 69 74 20 74 6f 20 73 65 65 20 69 74 73 20 63 | it to see its c| 000003c0 6f 6e 74 65 6e 74 73 2e 0a 0a 42 6f 62 3a 68 2e |ontents...Bob:h.| 000003d0 77 69 6d 70 2e 74 65 6d 70 6c 61 74 65 73 20 20 |wimp.templates | 000003e0 20 20 20 4c 69 62 72 61 72 79 20 66 69 6c 65 3a | Library file:| 000003f0 20 6c 6f 61 64 20 74 65 6d 70 6c 61 74 65 73 2c | load templates,| 00000400 20 67 65 74 20 77 69 6e 64 6f 77 20 68 61 6e 64 | get window hand| 00000410 6c 65 73 0a 42 6f 62 3a 68 2e 77 69 6d 70 2e 65 |les.Bob:h.wimp.e| 00000420 76 5f 70 72 6f 63 65 73 73 20 20 20 20 4c 69 62 |v_process Lib| 00000430 72 61 72 79 20 66 69 6c 65 3a 20 6d 61 69 6e 20 |rary file: main | 00000440 6c 6f 6f 70 20 66 6f 72 20 77 69 6d 70 20 70 72 |loop for wimp pr| 00000450 6f 67 72 61 6d 73 0a 3c 45 78 65 63 24 64 69 72 |ograms.<Exec$dir| 00000460 3e 2e 6d 61 69 6e 20 20 20 20 20 20 20 20 20 20 |>.main | 00000470 4d 61 69 6e 20 70 72 6f 67 72 61 6d 0a 0a 54 77 |Main program..Tw| 00000480 6f 20 6c 69 62 72 61 72 79 20 66 69 6c 65 73 20 |o library files | 00000490 61 72 65 20 73 70 65 63 69 66 69 65 64 2c 20 61 |are specified, a| 000004a0 6e 64 20 74 68 65 20 74 65 78 74 66 69 6c 65 20 |nd the textfile | 000004b0 6d 61 69 6e 2e 20 4d 61 69 6e 20 63 6f 6e 74 61 |main. Main conta| 000004c0 69 6e 73 0a 74 68 65 20 66 75 6e 63 74 69 6f 6e |ins.the function| 000004d0 20 6d 61 69 6e 20 2d 20 74 68 65 20 65 6e 74 72 | main - the entr| 000004e0 79 20 70 6f 69 6e 74 20 69 6e 74 6f 20 74 68 65 |y point into the| 000004f0 20 70 72 6f 67 72 61 6d 2e 20 54 68 65 20 66 69 | program. The fi| 00000500 72 73 74 20 6c 69 6e 65 0a 28 61 70 61 72 74 20 |rst line.(apart | 00000510 66 72 6f 6d 20 63 6f 6d 6d 65 6e 74 73 29 20 69 |from comments) i| 00000520 73 0a 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 |s.. | 00000530 20 20 20 40 62 20 3d 20 40 28 6e 65 77 73 74 72 | @b = @(newstr| 00000540 69 6e 67 28 35 30 30 29 29 3b 20 0a 0a 77 68 69 |ing(500)); ..whi| 00000550 63 68 20 63 72 65 61 74 65 73 20 61 20 66 69 78 |ch creates a fix| 00000560 65 64 20 62 75 66 66 65 72 2c 20 35 30 30 20 62 |ed buffer, 500 b| 00000570 79 74 65 73 20 6c 6f 6e 67 2c 20 61 74 20 74 68 |ytes long, at th| 00000580 65 20 61 64 64 72 65 73 73 20 40 62 2e 20 4e 6f |e address @b. No| 00000590 74 65 0a 74 68 65 20 63 6f 6e 76 65 6e 74 69 6f |te.the conventio| 000005a0 6e 20 6f 66 20 75 73 69 6e 67 20 40 20 61 73 20 |n of using @ as | 000005b0 74 68 65 20 66 69 72 73 74 20 6c 65 74 74 65 72 |the first letter| 000005c0 20 74 6f 20 72 65 6d 69 6e 64 20 6f 75 72 73 65 | to remind ourse| 000005d0 6c 76 65 73 20 74 68 61 74 0a 40 62 20 69 73 20 |lves that.@b is | 000005e0 61 6e 20 61 64 64 72 65 73 73 2e 0a 0a 54 68 65 |an address...The| 000005f0 6e 0a 0a 20 68 61 6e 64 6c 65 72 20 3d 20 6e 65 |n.. handler = ne| 00000600 77 76 65 63 74 6f 72 28 32 30 29 3b 20 20 20 20 |wvector(20); | 00000610 20 20 20 20 20 0a 20 68 61 6e 64 6c 65 72 5b 4d | . handler[M| 00000620 6f 75 73 65 5f 43 6c 69 63 6b 5d 20 3d 20 64 6f |ouse_Click] = do| 00000630 5f 4d 6f 75 73 65 5f 43 6c 69 63 6b 3b 0a 20 68 |_Mouse_Click;. h| 00000640 61 6e 64 6c 65 72 5b 4d 65 6e 75 5f 53 65 6c 65 |andler[Menu_Sele| 00000650 63 74 69 6f 6e 5d 20 3d 20 64 6f 5f 4d 65 6e 75 |ction] = do_Menu| 00000660 5f 53 65 6c 65 63 74 69 6f 6e 3b 0a 20 68 61 6e |_Selection;. han| 00000670 64 6c 65 72 5b 55 73 65 72 5f 4d 65 73 73 61 67 |dler[User_Messag| 00000680 65 5d 20 3d 20 68 61 6e 64 6c 65 72 5b 55 73 65 |e] = handler[Use| 00000690 72 5f 4d 65 73 73 61 67 65 5f 52 65 63 6f 72 64 |r_Message_Record| 000006a0 65 64 5d 20 3d 20 64 6f 5f 4d 65 73 73 61 67 65 |ed] = do_Message| 000006b0 3b 0a 0a 63 72 65 61 74 65 73 20 61 20 76 65 63 |;..creates a vec| 000006c0 74 6f 72 20 6f 66 20 68 61 6e 64 6c 65 72 73 20 |tor of handlers | 000006d0 74 6f 20 72 65 73 70 6f 6e 64 20 74 6f 20 74 68 |to respond to th| 000006e0 65 20 77 69 6e 64 6f 77 20 6d 61 6e 61 67 65 72 |e window manager| 000006f0 2e 20 57 65 20 6f 6e 6c 79 0a 6e 65 65 64 20 74 |. We only.need t| 00000700 6f 20 72 65 73 70 6f 6e 64 20 74 6f 20 66 6f 75 |o respond to fou| 00000710 72 20 72 65 61 73 6f 6e 20 63 6f 64 65 73 3a 0a |r reason codes:.| 00000720 0a 20 20 20 20 20 20 20 20 20 20 4d 6f 75 73 65 |. Mouse| 00000730 5f 43 6c 69 63 6b 0a 20 20 20 20 20 20 20 20 20 |_Click. | 00000740 20 4d 65 6e 75 5f 53 65 6c 65 63 74 69 6f 6e 0a | Menu_Selection.| 00000750 20 20 20 20 20 20 20 20 20 20 55 73 65 72 5f 4d | User_M| 00000760 65 73 73 61 67 65 0a 20 20 20 20 20 20 20 20 20 |essage. | 00000770 20 55 73 65 72 5f 4d 65 73 73 61 67 65 5f 52 65 | User_Message_Re| 00000780 63 6f 72 64 65 64 0a 0a 54 68 65 20 68 61 6e 64 |corded..The hand| 00000790 6c 65 72 27 73 20 63 6f 6d 70 6f 6e 65 6e 74 73 |ler's components| 000007a0 20 66 6f 72 20 74 68 65 73 65 20 72 65 61 73 6f | for these reaso| 000007b0 6e 20 63 6f 64 65 73 20 61 72 65 20 73 65 74 20 |n codes are set | 000007c0 74 6f 20 66 75 6e 63 74 69 6f 6e 73 0a 61 70 70 |to functions.app| 000007d0 65 61 72 69 6e 67 20 6c 61 74 65 72 20 69 6e 20 |earing later in | 000007e0 74 68 65 20 66 69 6c 65 20 4d 61 69 6e 2e 20 54 |the file Main. T| 000007f0 68 65 20 72 65 73 74 20 61 72 65 20 6e 69 6c 20 |he rest are nil | 00000800 62 79 20 64 65 66 61 75 6c 74 2e 0a 41 20 67 65 |by default..A ge| 00000810 6e 65 72 69 63 20 68 61 6e 64 6c 65 72 20 66 75 |neric handler fu| 00000820 6e 63 74 69 6f 6e 20 74 61 6b 65 73 20 74 68 72 |nction takes thr| 00000830 65 65 20 61 72 67 75 6d 65 6e 74 73 20 2d 20 74 |ee arguments - t| 00000840 68 65 20 66 69 72 73 74 2c 20 74 68 65 20 61 64 |he first, the ad| 00000850 64 72 65 73 73 0a 6f 66 20 61 20 6d 65 73 73 61 |dress.of a messa| 00000860 67 65 20 62 75 66 66 65 72 20 2d 20 74 68 65 20 |ge buffer - the | 00000870 73 65 63 6f 6e 64 20 69 73 20 61 20 75 73 65 72 |second is a user| 00000880 2d 70 61 72 61 6d 65 74 65 72 2c 20 74 68 61 74 |-parameter, that| 00000890 20 63 61 6e 20 62 65 20 75 73 65 64 0a 66 6f 72 | can be used.for| 000008a0 20 70 61 73 73 69 6e 67 20 69 6e 20 64 61 74 61 | passing in data| 000008b0 2c 20 61 6e 64 20 74 68 65 20 74 68 69 72 64 20 |, and the third | 000008c0 61 20 70 6f 69 6e 74 65 72 20 74 6f 20 61 20 6d |a pointer to a m| 000008d0 61 73 6b 20 77 6f 72 64 20 74 6f 20 74 65 6c 6c |ask word to tell| 000008e0 20 74 68 65 0a 77 69 6e 64 6f 77 20 6d 61 6e 61 | the.window mana| 000008f0 67 65 72 20 77 68 69 63 68 20 65 76 65 6e 74 73 |ger which events| 00000900 20 6f 75 72 20 74 61 73 6b 20 69 73 20 6e 6f 74 | our task is not| 00000910 20 69 6e 74 65 72 65 73 74 65 64 20 69 6e 20 72 | interested in r| 00000920 65 63 65 69 76 69 6e 67 2e 20 0a 49 6e 20 74 68 |eceiving. .In th| 00000930 69 73 20 65 78 61 6d 70 6c 65 2c 20 74 68 65 20 |is example, the | 00000940 75 73 65 72 2d 70 61 72 61 6d 65 74 65 72 20 68 |user-parameter h| 00000950 61 73 20 74 68 65 20 76 61 6c 75 65 20 6e 69 6c |as the value nil| 00000960 2e 20 54 68 65 20 68 61 6e 64 6c 65 72 20 0a 66 |. The handler .f| 00000970 75 6e 63 74 69 6f 6e 20 6d 75 73 74 20 72 65 74 |unction must ret| 00000980 75 72 6e 20 46 41 4c 53 45 20 69 66 20 69 74 20 |urn FALSE if it | 00000990 69 73 20 74 6f 20 63 61 75 73 65 20 74 68 65 20 |is to cause the | 000009a0 70 72 6f 67 72 61 6d 20 74 6f 20 74 65 72 6d 69 |program to termi| 000009b0 6e 61 74 65 2c 20 0a 61 6e 64 20 54 52 55 45 20 |nate, .and TRUE | 000009c0 6f 74 68 65 72 77 69 73 65 2e 0a 0a 54 68 65 20 |otherwise...The | 000009d0 73 74 61 74 65 6d 65 6e 74 0a 0a 20 69 6e 20 28 |statement.. in (| 000009e0 6d 65 73 67 5f 6c 69 73 74 3d 20 6e 65 77 73 74 |mesg_list= newst| 000009f0 72 69 6e 67 28 38 29 29 20 70 75 74 0a 20 20 20 |ring(8)) put. | 00000a00 20 20 7b 20 4d 65 73 73 61 67 65 5f 44 61 74 61 | { Message_Data| 00000a10 4c 6f 61 64 3b 20 30 3b 20 7d 20 0a 0a 63 72 65 |Load; 0; } ..cre| 00000a20 61 74 65 73 20 61 20 74 77 6f 2d 77 6f 72 64 20 |ates a two-word | 00000a30 62 75 66 66 65 72 20 63 61 6c 6c 65 64 20 6d 65 |buffer called me| 00000a40 73 67 2d 6c 69 73 74 2c 20 63 6f 6e 74 61 69 6e |sg-list, contain| 00000a50 69 6e 67 20 74 68 65 20 6d 65 73 73 61 67 65 73 |ing the messages| 00000a60 0a 77 65 20 77 61 6e 74 20 21 45 78 65 63 20 74 |.we want !Exec t| 00000a70 6f 20 72 65 63 65 69 76 65 2e 20 54 68 65 20 27 |o receive. The '| 00000a80 69 6e 20 2e 2e 20 70 75 74 20 7b 20 2e 2e 20 3b |in .. put { .. ;| 00000a90 20 2e 2e 2e 20 3b 7d 27 20 73 74 72 75 63 74 75 | ... ;}' structu| 00000aa0 72 65 0a 69 73 20 63 6f 6e 76 65 6e 69 65 6e 74 |re.is convenient| 00000ab0 20 66 6f 72 20 66 69 6c 6c 69 6e 67 20 62 75 66 | for filling buf| 00000ac0 66 65 72 73 20 77 69 74 68 20 77 6f 72 64 73 20 |fers with words | 00000ad0 61 6e 64 20 73 74 72 69 6e 67 73 2e 0a 0a 57 65 |and strings...We| 00000ae0 20 73 74 61 72 74 20 21 45 78 65 63 20 61 73 20 | start !Exec as | 00000af0 61 20 77 69 6d 70 20 74 61 73 6b 20 77 69 74 68 |a wimp task with| 00000b00 0a 0a 20 77 69 6d 70 5f 69 6e 69 74 28 33 31 30 |.. wimp_init(310| 00000b10 2c 22 45 78 65 63 22 2c 6d 65 73 67 5f 6c 69 73 |,"Exec",mesg_lis| 00000b20 74 29 3b 0a 0a 54 68 65 20 49 6e 66 6f 20 62 6f |t);..The Info bo| 00000b30 78 20 69 74 65 6d 20 6f 66 20 74 68 65 20 6d 65 |x item of the me| 00000b40 6e 75 20 69 73 20 64 65 66 69 6e 65 64 20 69 6e |nu is defined in| 00000b50 20 61 20 74 65 6d 70 6c 61 74 65 20 66 69 6c 65 | a template file| 00000b60 2e 20 54 68 65 20 6c 69 6e 65 73 0a 0a 20 28 77 |. The lines.. (w| 00000b70 69 6e 64 20 3d 20 6e 65 77 76 65 63 74 6f 72 28 |ind = newvector(| 00000b80 31 29 29 5b 30 5d 20 3d 20 22 69 6e 66 6f 22 3b |1))[0] = "info";| 00000b90 0a 20 69 6e 66 6f 20 3d 20 74 65 6d 70 6c 61 74 |. info = templat| 00000ba0 65 73 28 22 3c 45 78 65 63 24 44 69 72 3e 2e 54 |es("<Exec$Dir>.T| 00000bb0 65 6d 70 6c 61 74 65 73 22 2c 77 69 6e 64 29 5b |emplates",wind)[| 00000bc0 30 5d 3b 0a 0a 6c 6f 61 64 20 74 68 65 20 74 65 |0];..load the te| 00000bd0 6d 70 6c 61 74 65 20 61 6e 64 20 67 65 74 20 74 |mplate and get t| 00000be0 68 65 20 77 69 6e 64 6f 77 2d 68 61 6e 64 6c 65 |he window-handle| 00000bf0 20 27 69 6e 66 6f 27 20 6f 66 20 74 68 69 73 20 | 'info' of this | 00000c00 62 6f 78 2e 20 54 68 65 0a 74 65 6d 70 6c 61 74 |box. The.templat| 00000c10 65 73 20 66 75 6e 63 74 69 6f 6e 2c 20 64 65 66 |es function, def| 00000c20 69 6e 65 64 20 69 6e 20 42 6f 62 3a 68 2e 77 69 |ined in Bob:h.wi| 00000c30 6d 70 2e 74 65 6d 70 6c 61 74 65 73 20 74 61 6b |mp.templates tak| 00000c40 65 73 20 74 77 6f 20 61 72 67 75 6d 65 6e 74 73 |es two arguments| 00000c50 2c 0a 74 68 65 20 66 69 72 73 74 2c 20 61 20 73 |,.the first, a s| 00000c60 74 72 69 6e 67 2c 20 74 68 65 20 70 61 74 68 6e |tring, the pathn| 00000c70 61 6d 65 20 6f 66 20 74 68 65 20 74 65 6d 70 6c |ame of the templ| 00000c80 61 74 65 20 66 69 6c 65 2c 20 74 68 65 20 73 65 |ate file, the se| 00000c90 63 6f 6e 64 0a 61 20 76 65 63 74 6f 72 20 6f 66 |cond.a vector of| 00000ca0 20 77 69 6e 64 6f 77 20 6e 61 6d 65 73 2e 20 49 | window names. I| 00000cb0 74 20 72 65 74 75 72 6e 73 20 61 20 76 65 63 74 |t returns a vect| 00000cc0 6f 72 20 6f 66 20 63 6f 72 72 65 73 70 6f 6e 64 |or of correspond| 00000cd0 69 6e 67 20 77 69 6e 64 6f 77 0a 68 61 6e 64 6c |ing window.handl| 00000ce0 65 73 2e 20 54 68 65 20 76 65 63 74 6f 72 20 27 |es. The vector '| 00000cf0 77 69 6e 64 27 20 69 73 20 64 65 66 69 6e 65 64 |wind' is defined| 00000d00 20 61 73 20 61 20 31 2d 63 6f 6d 70 6f 6e 65 6e | as a 1-componen| 00000d10 74 20 76 65 63 74 6f 72 2e 0a 0a 54 68 65 20 6c |t vector...The l| 00000d20 69 6e 65 73 0a 0a 20 69 63 6f 6e 20 3d 20 6d 61 |ines.. icon = ma| 00000d30 6b 65 5f 69 63 6f 6e 28 29 3b 0a 20 6d 65 6e 75 |ke_icon();. menu| 00000d40 20 3d 20 6d 61 6b 65 5f 6d 65 6e 75 28 29 3b 0a | = make_menu();.| 00000d50 0a 73 68 6f 75 6c 64 20 62 65 20 73 65 6c 66 2d |.should be self-| 00000d60 65 78 70 6c 61 6e 61 74 6f 72 79 2e 20 54 68 65 |explanatory. The| 00000d70 20 66 75 6e 63 74 69 6f 6e 20 6d 61 69 6e 20 66 | function main f| 00000d80 69 6e 69 73 68 65 73 20 77 69 74 68 20 74 68 65 |inishes with the| 00000d90 0a 73 74 61 74 65 6d 65 6e 74 20 74 68 61 74 20 |.statement that | 00000da0 64 6f 65 73 20 61 6c 6c 20 74 68 65 20 77 6f 72 |does all the wor| 00000db0 6b 0a 0a 20 28 6d 61 73 6b 70 74 72 20 3d 20 6e |k.. (maskptr = n| 00000dc0 65 77 76 65 63 74 6f 72 28 31 29 29 5b 30 5d 20 |ewvector(1))[0] | 00000dd0 3d 20 26 31 39 33 33 3b 0a 20 65 76 65 6e 74 5f |= &1933;. event_| 00000de0 70 72 6f 63 65 73 73 28 6d 61 73 6b 70 74 72 2c |process(maskptr,| 00000df0 40 62 2c 68 61 6e 64 6c 65 72 2c 6e 69 6c 29 3b |@b,handler,nil);| 00000e00 20 0a 0a 54 68 65 20 66 75 6e 63 74 69 6f 6e 20 | ..The function | 00000e10 65 76 65 6e 74 5f 70 72 6f 63 65 73 73 20 69 73 |event_process is| 00000e20 20 64 65 66 69 6e 65 64 20 69 6e 20 42 6f 62 3a | defined in Bob:| 00000e30 68 2e 65 76 5f 70 72 6f 63 65 73 73 2e 0a 0a 65 |h.ev_process...e| 00000e40 76 65 6e 74 5f 70 72 6f 63 65 73 73 28 6d 61 73 |vent_process(mas| 00000e50 6b 70 74 72 2c 62 75 66 66 65 72 2c 61 63 74 69 |kptr,buffer,acti| 00000e60 6f 6e 2c 75 73 65 72 29 0a 7b 0a 20 6c 6f 63 61 |on,user).{. loca| 00000e70 6c 20 72 2c 20 72 65 73 70 6f 6e 64 2c 20 67 6f |l r, respond, go| 00000e80 5f 6f 6e 3b 0a 20 72 20 3d 20 6e 65 77 76 65 63 |_on;. r = newvec| 00000e90 74 6f 72 28 38 29 3b 0a 20 67 6f 5f 6f 6e 20 3d |tor(8);. go_on =| 00000ea0 20 54 52 55 45 3b 0a 20 77 68 69 6c 65 28 67 6f | TRUE;. while(go| 00000eb0 5f 6f 6e 29 0a 20 7b 0a 20 20 72 5b 30 5d 20 3d |_on). {. r[0] =| 00000ec0 20 6d 61 73 6b 70 74 72 5b 30 5d 3b 0a 20 20 72 | maskptr[0];. r| 00000ed0 5b 31 5d 20 3d 20 62 75 66 66 65 72 3b 0a 20 20 |[1] = buffer;. | 00000ee0 73 77 69 28 22 57 69 6d 70 5f 50 6f 6c 6c 22 2c |swi("Wimp_Poll",| 00000ef0 72 29 3b 0a 20 20 67 6f 5f 6f 6e 20 3d 0a 20 20 |r);. go_on =. | 00000f00 20 20 20 28 74 79 70 65 6f 66 28 72 65 73 70 6f | (typeof(respo| 00000f10 6e 64 20 3d 20 61 63 74 69 6f 6e 5b 72 5b 30 5d |nd = action[r[0]| 00000f20 5d 29 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 |]). | 00000f30 20 20 3d 3d 20 42 59 54 45 43 4f 44 45 29 3f 72 | == BYTECODE)?r| 00000f40 65 73 70 6f 6e 64 28 62 75 66 66 65 72 2c 75 73 |espond(buffer,us| 00000f50 65 72 2c 6d 61 73 6b 70 74 72 29 3a 54 52 55 45 |er,maskptr):TRUE| 00000f60 3b 0a 20 7d 0a 20 77 69 6d 70 5f 63 6c 6f 73 65 |;. }. wimp_close| 00000f70 64 6f 77 6e 28 29 3b 0a 7d 0a 0a 54 68 69 73 20 |down();.}..This | 00000f80 66 75 6e 63 74 69 6f 6e 20 70 6f 6c 6c 73 20 74 |function polls t| 00000f90 68 65 20 77 69 6d 70 2c 20 61 6e 64 2c 20 69 66 |he wimp, and, if| 00000fa0 20 74 68 65 20 63 6f 6d 70 6f 6e 65 6e 74 20 6f | the component o| 00000fb0 66 20 74 68 65 20 76 65 63 74 6f 72 0a 27 61 63 |f the vector.'ac| 00000fc0 74 69 6f 6e 27 20 28 77 68 69 63 68 20 4d 55 53 |tion' (which MUS| 00000fd0 54 20 68 61 76 65 20 61 74 20 6c 65 61 73 74 20 |T have at least | 00000fe0 32 30 20 63 6f 6d 70 6f 6e 65 6e 74 73 29 20 67 |20 components) g| 00000ff0 69 76 65 6e 20 62 79 20 74 68 65 0a 72 65 74 75 |iven by the.retu| 00001000 72 6e 65 64 20 72 65 61 73 6f 6e 2d 63 6f 64 65 |rned reason-code| 00001010 20 69 73 20 61 20 66 75 6e 63 74 69 6f 6e 2c 20 | is a function, | 00001020 74 68 61 74 20 66 75 6e 63 74 69 6f 6e 20 69 73 |that function is| 00001030 20 63 61 6c 6c 65 64 2e 20 49 66 20 74 68 65 0a | called. If the.| 00001040 66 75 6e 63 74 69 6f 6e 20 72 65 74 75 72 6e 73 |function returns| 00001050 20 46 41 4c 53 45 2c 20 65 78 65 63 75 74 69 6f | FALSE, executio| 00001060 6e 20 66 61 6c 6c 73 20 74 68 72 6f 75 67 68 20 |n falls through | 00001070 74 6f 20 77 69 6d 70 5f 63 6c 6f 73 65 64 6f 77 |to wimp_closedow| 00001080 6e 0a 61 6e 64 20 74 68 65 20 66 75 6e 63 74 69 |n.and the functi| 00001090 6f 6e 20 6d 61 69 6e 20 74 65 72 6d 69 6e 61 74 |on main terminat| 000010a0 65 73 2e 0a 0a 54 68 65 20 65 76 65 6e 74 5f 70 |es...The event_p| 000010b0 72 6f 63 65 73 73 20 66 75 6e 63 74 69 6f 6e 20 |rocess function | 000010c0 70 72 6f 76 69 64 65 73 20 61 20 77 61 79 20 6f |provides a way o| 000010d0 66 20 6d 6f 64 75 6c 61 72 69 7a 69 6e 67 20 77 |f modularizing w| 000010e0 69 6d 70 0a 70 72 6f 67 72 61 6d 73 2e 20 49 74 |imp.programs. It| 000010f0 20 69 73 20 74 68 65 20 70 6f 73 73 69 62 69 6c | is the possibil| 00001100 69 74 79 20 6f 66 20 68 61 76 69 6e 67 20 76 65 |ity of having ve| 00001110 63 74 6f 72 73 20 6f 66 20 66 75 6e 63 74 69 6f |ctors of functio| 00001120 6e 73 20 77 68 69 63 68 0a 65 6e 61 62 6c 65 73 |ns which.enables| 00001130 20 41 72 6d 42 6f 62 20 74 6f 20 67 61 69 6e 20 | ArmBob to gain | 00001140 69 6e 20 65 78 70 72 65 73 73 69 76 65 6e 65 73 |in expressivenes| 00001150 73 20 6f 76 65 72 20 42 61 73 69 63 2e 0a 0a 4e |s over Basic...N| 00001160 6f 77 20 6c 65 74 20 75 73 20 6c 6f 6f 6b 20 61 |ow let us look a| 00001170 74 20 74 68 65 20 68 61 6e 64 6c 65 72 20 66 75 |t the handler fu| 00001180 6e 63 74 69 6f 6e 73 2e 20 54 68 65 20 6d 6f 73 |nctions. The mos| 00001190 74 20 69 6e 74 65 72 65 73 74 69 6e 67 20 69 73 |t interesting is| 000011a0 0a 0a 64 6f 5f 4d 65 73 73 61 67 65 28 61 2c 75 |..do_Message(a,u| 000011b0 73 65 72 2c 6d 61 73 6b 70 74 72 29 0a 7b 0a 20 |ser,maskptr).{. | 000011c0 73 77 69 74 63 68 28 a3 28 61 2b 31 36 29 29 0a |switch(.(a+16)).| 000011d0 20 20 20 20 7b 0a 20 20 20 20 20 63 61 73 65 20 | {. case | 000011e0 4d 65 73 73 61 67 65 5f 51 75 69 74 3a 0a 20 20 |Message_Quit:. | 000011f0 20 20 20 20 20 72 65 74 75 72 6e 20 46 41 4c 53 | return FALS| 00001200 45 3b 20 20 2f 2f 20 69 2e 65 2e 20 64 6f 20 6e |E; // i.e. do n| 00001210 6f 74 20 63 6f 6e 74 69 6e 75 65 0a 20 20 20 20 |ot continue. | 00001220 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 20 63 | break;. c| 00001230 61 73 65 20 4d 65 73 73 61 67 65 5f 44 61 74 61 |ase Message_Data| 00001240 4c 6f 61 64 3a 20 20 0a 20 20 20 20 20 20 20 20 |Load: . | 00001250 69 66 20 28 a3 28 61 2b 32 30 29 3d 3d 2d 32 20 |if (.(a+20)==-2 | 00001260 26 26 20 a3 28 61 2b 32 34 29 3d 3d 69 63 6f 6e |&& .(a+24)==icon| 00001270 29 0a 20 20 20 20 20 20 20 20 20 20 20 61 63 74 |). act| 00001280 28 61 2c 75 73 65 72 5f 70 72 6f 63 65 73 73 29 |(a,user_process)| 00001290 3b 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e |;. return| 000012a0 20 54 52 55 45 3b 0a 20 20 20 20 20 20 20 20 62 | TRUE;. b| 000012b0 72 65 61 6b 3b 0a 20 20 20 20 20 64 65 66 61 75 |reak;. defau| 000012c0 6c 74 3a 0a 20 20 20 20 20 20 20 20 72 65 74 75 |lt:. retu| 000012d0 72 6e 20 54 52 55 45 3b 0a 20 20 20 20 20 20 20 |rn TRUE;. | 000012e0 20 62 72 65 61 6b 3b 0a 20 20 20 20 7d 0a 7d 0a | break;. }.}.| 000012f0 0a 54 68 65 20 66 69 72 73 74 20 61 72 67 75 6d |.The first argum| 00001300 65 6e 74 20 61 20 69 73 20 74 68 65 20 61 64 64 |ent a is the add| 00001310 72 65 73 73 20 6f 66 20 74 68 65 20 6d 65 73 73 |ress of the mess| 00001320 61 67 65 20 62 75 66 66 65 72 2e 20 54 68 65 20 |age buffer. The | 00001330 a3 20 6f 70 65 72 61 74 6f 72 0a 66 65 74 63 68 |. operator.fetch| 00001340 65 73 20 74 68 65 20 69 6e 74 65 67 65 72 20 73 |es the integer s| 00001350 74 6f 72 65 64 20 61 74 20 69 74 73 20 61 72 67 |tored at its arg| 00001360 75 6d 65 6e 74 2e 20 49 66 20 61 20 44 61 74 61 |ument. If a Data| 00001370 4c 6f 61 64 20 6d 65 73 73 61 67 65 20 69 73 0a |Load message is.| 00001380 72 65 63 65 69 76 65 64 20 62 65 63 61 75 73 65 |received because| 00001390 20 73 6f 6d 65 74 68 69 6e 67 20 68 61 73 20 62 | something has b| 000013a0 65 65 6e 20 64 72 61 67 67 65 64 20 74 6f 20 74 |een dragged to t| 000013b0 68 65 20 69 63 6f 6e 62 61 72 20 69 63 6f 6e 2c |he iconbar icon,| 000013c0 0a 74 68 65 6e 20 61 63 74 28 61 2c 75 73 65 72 |.then act(a,user| 000013d0 5f 70 72 6f 63 65 73 73 29 20 69 73 20 63 61 6c |_process) is cal| 000013e0 6c 65 64 2e 20 54 68 65 20 66 75 6e 63 74 69 6f |led. The functio| 000013f0 6e 20 61 63 74 20 67 65 74 73 20 74 68 65 20 70 |n act gets the p| 00001400 61 74 68 6e 61 6d 65 0a 61 6e 64 20 66 69 6c 65 |athname.and file| 00001410 74 79 70 65 20 6f 66 20 74 68 65 20 6f 62 6a 65 |type of the obje| 00001420 63 74 20 64 72 61 67 67 65 64 2c 20 61 63 6b 6e |ct dragged, ackn| 00001430 6f 77 6c 65 64 67 65 73 20 74 68 65 20 44 61 74 |owledges the Dat| 00001440 61 4c 6f 61 64 20 6d 65 73 73 61 67 65 2c 0a 61 |aLoad message,.a| 00001450 6e 64 20 70 61 73 73 65 73 20 74 68 65 20 70 61 |nd passes the pa| 00001460 74 68 6e 61 6d 65 20 61 6e 64 20 66 69 6c 65 74 |thname and filet| 00001470 79 70 65 20 74 6f 20 69 74 73 20 73 65 63 6f 6e |ype to its secon| 00001480 64 20 61 72 67 75 6d 65 6e 74 2e 0a 0a 61 63 74 |d argument...act| 00001490 28 61 2c 66 29 0a 7b 0a 20 6c 6f 63 61 6c 20 66 |(a,f).{. local f| 000014a0 69 6c 65 6e 61 6d 65 2c 20 66 69 6c 65 74 79 70 |ilename, filetyp| 000014b0 65 3b 0a 20 66 69 6c 65 6e 61 6d 65 20 3d 20 24 |e;. filename = $| 000014c0 28 61 2b 34 34 29 3b 0a 20 66 69 6c 65 74 79 70 |(a+44);. filetyp| 000014d0 65 20 3d 20 a3 28 61 2b 34 30 29 3b 0a 20 a3 a3 |e = .(a+40);. ..| 000014e0 28 61 2b 31 36 2c 4d 65 73 73 61 67 65 5f 44 61 |(a+16,Message_Da| 000014f0 74 61 4c 6f 61 64 41 63 6b 29 3b 0a 20 a3 a3 28 |taLoadAck);. ..(| 00001500 61 2b 31 32 2c a3 28 61 2b 38 29 29 3b 0a 20 72 |a+12,.(a+8));. r| 00001510 5b 30 5d 20 3d 20 55 73 65 72 5f 4d 65 73 73 61 |[0] = User_Messa| 00001520 67 65 5f 41 63 6b 6e 6f 77 6c 65 64 67 65 3b 0a |ge_Acknowledge;.| 00001530 20 72 5b 31 5d 20 3d 20 61 3b 0a 20 72 5b 32 5d | r[1] = a;. r[2]| 00001540 20 3d 20 30 3b 0a 20 73 77 69 28 22 57 69 6d 70 | = 0;. swi("Wimp| 00001550 5f 53 65 6e 64 4d 65 73 73 61 67 65 22 2c 72 29 |_SendMessage",r)| 00001560 3b 0a 20 66 28 66 69 6c 65 6e 61 6d 65 2c 66 69 |;. f(filename,fi| 00001570 6c 65 74 79 70 65 29 3b 0a 7d 0a 0a 54 68 65 20 |letype);.}..The | 00001580 24 20 66 75 6e 63 74 69 6f 6e 20 72 65 74 75 72 |$ function retur| 00001590 6e 73 20 74 68 65 20 73 74 72 69 6e 67 20 28 74 |ns the string (t| 000015a0 65 72 6d 69 6e 61 74 65 64 20 62 79 20 61 6e 20 |erminated by an | 000015b0 41 53 43 49 49 20 63 6f 64 65 20 6c 65 73 73 0a |ASCII code less.| 000015c0 74 68 61 6e 20 33 32 29 20 73 74 6f 72 65 64 20 |than 32) stored | 000015d0 61 74 20 61 6e 20 61 64 64 72 65 73 73 2e 20 54 |at an address. T| 000015e0 68 65 20 a3 a3 20 66 75 6e 63 74 69 6f 6e 20 6d |he .. function m| 000015f0 61 79 20 62 65 20 75 73 65 64 20 66 6f 72 20 70 |ay be used for p| 00001600 6f 6b 69 6e 67 20 0a 34 2d 62 79 74 65 20 77 6f |oking .4-byte wo| 00001610 72 64 73 20 69 6e 74 6f 20 70 6f 73 69 74 69 6f |rds into positio| 00001620 6e 73 20 69 6e 20 62 75 66 66 65 72 73 2e 0a 0a |ns in buffers...| 00001630 4e 6f 74 65 20 68 6f 77 20 74 68 65 20 66 75 6e |Note how the fun| 00001640 63 74 69 6f 6e 20 66 2c 20 74 68 65 20 61 63 74 |ction f, the act| 00001650 69 6f 6e 20 74 6f 20 62 65 20 74 61 6b 65 6e 2c |ion to be taken,| 00001660 20 69 73 20 70 61 73 73 65 64 20 61 73 20 61 20 | is passed as a | 00001670 70 61 72 61 6d 65 74 65 72 2e 0a |parameter..| 0000167b