title HERC - hercules daisywheel typewriter
;
; a printer driver for the daisy wheel typewriters
;
;     Prsident electronic 6005i
;     Hercules electronic portable
;     Erika electronic portable
;     Privileg electronic 2300
;     Sigma SM 8500i
;
; written by:
;     E. Lenz
;     Johann-Fichte-Strasse 11
;     8 Munich 40
;     Germany
;
CODE       SEGMENT PARA PUBLIC 'CODE'
           ASSUME cs:CODE, ds:CODE

           org  100h
start:     jmp  init_int17

int17_new: jmp  short int
under      db   0
int:       cmp  ah,0
           jne  bios_call      ;not a printer write
           push bx
           push ds
           push cs             ;get the right segment
           pop  ds

           cmp  al,'<'         ;test for begin of underline
           jne  nostart
           mov  under,1
           jmp  short no_go
nostart:   cmp  al,'>'         ;test for end of underline
           jne  noend
           mov  under,0
           jmp  short no_go
noend:     lea  bx,print_table ;translate the code to hercules
           xlat print_table
           cmp  al,2           ;test for the dead key ^
           jne  nodead
           int  60h
           mov  ax,20h
nodead:    cmp  al,60h         ;test for the dead key `
           jne  wodead
           int  60h
           mov  ax,20h
wodead:    cmp  under,0
           je   to_bios
           int  60h            ;print the thing
           mov  ax,7fh         ;backspace
           int  60h
           mov  ax,'_'         ;underline
to_bios:   pop  ds
           pop  bx
bios_call: int  60h
           iret
no_go:     pop  ds
           pop  bx
           iret

;
; conversion table for hercules
;
print_table label byte
           db 0     ;0
           db 0     ;1
           db 0     ;2
           db 0     ;3
           db 0     ;4
           db 0     ;5
           db 0     ;6
           db 0     ;7
           db 0     ;8
           db 0     ;9
           db 0ah   ;line feed
           db 0     ;bh
           db 0     ;ch
           db 0dh   ;carriage return
           db 0     ;eh
           db 0     ;fh
           db 0     ;10h
           db 0     ;11h
           db 0     ;12h
           db 0     ;13h
           db 0     ;14h
           db 40h   ;Paragraph
           db 0     ;16h
           db 0     ;17h
           db 0     ;18h
           db 0     ;19h
           db 0     ;1ah
           db 0     ;1bh
           db 0     ;1ch
           db 0     ;1dh
           db 0     ;1eh
           db 0     ;1fh
           db ' '
           db '!'
           db '"'
           db '#'
           db '$'
           db '%'
           db '&'
           db 27h   ;'
           db '('
           db ')'
           db '*'
           db '+'
           db ','
           db '-'
           db '.'
           db '/'
           db '0'
           db '1'
           db '2'
           db '3'
           db '4'
           db '5'
           db '6'
           db '7'
           db '8'
           db '9'
           db ':'
           db ';'
           db 0     ;3ch
           db '='
           db 0     ;3eh
           db '?'
           db 0     ;40h
           db 'A'
           db 'B'
           db 'C'
           db 'D'
           db 'E'
           db 'F'
           db 'G'
           db 'H'
           db 'I'
           db 'J'
           db 'K'
           db 'L'
           db 'M'
           db 'N'
           db 'O'
           db 'P'
           db 'Q'
           db 'R'
           db 'S'
           db 'T'
           db 'U'
           db 'V'
           db 'W'
           db 'X'
           db 'Y'
           db 'Z'
           db 0     ;5bh
           db 0     ;5ch
           db 0     ;5dh
           db 2     ;^
           db '_'
           db 60h   ;`
           db 'a'
           db 'b'
           db 'c'
           db 'd'
           db 'e'
           db 'f'
           db 'g'
           db 'h'
           db 'i'
           db 'j'
           db 'k'
           db 'l'
           db 'm'
           db 'n'
           db 'o'
           db 'p'
           db 'q'
           db 'r'
           db 's'
           db 't'
           db 'u'
           db 'v'
           db 'w'
           db 'x'
           db 'y'
           db 'z'
           db 0     ;7bh
           db 11h   ;|
           db 0     ;7dh
           db 0     ;7eh
           db 0     ;7fh
           db 0     ;80h
           db 7dh   ;
           db 13h   ;
           db 0     ;83h
           db 7bh   ;
           db 0     ;85h
           db 0     ;86h
           db 12h   ;
           db 0     ;88h
           db 0     ;89h
           db 3     ;
           db 0     ;8bh
           db 0     ;8ch
           db 0     ;8dh
           db 5bh   ;
           db 0     ;8fh
           db 0     ;90h
           db 0     ;91h
           db 0     ;92h
           db 0     ;93h
           db 7ch   ;
           db 0     ;95h
           db 0     ;96h
           db 0     ;97h
           db 0     ;98h
           db 5ch   ;
           db 5dh   ;
           db 0     ;9bh
           db 10h   ;
           db 0     ;9dh
           db 0     ;9eh
           db 0     ;9fh
           db 0     ;a0h
           db 0     ;a1h
           db 0     ;a2h
           db 0     ;a3h
           db 0     ;a4h
           db 0     ;a5h
           db 0     ;a6h
           db 0     ;a7h
           db 0     ;a8h
           db 0     ;a9h
           db 0     ;aah
           db 0     ;abh
           db 0     ;ach
           db 0     ;adh
           db 0     ;aeh
           db 0     ;afh
           db 0     ;b0h
           db 0     ;b1h
           db 0     ;b2h
           db 0     ;b3h
           db 0     ;b4h
           db 0     ;b5h
           db 0     ;b6h
           db 0     ;b7h
           db 0     ;b8h
           db 0     ;b9h
           db 0     ;bah
           db 0     ;bbh
           db 0     ;bch
           db 0     ;bdh
           db 0     ;beh
           db 0     ;bfh
           db 0     ;c0h
           db 0     ;c1h
           db 0     ;c2h
           db 0     ;c3h
           db 0     ;c4h
           db 0     ;c5h
           db 0     ;c6h
           db 0     ;c7h
           db 0     ;c8h
           db 0     ;c9h
           db 0     ;cah
           db 0     ;cbh
           db 0     ;cch
           db 0     ;cdh
           db 0     ;ceh
           db 0     ;cfh
           db 0     ;d0h
           db 0     ;d1h
           db 0     ;d2h
           db 0     ;d3h
           db 0     ;d4h
           db 0     ;d5h
           db 0     ;d6h
           db 0     ;d7h
           db 0     ;d8h
           db 0     ;d9h
           db 0     ;dah
           db 0     ;dbh
           db 0     ;dch
           db 0     ;ddh
           db 0     ;deh
           db 0     ;dfh
           db 0     ;e0h
           db 7eh   ;
           db 0     ;e2h
           db 0     ;e3h
           db 0     ;e4h
           db 0     ;e5h
           db 14h   ;
           db 0     ;e7h
           db 0     ;e8h
           db 0     ;e9h
           db 0     ;eah
           db 0     ;ebh
           db 0     ;ech
           db 0     ;edh
           db 0     ;eeh
           db 0     ;efh
           db 0     ;f0h
           db 0     ;f1h
           db 0     ;f2h
           db 0     ;f3h
           db 0     ;f4h
           db 0     ;f5h
           db 0     ;f6h
           db 0     ;f7h
           db 5eh   ;
           db 0     ;f9h
           db 0     ;fah
           db 0     ;fbh
           db 0     ;fch
           db 16h   ;
           db 0     ;feh
           db 0     ;ffh
end_int17_new:

;
; check if interrupt 60 is zero
;

init_int17: mov  ah,53
           mov  al,60h
           int  21h
           push es
           pop  dx
           cmp  dx,0
           jnz  error
           cmp  bx,0
           jnz  error

;
; set interrupt 17 to interrupt 60
;

           mov  ah,53
           mov  al,17h
           int  21h
           push es
           pop  ds
           mov  dx,bx
           mov  ah,37
           mov  al,60h
           int  21h

;
; set new interrupt 17 address
;
           mov  ah,37
           mov  al,17h
           lea  dx,int17_new
           push cs
           pop  ds
           int  21h

           lea  dx,say
           mov  ah,9           ;write string
           int  21h

           lea  dx,end_int17_new ;terminate but stay resident
           int  27h

error:     lea  dx,err
           mov  ah,9           ;write string
           int  21h

           mov  ah,4ch         ;return to DOS
           int  21h

say        db 0ah,0dh
           db 'Hercules interrupt routine int 17 installed'
           db 0ah,0ah,0dh
           db 'Vector 60h may not be changed'
           db 0d,0d,'$'

err        db 0ah,0dh
           db 'cannot install Hercules interrupt routine int 17'
           db 0d,0d,'$'

CODE       ENDS
           END start
