First steps into Z88DK...and many more to come!

Discuss game and other programming topics not specifically covered in another forum

Moderator: Programming Moderators

Alcoholics Anonymous
Posts: 495
Joined: Mon May 29, 2017 7:00 pm

Re: First steps into Z88DK...and many more to come!

Post by Alcoholics Anonymous » Sun Apr 29, 2018 5:14 pm

Mucking around in the "Toolchain Executables" in the Global Compiler settings, I have the current program files linked...

Code: Select all

Code: Select all

C Compiler:  zcc.exe
C++ Compiler: zcc.exe
Linker for dynamic Libs: z88dk-lib.exe
Linker for static libs: z88dk-lib.exe
Debugger: GDB/CDB debugger: default
Resouce compiler: windres.exe
Make program: appmake.exe
I don't use codeblocks but is it possible to leave some of these fields empty?

Code: Select all

C Compiler:  zcc.exe
C++ Compiler: 
Linker for dynamic Libs: 
Linker for static libs: zcc.exe
Debugger: 
Resouce compiler: 
Make program: make.exe
The "Make program" is usually "make" which reads the Makefile to figure out what needs to be done. This is not something available in Windows and must be installed separately.

There's no C++ but I suppose it won't hurt to have "zcc.exe" in there like you had.

There's no dynamic libraries and I'm not sure what codeblocks does with that, other than maybe it uses a different link line to form a dynamically linked binary rather than a statically linked one. It probably woudn't hurt to put "zcc.exe." there if you had to. This linker option I think is responsible for forming the executable from the object files.

What you want it to do is after the object files are formed, you want it to call zcc again to link them all together. This will be the familiar compile line used for *.c files but instead you would use the *.o object files instead.

So you want codeblocks to make the object files with something like this for each *.c:

Code: Select all

zcc +zx -vn -clib=sdcc_iy  -c "D:\ZXSpectrum projects\DevProjects\zeedk\main.c"
// Here optimization level matters because this is where the .c gets translated to .asm.
// Things to do with generating the output binary do not matter because an output binary is not being made. This would be things like startup, subtype, create-app
// In more advanced applications, this is also where you would tell the c compiler which memory banks to put code/data into.

And then you want to put it together with one final invoke of zcc that does the linking of all object files:

Code: Select all

zcc +zx -vn -clib=sdcc_iy -startup=31 "D:\ZXSpectrum projects\DevProjects\zeedk\main.o" -pragma-include:zpragma.inc -subtype=sna -Cz"--clean" -create-app
// Here things to do with generating the binary are needed: things like startup, subtype, create-app, pragmas
// Only object files should be listed here. You can put asm files here too, in which case zcc will assemble all in this statement. This is ok because assembling is very fast so it's no problem to assemble everything all the time. However, you can also stick to the Makefile framework and assemble .asm files to object files like you did with the .c. Then this line would only list the *.o files. If you do this, make sure the *.asm and *.c files have different basenames. Eg do not name one file "foo.asm" and another "foo.c" because the object file name for both will be "foo.o".

The "pragma-include" is optional and will read project pragmas from a central file.
The "subtype" and "create-app" together will decide what form the output will take: tap, bin, sna, etc. The "clean" option sent to appmake will do some cleanup after creating the sna, as produced in this example.
"startup" chooses a crt and in this case it's one without any stdio,stdin,stdout for programs that don't use stdio for text input/output.


The one great advantage that Makefiles have is the incremental compilation. This matters when it takes a long time to compile files and that is the case with zsdcc used as c compiler with optimization turned up. Otherwise, I would skip Makefiles and just supply a project file to zcc:

Code: Select all

zcc +zx -vn -clib=sdcc_iy -startup=31 @zproject.lst -pragma-include:zpragma.inc -subtype=sna -Cz"--clean" -create-app
with the file "zproject.lst" listing all the files in your project. zcc will read that list and compile/assemble/whatever all files into the output binary.

zproject.lst

Code: Select all

; comment
main.c
more/this.asm
yo.asm.m4
what.c
But as this compiles everything from scratch, it can potentially take a long time when zsdcc is involved.

