Author Topic: Romhack's WIP thread  (Read 23862 times)

Offline dink

  • Administrator
  • *****
  • Posts: 2677
  • Karma: +227/-0
  • feed the horse yumyum
Re: Romhack's WIP thread
« Reply #45 on: April 06, 2015, 07:02:00 pm »
TMS34020 is what Battle Toads uses, and FBA needs Battle Toads :)  Hopefully a possibility? :D

best regards,
- dink

Offline Romhack

  • Expert
  • *****
  • Posts: 94
  • Karma: +49/-0
Re: Romhack's WIP thread
« Reply #46 on: April 07, 2015, 12:14:23 am »
TMS34020 is what Battle Toads uses, and FBA needs Battle Toads :)  Hopefully a possibility? :D

best regards,
- dink
Of course. TMS34020 has more opcodes (40+), MAME only implements 5 and Battletoads runs very well.
There's a lot of great games with TMS34010:

TMS34010
TMS34020

Offline CaptainCPS

  • Administrator
  • *****
  • Posts: 1520
  • Karma: +126/-0
  • FB Alpha Team
    • CaptainCPS's Home
Re: Romhack's WIP thread
« Reply #47 on: April 07, 2015, 05:06:05 pm »
First of all, hiyas everyone!!  :biggrin: I hope everyone is doing alright. I have been watching the progress of FBA through my email (Assembla notifications), even when I was not able to come and participate here as I used to. I am happy that FB Alpha project has continued growing and evolving.

Nice to meet you Romhack and dink, I been following your updates and man! they are awesome :D you guys are great! keep up your great work!

Congrats to everyone (JacKc, iq_132, Barry, dink, Romhack, and company!) on everything that has been implemented to FBA through all this time.

Take care guys!

SeeYa!
 :biggrin:

Offline dink

  • Administrator
  • *****
  • Posts: 2677
  • Karma: +227/-0
  • feed the horse yumyum
Re: Romhack's WIP thread
« Reply #48 on: April 07, 2015, 06:19:07 pm »
Hi CaptainCPS, nice to finally meet you :)  FBA is the greatest! :)

best regards,
- dink

Offline Romhack

  • Expert
  • *****
  • Posts: 94
  • Karma: +49/-0
Re: Romhack's WIP thread
« Reply #49 on: April 08, 2015, 05:47:50 pm »
Thanks and nice to meet you too, CaptainCPS  :biggrin:
----

Well, I think it's time to write some TM34010's video routines, MK3 already writes to these registers (also into DMA registers, MidwayPic, etc...)  ;p
https://bitbucket.org/zxmarcos/tms34010emu/src

Offline iq_132

  • Administrator
  • *****
  • Posts: 3580
  • Karma: +376/-0
  • Just a lion with a sword
    • NeoSource
Re: Romhack's WIP thread
« Reply #50 on: April 08, 2015, 08:43:36 pm »
Nice to see you again Cap! I would love to see you active again, even just a little bit. :)

I always start to miss people like Jimmy_Page, Ferchogtx, and kenshiro when I see someone who hasn't been active in a long time.


Offline JacKc

  • FBA Dev
  • ******
  • Posts: 1562
  • Karma: +51/-0
  • Sarah Connor !?
Re: Romhack's WIP thread
« Reply #51 on: April 09, 2015, 06:38:05 am »
Welcome back Cap!

Like iq said, i will be happy to see you acive again  :smilie:


Offline dink

  • Administrator
  • *****
  • Posts: 2677
  • Karma: +227/-0
  • feed the horse yumyum
Re: Romhack's WIP thread
« Reply #52 on: May 08, 2015, 07:04:58 pm »
Romhack, I finally got Killer Instinct running on my PC :) (13 frames/sec on my p4!)
Theres a few problems, though...

