c64: presets

This commit is contained in:
Steven Hugg 2023-11-20 15:29:51 -06:00
parent 8091985fde
commit 16fcf33881
4 changed files with 122 additions and 44 deletions

View File

@ -9,6 +9,7 @@ A simple music player.
#include "sidmacros.h" #include "sidmacros.h"
#include <cbm_petscii_charmap.h> #include <cbm_petscii_charmap.h>
#include <6502.h>
// SID frequency table (PAL version) // SID frequency table (PAL version)
const int note_table_pal[96] = { const int note_table_pal[96] = {
@ -149,7 +150,7 @@ void drawParams() {
} }
} }
void setParamValues() { void setSIDRegisters() {
char i; char i;
word val; word val;
char buf[30]; char buf[30];
@ -179,57 +180,61 @@ void setParamValues() {
music_wavebits = buf[0x04]; music_wavebits = buf[0x04];
} }
void tick(int i) { char music_update() {
while (i--) { if (!music_ptr) start_music(music1);
wait_vblank(); play_music();
play_music(); return IRQ_NOT_HANDLED;
}
} }
void handleInput() { void handleInput() {
char key = 0; char key = 0;
char joy = joy_read(0); char joy = joy_read(0);
if (joy == 0) return;
if (JOY_UP(joy)) key = 'i'; if (JOY_UP(joy)) key = 'i';
if (JOY_DOWN(joy)) key = 'k'; if (JOY_DOWN(joy)) key = 'k';
if (JOY_LEFT(joy)) key = 'j'; if (JOY_LEFT(joy)) key = 'j';
if (JOY_RIGHT(joy)) key = 'l'; if (JOY_RIGHT(joy)) key = 'l';
switch (key) { switch (key) {
case 'i': // UP case 'i': // UP
if (currentParam > 0) { if (currentParam > 0) {
--currentParam; --currentParam;
drawValue(currentParam+1); drawValue(currentParam+1);
drawValue(currentParam); drawValue(currentParam);
tick(3); }
} break;
break; case 'k': // DOWN
case 'k': // DOWN if (currentParam < NPARAMS - 1) {
if (currentParam < NPARAMS - 1) { ++currentParam;
++currentParam; drawValue(currentParam-1);
drawValue(currentParam-1); drawValue(currentParam);
drawValue(currentParam); }
tick(3); break;
} case 'j': // LEFT
break; if (paramValues[currentParam] > SID_PARAMS[currentParam].low) {
case 'j': // LEFT paramValues[currentParam]--;
if (paramValues[currentParam] > SID_PARAMS[currentParam].low) { drawValue(currentParam);
paramValues[currentParam]--; setSIDRegisters();
drawValue(currentParam); }
setParamValues(); break;
} case 'l': // RIGHT
break; if (paramValues[currentParam] < SID_PARAMS[currentParam].high) {
case 'l': // RIGHT paramValues[currentParam]++;
if (paramValues[currentParam] < SID_PARAMS[currentParam].high) { drawValue(currentParam);
paramValues[currentParam]++; setSIDRegisters();
drawValue(currentParam); }
setParamValues(); break;
} }
break; // delay a few frames to slow down movement
} waitvsync();
waitvsync();
waitvsync();
} }
void main(void) void main(void)
{ {
joy_install (joy_static_stddrv); joy_install (joy_static_stddrv);
// set initial SID parameters
paramValues[0] = 15; paramValues[0] = 15;
paramValues[1] = 8; paramValues[1] = 8;
paramValues[2] = 8; paramValues[2] = 8;
@ -237,14 +242,19 @@ void main(void)
paramValues[4] = 4; paramValues[4] = 4;
paramValues[5] = 4; paramValues[5] = 4;
paramValues[7] = 1; // pulse paramValues[7] = 1; // pulse
setSIDRegisters();
// draw the UI
drawParams(); drawParams();
setParamValues();
// set IRQ routine called every frame
set_irq(music_update, (void*)0x9f00, 0x100);
// main loop to handle UI
music_ptr = 0; music_ptr = 0;
while (1) { while (1) {
waitvsync();
handleInput(); handleInput();
if (!music_ptr) start_music(music1);
tick(1);
} }
} }

