Browse Source

fix SHIFT/CTRL+L not working, restore old rendering code, minor improvements, enable R: device (not working yet?)

master
Adrian Siekierka 2 years ago
parent
commit
520bad0890
7 changed files with 88 additions and 60 deletions
  1. 3
    2
      Makefile.3ds
  2. 2
    2
      src/3ds/config.h
  3. 17
    34
      src/3ds/input.c
  4. 5
    0
      src/3ds/main.c
  5. 1
    4
      src/3ds/sound_ndsp.c
  6. 57
    15
      src/3ds/video.c
  7. 3
    3
      src/3ds/video.h

+ 3
- 2
Makefile.3ds View File

@@ -85,6 +85,7 @@ SOURCES = \
src/pia.c \
src/pokey.c \
src/pokeysnd.c \
src/rdevice.c \
src/remez.c \
src/rtime.c \
src/screen.c \
@@ -114,7 +115,7 @@ SHADERS = \
#---------------------------------------------------------------------------------
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft

CFLAGS := -g -Wall -O2 -flto -mword-relocations -D_GNU_SOURCE \
CFLAGS := -g -Wall -O2 -mword-relocations -D_GNU_SOURCE \
-fomit-frame-pointer -ffunction-sections \
$(ARCH)

@@ -161,7 +162,7 @@ export OFILES := $(addsuffix .o,$(BINFILES)) \

export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD) -I$(DEVKITPRO)/portlibs/3ds/include/SDL2 \
-I$(CURDIR)/$(BUILD) \
-I$(CURDIR)/src/3ds

export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)

+ 2
- 2
src/3ds/config.h View File

@@ -421,10 +421,10 @@
/* #undef RPI */

/* Define to use R: device. */
/* #undef R_IO_DEVICE */
#define R_IO_DEVICE

/* Define to use IP network connection with the R: device. */
/* #undef R_NETWORK */
#define R_NETWORK

/* Define to use the host serial port with the R: device. */
/* #undef R_SERIAL */

+ 17
- 34
src/3ds/input.c View File

@@ -32,6 +32,7 @@
#include "log.h"
#include "platform.h"
#include "ui.h"
#include "video.h"

int key_control;
int current_key_down = AKEY_NONE;
@@ -39,6 +40,7 @@ int dpad_as_keyboard = 1;
u64 key_down_time = 0;

#define WARMSTART_HOLD_TIME 3*1000
#define AKEY_WAS_SHIFT_CTRL -992

