home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / patchcompiler_437.lzh / PatchCompiler / Source / PatchStarModule.Ass < prev    next >
Text File  |  1991-01-16  |  10KB  |  415 lines

  1.     opt l+    ; linkable
  2.  
  3.  
  4. ;  V11
  5. ;  ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  6. ;  ­­                    Patch Module V1.00                        ­­
  7. ;  ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  8. ;  ­­  © Roger Fischlin, Steigerwaldweg 6, 6450 Hanau 7, Germany   ­­
  9. ;  ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  10.  
  11.     opt    p+
  12.  
  13.  
  14.     XDEF    PATCH_MODULE_START,PATCH_MODULE_END
  15.     XDEF.l    PATCH_MODULE_SIZE
  16.  
  17.     incdir       "ram:include/"
  18.  
  19.             include     exec/memory.i
  20.     include    exec/exec_lib.i
  21.     include    exec/interrupts.i
  22.     include    libraries/dos_lib.i
  23.     include    libraries/dos.i
  24.     include    libraries/dosextens.i
  25.  
  26. PATCH_MODULE_START
  27.  
  28. ; Commands
  29.  
  30. ;  ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  31. ;  ­­ BEGIN        "B"    Byte                  ­­
  32. ;  ­­         0    Byte                  ­­
  33. ;  ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  34. ;  ­­ END        "E"    Byte                  ­­
  35. ;  ­­         0    Byte                  ­­
  36. ;  ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  37. ;  ­­ QUIT        "Q"    Byte                  ­­
  38. ;  ­­         0    Byte                  ­­
  39. ;  ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  40. ;  ­­ TEXT        "T"    Byte                  ­­
  41. ;  ­­         Size    Byte                  ­­
  42. ;  ­­         ASCII    Byte (word alligned)  ­­
  43. ;  ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  44. ;  ­­ PATCH        "P"    Byte                  ­­
  45. ;  ­­         Size    Byte                  ­­
  46. ;  ­­         Address    Long                  ­­
  47. ;  ­­         Data    Byte (word alligned)  ­­
  48. ;  ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  49. ;  ­­ CHECK        "C"    Byte                  ­­
  50. ;  ­­         Size    Byte                  ­­
  51. ;  ­­         Address    Long                  ­­
  52. ;  ­­         Data    Byte (word alligned)  ­­
  53. ;  ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  54. ;  ­­ IF         "I"    Byte                  ­­
  55. ;  ­­         true/false    Byte (true = 0)       ­­
  56. ;  ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  57. ;  ­­ end of patch    "."    Byte                  ­­
  58. ;  ­­         0    Byte                  ­­
  59. ;  ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  60.  
  61.  
  62. DOS    macro            ; one library, one macro .....
  63.     move.l    a5,a6
  64.     jsr    _LVO\1(a6)
  65.     endm
  66.  
  67.         
  68.  
  69. OpenThem    clr.b    -1(a0,d0)        ; a0 ^begin of arg
  70.     move.l    a0,a4
  71.     lea    dosname(pc),a1        ; open DOS
  72.     moveq.l    #33,d0
  73.     CALLEXEC     OpenLibrary
  74.     move.l    d0,a5
  75.     tst.l    d0
  76.     beq    NoDOS
  77.     bsr    Main
  78.     move.l    a5,a1        ; close DOS
  79.     CALLEXEC    CloseLibrary
  80. NoDOS    moveq.l    #0,d0
  81.     rts
  82. dosname    DOSNAME
  83.  
  84.  
  85. Main    cmp.b    #"?",(a4)        ; check args !
  86.     beq    INFO
  87.     tst.b    (a4)
  88.     beq    INFO        ; no arg ?
  89. .Loop1    move.b    (a4)+,d0
  90.     cmp.b    #" ",d0        ; skip spaces and tabs 
  91.     beq.s    .Loop1
  92.     cmp.b    #9,d0
  93.     beq.s    .Loop1
  94.     cmp.b    #"'",d0
  95.     beq.s    .Quote
  96.     cmp.b    #'"',d0
  97.     bne.s    .Label1
  98. .Quote    move.l    a4,a0        ; save ^file name
  99. .Loop2    move.b    (a0)+,d1        ; skip name
  100.     beq.s    OpenFile        ; file name not in quotation marks !
  101.     cmp.b    d0,d1        ; same quotation mark ?
  102.     bne.s    .Loop2
  103.     clr.b    -1(a0)        ; terminate file name
  104.     addq.l    #1,a4        ; skip next command ..
  105.     bra.s    OpenFile
  106.  
  107. .Label1    move.l    a4,a0        ; terminate end of file name
  108. .Loop3    move.b    (a0)+,d0
  109.     beq.s    OpenFile
  110.     cmp.b    #" ",d0
  111.     beq.s    .Label2
  112.     cmp.b    #9,d0
  113.     bne.s    .Loop3
  114. .Label2    clr.b    -1(a0)        ; terminate with $00 byte
  115.     
  116.  
  117. OpenFile    subq.l    #1,a4
  118.  
  119.     move.l    a4,d1        ; open file
  120.     move.l    #MODE_OLDFILE,d2
  121.     DOS    Open
  122.     lea.l    Filehandle(pc),a0
  123.     move.l    d0,(a0)
  124.     bne.s    .Label1
  125.  
  126.     lea.l    .ErrorText1(pc),a0    ; write error msg
  127.     moveq.l    #.ErrorText1E-.ErrorText1,d0
  128.     bra    CLI_Text
  129. .ErrorText1    dc.b    "Couldn't open file !",$a
  130. .ErrorText1E    even    
  131.  
  132. .Label1    lea.l    Command(pc),a4        ; start patching
  133. .Label0    tst.b    (a4)+        ; skip info text
  134.     bne.s    .Label0
  135.     move.l    a4,d0        ; word alligned !
  136.     addq.l    #1,d0
  137.     bclr    #0,d0
  138.     move.l    d0,a4
  139.  
  140.  
  141. Next    moveq.l    #0,d0        ; CTRL-C ?
  142.     moveq.l    #0,d1
  143.     CALLEXEC    SetSignal
  144.     btst    #12,d0
  145.     bne    UserBreak
  146.  
  147.     move.b    (a4)+,d0        ; get command
  148.     cmp.b    #"T",d0        ; text ?
  149.     beq    TEXT
  150.     cmp.b    #"P",d0        ; patch ?
  151.     beq    PATCH
  152.     cmp.b    #"C",d0        ; check ?
  153.     beq    CHECK
  154.     cmp.b    #"I",d0        ; If ?
  155.     beq    _IF
  156.     cmp.b    #"B",d0        ; begin ?
  157.     beq    BEGIN
  158.     cmp.b    #"E",d0        ; end ?
  159.     beq    END
  160.     cmp.b    #"Q",d0        ; quit ?
  161.     beq.s    QUIT    
  162.     cmp.b    #".",d0        ; end of patch ?
  163.     beq.s    QUIT    
  164.  
  165. UnknownCommand    lea.l    UCText1(pc),a0        ; write "unknown command"
  166.     moveq.l    #UCText1E-UCText1,d0
  167.     bsr    CLI_Text
  168.     bra.s    QUIT
  169. UserBreak    lea.l    UBText1(pc),a0        ; write "user break"
  170.     moveq.l    #UBText1E-UBText1,d0
  171.     bsr    CLI_Text
  172.  
  173. QUIT    move.l    Filehandle(pc),d1    ; close file
  174.     DOS    Close
  175.     rts
  176.  
  177. UCText1    dc.b    "unknown command !",$a
  178. UCText1E    even    
  179. UBText1    dc.b    "user break.",$a
  180. UBText1E    even    
  181.  
  182. Filehandle    dc.l    0
  183. CountBEGIN    dc.l    0
  184. Flag    dc.b    0
  185.     even
  186.  
  187. ; ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  188. ; ­­                      BEGIN                           ­­
  189. ; ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  190.  
  191. BEGIN    addq.l    #1,a4
  192.     lea.l    CountBEGIN(pc),a0    ; one more BEGIN
  193.     addq.l    #1,(a0)
  194.     bra    Next
  195.  
  196. ; ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  197. ; ­­                      END                             ­­
  198. ; ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  199.  
  200. END    addq.l    #1,a4
  201.     lea.l    CountBEGIN(pc),a0
  202.     tst.l    (a0)        ; check if there are more ENDs than BEGINs
  203.     beq    .MoreENDs
  204.     subq.l    #1,(a0)        ; one BEGIN-END depth less
  205.     bra    Next
  206. .MoreENDs    lea.l    .ErrorText1(pc),a0    ; write error msg
  207.     moveq.l    #.ErrorText1E-.ErrorText1,d0
  208.     bsr    CLI_Text
  209.     bra    QUIT
  210. .ErrorText1    dc.b    "END without BEGIN !",$a
  211. .ErrorText1E    even    
  212.     
  213.  
  214. ; ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  215. ; ­­                      TEXT                            ­­
  216. ; ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  217.  
  218. TEXT    moveq.l    #0,d0        ; get text length
  219.     move.b    (a4),d0
  220.     moveq.l    #0,d1
  221.     move.b    (a4)+,d1        ; get pointer to next command
  222.     move.l    a4,a0
  223.     addq.l    #1,d1
  224.     bclr    #0,d1
  225.     add.l    d1,a4
  226.     bsr    CLI_Text        ; write text
  227.     beq    Next
  228.     bra    QUIT        ; write error
  229.     
  230. ; ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  231. ; ­­                      PATCH                           ­­
  232. ; ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  233.  
  234. PATCH    moveq.l    #0,d4        ; get patch length
  235.     move.b    (a4)+,d4
  236.     move.l    Filehandle(pc),d1    ; get file position to patch
  237.     move.l    (a4)+,d2
  238.     moveq.l    #OFFSET_BEGINNING,d3
  239.     DOS    Seek
  240.  
  241.     move.l    d4,d3    
  242.     move.l    a4,d2
  243.     move.l    d4,d0        ; get pointer to next command
  244.     addq.l    #1,d0
  245.     bclr    #0,d0
  246.     add.l    d0,a4
  247.     
  248.     move.l    Filehandle(pc),d1    ; patch
  249.     DOS    Write
  250.     cmp.l    d0,d3        ; write error ?
  251.     beq    Next
  252.     
  253.     lea.l    .ErrorText1(pc),a0    ; write error msg
  254.     moveq.l    #.ErrorText1E-.ErrorText1,d0
  255.     bsr    CLI_Text
  256.     bra    QUIT
  257. .ErrorText1    dc.b    "Write error !",$a
  258. .ErrorText1E    even    
  259.     
  260. ; ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  261. ; ­­                      CHECK                           ­­
  262. ; ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  263.  
  264. CHECK    moveq.l    #0,d4        ; get check length
  265.     move.b    (a4)+,d4
  266.     move.l    Filehandle(pc),d1    ; get file position
  267.     move.l    (a4)+,d2
  268.     moveq.l    #OFFSET_BEGINNING,d3
  269.     DOS    Seek
  270.  
  271.     lea.l    .Buffer(pc),a0
  272.     move.l    a0,d2
  273.     move.l    d4,d3
  274.     move.l    Filehandle(pc),d1    ; get file data
  275.     DOS    Read
  276.     cmp.l    d0,d3        ; write error ?
  277.     bne    .Error
  278.     
  279.     lea.l    Flag(pc),a2
  280.     clr.b    (a2)        ; set flag to true
  281.  
  282.     subq.l    #1,d4
  283.     lea.l    .Buffer(pc),a0
  284.     move.l    a4,a1
  285.     move.l    d4,d0        ; get pointer to next command
  286.     addq.l    #1+1,d0
  287.     bclr    #0,d0
  288.     add.l    d0,a4
  289.     
  290. .Loop    cmpm.b    (a0)+,(a1)+        ; compare
  291.     bne.s    .False
  292.     dbra    d4,.Loop
  293.     bra    Next
  294.  
  295. .False    move.b    #1,(a2)        ; set flag to false
  296.     bra    Next
  297.     
  298. .Error    lea.l    .ErrorText1(pc),a0    ; write error msg
  299.     moveq.l    #.ErrorText1E-.ErrorText1,d0
  300.     bsr    CLI_Text
  301.     bra    QUIT
  302. .ErrorText1    dc.b    "Read error !",$a
  303. .ErrorText1E    even    
  304.     
  305. .Buffer    ds.b    255
  306.     even
  307.  
  308. ; ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  309. ; ­­                        IF                            ­­
  310. ; ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  311.  
  312. _IF    move.b    (a4)+,d0        ; true or false ?
  313.     cmp.w    #"B"<<8,(a4)        ; next command "BEGIN" ?
  314.     bne.s    .Error
  315.     cmp.b    Flag(pc),d0
  316.     beq    Next        ; execute next commands
  317.  
  318.  
  319.     move.l    CountBEGIN(pc),d5     ; continue with same depth
  320.     
  321. .Skip
  322. .WordCommand    move.b    (a4)+,d0        ; skip command
  323.     moveq.l    #0,d1
  324.     move.b    (a4)+,d1
  325.     cmp.b    #"B",d0
  326.     beq.s    .Begin
  327.     cmp.b    #"E",d0
  328.     beq.s    .End
  329.     cmp.b    #"Q",d0        ; command consists of one word
  330.     beq.s    .WordCommand
  331.     cmp.b    #"I",d0        ; command consists of one word
  332.     beq.s    .WordCommand
  333.     cmp.b    #".",d0        ; end of patch ?!?
  334.     beq    .Error2
  335.     cmp.b    #"P",d0        ; command consists of several bytes
  336.     beq.s    .BytesCommand
  337.     cmp.b    #"C",d0        ; command consists of several bytes
  338.     beq.s    .BytesCommand
  339.     cmp.b    #"T",d0        ; text command
  340.     beq.s    .TextCommand
  341.     bra    UnknownCommand        ; unknown .....
  342.  
  343. .BytesCommand    addq.l    #4,a4
  344. .TextCommand    addq.l    #1,d1    
  345.     bclr    #0,d1        ; word alligned
  346.     add.l    d1,a4
  347.     bra.s    .Skip
  348.  
  349. .Begin    lea.l    CountBEGIN(pc),a0    ; one more BEGIN
  350.     addq.l    #1,(a0)
  351.     bra    .Skip
  352.  
  353. .End    lea.l    CountBEGIN(pc),a0
  354.     tst.l    (a0)        ; check if there are more ENDs than BEGINs
  355.     beq    .Error3
  356.     subq.l    #1,(a0)
  357.     cmp.l    (a0),d5        ; reached old depth ?
  358.     beq    Next
  359.     bra    .Skip
  360.     
  361.  
  362. .Error    lea.l    .ErrorText1(pc),a0    ; write error msg
  363.     moveq.l    #.ErrorText1E-.ErrorText1,d0
  364. .Label1    bsr    CLI_Text
  365.     bra    QUIT
  366. .ErrorText1    dc.b    "IF without BEGIN !",$a
  367. .ErrorText1E    even    
  368. .Error2    lea.l    .ErrorText2(pc),a0    ; write error msg
  369.     moveq.l    #.ErrorText2E-.ErrorText2,d0
  370.     bra.s    .Label1
  371. .ErrorText2    dc.b    "Unextected end of patch !",$a
  372. .ErrorText2E    even    
  373. .Error3    lea.l    .ErrorText3(pc),a0    ; write error msg
  374.     moveq.l    #.ErrorText3E-.ErrorText3,d0
  375.     bra.s    .Label1
  376. .ErrorText3    dc.b    "END without BEGIN !",$a
  377. .ErrorText3E    even    
  378.  
  379. ; ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  380. ; ­­                      INFO                            ­­
  381. ; ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  382.     
  383. INFO    lea.l    Command(pc),a0        ; get length of info string
  384.     moveq.l    #-1,d0
  385. .Label1    addq.l    #1,d0
  386.     tst.b    (a0)+
  387.     bne.s    .Label1
  388.     lea.l    Command(pc),a0        ; write string
  389. ;    bra    CLI_Text    
  390.  
  391. ; ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  392. ; ­­                Write Text to CLI                     ­­
  393. ; ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  394.  
  395. CLI_Text    movem.l    a0/d0,-(sp)
  396.     DOS    Output        ; get handle to CLI window
  397.     move.l    d0,d1
  398.     move.l    (sp)+,d3
  399.     move.l    (sp)+,d2
  400.     DOS    Write
  401.     cmp.l    d0,d3        ; write error
  402.     beq.s    .OK
  403.     moveq.l    #-1,d0
  404.     tst    d0
  405.     rts
  406. .OK    moveq.l    #0,d0
  407.     tst    d0
  408.     rts
  409.  
  410. Command
  411. PATCH_MODULE_END
  412.  
  413. PATCH_MODULE_SIZE equ PATCH_MODULE_END-PATCH_MODULE_START
  414.  
  415.