Skip to content

Commit

Permalink
Merge branch 'trunk' into gfx-rdp
Browse files Browse the repository at this point in the history
  • Loading branch information
rasky committed Sep 29, 2023
2 parents 95616a3 + e1db7bb commit 4130578
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 97 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!
40 changes: 33 additions & 7 deletions include/asset.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@
* If you know that the file will never be compressed and you absolutely need
* to freely seek, simply use the standard fopen() function.
*
* ## Asset compression
*
* To compress your own data files, you can use the mkasset tool.
*
* There are currently two compression levels:
*
* * Level 1: this is based on LZ4 by Yann Collet. It is extremely fast and
* produce reasonable compression ratios. It is so fast at decompression
* that our implementation is typically faster at loading and decompressing
* a compressed asset, rather than loading it uncompressed. Libdragon tools
* will compress at level 1 by default.
* * Level 2: this is based on LZH5 by Haruhiko Okumura, part of the LHA archiver.
* It is slower than LZ4, but it produces better compression ratios. It has
* been measured to beat gzip/zlib for small files like those typically used
* on N64. Level 2 should be selected if there is a necessity to squeeze data
* at the maximum ratio, at the expense of loading speed.
*
* To minimize text siz and RAM usage, only the decompression code for level 1
* is compiled by default. If you need to use level 2, you must call
* #asset_init_compression(2).
*/

#include <stdio.h>
Expand Down Expand Up @@ -95,8 +115,8 @@ extern "C" {
* If the file was compressed using the mkasset tool, it will be
* automatically uncompressed.
*
* @param fn Filename to load (including filesystem prefix)
* @param sz Pointer to an integer where the size of the file will be stored
* @param fn Filename to load (including filesystem prefix, eg: "rom:/foo.dat")
* @param sz If not NULL, this will be filed with the uncompressed size of the loaded file
* @return void* Pointer to the loaded file (must be freed with free() when done)
*/
void *asset_load(const char *fn, int *sz);
Expand All @@ -108,12 +128,18 @@ void *asset_load(const char *fn, int *sz);
* If the file was compressed using the mkasset tool, it will be
* automatically uncompressed as it is being read.
*
* Note that since the file can be optionally compressed, the returned
* FILE* cannot be rewinded. It must be read sequentially, or seeked forward.
* Seeking backward is not supported.
* Note that since the file might be compressed, the returned
* FILE* cannot be rewinded, nor seeked backward, as that would be impossible
* to do efficiently on a compressed file. Seeking forward is supported and is
* simulated by reading (decompressing) and discarding data.
*
* @param fn Filename to open (including filesystem prefix)
* @param sz If not NULL, pointer to an integer where the size of the file will be stored
* This behavior of the returned file is enforced also for non compressed
* assets, so that the code is ready to switch to compressed assets if
* required. If you need random access to an uncompressed file, simply use
* the standard fopen() function.
*
* @param fn Filename to load (including filesystem prefix, eg: "rom:/foo.dat")
* @param sz If not NULL, this will be filed with the uncompressed size of the loaded file
* @return FILE* FILE pointer to use with standard C functions (fread, fclose)
*/
FILE *asset_fopen(const char *fn, int *sz);
Expand Down
4 changes: 2 additions & 2 deletions src/compress/ringbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ void __ringbuf_copy(decompress_ringbuf_t *ringbuf, int copy_offset, uint8_t *dst
int ringbuf_copy_pos = (ringbuf->ringbuf_pos - copy_offset) & (RING_BUFFER_SIZE-1);
int dst_pos = 0;
while (count > 0) {
int wn = count;
int wn = count;
wn = wn < RING_BUFFER_SIZE - ringbuf_copy_pos ? wn : RING_BUFFER_SIZE - ringbuf_copy_pos;
wn = wn < RING_BUFFER_SIZE - ringbuf->ringbuf_pos ? wn : RING_BUFFER_SIZE - ringbuf->ringbuf_pos;
wn = wn < RING_BUFFER_SIZE - ringbuf->ringbuf_pos ? wn : RING_BUFFER_SIZE - ringbuf->ringbuf_pos;
count -= wn;

// Check if there's an overlap in the ring buffer between read and write pos, in which
Expand Down
4 changes: 2 additions & 2 deletions src/inspector.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#ifndef NDEBUG
#include "graphics.h"
#include "display.h"
#include "debug.h"
Expand Down Expand Up @@ -575,6 +574,7 @@ void __inspector_cppexception(const char *exctype, const char *what) {
__builtin_unreachable();
}

#ifndef NDEBUG
__attribute__((constructor))
void __inspector_init(void) {
// Register SYSCALL 0x1 for assertion failures
Expand All @@ -584,4 +584,4 @@ void __inspector_init(void) {
}
register_syscall_handler(handler, 0x00001, 0x00002);
}
#endif /* NDBUEG */
#endif
2 changes: 1 addition & 1 deletion tools/audioconv64/conv_ym64.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ int ym_convert(const char *infn, const char *outfn) {

// Initialize LHA decompression, and read back the now uncompressed header.
// Decompression is performed via a minimal version of
// https://github.com/fragglet/lhasa, stored in lz5h.h.
// https://github.com/fragglet/lhasa, stored in lzh5.h.
fseek(ym_f, head[0]+2, SEEK_SET);
ym_compressed = true;
decompress_lzh5_init(ym_decoder, ym_f);
Expand Down

0 comments on commit 4130578

Please sign in to comment.