Skip to content

Commit

Permalink
Turn dfsdemo into a text file reader instead of a module sound file p…
Browse files Browse the repository at this point in the history
…layer
  • Loading branch information
Dragorn421 committed Sep 3, 2023
1 parent 502b388 commit e0225d9
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 85 deletions.
2 changes: 0 additions & 2 deletions examples/dfsdemo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/*)
Expand Down
126 changes: 43 additions & 83 deletions examples/dfsdemo/dfsdemo.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <libdragon.h>
#include <mikmod.h>

#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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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)
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions examples/dfsdemo/filesystem/dorian_gray.txt
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions examples/dfsdemo/filesystem/libdragon.txt
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 4 additions & 0 deletions examples/dfsdemo/filesystem/my_sub/another.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Hello
on
four
lines!

0 comments on commit e0225d9

Please sign in to comment.