From db39f6e5b71173e2314f520bed282e51c1c708b3 Mon Sep 17 00:00:00 2001 From: Jorj Bauer Date: Sat, 11 Jul 2020 19:43:00 -0400 Subject: [PATCH] sort disk images in the BIOS --- bios.cpp | 29 +++++++++++++++++++++++++++++ bios.h | 2 ++ 2 files changed, 31 insertions(+) diff --git a/bios.cpp b/bios.cpp index 95cd08e..883bdac 100644 --- a/bios.cpp +++ b/bios.cpp @@ -1,3 +1,4 @@ +#include #include "globals.h" #include "bios.h" @@ -824,6 +825,7 @@ uint16_t BIOS::DrawDiskNames(uint8_t page, int8_t selection, const char *filter) return fileCount; } +// Read a directory, cache all the entries uint16_t BIOS::cacheAllEntries(const char *filter) { // If we've already cached this directory, then just return it @@ -860,12 +862,39 @@ uint16_t BIOS::cacheAllEntries(const char *filter) /* NOTREACHED */ } +void BIOS::swapCacheEntries(int a, int b) +{ + struct _cacheEntry tmpEntry; + strcpy(tmpEntry.fn, biosCache[a].fn); + strcpy(biosCache[a].fn, biosCache[b].fn); + strcpy(biosCache[b].fn, tmpEntry.fn); +} + +// Take all the entries in the cache and sort htem +void BIOS::sortCachedEntries() +{ + if (numCacheEntries <= 1) + return; + + bool changedAnything = true; + while (changedAnything) { + changedAnything = false; + for (int i=0; i 0) { + swapCacheEntries(i, i+1); + changedAnything = true; + } + } + } +} + uint16_t BIOS::GatherFilenames(uint8_t pageOffset, const char *filter) { uint8_t startNum = 10 * pageOffset; uint8_t count = 0; // number we're including in our listing uint16_t numEntriesTotal = cacheAllEntries(filter); + sortCachedEntries(); if (numEntriesTotal > BIOSCACHESIZE) { // ... umm, this is a problem. FIXME? } diff --git a/bios.h b/bios.h index 5109ba5..858c197 100644 --- a/bios.h +++ b/bios.h @@ -46,6 +46,8 @@ class BIOS { void showAbout(); uint16_t cacheAllEntries(const char *filter); + void sortCachedEntries(); + void swapCacheEntries(int a, int b); private: int8_t selectedFile;