Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding new commands to ZX BASIC
#1
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).
Reply
#2
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. <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Library">http://www.boriel.com/wiki/en/index.php ... IC:Library</a><!-- m -->

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!)
Reply
#3
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. <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Library">http://www.boriel.com/wiki/en/index.php ... IC:Library</a><!-- m -->
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.
Reply
#4
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 Wink
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!
Reply
#5
Ok, well I'll code the commands up as libraries, but I'd still like to know how to add commands.
Reply
#6
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.
Reply
#7
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.
Reply
#8
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!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)