home *** CD-ROM | disk | FTP | other *** search
/ Supremacy 2 / Supremacy-2.iso / Pompey / PP_062.MSA / TOMATO.S < prev    next >
Text File  |  1989-04-06  |  7KB  |  318 lines

  1.  
  2. **** CONVERT BINARY TO SOURCE
  3. **** Set tabs to 13 for tidyness
  4. **** if you haven't got devpac 2.2 gemmacro.s, or aeslib.s
  5. **** and are using older versions, set TOS1_4 to no.
  6. **** Written by the Genie of the Pompey Pirates ummm, ages ago
  7. **** Just thought it might be useful to some of you (especialy
  8. **** if you know sod all about gem). 
  9.  
  10.     opt    o+    OPTIMISE
  11.  
  12. **** You can find gemmacro.s on the Pompey Pirates devpac menu
  13. **** If you don't have it handy.
  14.  
  15.     include    gemmacro.s
  16.  
  17. yes    =    1    for conitional assembly
  18. no    =    0
  19. TOS1_4    =    yes    if you don't have tos 1.4 this
  20. *            must be no, or it may bomb.
  21. *            if you have got tos 1.4 it will
  22. *            do an extendid f_sel!
  23. *
  24.  
  25. start
  26.     pea    end-(start-256).w    neat memory skrink
  27.     pea    start-256(pc)    saves having to
  28.     pea    $4a0000        mess with the stack
  29.     trap    #1        and is a lot shorter
  30.     lea    12(sp),sp        code.
  31.     lea    stack(pc),sp
  32.     appl_init            must always init gem
  33.     graf_mouse    #0        arrow
  34. goagain    form_alert    #2,#alertstring    brimgs up an alert box
  35.     subq    #1,d0
  36.     move.w    d0,size
  37.     ifne    TOS1_4
  38.     fsel_exinput    #path,#name,#ltitle
  39.     elseif
  40.     fsel_input    #path,#name
  41.     endc
  42.     move.w    (a0),d0        all this does is
  43.     beq    exit        get the full path
  44.     lea    path(pc),a0        and filename together
  45.     lea    savepath(pc),a1
  46. up    cmp.b    #'*',(a0)
  47.     beq.s    notup
  48.     move.b    (a0)+,(a1)+
  49.     move.l    a1,a3
  50.     bra.s    up
  51. notup
  52.     lea    name(pc),a1        then it assumes you want
  53. down    move.b    (a1)+,(a0)+        the same path and filename
  54.     bne.s    down        with the .S extender, so it
  55. savernamer    move.l    a3,a0        will put you back into the
  56.     move.b    #'*',(a0)+        same directory.
  57.     move.b    #'.',(a0)+
  58.     move.b    #'S',(a0)+
  59.     move.b    #0,(a0)+
  60.     move.b    #0,(a0)
  61.     lea    name(pc),a0
  62. dot    cmp.b    #'.',(a0)+
  63.     bne.s    dot
  64.     move.b    #'S',(a0)+
  65.     move.b    #0,(a0)
  66.     lea    savepath(pc),a1    
  67.     ifne    TOS1_4
  68.     fsel_exinput    #savepath,#name,#stitle
  69.     elseif
  70.     fsel_input    #savepath,#name
  71.     endc
  72.     beq    exit
  73.     lea    savepath(pc),a0
  74. up2    cmp.b    #'*',(a0)+        this makes sure of the chosen
  75.     bne.s    up2        directory (can be completely
  76.     lea    -1(a0),a0        different).
  77.     lea    name(pc),a1
  78. down2    move.b    (a1)+,(a0)+
  79.  
  80.     bne.s    down2
  81.     
  82.     move.w    #$2f,-(sp)        get dta to find file info
  83.     trap    #1
  84.     addq.l    #2,sp
  85.     move.l    d0,dtabuff
  86.     move.w    #0,-(sp)        sfirst for the file size
  87.     pea    path(pc)        as we have done a memory
  88.     move.w    #$4e,-(sp)        shrink me need memory back
  89.     trap    #1        if I hadn't done a mem shrink
  90.     addq.l    #8,sp        gem would squinny
  91.     move.l    dtabuff(pc),a0
  92.     move.l    26(a0),d0
  93.     move.l    d0,d4
  94.     move.l    d0,d5
  95.     lsl    #2,d4        4 times the amount seems to be
  96.     move.l    d0,-(sp)        enough
  97.     move.w    #$48,-(sp)        malloc for load file
  98.     trap    #1        
  99.     addq.l    #6,sp
  100.     movem.l    d0/a0-a1,-(sp)
  101.     move.l    d0,a0
  102.     move.l    d5,a1
  103.     bsr    clearram
  104.     movem.l    (sp)+,d0/a0-a1
  105.     move.l    d0,filebuffer
  106.     move.l    d4,-(sp)        malloc for save file
  107.     move.w    #$48,-(sp)        note no ckeck is done to
  108.     trap    #1        see if there was memory
  109.     addq.l    #6,sp
  110.  
  111.     movem.l    d0/a0-a1,-(sp)
  112.     move.l    d0,a0
  113.     move.l    d4,a1
  114.     bsr    clearram        clean it up cause gem
  115.     movem.l    (sp)+,d0/a0-a1    fills it with crap
  116.  
  117.     move.l    d0,source
  118.     move.w    #0,-(sp)
  119.     pea    path(pc)
  120.     move.w    #$3d,-(sp)        open file
  121.     trap    #1
  122.     addq.l    #8,sp
  123.     move.w    d0,-(sp)
  124.     move.w    #$3e,-(sp)        ready for close file
  125.     move.l    filebuffer(pc),-(sp)
  126.     pea    $3456789        no file's gonna be that big!
  127.     move.w    d0,-(sp)
  128.     move.w    #$3f,-(sp)        read file
  129.     trap    #1
  130.     move.l    d0,d7
  131.     lea    12(sp),sp
  132.     trap    #1        close file
  133.     addq.l    #4,sp
  134.     move.l    source(pc),a6
  135.  
  136.     move.l    filebuffer(pc),a0
  137.     move.l    a6,a1        binary code address
  138.     move.w    size,d0
  139.     lsl    #2,d0
  140.     lea    sizes(pc),a3
  141.     move.l    (a3,d0.w),a3
  142.     move.l    a3,a2
  143.     cmp.w    #4,d0        do words?
  144.     beq.s    dowords
  145.     cmp.w    #8,d0        do longs then?
  146.     beq.s    dolongs
  147.  
  148. ****    it's bytes boys
  149.  
  150.     moveq    #0,d3
  151.     moveq    #1,d5
  152.     bra.s    mainloop
  153. dowords    moveq    #1,d3
  154.     moveq    #2,d5
  155.     bra.s    mainloop
  156. dolongs    moveq    #2,d3
  157.     moveq    #3,d5
  158. mainloop
  159.     move.l    source,a5
  160.     move.b    (a2)+,(a1)+
  161.     move.b    (a2)+,(a1)+
  162.     move.b    (a2)+,(a1)+
  163.     move.b    (a2)+,(a1)+
  164.     move.b    (a2)+,(a1)+
  165.     move.b    (a2)+,(a1)+
  166.     
  167.     bsr    convert
  168.     move.l    a3,a2
  169.     cmp.l    a0,a5
  170.     bgt.s    mainloop
  171.     move.l    a1,endsource
  172.         
  173.     move.w    #0,-(sp)
  174.     pea    savepath(pc)
  175.     move.w    #$3c,-(sp)        create the save file
  176.     trap    #1
  177.     addq.l    #8,sp
  178.     tst.l    d0
  179.     bmi    filerror
  180.     move.w    d0,d7
  181.     move.l    source(pc),-(sp)
  182.     move.l    endsource,a0
  183.     sub.l    source,a0
  184.     lea    -2(a0),a0
  185.     pea    (a0)
  186.     move.w    d0,-(sp)
  187.     move.w    #$40,-(sp)        write it
  188.     trap    #1
  189.     lea    12(sp),sp
  190.     tst.l    d0
  191.     bmi.s    filerror
  192.     move.w    d7,-(sp)
  193.     move.w    #$3e,-(sp)
  194.     trap    #1        close
  195.     addq.l    #4,sp
  196.     tst.l    d0
  197.     bmi.s    filerror
  198.     move.l    filebuffer(pc),-(sp)    mfree
  199.     move.w    #$49,-(sp)
  200.     trap    #1
  201.     addq.l    #6,sp
  202.     move.l    source(pc),-(sp)    mfree
  203.     move.w    #$49,-(sp)
  204.     trap    #1
  205.     addq.l    #6,sp
  206.     
  207.     form_alert    #2,#alert3
  208.     cmp.w    #1,d0
  209.     beq    goagain
  210.     
  211.     
  212.     
  213.     
  214. exit    appl_exit
  215.     clr.w    -(sp)
  216.     trap    #1
  217. clearram
  218. doclear
  219.     add.l    a0,a1
  220. doclear1    move.b    #0,(a0)+
  221.     cmp.l    a1,a0
  222.     blt.s    doclear1
  223.     rts
  224. filerror
  225.     graf_mouse    #0
  226.     form_alert    #1,#alert4
  227.     cmp.w    #1,d0
  228.     beq    goagain
  229.     move.l    filebuffer(pc),-(sp)    mfree
  230.     move.w    #$49,-(sp)
  231.     trap    #1
  232.     addq.l    #6,sp
  233.     move.l    source(pc),-(sp)    mfree
  234.     move.w    #$49,-(sp)
  235.     trap    #1
  236.     addq.l    #6,sp
  237.  
  238.     bra.s    exit
  239. convert
  240. **** convert a long word hex to hex ascii
  241. **** enter with a0 number to convert. a1 buffer
  242. **** enter with d3 as size to do 1 for byte 2 for word 3 for long
  243.     move.w    d3,resetd3+2
  244.     moveq    #0,d0
  245.     moveq    #0,d1
  246.     moveq    #16,d4
  247.     divu    d5,d4
  248.     subq    #1,d4
  249.     move.b    #'$',(a1)+
  250.     
  251. more12
  252.     cmp.l    a0,a5
  253.     beq.s    byebye
  254.     move.b    (a0)+,d0
  255.     
  256.     lsl.w    #8,d0
  257.     roxr.l    #4,d0
  258.     ror.b    #4,d0
  259.     move.b    d0,d1
  260.     ror.w    #8,d0
  261.     ext    d0
  262.     ext    d1
  263.     cmp.b    #9,d0
  264.     bgt.s    letter
  265.     add    #$30,d0
  266.     bra.s    dr1
  267. letter    add    #$57,d0
  268. dr1    cmp.b    #9,d1
  269.     bgt.s    lett
  270.     add    #$30,d1
  271.     bra.s    more_convert
  272.     
  273. lett    add    #$57,d1
  274. more_convert
  275.     move.b    d0,(a1)+
  276.     move.b    d1,(a1)+
  277.  
  278.     dbf    d3,more12
  279. resetd3    move.w    #0,d3
  280.     move.b    #',',(a1)+
  281.     move.b    #'$',(a1)+
  282.     dbf    d4,more12
  283.     lea    -2(a1),a1
  284.  
  285.     move.b    #13,(a1)+
  286.     move.b    #10,(a1)+
  287. byebye    rts
  288.     
  289.     
  290. alertstring    dc.b    "[1][  |Convert HEX file to SOURCE.|What"
  291.     dc.b    " size do you want to use.][ BYTE | WORD | LONG ]",0
  292. alert2    dc.b    "[1][  |Process done. SAVING][ OK ]",0
  293. alert3    dc.b    "[1][  |File saved ok. Wanna go again?][ YES | NO ]",0
  294. alert4    dc.b    "[1][  |ERROR saving file. Start again][ YES | NO ]",0
  295. ltitle    dc.b    "LOAD FILE TO CONVERT",0
  296. stitle    dc.b    "SAVE CONVERTED FILE",0
  297.     include    aeslib.s
  298.     data
  299. sizes    dc.l    size1,size2,size3
  300.  
  301. size1    dc.b    9,"DC.B",9
  302. size2    dc.b    9,"DC.W",9
  303. size3    dc.b    9,"DC.L",9
  304.     bss
  305. source    ds.l    1
  306. endsource    ds.l    1
  307. savepath    ds.l    12
  308. path     
  309.     DS.L    12
  310. name    ds.b    16
  311. size    ds.w    1
  312. dtabuff    ds.l    1
  313. filebuffer    ds.l    1
  314.     ds.l    99
  315. stack    ds.l    1
  316. end
  317.  
  318.