Home Page
Posted By: Golden Child apple2 conan joystick weirdness - 05/04/22 06:19 PM
Hi guys,

Was watching some longplays on youtube and got inspired to play Datasoft Conan but I had some weirdness with the joystick.


For some reason, using apple2e the joystick isn't working correctly, I can't go up the ladder.

Apple2p works. Apple2c works.

but strangely apple2e and apple2ee doesn't work.

I try a little basic program

100 ? PDL(0), PDL(1)
110 GOTO 100

and it doesn't seem to respond for apple2e. For apple2p only PDL(1) seems to respond. I'm kinda baffled.

I tried total replay and it said no joystick detected and I've got -gameio joy specified.


edit:
total replay with apple2p 242 detects joystick
total replay with apple2p 243 doesn't detect joystick

(both self compiled)
Posted By: R. Belmont Re: apple2 conan joystick weirdness - 05/04/22 09:06 PM
That's bizarre. Literally nothing changed in apple2p or the gameio stuff for 243.
Posted By: Golden Child Re: apple2 conan joystick weirdness - 05/04/22 10:44 PM
Yeah, I don't know if there's something wrong with this computer.

What's really wacky is that sometimes when I launch my self compiled mame 243 with Total Replay sometimes it will detect the joystick and sometimes it won't. I always thought it was supposed to be deterministic, but maybe it's one of those uninitialized memory things or memory's getting trashed.
Posted By: Vas Crabb Re: apple2 conan joystick weirdness - 05/05/22 04:57 AM
Use a debug build? Use valgrind to catch uninitialised memory?
Posted By: Alegend45 Re: apple2 conan joystick weirdness - 05/05/22 04:29 PM
Wasn't 0.243 the release MAME finally merged drvnoclear? Maybe this is fallout from that.
Posted By: R. Belmont Re: apple2 conan joystick weirdness - 05/05/22 04:45 PM
That's a very good point. I'll check for uninitialized variables.
Posted By: Golden Child Re: apple2 conan joystick weirdness - 05/05/22 05:44 PM
I installed Valgrind and ran with it and it says "Conditional jump or move depends on uninitialized value(s) and it lists apple2_state::controller_strobe_w".

maybe it fails to handle the case where m_joystick_x1_time < machine time and never updates the m_joystick_x1_time (like NaN comparison or something) because I don't see where m_joystick_x1_time (and the others get initialized)


Code
void apple2_state::controller_strobe_w(u8 data)
{
        // 558 monostable one-shot timers; a running timer cannot be restarted
        if (machine().time().as_double() >= m_joystick_x1_time)
        {
                m_joystick_x1_time = machine().time().as_double() + m_x_calibration * m_gameio->pdl0_r();
        }
        if (machine().time().as_double() >= m_joystick_y1_time)
        {
                m_joystick_y1_time = machine().time().as_double() + m_y_calibration * m_gameio->pdl1_r();
        }
        if (machine().time().as_double() >= m_joystick_x2_time)
        {
                m_joystick_x2_time = machine().time().as_double() + m_x_calibration * m_gameio->pdl2_r();
        }
        if (machine().time().as_double() >= m_joystick_y2_time)
        {
                m_joystick_y2_time = machine().time().as_double() + m_y_calibration * m_gameio->pdl3_r();
        }

}
Posted By: Just Desserts Re: apple2 conan joystick weirdness - 05/05/22 10:27 PM
Originally Posted by Golden Child
maybe it fails to handle the case where m_joystick_x1_time < machine time and never updates the m_joystick_x1_time (like NaN comparison or something) because I don't see where m_joystick_x1_time (and the others get initialized)

You mean it fails to handle the case where m_joystick_*_time > machine_time. Every one of those checks is a less-than check. The relevant members should simply be initialized to zero.
Posted By: Golden Child Re: apple2 conan joystick weirdness - 05/05/22 10:54 PM
You're right, JD.

If one of the variables is NaN the comparison will always fail. So if the uninitialized variable gets NaN the comparison fails and then it will never get updated.

At least that's the way I understand it. (Plugging NaN < 1.0 into firefox's console gives false)

"If your compiler produces a NaN, it has the unusual property that it is not equal to any value, including itself. For example, if a is NaN, then a == a is false. In fact, if a is NaN, then a will be neither less than, equal to, nor greater than any value including itself. In other words, regardless of the value of b, a < b, a <= b, a > b, a >= b, and a == b will all return false."

Also, if the uninitialized variable m_joystick_x1_time is large, the comparison (machine().time().as_double() >= m_joystick_x1_time) will not be true and it will never update the m_joystick_x1_time.
Posted By: R. Belmont Re: apple2 conan joystick weirdness - 05/06/22 02:07 AM
Right, it's just that those aren't initialized in apple2.cpp or apple2e.cpp (but they are in apple2gs.cpp). I'll check in a fix in a minute. (And thanks to Alegend for suggesting what was actually the problem!).
Posted By: Golden Child Re: apple2 conan joystick weirdness - 05/06/22 09:11 AM
Thanks RB, Alegend45, Vas and JD. Glad to know it wasn't gremlins in my system.
© Forums