Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - Psychotic Balloon (new tech demo game)

Reply to topic
Author Message
  • Joined: 18 Dec 2014
  • Posts: 95
  • Location: Canada
Reply with quote
Psychotic Balloon (new tech demo game)
Post Posted: Wed Nov 11, 2015 11:07 pm
; I'm using a animation state for aabb since I'm (new )can you guys show me a better way
ld a,(BalloonAnimationState)
add a,a
ld e,a
ld d,0
ld hl,BalloonBoundingBoxData
add hl,de
ld a,(hl)
inc hl
ld h,(hl)
ld l,a
jp (hl)
ret

;This is a problem I have Multi entries into my Collision calls
BalloonStraightFrameCollision:
ld hl,BalloonStraightCollisionData ;Here how would I create data drivin pointer,either I'm not thinking or I'm that dumb,
ld a,(YBalloon)
ld c,a
ld a,(XBalloon)
ld b,a
push bc
call Do_BallonTopCollision
pop bc
push bc
call Do_BalloonBottomCollision
pop bc
push bc
call Do_BalloonLeftCollision
pop bc
push bc
call Do_BalloonRightCollision
pop bc
ret




Do_ConvertXYToTile:
push hl
ld a,b
and 248
rrca
rrca
rrca
add a,a
ld e,a
ld d,0
ld a,c
and 248
rrca
rrca
rrca
add a,a
add a,a
add a,a
ld l,a
ld h,0
add hl,hl
add hl,hl
add hl,hl
; add hl,hl
add hl,de
ld de,TilePlacementData
add hl,de
ld a,(hl)
pop hl
ret




BalloonBoundingBoxData:
.dw BalloonLeftFrame2Collision
.dw BalloonLeftFrame1Collision
.dw BalloonStraightFrameCollision
.dw BalloonRightFrame1Collision
.dw BalloonRightFrame2Collision




BalloonStraightCollisionData:
.db $06,$04,$00,$04,$00,$00,$00,$00
.db $1f,$03,$00,$01,$00,$00,$00,$00
.db $08,$00,$08,$01,$08,$04,$08,$00
.db $08,$06,$08,$01,$08,$fe,$08,$00







BalloonStraightCollisionData:
.db $06,$04,$00,$04,$00,$00,$00,$00
.db $1f,$03,$00,$01,$00,$00,$00,$00
.db $08,$00,$08,$01,$08,$04,$08,$00
.db $08,$06,$08,$01,$08,$fe,$08,$00
  View user's profile Send private message
  • Joined: 01 Jan 2014
  • Posts: 331
Reply with quote
Post Posted: Thu Nov 12, 2015 3:28 am
Hey,

Not sure what you are asking? Could you be more specific? Data driven pointer?

If you are iterating over a table then inc or dec.

If you are doing look ups you need to take the table base address and add to corresponding data.

If you are iterating over a series of tables then what I usually do is write the table addresses to ram and iterate over that (probably a cleaner way but could not find it in wla-z80).

If you need to refer to a specific table based on some logic then same as above (write a list of the table addresses) but instead of iterating over the list you need to add to the base address such that you get the right table. So essentially you create a look up table which stores the addresses of hard data or other lookup tables.


I assume by aabb you are referring to Axis-Aligned Bounding Box. From post I assume you intend to store multiple values for multiple animation frames. If so seams kind of overkill. AABB would at best represent a broad indication of collision unless your bloons are rectangle :p

Collision detection done on old school machines is usually cheap and nasty due to the cost of accurate collision detection. If you must have perfect collision detection then you should look at PPC (Pixel Perfect Collision). Personally I would not suggest PPC on SMS.

If you are comfortable with look up tables then Circle Collision may be a better fit.

If you plan to have a large number items to check collisions on you will probably need to include some phases to break down the work load.
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14759
  • Location: London
Reply with quote
Post Posted: Thu Nov 12, 2015 2:30 pm
You may be interested in: http://www.smspower.org/forums/14606-BestWayToDoAddHlA

jp (hl) is a jump, you can't return to the next line. That seems OK though, the jumped to code will return to the caller of the first routine (assuming it is called, the orphaned ret suggests it is).

It's not clear what you're trying to achieve. Your game may benefit from hardware sprite collision detection, if the gameplay never has overlapping sprites for any other purpose. That would get you pixel precise collisions, but would be quite tricky (you would need to dynamically add sprites to the walls etc near the player). Else as mentioned, simple collision detection may not map well to your sprite shape.
  View user's profile Send private message Visit poster's website
  • Joined: 18 Dec 2014
  • Posts: 95
  • Location: Canada
Reply with quote
Post Posted: Fri Nov 13, 2015 1:06 am
First off thank you both for taking the time to reply(thanks gentlemen)
I wasen't clear on my question i don't want multi calls on my collision code.How can I keep a pointer active is what I am asking sorry if this is a newbie question.I get what you're saying maxim but I don't want to use sprites,i can calculate the aabb per animation state.As your aware Maxim my sprite"swings"i've no problem with the bounding box as it's calculated per animation state,i've a problem with maintain an active pointer i'm used to 6502 and not z80 can you show me a code example on maintain a pointer in z80?I'm French so my English is so..so I apologize.



