Re: Assembler Question



Alfred:

> I would do it a bit differently, since I'm not much good with those
> carry bit tricks:

that was no trick ;) that was 16bit number with sign

ldy #$00
txa
bpl plus1
dey
plus1 ...

Y reg. will hold MSB so if X reg. is positive then we just add 0000-007f,
else we add FF80-FFFF (add with carry two bytes - not a trick).

Your code with for example 120 in X reg. MOD_max_x=159 cursor_x=150
mouse X position is legal within (0,159) and we moving +120
(positive value):


> txa
> clc
> adc cursor_x

so we have 150+120 which is 14 cause we lost highest bit of 270

> tay
> txa
> bmi _negativ ; mx=negativ? yes -> _negativ

not executed because it is positive

> cpy MOD_max_x
> bcc _lesser_max

executed, 14 is lesser

> ldy MOD_max_x
> _lesser_max
> sty cursor_X
> rts

so we have 150+120 -> 14 - mouse jumped from right side of screen
to the left and should stay at max_x on the right side.


--
Sc0rpi0
I hated going to weddings.
All the grandmas would poke me saying "You're next".
They stopped that when I started doing it to them at funerals.
.



Relevant Pages