NABU Computer Support

Discussion about other targets
GryBsh
Member
Posts: 21
Joined: Sun Jan 01, 2023 12:56 pm

Re: NABU Computer Support

Post by GryBsh »

You already don't need to stick to that name. If you make a `NABUs` folder in with the NNS binary (in the prebuilt zips there is an empty one), you can name you .nabu file whatever you like:
Screenshot 2023-11-17 162849.png
Screenshot 2023-11-17 163046.png
I think the NABU.ca adapter was fussy about having the 000001 name, it may still I don't know its been quite some time since I've used it. But most others give you some mechanism of loading a nabu with an arbitrary name. Whatever file is defined by the source/program is what is sent when the NABU requests pak 1.

I am modifying the on NABU menu the nabunetwork.com adapter already has. It is hard coded to work with the 4 top level menus it has. NNS has more top level menus, and some like cycle direct (which will glitch start any item in the cycle without having to use the menu) go on for pages and pages, and the way it worked didn't lend well to that. Because it was purpose built for that adapter software.

There is basically nothing left of the original at this point, I even changed the communication back and forth to the adapter. (whats in the test code above). But this its so you can run change programs without the UI. It returns to the menu on reboot. NNS get used at a lot of cons and meetups, because it can drive multiple serial as well as TCP NABUs at once. Being able to have each one operate completely independently would be the ideal.
You do not have the required permissions to view the files attached to this post.
GryBsh
Member
Posts: 21
Joined: Sun Jan 01, 2023 12:56 pm

Re: NABU Computer Support

Post by GryBsh »

Well, I've hit another odd one.
if we take this slightly modified version of the test code I posted before

Code: Select all

#include <stdlib.h>
#include <stdio.h>
#include <video/tms99x8.h>
#include <arch/nabu/hcca.h>

#define byte uint8_t
#define uint uint32_t
#define ushort uint16_t

struct Menu
{
	byte count;
	byte pages;
	char *items[20];
};

void main() {
    vdp_set_mode(0);
    byte loop = 0;
    while (1)
    {
        // I've had to put this here because there is a key press 
        // in the buffer on restart.
        puts("Press any key to continue\n");
        getkey(); 
        if (loop > 9) loop = 0;
        
        struct Menu *menu = malloc(sizeof(struct Menu));
        printf("%c", 12);

        hcca_reset_write();
        hcca_start_read(HCCA_MODE_RB, NULL, 0);

        hcca_writeByte(0x30);
        hcca_writeByte(loop);
        hcca_writeByte(0);
   
        hcca_start_write(HCCA_MODE_BLOCK, NULL, 0);
        ushort length = hcca_readUInt16();
        byte *data = malloc(length);
        for (int i = 0; i < length; i++)
        {
            data[i] = hcca_readByte();
        }
        printf("Menu Bytes: %d\n", length);
        
        menu->pages = length == 0 ? 0 : data[0];        
        printf("Menu Pages: %d\n", menu->pages);
        
        
        int count = 0;
        for (int i = 1; i < length; count++ )
        {
            byte n_length = data[i++];
            printf("I: %d, L: %d\n", count, n_length);
            char *item = malloc(n_length);
            for (int n = 0; n < n_length; n++)
            {       
                item[n] = data[i++];
            }
            item[n_length] = '\0';
            menu->items[count] = item;
            
        }
        menu->count = count;
        free(data);

        printf("Menu Count: %d\n", menu->count);
        
        for (int i = 0; i < menu->count; i++)
        {
            printf("%s\n", menu->items[i]);
        }
        
        free(menu);
        loop++;

        puts("________________________________\n");
    }
}
If you compile this without '-compiler=sdcc', it compiles, but it will get to the nabu.ca menu and it just stops dead. If I use sdcc, I get several warnings about missing prototypes, not just in my code, but also in math_genmath.h. And it works just fine besides some random lock ups that happen in both cases.