BalloonBoundingBoxData:
.dw BalloonLeftFrame2Collision
.dw BalloonLeftFrame1Collision
.dw BalloonStraightFrameCollision
.dw BalloonRightFrame1Collision
.dw BalloonRightFrame2Collision


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
BalloonStraightFrameCollision:
  ld hl,BalloonStraightCollisionData      ;<---I want this as an active pointer
so I need not  rewrite this function over and over   
  ld a,(YBalloon)
  ld c,a
  ld a,(XBalloon)
;  ld b,a
;  push bc
;  call Do_BallonTopCollision
;  pop bc
;  push bc
;  call Do_BalloonBottomCollision
;  pop bc
;  push bc
;  call Do_BalloonLeftCollision
;  pop bc
;  push bc
;  call Do_BalloonRightCollision
;  pop bc
  ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
BalloonRightFrame1Collision:
  ld hl,BalloonStraightCollisionData        ;<---I want this as an active pointer
  ld a,(YBalloon)
  ld c,a
  ld a,(XBalloon)
;  ld b,a
;  push bc
;  call Do_BallonTopCollision
;  pop bc
;  push bc
;  call Do_BalloonBottomCollision
;  pop bc
;  push bc
;  call Do_BalloonLeftCollision
;  pop bc
;  push bc
;  call Do_BalloonRightCollision
;  pop bc
  ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
BalloonRightFrame2Collision:
  ld hl,BalloonStraightCollisionData          ;<---I want this as an active pointer
  ld a,(YBalloon)
  ld c,a
  ld a,(XBalloon)
;  ld b,a
;  push bc
;  call Do_BallonTopCollision
;  pop bc
;  push bc
;  call Do_BalloonBottomCollision
;  pop bc
;  push bc
;  call Do_BalloonLeftCollision
;  pop bc
;  push bc
;  call Do_BalloonRightCollision
;  pop bc
  ret
  View user's profile Send private message
  • Joined: 18 Dec 2014
  • Posts: 95
  • Location: Canada
Reply with quote
Post Posted: Fri Nov 13, 2015 1:48 am
psidum wrote
I assume by aabb you are referring to Axis-Aligned Bounding Box. From post I assume you intend to store multiple values for multiple animation frames. If so seams kind of overkill. AABB would at best represent a broad indication of collision unless your bloons are rectangle.


Can you go into more detail as I'm not understanding my friend.How would you handle it?
  View user's profile Send private message
  • Joined: 01 Jan 2014
  • Posts: 331
Reply with quote
Post Posted: Fri Nov 13, 2015 7:12 am
OmegaPrime wrote
psidum wrote
I assume by aabb you are referring to Axis-Aligned Bounding Box. From post I assume you intend to store multiple values for multiple animation frames. If so seams kind of overkill. AABB would at best represent a broad indication of collision unless your bloons are rectangle.


Can you go into more detail as I'm not understanding my friend.How would you handle it?


Safe to say ignore what I said, If you are not using sprites and it works then all is good.


So active pointers... I am not sure exactly what you are after. Will give over view of difference between 6502 and z80 from 6502 programming perspective. I am not an expert so someone might need to correct.

6502 and z80 are quite different. Zero page on 6502 used to offset lack of registers. 6502 largely stores active pointers in memory due to register limitations.

z80 has lots of registers and no zero page. No need to use a zero page for addressing with z80. Instead use registers. You can use contents of hl, ix, iy for addressing. Examples...

ld (hl), nn  ; write nn to memory location stored in hl
jp hl ; jump to address stored in hl
jp (hl) ; jump to address stored at memory address hl
inc (hl) ; inc the value at address hl


- hl and hl' support extended addressing (pointer lookup).
- ix and iy support indexed addressing (slightly more expensive to use).

ix, iy indexed addressing strange. No substitute for indirect mode on 6502 (??? feel free to jump in if I am wrong). Offset not based on register, instead written in code.

ld a, (ix+n)


Not really a problem though as registers very flexible. Can achieve 6502 indirect mode flexibility with ix, iy via self modifying code if really needed.

z80 also has 4 other 16 bit registers bc, bc', de, de'. z80 also has other register combinations but not relevant here.

I am not sure what you are doing with the code. See you want a pointer but not sure what you plan to do with it. If you wanted to pass a pointer between calls then you could...



.define BalloonCollisionDataPointer $C000  ;replace $C000 desired ram location


BalloonCollision:
  ld hl, (BalloonCollisionDataPointer) ; read pointer from ram.
  ld a,(YBalloon)
  ld c,a
  ld a,(XBalloon)
 
  ; do stuff with pointer.
  ; ...

 
  ; write it back to ram for later use.
  ld (BalloonCollisionDataPointer), hl
 
  ret


Alternatively you could store on stack or use ix, iy if you know you don't need them for anything else.


