Help with some programming problems - collision

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
theelf
Newbie
Posts: 6
Joined: Fri Aug 06, 2010 12:59 pm

Help with some programming problems - collision

Post by theelf » Fri Aug 06, 2010 1:16 pm

Hi! im new here, thanks for this great forum, and sorry my english


I´m programming in Basiegaxorz, and i have a problem with collision between sprites

I use this code to check the collision flag of the vdp

Code: Select all

peekint(&hC00004).5
The problem is that the code works OK in some emulators, like Gens, and in a Megadrive chinesse clone.....

But in Fusion and real Megadrive no work.... :(

Could someone help to find the problem? thanxs!!!!

Cristian



PD: Small BEX code

Code: Select all

 a=addsprite(1,1)
 b=addsprite(1,1)
 propsprite a,1,1
 propsprite b,2,2
 movesprite a,256,256
 c=300
 while 1
   movesprite b,256,c
   sleep 1
   c=c-4
   d=peekint(&hC00004).5
  locate 0,0
  print d
 wend

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Fri Aug 06, 2010 2:25 pm

Probably read aligment problem, similar to one which was in BEX TFD player. Try to use assembly inline instead of peekint.

theelf
Newbie
Posts: 6
Joined: Fri Aug 06, 2010 12:59 pm

Post by theelf » Fri Aug 06, 2010 2:39 pm

Probably read aligment problem, similar to one which was in BEX TFD player. Try to use assembly inline instead of peekint.
Hi, thanks for the reply. I make the function in assembler, but same problem. Works in gens, not in Fusion...


Code: Select all

 a=addsprite(1,1)
 b=addsprite(1,1)
 propsprite a,1,1
 propsprite b,2,2
 movesprite a,256,256
 c=300
 while 1
   movesprite b,256,c
   sleep 1
   c=c-4
   d=Colision()
  locate 0,0
  print d
 wend


Declare Asm Function Colision()
 move.w ($C00004),d0
 andi.l #%100000,d0
 lsr.b #5,d0
End Function

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Fri Aug 06, 2010 2:48 pm

There is also a note in Charles McDonald's doc you may need to take into account:
This bit is most likely cleared at the end of the frame.
Actually, you'd better to solve the problem in the right way: do not use the flag at all, because it has very limited use.

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Fri Aug 06, 2010 3:05 pm

Yep, on my (old) collide doc, I explain how to handle sprite collision...and avoid this unuseful bit!

theelf
Newbie
Posts: 6
Joined: Fri Aug 06, 2010 12:59 pm

Post by theelf » Fri Aug 06, 2010 3:38 pm

There is also a note in Charles McDonald's doc you may need to take into account:

Quote:
This bit is most likely cleared at the end of the frame.

Yes, i know this line of this Doc. Because i don't understand to much what he say, when i read, i try to put the collision code, before sleep, after sleep, using tvblank, waitraster...

Even i make a raster effect in middle of screen, and put code inside, whiteout luck...

Yep, on my (old) collide doc, I explain how to handle sprite collision...and avoid this unuseful bit!
Hi, thanks for reply!! i read your doc, but sorry, i don´t find when you explain how to solve the problem of the bit,

can you point me in where part of the doc is the solution? thank you

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Fri Aug 06, 2010 5:23 pm

I meant how to avoid using the bit

theelf
Newbie
Posts: 6
Joined: Fri Aug 06, 2010 12:59 pm

Post by theelf » Fri Aug 06, 2010 6:52 pm

I meant how to avoid using the bit

Ah ok, well i want to use it, thanxs anyway for your help, and good tutorial, i use my own method for collisions but i take notes of yours! ! :) thanks for your work


Still i´m keep looking for solution to the collision flag... hope, someone have some idea where the problem is ... ?¿

thanxs

Eke
Very interested
Posts: 884
Joined: Wed Feb 28, 2007 2:57 pm
Contact:

Post by Eke » Sat Aug 07, 2010 8:05 am

This flag is set when non-transparent and visible sprites overlap.
It is set on the first line shared by the 2 sprites (VDP is drawing screen line by line).
It is cleared either on line 0 or line 224 (not sure about that but what is sure is collision cannot happen after line 224) and also after the VDP status has been read.

With that said, by using sleep(1), it's very unlikely you will fall exactly in the short period where the flag is being set, you should probably program an horizontal interrupt on each line and check the flag here, if it is set, you would know that collision occured on the previous line.

theelf
Newbie
Posts: 6
Joined: Fri Aug 06, 2010 12:59 pm

Post by theelf » Sat Aug 07, 2010 3:33 pm

With that said, by using sleep(1), it's very unlikely you will fall exactly in the short period where the flag is being set, you should probably program an horizontal interrupt on each line and check the flag here, if it is set, you would know that collision occured on the previous line.
Hi, thanxs for reply. Can you make a example how to program a horizontal interrupt?

I try using waitraster instead sleep, and try every number and combination, with halt,valt,dalt... etc no luck

Every test, works ok on Gens, and no works on Fusion... maybe knows whats the difference on both emulators help me...

Im stuck with this problem...

Thanxs [/quote]

Eke
Very interested
Posts: 884
Joined: Wed Feb 28, 2007 2:57 pm
Contact:

Post by Eke » Sat Aug 07, 2010 4:15 pm

theelf wrote:
Hi, thanxs for reply. Can you make a example how to program a horizontal interrupt?
you must write $00 to VDP register $0A to make HINT occurs every line ($01 every 2 lines, etc) and $14 to VDP register $00 to enable HINT.

you must also program a proper HINT callback in your code (interrupt level 4) and set the CPU interrut mask properly

I have no idea how you would do that in Basiegaxorz though...
Every test, works ok on Gens, and no works on Fusion... maybe knows whats the difference on both emulators help me...
simply because Gens does not accurately emulate this bit, it is set but never cleared, so once a collision has occurs, your code will always detect a collision on every frame, even if there isn't... still not very useful

theelf
Newbie
Posts: 6
Joined: Fri Aug 06, 2010 12:59 pm

Post by theelf » Sat Aug 07, 2010 8:02 pm

you must write $00 to VDP register $0A to make HINT occurs every line ($01 every 2 lines, etc) and $14 to VDP register $00 to enable HINT.

you must also program a proper HINT callback in your code (interrupt level 4) and set the CPU interrut mask properly
Thanks for your reply and time

Post Reply