Home » Archimedes archive » Zipped Apps » 1st Word Plus » WP/programs/hoare/CurVarHelp
WP/programs/hoare/CurVarHelp
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 » Zipped Apps » 1st Word Plus |
Filename: | WP/programs/hoare/CurVarHelp |
Read OK: | ✔ |
File size: | 0743 bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
The first is with reference to the article on setting the Arthur prompt to the current directory name which appeared in Archive Vol 2 No4. There is a much easier way of doing this which only uses RMA memory temporarily and does not rely on interception of vectors. The approach required is to set up a special type of system variable which calls a segment of machine code to read or write its value. Full information and an example program are given on pages 347-351 of the programmer's reference manual. The short BASIC program DirPrmtSrc creates a utility file DirPrompt. The currnet directory prompt is set up by running this utility at the start of a session. DirPrompt creates the variable Curr$Dir and sets Cli$Prompt to print it instead of the normal prompt. When Curr$Dir is created it is given the type 16 which causes the operating system to copy the code for reading it into the system heap where all variables are stored. When the code is called it uses "OS_GBPB" to read the current directory and passes this back as the variable value. No code is needed for writing the variable since it is updated by the current filing system. RMA memory is required to run the utility, but is released as soon as the variable has been created. If you are already in BASIC and have no RMA space then running the BASIC program will do the job if lines 360 and 370 are deleted and the following line inserted 360CALL CreateVar Notes 1. *UNSET cannot be used to delete a type 16 variable and so, if you wish to revert to the normal prompt you must *UNSET Cli$Prompt. 2. If an error occurs when trying to read the directory, such as when the desktop filing system is in use, then the variable is set to a null string and a blank line is printed before the normal prompt. 3. Once set up, Curr$Dir survives until the next Ctrl Break. Steve Hoare, Washington DC.
00000000 54 68 65 20 66 69 72 73 74 20 69 73 20 77 69 74 |The first is wit| 00000010 68 20 72 65 66 65 72 65 6e 63 65 20 74 6f 20 74 |h reference to t| 00000020 68 65 20 61 72 74 69 63 6c 65 20 6f 6e 20 73 65 |he article on se| 00000030 74 74 69 6e 67 20 74 68 65 20 41 72 74 68 75 72 |tting the Arthur| 00000040 20 70 72 6f 6d 70 74 20 74 6f 20 74 68 65 20 63 | prompt to the c| 00000050 75 72 72 65 6e 74 20 64 69 72 65 63 74 6f 72 79 |urrent directory| 00000060 20 6e 61 6d 65 20 77 68 69 63 68 20 61 70 70 65 | name which appe| 00000070 61 72 65 64 20 69 6e 20 41 72 63 68 69 76 65 20 |ared in Archive | 00000080 56 6f 6c 20 32 20 4e 6f 34 2e 20 54 68 65 72 65 |Vol 2 No4. There| 00000090 20 69 73 20 61 20 6d 75 63 68 20 65 61 73 69 65 | is a much easie| 000000a0 72 20 77 61 79 20 6f 66 20 64 6f 69 6e 67 20 74 |r way of doing t| 000000b0 68 69 73 20 77 68 69 63 68 20 6f 6e 6c 79 20 75 |his which only u| 000000c0 73 65 73 20 52 4d 41 20 6d 65 6d 6f 72 79 20 74 |ses RMA memory t| 000000d0 65 6d 70 6f 72 61 72 69 6c 79 20 61 6e 64 20 64 |emporarily and d| 000000e0 6f 65 73 20 6e 6f 74 20 72 65 6c 79 20 6f 6e 20 |oes not rely on | 000000f0 69 6e 74 65 72 63 65 70 74 69 6f 6e 20 6f 66 20 |interception of | 00000100 76 65 63 74 6f 72 73 2e 20 54 68 65 20 61 70 70 |vectors. The app| 00000110 72 6f 61 63 68 20 72 65 71 75 69 72 65 64 20 69 |roach required i| 00000120 73 20 74 6f 20 73 65 74 20 75 70 20 61 20 73 70 |s to set up a sp| 00000130 65 63 69 61 6c 20 74 79 70 65 20 6f 66 20 73 79 |ecial type of sy| 00000140 73 74 65 6d 20 76 61 72 69 61 62 6c 65 20 77 68 |stem variable wh| 00000150 69 63 68 20 63 61 6c 6c 73 20 61 20 73 65 67 6d |ich calls a segm| 00000160 65 6e 74 20 6f 66 20 6d 61 63 68 69 6e 65 20 63 |ent of machine c| 00000170 6f 64 65 20 74 6f 20 72 65 61 64 20 6f 72 20 77 |ode to read or w| 00000180 72 69 74 65 20 69 74 73 20 76 61 6c 75 65 2e 20 |rite its value. | 00000190 46 75 6c 6c 20 69 6e 66 6f 72 6d 61 74 69 6f 6e |Full information| 000001a0 20 61 6e 64 20 61 6e 20 65 78 61 6d 70 6c 65 20 | and an example | 000001b0 70 72 6f 67 72 61 6d 20 61 72 65 20 67 69 76 65 |program are give| 000001c0 6e 20 6f 6e 20 70 61 67 65 73 20 33 34 37 2d 33 |n on pages 347-3| 000001d0 35 31 20 6f 66 20 74 68 65 20 70 72 6f 67 72 61 |51 of the progra| 000001e0 6d 6d 65 72 27 73 20 72 65 66 65 72 65 6e 63 65 |mmer's reference| 000001f0 20 6d 61 6e 75 61 6c 2e 0d 0d 54 68 65 20 73 68 | manual...The sh| 00000200 6f 72 74 20 42 41 53 49 43 20 70 72 6f 67 72 61 |ort BASIC progra| 00000210 6d 20 44 69 72 50 72 6d 74 53 72 63 20 63 72 65 |m DirPrmtSrc cre| 00000220 61 74 65 73 20 61 20 75 74 69 6c 69 74 79 20 66 |ates a utility f| 00000230 69 6c 65 20 44 69 72 50 72 6f 6d 70 74 2e 20 54 |ile DirPrompt. T| 00000240 68 65 20 63 75 72 72 6e 65 74 20 64 69 72 65 63 |he currnet direc| 00000250 74 6f 72 79 20 70 72 6f 6d 70 74 20 69 73 20 73 |tory prompt is s| 00000260 65 74 20 75 70 20 62 79 20 72 75 6e 6e 69 6e 67 |et up by running| 00000270 20 74 68 69 73 20 75 74 69 6c 69 74 79 20 61 74 | this utility at| 00000280 20 74 68 65 20 73 74 61 72 74 20 6f 66 20 61 20 | the start of a | 00000290 73 65 73 73 69 6f 6e 2e 20 44 69 72 50 72 6f 6d |session. DirProm| 000002a0 70 74 20 63 72 65 61 74 65 73 20 74 68 65 20 76 |pt creates the v| 000002b0 61 72 69 61 62 6c 65 20 43 75 72 72 24 44 69 72 |ariable Curr$Dir| 000002c0 20 61 6e 64 20 73 65 74 73 20 43 6c 69 24 50 72 | and sets Cli$Pr| 000002d0 6f 6d 70 74 20 74 6f 20 70 72 69 6e 74 20 69 74 |ompt to print it| 000002e0 20 69 6e 73 74 65 61 64 20 6f 66 20 74 68 65 20 | instead of the | 000002f0 6e 6f 72 6d 61 6c 20 70 72 6f 6d 70 74 2e 20 57 |normal prompt. W| 00000300 68 65 6e 20 43 75 72 72 24 44 69 72 20 69 73 20 |hen Curr$Dir is | 00000310 63 72 65 61 74 65 64 20 69 74 20 69 73 20 67 69 |created it is gi| 00000320 76 65 6e 20 74 68 65 20 74 79 70 65 20 31 36 20 |ven the type 16 | 00000330 77 68 69 63 68 20 63 61 75 73 65 73 20 74 68 65 |which causes the| 00000340 20 6f 70 65 72 61 74 69 6e 67 20 73 79 73 74 65 | operating syste| 00000350 6d 20 74 6f 20 63 6f 70 79 20 74 68 65 20 63 6f |m to copy the co| 00000360 64 65 20 66 6f 72 20 72 65 61 64 69 6e 67 20 69 |de for reading i| 00000370 74 20 69 6e 74 6f 20 74 68 65 20 73 79 73 74 65 |t into the syste| 00000380 6d 20 68 65 61 70 20 77 68 65 72 65 20 61 6c 6c |m heap where all| 00000390 20 76 61 72 69 61 62 6c 65 73 20 61 72 65 20 73 | variables are s| 000003a0 74 6f 72 65 64 2e 20 57 68 65 6e 20 74 68 65 20 |tored. When the | 000003b0 63 6f 64 65 20 69 73 20 63 61 6c 6c 65 64 20 69 |code is called i| 000003c0 74 20 75 73 65 73 20 22 4f 53 5f 47 42 50 42 22 |t uses "OS_GBPB"| 000003d0 20 74 6f 20 72 65 61 64 20 74 68 65 20 63 75 72 | to read the cur| 000003e0 72 65 6e 74 20 64 69 72 65 63 74 6f 72 79 20 61 |rent directory a| 000003f0 6e 64 20 70 61 73 73 65 73 20 74 68 69 73 20 62 |nd passes this b| 00000400 61 63 6b 20 61 73 20 74 68 65 20 76 61 72 69 61 |ack as the varia| 00000410 62 6c 65 20 76 61 6c 75 65 2e 20 4e 6f 20 63 6f |ble value. No co| 00000420 64 65 20 69 73 20 6e 65 65 64 65 64 20 66 6f 72 |de is needed for| 00000430 20 77 72 69 74 69 6e 67 20 74 68 65 20 76 61 72 | writing the var| 00000440 69 61 62 6c 65 20 73 69 6e 63 65 20 69 74 20 69 |iable since it i| 00000450 73 20 75 70 64 61 74 65 64 20 62 79 20 74 68 65 |s updated by the| 00000460 20 63 75 72 72 65 6e 74 20 66 69 6c 69 6e 67 20 | current filing | 00000470 73 79 73 74 65 6d 2e 20 52 4d 41 20 6d 65 6d 6f |system. RMA memo| 00000480 72 79 20 69 73 20 72 65 71 75 69 72 65 64 20 74 |ry is required t| 00000490 6f 20 72 75 6e 20 74 68 65 20 75 74 69 6c 69 74 |o run the utilit| 000004a0 79 2c 20 62 75 74 20 69 73 20 72 65 6c 65 61 73 |y, but is releas| 000004b0 65 64 20 61 73 20 73 6f 6f 6e 20 61 73 20 74 68 |ed as soon as th| 000004c0 65 20 76 61 72 69 61 62 6c 65 20 68 61 73 20 62 |e variable has b| 000004d0 65 65 6e 20 63 72 65 61 74 65 64 2e 20 49 66 20 |een created. If | 000004e0 79 6f 75 20 61 72 65 20 61 6c 72 65 61 64 79 20 |you are already | 000004f0 69 6e 20 42 41 53 49 43 20 61 6e 64 20 68 61 76 |in BASIC and hav| 00000500 65 20 6e 6f 20 52 4d 41 20 73 70 61 63 65 20 74 |e no RMA space t| 00000510 68 65 6e 20 72 75 6e 6e 69 6e 67 20 74 68 65 20 |hen running the | 00000520 42 41 53 49 43 20 70 72 6f 67 72 61 6d 20 77 69 |BASIC program wi| 00000530 6c 6c 20 64 6f 20 74 68 65 20 6a 6f 62 20 69 66 |ll do the job if| 00000540 20 6c 69 6e 65 73 20 33 36 30 20 61 6e 64 20 33 | lines 360 and 3| 00000550 37 30 20 61 72 65 20 64 65 6c 65 74 65 64 20 61 |70 are deleted a| 00000560 6e 64 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 |nd the following| 00000570 20 6c 69 6e 65 20 69 6e 73 65 72 74 65 64 0d 0d | line inserted..| 00000580 33 36 30 43 41 4c 4c 20 43 72 65 61 74 65 56 61 |360CALL CreateVa| 00000590 72 0d 0d 4e 6f 74 65 73 20 31 2e 20 2a 55 4e 53 |r..Notes 1. *UNS| 000005a0 45 54 20 63 61 6e 6e 6f 74 20 62 65 20 75 73 65 |ET cannot be use| 000005b0 64 20 74 6f 20 64 65 6c 65 74 65 20 61 20 74 79 |d to delete a ty| 000005c0 70 65 20 31 36 20 76 61 72 69 61 62 6c 65 20 61 |pe 16 variable a| 000005d0 6e 64 20 73 6f 2c 20 69 66 20 79 6f 75 20 77 69 |nd so, if you wi| 000005e0 73 68 20 74 6f 20 72 65 76 65 72 74 20 74 6f 20 |sh to revert to | 000005f0 74 68 65 20 6e 6f 72 6d 61 6c 20 70 72 6f 6d 70 |the normal promp| 00000600 74 20 79 6f 75 20 6d 75 73 74 20 2a 55 4e 53 45 |t you must *UNSE| 00000610 54 20 43 6c 69 24 50 72 6f 6d 70 74 2e 20 32 2e |T Cli$Prompt. 2.| 00000620 20 49 66 20 61 6e 20 65 72 72 6f 72 20 6f 63 63 | If an error occ| 00000630 75 72 73 20 77 68 65 6e 20 74 72 79 69 6e 67 20 |urs when trying | 00000640 74 6f 20 72 65 61 64 20 74 68 65 20 64 69 72 65 |to read the dire| 00000650 63 74 6f 72 79 2c 20 73 75 63 68 20 61 73 20 77 |ctory, such as w| 00000660 68 65 6e 20 74 68 65 20 64 65 73 6b 74 6f 70 20 |hen the desktop | 00000670 66 69 6c 69 6e 67 20 73 79 73 74 65 6d 20 69 73 |filing system is| 00000680 20 69 6e 20 75 73 65 2c 20 74 68 65 6e 20 74 68 | in use, then th| 00000690 65 20 76 61 72 69 61 62 6c 65 20 69 73 20 73 65 |e variable is se| 000006a0 74 20 74 6f 20 61 20 6e 75 6c 6c 20 73 74 72 69 |t to a null stri| 000006b0 6e 67 20 61 6e 64 20 61 20 62 6c 61 6e 6b 20 6c |ng and a blank l| 000006c0 69 6e 65 20 69 73 20 70 72 69 6e 74 65 64 20 62 |ine is printed b| 000006d0 65 66 6f 72 65 20 74 68 65 20 6e 6f 72 6d 61 6c |efore the normal| 000006e0 20 70 72 6f 6d 70 74 2e 20 33 2e 20 4f 6e 63 65 | prompt. 3. Once| 000006f0 20 73 65 74 20 75 70 2c 20 43 75 72 72 24 44 69 | set up, Curr$Di| 00000700 72 20 73 75 72 76 69 76 65 73 20 75 6e 74 69 6c |r survives until| 00000710 20 74 68 65 20 6e 65 78 74 20 43 74 72 6c 20 42 | the next Ctrl B| 00000720 72 65 61 6b 2e 0d 0d 53 74 65 76 65 20 48 6f 61 |reak...Steve Hoa| 00000730 72 65 2c 20 57 61 73 68 69 6e 67 74 6f 6e 20 44 |re, Washington D| 00000740 43 2e 0d |C..| 00000743