Merge pull request #5 from CTurt/master

Update
This commit is contained in:
Poke 2015-09-09 16:41:11 +09:30
commit da0a344f2f
10 changed files with 47 additions and 149 deletions

View File

@ -1,5 +1,13 @@
#pragma once
#ifndef REG_LCDBACKLIGHTMAIN
#define REG_LCDBACKLIGHTMAIN (u32)(0x1ED02240 - 0x1EB00000)
#endif
#ifndef REG_LCDBACKLIGHTSUB
#define REG_LCDBACKLIGHTSUB (u32)(0x1ED02A40 - 0x1EB00000)
#endif
inline void clearScreen(void);
#define drawPixelRGB(x, y, r, g, b) drawPixelRGBFramebuffer(0, x, y, r, g, b)
@ -10,3 +18,6 @@ inline void drawBoxFramebuffer(u8 *fb, int x, int y, int width, int height, u8 r
#define drawString(sx, sy, text, ...) drawStringFramebuffer(0, sx, sy, text, ##__VA_ARGS__)
void drawStringFramebuffer(u8 *fb, int sx, int sy, char *text, ...);
void disableBacklight();
void enableBacklight();

View File

@ -155,3 +155,21 @@ void drawStringFramebuffer(u8 *fb, int sx, int sy, char *text, ...) {
sx += 8;
}
}
static u32 brightnessMain;
static u32 brightnessSub;
void disableBacklight() {
u32 off = 0;
GSPGPU_ReadHWRegs(NULL, REG_LCDBACKLIGHTMAIN, &brightnessMain, 4);
GSPGPU_ReadHWRegs(NULL, REG_LCDBACKLIGHTSUB, &brightnessSub, 4);
GSPGPU_WriteHWRegs(NULL, REG_LCDBACKLIGHTMAIN, &off, 4);
GSPGPU_WriteHWRegs(NULL, REG_LCDBACKLIGHTSUB, &off, 4);
}
void enableBacklight() {
GSPGPU_WriteHWRegs(NULL, REG_LCDBACKLIGHTMAIN, &brightnessMain, 4);
GSPGPU_WriteHWRegs(NULL, REG_LCDBACKLIGHTSUB, &brightnessSub, 4);
}

View File

