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

zxscreen

v1.0.2

Published

ZX Spectrum Screen Simulator

Downloads

34

Readme

ZX Screen

What is this?

ZXScreen is the result of me challenging myself to write something to display ZX Spectrum graphics in HTML & CSS without using the canvas element. I'm not really sure how useful this is for anyone, and it's not the fastest thing in the world (each 'screen' uses north of 56,000 HTML elements!) - but hey, it works!

You can view a live demo here (works best on desktop browsers)

For the curious - if you're interested in the technical details of the ZX Spectrum display, you can find a pretty good write-up at http://www.breakintoprogram.co.uk/computers/zx-spectrum/screen-memory-layout

How to use

ZXScreen is implemented as an ES module (zxscreen.js in the repo). Simply import it into your project and start using it. It has no dependencies or side effects. I personally recommend using Skypack to do the import:

import * as zxs from 'https://cdn.skypack.dev/zxscreen?min'

Initialising a Screen

To set up a new screen, simply call the screen function. You can optionally pass a container for the screen (defaults to document.body), and an options object where you can specify the pixelSize (defaults to 1), and the initialMemory (defaults to the ZX Screen splash image). The screen function actually returns an object containing the screen's data - container, pixelSize, _mem (array containing the image data) - but you needn't worry about this unless you have cause to use it (possibly for using multiple screens at once - which will probably be extremely slow).

zxs.screen(document.getElementById('zxs'), { pixelSize:2 })

Writing to the Screen

All writing to the screen is done directly by writing bytes to the screen memory - ZXScreen provides no graphics routines for drawing text, lines, etc. These are left as an exercise for the reader 😁

// write a single byte to the screen memory
zxs.poke(address, value)
// write multiple bytes to the screen memory (values should be an array/iterable containing byte data)
zxs.poke$(address, values) 

Both of the memory writing functions take an optional third parameter which is a Screen object returned by the screen function. If omitted, the mostly recently created Screen will be written to.

Utility functions

  • blankScreenMemory - returns an array with a 'blank' screen. Useful in the initialMemory param of the screen function. Has optional parameters attr (specifies the colour attribute for the screen - defaults to 56 - black ink, white background, not bright, not flashing), and fill (specifies the byte value to fill the bitmap portion of the screen with - defaults to 0)
  • ipbfToAttribute - Takes an array of [ink, paper, bright, flash] and converts them to single colour attribute value - bright and flash are optional and default to 0
  • yposMemoryOffset - Takes a y coordinate (0 being top row) and returns the memory offset for the start of that row in the bitmap
  • colIndexToRGB - Should you need it, this function returns the RGB value of the given colour index (0-15)
  • setConfig - Probably not very useful, but allows you to change the configuration of ZX Screen (RGB values for bright/non-bright, memory base address)
  • config - Not a function, but an object containing the current config