Skip to content

Instantly share code, notes, and snippets.

@profi200
Created September 29, 2021 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save profi200/1bb9064603553d523dbcc9a5194732f9 to your computer and use it in GitHub Desktop.
Save profi200/1bb9064603553d523dbcc9a5194732f9 to your computer and use it in GitHub Desktop.
#include <inttypes.h>
#include <gba_console.h>
#include <gba_video.h>
#include <gba_interrupt.h>
#include <gba_systemcalls.h>
#include <gba_input.h>
#include <gba_sound.h>
#include <gba_timers.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main(void)
{
// the vblank interrupt must be enabled for VBlankIntrWait() to work
// since the default dispatcher handles the bios flags no vblank handler
// is required
irqInit();
irqEnable(IRQ_VBLANK);
consoleDemoInit();
REG_SOUNDCNT_X = 1u<<7;
REG_SOUNDCNT_H = 2u;
REG_SOUNDCNT_L = 1u<<12 | 1u<<8 | 7u<<4 | 7u;
SNDBIAS = 3u<<14 | 0x200u;
REG_SOUND1CNT_L = 0;
REG_SOUND1CNT_H = 15u<<12 | 2u<<6;
REG_SOUND1CNT_X = 1u<<15; // start
u16 freq = 1000;
bool freqChanged = true;
while(1)
{
const u16 kHeld = REG_KEYINPUT ^ 0xFFFFu;
if(kHeld & KEY_UP) {freq++; freqChanged = true;}
else if(kHeld & KEY_DOWN) {freq--; freqChanged = true;}
if(freqChanged)
{
freqChanged = false;
REG_SOUND1CNT_X = 2048 - (131072 / freq);
iprintf("\rFreq: %05" PRIu16, freq);
}
VBlankIntrWait();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment