home *** CD-ROM | disk | FTP | other *** search
Wrap
[ (c) 1986 by Carson Wilson. All rights reserved. This file may be reproduced for non-profit use only. The author is not responsible for losses resulting from the use of or inability to use this file. ] GUIDE to PATCHING CP/M TURBO PASCAL for USER NUMBERS I. Introduction As the title indicates, this is not an actual patch for Turbo. It is a guide which gives general instructions on how to patch Turbo for CP/M's user numbers. Unless you have the exact version of Turbo I have, you will probably have to "write some code" of your own to make this patch work. Turbo is a tightly coded package. To patch it requires intelligent disassembly of Turbo and use of assembly language. This guide is designed to aid you in developing a patch for your particular version of Turbo. II. Explanation When writing a program, one normally changes it by adding features to or removing features from its source code at the appropriate place. But in this case we don't have the luxury of working with source code; only Turbo's object code is available to us. Because of the nature of compiled instructions, any features we add will have to take up code space already present within the program. Most of the space within an assembled program is already occupied by other instructions. If we simply add our custom instructions at the desired place in the code, we eliminate other, possibly vital features of the program. The solution is to find areas within the program we are patching which are not already occupied by instructions. Using a debugger, we can add our custom routines to these blank areas without interfering with the program's normal execution. One additional detail remains to be accounted for. The patched program must call or jump to our subroutine(s) during execution. The most obvious way of achieving this is simply to insert a "jump" or "call" instruction to the address of our custom routine at the proper place in the program's code. Then, when the program reaches this point, it will perform the instructions in our routine and resume execution. "Yes, but won't that jump itself overwrite the original code?", someone asks. Here, we have a problem. We could easily get the program to call our subroutine at the appropriate time, but the "call" or "jump" instruction itself takes up space--space which is normally occupied by other instructions. Getting around this problem requires sneakiness. Because our jump or call instruction typically takes up three bytes of code, we must replace the three bytes we have overwritten when we get to our custom routine. This can be done in a number of ways; the important thing is that the patched program thinks nothing unusual has happened when control returns to it. 1 II. What the Patches Do The patches I designed do two things. The first one displays the current user as a number from 1 to 9 or a character from ":" to "@" along with the current drive at Turbo's main menu: --------------------------top of screen-------------------------- Logged drive: B0 Work file: Main file: Edit Compile Run Save eXecute Dir Quit compiler Options Text: 0 bytes (7BF5-7BF5) Free: 20493 bytes (7BF6-CC03) > characters from ":" to "@" are used to represent user areas 10 through 15. The second patch allows the user to select a user area or a drive letter in response to Turbo's "New drive:" prompt: --------------------------top of screen-------------------------- Logged drive: B0 Work file: Main file: Edit Compile Run Save eXecute Dir Quit compiler Options Text: 0 bytes (7BF5-7BF5) Free: 20493 bytes (7BF6-CC03) > New drive: 5 > 2 --------------------------top of screen-------------------------- Logged drive: B5 Work file: Main file: Edit Compile Run Save eXecute Dir Quit compiler Options Text: 0 bytes (7BF5-7BF5) Free: 20493 bytes (7BF6-CC03) > > IV. The Patches The following are examples based on Turbo version 3.00A for the Morrow. While the exact addresses may vary from version to version, the general form of this patch should apply to all CP/M Turbo Pascals of version 3.0 and higher. Step 1. The first object is to locate free space within Turbo's code. Using DDT's Dump option, I can view such an area between 128 and 153 hex at the beginning of my version: -d100 16f 0100 C3 E2 20 CD AB 43 6F 70 79 72 69 67 68 74 20 28 .. ..Copyright ( 0110 43 29 9 31 39 38 35 20 42 4F 52 4C 41 4E 44 4 C) 1985 BORLAND 01 0149 6E 63 00 04 00 A1 42 4 C4 C0 0 0 0 4 CInc....B........ 0130 00 00 00 00 00 00 00 00 0 ................ 014444444................ 01550 14 54 65 6C 65 76 69 64 65 6F F 9 31 ....Televideo 91 0160 32 2F 39 35 30 2F 39 32 18 8 8 2/920/92P....... - Step 2. The next step is to locate Turbo's routine to display its main menu. This routine is located by looking for the words 8 8ayed in Turbo's main menu. For example: 00 3 -d2270 231f 2270 1A FE 1A C8 FE 20 C0 13 18 F6 CD 3E 02 CDCDA 01 ..... .....>.... 2280 CC 6F 67 67 65 660 0 72 69 76 65 3A AAE .ogged drive:... 2290 19 9 05 4 CC6 41 1 C9 03 CD CD 01 8D 8A 8A D7 .....A.......... 2222 6F 72 6B B 66 69 69 65 3A AA AA A9 9 31 CD FA ork file:...51.. 22B0 01 8D 8A A 61 69 6E 9 656 69 6 6 3 3. This11 ....ain file:... 22C0 F9 44 CD F8 2D D FA 01 8D 8A 8A 85 64 69 7 .D..--dit 22D0 20 2 20 main m3 6F 6D 70 69 669 669 669 6D2 75 6E .ompile .un 22EE600 D3 61 76 65 0D 0A 0A 65 D8 rive:.3 75 74 .ave...e.ecut 22F 0A5 600 C4 698 r600 600 600 D1 75 65 6 e .ir .uit 23030 0A3 6F 6 6 0A 0A 65 72 F 70 74 69 6F compiler .ptio 2310 6E 73 0D 0A 0A 54 65 78 74 3A 20 4 CED 5B 44 45 ns...Text: ..[DE - Step 3. Once we have found this general area, we need to locate the precise location at which Turbo 8 8ays the logged drive. The instructions to do this lie between the words "Logged drive:" and "Work file:" in Turbo's menu display routine. These instructions may be found using DDT's List command. For example (my comments): -l228d 229f 228D ANA B 228E NOP 228F MVI C,19 ; call BDOS "get current drive" function69 66291 CALL 0005 ; - returns s ent drive code in 'a' reg. 2294 ADI I ; convert it to a c actert co96 CALL 03C9 ; ;splay it (it's now a drive letter) 2299 9 L 01FA FA FA play following characters (my vers.l2229C A AA AL ; carriageageurn - high bit sett co9t co9ADDD D line feed - " " "t co9E ADAD ; line feed - " " " 229F RST 02 ; "W" for "Work file:" with s s bit it t cot co 2 4 Step 4file:" The place to call our subroutine toCC CC the current user number is immediately after ter ter lays the curr 3 rive letter. We will do this by overwriting the next three bytes of instructions with a call to our customF ine. Before overwriting these bytes, we must record them so that we can duplicate them fromter lthin our subroutine. In my version, the call to dcall oay the curthe curthe curetter begins at 2296 hex. The next instruction, "CACA 01FA", begins at 2299 0 00 This iis i instruction my subroutine dour suicates. A):): writing it down, I overwrite it with a call to my y outine erty using DDT's Assemble command: -a2299 229file:" call 129 9 second byte of e he spacA my Turbo 229C - 40 00 Step 5. Next, we write the ion mion msplay the c wrnt user at the free patch area we 44ed in step 1. I include the linon I instructiote ae alast 1. n of my custom routine-- -a1298 8ayfile:" mvi e,ff f get ready to. . . 012B m mc,,,,,;;;;;;. . .get cget ct user8 8ayD call 5 ; get user in 'a' regigir 0130 adi 30 ; makmak into a charactell t 0135 movmak a 229Cet ready to. . 0A 0133 01369 6Dc,2 e ; D 0A a downarrrrrrrrr in in regististist5 call 5 ; 01 01 Ste 0138 jmp 1f8 8ayf8 8ayf do instructiitten9 9uction, back to menu 013BB The "jmp 11" in" intion replaces the code in Turbo which I ): te in , bap 4 (above) with a cer o this routine. I could have used "call all a and ret30 30 tead4 C4jf go a c is just a way to save a byte of code. The address to jump to may vary between versions of Turbo. W 20 m 20 mnow completed t012stom 5 ; do i to -- stomt utineat Turbo's main menu. You may want to quit jus now and save ve w versionversionversionto aep 4 - ile: -g0 ; exit jus A>>e 121 turbo.com ; create new dis35 le. versiont = rite ; number of 256-incblocks *(see CP/M manual, ch. 4)file:"Run the rec version to see if t012rrevmr is indeed d32yed along with E ACC Cive. :) d3 mbermber) t ut) we 4on toon to "g "g "g Step 6 this The next patch use1 tsame pri > i3 7as the first, but is somewhat morereadllenis iig. "irst, we find the general region whereereo prompt1 tuser for a new de Wult drt drThis is don 4 looking for the words of the prompttor example, -d2cc0 2d00 000000002CC0 1F 30 FB 03 44 "8 3A 71 7B 5 6 D8 29 8 3Aive. CD 4 C.0....:q{..CP//// 2CD0 02 4E 6 737 9 654 urr 69 76 65 ciD routine. 22 1A FE .New drive..a"..2 12 1A ;y iFA F 04 4 C8 3A0h bD A6 04 D6 41 >. "E 10 . .:........all aaa2 1cl D69 74 CCE 00 00 732 F1 370 1a a0 5F 0E 0E C3 65 .....er.2.._...e 2D00 72 CD 00 02ste8 5locatF 4E 29 3.......k fD E1 03 r... (Y/N)? ....9 s 5 reveals the prompt " > idrive" to the rightr ise screen in my ve calln of Turbo this t drt7 this Having 65 Dd this area, we next need to fon to the p A whe .pTurbo processe2Cser's respons; "'a'prompt. IR particular,rsio are looking for the spotludcc09 0etermineten9whether the response was a c a1 tu less than "AFB All responses I If less than "A9 3. the 5 71rive:" prompt are automatically ignored by T) wSTB ine 9 3ch checks the user's input 44low1 t5 71rive:" prompt in the code jmr esomew3 7. atch u1 >omments): spla80cda his gf0 2w vDD8NOPcurr 2w vDs e..aL 22user futineCD0o get utineresponse69 66CDE LDAX D ; ps int in regi, c lle69 66CDF CPI 1A ; n the if 186E ontrolreadract Ste w v0 2d ??= 20 ing 669 66CE2 DCR . F70 1ajump ahead to $w vE8 if not69 66CE 013BLDD8000 2w vE6 ??= 1869 66CE7 DAD B 2w vEy .aL 04D A35 ltranslate respons; "uppercase69 66CEs eSUI me ppppppp; n the if response was less than "Aour sui 2w vED RC ; -rn to menu if so 2w vEE CPI 1069 66Cle. RN to m69 66C0hcurrspla 6 p 8 this Normally, if erbo senses that the response given t, we ne 5 71rive: " prompt was a c a1 tuter lth an ordinal value of less than 41 hex (capital A), i mcimply -rns to 'a'3Eenu 0A 2B0 00 e we wanteen i to accepnd ser numbers asrsioll as drive letters in response to its prompt, we will 30 te the ion m whAss compare1 trespons; "capital Ater lth a bo our patch. To do this, routine-verwion mi the three bytes beginning at his geba"ex in my versioto oureen iter lth a bo my remaining free patch space at address 13b hex44eeeeeeee-et ceb....:s ede p 13b wi1st instr byte actely yustom ro do i 1.....:E -curr S0 00 e we a .p6 hng a jump N instead of aee p instruction in this case,rsio must remember not only -- Ns wt co ve overwritten, but also the address of the next inCACsemb so that our subroutine can jump back to this spot in Turbo.ST9 9uctionAD verwrote was "SUI 41," an2c a whessurbo next N was his gee hex in my version. 6A 5t drt9 this Now we a .pertyy to wion mi the final segmentr isis patch. w di custom ro do i tests for a numeric response to Turbo's 5 ew drive:" prompt, 6 Step a regioistiault user when approp te, or -rning to Turbo'sB ine to 6 a regiodisk drive if a drive letter was selected44eeeeeeee-a13bLL su69 6D30itt see if response was less than "0our suiomptD rcalon; -rn to menu if so omptE cpi 11 ; n the if response was less than "Aour sui 0140 jc 148 ; ep 4 s, ses the regiouser if so 0143 su69 6D11 ; no, subtract the 's L 11 (30+11=ress CP/ . 01411de p his gee urn .go back whe .pppp e): off . vers.) 014y o ie,4 C4j>>t ertyy toD 0Atte149 . c.0.w c) w is jent u new into 014s ede p 5 ; ent u user and -rn to = 01AA.c 229Che only things which may vW with di 3.erent versions of Turboter lll be 1) the a whesses of this patch and 2) the a whess to jump back to. This compff1 tpatch to Turbo. QuittDT, sexi AD image as above, and test your new 0 .of T) w I mchould calln): tNew user area as a c a1 tu from "09 3. "@", with characters ":" through "@" representing users 10 through 16. I mchould also respond t, we nese characters at the 5 71rive:" prompt, settat Tu): tNew user accordingly. V. Successful Patch If you a bsuccessfully patched your Turbo and intend to pass this file alI., please use this 6 to record wherA your 0 .of Twayhe patches g600 6w diter lll allow future users of this file to compff the patch mo .peasily a d3 afely. H E Xr cA D D R E S S E S --------- Patch 1 ---------- curr Turbo Pascal C D4falon---- Patch 2 ---- Version/Machine D4f Fo66ing DiI iy jump to ener o Author User C a1 tus User Ses theUser Ses theUs Ste o Date ion mB ine ion mB ine ion m =============== ======= ========== ======= ======== ======== 3.00D8/ Morrow $. I $01"W"$8 Y/$w vEB $013B o Carson Wilson o June 23, 198679 [ space for mor. . .dresses ] -7B (Y7 fre I012scc0are problems or questionsjump tontact me at these computer bu44 tin boards44eeeeeeeeeeeeeeeeeeee llipute Z-Node 76 (312) 664-1730 (312) 0A 9-1730fre-7B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7B (Y8 -7B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7B SSSSSSS