in dcs2k.cpp, in Dcs2kRender() it overflows the soundbuffer (causing a crash):
Code: [Select]
    for (int i = 0; i < nSegmentLenght; i++) {
INT16 sample = pSoundBuffer->sample();
pSoundBuf[i * 2 + 0] = sample;
pSoundBuf[i * 2 + 1] = sample;
}
the * 2 should not be there, I think?

also, I get a division by zero crash on line 99:
Code: [Select]
    T sample() {
        int sum = 0;
        for (int x = 0; x < t2h_count; x++)
sum += next();
        return sum / t2h_count;
    }

I changed it to:
Code: [Select]
        return (t2h_count) ? sum / t2h_count : 0; and removed the * 2 from indexing pSoundBuf[].  Now it runs fine, but theres no sound at all.  Ideas? :)

best regards,
- dink
« Last Edit: May 08, 2015, 07:06:55 pm by dink »

Offline Romhack

  • Expert
  • *****
  • Posts: 94
  • Karma: +49/-0
Re: Romhack's WIP thread
« Reply #53 on: May 08, 2015, 08:01:27 pm »
Romhack, I finally got Killer Instinct running on my PC :) (13 frames/sec on my p4!)
Theres a few problems, though...

in dcs2k.cpp, in Dcs2kRender() it overflows the soundbuffer (causing a crash):
Code: [Select]
    for (int i = 0; i < nSegmentLenght; i++) {
INT16 sample = pSoundBuffer->sample();
pSoundBuf[i * 2 + 0] = sample;
pSoundBuf[i * 2 + 1] = sample;
}
the * 2 should not be there, I think?
*2 is for stereo pBurnSoundOut (linux default configuration is 22kHz stereo). I don't know if FBA uses stereo sound on windows.

Quote
also, I get a division by zero crash on line 99:
Code: [Select]
    T sample() {
        int sum = 0;
        for (int x = 0; x < t2h_count; x++)
sum += next();
        return sum / t2h_count;
    }

I changed it to:
Code: [Select]
        return (t2h_count) ? sum / t2h_count : 0; and removed the * 2 from indexing pSoundBuf[].  Now it runs fine, but theres no sound at all.  Ideas? :)

best regards,
- dink

The problem is native sample rate of FBA. FBA SampleRate needs to be lower than 31250Hz (KI e KI2 samplerate), look at this code:
Code: [Select]
    void set_host_rate(int freq) {
        host_rate = freq;
        factor = static_cast<double>(host_rate) / static_cast<double>(target_rate);
        unused = target_rate * factor;
        t2h_count = target_rate / unused;
    }
I used a naive approach to downsample from 31250Hz to 22000Hz, It calculates the factor between fba samplerate (host_rate) and driver samplerate (target_rate), then I calculate how many samples it needs to "ignore". t2h_count is just how many samples to skip on driver original sound to match FBA sound output frequency. However, if host_rate < target_rate, then factor is <0, unused is an integer so it's truncated to 0.

Code: [Select]
T sample() {
        int sum = 0;
        for (int x = 0; x < t2h_count; x++)
            sum += next();
        return sum / t2h_count;
    }
It just calculates arithmetic mean of skipped samples, each FBA samples needs t2h_count driver samples  :smilie:.

Offline Treble Winner

  • FBA Dev
  • ******
  • Posts: 1814
  • Karma: +105/-0
  • FB Alpha Team
    • http://www.barryharris.me.uk
Re: Romhack's WIP thread
« Reply #54 on: May 09, 2015, 12:19:07 pm »
Romhack,

I have the KI stuff building in MinGW (GCC4.9) and MSVC 2013 (x86 only).

I'm nearly there with the x64 DRC, but they both MinGW and MSVC are falling over at the same points;

mips3_x64_ew.h (lines 27 and 42, called via the macros)
Code: [Select]
F_ADR(mips3::translate)
and;

mips3_x64.cpp (line 458)
Code: [Select]
mov(rax, (size_t) (void*)f);
MSVC is complaining with the following;

