;START
                    OPT     D+

* -            ByteKiller cruncher written by Lord Blitter             - *
* -                 and improved by Cath of Fury 1992                  - *

* -                     Equates and defines needed                     - *

LF                  equ     10
ESC                 equ     $1B
color0              equ     $00000180
_custom             equ     $00dff000
Relative            equ     1   ; set this and code will be pc-relative,ha ha
_LVOFlush           equ     -360

* -                               Macros                               - *

Write               macro
                    movem.l d0-d7/a0-a6,-(sp)
                    move.l  #\1,d2
                    move.l  #l_\1,d3                 ; length of message
                    jsr     _Write(pc)
                    movem.l (sp)+,d0-d7/a0-a6
                    endm

length              macro
l_\1                equ     *-\1
                    even
                    endm

ptr                 macro
                    dc.l   \1
                    dc.w   l_\1
                    endm

Found               macro
                    move.l  #\1,d2
                    move.l  #l_\1,d3
                    bra     KnownType
                    endm

* -                         Code starts here                           - *

                    section cruncher,code

                    lea     DosLibName,a1
                    CALLEXEC OldOpenLibrary            ; open dos.library
                    move.l  d0,DosBase
                    beq.s   QuitOnError

                    bra.s   StartOfProgram             ; jump to program
 
QuitOnError         clr.l   _custom+color0             ; Bye bye
                    moveq.l #-1,d0
                    rts     
_Write 
                    move.l  InitOutput,d1
                    CALLDOS Write
                    rts

StartOfProgram
                    CALLDOS Output                      ; get output handle
                    move.l  d0,InitOutput
                    CALLDOS Input                       ; get input handle
                    move.l  d0,InitInput

                    Write StartupText

                    Write FreeChipMem

                    move.l   #MEMF_CHIP|MEMF_LARGEST,d1 ; Get largest available
                    CALLEXEC AvailMem                   ; chip memory size
                    divu     #1024,d0                   ; convert from  K to MB
                    and.l    #$0000ffff,d0
                    bsr      NumberToString
                    Write    FreeFastMem

                    move.l   #MEMF_FAST|MEMF_LARGEST,d1 ; Get largest available
                    CALLEXEC AvailMem                   ; fast memory size
                    divu     #1024,d0                   ; convert from K To MB
                    and.l    #$0000ffff,d0
                    bsr      NumberToString

InputWorkSpace
                    Write   AllocateWork

                    bsr     WipeBuffer                  ; Clr input buffer

                    moveq.l #4,d3                       ; 4 bytes + 1 for LF
                    bsr     ReadIn                      ; Read in from stdin
                    cmp.l   #1,d0
                    bls.s   InputWorkSpace
 
                    subq.l  #1,d0                       ; length of string
                    move.l  #Buffer,a0                  ; ptr to buffer
                    add.l   d0,a0                       ; ptr to end of string
                    move.b  -(a0),d1                    ; fetch char
                    subq.l  #1,d0                       ; sub length of string
                    bsr     StringToNum
                    cmp.b   #10,d1
                    bcc.s   InputWorkSpace
 
                    moveq.l #0,d2
                    move.b  d1,d2
                    tst.b   d0
                    beq.s   lbC00010A
 
                    move.b  -(a0),d1
                    subq.l  #1,d0
                    bsr     StringToNum
                    cmp.b   #10,d1
                    bcc.s   InputWorkSpace
 
                    and.w   #15,d1
                    mulu    #10,d1
                    add.w   d1,d2
                    tst.b   d0
                    beq.s   lbC00010A
 
                    move.b  -(a0),d1
                    bsr     StringToNum
                    cmp.b   #10,d1
                    bcc     InputWorkSpace
 
                    and.w   #15,d1
                    mulu    #100,d1
                    add.w   d1,d2
                    tst.w   d2
                    beq     InputWorkSpace
 
lbC00010A           moveq.l #0,d0
                    subq.w  #1,d2
lbC00010E           add.l   #$00000400,d0
                    dbra    d2,lbC00010E
 
                    move.l   d0,LengthToAlloc
                    move.l   #MEMF_PUBLIC|MEMF_CLEAR,d1
                    move.l   LengthToAlloc,d0
                    CALLEXEC AllocMem
                    move.l   d0,AllocMem
                    beq      InputWorkSpace
 
                    add.l    #$00000080,d0
                    move.l   d0,FileBuffer
ReadFileName
                    Write    LoadName
 
                    moveq.l  #$1E,d3                       ; Length
                    bsr      ReadIn
                    cmp.l    #1,d0
                    bls.s    ReadFileName
 
                    subq.l   #1,d0
                    lea      Buffer,a0
                    add.l    d0,a0
                    clr.b    (a0)
                    lea      Buffer,a0
                    cmp.b    #'-',(a0)
                    bne.s    NotCliCommand
 
                    addq.l   #1,a0
                    move.l   a0,d1
                    moveq.l  #0,d2
                    move.l   InitOutput,d3
                    CALLDOS  Execute
                    bra.s    ReadFileName
 
