home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / POLYBOOT.ZIP / PATCH401.ASM < prev    next >
Assembly Source File  |  1990-09-16  |  11KB  |  435 lines

  1. ;*************************************************************************
  2. ;*                                                                       *
  3. ;*  #MODUL:    PATCH401                         *
  4. ;*                                                                       *
  5. ;*  #Aufgabe:    Programm zum Patch von DOS 4.01 Systemdateien für     *
  6. ;*                POLYBOOT                 *
  7. ;*  #Inhalt:                                                             *
  8. ;*                                                                       *
  9. ;*  #Fehlerbehandlung:    -                         *
  10. ;*                                                                       *
  11. ;*************************************************************************
  12.  
  13. bell      equ        7
  14. cr      equ        0dh
  15. lf      equ        0ah
  16. escchr      equ        1bh
  17. BYTCNT      equ        20
  18.  
  19. code      segment
  20.       assume    cs:code, ds:code, es:nothing
  21.  
  22. offs0      label     near        ;benötigt für Adressberechnungen
  23.  
  24.       org        100h
  25. _main:      cld
  26.       mov        ax,ds
  27.       mov        es,ax
  28.       mov        si,80h
  29.       lodsb
  30.       mov        cl,al
  31.       mov        ch,0
  32.       mov        byte ptr [drive],0FFh
  33. patch01:  jcxz        patch03
  34.       lodsb
  35.       dec        cx
  36.       cmp        al,' '
  37.       je        patch01
  38.       cmp        al,'z'
  39.       ja        usage
  40.       cmp        al,'a'
  41.       jb        patch02
  42.       and        al,011011111b
  43. patch02:  cmp        al,'Z'
  44.       ja        usage
  45.       sub        al,'A'
  46.       jb        usage
  47.       cmp        byte ptr[drive],0FFh
  48.       jne        usage
  49.       mov        byte ptr[drive],al
  50.       lodsb
  51.       dec        cx
  52.       cmp        al,':'
  53.       je        patch01
  54. usage:      mov        dx,offset [usemsg]
  55. patcherr: mov        ah,9
  56.       int        21h
  57.       mov        ax,4C01h
  58.       int        21h
  59.  
  60. nothat:   mov        dx,offset [nosudr1]
  61.       mov        ah,9
  62.       int        21h
  63.       mov        dl,byte ptr [drive]
  64.       add        dl,'A'
  65.       mov        ah,2
  66.       int        21h
  67.       mov        dx,offset [nosudr2]
  68.       jmp        patcherr
  69.  
  70. patch03:  cmp        byte ptr[drive],0FFh
  71.       je        usage
  72.       mov        ah,8
  73.       mov        dl,80h
  74.       int        13h
  75.       jnc        @F
  76.       mov        dl,0
  77. @@:      int        11h
  78.       rol        al,1
  79.       rol        al,1
  80.       and        al,3
  81.       jnz        patch04
  82.       inc        ax
  83. patch04:  mov        ah,byte ptr[drive]
  84.       sub        ah,al
  85.       ja        @F
  86.       push        ax
  87.       mov        dx,offset [nohard]
  88.       mov        ah,9
  89.       int        21h
  90.       pop        ax
  91.       mov        ah,0
  92. @@:      mov        byte ptr [hd_nro],ah
  93.       add        al,dl
  94.       cmp        byte ptr [drive],al
  95.       ja        nothat
  96.       call        testbio
  97.       jc        noibm
  98.       call        testdos
  99.       jnc        patch05
  100. noibm:      mov        dx,offset [ibmerr]
  101.       jmp        patcherr
  102. patch05:  mov        al,byte ptr [drive]
  103.       mov        bx,offset [buffer]
  104.       mov        cx,1
  105.       mov        dx,0        ;read boot sector
  106.       int        25h
  107.       popf
  108.       mov        ax,32
  109.       mul        word ptr[bx+11h]
  110.       mov        cx,word ptr[bx+0Bh]
  111.       add        ax,cx
  112.       dec        ax
  113.       div        cx
  114.       mov        word ptr[bioanf],ax
  115.       mov        al,byte ptr[bx+0Dh]
  116.       cbw
  117.       mov        word ptr[dosanf],ax
  118.       mov        al,byte ptr [bx+10h]
  119.       cbw
  120.       mul        word ptr [bx+16h]
  121.       add        ax,word ptr [bx+0Eh]
  122.       add        word ptr[bioanf],ax
  123.       mov        dx,ax
  124.       mov        cx,1
  125.       mov        al,byte ptr [drive]
  126.       int        25h
  127.       popf
  128.       mov        di,bx
  129.       mov        cx,11
  130.       mov        si,offset [ibmbio]
  131.      rep  cmpsb
  132.       jnz        notboot
  133.       lea        di,[bx+20h]
  134.       mov        cx,11
  135.       mov        si,offset [ibmdos]
  136.      rep  cmpsb
  137.       jz        patch06
  138. notboot:  mov        dx,offset [syserr]
  139.       jmp        patcherr
  140.  
  141. patch06:  mov        ax,word ptr [bx+3Ah]
  142.       sub        ax,2
  143.       mul        word ptr [dosanf]
  144.       add        ax,word ptr [bioanf]
  145.       mov        word ptr [dosanf],ax
  146.  
  147. ;--- compare sector and file-oriented read bytes
  148.  
  149.       mov        ah,0
  150.       call        openbio
  151.       jc        notboot
  152.       mov        ax,word ptr [bioanf]
  153.       mov        word ptr [cursec],ax
  154. patch07:  mov        bx,word ptr [handle]
  155.       mov        cx,12
  156.       mov        dx,offset [buffer2]
  157.       mov        ah,3Fh
  158.       int        21h
  159.       jc        susperr
  160.       and        ax,ax
  161.       jz        patch08
  162.       push        ax
  163.       call        readsec
  164.       jc        susperr
  165.       pop        cx
  166.       mov        si,offset [buffer]
  167.       mov        di,offset [buffer2]
  168.      rep  cmpsb
  169.       jnz        notboot
  170.       mov        dx,500
  171.       mov        cx,0
  172.       mov        bx,word ptr [handle]
  173.       mov        ax,4201h
  174.       int        21h
  175.       jnc        patch07
  176. susperr:  mov        dx,offset [interr]
  177.       jmp        patcherr
  178.  
  179. patch08:  call        closefl
  180.       mov        ax,word ptr [dosanf]
  181.       cmp        word ptr [cursec],ax
  182.       jnc        patch09
  183.       mov        word ptr [cursec],ax
  184.       mov        ah,0
  185.       call        opendos
  186.       jnc        patch07
  187.       jmp        notboot
  188.  
  189. patch09:  mov        byte ptr [buffer2],0
  190.       mov        ah,0        ;READ ONLY
  191.       call        openbio
  192.       jc        susperr
  193.       mov        si,offset [hd1org]
  194.       call        testfl
  195.       jnc        patch10
  196.       or        byte ptr [buffer2],1
  197.       mov        ah,0        ;READ ONLY
  198.       call        openbio
  199.       jc        susperr
  200.       mov        si,offset [hd1pat]
  201.       call        testfl
  202.       jnc        patch10
  203.       jmp        noibm
  204. patch10:  mov        ah,0        ;READ ONLY
  205.       call        openbio
  206.       jc        susperr
  207.       mov        si,offset [hd2org]
  208.       call        testfl
  209.       jnc        patch11
  210.       or        byte ptr [buffer2],2
  211.       mov        ah,0        ;READ ONLY
  212.       call        openbio
  213.       jc        susperr
  214.       mov        si,offset [hd2pat]
  215.       call        testfl
  216.       jnc        patch11
  217.       jmp        noibm
  218. patch11:  mov        al,byte ptr [hd_nro]
  219.       xor        al,byte ptr [buffer2]
  220.       jnz        patch12
  221.       mov        dx,offset [nopatch]
  222.       jmp        patcherr
  223. patch12:  mov        byte ptr [buffer2],al
  224.       mov        dx,82h
  225.       mov        ax,4300h        ;GET ATTRIBUTES
  226.       int        21h
  227.       mov        word ptr [cursec],cx
  228.       and        cx,0FFE6h        ;NO SUBDIR, NO VOL_ID, NO READ_ONLY
  229.       mov        dx,82h
  230.       mov        ax,4301h        ;SET ATTRIBUTES
  231.       int        21h
  232.       mov        ah,2        ;READ/WRITE
  233.       call        openbio
  234.       test        byte ptr [buffer2],1
  235.       jz        patch14
  236.       mov        si,offset [hd1org]
  237.       test        byte ptr [hd_nro],1
  238.       jz        patch13
  239.       mov        si,offset [hd1pat]
  240. patch13:  call        patcher
  241.       jnc        patch14
  242.       jmp        susperr
  243. patch14:  test        byte ptr [buffer2],2
  244.       jz        patch16
  245.       mov        si,offset [hd2org]
  246.       test        byte ptr [hd_nro],2
  247.       jz        patch15
  248.       mov        si,offset [hd2pat]
  249. patch15:  call        patcher
  250.       jnc        patch16
  251.       jmp        susperr
  252. patch16:  call        closefl
  253.       mov        cx,word ptr [cursec]
  254.       and        cx,0FFE7h        ;NO SUBDIR, NO VOL_ID
  255.       mov        dx,82h
  256.       mov        ax,4301h        ;SET ATTRIBUTES
  257.       int        21h
  258.       mov        dx,offset [succmsg]
  259.       mov        ah,9
  260.       int        21h
  261. exit:      mov        ax,4C00h
  262.       int        21h
  263.  
  264.  
  265. ;------------------------------------------------------------
  266. ; READSEC: Liest Sektor (in CURSEC) in Buffer ein.
  267. ;------------------------------------------------------------
  268. readsec:  mov        al,byte ptr [drive]
  269.       mov        bx,offset [buffer]
  270.       mov        cx,1
  271.       mov        dx,word ptr [cursec]
  272.       int        25h
  273.       popf
  274.       jc        endrsec
  275.       inc        word ptr [cursec]
  276. endrsec:  ret
  277.  
  278. ;------------------------------------------------------------
  279. ; TESTXXX: Testet IBMBIO und IBMDOS auf Version 4.01
  280. ;------------------------------------------------------------
  281.  
  282. testbio:  mov        ah,0        ; READ-ONLY
  283.       call        openbio
  284.       mov        si,offset [biocmp]
  285.       jmp        testfl
  286. testdos:  mov        ah,0        ; READ-ONLY
  287.       call        opendos
  288.       mov        si,offset [doscmp]
  289. testfl:   jc        teste2
  290.       lodsw
  291.       mov        dx,ax
  292.       mov        cx,0
  293.       mov        bx,word ptr [handle]
  294.       mov        ax,4200h
  295.       int        21h
  296.       jc        teste1
  297.       mov        cx,word ptr[si]
  298.       mov        dx,offset [buffer]
  299.       mov        ah,3Fh
  300.       int        21h
  301.       jc        teste1
  302.       mov        cx,ax
  303.       lodsw
  304.       cmp        ax,cx
  305.       jne        teste1
  306.       mov        di,offset [buffer]
  307.      rep  cmpsb
  308.       jnz        teste1
  309.       call        closefl
  310.       ret
  311.  
  312. teste1:   call        closefl
  313. teste2:   stc
  314.       ret
  315.  
  316.  
  317. ;------------------------------------------------------------
  318. ; OPENXXX: Öffnet IBMBIO und IBMDOS
  319. ;------------------------------------------------------------
  320.  
  321. openbio:  mov        si,offset [biopath]
  322.       jmp        openfl
  323. opendos:  mov        si,offset [dospath]
  324. openfl:   mov        di,84h
  325. openfl1:  lodsb
  326.       stosb
  327.       and        al,al
  328.       jnz        openfl1
  329.       mov        dx,82h
  330.       mov        al,ah
  331.       mov        ah,3Dh
  332.       int        21h
  333.       jc        openex
  334.       mov        word ptr [handle],ax
  335. openex:   ret
  336.  
  337. ;------------------------------------------------------------
  338. ; CLOSEFL: Schliesst IBMBIO und IBMDOS
  339. ;------------------------------------------------------------
  340.  
  341. closefl:  mov        bx,word ptr [handle]
  342.       mov        ah,3Eh
  343.       ret
  344.  
  345.  
  346. ;------------------------------------------------------------
  347. ; PATCHER: Führt Patch durch
  348. ;------------------------------------------------------------
  349.  
  350. patcher:  lodsw
  351.       mov        dx,ax
  352.       mov        cx,0
  353.       mov        bx,word ptr [handle]
  354.       mov        ax,4200h
  355.       int        21h
  356.       jc        patche1
  357.       mov        cx,word ptr[si]
  358.       lea        dx,[si+2]
  359.       mov        ah,40h
  360.       int        21h
  361.       jc        patche1
  362.       cmp        ax,word ptr [si]
  363.       je        patche2
  364. patche1:  stc
  365. patche2:  ret
  366.  
  367.  
  368. ;------------------------------------------------------------
  369. ; Datenbereich fuer PATCH
  370. ;------------------------------------------------------------
  371.  
  372. usemsg:   DB        'USAGE:   PATCH401 d:',0Dh,0Ah,0Ah
  373.       DB        'Drive d: must be a physical harddisc drive or Floppy Disk',0Dh,0Ah,24h
  374. nohard:   DB        'This is not a harddisc drive - patching reversed for Floppy boot',0Dh,0Ah,24h
  375. nosudr1:  DB        'Drive $'
  376. nosudr2:  DB        ': is not a physical harddisc drive',0Dh,0Ah,24h
  377. syserr:   DB        'DOS is not bootable (not transferred by SYS)',0Dh,0Ah,24h
  378. ibmerr:   DB        'DOS is not IBM PC-DOS 4.01',0Dh,0Ah,24h
  379. nopatch:  DB        'Patch already made, no further patch necessary !',0Dh,0Ah,24h
  380. interr:   DB        'Internal Error - Please Contact Markus Noller, W. Germany (07191) 59110 !',0Dh,0Ah,24h
  381. succmsg:  DB        'PC-DOS 4.01 successfully patched',0Dh,0Ah,24h
  382.  
  383. ibmbio:   DB        'IBMBIO  COM'
  384. ibmdos:   DB        'IBMDOS  COM'
  385.  
  386. biopath:  DB        '\IBMBIO.COM',0
  387. dospath:  DB        '\IBMDOS.COM',0
  388.  
  389. biocmp:   DW        08021h        ;Offset
  390.       DW        07h         ;Länge
  391.       DB        ' 4.00',0Dh,0Ah
  392.  
  393. doscmp:   DW        08C87h        ;Offset
  394.       DW        07h         ;Länge
  395.       DB        ' 4.00',0Dh,0Ah
  396.  
  397. hd1org:   DW        7B49h        ;Offset
  398.       DW        0Ch         ;Länge
  399.       DB        '\CONFIG.SYS',0
  400.  
  401. hd1pat:   DW        7B49h        ;Offset
  402.       DW        0Ch         ;Länge
  403.       DB        '\CONFIG.DOS',0
  404.  
  405. hd2org:   DW        36CAh        ;Offset
  406.       DW        14h         ;Länge
  407.       DB        0D0h, 0C0h, 025h, 003h
  408.       DB        000h, 075h, 006h, 040h
  409.       DB        02Eh, 0FEh, 006h, 0C4h
  410.       DB        001h, 040h, 08Ah, 0C8h
  411.       DB        0F6h, 0C2h, 080h, 075h
  412.  
  413. hd2pat:   DW        36CAh        ;Offset
  414.       DW        14h         ;Länge
  415.       DB        0D0h, 0C0h, 024h, 003h
  416.       DB        075h, 006h, 040h, 02Eh
  417.       DB        0FEh, 006h, 0C4h, 001h
  418.       DB        040h, 08Ah, 0C8h, 040h
  419.       DB        0F6h, 0C2h, 080h, 075h
  420.  
  421. bioanf:   DW        0
  422. dosanf:   DW        0
  423. handle:   DW        0
  424. cursec:   DW        0
  425.  
  426. drive:      DB        0
  427. hd_nro:   DB        0
  428.  
  429. buffer:   DB        512 dup (?)
  430. buffer2:  DB        12 dup (?)
  431.  
  432. code      ends
  433.  
  434.       end        _main
  435.