NABU Computer Support

Discussion about other targets
DJ Sures
Member
Posts: 67
Joined: Sun Dec 11, 2022 12:41 pm

NABU Computer Support

Post by DJ Sures »

Hello,

I'm part of the NABU Computer Preservation Group. We've been working on restoring the 1982 NABU network to its original state. We created a homebrew loader in our adapter emulator during development and reverse engineering. This allows loading any homebrew binaries compiled for the NABU hardware configuration. There are no API BIOS like the Coleco or MSX to aid the programmer - so a development environment with graphics (font/sprite), sound, and keyboard i/o support is needed. After a few experiments, I determined z88dk would be a great candidate. What is the process of intriguing the z88dk team to add support for the NABU? I can start by providing some hw information...

- The CPU is a Z80A @ 3.58 MHz

- 64K of RAM (16k of dedicated video ram)

- The BIOS loads a binary on startup from the network adapter, which usually gets its application from a cable model. The BIOS writes the application code starting at $1410. But the execution entry point is $140D. So we just put 3 NOP at the start of every program.

- The VDP is a TMS9918A with 16k x 8 dynamic ram (not connected to z80 bus). VDP Data port is 0xA0h. VDP latch is 0xA1h

- The Sound IC is an AY-3-8910. Its write/read data port is 0x40h. Its latch port is 0x41h

- The keyboard is a UART and receives keycodes in ASCII. The upper ASCII values are for the joysticks and some error messages. The keyboard data port is 0x90h. The keyboard status port is 0x91h

- There is a communication port to the network adapter at 0x80 for reading and writing.

MAME published a machine emulator for the NABU a few hours ago using our templates from the reverse engineer process.

What we're looking for from z88dk is support for your graphic library, sound library, and stdio to print to the screen and input from the keyboard. This will be a good starting template for homebrew developers to create applications on this rare and unknown machine.

We have technical documentation that dives into details of the overview that I provided here: https://nabu.ca/homebrew

Thanks, and I'm looking forward to working with you all!
DJ
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: NABU Computer Support

Post by dom »

Given that it's a VDP machine, adding support for the graphics side of things should be pretty easy.

In this commit support for the LM80c was added which has a VDP and AY:

https://github.com/z88dk/z88dk/commit/c ... 6a48a48316

Which should cover a lot of the basic functionality you need.
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: NABU Computer Support

Post by dom »

I've added bare bones support for the Nabu. I'm waiting for a mame build in order to do any testing of it
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: NABU Computer Support

Post by stefano »

I discovered the NABU just yesterday, it's fantastic to see it addressed already!
DJ Sures
Member
Posts: 67
Joined: Sun Dec 11, 2022 12:41 pm

Re: NABU Computer Support

Post by DJ Sures »

Wow, great - native z88dk support for the Nabu will deprecate the z88dk library I've been publishing for homebrew apps. I have attached my NABULIB for reference.

NABULIB:
NABULIB.zip
Specific things regarding the clock frequency in that lib are:

1) high and low byte values for AY notes

2) HCCA send and receive

3) Keyboard input

Did you get the NABU Mame yet? You will need my internet adapter for it to do anything useful. Get it from https://nabu.ca/nabu-internet-adapter-downloads
You do not have the required permissions to view the files attached to this post.
DJ Sures
Member
Posts: 67
Joined: Sun Dec 11, 2022 12:41 pm

Re: NABU Computer Support

Post by DJ Sures »

I should add a hello world template using the ORG to set for $140D.

1) The binary is loaded starting at $1410

2) The entry point is $140D, which is why there are 3 NOP for the difference between the loading address and the entry point address

Code: Select all

static void orgit() __naked {
  __asm
  org     0x140D
    nop
    nop
    nop
    __endasm;
}

void main2();

void main() {

  main2();
}

#include <z80.h>
#include "../NABULIB/NABU.h"
#include "../NABULIB/tms9918.h"

uint16_t _inCntr = 0;

