Browse Source

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

Adrian Siekierka 1 year 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 = \
85 85
 	src/pia.c \
86 86
 	src/pokey.c \
87 87
 	src/pokeysnd.c \
88
+	src/rdevice.c \
88 89
 	src/remez.c \
89 90
 	src/rtime.c \
90 91
 	src/screen.c \
@@ -114,7 +115,7 @@ SHADERS = \
114 115
 #---------------------------------------------------------------------------------
115 116
 ARCH	:=	-march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
116 117
 
117
-CFLAGS	:=	-g -Wall -O2 -flto -mword-relocations -D_GNU_SOURCE \
118
+CFLAGS	:=	-g -Wall -O2 -mword-relocations -D_GNU_SOURCE \
118 119
 			-fomit-frame-pointer -ffunction-sections \
119 120
 			$(ARCH)
120 121
 
@@ -161,7 +162,7 @@ export OFILES	:=	$(addsuffix .o,$(BINFILES)) \
161 162
 
162 163
 export INCLUDE	:=	$(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
163 164
 			$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
164
-			-I$(CURDIR)/$(BUILD) -I$(DEVKITPRO)/portlibs/3ds/include/SDL2 \
165
+			-I$(CURDIR)/$(BUILD) \
165 166
 			-I$(CURDIR)/src/3ds
166 167
 
167 168
 export LIBPATHS	:=	$(foreach dir,$(LIBDIRS),-L$(dir)/lib)

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

@@ -421,10 +421,10 @@
421 421
 /* #undef RPI */
422 422
 
423 423
 /* Define to use R: device. */
424
-/* #undef R_IO_DEVICE */
424
+#define R_IO_DEVICE
425 425
 
426 426
 /* Define to use IP network connection with the R: device. */
427
-/* #undef R_NETWORK */
427
+#define R_NETWORK
428 428
 
429 429
 /* Define to use the host serial port with the R: device. */
430 430
 /* #undef R_SERIAL */

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

@@ -32,6 +32,7 @@
32 32
 #include "log.h"
33 33
 #include "platform.h"
34 34
 #include "ui.h"
35
+#include "video.h"
35 36
 
36 37
 int key_control;
37 38
 int current_key_down = AKEY_NONE;
@@ -39,6 +40,7 @@ int dpad_as_keyboard = 1;
39 40
 u64 key_down_time = 0;
40 41
 
41 42
 #define WARMSTART_HOLD_TIME 3*1000
43
+#define AKEY_WAS_SHIFT_CTRL -992
42 44
 
43 45
 touch_area_t N3DS_touch_areas_key[] = {
44 46
 	{ 2, 130, 22, 22, AKEY_ESCAPE, 0 },
@@ -174,19 +176,7 @@ void N3DS_DrawKeyboard(C3D_Tex *tex)
174 176
 
175 177
 	N3DS_DrawTexture(tex, 0, 0, 0, 0, 320, 240);
176 178
 
177
-	if (INPUT_key_shift != 0)
178
-	{
179
-		N3DS_DrawTexture(tex, 2, 194, 322, 194, 43, 22);
180
-		N3DS_DrawTexture(tex, 254, 194, 574, 194, 43, 22);
181
-	}
182
-
183
-	if (N3DS_IsControlPressed())
184
-	{
185
-		N3DS_DrawTexture(tex, 2, 172, 322, 172, 37, 22);
186
-	}
187
-
188 179
 	int key_down = current_key_down;
189
-	if (key_down == AKEY_SHFT || key_down == AKEY_CTRL) key_down = AKEY_NONE;
190 180
 	if (key_down >= 0) key_down &= ~AKEY_SHFTCTRL;
191 181
 
192 182
 	hidTouchRead(&pos);
@@ -194,6 +184,8 @@ void N3DS_DrawKeyboard(C3D_Tex *tex)
194 184
 	{
195 185
 		touch_area_t* area = &keyTable[i];
196 186
 		if (key_down == area->keycode
187
+                        || (INPUT_key_shift != 0 && area->keycode == AKEY_SHFT)
188
+                        || (N3DS_IsControlPressed() && area->keycode == AKEY_CTRL)
197 189
 			|| (isTouch && (
198 190
 				(area->keycode == AKEY_START) ||
199 191
 				(area->keycode == AKEY_SELECT) ||
@@ -243,7 +235,7 @@ int PLATFORM_Keyboard(void)
243 235
 
244 236
 	if (kUp & KEY_TOUCH)
245 237
 	{
246
-		if (current_key_down != AKEY_CTRL && current_key_down != AKEY_SHFT)
238
+		if (current_key_down != AKEY_WAS_SHIFT_CTRL)
247 239
 		{
248 240
 			INPUT_key_shift = 0;
249 241
 			key_control = 0;
@@ -316,14 +308,13 @@ int PLATFORM_Keyboard(void)
316 308
 	{
317 309
 		hidTouchRead(&pos);
318 310
 		touch_area_t* keyTable = N3DS_TOUCH_AREAS;
319
-		int keyTableLen = N3DS_TOUCH_AREA_MAX;
320 311
 		bool down = (kDown & KEY_TOUCH) != 0;
321 312
 		bool touching = ((kDown | kHeld) & KEY_TOUCH) != 0;
322 313
 		bool refresh = false;
323 314
 
324 315
 		if (down) current_key_down = AKEY_NONE;
325 316
 
326
-		for (int i = 0; i < keyTableLen; i++)
317
+		for (int i = 0; i < N3DS_TOUCH_AREA_MAX; i++)
327 318
 		{
328 319
 			touch_area_t* area = &keyTable[i];
329 320
 			if (isKeyTouched(&pos, area))
@@ -332,21 +323,15 @@ int PLATFORM_Keyboard(void)
332 323
 				switch (area->keycode)
333 324
 				{
334 325
 					case AKEY_SHFT:
335
-						if (down)
336
-						{
337
-							INPUT_key_shift = 1;
338
-							Atari800_display_screen = TRUE;
339
-							current_key_down = AKEY_SHFT;
340
-						}
341
-						break;
326
+						if (down) Atari800_display_screen = TRUE;
327
+						INPUT_key_shift = 1;
328
+						current_key_down = AKEY_WAS_SHIFT_CTRL;
329
+						return AKEY_NONE;
342 330
 					case AKEY_CTRL:
343
-						if (down)
344
-						{
345
-							key_control = 1;
346
-							Atari800_display_screen = TRUE;
347
-							current_key_down = AKEY_CTRL;
348
-						}
349
-						break;
331
+						if (down) Atari800_display_screen = TRUE;
332
+						key_control = 1;
333
+						current_key_down = AKEY_WAS_SHIFT_CTRL;
334
+						return AKEY_NONE;
350 335
 					case AKEY_START:
351 336
 						if (touching) INPUT_key_consol &= ~INPUT_CONSOL_START;
352 337
 						break;
@@ -360,10 +345,11 @@ int PLATFORM_Keyboard(void)
360 345
 						if (down)
361 346
 						{
362 347
 							key_down_time = osGetTime();
363
-							current_key_down = AKEY_WARMSTART;
348
+							current_key_down = AKEY_NONE;
364 349
 							break;
365 350
 						} else if (touching && (osGetTime() - key_down_time) > WARMSTART_HOLD_TIME)
366 351
 						{
352
+							Atari800_display_screen = TRUE;
367 353
 							return AKEY_WARMSTART;
368 354
 						}
369 355
 					default:
@@ -377,10 +363,7 @@ int PLATFORM_Keyboard(void)
377 363
 		}
378 364
 
379 365
 		if (refresh) Atari800_display_screen = TRUE;
380
-		if (current_key_down == AKEY_SHFT || current_key_down == AKEY_CTRL || current_key_down == AKEY_WARMSTART)
381
-			return AKEY_NONE;
382
-		else
383
-			return current_key_down;
366
+		return current_key_down;
384 367
 	}
385 368
 
386 369
 	return AKEY_NONE;

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

@@ -38,6 +38,7 @@
38 38
 #ifdef SOUND
39 39
 #include "../sound.h"
40 40
 #endif
41
+#include "video.h"
41 42
 #include "videomode.h"
42 43
 
43 44
 static bool PLATFORM_IsNew3DS;
@@ -85,6 +86,8 @@ int PLATFORM_Exit(int run_monitor)
85 86
 	} else {
86 87
 		N3DS_ExitVideo();
87 88
 
89
+		acExit();
90
+
88 91
 		ptmSysmExit();
89 92
 		romfsExit();
90 93
 	}
@@ -100,6 +103,8 @@ int main(int argc, char **argv)
100 103
 	osSetSpeedupEnable(1);
101 104
 	APT_SetAppCpuTimeLimit(80);
102 105
 
106
+	acInit();
107
+
103 108
 	// set config defaults
104 109
 	PLATFORM_IsNew3DS = PTMSYSM_CheckNew3DS();
105 110
 	POKEYSND_enable_new_pokey = PLATFORM_IsNew3DS;

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

@@ -42,8 +42,7 @@ void N3DS_ClearAudioData(void);
42 42
 
43 43
 int PLATFORM_SoundSetup(Sound_setup_t *setup)
44 44
 {
45
-	setup->buffer_frames &= ~3;
46
-	setup->sample_size = 1;
45
+	setup->buffer_frames = (setup->buffer_frames + 7) & (~0x07);
47 46
 
48 47
 	if (setup->buffer_frames == 0)
49 48
 	{
@@ -74,8 +73,6 @@ void N3DS_SoundCallback(void* dud)
74 73
 		if (N3DS_sound->sample_size > 1)
75 74
 		{
76 75
 			Sound_Callback((u8*) N3DS_audioBuf[N3DS_soundFillBlock].data_pcm8, flen);
77
-			for(int i = 0; i < ilen; i++)
78
-				invbuf[i] ^= 0x80008000;
79 76
 		} else
80 77
 		{
81 78
 			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;
51 51
 VIDEOMODE_MODE_t N3DS_VIDEO_mode;
52 52
 static int ctable[256];
53 53
 
54
+// #define SOFTWARE_INTERLAVE
55
+
56
+#ifdef SOFTWARE_INTERLEAVE
54 57
 static u8 morton_lut[64] = {
55 58
         0x00, 0x01, 0x04, 0x05, 0x10, 0x11, 0x14, 0x15,
56 59
 	0x02, 0x03, 0x06, 0x07, 0x12, 0x13, 0x16, 0x17,
@@ -66,16 +69,6 @@ static s8 morton_delta_y[8] = {
66 69
         0x02, 0x06, 0x02, 0x16, 0x02, 0x06, 0x02, 0x16
67 70
 };
68 71
 
69
-void N3DS_VIDEO_PaletteUpdate()
70
-{
71
-	int i;
72
-
73
-	for (i = 0; i < 256; i++)
74
-	{
75
-		ctable[i] = Colours_table[i] << 8 | 0xFF;
76
-	}
77
-}
78
-
79 72
 static void N3DS_RenderMorton8to32(u8 *src, u32 *dest)
80 73
 {
81 74
 	int x, y, xm, ym;
@@ -129,6 +122,17 @@ static void N3DS_RenderMorton32to32(u32 *src, u32 *dest, u32 pitch, u32 width, u
129 122
 		}
130 123
 	}
131 124
 }
125
+#endif
126
+
127
+void N3DS_VIDEO_PaletteUpdate()
128
+{
129
+	int i;
130
+
131
+	for (i = 0; i < 256; i++)
132
+	{
133
+		ctable[i] = Colours_table[i] << 8 | 0xFF;
134
+	}
135
+}
132 136
 
133 137
 static void N3DS_RenderNormal(u8 *src, u32 *dest)
134 138
 {
@@ -162,8 +166,12 @@ void N3DS_InitVideo(void)
162 166
 	C3D_RenderTargetSetOutput(target_bottom, GFX_BOTTOM, GFX_LEFT,
163 167
 		GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGB8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8));
164 168
 
169
+#ifdef SOFTWARE_INTERLAVE
170
+	C3D_TexInit(&tex, 512, 256, GPU_RGBA8);
171
+#else
165 172
 	C3D_TexInit(&tex, 512, 256, GPU_RGBA8);
166
-	texBuf = malloc(Screen_WIDTH * Screen_HEIGHT * 4);
173
+#endif
174
+	texBuf = linearAlloc(512 * 256 * 4);
167 175
 
168 176
 	ctr_load_png(&kbd_display, "romfs:/kbd_display.png", TEXTURE_TARGET_VRAM);
169 177
 
@@ -185,7 +193,7 @@ void N3DS_InitVideo(void)
185 193
 
186 194
 void N3DS_ExitVideo(void)
187 195
 {
188
-	free(texBuf);
196
+	linearFree(texBuf);
189 197
 
190 198
 	C3D_TexDelete(&kbd_display);
191 199
 	C3D_TexDelete(&tex);
@@ -290,27 +298,56 @@ void N3DS_DrawTexture(C3D_Tex* tex, int x, int y, int tx, int ty, int width, int
290 298
 void PLATFORM_DisplayScreen(void)
291 299
 {
292 300
 	u8 *src;
301
+#ifdef SOFTWARE_INTERLAVE
293 302
 	u32 *dest;
303
+#endif
294 304
 	float xmin, ymin, xmax, ymax, txmin, tymin, txmax, tymax;
295 305
 
296
-	if (!C3D_FrameBegin(0))
297
-		return false;
298
-
299 306
 	src = (u8*) Screen_atari;
300 307
 	src += Screen_WIDTH * VIDEOMODE_src_offset_top + VIDEOMODE_src_offset_left;
308
+#ifdef SOFTWARE_INTERLAVE
301 309
 	dest = (u32*) tex.data;
302 310
 
311
+	if (!C3D_FrameBegin(0))
312
+		return;
313
+#endif
314
+
303 315
 #ifdef PAL_BLENDING
304 316
 	if (N3DS_VIDEO_mode == VIDEOMODE_MODE_NORMAL && ARTIFACT_mode == ARTIFACT_PAL_BLEND)
305 317
 	{
318
+#ifdef SOFTWARE_INTERLAVE
306 319
 		PAL_BLENDING_Blit32(texBuf, src, Screen_WIDTH, VIDEOMODE_src_width, VIDEOMODE_src_height, VIDEOMODE_src_offset_top % 2);
307 320
 		N3DS_RenderMorton32to32(texBuf, dest, Screen_WIDTH, VIDEOMODE_src_width, VIDEOMODE_src_height);
321
+#else
322
+		PAL_BLENDING_Blit32(texBuf, src, tex.width, VIDEOMODE_src_width, VIDEOMODE_src_height, VIDEOMODE_src_offset_top % 2);
323
+#endif
308 324
 	}
309 325
 	else
310 326
 #endif
327
+	{
328
+#ifdef SOFTWARE_INTERLAVE
311 329
 		N3DS_RenderMorton8to32(src, dest);
330
+#else
331
+		N3DS_RenderNormal(src, texBuf);
332
+#endif
333
+	}
312 334
 
335
+#ifdef SOFTWARE_INTERLAVE
313 336
 	GSPGPU_FlushDataCache(dest, 512 * 256 * 4);
337
+#else
338
+	GSPGPU_FlushDataCache(texBuf, 512 * 256 * 4);
339
+	C3D_SafeDisplayTransfer(texBuf, GX_BUFFER_DIM(512, 256), tex.data, GX_BUFFER_DIM(tex.width, tex.height),
340
+		(GX_TRANSFER_FLIP_VERT(1) | GX_TRANSFER_OUT_TILED(1) | GX_TRANSFER_RAW_COPY(0) |
341
+		GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGBA8) |
342
+		GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO))
343
+	);
344
+	gspWaitForPPF();
345
+
346
+	if (!C3D_FrameBegin(0))
347
+		return;
348
+
349
+	GSPGPU_FlushDataCache(tex.data, 512 * 256 * 4);
350
+#endif
314 351
 
315 352
 	C3D_FrameDrawOn(target_bottom);
316 353
 	C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, shader.proj_loc, &proj_bottom);
@@ -323,8 +360,13 @@ void PLATFORM_DisplayScreen(void)
323 360
 	ymax = ymin + VIDEOMODE_dest_height;
324 361
 	txmax = ((float) VIDEOMODE_src_width / tex.width);
325 362
 	txmin = 0.0f;
363
+#ifdef SOFTWARE_INTERLEAVE
326 364
 	tymin = 1.0f - ((float) VIDEOMODE_src_height / tex.height);
327 365
 	tymax = 1.0f;
366
+#else
367
+	tymin = ((float) VIDEOMODE_src_height / tex.height);
368
+	tymax = 0.0f;
369
+#endif
328 370
 
329 371
 	C3D_FrameDrawOn(target_top);
330 372
 	C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, shader.proj_loc, &proj_top);

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

@@ -1,5 +1,5 @@
1
-#ifndef 3DS_VIDEO_H_
2
-#define 3DS_VIDEO_H_
1
+#ifndef _3DS_VIDEO_H_
2
+#define _3DS_VIDEO_H_
3 3
 
4 4
 #include <stdio.h>
5 5
 #include "config.h"
@@ -9,4 +9,4 @@ void N3DS_InitVideo(void);
9 9
 void N3DS_ExitVideo(void);
10 10
 void N3DS_DrawTexture(C3D_Tex* tex, int x, int y, int tx, int ty, int width, int height);
11 11
 
12
-#endif /* 3DS_VIDEO_H_ */
12
+#endif /* _3DS_VIDEO_H_ */

Loading…
Cancel
Save