"basic label" jumper (in asm ofcourse)

Got a brilliant program idea? Let us know!

Moderator: MaxCoderz Staff

DarkAuron
Maxcoderz Staff
Posts: 1349
Joined: Sat 18 Dec, 2004 6:53 pm

Post by DarkAuron »

Well of course, but you should always push TI-BASIC to its limits. And using Return clears up any blocks its in, so it won't memory leak.
[Gridwars Score] - E: 1860037 M: 716641 H: 261194
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

but uhm, wouldnt it like return to shell/OS/calling program?
DarkAuron
Maxcoderz Staff
Posts: 1349
Joined: Sat 18 Dec, 2004 6:53 pm

Post by DarkAuron »

Yes, it returns it to the calling program. But if that calling program calls itself, i.e. being recursive in a way, then you can build subroutines within a program.
[Gridwars Score] - E: 1860037 M: 716641 H: 261194
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

oh yea you did it that way..
but its still faster to do it in asm..
Gambit
Sir Posts-A-Lot
Posts: 252
Joined: Mon 21 Feb, 2005 5:34 am
Location: Laveen, Arizona

Post by Gambit »

Whenever you execute the 'jp' or 'jr' instruction in assembly, you modify a register called the program counter. If you draw parallels, BASIC too must have some form of a program start, program end, and program counter.

http://wikiti.denglend.net/index.php?ti ... s:RAM:965F
http://wikiti.denglend.net/index.php?ti ... s:RAM:965D
http://wikiti.denglend.net/index.php?ti ... s:RAM:965B
http://wikiti.denglend.net/index.php?ti ... s:RAM:9652

How can you use these variables to search a BASIC program for all the label tokens and generate a table of labels? And once that's done, how can you intercept a Goto so that it will jump using this table instead of its default "searching the program from the top untill it finds the right label?"

Just some thoughts to get you thinking. :wink:
"If SOURCE is outlawed, only outlaws will have SOURCE."
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

ok thanx mate

edit: maybe i could make a asm program to use instead of "Goto", maybe, but intercepting goto's is something for great programmers who make apps with parserhooks..
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

the code that should search the calling basic program for any labels and store them all in savesscreen (first token, second token, h, l) hl being the location of the label with the name token1+token2.
but would it? (my code so ineffecient, i know, and probebly loads of mistakes)

Code: Select all

Search:
		ld ix,$965F	;BASIC end
		ld l,(ix)
		inc ix		;}load hl with basic-end
		ld h,(ix)
		ld ix,$965B	;BASIC start
		ld c,(ix)
		inc ix		;}load bc with basic-start
		ld b,(ix)
		push bc
		SCF
		CCF
		sbc hl,bc	;hl is now the length (end - start)
		push hl
		pop bc		;length of basic prog in bc
		pop hl		;begin of basic prog in hl
		ld a,tLbl	;compare with tLbl
		ld de,savesscreen	;destination
searchloop:
		cpir		;search untill end-of-prog or Lbl encountered
		ret nz		;end reached
		ldi
		ldi	;save 2 tokens: label name1+name2
		push de
		pop ix
		ld (ix),h
		inc ix			;token 1, token 2, h, l, next label
		ld (ix),l
		inc de
		inc de
		jr searchloop
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

I made an app with parserhook that intercepts Lbl and Goto but doesnt actually do anything with them yet, working on it..
Edit: it now works, great fun. But it only stores 16 labels* because otherwise the appvar would get huge.
*: or the same label up to 16 times, which happens when you repeat over a label.. I'll work on rejecting a label that allready exists.
note: I used my own parser equates which can be found here and it still works (for once I didn't completely mess everything up)
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

I clocked it, and.. its crap. So just use the old Lbl I guess they weren't that bad, and they support forward refference, my code just hand controll back to the TI OS when it can't find a label, so if a Goto is a forward refference, you'd end up doing the same but with a huge overhead included, otherwise it was only a little bit faster (although it probebly makes a difference in huge programs, but just use Repeat, While and For, they're just as fast and don't need an appvar for storage)
Post Reply