NotCliCommand       cmp.l    #'exit',(a0)
                    beq      FreeAndQuit
  
                    move.l   #Buffer,d1
                    move.l   #$000003ED,d2
                    CALLDOS  Open
                    move.l   d0,_OurLock
                    bne.s    FileOpenOk             ; Opened file Ok
                    Write    FileNotFound
                    bra      ReadFileName
FileOpenOk 
                    move.l   _OurLock,d1
                    move.l   FileBuffer,d2
                    move.l   LengthToAlloc,d3
                    sub.l    #$00000080,d3    ; make sure we dont overrun buffer
                    CALLDOS  Read
                    move.l   d0,ActualLength
                    move.l   _OurLock,d1
                    CALLDOS Close

                    move.l   LengthToAlloc,d0
                    sub.l    #$00000080,d0

                    cmp.l    ActualLength,d0
                    bhi      ReadOk           ; Did we read nothing or overrun

                    Write    FileOverrun
                    bra      ReadFileName
ReadOk
                    move.l   FileBuffer,a0
	
; Determine the type of file if possible.

                    cmp.l    #$000003f3,(a0)
                    bne      FileIsNotExec

                    Write    Warning
FileIsNotExec
                    Write    FileTypeIs

                    lea      WhatIs,a1
ContinueSearch
                    clr.l    d0
                    move.w   (a1)+,d0		; fetch offset/control word
                    cmp.w    #-1,d0		; is it end of list
                    beq.s    UnknownType	; branch if so
                    move.l   (a1)+,a2		; fetch Compare longword
                    cmp.w    #-2,d0             ; Is a search150 control
                    beq.s    DoSearch           ; Yup
                    cmp.l    (a0,d0.w),a2	; compare it against file
                    beq.s    FoundMatch		; branch if Matched
NotFound
                    add.l    #6,a1		; next record
                    bra.s    ContinueSearch	; continue
DoSearch
                    move.l   #$150,d0
SearchLoop
                    cmp.l    (a0,d0.w),a2
                    beq.s    FoundMatch
                    sub.w    #2,d0
                    bne.s    SearchLoop
                    bra.s    NotFound                    
FoundMatch
                    move.l   (a1)+,d2		; Fetch ptr to string
                    clr.l    d3
                    move.w   (a1)+,d3		; fetch length of string
                    bra.s    KnownType		; write it out

UnknownType
                    Found    DataAbsFile
KnownType
                    movem.l  d0-d7/a0-a6,-(sp)
                    jsr      _Write(pc)
                    movem.l  (sp)+,d0-d7/a0-a6

AlreadyDeterminedType
                    Write    OriginalLength
                    move.l   ActualLength,d0    ; Number to convert
                    bsr      NumberToString
ReadScanWidth
                    Write    OffsetLength
                    move.l   #OffsetLength,d2
_Length
                    bsr      WipeBuffer
                    moveq.l  #5,d3              ; length to read
                    bsr      ReadIn
                    cmp.l    #1,d0
                    bls.s    ReadScanWidth
 
                    moveq.l  #4,d0
                    bsr      ConvertNumber
                    cmp.w    #$1000,d0          ; Number to low (1.3 machines)
                    ble.s    CheckLowerBound
                    Write    TooHigh
                    bra.s    ReadScanWidth
CheckLowerBound
                    cmp.w    #$5,d0             ; User being funny
                    bhi.s    ScanWidthOk
                    Write    WantLongerFile
                    bra      ReadScanWidth
ScanWidthOk 
                    bclr     #0,d0
                    move.l   d0,ScanWidth

;                   CALLEXEC Forbid
                    bsr      CrunchFile
;                   CALLEXEC Permit

                    move.l   AllocMem,a0
                    move.l   LengthOfPacked,(a0)

                    Write    Won

                    move.l  ActualLength,a1
                    move.l  LengthOfPacked,a2
                    sub.l   a2,a1
                    move.l  a1,d0
                    bsr     NumberToString
 

                  ifne 0
                    move.l  DosBase,a6
                    lea     lbL00077C(pc),a5
                    moveq.l #5,d1
lbC00029A           move.w  (a5)+,d0
                    bsr     lbC00056A
                    dbra    d1,lbC00029A
                  endc


                    Write   PackedLength
                    move.l  LengthOfPacked,d0
                    add.l   #12,d0               ; account for bss
                    bsr     NumberToString       ; write length of packed data
