@@ -17,21 +17,23 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "dirlist.h"
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include <mem/heap.h>
|
||||
#include <utils/types.h>
|
||||
|
||||
#define MAX_ENTRIES 64
|
||||
|
||||
char *dirlist(const char *directory, const char *pattern, bool includeHiddenFiles, bool parse_dirs)
|
||||
dirlist_t *dirlist(const char *directory, const char *pattern, bool includeHiddenFiles, bool parse_dirs)
|
||||
{
|
||||
int res = 0;
|
||||
u32 i = 0, j = 0, k = 0;
|
||||
u32 k = 0;
|
||||
DIR dir;
|
||||
FILINFO fno;
|
||||
|
||||
char *dir_entries = (char *)zalloc(MAX_ENTRIES * 256);
|
||||
char *temp = (char *)zalloc(256);
|
||||
dirlist_t *dir_entries = (dirlist_t *)malloc(sizeof(dirlist_t));
|
||||
|
||||
// Setup pointer tree.
|
||||
for (u32 i = 0; i < DIR_MAX_ENTRIES; i++)
|
||||
dir_entries->name[i] = &dir_entries->data[i * 256];
|
||||
|
||||
if (!pattern && !f_opendir(&dir, directory))
|
||||
{
|
||||
@@ -47,9 +49,8 @@ char *dirlist(const char *directory, const char *pattern, bool includeHiddenFile
|
||||
{
|
||||
if ((fno.fname[0] != '.') && (includeHiddenFiles || !(fno.fattrib & AM_HID)))
|
||||
{
|
||||
strcpy(dir_entries + (k * 256), fno.fname);
|
||||
k++;
|
||||
if (k > (MAX_ENTRIES - 1))
|
||||
strcpy(&dir_entries->data[k * 256], fno.fname);
|
||||
if (++k >= DIR_MAX_ENTRIES)
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -62,9 +63,8 @@ char *dirlist(const char *directory, const char *pattern, bool includeHiddenFile
|
||||
{
|
||||
if (!(fno.fattrib & AM_DIR) && (fno.fname[0] != '.') && (includeHiddenFiles || !(fno.fattrib & AM_HID)))
|
||||
{
|
||||
strcpy(dir_entries + (k * 256), fno.fname);
|
||||
k++;
|
||||
if (k > (MAX_ENTRIES - 1))
|
||||
strcpy(&dir_entries->data[k * 256], fno.fname);
|
||||
if (++k >= DIR_MAX_ENTRIES)
|
||||
break;
|
||||
}
|
||||
res = f_findnext(&dir, &fno);
|
||||
@@ -74,27 +74,27 @@ char *dirlist(const char *directory, const char *pattern, bool includeHiddenFile
|
||||
|
||||
if (!k)
|
||||
{
|
||||
free(temp);
|
||||
free(dir_entries);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Terminate name list.
|
||||
dir_entries->name[k] = NULL;
|
||||
|
||||
// Reorder ini files by ASCII ordering.
|
||||
for (i = 0; i < k - 1 ; i++)
|
||||
for (u32 i = 0; i < k - 1 ; i++)
|
||||
{
|
||||
for (j = i + 1; j < k; j++)
|
||||
for (u32 j = i + 1; j < k; j++)
|
||||
{
|
||||
if (strcmp(&dir_entries[i * 256], &dir_entries[j * 256]) > 0)
|
||||
if (strcmp(dir_entries->name[i], dir_entries->name[j]) > 0)
|
||||
{
|
||||
strcpy(temp, &dir_entries[i * 256]);
|
||||
strcpy(&dir_entries[i * 256], &dir_entries[j * 256]);
|
||||
strcpy(&dir_entries[j * 256], temp);
|
||||
char *tmp = dir_entries->name[i];
|
||||
dir_entries->name[i] = dir_entries->name[j];
|
||||
dir_entries->name[j] = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(temp);
|
||||
|
||||
return dir_entries;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018 CTCaer
|
||||
* Copyright (c) 2018-2024 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
@@ -16,4 +16,12 @@
|
||||
|
||||
#include <utils/types.h>
|
||||
|
||||
char *dirlist(const char *directory, const char *pattern, bool includeHiddenFiles, bool parse_dirs);
|
||||
#define DIR_MAX_ENTRIES 64
|
||||
|
||||
typedef struct _dirlist_t
|
||||
{
|
||||
char *name[DIR_MAX_ENTRIES];
|
||||
char data[DIR_MAX_ENTRIES * 256];
|
||||
} dirlist_t;
|
||||
|
||||
dirlist_t *dirlist(const char *directory, const char *pattern, bool includeHiddenFiles, bool parse_dirs);
|
||||
|
||||
@@ -53,7 +53,7 @@ ini_sec_t *_ini_create_section(link_t *dst, ini_sec_t *csec, char *name, u8 type
|
||||
return csec;
|
||||
}
|
||||
|
||||
int ini_parse(link_t *dst, char *ini_path, bool is_dir)
|
||||
int ini_parse(link_t *dst, const char *ini_path, bool is_dir)
|
||||
{
|
||||
FIL fp;
|
||||
u32 lblen;
|
||||
@@ -62,7 +62,7 @@ int ini_parse(link_t *dst, char *ini_path, bool is_dir)
|
||||
ini_sec_t *csec = NULL;
|
||||
|
||||
char *lbuf = NULL;
|
||||
char *filelist = NULL;
|
||||
dirlist_t *filelist = NULL;
|
||||
char *filename = (char *)malloc(256);
|
||||
|
||||
strcpy(filename, ini_path);
|
||||
@@ -85,9 +85,9 @@ int ini_parse(link_t *dst, char *ini_path, bool is_dir)
|
||||
// Copy ini filename in path string.
|
||||
if (is_dir)
|
||||
{
|
||||
if (filelist[k * 256])
|
||||
if (filelist->name[k])
|
||||
{
|
||||
strcpy(filename + pathlen, &filelist[k * 256]);
|
||||
strcpy(filename + pathlen, filelist->name[k]);
|
||||
k++;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -43,7 +43,7 @@ typedef struct _ini_sec_t
|
||||
u32 color;
|
||||
} ini_sec_t;
|
||||
|
||||
int ini_parse(link_t *dst, char *ini_path, bool is_dir);
|
||||
int ini_parse(link_t *dst, const char *ini_path, bool is_dir);
|
||||
char *ini_check_special_section(ini_sec_t *cfg);
|
||||
void ini_free(link_t *src);
|
||||
|
||||
|
||||
@@ -28,10 +28,32 @@ static void _s_putc(char c)
|
||||
*sout_buf += 1;
|
||||
}
|
||||
|
||||
static void _s_puts(char *s)
|
||||
static void _s_putspace(int fcnt)
|
||||
{
|
||||
if (fcnt <= 0)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < fcnt; i++)
|
||||
_s_putc(' ');
|
||||
}
|
||||
|
||||
static void _s_puts(char *s, char fill, int fcnt)
|
||||
{
|
||||
if (fcnt)
|
||||
{
|
||||
fcnt = fcnt - strlen(s);
|
||||
|
||||
// Left padding. Check if padding is not space based (dot counts as such).
|
||||
if (fill != '.')
|
||||
_s_putspace(fcnt);
|
||||
}
|
||||
|
||||
for (; *s; s++)
|
||||
_s_putc(*s);
|
||||
|
||||
// Right padding. Check if padding is space based (dot counts as such).
|
||||
if (fill == '.')
|
||||
_s_putspace(fcnt);
|
||||
}
|
||||
|
||||
static void _s_putn(u32 v, int base, char fill, int fcnt)
|
||||
@@ -75,9 +97,28 @@ static void _s_putn(u32 v, int base, char fill, int fcnt)
|
||||
}
|
||||
}
|
||||
|
||||
_s_puts(p);
|
||||
_s_puts(p, 0, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Padding:
|
||||
* Numbers:
|
||||
* %3d: Fill: ' ', Count: 3.
|
||||
* % 3d: Fill: ' ', Count: 3.
|
||||
* %.3d: Fill: '.', Count: 3.
|
||||
* %23d: Fill: '2', Count: 3.
|
||||
* % 23d: Fill: ' ', Count: 23.
|
||||
* %223d: Fill: '2', Count: 23.
|
||||
*
|
||||
* Strings, Fill: ' ':
|
||||
* %3s: Count: 5, Left.
|
||||
* %23s: Count: 5, Left.
|
||||
* %223s: Count: 25, Left.
|
||||
* %.3s: Count: 5, Right.
|
||||
* %.23s: Count: 25, Right.
|
||||
* %.223s: Count: 225, Right.
|
||||
*/
|
||||
|
||||
void s_printf(char *out_buf, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
@@ -94,8 +135,8 @@ void s_printf(char *out_buf, const char *fmt, ...)
|
||||
fill = 0;
|
||||
fcnt = 0;
|
||||
|
||||
// Check for padding. Number or space based.
|
||||
if ((*fmt >= '0' && *fmt <= '9') || *fmt == ' ')
|
||||
// Check for padding. Number or space based (dot count as space for string).
|
||||
if ((*fmt >= '0' && *fmt <= '9') || *fmt == ' ' || *fmt == '.')
|
||||
{
|
||||
fcnt = *fmt; // Padding size or padding type.
|
||||
fmt++;
|
||||
@@ -132,7 +173,7 @@ parse_padding_dec:
|
||||
break;
|
||||
|
||||
case 's':
|
||||
_s_puts(va_arg(ap, char *));
|
||||
_s_puts(va_arg(ap, char *), fill, fcnt);
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
@@ -221,7 +262,7 @@ parse_padding_dec:
|
||||
break;
|
||||
|
||||
case 's':
|
||||
_s_puts(va_arg(ap, char *));
|
||||
_s_puts(va_arg(ap, char *), fill, fcnt);
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
|
||||
@@ -21,7 +21,25 @@
|
||||
|
||||
#include <utils/types.h>
|
||||
|
||||
/*
|
||||
* Padding:
|
||||
* Numbers:
|
||||
* %3d: Fill: ' ', Count: 3.
|
||||
* % 3d: Fill: ' ', Count: 3.
|
||||
* %23d: Fill: '2', Count: 3.
|
||||
* % 23d: Fill: ' ', Count: 23.
|
||||
* %223d: Fill: '2', Count: 23.
|
||||
*
|
||||
* Strings, Fill: ' ':
|
||||
* %3s: Count: 5, Left.
|
||||
* %23s: Count: 5, Left.
|
||||
* %223s: Count: 25, Left.
|
||||
* %.3s: Count: 5, Right.
|
||||
* %.23s: Count: 25, Right.
|
||||
* %.223s: Count: 225, Right.
|
||||
*/
|
||||
|
||||
void s_printf(char *out_buf, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
|
||||
void s_vprintf(char *out_buf, const char *fmt, va_list ap);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -98,10 +98,12 @@ typedef unsigned long uptr;
|
||||
#define OFFSET_OF(t, m) ((uptr)&((t *)NULL)->m)
|
||||
#define CONTAINER_OF(mp, t, mn) ((t *)((uptr)mp - OFFSET_OF(t, mn)))
|
||||
|
||||
#define byte_swap_16(num) ((((num) >> 8) & 0xff) | (((num) << 8) & 0xff00))
|
||||
#define byte_swap_32(num) ((((num) >> 24) & 0xff) | (((num) << 8) & 0xff0000) | \
|
||||
(((num) >> 8 ) & 0xff00) | (((num) << 24) & 0xff000000))
|
||||
#define byte_swap_16(num) ((((num) >> 8) & 0xFF) | (((num) & 0xFF) << 8))
|
||||
#define byte_swap_32(num) ((((num) >> 24) & 0xFF) | (((num) & 0xFF00) << 8 ) | \
|
||||
(((num) >> 8 ) & 0xFF00) | (((num) & 0xFF) << 24))
|
||||
|
||||
#define likely(x) (__builtin_expect((x) != 0, 1))
|
||||
#define unlikely(x) (__builtin_expect((x) != 0, 0))
|
||||
|
||||
/* Bootloader/Nyx */
|
||||
#define BOOT_CFG_AUTOBOOT_EN BIT(0)
|
||||
|
||||
@@ -29,8 +29,6 @@
|
||||
#include <storage/sd.h>
|
||||
#include <utils/util.h>
|
||||
|
||||
#define USE_RTC_TIMER
|
||||
|
||||
u8 bit_count(u32 val)
|
||||
{
|
||||
u8 cnt = 0;
|
||||
@@ -197,10 +195,32 @@ int atoi(const char *nptr)
|
||||
return (int)strtol(nptr, (char **)NULL, 10);
|
||||
}
|
||||
|
||||
void exec_cfg(u32 *base, const cfg_op_t *ops, u32 num_ops)
|
||||
void reg_write_array(u32 *base, const reg_cfg_t *cfg, u32 num_cfg)
|
||||
{
|
||||
for (u32 i = 0; i < num_ops; i++)
|
||||
base[ops[i].off] = ops[i].val;
|
||||
// Expected register offset is a u32 array index.
|
||||
for (u32 i = 0; i < num_cfg; i++)
|
||||
base[cfg[i].idx] = cfg[i].val;
|
||||
}
|
||||
|
||||
u16 crc16_calc(const u8 *buf, u32 len)
|
||||
{
|
||||
const u8 *p, *q;
|
||||
u16 crc = 0x55aa;
|
||||
|
||||
static u16 table[16] = {
|
||||
0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401,
|
||||
0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400
|
||||
};
|
||||
|
||||
q = buf + len;
|
||||
for (p = buf; p < q; p++)
|
||||
{
|
||||
u8 oct = *p;
|
||||
crc = (crc >> 4) ^ table[crc & 0xf] ^ table[(oct >> 0) & 0xf];
|
||||
crc = (crc >> 4) ^ table[crc & 0xf] ^ table[(oct >> 4) & 0xf];
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
u32 crc32_calc(u32 crc, const u8 *buf, u32 len)
|
||||
@@ -262,7 +282,7 @@ void power_set_state(power_state_t state)
|
||||
sd_end();
|
||||
|
||||
// De-initialize and power down various hardware.
|
||||
hw_reinit_workaround(false, 0);
|
||||
hw_deinit(false, 0);
|
||||
|
||||
// Set power state.
|
||||
switch (state)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2018 naehrwert
|
||||
* Copyright (c) 2018-2022 CTCaer
|
||||
* Copyright (c) 2018-2024 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
@@ -21,8 +21,6 @@
|
||||
#include <utils/types.h>
|
||||
#include <mem/minerva.h>
|
||||
|
||||
#define CFG_SIZE(array) (sizeof(array) / sizeof(cfg_op_t))
|
||||
|
||||
#define NYX_NEW_INFO 0x3058594E
|
||||
|
||||
typedef enum
|
||||
@@ -59,6 +57,12 @@ typedef struct _cfg_op_t
|
||||
u32 val;
|
||||
} cfg_op_t;
|
||||
|
||||
typedef struct _reg_cfg_t
|
||||
{
|
||||
u32 idx;
|
||||
u32 val;
|
||||
} reg_cfg_t;
|
||||
|
||||
typedef struct _nyx_info_t
|
||||
{
|
||||
u32 magic;
|
||||
@@ -88,7 +92,9 @@ u64 sqrt64(u64 num);
|
||||
long strtol(const char *nptr, char **endptr, register int base);
|
||||
int atoi(const char *nptr);
|
||||
|
||||
void reg_write_array(u32 *base, const reg_cfg_t *cfg, u32 num_cfg);
|
||||
void exec_cfg(u32 *base, const cfg_op_t *ops, u32 num_ops);
|
||||
u16 crc16_calc(const u8 *buf, u32 len);
|
||||
u32 crc32_calc(u32 crc, const u8 *buf, u32 len);
|
||||
|
||||
void panic(u32 val);
|
||||
|
||||
Reference in New Issue
Block a user