void main2() {

  vdp_init_textmode(0x0f, 0x00);

  while (true) {

    vdp_set_cursor2(0, 0);

    vdp_print("Hello World");

    vdp_set_cursor2(0, 1);

    vdp_WriteUInt16(_inCntr);

    _inCntr++;
  }
}
DJ Sures
Member
Posts: 67
Joined: Sun Dec 11, 2022 12:41 pm

Re: NABU Computer Support

Post by DJ Sures »

*Apologies for all the flooding of messages - but I'm adding information as I feel it is relevant to your efforts.

I did mention the BIOS in my first post - however, the BIOS is limited to only loading the program from HCCA into RAM at the address I mentioned earlier. The BIOS does not contain helper functions like other systems, such as keyboard input, vdp, sound, etc.

If you look at the library I posted above (NABULIB), I am polling the keyboard and HCCA because I cannot get interrupts to compile with ZCC.
I keep getting an error about the "Old Style C Declaration" on the M_BEGIN_ISR defined in IM2.H. So I cannot help you with the interrupts on that hardware yet.

For example, the code below will return this error...
zcc +z80 -mz80 -startup 0 -zorg 0x140D --no-crt -O3 --opt-code-speed -lm main.c -o "C:\NABU Segments\000001.nabu"

../NABULIB/tms9918.c:313: warning 110: conditional flow changed by optimizer: so said EVELYN the modified DOG
main.c:29: error 7: Old style C declaration. IGNORED 'M_BEGIN_ISR'
main.c:33: error 1: Syntax error, declaration ignored at 'M_END_ISR'
main.c:35: syntax error: token -> '{' ; column 14
main.c:44: syntax error: token -> '(' ; column 21

Code: Select all

static void orgit() __naked {
  __asm
  org     0x140D
    nop
    nop
    nop
    __endasm;
}

void main2();

void main() {

  main2();
}

#include <z80.h>
#include <im2.h>
#include "../NABULIB/NABU.h"
#include "../NABULIB/tms9918.h"

uint16_t _timer = 0;
uint16_t _inCntr = 0;

/* Ensure IM2 is left at exit */
#pragma output CRT_INTERRUPT_MODE_EXIT = 2

 // this isr will count down several timers to 0
M_BEGIN_ISR(isr) {

  _timer++;
}
M_END_ISR

void main2() {

  NABU_DisableInterrupts();

  //im2_Init(0xd300);                // place z80 in im2 mode with interrupt vector table located at 0xd300
  //memset(0xd300, 0xd4, 257);       // initialize 257-byte im2 vector table with all 0xd4 bytes
  //bpoke(0xd4d4, 195);              // POKE jump instruction at address 0xd4d4 (interrupt service routine entry)
  //wpoke(0xd4d5, isr);              // POKE isr address following the jump instruction

  im2_init((void*)0xd300);
  memset((void*)0xd300, 0xd4, 257);
  z80_bpoke(0xd4d4, 195);
  z80_wpoke(0xd4d5, (unsigned int)isr);

  NABU_EnableInterrupts();

  vdp_init_textmode(0x0f, 0x00);

  while (true) {

    vdp_set_cursor2(0, 0);

    vdp_WriteUInt16(_timer);

    vdp_set_cursor2(0, 1);

    vdp_WriteUInt16(_inCntr);

    _inCntr++;
  }
}
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: NABU Computer Support

Post by dom »

I've not been able to find an appropriate macOS build with support so I'm building it myself from the brijohn fork.

Once that's built we'll see where I am.
DJ Sures
Member
Posts: 67
Joined: Sun Dec 11, 2022 12:41 pm

Re: NABU Computer Support

Post by DJ Sures »

That's fantastic - great to hear. I did get interrupts working, so I created a circular buffer for the HCCA as a test. It's added to my recent NABULIB, which I have to fix a few things before posting.

Summary...

Code: Select all

