Newbie in need of help!

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
User avatar
RobertK
Well known member
Posts: 347
Joined: Mon Feb 26, 2018 12:58 pm

Post by RobertK »

One more question about the VT100 Console I/O gotoxy() function: is this supposed to work as well with the VG5000 and VZ200 graphics modes?

If not, then we can live with that.

If so, then let me tell you that it currently does not work (while in standard text mode it does).

Here is a little test program.

Code: Select all

/*
z88dk VT100 Console I/O ANSI driver gotoxy() test
Only for targets that support VT100 console emulation, 
see https://www.z88dk.org/wiki/doku.php?id=targets
Author: RobertK, 2018-04-07

Compile commands:

=== ZX81 (requires WRX hires-graphics) ===
zcc +zx81 gotoxytest.c -o gotoxytest -create-app -lndos -subtype=_wrx64 -clib=wrxansi -pragma-define:ansicolumns=64

=== Jupiter Ace ===
zcc +ace -lgfxace -clib=ansi -vn -create-app gotoxytest.c -o gt.bin
load the program in the Jupiter Ace by typing:
0 0 bload gt.bin

=== Mattel Aquarius ===
zcc +aquarius -clib=ansi -lgfxaq48 -lm -create-app gotoxytest.c -o gotoxytest_aquarius

=== Sharp MZ-700 ===
zcc +mz -clib=ansi -lm -create-app gotoxytest.c -o gotoxytest_sharpmz

=== Robotron Z1013 ===
zcc +z1013 -clib=ansi -lm -create-app gotoxytest.c -o gotoxytest_z1013
   
=== VZ200 / Laser 210 / Laser 110 ===
zcc +vz -lm -clib=ansi -o gotoxytest_vz200_text.vz gotoxytest.c
(text mode)
or
zcc +vz -lm -pragma-redirect=fputc_cons=putc4x6 -o gotoxytest_vz200_graphics.vz gotoxytest.c 
(graphics mode) *
uncomment the clg() call below before compiling the graphics version
Note: it seems that it is not possible to combine graphics mode and ansi VT emulation

=== Philips VG5000 === 
zcc +vg5k -create-app -lm gotoxytest.c -o gotoxytest_vg5000_text
(text mode)
or
zcc +vg5k -create-app -clib=graphics -lm gotoxytest.c -o gotoxytest_vg5000_graphics
(graphics mode) *
uncomment the clg() call below before compiling the graphics version
(Note: ansi VT emulation is implicit for that system, so the -clib=ansi parameter is not required)

*/

#include <stdio.h>
#include <conio.h>        // VT100 Console I/O ANSI driver

void main()
{

        #if defined(__VZ200__) || defined(__VG5000__)
          // clg();  // activate graphics mode
        #endif

        printf("%c",12); // clear the screen  

        gotoxy(2,2);
        cprintf("abc");
        
        gotoxy(3,3);
        cprintf("def");

        gotoxy(4,4);
        printf("ijk");
        
        gotoxy(5,5);
        printf("press any key\n");        
                
        getch();
        printf("%c",12); // clear the screen  
        
}
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

not at the moment, you can set the text position by setting x_4x6 and y_4x6, they are declared in graphics.h and are pixel-wide granular
User avatar
RobertK
Well known member
Posts: 347
Joined: Mon Feb 26, 2018 12:58 pm

Post by RobertK »

I would now like to use some math functions:

Code: Select all

#include <stdio.h>
#include <math.h>

int main()
{
        float f;
        f=sin(3);
        
        printf("%c",12); // clear the screen
        printf("sin(3) is %f",f);
        while(!kbhit());
        return 0;
}
But I get these compile errors:

Code: Select all

