home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_06 / PP82.ZIP / PP82.MSA / POMPEY / EXECHEAD.S < prev    next >
Text File  |  1991-05-24  |  6KB  |  276 lines

  1. no    equ    0
  2. yes    equ    1
  3.  
  4. * EXEC HEADER FOR EXEC FILES PACKED WITH POMPEY PACKER 1.9a
  5. * If you do not wish to pack program files as EXEC files within the packer,
  6. * or wish to do something more than print a message while the program
  7. * depacks, an alternative is to pack your program file as a DATA file,
  8. * and then INCBIN it in this source - see the last line.
  9. * Goto line 253 of this source for a good place to put modifications.
  10. * You can customise this exec header by setting the values below to YES or
  11. * NO. 'lowresonly' will correctly justify the 'POMPEY PACKER V1.9a' text if
  12. * it is set to NO, if set to yes, it will just print in the middle of the
  13. * screen on low res, but will be incorrectly justified in med/high res.
  14. * 'printheading' will print the "POMPEY PACKER V1.9a' text if set to YES.
  15. * 'okrobnorthen' will work with Rob Northen protection if set to YES; if
  16. * set to NO it will lock up if protected with RN protection, but will save
  17. * a few bytes. Preserveregs will preserve all registers if set to YES; but
  18. * currently uses the base page's command line area to save them in...
  19. * Clearbss can be turned off using NO to save a couple of bytes if your
  20. * packed program has no BSS area.
  21.  
  22. lowresonly    equ    yes
  23. printheading    equ    yes
  24. okrobnorthen    equ    no
  25. preserveregs    equ    no
  26. clearbss    equ    yes
  27.  
  28. start
  29.     ifne    preserveregs
  30.     movem.l    d0-d7/a0-a6,start-128
  31.     endc
  32.     move.l    4(sp),a5        base page address
  33.     clr.l    -(sp)
  34.     move.w    #$20,-(sp)
  35.     trap    #1
  36.     move.l    d0,2(sp)
  37.  
  38.     ifne    printheading
  39.     ifeq    lowresonly
  40.     move.w    #4,-(sp)        change x co-or of
  41.     trap    #14        text if in medium
  42.     addq.l    #2,sp        or high res
  43.     tst.w    d0
  44.     beq.s    low
  45.     lea    x(pc),a0
  46.     add.b    #20,(a0)
  47.     endc
  48. low    pea    text(pc)
  49.     move.w    #9,-(sp)
  50.     trap    #1
  51.     addq.l    #6,sp
  52.     endc
  53.  
  54.     ifne    okrobnorthen
  55.     lea    endoffile,a4
  56.     endc
  57.  
  58.     move.l    a4,a0
  59. depack    movea.l    a0,a3            Start of packed file 
  60.     lea    -12(a0),a0
  61.     sub.l    (a0),a3            sub the packedsize.
  62.     movea.l    a3,a2
  63.     add.l    4(a0),a2
  64.     lea    $ffff8240.w,a4
  65.     move.w    (a4),d5            Save color
  66.  
  67. empty    move.b    -(a0),d0        Unpack data.
  68.     beq.s    empty            Not empty.
  69. umain    moveq    #0,d2
  70.     bsr    shifter
  71.     bcs.s    rep
  72.  
  73.     move.b    -(a0),d2
  74. output    move.b    d2,-(a2)
  75.     bra.s    ecxit
  76.  
  77. rep3    moveq    #15,d4            16bit in-operative.
  78.     moveq    #2,d3
  79.     bsr.s    leader
  80.     bne.s    rloop
  81.     move.w    d4,d2
  82.     bra.s    output
  83.         
  84. rep    bsr.s    shifter
  85.     bcc.s    repeat
  86.     bsr.s    shifter
  87.     bcc.s    rep3
  88.     bsr.s    shifter
  89.     bcs.s    rep4
  90. special    moveq    #2,d1
  91.     bsr    nibit
  92.     exg    d1,d2
  93.     addq.w    #1,d2
  94.     bset    d1,d2
  95.     bra.s    output
  96.     
  97. rep4    bsr.s    shifter
  98.     bcc.s    rep5            V1.7 incompatability
  99.     moveq    #15,d4            16bit in-operative.
  100.     move.w    #3,d3
  101.     bsr.s    leader
  102.     bne.s    rloop
  103.     move.b    (a2),-(a2)
  104.  
  105. ecxit    move.w    d2,(a4)
  106.     move.w    d5,(a4)
  107.     cmpa.l    a2,a3
  108.     blt.s    umain
  109.     bra    sort_it_out
  110.  
  111. rep5    moveq    #4,d3
  112.     bra.s    reps
  113.  
  114. ; **    Offset bitsize is x bits depending upon D2.
  115. ; **    Also serves to reproduce RUNS , because an offset of 1 = same
  116. ; **    character repeated D3 times.
  117.  
  118. repeat    bsr.s    shifter
  119.     bcs.s    rep2
  120.     moveq    #1,d1
  121. .1    lsr.b    #1,d0
  122.     bne.s    .2
  123.     move.b    -(a0),d0
  124.     roxr.b    #1,d0
  125. .2    addx.w    d2,d2
  126.     dbf    d1,.1
  127.     
  128.     move.w    d2,d1            Copy bitcount
  129.     beq.s    runing            If ZERO then do RUNS
  130.     addq.w    #1,d1
  131.     add.w    d1,d1
  132.     subq.w    #1,d1
  133.     bsr.s    nibit
  134.     move.w    d2,d3
  135. reps    bsr.s    lead1            Get offset size.
  136. rloop    movea.l    a2,a1
  137.     add.l    d2,a1            Add the offset.
  138. replp    move.b    -(a1),-(a2)
  139.     dbf    d3,replp
  140.     bra.s    ecxit
  141.  
  142. shifter    lsr.b    #1,d0
  143.     bne.s    noz
  144.     move.b    -(a0),d0
  145.     roxr.b    #1,d0
  146. noz    rts
  147.  
  148. ; **    Collect 2bit leader into D1
  149. ; **    Algorithm :- 2bits + 1 (1 to 4) * 4.
  150. ; **    Return the BITS in D2.
  151.  
  152. lead1    moveq    #0,d4            16bits operative.
  153. leader    moveq    #1,d1
  154.  
  155.     moveq    #0,d2
  156. n1    lsr.b    #1,d0
  157.     bne.s    n2
  158.     move.b    -(a0),d0
  159.     roxr.b    #1,d0
  160. n2    addx.w    d2,d2
  161.     dbf    d1,n1
  162.  
  163.     move.w    d2,d1
  164.     addq.w    #1,d1
  165.     lsl.w    #2,d1
  166.     subq.w    #1,d1
  167.     eor.b    d1,d4
  168.     bne.s    nibit
  169.     rts    
  170. nibs    moveq    #7,d1
  171. nibit    moveq    #0,d2
  172. nlp    lsr.b    #1,d0
  173.     bne.s    nlp1
  174.     move.b    -(a0),d0
  175.     roxr.b    #1,d0
  176. nlp1    addx.w    d2,d2
  177.     dbf    d1,nlp
  178.     rts
  179. runing    bsr.s    lead1            16bits operative
  180.     move.w    d2,d3
  181.     moveq    #1,d2
  182.     bra.s    rloop
  183. rep2    moveq    #1,d3            Size of loop.
  184.     move.b    -(a0),d2
  185.     bra.s    rloop
  186.  
  187. sort_it_out    trap    #1
  188.     addq.l    #6,sp
  189. * a3 is already pointing to start of depacked program
  190.     move.l    2(a3),a0        text segment
  191.     add.l    6(a3),a0        + data segment
  192.     add.l    14(a3),a0        + symbol table
  193.     lea    28(a0),a0        + header
  194.     add.l    a3,a0        + start of program
  195. * a0 now points to relocation table
  196.     move.l    8(a5),d0        d0 points to TEXT
  197.     lea    28(a3),a3        a3 points to program
  198.     move.l    a3,a6
  199.     tst.l    (a0)        zero 1st relocation?
  200.     beq.s    done_reloc
  201.  
  202.     moveq    #0,d1
  203.     add.l    (a0)+,a3        + offset
  204. relocate    add.l    d0,(a3)        relocate it
  205. add_no_reloc    move.b    (a0)+,d1        next byte
  206.     beq.s    done_reloc        zero is end
  207.     cmp.b    #1,d1        1 is add 254, but
  208.     bne.s    not1        don't relocate
  209.     lea    254(a3),a3
  210.     bra.s    add_no_reloc
  211. not1    add.l    d1,a3        + offset
  212.     bra.s    relocate
  213.  
  214. done_reloc    lea    packedfile+2(pc),a2    past $601a
  215.     move.l    (a2),12(a5)        write real TEXT len
  216.     add.l    (a2),d0        TEXT len + TEXT addr
  217.     move.l    d0,16(a5)        write real DATA addr
  218.     move.l    4(a2),20(a5)        write real DATA len
  219.     add.l    4(a2),d0        + DATA len
  220.     move.l    d0,24(a5)        write real BSS addr
  221.     move.l    8(a2),28(a5)        write real BSS len
  222.  
  223. * now move code somewhere safe
  224.     move.l    sp,a0
  225.     lea    -256(a0),a0
  226.     pea    (a0)
  227.     lea    mover(pc),a1
  228.     moveq    #(endofmover-mover)/2-1,d0
  229. copy_mover    move.w    (a1)+,(a0)+
  230.     dbf    d0,copy_mover
  231.     rts
  232.  
  233. * move the program down to the correct address
  234. mover    move.l    12(a5),d0        TEXT len
  235.     add.l    20(a5),d0        + DATA len
  236.     lsr.l    #1,d0        divide by 2
  237.     addq.l    #1,d0        one for luck
  238.     move.l    8(a5),a4        pointer to TEXT addr
  239.     pea    (a4)        run address
  240. copydown    move.w    (a6)+,(a4)+
  241.     subq.l    #1,d0
  242.     bne.s    copydown
  243.     ifne    clearbss
  244. * clear the BSS
  245.     move.l    28(a5),d1
  246.     add.l    #(packedfile-start)+28,d1
  247.     lsr.l    #2,d1        bug fixed...!
  248.     addq.l    #1,d1
  249. clrbss    move.l    d0,(a4)+
  250.     subq.l    #1,d1
  251.     bne.s    clrbss
  252.     endc
  253. * if you wish to modify part of your program file, but don't wish to repack
  254. * it, you can put a piece of code like this at this point:
  255. *    move.l    8(a5),a5    a5 now points to TEXT area of prog.
  256. * now you can carry out modifications off (a5), etc. such as:
  257. *    move.w    #$4e71,20(a5)
  258. * or whatever you want!
  259.     ifne    preserveregs
  260.     movem.l    start-128,d0-d7/a0-a6
  261.     movem.l    d0-d7/a0-a6,-(sp)
  262.     lea    start-128,a0
  263.     moveq    #15-1,d0
  264. clregs    clr.l    (a0)+
  265.     dbf    d0,clregs
  266.     movem.l    (sp)+,d0-d7/a0-a6
  267.     endc
  268.     rts            run the program
  269. endofmover
  270.     ifne    printheading
  271. text    dc.b    27,"E",27,"Y",32
  272. x    dc.b    43,"POMPEY PACKER V1.9y",0
  273.     endc
  274. * the packed exec file goes here
  275. packedfile    incbin    "f:\test"
  276. endoffile