Running example code

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
Creator
Member
Posts: 20
Joined: Tue Feb 21, 2023 4:07 am

Running example code

Post by Creator »

For my first attempt at using these tool I try example code clock.c but no luck so far.
Code compiles and generates a.O and a.bin files On loading a.o (renamed zx80_2.o to easily suit my system) I get a blank screen. List results in 0/0 on lower screen and Run just clears the screen & presents another K cursor

Win10 64 bit system
ZX80
16k RAM -- my design -successfully loads & executes .o files generated via ZxToken (a BASIC text to .o file generator). Also tried the minimalist code below with same result

Code: Select all

/*
 *  zcc +zx80 -create-app -llib3d hw.c
  derived from  $Id: clock.c,v 1.1 2013-01-07 14:39:58 stefano Exp $
*/

#include <stdlib.h>
#include <stdio.h>

main()
{
	printf("Hello World.");
}
Example code smallgfx.c loads and presents 22 lines to the screen. 1 randomise usr(16525) 20 lines of Rem statements and 22 stop. At the Run cmd the screen scrambles (probably as expected) and never does anything else.

Same results whether using latest or year old build.

Anything jump out that I'm doing wrong or not understanding ?
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Running example code

Post by dom »

It's been a while since I've tried out the ZX80 target - I'm just using the EightyOne emulator.

examples/console/world.c (so Hello World) works correctly so I'd expect your minimal example to work - can you double check your generated binary using EightyOne?

I'm not having much joy with smallgfx - I end up with a black screen so I'll need to look into that.
Creator
Member
Posts: 20
Joined: Tue Feb 21, 2023 4:07 am

Re: Running example code

Post by Creator »

OK. I've downloaded and extracted EightyOne but am getting error popups (EAAccess Violation) when I click on eightyOne.exe / Run. Does that run standalone on a Win10 machine ?
Creator
Member
Posts: 20
Joined: Tue Feb 21, 2023 4:07 am

Re: Running example code

Post by Creator »

Error popups occur at 'initializing Midi'
Creator
Member
Posts: 20
Joined: Tue Feb 21, 2023 4:07 am

Re: Running example code

Post by Creator »

Downloaded & extracted a fresh copy of eightyone v1.31. Same issue. I have a ver 1.0a of eightyone that does run. Will that work for this test ?
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: Running example code

Post by Timmy »

So I just dig out an older version of EightyOne and tried out something.

I've tried several things, and this following program worked for me. The .O file worked in EightyOne.

Code: Select all

/*
* zcc +zx80 -create-app zx80-1.c -o zx80-1.bin -lm
*/

#include <graphics.h>
#include <stdio.h>

main()
{
printf("Hello World.");
fgetc_cons();
}


(also don't forget to put an extra new line at the end of your code, just in case.)

I don't know why this one works, compared to your code above. I'm not an ZX80 developer at all.

Also, I will be back to bed now. :)
Creator
Member
Posts: 20
Joined: Tue Feb 21, 2023 4:07 am

Re: Running example code

Post by Creator »

Did clock & smallgfx not work ?
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: Running example code

Post by Timmy »

Creator wrote: Fri Feb 24, 2023 2:36 am Did clock & smallgfx not work ?
They work both over here, obviously. But if my code above did not work for you, as well as the clock and smallgfx, then you might have some other problem at your side.

For example, did you set up your emulator to be an ZX80 emulator?
Creator
Member
Posts: 20
Joined: Tue Feb 21, 2023 4:07 am

Re: Running example code

Post by Creator »

I'm not getting anything to load. Real dumb guy question & I've delayed asking cause I know it's really dumb. Eightyone starts out with the keyboard image then after it initializes presents a CRT like image with a K cursor. Do I start a load (W key) from there ? The file dropdown has an 'open tape' option that presents files in a folder. Do I start a load from there ? I've tries several combination using these with nothing loading. How to I load an .o file ?
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: Running example code

Post by Timmy »

1) Look at the bottom left corner of the emulator.
2) Press F6
3) Change it into 80, 16K
4) Verify bottom left corner that it says 80 and 16K
5) Drag the O file into the emulator
6) You should see some code on screen
7) RUN

Do let us know if this worked, or where you get stuck.
Creator
Member
Posts: 20
Joined: Tue Feb 21, 2023 4:07 am

Re: Running example code

Post by Creator »

16k Zx80 Yes. Drag & Drop .o file No I drag .o file & get an up arrow with a + sign but no text appears. 0/0 on lower display lines. No run no list. I'm running EightyOne ver 1.0A cause the latest and one year old versions would not properly load.
Creator
Member
Posts: 20
Joined: Tue Feb 21, 2023 4:07 am