Error at file 'mathtest.c' line 29: symbol 'float' not defined
Error at file 'mathtest.c' line 31: symbol 'sin' not defined
Error at file '/home/build/z88dk/build/z88dk/libsrc/_DEVELOPMENT/stdlib/z80/__dtoa__.asm' line 48: symbol 'asm_fpclassify' not defined
Error at file '/home/build/z88dk/build/z88dk/libsrc/_DEVELOPMENT/stdlib/z80/__dtoa__.asm' line 73: symbol '__dtoa_base10' not defined
Error at file '/home/build/z88dk/build/z88dk/libsrc/_DEVELOPMENT/stdlib/z80/__dtoa__.asm' line 106: symbol '__dtoa_digits' not defined
Error at file '/home/build/z88dk/build/z88dk/libsrc/_DEVELOPMENT/stdlib/z80/__dtoa__.asm' line 140: symbol '__dtoa_digits' not defined
Error at file '/home/build/z88dk/build/z88dk/libsrc/_DEVELOPMENT/stdlib/z80/__dtoa_preamble.asm' line 54: symbol '__dtoa_sgnabs' not defined
Error at file '/home/build/z88dk/build/z88dk/libsrc/_DEVELOPMENT/stdlib/z80/__dtoa_print.asm' line 34: symbol '__stdio_printf_sign_0' not defined
Error at file '/home/build/z88dk/build/z88dk/libsrc/_DEVELOPMENT/stdlib/z80/__dtoe__.asm' line 47: symbol 'asm_fpclassify' not defined
Error at file '/home/build/z88dk/build/z88dk/libsrc/_DEVELOPMENT/stdlib/z80/__dtoe__.asm' line 72: symbol '__dtoa_base10' not defined
Error at file '/home/build/z88dk/build/z88dk/libsrc/_DEVELOPMENT/stdlib/z80/__dtoe__.asm' line 97: symbol '__dtoa_digits' not defined
Error at file '/home/build/z88dk/build/z88dk/libsrc/_DEVELOPMENT/stdlib/z80/__dtoe__.asm' line 105: symbol '__dtoa_digits' not defined
Error at file 'crt0_fp/fa.asm' line 12: symbol 'init_floatpack' not defined
13 errors occurred during assembly
Errors in source file C:\Misc\z88dk\lib\config\\..\..\\lib\target\zx81\classic\zx81_crt0.asm:
Error at file 'mathtest.c' line 29: symbol 'float' not defined
                   ^ ----
Error at file 'mathtest.c' line 31: symbol 'sin' not defined
                   ^ ---- 1 errors occurred during assembly
Error at file '/home/build/z88dk/build/z88dk/libsrc/_DEVELOPMENT/stdlib/z80/__dtoa__.asm' line 48: symbol 'asm_fpclassify' not defined
Error at file '/home/build/z88dk/build/z88dk/libsrc/_DEVELOPMENT/stdlib/z80/__dtoa__.asm' line 73: symbol '__dtoa_base10' not defined
Error at file '/home/build/z88dk/build/z88dk/libsrc/_DEVELOPMENT/stdlib/z80/__dtoa__.asm' line 106: symbol '__dtoa_digits' not defined
Error at file '/home/build/z88dk/build/z88dk/libsrc/_DEVELOPMENT/stdlib/z80/__dtoa__.asm' line 140: symbol '__dtoa_digits' not defined
Error at file '/home/build/z88dk/build/z88dk/libsrc/_DEVELOPMENT/stdlib/z80/__dtoa_preamble.asm' line 54: symbol '__dtoa_sgnabs' not defined
Error at file '/home/build/z88dk/build/z88dk/libsrc/_DEVELOPMENT/stdlib/z80/__dtoa_print.asm' line 34: symbol '__stdio_printf_sign_0' not defined
Error at file '/home/build/z88dk/build/z88dk/libsrc/_DEVELOPMENT/stdlib/z80/__dtoe__.asm' line 47: symbol 'asm_fpclassify' not defined
Error at file '/home/build/z88dk/build/z88dk/libsrc/_DEVELOPMENT/stdlib/z80/__dtoe__.asm' line 72: symbol '__dtoa_base10' not defined
Error at file '/home/build/z88dk/build/z88dk/libsrc/_DEVELOPMENT/stdlib/z80/__dtoe__.asm' line 97: symbol '__dtoa_digits' not defined
Error at file '/home/build/z88dk/build/z88dk/libsrc/_DEVELOPMENT/stdlib/z80/__dtoe__.asm' line 105: symbol '__dtoa_digits' not defined
Error at file 'crt0_fp/fa.asm' line 12: symbol 'init_floatpack' not defined
When I try to only assign a value to a float variable (with math.h included), I get the following compilation error:

