commanderx16 / x16-rom

Other
153 stars 43 forks source link

LOAD restarts BASIC program #138

Open ekmett opened 4 years ago

ekmett commented 4 years ago

We have 3 behaviors that are out of sync between the actual emulator/rom, the programmer's reference manual, and the way the Commodore worked with LOAD from within a running BASIC program.

Whenever I run LOAD from within a BASIC program, the running basic program restarts.

But the example from the Programmer's Reference Manual fires off several LOADs in series:

  10 REM LOAD VERA SETTINGS
  20 LOAD"VERA.BIN",1,17 : REM SET ADDRESS TO $FXXXX

actually loops back to the start here rather than progress to

  30 REM LOAD TILES
  40 LOAD"TILES.BIN",1,3 : REM SET ADDRESS TO $1XXXX
  50 REM LOAD MAP
  60 LOAD"MAP.BIN",1,2 : REM SET ADDRESS TO $0XXXX

When I saw this example, I'd first hoped to use this to prep a loading screen from file, blit data into banks, and then launch the real body of the program without any setup cruft taking space in the main PRG. It strikes me that it is more powerful to be able to do this sort of binary data loading thing directly rather than having to OPEN and blit data into the right place yourself.

Even if you still need to figure out the right behavior for chainloading.

But even though we restart, so the Progammer's Reference Manual example breaks, we aren't able to do the same things we did do back on the Commodore. The restart acts different in other ways.

When it does restart itself, even when it doesn't clobber the running program, the READ cursor and variables happen to reset. But that means you don't really have any good way to track your progress through your chainloader. (Literally the only trick I could come up with was to peek/poke $803 and change the first line number into a stage counter!)

1 READ M,F$,N:POKE 40801,M:PRINT F$:LOAD F$,8,N
2 DATA 1,"BANK-1.BIN",1
3 DATA 2,"BANK-2.BIN",1
4 DATA 1,"MAIN.PRG",0

would be the sort of program I'd expect to have work if we didn't reset READ

Or

1 POKE 40801,1: LOAD "BANK-1.BIN",8,1
2 POKE 40801,2: LOAD "BANK-2.BIN",8,1
3 LOAD "MAIN.PRG"

if we instead matched the behavior in the programmer's reference manual and could do multiple loads without the program restarting.

ekmett commented 4 years ago

I also note that the old c64 SYS57812"FILENAME",8,1 trick doesn't work, because I'm presuming things moved around in the new ROM and it isn't in the documented API, which means invoking the kernel load more directly from BASIC is rather more involved.

ekmett commented 4 years ago

It looks like

LOAD"FOO",8,1,$a000

works without restarting BASIC, but is currently undocumented?

BruceMcF commented 4 years ago

Has the resetting of variables when loading a program from inside Basic been fixed? It seems like between that and an an ability to load to direct memory without resetting basic, then a basic program to check if binaries are in place and execute them, otherwise load them and call itself again, should work.

I tried: 10 IF A=1 THEN GOTO 100 20 A=1 30 PRINT"FIRST" 40 LOAD"2STATE" 100 PRINT"SECOND" SAVE"2STATE"

RUN

gives

FIRST SECOND

So by experiment, it doesn't seem like LOAD from a program is resetting variables.