From 63d036203cfdf773d4f16b4beac7b55558850c52 Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Sun, 3 Sep 2023 23:59:53 +0200 Subject: [PATCH] Turn dfsdemo into a text file reader instead of a module sound file player --- examples/dfsdemo/Makefile | 2 - examples/dfsdemo/dfsdemo.c | 126 ++++++------------ ...E_MOD_XM_IT_S3M_FILES_HERE => dirhint.txt} | 0 examples/dfsdemo/filesystem/dorian_gray.txt | 14 ++ examples/dfsdemo/filesystem/libdragon.txt | 2 + .../dfsdemo/filesystem/my_sub/another.txt | 4 + 6 files changed, 63 insertions(+), 85 deletions(-) rename examples/dfsdemo/filesystem/{PLACE_MOD_XM_IT_S3M_FILES_HERE => dirhint.txt} (100%) create mode 100644 examples/dfsdemo/filesystem/dorian_gray.txt create mode 100644 examples/dfsdemo/filesystem/libdragon.txt create mode 100644 examples/dfsdemo/filesystem/my_sub/another.txt diff --git a/examples/dfsdemo/Makefile b/examples/dfsdemo/Makefile index 903f3437e1..fa9b37f0ff 100644 --- a/examples/dfsdemo/Makefile +++ b/examples/dfsdemo/Makefile @@ -7,8 +7,6 @@ include $(N64_INST)/include/n64.mk OBJS = $(BUILD_DIR)/dfsdemo.o dfsdemo.z64: N64_ROM_TITLE = "DragonFS Demo" -dfsdemo.z64: N64_CFLAGS += -I$(N64_ROOTDIR)/include -dfsdemo.z64: N64_LDFLAGS += -L$(N64_ROOTDIR)/lib -lmikmod dfsdemo.z64: $(BUILD_DIR)/dfsdemo.dfs $(BUILD_DIR)/dfsdemo.dfs: $(wildcard filesystem/*) diff --git a/examples/dfsdemo/dfsdemo.c b/examples/dfsdemo/dfsdemo.c index d8061557a8..0549f61ef2 100644 --- a/examples/dfsdemo/dfsdemo.c +++ b/examples/dfsdemo/dfsdemo.c @@ -1,18 +1,13 @@ #include #include +#include #include #include #include #include -#include #define MAX_LIST 20 -// Hint linker on it is OK to put these on .data section -// This is ugly, there must be a better way? -MIKMODAPI extern UWORD md_mode __attribute__((section (".data"))); -MIKMODAPI extern UWORD md_mixfreq __attribute__((section (".data"))); - typedef struct { uint32_t type; @@ -216,25 +211,12 @@ void display_dir(direntry_t *list, int cursor, int page, int max, int count) int main(void) { - /* Initialize audio and video */ - audio_init(44100,2); + /* Initialize video */ console_init(); /* Initialize key detection */ controller_init(); - MikMod_RegisterAllDrivers(); - MikMod_RegisterAllLoaders(); - - md_mode |= DMODE_16BITS; - md_mode |= DMODE_SOFT_MUSIC; - md_mode |= DMODE_SOFT_SNDFX; - //md_mode |= DMODE_STEREO; - - md_mixfreq = audio_get_frequency(); - - MikMod_Init(""); - if(dfs_init( DFS_DEFAULT_LOCATION ) != DFS_ESUCCESS) { printf("Filesystem failed to start!\n"); @@ -274,80 +256,58 @@ int main(void) if(keys.c[0].C_right && list[cursor].type == DT_REG) { - /* Module playing loop */ - MODULE *module = NULL; - /* Concatenate to make file */ char path[512]; strcpy( path, dir ); strcat( path, list[cursor].filename ); - module = Player_Load(path, 256, 0); - - /* Ensure that first part of module doesn't get cut off */ - audio_write_silence(); - audio_write_silence(); - - if(module) - { - char c = '-'; - int sw = 0; - - Player_Start(module); - - while(1) - { - if(sw == 5) - { - console_clear(); - display_dir(list, cursor, page, MAX_LIST, count); - - sw = 0; - switch(c) - { - case '-': - c = '\\'; - break; - case '\\': - c = '|'; - break; - case '|': - c = '/'; - break; - case '/': - c = '-'; - break; + FILE* f; + f = fopen(path, "r"); + if (f == NULL) { + printf("Failed to open %s\n", path); + } else { + printf("Hold A to scroll\n"); + char buf[1024]; + size_t nread; + while ((nread = fread(buf, sizeof(buf[0]), sizeof(buf) - 1, f)) != 0) { + buf[nread] = '\0'; + char* s = buf; + while (s != NULL) { + char* s_next_line = strchr(s, '\n'); + if (s_next_line == NULL) { + printf("%s", s); + s = NULL; + } else { + printf("%.*s\n", s_next_line - s, s); + console_render(); + s = s_next_line + 1; + + wait_ms(100); + controller_scan(); + while (!get_keys_pressed().c[0].A) { + wait_ms(10); + controller_scan(); + } } - - printf("\n\n\n%c Playing module", c); - console_render(); - } - else - { - sw++; } + } + if (ferror(f)) { + printf("Error while reading %s\n", path); + } - MikMod_Update(); - - controller_scan(); - struct controller_data keys = get_keys_down(); - - if(keys.c[0].C_left || !Player_Active()) - { - /* End playback */ - audio_write_silence(); - audio_write_silence(); - audio_write_silence(); - audio_write_silence(); + fclose(f); + } - break; - } - } - - Player_Stop(); - Player_Free(module); + printf("Press B to quit\n"); + console_render(); + controller_scan(); + while (!get_keys_down().c[0].B) { + wait_ms(10); + controller_scan(); } + + continue; } if(keys.c[0].L) diff --git a/examples/dfsdemo/filesystem/PLACE_MOD_XM_IT_S3M_FILES_HERE b/examples/dfsdemo/filesystem/dirhint.txt similarity index 100% rename from examples/dfsdemo/filesystem/PLACE_MOD_XM_IT_S3M_FILES_HERE rename to examples/dfsdemo/filesystem/dirhint.txt diff --git a/examples/dfsdemo/filesystem/dorian_gray.txt b/examples/dfsdemo/filesystem/dorian_gray.txt new file mode 100644 index 0000000000..7436ecbedb --- /dev/null +++ b/examples/dfsdemo/filesystem/dorian_gray.txt @@ -0,0 +1,14 @@ +THE PICTURE OF DORIAN GRAY. + + +CHAPTER I. + +THE studio was filled with the rich odour of roses, and when the light summer wind stirred amidst the trees of the garden there came through the open door the heavy scent of the lilac, or the more delicate perfume of the pink-flowering thorn. + +From the corner of the divan of Persian saddlebags on which he was lying, smoking, as was his custom, innumerable cigarettes, Lord Henry Wotton could just catch the gleam of the honey-sweet and honey-coloured blossoms of a laburnum, whose tremulous branches seemed hardly able to bear the burden of a beauty so flame-like as theirs; and now and then the fantastic shadows of birds in flight flitted across the long tussore-silk curtains that were stretched in front of the huge window, producing a kind of momentary Japanese effect, and making him think of those pallid jade-faced painters of Tokio who, through the medium of an art that is necessarily immobile, seek to convey the sense of swiftness and motion. The sullen murmur of the bees shouldering their way through the long unmown grass, or circling with monotonous insistence round the dusty gilt horns of the straggling woodbine, seemed to make the stillness more oppressive. The dim roar of London was like the bourdon note of a distant organ. + +In the centre of the room, clamped to an upright easel, stood the full-length portrait of a young man of extraordinary personal beauty, and in front of it, some little distance away, was sitting the artist himself, Basil Hallward, whose sudden disappearance some years ago caused, at the time, such public excitement, and gave rise to so many strange conjectures. + +As the painter looked at the gracious and comely form he had so skilfully mirrored in his art, a smile of pleasure passed across his face, and seemed about to linger there. But he suddenly started up, and, closing his eyes, placed his fingers upon the lids, as though he sought to imprison within his brain some curious dream from which he feared he might awake. + +"It is your best work, Basil, the best thing you have ever done," said Lord Henry, languidly. "You must certainly send it next year to the Grosvenor. The Academy is too large and too vulgar. diff --git a/examples/dfsdemo/filesystem/libdragon.txt b/examples/dfsdemo/filesystem/libdragon.txt new file mode 100644 index 0000000000..0d7a222d02 --- /dev/null +++ b/examples/dfsdemo/filesystem/libdragon.txt @@ -0,0 +1,2 @@ +Libdragon is an open-source SDK for Nintendo 64. +It aims for a complete N64 programming experience while providing programmers with modern approach to programming and debugging. diff --git a/examples/dfsdemo/filesystem/my_sub/another.txt b/examples/dfsdemo/filesystem/my_sub/another.txt new file mode 100644 index 0000000000..6edcb5b0be --- /dev/null +++ b/examples/dfsdemo/filesystem/my_sub/another.txt @@ -0,0 +1,4 @@ +Hello +on +four +lines!