Code: Select all

Error at file 'crt0_fp/fa.asm' line 12: symbol 'init_floatpack' not defined
1 errors occurred during assembly
Errors in source file C:\Misc\z88dk\lib\config\\..\..\\lib\target\zx81\classic\zx81_crt0.asm:
Error at file 'crt0_fp/fa.asm' line 12: symbol 'init_floatpack' not defined
Obviously something is missing, but what?

Math.h includes float.h, so this one should already be there.
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

There is more than one float library so you have to specify which one you're using by linking to it on the command line. "-lm" will get the default choice.
For the zx81 in classic, I think "-lm" uses the rom float package (in which case the program will be smaller) or else it will be genmath.
User avatar
RobertK
Well known member
Posts: 347
Joined: Mon Feb 26, 2018 12:58 pm

Post by RobertK »

With the -lm compile parameter added it works now, thanks.
I even had that parameter in some of my compile batch files for my H-Tron game, without knowing what it was for. I will better remove it because my game does not require any float variables.
User avatar
RobertK
Well known member
Posts: 347
Joined: Mon Feb 26, 2018 12:58 pm

Post by RobertK »

I have been using z88dk for almost a year now, but I still haven't found out how to use a makefile. I have always compiled my programs using a batch file that sets the path and required variables and then calls zcc with appropriate parameters.

Now I would like to build the Pac-Man hardware sample: Use the Makefile provided in the {z88dk}/examples/pacman folder.

What exactly needs to be done to compile the program using that makefile?
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

There's some instructions on how to compile the classic libraries on windows here: https://github.com/z88dk/z88dk/wiki/libsrc

If you follow those upto step 12 then you'll have a shell where you can cd into the pacman example directory and just type make and a ROM file will be generated.
User avatar
RobertK
Well known member
Posts: 347
Joined: Mon Feb 26, 2018 12:58 pm

Post by RobertK »

Hmm, I followed the instructions (not sure if 11. and 12. need to done every time I restart git-bash), but Make gives me a "the system cannot find the file specified" error.
Image
(the error message is in German because my Windows is set to that language)

I'm using Windows 10, UAC is disabled as far as possible (you can no longer turn it off entirely under Windows 10).

I also noticed that running git-bash.exe as an Administrator makes no difference than double-clicking it, I always see my user name at the git-bash prompt, and the make error is the same.
User avatar
RobertK
Well known member
Posts: 347
Joined: Mon Feb 26, 2018 12:58 pm

Post by RobertK »

The git-bash problem has been solved now thanks to Dom's help. You need to make sure that z88dk is in your path so that you can run "zcc" from any directory within the git-bash console - before that does not work, make won't work either.

Another simple question (entirely different topic): we have the getmaxx() and getmaxy() functions to determine the graphics screen dimensions. But is it also possible to programatically determine the *text* screen dimensions?

That would of course be helpful for cross-developement.

I had a look at Fabrizio's Cross Chase source and I saw that he's also defining the screen size for each target manually (in display_target_settings.h).
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

screensize() in conio.h should do what you want.
User avatar
RobertK
Well known member
Posts: 347
Joined: Mon Feb 26, 2018 12:58 pm

Post by RobertK »

Two simple questions about memory limitations:

1. The simplest Hello World program compiled for the ZX81 results in a 4K .p file. This makes it impossible to write anything for the unexpanded 1K ZX81. Is there maybe some option to create a size-optimized binary?
I remember that Turbo C for DOS had an "Optimize for Speed or Size" option, maybe there is something similar in z88dk?

2. When compiling for a 16K RAM WRX graphics ZX81, what is the maximum size that the .p file may have? I have noticed that smaller WRX-compiled programs work, but a 9K .p file does not - probably because WRX uses a great part of the available RAM for screen memory?
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

Some experiments:

The following is 2567 bytes:

Code: Select all

#include <stdio.h>

#pragma define CLIB_EXIT_STACK_SIZE=0

int main() {
        printf("Hello world\n");
}
The following is 1256 bytes:

