1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-29 14:51:17 +00:00
8bitworkshop/presets/c64/siddemo.c

94 lines
2.0 KiB
C
Raw Normal View History

2022-08-09 19:39:27 +00:00
#include "common.h"
//#link "common.c"
2022-08-11 20:27:20 +00:00
#include <tgi.h>
//#resource "c64-sid.cfg"
#define CFGFILE c64-sid.cfg
//#resource "sidmusic1.bin"
//#link "sidplaysfx.ca65"
#include "sidplaysfx.h"
2022-08-11 20:27:20 +00:00
static const unsigned char Palette[2] =
{ TGI_COLOR_BLUE, TGI_COLOR_WHITE };
static int sweep = 0;
#define BITMAP_START 0xe020
// recursive macros to quickly set bitmap memory
#define SID_SIGNAL_4(index) \
POKE(BITMAP_START + (index) + 0, SID.noise); \
POKE(BITMAP_START + (index) + 1, SID.noise); \
POKE(BITMAP_START + (index) + 2, SID.noise); \
POKE(BITMAP_START + (index) + 3, SID.noise);
#define SID_SIGNAL_16(index) \
SID_SIGNAL_4(index); \
SID_SIGNAL_4(index+4); \
SID_SIGNAL_4(index+8); \
SID_SIGNAL_4(index+12);
#define SID_SIGNAL_64(index) \
SID_SIGNAL_16(index); \
SID_SIGNAL_16(index+16); \
SID_SIGNAL_16(index+32); \
SID_SIGNAL_16(index+48);
void show_signal() {
// push SID voice 3 signal to screen memory
// as fast as we can
SID_SIGNAL_64(0);
SID_SIGNAL_64(64);
SID_SIGNAL_64(128);
SID_SIGNAL_64(192);
}
void show_envelope() {
// read envelope value and plot vertical lines
// via TGI library
byte value = 199 - (SID.read3 >> 1);
tgi_setcolor(0);
tgi_line(sweep, 199 - 128, sweep, value - 1);
tgi_setcolor(1);
tgi_line(sweep, value, sweep, 240);
if (++sweep == 320) sweep = 0;
}
void main(void) {
2022-08-11 20:27:20 +00:00
// install TGI graphics driver
tgi_install(tgi_static_stddrv);
tgi_init();
tgi_clear();
tgi_setpalette(Palette);
// initialize SID player
sid_init(0);
sid_start();
2022-08-11 20:27:20 +00:00
// install joystick driver
joy_install(joy_static_stddrv);
while (1) {
2022-08-11 20:27:20 +00:00
// play sound effect when joystick is moved
byte joy = joy_read(0);
if (joy) {
sid_sfx(joy & 3);
2022-08-11 20:27:20 +00:00
// exit when fire button pressed
if (JOY_BTN_1(joy)) { break; }
}
2022-08-11 20:27:20 +00:00
// sync with frame rate
waitvsync();
2022-08-11 20:27:20 +00:00
// update SID player
2022-07-20 19:32:47 +00:00
sid_update();
2022-08-11 20:27:20 +00:00
// update graphs
show_envelope();
show_signal();
}
2022-08-11 20:27:20 +00:00
tgi_uninstall();
sid_stop();
}