/// <summary>
/// HCCA RX Input buffer (256 bytes)
/// </summary>
volatile uint8_t _rxBuffer[256];

/// <summary>
/// HCCA RX read position
/// </summary>
uint8_t _rxReadPos = 0;

/// <summary>
/// HCCA RX write position (used in interrupt)
/// </summary>
volatile uint8_t _rxWritePos = 0;

IM2_DEFINE_ISR(isr) {

  if (hcca_IsDataAvailable()) {

    _rxBuffer[_rxWritePos] = hcca_readByte();

    _rxWritePos++;
  }
}

void hcca_EnableReceiveBufferInterrupt() {

  NABU_DisableInterrupts();

  memset((void*)0xd300, 0xd4, 257);
  z80_bpoke(0xd4d4, 195);
  z80_wpoke(0xd4d5, (unsigned int)isr);
  im2_init((void*)0xd300);

  NABU_EnableInterrupts();
}

bool hcca_IsRxBufferAvailable() {

  return _rxWritePos != _rxReadPos;
}

uint8_t hcca_readFromBuffer() {

  uint8_t ret = _rxBuffer[_rxReadPos];

  _rxReadPos++;

  return ret;
}
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: NABU Computer Support

Post by dom »

DJ Sures wrote: Fri Dec 23, 2022 8:22 amDid you get the NABU Mame yet? You will need my internet adapter for it to do anything useful. Get it from https://nabu.ca/nabu-internet-adapter-downloads
So after 5 hours something popped out and I've added an option to the +cpm target (-subtype=nabu) which will create discs and has access to our standard VDP library:

Code: Select all

zcc +cpm -subtype=nabu [files.c] -create-app
Unless there's a command line alternative, I'm not going to get anywhere fast with the "internet adapter" route - Windows.Forms isn't available within mono for non-archaic mac version.

So, I'll continue adding hardware support to the CP/M support library - the code is shared with the non-CP/M target so the effort isn't wasted.
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: NABU Computer Support

Post by dom »

Well, after a bit of head scratching over why interrupts were being enabled seemingly randomly (hint writing to AY register 7 causes Mame to re-evaluate the IRQ settings) I've now got the Tracker modules working on the Nabu.

So in theory the basics and extras are working: screen, keyboard, sound chip and the Nabu is supported under CP/M (tested) and as a native target (untested).

I'd like to add support for interrupts for the native target: is im2 handled properly on the machine - i.e. can I register different handlers for each interrupt source or do I have to do it the 257 byte table way?

We've now got a wiki page: https://github.com/z88dk/z88dk/wiki/Platform---Nabu so it's all official
User avatar
RobertK
Well known member
Posts: 347
Joined: Mon Feb 26, 2018 12:58 pm

Re: NABU Computer Support

Post by RobertK »

Thanks Dom for adding this new target!

I've tried running my Deepspace game in CP/M mode on a Nabu-enabled MAME build, and it looks pretty good already, but there is still a problem when there is text output in graphics mode (TMS9918 mode 2): printing text always generates some garbage on the upper part of the screen. You can reproduce it already at the startup screen of my game by pressing S or C to toggle the sound or control option.

Attached is a test package.

@DJ Sures: it's great that you showed up here, I've been following your NABU videos since the very first one - YT recommended it to me after having previously watched Adrians's NABU video...
You do not have the required permissions to view the files attached to this post.
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: NABU Computer Support

Post by dom »

RobertK wrote: Wed Dec 28, 2022 9:58 pm printing text always generates some garbage on the upper part of the screen. You can reproduce it already at the startup screen of my game by pressing S or C to toggle the sound or control option.
I have a hunch that it's might be reading the keyboard that causes that problem - I can also see a keyboard cursor blinking away as well.

Edit: Yes it is reading the keyboard that's causing the problem + cursor is coming from the interrupts. I've got something working by disabling interrupts and reading the keyboard port directly but I'd like to figure out a cleaner way to do it.
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: NABU Computer Support

