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

  1. * This is the source you'll need to run a program with packed data files.
  2. * Obviously this is only going to be of use with programs that use *REAL*
  3. * files - i.e. gemdos accessed ones. Many programs will use files ok, but
  4. * as soon as you pack them all hell will break loose - I won't go into the
  5. * reasons and solutions here, though I may do in a future doc file...
  6. * Remember that this program is just a patch to run another program which
  7. * is your game/loader/whatever - so you'll have to change the filename on
  8. * line 279 of this source.
  9. yes    equ    1
  10. no    equ    0
  11.  
  12. * the following line is important: if you want to run another program as
  13. * mentioned above, then leave it set to 'no'. If, however, you want to
  14. * stick it in an AUTO program and leave it in memory, which could save
  15. * diskspace if you have a lot of programs with packed data files on the
  16. * same disk, then set it to 'yes'.
  17.  
  18. tsr    equ    no
  19.  
  20. * The new improved Auto-depacker...
  21. * For 1.8/1.9/1.9a-y packed files.
  22. * Any program that picks up the filesize from the DTA after a SFIRST will
  23. * now get the correct; unpacked; length.
  24.  
  25.     opt    o+,d-,x-
  26.  
  27. start
  28.     ifeq    tsr
  29.     pea    (end-(start-256)).w    save THIS much
  30.     pea    start-256(pc)    from basepage
  31.     pea    $4a0000    m_shrink with null before it
  32.     trap    #1
  33.     lea    12(sp),sp
  34.     endc
  35.     lea    mystack(pc),sp
  36.  
  37.     lea    newvector(pc),a0    patch trap #1 vector
  38.     bsr.s    supexec
  39.  
  40.     ifeq    tsr
  41.     pea    envcom(pc)
  42.     move.l    (sp),-(sp)
  43.     pea    filename(pc)
  44.     pea    $4b0000
  45.     trap    #1
  46.     lea    16(sp),sp
  47.     lea    oldvector(pc),a0
  48.     bsr.s    supexec
  49.     clr.w    -(sp)
  50.     elseif
  51.     clr.w    -(sp)
  52.     pea    (end-(start-256)).w
  53.     move.w    #$31,-(sp)
  54.     endc
  55.     trap    #1
  56.  
  57. supexec    pea    (a0)
  58.     move.w    #38,-(sp)    run a routine in supervisor mode
  59.     trap    #14
  60.     addq.l    #6,sp
  61.     rts
  62.     
  63. newvector    move.l    $84.w,oldtrap1+2
  64.     move.l    #newtrap1,$84.w
  65.     rts
  66.  
  67. oldvector    move.l    oldtrap1+2(pc),$84.w
  68.     move.b    #7,$484.w
  69.     rts
  70.  
  71. * this is where TRAP #1 goes now...
  72.  
  73. newtrap1    move.l    a0,save_a0
  74.     btst    #5,(sp)        super mode bit set?
  75.     bne.s    super
  76.     move.l    usp,a0        user stack pointer
  77.     bra.s    user
  78.  
  79. super    lea    6(sp),a0        SSP plus return addr.l and SR.w
  80.  
  81. user    tst.w    intrap1
  82.     bne.s    dotrap
  83.     cmp.w    #$3f,(a0)        f_read?
  84.     beq.s    fread
  85.     cmp.w    #$4e,(a0)
  86.     bne.s    dotrap
  87.     move.l    2(a0),a0
  88.     cmp.b    #'.',(a0)
  89.     beq.s    dotrap
  90.     move.l    a0,sfirstfile+2
  91.     move.l    2(sp),return+2
  92.     move.l    #resize,2(sp)
  93.     bra.s    dotrap
  94.  
  95. fread    move.l    8(a0),loadto+2    save file read address
  96.     move.l    2(sp),return+2    save return addr
  97.     move.l    #depack,2(sp)    replace return addr
  98. dotrap    move.l    save_a0(pc),a0
  99. oldtrap1    jmp    0.l    becomes JMP <old trap #1 vector>
  100.  
  101.  
  102. resize    movem.l    d0-d7/a0-a6,regs
  103.     move.l    d0,rsize+2
  104.     move.w    #$2f,-(sp)        get DTA
  105.     trap    #1
  106.     addq.l    #2,sp
  107.     move.l    d0,a6
  108.     clr.w    -(sp)
  109. sfirstfile    pea    0.l        open the searched file
  110.     move.w    #$3d,-(sp)
  111.     trap    #1
  112.     addq.l    #8,sp
  113.     move.w    #2,-(sp)        from the end of the
  114.     move.w    d0,-(sp)        file...
  115.     move.w    d0,d7
  116.     pea    -8.w        -8 bytes
  117.     move.w    #$42,-(sp)
  118.     trap    #1
  119.     lea    10(sp),sp
  120.     pea    sizebuff(pc)
  121.     pea    8.w
  122.     move.w    d7,-(sp)
  123.     move.w    #$3f,-(sp)
  124.     st    intrap1
  125.     trap    #1
  126.     sf    intrap1
  127.     lea    12(sp),sp
  128.     move.w    d7,-(sp)
  129.     move.w    #$3e,-(sp)
  130.     trap    #1
  131.     addq.l    #4,sp
  132.     cmp.l    #'POPI',sizebuff+4
  133.     bne.s    return2
  134.     move.l    sizebuff(pc),26(a6)
  135.     bra.s    return2
  136.  
  137. depack    tst.w    2(sp)            error reading file?
  138.     bmi.s    return
  139.     movem.l    d0-d7/a0-a6,regs
  140. loadto    move.l    #0,a3
  141.     move.l    d0,rsize+2        Save it incase it aint ours.
  142.     add.l    d0,a3
  143.     move.l    a3,a0
  144.     move.l    a3,d7
  145.     and.l    #1,d7
  146.     tst.b    d7
  147.     bne.s    return2
  148.  
  149.     cmp.l    #'POPI',-(a3)
  150.     bne.s    return2
  151.     move.l    -(a3),rsize+2        Now save real program size.
  152.     movem.l    d1-d7/a0-a6,-(sp)
  153.     move.l    a0,unpack+2
  154.     lea    unpack(pc),a0
  155.     bsr    supexec
  156.     movem.l    (sp)+,d1-d7/a0-a6
  157. return2    movem.l    regs(pc),d0-d7/a0-a6
  158. rsize    move.l    #$f0000000,d0
  159. return    jmp    0.l            back to whatever used f_read
  160.  
  161. * the new value for d0 is because some program might check the number of
  162. * bytes read. d0 becomes the length of the UNPACKED file, not the number
  163. * of bytes actually read.
  164.  
  165. unpack    lea    0.l,a0
  166.  
  167.     move.l    a0,a3
  168.     lea    -12(a0),a0
  169.     sub.l    (a0),a3
  170.     move.l    a3,a2
  171.     add.l    4(a0),a2
  172.     lea    $ffff8240.w,a4
  173.  
  174.     MOVE.W    (A4),D5
  175. L76EF0    MOVE.B    -(A0),D0
  176.     BEQ.S    L76EF0
  177. L76EF4    MOVEQ    #0,D2
  178.     BSR.s    L76F78
  179.     BCS.S    L76F0E
  180.     MOVE.B    -(A0),D2
  181. L76EFE    MOVE.B    D2,-(A2)
  182.     BRA.S    L76F38
  183. L76F02    MOVEQ    #$F,D4
  184.     MOVEQ    #2,D3
  185.     BSR.s    L76F84
  186.     BNE.s    L76F6C
  187.     MOVE.W    D4,D2
  188.     BRA.S    L76EFE
  189. L76F0E    BSR.s    L76F78
  190.     BCC.S    L76F48
  191. L76F12    BSR.s    L76F78
  192.     BCC.S    L76F02
  193.     BSR.S    L76F78
  194.     BCS.S    L76F28
  195.     MOVEQ    #2,D1
  196.     BSR    L76FA6
  197.     EXG    D1,D2
  198.     ADDQ.W    #1,D2
  199.     BSET    D1,D2
  200.     BRA.S    L76EFE
  201. L76F28    BSR.S    L76F78
  202.     BCC.S    L76F44
  203.     MOVEQ    #$F,D4
  204.     MOVE.W    #3,D3
  205.     BSR.S    L76F84
  206.     BNE.S    L76F6C
  207.     MOVE.B    (A2),-(A2)
  208. L76F38    move.w    d2,(a4)
  209.     MOVE.W    D5,(a4)
  210.     CMPA.L    A2,A3
  211.     BLT.S    L76EF4
  212.     rts            run the code
  213.  
  214.  
  215. L76F44    MOVEQ    #4,D3
  216.     BRA.S    L76F6A
  217. L76F48    BSR.S    L76F78
  218. L76F4A    BCS.S    L76FC0
  219.     MOVEQ    #1,D1
  220. L76F4E    LSR.B    #1,D0
  221.     BNE.S    L76F56
  222.     MOVE.B    -(A0),D0
  223.     ROXR.B    #1,D0
  224. L76F56    ADDX.W    D2,D2
  225.     DBF    D1,L76F4E
  226.     MOVE.W    D2,D1
  227.     BEQ.S    L76FB8
  228.     ADDQ.W    #1,D1
  229.     ADD.W    D1,D1
  230.     SUBQ.W    #1,D1
  231.     BSR.S    L76FA6
  232.     MOVE.W    D2,D3
  233. L76F6A    BSR.S    L76F82
  234. L76F6C    MOVEA.L    A2,A1
  235.     ADDA.L    D2,A1
  236. L76F70    MOVE.B    -(A1),-(A2)
  237.     DBF    D3,L76F70
  238.     BRA.S    L76F38
  239. L76F78    LSR.B    #1,D0
  240.     BNE.S    L76F80
  241. L76F7C    MOVE.B    -(A0),D0
  242.     ROXR.B    #1,D0
  243. L76F80    RTS
  244. L76F82    MOVEQ    #0,D4
  245. L76F84    MOVEQ    #1,D1
  246.     MOVEQ    #0,D2
  247. L76F88    LSR.B    #1,D0
  248.     BNE.S    L76F90
  249.     MOVE.B    -(A0),D0
  250.     ROXR.B    #1,D0
  251. L76F90    ADDX.W    D2,D2
  252.     DBF    D1,L76F88
  253.     MOVE.W    D2,D1
  254.     ADDQ.W    #1,D1
  255.     LSL.W    #2,D1
  256.     SUBQ.W    #1,D1
  257.     EOR.B    D1,D4
  258.     BNE.S    L76FA6
  259.     RTS
  260.     MOVEQ    #7,D1
  261. L76FA6    MOVEQ    #0,D2
  262. L76FA8    LSR.B    #1,D0
  263.     BNE.S    L76FB0
  264.     MOVE.B    -(A0),D0
  265. L76FAE    ROXR.B    #1,D0
  266. L76FB0    ADDX.W    D2,D2
  267.     DBF    D1,L76FA8
  268.     RTS
  269. L76FB8    BSR.S    L76F82
  270.     MOVE.W    D2,D3
  271.     MOVEQ    #1,D2
  272.     BRA.S    L76F6C
  273. L76FC0    MOVEQ    #1,D3
  274.     MOVE.B    -(A0),D2
  275.     BRA.S    L76F6C
  276. *******************************************************
  277.     data
  278.     ifeq    tsr
  279. filename    dc.b    "PROGRAM.EXE",0
  280.     endc
  281.     bss
  282. regs    ds.l    15
  283. save_a0    ds.l    1
  284. envcom    ds.l    1
  285. sizebuff    ds.l    2
  286. intrap1    ds.w    1
  287.     ds.w    127
  288. mystack    ds.w    1
  289. end