Jump to content
IGNORED

calculating HMxx values


SvOlli

Recommended Posts

Before I go boldly reinventing the wheel again:

 

Let's say, I've got a sprite of which I know that it is on position 55, and I want to move that sprite to position 60. Then I need a routine that converts that to the correct HMxx value. As a first shot, I'd come up with something like:

 

  clc
  lda newpos
  adc #$07 ; for later offset in table
  sec
  sbc oldpos
  tay
  lda hmtable,y ; table containing the 16 possible values for sprite movement from 7-to-left to 8-to-right
  sta HMxx

 

Anyone found already a nice cpu cycle optimized solution for this question?

Link to comment
Share on other sites

Nothing great, but I think you can go at least 2 cycles faster like this:

 

 

;HMxx
LEFT_7  = $70
LEFT_6  = $60
LEFT_5  = $50
LEFT_4  = $40
LEFT_3  = $30
LEFT_2  = $20
LEFT_1  = $10
NO_MOTION  = $00
RIGHT_1  = $F0
RIGHT_2  = $E0
RIGHT_3  = $D0
RIGHT_4  = $C0
RIGHT_5  = $B0
RIGHT_6  = $A0
RIGHT_7  = $90
RIGHT_8  = $80


 sec
 lda  newpos
 sbc  oldpos
 and  #$0F  ; If X=$0F here, use SBX #0, and lda HmoveTab,X
 tay
 lda  HmoveTab,Y
 sta  HMxx


HmoveTab:
 .byte NO_MOTION  ; Y=0
 .byte RIGHT_1
 .byte RIGHT_2
 .byte RIGHT_3
 .byte RIGHT_4
 .byte RIGHT_5
 .byte RIGHT_6
 .byte RIGHT_7
 .byte RIGHT_8
 .byte LEFT_7  ; Y=9
 .byte LEFT_6  ; A
 .byte LEFT_5  ; B
 .byte LEFT_4  ; C
 .byte LEFT_3  ; D
 .byte LEFT_2  ; E
 .byte LEFT_1  ; F

Link to comment
Share on other sites

This might work, still have to test it some more...

 

 

 

 sec
 lda  newpos
 sbc  oldpos
 asl
 adc  #2
 asl
 asl
 asl
 sta  HMxx

 

 

There is also the problem of wrap around, i.e. old position = 2, new position = 158, want LEFT_4 for HMxx. I'm not sure if any of these routines handle that.

Link to comment
Share on other sites

Nothing great, but I think you can go at least 2 cycles faster like this:

 

 

sec
lda newpos
sbc oldpos
and #$0F ; If X=$0F here, use SBX #0, and lda HmoveTab,X
tay
lda HmoveTab,Y
sta HMxx

HmoveTab:
.byte NO_MOTION ; Y=0
.byte RIGHT_1
.byte RIGHT_2
.byte RIGHT_3
.byte RIGHT_4
.byte RIGHT_5
.byte RIGHT_6
.byte RIGHT_7
.byte RIGHT_8
.byte LEFT_7 ; Y=9
.byte LEFT_6 ; A
.byte LEFT_5 ; B
.byte LEFT_4 ; C
.byte LEFT_3 ; D
.byte LEFT_2 ; E
.byte LEFT_1 ; F

 

If the rest of the code allows, you could also split up the table and arrange it so that LEFT is at the top of a page and RIGHT at the bottom. This would get rid of the AND $0F.

Link to comment
Share on other sites

sec
lda oldpos
sbc newpos
asl
asl
asl
asl
sta HMxx

That was the same idea, I had in bed last night:

; a already contains position from calculation
sec
eor #$ff
adc oldpos
asl
asl
asl
asl
sta HMxx

And it leaves X and Y untouched.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...