Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update #5

Merged
merged 6 commits into from
Sep 9, 2015
Merged
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
11 changes: 11 additions & 0 deletions 3DS/include/drawing.h
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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();
18 changes: 18 additions & 0 deletions 3DS/source/drawing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
24 changes: 9 additions & 15 deletions 3DS/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand All @@ -104,6 +102,8 @@ int main(void) {
if(keyboardToggle) {
keyboardActive = !keyboardActive;
keyboardToggle = false;

if(keyboardActive) enableBacklight();
}
}
else keyboardToggle = true;
Expand Down Expand Up @@ -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);

Expand All @@ -156,6 +148,8 @@ int main(void) {

exit:

enableBacklight();

SOC_Shutdown();

svcCloseHandle(fileHandle);
Expand Down
12 changes: 3 additions & 9 deletions PC/Makefile
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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 $@

Expand Down
2 changes: 2 additions & 0 deletions PC/include/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
16 changes: 0 additions & 16 deletions PC/include/screenshot.h

This file was deleted.

7 changes: 1 addition & 6 deletions PC/source/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 3DS Controller Server

#define VERSION 0.5
#define VERSION 0.6

#include <stdio.h>
#include <stdbool.h>
Expand All @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -221,8 +218,6 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
}

if(vJoy) updateJoystick();

//sendScreenshot();
}

error("accept()");
Expand Down
80 changes: 0 additions & 80 deletions PC/source/screenshot.cpp

This file was deleted.

22 changes: 0 additions & 22 deletions PC/source/wireless.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "general.h"

#include "settings.h"
#include "screenshot.h"

#include "wireless.h"

Expand Down Expand Up @@ -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);
}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down