Quote
Compiling src/cpu/mips3/x64/mips3_x64.cpp...
mips3_x64.cpp
d:\fbasrc\src\cpu\mips3\x64\mips3_x64_rw.h(59) : error C2440: 'type cast' : cann
ot convert from 'uint32_t (__cdecl mips::mips3::* )(mips::addr_t,mips::addr_t *)
' to 'void *'
        There is no context in which this conversion is possible
d:\fbasrc\src\cpu\mips3\x64\mips3_x64_rw.h(59) : error C2661: 'Xbyak::CodeGenera
tor::mov' : no overloaded function takes 1 arguments

and;

Quote
Compiling src/cpu/mips3/x64/mips3_x64.cpp...
mips3_x64.cpp
src/cpu/mips3/x64/mips3_x64.cpp(458) : error C2440: 'type cast' : cannot convert
 from 'void (__cdecl mips::mips3::* )(uint32_t)' to 'void *'
        There is no context in which this conversion is possible
src/cpu/mips3/x64/mips3_x64.cpp(458) : error C2661: 'Xbyak::CodeGenerator::mov'
: no overloaded function takes 1 arguments

If I remove the offending code, both GCC and MSVC compile and link fine (but crash on starting the driver).

Any ideas on how to do this in a more compliant, compiler friendly way?

Looks like there are some endian issues to resolve, but I can look at these when we are building ok!
« Last Edit: May 09, 2015, 12:20:30 pm by Treble Winner »

Offline iq_132

  • Administrator
  • *****
  • Posts: 3580
  • Karma: +376/-0
  • Just a lion with a sword
    • NeoSource
Re: Romhack's WIP thread
« Reply #55 on: May 09, 2015, 01:53:12 pm »
Romhack,

I have the KI stuff building in MinGW (GCC4.9) and MSVC 2013 (x86 only).

I'm nearly there with the x64 DRC, but they both MinGW and MSVC are falling over at the same points;

mips3_x64_ew.h (lines 27 and 42, called via the macros)
Code: [Select]
F_ADR(mips3::translate)
and;

mips3_x64.cpp (line 458)
Code: [Select]
mov(rax, (size_t) (void*)f);
MSVC is complaining with the following;

and;

If I remove the offending code, both GCC and MSVC compile and link fine (but crash on starting the driver).

Any ideas on how to do this in a more compliant, compiler friendly way?

Looks like there are some endian issues to resolve, but I can look at these when we are building ok!

Can you create a trampoline function that is void ?


Offline Romhack

  • Expert
  • *****
  • Posts: 94
  • Karma: +49/-0
Re: Romhack's WIP thread
« Reply #56 on: May 09, 2015, 07:05:43 pm »
Can you create a trampoline function that is void ?

I did not know but we can't take address of a member function on C++ standard  :eek: https://isocpp.org/wiki/faq/pointers-to-members#cant-cvt-memfnptr-to-voidptr.

I'm thinking of turning this code:
Code: [Select]
class cpu {
    int reg;
    void inc(uint32_t opcode) {
        reg++;
    }
}

into:

Code: [Select]
class cpu {
    int reg;
    static inline void add(cpu *p, uint32_t opcode) {
        p->reg++;
    }
}
Dolphin uses this style.


With MSVC, there's another issue: the ABI, current calling ABI (used on mips3_x64::fallback and mips3_x64_rw.h) is SysV AMD64: http://en.wikipedia.org/wiki/X86_calling_conventions.


Offline Treble Winner

  • FBA Dev
  • ******
  • Posts: 1814
  • Karma: +105/-0
  • FB Alpha Team
    • http://www.barryharris.me.uk
Re: Romhack's WIP thread
« Reply #57 on: May 12, 2015, 12:51:51 pm »
I have x64 building with GCC now - but it crashes at driver start. GDB gives;

