Jump to content
VincentF

Basic syntax highlighter

Recommended Posts

Posted (edited)

Hello everybody !

Some days ago I discovered millfork, a programming language designed for Z80 and 6502 computers. I saw that X16 is supported and so I started to write a prototype with this language to see what it can do.

This first prototype is a Basic syntax highlighter. it writes on the screen lines of Basic with colors for the line numbers, basic keywords and literal values (strings and numbers).

After compiling in Release mode, I was impressed by the resulting .prg file that was around 1KB ! Knowing that basic keywords can take around 400 bytes, I think that the compiler has done a pretty good work (although I still think it can be lighter if someone takes time to optimize it or even use a different approach than mine).

x16_basic_highlight.png.767342f315a38f9891fce14d2321e71c.png

For now, sadly, this program uses strings of Basic as input and outputs them directly on screen. It's useless because it's not using the Basic code stored in memory. Do you think that something like this is possible to do ?

One approach that I think can work is just calling "LIST" and then a "SYS" command to read the on-screen basic code and highlight it on the fly.

I'm attaching the millfork source file basichighlight.mfk and the released prg basichighlight.prg so you can take a look and maybe talk about it further ? 🙂

Note : In the millfork file, I have commented the tiny text adventure written by Robin from 8-bit show and tell as a way to test the syntax highlighter. Notice that the code is altered because of some limitations of my program that can't handle lines going beyond the right side of the screen.

Thanks you for reading ! I'll eventually post updates on this thread if I have more content to share in the future 😄

Edited by VincentF
removed "written with millfork" from post title
  • Like 2

Share this post


Link to post
Share on other sites
Posted (edited)

Update :

I rewrote the parser in assembly (I admit it was way harder than with Millfork) but it's not only that.

On my way to learn how the X16 works, I found out I didn't though about IRQs as a possible solution to my previous question. So what I did is write a custom IRQ routine that runs before the Kernal's own subroutine.
What this routine do is find out when the cursor has changed its line and parses the potential code found in the cursor's old position. It ignores the line if it's not starting by a number.

highlight.gif.27abaade7f3946079b479c6fbda3151b.gif

With that, the program is even lighter than the previous one, from around 200 bytes ! 🙂

Internally, the program insert the classic BASIC program SYS command but also a second command "NEW" so that you can start writing your basic code directly after running the program.
The main code is located at address $8000 so you have some space to write your basic program.

Here's the prg file : highlight.prg

The source code consist of few files so I will post a zip file containing them. don't mind the weird tree it's mainly because my programs shares the same libraries. basic_highlight_src.zip

I didn't have tested everything so maybe there are bugs that I don't have found yet. Feel free to report anything you found while testing 🙂

Again, thanks for reading !

Edited by VincentF
typos, wording
  • Like 5

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Please review our Terms of Use