gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Manage timer

#21079 - coredump - Sun May 23, 2004 4:19 pm

Hello,

I'm new on GBA development and I'd like to manage a timer for
buffered all gamepad during a moment in order to check eventual
"combos". So, my idea is to put the timer 2 on cascade and check
a "combos" during a cycle of 10 * 0.25us. Nothing work :(

my code:

Code:

#define TIMER1_CR               *(volatile u16 *)0x4000106
#define TIMER2_CR               *(volatile u16 *)0x400010A
 
 
#define TIMER1_DATA            *(volatile u16 *)0x4000104
#define TIMER2_DATA            *(volatile u16 *)0x4000108
 
#define ENABLE_TIMER           (1 << 7)
#define IRQ_TIMER              (1 << 6)
#define CASCADE_TIMER          (1 << 2)
 
#define RATIO_64                 0x1
 
int    get_key(void)
{
   int key;
   u16  cycle;
 
   TIMER1_CR = RATIO_64 | ENABLE_TIMER | IRQ_TIMER;
   TIMER2_CR = CASCADE_TIMER | ENABLE_TIMER;
   key = 0;
   while ((cycle = TIMER2_DATA) < 10)
   {
        /* buffered key.*/
   }
   return (key);
}


thx.

#21080 - poslundc - Sun May 23, 2004 5:30 pm

Finite State Machines

Dan.

#21083 - dagamer34 - Sun May 23, 2004 6:36 pm

poslundc wrote:
Finite State Machines

Dan.


I think Dan is tired of saying Finite State Machines to answer these kinds of problems. Maybe it's time to put this in the FAQ, don't you think tepples?

And tepples, you need to update the linker section of the FAQ as Success-HK and MW Electronics no longer sell flash carts.
_________________
Little kids and Playstation 2's don't mix. :(

#21091 - mr_schmoe - Sun May 23, 2004 8:27 pm

I don't think that answered his question. I'm assuming he's trying to do something like a Mortal Kombat type game (correct me if I'm wrong) where a certain combonation of buttons produces a special attack. Now, if that's the case, what the hell does a finite state machine have to do with that. It's my understanding that a finite state machine in respect to a game, only means that each character has a finite number of states or modes or actions being preformed or whatever and the key input changes that state based on whatever the programmer decides it needs to do. So, again, what does FSM have to do with checking key combos over a period of time.

My suggestion is you use a keyboard interrupt. That way, you can store the key data directy into a buffer and check it in you main loop for the correct combonations and reset the buffer accordingly.

#21097 - tepples - Sun May 23, 2004 9:30 pm

dagamer34 wrote:
I think Dan is tired of saying Finite State Machines to answer these kinds of problems. Maybe it's time to put this in the FAQ, don't you think tepples?

And tepples, you need to update the linker section of the FAQ as Success-HK and MW Electronics no longer sell flash carts.

Phicks'd on both accounts.

mr_schmoe wrote:
I'm assuming he's trying to do something like a Mortal Kombat type game (correct me if I'm wrong) where a certain combonation of buttons produces a special attack. Now, if that's the case, what the hell does a finite state machine have to do with that.

For each one-on-one karate game, there exists an alphabet of button presses such as "up", "forward", and "kick". For each different playable character, there exists a regular language whose strings are the set of moves that result in magic attacks. For example, for some characters in some Street Fighter II knockoffs such as Data East's Fighter's History and Interplay's Clay Fighter, the string "forward down forward punch" produces an upward attack, "down forward punch" produces a fireball, and "down back kick" produces a whirling attack. A finite state machine (also called a finite automaton) "decides" a regular language, that is, it produces a 1 if a string is a move and a 0 if not.

Many games read symbols from the joypad at 60 Hz, but some fighter players are faster than that. Now it seems coredump is trying to sample the joypad faster than 60 Hz in order to read symbols as fast as players can generate them.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#21107 - poslundc - Sun May 23, 2004 11:04 pm

dagamer34 wrote:
I think Dan is tired of saying Finite State Machines to answer these kinds of problems.


Yeah, I just had a look at my post and it was pretty glib. It was late and I was tired; sorry about that.

mr_schmoe: in addition to what tepples has already said I'll summarize by saying FSMs provide a structure with which you can handle a series of decisions from one input to the next. This is precisely the kind of thing people are looking to do in GBA programming, whether it's detecting something as simple as the moment a button is released after being pressed, or detecting a complicated series of inputs in a given timeframe. Let me know if you desire a more specific example.

Dan.

#21124 - coredump - Mon May 24, 2004 11:24 am

Quote:

I'm assuming he's trying to do something like a Mortal Kombat type game (correct me if I'm wrong) where a certain combonation of buttons produces a special attack.


You'r right.

Quote:

My suggestion is you use a keyboard interrupt. That way, you can store the key data directy into a buffer and check it in you main loop for the correct combonations and reset the buffer accordingly.


What do you mean by "interrupt keyboard" ? It seemed to be a good way
but i "interrupot keyboard" is weird for me.

Regards.

#21133 - coredump - Mon May 24, 2004 4:56 pm

Ok, after the loop I reset the TIMER2_DATA and it's work but it seems
that the "loop time" is too high I changed:
Code:

while ((cycle = TIMER2_DATA) < 10)

by :
Code:

while ((cycle = TIMER2_DATA) < 1)


with the same frequence "RATIO_64" then I'd like to know why the loop
is too low because:
tepples wrote:

Many games read symbols from the joypad at 60 Hz, but some fighter players are faster than that. Now it seems coredump is trying to sample the joypad faster than 60 Hz in order to read symbols as fast as players can generate them.


Regards.