Calculated GOTO

Basic and Machine Language

Moderator: Moderators

Post Reply
Rob Murphy
Vic 20 Drifter
Posts: 35
Joined: Fri Dec 17, 2004 8:14 pm

Calculated GOTO

Post by Rob Murphy »

I wanted to pass this little gem along. I found it in an old RUN Mag.

1000 POKE785,188:POKE786,168:POKE GL,PEEK(GL):GL=USR(0)

Set the value GL to the line number you want to jump to. Then Enter:

GOTO 1000

It says it works on the C64, but it being low memory I think it will work with the VIC20 too.

Thanks to Randy Thompson for the idea.

Rob
Rob Murphy
User avatar
Jeff-20
Denial Founder
Posts: 5759
Joined: Wed Dec 31, 1969 6:00 pm

Post by Jeff-20 »

can someone test this on a VIC? Mine is not hooked up at the moment.
also, how would this be an improvement over the ON/GOTO command?
High Scores, Links, and Jeff's Basic Games page.
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

@Jeff: Calculated GOTOs are useful, if you have a LOT of jump targets, whose line-numbers follow a regular pattern, say, 300, 400, 500, ..., 1800, 1900,..., and you couldn't put all these in one ON GOTO command.

@Rob: This surely won't work directly on a VIC, as the routine alters the USR vector to call (presumably, I'll check this as I write this) a part of the GOTO routine. The USR vector had been relocated from 1/2 on the VIC to 785/786 on the C=64. Furthermore the POKE GL,PEEK(GL) only seems to be an intricate way to set up the right values in $14/$15 for the GOTO routine (and could mess up with read-sensitive I/O registers...)

[15 mins. later]

POKE 1,163:POKE 2,200:POKE GL,PEEK(GL):GL=USR(0) works.

I checked this with:

4711 GL=6502:PRINT"A";:GOTO12345
6502 GL=4711:PRINT"B";:GOTO12345
9999 END
12345 POKE 1,163:POKE 2,200:POKE GL,PEEK(GL):GL=USR(0)

Of course, Adresses 1 and 2 only need to be set up once.

Greetings,

Michael
Boray
Musical Smurf
Posts: 4064
Joined: Mon May 03, 2004 10:47 am

Post by Boray »

How cool! Thanks!

/Anders
PRG Starter - a VICE helper / Vic Software (Boray Gammon, SD2IEC music player, Vic Disk Menu, Tribbles, Mega Omega, How Many 8K etc.)
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

I've found a way to avoid the problematic POKEGL,PEEK(GL) combination. Furthermore, it allows the line number to be passed as argument with the USR function. We need 6 bytes for a small ML routine, which fits nicely behind the screen memory... :)

100 S=8186:REM S=4602 for +8K RAM expansion, or more
110 FORI=0TO5:READA:POKES+I,A:NEXT
120 POKE1,250
130 POKE2,31:REM POKE2,17 for +8K RAM expansion, or more
140 DATA32,247,215,76,163,200

call with: dummy=USR(linenr.), test with:

4711 PRINT"A";:X=USR(6502)
4712 END
6502 PRINT"B";:X=USR(4711)
6503 END

and, finally...

0 POKE1,18:POKE2,16:REMZZZZZZ
1 S=4096:FORI=0TO5:READA:POKES+18+I,A:NEXT
2 DATA32,247,215,76,163,200

(for +8K RAM ex., or more, write POKE2,18 and S=4608 instead)

RUN the program. After this, you can delete the lines 1 and 2. Never edit line 0. Test as above.

Cheers,

Michael
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

Ah, this is turning into ZX-81 programming, where RAM statements were a very common (and the only?) way to keep ML code with a Basic program.

In ZX Basic though (at least Speccy), there is GOTO A where A is a variable. It doesn't work with CBM Basic, but using this extention you can get the same effect.
Anders Carlsson

Image Image Image Image Image
Rob Murphy
Vic 20 Drifter
Posts: 35
Joined: Fri Dec 17, 2004 8:14 pm

Post by Rob Murphy »

Wow!

That's great. Mike you sure know your stuff. And using that little piece of memory after the screen, very nice(I like that).

Maybe I'll run some more of those C64 tricks past you guys and see what happens.

The Later RUN mags catered more twards 64/128 things.

Thanks.
Rob Murphy
Post Reply