nimgobus

package
v0.0.0-...-68482a3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2022 License: Apache-2.0, Apache-2.0 Imports: 22 Imported by: 0

README

nimgobus

An RM Nimbus-inspired Ebiten extension for building retro apps and games in Go.

Nimgobus is a tribute project and is in no way linked to or endorsed by RM plc.

About

Nimgobus is an extension of the excellent Ebiten game engine. It mimicks the 16-bit graphics and text drivers of the RM Nimbus PC186, found in classrooms all over the UK in the 1980s and early 90s. With Nimgobus you can develop Go applications that have the 16 colour charm of classic Nimbus software such as PaintSPA, Ourfacts and Caxton Press. However, it is not an emulation of the Nimbus itself. This means you get the best of both worlds:

  • Cutting-edge Go computing power, beautifully presented in up to 16 colours
  • Build for Linux, Windows, Mobile and Web thanks to Ebiten's cross-platform support
  • Embed a Nimbus as a component within another user interface (if you really want to go nuts)

Usage

Nimgobus generates a screen image that can be embedded in an Ebiten application. First add Nimgobus to your Game struct:

type Game struct {
	count           int
	// ...
	nimgobus.Nimbus // Embed the Nimbus in the Game struct
}

In your NewGame() function, initialize the Nimbus before sending any commands to it:

func NewGame() *Game {
	game := &Game{}
	// ...
	game.Init() // Initialize Nimgobus
	return game
}

In the Update() function add a call to update the Nimbus monitor screen:

func (g *Game) Update() error {
	// ...
	g.Nimbus.Update() // Update the app on all subsequent iterations
	// ...
	return nil
}

The Nimbus screen can be retrieved like this:

img := g.Monitor

And commands sent like this:

g.Cls()
g.Print("Even a stopped clock gives the right time twice a day.")

See the examples below for working examples to get you started.

Syntax

For the sake of authenticity the syntax used in nimgobus is influenced by RM Basic (the Basic interpreter supplied with the original Nimbus), including the way screen coordinates are handled. It is therefore highly recommended to read the original documentation for RM Basic (see links).

Some commands have been implement in nimgobus in exactly they same way as in RM Basic. Optional arguments, which were used extensively in RM Basic (for example BRUSH, DIRECTION, FONT in the PLOT command) are not so easily reproduced because Go does not support functions with optional parameters. Where optional parameters are used by functions in RM Basic, nimgobus instead accepts an 'options' struct as a parameter. In some cases this has rendered obsolete RM Basic features that set default values for BRUSH, FONT, etc.

Examples

greeting.go

greeting

modes.go

modes

isstracker.go

isstracker

Acknowledgements

Thanks to Peter Hellberg for suggestions and improvements.

Documentation

Overview

Package nimgobus is RM Nimbus-inspired Ebiten extension for building building retro apps and games in Go. It mimicks the 16-bit graphics and text drivers of the RM Nimbus PC186, found in classrooms all over the UK in the 1980s and early 90s.

With Nimgobus you can develop Go applications that have the cheesey and often 'chromatically challenging' look and feel of classic Nimbus software such as PaintSPA, Ourfacts and Caxton Press.

Nimgobus is a tribute project and is in no way linked to or endorsed by RM plc.

For more background and working examples see https://github.com/adamstimb/nimgobus

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AreaOptions

type AreaOptions struct {
	Brush     int
	Over      int
	FillStyle FillStyle
}

type CircleOptions

type CircleOptions struct {
	Brush     int
	Over      int
	FillStyle FillStyle
}

type FileObj

type FileObj struct {
	File    *os.File
	Writing bool
}

FileObj describes a file object and whether its for writing or reading

type FillStyle

type FillStyle struct {
	Style    int // 1 for solid/dithered, 2 for hatched, 3 for hollow (edge)
	Hatching int // Hatching type if Style==2
	Colour2  int // 2nd hatching colour if Style==2
}

FillStyle describes the fill settings for AREA, FLOOD, CIRCLE, and SLICE

type FloodOptions

type FloodOptions struct {
	Brush         int
	UseEdgeColour bool
	EdgeColour    int
	FillStyle     FillStyle
}

type LineOptions

type LineOptions struct {
	Brush     int
	Font      int
	Direction int
	SizeX     int
	SizeY     int
	Over      int
}

type Nimbus

type Nimbus struct {
	PaddingX int
	PaddingY int
	Scale    float64
	Monitor  *ebiten.Image // The Monitor image including background

	MouseX      int  // Mouse position and button press
	MouseY      int  //
	MouseButton int  //
	MouseOn     bool //

	BreakInterruptDetected bool             // Flag is set to true if user makes a <BREAK>
	FileChannels           map[int]*FileObj // File channels and their objects are stored here when they're opened/created
	// contains filtered or unexported fields
}

Nimbus acts as a container for all the components of the Nimbus monitor. You only need to call the Init() method after declaring a new Nimbus.

func (*Nimbus) AdvanceCursor

func (n *Nimbus) AdvanceCursor(forceCarriageReturn bool)

