Crashing by an Unknown reason

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
DeoxysKyogre
Newbie
Posts: 2
Joined: Sat Jan 21, 2012 6:19 pm
Location: Wily's Castle

Crashing by an Unknown reason

Post by DeoxysKyogre »

I was doing an ability for Dark Super Sonic, called the Dark Rings Attack, for my hack of Sonic 1. It has a new object "Object 10", but for example if you perform it it sometimes crashes, in some places and moments. I've also noticed that it's all because of the dbf there, but I don't know how to fix it.
The code:

Obj10: ; XREF: Obj_Index
moveq #0,d0
move.b $24(a0),d0
move.w Obj10_Index(pc,d0.w),d1
jmp Obj10_Index(pc,d1.w)
; ===========================================================================
Obj10_Index: dc.w Obj10_Main-Obj10_Index
dc.w Obj10_Move-Obj10_Index
; ===========================================================================

Obj10_Main: ; XREF: Obj3B_Index
move.w ($FFFFD008).w,8(a0) ; match X position with Sonic
move.w ($FFFFD00C).w,$C(a0) ; match Y position with Sonic
movea.l a0,a1
moveq #0,d3
moveq #1,d2
moveq #0,d1
move.b #5,d1

Obj10_MainLoop:
move.l d1,-(sp)

move.b #$10,(a1) ; load chaos emerald object
addq.b #2,$24(a1)
move.l #Map_obj25,4(a1)
move.w #$27B2,2(a1)
move.b #4,1(a1)
move.b #1,$18(a1)
move.w 8(a0),$38(a1)
move.w $C(a0),$3A(a1)
move.b #50,$30(a0)
move.b #100,$31(a0)
;move.b d2,$1C(a1)
;move.b d2,$1A(a1)
;addq.b #1,$33(a1)
move.b d3,$26(a1)
addi.b #$2A,d3
move.b #1,$16(a1)

lea $40(a1),a1

move.l (sp)+,d1
dbf d1,Obj10_MainLoop ; repeat 5 more times


Obj10_Move: ; XREF: Obj88_Index
subq.b #1,$30(a0)
subq.b #1,$31(a0)
move.w $3E(a0),d0
add.w d0,$26(a0)
move.b $26(a0),d0
jsr (CalcSine).l
moveq #0,d4
move.b $3C(a0),d4
muls.w d4,d1
asr.l #8,d1
muls.w d4,d0
asr.l #8,d0
add.w $38(a0),d1
add.w $3A(a0),d0
move.w d1,8(a0)
move.w d0,$C(a0)
cmpi.w #$E000,$3C(a0)
beq.s loc2_55FA
addi.w #$100,$3C(a0)

loc2_55FA:
tst.b $30(a0)
bne.s NiuCoud
clr.b ($FFFFF7C8).w
NiuCoud:
cmpi.w #$2000,$3E(a0)
beq.s loc2_5608
addi.w #$20,$3E(a0)


loc2_5608:
cmpi.w #$140,$3A(a0)
beq locret2_5614
;subq.w #1,$3A(a0)

locret2_5614:
tst.b $31(a0)
bne.s loldisplay
jmp DeleteObject
Loldisplay
move.b #2,$1C(a0)
jsr TouchResponse
jmp DisplaySprite

The problem is in Obj10_MainLoop. If you know why this is happening, please tell me how to fix it, if you can.

Thanks in advance.
fletto
Newbie
Posts: 6
Joined: Wed May 23, 2012 5:17 pm

Re: Crashing by an Unknown reason

Post by fletto »

DeoxysKyogre wrote:I was doing an ability for Dark Super Sonic, called the Dark Rings Attack, for my hack of Sonic 1. It has a new object "Object 10", but for example if you perform it it sometimes crashes, in some places and moments. I've also noticed that it's all because of the dbf there, but I don't know how to fix it.
The code:

Obj10: ; XREF: Obj_Index
moveq #0,d0
move.b $24(a0),d0
move.w Obj10_Index(pc,d0.w),d1
jmp Obj10_Index(pc,d1.w)
; ===========================================================================
Obj10_Index: dc.w Obj10_Main-Obj10_Index
dc.w Obj10_Move-Obj10_Index
; ===========================================================================

Obj10_Main: ; XREF: Obj3B_Index
move.w ($FFFFD008).w,8(a0) ; match X position with Sonic
move.w ($FFFFD00C).w,$C(a0) ; match Y position with Sonic
movea.l a0,a1
moveq #0,d3
moveq #1,d2
moveq #0,d1
move.b #5,d1
*Snip*
It might be some issue with leftover values on D1 (your loop counter -- IIRC dbf takes 16 bits of the target register into account.)
Try moveq #5, d1 or move.w #5, d1 instead, I'm guessing it'll fix the problem. Hope that helps.

*Edit* Nevermind, I didn't notice the previous moveq #0, d1, that should clear out the upper bits. Dang.

*Edit 2*

Obj10_Index: dc.w Obj10_Main-Obj10_Index
dc.w Obj10_Move-Obj10_Index

Are you sure the compiler generated these two offsets properly? Could it be that the second entry is pointing to your dbf opcode by mistake?
DeoxysKyogre
Newbie
Posts: 2
Joined: Sat Jan 21, 2012 6:19 pm
Location: Wily's Castle

Re: Crashing by an Unknown reason

Post by DeoxysKyogre »

fletto wrote:
It might be some issue with leftover values on D1 (your loop counter -- IIRC dbf takes 16 bits of the target register into account.)
Try moveq #5, d1 or move.w #5, d1 instead, I'm guessing it'll fix the problem. Hope that helps.

*Edit* Nevermind, I didn't notice the previous moveq #0, d1, that should clear out the upper bits. Dang.

*Edit 2*

Obj10_Index: dc.w Obj10_Main-Obj10_Index
dc.w Obj10_Move-Obj10_Index

Are you sure the compiler generated these two offsets properly? Could it be that the second entry is pointing to your dbf opcode by mistake?
Nevermind, I have done another method and it worked. Thanks anyways! :D
Post Reply