There is also a key press in the buffer on a restart, which is why there is the getkey() at the beginning, so it won't just skip the first page.
User avatar
dom
Well known member
Posts: 2140
Joined: Sun Jul 15, 2007 10:01 pm

Re: NABU Computer Support

Post by dom »

Oh, it looks like I forgot to document something!

So, with _RB you're reading into a ring buffer of a fixed size. By default that fixed size is 256 bytes. So, page 2 has a size of 324 so the ringbuffer wraps and so the length is probably reading something large and it just gets stuck in the loop trying to read that many bytes.

Configure the ringbuffer size with -pragma-define:CLIB_RXBUF_SIZE=512 (or another multiple of 256), likewise there's a CLIB_TXBUF_SIZE for sending.
GryBsh
Member
Posts: 21
Joined: Sun Jan 01, 2023 12:56 pm

Re: NABU Computer Support

Post by GryBsh »

You're a legend. Thanks! Even after generously expanding the buffers it still locks up from time to time, always when waiting to read data.
Not sure what thats about. But it's working well enough that my Launcher menu is now shipping with NNS.

Also, Joystick 0 inputs are coming in as Joystick 1. Not sure what thats about either.
User avatar
dom
Well known member
Posts: 2140
Joined: Sun Jul 15, 2007 10:01 pm

Re: NABU Computer Support

Post by dom »

Joysticks, yeah I can see the bug! I'll fix it up this evening.

Code: Select all

handle_keyboard:
    ld      a,(__nabu_key_mode)
    ld      hl,__nabu_j1
    cp      1
    jr      z,handle_joy
    ld      hl,__nabu_j1
    cp      2
    jr      z,handle_joy
GryBsh
Member
Posts: 21
Joined: Sun Jan 01, 2023 12:56 pm

Re: NABU Computer Support

Post by GryBsh »

I've tried the last 2 nighlies, and I can see your change in the libsrc folder, but the behavior persists. :(
User avatar
dom
Well known member
Posts: 2140
Joined: Sun Jul 15, 2007 10:01 pm

Re: NABU Computer Support

Post by dom »

I'm temporarily confused as to what was going on so I've rewritten the code a little and it now seems to be working (the routine is in the nabu_int.lib library if you want to recompile yourself).
GryBsh
Member
Posts: 21
Joined: Sun Jan 01, 2023 12:56 pm

Re: NABU Computer Support

Post by GryBsh »

After a weeklong conference and catching up afterwards, I've gotten back to this.
I have pulled and built the latest source about half an hour ago, and I still need to change the input on the launcher to Joystick 1 to get input from what should be Joystick 0. 🤷
User avatar
dom
Well known member
Posts: 2140
Joined: Sun Jul 15, 2007 10:01 pm

Re: NABU Computer Support

Post by dom »

I did test with mame and a psx joypad and there were problems which I resolved.

A couple of points that might be considered gotchas.

1. The joystick reading code is in the nabu_int library
2. joystick() is 1 indexed not 0 indexed.
GryBsh
Member
Posts: 21
Joined: Sun Jan 01, 2023 12:56 pm

Re: NABU Computer Support

Post by GryBsh »

Thinking joystick() is 0 indexed is my problem :lol:
Thanks!
productiondave
New member
Posts: 6
Joined: Wed Jan 10, 2024 11:32 pm

Re: NABU Computer Support

Post by productiondave »

Hey,

I am looking to see if I can port my nabu-games over to native/latest z88dk. I have been using an older library that no longer works since SDCC was upgraded in z88dk. (a topic for a different thread maybe)


The first step is learning how to compile code for CPM.

I am trying to compile: examples/nabu/inputtest.c into a CPM com file.

Code: Select all

./../z88dk/bin/zcc +cpm -subtype=nabu -o tester.com main.c
target/nabu/games/joystick.asm:21: error: undefined symbol: __nabu_j1
  ^---- __nabu_j1
target/nabu/games/joystick.asm:24: error: undefined symbol: __nabu_j2
  ^---- __nabu_j2