@ -34,7 +34,8 @@ int main(void) {
acInit();
gfxInitDefault();
//consoleInit(GFX_BOTTOM, NULL);
gfxSetDoubleBuffering(GFX_TOP, false);
gfxSetDoubleBuffering(GFX_BOTTOM, false);
if(setjmp(exitJmp)) goto exit;
@ -81,20 +82,17 @@ int main(void) {
gfxFlushBuffers();
gfxSwapBuffers();
clearScreen();
gfxFlushBuffers();
gfxSwapBuffers();
disableBacklight();
while(aptMainLoop()) {
hidScanInput();
irrstScanInput();
u32 kHeld = hidKeysHeld();
circlePosition circlePad;
circlePosition cStick;
hidCstickRead(&cStick);
hidCircleRead(&circlePad);
irrstCstickRead(&cStick);
touchPosition touch;
touchRead(&touch);
@ -104,6 +102,8 @@ int main(void) {
if(keyboardToggle) {
keyboardActive = !keyboardActive;
keyboardToggle = false;
if(keyboardActive) enableBacklight();
}
}
else keyboardToggle = true;
@ -137,15 +137,7 @@ int main(void) {
sendKeys(kHeld, circlePad, touch, cStick);
receiveBuffer(sizeof(struct packet));
/*u8 *frame = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
switch(rcvBuf.command) {
case SCREENSHOT:
//drawStringFramebuffer(frame, 10, 10, "R");
break;
}*/
//receiveBuffer(sizeof(struct packet));
if((kHeld & KEY_START) && (kHeld & KEY_SELECT)) longjmp(exitJmp, 1);
@ -156,6 +148,8 @@ int main(void) {
exit:
enableBacklight();
SOC_Shutdown();
svcCloseHandle(fileHandle);

View File

@ -1,16 +1,13 @@
CC := gcc
CP := g++
LN := g++
LN := gcc
ODIR := build
SDIR := source
IDIR := include
LDIR := lib
CFLAGS := -I$(IDIR) -fms-extensions -O2 -Wall
LFLAGS := -L$(LDIR) -lvJoyInterface -lws2_32 -lGdi32 -lgdiplus -static-libgcc -static-libstdc++
LFLAGS := $(LDIR)/vJoyInterface.lib -lws2_32 -lGdi32 -lgdiplus -static-libgcc
CFILES := $(wildcard $(SDIR)/*.c)
CPPFILES := $(wildcard $(SDIR)/*.cpp)
OBJS := $(patsubst $(SDIR)/%.c, build/%.o, $(wildcard $(SDIR)/*.c))
OBJS += $(patsubst $(SDIR)/%.cpp, build/%.o, $(wildcard $(SDIR)/*.cpp))
OBJS := $(patsubst $(SDIR)/%.c, $(ODIR)/%.o, $(wildcard $(SDIR)/*.c))
PLATFORM = $(shell uname)
@ -32,9 +29,6 @@ $(TARGET): $(ODIR) $(OBJS)
$(ODIR)/%.o: $(SDIR)/%.c
$(CC) -c -o $@ $< $(CFLAGS)
$(ODIR)/%.o: $(SDIR)/%.cpp
$(CP) -c -o $@ $< $(CFLAGS)
$(ODIR):
@mkdir $@

View File

@ -15,7 +15,9 @@
#define KEYEVENTF_SCANCODE 0x08
#endif
#ifndef MAPVK_VK_TO_VSC
#define MAPVK_VK_TO_VSC 0
#endif
#define newpress(key) ((currentKeys & key) && !(lastKeys & key))
#define release(key) (!(currentKeys & key) && (lastKeys & key))

View File

@ -1,16 +0,0 @@
#pragma once
#include <windows.h>
#ifdef __cplusplus
extern "C" {
#endif
#define SCREENSHOT_NAME "tempScreen.jpg"
#define SCREENSHOT_NAMEL L"tempScreen.jpg"
void screenshot(const WCHAR *filename, BOOL fullscreen, int windowedX, int windowedY, ULONG quality);
#ifdef __cplusplus
}
#endif

View File

@ -1,6 +1,6 @@
// 3DS Controller Server
#define VERSION 0.5
#define VERSION 0.6
#include <stdio.h>
#include <stdbool.h>
@ -12,7 +12,6 @@
#include "joystick.h"
#include "settings.h"
#include "keyboard.h"
#include "screenshot.h"
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow) {
printf("3DS Controller Server %.1f\n", VERSION);
@ -23,8 +22,6 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
double widthMultiplier = screenWidth / 320.0;
double heightMultiplier = screenHeight / 240.0;
//screenshot(SCREENSHOT_NAMEL, TRUE, 0, 0, 18);
bool vJoy = true;
UINT iInterface = 1;
@ -221,8 +218,6 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
}
if(vJoy) updateJoystick();
//sendScreenshot();
}
error("accept()");

View File

@ -1,80 +0,0 @@
#include <windows.h>
#include <GdiPlus.h>
#include "screenshot.h"
extern "C" {
int GetEncoderClsid(const WCHAR *format, CLSID *pClsid) {
using namespace Gdiplus;
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytes
ImageCodecInfo *pImageCodecInfo = NULL;
GetImageEncodersSize(&num, &size);
if(size == 0)
return -1; // Failure
pImageCodecInfo = (ImageCodecInfo *)(malloc(size));
if(pImageCodecInfo == NULL)
return -1; // Failure
GetImageEncoders(num, size, pImageCodecInfo);
UINT j;
for(j = 0; j < num; j++) {
if(wcscmp(pImageCodecInfo[j].MimeType, format) == 0) {
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j; // Success
}
}
free(pImageCodecInfo);
return 0;
}
void screenshot(const WCHAR *filename, BOOL fullscreen, int windowedX, int windowedY, ULONG quality) {
using namespace Gdiplus;
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
{
HDC scrdc, memdc;
HBITMAP membit;
scrdc = ::GetDC(0);
memdc = CreateCompatibleDC(scrdc);
membit = CreateCompatibleBitmap(scrdc, 400, 240);
HBITMAP hOldBitmap = (HBITMAP) SelectObject(memdc, membit);
EncoderParameters encoderParams;
encoderParams.Count = 1;
encoderParams.Parameter[0].NumberOfValues = 1;
encoderParams.Parameter[0].Guid = EncoderQuality;
encoderParams.Parameter[0].Type = EncoderParameterValueTypeLong;
encoderParams.Parameter[0].Value = &quality;
if(fullscreen) {
StretchBlt(memdc, 0, 0, 400, 240, scrdc, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SRCCOPY);
}
else {
BitBlt(memdc, 0, 0, 400, 240, scrdc, windowedX, windowedY, SRCCOPY);
}
Gdiplus::Bitmap bitmap(membit, NULL);
CLSID clsid;
GetEncoderClsid(L"image/jpeg", &clsid);
bitmap.Save(filename, &clsid, &encoderParams);
SelectObject(memdc, hOldBitmap);
DeleteObject(memdc);
DeleteObject(membit);
::ReleaseDC(0, scrdc);
}
GdiplusShutdown(gdiplusToken);
}
}

View File

@ -3,7 +3,6 @@
#include "general.h"
#include "settings.h"
#include "screenshot.h"
#include "wireless.h"
@ -79,24 +78,3 @@ void sendBuffer(int length) {
int receiveBuffer(int length) {
return recvfrom(listener, (char *)&buffer, length, 0, (struct sockaddr *)&client_in, &sockaddr_in_sizePtr);
}
void sendScreenshot(void) {
FILE *f = fopen(SCREENSHOT_NAME, "rb");
fseek(f, 0, SEEK_END);
size_t len = ftell(f);
unsigned char *screenshotData = malloc(len);
rewind(f);
fread(screenshotData, len, 1, f);
fclose(f);
buffer.command = SCREENSHOT;
while(1) {
int tl = len - buffer.offset > SCREENSHOT_CHUNK ? SCREENSHOT_CHUNK : len - buffer.offset;
memcpy(buffer.data, screenshotData + buffer.offset, tl);
sendBuffer(tl + offsetof(struct packet, screenshotPacket));
if(tl < SCREENSHOT_CHUNK) break;
}
free(screenshotData);
}

View File

@ -5,8 +5,10 @@ A 3DS homebrew application which allows you to use your 3DS as a wireless contro
### Download
The latest release will always be downloadable from [here](https://github.com/CTurt/3DSController/releases/).
If you are updating to 0.6 from an older version, you will need to make sure you update vJoy to the recommended version.
### Setup and Usage
Firstly, if you want to be able to use the circle pad as a joystick you will need to install [vJoy (version 2.0.5-120515 is preferable)](http://sourceforge.net/projects/vjoystick/files/Beta%202.x/2.0.5-120515/vJoy_205_050515.exe/download). However, if you just want to use keyboard buttons, this is not necessary.
Firstly, if you want to be able to register the circle pad or touch screen as a joystick you will need to install [vJoy (version 2.0.5-120515 is preferable)](http://sourceforge.net/projects/vjoystick/files/Beta%202.x/2.0.5-120515/vJoy_205_050515.exe/download). However, if you just want to use keyboard buttons, this is not necessary.
Extract the archive and copy the executable in the `3DS` directory with the extension that applies to your loader: `3DSController.3dsx` and `3DSController.smdh` for Ninjhax, `3DSController.3ds` for flashcards, or `3DSController.cia` for CFWs, into your 3DS's SD card or flashcard's micro SD card.