Ned – Project Update #1

One of the ambitions I have for the ZX Spectrum Next after I’ve finished the Lords of Midnight port is to provide a complete development environment on the Next itself. Currently, I have to write code on a PC, assemble and test it using Mike Dailly’s wonderful snasm and Cspect tools, and then copy a .sna file to an SD card, physically take that to my Next, remount the card (via the browser) and run it. I have a FlashAir SD card, so in theory I can just copy the files from my PC over the network to the card plugged into my Next. In practice, the damn thing never works.

Well this is tedious.

So I decided that I would embark on writing a set of tools that allow me to only require a Next to do development. I could write Z80 code on paper, hand-assemble it, then pull out my favourite hex-editor and type code in. Not only is that even more tedious but this would require BASIC taking up a load of memory while I program.

The first tool I require is a text editor. I mentioned this idea to the Next team, it got a good response and I was told I should use the new tilemap video mode to implement a 80×32 text screen. I decided I would like to write an editor similar to vi in that it has a mode for entering text (insert mode), and a mode for doing manipulations on it (normal mode). For those that are not familar with vi and its modes, having two modes of use is useful for a machine that doesn’t have a full keyboard that we’re used to on PCs.

Of course, I will not be porting vi as it would take too much effort and I would like to end up with a tool that works with NextZXOS with the final result being a dot command. So the whole tool needs to fit in 8K preferably. But I will be taking some inspiration from it and borrowing some of its commands. I will also make it a little simpler for first users too. For example, and this will only be understood by vi users, I would have insert mode the default mode for new files, and normal mode for already existing files that are opened. These means you can create a new file and start typing immediately. I will also add simple keystrokes to save and quit too.

So today I started coding. I wanted to get the tilemap system worked out and the palette, then try printing some text. I borrowed a font from David Saphier and quickly got this running:

Hello to you too!

Now I wanted to try and support different colours. Because of the way the tilemap attributes system worked, I could only do 16 combinations of paper and ink colours. I could have one combination for normal text, another for the cursor, another for some rudimentary syntax highlighting and so on. After coding this, I got this slightly more interesting screen:

It’s starting to look like an editor

For the technical of you, I arranged the memory layout so that code would lie between $8000 and $9fff, editor state at $7000, and the text buffer from $c000 onwards. This allows for a 16K text buffer. This will be ample for a working towards a first version of the editor. After this decision was made, I embedded a test text file into the memory at $c000 onwards and set about writing the routines to draw the file on the screen. I have written it so it can handle scrolling in all four directions. By the end of the day I had something on my screen:

Now it really looks like a text editor!

Of course, I have no code to interpret keyboard commands and allow me to scroll around the file. So my next milestone is to do just that: implement keyboard routines (there’s a reason I am not using the ROM routines and I will discuss that another time); implement a cursor; and allow the cursor to move around the file. I hope to support the four cursor directions, page up, page down, home & end for both lines and files, as well as jump through words.

Finally, I decided to see how it looked on my own ZX Spectrum Next:

Just seeing this on real hardware has motivated me more to complete this. For any old Amiga programmers, perhaps you might understand when I say that this gave me HiSoft DevPac3 vibe!

2 Comments

  • Paul Land AKA Jaquen Dax says:

    Fantastic Work there Matt. You are making some real headway. I am so looking forward to this. Being able to Dev in Assembler properly on the Next is very exciting indeed. If you need any testing done I’ll willing help anyway I can. For me this is THE most important missing link for the Next.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.