Plugin For 8-bit music sounds

I wonder, is it possible for me to make a plugin for 8-bit music instruments? Like the ones that you hear in video game tunes like the ones from Duck Hunt and Super Mario Brothers 1, 2, and 3? If so, how would I make this one?

Yes it’s possible, but not easy.
The number of bits (8-bit) is largely irrelevant to the character of this type of music. More important is the type of synthesized tones, and the character of the tune.
Whether it’s a Nintendo, Commodore, or other early computer sound system, the important thing is that these machines were limited to a small range of waveforms (typically pulse, triangle and noise) and a small number of channels (usually between 3 and 6 channels. Due to the small number of sound channels (small number of sounds that could play at the same time), musical chords were usually played as rapid arpeggios, which is one of the characteristic features of this type of music.

Originally the music would have been composed on a “tracker”, which is an early form of “sequencer”. In Nyquist, the musical score may be written using “Adagio” notation (see: http://www.cs.cmu.edu/~rbd/doc/nyquist/part11.html#index835)

Simple “instruments” may be created as functions, using a single Nyquist oscillator function such as “osc-tri” http://www.cs.cmu.edu/~rbd/doc/nyquist/part8.html#index371) or “osc-pulse” (http://www.cs.cmu.edu/~rbd/doc/nyquist/part8.html#index373) and applying a simple envelope function such as “env” (http://www.cs.cmu.edu/~rbd/doc/nyquist/part8.html#index334)

Here is a very simple and short example using just a triangle wave and two sound channels:

;type generate

(defun my-note (pitch dur)
  (mult (pwlv 0 0.1 0.5 1 0)
        (osc pitch dur *tri-table*)))

(stretch 0.5
(sim
(seq (my-note c5 i) (my-note e5 i) (my-note f5 i) (my-note g5 i) (my-note c5 q))
(seq (my-note c6 q) (my-note b5 i) (my-note a5 i) (my-note e5 q))))

Here’s a couple examples of what I mean.

Yes, lots of work.
Here’s a slightly more complex example:

;type generate

(defun saw (pitch dur)
  (mult (pwlv 0 0.1 0.5 dur 0)
        (osc pitch dur *tri-table*)))

(defun square (pitch dur)
  (let ((hz (step-to-hz pitch)))
    (mult (pwlv 0 0.1 0.5 dur 0)
          (osc-pulse hz 0.5))))

(defun drum (dur)
  (mult (pwev 1 (* 0.1 dur) 0.5 dur 0.1)
        (sim (osc-pulse 194 dur)
             (noise dur))))

(stretch 0.5
  (sim
    (mult 0.3 (seq (square c5 i) (s-rest i)(s-rest s)(square e5 s) (square f5 s) (square g5 i)
                   (s-rest i) (square c5 q) (s-rest i) (square c4 i)))
    (mult 0.2 (seq (saw c6 q) (saw b5 i) (s-rest s) (saw a5 s) (saw e5 q)
                   (saw b5 i) (s-rest s) (saw a5 s)(saw g6 q)))
    (mult 0.1 (seq (drum s)(drum s)(s-rest q)(drum s)(s-rest s)(s-rest q)
                   (drum s)(drum s)(s-rest i)(drum s)(s-rest s)))))

I wonder how I can make a virtual instrument out of this? It seems when I generate the code you’ve posted, I only get a few notes and a few drum samples.

In the code that I posted there are 3 “instruments”, the buzzing “square” instrument, the whistle-like “triangle” instrument, and the noise based “drum” instrument. These are defined in the functions “square”, “saw” and “drum” respectively.
The “drum” instrument takes just one parameter, which is the note duration. The other instruments take two parameters, pitch and duration.
In order to make a tune, you need to devise a way to trigger a sequence of notes from the instruments. I did that in the example by writing three sequences using the SEQ function, and playing them simultaneously using the SIM function. That is clearly not a very user friendly way to input the note sequence. A better way might be to use “string” controls into which the user can type their sequence (for example using a modified version of “Adagio” notation. You would need to write the code to parse the input strings and generate the sound sequence from that data.