Something special about BASIC line 0

By Eugeny_Brychkov

Paragon (1127)

Eugeny_Brychkov's picture

16-02-2020, 21:26

Found a funny thing, never caught it before and have no idea if it is documented and ever found before.
If you type
0 screen 2
or any other command into line 0, then perform LIST, it displays
0--SCREEN 2
where '-' is space. Then if you get up two lines up and press ENTER on listed line 0, then perform list again, you will have
0---SCREEN 2
BASIC adds one extra space to line 0 at its beginning. Does not happen for other choices I tested.

Login or register to post comments

By Gig71

Resident (39)

Gig71's picture

16-02-2020, 23:09

Just tested.
Funny Thing !

By Manuel

Ascended (16125)

Manuel's picture

17-02-2020, 00:03

Yeah, I noticed that as well (don't remember when, must have been decades ago)... Perhaps someone could find out whether it's a bug or a side effect of some other thing.

By thegeps

Champion (366)

thegeps's picture

17-02-2020, 00:17

Wrote about this also in my 10liner code description two days ago..

https://www.msx.org/forum/msx-talk/development/10liner-basic...

By Parn

Champion (485)

Parn's picture

17-02-2020, 15:01

I stumbled upon this decades ago, when I made most of my FM-BASIC music. I used lines 0 to 9 to put information like track name, where it was from, original composer, date of composition and arrangement and such. I soon noticed line 0 worked differently from other lines by not ignoring any space between its number and its content. I noticed this happens while tokenizing the line, but I don't know why.

By Pencioner

Paragon (1077)

Pencioner's picture

17-02-2020, 16:46

Line number 0 is presented as two zero bytes when tokenized. Two zero bytes also used for indicating end of basic program in memory (after last line). Might be this is kind of protection from false positive of program end by putting &h20 (space) after the line number 0? So it could have a check for two zero bytes and then next byte shouldn't be a space, to indicate end of basic program?

By Parn

Champion (485)

Parn's picture

17-02-2020, 17:52

I don't think so, since the end of the program is also marked on the last line. Also, no spaces are stored when you don't put a space between 0 and its first statement. The only difference is that when you explicitly write a single space between the line number and its first statement, it will be ignored during tokenizing if the line isn't numbered 0.

By pgimeno

Resident (64)

pgimeno's picture

17-02-2020, 23:42

My tokenizer supports this quirk (I think it's a bug):

https://notabug.org/pgimeno/vdptest/src/4ac0262980e4f4469d6b...

Entering e.g. 0SCREEN 2 removes the space.

Edit: Yes, it's a bug. The same entry point used for direct commands is used for entering lines, and a zero line number (in register DE at that point, routine at 4195h in the HX-10 ROM) is interpreted as a direct command, which makes it not skip the first leading space, not sure why it wants to keep it but that's the cause.

L4195:
  LD A,D
  OR E
  JR Z,L419F
  LD A,(HL)
  CP ' '
  JR NZ,L419F
  INC HL
L419F: