From be17031ffcba0105b06b76355c7ddae00cb5226a Mon Sep 17 00:00:00 2001 From: MasterFeizz Date: Thu, 22 Oct 2015 22:56:57 -0400 Subject: [PATCH] Initial networking and overlay enhancements --- Makefile | 7 +- keyboardOverlay.bin | Bin 153600 -> 153600 bytes source/in_ctr.c | 141 +------------- source/net_dgrm.c | 14 +- source/net_udp.h | 2 +- source/net_udpctr.c | 446 ++++++++++++++++++++++++++++++++++++++++++++ source/sys_ctr.c | 7 +- source/touch_ctr.c | 163 ++++++++++++++++ source/touch_ctr.h | 16 ++ source/vid_ctr.c | 15 +- 10 files changed, 656 insertions(+), 155 deletions(-) create mode 100644 source/net_udpctr.c create mode 100644 source/touch_ctr.c create mode 100644 source/touch_ctr.h diff --git a/Makefile b/Makefile index 7f52991..d6ee7cc 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,7 @@ BUILD := build SOURCES := source APP_AUTHOR := MasterFeizz APP_TITLE := ctrQuake +APP_DESCRIPTION := Port of Quake DATA := data INCLUDES := include @@ -143,9 +144,11 @@ COMMON_OBJS = chase.o \ snd_mem.o \ snd_ctr.o \ vid_ctr.o \ - net_none.o \ + net_bsd.o \ + net_udpctr.o \ in_ctr.o \ - cd_null.o + cd_null.o \ + touch_ctr.o CFILES := $(COMMON_OBJS) diff --git a/keyboardOverlay.bin b/keyboardOverlay.bin index 6f49d47608d6ff7b6e4a93823a685338da13c76f..4e38be9477f720b20cbd721334e989c64ff04356 100644 GIT binary patch literal 153600 zcmeHQO_JL-7o2jum}@w87Ov8_n5CCqx{8~eA#KE;=U=F_5PoEj{|9sOwF>pKs zjJJ<(E&^Xaz9H`2tbghy4z3jgh`INlUtTR1zf1YVz?B(zH$QLKJ>T*^+!LxU26`Ci z)y?nUKFrS?&_6f!+kansW)oHnL=3$C_=-5{`G?r!-tWiPmshiR`ul%>m0sbzB^>&M zH7=ikhu41*dtJ{Eh`m_oHrgrXT0pyw$FG zJCa?$^MO*Vb(O2(b>a2&IN;NqW$o^yf1$4B>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#r|Jv0$J*62S|I(Tyr`qL&{7Y++J?%0;{8o>}i()@~>U3ldEa2$-j2BPETnD$iK8E$*FcZA^*~vWKX*c zkbmuJom@?GP5!m3b$UuOK>npQNlvxP3Hg`SBzxLrfc$G$>*Q*hYx1vMtcu%>1^8Nn# zGTf!rSSSCzzkYsvuDZY9;uHqfs!Q5!^V}kj;q4J!d98%C7c9Q7zYh_I*VacMz%$PQ zuTf8@|0=AL*Y)`~@U&ZjZ{NONzS`6&dANR_<=*f0^YkW<<*Lt-(R1$l?CW_t5RmtP zyZ&V9cJEhfozz;_ufu&H`L{loTCraE*K;JSzKB_C9@kpecwNoczLeh4Ao#3^K)ru|jYrE*5Z2A7*?q9c;@K3Lg+xhr;Q?D1iR`IkqoAYbBw?+Q# zk$B^nx8e`A*H@r?WnkJ|1zve!90+Wp^+ZBws#<9_mQ zkHj0tO#bba9Y=_p{2Nyz&st}I{5t|i_BsdhuXVlC-#7#0-(J~qgt*DSaW(R+bq2`4 zBXDG|b0Gg(*E{`+HWk%Drb?^qH>l?>8r}=jXq>|J=sKKUou#D=>^@)=X}F z-apRIKgKNCn)AaUPc4)FNZS|4Kf{|QrGDgXcg diff --git a/source/in_ctr.c b/source/in_ctr.c index b9283a8..202dcfd 100644 --- a/source/in_ctr.c +++ b/source/in_ctr.c @@ -26,158 +26,30 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <3ds.h> #include "ctr.h" -//Touchscreen mode identifiers -#define TMODE_TOUCHPAD 1 -#define TMODE_KEYBOARD 2 -#define TMODE_SETTINGS 3 - -//Keyboard is currently laid out on a 14*4 grid of 20px*20px boxes for lazy implementation -char keymap[14 * 4] = { - '`' , '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '+', K_BACKSPACE, - K_TAB, 'q' , 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '|', - 0, 'a' , 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', K_ENTER, K_ENTER, - K_SHIFT, 'z' , 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', K_SHIFT, K_SHIFT, K_SHIFT -}; - -u16* touchpadOverlay; -u16* keyboardOverlay; - circlePosition cstick; circlePosition circlepad; touchPosition oldtouch, touch; -char lastKey = 0; - -int tmode; -u16* tfb; - -u64 lastTap = 0; -void ctrTouchpadTap(){ - u64 thisTap = Sys_FloatTime(); - if(oldtouch.py > 195 && oldtouch.py < 240 && oldtouch.px > 0 && oldtouch.px < 45){ - Key_Event('`', true); - lastKey = '`'; - } - else if(oldtouch.py > 195 && oldtouch.py < 240 && oldtouch.px > 1 && oldtouch.px < 320){ - tmode = 2; - ctrDrawTouchOverlay(); - } - else if ((thisTap - lastTap) < 0.5){ - Key_Event(K_SPACE, true); - lastKey = K_SPACE; - } - lastTap = thisTap; -} - -void ctrKeyboardTap(){ - if(oldtouch.py > 20 && oldtouch.py < 100 && oldtouch.px > 15 && oldtouch.px < 295){ - char key = keymap[((oldtouch.py - 20) / 20) * 14 + (oldtouch.px - 15)/20]; - Key_Event(key, true); - lastKey = key; - } - - else if(oldtouch.py > 100 && oldtouch.py < 120 && oldtouch.px > 95 && oldtouch.px < 215){ - Key_Event(K_SPACE, true); - lastKey = K_SPACE; - } - - if(oldtouch.py > 195 && oldtouch.py < 240 && oldtouch.px > 1 && oldtouch.px < 320){ - tmode = 1; - ctrDrawTouchOverlay(); - } -} - -void ctrProcessTap(){ - if(tmode == TMODE_TOUCHPAD) - ctrTouchpadTap(); - else - ctrKeyboardTap(); -} - -void ctrDrawTouchOverlay(){ - u16* overlay = 0; - if(tmode == TMODE_TOUCHPAD) - overlay = touchpadOverlay; - else - overlay = keyboardOverlay; - - if(!overlay) - return; - int x,y; - - for(x=0; x<320; x++){ - for(y=0; y<240;y++){ - tfb[(x*240 + (239 - y))] = overlay[(y*320 + x)]; - } - } - -} void IN_Init (void) { if ( COM_CheckParm ("-nomouse") ) return; - - tmode = TMODE_TOUCHPAD; //Start in touchpad Mode - - tfb = (u16*)gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL); - - //Load overlay files from sdmc for easier testing - FILE *texture = fopen("touchpadOverlay.bin", "rb"); - if(!texture) - Sys_Error("Could not open touchpadOverlay.bin\n"); - fseek(texture, 0, SEEK_END); - int size = ftell(texture); - fseek(texture, 0, SEEK_SET); - touchpadOverlay = malloc(size); - fread(touchpadOverlay, 1, size, texture); - fclose(texture); - - texture = fopen("keyboardOverlay.bin", "rb"); - if(!texture) - Sys_Error("Could not open keyboardOverlay.bin\n"); - fseek(texture, 0, SEEK_END); - size = ftell(texture); - fseek(texture, 0, SEEK_SET); - keyboardOverlay = malloc(size); - fread(keyboardOverlay, 1, size, texture); - fclose(texture); } void IN_Shutdown (void) { - free(touchpadOverlay); - free(keyboardOverlay); } void IN_Commands (void) { } -u64 tick; - void IN_Move (usercmd_t *cmd) { - - if(lastKey){ - Key_Event(lastKey, false); - lastKey = 0; - } - - if(hidKeysDown() & KEY_TOUCH){ - hidTouchRead(&oldtouch); - tick = Sys_FloatTime(); - } - - //If touchscreen is released in certain amount of time it's a tap - if(hidKeysUp() & KEY_TOUCH){ - if((Sys_FloatTime() - tick) < 1.0) //FIX ME: find optimal timeframe - ctrProcessTap(); - } - - else if(hidKeysHeld() & KEY_TOUCH){ + if(hidKeysHeld() & KEY_TOUCH){ hidTouchRead(&touch); - touch.px = (touch.px + oldtouch.px) / 2; - touch.py = (touch.py + oldtouch.py) / 2; + touch.px = (touch.px + oldtouch.px) / 2; + touch.py = (touch.py + oldtouch.py) / 2; cl.viewangles[YAW] -= (touch.px - oldtouch.px) * sensitivity.value/2; if(in_mlook.state & 1) cl.viewangles[PITCH] += (touch.py - oldtouch.py) * sensitivity.value/2; @@ -185,8 +57,11 @@ void IN_Move (usercmd_t *cmd) } hidCircleRead(&circlepad); - cmd->forwardmove += m_forward.value * circlepad.dy * 2; //FIX ME: allow circlepad sensitivity to be changed - cmd->sidemove += m_side.value * circlepad.dx * 2; //FIX ME: allow player to choose between strafing or turning + //CirclePad deadzone to fix ghost movements + if(abs(circlepad.dy) > 15) + cmd->forwardmove += m_forward.value * circlepad.dy * 2; //FIX ME: allow circlepad sensitivity to be changed + if(abs(circlepad.dx) > 15) + cmd->sidemove += m_side.value * circlepad.dx * 2; //FIX ME: allow player to choose between strafing or turning //cStick is only available on N3DS... Until libctru implements support for circlePad Pro if(isN3DS){ diff --git a/source/net_dgrm.c b/source/net_dgrm.c index a293b77..ae13517 100644 --- a/source/net_dgrm.c +++ b/source/net_dgrm.c @@ -8,7 +8,7 @@ of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -326,7 +326,7 @@ int Datagram_GetMessage (qsocket_t *sock) ReSendMessage (sock); while(1) - { + { length = sfunc.Read (sock->socket, (byte *)&packetBuffer, NET_DATAGRAMSIZE, &readaddr); // if ((rand() & 255) > 220) @@ -890,7 +890,7 @@ static qsocket_t *_Datagram_CheckNewConnections (void) int activeNumber; int clientNumber; client_t *client; - + playerNumber = MSG_ReadByte(); activeNumber = -1; for (clientNumber = 0, client = svs.clients; clientNumber < svs.maxclients; clientNumber++, client++) @@ -1067,7 +1067,7 @@ static qsocket_t *_Datagram_CheckNewConnections (void) return NULL; } - // everything is allocated, just fill in the details + // everything is allocated, just fill in the details sock->socket = newsock; sock->landriver = net_landriverlevel; sock->addr = clientaddr; @@ -1210,7 +1210,8 @@ void Datagram_SearchForHosts (qboolean xmit) } } - +//Temporary fix for 3DS +int ctrport_fix = 5001; static qsocket_t *_Datagram_Connect (char *host) { struct qsockaddr sendaddr; @@ -1227,7 +1228,8 @@ static qsocket_t *_Datagram_Connect (char *host) if (dfunc.GetAddrFromName(host, &sendaddr) == -1) return NULL; - newsock = dfunc.OpenSocket (0); + newsock = dfunc.OpenSocket (ctrport_fix); + ctrport_fix++; if (newsock == -1) return NULL; diff --git a/source/net_udp.h b/source/net_udp.h index 7530301..780bdbf 100644 --- a/source/net_udp.h +++ b/source/net_udp.h @@ -8,7 +8,7 @@ of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. diff --git a/source/net_udpctr.c b/source/net_udpctr.c new file mode 100644 index 0000000..3d44808 --- /dev/null +++ b/source/net_udpctr.c @@ -0,0 +1,446 @@ +/* +Copyright (C) 1996-1997 Id Software, Inc. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ +// net_udp.c + +#include "quakedef.h" +#include "net_udp.h" + +#include +#include +#include + +#include <3ds.h> +#include + + +inline uint32_t htonl(uint32_t hostlong) +{ + return __builtin_bswap32(hostlong); +} + +inline uint16_t htons(uint16_t hostshort) +{ + return __builtin_bswap16(hostshort); +} + +inline uint32_t ntohl(uint32_t netlong) +{ + return __builtin_bswap32(netlong); +} + +inline uint16_t ntohs(uint16_t netshort) +{ + return __builtin_bswap16(netshort); +} + +#define SOC_BUFFERSIZE 0x100000 +#define SOC_ALIGN 0x1000 + +static u32 *SOC_buffer = NULL; + +extern int gethostname (char *, int); +extern int close (int); + +extern cvar_t hostname; + +static int net_acceptsocket = -1; // socket for fielding new connections +static int net_controlsocket; +static int net_broadcastsocket = 0; +static struct qsockaddr broadcastaddr; + +static unsigned long myAddr; + +#include "net_udp.h" + +//============================================================================= + +int UDP_Init (void) +{ + struct hostent *local; + char buff[15]; + struct qsockaddr addr; + char *colon; + int ret; + + if (COM_CheckParm ("-noudp")) + return -1; + + SOC_buffer = (u32*)memalign(SOC_ALIGN, SOC_BUFFERSIZE); + if(SOC_buffer == NULL) + { + Sys_Error("Failed to allocate SOC_Buffer\n"); + } + ret = SOC_Initialize(SOC_buffer, SOC_BUFFERSIZE); + if(SOC_buffer == NULL) + { + Sys_Error("SOC_Initialize failed\n"); + } + myAddr = gethostid(); + + // if the quake hostname isn't set, set it to the machine name + if (Q_strcmp(hostname.string, "UNNAMED") == 0) + { + Cvar_Set ("hostname", "3ds"); + } + + if ((net_controlsocket = UDP_OpenSocket (5000)) == -1) //Passing 0 causes function to fail on 3DS + Sys_Error("UDP_Init: Unable to open control socket\n"); + + ((struct sockaddr_in *)&broadcastaddr)->sin_family = AF_INET; + ((struct sockaddr_in *)&broadcastaddr)->sin_addr.s_addr = INADDR_BROADCAST; + ((struct sockaddr_in *)&broadcastaddr)->sin_port = htons(net_hostport); + + UDP_GetSocketAddr (net_controlsocket, &addr); + Q_strcpy(my_tcpip_address, UDP_AddrToString (&addr)); + colon = Q_strrchr (my_tcpip_address, ':'); + if (colon) + *colon = 0; + + Con_Printf("UDP Initialized\n"); + tcpipAvailable = true; + + return net_controlsocket; +} + +//============================================================================= + +void UDP_Shutdown (void) +{ + UDP_Listen (false); + UDP_CloseSocket (net_controlsocket); +} + +//============================================================================= + +void UDP_Listen (qboolean state) +{ + // enable listening + if (state) + { + if (net_acceptsocket != -1) + return; + if ((net_acceptsocket = UDP_OpenSocket (net_hostport)) == -1) + Sys_Error ("UDP_Listen: Unable to open accept socket\n"); + return; + } + + // disable listening + if (net_acceptsocket == -1) + return; + UDP_CloseSocket (net_acceptsocket); + net_acceptsocket = -1; +} + +//============================================================================= + +int UDP_OpenSocket (int port) +{ + int newsocket; + struct sockaddr_in address; + qboolean _true = true; + int yes = 1; + int rc; + + if ((newsocket = socket(AF_INET, SOCK_DGRAM, 0)) == -1) + return -1; + + int flags = fcntl(newsocket, F_GETFL, 0); + if ( fcntl(newsocket, F_SETFL, flags | O_NONBLOCK) == -1) + goto ErrorReturn; + + address.sin_family = AF_INET; + address.sin_addr.s_addr = htonl(INADDR_ANY); + address.sin_port = htons(port); + + + if( bind (newsocket, (void *)&address, sizeof(address)) == -1) + goto ErrorReturn; + + return newsocket; + +ErrorReturn: + close (newsocket); + return -1; +} + +//============================================================================= + +int UDP_CloseSocket (int socket) +{ + if (socket == net_broadcastsocket) + net_broadcastsocket = 0; + close (socket); + return SOC_Shutdown(); +} + + +//============================================================================= +/* +============ +PartialIPAddress + +this lets you type only as much of the net address as required, using +the local network components to fill in the rest +============ +*/ +static int PartialIPAddress (char *in, struct qsockaddr *hostaddr) +{ + char buff[256]; + char *b; + int addr; + int num; + int mask; + int run; + int port; + + buff[0] = '.'; + b = buff; + strcpy(buff+1, in); + if (buff[1] == '.') + b++; + + addr = 0; + mask=-1; + while (*b == '.') + { + b++; + num = 0; + run = 0; + while (!( *b < '0' || *b > '9')) + { + num = num*10 + *b++ - '0'; + if (++run > 3) + return -1; + } + if ((*b < '0' || *b > '9') && *b != '.' && *b != ':' && *b != 0) + return -1; + if (num < 0 || num > 255) + return -1; + mask<<=8; + addr = (addr<<8) + num; + } + + if (*b++ == ':') + port = Q_atoi(b); + else + port = net_hostport; + + hostaddr->sa_family = AF_INET; + ((struct sockaddr_in *)hostaddr)->sin_port = htons((short)port); + ((struct sockaddr_in *)hostaddr)->sin_addr.s_addr = (myAddr & htonl(mask)) | htonl(addr); + + return 0; +} +//============================================================================= + +int UDP_Connect (int socket, struct qsockaddr *addr) +{ + return 0; +} + +//============================================================================= + +int UDP_CheckNewConnections (void) +{ + unsigned long available; + char buf[4]; + + if (net_acceptsocket == -1) + return -1; + + if (recvfrom (net_acceptsocket, buf, 4, 0x10000000, NULL, NULL) > 0) + return net_acceptsocket; + + return -1; +} + +//============================================================================= + +int UDP_Read (int socket, byte *buf, int len, struct qsockaddr *addr) +{ + int addrlen = sizeof (struct qsockaddr); + int ret; + + ret = recvfrom (socket, buf, len, 0, (struct sockaddr *)addr, &addrlen); + if (ret == -1 ) + return 0; + return ret; +} + +//============================================================================= + +int UDP_MakeSocketBroadcastCapable (int socket) +{ + int i = 1; + + //This will fail on 3DS with current version of libctru + // make this socket broadcast capable + //if (setsockopt(socket, SOL_SOCKET, SO_BROADCAST, &i, sizeof(i)) < 0) + // return -1; + net_broadcastsocket = socket; + + return 0; +} + +//============================================================================= + +int UDP_Broadcast (int socket, byte *buf, int len) +{ + int ret; + + if (socket != net_broadcastsocket) + { + if (net_broadcastsocket != 0) + Sys_Error("Attempted to use multiple broadcasts sockets\n"); + ret = UDP_MakeSocketBroadcastCapable (socket); + if (ret == -1) + { + Con_Printf("Unable to make socket broadcast capable\n"); + return ret; + } + } + + return UDP_Write (socket, buf, len, &broadcastaddr); +} + +//============================================================================= + +int UDP_Write (int socket, byte *buf, int len, struct qsockaddr *addr) +{ + int ret; + + ret = sendto (socket, buf, len, 0, (struct sockaddr *)addr, sizeof(struct qsockaddr)); + if (ret == -1 ) + return 0; + return ret; +} + +//============================================================================= + +char *UDP_AddrToString (struct qsockaddr *addr) +{ + static char buffer[22]; + int haddr; + + haddr = ntohl(((struct sockaddr_in *)addr)->sin_addr.s_addr); + sprintf(buffer, "%d.%d.%d.%d:%d", (haddr >> 24) & 0xff, (haddr >> 16) & 0xff, (haddr >> 8) & 0xff, haddr & 0xff, ntohs(((struct sockaddr_in *)addr)->sin_port)); + return buffer; +} + +//============================================================================= + +int UDP_StringToAddr (char *string, struct qsockaddr *addr) +{ + int ha1, ha2, ha3, ha4, hp; + int ipaddr; + + sscanf(string, "%d.%d.%d.%d:%d", &ha1, &ha2, &ha3, &ha4, &hp); + ipaddr = (ha1 << 24) | (ha2 << 16) | (ha3 << 8) | ha4; + + addr->sa_family = AF_INET; + ((struct sockaddr_in *)addr)->sin_addr.s_addr = htonl(ipaddr); + ((struct sockaddr_in *)addr)->sin_port = htons(hp); + return 0; +} + +//============================================================================= + +int UDP_GetSocketAddr (int socket, struct qsockaddr *addr) +{ + int addrlen = sizeof(struct qsockaddr); + unsigned int a; + + Q_memset(addr, 0, sizeof(struct qsockaddr)); + getsockname(socket, (struct sockaddr *)addr, &addrlen); + a = ((struct sockaddr_in *)addr)->sin_addr.s_addr; + if (a == 0 || a == inet_addr("127.0.0.1")) + ((struct sockaddr_in *)addr)->sin_addr.s_addr = myAddr; + + return 0; +} + +//============================================================================= + +int UDP_GetNameFromAddr (struct qsockaddr *addr, char *name) +{ + struct hostent *hostentry; + + hostentry = gethostbyaddr ((char *)&((struct sockaddr_in *)addr)->sin_addr, sizeof(struct in_addr), AF_INET); + if (hostentry) + { + Q_strncpy (name, (char *)hostentry->h_name, NET_NAMELEN - 1); + return 0; + } + + Q_strcpy (name, UDP_AddrToString (addr)); + return 0; +} + +//============================================================================= + +int UDP_GetAddrFromName(char *name, struct qsockaddr *addr) +{ + struct hostent *hostentry; + + if (name[0] >= '0' && name[0] <= '9') + return PartialIPAddress (name, addr); + + hostentry = gethostbyname (name); + if (!hostentry) + return -1; + + addr->sa_family = AF_INET; + ((struct sockaddr_in *)addr)->sin_port = htons(net_hostport); + ((struct sockaddr_in *)addr)->sin_addr.s_addr = *(int *)hostentry->h_addr_list[0]; + + return 0; +} + +//============================================================================= + +int UDP_AddrCompare (struct qsockaddr *addr1, struct qsockaddr *addr2) +{ + if (addr1->sa_family != addr2->sa_family) + return -1; + + if (((struct sockaddr_in *)addr1)->sin_addr.s_addr != ((struct sockaddr_in *)addr2)->sin_addr.s_addr) + return -1; + + if (((struct sockaddr_in *)addr1)->sin_port != ((struct sockaddr_in *)addr2)->sin_port) + return 1; + + return 0; +} + +//============================================================================= + +int UDP_GetSocketPort (struct qsockaddr *addr) +{ + return ntohs(((struct sockaddr_in *)addr)->sin_port); +} + + +int UDP_SetSocketPort (struct qsockaddr *addr, int port) +{ + ((struct sockaddr_in *)addr)->sin_port = htons(port); + return 0; +} + +//============================================================================= diff --git a/source/sys_ctr.c b/source/sys_ctr.c index 18246ff..57897ef 100644 --- a/source/sys_ctr.c +++ b/source/sys_ctr.c @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <3ds.h> #include "ctr.h" +#include "touch_ctr.h" u8 isN3DS; @@ -289,6 +290,8 @@ void Sys_SendKeyEvents (void) CTR_KeyDown(kDown); if(kUp) CTR_KeyUp(kUp); + + Touch_Update(); } void Sys_HighFPPrecision (void) @@ -304,6 +307,7 @@ void Sys_LowFPPrecision (void) int main (int argc, char **argv) { float time, oldtime; + APT_CheckNew3DS(NULL, &isN3DS); if(isN3DS) osSetSpeedupEnable(true); @@ -326,7 +330,8 @@ int main (int argc, char **argv) parms.argv = com_argv; Host_Init (&parms); hostInitialized = true; - ctrDrawTouchOverlay(); + Touch_Init(); + Touch_DrawOverlay(); //Sys_Init(); oldtime = Sys_FloatTime() -0.1; while (1) diff --git a/source/touch_ctr.c b/source/touch_ctr.c new file mode 100644 index 0000000..24bd67f --- /dev/null +++ b/source/touch_ctr.c @@ -0,0 +1,163 @@ +/* +Copyright (C) 2015 Felipe Izzo + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +//FIX ME: load all hardcoded values from file + +#include "quakedef.h" + +#include <3ds.h> +#include "touch_ctr.h" + +//Keyboard is currently laid out on a 14*4 grid of 20px*20px boxes for lazy implementation +char keymap[14 * 6] = { + K_ESCAPE , K_F1, K_F2, K_F3, K_F4, K_F5, K_F6, K_F7, K_F8, K_F9, K_F10, K_F11, K_F12, 0, + '`' , '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '+', K_BACKSPACE, + K_TAB, 'q' , 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '|', + 0, 'a' , 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', K_ENTER, K_ENTER, + K_SHIFT, 'z' , 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 0, K_UPARROW, 0, + 0, 0 , 0, 0, K_SPACE, K_SPACE, K_SPACE, K_SPACE, K_SPACE, K_SPACE, 0, K_LEFTARROW, K_DOWNARROW, K_RIGHTARROW +}; + +u16* touchpadOverlay; +u16* keyboardOverlay; +char lastKey = 0; +int tmode; +u16* tfb; +touchPosition oldtouch, touch; +u64 tick; + +u64 lastTap = 0; +void Touch_TouchpadTap(){ + u64 thisTap = Sys_FloatTime(); + if(oldtouch.py > 195 && oldtouch.py < 240 && oldtouch.px > 0 && oldtouch.px < 45){ + Key_Event('`', true); + lastKey = '`'; + } + else if(oldtouch.py > 195 && oldtouch.py < 240 && oldtouch.px > 270 && oldtouch.px < 320){ + tmode = 2; + Touch_DrawOverlay(); + } + else if ((thisTap - lastTap) < 0.5){ + Key_Event(K_SPACE, true); + lastKey = K_SPACE; + } + lastTap = thisTap; +} + +int shiftToggle = 0; +void Touch_KeyboardTap(){ + if(oldtouch.py > 5 && oldtouch.py < 138 && oldtouch.px > 5 && oldtouch.px < 315){ + char key = keymap[((oldtouch.py - 6) / 22) * 14 + (oldtouch.px - 6)/22]; + if(key == K_SHIFT){ + shiftToggle = !shiftToggle; + Key_Event(K_SHIFT,shiftToggle); + Touch_DrawOverlay(); + } + else { + Key_Event(key, true); + lastKey = key; + } + } + + if(oldtouch.py > 195 && oldtouch.py < 240 && oldtouch.px > 270 && oldtouch.px < 320){ + tmode = 1; + shiftToggle = 0; + Key_Event(K_SHIFT,false); + Touch_DrawOverlay(); + } +} + +void Touch_ProcessTap(){ + if(tmode == TMODE_TOUCHPAD) + Touch_TouchpadTap(); + else + Touch_KeyboardTap(); +} + +void Touch_DrawOverlay(){ + u16* overlay = 0; + if(tmode == TMODE_TOUCHPAD) + overlay = touchpadOverlay; + else + overlay = keyboardOverlay; + + if(!overlay) + return; + int x,y; + + for(x=0; x<320; x++){ + for(y=0; y<240;y++){ + tfb[(x*240 + (239 - y))] = overlay[(y*320 + x)]; + } + } + + if(tmode == TMODE_KEYBOARD && shiftToggle == 1){ + for(x=20; x<24; x++){ + for(y=98; y<102;y++){ + tfb[(x*240 + (239 - y))] = RGB8_to_565(0,255,0); + } + } + } + +} + +void Touch_Init(){ + tmode = TMODE_TOUCHPAD; //Start in touchpad Mode + tfb = (u16*)gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL); + + //Load overlay files from sdmc for easier testing + FILE *texture = fopen("touchpadOverlay.bin", "rb"); + if(!texture) + Sys_Error("Could not open touchpadOverlay.bin\n"); + fseek(texture, 0, SEEK_END); + int size = ftell(texture); + fseek(texture, 0, SEEK_SET); + touchpadOverlay = malloc(size); + fread(touchpadOverlay, 1, size, texture); + fclose(texture); + + texture = fopen("keyboardOverlay.bin", "rb"); + if(!texture) + Sys_Error("Could not open keyboardOverlay.bin\n"); + fseek(texture, 0, SEEK_END); + size = ftell(texture); + fseek(texture, 0, SEEK_SET); + keyboardOverlay = malloc(size); + fread(keyboardOverlay, 1, size, texture); + fclose(texture); +} + +void Touch_Update(){ + if(lastKey){ + Key_Event(lastKey, false); + lastKey = 0; + } + + if(hidKeysDown() & KEY_TOUCH){ + hidTouchRead(&oldtouch); + tick = Sys_FloatTime(); + } + + //If touchscreen is released in certain amount of time it's a tap + if(hidKeysUp() & KEY_TOUCH){ + if((Sys_FloatTime() - tick) < 1.0) //FIX ME: find optimal timeframe + Touch_ProcessTap(); + } +} diff --git a/source/touch_ctr.h b/source/touch_ctr.h new file mode 100644 index 0000000..85d8646 --- /dev/null +++ b/source/touch_ctr.h @@ -0,0 +1,16 @@ +#ifndef __TOUCH__ +#define __TOUCH__ + +//Touchscreen mode identifiers +#define TMODE_TOUCHPAD 1 +#define TMODE_KEYBOARD 2 +#define TMODE_SETTINGS 3 + +void Touch_TouchpadTap(); +void Touch_KeyboardTap(); +void Touch_ProcessTap(); +void Touch_DrawOverlay(); +void Touch_Init(); +void Touch_Update(); + +#endif diff --git a/source/vid_ctr.c b/source/vid_ctr.c index 8f083ee..f62d452 100644 --- a/source/vid_ctr.c +++ b/source/vid_ctr.c @@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. viddef_t vid; // global video state -int basewidth, baseheight, offset; +int basewidth, baseheight; byte *vid_buffer; short *zbuffer; @@ -59,16 +59,7 @@ void VID_ShiftPalette (unsigned char *palette) void VID_Init (unsigned char *palette) { baseheight = 240; - - if(isN3DS){ - basewidth = 400; - offset = 0; - } - - else{ - basewidth = 320; - offset = 40; - } + basewidth = 400; vid_buffer = malloc(sizeof(byte) * basewidth * baseheight); zbuffer = malloc(sizeof(short) * basewidth * baseheight); @@ -96,7 +87,7 @@ void VID_Update (vrect_t *rects) int x,y; for(x=0; x