I would still recommend distributing a project file with open source projects even if you use a Makefile for development. The reason is, this will allow someone to grab your source, enter one line and compile the whole works into the output binary. It also avoids issues with windows because most windows users will not have "make" available but they will be able to use zcc this way to build the output.
Last edited by Alcoholics Anonymous on Sun Apr 29, 2018 5:38 pm, edited 1 time in total.

Alcoholics Anonymous
Posts: 495
Joined: Mon May 29, 2017 7:00 pm

Re: First steps into Z88DK...and many more to come!

Post by Alcoholics Anonymous » Sun Apr 29, 2018 5:36 pm

SamusDrake wrote:
Sat Apr 28, 2018 9:36 am
Which brings me to the last thought of the day - how much hassle would it be to put a program onto a chip'n'pcb and pop it into a real Mastersystem! Or getting a suitable FPGA board - low cost of course - and setting it up as a Master System...hmmm.
It shouldn't be hard at all but I've seen people mainly butcher old carts instead of making new ones. The other alternative is the Everdrive (I think - I only read about these things in passing) which can hold a lot of games, including ones you dev.

Master System... it would be nice to see an option for this core on the Next :)

User avatar
SevenFFF
Posts: 209
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Re: First steps into Z88DK...and many more to come!

Post by SevenFFF » Sun Apr 29, 2018 5:46 pm

I have a GameBoy/Color EverDrive, they're rather good. A little expensive compared with the price of used hardware, but well worth it.

I only got it to dev with, but as a side benefit you can fit every game there ever was on there, as well.

Sadly they take microSD cards not fullsize SD, but you can get adaptors that go the other way, so FlashAir wifi cards would still be an option.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel Spectron 2084blog

SamusDrake
Posts: 250
Joined: Mon Jun 26, 2017 10:11 pm
Contact:

Re: First steps into Z88DK...and many more to come!

Post by SamusDrake » Mon Apr 30, 2018 8:49 am

Having spent more time with Codeblocks, I think the problem maybe the Make program I'm providing. I've noticed when setting up SGDK you use the Make program provided with that SDK, but as I couldnt locate one for Z88DK, I tried others - MingGW being one of them. Also in the project settings I've provided the Makefile whereas before I didnt provide the path for the full filename. Bit of a loss as to what to explore next for this issue, but I've at least become more familiar with CodeBlocks - even found I could set up environment variables instead of having to do it for windows itself, if I only needed to compile from Codeblocks...which is nice.

Also beavering away at the Master System stuff, which seems simple enough. I think the only thing that poses a challenge would be creating palettes and bitmap data for the VDP's vram, but I'm at least confident on that front and see it as only hard graft. Only regret about the SMS is the joypad only having a D-pad and two buttons - as that limits the gameplay possibilities. I have thought about an Everdrive, but their availability seems to be limited - which is a shame...

User avatar
SevenFFF
Posts: 209
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Re: First steps into Z88DK...and many more to come!

Post by SevenFFF » Mon Apr 30, 2018 2:00 pm

SamusDrake wrote:
Mon Apr 30, 2018 8:49 am
I have thought about an Everdrive, but their availability seems to be limited - which is a shame...
Yes, I think they're quite a small operation. I ordered from somebody who claimed to have them in stock, but it still took ages to ship, and came from Ukraine. I suspected it was made to order and drop-shipped from the manufacturer.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel Spectron 2084blog

SamusDrake
Posts: 250
Joined: Mon Jun 26, 2017 10:11 pm
Contact:

Re: First steps into Z88DK...and many more to come!

Post by SamusDrake » Mon Apr 30, 2018 8:22 pm

Mucking around with the libctest.c example for the Master system to get a better idea of what-does-what...

Code: Select all

/*********************************************************
 *
 * "main.c" by S.A Ray (SamusDrake). This is a modification 
 * of libctest.c, which I believe is the work of a developer
 * named suborb.				 
 *
 ********************************************************* 
 *
 * Compile with: zcc +sms -vn main.c -o main.bin -create-app
 *
 *********************************************************         
 *
 * Written using z88dk.
 *
 * As always, cheers to the community at the ZX Spectrum 
 * Next forum. ^_^
 *
 *********************************************************/ 

#include <stdio.h>
#include <sms.h>

