Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user Harvey ! (Registered 2024-11-25) You are not logged in - nap
CSDb User Forums


Forums > C64 Productions > Character -> Sprite
2003-01-17 20:11
Dr. Jay
Account closed

Registered: Jan 2003
Posts: 32
Character -> Sprite

I'm trying to map a sprite to overlay the character.

I've got everything in place - finding the character in rom, copying the bits to the sprite buffer, setting it, etc.

However, my 6502 is VERY rusty and I'm trying to map the x,y coordinate of the character to the x, y coordinate for a sprite.

My philosophy is that something at $0400 would represent #24, #50 (the x,y offset for the border - these values may be wrong - I'm coding NTSC) so I take the address of the character on the screen, subtract 40 until I hit page $03 and the number of times I subtract 40 is my "y" offset (multiply by 8 and add 50) and then adding 40 back will get me my "x" offset (multiply by 8 and add 24).

This apparently isn't working and I'm wondering if my approach is flawed or just my use of 6502 to do the math.

For example, to get the character at $0427 I subtract #40 and hit the $03 page, so I know y offset is 0 (if it were $0428 I'd know the y offset is 1) so I do 8 * 0 + 50 = 50 for the y (at $0433 it'd be 1 * 8 + 50 = 58).

For x I am at $03ff so the low byte ($ff) with #40 added back gets me $27 so I call that x, multiply by 8 and add 24, set the high bit, etc.

Here is the code ... it is computing the Y okay (I think it might be off by 8 rasters) but my X is flaked:

The address is in temp, temp+1 so if the character is at $0407 then temp = $07 and temp+1 = $04:

cmploop lda temp ; 40 columns - subtract until we cross the $0400 border
sec
sbc #40 ; to get y position and then adjust to get x
sta temp
bcc compx ; if carry is clear then we adjust the next page
iny ; we've gone up a line
sec ; relocatable jump
bcs cmploop
compx lda temp+1
sbc #$00 ; will subtract if overflow
sta temp+1
cmp #$03 ; down to 3 page?
beq calcy ; yes -- now get y offset
iny ; otherwise increment the y position
sec
bcs cmploop ; relocatable jump
calcy lda temp ; y contains y position, add 40 to accumulator to get true x position
adc #40
clc
rol
rol
rol
bcc storex ; don't set high bit if carry is clear
tax
lda #$01 ; set MSB because we overflowed
ora $d010
sta $d010
txa
storex adc #24 ; left border
sta $d000
tya ; now take y and multiply by 8
rol
rol
rol
adc #50 ; top border
sta $d001 ; no overflow because max value 25 x 8 = 192 < 256

Any help???

2003-01-17 20:18
Dr. Jay
Account closed

Registered: Jan 2003
Posts: 32
Nevermind - I'm an idiot. I was using zero page addressing to find my screen location, then storing the zero page as my offset, instead of transferring y.

In other words, if I do

lda ($fb),y with $00 in $fb and $04 in $fc, then I was doing this:

lda $fb
sta temp
lda $fc
sta temp+1

when I should have done this:

tya
sta temp
lda $fc
sta temp+1

to get the address.

Thanks!
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Holy Moses/Role
A3/AFL
WVL/Xenon
Nordischsound/Hokuto..
Guests online: 133
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Coma Light 13  (9.7)
4 The Demo Coder  (9.6)
5 Edge of Disgrace  (9.6)
6 Mojo  (9.6)
7 What Is The Matrix 2  (9.6)
8 Uncensored  (9.6)
9 Wonderland XIV  (9.6)
10 Comaland 100%  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 Party Elk 2  (9.6)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.6)
5 Libertongo  (9.5)
6 Rainbow Connection  (9.5)
7 Onscreen 5k  (9.5)
8 Morph  (9.5)
9 Dawnfall V1.1  (9.5)
10 It's More Fun to Com..  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Nostalgia  (9.3)
5 Triad  (9.2)
Top Musicians
1 Rob Hubbard  (9.7)
2 Jeroen Tel  (9.7)
3 Mutetus  (9.7)
4 Jammer  (9.6)
5 Linus  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.053 sec.