Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ DEVKITARM ?= /opt/devkitpro/devkitARM

VERSION ?= $(cat include/version.h)

GAME_TITLE := dslibris
GAME_SUBTITLE1 := An EPUB ebook reader [$(VERSION)]
GAME_SUBTITLE2 := https://github.com/rhaleblian/dslibris
GAME_TITLE := DSLibris
GAME_SUBTITLE1 := An EPUB ebook reader
GAME_SUBTITLE2 := Ray H., Adrian Gj. Et al.
GAME_ICON := $(PWD)/gfx/icon.bmp

include $(DEVKITARM)/ds_rules
Expand Down Expand Up @@ -45,7 +45,7 @@ LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -lfat -lnds9 -lexpat -lz -lbz2 -lpng -lfreetype
LIBS := -lfat -lnds9 -lexpat -lz -lbz2 -lpng -lfreetype -lauxmem

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
Expand Down
Binary file modified etc/dldi/r4tf_v2.dldi
Binary file not shown.
22 changes: 22 additions & 0 deletions etc/dldi/r4tf_v2.dldi.idx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
SIZE 268435456
DIR 0 Book
DIR 0 Font
FILE 0 163854 -4685926895 1530297228 Book/Dune, part 2.epub
FILE 0 127504 -4685926847 1530297228 Book/Dune, part 3.epub
FILE 0 25254 -4685926819 1530297228 Book/Dune, part 4 appendix.epub
FILE 0 23306 -4685926796 1530297228 Book/Dune, part 5 terminology and extra.epub
FILE 0 205159 -4685926956 1530297228 Book/Dune, part1.epub
FILE 0 24293016 -4718926683 1530297228 Book/The Book of Ramen.epub
FILE 0 7374860 -4717918353 1530297228 Book/The Offical Highway Code - 2022 edition_ DVSA Safe Driving -- Driver & Vehicle Standards Agency, Great Britain_ Department -- 2022 -- The Stationery -- 9780115539954 -- 190f5fac1304fa117bf1e10252eb2fe5 -- Anna’s Archive.epub
FILE 0 5611 -4684215544 1530297228 Book/quickstart.epub
FILE 0 3958 -4717276422 1530297228 Book/releasenotes.epub
FILE 0 681914 -4680030733 1530297228 Book/william-shakespeare_macbeth_advanced.epub
FILE 0 110660 -4717473884 1530297228 Font/LiberationSans-Regular.ttf
FILE 0 167428 -4717473884 1530297228 Font/LiberationSerif-Bold.ttf
FILE 0 171264 -4717473884 1530297228 Font/LiberationSerif-BoldItalic.ttf
FILE 0 164936 -4717473884 1530297228 Font/LiberationSerif-Italic.ttf
FILE 0 172736 -4717473884 1530297228 Font/LiberationSerif-Regular.ttf
FILE 0 2097152 -4679112417 1530297359 dslibris.nds
FILE 0 0 -4679112695 1530297228 dslibris.swap
FILE 0 0 -4679115820 1530297228 dslibris.xml
FILE 0 5 -4679112676 1530297232 fileName.txt
2 changes: 2 additions & 0 deletions gfx/LISCENCE_MEGAICON
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
As part of the splash:
"Book" by Honza M. is licensed under CC BY 2.0.
Binary file modified gfx/icon.bmp
Binary file not shown.
Binary file removed gfx/icon.psd
Binary file not shown.
Binary file added gfx/megaicon.kra
Binary file not shown.
Binary file modified gfx/megaicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions gfx/splash.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
// splash, 256x256@16,
// Alphabit on.
// + bitmap lz77 compressed
// Total size: 18304 = 18304
// Total size: 33284 = 33284
//
// Time-stamp: 2020-05-28, 20:21:06
// Exported by Cearn's GBA Image Transmogrifier, v0.8.15
// Time-stamp: 2025-09-25, 23:02:59
// Exported by Cearn's GBA Image Transmogrifier, v0.9.2
// ( http://www.coranac.com/projects/#grit )
//
//======================================================================

#ifndef GRIT_SPLASH_H
#define GRIT_SPLASH_H

#define splashBitmapLen 18304
extern const unsigned int splashBitmap[4576];
#define splashBitmapLen 33284
extern const unsigned int splashBitmap[8321];

#endif // GRIT_SPLASH_H

