How to make bit toggle by change?

If you are having problems finding or using cheats for an Emulator (particularly MAME/MESS) or have found a trick that you wish to share this is the place to do it. But please read the Cheat FAQ first.
Post Reply
User avatar
NotAGoodName
Posts: 331
Joined: Wed Feb 18, 2009 7:09 am
Location: MO, USA
Contact:

How to make bit toggle by change?

Post by NotAGoodName »

Ok. I'm almost done with Shining Force 2. All 1MB+ of it. I've run into a problem, however. I want to make a cheat where you can toggle a bit value using a change value cheat. This cheat surprisingly half way works, and it works on the part I didn't think would work. The problem is that it isn't detecting the set value properly to perform the disable half.

Example:

Code: Select all

	<cheat desc="Force Status Toggle (Group 1)">
		<parameter>
			<item value="0x80">Bowie (avoid)</item>
			<item value="0x40">Sarah</item>
			<item value="0x20">Chester</item>
			<item value="0x10">Jaha</item>
			<item value="0x08">Kazin</item>
			<item value="0x04">Slade</item>
			<item value="0x02">Kiwi</item>
			<item value="0x01">Peter</item>
		</parameter>
		<script state="change">
			<action condition="maincpu.pb@FFF68A==param|(maincpu.pb@FFF68A BAND ~param)">maincpu.pb@FFF68A=00|(maincpu.pb@FFF68A BAND ~param)</action>
			<action condition="maincpu.pb@FFF68A==00|(maincpu.pb@FFF68A BAND ~param)">maincpu.pb@FFF68A=param|(maincpu.pb@FFF68A BAND ~param)</action>
		</script>
	</cheat>
Detecting that the bit at the parameter is 00 works (second action). First action fails.
Aww yeah. AMD A10-7850K givin' MAME and MESS systems what for.
User avatar
Pugsy
Posts: 3675
Joined: Fri Aug 17, 2001 12:59 am
Location: North Wales, UK.
Has thanked: 1 time
Been thanked: 15 times
Contact:

Re: How to make bit toggle by change?

Post by Pugsy »

Bit of over-engineering there me thinks...

A simple binary Exclusive OR should do the trick.

Code: Select all

   <cheat desc="Force Status Toggle (Group 1)">
      <parameter>
         <item value="0x80">Bowie (avoid)</item>
         <item value="0x40">Sarah</item>
         <item value="0x20">Chester</item>
         <item value="0x10">Jaha</item>
         <item value="0x08">Kazin</item>
         <item value="0x04">Slade</item>
         <item value="0x02">Kiwi</item>
         <item value="0x01">Peter</item>
      </parameter>
      <script state="change">
         <action>maincpu.pb@FFF68A=(maincpu.pb@FFF68A ^ param)</action>
      </script>
   </cheat>
Pugsy

Servicing your cheating needs since 1985 8)

Grab the latest cheat collection:
MAME 0.264 XML cheat collection (3 APRIL 2024) from http://www.mamecheat.co.uk or direct from:-
https://mega.nz/file/SxsQUJoT#jBdz6GLm_ ... QzFGSMms2c (ZIP Archive 3.8 MB)
User avatar
NotAGoodName
Posts: 331
Joined: Wed Feb 18, 2009 7:09 am
Location: MO, USA
Contact:

Re: How to make bit toggle by change?

Post by NotAGoodName »

That did the trick. Thanks again.

I should learn C. Then I could do MATLAB. Err...I mean make genesis.c suck less.
Aww yeah. AMD A10-7850K givin' MAME and MESS systems what for.
Post Reply