Extending the Sinclair BASIC with C

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
stefano
Well known member
Posts: 1772
Joined: Mon Jul 16, 2007 7:39 pm

Extending the Sinclair BASIC with C

Post by stefano »

I'm sure some of you will find this trick intriguing:

Code: Select all

#include <stdio.h>
#include <arch/zx/spectrum.h>

main(int arg2, char *arg1)
{
	ARG_STR;
	ARG_INT;
	ARG_END;
	
	printf("Arg1: %s, arg2: %d \n", arg1 ,arg2);

	STMT_RET;
}
zx-basic-c.png
You do not have the required permissions to view the files attached to this post.
stefano
Well known member
Posts: 1772
Joined: Mon Jul 16, 2007 7:39 pm

Re: Extending the Sinclair BASIC with C

Post by stefano »

Attempting to gather a similar result on the ZX81 is more tricky.
The string termination patch works but the text requires to be converted to ASCII, or a bit of trickery with zx_asciimode(0)/zx_asciimode(1).
("-*114" = "HELLO")

Moreover I still haven't found a robust way to get back to the BASIC interpreter, due to the same reasons preventing zx_goto() to work on the ZX81.
Probably a bit of hacking around exit() will work ;)
zx81-basic-c.png
You do not have the required permissions to view the files attached to this post.
stefano
Well known member
Posts: 1772
Joined: Mon Jul 16, 2007 7:39 pm

Re: Extending the Sinclair BASIC with C

Post by stefano »

2-zx-basic-c.png
Solved !


...to show "HELLO" correctly:

Code: Select all

#include <stdio.h>
#include <zx81.h>

main(unsigned int arg2, char *arg1)
{
	ARG_STR;
	ARG_UINT;
	ARG_END;
	
	printf("Arg1: ");
	zx_asciimode(0);
	printf("%s", arg1);
	zx_asciimode(1);
	printf(", arg2: %u \n" ,arg2);

	STMT_RET;
}
You do not have the required permissions to view the files attached to this post.
stefano
Well known member
Posts: 1772
Joined: Mon Jul 16, 2007 7:39 pm

Re: Extending the Sinclair BASIC with C

Post by stefano »

Just extended support to Lambda 8300 and TS2068
stefano
Well known member
Posts: 1772
Joined: Mon Jul 16, 2007 7:39 pm

Re: Extending the Sinclair BASIC with C

Post by stefano »

Just to show myself that this could be useful, I tried to export few of the zx81 graphics functions to its BASIC interpreter.

https://www.sinclairzxworld.com/viewtop ... 192#p47192


It permitted me to identify a number of bugs I totally forgot to fix. .
Post Reply