Limit the "No Loop" increment to one variable

By igal

Master (217)

igal's picture

05-08-2017, 17:07

Please, what is the right order?

Here is the example:
10 HS = 100
VDP (24) = VDP (24) +1 without exceeding HS
VDP (24) = VDP (24) +1 without exceeding HS
40 VDP (24) = VDP (24) +1 without exceeding HS
50 VDP (24) = VDP (24) +1 without exceeding HS
100 VDP (24) = 0: HS = 20
120 VDP (24) = VDP (24) +1 without exceeding HS
130 VDP (24) = VDP (24) +1 without exceeding HS
140 VDP (24) = VDP (24) +1 without exceeding HS
150 VDP (24) = VDP (24) +1 without exceeding HS

I am looking for the command that replaces "WITHOUT EXCEED" but I do not want to "Loop"! No "IF THEN RETURN" etc. etc ...
Just a command that imitates the increment to the value "EQUAL TO HS"!

Do you have a solution "Simple and clear please?"

Thank you for your help Face

Login or register to post comments

By Manuel

Ascended (19469)

Manuel's picture

05-08-2017, 17:28

VDP(24) = VDP(24) + 1 + (VDP(24) = HS)

Using trickery of how booleans are represented as integers in BASIC.: TRUE = -1 and FALSE = 0.

Note: untested.

By sd_snatcher

Prophet (3659)

sd_snatcher's picture

05-08-2017, 18:11

Here's a slightly optimized version: Wink

VDP(24)=VDP(24)-(VDP(24)

By Manuel

Ascended (19469)

Manuel's picture

05-08-2017, 19:03

sd_snatcher wrote:

Here's a slightly optimized version: Wink

VDP(24)=VDP(24)-(VDP(24)<HS)

(made readable because of forum quirkiness....)

By igal

Master (217)

igal's picture

06-08-2017, 12:15

Thank you for your help.
Unfortunately, the scroll only works if the variable contains a Positive value!
Let me explain ... I would like to be able to scroll up or down just by indicating the value of one or even two variables.

You have an idea please Wink

By Manuel

Ascended (19469)

Manuel's picture

06-08-2017, 16:16

So, make a DR (direction) variable, which is either 1 or -1.

VDP(24) = VDP(24) + DR * (VDP(24) = HS)

You may also need a lower limit, right? For that you can expand the boolean expression a bit.

By igal

Master (217)

igal's picture

08-08-2017, 18:01

Hi Manuel.

The variable to mount the scroll is +1
The variable to scroll down is +254

I remember that there is no negative value to VDP (24)!
The solution to my problem can be summarized as follows:

In order to climb:
HS = 100
VDP (24) = VDP (24) + 1 + (VDP (24) = HS)
VDP (24) = VDP (24) + 1 + (VDP (24) = HS)
VDP (24) = VDP (24) + 1 + (VDP (24) = HS)
VDP (24) = VDP (24) + 1 + (VDP (24) = HS)
No problem is encountered since VDP is 0 and goes up to 100!

To go down:
HS = 100
VDP (24) = VDP (24) + 254 AND 255 + (VDP (24) = HS)
VDP (24) = VDP (24) + 254 AND 255 + (VDP (24) = HS)
VDP (24) = VDP (24) + 254 AND 255 + (VDP (24) = HS)
VDP (24) = VDP (24) + 254 AND 255 + (VDP (24) = HS)
Big problem since VDP goes from the value 0 to 254 and returns to 0 as soon as 255 is reached Sad

You suggested a solution by adding the variable DR which should therefore be [1 to go up] or [254 to go down]
This is a very good idea but raises the problem of reinitialization of DR to not exceed the maximum value of vdp (24) ie 255!
By doing the following:

10 DR = 254
15 HS = 100
20 VDP (24) = VDP (24) + DRAND255 ??? = HS ???
30 GOTO 20

On SCROLL down but we NEVER reach the HS value and so the scroll does not stabilize at 100 Sad

Do you have an idea even by develloping a little the command line but "Without going through a loop"?

Thanks for your help Smile

By Manuel

Ascended (19469)

Manuel's picture

08-08-2017, 23:20

+254 is the same as -2, +255 is the same as -1... just use AND 255 and the sign doesn't really matter.

Here's a little test program. Try with DR=1 and DR=-1. I think it does what you need, doesn't it?

10 HS=100: DR= 1
20 A = (A + DR + DR*(HS=A))AND255:PRINTA
30 GOTO 20

So, for your case, replace A with VDP(24).

By igal

Master (217)

igal's picture

11-08-2017, 15:13

Thanks Manuel. Everything works perfectly.
I have made a little movie with Sprite and Scroll Horizontal=> Horizontal+Vertical Up => Horizontal+Vertical Down:
https://youtu.be/0Oh3Y8YWJOE

I just modify by "DR by step +2 or -2" to coincide with my horizontal scroll.

This gives this:
190 'Variables des Vertical et Horizontal.
200 HA=0:'Latitude du copy Verticale
205 HS=190:'Buté du scroll V Verticale
210 DR=-2:'Direction du scroll V Verticale
471 COPY"1"TO(VA,HA):VA=VA+2:SETSCROLLVA:VDP(24)=(VDP(24)+DR+DR*(HS=VDP(24)))AND255
472 COPY"2"TO(VA,HA):VA=VA+2:SETSCROLLVA:VDP(24)=(VDP(24)+DR+DR*(HS=VDP(24)))AND255
473 COPY"3"TO(VA,HA):VA=VA+2:SETSCROLLVA:VDP(24)=(VDP(24)+DR+DR*(HS=VDP(24)))AND255
474 COPY"4"TO(VA,HA):VA=VA+2:SETSCROLLVA:VDP(24)=(VDP(24)+DR+DR*(HS=VDP(24)))AND255
475 COPY"5"TO(VA,HA):VA=VA+2:SETSCROLLVA:VDP(24)=(VDP(24)+DR+DR*(HS=VDP(24)))AND255
476 COPY"6"TO(VA,HA):VA=VA+2:SETSCROLLVA:VDP(24)=(VDP(24)+DR+DR*(HS=VDP(24)))AND255
477 COPY"7"TO(VA,HA):VA=VA+2:SETSCROLLVA:VDP(24)=(VDP(24)+DR+DR*(HS=VDP(24)))AND255
478 COPY"8"TO(VA,HA):VA=VA+2:SETSCROLLVA:VDP(24)=(VDP(24)+DR+DR*(HS=VDP(24)))AND255
480 CALL CHDIR (".."):CALL CHDIR ("1")
...
...

Want you help me for make a "complète and simple" solution for move to move the entire sprite management area on page 1?
I'm in screen 5, and I use the entire page zero from the lines:
0 => 191 and 192 => 255!
This allows me to scroll easily scenery just by "copying" them on these two "zones".

In the past, I was given directions to move the entire area reserved for managing sprites, but this is beyond my intellectual capacity I think because I never got there lol

Thank for your help ._,