home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / TPS_MAG / TPS_MAG.MSA / PROGRAMS / CHUNK.S next >
Text File  |  2010-04-21  |  24KB  |  963 lines

  1.         opt c+,d-,o+
  2. **********************************************************
  3. ** ultraload/megaload/whatever its called now        **
  4. ** is a product of Dackco Industries. Instructions    **
  5. ** for use are included right at the end of the        **
  6. ** code.                        **
  7. **********************************************************
  8.  
  9. ** fixed 10/2/90 for standard file create bug
  10. ** fixed 16/2/90 for FDUP  (who uses this???)
  11. ** fixed 19/2/90 for standard handles
  12. ** fixed 19/2/90 for F_FORCE (what???)
  13. ** fixed 21/2/90 for non bufferd reads
  14. ** fixed 21/2/90 for correct handling of PRN: etc
  15. ** fixed 25/2/90 for buggy version of FDUP as used by AUTOROUTE
  16. ** fixed 25/2/90 for closing already closed file
  17. ** fixed 22/4/90 for repeated opening and closing of same buffered
  18. **          file
  19. ** fixed 22/4/90 for opening of standard handled file
  20. ** major upgrade 28/5/90-31/5/90 for EGBs chunk packer
  21. ** (hard bit is mine though!!!)
  22.  
  23. buff_len    equ    17000        ;set higher than chunk size
  24. maxfiles    equ    32
  25. buffdhead    equ    "LSD$"
  26. normlhead    equ    "LSD!"
  27. chnkhead    equ    "LSDC"
  28.  
  29.     bra    main
  30.  
  31. gam        dc.b "filename.egb",0
  32.         even
  33.  
  34. text    DC.B 27,"E",27,"f",27,"w"
  35.     dc.b "Automation",13,10
  36.     dc.b "present BAD CAT",13,10
  37.     dc.b "though it should be called trash-cat"
  38.     DC.B 00,00
  39.  
  40.     EVEN
  41.  
  42.     
  43. main    MOVEA.L    4(A7),A5
  44.     move.l $c(a5),d0
  45.     add.l $14(a5),d0
  46.     add.l $1c(a5),d0
  47.     add.l #$200,d0
  48.     add.l #buff_len,d0    ;add buffer length
  49.                 ;take out if absolute address
  50.                 ;buffer
  51.  
  52.     move.l d0,-(sp)
  53.     move.l a5,-(sp)
  54.     move.l #$4a0000,-(sp)
  55.     trap #1            ;mshrink
  56.     lea $c(a7),a7
  57.  
  58.     dc.w    $a00a
  59.     pea    text
  60.     move.w    #9,-(a7)
  61.     trap    #1        ;text print
  62.     addq.l    #6,a7
  63.     dc.w    $a009
  64.  
  65.     move.w    #7,-(a7)
  66.     trap    #1        ;wait for key
  67.     addq.l    #2,a7
  68.  
  69.     move.l    #buff_start,buff_add    ;set buffer start address
  70.                     ;change buff_start to absolute
  71.                     ;address if needed
  72.  
  73. CHEAT    CLR.L    -(A7)
  74.     MOVE.W    #$20,-(A7)
  75.     TRAP    #$01            ;supervisor
  76.     ADDQ.L    #6,A7
  77.     LEA    SUPERLNG(PC),A6
  78.     MOVE.L    D0,(A6)            ;save old stack address
  79.     MOVE.L    $84,tr1            ;save old trap1 address
  80.     MOVE.L    #T1,$84            ;set trap1 to my code
  81.     MOVE.L    SUPERLNG(PC),-(A7)
  82.     MOVE.W    #$20,-(A7)
  83.     TRAP    #$01            ;usermode
  84.     ADDQ.L    #6,A7
  85. stkk    clr.l    in_use            ;so first read gets file
  86.     clr.l     $60000
  87.     pea     $60000
  88.     pea    $60000
  89.     move.l     #gam,-(sp)
  90.     move.l     #$4b0000,-(sp)
  91.     trap     #1            ;run next program
  92.     lea 16(a7),a7
  93.     clr.w     -(sp)
  94.     trap     #1            ;back to desktop
  95.  
  96.  
  97. ;multi file read 1st October 1989
  98. ;fix 11th October 1989 for decode from odd address
  99. ;bastard bug to find
  100.  
  101. T1        tst.w    inside        ;check if called from inside trap1
  102.         bne    bye        ;yes then exit
  103.         MOVEM.L A0-A6/d0-d7,reg    
  104.         movea.l    a7,a1
  105.         addq.l     #6,a1
  106.         move.w     (a7),d0
  107.         btst     #$d,d0        ;check for which stack data
  108.         bne.s     ok1        ;is in. if no then its in super
  109.         move.l     usp,a1        ;else its the user stack
  110. ok1        cmpi.w     #$3d,(a1)    ;file open
  111.         beq    openup
  112.         cmpi.w    #$3f,(a1)    ;file read
  113.         beq    read
  114.         cmpi.w    #$3e,(a1)    ;file close
  115.         beq    close
  116.         cmpi.w    #$3c,(a1)    ;file create
  117.         beq    create
  118.         cmpi.w    #$40,(a1)    ;file write
  119.         beq    write
  120.         cmpi.w    #$42,(a1)    ;file seek
  121.         beq    seek
  122.         cmpi.w    #$4e,(a1)    ;f_next
  123.         beq    ffirst
  124.         cmpi.w    #$45,(a1)    ;f_dup
  125.         beq    fdup
  126.         cmpi.w    #$46,(a1)    ;f_force
  127.         beq    fforce
  128.         cmpi.w    #0,(a1)        ;exit
  129.         bne.s    open
  130.         move.l    tr1,$84        ;old trap1 back
  131. open        movem.l     reg(pc),a0-a6/d0-d7
  132. bye        dc.w     $4ef9
  133. tr1        dc.l     $0
  134.  
  135. openup        move.w    #1,inside    ;do normal traps
  136.         lea    f_names,a0
  137.         lea    300(a0),a0
  138.         move.l    #5,d0
  139. s_loop        addq.l    #1,d0
  140.         lea    60(a0),a0
  141.         tst.b    (a0)
  142.         bne.s    s_loop        ;search for empty slot
  143.                     ;i.e. one with first byte
  144.                     ;set to 0
  145.  
  146. ;d0=my pretend file handle
  147.  
  148.         move.l    d0,d7        ;save handle
  149.         move.l    d0,d6        ;ditto
  150.         move.l    a0,a5        ;save location of empty slot
  151.         move.l    2(a1),a6    ;save file name address
  152.  
  153. ;open file
  154.         move.w    6(a1),-(a7)    ;bastard bug for standards
  155.         move.l    a6,-(a7)
  156.         move.w    #$3d,-(a7)
  157.         trap    #1        ;f_open
  158.         addq.l    #8,a7
  159.  
  160.         tst.l    d0
  161.         bmi    error        ;in case file not there
  162.  
  163.         move.l    d0,d4        ;save real handle
  164.  
  165. ** insert 1 for uncom file read
  166.  
  167.         clr.l    i_buff        ;clear buffer
  168.         pea    i_buff
  169.         move.l    #8,-(a7)    ;number of bytes=8
  170.         move.w    d4,-(a7)
  171.         move.w    #$3f,-(a7)
  172.         trap    #1        ;f_read
  173.         lea    12(a7),a7
  174.         clr.w    -(a7)        ;type 0 (absolute)
  175.         move.w    d4,-(a7)    ;file handle
  176.         clr.l    -(a7)        ;start of file
  177.         move.w    #$42,-(a7)
  178.         trap    #1        ;f_seek
  179.         lea    10(a7),a7
  180.  
  181. ;copy filename
  182.         move.l    a6,a4            ;save address of name
  183.         move.l    #59,d0
  184. c_loop        move.b    (a6)+,(a5)+
  185.         dbra    d0,c_loop
  186.  
  187.         lsl.l    #2,d7            ;times4
  188.         lea    so_read,a0
  189.         move.l    #0,(a0,d7.w)        ;clear amount read so far
  190.  
  191.         cmp.l    #buffdhead,i_buff     ;check if file buff/compacted
  192.         beq.s    nermal            ;yes so set up correct handler
  193. stn_file    lea    real_hand,a0        ;start of real handles array
  194.         move.l    d4,(a0,d7.w)        ;save real handle
  195.         lea    chunked,a0
  196.         move.l    #0,(a0,d7.w)        ;show file not chunked
  197.         cmp.l    #chnkhead,i_buff    ;check if file chunked
  198.         bne    not_good
  199.         move.l    #-1,(a0,d7.w)        ;set chunked flag to true
  200.         lea    f_lengths,a0
  201.         move.l    i_len,(a0,d7.w)        ;save file length in array
  202.         bra    chk_same        ;check if same file loaded
  203.  
  204.  
  205. ;copy file name to storage
  206.  
  207. nermal        lea    f_lengths,a0
  208.         move.l    i_len,(a0,d7.w)        ;save file length in array
  209.         lea    real_hand,a0
  210.         move.l    #-1,(a0,d7.w)        ;show handle is fake by setting to -1
  211.         lea    chunked,a0
  212.         move.l    #0,(a0,d7.w)        ;show its not chunked
  213.  
  214. ;close file as finished
  215.  
  216.         move.w    d4,-(a7)
  217.         move.w    #$3e,-(a7)
  218.         trap    #1            ;f_close
  219.         addq.l    #4,a7
  220.  
  221. ;already loaded file check
  222.  
  223. chk_same    lea    file_loaded_name,a5    ;get saved files name
  224. still_same    tst.b    (a4)            ;check if end of new f_name
  225.         beq.s    same_file        ;yes then maybe files same
  226.         cmp.b    (a4)+,(a5)+        ;check name against saved one
  227.         beq.s    still_same        ;same so check next byte
  228.         bra.s    not_good        ;different so dont worry
  229. same_file    tst.b    (a5)            ;check eofname in saved name
  230.         bne.s    not_good        ;different so dont worry
  231.         move.l    d6,in_use        ;same name so save handle
  232.  
  233. not_good    clr.w    inside        ;my traps again
  234.         move.l    d6,-(a7)    ;d6 contains fake file handle
  235.         movem.l    reg,a0-a6/d0-d7
  236.         move.l    (a7)+,d0    ;give back my handle
  237.         rte
  238.  
  239. read        clr.l    d0
  240.         move.w    2(a1),d0    ;get handle
  241.         tst.w    d0
  242.         bmi    stan_f
  243.         move.w    d0,d1
  244.         lsl.l    #2,d1        ;*4
  245.         lea    real_hand,a0
  246.         move.l    (a0,d1.w),d2    ;get real handle
  247.         cmp.w    #$ffff,d2    ;is file compacted?
  248.         beq    cor_blimy    ;yes so buffered read
  249.         lea    chunked,a0
  250.         move.l    (a0,d1.w),d3    ;check if chunked
  251.         tst.l    d3
  252.         bne    sodding_chunk
  253. stan_f        move.w    #1,inside    ;my traps out d window
  254.         move.l    8(a1),d7    ;get whereto
  255.         move.l    d7,-(a7)    ;whereto
  256.         move.l    4(a1),-(a7)    ;number of bytes
  257.         move.w    d2,-(a7)    ;file handle
  258.         move.w    #$3f,-(a7)
  259.         trap    #1        ;f_read
  260.         lea    12(a7),a7
  261.         clr.w    inside        ;my traps again
  262.         move.l    d0,d5        ;save count of bytes read
  263.         move.l    d7,a0        ;whereto
  264.         clr.l    d0
  265.         move.b    (a0),d0
  266.         lsl.w    #8,d0
  267.         move.b    1(a0),d0
  268.         swap    d0
  269.         move.b    2(a0),d0
  270.         lsl.w    #8,d0
  271.         move.b    3(a0),d0    ;gets 4 bytes from a0
  272.         cmp.l    #normlhead,d0    ;check for nonbuff pack
  273.         bne    titter        ;normal file
  274.         lea    -$200(a0),a1    ;destination
  275.         move.l    a1,a2
  276.         lea    tmp_sav,a3
  277.         move.l    #$1ff,d1
  278. firk1        move.b    (a2)+,(a3)+
  279.         dbra    d1,firk1    ;save 200 bytes below
  280. firk2        move.b    (a0)+,(a1)+
  281.         subq.l    #1,d5
  282.         bne.s    firk2        ;copy down
  283.         move.l    a2,a1
  284.         lea    -$200(a1),a0
  285.         move.l    a0,-(a7)    ;save start
  286.         bsr    DEPACK
  287.         move.l    (a7)+,a0
  288.         lea    tmp_sav,a1
  289.         move.l    #$1ff,d1
  290. firk3        move.b    (a1)+,(a0)+
  291.         dbra    d1,firk3    ;copy bytes back
  292.         bra    titter        ;get out
  293.  
  294. cor_blimy    cmp.l    in_use,d0
  295.         beq    all_in
  296.         move.l    a1,a5        ;preserve stack
  297.         move.w    #1,inside    ;normal trap code
  298.         move.l    d0,in_use    ;tell system this file is in use
  299.         mulu    #60,d0        ;d0=d0*60
  300.         lea    f_names,a0
  301.         add.l    d0,a0        ;get correct filename
  302.         move.l    a0,a1        ;preserve value
  303.         lea    file_loaded_name,a2
  304.         move.w    #59,d0
  305. save_name    move.b    (a1)+,(a2)+
  306.         dbra    d0,save_name
  307.  
  308.         clr.w    -(a7)
  309.         move.l    a0,-(a7)
  310.         move.w    #$3d,-(a7)
  311.         trap    #1        ;f_open
  312.         addq.l    #8,a7
  313.         move.w    d0,d6        ;save handle
  314.         move.l    buff_add,-(a7)
  315.         move.l    #buff_len,-(a7)
  316.         move.w    d0,-(a7)
  317.         move.w    #$3f,-(a7)
  318.         trap    #1        ;f_read file into buffer
  319.         lea    12(a7),a7
  320.         move.w    d6,-(a7)
  321.         move.w    #$3e,-(a7)
  322.         trap    #1        ;f_close
  323.         addq.l    #4,a7
  324.         clr.w    inside        ;my traps again
  325.         move.l    buff_add,a0    ;source of depack
  326.         move.l    a0,a1        ;destination of depack
  327.         add.l    #200,a1        ;=source +200
  328.         move.l    4(a0),d7    ;length
  329.         bsr    DEPACK
  330.         move.l    buff_add,a0    ;copy file back 200 bytes
  331.         move.l    a0,a1
  332.         add.l    #200,a1
  333. m2_back        move.b    (a1)+,(a0)+
  334.         subq.l    #1,d7
  335.         bne.s    m2_back
  336. read_in        move.l    a5,a1        ;put stack back in a1
  337. all_in        move.l    4(a1),d0    ;bytes to move
  338.         move.l    d0,d5
  339.         move.l    8(a1),a0    ;whereto
  340.         move.l    in_use,d1
  341.         lsl.l    #2,d1        ;*4
  342.         lea    so_read,a2
  343.         lea    f_lengths,a3
  344.         move.l    (a2,d1.w),d2    ;current offset
  345.         move.l    (a3,d1.w),d3    ;length of this file
  346.         move.l    buff_add,a1    ;get buffer start
  347.         add.l    d2,a1        ;add current offset
  348. do_it        move.b    (a1)+,(a0)+    ;move a byte
  349.         addq.l    #1,d2
  350.         cmp.l    d2,d3        ;check if past end of file
  351.         blt.s    past_end
  352.         subq.l    #1,d0        ;number left to copy -1
  353.         bne.s    do_it        ;have we copied all?
  354.         bra.s    wibble
  355. past_end    move.l    d3,d2        ;if past end then offset=end
  356. wibble        move.l    d2,(a2,d1.w)    ;save new offset
  357.         sub.l    d0,d5        ;get number of bytes read
  358.         bra    titter
  359.  
  360. sodding_chunk    cmp.l    in_use,d0
  361.         beq    all_in2
  362.         move.l    a1,a5        ;preserve stack
  363.         move.w    #1,inside    ;normal trap code
  364.         move.l    d0,in_use    ;tell system this file is in use
  365.         mulu    #60,d0        ;*60
  366.         lea    f_names,a1
  367.         add.l    d0,a1        ;get this files name
  368.         lea    file_loaded_name,a2
  369.         move.w    #59,d0
  370. save_name2    move.b    (a1)+,(a2)+    ;save filename
  371.         dbra    d0,save_name2
  372.         move.l    d2,d7        ;save real handle
  373. *d2=real handle
  374.         clr.w    -(a7)        ;type 0 (absolute)
  375.         move.w    d7,-(a7)    ;file handle
  376.         clr.l    -(a7)        ;start of file
  377.         move.w    #$42,-(a7)
  378.         trap    #1        ;f_seek
  379.         lea    10(a7),a7
  380. *get header
  381.         pea    i_buff
  382.         move.l    #1024,-(a7)
  383.         move.w    d7,-(a7)
  384.         move.w    #$3f,-(a7)
  385.         trap    #1        ;f_read file into buffer
  386.         lea    12(a7),a7
  387.  
  388.  
  389.         move.l    #-1,mini
  390.         move.l    a5,a1        ;restore stack
  391.         move.l    d7,d2        ;restore real handle
  392.         move.l    in_use,d0    ;restore file handle
  393.         move.l    d0,d1
  394.         lsl.l    #2,d1        ;restore 4* handle
  395. all_in2        lea so_read,a0
  396.         move.l    (a0,d1.w),d4    ;get current offset
  397.         move.l    4(a1),d5    ;number of bytes
  398.         move.l    d4,d7
  399.         add.l    d5,d7        ;calculate final offset
  400.         cmp.l    d4,d7        ;check for -ve bytes to read
  401.         blt.s    nicensafe
  402.         lea    f_lengths,a0
  403.         cmp.l    (a0,d1.w),d7    ;check if past end of file
  404.         blt    no_clip
  405. nicensafe    move.l    (a0,d1.w),d7
  406. no_clip        sub.l    d4,d7
  407.         move.l    d7,d5        ;now contains #of bytes to xfer
  408.         move.l    8(a1),a4    ;whereto
  409.         move.l    a4,a5
  410.         add.l    d5,a5        ;end locn
  411.         sub.l    #1,a5
  412.         tst.l    d5
  413.         beq    titter        ;if no bytes to read
  414. startxfer    lea so_read,a0
  415.         move.l    (a0,d1.w),d0    ;get offset
  416.         move.l    d0,d4        ;save it
  417.         move.l    chnksize,d3    ;get chunksize
  418.         subq.l    #1,d3        ;create mask
  419.         and.l    d3,d0        ;perform mod operation on offset
  420.          move.l    d3,d7        ;save mask
  421.         eor.l    #-1,d3        ;change mask for div-mod
  422.         and.l    d3,d4        ;d4 nov contains int(offset/chnksize)*chnksize
  423.         cmp.l    mini,d4        ;check if already loaded chunk
  424.         beq    all_in3        ;yes
  425.         move.l    d4,mini        ;save block i.d.
  426.         movem.l    d0-d7/a0-a6,-(a7);save registers
  427.         move.l    d2,d7        ;save file handle
  428.         move.w    #1,inside    ;my traps
  429.         move.l    chnksize,d6
  430.         divu    d6,d4        ;get correct table offset
  431.         lsl.l    #2,d4
  432.         lea    restofbuff,a0    ;get table
  433.         clr.w    -(a7)        ;type 0 (absolute)
  434.         move.w    d7,-(a7)    ;file handle
  435.         move.l    (a0,d4.w),-(a7)    ;position of chunk
  436.         move.w    #$42,-(a7)
  437.         trap    #1        ;f_seek
  438.         lea    10(a7),a7
  439.  
  440.         move.l    buff_add,-(a7)
  441.         move.l    chnksize,-(a7)
  442.         move.w    d7,-(a7)
  443.         move.w    #$3f,-(a7)
  444.         trap    #1        ;f_read file into buffer
  445.         lea    12(a7),a7
  446.         clr.w    inside        ;my traps again
  447.         move.l    buff_add,a0
  448.         cmp.l    #buffdhead,(a0)    ;check if compacted
  449.         beq.s    squit
  450.         cmp.l    #normlhead,(a0)    ;check buffered
  451.         bne.s    squity
  452.  
  453. squit        move.l    buff_add,a0    ;source of depack
  454.         lea    200(a0),a1    ;=source +200
  455.         move.l    4(a0),d7    ;length
  456.         bsr    DEPACK
  457.         move.l    buff_add,a0    ;copy file back 200 bytes
  458.         lea    200(a0),a1    ;=source +200
  459. m2_back4    move.b    (a1)+,(a0)+
  460.         subq.l    #1,d7
  461.         bne.s    m2_back4
  462.  
  463.  
  464. squity        movem.l    (a7)+,d0-d7/a0-a6;restore regs
  465. all_in3        move.l    buff_add,a0
  466. copy_next_b    move.b    (a0,d0.w),(a4)+    ;copy a byte
  467.         addq.l    #1,d0
  468.         cmp.l    a5,a4        ;reached end    
  469.         bgt.s    christknows
  470.         and.l    d7,d0        ;restrict range 0 to cnhksize-1    
  471.         bne.s    copy_next_b    ;chnk not finished
  472.         add.l    chnksize,d4    ;get next block
  473.         lea    so_read,a0
  474.         move.l    d4,(a0,d1.w)    ;save offset
  475.         bra    startxfer
  476. christknows    add.l    d0,d4        ;final offset
  477.         lea    so_read,a0
  478.         move.l    d4,(a0,d1.w)    ;save offset
  479.  
  480. titter        move.l    d5,-(a7)
  481.         movem.l    reg,a0-a6/d0-d7
  482.         move.l    (a7)+,d0    ;return #bytes read
  483.         rte
  484.  
  485. close        clr.l    d0
  486.         clr.l    d7
  487.         move.w    2(a1),d7    ;get handle
  488.         move.l    d7,d6        ;copy it
  489.         move.l    d7,d5        ;in case its a standard one
  490.         move.l    d7,d4
  491.         lsl.l    #2,d6
  492.         lea    real_hand,a5
  493.         tst.w    d7        ;check if handle negative
  494.         bmi.s    stn_stnt    ;yes so handle it as a standard file
  495.         mulu    #60,d4        ;offset into name array
  496.         lea    f_names,a4
  497.         tst.b    (a4,d4.w)    ;file created/open?
  498.         bne.s    fileisok
  499.         move.l    #$ffffffdb,d0    ;illegal handle error
  500.         bra    out_we_go
  501. fileisok    move.l    (a5,d6.w),d5    ;else get real handle from list
  502.         cmp.l    #-1,d5        ;is file buffered (=-1)
  503.         beq.s    buffallclosed    ;yes so its already closed
  504. stn_stnt    move.w    #1,inside    ;close the file for real
  505.         move.w    d5,-(a7)    ;use either real handle
  506.         move.w    #$3e,-(a7)
  507.         trap    #1        ;f_close
  508.         addq.l    #4,a7
  509.         clr.w    inside        ;my traps again
  510.         tst.l    d0        ;erred?
  511.         bmi.s    out_we_go    ;yes do dont close rest
  512. buffallclosed    tst.w    d7        ;check for STNDRD file
  513.         bmi.s    out_we_go
  514.         cmp.l    in_use,d7    ;closing file currently loaded
  515.         bne.s    lucky
  516.         move.l    #-1,in_use    ;make it invalid
  517. lucky        clr.w    d5        ;check for FDUP on this file
  518.         swap    d5        ;move top bit of REAL_HAND to bottom
  519.         tst.w    d5        ;is it 0 (not FDUPED)
  520.         beq.s    not_duped
  521.         cmp.w    #$ffff,d5    ;is it an unbuffered load?
  522.         beq.s    not_duped
  523.         move.l    d5,(a5,d6.w)    ;its FDUPED so save next handle to use
  524.         bra    out_we_go
  525. not_duped    mulu    #60,d7        ;get offset into name array
  526.         lea    f_names,a5
  527.         move.b    #0,(a5,d7.w)    ;set bytes to 0/shows slot empty
  528. out_we_go    move.l    d0,-(a7)
  529.         movem.l    reg,a0-a6/d0-d7
  530.         move.l    (a7)+,d0    
  531.         rte
  532.  
  533. seek        lea    so_read,a2
  534.         lea    f_lengths,a3
  535.         clr.l    d0
  536.         move.w    6(a1),d0    ;file handle
  537.         lsl.l    #2,d0        ;*4
  538.         clr.l    d1
  539.         move.w    8(a1),d1    ;type of seek
  540.         move.l    2(a1),d2    ;offset
  541.  
  542. com_seek    tst.w    d1        ;type 0?
  543.         bne.s    one_two
  544.  
  545. ;absolute move=type 0
  546.  
  547.         move.l    d2,d3        ;offset = new offset
  548.         bra.s    same_end
  549. one_two        cmp.w    #1,d1
  550.         bne.s    mustbe2
  551.  
  552. ;type 1=from current place
  553.  
  554.         move.l    (a2,d0.w),d3
  555.         add.l    d2,d3        ;add new offset to current
  556.         bra.s    same_end
  557. mustbe2        move.l    (a3,d0.w),d3
  558.         sub.l    d2,d3        ;sub new offset from length
  559.  
  560. ;type 2=from end
  561.  
  562. same_end    move.l    (a3,d0.w),d4    ;get length
  563.         cmp.l    d3,d4
  564.         bgt.s    ok_so_far    ;not past end
  565.         move.l    d4,d3        ;else offset = end
  566. ok_so_far    cmp.l    #0,d3
  567.         bgt.s    still_ok    ;not before start
  568.         clr.l    d3        ;else offset = start
  569. still_ok    move.l    d3,(a2,d0.w)    ;save new offset
  570.         lea    real_hand,a0
  571.         move.l    (a0,d0.w),d4
  572.         cmp.l    #-1,d4        ;check if buffered compacted file
  573.         beq.s    sodit1        ;yes then my routine
  574.         lea    chunked,a0
  575.         move.l    (a0,d0.w),d5    ;get if chunked flag
  576.         tst.l    d5        ;is is chunked
  577.         bne.s    sodit1        ;yes then my routine
  578.         move.w    #1,inside    ;no so have to do it for real
  579.         move.w    d1,-(a7)    ;type
  580.         move.w    d4,-(a7)    ;handle
  581.         move.l    d2,-(a7)    ;offset
  582.         move.w    #$42,-(a7)
  583.         trap    #1        ;f_seek
  584.         lea    10(a7),a7
  585.         move.l    d0,d3        ;save new offset for returning
  586.         clr.w    inside
  587.  
  588. sodit1        move.l    d3,-(a7)
  589.         movem.l    reg,a0-a6/d0-d7
  590.         move.l    (a7)+,d0    ;return new offset
  591.         rte
  592.  
  593. error        clr.w    inside        ;clear traps
  594.         move.l    d0,-(a7)
  595.         movem.l    reg,a0-a6/d0-d7
  596.         move.l    (a7)+,d0    ;return error
  597.         rte    
  598.  
  599. create        move.w    #1,inside    ;do normal traps
  600.         lea    f_names,a0
  601.         add.l    #300,a0
  602.         move.l    #5,d0
  603. sc_loop        addq.l    #1,d0
  604.         add.l    #60,a0
  605.         tst.b    (a0)
  606.         bne.s    sc_loop        ;search for empty slot
  607.                     ;i.e. one with first byte
  608.                     ;set to 0
  609.  
  610. ;d0=my pretend file handle
  611.  
  612.         move.l    d0,d7        ;save it
  613.         move.l    a0,a5        ;save slot start
  614.         move.w    6(a1),-(a7)
  615.         move.l    2(a1),-(a7)
  616.         move.w    #$3c,-(a7)
  617.         trap    #1        ;f_create
  618.         addq.l    #8,a7
  619.  
  620. ;d0=what real handle should be
  621.  
  622.         tst.w    d0
  623.         bmi    no_way_create    ;check for error
  624. dup2        move.b    #"I",(a5)    ;mark slot as used
  625.         lea    real_hand,a0
  626.         move.l    d7,d6        ;preserve my handle
  627.         lsl.l    #2,d7        ;fake *4 = place in array
  628.         move.l    d0,(a0,d7.w)    ;save real handle
  629.         move.l    d6,d0        ;give back my handle
  630.  
  631.  
  632. no_way_create    clr.w    inside
  633.         move.l    d0,-(a7)
  634.         movem.l    reg,a0-a6/d0-d7
  635.         move.l    (a7)+,d0    ;return either my file handle or error
  636.         rte        
  637.  
  638. write        clr.l    d0
  639.         move.w    2(a1),d0    ;get fake handle
  640.         tst.w    d0
  641.         bmi    open
  642.         lsl.l    #2,d0
  643.         lea    real_hand,a0
  644.         move.l    (a0,d0.w),d1    ;get real handle
  645.         move.w    d1,2(a1)    ;change it (assume it has been created!)
  646.         bra    open        ;do normal trap#1
  647.  
  648. ffirst        move.l    2(a1),d5
  649.         move.w    6(a1),d6
  650.         move.w    #1,inside
  651.         move.w    d6,-(a7)
  652.         move.l    d5,-(a7)
  653.         move.w    #$4e,-(a7)
  654.         trap    #1        ;f_first
  655.         addq.l    #8,a7
  656.         tst.w    d0
  657.         bne    exit_route
  658.         move.w    #$2f,-(a7)
  659.         trap    #1        ;get bpb address in d0
  660.         addq.l    #2,a7
  661.         move.l    d0,d7        ;save bpb address
  662.         add.l    #$1e,d0
  663.         clr.w    -(a7)
  664.         move.l    d0,-(a7)
  665.         move.w    #$3d,-(a7)
  666.         trap    #1        ;f_open
  667.         addq.l    #8,a7
  668.         tst.l    d0
  669.         bmi.s    doont
  670.         move.w    d0,d6
  671.         clr.l    tmp_read
  672.         pea    tmp_read
  673.         move.l    #8,-(a7)
  674.         move.w    d0,-(a7)
  675.         move.w    #$3f,-(a7)
  676.         trap    #1        ;read 8 bytes
  677.         lea    12(a7),a7
  678.         move.w    d6,-(a7)
  679.         move.w    #$3e,-(a7)
  680.         trap    #1
  681.         addq.l    #4,a7
  682.         lea    tmp_read,a0
  683.         cmp.l    #buffdhead,(a0)    ;check if compacted
  684.         beq.s    doont1
  685.         cmp.l    #normlhead,(a0)    ;check buffered
  686.         bne.s    doont
  687. doont1        move.l    d7,a1
  688.         move.l    4(a0),26(a1)    ;yes so change length to
  689.                     ;uncompacted length (in case sneaky)
  690. doont        clr.l    d0        ;show file found
  691. exit_route    clr.w    inside
  692.         move.l    d0,-(a7)
  693.         movem.l    reg,a0-a6/d0-d7
  694.         move.l    (a7)+,d0
  695.         rte
  696.  
  697. fdup        move.w    #1,inside    ;do normal traps
  698.         lea    f_names,a0
  699.         add.l    #300,a0
  700.         move.l    #5,d0
  701. sc_loop2    addq.l    #1,d0
  702.         add.l    #60,a0
  703.         tst.b    (a0)
  704.         bne.s    sc_loop2    ;search for empty slot
  705.                     ;i.e. one with first byte
  706.                     ;set to 0
  707.  
  708. ;d0=my pretend file handle
  709.  
  710.         move.l    d0,d7        ;save it
  711.         move.l    a0,a5        ;save slot start
  712.         move.w    2(a1),d5
  713.         move.w    d5,-(a7)
  714.  
  715.         move.w    #$45,-(a7)
  716.         trap    #1        ;f_dup
  717.         addq.l    #4,a7
  718.         tst.w    d0        ;only word test
  719.         bmi    error
  720.         neg.l    d5        ;turns STNDRD name into file handle
  721.         swap    d5        ;move handle into top word
  722.         move.w    d0,d5        ;get FDUP handle
  723.         move.l    d5,d0        ;put both handles into perspective
  724.         bra    dup2        ;same as create code
  725.  
  726. fforce        clr.l    d0
  727.         move.w    4(a1),d0    ;get spook handle
  728.         lea    real_hand,a5
  729.         tst.w    d0
  730.         bmi.s    sod_stan
  731.         lsl.l    #2,d0        ;*4
  732.         move.l    (a5,d0.w),d0    ;get real handle
  733.         move.w    d0,4(a1)    ;change fake handle to real one
  734. sod_stan    clr.l    d1
  735.         move.w    2(a1),d1
  736.         lsl.l    #2,d1
  737.         move.l    d0,(a5,d1.w)    ;save handle in my list
  738.         bra    open        ;do normal trap 1
  739.  
  740. reg        ds.l    16
  741. tmp_read    ds.l    4
  742. crunpos        dc.l 0
  743.  
  744. ;should now be capable of decoding from odd to odd addresses
  745. ;11th October 1989
  746.  
  747. DEPACK        adda.l #4,a0
  748.         move.w $ff8240,-(sp)
  749.         lea    crunpos(pc),a6
  750.         move.l a0,(a6)        ;save crunch position
  751.         move.b (a0)+,d5
  752.         lsl.w     #8,d5
  753.         move.b    (a0)+,d5
  754.         swap    d5
  755.         move.b    (a0)+,d5
  756.         lsl.w    #8,d5
  757.         move.b    (a0)+,d5
  758.         adda.l d5,a1
  759.         move.b    (a0),d0
  760.         lsl.w    #8,d0
  761.         move.b    1(a0),d0
  762.         swap    d0
  763.         move.b    2(a0),d0
  764.         lsl.w    #8,d0
  765.         move.b    3(a0),d0
  766.         adda.l     d0,a0
  767.         subq.l #4,a0
  768.         move.b    -2(a0),d0
  769.         lsl.w    #8,d0
  770.         move.b    -1(a0),d0
  771.         subq.l    #2,a0
  772.         tst.w    d0
  773.         bpl.s L_1
  774.         subq.l #1,a0
  775. L_1        move.b -(a0),d0
  776. L_2        lsl.b #1,d0
  777.         bne.s L_3
  778.         MOVE.B    -(A0),D0
  779.         ROXL.B    #1,D0
  780. L_3        BCC.S    L_10
  781.         CLR.W    D1
  782.         LSL.B    #1,D0
  783.         BNE.S    L_4
  784.         MOVE.B    -(A0),D0
  785.         ROXL.B    #1,D0
  786. L_4        BCC.S    L_9
  787.         LEA    NUMS(PC),A3
  788.         MOVEQ    #3,D3
  789. L_5        CLR.W    D1
  790.         MOVE.B    0(A3,D3.W),D2
  791.         EXT.W    D2
  792.         MOVEQ    #-1,D4
  793.         LSL.W    D2,D4
  794.         NOT.W    D4
  795.         SUBQ.W    #1,D2
  796. L_6        LSL.B    #1,D0
  797.         BNE.S    L_7
  798.         MOVE.B    -(A0),D0
  799.         ROXL.B    #1,D0
  800. L_7        ROXL.W    #1,D1
  801.         DBF    D2,L_6
  802.         TST.W    D3
  803.         BEQ.S    L_8
  804.         CMP.W    D1,D4
  805.         DBNE    D3,L_5
  806. L_8        MOVE.B    4(A3,D3.W),D2
  807.         EXT.W    D2
  808.         ADD.W    D2,D1
  809.         BRA    L_9
  810.  
  811. NUMS        DC.B    $0A,$03,$02,$02,$0E,$07,$04,$01
  812.  
  813. L_9        MOVE.B    -(A0),-(A1)
  814.         eor.w    #$777,$ff8240
  815.         DBF    D1,L_9
  816. L_10        MOVE.L    crunpos(pc),A3        ;get crunch position
  817.         ADDQ.L    #$8,A3
  818.         CMPA.L    A3,A0
  819.         BLE    BYENOW
  820.         LEA    NUMS2(PC),A3
  821.         MOVEQ    #3,D2
  822. L_11        LSL.B    #1,D0
  823.         BNE.S    L_12
  824.         MOVE.B    -(A0),D0
  825.         ROXL.B    #1,D0
  826. L_12        BCC.S    L_13
  827.         DBF    D2,L_11
  828. L_13        CLR.W    D1
  829.         ADDQ.W    #1,D2
  830.         MOVE.B    0(A3,D2.W),D3
  831.         BEQ.S    L_16
  832.         EXT.W    D3
  833.         SUBQ.W    #1,D3
  834. L_14        LSL.B    #1,D0
  835.         BNE.S    L_15
  836.         MOVE.B    -(A0),D0
  837.         ROXL.B    #1,D0
  838. L_15        ROXL.W    #1,D1
  839.         DBF    D3,L_14
  840. L_16        MOVE.B    5(A3,D2.W),D3
  841.         EXT.W    D3
  842.         ADD.W    D3,D1
  843.         BRA    L_161
  844.  
  845. NUMS2        DC.B    $0A,$02,$01,$00,$00,$0A,$06,$04,$03,$02
  846.  
  847. L_161        CMPI.W    #2,D1
  848.         BEQ.S    L_22
  849.         LEA    NUMS3(PC),A3
  850.         MOVEQ    #1,D3
  851. L_17        LSL.B    #1,D0
  852.         BNE.S    L_18
  853.         MOVE.B    -(A0),D0
  854.         ROXL.B    #1,D0
  855. L_18        BCC.S    L_19
  856.         DBF    D3,L_17
  857. L_19        ADDQ.W    #1,D3
  858.         CLR.W    D2
  859.         MOVE.B    0(A3,D3.W),D4
  860.         EXT.W    D4
  861. L_20        LSL.B    #1,D0
  862.         BNE.S    L_21
  863.         MOVE.B    -(A0),D0
  864.         ROXL.B    #1,D0
  865. L_21        ROXL.W    #1,D2
  866.         DBF    D4,L_20
  867.         LSL.W    #1,D3
  868.         ADD.W    4(A3,D3.W),D2
  869.         BRA.S    L_26
  870.  
  871. NUMS3        DC.B    $0B,$04,$07,$00,$01,$20,$00,$00
  872.         DC.B    $00,$20,$00,$00
  873.  
  874. L_22        CLR.W    D2
  875.         MOVEQ    #5,D3
  876.         CLR.W    D4
  877.         LSL.b    #1,D0
  878.         BNE.S    L_23
  879.         MOVE.B    -(A0),D0
  880.         ROXL.B    #1,D0
  881. L_23        BCC.S    L_24
  882.         MOVEQ    #8,D3
  883.         MOVEQ    #$40,D4
  884. L_24        LSL.B    #1,D0
  885.         BNE.S    L_25
  886.         MOVE.B    -(A0),D0
  887.         ROXL.B    #1,D0
  888. L_25        ROXL.W    #1,D2
  889.         DBF    D3,L_24
  890.         ADD.W    D4,D2
  891. L_26        LEA    0(A1,D2.W),A2
  892.         EXT.L    D1
  893.         ADDA.L    D1,A2
  894.         SUBQ.W    #1,D1
  895. L_27        MOVE.B    -(A2),-(A1)
  896.         DBF    D1,L_27
  897.         BRA    L_2
  898. BYENOW        move.w (a7)+,$ff8240
  899.         RTS
  900.  
  901.         section bss
  902.  
  903.         dcb.l    maxfiles,0
  904.  
  905.  
  906. SUPERLNG    ds.L    1
  907. in_use        ds.l    1
  908. inside        ds.w    1
  909. buff_add    ds.l    1
  910. mini        ds.l    1
  911. file_loaded_name ds.b    60
  912. so_read        dcb.l    maxfiles,0
  913. f_lengths    dcb.l    maxfiles,0
  914. f_names        rept    maxfiles
  915.         dcb.b    60,0
  916.         endr
  917. real_hand    dc.l    0,1,2,3,4,5
  918.         dcb.l    maxfiles,0
  919. offsets        dcb.l    maxfiles,0
  920. chunked        dcb.l    maxfiles,0
  921. tmp_sav        ds.b    200
  922. numb_chnk    ds.l    1
  923. i_buff        ds.l    1
  924. i_len        ds.l    1
  925. chnksize    ds.l    1
  926. restofbuff    ds.l    253
  927. buff_start    ds.l    1    ;start of buffer space
  928.  
  929. **********************************************************
  930. ** O.K. Here it is. The low calorie lemon and lime     **
  931. ** flavoured ultraload (tm) with added chunky bits.     **
  932. ** This came about because of Alien and E.G.B.-whoops   **
  933. ** I got them both in the same breath- Alien because of **
  934. ** the slagging off of Autoroute (about to be redone)    **
  935. ** and E.G.B. cos he could be bothered to rewrite the    **
  936. ** packer to chunk pack fuck-off-nasty-size files in an    **
  937. ** interesting and somehow seductive way................**
  938. **                            **
  939. ** Instructions                        **
  940. ** 1)Pack all the files using packer 2.5        **
  941. ** 2)set buff_len=to max size of chunk used (4/8/16k)    **
  942. ** (i.e. 4096,8192,16384)                **
  943. ** 3)if all files can load using offset packing or load **
  944. **   directly then you can set it equal to 0        **
  945. ** 4)set maxfiles =to maxfiles that are open at once+6  **
  946. ** 5)set buffhead etc to the values you've used to pack **
  947. **   the files. Defaults are LSDC for chunked, LSD! for **
  948. **   straight loaders, LSD$ for buffered files.        **
  949. ** 6)change gam=to program name to run            **
  950. ** 7)assemble this damn code. (use GENST2 2.02 as other **
  951. **   versions do not produce correct code.............)    **
  952. **                            **
  953. ** Problems                        **
  954. ** 1)FNEXT is not supported...but it  works anyhow      **
  955. ** 2)Resource file loading is not supported (its TRAP2) **
  956. ** 3)My girlfriend has just left me.................... **
  957. **                            **
  958. ** Updates                        **
  959. ** The next version will have the above problems solved **
  960. ** by next time (except number 3 probably)        **
  961. **                            **
  962. **        DACK (Depressed And Crazy Kid) 1990    **
  963. **********************************************************