ExecOrDataFile
                    Write   ExecOrData
                    moveq.l #30,d3               ; length to read
                    bsr     ReadIn
                    cmp.l   #1,d0                ; Didn't enter anything
                    bls.s   ExecOrDataFile
 
                    lea     Buffer,a0
                    cmp.b   #'d',(a0)            ; Was a 'd' entered
                    beq     DataFile
 
                    cmp.b   #'e',(a0)            ; was an 'e' entered
                    bne.s   ExecOrDataFile

                    move.l  LengthOfPacked,d0
                    add.l   #292,d0
                    cmp.l   ActualLength,d0
                    blo.s   GetLocateAt
                    Write   FileHeadLonger

GetLocateAt
                    Write   LocateFileAt
                    moveq.l #$1E,d3              ; Length To Read
                    bsr     ReadIn
                    cmp.l   #1,d0
                    bls.s   GetLocateAt
 
                    moveq.l #5,d0                ; length of number to convert
                    bsr     ConvertNumber
                    move.l  d0,LocateAddr
                    move.l  d0,a1
                    jsr     TypeMemRoutine
ReadJumpAddr
                    Write   JumpInAddr
                    moveq.l #30,d3              ; length to read
                    bsr     ReadIn
                    cmp.l   #1,d0
                    bls.s   ReadJumpAddr
 
                    moveq.l #5,d0               ; length of number to convert
                    bsr     ConvertNumber
                    move.l  d0,JumpAddr
                    move.l  d0,a1
                    jsr     TypeMemRoutine

                    move.l  AllocMem,a0
                    add.l   LengthOfPacked,a0
                    add.l   #12,a0              ; add on bss bit
                    move.l  a0,a1
                    add.l   #$0000010C,a1
                    move.l  a1,a2
                    move.l  LengthOfPacked,d0
                    add.l   #12,d0
                    move.l  d0,d1
                    swap    d1
                    bra.s   lbC0003B6
 
lbC0003B4           move.b  -(a0),-(a1)
lbC0003B6           dbra    d0,lbC0003B4
 
                    dbra    d1,lbC0003B4
 
                    lea     Decruncher,a0
                    move.l  AllocMem,a1
                    move.w  #$010B,d0
lbC0003CE           move.b  (a0)+,(a1)+
                    dbra    d0,lbC0003CE
 
                    move.l  a2,d0
                    sub.l   AllocMem,d0
                    sub.l   #$00000024,d0
                    move.l  d0,d1
                    divu    #4,d1
                    swap    d1
                    tst.b   d1
                    beq.s   lbC0003FC
 
                    addq.l  #2,d0
                    move.l  d0,d1
                    divu    #4,d1
                    swap    d1
lbC0003FC
                    swap    d1
                    move.l  AllocMem,a0
                    move.l  d1,Length1(a0)           ; $14
                    move.l  d1,Length2(a0)           ; $20
                    add.l   #$00000024,d0
                    move.l  d0,a2
                    add.l   a0,a2
                    add.l   #$00000018,d0
                    sub.l   #12,d0
                    move.l  d0,LengthOfPacked

                    lea     RelocBSSData,a0
                    move.l  a2,a1
                    moveq.l #LengthBSS,d0
lbC000432           move.b  (a0)+,(a1)+
                    dbra    d0,lbC000432
 
                    move.l  AllocMem,a0
                    move.l  LocateAddr,Reloc1(a0)   ; Fill in LocateAddr (2a)
                    move.l  JumpAddr,Reloc2(a0)     ; Fill in JumpAddr ($d0)
DataFile
                    move.l  LengthOfPacked,d0
                    cmp.l   ActualLength,d0
                    blo.s   SaveFile
                    Write   FileLonger
SaveFile
                    Write   SaveFileName
                    moveq.l #$1E,d3                 ; Length to input
                    bsr     ReadIn
                    cmp.l   #1,d0
                    bls.s   DataFile                ; Re-Read filename
 
                    subq.l  #1,d0
                    lea     Buffer,a0
                    add.l   d0,a0
                    clr.b   (a0)
                    lea     Buffer,a0
                    cmp.b   #'-',(a0)
                    bne.s   IsItExit                ; Is it a command
 
                    addq.l  #1,a0
                    move.l  a0,d1
                    moveq.l #0,d2
                    move.l  InitOutput,d3
                    CALLDOS Execute
                    bra     DataFile
 
IsItExit            cmp.l   #'exit',(a0)
                    beq.s   FreeAndQuit
 
                    move.l  #Buffer,d1              ; FileName
                    move.l  #MODE_NEWFILE,d2        ; File Mode
                    CALLDOS Open
                    move.l  d0,_OurLock
                    move.l  d0,d1
                    move.l  AllocMem,d2         ; Address of crunched data
                    move.l  LengthOfPacked,d3   ; Length of file
                    add.l   #12,d3              ; Add BSS bit
                    CALLDOS Write
                    cmp.l   #-1,d0              ; Was there an error
                    beq     DataFile            ; Yup
 
                    move.l   _OurLock,d1         ; Close output file
                    CALLDOS  Close
