home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / zsus / progpack / tp-user.lbr / TP-USER.PZT / TP-USER.PAT
Encoding:
Text File  |  1992-05-13  |  17.0 KB  |  387 lines

  1.         [ (c) 1986 by Carson Wilson. All rights reserved. This file may 
  2.         be reproduced for non-profit use only. The author is not 
  3.         responsible for losses resulting from the use of or inability to 
  4.         use this file. ]
  5.           
  6.  
  7.               GUIDE to PATCHING CP/M TURBO PASCAL for USER NUMBERS
  8.  
  9.         I. Introduction
  10.  
  11.              As the title indicates, this is not an actual patch for 
  12.         Turbo. It is a guide which gives general instructions on how to 
  13.         patch Turbo for CP/M's user numbers. Unless you have the exact 
  14.         version of Turbo I have, you will probably have to "write some 
  15.         code" of your own to make this patch work. Turbo is a tightly 
  16.         coded package. To patch it requires intelligent disassembly of 
  17.         Turbo and use of assembly language. This guide is designed to aid 
  18.         you in developing a patch for your particular version of Turbo.
  19.  
  20.         II. Explanation
  21.  
  22.              When writing a program, one normally changes it by adding 
  23.         features to or removing features from its source code at the 
  24.         appropriate place. But in this case we don't have the luxury of 
  25.         working with source code; only Turbo's object code is available 
  26.         to us. Because of the nature of compiled instructions, any 
  27.         features we add will have to take up code space already present 
  28.         within the program. Most of the space within an assembled program 
  29.         is already occupied by other instructions. If we simply add our 
  30.         custom instructions at the desired place in the code, we 
  31.         eliminate other, possibly vital features of the program. 
  32.              The solution is to find areas within the program we are 
  33.         patching which are not already occupied by instructions. Using a 
  34.         debugger, we can add our custom routines to these blank areas 
  35.         without interfering with the program's normal execution. 
  36.              One additional detail remains to be accounted for. The 
  37.         patched program must call or jump to our subroutine(s) during 
  38.         execution. The most obvious way of achieving this is simply to 
  39.         insert a "jump" or "call" instruction to the address of our 
  40.         custom routine at the proper place in the program's code. Then, 
  41.         when the program reaches this point, it will perform the 
  42.         instructions in our routine and resume execution. 
  43.              "Yes, but won't that jump itself overwrite the original 
  44.         code?", someone asks. 
  45.              Here, we have a problem. We could easily get the program to 
  46.         call our subroutine at the appropriate time, but the "call" or 
  47.         "jump" instruction itself takes up space--space which is normally 
  48.         occupied by other instructions. Getting around this problem 
  49.         requires sneakiness. Because our jump or call instruction 
  50.         typically takes up three bytes of code, we must replace the three 
  51.         bytes we have overwritten when we get to our custom routine. This 
  52.         can be done in a number of ways; the important thing is that the 
  53.         patched program thinks nothing unusual has happened when control 
  54.         returns to it. 
  55.  
  56.                                         1
  57.  
  58.         II. What the Patches Do
  59.  
  60.              The patches I designed do two things. The first one displays 
  61.         the current user as a number from 1 to 9 or a character from ":" 
  62.         to "@" along with the current drive at Turbo's main menu:
  63.  
  64.         --------------------------top of screen--------------------------
  65.         Logged drive: B0
  66.  
  67.         Work file: 
  68.         Main file: 
  69.  
  70.         Edit     Compile  Run   Save
  71.  
  72.         eXecute  Dir      Quit  compiler Options
  73.  
  74.         Text:     0 bytes (7BF5-7BF5)
  75.         Free: 20493 bytes (7BF6-CC03)
  76.  
  77.         > 
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.         characters from ":" to "@" are used to represent user areas 10 
  88.         through 15.
  89.              The second patch allows the user to select a user area or a 
  90.         drive letter in response to Turbo's "New drive:" prompt:
  91.  
  92.         --------------------------top of screen--------------------------
  93.         Logged drive: B0
  94.  
  95.         Work file: 
  96.         Main file: 
  97.  
  98.         Edit     Compile  Run   Save
  99.  
  100.         eXecute  Dir      Quit  compiler Options
  101.  
  102.         Text:     0 bytes (7BF5-7BF5)
  103.         Free: 20493 bytes (7BF6-CC03)
  104.  
  105.         >
  106.         New drive: 5
  107.  
  108.         >
  109.  
  110.  
  111.                                         2
  112.         --------------------------top of screen--------------------------
  113.         Logged drive: B5
  114.  
  115.         Work file: 
  116.         Main file: 
  117.  
  118.         Edit     Compile  Run   Save
  119.  
  120.         eXecute  Dir      Quit  compiler Options
  121.  
  122.         Text:     0 bytes (7BF5-7BF5)
  123.         Free: 20493 bytes (7BF6-CC03)
  124.  
  125.         >
  126.  
  127.         >
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.         IV. The Patches
  136.  
  137.              The following are examples based on Turbo version 3.00A for 
  138.         the Morrow. While the exact addresses may vary from version to 
  139.         version, the general form of this patch should apply to all CP/M 
  140.         Turbo Pascals of version 3.0 and higher.
  141.  
  142.              Step 1.
  143.  
  144.              The first object is to locate free space within Turbo's 
  145.         code. Using DDT's Dump option, I can view such an area between 
  146.         128 and 153 hex at the beginning of my version:
  147.  
  148.         -d100 16f
  149.         0100 C3 E2 20 CD AB 43 6F 70 79 72 69 67 68 74 20 28 .. ..Copyright (
  150.         0110 43 29 9 31 39 38 35 20 42 4F 52 4C 41 4E 44 4 C) 1985 BORLAND 
  151.         01
  152.         0149 6E 63 00 04 00 A1 42 4 C4 C0 0 0 0 4 CInc....B........
  153.         0130 00 00 00 00 00 00 00 00 0 ................
  154.         014444444................
  155.         01550 14 54 65 6C 65 76 69 64 65 6F F 9 31 ....Televideo 91
  156.         0160 32 2F 39 35 30 2F 39 32 
  157.  
  158.  
  159.  
  160.  18 8 8 2/920/92P.......
  161.         -
  162.              Step 2.
  163.  
  164.              The next step is to locate Turbo's routine to display its 
  165.         main menu. This routine is located by looking for the words 
  166.         8 8ayed in Turbo's main menu. For example: 00                                        3
  167.         -d2270 231f
  168.         2270 1A FE 1A C8 FE 20 C0 13 18 F6 CD 3E 02 CDCDA 01 ..... .....>....
  169.         2280 CC 6F 67 67 65 660 0  72 69 76 65 3A AAE .ogged drive:...
  170.         2290 19 9 05 4 CC6 41 1 C9 03 CD CD 01 8D 8A 8A D7 .....A..........
  171.         2222 6F 72 6B B 66 69 69 65 3A AA AA A9 9 31 CD FA ork file:...51..
  172.         22B0 01 8D 8A A 61 69 6E 9 656 69 6 6 3 3. This11 ....ain file:...
  173.         22C0 F9 44 CD F8 2D D FA 01 8D 8A 8A 85 64 69 7
  174.  .D..--dit 
  175.         22D0 20 2 20 main m3 6F 6D 70 69 669 669 669 6D2 75 6E     .ompile  .un
  176.         22EE600 D3 61 76 65 0D 0A 0A 65 D8 rive:.3 75 74    .ave...e.ecut
  177.         22F 0A5 600 C4 698 r600 600 600 D1 75 65 6 e  .ir      .uit
  178.         23030 0A3 6F 6 6  0A 0A 65 72
  179. F 70 74 69 6F   compiler .ptio
  180.         2310 6E 73 0D 0A 0A 54 65 78 74 3A 20 4 CED 5B 44 45 ns...Text: ..[DE
  181.         -
  182.              Step 3.
  183.  
  184.              Once we have found this general area, we need to locate the 
  185.         precise location at which Turbo 8 8ays the logged drive. The 
  186.         instructions to do this lie between the words "Logged drive:" and 
  187.         "Work file:" in Turbo's menu display routine. These instructions 
  188.         may be found using DDT's List command. For example (my comments):
  189.  
  190.         -l228d 229f
  191.           228D  ANA  B 
  192.           228E  NOP  
  193.           228F  MVI  C,19     ; call BDOS "get current drive" function69 66291  CALL 0005     ; - returns s ent drive code in 'a' reg.
  194.           2294  ADI  I         ; convert it to a c
  195.  
  196.  
  197. actert co96  CALL 03C9     ;     ;splay it (it's now a drive letter)
  198.           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       -  "    "   " 
  199.           229F  RST  02       ; "W" for "Work file:" with s s bit it t cot co 
  200.         2 4
  201.              Step 4file:"
  202. The place to call our subroutine toCC CC the current user 
  203.         number is immediately after ter ter lays the curr 3 rive 
  204.         letter. We will do this by overwriting the next three bytes of 
  205.         instructions with a call to our customF                                                                                                                    ine. Before 
  206.         overwriting these bytes, we must record them so that we can 
  207.         duplicate them fromter lthin our subroutine. 
  208.              In my version, the call to dcall oay the curthe curthe curetter 
  209.         begins at 2296 hex. The next instruction, "CACA 01FA", begins at 
  210.         2299 0 00 This iis i instruction my subroutine dour suicates. A):):
  211.         writing it down, I overwrite it with a call to my y outine erty using DDT's Assemble command:
  212.  
  213.         -a2299
  214.         229file:"
  215. call 129 9 second byte of e he spacA   my Turbo
  216.         229C
  217.         -
  218.  
  219.  
  220.                                         40 00
  221. Step 5.
  222.  
  223.              Next, we write the ion mion msplay the c
  224.         wrnt user at 
  225.         the free patch area we 44ed in step 1. I include the 
  226.         linon I instructiote ae alast 1. n of my custom 
  227.         routine--        -a1298 8ayfile:"
  228. mvi e,ff f get ready to. . . 
  229.         012B  m mc,,,,,;;;;;;. . .get cget ct user8 8ayD  call 5          ; get user in 'a' regigir
  230.         0130  adi 30          ; makmak into a charactell t
  231.         0135  movmak a         229Cet ready to. .  0A 0133 
  232.         01369 6Dc,2 e 
  233.         ; D 0A a downarrrrrrrrr in  in  regististist5  call 5          ;          
  234.         01
  235.  
  236.         01
  237.  
  238.              Ste        0138  jmp 1f8 8ayf8 8ayf do instructiitten9 9uction, back to menu
  239.         013BB
  240.              The "jmp 11" in" intion replaces the code in Turbo which I 
  241.         ):
  242. te in , bap 4 (above) with a cer 
  243. o this routine. I could 
  244.         have used "call all a and ret30 30 tead4 C4jf go a c is just a way 
  245.         to save a byte of code. The address to jump to may vary between 
  246.         versions of Turbo.
  247.  
  248.              W 20 m 20 mnow completed t012stom 5          ; do i to          -- stomt utineat Turbo's main menu. You may want to quit jus now 
  249.         and save ve w versionversionversionto aep 4
  250.         -
  251. ile:
  252.  
  253.         -g0                               ; exit jus
  254.         A>>e 121 turbo.com              ; create new dis35  le. versiont = 
  255.         rite                                ;  number of 256-incblocks 
  256.                                           *(see CP/M manual, ch. 4)file:"Run the  rec version to see if t012rrevmr is indeed 
  257.         d32yed along with E  ACC Cive. 
  258.  
  259.         :)   
  260.         d3   mbermber)     
  261. t ut)   we 4on toon to "g "g "g
  262.  
  263.              Step 6 this The next patch use1 tsame pri
  264.  
  265.         >
  266. i3 7as the first, but is 
  267.         somewhat morereadllenis iig.   "irst, we find the general region 
  268.         whereereo prompt1 tuser for a new de
  269.  
  270.              Wult drt drThis is 
  271.         don                                        4 looking for the words of the prompttor example,
  272.  
  273.         -d2cc0 2d00 000000002CC0 1F 30 FB 03 44   "8 3A 71 7B 5 6 D8 29 8 3Aive.  CD 4 C.0....:q{..CP////
  274.         2CD0 02 4E 6 737 9 654 urr 69 76 65 ciD routine. 22 1A FE .New drive..a"..2 12 
  275.  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
  276.         2D00 72 CD 00 02ste8 5locatF 4E 29 3.......k fD E1 03 r... (Y/N)? ....9 s
  277.  
  278.                                         5
  279.         reveals the prompt "
  280.  
  281.         >
  282. idrive" to the rightr ise screen in my 
  283.         ve calln of Turbo this t drt7 this Having 65 Dd this area, we next need to fon to  the p
  284.         A 
  285.         whe .pTurbo processe2Cser's respons; "'a'prompt. IR
  286.         particular,rsio are looking for the spotludcc09 0etermineten9whether the response was a c
  287.  
  288.  
  289. a1 tu less than "AFB All responses I  If less than "A9 3. the 5
  290. 71rive:" prompt are automatically 
  291.         ignored by T)   wSTB  ine 9 3ch checks the user's input 
  292.         44low1 t5
  293. 71rive:" prompt in the code jmr esomew3 7.
  294.                                                                                                                 atch u1 >omments): 
  295.  
  296. spla80cda his gf0
  297.  
  298.           2w vDD8NOPcurr
  299.           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
  300.              Ste          w v0 2d  ??=  20       ing 669 66CE2  DCR . F70 1ajump ahead to $w vE8 if not69 66CE
  301.         013BLDD8000
  302.  
  303.  
  304.  
  305.           2w vE6  ??=  1869 66CE7  DAD  B
  306.  
  307.           2w vEy 
  308.                                               .aL 04D A35  ltranslate respons; "uppercase69 66CEs eSUI  me ppppppp; n the   if response was less than "Aour sui
  309.           2w vED  RC            ;          -rn to menu if so
  310.  
  311.           2w vEE  CPI  1069 66Cle. RN to m69 66C0hcurrspla 6  p 8 this Normally, if erbo senses that the response given t, we ne 
  312.         5
  313. 71rive: " prompt was a c
  314.  
  315.  
  316. a1 tuter lth an ordinal value of 
  317.         less than 41 hex (capital A), i mcimply          -rns to 'a'3Eenu 0A 2B0 00
  318. e we wanteen i to accepnd ser numbers asrsioll as drive 
  319.         letters in response to its prompt, we will  30 te the ion m
  320.         whAss compare1 trespons; "capital Ater lth a 
  321.         bo our 
  322.         patch. To do this, routine-verwion mi the three bytes beginning at his geba"ex in my versioto oureen iter lth a 
  323.         bo my remaining free patch 
  324.         space at address 13b hex44eeeeeeee-et ceb....:s ede
  325. p 13b                                wi1st  instr byte actely yustom ro do i 1.....:E
  326.         -curr
  327.              S0 00
  328. e we a .p6 hng a jump 
  329.  
  330.              N instead of aee p 
  331.         instruction in this case,rsio must remember not only -- 
  332.  
  333.              Ns wt co ve overwritten, but also the address of the next 
  334.         inCACsemb so that our subroutine can jump back to this 
  335.         spot in Turbo.ST9 9uctionAD verwrote was "SUI 41," an2c
  336.         a whessurbo  next 
  337.  
  338.              N was his gee hex in my version. 
  339.  
  340.  
  341.                                         6A 5t drt9 this Now we a .pertyy to wion mi the final segmentr isis patch. 
  342.         w di custom ro do i tests for a numeric response to Turbo's 5
  343. ew 
  344.         drive:" prompt,  6 Step  a  regioistiault user when approp 
  345.           te, or 
  346.                  -rning to Turbo'sB  ine to  6  a  regiodisk drive if a drive 
  347.         letter was selected44eeeeeeee-a13bLL  su69 6D30itt see if response was less than "0our suiomptD  rcalon;          -rn to menu if so
  348. omptE  cpi 11          ; n the   if response was less than "Aour sui
  349.         0140  jc 148          ; ep 4
  350. s, ses the regiouser if so
  351.         0143  su69 6D11          ; no, subtract the 's L 11 (30+11=ress CP/ .
  352.         01411de
  353. p his gee urn .go back whe .pppp
  354. e): off .
  355.                                                                                                                           vers.)
  356.         014y 
  357.                                                                                                              o        ie,4 C4j>>t ertyy toD 0Atte149  .   c.0.w c) w is jent u new  into
  358.         014s ede
  359. p 5           ; ent u user and          -rn to  =
  360.         01AA.c
  361.         229Che only things which may vW with di 3.erent versions of 
  362.         Turboter lll be 1) the a whesses of this patch and 2) the a whess 
  363.         to jump back to.
  364.  
  365.              This compff1 tpatch to Turbo. QuittDT, sexi AD 
  366.         image as above, and test your new 0 .of T)   w I mchould 
  367.          calln):
  368. tNew user area as a c
  369.  
  370.  
  371. a1 tu from "09 3. "@", 
  372.         with characters ":" through "@" representing users 10 through 16. 
  373.         I mchould also respond t, we nese characters at the 5
  374. 71rive:" 
  375.         prompt, settat Tu):
  376. tNew user accordingly. 
  377.  
  378.         V. Successful Patch
  379.  
  380.  
  381.  
  382.  
  383.              If you  a bsuccessfully patched your Turbo and intend to 
  384.         pass this file alI., please use this  6  to record wherA   your 
  385.         0 .of Twayhe patches g600 6w diter lll allow future users of 
  386.         this file to compff the patch mo .peasily a
  387.         d3 afely. 
  388.  
  389.                                     H E Xr cA D D R E S S E S 
  390.                          --------- Patch 1 ---------- curr
  391.         Turbo Pascal     C 
  392.  
  393.    D4falon---- Patch 2 ---- 
  394.         Version/Machine  D4f  Fo66ing   DiI iy  jump to ener
  395.         o Author         User     C
  396.  
  397.  
  398. a1 tus  User     Ses theUser  Ses theUs
  399.              Ste        o Date           ion mB  ine     ion mB  ine   ion m
  400.         ===============  =======  ==========  =======  ========  ========
  401.         3.00D8/ Morrow   $. I      $01"W"$8  Y/$w vEB     $013B
  402.         o Carson Wilson
  403.         o June 23, 198679                          [ space for mor. . .dresses ]
  404. -7B (Y7
  405. fre
  406.              I012scc0are problems or questionsjump tontact me at these 
  407.         computer bu44 tin boards44eeeeeeeeeeeeeeeeeeee  
  408. llipute Z-Node 76 
  409.                      (312) 664-1730     
  410.                      (312) 0A 9-1730fre-7B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7B (Y8
  411. -7B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7B
  412. SSSSSSS