#!/usr/bin/env python

import sys
import time
import math

import gameduino

gd = gameduino.Gameduino(sys.argv[1], 115200)

gd.silence()

SOUNDBUFFER = 0x3f00
gd.wr(gameduino.COMM, 0)
if 1:
    gd.voice(0, 0, int(312.5 * 4), 255, 255)
elif 0:
    for i in range(256):
        th = 10 * i * math.pi * 2 / 256
        gd.wr(SOUNDBUFFER + i, 0xff & int(127 * math.sin(th)));
    gd.dump(SOUNDBUFFER, 256)
    gd.microcode(gameduino.readarray("../j1firmware/soundbuffer.binle"))
else:
    for i in range(128):
        th = 1 * i * math.pi * 2 / 128
        gd.wr16(SOUNDBUFFER + 2 * i, 0xffff & int(32767 * math.sin(th)));
    gd.dump(SOUNDBUFFER, 256)
    gd.microcode(gameduino.readarray("../j1firmware/soundbuffer16.binle"))

time.sleep(999)