target/nabu/games/paddle.asm:19: error: undefined symbol: __nabu_p1
  ^---- __nabu_p1
make: *** [Makefile:9: all] Error 1
When I compile with +nabu on it's own (IE: Native Nabu package / not CPM) it works.

Is there something special I need to do to cause the compiler to find the nabu games target for the joystick?

I am running version 2.3 of z88dk from here: https://github.com/z88dk/z88dk/releases/tag/v2.3

Thanks for your help!
User avatar
dom
Well known member
Posts: 2140
Joined: Sun Jul 15, 2007 10:01 pm

Re: NABU Computer Support

Post by dom »

You'll need to compile with -lnabu_int - because we override the interrupt handlers the keyboard code is kept in a separate library to avoid issues in the case you don't need extra features and just want to use BDOS calls.
productiondave
New member
Posts: 6
Joined: Wed Jan 10, 2024 11:32 pm

Re: NABU Computer Support

Post by productiondave »

Yeah for game dev, I won't be using bdos calls.

I'll test this tomorrow morning.

What impact does nabu_int have on the keyboard? How should I test for a keypress - and if pressed, read the key - in a gameloop?
productiondave
New member
Posts: 6
Joined: Wed Jan 10, 2024 11:32 pm

Re: NABU Computer Support

Post by productiondave »

I added the nabu_int library and it worked perfectly! Thanks.
User avatar
dom
Well known member
Posts: 2140
Joined: Sun Jul 15, 2007 10:01 pm

Re: NABU Computer Support

Post by dom »

productiondave wrote: Fri Jan 12, 2024 11:21 amWhat impact does nabu_int have on the keyboard? How should I test for a keypress - and if pressed, read the key - in a gameloop?
It just means that getk() and fgetc_cons() now use the key captured via the interrupt rather than call into BDOS to get the keypress
productiondave
New member
Posts: 6
Joined: Wed Jan 10, 2024 11:32 pm

Re: NABU Computer Support

Post by productiondave »

Perfect. That's exactly what I was hoping. Thanks!
GryBsh
Member
Posts: 21
Joined: Sun Jan 01, 2023 12:56 pm

Re: NABU Computer Support

Post by GryBsh »

So in experimenting, it looks like the random hangs in the NABU launcher appear to be it hitting some kind of interrupt in the middle of the transfer. I could reproduce the same type of failure when I added a working clock to the menu and the transfer would slam into the raster interrupt.
Any advice on what I could do about this besides transfer data in smaller chunks? If thats the answer so be it, but it will take a bit of doing for me to change the launcher to not gobble menu pages whole.
User avatar
dom
Well known member
Posts: 2140
Joined: Sun Jul 15, 2007 10:01 pm

Re: NABU Computer Support

Post by dom »

Hmmm. It’s a bit of a sledgehammer but there’s a nabu_set_interrupt in arch/nabu.h so you could disable the VDP interrupt.

There’s also uint8_t nabu_get_interrupt() which isn’t in the header yet.
User avatar
dom
Well known member
Posts: 2140
Joined: Sun Jul 15, 2007 10:01 pm

Re: NABU Computer Support

Post by dom »

I've now exported the following functions:

Code: Select all

extern void __LIB__    nabu_set_interrupt(int enabled) __z88dk_fastcall;
extern uint8_t __LIB__ nabu_set_interrupts(void);
extern void __LIB__    nabu_enable_interrupt(uint8_t flags) __z88dk_fastcall;
extern void __LIB__    nabu_disable_interrupt(uint8_t flags) __z88dk_fastcall;
So to disable the VDP interrupt you can do this:

Code: Select all

nabu_disable_interrupt(NABU_INT_VSYNC);
And enabling likewise.
GryBsh
Member
Posts: 21
Joined: Sun Jan 01, 2023 12:56 pm

Re: NABU Computer Support

Post by GryBsh »

Well, it might be a sledgehammer, but it does work.
I can get a ticking clock AND lockup free transfers at the same time.
Many thanks :)
Post Reply