Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

Ads

#1 2011-02-14 18:53:57

frax91
New member
Registered: 2011-02-12
Posts: 7

GDK troubles - microtracker

Hi everybody

Last night I've been writting a extremely simple tracker reusing some of the piano.c code.
the idea is to save all the notes played in a array and play the notes in the array when start is pushed


Code:

/*

Compile like this:



..\..\bin\lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -c -o piano.o piano.c

..\..\bin\lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -o piano.gb piano.o



(Same as in make.bat in examples)



*/



#include <gb/gb.h>

#include <stdio.h>

#include <gb/console.h>



void play_note(UBYTE notevalue);



enum notes {

  C0, Cd0, D0, Dd0, E0, F0, Fd0, G0, Gd0, A0, Ad0, B0,

  C1, Cd1, D1, Dd1, E1, F1, Fd1, G1, Gd1, A1, Ad1, B1,

  C2, Cd2, D2, Dd2, E2, F2, Fd2, G2, Gd2, A2, Ad2, B2,

  C3, Cd3, D3, Dd3, E3, F3, Fd3, G3, Gd3, A3, Ad3, B3,

  C4, Cd4, D4, Dd4, E4, F4, Fd4, G4, Gd4, A4, Ad4, B4,

  C5, Cd5, D5, Dd5, E5, F5, Fd5, G5, Gd5, A5, Ad5, B5

};



const UWORD frequencies[] = {

  44, 156, 262, 363, 457, 547, 631, 710, 786, 854, 923, 986,

  1046, 1102, 1155, 1205, 1253, 1297, 1339, 1379, 1417, 1452, 1486, 1517,

  1546, 1575, 1602, 1627, 1650, 1673, 1694, 1714, 1732, 1750, 1767, 1783,

  1798, 1812, 1825, 1837, 1849, 1860, 1871, 1881, 1890, 1899, 1907, 1915,

  1923, 1930, 1936, 1943, 1949, 1954, 1959, 1964, 1969, 1974, 1978, 1982,

  1985, 1988, 1992, 1995, 1998, 2001, 2004, 2006, 2009, 2011, 2013, 2015

};





void main()

{
    int i= 0;
    int track_pointer=0;
    int track[32] = { B5 }; // track array, initiallized on B5

    UBYTE input;        // Variable for joypad data

    NR50_REG = 0x77;    // This turns on sound (Off by default!)

    NR51_REG = 0xFF;    // This turns on sound (Off by default!)

    NR52_REG = 0x80;    // This turns on sound (Off by default!)

    puts("Ver 0.1");
    puts("    -MONOTRACK-");

    while(1){    // Loop forever

        input = joypad();    // Read the joypad
        if(track_pointer!=32) //32 is the max. size of the track
        {

        if(input &J_A){
            printf(" %u", track_pointer);

            puts("-G2");        //print the note
            track[track_pointer]=G2;
            play_note(G2);
            track_pointer=track_pointer+1;

            waitpadup();    // Wait until the button is released

        }
        else if(input &J_B){
            printf(" %u", track_pointer);

            puts("-F2");        // print the note
            track[track_pointer]=F2;
            play_note(F2);
            track_pointer=track_pointer+1;

            waitpadup();    // Wait until the button is released

        }
        else if(input &J_SELECT){
        printf(" %u", track_pointer);
        puts("-A2");
        track[track_pointer]=A2;
        play_note(A2);
        track_pointer=track_pointer+1;
        waitpadup();
        }
        else if(input &J_UP){
        play_note(C2);
        waitpadup();
        }
        }

    if(input & J_START){
                        puts(" ");

            puts("PLAY");        // play message
            i=0;
            while(i<track_pointer) //plays all the notes that the user have entered
            {
            play_note(track[i]);
            i++;
            delay(200);
            }
            waitpadup();

        }

    }

}

void play_note(UBYTE notevalue){

    UBYTE flo, fhi;

    UWORD freq = frequencies[notevalue];



    // Volume envelope

    NR12_REG = 0xF3;    // F=maximum volume, 3=sound fade out

    // Waveform

    NR11_REG = 0xA1;    // 50% square wave

    // Frequency

    flo = (UBYTE)freq & 0xFF;

    fhi = (UBYTE)((freq & 0x0700)>>8);

    NR13_REG = flo;    // Take lower 8 bits from the function argument

    NR14_REG = 0x80 | fhi;

    // Take 3 more bits from the function argument, and set the start bit

}

but now when I try to ad code here

Code:

        else if(input &J_UP){
        play_note(C2);
        waitpadup();
        }

for example

Code:

        else if(input &J_UP){
                printf(" %u", track_pointer);
                puts("-A2");
        play_note(A2);
                track[track_pointer]=A2;
                track_pointer=track_pointer+1;
        waitpadup();
        }

or annything else, it just fails compiling with a bunch of scary "error *** FATAL Compiler Internal Error in file 'asm.c' line number '103' : code generator internal error "
Does anybody know what the F*** happens with this compiler? it seems to fail totally randomly

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson