Permalink
Browse files

play the song

  • Loading branch information...
jkotlinski committed Jun 24, 2018
1 parent b1a71eb commit 4314159836c46d1838a3408f729f9087aec9829f
Showing with 68 additions and 2 deletions.
  1. +20 −0 input.h
  2. +48 −2 lsdpack.cpp
20 input.h
@@ -0,0 +1,20 @@
#pragma once

#include "inputgetter.h"

enum Button { A = 0x01, B = 0x02, SELECT = 0x04, START = 0x08,
RIGHT = 0x10, LEFT = 0x20, UP = 0x40, DOWN = 0x80 };

struct Input : public gambatte::InputGetter {
Input() : pressed(0) {}

virtual unsigned operator()() {
return pressed;
}

void press(unsigned button) {
pressed = button;
}

unsigned pressed;
};
@@ -1,12 +1,58 @@
#include <cstdio>

#include "libgambatte/include/gambatte.h"
#include "gambatte.h"

#include "input.h"

gambatte::GB gameboy;
Input input;

void run_one_frame() {
size_t samples = 35112;
long unsigned int audioBuffer[35112 + 2064];
gameboy.runFor(0, 0, &audioBuffer[0], samples);
}

void wait(int seconds) {
for (int i = 0; i < 60 * seconds; ++i) {
run_one_frame();
}
}

void press(unsigned key, int seconds = 1) {
input.press(key);
wait(seconds);
}

void go_to_file_load() {
press(SELECT | UP);
press(DOWN);
press(A);
press(0);
press(A);
press(0);
}

void load_first_entry() {
press(UP, 2); // scroll to top
press(0);
press(A, 10); // wait or song load
press(0);
}

void play_song() {
input.press(START);
}

int main(int argc, char* argv[]) {
if (argc != 2) {
fprintf(stderr, "usage: lsdpack <lsdj.gb>");
return 1;
}
gambatte::GB gameboy;
gameboy.setInputGetter(&input);
gameboy.load(argv[1]);

go_to_file_load();
load_first_entry();
play_song();
}

0 comments on commit 4314159

Please sign in to comment.