forked from Mirror/GodMode9
Some source code reorganisation
This commit is contained in:
parent
bc66cd0ccf
commit
500333b011
78
arm9/source/common/touchcal.c
Normal file
78
arm9/source/common/touchcal.c
Normal file
@ -0,0 +1,78 @@
|
||||
#include "touchcal.h"
|
||||
#include "ui.h"
|
||||
#include "hid.h"
|
||||
|
||||
|
||||
bool ShowCalibrationDialog(void)
|
||||
{
|
||||
static const u32 dot_positions[][2] = {
|
||||
{16, 16},
|
||||
{320 - 16, 240 - 16},
|
||||
{16, 240 - 16},
|
||||
{320 - 16, 16},
|
||||
};
|
||||
|
||||
HID_CalibrationData calibrations[countof(dot_positions)];
|
||||
for (u32 i = 0; i < countof(dot_positions); i++) {
|
||||
calibrations[i].screen_x = dot_positions[i][0];
|
||||
calibrations[i].screen_y = dot_positions[i][1];
|
||||
}
|
||||
|
||||
// clear screen, draw instructions
|
||||
ClearScreen(BOT_SCREEN, COLOR_STD_BG);
|
||||
DrawStringCenter(BOT_SCREEN, COLOR_STD_FONT, COLOR_STD_BG,
|
||||
"Touch the red crosshairs to\ncalibrate your touchscreen.\n \nUse the stylus for best\nresults!");
|
||||
|
||||
// actual calibration
|
||||
for (u32 current_dot = 0; current_dot < countof(dot_positions); current_dot++) {
|
||||
// draw four crosshairs
|
||||
for (u32 i = 0; i < countof(dot_positions); i++) {
|
||||
int color_cross = (i < current_dot) ? COLOR_BRIGHTGREEN : (i == current_dot) ? COLOR_RED : COLOR_STD_FONT;
|
||||
for (u32 r = 2; r < 8; r++) {
|
||||
DrawPixel(BOT_SCREEN, dot_positions[i][0] + 0, dot_positions[i][1] + r, color_cross);
|
||||
DrawPixel(BOT_SCREEN, dot_positions[i][0] + r, dot_positions[i][1] + 0, color_cross);
|
||||
DrawPixel(BOT_SCREEN, dot_positions[i][0] + 0, dot_positions[i][1] - r, color_cross);
|
||||
DrawPixel(BOT_SCREEN, dot_positions[i][0] - r, dot_positions[i][1] + 0, color_cross);
|
||||
}
|
||||
}
|
||||
|
||||
// wait until touchscreen released
|
||||
while (HID_ReadState() & (BUTTON_B | BUTTON_TOUCH));
|
||||
|
||||
// wait for input, store calibration data
|
||||
while (1) {
|
||||
u32 pressed = HID_ReadState();
|
||||
if (pressed & BUTTON_B) {
|
||||
return false;
|
||||
} else if (pressed & BUTTON_TOUCH) {
|
||||
calibrations[current_dot].ts_raw = HID_ReadRawTouchState();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return HID_SetCalibrationData(calibrations, countof(dot_positions), 320, 240);
|
||||
}
|
||||
|
||||
void ShowTouchPlayground(void)
|
||||
{
|
||||
ClearScreen(BOT_SCREEN, COLOR_STD_BG);
|
||||
|
||||
while(1) {
|
||||
u16 tx, ty;
|
||||
u32 pressed = HID_ReadState();
|
||||
|
||||
if (pressed & BUTTON_TOUCH) {
|
||||
HID_ReadTouchState(&tx, &ty);
|
||||
if (tx < 320 && ty < 240)
|
||||
DrawPixel(BOT_SCREEN, tx, ty, COLOR_BRIGHTYELLOW);
|
||||
} else {
|
||||
tx = ty = 0;
|
||||
}
|
||||
|
||||
DrawStringF(BOT_SCREEN, 16, 16, COLOR_STD_FONT, COLOR_STD_BG, "Current touchscreen coordinates: %3.3d, %3.3d", tx, ty);
|
||||
if (pressed & BUTTON_B)
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
6
arm9/source/common/touchcal.h
Normal file
6
arm9/source/common/touchcal.h
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
|
||||
bool ShowCalibrationDialog(void);
|
||||
void ShowTouchPlayground(void);
|
@ -1072,77 +1072,3 @@ bool ShowProgress(u64 current, u64 total, const char* opstr)
|
||||
|
||||
return !CheckButton(BUTTON_B);
|
||||
}
|
||||
|
||||
bool ShowCalibrationDialog(void)
|
||||
{
|
||||
static const u32 dot_positions[][2] = {
|
||||
{16, 16},
|
||||
{320 - 16, 240 - 16},
|
||||
{16, 240 - 16},
|
||||
{320 - 16, 16},
|
||||
};
|
||||
|
||||
HID_CalibrationData calibrations[countof(dot_positions)];
|
||||
for (u32 i = 0; i < countof(dot_positions); i++) {
|
||||
calibrations[i].screen_x = dot_positions[i][0];
|
||||
calibrations[i].screen_y = dot_positions[i][1];
|
||||
}
|
||||
|
||||
// clear screen, draw instructions
|
||||
ClearScreen(BOT_SCREEN, COLOR_STD_BG);
|
||||
DrawStringCenter(BOT_SCREEN, COLOR_STD_FONT, COLOR_STD_BG,
|
||||
"Touch the red crosshairs to\ncalibrate your touchscreen.\n \nUse the stylus for best\nresults!");
|
||||
|
||||
// actual calibration
|
||||
for (u32 current_dot = 0; current_dot < countof(dot_positions); current_dot++) {
|
||||
// draw four crosshairs
|
||||
for (u32 i = 0; i < countof(dot_positions); i++) {
|
||||
int color_cross = (i < current_dot) ? COLOR_BRIGHTGREEN : (i == current_dot) ? COLOR_RED : COLOR_STD_FONT;
|
||||
for (u32 r = 2; r < 8; r++) {
|
||||
DrawPixel(BOT_SCREEN, dot_positions[i][0] + 0, dot_positions[i][1] + r, color_cross);
|
||||
DrawPixel(BOT_SCREEN, dot_positions[i][0] + r, dot_positions[i][1] + 0, color_cross);
|
||||
DrawPixel(BOT_SCREEN, dot_positions[i][0] + 0, dot_positions[i][1] - r, color_cross);
|
||||
DrawPixel(BOT_SCREEN, dot_positions[i][0] - r, dot_positions[i][1] + 0, color_cross);
|
||||
}
|
||||
}
|
||||
|
||||
// wait until touchscreen released
|
||||
while (HID_ReadState() & (BUTTON_B | BUTTON_TOUCH));
|
||||
|
||||
// wait for input, store calibration data
|
||||
while (1) {
|
||||
u32 pressed = HID_ReadState();
|
||||
if (pressed & BUTTON_B) {
|
||||
return false;
|
||||
} else if (pressed & BUTTON_TOUCH) {
|
||||
calibrations[current_dot].ts_raw = HID_ReadRawTouchState();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return HID_SetCalibrationData(calibrations, countof(dot_positions), 320, 240);
|
||||
}
|
||||
|
||||
void ShowTouchPlayground(void)
|
||||
{
|
||||
ClearScreen(BOT_SCREEN, COLOR_STD_BG);
|
||||
|
||||
while(1) {
|
||||
u16 tx, ty;
|
||||
u32 pressed = HID_ReadState();
|
||||
|
||||
if (pressed & BUTTON_TOUCH) {
|
||||
HID_ReadTouchState(&tx, &ty);
|
||||
if (tx < 320 && ty < 240)
|
||||
DrawPixel(BOT_SCREEN, tx, ty, COLOR_BRIGHTYELLOW);
|
||||
} else {
|
||||
tx = ty = 0;
|
||||
}
|
||||
|
||||
DrawStringF(BOT_SCREEN, 16, 16, COLOR_STD_FONT, COLOR_STD_BG, "Current touchscreen coordinates: %3.3d, %3.3d", tx, ty);
|
||||
if (pressed & BUTTON_B)
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ bool SetFontFromPbm(const void* pbm, const u32 pbm_size);
|
||||
|
||||
void ClearScreen(unsigned char *screen, int color);
|
||||
void ClearScreenF(bool clear_main, bool clear_alt, int color);
|
||||
void DrawPixel(u8* screen, int x, int y, int color);
|
||||
void DrawRectangle(u8* screen, int x, int y, int width, int height, int color);
|
||||
void DrawBitmap(u8* screen, int x, int y, int w, int h, u8* bitmap);
|
||||
void DrawQrCode(u8* screen, u8* qrcode);
|
||||
@ -82,6 +83,3 @@ u64 ShowNumberPrompt(u64 start_val, const char *format, ...);
|
||||
bool ShowDataPrompt(u8* data, u32* size, const char *format, ...);
|
||||
bool ShowRtcSetterPrompt(void* time, const char *format, ...);
|
||||
bool ShowProgress(u64 current, u64 total, const char* opstr);
|
||||
|
||||
bool ShowCalibrationDialog(void);
|
||||
void ShowTouchPlayground(void);
|
||||
|
26
arm9/source/crypto/crc16.c
Normal file
26
arm9/source/crypto/crc16.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include "crc16.h"
|
||||
|
||||
#define CRC16_TABVAL \
|
||||
0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401, \
|
||||
0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400
|
||||
|
||||
|
||||
// see: https://github.com/TASVideos/desmume/blob/master/desmume/src/bios.cpp#L1070tions
|
||||
u16 crc16_quick(const void* src, u32 len) {
|
||||
const u16 tabval[] = { CRC16_TABVAL };
|
||||
u16* data = (u16*) src;
|
||||
u16 crc = 0xFFFF;
|
||||
|
||||
for (len >>= 1; len; len--) {
|
||||
u16 curr = *(data++);
|
||||
for (u32 i = 0; i < 4; i++) {
|
||||
u16 tval = tabval[crc&0xF];
|
||||
crc >>= 4;
|
||||
crc ^= tval;
|
||||
tval = tabval[(curr >> (4*i))&0xF];
|
||||
crc ^= tval;
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
5
arm9/source/crypto/crc16.h
Normal file
5
arm9/source/crypto/crc16.h
Normal file
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
|
||||
u16 crc16_quick(const void* src, u32 len);
|
@ -1,9 +1,8 @@
|
||||
#include "nds.h"
|
||||
#include "vff.h"
|
||||
#include "crc16.h"
|
||||
#include "utf.h"
|
||||
|
||||
#define CRC16_TABVAL 0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401, 0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400
|
||||
|
||||
#define FNT_ENTRY_ISDIR(e) ((bool)((*(u8*)(e))&0x80))
|
||||
#define FNT_ENTRY_FNLEN(e) ((*(u8*)(e))&~0x80)
|
||||
#define FNT_ENTRY_LEN(e) (1 + FNT_ENTRY_FNLEN(e) + (FNT_ENTRY_ISDIR(e)?2:0))
|
||||
@ -22,26 +21,6 @@ typedef struct {
|
||||
} __attribute__((packed)) NitroFatEntry;
|
||||
|
||||
|
||||
// see: https://github.com/TASVideos/desmume/blob/master/desmume/src/bios.cpp#L1070tions
|
||||
u16 crc16_quick(const void* src, u32 len) {
|
||||
const u16 tabval[] = { CRC16_TABVAL };
|
||||
u16* data = (u16*) src;
|
||||
u16 crc = 0xFFFF;
|
||||
|
||||
for (len >>= 1; len; len--) {
|
||||
u16 curr = *(data++);
|
||||
for (u32 i = 0; i < 4; i++) {
|
||||
u16 tval = tabval[crc&0xF];
|
||||
crc >>= 4;
|
||||
crc ^= tval;
|
||||
tval = tabval[(curr >> (4*i))&0xF];
|
||||
crc ^= tval;
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
u32 ValidateTwlHeader(TwlHeader* twl) {
|
||||
if (twl->logo_crc != NDS_LOGO_CRC16) return 1;
|
||||
return (crc16_quick(twl->logo, sizeof(twl->logo)) == NDS_LOGO_CRC16) ? 0 : 1;
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "support.h"
|
||||
#include "ui.h"
|
||||
#include "hid.h"
|
||||
#include "touchcal.h"
|
||||
#include "fs.h"
|
||||
#include "utils.h"
|
||||
#include "nand.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user