ZXtool - intimately examine P files

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

ZXtool - intimately examine P files

Post by sirmorris »

Here's a little toy to while away those hours when you're not waving at snowflakes or pursuing other such important activities.

*** Updated to V1.5 20 May 2012 *** : Added more complete variable dumping, array content is now shown


With this tool you can:
  • List the BASIC code
  • View the BASIC variables
  • View the system variables
  • Copy a line of code
  • Insert a line of code
  • Make the program auto-run at a particular line
  • Stop a program from auto-running
  • Other great stuff**
ZX81 P-file Utility by SirMorris V1.5

Largely based on ZX81LIST (C) Jack Raats, Steenbergen 1992

Usage:
ZXTool [p-file name] ([option]...[option])

Options:
vrb : verbose. Extra information is printed.
list : produce program listing.
vars : produce variable listing.
sysvars : produce system variable listing.
noauto : stop the program from auto-running.
auto=[line] : make the program auto-run from the specified line number.
extract=[line] : extract program line to temp.q
insert : insert/overwrite program line from temp.q

If no options are specified, a listing is performed.

I use it in conjunction with my Z88DK programming. Once the C is compiled I extract the REM line to a file and then insert it into the BASIC template that I have already prepared. Set the auto-run line number and away I go! It saves loads of time.

There are a couple of things remaining to do - like displaying the values of arrayed numbers and strings in verbose mode, but it's otherwise complete.

Have a play and let me know how you get on!

Charlie


** this is actually a lie.
Attachments
zxtool.zip
V1.5
(67.64 KiB) Downloaded 711 times
Last edited by sirmorris on Sun May 20, 2012 11:32 am, edited 5 times in total.
User avatar
bbock
Posts: 54
Joined: Wed Jan 12, 2011 7:59 pm

Re: ZXtool - intimately examine P files

Post by bbock »

Hi sirmorris,

that's a cute little tool. I guess it will help me a lot - in conjunction with z88dk, of course :)

Bernd
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: ZXtool - intimately examine P files

Post by sirmorris »

I found it very difficult when my C program required some ZX-BASIC to support it. Now everything happens in my build script :D
User avatar
bbock
Posts: 54
Joined: Wed Jan 12, 2011 7:59 pm

Re: ZXtool - intimately examine P files

Post by bbock »

That's what I am going to do as well, I guess :D
I'm using Eclipse with a cmd file as "build script" - well, probably not the best solution, but it works for me.
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: ZXtool - intimately examine P files

Post by PokeMon »

Great stuff. ;)
Does it work with ZX80 files as well ?
Because Paul always ask for tools for the ZX80.
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: ZXtool - intimately examine P files

Post by sirmorris »

Um... Probably not :)

The simple truth is that there aren't so many ZX80 programs to work with..!

The source code is there too so it shouldn't be hard to convert.

C
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: ZXtool - intimately examine P files

Post by PokeMon »

Maybe I can integrate this in my IDE ? ;)
User avatar
Paul
Posts: 1517
Joined: Thu May 27, 2010 8:15 am
Location: Germanys west end

Re: ZXtool - intimately examine P files

Post by Paul »

And the sad truth is that z88dk also doesn't support ZX80 :(
And as long as I keep on adapting to ZX80 whatever the rest of the world programs for the ZX81, I will hardly ever find the time to write a ZX80 program :shock:
In theory, there is no difference between theory and practice. But, in practice, there is.
User avatar
siggi
Posts: 990
Joined: Thu May 08, 2008 9:30 am
Location: Wetterau, Germany
Contact:

Re: ZXtool - intimately examine P files

Post by siggi »

Paul wrote:And the sad truth is that z88dk also doesn't support ZX80 :(
GOTO http://www.z88dk.org/forum/viewforum.php?id=8
My ZX81 web-server: online since 2007, running since dec. 2020 using ZeddyNet hardware
http://zx81.ddns.net/ZxTeaM
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: ZXtool - intimately examine P files

Post by sirmorris »

I've been asked about merging programs. I'm sure there's an app somewhere which does this more easily, but I haven't found it yet.

Let's say there's 2 programs, one of which has a sizeable chunk of machine code. It's called PLAYER. Another contains a couple of routines you'd like to add to PLAYER. Let's call it GFXRTN.

Using 2 programs: ZXTOOL and ZXTEXT2P we can build our final program. ZXTOOL will export machine code and list the programs as BASIC text, and ZXTEXT2P will recompile to text into a P file. If the machine code is in a REM at line 1 then I'd do the following:

ZXTOOL PLAYER ext=1

This will extract line 1 into its own file; TEMP.Q.

Next, list the BASIC of both files.

ZXTOOL PLAYER.P > PLAYER.TXT
ZXTOOL GFXRTN.P > GFXRTN.TXT

Load the texts into your favourite editor. Remove the machine-code REM as it's going to be put back later.

Note which line numbers are a target for a GOSUB, or GOTO. If there are any computed GOTOs then extra care is needed. Any line which is a target needs to be given a label, and any line referencing the target line needs to have the line number changed from a value to a label like this:

Code: Select all

    CLS
     PRINT "HELLO WORLD."
    @loop1:
    PRINT "THIS IS A LOOP"
    GOTO @loop1
Note that label definitions are given a colon, and references are not. If the GOTO target is variable, make sure the variable or expression uses the label instead of the base line number.

Code: Select all

GOSUB 1000 + 10 * P
...
1000 LET A = 4
1005 RETURN
1010 LET A = 50
etc
would become:

Code: Select all

GOSUB @onethousand + 10 * P
...
@onethousand:
LET A = 4
RETURN
LET A = 50
etc
The sharper-eyed viewers may have noticed that you need to take the line-number increment into account here but I'll leave that as an exercise for the reader.

Once all the labels are in place, remove the line numbers. Do the same thing for the second program then paste them together. Save the merged code as BASE.TXT, or whatever.

Now you can compile the base program using ZXTEXT2P in 'label' mode - instructions here.

When all this is successful, you can put the machine-code back with zxtool;

ZXTOOL BASE.P ins

There you go! Any modifications to call the new code can be made one the old program is tested and working.

Make the new file auto-running if you like, here we'll assume line 10 is the entry point:

ZXTOOL BASE.P auto=10


Have fun!

C
Post Reply