View File

@ -3,6 +3,7 @@
//#link "common.c" //#link "common.c"
#include <tgi.h> #include <tgi.h>
#include <6502.h>
//#resource "c64-sid.cfg" //#resource "c64-sid.cfg"
#define CFGFILE c64-sid.cfg #define CFGFILE c64-sid.cfg
@ -57,6 +58,11 @@ void show_envelope() {
if (++sweep == 320) sweep = 0; if (++sweep == 320) sweep = 0;
} }
char music_update() {
sid_update();
return IRQ_NOT_HANDLED;
}
void main(void) { void main(void) {
// install TGI graphics driver // install TGI graphics driver
tgi_install(tgi_static_stddrv); tgi_install(tgi_static_stddrv);
@ -71,6 +77,9 @@ void main(void) {
// install joystick driver // install joystick driver
joy_install(joy_static_stddrv); joy_install(joy_static_stddrv);
// set IRQ routine called every frame
set_irq(music_update, (void*)0x9f00, 0x100);
while (1) { while (1) {
// play sound effect when joystick is moved // play sound effect when joystick is moved
byte joy = joy_read(0); byte joy = joy_read(0);
@ -81,8 +90,6 @@ void main(void) {
} }
// sync with frame rate // sync with frame rate
waitvsync(); waitvsync();
// update SID player
sid_update();
// update graphs // update graphs
show_envelope(); show_envelope();
show_signal(); show_signal();

60
presets/c64/test_setirq.c Normal file
View File

@ -0,0 +1,60 @@
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <peekpoke.h>
#include <string.h>
#include <c64.h>
#include <cbm_petscii_charmap.h>
#include "common.h"
//#link "common.c"
#include <6502.h>
#include <setjmp.h>
char interrupt_handler() {
// only needed if CIA interupts are still active
if (!(VIC.irr & VIC_IRR_IRST)) return IRQ_NOT_HANDLED;
// change colors so we can see where the IRQ fired
VIC.bgcolor0++;
VIC.bordercolor++;
// reading VIC.rasterline returns the current line
// setting it changes the line where the IRQ fires
if (VIC.rasterline >= 245) {
VIC.rasterline = 40;
} else {
VIC.rasterline = 245;
}
// acknowledge VIC raster interrupt (bit 0)
VIC.irr = 1;
// change colors back to where they were
VIC.bgcolor0--;
VIC.bordercolor--;
return IRQ_HANDLED;
}
void set_frame_irq(char scanline) {
// deactivate CIA interrupts (keyboard, etc)
CIA1.icr = 0x7f;
// set raster line for interrupt
VIC.ctrl1 &= 0x7f; // clear raster line bit 8
VIC.rasterline = scanline;
// activate VIC raster interrupts
VIC.imr = 1;
}
void main(void) {
clrscr();
printf("\nHello World!\n");
// set interrupt routine
set_irq(interrupt_handler, (void*)0x9f00, 0x100);
// disable CIA interrupt, activate VIC interrupt
set_frame_irq(255);
while (1) {
printf("%d ", VIC.rasterline);
}
}

View File

@ -10,7 +10,8 @@ const C64_PRESETS : Preset[] = [
{id:'joymove.c', name:'Sprite Movement'}, {id:'joymove.c', name:'Sprite Movement'},
{id:'sprite_collision.c', name:'Sprite Collision'}, {id:'sprite_collision.c', name:'Sprite Collision'},
{id:'scroll1.c', name:'Scrolling (Single Buffer)'}, {id:'scroll1.c', name:'Scrolling (Single Buffer)'},
{id:'test_display_list.c', name:'Display List / Raster IRQ'}, {id:'test_setirq.c', name:'Raster Interrupts'},
{id:'test_display_list.c', name:'Raster IRQ Library'},
{id:'scrolling_text.c', name:'Big Scrolling Text'}, {id:'scrolling_text.c', name:'Big Scrolling Text'},
{id:'side_scroller.c', name:'Side-Scrolling Game'}, {id:'side_scroller.c', name:'Side-Scrolling Game'},
{id:'scroll2.c', name:'Scrolling (Double Buffer)'}, {id:'scroll2.c', name:'Scrolling (Double Buffer)'},