; this is a resident printer utility to ; convert Toshiba 1340 hi-res graphics to DMP-2100 graphics ; ; 6-12-1986 by Clarence Wilkerson ; ROM BIOS calls prtint equ 17h newprtint equ 88h ; DOS calls TSR equ 27h ; terminate but stay resident by int 27h ; set dx to last address to be saved ; int 21h calls DOS equ 21h prtstrng equ 9h setint equ 25h getint equ 35h ; general equates cr equ 0dh lf equ 0ah ESC equ 27 code segment para assume cs:code, es:code, ds:code, ss:nothing org 100h ; done as a .COM program gothere proc far ; has to start at 100h. jump to disposable routines jmp putinplace gothere endp useold17h proc near ; do I need to restore flags? no ... int newprtint iret useold17h endp newprt proc far ; print char in al to printer dx ; return error codes in ah cmp dx,cs:printer ; is it the right printer? jnz useold17h or ah,ah ; only trap print routine, ah=0 jnz useold17h ; gofurther ; not a trivial case, so ; save all registers except a: assume stack is large enough push bx push cx push ds push dx push es push di push si pushf ; save al, since ax is frequently used mov cs:newchar,al ; know that ah is 0, or wouldn't be here ; get current state, and jump to particular routine mov ax,cs:currentstate mov cx,ax ; for future use cmp ax,6 ; check for out of range jae undefined ; may have offset problem ; skip out from here to test by passing through ; prepare for action mov bx,offset cs:messall ; set string address mov al,cs:newchar ; get back char cmp al,ESC ; esc jz isescape ; if escape, dump buffer, restart state at 1 ; ; special case for last char ; xchg bx,cx cmp al,byte ptr cs:messall[bx] ; on track so far??? xchg bx,cx jnz flush ; did not match, so dump it ; so does match the char needed. bump the state cmp cx,5 ; on the last leg? jz lastbyte ; still matching, but not done, so increment state of machine inc cs:currentstate jmp tidyup lastbyte: ; have match ESC;0000, so don't send it out. mov cs:currentstate,0 ; reset machine state mov ah,01010000B ; in case don't send anything, set the right jmp tidyup ; error return back in ah newprt endp undefined proc near mov cs:currentstate,0 ; reset machine state mov al,cs:newchar ; send out char call printone jmp tidyup undefined endp isescape proc near ; print buffer[0..cx-1] mov cs:currentstate,1 ; escape buffer started ; cx has old state or cl,ch ; if no current buffer, don't try to send it ; if in state 0 then nothing to send out jnz overes mov ah,01010000B ; but do send right flags back jmp tidyup overes:call printstring ; print cx chars from string jmp tidyup ; no newchar, since we know it is ESC isescape endp flush proc near ; have already loaded cx and dx ; will print old [buffer[0..cx-1] + new char mov cs:currentstate,0 or cl,ch ; zero chars case jnz overf ; in case no chars call printstring overf: mov al,cs:newchar ; so flush and print newchar call printone ; will have error code in ah jmp short tidyup flush endp tidyup proc near mov al,cs:newchar ; ah has error return from an popf pop si pop di pop es ; honest int 17h call, or one of the pop dx pop ds ; buffered fake ones above pop cx pop bx iret tidyup endp printone proc near ; send al to lpt1 via new interrupt newprtint push bx push cx mov ah,0 mov dx,cs:printer int newprtint pop cx pop bx ret ; don't save ax, because want error flags in ah printone endp printstring proc near ; print null terminated string pointed to by cs:bx ; up to cx chars long push bx push cx xor bx,bx sloop: or cl,ch jz sfinish mov al,cs:messall[bx] or al,al jz sfinish inc bx dec cx ; call printone jmp sloop sfinish: pop cx pop bx ret printstring endp procedure ascii2bin ; take 10*ascii and add al to it ; put back in ascii push ax push dx ; overflow may go into dx and al,0fh ; assume ascii '0...9' cbw mov cs:temp,ax mov ax,ascii mul 10 add ax,temp mov ascii,ax pop dx pop ax ret ascii2bin endp procedure convert4to3 ; convert 4 six bit bytes to 3 eight bit bytes ; new[1]:= old[1] shl 2 +( old[2] and 00110000b) shr 4; ; new[2]:= (old[2] and 00001111b) shl 4 + (old[3] and 00111100b) shr 2; ; new[3]:= old[4] + ( old[3] and 3) shl 6 ; push ax push cx mov al,old[1] add al add al mov new[1],al mov al,old[2] and al,00110000b mov cl,4 shr al,cl add new[1],al mov al,old[2] and al,00001111b mov cl,4 shl al,cl mov new[2],al mov al,old[3] and al,00111100b mov cl,2 shr al,cl add new[2],al mov al,old[3] and al,3 mov cl,6 shl al,cl add al,old[4] mov new[3],al pop cx pop ax ret convert4to2 endp temp dw 0 ascii dw 0 oldbar db 4 dup(0); holding for old vertical data newbar db 3 dup(0); holding for new vertical data newchar db 0 printer dw 0 ; possible values 0,1,2 for now currentstate dw 0 ; possible states are 0,1,2,3,4,5 grafon db ESC,';',0 old17h dd 0 db 10 dup('END'); ; data for a line howmany dw 0 linebuffer db 7800 dup(0) ;;;; below this point is thrown away after initialization thatsall label byte ; throw away the signon message ; and initialization code putinplace proc near ; part executed as DOS program mov ax,cs mov ds,ax ; set segment addresses mov es,ax ; check the command line for any arguments mov al, byte ptr cs:[80h] or al,al jz setzero ; printer 0 xor bx,bx mov bl,al mov al, cs:[bx+128] ; get the last char on line cmp al,'2' jz settwo cmp al,'3' jz setthree setzero: mov cs:printer,0; mov cs:which,31h jmp over settwo: mov cs:printer,1 mov cs:which,32h jmp over setthree: mov cs:printer,2 mov cs:which,33h jmp over over: mov dx, offset greeting mov ah,prtstrng int DOS ; print the string ; get the old 17h interrupt mov al,prtint ; get printer interrupt mov ah,getint int DOS ; set trap for 17h calls mov ax,es mov word ptr old17h[2],ax mov word ptr old17h,bx mov al,prtint push cs pop ds mov dx,offset newprt mov ah, setint int dos ; set up int newprtint as same as 17h was lds dx,dword ptr old17h mov al,newprtint mov ah,setint int DOS ; mov cs:currentstate,0 mov cs:newchar,0 ; mov dx, offset thatsall int TSR ; back to dos, but keep program around putinplace endp greeting db cr,lf,'Installing T1340 graphics trap on INT 17H.' db cr,lf db 'Converts to DMP-2100 graphics.' db cr,lf db 'Uses INT 88h also. Affects only LPT' which db '1' db ' output.' db cr,lf,'Usage is ' db cr,lf,' C> TOS2DMP X' db cr,lf,'where X is 1,2, or 3 for LPTX trapping.' db cr,lf,'$' code ends end gothere; jmp then to putinplace