4

I want to end a C128 lm program the same way as the BASIC NEW command was executed. I tried to call the known entry point at $51D6 via JSR but is seems to not perform.

3
  • Can you not just execute NEW itself from the program? That would have been the first thing I tried. Or are some commands only valid in immediate mode (i.e., not in a running program)?
    – paxdiablo
    Commented Aug 14, 2023 at 2:48
  • Hi, sorry, I didn't specify the program is written in C.
    – Sergio
    Commented Aug 14, 2023 at 9:02
  • Ah, that makes more sense. But would the BASIC NEW command necessarily stop a running executable? I would have thought it would simply clear out the BASIC code. Though, keep in mind I'm not au fait at all with Commodore boxes, they were way to expensive for me in my youth.
    – paxdiablo
    Commented Aug 14, 2023 at 10:02

1 Answer 1

6

The C128 ROM-BASIC's NEW command starts with a test for parameters that follow and expects none - makes sense as NEW shouldn't have any (*1). This is communicated by the zero flag. If not set on entry (meaning parameters follow), it will return without doing anything as seen here:

51D6: F0 01 BEQ $51D9
51D8: 60    RTS

51D9: A9 00 LDA #$00
51DB: ...

Two possible ways to use this:

  • Clear the zero flag before calling to $51D6 (like by LDA #0;JSR $51D6).

Or

  • Use $51D9 as alternate entry point circumventing the whole test (JSR $51D9).

Pick your flavour :)


In C64's BASIC-ROM the same is seen at $A642 - with $A644 being the entry point to avoid the test.


P.S.: That's how to call NEW, but keep in mind that NEW does not clear any memory. It resets BASIC pointers to start value and creates a zero length program. The rest of program (and data) memory stays intact (*2). It also cares only about BASIC variables, not other variables regarding system configuration.

If removing your code (and data) from memory is your goal, then your program has to do it directly and on its own.


*1 - At least not in MS-BASIC - more classic BASIC may disagree (see here at p.20 :))

*2 - That's also why it's possible to restore a BASIC program after NEW as described in this answer.

9
  • Hi, thank you for your answer. I just tried on VICE doing this: I added a row like: 10 PRINT after in the monitor I added at address $1300 this: LDA #0 JSR $51D6 RTS Out of the monitor I did: SYS DEC("1300") but then break into monitor at $3751 on bank 0. jsr to $51D9 break into the monitor as well. In all the cases the basic pgm is still there. One this I noticed, is that after going to the monitor if I exit and I retry to sys to 51d9 or 51a6, it does not break into monitor and the pgm is cleared! So how can I do this preventing it to enter into the monitor ?
    – Sergio
    Commented Aug 14, 2023 at 8:50
  • I'm looking at the disassembly of the c128 ROM at klasek.at/c64/c128-rom-listing.html, I don't understand why it goes to $03750...
    – Sergio
    Commented Aug 14, 2023 at 9:04
  • 1
    @Sergio It sounds like if you're expecting NEW to clear memory in some way? That's not how it works. New doesn't do this. New only resets all pointers and inserts a zero length program at the beginning of BASIC memory. If you want to clear out your code or da, you'll have to do this by hand. (Also the reason why it's always good to add the goal to be reached in a quetsion, not the way).
    – Raffzahn
    Commented Aug 14, 2023 at 11:26
  • If you just want to return the machine to a usable Basic call one of the BASIC entry points - either warm or cold. They are at the top of the ROM Disassembly in the answer.
    – Brian
    Commented Aug 14, 2023 at 11:59
  • I'm not an expert, but if I type new, and after that I type list or I check the free memory. The memory is greater than before and the basic pgm is no more present in memory. I want to do the same. If I was in basic I could simply add new on the last line to be executed. I'm in C , and I want to clear the memory invoking the new routine when I exit the program (as written in the first question). I can't call a warm not a cold reset because I've the option to go back where I was thanks to an LM adding a new basic command.
    – Sergio
    Commented Aug 14, 2023 at 18:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .