diff --git a/CHANGELOG.txt b/CHANGELOG.txt index dfda3b5..f68c6c2 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,8 @@ ToneMatrix changelog: +0.92: + - Fixed some things in the code + 0.9: - Added save song and load song functions - Changed from 12 grids to 16 grids diff --git a/src/EBOOT.PBP b/src/EBOOT.PBP new file mode 100644 index 0000000..e52ece6 Binary files /dev/null and b/src/EBOOT.PBP differ diff --git a/src/Makefile b/src/Makefile index f1a710c..a69f680 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,5 @@ TARGET = tm -OBJS = main.o draw.o file.o menu.o misc.o sound.o +OBJS = draw.o file.o grid.o main.o menu.o misc.o rhythm.o sound.o CFLAGS = -G4 -Wall -O2 CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti @@ -10,7 +10,7 @@ BUILD_PRX = 1 LIBS = -losl -lc -ljpeg -lpng -lz -lpspsdk -lpspctrl -lpspumd -lpsprtc -lpsppower -lpspgu -lpspgum -lpsphprm -lpspaudiolib -lpspaudio -lm EXTRA_TARGETS = EBOOT.PBP -PSP_EBOOT_TITLE = ToneMatrix 0.9 +PSP_EBOOT_TITLE = ToneMatrix 0.93 PSP_EBOOT_ICON = ICON0.PNG PSPSDK=$(shell psp-config --pspsdk-path) diff --git a/src/PARAM.SFO b/src/PARAM.SFO new file mode 100644 index 0000000..c25cfae Binary files /dev/null and b/src/PARAM.SFO differ diff --git a/src/draw.c b/src/draw.c index 817d29f..606f4f4 100644 --- a/src/draw.c +++ b/src/draw.c @@ -2,6 +2,30 @@ * Copyright (c) 2012 Tanner Babcock */ #include #include "main.h" +#include "draw.h" + +int tmGetColor(char gridval, int x, int y) { + int c = 0; + if (tmMuteEmpty(mute) || solo == 0) { + switch (gridval) { + case OFF: case CURSOFF: c = (x == col) ? HOFF : OFFC; break; + case ON: case CURSON: c = (x == col) ? HON : ONC; break; + } + } + if (mute[y-1] && solo == 0) { + switch (gridval) { + case OFF: case CURSOFF: c = (x == col) ? MHOFF : MOFF; break; + case ON: case CURSON: c = (x == col) ? MHON : MON; break; + } + } + if (solo == y && tmMuteEmpty(mute)) { + switch (gridval) { + case OFF: case CURSOFF: c = (x == col) ? SHOFF : SOFF; break; + case ON: case CURSON: c = (x == col) ? SHON : SON; break; + } + } + return c; +} // GOLD void tmDrawGrid(void) { @@ -9,49 +33,9 @@ void tmDrawGrid(void) { oslDrawFillRect(0, 15, 480, 255, RGBA(0, 0, 0, 255)); for (x = 1; x < (MAX_X+1); x++) { for (y = 1; y < (MAX_Y+1); y++) { - if (tmMuteEmpty(mute) || solo == 0) { - if (data[current].grid[x-1][y-1] == OFF) - oslDrawFillRect(x1form, y1form, x2form, y2form, (x == col) ? HOFF : OFFC); - else if (data[current].grid[x-1][y-1] == ON) - oslDrawFillRect(x1form, y1form, x2form, y2form, (x == col) ? HON : ONC); - else if (data[current].grid[x-1][y-1] == CURSOFF) { - oslDrawFillRect(x1form, y1form, x2form, y2form, (x == col) ? HOFF : OFFC); - oslDrawImageXY(select, x1form, y1form); - } - else if (data[current].grid[x-1][y-1] == CURSON) { - oslDrawFillRect(x1form, y1form, x2form, y2form, (x == col) ? HON : ONC); - oslDrawImageXY(select, x1form, y1form); - } - } - if (mute[y-1] && solo == 0) { - if (data[current].grid[x-1][y-1] == OFF) - oslDrawFillRect(x1form, y1form, x2form, y2form, (x == col) ? MHOFF : MOFF); - else if (data[current].grid[x-1][y-1] == ON) - oslDrawFillRect(x1form, y1form, x2form, y2form, (x == col) ? MHON : MON); - else if (data[current].grid[x-1][y-1] == CURSOFF) { - oslDrawFillRect(x1form, y1form, x2form, y2form, (x == col) ? MHOFF : MOFF); - oslDrawImageXY(select, x1form, y1form); - } - else if (data[current].grid[x-1][y-1] == CURSON) { - oslDrawFillRect(x1form, y1form, x2form, y2form, (x == col) ? MHON : MON); - oslDrawImageXY(select, x1form, y1form); - } - } - - if (solo == y && tmMuteEmpty(mute)) { - if (data[current].grid[x-1][y-1] == OFF) - oslDrawFillRect(x1form, y1form, x2form, y2form, (x == col) ? SHOFF : SOFF); - else if (data[current].grid[x-1][y-1] == ON) - oslDrawFillRect(x1form, y1form, x2form, y2form, (x == col) ? SHON : SON); - else if (data[current].grid[x-1][y-1] == CURSOFF) { - oslDrawFillRect(x1form, y1form, x2form, y2form, (x == col) ? SHOFF : SOFF); - oslDrawImageXY(select, x1form, y1form); - } - else if (data[current].grid[x-1][y-1] == CURSON) { - oslDrawFillRect(x1form, y1form, x2form, y2form, (x == col) ? SHON : SON); - oslDrawImageXY(select, x1form, y1form); - } - } + oslDrawFillRect(x1form, y1form, x2form, y2form, tmGetColor(data[current].grid[x-1][y-1], x, y)); + if (data[current].grid[x-1][y-1] == CURSON || data[current].grid[x-1][y-1] == CURSOFF) + oslDrawImageXY(select, x1form, y1form); } } return; diff --git a/src/draw.h b/src/draw.h new file mode 100644 index 0000000..fc6975d --- /dev/null +++ b/src/draw.h @@ -0,0 +1,24 @@ +/* ToneMatrix - draw.h + * Copyright (c) 2011-2012 Tanner Babcock */ +#ifndef DRAW_H +#define DRAW_H + +#define OFFC RGBA(30,30,30,255) // off +#define ONC RGBA(199,199,199,255) // on +#define HOFF RGBA(50,50,50,255) // lit up and off +#define HON RGBA(220,220,220,255) // lit up and on +#define MOFF RGBA(40,0,0,255) // off, row muted +#define MON RGBA(199,0,0,255) // on, row muted +#define MHOFF RGBA(60,0,0,255) // lit up and off, row muted +#define MHON RGBA(220,0,0,255) // lit up and on, row muted +#define SOFF RGBA(0,7,40,255) // off, row soloed +#define SON RGBA(0,8,199,255) // on, row soloed +#define SHOFF RGBA(0,7,60,255) // lit up and off, row soloed +#define SHON RGBA(0,8,220,255) // lit up and on, row soloed + +#define x1form ((x*30)-29) +#define y1form ((15+(y*30))-29) +#define x2form ((x*30)-1) +#define y2form ((15+(y*30))-1) + +#endif diff --git a/src/file.c b/src/file.c index 8846012..c66c794 100644 --- a/src/file.c +++ b/src/file.c @@ -33,10 +33,10 @@ void tmFileDialog(bool save) { songMeta[x].minute = a.st_mtime.minute; songMeta[x].hour = a.st_mtime.hour; } - // I have to make a separate struct because accessing sm->tm_mday - // from the while (!osl_quit) fries the memory stick - // same reason why there's a bool empty[] - + /* I have to make a separate struct because accessing sm->tm_mday + from the while (!osl_quit) fries the memory stick + same reason why there's a bool empty[] + */ for (x = 0; x < MAX_SAVE_SLOTS; x++) { bzero(tmp, sizeof(tmp)); sprintf(tmp, "songs/song%d.tms", x); diff --git a/src/grid.c b/src/grid.c new file mode 100644 index 0000000..f886386 --- /dev/null +++ b/src/grid.c @@ -0,0 +1,40 @@ +/* ToneMatrix - grid.c + * Copyright (c) 2011-2012 Tanner Babcock */ +#include +#include +#include "main.h" + +void tmClear(tmGrid *g) { + int y, z; + for (y = 0; y < MAX_X; y++) { + for (z = 0; z < MAX_Y; z++) + g->grid[y][z] = OFF; + } + g->grid[0][0] = CURSOFF; + return; +} + +bool tmIsGridEmpty(tmGrid *g) { + int x, y; + for (x = 0; x < MAX_Y; x++) { + for (y = 0; y < MAX_X; y++) { + if (g->grid[x][y] != OFF && g->grid[x][y] != CURSOFF) + return FALSE; + } + } + return TRUE; +} + +void tmSwitchGrid(int *a, int *b) { + // call from tmMainloop with tmSwitchGrid(&x, &y) + int x, y; + for (x = 0; x < MAX_X; x++) { + for (y = 0; y < MAX_Y; y++) { + if (data[current].grid[x][y] == CURSON) + data[current].grid[x][y] = ON; + if (data[current].grid[x][y] == CURSOFF) + data[current].grid[x][y] = OFF; + } + } + return; +} diff --git a/src/main.c b/src/main.c index 812f2a4..19321db 100644 --- a/src/main.c +++ b/src/main.c @@ -4,15 +4,16 @@ #include #include #include "main.h" +#include "menu.h" #define c data[current] PSP_MODULE_INFO("ToneMatrix", 0, 1, 1); PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU); -PSP_HEAP_SIZE_KB(-2048); +PSP_HEAP_SIZE_KB(2048); void tmMainLoop(void) { int x = 0, y = 0, q, m; int tmpcurrent = current; - clock_t start, cu, d; + clock_t start, cu; start = sceKernelLibcClock(); oslClearScreen(RGBA(0, 0, 0, 255)); tmStart(); @@ -78,7 +79,7 @@ void tmMainLoop(void) { else if (c.grid[x-1][y] == OFF) c.grid[x-1][y] = CURSOFF; x--; - } + } } if (osl_keys->pressed.right) { if (x < (MAX_X-1)) { @@ -121,7 +122,7 @@ void tmMainLoop(void) { solo = 0; mute[y] = (mute[y]) ? FALSE : TRUE; } - + if (osl_keys->pressed.R) { if (current < 11) current++; @@ -142,12 +143,12 @@ void tmMainLoop(void) { tmHelp(); break; case CLEARM: - data[current] = tmClear(); + tmClear(&data[current]); break; case CLEARALLM: if (tmClearAllWarning()) { for (q = 0; q < MAX_GRIDS; q++) - data[q] = tmClear(); + tmClear(&data[q]); current = 0; x = 0, y = 0; } diff --git a/src/main.h b/src/main.h index 3b371dc..ce9cac9 100644 --- a/src/main.h +++ b/src/main.h @@ -1,61 +1,26 @@ /* ToneMatrix - main.h - * Copyright (c) 2012 Tanner Babcock */ + * Copyright (c) 2011-2012 Tanner Babcock */ #ifndef MAIN_H #define MAIN_H #include #include -#define VERSION "0.9" +#define VERSION "0.93" #define bool char #define tmQuit() oslEndGfx(); oslQuit() #define tmAbort(err) \ - int s; \ oslClearScreen(RGBA(0, 0, 0, 255)); \ - for (s = 0; s < 4; s++) { \ - oslStartDrawing(); \ - oslReadKeys(); \ - oslDrawString(10, 10, err); \ - oslEndDrawing(); \ - oslSyncFrame(); \ - } \ + oslStartDrawing(); \ + oslReadKeys(); \ + oslDrawString(10, 10, err); \ + oslEndDrawing(); \ + oslSyncFrame();\ sceKernelDelayThread(2000000); \ tmQuit() -#define OFFC RGBA(30,30,30,255) // off -#define ONC RGBA(199,199,199,255) // on -#define HOFF RGBA(50,50,50,255) // lit up and off -#define HON RGBA(220,220,220,255) // lit up and on -#define MOFF RGBA(40,0,0,255) // off, row muted -#define MON RGBA(199,0,0,255) // on, row muted -#define MHOFF RGBA(60,0,0,255) // lit up and off, row muted -#define MHON RGBA(220,0,0,255) // lit up and on, row muted -#define SOFF RGBA(0,7,40,255) // off, row soloed -#define SON RGBA(0,8,199,255) // on, row soloed -#define SHOFF RGBA(0,7,60,255) // lit up and off, row soloed -#define SHON RGBA(0,8,220,255) // lit up and on, row soloed - -#define x1form ((x*30)-29) -#define y1form ((15+(y*30))-29) -#define x2form ((x*30)-1) -#define y2form ((15+(y*30))-1) - enum { FALSE, TRUE }; enum { OFF, ON, CURSOFF, CURSON }; -enum { - SAVEM, // Save song - LOADM, // Load song - HELPM, // Help me - LOOPM, // Loop all: on - TEMPOM, // Tempo: 120 BPM - GRIDM, // Grid: 0 - BREAK, // - CUTM, // Cut grid - COPYM, // Copy grid - PASTEM, // Paste grid - CLEARM, // Clear current grid - CLEARALLM // Clear all grids -}; enum { MAX_MENU_ITEMS = 12, MAX_GRIDS = 16, @@ -67,7 +32,7 @@ enum { }; typedef struct { - char grid[16][8]; + char grid[MAX_X][MAX_Y]; } tmGrid; int bpm; @@ -82,29 +47,43 @@ SceUID soundloop; OSL_SOUND *sound[MAX_Y]; OSL_IMAGE *select; -void tmInit(void); -void tmDebug(int x, int y, const char *str); -void tmSoundLoop(void); -void tmMainLoop(void); +// draw.c +int tmGetColor(char gridval, int x, int y); void tmDrawGrid(void); + +// file.c +void tmFileDialog(bool save); +bool tmDoesFileExist(const char *path); +void tmRead(int slot); +void tmWrite(int slot); + +// grid.c +void tmClear(tmGrid *g); +bool tmIsGridEmpty(tmGrid *g); +void tmSwitchGrid(int *a, int *b); + +// main.c +void tmMainLoop(void); + +// menu.c +unsigned char tmMenu(void); void tmHelp(void); +bool tmClearAllWarning(void); +bool tmOverwriteWarning(int slot); +bool tmDeleteWarning(int slot); + +// misc.c +void tmInit(void); +void tmDebug(int x, int y, const char *str); void setUpVirtualFileMenu(void); -unsigned char tmMenu(void); -tmGrid tmClear(void); + +// rhythm.c double tmTempo(int b); int tmBPM(double t); -void tmMuteCheck(void); bool tmMuteEmpty(bool m[8]); -bool tmIsGridEmpty(tmGrid g); -void tmSwitchGrid(int a, int b); -bool tmClearAllWarning(void); -void tmFileDialog(bool save); -bool tmOverwriteWarning(int slot); -bool tmDeleteWarning(int slot); -bool tmDoesFileExist(const char *path); -const char * tmOSK(const char *name); -void tmRead(int slot); -void tmWrite(int slot); + +// sound.c +void tmSoundLoop(void); void tmStop(void); void tmStart(void); diff --git a/src/menu.c b/src/menu.c index 13a67a4..b55050e 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1,7 +1,8 @@ /* ToneMatrix - menu.c * Copyright (c) 2012 Tanner Babcock */ #include -#include "main.h" +#include "main.h" +#include "menu.h" unsigned char tmMenu(void) { int x; @@ -42,7 +43,7 @@ unsigned char tmMenu(void) { sprintf(mstrings[x], "%s Copy grid", (menuoption == x) ? "->" : " "); break; case PASTEM: - if (tmIsGridEmpty(clipboard)) + if (tmIsGridEmpty(&clipboard)) oslSetTextColor(RGBA(255,0,0,255)); sprintf(mstrings[x], "%s Paste grid", (menuoption == x) ? "->" : " "); break; @@ -108,17 +109,17 @@ unsigned char tmMenu(void) { else { switch (menuoption) { case CUTM: - clipboard = tmClear(); + tmClear(&clipboard); clipboard = data[current]; - data[current] = tmClear(); + tmClear(&data[current]); break; case COPYM: - clipboard = tmClear(); + tmClear(&clipboard); clipboard = data[current]; break; case PASTEM: - if (!tmIsGridEmpty(clipboard)) { - data[current] = tmClear(); + if (!tmIsGridEmpty(&clipboard)) { + tmClear(&data[current]); data[current] = clipboard; } break; diff --git a/src/menu.h b/src/menu.h new file mode 100644 index 0000000..54e0dfe --- /dev/null +++ b/src/menu.h @@ -0,0 +1,21 @@ +/* ToneMatrix - menu.h + * Copyright (c) 2011-2012 Tanner Babcock */ +#ifndef MENU_H +#define MENU_H + +enum { + SAVEM, // Save song + LOADM, // Load song + HELPM, // Help me + LOOPM, // Loop all: on + TEMPOM, // Tempo: 120 BPM + GRIDM, // Grid: 0 + BREAK, + CUTM, // Cut grid + COPYM, // Copy grid + PASTEM, // Paste grid + CLEARM, // Clear current grid + CLEARALLM // Clear all grids +}; + +#endif diff --git a/src/misc.c b/src/misc.c index 7fefb6f..07e6b59 100644 --- a/src/misc.c +++ b/src/misc.c @@ -41,9 +41,9 @@ void tmInit(void) { select = oslLoadImageFilePNG("select.png", OSL_IN_RAM, OSL_PF_5551); oslSetBkColor(RGBA(0, 0, 0, 0)); current = 0; - clipboard = tmClear(); + tmClear(&clipboard); for (y = 0; y < MAX_GRIDS; y++) - data[y] = tmClear(); + tmClear(&data[y]); quit = FALSE; col = 0; menuoption = 0; @@ -51,7 +51,7 @@ void tmInit(void) { bpm = tmBPM(tempo); isplaying = TRUE; loopall = TRUE; - soundloop = sceKernelCreateThread("Sound Loop", tmSoundLoop, 0x11, (256 * 1024), PSP_THREAD_ATTR_USER, NULL); + soundloop = sceKernelCreateThread("Sound Loop", (SceKernelThreadEntry)tmSoundLoop, 0x11, (256 * 1024), PSP_THREAD_ATTR_USER, NULL); oslClearScreen(RGBA(0, 0, 0, 255)); return; } @@ -71,56 +71,3 @@ void tmDebug(int x, int y, const char *str) { OSL_VIRTUALFILENAME ram_files[] = {{"ram:/select.png", (void*)select_data, sizeof(select_data), &VF_MEMORY}}; oslAddVirtualFileList(ram_files, oslNumberof(ram_files)); } */ - -tmGrid tmClear(void) { - int y, z; - tmGrid g; - for (y = 0; y < MAX_X; y++) { - for (z = 0; z < MAX_Y; z++) - g.grid[y][z] = OFF; - } - g.grid[0][0] = CURSOFF; - return g; -} - -double tmTempo(int b) { - return (15000000 / b); -} - -int tmBPM(double t) { - return (15000000 / t); -} - -bool tmMuteEmpty(bool m[8]) { - int x; - for (x = 0; x < MAX_Y; x++) { - if (m[x]) - return FALSE; - } - return TRUE; -} - -bool tmIsGridEmpty(tmGrid g) { - int x, y; - for (x = 0; x < MAX_Y; x++) { - for (y = 0; y < MAX_X; y++) { - if (g.grid[x][y] != OFF && g.grid[x][y] != CURSOFF) - return FALSE; - } - } - return TRUE; -} - -void tmSwitchGrid(int a, int b) { - // call from tmMainloop with tmSwitchGrid(&x, &y) - int x, y; - for (x = 0; x < MAX_X; x++) { - for (y = 0; y < MAX_Y; y++) { - if (data[current].grid[x][y] == CURSON) - data[current].grid[x][y] = ON; - if (data[current].grid[x][y] == CURSOFF) - data[current].grid[x][y] = OFF; - } - } - return; -} diff --git a/src/rhythm.c b/src/rhythm.c new file mode 100644 index 0000000..b2a2683 --- /dev/null +++ b/src/rhythm.c @@ -0,0 +1,20 @@ +/* ToneMatrix - rhythm.c + * Copyright (c) 2011-2012 Tanner Babcock */ +#include "main.h" + +double tmTempo(int b) { + return (15000000 / b); +} + +int tmBPM(double t) { + return (15000000 / t); +} + +bool tmMuteEmpty(bool m[8]) { + int x; + for (x = 0; x < MAX_Y; x++) { + if (m[x]) + return FALSE; + } + return TRUE; +} diff --git a/src/sound.c b/src/sound.c index 648b515..aad9066 100644 --- a/src/sound.c +++ b/src/sound.c @@ -22,14 +22,14 @@ void tmSoundLoop(void) { } if (rflag) { if (loopall) - current = (!tmIsGridEmpty(data[current+1])) ? (current+1) : 0; + current = (!tmIsGridEmpty(&data[current+1])) ? (current+1) : 0; } else { if (loopall) - current = ((!tmIsGridEmpty(data[current+1])) && (current < MAX_GRIDS)) ? (current+1) : 0; + current = ((!tmIsGridEmpty(&data[current+1])) && (current < MAX_GRIDS)) ? (current+1) : 0; } } - sceKernelExitDeleteThread(NULL); + sceKernelExitDeleteThread(0); return; } diff --git a/src/tm.elf b/src/tm.elf new file mode 100644 index 0000000..bf75ec6 Binary files /dev/null and b/src/tm.elf differ diff --git a/src/tm.prx b/src/tm.prx new file mode 100644 index 0000000..ab5d159 Binary files /dev/null and b/src/tm.prx differ diff --git a/unsigned/EBOOT.PBP b/unsigned/EBOOT.PBP index b53be5b..e52ece6 100644 Binary files a/unsigned/EBOOT.PBP and b/unsigned/EBOOT.PBP differ