Skip to content

Instantly share code, notes, and snippets.

@ashdnazg
Created January 20, 2026 12:56
Show Gist options
  • Select an option

  • Save ashdnazg/ce73d2618eeaf068f57ac1bc60889de7 to your computer and use it in GitHub Desktop.

Select an option

Save ashdnazg/ce73d2618eeaf068f57ac1bc60889de7 to your computer and use it in GitHub Desktop.
Patch for Turbo Pascal 3.01a enabling CLI execution
# Patch for Turbo Pascal 3.01a as disassembled by https://www.pcengines.ch/tp3.htm
# to enable command line execution.
diff --git a/TPSRC b/TPSRC
index 344ef4a..2161173 100644
--- a/TPSRC
+++ b/TPSRC
@@ -5785,7 +5785,8 @@ chain1 POP errpos ;get ret addr
MOV SP,spval ;restore SP
CALL reinit2 ;reinit files, I/O
MOV verror,#$10D0 ;set break vector
- JMP start2 ;'start - no memory init
+ ; Fix opcode to fit borland exactly
+ B $E9,$22,$00 ;JMP start2 ;'start - no memory init
cherr1 MOV DL,#$01 ;File not found
JMP operr ;'
cherr2 MOV.B errnum,#$21 ;Not allowed in direct mode
@@ -5828,7 +5829,38 @@ kmeminit MOV SS,stackseg ;set stack segment
MOV SP,stackpt ;set stack pointer
PUSH AX ;save flag
MOV CX,#$0010 ;16 files
- CALL initio ;init files, I/O
+ ;CALL initio ;init files, I/O
+; The above call is inlined below, but without the time measuring
+ MOV DI,#filetab ;set pt to file tab
+ MOV filtabpt,DI
+ MOV filemax,CX ;CX=max number of open files
+ XOR AX,AX ;clear file list
+ PUSH DS ;DS -> ES
+ POP ES
+ CLD
+ REPZ
+ STOS
+ MOV ES,AX ;segment 0:
+ ES:
+ MOV verrhnd,#errhndl ;set vector:
+ ES: ;error handler
+ MOV verrhnd1,CS
+; inlined from msspeed
+ CS: ;measurement value
+ ; the followig was changed from setting not done, to done
+ MOV.B measdone,#$FF ;flag: done
+ MOV SI,#timvec ;ptr to timer INT
+ ES:
+ MOV AX,[SI]
+ CS:
+ MOV vtimer,AX ;save it
+ ES:
+ MOV AX,[SI]$02
+ CS:
+ MOV vtimer1,AX
+; delegate to reinit1
+ CALL reinit1
+; end of inlined initio
POP AX ;get flag
OR AX,AX ;test it
PUSH AX ;save it again
@@ -5857,37 +5889,45 @@ kinitvar MOV AX,#txstrt ;init vars
MOV AH,#$19 ;get default drive
CALL dos
MOV defdrv,AL ;store it
- CALL xclrscr ;ClrScr
- CALL prints ;write string
- B "---------------------------------------",$0D
- B $0A,"TURBO Pascal system ",$00
- CALL klowvid ;do LowVideo
- CALL prints ;write string
- B "Version 3.01A",$00
- CALL knrmvid ;do HighVideo
- CALL prints ;write string
- B $0D,$0A," ",$00
- CALL klowvid
- CALL prints
- B "PC-DOS",$00
- CALL knrmvid
- CALL prints
- B $0D,$0A,$0A,$00
- CALL klowvid
- CALL prints
- B "Copyright (C) 1983,84,85",$00
- CALL knrmvid
- CALL prints
- B " BORLAND Inc.",$0D,$0A,"-----------------------"
- B "----------------",$0D,$0A,$0A,$00
- MOV BX,#displstr ;write display type
- CALL putstr
- CALL prints
- B $0D,$0A,$0A,$0A,$0A,"Include error messages",$00
- CALL yornln ;Y or N ?
- MOV msgflg,AL ;store flag
- JZ kclr ;:no
- CALL kreaderr ;read error messages
+ MOV msgflg,#$00 ;store flag
+ MOV.B cpmode,#$02 ; compile to COM file
+ MOV.B codedest,#$02 ; compile to COM file
+copycmdargs PUSH AX
+ PUSH DS ; DS -> ES
+ POP ES
+ PUSH CS ; CS -> DS
+ POP DS
+
+ XOR CX,CX ;clear
+ MOV CL,[$80] ; CLI length
+ CMP CL,#$01
+ JLE retcopycmdargs
+
+ MOV SI,#$82 ; source ptr
+ MOV DI,#workpn ; dest ptr
+copyarg1
+ LODS.B ; get char
+ CMP AL,#$20 ; space ?
+ JLE copyend1 ; break on space or less
+ STOS.B ; copy it
+ LOOP copyarg1 ; next char
+copyend1
+ XOR AL,AL ; terminator
+ STOS.B ; store it
+
+ PUSH ES ; ES -> DS
+ POP DS
+
+ CALL kw2 ; load work file
+ CALL kcomp ; compile?
+
+retcopycmdargs
+ MOV AX,#$004C ;end of process
+ INT $21
+ B "bufferbufferbufferbufferbufferbufferbufferbufferbufferbuffer"
+ B "bufferbufferbufferbufferbufferbufferbufferbufferbufferbuffer"
+ B "bufferbufferbufferbufferbufferbufferbufferbufferbufferbuffer"
+ B "buffer"
kclr CALL kclrtxt ;clear text
CALL kmenu ;write menu
kmainlp MOV SP,stackpt ;main loop: restore SP
@@ -6654,7 +6694,8 @@ kcerror CALL vidattr3 ;Error message
XOR AX,AX ;get error number
MOV AL,cperr
CALL knum1 ;write it
- TEST.B msgflg,#$FF ;error msgs included ?
+ JMP retcopycmdargs
+ B "bb"
JZ kcwend ;:no
MOV BX,#txstrt ;pointer to messages
kcmsr MOV.B AL,[BX] ;get char
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment