Moving basic memory while running?

Basic and Machine Language

Moderator: Moderators

Post Reply
Boray
Musical Smurf
Posts: 4064
Joined: Mon May 03, 2004 10:47 am

Moving basic memory while running?

Post by Boray »

If I for example have the basic memory set to address 4608, and then load a basic program to address 8192. Can I then do anything to move the basic memory and run that program at 8192? I know how to first move the memory and then load and run (poke8192,0:poke44,32:new), but if I want to do it in the opposite order? First load and then move memory pointers to that loaded program then run. This would allow me to make 1 file games for the expanded vic, rather than 2 or 3 part games...

/Anders
Leeeeee
soldering master
Posts: 396
Joined: Fri Apr 23, 2004 8:14 am

Post by Leeeeee »

Can I then do anything to move the basic memory and run that program at 8192?
You'll need to set the pointers as follows.

Code: Select all

Address Pointer             Value
------- ------------------  -----
43-44   Start of Basic      8192
45-46   Start of Variables  First byte after program
47-48   Start of Arrays     First byte after program
49-50   End of Arrays       First byte after program
51-52   String storage      End of memory+1
Values are 16 bit addresses with the low byte in the low address.

You may only need to set the start of basic and the start of variables and then do CLEAR:RUN or even just RUN may work as it does an implied CLEAR first.

I could be one byte out with some values, it's been a while. 8^)=

Cheers,

Lee.
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

Lee is perfectly correct, which I just verified through emulation (yes, I know I'm a bastard for praising emulation, but since the ROM code should be identical to the real thing, I believe in the results).

1. I started the VIC with 8K expansion memory, issued POKE 44,32:POKE 8192,0:NEW
2. Then I entered a small 10 PRINT"BLAH":GOTO 10 program
3. Then I poked back with POKE 44,18:POKE 4608,0:NEW
4. The program at 8192 is kept intact
5. I run this one-liner 10 POKE 44,32:POKE 8192,0:RUN

Voila! Basic and all the pointers move accordingly and the program starts right away. If you for some reason want to do it the machine code/SYS way, the calls are:

NEW = JSR $C642 (SYS 50754)
CLR = JSR $C65E (SYS 50782)
RUN = JSR $0079:JSR $C659:JMP $C7AE (can not be done through Basic?)

The last line of machine code is very useful if you ever want to start a Basic program from machine language:

$0079 (zero page!) is part of the routine to fetch a byte of Basic text
$C659 resets execution to start of program followed by CLR
$C7AE checks for STOP key and then handles next Basic statement already fetched

It also works perfectly on the C64 if you change the two latter addresses to A659 and A7AE.
Anders Carlsson

Image Image Image Image Image
Leeeeee
soldering master
Posts: 396
Joined: Fri Apr 23, 2004 8:14 am

Post by Leeeeee »

There's probably an easier way to do it. After you've loaded the program into memory and done the POKE 44,32 if you call the routine that rebuilds the BASIC line chain it should set all the pointers except the end of memory for you.

I don't have a disassembly of BASIC 2 handy so don't know the entry point to this routine but it's what I do in my 680x0 BASIC after loading a program binary image.

Lee.
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

There are a few entries to warm-start Basic. I wonder if any of those can be useful. Otherwise, Funet has memory maps etc if one can't find those elsewhere. The all-Basic way should work, or otherwise we have some ideas how to approach in machine code.

680x0 Basic? Is it also derived from Microsoft's one?
Anders Carlsson

Image Image Image Image Image
Boray
Musical Smurf
Posts: 4064
Joined: Mon May 03, 2004 10:47 am

Post by Boray »

Thank you very much! I will try it right now!

/Anders
Leeeeee
soldering master
Posts: 396
Joined: Fri Apr 23, 2004 8:14 am

Post by Leeeeee »

680x0 Basic? Is it also derived from Microsoft's one?
Nope. It's similar syntax but the code is mine, every byte of it.

Lee.
Boray
Musical Smurf
Posts: 4064
Joined: Mon May 03, 2004 10:47 am

Post by Boray »

It worked! Just as Lee described.... But I found an even simpler way. When a program is loaded, the poiners 45,46 etc. are automatically set to behind the loaded program, and because I have the basic program last in the resulting file, those pointers are set by themselves when the file is loaded. I only have to change the start pointer.

So, if you have the basic starting at 8192, you only have to do the following...

(reset)

10 poke 44,32:run
(make the small basic start)

load "gfx and machine language part",8,1
(loads into the graphics mem)

poke 44,32: poke 32*256,0: new
(move basic to 8192)

load "basic part",8
(load main basic part)

poke 44,18
(move back the beginning of basic to default)

save "whole program",8
(And everything saves as one big file)

Very nice as you don't even have to bother to look what the ending address is...

Thanks again for the help! I will post the result(s) soon in the "expanded programs" section...

Btw, Lee... Your 680x0 basic... Is it for amiga?

/Anders
Leeeeee
soldering master
Posts: 396
Joined: Fri Apr 23, 2004 8:14 am

Post by Leeeeee »

No, it's for any 680x0 computer that has at least character I/O. I wrote it because I had a 68008 single board computer and wanted something to interactively manipulate the hardware.

Go see ..

http://www.themotionstore.com/leeedavis ... index.html

for more details.

Lee.
vic user
VicGyver
Posts: 1401
Joined: Thu Mar 25, 2004 9:40 am

Post by vic user »

So this could actually work on a 68030 computer, like a Mac SE30?

Chris
Leeeeee
soldering master
Posts: 396
Joined: Fri Apr 23, 2004 8:14 am

Post by Leeeeee »

Probably, though it is not OS friendly or even OS aware. I dare say it could be made to work on the bare motherboard by writing some character I/O routines for the serial port (I assume there is one) and making a set of ROMs to replace the Apple ROMs.

It has been ported to the Atari Jaguar, but not by me.

Lee.
vic user
VicGyver
Posts: 1401
Joined: Thu Mar 25, 2004 9:40 am

Post by vic user »

well it sounds exciting to try anyway.

i would love to have BASIC on that little mac.

chris
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

Isn't there something like MacBasic available for warez download somewhere?
Anders Carlsson

Image Image Image Image Image
vic user
VicGyver
Posts: 1401
Joined: Thu Mar 25, 2004 9:40 am

Post by vic user »

well, there is chipmunk basic, free for download.

all i have to do now, is find a copy of unstuffit, then dowload chip

chris
Post Reply