Expand Down
Binary file modified gfx/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed gfx/splash.psd
Binary file not shown.
1,822 changes: 1,175 additions & 647 deletions gfx/splash.s

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions include/button.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class Button {
//! label on second line, used for author in the library screen.
void SetLabel2(std::string s);
inline void SetStyle(int astyle) { style = astyle; };
void Draw(u16 *fb, bool highlight = false);
void Draw(u16 *fb, bool highlight, bool ui);
inline void Draw(bool highlight = false) {
Draw(ts->GetScreen(), highlight);
Draw(ts->GetScreen(), highlight, true);
}
void Move(u16 x, u16 y);
void Resize(u16 x, u16 y);
Expand Down
3 changes: 3 additions & 0 deletions include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include FT_FREETYPE_H
#include "nds.h"
#include "splash.h"
#include "app.h"

#define MARGINLEFT 12
#define MARGINRIGHT 12
Expand Down Expand Up @@ -53,3 +54,5 @@ int halt(const char *msg, int vblanks = -1);
int getSize(u8 *source, u16 *dest, u32 arg);
u8 readByte(u8 *source);
void drawstack(u16 *screen);

extern App* app;
5 changes: 4 additions & 1 deletion include/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ A Book contains a vector of Pages.
#pragma once

#include <nds.h>
#include <auxmem.h>

#include "book.h"
#include "text.h"

Expand All @@ -36,6 +38,7 @@ class Page {
public:
//! UTF-8 chars, allocated per-page at parse time, to exact length.
u8 *buf;
//AM_addr_t buffer;
//! Length of buf.
int length;
//! In a book-long char buffer, where would i begin?
Expand All @@ -45,7 +48,7 @@ class Page {
Page(Book *b);
Page(Book *b, Text *t);
~Page();
u8* GetBuffer() { return buf; }
//u8* GetBuffer() { return (u8*)"TEST"; } //TODO
int GetLength() { return length; }
//! Copy src to buf for len bytes.
u8 SetBuffer(u8 *src, u16 len);
Expand Down
10 changes: 10 additions & 0 deletions include/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

#define CACHESIZE 512

#define SCREENRIGHT BG_BMP_RAM(0)
#define SCREENRIGHT2 BG_BMP_RAM(8)
#define SCREENLEFT BG_BMP_RAM_SUB(0)

class App;
int asciiart();
const char* ErrorString(u8);
Expand Down Expand Up @@ -81,6 +85,8 @@ class Text {
bool usebgcolor;
//! Pointers to screens and which one is current.
u16 *screen, *screenleft, *screenright;
int bg_main;

//! Offscreen buffer. Only used when OFFSCREEN defined.
u16 *offscreen;
struct {
Expand All @@ -95,6 +101,9 @@ class Text {
Text();
Text(class App *parent) { app = parent; }
~Text();

void UpdateMain();

int Init();
void InitPen(void);
void Begin();
Expand Down Expand Up @@ -134,6 +143,7 @@ class Text {
void ClearRect(u16 xl, u16 yl, u16 xh, u16 yh);
void ClearScreen();
void ClearScreen(u16*, u8, u8, u8);
void ClearScreenSpecial();
void CopyScreen(u16 *src, u16 *dst);
void SwapScreens();

Expand Down
2 changes: 1 addition & 1 deletion include/version.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define VERSION "1.6.0"
#define VERSION "ag0.1"
40 changes: 40 additions & 0 deletions portlibs/nds/include/auxmem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifdef __cplusplus
extern "C" {
#endif

#ifndef AUXMEM_H
#define AUXMEM_H

#include <stddef.h>
#include <stdint.h>

typedef size_t AM_addr_t;
typedef enum {
AM_SUCCESS, //Complete Success
AM_FAILURE, //Complete Failure
//TODO comprehensive error states
} AM_error_t;

extern AM_error_t AM_error_g;

extern void AM_init(const char * file, size_t size);

extern void AM_setbyte(AM_addr_t address, uint8_t byte_value);
extern uint8_t AM_getbyte(AM_addr_t address);

extern void AM_setbytes(AM_addr_t address, uint8_t * byte_array, size_t size);
extern void AM_getbytes(AM_addr_t address, uint8_t * byte_array, size_t size);
extern uint8_t * AM_getbytes_heap(AM_addr_t address, size_t size);

/*
extern void AM_set_strcap(size_t str_cap);
extern void AM_setstring(AM_addr_t address, const char * string);
*/

extern void AM_quit();

#endif

#ifdef __cplusplus
}
#endif
27 changes: 27 additions & 0 deletions portlibs/nds/include/auxmem/heap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifdef __cplusplus
extern "C" {
#endif

#ifndef AUXMEM_HEAP_H
#define AUXMEM_HEAP_H

#include <auxmem.h>
#include <stdlib.h>
#include <stdbool.h>

#define AMALLOC_NULL 0

extern void AMALLOC_init(uint16_t blocksize);

extern AM_addr_t AMALLOC_alloc(size_t size);
extern void AMALLOC_free(size_t address);
extern void AMALLOC_clean();

extern size_t AMALLOC_getfree();
extern bool AMALLOC_isempty();

#endif

#ifdef __cplusplus
}
#endif
Binary file added portlibs/nds/lib/libauxmem.a
Binary file not shown.
65 changes: 45 additions & 20 deletions source/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

#include "app.h"

#include <auxmem.h>
#include <auxmem/heap.h>

#include <errno.h>
#include <stdlib.h>
#include <stdint.h>
Expand All @@ -31,6 +34,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include <unistd.h>
#include <algorithm> // for std::sort
#include <fat.h>
#include <string>

#include "main.h"
#include "parse.h"
Expand Down Expand Up @@ -110,54 +114,70 @@ int App::Run(void)
const int ok = 0;

// Start up typesetter.

if (ts->Init() != ok)
halt("[FAIL] typesetter\n");

//Loading Preferences
prefs->Read();

// Start up screens.

InitScreens();
SetOrientation(orientation);
ts->SetStyle(TEXT_STYLE_BROWSER);
ts->PrintSplash(ts->screenleft);

/*
// Initializing AUXMEM
PrintStatus("Initializing Swap... Please wait");
AM_init((const char * )"dslibris.swap", (size_t) 16 * 1024 * 1024); //16 MiB swap file (investigate why I can't go higher)
AMALLOC_init(128);
//AM_setbyte(0x01, 0xFF);
*/

// Construct library.

PrintStatus("Loading Books... Please wait");
if (FindBooks() != ok)
halt("[FAIL] no book directory\n");
if (bookcount == 0)
halt("[FAIL] no books\n");

std::sort(books.begin(),books.end(),&book_title_lessthan);

prefs->Read();
prefs->Read(); //For some daft reason we need to load this twice else you allways start from the first page
for(auto &book : books)
{
book->Index();
book->GetBookmarks()->sort();
}

// Set up menus.

PrefsInit();
browser_init();
browser_view_dirty = true;

PrintStatus(VERSION);

// Display Version
std::string status = "version ";
PrintStatus((status + VERSION).c_str());

// Resume reading from the last session.

// char msg[32]; sprintf(msg, "%d\n", bookcurrent); halt(msg);
if(reopen && bookcurrent) {
bookselected = bookcurrent;
OpenBook();
}


keysSetRepeat(60,2);
while (pmMainLoop())
{
swiWaitForVBlank();
scanKeys();

if((keysHeld() & KEY_START) && (keysHeld() & KEY_SELECT))
exit(0);

if(mode == APP_MODE_BOOK)
bgSetMapBase(ts->bg_main, 0);
else
bgSetMapBase(ts->bg_main, 8);

switch (mode) {
case APP_MODE_BOOK:
HandleEventInBook();
Expand Down Expand Up @@ -186,6 +206,8 @@ int App::Run(void)
if (fontmenu->isDirty()) fontmenu->draw();
break;
}
swiWaitForVBlank();
ts->UpdateMain();
}
return 0;
}
Expand Down Expand Up @@ -304,8 +326,8 @@ void App::SetOrientation(bool turned_right)
REG_BG3Y = 0 << 8;
REG_BG3X_SUB = 191 << 8;
REG_BG3Y_SUB = 0 << 8;
ts->screenright = (u16*)BG_BMP_RAM_SUB(0);
ts->screenleft = (u16*)BG_BMP_RAM(0);
ts->screenleft = (u16*)SCREENLEFT;
ts->screenright = (u16*)SCREENRIGHT;
orientation = true;
// TODO put this in user coords
key.down = KEY_UP;
Expand All @@ -323,8 +345,8 @@ void App::SetOrientation(bool turned_right)
REG_BG3Y = 255 << 8;
REG_BG3X_SUB = 0 << 8;
REG_BG3Y_SUB = 255 << 8;
ts->screenright = (u16*)BG_BMP_RAM_SUB(0);
ts->screenleft = (u16*)BG_BMP_RAM(0);
ts->screenleft = (u16*)SCREENLEFT;
ts->screenright = (u16*)SCREENRIGHT;
orientation = false;
// TODO put this in user coords
key.down = KEY_DOWN;
Expand All @@ -347,19 +369,22 @@ void App::SetOrientation(bool turned_right)
void App::InitScreens()
{
videoSetMode(MODE_5_2D);
vramSetBankA(VRAM_A_MAIN_BG);
bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 0,0);
vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
vramSetBankB(VRAM_B_MAIN_BG_0x06020000);
ts->bg_main = bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 0,0);
videoSetModeSub(MODE_5_2D);
vramSetBankC(VRAM_C_SUB_BG);
vramSetBankC(VRAM_C_SUB_BG_0x06200000);
bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 0,0);

bgSetMapBase(ts->bg_main, 8);
ts->SetScreen(ts->screenright);
ts->ClearScreen();
ts->SetScreen(ts->screenleft);
ts->ClearScreen();
SetOrientation(orientation);
if(invert) {
if(!invert) {
lcdSwap();
}
ts->UpdateMain();
}

void App::PrintStatus(const char *msg)
Expand Down
Loading