Sorry if that didn't help. If you need more help I suggest describing the core problem you are trying to solve rather than list parts of code.
  View user's profile Send private message
  • Joined: 18 Dec 2014
  • Posts: 95
  • Location: Canada
Reply with quote
Post Posted: Fri Nov 13, 2015 7:37 am
Thank you psidum that is very clear
  View user's profile Send private message
  • Joined: 18 Dec 2014
  • Posts: 95
  • Location: Canada
Reply with quote
Post Posted: Fri Nov 13, 2015 8:36 am
I'm a newbie psidum can I handle this better?

:;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Do_ObjectUpdates:
ld e,(ix+objectXConstl)
ld d,(ix+objectXConsth)
ld l ,(ix+objectXl)
ld h,(ix+objectXh)
add hl,de
ld ,(ix+objectXl),l
ld ,(ix+objectXh),h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
here psidum!!!
call Do_GetJoyPadInPut
ld a,(_JoyPadInput)
and %00001111
ld e,a
ld d,0
ld hl,JoyPadDataTable
add hl,de
ld a,(hl)
add a
add a
ld e,a
ld d,0
ld hl,BalloonVelocityDataTable
add hl,de
ld c,(hl)
inc hl
ld b,(hl)
inc hl
ld e,(hl)
inc hl
ld d,(hl)
ld (ix+YObjectFractionalSpeedOffset),c
ld (ix+YObjectSpeedOffset),b
ld (ix+XObjectFractionalSpeedOffset),e
ld (ix+XObjectSpeedOffset),d
ret

JoyPadDataTab:.db $00,$01,$02,$00,$03,$04,$05,$00,$06,$07,$08


BalloonVelocityDataTable:
;Null
.db $00,$00,$00,$00
;JoyPadUpPressed
.db $00,$ff,$00,$00
;JoyPadDownPressed
.db $00,$01,$00,$00
;JoyPadLeftPressed
.db $00,$00,$00,$ff
;JoyPadLeftAndUpPressed
.db $2b,$ff,$00,$ff
;JoyPadLeftPressed
.db $20,$01,$00,$ff
;JoyPadRightPressed
.db $00,$00,$00,$01
;JoyPadRight&UpPressed
.db $2b,$ff,$00,$01
;JoyPadRight&DownPressed
.db $20,$01,$00,$01

I reversed engineered donkey kong jr and they use one frame offset and it threw off maxim sorry buddy.Thats why my table doesn't make sense
  View user's profile Send private message
  • Joined: 01 Jan 2014
  • Posts: 331
Reply with quote
Post Posted: Fri Nov 13, 2015 10:25 am
Last edited by psidum on Sun Nov 15, 2015 12:21 am; edited 1 time in total
Well you should know I am a newbie too. Some people here eclipse my experience by 10 years + :p

From looking at code you are.

- getting controller input.
- masking byte to isolate lower 4 bits.
- adding this to the base table address of JoyPadDataTable.
- getting the desired value from JoyPadDataTable.
- multiplying this value by 4 to identify required entries in BalloonVelocityDataTable.
- adding it to base table address of BalloonVelocityDataTable.
- populating offsets of ix with desired values from BalloonVelocityDataTable.

There are some syntax errors. Probably time to find an editor and compile code as you go to identify. I recommend Efrys IDE, it takes a little time to set up and requires java but it is worth it. Alternatively if you look at Maxims tutorial he has a set up with conTEXT which does not require java.


Removed incorrect info about little indian (thanks Maxim).


I am not a fan of optimizing code too early. Get the code up and running then optimize if you are running short of cycles. Emulicious has a built in profiler which I currently have a love affair with.

One thing that did stick out was the JoyPadDataTable. If you store the values as multiples of 4 you won't need to do the multiplications on the sms. Hardly a saving though.
  View user's profile Send private message
  • Joined: 18 Dec 2014
  • Posts: 95
  • Location: Canada
Reply with quote
Post Posted: Fri Nov 13, 2015 11:42 pm
Thank you very much psidum i've read everything you've written.I've also read you're link maxim thank you also.
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14759
  • Location: London
Reply with quote
Post Posted: Sat Nov 14, 2015 5:29 pm
psidum wrote
z80 stores 16 bit values in little indian format. So $4080 in hl would be h = $80, l=40. Same for when you write 16 bit values to RAM. You are currently adding to the high byte when adding on base addresses...

ld e,a
ld d,0


needs to become

ld e,0
ld d,a


I think this is wrong. Value $4080 in hl means h=$40, l=$80. If you store that to RAM then it will be stored in the order $80, $40. So if you want to set de = a then you do the first code snippet above, not the second.

However, you almost never have to think about this because the assembler takes care of most of it. Just put .dw 1 to emit $01, $00 for example.
  View user's profile Send private message Visit poster's website
  • Joined: 01 Jan 2014
  • Posts: 331
Reply with quote
Post Posted: Sat Nov 14, 2015 10:31 pm
Thanks Maxim, disregard what I said about the 16 bit additions.
  View user's profile Send private message
Reply to topic



Back to the top of this page

Back to SMS Power!