// Palette for 'sprite layer'?
unsigned char pal1[] = {0x0C, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

// Palette for 'tile layer'?
unsigned char pal2[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

// Function prototypes.
void print_message( char *message, int x, int y );
void init_program();

/////////////////////////////////////////////////////////////////////////

/////////////////////////////
// entry point to program. //
/////////////////////////////
void main()
{
	init_program();

	print_message( "SEGA MASTER SYSTEM", 6, 11 );
	
	while( TRUE ) 
	{
		wait_vblank_noint();
	}
}

/////////////////////////////////////////////////
// Clear vram, load a font and palette entries //
// and set the VDP registers                   //
/////////////////////////////////////////////////
void init_program()
{
	clear_vram();
	load_tiles( standard_font, 0, 255, 1 );

	load_palette( pal1, 0, 16 );
	load_palette( pal2, 16, 16 );

	set_vdp_reg( VDP_REG_FLAGS1, 
		     VDP_REG_FLAGS1_BIT7 | VDP_REG_FLAGS1_SCREEN );
}

////////////////////////////////////////
// Displays a text message on screen. //
////////////////////////////////////////
void print_message( char *message, int x, int y )
{
	gotoxy( x, y );
	printf( message );
}

...it certainly provided a good starting point, and I hope the original author doesn't mind.

Alcoholics Anonymous
Posts: 495
Joined: Mon May 29, 2017 7:00 pm

Re: First steps into Z88DK...and many more to come!

Post by Alcoholics Anonymous » Tue May 01, 2018 5:28 am

For the sms you may want to check out devkitsms in the newlib. This is the c api that is now in common use for the master system. There are examples inside z88dk here: https://github.com/z88dk/z88dk/tree/mas ... AMPLES/sms

The astroforce code is inside z88dk, here's a youtube vid:



The same author wrote silver valley also using devkitsms and z88dk but the source is not open:



The classic library that you're using above has a different api that was written years earlier and is not quite as capable.

SamusDrake
Posts: 250
Joined: Mon Jun 26, 2017 10:11 pm
Contact:

Re: First steps into Z88DK...and many more to come!

Post by SamusDrake » Thu May 03, 2018 10:01 pm

Okay, I think I'm closing in on the problem with Code::Blocks...

I have Mingw set up on the Windows 10 computer and I can run the command gcc from any directory location. But for zcc, I must be in the Z88DK\bin folder to run it. Anywhere else and it dont work...

Its now gnawing away at me that I haven't set it up properly in the environment variables. Going to work on this and hope to have the solution soon...

Alcoholics Anonymous
Posts: 495
Joined: Mon May 29, 2017 7:00 pm

Re: First steps into Z88DK...and many more to come!

Post by Alcoholics Anonymous » Fri May 04, 2018 5:02 am

SamusDrake wrote:
Thu May 03, 2018 10:01 pm
But for zcc, I must be in the Z88DK\bin folder to run it. Anywhere else and it dont work...

Its now gnawing away at me that I haven't set it up properly in the environment variables. Going to work on this and hope to have the solution soon...
It sounds liike z88dk/bin is not in your path. There are two environment variables you need to set: ZCCCFG and adding z88dk/bin to PATH:
https://www.z88dk.org/wiki/doku.php?id= ... nt#windows

SamusDrake
Posts: 250
Joined: Mon Jun 26, 2017 10:11 pm
Contact:

Re: First steps into Z88DK...and many more to come!

Post by SamusDrake » Fri May 04, 2018 8:03 am

I had z88dk on another drive that wasn't C:\ but that alone shouldn't have failed, but the path was long winded so in the end I just relocated it the C drive and simply C:\z88dk...

For some reason it now works from command prompt(yay!), although still no dice in CodeBlocks, but I think thats now just a case of getting it to use the makefile I have provided. Alvin, would I be correct in using Mingw's mingw32-make.exe as the make program for z88dk? I get the following error( from command prompt, not Codeblocks ) when using it...

Code: Select all

Makefile:1: *** recipe commences before first target.   Stop.
...and this is the contents of the make file....

Code: Select all

zcc +zx -vn -clib=sdcc_iy -startup=31 -c main.c

Post Reply