Jump to content
  • 0

List BASIC Keywords Program in BASIC or Forth, How to Write?


mobluse
 Share

Question

I would like to write a program in BASIC or Forth that runs on X16 and that lists the keywords in Commander X16 BASIC v2 by reading them from ROM.

I found this old question of mine: https://web.archive.org/web/20200530202849/http://temp.murray2.com/threads/list-basic-keywords-program-in-wiki-doesnt-work.425/

I was wondering if any progress have been made. The problem was that you could not read from another ROM bank than Kernal from BASIC.

Link to comment
Share on other sites

14 answers to this question

Recommended Posts

  • 0
Posted (edited)

I've made some progress, and found a block with BASIC keywords in bank 4.

10 GOTO 1000
100 POKE $7E,L:POKE $7F,H
110 POKE 780,$7E:POKE 781,B:POKE 782,0:SYS $FF74
120 G=PEEK(780)
130 RETURN
1000 A$=""
1010 FOR B=0 TO 7
1020 FOR H=$C0 TO $FF     
1030 FOR L=0 TO $FF
1040 GOSUB 100
1045 C=G AND 127
1050 IF NOT(ASC("A")<=C AND C<=ASC("Z")) THEN GOTO 1058
1052 A$=A$+CHR$(C)
1054 GOTO 1060
1058 A$=""
1060 IF NOT(G>127) THEN GOTO 1070
1064 A=LEN(A$)
1066 IF A>=3 THEN PRINT A$
1068 A$=""
1070 NEXT
1080 NEXT
1085 PRINT CHR$(7);
1090 NEXT

Edited by mobluse
Link to comment
Share on other sites

  • 0

Now I succeeded to write a program, similar to the original, that lists the keywords in Commander X16 BASIC v2:

10 GOTO 1010
100 POKE $7E,L:POKE $7F,H
110 POKE 780,$7E:POKE 781,B:POKE 782,0:SYS $FF74:REM FETCH
120 G=PEEK(780)
130 RETURN
1010 B=4
1020 BASE=$C0DE
1030 FOR P=BASE TO BASE+388
1035 H=INT(P/256):L=P-256*H
1040 GOSUB 100
1050 PRINT CHR$(G AND 127);    
1060 IF G>127 THEN PRINT ,
1070 NEXT

Now I would like to print the keyword abbreviations, also from ROM. Anyone who knows how to do this?

2022-05-30-204048_640x480_scrot.png

  • Like 1
Link to comment
Share on other sites

  • 0
On 5/30/2022 at 1:54 PM, desertfish said:

I think the abbreviations are not listed explicitly and just defined as "first letter of token" followed by "shifted second letter of token".

That works for some of them. PRINT# is pR, but PRINT is ?.

Link to comment
Share on other sites

  • 0
  • Super Administrators
On 5/30/2022 at 1:11 PM, desertfish said:

hmmm that is peculiar indeed, I notice that '?' is absent from the list above too, while some operators ARE in the token list. 

Actually all of the operators are on the token list. The ? is not because it's not an operator or keyword. The question mark is converted to the PRINT token when a line is tokenized. The only time you'll actually see a question mark in a program listing is inside of quotes. 

  • Like 1
Link to comment
Share on other sites

  • 0
Posted (edited)

I discovered that the abbreviations can be deduced from the order of the keywords generated by the program. An earlier keyword can have a shorter abbreviation. If a full word is needed it cannot end in a letter of the opposite case. Use R41:

x16emu -bas keywords.bas -run -echo

Copy console output to a bas-file. 

x16emu -bas abbr.bas -echo

LIST

They should be the same program that cannot run, but demonstrates abbreviations that work. It would be possible to write a BASIC program that can list the abbreviation for each keyword.

keywords.bas

abbr.bas

Edited by mobluse
Link to comment
Share on other sites

  • 0

Yes, I saw the video when it came out, but now I've watched it again: 

BTW The gosuB bug is also in X16 R41. I have some old pocket computers that also have the possibility to abbreviate commands, but those abbreviations are more normal, ending with a dot.

  • Like 1
Link to comment
Share on other sites

  • 0

I figured out how to derive the abbreviations from the order of the keywords, see this program and game:

Now I'm interested to know how I find built in variables in ROM or RAM: e.g. TI, TI$, and ST; these also exist in C64. There are things in X16 BASIC v2 that now are keywords, e.g. MX and MY, but AFAIK could have been built in variables like ST. Why are variable like things sometimes keywords and sometimes built in variables?

Link to comment
Share on other sites

  • 0
  • Super Administrators
On 6/7/2022 at 6:53 AM, mobluse said:

Why are variable like things sometimes keywords and sometimes built in variables?

The difference is that a keyword that returns a value is a function. Functions need a symbol on the token table, and they are executed like commands in the BASIC program. Most importantly, functions always have parentheses after them, marking them as functions, not as variable. 

Things like SIN(X) or INT(Z) are examples of functions, and you'll find those on the token table. You won't find MX or ST, because pseudo-variables aren't functions, they are actually "constants" (which are not...constant.). 

As far as I can tell, the interpreter directly checks for certain two-letter combinations when it evaluates variable names. The actual decision about whether to use a constant (just MX) or a function [something like MOUSE(n) ] to read the mouse position is probably arbitrary: the constant uses less code to implement and may be easier to remember. The down side is that introducing new BASIC constants can step on existing programs, and I've had type-in programs and programs written for C64 fail when running on the CX16, because they attempted to use variable names that the Commander reserves as constants.

 

 

 

  • Like 1
Link to comment
Share on other sites

  • 0

But my keyword quiz game above finds variable like MX, MY, and MB (which start to work after MOUSE 1) on the token table, but it doesn't find ST, TI, and TI$. You cannot assign to MX, MY, MB, and ST, but you can assign to TI and TI$, but not out of range number to TI (e.g. 1E8) or non-time strings to TI$.

Link to comment
Share on other sites

  • 0

Yeah.

It's inconsistent.

But that's because each of these types of thing is a separate category.

ST, for example, is part of file I/O, so the code that handles it is in that part of the ROM.

TI, TI$, and DA$ are reserved variables, that can be assigned specific values, but also have their values updated by other hardware in the system.

MX, MY, and MB are more like GET, in that they exist to make user input available to the interpreter. They aren't really variables; they're more like functions that take no arguments.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use