Hidden BASIC lines at end of program space

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
stroebeljc
Posts: 63
Joined: Thu Apr 23, 2020 6:02 am

Hidden BASIC lines at end of program space

Post by stroebeljc »

I was looking for a trick here that I haven't seen discussed yet. Maybe it is, but I just haven't searched thoroughly enough. Anyway, I can describe it here. I have a program in which the last BASIC line, a REM statement, is totally hidden from the program listing. It's intended to contain, of course, assembly code. However, it's the manner in which this line is created that is interesting.
  1. At the end of the program, create a REM statement with an adequate number of trailing spaces to store the assembly code.
  2. If you're starting fresh and this is the only line in your code, then POKE 16509,118 at the command line (this is the high byte of the line number).
  3. Otherwise, count back from the value of D-FILE by the (number of spaces + 6) and POKE that address with 118.
  4. LIST will no longer show this line!
You can then use addresses from D-FILE minus (number of spaces + 5) to D-FILE minus 1 for code.
The other piece is that you need to determine any POKE addresses and USR call addresses at runtime by reading D-FILE and subtracting offsets from it.

Has anyone ever done this?
Last edited by stroebeljc on Wed Apr 29, 2020 4:13 pm, edited 1 time in total.
John
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Hidden BASIC lines at end of program space

Post by XavSnap »

Code: Select all

1 REM HELLO
2 PRINT "HELLO"
3 REM [DEC : 118,118]
1 REM [DEC : 118,118,0,0,0,0,0,0,0,0,0,0,0,201]
:o
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
stroebeljc
Posts: 63
Joined: Thu Apr 23, 2020 6:02 am

Re: Hidden BASIC lines at end of program space

Post by stroebeljc »

XavSnap wrote: Tue Apr 28, 2020 10:12 pm

Code: Select all

1 REM HELLO
2 PRINT "HELLO"
3 REM [DEC : 118,118]
1 REM [DEC : 118,118,0,0,0,0,0,0,0,0,0,0,0,201]
:o
Yup
John
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Hidden BASIC lines at end of program space

Post by dr beep »

stroebeljc wrote: Tue Apr 28, 2020 9:33 pm I was looking for a trick here that I haven't seen discussed yet. Maybe it is, but I just haven't searched thoroughly enough. Anyway, I can describe it here. I have a program in which the last BASIC line, a REM statement, is totally hidden from the program listing. It's intended to contain, of course, assembly code. However, it's the manner in which this line is created that is interesting.
  1. At the end of the program, create a REM statement with an adequate number of trailing spaces to store the assembly code.
  2. If you're starting fresh and this is the only line in your code, then POKE 16509,118 at the command line (this is the high byte of the line number).
  3. Otherwise, count back from the value of D-FILE by the (number of spaces + 6) and POKE that address with 118.
  4. LIST will no longer show this line!
You can then use addresses from D-FILE minus (number of spaces + 5) to D-FILE minus 1 for code.
The other piece is that you need to determine any POKE addresses and USR call addresses at runtime by reading D-FILE and subtracting offsets from it.

Has anyone ever done this?
Yep... see the manual of USCII

Code: Select all

USCII : User Specified Character Integrated Interpreter
-------------------------------------------------------

Introduction:
-------------
Hires graphics are possible on a ZX81. Games are written in it.
However in BASIC you never had a utility to define your own graphics.
Finally (2019) you can use 25 user characters together with the default ROM-set
in your own games.

How to use:
-----------
Load the USCII like any other game.
After loading you will see 1 line with 
"0 REM PRINT USR 22722;H"
This line holds a lot more data, but it is made invisible.
NEVER delete this line. The line holds the machinecode for the interpreter, 
the hiresscreen and the data for 25 user graphics.

You can now code your own program. The first line to enter is a bit slow, but after
that the program can be typed quicker.

With USCII you will get the use of extra commands to select a hires mode and your own 
characters. The commands are easy to use and most error checking is done by the ROM.
All extra commands will start with PRINT USR 22722

Switch hiresscreen on:
----------------------
PRINT USR 22722;H
The game will now show the hires screen until BREAK is pressed or hires display is switched off.