AdvanceCursor moves the cursor forward and handles line feeds and carriage returns

func (*Nimbus) Area

func (n *Nimbus) Area(opt AreaOptions, coordList []XyCoord)

Area draws a filled polygon of coordinates on the screen

func (*Nimbus) AskBlocksize

func (n *Nimbus) AskBlocksize(b int) (width, height, mode int)

AskBlocksize returns the width, height and original screen mode of an image block

func (*Nimbus) AskCurpos

func (n *Nimbus) AskCurpos() (int, int)

AskCurpos returns the current cursor position within the selected text box

func (*Nimbus) AskDrawing

func (n *Nimbus) AskDrawing(p ...int) (slot, x1, y1, x2, y2 int)

AskDrawing returns the current drawingbox slot and it's boundaries

func (*Nimbus) AskFillStyle

func (n *Nimbus) AskFillStyle() FillStyle

AskFillStyle gets the current fill style

func (*Nimbus) AskMode

func (n *Nimbus) AskMode() int

AskMode returns the current screen mode (40 column or 80 column)

func (*Nimbus) AskSound

func (n *Nimbus) AskSound() bool

AskSound returns true if the sound engine is on

func (*Nimbus) AskVoice

func (n *Nimbus) AskVoice() int

AskVoice returns the selected voice

func (*Nimbus) AskWriting

func (n *Nimbus) AskWriting(p ...int) (slot, col1, row1, col2, row2 int)

AskWriting returns the current textbox slot and it's boundaries

func (*Nimbus) Bell

func (n *Nimbus) Bell()

Bell makes the Nimbus bell sound

func (*Nimbus) Boot

func (n *Nimbus) Boot()

Boot simulates the RM Nimbus "Welcome" boot screen and operating system loading workflow. The original Nimbus would also display system info, such as firmware version, serial number, memory, etc. Nimgobus immitates this using the Go compiler version as the firmware version, and displays the actual physical and virtual memory size. Serial number is a string constant as is the serial number of the Nimbus that provided the ROM dump for the emulation on MAME, from which various bits and pieces were reversed engineering for nimgobus.

func (*Nimbus) Circle

func (n *Nimbus) Circle(opt CircleOptions, r, x, y int)

Circle draws a a filled circle

func (*Nimbus) Clearblock

func (n *Nimbus) Clearblock()

Clearblock resets all the image blocks

func (*Nimbus) Clg

func (n *Nimbus) Clg()

Clg clears the selected drawingbox

func (*Nimbus) Cls

func (n *Nimbus) Cls(p ...int)

Cls clears the selected textbox if no parameters are passed, or clears another textbox if one parameter is passed

func (*Nimbus) Delblock

func (n *Nimbus) Delblock(b int)

Delblock "deletes" an image block by setting it's deleted flag to true

func (*Nimbus) Fetch

func (n *Nimbus) Fetch(b int, path string) bool

Fetch receives an image, downsamples the number of colours to 4 or 16 depending on current screen mode, and assigns it to a Nimbus image block

func (*Nimbus) Flood

func (n *Nimbus) Flood(opt FloodOptions, coord XyCoord)

Flood seeds a boundary fill at x, y

func (*Nimbus) ForceRedraw

func (n *Nimbus) ForceRedraw()

ForceRedraw forces the monitor to redraw in the case of, for example, change of border colour

func (*Nimbus) Get

func (n *Nimbus) Get() int

Get returns a single character code input from the keyboard. If no key was pressed then -1 is returned.

func (*Nimbus) GetPixel

func (n *Nimbus) GetPixel(x, y int) (colour int)

getPixel waits until the drawQueue is empty gets the colour of a pixel in the video memory

func (*Nimbus) Init

func (n *Nimbus) Init()

Init initializes a new Nimbus. You must call this method after declaring a new Nimbus variable.

func (*Nimbus) Input

func (n *Nimbus) Input(prepopulateBuffer string) string

Input receives keyboard input into a string of up to 256 chars and returns the string when ENTER is pressed. The user can edit the string using the delete key and left and right arrow keys. A prompt is printed on the screen at the current cursor position and the user's input is echoed to screen after the prompt. The input buffer can also be pre-populated.

func (*Nimbus) Keep

func (n *Nimbus) Keep(b int, format, path string) error

Keep saves an image block b with a specific format

func (*Nimbus) Line

func (n *Nimbus) Line(opt LineOptions, coordList []XyCoord)

Line draws a list of coordinates on the screen connected by lines

func (*Nimbus) Note

func (n *Nimbus) Note(pitch1, pitch2, duration, volume, envelope int) bool

func (*Nimbus) PlayQueues

func (n *Nimbus) PlayQueues()

PlayQueue plays all the notes in all the queues

func (n *Nimbus) PlonkLogo(x, y int)

PlonkLogo draws the RM Nimbus logo

func (*Nimbus) Plot

func (n *Nimbus) Plot(opt PlotOptions, text string, x, y int)

Plot draws a string of characters on the paper at a given location with the colour, size and orientation of your choice.