Post by dom »

dom wrote: Tue Dec 27, 2022 10:06 pmI'd like to add support for interrupts for the native target: is im2 handled properly on the machine - i.e. can I register different handlers for each interrupt source or do I have to do it the 257 byte table way?
Answering my own questions, but for future reference then yes, register different handlers for each interrupt source. CP/M adds a vector at ff04 to handle reading the keyboard, and another one at ff06 for vsync, so by inference the following can be registered:

+00 HCCA Receive
+02 HCCA Send
+04 Detachable Keyboard
+06 Video Frame Sync
+08 Option Card 0
+0a Option Card I
+0c Option Card 2
+0e Option Card 3
DJ Sures
Member
Posts: 67
Joined: Sun Dec 11, 2022 12:41 pm

Re: NABU Computer Support

Post by DJ Sures »

Thanks, everyone - this is great to see. I have continued adding support for my Nabu-lib, which now has remote file support. I'm modifying a CPM build to use the HCCA for storing files remotely on the internet adapter. The challenge CPM has now is that no one can run it on real hardware. There are only 3 or 4 floppy drives and controllers in existence. So until I get CPM running with remote files via HCCA from the IA, apps are loaded via homebrew entry address ORG $140D.

Are you considering a homebrew compile option in the wiki? I can modify my NABU-LIB to your homebrew target settings and will distribute that.

Here's my NABU-LIB with examples: https://github.com/DJSures/NABU-LIB

Also, Happy new year!
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: NABU Computer Support

Post by dom »

The primary compilation example on the wiki is for the homebrew target.

Unfortunately, I've got absolutely no way of testing it because I can't run the IA.

However, the code is shared between CP/M and home-brew so it should work assuming the setup is good.
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: NABU Computer Support

Post by dom »

I've hooked the interrupts so a frame tick interrupt is now available. I've also taken the decision to handle the keyboard ISR as well.

The handling of the keyboard is trivial, no debounce, autorepeat or anything like that but hopefully it's broadly functional.

Interrupts should be restored to whatever CP/M had set on exit, but it may not be foolproof.

What this means that DeepSpace now behaves a bit better - no screen defects. It's a little awkward to control for some reason - I don't remember other versions being like that so there might be some more stuff still to do.

Next stage will be to handle the HCCA interrupts and provide serial access etc
GryBsh
Member
Posts: 21
Joined: Sun Jan 01, 2023 12:56 pm

Re: NABU Computer Support

Post by GryBsh »

dom wrote: Sat Dec 31, 2022 6:02 pm The primary compilation example on the wiki is for the homebrew target.

Unfortunately, I've got absolutely no way of testing it because I can't run the IA.

However, the code is shared between CP/M and home-brew so it should work assuming the setup is good.
There are several other Adaptor emulators/simulators. Take a look at github, several to choose from :)
I made one and I ship macOS binaries and I've gotten feedback it does work on it. It is made with dotnet, but doesn't require mono or any runtimes installed: I bundled it all in. NO UI though. https://github.com/GryBsh/NabuNetworkEmulator/releases/

To use mine with just MAME via TCP, in the appsettings.json, add "Enabled: false" to or remove completely the Serial adapter config (or it will complain at you every 5 seconds). And then you can either drop your nabu files in the NABUs folder and change the "Channel" to the name of your NABU file, or you can just name it 000001.nabu and omit the Channel from the TCP adapter config and it will find it as pak 1. If you close MAME, it will gracefully abort and start trying to connect again. If you close the emulator, at least on Windows, MAME never seems to realize you've disconnected. You can copy it and change the port numbers on both ends and run more than one instance of TCP on multiple ports.

Use mine or use another one, but you have options that are not the IA you can't get to run :)
Last edited by GryBsh on Sun Jan 01, 2023 1:17 pm, edited 1 time in total.
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: NABU Computer Support

Post by dom »

