home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff361.lzh / FileMaster / PatchMaker / PatchMaker.s < prev    next >
Text File  |  1990-08-11  |  10KB  |  429 lines

  1.  
  2. ;    ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  3. ;    ­­                                                              ­­
  4. ;    ­­                Patch Maker  V1.0  (Jan. 1990)                ­­
  5. ;    ­­                                                              ­­
  6. ;    ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  7. ;    ­­                                                              ­­
  8. ;    ­­               Author: Roger Fischlin                         ­­
  9. ;    ­­                       Steigerwaldweg 6                       ­­
  10. ;    ­­                       D-6450 Hanau 7                         ­­
  11. ;    ­­                       West Germany                           ­­
  12. ;    ­­                                                              ­­
  13. ;    ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  14. ;    ­­                                                              ­­
  15. ;    ­­ Patch Maker is public domain software - so feel free to copy ­­
  16. ;    ­­                         it.                                  ­­
  17. ;    ­­                                                              ­­
  18. ;    ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  19. ;    ­­                                                              ­­
  20. ;    ­­              Assembler : DevPac Assembler V2.1               ­­
  21. ;    ­­              Linker    : Blink                               ­­
  22. ;    ­­                                                              ­­
  23. ;    ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  24.  
  25.  
  26.  
  27.  
  28.     incdir       ":include/"
  29.  
  30.     include    libraries/dos_lib.i
  31.     include    libraries/dos.i
  32.     include    exec/exec.i
  33.     include    exec/exec_lib.i
  34.  
  35.     include    misc/easystart.i
  36.  
  37. OpenThem    clr.l    Differences
  38.     move.l    d0,d6
  39.     lea    dosname(pc),a1        ; open Dos.library
  40.     moveq.l    #0,d0
  41.     CALLEXEC     OpenLibrary
  42.     move.l    d0,_DOSBase
  43.     beq    NoDos
  44.  
  45.     tst.l    returnMsg        ; get output handle
  46.     beq    CLI
  47.     move.l    #ConWindow,d1
  48.     move.l    #MODE_NEWFILE,d2    ; started from Workbench
  49.     CALLDOS    Open        ; so we must open an own window
  50.     tst.l    d0
  51.     beq    CloseDos    
  52.     move.l    d0,OutputHandle
  53.     bra.s    MakePatch
  54. CLI    CALLDOS    Output        ; started from CLI
  55.     move.l    d0,OutputHandle
  56.     
  57.     cmp.l    #1,d6        ; "?" ?
  58.     beq.s    MakePatch
  59.     move.l    OutputHandle,d1    ; write info text
  60.     move.l    #InfoText,d2
  61.     move.l    #Info_Length,d3
  62.     CALLDOS    Write
  63.     bra    CloseCon
  64.         
  65.  
  66.  
  67. MakePatch    move.l    OutputHandle,d1    ; write headline
  68.     move.l    #Headline,d2
  69.     move.l    #HL_Length,d3
  70.     CALLDOS    Write
  71.     
  72.  
  73.     move.l    OutputHandle,d1    ; ask user
  74.     move.l    #Text1,d2
  75.     move.l    #57-32,d3
  76.     CALLDOS    Write
  77.     move.l    OutputHandle,d1    ; get first file name
  78.     move.l    #Buffer1,d2
  79.     move.l    #256,d3
  80.     CALLDOS    Read
  81.     cmp.l    #1,d0        ; user just pressed return
  82.     beq    CloseCon
  83.     lea.l    Buffer1,a0
  84.     clr.b    -1(a0,d0)
  85.  
  86.     move.l    OutputHandle,d1    ; ask user
  87.     move.l    #Text2,d2
  88.     move.l    #57-32,d3
  89.     CALLDOS    Write
  90.     move.l    OutputHandle,d1    ; get first file name
  91.     move.l    #Buffer2,d2
  92.     move.l    #256,d3
  93.     CALLDOS    Read
  94.     cmp.l    #1,d0        ; user just pressed return
  95.     beq    CloseCon
  96.     lea.l    Buffer2,a0
  97.     clr.b    -1(a0,d0)
  98.     
  99.     move.l    OutputHandle,d1    ; ask user
  100.     move.l    #Text3,d2
  101.     move.l    #57-32,d3
  102.     CALLDOS    Write
  103.     move.l    OutputHandle,d1    ; get first file name
  104.     move.l    #PatchName,d2
  105.     move.l    #256,d3
  106.     CALLDOS    Read
  107.     cmp.l    #1,d0        ; user just pressed return
  108.     beq    CloseCon
  109.     lea.l    PatchName,a0
  110.     clr.b    -1(a0,d0)
  111.  
  112.  
  113.     move.l    #Buffer1,d1        ; open files
  114.     move.l    #MODE_OLDFILE,d2
  115.     CALLDOS    Open
  116.     tst.l    d0
  117.     beq    Open1Error
  118.     move.l    d0,FileHandle1
  119.     move.l    #Buffer2,d1
  120.     move.l    #MODE_OLDFILE,d2
  121.     CALLDOS    Open
  122.     tst.l    d0
  123.     beq    Open2Error
  124.     move.l    d0,FileHandle2
  125.     move.l    #PatchName,d1
  126.     move.l    #MODE_NEWFILE,d2
  127.     CALLDOS    Open
  128.     tst.l    d0
  129.     beq    Open3Error
  130.     move.l    d0,FileHandle3
  131.  
  132.     move.l    #Buffer1,d1        ; get lock for file size
  133.     moveq.l    #-2,d2
  134.     CALLDOS    Lock
  135.     move.l    d0,d5
  136.     beq    ReadError
  137.     move.l    d0,d1
  138.     move.l    #FIB,d2    
  139.     CALLDOS    Examine
  140.     move.l    d0,d6
  141.     move.l    d5,d1
  142.     CALLDOS    UnLock
  143.     tst.l    d6
  144.     beq    ReadError
  145.     move.l    FIB+fib_Size,d4    ; file 1 size
  146.  
  147.     move.l    #Buffer2,d1        ; get lock for file size
  148.     moveq.l    #-2,d2
  149.     CALLDOS    Lock
  150.     move.l    d0,d5
  151.     beq    ReadError
  152.     move.l    d0,d1
  153.     move.l    #FIB,d2    
  154.     CALLDOS    Examine
  155.     move.l    d0,d6
  156.     move.l    d5,d1
  157.     CALLDOS    UnLock
  158.     tst.l    d6
  159.     beq    ReadError
  160.     cmp.l    FIB+fib_Size,d4    ; comapre file sizes
  161.     bne    DifferentSizes
  162.  
  163.     move.l    OutputHandle,d1    ; write $a
  164.     move.l    #ReturnText,d2
  165.     moveq.l    #1,d3
  166.     CALLDOS    Write
  167.     move.l    #-4*1024,Offset    ; clear offset
  168.  
  169.     
  170. NextBlock    jsr    UserBreak
  171.     add.l    #4*1024,Offset
  172.     jsr    PrintCurrentPos
  173.     move.l    FileHandle1,d1        ; read block (4 KB)
  174.     move.l    #Buffer1,d2
  175.     move.l    #4*1024,d3
  176.     CALLDOS    Read
  177.     tst.l    d0
  178.     bmi    ReadError        ; error !    
  179.     tst.l    d0
  180.     beq    End        ; reached end of file 
  181.     move.l    d0,d5
  182.     move.l    FileHandle2,d1        ; read block (4 KB)
  183.     move.l    #Buffer2,d2
  184.     move.l    #4*1024,d3
  185.     CALLDOS    Read
  186.     cmp.l    d0,d5
  187.     bne    ReadError        ; same number of bytes ??
  188.     add.l    #Buffer1,d5
  189.     move.l    d5,BufferSize
  190.  
  191.     lea.l    Buffer1,a4        ; make patch by comparing both buffers
  192.     lea.l    Buffer2,a5
  193. Compare1    cmpm.b    (a4)+,(a5)+        ; same byte ?
  194.     beq    NoDifference
  195.     move.l    a4,d0
  196.     subq.l    #1,d0
  197.     sub.l    #Buffer1,d0
  198.     add.l    Offset,d0        ; get offset
  199.     lea.l    OffsetText+1,a0
  200.     jsr    MakeHex
  201.     move.l    FileHandle3,d1
  202.     move.l    #OffsetText,d2
  203.     move.l    #42-32,d3
  204.     CALLDOS    Write        ; write offset to patch
  205.     cmp.l    #42-32,d0
  206.     bne    ReadError
  207.     lea.l    -1(a4),a4
  208.     lea.l    -1(a5),a5
  209.     moveq.l    #0,d7        ; up to 16 bytes per row
  210.  
  211. Compare2    cmpm.b    (a4)+,(a5)+        
  212.     beq    NoMoreDiff
  213.     addq.l    #1,d7
  214.     add.l    #1,Differences
  215.     move.b    -1(a5),d0
  216.     jsr    MakeByte
  217.     move.l    FileHandle3,d1
  218.     move.l    #ByteText,d2
  219.     moveq.l    #3,d3
  220.     CALLDOS    Write        ; write byte to patch
  221.     cmp.l    #3,d0
  222.     bne    ReadError
  223.     move.l    a4,d0
  224.     cmp.b    #16,d7        ; already 16 bytes ?
  225.     beq    NoMoreDiff        
  226.     cmp.l    BufferSize,d0        ; reached end of buffer ?
  227.     bne    Compare2    
  228.     bra    NextBlock
  229. NoMoreDiff    move.l    FileHandle3,d1        ; write $a to patch
  230.     move.l    #ReturnText,d2
  231.     moveq.l    #1,d3
  232.     CALLDOS    Write
  233.     cmp.l    #1,d0
  234.     bne    ReadError
  235.  
  236. NoDifference    move.l    a4,d0
  237.     cmp.l    BufferSize,d0        ; reached end of buffer ?
  238.     bne    Compare1    
  239.     bra    NextBlock
  240.  
  241. End    lea.l    PatchText+54-38+2,a0    ; write patch size
  242.     move.l    Differences,d0
  243.     bsr    MakeHex
  244.     move.l    OutputHandle,d1    
  245.     move.l    #PatchText,d2
  246.     move.l    #67-38+3,d3
  247.     CALLDOS    Write
  248.  
  249. CloseFile3    move.l    FileHandle3,d1        ; close files
  250.     CALLDOS    Close
  251. CloseFile2    move.l    FileHandle2,d1
  252.     CALLDOS    Close
  253. CloseFile1    move.l    FileHandle1,d1
  254.     CALLDOS    Close
  255.  
  256.     move.l    OutputHandle,d1    ; print out some nice words
  257.     move.l    #GoodByeText,d2
  258.     move.l    #52-35+3,d3
  259.     CALLDOS    Write
  260.     
  261. CloseCon    tst.l    returnMsg
  262.     beq    CloseDos
  263.     move.l    OutputHandle,d1    ; wait  until user presses RETURN
  264.     move.l    #ConText,d2
  265.     move.l    #60-35+1,d3
  266.     CALLDOS    Write
  267.     move.l    OutputHandle,d1    
  268.     move.l    #Buffer1,d2
  269.     moveq.l    #1,d3
  270.     CALLDOS    Read
  271.     
  272.     move.l    OutputHandle,d1    ; close window if started from WB
  273.     CALLDOS    Close
  274.  
  275. CloseDos    move.l    _DOSBase,a1        ; close dos.library
  276.     CALLEXEC    CloseLibrary
  277.  
  278. NoDos    moveq.l    #0,d0
  279.     rts
  280.  
  281. *
  282. * error routines - print error text
  283. *
  284.  
  285. DifferentSizes    move.l    OutputHandle,d1    
  286.     move.l    #DiffSizesText,d2
  287.     move.l    #57-35+2,d3
  288.     CALLDOS    Write
  289.     bra    CloseFile3
  290. Open1Error    move.l    OutputHandle,d1    
  291.     move.l    #Open1ErrorText,d2
  292.     move.l    #67-35+3,d3
  293.     CALLDOS    Write
  294.     bra    CloseDos
  295. Open2Error    move.l    OutputHandle,d1    
  296.     move.l    #Open2ErrorText,d2
  297.     move.l    #67-35+3,d3
  298.     CALLDOS    Write
  299.     bra    CloseFile1
  300. Open3Error    move.l    OutputHandle,d1    
  301.     move.l    #Open3ErrorText,d2
  302.     move.l    #67-35+3,d3
  303.     CALLDOS    Write
  304.     bra    CloseFile2
  305. ReadError    move.l    OutputHandle,d1    
  306.     move.l    #DiskErrorText,d2
  307.     move.l    #67-35+4,d3
  308.     CALLDOS    Write
  309.     bra    CloseFile3
  310.  
  311.  
  312. *
  313. * subroutines    
  314. *
  315. MakeHex    lea.l    Hex(pc),a1        ; convert d0-> ASCII
  316.     lsl.l    #8,d0
  317.     moveq.l    #5,d2
  318. NextNibble    rol.l    #4,d0
  319.     move.b    d0,d1
  320.     and.l    #$f,d1
  321.     move.b    (a1,d1),(a0)+
  322.     dbra    d2,NextNibble
  323.     rts
  324.  
  325. MakeByte    lea.l    Hex(pc),a0        ; convert d0-> ASCII
  326.     move.b    d0,d1
  327.     and.l    #$f,d1
  328.     lsr.b    #4,d0
  329.     and.l    #$f,d0
  330.     move.b    (a0,d0),ByteText
  331.     move.b    (a0,d1),ByteText+1
  332.     rts
  333.     
  334. PrintCurrentPos
  335.     lea.l    CurrentPosText+47-32(pc),a0    ; write current offset
  336.     move.l    Offset,d0
  337.     bsr    MakeHex
  338.     move.l    OutputHandle,d1    
  339.     move.l    #CurrentPosText,d2
  340.     move.l    #53-32+1,d3
  341.     CALLDOS    Write
  342.     rts
  343.  
  344. UserBreak    sub.l    a1,a1        ; check if user break
  345.     CALLEXEC    FindTask
  346.     move.l    d0,a0
  347.     move.l    26(a0),d0
  348.     and.l    #%1111<<12,d0
  349.     tst.l    d0
  350.     bne.s    Break
  351.     rts
  352. Break    lea.l    4(a7),a7        ; exit jsr
  353.     move.l    OutputHandle,d1    
  354.     move.l    #UserBreakText,d2
  355.     move.l    #50-38+4,d3
  356.     CALLDOS    Write
  357.     bra    CloseFile3
  358.     
  359.  
  360.         
  361.  
  362.     even
  363. Text1    dc.b    "Enter first  file name : "
  364.     even
  365. Text2    dc.b    "Enter second file name : "
  366.     even
  367. Text3    dc.b    "Enter patch name       : "
  368.     even
  369. DiffSizesText    dc.b    $a,"Different file sizes !",$a
  370.     even
  371. Open1ErrorText    dc.b    $a,"ERROR - can't open first file ! ",$a,$a
  372.     even
  373. Open2ErrorText    dc.b    $a,"ERROR - can't open second file !",$a,$a
  374.     even
  375. Open3ErrorText    dc.b    $a,"ERROR - can't open patch file ! ",$a,$a
  376.     even
  377. DiskErrorText    dc.b    $a,$a,"ERROR - can't read/write bytes !",$a,$a
  378.     even
  379. UserBreakText    dc.b    $a,$a,"USER BREAK !",$a,$a
  380.     even
  381. GoodByeText    dc.b    $a,"Have a nice day !",$a,$a
  382.     even
  383. PatchText    dc.b    $a,$a,"Patch contains $000000 bytes.",$a
  384.     even
  385. ConText    dc.b    $a,"Press RETURN key to exit."
  386.     even
  387. InfoText
  388. Headline    dc.b    $a,$9b,"4;31;40m","            PATCH-MAKER   by Roger Fischlin 1/90            ",$9b,"0;31;40m",$a,$a
  389. HL_Length equ *-Headline
  390.     dc.b    "This small utility compares two files and  creates a  patch.",$a
  391.     dc.b    "So if somebody has got  the first  file, the  patch and FILE",$a
  392.     dc.b    "MASTER (Fish 298) he can create the second file. It's useful",$a 
  393.     dc.b    "if the first file isn't public domain.",$a,$a
  394.     dc.b    "                 Author : Roger Fischlin",$a
  395.     dc.b    "                          Steigerwaldweg 6",$a
  396.     dc.b    "                          D-6450 Hanau 7",$a
  397.     dc.b    "                          West Germany",$a,$a
  398.     dc.b    " PATCH MAKER is public domain / FILE MASTER is shareware !",$a,$a
  399. Info_Length equ *-InfoText
  400.     even
  401. CurrentPosText    dc.b    "Please wait - $000000",$0d
  402. OffsetText    dc.b    "$000000 : "
  403.     even
  404. ByteText    dc.b    "   "
  405.     even
  406. ReturnText    dc.b    $a
  407.     even
  408. Hex    dc.b    "0123456789abcdef"
  409. dosname    DOSNAME
  410.     even
  411. ConWindow    dc.b    "CON:60/20/520/150/Patch Maker Window",0
  412.     even
  413.  
  414.     Section    "",BSS
  415.  
  416. FileHandle1    ds.l    1
  417. FileHandle2    ds.l    1
  418. FileHandle3    ds.l    1
  419. _DOSBase    ds.l    1
  420. OutputHandle    ds.l    1
  421. Offset    ds.l    1
  422. Differences    ds.l    1
  423. BufferSize    ds.l    1
  424. Buffer1    ds.b    4*1024
  425. Buffer2    ds.b    4*1024
  426. PatchName    ds.b    256
  427.     cnop    0,4
  428. FIB    ds.b    fib_SIZEOF
  429.