FreeAndQuit
                    move.l   LengthToAlloc,d0    ; Free memory
                    move.l   AllocMem,a1
                    CALLEXEC FreeMem
                    move.l   DosBase,a1          ; close dos library
                    CALLEXEC CloseLibrary
                    clr.l    d0
                    rts	                    ; quit
 
ConvertNumber       movem.l  d1-d7/a0-a6,-(sp)
                    move.l   d0,d3
                    clr.l    d0
                    clr.l    d1
                    clr.l    d2
                    lea      Buffer,a0
DoConv              move.b   (a0)+,d1
                    bsr      StringToNum
                    and.w    #15,d1
                    lsl.l    #4,d2
                    or.w     d1,d2
                    cmp.b    #10,(a0)
                    beq.s    lbC00053E
 
                    dbra     d3,DoConv
 
lbC00053E           move.l   d2,d0
                    movem.l  (sp)+,d1-d7/a0-a6
                    rts     
 
StringToNum         movem.l  d0/a0,-(sp)
                    moveq.l  #0,d0
                    lea      ConvertStr,a0
lbC000552           cmp.b    0(a0,d0.l),d1
                    beq.s    lbC000562
 
                    addq.l   #1,d0
                    cmp.l    #$00000010,d0
                    bcs.s    lbC000552
 
lbC000562           move.l   d0,d1
                    movem.l  (sp)+,d0/a0
                    rts     
 
lbC00056A           movem.l  d0-d7/a0-a6,-(sp)
                    lea      Buffer,a0
                    addq.l   #6,a0
                    lea      ConvertStr,a1
                    move.b   #$20,-(a0)
                    moveq.l  #4,d2
lbC000586           move.l   d0,d1
                    and.l    #15,d1
                    move.b   0(a1,d1.l),-(a0)
                    lsr.l    #4,d0
                    dbra     d2,lbC000586
 
                    move.b   #$24,(a0)
                    move.l   InitOutput,d1        ; write out buffer
                    move.l   #Buffer,d2
                    moveq.l  #6,d3                ; length of string
                    CALLDOS  Write
                    movem.l  (sp)+,d0-d7/a0-a6
                    rts     
 
NumberToString      movem.l  d0-d7/a0-a6,-(sp)
                    lea      Buffer,a0
                    add.l    #10,a0
                    lea      ConvertStr,a1
                    move.b   #10,-(a0)
                    moveq.l  #8,d2
lbC0005D0           move.l   d0,d1
                    and.l    #15,d1
                    move.b   0(a1,d1.l),-(a0)
                    lsr.l    #4,d0
                    dbra     d2,lbC0005D0
 
                    move.b   #$24,(a0)
                    move.l   InitOutput,d1       ; write out buffer
                    move.l   #Buffer,d2
                    moveq.l  #10,d3              ; Length of string
                    CALLDOS  Write
                    movem.l  (sp)+,d0-d7/a0-a6
                    rts     
 
CrunchFile          move.l   FileBuffer,a0
                    move.l   FileBuffer,a1
                    add.l    ActualLength,a1
                    move.l   AllocMem,a2
                    move.l   #0,(a2)+
                    move.l   ActualLength,(a2)+
                    move.l   #0,(a2)+
                    moveq.l  #1,d2
                    clr.w    d1
                    clr.l    d7
lbC00062E           bsr.s    lbC000670
                    tst.b    d0
                    beq.s    lbC000640
 
                    addq.w   #1,d1
                    cmp.w    #$0108,d1
                    bne.s    lbC000640
 
                    bsr      lbC000788
lbC000640           cmp.l    a0,a1
                    bgt.s    lbC00062E
 
                    bsr      lbC000788
                    bsr      lbC0007C4
                    move.l   a2,d0
                    sub.l    AllocMem,d0
                    sub.l    #12,d0
                    move.l   d0,LengthOfPacked
                    move.l   AllocMem,a3
                    move.l   d7,8(a3)
                    move.l   d0,(a3)
                    rts     
 
lbC000670           move.l   a0,a3
                    add.l    ScanWidth,a3
                    cmp.l    a1,a3
                    ble.s    lbC00067E
 
                    move.l   a1,a3
lbC00067E           moveq.l  #1,d5
                    move.l   a0,a5
                    addq.w   #1,a5
lbC000684           move.b   (a0),d3
                    move.b   1(a0),d4
lbC00068A           cmp.b    (a5)+,d3
                    bne.s    lbC000692
 
                    cmp.b    (a5),d4
                    beq.s    lbC000698
 