Re: Running example code

Post by Creator »

I have no grid power here and I'm rationing my generator fuel cause there are hundreds of thousands without power here (SE Michigan) and fuel is also a problem so It may appear I disappeared but I'll be back
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: Running example code

Post by Timmy »

Take care of yourself first and then you can come back later.

If you have problems with installing EightyOne you could try a ZX80/ZX81 forum like sinclairzxworld. They will be able to help you out with EightyOne there.

Or, now that we know that the .O files work (at least, at my end) and that your real zx80 can load .O files, you could just try loading them directly.
Creator
Member
Posts: 20
Joined: Tue Feb 21, 2023 4:07 am

Re: Running example code

Post by Creator »

Well, I am not able to load & run .o file generated by z88dk.
Creator
Member
Posts: 20
Joined: Tue Feb 21, 2023 4:07 am

Re: Running example code

Post by Creator »

OK now I can run some example programs (clock and smallgfx) but not world.c. Even stripped down to just a single line in main()

#include <stdio.h>

main()
{
printf("Hello World.");
}

It runs but no text to the screen unless I print it several times (6) and then it appears on the lower screen.
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: Running example code

Post by Timmy »

I'm surprised, as the simple program I posted earlier in the thread is basically comprised of three lines from smallgfx.c (fgetc_cons + #includes) and one line from clock.c (printf).

Are you sure you got those two programs working? How do they look like on your screen? And is that on the emulator or on your own machine?
Creator
Member
Posts: 20
Joined: Tue Feb 21, 2023 4:07 am

Re: Running example code

Post by Creator »

Yea, I'm surprised too. Running on my machine clock asks for hour & minutes then presents a crude full screen clock that keeps time, smallgfx displays a crude graphic full screen.

Nothing but trouble with eightyone. Ver 1.13 won't complete its initialization and run, it gets several popups at 'Initializing Midi' starting with EAAccess violation then crashes out. Removing eightyone.ini or disabling MidiDev inside there is no help.
Eightyone ver 1.0a is just flakey, yesterday I was able to get it to successfully load world.c, clock.c and smallgfx.c but going back later no loads where possible. I've looked and asked for a manual / instructions on using EightyOne to no avail. It's use may be obvious to those who grew up with it but many options are not intuitive and may explain with I'm having trouble it.
Creator
Member
Posts: 20
Joined: Tue Feb 21, 2023 4:07 am

Re: Running example code

Post by Creator »

Maybe there's something I'm doing in the process of compiling / moving the .o around for use. I'll go off and chase that.
Creator
Member
Posts: 20
Joined: Tue Feb 21, 2023 4:07 am

Re: Running example code

Post by Creator »

Problem has to do with the way ZX80 does prints to the screen. Can't just have a print statement.

This works
#include <stdio.h>
main()
{
printf("\nhello world: ");
gets(aaa);
}
Creator
Member
Posts: 20
Joined: Tue Feb 21, 2023 4:07 am

Re: Running example code

Post by Creator »

Well, if char aaa[5];
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: Running example code

Post by Timmy »

Yes, that's kind of important. When a program is finished in C, the program will **try** to return to BASIC. And then crashes.

If you want to do return to BASIC safely, you might need to set up things so that you can return to BASIC safely. Otherwise it will crash. No, I don't know how to return to BASIC safely, but perhaps someone else knows.

Default C programs doesn't do that. Because most programs are games anyway, so we don't need to set up things to return to ROM, and save some bytes.

For simple programs, a function like fgetc_cons() or gets() is enough. Perhaps the zx80 needs a vertical retrace to draw things on screen, and you need to wait for that.

And I'm glad you got it working on your real machine.
salvacam
New member
Posts: 2
Joined: Thu Apr 27, 2023 8:33 pm

Re: Running example code

Post by salvacam »

A couple of years ago I made a small program for ZX80, here is the code in case it can help you
https://salvacam.gitlab.io/asset/ticTacToeHell.c
Using this command to compile

Code: Select all

z88dk/bin/zcc +zx80 -Dzx80 -lm -create-app ${x}.c -o ${x}.o 
replace ${0} with the name of the file
salvacam
New member
Posts: 2
Joined: Thu Apr 27, 2023 8:33 pm

Re: Running example code

Post by salvacam »

Or this command

Code: Select all

z88dk/bin/zcc +zx80 -lm -create-app -Cz--collapsed ${x}.c -o ${x}.o
Post Reply