This wiki is being migrated to http://www.github.com/z88dk/z88dk/wiki

User Tools

Site Tools


library:newbrain

Grundy NewBrain LIBRARY (newbrain.h)

Version all
Header {z88dk}/include/newbrain.h
Source {z88dk}/libsrc/newbrain
Include #include <newbrain.h>
Linking n/a
Compile n/a
Supported Grundy BewBrain
Comments n/a

The “newbrain” library contains functions specific to the Grundy NewBrain computer.

Streams

Stream data structure

The following data structure describes the NewBrain streams; the currently available functions don't need it because it is transparently managed by the ROM routines. It is useful only to create custom devices.

  struct NB_STREAM {
           u8_t     stream;       /* stream number      */
           u8_t     driver;       /* driver number      */
           u8_t     port;         /* port number        */
           u8_t     unused;       /* unused             */
           u16_t    address;      /* own memory address */
  };

Driver data structure

  struct NB_DRIVER {
           u8_t    entries;        /* Number of entry points less 1 */
           u8_t    openin;         /* open for input                */
           u8_t    openout;        /* open for output               */
           u8_t    dinput;         /* reads a byte from device      */
           u8_t    doutput;        /* outputs a byte                */
           u8_t    dclose;         /* close the device              */
  }

int nb_open(int mode, int stream, int device, int port, char *paramstr)

Open a stream; these functions are used by the fcntl driver too.

If an error occurs, the error code is returned, otherwise zero.

Examples:

Allocate more memory on channel '0' (console), then open a graphics window leaving two text rows on the top. The graphics device shares the console memory.

   nb_open( OUTP, 0, 0, 0, "150" );
   nb_open( OUTP, 5, DEV_GRAPHICS, 5, "#0,229" );
   printf("Hello!\n2 lines text + lo rez graphics...");

Open the 80 columns console (available on expanded models only), and replace the default output device. Note that the control characters (i.e. line feed) are different.

nb_close (0);
nb_open( OUTP, 0, DEV_SSEIO, 0, "" );

void nb_close(int stream)

Close a file/stream.

void nb_clear()

Close all the streams.

void nb_putc(int stream, char byte)

Send a byte to the stream.

void nb_puts(int stream, char *text)

Send a string to the stream.

int nb_putblock(int stream, char *bytes, int length)

Send a byte block to the stream. Returns the number of bytes effectively written.

void nb_putval( int stream, int value )

Send a NewBrain-formatted numeric value to the stream.

char nb_getc(int stream)

Get a byte from the stream.

char *nb_gets(int stream, char *bytes, int length)

Get a string of max 255 characters from the stream.

Examples:

Read the directory from floppy disk.

char buf[150];
	
	/*  Open the directory device on stream 50 */
	nb_open( OUTP, 50, DEV_SDISCIO, 0, "" );
	
	/* send 'DIR' command (3) for 'A:*.*' to directory device */
	nb_puts( 50, "3A:*.*\n" );
	
	while (strlen( nb_gets(50, buf) )>0) {
	  printf ("%s\n",buf);
	  nb_puts( 50, "4");	/* ask for next item */
	}

	nb_close( 50 );

int nb_getblock(int stream, char *bytes, int length)

Get a byte block from the stream. Returns the number of bytes effectively read.

Misc Functions

void fputc_lcd(int position, int character)

Put a char un the AD models LCD display (position from 0 to 15)

Probably works in non-expanded mode only

void fputs_lcd( char *text )

Sends a string to the AD models LCD display.

Probably works in non expanded models only

int break_status()

Returns true on an user BREAK request

void warm_reset()

warm_reset: jump to BASIC entry

Works in non-expanded models only

library/newbrain.txt · Last modified: 2017/03/25 08:49 (external edit)