3

As mentioned in this answer about how the C64 stores BASIC program text, MS-BASIC uses a pointer called TXTTAB that points to the start of the program text, which is typically at address 1 in a page. For example, on the Commodore 64 it's at address $0801:

PRINT PEEK(44), PEEK(43)
 8         1

As 8-Bit Show and Tell points out at 20:29 in this video (which is demonstrating a technique developed decades ago), when moving the BASIC program text start area, you need to ensure that the byte just before your new TXTTAB start point is set to 0 for BASIC to function properly:

POKE 1024 [the byte before the new TXTPTR], yeah, that's the start of BASIC memory, just putting a zero there, which is necessary; if you don't do that you'll get syntax error when you try to do anything in BASIC, even if you try and LIST.

This is not entirely correct; in VICE I tried POKE 2048,1 and LIST still worked, but other commands, such as NEW, RUN and GOTO 10 (after I'd entered a line 10) did produce ?SYNTAX ERROR.

The Apple II+ (emulated with AppleWin) running Applesoft BASIC has similar issues; POKE 2048,1 produces ?SYNTAX ERROR when I type NEW (though it does clear the program) and with the program 10 PRINT "HELLO" in memory, typing RUN produces ?SYNTAX ERROR in 65044.

The same issues also arise on an MSX2 machine (Sony HB-F1XD emulated with OpenMSX): POKE 32768,1 produces syntax errors for NEW and RUN with a program similar to the above.

Why is that location required to be zero?

cjs
  • 25,592
  • 2
  • 79
  • 179
  • 2
    Is this a duplicate or does the same answer apply? https://retrocomputing.stackexchange.com/questions/17475/basic-assembler-startup-code-c64 – Justme Jun 05 '22 at 21:33
  • Is your emulator able to set a watchpoint on that address, so that it drops to the debugger when it is read or written? That would help identify the code that accesses it, and then you could try to figure out what it does. – Nate Eldredge Jun 05 '22 at 22:24
  • @Justme No, that's pretty much entirely unrelated. That guy's just got the start point for BASIC program text incorrect (he's using [TXTTAB]-1 rather than [TXTTAB]). He could make it work fine after loading by setting the value in TXTTAB to $0800 and putting 0 in $07FF. Or recreate the problem above by putting 1 in $07FF. I am not shifting my program to the wrong location; I am simply changing a location just outside my program, a location one that doesn't have any apparent use. – cjs Jun 06 '22 at 01:25
  • 1
    @cjs There is a comment that should be an answer for you : "on the first location a 0 is needed because the RUN command starts with the BASIC text pointer pointing to the last read character. This 0 byte provides an end-of-line condition, which let the interpreter search for the next line (an implicit GOTO 0) and advance to $801 as the first line to interpret" which is confirmed by another comment about disassebly of RUN. – Justme Jun 06 '22 at 05:00
  • @Justme Well, it turns out this is a duplicate question, or almost one, just not a duplicate of the question you were looking at. Why does Applesoft get confused by a nonzero value at $0800? doesn't mention that this is not an Applesoft-specific problem, but has an answer explaining what's going on with the RUN command, though not the NEW command. It didn't come up in my search because the answer misspells TXTTAB as TEXTTAB. (It is spelt correctly in comments on that answer; apparently search doesn't look at comments.) – cjs Jun 06 '22 at 06:20
  • (BTW, I'm leaving the question open in the hope that someone will explain what's up with NEW, and what other commands would also be affected by this design decision.) – cjs Jun 06 '22 at 06:32
  • 2
    If this is about the details of New, then better close this and do a dedicated follow up to Why does Applesoft get confused by a nonzero value at $0800? focused on that item Otherwise it's just confusing future readers. – Raffzahn Jun 06 '22 at 08:14
  • @Raffzahn Please read the previous comments. That post has already been linked by me with further explanation. – cjs Jun 06 '22 at 08:17
  • @Raffzahn I did read your original comment. Changing it with a drastic edit after I've responded and then scolding me for not knowing you were going to edit it is not very nice. I don't need the aggro, so let's not continue this discussion. – cjs Jun 06 '22 at 08:20
  • @cjs Mind to read as well? Thinking of it, since you seam to assume by default that others do not read comments (like shown by yourself) this makes a great example why redefinition in comments is not a good idea. If you still want to know the fine details of NEW, closing and doing a focused question would be the way to go. – Raffzahn Jun 06 '22 at 08:23
  • @cjs Which original comment? 4 years on RC.SE and it's still NEW to you that issuing a close by dupe does create an automated entry? Come on... I think it's a good idea to turn such default entries into something more useful, do you? Also, the only 'aggro' here is added by you by replying within seconds in defensive manner.What about using that time to think rather before writing (did again, didn't you) and see how to improve your questions instead of trying to force it down? – Raffzahn Jun 06 '22 at 08:28

0 Answers0