[net.micro.ti] Using PC-DOS Turbo Pascal on the TI-Pro

las@apr.UUCP (Larry Shurr) (06/03/86)

Would you like to be able to execute the PC-DOS version of Turbo Pascal 
on your Texas Instruments Professional Computer rather than the generic 
MS-DOS version?  Let me tell you why the answer is yes.

        * Faster screen output

	* Support for function keys

        - but more importantly -

        * You can order the PC-DOS versions from the mail-order
          discounters much more cheaply than from Borland

I have determined how to do this adaptation.  You will need to use the 
TI-supplied program, EMULATE.COM and and you must apply the following 
patches to the TURBO.COM program image.  Please note: This patch set 
only gets Turbo Pascal up and running.  Most of the special IBM PC 
support features such as sound and graphics still do not work.  If there
is sufficient interest, I MAY work on additional patches to get these 
to work (I would like to see these features working, myself.  If you 
come up with any such patches, please send them to me and I will com-
bine them with any new patches I come up with to produce an updated 
patch set.

Now, assuming your answer is yes, here's what you want to know.  But 
first, a disclaimer:

	I have tested the following patches and I believe 
	that they work as stated.  However, when you patch
	your copy of Turbo Pascal, you do so at your own 
	discretion and at your own risk.  Neither I, my 
	employer, or anyone else  warrant these modifica-
	tions in any way; nor will I or anyone else 
	indemnify you against the consequences of employing 
	them.

Now, enough legal stuff, on with the info:

Required:

        * MS-DOS 2.11 or later for the TI Pro
        * PC-DOS version 3.01A of Turbo Pascal

What to do:

You must use the EMULATE.COM program supplied on the MS-DOS release disk.  
When executed, this program installs itself as a resident program and 
emulates a number of the IBM PC ROM BIOS functions.  This program will 
translate Turbo Pascal's BIOS calls to the appropriate TI Pro calls.  
This is how the keyboard and screen I/O are supported.  For your con-
venience, edit your AUTOEXEC.BAT file to execute EMULATE.COM.  If you 
fail to install EMULATE.COM and you attempt to run TURBO.COM, even with 
the patches, you will be rewarded with a 1042 system error (wild inter-
rupt) and you will have to reboot.

In addition, the patches described below are required.  These changes are 
for the "plain" version of Turbo Pascal.  They may be applicable to the 
8087 and BCD versions as well.  If the affected code is in a different 
place, however, the patches will have to be adapted.  I'm not in a 
position to determine that right now, sorry.

The affected code is in two areas:  One is a rather funky segment of code 
which apparently estimates the system clock speed by intercepting the real-
time clock interrupt and flipping a flag while a loop spins waiting for the 
the state of that flag to change.  On the TI Pro, the measure will be too 
fast, due to its 25 millisecond clock interval (instead of the IBM PC' 55 
milliseconds).  I do not yet know what this estimate is used for (I suspect 
it has to do with the sound feature) and I have done nothing to correct the 
error in the estimate.  The other change is in a routine used by the Turbo 
Pascal editor to write to the display.  The Turbo editor is "poorly behaved" 
and writes directly to video memory.  I have patched this code to write to 
the TI Pro's video memory.  Since the TI display hardware is significantly 
different from the IBM PC, the result is itself rather funky, but effective.


		Differences between the IBM PC version
		of TURBO.COM and the patched version
		for the TI Pro:

Offset        Original  New
in File       data for  data for
TURBO.COM     IBM PC    TI Pro
--------      ------    ------
000000A6      20        0C
000000A7      00        01
000000CC      20        0C
000000CD      00        01
00005092      16        2D
00005097      8B        B4
00005098      FD        17
00005099      8E        CD
0000509A      06        49
0000509B      90        D1
0000509C      05        ED
0000509D      BE        03
0000509E      EE        EA
0000509F      04        B8
000050A0      80        00
000050A1      3E        DE
000050A2      93        8E
000050A3      05        C0
000050A4      FF        8B
000050A5      74        FD
000050A6      03        BE
000050A7      F3        EE
000050A8      A5        04
000050A9      C3        AD
000050AA      BA        82
000050AB      DA        FC
000050AC      03        07
000050AD      AD        75
000050AE      8B        02
000050AF      E8        B4
000050B0      EC        0D
000050B1      D0        26
000050B2      D8        88
000050B3      72        26
000050B4      FB        00
000050B5      FA        18
000050B6      EC        AA
000050B7      D0        E2
000050B8      D8        F0
000050B9      73        26
000050BA      FB        C6
000050BB      95        06
000050BC      AB        00
000050BD      FB        18
000050BE      E2        0F
000050BF      ED        90


Following is a disassembly listing of the affected code for the IBM PC 
version of TURBO Pascal.  The "xxxx"'s in the listing represent the 
fact that the segment portion of the address is dependent on your 
system configuration.  The segment base for the program is irrelevant 
for purpose of this discussion anyway.


			    Code for IBM PClone


xxxx:01A0 C606940100                    MOV     B,[0194],00
xxxx:01A5 BE2000                        MOV     SI,0020
xxxx:01A8 26:8B04                       MOV     AX,ES:[SI]
xxxx:01AB 2E:A39501                     MOV     CS:[0195],AX
xxxx:01AF 26:8B4402                     MOV     AX,ES:[SI+0002]
xxxx:01B3 2E:A39701                     MOV     CS:[0197],AX
xxxx:01B7 FA                            CLI
xxxx:01B8 26:C704C401                   MOV     W,ES:[SI],01C4
xxxx:01BD 26:8C4C02                     MOV     ES:[SI+0002],CS
xxxx:01C1 FB                            STI
xxxx:01C2 EB22                          JMPS    01E6
xxxx:01C4 1E                            PUSH    DS
xxxx:01C5 50                            PUSH    AX
xxxx:01C6 33C0                          XOR     AX,AX
xxxx:01C8 8ED8                          MOV     DS,AX
xxxx:01CA C7062000DB01                  MOV     W,[0020],01DB
xxxx:01D0 2E:A39201                     MOV     CS:[0192],AX
xxxx:01D4 58                            POP     AX
xxxx:01D5 1F                            POP     DS
xxxx:01D6 2E:FF2E9501                   JMP     F,CS:[0195]
xxxx:01DB 2E:C6069401FF                 MOV     B,CS:[0194],FF
xxxx:01E1 2E:FF2E9501                   JMP     F,CS:[0195]

xxxx:5191 7416                          JZ      51A9
xxxx:5193 8BCE                          MOV     CX,SI
xxxx:5195 D1E9                          SHR     CX,1
xxxx:5197 8BFD                          MOV     DI,BP
xxxx:5199 8E069005                      MOV     ES,[0590]
xxxx:519D BEEE04                        MOV     SI,04EE
xxxx:51A0 803E9305FF                    CMP     B,[0593],FF
xxxx:51A5 7403                          JZ      51AA
xxxx:51A7 F3/A5                   REP   MOVSW
xxxx:51A9 C3                            RET
xxxx:51AA BADA03                        MOV     DX,03DA
xxxx:51AD AD                            LODSW
xxxx:51AE 8BE8                          MOV     BP,AX
xxxx:51B0 EC                            IN      AL,DX
xxxx:51B1 D0D8                          RCR     AL,1
xxxx:51B3 72FB                          JC      51B0
xxxx:51B5 FA                            CLI
xxxx:51B6 EC                            IN      AL,DX
xxxx:51B7 D0D8                          RCR     AL,1
xxxx:51B9 73FB                          JNC     51B6
xxxx:51BB 95                            XCHG    AX,BP
xxxx:51BC AB                            STOSW
xxxx:51BD FB                            STI
xxxx:51BE E2ED                          LOOP    51AD
xxxx:51C0 C3                            RET


Similarly, the following is a disassembly listing of the code as 
modified for the TI Pro with the changed code marked for easy
reference.

			Code for TI Professional

		     ( "<---" indicates new code )

xxxx:01A0 C606940100                    MOV     B,[0194],00
xxxx:01A5 BE0C01                        MOV     SI,010C         <---
xxxx:01A8 26:8B04                       MOV     AX,ES:[SI]
xxxx:01AB 2E:A39501                     MOV     CS:[0195],AX
xxxx:01AF 26:8B4402                     MOV     AX,ES:[SI+0002]
xxxx:01B3 2E:A39701                     MOV     CS:[0197],AX
xxxx:01B7 FA                            CLI
xxxx:01B8 26:C704C401                   MOV     W,ES:[SI],01C4
xxxx:01BD 26:8C4C02                     MOV     ES:[SI+0002],CS
xxxx:01C1 FB                            STI
xxxx:01C2 EB22                          JMPS    01E6
xxxx:01C4 1E                            PUSH    DS
xxxx:01C5 50                            PUSH    AX
xxxx:01C6 33C0                          XOR     AX,AX
xxxx:01C8 8ED8                          MOV     DS,AX
xxxx:01CA C7060C01DB01                  MOV     W,[010C],01DB   <---
xxxx:01D0 2E:A39201                     MOV     CS:[0192],AX
xxxx:01D4 58                            POP     AX
xxxx:01D5 1F                            POP     DS
xxxx:01D6 2E:FF2E9501                   JMP     F,CS:[0195]
xxxx:01DB 2E:C6069401FF                 MOV     B,CS:[0194],FF
xxxx:01E1 2E:FF2E9501                   JMP     F,CS:[0195]

xxxx:5191 742D                          JZ      51C0            <---
xxxx:5193 8BCE                          MOV     CX,SI  
xxxx:5195 D1E9                          SHR     CX,1  
xxxx:5197 B417                          MOV     AH,17           <---
xxxx:5199 CD49                          INT     49              <---
xxxx:519B D1ED                          SHR     BP,1            <---
xxxx:519D 03EA                          ADD     BP,DX           <---
xxxx:519F B800DE                        MOV     AX,DE00         <---
xxxx:51A2 8EC0                          MOV     ES,AX           <---
xxxx:51A4 8BFD                          MOV     DI,BP           <---
xxxx:51A6 BEEE04                        MOV     SI,04EE         <---
xxxx:51A9 AD                            LODSW                   <---
xxxx:51AA 82FC07                        CMP     AH,07           <---
xxxx:51AD 7502                          JNZ     51B1            <---
xxxx:51AF B40D                          MOV     AH,0D           <---
xxxx:51B1 26:88260018                   MOV     ES:[1800],AH    <---
xxxx:51B6 AA                            STOSB                   <---
xxxx:51B7 E2F0                          LOOP    51A9            <---
xxxx:51B9 26:C60600180F                 MOV     B,ES:[1800],0F  <---
xxxx:51BF 90                            NOP                     <---
xxxx:51C0 C3                            RET


		Commands for modifying TURBO.COM

You may modify TURBO.COM using the MS-DOS DEBUG program.  Assume that 
you have a copy of TURBO.COM in drive A: and that you have selected 
A: as your default drive.  Enter the following seuquence of commands 
to modify it for the TI Professional Computer.  Note: perform these 
modifications on a copy of your turbo disk, not your original.

A>debug turbo.com
-a1a5
xxxx:01A5    MOV     SI,010C
xxxx:01A8
-a1ca
xxxx:01CA    MOV     W,[010C],01DB
xxxx:01D0
-a5191
xxxx:5191    JZ      51C0
xxxx:5193    MOV     CX,SI
xxxx:5195    SHR     CX,1
xxxx:5197    MOV     AH,17
xxxx:5199    INT     49
xxxx:519B    SHR     BP,1
xxxx:519D    ADD     BP,DX
xxxx:519F    MOV     AX,DE00
xxxx:51A2    MOV     ES,AX
xxxx:51A4    MOV     DI,BP
xxxx:51A6    MOV     SI,04EE
xxxx:51A9    LODSW
xxxx:51AA    CMP     AH,07
xxxx:51AD    JNZ     51B1
xxxx:51AF    MOV     AH,0D
xxxx:51B1    MOV     ES:[1800],AH
xxxx:51B6    STOSB
xxxx:51B7    LOOP    51A9
xxxx:51B9    MOV     B,ES:[1800],0F
xxxx:51BF    NOP
xxxx:51C0    RET
-w
-q
A>

You will now have a TI Pro version.  When you run this program on a
TI Pro on which you have installed EMULATE.COM, you will now be able
to use Turbo Pascal.

Hope this information increases your computing pleasure.

Regards,
Larry
-- 
------------------------------------------------------------------------------
BRITANNUS (shocked): Caesar, this is not proper.
THEODOTUS (outraged): How?
CAESAR (recovering his self-possession):
  Pardon him Theodotus: he is a barbarian, and thinks that
  the customs of his tribe and island are the laws of nature.
(_Caesar and Cleopatra_, Act II - G. B. Shaw)

Larry A. Shurr (osu-eddie!apr!las || 137c South Towne Ln; Delaware, OH 43015)