Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
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
Seppo Heavy
commodore_freak
iceout/Avatar/HF
Airwolf/F4CG
awsm/MYD
ritti/TLN
Guests online: 333
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 No Bounds  (9.6)
6 Comaland 100%  (9.6)
7 Uncensored  (9.6)
8 The Ghost  (9.6)
9 Wonderland XIV  (9.6)
10 Bromance  (9.6)
Top onefile Demos
1 Party Elk 2  (9.7)
2 Cubic Dream  (9.6)
3 Copper Booze  (9.5)
4 Rainbow Connection  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Onscreen 5k  (9.5)
7 Dawnfall V1.1  (9.5)
8 Quadrants  (9.5)
9 Daah, Those Acid Pil..  (9.5)
10 Birth of a Flower  (9.5)
Top Groups
1 Booze Design  (9.3)
2 Nostalgia  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Logo Graphicians
1 Sander  (10)
2 Facet  (9.7)
3 Mermaid  (9.4)
4 Pal  (9.4)
5 Shine  (9.3)

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