GryBsh wrote: Sun Jan 01, 2023 1:13 pmThere are several other Adaptor emulators/simulators. Take a look at github, several to choose from :)
I made one and I ship macOS binaries and I've gotten feedback it does work on it. It is made with dotnet, but doesn't require mono or any runtimes installed: I bundled it all in. NO UI though. https://github.com/GryBsh/NabuNetworkEmulator/releases/
Thank you - I was hoping there was an alternative. I can confirm it runs and loads the cycle PAK files.

No joy with a nabu file though:

Code: Select all

17:28:09 info: Nabu.Network.NetworkSimulator[0] Refresh Channel List from Source: Local
17:28:09 info: Nabu.Network.NetworkSimulator[0] Adding [cycle1] cycle1 from Local
17:28:09 info: Nabu.Network.NetworkSimulator[0] Adding [cycle2] cycle2 from Local
17:28:09 info: Nabu.Network.NetworkSimulator[0] Adding []  from Local
17:28:10 info: Nabu.Network.NetworkSimulator[0] Refreshed (3 Channels)
...
17:28:16 info: Nabu.Network.NabuNetProtocol[0] NPC: Segment: 0000, PAK: 000001, NA: Confirmed
17:28:16 warn: Nabu.Network.NetworkSimulator[0] NTWRK: No Channel or NABU file for 1
Making NabuRoot absolute fixed the problem, so I'm guessing there's something wrong around about here: https://github.com/GryBsh/NabuNetworkEm ... or.cs#L137
DJ Sures
Member
Posts: 67
Joined: Sun Dec 11, 2022 12:41 pm

Re: NABU Computer Support

Post by DJ Sures »

the official nabu Internet Adapter does work on mac, but you need to launch it with mono32, instead of mono

So type

mono32 ./InternetAdapter.exe
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: NABU Computer Support

Post by dom »

I'm afraid that hasn't worked for a few macOS versions - x86 support was removed a while back - I'm running Big Sur for reference:

Code: Select all

% mono32
zsh: bad CPU type in executable: mono32
% file `which mono32`
/Library/Frameworks/Mono.framework/Versions/Current/Commands/mono32: Mach-O executable i386
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: NABU Computer Support

Post by dom »

Anyway, after all of that I can confirm that +nabu is now working and I can get back to the hcca code.
GryBsh
Member
Posts: 21
Joined: Sun Jan 01, 2023 12:56 pm

Re: NABU Computer Support

Post by GryBsh »

dom wrote: Sun Jan 01, 2023 5:50 pm Making NabuRoot absolute fixed the problem, so I'm guessing there's something wrong around about here: https://github.com/GryBsh/NabuNetworkEm ... or.cs#L137
Because if I am going to make a mistake, it's going to be something like pathing and I am going to read this right after I build new binaries XD.
I'll give that a fix. Thanks!
Last edited by GryBsh on Sun Jan 01, 2023 7:43 pm, edited 1 time in total.
DJ Sures
Member
Posts: 67
Joined: Sun Dec 11, 2022 12:41 pm

Re: NABU Computer Support

Post by DJ Sures »

dom wrote: Sun Jan 01, 2023 6:28 pm I'm afraid that hasn't worked for a few macOS versions - x86 support was removed a while back - I'm running Big Sur for reference:

Code: Select all

% mono32
zsh: bad CPU type in executable: mono32
% file `which mono32`
/Library/Frameworks/Mono.framework/Versions/Current/Commands/mono32: Mach-O executable i386
oooooooh! Geez - Mono was the world's last hope at cross platform GUI. Ugh... don't get me started on Avalonia

Anyway - looks like GryBsh's command-line will work for ya. Guess I can build a dotnet cli of mine but Gry's got it covered :D
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: NABU Computer Support

Post by dom »

There’s always swing…

In all seriousness I think the answer these days is “use a browser” - either host a Webapp in a process that handles serial/tcp etc or just use the Webapis that expose that functionality and not have a native side.
Post Reply