##########################################################################\r
\r
SRCS = \\r
- badge/main.c \\r
+ badge/fahrplan.c \\r
badge/init.c \\r
+ badge/main.c \\r
badge/jumpnrun/collision.c \\r
badge/jumpnrun/enemies.c \\r
badge/jumpnrun/game_state.c \\r
--- /dev/null
+#include "fahrplan.h"
+#include "ui/browser.h"
+
+#include <drivers/fatfs/ff.h>
+
+#define FAHRPLAN_PATH "/fahrplan"
+#define FAHRPLAN_MENUFILE "fahrplan.lst"
+#define FAHRPLAN_POSFILE "selected.dat"
+
+static size_t badge_load_fahrplan_pos(void) {
+ size_t pos = 0;
+ FIL fd;
+
+ if(FR_OK == f_open(&fd, FAHRPLAN_POSFILE, FA_OPEN_EXISTING | FA_READ)) {
+ UINT bytes;
+ size_t buf;
+ if(FR_OK == f_read(&fd, &buf, sizeof(buf), &bytes) && bytes == sizeof(buf)) {
+ pos = buf;
+ }
+
+ f_close(&fd);
+ }
+
+ return pos;
+}
+
+static void badge_save_fahrplan_pos(size_t pos) {
+ FIL fd;
+
+ if(FR_OK == f_open(&fd, FAHRPLAN_POSFILE, FA_CREATE_ALWAYS | FA_WRITE)) {
+ UINT bytes;
+ f_write(&fd, &pos, sizeof(pos), &bytes);
+ f_close(&fd);
+ }
+}
+
+void badge_fahrplan(void) {
+ f_chdir(FAHRPLAN_PATH);
+
+ size_t oldpos = badge_load_fahrplan_pos();
+ size_t pos = oldpos;
+
+ badge_browse_textfiles(FAHRPLAN_MENUFILE, &pos);
+
+ if(oldpos != pos) {
+ badge_save_fahrplan_pos(pos);
+ }
+}
--- /dev/null
+#ifndef INCLUDED_BADGE_FAHRPLAN_H
+#define INCLUDED_BADGE_FAHRPLAN_H
+
+void badge_fahrplan(void);
+
+#endif
#include "core/cmd/cmd.h"
#endif
+#include "fahrplan.h"
#include "init.h"
#include "ui/browser.h"
#include "ui/display.h"
for(;;);
}
-static void fahrplan(void) {
- f_chdir("/fahrplan");
- badge_browse_textfiles("fahrplan.lst");
-}
-
uint8_t main_menu_show(uint8_t selected) {
char const menu_buf[][15] = {
"Vanity-Screen",
switch(selected) {
case 0: badge_vanity_show(); break;
case 1: jumpnrun_play (); break;
- case 2: fahrplan (); break;
+ case 2: badge_fahrplan (); break;
case 3: usbmode (); break;
}
}
}
}
-void badge_browse_textfiles(char const *menufile) {
+void badge_browse_textfiles(char const *menufile, size_t *selected) {
char buf[FNAME_MAX + 1];
size_t first_visible = 0;
- size_t selected = 0;
- while(0 == badge_pick_filename(buf, menufile, &first_visible, &selected)) {
+ while(0 == badge_pick_filename(buf, menufile, &first_visible, selected)) {
badge_browse_textfile(buf);
}
}
#ifndef INCLUDED_BADGE_UI_BROWSER_H
#define INCLUDED_BADGE_UI_BROWSER_H
+#include <stddef.h>
+
void badge_browse_textfile(char const *fname);
-void badge_browse_textfiles(char const *menufile);
+void badge_browse_textfiles(char const *menufile, size_t *selected);
#endif
size_t first_used_row = 0;
size_t used_rows = MENU_ENTRIES_VISIBLE;
+ if(selected >= n) {
+ selected = n - 1;
+ }
+
if(n <= MENU_ENTRIES_VISIBLE) {
*first_visible = 0;
used_rows = n;