touch_area_t N3DS_touch_areas_key[] = {
{ 2, 130, 22, 22, AKEY_ESCAPE, 0 },
@@ -174,19 +176,7 @@ void N3DS_DrawKeyboard(C3D_Tex *tex)

N3DS_DrawTexture(tex, 0, 0, 0, 0, 320, 240);

if (INPUT_key_shift != 0)
{
N3DS_DrawTexture(tex, 2, 194, 322, 194, 43, 22);
N3DS_DrawTexture(tex, 254, 194, 574, 194, 43, 22);
}

if (N3DS_IsControlPressed())
{
N3DS_DrawTexture(tex, 2, 172, 322, 172, 37, 22);
}

int key_down = current_key_down;
if (key_down == AKEY_SHFT || key_down == AKEY_CTRL) key_down = AKEY_NONE;
if (key_down >= 0) key_down &= ~AKEY_SHFTCTRL;

hidTouchRead(&pos);
@@ -194,6 +184,8 @@ void N3DS_DrawKeyboard(C3D_Tex *tex)
{
touch_area_t* area = &keyTable[i];
if (key_down == area->keycode
|| (INPUT_key_shift != 0 && area->keycode == AKEY_SHFT)
|| (N3DS_IsControlPressed() && area->keycode == AKEY_CTRL)
|| (isTouch && (
(area->keycode == AKEY_START) ||
(area->keycode == AKEY_SELECT) ||
@@ -243,7 +235,7 @@ int PLATFORM_Keyboard(void)

if (kUp & KEY_TOUCH)
{
if (current_key_down != AKEY_CTRL && current_key_down != AKEY_SHFT)
if (current_key_down != AKEY_WAS_SHIFT_CTRL)
{
INPUT_key_shift = 0;
key_control = 0;
@@ -316,14 +308,13 @@ int PLATFORM_Keyboard(void)
{
hidTouchRead(&pos);
touch_area_t* keyTable = N3DS_TOUCH_AREAS;
int keyTableLen = N3DS_TOUCH_AREA_MAX;
bool down = (kDown & KEY_TOUCH) != 0;
bool touching = ((kDown | kHeld) & KEY_TOUCH) != 0;
bool refresh = false;

if (down) current_key_down = AKEY_NONE;

for (int i = 0; i < keyTableLen; i++)
for (int i = 0; i < N3DS_TOUCH_AREA_MAX; i++)
{
touch_area_t* area = &keyTable[i];
if (isKeyTouched(&pos, area))
@@ -332,21 +323,15 @@ int PLATFORM_Keyboard(void)
switch (area->keycode)
{
case AKEY_SHFT:
if (down)
{
INPUT_key_shift = 1;
Atari800_display_screen = TRUE;
current_key_down = AKEY_SHFT;
}
break;
if (down) Atari800_display_screen = TRUE;
INPUT_key_shift = 1;
current_key_down = AKEY_WAS_SHIFT_CTRL;
return AKEY_NONE;
case AKEY_CTRL:
if (down)
{
key_control = 1;
Atari800_display_screen = TRUE;
current_key_down = AKEY_CTRL;
}
break;
if (down) Atari800_display_screen = TRUE;
key_control = 1;
current_key_down = AKEY_WAS_SHIFT_CTRL;
return AKEY_NONE;
case AKEY_START:
if (touching) INPUT_key_consol &= ~INPUT_CONSOL_START;
break;
@@ -360,10 +345,11 @@ int PLATFORM_Keyboard(void)
if (down)
{
key_down_time = osGetTime();
current_key_down = AKEY_WARMSTART;
current_key_down = AKEY_NONE;
break;
} else if (touching && (osGetTime() - key_down_time) > WARMSTART_HOLD_TIME)
{
Atari800_display_screen = TRUE;
return AKEY_WARMSTART;
}
default:
@@ -377,10 +363,7 @@ int PLATFORM_Keyboard(void)
}

if (refresh) Atari800_display_screen = TRUE;
if (current_key_down == AKEY_SHFT || current_key_down == AKEY_CTRL || current_key_down == AKEY_WARMSTART)
return AKEY_NONE;
else
return current_key_down;
return current_key_down;
}

return AKEY_NONE;

+ 5
- 0
src/3ds/main.c View File

@@ -38,6 +38,7 @@
#ifdef SOUND
#include "../sound.h"
#endif
#include "video.h"
#include "videomode.h"

static bool PLATFORM_IsNew3DS;
@@ -85,6 +86,8 @@ int PLATFORM_Exit(int run_monitor)
} else {
N3DS_ExitVideo();

acExit();

ptmSysmExit();
romfsExit();
}
@@ -100,6 +103,8 @@ int main(int argc, char **argv)
osSetSpeedupEnable(1);
APT_SetAppCpuTimeLimit(80);

acInit();

// set config defaults
PLATFORM_IsNew3DS = PTMSYSM_CheckNew3DS();
POKEYSND_enable_new_pokey = PLATFORM_IsNew3DS;

+ 1
- 4
src/3ds/sound_ndsp.c View File

@@ -42,8 +42,7 @@ void N3DS_ClearAudioData(void);

int PLATFORM_SoundSetup(Sound_setup_t *setup)
{
setup->buffer_frames &= ~3;
setup->sample_size = 1;
setup->buffer_frames = (setup->buffer_frames + 7) & (~0x07);

if (setup->buffer_frames == 0)
{
@@ -74,8 +73,6 @@ void N3DS_SoundCallback(void* dud)
if (N3DS_sound->sample_size > 1)
{
Sound_Callback((u8*) N3DS_audioBuf[N3DS_soundFillBlock].data_pcm8, flen);
for(int i = 0; i < ilen; i++)
invbuf[i] ^= 0x80008000;
} else
{
Sound_Callback((u8*) N3DS_audioBuf[N3DS_soundFillBlock].data_pcm8, flen);

+ 57
- 15
src/3ds/video.c View File

@@ -51,6 +51,9 @@ static u32 *texBuf;
VIDEOMODE_MODE_t N3DS_VIDEO_mode;
static int ctable[256];

// #define SOFTWARE_INTERLAVE

#ifdef SOFTWARE_INTERLEAVE
static u8 morton_lut[64] = {
0x00, 0x01, 0x04, 0x05, 0x10, 0x11, 0x14, 0x15,
0x02, 0x03, 0x06, 0x07, 0x12, 0x13, 0x16, 0x17,
@@ -66,16 +69,6 @@ static s8 morton_delta_y[8] = {
0x02, 0x06, 0x02, 0x16, 0x02, 0x06, 0x02, 0x16
};

void N3DS_VIDEO_PaletteUpdate()
{
int i;

for (i = 0; i < 256; i++)
{
ctable[i] = Colours_table[i] << 8 | 0xFF;
}
}

static void N3DS_RenderMorton8to32(u8 *src, u32 *dest)
{
int x, y, xm, ym;
@@ -129,6 +122,17 @@ static void N3DS_RenderMorton32to32(u32 *src, u32 *dest, u32 pitch, u32 width, u
}
}
}
#endif

void N3DS_VIDEO_PaletteUpdate()
{
int i;

for (i = 0; i < 256; i++)
{
ctable[i] = Colours_table[i] << 8 | 0xFF;
}
}

static void N3DS_RenderNormal(u8 *src, u32 *dest)
{
@@ -162,8 +166,12 @@ void N3DS_InitVideo(void)
C3D_RenderTargetSetOutput(target_bottom, GFX_BOTTOM, GFX_LEFT,
GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGB8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8));

#ifdef SOFTWARE_INTERLAVE
C3D_TexInit(&tex, 512, 256, GPU_RGBA8);
#else
C3D_TexInit(&tex, 512, 256, GPU_RGBA8);
texBuf = malloc(Screen_WIDTH * Screen_HEIGHT * 4);
#endif
texBuf = linearAlloc(512 * 256 * 4);

ctr_load_png(&kbd_display, "romfs:/kbd_display.png", TEXTURE_TARGET_VRAM);

@@ -185,7 +193,7 @@ void N3DS_InitVideo(void)

void N3DS_ExitVideo(void)
{
free(texBuf);
linearFree(texBuf);

C3D_TexDelete(&kbd_display);
C3D_TexDelete(&tex);
@@ -290,27 +298,56 @@ void N3DS_DrawTexture(C3D_Tex* tex, int x, int y, int tx, int ty, int width, int
void PLATFORM_DisplayScreen(void)
{
u8 *src;
#ifdef SOFTWARE_INTERLAVE
u32 *dest;
#endif
float xmin, ymin, xmax, ymax, txmin, tymin, txmax, tymax;

if (!C3D_FrameBegin(0))
return false;

src = (u8*) Screen_atari;
src += Screen_WIDTH * VIDEOMODE_src_offset_top + VIDEOMODE_src_offset_left;
#ifdef SOFTWARE_INTERLAVE
dest = (u32*) tex.data;

if (!C3D_FrameBegin(0))
return;
#endif

#ifdef PAL_BLENDING
if (N3DS_VIDEO_mode == VIDEOMODE_MODE_NORMAL && ARTIFACT_mode == ARTIFACT_PAL_BLEND)
{
#ifdef SOFTWARE_INTERLAVE
PAL_BLENDING_Blit32(texBuf, src, Screen_WIDTH, VIDEOMODE_src_width, VIDEOMODE_src_height, VIDEOMODE_src_offset_top % 2);
N3DS_RenderMorton32to32(texBuf, dest, Screen_WIDTH, VIDEOMODE_src_width, VIDEOMODE_src_height);
#else
PAL_BLENDING_Blit32(texBuf, src, tex.width, VIDEOMODE_src_width, VIDEOMODE_src_height, VIDEOMODE_src_offset_top % 2);
#endif
}
else
#endif
{
#ifdef SOFTWARE_INTERLAVE
N3DS_RenderMorton8to32(src, dest);
#else
N3DS_RenderNormal(src, texBuf);
#endif
}

#ifdef SOFTWARE_INTERLAVE
GSPGPU_FlushDataCache(dest, 512 * 256 * 4);
#else
GSPGPU_FlushDataCache(texBuf, 512 * 256 * 4);
C3D_SafeDisplayTransfer(texBuf, GX_BUFFER_DIM(512, 256), tex.data, GX_BUFFER_DIM(tex.width, tex.height),
(GX_TRANSFER_FLIP_VERT(1) | GX_TRANSFER_OUT_TILED(1) | GX_TRANSFER_RAW_COPY(0) |
GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGBA8) |
GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO))
);
gspWaitForPPF();

if (!C3D_FrameBegin(0))
return;

GSPGPU_FlushDataCache(tex.data, 512 * 256 * 4);
#endif

C3D_FrameDrawOn(target_bottom);
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, shader.proj_loc, &proj_bottom);
@@ -323,8 +360,13 @@ void PLATFORM_DisplayScreen(void)
ymax = ymin + VIDEOMODE_dest_height;
txmax = ((float) VIDEOMODE_src_width / tex.width);
txmin = 0.0f;
#ifdef SOFTWARE_INTERLEAVE
tymin = 1.0f - ((float) VIDEOMODE_src_height / tex.height);
tymax = 1.0f;
#else
tymin = ((float) VIDEOMODE_src_height / tex.height);
tymax = 0.0f;
#endif

C3D_FrameDrawOn(target_top);
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, shader.proj_loc, &proj_top);

+ 3
- 3
src/3ds/video.h View File

@@ -1,5 +1,5 @@
#ifndef 3DS_VIDEO_H_
#define 3DS_VIDEO_H_
#ifndef _3DS_VIDEO_H_
#define _3DS_VIDEO_H_

#include <stdio.h>
#include "config.h"
@@ -9,4 +9,4 @@ void N3DS_InitVideo(void);
void N3DS_ExitVideo(void);
void N3DS_DrawTexture(C3D_Tex* tex, int x, int y, int tx, int ty, int width, int height);

#endif /* 3DS_VIDEO_H_ */
#endif /* _3DS_VIDEO_H_ */

Loading…
Cancel
Save