Code: [Select]
Program received signal SIGSEGV, Segmentation fault.
0x000000000101a92c in mips::mips3::tlb_translate(unsigned long long) ()
(gdb) bt
#0  0x000000000101a92c in mips::mips3::tlb_translate(unsigned long long) ()
#1  0x0000000007b09ec0 in ?? ()
#2  0x000000000022e768 in ?? ()
#3  0x8b4d07a85610bf41 in ?? ()
#4  0x0000000001078481 in std::__detail::_Map_base<unsigned long long, std::pair<unsigned long long const, void*>, std::allocator<std::pair<unsigned long long const, void*> >, std::__detail::_Select1st, std::equal_to<unsigned long long>, std::hash<unsigned long long>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true>, true>::operator[](unsigned long long const&) ()
#5  0x000000000022e7d0 in ?? ()
#6  0x0000000000eb2e09 in mips::mips3::translate(unsigned long long, unsigned long long*) ()
#7  0x000000000ec218c4 in ?? ()
#8  0x00000000000018c4 in ?? ()
#9  0x0000000007a85250 in ?? ()
#10 0x0000000007a84990 in ?? ()
#11 0x0000000007a84ab0 in ?? ()
#12 0x0000000000eb09cc in mips::mips3::SW(unsigned int) ()
#13 0x000000000ec218c4 in ?? ()
#14 0x00000000000018c4 in ?? ()
#15 0x000000000022e7f0 in ?? ()
#16 0x0000000000000004 in ?? ()
#17 0xffffffffbfc003cc in ?? ()
#18 0x00000000000018c4 in ?? ()
#19 0x000000000022e810 in ?? ()
#20 0x000000000ec2192e in ?? ()
#21 0x000000000ec218c4 in ?? ()
#22 0x000000000ec218c4 in ?? ()
#23 0x0000000000000000 in ?? ()
(gdb)

Any ideas?

Offline Romhack

  • Expert
  • *****
  • Posts: 94
  • Karma: +49/-0
Re: Romhack's WIP thread
« Reply #58 on: May 12, 2015, 06:41:05 pm »
Just ABI problems. Replace prolog, epilog and fallback functions on mips3_x64.cpp to:


mips3_x64::fallback()
Code: [Select]
void mips3_x64::fallback(uint32_t opcode, void (mips3::*f)(uint32_t))
{
#ifdef _WIN32
    // WIN64 ABI - MICROSOFT
    mov(rcx, (size_t) m_core);
    mov(edx, opcode);
#else
    // SysV AMD64 ABI - GNU
    mov(rdi, (size_t) m_core);
    mov(esi, opcode);
#endif
    mov(rax, (size_t) (void*)f);
    call(rax);
}


mips3_x64::prolog()
Code: [Select]
void mips3_x64::prolog()
{
    // R15 = cycle counter
    // RBX = cpu_state base
    push(rbp);
    push(rbx);
#ifdef _WIN32
    push(rsi);
    push(rdi);
#endif
    push(r15);
    mov(rbp, rsp);
    sub(rsp, 16);
    mov(rbx, ADR(m_core->m_state));
    mov(r15, ADR(m_icounter));
    mov(r15, ptr[r15]);

    check_icounter();
}

mips3_x64::epilog(bool do_ret)
Code: [Select]
void mips3_x64::epilog(bool do_ret)
{
    add(rsp, 16);
    mov(rax, ADR(m_icounter));
    mov(ptr[rax], r15);
    pop(r15);
#if _WIN32
    pop(rdi);
    pop(rsi);
#endif
    pop(rbx);
    pop(rbp);
    if (do_ret)
        ret();
}


Now it's running. I need to rewrite functions in mips3_x64_rw.h (even on linux they are disabled).

Offline Treble Winner

  • FBA Dev
  • ******
  • Posts: 1814
  • Karma: +105/-0
  • FB Alpha Team
    • http://www.barryharris.me.uk
Re: Romhack's WIP thread
« Reply #59 on: May 12, 2015, 07:15:30 pm »
Thanks Romhack - MinGW64 is now running without crashing.

If we could just fix the compile errors for MSVC x64 we'd be sorted for building.