Skip to content
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
57 changes: 57 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
BasedOnStyle: LLVM
MaxEmptyLinesToKeep: 1
ColumnLimit: 120
ExperimentalAutoDetectBinPacking: true

# Pack
PackConstructorInitializers: Never
BinPackParameters: false
BinPackArguments: false

# Indentation
UseTab: Always
IndentWidth: 4
ContinuationIndentWidth: 4
TabWidth: 4
AccessModifierOffset: -4
IndentCaseBlocks: false
IndentCaseLabels: false

# Namespace
CompactNamespaces: true
NamespaceIndentation: None
FixNamespaceComments: true

# Allow
AllowShortLambdasOnASingleLine: Inline
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false

# Align
AlignConsecutiveShortCaseStatements:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AlignCaseColons: false
AlignAfterOpenBracket: AlwaysBreak
AlignEscapedNewlines: Left

# Break
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
# BreakConstructorInitializers: AfterColon
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true

# Insert
InsertBraces: false
InsertNewlineAtEOF: true

# Remove
RemoveBracesLLVM: true
KeepEmptyLines:
AtStartOfFile: false
AtStartOfBlock: false
AtEndOfFile: false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ docs
warn.log
*.bz2
*~
*.json
14 changes: 12 additions & 2 deletions include/nds/arm9/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ typedef struct PrintConsole

bool consoleInitialised; /*!< True if the console is initialized */
bool loadGraphics; /*!< True if consoleInit should attempt to load font graphics into background memory */

int bg2Id; // ID of bg used for ANSI background colors!
u16 *fontBg2Map, *fontBg2Gfx; // map & gfx for the 2nd bg
u16 fontCurPal2; // palette for background colors

// Internal buffer for potential ANSI escape sequences, as all the characters may not be available in one con_write() call.
char escBuf[32];
int escBufLen;
}PrintConsole;


Expand Down Expand Up @@ -198,7 +206,7 @@ void consoleSetWindow(PrintConsole* console, int x, int y, int width, int height
this should only be used when using a single console or without changing the console that is returned, other wise use consoleInit()
\return A pointer to the console with the default values
*/
PrintConsole* consoleGetDefault(void);
const PrintConsole* consoleGetDefault(void);

/*! \brief Make the specified console the render target
\param console A pointer to the console struct (must have been initialized with consoleInit(PrintConsole* console)
Expand All @@ -215,9 +223,11 @@ PrintConsole *consoleSelect(PrintConsole* console);
\param tileBase the tile graphics base
\param mainDisplay if true main engine is used, otherwise false
\param loadGraphics if true the default font graphics will be loaded into the layer
\param ansiBgColors if true, uses `layer + 1` and `tileBase + 1` for ANSI background color escape sequences.
make sure the next initialized console does not use `layer + 1` and `tileBase + 1` !
\return A pointer to the current console.
*/
PrintConsole* consoleInit(PrintConsole* console, int layer, BgType type, BgSize size, int mapBase, int tileBase, bool mainDisplay, bool loadGraphics);
PrintConsole* consoleInit(PrintConsole* console, int layer, BgType type, BgSize size, int mapBase, int tileBase, bool mainDisplay, bool loadGraphics, bool ansiBgColors);

/*! \brief Initialize the console to a default state for prototyping.
This function sets the console to use sub display, VRAM_C, and BG0 and enables MODE_0_2D on the
Expand Down
96 changes: 96 additions & 0 deletions source/arm9/console-cursor.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*---------------------------------------------------------------------------------

Copyright (C) 2025
trustytrojan

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.

Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.

---------------------------------------------------------------------------------*/
#include "console-priv.h"

// These save the palette and character of whatever tile the cursor moves on top of.
// fb2mv should always contain the full block ASCII character (219).
static u16 fbmvUnderCursor, fb2mvUnderCursor;

void consoleSaveTileUnderCursor(void) {
fbmvUnderCursor = *consoleFontBgMapAtCursor();
fb2mvUnderCursor = *consoleFontBg2MapAtCursor();
}

void consoleRestoreTileUnderCursor(void) {
*consoleFontBgMapAtCursor() = fbmvUnderCursor;
*consoleFontBg2MapAtCursor() = fb2mvUnderCursor;
}

void consoleDrawCursor(void) {
// foreground: this is the character itself. we need to turn it black,
// which would usually be a fontCurPal of (0 << 12). however fbmvUnderCursor
// is not being computed on the fly (like below), so 99% of the time it
// does not have those bits zeroed inside. (who uses black on black?)
// so we need to zero-out those bits to make it black:
*consoleFontBgMapAtCursor() = 0x0fff & fbmvUnderCursor;

// background: just use bright write (15)
*consoleFontBg2MapAtCursor() = (15 << 12) | consoleComputeFontBg2MapValue(219);
}

void consoleSetCursorPos(const int x, const int y) {
if (currentConsole->bg2Id != -1)
consoleRestoreTileUnderCursor();

currentConsole->cursorX = x;
currentConsole->cursorY = y;

if (currentConsole->bg2Id != -1) {
consoleSaveTileUnderCursor();

// original tile saved! now let's make the cursor visible with
// white background and black foreground.
consoleDrawCursor();
}
}

void consoleSetCursorY(const int y) {
consoleSetCursorPos(currentConsole->cursorX, y);
}

void consoleSetCursorX(const int x) {
consoleSetCursorPos(x, currentConsole->cursorY);
}

int clamp(const int n, const int min, const int max) {
if (n < min)
return min;
if (n > max)
return max;
return n;
}

void consoleMoveCursorX(const int dx) {
const PrintConsole *const c = currentConsole;
const int newX = c->cursorX + dx;
const int maxX = c->windowWidth - 1;
consoleSetCursorX(clamp(newX, 0, maxX));
}

void consoleMoveCursorY(const int dy) {
const PrintConsole *const c = currentConsole;
const int newY = c->cursorY + dy;
const int maxY = c->windowHeight - 1;
consoleSetCursorY(clamp(newY, 0, maxY));
}
Loading