zsnes port to C language

Strictly for discussing ZSNES development and for submitting code. You can also join us on IRC at irc.freenode.net in #zsnes.
Please, no requests here.

Moderator: ZSNES Mods

Post Reply
flaggy
New Member
Posts: 3
Joined: Tue Oct 30, 2012 2:49 am

zsnes port to C language

Post by flaggy »

It looks like you guys started porting things to C, but then stoped. Is there a reason for that? Is there something that just can't be ported to C? It would be very good if everything was written in C because then we could compile zsnes to 64 bits intel processor and several other targets. It would also be interesting to have a arm port of zsnes. All that would be much easier if zsnes were 100% C code.
Gil_Hamilton
Buzzkill Gil
Posts: 4267
Joined: Wed Jan 12, 2005 7:14 pm

Re: zsnes port to C language

Post by Gil_Hamilton »

It's ongoing. Important people have bad cases of real life syndrome, which has several severe symptoms including "no free time for hobby coding".

And I still maintain that whatever comes out won't be ZSNES, since the entire emulation core will be new.

And absolutely everyone knows the advantages. It's why porting a shit-ton of cryptic x86 assembly to C was ever started.
Squall_Leonhart wrote:
You have your 2s, 4s, 8s, 16s, 32s, 64s, and 128s(crash course in binary counting!). But no 1s.
DirectInput represents all bits, not just powers of 2 in an axis.


KHDownloads
grinvader
ZSNES Shake Shake Prinny
Posts: 5622
Joined: Wed Jul 28, 2004 4:15 pm
Location: PAL50, dood !

Re: zsnes port to C language

Post by grinvader »

And by important people he means everyone involved.


Gil_Hamilton wrote:And I still maintain that whatever comes out won't be ZSNES, since the entire emulation core will be new.

Well, it's about the spirit imo. A program's identity stems from its guts, direct consequence of the skills and quirks of its authors.
So if there's a reason it won't be ZSNES, it's because zsknight and _Demo_ aren't doing it, essentially.
皆黙って俺について来い!!

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
flaggy
New Member
Posts: 3
Joined: Tue Oct 30, 2012 2:49 am

Re: zsnes port to C language

Post by flaggy »

I was just curious whether rewriting things in C was a worthy goal, or if it was hopeless. I decided I'd have a go at it. So I began with init function. I found this part

Code: Select all

    ; Initialize volume
    xor edx,edx
    movzx eax,byte[MusicRelVol]
    shl eax,7
    mov ebx,0A3D70A3Dh
    mul ebx
    shr edx,6
    cmp dl,127
    jb .noof
    mov dl,127
.noof
    mov [MusicVol],dl


which I translated to

Code: Select all

    int64_t vol = MusicRelVol << 7;                    
    vol *= 0xA3D70A3D;                                 
    vol >>= 38;
    if (vol > 127)                                     
        vol = 127;
    MusicVol = vol;


Still, I'm puzzled as what does all those shift and multiplying by 0xA3D70A3D means. I ploted the function

((x<<7) * 0xA3D70A3D) >> 38

and I figured that it's very close to the function f(x) = 1.28x - 0.5.

Still, I had no further insight as why to use such an awkward function for translating MusicRelVol into MusicVol. It seems to me that MusicRelVol goes from 0 to 100 and MusicVol goes from 0 to 127. Anybody care to join me in this task?
flaggy
New Member
Posts: 3
Joined: Tue Oct 30, 2012 2:49 am

Re: zsnes port to C language

Post by flaggy »

I have set up a public repository with the development I'm doing. Everyone is welcomed to help me out making the transition from assembly to C:

https://github.com/aflag/zsnes

I hope eventually we'll be able to merge any changes back to the main development branch.
kode54
Zealot
Posts: 1140
Joined: Wed Jul 28, 2004 3:31 am
Contact:

Re: zsnes port to C language

Post by kode54 »

That was from me being really "clever" by borrowing fixed point multiplication optimizations from Intel's C/C++ compiler a long time ago. No better reason, really.
grinvader
ZSNES Shake Shake Prinny
Posts: 5622
Joined: Wed Jul 28, 2004 4:15 pm
Location: PAL50, dood !

Re: zsnes port to C language

Post by grinvader »

flaggy wrote:

Code: Select all

    shr edx,6

>

Code: Select all

    vol >>= 38;

Don't forget to check if your port actually does what the original did while you're at it.

(Edit: i.e. killing eax' contents does not work in other spots)


Regarding your attempt: you'd think starting at init is the right choice, but shortly thereafter you hit the main gui jump and execloop... If you're fine with assembly, feel free to actually trace it out. It's a unique experience.
Mind you, all that block is gonna die with the rewrite. Some of the messy stuff in there causes a good half of the issues.

If you want to help, please join the irc dev channel and hit us up, we always welcome new slaves^Whelpers.
皆黙って俺について来い!!

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
Fras
Hazed
Posts: 54
Joined: Tue Jan 16, 2007 5:32 pm

Re: zsnes port to C language

Post by Fras »

Wasn't there another C port attempt fairly recently, by the way? I don't remember his name, but I think he had done a decent bit of porting before he got taken away by real life.
grinvader
ZSNES Shake Shake Prinny
Posts: 5622
Joined: Wed Jul 28, 2004 4:15 pm
Location: PAL50, dood !

Re: zsnes port to C language

Post by grinvader »

Yes, Tron did a lot of work.
皆黙って俺について来い!!

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
kode54
Zealot
Posts: 1140
Joined: Wed Jul 28, 2004 3:31 am
Contact:

Re: zsnes port to C language

Post by kode54 »

Oh yeah, now I remember, I did that because Intel compiler thought that code like that was faster than using division opcodes. Seriously, just use *128/100.
Post Reply