lbC000692           cmp.l    a5,a3
                    bgt.s    lbC00068A
 
                    bra.s    lbC0006F4
 
lbC000698           subq.w   #1,a5
                    move.l   a0,a4
lbC00069C           move.b   (a4)+,d3
                    cmp.b    (a5)+,d3
                    bne.s    lbC0006A6
 
                    cmp.l    a5,a3
                    bgt.s    lbC00069C
 
lbC0006A6           move.l   a4,d3
                    sub.l    a0,d3
                    subq.l   #1,d3
                    cmp.l    d3,d5
                    bge.s    lbC0006F0
 
                    move.l   a5,d4
                    sub.l    a0,d4
                    sub.l    d3,d4
                    subq.w   #1,d4
                    cmp.l    #4,d3
                    ble.s    lbC0006D0
 
                    moveq.l  #6,d6
                    cmp.l    #$00000101,d3
                    blt.s    lbC0006CE
 
                    move.w   #$0100,d3
lbC0006CE           bra.s    lbC0006D6
 
lbC0006D0           move.w   d3,d6
                    subq.w   #2,d6
                    lsl.w    #1,d6
lbC0006D6           lea      lbL000754(pc),a6
                    cmp.w    0(a6,d6.w),d4
                    bge.s    lbC0006F0
 
                    move.l   d3,d5
                    move.l   d4,lbL00074E
                    move.b   d6,lbW000752

lbC0006F0           cmp.l    a5,a3
                    bgt.s    lbC000684
 
lbC0006F4           cmp.l    #1,d5
                    beq.s    lbC000740
 
                    bsr.s    lbC000788
                    move.b   lbW000752(pc),d6
                    move.l   lbL00074E(pc),d3
                    move.w   d3,_custom+color0
                    move.w   8(a6,d6.w),d0
                    bsr.s    lbC0007B6
                    move.w   $0010(a6,d6.w),d0
                    beq.s    lbC000728
 
                    move.l   d5,d3
                    subq.w   #1,d3
                    bsr.s    lbC0007B6
lbC000728           move.w   $0018(a6,d6.w),d0
                    move.w   $0020(a6,d6.w),d3
                    bsr.s    lbC0007B6
                    addq.w   #1,$0028(a6,d6.w)
                    add.l    d5,a0
                    clr.b    d0
                    rts     
 
lbC000740           move.b   (a0)+,d3
                    moveq.l  #8,d0
                    bsr.s    lbC0007B6
                    moveq.l  #1,d0
                    rts     
 


lbC000788           tst.w    d1
                    beq.s    lbC0007A2
 
                    move.w   d1,d3
                    clr.w    d1
                    cmp.w    #9,d3
                    bge.s    lbC0007A4
                    addq.w   #1,lbW000784
                    subq.w   #1,d3
                    moveq.l  #5,d0
                    bra.s    lbC0007B6
 
lbC0007A2           rts     
 
lbC0007A4
                    addq.w   #1,lbW000786
                    sub.w    #9,d3
                    or.w     #$0700,d3
                    moveq.l  #11,d0
;                   nop     
lbC0007B6           subq.w   #1,d0
lbC0007B8           lsr.l    #1,d3
                    roxl.l   #1,d2
                    bcs.s    lbC0007C6
 
                    dbra     d0,lbC0007B8
 
                    rts     
 
lbC0007C4           clr.w    d0
lbC0007C6           move.l   d2,(a2)+
                    eor.l    d2,d7
                    moveq.l  #1,d2
                    dbra     d0,lbC0007B8
 
                    rts     

WipeBuffer          movem.l  d0/a0,-(sp)
                    lea      Buffer,a0
                    moveq.l  #14,d0
Clrbuffer           clr.w    (a0)+
                    dbra     d0,Clrbuffer
 
                    movem.l  (sp)+,d0/a0
                    rts     
TypeMemRoutine
                    CALLEXEC TypeOfMem
                    tst.l    d0
                    bne.s    MemoryAvailable

                    Write    NoMemoryThere
                    bra      EndMemRoutine

; This next bit determines what type of memory is available at the
; address specified.

MemoryAvailable
                    Write    TypeOfMem
                    btst     #0,d0
                    beq.s    NotPublic
                    Write    IsPublicMem
                    bra      ChipOrFast
NotPublic
                    btst     #8,d0
                    beq.s    NotLocal
                    Write    IsLocalMem
                    bra      ChipOrFast
NotLocal
                    btst     #9,d0
                    beq.s    ChipOrFast
                    Write    Is24BitMem
ChipOrFast
                    btst     #1,d0
                    beq.s    NotChipMem
                    Write    IsChipMem
                    bra.s    EndMemRoutine
NotChipMem
                    btst     #2,d0
                    beq.s    NotFastOrChip
                    Write    IsFastMem
                    bra.s    EndMemRoutine
NotFastOrChip
                    Write    WowWhatKindOfRam
EndMemRoutine
                    rts
ReadIn
                    move.l   InitInput,d1
                    move.l   #Buffer,d2
                    CALLDOS  Read
	ifeq	1
                    movem.l  d0-d7/a0-a6,-(sp)

                    move.l   InitInput,d1
                    move.l   #100,d2
                    CALLDOS  WaitForChar
                    cmp.l    #0,d0
                    beq.s    LeaveRead

                    move.l   InitInput,d1
                    move.l   #Trebor,d2
                    move.l   #100,d3
                    CALLDOS  Read
LeaveRead
                    movem.l  (sp)+,d0-d7/a0-a6
	endc
                    rts

Trebor              dcb.l    20

lbL00074E           dc.l     0
lbW000752           dc.w     0
lbL000754           dc.l     $01000200
                    dc.l     $04001000
                    dc.l     $00080009
                    dc.l     $000A000C
                    dc.l     0
                    dc.l     8
                    dc.l     $00020003
                    dc.l     $00030003
                    dc.l     $00010004
                    dc.l     $00050006
lbL00077C           dc.l     0
                    dc.l     0
lbW000784           dc.w     0
lbW000786           dc.w     0

	section	 ByteKillerData,data

                    ; This is the decruncher for the executable option
 
LengthOfPacked      dc.l     0

Decruncher
                    dc.l     $000003F3        ; Hunk Header
                    dc.l     0
                    dc.l     1                ; number of hunks (2)
                    dc.l     0
                    dc.l     1                ; ? (1)
Length1             equ      *-Decruncher
                    dc.l     $3b              ; length of hunk
                    dc.l     0
                    dc.l     $000003E9        ; Hunk code
Length2             equ      *-Decruncher
                    dc.l     $3B              ; Hunk Length

       ; Start of Code Check longword

                    dc.l     $41FA00E6        ; lea +0e6,a0
                    dc.w     $43F9            ; lea LoadAddr,a1
Reloc1              equ      *-Decruncher
                    dc.l     $00040000
                    dc.w     $2018
                    dc.l     $22182A18
                    dc.l     $2449D1C0
                    dc.l     $D5C12020
                    dc.l     $B185E288
                    dc.l     $66046100
                    dc.l     $00A2653C
                    dc.l     $72087601
                    dc.l     $E2886604
                    dc.l     $61000094
                    dc.l     $655A7203
                    dc.l     $42446100
                    dc.l     $00963602
                    dc.l     $D6447207
                    dc.l     $E2886604
                    dc.l     $6100007C
                    dc.l     $E39251C9
                    dc.l     $FFF41502
                    dc.l     $51CBFFEC
                    dc.l     $60000044
                    dc.l     $72087808
                    dc.l     $6000FFD8
                    dc.l     $72026100
                    dc.l     $006A0C02
                    dc.l     $00026D16
                    dc.l     $0C020003
                    dc.l     $67E67208
                    dc.l     $61000058
                    dc.l     $3602323C
                    dc.l     $000C6000
                    dc.l     $000C323C
                    dc.l     $0009D242
                    dc.l     $54423602
                    dc.l     $61000040
                    dc.l     $534A14B2
                    dc.l     $200051CB
                    dc.l     $FFF833F9
                    dc.l     $00DFFA06
DecrColor           dc.l     $00DFF180        ; Flash screen
                    dc.l     $B3CA6D00
                    dc.l     $FF724EF9        ; jmp $address
Reloc2              equ      *-Decruncher
                    dc.l     $00123456
                    dc.l     $303CFFFF
                    dc.l     $33C000DF
                    dc.l     $F18051C8
                    dc.l     $FFF870FF
                    dc.l     $4E752020
                    dc.l     $B18544FC
                    dc.l     $0010E290
                    dc.l     $4E755341
                    dc.l     $4242E288
                    dc.l     $660A2020
                    dc.l     $B18544FC
                    dc.l     $0010E290
                    dc.l     $E39251C9
                    dc.l     $FFEE4E75
                    dc.l     $E290E392

RelocBSSData        ; changed to Symbol table as these are ignored by dos
                    dc.l     $000003f0        ; Reloc ? Why ? 0x3ec
                    dc.l     0
                    dc.l     $000003F2        ; End of hunk

                    dc.l     $000003f0        ; Bss ? Why ? 0x3eb
                    dc.l     0
                    dc.l     $000003F2        ; End of hunk

LengthBSS           equ      *-RelocBSSData
 
