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
Calculated GOTO
Moderator: Moderators
- Mike
- Herr VC
- Posts: 4841
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
@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
@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
How cool! Thanks!
/Anders
/Anders
PRG Starter - a VICE helper / Vic Software (Boray Gammon, SD2IEC music player, Vic Disk Menu, Tribbles, Mega Omega, How Many 8K etc.)
- Mike
- Herr VC
- Posts: 4841
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
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
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
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.
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
-
- Vic 20 Drifter
- Posts: 35
- Joined: Fri Dec 17, 2004 8:14 pm