Program that adds statements to a BASIC program

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
User avatar
mrtinb
Posts: 1120
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Program that adds statements to a BASIC program

Post by mrtinb » Sat Nov 07, 2015 9:30 am

Hi :)

I would like to modify a BASIC program via BASIC (or ML).

It’s easy to read from the BASIC program, as that starts at address PROGRAM 16509/407D.

It should also be relatively simple to modify the program, as long as it’s modifying from one char to another.

The problem arises when you want to insert new lines into the BASIC program. Then the whole memory has to be pushed forward in memory.

Is there any subroutines in ROM that does this, I can use?

I know from Commodore 64 it was possible to fill the keyboard buffer with chars e.g. “50 PRINT A$<NL>” and this statement would be executed resulting in a new line added to the program.

From reading the ‘ROM Disassembled’-book for ZX81, it seems like there’s no keyboard buffer, and routine that inserts statements into the BASIC program, reads directly from the keyboard.

Any thoughts on this?

/Martin
Last edited by mrtinb on Thu Mar 17, 2016 4:21 pm, edited 1 time in total.
Martin
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube

User avatar
siggi
Posts: 883
Joined: Thu May 08, 2008 9:30 am
Location: Dauernheim, Germany
Contact:

Re: Program that adds statements to a BASIC program

Post by siggi » Sat Nov 07, 2015 11:20 am

Yes, there is a ROM routine, which can be used (of course in FAST mode) to make space anywhere (e. g. in program or variable section) and which also updates the pointers in the system variables, which are affected by that. I used this routine in MEFISDOS (m/c) to insert BASIC lines into an existing BASIC program.
I will post the code later ...

Siggi
My ZX81 web-server: online since 2007
http://zx81-siggi.endoftheinternet.org/index.html

User avatar
siggi
Posts: 883
Joined: Thu May 08, 2008 9:30 am
Location: Dauernheim, Germany
Contact:

Re: Program that adds statements to a BASIC program

Post by siggi » Sat Nov 07, 2015 3:25 pm

Hi Martin
the routine to make space is located at $99E in ROM. BC register must hold the size of the memory block needed, HL points to the address, where the space is needed.

Code: Select all

ld BC, length
ld HL, address
call $99e
After that, you can "poke" that space to get the new BASIC line there.

Wilf Rigter's RAMDOS is an example, how to insert a BASIC-program or variables to an existing program:
http://www.user.dccnet.com/wrigter/inde ... RAMDOS.htm

See label "LOADB" in the RAMDOS listing:
http://www.user.dccnet.com/wrigter/inde ... RD2SRC.txt

HTH Siggi
My ZX81 web-server: online since 2007
http://zx81-siggi.endoftheinternet.org/index.html

User avatar
mrtinb
Posts: 1120
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: Program that adds statements to a BASIC program

Post by mrtinb » Mon Jan 25, 2016 4:12 pm

Thank you very much.

It was just What I needed.

/Martin
Martin
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube

User avatar
Math123
Posts: 34
Joined: Sun May 11, 2008 11:14 pm
Location: Germany Wuppertal
Contact:

Re: Program that adds statements to a BASIC program

Post by Math123 » Wed Mar 16, 2016 6:14 pm

Hi Martin,

some times ago I made a Basic program that can add Basic-lines at its end. It uses only PEEK and POKE and a tricky hack to make space.
genline.p
(2.16 KiB) Downloaded 110 times
I am still looking to find a way for deleting lines...
If there is a solution, then someone could make a Basic-program that ist able to replicate and/or modify itself. :shock:

Matthias

User avatar
Andy Rea
Posts: 1546
Joined: Fri May 09, 2008 2:48 pm
Location: notts UK

Re: Program that adds statements to a BASIC program

Post by Andy Rea » Wed Mar 16, 2016 7:14 pm

Haha cool, could this.be the beginning of a virus for zx81 ?::
6 x ZX81, 1 x TS1500 , 1 x +3e, 1 x timex 2040 printer, 1 x timex 2020 cassette deck, siclair printer and some spectrum

User avatar
1024MAK
Posts: 2564
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: Program that adds statements to a BASIC program

Post by 1024MAK » Thu Mar 17, 2016 12:15 am

ZeddySkyNet :shock: :?

User avatar
siggi
Posts: 883
Joined: Thu May 08, 2008 9:30 am
Location: Dauernheim, Germany
Contact:

Re: Program that adds statements to a BASIC program

Post by siggi » Thu Mar 17, 2016 3:34 pm

Math123 wrote:Hi Martin,

some times ago I made a Basic program that can add Basic-lines at its end. It uses only PEEK and POKE and a tricky hack to make space.
genline.p
I am still looking to find a way for deleting lines...
Did you try "THE 'RECLAIMING' SUBROUTINES"?

http://k1.spdns.de/Vintage/Sinclair/80/ ... ra%29.html

Siggi
My ZX81 web-server: online since 2007
http://zx81-siggi.endoftheinternet.org/index.html

Post Reply