Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Commit

Permalink
Make menu look a bit better. Attempts at audio were made (not working…
Browse files Browse the repository at this point in the history
… yet)
  • Loading branch information
Matteo Forlani committed Feb 16, 2024
1 parent 35244c1 commit df29325
Show file tree
Hide file tree
Showing 5 changed files with 749 additions and 20 deletions.
87 changes: 67 additions & 20 deletions gb_cardputer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
#include "peanutgb/peanut_gb.h"
#include "SD.h"

// TODO: Make a menu to pick ROM files from the SD card
#define ROM_FILE "/rom.gb"

#define DEST_W 240
#define DEST_H 135

Expand Down Expand Up @@ -167,10 +164,33 @@ void draw_frame(uint32_t fb[144][160]) {

#endif

// Shorten ROM display names if they're too long.
// Memory alloc with C strings is hard so this goes unused for now
//char* clamp_str(char* input) {
// if(strlen(input) > 10) {
// char* output = (char*)malloc(sizeof(char)*4+sizeof(char)*strlen(input));
// for (int i = 0; i < 9; i++) {
// output[i] = input[i];
// }
// sprintf(output, "%s...", input);
// return output;
// } else {
// return input;
// }
//}

void set_font_size(int size) {
int textsize = M5Cardputer.Display.height() / size;
if(textsize == 0) {
textsize = 1;
}
M5Cardputer.Display.setTextSize(textsize);
}

// Opens a ROM file picker menu
// and returns a string containing
// the path of the picked ROM.
char* file_picker(int text_size) {
char* file_picker() {
// Open SD card root dir.
File root_dir = SD.open("/");
String file_list[MAX_FILES];
Expand Down Expand Up @@ -255,21 +275,22 @@ char* file_picker(int text_size) {
// Down: s
// Play: l
switch(i) {
case 'e':
case ';':
select_index--;
delay(300);
break;
case 's':
case '.':
select_index++;
delay(300);
break;
case 'l':
file_picked = true;
break;
default:
break;
}
}

if(status.enter) {
file_picked = true;
}
}

// Loop over list if we went over its bounds
Expand All @@ -282,17 +303,37 @@ char* file_picker(int text_size) {
}

// Render controls
M5Cardputer.Display.drawString("Up/Down: E/S; Select: L", 0, 0);
// M5Cardputer.Display.drawString("Up/Down: E/S; Select: L", 0, 0);

//M5Cardputer.Display.setTextDatum(MC_DATUM);

const int dispW = M5Cardputer.Display.width();
const int dispH = M5Cardputer.Display.height();

// Render list
for(int i = 0; i < file_list_size; i++) {
// Add an arrow to point to
// the currently selected file

if(select_index == i) {
M5Cardputer.Display.drawString(" > ", 0, 10+i*10);
M5Cardputer.Display.drawString(file_list_cstr[i], 20, 10+i*10);
} else {
M5Cardputer.Display.drawString(file_list_cstr[i], 0, 10+i*10);
set_font_size(64);
int textW = M5Cardputer.Display.textWidth(file_list_cstr[i]);
int textH = M5Cardputer.Display.fontHeight();

M5Cardputer.Display.drawString(" > ", 0, (dispH/2)-(textH/2));
M5Cardputer.Display.drawString(file_list_cstr[i], (dispW/2)-(textW/2), (dispH/2)-(textH/2));
} else if(i == select_index-1) {
set_font_size(128);
int textW = M5Cardputer.Display.textWidth(file_list_cstr[i]);
int textH = M5Cardputer.Display.fontHeight();

M5Cardputer.Display.drawString(file_list_cstr[i], (dispW/2)-(textW/2), (dispH/2)-(textH/2)-textH*2);
} else if(i == select_index+1) {
set_font_size(128);
int textW = M5Cardputer.Display.textWidth(file_list_cstr[i]);
int textH = M5Cardputer.Display.fontHeight();

M5Cardputer.Display.drawString(file_list_cstr[i], (dispW/2)-(textW/2), (dispH/2)-(textH/2)+textH*2);
}
}
}
Expand All @@ -303,6 +344,12 @@ char* file_picker(int text_size) {
return selected_path;
}

#if ENABLE_SOUND
void audioSetup() {
// headache. stopped here lol
}
#endif

void setup() {
// put your setup code here, to run once:

Expand All @@ -311,13 +358,13 @@ void setup() {
// Use keyboard.
M5Cardputer.begin(cfg, true);

#if ENABLE_SOUND
M5Cardputer.Speaker.begin();
#endif

// Set display rotation to horizontal.
M5Cardputer.Display.setRotation(1);
int textsize = M5Cardputer.Display.height() / 256;
if(textsize == 0) {
textsize = 1;
}
M5Cardputer.Display.setTextSize(textsize);
set_font_size(64);

// Initialize SD card.
// Some of this code is taken from
Expand All @@ -340,7 +387,7 @@ void setup() {


debugPrint("Before filepick");
char* selected_file = file_picker(textsize);
char* selected_file = file_picker();
debugPrint(selected_file);
debugPrint("After filepick");

Expand Down
16 changes: 16 additions & 0 deletions glue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// glue minigb_apu and gb_cardputer together
// very rough
// matthew5pl.net

typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;

typedef int int32_t;
typedef short int16_t;
typedef char int8_t;

// who cares about efficiency
#define bool char
#define true 1
#define false 0
20 changes: 20 additions & 0 deletions minigb_apu_cardputer/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2017 Alex Baines <[email protected]>
Copyright (c) 2019 Mahyar Koshkouei <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit df29325

Please sign in to comment.