Page 1 of 1

Help with small macro implementation

Posted: Wed Jan 05, 2011 3:53 pm
by gompertz
Hi All,

I'm stumped at the best approach for the following situation:

I've created a non-scrolling level of 32x28 8x8tiles to fill the screen, and I have stored the existence of a platform tile as a 00000001 or a 00000000 for each of these 896 tiles starting at address 0xa00. (Yes, big waste of memory using a whole byte on each tile, but trying to keep it simple for now).

Anyways, my sprite has its x and y position stored at $0900 and $0901 respectively and am trying to implement the below macro:

Code: Select all

.macro BoolDown
; Input: X and Y co-ordinates
; Output: Result if legal move stored in $0902
; Purpose: Given X and Y position, if there is a platform tile below 
;               the current position then $0902 is 1, otherwise 0.
ldx $0900 ; load x position
ldy $0901 ; load y position 
lda #(????)
cmp #%00000001
bne +
lda #1
sta $0902
+
lda #0
sta $0902
.endm
My first instinct to locate in memory the address of the tile below me is along the lines of the following
If ($0901+1)*32+$0900+0xa00 is 1 then $0902 set to 0; o/w 1.

I've added 1 to $0901 so that we're talking one tile "row" down from my current position.

However I am stumped on how to implement this in asm without tons of complicated asl sort of deals.

Alas, Is this style even acceptable for collision detection?

Any help is appreciated!

Posted: Wed Jan 05, 2011 5:11 pm
by Dwedit
Something like this?
#define Locate(xx,yy) lda #((xx) + (yy) * 32) & $FF \ sta PPUADDR \ lda #((xx) + (yy)*32) / 256 \ sta PPUADDR

This is for TASM, change your syntax accordingly.
Edit: that's just for constants unfortunately.


To multiply by 32 easily in 6502 asm:
lda YPos
sta temp
lda #0
ror temp
ror a
ror temp
ror a
ror temp
ror a
;a = xxx.....
;temp = ...xxxxx
Then you use 'temp' as your high byte, and add X to A as your low byte.

Posted: Wed Jan 05, 2011 8:19 pm
by gompertz
Thanks I'll fiddle with your suggestions tomorrow when back on the devcomp :)

It also dawned on me afterwards I need to convert the raw x and y positions into x-tile and y-tile positions by doing modulus 8 on x and y (my sprite is 8x8). And THEN do the whole multiplying by 32 etc etc.

I really wonder if I'm going about this collision detection the right way however and am curious how it was really done way back when.