func (*Nimbus) Points

func (n *Nimbus) Points(opt PointsOptions, coordList []XyCoord)

Points draws points at some given coordinates on the screen

func (*Nimbus) Print

func (n *Nimbus) Print(s string)

Print

func (*Nimbus) Put

func (n *Nimbus) Put(c int)

Put draws an ASCII char at the cursor position

func (*Nimbus) Queue

func (n *Nimbus) Queue(v int) int

Queue returns the number of free slots in a voice queue

func (*Nimbus) Readblock

func (n *Nimbus) Readblock(b, x1, y1, x2, y2 int)

Readblock reads an area x1, y1, x2, y2 of the screen into block b

func (*Nimbus) SetBorder

func (n *Nimbus) SetBorder(c int)

SetBorder sets the borderColour

func (*Nimbus) SetColour

func (n *Nimbus) SetColour(paletteSlot, basicColour, flashSpeed, flashColour int)

SetColour assigns one of the basic colours to a slot in the current palette

func (*Nimbus) SetCurpos

func (n *Nimbus) SetCurpos(col, row int)

SetCurpos sets the cursor position within the selected text box

func (*Nimbus) SetCursor

func (n *Nimbus) SetCursor(p ...int)

SetCursor changes the cursor state. Between 1 and 3 parameters can be passed. The first parameter sets the cursor mode (< 0 for invisible cursor, 0 for flashing cursor, > 0 for visible cursor without flashing), the second parameter sets the ASCII code of the cursor char, the third parameter sets the charset of the cursor char.

func (*Nimbus) SetDrawing

func (n *Nimbus) SetDrawing(p ...int)

SetDrawing selects a drawingbox if only 1 parameter is passed (index), or defines a drawingbox if 5 parameters are passed (index, col1, row1, col2, row2)

func (*Nimbus) SetEnvelope

func (n *Nimbus) SetEnvelope(slot, attackTime, attackLevel, decayTime, decayLevel,
	sustainTime, sustainLevel, releaseTime int)

func (*Nimbus) SetFillStyle

func (n *Nimbus) SetFillStyle(style, hatching, colour2 int)

SetFillStyle sets the fill style for AREA, CIRCLE, SLICE and FLOOD

func (*Nimbus) SetMode

func (n *Nimbus) SetMode(columns int)

SetMode sets the screen mode. 40 is low-resolution, high-colour mode (320x250) and 80 is high-resolutions, low-colour mode (640x250)

func (*Nimbus) SetMouse

func (n *Nimbus) SetMouse(mouseOn bool)

SetMouse turns the mouse monitor on (true) or turns it off (false)

func (*Nimbus) SetPaper

func (n *Nimbus) SetPaper(c int)

SetPaper sets paperColour

func (*Nimbus) SetPattern

func (n *Nimbus) SetPattern(slot, row, c1, c2, c3, c4 int)

SetPattern defines the user-definable patterns

func (*Nimbus) SetPen

func (n *Nimbus) SetPen(c int)

SetPen sets penColour

func (*Nimbus) SetSound

func (n *Nimbus) SetSound(v bool)

SetSound turns the sound engine on and off

func (*Nimbus) SetTone

func (n *Nimbus) SetTone(t bool)

func (*Nimbus) SetVoice

func (n *Nimbus) SetVoice(v int)

func (*Nimbus) SetWriting

func (n *Nimbus) SetWriting(p ...int)

SetWriting selects a textbox if only 1 parameter is passed (index), or defines a textbox if 5 parameters are passed (index, col1, row1, col2, row2)

func (*Nimbus) Squash

func (n *Nimbus) Squash(b, x, y int, over bool)

Squash is the same as Writeblock but scales the image by 1/4

func (*Nimbus) Update

func (n *Nimbus) Update(PaddingX, PaddingY int, Scale float64)

Update is called by every game.Update()

func (*Nimbus) ValidateBrush

func (n *Nimbus) ValidateBrush(c int) bool

ValidateBrush validates if a colour/palette slot is valid for the current screen mode

func (*Nimbus) ValidateColour

func (n *Nimbus) ValidateColour(c int) bool

ValidateColour validates if a colour/palette slot is valid for the current screen mode

func (*Nimbus) ValidateStyle

func (n *Nimbus) ValidateStyle(s int) bool

ValidateStyle validates if a style slot is valid

func (*Nimbus) Writeblock

func (n *Nimbus) Writeblock(b, x, y int, over bool)

Writeblock draws an image block on the screen at position x, y

type PlotOptions

type PlotOptions struct {
	Brush     int
	Font      int
	Direction int
	SizeX     int
	SizeY     int
	Over      int
}

type PointsOptions

type PointsOptions struct {
	Style int
	Brush int
	Over  int
}

type Sprite

type Sprite struct {
	// contains filtered or unexported fields
}

Sprite defines a sprite that contains a 2d image array, a screen co-ordinate, colour and overwrite (XOR) mode

type XyCoord

type XyCoord struct {
	X int
	Y int
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL