While loop using goto codetype?

Started by mugwhump, December 29, 2009, 08:00:17 AM

Previous topic - Next topic

mugwhump

This should be possible, right? I'm pretty sure I'm using the goto code wrong though cuz it keeps freezing on me.

Pasted for convenience:
CST0 : Set Repeat

6000NNNN 0000000P = set repeat Store next code address and NNNN (number of times to repeat) in bP (block P).

CST1 : Execute Repeat

62000000 0000000P = execute repeat If NNNN stored in bP is >0, it is decreased and the code handler jumps to the next code addres stored in bP.

CST2 : Return

64000000 0000000P = return if true If the code execution status is true, the code handler jumps to
the next code address stored in bP (NNNN is not touched).

64100000 0000000P = return if false If the code execution status is false, the code handler jumps to
the next code address stored in bP (NNNN is not touched).

64200000 0000000P = return The code handler jumps to the next code address stored in bP
(NNNN is not touched), whatever the code execution status is.

CST3 : Goto

6600XXXX 00000000 = goto if true If the code execution status is true, the code handler jumps
to (next line of code + XXXX lines). XXXX is signed.

6610XXXX 00000000 = goto if false If the code execution status is falsethe code handler jumps
to (next line of code + XXXX lines). XXXX is signed.

6620XXXX 00000000 = goto The code handler jumps to (next line of code + XXXX lines).
XXXX is signed.

CST4 : Gosub

6800XXXX 0000000P = gosub if true If the code execution status is true, the code handler stores the
next code address in bP, then it jumps to (next line of code + XXXX lines). XXXX is signed.

6810XXXX 0000000P = gosub if false If the code execution status is false, the code handler stores the next code address in bP, then it jumps to (next line of code + XXXX lines). XXXX is signed.

6820XXXX 0000000P = gosub The code handler stores the next code address in bP, then it jumps to
(next line of code + XXXX lines). XXXX is signed.



Here's an example code that freezes the game:
  80000000 00000000 gr0=0
  80000001 00000000 gr1=0
*86000000 00000001 gr0+=1
  86000001 00000001 gr1+=1
  26001808 00000005 32 bits if gr0(located at 80001808) < 5
  6600FFFC 00000000 jump -4 lines from the next line to*
  E0000000 80008000

This code should just set gr0 and gr1 to 5, but it just freezes. I don't think it's looping indefinately either...
A lot of the codetypes above seem to involve 'storing the code address in bP.' Is that something I need to be doing here? Do I need to use another code along with goto?

Almas

#1
Did gr0 move? I swear it used to be at 80001800

EDIT:

The GoTo codetype probably measures 0x8 as one line (as this is how it appears in memory). You've set it to the wrong value. You should be setting it to FFD0 or so.

mugwhump

#2
Yeah, it moved. In 1.9.1 at least.

So do you mean that, say, 80008000 is counted as one line? Cuz FFD0 is -48, and that wouldn't make sense :p
Or did you mean just 8000 would be one line? That would make sense if you meant to type FFF0.

Also, the goto code would start counting backwards from the beginning of E0000000 80008000, correct?

Thanks for the help

Edit: I tried a wide range of values between FFD0 and FFFC and all of them froze (except for 0000 but that doesn't do anything lol).
I think I must be doing something else wrong :/

Almas

Honestly I'd just insist on using ASM, as I did last time. Much less room for confusion as to why something doesn't work. It's also a great skill as it lets you create much more complex codes. But...

Maybe just try using the execute repeat code block? Set it to an arbitrarily high number, and then use an if... execute repeat loop.

mugwhump

Yeah something like that. I still dunno how to use the goto, but now at least I can do my while loop

While loop code:
60000000 0000000P
*code to be repeated*
*if statement*
64000000 0000000P (if if statement==true, repeat code. Or use 641 or 642)
*endif*


Anyways the reason I wanted that was for a division algorithm. I'll post it for learning purposes :3

80000003 8000182E gr3 stores gr2's quotienty thing address
80000001 0000NNNN gr1 =Numerator
84100001 8000182C load numerator into address2
80000000 00000000 gr0=0
80000002 00000000 gr2=0
60000000 00000000 store next codes in b0, keep repeating
86000000 00000001*gr0+=1 (quotient counter)
86000002 0000DDDD gr2+=Denominator
84100002 8000182E load gr2 into address3
A400182C 3F000000 if gr2(gr3 address)>gr1(numerator, address2)
64000000 00000000 jump to *
E2000001 00000000 endif

By the end of that, gr0 will contain the quotient of NNNN divided by DDDD, rounded up.