Emulator

I decided to do some work on a simple Libby8 emulator. With an emulator it should be possible to do some Libby8 development before the hardware is working - it means some of the many, avid followers of Libby8dev can contribute to the project pretty much right now, by being able to write software for the platform.

To get a Libby8Emulator to work I pieced together:

My initial stage was to get Qaop to run as a hybrid ZX Spectrum / Libby8, by supporting the HALT interface and a switch to the Libby8 video mode. Then I created a 'proper' emulator which can boot actual roms. This is the version that's been released here.

There's not much documentation for the software side of Libby8, you'll have to figure it out by yourself. The current Libby8 bootstrap code and SDCC compilation commands are in the file Libby8BootRom.c. At the moment Libby8 supports the following API:

// Libby API.

void LibbyPutCh(char ch); // Displays a character, supports \n and wraps around the screen.

void LibbyPutS(char *str); // Displays a null-terminated string.

void LibbyPutSN(char *str, int len); // Displays n characters of a string even if some are null.

void LibbyAt(byte x, byte y); // Moves the cursor position to x,y in 8x8 character units.

void LibbyCls(void); // Clears the Libby screen using Ldir.

int LibbyTime(void); // Returns the bottom 2 bytes of the libby clock in milliseconds.

char Inkey(void); // Returns a keypress (later versions will also return the keymap ).

void Libby8VidSet(byte mode); // Sets a Libby8 video mode, only 256x192 is supported.

void LibbyBlockRead(unsigned int block, char *dst); // Reads a 1k block from the 384K Amic Flash Disk.

void LibbyBlockWrite(unsigned int block, char *src); // Writes a 1k block to the 384K Amic Flash Disk.

void PutHex(uint n);

void PutUint(uint n);

You can use the API in your own code to provide access to the 'hardware'. You shouldn't change the bootstrap code in the _start function or add any code or data before _start, as this code is pretty much what the real Libby8 bootstrap will do. Importantly you must not define any automatically initialised variables. At this point you should be able to create your own Rom applications and games and also store data in 'flash'. As for a real Libby8 the video starts at 0x6800 and runs in monochrome for 6K. Unlike a ZX Spectrum video is linear - every successive row starts 32 bytes after the previous one.

This Libby8 runs at full speed emulation - actually about 25% faster than before. The current 'rom' does a benchtest showing the number of ms used to clear the screen & display the test pattern. Then it displays 'Hello You!' in a box that bounces around and you can control it with 'f'/'s' to make it faster or slower; 'z'/'x' to decrease/increase the x step; 'o'/'k' to decrease/increase the y step. Pressing 'd' runs the disk test.

Here's an early Libby8 screenshot:

It was the result of running:

void main(void)

{

    char ch;

    int timeout=0;

    TestPat();

    Libby8VidSet(1);    // enable Libby8Video.

    LibbyAt(10,10);    //

    LibbyPutS("Libby8! - Press Q");

    while((ch=Inkey())!='Q' && ++timeout) {

        LibbyAt(30,10);

        LibbyPutCh(ch);

    }

    LibbyAt(10,11);

    LibbyPutS("Done, Pressed=");

    LibbyPutCh(ch);

    LibbyAt(10,12);

    LibbyPutS("Waiting for 5s");

    timeout=LibbyTime()+5000;    //

    while(LibbyTime()-timeout<0)

        ;    // wait.

    LibbyCls();

    timeout=LibbyTime()+1000;    //

    while(LibbyTime()-timeout<0)

        ;    // wait.

    LibbyCls();   

}

Have fun!