ActualLength        dc.l     0
Buffer              dcb.l    14,0
LengthToAlloc       dc.l     0
AllocMem            dc.l     0
FileBuffer          dc.l     0
LocateAddr          dc.l     0
JumpAddr            dc.l     0
_OurLock            dc.l     0
InitOutput          dc.l     0
InitInput           dc.l     0
DosBase             dc.l     0
DosLibName          dc.b     'dos.library',0
ConvertStr          dc.b     '0123456789abcdef'
ScanWidth           dc.l     0

                    even

StartupText         dc.b     LF
                    dc.b     ESC,'[3m'
                    dc.b     'LORD BLITTER',$27,'S BYTEKILLER V1.3+',LF
                    dc.b     'MODIFIED BY PSYCHO OF THE AWA. VERS 1.31  ',LF
                    dc.b     'USER INTERFACE BY J.J.',$27,'87 of THE BLIZZARD  :  18.11.87',LF
                    dc.b     ESC,'[2m'
                    dc.b     'MODIFIED BY CATH OF THE FURY. VERS 2.03 : 20.07.92'
                    dc.b     ESC,'[0m',LF
                    length   StartupText

AllocateWork        dc.b     LF
                    dc.b     'Allocate work space (KByte) :$'
                    length   AllocateWork

FileOverrun         dc.b    LF
                    dc.b    'Warning: File has overrun the allocated buffer, likely memory corruption'
                    length   FileOverrun

LoadName            dc.b    LF
                    dc.b    'Filename to load (exit to leave,'
                    dc.b    ' -(command) to execute CLI command.)',LF
                    dc.b    'Filename/Command :'
                    length  LoadName

OriginalLength      dc.b    LF,'Original length :'
                    length  OriginalLength

PackedLength        dc.b    LF,'Packed length :'
                    length  PackedLength

SaveFileName        dc.b    LF,'Save Filename (exit to leave,'
                    dc.b    ' -(command) to execute CLI command.)',LF
                    dc.b    'Filename/Command :'
                    length  SaveFileName

OffsetLength        dc.b    LF,'Scan Width (max $1000) :$'
                    length  OffsetLength

ExecOrData          dc.b    LF,'Create executable file or data file ? (e/d) :'
                    length  ExecOrData

LocateFileAt        dc.b    LF
                    dc.b    'Locate file at :$'
                    length  LocateFileAt

JumpInAddr          dc.b    LF
                    dc.b    'Jump to address after DeCruncher :$'
                    length  JumpInAddr

FlashType           dc.b    LF
                    dc.b    '1-BackGround,2-Text,3-Sprite,4-Modulo'
                    length  FlashType

FreeChipMem         dc.b    LF
                    dc.b    'Largest block of chip memory available (KByte) :'
                    length   FreeChipMem

FreeFastMem         dc.b   LF
                    dc.b   'Largest block of fast memory available (KByte) :'
                    length FreeFastMem

TypeOfMem           dc.b   LF
                    dc.b   'Type of Memory at that address is :'
                    length TypeOfMem

NoMemoryThere       dc.b   LF
                    dc.b   'Warning: The address you specified is invalid and either has no',LF
                    dc.b   'memory available there or is in ROM or is in the low memory area',LF
                    length NoMemoryThere

IsChipMem           dc.b   'Chip memory',LF
                    length IsChipMem

IsFastMem           dc.b   'Real Fast memory',LF
                    length IsFastMem

IsFakeFastMem       dc.b   'Fake Fast memory',LF
                    length IsFakeFastMem

Is24BitMem          dc.b   '24 bit DMA, '
                    length Is24BitMem

IsLocalMem          dc.b   'Local, '
                    length IsLocalMem

IsPublicMem         dc.b   'Public, '
                    length IsPublicMem

WowWhatKindOfRam    dc.b   'What kind of RAM do you have ? 32 Bit ?'
                    length WowWhatKindOfRam

Won                 dc.b   LF
                    dc.b   'Bytes Saved :'
                    length Won

Warning             dc.b   LF
 dc.b '**********************************************************************',LF
 dc.b '*  Warning: This appears to be a relocatable file and this version   *',LF
 dc.b '*          of ByteKiller doesn',$27,'t handle relocs properly yet          *',LF
 dc.b '**********************************************************************',LF
                    length Warning

FileNotFound        dc.b   LF
                    dc.b   'Couldn',$27,'t find that file !',LF
                    length FileNotFound

WantLongerFile      dc.b   LF,'File would be longer !',LF
                    length WantLongerFile

TooHigh             dc.b   LF,'Scan width is to high ($6-$1000)',LF
                    length TooHigh

FileTypeIs          dc.b   'File is a '
                    length FileTypeIs

WarnAlreadyPacked   dc.b   'ByteKiller 1.00-2.00 packed executable',LF
                    length WarnAlreadyPacked

PPDataFile          dc.b   'PowerPacker Data file'
                    length PPDataFile

STCDataFile         dc.b   'StoneCracker 401 Data file'
                    length STCDataFile

PackedPPLib         dc.b   'PowerPacker Exec + Library header'
                    length PackedPPLib

PackedPPExec        dc.b   'PowerPacker Executable'
                    length PackedPPExec

PackedImpLib        dc.b   'Imploder 4.0 Executable + Library decruncher'
                    length PackedImpLib

PackedImpExec       dc.b   'Imploder 4.0 Executable'
                    length PackedImpExec

IFFFile             dc.b   'IFF file'
                    length IFFFile

DeluxeEdBBLib       dc.b   'Deluxe Editor BB Library'
                    length DeluxeEdBBLib

LhaV5               dc.b   'Lharc Version 5'
                    length LhaV5

LhaV1               dc.b   'Lharc Version 1'
                    length LhaV1

InfoFileV1          dc.b   '.INFO file version 1'
                    length InfoFileV1

InterLeavedBitMap   dc.b   'IFF Interleaved Bitmap'
                    length InterLeavedBitMap

AnimFileBrush       dc.b   'IFF Anim or brush'
                    length AnimFileBrush

IffBrush            dc.b   'IFF Brush'
                    length IffBrush

PreferencesFile     dc.b   'Preferences File'
                    length PreferencesFile

Tetragon            dc.b   'Tetragon Cruncher'
                    length Tetragon

TucCruncher         dc.b   'Tuc-Cruncher'
                    length TucCruncher

ComPack             dc.b   'ComPack'
                    length ComPack

DoubleAction        dc.b   'Double action by Tristar',0
                    length DoubleAction

DefJam              dc.b   'DefJam Packer',0
                    length DefJam

ActionReplay        dc.b   'Action Replay file',0
                    length ActionReplay

NormalOrUnknown     dc.b   'Normal executable or unknown cruncher'
                    length NormalOrUnknown

DataAbsFile         dc.b   'Data file or absolute'
                    length DataAbsFile

FileLonger          dc.b   LF,'File longer than original',LF
                    length FileLonger

FileHeadLonger      dc.b   LF,'File + Header longer than original !',LF
                    length FileHeadLonger

_DOSBase            equ     DosBase          ; for system compatibility

FlashTable          dc.b    $00,$0
 ; Recognised file types ( most of them are accurate )

                    cnop   0,4
WhatIs
                    dc.w   $24                                  ; Offset
                    dc.l   $41fa00e6                            ; check value
                    ptr    WarnAlreadyPacked                    ; Text,length
                    dc.w   $60
                    dc.l   $66ea6130
                    ptr    PackedImpExec
                    dc.w   $60
                    dc.l   $72790020
                    ptr    PackedImpLib
                    dc.w   $34
                    dc.l   $d1c85848
                    ptr    PackedPPExec
                    dc.w   $38
                    dc.l   $fdd84a80
                    ptr    PackedPPLib
                    dc.w   0
                    dc.l   'S401'
                    ptr    STCDataFile
                    dc.w   0
                    dc.l   'PP20'
                    ptr    PPDataFile
                    dc.w   4
                    dc.l   ': De'
                    ptr    DeluxeEdBBLib
                    dc.w   4
                    dc.l   $68352de9
                    ptr    LhaV5
                    dc.w   4
                    dc.l   $68312d31
                    ptr    LhaV1
                    dc.w   0
                    dc.l   $E3100001
                    ptr    InfoFileV1
                    dc.w   8
                    dc.l   'PREF'
                    ptr    PreferencesFile
                    dc.w   $60
                    dc.l   'GRAB'
                    ptr    IffBrush
                    dc.w   8
                    dc.l   'ANIM'
                    ptr    AnimFileBrush
                    dc.w   8
                    dc.l   'ILBM'
                    ptr    InterLeavedBitMap
                    dc.w   -2			; Search first $150 bytes
                    dc.l   'GON '
                    ptr    Tetragon
                    dc.w   $44
                    dc.l   'rich'
                    ptr    TucCruncher
                    dc.w   0
                    dc.l   $504
                    ptr    ComPack
                    dc.w   $80
                    dc.l   'Doub'
                    ptr    DoubleAction
                    dc.w   0
                    dc.l   'ARPF'
                    ptr    ActionReplay
                    dc.w   0
                    dc.l   'FORM'
                    ptr    IFFFile
                    dc.w   $178
                    dc.l   'JAM '
                    ptr    DefJam
                    dc.w   0
                    dc.l   $3f3
                    ptr    NormalOrUnknown
                    dc.w   -1                     ; end of list
                    dc.l   0
                    dc.l   0

           *--------------------------------------------------*
            dc.b "$VER: ByteKiller Two by Cath of Fury 1992",0
           *--------------------------------------------------*

                    END
;END