Setting up an eprom with coral basic interpreter

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
User avatar
Paul
Posts: 1517
Joined: Thu May 27, 2010 8:15 am
Location: Germanys west end

Re: Setting up an eprom with coral basic interpreter

Post by Paul »

mrtinb wrote: Thu Nov 10, 2022 9:29 pm I'm a COBOL developer by profession. It's not as bad as people make it.
I also used COBOL as main language for several years.
It's not bad at all.
I have no objection against it.
It's just a lot to type to get something done.
That's all.
In theory, there is no difference between theory and practice. But, in practice, there is.
User avatar
xubuntu
Posts: 84
Joined: Sat Jun 18, 2022 12:42 pm
Location: Athens, GR

Re: Setting up an eprom with coral basic interpreter

Post by xubuntu »

Ok so...

You can call me old-fashioned or conservative, but I want my fillet bloody, my girlfriend skinny, my basic without shortcuts and my background black.

In order to get the inverted mode (black background) on the VLA81 we need to move the 2 down switches and then push the value 3 into port 231.

In assembly:

Code: Select all

LD A,3
OUT (231),A
RET
Machine code:

Code: Select all

3E 03 D3 E7 C9
In basic:

Code: Select all

10 POKE 16514,62
20 POKE 16515,3
30 POKE 16516,211
40 POKE 16517,231
50 POKE 16518,201
The above basic code is equavalent to 3E 03 D3 E7 C9, with the difference that those instructions are now placed in memory addresses 16514-16518.

Then I guess we need to execute code starting in 16514 so we need "RAND USR 16514" or "PRINT USR 16514"? What's the bloody difference? Will both work?

The C9 instruction, or else the RETURN instruction, will take us back to BASIC prompt using the memory location saved in the stack? I guess?

So what will happen when we put those 5 instructions in our CORAL.ROM ?

I guess we have to place the four instructions 3E 03 D3 E7 but the C9 won't have any use there. In exchange with C9 we need a jump to our coral basic prompt.

So Mr. Mark can tell us where I am wrong, although I assume I ain't.

The magician Mr. Paul is pleased (I mean, we please him) to generate a new CORAL.ROM including the inverted to black background routine, for all of us who DO own a VLA81 and prefer our girlfriend skinny and our background BLACK.

Thank u
Last edited by xubuntu on Mon Nov 21, 2022 11:59 am, edited 2 times in total.
User avatar
mrtinb
Posts: 1910
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: Setting up an eprom with coral basic interpreter

Post by mrtinb »

xubuntu wrote: Mon Nov 21, 2022 11:42 am Then I guess we need to execute code starting in 16514 so we need "RAND USR 16514" or "PRINT USR 16514"? What's the bloody difference? Will both work?
Looking at this from machine code, the same thing happens. That is the USR 16514 part. So here machine code at address 16514 is run, and when routine is exited with RET, the content of the BC register is returned to Basic.

So what is the difference with RAND USR 16514 and PRINT USR 16514? Well first PRINT USR 16514 prints the value of the BC register. And with RAND USR 16514 the value of the BC register is used as input for the RAND function. And as written in the ZX81 Basic Programming manual, the random number generator is updated with the value from the machine code.

So if you want to print the value from the machine code routine, you use PRINT USR 16514, and if you don't care about the value you can give it to the random number generator with RAND USR 16514. You also have the opportunity to save the value into a variable like in LET X=USR 16514.
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
User avatar
xubuntu
Posts: 84
Joined: Sat Jun 18, 2022 12:42 pm
Location: Athens, GR

Re: Setting up an eprom with coral basic interpreter

Post by xubuntu »

Martin I didn't understand a bit of what you just wrote... but thank you anyway !

Is a REM statement needed in our case?
User avatar
mrtinb
Posts: 1910
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: Setting up an eprom with coral basic interpreter

Post by mrtinb »

xubuntu wrote: Mon Nov 21, 2022 12:03 pm Why is a REM needed since we poked directly into specific memory locations ?
The REM statement just reserves some bytes in memory, that can be overwritten by the POKEs. If we don't have the REM statement, our Basic program gets overwritten and corrupted. If you see chapter 27 of the manual Sinclair ZX81 Basic Programming we have these addresses:

Code: Select all

16509 Start of program. It starts with the first line number and takes 2 bytes.
16511 Contains the length of the first line and takes 2 bytes.
16513 Contains the first byte of the Basic program: In this case value 234 which is the keyword REM (see Appendix A)
16514 Is the first byte after the REM statement, and here we have poked in our program.
If we didn't have the REM statement, the pokes would overwrite the content of line 10, and the program would be corrupted.
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
User avatar
xubuntu
Posts: 84
Joined: Sat Jun 18, 2022 12:42 pm
Location: Athens, GR

Re: Setting up an eprom with coral basic interpreter

Post by xubuntu »

I don't understand.
the pokes would overwrite the content of line 10
What means "the pokes would overwrite the content of line 10" ?

Line 10 is a poke. It enters the decimal number 62 into memory location 16514.

What would have happened if I didn't use a rem statement? Which... I don't.

As I understand, the REM statement tells the machine to write code in 16514.

But we did that manually. We poked instructions into the addresses of our choice. And then we tell it to go execute those instructions with the USR command.

So a REM is not needed !
User avatar
1024MAK
Posts: 5118
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: Setting up an eprom with coral basic interpreter

Post by 1024MAK »

First let’s look at what each bit of PRINT USR 16514 does.

PRINT will print on screen nothing, characters or numbers depending on what follows it.

USR is a function. Functions return a value. They may also take a value. In the case of USR, the value that the function needs to be given is the address in memory where you want the machine to start executing machine code.

If/when the Z80 executes a RET (or any of the other variations), a return to BASIC occurs, which includes finishing the rest of the USR function. As I said, a function returns a value. In the case of USR, the value that is returned happens to be the value in one of the Z80 registers. The value may or may not be meaningful, it depends on what the machine code does. With the short machine code program that you listed above, the value returned is not meaningful. Hence the actual value returned is irrelevant.

Hence when the PRINT instruction sees the value returned by the USR function, it prints the value. The value returned is a number, hence PRINT will print this number.

Next, RAND USR 16514

RAND is short for randomise. ZX81 BASIC can generate pseudo random numbers. RAND is part of this system. It sets the “seed” for the random number generator. We don’t actually care about this here. We are simply using RAND as a BASIC statement to use up the returned value from USR that we don’t actually care about.

Hence RAND USR 16514 calls the machine code routine at 16514, and then stores the returned value somewhere. We don’t care what the value is, or where it goes. But it has to go somewhere to keep BASIC happy.

What USR stands for, well, that’s lost in the mists of time…

Machine code has to live somewhere. A REM gives it a nice safe home. A home where it won’t be written over, or where it won’t interfere with anything else.

It’s a bit like reserving a hotel room. You don’t want to go to bed, only to find someone else that you don’t know jumping in on top of you!

You don’t have to use a REM to reserve space if you put the machine code somewhere else where it will not be written over by BASIC and where it will not interfere with BASIC.

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
User avatar
xubuntu
Posts: 84
Joined: Sat Jun 18, 2022 12:42 pm
Location: Athens, GR

Re: Setting up an eprom with coral basic interpreter

Post by xubuntu »

Could you talk to me like a programmer and not like a kid ?

We are in BASIC prompt. And WE ARE in a safe location. The PC is set to that safe location. Let's say for the shake of our example that this safe location is 20000.

So we are in basic prompt typing commands and we type:

PRINT USR 25000
RET

Address 20000 will be saved in the stack.
The program will jump to 25000.
It will then return to 20000 with the RET command.

There is no need for a REM.

Unless we WEREN'T in a safe place, which is impossible since we had BASIC prompt in front of us.

Where am I wrong?

why is
Hence the actual value returned is irrelevant.
??

Why is the returned value irrelevant ? It's the value that we were before the jump, it's not irrelevant.

Code: Select all

Machine code has to live somewhere. 
No it won't just live "somewhere". It will live in 16514 where we put it! I am not using an assembled p file here, I am using BASIC commands and it pretty well knows that this "somewhere" is 16514..
User avatar
mrtinb
Posts: 1910
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: Setting up an eprom with coral basic interpreter

Post by mrtinb »

It is difficult to give you a whole course on how to program the ZX81. It has many quirks.

I would advise you to read chapter 25-28 and appendix A in the manual:

https://worldofspectrum.net/ZX81BasicProgramming/

And also read the best book on machine language for the ZX81: Mastering Machine Code on Your ZX81:

http://www.users.waitrose.com/~thunor/m ... index.html
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
User avatar
Paul
Posts: 1517
Joined: Thu May 27, 2010 8:15 am
Location: Germanys west end

Re: Setting up an eprom with coral basic interpreter

Post by Paul »

xubuntu wrote: Mon Nov 21, 2022 12:39 pm I don't understand.
So a REM is not needed !
That's right.
MC up to 32bytes fit into the printer buffer.
In theory, there is no difference between theory and practice. But, in practice, there is.
Post Reply