Giter VIP home page Giter VIP logo

petrock's Introduction

PET Rock

CI

A spectrum analyzer display for the C64 that receives its data from an ESP32 MCU on the user port that does the audio processing, FFT, etc.

General Idea for Newcomers

The application logic is implemented in petrock.asm. It pulls in a few supporting include files to define symbols, add demo data, and facilitate serial communication.

The application draws 16 vertical bands of the spectrum analyzer which can be up to 16 high. The program first clears the screen, draws the border and text, fills in color, and the main draw loop calls DrawBand for each one in turn. Each frame draws a new set of peaks from the PeakData table, which has 16 entries, one per band. That data is replaced either by a new frame of demo data or an incoming serial packet and the process is repeated, running at about 40 fps.

Color RAM can be filled with different patterns by stepping through the visual styles with the C key, but it is not drawn each and every frame.

Basic bar draw is to walk down the bar and draw a blank (when above the bar), the top of the bar, then the middle pieces, then the bottom. A visual style definition is set that includes all of the PETSCII chars you need to draw a band, like the corners and sides, etc. It can be changed with the S key.

Every frame the serial port is checked for incoming data which is then stored in the SerialBuf. If that fills up without a nul it is reset, but if a nul comess in at the right place (right packet size) and the magic byte matches, it is used as new peakdata and stored in the PeakData table. The code on the ESP32 sends it over as 16 nibbles packed into 8 bytes plus a VU value.

The built-in serial code on the C64 is poor, and serdrv.s contains a new implementation for the C64 that works well for receiving data up to 4800 baud.

Configuring and building

In the settings.inc file, a number of symbols are defined that can be used to configure the build:

Name Possible values Mandatory Meaning
C64 0 or 1 No Configure build for the Commodore 64. Exactly one of C64 or PET must be defined to equal 1.
DEBUG 0 or 1 Yes Set to 1 to enable code that only is included for debug builds.
PET 0 or 1 No Configure build for the PET. Exactly one of C64 or PET must be defined to equal 1.
TIMING 0 or 1 Yes Set to 1 to show timing information concerning the drawing of spectrum analyzer updates. Only supported on the C64 and has not been used for a while, so may need some attention to make it work.

Note that the PET and C64 symbols are not set by default. The reason is that the assembly target is a prime candidate to be set via the command line. Also, on the PET only the demo mode (see below) currently works. The reason is that we're still looking for suitable serial code for audio data ingestion on the PET.

This repository's code targets the ca65 assembler and cl65 linker that are part of the cc65 GitHub project. You will need a fairly recent build of cc65 for assembly of this repository's contents to work. If you receive errors about the .literal mnemonic, this is the likely reason.

With the cc65 toolkit installed and in your PATH, you can build the application using any of the following commands:

  • If the assembly target is set in settings.inc:

    cl65 -o petrock.prg -t none petrock.asm
    
  • For the PET:

    cl65 -o petrock.prg --asm-define PET=1 -t none petrock.asm
    
  • For the Commodore 64:

    cl65 -o petrock.prg --asm-define C64=1 -t none petrock.asm
    

Loading and running

Assuming the petrock.prg file is on a disk in device 8, the spectrum analyzer display can be loaded using the following command:

LOAD "PETROCK.PRG",8

When the application is running, its appearance can be modified by pressing certain keys. Also, a demo mode can be enabled in case no serial input is available.

You can press H to see what key presses are recognized.

6502 assembly

For those who would like more information about the 6502 CPU and/or about writing assembly code for it, the folks at 6502.org have compiled a lot of resources on the topic. Amongst others, there is a page that contains links to tutorials and primers, which itself links to a detailed description of the 6502 opcodes used in the PET clock source code.

petrock's People

Contributors

davepl avatar rbergen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.