Code: Select all

#include <stdio.h>

#pragma printf ""
#pragma define CLIB_EXIT_STACK_SIZE=0

int main() {
        printf("Hello world\n");
}
The following is 851 bytes:

Code: Select all

#include <stdio.h>

#pragma printf ""
#pragma define CRT_ENABLE_STDIO=0
#pragma define CLIB_EXIT_STACK_SIZE=0

int main() {
        printk("Hello world\n");
}
The following is 659 bytes:

Code: Select all

#include <stdio.h>

#pragma define CRT_ENABLE_STDIO=0
#pragma define CLIB_EXIT_STACK_SIZE=0

int main() {
        puts_cons("Hello world\n");
}
Finally this is 317 bytes:

Code: Select all

#include <stdio.h>

// Compile with -pragma-redirect:fputc_cons=myputc

#pragma define CRT_ENABLE_STDIO=0
#pragma define CLIB_EXIT_STACK_SIZE=0

int main() {
        puts_cons("Hello world\n");
}

int dummy() __naked
{
#asm
        PUBLIC myputc
        PUBLIC  _myputc
myputc:
_myputc:
        ld      a,l
        rst     16
        ret
#endasm
}
User avatar
RobertK
Well known member
Posts: 347
Joined: Mon Feb 26, 2018 12:58 pm

Post by RobertK »

Ok, I tried you first trick, but i must be doing something wrong.

This is 3597 bytes, both with and without the stack size line:

Code: Select all

// Compile with
// zcc +zx81 -startup=2 -o hello_ZX81 -create-app hello.c

#pragma define CLIB_EXIT_STACK_SIZE=0

void main()
{ 
  printf("\nhello\n");
  fgetc_cons();        // wait for keypress          
}
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

The main contributor will be the printf formatters, I start off at 3592 for the .P file (I've obviously got slightly older libs)

Adding #pragma printf "" (which is needed in this case because there are no explicit formatters used), gets us to 2281

Switching to printk() gets to 2143.

Disabling std* streams (#pragma define CRT_ENABLE_STDIO=0) gets to 1876

The .P file includes a full expanded display so there's 768 bytes blow straight away.
User avatar
RobertK
Well known member
Posts: 347
Joined: Mon Feb 26, 2018 12:58 pm

Post by RobertK »

Ok, so you measured the size of the extension-less file that z88dk creates, rather than the .p file.

But how can I run this file in the EightyOne emulator? Probably with "Load Memory block", but to what address?

The .p file won't run with only 1K RAM because of the extra 768 bytes you mentioned.

BTW, your last sample displays "JKLMNOPQRSTUV" in inverse instead of "Hello world", any idea why? I compiled it like this:

zcc +zx81 -startup=2 -pragma-redirect:fputc_cons=myputc -o hellosmall_ZX81 -create-app hellosmall.c
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

-Cz?collapses will create the .P file with a collapsed display - so 24 bytes rather than 768.

The last example doesn?t do the conversion from ascii to the zc81 character set - the conversion code takes up memory so it?s probably best not to do it on a 1k model.

There?s probably some more savings to be made in the crt file so if you?re still short a bit of pruning can be done.
User avatar
RobertK
Well known member
Posts: 347
Joined: Mon Feb 26, 2018 12:58 pm

Post by RobertK »

It should be -Cz--collapsed (as I found out by trial and error).

With that, the fourth sample .p file fits into 1K RAM, but gives an out-of-sync broken screen. Probably some more tricks are required to display something on the screen.

But it seems that this is NOT a newbie topic. Maybe you can elaborate on that one day, describing the side-effects of each trick and how to overcome them.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

the collapsed display has the only effect of reducing the binary size at rest. After having been loaded (saving a bit of time), the display will be restored at its original size, unless you have only 1k. It is not absolutely a beginner 's task to compile a program for 1 or 2 k of memory
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

RobertK wrote:It should be -Cz--collapsed (as I found out by trial and error).
Sorry - I think that was either an autocorrect mistake due to my thumb hitting the wrong virtual key. Glad you found it in the end though. Running appmake +zx81 (or your chosen port) will show all the valid options available.
Post Reply