npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@chipcode/octopus

v0.3.5

Published

Preprocessing for Octo-flavoured CHIP-8 source files (and other text files)

Downloads

13

Readme

Octopus

This command line tool can do pre-processing on text based input files. It is intended for use with Octo-flavoured CHIP-8 assembly code, but it can be used with any text file.

Installing and running

Install Octopus as an NPM package, either for a project or globally:

npm install --save-dev @chipcode/octopus

You can then run Octopus on the command line:

npx octopus <input file> <output file> <option 1> <option 2>

Or you can use Octopus in your package.json file, for example to build a Cosmac VIP and a SUPERCHIP version of your project:

{
  "scripts": {
    "build": "npm run build-vip && npm run build-schip",
    "build-vip": "octopus ./src/index.8o ./bin/project-vip.8o VIP",
    "build-schip": "octopus ./src/index.8o ./bin/project-schip.8o SCHIP"
  }
}

Which you can then run using:

npm run build

Features

Conditional code inclusion

With Octopus, you can use :if, :unless, :else and :end in your code to switch on options, like so:

: store-values
  i := target
  save v2      # This doesn't increment i on SCHIP
  :if SCHIP    # Conditionally fix that issue
    vF := 3
    i += vF
  :end
  return

Now the conditional code between :if and :end will be included in the target file only if the option SCHIP is set.

Note that you can not use expressions, and options can only be either set (true) or unset (false). To set an option, give it as a parameter to the Octopus invocation or set it with :const (see below).

Here is a more complicated example, also showing the use of :else and :unless (which is basically "if not").

: store-values
  i := target
  :if XOCHIP
    save v3 - v4   # This XO-CHIP opcode doesn't increment i
  :else
    v0 := v3
    v1 := v4
    save v1        # This doesn't increment i on SUPERCHIP
  :end
  :unless VIP      # So on anything but VIP, we need to increment i manually
    vF := 2
    i += vF
  :end
  return

Set, reset and dump options

As described, options can be either set (true) or unset (false). You can set options by providing them to the Octopus invocation on the command line, or in your code with :const. If you set a constant to zero, it will be unset (false) from the perspective of Octopus. Any other value will be considered set (true).

  :if VIP
    :const USE_SCROLLING 0
  :else
    :const USE_SCROLLING 1
  :end

  # ...

  :if USE_SCROLLING
    scroll-down 8
  :end

When you're playing with options, and you run into issues, you can use the :dump-options command to instruct Octopus to output all those options that are set at that point in the program.

  :const OPTION_1 1
  :const OPTION_2 0
  :dump-options

  :const OPTION_2 1
  :dump-options

This will output:

Options on line 3: [ 'OPTION_1' ]
Options on line 6: [ 'OPTION_1', 'OPTION_2' ]

Include other files

When a project gets too large for a single source file, it is nice to be able to split it up into more logical segments. The Octopus :include command allows you to include another file into the current source file.

  :include "renderer.8o"
  :include "images/bitmaps.8o"

Including image files

If you wish to directly include an image file like a PNG file or a JPEG file as one or more sprites, you can do so through the image-loader plugin.

Automatic re-ordering of code

When writing XO-CHIP code, you need to keep the code that executes in the first 3.5K of memory. Beyond that you can have another 60K of data. This is because XO-CHIP does provide an instruction to load a 16-bit address into i (i := long <label>), but no instructions to jump to or call a 16-bit label.

However, when writing code it is much more convenient to be able to keep the code and the data that the code operates on close together. Octopus can automatically solve this issue for you, if you annotate your code with :segment code and :segment data.

Each file is considered to automatically start with :segment code, so you can leave that out if your file does indeed start with executable code.

  i := long table
  load v4
  # Do something intelligent with data...

:segment data

: table
  0 1 2 3 4