JMA Compression

General area for talk about ZSNES. The best place to ask for related questions as well as troubleshooting.

Moderator: ZSNES Mods

Post Reply
kieran_
Mugwump
Posts: 824
Joined: Fri Jul 30, 2004 9:05 pm

Post by kieran_ »

Nach wrote:
kilivipin wrote: Oh.. Thanks.
I just didn't see any credits in the nsrt 3.3 binary.
Read the readme next time.
That was what I meant. I checked the readme in the 3.3 binary, butI did not find any credit for 7zip.
Nach
ZSNES Developer
ZSNES Developer
Posts: 3904
Joined: Tue Jul 27, 2004 10:54 pm
Location: Solar powered park bench
Contact:

Post by Nach »

kilivipin wrote:
Nach wrote:
kilivipin wrote: Oh.. Thanks.
I just didn't see any credits in the nsrt 3.3 binary.
Read the readme next time.
That was what I meant. I checked the readme in the 3.3 binary, butI did not find any credit for 7zip.
Igor Pavlov is clearly thanked in the readme.
May 9 2007 - NSRT 3.4, now with lots of hashing and even more accurate information! Go download it.
_____________
Insane Coding
kieran_
Mugwump
Posts: 824
Joined: Fri Jul 30, 2004 9:05 pm

Post by kieran_ »

Nach wrote:
kilivipin wrote:
Nach wrote:
kilivipin wrote: Oh.. Thanks.
I just didn't see any credits in the nsrt 3.3 binary.
Read the readme next time.
That was what I meant. I checked the readme in the 3.3 binary, butI did not find any credit for 7zip.
Igor Pavlov is clearly thanked in the readme.
SHIT!
I was looking for a credit to 7zip. Ah well...
denzilla
Hazed
Posts: 55
Joined: Sun Sep 26, 2004 9:31 pm

Post by denzilla »

Will Igor implement JMA compression/decompression into future versions of 7zip? I'll prolly stick to zip until something other that NSRT is able to manipulate the file format.

Good work nonetheless, NACH. You're a helluva coder!
Nach
ZSNES Developer
ZSNES Developer
Posts: 3904
Joined: Tue Jul 27, 2004 10:54 pm
Location: Solar powered park bench
Contact:

Post by Nach »

denzilla wrote:Will Igor implement JMA compression/decompression into future versions of 7zip? I'll prolly stick to zip until something other that NSRT is able to manipulate the file format.
Probably not. I've been following his forum for ages, and he's never done a single thing anyone has suggested.
denzilla wrote: Good work nonetheless, NACH. You're a helluva coder!
Thanks. But I really can't take a lot of credit, so much of JMA was done by others.
May 9 2007 - NSRT 3.4, now with lots of hashing and even more accurate information! Go download it.
_____________
Insane Coding
denzilla
Hazed
Posts: 55
Joined: Sun Sep 26, 2004 9:31 pm

Post by denzilla »

Even if you can't take full credit for this feature, you're still a valuable asset to the Zsnes team. Thanks again :)
Dead
Lurker
Posts: 118
Joined: Sat Sep 25, 2004 10:59 am
Location: I don't know where I am

Post by Dead »

It can't be said too many times, Nach. You are a boon to the SNES emulation community.
kieran_
Mugwump
Posts: 824
Joined: Fri Jul 30, 2004 9:05 pm

Post by kieran_ »

Syvalion wrote:It can't be said too many times, Nach. You are a boon to the SNES emulation community.
And Pagefault is the Mill to Snes emulaion community.
Dead
Lurker
Posts: 118
Joined: Sat Sep 25, 2004 10:59 am
Location: I don't know where I am

Post by Dead »

Yeah. It's so hard to suck up to only one ZSNES dev at a time, because we are grateful for each and every one of them. :P Am I right?

I actually feel guilty for enjoying ZSNES for all these years, to the extent that I am taking steps to someday cotribute to the project. Hopefully soon.
grinvader
ZSNES Shake Shake Prinny
Posts: 5632
Joined: Wed Jul 28, 2004 4:15 pm
Location: PAL50, dood !

Post by grinvader »

Syvalion wrote:I actually feel guilty for enjoying ZSNES for all these years, to the extent that I am taking steps to someday cotribute to the project. Hopefully soon.
Get your ass in gear and join the dev channel, then.

Don't worry, it's only painful the first time.
And the second... or maybe 3 times.










More like 10, actually.
Come on, we'll just eat your brains with gravel.
皆黙って俺について来い!!

Code: Select all

<jmr> bsnes has the most accurate wiki page but it takes forever to load (or something)
Pantheon: Gideon Zhi | CaitSith2 | Nach | kode54
Noxious Ninja
Dark Wind
Posts: 1271
Joined: Thu Jul 29, 2004 8:58 pm
Location: Texas
Contact:

Post by Noxious Ninja »

Hm, I might have to stop by. Can you teach me l33t C ABI stuff and how to connect C code to ASM code?
[u][url=http://bash.org/?577451]#577451[/url][/u]
Dead
Lurker
Posts: 118
Joined: Sat Sep 25, 2004 10:59 am
Location: I don't know where I am

Post by Dead »

grinvader wrote:Come on, we'll just eat your brains with gravel.
Deal.
grinvader
ZSNES Shake Shake Prinny
Posts: 5632
Joined: Wed Jul 28, 2004 4:15 pm
Location: PAL50, dood !

Post by grinvader »

Noxious Ninja wrote:Hm, I might have to stop by. Can you teach me l33t C ABI stuff and how to connect C code to ASM code?
I can tell you what I know on porting asm into c; it's quite different than simply 'connecting' C to ASM.
皆黙って俺について来い!!

Code: Select all

<jmr> bsnes has the most accurate wiki page but it takes forever to load (or something)
Pantheon: Gideon Zhi | CaitSith2 | Nach | kode54
Starman Ghost
Trooper
Posts: 535
Joined: Wed Jul 28, 2004 3:26 am

Post by Starman Ghost »

grinvader wrote:
Noxious Ninja wrote:Hm, I might have to stop by. Can you teach me l33t C ABI stuff and how to connect C code to ASM code?
I can tell you what I know on porting asm into c; it's quite different than simply 'connecting' C to ASM.
Do you actually know enough asm to look at the code and be able to write the equivalent in C or do you have to ask what it does before you can write the C equivelant?
[code]<Guo_Si> Hey, you know what sucks?
<TheXPhial> vaccuums
<Guo_Si> Hey, you know what sucks in a metaphorical sense?
<TheXPhial> black holes
<Guo_Si> Hey, you know what just isn't cool?
<TheXPhial> lava?[/code]
Noxious Ninja
Dark Wind
Posts: 1271
Joined: Thu Jul 29, 2004 8:58 pm
Location: Texas
Contact:

Post by Noxious Ninja »

grinvader wrote:
Noxious Ninja wrote:Hm, I might have to stop by. Can you teach me l33t C ABI stuff and how to connect C code to ASM code?
I can tell you what I know on porting asm into c; it's quite different than simply 'connecting' C to ASM.
Oh, I know. I mean, if I take an ASM function and write a C equivalent, how do I call that function, pass arguments, collect return values, that stuff.
Megabyte wrote:
grinvader wrote:
Noxious Ninja wrote:Hm, I might have to stop by. Can you teach me l33t C ABI stuff and how to connect C code to ASM code?
I can tell you what I know on porting asm into c; it's quite different than simply 'connecting' C to ASM.
Do you actually know enough asm to look at the code and be able to write the equivalent in C or do you have to ask what it does before you can write the C equivelant?
To a certain extent. I found a decent x86 assembler reference, and that helped. Unfortunately, the images in it seem to be broken, but it's good for looking up instructions.

http://faydoc.tripod.com/cpu/index.htm

There's still NASM syntax things that that doesn't explain, but I'm able to understand a few blockes of code in the GUI routines now.
[u][url=http://bash.org/?577451]#577451[/url][/u]
grinvader
ZSNES Shake Shake Prinny
Posts: 5632
Joined: Wed Jul 28, 2004 4:15 pm
Location: PAL50, dood !

Post by grinvader »

Megabyte wrote:Do you actually know enough asm to look at the code and be able to write the equivalent in C or do you have to ask what it does before you can write the C equivelant?
Do I sound like a total retard or something ?
ASM isn't hard to understand, it's hard to maintain. ASM intructions are quite explicit.
The porting problems come with registers and program structure.
ASM is unstructured, like BASIC. Lots of conditionnal jumps and tests everywhere. A bit of reflexion gives the best C fit.
Then registers and memory locations, those are quite bothersome, but once you know how to handle them, porting is almost as easy as pie, just time-consuming.
Noxious Ninja wrote:
grinvader wrote:
Noxious Ninja wrote:Hm, I might have to stop by. Can you teach me l33t C ABI stuff and how to connect C code to ASM code?
I can tell you what I know on porting asm into c; it's quite different than simply 'connecting' C to ASM.
Oh, I know. I mean, if I take an ASM function and write a C equivalent, how do I:
call that function
Extremely easy
pass arguments
Depends on where they are. Memory locations are easy to pass, but registers... not more than one.
collect return values
Same as above, and note that most asm funcs don't have a return value. They just modify the registers needed, and return to the caller. So most C ports are void func() {<stuff>}
皆黙って俺について来い!!

Code: Select all

<jmr> bsnes has the most accurate wiki page but it takes forever to load (or something)
Pantheon: Gideon Zhi | CaitSith2 | Nach | kode54
Nach
ZSNES Developer
ZSNES Developer
Posts: 3904
Joined: Tue Jul 27, 2004 10:54 pm
Location: Solar powered park bench
Contact:

Post by Nach »

Well if you stop by the channel, we usually discuss programming when we're around. How to link C with asm and call correctly and port and stuff is a perfectly normal topic of discussion.
We even had a major argument about signed values today. So come on in, the water could wash away everything but the toughness in you.
May 9 2007 - NSRT 3.4, now with lots of hashing and even more accurate information! Go download it.
_____________
Insane Coding
Starman Ghost
Trooper
Posts: 535
Joined: Wed Jul 28, 2004 3:26 am

Post by Starman Ghost »

grinvader wrote:
Megabyte wrote:Do you actually know enough asm to look at the code and be able to write the equivalent in C or do you have to ask what it does before you can write the C equivelant?
Do I sound like a total retard or something ?
I didn't mean to imply that. I know nothing about asm and have always heard it is difficult to work with, which is why I asked.
[code]<Guo_Si> Hey, you know what sucks?
<TheXPhial> vaccuums
<Guo_Si> Hey, you know what sucks in a metaphorical sense?
<TheXPhial> black holes
<Guo_Si> Hey, you know what just isn't cool?
<TheXPhial> lava?[/code]
Nach
ZSNES Developer
ZSNES Developer
Posts: 3904
Joined: Tue Jul 27, 2004 10:54 pm
Location: Solar powered park bench
Contact:

Post by Nach »

Megabyte wrote:
grinvader wrote:
Megabyte wrote:Do you actually know enough asm to look at the code and be able to write the equivalent in C or do you have to ask what it does before you can write the C equivelant?
Do I sound like a total retard or something ?
I didn't mean to imply that. I know nothing about asm and have always heard it is difficult to work with, which is why I asked.
Learning what you need to learn in asm to get by is actually easier than any language other than BASIC.

The great thing about assembly is, you can never have a complex line.

Let's take a nice example:
C complexity:

Code: Select all

*(*ram+size) -= (buffer > size >> 2*money) ? ((buffer << 1)+(unsigned long long)&myfunc*2<<16) : &myfunc+*money;
And you can write much more complex stuff than that on a single line in C.
Asm complexity:

Code: Select all

add dword[eax+ebx*4],esi
And that's the most complex thing you're going to see on one line in assembly.
May 9 2007 - NSRT 3.4, now with lots of hashing and even more accurate information! Go download it.
_____________
Insane Coding
grinvader
ZSNES Shake Shake Prinny
Posts: 5632
Joined: Wed Jul 28, 2004 4:15 pm
Location: PAL50, dood !

Post by grinvader »

To add to Nach's post:
Usually you end up compiling several lines of asm code on one line of C code, which is why asm has a lot of simple lines.

Example: (I love that one, it's one of my most impressive ports)
ASM:

Code: Select all

NEWSYM CapturePicture 	 
     pushad 	 
     mov esi,[vidbuffer] 	 
     add esi,288*2+16*2 	 
     mov edi,PrevPicture 	 
     mov edx,56 	 
 .next 	 
     push esi 	 
     push edx 	 
     mov dx,1111011111011110b 	 
     cmp byte[newengen],0 	 
     je .noneweng2 	 
     cmp byte[nggposng],5 	 
     jne .noneweng2 	 
     mov dx,0111101111011110b 	 
 .noneweng2 	 
     mov ecx,64 	 
 .loop 	 
     mov ax,[esi] 	 
     mov bx,[esi+4] 	 
     and ax,dx 	 
     and bx,dx 	 
     shr ax,1 	 
     shr bx,1 	 
     add ax,bx 	 
     push ax 	 
     mov ax,[esi+288*2] 	 
     mov bx,[esi+4+288*2] 	 
     and ax,dx 	 
     and bx,dx 	 
     shr ax,1 	 
     shr bx,1 	 
     add bx,ax 	 
     pop ax 	 
     and ax,dx 	 
     and bx,dx 	 
     shr ax,1 	 
     shr bx,1 	 
     add ax,bx 	 
     mov [edi],ax 	 
     add esi,8 	 
     add edi,2 	 
     dec ecx 	 
     jnz .loop 	 
     pop edx 	 
     pop esi 	 
     add esi,288*2*4 	 
     dec edx 	 
     jnz near .next 	 
     cmp byte[newengen],0 	 
     je .noneweng 	 
     cmp byte[nggposng],5 	 
     jne .noneweng 	 
     mov edx,PrevPicture 	 
     mov ecx,64*56 	 
 .loop2 	 
     mov ax,[edx] 	 
     mov bx,ax 	 
     and ax,0111111111100000b 	 
     and bx,0000000000011111b 	 
     shl ax,1 	 
     or bx,ax 	 
     mov [edx],bx 	 
     add edx,2 	 
     dec ecx 	 
     jnz .loop2 	 
 .noneweng 	 
     popad 	 
     ret
C:

Code: Select all

void CapturePicture()
{
    unsigned short work1, work2, filter;
    unsigned int i, j, offset, pppos=0;

    if ((newengen & 0xFF) && ((nggposng[0] & 0xFF) == 5))
    {
	filter = 0x7BDE;	// 0111 1011 1101 1110
    }
    else
    {
	filter = 0xF7DE;	// 1111 0111 1101 1110
    }

    for (j=0 ; j<56 ; j++)
    {
	offset = 288+16+j*288*4;

	for (i=0 ; i<64 ; i++)
	{
	    work1 = ((vidbuffer[offset] & filter)>>1) + ((vidbuffer[offset+2] & filter)>>1);
	    work2 = ((vidbuffer[offset+288] & filter)>>1) + ((vidbuffer[offset+288+2] & filter)>>1);
	    PrevPicture[pppos] = ((work1 & filter)>>1) + ((work2 & filter)>>1);
	    offset += 4;
	    pppos++;
	}
    }

    if ((newengen & 0xFF) && ((nggposng[0] & 0xFF) == 5))
    {
	for (pppos=0 ; pppos<64*56 ; pppos++)
	{
	    PrevPicture[pppos] = ((PrevPicture[pppos] & 0x7FE0)<<1)|(PrevPicture[pppos] & 0x001F);
	} // 0111 1111 1110 0000 and 0000 0000 0001 1111
    }
}
皆黙って俺について来い!!

Code: Select all

<jmr> bsnes has the most accurate wiki page but it takes forever to load (or something)
Pantheon: Gideon Zhi | CaitSith2 | Nach | kode54
Noxious Ninja
Dark Wind
Posts: 1271
Joined: Thu Jul 29, 2004 8:58 pm
Location: Texas
Contact:

Post by Noxious Ninja »

grinvader wrote:Example: (I love that one, it's one of my most impressive ports)
Heh. That's a fairly complex piece of code there.

Can you do all that in your head, or do you have to get out some paper and trace the execution?
[u][url=http://bash.org/?577451]#577451[/url][/u]
Bent
Lurker
Posts: 193
Joined: Wed Jul 28, 2004 5:16 am

Post by Bent »

Just trying to get a few things clear here...

I have written programs in MIPS assembly language before, and unuccessfully tried to do some Z80 programs (lost interest). From what I remember hearing, x86 is a bit tougher than MIPS because of limited amounts of registers right? MIPS compatable processors had something like 32 general purpose registers of which most of them were almost always usable. Does the x86 have some 32bit registers and some 16bit?

Also, how much of a difference does the fact that it is a CISC CPU instead of a RISC CPU make? Is the instruction set much larger? One thing I liked about assembly is that it was very easy to see exactly what was happening to the processor at any given moment, even if it did make the program harder to read as a whole.
~Bent
grinvader
ZSNES Shake Shake Prinny
Posts: 5632
Joined: Wed Jul 28, 2004 4:15 pm
Location: PAL50, dood !

Post by grinvader »

Noxious Ninja wrote:
grinvader wrote:Example: (I love that one, it's one of my most impressive ports)
Heh. That's a fairly complex piece of code there.

Can you do all that in your head, or do you have to get out some paper and trace the execution?
I used a flowchart for stateloader, because it was called 4 times with different parameters each time in asm. Preparing in such cases saves a lot of time.
But for 1-way functions, I usually convert them on-the-fly. Reading ahead of opcodes gets easier and easier as time goes.

You end up 'seeing' C in opcodes. If, For, Switch... and so on. This func features a double imbricated for using a register that gets pushed during the small loop so that it can be used in storing/manipulating values.

By analysing the C, you should be able to see what the asm does.
皆黙って俺について来い!!

Code: Select all

<jmr> bsnes has the most accurate wiki page but it takes forever to load (or something)
Pantheon: Gideon Zhi | CaitSith2 | Nach | kode54
Nach
ZSNES Developer
ZSNES Developer
Posts: 3904
Joined: Tue Jul 27, 2004 10:54 pm
Location: Solar powered park bench
Contact:

Post by Nach »

Bent wrote:x86 is a bit tougher than MIPS because of limited amounts of registers right?
When writing a complex function, yes the register limit is a problem.
Bent wrote: MIPS compatable processors had something like 32 general purpose registers of which most of them were almost always usable. Does the x86 have some 32bit registers and some 16bit?
The 16 bit registers are part of the 32 bit ones. Meaning you can access a 32 bit reg half way if you want.
Bent wrote: Also, how much of a difference does the fact that it is a CISC CPU instead of a RISC CPU make? Is the instruction set much larger?
I don't know the full instruction set of MIPS and x86, but I think x86 has a larger set.
To be honest though, I only use a dozen opcodes or so on a regular bases anyway.
May 9 2007 - NSRT 3.4, now with lots of hashing and even more accurate information! Go download it.
_____________
Insane Coding
kieran_
Mugwump
Posts: 824
Joined: Fri Jul 30, 2004 9:05 pm

Post by kieran_ »

Coding is complex.
Post Reply