Fixed this song to work with renamed commands('@' and 'i').
[pineappletracker.git] / main.c
blob9814abab00eaf415b35c5d8f81e989ae7ca0873b
1 #include <stdio.h>
2 #include <err.h>
3 #include <SDL/SDL.h>
5 #include "stuff.h"
7 const u16 instrptr[] = {
8 0, 1
9 };
11 const u8 instrdata[] = {
12 0, 0,
13 'v', 255, 'm', 0x11, '+', 0, 'w', WF_PUL, 'f', 0xef, 't', 8, 'f', 0xfc, 0, 0, // lead
14 'v', 255, 'w', WF_NOI, 't', 2, '+', 0, 'w', WF_SAW, 'f', 0xef, 't', 8, 'f', 0, 't', 12, '~', 0x37, 'f', 0xfc, 0, 0, // lead+vibr
15 'v', 255, 'w', WF_NOI, 't', 2, 'm', 0x11, '+', 12, 'w', WF_PUL, 'f', 0xfc, 't', 2, '+', 7, 't', 2, '+', 3, 't', 2, '+', 0, 't', 2, 'j', 5, 0, 0, // arp
16 'v', 255, 'w', WF_NOI, 't', 2, 'd', 0x80, '+', 0, 'w', WF_PUL, 'l', 0x80, 't', 12, 'v', 0, 0, 0 // bass drum
19 const struct track trackdata = {
21 {12*3+0, 1, {'i', 0}, {0xff, 0}},
22 {12*2+0, 1, {0, 0}, {0, 0}},
23 {12*3+0, 1, {0, 0}, {0, 0}},
24 {12*3+3, 1, {0, 0}, {0, 0}},
25 {12*2+0, 1, {0, 0}, {0, 0}},
26 {12*3+3, 1, {0, 0}, {0, 0}},
27 {12*3+2, 1, {0, 0}, {0, 0}},
28 {12*2+0, 1, {0, 0}, {0, 0}},
29 {12*3+7, 1, {0, 0}, {0, 0}},
30 {12*2+0, 1, {0, 0}, {0, 0}},
31 {12*3+3, 1, {0, 0}, {0, 0}},
32 {12*2+0, 1, {0, 0}, {0, 0}},
33 {12*3+2, 1, {0, 0}, {0, 0}},
34 {12*2+0, 1, {0, 0}, {0, 0}},
35 {12*2+10, 1, {0, 0}, {0, 0}},
36 {12*2+0, 1, {0, 0}, {0, 0}},
37 {12*3+0, 1, {0, 0}, {0, 0}},
38 {12*2+0, 1, {0, 0}, {0, 0}},
39 {12*3+0, 1, {0, 0}, {0, 0}},
40 {12*3+3, 1, {0, 0}, {0, 0}},
41 {12*2+0, 1, {0, 0}, {0, 0}},
42 {12*3+3, 1, {0, 0}, {0, 0}},
43 {12*3+7, 1, {0, 0}, {0, 0}},
44 {12*3+8, 1, {0, 0}, {0, 0}},
45 {12*3+5, 1, {0, 0}, {0, 0}},
46 {12*3+7, 1, {0, 0}, {0, 0}},
47 {12*3+3, 1, {0, 0}, {0, 0}},
48 {12*3+2, 1, {0, 0}, {0, 0}},
49 {12*2+0, 1, {0, 0}, {0, 0}},
50 {12*2+10, 1, {0, 0}, {0, 0}},
51 {12*2+7, 1, {0, 0}, {0, 0}},
52 {12*3+2, 1, {0, 0}, {0, 0}},
56 void audiocb(void *userdata, Uint8 *buf, int len) {
57 int i;
59 for(i = 0; i < len; i++) {
60 buf[i] = interrupthandler();
64 int main(int argc, char **argv) {
65 SDL_AudioSpec requested, obtained;
66 FILE *ztlog;
68 ztlog = fopen("ztlog","w");
70 if (SDL_Init( SDL_INIT_AUDIO | SDL_INIT_JOYSTICK ) < 0) {
71 fprintf(ztlog, "Couldn't initialize SDL: %s\n", SDL_GetError());
72 exit(1);
75 initjoystick();
77 fprintf(ztlog, "%i joysticks were found.\n\n", SDL_NumJoysticks() );
78 fprintf(ztlog, "The names of the joysticks are:\n");
80 int i;
81 for( i=0; i < SDL_NumJoysticks(); i++ ) {
82 fprintf(ztlog," %s\n", SDL_JoystickName(i));
85 atexit(SDL_Quit);
87 requested.freq = 16000;
88 requested.format = AUDIO_U8;
89 requested.samples = 256;
90 requested.callback = audiocb;
91 requested.channels = 1;
93 // comment this out to run on grace
94 /*if(SDL_OpenAudio(&requested, &obtained) == -1) {
95 err(1, "SDL_OpenAudio");
96 }*/
98 // Actually if we don't do error checking it just works on grace and
99 // // locally with sound :3
100 SDL_OpenAudio(&requested, &obtained);
102 fprintf(stderr, "freq %d\n", obtained.freq);
103 fprintf(stderr, "samples %d\n", obtained.samples);
105 initchip();
106 initgui();
108 if(argc != 2) {
109 loadfile("untitled.song");
110 } else {
111 loadfile(argv[1]);
114 SDL_PauseAudio(0);
116 guiloop();
118 return 0;