English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 10 December 2014, 18:11   #1
Asle
Registered User
 
Join Date: May 2006
Location: Paris/France
Age: 52
Posts: 527
noise depakker.s help

hello,

The Noisepakker proggy (http://demozoo.org/productions/95863/) comes with a asm to depack, but my 68k is next to nonexistent. Could anyone translate the following lines to something readable (say, C-like description) ?

with thanks
Quote:

; #############################################################################
; depack routine for module packer
; In :
; a0 = Pointer on module

depack_module:

bsr analyse_module ; find sample start/end

bsr init_depack

movea.l sample_start(PC),A0 ; packed sample
move.l sample_end(PC),D0
sub.l A0,D0 ; unpacked length

move.l D0,-(A7)
bsr depack_sample ; depack over source
move.l (A7)+,D0
rts

; a0=module address

analyse_module: move.l A0,-(A7)

lea $03b8(A0),A1

moveq #$7f,D0
moveq #0,D4
mt_loop: move.l D4,D2
subq.w #1,D0
mt_lop2: move.b (A1)+,D4
cmp.b D2,D4
bgt.s mt_loop
dbra D0,mt_lop2
addq.b #1,D2

asl.l #8,D2
asl.l #2,D2
add.l #$043c,D2
move.l D2,D1
add.l A0,D2
movea.l D2,A2

move.l A2,sample_start

moveq #$1e,D0
mt_lop3:
moveq #0,D4
move.w 42(A0),D4
add.l D4,D4
adda.l D4,A2
adda.l #$1e,A0
dbra D0,mt_lop3

move.l A2,sample_end

movea.l (A7)+,A0

rts

; a0=packed sample (also destination)
; d0=unpacked length

depack_sample:
lea depack_hi(PC),A2
lea depack_lo(PC),A3

addq.l #1,D0
and.b #-2,D0 ; round length up
move.l D0,D7
lsr.l #1,D7 ; sample length in words

lea 0(A0,D0.l),A1 ; destination end
adda.l D7,A0 ; source end

move.w #128,D0 ; last byte
moveq #0,D1 ; clear temp

depack_loop: move.b -(A0),D1 ; get 2 distances
add.b 0(A2,D1.w),D0
move.b D0,-(A1)
add.b 0(A3,D1.w),D0
move.b D0,-(A1)

subq.l #1,D7
bne.s depack_loop

rts

init_depack:

lea depack_lo(PC),A1
move.w #15,D7
init1: lea power_bytes(PC),A0
move.w #15,D6
init2: move.b (A0)+,(A1)+
dbra D6,init2
dbra D7,init1

lea power_bytes(PC),A0
lea depack_hi(PC),A1
move.w #15,D7
init3: move.w #15,D6
move.b (A0)+,D0
init4: move.b D0,(A1)+
dbra D6,init4
dbra D7,init3

rts


power_bytes: DC.B -128,-64,-32,-16,-8,-4,-2,-1,0,1,2,4,8,16,32,64

sample_start: DC.L 0
sample_end: DC.L 0

depack_lo: DS.B 256
depack_hi: DS.B 256

; DEPACK END
END
Asle is offline  
Old 11 December 2014, 13:05   #2
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,510
Something like this (untested):

Code:
struct Sample {
  char Name[22];
  unsigned char WordLen[2];
  unsigned char Volume[2];
  char Rest[4];
};

struct Mod {
  char Header[20];
  struct Sample Samples[31];
  char SongLen;
  char Arrangement[128];
  char MK[4];
  char Patterns[1024];
};

#define PATTERNSIZE (2<<10)

static char *sample_start,*sample_end;
static char depack_lo[256],depack_hi[256];


static unsigned be_word(unsigned char *p)
{
  return ((unsigned)p[0]<<8) | (unsigned)p[1];
}


static void analyse_module(struct Mod *modptr)
{
  char maxpat = 0;
  int i;

  /* find highest pattern number from song arrangement list */
  for (i=0; i<128; i++) {
    if (modptr->Arrangement[i] > maxpat)
      maxpat = modptr->Arrangement[i];
  }

  sample_start = &modptr->Patterns[(maxpat+1)*PATTERNSIZE];

  /* sum up all sample lengths to find end of samples */
  sample_end = sample_start;
  for (i=0; i<31; i++)
    sample_end += 2 * be_word(modptr->Samples[i].WordLen);
}


static void init_depack(void)
{
  static const char power_bytes[] = {
    -128,-64,-32,-16,-8,-4,-2,-1,0,1,2,4,8,16,32,64
  };
  int i,j;

  for (i=0; i<16; i++) {
    for (j=0; j<16; j++)
      depack_lo[i*16+j] = power_bytes[j];
  }
  for (i=i; i<16; i++) {
    for (j=0; j<16; j++)
      depack_hi[i*16+j] = power_bytes[i];
  }
}


static void depack_sample(char *sample,unsigned unpacklen)
{
  int remaining_bytes = (unpacklen + 1) & ~1;  /* align to next word */
  char *src = sample + remaining_bytes / 2;
  char *dst = sample + remaining_bytes;
  char s,d;

  for (s=0x80; remaining_bytes>0; remaining_bytes-=2) {
    d = *(--src);
    s += depack_hi[d];
    *(--dst) = s;
    s += depack_lo[d];
    *(--dst) = s;
  }
}


unsigned depack_module(struct Mod *modptr)
{
  analyse_module(modptr);
  init_depack();
  depack_sample(sample_start,sample_end-sample_start);
  return sample_end - sample_start;
}
phx is offline  
Old 11 December 2014, 14:36   #3
Asle
Registered User
 
Join Date: May 2006
Location: Paris/France
Age: 52
Posts: 527
Hey, thanks for your help

So basically, we build a static table containing this:
Code:
-128, -64, -32, -16,  -8,  -4,  -2,  -1,   0,   1,   2,   4,   8,  16,  32,  64,
-128, -64, -32, -16,  -8,  -4,  -2,  -1,   0,   1,   2,   4,   8,  16,  32,  64,
-128, -64, -32, -16,  -8,  -4,  -2,  -1,   0,   1,   2,   4,   8,  16,  32,  64,
-128, -64, -32, -16,  -8,  -4,  -2,  -1,   0,   1,   2,   4,   8,  16,  32,  64,
-128, -64, -32, -16,  -8,  -4,  -2,  -1,   0,   1,   2,   4,   8,  16,  32,  64,
-128, -64, -32, -16,  -8,  -4,  -2,  -1,   0,   1,   2,   4,   8,  16,  32,  64,
-128, -64, -32, -16,  -8,  -4,  -2,  -1,   0,   1,   2,   4,   8,  16,  32,  64,
-128, -64, -32, -16,  -8,  -4,  -2,  -1,   0,   1,   2,   4,   8,  16,  32,  64,
-128, -64, -32, -16,  -8,  -4,  -2,  -1,   0,   1,   2,   4,   8,  16,  32,  64,
-128, -64, -32, -16,  -8,  -4,  -2,  -1,   0,   1,   2,   4,   8,  16,  32,  64,
-128, -64, -32, -16,  -8,  -4,  -2,  -1,   0,   1,   2,   4,   8,  16,  32,  64,
-128, -64, -32, -16,  -8,  -4,  -2,  -1,   0,   1,   2,   4,   8,  16,  32,  64,
-128, -64, -32, -16,  -8,  -4,  -2,  -1,   0,   1,   2,   4,   8,  16,  32,  64,
-128, -64, -32, -16,  -8,  -4,  -2,  -1,   0,   1,   2,   4,   8,  16,  32,  64,
-128, -64, -32, -16,  -8,  -4,  -2,  -1,   0,   1,   2,   4,   8,  16,  32,  64,
-128, -64, -32, -16,  -8,  -4,  -2,  -1,   0,   1,   2,   4,   8,  16,  32,  64,
-128,-128,-128,-128,-128,-128,-128,-128,-128,-128,-128,-128,-128,-128,-128,-128,
 -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64,
 -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32,
 -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16, -16,
  -8,  -8,  -8,  -8,  -8,  -8,  -8,  -8,  -8,  -8,  -8,  -8,  -8,  -8,  -8,  -8,
  -4,  -4,  -4,  -4,  -4,  -4,  -4,  -4,  -4,  -4,  -4,  -4,  -4,  -4,  -4,  -4,
  -2,  -2,  -2,  -2,  -2,  -2,  -2,  -2,  -2,  -2,  -2,  -2,  -2,  -2,  -2,  -2,
  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,   1,
   2,   2,   2,   2,   2,   2,   2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
   4,   4,   4,   4,   4,   4,   4,   4,   4,   4,   4,   4,   4,   4,   4,   4,
   8,   8,   8,   8,   8,   8,   8,   8,   8,   8,   8,   8,   8,   8,   8,   8,
  16,  16,  16,  16,  16,  16,  16,  16,  16,  16,  16,  16,  16,  16,  16,  16,
  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,  32,
  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,
then, starting from the end of the packed sample data, we generate two bytes out of one packed byte.

This production has examples : http://demozoo.org/productions/79312/
I took one, attached (as .7z since we can't attach .mod), and tried.

Last byte is 0x08, so:

d = *(--src); /* d = 0x08 */
s += depack_hi[d]; /* depack_hi[8] = -128 and s = 0 then */
*(--dst) = s; /* destination last byte is 0x00 */
s += depack_lo[d]; /* depack_lo[8] = 0 and s = 0 then */
*(--dst) = s; /* destination previous byte is 0x00 */

and we start over with the previous packed byte, being 0x88 (shouldn't d be declared as unsigned ?)

d = *(--src); /* d = 0x88 */
s += depack_hi[d]; /* depack_hi[0x88] = 0 and s = 0 then since it's not reinitialized and was valued 0 */
*(--dst) = s; /* destination previous byte is 0x00 */
s += depack_lo[d]; /* depack_lo[88] = 0 and s = 0 then */
*(--dst) = s; /* destination prvious byte is 0x00 */

etc.

Applying this logic results is pure garbage. Either signed or not signed (Atari ST replay are fond of signed samples data in MODs). I tried to force d as unsigned and the result IS BETTER

So, it's all fine in the end.
Attached Files
File Type: 7z CRUSADER.7z (56.7 KB, 103 views)

Last edited by Asle; 11 December 2014 at 15:52. Reason: update after another check of code
Asle is offline  
Old 11 December 2014, 18:02   #4
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,510
Quote:
Originally Posted by Asle View Post
I tried to force d as unsigned and the result IS BETTER
Indeed, the index should be unsigned, otherwise you would access memory before the depack_hi/depack_lo array.
phx is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Power off death noise john1979 support.Hardware 15 10 September 2012 12:27
TechnoSound 2 making noise Amiga1992 support.Hardware 10 02 February 2012 18:49
Fatal Noise viddi Games images which need to be WHDified 6 24 August 2008 23:29
Crappy Noise Ebster support.WinUAE 2 13 February 2006 22:23
Awful Noise Enverex support.WinUAE 8 11 February 2004 23:36

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 21:36.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.09787 seconds with 16 queries