DS: Improve text console support

This commit is contained in:
Cameron Cawley 2020-08-06 17:24:14 +01:00 committed by Eugene Sandulenko
parent 438c2d8714
commit 704deec031
4 changed files with 59 additions and 159 deletions

View File

@ -123,10 +123,8 @@ static int subScreenScale = 256;
static bool highBuffer;
static bool displayModeIs8Bit = false;
static bool consoleEnable = false;
static bool gameScreenSwap = false;
bool isCpuScalerEnabled();
//#define HEAVY_LOGGING
static int storedMouseX = 0;
static int storedMouseY = 0;
@ -156,8 +154,6 @@ static bool cpuScalerEnable = false;
static u8 *scalerBackBuffer = NULL;
static u16 savedPalEntry255 = RGB15(31, 31, 31);
void setIcon(int num, int x, int y, int imageNum, int flags, bool enable);
void setIconMain(int num, int x, int y, int imageNum, int flags, bool enable);
@ -251,38 +247,15 @@ void setUnscaledMode(bool enable) {
}
void displayMode8Bit() {
#ifdef HEAVY_LOGGING
printf("displayMode8Bit...");
#endif
u16 buffer[32 * 32];
setOptions();
if (!displayModeIs8Bit) {
for (int r = 0; r < 32 * 32; r++) {
buffer[r] = ((u16 *) SCREEN_BASE_BLOCK_SUB(4))[r];
}
} else {
for (int r = 0; r < 32 * 32; r++) {
buffer[r] = ((u16 *) SCREEN_BASE_BLOCK(2))[r];
}
}
displayModeIs8Bit = true;
videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP);
vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
vramSetBankB(VRAM_B_MAIN_BG_0x06020000);
if (isCpuScalerEnabled()) {
videoSetMode(MODE_5_2D | (consoleEnable ? DISPLAY_BG0_ACTIVE : 0) | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP);
videoSetModeSub(MODE_3_2D /*| DISPLAY_BG0_ACTIVE*/ | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP); //sub bg 0 will be used to print text
vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
vramSetBankB(VRAM_B_MAIN_BG_0x06020000);
vramSetBankC(VRAM_C_SUB_BG_0x06200000);
vramSetBankD(VRAM_D_SUB_SPRITE);
vramSetBankH(VRAM_H_LCD);
REG_BG3CNT = BG_BMP16_256x256 | BG_BMP_BASE(8);
REG_BG3PA = 256;
@ -291,17 +264,6 @@ void displayMode8Bit() {
REG_BG3PD = (int) ((200.0f / 192.0f) * 256);
} else {
videoSetMode(MODE_5_2D | (consoleEnable ? DISPLAY_BG0_ACTIVE : 0) | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP);
videoSetModeSub(MODE_3_2D /*| DISPLAY_BG0_ACTIVE*/ | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP); //sub bg 0 will be used to print text
vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
vramSetBankB(VRAM_B_MAIN_BG_0x06020000);
vramSetBankC(VRAM_C_SUB_BG_0x06200000);
vramSetBankD(VRAM_D_SUB_SPRITE);
vramSetBankH(VRAM_H_LCD);
REG_BG3CNT = BG_BMP8_512x256 | BG_BMP_BASE(8);
REG_BG3PA = (int) (((float) (gameWidth) / 256.0f) * 256);
@ -310,36 +272,17 @@ void displayMode8Bit() {
REG_BG3PD = (int) ((200.0f / 192.0f) * 256);
}
#ifdef DISABLE_TEXT_CONSOLE
videoSetModeSub(MODE_3_2D | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP);
vramSetBankC(VRAM_C_SUB_BG_0x06200000);
vramSetBankD(VRAM_D_SUB_SPRITE);
REG_BG3CNT_SUB = BG_BMP8_512x256;
REG_BG3PA_SUB = (int) (subScreenWidth / 256.0f * 256);
REG_BG3PB_SUB = 0;
REG_BG3PC_SUB = 0;
REG_BG3PD_SUB = (int) (subScreenHeight / 192.0f * 256);
consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 2, 0, true, true);
// Set this again because consoleinit resets it
videoSetMode(MODE_5_2D | (consoleEnable ? DISPLAY_BG0_ACTIVE : 0) | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP);
// Move the cursor to the bottom of the screen using ANSI escape code
printf("\033[23;0f");
for (int r = 0; r < 32 * 32; r++) {
((u16 *) SCREEN_BASE_BLOCK(2))[r] = buffer[r];
}
// ConsoleInit destroys the hardware palette :-(
if (OSystem_DS::instance()) {
OSystem_DS::instance()->restoreHardwarePalette();
}
#ifdef HEAVY_LOGGING
printf("done\n");
#endif
#endif
if (gameScreenSwap) {
lcdMainOnTop();
@ -391,79 +334,34 @@ void setCursorIcon(const u8 *icon, uint w, uint h, byte keycolor, int hotspotX,
void displayMode16Bit() {
#ifdef HEAVY_LOGGING
printf("displayMode16Bit...");
#endif
u16 buffer[32 * 32 * 2];
if (!displayModeIs8Bit) {
for (int r = 0; r < 32 * 32; r++) {
buffer[r] = ((u16 *) SCREEN_BASE_BLOCK_SUB(4))[r];
}
} else {
if (displayModeIs8Bit) {
saveGameBackBuffer();
for (int r = 0; r < 32 * 32; r++) {
buffer[r] = ((u16 *) SCREEN_BASE_BLOCK(2))[r];
}
}
videoSetMode(MODE_5_2D | /*DISPLAY_BG0_ACTIVE |*/ DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP);
videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP); //sub bg 0 will be used to print text
videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP);
vramSetBankA(VRAM_A_MAIN_BG);
vramSetBankB(VRAM_B_MAIN_BG);
vramSetBankC(VRAM_C_MAIN_BG);
vramSetBankD(VRAM_D_MAIN_BG);
vramSetBankH(VRAM_H_SUB_BG);
REG_BG3CNT = BG_BMP16_512x256;
highBuffer = false;
memset(BG_GFX, 0, 512 * 256 * 2);
savedPalEntry255 = BG_PALETTE_SUB[255];
BG_PALETTE_SUB[255] = RGB15(31,31,31);//by default font will be rendered with color 255
// Do text stuff
REG_BG0CNT_SUB = BG_MAP_BASE(4) | BG_TILE_BASE(0);
REG_BG0VOFS_SUB = 0;
consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 4, 0, false, true);
for (int r = 0; r < 32 * 32; r++) {
((u16 *) SCREEN_BASE_BLOCK_SUB(4))[r] = buffer[r];
}
consoleSetWindow(NULL, 0, 0, 32, 24);
lcdMainOnBottom();
displayModeIs8Bit = false;
// ConsoleInit destroys the hardware palette :-(
OSystem_DS::instance()->restoreHardwarePalette();
REG_BG3PA = isCpuScalerEnabled() ? 256 : (int) (1.25f * 256);
REG_BG3PB = 0;
REG_BG3PC = 0;
REG_BG3PD = (int) ((200.0f / 192.0f) * 256);
#ifdef HEAVY_LOGGING
printf("done\n");
#endif
BG_PALETTE_SUB[255] = RGB15(31,31,31);//by default font will be rendered with color 255
}
void displayMode16BitFlipBuffer() {
#ifdef HEAVY_LOGGING
printf("Flip %s...", displayModeIs8Bit ? "8bpp" : "16bpp");
#endif
if (!displayModeIs8Bit) {
u16 *back = get16BitBackBuffer();
@ -485,9 +383,6 @@ void displayMode16BitFlipBuffer() {
BG_PALETTE,
getGameHeight() );
}
#ifdef HEAVY_LOGGING
printf("done\n");
#endif
}
void setShakePos(int shakeXOffset, int shakeYOffset) {
@ -604,9 +499,10 @@ void setZoomedScreenScroll(int x, int y, bool shake) {
touchY = y >> 8;
}
#ifdef DISABLE_TEXT_CONSOLE
REG_BG3X_SUB = x + ((shake && (frameCount & 1) == 0)? 64: 0);
REG_BG3Y_SUB = y;
#endif
}
void setZoomedScreenScale(int x, int y) {
@ -615,10 +511,12 @@ void setZoomedScreenScale(int x, int y) {
touchScY = y;
}
#ifdef DISABLE_TEXT_CONSOLE
REG_BG3PA_SUB = x;
REG_BG3PB_SUB = 0;
REG_BG3PC_SUB = 0;
REG_BG3PD_SUB = y;
#endif
}
Common::Point transformPoint(uint16 x, uint16 y) {
@ -767,22 +665,11 @@ void setTopScreenTarget(int x, int y) {
void initHardware() {
powerOn(POWER_ALL);
vramSetBankD(VRAM_D_SUB_SPRITE);
vramSetBankE(VRAM_E_MAIN_SPRITE);
for (int r = 0; r < 255; r++) {
BG_PALETTE[r] = 0;
}
BG_PALETTE[255] = RGB15(0,31,0);
for (int r = 0; r < 255; r++) {
BG_PALETTE_SUB[r] = 0;
}
BG_PALETTE_SUB[255] = RGB15(0,31,0);
// Allocate save buffer for game screen
displayMode16Bit();
@ -800,8 +687,6 @@ void initHardware() {
frameCount = 0;
callback = NULL;
BG_PALETTE[255] = RGB15(31,31,31);//by default font will be rendered with color 255
//irqs are nice
irqSet(IRQ_VBLANK, VBlankHandler);
irqEnable(IRQ_VBLANK);
@ -811,7 +696,16 @@ void initHardware() {
timerStart(0, ClockDivider_1, (u16)TIMER_FREQ(1000), timerTickHandler);
REG_IME = 1;
BG_PALETTE[255] = RGB15(0,0,31);
videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP);
vramSetBankD(VRAM_D_SUB_SPRITE);
vramSetBankE(VRAM_E_MAIN_SPRITE);
#ifndef DISABLE_TEXT_CONSOLE
vramSetBankH(VRAM_H_SUB_BG);
consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true);
printf("Testing the console\n");
#endif
initSprites();
@ -838,7 +732,7 @@ void *fastRamAlloc(int size) {
void *result = (void *) fastRamPointer;
fastRamPointer += size;
if(fastRamPointer > fastRamData + FAST_RAM_SIZE) {
printf("FastRam (ITCM) allocation failed!\n");
warning("FastRam (ITCM) allocation failed");
return malloc(size);
}
return result;
@ -855,20 +749,10 @@ void fastRamReset() {
/////////////////
int main(int argc, char **argv) {
#ifndef DISABLE_TEXT_CONSOLE
consoleDebugInit(DebugDevice_NOCASH);
nocashMessage("startup\n");
#endif
DS::initHardware();
defaultExceptionHandler();
if (!nitroFSInit(NULL)) {
printf("nitroFSInit failure: terminating\n");
return(1);
}
g_system = new OSystem_DS();
assert(g_system);

View File

@ -27,6 +27,9 @@
#define FORBIDDEN_SYMBOL_EXCEPTION_printf
#define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
#include <nds.h>
#include <filesystem.h>
#include "common/scummsys.h"
#include "common/system.h"
@ -36,7 +39,6 @@
#include "common/translation.h"
#include "osystem_ds.h"
#include "nds.h"
#include "dsmain.h"
#include "common/config-manager.h"
#include "common/str.h"
@ -58,6 +60,8 @@ OSystem_DS::OSystem_DS()
_disableCursorPalette(true), _graphicsEnable(true), _gammaValue(0)
{
_instance = this;
nitroFSInit(NULL);
_fsFactory = new DevoptabFilesystemFactory();
}
@ -142,7 +146,9 @@ void OSystem_DS::setPalette(const byte *colors, uint start, uint num) {
if (DS::getIsDisplayMode8Bit()) {
int col = applyGamma(paletteValue);
BG_PALETTE[r] = col;
#ifdef DISABLE_TEXT_CONSOLE
BG_PALETTE_SUB[r] = col;
#endif
}
_palette[r] = paletteValue;
@ -152,16 +158,6 @@ void OSystem_DS::setPalette(const byte *colors, uint start, uint num) {
}
}
void OSystem_DS::restoreHardwarePalette() {
// Set the hardware palette up based on the stored palette
for (int r = 0; r < 255; r++) {
int col = applyGamma(_palette[r]);
BG_PALETTE[r] = col;
BG_PALETTE_SUB[r] = col;
}
}
void OSystem_DS::setCursorPalette(const byte *colors, uint start, uint num) {
for (unsigned int r = start; r < start + num; r++) {
@ -202,7 +198,9 @@ void OSystem_DS::copyRectToScreen(const void *buf, int pitch, int x, int y, int
u16 *bg;
s32 stride;
#ifdef DISABLE_TEXT_CONSOLE
u16 *bgSub = (u16 *)BG_GFX_SUB;
#endif
// The DS video RAM doesn't support 8-bit writes because Nintendo wanted
// to save a few pennies/euro cents on the hardware.
@ -224,7 +222,9 @@ void OSystem_DS::copyRectToScreen(const void *buf, int pitch, int x, int y, int
for (int dy = y; dy < y + h; dy++) {
u8 *dest = ((u8 *) (bg)) + (dy * stride) + x;
#ifdef DISABLE_TEXT_CONSOLE
u8 *destSub = ((u8 *) (bgSub)) + (dy * 512) + x;
#endif
const u8 *src = (const u8 *) buf + (pitch * by);
u32 dx;
@ -240,23 +240,32 @@ void OSystem_DS::copyRectToScreen(const void *buf, int pitch, int x, int y, int
mix = (mix & 0x00FF) | (*src++ << 8);
*dest = mix;
#ifdef DISABLE_TEXT_CONSOLE
*destSub = mix;
#endif
dest += 2;
#ifdef DISABLE_TEXT_CONSOLE
destSub += 2;
#endif
pixelsLeft--;
}
// We can now assume dest is aligned
u16 *dest16 = (u16 *) dest;
#ifdef DISABLE_TEXT_CONSOLE
u16 *destSub16 = (u16 *) destSub;
#endif
for (dx = 0; dx < pixelsLeft; dx+=2) {
u16 mix;
mix = *src + (*(src + 1) << 8);
*dest16++ = mix;
#ifdef DISABLE_TEXT_CONSOLE
*destSub16++ = mix;
#endif
src += 2;
}
@ -270,7 +279,9 @@ void OSystem_DS::copyRectToScreen(const void *buf, int pitch, int x, int y, int
mix = (mix & 0x00FF) | ((*src++) << 8);
*dest16 = mix;
#ifdef DISABLE_TEXT_CONSOLE
*destSub16 = mix;
#endif
}
by++;
@ -285,17 +296,23 @@ void OSystem_DS::copyRectToScreen(const void *buf, int pitch, int x, int y, int
for (int dy = y; dy < y + h; dy++) {
u16 *dest1 = bg + (dy * (stride >> 1)) + (x >> 1);
#ifdef DISABLE_TEXT_CONSOLE
u16 *dest2 = bgSub + (dy << 8) + (x >> 1);
#endif
DC_FlushRange(src, w << 1);
DC_FlushRange(dest1, w << 1);
#ifdef DISABLE_TEXT_CONSOLE
DC_FlushRange(dest2, w << 1);
#endif
dmaCopyHalfWords(3, src, dest1, w);
#ifdef DISABLE_TEXT_CONSOLE
if ((!_frameBufferExists) || (buf == _framebuffer.getPixels())) {
dmaCopyHalfWords(2, src, dest2, w);
}
#endif
while (dmaBusy(2) || dmaBusy(3));
@ -520,9 +537,8 @@ void OSystem_DS::clearFocusRectangle() {
void OSystem_DS::logMessage(LogMessageType::Type type, const char *message) {
#ifndef DISABLE_TEXT_CONSOLE
nocashMessage((char *)message);
#endif
printf("%s", message);
#endif
}
u16 OSystem_DS::applyGamma(u16 color) {

View File

@ -84,8 +84,6 @@ protected:
virtual void grabPalette(byte *colors, uint start, uint num) const;
public:
void restoreHardwarePalette();
virtual void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h);
virtual void updateScreen();
virtual void setShakePos(int shakeXOffset, int shakeYOffset);

6
configure vendored
View File

@ -1881,7 +1881,7 @@ else
fi
case $_host in
arm-*riscos | caanoo | gp2x | gp2xwiz | openpandora | psp | psp2 | switch)
arm-*riscos | caanoo | ds | gp2x | gp2xwiz | openpandora | psp | psp2 | switch)
if test "$_debug_build" = auto; then
# If you want to debug one of these platforms, use '--disable-optimizations --enable-debug'
_debug_build=no
@ -3401,12 +3401,14 @@ if test -n "$_host"; then
_port_mk="backends/platform/dc/dreamcast.mk"
;;
ds)
if test "$_debug_build" != yes; then
append_var DEFINES "-DDISABLE_TEXT_CONSOLE"
fi
append_var DEFINES "-DDISABLE_COMMAND_LINE"
append_var DEFINES "-DDISABLE_DOSBOX_OPL"
append_var DEFINES "-DDISABLE_FANCY_THEMES"
append_var DEFINES "-DDISABLE_SID"
append_var DEFINES "-DDISABLE_NES_APU"
append_var DEFINES "-DDISABLE_TEXT_CONSOLE"
append_var DEFINES "-DREDUCE_MEMORY_USAGE"
append_var DEFINES "-DSTREAM_AUDIO_FROM_DISK"
append_var DEFINES "-DVECTOR_RENDERER_FORMAT=1555"