FAQ  •  Register  •  Login

Adding new commands to ZX BASIC

<<

cheveron

User avatar

Posts: 71

Joined: Sat Dec 11, 2010 11:22 pm

Post Fri Dec 06, 2013 9:43 am

Adding new commands to ZX BASIC

Just to help me understand the structure of the language a bit better I'd like to know what the method would be for adding commands. I'm mainly interested in adding the following commands from SE Basic IV:

CLUT: select color look-up table (0 to 3)
COLOR: absolute attribute value (0 to 255)
PALETTE: set ULAplus registers
RESET: restore palette from palette buffer (first 64 bytes after screen)
PUT: wrapper for LDIR
SCROLL: text display scrolling
SOUND: set AY registers
SPEED: set CPU speed for clones

But I can also provide support for the one everyone is always asking for:

PLAY

All of this can be done without requiring either the SE Basic ROM or the 128 ROM. Having said that PLAY isn't very versatile, can't be interrupt driven, and has a fairly large RAM overhead (the routine takes 2296 bytes).
<<

britlion

Posts: 766

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Fri Dec 06, 2013 10:39 am

Re: Adding new commands to ZX BASIC

To add commands to the compiler, you'd have to rewrite the compiler such that it knew what to do with new commands. So far that's been down to Boriel only.

To add new features, however - we do that all the time. You can write functions and subroutines and publish them for others to use. Ideally, add them to the Library in the wiki. http://www.boriel.com/wiki/en/index.php ... IC:Library

By that logic, I (and others!) have been adding new commands to the language all the time. 64 character printing commands ( print64("hello world") ), double size printing or faster maths options. You just write it to a file, #include it and away you go with new commands available. If you don't like it, you can tweak it for your programs - but sharing useful subroutines and functions is a way of extending the language for everyone else as well.

Most of the stuff you list is a trivial bit of assembly, really - and you can copy them right out of your SE basic code I suspect. The library routines there will be good pointers for how to get

SUB put (source as uInteger, destination as uinteger)

variables like those from the popping stack or from using the IX pointer into assembly code.

Code for Play is definitely more reasonable for Boriel to include - but write it up as a sub first and submit it. Other stuff that's got in began life there.
(Though automated 128K memory support would be far more useful, I think!)
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Fri Dec 06, 2013 12:00 pm

Re: Adding new commands to ZX BASIC

britlion wrote:To add commands to the compiler, you'd have to rewrite the compiler such that it knew what to do with new commands. So far that's been down to Boriel only.

To add new features, however - we do that all the time. You can write functions and subroutines and publish them for others to use. Ideally, add them to the Library in the wiki. http://www.boriel.com/wiki/en/index.php ... IC:Library

It's like Britlion says. If you think in a language like C, it has succeeded because it's very simple (only 20 keywords or less) and has a lot of libraries.

If you make ZX BASIC to compile for other computer architecture, what happens if it is text only? Or any other strange device?
That's why POINT and ATTR for example are in the library: on some other computers ATTR and POINT will make no sense. :roll:
So the best way will be to implement those function and subs on include files.

Of course there are some core features missing I would like to add (but at the moment I'm not even living at my home!)
For example:
- ON ... GOTO/GOSUB (e.g. ON <expression> GOTO 100, 200, 300
- SELECT ... CASE (equivalent of Switch in c)
- More complex data strucrures
etc. etc.

These require syntactic changes, and I'm working hard to move them to the new parser (2.0 or 1.4) scheme.
<<

LCD

Posts: 596

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

Post Fri Dec 06, 2013 12:39 pm

Re: Adding new commands to ZX BASIC

boriel wrote:Of course there are some core features missing I would like to add (but at the moment I'm not even living at my home!)
For example:
- ON ... GOTO/GOSUB (e.g. ON <expression> GOTO 100, 200, 300

I never used this in any BASIC dialect, but line numbers are obsolete now. I'm sure, you will make them work with labels too.
boriel wrote:- SELECT ... CASE (equivalent of Switch in c)

Thats great. I missed this from your compiler
boriel wrote:- More complex data strucrures
?
Linked Lists like:
  Code:
Structure Spritedata
  posx as ubyte
  posy as ubyte
  hits as ubyte
  name as string
Endstructure
dim sprites(15) as spritedata
sprites.posx(0)=16
sprites.hits(7)=255
sprites.name(3)="Panzer"

At least what I understand as data structure.
boriel wrote:etc. etc.

etc sounds good too ;)
boriel wrote:
These require syntactic changes, and I'm working hard to move them to the new parser (2.0 or 1.4) scheme.

New Parser scheme? Will be the old sources still compilable wirh 1.4 or 2.0?
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
<<

cheveron

User avatar

Posts: 71

Joined: Sat Dec 11, 2010 11:22 pm

Post Sat Dec 07, 2013 9:23 am

Re: Adding new commands to ZX BASIC

Ok, well I'll code the commands up as libraries, but I'd still like to know how to add commands.
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Mon Dec 09, 2013 7:16 pm

Re: Adding new commands to ZX BASIC

cheveron wrote:Ok, well I'll code the commands up as libraries, but I'd still like to know how to add commands.

If by 'commands' you mean something like:
<identifier> <expression>, <expression> ...
E.g.
SCROLL 20, a, 30, c
No, it can't be done.
A library is just a .bas file with subroutines and functions (see for example point.bas or attr.bas). It's just that, nothing else.
Otherwise, yes, we have to touch the parser and at the moment this is not that easy.
<<

cheveron

User avatar

Posts: 71

Joined: Sat Dec 11, 2010 11:22 pm

Post Fri Dec 13, 2013 9:35 am

Re: Adding new commands to ZX BASIC

boriel wrote:
cheveron wrote:Ok, well I'll code the commands up as libraries, but I'd still like to know how to add commands.

If by 'commands' you mean something like:
<identifier> <expression>, <expression> ...
E.g.
SCROLL 20, a, 30, c
No, it can't be done.
A library is just a .bas file with subroutines and functions (see for example point.bas or attr.bas). It's just that, nothing else.
Otherwise, yes, we have to touch the parser and at the moment this is not that easy.


I was assuming it would need to be done in Python. I had a look over the code and it seems that you are pre-tokenizing the .BAS files. Assuming you don't want to use tokens for commands currently implemented as libraries that still gives you codes 0 to 5 to use for new commands.
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sun Dec 29, 2013 2:13 pm

Re: Adding new commands to ZX BASIC

cheveron wrote:I was assuming it would need to be done in Python. I had a look over the code and it seems that you are pre-tokenizing the .BAS files. Assuming you don't want to use tokens for commands currently implemented as libraries that still gives you codes 0 to 5 to use for new commands.


First of all, happy new year to you all. Sorry for the delay: I've been giving a big *boost* to ZX Basic 1.4.x (new generation compiler), so was not very present in the forum

Regarding to your question, I think you're referring to the .BAS tokenizer for the loader. That is, a Sinclair Basic Loader packed within the .tap/.tzx files to load and execute the machine code. It's very (*VERY*) simple and just tokenize little listings, such as LOAD "" CODE, RANDOMIZE USR or the like.
Of course this could be easily extensible, but it's not related to the compiler.

I'm currently working on other part, so users can add more compiler target systems (e.g. MSX).
If you can code SCROLL to be used with parenthesis, then you can implement a .bas listing with a SUB and that's all.
Other thing could be to add something like ".obj" or ".dll" libraries (and releasing only the header function, a la C). But at the moment no one has been able to found a good documentation on .obj files used for example in Z88DK. Doing so will allow ZX Basic and ZX88DK libraries to be interchangeable!

Return to ZX Basic Compiler

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO