home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / utils / easyun.zip / DE-JET2.ASM < prev    next >
Assembly Source File  |  1986-10-23  |  49KB  |  980 lines

  1.                 page 50,132
  2. ;*******************************************************************************
  3. ;                              Program DE-JET
  4. ;
  5. ;                               version 2.00
  6. ;
  7. ; Brought to you by the friends of George P. Burdell , Georgia Tech. 10/22/86
  8. ;
  9. ; Function: Read 'Jet' program from protected disk, put in 'exe' file format
  10. ;           with several extensions including exit to dos and inclusion of
  11. ;           extra options sectors while maintaining the ability to load a
  12. ;           scenery disk and accept command line parameters.
  13. ;
  14. ;           All terminates are type 4ch with errorlevel = 2 (hard error) while
  15. ;           clean exit is errorlevel = 0 and CTRL-C is errorlevel = 1
  16. ;
  17. ;           All calls are Dos type except int 13h (bios disk access) and
  18. ;           int 11h (bios installed equipment).
  19. ;
  20. ;           This version of De-Jet fixes DMA boundary error over ver 1.00 and
  21. ;           retry on loading of extended situations sectors over ver 1.00 also.
  22. ;
  23. ;           This version (v 2.00) fixes an print string error which occurs when
  24. ;           'error_3' is to be printed. It also happens to do JET v1.3 now.
  25. ;           The loader checksum will distinguish between the two versions and
  26. ;           will set the version flag to signal the proper changes for the
  27. ;           'mod_jet' procedure to make. The major changes were relocation of
  28. ;           the stack from 1dee to 0090. Change of address of the print
  29. ;           graphic string subroutine. Change of the load address of the extra
  30. ;           situations sectors.
  31. ;
  32. ;           This program should assemble on MASM 4.0 with no errors. Empty
  33. ;           segment warning error may occur on other assemblers however this is
  34. ;           a warning and is inconsequential.
  35. ;
  36. ;*******************************************************************************
  37. ;
  38. ;
  39. ;
  40. stackseg  segment  para  stack  'stack'
  41. ;
  42.           db  32 dup('STACK   ')        ;reserve 100h bytes for the stack
  43. ;
  44. stack_top  label  word                  ;top of stack = stack_top
  45. stackseg  ends
  46. ;
  47. ;
  48. ;
  49. dataseg   segment  para  public  'data'
  50.  
  51.  
  52. ;EQUATES follow
  53.  
  54. chk_sum_10 equ  0ad62h                  ;loader checksum for ver 1.0
  55. chk_sum_13 equ  07b84h                  ;loader checksum for ver 1.3
  56. copy_c_sum equ  05c72h                  ;copyright checksum
  57. cr         equ  0dh                     ;carriage return character
  58. lf         equ  0ah                     ;line feed character
  59. eom        equ  '$'                     ;print string terminator
  60. ;
  61.  
  62. ;MISC VARIABLES follow
  63.  
  64. sec_buff  db     400h dup(00h)          ;1K sector buffer at beginning of ds seg
  65. int_1e    dw     2 dup(0000h)           ;storage for proper int 1eh
  66. spec_case db     00h                    ;floppy flag, for De-Jet to single floppy sys.
  67. retry     db     05h                    ;retry counter
  68. seg       dw     0000h                  ;Jet construction segment
  69. version   db     00h                    ;version storage byte (10 or 13)
  70. ;
  71.  
  72. ;GENERAL MESSAGES follow
  73.  
  74. hello     db     'De-Jet v2.00',cr,lf,eom
  75. mesg_1    db     'Insert JET disk in drive A:, "JET.EXE" will be written to drive '
  76. prt_drive db     00h,cr,lf,eom
  77. strk_key  db     '...strike a key when ready or CTRL-C to stop.',cr,lf,lf,eom
  78. mesg_2    db     '...insert destination disk for JET.EXE in drive ',eom
  79. mesg_3    db     'Conversion complete.',cr,lf,eom
  80. ;
  81.  
  82. ;ERROR MESSAGES follow
  83.  
  84. error_1   db     '*** bios sector read failure - ABORT',cr,lf,eom
  85. error_2   db     '*** unidentified Jet loader version - ABORT',cr,lf,eom
  86. error_3   db     '*** unidentified Jet version, "OPCODE" not present - ABORT',cr,lf,eom
  87. error_4   db     '*** file write error.',cr,lf,eom
  88. error_5   db     '*** you forgot the drive specification.',cr,lf,eom
  89. error_6   db     '*** invalid drive specification.',cr,lf,eom
  90. error_7   db     '*** not enough space available on specified drive.',cr,lf,eom
  91. error_8   db     '*** sector buffer on DMA boundary - see instructions.',cr,lf,eom
  92. ;
  93.  
  94. ;MISC TABLES AND STRINGS follow
  95.  
  96. copyright db     'L|yqr~*~y*ây*lâ*,^ro*p|soxn}*yp*Qoy|qo*Z8*L|novv,6*Qoy|qsk*^omr*;:9<=9B@*.'
  97. copylen   equ    $-copyright
  98.  
  99.                  ;this parameter table is of non-dos format, used by the Jet loader
  100.  
  101. parmtable db     0cfh,02h,25h,03h,05h,2ah,0ffh,50h,83h,13h,04h,0c0h,50h,8bh,46h,0feh
  102.  
  103.                  ;standard link header
  104.  
  105. link_head  db    4dh,5ah,00,00,0a8h,00,00,00,20h,00,00,00,0ffh,0ffh,00,00
  106. link_stack db    0eeh,1dh
  107. link_len   equ   $-link_head
  108.  
  109.                  ;filename in ascii-z string format, leading zero is for drive spec.
  110.  
  111. writefile db     00h,':JET.EXE',00h
  112. ;
  113.  
  114. ;FIXUPS follow
  115.  
  116. ;  These fixups are for the version 1.0 of Jet and represent many hours of
  117. ;  debugging. Some of the code has been coded with the 'db' directive because
  118. ;  the assembler will not assemble these instructions outside the code segment.
  119. ;  All 'db' instructions have the asm equivalent in the trailing comment field.
  120. ;
  121. ;  The fixups are in the format 'FIXUP_??' where ?? represents the offset from
  122. ;  the first byte of Jet data past the link header. They were done like this
  123. ;  so that I could remember where they went in the original debugged binary
  124. ;  file.
  125. ;
  126. ;  An explanation of each fixup should precede the fixup and comments of the
  127. ;  fixup code are included.
  128.  
  129. fixup_00         label   byte             ;jump to our initialization code
  130.                  jmp  $+(347h)            ;at offset 347h in the current segment
  131. length_00    equ $-fixup_00
  132. ;
  133. ;FIXUP_347 contains all of our hooks out of this segment. Jet takes up almost
  134. ;          64K of data and I do not know how close it comes to the end of the
  135. ;          segment, so a new segment appended to the end of the Jet segment was
  136. ;          created to allow room for some of our code. I have determined that
  137. ;          location 347h has unwanted code and is over-written with our code
  138. ;          up to 3abh where their code is required again.
  139.  
  140. fixup_347        label  byte
  141.                  mov ax,cs                ;init. is at cs+10000 : offset 00h
  142.                  add ax,1000h             ;point to new segment (old + 64K), called post seg
  143.                  push ax                  ;push seg onto stack
  144.                  sub ax,ax                ;point ax to offset zero
  145.                  push ax                  ;push offset into post seg onto the stack
  146.              db  0cbh                     ;(retf) far return as the jump to seg : offset
  147. ;
  148. prt_calls        label  byte
  149.                  call $+(6e9ah-351h)      ;location 351h : call to prt graphics at 6e9ah
  150.                  mov si,35bh              ;point to string EXIT TO DOS
  151.                  call $+(6e9ah-357h)      ;location 357h : call to prt graphics at 6e9ah
  152.                  ret                      ;return back to their menu routine
  153. ;
  154. ;this is the 'EXIT TO DOS' string, screen position precedes it, terminates with a 00h
  155.  
  156. EXIT_string  db  2ah,1ch,'<6> EXIT TO DOS',00h  ;2a1c is position on screen
  157. ;
  158.                  cmp al,02h               ;test if select less than 1
  159.                  jl  $+(385h-36fh)        ;location 36fh : jl 385h if bad input char
  160.                  cmp al,07h               ;check if select 6 or greater
  161.                  jg  $+(385h-373h)        ;373 : jg 385 if bad input char
  162.                  jnz $+(382h-375h)        ;375 : jnz 382 if good but not exit dos
  163.                  mov ax,cs                ;prep do exit to DOS
  164.                  add ax,1000h             ;point to the post seg
  165.                  push ax                  ;push seg
  166.                  mov ax,40h               ;offset of our exit to dos routine in post seg
  167.                  push ax                  ;push the offset
  168.              db  0cbh                     ;(retf) far return to cs +10000 : offset 40h
  169.                  jmp $+(55ch-382h)        ;382 : jmp 55c do the selected option (their code)
  170.                  jmp $+(551h-385h)        ;385 : jmp 551 get another char code  (their code)
  171. ;
  172.                  mov ax,cs                ;prep mov in extended situation sects.
  173.                  add ax,1000h             ;point to post seg
  174.                  push ax                  ;push the seg
  175.                  mov ax,66h               ;point to ofset of our routine in post seg
  176.                  push ax                  ;push offset
  177.              db  0cbh                     ;(retf) far return to cs +10000 : offset 66h
  178.                  ret                      ;ret from calling load at 684h or 68ah where they called from
  179. ;
  180.                  mov ax,cs                ;prep mov in more extended situation sectors
  181.                  add ax,1000h             ;point to post seg
  182.                  push ax                  ;push the segment
  183.                  mov ax,8eh               ;point to offset of our code in post seg
  184.                  push ax                  ;push the offset
  185.              db  0cbh                     ;(retf) far return to cs +10000 : offset 8eh
  186.                  ret                      ;ret from calling load at 6b4h where they called from
  187. ;
  188.                  mov ax,cs                ;extra hook for future use
  189.                  add ax,1000h
  190.                  push ax
  191.                  mov ax,0b6h
  192.                  push ax
  193.              db  0cbh                     ;(retf) far return to cs +10000 : offset b6h
  194.  
  195.  
  196. length_347   equ $-fixup_347
  197.  
  198. option_calls     label  byte              ;replacement calls for version 1.3 moved in by mod_jet
  199.  
  200.                  call $+(6c86h-351h)      ;location 351h : call to prt graphics at 6e9ah
  201.                  mov si,35bh              ;point to string EXIT TO DOS
  202.                  call $+(6c86h-357h)      ;location 357h : call to prt graphics at 6e9ah
  203.                  ret                      ;return back to their menu routine
  204.  
  205. len_opt_calls equ $-option_calls
  206. ;
  207. ;
  208. ;
  209. ;POSTSEG contains all of the required code to perform the command line
  210. ;        parameter functions. It performs initialization functions which
  211. ;        currently consist of saving the first 20h interupt vectors. It's
  212. ;        easier to do this than selectively restore those which have been
  213. ;        destroyed as I am uncertain of which vectors will be destroyed.
  214. ;        However I do know that if you do a load scenery disk, the disk parm
  215. ;        pointer gets wiped out again so we need to catch that one.
  216. ;
  217. ;        Postseg has the 'exit to dos' code which puts back the old vector
  218. ;        table and does a clear screen reset to 80 column mode and dos
  219. ;        terminate function.
  220. ;
  221. ;        Postseg also has the two routines which copy in the required
  222. ;        extended situations sectors when called upon. There are two sections
  223. ;        for this purpose because there are two different sets of sectors
  224. ;        to be copied in place.
  225.  
  226. postseg      label  byte
  227.              db  80h,3eh,80h,00h,02h          ;(cmp byte ptr [80h],02) are there command line parameters ?
  228.                  jnz  $+(1bh-5h)              ;offset 5h : jnz to 1bh if no command line parms present
  229.              db  0a0h,82h,00h                 ;(mov al,[82h]) otherwise load parm letter into al
  230.                  and al,0f0h                  ;take high nibble
  231.                  cmp al,40h                   ;is it a capital letter
  232.                  jz  $+(15h-0eh)              ;ofset eh : jz 15h if already upper case
  233.              db  80h,2eh,82h,00h,20h          ;(sub byte ptr [82h],20h) otherwise subtract 20h to make upper case
  234.              db  0a0h,82h,00h                 ;(mov al,[82h]) put parm in al
  235.              db  0a2h,22h,08h                 ;(mov [822],al) put parm where jet looks for it
  236.                  sub ax,ax                    ;prep mov 20 int vectors at seg 0000h
  237.                  mov ds,ax                    ;load ds with source seg
  238.                  mov si,ax                    ;set source index to beginning of table
  239.                  mov di,1000h                 ;put at offset 1000h in post seg
  240.                  mov ax,cs                    ;set destination segment up
  241.                  mov es,ax
  242.                  mov cx,40h                   ;move 40h words, vectors 00h - 1fh
  243.                  cld                          ;increment through memory
  244.                  cli                          ;allow no maskable int's and pray for no NMI
  245.                  repz movsw                   ;move 'em out
  246.                  sti                          ;allow interrupts now
  247.                  mov ax,cs                    ;prepare to leave post seg
  248.                  sub ax,1000h                 ;point to Jet seg
  249.                  push ax                      ;push segment
  250.                  mov ds,ax                    ;reset ds and es segments
  251.                  mov es,ax
  252.                  mov ax,3abh                  ;return to cs - 10000h : offset 3abh
  253.                  push ax                      ;push offset of return
  254.              db  0cbh                         ;(retf) back to Jet
  255.                  nop                          ;why not take a breather ?
  256.                  sub ax,ax                    ;entry for exit to dos code
  257.                  mov es,ax                    ;point destination segment to low vector table
  258.                  mov di,ax                    ;point di to beginning of the table
  259.                  mov si,1000h                 ;point source to old saved table in post seg
  260.                  mov ax,cs                    ;prep restore 20 int's to low mem
  261.                  mov ds,ax                    ;point source segment to post seg
  262.                  mov cx,40h                   ;move 40h words, vectors 00h - 1fh
  263.                  cld                          ;increment through memory
  264.                  cli                          ;turn off maskable int's, pray for no MNI
  265.                  repz movsw                   ;move 'em back where they belong
  266.                  sti                          ;allow int's
  267.                  sub ax,1010h                 ;set es and ds segs to point to link header
  268.                  mov ds,ax                    ;set them both
  269.                  mov es,ax
  270.                  mov ax,03h                   ;restore video, clear screen and set 80x25 color
  271.                  int 10h                      ;call bios
  272.                  mov ax,4c00h                 ;terminate process function errorlevel = 0
  273.                  int 21h                      ;call to dos
  274. ;
  275.                  push ds                      ;entry for mov mem sectors e67-f67
  276.                  push es                      ;save the es and ds regs
  277.                  mov ax,cs                    ;point source seg to post seg
  278.                  mov ds,ax
  279.                  sub ax,1000h                 ;point es to Jet seg
  280.                  mov es,ax                    ;track E sec. 67-69,track F 65-67
  281.                  mov si,2000h                 ;sectors currently reside at offset 2000h in post seg
  282.                  mov di,0dfd7h                ;put them here in Jet seg unless version 1.3 then de6ah
  283. copy_pt_1  equ   $-2
  284.                  mov cx,0c00h                 ;6K bytes to move
  285.                  cld                          ;increment through memory
  286.                  cli
  287.                  repz movsw                   ;move' em out
  288.                  sti
  289.                  pop es                       ;restore old segments
  290.                  pop ds
  291.                  push ax                      ;push Jet segment
  292.                  mov ax,393h                  ;return here in the HOOKS code
  293.                  push ax                      ;push offset of return
  294.              db  0c6h,06h,0b1h,1bh,00h        ;(mov byte ptr [1bb1h],00h) for Jet, they do it so I will too
  295.                  sub ax,ax                    ;clear the ax for the hell of it
  296.              db  0cbh                         ;(retf) far return to cs -10000 : offset 393h
  297. ;
  298.                  mov ax,cs                    ;this is the other set of extra sectors to be moved
  299.                  push ds                      ;this is just like the above routine except for the
  300.                  push es                      ;offset where the sectors are found in the post seg
  301.                  mov ds,ax                    ;and the length to be moved, so you can figure it out
  302.                  sub ax,1000h                 ;on your own !
  303.                  mov es,ax                    ;track 10 sec. 65-69
  304.                  mov si,3800h                 ;sectors are currently 3800
  305.                  mov di,0dfd7h                ;put them here except for v1.3 will change to de6ah
  306. copy_pt_2  equ   $-2
  307.                  mov cx,0a00h                 ;5K bytes to move
  308.                  cld
  309.                  cli
  310.                  repz movsw                   ;move 'em out
  311.                  sti
  312.                  pop es
  313.                  pop ds
  314.                  push ax                      ;time to leave this place again
  315.                  mov ax,39fh
  316.                  push ax
  317.              db  0c6h,06h,0b1h,1bh,00h        ;(mov byte ptr [1bb1h],00h) for Jet
  318.                  sub ax,ax
  319.              db  0cbh                         ;(retf) far return to cs -10000 : offset 39fh
  320. length_post  equ $-postseg
  321. ;
  322. fixup_6f0d       label   byte
  323.                  jmp  $-(6f0dh-351h)          ;6f0d : jmp to 351 print exit to dos v1.3
  324. length_6f0d  equ $-fixup_6f0d
  325. ;
  326. fixup_712a       label   byte
  327.                  jmp  $-(712ah-351h)          ;712a : jmp to 351 print exit to dos v1.0
  328. length_712a  equ $-fixup_712a
  329. ;
  330. fixup_554        label   byte
  331.                  jmp  $-(554h-36dh)           ;554 : jmp to 36d to check selection
  332.                  nop                          ;nop out some old stuff
  333.                  nop
  334.                  nop
  335.                  nop
  336.                  nop
  337. length_554   equ $-fixup_554
  338. ;
  339. fixup_684        label   byte
  340.                  call  $-(684h-388h)          ;684 : call 388 load sectors
  341. length_684   equ $-fixup_684
  342. ;
  343. fixup_68a        label   byte
  344.                  call  $-(68ah-388h)          ;68a : call 388 load sectors
  345. length_68a   equ $-fixup_68a
  346. ;
  347. fixup_6b4        label   byte
  348.                  call  $-(6b4h-394h)          ;6b4 : call 394 load sectors
  349. length_6b4   equ $-fixup_6b4
  350. ;
  351.  
  352. dataseg   ends
  353. ;
  354. ;
  355. ;
  356. codeseg   segment  para  public  'code'
  357. ;
  358. begin           proc   far
  359.  
  360.            assume cs:codeseg,ds:dataseg,ss:stackseg,es:dataseg
  361.  
  362.                 push   ds                ;used by dos for return to dos
  363.                 sub    ax,ax             ;ds:0000h points to dos int 20
  364.                 push   ax                ;at PSP
  365. ;
  366.                 mov    ax,dataseg        ;iniatialize the ds segment
  367.                 mov    ds,ax             ;register for our program
  368. ;
  369.                 push   ax                ;save ds segment value for es later
  370.                 mov    bx,ax             ;test to see if sector buffer is on a DMA boundary
  371.                 add    bx,40h            ;add 1K, the size of the sector buffer, to the segment value
  372.                 and    bx,0f000h         ;mask all but top nibble
  373.                 and    ax,0f000h         ;same for ax
  374.  
  375.                 cmp    ax,bx             ;test upper nibble for change of seg
  376.                 jz     get_spec          ;if zero then not on 64K boundary, continue
  377.  
  378.                 pop    ax                ;save stack integrity by dumping old ax
  379.                 lea    dx,error_8        ;point to error message 8
  380.                 mov    ah,09h            ;dos function to print string
  381.                 int 21h                  ;call to dos
  382.  
  383.                 mov    ax,4c01h          ;function to terminate process with errorlevel = 2, 'hard error'
  384.                 int 21h                  ;call to dos
  385. ;
  386. get_spec:       pop    ax                ;restore segment relocatable value
  387.                 mov    bl,es:[80h]       ;get parm length
  388.                 cmp    bl,00h            ;if less than one then do error_5
  389.                 jg     parse             ;
  390.                 lea    dx,error_5        ;print error_5 and terminate
  391.                 mov    ah,09h            ;print string function
  392.                 int 21h                  ;call to dos
  393.                 ret                      ;terminate
  394. ;
  395. parse:          mov    cl,byte ptr es:[82h]          ;get drive spec from command line
  396.                 and    cl,0dfh                       ;force it to upper case
  397.                 mov    byte ptr ds:writefile,cl      ;put it at beginning of filename string
  398.                 sub    cx,cx                         ;clear the used registers
  399.                 mov    es,ax                         ;put proper value in es now
  400. ;
  401.                 lea    dx,hello          ;print the prog hello message
  402.                 mov    ah,09h            ;dos print string function
  403.                 int 21h                  ;call to dos
  404.                 lea    bx,copyright      ;decrypt the copyright
  405.                 mov    cx,copylen
  406.                 cld
  407. decrypt:        sub    byte ptr [bx],0ah
  408.                 inc    bx
  409.                 loop   decrypt
  410.                 lea    dx,copyright      ;print the copyright
  411.                 mov    ah,09h
  412.                 int 21h
  413.                 lea    bx,copyright      ;encrypt the copyright
  414.                 mov    cx,copylen
  415.                 cld
  416. encrypt:        add    byte ptr [bx],0ah
  417.                 inc    bx
  418.                 loop   encrypt           ;end copyright code
  419. ;
  420.                 mov    al,writefile      ;move drive spec to message string
  421.                 mov    prt_drive,al
  422. ;
  423.                 call   save_int_1e       ;save old disk parm table pointer
  424. ;
  425.                 call   test_drive        ;test for drive and drive space avail.
  426. ;
  427.                 mov    ah,09h            ;ask insert jet disk
  428.                 lea    dx,mesg_1         ;
  429.                 int 21h
  430.                 lea    dx,strk_key       ;ask strike a key
  431.                 mov    ah,09h            ;print string function
  432.                 int 21h                  ;call dos
  433.                 mov    ah,08h            ;wait for a key or ctrl-c break but do not echo
  434.                 int 21h                  ;call dos
  435. ;
  436.                 mov    cx,0165h          ;loader sector on Jet disk
  437.  
  438.                 call   new_int_1e        ;point to new parm table
  439. ;
  440.                 call   load_sector       ;load initial loader into the sector buffer in the ds
  441. ;
  442.                 call   check_sum         ;make sure the loader is the same as mine
  443. ;
  444.                 call   set_seg           ;set up construction segment in es and variable seg
  445. ;
  446.                 mov    cx,8000h          ;prep to clear 64K segment to zeros
  447.                 mov    ax,0000h
  448.                 mov    di,ax             ;beginning of the segment
  449.                 cld                      ;increment through memory
  450.                 rep stosw                ;store cx ax's into es:di
  451.  
  452.                 mov    ax,es             ;point to next segment
  453.                 add    ax,1000h
  454.                 mov    es,ax             ;put new seg back in es
  455.  
  456.                 mov    cx,2800h          ;number of words to clear in this seg
  457.                 mov    ax,0000h          ;store zeros
  458.                 mov    di,ax             ;beginning of the segment
  459.                 cld                      ;increment through memory
  460.                 rep stosw                ;store cx ax's into es:di
  461.  
  462.                 mov    es,seg            ;put seg back in es
  463. ;
  464.                 call   link_header       ;create link header
  465. ;
  466.                 add    seg,20h           ;set new segment to point to first byte past link header
  467.                 mov    es,seg            ;put new
  468.  
  469.                 mov    bx,0000h          ;where to put the sector within construction segment
  470.                 call   move_sector       ;put loader in proper place in construction segment
  471. ;
  472.                 mov    cx,0166h          ;first sector in the long group to come
  473.                 add    bx,400h           ;point to next sector location for move_sector
  474.  
  475. group_load:     call   load_sector       ;load the sector
  476.  
  477.                 call   move_sector       ;move it to proper place in memory
  478.  
  479.                 add    bx,400h           ;point to next sector move position
  480.                 inc    cl                ;the next sector on the track
  481.                 cmp    cl,6ah            ;is sector header nember above 69h
  482.                 jz     next_track        ;if so then increment the track count
  483.                 jmp    group_load        ;load next sector in the string
  484.  
  485. next_track:     sub    cl,05h            ;point to first sector on the track
  486.                 inc    ch                ;point to the next track
  487.                 cmp    ch,0dh            ;is it track 0dh ?
  488.                 jnz    group_load        ;if not continue group load
  489.                                          ;if it is 0dh then thru with the group load
  490.  
  491.                 mov    cx,0e67h          ;point to first of extended situations sectors
  492.                 mov    bx,es             ;need to change es to post segment = construction seg + 64K
  493.                 add    bx,1000h          ;add the 64K
  494.                 mov    es,bx             ;put it into the es again
  495.  
  496.                 mov    bx,2000h          ;put them at offset 2000h in the post seg
  497.  
  498. load_extra:     call   load_sector       ;load the sector in cx into sector buffer
  499.  
  500.                 call   move_sector       ;move it to place pointed to be es:bx
  501.  
  502.                 add    bx,400h           ;next sector position in post seg
  503.                 inc    cl                ;next sector on the track
  504.                 cmp    cx,0f68h          ;is it the end of this 6 sector string
  505.                 jne    check_done        ;if not then check if done loading
  506.  
  507.                 inc    cl                ;if last in this string of sectors then
  508.                 inc    cl                ;set cx so that next sector read will be 1065h
  509.  
  510. check_done:     cmp    cx,106ah          ;if this value then leave this load section
  511.                 je     do_mods           ;and go to modify code call
  512.  
  513. track_test:     cmp    cl,6ah            ;is it time to step tracks
  514.                 je     step_track        ;if so then new track
  515.                 jmp    load_extra        ;read the sector
  516.  
  517. step_track:     sub    cl,05h            ;first sector on the new track
  518.                 inc    ch                ;the new track
  519.                 jmp    load_extra        ;load the next sector
  520. ;
  521. ;
  522. do_mods:        mov    es,seg            ;put construction segment back in the es
  523.  
  524.                 call   mod_jet
  525. ;
  526.                 call   old_int_1e        ;put old int 1e back
  527. ;
  528.                 call   write_file
  529. ;
  530.                 lea    dx,mesg_3         ;print done message
  531.                 mov    ah,09h
  532.                 int 21h
  533. ;
  534.                 ret
  535.  
  536. begin           endp
  537. ;
  538. test_drive      proc  near
  539.                 mov     dl,writefile     ;get drive spec
  540.                 sub     dl,40h           ;convert to dos drive num A=1,B=2,...
  541.                 push    dx
  542.                 cmp     dl,02h           ;is it greater than B
  543.                 jg      continue         ;if so continue
  544.                 int 11h                  ;get system switch stats
  545.                 test    al,01h           ;test if any floppys attached
  546.                 jz      not_valid
  547.                 and     al,11000000b     ;mask bits
  548.                 rol     al,1
  549.                 rol     al,1             ;al has num disk drives minus one
  550.                 sub     dl,01h
  551.                 and     al,dl            ;if more than one floppy and drive B
  552.                 jnz     continue         ;then continue
  553.                 mov     spec_case,0ffh   ;set special case flag
  554.                 lea     dx,mesg_2        ;print insert the right disk message
  555.                 mov     ah,09h
  556.                 int 21h
  557.                 lea     dx,prt_drive     ;tag on the drive spec
  558.                 mov     ah,09h
  559.                 int 21h
  560.                 lea     dx,strk_key      ;ask strike a key
  561.                 mov     ah,09h
  562.                 int 21h
  563.                 mov     ah,08h           ;wait for a key or ctrl-c to break
  564.                 int 21h
  565. ;
  566. continue:       mov     ah,36h
  567.                 pop     dx               ;put dos drive back in dx
  568.                 int 21h                  ;dos drive test
  569.                 cmp     ax,0ffffh        ;ffff if drive invalid
  570.                 je      not_valid
  571.                 mul     cx               ;bytes per cluster in dx:ax, dx probably 0
  572.                 mul     bx               ;bytes avail in dx:ax
  573.                 cmp     dx,0001h         ;over 64K bytes ?
  574.                 jb      no_room          ;if not do no_room
  575.                 ja      test_exit        ;if greater then plenty of room so exit
  576.                 cmp     ax,5000h         ;over 5000 bytes on drive (plus dx) ?
  577.                 jna     no_room          ;if not do no room
  578. test_exit:      ret
  579. not_valid:      lea     dx,error_6       ;print error and return to dos
  580.                 mov     ah,09h
  581.                 int 21h
  582. ;
  583.                 call    old_int_1e
  584. ;
  585.                 mov     ax,4c01h         ;function to terminate process with errorlevel = 2, 'hard error'
  586.                 int 21h                  ;call to dos
  587. no_room:        lea     dx,error_7       ;print error and return to dos
  588.                 mov     ah,09h
  589.                 int 21h
  590.                 mov     ax,4c01h         ;function to terminate process with errorlevel = 2, 'hard error'
  591.                 int 21h                  ;call to dos
  592. test_drive      endp
  593. ;
  594. save_int_1e     proc  near
  595.                 push    es               ;save the es
  596.                 push    bx               ;save the bx
  597.                 push    ax               ;save the ax
  598.  
  599.                 mov     al,1eh           ;interrupt # in al
  600.                 mov     ah,35h           ;get interrupt address in es:bx
  601.                 int 21h
  602.  
  603.                 mov     int_1e,bx        ;save the interupt in int_1e
  604.                 mov     int_1e +2,es     ;save the high part in int_1e +2
  605.  
  606.                 pop     ax               ;bring back those saved registers
  607.                 pop     bx
  608.                 pop     es
  609.                 ret                      ;get the hell out of here
  610. save_int_1e     endp
  611. ;
  612. new_int_1e      proc  near
  613.                 push    dx               ;save the dx, remember the ds is already set
  614.                 push    ax               ;save the ax
  615.  
  616.                 lea     dx,parmtable     ;new parm table offset in dx
  617.                 mov     al,1eh           ;do interrupt 1eh
  618.                 mov     ah,25h           ;put int al offset dx, segment ds in place
  619.                 int 21h                  ;dos replace vector call
  620.  
  621.                 pop     ax               ;restore the ax
  622.                 pop     dx               ;bring the dx back to original value
  623.                 ret                      ;leave this place
  624. new_int_1e      endp
  625. ;
  626. load_sector     proc  near
  627. ;
  628.                 push    es               ;save es and bx
  629.                 push    bx
  630.                 push    ds               ;mov ds to es
  631.                 pop     es
  632. ;
  633.                 mov     retry,05h        ;five tries to read the sector
  634. ;
  635. read_sector:    lea     bx,sec_buff      ;load offset of buffer in the ds
  636.                 mov     al,01h           ;one sector
  637.                 mov     ah,02h           ;read
  638.                 mov     dl,00h           ;drive A
  639.                 mov     dh,00h           ;side zero
  640.                                          ;track and sector already in cx
  641.                 int 13h                  ;bios disk read
  642.                 jnc     good_read        ;if ok then continue
  643.                 dec     retry            ;if bad read then decrement the retry count
  644.                 jnz     read_sector
  645.                 lea     dx,error_1       ;point to the error message
  646.                 mov     ah,09h           ;dos print string function
  647.                 int 21h                  ;call to dos
  648. ;
  649.                 call    old_int_1e
  650. ;
  651.                 mov     ax,4c01h         ;function to terminate process with errorlevel = 2, 'hard error'
  652.                 int 21h                  ;call to dos
  653. ;
  654. good_read:      pop     bx               ;restore bx
  655.                 pop     es               ;bring back the original es which contains contruction segment
  656.                 ret                      ;leave this place now
  657. load_sector     endp
  658. ;
  659. ;
  660. ;
  661. move_sector     proc  near
  662.                 push   cx                ;save the cx
  663.                 push   di                ;save the di
  664.  
  665.                 lea    si,sec_buff       ;point source to sector buffer
  666.                 mov    di,bx             ;point di to destination in construction seg
  667.                 mov    cx,400h           ;mov 1K bytes
  668.                 cld                      ;increment through memory
  669.                 rep movsb                ;mov cx bytes from ds:si to es:di
  670.  
  671.                 pop    di                ;restore the di
  672.                 pop    cx                ;restore the cx
  673.                 ret                      ;exit to calling procedure
  674.  
  675. move_sector     endp
  676. ;
  677. ;
  678. ;
  679. mod_jet         proc  near
  680.  
  681.                 lea     si,fixup_00            ;put in first jmp into our code
  682.                 mov     di,00h                 ;put at offset 00h
  683.                 cmp     byte ptr es:[di],90h   ;check th opcode first
  684.                 je      go_on                  ;make sure its a nop
  685.                 jmp     bad_opcode             ;had to be done this way because bad_opcode out of range for jnz
  686. go_on:          mov     cx,length_00           ;put the length of the fix in the cx for the move
  687.                 cld                            ;increment through memory
  688.                 rep movsb                      ;move from ds:si to es:di
  689. ;
  690. ;
  691.                 cmp     byte ptr version,13h   ;check for version 1.3
  692.                 jne     cont_347               ;if not continue with fixup_347
  693.  
  694.                 lea     si,option_calls        ;prep to move in optional calls for ver 1.3
  695.                 lea     di,prt_calls           ;here's where they go
  696.                 push    es                     ;set es up to point in ds
  697.                 push    ds
  698.                 pop     es
  699.  
  700.                 mov     cx,len_opt_calls       ;num bytes to move
  701.                 cld                            ;increment the si,di
  702.                 repz movsb                     ;move'em
  703.  
  704.                 pop     es                     ;restore es to point to construct seg
  705.  
  706.  
  707. cont_347:       lea     si,fixup_347           ;move in hooks
  708.                 mov     di,347h                ;put at offset 347h
  709.                 mov     cx,length_347          ;length of the fix
  710.                 cld                            ;increment through memory
  711.                 rep movsb                      ;move from ds:si to es:di
  712. ;
  713. ;
  714.                 mov     di,722h                ;put in command line required
  715.                 mov     word ptr es:[di],2020h ;put at offset 722h
  716. ;
  717. ;
  718.                 lea     si,fixup_554           ;key board hook to exit to dos
  719.                 mov     di,554h                ;put at offset 554h
  720.                 mov     cx,length_554          ;length of the fix
  721.                 cld                            ;increment through memory
  722.                 rep movsb                      ;move from ds:si to es:di
  723. ;
  724. ;
  725.                 lea     si,fixup_684           ;load extra sectors hook
  726.                 mov     di,684h                ;put at offset 684h
  727.                 cmp     byte ptr es:[di],0e8h  ;make sure its a call
  728.                 je      more_684               ;if it is continue
  729.                 jmp     bad_opcode             ;otherwise do bad opcode error
  730. more_684:       mov     cx,length_684          ;length of the fix
  731.                 cld                            ;increment through memory
  732.                 rep movsb                      ;move from ds:si to es:di
  733. ;
  734. ;
  735.                 lea     si,fixup_68a           ;another load extra sectors hook
  736.                 mov     di,68ah                ;put t offset 68ah
  737.                 cmp     byte ptr es:[di],0e8h  ;make sure its a call
  738.                 jnz     bad_opcode             ;if bad opcode then error
  739.                 mov     cx,length_68a          ;length of the fix
  740.                 cld                            ;increment through memory
  741.                 rep movsb                      ;move from ds:si to es:di
  742. ;
  743. ;
  744.                 lea     si,fixup_6b4           ;the last load extra sectors hook
  745.                 mov     di,6b4h                ;put at offset 6b4
  746.                 cmp     byte ptr es:[di],0e8h  ;make sure its a call
  747.                 jnz     bad_opcode             ;if bad opcode then error
  748.                 mov     cx,length_6b4          ;length of the fix
  749.                 cld                            ;increment through memory
  750.                 rep movsb                      ;move from ds:si to es:di
  751. ;
  752. ;
  753.                 cmp     byte ptr version,13h   ;check for version 1.3
  754.                 jz      other_pg               ;if so do the other print graphics hook mod
  755.  
  756.                 lea     si,fixup_712a          ;prt graphics hook
  757.                 mov     di,712ah               ;put at offset 712ah
  758.                 cmp     byte ptr es:[di],0e8h  ;make sure its a call
  759.                 jnz     bad_opcode             ;if not right opcode then error
  760.                 mov     cx,length_712a         ;length of the fix
  761.                 cld                            ;increment through memory
  762.                 rep movsb                      ;move from ds:si to es:di
  763.                 jmp     put_postseg            ;continue on skipping next mod
  764.  
  765. other_pg:       lea     si,fixup_6f0d          ;prt graphics hook
  766.                 mov     di,6f0dh               ;put at offset 6f0dh
  767.                 cmp     byte ptr es:[di],0e8h  ;make sure its a call
  768.                 jnz     bad_opcode             ;if not right opcode then error
  769.                 mov     cx,length_6f0d         ;length of the fix
  770.                 cld                            ;increment through memory
  771.                 rep movsb                      ;move from ds:si to es:di
  772. ;
  773. ;
  774. put_postseg:    cmp     byte ptr version,13h      ;is it version 1.3
  775.                 jne     cont_postseg              ;if not then continue on
  776.                 mov     word ptr copy_pt_1,0de6ah ;need to change address of point where extra sector
  777.                 mov     word ptr copy_pt_2,0de6ah ;info is copied into code segment
  778.                                                   ;then continue
  779.  
  780. cont_postseg:   lea     si,postseg             ;move in post segment code
  781.                 push    es                     ;save this segment
  782.                 mov     bx,es                  ;point to the new segment
  783.                 add     bx,1000h               ;which is 10000h past the old
  784.                 mov     es,bx                  ;load the new segment
  785.                 mov     di,00h                 ;point to beginning of new segment
  786.                 mov     cx,length_post         ;length of the fix
  787.                 cld                            ;increment through memory
  788.                 rep movsb                      ;move from ds:si to es:di
  789.                 pop     es                     ;restore the es
  790. ;
  791.                 ret                            ;return to calling procedure
  792. ;
  793. bad_opcode:     lea     dx,error_3             ;print error 3 message
  794.                 mov     ah,09h
  795.                 int 21h
  796. ;
  797.                 call    old_int_1e
  798. ;
  799.                 mov     ax,4c01h               ;function to terminate process with errorlevel = 2, 'hard error'
  800.                 int 21h                        ;call to dos
  801.  
  802. mod_jet         endp
  803. ;
  804. ;
  805. ;
  806. link_header     proc  near
  807.                 push   si                ;save si and si
  808.                 push   di
  809.  
  810.                 cmp    byte ptr version,13h      ;is this version 1.3
  811.                 jne    cont_link                 ;if not continue on
  812.                 mov    byte ptr link_stack,90h   ;change initial stack to 0090 from 1dee
  813.                 mov    byte ptr link_stack+1,00h
  814.  
  815. cont_link:      lea    si,link_head      ;point to link header info
  816.                 mov    di,00h            ;point to beginning of consruction seg
  817.                 mov    cx,link_len       ;load length of link header info
  818.                 cld                      ;increment through memory
  819.                 rep movsb                ;move link header into construction seg
  820.  
  821.                 pop    di                ;restore si and di
  822.                 pop    si
  823.  
  824.                 ret                      ;return to calling procedure
  825. link_header     endp
  826. ;
  827. write_file      proc  near
  828.                 push    ds               ;save the ds
  829.                 cmp     spec_case,0ffh   ;is this a special drive case
  830.                 jnz     do_write
  831.                 lea     dx,mesg_2        ;ask insert right disk
  832.                 mov     ah,09h
  833.                 int 21h
  834.                 lea     dx,prt_drive     ;print the drive spec
  835.                 mov     ah,09h
  836.                 int 21h
  837.                 lea     dx,strk_key      ;ask srike a ket to continue
  838.                 mov     ah,09h
  839.                 int 21h
  840.                 mov     ah,08h           ;wait for a key or ctrl-c to break
  841.                 int 21h
  842. ;
  843. do_write:       lea     bx,copyright     ;load address of copyright string
  844.                 sub     ax,ax            ;clear the ax
  845.                 mov     cx,(copylen/2h)  ;add this many words
  846. copy_chk:       add     ax,[bx]          ;add to ax
  847.                 inc     bx               ;point to next word
  848.                 inc     bx
  849.                 loop    copy_chk         ;loop until all words done
  850.                 cmp     ax,copy_c_sum    ;is it correct ?
  851.                 jne     bad_write        ;if not then don't write the Jet.exe file
  852. ;
  853.                 lea     dx,writefile     ;point to file and path ascii-z string
  854.                 mov     cx,20h           ;attribute of file to be created
  855.                 mov     ah,3ch           ;dos create file function
  856.                 int 21h                  ;call to dos
  857.                 jc      bad_write        ;carry set then handle the error
  858. ;
  859.                 mov     dx,seg           ;load segment of Jet info
  860.                 sub     dx,20h           ;relocate to link header
  861.                 mov     ds,dx            ;put the segment in ds
  862.                 sub     dx,dx            ;point to the beginning of the file in memory
  863.                 mov     cx,0ffffh        ;write this many bytes, this is max allowed
  864.                 mov     bx,ax            ;put the file handle in the bx for this function call
  865.                 mov     ah,40h           ;write to file function
  866.                 int 21h                  ;call to dos
  867.                 jc      bad_write        ;carry set then handle the error
  868.                 cmp     ax,0ffffh        ;was correct number of bytes written ?
  869.                 jnz     bad_write        ;if not then handle the error
  870. ;
  871.                 mov     cx,0h            ;move pointer past the end of the file
  872.                 mov     dx,01h           ;this many bytes (1)
  873.                 mov     ah,42h           ;function to move pointer
  874.                 mov     al,02h           ;method of pointer movement
  875.                 int 21h                  ;call to dos
  876.                 jc      bad_write        ;carry set then handle the error
  877. ;
  878.                 mov     dx,ds            ;point to the next segment to write from
  879.                 add     dx,1000h         ;add 64K
  880.                 mov     ds,dx            ;put the new segment back in the ds
  881.                 sub     dx,dx            ;point to the beginning of the segment
  882.                 mov     cx,5000h         ;write this many bytes
  883.                 mov     ah,40h           ;write to file function
  884.                 int 21h                  ;call to dos
  885.                 jc      bad_write        ;if carry set then handle error
  886.                 cmp     ax,5000h         ;was correct number of bytes written ?
  887.                 jnz     bad_write        ;if not then do error
  888. ;
  889.                 mov     ah,3eh           ;close file function, handle in bx
  890.                 int 21h                  ;call to dos
  891.                 jc      bad_write        ;if carry set then handle the error
  892.  
  893.                 pop     ds               ;restore the ds segment
  894.  
  895.                 ret                      ;return to calling procedure
  896. ;
  897. bad_write:      pop     ds               ;error handling here, restore the ds
  898.                 lea     dx,error_4       ;point to error message
  899.                 mov     ah,09h           ;print string function
  900.                 int 21h                  ;call to dos
  901.  
  902.                 mov     ax,4c01h         ;function to terminate process with errorlevel = 2, 'hard error'
  903.                 int 21h                  ;call to dos
  904. ;
  905. write_file      endp
  906. ;
  907. ;
  908. ;
  909. check_sum       proc  near
  910.                 mov   cx,200h            ;sum 512 words
  911.                 lea   bx,sec_buff        ;they are in the sector buffer
  912.                 sub   ax,ax              ;clear the ax to hold the sum
  913. sum:            add   ax,[bx]            ;add this word to the ax
  914.                 inc   bx                 ;point to next word
  915.                 inc   bx
  916.                 loop  sum                ;do 200h words
  917.                 mov   bx,chk_sum_10      ;load correct v1.0 value into bx
  918.                 cmp   ax,bx              ;is it Jet ver 1.0 ?
  919.                 je    exit_10            ;if so do the proper exit routine
  920.                 mov   bx,chk_sum_13      ;load correct v1.3 value into bx
  921.                 cmp   ax,bx              ;is it Jet ver 1.3 ?
  922.                 je    exit_13            ;if so do the proper exit routine
  923.                                          ;if not drop thru to error code
  924.  
  925. bad_chksum:     lea   dx,error_2         ;unidentified loader message
  926.                 mov   ah,09h             ;print function
  927.                 int 21h                  ;call dos function
  928.  
  929.                 call  old_int_1e         ;put the old parameter table pointer back
  930.  
  931.                 mov   ax,4c01h           ;function to terminate process with errorlevel = 2, 'hard error'
  932.                 int 21h                  ;call dos function
  933.  
  934. exit_10:        mov   version,10h        ;put 10 hex into version
  935.                 ret                      ;and leave procedure
  936.  
  937. exit_13:        mov   version,13h        ;put 13 hex into version
  938.                 ret                      ;and leave procedure
  939.  
  940. check_sum       endp
  941. ;
  942. ;
  943. ;
  944. old_int_1e      proc  near
  945.                 push    ds               ;save the ds register
  946.                 push    dx               ;save the dx register
  947.  
  948.                 mov     dx,word ptr int_1e      ;get old offset value
  949.                 mov     ax,word ptr int_1e +2   ;get old segment value
  950.                 mov     ds,ax                   ;put segment value in ds
  951.                 mov     ah,25h                  ;dos change interrupt function
  952.                 mov     al,1eh                  ;interrupt number
  953.                 int 21h                         ;call dos function
  954.  
  955.                 pop     dx               ;restore the dx
  956.                 pop     ds               ;restore the ds
  957.                 ret                      ;return from procedure
  958. old_int_1e      endp
  959. ;
  960. ;
  961. ;
  962. set_seg         proc  near
  963.                 push    ax               ;save the ax
  964.                 mov     ax,construct     ;load segment after the code segment
  965.                 mov     es,ax            ;put it in the es
  966.                 mov     seg,ax           ;and in the proper variable for future reference
  967.                 pop     ax               ;restore ax
  968.                 ret                      ;return to calling procedure
  969.  
  970. set_seg         endp
  971. ;
  972. ;
  973. ;
  974. codeseg         ends                     ;end of code
  975. ;
  976. construct       segment  para            ;define Jet construction segment
  977. construct       ends
  978. ;
  979.                 end     begin            ;end of program
  980.