; SID2TTY.ASM v 1.0 10/10/84 B. Mitchell (Plu*Perfect Systems) ; ; SID/ZSID/DDT Console Redirection Patch ; ;SID2TTY is a small, public-domain program that ;dynamically patches the SID debugger (Data Resources, Inc.) to ;redirect all of SID's console input and output to the logical TTY: ;device. (ZSID2TTY and DDT2TTY are the ZSID and DDT versions.) ; ;By using a second terminal as the TTY: device to "command" SID, ;one can debug programs without interfering with standard console ;input and output. Thus, (assuming the usual CON:=CRT: ;assignment) a program's standard output will appear on the video ;monitor exactly as if the debugger were not in use, and program ;input will be entered on the standard keyboard. ; ;The patch itself is just 23 bytes -- it changes the IOBYTE each time ;SID calls for bdos console i/o service and restores it afterwards. ;The patch is relocated to protected high memory, below SID (and ;below any .SYM and .UTL files, which should be loaded first). ; ;Source file: SID2TTY.ASM for assembly with ASM or MAC. ; The ZSID and DDT versions are obtained by ; changing three equates. ; ;Requirements: CP/M 2.2 - 3.0 with IOBYTE implemented in bios. ; 8080, 8085 or Z80 CPU. ; SID v. 1.4 or ZSID v. 1.4 or DDT v2.2. ; External terminal connected to TTY: ; ;Installation: Set the equates for SID, ZSID or DDT. ; If your TTY: device needs initialization or ; de-initialization, insert the code in place ; of dummy routines. ; ;Bugs: Exiting from SID with ^C leaves the console ; redirected to TTY: (unless the BIOS improperly ; restores the IOBYTE on warmboots). The ; recommended fix is simply to exit with a "G0". ; Should you happen to hit ^C, reload SID and reset ; the IOBYTE to its original value, then exit with ; ^C from the CRT terminal. ; ;Remarks: 1. Although it would be possible to trap the ; warmboot and restore the IOBYTE, it's difficult to ; do correctly. Trapping 0001h violates the basic CP/M ; addressing convention, making it impossible to ; run other resident modules that need to locate the BIOS ; and BDOS. Trapping the warmboot at the BIOS jump ; vector does preserve addressing, but it still requires ; special efforts to maintain compatibility with any higher ; resident modules, and the trap must remove itself ; without disturbing them. Since the application here ; is manual, interactive debugging, it seems best to ; favor compatibility and do a manual restoration. ; ; 2. The assembler portion of SID/ZSID can be removed ; with the "-A" command to gain 680h bytes, but ; this must be done BEFORE loading SID2TTY. ; ;Version: 1.0 -- 10 October 1984 B. Mitchell ; ;Revisions: Please forward any revisions and improvements ; to the author. ; ;Author: Bridger Mitchell ; Plu*Perfect Systems ; Box 1494, Idyllwild CA 92349 ; (714) 659-4432 ; ;Note: Not tested on CP/M 3.0. ; ; VERS equ 1$0 ; FALSE equ 0 TRUE equ NOT FALSE ; ; exactly ONE of the next 3 equates must be TRUE -- SID equ TRUE ZSID equ FALSE DDT equ FALSE ; CR equ 0dh LF equ 0ah BELL equ 07h ; IOBYTE equ 0003h BDOS equ 0005h ; org 100h START: jmp help jmp install jmp deinittty ; signature:db 'NEXT PC' ;common SID/ZSID/DDT code siglen equ $-signature IF SID ; modsiz equ 1800h ;size of debugger module sigad equ 0E42h ;offset to signature callbd equ 06A4H ;offset to call_bdos routine fn2ad equ 1004h ;offset to addr of function 2 bdos call fn10ad equ 0FF2H ; ditto fn 10 fn11ad equ 1065h ; ditto fn 11 ; usage: db CR,LF,'SID2TTY v. ' db vers/10+'0','.',(vers mod 10)+'0' db ' -- Redirect SID console i/o to TTY:',CR,LF db ' -- Usage --',CR,LF db 'Load SID, then .SYM and .UTL files',CR,LF db ' #I* filename.SYM',CR,LF db ' #R',CR,LF db ' #ISID2TTY.COM',CR,LF db ' #R',CR,LF db ' #G103 ==>> SID''s console is now TTY:',CR,LF db ' #Ifilename.COM (or .HEX) to debug',CR,LF db ' #R',CR,LF db ' #D3 ==>>display IOBYTE for reference',CR,LF,LF db 'Use ''G0'', not ''^C'' to exit from SID.',CR,LF db 'If needed, first de-initialize the TTY: by',CR,LF db ' #G106',CR,LF db '(This message can be displayed under SID by the command:' db CR,LF,' G100 or C100 before loading ''filename'')' db CR,LF,LF,'$' ; errmsg: db CR,LF,BELL,'Can''t find SID v 1.4!$' ENDIF ;IF SID IF ZSID ; modsiz equ 2200h sigad equ 1682h callbd equ 0EAFH fn2ad equ 1880h fn10ad equ 186Eh fn11ad equ 18E1h ; usage: db CR,LF,LF,'ZSID2TTY v. ' db vers/10+'0','.',(vers mod 10)+'0' db ' -- Redirect ZSID console i/o to TTY:',CR,LF,LF db ' -- Usage --',CR,LF db 'Load ZSID, then .SYM and .UTL files',CR,LF db ' #I* filename.SYM',CR,LF db ' #R',CR,LF db ' #IZSID2TTY.COM',CR,LF db ' #R',CR,LF db ' #G103 ==>> ZSID''s console is now TTY:',CR,LF db ' #Ifilename.COM (or .HEX) to debug',CR,LF db ' #R',CR,LF db ' #D3 ==>>display IOBYTE for reference',CR,LF,LF db 'Use ''G0'', not ''^C'' to exit from ZSID.',CR,LF db 'If needed, first de-initialize the TTY: by',CR,LF db ' #G106',CR,LF db '(This message can be displayed under ZSID by the command:' db CR,LF,' G100 or C100 before loading ''filename'')' db CR,LF,LF,'$' ; errmsg: db CR,LF,BELL,'Can''t find ZSID v 1.4!$' ENDIF ;IF ZSID IF DDT ; modsiz equ 1000h sigad equ 0A71h callbd equ 06A2h fn2ad equ 0BCEh fn10ad equ 0C25h fn11ad equ 0BBCh ; usage: db CR,LF,LF,'DDT2TTY v. ' db vers/10+'0','.',(vers mod 10)+'0' db ' -- Redirect DDT console i/o to TTY:',CR,LF,LF db ' -- Usage --',CR,LF db 'A>DDT DDT2TTY.COM',CR,LF db ' *G103 ==>> DDT''s console is now TTY:',CR,LF db ' *Ifilename.COM (or .HEX) to debug',CR,LF db ' *R',CR,LF db ' *D3 ==>>display IOBYTE for reference',CR,LF,LF db 'Use ''G0'', not ''^C'' to exit from DDT.',CR,LF db 'If needed, first de-initialize the TTY: by',CR,LF db ' #G106',CR,LF db '(This message can be displayed under DDT by the command:' db CR,LF,' G100 before loading ''filename'')' db CR,LF,LF,'$' ; errmsg:db CR,LF,BELL,'Can''t find DDT v 2.2!$' ENDIF ;IF DDT ; ; ; Display usage message & quit ; This is executed if SID2TTY is run as a .COM file ; It can also be C'd or G'd from the debugger. ; HELP: lxi d,usage print: mvi c,9 call bdos lxi h,0 ;is debugger in use on default stack? dad sp mov a,h cpi 2 rnc ;return to caller (ccp) rst 7 ;return to debugger ; ERR: lxi d,errmsg jmp print ; ; INSTALL: ; ;Search for SID signature in high memory. ; Search downward to find first image of the debugger, ; in case other copies are lying around. This also ; allows other resident modules to exist above the ; debugger. Debugger is always located on a page boundary. ; lhld 1 lxi d,-(modsiz+3) dad d ;start at max possible addr search: push h ; in case cp/m 3.0 lxi d,sigad dad d call compar pop h jz found mov a,h cpi 10h ;quit looking at 1000h jc err dcr h ;try 1 page lower jmp search ; compar: lxi d,signature mvi b,siglen complp: ldax d cmp m rnz inx h inx d dcr b jnz complp ret ; ; Debugger located. Calculate run-time addresses & patch ; into code and debugger. ; found: push h ; save base addr of sid lxi d,callbd ;put run-time addresses into code dad d xchg lxi h,pat3 ; the call_bdos routine address mov m,e inx h mov m,d lhld 6 ;the protect address/base of high code lxi d,-codelen dad d shld protad push h ;save run-time base of high code lxi d,saviob-code dad d shld pat1 lhld 6 shld pat2 pop d ;get destination push d lxi h,code ;move the code up mvi b,codelen lp: mov a,m stax d inx h inx d dcr b jnz lp pop b ;patch sid's console io calls inx b inx b inx b ; ..to point at code entry ('divert') lxi h,fn10ad ;index into sid module pop d ;de = base of sid dad d mov m,c ;plug diversion address into call inx h mov m,b lxi h,fn2ad dad d mov m,c inx h mov m,b lxi h,fn11ad dad d mov m,c inx h mov m,b protad equ $+1 lxi h,$-$ ;protect the redirection code shld 6 call INITTTY ;do any user-supplied initialization rst 7 ;return to sid on TTY: device ; ; ; The REDIRECTION CODE, which is moved up just below SID ; pat2 equ $+1 CODE: jmp $-$ ;jmp to sid entry divert: lxi h,iobyte mov a,m pat1 equ $+1 sta $-$ ;save the iobyte ani 0fch ; assign CON: to TTY: for sid mov m,a pat3 equ $+1 call $-$ ;sid's call_bdos routine saviob equ $+1 retadd: mvi a,$-$ ;restore user's iobyte sta iobyte mov a,l ;get bdos return param back to A ret codelen equ $-code ; ; User-supplied TTY: initialization routine. ; Use this to set baud rate, channel parameters, etc. ; INITTTY: ret ; ; User-supplied TTY: de-initialization routine. ; Use this to restore TTY: device to regular settings. ; DEINITTTY: ret END