Help with small macro implementation

Discussion of hardware and software development for Super NES and Super Famicom.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
gompertz
Posts: 5
Joined: Fri Dec 17, 2010 10:00 pm

Help with small macro implementation

Post 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!
User avatar
Dwedit
Posts: 4470
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post 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.
gompertz
Posts: 5
Joined: Fri Dec 17, 2010 10:00 pm

Post 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.
Post Reply