Basic over Sysvar

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
Post Reply
Brimbard
Posts: 10
Joined: Wed Dec 01, 2021 8:12 pm

Basic over Sysvar

Post by Brimbard »

Hello,

while looking into the thread viewtopic.php?p=41302#p41302 I was wondering how the initial start part works.

After some hours of puzzling I can see now some basic code within certain sysvars.
Some other sysvars get automatically set by the load procedure and a few are finally set by a machine code program.
This MC program is located as fractions in the sysvars as well and will partially overwrite the Basic line which started it.

abstracting from the actual locations and unconditional jumps the program logic could be described as:

Code: Select all

9793 GOTO USR 16393

basic:  ld h,dfile_h            ; highbyte of dfile
        ld l,dfile_l
oldpcc: ld (D_FILE),hl          ; self overwriting
strlen: ld h,vars_h
t_addr: ld c,h                  ; $4C follows $3B which is the code for RUN
        inc c                   ; $0C40 it's address, just ignore
seed:   ld l,vars_l
frames: ld (hl),$E9             ; frames will decrease the provided opcode
                                ; this will load 'jp(hl)' into vars
coords: jp gamecode
That does not look too bad.

But considering: Line number 9793 is already the 'ld h,dfile_h'. :o
The Basic line calls a machine code starting with it's own line number!

And :shock: Boy, I can hardly believe the code at 't_addr' and 'frames' which the debugger showed me.
In the comments is the explanation I came up with.

Please let me know if you have different ideas or if I may have missed something.
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Basic over Sysvar

Post by dr beep »

You forget that bit 6 of frames highbyte must be kept set to work as well.

This code corrupts dfile that is why it is repaired and e9 in last is to compress the compressed screen when your screen has only linefeeds. This opcode after last line in use can save many linefeedds.
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Basic over Sysvar

Post by dr beep »

My model for 1K hires does even more over sysvar. It also makes a copy in 48K range of the code to make the game work with more than 16K RAM.
Brimbard
Posts: 10
Joined: Wed Dec 01, 2021 8:12 pm

Re: Basic over Sysvar

Post by Brimbard »

Thanks for confirming and also pointing out Bit 6.
Just that I think I need to dive deeper in the display routines (and their relation to the hardware) to fully comprehend.
But I will use this going forward as is definitely works as you described. :)

In the game code example we started after cdflags which would be still within sysvars.
Are you saying you manage the copy routine even before cdflags?
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Basic over Sysvar

Post by dr beep »

After loading a large part of sysvar can be reused. I often place routines on the screen or even on the stack before it is used by the program and copy those over sysvar. Then I allow the program to use the screen for the game.

example:
I code a simplified random function that also uses frames in the randomness.
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Basic over Sysvar

Post by dr beep »

Display doesn't use much sysvar, BASIC does so once out of BASIC you can use sysvar for ie your variable pointers. First 12 from 4000 are always useable.
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Basic over Sysvar

Post by dr beep »

Explanation of the routine and reuse of the sysvar with new routines that are stored temporary on the screen.

https://www.youtube.com/watch?v=piMV3asz-8Y
Brimbard
Posts: 10
Joined: Wed Dec 01, 2021 8:12 pm

Re: Basic over Sysvar

Post by Brimbard »

thanks, I know understand how and why you "place place routines on the screen or even on the stack". :)
Post Reply