stardot / beebasm

A portable 6502 assembler with BBC Micro style syntax
http://www.retrosoftware.co.uk/wiki/index.php/BeebAsm
GNU General Public License v3.0
83 stars 26 forks source link

PUTBASIC auto-line-numbering doesn't like programs starting with line number 0 #62

Open ZornsLemma opened 2 years ago

ZornsLemma commented 2 years ago

This can be seen by tweaking test/3-directives/basicrhstoken.bas to look like this:

0p=PAGE
PRINT p
?&900=PAGE MOD 256
PRINT FNpage
PRINT ?&900
?&901=TIME MOD 256
PRINT ?&901
PRINT FNtime
END
DEF FNpage
=PAGE
DEF FNtime
=TIME

The corresponding test case then generates the error:

basicrhstoken.6502:1: error: basicrhstoken.bas: Out of sequence line numbers (0 followed by 0) at line 2

(Of course the test would probably fail anyway, as the tokenised BASIC program would have different line numbers and the gold .ssd wouldn't match. I'm just using this as a convenient way to illustrate the problem.)

I suspect the natural fix is as simple as changing the initial value of CurLine from 1 to 0 in ImportBASIC(). This will cause beebasm output using auto-line-numbering of BASIC to change (because line numbers will start at 1 instead of 0); I don't know if it's worth the pain of making a more involved fix.

(Credit to TobyLobster for finding this indirectly; it happens in basictool and I realised PUTBASIC would almost certainly have the same problem.)