Switch hiresscreen off:
-----------------------
PRINT USR 22722;L
The game will return to the standard screen. The hiresscreen is saved as it is now.

Clear hiresscreen:
------------------
PRINT USR 22722;C
You are allowed to type CLS also.

Define user specified characters:
---------------------------------
You have 25 characters free to define. They start at 192 up to 216 (25!).
You can define characters by
PRINT USR 22722;U;nr;d1;d2;d3;d4;d5;d6;d7;d8
The U for USC and nr is the USC to start and d1 to d8 the value (0-255) for the character
Multiple USC can be set by adding more data. The program will automatically set the next USC.
You can also set USC 1 by 1

Printing on hiresscreen:
------------------------
Each PRINT starts with PRINT USR 22722; 
After that you can use AT (not TAB) and text like you do in lowres.
The USC can be printed as CHR$ 192 and on.
Only integer numbers from 0 to 65535 can be printed, other numbers must use the slow STR$

Errors:
-------
When an error occurs this will not show, when your game freezes just press BREAK and the error
will show on the lowres screen.
Adding too much USC with too much data will not give an error, but will corrupt your BASIC.

Saving program:
---------------
When you save your code the graphics and hiresscreen at that moment are saved too.
stroebeljc
Posts: 63
Joined: Thu Apr 23, 2020 6:02 am

Re: Hidden BASIC lines at end of program space

Post by stroebeljc »

Cool!
John
User avatar
mrtinb
Posts: 1906
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: Hidden BASIC lines at end of program space

Post by mrtinb »

It is UDG (user defined graphics) emulated with WRX hires graphics (Wilf Rigter graphiX).

(WRX requires a hardware modification to your RAMpack.)
Last edited by mrtinb on Wed Apr 29, 2020 11:20 pm, edited 1 time in total.
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
stroebeljc
Posts: 63
Joined: Thu Apr 23, 2020 6:02 am

Re: Hidden BASIC lines at end of program space

Post by stroebeljc »

mrtinb wrote: Wed Apr 29, 2020 10:19 pm It is UDG (user defined graphics) emulated with WRX hires graphics (Wilf Rigter graphic).

(WRX requires a hardware modification to your RAMpack.)
One thing that is different is that you are not really hiding basic lines. You just have a huge REM at line 0 and all of your BASIC code comes after. There are no hidden BASIC lines, as in this memory image. The hidden stuff follows the BASIC.
Hidden BASIC.png
John
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Hidden BASIC lines at end of program space

Post by dr beep »

stroebeljc wrote: Wed Apr 29, 2020 11:08 pm
mrtinb wrote: Wed Apr 29, 2020 10:19 pm It is UDG (user defined graphics) emulated with WRX hires graphics (Wilf Rigter graphic).

(WRX requires a hardware modification to your RAMpack.)
One thing that is different is that you are not really hiding basic lines. You just have a huge REM at line 0 and all of your BASIC code comes after. There are no hidden BASIC lines, as in this memory image. The hidden stuff follows the BASIC.

Hidden BASIC.png
True... but same technic. Double 118.
stroebeljc
Posts: 63
Joined: Thu Apr 23, 2020 6:02 am

Re: Hidden BASIC lines at end of program space

Post by stroebeljc »

dr beep wrote: Thu Apr 30, 2020 10:07 pm True... but same technic. Double 118.
I see. You're using the double 118 within a BASIC statement to stop printing any further characters in that statement, versus the method I described which places the double 118 at the end of a statement.

Interesting tricks, indeed.
John
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Hidden BASIC lines at end of program space

Post by dr beep »

I am coding directly in a compiler and compile to .P
My BASIC is always just 1 line, the call to MC only.
My MC is stored in every available address.
I have placed my BASIC line call to MC fully over the sysvar.
My games have autostart. When you would hack the NXTLIN you still don't get a line of BASIC since it is placed over sysvar.
Because I am not using the editor to enter lines I can make such games.
If you want to code the most out of a ZX81 you must not code ON the ZX81 but on other platform and make it only loadable for the ZX81.
Post Reply