Skip to content

Commit

Permalink
Switch: hw acceleration + swkbd supports
Browse files Browse the repository at this point in the history
  • Loading branch information
usineur committed Jan 5, 2019
1 parent 072688f commit d2e2200
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 23 deletions.
16 changes: 15 additions & 1 deletion CMakeLists.txt
Expand Up @@ -21,16 +21,30 @@ add_executable(${CMAKE_PROJECT_NAME}.elf
target_link_libraries(${CMAKE_PROJECT_NAME}.elf
SDL2_image
SDL2
EGL
glapi
drm_nouveau
jpeg
png
z
nx
m
stdc++
-specs=${DEVKITPRO}/libnx/switch.specs
)

add_custom_target(${CMAKE_PROJECT_NAME}.nro
DEPENDS ${CMAKE_PROJECT_NAME}.elf
COMMAND nacptool --create "${CMAKE_PROJECT_NAME}" "usineur" "1.0" ${CMAKE_PROJECT_NAME}.nacp
COMMAND nacptool --create "${CMAKE_PROJECT_NAME}" "usineur" "1.1" ${CMAKE_PROJECT_NAME}.nacp
COMMAND elf2nro ${CMAKE_PROJECT_NAME}.elf ${CMAKE_PROJECT_NAME}.nro --icon=${CMAKE_SOURCE_DIR}/res/icon.jpg --nacp=${CMAKE_PROJECT_NAME}.nacp
)

add_custom_target(send
COMMAND curl -T ${CMAKE_PROJECT_NAME}.nro ftp://$(SWITCHIP):5000/switch/${CMAKE_PROJECT_NAME}/
DEPENDS ${CMAKE_PROJECT_NAME}.nro
)

add_custom_target(nxlink
COMMAND nxlink -a $(SWITCHIP) ${CMAKE_PROJECT_NAME}.nro -s -p ${CMAKE_PROJECT_NAME}/${CMAKE_PROJECT_NAME}.nro
DEPENDS ${CMAKE_PROJECT_NAME}.nro
)
2 changes: 1 addition & 1 deletion src/proto.h
Expand Up @@ -466,7 +466,7 @@ void __pascal far draw_table(int which_table);
void __pascal far draw_wipes(int which);
void __pascal far draw_back_fore(int which_table,int index);
void __pascal far draw_mid(int index);
void __pascal far draw_image(image_type far *image,image_type far *mask,int xpos,int ypos,int blit);
void __pascal far draw_image_1(image_type far *image,image_type far *mask,int xpos,int ypos,int blit);
void __pascal far draw_wipe(int index);
void __pascal far calc_gate_pos();
void __pascal far draw_gate_back();
Expand Down
8 changes: 8 additions & 0 deletions src/seg000.c
Expand Up @@ -22,6 +22,10 @@ The authors of this program may be contacted at http://forum.princed.org
#include <setjmp.h>
#include <math.h>

#ifdef __SWITCH__
#include <switch.h>
#endif

// data:461E
dat_type * dathandle;

Expand All @@ -30,6 +34,10 @@ word need_redraw_because_flipped;

// seg000:0000
void far pop_main() {
#ifdef NXLINK
socketInitializeDefault();
nxlinkStdio();
#endif
if (check_param("--version") || check_param("-v")) {
printf ("SDLPoP v%s\n", SDLPOP_VERSION);
exit(0);
Expand Down
6 changes: 3 additions & 3 deletions src/seg008.c
Expand Up @@ -900,7 +900,7 @@ void __pascal far draw_back_fore(int which_table,int index) {
mask = chtab->images[chtab->n_images / 2 + table_entry->id];
}
*/
draw_image(image, mask, table_entry->xh * 8 + table_entry->xl, table_entry->y, table_entry->blit);
draw_image_1(image, mask, table_entry->xh * 8 + table_entry->xl, table_entry->y, table_entry->blit);
}


Expand Down Expand Up @@ -989,7 +989,7 @@ void __pascal far draw_mid(int index) {
add_peel(round_xpos_to_byte(xpos, 0), round_xpos_to_byte(image->w/*width*/ + xpos, 1), ypos, image->h/*height*/);
}
//printf("Midtable: drawing (chtab %d, image %d) at (x=%d, y=%d)\n",chtab_id,image_id,xpos,ypos); // debug
draw_image(image, mask, xpos, ypos, blit);
draw_image_1(image, mask, xpos, ypos, blit);

if (chtab_flip_clip[chtab_id]) {
reset_clip_rect();
Expand All @@ -1004,7 +1004,7 @@ void __pascal far draw_mid(int index) {
}

// seg008:167B
void __pascal far draw_image(image_type far *image,image_type far *mask,int xpos,int ypos,int blit) {
void __pascal far draw_image_1(image_type far *image,image_type far *mask,int xpos,int ypos,int blit) {
rect_type rect;
switch (blit) {
case blitters_10h_transp:
Expand Down
33 changes: 15 additions & 18 deletions src/seg009.c
Expand Up @@ -41,16 +41,7 @@ The authors of this program may be contacted at http://forum.princed.org
#define BTN_UP 13
#define BTN_RIGHT 14
#define BTN_DOWN 15

int access(const char *pathname, int mode)
{
struct stat st;

if (stat(pathname, &st) < 0)
return -1;

return 0;
}
#include <switch.h>
#endif

// Most functions in this file are different from those in the original game.
Expand Down Expand Up @@ -279,6 +270,9 @@ void __pascal far restore_stuff() {

// seg009:0E33
int __pascal far key_test_quit() {
#ifdef NXLINK
socketExit();
#endif
word key;
key = read_key();
if (key == (SDL_SCANCODE_Q | WITH_CTRL)) { // ctrl-q
Expand Down Expand Up @@ -1482,6 +1476,13 @@ void __pascal far draw_text_cursor(int xpos,int ypos,int color) {

// seg009:053C
int __pascal far input_str(const rect_type far *rect,char *buffer,int max_length,const char *initial,int has_initial,int arg_4,int color,int bgcolor) {
#ifdef __SWITCH__
SwkbdConfig kbd;
swkbdCreate(&kbd, 0);
swkbdConfigMakePresetDefault(&kbd);
swkbdShow(&kbd, buffer, max_length);
return strlen(buffer);
#endif
short length;
word key;
short cursor_visible;
Expand Down Expand Up @@ -2279,19 +2280,19 @@ void __pascal far set_gr_mode(byte grmode) {
#ifdef SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING
SDL_SetHint(SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING, "1");
#endif
#ifdef __SWITCH__
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK) != 0) {
#else
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE |
SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC ) != 0) {
#endif
sdlperror("SDL_Init");
quit(1);
}

//SDL_EnableUNICODE(1); //deprecated
Uint32 flags = 0;
#ifdef __SWITCH__
start_fullscreen = 1;
#else
if (!start_fullscreen) start_fullscreen = check_param("full") != NULL;
#endif
if (start_fullscreen) flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
flags |= SDL_WINDOW_RESIZABLE;
flags |= SDL_WINDOW_ALLOW_HIGHDPI; // for Retina displays
Expand All @@ -2309,11 +2310,7 @@ void __pascal far set_gr_mode(byte grmode) {
pop_window_width, pop_window_height, flags);
// Make absolutely sure that VSync will be off, to prevent timer issues.
SDL_SetHint(SDL_HINT_RENDER_VSYNC, "0");
#ifdef __SWITCH__
renderer_ = SDL_CreateRenderer(window_, -1 , SDL_RENDERER_SOFTWARE);
#else
renderer_ = SDL_CreateRenderer(window_, -1 , SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
#endif
SDL_RendererInfo renderer_info;
if (SDL_GetRendererInfo(renderer_, &renderer_info) == 0) {
if (renderer_info.flags & SDL_RENDERER_TARGETTEXTURE) {
Expand Down

0 comments on commit d2e2200

Please sign in to comment.