From 29fb71cab865b76a2a0700e6e8382c100491c456 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 13 Jun 2019 13:11:33 +0200 Subject: BAHAHAHAHHHH mostly just going to derp around some, so don't hold your breath here --- src/NDS.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/NDS.h b/src/NDS.h index 3243337..9b7a10a 100644 --- a/src/NDS.h +++ b/src/NDS.h @@ -120,7 +120,8 @@ extern u8 ROMSeed1[2*8]; extern u8 ARM9BIOS[0x1000]; extern u8 ARM7BIOS[0x4000]; -#define MAIN_RAM_SIZE 0x400000 +//#define MAIN_RAM_SIZE 0x400000 +#define MAIN_RAM_SIZE 0x1000000 extern u8 MainRAM[MAIN_RAM_SIZE]; -- cgit v1.2.3 From b03c727fb9525b90163472962bb59713ed535da5 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 13 Jun 2019 13:59:11 +0200 Subject: blarg --- melonDS.cbp | 4 ++++ src/DSi.cpp | 17 +++++++++++++++++ src/DSi.h | 17 +++++++++++++++++ src/DSiCrypto.cpp | 17 +++++++++++++++++ src/DSiCrypto.h | 17 +++++++++++++++++ 5 files changed, 72 insertions(+) create mode 100644 src/DSi.cpp create mode 100644 src/DSi.h create mode 100644 src/DSiCrypto.cpp create mode 100644 src/DSiCrypto.h (limited to 'src') diff --git a/melonDS.cbp b/melonDS.cbp index 0af2f4a..59df311 100644 --- a/melonDS.cbp +++ b/melonDS.cbp @@ -100,6 +100,10 @@ + + + + diff --git a/src/DSi.cpp b/src/DSi.cpp new file mode 100644 index 0000000..6a524dd --- /dev/null +++ b/src/DSi.cpp @@ -0,0 +1,17 @@ +/* + Copyright 2016-2019 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ diff --git a/src/DSi.h b/src/DSi.h new file mode 100644 index 0000000..6a524dd --- /dev/null +++ b/src/DSi.h @@ -0,0 +1,17 @@ +/* + Copyright 2016-2019 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ diff --git a/src/DSiCrypto.cpp b/src/DSiCrypto.cpp new file mode 100644 index 0000000..6a524dd --- /dev/null +++ b/src/DSiCrypto.cpp @@ -0,0 +1,17 @@ +/* + Copyright 2016-2019 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ diff --git a/src/DSiCrypto.h b/src/DSiCrypto.h new file mode 100644 index 0000000..6a524dd --- /dev/null +++ b/src/DSiCrypto.h @@ -0,0 +1,17 @@ +/* + Copyright 2016-2019 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ -- cgit v1.2.3 From 0e421ccebd3ebabfbbabcae96acc262b76198ad2 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 13 Jun 2019 14:41:54 +0200 Subject: add all sorts of shit --- melonDS.cbp | 9 + src/DSi.cpp | 16 ++ src/DSi.h | 14 ++ src/DSiCrypto.h | 7 + src/NDS.cpp | 36 +-- src/NDS.h | 4 +- src/sha1/sha1.c | 276 +++++++++++++++++++++ src/sha1/sha1.h | 17 ++ src/tiny-AES-c/README.md | 80 ++++++ src/tiny-AES-c/aes.c | 572 +++++++++++++++++++++++++++++++++++++++++++ src/tiny-AES-c/aes.h | 90 +++++++ src/tiny-AES-c/aes.hpp | 12 + src/tiny-AES-c/unlicense.txt | 24 ++ 13 files changed, 1141 insertions(+), 16 deletions(-) create mode 100644 src/sha1/sha1.c create mode 100644 src/sha1/sha1.h create mode 100644 src/tiny-AES-c/README.md create mode 100644 src/tiny-AES-c/aes.c create mode 100644 src/tiny-AES-c/aes.h create mode 100644 src/tiny-AES-c/aes.hpp create mode 100644 src/tiny-AES-c/unlicense.txt (limited to 'src') diff --git a/melonDS.cbp b/melonDS.cbp index 59df311..97958f5 100644 --- a/melonDS.cbp +++ b/melonDS.cbp @@ -254,6 +254,15 @@ + + + + + + + diff --git a/src/DSi.cpp b/src/DSi.cpp index 6a524dd..376e6a0 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -15,3 +15,19 @@ You should have received a copy of the GNU General Public License along with melonDS. If not, see http://www.gnu.org/licenses/. */ + +#include "DSi.h" +#include "tiny-AES-c/aes.hpp" +#include "sha1/sha1.h" + +namespace DSi +{ + +bool LoadNAND() +{ + // + + return true; +} + +} diff --git a/src/DSi.h b/src/DSi.h index 6a524dd..2c71ad9 100644 --- a/src/DSi.h +++ b/src/DSi.h @@ -15,3 +15,17 @@ You should have received a copy of the GNU General Public License along with melonDS. If not, see http://www.gnu.org/licenses/. */ + +#ifndef DSI_H +#define DSI_H + +#include "types.h" + +namespace DSi +{ + +bool LoadNAND(); + +} + +#endif // DSI_H diff --git a/src/DSiCrypto.h b/src/DSiCrypto.h index 6a524dd..dc9bfe6 100644 --- a/src/DSiCrypto.h +++ b/src/DSiCrypto.h @@ -15,3 +15,10 @@ You should have received a copy of the GNU General Public License along with melonDS. If not, see http://www.gnu.org/licenses/. */ + +#ifndef DSICRYPTO_H +#define DSICRYPTO_H + +// + +#endif // DSICRYPTO_H diff --git a/src/NDS.cpp b/src/NDS.cpp index ea34103..f00665e 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -31,6 +31,8 @@ #include "Wifi.h" #include "Platform.h" +#include "DSi.h" + namespace NDS { @@ -83,8 +85,8 @@ u32 SchedListMask; u32 CPUStop; -u8 ARM9BIOS[0x1000]; -u8 ARM7BIOS[0x4000]; +u8 ARM9BIOS[0x10000]; +u8 ARM7BIOS[0x10000]; u8 MainRAM[MAIN_RAM_SIZE]; @@ -387,6 +389,9 @@ void Reset() LastSysClockCycles = 0; + memset(ARM9BIOS, 0, 0x10000); + memset(ARM7BIOS, 0, 0x10000); + f = Platform::OpenLocalFile("bios9.bin", "rb"); if (!f) { @@ -421,6 +426,8 @@ void Reset() fclose(f); } + DSi::LoadNAND(); + // TODO for later: configure this when emulating a DSi ARM9ClockShift = 1; @@ -1566,9 +1573,9 @@ void debug(u32 param) u8 ARM9Read8(u32 addr) { - if ((addr & 0xFFFFF000) == 0xFFFF0000) + if ((addr & 0xFFFF0000) == 0xFFFF0000) { - return *(u8*)&ARM9BIOS[addr & 0xFFF]; + return *(u8*)&ARM9BIOS[addr & 0xFFFF]; } switch (addr & 0xFF000000) @@ -1627,9 +1634,9 @@ u8 ARM9Read8(u32 addr) u16 ARM9Read16(u32 addr) { - if ((addr & 0xFFFFF000) == 0xFFFF0000) + if ((addr & 0xFFFF0000) == 0xFFFF0000) { - return *(u16*)&ARM9BIOS[addr & 0xFFF]; + return *(u16*)&ARM9BIOS[addr & 0xFFFF]; } switch (addr & 0xFF000000) @@ -1688,9 +1695,9 @@ u16 ARM9Read16(u32 addr) u32 ARM9Read32(u32 addr) { - if ((addr & 0xFFFFF000) == 0xFFFF0000) + if ((addr & 0xFFFF0000) == 0xFFFF0000) { - return *(u32*)&ARM9BIOS[addr & 0xFFF]; + return *(u32*)&ARM9BIOS[addr & 0xFFFF]; } switch (addr & 0xFF000000) @@ -1896,9 +1903,10 @@ bool ARM9GetMemRegion(u32 addr, bool write, MemRegion* region) u8 ARM7Read8(u32 addr) { - if (addr < 0x00004000) + if (addr < 0x00010000) { - if (ARM7->R[15] >= 0x4000) + // TODO: check the boundary? is it 4000 or higher on regular DS? + if (ARM7->R[15] >= 0x00010000) return 0xFF; if (addr < ARM7BIOSProt && ARM7->R[15] >= ARM7BIOSProt) return 0xFF; @@ -1952,9 +1960,9 @@ u8 ARM7Read8(u32 addr) u16 ARM7Read16(u32 addr) { - if (addr < 0x00004000) + if (addr < 0x00010000) { - if (ARM7->R[15] >= 0x4000) + if (ARM7->R[15] >= 0x00010000) return 0xFFFF; if (addr < ARM7BIOSProt && ARM7->R[15] >= ARM7BIOSProt) return 0xFFFF; @@ -2015,9 +2023,9 @@ u16 ARM7Read16(u32 addr) u32 ARM7Read32(u32 addr) { - if (addr < 0x00004000) + if (addr < 0x00010000) { - if (ARM7->R[15] >= 0x4000) + if (ARM7->R[15] >= 0x00010000) return 0xFFFFFFFF; if (addr < ARM7BIOSProt && ARM7->R[15] >= ARM7BIOSProt) return 0xFFFFFFFF; diff --git a/src/NDS.h b/src/NDS.h index 9b7a10a..e8bb44d 100644 --- a/src/NDS.h +++ b/src/NDS.h @@ -117,8 +117,8 @@ extern u16 ExMemCnt[2]; extern u8 ROMSeed0[2*8]; extern u8 ROMSeed1[2*8]; -extern u8 ARM9BIOS[0x1000]; -extern u8 ARM7BIOS[0x4000]; +extern u8 ARM9BIOS[0x10000]; +extern u8 ARM7BIOS[0x10000]; //#define MAIN_RAM_SIZE 0x400000 #define MAIN_RAM_SIZE 0x1000000 diff --git a/src/sha1/sha1.c b/src/sha1/sha1.c new file mode 100644 index 0000000..2c50433 --- /dev/null +++ b/src/sha1/sha1.c @@ -0,0 +1,276 @@ + +/* from valgrind tests */ + +/* ================ sha1.c ================ */ +/* +SHA-1 in C +By Steve Reid +100% Public Domain + +Test Vectors (from FIPS PUB 180-1) +"abc" + A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D +"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" + 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 +A million repetitions of "a" + 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F +*/ + +/* #define LITTLE_ENDIAN * This should be #define'd already, if true. */ +/* #define SHA1HANDSOFF * Copies data before messing with it. */ + +#define SHA1HANDSOFF + +#include +#include +#include /* for u_int*_t */ +#if defined(__sun) +#include "solarisfixes.h" +#endif +#include "sha1.h" + +#ifndef BYTE_ORDER +#if (BSD >= 199103) +# include +#else +#if defined(linux) || defined(__linux__) +# include +#else +#define LITTLE_ENDIAN 1234 /* least-significant byte first (vax, pc) */ +#define BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */ +#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp)*/ + +#if defined(vax) || defined(ns32000) || defined(sun386) || defined(__i386__) || \ + defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \ + defined(__alpha__) || defined(__alpha) +#define BYTE_ORDER LITTLE_ENDIAN +#endif + +#if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \ + defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \ + defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\ + defined(apollo) || defined(__convex__) || defined(_CRAY) || \ + defined(__hppa) || defined(__hp9000) || \ + defined(__hp9000s300) || defined(__hp9000s700) || \ + defined (BIT_ZERO_ON_LEFT) || defined(m68k) || defined(__sparc) +#define BYTE_ORDER BIG_ENDIAN +#endif +#endif /* linux */ +#endif /* BSD */ +#endif /* BYTE_ORDER */ + +#if defined(__BYTE_ORDER) && !defined(BYTE_ORDER) +#if (__BYTE_ORDER == __LITTLE_ENDIAN) +#define BYTE_ORDER LITTLE_ENDIAN +#else +#define BYTE_ORDER BIG_ENDIAN +#endif +#endif + +#if !defined(BYTE_ORDER) || \ + (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN && \ + BYTE_ORDER != PDP_ENDIAN) + /* you must determine what the correct bit order is for + * your compiler - the next line is an intentional error + * which will force your compiles to bomb until you fix + * the above macros. + */ +#error "Undefined or invalid BYTE_ORDER" +#endif + +#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) + +/* blk0() and blk() perform the initial expand. */ +/* I got the idea of expanding during the round function from SSLeay */ +#if BYTE_ORDER == LITTLE_ENDIAN +#define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \ + |(rol(block->l[i],8)&0x00FF00FF)) +#elif BYTE_ORDER == BIG_ENDIAN +#define blk0(i) block->l[i] +#else +#error "Endianness not defined!" +#endif +#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \ + ^block->l[(i+2)&15]^block->l[i&15],1)) + +/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ +#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30); +#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30); +#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30); +#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); +#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30); + + +/* Hash a single 512-bit block. This is the core of the algorithm. */ + +void SHA1Transform(u_int32_t state[5], const unsigned char buffer[64]) +{ +u_int32_t a, b, c, d, e; +typedef union { + unsigned char c[64]; + u_int32_t l[16]; +} CHAR64LONG16; +#ifdef SHA1HANDSOFF +CHAR64LONG16 block[1]; /* use array to appear as a pointer */ + memcpy(block, buffer, 64); +#else + /* The following had better never be used because it causes the + * pointer-to-const buffer to be cast into a pointer to non-const. + * And the result is written through. I threw a "const" in, hoping + * this will cause a diagnostic. + */ +CHAR64LONG16* block = (const CHAR64LONG16*)buffer; +#endif + /* Copy context->state[] to working vars */ + a = state[0]; + b = state[1]; + c = state[2]; + d = state[3]; + e = state[4]; + /* 4 rounds of 20 operations each. Loop unrolled. */ + R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3); + R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7); + R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11); + R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15); + R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19); + R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23); + R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27); + R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31); + R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35); + R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39); + R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43); + R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47); + R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51); + R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55); + R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59); + R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63); + R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67); + R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71); + R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75); + R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79); + /* Add the working vars back into context.state[] */ + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; + state[4] += e; + /* Wipe variables */ + a = b = c = d = e = 0; +#ifdef SHA1HANDSOFF + memset(block, '\0', sizeof(block)); +#endif +} + + +/* SHA1Init - Initialize new context */ + +void SHA1Init(SHA1_CTX* context) +{ + /* SHA1 initialization constants */ + context->state[0] = 0x67452301; + context->state[1] = 0xEFCDAB89; + context->state[2] = 0x98BADCFE; + context->state[3] = 0x10325476; + context->state[4] = 0xC3D2E1F0; + context->count[0] = context->count[1] = 0; +} + + +/* Run your data through this. */ + +void SHA1Update(SHA1_CTX* context, const unsigned char* data, u_int32_t len) +{ +u_int32_t i; +u_int32_t j; + + j = context->count[0]; + if ((context->count[0] += len << 3) < j) + context->count[1]++; + context->count[1] += (len>>29); + j = (j >> 3) & 63; + if ((j + len) > 63) { + memcpy(&context->buffer[j], data, (i = 64-j)); + SHA1Transform(context->state, context->buffer); + for ( ; i + 63 < len; i += 64) { + SHA1Transform(context->state, &data[i]); + } + j = 0; + } + else i = 0; + memcpy(&context->buffer[j], &data[i], len - i); +} + + +/* Add padding and return the message digest. */ + +void SHA1Final(unsigned char digest[20], SHA1_CTX* context) +{ +unsigned i; +unsigned char finalcount[8]; +unsigned char c; + +#if 0 /* untested "improvement" by DHR */ + /* Convert context->count to a sequence of bytes + * in finalcount. Second element first, but + * big-endian order within element. + * But we do it all backwards. + */ + unsigned char *fcp = &finalcount[8]; + + for (i = 0; i < 2; i++) + { + u_int32_t t = context->count[i]; + int j; + + for (j = 0; j < 4; t >>= 8, j++) + *--fcp = (unsigned char) t + } +#else + for (i = 0; i < 8; i++) { + finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)] + >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */ + } +#endif + c = 0200; + SHA1Update(context, &c, 1); + while ((context->count[0] & 504) != 448) { + c = 0000; + SHA1Update(context, &c, 1); + } + SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */ + for (i = 0; i < 20; i++) { + digest[i] = (unsigned char) + ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255); + } + /* Wipe variables */ + memset(context, '\0', sizeof(*context)); + memset(&finalcount, '\0', sizeof(finalcount)); +} +/* ================ end of sha1.c ================ */ + +#if 0 +#define BUFSIZE 4096 + +int +main(int argc, char **argv) +{ + SHA1_CTX ctx; + unsigned char hash[20], buf[BUFSIZE]; + int i; + + for(i=0;i +100% Public Domain +*/ + +typedef struct { + u_int32_t state[5]; + u_int32_t count[2]; + unsigned char buffer[64]; +} SHA1_CTX; + +void SHA1Transform(u_int32_t state[5], const unsigned char buffer[64]); +void SHA1Init(SHA1_CTX* context); +void SHA1Update(SHA1_CTX* context, const unsigned char* data, u_int32_t len); +void SHA1Final(unsigned char digest[20], SHA1_CTX* context); diff --git a/src/tiny-AES-c/README.md b/src/tiny-AES-c/README.md new file mode 100644 index 0000000..e32e25e --- /dev/null +++ b/src/tiny-AES-c/README.md @@ -0,0 +1,80 @@ +### Tiny AES in C + +This is a small and portable implementation of the AES [ECB](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Electronic_Codebook_.28ECB.29), [CTR](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Counter_.28CTR.29) and [CBC](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher_Block_Chaining_.28CBC.29) encryption algorithms written in C. + +You can override the default key-size of 128 bit with 192 or 256 bit by defining the symbols AES192 or AES256 in `aes.h`. + +The API is very simple and looks like this (I am using C99 ``-style annotated types): + +```C +/* Initialize context calling one of: */ +void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key); +void AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, const uint8_t* iv); + +/* ... or reset IV at random point: */ +void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv); + +/* Then start encrypting and decrypting with the functions below: */ +void AES_ECB_encrypt(const struct AES_ctx* ctx, uint8_t* buf); +void AES_ECB_decrypt(const struct AES_ctx* ctx, uint8_t* buf); + +void AES_CBC_encrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length); +void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length); + +/* Same function for encrypting as for decrypting in CTR mode */ +void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length); +``` + +Note: + * No padding is provided so for CBC and ECB all buffers should be multiples of 16 bytes. For padding [PKCS7](https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7) is recommendable. + * ECB mode is considered unsafe for most uses and is not implemented in streaming mode. If you need this mode, call the function for every block of 16 bytes you need encrypted. See [wikipedia's article on ECB](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Electronic_Codebook_(ECB)) for more details. + +You can choose to use any or all of the modes-of-operations, by defining the symbols CBC, CTR or ECB. See the header file for clarification. + +C++ users should `#include` [aes.hpp](https://github.com/kokke/tiny-AES-c/blob/master/aes.hpp) instead of [aes.h](https://github.com/kokke/tiny-AES-c/blob/master/aes.h) + +There is no built-in error checking or protection from out-of-bounds memory access errors as a result of malicious input. + +The module uses less than 200 bytes of RAM and 1-2K ROM when compiled for ARM, but YMMV depending on which modes are enabled. + +It is one of the smallest implementations in C I've seen yet, but do contact me if you know of something smaller (or have improvements to the code here). + +I've successfully used the code on 64bit x86, 32bit ARM and 8 bit AVR platforms. + + +GCC size output when only CTR mode is compiled for ARM: + + $ arm-none-eabi-gcc -Os -DCBC=0 -DECB=0 -DCTR=1 -c aes.c + $ size aes.o + text data bss dec hex filename + 1343 0 0 1343 53f aes.o + +.. and when compiling for the THUMB instruction set, we end up just below 1K in code size. + + $ arm-none-eabi-gcc -Os -mthumb -DCBC=0 -DECB=0 -DCTR=1 -c aes.c + $ size aes.o + text data bss dec hex filename + 979 0 0 979 3d3 aes.o + + +I am using the Free Software Foundation, ARM GCC compiler: + + $ arm-none-eabi-gcc --version + arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 8-2018-q4-major) 8.2.1 20181213 (release) + Copyright (C) 2018 Free Software Foundation, Inc. + This is free software; see the source for copying conditions. There is NO + warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + + +This implementation is verified against the data in: + +[National Institute of Standards and Technology Special Publication 800-38A 2001 ED](http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf) Appendix F: Example Vectors for Modes of Operation of the AES. + +The other appendices in the document are valuable for implementation details on e.g. padding, generation of IVs and nonces in CTR-mode etc. + + +A heartfelt thank-you to all the nice people out there who have contributed to this project. + + +All material in this repository is in the public domain. diff --git a/src/tiny-AES-c/aes.c b/src/tiny-AES-c/aes.c new file mode 100644 index 0000000..313ff71 --- /dev/null +++ b/src/tiny-AES-c/aes.c @@ -0,0 +1,572 @@ +/* + +This is an implementation of the AES algorithm, specifically ECB, CTR and CBC mode. +Block size can be chosen in aes.h - available choices are AES128, AES192, AES256. + +The implementation is verified against the test vectors in: + National Institute of Standards and Technology Special Publication 800-38A 2001 ED + +ECB-AES128 +---------- + + plain-text: + 6bc1bee22e409f96e93d7e117393172a + ae2d8a571e03ac9c9eb76fac45af8e51 + 30c81c46a35ce411e5fbc1191a0a52ef + f69f2445df4f9b17ad2b417be66c3710 + + key: + 2b7e151628aed2a6abf7158809cf4f3c + + resulting cipher + 3ad77bb40d7a3660a89ecaf32466ef97 + f5d3d58503b9699de785895a96fdbaaf + 43b1cd7f598ece23881b00e3ed030688 + 7b0c785e27e8ad3f8223207104725dd4 + + +NOTE: String length must be evenly divisible by 16byte (str_len % 16 == 0) + You should pad the end of the string with zeros if this is not the case. + For AES192/256 the key size is proportionally larger. + +*/ + + +/*****************************************************************************/ +/* Includes: */ +/*****************************************************************************/ +#include +#include // CBC mode, for memset +#include "aes.h" + +/*****************************************************************************/ +/* Defines: */ +/*****************************************************************************/ +// The number of columns comprising a state in AES. This is a constant in AES. Value=4 +#define Nb 4 + +#if defined(AES256) && (AES256 == 1) + #define Nk 8 + #define Nr 14 +#elif defined(AES192) && (AES192 == 1) + #define Nk 6 + #define Nr 12 +#else + #define Nk 4 // The number of 32 bit words in a key. + #define Nr 10 // The number of rounds in AES Cipher. +#endif + +// jcallan@github points out that declaring Multiply as a function +// reduces code size considerably with the Keil ARM compiler. +// See this link for more information: https://github.com/kokke/tiny-AES-C/pull/3 +#ifndef MULTIPLY_AS_A_FUNCTION + #define MULTIPLY_AS_A_FUNCTION 0 +#endif + + + + +/*****************************************************************************/ +/* Private variables: */ +/*****************************************************************************/ +// state - array holding the intermediate results during decryption. +typedef uint8_t state_t[4][4]; + + + +// The lookup-tables are marked const so they can be placed in read-only storage instead of RAM +// The numbers below can be computed dynamically trading ROM for RAM - +// This can be useful in (embedded) bootloader applications, where ROM is often limited. +static const uint8_t sbox[256] = { + //0 1 2 3 4 5 6 7 8 9 A B C D E F + 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, + 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, + 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, + 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, + 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, + 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, + 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, + 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, + 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, + 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, + 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, + 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, + 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, + 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, + 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, + 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 }; + +static const uint8_t rsbox[256] = { + 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, + 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, + 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e, + 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25, + 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, + 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84, + 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06, + 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, + 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73, + 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e, + 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, + 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4, + 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f, + 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, + 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61, + 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d }; + +// The round constant word array, Rcon[i], contains the values given by +// x to the power (i-1) being powers of x (x is denoted as {02}) in the field GF(2^8) +static const uint8_t Rcon[11] = { + 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 }; + +/* + * Jordan Goulder points out in PR #12 (https://github.com/kokke/tiny-AES-C/pull/12), + * that you can remove most of the elements in the Rcon array, because they are unused. + * + * From Wikipedia's article on the Rijndael key schedule @ https://en.wikipedia.org/wiki/Rijndael_key_schedule#Rcon + * + * "Only the first some of these constants are actually used – up to rcon[10] for AES-128 (as 11 round keys are needed), + * up to rcon[8] for AES-192, up to rcon[7] for AES-256. rcon[0] is not used in AES algorithm." + */ + + +/*****************************************************************************/ +/* Private functions: */ +/*****************************************************************************/ +/* +static uint8_t getSBoxValue(uint8_t num) +{ + return sbox[num]; +} +*/ +#define getSBoxValue(num) (sbox[(num)]) +/* +static uint8_t getSBoxInvert(uint8_t num) +{ + return rsbox[num]; +} +*/ +#define getSBoxInvert(num) (rsbox[(num)]) + +// This function produces Nb(Nr+1) round keys. The round keys are used in each round to decrypt the states. +static void KeyExpansion(uint8_t* RoundKey, const uint8_t* Key) +{ + unsigned i, j, k; + uint8_t tempa[4]; // Used for the column/row operations + + // The first round key is the key itself. + for (i = 0; i < Nk; ++i) + { + RoundKey[(i * 4) + 0] = Key[(i * 4) + 0]; + RoundKey[(i * 4) + 1] = Key[(i * 4) + 1]; + RoundKey[(i * 4) + 2] = Key[(i * 4) + 2]; + RoundKey[(i * 4) + 3] = Key[(i * 4) + 3]; + } + + // All other round keys are found from the previous round keys. + for (i = Nk; i < Nb * (Nr + 1); ++i) + { + { + k = (i - 1) * 4; + tempa[0]=RoundKey[k + 0]; + tempa[1]=RoundKey[k + 1]; + tempa[2]=RoundKey[k + 2]; + tempa[3]=RoundKey[k + 3]; + + } + + if (i % Nk == 0) + { + // This function shifts the 4 bytes in a word to the left once. + // [a0,a1,a2,a3] becomes [a1,a2,a3,a0] + + // Function RotWord() + { + const uint8_t u8tmp = tempa[0]; + tempa[0] = tempa[1]; + tempa[1] = tempa[2]; + tempa[2] = tempa[3]; + tempa[3] = u8tmp; + } + + // SubWord() is a function that takes a four-byte input word and + // applies the S-box to each of the four bytes to produce an output word. + + // Function Subword() + { + tempa[0] = getSBoxValue(tempa[0]); + tempa[1] = getSBoxValue(tempa[1]); + tempa[2] = getSBoxValue(tempa[2]); + tempa[3] = getSBoxValue(tempa[3]); + } + + tempa[0] = tempa[0] ^ Rcon[i/Nk]; + } +#if defined(AES256) && (AES256 == 1) + if (i % Nk == 4) + { + // Function Subword() + { + tempa[0] = getSBoxValue(tempa[0]); + tempa[1] = getSBoxValue(tempa[1]); + tempa[2] = getSBoxValue(tempa[2]); + tempa[3] = getSBoxValue(tempa[3]); + } + } +#endif + j = i * 4; k=(i - Nk) * 4; + RoundKey[j + 0] = RoundKey[k + 0] ^ tempa[0]; + RoundKey[j + 1] = RoundKey[k + 1] ^ tempa[1]; + RoundKey[j + 2] = RoundKey[k + 2] ^ tempa[2]; + RoundKey[j + 3] = RoundKey[k + 3] ^ tempa[3]; + } +} + +void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key) +{ + KeyExpansion(ctx->RoundKey, key); +} +#if (defined(CBC) && (CBC == 1)) || (defined(CTR) && (CTR == 1)) +void AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, const uint8_t* iv) +{ + KeyExpansion(ctx->RoundKey, key); + memcpy (ctx->Iv, iv, AES_BLOCKLEN); +} +void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv) +{ + memcpy (ctx->Iv, iv, AES_BLOCKLEN); +} +#endif + +// This function adds the round key to state. +// The round key is added to the state by an XOR function. +static void AddRoundKey(uint8_t round, state_t* state, const uint8_t* RoundKey) +{ + uint8_t i,j; + for (i = 0; i < 4; ++i) + { + for (j = 0; j < 4; ++j) + { + (*state)[i][j] ^= RoundKey[(round * Nb * 4) + (i * Nb) + j]; + } + } +} + +// The SubBytes Function Substitutes the values in the +// state matrix with values in an S-box. +static void SubBytes(state_t* state) +{ + uint8_t i, j; + for (i = 0; i < 4; ++i) + { + for (j = 0; j < 4; ++j) + { + (*state)[j][i] = getSBoxValue((*state)[j][i]); + } + } +} + +// The ShiftRows() function shifts the rows in the state to the left. +// Each row is shifted with different offset. +// Offset = Row number. So the first row is not shifted. +static void ShiftRows(state_t* state) +{ + uint8_t temp; + + // Rotate first row 1 columns to left + temp = (*state)[0][1]; + (*state)[0][1] = (*state)[1][1]; + (*state)[1][1] = (*state)[2][1]; + (*state)[2][1] = (*state)[3][1]; + (*state)[3][1] = temp; + + // Rotate second row 2 columns to left + temp = (*state)[0][2]; + (*state)[0][2] = (*state)[2][2]; + (*state)[2][2] = temp; + + temp = (*state)[1][2]; + (*state)[1][2] = (*state)[3][2]; + (*state)[3][2] = temp; + + // Rotate third row 3 columns to left + temp = (*state)[0][3]; + (*state)[0][3] = (*state)[3][3]; + (*state)[3][3] = (*state)[2][3]; + (*state)[2][3] = (*state)[1][3]; + (*state)[1][3] = temp; +} + +static uint8_t xtime(uint8_t x) +{ + return ((x<<1) ^ (((x>>7) & 1) * 0x1b)); +} + +// MixColumns function mixes the columns of the state matrix +static void MixColumns(state_t* state) +{ + uint8_t i; + uint8_t Tmp, Tm, t; + for (i = 0; i < 4; ++i) + { + t = (*state)[i][0]; + Tmp = (*state)[i][0] ^ (*state)[i][1] ^ (*state)[i][2] ^ (*state)[i][3] ; + Tm = (*state)[i][0] ^ (*state)[i][1] ; Tm = xtime(Tm); (*state)[i][0] ^= Tm ^ Tmp ; + Tm = (*state)[i][1] ^ (*state)[i][2] ; Tm = xtime(Tm); (*state)[i][1] ^= Tm ^ Tmp ; + Tm = (*state)[i][2] ^ (*state)[i][3] ; Tm = xtime(Tm); (*state)[i][2] ^= Tm ^ Tmp ; + Tm = (*state)[i][3] ^ t ; Tm = xtime(Tm); (*state)[i][3] ^= Tm ^ Tmp ; + } +} + +// Multiply is used to multiply numbers in the field GF(2^8) +// Note: The last call to xtime() is unneeded, but often ends up generating a smaller binary +// The compiler seems to be able to vectorize the operation better this way. +// See https://github.com/kokke/tiny-AES-c/pull/34 +#if MULTIPLY_AS_A_FUNCTION +static uint8_t Multiply(uint8_t x, uint8_t y) +{ + return (((y & 1) * x) ^ + ((y>>1 & 1) * xtime(x)) ^ + ((y>>2 & 1) * xtime(xtime(x))) ^ + ((y>>3 & 1) * xtime(xtime(xtime(x)))) ^ + ((y>>4 & 1) * xtime(xtime(xtime(xtime(x)))))); /* this last call to xtime() can be omitted */ + } +#else +#define Multiply(x, y) \ + ( ((y & 1) * x) ^ \ + ((y>>1 & 1) * xtime(x)) ^ \ + ((y>>2 & 1) * xtime(xtime(x))) ^ \ + ((y>>3 & 1) * xtime(xtime(xtime(x)))) ^ \ + ((y>>4 & 1) * xtime(xtime(xtime(xtime(x)))))) \ + +#endif + +#if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1) +// MixColumns function mixes the columns of the state matrix. +// The method used to multiply may be difficult to understand for the inexperienced. +// Please use the references to gain more information. +static void InvMixColumns(state_t* state) +{ + int i; + uint8_t a, b, c, d; + for (i = 0; i < 4; ++i) + { + a = (*state)[i][0]; + b = (*state)[i][1]; + c = (*state)[i][2]; + d = (*state)[i][3]; + + (*state)[i][0] = Multiply(a, 0x0e) ^ Multiply(b, 0x0b) ^ Multiply(c, 0x0d) ^ Multiply(d, 0x09); + (*state)[i][1] = Multiply(a, 0x09) ^ Multiply(b, 0x0e) ^ Multiply(c, 0x0b) ^ Multiply(d, 0x0d); + (*state)[i][2] = Multiply(a, 0x0d) ^ Multiply(b, 0x09) ^ Multiply(c, 0x0e) ^ Multiply(d, 0x0b); + (*state)[i][3] = Multiply(a, 0x0b) ^ Multiply(b, 0x0d) ^ Multiply(c, 0x09) ^ Multiply(d, 0x0e); + } +} + + +// The SubBytes Function Substitutes the values in the +// state matrix with values in an S-box. +static void InvSubBytes(state_t* state) +{ + uint8_t i, j; + for (i = 0; i < 4; ++i) + { + for (j = 0; j < 4; ++j) + { + (*state)[j][i] = getSBoxInvert((*state)[j][i]); + } + } +} + +static void InvShiftRows(state_t* state) +{ + uint8_t temp; + + // Rotate first row 1 columns to right + temp = (*state)[3][1]; + (*state)[3][1] = (*state)[2][1]; + (*state)[2][1] = (*state)[1][1]; + (*state)[1][1] = (*state)[0][1]; + (*state)[0][1] = temp; + + // Rotate second row 2 columns to right + temp = (*state)[0][2]; + (*state)[0][2] = (*state)[2][2]; + (*state)[2][2] = temp; + + temp = (*state)[1][2]; + (*state)[1][2] = (*state)[3][2]; + (*state)[3][2] = temp; + + // Rotate third row 3 columns to right + temp = (*state)[0][3]; + (*state)[0][3] = (*state)[1][3]; + (*state)[1][3] = (*state)[2][3]; + (*state)[2][3] = (*state)[3][3]; + (*state)[3][3] = temp; +} +#endif // #if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1) + +// Cipher is the main function that encrypts the PlainText. +static void Cipher(state_t* state, const uint8_t* RoundKey) +{ + uint8_t round = 0; + + // Add the First round key to the state before starting the rounds. + AddRoundKey(0, state, RoundKey); + + // There will be Nr rounds. + // The first Nr-1 rounds are identical. + // These Nr-1 rounds are executed in the loop below. + for (round = 1; round < Nr; ++round) + { + SubBytes(state); + ShiftRows(state); + MixColumns(state); + AddRoundKey(round, state, RoundKey); + } + + // The last round is given below. + // The MixColumns function is not here in the last round. + SubBytes(state); + ShiftRows(state); + AddRoundKey(Nr, state, RoundKey); +} + +#if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1) +static void InvCipher(state_t* state, const uint8_t* RoundKey) +{ + uint8_t round = 0; + + // Add the First round key to the state before starting the rounds. + AddRoundKey(Nr, state, RoundKey); + + // There will be Nr rounds. + // The first Nr-1 rounds are identical. + // These Nr-1 rounds are executed in the loop below. + for (round = (Nr - 1); round > 0; --round) + { + InvShiftRows(state); + InvSubBytes(state); + AddRoundKey(round, state, RoundKey); + InvMixColumns(state); + } + + // The last round is given below. + // The MixColumns function is not here in the last round. + InvShiftRows(state); + InvSubBytes(state); + AddRoundKey(0, state, RoundKey); +} +#endif // #if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1) + +/*****************************************************************************/ +/* Public functions: */ +/*****************************************************************************/ +#if defined(ECB) && (ECB == 1) + + +void AES_ECB_encrypt(const struct AES_ctx* ctx, uint8_t* buf) +{ + // The next function call encrypts the PlainText with the Key using AES algorithm. + Cipher((state_t*)buf, ctx->RoundKey); +} + +void AES_ECB_decrypt(const struct AES_ctx* ctx, uint8_t* buf) +{ + // The next function call decrypts the PlainText with the Key using AES algorithm. + InvCipher((state_t*)buf, ctx->RoundKey); +} + + +#endif // #if defined(ECB) && (ECB == 1) + + + + + +#if defined(CBC) && (CBC == 1) + + +static void XorWithIv(uint8_t* buf, const uint8_t* Iv) +{ + uint8_t i; + for (i = 0; i < AES_BLOCKLEN; ++i) // The block in AES is always 128bit no matter the key size + { + buf[i] ^= Iv[i]; + } +} + +void AES_CBC_encrypt_buffer(struct AES_ctx *ctx, uint8_t* buf, uint32_t length) +{ + uintptr_t i; + uint8_t *Iv = ctx->Iv; + for (i = 0; i < length; i += AES_BLOCKLEN) + { + XorWithIv(buf, Iv); + Cipher((state_t*)buf, ctx->RoundKey); + Iv = buf; + buf += AES_BLOCKLEN; + //printf("Step %d - %d", i/16, i); + } + /* store Iv in ctx for next call */ + memcpy(ctx->Iv, Iv, AES_BLOCKLEN); +} + +void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length) +{ + uintptr_t i; + uint8_t storeNextIv[AES_BLOCKLEN]; + for (i = 0; i < length; i += AES_BLOCKLEN) + { + memcpy(storeNextIv, buf, AES_BLOCKLEN); + InvCipher((state_t*)buf, ctx->RoundKey); + XorWithIv(buf, ctx->Iv); + memcpy(ctx->Iv, storeNextIv, AES_BLOCKLEN); + buf += AES_BLOCKLEN; + } + +} + +#endif // #if defined(CBC) && (CBC == 1) + + + +#if defined(CTR) && (CTR == 1) + +/* Symmetrical operation: same function for encrypting as for decrypting. Note any IV/nonce should never be reused with the same key */ +void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length) +{ + uint8_t buffer[AES_BLOCKLEN]; + + unsigned i; + int bi; + for (i = 0, bi = AES_BLOCKLEN; i < length; ++i, ++bi) + { + if (bi == AES_BLOCKLEN) /* we need to regen xor compliment in buffer */ + { + + memcpy(buffer, ctx->Iv, AES_BLOCKLEN); + Cipher((state_t*)buffer,ctx->RoundKey); + + /* Increment Iv and handle overflow */ + for (bi = (AES_BLOCKLEN - 1); bi >= 0; --bi) + { + /* inc will overflow */ + if (ctx->Iv[bi] == 255) + { + ctx->Iv[bi] = 0; + continue; + } + ctx->Iv[bi] += 1; + break; + } + bi = 0; + } + + buf[i] = (buf[i] ^ buffer[bi]); + } +} + +#endif // #if defined(CTR) && (CTR == 1) + diff --git a/src/tiny-AES-c/aes.h b/src/tiny-AES-c/aes.h new file mode 100644 index 0000000..87f1471 --- /dev/null +++ b/src/tiny-AES-c/aes.h @@ -0,0 +1,90 @@ +#ifndef _AES_H_ +#define _AES_H_ + +#include + +// #define the macros below to 1/0 to enable/disable the mode of operation. +// +// CBC enables AES encryption in CBC-mode of operation. +// CTR enables encryption in counter-mode. +// ECB enables the basic ECB 16-byte block algorithm. All can be enabled simultaneously. + +// The #ifndef-guard allows it to be configured before #include'ing or at compile time. +#ifndef CBC + #define CBC 1 +#endif + +#ifndef ECB + #define ECB 1 +#endif + +#ifndef CTR + #define CTR 1 +#endif + + +#define AES128 1 +//#define AES192 1 +//#define AES256 1 + +#define AES_BLOCKLEN 16 //Block length in bytes AES is 128b block only + +#if defined(AES256) && (AES256 == 1) + #define AES_KEYLEN 32 + #define AES_keyExpSize 240 +#elif defined(AES192) && (AES192 == 1) + #define AES_KEYLEN 24 + #define AES_keyExpSize 208 +#else + #define AES_KEYLEN 16 // Key length in bytes + #define AES_keyExpSize 176 +#endif + +struct AES_ctx +{ + uint8_t RoundKey[AES_keyExpSize]; +#if (defined(CBC) && (CBC == 1)) || (defined(CTR) && (CTR == 1)) + uint8_t Iv[AES_BLOCKLEN]; +#endif +}; + +void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key); +#if (defined(CBC) && (CBC == 1)) || (defined(CTR) && (CTR == 1)) +void AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, const uint8_t* iv); +void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv); +#endif + +#if defined(ECB) && (ECB == 1) +// buffer size is exactly AES_BLOCKLEN bytes; +// you need only AES_init_ctx as IV is not used in ECB +// NB: ECB is considered insecure for most uses +void AES_ECB_encrypt(const struct AES_ctx* ctx, uint8_t* buf); +void AES_ECB_decrypt(const struct AES_ctx* ctx, uint8_t* buf); + +#endif // #if defined(ECB) && (ECB == !) + + +#if defined(CBC) && (CBC == 1) +// buffer size MUST be mutile of AES_BLOCKLEN; +// Suggest https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7 for padding scheme +// NOTES: you need to set IV in ctx via AES_init_ctx_iv() or AES_ctx_set_iv() +// no IV should ever be reused with the same key +void AES_CBC_encrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length); +void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length); + +#endif // #if defined(CBC) && (CBC == 1) + + +#if defined(CTR) && (CTR == 1) + +// Same function for encrypting as for decrypting. +// IV is incremented for every block, and used after encryption as XOR-compliment for output +// Suggesting https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7 for padding scheme +// NOTES: you need to set IV in ctx with AES_init_ctx_iv() or AES_ctx_set_iv() +// no IV should ever be reused with the same key +void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, uint32_t length); + +#endif // #if defined(CTR) && (CTR == 1) + + +#endif //_AES_H_ diff --git a/src/tiny-AES-c/aes.hpp b/src/tiny-AES-c/aes.hpp new file mode 100644 index 0000000..ade1642 --- /dev/null +++ b/src/tiny-AES-c/aes.hpp @@ -0,0 +1,12 @@ +#ifndef _AES_HPP_ +#define _AES_HPP_ + +#ifndef __cplusplus +#error Do not include the hpp header in a c project! +#endif //__cplusplus + +extern "C" { +#include "aes.h" +} + +#endif //_AES_HPP_ diff --git a/src/tiny-AES-c/unlicense.txt b/src/tiny-AES-c/unlicense.txt new file mode 100644 index 0000000..68a49da --- /dev/null +++ b/src/tiny-AES-c/unlicense.txt @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to -- cgit v1.2.3 From 83d23939db58a3d59d97e26c7dc3cfd9ea7927d9 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 15 Jun 2019 13:09:11 +0200 Subject: melonDSi: skeleton in place --- src/ARM.h | 31 +++-- src/CP15.cpp | 31 +++-- src/DSi.cpp | 393 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/DSi.h | 33 +++++ src/NDS.cpp | 65 +++++----- src/sha1/sha1.c | 17 +-- src/sha1/sha1.h | 10 +- 7 files changed, 518 insertions(+), 62 deletions(-) (limited to 'src') diff --git a/src/ARM.h b/src/ARM.h index d13d535..6b6e330 100644 --- a/src/ARM.h +++ b/src/ARM.h @@ -23,6 +23,7 @@ #include "types.h" #include "NDS.h" +#include "DSi.h" #define ROR(x, n) (((x) >> (n)) | ((x) << (32-(n)))) @@ -271,17 +272,20 @@ public: u16 CodeRead16(u32 addr) { - return NDS::ARM7Read16(addr); + //return NDS::ARM7Read16(addr); + return DSi::ARM7Read16(addr); } u32 CodeRead32(u32 addr) { - return NDS::ARM7Read32(addr); + //return NDS::ARM7Read32(addr); + return DSi::ARM7Read32(addr); } void DataRead8(u32 addr, u32* val) { - *val = NDS::ARM7Read8(addr); + *val = DSi::ARM7Read8(addr); + //*val = NDS::ARM7Read8(addr); DataRegion = addr >> 24; DataCycles = NDS::ARM7MemTimings[DataRegion][0]; } @@ -290,7 +294,8 @@ public: { addr &= ~1; - *val = NDS::ARM7Read16(addr); + *val = DSi::ARM7Read16(addr); + //*val = NDS::ARM7Read16(addr); DataRegion = addr >> 24; DataCycles = NDS::ARM7MemTimings[DataRegion][0]; } @@ -299,7 +304,8 @@ public: { addr &= ~3; - *val = NDS::ARM7Read32(addr); + *val = DSi::ARM7Read32(addr); + //*val = NDS::ARM7Read32(addr); DataRegion = addr >> 24; DataCycles = NDS::ARM7MemTimings[DataRegion][2]; } @@ -308,13 +314,15 @@ public: { addr &= ~3; - *val = NDS::ARM7Read32(addr); + *val = DSi::ARM7Read32(addr); + //*val = NDS::ARM7Read32(addr); DataCycles += NDS::ARM7MemTimings[DataRegion][3]; } void DataWrite8(u32 addr, u8 val) { - NDS::ARM7Write8(addr, val); + DSi::ARM7Write8(addr, val); + //NDS::ARM7Write8(addr, val); DataRegion = addr >> 24; DataCycles = NDS::ARM7MemTimings[DataRegion][0]; } @@ -323,7 +331,8 @@ public: { addr &= ~1; - NDS::ARM7Write16(addr, val); + DSi::ARM7Write16(addr, val); + //NDS::ARM7Write16(addr, val); DataRegion = addr >> 24; DataCycles = NDS::ARM7MemTimings[DataRegion][0]; } @@ -332,7 +341,8 @@ public: { addr &= ~3; - NDS::ARM7Write32(addr, val); + DSi::ARM7Write32(addr, val); + //NDS::ARM7Write32(addr, val); DataRegion = addr >> 24; DataCycles = NDS::ARM7MemTimings[DataRegion][2]; } @@ -341,7 +351,8 @@ public: { addr &= ~3; - NDS::ARM7Write32(addr, val); + DSi::ARM7Write32(addr, val); + //NDS::ARM7Write32(addr, val); DataCycles += NDS::ARM7MemTimings[DataRegion][3]; } diff --git a/src/CP15.cpp b/src/CP15.cpp index a4db5f3..4654a2a 100644 --- a/src/CP15.cpp +++ b/src/CP15.cpp @@ -19,6 +19,7 @@ #include #include #include "NDS.h" +#include "DSi.h" #include "ARM.h" @@ -680,7 +681,8 @@ u32 ARMv5::CodeRead32(u32 addr, bool branch) if (CodeMem.Mem) return *(u32*)&CodeMem.Mem[addr & CodeMem.Mask]; - return NDS::ARM9Read32(addr); + //return NDS::ARM9Read32(addr); + return DSi::ARM9Read32(addr); } @@ -699,7 +701,8 @@ void ARMv5::DataRead8(u32 addr, u32* val) return; } - *val = NDS::ARM9Read8(addr); + *val = DSi::ARM9Read8(addr); + //*val = NDS::ARM9Read8(addr); DataCycles = MemTimings[addr >> 12][1]; } @@ -720,7 +723,8 @@ void ARMv5::DataRead16(u32 addr, u32* val) return; } - *val = NDS::ARM9Read16(addr); + *val = DSi::ARM9Read16(addr); + //*val = NDS::ARM9Read16(addr); DataCycles = MemTimings[addr >> 12][1]; } @@ -741,7 +745,8 @@ void ARMv5::DataRead32(u32 addr, u32* val) return; } - *val = NDS::ARM9Read32(addr); + *val = DSi::ARM9Read32(addr); + //*val = NDS::ARM9Read32(addr); DataCycles = MemTimings[addr >> 12][2]; } @@ -762,7 +767,8 @@ void ARMv5::DataRead32S(u32 addr, u32* val) return; } - *val = NDS::ARM9Read32(addr); + *val = DSi::ARM9Read32(addr); + //*val = NDS::ARM9Read32(addr); DataCycles += MemTimings[addr >> 12][3]; } @@ -781,7 +787,8 @@ void ARMv5::DataWrite8(u32 addr, u8 val) return; } - NDS::ARM9Write8(addr, val); + DSi::ARM9Write8(addr, val); + //NDS::ARM9Write8(addr, val); DataCycles = MemTimings[addr >> 12][1]; } @@ -802,7 +809,8 @@ void ARMv5::DataWrite16(u32 addr, u16 val) return; } - NDS::ARM9Write16(addr, val); + DSi::ARM9Write16(addr, val); + //NDS::ARM9Write16(addr, val); DataCycles = MemTimings[addr >> 12][1]; } @@ -823,7 +831,8 @@ void ARMv5::DataWrite32(u32 addr, u32 val) return; } - NDS::ARM9Write32(addr, val); + DSi::ARM9Write32(addr, val); + //NDS::ARM9Write32(addr, val); DataCycles = MemTimings[addr >> 12][2]; } @@ -844,7 +853,8 @@ void ARMv5::DataWrite32S(u32 addr, u32 val) return; } - NDS::ARM9Write32(addr, val); + DSi::ARM9Write32(addr, val); + //NDS::ARM9Write32(addr, val); DataCycles += MemTimings[addr >> 12][3]; } @@ -857,6 +867,7 @@ void ARMv5::GetCodeMemRegion(u32 addr, NDS::MemRegion* region) return; }*/ - NDS::ARM9GetMemRegion(addr, false, &CodeMem); + DSi::ARM9GetMemRegion(addr, false, &CodeMem); + //NDS::ARM9GetMemRegion(addr, false, &CodeMem); } diff --git a/src/DSi.cpp b/src/DSi.cpp index 376e6a0..8026e49 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -16,18 +16,409 @@ with melonDS. If not, see http://www.gnu.org/licenses/. */ +#include "NDS.h" #include "DSi.h" #include "tiny-AES-c/aes.hpp" #include "sha1/sha1.h" +#include "Platform.h" + namespace DSi { +// + + +bool LoadBIOS() +{ + FILE* f; + u32 i; + + f = Platform::OpenLocalFile("bios9i.bin", "rb"); + if (!f) + { + printf("ARM9i BIOS not found\n"); + + for (i = 0; i < 16; i++) + ((u32*)NDS::ARM9BIOS)[i] = 0xE7FFDEFF; + } + else + { + fseek(f, 0, SEEK_SET); + fread(NDS::ARM9BIOS, 0x10000, 1, f); + + printf("ARM9i BIOS loaded\n"); + fclose(f); + } + + f = Platform::OpenLocalFile("bios7i.bin", "rb"); + if (!f) + { + printf("ARM7i BIOS not found\n"); + + for (i = 0; i < 16; i++) + ((u32*)NDS::ARM7BIOS)[i] = 0xE7FFDEFF; + } + else + { + // TODO: check if the first 32 bytes are crapoed + + fseek(f, 0, SEEK_SET); + fread(NDS::ARM7BIOS, 0x10000, 1, f); + + printf("ARM7i BIOS loaded\n"); + fclose(f); + } + + // herp + *(u32*)&NDS::ARM9BIOS[0] = 0xEAFFFFFE; + *(u32*)&NDS::ARM7BIOS[0] = 0xEAFFFFFE; + + return true; +} + bool LoadNAND() { - // + printf("Loading DSi NAND\n"); + + FILE* f = Platform::OpenLocalFile("nand.bin", "rb"); + if (f) + { + u32 bootparams[8]; + fseek(f, 0x220, SEEK_SET); + fread(bootparams, 4, 8, f); + + printf("ARM9: offset=%08X size=%08X RAM=%08X size_aligned=%08X\n", + bootparams[0], bootparams[1], bootparams[2], bootparams[3]); + printf("ARM7: offset=%08X size=%08X RAM=%08X size_aligned=%08X\n", + bootparams[4], bootparams[5], bootparams[6], bootparams[7]); + +#define printhex(str, size) { for (int z = 0; z < (size); z++) printf("%02X", (str)[z]); printf("\n"); } +#define printhex_rev(str, size) { for (int z = (size)-1; z >= 0; z--) printf("%02X", (str)[z]); printf("\n"); } + + u8 emmc_cid[16]; + u8 consoleid[8]; + fseek(f, 0xF000010, SEEK_SET); + fread(emmc_cid, 1, 16, f); + fread(consoleid, 1, 8, f); + + printf("eMMC CID: "); printhex(emmc_cid, 16); + printf("Console ID: "); printhex_rev(consoleid, 8); + + fclose(f); + } return true; } + +u8 ARM9Read8(u32 addr) +{ + switch (addr & 0xFF000000) + { + case 0x04000000: + return ARM9IORead8(addr); + } + + return NDS::ARM9Read8(addr); +} + +u16 ARM9Read16(u32 addr) +{ + switch (addr & 0xFF000000) + { + case 0x04000000: + return ARM9IORead16(addr); + } + + return NDS::ARM9Read16(addr); +} + +u32 ARM9Read32(u32 addr) +{ + switch (addr & 0xFF000000) + { + case 0x04000000: + return ARM9IORead32(addr); + } + + return NDS::ARM9Read32(addr); +} + +void ARM9Write8(u32 addr, u8 val) +{ + switch (addr & 0xFF000000) + { + case 0x04000000: + ARM9IOWrite8(addr, val); + return; + } + + return NDS::ARM9Write8(addr, val); +} + +void ARM9Write16(u32 addr, u16 val) +{ + switch (addr & 0xFF000000) + { + case 0x04000000: + ARM9IOWrite16(addr, val); + return; + } + + return NDS::ARM9Write16(addr, val); +} + +void ARM9Write32(u32 addr, u32 val) +{ + switch (addr & 0xFF000000) + { + case 0x04000000: + ARM9IOWrite32(addr, val); + return; + } + + return NDS::ARM9Write32(addr, val); +} + +bool ARM9GetMemRegion(u32 addr, bool write, NDS::MemRegion* region) +{ + switch (addr & 0xFF000000) + { + case 0x02000000: + region->Mem = NDS::MainRAM; + region->Mask = MAIN_RAM_SIZE-1; + return true; + } + + if ((addr & 0xFFFF0000) == 0xFFFF0000 && !write) + { + region->Mem = NDS::ARM9BIOS; + region->Mask = 0xFFFF; + return true; + } + + region->Mem = NULL; + return false; +} + + + +u8 ARM7Read8(u32 addr) +{ + switch (addr & 0xFF800000) + { + case 0x04000000: + return ARM7IORead8(addr); + } + + return NDS::ARM7Read8(addr); +} + +u16 ARM7Read16(u32 addr) +{ + switch (addr & 0xFF800000) + { + case 0x04000000: + return ARM7IORead16(addr); + } + + return NDS::ARM7Read16(addr); +} + +u32 ARM7Read32(u32 addr) +{ + switch (addr & 0xFF800000) + { + case 0x04000000: + return ARM7IORead32(addr); + } + + return NDS::ARM7Read32(addr); +} + +void ARM7Write8(u32 addr, u8 val) +{ + switch (addr & 0xFF800000) + { + case 0x04000000: + ARM7IOWrite8(addr, val); + return; + } + + return NDS::ARM7Write8(addr, val); +} + +void ARM7Write16(u32 addr, u16 val) +{ + switch (addr & 0xFF800000) + { + case 0x04000000: + ARM7IOWrite16(addr, val); + return; + } + + return NDS::ARM7Write16(addr, val); +} + +void ARM7Write32(u32 addr, u32 val) +{ + switch (addr & 0xFF800000) + { + case 0x04000000: + ARM7IOWrite32(addr, val); + return; + } + + return NDS::ARM7Write32(addr, val); +} + +bool ARM7GetMemRegion(u32 addr, bool write, NDS::MemRegion* region) +{ + switch (addr & 0xFF800000) + { + case 0x02000000: + case 0x02800000: + region->Mem = NDS::MainRAM; + region->Mask = MAIN_RAM_SIZE-1; + return true; + } + + // BIOS. ARM7 PC has to be within range. + /*if (addr < 0x00010000 && !write) + { + if (NDS::ARM7->R[15] < 0x00010000 && (addr >= NDS::ARM7BIOSProt || NDS::ARM7->R[15] < NDS::ARM7BIOSProt)) + { + region->Mem = NDS::ARM7BIOS; + region->Mask = 0xFFFF; + return true; + } + }*/ + + region->Mem = NULL; + return false; +} + + + + +#define CASE_READ8_16BIT(addr, val) \ + case (addr): return (val) & 0xFF; \ + case (addr+1): return (val) >> 8; + +#define CASE_READ8_32BIT(addr, val) \ + case (addr): return (val) & 0xFF; \ + case (addr+1): return ((val) >> 8) & 0xFF; \ + case (addr+2): return ((val) >> 16) & 0xFF; \ + case (addr+3): return (val) >> 24; + +u8 ARM9IORead8(u32 addr) +{ + switch (addr) + { + } + + return NDS::ARM9IORead8(addr); +} + +u16 ARM9IORead16(u32 addr) +{ + switch (addr) + { + } + + return NDS::ARM9IORead16(addr); +} + +u32 ARM9IORead32(u32 addr) +{ + switch (addr) + { + } + + return NDS::ARM9IORead32(addr); +} + +void ARM9IOWrite8(u32 addr, u8 val) +{ + switch (addr) + { + } + + return NDS::ARM9IOWrite8(addr, val); +} + +void ARM9IOWrite16(u32 addr, u16 val) +{ + switch (addr) + { + } + + return NDS::ARM9IOWrite16(addr, val); +} + +void ARM9IOWrite32(u32 addr, u32 val) +{ + switch (addr) + { + } + + return NDS::ARM9IOWrite32(addr, val); +} + + +u8 ARM7IORead8(u32 addr) +{ + switch (addr) + { + } + + return NDS::ARM7IORead8(addr); +} + +u16 ARM7IORead16(u32 addr) +{ + switch (addr) + { + } + + return NDS::ARM7IORead16(addr); +} + +u32 ARM7IORead32(u32 addr) +{ + switch (addr) + { + } + + return NDS::ARM7IORead32(addr); +} + +void ARM7IOWrite8(u32 addr, u8 val) +{ + switch (addr) + { + } + + return NDS::ARM7IOWrite8(addr, val); +} + +void ARM7IOWrite16(u32 addr, u16 val) +{ + switch (addr) + { + } + + return NDS::ARM7IOWrite16(addr, val); +} + +void ARM7IOWrite32(u32 addr, u32 val) +{ + switch (addr) + { + } + + return NDS::ARM7IOWrite32(addr, val); +} + } diff --git a/src/DSi.h b/src/DSi.h index 2c71ad9..2a3ee21 100644 --- a/src/DSi.h +++ b/src/DSi.h @@ -24,8 +24,41 @@ namespace DSi { +bool LoadBIOS(); bool LoadNAND(); +u8 ARM9Read8(u32 addr); +u16 ARM9Read16(u32 addr); +u32 ARM9Read32(u32 addr); +void ARM9Write8(u32 addr, u8 val); +void ARM9Write16(u32 addr, u16 val); +void ARM9Write32(u32 addr, u32 val); + +bool ARM9GetMemRegion(u32 addr, bool write, NDS::MemRegion* region); + +u8 ARM7Read8(u32 addr); +u16 ARM7Read16(u32 addr); +u32 ARM7Read32(u32 addr); +void ARM7Write8(u32 addr, u8 val); +void ARM7Write16(u32 addr, u16 val); +void ARM7Write32(u32 addr, u32 val); + +bool ARM7GetMemRegion(u32 addr, bool write, NDS::MemRegion* region); + +u8 ARM9IORead8(u32 addr); +u16 ARM9IORead16(u32 addr); +u32 ARM9IORead32(u32 addr); +void ARM9IOWrite8(u32 addr, u8 val); +void ARM9IOWrite16(u32 addr, u16 val); +void ARM9IOWrite32(u32 addr, u32 val); + +u8 ARM7IORead8(u32 addr); +u16 ARM7IORead16(u32 addr); +u32 ARM7IORead32(u32 addr); +void ARM7IOWrite8(u32 addr, u8 val); +void ARM7IOWrite16(u32 addr, u16 val); +void ARM7IOWrite32(u32 addr, u32 val); + } #endif // DSI_H diff --git a/src/NDS.cpp b/src/NDS.cpp index f00665e..5481f6f 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -392,44 +392,51 @@ void Reset() memset(ARM9BIOS, 0, 0x10000); memset(ARM7BIOS, 0, 0x10000); - f = Platform::OpenLocalFile("bios9.bin", "rb"); - if (!f) + if (true) { - printf("ARM9 BIOS not found\n"); + DSi::LoadBIOS(); + DSi::LoadNAND(); - for (i = 0; i < 16; i++) - ((u32*)ARM9BIOS)[i] = 0xE7FFDEFF; + ARM9ClockShift = 2; } else { - fseek(f, 0, SEEK_SET); - fread(ARM9BIOS, 0x1000, 1, f); + f = Platform::OpenLocalFile("bios9.bin", "rb"); + if (!f) + { + printf("ARM9 BIOS not found\n"); - printf("ARM9 BIOS loaded\n"); - fclose(f); - } + for (i = 0; i < 16; i++) + ((u32*)ARM9BIOS)[i] = 0xE7FFDEFF; + } + else + { + fseek(f, 0, SEEK_SET); + fread(ARM9BIOS, 0x1000, 1, f); - f = Platform::OpenLocalFile("bios7.bin", "rb"); - if (!f) - { - printf("ARM7 BIOS not found\n"); + printf("ARM9 BIOS loaded\n"); + fclose(f); + } - for (i = 0; i < 16; i++) - ((u32*)ARM7BIOS)[i] = 0xE7FFDEFF; - } - else - { - fseek(f, 0, SEEK_SET); - fread(ARM7BIOS, 0x4000, 1, f); + f = Platform::OpenLocalFile("bios7.bin", "rb"); + if (!f) + { + printf("ARM7 BIOS not found\n"); - printf("ARM7 BIOS loaded\n"); - fclose(f); - } + for (i = 0; i < 16; i++) + ((u32*)ARM7BIOS)[i] = 0xE7FFDEFF; + } + else + { + fseek(f, 0, SEEK_SET); + fread(ARM7BIOS, 0x4000, 1, f); - DSi::LoadNAND(); + printf("ARM7 BIOS loaded\n"); + fclose(f); + } - // TODO for later: configure this when emulating a DSi - ARM9ClockShift = 1; + ARM9ClockShift = 1; + } ARM9Timestamp = 0; ARM9Target = 0; ARM7Timestamp = 0; ARM7Target = 0; @@ -443,8 +450,8 @@ void Reset() MapSharedWRAM(0); - ExMemCnt[0] = 0; - ExMemCnt[1] = 0; + ExMemCnt[0] = 0x4000; + ExMemCnt[1] = 0x4000; memset(ROMSeed0, 0, 2*8); memset(ROMSeed1, 0, 2*8); SetGBASlotTimings(); diff --git a/src/sha1/sha1.c b/src/sha1/sha1.c index 2c50433..3729550 100644 --- a/src/sha1/sha1.c +++ b/src/sha1/sha1.c @@ -42,7 +42,8 @@ A million repetitions of "a" #if defined(vax) || defined(ns32000) || defined(sun386) || defined(__i386__) || \ defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \ - defined(__alpha__) || defined(__alpha) + defined(__alpha__) || defined(__alpha) || \ + defined(__WIN32__) #define BYTE_ORDER LITTLE_ENDIAN #endif @@ -103,12 +104,12 @@ A million repetitions of "a" /* Hash a single 512-bit block. This is the core of the algorithm. */ -void SHA1Transform(u_int32_t state[5], const unsigned char buffer[64]) +void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]) { -u_int32_t a, b, c, d, e; +uint32_t a, b, c, d, e; typedef union { unsigned char c[64]; - u_int32_t l[16]; + uint32_t l[16]; } CHAR64LONG16; #ifdef SHA1HANDSOFF CHAR64LONG16 block[1]; /* use array to appear as a pointer */ @@ -178,10 +179,10 @@ void SHA1Init(SHA1_CTX* context) /* Run your data through this. */ -void SHA1Update(SHA1_CTX* context, const unsigned char* data, u_int32_t len) +void SHA1Update(SHA1_CTX* context, const unsigned char* data, uint32_t len) { -u_int32_t i; -u_int32_t j; +uint32_t i; +uint32_t j; j = context->count[0]; if ((context->count[0] += len << 3) < j) @@ -219,7 +220,7 @@ unsigned char c; for (i = 0; i < 2; i++) { - u_int32_t t = context->count[i]; + uint32_t t = context->count[i]; int j; for (j = 0; j < 4; t >>= 8, j++) diff --git a/src/sha1/sha1.h b/src/sha1/sha1.h index 9d6f129..56ffa56 100644 --- a/src/sha1/sha1.h +++ b/src/sha1/sha1.h @@ -5,13 +5,15 @@ By Steve Reid 100% Public Domain */ +#include + typedef struct { - u_int32_t state[5]; - u_int32_t count[2]; + uint32_t state[5]; + uint32_t count[2]; unsigned char buffer[64]; } SHA1_CTX; -void SHA1Transform(u_int32_t state[5], const unsigned char buffer[64]); +void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]); void SHA1Init(SHA1_CTX* context); -void SHA1Update(SHA1_CTX* context, const unsigned char* data, u_int32_t len); +void SHA1Update(SHA1_CTX* context, const unsigned char* data, uint32_t len); void SHA1Final(unsigned char digest[20], SHA1_CTX* context); -- cgit v1.2.3 From ebd1a359cc72c4dadf2741bf3f4bb96dfcc5b505 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 15 Jun 2019 13:46:20 +0200 Subject: setup new-WRAM mapping. hark hark hark --- src/DSi.cpp | 202 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/DSi.h | 5 ++ 2 files changed, 206 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index 8026e49..920981d 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -16,6 +16,8 @@ with melonDS. If not, see http://www.gnu.org/licenses/. */ +#include +#include #include "NDS.h" #include "DSi.h" #include "tiny-AES-c/aes.hpp" @@ -26,7 +28,19 @@ namespace DSi { -// +u32 MBK[2][9]; + +u8 NWRAM_A[0x40000]; +u8 NWRAM_B[0x40000]; +u8 NWRAM_C[0x40000]; + +u8* NWRAMMap_A[2][4]; +u8* NWRAMMap_B[3][4]; +u8* NWRAMMap_C[3][4]; + +u32 NWRAMStart[2][3]; +u32 NWRAMEnd[2][3]; +u32 NWRAMMask[2][3]; bool LoadBIOS() @@ -81,6 +95,18 @@ bool LoadNAND() { printf("Loading DSi NAND\n"); + memset(NWRAM_A, 0, 0x40000); + memset(NWRAM_B, 0, 0x40000); + memset(NWRAM_C, 0, 0x40000); + + memset(MBK, 0, sizeof(MBK)); + memset(NWRAMMap_A, 0, sizeof(NWRAMMap_A)); + memset(NWRAMMap_B, 0, sizeof(NWRAMMap_B)); + memset(NWRAMMap_C, 0, sizeof(NWRAMMap_C)); + memset(NWRAMStart, 0, sizeof(NWRAMStart)); + memset(NWRAMEnd, 0, sizeof(NWRAMEnd)); + memset(NWRAMMask, 0, sizeof(NWRAMMask)); + FILE* f = Platform::OpenLocalFile("nand.bin", "rb"); if (f) { @@ -93,6 +119,45 @@ bool LoadNAND() printf("ARM7: offset=%08X size=%08X RAM=%08X size_aligned=%08X\n", bootparams[4], bootparams[5], bootparams[6], bootparams[7]); + // read and apply new-WRAM settings + + u32 mbk[12]; + fseek(f, 0x380, SEEK_SET); + fread(mbk, 4, 12, f); + + MapNWRAM_A(0, mbk[0] & 0xFF); + MapNWRAM_A(1, (mbk[0] >> 8) & 0xFF); + MapNWRAM_A(2, (mbk[0] >> 16) & 0xFF); + MapNWRAM_A(3, mbk[0] >> 24); + + MapNWRAM_B(0, mbk[1] & 0xFF); + MapNWRAM_B(1, (mbk[1] >> 8) & 0xFF); + MapNWRAM_B(2, (mbk[1] >> 16) & 0xFF); + MapNWRAM_B(3, mbk[1] >> 24); + MapNWRAM_B(4, mbk[2] & 0xFF); + MapNWRAM_B(5, (mbk[2] >> 8) & 0xFF); + MapNWRAM_B(6, (mbk[2] >> 16) & 0xFF); + MapNWRAM_B(7, mbk[2] >> 24); + + MapNWRAM_C(0, mbk[3] & 0xFF); + MapNWRAM_C(1, (mbk[3] >> 8) & 0xFF); + MapNWRAM_C(2, (mbk[3] >> 16) & 0xFF); + MapNWRAM_C(3, mbk[3] >> 24); + MapNWRAM_C(4, mbk[4] & 0xFF); + MapNWRAM_C(5, (mbk[4] >> 8) & 0xFF); + MapNWRAM_C(6, (mbk[4] >> 16) & 0xFF); + MapNWRAM_C(7, mbk[4] >> 24); + + MapNWRAMRange(0, 0, mbk[5]); + MapNWRAMRange(0, 1, mbk[6]); + MapNWRAMRange(0, 2, mbk[7]); + + MapNWRAMRange(1, 0, mbk[8]); + MapNWRAMRange(1, 1, mbk[9]); + MapNWRAMRange(1, 2, mbk[10]); + + // TODO: MBK9 protect thing + #define printhex(str, size) { for (int z = 0; z < (size); z++) printf("%02X", (str)[z]); printf("\n"); } #define printhex_rev(str, size) { for (int z = (size)-1; z >= 0; z--) printf("%02X", (str)[z]); printf("\n"); } @@ -112,6 +177,141 @@ bool LoadNAND() } +// new WRAM mapping +// TODO: find out what happens upon overlapping slots!! + +void MapNWRAM_A(u32 num, u8 val) +{ + int mbkn = 0, mbks = 8*num; + + u8 oldval = (MBK[0][mbkn] >> mbks) & 0xFF; + if (oldval == val) return; + + MBK[0][mbkn] &= ~(0xFF << mbks); + MBK[0][mbkn] |= (val << mbks); + MBK[1][mbkn] = MBK[0][mbkn]; + + u8* ptr = &NWRAM_A[num << 16]; + + if (oldval & 0x80) + { + if (NWRAMMap_A[oldval & 0x01][(oldval >> 2) & 0x3] == ptr) + NWRAMMap_A[oldval & 0x01][(oldval >> 2) & 0x3] = NULL; + } + + if (val & 0x80) + { + NWRAMMap_A[val & 0x01][(val >> 2) & 0x3] = ptr; + } +} + +void MapNWRAM_B(u32 num, u8 val) +{ + int mbkn = 1+(num>>2), mbks = 8*(num&3); + + u8 oldval = (MBK[0][mbkn] >> mbks) & 0xFF; + if (oldval == val) return; + + MBK[0][mbkn] &= ~(0xFF << mbks); + MBK[0][mbkn] |= (val << mbks); + MBK[1][mbkn] = MBK[0][mbkn]; + + u8* ptr = &NWRAM_B[num << 15]; + + if (oldval & 0x80) + { + if (oldval & 0x02) oldval &= 0xFE; + + if (NWRAMMap_B[oldval & 0x03][(oldval >> 2) & 0x7] == ptr) + NWRAMMap_B[oldval & 0x03][(oldval >> 2) & 0x7] = NULL; + } + + if (val & 0x80) + { + if (val & 0x02) val &= 0xFE; + + NWRAMMap_B[val & 0x03][(val >> 2) & 0x7] = ptr; + } +} + +void MapNWRAM_C(u32 num, u8 val) +{ + int mbkn = 3+(num>>2), mbks = 8*(num&3); + + u8 oldval = (MBK[0][mbkn] >> mbks) & 0xFF; + if (oldval == val) return; + + MBK[0][mbkn] &= ~(0xFF << mbks); + MBK[0][mbkn] |= (val << mbks); + MBK[1][mbkn] = MBK[0][mbkn]; + + u8* ptr = &NWRAM_C[num << 15]; + + if (oldval & 0x80) + { + if (oldval & 0x02) oldval &= 0xFE; + + if (NWRAMMap_C[oldval & 0x03][(oldval >> 2) & 0x7] == ptr) + NWRAMMap_C[oldval & 0x03][(oldval >> 2) & 0x7] = NULL; + } + + if (val & 0x80) + { + if (val & 0x02) val &= 0xFE; + + NWRAMMap_C[val & 0x03][(val >> 2) & 0x7] = ptr; + } +} + +void MapNWRAMRange(u32 cpu, u32 num, u32 val) +{ + u32 oldval = MBK[cpu][5+num]; + if (oldval == val) return; + + MBK[cpu][5+num] = val; + + // TODO: what happens when the ranges are 'out of range'???? + if (num == 0) + { + u32 start = 0x03000000 + (((val >> 4) & 0xFF) << 16); + u32 end = 0x03000000 + (((val >> 20) & 0x1FF) << 16); + u32 size = (val >> 12) & 0x3; + + printf("NWRAM-A: ARM%d range %08X-%08X, size %d\n", cpu?7:9, start, end, size); + + NWRAMStart[cpu][num] = start; + NWRAMEnd[cpu][num] = end; + + switch (size) + { + case 0: + case 1: NWRAMMask[cpu][num] = 0x0; break; + case 2: NWRAMMask[cpu][num] = 0x1; break; // CHECKME + case 3: NWRAMMask[cpu][num] = 0x3; break; + } + } + else + { + u32 start = 0x03000000 + (((val >> 3) & 0x1FF) << 15); + u32 end = 0x03000000 + (((val >> 19) & 0x3FF) << 15); + u32 size = (val >> 12) & 0x3; + + printf("NWRAM-%c: ARM%d range %08X-%08X, size %d\n", 'A'+num, cpu?7:9, start, end, size); + + NWRAMStart[cpu][num] = start; + NWRAMEnd[cpu][num] = end; + + switch (size) + { + case 0: NWRAMMask[cpu][num] = 0x0; break; + case 1: NWRAMMask[cpu][num] = 0x1; break; + case 2: NWRAMMask[cpu][num] = 0x3; break; + case 3: NWRAMMask[cpu][num] = 0x7; break; + } + } +} + + u8 ARM9Read8(u32 addr) { switch (addr & 0xFF000000) diff --git a/src/DSi.h b/src/DSi.h index 2a3ee21..040c39b 100644 --- a/src/DSi.h +++ b/src/DSi.h @@ -27,6 +27,11 @@ namespace DSi bool LoadBIOS(); bool LoadNAND(); +void MapNWRAM_A(u32 num, u8 val); +void MapNWRAM_B(u32 num, u8 val); +void MapNWRAM_C(u32 num, u8 val); +void MapNWRAMRange(u32 cpu, u32 num, u32 val); + u8 ARM9Read8(u32 addr); u16 ARM9Read16(u32 addr); u32 ARM9Read32(u32 addr); -- cgit v1.2.3 From 7aa5131ec719f6dc4577a660ce94d793aa4a8617 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 15 Jun 2019 14:05:31 +0200 Subject: run teh binary. BAHAHAHAHAHAHAHAAHHHH it doesn't do much for now tho --- src/DSi.cpp | 284 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/DSi.h | 2 + src/NDS.cpp | 2 + 3 files changed, 288 insertions(+) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index 920981d..22741aa 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -20,14 +20,26 @@ #include #include "NDS.h" #include "DSi.h" +#include "ARM.h" #include "tiny-AES-c/aes.hpp" #include "sha1/sha1.h" #include "Platform.h" +namespace NDS +{ + +extern ARMv5* ARM9; +extern ARMv4* ARM7; + +} + + namespace DSi { +u32 BootAddr[2]; + u32 MBK[2][9]; u8 NWRAM_A[0x40000]; @@ -43,6 +55,12 @@ u32 NWRAMEnd[2][3]; u32 NWRAMMask[2][3]; +void Reset() +{ + NDS::ARM9->JumpTo(BootAddr[0]); + NDS::ARM7->JumpTo(BootAddr[1]); +} + bool LoadBIOS() { FILE* f; @@ -158,6 +176,56 @@ bool LoadNAND() // TODO: MBK9 protect thing + // load binaries + // TODO: optionally support loading from actual NAND? + // currently decrypted binaries have to be provided + // they can be decrypted with twltool + + FILE* bin; + + bin = Platform::OpenLocalFile("boot2_9.bin", "rb"); + if (bin) + { + u32 dstaddr = bootparams[2]; + for (u32 i = 0; i < bootparams[1]; i += 4) + { + u32 _tmp; + fread(&_tmp, 4, 1, bin); + ARM9Write32(dstaddr, _tmp); + dstaddr += 4; + } + + fclose(bin); + } + else + { + printf("ARM9 boot2 not found\n"); + } + + bin = Platform::OpenLocalFile("boot2_7.bin", "rb"); + if (bin) + { + u32 dstaddr = bootparams[6]; + for (u32 i = 0; i < bootparams[5]; i += 4) + { + u32 _tmp; + fread(&_tmp, 4, 1, bin); + ARM7Write32(dstaddr, _tmp); + dstaddr += 4; + } + + fclose(bin); + } + else + { + printf("ARM7 boot2 not found\n"); + } + + // repoint CPUs to the boot2 binaries + + BootAddr[0] = bootparams[2]; + BootAddr[1] = bootparams[6]; + #define printhex(str, size) { for (int z = 0; z < (size); z++) printf("%02X", (str)[z]); printf("\n"); } #define printhex_rev(str, size) { for (int z = (size)-1; z >= 0; z--) printf("%02X", (str)[z]); printf("\n"); } @@ -316,6 +384,24 @@ u8 ARM9Read8(u32 addr) { switch (addr & 0xFF000000) { + case 0x03000000: + if (addr >= NWRAMStart[0][0] && addr < NWRAMEnd[0][0]) + { + u8* ptr = NWRAMMap_A[0][(addr >> 16) & NWRAMMask[0][0]]; + return ptr ? *(u8*)&ptr[addr & 0xFFFF] : 0; + } + if (addr >= NWRAMStart[0][1] && addr < NWRAMEnd[0][1]) + { + u8* ptr = NWRAMMap_B[0][(addr >> 15) & NWRAMMask[0][1]]; + return ptr ? *(u8*)&ptr[addr & 0x7FFF] : 0; + } + if (addr >= NWRAMStart[0][2] && addr < NWRAMEnd[0][2]) + { + u8* ptr = NWRAMMap_C[0][(addr >> 15) & NWRAMMask[0][2]]; + return ptr ? *(u8*)&ptr[addr & 0x7FFF] : 0; + } + return NDS::ARM9Read8(addr); + case 0x04000000: return ARM9IORead8(addr); } @@ -327,6 +413,24 @@ u16 ARM9Read16(u32 addr) { switch (addr & 0xFF000000) { + case 0x03000000: + if (addr >= NWRAMStart[0][0] && addr < NWRAMEnd[0][0]) + { + u8* ptr = NWRAMMap_A[0][(addr >> 16) & NWRAMMask[0][0]]; + return ptr ? *(u16*)&ptr[addr & 0xFFFF] : 0; + } + if (addr >= NWRAMStart[0][1] && addr < NWRAMEnd[0][1]) + { + u8* ptr = NWRAMMap_B[0][(addr >> 15) & NWRAMMask[0][1]]; + return ptr ? *(u16*)&ptr[addr & 0x7FFF] : 0; + } + if (addr >= NWRAMStart[0][2] && addr < NWRAMEnd[0][2]) + { + u8* ptr = NWRAMMap_C[0][(addr >> 15) & NWRAMMask[0][2]]; + return ptr ? *(u16*)&ptr[addr & 0x7FFF] : 0; + } + return NDS::ARM9Read16(addr); + case 0x04000000: return ARM9IORead16(addr); } @@ -338,6 +442,24 @@ u32 ARM9Read32(u32 addr) { switch (addr & 0xFF000000) { + case 0x03000000: + if (addr >= NWRAMStart[0][0] && addr < NWRAMEnd[0][0]) + { + u8* ptr = NWRAMMap_A[0][(addr >> 16) & NWRAMMask[0][0]]; + return ptr ? *(u32*)&ptr[addr & 0xFFFF] : 0; + } + if (addr >= NWRAMStart[0][1] && addr < NWRAMEnd[0][1]) + { + u8* ptr = NWRAMMap_B[0][(addr >> 15) & NWRAMMask[0][1]]; + return ptr ? *(u32*)&ptr[addr & 0x7FFF] : 0; + } + if (addr >= NWRAMStart[0][2] && addr < NWRAMEnd[0][2]) + { + u8* ptr = NWRAMMap_C[0][(addr >> 15) & NWRAMMask[0][2]]; + return ptr ? *(u32*)&ptr[addr & 0x7FFF] : 0; + } + return NDS::ARM9Read32(addr); + case 0x04000000: return ARM9IORead32(addr); } @@ -349,6 +471,24 @@ void ARM9Write8(u32 addr, u8 val) { switch (addr & 0xFF000000) { + case 0x03000000: + if (addr >= NWRAMStart[0][0] && addr < NWRAMEnd[0][0]) + { + u8* ptr = NWRAMMap_A[0][(addr >> 16) & NWRAMMask[0][0]]; + if (ptr) *(u8*)&ptr[addr & 0xFFFF] = val; + } + if (addr >= NWRAMStart[0][1] && addr < NWRAMEnd[0][1]) + { + u8* ptr = NWRAMMap_B[0][(addr >> 15) & NWRAMMask[0][1]]; + if (ptr) *(u8*)&ptr[addr & 0x7FFF] = val; + } + if (addr >= NWRAMStart[0][2] && addr < NWRAMEnd[0][2]) + { + u8* ptr = NWRAMMap_C[0][(addr >> 15) & NWRAMMask[0][2]]; + if (ptr) *(u8*)&ptr[addr & 0x7FFF] = val; + } + return NDS::ARM9Write8(addr, val); + case 0x04000000: ARM9IOWrite8(addr, val); return; @@ -361,6 +501,24 @@ void ARM9Write16(u32 addr, u16 val) { switch (addr & 0xFF000000) { + case 0x03000000: + if (addr >= NWRAMStart[0][0] && addr < NWRAMEnd[0][0]) + { + u8* ptr = NWRAMMap_A[0][(addr >> 16) & NWRAMMask[0][0]]; + if (ptr) *(u16*)&ptr[addr & 0xFFFF] = val; + } + if (addr >= NWRAMStart[0][1] && addr < NWRAMEnd[0][1]) + { + u8* ptr = NWRAMMap_B[0][(addr >> 15) & NWRAMMask[0][1]]; + if (ptr) *(u16*)&ptr[addr & 0x7FFF] = val; + } + if (addr >= NWRAMStart[0][2] && addr < NWRAMEnd[0][2]) + { + u8* ptr = NWRAMMap_C[0][(addr >> 15) & NWRAMMask[0][2]]; + if (ptr) *(u16*)&ptr[addr & 0x7FFF] = val; + } + return NDS::ARM9Write16(addr, val); + case 0x04000000: ARM9IOWrite16(addr, val); return; @@ -373,6 +531,24 @@ void ARM9Write32(u32 addr, u32 val) { switch (addr & 0xFF000000) { + case 0x03000000: + if (addr >= NWRAMStart[0][0] && addr < NWRAMEnd[0][0]) + { + u8* ptr = NWRAMMap_A[0][(addr >> 16) & NWRAMMask[0][0]]; + if (ptr) *(u32*)&ptr[addr & 0xFFFF] = val; + } + if (addr >= NWRAMStart[0][1] && addr < NWRAMEnd[0][1]) + { + u8* ptr = NWRAMMap_B[0][(addr >> 15) & NWRAMMask[0][1]]; + if (ptr) *(u32*)&ptr[addr & 0x7FFF] = val; + } + if (addr >= NWRAMStart[0][2] && addr < NWRAMEnd[0][2]) + { + u8* ptr = NWRAMMap_C[0][(addr >> 15) & NWRAMMask[0][2]]; + if (ptr) *(u32*)&ptr[addr & 0x7FFF] = val; + } + return NDS::ARM9Write32(addr, val); + case 0x04000000: ARM9IOWrite32(addr, val); return; @@ -408,6 +584,24 @@ u8 ARM7Read8(u32 addr) { switch (addr & 0xFF800000) { + case 0x03000000: + if (addr >= NWRAMStart[1][0] && addr < NWRAMEnd[1][0]) + { + u8* ptr = NWRAMMap_A[1][(addr >> 16) & NWRAMMask[1][0]]; + return ptr ? *(u8*)&ptr[addr & 0xFFFF] : 0; + } + if (addr >= NWRAMStart[1][1] && addr < NWRAMEnd[1][1]) + { + u8* ptr = NWRAMMap_B[1][(addr >> 15) & NWRAMMask[1][1]]; + return ptr ? *(u8*)&ptr[addr & 0x7FFF] : 0; + } + if (addr >= NWRAMStart[1][2] && addr < NWRAMEnd[1][2]) + { + u8* ptr = NWRAMMap_C[1][(addr >> 15) & NWRAMMask[1][2]]; + return ptr ? *(u8*)&ptr[addr & 0x7FFF] : 0; + } + return NDS::ARM7Read8(addr); + case 0x04000000: return ARM7IORead8(addr); } @@ -419,6 +613,24 @@ u16 ARM7Read16(u32 addr) { switch (addr & 0xFF800000) { + case 0x03000000: + if (addr >= NWRAMStart[1][0] && addr < NWRAMEnd[1][0]) + { + u8* ptr = NWRAMMap_A[1][(addr >> 16) & NWRAMMask[1][0]]; + return ptr ? *(u16*)&ptr[addr & 0xFFFF] : 0; + } + if (addr >= NWRAMStart[1][1] && addr < NWRAMEnd[1][1]) + { + u8* ptr = NWRAMMap_B[1][(addr >> 15) & NWRAMMask[1][1]]; + return ptr ? *(u16*)&ptr[addr & 0x7FFF] : 0; + } + if (addr >= NWRAMStart[1][2] && addr < NWRAMEnd[1][2]) + { + u8* ptr = NWRAMMap_C[1][(addr >> 15) & NWRAMMask[1][2]]; + return ptr ? *(u16*)&ptr[addr & 0x7FFF] : 0; + } + return NDS::ARM7Read16(addr); + case 0x04000000: return ARM7IORead16(addr); } @@ -430,6 +642,24 @@ u32 ARM7Read32(u32 addr) { switch (addr & 0xFF800000) { + case 0x03000000: + if (addr >= NWRAMStart[1][0] && addr < NWRAMEnd[1][0]) + { + u8* ptr = NWRAMMap_A[1][(addr >> 16) & NWRAMMask[1][0]]; + return ptr ? *(u32*)&ptr[addr & 0xFFFF] : 0; + } + if (addr >= NWRAMStart[1][1] && addr < NWRAMEnd[1][1]) + { + u8* ptr = NWRAMMap_B[1][(addr >> 15) & NWRAMMask[1][1]]; + return ptr ? *(u32*)&ptr[addr & 0x7FFF] : 0; + } + if (addr >= NWRAMStart[1][2] && addr < NWRAMEnd[1][2]) + { + u8* ptr = NWRAMMap_C[1][(addr >> 15) & NWRAMMask[1][2]]; + return ptr ? *(u32*)&ptr[addr & 0x7FFF] : 0; + } + return NDS::ARM7Read32(addr); + case 0x04000000: return ARM7IORead32(addr); } @@ -441,6 +671,24 @@ void ARM7Write8(u32 addr, u8 val) { switch (addr & 0xFF800000) { + case 0x03000000: + if (addr >= NWRAMStart[1][0] && addr < NWRAMEnd[1][0]) + { + u8* ptr = NWRAMMap_A[1][(addr >> 16) & NWRAMMask[1][0]]; + if (ptr) *(u8*)&ptr[addr & 0xFFFF] = val; + } + if (addr >= NWRAMStart[1][1] && addr < NWRAMEnd[1][1]) + { + u8* ptr = NWRAMMap_B[1][(addr >> 15) & NWRAMMask[1][1]]; + if (ptr) *(u8*)&ptr[addr & 0x7FFF] = val; + } + if (addr >= NWRAMStart[1][2] && addr < NWRAMEnd[1][2]) + { + u8* ptr = NWRAMMap_C[1][(addr >> 15) & NWRAMMask[1][2]]; + if (ptr) *(u8*)&ptr[addr & 0x7FFF] = val; + } + return NDS::ARM7Write8(addr, val); + case 0x04000000: ARM7IOWrite8(addr, val); return; @@ -453,6 +701,24 @@ void ARM7Write16(u32 addr, u16 val) { switch (addr & 0xFF800000) { + case 0x03000000: + if (addr >= NWRAMStart[1][0] && addr < NWRAMEnd[1][0]) + { + u8* ptr = NWRAMMap_A[1][(addr >> 16) & NWRAMMask[1][0]]; + if (ptr) *(u16*)&ptr[addr & 0xFFFF] = val; + } + if (addr >= NWRAMStart[1][1] && addr < NWRAMEnd[1][1]) + { + u8* ptr = NWRAMMap_B[1][(addr >> 15) & NWRAMMask[1][1]]; + if (ptr) *(u16*)&ptr[addr & 0x7FFF] = val; + } + if (addr >= NWRAMStart[1][2] && addr < NWRAMEnd[1][2]) + { + u8* ptr = NWRAMMap_C[1][(addr >> 15) & NWRAMMask[1][2]]; + if (ptr) *(u16*)&ptr[addr & 0x7FFF] = val; + } + return NDS::ARM7Write16(addr, val); + case 0x04000000: ARM7IOWrite16(addr, val); return; @@ -465,6 +731,24 @@ void ARM7Write32(u32 addr, u32 val) { switch (addr & 0xFF800000) { + case 0x03000000: + if (addr >= NWRAMStart[1][0] && addr < NWRAMEnd[1][0]) + { + u8* ptr = NWRAMMap_A[1][(addr >> 16) & NWRAMMask[1][0]]; + if (ptr) *(u32*)&ptr[addr & 0xFFFF] = val; + } + if (addr >= NWRAMStart[1][1] && addr < NWRAMEnd[1][1]) + { + u8* ptr = NWRAMMap_B[1][(addr >> 15) & NWRAMMask[1][1]]; + if (ptr) *(u32*)&ptr[addr & 0x7FFF] = val; + } + if (addr >= NWRAMStart[1][2] && addr < NWRAMEnd[1][2]) + { + u8* ptr = NWRAMMap_C[1][(addr >> 15) & NWRAMMask[1][2]]; + if (ptr) *(u32*)&ptr[addr & 0x7FFF] = val; + } + return NDS::ARM7Write32(addr, val); + case 0x04000000: ARM7IOWrite32(addr, val); return; diff --git a/src/DSi.h b/src/DSi.h index 040c39b..b1b4abf 100644 --- a/src/DSi.h +++ b/src/DSi.h @@ -24,6 +24,8 @@ namespace DSi { +void Reset(); + bool LoadBIOS(); bool LoadNAND(); diff --git a/src/NDS.cpp b/src/NDS.cpp index 5481f6f..c285910 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -510,6 +510,8 @@ void Reset() SPI::Reset(); RTC::Reset(); Wifi::Reset(); + + DSi::Reset(); } void Stop() -- cgit v1.2.3 From 58e3ff61ac31a6ac20e12d03c518a6c16715e83c Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 15 Jun 2019 16:58:02 +0200 Subject: add I2C shito --- melonDS.cbp | 2 + src/ARM.cpp | 1 + src/DSi.cpp | 8 +++ src/DSi.h | 2 +- src/DSi_I2C.cpp | 185 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/DSi_I2C.h | 41 +++++++++++++ src/SPI.cpp | 2 +- src/SPI.h | 1 - 8 files changed, 239 insertions(+), 3 deletions(-) create mode 100644 src/DSi_I2C.cpp create mode 100644 src/DSi_I2C.h (limited to 'src') diff --git a/melonDS.cbp b/melonDS.cbp index 97958f5..bbe07dd 100644 --- a/melonDS.cbp +++ b/melonDS.cbp @@ -104,6 +104,8 @@ + + diff --git a/src/ARM.cpp b/src/ARM.cpp index f50af25..870c455 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -175,6 +175,7 @@ void ARMv5::JumpTo(u32 addr, bool restorecpsr) // aging cart debug crap //if (addr == 0x0201764C) printf("capture test %d: R1=%08X\n", R[6], R[1]); //if (addr == 0x020175D8) printf("capture test %d: res=%08X\n", R[6], R[0]); + if (addr==0x037CA0D0) printf("VLORP %08X\n", R[15]); u32 oldregion = R[15] >> 24; u32 newregion = addr >> 24; diff --git a/src/DSi.cpp b/src/DSi.cpp index 22741aa..057d229 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -25,6 +25,8 @@ #include "sha1/sha1.h" #include "Platform.h" +#include "DSi_I2C.h" + namespace NDS { @@ -59,6 +61,8 @@ void Reset() { NDS::ARM9->JumpTo(BootAddr[0]); NDS::ARM7->JumpTo(BootAddr[1]); + + DSi_I2C::Reset(); } bool LoadBIOS() @@ -855,6 +859,8 @@ u8 ARM7IORead8(u32 addr) { switch (addr) { + case 0x04004500: return DSi_I2C::ReadData(); + case 0x04004501: return DSi_I2C::Cnt; } return NDS::ARM7IORead8(addr); @@ -882,6 +888,8 @@ void ARM7IOWrite8(u32 addr, u8 val) { switch (addr) { + case 0x04004500: DSi_I2C::WriteData(val); return; + case 0x04004501: DSi_I2C::WriteCnt(val); return; } return NDS::ARM7IOWrite8(addr, val); diff --git a/src/DSi.h b/src/DSi.h index b1b4abf..02f84da 100644 --- a/src/DSi.h +++ b/src/DSi.h @@ -19,7 +19,7 @@ #ifndef DSI_H #define DSI_H -#include "types.h" +#include "NDS.h" namespace DSi { diff --git a/src/DSi_I2C.cpp b/src/DSi_I2C.cpp new file mode 100644 index 0000000..1836c31 --- /dev/null +++ b/src/DSi_I2C.cpp @@ -0,0 +1,185 @@ +/* + Copyright 2016-2019 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include +#include +#include "DSi.h" +#include "DSi_I2C.h" + + +namespace DSi_BPTWL +{ + +u8 Registers[0x100]; +u32 CurPos; + +bool Init() +{ + return true; +} + +void DeInit() +{ +} + +void Reset() +{ + CurPos = 0; + memset(Registers, 0x5A, 0x100); + + Registers[0x00] = 0x33; // TODO: support others?? + Registers[0x01] = 0x00; + Registers[0x02] = 0x50; + Registers[0x10] = 0x00; // power btn + Registers[0x11] = 0x00; // reset + Registers[0x12] = 0x00; // power btn tap + Registers[0x20] = 0x83; // battery + Registers[0x21] = 0x07; + Registers[0x30] = 0x13; + Registers[0x31] = 0x00; // camera power + Registers[0x40] = 0x1F; // volume + Registers[0x41] = 0x04; // backlight + Registers[0x60] = 0x00; + Registers[0x61] = 0x01; + Registers[0x62] = 0x50; + Registers[0x63] = 0x00; + Registers[0x70] = 0x00; // boot flag + Registers[0x71] = 0x00; + Registers[0x72] = 0x00; + Registers[0x73] = 0x00; + Registers[0x74] = 0x00; + Registers[0x75] = 0x00; + Registers[0x76] = 0x00; + Registers[0x77] = 0x00; + Registers[0x80] = 0x10; + Registers[0x81] = 0x64; +} + +void Start() +{ + CurPos = 0; +} + +u8 Read(bool last) +{ + return Registers[CurPos++]; +} + +void Write(u8 val, bool last) +{ + if (CurPos == 0x11 || CurPos == 0x12 || + CurPos == 0x21 || + CurPos == 0x30 || CurPos == 0x31 || + CurPos == 0x40 || CurPos == 0x31 || + CurPos == 0x60 || CurPos == 0x63 || + (CurPos >= 0x70 && CurPos <= 0x77) || + CurPos == 0x80 || CurPos == 0x81) + { + Registers[CurPos] = val; + } + + CurPos++; +} + +} + + +namespace DSi_I2C +{ + +u8 Cnt; +u32 Device; + +bool Init() +{ + if (!DSi_BPTWL::Init()) return false; + + return true; +} + +void DeInit() +{ + DSi_BPTWL::DeInit(); +} + +void Reset() +{ + Device = -1; + + DSi_BPTWL::Reset(); +} + +void WriteCnt(u8 val) +{ + val &= 0xF7; + // TODO: check ACK flag + // TODO: transfer delay + + if (val & (1<<7)) + { + if (val & (1<<2)) + { + Device = -1; + printf("I2C: start\n"); + } + } + + Cnt = val; +} + +u8 ReadData() +{ + switch (Device) + { + case 0x4A: return DSi_BPTWL::Read(Cnt & (1<<0)); + + default: + printf("I2C: read from unknown device %02X\n", Device); + break; + } + + return 0; +} + +void WriteData(u8 val) +{ + if (Device == -1) + { + Device = val; + switch (Device) + { + case 0x4A: DSi_BPTWL::Start(); return; + + default: + printf("I2C: start on unknown device %02X\n", Device); + break; + } + return; + } + + switch (Device) + { + case 0x4A: DSi_BPTWL::Write(val, Cnt & (1<<0)); return; + + default: + printf("I2C: write to unknown device %02X\n", Device); + break; + } +} + +} diff --git a/src/DSi_I2C.h b/src/DSi_I2C.h new file mode 100644 index 0000000..d058be1 --- /dev/null +++ b/src/DSi_I2C.h @@ -0,0 +1,41 @@ +/* + Copyright 2016-2019 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef DSI_I2C_H +#define DSI_I2C_H + +namespace DSi_I2C +{ + +extern u8 Cnt; + +bool Init(); +void DeInit(); +void Reset(); +//void DoSavestate(Savestate* file); + +void WriteCnt(u8 val); + +u8 ReadData(); +void WriteData(u8 val); + +//void TransferDone(u32 param); + +} + +#endif // DSI_I2C_H diff --git a/src/SPI.cpp b/src/SPI.cpp index 759bbd9..8bee66f 100644 --- a/src/SPI.cpp +++ b/src/SPI.cpp @@ -581,7 +581,7 @@ namespace SPI u16 Cnt; -u32 CurDevice; +u32 CurDevice; // remove me bool Init() diff --git a/src/SPI.h b/src/SPI.h index 9b987ca..21ad9a6 100644 --- a/src/SPI.h +++ b/src/SPI.h @@ -50,7 +50,6 @@ void DeInit(); void Reset(); void DoSavestate(Savestate* file); -u16 ReadCnt(); void WriteCnt(u16 val); u8 ReadData(); -- cgit v1.2.3 From 93330d267037460a2af25744ab169ebc31d1d45f Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 15 Jun 2019 17:23:48 +0200 Subject: fix I2C shit? I think --- src/DSi.cpp | 4 +++ src/DSi_I2C.cpp | 82 +++++++++++++++++++++++++++++++++------------------------ 2 files changed, 51 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index 057d229..3ec5ab1 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -59,6 +59,10 @@ u32 NWRAMMask[2][3]; void Reset() { + //NDS::ARM9->CP15Write(0x910, 0x0D00000A); + //NDS::ARM9->CP15Write(0x911, 0x00000020); + //NDS::ARM9->CP15Write(0x100, NDS::ARM9->CP15Read(0x100) | 0x00050000); + NDS::ARM9->JumpTo(BootAddr[0]); NDS::ARM7->JumpTo(BootAddr[1]); diff --git a/src/DSi_I2C.cpp b/src/DSi_I2C.cpp index 1836c31..03fe85e 100644 --- a/src/DSi_I2C.cpp +++ b/src/DSi_I2C.cpp @@ -103,6 +103,8 @@ namespace DSi_I2C { u8 Cnt; +u8 Data; + u32 Device; bool Init() @@ -119,6 +121,9 @@ void DeInit() void Reset() { + Cnt = 0; + Data = 0; + Device = -1; DSi_BPTWL::Reset(); @@ -126,17 +131,54 @@ void Reset() void WriteCnt(u8 val) { + printf("I2C: write CNT %02X\n", val); + val &= 0xF7; // TODO: check ACK flag // TODO: transfer delay + // TODO: IRQ + // TODO: check read/write direction if (val & (1<<7)) { - if (val & (1<<2)) + bool islast = Cnt & (1<<0); + + if (val & (1<<5)) + { + // read + printf("I2C read, device=%02X, cnt=%02X, last=%d\n", Device, Cnt, islast); + + switch (Device) + { + case 0x4A: Data = DSi_BPTWL::Read(islast); break; + default: Data = 0; break; + } + } + else { - Device = -1; - printf("I2C: start\n"); + // write + printf("I2C write, device=%02X, cnt=%02X, last=%d\n", Device, Cnt, islast); + + if (val & (1<<1)) + { + Device = Data; + printf("I2C: start, device=%02X\n", Device); + + switch (Device) + { + case 0x4A: DSi_BPTWL::Start(); return; + } + } + else + { + switch (Device) + { + case 0x4A: DSi_BPTWL::Write(Data, islast); break; + } + } } + + val &= 0x7F; } Cnt = val; @@ -144,42 +186,12 @@ void WriteCnt(u8 val) u8 ReadData() { - switch (Device) - { - case 0x4A: return DSi_BPTWL::Read(Cnt & (1<<0)); - - default: - printf("I2C: read from unknown device %02X\n", Device); - break; - } - - return 0; + return Data; } void WriteData(u8 val) { - if (Device == -1) - { - Device = val; - switch (Device) - { - case 0x4A: DSi_BPTWL::Start(); return; - - default: - printf("I2C: start on unknown device %02X\n", Device); - break; - } - return; - } - - switch (Device) - { - case 0x4A: DSi_BPTWL::Write(val, Cnt & (1<<0)); return; - - default: - printf("I2C: write to unknown device %02X\n", Device); - break; - } + Data = val; } } -- cgit v1.2.3 From 4d3f346edcd8b7edff2415d7c90903c54d4ee34f Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 15 Jun 2019 18:30:12 +0200 Subject: get it to do more interesting things --- src/ARM.cpp | 4 +++- src/DSi.cpp | 1 + src/DSi_I2C.cpp | 19 ++++++++++++------- 3 files changed, 16 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/ARM.cpp b/src/ARM.cpp index 870c455..ee72fbe 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -175,7 +175,7 @@ void ARMv5::JumpTo(u32 addr, bool restorecpsr) // aging cart debug crap //if (addr == 0x0201764C) printf("capture test %d: R1=%08X\n", R[6], R[1]); //if (addr == 0x020175D8) printf("capture test %d: res=%08X\n", R[6], R[0]); - if (addr==0x037CA0D0) printf("VLORP %08X\n", R[15]); + //if (addr==0x037CA0D0) printf("VLORP %08X\n", R[15]); u32 oldregion = R[15] >> 24; u32 newregion = addr >> 24; @@ -243,6 +243,8 @@ void ARMv4::JumpTo(u32 addr, bool restorecpsr) else addr &= ~0x1; } + //if (addr==0x037D5A18) printf("SHITTY FUNC. %08X\n", R[15]); + u32 oldregion = R[15] >> 23; u32 newregion = addr >> 23; diff --git a/src/DSi.cpp b/src/DSi.cpp index 3ec5ab1..0472f1d 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -817,6 +817,7 @@ u16 ARM9IORead16(u32 addr) { switch (addr) { + case 0x04004004: return 0; // TODO } return NDS::ARM9IORead16(addr); diff --git a/src/DSi_I2C.cpp b/src/DSi_I2C.cpp index 03fe85e..4a4f1e7 100644 --- a/src/DSi_I2C.cpp +++ b/src/DSi_I2C.cpp @@ -133,7 +133,6 @@ void WriteCnt(u8 val) { printf("I2C: write CNT %02X\n", val); - val &= 0xF7; // TODO: check ACK flag // TODO: transfer delay // TODO: IRQ @@ -141,41 +140,47 @@ void WriteCnt(u8 val) if (val & (1<<7)) { - bool islast = Cnt & (1<<0); + bool islast = val & (1<<0); if (val & (1<<5)) { // read - printf("I2C read, device=%02X, cnt=%02X, last=%d\n", Device, Cnt, islast); + val &= 0xF7; switch (Device) { case 0x4A: Data = DSi_BPTWL::Read(islast); break; default: Data = 0; break; } + + printf("I2C read, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); } else { // write - printf("I2C write, device=%02X, cnt=%02X, last=%d\n", Device, Cnt, islast); + val &= 0xE7; if (val & (1<<1)) { - Device = Data; - printf("I2C: start, device=%02X\n", Device); + Device = Data & 0xFE; + printf("I2C: %s start, device=%02X\n", (Data&0x01)?"read":"write", Device); switch (Device) { - case 0x4A: DSi_BPTWL::Start(); return; + case 0x4A: DSi_BPTWL::Start(); break; } } else { + printf("I2C write, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); + switch (Device) { case 0x4A: DSi_BPTWL::Write(Data, islast); break; } } + + val |= (1<<4); } val &= 0x7F; -- cgit v1.2.3 From 7b19a012040185a28474b6782da206c46a53c614 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 15 Jun 2019 18:39:34 +0200 Subject: betterer I2C --- src/DSi_I2C.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/DSi_I2C.cpp b/src/DSi_I2C.cpp index 4a4f1e7..b7b7022 100644 --- a/src/DSi_I2C.cpp +++ b/src/DSi_I2C.cpp @@ -39,7 +39,7 @@ void DeInit() void Reset() { - CurPos = 0; + CurPos = -1; memset(Registers, 0x5A, 0x100); Registers[0x00] = 0x33; // TODO: support others?? @@ -72,16 +72,36 @@ void Reset() void Start() { - CurPos = 0; + printf("BPTWL: start\n"); } u8 Read(bool last) { + if (last) + { + CurPos = -1; + return 0; + } + + printf("BPTWL: read %02X -> %02X\n", CurPos, Registers[CurPos]); return Registers[CurPos++]; } void Write(u8 val, bool last) { + if (last) + { + CurPos = -1; + return; + } + + if (CurPos == -1) + { + CurPos = val; + printf("BPTWL: reg=%02X\n", val); + return; + } + if (CurPos == 0x11 || CurPos == 0x12 || CurPos == 0x21 || CurPos == 0x30 || CurPos == 0x31 || @@ -93,7 +113,8 @@ void Write(u8 val, bool last) Registers[CurPos] = val; } - CurPos++; + printf("BPTWL: write %02X -> %02X\n", CurPos, val); + CurPos++; // CHECKME } } -- cgit v1.2.3 From 78c41736c391f65d8e6af5492ee621c956c6ed01 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 16 Jun 2019 14:26:54 +0200 Subject: fix fucking ass-stupid bug with new-WRAM handling --- src/ARM.cpp | 6 ------ src/DSi.cpp | 27 ++++++++++++++++++++++++++- src/DSi_I2C.cpp | 1 + 3 files changed, 27 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/ARM.cpp b/src/ARM.cpp index ee72fbe..b7fe3c7 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -175,7 +175,6 @@ void ARMv5::JumpTo(u32 addr, bool restorecpsr) // aging cart debug crap //if (addr == 0x0201764C) printf("capture test %d: R1=%08X\n", R[6], R[1]); //if (addr == 0x020175D8) printf("capture test %d: res=%08X\n", R[6], R[0]); - //if (addr==0x037CA0D0) printf("VLORP %08X\n", R[15]); u32 oldregion = R[15] >> 24; u32 newregion = addr >> 24; @@ -222,9 +221,6 @@ void ARMv5::JumpTo(u32 addr, bool restorecpsr) CPSR &= ~0x20; } - // TODO: investigate this - // firmware jumps to region 01FFxxxx, but region 5 (01000000-02000000) is set to non-executable - // is melonDS fucked up somewhere, or is the DS PU just incomplete/crapoed? /*if (!(PU_Map[addr>>12] & 0x04)) { printf("jumped to %08X. very bad\n", addr); @@ -243,8 +239,6 @@ void ARMv4::JumpTo(u32 addr, bool restorecpsr) else addr &= ~0x1; } - //if (addr==0x037D5A18) printf("SHITTY FUNC. %08X\n", R[15]); - u32 oldregion = R[15] >> 23; u32 newregion = addr >> 23; diff --git a/src/DSi.cpp b/src/DSi.cpp index 0472f1d..ae1bed2 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -484,16 +484,19 @@ void ARM9Write8(u32 addr, u8 val) { u8* ptr = NWRAMMap_A[0][(addr >> 16) & NWRAMMask[0][0]]; if (ptr) *(u8*)&ptr[addr & 0xFFFF] = val; + return; } if (addr >= NWRAMStart[0][1] && addr < NWRAMEnd[0][1]) { u8* ptr = NWRAMMap_B[0][(addr >> 15) & NWRAMMask[0][1]]; if (ptr) *(u8*)&ptr[addr & 0x7FFF] = val; + return; } if (addr >= NWRAMStart[0][2] && addr < NWRAMEnd[0][2]) { u8* ptr = NWRAMMap_C[0][(addr >> 15) & NWRAMMask[0][2]]; if (ptr) *(u8*)&ptr[addr & 0x7FFF] = val; + return; } return NDS::ARM9Write8(addr, val); @@ -514,16 +517,19 @@ void ARM9Write16(u32 addr, u16 val) { u8* ptr = NWRAMMap_A[0][(addr >> 16) & NWRAMMask[0][0]]; if (ptr) *(u16*)&ptr[addr & 0xFFFF] = val; + return; } if (addr >= NWRAMStart[0][1] && addr < NWRAMEnd[0][1]) { u8* ptr = NWRAMMap_B[0][(addr >> 15) & NWRAMMask[0][1]]; if (ptr) *(u16*)&ptr[addr & 0x7FFF] = val; + return; } if (addr >= NWRAMStart[0][2] && addr < NWRAMEnd[0][2]) { u8* ptr = NWRAMMap_C[0][(addr >> 15) & NWRAMMask[0][2]]; if (ptr) *(u16*)&ptr[addr & 0x7FFF] = val; + return; } return NDS::ARM9Write16(addr, val); @@ -544,16 +550,19 @@ void ARM9Write32(u32 addr, u32 val) { u8* ptr = NWRAMMap_A[0][(addr >> 16) & NWRAMMask[0][0]]; if (ptr) *(u32*)&ptr[addr & 0xFFFF] = val; + return; } if (addr >= NWRAMStart[0][1] && addr < NWRAMEnd[0][1]) { u8* ptr = NWRAMMap_B[0][(addr >> 15) & NWRAMMask[0][1]]; if (ptr) *(u32*)&ptr[addr & 0x7FFF] = val; + return; } if (addr >= NWRAMStart[0][2] && addr < NWRAMEnd[0][2]) { u8* ptr = NWRAMMap_C[0][(addr >> 15) & NWRAMMask[0][2]]; if (ptr) *(u32*)&ptr[addr & 0x7FFF] = val; + return; } return NDS::ARM9Write32(addr, val); @@ -684,16 +693,19 @@ void ARM7Write8(u32 addr, u8 val) { u8* ptr = NWRAMMap_A[1][(addr >> 16) & NWRAMMask[1][0]]; if (ptr) *(u8*)&ptr[addr & 0xFFFF] = val; + return; } if (addr >= NWRAMStart[1][1] && addr < NWRAMEnd[1][1]) { u8* ptr = NWRAMMap_B[1][(addr >> 15) & NWRAMMask[1][1]]; if (ptr) *(u8*)&ptr[addr & 0x7FFF] = val; + return; } if (addr >= NWRAMStart[1][2] && addr < NWRAMEnd[1][2]) { u8* ptr = NWRAMMap_C[1][(addr >> 15) & NWRAMMask[1][2]]; if (ptr) *(u8*)&ptr[addr & 0x7FFF] = val; + return; } return NDS::ARM7Write8(addr, val); @@ -714,16 +726,19 @@ void ARM7Write16(u32 addr, u16 val) { u8* ptr = NWRAMMap_A[1][(addr >> 16) & NWRAMMask[1][0]]; if (ptr) *(u16*)&ptr[addr & 0xFFFF] = val; + return; } if (addr >= NWRAMStart[1][1] && addr < NWRAMEnd[1][1]) { u8* ptr = NWRAMMap_B[1][(addr >> 15) & NWRAMMask[1][1]]; if (ptr) *(u16*)&ptr[addr & 0x7FFF] = val; + return; } if (addr >= NWRAMStart[1][2] && addr < NWRAMEnd[1][2]) { u8* ptr = NWRAMMap_C[1][(addr >> 15) & NWRAMMask[1][2]]; if (ptr) *(u16*)&ptr[addr & 0x7FFF] = val; + return; } return NDS::ARM7Write16(addr, val); @@ -744,16 +759,19 @@ void ARM7Write32(u32 addr, u32 val) { u8* ptr = NWRAMMap_A[1][(addr >> 16) & NWRAMMask[1][0]]; if (ptr) *(u32*)&ptr[addr & 0xFFFF] = val; + return; } if (addr >= NWRAMStart[1][1] && addr < NWRAMEnd[1][1]) { u8* ptr = NWRAMMap_B[1][(addr >> 15) & NWRAMMask[1][1]]; if (ptr) *(u32*)&ptr[addr & 0x7FFF] = val; + return; } if (addr >= NWRAMStart[1][2] && addr < NWRAMEnd[1][2]) { u8* ptr = NWRAMMap_C[1][(addr >> 15) & NWRAMMask[1][2]]; if (ptr) *(u32*)&ptr[addr & 0x7FFF] = val; + return; } return NDS::ARM7Write32(addr, val); @@ -827,6 +845,7 @@ u32 ARM9IORead32(u32 addr) { switch (addr) { + case 0x04004010: return 1; // todo } return NDS::ARM9IORead32(addr); @@ -864,8 +883,11 @@ u8 ARM7IORead8(u32 addr) { switch (addr) { + case 0x04004000: return 0x01; + case 0x04004001: return 0x01; + case 0x04004500: return DSi_I2C::ReadData(); - case 0x04004501: return DSi_I2C::Cnt; + case 0x04004501: printf("read I2C CNT %02X\n", DSi_I2C::Cnt); return DSi_I2C::Cnt; } return NDS::ARM7IORead8(addr); @@ -875,6 +897,8 @@ u16 ARM7IORead16(u32 addr) { switch (addr) { + case 0x04004004: return 0x0187; + case 0x04004006: return 0; // JTAG register } return NDS::ARM7IORead16(addr); @@ -884,6 +908,7 @@ u32 ARM7IORead32(u32 addr) { switch (addr) { + case 0x04004008: return 0x80000000; // HAX } return NDS::ARM7IORead32(addr); diff --git a/src/DSi_I2C.cpp b/src/DSi_I2C.cpp index b7b7022..8b01b0e 100644 --- a/src/DSi_I2C.cpp +++ b/src/DSi_I2C.cpp @@ -212,6 +212,7 @@ void WriteCnt(u8 val) u8 ReadData() { + printf("I2C: read the data: %02X\n", Data); return Data; } -- cgit v1.2.3 From 566a8df6cd5af057a77cf8bed091e1b7a18bfecd Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 16 Jun 2019 15:05:18 +0200 Subject: add IE2/IF2 --- src/DSi.cpp | 10 ++++++++++ src/NDS.cpp | 16 ++++++++++++++++ src/NDS.h | 41 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 64 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index ae1bed2..206c253 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -897,6 +897,9 @@ u16 ARM7IORead16(u32 addr) { switch (addr) { + case 0x04000218: return NDS::IE2; + case 0x0400021C: return NDS::IF2; + case 0x04004004: return 0x0187; case 0x04004006: return 0; // JTAG register } @@ -908,6 +911,9 @@ u32 ARM7IORead32(u32 addr) { switch (addr) { + case 0x04000218: return NDS::IE2; + case 0x0400021C: return NDS::IF2; + case 0x04004008: return 0x80000000; // HAX } @@ -929,6 +935,8 @@ void ARM7IOWrite16(u32 addr, u16 val) { switch (addr) { + case 0x04000218: NDS::IE2 = (val & 0x7FF7); NDS::UpdateIRQ(1); return; + case 0x0400021C: NDS::IF2 &= ~(val & 0x7FF7); NDS::UpdateIRQ(1); return; } return NDS::ARM7IOWrite16(addr, val); @@ -938,6 +946,8 @@ void ARM7IOWrite32(u32 addr, u32 val) { switch (addr) { + case 0x04000218: NDS::IE2 = (val & 0x7FF7); NDS::UpdateIRQ(1); return; + case 0x0400021C: NDS::IF2 &= ~(val & 0x7FF7); NDS::UpdateIRQ(1); return; } return NDS::ARM7IOWrite32(addr, val); diff --git a/src/NDS.cpp b/src/NDS.cpp index c285910..5ca55f3 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -107,6 +107,7 @@ u8 ROMSeed1[2*8]; // IO shit u32 IME[2]; u32 IE[2], IF[2]; +u32 IE2, IF2; u8 PostFlag9; u8 PostFlag7; @@ -462,6 +463,8 @@ void Reset() IME[1] = 0; IE[1] = 0; IF[1] = 0; + IE2 = 0; + IF2 = 0; PostFlag9 = 0x00; PostFlag7 = 0x00; @@ -1067,6 +1070,7 @@ void UpdateIRQ(u32 cpu) if (IME[cpu] & 0x1) { arm->IRQ = IE[cpu] & IF[cpu]; + if (cpu) arm->IRQ |= (IE2 & IF2); } else { @@ -1086,6 +1090,18 @@ void ClearIRQ(u32 cpu, u32 irq) UpdateIRQ(cpu); } +void SetIRQ2(u32 irq) +{ + IF2 |= (1 << irq); + UpdateIRQ(1); +} + +void ClearIRQ2(u32 irq) +{ + IF2 &= ~(1 << irq); + UpdateIRQ(1); +} + bool HaltInterrupted(u32 cpu) { if (cpu == 0) diff --git a/src/NDS.h b/src/NDS.h index e8bb44d..e6cd2ee 100644 --- a/src/NDS.h +++ b/src/NDS.h @@ -74,12 +74,42 @@ enum IRQ_IPCSync, IRQ_IPCSendDone, IRQ_IPCRecv, - IRQ_CartSendDone, - IRQ_CartIREQMC, + IRQ_CartSendDone, // TODO: less misleading name + IRQ_CartIREQMC, // IRQ triggered by game cart (example: Pokémon Typing Adventure, BT controller) IRQ_GXFIFO, IRQ_LidOpen, IRQ_SPI, - IRQ_Wifi + IRQ_Wifi, + + // DSi IRQs + IRQ_DSi_DSP = 24, + IRQ_DSi_Camera, + IRQ_DSi_Unk26, + IRQ_DSi_Unk27, + IRQ_DSi_NDMA0, + IRQ_DSi_NDMA1, + IRQ_DSi_NDMA2, + IRQ_DSi_NDMA3, +}; + +enum +{ + // DSi ARM7-side IE2/IF2 + IRQ2_DSi_GPIO18_0 = 0, + IRQ2_DSi_GPIO18_1, + IRQ2_DSi_GPIO18_2, + IRQ2_DSi_Unused35, + IRQ2_DSi_GPIO33_0, + IRQ2_DSi_Headphone, + IRQ2_DSi_PowerButton, + IRQ2_DSi_GPIO33_3, // "sound enable input" + IRQ2_DSi_SDMMC, + IRQ2_DSi_SD_Data1, + IRQ2_DSi_SDIO, + IRQ2_DSi_SDIO_Data1, + IRQ2_DSi_AES, + IRQ2_DSi_I2C, + IRQ2_DSi_MicExt }; typedef struct @@ -109,6 +139,8 @@ extern u32 ARM9ClockShift; extern u32 IME[2]; extern u32 IE[2]; extern u32 IF[2]; +extern u32 IE2; +extern u32 IF2; extern Timer Timers[8]; extern u16 PowerControl9; @@ -162,8 +194,11 @@ void Halt(); void MapSharedWRAM(u8 val); +void UpdateIRQ(u32 cpu); void SetIRQ(u32 cpu, u32 irq); void ClearIRQ(u32 cpu, u32 irq); +void SetIRQ2(u32 irq); +void ClearIRQ2(u32 irq); bool HaltInterrupted(u32 cpu); void StopCPU(u32 cpu, u32 mask); void ResumeCPU(u32 cpu, u32 mask); -- cgit v1.2.3 From d4dd97638d1615f51bcadd256d390a895519d565 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 16 Jun 2019 17:01:49 +0200 Subject: lay base for SD shit --- melonDS.cbp | 2 ++ src/DSi.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/DSi.h | 2 ++ src/DSi_SD.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/DSi_SD.h | 41 +++++++++++++++++++++++++++++++++ src/NDS.cpp | 4 ++++ src/version.h | 2 +- 7 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 src/DSi_SD.cpp create mode 100644 src/DSi_SD.h (limited to 'src') diff --git a/melonDS.cbp b/melonDS.cbp index bbe07dd..e75e02c 100644 --- a/melonDS.cbp +++ b/melonDS.cbp @@ -106,6 +106,8 @@ + + diff --git a/src/DSi.cpp b/src/DSi.cpp index 206c253..e30e3e1 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -26,6 +26,7 @@ #include "Platform.h" #include "DSi_I2C.h" +#include "DSi_SD.h" namespace NDS @@ -56,6 +57,27 @@ u32 NWRAMStart[2][3]; u32 NWRAMEnd[2][3]; u32 NWRAMMask[2][3]; +DSi_SD* SDMMC; +DSi_SD* SDIO; + + +bool Init() +{ + if (!DSi_I2C::Init()) return false; + + SDMMC = new DSi_SD(0); + SDIO = new DSi_SD(1); + + return true; +} + +void DeInit() +{ + DSi_I2C::DeInit(); + + delete SDMMC; + delete SDIO; +} void Reset() { @@ -67,6 +89,9 @@ void Reset() NDS::ARM7->JumpTo(BootAddr[1]); DSi_I2C::Reset(); + + SDMMC->Reset(); + SDIO->Reset(); } bool LoadBIOS() @@ -904,6 +929,15 @@ u16 ARM7IORead16(u32 addr) case 0x04004006: return 0; // JTAG register } + if (addr >= 0x04004800 && addr < 0x04004A00) + { + return SDMMC->Read(addr); + } + if (addr >= 0x04004A00 && addr < 0x04004C00) + { + return SDIO->Read(addr); + } + return NDS::ARM7IORead16(addr); } @@ -917,6 +951,15 @@ u32 ARM7IORead32(u32 addr) case 0x04004008: return 0x80000000; // HAX } + if (addr >= 0x04004800 && addr < 0x04004A00) + { + return SDMMC->Read(addr) | (SDMMC->Read(addr+2) << 16); + } + if (addr >= 0x04004A00 && addr < 0x04004C00) + { + return SDIO->Read(addr) | (SDIO->Read(addr+2) << 16); + } + return NDS::ARM7IORead32(addr); } @@ -939,6 +982,17 @@ void ARM7IOWrite16(u32 addr, u16 val) case 0x0400021C: NDS::IF2 &= ~(val & 0x7FF7); NDS::UpdateIRQ(1); return; } + if (addr >= 0x04004800 && addr < 0x04004A00) + { + SDMMC->Write(addr, val); + return; + } + if (addr >= 0x04004A00 && addr < 0x04004C00) + { + SDIO->Write(addr, val); + return; + } + return NDS::ARM7IOWrite16(addr, val); } @@ -950,6 +1004,19 @@ void ARM7IOWrite32(u32 addr, u32 val) case 0x0400021C: NDS::IF2 &= ~(val & 0x7FF7); NDS::UpdateIRQ(1); return; } + if (addr >= 0x04004800 && addr < 0x04004A00) + { + SDMMC->Write(addr, val & 0xFFFF); + SDMMC->Write(addr+2, val >> 16); + return; + } + if (addr >= 0x04004A00 && addr < 0x04004C00) + { + SDIO->Write(addr, val & 0xFFFF); + SDIO->Write(addr+2, val >> 16); + return; + } + return NDS::ARM7IOWrite32(addr, val); } diff --git a/src/DSi.h b/src/DSi.h index 02f84da..6d45a10 100644 --- a/src/DSi.h +++ b/src/DSi.h @@ -24,6 +24,8 @@ namespace DSi { +bool Init(); +void DeInit(); void Reset(); bool LoadBIOS(); diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp new file mode 100644 index 0000000..58b733c --- /dev/null +++ b/src/DSi_SD.cpp @@ -0,0 +1,72 @@ +/* + Copyright 2016-2019 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include +#include +#include "DSi.h" +#include "DSi_SD.h" + + +DSi_SD::DSi_SD(u32 num) +{ + Num = num; +} + +DSi_SD::~DSi_SD() +{ + // +} + +void DSi_SD::Reset() +{ + if (Num == 0) + { + PortSelect = 0x0200; // CHECKME + } + else + { + PortSelect = 0x0100; // CHECKME + } +} + +void DSi_SD::DoSavestate(Savestate* file) +{ + // TODO! +} + + +u16 DSi_SD::Read(u32 addr) +{ + switch (addr & 0x1FF) + { + case 0x002: return PortSelect & 0x030F; + } + + printf("unknown %s read %08X\n", Num?"SDIO":"SD/MMC", addr); + return 0; +} + +void DSi_SD::Write(u32 addr, u16 val) +{ + switch (addr & 0x1FF) + { + case 0x002: PortSelect = val; return; + } + + printf("unknown %s write %08X %04X\n", Num?"SDIO":"SD/MMC", addr, val); +} diff --git a/src/DSi_SD.h b/src/DSi_SD.h new file mode 100644 index 0000000..ce3eb84 --- /dev/null +++ b/src/DSi_SD.h @@ -0,0 +1,41 @@ +/* + Copyright 2016-2019 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef DSI_SD_H +#define DSI_SD_H + +class DSi_SD +{ +public: + DSi_SD(u32 num); + ~DSi_SD(); + + void Reset(); + + void DoSavestate(Savestate* file); + + u16 Read(u32 addr); + void Write(u32 addr, u16 val); + +private: + u32 Num; + + u16 PortSelect; +}; + +#endif // DSI_SD_H diff --git a/src/NDS.cpp b/src/NDS.cpp index 5ca55f3..414f87c 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -178,6 +178,8 @@ bool Init() if (!RTC::Init()) return false; if (!Wifi::Init()) return false; + if (!DSi::Init()) return false; + return true; } @@ -198,6 +200,8 @@ void DeInit() SPI::DeInit(); RTC::DeInit(); Wifi::DeInit(); + + DSi::DeInit(); } diff --git a/src/version.h b/src/version.h index cc15c89..bb97c3c 100644 --- a/src/version.h +++ b/src/version.h @@ -19,7 +19,7 @@ #ifndef VERSION_H #define VERSION_H -#define MELONDS_VERSION "0.8.1" +#define MELONDS_VERSION "0.8.1-DSi" #define MELONDS_URL "http://melonds.kuribo64.net/" -- cgit v1.2.3 From bedc0220fca7cb92ad37c3bac0e503372ea84ffc Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 17 Jun 2019 13:24:37 +0200 Subject: take this shit further --- src/DSi.cpp | 8 +-- src/DSi_SD.cpp | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- src/DSi_SD.h | 55 +++++++++++++++++- 3 files changed, 222 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index e30e3e1..8315fb8 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -57,16 +57,16 @@ u32 NWRAMStart[2][3]; u32 NWRAMEnd[2][3]; u32 NWRAMMask[2][3]; -DSi_SD* SDMMC; -DSi_SD* SDIO; +DSi_SDHost* SDMMC; +DSi_SDHost* SDIO; bool Init() { if (!DSi_I2C::Init()) return false; - SDMMC = new DSi_SD(0); - SDIO = new DSi_SD(1); + SDMMC = new DSi_SDHost(0); + SDIO = new DSi_SDHost(1); return true; } diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index 58b733c..a821fe5 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -20,19 +20,27 @@ #include #include "DSi.h" #include "DSi_SD.h" +#include "Platform.h" -DSi_SD::DSi_SD(u32 num) +#define SD_DESC (Num?"SDIO":"SD/MMC") + + +DSi_SDHost::DSi_SDHost(u32 num) { Num = num; + + Ports[0] = NULL; + Ports[1] = NULL; } -DSi_SD::~DSi_SD() +DSi_SDHost::~DSi_SDHost() { - // + if (Ports[0]) delete Ports[0]; + if (Ports[1]) delete Ports[1]; } -void DSi_SD::Reset() +void DSi_SDHost::Reset() { if (Num == 0) { @@ -42,31 +50,180 @@ void DSi_SD::Reset() { PortSelect = 0x0100; // CHECKME } + + SoftReset = 0x0007; // CHECKME + + Command = 0; + Param = 0; + memset(ResponseBuffer, 0, sizeof(ResponseBuffer)); + + IRQStatus = 0; + IRQMask = 0x8B7F031D; + + if (Ports[0]) delete Ports[0]; + if (Ports[1]) delete Ports[1]; + Ports[0] = NULL; + Ports[1] = NULL; + + if (Num == 0) + { + // TODO: port 0 (SD) + Ports[1] = new DSi_MMCStorage(this, true, "nand.bin"); + } + else + { + // TODO: SDIO (wifi) + } } -void DSi_SD::DoSavestate(Savestate* file) +void DSi_SDHost::DoSavestate(Savestate* file) { // TODO! } -u16 DSi_SD::Read(u32 addr) +void DSi_SDHost::SetIRQ(u32 irq) { + u32 oldflags = IRQStatus & ~IRQMask; + + IRQStatus |= (1<> 16; + + case 0x00C: return ResponseBuffer[0]; + case 0x00E: return ResponseBuffer[1]; + case 0x010: return ResponseBuffer[2]; + case 0x012: return ResponseBuffer[3]; + case 0x014: return ResponseBuffer[4]; + case 0x016: return ResponseBuffer[5]; + case 0x018: return ResponseBuffer[6]; + case 0x01A: return ResponseBuffer[7]; + + case 0x01C: return IRQStatus & 0x031D; + case 0x01E: return (IRQStatus >> 16) & 0x8B7F; + case 0x020: return IRQMask & 0x031D; + case 0x022: return (IRQMask >> 16) & 0x8B7F; + + case 0x0E0: return SoftReset; } - printf("unknown %s read %08X\n", Num?"SDIO":"SD/MMC", addr); + printf("unknown %s read %08X\n", SD_DESC, addr); return 0; } -void DSi_SD::Write(u32 addr, u16 val) +void DSi_SDHost::Write(u32 addr, u16 val) { + //printf("SDMMC WRITE %08X %04X %08X\n", addr, val, NDS::GetPC(1)); + switch (addr & 0x1FF) { + case 0x000: + { + Command = val; + u8 cmd = Command & 0x3F; + + DSi_SDDevice* dev = Ports[PortSelect & 0x1]; + if (dev) + { + switch ((Command >> 6) & 0x3) + { + case 0: dev->SendCMD(cmd, Param); break; + case 1: dev->SendACMD(cmd, Param); break; + default: + printf("%s: unknown command type %d, %02X %08X\n", SD_DESC, (Command>>6)&0x3, cmd, Param); + break; + } + } + } + return; + case 0x002: PortSelect = val; return; + case 0x004: Param = (Param & 0xFFFF0000) | val; return; + case 0x006: Param = (Param & 0x0000FFFF) | (val << 16); return; + + case 0x01C: IRQStatus &= ~(u32)val; return; + case 0x01E: IRQStatus &= ~((u32)val << 16); return; + case 0x020: IRQMask = (IRQMask & 0x8B7F0000) | (val & 0x031D); return; + case 0x022: IRQMask = (IRQMask & 0x0000031D) | ((val & 0x8B7F) << 16); return; + + case 0x0E0: + if ((SoftReset & 0x0001) && !(val & 0x0001)) + { + printf("%s: RESET\n", SD_DESC); + // TODO: STOP_INTERNAL_ACTION + // TODO: SD_RESPONSE + IRQStatus = 0; + // TODO: ERROR_DETAIL_STATUS + // TODO: CARD_CLK_CTL + // TODO: CARD_OPTION + // TODO: CARD_IRQ_STAT + // TODO: FIFO16 shit + } + SoftReset = 0x0006 | (val & 0x0001); + return; + } + + printf("unknown %s write %08X %04X\n", SD_DESC, addr, val); +} + + +DSi_MMCStorage::DSi_MMCStorage(DSi_SDHost* host, bool internal, const char* path) : DSi_SDDevice(host) +{ + Internal = internal; + strncpy(FilePath, path, 1023); FilePath[1023] = '\0'; + + File = Platform::OpenLocalFile(path, "r+b"); + + CSR = 0x00; // checkme +} + +DSi_MMCStorage::~DSi_MMCStorage() +{ + if (File) fclose(File); +} + +void DSi_MMCStorage::SendCMD(u8 cmd, u32 param) +{ + switch (cmd) + { + case 0x00: // reset/etc + Host->SendResponse(CSR, true); + return; + + case 0x08: // set voltage + Host->SendResponse(param, true); + return; } - printf("unknown %s write %08X %04X\n", Num?"SDIO":"SD/MMC", addr, val); + printf("MMC: unknown CMD %02X %08X\n", cmd, param); +} + +void DSi_MMCStorage::SendACMD(u8 cmd, u32 param) +{ + printf("MMC: ACMD %02X %08X\n", cmd, param); } diff --git a/src/DSi_SD.h b/src/DSi_SD.h index ce3eb84..248755d 100644 --- a/src/DSi_SD.h +++ b/src/DSi_SD.h @@ -19,16 +19,21 @@ #ifndef DSI_SD_H #define DSI_SD_H -class DSi_SD +class DSi_SDDevice; + + +class DSi_SDHost { public: - DSi_SD(u32 num); - ~DSi_SD(); + DSi_SDHost(u32 num); + ~DSi_SDHost(); void Reset(); void DoSavestate(Savestate* file); + void SendResponse(u32 val, bool last); + u16 Read(u32 addr); void Write(u32 addr, u16 val); @@ -36,6 +41,50 @@ private: u32 Num; u16 PortSelect; + u16 SoftReset; + + u32 IRQStatus; // IF + u32 IRQMask; // ~IE + + u16 Command; + u32 Param; + u16 ResponseBuffer[8]; + + DSi_SDDevice* Ports[2]; + + void SetIRQ(u32 irq); +}; + + +class DSi_SDDevice +{ +public: + DSi_SDDevice(DSi_SDHost* host) { Host = host; } + ~DSi_SDDevice() {} + + virtual void SendCMD(u8 cmd, u32 param) = 0; + virtual void SendACMD(u8 cmd, u32 param) = 0; + +protected: + DSi_SDHost* Host; +}; + + +class DSi_MMCStorage : public DSi_SDDevice +{ +public: + DSi_MMCStorage(DSi_SDHost* host, bool internal, const char* path); + ~DSi_MMCStorage(); + + void SendCMD(u8 cmd, u32 param); + void SendACMD(u8 cmd, u32 param); + +private: + bool Internal; + char FilePath[1024]; + FILE* File; + + u8 CSR; }; #endif // DSI_SD_H -- cgit v1.2.3 From 6c75275593c854ab6324f9c38155930ed1ca9328 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 17 Jun 2019 18:40:45 +0200 Subject: moar SD/MMC commands --- src/DSi.cpp | 13 +++++---- src/DSi.h | 2 ++ src/DSi_SD.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- src/DSi_SD.h | 13 +++++++-- 4 files changed, 100 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index 8315fb8..abd3bd6 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -60,6 +60,9 @@ u32 NWRAMMask[2][3]; DSi_SDHost* SDMMC; DSi_SDHost* SDIO; +u64 ConsoleID; +u8 eMMC_CID[16]; + bool Init() { @@ -262,14 +265,12 @@ bool LoadNAND() #define printhex(str, size) { for (int z = 0; z < (size); z++) printf("%02X", (str)[z]); printf("\n"); } #define printhex_rev(str, size) { for (int z = (size)-1; z >= 0; z--) printf("%02X", (str)[z]); printf("\n"); } - u8 emmc_cid[16]; - u8 consoleid[8]; fseek(f, 0xF000010, SEEK_SET); - fread(emmc_cid, 1, 16, f); - fread(consoleid, 1, 8, f); + fread(eMMC_CID, 1, 16, f); + fread(&ConsoleID, 1, 8, f); - printf("eMMC CID: "); printhex(emmc_cid, 16); - printf("Console ID: "); printhex_rev(consoleid, 8); + printf("eMMC CID: "); printhex(eMMC_CID, 16); + printf("Console ID: %llx\n", ConsoleID); fclose(f); } diff --git a/src/DSi.h b/src/DSi.h index 6d45a10..3ebee37 100644 --- a/src/DSi.h +++ b/src/DSi.h @@ -24,6 +24,8 @@ namespace DSi { +extern u8 eMMC_CID[16]; + bool Init(); void DeInit(); void Reset(); diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index a821fe5..35859cc 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -52,6 +52,7 @@ void DSi_SDHost::Reset() } SoftReset = 0x0007; // CHECKME + SDClock = 0; Command = 0; Param = 0; @@ -67,8 +68,11 @@ void DSi_SDHost::Reset() if (Num == 0) { + DSi_MMCStorage* mmc = new DSi_MMCStorage(this, true, "nand.bin"); + mmc->SetCID(DSi::eMMC_CID); + // TODO: port 0 (SD) - Ports[1] = new DSi_MMCStorage(this, true, "nand.bin"); + Ports[1] = mmc; } else { @@ -129,6 +133,8 @@ u16 DSi_SDHost::Read(u32 addr) case 0x020: return IRQMask & 0x031D; case 0x022: return (IRQMask >> 16) & 0x8B7F; + case 0x024: return SDClock; + case 0x0E0: return SoftReset; } @@ -150,10 +156,13 @@ void DSi_SDHost::Write(u32 addr, u16 val) DSi_SDDevice* dev = Ports[PortSelect & 0x1]; if (dev) { + // CHECKME + // "Setting Command Type to "ACMD" is automatically sending an APP_CMD prefix prior to the command number" + // except DSi boot2 manually sends an APP_CMD prefix AND sets the next command to be ACMD switch ((Command >> 6) & 0x3) { case 0: dev->SendCMD(cmd, Param); break; - case 1: dev->SendACMD(cmd, Param); break; + case 1: /*dev->SendCMD(55, 0);*/ dev->SendCMD(cmd, Param); break; default: printf("%s: unknown command type %d, %02X %08X\n", SD_DESC, (Command>>6)&0x3, cmd, Param); break; @@ -171,6 +180,8 @@ void DSi_SDHost::Write(u32 addr, u16 val) case 0x020: IRQMask = (IRQMask & 0x8B7F0000) | (val & 0x031D); return; case 0x022: IRQMask = (IRQMask & 0x0000031D) | ((val & 0x8B7F) << 16); return; + case 0x024: SDClock = val & 0x03FF; return; + case 0x0E0: if ((SoftReset & 0x0001) && !(val & 0x0001)) { @@ -200,6 +211,14 @@ DSi_MMCStorage::DSi_MMCStorage(DSi_SDHost* host, bool internal, const char* path File = Platform::OpenLocalFile(path, "r+b"); CSR = 0x00; // checkme + + // TODO: busy bit + // TODO: SDHC/SDXC bit + OCR = 0x80FF8000; + + // TODO: customize based on card size etc + u8 csd_template[16] = {0x40, 0x40, 0x96, 0xE9, 0x7F, 0xDB, 0xF6, 0xDF, 0x01, 0x59, 0x0F, 0x2A, 0x01, 0x26, 0x90, 0x00}; + memcpy(CSD, csd_template, 16); } DSi_MMCStorage::~DSi_MMCStorage() @@ -209,21 +228,76 @@ DSi_MMCStorage::~DSi_MMCStorage() void DSi_MMCStorage::SendCMD(u8 cmd, u32 param) { + if (CSR & (1<<5)) + { + CSR &= ~(1<<5); + return SendACMD(cmd, param); + } + switch (cmd) { - case 0x00: // reset/etc + case 0: // reset/etc Host->SendResponse(CSR, true); return; - case 0x08: // set voltage + case 2: + case 10: // get CID + Host->SendResponse(*(u32*)&CID[0], false); + Host->SendResponse(*(u32*)&CID[1], false); + Host->SendResponse(*(u32*)&CID[2], false); + Host->SendResponse(*(u32*)&CID[3], true); + //if (cmd == 2) SetState(0x02); + return; + + case 3: // get/set RCA + if (Internal) + { + RCA = param >> 16; + Host->SendResponse(CSR|0x10000, true); // huh?? + } + else + { + // TODO + printf("CMD3 on SD card: TODO\n"); + } + return; + + case 7: // select card (by RCA) + Host->SendResponse(CSR, true); + return; + + case 8: // set voltage Host->SendResponse(param, true); return; + + case 9: // get CSD + Host->SendResponse(*(u32*)&CSD[0], false); + Host->SendResponse(*(u32*)&CSD[1], false); + Host->SendResponse(*(u32*)&CSD[2], false); + Host->SendResponse(*(u32*)&CSD[3], true); + return; + + case 55: // ?? + printf("CMD55 %08X\n", param); + CSR |= (1<<5); + Host->SendResponse(CSR, true); + return; } - printf("MMC: unknown CMD %02X %08X\n", cmd, param); + printf("MMC: unknown CMD %d %08X\n", cmd, param); } void DSi_MMCStorage::SendACMD(u8 cmd, u32 param) { - printf("MMC: ACMD %02X %08X\n", cmd, param); + switch (cmd) + { + case 41: // set operating conditions + OCR &= 0xBF000000; + OCR |= (param & 0x40FFFFFF); + Host->SendResponse(OCR, true); + SetState(0x01); + return; + } + + printf("MMC: unknown ACMD %d %08X\n", cmd, param); } diff --git a/src/DSi_SD.h b/src/DSi_SD.h index 248755d..d223fac 100644 --- a/src/DSi_SD.h +++ b/src/DSi_SD.h @@ -42,6 +42,7 @@ private: u16 PortSelect; u16 SoftReset; + u16 SDClock; u32 IRQStatus; // IF u32 IRQMask; // ~IE @@ -63,7 +64,6 @@ public: ~DSi_SDDevice() {} virtual void SendCMD(u8 cmd, u32 param) = 0; - virtual void SendACMD(u8 cmd, u32 param) = 0; protected: DSi_SDHost* Host; @@ -76,6 +76,8 @@ public: DSi_MMCStorage(DSi_SDHost* host, bool internal, const char* path); ~DSi_MMCStorage(); + void SetCID(u8* cid) { memcpy(CID, cid, 16); } + void SendCMD(u8 cmd, u32 param); void SendACMD(u8 cmd, u32 param); @@ -84,7 +86,14 @@ private: char FilePath[1024]; FILE* File; - u8 CSR; + u8 CID[16]; + u8 CSD[16]; + + u32 CSR; + u32 OCR; + u32 RCA; + + void SetState(u32 state) { CSR &= ~(0xF << 9); CSR |= (state << 9); } }; #endif // DSI_SD_H -- cgit v1.2.3 From dc3c9f5bf8d86dfa11ecf239a28ca50f7bfe3fe6 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 18 Jun 2019 14:12:37 +0200 Subject: take all the SDMMC shit further. now it's completing MMC init and trying to read shit. --- src/DSi.h | 5 ++ src/DSi_SD.cpp | 196 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- src/DSi_SD.h | 25 ++++++++ src/NDS.h | 3 + 4 files changed, 218 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/DSi.h b/src/DSi.h index 3ebee37..efd533a 100644 --- a/src/DSi.h +++ b/src/DSi.h @@ -20,12 +20,17 @@ #define DSI_H #include "NDS.h" +#include "DSi_SD.h" namespace DSi { extern u8 eMMC_CID[16]; +extern DSi_SDHost* SDMMC; +extern DSi_SDHost* SDIO; + + bool Init(); void DeInit(); void Reset(); diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index 35859cc..76c2676 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -30,12 +30,18 @@ DSi_SDHost::DSi_SDHost(u32 num) { Num = num; + DataFIFO[0] = new FIFO(0x100); + DataFIFO[1] = new FIFO(0x100); + Ports[0] = NULL; Ports[1] = NULL; } DSi_SDHost::~DSi_SDHost() { + delete DataFIFO[0]; + delete DataFIFO[1]; + if (Ports[0]) delete Ports[0]; if (Ports[1]) delete Ports[1]; } @@ -53,14 +59,26 @@ void DSi_SDHost::Reset() SoftReset = 0x0007; // CHECKME SDClock = 0; + SDOption = 0; Command = 0; Param = 0; memset(ResponseBuffer, 0, sizeof(ResponseBuffer)); + DataFIFO[0]->Clear(); + DataFIFO[1]->Clear(); + CurFIFO = 0; + IRQStatus = 0; IRQMask = 0x8B7F031D; + DataCtl = 0; + Data32IRQ = 0; + DataMode = 0; + BlockCount16 = 0; BlockCount32 = 0; BlockCountInternal = 0; + BlockLen16 = 0; BlockLen32 = 0; + StopAction = 0; + if (Ports[0]) delete Ports[0]; if (Ports[1]) delete Ports[1]; Ports[0] = NULL; @@ -86,6 +104,11 @@ void DSi_SDHost::DoSavestate(Savestate* file) } +void DSi_SDHost::ClearIRQ(u32 irq) +{ + IRQStatus &= ~(1<CurFIFO ^= 1; + + host->ClearIRQ(25); + host->SetIRQ(24); + if (param & 0x2) host->SetIRQ(2); +} + +void DSi_SDHost::SendData(u8* data, u32 len, bool last) +{ + printf("%s: data RX, len=%d, blkcnt=%d blklen=%d, irq=%08X\n", SD_DESC, len, BlockCount16, BlockLen16, IRQMask); + if (len != BlockLen16) printf("!! BAD BLOCKLEN\n"); + + u32 f = CurFIFO ^ 1; + for (u32 i = 0; i < len; i += 2) + DataFIFO[f]->Write(*(u16*)&data[i]); + + //CurFIFO = f; + //SetIRQ(24); + // TODO: determine what the delay should be! + // for now, this is a placeholder + // we need a delay because DSi boot2 will send a command and then wait for IRQ0 + // but if IRQ24 is thrown instantly, the handler clears IRQ0 before the + // send-command function starts polling IRQ status + u32 param = Num | (last << 1); + NDS::ScheduleEvent(NDS::Event_DSi_SDTransfer, false, 512, FinishSend, param); +} + u16 DSi_SDHost::Read(u32 addr) { @@ -119,6 +173,9 @@ u16 DSi_SDHost::Read(u32 addr) case 0x004: return Param & 0xFFFF; case 0x006: return Param >> 16; + case 0x008: return StopAction; + case 0x00A: return BlockCount16; + case 0x00C: return ResponseBuffer[0]; case 0x00E: return ResponseBuffer[1]; case 0x010: return ResponseBuffer[2]; @@ -128,14 +185,70 @@ u16 DSi_SDHost::Read(u32 addr) case 0x018: return ResponseBuffer[6]; case 0x01A: return ResponseBuffer[7]; - case 0x01C: return IRQStatus & 0x031D; - case 0x01E: return (IRQStatus >> 16) & 0x8B7F; + case 0x01C: return (IRQStatus & 0x031D) | 0x0030; // TODO: adjust insert flags for SD card + case 0x01E: return ((IRQStatus >> 16) & 0x8B7F); case 0x020: return IRQMask & 0x031D; case 0x022: return (IRQMask >> 16) & 0x8B7F; case 0x024: return SDClock; + case 0x026: return BlockLen16; + case 0x028: return SDOption; + + case 0x030: // FIFO16 + { + // TODO: decrement BlockLen???? + + u32 f = CurFIFO; + if (DataFIFO[f]->IsEmpty()) + { + // TODO + return 0; + } + + DSi_SDDevice* dev = Ports[PortSelect & 0x1]; + u16 ret = DataFIFO[f]->Read(); + + if (DataFIFO[f]->IsEmpty()) + { + ClearIRQ(24); + + if (BlockCountInternal == 0) + { + printf("%s: data RX complete", SD_DESC); + + if (StopAction & (1<<8)) + { + printf(", sending CMD12"); + if (dev) dev->SendCMD(12, 0); + } + + printf("\n"); + + // CHECKME: presumably IRQ2 should not trigger here, but rather + // when the data transfer is done + //SetIRQ(0); + //SetIRQ(2); + } + else + { + BlockCountInternal--; + + if (dev) dev->ContinueTransfer(); + } + + SetIRQ(25); + } + + return ret; + } + + case 0x0D8: return DataCtl; case 0x0E0: return SoftReset; + + case 0x100: return Data32IRQ; + case 0x104: return BlockLen32; + case 0x108: return BlockCount32; } printf("unknown %s read %08X\n", SD_DESC, addr); @@ -171,32 +284,55 @@ void DSi_SDHost::Write(u32 addr, u16 val) } return; - case 0x002: PortSelect = val; return; + case 0x002: PortSelect = val; printf("%s: PORT SELECT %04X\n", SD_DESC, val); return; case 0x004: Param = (Param & 0xFFFF0000) | val; return; case 0x006: Param = (Param & 0x0000FFFF) | (val << 16); return; - case 0x01C: IRQStatus &= ~(u32)val; return; - case 0x01E: IRQStatus &= ~((u32)val << 16); return; + case 0x008: StopAction = val & 0x0101; return; + case 0x00A: BlockCount16 = val; BlockCountInternal = val; return; + + case 0x01C: IRQStatus &= (val | 0xFFFF0000); return; + case 0x01E: IRQStatus &= ((val << 16) | 0xFFFF); return; case 0x020: IRQMask = (IRQMask & 0x8B7F0000) | (val & 0x031D); return; case 0x022: IRQMask = (IRQMask & 0x0000031D) | ((val & 0x8B7F) << 16); return; case 0x024: SDClock = val & 0x03FF; return; + case 0x026: + BlockLen16 = val & 0x03FF; + if (BlockLen16 > 0x200) BlockLen16 = 0x200; + return; + case 0x028: SDOption = val & 0xC1FF; return; + + case 0x0D8: + DataCtl = (val & 0x0022); + DataMode = ((DataCtl >> 1) & 0x1) & ((Data32IRQ >> 1) & 0x1); + printf("%s: data mode %d-bit\n", SD_DESC, DataMode?32:16); + return; case 0x0E0: if ((SoftReset & 0x0001) && !(val & 0x0001)) { printf("%s: RESET\n", SD_DESC); - // TODO: STOP_INTERNAL_ACTION - // TODO: SD_RESPONSE + StopAction = 0; + memset(ResponseBuffer, 0, sizeof(ResponseBuffer)); IRQStatus = 0; // TODO: ERROR_DETAIL_STATUS - // TODO: CARD_CLK_CTL - // TODO: CARD_OPTION + SDClock &= ~0x0500; + SDOption = 0x40EE; // TODO: CARD_IRQ_STAT // TODO: FIFO16 shit } SoftReset = 0x0006 | (val & 0x0001); return; + + case 0x100: + Data32IRQ = (val & 0x1802) | (Data32IRQ & 0x0300); + if (val & (1<<10)) printf("TODO: SD/MMC: CLEAR FIFO32\n"); + DataMode = ((DataCtl >> 1) & 0x1) & ((Data32IRQ >> 1) & 0x1); + printf("%s: data mode %d-bit\n", SD_DESC, DataMode?32:16); + return; + case 0x104: BlockLen32 = val & 0x03FF; return; + case 0x108: BlockCount32 = val; return; } printf("unknown %s write %08X %04X\n", SD_DESC, addr, val); @@ -210,7 +346,7 @@ DSi_MMCStorage::DSi_MMCStorage(DSi_SDHost* host, bool internal, const char* path File = Platform::OpenLocalFile(path, "r+b"); - CSR = 0x00; // checkme + CSR = 0x00000100; // checkme // TODO: busy bit // TODO: SDHC/SDXC bit @@ -219,6 +355,12 @@ DSi_MMCStorage::DSi_MMCStorage(DSi_SDHost* host, bool internal, const char* path // TODO: customize based on card size etc u8 csd_template[16] = {0x40, 0x40, 0x96, 0xE9, 0x7F, 0xDB, 0xF6, 0xDF, 0x01, 0x59, 0x0F, 0x2A, 0x01, 0x26, 0x90, 0x00}; memcpy(CSD, csd_template, 16); + + // checkme + memset(SCR, 0, 8); + *(u32*)&SCR[0] = 0x012A0000; + + memset(SSR, 0, 64); } DSi_MMCStorage::~DSi_MMCStorage() @@ -277,8 +419,16 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param) Host->SendResponse(*(u32*)&CSD[3], true); return; + case 12: // stop operation + Host->SendResponse(CSR, true); + return; + + case 16: // set block size + BlockSize = param; + Host->SendResponse(CSR, true); + return; + case 55: // ?? - printf("CMD55 %08X\n", param); CSR |= (1<<5); Host->SendResponse(CSR, true); return; @@ -291,13 +441,37 @@ void DSi_MMCStorage::SendACMD(u8 cmd, u32 param) { switch (cmd) { + case 6: // set bus width (TODO?) + printf("SET BUS WIDTH %08X\n", param); + Host->SendResponse(CSR, true); + return; + + case 13: // get SSR + Host->SendResponse(CSR, true); + Host->SendData(SSR, 64, true); + return; + case 41: // set operating conditions OCR &= 0xBF000000; OCR |= (param & 0x40FFFFFF); Host->SendResponse(OCR, true); SetState(0x01); return; + + case 42: // ??? + Host->SendResponse(CSR, true); + return; + + case 51: // get SCR + Host->SendResponse(CSR, true); + Host->SendData(SCR, 8, true); + return; } printf("MMC: unknown ACMD %d %08X\n", cmd, param); } + +void DSi_MMCStorage::ContinueTransfer() +{ + // +} diff --git a/src/DSi_SD.h b/src/DSi_SD.h index d223fac..ae8cd11 100644 --- a/src/DSi_SD.h +++ b/src/DSi_SD.h @@ -19,6 +19,10 @@ #ifndef DSI_SD_H #define DSI_SD_H +#include +#include "FIFO.h" + + class DSi_SDDevice; @@ -32,7 +36,9 @@ public: void DoSavestate(Savestate* file); + static void FinishSend(u32 param); void SendResponse(u32 val, bool last); + void SendData(u8* data, u32 len, bool last); u16 Read(u32 addr); void Write(u32 addr, u16 val); @@ -43,16 +49,28 @@ private: u16 PortSelect; u16 SoftReset; u16 SDClock; + u16 SDOption; u32 IRQStatus; // IF u32 IRQMask; // ~IE + u16 DataCtl; + u16 Data32IRQ; + u32 DataMode; // 0=16bit 1=32bit + u16 BlockCount16, BlockCount32, BlockCountInternal; + u16 BlockLen16, BlockLen32; + u16 StopAction; + u16 Command; u32 Param; u16 ResponseBuffer[8]; + FIFO* DataFIFO[2]; + u32 CurFIFO; // FIFO accessible for read/write + DSi_SDDevice* Ports[2]; + void ClearIRQ(u32 irq); void SetIRQ(u32 irq); }; @@ -64,6 +82,7 @@ public: ~DSi_SDDevice() {} virtual void SendCMD(u8 cmd, u32 param) = 0; + virtual void ContinueTransfer() = 0; protected: DSi_SDHost* Host; @@ -81,6 +100,8 @@ public: void SendCMD(u8 cmd, u32 param); void SendACMD(u8 cmd, u32 param); + void ContinueTransfer(); + private: bool Internal; char FilePath[1024]; @@ -92,6 +113,10 @@ private: u32 CSR; u32 OCR; u32 RCA; + u8 SCR[8]; + u8 SSR[64]; + + u32 BlockSize; void SetState(u32 state) { CSR &= ~(0xF << 9); CSR |= (state << 9); } }; diff --git a/src/NDS.h b/src/NDS.h index e6cd2ee..f87ffed 100644 --- a/src/NDS.h +++ b/src/NDS.h @@ -42,6 +42,9 @@ enum Event_Div, Event_Sqrt, + // DSi + Event_DSi_SDTransfer, + Event_MAX }; -- cgit v1.2.3 From eb18643762c79a38aa3ae31d580fa71a7db1c08f Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 18 Jun 2019 18:39:13 +0200 Subject: add data32 IRQ thing --- src/DSi_SD.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- src/DSi_SD.h | 9 ++++++- 2 files changed, 86 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index 76c2676..2e16140 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -104,9 +104,29 @@ void DSi_SDHost::DoSavestate(Savestate* file) } +void DSi_SDHost::UpdateData32IRQ() +{ + if (DataMode == 0) return; + + u32 oldflags = ((Data32IRQ >> 8) & 0x1) | (((~Data32IRQ) >> 8) & 0x2); + oldflags &= (Data32IRQ >> 11); + + Data32IRQ &= ~0x0300; + if (IRQStatus & (1<<24)) Data32IRQ |= (1<<8); + if (!(IRQStatus & (1<<25))) Data32IRQ |= (1<<9); + + u32 newflags = ((Data32IRQ >> 8) & 0x1) | (((~Data32IRQ) >> 8) & 0x2); + newflags &= (Data32IRQ >> 11); + + if ((oldflags == 0) && (newflags != 0)) + NDS::SetIRQ2(Num ? NDS::IRQ2_DSi_SDIO : NDS::IRQ2_DSi_SDMMC); +} + void DSi_SDHost::ClearIRQ(u32 irq) { IRQStatus &= ~(1<SetIRQ(2); } -void DSi_SDHost::SendData(u8* data, u32 len, bool last) +void DSi_SDHost::SendData(u8* data, u32 len) { printf("%s: data RX, len=%d, blkcnt=%d blklen=%d, irq=%08X\n", SD_DESC, len, BlockCount16, BlockLen16, IRQMask); if (len != BlockLen16) printf("!! BAD BLOCKLEN\n"); + bool last = (BlockCountInternal == 0); + u32 f = CurFIFO ^ 1; for (u32 i = 0; i < len; i += 2) DataFIFO[f]->Write(*(u16*)&data[i]); @@ -255,6 +279,12 @@ u16 DSi_SDHost::Read(u32 addr) return 0; } +u32 DSi_SDHost::ReadFIFO32() +{ + // + return 0; +} + void DSi_SDHost::Write(u32 addr, u16 val) { //printf("SDMMC WRITE %08X %04X %08X\n", addr, val, NDS::GetPC(1)); @@ -289,7 +319,7 @@ void DSi_SDHost::Write(u32 addr, u16 val) case 0x006: Param = (Param & 0x0000FFFF) | (val << 16); return; case 0x008: StopAction = val & 0x0101; return; - case 0x00A: BlockCount16 = val; BlockCountInternal = val; return; + case 0x00A: BlockCount16 = val; BlockCountInternal = val; printf("%s: BLOCK COUNT %d\n", SD_DESC, val); return; case 0x01C: IRQStatus &= (val | 0xFFFF0000); return; case 0x01E: IRQStatus &= ((val << 16) | 0xFFFF); return; @@ -327,7 +357,12 @@ void DSi_SDHost::Write(u32 addr, u16 val) case 0x100: Data32IRQ = (val & 0x1802) | (Data32IRQ & 0x0300); - if (val & (1<<10)) printf("TODO: SD/MMC: CLEAR FIFO32\n"); + if (val & (1<<10)) + { + // kind of hacky + u32 f = CurFIFO; + DataFIFO[f]->Clear(); + } DataMode = ((DataCtl >> 1) & 0x1) & ((Data32IRQ >> 1) & 0x1); printf("%s: data mode %d-bit\n", SD_DESC, DataMode?32:16); return; @@ -338,6 +373,11 @@ void DSi_SDHost::Write(u32 addr, u16 val) printf("unknown %s write %08X %04X\n", SD_DESC, addr, val); } +void DSi_SDHost::WriteFIFO32(u32 val) +{ + // +} + DSi_MMCStorage::DSi_MMCStorage(DSi_SDHost* host, bool internal, const char* path) : DSi_SDDevice(host) { @@ -361,6 +401,10 @@ DSi_MMCStorage::DSi_MMCStorage(DSi_SDHost* host, bool internal, const char* path *(u32*)&SCR[0] = 0x012A0000; memset(SSR, 0, 64); + + BlockSize = 0; + RWAddress = 0; + RWCommand = 0; } DSi_MMCStorage::~DSi_MMCStorage() @@ -425,9 +469,24 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param) case 16: // set block size BlockSize = param; + if (BlockSize > 0x200) + { + // TODO! raise error + printf("!! SD/MMC: BAD BLOCK LEN %d\n", BlockSize); + BlockSize = 0x200; + } Host->SendResponse(CSR, true); return; + case 18: // read multiple blocks + printf("READ_MULTIPLE_BLOCKS addr=%08X size=%08X\n", param, BlockSize); + RWAddress = param; + RWCommand = 18; + Host->SendResponse(CSR, true); + ReadBlock(RWAddress); + RWAddress += BlockSize; + return; + case 55: // ?? CSR |= (1<<5); Host->SendResponse(CSR, true); @@ -448,7 +507,7 @@ void DSi_MMCStorage::SendACMD(u8 cmd, u32 param) case 13: // get SSR Host->SendResponse(CSR, true); - Host->SendData(SSR, 64, true); + Host->SendData(SSR, 64); return; case 41: // set operating conditions @@ -464,7 +523,7 @@ void DSi_MMCStorage::SendACMD(u8 cmd, u32 param) case 51: // get SCR Host->SendResponse(CSR, true); - Host->SendData(SCR, 8, true); + Host->SendData(SCR, 8); return; } @@ -473,5 +532,18 @@ void DSi_MMCStorage::SendACMD(u8 cmd, u32 param) void DSi_MMCStorage::ContinueTransfer() { - // + ReadBlock(RWAddress); + RWAddress += BlockSize; +} + +void DSi_MMCStorage::ReadBlock(u32 addr) +{ + if (!File) return; + + printf("SD/MMC: reading block @ %08X, len=%08X\n", addr, BlockSize); + + u8 data[0x200]; + fseek(File, addr, SEEK_SET); // TODO: adjust for SDHC/etc + fread(data, 1, BlockSize, File); + Host->SendData(data, BlockSize); } diff --git a/src/DSi_SD.h b/src/DSi_SD.h index ae8cd11..57da7df 100644 --- a/src/DSi_SD.h +++ b/src/DSi_SD.h @@ -38,10 +38,12 @@ public: static void FinishSend(u32 param); void SendResponse(u32 val, bool last); - void SendData(u8* data, u32 len, bool last); + void SendData(u8* data, u32 len); u16 Read(u32 addr); void Write(u32 addr, u16 val); + u32 ReadFIFO32(); + void WriteFIFO32(u32 val); private: u32 Num; @@ -70,6 +72,7 @@ private: DSi_SDDevice* Ports[2]; + void UpdateData32IRQ(); void ClearIRQ(u32 irq); void SetIRQ(u32 irq); }; @@ -117,8 +120,12 @@ private: u8 SSR[64]; u32 BlockSize; + u32 RWAddress; + u32 RWCommand; void SetState(u32 state) { CSR &= ~(0xF << 9); CSR |= (state << 9); } + + void ReadBlock(u32 addr); }; #endif // DSI_SD_H -- cgit v1.2.3 From 7335379127f3b39298c57b1a691f1650af31d381 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 18 Jun 2019 19:00:44 +0200 Subject: HARK HARK HARK --- melonDS.cbp | 4 ++++ src/DSi_AES.cpp | 17 +++++++++++++++++ src/DSi_AES.h | 24 ++++++++++++++++++++++++ src/DSi_NDMA.cpp | 17 +++++++++++++++++ src/DSi_NDMA.h | 24 ++++++++++++++++++++++++ 5 files changed, 86 insertions(+) create mode 100644 src/DSi_AES.cpp create mode 100644 src/DSi_AES.h create mode 100644 src/DSi_NDMA.cpp create mode 100644 src/DSi_NDMA.h (limited to 'src') diff --git a/melonDS.cbp b/melonDS.cbp index e75e02c..2346093 100644 --- a/melonDS.cbp +++ b/melonDS.cbp @@ -104,8 +104,12 @@ + + + + diff --git a/src/DSi_AES.cpp b/src/DSi_AES.cpp new file mode 100644 index 0000000..6a524dd --- /dev/null +++ b/src/DSi_AES.cpp @@ -0,0 +1,17 @@ +/* + Copyright 2016-2019 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ diff --git a/src/DSi_AES.h b/src/DSi_AES.h new file mode 100644 index 0000000..028523a --- /dev/null +++ b/src/DSi_AES.h @@ -0,0 +1,24 @@ +/* + Copyright 2016-2019 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef DSI_AES_H +#define DSI_AES_H + +// + +#endif // DSI_AES_H diff --git a/src/DSi_NDMA.cpp b/src/DSi_NDMA.cpp new file mode 100644 index 0000000..6a524dd --- /dev/null +++ b/src/DSi_NDMA.cpp @@ -0,0 +1,17 @@ +/* + Copyright 2016-2019 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ diff --git a/src/DSi_NDMA.h b/src/DSi_NDMA.h new file mode 100644 index 0000000..6661652 --- /dev/null +++ b/src/DSi_NDMA.h @@ -0,0 +1,24 @@ +/* + Copyright 2016-2019 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef DSI_NDMA_H +#define DSI_NDMA_H + +// + +#endif // DSI_NDMA_H -- cgit v1.2.3 From 841122bc51156f3f1d351c47c8ac17af7a605e56 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 18 Jun 2019 21:12:39 +0200 Subject: prevent old DMA from being a shitshow. --- src/DMA.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/DMA.cpp b/src/DMA.cpp index 51ce825..2814264 100644 --- a/src/DMA.cpp +++ b/src/DMA.cpp @@ -18,6 +18,7 @@ #include #include "NDS.h" +#include "DSi.h" #include "DMA.h" #include "NDSCart.h" #include "GPU.h" @@ -232,7 +233,8 @@ void DMA::Run9() { NDS::ARM9Timestamp += (unitcycles << NDS::ARM9ClockShift); - NDS::ARM9Write16(CurDstAddr, NDS::ARM9Read16(CurSrcAddr)); + //NDS::ARM9Write16(CurDstAddr, NDS::ARM9Read16(CurSrcAddr)); + DSi::ARM9Write16(CurDstAddr, DSi::ARM9Read16(CurSrcAddr)); CurSrcAddr += SrcAddrInc<<1; CurDstAddr += DstAddrInc<<1; @@ -268,7 +270,8 @@ void DMA::Run9() { NDS::ARM9Timestamp += (unitcycles << NDS::ARM9ClockShift); - NDS::ARM9Write32(CurDstAddr, NDS::ARM9Read32(CurSrcAddr)); + //NDS::ARM9Write32(CurDstAddr, NDS::ARM9Read32(CurSrcAddr)); + DSi::ARM9Write32(CurDstAddr, DSi::ARM9Read32(CurSrcAddr)); CurSrcAddr += SrcAddrInc<<2; CurDstAddr += DstAddrInc<<2; @@ -344,7 +347,8 @@ void DMA::Run7() { NDS::ARM7Timestamp += unitcycles; - NDS::ARM7Write16(CurDstAddr, NDS::ARM7Read16(CurSrcAddr)); + //NDS::ARM7Write16(CurDstAddr, NDS::ARM7Read16(CurSrcAddr)); + DSi::ARM7Write16(CurDstAddr, DSi::ARM7Read16(CurSrcAddr)); CurSrcAddr += SrcAddrInc<<1; CurDstAddr += DstAddrInc<<1; @@ -380,7 +384,8 @@ void DMA::Run7() { NDS::ARM7Timestamp += unitcycles; - NDS::ARM7Write32(CurDstAddr, NDS::ARM7Read32(CurSrcAddr)); + //NDS::ARM7Write32(CurDstAddr, NDS::ARM7Read32(CurSrcAddr)); + DSi::ARM7Write32(CurDstAddr, DSi::ARM7Read32(CurSrcAddr)); CurSrcAddr += SrcAddrInc<<2; CurDstAddr += DstAddrInc<<2; -- cgit v1.2.3 From d6bbc6f0f1ede57f0805137617ba670a49f7506f Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 18 Jun 2019 22:54:07 +0200 Subject: tremble upon the NDMA implementation that doesn't do much beyond getting stuck --- src/DMA.cpp | 6 -- src/DSi.cpp | 171 +++++++++++++++++++++++++++++++ src/DSi.h | 4 + src/DSi_NDMA.cpp | 301 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/DSi_NDMA.h | 74 +++++++++++++- src/NDS.cpp | 4 + src/NDS.h | 5 +- 7 files changed, 556 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/DMA.cpp b/src/DMA.cpp index 2814264..0826d7a 100644 --- a/src/DMA.cpp +++ b/src/DMA.cpp @@ -20,15 +20,9 @@ #include "NDS.h" #include "DSi.h" #include "DMA.h" -#include "NDSCart.h" #include "GPU.h" -// NOTES ON DMA SHIT -// -// * could use optimized code paths for common types of DMA transfers. for example, VRAM -// have to profile it to see if it's actually worth doing - // DMA TIMINGS // diff --git a/src/DSi.cpp b/src/DSi.cpp index abd3bd6..0c9c26c 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -25,6 +25,7 @@ #include "sha1/sha1.h" #include "Platform.h" +#include "DSi_NDMA.h" #include "DSi_I2C.h" #include "DSi_SD.h" @@ -57,6 +58,9 @@ u32 NWRAMStart[2][3]; u32 NWRAMEnd[2][3]; u32 NWRAMMask[2][3]; +u32 NDMACnt[2]; +DSi_NDMA* NDMAs[8]; + DSi_SDHost* SDMMC; DSi_SDHost* SDIO; @@ -68,6 +72,15 @@ bool Init() { if (!DSi_I2C::Init()) return false; + NDMAs[0] = new DSi_NDMA(0, 0); + NDMAs[1] = new DSi_NDMA(0, 1); + NDMAs[2] = new DSi_NDMA(0, 2); + NDMAs[3] = new DSi_NDMA(0, 3); + NDMAs[4] = new DSi_NDMA(1, 0); + NDMAs[5] = new DSi_NDMA(1, 1); + NDMAs[6] = new DSi_NDMA(1, 2); + NDMAs[7] = new DSi_NDMA(1, 3); + SDMMC = new DSi_SDHost(0); SDIO = new DSi_SDHost(1); @@ -78,6 +91,8 @@ void DeInit() { DSi_I2C::DeInit(); + for (int i = 0; i < 8; i++) delete NDMAs[i]; + delete SDMMC; delete SDIO; } @@ -91,6 +106,9 @@ void Reset() NDS::ARM9->JumpTo(BootAddr[0]); NDS::ARM7->JumpTo(BootAddr[1]); + NDMACnt[0] = 0; NDMACnt[1] = 0; + for (int i = 0; i < 8; i++) NDMAs[i]->Reset(); + DSi_I2C::Reset(); SDMMC->Reset(); @@ -279,6 +297,40 @@ bool LoadNAND() } +void RunNDMAs(u32 cpu) +{ + // TODO: round-robin mode (requires DMA channels to have a subblock delay set) + + if (cpu == 0) + { + if (NDS::ARM9Timestamp >= NDS::ARM9Target) return; + + // + } + else + { + if (NDS::ARM7Timestamp >= NDS::ARM7Target) return; + + // + } +} + +void StallNDMAs() +{ + // TODO +} + +bool NDMAsRunning(u32 cpu) +{ + cpu <<= 2; + if (NDMAs[cpu+0]->IsRunning()) return true; + if (NDMAs[cpu+1]->IsRunning()) return true; + if (NDMAs[cpu+2]->IsRunning()) return true; + if (NDMAs[cpu+3]->IsRunning()) return true; + return false; +} + + // new WRAM mapping // TODO: find out what happens upon overlapping slots!! @@ -872,6 +924,36 @@ u32 ARM9IORead32(u32 addr) switch (addr) { case 0x04004010: return 1; // todo + + case 0x04004100: return NDMACnt[0]; + case 0x04004104: return NDMAs[0]->SrcAddr; + case 0x04004108: return NDMAs[0]->DstAddr; + case 0x0400410C: return NDMAs[0]->TotalLength; + case 0x04004110: return NDMAs[0]->BlockLength; + case 0x04004114: return NDMAs[0]->SubblockTimer; + case 0x04004118: return NDMAs[0]->FillData; + case 0x0400411C: return NDMAs[0]->Cnt; + case 0x04004120: return NDMAs[1]->SrcAddr; + case 0x04004124: return NDMAs[1]->DstAddr; + case 0x04004128: return NDMAs[1]->TotalLength; + case 0x0400412C: return NDMAs[1]->BlockLength; + case 0x04004130: return NDMAs[1]->SubblockTimer; + case 0x04004134: return NDMAs[1]->FillData; + case 0x04004138: return NDMAs[1]->Cnt; + case 0x0400413C: return NDMAs[2]->SrcAddr; + case 0x04004140: return NDMAs[2]->DstAddr; + case 0x04004144: return NDMAs[2]->TotalLength; + case 0x04004148: return NDMAs[2]->BlockLength; + case 0x0400414C: return NDMAs[2]->SubblockTimer; + case 0x04004150: return NDMAs[2]->FillData; + case 0x04004154: return NDMAs[2]->Cnt; + case 0x04004158: return NDMAs[3]->SrcAddr; + case 0x0400415C: return NDMAs[3]->DstAddr; + case 0x04004160: return NDMAs[3]->TotalLength; + case 0x04004164: return NDMAs[3]->BlockLength; + case 0x04004168: return NDMAs[3]->SubblockTimer; + case 0x0400416C: return NDMAs[3]->FillData; + case 0x04004170: return NDMAs[3]->Cnt; } return NDS::ARM9IORead32(addr); @@ -899,6 +981,35 @@ void ARM9IOWrite32(u32 addr, u32 val) { switch (addr) { + case 0x04004100: NDMACnt[0] = val & 0x800F0000; return; + case 0x04004104: NDMAs[0]->SrcAddr = val & 0xFFFFFFFC; return; + case 0x04004108: NDMAs[0]->DstAddr = val & 0xFFFFFFFC; return; + case 0x0400410C: NDMAs[0]->TotalLength = val & 0x0FFFFFFF; return; + case 0x04004110: NDMAs[0]->BlockLength = val & 0x00FFFFFF; return; + case 0x04004114: NDMAs[0]->SubblockTimer = val & 0x0003FFFF; return; + case 0x04004118: NDMAs[0]->FillData = val; return; + case 0x0400411C: NDMAs[0]->WriteCnt(val); return; + case 0x04004120: NDMAs[1]->SrcAddr = val & 0xFFFFFFFC; return; + case 0x04004124: NDMAs[1]->DstAddr = val & 0xFFFFFFFC; return; + case 0x04004128: NDMAs[1]->TotalLength = val & 0x0FFFFFFF; return; + case 0x0400412C: NDMAs[1]->BlockLength = val & 0x00FFFFFF; return; + case 0x04004130: NDMAs[1]->SubblockTimer = val & 0x0003FFFF; return; + case 0x04004134: NDMAs[1]->FillData = val; return; + case 0x04004138: NDMAs[1]->WriteCnt(val); return; + case 0x0400413C: NDMAs[2]->SrcAddr = val & 0xFFFFFFFC; return; + case 0x04004140: NDMAs[2]->DstAddr = val & 0xFFFFFFFC; return; + case 0x04004144: NDMAs[2]->TotalLength = val & 0x0FFFFFFF; return; + case 0x04004148: NDMAs[2]->BlockLength = val & 0x00FFFFFF; return; + case 0x0400414C: NDMAs[2]->SubblockTimer = val & 0x0003FFFF; return; + case 0x04004150: NDMAs[2]->FillData = val; return; + case 0x04004154: NDMAs[2]->WriteCnt(val); return; + case 0x04004158: NDMAs[3]->SrcAddr = val & 0xFFFFFFFC; return; + case 0x0400415C: NDMAs[3]->DstAddr = val & 0xFFFFFFFC; return; + case 0x04004160: NDMAs[3]->TotalLength = val & 0x0FFFFFFF; return; + case 0x04004164: NDMAs[3]->BlockLength = val & 0x00FFFFFF; return; + case 0x04004168: NDMAs[3]->SubblockTimer = val & 0x0003FFFF; return; + case 0x0400416C: NDMAs[3]->FillData = val; return; + case 0x04004170: NDMAs[3]->WriteCnt(val); return; } return NDS::ARM9IOWrite32(addr, val); @@ -950,6 +1061,36 @@ u32 ARM7IORead32(u32 addr) case 0x0400021C: return NDS::IF2; case 0x04004008: return 0x80000000; // HAX + + case 0x04004100: return NDMACnt[1]; + case 0x04004104: return NDMAs[4]->SrcAddr; + case 0x04004108: return NDMAs[4]->DstAddr; + case 0x0400410C: return NDMAs[4]->TotalLength; + case 0x04004110: return NDMAs[4]->BlockLength; + case 0x04004114: return NDMAs[4]->SubblockTimer; + case 0x04004118: return NDMAs[4]->FillData; + case 0x0400411C: return NDMAs[4]->Cnt; + case 0x04004120: return NDMAs[5]->SrcAddr; + case 0x04004124: return NDMAs[5]->DstAddr; + case 0x04004128: return NDMAs[5]->TotalLength; + case 0x0400412C: return NDMAs[5]->BlockLength; + case 0x04004130: return NDMAs[5]->SubblockTimer; + case 0x04004134: return NDMAs[5]->FillData; + case 0x04004138: return NDMAs[5]->Cnt; + case 0x0400413C: return NDMAs[6]->SrcAddr; + case 0x04004140: return NDMAs[6]->DstAddr; + case 0x04004144: return NDMAs[6]->TotalLength; + case 0x04004148: return NDMAs[6]->BlockLength; + case 0x0400414C: return NDMAs[6]->SubblockTimer; + case 0x04004150: return NDMAs[6]->FillData; + case 0x04004154: return NDMAs[6]->Cnt; + case 0x04004158: return NDMAs[7]->SrcAddr; + case 0x0400415C: return NDMAs[7]->DstAddr; + case 0x04004160: return NDMAs[7]->TotalLength; + case 0x04004164: return NDMAs[7]->BlockLength; + case 0x04004168: return NDMAs[7]->SubblockTimer; + case 0x0400416C: return NDMAs[7]->FillData; + case 0x04004170: return NDMAs[7]->Cnt; } if (addr >= 0x04004800 && addr < 0x04004A00) @@ -1003,6 +1144,36 @@ void ARM7IOWrite32(u32 addr, u32 val) { case 0x04000218: NDS::IE2 = (val & 0x7FF7); NDS::UpdateIRQ(1); return; case 0x0400021C: NDS::IF2 &= ~(val & 0x7FF7); NDS::UpdateIRQ(1); return; + + case 0x04004100: NDMACnt[1] = val & 0x800F0000; return; + case 0x04004104: NDMAs[4]->SrcAddr = val & 0xFFFFFFFC; return; + case 0x04004108: NDMAs[4]->DstAddr = val & 0xFFFFFFFC; return; + case 0x0400410C: NDMAs[4]->TotalLength = val & 0x0FFFFFFF; return; + case 0x04004110: NDMAs[4]->BlockLength = val & 0x00FFFFFF; return; + case 0x04004114: NDMAs[4]->SubblockTimer = val & 0x0003FFFF; return; + case 0x04004118: NDMAs[4]->FillData = val; return; + case 0x0400411C: NDMAs[4]->WriteCnt(val); return; + case 0x04004120: NDMAs[5]->SrcAddr = val & 0xFFFFFFFC; return; + case 0x04004124: NDMAs[5]->DstAddr = val & 0xFFFFFFFC; return; + case 0x04004128: NDMAs[5]->TotalLength = val & 0x0FFFFFFF; return; + case 0x0400412C: NDMAs[5]->BlockLength = val & 0x00FFFFFF; return; + case 0x04004130: NDMAs[5]->SubblockTimer = val & 0x0003FFFF; return; + case 0x04004134: NDMAs[5]->FillData = val; return; + case 0x04004138: NDMAs[5]->WriteCnt(val); return; + case 0x0400413C: NDMAs[6]->SrcAddr = val & 0xFFFFFFFC; return; + case 0x04004140: NDMAs[6]->DstAddr = val & 0xFFFFFFFC; return; + case 0x04004144: NDMAs[6]->TotalLength = val & 0x0FFFFFFF; return; + case 0x04004148: NDMAs[6]->BlockLength = val & 0x00FFFFFF; return; + case 0x0400414C: NDMAs[6]->SubblockTimer = val & 0x0003FFFF; return; + case 0x04004150: NDMAs[6]->FillData = val; return; + case 0x04004154: NDMAs[6]->WriteCnt(val); return; + case 0x04004158: NDMAs[7]->SrcAddr = val & 0xFFFFFFFC; return; + case 0x0400415C: NDMAs[7]->DstAddr = val & 0xFFFFFFFC; return; + case 0x04004160: NDMAs[7]->TotalLength = val & 0x0FFFFFFF; return; + case 0x04004164: NDMAs[7]->BlockLength = val & 0x00FFFFFF; return; + case 0x04004168: NDMAs[7]->SubblockTimer = val & 0x0003FFFF; return; + case 0x0400416C: NDMAs[7]->FillData = val; return; + case 0x04004170: NDMAs[7]->WriteCnt(val); return; } if (addr >= 0x04004800 && addr < 0x04004A00) diff --git a/src/DSi.h b/src/DSi.h index efd533a..32253a7 100644 --- a/src/DSi.h +++ b/src/DSi.h @@ -38,6 +38,10 @@ void Reset(); bool LoadBIOS(); bool LoadNAND(); +void RunNDMAs(u32 cpu); +void StallNDMAs(); +bool NDMAsRunning(u32 cpu); + void MapNWRAM_A(u32 num, u8 val); void MapNWRAM_B(u32 num, u8 val); void MapNWRAM_C(u32 num, u8 val); diff --git a/src/DSi_NDMA.cpp b/src/DSi_NDMA.cpp index 6a524dd..a8055eb 100644 --- a/src/DSi_NDMA.cpp +++ b/src/DSi_NDMA.cpp @@ -15,3 +15,304 @@ You should have received a copy of the GNU General Public License along with melonDS. If not, see http://www.gnu.org/licenses/. */ + +#include +#include "NDS.h" +#include "DSi.h" +#include "DSi_NDMA.h" +#include "GPU.h" + + + +DSi_NDMA::DSi_NDMA(u32 cpu, u32 num) +{ + CPU = cpu; + Num = num; + + Reset(); +} + +DSi_NDMA::~DSi_NDMA() +{ +} + +void DSi_NDMA::Reset() +{ + SrcAddr = 0; + DstAddr = 0; + TotalLength = 0; + BlockLength = 0; + SubblockTimer = 0; + FillData = 0; + Cnt = 0; + + StartMode = 0; + CurSrcAddr = 0; + CurDstAddr = 0; + SubblockLength = 0; + RemCount = 0; + IterCount = 0; + TotalRemCount = 0; + SrcAddrInc = 0; + DstAddrInc = 0; + + Running = false; + InProgress = false; +} + +void DSi_NDMA::DoSavestate(Savestate* file) +{ + // TODO! +} + +void DSi_NDMA::WriteCnt(u32 val) +{ + u32 oldcnt = Cnt; + Cnt = val; + + if ((!(oldcnt & 0x80000000)) && (val & 0x80000000)) // checkme + { + CurSrcAddr = SrcAddr; + CurDstAddr = DstAddr; + TotalRemCount = TotalLength; + + switch ((Cnt >> 10) & 0x3) + { + case 0: DstAddrInc = 1; break; + case 1: DstAddrInc = -1; break; + case 2: DstAddrInc = 0; break; + case 3: DstAddrInc = 1; printf("BAD NDMA DST INC MODE 3\n"); break; + } + + switch ((Cnt >> 13) & 0x3) + { + case 0: SrcAddrInc = 1; break; + case 1: SrcAddrInc = -1; break; + case 2: SrcAddrInc = 0; break; + case 3: SrcAddrInc = 0; break; // fill mode + } + + StartMode = (Cnt >> 24) & 0x1F; + if (StartMode > 0x10) StartMode = 0x10; + if (CPU == 1) StartMode |= 0x20; + + if ((StartMode & 0x1F) == 0x10) + Start(); + + if (StartMode != 0x10 && StartMode != 0x30) + printf("UNIMPLEMENTED ARM%d NDMA%d START MODE %02X, %08X->%08X\n", CPU?7:9, Num, StartMode, SrcAddr, DstAddr); + } +} + +void DSi_NDMA::Start() +{ + if (Running) return; + + if (!InProgress) + { + RemCount = BlockLength; + if (!RemCount) + RemCount = 0x1000000; + } + + // TODO: how does GXFIFO DMA work with all the block shito? + IterCount = RemCount; + + if (IterCount > TotalRemCount) + IterCount = TotalRemCount; + + if (Cnt & (1<<12)) CurDstAddr = DstAddr; + if (Cnt & (1<<15)) CurSrcAddr = SrcAddr; + + printf("ARM%d NDMA%d %08X %02X %08X->%08X %d bytes\n", CPU?7:9, Num, Cnt, StartMode, CurSrcAddr, CurDstAddr, RemCount*4); + + //IsGXFIFODMA = (CPU == 0 && (CurSrcAddr>>24) == 0x02 && CurDstAddr == 0x04000400 && DstAddrInc == 0); + + // TODO eventually: not stop if we're running code in ITCM + + if (SubblockTimer & 0xFFFF) + printf("TODO! NDMA SUBBLOCK TIMER: %08X\n", SubblockTimer); + + if (NDS::DMAsRunning(CPU)) + Running = 1; + else + Running = 2; + + InProgress = true; + NDS::StopCPU(CPU, 1<<(Num+4)); +} + +void DSi_NDMA::Run() +{ + if (!Running) return; + if (CPU == 0) return Run9(); + else return Run7(); +} + +void DSi_NDMA::Run9() +{ + if (NDS::ARM9Timestamp >= NDS::ARM9Target) return; + + Executing = true; + + // add NS penalty for first accesses in burst + bool burststart = (Running == 2); + Running = 1; + + s32 unitcycles; + //s32 lastcycles = cycles; + + bool dofill = ((Cnt >> 13) & 0x3) == 3; + + if ((CurSrcAddr >> 24) == 0x02 && (CurDstAddr >> 24) == 0x02) + { + unitcycles = NDS::ARM9MemTimings[CurSrcAddr >> 14][2] + NDS::ARM9MemTimings[CurDstAddr >> 14][2]; + } + else + { + unitcycles = NDS::ARM9MemTimings[CurSrcAddr >> 14][3] + NDS::ARM9MemTimings[CurDstAddr >> 14][3]; + if ((CurSrcAddr >> 24) == (CurDstAddr >> 24)) + unitcycles++; + else if ((CurSrcAddr >> 24) == 0x02) + unitcycles--; + + /*if (burststart) + { + cycles -= 2; + cycles -= (NDS::ARM9MemTimings[CurSrcAddr >> 14][2] + NDS::ARM9MemTimings[CurDstAddr >> 14][2]); + cycles += unitcycles; + }*/ + } + + while (IterCount > 0 && !Stall) + { + NDS::ARM9Timestamp += (unitcycles << NDS::ARM9ClockShift); + + if (dofill) + DSi::ARM9Write32(CurDstAddr, FillData); + else + DSi::ARM9Write32(CurDstAddr, DSi::ARM9Read32(CurSrcAddr)); + + CurSrcAddr += SrcAddrInc<<2; + CurDstAddr += DstAddrInc<<2; + IterCount--; + RemCount--; + TotalRemCount--; + + if (NDS::ARM9Timestamp >= NDS::ARM9Target) break; + } + + Executing = false; + Stall = false; + + if (RemCount) + { + if (IterCount == 0) + { + Running = 0; + NDS::ResumeCPU(0, 1<<(Num+4)); + + //if (StartMode == 0x07) + // GPU3D::CheckFIFODMA(); + } + + return; + } + + if ((StartMode & 0x1F) == 0x10) // CHECKME + Cnt &= ~(1<<31); + else if (!(Cnt & (1<<29))) + { + if (TotalRemCount == 0) + Cnt &= ~(1<<31); + } + + if (Cnt & (1<<30)) + NDS::SetIRQ(0, NDS::IRQ_DSi_NDMA0 + Num); + + Running = 0; + InProgress = false; + NDS::ResumeCPU(0, 1<<(Num+4)); +} + +void DSi_NDMA::Run7() +{ + if (NDS::ARM7Timestamp >= NDS::ARM7Target) return; + + Executing = true; + + // add NS penalty for first accesses in burst + bool burststart = (Running == 2); + Running = 1; + + s32 unitcycles; + //s32 lastcycles = cycles; + + bool dofill = ((Cnt >> 13) & 0x3) == 3; + + if ((CurSrcAddr >> 24) == 0x02 && (CurDstAddr >> 24) == 0x02) + { + unitcycles = NDS::ARM7MemTimings[CurSrcAddr >> 15][2] + NDS::ARM7MemTimings[CurDstAddr >> 15][2]; + } + else + { + unitcycles = NDS::ARM7MemTimings[CurSrcAddr >> 15][3] + NDS::ARM7MemTimings[CurDstAddr >> 15][3]; + if ((CurSrcAddr >> 23) == (CurDstAddr >> 23)) + unitcycles++; + else if ((CurSrcAddr >> 24) == 0x02) + unitcycles--; + + /*if (burststart) + { + cycles -= 2; + cycles -= (NDS::ARM7MemTimings[CurSrcAddr >> 15][2] + NDS::ARM7MemTimings[CurDstAddr >> 15][2]); + cycles += unitcycles; + }*/ + } + + while (IterCount > 0 && !Stall) + { + NDS::ARM7Timestamp += unitcycles; + + if (dofill) + DSi::ARM7Write32(CurDstAddr, FillData); + else + DSi::ARM7Write32(CurDstAddr, DSi::ARM7Read32(CurSrcAddr)); + + CurSrcAddr += SrcAddrInc<<2; + CurDstAddr += DstAddrInc<<2; + IterCount--; + RemCount--; + + if (NDS::ARM7Timestamp >= NDS::ARM7Target) break; + } + + Executing = false; + Stall = false; + + if (RemCount) + { + if (IterCount == 0) + { + Running = 0; + NDS::ResumeCPU(1, 1<<(Num+4)); + } + + return; + } + + if ((StartMode & 0x1F) == 0x10) // CHECKME + Cnt &= ~(1<<31); + else if (!(Cnt & (1<<29))) + { + if (TotalRemCount == 0) + Cnt &= ~(1<<31); + } + + if (Cnt & (1<<30)) + NDS::SetIRQ(1, NDS::IRQ_DSi_NDMA0 + Num); + + Running = 0; + InProgress = false; + NDS::ResumeCPU(1, 1<<(Num+4)); +} diff --git a/src/DSi_NDMA.h b/src/DSi_NDMA.h index 6661652..d7b7483 100644 --- a/src/DSi_NDMA.h +++ b/src/DSi_NDMA.h @@ -19,6 +19,78 @@ #ifndef DSI_NDMA_H #define DSI_NDMA_H -// +#include "types.h" + +class DSi_NDMA +{ +public: + DSi_NDMA(u32 cpu, u32 num); + ~DSi_NDMA(); + + void Reset(); + + void DoSavestate(Savestate* file); + + void WriteCnt(u32 val); + void Start(); + + void Run(); + + void Run9(); + void Run7(); + + bool IsInMode(u32 mode) + { + return ((mode == StartMode) && (Cnt & 0x80000000)); + } + + bool IsRunning() { return Running!=0; } + + void StartIfNeeded(u32 mode) + { + if ((mode == StartMode) && (Cnt & 0x80000000)) + Start(); + } + + void StopIfNeeded(u32 mode) + { + if (mode == StartMode) + Cnt &= ~0x80000000; + } + + void StallIfRunning() + { + if (Executing) Stall = true; + } + + u32 SrcAddr; + u32 DstAddr; + u32 TotalLength; // total length, when transferring multiple blocks + u32 BlockLength; // length of one transfer + u32 SubblockTimer; // optional delay between subblocks (only in round-robin mode) + u32 FillData; + u32 Cnt; + +private: + u32 CPU, Num; + + u32 StartMode; + u32 CurSrcAddr; + u32 CurDstAddr; + u32 SubblockLength; // length transferred per run when delay is used + u32 RemCount; + u32 IterCount; + u32 TotalRemCount; + u32 SrcAddrInc; + u32 DstAddrInc; + + u32 Running; + bool InProgress; + + bool Executing; + bool Stall; + + bool IsGXFIFODMA; +}; #endif // DSI_NDMA_H diff --git a/src/NDS.cpp b/src/NDS.cpp index 414f87c..e20f62f 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -827,6 +827,7 @@ u32 RunFrame() if (!(CPUStop & 0x80000000)) DMAs[1]->Run(); if (!(CPUStop & 0x80000000)) DMAs[2]->Run(); if (!(CPUStop & 0x80000000)) DMAs[3]->Run(); + DSi::RunNDMAs(0); } else { @@ -849,6 +850,7 @@ u32 RunFrame() DMAs[5]->Run(); DMAs[6]->Run(); DMAs[7]->Run(); + DSi::RunNDMAs(1); } else { @@ -1153,6 +1155,7 @@ void GXFIFOStall() DMAs[1]->StallIfRunning(); DMAs[2]->StallIfRunning(); DMAs[3]->StallIfRunning(); + DSi::StallNDMAs(); } } @@ -1367,6 +1370,7 @@ bool DMAsRunning(u32 cpu) if (DMAs[cpu+1]->IsRunning()) return true; if (DMAs[cpu+2]->IsRunning()) return true; if (DMAs[cpu+3]->IsRunning()) return true; + if (DSi::NDMAsRunning(cpu>>2)) return true; return false; } diff --git a/src/NDS.h b/src/NDS.h index f87ffed..850e829 100644 --- a/src/NDS.h +++ b/src/NDS.h @@ -101,7 +101,7 @@ enum IRQ2_DSi_GPIO18_0 = 0, IRQ2_DSi_GPIO18_1, IRQ2_DSi_GPIO18_2, - IRQ2_DSi_Unused35, + IRQ2_DSi_Unused3, IRQ2_DSi_GPIO33_0, IRQ2_DSi_Headphone, IRQ2_DSi_PowerButton, @@ -138,7 +138,6 @@ extern u64 ARM9Timestamp, ARM9Target; extern u64 ARM7Timestamp, ARM7Target; extern u32 ARM9ClockShift; -// hax extern u32 IME[2]; extern u32 IE[2]; extern u32 IF[2]; @@ -146,6 +145,8 @@ extern u32 IE2; extern u32 IF2; extern Timer Timers[8]; +extern u32 CPUStop; + extern u16 PowerControl9; extern u16 ExMemCnt[2]; -- cgit v1.2.3 From 606a40e6b8f05bbc13d08e6e68fcf477c9a4a0e7 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 18 Jun 2019 22:57:37 +0200 Subject: y'know, actually running the DMA units might yield better results. --- src/ARM.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/DSi.cpp | 10 ++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ARM.cpp b/src/ARM.cpp index b7fe3c7..60dec9a 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -239,6 +239,36 @@ void ARMv4::JumpTo(u32 addr, bool restorecpsr) else addr &= ~0x1; } + /*if (addr==0x037D4668) printf("MYSTERY START\n"); + if (addr==0x037CA71C) printf("MYSTERY END\n"); + if (addr==0x037CCD68) printf("atomic_store %08X %08X, %08X\n", R[0], R[1], R[15]); + if (addr==0x037CDD00) printf("zog %08X\n", R[15]);*/ + /*if (addr==0x037CDC00) printf("sendcmd %08X %08X\n", R[0], R[15]); + if (addr==0x037CA700) printf("prepare CID, %08X\n", R[15]); + if(addr==0x037D4498) printf("READ SHITTY FIFO. %08X\n", R[15]); + if (addr==0x037CCD68) printf("atomic_store %08X %08X, %08X\n", R[0], R[1], R[15]); + if (addr>=0x037CEE00 && addr<=0x037CEE30) printf("shitty loop: %08X->%08X\n", R[15], addr); + if (R[15]==0x037CCD8C) printf("BERG!!! %08X\n", addr); + if (addr==0x037CD600) printf("XFER IRQ HANDLER\n"); + if (R[15]==0x037CD62C) printf("TERRIBLE HANDLER: %08X\n", addr); + if (addr==0x037CCE24) printf("SD IRQ HANDLER\n"); + if (addr==0x037CCD94) printf("atomic_load %08X %08X, %08X\n", R[0], R[1], R[15]); + if (addr==0x037CEB7C) printf("CHECK CSR RESULT. %08X %08X %08X, %08X\n", R[0], R[1], R[2], R[15]); + if (R[15]==0x037CEC6C) printf("RETURN FROM CSR CHECK: %08X %08X\n", R[0], R[3]+0x38); + if (addr==0x037CB2AC) printf("ZOG!\n"); + if (addr==0x037CB2A0) printf("GONP %08X %08X, %08X\n", R[1]+0x28, R[3]+0x34, R[15]); + if (addr==0x037CCFC0) printf("SDMMC TIMEOUT. %08X\n", R[15]); + if (addr==0x037D68A8) printf("BARKBARKBARK. %08X\n", R[15]); + if (addr==0x037CCF04) printf("BAKAAA\n"); + if (addr==0x037D6988) printf("MORPMORPMORPMORPMORPMORPMORPMORPMORP %08X\n", R[15]); + if (addr==0x37D6904) printf("TIMEOUT FARTORED! %08X, %08X %08X, %08X\n", R[4], R[3], R[12], R[15]); + // TIMEOUT FARTORED! 037E89B8, 00000000 00200BFB, 037D68FC + if (addr==0x037CD660) printf("BRAAAAAAAAAAAP %08X\n", R[15]); + if (addr==0x037CD798) printf("BRAAPP SHATORED. %08X, %08X %08X\n", R[0], R[1], R[2]); + if (addr==0x037CCD34) printf("atomic_and %08X %08X, %08X\n", R[0], R[1], R[15]);*/ + // atomic_and 0400481C 0000FFE7, 037CD850 + + u32 oldregion = R[15] >> 23; u32 newregion = addr >> 23; @@ -577,6 +607,13 @@ void ARMv4::Execute() } else AddCycles_C(); + + /*if (R[15]==0x037CEE18) printf("SHITTY POINTER = %08X\n", R[0]+0x34); + if (R[15]==0x037CEE1C) printf("SHITTY FLAG = %08X\n", R[0]); + if (R[15]==0x037D68F0) printf("TIMESTAMP THING = %08X:%08X, CUR=%08X:%08X, ptr=%08X\n", + R[3], R[12], R[1], R[0], R[4]); + //if (R[15]==0x037CB29C) printf("GLORG!!! %08X\n", R[3]+0x34); 037E8A8C + if (R[15]==0x037CD730) printf("COUNT OF SHITO. %08X %08X\n", R[0], R[2]);*/ } // TODO optimize this shit!!! diff --git a/src/DSi.cpp b/src/DSi.cpp index 0c9c26c..e6e3c5a 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -305,13 +305,19 @@ void RunNDMAs(u32 cpu) { if (NDS::ARM9Timestamp >= NDS::ARM9Target) return; - // + if (!(NDS::CPUStop & 0x80000000)) NDMAs[0]->Run(); + if (!(NDS::CPUStop & 0x80000000)) NDMAs[1]->Run(); + if (!(NDS::CPUStop & 0x80000000)) NDMAs[2]->Run(); + if (!(NDS::CPUStop & 0x80000000)) NDMAs[3]->Run(); } else { if (NDS::ARM7Timestamp >= NDS::ARM7Target) return; - // + NDMAs[4]->Run(); + NDMAs[5]->Run(); + NDMAs[6]->Run(); + NDMAs[7]->Run(); } } -- cgit v1.2.3 From b1ed835ae91d9bb507d4d7b2084bbcdcce729e2d Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 18 Jun 2019 23:05:36 +0200 Subject: might be more impressive if it actually worked, like this --- src/DSi_NDMA.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/DSi_NDMA.cpp b/src/DSi_NDMA.cpp index a8055eb..7c0b2a1 100644 --- a/src/DSi_NDMA.cpp +++ b/src/DSi_NDMA.cpp @@ -118,13 +118,16 @@ void DSi_NDMA::Start() // TODO: how does GXFIFO DMA work with all the block shito? IterCount = RemCount; - if (IterCount > TotalRemCount) - IterCount = TotalRemCount; + if (((StartMode & 0x1F) != 0x10) && !(Cnt & (1<<29))) + { + if (IterCount > TotalRemCount) + IterCount = TotalRemCount; + } if (Cnt & (1<<12)) CurDstAddr = DstAddr; if (Cnt & (1<<15)) CurSrcAddr = SrcAddr; - printf("ARM%d NDMA%d %08X %02X %08X->%08X %d bytes\n", CPU?7:9, Num, Cnt, StartMode, CurSrcAddr, CurDstAddr, RemCount*4); + printf("ARM%d NDMA%d %08X %02X %08X->%08X %d bytes, total=%d\n", CPU?7:9, Num, Cnt, StartMode, CurSrcAddr, CurDstAddr, RemCount*4, TotalRemCount*4); //IsGXFIFODMA = (CPU == 0 && (CurSrcAddr>>24) == 0x02 && CurDstAddr == 0x04000400 && DstAddrInc == 0); -- cgit v1.2.3 From f0131cfac9fc82dd0e1a74ba06f840a0b26d8966 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 18 Jun 2019 23:10:55 +0200 Subject: plug it to the SD/MMC FIFO. now half the shit is done. --- src/DSi.cpp | 4 ++++ src/DSi_SD.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index e6e3c5a..fc590e1 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -1101,10 +1101,12 @@ u32 ARM7IORead32(u32 addr) if (addr >= 0x04004800 && addr < 0x04004A00) { + if (addr == 0x0400490C) return SDMMC->ReadFIFO32(); return SDMMC->Read(addr) | (SDMMC->Read(addr+2) << 16); } if (addr >= 0x04004A00 && addr < 0x04004C00) { + if (addr == 0x04004B0C) return SDIO->ReadFIFO32(); return SDIO->Read(addr) | (SDIO->Read(addr+2) << 16); } @@ -1184,12 +1186,14 @@ void ARM7IOWrite32(u32 addr, u32 val) if (addr >= 0x04004800 && addr < 0x04004A00) { + if (addr == 0x0400490C) { SDMMC->WriteFIFO32(val); return; } SDMMC->Write(addr, val & 0xFFFF); SDMMC->Write(addr+2, val >> 16); return; } if (addr >= 0x04004A00 && addr < 0x04004C00) { + if (addr == 0x04004B0C) { SDIO->WriteFIFO32(val); return; } SDIO->Write(addr, val & 0xFFFF); SDIO->Write(addr+2, val >> 16); return; diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index 2e16140..42b515c 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -281,8 +281,53 @@ u16 DSi_SDHost::Read(u32 addr) u32 DSi_SDHost::ReadFIFO32() { - // - return 0; + if (DataMode != 1) return 0; + + // TODO: decrement BlockLen???? + + u32 f = CurFIFO; + if (DataFIFO[f]->IsEmpty()) + { + // TODO + return 0; + } + + DSi_SDDevice* dev = Ports[PortSelect & 0x1]; + u32 ret = DataFIFO[f]->Read(); + ret |= (DataFIFO[f]->Read() << 16); + + if (DataFIFO[f]->IsEmpty()) + { + ClearIRQ(24); + + if (BlockCountInternal == 0) + { + printf("%s: data32 RX complete", SD_DESC); + + if (StopAction & (1<<8)) + { + printf(", sending CMD12"); + if (dev) dev->SendCMD(12, 0); + } + + printf("\n"); + + // CHECKME: presumably IRQ2 should not trigger here, but rather + // when the data transfer is done + //SetIRQ(0); + //SetIRQ(2); + } + else + { + BlockCountInternal--; + + if (dev) dev->ContinueTransfer(); + } + + SetIRQ(25); + } + + return ret; } void DSi_SDHost::Write(u32 addr, u16 val) -- cgit v1.2.3 From 81dde71ebac19cf9a68dd7a2a41561cbcbfacc68 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 19 Jun 2019 14:24:49 +0200 Subject: add AES, fix a bunch of bugs we're getting an error screen! wee --- src/ARM.cpp | 37 ------- src/DSi.cpp | 55 ++++++++++ src/DSi.h | 3 + src/DSi_AES.cpp | 303 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/DSi_AES.h | 26 ++++- src/DSi_NDMA.cpp | 21 ++-- src/DSi_SD.cpp | 21 ++-- src/NDS.cpp | 6 +- 8 files changed, 416 insertions(+), 56 deletions(-) (limited to 'src') diff --git a/src/ARM.cpp b/src/ARM.cpp index 60dec9a..b7fe3c7 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -239,36 +239,6 @@ void ARMv4::JumpTo(u32 addr, bool restorecpsr) else addr &= ~0x1; } - /*if (addr==0x037D4668) printf("MYSTERY START\n"); - if (addr==0x037CA71C) printf("MYSTERY END\n"); - if (addr==0x037CCD68) printf("atomic_store %08X %08X, %08X\n", R[0], R[1], R[15]); - if (addr==0x037CDD00) printf("zog %08X\n", R[15]);*/ - /*if (addr==0x037CDC00) printf("sendcmd %08X %08X\n", R[0], R[15]); - if (addr==0x037CA700) printf("prepare CID, %08X\n", R[15]); - if(addr==0x037D4498) printf("READ SHITTY FIFO. %08X\n", R[15]); - if (addr==0x037CCD68) printf("atomic_store %08X %08X, %08X\n", R[0], R[1], R[15]); - if (addr>=0x037CEE00 && addr<=0x037CEE30) printf("shitty loop: %08X->%08X\n", R[15], addr); - if (R[15]==0x037CCD8C) printf("BERG!!! %08X\n", addr); - if (addr==0x037CD600) printf("XFER IRQ HANDLER\n"); - if (R[15]==0x037CD62C) printf("TERRIBLE HANDLER: %08X\n", addr); - if (addr==0x037CCE24) printf("SD IRQ HANDLER\n"); - if (addr==0x037CCD94) printf("atomic_load %08X %08X, %08X\n", R[0], R[1], R[15]); - if (addr==0x037CEB7C) printf("CHECK CSR RESULT. %08X %08X %08X, %08X\n", R[0], R[1], R[2], R[15]); - if (R[15]==0x037CEC6C) printf("RETURN FROM CSR CHECK: %08X %08X\n", R[0], R[3]+0x38); - if (addr==0x037CB2AC) printf("ZOG!\n"); - if (addr==0x037CB2A0) printf("GONP %08X %08X, %08X\n", R[1]+0x28, R[3]+0x34, R[15]); - if (addr==0x037CCFC0) printf("SDMMC TIMEOUT. %08X\n", R[15]); - if (addr==0x037D68A8) printf("BARKBARKBARK. %08X\n", R[15]); - if (addr==0x037CCF04) printf("BAKAAA\n"); - if (addr==0x037D6988) printf("MORPMORPMORPMORPMORPMORPMORPMORPMORP %08X\n", R[15]); - if (addr==0x37D6904) printf("TIMEOUT FARTORED! %08X, %08X %08X, %08X\n", R[4], R[3], R[12], R[15]); - // TIMEOUT FARTORED! 037E89B8, 00000000 00200BFB, 037D68FC - if (addr==0x037CD660) printf("BRAAAAAAAAAAAP %08X\n", R[15]); - if (addr==0x037CD798) printf("BRAAPP SHATORED. %08X, %08X %08X\n", R[0], R[1], R[2]); - if (addr==0x037CCD34) printf("atomic_and %08X %08X, %08X\n", R[0], R[1], R[15]);*/ - // atomic_and 0400481C 0000FFE7, 037CD850 - - u32 oldregion = R[15] >> 23; u32 newregion = addr >> 23; @@ -607,13 +577,6 @@ void ARMv4::Execute() } else AddCycles_C(); - - /*if (R[15]==0x037CEE18) printf("SHITTY POINTER = %08X\n", R[0]+0x34); - if (R[15]==0x037CEE1C) printf("SHITTY FLAG = %08X\n", R[0]); - if (R[15]==0x037D68F0) printf("TIMESTAMP THING = %08X:%08X, CUR=%08X:%08X, ptr=%08X\n", - R[3], R[12], R[1], R[0], R[4]); - //if (R[15]==0x037CB29C) printf("GLORG!!! %08X\n", R[3]+0x34); 037E8A8C - if (R[15]==0x037CD730) printf("COUNT OF SHITO. %08X %08X\n", R[0], R[2]);*/ } // TODO optimize this shit!!! diff --git a/src/DSi.cpp b/src/DSi.cpp index fc590e1..fd58872 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -28,6 +28,7 @@ #include "DSi_NDMA.h" #include "DSi_I2C.h" #include "DSi_SD.h" +#include "DSi_AES.h" namespace NDS @@ -71,6 +72,7 @@ u8 eMMC_CID[16]; bool Init() { if (!DSi_I2C::Init()) return false; + if (!DSi_AES::Init()) return false; NDMAs[0] = new DSi_NDMA(0, 0); NDMAs[1] = new DSi_NDMA(0, 1); @@ -90,6 +92,7 @@ bool Init() void DeInit() { DSi_I2C::DeInit(); + DSi_AES::DeInit(); for (int i = 0; i < 8; i++) delete NDMAs[i]; @@ -110,6 +113,7 @@ void Reset() for (int i = 0; i < 8; i++) NDMAs[i]->Reset(); DSi_I2C::Reset(); + DSi_AES::Reset(); SDMMC->Reset(); SDIO->Reset(); @@ -336,6 +340,24 @@ bool NDMAsRunning(u32 cpu) return false; } +void CheckNDMAs(u32 cpu, u32 mode) +{ + cpu <<= 2; + NDMAs[cpu+0]->StartIfNeeded(mode); + NDMAs[cpu+1]->StartIfNeeded(mode); + NDMAs[cpu+2]->StartIfNeeded(mode); + NDMAs[cpu+3]->StartIfNeeded(mode); +} + +void StopNDMAs(u32 cpu, u32 mode) +{ + cpu <<= 2; + NDMAs[cpu+0]->StopIfNeeded(mode); + NDMAs[cpu+1]->StopIfNeeded(mode); + NDMAs[cpu+2]->StopIfNeeded(mode); + NDMAs[cpu+3]->StopIfNeeded(mode); +} + // new WRAM mapping // TODO: find out what happens upon overlapping slots!! @@ -1097,6 +1119,9 @@ u32 ARM7IORead32(u32 addr) case 0x04004168: return NDMAs[7]->SubblockTimer; case 0x0400416C: return NDMAs[7]->FillData; case 0x04004170: return NDMAs[7]->Cnt; + + case 0x04004400: return DSi_AES::ReadCnt(); + case 0x0400440C: return DSi_AES::ReadOutputFIFO(); } if (addr >= 0x04004800 && addr < 0x04004A00) @@ -1182,6 +1207,36 @@ void ARM7IOWrite32(u32 addr, u32 val) case 0x04004168: NDMAs[7]->SubblockTimer = val & 0x0003FFFF; return; case 0x0400416C: NDMAs[7]->FillData = val; return; case 0x04004170: NDMAs[7]->WriteCnt(val); return; + + case 0x04004400: DSi_AES::WriteCnt(val); return; + case 0x04004404: DSi_AES::WriteBlkCnt(val); return; + case 0x04004408: DSi_AES::WriteInputFIFO(val); return; + } + + if (addr >= 0x04004420 && addr < 0x04004430) + { + addr -= 0x04004420; + DSi_AES::WriteIV(addr, val, 0xFFFFFFFF); + return; + } + if (addr >= 0x04004430 && addr < 0x04004440) + { + addr -= 0x04004430; + DSi_AES::WriteMAC(addr, val, 0xFFFFFFFF); + return; + } + if (addr >= 0x04004440 && addr < 0x04004500) + { + addr -= 0x04004440; + int n = 0; + while (addr > 0x30) { addr -= 0x30; n++; } + + switch (addr >> 4) + { + case 0: DSi_AES::WriteKeyNormal(n, addr&0xF, val, 0xFFFFFFFF); return; + case 1: DSi_AES::WriteKeyX(n, addr&0xF, val, 0xFFFFFFFF); return; + case 2: DSi_AES::WriteKeyY(n, addr&0xF, val, 0xFFFFFFFF); return; + } } if (addr >= 0x04004800 && addr < 0x04004A00) diff --git a/src/DSi.h b/src/DSi.h index 32253a7..642a56a 100644 --- a/src/DSi.h +++ b/src/DSi.h @@ -26,6 +26,7 @@ namespace DSi { extern u8 eMMC_CID[16]; +extern u64 ConsoleID; extern DSi_SDHost* SDMMC; extern DSi_SDHost* SDIO; @@ -41,6 +42,8 @@ bool LoadNAND(); void RunNDMAs(u32 cpu); void StallNDMAs(); bool NDMAsRunning(u32 cpu); +void CheckNDMAs(u32 cpu, u32 mode); +void StopNDMAs(u32 cpu, u32 mode); void MapNWRAM_A(u32 num, u8 val); void MapNWRAM_B(u32 num, u8 val); diff --git a/src/DSi_AES.cpp b/src/DSi_AES.cpp index 6a524dd..8271e3e 100644 --- a/src/DSi_AES.cpp +++ b/src/DSi_AES.cpp @@ -15,3 +15,306 @@ You should have received a copy of the GNU General Public License along with melonDS. If not, see http://www.gnu.org/licenses/. */ + +#include +#include +#include "DSi.h" +#include "DSi_AES.h" +#include "FIFO.h" +#include "tiny-AES-c/aes.hpp" + + +namespace DSi_AES +{ + +u32 Cnt; + +u32 BlkCnt; +u32 RemBlocks; + +u32 InputDMASize, OutputDMASize; +u32 AESMode; + +FIFO* InputFIFO; +FIFO* OutputFIFO; + +u8 IV[16]; + +u8 KeyNormal[4][16]; +u8 KeyX[4][16]; +u8 KeyY[4][16]; + +u8 CurKey[16]; + +AES_ctx Ctx; + + +void Swap16(u8* dst, u8* src) +{ + for (int i = 0; i < 16; i++) + dst[i] = src[15-i]; +} + +void ROL16(u8* val, u32 n) +{ + u32 n_coarse = n >> 3; + u32 n_fine = n & 7; + u8 tmp[16]; + + for (u32 i = 0; i < 16; i++) + { + tmp[i] = val[(i - n_coarse) & 0xF]; + } + + for (u32 i = 0; i < 16; i++) + { + val[i] = (tmp[i] << n_fine) | (tmp[(i - 1) & 0xF] >> (8-n_fine)); + } +} + +#define _printhex(str, size) { for (int z = 0; z < (size); z++) printf("%02X", (str)[z]); printf("\n"); } + + +bool Init() +{ + InputFIFO = new FIFO(16); + OutputFIFO = new FIFO(16); + + const u8 zero[16] = {0}; + AES_init_ctx_iv(&Ctx, zero, zero); + + return true; +} + +void DeInit() +{ + delete InputFIFO; + delete OutputFIFO; +} + +void Reset() +{ + Cnt = 0; + + BlkCnt = 0; + RemBlocks = 0; + + InputDMASize = 0; + OutputDMASize = 0; + AESMode = 0; + + InputFIFO->Clear(); + OutputFIFO->Clear(); + + memset(KeyNormal, 0, sizeof(KeyNormal)); + memset(KeyX, 0, sizeof(KeyX)); + memset(KeyY, 0, sizeof(KeyY)); + + memset(CurKey, 0, sizeof(CurKey)); + + // initialize keys, as per GBAtek + + // slot 3: console-unique eMMC crypto + *(u32*)&KeyX[3][0] = (u32)DSi::ConsoleID; + *(u32*)&KeyX[3][4] = (u32)DSi::ConsoleID ^ 0x24EE6906; + *(u32*)&KeyX[3][8] = (u32)(DSi::ConsoleID >> 32) ^ 0xE65B601D; + *(u32*)&KeyX[3][12] = (u32)(DSi::ConsoleID >> 32); + *(u32*)&KeyY[3][0] = 0x0AB9DC76; + *(u32*)&KeyY[3][4] = 0xBD4DC4D3; + *(u32*)&KeyY[3][8] = 0x202DDD1D; +} + + +void ProcessBlock_CTR() +{ + u8 data[16]; + u8 data_rev[16]; + + *(u32*)&data[0] = InputFIFO->Read(); + *(u32*)&data[4] = InputFIFO->Read(); + *(u32*)&data[8] = InputFIFO->Read(); + *(u32*)&data[12] = InputFIFO->Read(); + + //printf("AES-CTR: INPUT: "); _printhex(data, 16); + + Swap16(data_rev, data); + AES_CTR_xcrypt_buffer(&Ctx, data_rev, 16); + Swap16(data, data_rev); + + //printf("AES-CTR: OUTPUT: "); _printhex(data, 16); + + OutputFIFO->Write(*(u32*)&data[0]); + OutputFIFO->Write(*(u32*)&data[4]); + OutputFIFO->Write(*(u32*)&data[8]); + OutputFIFO->Write(*(u32*)&data[12]); +} + + +u32 ReadCnt() +{ + u32 ret = Cnt; + + ret |= InputFIFO->Level(); + ret |= (OutputFIFO->Level() << 5); + + return ret; +} + +void WriteCnt(u32 val) +{ + u32 oldcnt = Cnt; + Cnt = val & 0xFC1FF000; + + if (val & (1<<10)) InputFIFO->Clear(); + if (val & (1<<11)) OutputFIFO->Clear(); + + u32 dmasize[4] = {4, 8, 12, 16}; + InputDMASize = dmasize[3 - ((val >> 12) & 0x3)]; + OutputDMASize = dmasize[(val >> 14) & 0x3]; + + AESMode = (val >> 28) & 0x3; + if (AESMode < 2) printf("AES-CCM TODO\n"); + + if (val & (1<<24)) + { + u32 slot = (val >> 26) & 0x3; + memcpy(CurKey, KeyNormal[slot], 16); + + //printf("AES: key(%d): ", slot); _printhex(CurKey, 16); + + u8 tmp[16]; + Swap16(tmp, CurKey); + AES_init_ctx(&Ctx, tmp); + } + + if (!(oldcnt & (1<<31)) && (val & (1<<31))) + { + // transfer start (checkme) + RemBlocks = BlkCnt >> 16; + } + + printf("AES CNT: %08X / mode=%d inDMA=%d outDMA=%d blocks=%d\n", + val, AESMode, InputDMASize, OutputDMASize, RemBlocks); +} + +void WriteBlkCnt(u32 val) +{ + BlkCnt = val; +} + +u32 ReadOutputFIFO() +{ + return OutputFIFO->Read(); +} + +void WriteInputFIFO(u32 val) +{ + // TODO: add some delay to processing + + InputFIFO->Write(val); + + if (!(Cnt & (1<<31))) return; + + while (InputFIFO->Level() >= 4 && RemBlocks > 0) + { + switch (AESMode) + { + case 2: + case 3: ProcessBlock_CTR(); break; + default: + // dorp + OutputFIFO->Write(InputFIFO->Read()); + OutputFIFO->Write(InputFIFO->Read()); + OutputFIFO->Write(InputFIFO->Read()); + OutputFIFO->Write(InputFIFO->Read()); + } + + RemBlocks--; + } + + if (OutputFIFO->Level() >= OutputDMASize) + { + // trigger DMA + DSi::CheckNDMAs(1, 0x2B); + } + // TODO: DMA the other way around + + if (RemBlocks == 0) + { + Cnt &= ~(1<<31); + if (Cnt & (1<<30)) NDS::SetIRQ2(NDS::IRQ2_DSi_AES); + } +} + + +void WriteIV(u32 offset, u32 val, u32 mask) +{ + u32 old = *(u32*)&IV[offset]; + + *(u32*)&IV[offset] = (old & ~mask) | (val & mask); + + //printf("AES: IV: "); _printhex(IV, 16); + + u8 tmp[16]; + Swap16(tmp, IV); + AES_ctx_set_iv(&Ctx, tmp); +} + +void WriteMAC(u32 offset, u32 val, u32 mask) +{ + // +} + +void DeriveNormalKey(u32 slot) +{ + const u8 key_const[16] = {0xFF, 0xFE, 0xFB, 0x4E, 0x29, 0x59, 0x02, 0x58, 0x2A, 0x68, 0x0F, 0x5F, 0x1A, 0x4F, 0x3E, 0x79}; + u8 tmp[16]; + + //printf("keyX: "); _printhex(KeyX[slot], 16); + //printf("keyY: "); _printhex(KeyY[slot], 16); + + for (int i = 0; i < 16; i++) + tmp[i] = KeyX[slot][i] ^ KeyY[slot][i]; + + u32 carry = 0; + for (int i = 0; i < 16; i++) + { + u32 res = tmp[i] + key_const[15-i] + carry; + tmp[i] = res & 0xFF; + carry = res >> 8; + } + + ROL16(tmp, 42); + + //printf("derive normalkey %d\n", slot); _printhex(tmp, 16); + + memcpy(KeyNormal[slot], tmp, 16); +} + +void WriteKeyNormal(u32 slot, u32 offset, u32 val, u32 mask) +{ + u32 old = *(u32*)&KeyNormal[slot][offset]; + + *(u32*)&KeyNormal[slot][offset] = (old & ~mask) | (val & mask); +} + +void WriteKeyX(u32 slot, u32 offset, u32 val, u32 mask) +{ + u32 old = *(u32*)&KeyX[slot][offset]; + + *(u32*)&KeyX[slot][offset] = (old & ~mask) | (val & mask); +} + +void WriteKeyY(u32 slot, u32 offset, u32 val, u32 mask) +{ + u32 old = *(u32*)&KeyY[slot][offset]; + + *(u32*)&KeyY[slot][offset] = (old & ~mask) | (val & mask); + + if (offset >= 0xC) + { + DeriveNormalKey(slot); + } +} + +} diff --git a/src/DSi_AES.h b/src/DSi_AES.h index 028523a..7c388f5 100644 --- a/src/DSi_AES.h +++ b/src/DSi_AES.h @@ -19,6 +19,30 @@ #ifndef DSI_AES_H #define DSI_AES_H -// +#include "types.h" + +namespace DSi_AES +{ + +extern u32 Cnt; + +bool Init(); +void DeInit(); +void Reset(); + +u32 ReadCnt(); +void WriteCnt(u32 val); +void WriteBlkCnt(u32 val); + +u32 ReadOutputFIFO(); +void WriteInputFIFO(u32 val); + +void WriteIV(u32 offset, u32 val, u32 mask); +void WriteMAC(u32 offset, u32 val, u32 mask); +void WriteKeyNormal(u32 slot, u32 offset, u32 val, u32 mask); +void WriteKeyX(u32 slot, u32 offset, u32 val, u32 mask); +void WriteKeyY(u32 slot, u32 offset, u32 val, u32 mask); + +} #endif // DSI_AES_H diff --git a/src/DSi_NDMA.cpp b/src/DSi_NDMA.cpp index 7c0b2a1..aed78af 100644 --- a/src/DSi_NDMA.cpp +++ b/src/DSi_NDMA.cpp @@ -99,7 +99,8 @@ void DSi_NDMA::WriteCnt(u32 val) if ((StartMode & 0x1F) == 0x10) Start(); - if (StartMode != 0x10 && StartMode != 0x30) + if (StartMode != 0x10 && StartMode != 0x30 && + StartMode != 0x2B) printf("UNIMPLEMENTED ARM%d NDMA%d START MODE %02X, %08X->%08X\n", CPU?7:9, Num, StartMode, SrcAddr, DstAddr); } } @@ -223,16 +224,19 @@ void DSi_NDMA::Run9() } if ((StartMode & 0x1F) == 0x10) // CHECKME + { Cnt &= ~(1<<31); + if (Cnt & (1<<30)) NDS::SetIRQ(0, NDS::IRQ_DSi_NDMA0 + Num); + } else if (!(Cnt & (1<<29))) { if (TotalRemCount == 0) + { Cnt &= ~(1<<31); + if (Cnt & (1<<30)) NDS::SetIRQ(0, NDS::IRQ_DSi_NDMA0 + Num); + } } - if (Cnt & (1<<30)) - NDS::SetIRQ(0, NDS::IRQ_DSi_NDMA0 + Num); - Running = 0; InProgress = false; NDS::ResumeCPU(0, 1<<(Num+4)); @@ -305,16 +309,19 @@ void DSi_NDMA::Run7() } if ((StartMode & 0x1F) == 0x10) // CHECKME + { Cnt &= ~(1<<31); + if (Cnt & (1<<30)) NDS::SetIRQ(1, NDS::IRQ_DSi_NDMA0 + Num); + } else if (!(Cnt & (1<<29))) { if (TotalRemCount == 0) + { Cnt &= ~(1<<31); + if (Cnt & (1<<30)) NDS::SetIRQ(1, NDS::IRQ_DSi_NDMA0 + Num); + } } - if (Cnt & (1<<30)) - NDS::SetIRQ(1, NDS::IRQ_DSi_NDMA0 + Num); - Running = 0; InProgress = false; NDS::ResumeCPU(1, 1<<(Num+4)); diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index 42b515c..bb3c4a4 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -473,10 +473,10 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param) case 2: case 10: // get CID - Host->SendResponse(*(u32*)&CID[0], false); - Host->SendResponse(*(u32*)&CID[1], false); - Host->SendResponse(*(u32*)&CID[2], false); - Host->SendResponse(*(u32*)&CID[3], true); + Host->SendResponse(*(u32*)&CID[12], false); + Host->SendResponse(*(u32*)&CID[8], false); + Host->SendResponse(*(u32*)&CID[4], false); + Host->SendResponse(*(u32*)&CID[0], true); //if (cmd == 2) SetState(0x02); return; @@ -502,13 +502,18 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param) return; case 9: // get CSD - Host->SendResponse(*(u32*)&CSD[0], false); - Host->SendResponse(*(u32*)&CSD[1], false); - Host->SendResponse(*(u32*)&CSD[2], false); - Host->SendResponse(*(u32*)&CSD[3], true); + Host->SendResponse(*(u32*)&CSD[12], false); + Host->SendResponse(*(u32*)&CSD[8], false); + Host->SendResponse(*(u32*)&CSD[4], false); + Host->SendResponse(*(u32*)&CSD[0], true); return; case 12: // stop operation + // TODO + Host->SendResponse(CSR, true); + return; + + case 13: // get status Host->SendResponse(CSR, true); return; diff --git a/src/NDS.cpp b/src/NDS.cpp index e20f62f..7513d57 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -1582,12 +1582,12 @@ void debug(u32 param) printf("ARM7 PC=%08X LR=%08X %08X\n", ARM7->R[15], ARM7->R[14], ARM7->R_IRQ[1]); printf("ARM9 IME=%08X IE=%08X IF=%08X\n", IME[0], IE[0], IF[0]); - printf("ARM7 IME=%08X IE=%08X IF=%08X\n", IME[1], IE[1], IF[1]); + printf("ARM7 IME=%08X IE=%08X IF=%08X IE2=%04X IF2=%04X\n", IME[1], IE[1], IF[1], IE2, IF2); //for (int i = 0; i < 9; i++) // printf("VRAM %c: %02X\n", 'A'+i, GPU::VRAMCNT[i]); - FILE* + /*FILE* shit = fopen("debug/card.bin", "wb"); for (u32 i = 0x02000000; i < 0x02400000; i+=4) { @@ -1599,7 +1599,7 @@ void debug(u32 param) u32 val = ARM7Read32(i); fwrite(&val, 4, 1, shit); } - fclose(shit); + fclose(shit);*/ } -- cgit v1.2.3 From 78b28f6a5cd40c77f63acc0fbd95135c45187e2a Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 19 Jun 2019 14:44:00 +0200 Subject: fix bug with SD reads going a bit too far --- src/DSi_SD.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index bb3c4a4..9775ca8 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -160,12 +160,12 @@ void DSi_SDHost::FinishSend(u32 param) host->ClearIRQ(25); host->SetIRQ(24); - if (param & 0x2) host->SetIRQ(2); + //if (param & 0x2) host->SetIRQ(2); } void DSi_SDHost::SendData(u8* data, u32 len) { - printf("%s: data RX, len=%d, blkcnt=%d blklen=%d, irq=%08X\n", SD_DESC, len, BlockCount16, BlockLen16, IRQMask); + printf("%s: data RX, len=%d, blkcnt=%d (%d) blklen=%d, irq=%08X\n", SD_DESC, len, BlockCount16, BlockCountInternal, BlockLen16, IRQMask); if (len != BlockLen16) printf("!! BAD BLOCKLEN\n"); bool last = (BlockCountInternal == 0); @@ -236,7 +236,7 @@ u16 DSi_SDHost::Read(u32 addr) { ClearIRQ(24); - if (BlockCountInternal == 0) + if (BlockCountInternal <= 1) { printf("%s: data RX complete", SD_DESC); @@ -251,7 +251,7 @@ u16 DSi_SDHost::Read(u32 addr) // CHECKME: presumably IRQ2 should not trigger here, but rather // when the data transfer is done //SetIRQ(0); - //SetIRQ(2); + SetIRQ(2); } else { @@ -300,7 +300,7 @@ u32 DSi_SDHost::ReadFIFO32() { ClearIRQ(24); - if (BlockCountInternal == 0) + if (BlockCountInternal <= 1) { printf("%s: data32 RX complete", SD_DESC); @@ -315,7 +315,7 @@ u32 DSi_SDHost::ReadFIFO32() // CHECKME: presumably IRQ2 should not trigger here, but rather // when the data transfer is done //SetIRQ(0); - //SetIRQ(2); + SetIRQ(2); } else { -- cgit v1.2.3 From 6e5879f8bbf6bf85791b03f36675aa7991ae4771 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 19 Jun 2019 15:26:38 +0200 Subject: fix more bugs, get further --- src/DSi_AES.cpp | 1 + src/DSi_SD.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/DSi_AES.cpp b/src/DSi_AES.cpp index 8271e3e..1ba690f 100644 --- a/src/DSi_AES.cpp +++ b/src/DSi_AES.cpp @@ -243,6 +243,7 @@ void WriteInputFIFO(u32 val) { Cnt &= ~(1<<31); if (Cnt & (1<<30)) NDS::SetIRQ2(NDS::IRQ2_DSi_AES); + DSi::StopNDMAs(1, 0x2B); } } diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index 9775ca8..4a7fd2e 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -477,7 +477,7 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param) Host->SendResponse(*(u32*)&CID[8], false); Host->SendResponse(*(u32*)&CID[4], false); Host->SendResponse(*(u32*)&CID[0], true); - //if (cmd == 2) SetState(0x02); + if (cmd == 2) SetState(0x02); return; case 3: // get/set RCA @@ -509,7 +509,7 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param) return; case 12: // stop operation - // TODO + SetState(0x04); Host->SendResponse(CSR, true); return; @@ -525,6 +525,7 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param) printf("!! SD/MMC: BAD BLOCK LEN %d\n", BlockSize); BlockSize = 0x200; } + SetState(0x04); // CHECKME Host->SendResponse(CSR, true); return; @@ -535,6 +536,7 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param) Host->SendResponse(CSR, true); ReadBlock(RWAddress); RWAddress += BlockSize; + SetState(0x05); return; case 55: // ?? -- cgit v1.2.3 From 2a60fad0a51833a02e5e1c6dd7f59b4117676831 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 19 Jun 2019 15:54:07 +0200 Subject: fix moar bugs, get furtherer (add support for SDHC addressing) --- src/DSi_SD.cpp | 11 ++++++++++- src/DSi_SD.h | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index 4a7fd2e..fed26b1 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -532,6 +532,11 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param) case 18: // read multiple blocks printf("READ_MULTIPLE_BLOCKS addr=%08X size=%08X\n", param, BlockSize); RWAddress = param; + if (OCR & (1<<30)) + { + RWAddress <<= 9; + BlockSize = 512; + } RWCommand = 18; Host->SendResponse(CSR, true); ReadBlock(RWAddress); @@ -563,6 +568,10 @@ void DSi_MMCStorage::SendACMD(u8 cmd, u32 param) return; case 41: // set operating conditions + // CHECKME: + // DSi boot2 sets this to 0x40100000 (hardcoded) + // then has two codepaths depending on whether bit30 did get set + // is it settable at all on the MMC? OCR &= 0xBF000000; OCR |= (param & 0x40FFFFFF); Host->SendResponse(OCR, true); @@ -588,7 +597,7 @@ void DSi_MMCStorage::ContinueTransfer() RWAddress += BlockSize; } -void DSi_MMCStorage::ReadBlock(u32 addr) +void DSi_MMCStorage::ReadBlock(u64 addr) { if (!File) return; diff --git a/src/DSi_SD.h b/src/DSi_SD.h index 57da7df..3c76872 100644 --- a/src/DSi_SD.h +++ b/src/DSi_SD.h @@ -120,12 +120,12 @@ private: u8 SSR[64]; u32 BlockSize; - u32 RWAddress; + u64 RWAddress; u32 RWCommand; void SetState(u32 state) { CSR &= ~(0xF << 9); CSR |= (state << 9); } - void ReadBlock(u32 addr); + void ReadBlock(u64 addr); }; #endif // DSI_SD_H -- cgit v1.2.3 From d5a7c0bab8b700477e36932ca62fae28d2518ee9 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 19 Jun 2019 15:58:50 +0200 Subject: there, PSISP --- src/DSi_SD.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index fed26b1..fbb2e14 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -571,7 +571,8 @@ void DSi_MMCStorage::SendACMD(u8 cmd, u32 param) // CHECKME: // DSi boot2 sets this to 0x40100000 (hardcoded) // then has two codepaths depending on whether bit30 did get set - // is it settable at all on the MMC? + // is it settable at all on the MMC? probably not. + if (Internal) param &= ~(1<<30); OCR &= 0xBF000000; OCR |= (param & 0x40FFFFFF); Host->SendResponse(OCR, true); -- cgit v1.2.3 From b03e81edc84e191d9bda87555e9ae190de60b032 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 19 Jun 2019 16:56:58 +0200 Subject: add consoleID registers --- src/DSi.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index fd58872..b0c1ceb 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -1053,6 +1053,16 @@ u8 ARM7IORead8(u32 addr) case 0x04004500: return DSi_I2C::ReadData(); case 0x04004501: printf("read I2C CNT %02X\n", DSi_I2C::Cnt); return DSi_I2C::Cnt; + + case 0x04004D00: return ConsoleID & 0xFF; + case 0x04004D01: return (ConsoleID >> 8) & 0xFF; + case 0x04004D02: return (ConsoleID >> 16) & 0xFF; + case 0x04004D03: return (ConsoleID >> 24) & 0xFF; + case 0x04004D04: return (ConsoleID >> 32) & 0xFF; + case 0x04004D05: return (ConsoleID >> 40) & 0xFF; + case 0x04004D06: return (ConsoleID >> 48) & 0xFF; + case 0x04004D07: return ConsoleID >> 56; + case 0x04004D08: return 0; } return NDS::ARM7IORead8(addr); @@ -1067,6 +1077,12 @@ u16 ARM7IORead16(u32 addr) case 0x04004004: return 0x0187; case 0x04004006: return 0; // JTAG register + + case 0x04004D00: return ConsoleID & 0xFFFF; + case 0x04004D02: return (ConsoleID >> 16) & 0xFFFF; + case 0x04004D04: return (ConsoleID >> 32) & 0xFFFF; + case 0x04004D06: return ConsoleID >> 48; + case 0x04004D08: return 0; } if (addr >= 0x04004800 && addr < 0x04004A00) @@ -1122,6 +1138,10 @@ u32 ARM7IORead32(u32 addr) case 0x04004400: return DSi_AES::ReadCnt(); case 0x0400440C: return DSi_AES::ReadOutputFIFO(); + + case 0x04004D00: return ConsoleID & 0xFFFFFFFF; + case 0x04004D04: return ConsoleID >> 32; + case 0x04004D08: return 0; } if (addr >= 0x04004800 && addr < 0x04004A00) -- cgit v1.2.3 From 734c9024d5961c33aa61f8cd8352d716d281e19c Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 19 Jun 2019 17:16:44 +0200 Subject: add NWRAM registers --- src/DSi.cpp | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index b0c1ceb..a450666 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -197,6 +197,9 @@ bool LoadNAND() // read and apply new-WRAM settings + MBK[0][8] = 0; + MBK[1][8] = 0; + u32 mbk[12]; fseek(f, 0x380, SEEK_SET); fread(mbk, 4, 12, f); @@ -232,7 +235,10 @@ bool LoadNAND() MapNWRAMRange(1, 1, mbk[9]); MapNWRAMRange(1, 2, mbk[10]); - // TODO: MBK9 protect thing + // TODO: find out why it is 0xFF000000 + mbk[11] &= 0x00FFFF0F; + MBK[0][8] = mbk[11]; + MBK[1][8] = mbk[11]; // load binaries // TODO: optionally support loading from actual NAND? @@ -364,6 +370,12 @@ void StopNDMAs(u32 cpu, u32 mode) void MapNWRAM_A(u32 num, u8 val) { + if (MBK[0][8] & (1 << num)) + { + printf("trying to map NWRAM_A %d to %02X, but it is write-protected (%08X)\n", num, val, MBK[0][8]); + return; + } + int mbkn = 0, mbks = 8*num; u8 oldval = (MBK[0][mbkn] >> mbks) & 0xFF; @@ -389,6 +401,12 @@ void MapNWRAM_A(u32 num, u8 val) void MapNWRAM_B(u32 num, u8 val) { + if (MBK[0][8] & (1 << (8+num))) + { + printf("trying to map NWRAM_B %d to %02X, but it is write-protected (%08X)\n", num, val, MBK[0][8]); + return; + } + int mbkn = 1+(num>>2), mbks = 8*(num&3); u8 oldval = (MBK[0][mbkn] >> mbks) & 0xFF; @@ -418,6 +436,12 @@ void MapNWRAM_B(u32 num, u8 val) void MapNWRAM_C(u32 num, u8 val) { + if (MBK[0][8] & (1 << (16+num))) + { + printf("trying to map NWRAM_C %d to %02X, but it is write-protected (%08X)\n", num, val, MBK[0][8]); + return; + } + int mbkn = 3+(num>>2), mbks = 8*(num&3); u8 oldval = (MBK[0][mbkn] >> mbks) & 0xFF; @@ -928,10 +952,23 @@ bool ARM7GetMemRegion(u32 addr, bool write, NDS::MemRegion* region) case (addr+2): return ((val) >> 16) & 0xFF; \ case (addr+3): return (val) >> 24; +#define CASE_READ16_32BIT(addr, val) \ + case (addr): return (val) & 0xFFFF; \ + case (addr+2): return (val) >> 16; + u8 ARM9IORead8(u32 addr) { switch (addr) { + CASE_READ8_32BIT(0x04004040, MBK[0][0]) + CASE_READ8_32BIT(0x04004044, MBK[0][1]) + CASE_READ8_32BIT(0x04004048, MBK[0][2]) + CASE_READ8_32BIT(0x0400404C, MBK[0][3]) + CASE_READ8_32BIT(0x04004050, MBK[0][4]) + CASE_READ8_32BIT(0x04004054, MBK[0][5]) + CASE_READ8_32BIT(0x04004058, MBK[0][6]) + CASE_READ8_32BIT(0x0400405C, MBK[0][7]) + CASE_READ8_32BIT(0x04004060, MBK[0][8]) } return NDS::ARM9IORead8(addr); @@ -942,6 +979,16 @@ u16 ARM9IORead16(u32 addr) switch (addr) { case 0x04004004: return 0; // TODO + + CASE_READ16_32BIT(0x04004040, MBK[0][0]) + CASE_READ16_32BIT(0x04004044, MBK[0][1]) + CASE_READ16_32BIT(0x04004048, MBK[0][2]) + CASE_READ16_32BIT(0x0400404C, MBK[0][3]) + CASE_READ16_32BIT(0x04004050, MBK[0][4]) + CASE_READ16_32BIT(0x04004054, MBK[0][5]) + CASE_READ16_32BIT(0x04004058, MBK[0][6]) + CASE_READ16_32BIT(0x0400405C, MBK[0][7]) + CASE_READ16_32BIT(0x04004060, MBK[0][8]) } return NDS::ARM9IORead16(addr); @@ -953,6 +1000,16 @@ u32 ARM9IORead32(u32 addr) { case 0x04004010: return 1; // todo + case 0x04004040: return MBK[0][0]; + case 0x04004044: return MBK[0][1]; + case 0x04004048: return MBK[0][2]; + case 0x0400404C: return MBK[0][3]; + case 0x04004050: return MBK[0][4]; + case 0x04004054: return MBK[0][5]; + case 0x04004058: return MBK[0][6]; + case 0x0400405C: return MBK[0][7]; + case 0x04004060: return MBK[0][8]; + case 0x04004100: return NDMACnt[0]; case 0x04004104: return NDMAs[0]->SrcAddr; case 0x04004108: return NDMAs[0]->DstAddr; @@ -991,6 +1048,26 @@ void ARM9IOWrite8(u32 addr, u8 val) { switch (addr) { + case 0x04004040: MapNWRAM_A(0, val); return; + case 0x04004041: MapNWRAM_A(1, val); return; + case 0x04004042: MapNWRAM_A(2, val); return; + case 0x04004043: MapNWRAM_A(3, val); return; + case 0x04004044: MapNWRAM_B(0, val); return; + case 0x04004045: MapNWRAM_B(1, val); return; + case 0x04004046: MapNWRAM_B(2, val); return; + case 0x04004047: MapNWRAM_B(3, val); return; + case 0x04004048: MapNWRAM_B(4, val); return; + case 0x04004049: MapNWRAM_B(5, val); return; + case 0x0400404A: MapNWRAM_B(6, val); return; + case 0x0400404B: MapNWRAM_B(7, val); return; + case 0x0400404C: MapNWRAM_C(0, val); return; + case 0x0400404D: MapNWRAM_C(1, val); return; + case 0x0400404E: MapNWRAM_C(2, val); return; + case 0x0400404F: MapNWRAM_C(3, val); return; + case 0x04004050: MapNWRAM_C(4, val); return; + case 0x04004051: MapNWRAM_C(5, val); return; + case 0x04004052: MapNWRAM_C(6, val); return; + case 0x04004053: MapNWRAM_C(7, val); return; } return NDS::ARM9IOWrite8(addr, val); @@ -1009,6 +1086,10 @@ void ARM9IOWrite32(u32 addr, u32 val) { switch (addr) { + case 0x04004054: MapNWRAMRange(0, 0, val); return; + case 0x04004058: MapNWRAMRange(0, 1, val); return; + case 0x0400405C: MapNWRAMRange(0, 2, val); return; + case 0x04004100: NDMACnt[0] = val & 0x800F0000; return; case 0x04004104: NDMAs[0]->SrcAddr = val & 0xFFFFFFFC; return; case 0x04004108: NDMAs[0]->DstAddr = val & 0xFFFFFFFC; return; @@ -1051,6 +1132,16 @@ u8 ARM7IORead8(u32 addr) case 0x04004000: return 0x01; case 0x04004001: return 0x01; + CASE_READ8_32BIT(0x04004040, MBK[1][0]) + CASE_READ8_32BIT(0x04004044, MBK[1][1]) + CASE_READ8_32BIT(0x04004048, MBK[1][2]) + CASE_READ8_32BIT(0x0400404C, MBK[1][3]) + CASE_READ8_32BIT(0x04004050, MBK[1][4]) + CASE_READ8_32BIT(0x04004054, MBK[1][5]) + CASE_READ8_32BIT(0x04004058, MBK[1][6]) + CASE_READ8_32BIT(0x0400405C, MBK[1][7]) + CASE_READ8_32BIT(0x04004060, MBK[1][8]) + case 0x04004500: return DSi_I2C::ReadData(); case 0x04004501: printf("read I2C CNT %02X\n", DSi_I2C::Cnt); return DSi_I2C::Cnt; @@ -1078,6 +1169,16 @@ u16 ARM7IORead16(u32 addr) case 0x04004004: return 0x0187; case 0x04004006: return 0; // JTAG register + CASE_READ16_32BIT(0x04004040, MBK[1][0]) + CASE_READ16_32BIT(0x04004044, MBK[1][1]) + CASE_READ16_32BIT(0x04004048, MBK[1][2]) + CASE_READ16_32BIT(0x0400404C, MBK[1][3]) + CASE_READ16_32BIT(0x04004050, MBK[1][4]) + CASE_READ16_32BIT(0x04004054, MBK[1][5]) + CASE_READ16_32BIT(0x04004058, MBK[1][6]) + CASE_READ16_32BIT(0x0400405C, MBK[1][7]) + CASE_READ16_32BIT(0x04004060, MBK[1][8]) + case 0x04004D00: return ConsoleID & 0xFFFF; case 0x04004D02: return (ConsoleID >> 16) & 0xFFFF; case 0x04004D04: return (ConsoleID >> 32) & 0xFFFF; @@ -1106,6 +1207,16 @@ u32 ARM7IORead32(u32 addr) case 0x04004008: return 0x80000000; // HAX + case 0x04004040: return MBK[1][0]; + case 0x04004044: return MBK[1][1]; + case 0x04004048: return MBK[1][2]; + case 0x0400404C: return MBK[1][3]; + case 0x04004050: return MBK[1][4]; + case 0x04004054: return MBK[1][5]; + case 0x04004058: return MBK[1][6]; + case 0x0400405C: return MBK[1][7]; + case 0x04004060: return MBK[1][8]; + case 0x04004100: return NDMACnt[1]; case 0x04004104: return NDMAs[4]->SrcAddr; case 0x04004108: return NDMAs[4]->DstAddr; @@ -1198,6 +1309,11 @@ void ARM7IOWrite32(u32 addr, u32 val) case 0x04000218: NDS::IE2 = (val & 0x7FF7); NDS::UpdateIRQ(1); return; case 0x0400021C: NDS::IF2 &= ~(val & 0x7FF7); NDS::UpdateIRQ(1); return; + case 0x04004054: MapNWRAMRange(1, 0, val); return; + case 0x04004058: MapNWRAMRange(1, 1, val); return; + case 0x0400405C: MapNWRAMRange(1, 2, val); return; + case 0x04004060: val &= 0x00FFFF0F; MBK[0][8] = val; MBK[1][8] = val; return; + case 0x04004100: NDMACnt[1] = val & 0x800F0000; return; case 0x04004104: NDMAs[4]->SrcAddr = val & 0xFFFFFFFC; return; case 0x04004108: NDMAs[4]->DstAddr = val & 0xFFFFFFFC; return; -- cgit v1.2.3 From f4c7f5c96b5de3df75b9cb95d5e89b13b53a9d39 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 19 Jun 2019 18:55:48 +0200 Subject: support loading extra RSA keys from dsikeys.bin file (to dump from haxed DSi) --- src/DSi.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index a450666..ab76a76 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -68,6 +68,8 @@ DSi_SDHost* SDIO; u64 ConsoleID; u8 eMMC_CID[16]; +u8 ITCMInit[0x8000]; + bool Init() { @@ -112,6 +114,8 @@ void Reset() NDMACnt[0] = 0; NDMACnt[1] = 0; for (int i = 0; i < 8; i++) NDMAs[i]->Reset(); + memcpy(NDS::ARM9->ITCM, ITCMInit, 0x8000); + DSi_I2C::Reset(); DSi_AES::Reset(); @@ -303,6 +307,22 @@ bool LoadNAND() fclose(f); } + memset(ITCMInit, 0, 0x8000); + + f = fopen("dsikeys.bin", "rb"); + if (f) + { + // first 0x2524 bytes are loaded to 0x01FFC400 + + u32 dstaddr = 0x01FFC400; + fread(&ITCMInit[dstaddr & 0x7FFF], 0x2524, 1, f); + fclose(f); + } + else + { + printf("DSi keys not found\n"); + } + return true; } -- cgit v1.2.3 From dcae9788e510e44341b7535c267262b89667720b Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 19 Jun 2019 19:19:51 +0200 Subject: add NDMA start mode 0x0A (AES input FIFO) --- src/DSi_AES.cpp | 22 +++++++++++++++++++--- src/DSi_AES.h | 1 + src/DSi_NDMA.cpp | 8 +++++++- 3 files changed, 27 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/DSi_AES.cpp b/src/DSi_AES.cpp index 1ba690f..b427dcd 100644 --- a/src/DSi_AES.cpp +++ b/src/DSi_AES.cpp @@ -191,6 +191,8 @@ void WriteCnt(u32 val) { // transfer start (checkme) RemBlocks = BlkCnt >> 16; + + DSi::CheckNDMAs(1, 0x2A); } printf("AES CNT: %08X / mode=%d inDMA=%d outDMA=%d blocks=%d\n", @@ -204,7 +206,8 @@ void WriteBlkCnt(u32 val) u32 ReadOutputFIFO() { - return OutputFIFO->Read(); + u32 ret = OutputFIFO->Read(); + return ret; } void WriteInputFIFO(u32 val) @@ -234,17 +237,30 @@ void WriteInputFIFO(u32 val) if (OutputFIFO->Level() >= OutputDMASize) { - // trigger DMA + // trigger output DMA DSi::CheckNDMAs(1, 0x2B); } - // TODO: DMA the other way around if (RemBlocks == 0) { Cnt &= ~(1<<31); if (Cnt & (1<<30)) NDS::SetIRQ2(NDS::IRQ2_DSi_AES); + DSi::StopNDMAs(1, 0x2A); DSi::StopNDMAs(1, 0x2B); } + else + { + CheckInputDMA(); + } +} + +void CheckInputDMA() +{ + if (InputFIFO->Level() < InputDMASize) + { + // trigger input DMA + DSi::CheckNDMAs(1, 0x2A); + } } diff --git a/src/DSi_AES.h b/src/DSi_AES.h index 7c388f5..77a4400 100644 --- a/src/DSi_AES.h +++ b/src/DSi_AES.h @@ -36,6 +36,7 @@ void WriteBlkCnt(u32 val); u32 ReadOutputFIFO(); void WriteInputFIFO(u32 val); +void CheckInputDMA(); void WriteIV(u32 offset, u32 val, u32 mask); void WriteMAC(u32 offset, u32 val, u32 mask); diff --git a/src/DSi_NDMA.cpp b/src/DSi_NDMA.cpp index aed78af..cd84901 100644 --- a/src/DSi_NDMA.cpp +++ b/src/DSi_NDMA.cpp @@ -21,6 +21,7 @@ #include "DSi.h" #include "DSi_NDMA.h" #include "GPU.h" +#include "DSi_AES.h" @@ -100,7 +101,7 @@ void DSi_NDMA::WriteCnt(u32 val) Start(); if (StartMode != 0x10 && StartMode != 0x30 && - StartMode != 0x2B) + StartMode != 0x2A && StartMode != 0x2B) printf("UNIMPLEMENTED ARM%d NDMA%d START MODE %02X, %08X->%08X\n", CPU?7:9, Num, StartMode, SrcAddr, DstAddr); } } @@ -290,6 +291,7 @@ void DSi_NDMA::Run7() CurDstAddr += DstAddrInc<<2; IterCount--; RemCount--; + TotalRemCount--; if (NDS::ARM7Timestamp >= NDS::ARM7Target) break; } @@ -303,6 +305,8 @@ void DSi_NDMA::Run7() { Running = 0; NDS::ResumeCPU(1, 1<<(Num+4)); + + DSi_AES::CheckInputDMA(); } return; @@ -325,4 +329,6 @@ void DSi_NDMA::Run7() Running = 0; InProgress = false; NDS::ResumeCPU(1, 1<<(Num+4)); + + DSi_AES::CheckInputDMA(); } -- cgit v1.2.3 From 3807c9bf5b19bbea6eb10c12734a17e0c55b4f51 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 19 Jun 2019 21:57:08 +0200 Subject: combat AES overflowing and/or getting stuck --- src/DSi_AES.cpp | 59 +++++++++++++++++++++++++++++++++++--------------------- src/DSi_AES.h | 2 ++ src/DSi_NDMA.cpp | 4 +++- 3 files changed, 42 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/DSi_AES.cpp b/src/DSi_AES.cpp index b427dcd..9f48519 100644 --- a/src/DSi_AES.cpp +++ b/src/DSi_AES.cpp @@ -207,6 +207,9 @@ void WriteBlkCnt(u32 val) u32 ReadOutputFIFO() { u32 ret = OutputFIFO->Read(); + + CheckInputDMA(); + CheckOutputDMA(); return ret; } @@ -218,28 +221,7 @@ void WriteInputFIFO(u32 val) if (!(Cnt & (1<<31))) return; - while (InputFIFO->Level() >= 4 && RemBlocks > 0) - { - switch (AESMode) - { - case 2: - case 3: ProcessBlock_CTR(); break; - default: - // dorp - OutputFIFO->Write(InputFIFO->Read()); - OutputFIFO->Write(InputFIFO->Read()); - OutputFIFO->Write(InputFIFO->Read()); - OutputFIFO->Write(InputFIFO->Read()); - } - - RemBlocks--; - } - - if (OutputFIFO->Level() >= OutputDMASize) - { - // trigger output DMA - DSi::CheckNDMAs(1, 0x2B); - } + Update(); if (RemBlocks == 0) { @@ -261,6 +243,39 @@ void CheckInputDMA() // trigger input DMA DSi::CheckNDMAs(1, 0x2A); } + + Update(); +} + +void CheckOutputDMA() +{ + if (OutputFIFO->Level() >= OutputDMASize) + { + // trigger output DMA + DSi::CheckNDMAs(1, 0x2B); + } +} + +void Update() +{ + while (InputFIFO->Level() >= 4 && OutputFIFO->Level() <= 12 && RemBlocks > 0) + { + switch (AESMode) + { + case 2: + case 3: ProcessBlock_CTR(); break; + default: + // dorp + OutputFIFO->Write(InputFIFO->Read()); + OutputFIFO->Write(InputFIFO->Read()); + OutputFIFO->Write(InputFIFO->Read()); + OutputFIFO->Write(InputFIFO->Read()); + } + + RemBlocks--; + } + + CheckOutputDMA(); } diff --git a/src/DSi_AES.h b/src/DSi_AES.h index 77a4400..5e726cd 100644 --- a/src/DSi_AES.h +++ b/src/DSi_AES.h @@ -37,6 +37,8 @@ void WriteBlkCnt(u32 val); u32 ReadOutputFIFO(); void WriteInputFIFO(u32 val); void CheckInputDMA(); +void CheckOutputDMA(); +void Update(); void WriteIV(u32 offset, u32 val, u32 mask); void WriteMAC(u32 offset, u32 val, u32 mask); diff --git a/src/DSi_NDMA.cpp b/src/DSi_NDMA.cpp index cd84901..a62904a 100644 --- a/src/DSi_NDMA.cpp +++ b/src/DSi_NDMA.cpp @@ -129,7 +129,7 @@ void DSi_NDMA::Start() if (Cnt & (1<<12)) CurDstAddr = DstAddr; if (Cnt & (1<<15)) CurSrcAddr = SrcAddr; - printf("ARM%d NDMA%d %08X %02X %08X->%08X %d bytes, total=%d\n", CPU?7:9, Num, Cnt, StartMode, CurSrcAddr, CurDstAddr, RemCount*4, TotalRemCount*4); + //printf("ARM%d NDMA%d %08X %02X %08X->%08X %d bytes, total=%d\n", CPU?7:9, Num, Cnt, StartMode, CurSrcAddr, CurDstAddr, RemCount*4, TotalRemCount*4); //IsGXFIFODMA = (CPU == 0 && (CurSrcAddr>>24) == 0x02 && CurDstAddr == 0x04000400 && DstAddrInc == 0); @@ -307,6 +307,7 @@ void DSi_NDMA::Run7() NDS::ResumeCPU(1, 1<<(Num+4)); DSi_AES::CheckInputDMA(); + DSi_AES::CheckOutputDMA(); } return; @@ -331,4 +332,5 @@ void DSi_NDMA::Run7() NDS::ResumeCPU(1, 1<<(Num+4)); DSi_AES::CheckInputDMA(); + DSi_AES::CheckOutputDMA(); } -- cgit v1.2.3 From 95f4c1472b5c3d08d82b42747da397c19d8916ec Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 19 Jun 2019 22:08:35 +0200 Subject: probably betterer like this --- src/DSi_AES.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/DSi_AES.cpp b/src/DSi_AES.cpp index 9f48519..ced8d1a 100644 --- a/src/DSi_AES.cpp +++ b/src/DSi_AES.cpp @@ -222,18 +222,6 @@ void WriteInputFIFO(u32 val) if (!(Cnt & (1<<31))) return; Update(); - - if (RemBlocks == 0) - { - Cnt &= ~(1<<31); - if (Cnt & (1<<30)) NDS::SetIRQ2(NDS::IRQ2_DSi_AES); - DSi::StopNDMAs(1, 0x2A); - DSi::StopNDMAs(1, 0x2B); - } - else - { - CheckInputDMA(); - } } void CheckInputDMA() @@ -276,6 +264,14 @@ void Update() } CheckOutputDMA(); + + if (RemBlocks == 0) + { + Cnt &= ~(1<<31); + if (Cnt & (1<<30)) NDS::SetIRQ2(NDS::IRQ2_DSi_AES); + DSi::StopNDMAs(1, 0x2A); + DSi::StopNDMAs(1, 0x2B); + } } -- cgit v1.2.3 From 3d9e6c5c669c20893cd65cbbf3f293a315ab2225 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 20 Jun 2019 01:36:10 +0200 Subject: * fix more AES bugs * fix ass-stupid bug with NWRAM mapping --- src/DSi.cpp | 4 ++-- src/DSi_AES.cpp | 48 +++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index ab76a76..53c7135 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -52,8 +52,8 @@ u8 NWRAM_B[0x40000]; u8 NWRAM_C[0x40000]; u8* NWRAMMap_A[2][4]; -u8* NWRAMMap_B[3][4]; -u8* NWRAMMap_C[3][4]; +u8* NWRAMMap_B[3][8]; +u8* NWRAMMap_C[3][8]; u32 NWRAMStart[2][3]; u32 NWRAMEnd[2][3]; diff --git a/src/DSi_AES.cpp b/src/DSi_AES.cpp index ced8d1a..e218315 100644 --- a/src/DSi_AES.cpp +++ b/src/DSi_AES.cpp @@ -32,6 +32,8 @@ u32 Cnt; u32 BlkCnt; u32 RemBlocks; +bool OutputFlush; + u32 InputDMASize, OutputDMASize; u32 AESMode; @@ -73,6 +75,7 @@ void ROL16(u8* val, u32 n) } #define _printhex(str, size) { for (int z = 0; z < (size); z++) printf("%02X", (str)[z]); printf("\n"); } +#define _printhex2(str, size) { for (int z = 0; z < (size); z++) printf("%02X", (str)[z]); } bool Init() @@ -99,6 +102,8 @@ void Reset() BlkCnt = 0; RemBlocks = 0; + OutputFlush = false; + InputDMASize = 0; OutputDMASize = 0; AESMode = 0; @@ -114,6 +119,10 @@ void Reset() // initialize keys, as per GBAtek + // slot 0: modcrypt + *(u32*)&KeyX[0][0] = 0x746E694E; + *(u32*)&KeyX[0][4] = 0x6F646E65; + // slot 3: console-unique eMMC crypto *(u32*)&KeyX[3][0] = (u32)DSi::ConsoleID; *(u32*)&KeyX[3][4] = (u32)DSi::ConsoleID ^ 0x24EE6906; @@ -135,13 +144,13 @@ void ProcessBlock_CTR() *(u32*)&data[8] = InputFIFO->Read(); *(u32*)&data[12] = InputFIFO->Read(); - //printf("AES-CTR: INPUT: "); _printhex(data, 16); + //printf("AES-CTR: "); _printhex2(data, 16); Swap16(data_rev, data); AES_CTR_xcrypt_buffer(&Ctx, data_rev, 16); Swap16(data, data_rev); - //printf("AES-CTR: OUTPUT: "); _printhex(data, 16); + //printf(" -> "); _printhex(data, 16); OutputFIFO->Write(*(u32*)&data[0]); OutputFIFO->Write(*(u32*)&data[4]); @@ -165,8 +174,11 @@ void WriteCnt(u32 val) u32 oldcnt = Cnt; Cnt = val & 0xFC1FF000; - if (val & (1<<10)) InputFIFO->Clear(); - if (val & (1<<11)) OutputFIFO->Clear(); + /*if (val & (3<<10)) + { + if (val & (1<<11)) OutputFlush = true; + Update(); + }*/ u32 dmasize[4] = {4, 8, 12, 16}; InputDMASize = dmasize[3 - ((val >> 12) & 0x3)]; @@ -208,8 +220,19 @@ u32 ReadOutputFIFO() { u32 ret = OutputFIFO->Read(); - CheckInputDMA(); - CheckOutputDMA(); + if (Cnt & (1<<31)) + { + CheckInputDMA(); + CheckOutputDMA(); + } + else + { + if (OutputFIFO->Level() > 0) + DSi::CheckNDMAs(1, 0x2B); + else + DSi::StopNDMAs(1, 0x2B); + } + return ret; } @@ -226,6 +249,8 @@ void WriteInputFIFO(u32 val) void CheckInputDMA() { + if (RemBlocks == 0) return; + if (InputFIFO->Level() < InputDMASize) { // trigger input DMA @@ -270,7 +295,12 @@ void Update() Cnt &= ~(1<<31); if (Cnt & (1<<30)) NDS::SetIRQ2(NDS::IRQ2_DSi_AES); DSi::StopNDMAs(1, 0x2A); - DSi::StopNDMAs(1, 0x2B); + + if (OutputFIFO->Level() > 0) + DSi::CheckNDMAs(1, 0x2B); + else + DSi::StopNDMAs(1, 0x2B); + OutputFlush = false; } } @@ -298,8 +328,8 @@ void DeriveNormalKey(u32 slot) const u8 key_const[16] = {0xFF, 0xFE, 0xFB, 0x4E, 0x29, 0x59, 0x02, 0x58, 0x2A, 0x68, 0x0F, 0x5F, 0x1A, 0x4F, 0x3E, 0x79}; u8 tmp[16]; - //printf("keyX: "); _printhex(KeyX[slot], 16); - //printf("keyY: "); _printhex(KeyY[slot], 16); + //printf("slot%d keyX: ", slot); _printhex(KeyX[slot], 16); + //printf("slot%d keyY: ", slot); _printhex(KeyY[slot], 16); for (int i = 0; i < 16; i++) tmp[i] = KeyX[slot][i] ^ KeyY[slot][i]; -- cgit v1.2.3 From 5dd7fe05a895a0b6a25be62a579bdc120d4a2f35 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 20 Jun 2019 01:54:40 +0200 Subject: add some registers someday I should implement the SCFG shit correctly --- src/DSi.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index 53c7135..c8d4c7d 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -980,6 +980,8 @@ u8 ARM9IORead8(u32 addr) { switch (addr) { + case 0x04004000: return 1; + CASE_READ8_32BIT(0x04004040, MBK[0][0]) CASE_READ8_32BIT(0x04004044, MBK[0][1]) CASE_READ8_32BIT(0x04004048, MBK[0][2]) @@ -1018,6 +1020,7 @@ u32 ARM9IORead32(u32 addr) { switch (addr) { + case 0x04004008: return 0x8307F100; case 0x04004010: return 1; // todo case 0x04004040: return MBK[0][0]; @@ -1097,6 +1100,46 @@ void ARM9IOWrite16(u32 addr, u16 val) { switch (addr) { + case 0x04004040: + MapNWRAM_A(0, val & 0xFF); + MapNWRAM_A(1, val >> 8); + return; + case 0x04004042: + MapNWRAM_A(2, val & 0xFF); + MapNWRAM_A(3, val >> 8); + return; + case 0x04004044: + MapNWRAM_B(0, val & 0xFF); + MapNWRAM_B(1, val >> 8); + return; + case 0x04004046: + MapNWRAM_B(2, val & 0xFF); + MapNWRAM_B(3, val >> 8); + return; + case 0x04004048: + MapNWRAM_B(4, val & 0xFF); + MapNWRAM_B(5, val >> 8); + return; + case 0x0400404A: + MapNWRAM_B(6, val & 0xFF); + MapNWRAM_B(7, val >> 8); + return; + case 0x0400404C: + MapNWRAM_C(0, val & 0xFF); + MapNWRAM_C(1, val >> 8); + return; + case 0x0400404E: + MapNWRAM_C(2, val & 0xFF); + MapNWRAM_C(3, val >> 8); + return; + case 0x04004050: + MapNWRAM_C(4, val & 0xFF); + MapNWRAM_C(5, val >> 8); + return; + case 0x04004052: + MapNWRAM_C(6, val & 0xFF); + MapNWRAM_C(7, val >> 8); + return; } return NDS::ARM9IOWrite16(addr, val); @@ -1106,6 +1149,36 @@ void ARM9IOWrite32(u32 addr, u32 val) { switch (addr) { + case 0x04004040: + MapNWRAM_A(0, val & 0xFF); + MapNWRAM_A(1, (val >> 8) & 0xFF); + MapNWRAM_A(2, (val >> 16) & 0xFF); + MapNWRAM_A(3, val >> 24); + return; + case 0x04004044: + MapNWRAM_B(0, val & 0xFF); + MapNWRAM_B(1, (val >> 8) & 0xFF); + MapNWRAM_B(2, (val >> 16) & 0xFF); + MapNWRAM_B(3, val >> 24); + return; + case 0x04004048: + MapNWRAM_B(4, val & 0xFF); + MapNWRAM_B(5, (val >> 8) & 0xFF); + MapNWRAM_B(6, (val >> 16) & 0xFF); + MapNWRAM_B(7, val >> 24); + return; + case 0x0400404C: + MapNWRAM_C(0, val & 0xFF); + MapNWRAM_C(1, (val >> 8) & 0xFF); + MapNWRAM_C(2, (val >> 16) & 0xFF); + MapNWRAM_C(3, val >> 24); + return; + case 0x04004050: + MapNWRAM_C(4, val & 0xFF); + MapNWRAM_C(5, (val >> 8) & 0xFF); + MapNWRAM_C(6, (val >> 16) & 0xFF); + MapNWRAM_C(7, val >> 24); + return; case 0x04004054: MapNWRAMRange(0, 0, val); return; case 0x04004058: MapNWRAMRange(0, 1, val); return; case 0x0400405C: MapNWRAMRange(0, 2, val); return; -- cgit v1.2.3 From 000aa1f327c0fcfa627953fcb732884aec6867b1 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 20 Jun 2019 02:31:46 +0200 Subject: add LCD init flag in DISPSTAT --- src/DSi.cpp | 7 +++++-- src/GPU.cpp | 2 +- src/NDS.cpp | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index c8d4c7d..ee9d21c 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -21,8 +21,7 @@ #include "NDS.h" #include "DSi.h" #include "ARM.h" -#include "tiny-AES-c/aes.hpp" -#include "sha1/sha1.h" +#include "GPU.h" #include "Platform.h" #include "DSi_NDMA.h" @@ -121,6 +120,10 @@ void Reset() SDMMC->Reset(); SDIO->Reset(); + + // LCD init flag + GPU::DispStat[0] |= (1<<6); + GPU::DispStat[1] |= (1<<6); } bool LoadBIOS() diff --git a/src/GPU.cpp b/src/GPU.cpp index dcd79b4..0eb321c 100644 --- a/src/GPU.cpp +++ b/src/GPU.cpp @@ -20,7 +20,7 @@ #include #include "NDS.h" #include "GPU.h" -u64 vbltime; + namespace GPU { diff --git a/src/NDS.cpp b/src/NDS.cpp index 7513d57..6622373 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -1600,6 +1600,21 @@ void debug(u32 param) fwrite(&val, 4, 1, shit); } fclose(shit);*/ + FILE* + shit = fopen("debug/dump9.bin", "wb"); + for (u32 i = 0x02000000; i < 0x04000000; i+=4) + { + u32 val = DSi::ARM9Read32(i); + fwrite(&val, 4, 1, shit); + } + fclose(shit); + shit = fopen("debug/dump7.bin", "wb"); + for (u32 i = 0x02000000; i < 0x04000000; i+=4) + { + u32 val = DSi::ARM7Read32(i); + fwrite(&val, 4, 1, shit); + } + fclose(shit); } -- cgit v1.2.3 From d943a51b9658e1898f49b6773f85778ae7348400 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 20 Jun 2019 03:19:51 +0200 Subject: ayyy getting there! --- src/DSi.cpp | 2 +- src/DSi_I2C.cpp | 9 ++++----- src/DSi_NDMA.cpp | 4 ++-- src/DSi_SD.cpp | 5 ++++- src/NDS.cpp | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index ee9d21c..0e35d53 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -1239,7 +1239,7 @@ u8 ARM7IORead8(u32 addr) CASE_READ8_32BIT(0x04004060, MBK[1][8]) case 0x04004500: return DSi_I2C::ReadData(); - case 0x04004501: printf("read I2C CNT %02X\n", DSi_I2C::Cnt); return DSi_I2C::Cnt; + case 0x04004501: return DSi_I2C::Cnt; case 0x04004D00: return ConsoleID & 0xFF; case 0x04004D01: return (ConsoleID >> 8) & 0xFF; diff --git a/src/DSi_I2C.cpp b/src/DSi_I2C.cpp index 8b01b0e..845dd9d 100644 --- a/src/DSi_I2C.cpp +++ b/src/DSi_I2C.cpp @@ -152,7 +152,7 @@ void Reset() void WriteCnt(u8 val) { - printf("I2C: write CNT %02X\n", val); + //printf("I2C: write CNT %02X\n", val); // TODO: check ACK flag // TODO: transfer delay @@ -174,7 +174,7 @@ void WriteCnt(u8 val) default: Data = 0; break; } - printf("I2C read, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); + //printf("I2C read, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); } else { @@ -184,7 +184,7 @@ void WriteCnt(u8 val) if (val & (1<<1)) { Device = Data & 0xFE; - printf("I2C: %s start, device=%02X\n", (Data&0x01)?"read":"write", Device); + //printf("I2C: %s start, device=%02X\n", (Data&0x01)?"read":"write", Device); switch (Device) { @@ -193,7 +193,7 @@ void WriteCnt(u8 val) } else { - printf("I2C write, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); + //printf("I2C write, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); switch (Device) { @@ -212,7 +212,6 @@ void WriteCnt(u8 val) u8 ReadData() { - printf("I2C: read the data: %02X\n", Data); return Data; } diff --git a/src/DSi_NDMA.cpp b/src/DSi_NDMA.cpp index a62904a..37eb687 100644 --- a/src/DSi_NDMA.cpp +++ b/src/DSi_NDMA.cpp @@ -135,8 +135,8 @@ void DSi_NDMA::Start() // TODO eventually: not stop if we're running code in ITCM - if (SubblockTimer & 0xFFFF) - printf("TODO! NDMA SUBBLOCK TIMER: %08X\n", SubblockTimer); + //if (SubblockTimer & 0xFFFF) + // printf("TODO! NDMA SUBBLOCK TIMER: %08X\n", SubblockTimer); if (NDS::DMAsRunning(CPU)) Running = 1; diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index fbb2e14..3764a3c 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -218,6 +218,8 @@ u16 DSi_SDHost::Read(u32 addr) case 0x026: return BlockLen16; case 0x028: return SDOption; + case 0x02C: return 0; // TODO + case 0x030: // FIFO16 { // TODO: decrement BlockLen???? @@ -275,7 +277,7 @@ u16 DSi_SDHost::Read(u32 addr) case 0x108: return BlockCount32; } - printf("unknown %s read %08X\n", SD_DESC, addr); + printf("unknown %s read %08X @ %08X\n", SD_DESC, addr, NDS::GetPC(1)); return 0; } @@ -356,6 +358,7 @@ void DSi_SDHost::Write(u32 addr, u16 val) break; } } + else printf("%s: SENDING CMD %04X TO NULL DEVICE\n", SD_DESC, val); } return; diff --git a/src/NDS.cpp b/src/NDS.cpp index 6622373..61cf547 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -1600,7 +1600,7 @@ void debug(u32 param) fwrite(&val, 4, 1, shit); } fclose(shit);*/ - FILE* + /*FILE* shit = fopen("debug/dump9.bin", "wb"); for (u32 i = 0x02000000; i < 0x04000000; i+=4) { @@ -1614,7 +1614,7 @@ void debug(u32 param) u32 val = DSi::ARM7Read32(i); fwrite(&val, 4, 1, shit); } - fclose(shit); + fclose(shit);*/ } -- cgit v1.2.3 From 6c60e97a6312b04771f9a90baf573518eb3572d4 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 20 Jun 2019 22:42:28 +0200 Subject: fix another AES bug --- src/DSi_AES.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/DSi_AES.cpp b/src/DSi_AES.cpp index e218315..7f962fd 100644 --- a/src/DSi_AES.cpp +++ b/src/DSi_AES.cpp @@ -180,9 +180,10 @@ void WriteCnt(u32 val) Update(); }*/ - u32 dmasize[4] = {4, 8, 12, 16}; - InputDMASize = dmasize[3 - ((val >> 12) & 0x3)]; - OutputDMASize = dmasize[(val >> 14) & 0x3]; + u32 dmasize_in[4] = {0, 4, 8, 12}; + u32 dmasize_out[4] = {4, 8, 12, 16}; + InputDMASize = dmasize_in[(val >> 12) & 0x3]; + OutputDMASize = dmasize_out[(val >> 14) & 0x3]; AESMode = (val >> 28) & 0x3; if (AESMode < 2) printf("AES-CCM TODO\n"); @@ -251,7 +252,7 @@ void CheckInputDMA() { if (RemBlocks == 0) return; - if (InputFIFO->Level() < InputDMASize) + if (InputFIFO->Level() <= InputDMASize) { // trigger input DMA DSi::CheckNDMAs(1, 0x2A); -- cgit v1.2.3 From ed6b85bf33188fba010279adaa54f397daff7c86 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 20 Jun 2019 23:05:32 +0200 Subject: implement SD/MMC write (cmd25) --- src/DSi_SD.cpp | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/DSi_SD.h | 3 ++ 2 files changed, 112 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index 3764a3c..f1547d4 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -163,6 +163,42 @@ void DSi_SDHost::FinishSend(u32 param) //if (param & 0x2) host->SetIRQ(2); } +void DSi_SDHost::FinishReceive(u32 param) +{ + DSi_SDHost* host = (param & 0x1) ? DSi::SDIO : DSi::SDMMC; + DSi_SDDevice* dev = host->Ports[host->PortSelect & 0x1]; + + //host->CurFIFO ^= 1; + + host->ClearIRQ(24); + + if (host->BlockCountInternal <= 0) + { + printf("%s: data32 TX complete", (param&0x1)?"SDIO":"SD/MMC"); + + if (host->StopAction & (1<<8)) + { + printf(", sending CMD12"); + if (dev) dev->SendCMD(12, 0); + } + + printf("\n"); + + // CHECKME: presumably IRQ2 should not trigger here, but rather + // when the data transfer is done + //SetIRQ(0); + host->SetIRQ(2); + } + else + { + host->BlockCountInternal--; + + if (dev) dev->ContinueTransfer(); + } + + host->SetIRQ(25); +} + void DSi_SDHost::SendData(u8* data, u32 len) { printf("%s: data RX, len=%d, blkcnt=%d (%d) blklen=%d, irq=%08X\n", SD_DESC, len, BlockCount16, BlockCountInternal, BlockLen16, IRQMask); @@ -185,6 +221,24 @@ void DSi_SDHost::SendData(u8* data, u32 len) NDS::ScheduleEvent(NDS::Event_DSi_SDTransfer, false, 512, FinishSend, param); } +void DSi_SDHost::ReceiveData(u8* data, u32 len) +{ + printf("%s: data TX, len=%d, blkcnt=%d (%d) blklen=%d, irq=%08X\n", SD_DESC, len, BlockCount16, BlockCountInternal, BlockLen16, IRQMask); + if (len != BlockLen16) printf("!! BAD BLOCKLEN\n"); + + bool last = (BlockCountInternal == 0); + + u32 f = CurFIFO; + for (u32 i = 0; i < len; i += 2) + *(u16*)&data[i] = DataFIFO[f]->Read(); + + CurFIFO ^= 1; + + // TODO: determine what the delay should be! + u32 param = Num | (last << 1); + NDS::ScheduleEvent(NDS::Event_DSi_SDTransfer, false, 512, FinishReceive, param); +} + u16 DSi_SDHost::Read(u32 addr) { @@ -423,7 +477,21 @@ void DSi_SDHost::Write(u32 addr, u16 val) void DSi_SDHost::WriteFIFO32(u32 val) { - // + if (DataMode != 1) return; + + u32 f = CurFIFO; + if (DataFIFO[f]->IsFull()) + { + // TODO + printf("!!!! %s FIFO FULL\n", SD_DESC); + return; + } + + DataFIFO[f]->Write(val & 0xFFFF); + DataFIFO[f]->Write(val >> 16); + + ClearIRQ(25); + SetIRQ(24); } @@ -513,6 +581,7 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param) case 12: // stop operation SetState(0x04); + if (File) fflush(File); Host->SendResponse(CSR, true); return; @@ -547,6 +616,21 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param) SetState(0x05); return; + case 25: // write multiple blocks + printf("WRITE_MULTIPLE_BLOCKS addr=%08X size=%08X\n", param, BlockSize); + RWAddress = param; + if (OCR & (1<<30)) + { + RWAddress <<= 9; + BlockSize = 512; + } + RWCommand = 25; + Host->SendResponse(CSR, true); + WriteBlock(RWAddress); + RWAddress += BlockSize; + SetState(0x06); + return; + case 55: // ?? CSR |= (1<<5); Host->SendResponse(CSR, true); @@ -597,7 +681,17 @@ void DSi_MMCStorage::SendACMD(u8 cmd, u32 param) void DSi_MMCStorage::ContinueTransfer() { - ReadBlock(RWAddress); + switch (RWCommand) + { + case 18: + ReadBlock(RWAddress); + break; + + case 25: + WriteBlock(RWAddress); + break; + } + RWAddress += BlockSize; } @@ -608,7 +702,19 @@ void DSi_MMCStorage::ReadBlock(u64 addr) printf("SD/MMC: reading block @ %08X, len=%08X\n", addr, BlockSize); u8 data[0x200]; - fseek(File, addr, SEEK_SET); // TODO: adjust for SDHC/etc + fseek(File, addr, SEEK_SET); fread(data, 1, BlockSize, File); Host->SendData(data, BlockSize); } + +void DSi_MMCStorage::WriteBlock(u64 addr) +{ + if (!File) return; + + printf("SD/MMC: write block @ %08X, len=%08X\n", addr, BlockSize); + + u8 data[0x200]; + Host->ReceiveData(data, BlockSize); + fseek(File, addr, SEEK_SET); + fwrite(data, 1, BlockSize, File); +} diff --git a/src/DSi_SD.h b/src/DSi_SD.h index 3c76872..855dd5e 100644 --- a/src/DSi_SD.h +++ b/src/DSi_SD.h @@ -37,8 +37,10 @@ public: void DoSavestate(Savestate* file); static void FinishSend(u32 param); + static void FinishReceive(u32 param); void SendResponse(u32 val, bool last); void SendData(u8* data, u32 len); + void ReceiveData(u8* data, u32 len); u16 Read(u32 addr); void Write(u32 addr, u16 val); @@ -126,6 +128,7 @@ private: void SetState(u32 state) { CSR &= ~(0xF << 9); CSR |= (state << 9); } void ReadBlock(u64 addr); + void WriteBlock(u64 addr); }; #endif // DSI_SD_H -- cgit v1.2.3 From 1bd7243edc206fe56d34534bc5bd6260aaf943fe Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 20 Jun 2019 23:20:08 +0200 Subject: make it actually not crapo the NAND --- src/DSi_SD.cpp | 81 ++++++++++++++++++++++++++++------------------------------ src/DSi_SD.h | 1 - 2 files changed, 39 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index f1547d4..0da4283 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -163,42 +163,6 @@ void DSi_SDHost::FinishSend(u32 param) //if (param & 0x2) host->SetIRQ(2); } -void DSi_SDHost::FinishReceive(u32 param) -{ - DSi_SDHost* host = (param & 0x1) ? DSi::SDIO : DSi::SDMMC; - DSi_SDDevice* dev = host->Ports[host->PortSelect & 0x1]; - - //host->CurFIFO ^= 1; - - host->ClearIRQ(24); - - if (host->BlockCountInternal <= 0) - { - printf("%s: data32 TX complete", (param&0x1)?"SDIO":"SD/MMC"); - - if (host->StopAction & (1<<8)) - { - printf(", sending CMD12"); - if (dev) dev->SendCMD(12, 0); - } - - printf("\n"); - - // CHECKME: presumably IRQ2 should not trigger here, but rather - // when the data transfer is done - //SetIRQ(0); - host->SetIRQ(2); - } - else - { - host->BlockCountInternal--; - - if (dev) dev->ContinueTransfer(); - } - - host->SetIRQ(25); -} - void DSi_SDHost::SendData(u8* data, u32 len) { printf("%s: data RX, len=%d, blkcnt=%d (%d) blklen=%d, irq=%08X\n", SD_DESC, len, BlockCount16, BlockCountInternal, BlockLen16, IRQMask); @@ -233,10 +197,6 @@ void DSi_SDHost::ReceiveData(u8* data, u32 len) *(u16*)&data[i] = DataFIFO[f]->Read(); CurFIFO ^= 1; - - // TODO: determine what the delay should be! - u32 param = Num | (last << 1); - NDS::ScheduleEvent(NDS::Event_DSi_SDTransfer, false, 512, FinishReceive, param); } @@ -479,6 +439,7 @@ void DSi_SDHost::WriteFIFO32(u32 val) { if (DataMode != 1) return; + DSi_SDDevice* dev = Ports[PortSelect & 0x1]; u32 f = CurFIFO; if (DataFIFO[f]->IsFull()) { @@ -490,8 +451,41 @@ void DSi_SDHost::WriteFIFO32(u32 val) DataFIFO[f]->Write(val & 0xFFFF); DataFIFO[f]->Write(val >> 16); - ClearIRQ(25); - SetIRQ(24); + if (DataFIFO[f]->Level() < (BlockLen16>>1)) + { + ClearIRQ(25); + SetIRQ(24); + return; + } + + // we completed one block, send it to the SD card + + ClearIRQ(24); + SetIRQ(25); + + if (dev) dev->ContinueTransfer(); + + if (BlockCountInternal <= 1) + { + printf("%s: data32 TX complete", SD_DESC); + + if (StopAction & (1<<8)) + { + printf(", sending CMD12"); + if (dev) dev->SendCMD(12, 0); + } + + printf("\n"); + + // CHECKME: presumably IRQ2 should not trigger here, but rather + // when the data transfer is done + //SetIRQ(0); + SetIRQ(2); + } + else + { + BlockCountInternal--; + } } @@ -582,6 +576,7 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param) case 12: // stop operation SetState(0x04); if (File) fflush(File); + RWCommand = 0; Host->SendResponse(CSR, true); return; @@ -681,6 +676,8 @@ void DSi_MMCStorage::SendACMD(u8 cmd, u32 param) void DSi_MMCStorage::ContinueTransfer() { + if (RWCommand == 0) return; + switch (RWCommand) { case 18: diff --git a/src/DSi_SD.h b/src/DSi_SD.h index 855dd5e..007a8a8 100644 --- a/src/DSi_SD.h +++ b/src/DSi_SD.h @@ -37,7 +37,6 @@ public: void DoSavestate(Savestate* file); static void FinishSend(u32 param); - static void FinishReceive(u32 param); void SendResponse(u32 val, bool last); void SendData(u8* data, u32 len); void ReceiveData(u8* data, u32 len); -- cgit v1.2.3 From 1d138c058962d71f77e03d29234743dd3cd7dec9 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 20 Jun 2019 23:34:32 +0200 Subject: add SCFG_MC --- src/DSi.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index 0e35d53..8f35d91 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -44,6 +44,8 @@ namespace DSi u32 BootAddr[2]; +u32 SCFG_MC; + u32 MBK[2][9]; u8 NWRAM_A[0x40000]; @@ -121,6 +123,8 @@ void Reset() SDMMC->Reset(); SDIO->Reset(); + SCFG_MC = 0x0011; + // LCD init flag GPU::DispStat[0] |= (1<<6); GPU::DispStat[1] |= (1<<6); @@ -1004,6 +1008,7 @@ u16 ARM9IORead16(u32 addr) switch (addr) { case 0x04004004: return 0; // TODO + case 0x04004010: return SCFG_MC & 0xFFFF; CASE_READ16_32BIT(0x04004040, MBK[0][0]) CASE_READ16_32BIT(0x04004044, MBK[0][1]) @@ -1024,7 +1029,7 @@ u32 ARM9IORead32(u32 addr) switch (addr) { case 0x04004008: return 0x8307F100; - case 0x04004010: return 1; // todo + case 0x04004010: return SCFG_MC & 0xFFFF; case 0x04004040: return MBK[0][0]; case 0x04004044: return MBK[0][1]; @@ -1264,6 +1269,7 @@ u16 ARM7IORead16(u32 addr) case 0x04004004: return 0x0187; case 0x04004006: return 0; // JTAG register + case 0x04004010: return SCFG_MC & 0xFFFF; CASE_READ16_32BIT(0x04004040, MBK[1][0]) CASE_READ16_32BIT(0x04004044, MBK[1][1]) @@ -1302,6 +1308,7 @@ u32 ARM7IORead32(u32 addr) case 0x0400021C: return NDS::IF2; case 0x04004008: return 0x80000000; // HAX + case 0x04004010: return SCFG_MC; case 0x04004040: return MBK[1][0]; case 0x04004044: return MBK[1][1]; @@ -1382,6 +1389,13 @@ void ARM7IOWrite16(u32 addr, u16 val) { case 0x04000218: NDS::IE2 = (val & 0x7FF7); NDS::UpdateIRQ(1); return; case 0x0400021C: NDS::IF2 &= ~(val & 0x7FF7); NDS::UpdateIRQ(1); return; + + case 0x04004010: + val &= 0x800C; + if ((val & 0xC) == 0xC) val &= ~0xC; // hax + if (val & 0x8000) printf("SCFG_MC: weird NDS slot swap\n"); + SCFG_MC = (SCFG_MC & ~0x800C) | val; + return; } if (addr >= 0x04004800 && addr < 0x04004A00) @@ -1405,6 +1419,13 @@ void ARM7IOWrite32(u32 addr, u32 val) case 0x04000218: NDS::IE2 = (val & 0x7FF7); NDS::UpdateIRQ(1); return; case 0x0400021C: NDS::IF2 &= ~(val & 0x7FF7); NDS::UpdateIRQ(1); return; + case 0x04004010: + val &= 0xFFFF800C; + if ((val & 0xC) == 0xC) val &= ~0xC; // hax + if (val & 0x8000) printf("SCFG_MC: weird NDS slot swap\n"); + SCFG_MC = (SCFG_MC & ~0xFFFF800C) | val; + return; + case 0x04004054: MapNWRAMRange(1, 0, val); return; case 0x04004058: MapNWRAMRange(1, 1, val); return; case 0x0400405C: MapNWRAMRange(1, 2, val); return; -- cgit v1.2.3 From 8c6429095824ce42a354e1def86a45a19a3b1d90 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Fri, 21 Jun 2019 00:07:57 +0200 Subject: make it work better --- src/DSi_SD.cpp | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index 0da4283..7367eea 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -190,13 +190,34 @@ void DSi_SDHost::ReceiveData(u8* data, u32 len) printf("%s: data TX, len=%d, blkcnt=%d (%d) blklen=%d, irq=%08X\n", SD_DESC, len, BlockCount16, BlockCountInternal, BlockLen16, IRQMask); if (len != BlockLen16) printf("!! BAD BLOCKLEN\n"); - bool last = (BlockCountInternal == 0); - + DSi_SDDevice* dev = Ports[PortSelect & 0x1]; u32 f = CurFIFO; for (u32 i = 0; i < len; i += 2) *(u16*)&data[i] = DataFIFO[f]->Read(); CurFIFO ^= 1; + + if (BlockCountInternal <= 1) + { + printf("%s: data32 TX complete", SD_DESC); + + if (StopAction & (1<<8)) + { + printf(", sending CMD12"); + if (dev) dev->SendCMD(12, 0); + } + + printf("\n"); + + // CHECKME: presumably IRQ2 should not trigger here, but rather + // when the data transfer is done + //SetIRQ(0); + SetIRQ(2); + } + else + { + BlockCountInternal--; + } } @@ -464,28 +485,6 @@ void DSi_SDHost::WriteFIFO32(u32 val) SetIRQ(25); if (dev) dev->ContinueTransfer(); - - if (BlockCountInternal <= 1) - { - printf("%s: data32 TX complete", SD_DESC); - - if (StopAction & (1<<8)) - { - printf(", sending CMD12"); - if (dev) dev->SendCMD(12, 0); - } - - printf("\n"); - - // CHECKME: presumably IRQ2 should not trigger here, but rather - // when the data transfer is done - //SetIRQ(0); - SetIRQ(2); - } - else - { - BlockCountInternal--; - } } -- cgit v1.2.3 From 851e255b4099904b4784fa7e1c672f03e5ca531b Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 2 Jul 2019 23:46:39 +0200 Subject: * AES-CCM decrypt * fix a bunch of bugs --- src/DSi.cpp | 36 +++++++++++++-- src/DSi_AES.cpp | 134 +++++++++++++++++++++++++++++++++++++++++++++++++------ src/DSi_NDMA.cpp | 3 ++ src/DSi_SD.cpp | 23 +++++++--- src/DSi_SD.h | 1 + src/SPU.cpp | 7 ++- 6 files changed, 180 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index 8f35d91..e601da9 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -44,6 +44,8 @@ namespace DSi u32 BootAddr[2]; +u16 SCFG_Clock9; +u16 SCFG_Clock7; u32 SCFG_MC; u32 MBK[2][9]; @@ -123,11 +125,19 @@ void Reset() SDMMC->Reset(); SDIO->Reset(); + SCFG_Clock9 = 0x0187; // CHECKME + SCFG_Clock7 = 0x0187; SCFG_MC = 0x0011; // LCD init flag GPU::DispStat[0] |= (1<<6); GPU::DispStat[1] |= (1<<6); + + NDS::MapSharedWRAM(3); + + // TEST + u8 derp[16] = {0xE5, 0xCC, 0x5A, 0x8B, 0x56, 0xD0, 0xC9, 0x72, 0x9C, 0x17, 0xE8, 0xDC, 0x39, 0x12, 0x36, 0xA9}; + for (int i = 0; i < 16; i+=4) ARM7Write32(0x03FFC580+i, *(u32*)&derp[i]); } bool LoadBIOS() @@ -1007,7 +1017,7 @@ u16 ARM9IORead16(u32 addr) { switch (addr) { - case 0x04004004: return 0; // TODO + case 0x04004004: return SCFG_Clock9; case 0x04004010: return SCFG_MC & 0xFFFF; CASE_READ16_32BIT(0x04004040, MBK[0][0]) @@ -1079,6 +1089,16 @@ void ARM9IOWrite8(u32 addr, u8 val) { switch (addr) { + case 0x04000301: + // TODO: OPTIONAL PERFORMANCE HACK + // the DSi ARM9 BIOS has a bug where the IRQ wait function attempts to use (ARM7-only) HALTCNT + // effectively causing it to wait in a busy loop. + // for better DSi performance, we can implement an actual IRQ wait here. + // in practice this would only matter when running DS software in DSi mode (ie already a hack). + // DSi software does not use the BIOS IRQ wait function. + //if (val == 0x80 && NDS::ARM9->R[15] == 0xFFFF0268) NDS::ARM9->Halt(1); + return; + case 0x04004040: MapNWRAM_A(0, val); return; case 0x04004041: MapNWRAM_A(1, val); return; case 0x04004042: MapNWRAM_A(2, val); return; @@ -1108,6 +1128,12 @@ void ARM9IOWrite16(u32 addr, u16 val) { switch (addr) { + case 0x04004004: + // TODO: actually change clock! + printf("CLOCK9=%04X\n", val); + SCFG_Clock9 = val & 0x0187; + return; + case 0x04004040: MapNWRAM_A(0, val & 0xFF); MapNWRAM_A(1, val >> 8); @@ -1267,7 +1293,7 @@ u16 ARM7IORead16(u32 addr) case 0x04000218: return NDS::IE2; case 0x0400021C: return NDS::IF2; - case 0x04004004: return 0x0187; + case 0x04004004: return SCFG_Clock7; case 0x04004006: return 0; // JTAG register case 0x04004010: return SCFG_MC & 0xFFFF; @@ -1390,6 +1416,10 @@ void ARM7IOWrite16(u32 addr, u16 val) case 0x04000218: NDS::IE2 = (val & 0x7FF7); NDS::UpdateIRQ(1); return; case 0x0400021C: NDS::IF2 &= ~(val & 0x7FF7); NDS::UpdateIRQ(1); return; + case 0x04004004: + SCFG_Clock7 = val & 0x0187; + return; + case 0x04004010: val &= 0x800C; if ((val & 0xC) == 0xC) val &= ~0xC; // hax @@ -1482,7 +1512,7 @@ void ARM7IOWrite32(u32 addr, u32 val) { addr -= 0x04004440; int n = 0; - while (addr > 0x30) { addr -= 0x30; n++; } + while (addr >= 0x30) { addr -= 0x30; n++; } switch (addr >> 4) { diff --git a/src/DSi_AES.cpp b/src/DSi_AES.cpp index 7f962fd..8ae9082 100644 --- a/src/DSi_AES.cpp +++ b/src/DSi_AES.cpp @@ -42,11 +42,14 @@ FIFO* OutputFIFO; u8 IV[16]; +u8 MAC[16]; + u8 KeyNormal[4][16]; u8 KeyX[4][16]; u8 KeyY[4][16]; u8 CurKey[16]; +u8 CurMAC[16]; AES_ctx Ctx; @@ -77,6 +80,9 @@ void ROL16(u8* val, u32 n) #define _printhex(str, size) { for (int z = 0; z < (size); z++) printf("%02X", (str)[z]); printf("\n"); } #define _printhex2(str, size) { for (int z = 0; z < (size); z++) printf("%02X", (str)[z]); } +#define _printhexR(str, size) { for (int z = 0; z < (size); z++) printf("%02X", (str)[((size)-1)-z]); printf("\n"); } +#define _printhex2R(str, size) { for (int z = 0; z < (size); z++) printf("%02X", (str)[((size)-1)-z]); } + bool Init() { @@ -111,11 +117,16 @@ void Reset() InputFIFO->Clear(); OutputFIFO->Clear(); + memset(IV, 0, sizeof(IV)); + + memset(MAC, 0, sizeof(MAC)); + memset(KeyNormal, 0, sizeof(KeyNormal)); memset(KeyX, 0, sizeof(KeyX)); memset(KeyY, 0, sizeof(KeyY)); memset(CurKey, 0, sizeof(CurKey)); + memset(CurMAC, 0, sizeof(CurMAC)); // initialize keys, as per GBAtek @@ -123,6 +134,12 @@ void Reset() *(u32*)&KeyX[0][0] = 0x746E694E; *(u32*)&KeyX[0][4] = 0x6F646E65; + // slot 1: 'Tad'/dev.kp + *(u32*)&KeyX[1][0] = 0x4E00004A; + *(u32*)&KeyX[1][4] = 0x4A00004E; + *(u32*)&KeyX[1][8] = (u32)(DSi::ConsoleID >> 32) ^ 0xC80C4B72; + *(u32*)&KeyX[1][12] = (u32)DSi::ConsoleID; + // slot 3: console-unique eMMC crypto *(u32*)&KeyX[3][0] = (u32)DSi::ConsoleID; *(u32*)&KeyX[3][4] = (u32)DSi::ConsoleID ^ 0x24EE6906; @@ -134,6 +151,34 @@ void Reset() } +void ProcessBlock_CCM_Decrypt() +{ + u8 data[16]; + u8 data_rev[16]; + + *(u32*)&data[0] = InputFIFO->Read(); + *(u32*)&data[4] = InputFIFO->Read(); + *(u32*)&data[8] = InputFIFO->Read(); + *(u32*)&data[12] = InputFIFO->Read(); + + //printf("AES-CCM: "); _printhex2(data, 16); + + Swap16(data_rev, data); + AES_CTR_xcrypt_buffer(&Ctx, data_rev, 16); + + for (int i = 0; i < 16; i++) CurMAC[i] ^= data_rev[i]; + AES_ECB_encrypt(&Ctx, CurMAC); + + Swap16(data, data_rev); + + //printf(" -> "); _printhex2(data, 16); + + OutputFIFO->Write(*(u32*)&data[0]); + OutputFIFO->Write(*(u32*)&data[4]); + OutputFIFO->Write(*(u32*)&data[8]); + OutputFIFO->Write(*(u32*)&data[12]); +} + void ProcessBlock_CTR() { u8 data[16]; @@ -186,18 +231,12 @@ void WriteCnt(u32 val) OutputDMASize = dmasize_out[(val >> 14) & 0x3]; AESMode = (val >> 28) & 0x3; - if (AESMode < 2) printf("AES-CCM TODO\n"); + if (AESMode == 1) printf("AES-CCM TODO\n"); if (val & (1<<24)) { u32 slot = (val >> 26) & 0x3; memcpy(CurKey, KeyNormal[slot], 16); - - //printf("AES: key(%d): ", slot); _printhex(CurKey, 16); - - u8 tmp[16]; - Swap16(tmp, CurKey); - AES_init_ctx(&Ctx, tmp); } if (!(oldcnt & (1<<31)) && (val & (1<<31))) @@ -205,11 +244,45 @@ void WriteCnt(u32 val) // transfer start (checkme) RemBlocks = BlkCnt >> 16; + u8 key[16]; + u8 iv[16]; + + Swap16(key, CurKey); + Swap16(iv, IV); + + if (AESMode < 2) + { + if (BlkCnt & 0xFFFF) printf("AES: CCM EXTRA LEN TODO\n"); + + u32 maclen = (val >> 16) & 0x7; + if (maclen < 1) maclen = 1; + + iv[0] = 0x02; + for (int i = 0; i < 12; i++) iv[1+i] = iv[4+i]; + iv[13] = 0x00; + iv[14] = 0x00; + iv[15] = 0x01; + + AES_init_ctx_iv(&Ctx, key, iv); + + iv[0] |= (maclen << 3) | ((BlkCnt & 0xFFFF) ? (1<<6) : 0); + iv[13] = RemBlocks >> 12; + iv[14] = RemBlocks >> 4; + iv[15] = RemBlocks << 4; + + memcpy(CurMAC, iv, 16); + AES_ECB_encrypt(&Ctx, CurMAC); + } + else + { + AES_init_ctx_iv(&Ctx, key, iv); + } + DSi::CheckNDMAs(1, 0x2A); } - printf("AES CNT: %08X / mode=%d inDMA=%d outDMA=%d blocks=%d\n", - val, AESMode, InputDMASize, OutputDMASize, RemBlocks); + printf("AES CNT: %08X / mode=%d key=%d inDMA=%d outDMA=%d blocks=%d\n", + val, AESMode, (val >> 26) & 0x3, InputDMASize, OutputDMASize, RemBlocks); } void WriteBlkCnt(u32 val) @@ -219,6 +292,8 @@ void WriteBlkCnt(u32 val) u32 ReadOutputFIFO() { + if (OutputFIFO->IsEmpty()) printf("!!! AES OUTPUT FIFO EMPTY\n"); + u32 ret = OutputFIFO->Read(); if (Cnt & (1<<31)) @@ -241,6 +316,8 @@ void WriteInputFIFO(u32 val) { // TODO: add some delay to processing + if (InputFIFO->IsFull()) printf("!!! AES INPUT FIFO FULL\n"); + InputFIFO->Write(val); if (!(Cnt & (1<<31))) return; @@ -276,6 +353,7 @@ void Update() { switch (AESMode) { + case 0: ProcessBlock_CCM_Decrypt(); break; case 2: case 3: ProcessBlock_CTR(); break; default: @@ -293,6 +371,28 @@ void Update() if (RemBlocks == 0) { + if (AESMode == 0) + { + Ctx.Iv[13] = 0x00; + Ctx.Iv[14] = 0x00; + Ctx.Iv[15] = 0x00;_printhex(Ctx.Iv, 16); + AES_CTR_xcrypt_buffer(&Ctx, CurMAC, 16); + + //printf("FINAL MAC: "); _printhexR(CurMAC, 16); + //printf("INPUT MAC: "); _printhex(MAC, 16); + + Cnt |= (1<<21); + for (int i = 0; i < 16; i++) + { + if (CurMAC[15-i] != MAC[i]) Cnt &= ~(1<<21); + } + } + else + { + // CHECKME + Cnt &= ~(1<<21); + } + Cnt &= ~(1<<31); if (Cnt & (1<<30)) NDS::SetIRQ2(NDS::IRQ2_DSi_AES); DSi::StopNDMAs(1, 0x2A); @@ -313,15 +413,15 @@ void WriteIV(u32 offset, u32 val, u32 mask) *(u32*)&IV[offset] = (old & ~mask) | (val & mask); //printf("AES: IV: "); _printhex(IV, 16); - - u8 tmp[16]; - Swap16(tmp, IV); - AES_ctx_set_iv(&Ctx, tmp); } void WriteMAC(u32 offset, u32 val, u32 mask) { - // + u32 old = *(u32*)&MAC[offset]; + + *(u32*)&MAC[offset] = (old & ~mask) | (val & mask); + + //printf("AES: MAC: "); _printhex(MAC, 16); } void DeriveNormalKey(u32 slot) @@ -355,6 +455,8 @@ void WriteKeyNormal(u32 slot, u32 offset, u32 val, u32 mask) u32 old = *(u32*)&KeyNormal[slot][offset]; *(u32*)&KeyNormal[slot][offset] = (old & ~mask) | (val & mask); + + //printf("KeyNormal(%d): ", slot); _printhex(KeyNormal[slot], 16); } void WriteKeyX(u32 slot, u32 offset, u32 val, u32 mask) @@ -362,6 +464,8 @@ void WriteKeyX(u32 slot, u32 offset, u32 val, u32 mask) u32 old = *(u32*)&KeyX[slot][offset]; *(u32*)&KeyX[slot][offset] = (old & ~mask) | (val & mask); + + //printf("KeyX(%d): ", slot); _printhex(KeyX[slot], 16); } void WriteKeyY(u32 slot, u32 offset, u32 val, u32 mask) @@ -370,6 +474,8 @@ void WriteKeyY(u32 slot, u32 offset, u32 val, u32 mask) *(u32*)&KeyY[slot][offset] = (old & ~mask) | (val & mask); + //printf("[%08X] KeyY(%d): ", NDS::GetPC(1), slot); _printhex(KeyY[slot], 16); + if (offset >= 0xC) { DeriveNormalKey(slot); diff --git a/src/DSi_NDMA.cpp b/src/DSi_NDMA.cpp index 37eb687..e7fc7ab 100644 --- a/src/DSi_NDMA.cpp +++ b/src/DSi_NDMA.cpp @@ -123,7 +123,10 @@ void DSi_NDMA::Start() if (((StartMode & 0x1F) != 0x10) && !(Cnt & (1<<29))) { if (IterCount > TotalRemCount) + { IterCount = TotalRemCount; + RemCount = IterCount; + } } if (Cnt & (1<<12)) CurDstAddr = DstAddr; diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index 7367eea..93431b5 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -185,6 +185,17 @@ void DSi_SDHost::SendData(u8* data, u32 len) NDS::ScheduleEvent(NDS::Event_DSi_SDTransfer, false, 512, FinishSend, param); } +void DSi_SDHost::FinishReceive(u32 param) +{ + DSi_SDHost* host = (param & 0x1) ? DSi::SDIO : DSi::SDMMC; + DSi_SDDevice* dev = host->Ports[host->PortSelect & 0x1]; + + host->ClearIRQ(24); + host->SetIRQ(25); + + if (dev) dev->ContinueTransfer(); +} + void DSi_SDHost::ReceiveData(u8* data, u32 len) { printf("%s: data TX, len=%d, blkcnt=%d (%d) blklen=%d, irq=%08X\n", SD_DESC, len, BlockCount16, BlockCountInternal, BlockLen16, IRQMask); @@ -481,10 +492,12 @@ void DSi_SDHost::WriteFIFO32(u32 val) // we completed one block, send it to the SD card - ClearIRQ(24); - SetIRQ(25); + //ClearIRQ(24); + //SetIRQ(25); - if (dev) dev->ContinueTransfer(); + //if (dev) dev->ContinueTransfer(); + // TODO measure the actual delay!! + NDS::ScheduleEvent(NDS::Event_DSi_SDTransfer, false, 2048, FinishReceive, Num); } @@ -622,10 +635,10 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param) Host->SendResponse(CSR, true); WriteBlock(RWAddress); RWAddress += BlockSize; - SetState(0x06); + SetState(0x04); return; - case 55: // ?? + case 55: // appcmd prefix CSR |= (1<<5); Host->SendResponse(CSR, true); return; diff --git a/src/DSi_SD.h b/src/DSi_SD.h index 007a8a8..855dd5e 100644 --- a/src/DSi_SD.h +++ b/src/DSi_SD.h @@ -37,6 +37,7 @@ public: void DoSavestate(Savestate* file); static void FinishSend(u32 param); + static void FinishReceive(u32 param); void SendResponse(u32 val, bool last); void SendData(u8* data, u32 len); void ReceiveData(u8* data, u32 len); diff --git a/src/SPU.cpp b/src/SPU.cpp index ee9237f..d31a371 100644 --- a/src/SPU.cpp +++ b/src/SPU.cpp @@ -19,6 +19,7 @@ #include #include #include "NDS.h" +#include "DSi.h" #include "SPU.h" @@ -216,7 +217,8 @@ void Channel::FIFO_BufferData() for (u32 i = 0; i < burstlen; i += 4) { - FIFO[FIFOWritePos] = NDS::ARM7Read32(SrcAddr + FIFOReadOffset); + //FIFO[FIFOWritePos] = NDS::ARM7Read32(SrcAddr + FIFOReadOffset); + FIFO[FIFOWritePos] = DSi::ARM7Read32(SrcAddr + FIFOReadOffset); FIFOReadOffset += 4; FIFOWritePos++; FIFOWritePos &= 0x7; @@ -499,7 +501,8 @@ void CaptureUnit::FIFO_FlushData() { for (u32 i = 0; i < 4; i++) { - NDS::ARM7Write32(DstAddr + FIFOWriteOffset, FIFO[FIFOReadPos]); + //NDS::ARM7Write32(DstAddr + FIFOWriteOffset, FIFO[FIFOReadPos]); + DSi::ARM7Write32(DstAddr + FIFOWriteOffset, FIFO[FIFOReadPos]); FIFOReadPos++; FIFOReadPos &= 0x3; -- cgit v1.2.3 From ec042000cfa6b529569dccd5611efc5bfd73cd29 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 3 Jul 2019 00:07:51 +0200 Subject: lay base for DSi wifi --- melonDS.cbp | 2 ++ src/DSi_NWifi.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/DSi_NWifi.h | 39 +++++++++++++++++++++++++++++++++++++++ src/DSi_SD.cpp | 5 ++++- 4 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 src/DSi_NWifi.cpp create mode 100644 src/DSi_NWifi.h (limited to 'src') diff --git a/melonDS.cbp b/melonDS.cbp index 2346093..2fd6ed0 100644 --- a/melonDS.cbp +++ b/melonDS.cbp @@ -110,6 +110,8 @@ + + diff --git a/src/DSi_NWifi.cpp b/src/DSi_NWifi.cpp new file mode 100644 index 0000000..4e5d26d --- /dev/null +++ b/src/DSi_NWifi.cpp @@ -0,0 +1,49 @@ +/* + Copyright 2016-2019 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include +#include +#include "DSi.h" +#include "DSi_NWifi.h" + + +DSi_NWifi::DSi_NWifi(DSi_SDHost* host) : DSi_SDDevice(host) +{ + // +} + +DSi_NWifi::~DSi_NWifi() +{ + // +} + + +void DSi_NWifi::SendCMD(u8 cmd, u32 param) +{ + printf("NWIFI: unknown CMD %d %08X\n", cmd, param); +} + +void DSi_NWifi::SendACMD(u8 cmd, u32 param) +{ + printf("NWIFI: unknown ACMD %d %08X\n", cmd, param); +} + +void DSi_NWifi::ContinueTransfer() +{ + // +} diff --git a/src/DSi_NWifi.h b/src/DSi_NWifi.h new file mode 100644 index 0000000..34c3dd4 --- /dev/null +++ b/src/DSi_NWifi.h @@ -0,0 +1,39 @@ +/* + Copyright 2016-2019 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef DSI_NWIFI_H +#define DSI_NWIFI_H + +#include "DSi_SD.h" + +class DSi_NWifi : public DSi_SDDevice +{ +public: + DSi_NWifi(DSi_SDHost* host); + ~DSi_NWifi(); + + void SendCMD(u8 cmd, u32 param); + void SendACMD(u8 cmd, u32 param); + + void ContinueTransfer(); + +private: + // +}; + +#endif // DSI_NWIFI_H diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index 93431b5..6e73df5 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -20,6 +20,7 @@ #include #include "DSi.h" #include "DSi_SD.h" +#include "DSi_NWifi.h" #include "Platform.h" @@ -94,7 +95,9 @@ void DSi_SDHost::Reset() } else { - // TODO: SDIO (wifi) + DSi_NWifi* nwifi = new DSi_NWifi(this); + + Ports[0] = nwifi; } } -- cgit v1.2.3 From 5062ed543a881af2b1c4a7629d90812afeef945c Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 3 Jul 2019 01:17:23 +0200 Subject: HARK HARK HARK HARK --- src/DSi_NWifi.cpp | 293 +++++++++++++++++++++++++++++++++++++++++++++++++++++- src/DSi_NWifi.h | 16 ++- 2 files changed, 306 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/DSi_NWifi.cpp b/src/DSi_NWifi.cpp index 4e5d26d..5236551 100644 --- a/src/DSi_NWifi.cpp +++ b/src/DSi_NWifi.cpp @@ -22,9 +22,98 @@ #include "DSi_NWifi.h" +const u8 CIS0[256] = +{ + 0x01, 0x03, 0xD9, 0x01, 0xFF, + 0x20, 0x04, 0x71, 0x02, 0x00, 0x02, + 0x21, 0x02, 0x0C, 0x00, + 0x22, 0x04, 0x00, 0x00, 0x08, 0x32, + 0x1A, 0x05, 0x01, 0x01, 0x00, 0x02, 0x07, + 0x1B, 0x08, 0xC1, 0x41, 0x30, 0x30, 0xFF, 0xFF, 0x32, 0x00, + 0x14, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00 +}; + +const u8 CIS1[256] = +{ + 0x20, 0x04, 0x71, 0x02, 0x00, 0x02, + 0x21, 0x02, 0x0C, 0x00, + 0x22, 0x2A, 0x01, + 0x01, 0x11, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x08, + 0x00, 0x00, 0xFF, 0x80, + 0x00, 0x00, 0x00, + 0x00, 0x01, 0x0A, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x01, + 0x00, 0x01, 0x00, 0x01, + 0x80, 0x01, 0x06, + 0x81, 0x01, 0x07, + 0x82, 0x01, 0xDF, + 0xFF, + 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + + DSi_NWifi::DSi_NWifi(DSi_SDHost* host) : DSi_SDDevice(host) { - // + TransferCmd = 0xFFFFFFFF; + RemSize = 0; } DSi_NWifi::~DSi_NWifi() @@ -33,8 +122,149 @@ DSi_NWifi::~DSi_NWifi() } +u8 DSi_NWifi::F0_Read(u32 addr) +{ + switch (addr) + { + case 0x00000: return 0x11; + case 0x00001: return 0x00; + + case 0x00002: return 0x02; // writable?? + case 0x00003: return 0x02; + + case 0x00008: return 0x17; + + case 0x00009: return 0x00; + case 0x0000A: return 0x10; + case 0x0000B: return 0x00; + + case 0x00012: return 0x03; + + case 0x00109: return 0x00; + case 0x0010A: return 0x11; + case 0x0010B: return 0x00; + } + + if (addr >= 0x01000 && addr < 0x01100) + { + return CIS0[addr & 0xFF]; + } + if (addr >= 0x01100 && addr < 0x01200) + { + return CIS1[addr & 0xFF]; + } + + printf("NWIFI: unknown func0 read %05X\n", addr); + return 0; +} + +void DSi_NWifi::F0_Write(u32 addr, u8 val) +{ + printf("NWIFI: unknown func0 write %05X %02X\n", addr, val); +} + + +u8 DSi_NWifi::F1_Read(u32 addr) +{ + switch (addr) + { + } + + printf("NWIFI: unknown func1 read %05X\n", addr); + return 0; +} + +void DSi_NWifi::F1_Write(u32 addr, u8 val) +{ + printf("NWIFI: unknown func1 write %05X %02X\n", addr, val); +} + + +u8 DSi_NWifi::SDIO_Read(u32 func, u32 addr) +{ + switch (func) + { + case 0: return F0_Read(addr); + } + + printf("NWIFI: unknown SDIO read %d %05X\n", func, addr); + return 0; +} + +void DSi_NWifi::SDIO_Write(u32 func, u32 addr, u8 val) +{ + switch (func) + { + case 0: return F0_Write(addr, val); + } + + printf("NWIFI: unknown SDIO write %d %05X %02X\n", func, addr, val); +} + + void DSi_NWifi::SendCMD(u8 cmd, u32 param) { + switch (cmd) + { + case 52: // IO_RW_DIRECT + { + u32 func = (param >> 28) & 0x7; + u32 addr = (param >> 9) & 0x1FFFF; + + if (param & (1<<31)) + { + // write + + u8 val = param & 0xFF; + SDIO_Write(func, addr, val); + if (param & (1<<27)) + val = SDIO_Read(func, addr); // checkme + Host->SendResponse(val | 0x1000, true); + } + else + { + // read + + u8 val = SDIO_Read(func, addr); + Host->SendResponse(val | 0x1000, true); + } + } + return; + + case 53: // IO_RW_EXTENDED + { + u32 addr = (param >> 9) & 0x1FFFF; + + TransferCmd = param; + TransferAddr = addr; + if (param & (1<<27)) + { + RemSize = (param & 0x1FF) << 9; // checkme + } + else + { + RemSize = (param & 0x1FF); + if (!RemSize) RemSize = 0x200; + } + + if (param & (1<<31)) + { + // write + + WriteBlock(); + Host->SendResponse(0x1000, true); + } + else + { + // read + + ReadBlock(); + Host->SendResponse(0x1000, true); + } + } + return; + } + printf("NWIFI: unknown CMD %d %08X\n", cmd, param); } @@ -45,5 +275,64 @@ void DSi_NWifi::SendACMD(u8 cmd, u32 param) void DSi_NWifi::ContinueTransfer() { - // + if (TransferCmd & (1<<31)) + WriteBlock(); + else + ReadBlock(); +} + +void DSi_NWifi::ReadBlock() +{ + u32 func = (TransferCmd >> 28) & 0x7; + u32 len = (TransferCmd & (1<<27)) ? 0x200 : RemSize; + + u8 data[0x200]; + + for (u32 i = 0; i < len; i++) + { + data[i] = SDIO_Read(func, TransferAddr); + if (TransferCmd & (1<<26)) + { + TransferAddr++; + TransferAddr &= 0x1FFFF; // checkme + } + } + Host->SendData(data, len); + + if (RemSize > 0) + { + RemSize -= len; + if (RemSize == 0) + { + // TODO? + } + } +} + +void DSi_NWifi::WriteBlock() +{ + u32 func = (TransferCmd >> 28) & 0x7; + u32 len = (TransferCmd & (1<<27)) ? 0x200 : RemSize; + + u8 data[0x200]; + Host->ReceiveData(data, len); + + for (u32 i = 0; i < len; i++) + { + SDIO_Write(func, TransferAddr, data[i]); + if (TransferCmd & (1<<26)) + { + TransferAddr++; + TransferAddr &= 0x1FFFF; // checkme + } + } + + if (RemSize > 0) + { + RemSize -= len; + if (RemSize == 0) + { + // TODO? + } + } } diff --git a/src/DSi_NWifi.h b/src/DSi_NWifi.h index 34c3dd4..5d61951 100644 --- a/src/DSi_NWifi.h +++ b/src/DSi_NWifi.h @@ -33,7 +33,21 @@ public: void ContinueTransfer(); private: - // + u32 TransferCmd; + u32 TransferAddr; + u32 RemSize; + + u8 F0_Read(u32 addr); + void F0_Write(u32 addr, u8 val); + + u8 F1_Read(u32 addr); + void F1_Write(u32 addr, u8 val); + + u8 SDIO_Read(u32 func, u32 addr); + void SDIO_Write(u32 func, u32 addr, u8 val); + + void ReadBlock(); + void WriteBlock(); }; #endif // DSI_NWIFI_H -- cgit v1.2.3 From c5e14074c3b999d09b8a8612cfa7f011423e83ab Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 3 Jul 2019 12:37:34 +0200 Subject: * add SCFG_EXT * quick hack to detect cartridges --- src/DSi.cpp | 24 +++++++++++++++++++++--- src/DSi.h | 2 ++ src/DSi_I2C.cpp | 8 ++++---- src/NDSCart.cpp | 8 +++++--- 4 files changed, 32 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index e601da9..26a67f4 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -46,6 +46,7 @@ u32 BootAddr[2]; u16 SCFG_Clock9; u16 SCFG_Clock7; +u32 SCFG_EXT[2]; u32 SCFG_MC; u32 MBK[2][9]; @@ -127,7 +128,9 @@ void Reset() SCFG_Clock9 = 0x0187; // CHECKME SCFG_Clock7 = 0x0187; - SCFG_MC = 0x0011; + SCFG_EXT[0] = 0x8307F100; + SCFG_EXT[1] = 0x93FFFB06; + SCFG_MC = 0x0010;//0x0011; // LCD init flag GPU::DispStat[0] |= (1<<6); @@ -1038,7 +1041,7 @@ u32 ARM9IORead32(u32 addr) { switch (addr) { - case 0x04004008: return 0x8307F100; + case 0x04004008: return SCFG_EXT[0]; case 0x04004010: return SCFG_MC & 0xFFFF; case 0x04004040: return MBK[0][0]; @@ -1183,6 +1186,14 @@ void ARM9IOWrite32(u32 addr, u32 val) { switch (addr) { + case 0x04004008: + SCFG_EXT[0] &= ~0x8007F19F; + SCFG_EXT[0] |= (val & 0x8007F19F); + SCFG_EXT[1] &= ~0x0000F080; + SCFG_EXT[1] |= (val & 0x0000F080); + printf("SCFG_EXT = %08X / %08X (val9 %08X)\n", SCFG_EXT[0], SCFG_EXT[1], val); + return; + case 0x04004040: MapNWRAM_A(0, val & 0xFF); MapNWRAM_A(1, (val >> 8) & 0xFF); @@ -1333,7 +1344,7 @@ u32 ARM7IORead32(u32 addr) case 0x04000218: return NDS::IE2; case 0x0400021C: return NDS::IF2; - case 0x04004008: return 0x80000000; // HAX + case 0x04004008: return SCFG_EXT[1]; case 0x04004010: return SCFG_MC; case 0x04004040: return MBK[1][0]; @@ -1449,6 +1460,13 @@ void ARM7IOWrite32(u32 addr, u32 val) case 0x04000218: NDS::IE2 = (val & 0x7FF7); NDS::UpdateIRQ(1); return; case 0x0400021C: NDS::IF2 &= ~(val & 0x7FF7); NDS::UpdateIRQ(1); return; + case 0x04004008: + SCFG_EXT[0] &= ~0x03000000; + SCFG_EXT[0] |= (val & 0x03000000); + SCFG_EXT[1] &= ~0x93FF0F07; + SCFG_EXT[1] |= (val & 0x93FF0F07); + printf("SCFG_EXT = %08X / %08X (val7 %08X)\n", SCFG_EXT[0], SCFG_EXT[1], val); + return; case 0x04004010: val &= 0xFFFF800C; if ((val & 0xC) == 0xC) val &= ~0xC; // hax diff --git a/src/DSi.h b/src/DSi.h index 642a56a..db585b4 100644 --- a/src/DSi.h +++ b/src/DSi.h @@ -31,6 +31,8 @@ extern u64 ConsoleID; extern DSi_SDHost* SDMMC; extern DSi_SDHost* SDIO; +extern u8 ITCMInit[0x8000]; + bool Init(); void DeInit(); diff --git a/src/DSi_I2C.cpp b/src/DSi_I2C.cpp index 845dd9d..e88858b 100644 --- a/src/DSi_I2C.cpp +++ b/src/DSi_I2C.cpp @@ -72,7 +72,7 @@ void Reset() void Start() { - printf("BPTWL: start\n"); + //printf("BPTWL: start\n"); } u8 Read(bool last) @@ -83,7 +83,7 @@ u8 Read(bool last) return 0; } - printf("BPTWL: read %02X -> %02X\n", CurPos, Registers[CurPos]); + //printf("BPTWL: read %02X -> %02X\n", CurPos, Registers[CurPos]); return Registers[CurPos++]; } @@ -98,7 +98,7 @@ void Write(u8 val, bool last) if (CurPos == -1) { CurPos = val; - printf("BPTWL: reg=%02X\n", val); + //printf("BPTWL: reg=%02X\n", val); return; } @@ -113,7 +113,7 @@ void Write(u8 val, bool last) Registers[CurPos] = val; } - printf("BPTWL: write %02X -> %02X\n", CurPos, val); + //printf("BPTWL: write %02X -> %02X\n", CurPos, val); CurPos++; // CHECKME } diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index 0ecd304..0bb8b5c 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -19,6 +19,7 @@ #include #include #include "NDS.h" +#include "DSi.h" #include "NDSCart.h" #include "ARM.h" #include "CRC32.h" @@ -558,7 +559,8 @@ void Key1_ApplyKeycode(u32* keycode, u32 mod) void Key1_InitKeycode(u32 idcode, u32 level, u32 mod) { - memcpy(Key1_KeyBuf, &NDS::ARM7BIOS[0x30], 0x1048); // hax + //memcpy(Key1_KeyBuf, &NDS::ARM7BIOS[0x30], 0x1048); // hax + memcpy(Key1_KeyBuf, &DSi::ITCMInit[0x4894], 0x1048); // hax u32 keycode[3] = {idcode, idcode>>1, idcode<<1}; if (level >= 1) Key1_ApplyKeycode(keycode, mod); @@ -1185,11 +1187,11 @@ void WriteROMCnt(u32 val) *(u32*)&cmd[4] = *(u32*)&ROMCommand[4]; } - /*printf("ROM COMMAND %04X %08X %02X%02X%02X%02X%02X%02X%02X%02X SIZE %04X\n", + printf("ROM COMMAND %04X %08X %02X%02X%02X%02X%02X%02X%02X%02X SIZE %04X\n", SPICnt, ROMCnt, cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6], cmd[7], - datasize);*/ + datasize); switch (cmd[0]) { -- cgit v1.2.3 From 06716794a1d69512312e1dc251b9762d27b15c8d Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 24 Jul 2019 18:48:52 +0200 Subject: lots of things. attempting to make wifi init work. not there yet. --- src/DSi.cpp | 55 ++++++++++---- src/DSi_AES.cpp | 23 ++++++ src/DSi_NWifi.cpp | 214 +++++++++++++++++++++++++++++++++++++++++++++++++----- src/DSi_NWifi.h | 27 +++++++ src/DSi_SD.cpp | 70 ++++++++++++++---- src/DSi_SD.h | 2 +- src/NDS.h | 3 +- 7 files changed, 344 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index 26a67f4..aed6b89 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -73,6 +73,7 @@ u64 ConsoleID; u8 eMMC_CID[16]; u8 ITCMInit[0x8000]; +u8 ARM7Init[0x3C00]; bool Init() @@ -120,6 +121,9 @@ void Reset() memcpy(NDS::ARM9->ITCM, ITCMInit, 0x8000); + for (u32 i = 0; i < 0x3C00; i+=4) + ARM7Write32(0x03FFC400+i, *(u32*)&ARM7Init[i]); + DSi_I2C::Reset(); DSi_AES::Reset(); @@ -138,9 +142,16 @@ void Reset() NDS::MapSharedWRAM(3); - // TEST - u8 derp[16] = {0xE5, 0xCC, 0x5A, 0x8B, 0x56, 0xD0, 0xC9, 0x72, 0x9C, 0x17, 0xE8, 0xDC, 0x39, 0x12, 0x36, 0xA9}; - for (int i = 0; i < 16; i+=4) ARM7Write32(0x03FFC580+i, *(u32*)&derp[i]); + u32 eaddr = 0x03FFE6E4; + ARM7Write32(eaddr+0x00, *(u32*)&eMMC_CID[0]); + ARM7Write32(eaddr+0x04, *(u32*)&eMMC_CID[4]); + ARM7Write32(eaddr+0x08, *(u32*)&eMMC_CID[8]); + ARM7Write32(eaddr+0x0C, *(u32*)&eMMC_CID[12]); + ARM7Write16(eaddr+0x2C, 0x0001); + ARM7Write16(eaddr+0x2E, 0x0001); + ARM7Write16(eaddr+0x3C, 0x0100); + ARM7Write16(eaddr+0x3E, 0x40E0); + ARM7Write16(eaddr+0x42, 0x0001); } bool LoadBIOS() @@ -328,19 +339,31 @@ bool LoadNAND() } memset(ITCMInit, 0, 0x8000); + memset(ARM7Init, 0, 0x3C00); - f = fopen("dsikeys.bin", "rb"); + f = fopen("initmem9.bin", "rb"); if (f) { // first 0x2524 bytes are loaded to 0x01FFC400 u32 dstaddr = 0x01FFC400; - fread(&ITCMInit[dstaddr & 0x7FFF], 0x2524, 1, f); + fread(&ITCMInit[dstaddr & 0x7FFF], /*0x2524*/0x3C00, 1, f); + fclose(f); + } + else + { + printf("DSi ARM9 meminit not found\n"); + } + + f = fopen("initmem7.bin", "rb"); + if (f) + { + fread(ARM7Init, 0x3C00, 1, f); fclose(f); } else { - printf("DSi keys not found\n"); + printf("DSi ARM7 meminit not found\n"); } return true; @@ -559,7 +582,7 @@ void MapNWRAMRange(u32 cpu, u32 num, u32 val) u8 ARM9Read8(u32 addr) -{ +{if (addr>=0x2FFD7BC && addr<0x2FFD800) printf("EMMCGONP 8 9 %08X %08X\n", addr, NDS::GetPC(0)); switch (addr & 0xFF000000) { case 0x03000000: @@ -588,7 +611,7 @@ u8 ARM9Read8(u32 addr) } u16 ARM9Read16(u32 addr) -{ +{if (addr>=0x2FFD7BC && addr<0x2FFD800) printf("EMMCGONP 16 9 %08X %08X\n", addr, NDS::GetPC(0)); switch (addr & 0xFF000000) { case 0x03000000: @@ -617,7 +640,8 @@ u16 ARM9Read16(u32 addr) } u32 ARM9Read32(u32 addr) -{ +{if(addr==0x029D02D8) printf("READ SHITTY VTABLE: %08X\n", NDS::GetPC(0)); +if (addr>=0x2FFD7BC && addr<0x2FFD800) printf("EMMCGONP 32 9 %08X %08X\n", addr, NDS::GetPC(0)); switch (addr & 0xFF000000) { case 0x03000000: @@ -712,7 +736,7 @@ void ARM9Write16(u32 addr, u16 val) } void ARM9Write32(u32 addr, u32 val) -{ +{if(addr==0x02B05E34) printf("VGONP. %08X, %08X\n", val, NDS::GetPC(0)); switch (addr & 0xFF000000) { case 0x03000000: @@ -768,7 +792,8 @@ bool ARM9GetMemRegion(u32 addr, bool write, NDS::MemRegion* region) u8 ARM7Read8(u32 addr) -{ +{if(addr>=0x3FFC400 && addr<0x3FFE728) printf("OGON 8 %08X %08X\n", addr, NDS::GetPC(1)); +if (addr>=0x2FFD7BC && addr<0x2FFD800) printf("EMMCGONP 8 7 %08X %08X\n", addr, NDS::GetPC(1)); switch (addr & 0xFF800000) { case 0x03000000: @@ -797,7 +822,8 @@ u8 ARM7Read8(u32 addr) } u16 ARM7Read16(u32 addr) -{ +{if(addr>=0x3FFC400 && addr<0x3FFE728) printf("OGON 16 %08X %08X\n", addr, NDS::GetPC(1)); +if (addr>=0x2FFD7BC && addr<0x2FFD800) printf("EMMCGONP 16 7 %08X %08X\n", addr, NDS::GetPC(1)); switch (addr & 0xFF800000) { case 0x03000000: @@ -826,7 +852,8 @@ u16 ARM7Read16(u32 addr) } u32 ARM7Read32(u32 addr) -{ +{if(addr>=0x3FFC400 && addr<0x3FFE728) printf("OGON 32 %08X %08X\n", addr, NDS::GetPC(1)); +if (addr>=0x2FFD7BC && addr<0x2FFD800) printf("EMMCGONP 32 7 %08X %08X\n", addr, NDS::GetPC(1)); switch (addr & 0xFF800000) { case 0x03000000: @@ -855,7 +882,7 @@ u32 ARM7Read32(u32 addr) } void ARM7Write8(u32 addr, u8 val) -{ +{if(addr==0x0228CD74) printf("RAKAKA %02X %08X\n", val, NDS::GetPC(1)); switch (addr & 0xFF800000) { case 0x03000000: diff --git a/src/DSi_AES.cpp b/src/DSi_AES.cpp index 8ae9082..4aa97bc 100644 --- a/src/DSi_AES.cpp +++ b/src/DSi_AES.cpp @@ -22,6 +22,7 @@ #include "DSi_AES.h" #include "FIFO.h" #include "tiny-AES-c/aes.hpp" +#include "Platform.h" namespace DSi_AES @@ -130,6 +131,7 @@ void Reset() // initialize keys, as per GBAtek +#if 0 // slot 0: modcrypt *(u32*)&KeyX[0][0] = 0x746E694E; *(u32*)&KeyX[0][4] = 0x6F646E65; @@ -148,6 +150,27 @@ void Reset() *(u32*)&KeyY[3][0] = 0x0AB9DC76; *(u32*)&KeyY[3][4] = 0xBD4DC4D3; *(u32*)&KeyY[3][8] = 0x202DDD1D; +#endif + FILE* f = Platform::OpenLocalFile("aeskeys.bin", "rb"); + if (f) + { + fread(KeyNormal[0], 16, 1, f); + fread(KeyX[0], 16, 1, f); + fread(KeyY[0], 16, 1, f); + fread(KeyNormal[1], 16, 1, f); + fread(KeyX[1], 16, 1, f); + fread(KeyY[1], 16, 1, f); + fread(KeyNormal[2], 16, 1, f); + fread(KeyX[2], 16, 1, f); + fread(KeyY[2], 16, 1, f); + fread(KeyNormal[3], 16, 1, f); + fread(KeyX[3], 16, 1, f); + fread(KeyY[3], 16, 1, f); + + fclose(f); + } + else + printf("AES: aeskeys.bin not found\n"); } diff --git a/src/DSi_NWifi.cpp b/src/DSi_NWifi.cpp index 5236551..e0591fb 100644 --- a/src/DSi_NWifi.cpp +++ b/src/DSi_NWifi.cpp @@ -114,11 +114,20 @@ DSi_NWifi::DSi_NWifi(DSi_SDHost* host) : DSi_SDDevice(host) { TransferCmd = 0xFFFFFFFF; RemSize = 0; + + WindowData = 0; + WindowReadAddr = 0; + WindowWriteAddr = 0; + + // TODO: check the actual mailbox size (presumably 0x200) + for (int i = 0; i < 8; i++) + Mailbox[i] = new FIFO(0x200); } DSi_NWifi::~DSi_NWifi() { - // + for (int i = 0; i < 8; i++) + delete Mailbox[i]; } @@ -165,9 +174,54 @@ void DSi_NWifi::F0_Write(u32 addr, u8 val) u8 DSi_NWifi::F1_Read(u32 addr) -{ - switch (addr) +{printf("F1 READ %05X\n", addr); + if (addr < 0x100) + { + return Mailbox[4]->Read(); + } + else if (addr < 0x200) + { + return Mailbox[5]->Read(); + } + else if (addr < 0x300) + { + return Mailbox[6]->Read(); + } + else if (addr < 0x400) + { + return Mailbox[7]->Read(); + } + else if (addr < 0x800) + { + switch (addr) + { + case 0x00450: return 1; // HAX!! + + case 0x00474: return WindowData & 0xFF; + case 0x00475: return (WindowData >> 8) & 0xFF; + case 0x00476: return (WindowData >> 16) & 0xFF; + case 0x00477: return WindowData >> 24; + } + } + else if (addr < 0x1000) + { + return Mailbox[4]->Read(); + } + else if (addr < 0x1800) + { + return Mailbox[5]->Read(); + } + else if (addr < 0x2000) + { + return Mailbox[6]->Read(); + } + else if (addr < 0x2800) + { + return Mailbox[7]->Read(); + } + else { + return Mailbox[4]->Read(); } printf("NWIFI: unknown func1 read %05X\n", addr); @@ -175,7 +229,91 @@ u8 DSi_NWifi::F1_Read(u32 addr) } void DSi_NWifi::F1_Write(u32 addr, u8 val) -{ +{printf("F1 WRITE %05X %02X\n", addr, val); + if (addr < 0x100) + { + if (Mailbox[0]->IsFull()) printf("!!! NWIFI: MBOX0 FULL\n"); + Mailbox[0]->Write(val); + if (addr == 0xFF) BMI_Command(); + return; + } + else if (addr < 0x200) + { + if (Mailbox[1]->IsFull()) printf("!!! NWIFI: MBOX1 FULL\n"); + Mailbox[1]->Write(val); + return; + } + else if (addr < 0x300) + { + if (Mailbox[2]->IsFull()) printf("!!! NWIFI: MBOX2 FULL\n"); + Mailbox[2]->Write(val); + return; + } + else if (addr < 0x400) + { + if (Mailbox[3]->IsFull()) printf("!!! NWIFI: MBOX3 FULL\n"); + Mailbox[3]->Write(val); + return; + } + else if (addr < 0x800) + { + switch (addr) + { + case 0x00474: WindowData = (WindowData & 0xFFFFFF00) | val; return; + case 0x00475: WindowData = (WindowData & 0xFFFF00FF) | (val << 8); return; + case 0x00476: WindowData = (WindowData & 0xFF00FFFF) | (val << 16); return; + case 0x00477: WindowData = (WindowData & 0x00FFFFFF) | (val << 24); return; + + case 0x00478: + WindowWriteAddr = (WindowWriteAddr & 0xFFFFFF00) | val; + WindowWrite(); + return; + case 0x00479: WindowWriteAddr = (WindowWriteAddr & 0xFFFF00FF) | (val << 8); return; + case 0x0047A: WindowWriteAddr = (WindowWriteAddr & 0xFF00FFFF) | (val << 16); return; + case 0x0047B: WindowWriteAddr = (WindowWriteAddr & 0x00FFFFFF) | (val << 24); return; + + case 0x0047C: + WindowReadAddr = (WindowReadAddr & 0xFFFFFF00) | val; + WindowRead(); + return; + case 0x0047D: WindowReadAddr = (WindowReadAddr & 0xFFFF00FF) | (val << 8); return; + case 0x0047E: WindowReadAddr = (WindowReadAddr & 0xFF00FFFF) | (val << 16); return; + case 0x0047F: WindowReadAddr = (WindowReadAddr & 0x00FFFFFF) | (val << 24); return; + } + } + else if (addr < 0x1000) + { + if (Mailbox[0]->IsFull()) printf("!!! NWIFI: MBOX0 FULL\n"); + Mailbox[0]->Write(val); + if (addr == 0xFFF) BMI_Command(); + return; + } + else if (addr < 0x1800) + { + if (Mailbox[1]->IsFull()) printf("!!! NWIFI: MBOX1 FULL\n"); + Mailbox[1]->Write(val); + return; + } + else if (addr < 0x2000) + { + if (Mailbox[2]->IsFull()) printf("!!! NWIFI: MBOX2 FULL\n"); + Mailbox[2]->Write(val); + return; + } + else if (addr < 0x2800) + { + if (Mailbox[3]->IsFull()) printf("!!! NWIFI: MBOX3 FULL\n"); + Mailbox[3]->Write(val); + return; + } + else + { + if (Mailbox[0]->IsFull()) printf("!!! NWIFI: MBOX0 FULL\n"); + Mailbox[0]->Write(val); + if (addr == 0x3FFF) BMI_Command(); // CHECKME + return; + } + printf("NWIFI: unknown func1 write %05X %02X\n", addr, val); } @@ -185,6 +323,7 @@ u8 DSi_NWifi::SDIO_Read(u32 func, u32 addr) switch (func) { case 0: return F0_Read(addr); + case 1: return F1_Read(addr); } printf("NWIFI: unknown SDIO read %d %05X\n", func, addr); @@ -196,6 +335,7 @@ void DSi_NWifi::SDIO_Write(u32 func, u32 addr, u8 val) switch (func) { case 0: return F0_Write(addr, val); + case 1: return F1_Write(addr, val); } printf("NWIFI: unknown SDIO write %d %05X %02X\n", func, addr, val); @@ -203,7 +343,7 @@ void DSi_NWifi::SDIO_Write(u32 func, u32 addr, u8 val) void DSi_NWifi::SendCMD(u8 cmd, u32 param) -{ +{printf("NWIFI CMD %d %08X %08X\n", cmd, param, NDS::GetPC(1)); switch (cmd) { case 52: // IO_RW_DIRECT @@ -315,24 +455,62 @@ void DSi_NWifi::WriteBlock() u32 len = (TransferCmd & (1<<27)) ? 0x200 : RemSize; u8 data[0x200]; - Host->ReceiveData(data, len); - - for (u32 i = 0; i < len; i++) + if (Host->ReceiveData(data, len)) { - SDIO_Write(func, TransferAddr, data[i]); - if (TransferCmd & (1<<26)) + for (u32 i = 0; i < len; i++) { - TransferAddr++; - TransferAddr &= 0x1FFFF; // checkme + SDIO_Write(func, TransferAddr, data[i]); + if (TransferCmd & (1<<26)) + { + TransferAddr++; + TransferAddr &= 0x1FFFF; // checkme + } } - } - if (RemSize > 0) - { - RemSize -= len; - if (RemSize == 0) + if (RemSize > 0) { - // TODO? + RemSize -= len; + if (RemSize == 0) + { + // TODO? + } } } } + + +void DSi_NWifi::BMI_Command() +{ + // HLE command handling stub + u32 cmd = MB_Read32(0); + printf("BMI: cmd %08X\n", cmd); + + switch (cmd) + { + case 0x08: // BMI_GET_TARGET_ID + MB_Write32(4, 0xFFFFFFFF); + MB_Write32(4, 0x0000000C); + MB_Write32(4, 0x20000118); + MB_Write32(4, 0x00000002); + return; + } +} + + +void DSi_NWifi::WindowRead() +{ + printf("NWifi: window read %08X\n", WindowReadAddr); + + switch (WindowReadAddr) + { + case 0x40EC: WindowData = 0x02000001; return; + + // SOC_RESET_CAUSE + case 0x40C0: WindowData = 2; return; + } +} + +void DSi_NWifi::WindowWrite() +{ + printf("NWifi: window write %08X %08X\n", WindowWriteAddr, WindowData); +} diff --git a/src/DSi_NWifi.h b/src/DSi_NWifi.h index 5d61951..4ec010e 100644 --- a/src/DSi_NWifi.h +++ b/src/DSi_NWifi.h @@ -20,6 +20,7 @@ #define DSI_NWIFI_H #include "DSi_SD.h" +#include "FIFO.h" class DSi_NWifi : public DSi_SDDevice { @@ -48,6 +49,32 @@ private: void ReadBlock(); void WriteBlock(); + + void BMI_Command(); + + void WindowRead(); + void WindowWrite(); + + u32 MB_Read32(int n) + { + u32 ret = Mailbox[n]->Read(); + ret |= (Mailbox[n]->Read() << 8); + ret |= (Mailbox[n]->Read() << 16); + ret |= (Mailbox[n]->Read() << 24); + return ret; + } + + void MB_Write32(int n, u32 val) + { + Mailbox[n]->Write(val & 0xFF); val >>= 8; + Mailbox[n]->Write(val & 0xFF); val >>= 8; + Mailbox[n]->Write(val & 0xFF); val >>= 8; + Mailbox[n]->Write(val & 0xFF); + } + + FIFO* Mailbox[8]; + + u32 WindowData, WindowReadAddr, WindowWriteAddr; }; #endif // DSI_NWIFI_H diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index 6e73df5..c9edd78 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -185,7 +185,8 @@ void DSi_SDHost::SendData(u8* data, u32 len) // but if IRQ24 is thrown instantly, the handler clears IRQ0 before the // send-command function starts polling IRQ status u32 param = Num | (last << 1); - NDS::ScheduleEvent(NDS::Event_DSi_SDTransfer, false, 512, FinishSend, param); + NDS::ScheduleEvent(Num ? NDS::Event_DSi_SDIOTransfer : NDS::Event_DSi_SDMMCTransfer, + false, 512, FinishSend, param); } void DSi_SDHost::FinishReceive(u32 param) @@ -199,13 +200,19 @@ void DSi_SDHost::FinishReceive(u32 param) if (dev) dev->ContinueTransfer(); } -void DSi_SDHost::ReceiveData(u8* data, u32 len) +bool DSi_SDHost::ReceiveData(u8* data, u32 len) { printf("%s: data TX, len=%d, blkcnt=%d (%d) blklen=%d, irq=%08X\n", SD_DESC, len, BlockCount16, BlockCountInternal, BlockLen16, IRQMask); if (len != BlockLen16) printf("!! BAD BLOCKLEN\n"); - DSi_SDDevice* dev = Ports[PortSelect & 0x1]; u32 f = CurFIFO; + if ((DataFIFO[f]->Level() << 1) < len) + { + printf("%s: FIFO not full enough for a transfer (%d / %d)\n", SD_DESC, DataFIFO[f]->Level()<<1, len); + return false; + } + + DSi_SDDevice* dev = Ports[PortSelect & 0x1]; for (u32 i = 0; i < len; i += 2) *(u16*)&data[i] = DataFIFO[f]->Read(); @@ -213,7 +220,7 @@ void DSi_SDHost::ReceiveData(u8* data, u32 len) if (BlockCountInternal <= 1) { - printf("%s: data32 TX complete", SD_DESC); + printf("%s: data TX complete", SD_DESC); if (StopAction & (1<<8)) { @@ -232,12 +239,14 @@ void DSi_SDHost::ReceiveData(u8* data, u32 len) { BlockCountInternal--; } + + return true; } u16 DSi_SDHost::Read(u32 addr) { - //printf("SDMMC READ %08X %08X\n", addr, NDS::GetPC(1)); + //if(Num)printf("SDIO READ %08X %08X\n", addr, NDS::GetPC(1)); switch (addr & 0x1FF) { @@ -383,7 +392,7 @@ u32 DSi_SDHost::ReadFIFO32() void DSi_SDHost::Write(u32 addr, u16 val) { - //printf("SDMMC WRITE %08X %04X %08X\n", addr, val, NDS::GetPC(1)); + //if(Num)printf("SDIO WRITE %08X %04X %08X\n", addr, val, NDS::GetPC(1)); switch (addr & 0x1FF) { @@ -421,7 +430,11 @@ void DSi_SDHost::Write(u32 addr, u16 val) case 0x01C: IRQStatus &= (val | 0xFFFF0000); return; case 0x01E: IRQStatus &= ((val << 16) | 0xFFFF); return; case 0x020: IRQMask = (IRQMask & 0x8B7F0000) | (val & 0x031D); return; - case 0x022: IRQMask = (IRQMask & 0x0000031D) | ((val & 0x8B7F) << 16); return; + case 0x022: + IRQMask = (IRQMask & 0x0000031D) | ((val & 0x8B7F) << 16); + if (!DataFIFO[CurFIFO]->IsEmpty()) SetIRQ(24); // checkme + if (DataFIFO[CurFIFO]->IsEmpty()) SetIRQ(25); // checkme + return; case 0x024: SDClock = val & 0x03FF; return; case 0x026: @@ -430,6 +443,33 @@ void DSi_SDHost::Write(u32 addr, u16 val) return; case 0x028: SDOption = val & 0xC1FF; return; + case 0x030: // FIFO16 + { + DSi_SDDevice* dev = Ports[PortSelect & 0x1]; + u32 f = CurFIFO; + if (DataFIFO[f]->IsFull()) + { + // TODO + printf("!!!! %s FIFO FULL\n", SD_DESC); + return; + } + + DataFIFO[f]->Write(val); + + if (DataFIFO[f]->Level() < (BlockLen16>>1)) + { + ClearIRQ(25); + SetIRQ(24); + return; + } + + // we completed one block, send it to the SD card + // TODO measure the actual delay!! + NDS::ScheduleEvent(Num ? NDS::Event_DSi_SDIOTransfer : NDS::Event_DSi_SDMMCTransfer, + false, 2048, FinishReceive, Num); + } + return; + case 0x0D8: DataCtl = (val & 0x0022); DataMode = ((DataCtl >> 1) & 0x1) & ((Data32IRQ >> 1) & 0x1); @@ -494,13 +534,9 @@ void DSi_SDHost::WriteFIFO32(u32 val) } // we completed one block, send it to the SD card - - //ClearIRQ(24); - //SetIRQ(25); - - //if (dev) dev->ContinueTransfer(); // TODO measure the actual delay!! - NDS::ScheduleEvent(NDS::Event_DSi_SDTransfer, false, 2048, FinishReceive, Num); + NDS::ScheduleEvent(Num ? NDS::Event_DSi_SDIOTransfer : NDS::Event_DSi_SDMMCTransfer, + false, 2048, FinishReceive, Num); } @@ -726,7 +762,9 @@ void DSi_MMCStorage::WriteBlock(u64 addr) printf("SD/MMC: write block @ %08X, len=%08X\n", addr, BlockSize); u8 data[0x200]; - Host->ReceiveData(data, BlockSize); - fseek(File, addr, SEEK_SET); - fwrite(data, 1, BlockSize, File); + if (Host->ReceiveData(data, BlockSize)) + { + fseek(File, addr, SEEK_SET); + fwrite(data, 1, BlockSize, File); + } } diff --git a/src/DSi_SD.h b/src/DSi_SD.h index 855dd5e..22475d6 100644 --- a/src/DSi_SD.h +++ b/src/DSi_SD.h @@ -40,7 +40,7 @@ public: static void FinishReceive(u32 param); void SendResponse(u32 val, bool last); void SendData(u8* data, u32 len); - void ReceiveData(u8* data, u32 len); + bool ReceiveData(u8* data, u32 len); u16 Read(u32 addr); void Write(u32 addr, u16 val); diff --git a/src/NDS.h b/src/NDS.h index 850e829..e32908b 100644 --- a/src/NDS.h +++ b/src/NDS.h @@ -43,7 +43,8 @@ enum Event_Sqrt, // DSi - Event_DSi_SDTransfer, + Event_DSi_SDMMCTransfer, + Event_DSi_SDIOTransfer, Event_MAX }; -- cgit v1.2.3 From 0918da7b004ea2259989ab7063cfa1e20216f10a Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 24 Jul 2019 21:13:08 +0200 Subject: add BMI commands and other shit --- src/DSi_NWifi.cpp | 87 ++++++++++++++++++++++++++++++++++++++++++++++++------- src/DSi_NWifi.h | 4 +-- 2 files changed, 79 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/DSi_NWifi.cpp b/src/DSi_NWifi.cpp index e0591fb..6f23740 100644 --- a/src/DSi_NWifi.cpp +++ b/src/DSi_NWifi.cpp @@ -266,7 +266,7 @@ void DSi_NWifi::F1_Write(u32 addr, u8 val) case 0x00478: WindowWriteAddr = (WindowWriteAddr & 0xFFFFFF00) | val; - WindowWrite(); + WindowWrite(WindowWriteAddr, WindowData); return; case 0x00479: WindowWriteAddr = (WindowWriteAddr & 0xFFFF00FF) | (val << 8); return; case 0x0047A: WindowWriteAddr = (WindowWriteAddr & 0xFF00FFFF) | (val << 16); return; @@ -274,7 +274,7 @@ void DSi_NWifi::F1_Write(u32 addr, u8 val) case 0x0047C: WindowReadAddr = (WindowReadAddr & 0xFFFFFF00) | val; - WindowRead(); + WindowData = WindowRead(WindowReadAddr); return; case 0x0047D: WindowReadAddr = (WindowReadAddr & 0xFFFF00FF) | (val << 8); return; case 0x0047E: WindowReadAddr = (WindowReadAddr & 0xFF00FFFF) | (val << 16); return; @@ -487,30 +487,97 @@ void DSi_NWifi::BMI_Command() switch (cmd) { + case 0x03: // BMI_WRITE_MEMORY + { + u32 addr = MB_Read32(0); + u32 len = MB_Read32(0); + printf("BMI mem write %08X %08X\n", addr, len); + + for (int i = 0; i < len; i++) + { + u8 val = Mailbox[0]->Read(); + + // TODO: do something with it!! + } + } + return; + + case 0x04: // BMI_EXECUTE + { + u32 entry = MB_Read32(0); + u32 arg = MB_Read32(0); + + printf("BMI_EXECUTE %08X %08X\n", entry, arg); + } + return; + + case 0x06: // BMI_READ_SOC_REGISTER + { + u32 addr = MB_Read32(0); + u32 val = WindowRead(addr); + MB_Write32(4, val); + } + return; + + case 0x07: // BMI_WRITE_SOC_REGISTER + { + u32 addr = MB_Read32(0); + u32 val = MB_Read32(0); + WindowWrite(addr, val); + } + return; + case 0x08: // BMI_GET_TARGET_ID MB_Write32(4, 0xFFFFFFFF); MB_Write32(4, 0x0000000C); - MB_Write32(4, 0x20000118); + //MB_Write32(4, 0x20000118); + MB_Write32(4, 0x23000024); // ROM version (TODO: how to determine correct one?) MB_Write32(4, 0x00000002); return; + + case 0x0D: // BMI_LZ_STREAM_START + { + u32 addr = MB_Read32(0); + printf("BMI_LZ_STREAM_START %08X\n", addr); + } + return; + + case 0x0E: // BMI_LZ_DATA + { + u32 len = MB_Read32(0); + printf("BMI LZ write %08X\n", len); + + for (int i = 0; i < len; i++) + { + u8 val = Mailbox[0]->Read(); + + // TODO: do something with it!! + } + } + return; } } -void DSi_NWifi::WindowRead() +u32 DSi_NWifi::WindowRead(u32 addr) { - printf("NWifi: window read %08X\n", WindowReadAddr); + printf("NWifi: window read %08X\n", addr); - switch (WindowReadAddr) + switch (addr) { - case 0x40EC: WindowData = 0x02000001; return; + case 0x40EC: // chip ID + // 0D000000 / 0D000001 == AR6013 + // TODO: check firmware.bin to determine the correct value + return 0x0D000001; // SOC_RESET_CAUSE - case 0x40C0: WindowData = 2; return; + case 0x40C0: return 2; } + + return 0; } -void DSi_NWifi::WindowWrite() +void DSi_NWifi::WindowWrite(u32 addr, u32 val) { - printf("NWifi: window write %08X %08X\n", WindowWriteAddr, WindowData); + printf("NWifi: window write %08X %08X\n", addr, val); } diff --git a/src/DSi_NWifi.h b/src/DSi_NWifi.h index 4ec010e..0a36705 100644 --- a/src/DSi_NWifi.h +++ b/src/DSi_NWifi.h @@ -52,8 +52,8 @@ private: void BMI_Command(); - void WindowRead(); - void WindowWrite(); + u32 WindowRead(u32 addr); + void WindowWrite(u32 addr, u32 val); u32 MB_Read32(int n) { -- cgit v1.2.3 From f7f4ff0519309669e78b994e7c759d13808f0a87 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 4 Aug 2019 02:16:16 +0200 Subject: wifi: take this shit further. complete wifi init --- src/DSi.cpp | 20 ++-- src/DSi_NWifi.cpp | 328 +++++++++++++++++++++++++++++++++++++++++++++++++++--- src/DSi_NWifi.h | 41 +++++++ src/DSi_SD.cpp | 105 +++++++++++++---- src/DSi_SD.h | 19 +++- src/FIFO.h | 9 ++ src/NDS.h | 1 + src/SPI.cpp | 1 + src/SPI.h | 1 + 9 files changed, 468 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index aed6b89..17d7f0d 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -582,7 +582,7 @@ void MapNWRAMRange(u32 cpu, u32 num, u32 val) u8 ARM9Read8(u32 addr) -{if (addr>=0x2FFD7BC && addr<0x2FFD800) printf("EMMCGONP 8 9 %08X %08X\n", addr, NDS::GetPC(0)); +{ switch (addr & 0xFF000000) { case 0x03000000: @@ -611,7 +611,7 @@ u8 ARM9Read8(u32 addr) } u16 ARM9Read16(u32 addr) -{if (addr>=0x2FFD7BC && addr<0x2FFD800) printf("EMMCGONP 16 9 %08X %08X\n", addr, NDS::GetPC(0)); +{ switch (addr & 0xFF000000) { case 0x03000000: @@ -640,8 +640,7 @@ u16 ARM9Read16(u32 addr) } u32 ARM9Read32(u32 addr) -{if(addr==0x029D02D8) printf("READ SHITTY VTABLE: %08X\n", NDS::GetPC(0)); -if (addr>=0x2FFD7BC && addr<0x2FFD800) printf("EMMCGONP 32 9 %08X %08X\n", addr, NDS::GetPC(0)); +{ switch (addr & 0xFF000000) { case 0x03000000: @@ -736,7 +735,7 @@ void ARM9Write16(u32 addr, u16 val) } void ARM9Write32(u32 addr, u32 val) -{if(addr==0x02B05E34) printf("VGONP. %08X, %08X\n", val, NDS::GetPC(0)); +{ switch (addr & 0xFF000000) { case 0x03000000: @@ -792,8 +791,7 @@ bool ARM9GetMemRegion(u32 addr, bool write, NDS::MemRegion* region) u8 ARM7Read8(u32 addr) -{if(addr>=0x3FFC400 && addr<0x3FFE728) printf("OGON 8 %08X %08X\n", addr, NDS::GetPC(1)); -if (addr>=0x2FFD7BC && addr<0x2FFD800) printf("EMMCGONP 8 7 %08X %08X\n", addr, NDS::GetPC(1)); +{ switch (addr & 0xFF800000) { case 0x03000000: @@ -822,8 +820,7 @@ if (addr>=0x2FFD7BC && addr<0x2FFD800) printf("EMMCGONP 8 7 %08X %08X\n", addr, } u16 ARM7Read16(u32 addr) -{if(addr>=0x3FFC400 && addr<0x3FFE728) printf("OGON 16 %08X %08X\n", addr, NDS::GetPC(1)); -if (addr>=0x2FFD7BC && addr<0x2FFD800) printf("EMMCGONP 16 7 %08X %08X\n", addr, NDS::GetPC(1)); +{ switch (addr & 0xFF800000) { case 0x03000000: @@ -852,8 +849,7 @@ if (addr>=0x2FFD7BC && addr<0x2FFD800) printf("EMMCGONP 16 7 %08X %08X\n", addr, } u32 ARM7Read32(u32 addr) -{if(addr>=0x3FFC400 && addr<0x3FFE728) printf("OGON 32 %08X %08X\n", addr, NDS::GetPC(1)); -if (addr>=0x2FFD7BC && addr<0x2FFD800) printf("EMMCGONP 32 7 %08X %08X\n", addr, NDS::GetPC(1)); +{ switch (addr & 0xFF800000) { case 0x03000000: @@ -882,7 +878,7 @@ if (addr>=0x2FFD7BC && addr<0x2FFD800) printf("EMMCGONP 32 7 %08X %08X\n", addr, } void ARM7Write8(u32 addr, u8 val) -{if(addr==0x0228CD74) printf("RAKAKA %02X %08X\n", val, NDS::GetPC(1)); +{ switch (addr & 0xFF800000) { case 0x03000000: diff --git a/src/DSi_NWifi.cpp b/src/DSi_NWifi.cpp index 6f23740..013173f 100644 --- a/src/DSi_NWifi.cpp +++ b/src/DSi_NWifi.cpp @@ -20,6 +20,7 @@ #include #include "DSi.h" #include "DSi_NWifi.h" +#include "SPI.h" const u8 CIS0[256] = @@ -110,11 +111,25 @@ const u8 CIS1[256] = }; +// hax +DSi_NWifi* hax_wifi; +void triggerirq(u32 param) +{ + hax_wifi->SetIRQ_F1_Counter(0); +} + + DSi_NWifi::DSi_NWifi(DSi_SDHost* host) : DSi_SDDevice(host) { TransferCmd = 0xFFFFFFFF; RemSize = 0; + F0_IRQEnable = 0; + F0_IRQStatus = 0; + + F1_IRQEnable = 0; F1_IRQEnable_CPU = 0; F1_IRQEnable_Error = 0; F1_IRQEnable_Counter = 0; + F1_IRQStatus = 0; F1_IRQStatus_CPU = 0; F1_IRQStatus_Error = 0; F1_IRQStatus_Counter = 0; + WindowData = 0; WindowReadAddr = 0; WindowWriteAddr = 0; @@ -122,6 +137,30 @@ DSi_NWifi::DSi_NWifi(DSi_SDHost* host) : DSi_SDDevice(host) // TODO: check the actual mailbox size (presumably 0x200) for (int i = 0; i < 8; i++) Mailbox[i] = new FIFO(0x200); + + u8* mac = SPI_Firmware::GetWifiMAC(); + printf("NWifi MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", + mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + + memset(EEPROM, 0, 0x400); + + *(u32*)&EEPROM[0x000] = 0x300; + *(u16*)&EEPROM[0x008] = 0x8348; // TODO: determine properly (country code) + memcpy(&EEPROM[0x00A], mac, 6); + *(u32*)&EEPROM[0x010] = 0x60000000; + + memset(&EEPROM[0x03C], 0xFF, 0x70); + memset(&EEPROM[0x140], 0xFF, 0x8); + + u16 chk = 0xFFFF; + for (int i = 0; i < 0x300; i+=2) + chk ^= *(u16*)&EEPROM[i]; + + *(u16*)&EEPROM[0x004] = chk; + + EEPROMReady = 0; + + BootPhase = 0; } DSi_NWifi::~DSi_NWifi() @@ -131,6 +170,61 @@ DSi_NWifi::~DSi_NWifi() } +// CHECKME +// can IRQ status bits be set when the corresponding IRQs are disabled in the enable register? +// otherwise, does disabling them clear the status register? + +void DSi_NWifi::UpdateIRQ() +{ + F0_IRQStatus = 0; + IRQ = false; + + if (F1_IRQStatus & F1_IRQEnable) + F0_IRQStatus |= (1<<1); + + if (F0_IRQEnable & (1<<0)) + { + if (F0_IRQStatus & F0_IRQEnable) + IRQ = true; + } + + Host->SetCardIRQ(); +} + +void DSi_NWifi::UpdateIRQ_F1() +{ + F1_IRQStatus = 0; + + if (!Mailbox[4]->IsEmpty()) F1_IRQStatus |= (1<<0); + if (!Mailbox[5]->IsEmpty()) F1_IRQStatus |= (1<<1); + if (!Mailbox[6]->IsEmpty()) F1_IRQStatus |= (1<<2); + if (!Mailbox[7]->IsEmpty()) F1_IRQStatus |= (1<<3); + if (F1_IRQStatus_Counter & F1_IRQEnable_Counter) F1_IRQStatus |= (1<<4); + if (F1_IRQStatus_CPU & F1_IRQEnable_CPU) F1_IRQStatus |= (1<<6); + if (F1_IRQStatus_Error & F1_IRQEnable_Error) F1_IRQStatus |= (1<<7); + + UpdateIRQ(); +} + +void DSi_NWifi::SetIRQ_F1_Counter(u32 n) +{ + F1_IRQStatus_Counter |= (1<Read(); + u8 ret = Mailbox[4]->Read(); + UpdateIRQ_F1(); + return ret; } else if (addr < 0x200) { - return Mailbox[5]->Read(); + u8 ret = Mailbox[5]->Read(); + UpdateIRQ_F1(); + return ret; } else if (addr < 0x300) { - return Mailbox[6]->Read(); + u8 ret = Mailbox[6]->Read(); + UpdateIRQ_F1(); + return ret; } else if (addr < 0x400) { - return Mailbox[7]->Read(); + u8 ret = Mailbox[7]->Read(); + UpdateIRQ_F1(); + return ret; } else if (addr < 0x800) { switch (addr) { + case 0x00400: return F1_IRQStatus; + case 0x00401: return F1_IRQStatus_CPU; + case 0x00402: return F1_IRQStatus_Error; + case 0x00403: return F1_IRQStatus_Counter; + + case 0x00405: + { + u8 ret = 0; + + if (Mailbox[4]->Level() >= 4) ret |= (1<<0); + if (Mailbox[5]->Level() >= 4) ret |= (1<<1); + if (Mailbox[6]->Level() >= 4) ret |= (1<<2); + if (Mailbox[7]->Level() >= 4) ret |= (1<<3); + + return ret; + } + + case 0x00408: return Mailbox[4]->Peek(0); + case 0x00409: return Mailbox[4]->Peek(1); + case 0x0040A: return Mailbox[4]->Peek(2); + case 0x0040B: return Mailbox[4]->Peek(3); + + case 0x00418: return F1_IRQEnable; + case 0x00419: return F1_IRQEnable_CPU; + case 0x0041A: return F1_IRQEnable_Error; + case 0x0041B: return F1_IRQEnable_Counter; + + // GROSS FUCKING HACK + case 0x00440: ClearIRQ_F1_Counter(0); return 0; case 0x00450: return 1; // HAX!! case 0x00474: return WindowData & 0xFF; @@ -205,23 +347,33 @@ u8 DSi_NWifi::F1_Read(u32 addr) } else if (addr < 0x1000) { - return Mailbox[4]->Read(); + u8 ret = Mailbox[4]->Read(); + UpdateIRQ_F1(); + return ret; } else if (addr < 0x1800) { - return Mailbox[5]->Read(); + u8 ret = Mailbox[5]->Read(); + UpdateIRQ_F1(); + return ret; } else if (addr < 0x2000) { - return Mailbox[6]->Read(); + u8 ret = Mailbox[6]->Read(); + UpdateIRQ_F1(); + return ret; } else if (addr < 0x2800) { - return Mailbox[7]->Read(); + u8 ret = Mailbox[7]->Read(); + UpdateIRQ_F1(); + return ret; } else { - return Mailbox[4]->Read(); + u8 ret = Mailbox[4]->Read(); + UpdateIRQ_F1(); + return ret; } printf("NWIFI: unknown func1 read %05X\n", addr); @@ -229,36 +381,48 @@ u8 DSi_NWifi::F1_Read(u32 addr) } void DSi_NWifi::F1_Write(u32 addr, u8 val) -{printf("F1 WRITE %05X %02X\n", addr, val); +{ if (addr < 0x100) { if (Mailbox[0]->IsFull()) printf("!!! NWIFI: MBOX0 FULL\n"); Mailbox[0]->Write(val); - if (addr == 0xFF) BMI_Command(); + if (addr == 0xFF) HandleCommand(); + UpdateIRQ_F1(); return; } else if (addr < 0x200) { if (Mailbox[1]->IsFull()) printf("!!! NWIFI: MBOX1 FULL\n"); Mailbox[1]->Write(val); + UpdateIRQ_F1(); return; } else if (addr < 0x300) { if (Mailbox[2]->IsFull()) printf("!!! NWIFI: MBOX2 FULL\n"); Mailbox[2]->Write(val); + UpdateIRQ_F1(); return; } else if (addr < 0x400) { if (Mailbox[3]->IsFull()) printf("!!! NWIFI: MBOX3 FULL\n"); Mailbox[3]->Write(val); + UpdateIRQ_F1(); return; } else if (addr < 0x800) { switch (addr) { + case 0x00418: F1_IRQEnable = val; UpdateIRQ_F1(); return; + case 0x00419: F1_IRQEnable_CPU = val; UpdateIRQ_F1(); return; + case 0x0041A: F1_IRQEnable_Error = val; UpdateIRQ_F1(); return; + case 0x0041B: F1_IRQEnable_Counter = val; UpdateIRQ_F1(); return; + + // GROSS FUCKING HACK + case 0x00440: ClearIRQ_F1_Counter(0); return; + case 0x00474: WindowData = (WindowData & 0xFFFFFF00) | val; return; case 0x00475: WindowData = (WindowData & 0xFFFF00FF) | (val << 8); return; case 0x00476: WindowData = (WindowData & 0xFF00FFFF) | (val << 16); return; @@ -285,32 +449,37 @@ void DSi_NWifi::F1_Write(u32 addr, u8 val) { if (Mailbox[0]->IsFull()) printf("!!! NWIFI: MBOX0 FULL\n"); Mailbox[0]->Write(val); - if (addr == 0xFFF) BMI_Command(); + if (addr == 0xFFF) HandleCommand(); + UpdateIRQ_F1(); return; } else if (addr < 0x1800) { if (Mailbox[1]->IsFull()) printf("!!! NWIFI: MBOX1 FULL\n"); Mailbox[1]->Write(val); + UpdateIRQ_F1(); return; } else if (addr < 0x2000) { if (Mailbox[2]->IsFull()) printf("!!! NWIFI: MBOX2 FULL\n"); Mailbox[2]->Write(val); + UpdateIRQ_F1(); return; } else if (addr < 0x2800) { if (Mailbox[3]->IsFull()) printf("!!! NWIFI: MBOX3 FULL\n"); Mailbox[3]->Write(val); + UpdateIRQ_F1(); return; } else { if (Mailbox[0]->IsFull()) printf("!!! NWIFI: MBOX0 FULL\n"); Mailbox[0]->Write(val); - if (addr == 0x3FFF) BMI_Command(); // CHECKME + if (addr == 0x3FFF) HandleCommand(); // CHECKME + UpdateIRQ_F1(); return; } @@ -343,7 +512,7 @@ void DSi_NWifi::SDIO_Write(u32 func, u32 addr, u8 val) void DSi_NWifi::SendCMD(u8 cmd, u32 param) -{printf("NWIFI CMD %d %08X %08X\n", cmd, param, NDS::GetPC(1)); +{ switch (cmd) { case 52: // IO_RW_DIRECT @@ -426,6 +595,8 @@ void DSi_NWifi::ReadBlock() u32 func = (TransferCmd >> 28) & 0x7; u32 len = (TransferCmd & (1<<27)) ? 0x200 : RemSize; + len = Host->GetTransferrableLen(len); + u8 data[0x200]; for (u32 i = 0; i < len; i++) @@ -437,7 +608,7 @@ void DSi_NWifi::ReadBlock() TransferAddr &= 0x1FFFF; // checkme } } - Host->SendData(data, len); + len = Host->SendData(data, len); if (RemSize > 0) { @@ -454,8 +625,10 @@ void DSi_NWifi::WriteBlock() u32 func = (TransferCmd >> 28) & 0x7; u32 len = (TransferCmd & (1<<27)) ? 0x200 : RemSize; + len = Host->GetTransferrableLen(len); + u8 data[0x200]; - if (Host->ReceiveData(data, len)) + if (len = Host->ReceiveData(data, len)) { for (u32 i = 0; i < len; i++) { @@ -479,14 +652,32 @@ void DSi_NWifi::WriteBlock() } +void DSi_NWifi::HandleCommand() +{ + switch (BootPhase) + { + case 0: return BMI_Command(); + case 1: return WMI_Command(); + } +} + void DSi_NWifi::BMI_Command() { // HLE command handling stub u32 cmd = MB_Read32(0); - printf("BMI: cmd %08X\n", cmd); switch (cmd) { + case 0x01: // BMI_DONE + { + printf("BMI_DONE\n"); + EEPROMReady = 1; // GROSS FUCKING HACK + u8 ready_msg[8] = {0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00}; + SendWMIFrame(ready_msg, 8, 0, 0x00, 0x0000); + BootPhase = 1; + } + return; + case 0x03: // BMI_WRITE_MEMORY { u32 addr = MB_Read32(0); @@ -546,16 +737,94 @@ void DSi_NWifi::BMI_Command() { u32 len = MB_Read32(0); printf("BMI LZ write %08X\n", len); + //FILE* f = fopen("wififirm.bin", "ab"); for (int i = 0; i < len; i++) { u8 val = Mailbox[0]->Read(); // TODO: do something with it!! + //fwrite(&val, 1, 1, f); } + //fclose(f); } return; + + default: + printf("unknown BMI command %08X\n", cmd); + return; + } +} + +void DSi_NWifi::WMI_Command() +{ + // HLE command handling stub + u16 h0 = MB_Read16(0); + u16 len = MB_Read16(0); + u16 h2 = MB_Read16(0); + + u16 cmd = MB_Read16(0); + printf("WMI: cmd %04X\n", cmd); + + switch (cmd) + { + case 0x0002: // service connect + { + u16 svc_id = MB_Read16(0); + u16 conn_flags = MB_Read16(0); + + u8 svc_resp[10]; + *(u16*)&svc_resp[0] = 0x0003; + *(u16*)&svc_resp[2] = svc_id; + svc_resp[4] = 0; + svc_resp[5] = (svc_id & 0xFF) + 1; + *(u16*)&svc_resp[6] = 0x0001; + *(u16*)&svc_resp[8] = 0x0001; + SendWMIFrame(svc_resp, 10, 0, 0x00, 0x0000); + } + break; + + case 0x0004: // setup complete + { + u8 ready_evt[14]; + memset(ready_evt, 0, 14); + *(u16*)&ready_evt[0] = 0x1001; + memcpy(&ready_evt[2], SPI_Firmware::GetWifiMAC(), 6); + ready_evt[8] = 0x02; + *(u32*)&ready_evt[10] = 0x23000024; + // ctrl[0] = trailer size + // trailer[1] = trailer extra size + // trailer[0] = trailer type??? + SendWMIFrame(ready_evt, 14, 1, 0x00, 0x0000); + } + break; + + default: + printf("unknown WMI command %04X\n", cmd); + break; + } + + MB_Drain(0); +} + +void DSi_NWifi::SendWMIFrame(u8* data, u32 len, u8 ep, u8 flags, u16 ctrl) +{ + u32 wlen = 0; + + Mailbox[4]->Write(ep); // eid + Mailbox[4]->Write(flags); // flags + MB_Write16(4, len); // payload length + MB_Write16(4, ctrl); // ctrl + wlen += 6; + + for (int i = 0; i < len; i++) + { + Mailbox[4]->Write(data[i]); + wlen++; } + + for (; wlen & 0x7F; wlen++) + Mailbox[4]->Write(0); } @@ -563,6 +832,29 @@ u32 DSi_NWifi::WindowRead(u32 addr) { printf("NWifi: window read %08X\n", addr); + if ((addr & 0xFFFF00) == 0x520000) + { + // RAM host interest area + // TODO: different base based on hardware version + + switch (addr & 0xFF) + { + case 0x54: + // base address of EEPROM data + // TODO find what the actual address is! + return 0x1FFC00; + case 0x58: return EEPROMReady; // hax + } + + return 0; + } + + // hax + if ((addr & 0x1FFC00) == 0x1FFC00) + { + return *(u32*)&EEPROM[addr & 0x3FF]; + } + switch (addr) { case 0x40EC: // chip ID diff --git a/src/DSi_NWifi.h b/src/DSi_NWifi.h index 0a36705..e5fe637 100644 --- a/src/DSi_NWifi.h +++ b/src/DSi_NWifi.h @@ -33,11 +33,19 @@ public: void ContinueTransfer(); + void SetIRQ_F1_Counter(u32 n); + private: u32 TransferCmd; u32 TransferAddr; u32 RemSize; + void UpdateIRQ(); + void UpdateIRQ_F1(); + //void SetIRQ_F1_Counter(u32 n); + void ClearIRQ_F1_Counter(u32 n); + void SetIRQ_F1_CPU(u32 n); + u8 F0_Read(u32 addr); void F0_Write(u32 addr, u8 val); @@ -50,11 +58,28 @@ private: void ReadBlock(); void WriteBlock(); + void HandleCommand(); void BMI_Command(); + void WMI_Command(); + + void SendWMIFrame(u8* data, u32 len, u8 ep, u8 flags, u16 ctrl); u32 WindowRead(u32 addr); void WindowWrite(u32 addr, u32 val); + u16 MB_Read16(int n) + { + u16 ret = Mailbox[n]->Read(); + ret |= (Mailbox[n]->Read() << 8); + return ret; + } + + void MB_Write16(int n, u16 val) + { + Mailbox[n]->Write(val & 0xFF); val >>= 8; + Mailbox[n]->Write(val & 0xFF); + } + u32 MB_Read32(int n) { u32 ret = Mailbox[n]->Read(); @@ -72,9 +97,25 @@ private: Mailbox[n]->Write(val & 0xFF); } + void MB_Drain(int n) + { + while (!Mailbox[n]->IsEmpty()) Mailbox[n]->Read(); + } + FIFO* Mailbox[8]; + u8 F0_IRQEnable; + u8 F0_IRQStatus; + + u8 F1_IRQEnable, F1_IRQEnable_CPU, F1_IRQEnable_Error, F1_IRQEnable_Counter; + u8 F1_IRQStatus, F1_IRQStatus_CPU, F1_IRQStatus_Error, F1_IRQStatus_Counter; + u32 WindowData, WindowReadAddr, WindowWriteAddr; + + u8 EEPROM[0x400]; + u32 EEPROMReady; + + u32 BootPhase; }; #endif // DSI_NWIFI_H diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index c9edd78..07eca83 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -73,6 +73,10 @@ void DSi_SDHost::Reset() IRQStatus = 0; IRQMask = 0x8B7F031D; + CardIRQStatus = 0; + CardIRQMask = 0xC007; + CardIRQCtl = 0; + DataCtl = 0; Data32IRQ = 0; DataMode = 0; @@ -145,6 +149,25 @@ void DSi_SDHost::SetIRQ(u32 irq) if (irq == 24 || irq == 25) UpdateData32IRQ(); } +void DSi_SDHost::SetCardIRQ() +{ + if (!(CardIRQCtl & (1<<0))) return; + + u16 oldflags = CardIRQStatus & ~CardIRQMask; + DSi_SDDevice* dev = Ports[PortSelect & 0x1]; + + if (dev->IRQ) CardIRQStatus |= (1<<0); + else CardIRQStatus &= ~(1<<0); + + u16 newflags = CardIRQStatus & ~CardIRQMask; + + if ((oldflags == 0) && (newflags != 0)) // checkme + { + NDS::SetIRQ2(Num ? NDS::IRQ2_DSi_SDIO : NDS::IRQ2_DSi_SDMMC); + NDS::SetIRQ2(Num ? NDS::IRQ2_DSi_SDIO_Data1 : NDS::IRQ2_DSi_SD_Data1); + } +} + void DSi_SDHost::SendResponse(u32 val, bool last) { *(u32*)&ResponseBuffer[6] = *(u32*)&ResponseBuffer[4]; @@ -166,10 +189,10 @@ void DSi_SDHost::FinishSend(u32 param) //if (param & 0x2) host->SetIRQ(2); } -void DSi_SDHost::SendData(u8* data, u32 len) +u32 DSi_SDHost::SendData(u8* data, u32 len) { printf("%s: data RX, len=%d, blkcnt=%d (%d) blklen=%d, irq=%08X\n", SD_DESC, len, BlockCount16, BlockCountInternal, BlockLen16, IRQMask); - if (len != BlockLen16) printf("!! BAD BLOCKLEN\n"); + if (len != BlockLen16) { printf("!! BAD BLOCKLEN\n"); len = BlockLen16; } bool last = (BlockCountInternal == 0); @@ -187,6 +210,8 @@ void DSi_SDHost::SendData(u8* data, u32 len) u32 param = Num | (last << 1); NDS::ScheduleEvent(Num ? NDS::Event_DSi_SDIOTransfer : NDS::Event_DSi_SDMMCTransfer, false, 512, FinishSend, param); + + return len; } void DSi_SDHost::FinishReceive(u32 param) @@ -200,16 +225,16 @@ void DSi_SDHost::FinishReceive(u32 param) if (dev) dev->ContinueTransfer(); } -bool DSi_SDHost::ReceiveData(u8* data, u32 len) +u32 DSi_SDHost::ReceiveData(u8* data, u32 len) { printf("%s: data TX, len=%d, blkcnt=%d (%d) blklen=%d, irq=%08X\n", SD_DESC, len, BlockCount16, BlockCountInternal, BlockLen16, IRQMask); - if (len != BlockLen16) printf("!! BAD BLOCKLEN\n"); + if (len != BlockLen16) { printf("!! BAD BLOCKLEN\n"); len = BlockLen16; } u32 f = CurFIFO; if ((DataFIFO[f]->Level() << 1) < len) { printf("%s: FIFO not full enough for a transfer (%d / %d)\n", SD_DESC, DataFIFO[f]->Level()<<1, len); - return false; + return 0; } DSi_SDDevice* dev = Ports[PortSelect & 0x1]; @@ -240,7 +265,13 @@ bool DSi_SDHost::ReceiveData(u8* data, u32 len) BlockCountInternal--; } - return true; + return len; +} + +u32 DSi_SDHost::GetTransferrableLen(u32 len) +{ + if (len > BlockLen16) len = BlockLen16; // checkme + return len; } @@ -278,6 +309,10 @@ u16 DSi_SDHost::Read(u32 addr) case 0x02C: return 0; // TODO + case 0x034: return CardIRQCtl; + case 0x036: return CardIRQStatus; + case 0x038: return CardIRQMask; + case 0x030: // FIFO16 { // TODO: decrement BlockLen???? @@ -389,7 +424,7 @@ u32 DSi_SDHost::ReadFIFO32() return ret; } - +int morp = 0; void DSi_SDHost::Write(u32 addr, u16 val) { //if(Num)printf("SDIO WRITE %08X %04X %08X\n", addr, val, NDS::GetPC(1)); @@ -470,6 +505,20 @@ void DSi_SDHost::Write(u32 addr, u16 val) } return; + case 0x034: + CardIRQCtl = val & 0x0305; + printf("[%d] CardIRQCtl = %04X\n", Num, val); + SetCardIRQ(); + return; + case 0x036: + CardIRQStatus &= val; + return; + case 0x038: + CardIRQMask = val & 0xC007; + printf("[%d] CardIRQMask = %04X\n", Num, val); + SetCardIRQ(); + return; + case 0x0D8: DataCtl = (val & 0x0022); DataMode = ((DataCtl >> 1) & 0x1) & ((Data32IRQ >> 1) & 0x1); @@ -729,42 +778,54 @@ void DSi_MMCStorage::ContinueTransfer() { if (RWCommand == 0) return; + u32 len = 0; + switch (RWCommand) { case 18: - ReadBlock(RWAddress); + len = ReadBlock(RWAddress); break; case 25: - WriteBlock(RWAddress); + len = WriteBlock(RWAddress); break; } - RWAddress += BlockSize; + RWAddress += len; } -void DSi_MMCStorage::ReadBlock(u64 addr) +u32 DSi_MMCStorage::ReadBlock(u64 addr) { - if (!File) return; - printf("SD/MMC: reading block @ %08X, len=%08X\n", addr, BlockSize); + u32 len = BlockSize; + len = Host->GetTransferrableLen(len); + u8 data[0x200]; - fseek(File, addr, SEEK_SET); - fread(data, 1, BlockSize, File); - Host->SendData(data, BlockSize); + if (File) + { + fseek(File, addr, SEEK_SET); + fread(data, 1, len, File); + } + return Host->SendData(data, len); } -void DSi_MMCStorage::WriteBlock(u64 addr) +u32 DSi_MMCStorage::WriteBlock(u64 addr) { - if (!File) return; - printf("SD/MMC: write block @ %08X, len=%08X\n", addr, BlockSize); + u32 len = BlockSize; + len = Host->GetTransferrableLen(len); + u8 data[0x200]; - if (Host->ReceiveData(data, BlockSize)) + if (len = Host->ReceiveData(data, len)) { - fseek(File, addr, SEEK_SET); - fwrite(data, 1, BlockSize, File); + if (File) + { + fseek(File, addr, SEEK_SET); + fwrite(data, 1, len, File); + } } + + return len; } diff --git a/src/DSi_SD.h b/src/DSi_SD.h index 22475d6..149b72a 100644 --- a/src/DSi_SD.h +++ b/src/DSi_SD.h @@ -39,8 +39,11 @@ public: static void FinishSend(u32 param); static void FinishReceive(u32 param); void SendResponse(u32 val, bool last); - void SendData(u8* data, u32 len); - bool ReceiveData(u8* data, u32 len); + u32 SendData(u8* data, u32 len); + u32 ReceiveData(u8* data, u32 len); + u32 GetTransferrableLen(u32 len); + + void SetCardIRQ(); u16 Read(u32 addr); void Write(u32 addr, u16 val); @@ -58,6 +61,10 @@ private: u32 IRQStatus; // IF u32 IRQMask; // ~IE + u16 CardIRQStatus; + u16 CardIRQMask; + u16 CardIRQCtl; + u16 DataCtl; u16 Data32IRQ; u32 DataMode; // 0=16bit 1=32bit @@ -83,12 +90,14 @@ private: class DSi_SDDevice { public: - DSi_SDDevice(DSi_SDHost* host) { Host = host; } + DSi_SDDevice(DSi_SDHost* host) { Host = host; IRQ = false; } ~DSi_SDDevice() {} virtual void SendCMD(u8 cmd, u32 param) = 0; virtual void ContinueTransfer() = 0; + bool IRQ; + protected: DSi_SDHost* Host; }; @@ -127,8 +136,8 @@ private: void SetState(u32 state) { CSR &= ~(0xF << 9); CSR |= (state << 9); } - void ReadBlock(u64 addr); - void WriteBlock(u64 addr); + u32 ReadBlock(u64 addr); + u32 WriteBlock(u64 addr); }; #endif // DSI_SD_H diff --git a/src/FIFO.h b/src/FIFO.h index a9e9ed8..213db7a 100644 --- a/src/FIFO.h +++ b/src/FIFO.h @@ -89,6 +89,15 @@ public: return Entries[ReadPos]; } + T Peek(u32 offset) + { + u32 pos = ReadPos + offset; + if (pos >= NumEntries) + pos -= NumEntries; + + return Entries[pos]; + } + u32 Level() { return NumOccupied; } bool IsEmpty() { return NumOccupied == 0; } bool IsFull() { return NumOccupied >= NumEntries; } diff --git a/src/NDS.h b/src/NDS.h index e32908b..fd94a01 100644 --- a/src/NDS.h +++ b/src/NDS.h @@ -45,6 +45,7 @@ enum // DSi Event_DSi_SDMMCTransfer, Event_DSi_SDIOTransfer, + Event_DSi_NWifi, Event_MAX }; diff --git a/src/SPI.cpp b/src/SPI.cpp index 8bee66f..783e638 100644 --- a/src/SPI.cpp +++ b/src/SPI.cpp @@ -225,6 +225,7 @@ void SetupDirectBoot() u8 GetConsoleType() { return Firmware[0x1D]; } u8 GetWifiVersion() { return Firmware[0x2F]; } u8 GetRFVersion() { return Firmware[0x40]; } +u8* GetWifiMAC() { return &Firmware[0x36]; } u8 Read() { diff --git a/src/SPI.h b/src/SPI.h index 21ad9a6..44de876 100644 --- a/src/SPI.h +++ b/src/SPI.h @@ -29,6 +29,7 @@ void SetupDirectBoot(); u8 GetConsoleType(); u8 GetWifiVersion(); u8 GetRFVersion(); +u8* GetWifiMAC(); } -- cgit v1.2.3 From a6a9f74acc2fe1c0645dae7b06816d7fc6a67f81 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 4 Aug 2019 11:44:36 +0200 Subject: lay base for DSi-mode TSC --- melonDS.cbp | 2 + src/DSi_SPI_TSC.cpp | 113 +++++++++++++++++++++++++++++++++++++++++++++++++ src/DSi_SPI_TSC.h | 40 +++++++++++++++++ src/NDS.cpp | 32 ++++++++------ src/NDS.h | 2 - src/SPI.cpp | 14 ++++-- src/libui_sdl/main.cpp | 2 - 7 files changed, 186 insertions(+), 19 deletions(-) create mode 100644 src/DSi_SPI_TSC.cpp create mode 100644 src/DSi_SPI_TSC.h (limited to 'src') diff --git a/melonDS.cbp b/melonDS.cbp index 2fd6ed0..cc5357b 100644 --- a/melonDS.cbp +++ b/melonDS.cbp @@ -114,6 +114,8 @@ + + diff --git a/src/DSi_SPI_TSC.cpp b/src/DSi_SPI_TSC.cpp new file mode 100644 index 0000000..253cef8 --- /dev/null +++ b/src/DSi_SPI_TSC.cpp @@ -0,0 +1,113 @@ +/* + Copyright 2016-2019 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include +#include +#include "DSi.h" +#include "DSi_SPI_TSC.h" + + +namespace DSi_SPI_TSC +{ + +u32 DataPos; +u8 Index; +u8 Mode; +u8 Data; + +u16 TouchX, TouchY; + + +bool Init() +{ + return true; +} + +void DeInit() +{ +} + +void Reset() +{ + DataPos = 0; + + Mode = 0; + Index = 0; + Data = 0; +} + +void DoSavestate(Savestate* file) +{ + /*file->Section("SPTi"); + + file->Var32(&DataPos); + file->Var8(&ControlByte); + file->Var8(&Data); + + file->Var16(&ConvResult);*/ + // TODO!! +} + +void SetTouchCoords(u16 x, u16 y) +{ + TouchX = x; + TouchY = y; + + if (y == 0xFFF) return; + + TouchX <<= 4; + TouchY <<= 4; +} + +void MicInputFrame(s16* data, int samples) +{ + // TODO: forward to DS-mode TSC if needed +} + +u8 Read() +{ + return Data; +} + +void Write(u8 val, u32 hold) +{ +#define READWRITE(var) { if (Index & 0x01) Data = var; else var = val; } +printf("TSC: %02X %d\n", val, hold?1:0); + if (DataPos == 0) + { + Index = val; + } + else + { + if ((Index & 0xFE) == 0) + { + READWRITE(Mode); + } + else + { + printf("DSi_SPI_TSC: unknown IO, mode=%02X, index=%02X (%02X %s)\n", Mode, Index, Index>>1, (Index&1)?"read":"write"); + } + + Index += (1<<1); // increment index + } + + if (hold) DataPos++; + else DataPos = 0; +} + +} diff --git a/src/DSi_SPI_TSC.h b/src/DSi_SPI_TSC.h new file mode 100644 index 0000000..f3ffc32 --- /dev/null +++ b/src/DSi_SPI_TSC.h @@ -0,0 +1,40 @@ +/* + Copyright 2016-2019 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef DSI_SPI_TSC +#define DSI_SPI_TSC + +namespace DSi_SPI_TSC +{ + +extern u32 DataPos; + +bool Init(); +void DeInit(); +void Reset(); +void DoSavestate(Savestate* file); + +void SetTouchCoords(u16 x, u16 y); +void MicInputFrame(s16* data, int samples); + +u8 Read(); +void Write(u8 val, u32 hold); + +} + +#endif // DSI_SPI_TSC diff --git a/src/NDS.cpp b/src/NDS.cpp index 61cf547..da7f9f9 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -32,6 +32,7 @@ #include "Platform.h" #include "DSi.h" +#include "DSi_SPI_TSC.h" namespace NDS @@ -519,6 +520,7 @@ void Reset() Wifi::Reset(); DSi::Reset(); + KeyInput &= ~(1 << (16+6)); // TODO } void Stop() @@ -932,24 +934,30 @@ void CancelEvent(u32 id) } -void PressKey(u32 key) -{ - KeyInput &= ~(1 << key); -} - -void ReleaseKey(u32 key) -{ - KeyInput |= (1 << key); -} - void TouchScreen(u16 x, u16 y) { - SPI_TSC::SetTouchCoords(x, y); + if (true) // TODO!! + { + DSi_SPI_TSC::SetTouchCoords(x, y); + } + else + { + SPI_TSC::SetTouchCoords(x, y); + KeyInput &= ~(1 << (16+6)); + } } void ReleaseScreen() { - SPI_TSC::SetTouchCoords(0x000, 0xFFF); + if (true) // TODO!! + { + DSi_SPI_TSC::SetTouchCoords(0x000, 0xFFF); + } + else + { + SPI_TSC::SetTouchCoords(0x000, 0xFFF); + KeyInput |= (1 << (16+6)); + } } diff --git a/src/NDS.h b/src/NDS.h index fd94a01..d391cf7 100644 --- a/src/NDS.h +++ b/src/NDS.h @@ -180,8 +180,6 @@ void RelocateSave(const char* path, bool write); u32 RunFrame(); -void PressKey(u32 key); -void ReleaseKey(u32 key); void TouchScreen(u16 x, u16 y); void ReleaseScreen(); diff --git a/src/SPI.cpp b/src/SPI.cpp index 783e638..e21ad0c 100644 --- a/src/SPI.cpp +++ b/src/SPI.cpp @@ -22,6 +22,7 @@ #include "Config.h" #include "NDS.h" #include "SPI.h" +#include "DSi_SPI_TSC.h" #include "Platform.h" @@ -590,6 +591,7 @@ bool Init() if (!SPI_Firmware::Init()) return false; if (!SPI_Powerman::Init()) return false; if (!SPI_TSC::Init()) return false; + if (!DSi_SPI_TSC::Init()) return false; return true; } @@ -599,6 +601,7 @@ void DeInit() SPI_Firmware::DeInit(); SPI_Powerman::DeInit(); SPI_TSC::DeInit(); + DSi_SPI_TSC::DeInit(); } void Reset() @@ -608,6 +611,7 @@ void Reset() SPI_Firmware::Reset(); SPI_Powerman::Reset(); SPI_TSC::Reset(); + DSi_SPI_TSC::Reset(); } void DoSavestate(Savestate* file) @@ -620,6 +624,7 @@ void DoSavestate(Savestate* file) SPI_Firmware::DoSavestate(file); SPI_Powerman::DoSavestate(file); SPI_TSC::DoSavestate(file); + DSi_SPI_TSC::DoSavestate(file); } @@ -633,7 +638,8 @@ void WriteCnt(u16 val) { case 0x0000: SPI_Powerman::Hold = 0; break; case 0x0100: SPI_Firmware::Hold = 0; break; - case 0x0200: SPI_TSC::DataPos = 0; break; + //case 0x0200: SPI_TSC::DataPos = 0; break; + case 0x0200: DSi_SPI_TSC::DataPos = 0; break; } } @@ -659,7 +665,8 @@ u8 ReadData() { case 0x0000: return SPI_Powerman::Read(); case 0x0100: return SPI_Firmware::Read(); - case 0x0200: return SPI_TSC::Read(); + //case 0x0200: return SPI_TSC::Read(); + case 0x0200: return DSi_SPI_TSC::Read(); default: return 0; } } @@ -675,7 +682,8 @@ void WriteData(u8 val) { case 0x0000: SPI_Powerman::Write(val, Cnt&(1<<11)); break; case 0x0100: SPI_Firmware::Write(val, Cnt&(1<<11)); break; - case 0x0200: SPI_TSC::Write(val, Cnt&(1<<11)); break; + //case 0x0200: SPI_TSC::Write(val, Cnt&(1<<11)); break; + case 0x0200: DSi_SPI_TSC::Write(val, Cnt&(1<<11)); break; default: printf("SPI to unknown device %04X %02X\n", Cnt, val); break; } diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 86949eb..34e838c 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -1088,7 +1088,6 @@ void OnAreaMouseEvent(uiAreaHandler* handler, uiArea* area, uiAreaMouseEvent* ev if (Touching && (evt->Up == 1)) { Touching = false; - NDS::ReleaseKey(16+6); NDS::ReleaseScreen(); } else if (!Touching && (evt->Down == 1) && @@ -1096,7 +1095,6 @@ void OnAreaMouseEvent(uiAreaHandler* handler, uiArea* area, uiAreaMouseEvent* ev (x < (BottomScreenRect.X+BottomScreenRect.Width)) && (y < (BottomScreenRect.Y+BottomScreenRect.Height))) { Touching = true; - NDS::PressKey(16+6); } if (Touching) -- cgit v1.2.3 From f897d8c0d760e0e9583910b296901568abce6b90 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 4 Aug 2019 12:13:01 +0200 Subject: touchscreen input, somewhat it's off, need to patch the calibration data --- src/DSi_SPI_TSC.cpp | 86 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/DSi_SPI_TSC.cpp b/src/DSi_SPI_TSC.cpp index 253cef8..2ec9858 100644 --- a/src/DSi_SPI_TSC.cpp +++ b/src/DSi_SPI_TSC.cpp @@ -30,6 +30,8 @@ u8 Index; u8 Mode; u8 Data; +u8 Mode3Regs[0x80]; + u16 TouchX, TouchY; @@ -49,6 +51,18 @@ void Reset() Mode = 0; Index = 0; Data = 0; + + memset(Mode3Regs, 0, 0x80); + Mode3Regs[0x02] = 0x18; + Mode3Regs[0x03] = 0x87; + Mode3Regs[0x04] = 0x22; + Mode3Regs[0x05] = 0x04; + Mode3Regs[0x06] = 0x20; + Mode3Regs[0x09] = 0x40; + Mode3Regs[0x0E] = 0xAD; + Mode3Regs[0x0F] = 0xA0; + Mode3Regs[0x10] = 0x88; + Mode3Regs[0x11] = 0x81; } void DoSavestate(Savestate* file) @@ -67,11 +81,36 @@ void SetTouchCoords(u16 x, u16 y) { TouchX = x; TouchY = y; +printf("touching: %d/%d\n", x, y); + u8 oldpress = Mode3Regs[0x0E] & 0x01; + + if (y == 0xFFF) + { + // released + + // TODO: GBAtek says it can also be 1000 or 3000?? + TouchX = 0x7000; + TouchY = 0x7000; - if (y == 0xFFF) return; + Mode3Regs[0x09] = 0x40; + Mode3Regs[0x0E] |= 0x01; + } + else + { + // pressed - TouchX <<= 4; - TouchY <<= 4; + TouchX <<= 4; + TouchY <<= 4; + + Mode3Regs[0x09] = 0x80; + Mode3Regs[0x0E] &= ~0x01; + } + + if (oldpress ^ (Mode3Regs[0x0E] & 0x01)) + { + TouchX |= 0x8000; + TouchY |= 0x8000; + } } void MicInputFrame(s16* data, int samples) @@ -87,17 +126,54 @@ u8 Read() void Write(u8 val, u32 hold) { #define READWRITE(var) { if (Index & 0x01) Data = var; else var = val; } -printf("TSC: %02X %d\n", val, hold?1:0); + if (DataPos == 0) { Index = val; } else { - if ((Index & 0xFE) == 0) + u8 id = Index >> 1; + + if (id == 0) { READWRITE(Mode); } + else if (Mode == 0x03) + { + if (Index & 0x01) Data = Mode3Regs[id]; + else + { + if (id == 0x0D || id == 0x0E) + Mode3Regs[id] = (Mode3Regs[id] & 0x03) | (val & 0xFC); + } + } + else if ((Mode == 0xFC) && (Index & 0x01)) + { + if (id < 0x0B) + { + // X coordinates + + if (id & 0x01) Data = TouchX >> 8; + else Data = TouchX & 0xFF; + + TouchX &= 0x7FFF; + } + else if (id < 0x15) + { + // Y coordinates + + if (id & 0x01) Data = TouchY >> 8; + else Data = TouchY & 0xFF; + + TouchY &= 0x7FFF; // checkme + } + else + { + // whatever (TODO) + Data = 0; + } + } else { printf("DSi_SPI_TSC: unknown IO, mode=%02X, index=%02X (%02X %s)\n", Mode, Index, Index>>1, (Index&1)?"read":"write"); -- cgit v1.2.3 From a9f36929e05e40abc9e91567443199b07530638f Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 4 Aug 2019 14:34:33 +0200 Subject: TSC: add backwards-compatibility --- src/DSi_SPI_TSC.cpp | 98 ++++++++++++++++++++++++++++++++++++++--------------- src/NDS.cpp | 4 +-- src/NDS.h | 2 ++ src/SPI.h | 3 ++ 4 files changed, 77 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/DSi_SPI_TSC.cpp b/src/DSi_SPI_TSC.cpp index 2ec9858..507005b 100644 --- a/src/DSi_SPI_TSC.cpp +++ b/src/DSi_SPI_TSC.cpp @@ -19,6 +19,7 @@ #include #include #include "DSi.h" +#include "SPI.h" #include "DSi_SPI_TSC.h" @@ -27,10 +28,11 @@ namespace DSi_SPI_TSC u32 DataPos; u8 Index; -u8 Mode; +u8 Bank; u8 Data; -u8 Mode3Regs[0x80]; +u8 Bank3Regs[0x80]; +u8 TSCMode; u16 TouchX, TouchY; @@ -48,21 +50,23 @@ void Reset() { DataPos = 0; - Mode = 0; + Bank = 0; Index = 0; Data = 0; - memset(Mode3Regs, 0, 0x80); - Mode3Regs[0x02] = 0x18; - Mode3Regs[0x03] = 0x87; - Mode3Regs[0x04] = 0x22; - Mode3Regs[0x05] = 0x04; - Mode3Regs[0x06] = 0x20; - Mode3Regs[0x09] = 0x40; - Mode3Regs[0x0E] = 0xAD; - Mode3Regs[0x0F] = 0xA0; - Mode3Regs[0x10] = 0x88; - Mode3Regs[0x11] = 0x81; + memset(Bank3Regs, 0, 0x80); + Bank3Regs[0x02] = 0x18; + Bank3Regs[0x03] = 0x87; + Bank3Regs[0x04] = 0x22; + Bank3Regs[0x05] = 0x04; + Bank3Regs[0x06] = 0x20; + Bank3Regs[0x09] = 0x40; + Bank3Regs[0x0E] = 0xAD; + Bank3Regs[0x0F] = 0xA0; + Bank3Regs[0x10] = 0x88; + Bank3Regs[0x11] = 0x81; + + TSCMode = 0x01; // DSi mode } void DoSavestate(Savestate* file) @@ -79,10 +83,17 @@ void DoSavestate(Savestate* file) void SetTouchCoords(u16 x, u16 y) { + if (TSCMode == 0x00) + { + if (y == 0xFFF) NDS::KeyInput |= (1 << (16+6)); + else NDS::KeyInput &= ~(1 << (16+6)); + return SPI_TSC::SetTouchCoords(x, y); + } + TouchX = x; TouchY = y; -printf("touching: %d/%d\n", x, y); - u8 oldpress = Mode3Regs[0x0E] & 0x01; + + u8 oldpress = Bank3Regs[0x0E] & 0x01; if (y == 0xFFF) { @@ -92,8 +103,9 @@ printf("touching: %d/%d\n", x, y); TouchX = 0x7000; TouchY = 0x7000; - Mode3Regs[0x09] = 0x40; - Mode3Regs[0x0E] |= 0x01; + Bank3Regs[0x09] = 0x40; + //Bank3Regs[0x09] &= ~0x80; + Bank3Regs[0x0E] |= 0x01; } else { @@ -102,11 +114,12 @@ printf("touching: %d/%d\n", x, y); TouchX <<= 4; TouchY <<= 4; - Mode3Regs[0x09] = 0x80; - Mode3Regs[0x0E] &= ~0x01; + Bank3Regs[0x09] = 0x80; + //Bank3Regs[0x09] |= 0x80; + Bank3Regs[0x0E] &= ~0x01; } - if (oldpress ^ (Mode3Regs[0x0E] & 0x01)) + if (oldpress ^ (Bank3Regs[0x0E] & 0x01)) { TouchX |= 0x8000; TouchY |= 0x8000; @@ -115,16 +128,23 @@ printf("touching: %d/%d\n", x, y); void MicInputFrame(s16* data, int samples) { - // TODO: forward to DS-mode TSC if needed + if (TSCMode == 0x00) return SPI_TSC::MicInputFrame(data, samples); + + // otherwise we don't handle mic input + // TODO: handle it where it needs to be } u8 Read() { + if (TSCMode == 0x00) return SPI_TSC::Read(); + return Data; } void Write(u8 val, u32 hold) { + if (TSCMode == 0x00) return SPI_TSC::Write(val, hold); + #define READWRITE(var) { if (Index & 0x01) Data = var; else var = val; } if (DataPos == 0) @@ -137,18 +157,18 @@ void Write(u8 val, u32 hold) if (id == 0) { - READWRITE(Mode); + READWRITE(Bank); } - else if (Mode == 0x03) + else if (Bank == 0x03) { - if (Index & 0x01) Data = Mode3Regs[id]; + if (Index & 0x01) Data = Bank3Regs[id]; else { if (id == 0x0D || id == 0x0E) - Mode3Regs[id] = (Mode3Regs[id] & 0x03) | (val & 0xFC); + Bank3Regs[id] = (Bank3Regs[id] & 0x03) | (val & 0xFC); } } - else if ((Mode == 0xFC) && (Index & 0x01)) + else if ((Bank == 0xFC) && (Index & 0x01)) { if (id < 0x0B) { @@ -174,9 +194,31 @@ void Write(u8 val, u32 hold) Data = 0; } } + else if (Bank == 0xFF) + { + if (id == 0x05) + { + // TSC mode register + // 01: normal (DSi) mode + // 00: compatibility (DS) mode + + if (Index & 0x01) Data = TSCMode; + else + { + TSCMode = val; + if (TSCMode == 0x00) + { + printf("DSi_SPI_TSC: DS-compatibility mode\n"); + DataPos = 0; + NDS::KeyInput |= (1 << (16+6)); + return; + } + } + } + } else { - printf("DSi_SPI_TSC: unknown IO, mode=%02X, index=%02X (%02X %s)\n", Mode, Index, Index>>1, (Index&1)?"read":"write"); + printf("DSi_SPI_TSC: unknown IO, bank=%02X, index=%02X (%02X %s)\n", Bank, Index, Index>>1, (Index&1)?"read":"write"); } Index += (1<<1); // increment index diff --git a/src/NDS.cpp b/src/NDS.cpp index da7f9f9..42b5d9f 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -580,7 +580,7 @@ bool DoSavestate_Scheduler(Savestate* file) } if (funcid == -1) { - printf("savestate: VERY BAD!!!!! FUNCTION POINTER FOR EVENT %d NOT IN HACKY LIST. CANNOT SAVE. SMACK STAPLEBUTTER.\n", i); + printf("savestate: VERY BAD!!!!! FUNCTION POINTER FOR EVENT %d NOT IN HACKY LIST. CANNOT SAVE. SMACK ARISOTURA.\n", i); return false; } } @@ -694,7 +694,7 @@ bool DoSavestate(Savestate* file) for (int i = 0; i < 8; i++) DMAs[i]->DoSavestate(file); - file->Var8(&WRAMCnt); + file->Var8(&WRAMCnt); // FIXME!!!!! if (!file->Saving) { diff --git a/src/NDS.h b/src/NDS.h index d391cf7..309b16a 100644 --- a/src/NDS.h +++ b/src/NDS.h @@ -163,6 +163,8 @@ extern u8 ARM7BIOS[0x10000]; extern u8 MainRAM[MAIN_RAM_SIZE]; +extern u32 KeyInput; + bool Init(); void DeInit(); void Reset(); diff --git a/src/SPI.h b/src/SPI.h index 44de876..73fd57e 100644 --- a/src/SPI.h +++ b/src/SPI.h @@ -39,6 +39,9 @@ namespace SPI_TSC void SetTouchCoords(u16 x, u16 y); void MicInputFrame(s16* data, int samples); +u8 Read(); +void Write(u8 val, u32 hold); + } namespace SPI -- cgit v1.2.3 From 36c741241a3efbfeb81a447c53917b1ab586fe73 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 4 Aug 2019 16:46:02 +0200 Subject: support DSi-mode carts except they need to have the DSi-mode shit encrypted --- src/DSi.cpp | 27 ++++++++++++------ src/DSi.h | 1 + src/DSi_SD.cpp | 4 +-- src/NDSCart.cpp | 87 ++++++++++++++++++++++++++++++++++++++++----------------- src/NDSCart.h | 2 ++ 5 files changed, 85 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index 17d7f0d..771f67b 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -22,6 +22,7 @@ #include "DSi.h" #include "ARM.h" #include "GPU.h" +#include "NDSCart.h" #include "Platform.h" #include "DSi_NDMA.h" @@ -581,6 +582,22 @@ void MapNWRAMRange(u32 cpu, u32 num, u32 val) } +void Set_SCFG_MC(u32 val) +{ + u32 oldslotstatus = SCFG_MC & 0xC; + + val &= 0xFFFF800C; + if ((val & 0xC) == 0xC) val &= ~0xC; // hax + if (val & 0x8000) printf("SCFG_MC: weird NDS slot swap\n"); + SCFG_MC = (SCFG_MC & ~0xFFFF800C) | val; + + if ((oldslotstatus == 0x0) && ((SCFG_MC & 0xC) == 0x4)) + { + NDSCart::ResetCart(); + } +} + + u8 ARM9Read8(u32 addr) { switch (addr & 0xFF000000) @@ -1455,10 +1472,7 @@ void ARM7IOWrite16(u32 addr, u16 val) return; case 0x04004010: - val &= 0x800C; - if ((val & 0xC) == 0xC) val &= ~0xC; // hax - if (val & 0x8000) printf("SCFG_MC: weird NDS slot swap\n"); - SCFG_MC = (SCFG_MC & ~0x800C) | val; + Set_SCFG_MC((SCFG_MC & 0xFFFF0000) | val); return; } @@ -1491,10 +1505,7 @@ void ARM7IOWrite32(u32 addr, u32 val) printf("SCFG_EXT = %08X / %08X (val7 %08X)\n", SCFG_EXT[0], SCFG_EXT[1], val); return; case 0x04004010: - val &= 0xFFFF800C; - if ((val & 0xC) == 0xC) val &= ~0xC; // hax - if (val & 0x8000) printf("SCFG_MC: weird NDS slot swap\n"); - SCFG_MC = (SCFG_MC & ~0xFFFF800C) | val; + Set_SCFG_MC(val); return; case 0x04004054: MapNWRAMRange(1, 0, val); return; diff --git a/src/DSi.h b/src/DSi.h index db585b4..b29cdb5 100644 --- a/src/DSi.h +++ b/src/DSi.h @@ -32,6 +32,7 @@ extern DSi_SDHost* SDMMC; extern DSi_SDHost* SDIO; extern u8 ITCMInit[0x8000]; +extern u8 ARM7Init[0x3C00]; bool Init(); diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index 07eca83..44d8d62 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -191,7 +191,7 @@ void DSi_SDHost::FinishSend(u32 param) u32 DSi_SDHost::SendData(u8* data, u32 len) { - printf("%s: data RX, len=%d, blkcnt=%d (%d) blklen=%d, irq=%08X\n", SD_DESC, len, BlockCount16, BlockCountInternal, BlockLen16, IRQMask); + //printf("%s: data RX, len=%d, blkcnt=%d (%d) blklen=%d, irq=%08X\n", SD_DESC, len, BlockCount16, BlockCountInternal, BlockLen16, IRQMask); if (len != BlockLen16) { printf("!! BAD BLOCKLEN\n"); len = BlockLen16; } bool last = (BlockCountInternal == 0); @@ -796,7 +796,7 @@ void DSi_MMCStorage::ContinueTransfer() u32 DSi_MMCStorage::ReadBlock(u64 addr) { - printf("SD/MMC: reading block @ %08X, len=%08X\n", addr, BlockSize); + //printf("SD/MMC: reading block @ %08X, len=%08X\n", addr, BlockSize); u32 len = BlockSize; len = Host->GetTransferrableLen(len); diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index 0bb8b5c..c3765d8 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -475,6 +475,7 @@ u32 CartROMSize; u32 CartCRC; u32 CartID; bool CartIsHomebrew; +bool CartIsDSi; u32 CmdEncMode; u32 DataEncMode; @@ -557,10 +558,13 @@ void Key1_ApplyKeycode(u32* keycode, u32 mod) } } -void Key1_InitKeycode(u32 idcode, u32 level, u32 mod) +void Key1_InitKeycode(bool dsi, u32 idcode, u32 level, u32 mod) { //memcpy(Key1_KeyBuf, &NDS::ARM7BIOS[0x30], 0x1048); // hax - memcpy(Key1_KeyBuf, &DSi::ITCMInit[0x4894], 0x1048); // hax + if (dsi) + memcpy(Key1_KeyBuf, &DSi::ARM7Init[0x254], 0x1048); // hax + else + memcpy(Key1_KeyBuf, &DSi::ITCMInit[0x4894], 0x1048); // hax u32 keycode[3] = {idcode, idcode>>1, idcode<<1}; if (level >= 1) Key1_ApplyKeycode(keycode, mod); @@ -613,32 +617,19 @@ void DeInit() void Reset() { - SPICnt = 0; - ROMCnt = 0; - - memset(ROMCommand, 0, 8); - ROMDataOut = 0; - - Key2_X = 0; - Key2_Y = 0; - - memset(DataOut, 0, 0x4000); - DataOutPos = 0; - DataOutLen = 0; - CartInserted = false; if (CartROM) delete[] CartROM; CartROM = NULL; CartROMSize = 0; CartID = 0; CartIsHomebrew = false; + CartIsDSi = false; ROMCommandHandler = NULL; - CmdEncMode = 0; - DataEncMode = 0; - NDSCart_SRAM::Reset(); + + ResetCart(); } void DoSavestate(Savestate* file) @@ -893,6 +884,11 @@ bool LoadROM(const char* path, const char* sram, bool direct) fread(&gamecode, 4, 1, f); printf("Game code: %c%c%c%c\n", gamecode&0xFF, (gamecode>>8)&0xFF, (gamecode>>16)&0xFF, gamecode>>24); + u8 unitcode; + fseek(f, 0x12, SEEK_SET); + fread(&unitcode, 1, 1, f); + CartIsDSi = (unitcode & 0x02) != 0; + CartROM = new u8[CartROMSize]; memset(CartROM, 0, CartROMSize); fseek(f, 0, SEEK_SET); @@ -934,6 +930,9 @@ bool LoadROM(const char* path, const char* sram, bool direct) if (romparams[1] == 8) CartID |= 0x08000000; // NAND flag + if (CartIsDSi) + CartID |= 0x40000000; + printf("Cart ID: %08X\n", CartID); if (*(u32*)&CartROM[0x20] < 0x4000) @@ -969,11 +968,11 @@ bool LoadROM(const char* path, const char* sram, bool direct) strncpy((char*)&CartROM[arm9base], "encryObj", 8); - Key1_InitKeycode(gamecode, 3, 2); + Key1_InitKeycode(false, gamecode, 3, 2); for (u32 i = 0; i < 0x800; i += 8) Key1_Encrypt((u32*)&CartROM[arm9base + i]); - Key1_InitKeycode(gamecode, 2, 2); + Key1_InitKeycode(false, gamecode, 2, 2); Key1_Encrypt((u32*)&CartROM[arm9base]); } } @@ -981,9 +980,6 @@ bool LoadROM(const char* path, const char* sram, bool direct) CartIsHomebrew = true; } - // encryption - Key1_InitKeycode(gamecode, 2, 2); - // save printf("Save file: %s\n", sram); @@ -998,6 +994,27 @@ void RelocateSave(const char* path, bool write) NDSCart_SRAM::RelocateSave(path, write); } +void ResetCart() +{ + // CHECKME: what if there is a transfer in progress? + + SPICnt = 0; + ROMCnt = 0; + + memset(ROMCommand, 0, 8); + ROMDataOut = 0; + + Key2_X = 0; + Key2_Y = 0; + + memset(DataOut, 0, 0x4000); + DataOutPos = 0; + DataOutLen = 0; + + CmdEncMode = 0; + DataEncMode = 0; +} + void ReadROM(u32 addr, u32 len, u32 offset) { if (!CartInserted) return; @@ -1172,7 +1189,7 @@ void WriteROMCnt(u32 val) // handle KEY1 encryption as needed. // KEY2 encryption is implemented in hardware and doesn't need to be handled. u8 cmd[8]; - if (CmdEncMode == 1) + if (CmdEncMode == 1 || CmdEncMode == 11) { *(u32*)&cmd[0] = ByteSwap(*(u32*)&ROMCommand[4]); *(u32*)&cmd[4] = ByteSwap(*(u32*)&ROMCommand[0]); @@ -1218,11 +1235,23 @@ void WriteROMCnt(u32 val) break; case 0x3C: - if (CartInserted) CmdEncMode = 1; + if (CartInserted) + { + CmdEncMode = 1; + Key1_InitKeycode(false, *(u32*)&CartROM[0xC], 2, 2); + } + break; + + case 0x3D: + if (CartInserted && CartIsDSi) + { + CmdEncMode = 11; + Key1_InitKeycode(true, *(u32*)&CartROM[0xC], 1, 2); + } break; default: - if (CmdEncMode == 1) + if (CmdEncMode == 1 || CmdEncMode == 11) { switch (cmd[0] & 0xF0) { @@ -1238,6 +1267,12 @@ void WriteROMCnt(u32 val) case 0x20: { u32 addr = (cmd[2] & 0xF0) << 8; + if (CmdEncMode == 11) + { + u32 arm9i_base = *(u32*)&CartROM[0x1C0]; + addr -= 0x4000; + addr += arm9i_base; + } ReadROM(addr, 0x1000, 0); } break; diff --git a/src/NDSCart.h b/src/NDSCart.h index 0dc4220..05516d7 100644 --- a/src/NDSCart.h +++ b/src/NDSCart.h @@ -47,6 +47,8 @@ void DoSavestate(Savestate* file); bool LoadROM(const char* path, const char* sram, bool direct); void RelocateSave(const char* path, bool write); +void ResetCart(); + void WriteROMCnt(u32 val); u32 ReadROMData(); -- cgit v1.2.3 From 4d3d8433cbfc7916a344c18c491da401f6e32bfb Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 5 Aug 2019 19:52:03 +0200 Subject: * add old DS BIOSes and 04004000 BIOS-switch fixes audio issues when running DS games * attempt adding other fun shit like dynamic RAM size, but that mostly went nowhere for now --- src/DSi.cpp | 191 ++++++++++++++++++++++++++++++++++++++++++++++++++---------- src/DSi.h | 3 + src/NDS.cpp | 154 ++++++++++++++++++++++++++---------------------- src/NDS.h | 11 ++-- 4 files changed, 251 insertions(+), 108 deletions(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index 771f67b..9f07fa1 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -45,11 +45,15 @@ namespace DSi u32 BootAddr[2]; +u16 SCFG_BIOS; u16 SCFG_Clock9; u16 SCFG_Clock7; u32 SCFG_EXT[2]; u32 SCFG_MC; +u8 ARM9iBIOS[0x10000]; +u8 ARM7iBIOS[0x10000]; + u32 MBK[2][9]; u8 NWRAM_A[0x40000]; @@ -131,6 +135,7 @@ void Reset() SDMMC->Reset(); SDIO->Reset(); + SCFG_BIOS = 0x0101; // TODO: should be zero when booting from BIOS SCFG_Clock9 = 0x0187; // CHECKME SCFG_Clock7 = 0x0187; SCFG_EXT[0] = 0x8307F100; @@ -160,18 +165,21 @@ bool LoadBIOS() FILE* f; u32 i; + memset(ARM9iBIOS, 0, 0x10000); + memset(ARM7iBIOS, 0, 0x10000); + f = Platform::OpenLocalFile("bios9i.bin", "rb"); if (!f) { printf("ARM9i BIOS not found\n"); for (i = 0; i < 16; i++) - ((u32*)NDS::ARM9BIOS)[i] = 0xE7FFDEFF; + ((u32*)ARM9iBIOS)[i] = 0xE7FFDEFF; } else { fseek(f, 0, SEEK_SET); - fread(NDS::ARM9BIOS, 0x10000, 1, f); + fread(ARM9iBIOS, 0x10000, 1, f); printf("ARM9i BIOS loaded\n"); fclose(f); @@ -183,22 +191,25 @@ bool LoadBIOS() printf("ARM7i BIOS not found\n"); for (i = 0; i < 16; i++) - ((u32*)NDS::ARM7BIOS)[i] = 0xE7FFDEFF; + ((u32*)ARM7iBIOS)[i] = 0xE7FFDEFF; } else { // TODO: check if the first 32 bytes are crapoed fseek(f, 0, SEEK_SET); - fread(NDS::ARM7BIOS, 0x10000, 1, f); + fread(ARM7iBIOS, 0x10000, 1, f); printf("ARM7i BIOS loaded\n"); fclose(f); } // herp - *(u32*)&NDS::ARM9BIOS[0] = 0xEAFFFFFE; - *(u32*)&NDS::ARM7BIOS[0] = 0xEAFFFFFE; + *(u32*)&ARM9iBIOS[0] = 0xEAFFFFFE; + *(u32*)&ARM7iBIOS[0] = 0xEAFFFFFE; + + // TODO!!!! + // hax the upper 32K out of the goddamn DSi return true; } @@ -582,6 +593,22 @@ void MapNWRAMRange(u32 cpu, u32 num, u32 val) } +void Set_SCFG_Clock9(u16 val) +{ + SCFG_Clock9 = val & 0x0187; + return; + + NDS::ARM9Timestamp >>= NDS::ARM9ClockShift; + + printf("CLOCK9=%04X\n", val); + SCFG_Clock9 = val & 0x0187; + + if (SCFG_Clock9 & (1<<0)) NDS::ARM9ClockShift = 2; + else NDS::ARM9ClockShift = 1; + NDS::ARM9Timestamp <<= NDS::ARM9ClockShift; + NDS::ARM9->UpdateRegionTimings(0x00000000, 0xFFFFFFFF); +} + void Set_SCFG_MC(u32 val) { u32 oldslotstatus = SCFG_MC & 0xC; @@ -600,6 +627,14 @@ void Set_SCFG_MC(u32 val) u8 ARM9Read8(u32 addr) { + if ((addr >= 0xFFFF0000) && (!(SCFG_BIOS & (1<<1)))) + { + if ((addr >= 0xFFFF8000) && (SCFG_BIOS & (1<<0))) + return 0xFF; + + return *(u8*)&ARM9iBIOS[addr & 0xFFFF]; + } + switch (addr & 0xFF000000) { case 0x03000000: @@ -629,6 +664,14 @@ u8 ARM9Read8(u32 addr) u16 ARM9Read16(u32 addr) { + if ((addr >= 0xFFFF0000) && (!(SCFG_BIOS & (1<<1)))) + { + if ((addr >= 0xFFFF8000) && (SCFG_BIOS & (1<<0))) + return 0xFFFF; + + return *(u16*)&ARM9iBIOS[addr & 0xFFFF]; + } + switch (addr & 0xFF000000) { case 0x03000000: @@ -658,6 +701,14 @@ u16 ARM9Read16(u32 addr) u32 ARM9Read32(u32 addr) { + if ((addr >= 0xFFFF0000) && (!(SCFG_BIOS & (1<<1)))) + { + if ((addr >= 0xFFFF8000) && (SCFG_BIOS & (1<<0))) + return 0xFFFFFFFF; + + return *(u32*)&ARM9iBIOS[addr & 0xFFFF]; + } + switch (addr & 0xFF000000) { case 0x03000000: @@ -790,14 +841,28 @@ bool ARM9GetMemRegion(u32 addr, bool write, NDS::MemRegion* region) { case 0x02000000: region->Mem = NDS::MainRAM; - region->Mask = MAIN_RAM_SIZE-1; + region->Mask = NDS::MainRAMMask; return true; } if ((addr & 0xFFFF0000) == 0xFFFF0000 && !write) { - region->Mem = NDS::ARM9BIOS; - region->Mask = 0xFFFF; + if (SCFG_BIOS & (1<<1)) + { + if (addr >= 0xFFFF1000) + { + region->Mem = NULL; + return false; + } + + region->Mem = NDS::ARM9BIOS; + region->Mask = 0xFFF; + } + else + { + region->Mem = ARM9iBIOS; + region->Mask = 0xFFFF; + } return true; } @@ -809,6 +874,18 @@ bool ARM9GetMemRegion(u32 addr, bool write, NDS::MemRegion* region) u8 ARM7Read8(u32 addr) { + if ((addr < 0x00010000) && (!(SCFG_BIOS & (1<<9)))) + { + if ((addr >= 0x00008000) && (SCFG_BIOS & (1<<8))) + return 0xFF; + if (NDS::ARM7->R[15] >= 0x00010000) + return 0xFF; + if (addr < NDS::ARM7BIOSProt && NDS::ARM7->R[15] >= NDS::ARM7BIOSProt) + return 0xFF; + + return *(u8*)&ARM7iBIOS[addr]; + } + switch (addr & 0xFF800000) { case 0x03000000: @@ -838,6 +915,18 @@ u8 ARM7Read8(u32 addr) u16 ARM7Read16(u32 addr) { + if ((addr < 0x00010000) && (!(SCFG_BIOS & (1<<9)))) + { + if ((addr >= 0x00008000) && (SCFG_BIOS & (1<<8))) + return 0xFFFF; + if (NDS::ARM7->R[15] >= 0x00010000) + return 0xFFFF; + if (addr < NDS::ARM7BIOSProt && NDS::ARM7->R[15] >= NDS::ARM7BIOSProt) + return 0xFFFF; + + return *(u16*)&ARM7iBIOS[addr]; + } + switch (addr & 0xFF800000) { case 0x03000000: @@ -867,6 +956,18 @@ u16 ARM7Read16(u32 addr) u32 ARM7Read32(u32 addr) { + if ((addr < 0x00010000) && (!(SCFG_BIOS & (1<<9)))) + { + if ((addr >= 0x00008000) && (SCFG_BIOS & (1<<8))) + return 0xFFFFFFFF; + if (NDS::ARM7->R[15] >= 0x00010000) + return 0xFFFFFFFF; + if (addr < NDS::ARM7BIOSProt && NDS::ARM7->R[15] >= NDS::ARM7BIOSProt) + return 0xFFFFFFFF; + + return *(u32*)&ARM7iBIOS[addr]; + } + switch (addr & 0xFF800000) { case 0x03000000: @@ -1000,7 +1101,7 @@ bool ARM7GetMemRegion(u32 addr, bool write, NDS::MemRegion* region) case 0x02000000: case 0x02800000: region->Mem = NDS::MainRAM; - region->Mask = MAIN_RAM_SIZE-1; + region->Mask = NDS::MainRAMMask; return true; } @@ -1040,7 +1141,7 @@ u8 ARM9IORead8(u32 addr) { switch (addr) { - case 0x04004000: return 1; + case 0x04004000: return SCFG_BIOS & 0xFF; CASE_READ8_32BIT(0x04004040, MBK[0][0]) CASE_READ8_32BIT(0x04004044, MBK[0][1]) @@ -1060,6 +1161,7 @@ u16 ARM9IORead16(u32 addr) { switch (addr) { + case 0x04004000: return SCFG_BIOS & 0xFF; case 0x04004004: return SCFG_Clock9; case 0x04004010: return SCFG_MC & 0xFFFF; @@ -1081,6 +1183,7 @@ u32 ARM9IORead32(u32 addr) { switch (addr) { + case 0x04004000: return SCFG_BIOS & 0xFF; case 0x04004008: return SCFG_EXT[0]; case 0x04004010: return SCFG_MC & 0xFFFF; @@ -1172,9 +1275,7 @@ void ARM9IOWrite16(u32 addr, u16 val) switch (addr) { case 0x04004004: - // TODO: actually change clock! - printf("CLOCK9=%04X\n", val); - SCFG_Clock9 = val & 0x0187; + Set_SCFG_Clock9(val); return; case 0x04004040: @@ -1232,6 +1333,20 @@ void ARM9IOWrite32(u32 addr, u32 val) SCFG_EXT[1] &= ~0x0000F080; SCFG_EXT[1] |= (val & 0x0000F080); printf("SCFG_EXT = %08X / %08X (val9 %08X)\n", SCFG_EXT[0], SCFG_EXT[1], val); + /*switch ((SCFG_EXT[0] >> 14) & 0x3) + { + case 0: + case 1: + NDS::MainRAMMask = 0x3FFFFF; + printf("RAM: 4MB\n"); + break; + case 2: + case 3: // TODO: debug console w/ 32MB? + NDS::MainRAMMask = 0xFFFFFF; + printf("RAM: 16MB\n"); + break; + }*/ + printf("from %08X, ARM7 %08X, %08X\n", NDS::GetPC(0), NDS::GetPC(1), NDS::ARM7->R[1]); return; case 0x04004040: @@ -1307,8 +1422,8 @@ u8 ARM7IORead8(u32 addr) { switch (addr) { - case 0x04004000: return 0x01; - case 0x04004001: return 0x01; + case 0x04004000: return SCFG_BIOS & 0xFF; + case 0x04004001: return SCFG_BIOS >> 8; CASE_READ8_32BIT(0x04004040, MBK[1][0]) CASE_READ8_32BIT(0x04004044, MBK[1][1]) @@ -1323,14 +1438,14 @@ u8 ARM7IORead8(u32 addr) case 0x04004500: return DSi_I2C::ReadData(); case 0x04004501: return DSi_I2C::Cnt; - case 0x04004D00: return ConsoleID & 0xFF; - case 0x04004D01: return (ConsoleID >> 8) & 0xFF; - case 0x04004D02: return (ConsoleID >> 16) & 0xFF; - case 0x04004D03: return (ConsoleID >> 24) & 0xFF; - case 0x04004D04: return (ConsoleID >> 32) & 0xFF; - case 0x04004D05: return (ConsoleID >> 40) & 0xFF; - case 0x04004D06: return (ConsoleID >> 48) & 0xFF; - case 0x04004D07: return ConsoleID >> 56; + case 0x04004D00: if (SCFG_BIOS & (1<<10)) return 0; return ConsoleID & 0xFF; + case 0x04004D01: if (SCFG_BIOS & (1<<10)) return 0; return (ConsoleID >> 8) & 0xFF; + case 0x04004D02: if (SCFG_BIOS & (1<<10)) return 0; return (ConsoleID >> 16) & 0xFF; + case 0x04004D03: if (SCFG_BIOS & (1<<10)) return 0; return (ConsoleID >> 24) & 0xFF; + case 0x04004D04: if (SCFG_BIOS & (1<<10)) return 0; return (ConsoleID >> 32) & 0xFF; + case 0x04004D05: if (SCFG_BIOS & (1<<10)) return 0; return (ConsoleID >> 40) & 0xFF; + case 0x04004D06: if (SCFG_BIOS & (1<<10)) return 0; return (ConsoleID >> 48) & 0xFF; + case 0x04004D07: if (SCFG_BIOS & (1<<10)) return 0; return ConsoleID >> 56; case 0x04004D08: return 0; } @@ -1344,6 +1459,7 @@ u16 ARM7IORead16(u32 addr) case 0x04000218: return NDS::IE2; case 0x0400021C: return NDS::IF2; + case 0x04004000: return SCFG_BIOS; case 0x04004004: return SCFG_Clock7; case 0x04004006: return 0; // JTAG register case 0x04004010: return SCFG_MC & 0xFFFF; @@ -1358,10 +1474,10 @@ u16 ARM7IORead16(u32 addr) CASE_READ16_32BIT(0x0400405C, MBK[1][7]) CASE_READ16_32BIT(0x04004060, MBK[1][8]) - case 0x04004D00: return ConsoleID & 0xFFFF; - case 0x04004D02: return (ConsoleID >> 16) & 0xFFFF; - case 0x04004D04: return (ConsoleID >> 32) & 0xFFFF; - case 0x04004D06: return ConsoleID >> 48; + case 0x04004D00: if (SCFG_BIOS & (1<<10)) return 0; return ConsoleID & 0xFFFF; + case 0x04004D02: if (SCFG_BIOS & (1<<10)) return 0; return (ConsoleID >> 16) & 0xFFFF; + case 0x04004D04: if (SCFG_BIOS & (1<<10)) return 0; return (ConsoleID >> 32) & 0xFFFF; + case 0x04004D06: if (SCFG_BIOS & (1<<10)) return 0; return ConsoleID >> 48; case 0x04004D08: return 0; } @@ -1384,6 +1500,7 @@ u32 ARM7IORead32(u32 addr) case 0x04000218: return NDS::IE2; case 0x0400021C: return NDS::IF2; + case 0x04004000: return SCFG_BIOS; case 0x04004008: return SCFG_EXT[1]; case 0x04004010: return SCFG_MC; @@ -1430,8 +1547,8 @@ u32 ARM7IORead32(u32 addr) case 0x04004400: return DSi_AES::ReadCnt(); case 0x0400440C: return DSi_AES::ReadOutputFIFO(); - case 0x04004D00: return ConsoleID & 0xFFFFFFFF; - case 0x04004D04: return ConsoleID >> 32; + case 0x04004D00: if (SCFG_BIOS & (1<<10)) return 0; return ConsoleID & 0xFFFFFFFF; + case 0x04004D04: if (SCFG_BIOS & (1<<10)) return 0; return ConsoleID >> 32; case 0x04004D08: return 0; } @@ -1453,6 +1570,13 @@ void ARM7IOWrite8(u32 addr, u8 val) { switch (addr) { + case 0x04004000: + SCFG_BIOS |= (val & 0x03); + return; + case 0x04004001: + SCFG_BIOS |= ((val & 0x07) << 8); + return; + case 0x04004500: DSi_I2C::WriteData(val); return; case 0x04004501: DSi_I2C::WriteCnt(val); return; } @@ -1467,10 +1591,12 @@ void ARM7IOWrite16(u32 addr, u16 val) case 0x04000218: NDS::IE2 = (val & 0x7FF7); NDS::UpdateIRQ(1); return; case 0x0400021C: NDS::IF2 &= ~(val & 0x7FF7); NDS::UpdateIRQ(1); return; + case 0x04004000: + SCFG_BIOS |= (val & 0x0703); + return; case 0x04004004: SCFG_Clock7 = val & 0x0187; return; - case 0x04004010: Set_SCFG_MC((SCFG_MC & 0xFFFF0000) | val); return; @@ -1497,6 +1623,9 @@ void ARM7IOWrite32(u32 addr, u32 val) case 0x04000218: NDS::IE2 = (val & 0x7FF7); NDS::UpdateIRQ(1); return; case 0x0400021C: NDS::IF2 &= ~(val & 0x7FF7); NDS::UpdateIRQ(1); return; + case 0x04004000: + SCFG_BIOS |= (val & 0x0703); + return; case 0x04004008: SCFG_EXT[0] &= ~0x03000000; SCFG_EXT[0] |= (val & 0x03000000); diff --git a/src/DSi.h b/src/DSi.h index b29cdb5..bd37550 100644 --- a/src/DSi.h +++ b/src/DSi.h @@ -25,6 +25,9 @@ namespace DSi { +extern u8 ARM9iBIOS[0x10000]; +extern u8 ARM7iBIOS[0x10000]; + extern u8 eMMC_CID[16]; extern u64 ConsoleID; diff --git a/src/NDS.cpp b/src/NDS.cpp index 42b5d9f..95265cf 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -86,10 +86,11 @@ u32 SchedListMask; u32 CPUStop; -u8 ARM9BIOS[0x10000]; -u8 ARM7BIOS[0x10000]; +u8 ARM9BIOS[0x1000]; +u8 ARM7BIOS[0x4000]; -u8 MainRAM[MAIN_RAM_SIZE]; +u8 MainRAM[0x1000000]; +u32 MainRAMMask; u8 SharedWRAM[0x8000]; u8 WRAMCnt; @@ -235,7 +236,11 @@ void SetARM9RegionTimings(u32 addrstart, u32 addrend, int buswidth, int nonseq, ARM9MemTimings[i][3] = S32; } - ARM9->UpdateRegionTimings(addrstart<<14, addrend<<14); + addrstart <<= 14; + addrend <<= 14; + if (!addrend) addrend = 0xFFFFFFFF; + + ARM9->UpdateRegionTimings(addrstart, addrend); } void SetARM7RegionTimings(u32 addrstart, u32 addrend, int buswidth, int nonseq, int seq) @@ -395,53 +400,58 @@ void Reset() LastSysClockCycles = 0; - memset(ARM9BIOS, 0, 0x10000); - memset(ARM7BIOS, 0, 0x10000); + memset(ARM9BIOS, 0, 0x1000); + memset(ARM7BIOS, 0, 0x4000); - if (true) + // DS BIOSes are always loaded, even in DSi mode + // we need them for DS-compatible mode + + f = Platform::OpenLocalFile("bios9.bin", "rb"); + if (!f) { - DSi::LoadBIOS(); - DSi::LoadNAND(); + printf("ARM9 BIOS not found\n"); - ARM9ClockShift = 2; + for (i = 0; i < 16; i++) + ((u32*)ARM9BIOS)[i] = 0xE7FFDEFF; } else { - f = Platform::OpenLocalFile("bios9.bin", "rb"); - if (!f) - { - printf("ARM9 BIOS not found\n"); + fseek(f, 0, SEEK_SET); + fread(ARM9BIOS, 0x1000, 1, f); - for (i = 0; i < 16; i++) - ((u32*)ARM9BIOS)[i] = 0xE7FFDEFF; - } - else - { - fseek(f, 0, SEEK_SET); - fread(ARM9BIOS, 0x1000, 1, f); + printf("ARM9 BIOS loaded\n"); + fclose(f); + } - printf("ARM9 BIOS loaded\n"); - fclose(f); - } + f = Platform::OpenLocalFile("bios7.bin", "rb"); + if (!f) + { + printf("ARM7 BIOS not found\n"); - f = Platform::OpenLocalFile("bios7.bin", "rb"); - if (!f) - { - printf("ARM7 BIOS not found\n"); + for (i = 0; i < 16; i++) + ((u32*)ARM7BIOS)[i] = 0xE7FFDEFF; + } + else + { + fseek(f, 0, SEEK_SET); + fread(ARM7BIOS, 0x4000, 1, f); - for (i = 0; i < 16; i++) - ((u32*)ARM7BIOS)[i] = 0xE7FFDEFF; - } - else - { - fseek(f, 0, SEEK_SET); - fread(ARM7BIOS, 0x4000, 1, f); + printf("ARM7 BIOS loaded\n"); + fclose(f); + } - printf("ARM7 BIOS loaded\n"); - fclose(f); - } + if (true) + { + DSi::LoadBIOS(); + DSi::LoadNAND(); + ARM9ClockShift = 2; + MainRAMMask = 0xFFFFFF; + } + else + { ARM9ClockShift = 1; + MainRAMMask = 0x3FFFFF; } ARM9Timestamp = 0; ARM9Target = 0; @@ -450,7 +460,7 @@ void Reset() InitTimings(); - memset(MainRAM, 0, MAIN_RAM_SIZE); + memset(MainRAM, 0, 0x1000000); memset(SharedWRAM, 0, 0x8000); memset(ARM7WRAM, 0, 0x10000); @@ -1608,36 +1618,36 @@ void debug(u32 param) fwrite(&val, 4, 1, shit); } fclose(shit);*/ - /*FILE* - shit = fopen("debug/dump9.bin", "wb"); + FILE* + /*shit = fopen("debug/dump9.bin", "wb"); for (u32 i = 0x02000000; i < 0x04000000; i+=4) { u32 val = DSi::ARM9Read32(i); fwrite(&val, 4, 1, shit); } - fclose(shit); - shit = fopen("debug/dump7.bin", "wb"); + fclose(shit);*/ + shit = fopen("debug/dump7_2.bin", "wb"); for (u32 i = 0x02000000; i < 0x04000000; i+=4) { u32 val = DSi::ARM7Read32(i); fwrite(&val, 4, 1, shit); } - fclose(shit);*/ + fclose(shit); } u8 ARM9Read8(u32 addr) { - if ((addr & 0xFFFF0000) == 0xFFFF0000) + if ((addr & 0xFFFFF000) == 0xFFFF0000) { - return *(u8*)&ARM9BIOS[addr & 0xFFFF]; + return *(u8*)&ARM9BIOS[addr & 0xFFF]; } switch (addr & 0xFF000000) { case 0x02000000: - return *(u8*)&MainRAM[addr & (MAIN_RAM_SIZE - 1)]; + return *(u8*)&MainRAM[addr & MainRAMMask]; case 0x03000000: if (SWRAM_ARM9) @@ -1690,15 +1700,15 @@ u8 ARM9Read8(u32 addr) u16 ARM9Read16(u32 addr) { - if ((addr & 0xFFFF0000) == 0xFFFF0000) + if ((addr & 0xFFFFF000) == 0xFFFF0000) { - return *(u16*)&ARM9BIOS[addr & 0xFFFF]; + return *(u16*)&ARM9BIOS[addr & 0xFFF]; } switch (addr & 0xFF000000) { case 0x02000000: - return *(u16*)&MainRAM[addr & (MAIN_RAM_SIZE - 1)]; + return *(u16*)&MainRAM[addr & MainRAMMask]; case 0x03000000: if (SWRAM_ARM9) @@ -1751,15 +1761,15 @@ u16 ARM9Read16(u32 addr) u32 ARM9Read32(u32 addr) { - if ((addr & 0xFFFF0000) == 0xFFFF0000) + if ((addr & 0xFFFFF000) == 0xFFFF0000) { - return *(u32*)&ARM9BIOS[addr & 0xFFFF]; + return *(u32*)&ARM9BIOS[addr & 0xFFF]; } switch (addr & 0xFF000000) { case 0x02000000: - return *(u32*)&MainRAM[addr & (MAIN_RAM_SIZE - 1)]; + return *(u32*)&MainRAM[addr & MainRAMMask]; case 0x03000000: if (SWRAM_ARM9) @@ -1815,7 +1825,7 @@ void ARM9Write8(u32 addr, u8 val) switch (addr & 0xFF000000) { case 0x02000000: - *(u8*)&MainRAM[addr & (MAIN_RAM_SIZE - 1)] = val; + *(u8*)&MainRAM[addr & MainRAMMask] = val; return; case 0x03000000: @@ -1844,7 +1854,7 @@ void ARM9Write16(u32 addr, u16 val) switch (addr & 0xFF000000) { case 0x02000000: - *(u16*)&MainRAM[addr & (MAIN_RAM_SIZE - 1)] = val; + *(u16*)&MainRAM[addr & MainRAMMask] = val; return; case 0x03000000: @@ -1887,7 +1897,7 @@ void ARM9Write32(u32 addr, u32 val) switch (addr & 0xFF000000) { case 0x02000000: - *(u32*)&MainRAM[addr & (MAIN_RAM_SIZE - 1)] = val; + *(u32*)&MainRAM[addr & MainRAMMask] = val; return ; case 0x03000000: @@ -1931,7 +1941,7 @@ bool ARM9GetMemRegion(u32 addr, bool write, MemRegion* region) { case 0x02000000: region->Mem = MainRAM; - region->Mask = MAIN_RAM_SIZE-1; + region->Mask = MainRAMMask; return true; case 0x03000000: @@ -1959,10 +1969,10 @@ bool ARM9GetMemRegion(u32 addr, bool write, MemRegion* region) u8 ARM7Read8(u32 addr) { - if (addr < 0x00010000) + if (addr < 0x00004000) { // TODO: check the boundary? is it 4000 or higher on regular DS? - if (ARM7->R[15] >= 0x00010000) + if (ARM7->R[15] >= 0x00004000) return 0xFF; if (addr < ARM7BIOSProt && ARM7->R[15] >= ARM7BIOSProt) return 0xFF; @@ -1974,7 +1984,7 @@ u8 ARM7Read8(u32 addr) { case 0x02000000: case 0x02800000: - return *(u8*)&MainRAM[addr & (MAIN_RAM_SIZE - 1)]; + return *(u8*)&MainRAM[addr & MainRAMMask]; case 0x03000000: if (SWRAM_ARM7) @@ -2016,9 +2026,9 @@ u8 ARM7Read8(u32 addr) u16 ARM7Read16(u32 addr) { - if (addr < 0x00010000) + if (addr < 0x00004000) { - if (ARM7->R[15] >= 0x00010000) + if (ARM7->R[15] >= 0x00004000) return 0xFFFF; if (addr < ARM7BIOSProt && ARM7->R[15] >= ARM7BIOSProt) return 0xFFFF; @@ -2030,7 +2040,7 @@ u16 ARM7Read16(u32 addr) { case 0x02000000: case 0x02800000: - return *(u16*)&MainRAM[addr & (MAIN_RAM_SIZE - 1)]; + return *(u16*)&MainRAM[addr & MainRAMMask]; case 0x03000000: if (SWRAM_ARM7) @@ -2079,9 +2089,9 @@ u16 ARM7Read16(u32 addr) u32 ARM7Read32(u32 addr) { - if (addr < 0x00010000) + if (addr < 0x00004000) { - if (ARM7->R[15] >= 0x00010000) + if (ARM7->R[15] >= 0x00004000) return 0xFFFFFFFF; if (addr < ARM7BIOSProt && ARM7->R[15] >= ARM7BIOSProt) return 0xFFFFFFFF; @@ -2093,7 +2103,7 @@ u32 ARM7Read32(u32 addr) { case 0x02000000: case 0x02800000: - return *(u32*)&MainRAM[addr & (MAIN_RAM_SIZE - 1)]; + return *(u32*)&MainRAM[addr & MainRAMMask]; case 0x03000000: if (SWRAM_ARM7) @@ -2146,7 +2156,7 @@ void ARM7Write8(u32 addr, u8 val) { case 0x02000000: case 0x02800000: - *(u8*)&MainRAM[addr & (MAIN_RAM_SIZE - 1)] = val; + *(u8*)&MainRAM[addr & MainRAMMask] = val; return; case 0x03000000: @@ -2184,7 +2194,7 @@ void ARM7Write16(u32 addr, u16 val) { case 0x02000000: case 0x02800000: - *(u16*)&MainRAM[addr & (MAIN_RAM_SIZE - 1)] = val; + *(u16*)&MainRAM[addr & MainRAMMask] = val; return; case 0x03000000: @@ -2230,7 +2240,7 @@ void ARM7Write32(u32 addr, u32 val) { case 0x02000000: case 0x02800000: - *(u32*)&MainRAM[addr & (MAIN_RAM_SIZE - 1)] = val; + *(u32*)&MainRAM[addr & MainRAMMask] = val; return; case 0x03000000: @@ -2278,7 +2288,7 @@ bool ARM7GetMemRegion(u32 addr, bool write, MemRegion* region) case 0x02000000: case 0x02800000: region->Mem = MainRAM; - region->Mask = MAIN_RAM_SIZE-1; + region->Mask = MainRAMMask; return true; case 0x03000000: @@ -2555,7 +2565,7 @@ u32 ARM9IORead32(u32 addr) case 0x04000130: return (KeyInput & 0xFFFF) | (KeyCnt << 16); - case 0x04000180: return IPCSync9; + case 0x04000180: /*printf("ARM9 read IPCSYNC: %04X\n", IPCSync9);*/ return IPCSync9; case 0x040001A0: return NDSCart::SPICnt | (NDSCart::ReadSPIData() << 16); case 0x040001A4: return NDSCart::ROMCnt; @@ -2764,6 +2774,7 @@ void ARM9IOWrite16(u32 addr, u16 val) return; case 0x04000180: + printf("ARM9 IPCSYNC = %04X\n", val); IPCSync7 &= 0xFFF0; IPCSync7 |= ((val & 0x0F00) >> 8); IPCSync9 &= 0xB0FF; @@ -3348,6 +3359,7 @@ void ARM7IOWrite16(u32 addr, u16 val) case 0x04000138: RTC::Write(val, false); return; case 0x04000180: + printf("ARM7 IPCSYNC = %04X\n", val); IPCSync9 &= 0xFFF0; IPCSync9 |= ((val & 0x0F00) >> 8); IPCSync7 &= 0xB0FF; diff --git a/src/NDS.h b/src/NDS.h index 309b16a..1b572ea 100644 --- a/src/NDS.h +++ b/src/NDS.h @@ -155,13 +155,12 @@ extern u16 ExMemCnt[2]; extern u8 ROMSeed0[2*8]; extern u8 ROMSeed1[2*8]; -extern u8 ARM9BIOS[0x10000]; -extern u8 ARM7BIOS[0x10000]; +extern u8 ARM9BIOS[0x1000]; +extern u8 ARM7BIOS[0x4000]; +extern u16 ARM7BIOSProt; -//#define MAIN_RAM_SIZE 0x400000 -#define MAIN_RAM_SIZE 0x1000000 - -extern u8 MainRAM[MAIN_RAM_SIZE]; +extern u8 MainRAM[0x1000000]; +extern u32 MainRAMMask; extern u32 KeyInput; -- cgit v1.2.3 From 62a605cd9223e63ebeacc6f1270f98447592ebe8 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 6 Aug 2019 02:27:54 +0200 Subject: lay base for camera shito --- melonDS.cbp | 2 + src/DSi_Camera.cpp | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/DSi_Camera.h | 55 +++++++++++++++++++++ src/DSi_I2C.cpp | 32 ++++++++++-- 4 files changed, 227 insertions(+), 5 deletions(-) create mode 100644 src/DSi_Camera.cpp create mode 100644 src/DSi_Camera.h (limited to 'src') diff --git a/melonDS.cbp b/melonDS.cbp index cc5357b..be1f30b 100644 --- a/melonDS.cbp +++ b/melonDS.cbp @@ -106,6 +106,8 @@ + + diff --git a/src/DSi_Camera.cpp b/src/DSi_Camera.cpp new file mode 100644 index 0000000..66d08cb --- /dev/null +++ b/src/DSi_Camera.cpp @@ -0,0 +1,143 @@ +/* + Copyright 2016-2019 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include +#include +#include "DSi_Camera.h" + + +DSi_Camera* DSi_Camera0; // 78 / facing outside +DSi_Camera* DSi_Camera1; // 7A / selfie cam + + +bool DSi_Camera::Init() +{ + DSi_Camera0 = new DSi_Camera(0); + DSi_Camera1 = new DSi_Camera(1); + + return true; +} + +void DSi_Camera::DeInit() +{ + delete DSi_Camera0; + delete DSi_Camera1; +} + +void DSi_Camera::Reset() +{ + DSi_Camera0->ResetCam(); + DSi_Camera1->ResetCam(); +} + + +DSi_Camera::DSi_Camera(u32 num) +{ + Num = num; +} + +DSi_Camera::~DSi_Camera() +{ + // +} + +void DSi_Camera::ResetCam() +{ + DataPos = 0; + RegAddr = 0; + RegData = 0; +} + + +void DSi_Camera::Start() +{ +} + +u8 DSi_Camera::Read(bool last) +{ + u8 ret; + + if (DataPos < 2) + { + printf("DSi_Camera: WHAT??\n"); + ret = 0; + } + else + { + if (DataPos & 0x1) + { + ret = RegData & 0xFF; + RegAddr += 2; // checkme + } + else + { + RegData = ReadReg(RegAddr); + ret = RegData >> 8; + } + } + + if (last) DataPos = 0; + else DataPos++; + + return ret; +} + +void DSi_Camera::Write(u8 val, bool last) +{ + if (DataPos < 2) + { + if (DataPos == 0) + RegAddr = val << 8; + else + RegAddr |= val; + + if (RegAddr & 0x1) printf("DSi_Camera: !! UNALIGNED REG ADDRESS %04X\n", RegAddr); + } + else + { + if (DataPos & 0x1) + { + RegData |= val; + WriteReg(RegAddr, RegData); + RegAddr += 2; // checkme + } + else + { + RegData = val << 8; + } + } + + if (last) DataPos = 0; + else DataPos++; +} + +u16 DSi_Camera::ReadReg(u16 addr) +{ + switch (addr) + { + case 0x301A: return 0x0002; // HAX + } + + printf("DSi_Camera%d: unknown read %04X\n", Num, addr); + return 0; +} + +void DSi_Camera::WriteReg(u16 addr, u16 val) +{ + printf("DSi_Camera%d: unknown write %04X %04X\n", Num, addr, val); +} diff --git a/src/DSi_Camera.h b/src/DSi_Camera.h new file mode 100644 index 0000000..eba35cb --- /dev/null +++ b/src/DSi_Camera.h @@ -0,0 +1,55 @@ +/* + Copyright 2016-2019 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef DSI_CAMERA_H +#define DSI_CAMERA_H + +#include "types.h" + +class DSi_Camera +{ +public: + static bool Init(); + static void DeInit(); + static void Reset(); + + DSi_Camera(u32 num); + ~DSi_Camera(); + + void ResetCam(); + + void Start(); + u8 Read(bool last); + void Write(u8 val, bool last); + +private: + u32 Num; + + u32 DataPos; + u32 RegAddr; + u16 RegData; + + u16 ReadReg(u16 addr); + void WriteReg(u16 addr, u16 val); +}; + + +extern DSi_Camera* DSi_Camera0; +extern DSi_Camera* DSi_Camera1; + +#endif // DSI_CAMERA_H diff --git a/src/DSi_I2C.cpp b/src/DSi_I2C.cpp index e88858b..907d0ef 100644 --- a/src/DSi_I2C.cpp +++ b/src/DSi_I2C.cpp @@ -20,6 +20,7 @@ #include #include "DSi.h" #include "DSi_I2C.h" +#include "DSi_Camera.h" namespace DSi_BPTWL @@ -131,6 +132,7 @@ u32 Device; bool Init() { if (!DSi_BPTWL::Init()) return false; + if (!DSi_Camera::Init()) return false; return true; } @@ -138,6 +140,7 @@ bool Init() void DeInit() { DSi_BPTWL::DeInit(); + DSi_Camera::DeInit(); } void Reset() @@ -148,6 +151,7 @@ void Reset() Device = -1; DSi_BPTWL::Reset(); + DSi_Camera::Reset(); } void WriteCnt(u8 val) @@ -171,37 +175,55 @@ void WriteCnt(u8 val) switch (Device) { case 0x4A: Data = DSi_BPTWL::Read(islast); break; - default: Data = 0; break; + case 0x78: Data = DSi_Camera0->Read(islast); break; + case 0x7A: Data = DSi_Camera1->Read(islast); break; + default: + printf("I2C: read on unknown device %02X, cnt=%02X, data=%02X, last=%d\n", Device, val, 0, islast); + Data = 0; + break; } - //printf("I2C read, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); + printf("I2C read, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); } else { // write val &= 0xE7; + bool ack = true; if (val & (1<<1)) { Device = Data & 0xFE; - //printf("I2C: %s start, device=%02X\n", (Data&0x01)?"read":"write", Device); + printf("I2C: %s start, device=%02X\n", (Data&0x01)?"read":"write", Device); switch (Device) { case 0x4A: DSi_BPTWL::Start(); break; + case 0x78: DSi_Camera0->Start(); break; + case 0x7A: DSi_Camera1->Start(); break; + default: + printf("I2C: %s start on unknown device %02X\n", (Data&0x01)?"read":"write", Device); + ack = false; + break; } } else { - //printf("I2C write, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); + printf("I2C write, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); switch (Device) { case 0x4A: DSi_BPTWL::Write(Data, islast); break; + case 0x78: DSi_Camera0->Write(Data, islast); break; + case 0x7A: DSi_Camera1->Write(Data, islast); break; + default: + printf("I2C: write on unknown device %02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); + ack = false; + break; } } - val |= (1<<4); + if (ack) val |= (1<<4); } val &= 0x7F; -- cgit v1.2.3 From 28a9c7d9d1c44066e91664101362eab69ab12f4d Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 6 Aug 2019 13:06:14 +0200 Subject: camera: enough stub to pass firmware init --- src/DSi_Camera.cpp | 25 ++++++++++++++++++++++++- src/DSi_Camera.h | 3 +++ src/DSi_I2C.cpp | 14 +++++++------- 3 files changed, 34 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/DSi_Camera.cpp b/src/DSi_Camera.cpp index 66d08cb..45061b2 100644 --- a/src/DSi_Camera.cpp +++ b/src/DSi_Camera.cpp @@ -61,6 +61,9 @@ void DSi_Camera::ResetCam() DataPos = 0; RegAddr = 0; RegData = 0; + + PLLCnt = 0; + StandbyCnt = 0x4029; // checkme } @@ -130,7 +133,11 @@ u16 DSi_Camera::ReadReg(u16 addr) { switch (addr) { - case 0x301A: return 0x0002; // HAX + case 0x0000: return 0x2280; // chip ID + case 0x0014: return PLLCnt; + case 0x0018: return StandbyCnt; + + case 0x301A: return ((~StandbyCnt) & 0x4000) >> 12; } printf("DSi_Camera%d: unknown read %04X\n", Num, addr); @@ -139,5 +146,21 @@ u16 DSi_Camera::ReadReg(u16 addr) void DSi_Camera::WriteReg(u16 addr, u16 val) { + switch (addr) + { + case 0x0014: + // shouldn't be instant either? + val &= 0x7FFF; + val |= ((val & 0x0002) << 14); + PLLCnt = val; + return; + case 0x0018: + // TODO: this shouldn't be instant, but uh + val &= 0x003F; + val |= ((val & 0x0001) << 14); + StandbyCnt = val; + return; + } + printf("DSi_Camera%d: unknown write %04X %04X\n", Num, addr, val); } diff --git a/src/DSi_Camera.h b/src/DSi_Camera.h index eba35cb..78629b5 100644 --- a/src/DSi_Camera.h +++ b/src/DSi_Camera.h @@ -46,6 +46,9 @@ private: u16 ReadReg(u16 addr); void WriteReg(u16 addr, u16 val); + + u16 PLLCnt; + u16 StandbyCnt; }; diff --git a/src/DSi_I2C.cpp b/src/DSi_I2C.cpp index 907d0ef..ffb724f 100644 --- a/src/DSi_I2C.cpp +++ b/src/DSi_I2C.cpp @@ -156,7 +156,7 @@ void Reset() void WriteCnt(u8 val) { - //printf("I2C: write CNT %02X\n", val); + //printf("I2C: write CNT %02X, %08X\n", val, NDS::GetPC(1)); // TODO: check ACK flag // TODO: transfer delay @@ -179,11 +179,11 @@ void WriteCnt(u8 val) case 0x7A: Data = DSi_Camera1->Read(islast); break; default: printf("I2C: read on unknown device %02X, cnt=%02X, data=%02X, last=%d\n", Device, val, 0, islast); - Data = 0; + Data = 0xFF; break; } - printf("I2C read, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); + //printf("I2C read, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); } else { @@ -194,7 +194,7 @@ void WriteCnt(u8 val) if (val & (1<<1)) { Device = Data & 0xFE; - printf("I2C: %s start, device=%02X\n", (Data&0x01)?"read":"write", Device); + //printf("I2C: %s start, device=%02X\n", (Data&0x01)?"read":"write", Device); switch (Device) { @@ -203,13 +203,13 @@ void WriteCnt(u8 val) case 0x7A: DSi_Camera1->Start(); break; default: printf("I2C: %s start on unknown device %02X\n", (Data&0x01)?"read":"write", Device); - ack = false; + //ack = false; break; } } else { - printf("I2C write, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); + //printf("I2C write, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); switch (Device) { @@ -218,7 +218,7 @@ void WriteCnt(u8 val) case 0x7A: DSi_Camera1->Write(Data, islast); break; default: printf("I2C: write on unknown device %02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); - ack = false; + //ack = false; break; } } -- cgit v1.2.3 From 9c1ea0e539d797720ec5b0eaf999577ee5747eef Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 6 Aug 2019 13:31:27 +0200 Subject: guess after all we shouldn't send ACKs for nonexistant I2C devices --- src/DSi_I2C.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/DSi_I2C.cpp b/src/DSi_I2C.cpp index ffb724f..5ced51e 100644 --- a/src/DSi_I2C.cpp +++ b/src/DSi_I2C.cpp @@ -203,7 +203,7 @@ void WriteCnt(u8 val) case 0x7A: DSi_Camera1->Start(); break; default: printf("I2C: %s start on unknown device %02X\n", (Data&0x01)?"read":"write", Device); - //ack = false; + ack = false; break; } } @@ -218,7 +218,7 @@ void WriteCnt(u8 val) case 0x7A: DSi_Camera1->Write(Data, islast); break; default: printf("I2C: write on unknown device %02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); - //ack = false; + ack = false; break; } } -- cgit v1.2.3 From dcda848cdfd94aaa5549841d8ba3cb54370f9cbc Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 7 Aug 2019 12:57:12 +0200 Subject: * base for potentially re-encrypting modcrypt, doesn't seem to be required? but can also serve to decrypt it * revise SD IRQ behavior (fixing potential hang when loading DS games) --- src/DSi_AES.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/DSi_AES.h | 3 +++ src/DSi_SD.cpp | 29 ++++++++++++++++++++++----- src/DSi_SD.h | 1 + src/NDSCart.cpp | 23 ++++++++++++++++++++++ 5 files changed, 111 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/DSi_AES.cpp b/src/DSi_AES.cpp index 4aa97bc..e49ebf5 100644 --- a/src/DSi_AES.cpp +++ b/src/DSi_AES.cpp @@ -398,7 +398,7 @@ void Update() { Ctx.Iv[13] = 0x00; Ctx.Iv[14] = 0x00; - Ctx.Iv[15] = 0x00;_printhex(Ctx.Iv, 16); + Ctx.Iv[15] = 0x00; AES_CTR_xcrypt_buffer(&Ctx, CurMAC, 16); //printf("FINAL MAC: "); _printhexR(CurMAC, 16); @@ -505,4 +505,63 @@ void WriteKeyY(u32 slot, u32 offset, u32 val, u32 mask) } } + +// utility + +void GetModcryptKey(u8* romheader, u8* key) +{ + if ((romheader[0x01C] & 0x04) || (romheader[0x1BF] & 0x80)) + { + // dev key + memcpy(key, &romheader[0x000], 16); + return; + } + + u8 oldkeys[16*3]; + memcpy(&oldkeys[16*0], KeyX[0], 16); + memcpy(&oldkeys[16*1], KeyY[0], 16); + memcpy(&oldkeys[16*2], KeyNormal[0], 16); + + KeyX[0][8] = romheader[0x00C]; + KeyX[0][9] = romheader[0x00D]; + KeyX[0][10] = romheader[0x00E]; + KeyX[0][11] = romheader[0x00F]; + KeyX[0][12] = romheader[0x00F]; + KeyX[0][13] = romheader[0x00E]; + KeyX[0][14] = romheader[0x00D]; + KeyX[0][15] = romheader[0x00C]; + + memcpy(KeyY[0], &romheader[0x350], 16); + + DeriveNormalKey(0); + memcpy(key, KeyNormal[0], 16); + + memcpy(KeyX[0], &oldkeys[16*0], 16); + memcpy(KeyY[0], &oldkeys[16*1], 16); + memcpy(KeyNormal[0], &oldkeys[16*2], 16); +} + +void ApplyModcrypt(u8* data, u32 len, u8* key, u8* iv) +{ + u8 key_rev[16], iv_rev[16]; + u8 data_rev[16]; + u8 oldkeys[16*2]; + memcpy(&oldkeys[16*0], Ctx.RoundKey, 16); + memcpy(&oldkeys[16*1], Ctx.Iv, 16); + + Swap16(key_rev, key); + Swap16(iv_rev, iv); + AES_init_ctx_iv(&Ctx, key_rev, iv_rev); + + for (u32 i = 0; i < len; i += 16) + { + Swap16(data_rev, &data[i]); + AES_CTR_xcrypt_buffer(&Ctx, data_rev, 16); + Swap16(&data[i], data_rev); + } + + memcpy(Ctx.RoundKey, &oldkeys[16*0], 16); + memcpy(Ctx.Iv, &oldkeys[16*1], 16); +} + } diff --git a/src/DSi_AES.h b/src/DSi_AES.h index 5e726cd..354c4a7 100644 --- a/src/DSi_AES.h +++ b/src/DSi_AES.h @@ -46,6 +46,9 @@ void WriteKeyNormal(u32 slot, u32 offset, u32 val, u32 mask); void WriteKeyX(u32 slot, u32 offset, u32 val, u32 mask); void WriteKeyY(u32 slot, u32 offset, u32 val, u32 mask); +void GetModcryptKey(u8* romheader, u8* key); +void ApplyModcrypt(u8* data, u32 len, u8* key, u8* iv); + } #endif // DSI_AES_H diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index 44d8d62..796466d 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -149,6 +149,15 @@ void DSi_SDHost::SetIRQ(u32 irq) if (irq == 24 || irq == 25) UpdateData32IRQ(); } +void DSi_SDHost::UpdateIRQ(u32 oldmask) +{ + u32 oldflags = IRQStatus & ~oldmask; + u32 newflags = IRQStatus & ~IRQMask; + + if ((oldflags == 0) && (newflags != 0)) + NDS::SetIRQ2(Num ? NDS::IRQ2_DSi_SDIO : NDS::IRQ2_DSi_SDMMC); +} + void DSi_SDHost::SetCardIRQ() { if (!(CardIRQCtl & (1<<0))) return; @@ -424,7 +433,7 @@ u32 DSi_SDHost::ReadFIFO32() return ret; } -int morp = 0; + void DSi_SDHost::Write(u32 addr, u16 val) { //if(Num)printf("SDIO WRITE %08X %04X %08X\n", addr, val, NDS::GetPC(1)); @@ -464,11 +473,21 @@ void DSi_SDHost::Write(u32 addr, u16 val) case 0x01C: IRQStatus &= (val | 0xFFFF0000); return; case 0x01E: IRQStatus &= ((val << 16) | 0xFFFF); return; - case 0x020: IRQMask = (IRQMask & 0x8B7F0000) | (val & 0x031D); return; + case 0x020: + { + u32 oldmask = IRQMask; + IRQMask = (IRQMask & 0x8B7F0000) | (val & 0x031D); + UpdateIRQ(oldmask); + } + return; case 0x022: - IRQMask = (IRQMask & 0x0000031D) | ((val & 0x8B7F) << 16); - if (!DataFIFO[CurFIFO]->IsEmpty()) SetIRQ(24); // checkme - if (DataFIFO[CurFIFO]->IsEmpty()) SetIRQ(25); // checkme + { + u32 oldmask = IRQMask; + IRQMask = (IRQMask & 0x0000031D) | ((val & 0x8B7F) << 16); + UpdateIRQ(oldmask); + if (!DataFIFO[CurFIFO]->IsEmpty()) SetIRQ(24); // checkme + if (DataFIFO[CurFIFO]->IsEmpty()) SetIRQ(25); // checkme + } return; case 0x024: SDClock = val & 0x03FF; return; diff --git a/src/DSi_SD.h b/src/DSi_SD.h index 149b72a..f4ca26c 100644 --- a/src/DSi_SD.h +++ b/src/DSi_SD.h @@ -84,6 +84,7 @@ private: void UpdateData32IRQ(); void ClearIRQ(u32 irq); void SetIRQ(u32 irq); + void UpdateIRQ(u32 oldmask); }; diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index c3765d8..65cf8ae 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -23,6 +23,7 @@ #include "NDSCart.h" #include "ARM.h" #include "CRC32.h" +#include "DSi_AES.h" #include "Platform.h" @@ -599,6 +600,15 @@ void Key2_Encrypt(u8* data, u32 len) } +void ApplyModcrypt(u32 addr, u32 len, u8* iv) +{return; + u8 key[16]; + + DSi_AES::GetModcryptKey(&CartROM[0], key); + DSi_AES::ApplyModcrypt(&CartROM[addr], len, key, iv); +} + + bool Init() { if (!NDSCart_SRAM::Init()) return false; @@ -980,6 +990,19 @@ bool LoadROM(const char* path, const char* sram, bool direct) CartIsHomebrew = true; } + // re-encrypt modcrypt areas if needed + // TODO: somehow detect whether those are already encrypted + if (true) + { + u32 mod1 = *(u32*)&CartROM[0x220]; + u32 mod2 = *(u32*)&CartROM[0x228]; + + printf("Re-encrypting modcrypt areas: %08X, %08X\n", mod1, mod2); + + if (mod1) ApplyModcrypt(mod1, *(u32*)&CartROM[0x224], &CartROM[0x300]); + if (mod2) ApplyModcrypt(mod2, *(u32*)&CartROM[0x22C], &CartROM[0x314]); + } + // save printf("Save file: %s\n", sram); -- cgit v1.2.3 From 118b3b0f241973a1c667b03ce0d22d64d6b20d31 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 15 Oct 2019 23:30:01 +0200 Subject: don't auto-patch firmware touchscreen coordinates, atleast until we find out whether that causes problems in DSi mode --- src/SPI.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/SPI.cpp b/src/SPI.cpp index e21ad0c..81b0c04 100644 --- a/src/SPI.cpp +++ b/src/SPI.cpp @@ -152,6 +152,7 @@ void Reset() UserSettings = userdata; // fix touchscreen coords + #if 0 *(u16*)&Firmware[userdata+0x58] = 0; *(u16*)&Firmware[userdata+0x5A] = 0; Firmware[userdata+0x5C] = 0; @@ -174,12 +175,12 @@ void Reset() Firmware[0x39] = rand()&0xFF; Firmware[0x3A] = rand()&0xFF; Firmware[0x3B] = rand()&0xFF; - +#endif printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", Firmware[0x36], Firmware[0x37], Firmware[0x38], Firmware[0x39], Firmware[0x3A], Firmware[0x3B]); - *(u16*)&Firmware[0x2A] = CRC16(&Firmware[0x2C], *(u16*)&Firmware[0x2C], 0x0000); + //*(u16*)&Firmware[0x2A] = CRC16(&Firmware[0x2C], *(u16*)&Firmware[0x2C], 0x0000); // verify shit printf("FW: WIFI CRC16 = %s\n", VerifyCRC16(0x0000, 0x2C, *(u16*)&Firmware[0x2C], 0x2A)?"GOOD":"BAD"); -- cgit v1.2.3 From db6187a9532e7e3159f6191f6bbae1faac40c32e Mon Sep 17 00:00:00 2001 From: StapleButter Date: Wed, 16 Oct 2019 01:37:44 +0200 Subject: add DSi shit to cmakelists --- src/CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a1110f1..a4b1c6e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,6 +10,14 @@ add_library(core STATIC CP15.cpp CRC32.cpp DMA.cpp + DSi.cpp + DSi_AES.cpp + DSi_Camera.cpp + DSi_I2C.cpp + DSi_NDMA.cpp + DSi_NWifi.cpp + DSi_SD.cpp + DSi_SPI_TSC.cpp GPU.cpp GPU2D.cpp GPU3D.cpp @@ -24,6 +32,8 @@ add_library(core STATIC SPU.cpp Wifi.cpp WifiAP.cpp + + tiny-AES-c/aes.c ) if (WIN32) -- cgit v1.2.3 From e82364f010f6ad4e4883c241a05a4aac10cd75d6 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 19 Oct 2019 16:03:59 +0200 Subject: * some fixes to SD controller support, make it clear that there is no SD inserted, makes Flipnote work somewhat better * immediately clear AES busy flag when the block count is zero (occurs when loading DSi cart games) * implement NDMA start modes that have an old-DMA equivalent (except for GXFIFO mode) now it boots DSi carts! --- src/DSi.cpp | 16 +++++++++- src/DSi.h | 1 + src/DSi_AES.cpp | 90 +++++++++++++++++++++++++------------------------------- src/DSi_NDMA.cpp | 6 ++-- src/DSi_SD.cpp | 62 +++++++++++++++++++++++++++++++++----- src/NDS.cpp | 42 ++++++++++++++++++++++++++ src/NDSCart.cpp | 4 +-- 7 files changed, 159 insertions(+), 62 deletions(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index 9f07fa1..ef4e6da 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -411,6 +411,16 @@ void StallNDMAs() // TODO } +bool NDMAsInMode(u32 cpu, u32 mode) +{ + cpu <<= 2; + if (NDMAs[cpu+0]->IsInMode(mode)) return true; + if (NDMAs[cpu+1]->IsInMode(mode)) return true; + if (NDMAs[cpu+2]->IsInMode(mode)) return true; + if (NDMAs[cpu+3]->IsInMode(mode)) return true; + return false; +} + bool NDMAsRunning(u32 cpu) { cpu <<= 2; @@ -1156,7 +1166,7 @@ u8 ARM9IORead8(u32 addr) return NDS::ARM9IORead8(addr); } - +//u16 dicks = 0; u16 ARM9IORead16(u32 addr) { switch (addr) @@ -1174,6 +1184,8 @@ u16 ARM9IORead16(u32 addr) CASE_READ16_32BIT(0x04004058, MBK[0][6]) CASE_READ16_32BIT(0x0400405C, MBK[0][7]) CASE_READ16_32BIT(0x04004060, MBK[0][8]) + + //case 0x04004202: return dicks & 0xEF1F; } return NDS::ARM9IORead16(addr); @@ -1318,6 +1330,8 @@ void ARM9IOWrite16(u32 addr, u16 val) MapNWRAM_C(6, val & 0xFF); MapNWRAM_C(7, val >> 8); return; + + //case 0x04004202: dicks = val & 0xEF3F; return; } return NDS::ARM9IOWrite16(addr, val); diff --git a/src/DSi.h b/src/DSi.h index bd37550..5697237 100644 --- a/src/DSi.h +++ b/src/DSi.h @@ -47,6 +47,7 @@ bool LoadNAND(); void RunNDMAs(u32 cpu); void StallNDMAs(); +bool NDMAsInMode(u32 cpu, u32 mode); bool NDMAsRunning(u32 cpu); void CheckNDMAs(u32 cpu, u32 mode); void StopNDMAs(u32 cpu, u32 mode); diff --git a/src/DSi_AES.cpp b/src/DSi_AES.cpp index e49ebf5..7aae8f3 100644 --- a/src/DSi_AES.cpp +++ b/src/DSi_AES.cpp @@ -129,28 +129,8 @@ void Reset() memset(CurKey, 0, sizeof(CurKey)); memset(CurMAC, 0, sizeof(CurMAC)); - // initialize keys, as per GBAtek - -#if 0 - // slot 0: modcrypt - *(u32*)&KeyX[0][0] = 0x746E694E; - *(u32*)&KeyX[0][4] = 0x6F646E65; - - // slot 1: 'Tad'/dev.kp - *(u32*)&KeyX[1][0] = 0x4E00004A; - *(u32*)&KeyX[1][4] = 0x4A00004E; - *(u32*)&KeyX[1][8] = (u32)(DSi::ConsoleID >> 32) ^ 0xC80C4B72; - *(u32*)&KeyX[1][12] = (u32)DSi::ConsoleID; - - // slot 3: console-unique eMMC crypto - *(u32*)&KeyX[3][0] = (u32)DSi::ConsoleID; - *(u32*)&KeyX[3][4] = (u32)DSi::ConsoleID ^ 0x24EE6906; - *(u32*)&KeyX[3][8] = (u32)(DSi::ConsoleID >> 32) ^ 0xE65B601D; - *(u32*)&KeyX[3][12] = (u32)(DSi::ConsoleID >> 32); - *(u32*)&KeyY[3][0] = 0x0AB9DC76; - *(u32*)&KeyY[3][4] = 0xBD4DC4D3; - *(u32*)&KeyY[3][8] = 0x202DDD1D; -#endif + // initialize keys + FILE* f = Platform::OpenLocalFile("aeskeys.bin", "rb"); if (f) { @@ -233,12 +213,12 @@ u32 ReadCnt() ret |= InputFIFO->Level(); ret |= (OutputFIFO->Level() << 5); - +//printf("READ AES CNT: %08X, LEVELS: IN=%d OUT=%d\n", ret, InputFIFO->Level(), OutputFIFO->Level()); return ret; } void WriteCnt(u32 val) -{ +{printf("AES CNT = %08X\n", val); u32 oldcnt = Cnt; Cnt = val & 0xFC1FF000; @@ -267,41 +247,51 @@ void WriteCnt(u32 val) // transfer start (checkme) RemBlocks = BlkCnt >> 16; - u8 key[16]; - u8 iv[16]; + if (RemBlocks > 0) + { + u8 key[16]; + u8 iv[16]; - Swap16(key, CurKey); - Swap16(iv, IV); + Swap16(key, CurKey); + Swap16(iv, IV); - if (AESMode < 2) - { - if (BlkCnt & 0xFFFF) printf("AES: CCM EXTRA LEN TODO\n"); + if (AESMode < 2) + { + if (BlkCnt & 0xFFFF) printf("AES: CCM EXTRA LEN TODO\n"); - u32 maclen = (val >> 16) & 0x7; - if (maclen < 1) maclen = 1; + u32 maclen = (val >> 16) & 0x7; + if (maclen < 1) maclen = 1; - iv[0] = 0x02; - for (int i = 0; i < 12; i++) iv[1+i] = iv[4+i]; - iv[13] = 0x00; - iv[14] = 0x00; - iv[15] = 0x01; + iv[0] = 0x02; + for (int i = 0; i < 12; i++) iv[1+i] = iv[4+i]; + iv[13] = 0x00; + iv[14] = 0x00; + iv[15] = 0x01; - AES_init_ctx_iv(&Ctx, key, iv); + AES_init_ctx_iv(&Ctx, key, iv); - iv[0] |= (maclen << 3) | ((BlkCnt & 0xFFFF) ? (1<<6) : 0); - iv[13] = RemBlocks >> 12; - iv[14] = RemBlocks >> 4; - iv[15] = RemBlocks << 4; + iv[0] |= (maclen << 3) | ((BlkCnt & 0xFFFF) ? (1<<6) : 0); + iv[13] = RemBlocks >> 12; + iv[14] = RemBlocks >> 4; + iv[15] = RemBlocks << 4; - memcpy(CurMAC, iv, 16); - AES_ECB_encrypt(&Ctx, CurMAC); + memcpy(CurMAC, iv, 16); + AES_ECB_encrypt(&Ctx, CurMAC); + } + else + { + AES_init_ctx_iv(&Ctx, key, iv); + } + + DSi::CheckNDMAs(1, 0x2A); } else { - AES_init_ctx_iv(&Ctx, key, iv); - } + // no blocks to process? oh well. mark it finished + // CHECKME: does this trigger any IRQ or shit? - DSi::CheckNDMAs(1, 0x2A); + Cnt &= ~(1<<31); + } } printf("AES CNT: %08X / mode=%d key=%d inDMA=%d outDMA=%d blocks=%d\n", @@ -309,7 +299,7 @@ void WriteCnt(u32 val) } void WriteBlkCnt(u32 val) -{ +{printf("AES BLOCK CNT %08X / %d\n", val, val>>16); BlkCnt = val; } @@ -415,7 +405,7 @@ void Update() // CHECKME Cnt &= ~(1<<21); } - +printf("AES: FINISHED\n"); Cnt &= ~(1<<31); if (Cnt & (1<<30)) NDS::SetIRQ2(NDS::IRQ2_DSi_AES); DSi::StopNDMAs(1, 0x2A); diff --git a/src/DSi_NDMA.cpp b/src/DSi_NDMA.cpp index e7fc7ab..19c72b6 100644 --- a/src/DSi_NDMA.cpp +++ b/src/DSi_NDMA.cpp @@ -101,8 +101,10 @@ void DSi_NDMA::WriteCnt(u32 val) Start(); if (StartMode != 0x10 && StartMode != 0x30 && - StartMode != 0x2A && StartMode != 0x2B) - printf("UNIMPLEMENTED ARM%d NDMA%d START MODE %02X, %08X->%08X\n", CPU?7:9, Num, StartMode, SrcAddr, DstAddr); + StartMode != 0x04 && StartMode != 0x06 && StartMode != 0x07 && StartMode != 0x08 && StartMode != 0x09 && + StartMode != 0x24 && StartMode != 0x26 && StartMode != 0x28 && StartMode != 0x29 && StartMode != 0x2A && StartMode != 0x2B) + printf("UNIMPLEMENTED ARM%d NDMA%d START MODE %02X, %08X->%08X LEN=%d BLK=%d CNT=%08X\n", + CPU?7:9, Num, StartMode, SrcAddr, DstAddr, TotalLength, BlockLength, Cnt); } } diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index 796466d..a45a8ce 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -91,10 +91,16 @@ void DSi_SDHost::Reset() if (Num == 0) { + // TODO: eventually pull from host filesystem + /*DSi_MMCStorage* sd = new DSi_MMCStorage(this, false, "sd.bin"); + u8 sd_cid[16] = {0xBD, 0x12, 0x34, 0x56, 0x78, 0x03, 0x4D, 0x30, 0x30, 0x46, 0x50, 0x41, 0x00, 0x00, 0x15, 0x00}; + sd->SetCID(sd_cid);*/ + DSi_MMCStorage* sd = NULL; + DSi_MMCStorage* mmc = new DSi_MMCStorage(this, true, "nand.bin"); mmc->SetCID(DSi::eMMC_CID); - // TODO: port 0 (SD) + Ports[0] = sd; Ports[1] = mmc; } else @@ -196,6 +202,14 @@ void DSi_SDHost::FinishSend(u32 param) host->ClearIRQ(25); host->SetIRQ(24); //if (param & 0x2) host->SetIRQ(2); + + // TODO: this is an assumption and should eventually be confirmed + // Flipnote sets DMA blocklen to 128 words and totallen to 1024 words + // so, presumably, DMA should trigger when the FIFO is full + // 'full' being when it reaches whatever BlockLen16 is set to, or the + // other blocklen register, or when it is actually full (but that makes + // less sense) + DSi::CheckNDMAs(1, host->Num ? 0x29 : 0x28); } u32 DSi_SDHost::SendData(u8* data, u32 len) @@ -286,7 +300,7 @@ u32 DSi_SDHost::GetTransferrableLen(u32 len) u16 DSi_SDHost::Read(u32 addr) { - //if(Num)printf("SDIO READ %08X %08X\n", addr, NDS::GetPC(1)); + if(!Num)printf("SDMMC READ %08X %08X\n", addr, NDS::GetPC(1)); switch (addr & 0x1FF) { @@ -307,7 +321,24 @@ u16 DSi_SDHost::Read(u32 addr) case 0x018: return ResponseBuffer[6]; case 0x01A: return ResponseBuffer[7]; - case 0x01C: return (IRQStatus & 0x031D) | 0x0030; // TODO: adjust insert flags for SD card + case 0x01C: + { + u16 ret = (IRQStatus & 0x031D); + + if (!Num) + { + if (Ports[0]) // basic check of whether the SD card is inserted + ret |= 0x0030; + else + ret |= 0x0008; + } + else + { + // SDIO wifi is always inserted, I guess + ret |= 0x0030; + } + return ret; + } case 0x01E: return ((IRQStatus >> 16) & 0x8B7F); case 0x020: return IRQMask & 0x031D; case 0x022: return (IRQMask >> 16) & 0x8B7F; @@ -436,7 +467,7 @@ u32 DSi_SDHost::ReadFIFO32() void DSi_SDHost::Write(u32 addr, u16 val) { - //if(Num)printf("SDIO WRITE %08X %04X %08X\n", addr, val, NDS::GetPC(1)); + if(!Num)printf("SDMMC WRITE %08X %04X %08X\n", addr, val, NDS::GetPC(1)); switch (addr & 0x1FF) { @@ -464,7 +495,7 @@ void DSi_SDHost::Write(u32 addr, u16 val) } return; - case 0x002: PortSelect = val; printf("%s: PORT SELECT %04X\n", SD_DESC, val); return; + case 0x002: PortSelect = (val & 0x040F) | (PortSelect & 0x0300); printf("%s: PORT SELECT %04X (%04X)\n", SD_DESC, val, PortSelect); return; case 0x004: Param = (Param & 0xFFFF0000) | val; return; case 0x006: Param = (Param & 0x0000FFFF) | (val << 16); return; @@ -504,7 +535,7 @@ void DSi_SDHost::Write(u32 addr, u16 val) if (DataFIFO[f]->IsFull()) { // TODO - printf("!!!! %s FIFO FULL\n", SD_DESC); + printf("!!!! %s FIFO (16) FULL\n", SD_DESC); return; } @@ -582,12 +613,14 @@ void DSi_SDHost::WriteFIFO32(u32 val) { if (DataMode != 1) return; + printf("%s: WRITE FIFO32: LEVEL=%d/%d\n", SD_DESC, DataFIFO[CurFIFO]->Level(), (BlockLen16>>1)); + DSi_SDDevice* dev = Ports[PortSelect & 0x1]; u32 f = CurFIFO; if (DataFIFO[f]->IsFull()) { // TODO - printf("!!!! %s FIFO FULL\n", SD_DESC); + printf("!!!! %s FIFO (32) FULL\n", SD_DESC); return; } @@ -608,12 +641,26 @@ void DSi_SDHost::WriteFIFO32(u32 val) } +#define MMC_DESC (Internal?"NAND":"SDcard") + DSi_MMCStorage::DSi_MMCStorage(DSi_SDHost* host, bool internal, const char* path) : DSi_SDDevice(host) { Internal = internal; strncpy(FilePath, path, 1023); FilePath[1023] = '\0'; File = Platform::OpenLocalFile(path, "r+b"); + if (!File) + { + if (internal) + { + // TODO: proper failure + printf("!! MMC file %s does not exist\n", path); + } + else + { + File = Platform::OpenLocalFile(path, "w+b"); + } + } CSR = 0x00000100; // checkme @@ -674,6 +721,7 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param) { // TODO printf("CMD3 on SD card: TODO\n"); + Host->SendResponse((CSR & 0x1FFF) | ((CSR >> 6) & 0x2000) | ((CSR >> 8) & 0xC000) | (1 << 16), true); } return; diff --git a/src/NDS.cpp b/src/NDS.cpp index 95265cf..6933e95 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -1371,6 +1371,29 @@ void RunTimers(u32 cpu) +// matching NDMA modes for DSi +const u32 NDMAModes[] = +{ + // ARM9 + + 0x10, // immediate + 0x06, // VBlank + 0x07, // HBlank + 0x08, // scanline start + 0x09, // mainmem FIFO + 0x04, // DS cart slot + 0xFF, // GBA cart slot + 0x0A, // GX FIFO + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + + // ARM7 + + 0x30, // immediate + 0x26, // VBlank + 0x24, // DS cart slot + 0xFF, // wifi / GBA cart slot (TODO) +}; + bool DMAsInMode(u32 cpu, u32 mode) { cpu <<= 2; @@ -1378,6 +1401,13 @@ bool DMAsInMode(u32 cpu, u32 mode) if (DMAs[cpu+1]->IsInMode(mode)) return true; if (DMAs[cpu+2]->IsInMode(mode)) return true; if (DMAs[cpu+3]->IsInMode(mode)) return true; + + if (true) + { + cpu >>= 2; + return DSi::NDMAsInMode(cpu, NDMAModes[mode]); + } + return false; } @@ -1399,6 +1429,12 @@ void CheckDMAs(u32 cpu, u32 mode) DMAs[cpu+1]->StartIfNeeded(mode); DMAs[cpu+2]->StartIfNeeded(mode); DMAs[cpu+3]->StartIfNeeded(mode); + + if (true) + { + cpu >>= 2; + DSi::CheckNDMAs(cpu, NDMAModes[mode]); + } } void StopDMAs(u32 cpu, u32 mode) @@ -1408,6 +1444,12 @@ void StopDMAs(u32 cpu, u32 mode) DMAs[cpu+1]->StopIfNeeded(mode); DMAs[cpu+2]->StopIfNeeded(mode); DMAs[cpu+3]->StopIfNeeded(mode); + + if (true) + { + cpu >>= 2; + DSi::StopNDMAs(cpu, NDMAModes[mode]); + } } diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index 65cf8ae..b0e9837 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -1227,11 +1227,11 @@ void WriteROMCnt(u32 val) *(u32*)&cmd[4] = *(u32*)&ROMCommand[4]; } - printf("ROM COMMAND %04X %08X %02X%02X%02X%02X%02X%02X%02X%02X SIZE %04X\n", + /*printf("ROM COMMAND %04X %08X %02X%02X%02X%02X%02X%02X%02X%02X SIZE %04X\n", SPICnt, ROMCnt, cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6], cmd[7], - datasize); + datasize);*/ switch (cmd[0]) { -- cgit v1.2.3 From 1c72df43ab8a45c3d7253274d8b1cb6e286a41eb Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 20 Oct 2019 18:35:16 +0200 Subject: messing around --- src/DSi.cpp | 36 ++++++++++++++++++++++++++++++------ src/DSi.h | 2 ++ src/DSi_I2C.cpp | 7 +++++++ 3 files changed, 39 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index ef4e6da..71ef6d3 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -160,6 +160,27 @@ void Reset() ARM7Write16(eaddr+0x42, 0x0001); } +void SoftReset() +{ + // TODO: check exactly what is reset + // presumably, main RAM isn't reset, since the DSi can be told + // to boot a specific title this way + // BPTWL state wouldn't be reset either since BPTWL[0x70] is + // the warmboot flag + + // also, BPTWL[0x70] could be abused to quickly boot specific titles + + NDS::ARM9->Reset(); + NDS::ARM7->Reset(); + + DSi_AES::Reset(); + + LoadNAND(); + + NDS::ARM9->JumpTo(BootAddr[0]); + NDS::ARM7->JumpTo(BootAddr[1]); +} + bool LoadBIOS() { FILE* f; @@ -636,7 +657,8 @@ void Set_SCFG_MC(u32 val) u8 ARM9Read8(u32 addr) -{ +{if(addr==0x02FFC1B0) printf("ARM9 READ8 ROM REGION %08X\n", NDS::GetPC(0)); +if(addr==0x02FFFD70) printf("ARM9 READ8 CONSOLE REGION %08X\n", NDS::GetPC(0)); if ((addr >= 0xFFFF0000) && (!(SCFG_BIOS & (1<<1)))) { if ((addr >= 0xFFFF8000) && (SCFG_BIOS & (1<<0))) @@ -673,7 +695,7 @@ u8 ARM9Read8(u32 addr) } u16 ARM9Read16(u32 addr) -{ +{if(addr==0x02FFC1B0) printf("ARM9 READ16 ROM REGION %08X\n", NDS::GetPC(0)); if ((addr >= 0xFFFF0000) && (!(SCFG_BIOS & (1<<1)))) { if ((addr >= 0xFFFF8000) && (SCFG_BIOS & (1<<0))) @@ -710,7 +732,8 @@ u16 ARM9Read16(u32 addr) } u32 ARM9Read32(u32 addr) -{ +{if(addr==0x02FFC1B0) printf("ARM9 READ32 ROM REGION %08X\n", NDS::GetPC(0)); +if(addr==0x2FE71B0) return 0xFFFFFFFF; // hax: bypass region lock if ((addr >= 0xFFFF0000) && (!(SCFG_BIOS & (1<<1)))) { if ((addr >= 0xFFFF8000) && (SCFG_BIOS & (1<<0))) @@ -883,7 +906,8 @@ bool ARM9GetMemRegion(u32 addr, bool write, NDS::MemRegion* region) u8 ARM7Read8(u32 addr) -{ +{if(addr==0x02FFC1B0) printf("ARM7 READ8 ROM REGION %08X\n", NDS::GetPC(1)); +if(addr==0x02FFFD70) printf("ARM7 READ8 CONSOLE REGION %08X\n", NDS::GetPC(1)); if ((addr < 0x00010000) && (!(SCFG_BIOS & (1<<9)))) { if ((addr >= 0x00008000) && (SCFG_BIOS & (1<<8))) @@ -924,7 +948,7 @@ u8 ARM7Read8(u32 addr) } u16 ARM7Read16(u32 addr) -{ +{if(addr==0x02FFC1B0) printf("ARM7 READ16 ROM REGION %08X\n", NDS::GetPC(1)); if ((addr < 0x00010000) && (!(SCFG_BIOS & (1<<9)))) { if ((addr >= 0x00008000) && (SCFG_BIOS & (1<<8))) @@ -965,7 +989,7 @@ u16 ARM7Read16(u32 addr) } u32 ARM7Read32(u32 addr) -{ +{if(addr==0x02FFC1B0) printf("ARM7 READ32 ROM REGION %08X\n", NDS::GetPC(1)); if ((addr < 0x00010000) && (!(SCFG_BIOS & (1<<9)))) { if ((addr >= 0x00008000) && (SCFG_BIOS & (1<<8))) diff --git a/src/DSi.h b/src/DSi.h index 5697237..08712de 100644 --- a/src/DSi.h +++ b/src/DSi.h @@ -42,6 +42,8 @@ bool Init(); void DeInit(); void Reset(); +void SoftReset(); + bool LoadBIOS(); bool LoadNAND(); diff --git a/src/DSi_I2C.cpp b/src/DSi_I2C.cpp index 5ced51e..0ab7008 100644 --- a/src/DSi_I2C.cpp +++ b/src/DSi_I2C.cpp @@ -103,6 +103,13 @@ void Write(u8 val, bool last) return; } + if (CurPos == 0x11 && val == 0x01) + { + printf("BPTWL: soft-reset\n"); + val = 0; // checkme + DSi::SoftReset(); + } + if (CurPos == 0x11 || CurPos == 0x12 || CurPos == 0x21 || CurPos == 0x30 || CurPos == 0x31 || -- cgit v1.2.3 From f9ac26078b7d88803ea7079490f419b4a0bfe660 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 20 Oct 2019 18:52:33 +0200 Subject: look for NAND nocash footer at the end of the file rather than using a hardcoded offset. check whether the footer is present. --- src/DSi.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index 71ef6d3..15f06a2 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -361,12 +361,25 @@ bool LoadNAND() #define printhex(str, size) { for (int z = 0; z < (size); z++) printf("%02X", (str)[z]); printf("\n"); } #define printhex_rev(str, size) { for (int z = (size)-1; z >= 0; z--) printf("%02X", (str)[z]); printf("\n"); } - fseek(f, 0xF000010, SEEK_SET); + // read the nocash footer + + fseek(f, -0x40, SEEK_END); + + char nand_footer[16]; + const char* nand_footer_ref = "DSi eMMC CID/CPU"; + fread(nand_footer, 1, 16, f); + if (memcmp(nand_footer, nand_footer_ref, 16)) + { + printf("ERROR: NAND missing nocash footer\n"); + fclose(f); + return false; + } + fread(eMMC_CID, 1, 16, f); fread(&ConsoleID, 1, 8, f); printf("eMMC CID: "); printhex(eMMC_CID, 16); - printf("Console ID: %llx\n", ConsoleID); + printf("Console ID: %016llX\n", ConsoleID); fclose(f); } -- cgit v1.2.3 From de405ce8922713b78fe30c7612cbfc610578a474 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 14 Apr 2020 23:17:16 +0200 Subject: so, this is it this was a glorious fight, but I admit defeat --- melonDS.cbp | 2 ++ src/frontend/qt/main.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/frontend/qt/main.h | 24 ++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 src/frontend/qt/main.cpp create mode 100644 src/frontend/qt/main.h (limited to 'src') diff --git a/melonDS.cbp b/melonDS.cbp index 8d900d1..7305ee5 100644 --- a/melonDS.cbp +++ b/melonDS.cbp @@ -153,6 +153,8 @@ + + diff --git a/src/frontend/qt/main.cpp b/src/frontend/qt/main.cpp new file mode 100644 index 0000000..3f61ec6 --- /dev/null +++ b/src/frontend/qt/main.cpp @@ -0,0 +1,45 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include +#include +#include +#include + +// Qt includes and shit here, I guess + +#include "main.h" + +#include "../version.h" + + +// + + +int main(int argc, char** argv) +{ + srand(time(NULL)); + + printf("melonDS " MELONDS_VERSION "\n"); + printf(MELONDS_URL "\n"); + + printf("Arisotura hereby admits defeat\n"); + printf("NI DIEU NI MAITRE\n"); + + return 0; +} diff --git a/src/frontend/qt/main.h b/src/frontend/qt/main.h new file mode 100644 index 0000000..65d6518 --- /dev/null +++ b/src/frontend/qt/main.h @@ -0,0 +1,24 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef MAIN_H +#define MAIN_H + +// put the class shit here + +#endif // MAIN_H -- cgit v1.2.3 From 231f0fc2e5e22b2d4907341cc191cfc9215556fb Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 14 Apr 2020 23:38:48 +0200 Subject: welp --- melonDS.cbp | 4 ++-- src/frontend/qt/main.cpp | 45 -------------------------------------------- src/frontend/qt/main.h | 24 ----------------------- src/frontend/qt_sdl/main.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++++ src/frontend/qt_sdl/main.h | 24 +++++++++++++++++++++++ 5 files changed, 71 insertions(+), 71 deletions(-) delete mode 100644 src/frontend/qt/main.cpp delete mode 100644 src/frontend/qt/main.h create mode 100644 src/frontend/qt_sdl/main.cpp create mode 100644 src/frontend/qt_sdl/main.h (limited to 'src') diff --git a/melonDS.cbp b/melonDS.cbp index 7305ee5..2a33978 100644 --- a/melonDS.cbp +++ b/melonDS.cbp @@ -153,8 +153,8 @@ - - + + diff --git a/src/frontend/qt/main.cpp b/src/frontend/qt/main.cpp deleted file mode 100644 index 3f61ec6..0000000 --- a/src/frontend/qt/main.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#include -#include -#include -#include - -// Qt includes and shit here, I guess - -#include "main.h" - -#include "../version.h" - - -// - - -int main(int argc, char** argv) -{ - srand(time(NULL)); - - printf("melonDS " MELONDS_VERSION "\n"); - printf(MELONDS_URL "\n"); - - printf("Arisotura hereby admits defeat\n"); - printf("NI DIEU NI MAITRE\n"); - - return 0; -} diff --git a/src/frontend/qt/main.h b/src/frontend/qt/main.h deleted file mode 100644 index 65d6518..0000000 --- a/src/frontend/qt/main.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#ifndef MAIN_H -#define MAIN_H - -// put the class shit here - -#endif // MAIN_H diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp new file mode 100644 index 0000000..3f61ec6 --- /dev/null +++ b/src/frontend/qt_sdl/main.cpp @@ -0,0 +1,45 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include +#include +#include +#include + +// Qt includes and shit here, I guess + +#include "main.h" + +#include "../version.h" + + +// + + +int main(int argc, char** argv) +{ + srand(time(NULL)); + + printf("melonDS " MELONDS_VERSION "\n"); + printf(MELONDS_URL "\n"); + + printf("Arisotura hereby admits defeat\n"); + printf("NI DIEU NI MAITRE\n"); + + return 0; +} diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h new file mode 100644 index 0000000..65d6518 --- /dev/null +++ b/src/frontend/qt_sdl/main.h @@ -0,0 +1,24 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef MAIN_H +#define MAIN_H + +// put the class shit here + +#endif // MAIN_H -- cgit v1.2.3 From a85d41c53eed50f188502925ed34674397b86550 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 25 Apr 2020 18:51:08 +0200 Subject: berp. --- src/libui_sdl/CMakeLists.txt | 73 - src/libui_sdl/DlgAudioSettings.cpp | 197 -- src/libui_sdl/DlgAudioSettings.h | 30 - src/libui_sdl/DlgEmuSettings.cpp | 117 - src/libui_sdl/DlgEmuSettings.h | 30 - src/libui_sdl/DlgInputConfig.cpp | 663 ----- src/libui_sdl/DlgInputConfig.h | 31 - src/libui_sdl/DlgVideoSettings.cpp | 354 --- src/libui_sdl/DlgVideoSettings.h | 30 - src/libui_sdl/DlgWifiSettings.cpp | 271 -- src/libui_sdl/DlgWifiSettings.h | 31 - src/libui_sdl/LAN_PCap.cpp | 387 --- src/libui_sdl/LAN_PCap.h | 53 - src/libui_sdl/LAN_Socket.cpp | 1145 -------- src/libui_sdl/LAN_Socket.h | 38 - src/libui_sdl/MelonCap.cpp | 347 --- src/libui_sdl/MelonCap.h | 34 - src/libui_sdl/OSD.cpp | 435 --- src/libui_sdl/OSD.h | 35 - src/libui_sdl/Platform.cpp | 557 ---- src/libui_sdl/PlatformConfig.cpp | 151 - src/libui_sdl/PlatformConfig.h | 82 - src/libui_sdl/font.h | 135 - src/libui_sdl/libui/.travis.yml | 23 - src/libui_sdl/libui/ANNOUNCE.md | 22 - src/libui_sdl/libui/CMakeLists.txt | 219 -- src/libui_sdl/libui/Changelog.md | 33 - src/libui_sdl/libui/Compatibility.md | 141 - src/libui_sdl/libui/LICENSE | 9 - src/libui_sdl/libui/README.md | 185 -- src/libui_sdl/libui/TODO.md | 129 - .../libui/_abort/windowevents/darwin_window.m | 90 - src/libui_sdl/libui/_abort/windowevents/page15.c | 65 - src/libui_sdl/libui/_abort/windowevents/ui.h | 6 - .../libui/_abort/windowevents/unix_window.c | 97 - .../libui/_abort/windowevents/windows_window.cpp | 86 - src/libui_sdl/libui/_wip/rules.darwin | 6 - src/libui_sdl/libui/_wip/rules.unix | 3 - src/libui_sdl/libui/_wip/sv/normal | 25 - src/libui_sdl/libui/_wip/sv/normal.nots | 25 - src/libui_sdl/libui/_wip/sv/outlineview | 25 - src/libui_sdl/libui/_wip/sv/outlineview.nots | 25 - src/libui_sdl/libui/_wip/sv/sourcelist | 25 - src/libui_sdl/libui/_wip/sv/sourcelist.nots | 25 - src/libui_sdl/libui/_wip/sv/tableview | 25 - src/libui_sdl/libui/_wip/sv/tableview.nots | 25 - src/libui_sdl/libui/_wip/sv/textview | 25 - src/libui_sdl/libui/_wip/sv/textview.nots | 25 - src/libui_sdl/libui/_wip/table/test_page9.c | 80 - src/libui_sdl/libui/_wip/table/ui.h | 46 - src/libui_sdl/libui/_wip/table/unix_table.c | 87 - src/libui_sdl/libui/_wip/table/unix_tablemodel.c | 303 -- src/libui_sdl/libui/common/CMakeLists.txt | 16 - src/libui_sdl/libui/common/areaevents.c | 167 -- src/libui_sdl/libui/common/control.c | 117 - src/libui_sdl/libui/common/controlsigs.h | 25 - src/libui_sdl/libui/common/debug.c | 21 - src/libui_sdl/libui/common/matrix.c | 50 - src/libui_sdl/libui/common/shouldquit.c | 22 - src/libui_sdl/libui/common/uipriv.h | 58 - src/libui_sdl/libui/common/userbugs.c | 8 - src/libui_sdl/libui/darwin/CMakeLists.txt | 79 - src/libui_sdl/libui/darwin/alloc.m | 89 - src/libui_sdl/libui/darwin/area.m | 475 --- src/libui_sdl/libui/darwin/areaevents.m | 159 - src/libui_sdl/libui/darwin/autolayout.m | 161 -- src/libui_sdl/libui/darwin/box.m | 469 --- src/libui_sdl/libui/darwin/button.m | 113 - src/libui_sdl/libui/darwin/checkbox.m | 129 - src/libui_sdl/libui/darwin/colorbutton.m | 159 - src/libui_sdl/libui/darwin/combobox.m | 145 - src/libui_sdl/libui/darwin/control.m | 84 - src/libui_sdl/libui/darwin/datetimepicker.m | 42 - src/libui_sdl/libui/darwin/debug.m | 19 - src/libui_sdl/libui/darwin/draw.m | 454 --- src/libui_sdl/libui/darwin/drawtext.m | 655 ----- src/libui_sdl/libui/darwin/editablecombo.m | 185 -- src/libui_sdl/libui/darwin/entry.m | 251 -- src/libui_sdl/libui/darwin/fontbutton.m | 218 -- src/libui_sdl/libui/darwin/form.m | 561 ---- src/libui_sdl/libui/darwin/grid.m | 800 ------ src/libui_sdl/libui/darwin/group.m | 194 -- src/libui_sdl/libui/darwin/image.m | 82 - src/libui_sdl/libui/darwin/label.m | 43 - src/libui_sdl/libui/darwin/main.m | 239 -- src/libui_sdl/libui/darwin/map.m | 59 - src/libui_sdl/libui/darwin/menu.m | 368 --- src/libui_sdl/libui/darwin/multilineentry.m | 233 -- src/libui_sdl/libui/darwin/progressbar.m | 78 - src/libui_sdl/libui/darwin/radiobuttons.m | 207 -- src/libui_sdl/libui/darwin/scrollview.m | 61 - src/libui_sdl/libui/darwin/separator.m | 45 - src/libui_sdl/libui/darwin/slider.m | 147 - src/libui_sdl/libui/darwin/spinbox.m | 214 -- src/libui_sdl/libui/darwin/stddialogs.m | 123 - src/libui_sdl/libui/darwin/tab.m | 292 -- src/libui_sdl/libui/darwin/text.m | 19 - src/libui_sdl/libui/darwin/uipriv_darwin.h | 146 - src/libui_sdl/libui/darwin/util.m | 15 - src/libui_sdl/libui/darwin/window.m | 407 --- src/libui_sdl/libui/darwin/winmoveresize.m | 253 -- src/libui_sdl/libui/doc/area.md | 53 - src/libui_sdl/libui/doc/areahandler | 1 - src/libui_sdl/libui/doc/draw.md | 42 - src/libui_sdl/libui/doc/drawtext | 13 - src/libui_sdl/libui/doc/export/coretext | 5 - src/libui_sdl/libui/doc/form | 1 - src/libui_sdl/libui/doc/main | 1 - src/libui_sdl/libui/doc/mainsteps | 1 - src/libui_sdl/libui/doc/slider | 1 - src/libui_sdl/libui/doc/spinbox | 1 - src/libui_sdl/libui/doc/static | 2 - src/libui_sdl/libui/doc/windowmovesize | 3 - src/libui_sdl/libui/doc/winstatic | 1 - src/libui_sdl/libui/examples/CMakeLists.txt | 38 - .../libui/examples/controlgallery/darwin.png | Bin 97260 -> 0 bytes src/libui_sdl/libui/examples/controlgallery/main.c | 540 ---- .../libui/examples/controlgallery/unix.png | Bin 41757 -> 0 bytes .../libui/examples/controlgallery/windows.png | Bin 48217 -> 0 bytes .../libui/examples/cpp-multithread/main.cpp | 92 - src/libui_sdl/libui/examples/example.manifest | 20 - .../libui/examples/example.static.manifest | 32 - src/libui_sdl/libui/examples/histogram/main.c | 309 -- src/libui_sdl/libui/examples/resources.rc | 13 - src/libui_sdl/libui/nowintable.diff | 50 - src/libui_sdl/libui/oldhaiku.tgz | Bin 13965 -> 0 bytes src/libui_sdl/libui/test/CMakeLists.txt | 38 - src/libui_sdl/libui/test/drawtests.c | 1978 ------------- .../test/images/andlabs_16x16test_24june2016.png | Bin 272 -> 0 bytes .../test/images/andlabs_32x32test_24june2016.png | Bin 432 -> 0 bytes src/libui_sdl/libui/test/images/gen.go | 98 - ...con-theme-0.8.90_16x16_x-office-spreadsheet.png | Bin 704 -> 0 bytes ...con-theme-0.8.90_32x32_x-office-spreadsheet.png | Bin 1518 -> 0 bytes src/libui_sdl/libui/test/main.c | 180 -- src/libui_sdl/libui/test/menus.c | 112 - src/libui_sdl/libui/test/page1.c | 171 -- src/libui_sdl/libui/test/page10.c | 185 -- src/libui_sdl/libui/test/page11.c | 54 - src/libui_sdl/libui/test/page12.c | 60 - src/libui_sdl/libui/test/page13.c | 157 - src/libui_sdl/libui/test/page14.c | 350 --- src/libui_sdl/libui/test/page15.c | 260 -- src/libui_sdl/libui/test/page2.c | 215 -- src/libui_sdl/libui/test/page3.c | 69 - src/libui_sdl/libui/test/page4.c | 165 -- src/libui_sdl/libui/test/page5.c | 99 - src/libui_sdl/libui/test/page6.c | 126 - src/libui_sdl/libui/test/page7.c | 25 - src/libui_sdl/libui/test/page7a.c | 139 - src/libui_sdl/libui/test/page7b.c | 71 - src/libui_sdl/libui/test/page7c.c | 133 - src/libui_sdl/libui/test/page8.c | 46 - src/libui_sdl/libui/test/page9.c | 289 -- src/libui_sdl/libui/test/resources.rc | 13 - src/libui_sdl/libui/test/spaced.c | 177 -- src/libui_sdl/libui/test/test.h | 91 - src/libui_sdl/libui/test/test.manifest | 20 - src/libui_sdl/libui/test/test.static.manifest | 32 - src/libui_sdl/libui/ui.h | 763 ----- src/libui_sdl/libui/ui_darwin.h | 224 -- src/libui_sdl/libui/ui_unix.h | 154 - src/libui_sdl/libui/ui_windows.h | 280 -- src/libui_sdl/libui/unix/CMakeLists.txt | 87 - src/libui_sdl/libui/unix/alloc.c | 84 - src/libui_sdl/libui/unix/area.c | 853 ------ src/libui_sdl/libui/unix/box.c | 159 - src/libui_sdl/libui/unix/button.c | 57 - src/libui_sdl/libui/unix/cellrendererbutton.c | 299 -- src/libui_sdl/libui/unix/checkbox.c | 78 - src/libui_sdl/libui/unix/child.c | 120 - src/libui_sdl/libui/unix/colorbutton.c | 80 - src/libui_sdl/libui/unix/combobox.c | 66 - src/libui_sdl/libui/unix/control.c | 14 - src/libui_sdl/libui/unix/datetimepicker.c | 599 ---- src/libui_sdl/libui/unix/debug.c | 14 - src/libui_sdl/libui/unix/draw.c | 214 -- src/libui_sdl/libui/unix/draw.h | 21 - src/libui_sdl/libui/unix/drawmatrix.c | 115 - src/libui_sdl/libui/unix/drawpath.c | 199 -- src/libui_sdl/libui/unix/drawtext.c | 293 -- src/libui_sdl/libui/unix/editablecombo.c | 79 - src/libui_sdl/libui/unix/entry.c | 97 - src/libui_sdl/libui/unix/fontbutton.c | 70 - src/libui_sdl/libui/unix/form.c | 159 - src/libui_sdl/libui/unix/future.c | 42 - src/libui_sdl/libui/unix/gl.c | 251 -- src/libui_sdl/libui/unix/graphemes.c | 31 - src/libui_sdl/libui/unix/grid.c | 141 - src/libui_sdl/libui/unix/group.c | 89 - src/libui_sdl/libui/unix/image.c | 120 - src/libui_sdl/libui/unix/label.c | 36 - src/libui_sdl/libui/unix/main.c | 147 - src/libui_sdl/libui/unix/menu.c | 432 --- src/libui_sdl/libui/unix/multilineentry.c | 124 - src/libui_sdl/libui/unix/progressbar.c | 71 - src/libui_sdl/libui/unix/radiobuttons.c | 121 - src/libui_sdl/libui/unix/separator.c | 34 - src/libui_sdl/libui/unix/slider.c | 71 - src/libui_sdl/libui/unix/spinbox.c | 72 - src/libui_sdl/libui/unix/stddialogs.c | 116 - src/libui_sdl/libui/unix/tab.c | 97 - src/libui_sdl/libui/unix/text.c | 12 - src/libui_sdl/libui/unix/uipriv_unix.h | 71 - src/libui_sdl/libui/unix/util.c | 10 - src/libui_sdl/libui/unix/window.c | 462 --- src/libui_sdl/libui/windows/CMakeLists.txt | 92 - src/libui_sdl/libui/windows/_uipriv_migrate.hpp | 61 - src/libui_sdl/libui/windows/alloc.cpp | 64 - src/libui_sdl/libui/windows/area.cpp | 291 -- src/libui_sdl/libui/windows/area.hpp | 56 - src/libui_sdl/libui/windows/areadraw.cpp | 170 -- src/libui_sdl/libui/windows/areaevents.cpp | 435 --- src/libui_sdl/libui/windows/areascroll.cpp | 247 -- src/libui_sdl/libui/windows/areautil.cpp | 53 - src/libui_sdl/libui/windows/box.cpp | 324 --- src/libui_sdl/libui/windows/button.cpp | 126 - src/libui_sdl/libui/windows/checkbox.cpp | 117 - src/libui_sdl/libui/windows/colorbutton.cpp | 192 -- src/libui_sdl/libui/windows/colordialog.cpp | 1255 -------- src/libui_sdl/libui/windows/combobox.cpp | 110 - src/libui_sdl/libui/windows/compilerver.hpp | 13 - src/libui_sdl/libui/windows/container.cpp | 110 - src/libui_sdl/libui/windows/control.cpp | 121 - src/libui_sdl/libui/windows/d2dscratch.cpp | 166 -- src/libui_sdl/libui/windows/datetimepicker.cpp | 191 -- src/libui_sdl/libui/windows/debug.cpp | 84 - src/libui_sdl/libui/windows/draw.cpp | 578 ---- src/libui_sdl/libui/windows/draw.hpp | 24 - src/libui_sdl/libui/windows/drawmatrix.cpp | 117 - src/libui_sdl/libui/windows/drawpath.cpp | 246 -- src/libui_sdl/libui/windows/drawtext.cpp | 531 ---- src/libui_sdl/libui/windows/dwrite.cpp | 88 - src/libui_sdl/libui/windows/editablecombo.cpp | 115 - src/libui_sdl/libui/windows/entry.cpp | 134 - src/libui_sdl/libui/windows/events.cpp | 151 - src/libui_sdl/libui/windows/fontbutton.cpp | 122 - src/libui_sdl/libui/windows/fontdialog.cpp | 686 ----- src/libui_sdl/libui/windows/form.cpp | 326 --- src/libui_sdl/libui/windows/gl.cpp | 196 -- src/libui_sdl/libui/windows/graphemes.cpp | 80 - src/libui_sdl/libui/windows/grid.cpp | 665 ----- src/libui_sdl/libui/windows/group.cpp | 224 -- src/libui_sdl/libui/windows/init.cpp | 167 -- src/libui_sdl/libui/windows/label.cpp | 57 - src/libui_sdl/libui/windows/libui.manifest | 31 - src/libui_sdl/libui/windows/main.cpp | 130 - src/libui_sdl/libui/windows/menu.cpp | 420 --- src/libui_sdl/libui/windows/multilineentry.cpp | 152 - src/libui_sdl/libui/windows/notes | 3 - src/libui_sdl/libui/windows/parent.cpp | 144 - src/libui_sdl/libui/windows/progressbar.cpp | 83 - src/libui_sdl/libui/windows/radiobuttons.cpp | 196 -- src/libui_sdl/libui/windows/resources.hpp | 37 - src/libui_sdl/libui/windows/resources.rc | 96 - src/libui_sdl/libui/windows/separator.cpp | 69 - src/libui_sdl/libui/windows/sizing.cpp | 62 - src/libui_sdl/libui/windows/slider.cpp | 98 - src/libui_sdl/libui/windows/spinbox.cpp | 215 -- src/libui_sdl/libui/windows/stddialogs.cpp | 167 -- src/libui_sdl/libui/windows/tab.cpp | 294 -- src/libui_sdl/libui/windows/tabpage.cpp | 131 - src/libui_sdl/libui/windows/text.cpp | 106 - src/libui_sdl/libui/windows/uipriv_windows.hpp | 164 -- src/libui_sdl/libui/windows/utf16.cpp | 153 - src/libui_sdl/libui/windows/utilwin.cpp | 76 - src/libui_sdl/libui/windows/winapi.hpp | 55 - src/libui_sdl/libui/windows/window.cpp | 665 ----- src/libui_sdl/libui/windows/winpublic.cpp | 61 - src/libui_sdl/libui/windows/winutil.cpp | 143 - src/libui_sdl/main.cpp | 3029 -------------------- src/libui_sdl/main_shaders.h | 250 -- 271 files changed, 46177 deletions(-) delete mode 100644 src/libui_sdl/CMakeLists.txt delete mode 100644 src/libui_sdl/DlgAudioSettings.cpp delete mode 100644 src/libui_sdl/DlgAudioSettings.h delete mode 100644 src/libui_sdl/DlgEmuSettings.cpp delete mode 100644 src/libui_sdl/DlgEmuSettings.h delete mode 100644 src/libui_sdl/DlgInputConfig.cpp delete mode 100644 src/libui_sdl/DlgInputConfig.h delete mode 100644 src/libui_sdl/DlgVideoSettings.cpp delete mode 100644 src/libui_sdl/DlgVideoSettings.h delete mode 100644 src/libui_sdl/DlgWifiSettings.cpp delete mode 100644 src/libui_sdl/DlgWifiSettings.h delete mode 100644 src/libui_sdl/LAN_PCap.cpp delete mode 100644 src/libui_sdl/LAN_PCap.h delete mode 100644 src/libui_sdl/LAN_Socket.cpp delete mode 100644 src/libui_sdl/LAN_Socket.h delete mode 100644 src/libui_sdl/MelonCap.cpp delete mode 100644 src/libui_sdl/MelonCap.h delete mode 100644 src/libui_sdl/OSD.cpp delete mode 100644 src/libui_sdl/OSD.h delete mode 100644 src/libui_sdl/Platform.cpp delete mode 100644 src/libui_sdl/PlatformConfig.cpp delete mode 100644 src/libui_sdl/PlatformConfig.h delete mode 100644 src/libui_sdl/font.h delete mode 100644 src/libui_sdl/libui/.travis.yml delete mode 100644 src/libui_sdl/libui/ANNOUNCE.md delete mode 100644 src/libui_sdl/libui/CMakeLists.txt delete mode 100644 src/libui_sdl/libui/Changelog.md delete mode 100644 src/libui_sdl/libui/Compatibility.md delete mode 100644 src/libui_sdl/libui/LICENSE delete mode 100644 src/libui_sdl/libui/README.md delete mode 100644 src/libui_sdl/libui/TODO.md delete mode 100644 src/libui_sdl/libui/_abort/windowevents/darwin_window.m delete mode 100644 src/libui_sdl/libui/_abort/windowevents/page15.c delete mode 100644 src/libui_sdl/libui/_abort/windowevents/ui.h delete mode 100644 src/libui_sdl/libui/_abort/windowevents/unix_window.c delete mode 100644 src/libui_sdl/libui/_abort/windowevents/windows_window.cpp delete mode 100644 src/libui_sdl/libui/_wip/rules.darwin delete mode 100644 src/libui_sdl/libui/_wip/rules.unix delete mode 100644 src/libui_sdl/libui/_wip/sv/normal delete mode 100644 src/libui_sdl/libui/_wip/sv/normal.nots delete mode 100644 src/libui_sdl/libui/_wip/sv/outlineview delete mode 100644 src/libui_sdl/libui/_wip/sv/outlineview.nots delete mode 100644 src/libui_sdl/libui/_wip/sv/sourcelist delete mode 100644 src/libui_sdl/libui/_wip/sv/sourcelist.nots delete mode 100644 src/libui_sdl/libui/_wip/sv/tableview delete mode 100644 src/libui_sdl/libui/_wip/sv/tableview.nots delete mode 100644 src/libui_sdl/libui/_wip/sv/textview delete mode 100644 src/libui_sdl/libui/_wip/sv/textview.nots delete mode 100644 src/libui_sdl/libui/_wip/table/test_page9.c delete mode 100644 src/libui_sdl/libui/_wip/table/ui.h delete mode 100644 src/libui_sdl/libui/_wip/table/unix_table.c delete mode 100644 src/libui_sdl/libui/_wip/table/unix_tablemodel.c delete mode 100644 src/libui_sdl/libui/common/CMakeLists.txt delete mode 100644 src/libui_sdl/libui/common/areaevents.c delete mode 100644 src/libui_sdl/libui/common/control.c delete mode 100644 src/libui_sdl/libui/common/controlsigs.h delete mode 100644 src/libui_sdl/libui/common/debug.c delete mode 100644 src/libui_sdl/libui/common/matrix.c delete mode 100644 src/libui_sdl/libui/common/shouldquit.c delete mode 100644 src/libui_sdl/libui/common/uipriv.h delete mode 100644 src/libui_sdl/libui/common/userbugs.c delete mode 100644 src/libui_sdl/libui/darwin/CMakeLists.txt delete mode 100644 src/libui_sdl/libui/darwin/alloc.m delete mode 100644 src/libui_sdl/libui/darwin/area.m delete mode 100644 src/libui_sdl/libui/darwin/areaevents.m delete mode 100644 src/libui_sdl/libui/darwin/autolayout.m delete mode 100644 src/libui_sdl/libui/darwin/box.m delete mode 100644 src/libui_sdl/libui/darwin/button.m delete mode 100644 src/libui_sdl/libui/darwin/checkbox.m delete mode 100644 src/libui_sdl/libui/darwin/colorbutton.m delete mode 100644 src/libui_sdl/libui/darwin/combobox.m delete mode 100644 src/libui_sdl/libui/darwin/control.m delete mode 100644 src/libui_sdl/libui/darwin/datetimepicker.m delete mode 100644 src/libui_sdl/libui/darwin/debug.m delete mode 100644 src/libui_sdl/libui/darwin/draw.m delete mode 100644 src/libui_sdl/libui/darwin/drawtext.m delete mode 100644 src/libui_sdl/libui/darwin/editablecombo.m delete mode 100644 src/libui_sdl/libui/darwin/entry.m delete mode 100644 src/libui_sdl/libui/darwin/fontbutton.m delete mode 100644 src/libui_sdl/libui/darwin/form.m delete mode 100644 src/libui_sdl/libui/darwin/grid.m delete mode 100644 src/libui_sdl/libui/darwin/group.m delete mode 100644 src/libui_sdl/libui/darwin/image.m delete mode 100644 src/libui_sdl/libui/darwin/label.m delete mode 100644 src/libui_sdl/libui/darwin/main.m delete mode 100644 src/libui_sdl/libui/darwin/map.m delete mode 100644 src/libui_sdl/libui/darwin/menu.m delete mode 100644 src/libui_sdl/libui/darwin/multilineentry.m delete mode 100644 src/libui_sdl/libui/darwin/progressbar.m delete mode 100644 src/libui_sdl/libui/darwin/radiobuttons.m delete mode 100644 src/libui_sdl/libui/darwin/scrollview.m delete mode 100644 src/libui_sdl/libui/darwin/separator.m delete mode 100644 src/libui_sdl/libui/darwin/slider.m delete mode 100644 src/libui_sdl/libui/darwin/spinbox.m delete mode 100644 src/libui_sdl/libui/darwin/stddialogs.m delete mode 100644 src/libui_sdl/libui/darwin/tab.m delete mode 100644 src/libui_sdl/libui/darwin/text.m delete mode 100644 src/libui_sdl/libui/darwin/uipriv_darwin.h delete mode 100644 src/libui_sdl/libui/darwin/util.m delete mode 100644 src/libui_sdl/libui/darwin/window.m delete mode 100644 src/libui_sdl/libui/darwin/winmoveresize.m delete mode 100644 src/libui_sdl/libui/doc/area.md delete mode 100644 src/libui_sdl/libui/doc/areahandler delete mode 100644 src/libui_sdl/libui/doc/draw.md delete mode 100644 src/libui_sdl/libui/doc/drawtext delete mode 100644 src/libui_sdl/libui/doc/export/coretext delete mode 100644 src/libui_sdl/libui/doc/form delete mode 100644 src/libui_sdl/libui/doc/main delete mode 100644 src/libui_sdl/libui/doc/mainsteps delete mode 100644 src/libui_sdl/libui/doc/slider delete mode 100644 src/libui_sdl/libui/doc/spinbox delete mode 100644 src/libui_sdl/libui/doc/static delete mode 100644 src/libui_sdl/libui/doc/windowmovesize delete mode 100644 src/libui_sdl/libui/doc/winstatic delete mode 100644 src/libui_sdl/libui/examples/CMakeLists.txt delete mode 100644 src/libui_sdl/libui/examples/controlgallery/darwin.png delete mode 100644 src/libui_sdl/libui/examples/controlgallery/main.c delete mode 100644 src/libui_sdl/libui/examples/controlgallery/unix.png delete mode 100644 src/libui_sdl/libui/examples/controlgallery/windows.png delete mode 100644 src/libui_sdl/libui/examples/cpp-multithread/main.cpp delete mode 100644 src/libui_sdl/libui/examples/example.manifest delete mode 100644 src/libui_sdl/libui/examples/example.static.manifest delete mode 100644 src/libui_sdl/libui/examples/histogram/main.c delete mode 100644 src/libui_sdl/libui/examples/resources.rc delete mode 100644 src/libui_sdl/libui/nowintable.diff delete mode 100644 src/libui_sdl/libui/oldhaiku.tgz delete mode 100644 src/libui_sdl/libui/test/CMakeLists.txt delete mode 100644 src/libui_sdl/libui/test/drawtests.c delete mode 100644 src/libui_sdl/libui/test/images/andlabs_16x16test_24june2016.png delete mode 100644 src/libui_sdl/libui/test/images/andlabs_32x32test_24june2016.png delete mode 100644 src/libui_sdl/libui/test/images/gen.go delete mode 100644 src/libui_sdl/libui/test/images/tango-icon-theme-0.8.90_16x16_x-office-spreadsheet.png delete mode 100644 src/libui_sdl/libui/test/images/tango-icon-theme-0.8.90_32x32_x-office-spreadsheet.png delete mode 100644 src/libui_sdl/libui/test/main.c delete mode 100644 src/libui_sdl/libui/test/menus.c delete mode 100644 src/libui_sdl/libui/test/page1.c delete mode 100644 src/libui_sdl/libui/test/page10.c delete mode 100644 src/libui_sdl/libui/test/page11.c delete mode 100644 src/libui_sdl/libui/test/page12.c delete mode 100644 src/libui_sdl/libui/test/page13.c delete mode 100644 src/libui_sdl/libui/test/page14.c delete mode 100644 src/libui_sdl/libui/test/page15.c delete mode 100644 src/libui_sdl/libui/test/page2.c delete mode 100644 src/libui_sdl/libui/test/page3.c delete mode 100644 src/libui_sdl/libui/test/page4.c delete mode 100644 src/libui_sdl/libui/test/page5.c delete mode 100644 src/libui_sdl/libui/test/page6.c delete mode 100644 src/libui_sdl/libui/test/page7.c delete mode 100644 src/libui_sdl/libui/test/page7a.c delete mode 100644 src/libui_sdl/libui/test/page7b.c delete mode 100644 src/libui_sdl/libui/test/page7c.c delete mode 100644 src/libui_sdl/libui/test/page8.c delete mode 100644 src/libui_sdl/libui/test/page9.c delete mode 100644 src/libui_sdl/libui/test/resources.rc delete mode 100644 src/libui_sdl/libui/test/spaced.c delete mode 100644 src/libui_sdl/libui/test/test.h delete mode 100644 src/libui_sdl/libui/test/test.manifest delete mode 100644 src/libui_sdl/libui/test/test.static.manifest delete mode 100644 src/libui_sdl/libui/ui.h delete mode 100644 src/libui_sdl/libui/ui_darwin.h delete mode 100644 src/libui_sdl/libui/ui_unix.h delete mode 100644 src/libui_sdl/libui/ui_windows.h delete mode 100644 src/libui_sdl/libui/unix/CMakeLists.txt delete mode 100644 src/libui_sdl/libui/unix/alloc.c delete mode 100644 src/libui_sdl/libui/unix/area.c delete mode 100644 src/libui_sdl/libui/unix/box.c delete mode 100644 src/libui_sdl/libui/unix/button.c delete mode 100644 src/libui_sdl/libui/unix/cellrendererbutton.c delete mode 100644 src/libui_sdl/libui/unix/checkbox.c delete mode 100644 src/libui_sdl/libui/unix/child.c delete mode 100644 src/libui_sdl/libui/unix/colorbutton.c delete mode 100644 src/libui_sdl/libui/unix/combobox.c delete mode 100644 src/libui_sdl/libui/unix/control.c delete mode 100644 src/libui_sdl/libui/unix/datetimepicker.c delete mode 100644 src/libui_sdl/libui/unix/debug.c delete mode 100644 src/libui_sdl/libui/unix/draw.c delete mode 100644 src/libui_sdl/libui/unix/draw.h delete mode 100644 src/libui_sdl/libui/unix/drawmatrix.c delete mode 100644 src/libui_sdl/libui/unix/drawpath.c delete mode 100644 src/libui_sdl/libui/unix/drawtext.c delete mode 100644 src/libui_sdl/libui/unix/editablecombo.c delete mode 100644 src/libui_sdl/libui/unix/entry.c delete mode 100644 src/libui_sdl/libui/unix/fontbutton.c delete mode 100644 src/libui_sdl/libui/unix/form.c delete mode 100644 src/libui_sdl/libui/unix/future.c delete mode 100644 src/libui_sdl/libui/unix/gl.c delete mode 100644 src/libui_sdl/libui/unix/graphemes.c delete mode 100644 src/libui_sdl/libui/unix/grid.c delete mode 100644 src/libui_sdl/libui/unix/group.c delete mode 100644 src/libui_sdl/libui/unix/image.c delete mode 100644 src/libui_sdl/libui/unix/label.c delete mode 100644 src/libui_sdl/libui/unix/main.c delete mode 100644 src/libui_sdl/libui/unix/menu.c delete mode 100644 src/libui_sdl/libui/unix/multilineentry.c delete mode 100644 src/libui_sdl/libui/unix/progressbar.c delete mode 100644 src/libui_sdl/libui/unix/radiobuttons.c delete mode 100644 src/libui_sdl/libui/unix/separator.c delete mode 100644 src/libui_sdl/libui/unix/slider.c delete mode 100644 src/libui_sdl/libui/unix/spinbox.c delete mode 100644 src/libui_sdl/libui/unix/stddialogs.c delete mode 100644 src/libui_sdl/libui/unix/tab.c delete mode 100644 src/libui_sdl/libui/unix/text.c delete mode 100644 src/libui_sdl/libui/unix/uipriv_unix.h delete mode 100644 src/libui_sdl/libui/unix/util.c delete mode 100644 src/libui_sdl/libui/unix/window.c delete mode 100644 src/libui_sdl/libui/windows/CMakeLists.txt delete mode 100644 src/libui_sdl/libui/windows/_uipriv_migrate.hpp delete mode 100644 src/libui_sdl/libui/windows/alloc.cpp delete mode 100644 src/libui_sdl/libui/windows/area.cpp delete mode 100644 src/libui_sdl/libui/windows/area.hpp delete mode 100644 src/libui_sdl/libui/windows/areadraw.cpp delete mode 100644 src/libui_sdl/libui/windows/areaevents.cpp delete mode 100644 src/libui_sdl/libui/windows/areascroll.cpp delete mode 100644 src/libui_sdl/libui/windows/areautil.cpp delete mode 100644 src/libui_sdl/libui/windows/box.cpp delete mode 100644 src/libui_sdl/libui/windows/button.cpp delete mode 100644 src/libui_sdl/libui/windows/checkbox.cpp delete mode 100644 src/libui_sdl/libui/windows/colorbutton.cpp delete mode 100644 src/libui_sdl/libui/windows/colordialog.cpp delete mode 100644 src/libui_sdl/libui/windows/combobox.cpp delete mode 100644 src/libui_sdl/libui/windows/compilerver.hpp delete mode 100644 src/libui_sdl/libui/windows/container.cpp delete mode 100644 src/libui_sdl/libui/windows/control.cpp delete mode 100644 src/libui_sdl/libui/windows/d2dscratch.cpp delete mode 100644 src/libui_sdl/libui/windows/datetimepicker.cpp delete mode 100644 src/libui_sdl/libui/windows/debug.cpp delete mode 100644 src/libui_sdl/libui/windows/draw.cpp delete mode 100644 src/libui_sdl/libui/windows/draw.hpp delete mode 100644 src/libui_sdl/libui/windows/drawmatrix.cpp delete mode 100644 src/libui_sdl/libui/windows/drawpath.cpp delete mode 100644 src/libui_sdl/libui/windows/drawtext.cpp delete mode 100644 src/libui_sdl/libui/windows/dwrite.cpp delete mode 100644 src/libui_sdl/libui/windows/editablecombo.cpp delete mode 100644 src/libui_sdl/libui/windows/entry.cpp delete mode 100644 src/libui_sdl/libui/windows/events.cpp delete mode 100644 src/libui_sdl/libui/windows/fontbutton.cpp delete mode 100644 src/libui_sdl/libui/windows/fontdialog.cpp delete mode 100644 src/libui_sdl/libui/windows/form.cpp delete mode 100644 src/libui_sdl/libui/windows/gl.cpp delete mode 100644 src/libui_sdl/libui/windows/graphemes.cpp delete mode 100644 src/libui_sdl/libui/windows/grid.cpp delete mode 100644 src/libui_sdl/libui/windows/group.cpp delete mode 100644 src/libui_sdl/libui/windows/init.cpp delete mode 100644 src/libui_sdl/libui/windows/label.cpp delete mode 100644 src/libui_sdl/libui/windows/libui.manifest delete mode 100644 src/libui_sdl/libui/windows/main.cpp delete mode 100644 src/libui_sdl/libui/windows/menu.cpp delete mode 100644 src/libui_sdl/libui/windows/multilineentry.cpp delete mode 100644 src/libui_sdl/libui/windows/notes delete mode 100644 src/libui_sdl/libui/windows/parent.cpp delete mode 100644 src/libui_sdl/libui/windows/progressbar.cpp delete mode 100644 src/libui_sdl/libui/windows/radiobuttons.cpp delete mode 100644 src/libui_sdl/libui/windows/resources.hpp delete mode 100644 src/libui_sdl/libui/windows/resources.rc delete mode 100644 src/libui_sdl/libui/windows/separator.cpp delete mode 100644 src/libui_sdl/libui/windows/sizing.cpp delete mode 100644 src/libui_sdl/libui/windows/slider.cpp delete mode 100644 src/libui_sdl/libui/windows/spinbox.cpp delete mode 100644 src/libui_sdl/libui/windows/stddialogs.cpp delete mode 100644 src/libui_sdl/libui/windows/tab.cpp delete mode 100644 src/libui_sdl/libui/windows/tabpage.cpp delete mode 100644 src/libui_sdl/libui/windows/text.cpp delete mode 100644 src/libui_sdl/libui/windows/uipriv_windows.hpp delete mode 100644 src/libui_sdl/libui/windows/utf16.cpp delete mode 100644 src/libui_sdl/libui/windows/utilwin.cpp delete mode 100644 src/libui_sdl/libui/windows/winapi.hpp delete mode 100644 src/libui_sdl/libui/windows/window.cpp delete mode 100644 src/libui_sdl/libui/windows/winpublic.cpp delete mode 100644 src/libui_sdl/libui/windows/winutil.cpp delete mode 100644 src/libui_sdl/main.cpp delete mode 100644 src/libui_sdl/main_shaders.h (limited to 'src') diff --git a/src/libui_sdl/CMakeLists.txt b/src/libui_sdl/CMakeLists.txt deleted file mode 100644 index a3a7f8a..0000000 --- a/src/libui_sdl/CMakeLists.txt +++ /dev/null @@ -1,73 +0,0 @@ -project(libui_sdl) - -SET(SOURCES_LIBUI - main.cpp - Platform.cpp - PlatformConfig.cpp - LAN_Socket.cpp - LAN_PCap.cpp - DlgAudioSettings.cpp - DlgEmuSettings.cpp - DlgInputConfig.cpp - DlgVideoSettings.cpp - DlgWifiSettings.cpp - OSD.cpp -) - -if (WIN32) - set(CMAKE_RC_COMPILE_OBJECT " -i -o ") -endif() - -option(BUILD_SHARED_LIBS "Whether to build libui as a shared library or a static library" ON) -set(BUILD_SHARED_LIBS OFF) -add_subdirectory(libui) - -find_package(PkgConfig REQUIRED) -pkg_check_modules(SDL2 REQUIRED sdl2) - -add_executable(melonDS ${SOURCES_LIBUI}) -target_include_directories(melonDS PRIVATE ${SDL2_INCLUDE_DIRS}) -target_link_libraries(melonDS core libui ${SDL2_LIBRARIES}) - -if (UNIX) - option(UNIX_PORTABLE "Make a portable build that looks for its configuration in the current directory" OFF) - if (UNIX_PORTABLE) - add_definitions(-DUNIX_PORTABLE) - endif() - - find_package(PkgConfig REQUIRED) - pkg_check_modules(GTK3 REQUIRED gtk+-3.0) - - target_include_directories(melonDS PRIVATE ${GTK3_INCLUDE_DIRS}) - target_link_libraries(melonDS ${GTK3_LIBRARIES}) - - ADD_DEFINITIONS(${GTK3_CFLAGS_OTHER}) - - add_custom_command(OUTPUT melon_grc.c - COMMAND glib-compile-resources --sourcedir=${CMAKE_SOURCE_DIR} - --target=${CMAKE_CURRENT_BINARY_DIR}/melon_grc.c - --generate-source "${CMAKE_SOURCE_DIR}/melon_grc.xml" - COMMAND glib-compile-resources --sourcedir=${CMAKE_SOURCE_DIR} - --target=${CMAKE_CURRENT_BINARY_DIR}/melon_grc.h - --generate-header "${CMAKE_SOURCE_DIR}/melon_grc.xml") - - if (CMAKE_SYSTEM_NAME STREQUAL "Linux") - target_link_libraries(melonDS dl) - endif () - - target_sources(melonDS PUBLIC melon_grc.c) -elseif (WIN32) - target_sources(melonDS PUBLIC "${CMAKE_SOURCE_DIR}/melon.rc") - target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..") - target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32) -endif () - -install(FILES ../../net.kuribo64.melonDS.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) -install(FILES ../../icon/melon_16x16.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/16x16/apps RENAME net.kuribo64.melonDS.png) -install(FILES ../../icon/melon_32x32.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/32x32/apps RENAME net.kuribo64.melonDS.png) -install(FILES ../../icon/melon_48x48.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/48x48/apps RENAME net.kuribo64.melonDS.png) -install(FILES ../../icon/melon_64x64.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/64x64/apps RENAME net.kuribo64.melonDS.png) -install(FILES ../../icon/melon_128x128.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/128x128/apps RENAME net.kuribo64.melonDS.png) -install(FILES ../../icon/melon_256x256.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/256x256/apps RENAME net.kuribo64.melonDS.png) -install(FILES ../../romlist.bin DESTINATION ${CMAKE_INSTALL_PREFIX}/share/melonDS) -install(TARGETS melonDS RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) diff --git a/src/libui_sdl/DlgAudioSettings.cpp b/src/libui_sdl/DlgAudioSettings.cpp deleted file mode 100644 index 43836ae..0000000 --- a/src/libui_sdl/DlgAudioSettings.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#include -#include -#include - -#include "libui/ui.h" - -#include "../types.h" -#include "PlatformConfig.h" - -#include "DlgAudioSettings.h" - - -void MicLoadWav(char* path); - - -namespace DlgAudioSettings -{ - -bool opened; -uiWindow* win; - -uiSlider* slVolume; -uiRadioButtons* rbMicInputType; -uiEntry* txMicWavPath; - -int oldvolume; - - -void RevertSettings() -{ - Config::AudioVolume = oldvolume; -} - - -int OnCloseWindow(uiWindow* window, void* blarg) -{ - RevertSettings(); - opened = false; - return 1; -} - -void OnVolumeChanged(uiSlider* slider, void* blarg) -{ - Config::AudioVolume = uiSliderValue(slVolume); -} - -void OnMicWavBrowse(uiButton* btn, void* blarg) -{ - char* file = uiOpenFile(win, "WAV file (*.wav)|*.wav|Any file|*.*", NULL); - if (!file) - { - return; - } - - uiEntrySetText(txMicWavPath, file); - uiFreeText(file); -} - -void OnCancel(uiButton* btn, void* blarg) -{ - RevertSettings(); - - uiControlDestroy(uiControl(win)); - opened = false; -} - -void OnOk(uiButton* btn, void* blarg) -{ - Config::AudioVolume = uiSliderValue(slVolume); - Config::MicInputType = uiRadioButtonsSelected(rbMicInputType); - - char* wavpath = uiEntryText(txMicWavPath); - strncpy(Config::MicWavPath, wavpath, 511); - uiFreeText(wavpath); - - Config::Save(); - - if (Config::MicInputType == 3) MicLoadWav(Config::MicWavPath); - - uiControlDestroy(uiControl(win)); - opened = false; -} - -void Open() -{ - if (opened) - { - uiControlSetFocus(uiControl(win)); - return; - } - - opened = true; - win = uiNewWindow("Audio settings - melonDS", 400, 100, 0, 0, 0); - uiWindowSetMargined(win, 1); - uiWindowOnClosing(win, OnCloseWindow, NULL); - - uiBox* top = uiNewVerticalBox(); - uiWindowSetChild(win, uiControl(top)); - uiBoxSetPadded(top, 1); - - { - uiGroup* grp = uiNewGroup("Audio output"); - uiBoxAppend(top, uiControl(grp), 0); - uiGroupSetMargined(grp, 1); - - uiBox* in_ctrl = uiNewVerticalBox(); - uiGroupSetChild(grp, uiControl(in_ctrl)); - - uiLabel* label_vol = uiNewLabel("Volume:"); - uiBoxAppend(in_ctrl, uiControl(label_vol), 0); - - slVolume = uiNewSlider(0, 256); - uiSliderOnChanged(slVolume, OnVolumeChanged, NULL); - uiBoxAppend(in_ctrl, uiControl(slVolume), 0); - } - - { - uiGroup* grp = uiNewGroup("Microphone input"); - uiBoxAppend(top, uiControl(grp), 0); - uiGroupSetMargined(grp, 1); - - uiBox* in_ctrl = uiNewVerticalBox(); - uiGroupSetChild(grp, uiControl(in_ctrl)); - - rbMicInputType = uiNewRadioButtons(); - uiRadioButtonsAppend(rbMicInputType, "None"); - uiRadioButtonsAppend(rbMicInputType, "Microphone"); - uiRadioButtonsAppend(rbMicInputType, "White noise"); - uiRadioButtonsAppend(rbMicInputType, "WAV file:"); - uiBoxAppend(in_ctrl, uiControl(rbMicInputType), 0); - - uiBox* path_box = uiNewHorizontalBox(); - uiBoxAppend(in_ctrl, uiControl(path_box), 0); - - txMicWavPath = uiNewEntry(); - uiBoxAppend(path_box, uiControl(txMicWavPath), 1); - - uiButton* path_browse = uiNewButton("..."); - uiButtonOnClicked(path_browse, OnMicWavBrowse, NULL); - uiBoxAppend(path_box, uiControl(path_browse), 0); - } - - { - uiBox* in_ctrl = uiNewHorizontalBox(); - uiBoxSetPadded(in_ctrl, 1); - uiBoxAppend(top, uiControl(in_ctrl), 0); - - uiLabel* dummy = uiNewLabel(""); - uiBoxAppend(in_ctrl, uiControl(dummy), 1); - - uiButton* btncancel = uiNewButton("Cancel"); - uiButtonOnClicked(btncancel, OnCancel, NULL); - uiBoxAppend(in_ctrl, uiControl(btncancel), 0); - - uiButton* btnok = uiNewButton("Ok"); - uiButtonOnClicked(btnok, OnOk, NULL); - uiBoxAppend(in_ctrl, uiControl(btnok), 0); - } - - if (Config::AudioVolume < 0) Config::AudioVolume = 0; - else if (Config::AudioVolume > 256) Config::AudioVolume = 256; - - oldvolume = Config::AudioVolume; - - uiSliderSetValue(slVolume, Config::AudioVolume); - uiRadioButtonsSetSelected(rbMicInputType, Config::MicInputType); - uiEntrySetText(txMicWavPath, Config::MicWavPath); - - uiControlShow(uiControl(win)); -} - -void Close() -{ - if (!opened) return; - uiControlDestroy(uiControl(win)); - opened = false; -} - -} diff --git a/src/libui_sdl/DlgAudioSettings.h b/src/libui_sdl/DlgAudioSettings.h deleted file mode 100644 index 7a5afcc..0000000 --- a/src/libui_sdl/DlgAudioSettings.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#ifndef DLGAUDIOSETTINGS_H -#define DLGAUDIOSETTINGS_H - -namespace DlgAudioSettings -{ - -void Open(); -void Close(); - -} - -#endif // DLGAUDIOSETTINGS_H diff --git a/src/libui_sdl/DlgEmuSettings.cpp b/src/libui_sdl/DlgEmuSettings.cpp deleted file mode 100644 index c50f216..0000000 --- a/src/libui_sdl/DlgEmuSettings.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#include -#include - -#include "libui/ui.h" - -#include "../types.h" -#include "PlatformConfig.h" - -#include "DlgEmuSettings.h" - - -void ApplyNewSettings(int type); - - -namespace DlgEmuSettings -{ - -bool opened; -uiWindow* win; - -uiCheckbox* cbDirectBoot; - - -int OnCloseWindow(uiWindow* window, void* blarg) -{ - opened = false; - return 1; -} - -void OnCancel(uiButton* btn, void* blarg) -{ - uiControlDestroy(uiControl(win)); - opened = false; -} - -void OnOk(uiButton* btn, void* blarg) -{ - Config::DirectBoot = uiCheckboxChecked(cbDirectBoot); - - Config::Save(); - - uiControlDestroy(uiControl(win)); - opened = false; -} - -void Open() -{ - if (opened) - { - uiControlSetFocus(uiControl(win)); - return; - } - - opened = true; - win = uiNewWindow("Emu settings - melonDS", 300, 200, 0, 0, 0); - uiWindowSetMargined(win, 1); - uiWindowOnClosing(win, OnCloseWindow, NULL); - - uiBox* top = uiNewVerticalBox(); - uiWindowSetChild(win, uiControl(top)); - - { - uiBox* in_ctrl = uiNewVerticalBox(); - uiBoxAppend(top, uiControl(in_ctrl), 1); - - cbDirectBoot = uiNewCheckbox("Boot game directly"); - uiBoxAppend(in_ctrl, uiControl(cbDirectBoot), 0); - } - - { - uiBox* in_ctrl = uiNewHorizontalBox(); - uiBoxSetPadded(in_ctrl, 1); - uiBoxAppend(top, uiControl(in_ctrl), 0); - - uiLabel* dummy = uiNewLabel(""); - uiBoxAppend(in_ctrl, uiControl(dummy), 1); - - uiButton* btncancel = uiNewButton("Cancel"); - uiButtonOnClicked(btncancel, OnCancel, NULL); - uiBoxAppend(in_ctrl, uiControl(btncancel), 0); - - uiButton* btnok = uiNewButton("Ok"); - uiButtonOnClicked(btnok, OnOk, NULL); - uiBoxAppend(in_ctrl, uiControl(btnok), 0); - } - - uiCheckboxSetChecked(cbDirectBoot, Config::DirectBoot); - - uiControlShow(uiControl(win)); -} - -void Close() -{ - if (!opened) return; - uiControlDestroy(uiControl(win)); - opened = false; -} - -} diff --git a/src/libui_sdl/DlgEmuSettings.h b/src/libui_sdl/DlgEmuSettings.h deleted file mode 100644 index d937448..0000000 --- a/src/libui_sdl/DlgEmuSettings.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#ifndef DLGEMUSETTINGS_H -#define DLGEMUSETTINGS_H - -namespace DlgEmuSettings -{ - -void Open(); -void Close(); - -} - -#endif // DLGEMUSETTINGS_H diff --git a/src/libui_sdl/DlgInputConfig.cpp b/src/libui_sdl/DlgInputConfig.cpp deleted file mode 100644 index f4245b4..0000000 --- a/src/libui_sdl/DlgInputConfig.cpp +++ /dev/null @@ -1,663 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#include -#include -#include - -#include -#include "libui/ui.h" - -#include "../types.h" -#include "PlatformConfig.h" - -#include "DlgInputConfig.h" - - -extern int JoystickID; -extern SDL_Joystick* Joystick; - -extern void OpenJoystick(); - - -namespace DlgInputConfig -{ - -typedef struct -{ - int type; - uiWindow* win; - - uiAreaHandler areahandler; - uiArea* keypresscatcher; - - int numkeys; - int keymap[32]; - int joymap[32]; - - int pollid; - uiButton* pollbtn; - SDL_TimerID timer; - - int axes_rest[16]; - -} InputDlgData; - - -int dskeyorder[12] = {0, 1, 10, 11, 5, 4, 6, 7, 9, 8, 3, 2}; -char dskeylabels[12][8] = {"A:", "B:", "Select:", "Start:", "Right:", "Left:", "Up:", "Down:", "R:", "L:", "X:", "Y:"}; - -int identity[32] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}; - -char hotkeylabels[HK_MAX][32] = -{ - "Close/open lid:", - "Microphone:", - "Pause/resume:", - "Reset:", - "Fast forward:", - "Fast forward (toggle):", - "Decrease sunlight (Boktai):", - "Increase sunlight (Boktai):" -}; - -int openedmask; -InputDlgData inputdlg[2]; - - -void KeyMappingName(int id, char* str) -{ - if (id < 0) - { - strcpy(str, "None"); - return; - } - - int key = id & 0xFFFF; - char* keyname = uiKeyName(key); - strncpy(str, keyname, 63); str[63] = '\0'; - uiFreeText(keyname); - - int mod = id >> 16; - - if (key == 0x11D) mod = 0; - else if (key == 0x138) mod = 0; - else if (key == 0x036) mod = 0; - - if (mod != 0) - { - // CTRL / ALT / SHIFT - const int modscan[] = {0x1D, 0x38, 0x2A}; - char tmp[64]; - - for (int m = 2; m >= 0; m--) - { - if (!(mod & (1<> 4) & 0xF) + 1; - - switch (id & 0xF) - { - case 0x1: sprintf(str, "Hat %d up", hatnum); break; - case 0x2: sprintf(str, "Hat %d right", hatnum); break; - case 0x4: sprintf(str, "Hat %d down", hatnum); break; - case 0x8: sprintf(str, "Hat %d left", hatnum); break; - } - } - else - { - sprintf(str, "Button %d", (id & 0xFFFF) + 1); - } - } - else - { - strcpy(str, ""); - } - - if (id & 0x10000) - { - int axisnum = ((id >> 24) & 0xF) + 1; - - char tmp[64]; - memcpy(tmp, str, 64); - - switch ((id >> 20) & 0xF) - { - case 0: sprintf(str, "%s%sAxis %d +", tmp, hasbtn?" / ":"", axisnum); break; - case 1: sprintf(str, "%s%sAxis %d -", tmp, hasbtn?" / ":"", axisnum); break; - case 2: sprintf(str, "%s%sTrigger %d", tmp, hasbtn?" / ":"", axisnum); break; - } - } -} - - -void OnAreaDraw(uiAreaHandler* handler, uiArea* area, uiAreaDrawParams* params) -{ -} - -void OnAreaMouseEvent(uiAreaHandler* handler, uiArea* area, uiAreaMouseEvent* evt) -{ -} - -void OnAreaMouseCrossed(uiAreaHandler* handler, uiArea* area, int left) -{ -} - -void OnAreaDragBroken(uiAreaHandler* handler, uiArea* area) -{ -} - -void OnAreaResize(uiAreaHandler* handler, uiArea* area, int width, int height) -{ -} - -int OnAreaKeyEvent(uiAreaHandler* handler, uiArea* area, uiAreaKeyEvent* evt) -{ - InputDlgData* dlg = (InputDlgData*)uiControl(area)->UserData; - - if (dlg->pollid < 0) - return 0; - - if (evt->Scancode == 0x1D) // CTRL - return 1; - if (evt->Scancode == 0x38) // ALT - return 1; - if (evt->Scancode == 0x2A) // SHIFT - return 1; - - if (dlg->pollid > 12) - { - if (dlg->pollid < 0x100) return 0; - int id = dlg->pollid & 0xFF; - if (id > 12) return 0; - if (evt->Scancode != 0x1 || evt->Modifiers != 0) // ESC - { - if (evt->Scancode == 0xE && evt->Modifiers == 0) // backspace - dlg->joymap[id] = -1; - else - return 1; - } - - char keyname[64]; - JoyMappingName(dlg->joymap[id], keyname); - uiButtonSetText(dlg->pollbtn, keyname); - uiControlEnable(uiControl(dlg->pollbtn)); - - dlg->pollid = -1; - - uiControlSetFocus(uiControl(dlg->pollbtn)); - - return 1; - } - - if (!evt->Up) - { - // set key. - if (evt->Scancode != 0x1 || evt->Modifiers != 0) // ESC - { - int mod = (dlg->type == 0) ? 0 : evt->Modifiers; - - if (evt->Scancode == 0xE && evt->Modifiers == 0) // backspace - dlg->keymap[dlg->pollid] = -1; - else - dlg->keymap[dlg->pollid] = evt->Scancode | (mod << 16); - } - - char keyname[64]; - KeyMappingName(dlg->keymap[dlg->pollid], keyname); - uiButtonSetText(dlg->pollbtn, keyname); - uiControlEnable(uiControl(dlg->pollbtn)); - - dlg->pollid = -1; - - uiControlSetFocus(uiControl(dlg->pollbtn)); - } - - return 1; -} - -void FinishJoyMapping(void* param) -{ - InputDlgData* dlg = (InputDlgData*)param; - int id = dlg->pollid & 0xFF; - - char keyname[64]; - JoyMappingName(dlg->joymap[id], keyname); - uiButtonSetText(dlg->pollbtn, keyname); - uiControlEnable(uiControl(dlg->pollbtn)); - - dlg->pollid = -1; - - uiControlSetFocus(uiControl(dlg->pollbtn)); -} - -Uint32 JoyPoll(Uint32 interval, void* param) -{ - InputDlgData* dlg = (InputDlgData*)param; - - if (dlg->pollid < 0x100) - { - dlg->timer = 0; - return 0; - } - - int id = dlg->pollid & 0xFF; - if (id > 12) - { - dlg->timer = 0; - return 0; - } - - SDL_Joystick* joy = Joystick; - if (!joy) - { - dlg->timer = 0; - return 0; - } - if (!SDL_JoystickGetAttached(joy)) - { - dlg->timer = 0; - return 0; - } - - int oldmap; - if (dlg->joymap[id] == -1) oldmap = 0xFFFF; - else oldmap = dlg->joymap[id]; - - int nbuttons = SDL_JoystickNumButtons(joy); - for (int i = 0; i < nbuttons; i++) - { - if (SDL_JoystickGetButton(joy, i)) - { - dlg->joymap[id] = (oldmap & 0xFFFF0000) | i; - uiQueueMain(FinishJoyMapping, dlg); - dlg->timer = 0; - return 0; - } - } - - int nhats = SDL_JoystickNumHats(joy); - if (nhats > 16) nhats = 16; - for (int i = 0; i < nhats; i++) - { - Uint8 blackhat = SDL_JoystickGetHat(joy, i); - if (blackhat) - { - if (blackhat & 0x1) blackhat = 0x1; - else if (blackhat & 0x2) blackhat = 0x2; - else if (blackhat & 0x4) blackhat = 0x4; - else blackhat = 0x8; - - dlg->joymap[id] = (oldmap & 0xFFFF0000) | 0x100 | blackhat | (i << 4); - uiQueueMain(FinishJoyMapping, dlg); - dlg->timer = 0; - return 0; - } - } - - int naxes = SDL_JoystickNumAxes(joy); - if (naxes > 16) naxes = 16; - for (int i = 0; i < naxes; i++) - { - Sint16 axisval = SDL_JoystickGetAxis(joy, i); - int diff = abs(axisval - dlg->axes_rest[i]); - - if (dlg->axes_rest[i] < -16384 && axisval >= 0) - { - dlg->joymap[id] = (oldmap & 0xFFFF) | 0x10000 | (2 << 20) | (i << 24); - uiQueueMain(FinishJoyMapping, dlg); - dlg->timer = 0; - return 0; - } - else if (diff > 16384) - { - int axistype; - if (axisval > 0) axistype = 0; - else axistype = 1; - - dlg->joymap[id] = (oldmap & 0xFFFF) | 0x10000 | (axistype << 20) | (i << 24); - uiQueueMain(FinishJoyMapping, dlg); - dlg->timer = 0; - return 0; - } - } - - return interval; -} - - -void OnKeyStartConfig(uiButton* btn, void* data) -{ - InputDlgData* dlg = (InputDlgData*)uiControl(btn)->UserData; - - if (dlg->pollid != -1) - { - // TODO: handle this better? - if (dlg->pollid <= 12) - uiControlSetFocus(uiControl(dlg->keypresscatcher)); - return; - } - - int id = *(int*)data; - dlg->pollid = id; - dlg->pollbtn = btn; - - uiButtonSetText(btn, "[press key]"); - uiControlDisable(uiControl(btn)); - - uiControlSetFocus(uiControl(dlg->keypresscatcher)); -} - -void OnJoyStartConfig(uiButton* btn, void* data) -{ - InputDlgData* dlg = (InputDlgData*)uiControl(btn)->UserData; - - if (dlg->pollid != -1) - { - // TODO: handle this better? - if (dlg->pollid <= 12) - uiControlSetFocus(uiControl(dlg->keypresscatcher)); - return; - } - - int naxes = SDL_JoystickNumAxes(Joystick); - if (naxes > 16) naxes = 16; - for (int a = 0; a < naxes; a++) - { - dlg->axes_rest[a] = SDL_JoystickGetAxis(Joystick, a); - } - - int id = *(int*)data; - dlg->pollid = id | 0x100; - dlg->pollbtn = btn; - - uiButtonSetText(btn, "[press button / axis]"); - uiControlDisable(uiControl(btn)); - - dlg->timer = SDL_AddTimer(100, JoyPoll, dlg); - uiControlSetFocus(uiControl(dlg->keypresscatcher)); -} - - -void OnJoystickChanged(uiCombobox* cb, void* data) -{ - JoystickID = uiComboboxSelected(cb); - OpenJoystick(); -} - - -int OnCloseWindow(uiWindow* window, void* blarg) -{ - InputDlgData* dlg = (InputDlgData*)(uiControl(window)->UserData); - openedmask &= ~(1 << dlg->type); - if (dlg->timer) SDL_RemoveTimer(dlg->timer); - - JoystickID = Config::JoystickID; - OpenJoystick(); - - return 1; -} - -void OnGetFocus(uiWindow* window, void* blarg) -{ - InputDlgData* dlg = (InputDlgData*)(uiControl(window)->UserData); - - if (dlg->pollid >= 0) - uiControlSetFocus(uiControl(dlg->keypresscatcher)); -} - -void OnLoseFocus(uiWindow* window, void* blarg) -{ -} - -void OnCancel(uiButton* btn, void* data) -{ - InputDlgData* dlg = (InputDlgData*)data; - - uiControlDestroy(uiControl(dlg->win)); - openedmask &= ~(1 << dlg->type); - if (dlg->timer) SDL_RemoveTimer(dlg->timer); - - JoystickID = Config::JoystickID; - OpenJoystick(); -} - -void OnOk(uiButton* btn, void* data) -{ - InputDlgData* dlg = (InputDlgData*)data; - - if (dlg->type == 0) - { - memcpy(Config::KeyMapping, dlg->keymap, sizeof(int)*12); - memcpy(Config::JoyMapping, dlg->joymap, sizeof(int)*12); - } - else if (dlg->type == 1) - { - memcpy(Config::HKKeyMapping, dlg->keymap, sizeof(int)*HK_MAX); - memcpy(Config::HKJoyMapping, dlg->joymap, sizeof(int)*HK_MAX); - } - - Config::JoystickID = JoystickID; - - Config::Save(); - - uiControlDestroy(uiControl(dlg->win)); - openedmask &= ~(1 << dlg->type); - if (dlg->timer) SDL_RemoveTimer(dlg->timer); -} - -void Open(int type) -{ - InputDlgData* dlg = &inputdlg[type]; - - int mask = 1 << type; - if (openedmask & mask) - { - uiControlSetFocus(uiControl(dlg->win)); - return; - } - - openedmask |= mask; - - dlg->type = type; - dlg->pollid = -1; - dlg->timer = 0; - - if (type == 0) - { - dlg->numkeys = 12; - memcpy(dlg->keymap, Config::KeyMapping, sizeof(int)*12); - memcpy(dlg->joymap, Config::JoyMapping, sizeof(int)*12); - - dlg->win = uiNewWindow("Input config - melonDS", 600, 100, 0, 0, 0); - } - else if (type == 1) - { - dlg->numkeys = HK_MAX; - memcpy(dlg->keymap, Config::HKKeyMapping, sizeof(int)*HK_MAX); - memcpy(dlg->joymap, Config::HKJoyMapping, sizeof(int)*HK_MAX); - - dlg->win = uiNewWindow("Hotkey config - melonDS", 700, 100, 0, 0, 0); - } - - uiControl(dlg->win)->UserData = dlg; - - uiWindowSetMargined(dlg->win, 1); - uiWindowOnClosing(dlg->win, OnCloseWindow, NULL); - uiWindowOnGetFocus(dlg->win, OnGetFocus, NULL); - uiWindowOnLoseFocus(dlg->win, OnLoseFocus, NULL); - - dlg->areahandler.Draw = OnAreaDraw; - dlg->areahandler.MouseEvent = OnAreaMouseEvent; - dlg->areahandler.MouseCrossed = OnAreaMouseCrossed; - dlg->areahandler.DragBroken = OnAreaDragBroken; - dlg->areahandler.KeyEvent = OnAreaKeyEvent; - dlg->areahandler.Resize = OnAreaResize; - - uiBox* top = uiNewVerticalBox(); - uiWindowSetChild(dlg->win, uiControl(top)); - uiControlHide(uiControl(top)); - - { - uiBox* in_ctrl = uiNewHorizontalBox(); - uiBoxAppend(top, uiControl(in_ctrl), 0); - uiBoxSetPadded(in_ctrl, 1); - - uiGroup* g_key = uiNewGroup("Keyboard"); - uiBoxAppend(in_ctrl, uiControl(g_key), 1); - uiGrid* b_key = uiNewGrid(); - uiGroupSetChild(g_key, uiControl(b_key)); - - const int width = 240; - - for (int i = 0; i < dlg->numkeys; i++) - { - int j = (type==0) ? dskeyorder[i] : i; - - uiLabel* label = uiNewLabel((type==0) ? dskeylabels[j] : hotkeylabels[j]); - uiGridAppend(b_key, uiControl(label), 0, i, 1, 1, 1, uiAlignStart, 1, uiAlignCenter); - uiControlSetMinSize(uiControl(label), width, 1); - - char keyname[64]; - KeyMappingName(dlg->keymap[j], keyname); - - uiButton* btn = uiNewButton(keyname); - uiControl(btn)->UserData = dlg; - uiGridAppend(b_key, uiControl(btn), 1, i, 1, 1, 1, uiAlignFill, 1, uiAlignCenter); - uiButtonOnClicked(btn, OnKeyStartConfig, (type==0) ? &dskeyorder[i] : &identity[i]); - uiControlSetMinSize(uiControl(btn), width, 1); - } - - uiGroup* g_joy = uiNewGroup("Joystick"); - uiBoxAppend(in_ctrl, uiControl(g_joy), 1); - uiGrid* b_joy = uiNewGrid(); - uiGroupSetChild(g_joy, uiControl(b_joy)); - - for (int i = 0; i < dlg->numkeys; i++) - { - int j = (type==0) ? dskeyorder[i] : i; - - uiLabel* label = uiNewLabel((type==0) ? dskeylabels[j] : hotkeylabels[j]); - uiGridAppend(b_joy, uiControl(label), 0, i, 1, 1, 1, uiAlignStart, 1, uiAlignCenter); - uiControlSetMinSize(uiControl(label), width, 1); - - char keyname[64]; - JoyMappingName(dlg->joymap[j], keyname); - - uiButton* btn = uiNewButton(keyname); - uiControl(btn)->UserData = dlg; - uiGridAppend(b_joy, uiControl(btn), 1, i, 1, 1, 1, uiAlignFill, 1, uiAlignCenter); - uiButtonOnClicked(btn, OnJoyStartConfig, (type==0) ? &dskeyorder[i] : &identity[i]); - uiControlSetMinSize(uiControl(btn), width, 1); - } - - if (type == 0) - { - uiLabel* dummy = uiNewLabel(" "); - uiGridAppend(b_key, uiControl(dummy), 0, dlg->numkeys, 2, 1, 1, uiAlignFill, 1, uiAlignCenter); - - uiCombobox* joycombo = uiNewCombobox(); - uiGridAppend(b_joy, uiControl(joycombo), 0, dlg->numkeys, 2, 1, 1, uiAlignFill, 1, uiAlignCenter); - - int numjoys = SDL_NumJoysticks(); - if (numjoys < 1) - { - uiComboboxAppend(joycombo, "(no joysticks available)"); - uiControlDisable(uiControl(joycombo)); - } - else - { - for (int i = 0; i < numjoys; i++) - { - const char* joyname = SDL_JoystickNameForIndex(i); - char fullname[256]; - snprintf(fullname, 256, "%d. %s", i+1, joyname); - - uiComboboxAppend(joycombo, fullname); - } - - uiComboboxSetSelected(joycombo, JoystickID); - uiComboboxOnSelected(joycombo, OnJoystickChanged, NULL); - } - } - } - - uiLabel* filler = uiNewLabel(""); - uiBoxAppend(top, uiControl(filler), 1); - - { - uiBox* in_ctrl = uiNewHorizontalBox(); - uiBoxSetPadded(in_ctrl, 1); - uiBoxAppend(top, uiControl(in_ctrl), 0); - - uiLabel* dummy = uiNewLabel(""); - uiBoxAppend(in_ctrl, uiControl(dummy), 1); - - dlg->keypresscatcher = uiNewArea(&dlg->areahandler); - uiControl(dlg->keypresscatcher)->UserData = dlg; - uiBoxAppend(in_ctrl, uiControl(dlg->keypresscatcher), 0); - - uiButton* btncancel = uiNewButton("Cancel"); - uiButtonOnClicked(btncancel, OnCancel, dlg); - uiBoxAppend(in_ctrl, uiControl(btncancel), 0); - - uiButton* btnok = uiNewButton("Ok"); - uiButtonOnClicked(btnok, OnOk, dlg); - uiBoxAppend(in_ctrl, uiControl(btnok), 0); - } - - uiControlShow(uiControl(top)); - - uiControlShow(uiControl(dlg->win)); -} - -void Close(int type) -{ - if (openedmask & (1< -#include -#include - -#include "libui/ui.h" - -#include "../types.h" -#include "PlatformConfig.h" - -#include "DlgVideoSettings.h" - - -void ApplyNewSettings(int type); - - -namespace DlgVideoSettings -{ - -bool opened; -uiWindow* win; - -uiRadioButtons* rbRenderer; -uiCheckbox* cbGLDisplay; -uiCheckbox* cbVSync; -uiCheckbox* cbThreaded3D; -uiCombobox* cbResolution; -uiCheckbox* cbAntialias; - -int old_renderer; -int old_gldisplay; -int old_vsync; -int old_threaded3D; -int old_resolution; -int old_antialias; - - -void UpdateControls() -{ - int renderer = uiRadioButtonsSelected(rbRenderer); - - if (renderer == 0) - { - uiControlEnable(uiControl(cbGLDisplay)); - uiControlEnable(uiControl(cbThreaded3D)); - uiControlDisable(uiControl(cbResolution)); - //uiControlDisable(uiControl(cbAntialias)); - } - else - { - uiControlDisable(uiControl(cbGLDisplay)); - uiControlDisable(uiControl(cbThreaded3D)); - uiControlEnable(uiControl(cbResolution)); - //uiControlEnable(uiControl(cbAntialias)); - } -} - -void RevertSettings() -{ - bool apply0 = false; - bool apply2 = false; - bool apply3 = false; - - bool old_usegl = (old_gldisplay != 0) || (old_renderer != 0); - bool new_usegl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); - - if (old_renderer != Config::_3DRenderer) - { - Config::_3DRenderer = old_renderer; - apply3 = true; - } - - if (old_gldisplay != Config::ScreenUseGL) - { - Config::ScreenUseGL = old_gldisplay; - } - if (old_vsync != Config::ScreenVSync) - { - Config::ScreenVSync = old_vsync; - //ApplyNewSettings(4); - } - if (old_usegl != new_usegl) - { - apply2 = true; - } - - if (old_threaded3D != Config::Threaded3D) - { - Config::Threaded3D = old_threaded3D; - apply0 = true; - } - - if (old_resolution != Config::GL_ScaleFactor || - old_antialias != Config::GL_Antialias) - { - Config::GL_ScaleFactor = old_resolution; - Config::GL_Antialias = old_antialias; - apply0 = true; - } - - if (apply2) ApplyNewSettings(2); - else if (apply3) ApplyNewSettings(3); - if (apply0) ApplyNewSettings(0); -} - - -int OnCloseWindow(uiWindow* window, void* blarg) -{ - RevertSettings(); - opened = false; - return 1; -} - -void OnRendererChanged(uiRadioButtons* rb, void* blarg) -{ - int id = uiRadioButtonsSelected(rb); - bool old_usegl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); - - Config::_3DRenderer = id; - UpdateControls(); - - bool new_usegl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); - - if (new_usegl) uiControlEnable(uiControl(cbVSync)); - else uiControlDisable(uiControl(cbVSync)); - - if (new_usegl != old_usegl) - ApplyNewSettings(2); - else - ApplyNewSettings(3); - - uiControlSetFocus(uiControl(win)); -} - -void OnGLDisplayChanged(uiCheckbox* cb, void* blarg) -{ - Config::ScreenUseGL = uiCheckboxChecked(cb); - if (Config::ScreenUseGL) uiControlEnable(uiControl(cbVSync)); - else uiControlDisable(uiControl(cbVSync)); - ApplyNewSettings(2); - uiControlSetFocus(uiControl(win)); -} - -void OnVSyncChanged(uiCheckbox* cb, void* blarg) -{ - Config::ScreenVSync = uiCheckboxChecked(cb); - //ApplyNewSettings(4); -} - -void OnThreaded3DChanged(uiCheckbox* cb, void* blarg) -{ - Config::Threaded3D = uiCheckboxChecked(cb); - ApplyNewSettings(0); -} - -void OnResolutionChanged(uiCombobox* cb, void* blarg) -{ - int id = uiComboboxSelected(cb); - - Config::GL_ScaleFactor = id+1; - ApplyNewSettings(0); -} - -void OnAntialiasChanged(uiCheckbox* cb, void* blarg) -{ - Config::GL_Antialias = uiCheckboxChecked(cb); - ApplyNewSettings(0); -} - -void OnCancel(uiButton* btn, void* blarg) -{ - RevertSettings(); - - uiControlDestroy(uiControl(win)); - opened = false; -} - -void OnOk(uiButton* btn, void* blarg) -{ - Config::Save(); - - uiControlDestroy(uiControl(win)); - opened = false; -} - -void Open() -{ - if (opened) - { - uiControlSetFocus(uiControl(win)); - return; - } - - opened = true; - win = uiNewWindow("Video settings - melonDS", 400, 100, 0, 0, 0); - uiWindowSetMargined(win, 1); - uiWindowOnClosing(win, OnCloseWindow, NULL); - - uiBox* top = uiNewVerticalBox(); - uiWindowSetChild(win, uiControl(top)); - uiBoxSetPadded(top, 1); - - uiBox* splitter = uiNewHorizontalBox(); - uiBoxAppend(top, uiControl(splitter), 0); - uiBoxSetPadded(splitter, 1); - - uiBox* left = uiNewVerticalBox(); - uiBoxAppend(splitter, uiControl(left), 1); - uiBoxSetPadded(left, 1); - uiBox* right = uiNewVerticalBox(); - uiBoxAppend(splitter, uiControl(right), 1); - uiBoxSetPadded(right, 1); - - { - uiGroup* grp = uiNewGroup("Display settings"); - uiBoxAppend(left, uiControl(grp), 0); - uiGroupSetMargined(grp, 1); - - uiBox* in_ctrl = uiNewVerticalBox(); - uiGroupSetChild(grp, uiControl(in_ctrl)); - - uiLabel* lbl = uiNewLabel("3D renderer:"); - uiBoxAppend(in_ctrl, uiControl(lbl), 0); - - rbRenderer = uiNewRadioButtons(); - uiRadioButtonsAppend(rbRenderer, "Software"); - uiRadioButtonsAppend(rbRenderer, "OpenGL"); - uiRadioButtonsOnSelected(rbRenderer, OnRendererChanged, NULL); - uiBoxAppend(in_ctrl, uiControl(rbRenderer), 0); - - lbl = uiNewLabel(""); - uiBoxAppend(in_ctrl, uiControl(lbl), 0); - - cbGLDisplay = uiNewCheckbox("OpenGL display"); - uiCheckboxOnToggled(cbGLDisplay, OnGLDisplayChanged, NULL); - uiBoxAppend(in_ctrl, uiControl(cbGLDisplay), 0); - - cbVSync = uiNewCheckbox("VSync"); - uiCheckboxOnToggled(cbVSync, OnVSyncChanged, NULL); - uiBoxAppend(in_ctrl, uiControl(cbVSync), 0); - } - - { - uiGroup* grp = uiNewGroup("Software renderer"); - uiBoxAppend(right, uiControl(grp), 0); - uiGroupSetMargined(grp, 1); - - uiBox* in_ctrl = uiNewVerticalBox(); - uiGroupSetChild(grp, uiControl(in_ctrl)); - - cbThreaded3D = uiNewCheckbox("Threaded"); - uiCheckboxOnToggled(cbThreaded3D, OnThreaded3DChanged, NULL); - uiBoxAppend(in_ctrl, uiControl(cbThreaded3D), 0); - } - - { - uiGroup* grp = uiNewGroup("OpenGL renderer"); - uiBoxAppend(right, uiControl(grp), 0); - uiGroupSetMargined(grp, 1); - - uiBox* in_ctrl = uiNewVerticalBox(); - uiGroupSetChild(grp, uiControl(in_ctrl)); - - uiLabel* lbl = uiNewLabel("Internal resolution:"); - uiBoxAppend(in_ctrl, uiControl(lbl), 0); - - cbResolution = uiNewCombobox(); - uiComboboxOnSelected(cbResolution, OnResolutionChanged, NULL); - for (int i = 1; i <= 8; i++) - { - char txt[64]; - sprintf(txt, "%dx native (%dx%d)", i, 256*i, 192*i); - uiComboboxAppend(cbResolution, txt); - } - uiBoxAppend(in_ctrl, uiControl(cbResolution), 0); - - //lbl = uiNewLabel(""); - //uiBoxAppend(in_ctrl, uiControl(lbl), 0); - - //cbAntialias = uiNewCheckbox("Antialiasing"); - //uiCheckboxOnToggled(cbAntialias, OnAntialiasChanged, NULL); - //uiBoxAppend(in_ctrl, uiControl(cbAntialias), 0); - } - - { - uiBox* in_ctrl = uiNewHorizontalBox(); - uiBoxSetPadded(in_ctrl, 1); - uiBoxAppend(top, uiControl(in_ctrl), 0); - - uiLabel* dummy = uiNewLabel(""); - uiBoxAppend(in_ctrl, uiControl(dummy), 1); - - uiButton* btncancel = uiNewButton("Cancel"); - uiButtonOnClicked(btncancel, OnCancel, NULL); - uiBoxAppend(in_ctrl, uiControl(btncancel), 0); - - uiButton* btnok = uiNewButton("Ok"); - uiButtonOnClicked(btnok, OnOk, NULL); - uiBoxAppend(in_ctrl, uiControl(btnok), 0); - } - - Config::_3DRenderer = Config::_3DRenderer ? 1 : 0; - - if (Config::GL_ScaleFactor < 1) Config::GL_ScaleFactor = 1; - else if (Config::GL_ScaleFactor > 8) Config::GL_ScaleFactor = 8; - - old_renderer = Config::_3DRenderer; - old_gldisplay = Config::ScreenUseGL; - old_vsync = Config::ScreenVSync; - old_threaded3D = Config::Threaded3D; - old_resolution = Config::GL_ScaleFactor; - old_antialias = Config::GL_Antialias; - - uiCheckboxSetChecked(cbGLDisplay, Config::ScreenUseGL); - uiCheckboxSetChecked(cbVSync, Config::ScreenVSync); - uiCheckboxSetChecked(cbThreaded3D, Config::Threaded3D); - uiComboboxSetSelected(cbResolution, Config::GL_ScaleFactor-1); - //uiCheckboxSetChecked(cbAntialias, Config::GL_Antialias); - uiRadioButtonsSetSelected(rbRenderer, Config::_3DRenderer); - UpdateControls(); - - if (Config::ScreenUseGL || Config::_3DRenderer != 0) - uiControlEnable(uiControl(cbVSync)); - else - uiControlDisable(uiControl(cbVSync)); - - uiControlShow(uiControl(win)); -} - -void Close() -{ - if (!opened) return; - uiControlDestroy(uiControl(win)); - opened = false; -} - -} diff --git a/src/libui_sdl/DlgVideoSettings.h b/src/libui_sdl/DlgVideoSettings.h deleted file mode 100644 index 17072e0..0000000 --- a/src/libui_sdl/DlgVideoSettings.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#ifndef DLGVIDEOSETTINGS_H -#define DLGVIDEOSETTINGS_H - -namespace DlgVideoSettings -{ - -void Open(); -void Close(); - -} - -#endif // DLGVIDEOSETTINGS_H diff --git a/src/libui_sdl/DlgWifiSettings.cpp b/src/libui_sdl/DlgWifiSettings.cpp deleted file mode 100644 index d1ce8bd..0000000 --- a/src/libui_sdl/DlgWifiSettings.cpp +++ /dev/null @@ -1,271 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#include -#include -#include - -#include "libui/ui.h" - -#include "../types.h" -#include "PlatformConfig.h" - -#include "LAN_Socket.h" -#include "LAN_PCap.h" -#include "DlgWifiSettings.h" - - -#ifdef __WIN32__ -#define PCAP_NAME "winpcap/npcap" -#else -#define PCAP_NAME "libpcap" -#endif // __WIN32__ - - -void ApplyNewSettings(int type); - - -namespace DlgWifiSettings -{ - -bool opened; -uiWindow* win; - -bool haspcap; - -uiCheckbox* cbBindAnyAddr; - -uiLabel* lbAdapterList; -uiCombobox* cmAdapterList; -uiCheckbox* cbDirectLAN; - -uiLabel* lbAdapterMAC; -uiLabel* lbAdapterIP; -uiLabel* lbAdapterDNS0; -uiLabel* lbAdapterDNS1; - - -void UpdateAdapterControls() -{ - bool enable = haspcap && uiCheckboxChecked(cbDirectLAN); - - if (enable) - { - uiControlEnable(uiControl(lbAdapterList)); - uiControlEnable(uiControl(cmAdapterList)); - uiControlEnable(uiControl(lbAdapterMAC)); - uiControlEnable(uiControl(lbAdapterIP)); - } - else - { - uiControlDisable(uiControl(lbAdapterList)); - uiControlDisable(uiControl(cmAdapterList)); - uiControlDisable(uiControl(lbAdapterMAC)); - uiControlDisable(uiControl(lbAdapterIP)); - } -} - -void UpdateAdapterInfo() -{ - if (!haspcap) return; - - int sel = uiComboboxSelected(cmAdapterList); - if (sel < 0 || sel >= LAN_PCap::NumAdapters) return; - if (LAN_PCap::NumAdapters < 1) return; - - LAN_PCap::AdapterData* adapter = &LAN_PCap::Adapters[sel]; - char tmp[64]; - - sprintf(tmp, "MAC: %02X:%02X:%02X:%02X:%02X:%02X", - adapter->MAC[0], adapter->MAC[1], adapter->MAC[2], - adapter->MAC[3], adapter->MAC[4], adapter->MAC[5]); - uiLabelSetText(lbAdapterMAC, tmp); - - sprintf(tmp, "IP: %d.%d.%d.%d", - adapter->IP_v4[0], adapter->IP_v4[1], - adapter->IP_v4[2], adapter->IP_v4[3]); - uiLabelSetText(lbAdapterIP, tmp); - - /*sprintf(tmp, "Primary DNS: %d.%d.%d.%d", - adapter->DNS[0][0], adapter->DNS[0][1], - adapter->DNS[0][2], adapter->DNS[0][3]); - uiLabelSetText(lbAdapterDNS0, tmp); - - sprintf(tmp, "Secondary DNS: %d.%d.%d.%d", - adapter->DNS[1][0], adapter->DNS[1][1], - adapter->DNS[1][2], adapter->DNS[1][3]); - uiLabelSetText(lbAdapterDNS1, tmp);*/ -} - -int OnCloseWindow(uiWindow* window, void* blarg) -{ - opened = false; - return 1; -} - -void OnDirectModeToggle(uiCheckbox* c, void* blarg) -{ - UpdateAdapterControls(); -} - -void OnAdapterSelect(uiCombobox* c, void* blarg) -{ - UpdateAdapterInfo(); -} - -void OnCancel(uiButton* btn, void* blarg) -{ - uiControlDestroy(uiControl(win)); - opened = false; -} - -void OnOk(uiButton* btn, void* blarg) -{ - Config::SocketBindAnyAddr = uiCheckboxChecked(cbBindAnyAddr); - Config::DirectLAN = uiCheckboxChecked(cbDirectLAN); - - int sel = uiComboboxSelected(cmAdapterList); - if (sel < 0 || sel >= LAN_PCap::NumAdapters) sel = 0; - if (LAN_PCap::NumAdapters < 1) - { - Config::LANDevice[0] = '\0'; - } - else - { - strncpy(Config::LANDevice, LAN_PCap::Adapters[sel].DeviceName, 127); - Config::LANDevice[127] = '\0'; - } - - Config::Save(); - - uiControlDestroy(uiControl(win)); - opened = false; - - ApplyNewSettings(1); -} - -void Open() -{ - if (opened) - { - uiControlSetFocus(uiControl(win)); - return; - } - - LAN_Socket::Init(); - haspcap = LAN_PCap::Init(false); - - opened = true; - win = uiNewWindow("Wifi settings - melonDS", 400, 100, 0, 0, 0); - uiWindowSetMargined(win, 1); - uiWindowOnClosing(win, OnCloseWindow, NULL); - - uiBox* top = uiNewVerticalBox(); - uiWindowSetChild(win, uiControl(top)); - uiBoxSetPadded(top, 1); - - { - uiGroup* grp = uiNewGroup("Local"); - uiBoxAppend(top, uiControl(grp), 0); - uiGroupSetMargined(grp, 1); - - uiBox* in_ctrl = uiNewVerticalBox(); - uiGroupSetChild(grp, uiControl(in_ctrl)); - - cbBindAnyAddr = uiNewCheckbox("Bind socket to any address"); - uiBoxAppend(in_ctrl, uiControl(cbBindAnyAddr), 0); - } - - { - uiLabel* lbl; - - uiGroup* grp = uiNewGroup("Online"); - uiBoxAppend(top, uiControl(grp), 0); - uiGroupSetMargined(grp, 1); - - uiBox* in_ctrl = uiNewVerticalBox(); - uiGroupSetChild(grp, uiControl(in_ctrl)); - - cbDirectLAN = uiNewCheckbox("Direct mode (requires " PCAP_NAME " and ethernet connection)"); - uiCheckboxOnToggled(cbDirectLAN, OnDirectModeToggle, NULL); - uiBoxAppend(in_ctrl, uiControl(cbDirectLAN), 0); - - lbAdapterList = uiNewLabel("Network adapter:"); - uiBoxAppend(in_ctrl, uiControl(lbAdapterList), 0); - - cmAdapterList = uiNewCombobox(); - uiComboboxOnSelected(cmAdapterList, OnAdapterSelect, NULL); - uiBoxAppend(in_ctrl, uiControl(cmAdapterList), 0); - - lbAdapterMAC = uiNewLabel("MAC: ??"); - uiBoxAppend(in_ctrl, uiControl(lbAdapterMAC), 0); - lbAdapterIP = uiNewLabel("IP: ??"); - uiBoxAppend(in_ctrl, uiControl(lbAdapterIP), 0); - /*lbAdapterDNS0 = uiNewLabel("DNS0"); - uiBoxAppend(in_ctrl, uiControl(lbAdapterDNS0), 0); - lbAdapterDNS1 = uiNewLabel("DNS1"); - uiBoxAppend(in_ctrl, uiControl(lbAdapterDNS1), 0);*/ - } - - { - uiBox* in_ctrl = uiNewHorizontalBox(); - uiBoxSetPadded(in_ctrl, 1); - uiBoxAppend(top, uiControl(in_ctrl), 0); - - uiLabel* dummy = uiNewLabel(""); - uiBoxAppend(in_ctrl, uiControl(dummy), 1); - - uiButton* btncancel = uiNewButton("Cancel"); - uiButtonOnClicked(btncancel, OnCancel, NULL); - uiBoxAppend(in_ctrl, uiControl(btncancel), 0); - - uiButton* btnok = uiNewButton("Ok"); - uiButtonOnClicked(btnok, OnOk, NULL); - uiBoxAppend(in_ctrl, uiControl(btnok), 0); - } - - uiCheckboxSetChecked(cbBindAnyAddr, Config::SocketBindAnyAddr); - - int sel = 0; - for (int i = 0; i < LAN_PCap::NumAdapters; i++) - { - LAN_PCap::AdapterData* adapter = &LAN_PCap::Adapters[i]; - - uiComboboxAppend(cmAdapterList, adapter->FriendlyName); - - if (!strncmp(adapter->DeviceName, Config::LANDevice, 128)) - sel = i; - } - uiComboboxSetSelected(cmAdapterList, sel); - UpdateAdapterInfo(); - - uiCheckboxSetChecked(cbDirectLAN, Config::DirectLAN); - if (!haspcap) uiControlDisable(uiControl(cbDirectLAN)); - UpdateAdapterControls(); - - uiControlShow(uiControl(win)); -} - -void Close() -{ - if (!opened) return; - uiControlDestroy(uiControl(win)); - opened = false; -} - -} diff --git a/src/libui_sdl/DlgWifiSettings.h b/src/libui_sdl/DlgWifiSettings.h deleted file mode 100644 index a12cbfd..0000000 --- a/src/libui_sdl/DlgWifiSettings.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#ifndef DLGWIFISETTINGS_H -#define DLGWIFISETTINGS_H - -namespace DlgWifiSettings -{ - -void Open(); -void Close(); - -} - -#endif // DLGWIFISETTINGS_H - diff --git a/src/libui_sdl/LAN_PCap.cpp b/src/libui_sdl/LAN_PCap.cpp deleted file mode 100644 index ce278bc..0000000 --- a/src/libui_sdl/LAN_PCap.cpp +++ /dev/null @@ -1,387 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -// direct LAN interface. Currently powered by libpcap, may change. - -#include -#include -#include -#include -#include -#include "../Wifi.h" -#include "LAN_PCap.h" -#include "PlatformConfig.h" - -#ifdef __WIN32__ - #include -#else - #include - #include - #include - #include -#endif - - -// welp -#ifndef PCAP_OPENFLAG_PROMISCUOUS -#define PCAP_OPENFLAG_PROMISCUOUS 1 -#endif - - -#define DECL_PCAP_FUNC(ret, name, args, args2) \ - typedef ret (*type_##name) args; \ - type_##name ptr_##name = NULL; \ - ret name args { return ptr_##name args2; } - -DECL_PCAP_FUNC(int, pcap_findalldevs, (pcap_if_t** alldevs, char* errbuf), (alldevs,errbuf)) -DECL_PCAP_FUNC(void, pcap_freealldevs, (pcap_if_t* alldevs), (alldevs)) -DECL_PCAP_FUNC(pcap_t*, pcap_open_live, (const char* src, int snaplen, int flags, int readtimeout, char* errbuf), (src,snaplen,flags,readtimeout,errbuf)) -DECL_PCAP_FUNC(void, pcap_close, (pcap_t* dev), (dev)) -DECL_PCAP_FUNC(int, pcap_setnonblock, (pcap_t* dev, int nonblock, char* errbuf), (dev,nonblock,errbuf)) -DECL_PCAP_FUNC(int, pcap_sendpacket, (pcap_t* dev, const u_char* data, int len), (dev,data,len)) -DECL_PCAP_FUNC(int, pcap_dispatch, (pcap_t* dev, int num, pcap_handler callback, u_char* data), (dev,num,callback,data)) -DECL_PCAP_FUNC(const u_char*, pcap_next, (pcap_t* dev, struct pcap_pkthdr* hdr), (dev,hdr)) - - -namespace LAN_PCap -{ - -const char* PCapLibNames[] = -{ -#ifdef __WIN32__ - // TODO: name for npcap in non-WinPCap mode - "wpcap.dll", -#else - // Linux lib names - "libpcap.so.1", - "libpcap.so", -#endif - NULL -}; - -AdapterData* Adapters = NULL; -int NumAdapters = 0; - -void* PCapLib = NULL; -pcap_t* PCapAdapter = NULL; -AdapterData* PCapAdapterData; - -u8 PacketBuffer[2048]; -int PacketLen; -volatile int RXNum; - - -#define LOAD_PCAP_FUNC(sym) \ - ptr_##sym = (type_##sym)SDL_LoadFunction(lib, #sym); \ - if (!ptr_##sym) return false; - -bool TryLoadPCap(void* lib) -{ - LOAD_PCAP_FUNC(pcap_findalldevs) - LOAD_PCAP_FUNC(pcap_freealldevs) - LOAD_PCAP_FUNC(pcap_open_live) - LOAD_PCAP_FUNC(pcap_close) - LOAD_PCAP_FUNC(pcap_setnonblock) - LOAD_PCAP_FUNC(pcap_sendpacket) - LOAD_PCAP_FUNC(pcap_dispatch) - LOAD_PCAP_FUNC(pcap_next) - - return true; -} - -bool Init(bool open_adapter) -{ - // TODO: how to deal with cases where an adapter is unplugged or changes config?? - if (!PCapLib) - { - PCapLib = NULL; - - for (int i = 0; PCapLibNames[i]; i++) - { - void* lib = SDL_LoadObject(PCapLibNames[i]); - if (!lib) continue; - - if (!TryLoadPCap(lib)) - { - SDL_UnloadObject(lib); - continue; - } - - printf("PCap: lib %s, init successful\n", PCapLibNames[i]); - PCapLib = lib; - break; - } - - if (PCapLib == NULL) - { - printf("PCap: init failed\n"); - return false; - } - } - - PCapAdapter = NULL; - PacketLen = 0; - RXNum = 0; - - NumAdapters = 0; - - char errbuf[PCAP_ERRBUF_SIZE]; - int ret; - - pcap_if_t* alldevs; - ret = pcap_findalldevs(&alldevs, errbuf); - if (ret < 0 || alldevs == NULL) - { - printf("PCap: no devices available\n"); - return false; - } - - pcap_if_t* dev = alldevs; - while (dev) { NumAdapters++; dev = dev->next; } - - Adapters = new AdapterData[NumAdapters]; - memset(Adapters, 0, sizeof(AdapterData)*NumAdapters); - - AdapterData* adata = &Adapters[0]; - dev = alldevs; - while (dev) - { - adata->Internal = dev; - -#ifdef __WIN32__ - // hax - int len = strlen(dev->name); - len -= 12; if (len > 127) len = 127; - strncpy(adata->DeviceName, &dev->name[12], len); - adata->DeviceName[len] = '\0'; -#else - strncpy(adata->DeviceName, dev->name, 127); - adata->DeviceName[127] = '\0'; - - strncpy(adata->FriendlyName, adata->DeviceName, 127); - adata->FriendlyName[127] = '\0'; -#endif // __WIN32__ - - dev = dev->next; - adata++; - } - -#ifdef __WIN32__ - - ULONG bufsize = 16384; - IP_ADAPTER_ADDRESSES* buf = (IP_ADAPTER_ADDRESSES*)HeapAlloc(GetProcessHeap(), 0, bufsize); - ULONG uret = GetAdaptersAddresses(AF_INET, 0, NULL, buf, &bufsize); - if (uret == ERROR_BUFFER_OVERFLOW) - { - HeapFree(GetProcessHeap(), 0, buf); - buf = (IP_ADAPTER_ADDRESSES*)HeapAlloc(GetProcessHeap(), 0, bufsize); - uret = GetAdaptersAddresses(AF_INET, 0, NULL, buf, &bufsize); - } - if (uret != ERROR_SUCCESS) - { - printf("GetAdaptersAddresses() shat itself: %08X\n", uret); - return false; - } - - for (int i = 0; i < NumAdapters; i++) - { - adata = &Adapters[i]; - IP_ADAPTER_ADDRESSES* addr = buf; - while (addr) - { - if (strcmp(addr->AdapterName, adata->DeviceName)) - { - addr = addr->Next; - continue; - } - - WideCharToMultiByte(CP_UTF8, 0, addr->FriendlyName, 127, adata->FriendlyName, 127, NULL, NULL); - adata->FriendlyName[127] = '\0'; - - WideCharToMultiByte(CP_UTF8, 0, addr->Description, 127, adata->Description, 127, NULL, NULL); - adata->Description[127] = '\0'; - - if (addr->PhysicalAddressLength != 6) - { - printf("weird MAC addr length %d for %s\n", addr->PhysicalAddressLength, addr->AdapterName); - } - else - memcpy(adata->MAC, addr->PhysicalAddress, 6); - - IP_ADAPTER_UNICAST_ADDRESS* ipaddr = addr->FirstUnicastAddress; - while (ipaddr) - { - SOCKADDR* sa = ipaddr->Address.lpSockaddr; - if (sa->sa_family == AF_INET) - { - struct in_addr sa4 = ((sockaddr_in*)sa)->sin_addr; - memcpy(adata->IP_v4, &sa4, 4); - } - - ipaddr = ipaddr->Next; - } - - break; - } - } - - HeapFree(GetProcessHeap(), 0, buf); - -#else - - struct ifaddrs* addrs; - if (getifaddrs(&addrs) != 0) - { - printf("getifaddrs() shat itself :(\n"); - return false; - } - - for (int i = 0; i < NumAdapters; i++) - { - adata = &Adapters[i]; - struct ifaddrs* curaddr = addrs; - while (curaddr) - { - if (strcmp(curaddr->ifa_name, adata->DeviceName)) - { - curaddr = curaddr->ifa_next; - continue; - } - - if (!curaddr->ifa_addr) - { - printf("Device (%s) does not have an address :/\n", curaddr->ifa_name); - curaddr = curaddr->ifa_next; - continue; - } - - u16 af = curaddr->ifa_addr->sa_family; - if (af == AF_INET) - { - struct sockaddr_in* sa = (sockaddr_in*)curaddr->ifa_addr; - memcpy(adata->IP_v4, &sa->sin_addr, 4); - } - else if (af == AF_PACKET) - { - struct sockaddr_ll* sa = (sockaddr_ll*)curaddr->ifa_addr; - if (sa->sll_halen != 6) - printf("weird MAC length %d for %s\n", sa->sll_halen, curaddr->ifa_name); - else - memcpy(adata->MAC, sa->sll_addr, 6); - } - - curaddr = curaddr->ifa_next; - } - } - - freeifaddrs(addrs); - -#endif // __WIN32__ - - if (!open_adapter) return true; - if (PCapAdapter) pcap_close(PCapAdapter); - - // open pcap device - PCapAdapterData = &Adapters[0]; - for (int i = 0; i < NumAdapters; i++) - { - if (!strncmp(Adapters[i].DeviceName, Config::LANDevice, 128)) - PCapAdapterData = &Adapters[i]; - } - - dev = (pcap_if_t*)PCapAdapterData->Internal; - PCapAdapter = pcap_open_live(dev->name, 2048, PCAP_OPENFLAG_PROMISCUOUS, 1, errbuf); - if (!PCapAdapter) - { - printf("PCap: failed to open adapter %s\n", errbuf); - return false; - } - - pcap_freealldevs(alldevs); - - if (pcap_setnonblock(PCapAdapter, 1, errbuf) < 0) - { - printf("PCap: failed to set nonblocking mode\n"); - pcap_close(PCapAdapter); PCapAdapter = NULL; - return false; - } - - return true; -} - -void DeInit() -{ - if (PCapLib) - { - if (PCapAdapter) - { - pcap_close(PCapAdapter); - PCapAdapter = NULL; - } - - SDL_UnloadObject(PCapLib); - PCapLib = NULL; - } -} - - -void RXCallback(u_char* blarg, const struct pcap_pkthdr* header, const u_char* data) -{ - while (RXNum > 0); - - if (header->len > 2048-64) return; - - PacketLen = header->len; - memcpy(PacketBuffer, data, PacketLen); - RXNum = 1; -} - -int SendPacket(u8* data, int len) -{ - if (PCapAdapter == NULL) - return 0; - - if (len > 2048) - { - printf("LAN_SendPacket: error: packet too long (%d)\n", len); - return 0; - } - - pcap_sendpacket(PCapAdapter, data, len); - // TODO: check success - return len; -} - -int RecvPacket(u8* data) -{ - if (PCapAdapter == NULL) - return 0; - - int ret = 0; - if (RXNum > 0) - { - memcpy(data, PacketBuffer, PacketLen); - ret = PacketLen; - RXNum = 0; - } - - pcap_dispatch(PCapAdapter, 1, RXCallback, NULL); - return ret; -} - -} diff --git a/src/libui_sdl/LAN_PCap.h b/src/libui_sdl/LAN_PCap.h deleted file mode 100644 index 250b8e9..0000000 --- a/src/libui_sdl/LAN_PCap.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#ifndef LAN_PCAP_H -#define LAN_PCAP_H - -#include "../types.h" - -namespace LAN_PCap -{ - -typedef struct -{ - char DeviceName[128]; - char FriendlyName[128]; - char Description[128]; - - u8 MAC[6]; - u8 IP_v4[4]; - - void* Internal; - -} AdapterData; - - -extern AdapterData* Adapters; -extern int NumAdapters; - - -bool Init(bool open_adapter); -void DeInit(); - -int SendPacket(u8* data, int len); -int RecvPacket(u8* data); - -} - -#endif // LAN_PCAP_H diff --git a/src/libui_sdl/LAN_Socket.cpp b/src/libui_sdl/LAN_Socket.cpp deleted file mode 100644 index c6fbd4b..0000000 --- a/src/libui_sdl/LAN_Socket.cpp +++ /dev/null @@ -1,1145 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -// indirect LAN interface, powered by BSD sockets. - -#include -#include -#include -#include "../Wifi.h" -#include "LAN_Socket.h" -#include "../Config.h" - -#ifdef __WIN32__ - #include - #include - #define socket_t SOCKET - #define sockaddr_t SOCKADDR -#else - #include - #include - #include - #include - #include - #include - #include - #define socket_t int - #define sockaddr_t struct sockaddr - #define closesocket close -#endif - -#ifndef INVALID_SOCKET -#define INVALID_SOCKET (socket_t)-1 -#endif - - -namespace LAN_Socket -{ - -const u32 kSubnet = 0x0A400000; -const u32 kServerIP = kSubnet | 0x01; -const u32 kDNSIP = kSubnet | 0x02; -const u32 kClientIP = kSubnet | 0x10; - -const u8 kServerMAC[6] = {0x00, 0xAB, 0x33, 0x28, 0x99, 0x44}; -const u8 kDNSMAC[6] = {0x00, 0xAB, 0x33, 0x28, 0x99, 0x55}; - -u8 PacketBuffer[2048]; -int PacketLen; -volatile int RXNum; - -u16 IPv4ID; - - -// TODO: UDP sockets -// * use FIFO list -// * assign new socket when seeing new IP/port - - -typedef struct -{ - u8 DestIP[4]; - u16 SourcePort; - u16 DestPort; - - u32 SeqNum; // sequence number for incoming frames - u32 AckNum; - - // 0: unused - // 1: connected - u8 Status; - - socket_t Backend; - -} TCPSocket; - -typedef struct -{ - u8 DestIP[4]; - u16 SourcePort; - u16 DestPort; - - socket_t Backend; - struct sockaddr_in BackendAddr; - -} UDPSocket; - -TCPSocket TCPSocketList[16]; -UDPSocket UDPSocketList[4]; - -int UDPSocketID = 0; - - -bool Init() -{ - // TODO: how to deal with cases where an adapter is unplugged or changes config?? - //if (PCapLib) return true; - - //Lib = NULL; - PacketLen = 0; - RXNum = 0; - - IPv4ID = 1; - - memset(TCPSocketList, 0, sizeof(TCPSocketList)); - memset(UDPSocketList, 0, sizeof(UDPSocketList)); - - UDPSocketID = 0; - - return true; -} - -void DeInit() -{ - for (int i = 0; i < (sizeof(TCPSocketList)/sizeof(TCPSocket)); i++) - { - TCPSocket* sock = &TCPSocketList[i]; - if (sock->Backend) closesocket(sock->Backend); - } - - for (int i = 0; i < (sizeof(UDPSocketList)/sizeof(UDPSocket)); i++) - { - UDPSocket* sock = &UDPSocketList[i]; - if (sock->Backend) closesocket(sock->Backend); - } -} - - -void FinishUDPFrame(u8* data, int len) -{ - u8* ipheader = &data[0xE]; - u8* udpheader = &data[0x22]; - - // lengths - *(u16*)&ipheader[2] = htons(len - 0xE); - *(u16*)&udpheader[4] = htons(len - (0xE + 0x14)); - - // IP checksum - u32 tmp = 0; - - for (int i = 0; i < 20; i += 2) - tmp += ntohs(*(u16*)&ipheader[i]); - while (tmp >> 16) - tmp = (tmp & 0xFFFF) + (tmp >> 16); - tmp ^= 0xFFFF; - *(u16*)&ipheader[10] = htons(tmp); - - // UDP checksum - // (note: normally not mandatory, but some older sgIP versions require it) - tmp = 0; - tmp += ntohs(*(u16*)&ipheader[12]); - tmp += ntohs(*(u16*)&ipheader[14]); - tmp += ntohs(*(u16*)&ipheader[16]); - tmp += ntohs(*(u16*)&ipheader[18]); - tmp += ntohs(0x1100); - tmp += (len-0x22); - for (u8* i = udpheader; i < &udpheader[len-0x23]; i += 2) - tmp += ntohs(*(u16*)i); - if (len & 1) - tmp += ntohs((u_short)udpheader[len-0x23]); - while (tmp >> 16) - tmp = (tmp & 0xFFFF) + (tmp >> 16); - tmp ^= 0xFFFF; - if (tmp == 0) tmp = 0xFFFF; - *(u16*)&udpheader[6] = htons(tmp); -} - -void FinishTCPFrame(u8* data, int len) -{ - u8* ipheader = &data[0xE]; - u8* tcpheader = &data[0x22]; - - // lengths - *(u16*)&ipheader[2] = htons(len - 0xE); - - // IP checksum - u32 tmp = 0; - - for (int i = 0; i < 20; i += 2) - tmp += ntohs(*(u16*)&ipheader[i]); - while (tmp >> 16) - tmp = (tmp & 0xFFFF) + (tmp >> 16); - tmp ^= 0xFFFF; - *(u16*)&ipheader[10] = htons(tmp); - - u32 tcplen = ntohs(*(u16*)&ipheader[2]) - 0x14; - - // TCP checksum - tmp = 0; - tmp += ntohs(*(u16*)&ipheader[12]); - tmp += ntohs(*(u16*)&ipheader[14]); - tmp += ntohs(*(u16*)&ipheader[16]); - tmp += ntohs(*(u16*)&ipheader[18]); - tmp += ntohs(0x0600); - tmp += tcplen; - for (u8* i = tcpheader; i < &tcpheader[tcplen-1]; i += 2) - tmp += ntohs(*(u16*)i); - if (tcplen & 1) - tmp += ntohs((u_short)tcpheader[tcplen-1]); - while (tmp >> 16) - tmp = (tmp & 0xFFFF) + (tmp >> 16); - tmp ^= 0xFFFF; - *(u16*)&tcpheader[16] = htons(tmp); -} - - -void HandleDHCPFrame(u8* data, int len) -{ - u8 type = 0xFF; - - u32 transid = *(u32*)&data[0x2E]; - - u8* options = &data[0x11A]; - for (;;) - { - if (options >= &data[len]) break; - u8 opt = *options++; - if (opt == 255) break; - - u8 len = *options++; - switch (opt) - { - case 53: // frame type - type = options[0]; - break; - } - - options += len; - } - - if (type == 0xFF) - { - printf("DHCP: bad frame\n"); - return; - } - - printf("DHCP: frame type %d, transid %08X\n", type, transid); - - if (type == 1 || // discover - type == 3) // request - { - u8 resp[512]; - u8* out = &resp[0]; - - // ethernet - memcpy(out, &data[6], 6); out += 6; - memcpy(out, kServerMAC, 6); out += 6; - *(u16*)out = htons(0x0800); out += 2; - - // IP - u8* ipheader = out; - *out++ = 0x45; - *out++ = 0x00; - *(u16*)out = 0; out += 2; // total length - *(u16*)out = htons(IPv4ID); out += 2; IPv4ID++; - *out++ = 0x00; - *out++ = 0x00; - *out++ = 0x80; // TTL - *out++ = 0x11; // protocol (UDP) - *(u16*)out = 0; out += 2; // checksum - *(u32*)out = htonl(kServerIP); out += 4; // source IP - if (type == 1) - { - *(u32*)out = htonl(0xFFFFFFFF); out += 4; // destination IP - } - else if (type == 3) - { - *(u32*)out = htonl(kClientIP); out += 4; // destination IP - } - - // UDP - u8* udpheader = out; - *(u16*)out = htons(67); out += 2; // source port - *(u16*)out = htons(68); out += 2; // destination port - *(u16*)out = 0; out += 2; // length - *(u16*)out = 0; out += 2; // checksum - - // DHCP - u8* body = out; - *out++ = 0x02; - *out++ = 0x01; - *out++ = 0x06; - *out++ = 0x00; - *(u32*)out = transid; out += 4; - *(u16*)out = 0; out += 2; // seconds elapsed - *(u16*)out = 0; out += 2; - *(u32*)out = htonl(0x00000000); out += 4; // client IP - *(u32*)out = htonl(kClientIP); out += 4; // your IP - *(u32*)out = htonl(kServerIP); out += 4; // server IP - *(u32*)out = htonl(0x00000000); out += 4; // gateway IP - memcpy(out, &data[6], 6); out += 6; - memset(out, 0, 10); out += 10; - memset(out, 0, 192); out += 192; - *(u32*)out = 0x63538263; out += 4; // DHCP magic - - // DHCP options - *out++ = 53; *out++ = 1; - *out++ = (type==1) ? 2 : 5; // DHCP type: offer/ack - *out++ = 1; *out++ = 4; - *(u32*)out = htonl(0xFFFFFF00); out += 4; // subnet mask - *out++ = 3; *out++ = 4; - *(u32*)out = htonl(kServerIP); out += 4; // router - *out++ = 51; *out++ = 4; - *(u32*)out = htonl(442030); out += 4; // lease time - *out++ = 54; *out++ = 4; - *(u32*)out = htonl(kServerIP); out += 4; // DHCP server - *out++ = 6; *out++ = 4; - *(u32*)out = htonl(kDNSIP); out += 4; // DNS (hax) - - *out++ = 0xFF; - memset(out, 0, 20); out += 20; - - u32 framelen = (u32)(out - &resp[0]); - if (framelen & 1) { *out++ = 0; framelen++; } - FinishUDPFrame(resp, framelen); - - // TODO: if there is already a packet queued, this will overwrite it - // that being said, this will only happen during DHCP setup, so probably - // not a big deal - - PacketLen = framelen; - memcpy(PacketBuffer, resp, PacketLen); - RXNum = 1; - } -} - -void HandleDNSFrame(u8* data, int len) -{ - u8* ipheader = &data[0xE]; - u8* udpheader = &data[0x22]; - u8* dnsbody = &data[0x2A]; - - u32 srcip = ntohl(*(u32*)&ipheader[12]); - u16 srcport = ntohs(*(u16*)&udpheader[0]); - - u16 id = ntohs(*(u16*)&dnsbody[0]); - u16 flags = ntohs(*(u16*)&dnsbody[2]); - u16 numquestions = ntohs(*(u16*)&dnsbody[4]); - u16 numanswers = ntohs(*(u16*)&dnsbody[6]); - u16 numauth = ntohs(*(u16*)&dnsbody[8]); - u16 numadd = ntohs(*(u16*)&dnsbody[10]); - - printf("DNS: ID=%04X, flags=%04X, Q=%d, A=%d, auth=%d, add=%d\n", - id, flags, numquestions, numanswers, numauth, numadd); - - // for now we only take 'simple' DNS requests - if (flags & 0x8000) return; - if (numquestions != 1 || numanswers != 0) return; - - u8 resp[1024]; - u8* out = &resp[0]; - - // ethernet - memcpy(out, &data[6], 6); out += 6; - memcpy(out, kServerMAC, 6); out += 6; - *(u16*)out = htons(0x0800); out += 2; - - // IP - u8* resp_ipheader = out; - *out++ = 0x45; - *out++ = 0x00; - *(u16*)out = 0; out += 2; // total length - *(u16*)out = htons(IPv4ID); out += 2; IPv4ID++; - *out++ = 0x00; - *out++ = 0x00; - *out++ = 0x80; // TTL - *out++ = 0x11; // protocol (UDP) - *(u16*)out = 0; out += 2; // checksum - *(u32*)out = htonl(kDNSIP); out += 4; // source IP - *(u32*)out = htonl(srcip); out += 4; // destination IP - - // UDP - u8* resp_udpheader = out; - *(u16*)out = htons(53); out += 2; // source port - *(u16*)out = htons(srcport); out += 2; // destination port - *(u16*)out = 0; out += 2; // length - *(u16*)out = 0; out += 2; // checksum - - // DNS - u8* resp_body = out; - *(u16*)out = htons(id); out += 2; // ID - *(u16*)out = htons(0x8000); out += 2; // flags - *(u16*)out = htons(numquestions); out += 2; // num questions - *(u16*)out = htons(numquestions); out += 2; // num answers - *(u16*)out = 0; out += 2; // num authority - *(u16*)out = 0; out += 2; // num additional - - u32 curoffset = 12; - for (u16 i = 0; i < numquestions; i++) - { - if (curoffset >= (len-0x2A)) return; - - u8 bitlength = 0; - while ((bitlength = dnsbody[curoffset++]) != 0) - curoffset += bitlength; - - curoffset += 4; - } - - u32 qlen = curoffset-12; - if (qlen > 512) return; - memcpy(out, &dnsbody[12], qlen); out += qlen; - - curoffset = 12; - for (u16 i = 0; i < numquestions; i++) - { - // assemble the requested domain name - u8 bitlength = 0; - char domainname[256] = ""; int o = 0; - while ((bitlength = dnsbody[curoffset++]) != 0) - { - if ((o+bitlength) >= 255) - { - // welp. atleast try not to explode. - domainname[o++] = '\0'; - break; - } - - strncpy(&domainname[o], (const char *)&dnsbody[curoffset], bitlength); - o += bitlength; - - curoffset += bitlength; - if (dnsbody[curoffset] != 0) - domainname[o++] = '.'; - else - domainname[o++] = '\0'; - } - - u16 type = ntohs(*(u16*)&dnsbody[curoffset]); - u16 cls = ntohs(*(u16*)&dnsbody[curoffset+2]); - - printf("- q%d: %04X %04X %s", i, type, cls, domainname); - - // get answer - struct addrinfo dns_hint; - struct addrinfo* dns_res; - u32 addr_res; - - memset(&dns_hint, 0, sizeof(dns_hint)); - dns_hint.ai_family = AF_INET; // TODO: other address types (INET6, etc) - if (getaddrinfo(domainname, "0", &dns_hint, &dns_res) == 0) - { - struct addrinfo* p = dns_res; - while (p) - { - struct sockaddr_in* addr = (struct sockaddr_in*)p->ai_addr; - /*printf(" -> %d.%d.%d.%d", - addr->sin_addr.S_un.S_un_b.s_b1, addr->sin_addr.S_un.S_un_b.s_b2, - addr->sin_addr.S_un.S_un_b.s_b3, addr->sin_addr.S_un.S_un_b.s_b4);*/ - - //addr_res = addr->sin_addr.S_un.S_addr; - addr_res = *(u32*)&addr->sin_addr; - p = p->ai_next; - } - } - else - { - printf(" shat itself :("); - addr_res = 0; - } - - printf("\n"); - curoffset += 4; - - // TODO: betterer support - // (under which conditions does the C00C marker work?) - *(u16*)out = htons(0xC00C); out += 2; - *(u16*)out = htons(type); out += 2; - *(u16*)out = htons(cls); out += 2; - *(u32*)out = htonl(3600); out += 4; // TTL (hardcoded for now) - *(u16*)out = htons(4); out += 2; // address length - *(u32*)out = addr_res; out += 4; // address - } - - u32 framelen = (u32)(out - &resp[0]); - if (framelen & 1) { *out++ = 0; framelen++; } - FinishUDPFrame(resp, framelen); - - // TODO: if there is already a packet queued, this will overwrite it - // that being said, this will only happen during DHCP setup, so probably - // not a big deal - - PacketLen = framelen; - memcpy(PacketBuffer, resp, PacketLen); - RXNum = 1; -} - -void UDP_BuildIncomingFrame(UDPSocket* sock, u8* data, int len) -{ - u8 resp[2048]; - u8* out = &resp[0]; - - if (len > 1536) return; - - // ethernet - memcpy(out, Wifi::GetMAC(), 6); out += 6; // hurf - memcpy(out, kServerMAC, 6); out += 6; - *(u16*)out = htons(0x0800); out += 2; - - // IP - u8* resp_ipheader = out; - *out++ = 0x45; - *out++ = 0x00; - *(u16*)out = 0; out += 2; // total length - *(u16*)out = htons(IPv4ID); out += 2; IPv4ID++; - *out++ = 0x00; - *out++ = 0x00; - *out++ = 0x80; // TTL - *out++ = 0x11; // protocol (UDP) - *(u16*)out = 0; out += 2; // checksum - memcpy(out, sock->DestIP, 4); out += 4; // source IP - *(u32*)out = htonl(kClientIP); out += 4; // destination IP - - // UDP - u8* resp_tcpheader = out; - *(u16*)out = htons(sock->DestPort); out += 2; // source port - *(u16*)out = htons(sock->SourcePort); out += 2; // destination port - *(u16*)out = htons(len+8); out += 2; // length of header+data - *(u16*)out = 0; out += 2; // checksum - - memcpy(out, data, len); out += len; - - u32 framelen = (u32)(out - &resp[0]); - FinishUDPFrame(resp, framelen); - - // TODO: if there is already a packet queued, this will overwrite it - // that being said, this will only happen during DHCP setup, so probably - // not a big deal - - PacketLen = framelen; - memcpy(PacketBuffer, resp, PacketLen); - RXNum = 1; -} - -void HandleUDPFrame(u8* data, int len) -{ - u8* ipheader = &data[0xE]; - u8* udpheader = &data[0x22]; - - // debug - /*for (int j = 0; j < len; j += 16) - { - int rem = len - j; - if (rem > 16) rem = 16; - for (int i = 0; i < rem; i++) - { - printf("%02X ", data[i+j]); - } - printf("\n"); - }*/ - - u16 srcport = ntohs(*(u16*)&udpheader[0]); - u16 dstport = ntohs(*(u16*)&udpheader[2]); - - int sockid = -1; - UDPSocket* sock; - for (int i = 0; i < (sizeof(UDPSocketList)/sizeof(UDPSocket)); i++) - { - sock = &UDPSocketList[i]; - if (sock->Backend != 0 && !memcmp(&sock->DestIP, &ipheader[16], 4) && - sock->SourcePort == srcport && sock->DestPort == dstport) - { - sockid = i; - break; - } - } - - if (sockid == -1) - { - sockid = UDPSocketID; - sock = &UDPSocketList[sockid]; - - UDPSocketID++; - if (UDPSocketID >= (sizeof(UDPSocketList)/sizeof(UDPSocket))) - UDPSocketID = 0; - - if (sock->Backend != 0) - { - printf("LANMAGIC: closing previous UDP socket #%d\n", sockid); - closesocket(sock->Backend); - } - - sock->Backend = socket(AF_INET, SOCK_DGRAM, 0); - - memcpy(sock->DestIP, &ipheader[16], 4); - sock->SourcePort = srcport; - sock->DestPort = dstport; - - memset(&sock->BackendAddr, 0, sizeof(sock->BackendAddr)); - sock->BackendAddr.sin_family = AF_INET; - sock->BackendAddr.sin_port = htons(dstport); - memcpy(&sock->BackendAddr.sin_addr, &ipheader[16], 4); - /*if (bind(sock->Backend, (struct sockaddr*)&sock->BackendAddr, sizeof(sock->BackendAddr)) == -1) - { - printf("bind() shat itself :(\n"); - }*/ - - printf("LANMAGIC: opening UDP socket #%d to %d.%d.%d.%d:%d, srcport %d\n", - sockid, - ipheader[16], ipheader[17], ipheader[18], ipheader[19], - dstport, srcport); - } - - u16 udplen = ntohs(*(u16*)&udpheader[4]) - 8; - - printf("UDP: socket %d sending %d bytes\n", sockid, udplen); - sendto(sock->Backend, (char*)&udpheader[8], udplen, 0, - (struct sockaddr*)&sock->BackendAddr, sizeof(sock->BackendAddr)); -} - -void TCP_SYNACK(TCPSocket* sock, u8* data, int len) -{ - u8 resp[128]; - u8* out = &resp[0]; - - u8* ipheader = &data[0xE]; - u8* tcpheader = &data[0x22]; - - u32 seqnum = htonl(*(u32*)&tcpheader[4]); - seqnum++; - sock->AckNum = seqnum; - - //printf("SYNACK SEQ=%08X|%08X\n", sock->SeqNum, sock->AckNum); - - // ethernet - memcpy(out, &data[6], 6); out += 6; - memcpy(out, kServerMAC, 6); out += 6; - *(u16*)out = htons(0x0800); out += 2; - - // IP - u8* resp_ipheader = out; - *out++ = 0x45; - *out++ = 0x00; - *(u16*)out = 0; out += 2; // total length - *(u16*)out = htons(IPv4ID); out += 2; IPv4ID++; - *out++ = 0x00; - *out++ = 0x00; - *out++ = 0x80; // TTL - *out++ = 0x06; // protocol (TCP) - *(u16*)out = 0; out += 2; // checksum - *(u32*)out = *(u32*)&ipheader[16]; out += 4; // source IP - *(u32*)out = *(u32*)&ipheader[12]; out += 4; // destination IP - - // TCP - u8* resp_tcpheader = out; - *(u16*)out = *(u16*)&tcpheader[2]; out += 2; // source port - *(u16*)out = *(u16*)&tcpheader[0]; out += 2; // destination port - *(u32*)out = htonl(sock->SeqNum); out += 4; sock->SeqNum++; // seq number - *(u32*)out = htonl(seqnum); out += 4; // ack seq number - *(u16*)out = htons(0x8012); out += 2; // flags (SYN+ACK) - *(u16*)out = htons(0x7000); out += 2; // window size (uuuh) - *(u16*)out = 0; out += 2; // checksum - *(u16*)out = 0; out += 2; // urgent pointer - - // TCP options - *out++ = 0x02; *out++ = 0x04; // max segment size - *(u16*)out = htons(0x05B4); out += 2; - *out++ = 0x01; - *out++ = 0x01; - *out++ = 0x04; *out++ = 0x02; // SACK permitted - *out++ = 0x01; - *out++ = 0x03; *out++ = 0x03; // window size - *out++ = 0x08; - - u32 framelen = (u32)(out - &resp[0]); - //if (framelen & 1) { *out++ = 0; framelen++; } - FinishTCPFrame(resp, framelen); - - // TODO: if there is already a packet queued, this will overwrite it - // that being said, this will only happen during DHCP setup, so probably - // not a big deal - - PacketLen = framelen; - memcpy(PacketBuffer, resp, PacketLen); - RXNum = 1; -} - -void TCP_ACK(TCPSocket* sock, bool fin) -{ - u8 resp[64]; - u8* out = &resp[0]; - - u16 flags = 0x5010; - if (fin) flags |= 0x0001; - - //printf("%sACK SEQ=%08X|%08X\n", fin?"FIN":" ", sock->SeqNum, sock->AckNum); - - // ethernet - memcpy(out, Wifi::GetMAC(), 6); out += 6; - memcpy(out, kServerMAC, 6); out += 6; - *(u16*)out = htons(0x0800); out += 2; - - // IP - u8* resp_ipheader = out; - *out++ = 0x45; - *out++ = 0x00; - *(u16*)out = 0; out += 2; // total length - *(u16*)out = htons(IPv4ID); out += 2; IPv4ID++; - *out++ = 0x00; - *out++ = 0x00; - *out++ = 0x80; // TTL - *out++ = 0x06; // protocol (TCP) - *(u16*)out = 0; out += 2; // checksum - *(u32*)out = *(u32*)&sock->DestIP; out += 4; // source IP - *(u32*)out = htonl(kClientIP); out += 4; // destination IP - - // TCP - u8* resp_tcpheader = out; - *(u16*)out = htonl(sock->DestPort); out += 2; // source port - *(u16*)out = htonl(sock->SourcePort); out += 2; // destination port - *(u32*)out = htonl(sock->SeqNum); out += 4; // seq number - *(u32*)out = htonl(sock->AckNum); out += 4; // ack seq number - *(u16*)out = htons(flags); out += 2; // flags - *(u16*)out = htons(0x7000); out += 2; // window size (uuuh) - *(u16*)out = 0; out += 2; // checksum - *(u16*)out = 0; out += 2; // urgent pointer - - u32 framelen = (u32)(out - &resp[0]); - //if (framelen & 1) { *out++ = 0; framelen++; } - FinishTCPFrame(resp, framelen); - - // TODO: if there is already a packet queued, this will overwrite it - // that being said, this will only happen during DHCP setup, so probably - // not a big deal - - PacketLen = framelen; - memcpy(PacketBuffer, resp, PacketLen); - RXNum = 1; -} - -void TCP_BuildIncomingFrame(TCPSocket* sock, u8* data, int len) -{ - u8 resp[2048]; - u8* out = &resp[0]; - - if (len > 1536) return; -//printf("INCOMING SEQ=%08X|%08X\n", sock->SeqNum, sock->AckNum); - // ethernet - memcpy(out, Wifi::GetMAC(), 6); out += 6; // hurf - memcpy(out, kServerMAC, 6); out += 6; - *(u16*)out = htons(0x0800); out += 2; - - // IP - u8* resp_ipheader = out; - *out++ = 0x45; - *out++ = 0x00; - *(u16*)out = 0; out += 2; // total length - *(u16*)out = htons(IPv4ID); out += 2; IPv4ID++; - *out++ = 0x00; - *out++ = 0x00; - *out++ = 0x80; // TTL - *out++ = 0x06; // protocol (TCP) - *(u16*)out = 0; out += 2; // checksum - memcpy(out, sock->DestIP, 4); out += 4; // source IP - *(u32*)out = htonl(kClientIP); out += 4; // destination IP - - // TCP - u8* resp_tcpheader = out; - *(u16*)out = htons(sock->DestPort); out += 2; // source port - *(u16*)out = htons(sock->SourcePort); out += 2; // destination port - *(u32*)out = htonl(sock->SeqNum); out += 4; // seq number - *(u32*)out = htonl(sock->AckNum); out += 4; // ack seq number - *(u16*)out = htons(0x5018); out += 2; // flags (ACK, PSH) - *(u16*)out = htons(0x7000); out += 2; // window size (uuuh) - *(u16*)out = 0; out += 2; // checksum - *(u16*)out = 0; out += 2; // urgent pointer - - memcpy(out, data, len); out += len; - - u32 framelen = (u32)(out - &resp[0]); - FinishTCPFrame(resp, framelen); - - // TODO: if there is already a packet queued, this will overwrite it - // that being said, this will only happen during DHCP setup, so probably - // not a big deal - - PacketLen = framelen; - memcpy(PacketBuffer, resp, PacketLen); - RXNum = 1; - - sock->SeqNum += len; -} - -void HandleTCPFrame(u8* data, int len) -{ - u8* ipheader = &data[0xE]; - u8* tcpheader = &data[0x22]; - - u16 srcport = ntohs(*(u16*)&tcpheader[0]); - u16 dstport = ntohs(*(u16*)&tcpheader[2]); - u16 flags = ntohs(*(u16*)&tcpheader[12]); - - u32 tcpheaderlen = 4 * (flags >> 12); - u32 tcplen = ntohs(*(u16*)&ipheader[2]) - 0x14; - u32 tcpdatalen = tcplen - tcpheaderlen; - - /*printf("tcpflags=%04X header=%d data=%d seq=%08X|%08X\n", - flags, tcpheaderlen, tcpdatalen, - ntohl(*(u32*)&tcpheader[4]), - ntohl(*(u32*)&tcpheader[8]));*/ - - if (flags & 0x002) // SYN - { - int sockid = -1; - TCPSocket* sock; - for (int i = 0; i < (sizeof(TCPSocketList)/sizeof(TCPSocket)); i++) - { - sock = &TCPSocketList[i]; - if (sock->Status != 0 && !memcmp(&sock->DestIP, &ipheader[16], 4) && - sock->SourcePort == srcport && sock->DestPort == dstport) - { - printf("LANMAGIC: duplicate TCP socket\n"); - sockid = i; - break; - } - } - - if (sockid == -1) - { - for (int i = 0; i < (sizeof(TCPSocketList)/sizeof(TCPSocket)); i++) - { - sock = &TCPSocketList[i]; - if (sock->Status == 0) - { - sockid = i; - break; - } - } - } - - if (sockid == -1) - { - printf("LANMAGIC: !! TCP SOCKET LIST FULL\n"); - return; - } - - printf("LANMAGIC: opening TCP socket #%d to %d.%d.%d.%d:%d, srcport %d\n", - sockid, - ipheader[16], ipheader[17], ipheader[18], ipheader[19], - dstport, srcport); - - // keep track of it - sock->Status = 1; - memcpy(sock->DestIP, &ipheader[16], 4); - sock->DestPort = dstport; - sock->SourcePort = srcport; - sock->SeqNum = 0x13370000; - sock->AckNum = 0; - - // open backend socket - if (!sock->Backend) - { - sock->Backend = socket(AF_INET, SOCK_STREAM, 0); - } - - struct sockaddr_in conn_addr; - memset(&conn_addr, 0, sizeof(conn_addr)); - conn_addr.sin_family = AF_INET; - memcpy(&conn_addr.sin_addr, &ipheader[16], 4); - conn_addr.sin_port = htons(dstport); - if (connect(sock->Backend, (sockaddr*)&conn_addr, sizeof(conn_addr)) == -1) - { - printf("connect() shat itself :(\n"); - } - else - { - // acknowledge it - TCP_SYNACK(sock, data, len); - } - } - else - { - int sockid = -1; - TCPSocket* sock; - for (int i = 0; i < (sizeof(TCPSocketList)/sizeof(TCPSocket)); i++) - { - sock = &TCPSocketList[i]; - if (sock->Status != 0 && !memcmp(&sock->DestIP, &ipheader[16], 4) && - sock->SourcePort == srcport && sock->DestPort == dstport) - { - sockid = i; - break; - } - } - - if (sockid == -1) - { - printf("LANMAGIC: bad TCP packet\n"); - return; - } - - // TODO: check those - u32 seqnum = ntohl(*(u32*)&tcpheader[4]); - u32 acknum = ntohl(*(u32*)&tcpheader[8]); - sock->SeqNum = acknum; - sock->AckNum = seqnum + tcpdatalen; - - // send data over the socket - if (tcpdatalen > 0) - { - u8* tcpdata = &tcpheader[tcpheaderlen]; - - printf("TCP: socket %d sending %d bytes (flags=%04X)\n", sockid, tcpdatalen, flags); - send(sock->Backend, (char*)tcpdata, tcpdatalen, 0); - - // kind of a hack, there - TCP_ACK(sock, false); - } - - if (flags & 0x001) // FIN - { - // TODO: timeout etc - printf("TCP: socket %d closing\n", sockid); - - sock->Status = 0; - closesocket(sock->Backend); - sock->Backend = 0; - } - } -} - -void HandleARPFrame(u8* data, int len) -{ - u16 protocol = ntohs(*(u16*)&data[0x10]); - if (protocol != 0x0800) return; - - u16 op = ntohs(*(u16*)&data[0x14]); - u32 targetip = ntohl(*(u32*)&data[0x26]); - - // TODO: handle ARP to the client - // this only handles ARP to the DHCP/router - - if (op == 1) - { - // opcode 1=req 2=reply - // sender MAC - // sender IP - // target MAC - // target IP - - const u8* targetmac; - if (targetip == kServerIP) targetmac = kServerMAC; - else if (targetip == kDNSIP) targetmac = kDNSMAC; - else return; - - u8 resp[64]; - u8* out = &resp[0]; - - // ethernet - memcpy(out, &data[6], 6); out += 6; - memcpy(out, kServerMAC, 6); out += 6; - *(u16*)out = htons(0x0806); out += 2; - - // ARP - *(u16*)out = htons(0x0001); out += 2; // hardware type - *(u16*)out = htons(0x0800); out += 2; // protocol - *out++ = 6; // MAC address size - *out++ = 4; // IP address size - *(u16*)out = htons(0x0002); out += 2; // opcode - memcpy(out, targetmac, 6); out += 6; - *(u32*)out = htonl(targetip); out += 4; - memcpy(out, &data[0x16], 6+4); out += 6+4; - - u32 framelen = (u32)(out - &resp[0]); - - // TODO: if there is already a packet queued, this will overwrite it - // that being said, this will only happen during DHCP setup, so probably - // not a big deal - - PacketLen = framelen; - memcpy(PacketBuffer, resp, PacketLen); - RXNum = 1; - } - else - { - printf("wat??\n"); - } -} - -void HandlePacket(u8* data, int len) -{ - u16 ethertype = ntohs(*(u16*)&data[0xC]); - - if (ethertype == 0x0800) // IPv4 - { - u8 protocol = data[0x17]; - if (protocol == 0x11) // UDP - { - u16 srcport = ntohs(*(u16*)&data[0x22]); - u16 dstport = ntohs(*(u16*)&data[0x24]); - if (srcport == 68 && dstport == 67) // DHCP - { - printf("LANMAGIC: DHCP packet\n"); - return HandleDHCPFrame(data, len); - } - else if (dstport == 53 && htonl(*(u32*)&data[0x1E]) == kDNSIP) // DNS - { - printf("LANMAGIC: DNS packet\n"); - return HandleDNSFrame(data, len); - } - - printf("LANMAGIC: UDP packet %d->%d\n", srcport, dstport); - return HandleUDPFrame(data, len); - } - else if (protocol == 0x06) // TCP - { - printf("LANMAGIC: TCP packet\n"); - return HandleTCPFrame(data, len); - } - else - printf("LANMAGIC: unsupported IP protocol %02X\n", protocol); - } - else if (ethertype == 0x0806) // ARP - { - printf("LANMAGIC: ARP packet\n"); - return HandleARPFrame(data, len); - } - else - printf("LANMAGIC: unsupported ethernet type %04X\n", ethertype); -} - -int SendPacket(u8* data, int len) -{ - if (len > 2048) - { - printf("LAN_SendPacket: error: packet too long (%d)\n", len); - return 0; - } - - HandlePacket(data, len); - return len; -} - -int RecvPacket(u8* data) -{ - int ret = 0; - if (RXNum > 0) - { - memcpy(data, PacketBuffer, PacketLen); - ret = PacketLen; - RXNum = 0; - } - - for (int i = 0; i < (sizeof(TCPSocketList)/sizeof(TCPSocket)); i++) - { - TCPSocket* sock = &TCPSocketList[i]; - if (sock->Status != 1) continue; - - fd_set fd; - struct timeval tv; - - FD_ZERO(&fd); - FD_SET(sock->Backend, &fd); - tv.tv_sec = 0; - tv.tv_usec = 0; - - if (!select(sock->Backend+1, &fd, 0, 0, &tv)) - { - continue; - } - - u8 recvbuf[1024]; - int recvlen = recv(sock->Backend, (char*)recvbuf, 1024, 0); - if (recvlen < 1) - { - if (recvlen == 0) - { - // socket has closed from the other side - printf("TCP: socket %d closed from other side\n", i); - sock->Status = 2; - TCP_ACK(sock, true); - } - continue; - } - - printf("TCP: socket %d receiving %d bytes\n", i, recvlen); - TCP_BuildIncomingFrame(sock, recvbuf, recvlen); - - // debug - /*for (int j = 0; j < recvlen; j += 16) - { - int rem = recvlen - j; - if (rem > 16) rem = 16; - for (int k = 0; k < rem; k++) - { - printf("%02X ", recvbuf[k+j]); - } - printf("\n"); - }*/ - - //recvlen = recv(sock->Backend, (char*)recvbuf, 1024, 0); - //if (recvlen == 0) printf("it closed immediately after\n"); - } - - for (int i = 0; i < (sizeof(UDPSocketList)/sizeof(UDPSocket)); i++) - { - UDPSocket* sock = &UDPSocketList[i]; - if (sock->Backend == 0) continue; - - fd_set fd; - struct timeval tv; - - FD_ZERO(&fd); - FD_SET(sock->Backend, &fd); - tv.tv_sec = 0; - tv.tv_usec = 0; - - if (!select(sock->Backend+1, &fd, 0, 0, &tv)) - { - continue; - } - - u8 recvbuf[1024]; - sockaddr_t fromAddr; - socklen_t fromLen = sizeof(sockaddr_t); - int recvlen = recvfrom(sock->Backend, (char*)recvbuf, 1024, 0, &fromAddr, &fromLen); - if (recvlen < 1) continue; - - if (fromAddr.sa_family != AF_INET) continue; - struct sockaddr_in* fromAddrIn = (struct sockaddr_in*)&fromAddr; - if (memcmp(&fromAddrIn->sin_addr, sock->DestIP, 4)) continue; - if (ntohs(fromAddrIn->sin_port) != sock->DestPort) continue; - - printf("UDP: socket %d receiving %d bytes\n", i, recvlen); - UDP_BuildIncomingFrame(sock, recvbuf, recvlen); - } - - return ret; -} - -} diff --git a/src/libui_sdl/LAN_Socket.h b/src/libui_sdl/LAN_Socket.h deleted file mode 100644 index 8453a5f..0000000 --- a/src/libui_sdl/LAN_Socket.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#ifndef LAN_SOCKET_H -#define LAN_SOCKET_H - -#include "../types.h" - -namespace LAN_Socket -{ - -// - - -bool Init(); -void DeInit(); - -int SendPacket(u8* data, int len); -int RecvPacket(u8* data); - -} - -#endif // LAN_SOCKET_H diff --git a/src/libui_sdl/MelonCap.cpp b/src/libui_sdl/MelonCap.cpp deleted file mode 100644 index 2658b66..0000000 --- a/src/libui_sdl/MelonCap.cpp +++ /dev/null @@ -1,347 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#include -#include -#include "MelonCap.h" -#include "libui/ui.h" -#include "../NDS.h" -#include "../GPU.h" - -#include -#include -#include -#include - - -namespace MelonCap -{ - -uiWindow* Window; -uiArea* Area; -uiAreaHandler AreaHandler; -uiDrawBitmap* WinBitmap; -bool WinBitmapInited; - -u32* WinBitmapData; - -// this crap was built from the reverse-engineering of ds_capture.exe -// mixed in with their Linux capture sample code - -GUID InterfaceClass = {0xA0B880F6, 0xD6A5, 0x4700, {0xA8, 0xEA, 0x22, 0x28, 0x2A, 0xCA, 0x55, 0x87}}; -HANDLE CapHandle; -WINUSB_INTERFACE_HANDLE CapUSBHandle; - - -void OnAreaDraw(uiAreaHandler* handler, uiArea* area, uiAreaDrawParams* params) -{ - if (!WinBitmapInited) - { - if (WinBitmap) uiDrawFreeBitmap(WinBitmap); - - WinBitmapInited = true; - WinBitmap = uiDrawNewBitmap(params->Context, 768, 384, 0); - } - - if (!WinBitmap) return; - if (!WinBitmapData) return; - - uiRect rc = {0, 0, 768, 384}; - - uiDrawBitmapUpdate(WinBitmap, WinBitmapData); - uiDrawBitmapDraw(params->Context, WinBitmap, &rc, &rc, 0); -} - -void OnAreaMouseEvent(uiAreaHandler* handler, uiArea* area, uiAreaMouseEvent* evt) -{ -} - -void OnAreaMouseCrossed(uiAreaHandler* handler, uiArea* area, int left) -{ -} - -void OnAreaDragBroken(uiAreaHandler* handler, uiArea* area) -{ -} - -int OnAreaKeyEvent(uiAreaHandler* handler, uiArea* area, uiAreaKeyEvent* evt) -{ - return 1; -} - -void OnAreaResize(uiAreaHandler* handler, uiArea* area, int width, int height) -{ -} - - -void Init() -{ - printf("MelonCap init\n"); - - HDEVINFO devinfo = SetupDiGetClassDevsW(&InterfaceClass, NULL, NULL, DIGCF_DEVICEINTERFACE|DIGCF_PRESENT); - if (devinfo == INVALID_HANDLE_VALUE) return; - - int member = 0; - bool good = false; - for (;;) - { - SP_DEVICE_INTERFACE_DATA interfacedata; - memset(&interfacedata, 0, sizeof(interfacedata)); - interfacedata.cbSize = sizeof(interfacedata); - - BOOL ret = SetupDiEnumDeviceInterfaces(devinfo, NULL, &InterfaceClass, member, &interfacedata); - if (!ret) - { - printf("found %d interfaces\n", member); - break; - } - - DWORD requiredsize = 0; - SetupDiGetDeviceInterfaceDetailW(devinfo, &interfacedata, NULL, NULL, &requiredsize, NULL); - printf("%d: required size %d\n", member, requiredsize); - - PSP_DEVICE_INTERFACE_DETAIL_DATA_W interfacedetail = (PSP_DEVICE_INTERFACE_DETAIL_DATA_W)new u8[requiredsize]; - interfacedetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA_W); - ret = SetupDiGetDeviceInterfaceDetailW(devinfo, &interfacedata, interfacedetail, requiredsize, NULL, NULL); - if (ret) - { - printf("got interface detail: path=%S\n", interfacedetail->DevicePath); - HANDLE file = CreateFileW(interfacedetail->DevicePath, GENERIC_READ|GENERIC_WRITE, - FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL); - if (file != INVALID_HANDLE_VALUE) - { - WINUSB_INTERFACE_HANDLE usbhandle; - ret = WinUsb_Initialize(file, &usbhandle); - if (ret) - { - int val; - val = 0x1E; - WinUsb_SetPipePolicy(usbhandle, 0x00, PIPE_TRANSFER_TIMEOUT, 4, &val); - val = 0x32; - WinUsb_SetPipePolicy(usbhandle, 0x82, PIPE_TRANSFER_TIMEOUT, 4, &val); - val = 0x01; - WinUsb_SetPipePolicy(usbhandle, 0x82, RAW_IO, 1, &val); - - printf("looking good\n"); - good = true; - - CapHandle = file; - CapUSBHandle = usbhandle; - } - else - CloseHandle(file); - } - } - - delete[] (u8*)interfacedetail; - - if (good) break; - - member++; - } - - SetupDiDestroyDeviceInfoList(devinfo); - - - AreaHandler.Draw = OnAreaDraw; - AreaHandler.MouseEvent = OnAreaMouseEvent; - AreaHandler.MouseCrossed = OnAreaMouseCrossed; - AreaHandler.DragBroken = OnAreaDragBroken; - AreaHandler.KeyEvent = OnAreaKeyEvent; - AreaHandler.Resize = OnAreaResize; - - WinBitmapInited = false; - WinBitmapData = new u32[768*384]; - - Window = uiNewWindow("melonDS - topnotch pixel checker", 768, 384, 0, 0, 0); - Area = uiNewArea(&AreaHandler); - uiWindowSetChild(Window, uiControl(Area)); - - uiControlShow(uiControl(Window)); -} - -void DeInit() -{ - uiControlDestroy(uiControl(Window)); - uiDrawFreeBitmap(WinBitmap); - WinBitmapInited = false; - delete[] WinBitmapData; - - WinUsb_Free(CapUSBHandle); - CloseHandle(CapHandle); -} - - -int VendorIn(u8 req, u16 len, u8* buf) -{ - WINUSB_SETUP_PACKET pkt; - pkt.RequestType = 0xC0; // device to host - pkt.Request = req; - pkt.Value = 0; // ????? - pkt.Index = 0; - pkt.Length = len; - - ULONG ret = 0; - BOOL res = WinUsb_ControlTransfer(CapUSBHandle, pkt, buf, len, &ret, NULL); - if (!res) return -1; - return ret; -} - -int VendorOut(u8 req, u16 val, u16 len, u8* buf) -{ - WINUSB_SETUP_PACKET pkt; - pkt.RequestType = 0x40; // host to device - pkt.Request = req; - pkt.Value = val; - pkt.Index = 0; - pkt.Length = len; - - ULONG ret = 0; - BOOL res = WinUsb_ControlTransfer(CapUSBHandle, pkt, buf, len, &ret, NULL); - if (!res) return -1; - return ret; -} - -int BulkIn(u8* buf, u32 len) -{ - ULONG ret = 0; - BOOL res = WinUsb_ReadPipe(CapUSBHandle, 0x82, buf, len, &ret, NULL); - if (!res) return -1; - return ret; -} - - -u32 ConvertColor(u16 col) -{ - u32 b = col & 0x001F; - u32 g = (col & 0x07E0) >> 5; - u32 r = (col & 0xF800) >> 11; - - u32 ret = 0xFF000000; - ret |= ((r << 3) | (r >> 2)) << 16; - ret |= ((g << 2) | (g >> 4)) << 8; - ret |= (b << 3) | (b >> 2); - return ret; -} - -void CaptureFrame() -{ - u32 ret; - u8 derp; - u32 framelen = 256*384*2; - u16 frame[framelen/2]; - u32 framepos = 0; - u8 frameinfo[64]; - - ret = VendorOut(0x30, 0, 0, &derp); - if (ret < 0) return; - - int tries = 0; - while (framepos < framelen) - { - ret = BulkIn((u8*)&frame[framepos/2], framelen-framepos); - if (ret < 0) break; - if (ret == 0) - { - tries++; - if (tries >= 100) break; - continue; - } - framepos += ret; - } - - ret = VendorIn(0x30, 64, frameinfo); - if (ret < 0) return; - if ((frameinfo[0] & 0x03) != 0x03) return; - if (!frameinfo[52]) return; - - u16* in = &frame[0]; - u32* out = &WinBitmapData[256]; - - for (int y = 0; y < 384; y++) - { - u32* out = &WinBitmapData[((y/2)*768) + ((y&1)*128) + 256]; - - if (!(frameinfo[y>>3] & (1<<(y&7)))) - { - continue; - } - - for (int x = 0; x < 256/2; x++) - { - out[0] = ConvertColor(in[1]); - out[768*192] = ConvertColor(in[0]); - out++; - in += 2; - } - } -} - -void Update() -{ - // melonDS output - - int frontbuf = GPU::FrontBuffer; - - u32* topbuf = GPU::Framebuffer[frontbuf][0]; - if (topbuf) - { - for (int y = 0; y < 192; y++) - { - memcpy(&WinBitmapData[y*768], &topbuf[y*256], 256*4); - } - } - - u32* botbuf = GPU::Framebuffer[frontbuf][1]; - if (botbuf) - { - for (int y = 0; y < 192; y++) - { - memcpy(&WinBitmapData[(y+192)*768], &botbuf[y*256], 256*4); - } - } - - // DS capture - - CaptureFrame(); - - // compare - - for (int y = 0; y < 384; y++) - { - for (int x = 0; x < 256; x++) - { - u32 colA = WinBitmapData[(y*768) + x + 0]; - u32 colB = WinBitmapData[(y*768) + x + 256]; - - // best we get from the capture card is RGB565 - // so we'll ignore the lower bits - const u32 mask = 0x00F8FCF8; - colA &= mask; - colB &= mask; - - if (colA == colB) WinBitmapData[(y*768) + x + 512] = 0xFF000000;//0xFF00FF00; - else WinBitmapData[(y*768) + x + 512] = 0xFFFFFFFF;//0xFFFF0000; - } - } - - uiAreaQueueRedrawAll(Area); -} - -} diff --git a/src/libui_sdl/MelonCap.h b/src/libui_sdl/MelonCap.h deleted file mode 100644 index 33a391b..0000000 --- a/src/libui_sdl/MelonCap.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#ifndef MELONCAP_H -#define MELONCAP_H - -#include "types.h" - -namespace MelonCap -{ - -void Init(); -void DeInit(); - -void Update(); - -} - -#endif // MELONCAP_H diff --git a/src/libui_sdl/OSD.cpp b/src/libui_sdl/OSD.cpp deleted file mode 100644 index a01e39b..0000000 --- a/src/libui_sdl/OSD.cpp +++ /dev/null @@ -1,435 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#include -#include -#include -#include -#include "../types.h" - -#include "libui/ui.h" -#include "../OpenGLSupport.h" - -#include "OSD.h" -#include "font.h" - -#include "PlatformConfig.h" - -extern int WindowWidth, WindowHeight; - -namespace OSD -{ - -const u32 kOSDMargin = 6; - -struct Item -{ - Uint32 Timestamp; - char Text[256]; - u32 Color; - - u32 Width, Height; - u32* Bitmap; - - bool DrawBitmapLoaded; - uiDrawBitmap* DrawBitmap; - - bool GLTextureLoaded; - GLuint GLTexture; - -}; - -std::deque ItemQueue; - -GLint uOSDPos, uOSDSize; -GLuint OSDVertexArray; -GLuint OSDVertexBuffer; - -volatile bool Rendering; - - -bool Init(bool opengl) -{ - if (opengl) - { - GLuint prog; glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)&prog); - uOSDPos = glGetUniformLocation(prog, "uOSDPos"); - uOSDSize = glGetUniformLocation(prog, "uOSDSize"); - - float vertices[6*2] = - { - 0, 0, - 1, 1, - 1, 0, - 0, 0, - 0, 1, - 1, 1 - }; - - glGenBuffers(1, &OSDVertexBuffer); - glBindBuffer(GL_ARRAY_BUFFER, OSDVertexBuffer); - glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); - - glGenVertexArrays(1, &OSDVertexArray); - glBindVertexArray(OSDVertexArray); - glEnableVertexAttribArray(0); // position - glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (void*)(0)); - } - - return true; -} - -void DeInit(bool opengl) -{ - for (auto it = ItemQueue.begin(); it != ItemQueue.end(); ) - { - Item& item = *it; - - if (item.DrawBitmapLoaded && item.DrawBitmap) uiDrawFreeBitmap(item.DrawBitmap); - if (item.GLTextureLoaded && opengl) glDeleteTextures(1, &item.GLTexture); - if (item.Bitmap) delete[] item.Bitmap; - - it = ItemQueue.erase(it); - } -} - - -int FindBreakPoint(const char* text, int i) -{ - // i = character that went out of bounds - - for (int j = i; j >= 0; j--) - { - if (text[j] == ' ') - return j; - } - - return i; -} - -void LayoutText(const char* text, u32* width, u32* height, int* breaks) -{ - u32 w = 0; - u32 h = 14; - u32 totalw = 0; - u32 maxw = WindowWidth - (kOSDMargin*2); - int lastbreak = -1; - int numbrk = 0; - u16* ptr; - - memset(breaks, 0, sizeof(int)*64); - - for (int i = 0; text[i] != '\0'; ) - { - int glyphsize; - if (text[i] == ' ') - { - glyphsize = 6; - } - else - { - u32 ch = text[i]; - if (ch < 0x10 || ch > 0x7E) ch = 0x7F; - - ptr = &font[(ch-0x10) << 4]; - glyphsize = ptr[0]; - if (!glyphsize) glyphsize = 6; - else glyphsize += 2; // space around the character - } - - w += glyphsize; - if (w > maxw) - { - // wrap shit as needed - if (text[i] == ' ') - { - if (numbrk >= 64) break; - breaks[numbrk++] = i; - i++; - } - else - { - int brk = FindBreakPoint(text, i); - if (brk != lastbreak) i = brk; - - if (numbrk >= 64) break; - breaks[numbrk++] = i; - - lastbreak = brk; - } - - w = 0; - h += 14; - } - else - i++; - - if (w > totalw) totalw = w; - } - - *width = totalw; - *height = h; -} - -u32 RainbowColor(u32 inc) -{ - // inspired from Acmlmboard - - if (inc < 100) return 0xFFFF9B9B + (inc << 8); - else if (inc < 200) return 0xFFFFFF9B - ((inc-100) << 16); - else if (inc < 300) return 0xFF9BFF9B + (inc-200); - else if (inc < 400) return 0xFF9BFFFF - ((inc-300) << 8); - else if (inc < 500) return 0xFF9B9BFF + ((inc-400) << 16); - else return 0xFFFF9BFF - (inc-500); -} - -void RenderText(u32 color, const char* text, Item* item) -{ - u32 w, h; - int breaks[64]; - - bool rainbow = (color == 0); - u32 rainbowinc = ((text[0] * 17) + (SDL_GetTicks() * 13)) % 600; - - color |= 0xFF000000; - const u32 shadow = 0xE0000000; - - LayoutText(text, &w, &h, breaks); - - item->Width = w; - item->Height = h; - item->Bitmap = new u32[w*h]; - memset(item->Bitmap, 0, w*h*sizeof(u32)); - - u32 x = 0, y = 1; - u32 maxw = WindowWidth - (kOSDMargin*2); - int curline = 0; - u16* ptr; - - for (int i = 0; text[i] != '\0'; ) - { - int glyphsize; - if (text[i] == ' ') - { - x += 6; - } - else - { - u32 ch = text[i]; - if (ch < 0x10 || ch > 0x7E) ch = 0x7F; - - ptr = &font[(ch-0x10) << 4]; - int glyphsize = ptr[0]; - if (!glyphsize) x += 6; - else - { - x++; - - if (rainbow) - { - color = RainbowColor(rainbowinc); - rainbowinc = (rainbowinc + 30) % 600; - } - - // draw character - for (int cy = 0; cy < 12; cy++) - { - u16 val = ptr[4+cy]; - - for (int cx = 0; cx < glyphsize; cx++) - { - if (val & (1<Bitmap[((y+cy) * w) + x+cx] = color; - } - } - - x += glyphsize; - x++; - } - } - - i++; - if (breaks[curline] && i >= breaks[curline]) - { - i = breaks[curline++]; - if (text[i] == ' ') i++; - - x = 0; - y += 14; - } - } - - // shadow - for (y = 0; y < h; y++) - { - for (x = 0; x < w; x++) - { - u32 val; - - val = item->Bitmap[(y * w) + x]; - if ((val >> 24) == 0xFF) continue; - - if (x > 0) val = item->Bitmap[(y * w) + x-1]; - if (x < w-1) val |= item->Bitmap[(y * w) + x+1]; - if (y > 0) - { - if (x > 0) val |= item->Bitmap[((y-1) * w) + x-1]; - val |= item->Bitmap[((y-1) * w) + x]; - if (x < w-1) val |= item->Bitmap[((y-1) * w) + x+1]; - } - if (y < h-1) - { - if (x > 0) val |= item->Bitmap[((y+1) * w) + x-1]; - val |= item->Bitmap[((y+1) * w) + x]; - if (x < w-1) val |= item->Bitmap[((y+1) * w) + x+1]; - } - - if ((val >> 24) == 0xFF) - item->Bitmap[(y * w) + x] = shadow; - } - } -} - - -void AddMessage(u32 color, const char* text) -{ - if (!Config::ShowOSD) return; - - while (Rendering); - - Item item; - - item.Timestamp = SDL_GetTicks(); - strncpy(item.Text, text, 255); item.Text[255] = '\0'; - item.Color = color; - item.Bitmap = NULL; - - item.DrawBitmapLoaded = false; - item.GLTextureLoaded = false; - - ItemQueue.push_back(item); -} - -void WindowResized(bool opengl) -{ - /*for (auto it = ItemQueue.begin(); it != ItemQueue.end(); ) - { - Item& item = *it; - - if (item->DrawBitmapLoaded && item->DrawBitmap) uiDrawFreeBitmap(item->DrawBitmap); - //if (item->GLTextureLoaded && opengl) glDeleteTextures(1, &item->GLTexture); - - item->DrawBitmapLoaded = false; - item->GLTextureLoaded = false; - - if (item->Bitmap) delete[] item->Bitmap; - - it++; - }*/ -} - -void Update(bool opengl, uiAreaDrawParams* params) -{ - if (!Config::ShowOSD) - { - Rendering = true; - if (ItemQueue.size() > 0) DeInit(opengl); - Rendering = false; - return; - } - - Rendering = true; - - Uint32 tick_now = SDL_GetTicks(); - Uint32 tick_min = tick_now - 2500; - u32 y = kOSDMargin; - - if (opengl) - { - glBindBuffer(GL_ARRAY_BUFFER, OSDVertexBuffer); - glBindVertexArray(OSDVertexArray); - - glActiveTexture(GL_TEXTURE0); - - glEnable(GL_BLEND); - glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - } - - for (auto it = ItemQueue.begin(); it != ItemQueue.end(); ) - { - Item& item = *it; - - if (item.Timestamp < tick_min) - { - if (item.DrawBitmapLoaded && item.DrawBitmap) uiDrawFreeBitmap(item.DrawBitmap); - if (item.GLTextureLoaded && opengl) glDeleteTextures(1, &item.GLTexture); - if (item.Bitmap) delete[] item.Bitmap; - - it = ItemQueue.erase(it); - continue; - } - - if (!item.Bitmap) - { - RenderText(item.Color, item.Text, &item); - } - - if (opengl) - { - if (!item.GLTextureLoaded) - { - glGenTextures(1, &item.GLTexture); - glBindTexture(GL_TEXTURE_2D, item.GLTexture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, item.Width, item.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, item.Bitmap); - - item.GLTextureLoaded = true; - } - - glBindTexture(GL_TEXTURE_2D, item.GLTexture); - glUniform2i(uOSDPos, kOSDMargin, y); - glUniform2i(uOSDSize, item.Width, item.Height); - glDrawArrays(GL_TRIANGLES, 0, 2*3); - } - else - { - if (!item.DrawBitmapLoaded) - { - item.DrawBitmap = uiDrawNewBitmap(params->Context, item.Width, item.Height, 1); - uiDrawBitmapUpdate(item.DrawBitmap, item.Bitmap); - - item.DrawBitmapLoaded = true; - } - - uiRect rc_src = {0, 0, item.Width, item.Height}; - uiRect rc_dst = {kOSDMargin, y, item.Width, item.Height}; - - uiDrawBitmapDraw(params->Context, item.DrawBitmap, &rc_src, &rc_dst, 0); - } - - y += item.Height; - it++; - } - - Rendering = false; -} - -} diff --git a/src/libui_sdl/OSD.h b/src/libui_sdl/OSD.h deleted file mode 100644 index 12294ea..0000000 --- a/src/libui_sdl/OSD.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#ifndef OSD_H -#define OSD_H - -namespace OSD -{ - -bool Init(bool opengl); -void DeInit(bool opengl); - -void AddMessage(u32 color, const char* text); - -void WindowResized(bool opengl); -void Update(bool opengl, uiAreaDrawParams* params); - -} - -#endif // OSD_H diff --git a/src/libui_sdl/Platform.cpp b/src/libui_sdl/Platform.cpp deleted file mode 100644 index 54fa568..0000000 --- a/src/libui_sdl/Platform.cpp +++ /dev/null @@ -1,557 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#include -#include -#include -#include -#include "../Platform.h" -#include "PlatformConfig.h" -#include "LAN_Socket.h" -#include "LAN_PCap.h" -#include "libui/ui.h" -#include - -#ifdef __WIN32__ - #define NTDDI_VERSION 0x06000000 // GROSS FUCKING HACK - #include - //#include // FUCK THAT SHIT - extern "C" const GUID DECLSPEC_SELECTANY FOLDERID_RoamingAppData = {0x3eb685db, 0x65f9, 0x4cf6, {0xa0, 0x3a, 0xe3, 0xef, 0x65, 0x72, 0x9f, 0x3d}}; - #include - #include - #include - #define socket_t SOCKET - #define sockaddr_t SOCKADDR -#else - #include - #include - #include - #include - #include - #include - #define socket_t int - #define sockaddr_t struct sockaddr - #define closesocket close -#endif - -#ifndef INVALID_SOCKET -#define INVALID_SOCKET (socket_t)-1 -#endif - - -extern char* EmuDirectory; - -void Stop(bool internal); - - -namespace Platform -{ - - -typedef struct -{ - SDL_Thread* ID; - void (*Func)(); - -} ThreadData; - -int ThreadEntry(void* data) -{ - ThreadData* thread = (ThreadData*)data; - thread->Func(); - return 0; -} - - -socket_t MPSocket; -sockaddr_t MPSendAddr; -u8 PacketBuffer[2048]; - -#define NIFI_VER 1 - - -void StopEmu() -{ - Stop(true); -} - - -FILE* OpenFile(const char* path, const char* mode, bool mustexist) -{ - FILE* ret; - -#ifdef __WIN32__ - - int len = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0); - if (len < 1) return NULL; - WCHAR* fatpath = new WCHAR[len]; - int res = MultiByteToWideChar(CP_UTF8, 0, path, -1, fatpath, len); - if (res != len) { delete[] fatpath; return NULL; } // checkme? - - // this will be more than enough - WCHAR fatmode[4]; - fatmode[0] = mode[0]; - fatmode[1] = mode[1]; - fatmode[2] = mode[2]; - fatmode[3] = 0; - - if (mustexist) - { - ret = _wfopen(fatpath, L"rb"); - if (ret) ret = _wfreopen(fatpath, fatmode, ret); - } - else - ret = _wfopen(fatpath, fatmode); - - delete[] fatpath; - -#else - - if (mustexist) - { - ret = fopen(path, "rb"); - if (ret) ret = freopen(path, mode, ret); - } - else - ret = fopen(path, mode); - -#endif - - return ret; -} - -#if !defined(UNIX_PORTABLE) && !defined(__WIN32__) - -FILE* OpenLocalFile(const char* path, const char* mode) -{ - std::string fullpath; - if (path[0] == '/') - { - // If it's an absolute path, just open that. - fullpath = std::string(path); - } - else - { - // Check user configuration directory - std::string confpath = std::string(g_get_user_config_dir()) + "/melonDS/"; - g_mkdir_with_parents(confpath.c_str(), 0755); - fullpath = confpath + path; - } - - return OpenFile(fullpath.c_str(), mode, mode[0] != 'w'); -} - -FILE* OpenDataFile(const char* path) -{ - const char* melondir = "melonDS"; - const char* const* sys_dirs = g_get_system_data_dirs(); - const char* user_dir = g_get_user_data_dir(); - - // First check the user's data directory - char* fullpath = g_build_path("/", user_dir, melondir, path, NULL); - if (access(fullpath, R_OK) == 0) - { - FILE* f = fopen(fullpath, "r"); - g_free(fullpath); - return f; - } - free(fullpath); - - // Then check the system data directories - for (size_t i = 0; sys_dirs[i] != NULL; i++) - { - const char* dir = sys_dirs[i]; - char* fullpath = g_build_path("/", dir, melondir, path, NULL); - - if (access(fullpath, R_OK) == 0) - { - FILE* f = fopen(fullpath, "r"); - g_free(fullpath); - return f; - } - free(fullpath); - } - - FILE* f = fopen(path, "rb"); - if (f) return f; - - return NULL; -} - -#else - -FILE* OpenLocalFile(const char* path, const char* mode) -{ - bool relpath = false; - int pathlen = strlen(path); - -#ifdef __WIN32__ - if (pathlen > 3) - { - if (path[1] == ':' && path[2] == '\\') - return OpenFile(path, mode); - } -#else - if (pathlen > 1) - { - if (path[0] == '/') - return OpenFile(path, mode); - } -#endif - - if (pathlen >= 3) - { - if (path[0] == '.' && path[1] == '.' && (path[2] == '/' || path[2] == '\\')) - relpath = true; - } - - int emudirlen = strlen(EmuDirectory); - char* emudirpath; - if (emudirlen) - { - int len = emudirlen + 1 + pathlen + 1; - emudirpath = new char[len]; - strncpy(&emudirpath[0], EmuDirectory, emudirlen); - emudirpath[emudirlen] = '/'; - strncpy(&emudirpath[emudirlen+1], path, pathlen); - emudirpath[emudirlen+1+pathlen] = '\0'; - } - else - { - emudirpath = new char[pathlen+1]; - strncpy(&emudirpath[0], path, pathlen); - emudirpath[pathlen] = '\0'; - } - - // Locations are application directory, and AppData/melonDS on Windows or XDG_CONFIG_HOME/melonDS on Linux - - FILE* f; - - // First check current working directory - f = OpenFile(path, mode, true); - if (f) { delete[] emudirpath; return f; } - - // then emu directory - f = OpenFile(emudirpath, mode, true); - if (f) { delete[] emudirpath; return f; } - -#ifdef __WIN32__ - - // a path relative to AppData wouldn't make much sense - if (!relpath) - { - // Now check AppData - PWSTR appDataPath = NULL; - SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &appDataPath); - if (!appDataPath) - { - delete[] emudirpath; - return NULL; - } - - // this will be more than enough - WCHAR fatperm[4]; - fatperm[0] = mode[0]; - fatperm[1] = mode[1]; - fatperm[2] = mode[2]; - fatperm[3] = 0; - - int fnlen = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0); - if (fnlen < 1) { delete[] emudirpath; return NULL; } - WCHAR* wfileName = new WCHAR[fnlen]; - int res = MultiByteToWideChar(CP_UTF8, 0, path, -1, wfileName, fnlen); - if (res != fnlen) { delete[] wfileName; delete[] emudirpath; return NULL; } // checkme? - - const WCHAR* appdir = L"\\melonDS\\"; - - int pos = wcslen(appDataPath); - void* ptr = CoTaskMemRealloc(appDataPath, (pos+wcslen(appdir)+fnlen+1)*sizeof(WCHAR)); - if (!ptr) { delete[] wfileName; delete[] emudirpath; return NULL; } // oh well - appDataPath = (PWSTR)ptr; - - wcscpy(&appDataPath[pos], appdir); pos += wcslen(appdir); - wcscpy(&appDataPath[pos], wfileName); - - f = _wfopen(appDataPath, L"rb"); - if (f) f = _wfreopen(appDataPath, fatperm, f); - CoTaskMemFree(appDataPath); - delete[] wfileName; - if (f) { delete[] emudirpath; return f; } - } - -#else - - if (!relpath) - { - // Now check XDG_CONFIG_HOME - // TODO: check for memory leak there - std::string fullpath = std::string(g_get_user_config_dir()) + "/melonDS/" + path; - f = OpenFile(fullpath.c_str(), mode, true); - if (f) { delete[] emudirpath; return f; } - } - -#endif - - if (mode[0] != 'r') - { - f = OpenFile(emudirpath, mode); - if (f) { delete[] emudirpath; return f; } - } - - delete[] emudirpath; - return NULL; -} - -FILE* OpenDataFile(const char* path) -{ - return OpenLocalFile(path, "rb"); -} - -#endif - - -void* Thread_Create(void (*func)()) -{ - ThreadData* data = new ThreadData; - data->Func = func; - data->ID = SDL_CreateThread(ThreadEntry, "melonDS core thread", data); - return data; -} - -void Thread_Free(void* thread) -{ - delete (ThreadData*)thread; -} - -void Thread_Wait(void* thread) -{ - SDL_WaitThread((SDL_Thread*)((ThreadData*)thread)->ID, NULL); -} - - -void* Semaphore_Create() -{ - return SDL_CreateSemaphore(0); -} - -void Semaphore_Free(void* sema) -{ - SDL_DestroySemaphore((SDL_sem*)sema); -} - -void Semaphore_Reset(void* sema) -{ - while (SDL_SemTryWait((SDL_sem*)sema) == 0); -} - -void Semaphore_Wait(void* sema) -{ - SDL_SemWait((SDL_sem*)sema); -} - -void Semaphore_Post(void* sema) -{ - SDL_SemPost((SDL_sem*)sema); -} - - -void* GL_GetProcAddress(const char* proc) -{ - return uiGLGetProcAddress(proc); -} - - -bool MP_Init() -{ - int opt_true = 1; - int res; - -#ifdef __WIN32__ - WSADATA wsadata; - if (WSAStartup(MAKEWORD(2, 2), &wsadata) != 0) - { - return false; - } -#endif // __WIN32__ - - MPSocket = socket(AF_INET, SOCK_DGRAM, 0); - if (MPSocket < 0) - { - return false; - } - - res = setsockopt(MPSocket, SOL_SOCKET, SO_REUSEADDR, (const char*)&opt_true, sizeof(int)); - if (res < 0) - { - closesocket(MPSocket); - MPSocket = INVALID_SOCKET; - return false; - } - - sockaddr_t saddr; - saddr.sa_family = AF_INET; - *(u32*)&saddr.sa_data[2] = htonl(Config::SocketBindAnyAddr ? INADDR_ANY : INADDR_LOOPBACK); - *(u16*)&saddr.sa_data[0] = htons(7064); - res = bind(MPSocket, &saddr, sizeof(sockaddr_t)); - if (res < 0) - { - closesocket(MPSocket); - MPSocket = INVALID_SOCKET; - return false; - } - - res = setsockopt(MPSocket, SOL_SOCKET, SO_BROADCAST, (const char*)&opt_true, sizeof(int)); - if (res < 0) - { - closesocket(MPSocket); - MPSocket = INVALID_SOCKET; - return false; - } - - MPSendAddr.sa_family = AF_INET; - *(u32*)&MPSendAddr.sa_data[2] = htonl(INADDR_BROADCAST); - *(u16*)&MPSendAddr.sa_data[0] = htons(7064); - - return true; -} - -void MP_DeInit() -{ - if (MPSocket >= 0) - closesocket(MPSocket); - -#ifdef __WIN32__ - WSACleanup(); -#endif // __WIN32__ -} - -int MP_SendPacket(u8* data, int len) -{ - if (MPSocket < 0) - return 0; - - if (len > 2048-8) - { - printf("MP_SendPacket: error: packet too long (%d)\n", len); - return 0; - } - - *(u32*)&PacketBuffer[0] = htonl(0x4946494E); // NIFI - PacketBuffer[4] = NIFI_VER; - PacketBuffer[5] = 0; - *(u16*)&PacketBuffer[6] = htons(len); - memcpy(&PacketBuffer[8], data, len); - - int slen = sendto(MPSocket, (const char*)PacketBuffer, len+8, 0, &MPSendAddr, sizeof(sockaddr_t)); - if (slen < 8) return 0; - return slen - 8; -} - -int MP_RecvPacket(u8* data, bool block) -{ - if (MPSocket < 0) - return 0; - - fd_set fd; - struct timeval tv; - - FD_ZERO(&fd); - FD_SET(MPSocket, &fd); - tv.tv_sec = 0; - tv.tv_usec = block ? 5000 : 0; - - if (!select(MPSocket+1, &fd, 0, 0, &tv)) - { - return 0; - } - - sockaddr_t fromAddr; - socklen_t fromLen = sizeof(sockaddr_t); - int rlen = recvfrom(MPSocket, (char*)PacketBuffer, 2048, 0, &fromAddr, &fromLen); - if (rlen < 8+24) - { - return 0; - } - rlen -= 8; - - if (ntohl(*(u32*)&PacketBuffer[0]) != 0x4946494E) - { - return 0; - } - - if (PacketBuffer[4] != NIFI_VER) - { - return 0; - } - - if (ntohs(*(u16*)&PacketBuffer[6]) != rlen) - { - return 0; - } - - memcpy(data, &PacketBuffer[8], rlen); - return rlen; -} - - - -bool LAN_Init() -{ - if (Config::DirectLAN) - { - if (!LAN_PCap::Init(true)) - return false; - } - else - { - if (!LAN_Socket::Init()) - return false; - } - - return true; -} - -void LAN_DeInit() -{ - // checkme. blarg - //if (Config::DirectLAN) - // LAN_PCap::DeInit(); - //else - // LAN_Socket::DeInit(); - LAN_PCap::DeInit(); - LAN_Socket::DeInit(); -} - -int LAN_SendPacket(u8* data, int len) -{ - if (Config::DirectLAN) - return LAN_PCap::SendPacket(data, len); - else - return LAN_Socket::SendPacket(data, len); -} - -int LAN_RecvPacket(u8* data) -{ - if (Config::DirectLAN) - return LAN_PCap::RecvPacket(data); - else - return LAN_Socket::RecvPacket(data); -} - - -} diff --git a/src/libui_sdl/PlatformConfig.cpp b/src/libui_sdl/PlatformConfig.cpp deleted file mode 100644 index f78b195..0000000 --- a/src/libui_sdl/PlatformConfig.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#include -#include -#include -#include "PlatformConfig.h" - -namespace Config -{ - -int KeyMapping[12]; -int JoyMapping[12]; - -int HKKeyMapping[HK_MAX]; -int HKJoyMapping[HK_MAX]; - -int JoystickID; - -int WindowWidth; -int WindowHeight; -int WindowMaximized; - -int ScreenRotation; -int ScreenGap; -int ScreenLayout; -int ScreenSizing; -int ScreenFilter; - -int ScreenUseGL; -int ScreenVSync; -int ScreenRatio; - -int LimitFPS; -int AudioSync; -int ShowOSD; - -int DirectBoot; - -int SocketBindAnyAddr; -char LANDevice[128]; -int DirectLAN; - -int SavestateRelocSRAM; - -int AudioVolume; -int MicInputType; -char MicWavPath[512]; - -char LastROMFolder[512]; - - -ConfigEntry PlatformConfigFile[] = -{ - {"Key_A", 0, &KeyMapping[0], 32, NULL, 0}, - {"Key_B", 0, &KeyMapping[1], 31, NULL, 0}, - {"Key_Select", 0, &KeyMapping[2], 57, NULL, 0}, - {"Key_Start", 0, &KeyMapping[3], 28, NULL, 0}, - {"Key_Right", 0, &KeyMapping[4], 333, NULL, 0}, - {"Key_Left", 0, &KeyMapping[5], 331, NULL, 0}, - {"Key_Up", 0, &KeyMapping[6], 328, NULL, 0}, - {"Key_Down", 0, &KeyMapping[7], 336, NULL, 0}, - {"Key_R", 0, &KeyMapping[8], 54, NULL, 0}, - {"Key_L", 0, &KeyMapping[9], 86, NULL, 0}, - {"Key_X", 0, &KeyMapping[10], 17, NULL, 0}, - {"Key_Y", 0, &KeyMapping[11], 30, NULL, 0}, - - {"Joy_A", 0, &JoyMapping[0], -1, NULL, 0}, - {"Joy_B", 0, &JoyMapping[1], -1, NULL, 0}, - {"Joy_Select", 0, &JoyMapping[2], -1, NULL, 0}, - {"Joy_Start", 0, &JoyMapping[3], -1, NULL, 0}, - {"Joy_Right", 0, &JoyMapping[4], -1, NULL, 0}, - {"Joy_Left", 0, &JoyMapping[5], -1, NULL, 0}, - {"Joy_Up", 0, &JoyMapping[6], -1, NULL, 0}, - {"Joy_Down", 0, &JoyMapping[7], -1, NULL, 0}, - {"Joy_R", 0, &JoyMapping[8], -1, NULL, 0}, - {"Joy_L", 0, &JoyMapping[9], -1, NULL, 0}, - {"Joy_X", 0, &JoyMapping[10], -1, NULL, 0}, - {"Joy_Y", 0, &JoyMapping[11], -1, NULL, 0}, - - {"HKKey_Lid", 0, &HKKeyMapping[HK_Lid], 0x0D, NULL, 0}, - {"HKKey_Mic", 0, &HKKeyMapping[HK_Mic], 0x35, NULL, 0}, - {"HKKey_Pause", 0, &HKKeyMapping[HK_Pause], -1, NULL, 0}, - {"HKKey_Reset", 0, &HKKeyMapping[HK_Reset], -1, NULL, 0}, - {"HKKey_FastForward", 0, &HKKeyMapping[HK_FastForward], 0x0F, NULL, 0}, - {"HKKey_FastForwardToggle", 0, &HKKeyMapping[HK_FastForwardToggle], -1, NULL, 0}, - {"HKKey_SolarSensorDecrease", 0, &HKKeyMapping[HK_SolarSensorDecrease], 0x4B, NULL, 0}, - {"HKKey_SolarSensorIncrease", 0, &HKKeyMapping[HK_SolarSensorIncrease], 0x4D, NULL, 0}, - - {"HKJoy_Lid", 0, &HKJoyMapping[HK_Lid], -1, NULL, 0}, - {"HKJoy_Mic", 0, &HKJoyMapping[HK_Mic], -1, NULL, 0}, - {"HKJoy_Pause", 0, &HKJoyMapping[HK_Pause], -1, NULL, 0}, - {"HKJoy_Reset", 0, &HKJoyMapping[HK_Reset], -1, NULL, 0}, - {"HKJoy_FastForward", 0, &HKJoyMapping[HK_FastForward], -1, NULL, 0}, - {"HKJoy_FastForwardToggle", 0, &HKJoyMapping[HK_FastForwardToggle], -1, NULL, 0}, - {"HKJoy_SolarSensorDecrease", 0, &HKJoyMapping[HK_SolarSensorDecrease], -1, NULL, 0}, - {"HKJoy_SolarSensorIncrease", 0, &HKJoyMapping[HK_SolarSensorIncrease], -1, NULL, 0}, - - {"JoystickID", 0, &JoystickID, 0, NULL, 0}, - - {"WindowWidth", 0, &WindowWidth, 256, NULL, 0}, - {"WindowHeight", 0, &WindowHeight, 384, NULL, 0}, - {"WindowMax", 0, &WindowMaximized, 0, NULL, 0}, - - {"ScreenRotation", 0, &ScreenRotation, 0, NULL, 0}, - {"ScreenGap", 0, &ScreenGap, 0, NULL, 0}, - {"ScreenLayout", 0, &ScreenLayout, 0, NULL, 0}, - {"ScreenSizing", 0, &ScreenSizing, 0, NULL, 0}, - {"ScreenFilter", 0, &ScreenFilter, 1, NULL, 0}, - - {"ScreenUseGL", 0, &ScreenUseGL, 1, NULL, 0}, - {"ScreenVSync", 0, &ScreenVSync, 0, NULL, 0}, - {"ScreenRatio", 0, &ScreenRatio, 0, NULL, 0}, - - {"LimitFPS", 0, &LimitFPS, 0, NULL, 0}, - {"AudioSync", 0, &AudioSync, 1, NULL, 0}, - {"ShowOSD", 0, &ShowOSD, 1, NULL, 0}, - - {"DirectBoot", 0, &DirectBoot, 1, NULL, 0}, - - {"SockBindAnyAddr", 0, &SocketBindAnyAddr, 0, NULL, 0}, - {"LANDevice", 1, LANDevice, 0, "", 127}, - {"DirectLAN", 0, &DirectLAN, 0, NULL, 0}, - - {"SavStaRelocSRAM", 0, &SavestateRelocSRAM, 0, NULL, 0}, - - {"AudioVolume", 0, &AudioVolume, 256, NULL, 0}, - {"MicInputType", 0, &MicInputType, 1, NULL, 0}, - {"MicWavPath", 1, MicWavPath, 0, "", 511}, - - {"LastROMFolder", 1, LastROMFolder, 0, "", 511}, - - {"", -1, NULL, 0, NULL, 0} -}; - -} diff --git a/src/libui_sdl/PlatformConfig.h b/src/libui_sdl/PlatformConfig.h deleted file mode 100644 index 9e02862..0000000 --- a/src/libui_sdl/PlatformConfig.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#ifndef PLATFORMCONFIG_H -#define PLATFORMCONFIG_H - -#include "../Config.h" - -enum -{ - HK_Lid = 0, - HK_Mic, - HK_Pause, - HK_Reset, - HK_FastForward, - HK_FastForwardToggle, - HK_SolarSensorDecrease, - HK_SolarSensorIncrease, - HK_MAX -}; - -namespace Config -{ - -extern int KeyMapping[12]; -extern int JoyMapping[12]; - -extern int HKKeyMapping[HK_MAX]; -extern int HKJoyMapping[HK_MAX]; - -extern int JoystickID; - -extern int WindowWidth; -extern int WindowHeight; -extern int WindowMaximized; - -extern int ScreenRotation; -extern int ScreenGap; -extern int ScreenLayout; -extern int ScreenSizing; -extern int ScreenFilter; - -extern int ScreenUseGL; -extern int ScreenVSync; -extern int ScreenRatio; - -extern int LimitFPS; -extern int AudioSync; -extern int ShowOSD; - -extern int DirectBoot; - -extern int SocketBindAnyAddr; -extern char LANDevice[128]; -extern int DirectLAN; - -extern int SavestateRelocSRAM; - -extern int AudioVolume; -extern int MicInputType; -extern char MicWavPath[512]; - -extern char LastROMFolder[512]; - -} - -#endif // PLATFORMCONFIG_H diff --git a/src/libui_sdl/font.h b/src/libui_sdl/font.h deleted file mode 100644 index f2e4f87..0000000 --- a/src/libui_sdl/font.h +++ /dev/null @@ -1,135 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#ifndef FONT_H -#define FONT_H -unsigned short font[] = { - 12, 0, 0, 0,0x0C03, 0x0E07, 0x070E, 0x039C, 0x01F8, 0x00F0, 0x00F0, 0x01F8, 0x039C, 0x070E, 0x0E07, 0x0C03, - 12, 0, 0, 0,0x01C0, 0x00E0, 0x0060, 0x0860, 0x0C60, 0x0FE0, 0x07F0, 0x0038, 0x001C, 0x000E, 0x0007, 0x0003, - 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 2, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000, 0x0003, 0x0003, 0x0000, 0x0000, - 9, 0, 0, 0,0x01EF, 0x01EF, 0x018C, 0x01CE, 0x00E7, 0x0063, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 10, 0, 0, 0,0x00CC, 0x00CC, 0x03FF, 0x03FF, 0x00CC, 0x00CC, 0x03FF, 0x03FF, 0x00CC, 0x00CC, 0x0000, 0x0000, - 8, 0, 0, 0,0x0018, 0x00FE, 0x00FF, 0x001B, 0x007F, 0x00FE, 0x00D8, 0x00FF, 0x007F, 0x0018, 0x0000, 0x0000, - 10, 0, 0, 0,0x0306, 0x038F, 0x01CF, 0x00E6, 0x0070, 0x0038, 0x019C, 0x03CE, 0x03C7, 0x0183, 0x0000, 0x0000, - 10, 0, 0, 0,0x007C, 0x00FE, 0x00C6, 0x00EE, 0x007C, 0x037E, 0x03E7, 0x01F3, 0x03BF, 0x031E, 0x0000, 0x0000, - 4, 0, 0, 0,0x000F, 0x000F, 0x000C, 0x000E, 0x0007, 0x0003, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 4, 0, 0, 0,0x000C, 0x000E, 0x0007, 0x0003, 0x0003, 0x0003, 0x0003, 0x0007, 0x000E, 0x000C, 0x0000, 0x0000, - 4, 0, 0, 0,0x0003, 0x0007, 0x000E, 0x000C, 0x000C, 0x000C, 0x000C, 0x000E, 0x0007, 0x0003, 0x0000, 0x0000, - 10, 0, 0, 0,0x0030, 0x0333, 0x03B7, 0x01FE, 0x00FC, 0x00FC, 0x01FE, 0x03B7, 0x0333, 0x0030, 0x0000, 0x0000, - 10, 0, 0, 0,0x0030, 0x0030, 0x0030, 0x0030, 0x03FF, 0x03FF, 0x0030, 0x0030, 0x0030, 0x0030, 0x0000, 0x0000, - 4, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x000F, 0x000F, 0x000C, 0x000E, 0x0007, 0x0003, - 10, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x03FF, 0x03FF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 3, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0007, 0x0007, 0x0007, 0x0000, 0x0000, - 10, 0, 0, 0,0x0300, 0x0380, 0x01C0, 0x00E0, 0x0070, 0x0038, 0x001C, 0x000E, 0x0007, 0x0003, 0x0000, 0x0000, - 8, 0, 0, 0,0x007E, 0x00FF, 0x00C3, 0x00C3, 0x00C3, 0x00C3, 0x00C3, 0x00C3, 0x00FF, 0x007E, 0x0000, 0x0000, - 4, 0, 0, 0,0x0006, 0x0007, 0x0007, 0x0006, 0x0006, 0x0006, 0x0006, 0x0006, 0x000F, 0x000F, 0x0000, 0x0000, - 8, 0, 0, 0,0x007E, 0x00FF, 0x00C3, 0x00C0, 0x00FE, 0x007F, 0x0003, 0x0003, 0x00FF, 0x00FF, 0x0000, 0x0000, - 8, 0, 0, 0,0x007F, 0x00FF, 0x00C0, 0x00C0, 0x007C, 0x00FC, 0x00C0, 0x00C0, 0x00FF, 0x007F, 0x0000, 0x0000, - 8, 0, 0, 0,0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x00FF, 0x00FE, 0x0060, 0x0060, 0x0000, 0x0000, - 8, 0, 0, 0,0x00FF, 0x00FF, 0x0003, 0x0003, 0x007F, 0x00FF, 0x00C0, 0x00C0, 0x00FF, 0x007F, 0x0000, 0x0000, - 8, 0, 0, 0,0x007E, 0x007F, 0x0003, 0x0003, 0x007F, 0x00FF, 0x00C3, 0x00C3, 0x00FF, 0x007E, 0x0000, 0x0000, - 8, 0, 0, 0,0x00FF, 0x00FF, 0x00C0, 0x00E0, 0x0070, 0x0038, 0x001C, 0x000C, 0x000C, 0x000C, 0x0000, 0x0000, - 8, 0, 0, 0,0x007E, 0x00FF, 0x00C3, 0x00C3, 0x007E, 0x00FF, 0x00C3, 0x00C3, 0x00FF, 0x007E, 0x0000, 0x0000, - 8, 0, 0, 0,0x007E, 0x00FF, 0x00C3, 0x00C3, 0x00FF, 0x00FE, 0x00C0, 0x00C0, 0x00FE, 0x007E, 0x0000, 0x0000, - 3, 0, 0, 0,0x0000, 0x0000, 0x0007, 0x0007, 0x0000, 0x0000, 0x0000, 0x0007, 0x0007, 0x0000, 0x0000, 0x0000, - 4, 0, 0, 0,0x0000, 0x0000, 0x000E, 0x000E, 0x0000, 0x0000, 0x000C, 0x000E, 0x0007, 0x0003, 0x0000, 0x0000, - 6, 0, 0, 0,0x0030, 0x0038, 0x001C, 0x000E, 0x0007, 0x0007, 0x000E, 0x001C, 0x0038, 0x0030, 0x0000, 0x0000, - 7, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x007F, 0x007F, 0x0000, 0x0000, 0x007F, 0x007F, 0x0000, 0x0000, 0x0000, - 6, 0, 0, 0,0x0003, 0x0007, 0x000E, 0x001C, 0x0038, 0x0038, 0x001C, 0x000E, 0x0007, 0x0003, 0x0000, 0x0000, - 8, 0, 0, 0,0x007E, 0x00FF, 0x00C3, 0x00C3, 0x00F0, 0x0078, 0x0018, 0x0000, 0x0018, 0x0018, 0x0000, 0x0000, - 10, 0, 0, 0,0x00FC, 0x01FE, 0x0387, 0x0333, 0x037B, 0x03FB, 0x01F3, 0x0007, 0x03FE, 0x03FC, 0x0000, 0x0000, - 9, 0, 0, 0,0x00FE, 0x01FF, 0x0183, 0x0183, 0x0183, 0x01FF, 0x01FF, 0x0183, 0x0183, 0x0183, 0x0000, 0x0000, - 9, 0, 0, 0,0x00FF, 0x01FF, 0x0183, 0x0183, 0x00FF, 0x01FF, 0x0183, 0x0183, 0x01FF, 0x00FF, 0x0000, 0x0000, - 8, 0, 0, 0,0x00FE, 0x00FF, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x00FF, 0x00FE, 0x0000, 0x0000, - 9, 0, 0, 0,0x007F, 0x00FF, 0x01C3, 0x0183, 0x0183, 0x0183, 0x0183, 0x01C3, 0x00FF, 0x007F, 0x0000, 0x0000, - 9, 0, 0, 0,0x01FF, 0x01FF, 0x0003, 0x0003, 0x00FF, 0x00FF, 0x0003, 0x0003, 0x01FF, 0x01FF, 0x0000, 0x0000, - 9, 0, 0, 0,0x01FF, 0x01FF, 0x0003, 0x0003, 0x00FF, 0x00FF, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000, - 9, 0, 0, 0,0x01FE, 0x01FF, 0x0003, 0x0003, 0x01F3, 0x01F3, 0x0183, 0x0183, 0x01FF, 0x00FE, 0x0000, 0x0000, - 9, 0, 0, 0,0x0183, 0x0183, 0x0183, 0x0183, 0x01FF, 0x01FF, 0x0183, 0x0183, 0x0183, 0x0183, 0x0000, 0x0000, - 6, 0, 0, 0,0x003F, 0x003F, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x003F, 0x003F, 0x0000, 0x0000, - 9, 0, 0, 0,0x01F0, 0x01F0, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C3, 0x00C3, 0x00FF, 0x007E, 0x0000, 0x0000, - 9, 0, 0, 0,0x0183, 0x01C3, 0x00E3, 0x0073, 0x003F, 0x003F, 0x0073, 0x00E3, 0x01C3, 0x0183, 0x0000, 0x0000, - 7, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x007F, 0x007F, 0x0000, 0x0000, - 10, 0, 0, 0,0x0303, 0x0387, 0x03CF, 0x03FF, 0x037B, 0x0333, 0x0303, 0x0303, 0x0303, 0x0303, 0x0000, 0x0000, - 10, 0, 0, 0,0x0303, 0x0307, 0x030F, 0x031F, 0x033B, 0x0373, 0x03E3, 0x03C3, 0x0383, 0x0303, 0x0000, 0x0000, - 10, 0, 0, 0,0x01FE, 0x03FF, 0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x03FF, 0x01FE, 0x0000, 0x0000, - 9, 0, 0, 0,0x00FF, 0x01FF, 0x0183, 0x0183, 0x01FF, 0x00FF, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000, - 10, 0, 0, 0,0x01FE, 0x03FF, 0x0303, 0x0303, 0x0333, 0x0373, 0x03E3, 0x01C3, 0x03FF, 0x037E, 0x0000, 0x0000, - 9, 0, 0, 0,0x00FF, 0x01FF, 0x0183, 0x0183, 0x01FF, 0x00FF, 0x0073, 0x00E3, 0x01C3, 0x0183, 0x0000, 0x0000, - 10, 0, 0, 0,0x01FE, 0x01FF, 0x0003, 0x0003, 0x01FF, 0x03FE, 0x0300, 0x0300, 0x03FE, 0x01FE, 0x0000, 0x0000, - 10, 0, 0, 0,0x03FF, 0x03FF, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0000, 0x0000, - 9, 0, 0, 0,0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x01FF, 0x00FE, 0x0000, 0x0000, - 10, 0, 0, 0,0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x0387, 0x01CE, 0x00FC, 0x0078, 0x0030, 0x0000, 0x0000, - 10, 0, 0, 0,0x0303, 0x0303, 0x0303, 0x0303, 0x0333, 0x037B, 0x03FF, 0x03CF, 0x0387, 0x0303, 0x0000, 0x0000, - 10, 0, 0, 0,0x0303, 0x0387, 0x01CE, 0x00FC, 0x0078, 0x0078, 0x00FC, 0x01CE, 0x0387, 0x0303, 0x0000, 0x0000, - 10, 0, 0, 0,0x0303, 0x0387, 0x01CE, 0x00FC, 0x0078, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0000, 0x0000, - 10, 0, 0, 0,0x03FF, 0x03FF, 0x01C0, 0x00E0, 0x0070, 0x0038, 0x001C, 0x000E, 0x03FF, 0x03FF, 0x0000, 0x0000, - 4, 0, 0, 0,0x000F, 0x000F, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x000F, 0x000F, 0x0000, 0x0000, - 10, 0, 0, 0,0x0003, 0x0007, 0x000E, 0x001C, 0x0038, 0x0070, 0x00E0, 0x01C0, 0x0380, 0x0300, 0x0000, 0x0000, - 4, 0, 0, 0,0x000F, 0x000F, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x000F, 0x000F, 0x0000, 0x0000, - 8, 0, 0, 0,0x0018, 0x003C, 0x007E, 0x00E7, 0x00C3, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 10, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03FF, 0x03FF, - 4, 0, 0, 0,0x000F, 0x000F, 0x0003, 0x0007, 0x000E, 0x000C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 7, 0, 0, 0,0x0000, 0x0000, 0x003E, 0x007E, 0x0060, 0x007E, 0x007F, 0x0063, 0x007F, 0x007E, 0x0000, 0x0000, - 7, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x003F, 0x007F, 0x0063, 0x0063, 0x0063, 0x007F, 0x003F, 0x0000, 0x0000, - 7, 0, 0, 0,0x0000, 0x0000, 0x007E, 0x007F, 0x0003, 0x0003, 0x0003, 0x0003, 0x007F, 0x007E, 0x0000, 0x0000, - 7, 0, 0, 0,0x0060, 0x0060, 0x0060, 0x007E, 0x007F, 0x0063, 0x0063, 0x0063, 0x007F, 0x007E, 0x0000, 0x0000, - 7, 0, 0, 0,0x0000, 0x0000, 0x003E, 0x007F, 0x0063, 0x007F, 0x003F, 0x0003, 0x003F, 0x003E, 0x0000, 0x0000, - 6, 0, 0, 0,0x003C, 0x003E, 0x0006, 0x0006, 0x001F, 0x001F, 0x0006, 0x0006, 0x0006, 0x0006, 0x0000, 0x0000, - 7, 0, 0, 0,0x0000, 0x0000, 0x007E, 0x007F, 0x0063, 0x0063, 0x007F, 0x007E, 0x0060, 0x0060, 0x007E, 0x003E, - 7, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x003F, 0x007F, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x0000, 0x0000, - 2, 0, 0, 0,0x0003, 0x0003, 0x0000, 0x0000, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000, - 7, 0, 0, 0,0x0060, 0x0060, 0x0000, 0x0000, 0x0060, 0x0060, 0x0060, 0x0060, 0x0060, 0x0063, 0x007F, 0x003E, - 8, 0, 0, 0,0x0003, 0x0003, 0x00E3, 0x0073, 0x003B, 0x001F, 0x001F, 0x003B, 0x0073, 0x00E3, 0x0000, 0x0000, - 4, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x000F, 0x000E, 0x0000, 0x0000, - 10, 0, 0, 0,0x0000, 0x0000, 0x01FF, 0x03FF, 0x0333, 0x0333, 0x0333, 0x0333, 0x0333, 0x0333, 0x0000, 0x0000, - 7, 0, 0, 0,0x0000, 0x0000, 0x003F, 0x007F, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x0000, 0x0000, - 8, 0, 0, 0,0x0000, 0x0000, 0x007E, 0x00FF, 0x00C3, 0x00C3, 0x00C3, 0x00C3, 0x00FF, 0x007E, 0x0000, 0x0000, - 7, 0, 0, 0,0x0000, 0x0000, 0x003F, 0x007F, 0x0063, 0x0063, 0x007F, 0x003F, 0x0003, 0x0003, 0x0003, 0x0003, - 7, 0, 0, 0,0x0000, 0x0000, 0x007E, 0x007F, 0x0063, 0x0063, 0x007F, 0x007E, 0x0060, 0x0060, 0x0060, 0x0060, - 7, 0, 0, 0,0x0000, 0x0000, 0x003B, 0x007F, 0x0067, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000, - 8, 0, 0, 0,0x0000, 0x0000, 0x007E, 0x007F, 0x0003, 0x007F, 0x00FE, 0x00C0, 0x00FE, 0x007E, 0x0000, 0x0000, - 6, 0, 0, 0,0x0006, 0x0006, 0x003F, 0x003F, 0x0006, 0x0006, 0x0006, 0x0006, 0x003E, 0x003C, 0x0000, 0x0000, - 7, 0, 0, 0,0x0000, 0x0000, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x007F, 0x007E, 0x0000, 0x0000, - 10, 0, 0, 0,0x0000, 0x0000, 0x0303, 0x0303, 0x0303, 0x0387, 0x01CE, 0x00FC, 0x0078, 0x0030, 0x0000, 0x0000, - 10, 0, 0, 0,0x0000, 0x0000, 0x0303, 0x0303, 0x0333, 0x037B, 0x03FF, 0x03CF, 0x0387, 0x0303, 0x0000, 0x0000, - 8, 0, 0, 0,0x0000, 0x0000, 0x00C3, 0x00E7, 0x007E, 0x003C, 0x003C, 0x007E, 0x00E7, 0x00C3, 0x0000, 0x0000, - 10, 0, 0, 0,0x0000, 0x0000, 0x0303, 0x0307, 0x038E, 0x01DC, 0x00F8, 0x0070, 0x0038, 0x001C, 0x000E, 0x0006, - 8, 0, 0, 0,0x0000, 0x0000, 0x00FF, 0x00FF, 0x0070, 0x0038, 0x001C, 0x000E, 0x00FF, 0x00FF, 0x0000, 0x0000, - 6, 0, 0, 0,0x0038, 0x003C, 0x000C, 0x000C, 0x000F, 0x000F, 0x000C, 0x000C, 0x003C, 0x0038, 0x0000, 0x0000, - 2, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000, - 6, 0, 0, 0,0x0007, 0x000F, 0x000C, 0x000C, 0x003C, 0x003C, 0x000C, 0x000C, 0x000F, 0x0007, 0x0000, 0x0000, - 10, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x031C, 0x03BE, 0x01F7, 0x00E3, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 11, 0, 0, 0,0x0555, 0x0000, 0x0401, 0x0000, 0x0401, 0x0000, 0x0401, 0x0000, 0x0401, 0x0000, 0x0555, 0x0000, -}; -#endif diff --git a/src/libui_sdl/libui/.travis.yml b/src/libui_sdl/libui/.travis.yml deleted file mode 100644 index d271bd8..0000000 --- a/src/libui_sdl/libui/.travis.yml +++ /dev/null @@ -1,23 +0,0 @@ -os: - - linux - - osx - -# This makes us use Ubuntu 14 instead of 12 -dist: trusty - -# Notes: -# - Travis uses cmake 3.0.2 on OS X; we need 3.1 or newer (thanks tbodt) - -language: c -script: - - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get update; fi - - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install libgtk-3-dev -y || sudo apt-cache search libgtk3; fi - - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew update; fi - - mkdir build - - cd build - - cmake --version - - cmake .. -G "Unix Makefiles" - - make tester examples - - rm -rf * - - cmake .. -G "Unix Makefiles" -DBUILD_SHARED_LIBS=OFF - - make tester examples diff --git a/src/libui_sdl/libui/ANNOUNCE.md b/src/libui_sdl/libui/ANNOUNCE.md deleted file mode 100644 index 4db42eb..0000000 --- a/src/libui_sdl/libui/ANNOUNCE.md +++ /dev/null @@ -1,22 +0,0 @@ -# Old Announcements - -* **29 May 2016** - * **Alpha 3 is here!** Get it [here](https://github.com/andlabs/libui/releases/tag/alpha3). - * The next packaged release will introduce: - * uiGrid, another way to lay out controls, a la GtkGrid - * uiOpenGLArea, a way to render OpenGL content in a libui uiArea - * uiTable, a data grid control that may or may not have tree facilities (if it does, it will be called uiTree instead) - * a complete, possibly rewritten, drawing and text rendering infrastructure - -* **24 May 2016** - * You can now help choose [a potential new build system for libui](https://github.com/andlabs/libui/issues/62). - * Tomorrow I will decide if OS X 10.7 will also be dropped alongside GTK+ 3.4-3.8 this Saturday. Stay tuned. - -* **22 May 2016** - * Two more open questions I'd like your feedback on are available [here](https://github.com/andlabs/libui/issues/48) and [here](https://github.com/andlabs/libui/issues/25). - * Sometime in the next 48 hours (before 23:59 EDT on 24 May 2016) I will split `uiCombobox` into two separate controls, `uiCombobox` and `uiEditableCombobox`, each with slightly different events and "selected item" mechanics. Prepare your existing code. - -* **21 May 2016** - * I will now post announcements and updates here. - * Now that Ubuntu 16.04 LTS is here, no earlier than next Saturday, 28 May 2016 at noon EDT, **I will bump the minimum GTK+ version from 3.4 to 3.10**. This will add a lot of new features that I can now add to libui, such as search-oriented uiEntries, lists of arbitrary control layouts, and more. If you are still running a Linux distribution that doesn't come with 3.10, you will either need to upgrade or use jhbuild to set up a newer version of GTK+ in a private environment. - * You can decide if I should also drop OS X 10.7 [here](https://github.com/andlabs/libui/issues/46). diff --git a/src/libui_sdl/libui/CMakeLists.txt b/src/libui_sdl/libui/CMakeLists.txt deleted file mode 100644 index eb1696d..0000000 --- a/src/libui_sdl/libui/CMakeLists.txt +++ /dev/null @@ -1,219 +0,0 @@ -# 3 june 2016 -# see https://cmake.org/gitweb?p=cmake.git;a=commit;h=95cdf132489c79e88a10fdf7a7566fa002c7680b (thanks ngladitz in irc.freenode.net/#cmake) -cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) - -# TODOs -# - silence entering/leaving messages? -# - uname -s for more refined OS control -# - Haiku for haiku -# - debian DESTDIR? https://github.com/andlabs/libui/pull/10 -# - libui-combined* needs to be deleted so that custom command can run every time -# - add notelemetry.obj to *ALL TARGETS* on VS2015 and up - https://www.infoq.com/news/2016/06/visual-cpp-telemetry -# - switch to 3.1.0 features - -# the docs say we need to set this up prior to project() -set(CMAKE_OSX_DEPLOYMENT_TARGET "10.8") - -# we want to disable incremental linking -# see also: -# - https://github.com/bulletphysics/bullet3/blob/master/CMakeLists.txt#L43 -# - https://cmake.org/pipermail/cmake/2010-February/035174.html -# this must also go before project() -set(MSVC_INCREMENTAL_DEFAULT ON) - -# default to debug builds -# do this before project() just to be safe -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE DEBUG CACHE STRING "" FORCE) -endif() - -project(libui) -option(BUILD_SHARED_LIBS "Whether to build libui as a shared library or a static library" ON) - -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out") -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out") -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out") -set(CMAKE_PDB_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out") - -if(APPLE) - set(_OSNAME darwin) - set(_HASVERSION TRUE) - set(_VERSION "A") - - # always use our rpath - set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) - # the / is required by some older versions of OS X - set(CMAKE_INSTALL_RPATH "@executable_path/") - set(CMAKE_MACOSX_RPATH TRUE) -elseif(WIN32) - set(_OSNAME windows) - - # and don't include the default libraries with ANY of the builds - # note the CACHE FORCE stuff is required here - set(CMAKE_C_STANDARD_LIBRARIES CACHE STRING "" FORCE) - set(CMAKE_CXX_STANDARD_LIBRARIES CACHE STRING "" FORCE) -else() - set(_OSNAME unix) - set(_HASVERSION TRUE) - set(_VERSION "0") - - # always use our rpath - set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) - set(CMAKE_INSTALL_RPATH "\$ORIGIN") -endif() - -# common flags -if(MSVC) - # TODO subsystem version - - # TODO /Wall does too much - # TODO -Wno-switch equivalent - # TODO /sdl turns C4996 into an ERROR - # don't use /analyze; that requires us to write annotations everywhere - # TODO undecided flags from qo? - # /RTCc is not supplied because it's discouraged as of VS2015; see https://www.reddit.com/r/cpp/comments/46mhne/rtcc_rejects_conformant_code_with_visual_c_2015/d06auq5 - # /EHsc is to shut the compiler up in some cases - # TODO make /EHsc C++-only - set(_COMMON_CFLAGS - /W4 /wd4100 - /bigobj /nologo - /RTC1 /RTCs /RTCu - /EHsc - ) - - # note the /MANIFEST:NO (which must be / and uppercase); thanks FraGag (https://github.com/andlabs/libui/issues/93#issuecomment-223183436) - # TODO warnings on undefined symbols - set(_COMMON_LDFLAGS - /LARGEADDRESSAWARE - /NOLOGO - /INCREMENTAL:NO - /MANIFEST:NO - ) - - # TODO autogenerate a .def file? - - # more incremental linking fixes - # TODO actually get rid of incremental linking here -else() - set(_COMMON_CFLAGS - -Wall -Wextra -pedantic - -Wno-unused-parameter - -Wno-switch - -fvisibility=hidden - ) - # don't use C_VERSION or CXX_VERSION because they use GNU standards - # TODO we can actually do this; set both C_EXTENSIONS and CXX_EXTENSIONS to OFF - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c99") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11") - - set(_COMMON_LDFLAGS - -fvisibility=hidden - ) - - # don't require shipping the MinGW-w64 DLLs - if(WIN32) - list(APPEND _COMMON_LDFLAGS - -static - -static-libgcc - -static-libstdc++ - ) - endif() -endif() - -# problem: -# - target_link_libraries() only supports - for flags -# - but cmake only doesn't generate the manifest if the flag has a / -macro(_target_link_options_private _target) - foreach(_opt IN LISTS ${ARGN}) - set_property(TARGET ${_target} APPEND_STRING PROPERTY - LINK_FLAGS " ${_opt}") - endforeach() -endmacro() - -add_subdirectory("common") -add_subdirectory("${_OSNAME}") -add_library(${_LIBUINAME} ${_LIBUI_SOURCES}) -target_include_directories(${_LIBUINAME} - PUBLIC . - PRIVATE ${_LIBUI_INCLUEDIRS}) -target_compile_definitions(${_LIBUINAME} - PRIVATE ${_LIBUI_DEFS}) -# cmake produces this for us by default but only for shared libraries -target_compile_definitions(${_LIBUINAME} - PRIVATE libui_EXPORTS) -target_compile_options(${_LIBUINAME} - PUBLIC ${_COMMON_CFLAGS} - PRIVATE ${_LIBUI_CFLAGS}) -# TODO link directories? -if(BUILD_SHARED_LIBS) - target_link_libraries(${_LIBUINAME} - PRIVATE ${_LIBUI_LIBS}) -endif() -# TODO INTERFACE libs don't inherit to grandhcildren? -# on Windows the linker for static libraries is different; don't give it the flags -if(BUILD_SHARED_LIBS) - _target_link_options_private(${_LIBUINAME} - _COMMON_LDFLAGS - _LIBUI_LDFLAGS) -endif() -if(NOT BUILD_SHARED_LIBS) - _handle_static() - # TODO figure out a way to tell libui that it's static - target_compile_definitions(${_LIBUINAME} - PUBLIC _UI_STATIC) -endif() -if(NOT MSVC) - # on non-MSVC compilers cmake adds an extra lib- - # note that we apply this to libui, not to any intermediates - set_target_properties(libui PROPERTIES - OUTPUT_NAME ui) - - # flags for warning on undefined symbols - # TODO figure out why FreeBSD follows linked libraries here - # TODO figure out MSVC equivalents - if(BUILD_SHARED_LIBS) - if(NOT (${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)) - # on OS X we don't need to do this; Apple's linker warns about undefined symbols in -shared builds! - if(NOT APPLE) - target_link_libraries(libui - PRIVATE -Wl,--no-undefined -Wl,--no-allow-shlib-undefined - ) - endif() - endif() - endif() -endif() -if(BUILD_SHARED_LIBS) - if(_HASVERSION) - set_target_properties(${_LIBUINAME} PROPERTIES - SOVERSION "${_VERSION}") - endif() -endif() - -macro(_add_exec _name) - add_executable(${_name} - WIN32 EXCLUDE_FROM_ALL - ${ARGN}) - target_link_libraries(${_name} libui ${_LIBUI_STATIC_RES}) - _target_link_options_private(${_name} - _COMMON_LDFLAGS) - # make shared-linked executables PIC too - if(BUILD_SHARED_LIBS) - set_property(TARGET ${_name} PROPERTY - POSITION_INDEPENDENT_CODE True) - endif() - # TODO see above about INTERFACE - if(NOT BUILD_SHARED_LIBS) - target_link_libraries(${_name} - ${_LIBUI_LIBS}) - endif() - - # TODOfor some reason these don't propagate - if(NOT WIN32) - target_include_directories(${_name} - PUBLIC .) - target_compile_options(${_name} - PUBLIC ${_COMMON_CFLAGS}) - endif() -endmacro() -add_subdirectory("test") -add_subdirectory("examples") diff --git a/src/libui_sdl/libui/Changelog.md b/src/libui_sdl/libui/Changelog.md deleted file mode 100644 index 29fac27..0000000 --- a/src/libui_sdl/libui/Changelog.md +++ /dev/null @@ -1,33 +0,0 @@ -# Old Updates - -* **29 May 2016** - * Thanks to @pcwalton, we can now statically link libui! Simply do `make STATIC=1` instead of just `make`. - * On Windows you must link both `libui.lib` and `libui.res` AND provide a Common Controls 6 manifest for output static binaries to work properly. - -* **28 May 2016** - * As promised, **the minimum system requirements are now OS X 10.8 and GTK+ 3.10 for OS X and Unix, respectively**. - -* **26 May 2016** - * Two OS X-specific functions have been added: `uiDarwinMarginAmount()` and `uiDarwinPaddingAmount()`. These return the amount of margins and padding, respectively, to give to a control, and are intended for container implementations. These are suitable for the constant of a NSLayoutConstraint. They both take a pointer parameter that is reserved for future use and should be `NULL`. - -* **25 May 2016** - * uiDrawTextLayout attributes are now specified in units of *graphemes* on all platforms. This means characters as seen from a user's perspective, not Unicode codepoints or UTF-8 bytes. So a long string of combining marker codepoints after one codepoint would still count as one grapheme. - -* **24 May 2016** - * As promised, `uiCombobox` is now split into `uiCombobox` for non-editable comboboxes and `uiEditableCombobox` for editable comboboxes. Mind the function changes as well :) - * There is a new function `uiMainStep()`, which runs one iteration of the main loop. It takes a single boolean argument, indicating whether to wait for an event to occur or not. It returns true if an event was processed (or if no event is available if you don't want to wait) and false if the event loop was told to stop (for instance, `uiQuit()` was called). - -* **23 May 2016** - * Fixed surrogate pair drawing on OS X. - -* **22 May 2016** - * Removed `uiControlVerifyDestroy()`; that is now part of `uiFreeControl()` itself. - * Added `uiPi`, a constant for Ď€. This is provided for C and C++ programmers, where there is no standard named constant for Ď€; bindings authors shouldn't need to worry about this. - * Fixed uiMultilineEntry not properly having line breaks on Windows. - * Added `uiNewNonWrappingMultilineEntry()`, which creates a uiMultilineEntry that scrolls horizontally instead of wrapping lines. (This is not documented as being changeable after the fact on Windows, hence it's a creation-time choice.) - * uiAreas on Windows and some internal Direct2D areas now respond to `WM_PRINTCLIENT` properly, which should hopefully increase the quality of screenshots. - * uiDateTimePicker on GTK+ works properly on RTL layouts and no longer disappears off the bottom of the screen if not enough room is available. It will also no longer be marked for localization of the time format (what the separator should be and whether to use 24-hour time), as that information is not provided by the locale system. :( - * Added `uiUserBugCannotSetParentOnToplevel()`, which should be used by implementations of toplevel controls in their `SetParent()` implementations. This will also be the beginning of consolidating common user bug messages into a single place, though this will be one of the only few exported user bug functions. - * uiSpinbox and uiSlider now merely swap their min and max if min ≥ max. They will no longer panic and do nothing, respectively. - * Matrix scaling will no longer leave the matrix in an invalid state on OS X and GTK+. - * `uiMultilineEntrySetText()` and `uiMutlilineEntryAppend()` on GTK+ no longer fire `OnChanged()` events. diff --git a/src/libui_sdl/libui/Compatibility.md b/src/libui_sdl/libui/Compatibility.md deleted file mode 100644 index bc16f1b..0000000 --- a/src/libui_sdl/libui/Compatibility.md +++ /dev/null @@ -1,141 +0,0 @@ -# Useful things in newer versions - -## Windows -### Windows 7 -http://channel9.msdn.com/blogs/pdc2008/pc43 - -TODO look up PDC 2008 talk "new shell user interface" - -- new animation and text engine -- ribbon control (didn't this have some additional license?) -- LVITEM.piColFmt - -### Windows 8 - -### Windows 8.1 - -### Windows 10 - -## GTK+ -TODO what ships with Ubuntu Quantal (12.10)? - -### GTK+ 3.6 -ships with: Ubuntu Raring (13.04) - -- GtkEntry and GtkTextView have input purposes and input hints for external input methods but do not change input themselves - - according to Company, we connect to insert-text for that -- GtkLevelBar -- GtkMenuButton -- **GtkSearchEntry** - -### GTK+ 3.8 -ships with: Ubuntu Saucy (13.10) - -Not many interesting new things to us here, unless you count widget-internal tickers and single-click instead of double-click to select list items (a la KDE)... and oh yeah, also widget opacity. - -### GTK+ 3.10 -ships with: **Ubuntu Trusty (14.04 LTS)** -
GLib version: 2.40 - -- tab character stops in GtkEntry -- GtkHeaderBar - - intended for titlebar overrides; GtkInfoBar is what I keep thinking GtkHeaderBar is -- **GtkListBox** -- GtkRevealer for smooth animations of disclosure triangles -- GtkSearchBar for custom search popups -- **GtkStack and GtkStackSwitcher** -- titlebar overrides (seems to be the hot new thing) - -### GTK+ 3.12 -ships with: Ubuntu Utopic (14.10) -
GLib version: 2.42 - -- GtkActionBar (basically like the bottom-of-the-window toolbars in Mac programs) -- gtk_get_locale_direction(), for internationalization -- more control over GtkHeaderBar -- **GtkPopover** - - GtkPopovers on GtkMenuButtons -- GtkStack signaling -- **gtk_tree_path_new_from_indicesv()** (for when we add Table if we have trees too) - -### GTK+ 3.14 -ships with: **Debian Jessie**, Ubuntu Vivid (15.04) -
GLib version: Debian: 2.42, Ubuntu: 2.44 - -- gestures -- better GtkListbox selection handling -- more style classes (TODO also prior?) -- delayed switch changes on GtkSwitch - -### GTK+ 3.16 -ships with: Ubuntu Wily (15.10) -
GLib version: 2.46 - -- gtk_clipboard_get_default() (???) -- **GtkGLArea** -- proper xalign and yalign for GtkLabel; should get rid of runtime deprecation warnings -- better control of GtkListBox model-based creation (probably not relevant but) -- GtkModelButton (for GActions; probably not relevant?) -- wide handles on GtkPaned -- GtkPopoverMenu -- IPP paper names in GtkPaperSize (TODO will this be important for printing?) -- multiple matches in GtkSearchEntry (TODO evaluate priority) -- **GtkStackSidebar** -- GTK_STYLE_CLASS_LABEL, GTK_STYLE_CLASS_MONOSPACE, GTK_STYLE_CLASS_STATUSBAR, GTK_STYLE_CLASS_TOUCH_SELECTION, GTK_STYLE_CLASS_WIDE (TODO figure out which of these are useful) -- GtkTextView: extend-selection -- GtkTextView: font fallbacks - -### GTK+ 3.18 - -### GTK+ 3.20 - -## Cocoa -### Mac OS X 10.8 - -- Foundation ([full details](https://developer.apple.com/library/mac/releasenotes/Foundation/RN-FoundationOlderNotes/#//apple_ref/doc/uid/TP40008080-TRANSLATED_CHAPTER_965-TRANSLATED_DEST_999B)) - - NSDateComponents supports leap months - - NSNumberFormatter and NSDateFormatter default to 10.4 behavior by default (need to explicitly do this on 10.7) - - **NSUserNotification and NSUserNotificationCenter for Growl-style notifications** - - better linguistic triggers for Spanish and Italian - - NSByteCountFormatter -- AppKit ([full details](https://developer.apple.com/library/mac/releasenotes/AppKit/RN-AppKitOlderNotes/#X10_8Notes)) - - view-based NSTableView/NSOutlineView have expansion tooltips - - NSScrollView magnification - - Quick Look events; TODO see if they conflict with keyboard handling in Area - - NSPageController (maybe useful?) - - not useful for package UI, but may be useful for a new library (probably not by me): NSSharingService - - NSOpenPanel and NSSavePanel are now longer NSPanels or NSWindows in sandboxed applications; this may be an issue should anyone dare to enable sandboxing on a program that uses package ui - - NSTextAlternatives - - -[NSOpenGLContext setFullScreen] now ineffective - - +[NSColor underPageBackgroundColor] - -### Mac OS X 10.9 - -- Foundation ([full details](https://developer.apple.com/library/mac/releasenotes/Foundation/RN-Foundation/)) - - system-provided progress reporting/cancellation support - - NSURLComponents - - **NSCalendar, NSDateFormatter, and NSNumberFormatter are now thread-safe** - - various NSCalendar and NSDateComponents improvements -- AppKit ([full details](https://developer.apple.com/library/mac/releasenotes/AppKit/RN-AppKit/)) - - sheet handling is now block-based, queued, and in NSWindow; the delegate-based NSApplication API will still exist, except without the queue - - similar changes to NSAlert - - **return value changes to NSAlert** - - window visibility APIs (occlusion) - - NSApplicationActivationPolicyAccessory - - fullscreen toolbar behavior changes - - status items for multiple menu bars - - better NSSharingService support - - a special accelerated scrolling mode, Responsive Scrolling; won't matter for us since I plan to support the scroll wheel and it won't - - NSScrollView live scrolling notifications - - NSScrollView floating (anchored/non-scrolling) subviews - - better multimonitor support - - better key-value observing for NSOpenPanel/NSSavePanel (might want to look this up to see if we can override some other juicy details... TODO) - - better accessory view key-view handling in NSOpenPanel/NSSavePanel - - NSAppearance - - **-[NSTableView moveRowAtIndex:toIndex:] bug regarding first responders fixed** - - view-specific RTL overrides - -### Mac OS X 10.10 - -### Mac OS X 10.11 -* **NSLayoutGuide** diff --git a/src/libui_sdl/libui/LICENSE b/src/libui_sdl/libui/LICENSE deleted file mode 100644 index 2351d66..0000000 --- a/src/libui_sdl/libui/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -Copyright (c) 2014 Pietro Gagliardi - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -(this is called the MIT License or Expat License; see http://www.opensource.org/licenses/MIT) diff --git a/src/libui_sdl/libui/README.md b/src/libui_sdl/libui/README.md deleted file mode 100644 index 01275c0..0000000 --- a/src/libui_sdl/libui/README.md +++ /dev/null @@ -1,185 +0,0 @@ -# libui: a portable GUI library for C - -This README is being written.
-[![Build Status](https://travis-ci.org/andlabs/libui.svg)](https://travis-ci.org/andlabs/libui) - -## Announcements - -* **27 November 2016** - * Decided to split the table stuff into its own branch. It will be developed independently of everything else, along with a few other features. - -* **2 November 2016** - * Added two new functions to replace the deleted `uiWindowPosition()` and friends: `uiAreaBeginUserWindowMove()` and `uiAreaBeginUserWindowResize()`. When used in a `uiAreaHandler.Mouse()` event handler, these let you initiate a user-driven mouse move or mouse resize of the window at any point in a uiArea. - -* **31 October 2016** - * @krakjoe noticed that I accidentally used thread-unsafe code in uiQueueMain() on Unix. Fixed. - -* **24 October 2016** - * `uiWindowSetContentSize()` on Unix no longer needs to call up the GTK+ main loop. As a result, bugs related to strange behavior using that function (and the now-deleted `uiWindowSetPosition()` and `uiWindowCenter()`) should go away. I'll need to go through the bugs to verify as much, though. - -* **22 October 2016** - * Due to being unable to guarantee they will work (especially as we move toward capability-driven window systems like Wayland), or being unable to work without hacking that breaks other things, the following functions have been removed: `uiWindowPosition()`, `uiWindowSetPosition()`, `uiWindowCenter()`, and `uiWindowOnPositionChanged()`. Centering may come back at some point in the future, albeit in a possibly restricted form. A function to initiate a user move when a part of a uiArea is clicked will be provided soon. - -* **21 October 2016** - * `uiDrawTextWeightUltraBold` is now spelled correctly. Thanks to @krakjoe. - -* **18 June 2016** - * Help decide [the design of tables and trees in libui](https://github.com/andlabs/libui/issues/159); the implementation starts within the next few days, if not tomorrow! - -* **17 June 2016** - * **CMake 3.1.0 is now required.** This is due to CMake's rapid development pace in the past few years adding things libui needs to build on as many systems as possible. If your OS is supported by libui but its repositories ship with an older version of CMake, you will need to find an updated one somewhere. - * Please help [plan out a better menu API](https://github.com/andlabs/libui/issues/152). - -* **5 June 2016** - * **Alpha 3.1 is here.** This was a much-needed update to Alpha 3 that changes a few things: - * **The build system is now cmake.** cmake 2.8.11 or higher is needed. - * Static linking is now fully possible. - * MinGW linking is back, but static only. - -*Old announcements can be found in the ANNOUNCE.md file.* - -## Updates - -*Note that today's entry (Eastern Time) may be updated later today.* - -* ** And the blue outline on those buttons [ALL clicked buttons on Windows 7] won't go away - - I get this too - - not anymore -- SWP_NOCOPYBITS to avoid button redraw issues on Windows when not in tab, but only when making resize faster -- secondary side alignment control in uiBox -- Windows: don't abort if a cleanup function fails? - -- 32-bit Mac OS X support (requires lots of code changes) - - change the build system to be more receptive to arch changes - -notes to self -- explicitly document label position at top-left corner -- explicitly document that if number of radio buttons >= 1 there will always be a selection -- mark that uiControlShow() on a uiWindow() will bring to front and give keyboard focus because of OS X - - make sure ShowWindow() is sufficient for zorder on Windows -- document that you CAN use InsertAt functions to insert at the first invalid index, even if the array is empty -- note that uiTabInsertAt() does NOT change the current tab page (it may change its index if inserting before the current page) -- note that the default action for uiWindowOnClosing() is to return 0 (keep the window open) -- note that uiInitOptions should be initialized to zero -- explicitly document that uiCheckboxSetChecked() and uiEntrySetText() do not fire uiCheckboxOnToggled() and uiEntryOnChanged(), respectively -- note that if a menu is requested on systems with menubars on windows but no menus are defined, the result is a blank menubar, with whatever that means left up to the OS to decide -- note that handling of multiple consecutive separators in menus, leading separators in menus, and trailing separators in menus are all OS-defined -- note that uiDrawMatrixInvert() does not change the matrix if it fails -- note that the use of strings that are not strictly valid UTF-8 results in undefined behavior - -- test RTL - - automate RTL -- now that stock items are deprecated, I have to maintain translations of the Cancel, Open, and Save buttons on GTK+ myself (thanks baedert in irc.gimp.net/#gtk+) - - either that or keep using stock items - -- http://blogs.msdn.com/b/oldnewthing/archive/2014/02/26/10503148.aspx - -- build optimizations - -- use http://www.appveyor.com/ to do Windows build CI since people want CI - - - - - - -- consider just having the windows backend in C++ - - consider having it all in C++ - - - -don't forget LONGTERMs as well - -notes -- http://blogs.msdn.com/b/oldnewthing/archive/2004/03/29/101121.aspx on accelerators - -- group and tab should act as if they have no child if the child is hidden -on windows - - - -- a way to do recursive main loops - - how do we handle 0 returns from non-recursive uiMainStep() calls that aren't the main loop? (event handlers, for instance) -- should repeated calls to uiMainStep() after uiQuit() return 0 reliably? this will be needed for non-recursive loops - -http://stackoverflow.com/questions/38338426/meaning-of-ampersand-in-rc-files/38338841?noredirect=1#comment64093084_38338841 - -label shortcut keys - -- remove whining from source code - -[01:41:47] Hi. does pango support "fgalpha". I see that foreground="112233xx" works ( alpha=xx ), but fgalpha is a no-op -[01:52:29] pango_attr_foreground_alpha_new (32767) seems to be called in either case, but only the "foreground" attr works -[01:56:09] lolek (lolek@ip-91-244-230-76.simant.pl) joined the channel -[01:57:48] ok. seems like "foreground" is mandatory attr, 1. "foreground-without-alpha" + "alpha" works 2. "foreground-with-alpha" works. 3. "alpha" alone doesn -[01:57:52] 't work -[01:58:29] Is there a way to just specify alpha on the current foreground color ? -[02:00:23] lolek (lolek@ip-91-244-230-76.simant.pl) left the channel -[02:07:41] mjog (mjog@uniwide-pat-pool-129-94-8-98.gw.unsw.edu.au) left IRC (Quit: mjog) -[02:08:10] seb128 (seb128@53542B83.cm-6-5a.dynamic.ziggo.nl) joined the channel -[02:12:37] huh -[02:12:41] what version of pango? -[02:13:05] the latest . -[02:15:00] 1.40.3 -[02:20:46] I'll ahve to keep this in mind then, thanks -[02:20:59] if only there was a cairo-specific attribute for alpha... diff --git a/src/libui_sdl/libui/_abort/windowevents/darwin_window.m b/src/libui_sdl/libui/_abort/windowevents/darwin_window.m deleted file mode 100644 index 76180d8..0000000 --- a/src/libui_sdl/libui/_abort/windowevents/darwin_window.m +++ /dev/null @@ -1,90 +0,0 @@ -struct uiWindow { - // constraints - void (*onPositionChanged)(uiWindow *, void *); - void *onPositionChangedData; - BOOL suppressPositionChanged; - // onContentSizeChanged -}; - -@interface windowDelegateClass : NSObject { -// windowShouldClose: -- (void)windowDidMove:(NSNotification *)note; -// windowDidResize: -@end - -@implementation windowDelegateClass - -// - (BOOL)windowShouldClose:(id)sender - -// TODO doesn't happen live -- (void)windowDidMove:(NSNotification *)note -{ - uiWindow *w; - - w = [self lookupWindow:((NSWindow *) [note object])]; - if (!w->suppressPositionChanged) - (*(w->onPositionChanged))(w, w->onPositionChangedData); -} - -// - (void)windowDidResize:(NSNotification *)note - -// void uiWindowSetTitle(uiWindow *w, const char *title) - -void uiWindowPosition(uiWindow *w, int *x, int *y) -{ - NSScreen *screen; - NSRect r; - - r = [w->window frame]; - *x = r.origin.x; - // this is the right screen to use; thanks mikeash in irc.freenode.net/#macdev - // -mainScreen is useless for positioning (it's just the key window's screen) - // and we use -frame, not -visibleFrame, for dealing with absolute positions - screen = (NSScreen *) [[NSScreen screens] objectAtIndex:0]; - *y = ([screen frame].size.height - r.origin.y) - r.size.height; -} - -void uiWindowSetPosition(uiWindow *w, int x, int y) -{ - // -[NSWindow setFrameTopLeftPoint:] is acting weird so... - NSRect r; - NSScreen *screen; - - // this fires windowDidMove: - w->suppressPositionChanged = YES; - r = [w->window frame]; - r.origin.x = x; - screen = (NSScreen *) [[NSScreen screens] objectAtIndex:0]; - r.origin.y = [screen frame].size.height - (y + r.size.height); - [w->window setFrameOrigin:r.origin]; - w->suppressPositionChanged = NO; -} - -void uiWindowCenter(uiWindow *w) -{ - w->suppressPositionChanged = YES; - [w->window center]; - w->suppressPositionChanged = NO; -} - -void uiWindowOnPositionChanged(uiWindow *w, void (*f)(uiWindow *, void *), void *data) -{ - w->onPositionChanged = f; - w->onPositionChangedData = data; -} - -// void uiWindowContentSize(uiWindow *w, int *width, int *height) - -// static int defaultOnClosing(uiWindow *w, void *data) - -static void defaultOnPositionContentSizeChanged(uiWindow *w, void *data) -{ - // do nothing -} - -uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar) -{ -// uiWindowOnClosing(w, defaultOnClosing, NULL); - uiWindowOnPositionChanged(w, defaultOnPositionContentSizeChanged, NULL); -// uiWindowOnContentSizeChanged(w, defaultOnPositionContentSizeChanged, NULL); -} diff --git a/src/libui_sdl/libui/_abort/windowevents/page15.c b/src/libui_sdl/libui/_abort/windowevents/page15.c deleted file mode 100644 index 0cceba8..0000000 --- a/src/libui_sdl/libui/_abort/windowevents/page15.c +++ /dev/null @@ -1,65 +0,0 @@ -static uiSpinbox *x, *y; - -static void moveX(uiSpinbox *s, void *data) -{ - uiWindow *w = uiWindow(data); - int xp, yp; - - uiWindowPosition(w, &xp, &yp); - xp = uiSpinboxValue(x); - uiWindowSetPosition(w, xp, yp); -} - -static void moveY(uiSpinbox *s, void *data) -{ - uiWindow *w = uiWindow(data); - int xp, yp; - - uiWindowPosition(w, &xp, &yp); - yp = uiSpinboxValue(y); - uiWindowSetPosition(w, xp, yp); -} - -static void updatepos(uiWindow *w) -{ - int xp, yp; - - uiWindowPosition(w, &xp, &yp); - uiSpinboxSetValue(x, xp); - uiSpinboxSetValue(y, yp); -} - -static void center(uiButton *b, void *data) -{ - uiWindow *w = uiWindow(data); - - uiWindowCenter(w); - updatepos(w); -} - -void onMove(uiWindow *w, void *data) -{ - printf("move\n"); - updatepos(w); -} - -uiBox *makePage15(uiWindow *w) -{ - hbox = newHorizontalBox(); - // TODO if I make this 1 and not add anything else AND not call uiWindowOnPositionChanged(), on OS X the box won't be able to grow vertically - uiBoxAppend(page15, uiControl(hbox), 0); - - uiBoxAppend(hbox, uiControl(uiNewLabel("Position")), 0); - x = uiNewSpinbox(INT_MIN, INT_MAX); - uiBoxAppend(hbox, uiControl(x), 1); - y = uiNewSpinbox(INT_MIN, INT_MAX); - uiBoxAppend(hbox, uiControl(y), 1); - button = uiNewButton("Center"); - uiBoxAppend(hbox, uiControl(button), 0); - - uiSpinboxOnChanged(x, moveX, w); - uiSpinboxOnChanged(y, moveY, w); - uiButtonOnClicked(button, center, w); - uiWindowOnPositionChanged(w, onMove, NULL); - updatepos(w); -} diff --git a/src/libui_sdl/libui/_abort/windowevents/ui.h b/src/libui_sdl/libui/_abort/windowevents/ui.h deleted file mode 100644 index e0d24c7..0000000 --- a/src/libui_sdl/libui/_abort/windowevents/ui.h +++ /dev/null @@ -1,6 +0,0 @@ -// uiWindowSetTitle -_UI_EXTERN void uiWindowPosition(uiWindow *w, int *x, int *y); -_UI_EXTERN void uiWindowSetPosition(uiWindow *w, int x, int y); -_UI_EXTERN void uiWindowCenter(uiWindow *w); -_UI_EXTERN void uiWindowOnPositionChanged(uiWindow *w, void (*f)(uiWindow *, void *), void *data); -// uiWindowContentSize diff --git a/src/libui_sdl/libui/_abort/windowevents/unix_window.c b/src/libui_sdl/libui/_abort/windowevents/unix_window.c deleted file mode 100644 index 96af26a..0000000 --- a/src/libui_sdl/libui/_abort/windowevents/unix_window.c +++ /dev/null @@ -1,97 +0,0 @@ -struct uiWindow { -// void *onClosingData; - void (*onPositionChanged)(uiWindow *, void *); - void *onPositionChangedData; - gboolean changingPosition; -// void (*onContentSizeChanged)(uiWindow *, void *); -}; - -// static gboolean onClosing(GtkWidget *win, GdkEvent *e, gpointer data) - -static gboolean onConfigure(GtkWidget *win, GdkEvent *e, gpointer data) -{ - uiWindow *w = uiWindow(data); - - // there doesn't seem to be a way to determine if only moving or only resizing is happening :/ - if (w->changingPosition) - w->changingPosition = FALSE; - else - (*(w->onPositionChanged))(w, w->onPositionChangedData); - // always continue handling - return FALSE; -} - -// static void onSizeAllocate(GtkWidget *widget, GdkRectangle *allocation, gpointer data) - -// static int defaultOnClosing(uiWindow *w, void *data) - -static void defaultOnPositionContentSizeChanged(uiWindow *w, void *data) -{ - // do nothing -} - -// static void uiWindowDestroy(uiControl *c) - -// void uiWindowSetTitle(uiWindow *w, const char *title) - -// TODO allow specifying either as NULL on all platforms -void uiWindowPosition(uiWindow *w, int *x, int *y) -{ - gint rx, ry; - - gtk_window_get_position(w->window, &rx, &ry); - *x = rx; - *y = ry; -} - -void uiWindowSetPosition(uiWindow *w, int x, int y) -{ - w->changingPosition = TRUE; - gtk_window_move(w->window, x, y); - // gtk_window_move() is asynchronous - // we need to wait for a configure-event - // thanks to hergertme in irc.gimp.net/#gtk+ - while (w->changingPosition) - if (!uiMainStep(1)) - break; // stop early if uiQuit() called -} - -void uiWindowCenter(uiWindow *w) -{ - gint x, y; - GtkAllocation winalloc; - GdkWindow *gdkwin; - GdkScreen *screen; - GdkRectangle workarea; - - gtk_widget_get_allocation(w->widget, &winalloc); - gdkwin = gtk_widget_get_window(w->widget); - screen = gdk_window_get_screen(gdkwin); - gdk_screen_get_monitor_workarea(screen, - gdk_screen_get_monitor_at_window(screen, gdkwin), - &workarea); - - x = (workarea.width - winalloc.width) / 2; - y = (workarea.height - winalloc.height) / 2; - // TODO move up slightly? see what Mutter or GNOME Shell or GNOME Terminal do(es)? - uiWindowSetPosition(w, x, y); -} - -// TODO this and size changed get set during uiWindowDestroy -void uiWindowOnPositionChanged(uiWindow *w, void (*f)(uiWindow *, void *), void *data) -{ - w->onPositionChanged = f; - w->onPositionChangedData = data; -} - -// void uiWindowContentSize(uiWindow *w, int *width, int *height) - -uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar) -{ -// g_signal_connect(w->widget, "delete-event", G_CALLBACK(onClosing), w); - g_signal_connect(w->widget, "configure-event", G_CALLBACK(onConfigure), w); -// g_signal_connect(w->childHolderWidget, "size-allocate", G_CALLBACK(onSizeAllocate), w); -// uiWindowOnClosing(w, defaultOnClosing, NULL); - uiWindowOnPositionChanged(w, defaultOnPositionContentSizeChanged, NULL); -// uiWindowOnContentSizeChanged(w, defaultOnPositionContentSizeChanged, NULL); -} diff --git a/src/libui_sdl/libui/_abort/windowevents/windows_window.cpp b/src/libui_sdl/libui/_abort/windowevents/windows_window.cpp deleted file mode 100644 index 769c6db..0000000 --- a/src/libui_sdl/libui/_abort/windowevents/windows_window.cpp +++ /dev/null @@ -1,86 +0,0 @@ -struct uiWindow { -// BOOL hasMenubar; - void (*onPositionChanged)(uiWindow *, void *); - void *onPositionChangedData; - BOOL changingPosition; // to avoid triggering the above when programmatically doing this -// void (*onContentSizeChanged)(uiWindow *, void *); -}; - -static LRESULT CALLBACK windowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - case WM_WINDOWPOSCHANGED: - if ((wp->flags & SWP_NOMOVE) == 0) - if (!w->changingPosition) - (*(w->onPositionChanged))(w, w->onPositionChangedData); - // and continue anyway -// if ((wp->flags & SWP_NOSIZE) != 0) -} - -// static int defaultOnClosing(uiWindow *w, void *data) - -static void defaultOnPositionContentSizeChanged(uiWindow *w, void *data) -{ - // do nothing -} - -// static std::map windows; - -// void uiWindowSetTitle(uiWindow *w, const char *title) - -void uiWindowPosition(uiWindow *w, int *x, int *y) -{ - RECT r; - - uiWindowsEnsureGetWindowRect(w->hwnd, &r); - *x = r.left; - *y = r.top; -} - -void uiWindowSetPosition(uiWindow *w, int x, int y) -{ - w->changingPosition = TRUE; - if (SetWindowPos(w->hwnd, NULL, x, y, 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER) == 0) - logLastError(L"error moving window"); - w->changingPosition = FALSE; -} - -// static void windowMonitorRect(HWND hwnd, RECT *r) - -// TODO use the work rect instead? -void uiWindowCenter(uiWindow *w) -{ - RECT wr, mr; - int x, y; - LONG wwid, mwid; - LONG wht, mht; - - uiWindowsEnsureGetWindowRect(w->hwnd, &wr); - windowMonitorRect(w->hwnd, &mr); - wwid = wr.right - wr.left; - mwid = mr.right - mr.left; - x = (mwid - wwid) / 2; - wht = wr.bottom - wr.top; - mht = mr.bottom - mr.top; - y = (mht - wht) / 2; - // y is now evenly divided, however https://msdn.microsoft.com/en-us/library/windows/desktop/dn742502(v=vs.85).aspx says that 45% should go above and 55% should go below - // so just move 5% of the way up - // TODO should this be on the work area? - // TODO is this calculation correct? - y -= y / 20; - uiWindowSetPosition(w, x, y); -} - -void uiWindowOnPositionChanged(uiWindow *w, void (*f)(uiWindow *, void *), void *data) -{ - w->onPositionChanged = f; - w->onPositionChangedData = data; -} - -// void uiWindowContentSize(uiWindow *w, int *width, int *height) - -uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar) -{ -// uiWindowOnClosing(w, defaultOnClosing, NULL); - uiWindowOnPositionChanged(w, defaultOnPositionContentSizeChanged, NULL); -// uiWindowOnContentSizeChanged(w, defaultOnPositionContentSizeChanged, NULL); -} diff --git a/src/libui_sdl/libui/_wip/rules.darwin b/src/libui_sdl/libui/_wip/rules.darwin deleted file mode 100644 index e736a14..0000000 --- a/src/libui_sdl/libui/_wip/rules.darwin +++ /dev/null @@ -1,6 +0,0 @@ -every rule in ui_darwin.h -SetParent must be followed by SetSuperview and SyncEnableState - TODO can child cache it? -adding a child must be followed by a call to SyncEnableState -SyncEnableState() must call ShouldStopSyncEnableState() first thing -Enable() and Disable() must call SyncEnableState() AFTER CHANGING WHAT Enabled() WILL RETURN diff --git a/src/libui_sdl/libui/_wip/rules.unix b/src/libui_sdl/libui/_wip/rules.unix deleted file mode 100644 index 24765a9..0000000 --- a/src/libui_sdl/libui/_wip/rules.unix +++ /dev/null @@ -1,3 +0,0 @@ -every rule in ui_unix.h -SetParent must be followed by SetContainer - TODO can child cache it? diff --git a/src/libui_sdl/libui/_wip/sv/normal b/src/libui_sdl/libui/_wip/sv/normal deleted file mode 100644 index 8b6af87..0000000 --- a/src/libui_sdl/libui/_wip/sv/normal +++ /dev/null @@ -1,25 +0,0 @@ -2016-05-26 22:38:12.877 svtest[81790:544681] backgroundColor NSNamedColorSpace System controlColor -2016-05-26 22:38:12.877 svtest[81790:544681] drawsBackground 1 -2016-05-26 22:38:12.877 svtest[81790:544681] borderType 2 -2016-05-26 22:38:12.877 svtest[81790:544681] documentCursor (null) -2016-05-26 22:38:12.877 svtest[81790:544681] hasHorizontalScroller 1 -2016-05-26 22:38:12.877 svtest[81790:544681] hasVerticalScroller 1 -2016-05-26 22:38:12.877 svtest[81790:544681] autohidesScrollers 0 -2016-05-26 22:38:12.877 svtest[81790:544681] hasHorizontalRuler 0 -2016-05-26 22:38:12.878 svtest[81790:544681] hasVerticalRuler 0 -2016-05-26 22:38:12.878 svtest[81790:544681] rulersVisible 0 -2016-05-26 22:38:12.878 svtest[81790:544681] 10.10 autoAdjContentInsets 1 -2016-05-26 22:38:12.878 svtest[81790:544681] scrollerKnobStyle 0 -2016-05-26 22:38:12.878 svtest[81790:544681] scrollerStyle 1 -2016-05-26 22:38:12.878 svtest[81790:544681] horizontalLineScroll 10 -2016-05-26 22:38:12.878 svtest[81790:544681] verticalLineScroll 10 -2016-05-26 22:38:12.886 svtest[81790:544681] horizontalPageScroll 10 -2016-05-26 22:38:12.886 svtest[81790:544681] verticalPageScroll 10 -2016-05-26 22:38:12.886 svtest[81790:544681] scrollsDynamically 1 -2016-05-26 22:38:12.886 svtest[81790:544681] findBarPosition 1 -2016-05-26 22:38:12.886 svtest[81790:544681] usesPredomAxisScroll 0 -2016-05-26 22:38:12.886 svtest[81790:544681] horizontalElasticity 0 -2016-05-26 22:38:12.886 svtest[81790:544681] verticalElasticity 0 -2016-05-26 22:38:12.887 svtest[81790:544681] 10.8 allowsMagnification 0 -2016-05-26 22:38:12.887 svtest[81790:544681] 10.8 maxMagnification 4 -2016-05-26 22:38:12.887 svtest[81790:544681] 10.8 minMagnification 0.25 diff --git a/src/libui_sdl/libui/_wip/sv/normal.nots b/src/libui_sdl/libui/_wip/sv/normal.nots deleted file mode 100644 index 411d1d6..0000000 --- a/src/libui_sdl/libui/_wip/sv/normal.nots +++ /dev/null @@ -1,25 +0,0 @@ - backgroundColor NSNamedColorSpace System controlColor - drawsBackground 1 - borderType 2 - documentCursor (null) - hasHorizontalScroller 1 - hasVerticalScroller 1 - autohidesScrollers 0 - hasHorizontalRuler 0 - hasVerticalRuler 0 - rulersVisible 0 - 10.10 autoAdjContentInsets 1 - scrollerKnobStyle 0 - scrollerStyle 1 - horizontalLineScroll 10 - verticalLineScroll 10 - horizontalPageScroll 10 - verticalPageScroll 10 - scrollsDynamically 1 - findBarPosition 1 - usesPredomAxisScroll 0 - horizontalElasticity 0 - verticalElasticity 0 - 10.8 allowsMagnification 0 - 10.8 maxMagnification 4 - 10.8 minMagnification 0.25 diff --git a/src/libui_sdl/libui/_wip/sv/outlineview b/src/libui_sdl/libui/_wip/sv/outlineview deleted file mode 100644 index 67a3087..0000000 --- a/src/libui_sdl/libui/_wip/sv/outlineview +++ /dev/null @@ -1,25 +0,0 @@ -2016-05-26 22:42:16.208 svtest[82103:547159] backgroundColor NSNamedColorSpace System controlBackgroundColor -2016-05-26 22:42:16.208 svtest[82103:547159] drawsBackground 1 -2016-05-26 22:42:16.208 svtest[82103:547159] borderType 2 -2016-05-26 22:42:16.208 svtest[82103:547159] documentCursor (null) -2016-05-26 22:42:16.209 svtest[82103:547159] hasHorizontalScroller 1 -2016-05-26 22:42:16.209 svtest[82103:547159] hasVerticalScroller 1 -2016-05-26 22:42:16.209 svtest[82103:547159] autohidesScrollers 1 -2016-05-26 22:42:16.209 svtest[82103:547159] hasHorizontalRuler 0 -2016-05-26 22:42:16.209 svtest[82103:547159] hasVerticalRuler 0 -2016-05-26 22:42:16.209 svtest[82103:547159] rulersVisible 0 -2016-05-26 22:42:16.209 svtest[82103:547159] 10.10 autoAdjContentInsets 1 -2016-05-26 22:42:16.209 svtest[82103:547159] scrollerKnobStyle 0 -2016-05-26 22:42:16.209 svtest[82103:547159] scrollerStyle 1 -2016-05-26 22:42:16.209 svtest[82103:547159] horizontalLineScroll 19 -2016-05-26 22:42:16.209 svtest[82103:547159] verticalLineScroll 19 -2016-05-26 22:42:16.217 svtest[82103:547159] horizontalPageScroll 10 -2016-05-26 22:42:16.218 svtest[82103:547159] verticalPageScroll 10 -2016-05-26 22:42:16.218 svtest[82103:547159] scrollsDynamically 1 -2016-05-26 22:42:16.218 svtest[82103:547159] findBarPosition 1 -2016-05-26 22:42:16.218 svtest[82103:547159] usesPredomAxisScroll 0 -2016-05-26 22:42:16.218 svtest[82103:547159] horizontalElasticity 0 -2016-05-26 22:42:16.218 svtest[82103:547159] verticalElasticity 0 -2016-05-26 22:42:16.218 svtest[82103:547159] 10.8 allowsMagnification 0 -2016-05-26 22:42:16.218 svtest[82103:547159] 10.8 maxMagnification 4 -2016-05-26 22:42:16.218 svtest[82103:547159] 10.8 minMagnification 0.25 diff --git a/src/libui_sdl/libui/_wip/sv/outlineview.nots b/src/libui_sdl/libui/_wip/sv/outlineview.nots deleted file mode 100644 index fcf1849..0000000 --- a/src/libui_sdl/libui/_wip/sv/outlineview.nots +++ /dev/null @@ -1,25 +0,0 @@ - backgroundColor NSNamedColorSpace System controlBackgroundColor - drawsBackground 1 - borderType 2 - documentCursor (null) - hasHorizontalScroller 1 - hasVerticalScroller 1 - autohidesScrollers 1 - hasHorizontalRuler 0 - hasVerticalRuler 0 - rulersVisible 0 - 10.10 autoAdjContentInsets 1 - scrollerKnobStyle 0 - scrollerStyle 1 - horizontalLineScroll 19 - verticalLineScroll 19 - horizontalPageScroll 10 - verticalPageScroll 10 - scrollsDynamically 1 - findBarPosition 1 - usesPredomAxisScroll 0 - horizontalElasticity 0 - verticalElasticity 0 - 10.8 allowsMagnification 0 - 10.8 maxMagnification 4 - 10.8 minMagnification 0.25 diff --git a/src/libui_sdl/libui/_wip/sv/sourcelist b/src/libui_sdl/libui/_wip/sv/sourcelist deleted file mode 100644 index 010d652..0000000 --- a/src/libui_sdl/libui/_wip/sv/sourcelist +++ /dev/null @@ -1,25 +0,0 @@ -2016-05-26 22:43:58.600 svtest[82237:548359] backgroundColor (null) -2016-05-26 22:43:58.600 svtest[82237:548359] drawsBackground 0 -2016-05-26 22:43:58.600 svtest[82237:548359] borderType 2 -2016-05-26 22:43:58.600 svtest[82237:548359] documentCursor (null) -2016-05-26 22:43:58.600 svtest[82237:548359] hasHorizontalScroller 1 -2016-05-26 22:43:58.600 svtest[82237:548359] hasVerticalScroller 1 -2016-05-26 22:43:58.600 svtest[82237:548359] autohidesScrollers 1 -2016-05-26 22:43:58.600 svtest[82237:548359] hasHorizontalRuler 0 -2016-05-26 22:43:58.600 svtest[82237:548359] hasVerticalRuler 0 -2016-05-26 22:43:58.600 svtest[82237:548359] rulersVisible 0 -2016-05-26 22:43:58.601 svtest[82237:548359] 10.10 autoAdjContentInsets 1 -2016-05-26 22:43:58.601 svtest[82237:548359] scrollerKnobStyle 0 -2016-05-26 22:43:58.601 svtest[82237:548359] scrollerStyle 1 -2016-05-26 22:43:58.601 svtest[82237:548359] horizontalLineScroll 19 -2016-05-26 22:43:58.601 svtest[82237:548359] verticalLineScroll 19 -2016-05-26 22:43:58.645 svtest[82237:548359] horizontalPageScroll 10 -2016-05-26 22:43:58.645 svtest[82237:548359] verticalPageScroll 10 -2016-05-26 22:43:58.645 svtest[82237:548359] scrollsDynamically 1 -2016-05-26 22:43:58.645 svtest[82237:548359] findBarPosition 1 -2016-05-26 22:43:58.645 svtest[82237:548359] usesPredomAxisScroll 0 -2016-05-26 22:43:58.645 svtest[82237:548359] horizontalElasticity 0 -2016-05-26 22:43:58.646 svtest[82237:548359] verticalElasticity 0 -2016-05-26 22:43:58.646 svtest[82237:548359] 10.8 allowsMagnification 0 -2016-05-26 22:43:58.646 svtest[82237:548359] 10.8 maxMagnification 4 -2016-05-26 22:43:58.646 svtest[82237:548359] 10.8 minMagnification 0.25 diff --git a/src/libui_sdl/libui/_wip/sv/sourcelist.nots b/src/libui_sdl/libui/_wip/sv/sourcelist.nots deleted file mode 100644 index 742f41e..0000000 --- a/src/libui_sdl/libui/_wip/sv/sourcelist.nots +++ /dev/null @@ -1,25 +0,0 @@ - backgroundColor (null) - drawsBackground 0 - borderType 2 - documentCursor (null) - hasHorizontalScroller 1 - hasVerticalScroller 1 - autohidesScrollers 1 - hasHorizontalRuler 0 - hasVerticalRuler 0 - rulersVisible 0 - 10.10 autoAdjContentInsets 1 - scrollerKnobStyle 0 - scrollerStyle 1 - horizontalLineScroll 19 - verticalLineScroll 19 - horizontalPageScroll 10 - verticalPageScroll 10 - scrollsDynamically 1 - findBarPosition 1 - usesPredomAxisScroll 0 - horizontalElasticity 0 - verticalElasticity 0 - 10.8 allowsMagnification 0 - 10.8 maxMagnification 4 - 10.8 minMagnification 0.25 diff --git a/src/libui_sdl/libui/_wip/sv/tableview b/src/libui_sdl/libui/_wip/sv/tableview deleted file mode 100644 index 558b6e1..0000000 --- a/src/libui_sdl/libui/_wip/sv/tableview +++ /dev/null @@ -1,25 +0,0 @@ -2016-05-26 22:41:26.514 svtest[82032:546554] backgroundColor NSNamedColorSpace System controlBackgroundColor -2016-05-26 22:41:26.514 svtest[82032:546554] drawsBackground 1 -2016-05-26 22:41:26.514 svtest[82032:546554] borderType 2 -2016-05-26 22:41:26.514 svtest[82032:546554] documentCursor (null) -2016-05-26 22:41:26.515 svtest[82032:546554] hasHorizontalScroller 1 -2016-05-26 22:41:26.515 svtest[82032:546554] hasVerticalScroller 1 -2016-05-26 22:41:26.515 svtest[82032:546554] autohidesScrollers 1 -2016-05-26 22:41:26.515 svtest[82032:546554] hasHorizontalRuler 0 -2016-05-26 22:41:26.516 svtest[82032:546554] hasVerticalRuler 0 -2016-05-26 22:41:26.516 svtest[82032:546554] rulersVisible 0 -2016-05-26 22:41:26.516 svtest[82032:546554] 10.10 autoAdjContentInsets 1 -2016-05-26 22:41:26.516 svtest[82032:546554] scrollerKnobStyle 0 -2016-05-26 22:41:26.516 svtest[82032:546554] scrollerStyle 1 -2016-05-26 22:41:26.516 svtest[82032:546554] horizontalLineScroll 19 -2016-05-26 22:41:26.516 svtest[82032:546554] verticalLineScroll 19 -2016-05-26 22:41:26.528 svtest[82032:546554] horizontalPageScroll 10 -2016-05-26 22:41:26.528 svtest[82032:546554] verticalPageScroll 10 -2016-05-26 22:41:26.528 svtest[82032:546554] scrollsDynamically 1 -2016-05-26 22:41:26.528 svtest[82032:546554] findBarPosition 1 -2016-05-26 22:41:26.528 svtest[82032:546554] usesPredomAxisScroll 0 -2016-05-26 22:41:26.528 svtest[82032:546554] horizontalElasticity 0 -2016-05-26 22:41:26.528 svtest[82032:546554] verticalElasticity 0 -2016-05-26 22:41:26.528 svtest[82032:546554] 10.8 allowsMagnification 0 -2016-05-26 22:41:26.528 svtest[82032:546554] 10.8 maxMagnification 4 -2016-05-26 22:41:26.528 svtest[82032:546554] 10.8 minMagnification 0.25 diff --git a/src/libui_sdl/libui/_wip/sv/tableview.nots b/src/libui_sdl/libui/_wip/sv/tableview.nots deleted file mode 100644 index fcf1849..0000000 --- a/src/libui_sdl/libui/_wip/sv/tableview.nots +++ /dev/null @@ -1,25 +0,0 @@ - backgroundColor NSNamedColorSpace System controlBackgroundColor - drawsBackground 1 - borderType 2 - documentCursor (null) - hasHorizontalScroller 1 - hasVerticalScroller 1 - autohidesScrollers 1 - hasHorizontalRuler 0 - hasVerticalRuler 0 - rulersVisible 0 - 10.10 autoAdjContentInsets 1 - scrollerKnobStyle 0 - scrollerStyle 1 - horizontalLineScroll 19 - verticalLineScroll 19 - horizontalPageScroll 10 - verticalPageScroll 10 - scrollsDynamically 1 - findBarPosition 1 - usesPredomAxisScroll 0 - horizontalElasticity 0 - verticalElasticity 0 - 10.8 allowsMagnification 0 - 10.8 maxMagnification 4 - 10.8 minMagnification 0.25 diff --git a/src/libui_sdl/libui/_wip/sv/textview b/src/libui_sdl/libui/_wip/sv/textview deleted file mode 100644 index e636362..0000000 --- a/src/libui_sdl/libui/_wip/sv/textview +++ /dev/null @@ -1,25 +0,0 @@ -2016-05-26 22:40:02.050 svtest[81927:545793] backgroundColor NSCalibratedWhiteColorSpace 1 1 -2016-05-26 22:40:02.050 svtest[81927:545793] drawsBackground 1 -2016-05-26 22:40:02.051 svtest[81927:545793] borderType 2 -2016-05-26 22:40:02.052 svtest[81927:545793] documentCursor -2016-05-26 22:40:02.052 svtest[81927:545793] hasHorizontalScroller 0 -2016-05-26 22:40:02.052 svtest[81927:545793] hasVerticalScroller 1 -2016-05-26 22:40:02.052 svtest[81927:545793] autohidesScrollers 0 -2016-05-26 22:40:02.052 svtest[81927:545793] hasHorizontalRuler 0 -2016-05-26 22:40:02.052 svtest[81927:545793] hasVerticalRuler 0 -2016-05-26 22:40:02.052 svtest[81927:545793] rulersVisible 0 -2016-05-26 22:40:02.052 svtest[81927:545793] 10.10 autoAdjContentInsets 1 -2016-05-26 22:40:02.052 svtest[81927:545793] scrollerKnobStyle 0 -2016-05-26 22:40:02.052 svtest[81927:545793] scrollerStyle 1 -2016-05-26 22:40:02.054 svtest[81927:545793] horizontalLineScroll 10 -2016-05-26 22:40:02.055 svtest[81927:545793] verticalLineScroll 10 -2016-05-26 22:40:02.062 svtest[81927:545793] horizontalPageScroll 10 -2016-05-26 22:40:02.062 svtest[81927:545793] verticalPageScroll 10 -2016-05-26 22:40:02.062 svtest[81927:545793] scrollsDynamically 1 -2016-05-26 22:40:02.062 svtest[81927:545793] findBarPosition 1 -2016-05-26 22:40:02.062 svtest[81927:545793] usesPredomAxisScroll 0 -2016-05-26 22:40:02.062 svtest[81927:545793] horizontalElasticity 0 -2016-05-26 22:40:02.062 svtest[81927:545793] verticalElasticity 0 -2016-05-26 22:40:02.062 svtest[81927:545793] 10.8 allowsMagnification 0 -2016-05-26 22:40:02.062 svtest[81927:545793] 10.8 maxMagnification 4 -2016-05-26 22:40:02.063 svtest[81927:545793] 10.8 minMagnification 0.25 diff --git a/src/libui_sdl/libui/_wip/sv/textview.nots b/src/libui_sdl/libui/_wip/sv/textview.nots deleted file mode 100644 index 7476b0e..0000000 --- a/src/libui_sdl/libui/_wip/sv/textview.nots +++ /dev/null @@ -1,25 +0,0 @@ - backgroundColor NSCalibratedWhiteColorSpace 1 1 - drawsBackground 1 - borderType 2 - documentCursor - hasHorizontalScroller 0 - hasVerticalScroller 1 - autohidesScrollers 0 - hasHorizontalRuler 0 - hasVerticalRuler 0 - rulersVisible 0 - 10.10 autoAdjContentInsets 1 - scrollerKnobStyle 0 - scrollerStyle 1 - horizontalLineScroll 10 - verticalLineScroll 10 - horizontalPageScroll 10 - verticalPageScroll 10 - scrollsDynamically 1 - findBarPosition 1 - usesPredomAxisScroll 0 - horizontalElasticity 0 - verticalElasticity 0 - 10.8 allowsMagnification 0 - 10.8 maxMagnification 4 - 10.8 minMagnification 0.25 diff --git a/src/libui_sdl/libui/_wip/table/test_page9.c b/src/libui_sdl/libui/_wip/table/test_page9.c deleted file mode 100644 index f2351f2..0000000 --- a/src/libui_sdl/libui/_wip/table/test_page9.c +++ /dev/null @@ -1,80 +0,0 @@ -// 18 october 2015 -#include "test.h" - -// TODO manage the memory of the uiTableModel - -static intmax_t nColumns = 4; -static uiTableColumnType coltypes[] = { - uiTableColumnText, - uiTableColumnText, - uiTableColumnCheckbox, - uiTableColumnCheckbox, -}; - -static intmax_t nRows = 6; - -static intmax_t modelNumRows(uiTableModel *m, void *mData) -{ - return nRows; -} - -void *modelCellValue(uiTableModel *m, void *mData, intmax_t row, intmax_t column) -{ - char line[20]; - - line[0] = 'R'; - line[1] = 'o'; - line[2] = 'w'; - line[3] = ' '; - line[4] = row + '0'; - line[5] = '\0'; - switch (column) { - case 0: - case 1: - return uiTableModelFromString(line); - case 2: - return uiTableModelFromBool(row % 2 == 0); - case 3: - return uiTableModelFromBool(row % 3 == 0); - } - // TODO - return NULL; -} - -// TODO make this not need to be static -uiTableModelSpec spec; - -void modelSetCellValue(uiTableModel *m, void *mData, intmax_t row, intmax_t column, void *value) -{ - // TODO -} - -uiBox *makePage9(void) -{ - uiBox *page9; - uiTable *table; - uiTableModel *model; - uiTableColumnParams p; - intmax_t i; - - page9 = newVerticalBox(); - - table = uiNewTable(); - uiBoxAppend(page9, uiControl(table), 1); - - spec.NumRows = modelNumRows; - spec.CellValue = modelCellValue; - spec.SetCellValue = modelSetCellValue; - model = uiNewTableModel(nColumns, coltypes, &spec, NULL); - uiTableSetModel(table, model); - - for (i = 0; i < nColumns; i++) { - p.Name = "Column"; - p.Type = coltypes[i]; - p.Mutable = i % 2 == 1; - p.ValueColumn = i; - uiTableAppendColumn(table, &p); - } - - return page9; -} diff --git a/src/libui_sdl/libui/_wip/table/ui.h b/src/libui_sdl/libui/_wip/table/ui.h deleted file mode 100644 index a5c30c8..0000000 --- a/src/libui_sdl/libui/_wip/table/ui.h +++ /dev/null @@ -1,46 +0,0 @@ -typedef struct uiTable uiTable; -typedef struct uiTableModel uiTableModel; -typedef struct uiTableModelSpec uiTableModelSpec; -typedef struct uiTableColumnParams uiTableColumnParams; -typedef enum uiTableColumnType uiTableColumnType; -typedef enum uiTableNotification uiTableNotification; - -_UI_EXTERN uintmax_t uiTableType(void); -#define uiTable(this) ((uiTable *) uiIsA((this), uiTableType(), 1)) -_UI_EXTERN void uiTableSetModel(uiTable *t, uiTableModel *m); -_UI_EXTERN void uiTableAppendColumn(uiTable *t, uiTableColumnParams *p); -_UI_EXTERN uiTable *uiNewTable(void); - -enum uiTableColumnType { - uiTableColumnText, -//TODO uiTableColumnImage, - uiTableColumnCheckbox, -}; - -struct uiTableModelSpec { - intmax_t (*NumRows)(uiTableModel *m, void *mData); - void *(*CellValue)(uiTableModel *m, void *mData, intmax_t row, intmax_t column); - void (*SetCellValue)(uiTableModel *m, void *mData, intmax_t row, intmax_t column, void *value); -}; - -enum uiTableNotification { - uiTableRowInserted, - uiTableRowDeleted, - uiTableCellChanged, -}; - -_UI_EXTERN uiTableModel *uiNewTableModel(uintmax_t nCols, uiTableColumnType *types, uiTableModelSpec *spec, void *mData); -_UI_EXTERN void uiFreeTableModel(uiTableModel *m); -_UI_EXTERN void uiTableModelNotify(uiTableModel *m, uiTableNotification notification, intmax_t row, intmax_t column); - -#define uiTableModelFromBool(b) ((void *) ((intptr_t) (b))) -_UI_EXTERN void *uiTableModelFromString(const char *str); - -struct uiTableColumnParams { - const char *Name; - // TODO make this unnecessary - uiTableColumnType Type; - int Mutable; // TODO move to the model? - intmax_t ValueColumn; - // TODO background color -}; diff --git a/src/libui_sdl/libui/_wip/table/unix_table.c b/src/libui_sdl/libui/_wip/table/unix_table.c deleted file mode 100644 index 825cf67..0000000 --- a/src/libui_sdl/libui/_wip/table/unix_table.c +++ /dev/null @@ -1,87 +0,0 @@ -// 18 october 2015 -#include "uipriv_unix.h" - -struct uiTable { - uiUnixControl c; - GtkWidget *widget; - GtkContainer *scontainer; - GtkScrolledWindow *sw; - GtkWidget *treeWidget; - GtkTreeView *treeview; - GtkTreeSelection *selection; - uiTableModel *model; -}; - -uiUnixDefineControl( - uiTable // type name -) - -void uiTableSetModel(uiTable *t, uiTableModel *m) -{ - t->model = m; - gtk_tree_view_set_model(t->treeview, GTK_TREE_MODEL(t->model)); -} - -void uiTableAppendColumn(uiTable *t, uiTableColumnParams *p) -{ - GtkTreeViewColumn *col; - GtkCellRenderer *r; - const char *attribute; - const char *mutableAttr; - gboolean mutable; - - switch (p->Type) { - case uiTableColumnText: - r = gtk_cell_renderer_text_new(); - attribute = "text"; - mutableAttr = "editable"; - break; -//TODO case uiTableColumnImage: - // TODO - case uiTableColumnCheckbox: - r = gtk_cell_renderer_toggle_new(); - attribute = "active"; - mutableAttr = "activatable"; - break; - default: - complain("unknown table column type %d in uiTableAppendColumn()", p->Type); - } - mutable = FALSE; - if (p->Mutable) - mutable = TRUE; - g_object_set(r, - mutableAttr, mutable, - NULL); - col = gtk_tree_view_column_new_with_attributes(p->Name, r, - attribute, p->ValueColumn, - NULL); - // allow columns to be resized - gtk_tree_view_column_set_resizable(col, TRUE); - gtk_tree_view_append_column(t->treeview, col); -} - -uiTable *uiNewTable(void) -{ - uiTable *t; - - t = (uiTable *) uiNewControl(uiTableType()); - - t->widget = gtk_scrolled_window_new(NULL, NULL); - t->scontainer = GTK_CONTAINER(t->widget); - t->sw = GTK_SCROLLED_WINDOW(t->widget); - - t->treeWidget = gtk_tree_view_new(); - t->treeview = GTK_TREE_VIEW(t->treeWidget); - - t->selection = gtk_tree_view_get_selection(t->treeview); - - // give a border and add the table - gtk_scrolled_window_set_shadow_type(t->sw, GTK_SHADOW_IN); - gtk_container_add(t->scontainer, t->treeWidget); - // and make the table visible; only the scrolled window's visibility is controlled by libui - gtk_widget_show(t->treeWidget); - - uiUnixFinishNewControl(t, uiTable); - - return t; -} diff --git a/src/libui_sdl/libui/_wip/table/unix_tablemodel.c b/src/libui_sdl/libui/_wip/table/unix_tablemodel.c deleted file mode 100644 index 0223465..0000000 --- a/src/libui_sdl/libui/_wip/table/unix_tablemodel.c +++ /dev/null @@ -1,303 +0,0 @@ -// 18 october 2015 -#include "uipriv_unix.h" - -// On GTK+, uiTableModel is a GtkTreeModel. - -#define uiTableModelType (uiTableModel_get_type()) -#define uiTableModel(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), uiTableModelType, uiTableModel)) -#define isAreaWidget(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), uiTableModelType)) -#define uiTableModelClass(class) (G_TYPE_CHECK_CLASS_CAST((class), uiTableModelType, uiTableModelClass)) -#define isAreaWidgetClass(class) (G_TYPE_CHECK_CLASS_TYPE((class), uiTableModel)) -#define getAreaWidgetClass(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), uiTableModelType, uiTableModelClass)) - -typedef struct uiTableModel uiTableModel; -typedef struct uiTableModelClass uiTableModelClass; - -struct uiTableModel { - GObject parent_instance; - uiTableModelSpec *spec; - void *mData; - intmax_t nColumns; - GType *coltypes; -}; - -struct uiTableModelClass { - GObjectClass parent_class; -}; - -static void uiTableModel_treeModel_init(GtkTreeModelIface *); - -G_DEFINE_TYPE_WITH_CODE(uiTableModel, uiTableModel, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE(GTK_TYPE_TREE_MODEL, uiTableModel_treeModel_init)) - -static void uiTableModel_init(uiTableModel *m) -{ - // do nothing -} - -static void uiTableModel_dispose(GObject *obj) -{ - G_OBJECT_CLASS(uiTableModel_parent_class)->dispose(obj); -} - -static void uiTableModel_finalize(GObject *obj) -{ - uiTableModel *m = uiTableModel(obj); - - uiFree(m->coltypes); - G_OBJECT_CLASS(uiTableModel_parent_class)->finalize(obj); -} - -static GtkTreeModelFlags uiTableModel_get_flags(GtkTreeModel *mb) -{ - return GTK_TREE_MODEL_LIST_ONLY; -} - -static gint uiTableModel_get_n_columns(GtkTreeModel *mb) -{ - uiTableModel *m = uiTableModel(mb); - - return m->nColumns; -} - -static GType uiTableModel_get_column_type(GtkTreeModel *mb, gint index) -{ - uiTableModel *m = uiTableModel(mb); - - return m->coltypes[index]; -} - -/* -how our GtkTreeIters are stored: - stamp: either GOOD_STAMP or BAD_STAMP - user_data: row index -Thanks to Company in irc.gimp.net/#gtk+ for suggesting the GSIZE_TO_POINTER() t -rick. -*/ -#define GOOD_STAMP 0x1234 -#define BAD_STAMP 0x5678 -#define FROM(x) ((gint) GPOINTER_TO_SIZE((x))) -#define TO(x) GSIZE_TO_POINTER((gsize) (x)) - -#define numRows(m) ((*((m)->spec->NumRows))((m), (m)->mData)) -#define cellValue(m, row, col) ((*((m)->spec->CellValue))((m), (m)->mData, row, column)) - -static gboolean uiTableModel_get_iter(GtkTreeModel *mb, GtkTreeIter *iter, GtkTreePath *path) -{ - uiTableModel *m = uiTableModel(mb); - gint index; - - if (gtk_tree_path_get_depth(path) != 1) - goto bad; - index = gtk_tree_path_get_indices(path)[0]; - if (index < 0) - goto bad; - if (index >= numRows(m)) - goto bad; - iter->stamp = GOOD_STAMP; - iter->user_data = TO(index); - return TRUE; -bad: - iter->stamp = BAD_STAMP; - return FALSE; -} - -static GtkTreePath *uiTableModel_get_path(GtkTreeModel *mb, GtkTreeIter *iter) -{ - // note: from this point forward, the GOOD_STAMP checks ensure that the index stored in iter is nonnegative - if (iter->stamp != GOOD_STAMP) - return NULL; // this is what both GtkListStore and GtkTreeStore do - return gtk_tree_path_new_from_indices(FROM(iter->user_data), -1); -} - -void *uiTableModelFromString(const char *str) -{ - return g_strdup(str); -} - -#define toBool(v) ((int) ((intptr_t) (v))) -#define toStr(v) ((char *) (v)) - -static void uiTableModel_get_value(GtkTreeModel *mb, GtkTreeIter *iter, gint column, GValue *value) -{ - uiTableModel *m = uiTableModel(mb); - void *v; - GType type; - - if (iter->stamp != GOOD_STAMP) - return; // this is what both GtkListStore and GtkTreeStore do - v = cellValue(m, FROM(iter->user_data), column); - type = m->coltypes[column]; - g_value_init(value, type); - if (type == G_TYPE_STRING) - g_value_take_string(value, toStr(v)); - // the GValue now manages the memory of the string that was g_strdup()'d before - // TODO image - else if (type == G_TYPE_BOOLEAN) - g_value_set_boolean(value, toBool(v)); - else - complain("unknown GType in uiTableModel_get_value()"); -} - -static gboolean uiTableModel_iter_next(GtkTreeModel *mb, GtkTreeIter *iter) -{ - uiTableModel *m = uiTableModel(mb); - gint index; - - if (iter->stamp != GOOD_STAMP) - return FALSE; // this is what both GtkListStore and GtkTreeStore do - index = FROM(iter->user_data); - index++; - if (index >= numRows(m)) { - iter->stamp = BAD_STAMP; - return FALSE; - } - iter->user_data = TO(index); - return TRUE; -} - -static gboolean uiTableModel_iter_previous(GtkTreeModel *mb, GtkTreeIter *iter) -{ - uiTableModel *m = uiTableModel(mb); - gint index; - - if (iter->stamp != GOOD_STAMP) - return FALSE; // this is what both GtkListStore and GtkTreeStore do - index = FROM(iter->user_data); - if (index <= 0) { - iter->stamp = BAD_STAMP; - return FALSE; - } - index--; - iter->user_data = TO(index); - return TRUE; -} - -static gboolean uiTableModel_iter_children(GtkTreeModel *mb, GtkTreeIter *iter, GtkTreeIter *parent) -{ - uiTableModel *m = uiTableModel(mb); - - if (parent == NULL && numRows(m) > 0) { - iter->stamp = GOOD_STAMP; - iter->user_data = 0; - return TRUE; - } - iter->stamp = BAD_STAMP; - return FALSE; -} - -static gboolean uiTableModel_iter_has_child(GtkTreeModel *mb, GtkTreeIter *iter) -{ - return FALSE; -} - -static gint uiTableModel_iter_n_children(GtkTreeModel *mb, GtkTreeIter *iter) -{ - uiTableModel *m = uiTableModel(mb); - - if (iter == NULL) - return numRows(m); - return 0; -} - -static gboolean uiTableModel_iter_nth_child(GtkTreeModel *mb, GtkTreeIter *iter, GtkTreeIter *parent, gint n) -{ - uiTableModel *m = uiTableModel(mb); - - if (parent == NULL && n >= 0 && n < numRows(m)) { - iter->stamp = GOOD_STAMP; - iter->user_data = TO(n); - return TRUE; - } - iter->stamp = BAD_STAMP; - return FALSE; -} - -static gboolean uiTableModel_iter_parent(GtkTreeModel *mb, GtkTreeIter *iter, GtkTreeIter *child) -{ - iter->stamp = BAD_STAMP; - return FALSE; -} - -static void uiTableModel_class_init(uiTableModelClass *class) -{ - G_OBJECT_CLASS(class)->dispose = uiTableModel_dispose; - G_OBJECT_CLASS(class)->finalize = uiTableModel_finalize; -} - -static void uiTableModel_treeModel_init(GtkTreeModelIface *iface) -{ - iface->get_flags = uiTableModel_get_flags; - iface->get_n_columns = uiTableModel_get_n_columns; - iface->get_column_type = uiTableModel_get_column_type; - iface->get_iter = uiTableModel_get_iter; - iface->get_path = uiTableModel_get_path; - iface->get_value = uiTableModel_get_value; - iface->iter_next = uiTableModel_iter_next; - iface->iter_previous = uiTableModel_iter_previous; - iface->iter_children = uiTableModel_iter_children; - iface->iter_has_child = uiTableModel_iter_has_child; - iface->iter_n_children = uiTableModel_iter_n_children; - iface->iter_nth_child = uiTableModel_iter_nth_child; - iface->iter_parent = uiTableModel_iter_parent; - // no need for ref_node or unref_node -} - -uiTableModel *uiNewTableModel(uintmax_t nCols, uiTableColumnType *types, uiTableModelSpec *spec, void *mData) -{ - uiTableModel *m; - intmax_t i; - - m = uiTableModel(g_object_new(uiTableModelType, NULL)); - m->spec = spec; - m->mData = mData; - m->nColumns = nCols; - m->coltypes = (GType *) uiAlloc(m->nColumns * sizeof (GType), "GType[]"); - for (i = 0; i < m->nColumns; i++) - switch (types[i]) { - case uiTableColumnText: - m->coltypes[i] = G_TYPE_STRING; - break; -//TODO case uiTableColumnImage: - // TODO - case uiTableColumnCheckbox: - m->coltypes[i] = G_TYPE_BOOLEAN; - break; - default: - complain("unknown column type %d in uiNewTableModel()", types[i]); - } - return m; -} - -// TODO ensure no tables are subscribed -void uiFreeTableModel(uiTableModel *m) -{ - g_object_unref(m); -} - -void uiTableModelNotify(uiTableModel *m, uiTableNotification notification, intmax_t row, intmax_t column) -{ - GtkTreeModel *model = GTK_TREE_MODEL(m); - GtkTreePath *path; - GtkTreeIter iter; - - path = gtk_tree_path_new_from_indices(row, -1); - switch (notification) { - case uiTableRowInserted: - if (gtk_tree_model_get_iter(model, &iter, path) == FALSE) - complain("invalid row given to row inserted in uiTableModelNotify()"); - gtk_tree_model_row_inserted(model, path, &iter); - break; - case uiTableRowDeleted: - gtk_tree_model_row_deleted(model, path); - break; - case uiTableCellChanged: - if (gtk_tree_model_get_iter(model, &iter, path) == FALSE) - complain("invalid row given to row changed in uiTableModelNotify()"); - gtk_tree_model_row_changed(model, path, &iter); - break; - default: - complain("unknown uiTable notification %d in uiTableModelNotify()", notification); - } - gtk_tree_path_free(path); -} diff --git a/src/libui_sdl/libui/common/CMakeLists.txt b/src/libui_sdl/libui/common/CMakeLists.txt deleted file mode 100644 index 91d7949..0000000 --- a/src/libui_sdl/libui/common/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# 3 june 2016 - -list(APPEND _LIBUI_SOURCES - common/areaevents.c - common/control.c - common/debug.c - common/matrix.c - common/shouldquit.c - common/userbugs.c -) -set(_LIBUI_SOURCES ${_LIBUI_SOURCES} PARENT_SCOPE) - -list(APPEND _LIBUI_INCLUDEDIRS - common -) -set(_LIBUI_INCLUDEDIRS ${_LIBUI_INCLUDEDIRS} PARENT_SCOPE) diff --git a/src/libui_sdl/libui/common/areaevents.c b/src/libui_sdl/libui/common/areaevents.c deleted file mode 100644 index cf3c288..0000000 --- a/src/libui_sdl/libui/common/areaevents.c +++ /dev/null @@ -1,167 +0,0 @@ -// 29 march 2014 -#include "../ui.h" -#include "uipriv.h" - -/* -Windows and GTK+ have a limit of 2 and 3 clicks, respectively, natively supported. Fortunately, we can simulate the double/triple-click behavior to build higher-order clicks. We can use the same algorithm Windows uses on both: - http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx -For GTK+, we pull the double-click time and double-click distance, which work the same as the equivalents on Windows (so the distance is in all directions), from the GtkSettings system. - -On GTK+ this will also allow us to discard the GDK_BUTTON_2PRESS and GDK_BUTTON_3PRESS events, so the button press stream will be just like on other platforms. - -Thanks to mclasen, garnacho_, halfline, and tristan in irc.gimp.net/#gtk+. -*/ - -// x, y, xdist, ydist, and c.rect must have the same units -// so must time, maxTime, and c.prevTime -int clickCounterClick(clickCounter *c, int button, int x, int y, uintptr_t time, uintptr_t maxTime, int32_t xdist, int32_t ydist) -{ - // different button than before? if so, don't count - if (button != c->curButton) - c->count = 0; - - // (x, y) in the allowed region for a double-click? if not, don't count - if (x < c->rectX0) - c->count = 0; - if (y < c->rectY0) - c->count = 0; - if (x >= c->rectX1) - c->count = 0; - if (y >= c->rectY1) - c->count = 0; - - // too slow? if so, don't count - // note the below expression; time > (c.prevTime + maxTime) can overflow! - if ((time - c->prevTime) > maxTime) // too slow; don't count - c->count = 0; - - c->count++; // if either of the above ifs happened, this will make the click count 1; otherwise it will make the click count 2, 3, 4, 5, ... - - // now we need to update the internal structures for the next test - c->curButton = button; - c->prevTime = time; - c->rectX0 = x - xdist; - c->rectY0 = y - ydist; - c->rectX1 = x + xdist; - c->rectY1 = y + ydist; - - return c->count; -} - -void clickCounterReset(clickCounter *c) -{ - c->curButton = 0; - c->rectX0 = 0; - c->rectY0 = 0; - c->rectX1 = 0; - c->rectY1 = 0; - c->prevTime = 0; - c->count = 0; -} - -/* -For position independence across international keyboard layouts, typewriter keys are read using scancodes (which are always set 1). -Windows provides the scancodes directly in the LPARAM. -GTK+ provides the scancodes directly from the underlying window system via GdkEventKey.hardware_keycode. -On X11, this is scancode + 8 (because X11 keyboard codes have a range of [8,255]). -Wayland is guaranteed to give the same result (thanks ebassi in irc.gimp.net/#gtk+). -On Linux, where evdev is used instead of polling scancodes directly from the keyboard, evdev's typewriter section key code constants are the same as scancodes anyway, so the rules above apply. -Typewriter section scancodes are the same across international keyboards with some exceptions that have been accounted for (see KeyEvent's documentation); see http://www.quadibloc.com/comp/scan.htm for details. -Non-typewriter keys can be handled safely using constants provided by the respective backend API. - -Because GTK+ keysyms may or may not obey Num Lock, we also handle the 0-9 and . keys on the numeric keypad with scancodes (they match too). -*/ - -// use uintptr_t to be safe; the size of the scancode/hardware key code field on each platform is different -static const struct { - uintptr_t scancode; - char equiv; -} scancodeKeys[] = { - { 0x02, '1' }, - { 0x03, '2' }, - { 0x04, '3' }, - { 0x05, '4' }, - { 0x06, '5' }, - { 0x07, '6' }, - { 0x08, '7' }, - { 0x09, '8' }, - { 0x0A, '9' }, - { 0x0B, '0' }, - { 0x0C, '-' }, - { 0x0D, '=' }, - { 0x0E, '\b' }, - { 0x0F, '\t' }, - { 0x10, 'q' }, - { 0x11, 'w' }, - { 0x12, 'e' }, - { 0x13, 'r' }, - { 0x14, 't' }, - { 0x15, 'y' }, - { 0x16, 'u' }, - { 0x17, 'i' }, - { 0x18, 'o' }, - { 0x19, 'p' }, - { 0x1A, '[' }, - { 0x1B, ']' }, - { 0x1C, '\n' }, - { 0x1E, 'a' }, - { 0x1F, 's' }, - { 0x20, 'd' }, - { 0x21, 'f' }, - { 0x22, 'g' }, - { 0x23, 'h' }, - { 0x24, 'j' }, - { 0x25, 'k' }, - { 0x26, 'l' }, - { 0x27, ';' }, - { 0x28, '\'' }, - { 0x29, '`' }, - { 0x2B, '\\' }, - { 0x2C, 'z' }, - { 0x2D, 'x' }, - { 0x2E, 'c' }, - { 0x2F, 'v' }, - { 0x30, 'b' }, - { 0x31, 'n' }, - { 0x32, 'm' }, - { 0x33, ',' }, - { 0x34, '.' }, - { 0x35, '/' }, - { 0x39, ' ' }, - { 0xFFFF, 0 }, -}; - -static const struct { - uintptr_t scancode; - uiExtKey equiv; -} scancodeExtKeys[] = { - { 0x47, uiExtKeyN7 }, - { 0x48, uiExtKeyN8 }, - { 0x49, uiExtKeyN9 }, - { 0x4B, uiExtKeyN4 }, - { 0x4C, uiExtKeyN5 }, - { 0x4D, uiExtKeyN6 }, - { 0x4F, uiExtKeyN1 }, - { 0x50, uiExtKeyN2 }, - { 0x51, uiExtKeyN3 }, - { 0x52, uiExtKeyN0 }, - { 0x53, uiExtKeyNDot }, - { 0xFFFF, 0 }, -}; - -int fromScancode(uintptr_t scancode, uiAreaKeyEvent *ke) -{ - int i; - - for (i = 0; scancodeKeys[i].scancode != 0xFFFF; i++) - if (scancodeKeys[i].scancode == scancode) { - ke->Key = scancodeKeys[i].equiv; - return 1; - } - for (i = 0; scancodeExtKeys[i].scancode != 0xFFFF; i++) - if (scancodeExtKeys[i].scancode == scancode) { - ke->ExtKey = scancodeExtKeys[i].equiv; - return 1; - } - return 0; -} diff --git a/src/libui_sdl/libui/common/control.c b/src/libui_sdl/libui/common/control.c deleted file mode 100644 index 78d1e5f..0000000 --- a/src/libui_sdl/libui/common/control.c +++ /dev/null @@ -1,117 +0,0 @@ -// 26 may 2015 -#include "../ui.h" -#include "uipriv.h" - -void uiControlDestroy(uiControl *c) -{ - (*(c->Destroy))(c); -} - -uintptr_t uiControlHandle(uiControl *c) -{ - return (*(c->Handle))(c); -} - -uiControl *uiControlParent(uiControl *c) -{ - return (*(c->Parent))(c); -} - -void uiControlSetParent(uiControl *c, uiControl *parent) -{ - (*(c->SetParent))(c, parent); -} - -int uiControlToplevel(uiControl *c) -{ - return (*(c->Toplevel))(c); -} - -int uiControlVisible(uiControl *c) -{ - return (*(c->Visible))(c); -} - -void uiControlShow(uiControl *c) -{ - (*(c->Show))(c); -} - -void uiControlHide(uiControl *c) -{ - (*(c->Hide))(c); -} - -int uiControlEnabled(uiControl *c) -{ - return (*(c->Enabled))(c); -} - -void uiControlEnable(uiControl *c) -{ - (*(c->Enable))(c); -} - -void uiControlDisable(uiControl *c) -{ - (*(c->Disable))(c); -} - -void uiControlSetFocus(uiControl *c) -{ - (*(c->SetFocus))(c); -} - -void uiControlSetMinSize(uiControl *c, int w, int h) -{ - c->MinWidth = w; - c->MinHeight = h; - (*(c->SetMinSize))(c, w, h); -} - -#define uiControlSignature 0x7569436F - -uiControl *uiAllocControl(size_t size, uint32_t OSsig, uint32_t typesig, const char *typenamestr) -{ - uiControl *c; - - c = (uiControl *) uiAlloc(size, typenamestr); - c->Signature = uiControlSignature; - c->OSSignature = OSsig; - c->TypeSignature = typesig; - - c->MinWidth = -1; - c->MinHeight = -1; - - return c; -} - -void uiFreeControl(uiControl *c) -{ - if (uiControlParent(c) != NULL) - userbug("You cannot destroy a uiControl while it still has a parent. (control: %p)", c); - uiFree(c); -} - -void uiControlVerifySetParent(uiControl *c, uiControl *parent) -{ - uiControl *curParent; - - if (uiControlToplevel(c)) - userbug("You cannot give a toplevel uiControl a parent. (control: %p)", c); - curParent = uiControlParent(c); - if (parent != NULL && curParent != NULL) - userbug("You cannot give a uiControl a parent while it already has one. (control: %p; current parent: %p; new parent: %p)", c, curParent, parent); - if (parent == NULL && curParent == NULL) - implbug("attempt to double unparent uiControl %p", c); -} - -int uiControlEnabledToUser(uiControl *c) -{ - while (c != NULL) { - if (!uiControlEnabled(c)) - return 0; - c = uiControlParent(c); - } - return 1; -} diff --git a/src/libui_sdl/libui/common/controlsigs.h b/src/libui_sdl/libui/common/controlsigs.h deleted file mode 100644 index 1cbf18d..0000000 --- a/src/libui_sdl/libui/common/controlsigs.h +++ /dev/null @@ -1,25 +0,0 @@ -// 24 april 2016 - -#define uiAreaSignature 0x41726561 -#define uiBoxSignature 0x426F784C -#define uiButtonSignature 0x42746F6E -#define uiCheckboxSignature 0x43686B62 -#define uiColorButtonSignature 0x436F6C42 -#define uiComboboxSignature 0x436F6D62 -#define uiDateTimePickerSignature 0x44545069 -#define uiEditableComboboxSignature 0x45644362 -#define uiEntrySignature 0x456E7472 -#define uiFontButtonSignature 0x466F6E42 -#define uiFormSignature 0x466F726D -#define uiGridSignature 0x47726964 -#define uiGroupSignature 0x47727062 -#define uiLabelSignature 0x4C61626C -#define uiMultilineEntrySignature 0x4D6C6E45 -#define uiProgressBarSignature 0x50426172 -#define uiRadioButtonsSignature 0x5264696F -#define uiSeparatorSignature 0x53657061 -#define uiSliderSignature 0x536C6964 -#define uiSpinboxSignature 0x5370696E -#define uiTabSignature 0x54616273 -#define uiTableSignature 0x5461626C -#define uiWindowSignature 0x57696E64 diff --git a/src/libui_sdl/libui/common/debug.c b/src/libui_sdl/libui/common/debug.c deleted file mode 100644 index 97280b4..0000000 --- a/src/libui_sdl/libui/common/debug.c +++ /dev/null @@ -1,21 +0,0 @@ -// 13 may 2016 -#include "../ui.h" -#include "uipriv.h" - -void _implbug(const char *file, const char *line, const char *func, const char *format, ...) -{ - va_list ap; - - va_start(ap, format); - realbug(file, line, func, "POSSIBLE IMPLEMENTATION BUG; CONTACT ANDLABS:\n", format, ap); - va_end(ap); -} - -void _userbug(const char *file, const char *line, const char *func, const char *format, ...) -{ - va_list ap; - - va_start(ap, format); - realbug(file, line, func, "You have a bug: ", format, ap); - va_end(ap); -} diff --git a/src/libui_sdl/libui/common/matrix.c b/src/libui_sdl/libui/common/matrix.c deleted file mode 100644 index 676885d..0000000 --- a/src/libui_sdl/libui/common/matrix.c +++ /dev/null @@ -1,50 +0,0 @@ -// 11 october 2015 -#include -#include "../ui.h" -#include "uipriv.h" - -void uiDrawMatrixSetIdentity(uiDrawMatrix *m) -{ - m->M11 = 1; - m->M12 = 0; - m->M21 = 0; - m->M22 = 1; - m->M31 = 0; - m->M32 = 0; -} - -// The rest of this file provides basic utilities in case the platform doesn't provide any of its own for these tasks. -// Keep these as minimal as possible. They should generally not call other fallbacks. - -// see https://msdn.microsoft.com/en-us/library/windows/desktop/ff684171%28v=vs.85%29.aspx#skew_transform -// TODO see if there's a way we can avoid the multiplication -void fallbackSkew(uiDrawMatrix *m, double x, double y, double xamount, double yamount) -{ - uiDrawMatrix n; - - uiDrawMatrixSetIdentity(&n); - // TODO explain this - n.M12 = tan(yamount); - n.M21 = tan(xamount); - n.M31 = -y * tan(xamount); - n.M32 = -x * tan(yamount); - uiDrawMatrixMultiply(m, &n); -} - -void scaleCenter(double xCenter, double yCenter, double *x, double *y) -{ - *x = xCenter - (*x * xCenter); - *y = yCenter - (*y * yCenter); -} - -// the basic algorithm is from cairo -// but it's the same algorithm as the transform point, just without M31 and M32 taken into account, so let's just do that instead -void fallbackTransformSize(uiDrawMatrix *m, double *x, double *y) -{ - uiDrawMatrix m2; - - m2 = *m; - m2.M31 = 0; - m2.M32 = 0; - uiDrawMatrixTransformPoint(&m2, x, y); -} diff --git a/src/libui_sdl/libui/common/shouldquit.c b/src/libui_sdl/libui/common/shouldquit.c deleted file mode 100644 index 4e7aa5c..0000000 --- a/src/libui_sdl/libui/common/shouldquit.c +++ /dev/null @@ -1,22 +0,0 @@ -// 9 may 2015 -#include "../ui.h" -#include "uipriv.h" - -static int defaultOnShouldQuit(void *data) -{ - return 0; -} - -static int (*onShouldQuit)(void *) = defaultOnShouldQuit; -static void *onShouldQuitData; - -void uiOnShouldQuit(int (*f)(void *), void *data) -{ - onShouldQuit = f; - onShouldQuitData = data; -} - -int shouldQuit(void) -{ - return (*onShouldQuit)(onShouldQuitData); -} diff --git a/src/libui_sdl/libui/common/uipriv.h b/src/libui_sdl/libui/common/uipriv.h deleted file mode 100644 index d6b54e8..0000000 --- a/src/libui_sdl/libui/common/uipriv.h +++ /dev/null @@ -1,58 +0,0 @@ -// 6 april 2015 -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include "controlsigs.h" - -extern uiInitOptions options; - -extern void *uiAlloc(size_t, const char *); -#define uiNew(T) ((T *) uiAlloc(sizeof (T), #T)) -extern void *uiRealloc(void *, size_t, const char *); -extern void uiFree(void *); - -// ugh, this was only introduced in MSVC 2015... -#ifdef _MSC_VER -#define __func__ __FUNCTION__ -#endif -extern void realbug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap); -#define _ns2(s) #s -#define _ns(s) _ns2(s) -extern void _implbug(const char *file, const char *line, const char *func, const char *format, ...); -#define implbug(...) _implbug(__FILE__, _ns(__LINE__), __func__, __VA_ARGS__) -extern void _userbug(const char *file, const char *line, const char *func, const char *format, ...); -#define userbug(...) _userbug(__FILE__, _ns(__LINE__), __func__, __VA_ARGS__) - -// control.c -extern uiControl *newControl(size_t size, uint32_t OSsig, uint32_t typesig, const char *typenamestr); - -// shouldquit.c -extern int shouldQuit(void); - -// areaevents.c -typedef struct clickCounter clickCounter; -// you should call Reset() to zero-initialize a new instance -// it doesn't matter that all the non-count fields are zero: the first click will fail the curButton test straightaway, so it'll return 1 and set the rest of the structure accordingly -struct clickCounter { - int curButton; - int rectX0; - int rectY0; - int rectX1; - int rectY1; - uintptr_t prevTime; - int count; -}; -int clickCounterClick(clickCounter *c, int button, int x, int y, uintptr_t time, uintptr_t maxTime, int32_t xdist, int32_t ydist); -extern void clickCounterReset(clickCounter *); -extern int fromScancode(uintptr_t, uiAreaKeyEvent *); - -// matrix.c -extern void fallbackSkew(uiDrawMatrix *, double, double, double, double); -extern void scaleCenter(double, double, double *, double *); -extern void fallbackTransformSize(uiDrawMatrix *, double *, double *); - -#ifdef __cplusplus -} -#endif diff --git a/src/libui_sdl/libui/common/userbugs.c b/src/libui_sdl/libui/common/userbugs.c deleted file mode 100644 index 0a85874..0000000 --- a/src/libui_sdl/libui/common/userbugs.c +++ /dev/null @@ -1,8 +0,0 @@ -// 22 may 2016 -#include "../ui.h" -#include "uipriv.h" - -void uiUserBugCannotSetParentOnToplevel(const char *type) -{ - userbug("You cannot make a %s a child of another uiControl,", type); -} diff --git a/src/libui_sdl/libui/darwin/CMakeLists.txt b/src/libui_sdl/libui/darwin/CMakeLists.txt deleted file mode 100644 index dbef5d4..0000000 --- a/src/libui_sdl/libui/darwin/CMakeLists.txt +++ /dev/null @@ -1,79 +0,0 @@ -# 3 june 2016 - -list(APPEND _LIBUI_SOURCES - darwin/alloc.m - darwin/area.m - darwin/areaevents.m - darwin/autolayout.m - darwin/box.m - darwin/button.m - darwin/checkbox.m - darwin/colorbutton.m - darwin/combobox.m - darwin/control.m - darwin/datetimepicker.m - darwin/debug.m - darwin/draw.m - darwin/drawtext.m - darwin/editablecombo.m - darwin/entry.m - darwin/fontbutton.m - darwin/form.m - darwin/grid.m - darwin/group.m - darwin/image.m - darwin/label.m - darwin/main.m - darwin/map.m - darwin/menu.m - darwin/multilineentry.m - darwin/progressbar.m - darwin/radiobuttons.m - darwin/scrollview.m - darwin/separator.m - darwin/slider.m - darwin/spinbox.m - darwin/stddialogs.m - darwin/tab.m - darwin/text.m - darwin/util.m - darwin/window.m - darwin/winmoveresize.m -) -set(_LIBUI_SOURCES ${_LIBUI_SOURCES} PARENT_SCOPE) - -list(APPEND _LIBUI_INCLUDEDIRS - darwin -) -set(_LIBUI_INCLUDEDIRS _LIBUI_INCLUDEDIRS PARENT_SCOPE) - -set(_LIBUINAME libui PARENT_SCOPE) -if(NOT BUILD_SHARED_LIBS) - set(_LIBUINAME libui-temporary PARENT_SCOPE) -endif() -# thanks to Mr-Hide in irc.freenode.net/#cmake -macro(_handle_static) - set_target_properties(${_LIBUINAME} PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}") - set(_aname $) - set(_lname libui-combined.list) - set(_oname libui-combined.o) - add_custom_command( - OUTPUT ${_oname} - COMMAND - nm -m ${_aname} | sed -E -n "'s/^[0-9a-f]* \\([A-Z_]+,[a-z_]+\\) external //p'" > ${_lname} - COMMAND - ld -exported_symbols_list ${_lname} -r -all_load ${_aname} -o ${_oname} - COMMENT "Removing hidden symbols") - add_library(libui STATIC ${_oname}) - # otherwise cmake won't know which linker to use - set_target_properties(libui PROPERTIES - LINKER_LANGUAGE C) - set(_aname) - set(_lname) - set(_oname) -endmacro() - -set(_LIBUI_LIBS - objc "-framework Foundation" "-framework AppKit" -PARENT_SCOPE) diff --git a/src/libui_sdl/libui/darwin/alloc.m b/src/libui_sdl/libui/darwin/alloc.m deleted file mode 100644 index e271b90..0000000 --- a/src/libui_sdl/libui/darwin/alloc.m +++ /dev/null @@ -1,89 +0,0 @@ -// 4 december 2014 -#import -#import "uipriv_darwin.h" - -static NSMutableArray *allocations; -NSMutableArray *delegates; - -void initAlloc(void) -{ - allocations = [NSMutableArray new]; - delegates = [NSMutableArray new]; -} - -#define UINT8(p) ((uint8_t *) (p)) -#define PVOID(p) ((void *) (p)) -#define EXTRA (sizeof (size_t) + sizeof (const char **)) -#define DATA(p) PVOID(UINT8(p) + EXTRA) -#define BASE(p) PVOID(UINT8(p) - EXTRA) -#define SIZE(p) ((size_t *) (p)) -#define CCHAR(p) ((const char **) (p)) -#define TYPE(p) CCHAR(UINT8(p) + sizeof (size_t)) - -void uninitAlloc(void) -{ - NSMutableString *str; - NSValue *v; - - [delegates release]; - if ([allocations count] == 0) { - [allocations release]; - return; - } - str = [NSMutableString new]; - for (v in allocations) { - void *ptr; - - ptr = [v pointerValue]; - [str appendString:[NSString stringWithFormat:@"%p %s\n", ptr, *TYPE(ptr)]]; - } - userbug("Some data was leaked; either you left a uiControl lying around or there's a bug in libui itself. Leaked data:\n%s", [str UTF8String]); - [str release]; -} - -void *uiAlloc(size_t size, const char *type) -{ - void *out; - - out = malloc(EXTRA + size); - if (out == NULL) { - fprintf(stderr, "memory exhausted in uiAlloc()\n"); - abort(); - } - memset(DATA(out), 0, size); - *SIZE(out) = size; - *TYPE(out) = type; - [allocations addObject:[NSValue valueWithPointer:out]]; - return DATA(out); -} - -void *uiRealloc(void *p, size_t new, const char *type) -{ - void *out; - size_t *s; - - if (p == NULL) - return uiAlloc(new, type); - p = BASE(p); - out = realloc(p, EXTRA + new); - if (out == NULL) { - fprintf(stderr, "memory exhausted in uiRealloc()\n"); - abort(); - } - s = SIZE(out); - if (new <= *s) - memset(((uint8_t *) DATA(out)) + *s, 0, new - *s); - *s = new; - [allocations removeObject:[NSValue valueWithPointer:p]]; - [allocations addObject:[NSValue valueWithPointer:out]]; - return DATA(out); -} - -void uiFree(void *p) -{ - if (p == NULL) - implbug("attempt to uiFree(NULL)"); - p = BASE(p); - free(p); - [allocations removeObject:[NSValue valueWithPointer:p]]; -} diff --git a/src/libui_sdl/libui/darwin/area.m b/src/libui_sdl/libui/darwin/area.m deleted file mode 100644 index 23162e6..0000000 --- a/src/libui_sdl/libui/darwin/area.m +++ /dev/null @@ -1,475 +0,0 @@ -// 9 september 2015 -#import "uipriv_darwin.h" - -// 10.8 fixups -#define NSEventModifierFlags NSUInteger - -@interface areaView : NSView { - uiArea *libui_a; - NSTrackingArea *libui_ta; - NSSize libui_ss; - BOOL libui_enabled; -} -- (id)initWithFrame:(NSRect)r area:(uiArea *)a; -- (uiModifiers)parseModifiers:(NSEvent *)e; -- (void)doMouseEvent:(NSEvent *)e; -- (int)sendKeyEvent:(uiAreaKeyEvent *)ke; -- (int)doKeyDownUp:(NSEvent *)e up:(int)up; -- (int)doKeyDown:(NSEvent *)e; -- (int)doKeyUp:(NSEvent *)e; -- (int)doFlagsChanged:(NSEvent *)e; -- (void)setupNewTrackingArea; -- (void)setScrollingSize:(NSSize)s; -- (BOOL)isEnabled; -- (void)setEnabled:(BOOL)e; -@end - -struct uiArea { - uiDarwinControl c; - NSView *view; // either sv or area depending on whether it is scrolling - NSScrollView *sv; - areaView *area; - struct scrollViewData *d; - uiAreaHandler *ah; - BOOL scrolling; - NSEvent *dragevent; -}; - -@implementation areaView - -- (id)initWithFrame:(NSRect)r area:(uiArea *)a -{ - self = [super initWithFrame:r]; - if (self) { - self->libui_a = a; - [self setupNewTrackingArea]; - self->libui_ss = r.size; - self->libui_enabled = YES; - } - return self; -} - -- (void)drawRect:(NSRect)r -{ - uiArea *a = self->libui_a; - CGContextRef c; - uiAreaDrawParams dp; - - c = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort]; - // see draw.m under text for why we need the height - dp.Context = newContext(c, [self bounds].size.height); - - dp.AreaWidth = 0; - dp.AreaHeight = 0; - if (!a->scrolling) { - dp.AreaWidth = [self frame].size.width; - dp.AreaHeight = [self frame].size.height; - } - - dp.ClipX = r.origin.x; - dp.ClipY = r.origin.y; - dp.ClipWidth = r.size.width; - dp.ClipHeight = r.size.height; - - // no need to save or restore the graphics state to reset transformations; Cocoa creates a brand-new context each time - (*(a->ah->Draw))(a->ah, a, &dp); - - freeContext(dp.Context); -} - -- (BOOL)isFlipped -{ - return YES; -} - -- (BOOL)acceptsFirstResponder -{ - return YES; -} - -- (uiModifiers)parseModifiers:(NSEvent *)e -{ - NSEventModifierFlags mods; - uiModifiers m; - - m = 0; - mods = [e modifierFlags]; - if ((mods & NSControlKeyMask) != 0) - m |= uiModifierCtrl; - if ((mods & NSAlternateKeyMask) != 0) - m |= uiModifierAlt; - if ((mods & NSShiftKeyMask) != 0) - m |= uiModifierShift; - if ((mods & NSCommandKeyMask) != 0) - m |= uiModifierSuper; - return m; -} - -- (void)setupNewTrackingArea -{ - self->libui_ta = [[NSTrackingArea alloc] initWithRect:[self bounds] - options:(NSTrackingMouseEnteredAndExited | - NSTrackingMouseMoved | - NSTrackingActiveAlways | - NSTrackingInVisibleRect | - NSTrackingEnabledDuringMouseDrag) - owner:self - userInfo:nil]; - [self addTrackingArea:self->libui_ta]; -} - -- (void)updateTrackingAreas -{ - [self removeTrackingArea:self->libui_ta]; - [self->libui_ta release]; - [self setupNewTrackingArea]; -} - -// capture on drag is done automatically on OS X -- (void)doMouseEvent:(NSEvent *)e -{ - uiArea *a = self->libui_a; - uiAreaMouseEvent me; - NSPoint point; - int buttonNumber; - NSUInteger pmb; - unsigned int i, max; - - // this will convert point to drawing space - // thanks swillits in irc.freenode.net/#macdev - point = [self convertPoint:[e locationInWindow] fromView:nil]; - me.X = point.x; - me.Y = point.y; - - me.AreaWidth = 0; - me.AreaHeight = 0; - if (!a->scrolling) { - me.AreaWidth = [self frame].size.width; - me.AreaHeight = [self frame].size.height; - } - - buttonNumber = [e buttonNumber] + 1; - // swap button numbers 2 and 3 (right and middle) - if (buttonNumber == 2) - buttonNumber = 3; - else if (buttonNumber == 3) - buttonNumber = 2; - - me.Down = 0; - me.Up = 0; - me.Count = 0; - switch ([e type]) { - case NSLeftMouseDown: - case NSRightMouseDown: - case NSOtherMouseDown: - me.Down = buttonNumber; - me.Count = [e clickCount]; - break; - case NSLeftMouseUp: - case NSRightMouseUp: - case NSOtherMouseUp: - me.Up = buttonNumber; - break; - case NSLeftMouseDragged: - case NSRightMouseDragged: - case NSOtherMouseDragged: - // we include the button that triggered the dragged event in the Held fields - buttonNumber = 0; - break; - } - - me.Modifiers = [self parseModifiers:e]; - - pmb = [NSEvent pressedMouseButtons]; - me.Held1To64 = 0; - if (buttonNumber != 1 && (pmb & 1) != 0) - me.Held1To64 |= 1; - if (buttonNumber != 2 && (pmb & 4) != 0) - me.Held1To64 |= 2; - if (buttonNumber != 3 && (pmb & 2) != 0) - me.Held1To64 |= 4; - // buttons 4..32 - // https://developer.apple.com/library/mac/documentation/Carbon/Reference/QuartzEventServicesRef/index.html#//apple_ref/c/tdef/CGMouseButton says Quartz only supports up to 32 buttons - max = 32; - for (i = 4; i <= max; i++) { - uint64_t j; - - if (buttonNumber == i) - continue; - j = 1 << (i - 1); - if ((pmb & j) != 0) - me.Held1To64 |= j; - } - - if (self->libui_enabled) { - // and allow dragging here - a->dragevent = e; - (*(a->ah->MouseEvent))(a->ah, a, &me); - a->dragevent = nil; - } -} - -#define mouseEvent(name) \ - - (void)name:(NSEvent *)e \ - { \ - [self doMouseEvent:e]; \ - } -mouseEvent(mouseMoved) -mouseEvent(mouseDragged) -mouseEvent(rightMouseDragged) -mouseEvent(otherMouseDragged) -mouseEvent(mouseDown) -mouseEvent(rightMouseDown) -mouseEvent(otherMouseDown) -mouseEvent(mouseUp) -mouseEvent(rightMouseUp) -mouseEvent(otherMouseUp) - -- (void)mouseEntered:(NSEvent *)e -{ - uiArea *a = self->libui_a; - - if (self->libui_enabled) - (*(a->ah->MouseCrossed))(a->ah, a, 0); -} - -- (void)mouseExited:(NSEvent *)e -{ - uiArea *a = self->libui_a; - - if (self->libui_enabled) - (*(a->ah->MouseCrossed))(a->ah, a, 1); -} - -// note: there is no equivalent to WM_CAPTURECHANGED on Mac OS X; there literally is no way to break a grab like that -// even if I invoke the task switcher and switch processes, the mouse grab will still be held until I let go of all buttons -// therefore, no DragBroken() - -- (int)sendKeyEvent:(uiAreaKeyEvent *)ke -{ - uiArea *a = self->libui_a; - - return (*(a->ah->KeyEvent))(a->ah, a, ke); -} - -- (int)doKeyDownUp:(NSEvent *)e up:(int)up -{ - uiAreaKeyEvent ke; - - ke.Key = 0; - ke.ExtKey = 0; - ke.Modifier = 0; - - ke.Modifiers = [self parseModifiers:e]; - - ke.Up = up; - - if (!fromKeycode([e keyCode], &ke)) - return 0; - return [self sendKeyEvent:&ke]; -} - -- (int)doKeyDown:(NSEvent *)e -{ - return [self doKeyDownUp:e up:0]; -} - -- (int)doKeyUp:(NSEvent *)e -{ - return [self doKeyDownUp:e up:1]; -} - -- (int)doFlagsChanged:(NSEvent *)e -{ - uiAreaKeyEvent ke; - uiModifiers whichmod; - - ke.Key = 0; - ke.ExtKey = 0; - - // Mac OS X sends this event on both key up and key down. - // Fortunately -[e keyCode] IS valid here, so we can simply map from key code to Modifiers, get the value of [e modifierFlags], and check if the respective bit is set or not — that will give us the up/down state - if (!keycodeModifier([e keyCode], &whichmod)) - return 0; - ke.Modifier = whichmod; - ke.Modifiers = [self parseModifiers:e]; - ke.Up = (ke.Modifiers & ke.Modifier) == 0; - // and then drop the current modifier from Modifiers - ke.Modifiers &= ~ke.Modifier; - return [self sendKeyEvent:&ke]; -} - -- (void)setFrameSize:(NSSize)size -{ - uiArea *a = self->libui_a; - - [super setFrameSize:size]; - if (!a->scrolling) - // we must redraw everything on resize because Windows requires it - [self setNeedsDisplay:YES]; -} - -// TODO does this update the frame? -- (void)setScrollingSize:(NSSize)s -{ - self->libui_ss = s; - [self invalidateIntrinsicContentSize]; -} - -- (NSSize)intrinsicContentSize -{ - if (!self->libui_a->scrolling) - return [super intrinsicContentSize]; - return self->libui_ss; -} - -- (BOOL)becomeFirstResponder -{ - return [self isEnabled]; -} - -- (BOOL)isEnabled -{ - return self->libui_enabled; -} - -- (void)setEnabled:(BOOL)e -{ - self->libui_enabled = e; - if (!self->libui_enabled && [self window] != nil) - if ([[self window] firstResponder] == self) - [[self window] makeFirstResponder:nil]; -} - -@end - -uiDarwinControlAllDefaultsExceptDestroy(uiArea, view) - -static void uiAreaDestroy(uiControl *c) -{ - uiArea *a = uiArea(c); - - if (a->scrolling) - scrollViewFreeData(a->sv, a->d); - [a->area release]; - if (a->scrolling) - [a->sv release]; - uiFreeControl(uiControl(a)); -} - -// called by subclasses of -[NSApplication sendEvent:] -// by default, NSApplication eats some key events -// this prevents that from happening with uiArea -// see http://stackoverflow.com/questions/24099063/how-do-i-detect-keyup-in-my-nsview-with-the-command-key-held and http://lists.apple.com/archives/cocoa-dev/2003/Oct/msg00442.html -int sendAreaEvents(NSEvent *e) -{ - NSEventType type; - id focused; - areaView *view; - - type = [e type]; - if (type != NSKeyDown && type != NSKeyUp && type != NSFlagsChanged) - return 0; - focused = [[e window] firstResponder]; - if (focused == nil) - return 0; - if (![focused isKindOfClass:[areaView class]]) - return 0; - view = (areaView *) focused; - switch (type) { - case NSKeyDown: - return [view doKeyDown:e]; - case NSKeyUp: - return [view doKeyUp:e]; - case NSFlagsChanged: - return [view doFlagsChanged:e]; - } - return 0; -} - -void uiAreaSetSize(uiArea *a, int width, int height) -{ - if (!a->scrolling) - userbug("You cannot call uiAreaSetSize() on a non-scrolling uiArea. (area: %p)", a); - [a->area setScrollingSize:NSMakeSize(width, height)]; -} - -void uiAreaQueueRedrawAll(uiArea *a) -{ - [a->area setNeedsDisplay:YES]; -} - -void uiAreaScrollTo(uiArea *a, double x, double y, double width, double height) -{ - if (!a->scrolling) - userbug("You cannot call uiAreaScrollTo() on a non-scrolling uiArea. (area: %p)", a); - [a->area scrollRectToVisible:NSMakeRect(x, y, width, height)]; - // don't worry about the return value; it just says whether scrolling was needed -} - -void uiAreaBeginUserWindowMove(uiArea *a) -{ - libuiNSWindow *w; - - w = (libuiNSWindow *) [a->area window]; - if (w == nil) - return; // TODO - if (a->dragevent == nil) - return; // TODO - [w libui_doMove:a->dragevent]; -} - -void uiAreaBeginUserWindowResize(uiArea *a, uiWindowResizeEdge edge) -{ - libuiNSWindow *w; - - w = (libuiNSWindow *) [a->area window]; - if (w == nil) - return; // TODO - if (a->dragevent == nil) - return; // TODO - [w libui_doResize:a->dragevent on:edge]; -} - -uiArea *uiNewArea(uiAreaHandler *ah) -{ - uiArea *a; - - uiDarwinNewControl(uiArea, a); - - a->ah = ah; - a->scrolling = NO; - - a->area = [[areaView alloc] initWithFrame:NSZeroRect area:a]; - - a->view = a->area; - - return a; -} - -uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height) -{ - uiArea *a; - struct scrollViewCreateParams p; - - uiDarwinNewControl(uiArea, a); - - a->ah = ah; - a->scrolling = YES; - - a->area = [[areaView alloc] initWithFrame:NSMakeRect(0, 0, width, height) - area:a]; - - memset(&p, 0, sizeof (struct scrollViewCreateParams)); - p.DocumentView = a->area; - p.BackgroundColor = [NSColor controlColor]; - p.DrawsBackground = 1; - p.Bordered = NO; - p.HScroll = YES; - p.VScroll = YES; - a->sv = mkScrollView(&p, &(a->d)); - - a->view = a->sv; - - return a; -} diff --git a/src/libui_sdl/libui/darwin/areaevents.m b/src/libui_sdl/libui/darwin/areaevents.m deleted file mode 100644 index d7ceaaa..0000000 --- a/src/libui_sdl/libui/darwin/areaevents.m +++ /dev/null @@ -1,159 +0,0 @@ -// 30 march 2014 -#import "uipriv_darwin.h" - -/* -Mac OS X uses its own set of hardware key codes that are different from PC keyboard scancodes, but are positional (like PC keyboard scancodes). These are defined in , a Carbon header. As far as I can tell, there's no way to include this header without either using an absolute path or linking Carbon into the program, so the constant values are used here instead. - -The Cocoa docs do guarantee that -[NSEvent keyCode] results in key codes that are the same as those returned by Carbon; that is, these codes. -*/ - -// use uintptr_t to be safe -static const struct { - uintptr_t keycode; - char equiv; -} keycodeKeys[] = { - { 0x00, 'a' }, - { 0x01, 's' }, - { 0x02, 'd' }, - { 0x03, 'f' }, - { 0x04, 'h' }, - { 0x05, 'g' }, - { 0x06, 'z' }, - { 0x07, 'x' }, - { 0x08, 'c' }, - { 0x09, 'v' }, - { 0x0B, 'b' }, - { 0x0C, 'q' }, - { 0x0D, 'w' }, - { 0x0E, 'e' }, - { 0x0F, 'r' }, - { 0x10, 'y' }, - { 0x11, 't' }, - { 0x12, '1' }, - { 0x13, '2' }, - { 0x14, '3' }, - { 0x15, '4' }, - { 0x16, '6' }, - { 0x17, '5' }, - { 0x18, '=' }, - { 0x19, '9' }, - { 0x1A, '7' }, - { 0x1B, '-' }, - { 0x1C, '8' }, - { 0x1D, '0' }, - { 0x1E, ']' }, - { 0x1F, 'o' }, - { 0x20, 'u' }, - { 0x21, '[' }, - { 0x22, 'i' }, - { 0x23, 'p' }, - { 0x25, 'l' }, - { 0x26, 'j' }, - { 0x27, '\'' }, - { 0x28, 'k' }, - { 0x29, ';' }, - { 0x2A, '\\' }, - { 0x2B, ',' }, - { 0x2C, '/' }, - { 0x2D, 'n' }, - { 0x2E, 'm' }, - { 0x2F, '.' }, - { 0x32, '`' }, - { 0x24, '\n' }, - { 0x30, '\t' }, - { 0x31, ' ' }, - { 0x33, '\b' }, - { 0xFFFF, 0 }, -}; - -static const struct { - uintptr_t keycode; - uiExtKey equiv; -} keycodeExtKeys[] = { - { 0x41, uiExtKeyNDot }, - { 0x43, uiExtKeyNMultiply }, - { 0x45, uiExtKeyNAdd }, - { 0x4B, uiExtKeyNDivide }, - { 0x4C, uiExtKeyNEnter }, - { 0x4E, uiExtKeyNSubtract }, - { 0x52, uiExtKeyN0 }, - { 0x53, uiExtKeyN1 }, - { 0x54, uiExtKeyN2 }, - { 0x55, uiExtKeyN3 }, - { 0x56, uiExtKeyN4 }, - { 0x57, uiExtKeyN5 }, - { 0x58, uiExtKeyN6 }, - { 0x59, uiExtKeyN7 }, - { 0x5B, uiExtKeyN8 }, - { 0x5C, uiExtKeyN9 }, - { 0x35, uiExtKeyEscape }, - { 0x60, uiExtKeyF5 }, - { 0x61, uiExtKeyF6 }, - { 0x62, uiExtKeyF7 }, - { 0x63, uiExtKeyF3 }, - { 0x64, uiExtKeyF8 }, - { 0x65, uiExtKeyF9 }, - { 0x67, uiExtKeyF11 }, - { 0x6D, uiExtKeyF10 }, - { 0x6F, uiExtKeyF12 }, - { 0x72, uiExtKeyInsert }, // listed as the Help key but it's in the same position on an Apple keyboard as the Insert key on a Windows keyboard; thanks to SeanieB from irc.badnik.net and Psy in irc.freenode.net/#macdev for confirming they have the same code - { 0x73, uiExtKeyHome }, - { 0x74, uiExtKeyPageUp }, - { 0x75, uiExtKeyDelete }, - { 0x76, uiExtKeyF4 }, - { 0x77, uiExtKeyEnd }, - { 0x78, uiExtKeyF2 }, - { 0x79, uiExtKeyPageDown }, - { 0x7A, uiExtKeyF1 }, - { 0x7B, uiExtKeyLeft }, - { 0x7C, uiExtKeyRight }, - { 0x7D, uiExtKeyDown }, - { 0x7E, uiExtKeyUp }, - { 0xFFFF, 0 }, -}; - -static const struct { - uintptr_t keycode; - uiModifiers equiv; -} keycodeModifiers[] = { - { 0x37, uiModifierSuper }, // left command - { 0x38, uiModifierShift }, // left shift - { 0x3A, uiModifierAlt }, // left option - { 0x3B, uiModifierCtrl }, // left control - { 0x3C, uiModifierShift }, // right shift - { 0x3D, uiModifierAlt }, // right alt - { 0x3E, uiModifierCtrl }, // right control - // the following is not in Events.h for some reason - // thanks to Nicole and jedivulcan from irc.badnik.net - { 0x36, uiModifierSuper }, // right command - { 0xFFFF, 0 }, -}; - -BOOL fromKeycode(unsigned short keycode, uiAreaKeyEvent *ke) -{ - int i; - - for (i = 0; keycodeKeys[i].keycode != 0xFFFF; i++) - if (keycodeKeys[i].keycode == keycode) { - ke->Key = keycodeKeys[i].equiv; - return YES; - } - for (i = 0; keycodeExtKeys[i].keycode != 0xFFFF; i++) - if (keycodeExtKeys[i].keycode == keycode) { - ke->ExtKey = keycodeExtKeys[i].equiv; - return YES; - } - return NO; -} - -BOOL keycodeModifier(unsigned short keycode, uiModifiers *mod) -{ - int i; - - for (i = 0; keycodeModifiers[i].keycode != 0xFFFF; i++) - if (keycodeModifiers[i].keycode == keycode) { - *mod = keycodeModifiers[i].equiv; - return YES; - } - return NO; -} diff --git a/src/libui_sdl/libui/darwin/autolayout.m b/src/libui_sdl/libui/darwin/autolayout.m deleted file mode 100644 index 9964155..0000000 --- a/src/libui_sdl/libui/darwin/autolayout.m +++ /dev/null @@ -1,161 +0,0 @@ -// 15 august 2015 -#import "uipriv_darwin.h" - -NSLayoutConstraint *mkConstraint(id view1, NSLayoutAttribute attr1, NSLayoutRelation relation, id view2, NSLayoutAttribute attr2, CGFloat multiplier, CGFloat c, NSString *desc) -{ - NSLayoutConstraint *constraint; - - constraint = [NSLayoutConstraint constraintWithItem:view1 - attribute:attr1 - relatedBy:relation - toItem:view2 - attribute:attr2 - multiplier:multiplier - constant:c]; - // apparently only added in 10.9 - if ([constraint respondsToSelector:@selector(setIdentifier:)]) - [((id) constraint) setIdentifier:desc]; - return constraint; -} - -CGFloat uiDarwinMarginAmount(void *reserved) -{ - return 20.0; -} - -CGFloat uiDarwinPaddingAmount(void *reserved) -{ - return 8.0; -} - -// this is needed for NSSplitView to work properly; see http://stackoverflow.com/questions/34574478/how-can-i-set-the-position-of-a-nssplitview-nowadays-setpositionofdivideratind (stal in irc.freenode.net/#macdev came up with the exact combination) -// turns out it also works on NSTabView and NSBox too, possibly others! -// and for bonus points, it even seems to fix unsatisfiable-constraint-autoresizing-mask issues with NSTabView and NSBox too!!! this is nuts -void jiggleViewLayout(NSView *view) -{ - [view setNeedsLayout:YES]; - [view layoutSubtreeIfNeeded]; -} - -static CGFloat margins(int margined) -{ - if (!margined) - return 0.0; - return uiDarwinMarginAmount(NULL); -} - -void singleChildConstraintsEstablish(struct singleChildConstraints *c, NSView *contentView, NSView *childView, BOOL hugsTrailing, BOOL hugsBottom, int margined, NSString *desc) -{ - CGFloat margin; - - margin = margins(margined); - - c->leadingConstraint = mkConstraint(contentView, NSLayoutAttributeLeading, - NSLayoutRelationEqual, - childView, NSLayoutAttributeLeading, - 1, -margin, - [desc stringByAppendingString:@" leading constraint"]); - [contentView addConstraint:c->leadingConstraint]; - [c->leadingConstraint retain]; - - c->topConstraint = mkConstraint(contentView, NSLayoutAttributeTop, - NSLayoutRelationEqual, - childView, NSLayoutAttributeTop, - 1, -margin, - [desc stringByAppendingString:@" top constraint"]); - [contentView addConstraint:c->topConstraint]; - [c->topConstraint retain]; - - c->trailingConstraintGreater = mkConstraint(contentView, NSLayoutAttributeTrailing, - NSLayoutRelationGreaterThanOrEqual, - childView, NSLayoutAttributeTrailing, - 1, margin, - [desc stringByAppendingString:@" trailing >= constraint"]); - if (hugsTrailing) - [c->trailingConstraintGreater setPriority:NSLayoutPriorityDefaultLow]; - [contentView addConstraint:c->trailingConstraintGreater]; - [c->trailingConstraintGreater retain]; - - c->trailingConstraintEqual = mkConstraint(contentView, NSLayoutAttributeTrailing, - NSLayoutRelationEqual, - childView, NSLayoutAttributeTrailing, - 1, margin, - [desc stringByAppendingString:@" trailing == constraint"]); - if (!hugsTrailing) - [c->trailingConstraintEqual setPriority:NSLayoutPriorityDefaultLow]; - [contentView addConstraint:c->trailingConstraintEqual]; - [c->trailingConstraintEqual retain]; - - c->bottomConstraintGreater = mkConstraint(contentView, NSLayoutAttributeBottom, - NSLayoutRelationGreaterThanOrEqual, - childView, NSLayoutAttributeBottom, - 1, margin, - [desc stringByAppendingString:@" bottom >= constraint"]); - if (hugsBottom) - [c->bottomConstraintGreater setPriority:NSLayoutPriorityDefaultLow]; - [contentView addConstraint:c->bottomConstraintGreater]; - [c->bottomConstraintGreater retain]; - - c->bottomConstraintEqual = mkConstraint(contentView, NSLayoutAttributeBottom, - NSLayoutRelationEqual, - childView, NSLayoutAttributeBottom, - 1, margin, - [desc stringByAppendingString:@" bottom == constraint"]); - if (!hugsBottom) - [c->bottomConstraintEqual setPriority:NSLayoutPriorityDefaultLow]; - [contentView addConstraint:c->bottomConstraintEqual]; - [c->bottomConstraintEqual retain]; -} - -void singleChildConstraintsRemove(struct singleChildConstraints *c, NSView *cv) -{ - if (c->leadingConstraint != nil) { - [cv removeConstraint:c->leadingConstraint]; - [c->leadingConstraint release]; - c->leadingConstraint = nil; - } - if (c->topConstraint != nil) { - [cv removeConstraint:c->topConstraint]; - [c->topConstraint release]; - c->topConstraint = nil; - } - if (c->trailingConstraintGreater != nil) { - [cv removeConstraint:c->trailingConstraintGreater]; - [c->trailingConstraintGreater release]; - c->trailingConstraintGreater = nil; - } - if (c->trailingConstraintEqual != nil) { - [cv removeConstraint:c->trailingConstraintEqual]; - [c->trailingConstraintEqual release]; - c->trailingConstraintEqual = nil; - } - if (c->bottomConstraintGreater != nil) { - [cv removeConstraint:c->bottomConstraintGreater]; - [c->bottomConstraintGreater release]; - c->bottomConstraintGreater = nil; - } - if (c->bottomConstraintEqual != nil) { - [cv removeConstraint:c->bottomConstraintEqual]; - [c->bottomConstraintEqual release]; - c->bottomConstraintEqual = nil; - } -} - -void singleChildConstraintsSetMargined(struct singleChildConstraints *c, int margined) -{ - CGFloat margin; - - margin = margins(margined); - if (c->leadingConstraint != nil) - [c->leadingConstraint setConstant:-margin]; - if (c->topConstraint != nil) - [c->topConstraint setConstant:-margin]; - if (c->trailingConstraintGreater != nil) - [c->trailingConstraintGreater setConstant:margin]; - if (c->trailingConstraintEqual != nil) - [c->trailingConstraintEqual setConstant:margin]; - if (c->bottomConstraintGreater != nil) - [c->bottomConstraintGreater setConstant:margin]; - if (c->bottomConstraintEqual != nil) - [c->bottomConstraintEqual setConstant:margin]; -} diff --git a/src/libui_sdl/libui/darwin/box.m b/src/libui_sdl/libui/darwin/box.m deleted file mode 100644 index 18d536d..0000000 --- a/src/libui_sdl/libui/darwin/box.m +++ /dev/null @@ -1,469 +0,0 @@ -// 15 august 2015 -#import "uipriv_darwin.h" - -// TODO hiding all stretchy controls still hugs trailing edge - -@interface boxChild : NSObject -@property uiControl *c; -@property BOOL stretchy; -@property NSLayoutPriority oldPrimaryHuggingPri; -@property NSLayoutPriority oldSecondaryHuggingPri; -- (NSView *)view; -@end - -@interface boxView : NSView { - uiBox *b; - NSMutableArray *children; - BOOL vertical; - int padded; - - NSLayoutConstraint *first; - NSMutableArray *inBetweens; - NSLayoutConstraint *last; - NSMutableArray *otherConstraints; - - NSLayoutAttribute primaryStart; - NSLayoutAttribute primaryEnd; - NSLayoutAttribute secondaryStart; - NSLayoutAttribute secondaryEnd; - NSLayoutAttribute primarySize; - NSLayoutConstraintOrientation primaryOrientation; - NSLayoutConstraintOrientation secondaryOrientation; -} -- (id)initWithVertical:(BOOL)vert b:(uiBox *)bb; -- (void)onDestroy; -- (void)removeOurConstraints; -- (void)syncEnableStates:(int)enabled; -- (CGFloat)paddingAmount; -- (void)establishOurConstraints; -- (void)append:(uiControl *)c stretchy:(int)stretchy; -- (void)delete:(int)n; -- (int)isPadded; -- (void)setPadded:(int)p; -- (BOOL)hugsTrailing; -- (BOOL)hugsBottom; -- (int)nStretchy; -@end - -struct uiBox { - uiDarwinControl c; - boxView *view; -}; - -@implementation boxChild - -- (NSView *)view -{ - return (NSView *) uiControlHandle(self.c); -} - -@end - -@implementation boxView - -- (id)initWithVertical:(BOOL)vert b:(uiBox *)bb -{ - self = [super initWithFrame:NSZeroRect]; - if (self != nil) { - // the weird names vert and bb are to shut the compiler up about shadowing because implicit this/self is stupid - self->b = bb; - self->vertical = vert; - self->padded = 0; - self->children = [NSMutableArray new]; - - self->inBetweens = [NSMutableArray new]; - self->otherConstraints = [NSMutableArray new]; - - if (self->vertical) { - self->primaryStart = NSLayoutAttributeTop; - self->primaryEnd = NSLayoutAttributeBottom; - self->secondaryStart = NSLayoutAttributeLeading; - self->secondaryEnd = NSLayoutAttributeTrailing; - self->primarySize = NSLayoutAttributeHeight; - self->primaryOrientation = NSLayoutConstraintOrientationVertical; - self->secondaryOrientation = NSLayoutConstraintOrientationHorizontal; - } else { - self->primaryStart = NSLayoutAttributeLeading; - self->primaryEnd = NSLayoutAttributeTrailing; - self->secondaryStart = NSLayoutAttributeTop; - self->secondaryEnd = NSLayoutAttributeBottom; - self->primarySize = NSLayoutAttributeWidth; - self->primaryOrientation = NSLayoutConstraintOrientationHorizontal; - self->secondaryOrientation = NSLayoutConstraintOrientationVertical; - } - } - return self; -} - -- (void)onDestroy -{ - boxChild *bc; - - [self removeOurConstraints]; - [self->inBetweens release]; - [self->otherConstraints release]; - - for (bc in self->children) { - uiControlSetParent(bc.c, NULL); - uiDarwinControlSetSuperview(uiDarwinControl(bc.c), nil); - uiControlDestroy(bc.c); - } - [self->children release]; -} - -- (void)removeOurConstraints -{ - if (self->first != nil) { - [self removeConstraint:self->first]; - [self->first release]; - self->first = nil; - } - if ([self->inBetweens count] != 0) { - [self removeConstraints:self->inBetweens]; - [self->inBetweens removeAllObjects]; - } - if (self->last != nil) { - [self removeConstraint:self->last]; - [self->last release]; - self->last = nil; - } - if ([self->otherConstraints count] != 0) { - [self removeConstraints:self->otherConstraints]; - [self->otherConstraints removeAllObjects]; - } -} - -- (void)syncEnableStates:(int)enabled -{ - boxChild *bc; - - for (bc in self->children) - uiDarwinControlSyncEnableState(uiDarwinControl(bc.c), enabled); -} - -- (CGFloat)paddingAmount -{ - if (!self->padded) - return 0.0; - return uiDarwinPaddingAmount(NULL); -} - -- (void)establishOurConstraints -{ - boxChild *bc; - CGFloat padding; - NSView *prev; - NSLayoutConstraint *c; - BOOL (*hugsSecondary)(uiDarwinControl *); - - [self removeOurConstraints]; - if ([self->children count] == 0) - return; - padding = [self paddingAmount]; - - // first arrange in the primary direction - prev = nil; - for (bc in self->children) { - if (!uiControlVisible(bc.c)) - continue; - if (prev == nil) { // first view - self->first = mkConstraint(self, self->primaryStart, - NSLayoutRelationEqual, - [bc view], self->primaryStart, - 1, 0, - @"uiBox first primary constraint"); - [self addConstraint:self->first]; - [self->first retain]; - prev = [bc view]; - continue; - } - // not the first; link it - c = mkConstraint(prev, self->primaryEnd, - NSLayoutRelationEqual, - [bc view], self->primaryStart, - 1, -padding, - @"uiBox in-between primary constraint"); - [self addConstraint:c]; - [self->inBetweens addObject:c]; - prev = [bc view]; - } - if (prev == nil) // no control visible; act as if no controls - return; - self->last = mkConstraint(prev, self->primaryEnd, - NSLayoutRelationEqual, - self, self->primaryEnd, - 1, 0, - @"uiBox last primary constraint"); - [self addConstraint:self->last]; - [self->last retain]; - - // then arrange in the secondary direction - hugsSecondary = uiDarwinControlHugsTrailingEdge; - if (!self->vertical) - hugsSecondary = uiDarwinControlHugsBottom; - for (bc in self->children) { - if (!uiControlVisible(bc.c)) - continue; - c = mkConstraint(self, self->secondaryStart, - NSLayoutRelationEqual, - [bc view], self->secondaryStart, - 1, 0, - @"uiBox secondary start constraint"); - [self addConstraint:c]; - [self->otherConstraints addObject:c]; - c = mkConstraint([bc view], self->secondaryEnd, - NSLayoutRelationLessThanOrEqual, - self, self->secondaryEnd, - 1, 0, - @"uiBox secondary end <= constraint"); - if ((*hugsSecondary)(uiDarwinControl(bc.c))) - [c setPriority:NSLayoutPriorityDefaultLow]; - [self addConstraint:c]; - [self->otherConstraints addObject:c]; - c = mkConstraint([bc view], self->secondaryEnd, - NSLayoutRelationEqual, - self, self->secondaryEnd, - 1, 0, - @"uiBox secondary end == constraint"); - if (!(*hugsSecondary)(uiDarwinControl(bc.c))) - [c setPriority:NSLayoutPriorityDefaultLow]; - [self addConstraint:c]; - [self->otherConstraints addObject:c]; - } - - // and make all stretchy controls the same size - if ([self nStretchy] == 0) - return; - prev = nil; // first stretchy view - for (bc in self->children) { - if (!uiControlVisible(bc.c)) - continue; - if (!bc.stretchy) - continue; - if (prev == nil) { - prev = [bc view]; - continue; - } - c = mkConstraint(prev, self->primarySize, - NSLayoutRelationEqual, - [bc view], self->primarySize, - 1, 0, - @"uiBox stretchy size constraint"); - [self addConstraint:c]; - [self->otherConstraints addObject:c]; - } -} - -- (void)append:(uiControl *)c stretchy:(int)stretchy -{ - boxChild *bc; - NSLayoutPriority priority; - int oldnStretchy; - - bc = [boxChild new]; - bc.c = c; - bc.stretchy = stretchy; - bc.oldPrimaryHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(bc.c), self->primaryOrientation); - bc.oldSecondaryHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(bc.c), self->secondaryOrientation); - - uiControlSetParent(bc.c, uiControl(self->b)); - uiDarwinControlSetSuperview(uiDarwinControl(bc.c), self); - uiDarwinControlSyncEnableState(uiDarwinControl(bc.c), uiControlEnabledToUser(uiControl(self->b))); - - // if a control is stretchy, it should not hug in the primary direction - // otherwise, it should *forcibly* hug - if (bc.stretchy) - priority = NSLayoutPriorityDefaultLow; - else - // LONGTERM will default high work? - priority = NSLayoutPriorityRequired; - uiDarwinControlSetHuggingPriority(uiDarwinControl(bc.c), priority, self->primaryOrientation); - // make sure controls don't hug their secondary direction so they fill the width of the view - uiDarwinControlSetHuggingPriority(uiDarwinControl(bc.c), NSLayoutPriorityDefaultLow, self->secondaryOrientation); - - oldnStretchy = [self nStretchy]; - [self->children addObject:bc]; - - [self establishOurConstraints]; - if (bc.stretchy) - if (oldnStretchy == 0) - uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(self->b)); - - [bc release]; // we don't need the initial reference now -} - -- (void)delete:(int)n -{ - boxChild *bc; - int stretchy; - - bc = (boxChild *) [self->children objectAtIndex:n]; - stretchy = bc.stretchy; - - uiControlSetParent(bc.c, NULL); - uiDarwinControlSetSuperview(uiDarwinControl(bc.c), nil); - - uiDarwinControlSetHuggingPriority(uiDarwinControl(bc.c), bc.oldPrimaryHuggingPri, self->primaryOrientation); - uiDarwinControlSetHuggingPriority(uiDarwinControl(bc.c), bc.oldSecondaryHuggingPri, self->secondaryOrientation); - - [self->children removeObjectAtIndex:n]; - - [self establishOurConstraints]; - if (stretchy) - if ([self nStretchy] == 0) - uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(self->b)); -} - -- (int)isPadded -{ - return self->padded; -} - -- (void)setPadded:(int)p -{ - CGFloat padding; - NSLayoutConstraint *c; - - self->padded = p; - padding = [self paddingAmount]; - for (c in self->inBetweens) - [c setConstant:-padding]; -} - -- (BOOL)hugsTrailing -{ - if (self->vertical) // always hug if vertical - return YES; - return [self nStretchy] != 0; -} - -- (BOOL)hugsBottom -{ - if (!self->vertical) // always hug if horizontal - return YES; - return [self nStretchy] != 0; -} - -- (int)nStretchy -{ - boxChild *bc; - int n; - - n = 0; - for (bc in self->children) { - if (!uiControlVisible(bc.c)) - continue; - if (bc.stretchy) - n++; - } - return n; -} - -@end - -static void uiBoxDestroy(uiControl *c) -{ - uiBox *b = uiBox(c); - - [b->view onDestroy]; - [b->view release]; - uiFreeControl(uiControl(b)); -} - -uiDarwinControlDefaultHandle(uiBox, view) -uiDarwinControlDefaultParent(uiBox, view) -uiDarwinControlDefaultSetParent(uiBox, view) -uiDarwinControlDefaultToplevel(uiBox, view) -uiDarwinControlDefaultVisible(uiBox, view) -uiDarwinControlDefaultShow(uiBox, view) -uiDarwinControlDefaultHide(uiBox, view) -uiDarwinControlDefaultEnabled(uiBox, view) -uiDarwinControlDefaultEnable(uiBox, view) -uiDarwinControlDefaultDisable(uiBox, view) - -static void uiBoxSyncEnableState(uiDarwinControl *c, int enabled) -{ - uiBox *b = uiBox(c); - - if (uiDarwinShouldStopSyncEnableState(uiDarwinControl(b), enabled)) - return; - [b->view syncEnableStates:enabled]; -} - -uiDarwinControlDefaultSetSuperview(uiBox, view) - -static BOOL uiBoxHugsTrailingEdge(uiDarwinControl *c) -{ - uiBox *b = uiBox(c); - - return [b->view hugsTrailing]; -} - -static BOOL uiBoxHugsBottom(uiDarwinControl *c) -{ - uiBox *b = uiBox(c); - - return [b->view hugsBottom]; -} - -static void uiBoxChildEdgeHuggingChanged(uiDarwinControl *c) -{ - uiBox *b = uiBox(c); - - [b->view establishOurConstraints]; -} - -uiDarwinControlDefaultHuggingPriority(uiBox, view) -uiDarwinControlDefaultSetHuggingPriority(uiBox, view) - -static void uiBoxChildVisibilityChanged(uiDarwinControl *c) -{ - uiBox *b = uiBox(c); - - [b->view establishOurConstraints]; -} - -void uiBoxAppend(uiBox *b, uiControl *c, int stretchy) -{ - // LONGTERM on other platforms - // or at leat allow this and implicitly turn it into a spacer - if (c == NULL) - userbug("You cannot add NULL to a uiBox."); - [b->view append:c stretchy:stretchy]; -} - -void uiBoxDelete(uiBox *b, int n) -{ - [b->view delete:n]; -} - -int uiBoxPadded(uiBox *b) -{ - return [b->view isPadded]; -} - -void uiBoxSetPadded(uiBox *b, int padded) -{ - [b->view setPadded:padded]; -} - -static uiBox *finishNewBox(BOOL vertical) -{ - uiBox *b; - - uiDarwinNewControl(uiBox, b); - - b->view = [[boxView alloc] initWithVertical:vertical b:b]; - - return b; -} - -uiBox *uiNewHorizontalBox(void) -{ - return finishNewBox(NO); -} - -uiBox *uiNewVerticalBox(void) -{ - return finishNewBox(YES); -} diff --git a/src/libui_sdl/libui/darwin/button.m b/src/libui_sdl/libui/darwin/button.m deleted file mode 100644 index baccabb..0000000 --- a/src/libui_sdl/libui/darwin/button.m +++ /dev/null @@ -1,113 +0,0 @@ -// 13 august 2015 -#import "uipriv_darwin.h" - -struct uiButton { - uiDarwinControl c; - NSButton *button; - void (*onClicked)(uiButton *, void *); - void *onClickedData; -}; - -@interface buttonDelegateClass : NSObject { - struct mapTable *buttons; -} -- (IBAction)onClicked:(id)sender; -- (void)registerButton:(uiButton *)b; -- (void)unregisterButton:(uiButton *)b; -@end - -@implementation buttonDelegateClass - -- (id)init -{ - self = [super init]; - if (self) - self->buttons = newMap(); - return self; -} - -- (void)dealloc -{ - mapDestroy(self->buttons); - [super dealloc]; -} - -- (IBAction)onClicked:(id)sender -{ - uiButton *b; - - b = (uiButton *) mapGet(self->buttons, sender); - (*(b->onClicked))(b, b->onClickedData); -} - -- (void)registerButton:(uiButton *)b -{ - mapSet(self->buttons, b->button, b); - [b->button setTarget:self]; - [b->button setAction:@selector(onClicked:)]; -} - -- (void)unregisterButton:(uiButton *)b -{ - [b->button setTarget:nil]; - mapDelete(self->buttons, b->button); -} - -@end - -static buttonDelegateClass *buttonDelegate = nil; - -uiDarwinControlAllDefaultsExceptDestroy(uiButton, button) - -static void uiButtonDestroy(uiControl *c) -{ - uiButton *b = uiButton(c); - - [buttonDelegate unregisterButton:b]; - [b->button release]; - uiFreeControl(uiControl(b)); -} - -char *uiButtonText(uiButton *b) -{ - return uiDarwinNSStringToText([b->button title]); -} - -void uiButtonSetText(uiButton *b, const char *text) -{ - [b->button setTitle:toNSString(text)]; -} - -void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *, void *), void *data) -{ - b->onClicked = f; - b->onClickedData = data; -} - -static void defaultOnClicked(uiButton *b, void *data) -{ - // do nothing -} - -uiButton *uiNewButton(const char *text) -{ - uiButton *b; - - uiDarwinNewControl(uiButton, b); - - b->button = [[NSButton alloc] initWithFrame:NSZeroRect]; - [b->button setTitle:toNSString(text)]; - [b->button setButtonType:NSMomentaryPushInButton]; - [b->button setBordered:YES]; - [b->button setBezelStyle:NSRoundedBezelStyle]; - uiDarwinSetControlFont(b->button, NSRegularControlSize); - - if (buttonDelegate == nil) { - buttonDelegate = [[buttonDelegateClass new] autorelease]; - [delegates addObject:buttonDelegate]; - } - [buttonDelegate registerButton:b]; - uiButtonOnClicked(b, defaultOnClicked, NULL); - - return b; -} diff --git a/src/libui_sdl/libui/darwin/checkbox.m b/src/libui_sdl/libui/darwin/checkbox.m deleted file mode 100644 index dd1ce09..0000000 --- a/src/libui_sdl/libui/darwin/checkbox.m +++ /dev/null @@ -1,129 +0,0 @@ -// 14 august 2015 -#import "uipriv_darwin.h" - -struct uiCheckbox { - uiDarwinControl c; - NSButton *button; - void (*onToggled)(uiCheckbox *, void *); - void *onToggledData; -}; - -@interface checkboxDelegateClass : NSObject { - struct mapTable *buttons; -} -- (IBAction)onToggled:(id)sender; -- (void)registerCheckbox:(uiCheckbox *)c; -- (void)unregisterCheckbox:(uiCheckbox *)c; -@end - -@implementation checkboxDelegateClass - -- (id)init -{ - self = [super init]; - if (self) - self->buttons = newMap(); - return self; -} - -- (void)dealloc -{ - mapDestroy(self->buttons); - [super dealloc]; -} - -- (IBAction)onToggled:(id)sender -{ - uiCheckbox *c; - - c = (uiCheckbox *) mapGet(self->buttons, sender); - (*(c->onToggled))(c, c->onToggledData); -} - -- (void)registerCheckbox:(uiCheckbox *)c -{ - mapSet(self->buttons, c->button, c); - [c->button setTarget:self]; - [c->button setAction:@selector(onToggled:)]; -} - -- (void)unregisterCheckbox:(uiCheckbox *)c -{ - [c->button setTarget:nil]; - mapDelete(self->buttons, c->button); -} - -@end - -static checkboxDelegateClass *checkboxDelegate = nil; - -uiDarwinControlAllDefaultsExceptDestroy(uiCheckbox, button) - -static void uiCheckboxDestroy(uiControl *cc) -{ - uiCheckbox *c = uiCheckbox(cc); - - [checkboxDelegate unregisterCheckbox:c]; - [c->button release]; - uiFreeControl(uiControl(c)); -} - -char *uiCheckboxText(uiCheckbox *c) -{ - return uiDarwinNSStringToText([c->button title]); -} - -void uiCheckboxSetText(uiCheckbox *c, const char *text) -{ - [c->button setTitle:toNSString(text)]; -} - -void uiCheckboxOnToggled(uiCheckbox *c, void (*f)(uiCheckbox *, void *), void *data) -{ - c->onToggled = f; - c->onToggledData = data; -} - -int uiCheckboxChecked(uiCheckbox *c) -{ - return [c->button state] == NSOnState; -} - -void uiCheckboxSetChecked(uiCheckbox *c, int checked) -{ - NSInteger state; - - state = NSOnState; - if (!checked) - state = NSOffState; - [c->button setState:state]; -} - -static void defaultOnToggled(uiCheckbox *c, void *data) -{ - // do nothing -} - -uiCheckbox *uiNewCheckbox(const char *text) -{ - uiCheckbox *c; - - uiDarwinNewControl(uiCheckbox, c); - - c->button = [[NSButton alloc] initWithFrame:NSZeroRect]; - [c->button setTitle:toNSString(text)]; - [c->button setButtonType:NSSwitchButton]; - // doesn't seem to have an associated bezel style - [c->button setBordered:NO]; - [c->button setTransparent:NO]; - uiDarwinSetControlFont(c->button, NSRegularControlSize); - - if (checkboxDelegate == nil) { - checkboxDelegate = [[checkboxDelegateClass new] autorelease]; - [delegates addObject:checkboxDelegate]; - } - [checkboxDelegate registerCheckbox:c]; - uiCheckboxOnToggled(c, defaultOnToggled, NULL); - - return c; -} diff --git a/src/libui_sdl/libui/darwin/colorbutton.m b/src/libui_sdl/libui/darwin/colorbutton.m deleted file mode 100644 index 83b6157..0000000 --- a/src/libui_sdl/libui/darwin/colorbutton.m +++ /dev/null @@ -1,159 +0,0 @@ -// 15 may 2016 -#import "uipriv_darwin.h" - -// TODO no intrinsic height? - -@interface colorButton : NSColorWell { - uiColorButton *libui_b; - BOOL libui_changing; - BOOL libui_setting; -} -- (id)initWithFrame:(NSRect)frame libuiColorButton:(uiColorButton *)b; -- (void)deactivateOnClose:(NSNotification *)note; -- (void)libuiColor:(double *)r g:(double *)g b:(double *)b a:(double *)a; -- (void)libuiSetColor:(double)r g:(double)g b:(double)b a:(double)a; -@end - -// only one may be active at one time -static colorButton *activeColorButton = nil; - -struct uiColorButton { - uiDarwinControl c; - colorButton *button; - void (*onChanged)(uiColorButton *, void *); - void *onChangedData; -}; - -@implementation colorButton - -- (id)initWithFrame:(NSRect)frame libuiColorButton:(uiColorButton *)b -{ - self = [super initWithFrame:frame]; - if (self) { - // the default color is white; set it to black first (see -setColor: below for why we do it first) - [self libuiSetColor:0.0 g:0.0 b:0.0 a:1.0]; - - self->libui_b = b; - self->libui_changing = NO; - } - return self; -} - -- (void)activate:(BOOL)exclusive -{ - if (activeColorButton != nil) - activeColorButton->libui_changing = YES; - [NSColorPanel setPickerMask:NSColorPanelAllModesMask]; - [[NSColorPanel sharedColorPanel] setShowsAlpha:YES]; - [super activate:YES]; - activeColorButton = self; - // see stddialogs.m for details - [[NSColorPanel sharedColorPanel] setWorksWhenModal:NO]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(deactivateOnClose:) - name:NSWindowWillCloseNotification - object:[NSColorPanel sharedColorPanel]]; -} - -- (void)deactivate -{ - [super deactivate]; - activeColorButton = nil; - if (!self->libui_changing) - [[NSColorPanel sharedColorPanel] orderOut:nil]; - [[NSNotificationCenter defaultCenter] removeObserver:self - name:NSWindowWillCloseNotification - object:[NSColorPanel sharedColorPanel]]; - self->libui_changing = NO; -} - -- (void)deactivateOnClose:(NSNotification *)note -{ - [self deactivate]; -} - -- (void)setColor:(NSColor *)color -{ - uiColorButton *b = self->libui_b; - - [super setColor:color]; - // this is called by NSColorWell's init, so we have to guard - // also don't signal during a programmatic change - if (b != nil && !self->libui_setting) - (*(b->onChanged))(b, b->onChangedData); -} - -- (void)libuiColor:(double *)r g:(double *)g b:(double *)b a:(double *)a -{ - NSColor *rgba; - CGFloat cr, cg, cb, ca; - - // the given color may not be an RGBA color, which will cause the -getRed:green:blue:alpha: call to throw an exception - rgba = [[self color] colorUsingColorSpace:[NSColorSpace sRGBColorSpace]]; - [rgba getRed:&cr green:&cg blue:&cb alpha:&ca]; - *r = cr; - *g = cg; - *b = cb; - *a = ca; - // rgba will be autoreleased since it isn't a new or init call -} - -- (void)libuiSetColor:(double)r g:(double)g b:(double)b a:(double)a -{ - self->libui_setting = YES; - [self setColor:[NSColor colorWithSRGBRed:r green:g blue:b alpha:a]]; - self->libui_setting = NO; -} - -// NSColorWell has no intrinsic size by default; give it the default Interface Builder size. -- (NSSize)intrinsicContentSize -{ - return NSMakeSize(44, 23); -} - -@end - -uiDarwinControlAllDefaults(uiColorButton, button) - -// we do not want color change events to be sent to any controls other than the color buttons -// see main.m for more details -BOOL colorButtonInhibitSendAction(SEL sel, id from, id to) -{ - if (sel != @selector(changeColor:)) - return NO; - return ![to isKindOfClass:[colorButton class]]; -} - -static void defaultOnChanged(uiColorButton *b, void *data) -{ - // do nothing -} - -void uiColorButtonColor(uiColorButton *b, double *r, double *g, double *bl, double *a) -{ - [b->button libuiColor:r g:g b:bl a:a]; -} - -void uiColorButtonSetColor(uiColorButton *b, double r, double g, double bl, double a) -{ - [b->button libuiSetColor:r g:g b:bl a:a]; -} - -void uiColorButtonOnChanged(uiColorButton *b, void (*f)(uiColorButton *, void *), void *data) -{ - b->onChanged = f; - b->onChangedData = data; -} - -uiColorButton *uiNewColorButton(void) -{ - uiColorButton *b; - - uiDarwinNewControl(uiColorButton, b); - - b->button = [[colorButton alloc] initWithFrame:NSZeroRect libuiColorButton:b]; - - uiColorButtonOnChanged(b, defaultOnChanged, NULL); - - return b; -} diff --git a/src/libui_sdl/libui/darwin/combobox.m b/src/libui_sdl/libui/darwin/combobox.m deleted file mode 100644 index 89a2e28..0000000 --- a/src/libui_sdl/libui/darwin/combobox.m +++ /dev/null @@ -1,145 +0,0 @@ -// 14 august 2015 -#import "uipriv_darwin.h" - -// NSComboBoxes have no intrinsic width; we'll use the default Interface Builder width for them. -// NSPopUpButton is fine. -#define comboboxWidth 96 - -struct uiCombobox { - uiDarwinControl c; - NSPopUpButton *pb; - NSArrayController *pbac; - void (*onSelected)(uiCombobox *, void *); - void *onSelectedData; -}; - -@interface comboboxDelegateClass : NSObject { - struct mapTable *comboboxes; -} -- (IBAction)onSelected:(id)sender; -- (void)registerCombobox:(uiCombobox *)c; -- (void)unregisterCombobox:(uiCombobox *)c; -@end - -@implementation comboboxDelegateClass - -- (id)init -{ - self = [super init]; - if (self) - self->comboboxes = newMap(); - return self; -} - -- (void)dealloc -{ - mapDestroy(self->comboboxes); - [super dealloc]; -} - -- (IBAction)onSelected:(id)sender -{ - uiCombobox *c; - - c = uiCombobox(mapGet(self->comboboxes, sender)); - (*(c->onSelected))(c, c->onSelectedData); -} - -- (void)registerCombobox:(uiCombobox *)c -{ - mapSet(self->comboboxes, c->pb, c); - [c->pb setTarget:self]; - [c->pb setAction:@selector(onSelected:)]; -} - -- (void)unregisterCombobox:(uiCombobox *)c -{ - [c->pb setTarget:nil]; - mapDelete(self->comboboxes, c->pb); -} - -@end - -static comboboxDelegateClass *comboboxDelegate = nil; - -uiDarwinControlAllDefaultsExceptDestroy(uiCombobox, pb) - -static void uiComboboxDestroy(uiControl *cc) -{ - uiCombobox *c = uiCombobox(cc); - - [comboboxDelegate unregisterCombobox:c]; - [c->pb unbind:@"contentObjects"]; - [c->pb unbind:@"selectedIndex"]; - [c->pbac release]; - [c->pb release]; - uiFreeControl(uiControl(c)); -} - -void uiComboboxAppend(uiCombobox *c, const char *text) -{ - [c->pbac addObject:toNSString(text)]; -} - -int uiComboboxSelected(uiCombobox *c) -{ - return [c->pb indexOfSelectedItem]; -} - -void uiComboboxSetSelected(uiCombobox *c, int n) -{ - [c->pb selectItemAtIndex:n]; -} - -void uiComboboxOnSelected(uiCombobox *c, void (*f)(uiCombobox *c, void *data), void *data) -{ - c->onSelected = f; - c->onSelectedData = data; -} - -static void defaultOnSelected(uiCombobox *c, void *data) -{ - // do nothing -} - -uiCombobox *uiNewCombobox(void) -{ - uiCombobox *c; - NSPopUpButtonCell *pbcell; - - uiDarwinNewControl(uiCombobox, c); - - c->pb = [[NSPopUpButton alloc] initWithFrame:NSZeroRect pullsDown:NO]; - [c->pb setPreferredEdge:NSMinYEdge]; - pbcell = (NSPopUpButtonCell *) [c->pb cell]; - [pbcell setArrowPosition:NSPopUpArrowAtBottom]; - // the font defined by Interface Builder is Menu 13, which is lol - // just use the regular control size for consistency - uiDarwinSetControlFont(c->pb, NSRegularControlSize); - - // NSPopUpButton doesn't work like a combobox - // - it automatically selects the first item - // - it doesn't support duplicates - // but we can use a NSArrayController and Cocoa bindings to bypass these restrictions - c->pbac = [NSArrayController new]; - [c->pbac setAvoidsEmptySelection:NO]; - [c->pbac setSelectsInsertedObjects:NO]; - [c->pbac setAutomaticallyRearrangesObjects:NO]; - [c->pb bind:@"contentValues" - toObject:c->pbac - withKeyPath:@"arrangedObjects" - options:nil]; - [c->pb bind:@"selectedIndex" - toObject:c->pbac - withKeyPath:@"selectionIndex" - options:nil]; - - if (comboboxDelegate == nil) { - comboboxDelegate = [[comboboxDelegateClass new] autorelease]; - [delegates addObject:comboboxDelegate]; - } - [comboboxDelegate registerCombobox:c]; - uiComboboxOnSelected(c, defaultOnSelected, NULL); - - return c; -} diff --git a/src/libui_sdl/libui/darwin/control.m b/src/libui_sdl/libui/darwin/control.m deleted file mode 100644 index 9eaf47a..0000000 --- a/src/libui_sdl/libui/darwin/control.m +++ /dev/null @@ -1,84 +0,0 @@ -// 16 august 2015 -#import "uipriv_darwin.h" - -void uiDarwinControlSyncEnableState(uiDarwinControl *c, int state) -{ - (*(c->SyncEnableState))(c, state); -} - -void uiDarwinControlSetSuperview(uiDarwinControl *c, NSView *superview) -{ - (*(c->SetSuperview))(c, superview); -} - -BOOL uiDarwinControlHugsTrailingEdge(uiDarwinControl *c) -{ - return (*(c->HugsTrailingEdge))(c); -} - -BOOL uiDarwinControlHugsBottom(uiDarwinControl *c) -{ - return (*(c->HugsBottom))(c); -} - -void uiDarwinControlChildEdgeHuggingChanged(uiDarwinControl *c) -{ - (*(c->ChildEdgeHuggingChanged))(c); -} - -NSLayoutPriority uiDarwinControlHuggingPriority(uiDarwinControl *c, NSLayoutConstraintOrientation orientation) -{ - return (*(c->HuggingPriority))(c, orientation); -} - -void uiDarwinControlSetHuggingPriority(uiDarwinControl *c, NSLayoutPriority priority, NSLayoutConstraintOrientation orientation) -{ - (*(c->SetHuggingPriority))(c, priority, orientation); -} - -void uiDarwinControlChildVisibilityChanged(uiDarwinControl *c) -{ - (*(c->ChildVisibilityChanged))(c); -} - -void uiDarwinSetControlFont(NSControl *c, NSControlSize size) -{ - [c setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:size]]]; -} - -#define uiDarwinControlSignature 0x44617277 - -uiDarwinControl *uiDarwinAllocControl(size_t n, uint32_t typesig, const char *typenamestr) -{ - return uiDarwinControl(uiAllocControl(n, uiDarwinControlSignature, typesig, typenamestr)); -} - -BOOL uiDarwinShouldStopSyncEnableState(uiDarwinControl *c, BOOL enabled) -{ - int ce; - - ce = uiControlEnabled(uiControl(c)); - // only stop if we're going from disabled back to enabled; don't stop under any other condition - // (if we stop when going from enabled to disabled then enabled children of a disabled control won't get disabled at the OS level) - if (!ce && enabled) - return YES; - return NO; -} - -void uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl *c) -{ - uiControl *parent; - - parent = uiControlParent(uiControl(c)); - if (parent != NULL) - uiDarwinControlChildEdgeHuggingChanged(uiDarwinControl(parent)); -} - -void uiDarwinNotifyVisibilityChanged(uiDarwinControl *c) -{ - uiControl *parent; - - parent = uiControlParent(uiControl(c)); - if (parent != NULL) - uiDarwinControlChildVisibilityChanged(uiDarwinControl(parent)); -} diff --git a/src/libui_sdl/libui/darwin/datetimepicker.m b/src/libui_sdl/libui/darwin/datetimepicker.m deleted file mode 100644 index 44364d9..0000000 --- a/src/libui_sdl/libui/darwin/datetimepicker.m +++ /dev/null @@ -1,42 +0,0 @@ -// 14 august 2015 -#import "uipriv_darwin.h" - -struct uiDateTimePicker { - uiDarwinControl c; - NSDatePicker *dp; -}; - -uiDarwinControlAllDefaults(uiDateTimePicker, dp) - -static uiDateTimePicker *finishNewDateTimePicker(NSDatePickerElementFlags elements) -{ - uiDateTimePicker *d; - - uiDarwinNewControl(uiDateTimePicker, d); - - d->dp = [[NSDatePicker alloc] initWithFrame:NSZeroRect]; - [d->dp setBordered:NO]; - [d->dp setBezeled:YES]; - [d->dp setDrawsBackground:YES]; - [d->dp setDatePickerStyle:NSTextFieldAndStepperDatePickerStyle]; - [d->dp setDatePickerElements:elements]; - [d->dp setDatePickerMode:NSSingleDateMode]; - uiDarwinSetControlFont(d->dp, NSRegularControlSize); - - return d; -} - -uiDateTimePicker *uiNewDateTimePicker(void) -{ - return finishNewDateTimePicker(NSYearMonthDayDatePickerElementFlag | NSHourMinuteSecondDatePickerElementFlag); -} - -uiDateTimePicker *uiNewDatePicker(void) -{ - return finishNewDateTimePicker(NSYearMonthDayDatePickerElementFlag); -} - -uiDateTimePicker *uiNewTimePicker(void) -{ - return finishNewDateTimePicker(NSHourMinuteSecondDatePickerElementFlag); -} diff --git a/src/libui_sdl/libui/darwin/debug.m b/src/libui_sdl/libui/darwin/debug.m deleted file mode 100644 index c91c6a7..0000000 --- a/src/libui_sdl/libui/darwin/debug.m +++ /dev/null @@ -1,19 +0,0 @@ -// 13 may 2016 -#import "uipriv_darwin.h" - -// LONGTERM don't halt on release builds - -void realbug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap) -{ - NSMutableString *str; - NSString *formatted; - - str = [NSMutableString new]; - [str appendString:[NSString stringWithFormat:@"[libui] %s:%s:%s() %s", file, line, func, prefix]]; - formatted = [[NSString alloc] initWithFormat:[NSString stringWithUTF8String:format] arguments:ap]; - [str appendString:formatted]; - [formatted release]; - NSLog(@"%@", str); - [str release]; - __builtin_trap(); -} diff --git a/src/libui_sdl/libui/darwin/draw.m b/src/libui_sdl/libui/darwin/draw.m deleted file mode 100644 index 262ad3e..0000000 --- a/src/libui_sdl/libui/darwin/draw.m +++ /dev/null @@ -1,454 +0,0 @@ -// 6 september 2015 -#import "uipriv_darwin.h" - -struct uiDrawPath { - CGMutablePathRef path; - uiDrawFillMode fillMode; - BOOL ended; -}; - -uiDrawPath *uiDrawNewPath(uiDrawFillMode mode) -{ - uiDrawPath *p; - - p = uiNew(uiDrawPath); - p->path = CGPathCreateMutable(); - p->fillMode = mode; - return p; -} - -void uiDrawFreePath(uiDrawPath *p) -{ - CGPathRelease((CGPathRef) (p->path)); - uiFree(p); -} - -void uiDrawPathNewFigure(uiDrawPath *p, double x, double y) -{ - if (p->ended) - userbug("You cannot call uiDrawPathNewFigure() on a uiDrawPath that has already been ended. (path; %p)", p); - CGPathMoveToPoint(p->path, NULL, x, y); -} - -void uiDrawPathNewFigureWithArc(uiDrawPath *p, double xCenter, double yCenter, double radius, double startAngle, double sweep, int negative) -{ - double sinStart, cosStart; - double startx, starty; - - if (p->ended) - userbug("You cannot call uiDrawPathNewFigureWithArc() on a uiDrawPath that has already been ended. (path; %p)", p); - sinStart = sin(startAngle); - cosStart = cos(startAngle); - startx = xCenter + radius * cosStart; - starty = yCenter + radius * sinStart; - CGPathMoveToPoint(p->path, NULL, startx, starty); - uiDrawPathArcTo(p, xCenter, yCenter, radius, startAngle, sweep, negative); -} - -void uiDrawPathLineTo(uiDrawPath *p, double x, double y) -{ - // TODO refine this to require being in a path - if (p->ended) - implbug("attempt to add line to ended path in uiDrawPathLineTo()"); - CGPathAddLineToPoint(p->path, NULL, x, y); -} - -void uiDrawPathArcTo(uiDrawPath *p, double xCenter, double yCenter, double radius, double startAngle, double sweep, int negative) -{ - bool cw; - - // TODO likewise - if (p->ended) - implbug("attempt to add arc to ended path in uiDrawPathArcTo()"); - if (sweep > 2 * uiPi) - sweep = 2 * uiPi; - cw = false; - if (negative) - cw = true; - CGPathAddArc(p->path, NULL, - xCenter, yCenter, - radius, - startAngle, startAngle + sweep, - cw); -} - -void uiDrawPathBezierTo(uiDrawPath *p, double c1x, double c1y, double c2x, double c2y, double endX, double endY) -{ - // TODO likewise - if (p->ended) - implbug("attempt to add bezier to ended path in uiDrawPathBezierTo()"); - CGPathAddCurveToPoint(p->path, NULL, - c1x, c1y, - c2x, c2y, - endX, endY); -} - -void uiDrawPathCloseFigure(uiDrawPath *p) -{ - // TODO likewise - if (p->ended) - implbug("attempt to close figure of ended path in uiDrawPathCloseFigure()"); - CGPathCloseSubpath(p->path); -} - -void uiDrawPathAddRectangle(uiDrawPath *p, double x, double y, double width, double height) -{ - if (p->ended) - userbug("You cannot call uiDrawPathAddRectangle() on a uiDrawPath that has already been ended. (path; %p)", p); - CGPathAddRect(p->path, NULL, CGRectMake(x, y, width, height)); -} - -void uiDrawPathEnd(uiDrawPath *p) -{ - p->ended = TRUE; -} - -struct uiDrawContext { - CGContextRef c; - CGFloat height; // needed for text; see below -}; - -uiDrawContext *newContext(CGContextRef ctxt, CGFloat height) -{ - uiDrawContext *c; - - c = uiNew(uiDrawContext); - c->c = ctxt; - c->height = height; - return c; -} - -void freeContext(uiDrawContext *c) -{ - uiFree(c); -} - -// a stroke is identical to a fill of a stroked path -// we need to do this in order to stroke with a gradient; see http://stackoverflow.com/a/25034854/3408572 -// doing this for other brushes works too -void uiDrawStroke(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b, uiDrawStrokeParams *p) -{ - CGLineCap cap; - CGLineJoin join; - CGPathRef dashPath; - CGFloat *dashes; - size_t i; - uiDrawPath p2; - - if (!path->ended) - userbug("You cannot call uiDrawStroke() on a uiDrawPath that has not been ended. (path: %p)", path); - - switch (p->Cap) { - case uiDrawLineCapFlat: - cap = kCGLineCapButt; - break; - case uiDrawLineCapRound: - cap = kCGLineCapRound; - break; - case uiDrawLineCapSquare: - cap = kCGLineCapSquare; - break; - } - switch (p->Join) { - case uiDrawLineJoinMiter: - join = kCGLineJoinMiter; - break; - case uiDrawLineJoinRound: - join = kCGLineJoinRound; - break; - case uiDrawLineJoinBevel: - join = kCGLineJoinBevel; - break; - } - - // create a temporary path identical to the previous one - dashPath = (CGPathRef) path->path; - if (p->NumDashes != 0) { - dashes = (CGFloat *) uiAlloc(p->NumDashes * sizeof (CGFloat), "CGFloat[]"); - for (i = 0; i < p->NumDashes; i++) - dashes[i] = p->Dashes[i]; - dashPath = CGPathCreateCopyByDashingPath(path->path, - NULL, - p->DashPhase, - dashes, - p->NumDashes); - uiFree(dashes); - } - // the documentation is wrong: this produces a path suitable for calling CGPathCreateCopyByStrokingPath(), not for filling directly - // the cast is safe; we never modify the CGPathRef and always cast it back to a CGPathRef anyway - p2.path = (CGMutablePathRef) CGPathCreateCopyByStrokingPath(dashPath, - NULL, - p->Thickness, - cap, - join, - p->MiterLimit); - if (p->NumDashes != 0) - CGPathRelease(dashPath); - - // always draw stroke fills using the winding rule - // otherwise intersecting figures won't draw correctly - p2.fillMode = uiDrawFillModeWinding; - p2.ended = path->ended; - uiDrawFill(c, &p2, b); - // and clean up - CGPathRelease((CGPathRef) (p2.path)); -} - -// for a solid fill, we can merely have Core Graphics fill directly -static void fillSolid(CGContextRef ctxt, uiDrawPath *p, uiDrawBrush *b) -{ - // TODO this uses DeviceRGB; switch to sRGB - CGContextSetRGBFillColor(ctxt, b->R, b->G, b->B, b->A); - switch (p->fillMode) { - case uiDrawFillModeWinding: - CGContextFillPath(ctxt); - break; - case uiDrawFillModeAlternate: - CGContextEOFillPath(ctxt); - break; - } -} - -// for a gradient fill, we need to clip to the path and then draw the gradient -// see http://stackoverflow.com/a/25034854/3408572 -static void fillGradient(CGContextRef ctxt, uiDrawPath *p, uiDrawBrush *b) -{ - CGGradientRef gradient; - CGColorSpaceRef colorspace; - CGFloat *colors; - CGFloat *locations; - size_t i; - - // gradients need a color space - // for consistency with windows, use sRGB - colorspace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB); - - // make the gradient - colors = uiAlloc(b->NumStops * 4 * sizeof (CGFloat), "CGFloat[]"); - locations = uiAlloc(b->NumStops * sizeof (CGFloat), "CGFloat[]"); - for (i = 0; i < b->NumStops; i++) { - colors[i * 4 + 0] = b->Stops[i].R; - colors[i * 4 + 1] = b->Stops[i].G; - colors[i * 4 + 2] = b->Stops[i].B; - colors[i * 4 + 3] = b->Stops[i].A; - locations[i] = b->Stops[i].Pos; - } - gradient = CGGradientCreateWithColorComponents(colorspace, colors, locations, b->NumStops); - uiFree(locations); - uiFree(colors); - - // because we're mucking with clipping, we need to save the graphics state and restore it later - CGContextSaveGState(ctxt); - - // clip - switch (p->fillMode) { - case uiDrawFillModeWinding: - CGContextClip(ctxt); - break; - case uiDrawFillModeAlternate: - CGContextEOClip(ctxt); - break; - } - - // draw the gradient - switch (b->Type) { - case uiDrawBrushTypeLinearGradient: - CGContextDrawLinearGradient(ctxt, - gradient, - CGPointMake(b->X0, b->Y0), - CGPointMake(b->X1, b->Y1), - kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation); - break; - case uiDrawBrushTypeRadialGradient: - CGContextDrawRadialGradient(ctxt, - gradient, - CGPointMake(b->X0, b->Y0), - // make the start circle radius 0 to make it a point - 0, - CGPointMake(b->X1, b->Y1), - b->OuterRadius, - kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation); - break; - } - - // and clean up - CGContextRestoreGState(ctxt); - CGGradientRelease(gradient); - CGColorSpaceRelease(colorspace); -} - -void uiDrawFill(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b) -{ - if (!path->ended) - userbug("You cannot call uiDrawStroke() on a uiDrawPath that has not been ended. (path: %p)", path); - CGContextAddPath(c->c, (CGPathRef) (path->path)); - switch (b->Type) { - case uiDrawBrushTypeSolid: - fillSolid(c->c, path, b); - return; - case uiDrawBrushTypeLinearGradient: - case uiDrawBrushTypeRadialGradient: - fillGradient(c->c, path, b); - return; -// case uiDrawBrushTypeImage: - // TODO - return; - } - userbug("Unknown brush type %d passed to uiDrawFill().", b->Type); -} - -static void m2c(uiDrawMatrix *m, CGAffineTransform *c) -{ - c->a = m->M11; - c->b = m->M12; - c->c = m->M21; - c->d = m->M22; - c->tx = m->M31; - c->ty = m->M32; -} - -static void c2m(CGAffineTransform *c, uiDrawMatrix *m) -{ - m->M11 = c->a; - m->M12 = c->b; - m->M21 = c->c; - m->M22 = c->d; - m->M31 = c->tx; - m->M32 = c->ty; -} - -void uiDrawMatrixTranslate(uiDrawMatrix *m, double x, double y) -{ - CGAffineTransform c; - - m2c(m, &c); - c = CGAffineTransformTranslate(c, x, y); - c2m(&c, m); -} - -void uiDrawMatrixScale(uiDrawMatrix *m, double xCenter, double yCenter, double x, double y) -{ - CGAffineTransform c; - double xt, yt; - - m2c(m, &c); - xt = x; - yt = y; - scaleCenter(xCenter, yCenter, &xt, &yt); - c = CGAffineTransformTranslate(c, xt, yt); - c = CGAffineTransformScale(c, x, y); - c = CGAffineTransformTranslate(c, -xt, -yt); - c2m(&c, m); -} - -void uiDrawMatrixRotate(uiDrawMatrix *m, double x, double y, double amount) -{ - CGAffineTransform c; - - m2c(m, &c); - c = CGAffineTransformTranslate(c, x, y); - c = CGAffineTransformRotate(c, amount); - c = CGAffineTransformTranslate(c, -x, -y); - c2m(&c, m); -} - -void uiDrawMatrixSkew(uiDrawMatrix *m, double x, double y, double xamount, double yamount) -{ - fallbackSkew(m, x, y, xamount, yamount); -} - -void uiDrawMatrixMultiply(uiDrawMatrix *dest, uiDrawMatrix *src) -{ - CGAffineTransform c; - CGAffineTransform d; - - m2c(dest, &c); - m2c(src, &d); - c = CGAffineTransformConcat(c, d); - c2m(&c, dest); -} - -// there is no test for invertibility; CGAffineTransformInvert() is merely documented as returning the matrix unchanged if it isn't invertible -// therefore, special care must be taken to catch matrices who are their own inverses -// TODO figure out which matrices these are and do so -int uiDrawMatrixInvertible(uiDrawMatrix *m) -{ - CGAffineTransform c, d; - - m2c(m, &c); - d = CGAffineTransformInvert(c); - return CGAffineTransformEqualToTransform(c, d) == false; -} - -int uiDrawMatrixInvert(uiDrawMatrix *m) -{ - CGAffineTransform c, d; - - m2c(m, &c); - d = CGAffineTransformInvert(c); - if (CGAffineTransformEqualToTransform(c, d)) - return 0; - c2m(&d, m); - return 1; -} - -void uiDrawMatrixTransformPoint(uiDrawMatrix *m, double *x, double *y) -{ - CGAffineTransform c; - CGPoint p; - - m2c(m, &c); - p = CGPointApplyAffineTransform(CGPointMake(*x, *y), c); - *x = p.x; - *y = p.y; -} - -void uiDrawMatrixTransformSize(uiDrawMatrix *m, double *x, double *y) -{ - CGAffineTransform c; - CGSize s; - - m2c(m, &c); - s = CGSizeApplyAffineTransform(CGSizeMake(*x, *y), c); - *x = s.width; - *y = s.height; -} - -void uiDrawTransform(uiDrawContext *c, uiDrawMatrix *m) -{ - CGAffineTransform cm; - - m2c(m, &cm); - CGContextConcatCTM(c->c, cm); -} - -void uiDrawClip(uiDrawContext *c, uiDrawPath *path) -{ - if (!path->ended) - userbug("You cannot call uiDrawCilp() on a uiDrawPath that has not been ended. (path: %p)", path); - CGContextAddPath(c->c, (CGPathRef) (path->path)); - switch (path->fillMode) { - case uiDrawFillModeWinding: - CGContextClip(c->c); - break; - case uiDrawFillModeAlternate: - CGContextEOClip(c->c); - break; - } -} - -// TODO figure out what besides transforms these save/restore on all platforms -void uiDrawSave(uiDrawContext *c) -{ - CGContextSaveGState(c->c); -} - -void uiDrawRestore(uiDrawContext *c) -{ - CGContextRestoreGState(c->c); -} - -void uiDrawText(uiDrawContext *c, double x, double y, uiDrawTextLayout *layout) -{ - doDrawText(c->c, c->height, x, y, layout); -} diff --git a/src/libui_sdl/libui/darwin/drawtext.m b/src/libui_sdl/libui/darwin/drawtext.m deleted file mode 100644 index c376536..0000000 --- a/src/libui_sdl/libui/darwin/drawtext.m +++ /dev/null @@ -1,655 +0,0 @@ -// 6 september 2015 -#import "uipriv_darwin.h" - -// TODO -#define complain(...) implbug(__VA_ARGS__) - -// TODO double-check that we are properly handling allocation failures (or just toll free bridge from cocoa) -struct uiDrawFontFamilies { - CFArrayRef fonts; -}; - -uiDrawFontFamilies *uiDrawListFontFamilies(void) -{ - uiDrawFontFamilies *ff; - - ff = uiNew(uiDrawFontFamilies); - ff->fonts = CTFontManagerCopyAvailableFontFamilyNames(); - if (ff->fonts == NULL) - implbug("error getting available font names (no reason specified) (TODO)"); - return ff; -} - -int uiDrawFontFamiliesNumFamilies(uiDrawFontFamilies *ff) -{ - return CFArrayGetCount(ff->fonts); -} - -char *uiDrawFontFamiliesFamily(uiDrawFontFamilies *ff, int n) -{ - CFStringRef familystr; - char *family; - - familystr = (CFStringRef) CFArrayGetValueAtIndex(ff->fonts, n); - // toll-free bridge - family = uiDarwinNSStringToText((NSString *) familystr); - // Get Rule means we do not free familystr - return family; -} - -void uiDrawFreeFontFamilies(uiDrawFontFamilies *ff) -{ - CFRelease(ff->fonts); - uiFree(ff); -} - -struct uiDrawTextFont { - CTFontRef f; -}; - -uiDrawTextFont *mkTextFont(CTFontRef f, BOOL retain) -{ - uiDrawTextFont *font; - - font = uiNew(uiDrawTextFont); - font->f = f; - if (retain) - CFRetain(font->f); - return font; -} - -uiDrawTextFont *mkTextFontFromNSFont(NSFont *f) -{ - // toll-free bridging; we do retain, though - return mkTextFont((CTFontRef) f, YES); -} - -static CFMutableDictionaryRef newAttrList(void) -{ - CFMutableDictionaryRef attr; - - attr = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); - if (attr == NULL) - complain("error creating attribute dictionary in newAttrList()()"); - return attr; -} - -static void addFontFamilyAttr(CFMutableDictionaryRef attr, const char *family) -{ - CFStringRef cfstr; - - cfstr = CFStringCreateWithCString(NULL, family, kCFStringEncodingUTF8); - if (cfstr == NULL) - complain("error creating font family name CFStringRef in addFontFamilyAttr()"); - CFDictionaryAddValue(attr, kCTFontFamilyNameAttribute, cfstr); - CFRelease(cfstr); // dictionary holds its own reference -} - -static void addFontSizeAttr(CFMutableDictionaryRef attr, double size) -{ - CFNumberRef n; - - n = CFNumberCreate(NULL, kCFNumberDoubleType, &size); - CFDictionaryAddValue(attr, kCTFontSizeAttribute, n); - CFRelease(n); -} - -#if 0 -TODO -// See http://stackoverflow.com/questions/4810409/does-coretext-support-small-caps/4811371#4811371 and https://git.gnome.org/browse/pango/tree/pango/pangocoretext-fontmap.c for what these do -// And fortunately, unlike the traits (see below), unmatched features are simply ignored without affecting the other features :D -static void addFontSmallCapsAttr(CFMutableDictionaryRef attr) -{ - CFMutableArrayRef outerArray; - CFMutableDictionaryRef innerDict; - CFNumberRef numType, numSelector; - int num; - - outerArray = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); - if (outerArray == NULL) - complain("error creating outer CFArray for adding small caps attributes in addFontSmallCapsAttr()"); - - // Apple's headers say these are deprecated, but a few fonts still rely on them - num = kLetterCaseType; - numType = CFNumberCreate(NULL, kCFNumberIntType, &num); - num = kSmallCapsSelector; - numSelector = CFNumberCreate(NULL, kCFNumberIntType, &num); - innerDict = newAttrList(); - CFDictionaryAddValue(innerDict, kCTFontFeatureTypeIdentifierKey, numType); - CFRelease(numType); - CFDictionaryAddValue(innerDict, kCTFontFeatureSelectorIdentifierKey, numSelector); - CFRelease(numSelector); - CFArrayAppendValue(outerArray, innerDict); - CFRelease(innerDict); // and likewise for CFArray - - // these are the non-deprecated versions of the above; some fonts have these instead - num = kLowerCaseType; - numType = CFNumberCreate(NULL, kCFNumberIntType, &num); - num = kLowerCaseSmallCapsSelector; - numSelector = CFNumberCreate(NULL, kCFNumberIntType, &num); - innerDict = newAttrList(); - CFDictionaryAddValue(innerDict, kCTFontFeatureTypeIdentifierKey, numType); - CFRelease(numType); - CFDictionaryAddValue(innerDict, kCTFontFeatureSelectorIdentifierKey, numSelector); - CFRelease(numSelector); - CFArrayAppendValue(outerArray, innerDict); - CFRelease(innerDict); // and likewise for CFArray - - CFDictionaryAddValue(attr, kCTFontFeatureSettingsAttribute, outerArray); - CFRelease(outerArray); -} -#endif - -// Named constants for these were NOT added until 10.11, and even then they were added as external symbols instead of macros, so we can't use them directly :( -// kode54 got these for me before I had access to El Capitan; thanks to him. -#define ourNSFontWeightUltraLight -0.800000 -#define ourNSFontWeightThin -0.600000 -#define ourNSFontWeightLight -0.400000 -#define ourNSFontWeightRegular 0.000000 -#define ourNSFontWeightMedium 0.230000 -#define ourNSFontWeightSemibold 0.300000 -#define ourNSFontWeightBold 0.400000 -#define ourNSFontWeightHeavy 0.560000 -#define ourNSFontWeightBlack 0.620000 -static const CGFloat ctWeights[] = { - // yeah these two have their names swapped; blame Pango - [uiDrawTextWeightThin] = ourNSFontWeightUltraLight, - [uiDrawTextWeightUltraLight] = ourNSFontWeightThin, - [uiDrawTextWeightLight] = ourNSFontWeightLight, - // for this one let's go between Light and Regular - // we're doing nearest so if there happens to be an exact value hopefully it's close enough - [uiDrawTextWeightBook] = ourNSFontWeightLight + ((ourNSFontWeightRegular - ourNSFontWeightLight) / 2), - [uiDrawTextWeightNormal] = ourNSFontWeightRegular, - [uiDrawTextWeightMedium] = ourNSFontWeightMedium, - [uiDrawTextWeightSemiBold] = ourNSFontWeightSemibold, - [uiDrawTextWeightBold] = ourNSFontWeightBold, - // for this one let's go between Bold and Heavy - [uiDrawTextWeightUltraBold] = ourNSFontWeightBold + ((ourNSFontWeightHeavy - ourNSFontWeightBold) / 2), - [uiDrawTextWeightHeavy] = ourNSFontWeightHeavy, - [uiDrawTextWeightUltraHeavy] = ourNSFontWeightBlack, -}; - -// Unfortunately there are still no named constants for these. -// Let's just use normalized widths. -// As far as I can tell (OS X only ships with condensed fonts, not expanded fonts; TODO), regardless of condensed or expanded, negative means condensed and positive means expanded. -// TODO verify this is correct -static const CGFloat ctStretches[] = { - [uiDrawTextStretchUltraCondensed] = -1.0, - [uiDrawTextStretchExtraCondensed] = -0.75, - [uiDrawTextStretchCondensed] = -0.5, - [uiDrawTextStretchSemiCondensed] = -0.25, - [uiDrawTextStretchNormal] = 0.0, - [uiDrawTextStretchSemiExpanded] = 0.25, - [uiDrawTextStretchExpanded] = 0.5, - [uiDrawTextStretchExtraExpanded] = 0.75, - [uiDrawTextStretchUltraExpanded] = 1.0, -}; - -struct closeness { - CFIndex index; - CGFloat weight; - CGFloat italic; - CGFloat stretch; - CGFloat distance; -}; - -// Stupidity: CTFont requires an **exact match for the entire traits dictionary**, otherwise it will **drop ALL the traits**. -// We have to implement the closest match ourselves. -// Also we have to do this before adding the small caps flags, because the matching descriptors won't have those. -CTFontDescriptorRef matchTraits(CTFontDescriptorRef against, uiDrawTextWeight weight, uiDrawTextItalic italic, uiDrawTextStretch stretch) -{ - CGFloat targetWeight; - CGFloat italicCloseness, obliqueCloseness, normalCloseness; - CGFloat targetStretch; - CFArrayRef matching; - CFIndex i, n; - struct closeness *closeness; - CTFontDescriptorRef current; - CTFontDescriptorRef out; - - targetWeight = ctWeights[weight]; - switch (italic) { - case uiDrawTextItalicNormal: - italicCloseness = 1; - obliqueCloseness = 1; - normalCloseness = 0; - break; - case uiDrawTextItalicOblique: - italicCloseness = 0.5; - obliqueCloseness = 0; - normalCloseness = 1; - break; - case uiDrawTextItalicItalic: - italicCloseness = 0; - obliqueCloseness = 0.5; - normalCloseness = 1; - break; - } - targetStretch = ctStretches[stretch]; - - matching = CTFontDescriptorCreateMatchingFontDescriptors(against, NULL); - if (matching == NULL) - // no matches; give the original back and hope for the best - return against; - n = CFArrayGetCount(matching); - if (n == 0) { - // likewise - CFRelease(matching); - return against; - } - - closeness = (struct closeness *) uiAlloc(n * sizeof (struct closeness), "struct closeness[]"); - for (i = 0; i < n; i++) { - CFDictionaryRef traits; - CFNumberRef cfnum; - CTFontSymbolicTraits symbolic; - - closeness[i].index = i; - - current = CFArrayGetValueAtIndex(matching, i); - traits = CTFontDescriptorCopyAttribute(current, kCTFontTraitsAttribute); - if (traits == NULL) { - // couldn't get traits; be safe by ranking it lowest - // LONGTERM figure out what the longest possible distances are - closeness[i].weight = 3; - closeness[i].italic = 2; - closeness[i].stretch = 3; - continue; - } - - symbolic = 0; // assume no symbolic traits if none are listed - cfnum = CFDictionaryGetValue(traits, kCTFontSymbolicTrait); - if (cfnum != NULL) { - SInt32 s; - - if (CFNumberGetValue(cfnum, kCFNumberSInt32Type, &s) == false) - complain("error getting symbolic traits in matchTraits()"); - symbolic = (CTFontSymbolicTraits) s; - // Get rule; do not release cfnum - } - - // now try weight - cfnum = CFDictionaryGetValue(traits, kCTFontWeightTrait); - if (cfnum != NULL) { - CGFloat val; - - // LONGTERM instead of complaining for this and width and possibly also symbolic traits above, should we just fall through to the default? - if (CFNumberGetValue(cfnum, kCFNumberCGFloatType, &val) == false) - complain("error getting weight value in matchTraits()"); - closeness[i].weight = val - targetWeight; - } else - // okay there's no weight key; let's try the literal meaning of the symbolic constant - // LONGTERM is the weight key guaranteed? - if ((symbolic & kCTFontBoldTrait) != 0) - closeness[i].weight = ourNSFontWeightBold - targetWeight; - else - closeness[i].weight = ourNSFontWeightRegular - targetWeight; - - // italics is a bit harder because Core Text doesn't expose a concept of obliqueness - // Pango just does a g_strrstr() (backwards case-sensitive search) for "Oblique" in the font's style name (see https://git.gnome.org/browse/pango/tree/pango/pangocoretext-fontmap.c); let's do that too I guess - if ((symbolic & kCTFontItalicTrait) != 0) - closeness[i].italic = italicCloseness; - else { - CFStringRef styleName; - BOOL isOblique; - - isOblique = NO; // default value - styleName = CTFontDescriptorCopyAttribute(current, kCTFontStyleNameAttribute); - if (styleName != NULL) { - CFRange range; - - // note the use of the toll-free bridge for the string literal, since CFSTR() *can* return NULL - range = CFStringFind(styleName, (CFStringRef) @"Oblique", kCFCompareBackwards); - if (range.location != kCFNotFound) - isOblique = YES; - CFRelease(styleName); - } - if (isOblique) - closeness[i].italic = obliqueCloseness; - else - closeness[i].italic = normalCloseness; - } - - // now try width - // TODO this does not seem to be enough for Skia's extended variants; the width trait is 0 but the Expanded flag is on - // TODO verify the rest of this matrix (what matrix?) - cfnum = CFDictionaryGetValue(traits, kCTFontWidthTrait); - if (cfnum != NULL) { - CGFloat val; - - if (CFNumberGetValue(cfnum, kCFNumberCGFloatType, &val) == false) - complain("error getting width value in matchTraits()"); - closeness[i].stretch = val - targetStretch; - } else - // okay there's no width key; let's try the literal meaning of the symbolic constant - // LONGTERM is the width key guaranteed? - if ((symbolic & kCTFontExpandedTrait) != 0) - closeness[i].stretch = 1.0 - targetStretch; - else if ((symbolic & kCTFontCondensedTrait) != 0) - closeness[i].stretch = -1.0 - targetStretch; - else - closeness[i].stretch = 0.0 - targetStretch; - - CFRelease(traits); - } - - // now figure out the 3-space difference between the three and sort by that - for (i = 0; i < n; i++) { - CGFloat weight, italic, stretch; - - weight = closeness[i].weight; - weight *= weight; - italic = closeness[i].italic; - italic *= italic; - stretch = closeness[i].stretch; - stretch *= stretch; - closeness[i].distance = sqrt(weight + italic + stretch); - } - qsort_b(closeness, n, sizeof (struct closeness), ^(const void *aa, const void *bb) { - const struct closeness *a = (const struct closeness *) aa; - const struct closeness *b = (const struct closeness *) bb; - - // via http://www.gnu.org/software/libc/manual/html_node/Comparison-Functions.html#Comparison-Functions - // LONGTERM is this really the best way? isn't it the same as if (*a < *b) return -1; if (*a > *b) return 1; return 0; ? - return (a->distance > b->distance) - (a->distance < b->distance); - }); - // and the first element of the sorted array is what we want - out = CFArrayGetValueAtIndex(matching, closeness[0].index); - CFRetain(out); // get rule - - // release everything - uiFree(closeness); - CFRelease(matching); - // and release the original descriptor since we no longer need it - CFRelease(against); - - return out; -} - -// Now remember what I said earlier about having to add the small caps traits after calling the above? This gets a dictionary back so we can do so. -CFMutableDictionaryRef extractAttributes(CTFontDescriptorRef desc) -{ - CFDictionaryRef dict; - CFMutableDictionaryRef mdict; - - dict = CTFontDescriptorCopyAttributes(desc); - // this might not be mutable, so make a mutable copy - mdict = CFDictionaryCreateMutableCopy(NULL, 0, dict); - CFRelease(dict); - return mdict; -} - -uiDrawTextFont *uiDrawLoadClosestFont(const uiDrawTextFontDescriptor *desc) -{ - CTFontRef f; - CFMutableDictionaryRef attr; - CTFontDescriptorRef cfdesc; - - attr = newAttrList(); - addFontFamilyAttr(attr, desc->Family); - addFontSizeAttr(attr, desc->Size); - - // now we have to do the traits matching, so create a descriptor, match the traits, and then get the attributes back - cfdesc = CTFontDescriptorCreateWithAttributes(attr); - // TODO release attr? - cfdesc = matchTraits(cfdesc, desc->Weight, desc->Italic, desc->Stretch); - - // specify the initial size again just to be safe - f = CTFontCreateWithFontDescriptor(cfdesc, desc->Size, NULL); - // TODO release cfdesc? - - return mkTextFont(f, NO); // we hold the initial reference; no need to retain again -} - -void uiDrawFreeTextFont(uiDrawTextFont *font) -{ - CFRelease(font->f); - uiFree(font); -} - -uintptr_t uiDrawTextFontHandle(uiDrawTextFont *font) -{ - return (uintptr_t) (font->f); -} - -void uiDrawTextFontDescribe(uiDrawTextFont *font, uiDrawTextFontDescriptor *desc) -{ - // TODO -} - -// text sizes and user space points are identical: -// - https://developer.apple.com/library/mac/documentation/TextFonts/Conceptual/CocoaTextArchitecture/TypoFeatures/TextSystemFeatures.html#//apple_ref/doc/uid/TP40009459-CH6-51627-BBCCHIFF text points are 72 per inch -// - https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaDrawingGuide/Transforms/Transforms.html#//apple_ref/doc/uid/TP40003290-CH204-SW5 user space points are 72 per inch -void uiDrawTextFontGetMetrics(uiDrawTextFont *font, uiDrawTextFontMetrics *metrics) -{ - metrics->Ascent = CTFontGetAscent(font->f); - metrics->Descent = CTFontGetDescent(font->f); - metrics->Leading = CTFontGetLeading(font->f); - metrics->UnderlinePos = CTFontGetUnderlinePosition(font->f); - metrics->UnderlineThickness = CTFontGetUnderlineThickness(font->f); -} - -struct uiDrawTextLayout { - CFMutableAttributedStringRef mas; - CFRange *charsToRanges; - double width; -}; - -uiDrawTextLayout *uiDrawNewTextLayout(const char *str, uiDrawTextFont *defaultFont, double width) -{ - uiDrawTextLayout *layout; - CFAttributedStringRef immutable; - CFMutableDictionaryRef attr; - CFStringRef backing; - CFIndex i, j, n; - - layout = uiNew(uiDrawTextLayout); - - // TODO docs say we need to use a different set of key callbacks - // TODO see if the font attribute key callbacks need to be the same - attr = newAttrList(); - // this will retain defaultFont->f; no need to worry - CFDictionaryAddValue(attr, kCTFontAttributeName, defaultFont->f); - - immutable = CFAttributedStringCreate(NULL, (CFStringRef) [NSString stringWithUTF8String:str], attr); - if (immutable == NULL) - complain("error creating immutable attributed string in uiDrawNewTextLayout()"); - CFRelease(attr); - - layout->mas = CFAttributedStringCreateMutableCopy(NULL, 0, immutable); - if (layout->mas == NULL) - complain("error creating attributed string in uiDrawNewTextLayout()"); - CFRelease(immutable); - - uiDrawTextLayoutSetWidth(layout, width); - - // unfortunately the CFRanges for attributes expect UTF-16 codepoints - // we want graphemes - // fortunately CFStringGetRangeOfComposedCharactersAtIndex() is here for us - // https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Strings/Articles/stringsClusters.html says that this does work on all multi-codepoint graphemes (despite the name), and that this is the preferred function for this particular job anyway - backing = CFAttributedStringGetString(layout->mas); - n = CFStringGetLength(backing); - // allocate one extra, just to be safe - layout->charsToRanges = (CFRange *) uiAlloc((n + 1) * sizeof (CFRange), "CFRange[]"); - i = 0; - j = 0; - while (i < n) { - CFRange range; - - range = CFStringGetRangeOfComposedCharactersAtIndex(backing, i); - i = range.location + range.length; - layout->charsToRanges[j] = range; - j++; - } - // and set the last one - layout->charsToRanges[j].location = i; - layout->charsToRanges[j].length = 0; - - return layout; -} - -void uiDrawFreeTextLayout(uiDrawTextLayout *layout) -{ - uiFree(layout->charsToRanges); - CFRelease(layout->mas); - uiFree(layout); -} - -void uiDrawTextLayoutSetWidth(uiDrawTextLayout *layout, double width) -{ - layout->width = width; -} - -struct framesetter { - CTFramesetterRef fs; - CFMutableDictionaryRef frameAttrib; - CGSize extents; -}; - -// TODO CTFrameProgression for RTL/LTR -// TODO kCTParagraphStyleSpecifierMaximumLineSpacing, kCTParagraphStyleSpecifierMinimumLineSpacing, kCTParagraphStyleSpecifierLineSpacingAdjustment for line spacing -static void mkFramesetter(uiDrawTextLayout *layout, struct framesetter *fs) -{ - CFRange fitRange; - CGFloat width; - - fs->fs = CTFramesetterCreateWithAttributedString(layout->mas); - if (fs->fs == NULL) - complain("error creating CTFramesetter object in mkFramesetter()"); - - // TODO kCTFramePathWidthAttributeName? - fs->frameAttrib = NULL; - - width = layout->width; - if (layout->width < 0) - width = CGFLOAT_MAX; - // TODO these seem to be floor()'d or truncated? - fs->extents = CTFramesetterSuggestFrameSizeWithConstraints(fs->fs, - CFRangeMake(0, 0), - fs->frameAttrib, - CGSizeMake(width, CGFLOAT_MAX), - &fitRange); // not documented as accepting NULL -} - -static void freeFramesetter(struct framesetter *fs) -{ - if (fs->frameAttrib != NULL) - CFRelease(fs->frameAttrib); - CFRelease(fs->fs); -} - -// LONGTERM allow line separation and leading to be factored into a wrapping text layout - -// TODO reconcile differences in character wrapping on platforms -void uiDrawTextLayoutExtents(uiDrawTextLayout *layout, double *width, double *height) -{ - struct framesetter fs; - - mkFramesetter(layout, &fs); - *width = fs.extents.width; - *height = fs.extents.height; - freeFramesetter(&fs); -} - -// Core Text doesn't draw onto a flipped view correctly; we have to do this -// see the iOS bits of the first example at https://developer.apple.com/library/mac/documentation/StringsTextFonts/Conceptual/CoreText_Programming/LayoutOperations/LayoutOperations.html#//apple_ref/doc/uid/TP40005533-CH12-SW1 (iOS is naturally flipped) -// TODO how is this affected by the CTM? -static void prepareContextForText(CGContextRef c, CGFloat cheight, double *y) -{ - CGContextSaveGState(c); - CGContextTranslateCTM(c, 0, cheight); - CGContextScaleCTM(c, 1.0, -1.0); - CGContextSetTextMatrix(c, CGAffineTransformIdentity); - - // wait, that's not enough; we need to offset y values to account for our new flipping - *y = cheight - *y; -} - -// TODO placement is incorrect for Helvetica -void doDrawText(CGContextRef c, CGFloat cheight, double x, double y, uiDrawTextLayout *layout) -{ - struct framesetter fs; - CGRect rect; - CGPathRef path; - CTFrameRef frame; - - prepareContextForText(c, cheight, &y); - mkFramesetter(layout, &fs); - - // oh, and since we're flipped, y is the bottom-left coordinate of the rectangle, not the top-left - // since we are flipped, we subtract - y -= fs.extents.height; - - rect.origin = CGPointMake(x, y); - rect.size = fs.extents; - path = CGPathCreateWithRect(rect, NULL); - - frame = CTFramesetterCreateFrame(fs.fs, - CFRangeMake(0, 0), - path, - fs.frameAttrib); - if (frame == NULL) - complain("error creating CTFrame object in doDrawText()"); - CTFrameDraw(frame, c); - CFRelease(frame); - - CFRelease(path); - - freeFramesetter(&fs); - CGContextRestoreGState(c); -} - -// LONGTERM provide an equivalent to CTLineGetTypographicBounds() on uiDrawTextLayout? - -// LONGTERM keep this for later features and documentation purposes -#if 0 - w = CTLineGetTypographicBounds(line, &ascent, &descent, NULL); - // though CTLineGetTypographicBounds() returns 0 on error, it also returns 0 on an empty string, so we can't reasonably check for error - CFRelease(line); - - // LONGTERM provide a way to get the image bounds as a separate function later - bounds = CTLineGetImageBounds(line, c); - // though CTLineGetImageBounds() returns CGRectNull on error, it also returns CGRectNull on an empty string, so we can't reasonably check for error - - // CGContextSetTextPosition() positions at the baseline in the case of CTLineDraw(); we need the top-left corner instead - CTLineGetTypographicBounds(line, &yoff, NULL, NULL); - // remember that we're flipped, so we subtract - y -= yoff; - CGContextSetTextPosition(c, x, y); -#endif - -static CFRange charsToRange(uiDrawTextLayout *layout, int startChar, int endChar) -{ - CFRange start, end; - CFRange out; - - start = layout->charsToRanges[startChar]; - end = layout->charsToRanges[endChar]; - out.location = start.location; - out.length = end.location - start.location; - return out; -} - -#define rangeToCFRange() charsToRange(layout, startChar, endChar) - -void uiDrawTextLayoutSetColor(uiDrawTextLayout *layout, int startChar, int endChar, double r, double g, double b, double a) -{ - CGColorSpaceRef colorspace; - CGFloat components[4]; - CGColorRef color; - - // for consistency with windows, use sRGB - colorspace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB); - components[0] = r; - components[1] = g; - components[2] = b; - components[3] = a; - color = CGColorCreate(colorspace, components); - CGColorSpaceRelease(colorspace); - - CFAttributedStringSetAttribute(layout->mas, - rangeToCFRange(), - kCTForegroundColorAttributeName, - color); - CGColorRelease(color); // TODO safe? -} diff --git a/src/libui_sdl/libui/darwin/editablecombo.m b/src/libui_sdl/libui/darwin/editablecombo.m deleted file mode 100644 index 434add7..0000000 --- a/src/libui_sdl/libui/darwin/editablecombo.m +++ /dev/null @@ -1,185 +0,0 @@ -// 14 august 2015 -#import "uipriv_darwin.h" - -// So why did I split uiCombobox into uiCombobox and uiEditableCombobox? Here's (90% of the; the other 10% is GTK+ events) answer: -// When you type a value into a NSComboBox that just happens to be in the list, it will autoselect that item! -// I can't seem to find a workaround. -// Fortunately, there's other weird behaviors that made this split worth it. -// And besides, selected items make little sense with editable comboboxes... you either separate or combine them with the text entry :V - -// NSComboBoxes have no intrinsic width; we'll use the default Interface Builder width for them. -#define comboboxWidth 96 - -@interface libui_intrinsicWidthNSComboBox : NSComboBox -@end - -@implementation libui_intrinsicWidthNSComboBox - -- (NSSize)intrinsicContentSize -{ - NSSize s; - - s = [super intrinsicContentSize]; - s.width = comboboxWidth; - return s; -} - -@end - -struct uiEditableCombobox { - uiDarwinControl c; - NSComboBox *cb; - void (*onChanged)(uiEditableCombobox *, void *); - void *onChangedData; -}; - -@interface editableComboboxDelegateClass : NSObject { - struct mapTable *comboboxes; -} -- (void)controlTextDidChange:(NSNotification *)note; -- (void)comboBoxSelectionDidChange:(NSNotification *)note; -- (void)registerCombobox:(uiEditableCombobox *)c; -- (void)unregisterCombobox:(uiEditableCombobox *)c; -@end - -@implementation editableComboboxDelegateClass - -- (id)init -{ - self = [super init]; - if (self) - self->comboboxes = newMap(); - return self; -} - -- (void)dealloc -{ - mapDestroy(self->comboboxes); - [super dealloc]; -} - -- (void)controlTextDidChange:(NSNotification *)note -{ - uiEditableCombobox *c; - - c = uiEditableCombobox(mapGet(self->comboboxes, [note object])); - (*(c->onChanged))(c, c->onChangedData); -} - -// the above doesn't handle when an item is selected; this will -- (void)comboBoxSelectionDidChange:(NSNotification *)note -{ - // except this is sent BEFORE the entry is changed, and that doesn't send the above, so - // this is via http://stackoverflow.com/a/21059819/3408572 - it avoids the need to manage selected items - // this still isn't perfect — I get residual changes to the same value while navigating the list — but it's good enough - [self performSelector:@selector(controlTextDidChange:) - withObject:note - afterDelay:0]; -} - -- (void)registerCombobox:(uiEditableCombobox *)c -{ - mapSet(self->comboboxes, c->cb, c); - [c->cb setDelegate:self]; -} - -- (void)unregisterCombobox:(uiEditableCombobox *)c -{ - [c->cb setDelegate:nil]; - mapDelete(self->comboboxes, c->cb); -} - -@end - -static editableComboboxDelegateClass *comboboxDelegate = nil; - -uiDarwinControlAllDefaultsExceptDestroy(uiEditableCombobox, cb) - -static void uiEditableComboboxDestroy(uiControl *cc) -{ - uiEditableCombobox *c = uiEditableCombobox(cc); - - [comboboxDelegate unregisterCombobox:c]; - [c->cb release]; - uiFreeControl(uiControl(c)); -} - -void uiEditableComboboxAppend(uiEditableCombobox *c, const char *text) -{ - [c->cb addItemWithObjectValue:toNSString(text)]; -} - -char *uiEditableComboboxText(uiEditableCombobox *c) -{ - return uiDarwinNSStringToText([c->cb stringValue]); -} - -void uiEditableComboboxSetText(uiEditableCombobox *c, const char *text) -{ - NSString *t; - - t = toNSString(text); - [c->cb setStringValue:t]; - // yes, let's imitate the behavior that caused uiEditableCombobox to be separate in the first place! - // just to avoid confusion when users see an option in the list in the text field but not selected in the list - [c->cb selectItemWithObjectValue:t]; -} - -#if 0 -// LONGTERM -void uiEditableComboboxSetSelected(uiEditableCombobox *c, int n) -{ - if (c->editable) { - // see https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ComboBox/Tasks/SettingComboBoxValue.html#//apple_ref/doc/uid/20000256 - id delegate; - - // this triggers the delegate; turn it off for now - delegate = [c->cb delegate]; - [c->cb setDelegate:nil]; - - // this seems to work fine for -1 too - [c->cb selectItemAtIndex:n]; - if (n == -1) - [c->cb setObjectValue:@""]; - else - [c->cb setObjectValue:[c->cb objectValueOfSelectedItem]]; - - [c->cb setDelegate:delegate]; - return; - } - [c->pb selectItemAtIndex:n]; -} -#endif - -void uiEditableComboboxOnChanged(uiEditableCombobox *c, void (*f)(uiEditableCombobox *c, void *data), void *data) -{ - c->onChanged = f; - c->onChangedData = data; -} - -static void defaultOnChanged(uiEditableCombobox *c, void *data) -{ - // do nothing -} - -uiEditableCombobox *uiNewEditableCombobox(void) -{ - uiEditableCombobox *c; - - uiDarwinNewControl(uiEditableCombobox, c); - - c->cb = [[libui_intrinsicWidthNSComboBox alloc] initWithFrame:NSZeroRect]; - [c->cb setUsesDataSource:NO]; - [c->cb setButtonBordered:YES]; - [c->cb setCompletes:NO]; - uiDarwinSetControlFont(c->cb, NSRegularControlSize); - - if (comboboxDelegate == nil) { - comboboxDelegate = [[editableComboboxDelegateClass new] autorelease]; - [delegates addObject:comboboxDelegate]; - } - [comboboxDelegate registerCombobox:c]; - uiEditableComboboxOnChanged(c, defaultOnChanged, NULL); - - return c; -} diff --git a/src/libui_sdl/libui/darwin/entry.m b/src/libui_sdl/libui/darwin/entry.m deleted file mode 100644 index 219d080..0000000 --- a/src/libui_sdl/libui/darwin/entry.m +++ /dev/null @@ -1,251 +0,0 @@ -// 14 august 2015 -#import "uipriv_darwin.h" - -// Text fields for entering text have no intrinsic width; we'll use the default Interface Builder width for them. -#define textfieldWidth 96 - -@interface libui_intrinsicWidthNSTextField : NSTextField -@end - -@implementation libui_intrinsicWidthNSTextField - -- (NSSize)intrinsicContentSize -{ - NSSize s; - - s = [super intrinsicContentSize]; - s.width = textfieldWidth; - return s; -} - -@end - -// TODO does this have one on its own? -@interface libui_intrinsicWidthNSSecureTextField : NSSecureTextField -@end - -@implementation libui_intrinsicWidthNSSecureTextField - -- (NSSize)intrinsicContentSize -{ - NSSize s; - - s = [super intrinsicContentSize]; - s.width = textfieldWidth; - return s; -} - -@end - -// TODO does this have one on its own? -@interface libui_intrinsicWidthNSSearchField : NSSearchField -@end - -@implementation libui_intrinsicWidthNSSearchField - -- (NSSize)intrinsicContentSize -{ - NSSize s; - - s = [super intrinsicContentSize]; - s.width = textfieldWidth; - return s; -} - -@end - -struct uiEntry { - uiDarwinControl c; - NSTextField *textfield; - void (*onChanged)(uiEntry *, void *); - void *onChangedData; -}; - -static BOOL isSearchField(NSTextField *tf) -{ - return [tf isKindOfClass:[NSSearchField class]]; -} - -@interface entryDelegateClass : NSObject { - struct mapTable *entries; -} -- (void)controlTextDidChange:(NSNotification *)note; -- (IBAction)onSearch:(id)sender; -- (void)registerEntry:(uiEntry *)e; -- (void)unregisterEntry:(uiEntry *)e; -@end - -@implementation entryDelegateClass - -- (id)init -{ - self = [super init]; - if (self) - self->entries = newMap(); - return self; -} - -- (void)dealloc -{ - mapDestroy(self->entries); - [super dealloc]; -} - -- (void)controlTextDidChange:(NSNotification *)note -{ - [self onSearch:[note object]]; -} - -- (IBAction)onSearch:(id)sender -{ - uiEntry *e; - - e = (uiEntry *) mapGet(self->entries, sender); - (*(e->onChanged))(e, e->onChangedData); -} - -- (void)registerEntry:(uiEntry *)e -{ - mapSet(self->entries, e->textfield, e); - if (isSearchField(e->textfield)) { - [e->textfield setTarget:self]; - [e->textfield setAction:@selector(onSearch:)]; - } else - [e->textfield setDelegate:self]; -} - -- (void)unregisterEntry:(uiEntry *)e -{ - if (isSearchField(e->textfield)) - [e->textfield setTarget:nil]; - else - [e->textfield setDelegate:nil]; - mapDelete(self->entries, e->textfield); -} - -@end - -static entryDelegateClass *entryDelegate = nil; - -uiDarwinControlAllDefaultsExceptDestroy(uiEntry, textfield) - -static void uiEntryDestroy(uiControl *c) -{ - uiEntry *e = uiEntry(c); - - [entryDelegate unregisterEntry:e]; - [e->textfield release]; - uiFreeControl(uiControl(e)); -} - -char *uiEntryText(uiEntry *e) -{ - return uiDarwinNSStringToText([e->textfield stringValue]); -} - -void uiEntrySetText(uiEntry *e, const char *text) -{ - [e->textfield setStringValue:toNSString(text)]; - // don't queue the control for resize; entry sizes are independent of their contents -} - -void uiEntryOnChanged(uiEntry *e, void (*f)(uiEntry *, void *), void *data) -{ - e->onChanged = f; - e->onChangedData = data; -} - -int uiEntryReadOnly(uiEntry *e) -{ - return [e->textfield isEditable] == NO; -} - -void uiEntrySetReadOnly(uiEntry *e, int readonly) -{ - BOOL editable; - - editable = YES; - if (readonly) - editable = NO; - [e->textfield setEditable:editable]; -} - -static void defaultOnChanged(uiEntry *e, void *data) -{ - // do nothing -} - -// these are based on interface builder defaults; my comments in the old code weren't very good so I don't really know what talked about what, sorry :/ -void finishNewTextField(NSTextField *t, BOOL isEntry) -{ - uiDarwinSetControlFont(t, NSRegularControlSize); - - // THE ORDER OF THESE CALLS IS IMPORTANT; CHANGE IT AND THE BORDERS WILL DISAPPEAR - [t setBordered:NO]; - [t setBezelStyle:NSTextFieldSquareBezel]; - [t setBezeled:isEntry]; - - // we don't need to worry about substitutions/autocorrect here; see window_darwin.m for details - - [[t cell] setLineBreakMode:NSLineBreakByClipping]; - [[t cell] setScrollable:YES]; -} - -static NSTextField *realNewEditableTextField(Class class) -{ - NSTextField *tf; - - tf = [[class alloc] initWithFrame:NSZeroRect]; - [tf setSelectable:YES]; // otherwise the setting is masked by the editable default of YES - finishNewTextField(tf, YES); - return tf; -} - -NSTextField *newEditableTextField(void) -{ - return realNewEditableTextField([libui_intrinsicWidthNSTextField class]); -} - -static uiEntry *finishNewEntry(Class class) -{ - uiEntry *e; - - uiDarwinNewControl(uiEntry, e); - - e->textfield = realNewEditableTextField(class); - - if (entryDelegate == nil) { - entryDelegate = [[entryDelegateClass new] autorelease]; - [delegates addObject:entryDelegate]; - } - [entryDelegate registerEntry:e]; - uiEntryOnChanged(e, defaultOnChanged, NULL); - - return e; -} - -uiEntry *uiNewEntry(void) -{ - return finishNewEntry([libui_intrinsicWidthNSTextField class]); -} - -uiEntry *uiNewPasswordEntry(void) -{ - return finishNewEntry([libui_intrinsicWidthNSSecureTextField class]); -} - -uiEntry *uiNewSearchEntry(void) -{ - uiEntry *e; - NSSearchField *s; - - e = finishNewEntry([libui_intrinsicWidthNSSearchField class]); - s = (NSSearchField *) (e->textfield); - // TODO these are only on 10.10 -// [s setSendsSearchStringImmediately:NO]; -// [s setSendsWholeSearchString:NO]; - [s setBordered:NO]; - [s setBezelStyle:NSTextFieldRoundedBezel]; - [s setBezeled:YES]; - return e; -} diff --git a/src/libui_sdl/libui/darwin/fontbutton.m b/src/libui_sdl/libui/darwin/fontbutton.m deleted file mode 100644 index 22bc646..0000000 --- a/src/libui_sdl/libui/darwin/fontbutton.m +++ /dev/null @@ -1,218 +0,0 @@ -// 14 april 2016 -#import "uipriv_darwin.h" - -@interface fontButton : NSButton { - uiFontButton *libui_b; - NSFont *libui_font; -} -- (id)initWithFrame:(NSRect)frame libuiFontButton:(uiFontButton *)b; -- (void)updateFontButtonLabel; -- (IBAction)fontButtonClicked:(id)sender; -- (void)activateFontButton; -- (void)deactivateFontButton:(BOOL)activatingAnother; -- (void)deactivateOnClose:(NSNotification *)note; -- (uiDrawTextFont *)libuiFont; -@end - -// only one may be active at one time -static fontButton *activeFontButton = nil; - -struct uiFontButton { - uiDarwinControl c; - fontButton *button; - void (*onChanged)(uiFontButton *, void *); - void *onChangedData; -}; - -@implementation fontButton - -- (id)initWithFrame:(NSRect)frame libuiFontButton:(uiFontButton *)b -{ - self = [super initWithFrame:frame]; - if (self) { - self->libui_b = b; - - // imitate a NSColorWell in appearance - [self setButtonType:NSPushOnPushOffButton]; - [self setBordered:YES]; - [self setBezelStyle:NSShadowlessSquareBezelStyle]; - - // default font values according to the CTFontDescriptor reference - // this is autoreleased (thanks swillits in irc.freenode.net/#macdev) - self->libui_font = [[NSFont fontWithName:@"Helvetica" size:12.0] retain]; - [self updateFontButtonLabel]; - - // for when clicked - [self setTarget:self]; - [self setAction:@selector(fontButtonClicked:)]; - } - return self; -} - -- (void)dealloc -{ - // clean up notifications - if (activeFontButton == self) - [self deactivateFontButton:NO]; - [self->libui_font release]; - [super dealloc]; -} - -- (void)updateFontButtonLabel -{ - NSString *title; - - title = [NSString stringWithFormat:@"%@ %g", - [self->libui_font displayName], - [self->libui_font pointSize]]; - [self setTitle:title]; -} - -- (IBAction)fontButtonClicked:(id)sender -{ - if ([self state] == NSOnState) - [self activateFontButton]; - else - [self deactivateFontButton:NO]; -} - -- (void)activateFontButton -{ - NSFontManager *sfm; - - sfm = [NSFontManager sharedFontManager]; - if (activeFontButton != nil) - [activeFontButton deactivateFontButton:YES]; - [sfm setTarget:self]; - [sfm setSelectedFont:self->libui_font isMultiple:NO]; - [sfm orderFrontFontPanel:self]; - activeFontButton = self; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(deactivateOnClose:) - name:NSWindowWillCloseNotification - object:[NSFontPanel sharedFontPanel]]; - [self setState:NSOnState]; -} - -- (void)deactivateFontButton:(BOOL)activatingAnother -{ - NSFontManager *sfm; - - sfm = [NSFontManager sharedFontManager]; - [sfm setTarget:nil]; - if (!activatingAnother) - [[NSFontPanel sharedFontPanel] orderOut:self]; - activeFontButton = nil; - [[NSNotificationCenter defaultCenter] removeObserver:self - name:NSWindowWillCloseNotification - object:[NSFontPanel sharedFontPanel]]; - [self setState:NSOffState]; -} - -- (void)deactivateOnClose:(NSNotification *)note -{ - [self deactivateFontButton:NO]; -} - -- (void)changeFont:(id)sender -{ - NSFontManager *fm; - NSFont *old; - uiFontButton *b = self->libui_b; - - fm = (NSFontManager *) sender; - old = self->libui_font; - self->libui_font = [sender convertFont:self->libui_font]; - // do this even if it returns the same; we don't own anything that isn't from a new or alloc/init - [self->libui_font retain]; - // do this second just in case - [old release]; - [self updateFontButtonLabel]; - (*(b->onChanged))(b, b->onChangedData); -} - -- (NSUInteger)validModesForFontPanel:(NSFontPanel *)panel -{ - return NSFontPanelFaceModeMask | - NSFontPanelSizeModeMask | - NSFontPanelCollectionModeMask; -} - -- (uiDrawTextFont *)libuiFont -{ - return mkTextFontFromNSFont(self->libui_font); -} - -@end - -uiDarwinControlAllDefaults(uiFontButton, button) - -// we do not want font change events to be sent to any controls other than the font buttons -// see main.m for more details -BOOL fontButtonInhibitSendAction(SEL sel, id from, id to) -{ - if (sel != @selector(changeFont:)) - return NO; - return ![to isKindOfClass:[fontButton class]]; -} - -// we do not want NSFontPanelValidation messages to be sent to any controls other than the font buttons when a font button is active -// see main.m for more details -BOOL fontButtonOverrideTargetForAction(SEL sel, id from, id to, id *override) -{ - if (activeFontButton == nil) - return NO; - if (sel != @selector(validModesForFontPanel:)) - return NO; - *override = activeFontButton; - return YES; -} - -// we also don't want the panel to be usable when there's a dialog running; see stddialogs.m for more details on that -// unfortunately the panel seems to ignore -setWorksWhenModal: so we'll have to do things ourselves -@interface nonModalFontPanel : NSFontPanel -@end - -@implementation nonModalFontPanel - -- (BOOL)worksWhenModal -{ - return NO; -} - -@end - -void setupFontPanel(void) -{ - [NSFontManager setFontPanelFactory:[nonModalFontPanel class]]; -} - -static void defaultOnChanged(uiFontButton *b, void *data) -{ - // do nothing -} - -uiDrawTextFont *uiFontButtonFont(uiFontButton *b) -{ - return [b->button libuiFont]; -} - -void uiFontButtonOnChanged(uiFontButton *b, void (*f)(uiFontButton *, void *), void *data) -{ - b->onChanged = f; - b->onChangedData = data; -} - -uiFontButton *uiNewFontButton(void) -{ - uiFontButton *b; - - uiDarwinNewControl(uiFontButton, b); - - b->button = [[fontButton alloc] initWithFrame:NSZeroRect libuiFontButton:b]; - uiDarwinSetControlFont(b->button, NSRegularControlSize); - - uiFontButtonOnChanged(b, defaultOnChanged, NULL); - - return b; -} diff --git a/src/libui_sdl/libui/darwin/form.m b/src/libui_sdl/libui/darwin/form.m deleted file mode 100644 index 7cdb965..0000000 --- a/src/libui_sdl/libui/darwin/form.m +++ /dev/null @@ -1,561 +0,0 @@ -// 7 june 2016 -#import "uipriv_darwin.h" - -// TODO in the test program, sometimes one of the radio buttons can disappear (try when spaced) - -@interface formChild : NSView -@property uiControl *c; -@property (strong) NSTextField *label; -@property BOOL stretchy; -@property NSLayoutPriority oldHorzHuggingPri; -@property NSLayoutPriority oldVertHuggingPri; -@property (strong) NSLayoutConstraint *baseline; -@property (strong) NSLayoutConstraint *leading; -@property (strong) NSLayoutConstraint *top; -@property (strong) NSLayoutConstraint *trailing; -@property (strong) NSLayoutConstraint *bottom; -- (id)initWithLabel:(NSTextField *)l; -- (void)onDestroy; -- (NSView *)view; -@end - -@interface formView : NSView { - uiForm *f; - NSMutableArray *children; - int padded; - - NSLayoutConstraint *first; - NSMutableArray *inBetweens; - NSLayoutConstraint *last; - NSMutableArray *widths; - NSMutableArray *leadings; - NSMutableArray *middles; - NSMutableArray *trailings; -} -- (id)initWithF:(uiForm *)ff; -- (void)onDestroy; -- (void)removeOurConstraints; -- (void)syncEnableStates:(int)enabled; -- (CGFloat)paddingAmount; -- (void)establishOurConstraints; -- (void)append:(NSString *)label c:(uiControl *)c stretchy:(int)stretchy; -- (void)delete:(int)n; -- (int)isPadded; -- (void)setPadded:(int)p; -- (BOOL)hugsTrailing; -- (BOOL)hugsBottom; -- (int)nStretchy; -@end - -struct uiForm { - uiDarwinControl c; - formView *view; -}; - -@implementation formChild - -- (id)initWithLabel:(NSTextField *)l -{ - self = [super initWithFrame:NSZeroRect]; - if (self) { - self.label = l; - [self.label setTranslatesAutoresizingMaskIntoConstraints:NO]; - [self.label setContentHuggingPriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationHorizontal]; - [self.label setContentHuggingPriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationVertical]; - [self.label setContentCompressionResistancePriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationHorizontal]; - [self.label setContentCompressionResistancePriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationVertical]; - [self addSubview:self.label]; - - self.leading = mkConstraint(self.label, NSLayoutAttributeLeading, - NSLayoutRelationGreaterThanOrEqual, - self, NSLayoutAttributeLeading, - 1, 0, - @"uiForm label leading"); - [self addConstraint:self.leading]; - self.top = mkConstraint(self.label, NSLayoutAttributeTop, - NSLayoutRelationEqual, - self, NSLayoutAttributeTop, - 1, 0, - @"uiForm label top"); - [self addConstraint:self.top]; - self.trailing = mkConstraint(self.label, NSLayoutAttributeTrailing, - NSLayoutRelationEqual, - self, NSLayoutAttributeTrailing, - 1, 0, - @"uiForm label trailing"); - [self addConstraint:self.trailing]; - self.bottom = mkConstraint(self.label, NSLayoutAttributeBottom, - NSLayoutRelationEqual, - self, NSLayoutAttributeBottom, - 1, 0, - @"uiForm label bottom"); - [self addConstraint:self.bottom]; - } - return self; -} - -- (void)onDestroy -{ - [self removeConstraint:self.trailing]; - self.trailing = nil; - [self removeConstraint:self.top]; - self.top = nil; - [self removeConstraint:self.bottom]; - self.bottom = nil; - - [self.label removeFromSuperview]; - self.label = nil; -} - -- (NSView *)view -{ - return (NSView *) uiControlHandle(self.c); -} - -@end - -@implementation formView - -- (id)initWithF:(uiForm *)ff -{ - self = [super initWithFrame:NSZeroRect]; - if (self != nil) { - self->f = ff; - self->padded = 0; - self->children = [NSMutableArray new]; - - self->inBetweens = [NSMutableArray new]; - self->widths = [NSMutableArray new]; - self->leadings = [NSMutableArray new]; - self->middles = [NSMutableArray new]; - self->trailings = [NSMutableArray new]; - } - return self; -} - -- (void)onDestroy -{ - formChild *fc; - - [self removeOurConstraints]; - [self->inBetweens release]; - [self->widths release]; - [self->leadings release]; - [self->middles release]; - [self->trailings release]; - - for (fc in self->children) { - [self removeConstraint:fc.baseline]; - fc.baseline = nil; - uiControlSetParent(fc.c, NULL); - uiDarwinControlSetSuperview(uiDarwinControl(fc.c), nil); - uiControlDestroy(fc.c); - [fc onDestroy]; - [fc removeFromSuperview]; - } - [self->children release]; -} - -- (void)removeOurConstraints -{ - if (self->first != nil) { - [self removeConstraint:self->first]; - [self->first release]; - self->first = nil; - } - if ([self->inBetweens count] != 0) { - [self removeConstraints:self->inBetweens]; - [self->inBetweens removeAllObjects]; - } - if (self->last != nil) { - [self removeConstraint:self->last]; - [self->last release]; - self->last = nil; - } - if ([self->widths count] != 0) { - [self removeConstraints:self->widths]; - [self->widths removeAllObjects]; - } - if ([self->leadings count] != 0) { - [self removeConstraints:self->leadings]; - [self->leadings removeAllObjects]; - } - if ([self->middles count] != 0) { - [self removeConstraints:self->middles]; - [self->middles removeAllObjects]; - } - if ([self->trailings count] != 0) { - [self removeConstraints:self->trailings]; - [self->trailings removeAllObjects]; - } -} - -- (void)syncEnableStates:(int)enabled -{ - formChild *fc; - - for (fc in self->children) - uiDarwinControlSyncEnableState(uiDarwinControl(fc.c), enabled); -} - -- (CGFloat)paddingAmount -{ - if (!self->padded) - return 0.0; - return uiDarwinPaddingAmount(NULL); -} - -- (void)establishOurConstraints -{ - formChild *fc; - CGFloat padding; - NSView *prev, *prevlabel; - NSLayoutConstraint *c; - - [self removeOurConstraints]; - if ([self->children count] == 0) - return; - padding = [self paddingAmount]; - - // first arrange the children vertically and make them the same width - prev = nil; - for (fc in self->children) { - [fc setHidden:!uiControlVisible(fc.c)]; - if (!uiControlVisible(fc.c)) - continue; - if (prev == nil) { // first view - self->first = mkConstraint(self, NSLayoutAttributeTop, - NSLayoutRelationEqual, - [fc view], NSLayoutAttributeTop, - 1, 0, - @"uiForm first vertical constraint"); - [self addConstraint:self->first]; - [self->first retain]; - prev = [fc view]; - prevlabel = fc; - continue; - } - // not the first; link it - c = mkConstraint(prev, NSLayoutAttributeBottom, - NSLayoutRelationEqual, - [fc view], NSLayoutAttributeTop, - 1, -padding, - @"uiForm in-between vertical constraint"); - [self addConstraint:c]; - [self->inBetweens addObject:c]; - // and make the same width - c = mkConstraint(prev, NSLayoutAttributeWidth, - NSLayoutRelationEqual, - [fc view], NSLayoutAttributeWidth, - 1, 0, - @"uiForm control width constraint"); - [self addConstraint:c]; - [self->widths addObject:c]; - c = mkConstraint(prevlabel, NSLayoutAttributeWidth, - NSLayoutRelationEqual, - fc, NSLayoutAttributeWidth, - 1, 0, - @"uiForm label lwidth constraint"); - [self addConstraint:c]; - [self->widths addObject:c]; - prev = [fc view]; - prevlabel = fc; - } - if (prev == nil) // all hidden; act as if nothing there - return; - self->last = mkConstraint(prev, NSLayoutAttributeBottom, - NSLayoutRelationEqual, - self, NSLayoutAttributeBottom, - 1, 0, - @"uiForm last vertical constraint"); - [self addConstraint:self->last]; - [self->last retain]; - - // now arrange the controls horizontally - for (fc in self->children) { - if (!uiControlVisible(fc.c)) - continue; - c = mkConstraint(self, NSLayoutAttributeLeading, - NSLayoutRelationEqual, - fc, NSLayoutAttributeLeading, - 1, 0, - @"uiForm leading constraint"); - [self addConstraint:c]; - [self->leadings addObject:c]; - // coerce the control to be as wide as possible - // see http://stackoverflow.com/questions/37710892/in-auto-layout-i-set-up-labels-that-shouldnt-grow-horizontally-and-controls-th - c = mkConstraint(self, NSLayoutAttributeLeading, - NSLayoutRelationEqual, - [fc view], NSLayoutAttributeLeading, - 1, 0, - @"uiForm leading constraint"); - [c setPriority:NSLayoutPriorityDefaultHigh]; - [self addConstraint:c]; - [self->leadings addObject:c]; - c = mkConstraint(fc, NSLayoutAttributeTrailing, - NSLayoutRelationEqual, - [fc view], NSLayoutAttributeLeading, - 1, -padding, - @"uiForm middle constraint"); - [self addConstraint:c]; - [self->middles addObject:c]; - c = mkConstraint([fc view], NSLayoutAttributeTrailing, - NSLayoutRelationEqual, - self, NSLayoutAttributeTrailing, - 1, 0, - @"uiForm trailing constraint"); - [self addConstraint:c]; - [self->trailings addObject:c]; - // TODO - c = mkConstraint(fc, NSLayoutAttributeBottom, - NSLayoutRelationLessThanOrEqual, - self, NSLayoutAttributeBottom, - 1, 0, - @"TODO"); - [self addConstraint:c]; - [self->trailings addObject:c]; - } - - // and make all stretchy controls have the same height - prev = nil; - for (fc in self->children) { - if (!uiControlVisible(fc.c)) - continue; - if (!fc.stretchy) - continue; - if (prev == nil) { - prev = [fc view]; - continue; - } - c = mkConstraint([fc view], NSLayoutAttributeHeight, - NSLayoutRelationEqual, - prev, NSLayoutAttributeHeight, - 1, 0, - @"uiForm stretchy constraint"); - [self addConstraint:c]; - // TODO make a dedicated array for this - [self->leadings addObject:c]; - } - - // we don't arrange the labels vertically; that's done when we add the control since those constraints don't need to change (they just need to be at their baseline) -} - -- (void)append:(NSString *)label c:(uiControl *)c stretchy:(int)stretchy -{ - formChild *fc; - NSLayoutPriority priority; - NSLayoutAttribute attribute; - int oldnStretchy; - - fc = [[formChild alloc] initWithLabel:newLabel(label)]; - fc.c = c; - fc.stretchy = stretchy; - fc.oldHorzHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(fc.c), NSLayoutConstraintOrientationHorizontal); - fc.oldVertHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(fc.c), NSLayoutConstraintOrientationVertical); - [fc setTranslatesAutoresizingMaskIntoConstraints:NO]; - [self addSubview:fc]; - - uiControlSetParent(fc.c, uiControl(self->f)); - uiDarwinControlSetSuperview(uiDarwinControl(fc.c), self); - uiDarwinControlSyncEnableState(uiDarwinControl(fc.c), uiControlEnabledToUser(uiControl(self->f))); - - // if a control is stretchy, it should not hug vertically - // otherwise, it should *forcibly* hug - if (fc.stretchy) - priority = NSLayoutPriorityDefaultLow; - else - // LONGTERM will default high work? - priority = NSLayoutPriorityRequired; - uiDarwinControlSetHuggingPriority(uiDarwinControl(fc.c), priority, NSLayoutConstraintOrientationVertical); - // make sure controls don't hug their horizontal direction so they fill the width of the view - uiDarwinControlSetHuggingPriority(uiDarwinControl(fc.c), NSLayoutPriorityDefaultLow, NSLayoutConstraintOrientationHorizontal); - - // and constrain the baselines to position the label vertically - // if the view is a scroll view, align tops, not baselines - // this is what Interface Builder does - attribute = NSLayoutAttributeBaseline; - if ([[fc view] isKindOfClass:[NSScrollView class]]) - attribute = NSLayoutAttributeTop; - fc.baseline = mkConstraint(fc.label, attribute, - NSLayoutRelationEqual, - [fc view], attribute, - 1, 0, - @"uiForm baseline constraint"); - [self addConstraint:fc.baseline]; - - oldnStretchy = [self nStretchy]; - [self->children addObject:fc]; - - [self establishOurConstraints]; - if (fc.stretchy) - if (oldnStretchy == 0) - uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(self->f)); - - [fc release]; // we don't need the initial reference now -} - -- (void)delete:(int)n -{ - formChild *fc; - int stretchy; - - fc = (formChild *) [self->children objectAtIndex:n]; - stretchy = fc.stretchy; - - uiControlSetParent(fc.c, NULL); - uiDarwinControlSetSuperview(uiDarwinControl(fc.c), nil); - - uiDarwinControlSetHuggingPriority(uiDarwinControl(fc.c), fc.oldHorzHuggingPri, NSLayoutConstraintOrientationHorizontal); - uiDarwinControlSetHuggingPriority(uiDarwinControl(fc.c), fc.oldVertHuggingPri, NSLayoutConstraintOrientationVertical); - - [fc onDestroy]; - [self->children removeObjectAtIndex:n]; - - [self establishOurConstraints]; - if (stretchy) - if ([self nStretchy] == 0) - uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(self->f)); -} - -- (int)isPadded -{ - return self->padded; -} - -- (void)setPadded:(int)p -{ - CGFloat padding; - NSLayoutConstraint *c; - - self->padded = p; - padding = [self paddingAmount]; - for (c in self->inBetweens) - [c setConstant:-padding]; - for (c in self->middles) - [c setConstant:-padding]; -} - -- (BOOL)hugsTrailing -{ - return YES; // always hug trailing -} - -- (BOOL)hugsBottom -{ - // only hug if we have stretchy - return [self nStretchy] != 0; -} - -- (int)nStretchy -{ - formChild *fc; - int n; - - n = 0; - for (fc in self->children) { - if (!uiControlVisible(fc.c)) - continue; - if (fc.stretchy) - n++; - } - return n; -} - -@end - -static void uiFormDestroy(uiControl *c) -{ - uiForm *f = uiForm(c); - - [f->view onDestroy]; - [f->view release]; - uiFreeControl(uiControl(f)); -} - -uiDarwinControlDefaultHandle(uiForm, view) -uiDarwinControlDefaultParent(uiForm, view) -uiDarwinControlDefaultSetParent(uiForm, view) -uiDarwinControlDefaultToplevel(uiForm, view) -uiDarwinControlDefaultVisible(uiForm, view) -uiDarwinControlDefaultShow(uiForm, view) -uiDarwinControlDefaultHide(uiForm, view) -uiDarwinControlDefaultEnabled(uiForm, view) -uiDarwinControlDefaultEnable(uiForm, view) -uiDarwinControlDefaultDisable(uiForm, view) - -static void uiFormSyncEnableState(uiDarwinControl *c, int enabled) -{ - uiForm *f = uiForm(c); - - if (uiDarwinShouldStopSyncEnableState(uiDarwinControl(f), enabled)) - return; - [f->view syncEnableStates:enabled]; -} - -uiDarwinControlDefaultSetSuperview(uiForm, view) - -static BOOL uiFormHugsTrailingEdge(uiDarwinControl *c) -{ - uiForm *f = uiForm(c); - - return [f->view hugsTrailing]; -} - -static BOOL uiFormHugsBottom(uiDarwinControl *c) -{ - uiForm *f = uiForm(c); - - return [f->view hugsBottom]; -} - -static void uiFormChildEdgeHuggingChanged(uiDarwinControl *c) -{ - uiForm *f = uiForm(c); - - [f->view establishOurConstraints]; -} - -uiDarwinControlDefaultHuggingPriority(uiForm, view) -uiDarwinControlDefaultSetHuggingPriority(uiForm, view) - -static void uiFormChildVisibilityChanged(uiDarwinControl *c) -{ - uiForm *f = uiForm(c); - - [f->view establishOurConstraints]; -} - -void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy) -{ - // LONGTERM on other platforms - // or at leat allow this and implicitly turn it into a spacer - if (c == NULL) - userbug("You cannot add NULL to a uiForm."); - [f->view append:toNSString(label) c:c stretchy:stretchy]; -} - -void uiFormDelete(uiForm *f, int n) -{ - [f->view delete:n]; -} - -int uiFormPadded(uiForm *f) -{ - return [f->view isPadded]; -} - -void uiFormSetPadded(uiForm *f, int padded) -{ - [f->view setPadded:padded]; -} - -uiForm *uiNewForm(void) -{ - uiForm *f; - - uiDarwinNewControl(uiForm, f); - - f->view = [[formView alloc] initWithF:f]; - - return f; -} diff --git a/src/libui_sdl/libui/darwin/grid.m b/src/libui_sdl/libui/darwin/grid.m deleted file mode 100644 index d5c5fb1..0000000 --- a/src/libui_sdl/libui/darwin/grid.m +++ /dev/null @@ -1,800 +0,0 @@ -// 11 june 2016 -#import "uipriv_darwin.h" - -// TODO the assorted test doesn't work right at all - -@interface gridChild : NSView -@property uiControl *c; -@property int left; -@property int top; -@property int xspan; -@property int yspan; -@property int hexpand; -@property uiAlign halign; -@property int vexpand; -@property uiAlign valign; - -@property (strong) NSLayoutConstraint *leadingc; -@property (strong) NSLayoutConstraint *topc; -@property (strong) NSLayoutConstraint *trailingc; -@property (strong) NSLayoutConstraint *bottomc; -@property (strong) NSLayoutConstraint *xcenterc; -@property (strong) NSLayoutConstraint *ycenterc; - -@property NSLayoutPriority oldHorzHuggingPri; -@property NSLayoutPriority oldVertHuggingPri; -- (void)setC:(uiControl *)c grid:(uiGrid *)g; -- (void)onDestroy; -- (NSView *)view; -@end - -@interface gridView : NSView { - uiGrid *g; - NSMutableArray *children; - int padded; - - NSMutableArray *edges; - NSMutableArray *inBetweens; - - NSMutableArray *emptyCellViews; -} -- (id)initWithG:(uiGrid *)gg; -- (void)onDestroy; -- (void)removeOurConstraints; -- (void)syncEnableStates:(int)enabled; -- (CGFloat)paddingAmount; -- (void)establishOurConstraints; -- (void)append:(gridChild *)gc; -- (void)insert:(gridChild *)gc after:(uiControl *)c at:(uiAt)at; -- (int)isPadded; -- (void)setPadded:(int)p; -- (BOOL)hugsTrailing; -- (BOOL)hugsBottom; -- (int)nhexpand; -- (int)nvexpand; -@end - -struct uiGrid { - uiDarwinControl c; - gridView *view; -}; - -@implementation gridChild - -- (void)setC:(uiControl *)c grid:(uiGrid *)g -{ - self.c = c; - self.oldHorzHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(self.c), NSLayoutConstraintOrientationHorizontal); - self.oldVertHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(self.c), NSLayoutConstraintOrientationVertical); - - uiControlSetParent(self.c, uiControl(g)); - uiDarwinControlSetSuperview(uiDarwinControl(self.c), self); - uiDarwinControlSyncEnableState(uiDarwinControl(self.c), uiControlEnabledToUser(uiControl(g))); - - if (self.halign == uiAlignStart || self.halign == uiAlignFill) { - self.leadingc = mkConstraint(self, NSLayoutAttributeLeading, - NSLayoutRelationEqual, - [self view], NSLayoutAttributeLeading, - 1, 0, - @"uiGrid child horizontal alignment start constraint"); - [self addConstraint:self.leadingc]; - } - if (self.halign == uiAlignCenter) { - self.xcenterc = mkConstraint(self, NSLayoutAttributeCenterX, - NSLayoutRelationEqual, - [self view], NSLayoutAttributeCenterX, - 1, 0, - @"uiGrid child horizontal alignment center constraint"); - [self addConstraint:self.xcenterc]; - } - if (self.halign == uiAlignEnd || self.halign == uiAlignFill) { - self.trailingc = mkConstraint(self, NSLayoutAttributeTrailing, - NSLayoutRelationEqual, - [self view], NSLayoutAttributeTrailing, - 1, 0, - @"uiGrid child horizontal alignment end constraint"); - [self addConstraint:self.trailingc]; - } - - if (self.valign == uiAlignStart || self.valign == uiAlignFill) { - self.topc = mkConstraint(self, NSLayoutAttributeTop, - NSLayoutRelationEqual, - [self view], NSLayoutAttributeTop, - 1, 0, - @"uiGrid child vertical alignment start constraint"); - [self addConstraint:self.topc]; - } - if (self.valign == uiAlignCenter) { - self.ycenterc = mkConstraint(self, NSLayoutAttributeCenterY, - NSLayoutRelationEqual, - [self view], NSLayoutAttributeCenterY, - 1, 0, - @"uiGrid child vertical alignment center constraint"); - [self addConstraint:self.ycenterc]; - } - if (self.valign == uiAlignEnd || self.valign == uiAlignFill) { - self.bottomc = mkConstraint(self, NSLayoutAttributeBottom, - NSLayoutRelationEqual, - [self view], NSLayoutAttributeBottom, - 1, 0, - @"uiGrid child vertical alignment end constraint"); - [self addConstraint:self.bottomc]; - } -} - -- (void)onDestroy -{ - if (self.leadingc != nil) { - [self removeConstraint:self.leadingc]; - self.leadingc = nil; - } - if (self.topc != nil) { - [self removeConstraint:self.topc]; - self.topc = nil; - } - if (self.trailingc != nil) { - [self removeConstraint:self.trailingc]; - self.trailingc = nil; - } - if (self.bottomc != nil) { - [self removeConstraint:self.bottomc]; - self.bottomc = nil; - } - if (self.xcenterc != nil) { - [self removeConstraint:self.xcenterc]; - self.xcenterc = nil; - } - if (self.ycenterc != nil) { - [self removeConstraint:self.ycenterc]; - self.ycenterc = nil; - } - - uiControlSetParent(self.c, NULL); - uiDarwinControlSetSuperview(uiDarwinControl(self.c), nil); - uiDarwinControlSetHuggingPriority(uiDarwinControl(self.c), self.oldHorzHuggingPri, NSLayoutConstraintOrientationHorizontal); - uiDarwinControlSetHuggingPriority(uiDarwinControl(self.c), self.oldVertHuggingPri, NSLayoutConstraintOrientationVertical); -} - -- (NSView *)view -{ - return (NSView *) uiControlHandle(self.c); -} - -@end - -@implementation gridView - -- (id)initWithG:(uiGrid *)gg -{ - self = [super initWithFrame:NSZeroRect]; - if (self != nil) { - self->g = gg; - self->padded = 0; - self->children = [NSMutableArray new]; - - self->edges = [NSMutableArray new]; - self->inBetweens = [NSMutableArray new]; - - self->emptyCellViews = [NSMutableArray new]; - } - return self; -} - -- (void)onDestroy -{ - gridChild *gc; - - [self removeOurConstraints]; - [self->edges release]; - [self->inBetweens release]; - - [self->emptyCellViews release]; - - for (gc in self->children) { - [gc onDestroy]; - uiControlDestroy(gc.c); - [gc removeFromSuperview]; - } - [self->children release]; -} - -- (void)removeOurConstraints -{ - NSView *v; - - if ([self->edges count] != 0) { - [self removeConstraints:self->edges]; - [self->edges removeAllObjects]; - } - if ([self->inBetweens count] != 0) { - [self removeConstraints:self->inBetweens]; - [self->inBetweens removeAllObjects]; - } - - for (v in self->emptyCellViews) - [v removeFromSuperview]; - [self->emptyCellViews removeAllObjects]; -} - -- (void)syncEnableStates:(int)enabled -{ - gridChild *gc; - - for (gc in self->children) - uiDarwinControlSyncEnableState(uiDarwinControl(gc.c), enabled); -} - -- (CGFloat)paddingAmount -{ - if (!self->padded) - return 0.0; - return uiDarwinPaddingAmount(NULL); -} - -// LONGTERM stop early if all controls are hidden -- (void)establishOurConstraints -{ - gridChild *gc; - CGFloat padding; - int xmin, ymin; - int xmax, ymax; - int xcount, ycount; - BOOL first; - int **gg; - NSView ***gv; - BOOL **gspan; - int x, y; - int i; - NSLayoutConstraint *c; - int firstx, firsty; - BOOL *hexpand, *vexpand; - BOOL doit; - BOOL onlyEmptyAndSpanning; - - [self removeOurConstraints]; - if ([self->children count] == 0) - return; - padding = [self paddingAmount]; - - // first, figure out the minimum and maximum row and column numbers - // ignore hidden controls - first = YES; - for (gc in self->children) { - // this bit is important: it ensures row ymin and column xmin have at least one cell to draw, so the onlyEmptyAndSpanning logic below will never run on those rows - if (!uiControlVisible(gc.c)) - continue; - if (first) { - xmin = gc.left; - ymin = gc.top; - xmax = gc.left + gc.xspan; - ymax = gc.top + gc.yspan; - first = NO; - continue; - } - if (xmin > gc.left) - xmin = gc.left; - if (ymin > gc.top) - ymin = gc.top; - if (xmax < (gc.left + gc.xspan)) - xmax = gc.left + gc.xspan; - if (ymax < (gc.top + gc.yspan)) - ymax = gc.top + gc.yspan; - } - if (first != NO) // the entire grid is hidden; do nothing - return; - xcount = xmax - xmin; - ycount = ymax - ymin; - - // now build a topological map of the grid gg[y][x] - // also figure out which cells contain spanned views so they can be ignored later - // treat hidden controls by keeping the indices -1 - gg = (int **) uiAlloc(ycount * sizeof (int *), "int[][]"); - gspan = (BOOL **) uiAlloc(ycount * sizeof (BOOL *), "BOOL[][]"); - for (y = 0; y < ycount; y++) { - gg[y] = (int *) uiAlloc(xcount * sizeof (int), "int[]"); - gspan[y] = (BOOL *) uiAlloc(xcount * sizeof (BOOL), "BOOL[]"); - for (x = 0; x < xcount; x++) - gg[y][x] = -1; // empty - } - for (i = 0; i < [self->children count]; i++) { - gc = (gridChild *) [self->children objectAtIndex:i]; - if (!uiControlVisible(gc.c)) - continue; - for (y = gc.top; y < gc.top + gc.yspan; y++) - for (x = gc.left; x < gc.left + gc.xspan; x++) { - gg[y - ymin][x - xmin] = i; - if (x != gc.left || y != gc.top) - gspan[y - ymin][x - xmin] = YES; - } - } - - // if a row or column only contains emptys and spanning cells of a opposite-direction spannings, remove it by duplicating the previous row or column - for (y = 0; y < ycount; y++) { - onlyEmptyAndSpanning = YES; - for (x = 0; x < xcount; x++) - if (gg[y][x] != -1) { - gc = (gridChild *) [self->children objectAtIndex:gg[y][x]]; - if (gc.yspan == 1 || gc.top - ymin == y) { - onlyEmptyAndSpanning = NO; - break; - } - } - if (onlyEmptyAndSpanning) - for (x = 0; x < xcount; x++) { - gg[y][x] = gg[y - 1][x]; - gspan[y][x] = YES; - } - } - for (x = 0; x < xcount; x++) { - onlyEmptyAndSpanning = YES; - for (y = 0; y < ycount; y++) - if (gg[y][x] != -1) { - gc = (gridChild *) [self->children objectAtIndex:gg[y][x]]; - if (gc.xspan == 1 || gc.left - xmin == x) { - onlyEmptyAndSpanning = NO; - break; - } - } - if (onlyEmptyAndSpanning) - for (y = 0; y < ycount; y++) { - gg[y][x] = gg[y][x - 1]; - gspan[y][x] = YES; - } - } - - // now build a topological map of the grid's views gv[y][x] - // for any empty cell, create a dummy view - gv = (NSView ***) uiAlloc(ycount * sizeof (NSView **), "NSView *[][]"); - for (y = 0; y < ycount; y++) { - gv[y] = (NSView **) uiAlloc(xcount * sizeof (NSView *), "NSView *[]"); - for (x = 0; x < xcount; x++) - if (gg[y][x] == -1) { - gv[y][x] = [[NSView alloc] initWithFrame:NSZeroRect]; - [gv[y][x] setTranslatesAutoresizingMaskIntoConstraints:NO]; - [self addSubview:gv[y][x]]; - [self->emptyCellViews addObject:gv[y][x]]; - } else { - gc = (gridChild *) [self->children objectAtIndex:gg[y][x]]; - gv[y][x] = gc; - } - } - - // now figure out which rows and columns really expand - hexpand = (BOOL *) uiAlloc(xcount * sizeof (BOOL), "BOOL[]"); - vexpand = (BOOL *) uiAlloc(ycount * sizeof (BOOL), "BOOL[]"); - // first, which don't span - for (gc in self->children) { - if (!uiControlVisible(gc.c)) - continue; - if (gc.hexpand && gc.xspan == 1) - hexpand[gc.left - xmin] = YES; - if (gc.vexpand && gc.yspan == 1) - vexpand[gc.top - ymin] = YES; - } - // second, which do span - // the way we handle this is simple: if none of the spanned rows/columns expand, make all rows/columns expand - for (gc in self->children) { - if (!uiControlVisible(gc.c)) - continue; - if (gc.hexpand && gc.xspan != 1) { - doit = YES; - for (x = gc.left; x < gc.left + gc.xspan; x++) - if (hexpand[x - xmin]) { - doit = NO; - break; - } - if (doit) - for (x = gc.left; x < gc.left + gc.xspan; x++) - hexpand[x - xmin] = YES; - } - if (gc.vexpand && gc.yspan != 1) { - doit = YES; - for (y = gc.top; y < gc.top + gc.yspan; y++) - if (vexpand[y - ymin]) { - doit = NO; - break; - } - if (doit) - for (y = gc.top; y < gc.top + gc.yspan; y++) - vexpand[y - ymin] = YES; - } - } - - // now establish all the edge constraints - // leading and trailing edges - for (y = 0; y < ycount; y++) { - c = mkConstraint(self, NSLayoutAttributeLeading, - NSLayoutRelationEqual, - gv[y][0], NSLayoutAttributeLeading, - 1, 0, - @"uiGrid leading edge constraint"); - [self addConstraint:c]; - [self->edges addObject:c]; - c = mkConstraint(self, NSLayoutAttributeTrailing, - NSLayoutRelationEqual, - gv[y][xcount - 1], NSLayoutAttributeTrailing, - 1, 0, - @"uiGrid trailing edge constraint"); - [self addConstraint:c]; - [self->edges addObject:c]; - } - // top and bottom edges - for (x = 0; x < xcount; x++) { - c = mkConstraint(self, NSLayoutAttributeTop, - NSLayoutRelationEqual, - gv[0][x], NSLayoutAttributeTop, - 1, 0, - @"uiGrid top edge constraint"); - [self addConstraint:c]; - [self->edges addObject:c]; - c = mkConstraint(self, NSLayoutAttributeBottom, - NSLayoutRelationEqual, - gv[ycount - 1][x], NSLayoutAttributeBottom, - 1, 0, - @"uiGrid bottom edge constraint"); - [self addConstraint:c]; - [self->edges addObject:c]; - } - - // now align leading and top edges - // do NOT align spanning cells! - for (x = 0; x < xcount; x++) { - for (y = 0; y < ycount; y++) - if (!gspan[y][x]) - break; - firsty = y; - for (y++; y < ycount; y++) { - if (gspan[y][x]) - continue; - c = mkConstraint(gv[firsty][x], NSLayoutAttributeLeading, - NSLayoutRelationEqual, - gv[y][x], NSLayoutAttributeLeading, - 1, 0, - @"uiGrid column leading constraint"); - [self addConstraint:c]; - [self->edges addObject:c]; - } - } - for (y = 0; y < ycount; y++) { - for (x = 0; x < xcount; x++) - if (!gspan[y][x]) - break; - firstx = x; - for (x++; x < xcount; x++) { - if (gspan[y][x]) - continue; - c = mkConstraint(gv[y][firstx], NSLayoutAttributeTop, - NSLayoutRelationEqual, - gv[y][x], NSLayoutAttributeTop, - 1, 0, - @"uiGrid row top constraint"); - [self addConstraint:c]; - [self->edges addObject:c]; - } - } - - // now string adjacent views together - for (y = 0; y < ycount; y++) - for (x = 1; x < xcount; x++) - if (gv[y][x - 1] != gv[y][x]) { - c = mkConstraint(gv[y][x - 1], NSLayoutAttributeTrailing, - NSLayoutRelationEqual, - gv[y][x], NSLayoutAttributeLeading, - 1, -padding, - @"uiGrid internal horizontal constraint"); - [self addConstraint:c]; - [self->inBetweens addObject:c]; - } - for (x = 0; x < xcount; x++) - for (y = 1; y < ycount; y++) - if (gv[y - 1][x] != gv[y][x]) { - c = mkConstraint(gv[y - 1][x], NSLayoutAttributeBottom, - NSLayoutRelationEqual, - gv[y][x], NSLayoutAttributeTop, - 1, -padding, - @"uiGrid internal vertical constraint"); - [self addConstraint:c]; - [self->inBetweens addObject:c]; - } - - // now set priorities for all widgets that expand or not - // if a cell is in an expanding row, OR If it spans, then it must be willing to stretch - // otherwise, it tries not to - // note we don't use NSLayoutPriorityRequired as that will cause things to squish when they shouldn't - for (gc in self->children) { - NSLayoutPriority priority; - - if (!uiControlVisible(gc.c)) - continue; - if (hexpand[gc.left - xmin] || gc.xspan != 1) - priority = NSLayoutPriorityDefaultLow; - else - priority = NSLayoutPriorityDefaultHigh; - uiDarwinControlSetHuggingPriority(uiDarwinControl(gc.c), priority, NSLayoutConstraintOrientationHorizontal); - // same for vertical direction - if (vexpand[gc.top - ymin] || gc.yspan != 1) - priority = NSLayoutPriorityDefaultLow; - else - priority = NSLayoutPriorityDefaultHigh; - uiDarwinControlSetHuggingPriority(uiDarwinControl(gc.c), priority, NSLayoutConstraintOrientationVertical); - } - - // TODO make all expanding rows/columns the same height/width - - // and finally clean up - uiFree(hexpand); - uiFree(vexpand); - for (y = 0; y < ycount; y++) { - uiFree(gg[y]); - uiFree(gv[y]); - uiFree(gspan[y]); - } - uiFree(gg); - uiFree(gv); - uiFree(gspan); -} - -- (void)append:(gridChild *)gc -{ - BOOL update; - int oldnh, oldnv; - - [gc setTranslatesAutoresizingMaskIntoConstraints:NO]; - [self addSubview:gc]; - - // no need to set priority here; that's done in establishOurConstraints - - oldnh = [self nhexpand]; - oldnv = [self nvexpand]; - [self->children addObject:gc]; - - [self establishOurConstraints]; - update = NO; - if (gc.hexpand) - if (oldnh == 0) - update = YES; - if (gc.vexpand) - if (oldnv == 0) - update = YES; - if (update) - uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(self->g)); - - [gc release]; // we don't need the initial reference now -} - -- (void)insert:(gridChild *)gc after:(uiControl *)c at:(uiAt)at -{ - gridChild *other; - BOOL found; - - found = NO; - for (other in self->children) - if (other.c == c) { - found = YES; - break; - } - if (!found) - userbug("Existing control %p is not in grid %p; you cannot add other controls next to it", c, self->g); - - switch (at) { - case uiAtLeading: - gc.left = other.left - gc.xspan; - gc.top = other.top; - break; - case uiAtTop: - gc.left = other.left; - gc.top = other.top - gc.yspan; - break; - case uiAtTrailing: - gc.left = other.left + other.xspan; - gc.top = other.top; - break; - case uiAtBottom: - gc.left = other.left; - gc.top = other.top + other.yspan; - break; - // TODO add error checks to ALL enums - } - - [self append:gc]; -} - -- (int)isPadded -{ - return self->padded; -} - -- (void)setPadded:(int)p -{ - CGFloat padding; - NSLayoutConstraint *c; - -#if 0 /* TODO */ -dispatch_after( -dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC), -dispatch_get_main_queue(), -^{ [[self window] visualizeConstraints:[self constraints]]; } -); -#endif - self->padded = p; - padding = [self paddingAmount]; - for (c in self->inBetweens) - switch ([c firstAttribute]) { - case NSLayoutAttributeLeading: - case NSLayoutAttributeTop: - [c setConstant:padding]; - break; - case NSLayoutAttributeTrailing: - case NSLayoutAttributeBottom: - [c setConstant:-padding]; - break; - } -} - -- (BOOL)hugsTrailing -{ - // only hug if we have horizontally expanding - return [self nhexpand] != 0; -} - -- (BOOL)hugsBottom -{ - // only hug if we have vertically expanding - return [self nvexpand] != 0; -} - -- (int)nhexpand -{ - gridChild *gc; - int n; - - n = 0; - for (gc in self->children) { - if (!uiControlVisible(gc.c)) - continue; - if (gc.hexpand) - n++; - } - return n; -} - -- (int)nvexpand -{ - gridChild *gc; - int n; - - n = 0; - for (gc in self->children) { - if (!uiControlVisible(gc.c)) - continue; - if (gc.vexpand) - n++; - } - return n; -} - -@end - -static void uiGridDestroy(uiControl *c) -{ - uiGrid *g = uiGrid(c); - - [g->view onDestroy]; - [g->view release]; - uiFreeControl(uiControl(g)); -} - -uiDarwinControlDefaultHandle(uiGrid, view) -uiDarwinControlDefaultParent(uiGrid, view) -uiDarwinControlDefaultSetParent(uiGrid, view) -uiDarwinControlDefaultToplevel(uiGrid, view) -uiDarwinControlDefaultVisible(uiGrid, view) -uiDarwinControlDefaultShow(uiGrid, view) -uiDarwinControlDefaultHide(uiGrid, view) -uiDarwinControlDefaultEnabled(uiGrid, view) -uiDarwinControlDefaultEnable(uiGrid, view) -uiDarwinControlDefaultDisable(uiGrid, view) - -static void uiGridSyncEnableState(uiDarwinControl *c, int enabled) -{ - uiGrid *g = uiGrid(c); - - if (uiDarwinShouldStopSyncEnableState(uiDarwinControl(g), enabled)) - return; - [g->view syncEnableStates:enabled]; -} - -uiDarwinControlDefaultSetSuperview(uiGrid, view) - -static BOOL uiGridHugsTrailingEdge(uiDarwinControl *c) -{ - uiGrid *g = uiGrid(c); - - return [g->view hugsTrailing]; -} - -static BOOL uiGridHugsBottom(uiDarwinControl *c) -{ - uiGrid *g = uiGrid(c); - - return [g->view hugsBottom]; -} - -static void uiGridChildEdgeHuggingChanged(uiDarwinControl *c) -{ - uiGrid *g = uiGrid(c); - - [g->view establishOurConstraints]; -} - -uiDarwinControlDefaultHuggingPriority(uiGrid, view) -uiDarwinControlDefaultSetHuggingPriority(uiGrid, view) - -static void uiGridChildVisibilityChanged(uiDarwinControl *c) -{ - uiGrid *g = uiGrid(c); - - [g->view establishOurConstraints]; -} - -static gridChild *toChild(uiControl *c, int xspan, int yspan, int hexpand, uiAlign halign, int vexpand, uiAlign valign, uiGrid *g) -{ - gridChild *gc; - - if (xspan < 0) - userbug("You cannot have a negative xspan in a uiGrid cell."); - if (yspan < 0) - userbug("You cannot have a negative yspan in a uiGrid cell."); - gc = [gridChild new]; - gc.xspan = xspan; - gc.yspan = yspan; - gc.hexpand = hexpand; - gc.halign = halign; - gc.vexpand = vexpand; - gc.valign = valign; - [gc setC:c grid:g]; - return gc; -} - -void uiGridAppend(uiGrid *g, uiControl *c, int left, int top, int xspan, int yspan, int hexpand, uiAlign halign, int vexpand, uiAlign valign) -{ - gridChild *gc; - - // LONGTERM on other platforms - // or at leat allow this and implicitly turn it into a spacer - if (c == NULL) - userbug("You cannot add NULL to a uiGrid."); - gc = toChild(c, xspan, yspan, hexpand, halign, vexpand, valign, g); - gc.left = left; - gc.top = top; - [g->view append:gc]; -} - -void uiGridInsertAt(uiGrid *g, uiControl *c, uiControl *existing, uiAt at, int xspan, int yspan, int hexpand, uiAlign halign, int vexpand, uiAlign valign) -{ - gridChild *gc; - - gc = toChild(c, xspan, yspan, hexpand, halign, vexpand, valign, g); - [g->view insert:gc after:existing at:at]; -} - -int uiGridPadded(uiGrid *g) -{ - return [g->view isPadded]; -} - -void uiGridSetPadded(uiGrid *g, int padded) -{ - [g->view setPadded:padded]; -} - -uiGrid *uiNewGrid(void) -{ - uiGrid *g; - - uiDarwinNewControl(uiGrid, g); - - g->view = [[gridView alloc] initWithG:g]; - - return g; -} diff --git a/src/libui_sdl/libui/darwin/group.m b/src/libui_sdl/libui/darwin/group.m deleted file mode 100644 index 0050bbd..0000000 --- a/src/libui_sdl/libui/darwin/group.m +++ /dev/null @@ -1,194 +0,0 @@ -// 14 august 2015 -#import "uipriv_darwin.h" - -struct uiGroup { - uiDarwinControl c; - NSBox *box; - uiControl *child; - NSLayoutPriority oldHorzHuggingPri; - NSLayoutPriority oldVertHuggingPri; - int margined; - struct singleChildConstraints constraints; - NSLayoutPriority horzHuggingPri; - NSLayoutPriority vertHuggingPri; -}; - -static void removeConstraints(uiGroup *g) -{ - // set to contentView instead of to the box itself, otherwise we get clipping underneath the label - singleChildConstraintsRemove(&(g->constraints), [g->box contentView]); -} - -static void uiGroupDestroy(uiControl *c) -{ - uiGroup *g = uiGroup(c); - - removeConstraints(g); - if (g->child != NULL) { - uiControlSetParent(g->child, NULL); - uiDarwinControlSetSuperview(uiDarwinControl(g->child), nil); - uiControlDestroy(g->child); - } - [g->box release]; - uiFreeControl(uiControl(g)); -} - -uiDarwinControlDefaultHandle(uiGroup, box) -uiDarwinControlDefaultParent(uiGroup, box) -uiDarwinControlDefaultSetParent(uiGroup, box) -uiDarwinControlDefaultToplevel(uiGroup, box) -uiDarwinControlDefaultVisible(uiGroup, box) -uiDarwinControlDefaultShow(uiGroup, box) -uiDarwinControlDefaultHide(uiGroup, box) -uiDarwinControlDefaultEnabled(uiGroup, box) -uiDarwinControlDefaultEnable(uiGroup, box) -uiDarwinControlDefaultDisable(uiGroup, box) - -static void uiGroupSyncEnableState(uiDarwinControl *c, int enabled) -{ - uiGroup *g = uiGroup(c); - - if (uiDarwinShouldStopSyncEnableState(uiDarwinControl(g), enabled)) - return; - if (g->child != NULL) - uiDarwinControlSyncEnableState(uiDarwinControl(g->child), enabled); -} - -uiDarwinControlDefaultSetSuperview(uiGroup, box) - -static void groupRelayout(uiGroup *g) -{ - NSView *childView; - - removeConstraints(g); - if (g->child == NULL) - return; - childView = (NSView *) uiControlHandle(g->child); - singleChildConstraintsEstablish(&(g->constraints), - [g->box contentView], childView, - uiDarwinControlHugsTrailingEdge(uiDarwinControl(g->child)), - uiDarwinControlHugsBottom(uiDarwinControl(g->child)), - g->margined, - @"uiGroup"); - // needed for some very rare drawing errors... - jiggleViewLayout(g->box); -} - -// TODO rename these since I'm starting to get confused by what they mean by hugging -BOOL uiGroupHugsTrailingEdge(uiDarwinControl *c) -{ - uiGroup *g = uiGroup(c); - - // TODO make a function? - return g->horzHuggingPri < NSLayoutPriorityWindowSizeStayPut; -} - -BOOL uiGroupHugsBottom(uiDarwinControl *c) -{ - uiGroup *g = uiGroup(c); - - return g->vertHuggingPri < NSLayoutPriorityWindowSizeStayPut; -} - -static void uiGroupChildEdgeHuggingChanged(uiDarwinControl *c) -{ - uiGroup *g = uiGroup(c); - - groupRelayout(g); -} - -static NSLayoutPriority uiGroupHuggingPriority(uiDarwinControl *c, NSLayoutConstraintOrientation orientation) -{ - uiGroup *g = uiGroup(c); - - if (orientation == NSLayoutConstraintOrientationHorizontal) - return g->horzHuggingPri; - return g->vertHuggingPri; -} - -static void uiGroupSetHuggingPriority(uiDarwinControl *c, NSLayoutPriority priority, NSLayoutConstraintOrientation orientation) -{ - uiGroup *g = uiGroup(c); - - if (orientation == NSLayoutConstraintOrientationHorizontal) - g->horzHuggingPri = priority; - else - g->vertHuggingPri = priority; - uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(g)); -} - -static void uiGroupChildVisibilityChanged(uiDarwinControl *c) -{ - uiGroup *g = uiGroup(c); - - groupRelayout(g); -} - -char *uiGroupTitle(uiGroup *g) -{ - return uiDarwinNSStringToText([g->box title]); -} - -void uiGroupSetTitle(uiGroup *g, const char *title) -{ - [g->box setTitle:toNSString(title)]; -} - -void uiGroupSetChild(uiGroup *g, uiControl *child) -{ - NSView *childView; - - if (g->child != NULL) { - removeConstraints(g); - uiDarwinControlSetHuggingPriority(uiDarwinControl(g->child), g->oldHorzHuggingPri, NSLayoutConstraintOrientationHorizontal); - uiDarwinControlSetHuggingPriority(uiDarwinControl(g->child), g->oldVertHuggingPri, NSLayoutConstraintOrientationVertical); - uiControlSetParent(g->child, NULL); - uiDarwinControlSetSuperview(uiDarwinControl(g->child), nil); - } - g->child = child; - if (g->child != NULL) { - childView = (NSView *) uiControlHandle(g->child); - uiControlSetParent(g->child, uiControl(g)); - uiDarwinControlSetSuperview(uiDarwinControl(g->child), [g->box contentView]); - uiDarwinControlSyncEnableState(uiDarwinControl(g->child), uiControlEnabledToUser(uiControl(g))); - // don't hug, just in case we're a stretchy group - g->oldHorzHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(g->child), NSLayoutConstraintOrientationHorizontal); - g->oldVertHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(g->child), NSLayoutConstraintOrientationVertical); - uiDarwinControlSetHuggingPriority(uiDarwinControl(g->child), NSLayoutPriorityDefaultLow, NSLayoutConstraintOrientationHorizontal); - uiDarwinControlSetHuggingPriority(uiDarwinControl(g->child), NSLayoutPriorityDefaultLow, NSLayoutConstraintOrientationVertical); - } - groupRelayout(g); -} - -int uiGroupMargined(uiGroup *g) -{ - return g->margined; -} - -void uiGroupSetMargined(uiGroup *g, int margined) -{ - g->margined = margined; - singleChildConstraintsSetMargined(&(g->constraints), g->margined); -} - -uiGroup *uiNewGroup(const char *title) -{ - uiGroup *g; - - uiDarwinNewControl(uiGroup, g); - - g->box = [[NSBox alloc] initWithFrame:NSZeroRect]; - [g->box setTitle:toNSString(title)]; - [g->box setBoxType:NSBoxPrimary]; - [g->box setBorderType:NSLineBorder]; - [g->box setTransparent:NO]; - [g->box setTitlePosition:NSAtTop]; - // we can't use uiDarwinSetControlFont() because the selector is different - [g->box setTitleFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]]; - - // default to low hugging to not hug edges - g->horzHuggingPri = NSLayoutPriorityDefaultLow; - g->vertHuggingPri = NSLayoutPriorityDefaultLow; - - return g; -} diff --git a/src/libui_sdl/libui/darwin/image.m b/src/libui_sdl/libui/darwin/image.m deleted file mode 100644 index b62de31..0000000 --- a/src/libui_sdl/libui/darwin/image.m +++ /dev/null @@ -1,82 +0,0 @@ -// 25 june 2016 -#import "uipriv_darwin.h" - -struct uiImage { - NSImage *i; - NSSize size; - NSMutableArray *swizzled; -}; - -uiImage *uiNewImage(double width, double height) -{ - uiImage *i; - - i = uiNew(uiImage); - i->size = NSMakeSize(width, height); - i->i = [[NSImage alloc] initWithSize:i->size]; - i->swizzled = [NSMutableArray new]; - return i; -} - -void uiFreeImage(uiImage *i) -{ - NSValue *v; - - [i->i release]; - // to be safe, do this after releasing the image - for (v in i->swizzled) - uiFree([v pointerValue]); - [i->swizzled release]; - uiFree(i); -} - -void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, int pixelStride) -{ - NSBitmapImageRep *repCalibrated, *repsRGB; - uint8_t *swizzled, *bp, *sp; - int x, y; - unsigned char *pix[1]; - - // OS X demands that R and B are in the opposite order from what we expect - // we must swizzle :( - // LONGTERM test on a big-endian system - swizzled = (uint8_t *) uiAlloc((pixelStride * pixelHeight * 4) * sizeof (uint8_t), "uint8_t[]"); - bp = (uint8_t *) pixels; - sp = swizzled; - for (y = 0; y < pixelHeight * pixelStride; y += pixelStride) - for (x = 0; x < pixelStride; x++) { - sp[0] = bp[2]; - sp[1] = bp[1]; - sp[2] = bp[0]; - sp[3] = bp[3]; - sp += 4; - bp += 4; - } - - pix[0] = (unsigned char *) swizzled; - repCalibrated = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:pix - pixelsWide:pixelWidth - pixelsHigh:pixelHeight - bitsPerSample:8 - samplesPerPixel:4 - hasAlpha:YES - isPlanar:NO - colorSpaceName:NSCalibratedRGBColorSpace - bitmapFormat:0 - bytesPerRow:pixelStride - bitsPerPixel:32]; - repsRGB = [repCalibrated bitmapImageRepByRetaggingWithColorSpace:[NSColorSpace sRGBColorSpace]]; - [repCalibrated release]; - - [i->i addRepresentation:repsRGB]; - [repsRGB setSize:i->size]; - [repsRGB release]; - - // we need to keep swizzled alive for NSBitmapImageRep - [i->swizzled addObject:[NSValue valueWithPointer:swizzled]]; -} - -NSImage *imageImage(uiImage *i) -{ - return i->i; -} diff --git a/src/libui_sdl/libui/darwin/label.m b/src/libui_sdl/libui/darwin/label.m deleted file mode 100644 index 897bc3f..0000000 --- a/src/libui_sdl/libui/darwin/label.m +++ /dev/null @@ -1,43 +0,0 @@ -// 14 august 2015 -#import "uipriv_darwin.h" - -struct uiLabel { - uiDarwinControl c; - NSTextField *textfield; -}; - -uiDarwinControlAllDefaults(uiLabel, textfield) - -char *uiLabelText(uiLabel *l) -{ - return uiDarwinNSStringToText([l->textfield stringValue]); -} - -void uiLabelSetText(uiLabel *l, const char *text) -{ - [l->textfield setStringValue:toNSString(text)]; -} - -NSTextField *newLabel(NSString *str) -{ - NSTextField *tf; - - tf = [[NSTextField alloc] initWithFrame:NSZeroRect]; - [tf setStringValue:str]; - [tf setEditable:NO]; - [tf setSelectable:NO]; - [tf setDrawsBackground:NO]; - finishNewTextField(tf, NO); - return tf; -} - -uiLabel *uiNewLabel(const char *text) -{ - uiLabel *l; - - uiDarwinNewControl(uiLabel, l); - - l->textfield = newLabel(toNSString(text)); - - return l; -} diff --git a/src/libui_sdl/libui/darwin/main.m b/src/libui_sdl/libui/darwin/main.m deleted file mode 100644 index 59a8683..0000000 --- a/src/libui_sdl/libui/darwin/main.m +++ /dev/null @@ -1,239 +0,0 @@ -// 6 april 2015 -#import "uipriv_darwin.h" - -static BOOL canQuit = NO; -static NSAutoreleasePool *globalPool; -static applicationClass *app; -static appDelegate *delegate; - -static BOOL (^isRunning)(void); -static BOOL stepsIsRunning; - -@implementation applicationClass - -- (void)sendEvent:(NSEvent *)e -{ - if (sendAreaEvents(e) != 0) - return; - [super sendEvent:e]; -} - -// NSColorPanel always sends changeColor: to the first responder regardless of whether there's a target set on it -// we can override it here (see colorbutton.m) -// thanks to mikeash in irc.freenode.net/#macdev for informing me this is how the first responder chain is initiated -// it turns out NSFontManager also sends changeFont: through this; let's inhibit that here too (see fontbutton.m) -- (BOOL)sendAction:(SEL)sel to:(id)to from:(id)from -{ - if (colorButtonInhibitSendAction(sel, from, to)) - return NO; - if (fontButtonInhibitSendAction(sel, from, to)) - return NO; - return [super sendAction:sel to:to from:from]; -} - -// likewise, NSFontManager also sends NSFontPanelValidation messages to the first responder, however it does NOT use sendAction:from:to:! -// instead, it uses this one (thanks swillits in irc.freenode.net/#macdev) -// we also need to override it (see fontbutton.m) -- (id)targetForAction:(SEL)sel to:(id)to from:(id)from -{ - id override; - - if (fontButtonOverrideTargetForAction(sel, from, to, &override)) - return override; - return [super targetForAction:sel to:to from:from]; -} - -// hey look! we're overriding terminate:! -// we're going to make sure we can go back to main() whether Cocoa likes it or not! -// and just how are we going to do that, hm? -// (note: this is called after applicationShouldTerminate:) -- (void)terminate:(id)sender -{ - // yes that's right folks: DO ABSOLUTELY NOTHING. - // the magic is [NSApp run] will just... stop. - - // well let's not do nothing; let's actually quit our graceful way - NSEvent *e; - - if (!canQuit) - implbug("call to [NSApp terminate:] when not ready to terminate; definitely contact andlabs"); - - [realNSApp() stop:realNSApp()]; - // stop: won't register until another event has passed; let's synthesize one - e = [NSEvent otherEventWithType:NSApplicationDefined - location:NSZeroPoint - modifierFlags:0 - timestamp:[[NSProcessInfo processInfo] systemUptime] - windowNumber:0 - context:[NSGraphicsContext currentContext] - subtype:0 - data1:0 - data2:0]; - [realNSApp() postEvent:e atStart:NO]; // let pending events take priority (this is what PostQuitMessage() on Windows does so we have to do it here too for parity; thanks to mikeash in irc.freenode.net/#macdev for confirming that this parameter should indeed be NO) - - // and in case uiMainSteps() was called - stepsIsRunning = NO; -} - -@end - -@implementation appDelegate - -- (void)dealloc -{ - // Apple docs: "Don't Use Accessor Methods in Initializer Methods and dealloc" - [_menuManager release]; - [super dealloc]; -} - -- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)app -{ - // for debugging - NSLog(@"in applicationShouldTerminate:"); - if (shouldQuit()) { - canQuit = YES; - // this will call terminate:, which is the same as uiQuit() - return NSTerminateNow; - } - return NSTerminateCancel; -} - -- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)app -{ - return NO; -} - -@end - -uiInitOptions options; - -const char *uiInit(uiInitOptions *o) -{ - @autoreleasepool { - options = *o; - app = [[applicationClass sharedApplication] retain]; - // don't check for a NO return; something (launch services?) causes running from application bundles to always return NO when asking to change activation policy, even if the change is to the same activation policy! - // see https://github.com/andlabs/ui/issues/6 - [realNSApp() setActivationPolicy:NSApplicationActivationPolicyRegular]; - delegate = [appDelegate new]; - [realNSApp() setDelegate:delegate]; - - initAlloc(); - - // always do this so we always have an application menu - appDelegate().menuManager = [[menuManager new] autorelease]; - [realNSApp() setMainMenu:[appDelegate().menuManager makeMenubar]]; - - setupFontPanel(); - } - - globalPool = [[NSAutoreleasePool alloc] init]; - - return NULL; -} - -void uiUninit(void) -{ - if (!globalPool) { - userbug("You must call uiInit() first!"); - } - [globalPool release]; - - @autoreleasepool { - [delegate release]; - [realNSApp() setDelegate:nil]; - [app release]; - uninitAlloc(); - } -} - -void uiFreeInitError(const char *err) -{ -} - -void uiMain(void) -{ - isRunning = ^{ - return [realNSApp() isRunning]; - }; - [realNSApp() run]; -} - -void uiMainSteps(void) -{ - // SDL does this and it seems to be necessary for the menubar to work (see #182) - [realNSApp() finishLaunching]; - isRunning = ^{ - return stepsIsRunning; - }; - stepsIsRunning = YES; -} - -int uiMainStep(int wait) -{ - struct nextEventArgs nea; - - nea.mask = NSAnyEventMask; - - // ProPuke did this in his original PR requesting this - // I'm not sure if this will work, but I assume it will... - nea.duration = [NSDate distantPast]; - if (wait) // but this is normal so it will work - nea.duration = [NSDate distantFuture]; - - nea.mode = NSDefaultRunLoopMode; - nea.dequeue = YES; - - return mainStep(&nea, ^(NSEvent *e) { - return NO; - }); -} - -// see also: -// - http://www.cocoawithlove.com/2009/01/demystifying-nsapplication-by.html -// - https://github.com/gnustep/gui/blob/master/Source/NSApplication.m -int mainStep(struct nextEventArgs *nea, BOOL (^interceptEvent)(NSEvent *e)) -{ - NSDate *expire; - NSEvent *e; - NSEventType type; - - @autoreleasepool { - if (!isRunning()) - return 0; - - e = [realNSApp() nextEventMatchingMask:nea->mask - untilDate:nea->duration - inMode:nea->mode - dequeue:nea->dequeue]; - if (e == nil) - return 1; - - type = [e type]; - if (!interceptEvent(e)) - [realNSApp() sendEvent:e]; - [realNSApp() updateWindows]; - - // GNUstep does this - // it also updates the Services menu but there doesn't seem to be a public API for that so - if (type != NSPeriodic && type != NSMouseMoved) - [[realNSApp() mainMenu] update]; - - return 1; - } -} - -void uiQuit(void) -{ - canQuit = YES; - [realNSApp() terminate:realNSApp()]; -} - -// thanks to mikeash in irc.freenode.net/#macdev for suggesting the use of Grand Central Dispatch for this -// LONGTERM will dispatch_get_main_queue() break after _CFRunLoopSetCurrent()? -void uiQueueMain(void (*f)(void *data), void *data) -{ - // dispatch_get_main_queue() is a serial queue so it will not execute multiple uiQueueMain() functions concurrently - // the signature of f matches dispatch_function_t - dispatch_async_f(dispatch_get_main_queue(), data, f); -} diff --git a/src/libui_sdl/libui/darwin/map.m b/src/libui_sdl/libui/darwin/map.m deleted file mode 100644 index 46a7b8d..0000000 --- a/src/libui_sdl/libui/darwin/map.m +++ /dev/null @@ -1,59 +0,0 @@ -// 17 august 2015 -#import "uipriv_darwin.h" - -// unfortunately NSMutableDictionary copies its keys, meaning we can't use it for pointers -// hence, this file -// we could expose a NSMapTable directly, but let's treat all pointers as opaque and hide the implementation, just to be safe and prevent even more rewrites later -struct mapTable { - NSMapTable *m; -}; - -struct mapTable *newMap(void) -{ - struct mapTable *m; - - m = uiNew(struct mapTable); - m->m = [[NSMapTable alloc] initWithKeyOptions:(NSPointerFunctionsOpaqueMemory | NSPointerFunctionsOpaquePersonality) - valueOptions:(NSPointerFunctionsOpaqueMemory | NSPointerFunctionsOpaquePersonality) - capacity:0]; - return m; -} - -void mapDestroy(struct mapTable *m) -{ - if ([m->m count] != 0) - implbug("attempt to destroy map with items inside"); - [m->m release]; - uiFree(m); -} - -void *mapGet(struct mapTable *m, void *key) -{ - return NSMapGet(m->m, key); -} - -void mapSet(struct mapTable *m, void *key, void *value) -{ - NSMapInsert(m->m, key, value); -} - -void mapDelete(struct mapTable *m, void *key) -{ - NSMapRemove(m->m, key); -} - -void mapWalk(struct mapTable *m, void (*f)(void *key, void *value)) -{ - NSMapEnumerator e = NSEnumerateMapTable(m->m); - void *k = NULL; - void *v = NULL; - while (NSNextMapEnumeratorPair(&e, &k, &v)) { - f(k, v); - } - NSEndMapTableEnumeration(&e); -} - -void mapReset(struct mapTable *m) -{ - NSResetMapTable(m->m); -} diff --git a/src/libui_sdl/libui/darwin/menu.m b/src/libui_sdl/libui/darwin/menu.m deleted file mode 100644 index 735cac5..0000000 --- a/src/libui_sdl/libui/darwin/menu.m +++ /dev/null @@ -1,368 +0,0 @@ -// 28 april 2015 -#import "uipriv_darwin.h" - -static NSMutableArray *menus = nil; -static BOOL menusFinalized = NO; - -struct uiMenu { - NSMenu *menu; - NSMenuItem *item; - NSMutableArray *items; -}; - -struct uiMenuItem { - NSMenuItem *item; - int type; - BOOL disabled; - void (*onClicked)(uiMenuItem *, uiWindow *, void *); - void *onClickedData; -}; - -enum { - typeRegular, - typeCheckbox, - typeQuit, - typePreferences, - typeAbout, - typeSeparator, -}; - -static void mapItemReleaser(void *key, void *value) -{ - uiMenuItem *item; - - item = (uiMenuItem *)value; - [item->item release]; -} - -@implementation menuManager - -- (id)init -{ - self = [super init]; - if (self) { - self->items = newMap(); - self->hasQuit = NO; - self->hasPreferences = NO; - self->hasAbout = NO; - } - return self; -} - -- (void)dealloc -{ - mapWalk(self->items, mapItemReleaser); - mapReset(self->items); - mapDestroy(self->items); - uninitMenus(); - [super dealloc]; -} - -- (IBAction)onClicked:(id)sender -{ - uiMenuItem *item; - - item = (uiMenuItem *) mapGet(self->items, sender); - if (item->type == typeCheckbox) - uiMenuItemSetChecked(item, !uiMenuItemChecked(item)); - // use the key window as the source of the menu event; it's the active window - (*(item->onClicked))(item, windowFromNSWindow([realNSApp() keyWindow]), item->onClickedData); -} - -- (IBAction)onQuitClicked:(id)sender -{ - if (shouldQuit()) - uiQuit(); -} - -- (void)register:(NSMenuItem *)item to:(uiMenuItem *)smi -{ - switch (smi->type) { - case typeQuit: - if (self->hasQuit) - userbug("You can't have multiple Quit menu items in one program."); - self->hasQuit = YES; - break; - case typePreferences: - if (self->hasPreferences) - userbug("You can't have multiple Preferences menu items in one program."); - self->hasPreferences = YES; - break; - case typeAbout: - if (self->hasAbout) - userbug("You can't have multiple About menu items in one program."); - self->hasAbout = YES; - break; - } - mapSet(self->items, item, smi); -} - -// on OS X there are two ways to handle menu items being enabled or disabled: automatically and manually -// unfortunately, the application menu requires automatic menu handling for the Hide, Hide Others, and Show All items to work correctly -// therefore, we have to handle enabling of the other options ourselves -- (BOOL)validateMenuItem:(NSMenuItem *)item -{ - uiMenuItem *smi; - - // disable the special items if they aren't present - if (item == self.quitItem && !self->hasQuit) - return NO; - if (item == self.preferencesItem && !self->hasPreferences) - return NO; - if (item == self.aboutItem && !self->hasAbout) - return NO; - // then poll the item's enabled/disabled state - smi = (uiMenuItem *) mapGet(self->items, item); - return !smi->disabled; -} - -// Cocoa constructs the default application menu by hand for each program; that's what MainMenu.[nx]ib does -- (void)buildApplicationMenu:(NSMenu *)menubar -{ - NSString *appName; - NSMenuItem *appMenuItem; - NSMenu *appMenu; - NSMenuItem *item; - NSString *title; - NSMenu *servicesMenu; - - // note: no need to call setAppleMenu: on this anymore; see https://developer.apple.com/library/mac/releasenotes/AppKit/RN-AppKitOlderNotes/#X10_6Notes - appName = [[NSProcessInfo processInfo] processName]; - appMenuItem = [[[NSMenuItem alloc] initWithTitle:appName action:NULL keyEquivalent:@""] autorelease]; - appMenu = [[[NSMenu alloc] initWithTitle:appName] autorelease]; - [appMenuItem setSubmenu:appMenu]; - [menubar addItem:appMenuItem]; - - // first is About - title = [@"About " stringByAppendingString:appName]; - item = [[[NSMenuItem alloc] initWithTitle:title action:@selector(onClicked:) keyEquivalent:@""] autorelease]; - [item setTarget:self]; - [appMenu addItem:item]; - self.aboutItem = item; - - [appMenu addItem:[NSMenuItem separatorItem]]; - - // next is Preferences - item = [[[NSMenuItem alloc] initWithTitle:@"Preferences…" action:@selector(onClicked:) keyEquivalent:@","] autorelease]; - [item setTarget:self]; - [appMenu addItem:item]; - self.preferencesItem = item; - - [appMenu addItem:[NSMenuItem separatorItem]]; - - // next is Services - item = [[[NSMenuItem alloc] initWithTitle:@"Services" action:NULL keyEquivalent:@""] autorelease]; - servicesMenu = [[[NSMenu alloc] initWithTitle:@"Services"] autorelease]; - [item setSubmenu:servicesMenu]; - [realNSApp() setServicesMenu:servicesMenu]; - [appMenu addItem:item]; - - [appMenu addItem:[NSMenuItem separatorItem]]; - - // next are the three hiding options - title = [@"Hide " stringByAppendingString:appName]; - item = [[[NSMenuItem alloc] initWithTitle:title action:@selector(hide:) keyEquivalent:@"h"] autorelease]; - // the .xib file says they go to -1 ("First Responder", which sounds wrong...) - // to do that, we simply leave the target as nil - [appMenu addItem:item]; - item = [[[NSMenuItem alloc] initWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"] autorelease]; - [item setKeyEquivalentModifierMask:(NSAlternateKeyMask | NSCommandKeyMask)]; - [appMenu addItem:item]; - item = [[[NSMenuItem alloc] initWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""] autorelease]; - [appMenu addItem:item]; - - [appMenu addItem:[NSMenuItem separatorItem]]; - - // and finally Quit - // DON'T use @selector(terminate:) as the action; we handle termination ourselves - title = [@"Quit " stringByAppendingString:appName]; - item = [[[NSMenuItem alloc] initWithTitle:title action:@selector(onQuitClicked:) keyEquivalent:@"q"] autorelease]; - [item setTarget:self]; - [appMenu addItem:item]; - self.quitItem = item; -} - -- (NSMenu *)makeMenubar -{ - NSMenu *menubar; - - menubar = [[[NSMenu alloc] initWithTitle:@""] autorelease]; - [self buildApplicationMenu:menubar]; - return menubar; -} - -@end - -static void defaultOnClicked(uiMenuItem *item, uiWindow *w, void *data) -{ - // do nothing -} - -void uiMenuItemEnable(uiMenuItem *item) -{ - item->disabled = NO; - // we don't need to explicitly update the menus here; they'll be updated the next time they're opened (thanks mikeash in irc.freenode.net/#macdev) -} - -void uiMenuItemDisable(uiMenuItem *item) -{ - item->disabled = YES; -} - -void uiMenuItemOnClicked(uiMenuItem *item, void (*f)(uiMenuItem *, uiWindow *, void *), void *data) -{ - if (item->type == typeQuit) - userbug("You can't call uiMenuItemOnClicked() on a Quit item; use uiOnShouldQuit() instead."); - item->onClicked = f; - item->onClickedData = data; -} - -int uiMenuItemChecked(uiMenuItem *item) -{ - return [item->item state] != NSOffState; -} - -void uiMenuItemSetChecked(uiMenuItem *item, int checked) -{ - NSInteger state; - - state = NSOffState; - if ([item->item state] == NSOffState) - state = NSOnState; - [item->item setState:state]; -} - -static uiMenuItem *newItem(uiMenu *m, int type, const char *name) -{ - @autoreleasepool { - - uiMenuItem *item; - - if (menusFinalized) - userbug("You can't create a new menu item after menus have been finalized."); - - item = uiNew(uiMenuItem); - - item->type = type; - switch (item->type) { - case typeQuit: - item->item = [appDelegate().menuManager.quitItem retain]; - break; - case typePreferences: - item->item = [appDelegate().menuManager.preferencesItem retain]; - break; - case typeAbout: - item->item = [appDelegate().menuManager.aboutItem retain]; - break; - case typeSeparator: - item->item = [[NSMenuItem separatorItem] retain]; - [m->menu addItem:item->item]; - break; - default: - item->item = [[NSMenuItem alloc] initWithTitle:toNSString(name) action:@selector(onClicked:) keyEquivalent:@""]; - [item->item setTarget:appDelegate().menuManager]; - [m->menu addItem:item->item]; - break; - } - - [appDelegate().menuManager register:item->item to:item]; - item->onClicked = defaultOnClicked; - - [m->items addObject:[NSValue valueWithPointer:item]]; - - return item; - - } // @autoreleasepool -} - -uiMenuItem *uiMenuAppendItem(uiMenu *m, const char *name) -{ - return newItem(m, typeRegular, name); -} - -uiMenuItem *uiMenuAppendCheckItem(uiMenu *m, const char *name) -{ - return newItem(m, typeCheckbox, name); -} - -uiMenuItem *uiMenuAppendQuitItem(uiMenu *m) -{ - // duplicate check is in the register:to: selector - return newItem(m, typeQuit, NULL); -} - -uiMenuItem *uiMenuAppendPreferencesItem(uiMenu *m) -{ - // duplicate check is in the register:to: selector - return newItem(m, typePreferences, NULL); -} - -uiMenuItem *uiMenuAppendAboutItem(uiMenu *m) -{ - // duplicate check is in the register:to: selector - return newItem(m, typeAbout, NULL); -} - -void uiMenuAppendSeparator(uiMenu *m) -{ - newItem(m, typeSeparator, NULL); -} - -uiMenu *uiNewMenu(const char *name) -{ - @autoreleasepool { - - uiMenu *m; - - if (menusFinalized) - userbug("You can't create a new menu after menus have been finalized."); - if (menus == nil) - menus = [NSMutableArray new]; - - m = uiNew(uiMenu); - - m->menu = [[NSMenu alloc] initWithTitle:toNSString(name)]; - // use automatic menu item enabling for all menus for consistency's sake - - m->item = [[NSMenuItem alloc] initWithTitle:toNSString(name) action:NULL keyEquivalent:@""]; - [m->item setSubmenu:m->menu]; - - m->items = [NSMutableArray new]; - - [[realNSApp() mainMenu] addItem:m->item]; - - [menus addObject:[NSValue valueWithPointer:m]]; - - return m; - - } // @autoreleasepool -} - -void finalizeMenus(void) -{ - menusFinalized = YES; -} - -void uninitMenus(void) -{ - if (menus == NULL) - return; - [menus enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) { - NSValue *v; - uiMenu *m; - - v = (NSValue *) obj; - m = (uiMenu *) [v pointerValue]; - [m->items enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) { - NSValue *v; - uiMenuItem *mi; - - v = (NSValue *) obj; - mi = (uiMenuItem *) [v pointerValue]; - uiFree(mi); - }]; - [m->items release]; - uiFree(m); - }]; - [menus release]; -} diff --git a/src/libui_sdl/libui/darwin/multilineentry.m b/src/libui_sdl/libui/darwin/multilineentry.m deleted file mode 100644 index 605e900..0000000 --- a/src/libui_sdl/libui/darwin/multilineentry.m +++ /dev/null @@ -1,233 +0,0 @@ -// 8 december 2015 -#import "uipriv_darwin.h" - -// NSTextView has no intrinsic content size by default, which wreaks havoc on a pure-Auto Layout system -// we'll have to take over to get it to work -// see also http://stackoverflow.com/questions/24210153/nstextview-not-properly-resizing-with-auto-layout and http://stackoverflow.com/questions/11237622/using-autolayout-with-expanding-nstextviews -@interface intrinsicSizeTextView : NSTextView { - uiMultilineEntry *libui_e; -} -- (id)initWithFrame:(NSRect)r e:(uiMultilineEntry *)e; -@end - -struct uiMultilineEntry { - uiDarwinControl c; - NSScrollView *sv; - intrinsicSizeTextView *tv; - struct scrollViewData *d; - void (*onChanged)(uiMultilineEntry *, void *); - void *onChangedData; - BOOL changing; -}; - -@implementation intrinsicSizeTextView - -- (id)initWithFrame:(NSRect)r e:(uiMultilineEntry *)e -{ - self = [super initWithFrame:r]; - if (self) - self->libui_e = e; - return self; -} - -- (NSSize)intrinsicContentSize -{ - NSTextContainer *textContainer; - NSLayoutManager *layoutManager; - NSRect rect; - - textContainer = [self textContainer]; - layoutManager = [self layoutManager]; - [layoutManager ensureLayoutForTextContainer:textContainer]; - rect = [layoutManager usedRectForTextContainer:textContainer]; - return rect.size; -} - -- (void)didChangeText -{ - [super didChangeText]; - [self invalidateIntrinsicContentSize]; - if (!self->libui_e->changing) - (*(self->libui_e->onChanged))(self->libui_e, self->libui_e->onChangedData); -} - -@end - -uiDarwinControlAllDefaultsExceptDestroy(uiMultilineEntry, sv) - -static void uiMultilineEntryDestroy(uiControl *c) -{ - uiMultilineEntry *e = uiMultilineEntry(c); - - scrollViewFreeData(e->sv, e->d); - [e->tv release]; - [e->sv release]; - uiFreeControl(uiControl(e)); -} - -static void defaultOnChanged(uiMultilineEntry *e, void *data) -{ - // do nothing -} - -char *uiMultilineEntryText(uiMultilineEntry *e) -{ - return uiDarwinNSStringToText([e->tv string]); -} - -void uiMultilineEntrySetText(uiMultilineEntry *e, const char *text) -{ - [[e->tv textStorage] replaceCharactersInRange:NSMakeRange(0, [[e->tv string] length]) - withString:toNSString(text)]; - // must be called explicitly according to the documentation of shouldChangeTextInRange:replacementString: - e->changing = YES; - [e->tv didChangeText]; - e->changing = NO; -} - -// TODO scroll to end? -void uiMultilineEntryAppend(uiMultilineEntry *e, const char *text) -{ - [[e->tv textStorage] replaceCharactersInRange:NSMakeRange([[e->tv string] length], 0) - withString:toNSString(text)]; - e->changing = YES; - [e->tv didChangeText]; - e->changing = NO; -} - -void uiMultilineEntryOnChanged(uiMultilineEntry *e, void (*f)(uiMultilineEntry *e, void *data), void *data) -{ - e->onChanged = f; - e->onChangedData = data; -} - -int uiMultilineEntryReadOnly(uiMultilineEntry *e) -{ - return [e->tv isEditable] == NO; -} - -void uiMultilineEntrySetReadOnly(uiMultilineEntry *e, int readonly) -{ - BOOL editable; - - editable = YES; - if (readonly) - editable = NO; - [e->tv setEditable:editable]; -} - -static uiMultilineEntry *finishMultilineEntry(BOOL hscroll) -{ - uiMultilineEntry *e; - NSFont *font; - struct scrollViewCreateParams p; - - uiDarwinNewControl(uiMultilineEntry, e); - - e->tv = [[intrinsicSizeTextView alloc] initWithFrame:NSZeroRect e:e]; - - // verified against Interface Builder for a sufficiently customized text view - - // NSText properties: - // this is what Interface Builder sets the background color to - [e->tv setBackgroundColor:[NSColor colorWithCalibratedWhite:1.0 alpha:1.0]]; - [e->tv setDrawsBackground:YES]; - [e->tv setEditable:YES]; - [e->tv setSelectable:YES]; - [e->tv setFieldEditor:NO]; - [e->tv setRichText:NO]; - [e->tv setImportsGraphics:NO]; - [e->tv setUsesFontPanel:NO]; - [e->tv setRulerVisible:NO]; - // we'll handle font last - // while setAlignment: has been around since 10.0, the named constant "NSTextAlignmentNatural" seems to have only been introduced in 10.11 -#define ourNSTextAlignmentNatural 4 - [e->tv setAlignment:ourNSTextAlignmentNatural]; - // textColor is set to nil, just keep the dfault - [e->tv setBaseWritingDirection:NSWritingDirectionNatural]; - [e->tv setHorizontallyResizable:NO]; - [e->tv setVerticallyResizable:YES]; - - // NSTextView properties: - [e->tv setAllowsDocumentBackgroundColorChange:NO]; - [e->tv setAllowsUndo:YES]; - // default paragraph style is nil; keep default - [e->tv setAllowsImageEditing:NO]; - [e->tv setAutomaticQuoteSubstitutionEnabled:NO]; - [e->tv setAutomaticLinkDetectionEnabled:NO]; - [e->tv setDisplaysLinkToolTips:YES]; - [e->tv setUsesRuler:NO]; - [e->tv setUsesInspectorBar:NO]; - [e->tv setSelectionGranularity:NSSelectByCharacter]; - // there is a dedicated named insertion point color but oh well - [e->tv setInsertionPointColor:[NSColor controlTextColor]]; - // typing attributes is nil; keep default (we change it below for fonts though) - [e->tv setSmartInsertDeleteEnabled:NO]; - [e->tv setContinuousSpellCheckingEnabled:NO]; - [e->tv setGrammarCheckingEnabled:NO]; - [e->tv setUsesFindPanel:YES]; - [e->tv setEnabledTextCheckingTypes:0]; - [e->tv setAutomaticDashSubstitutionEnabled:NO]; - [e->tv setAutomaticDataDetectionEnabled:NO]; - [e->tv setAutomaticSpellingCorrectionEnabled:NO]; - [e->tv setAutomaticTextReplacementEnabled:NO]; - [e->tv setUsesFindBar:NO]; - [e->tv setIncrementalSearchingEnabled:NO]; - - // NSTextContainer properties: - [[e->tv textContainer] setWidthTracksTextView:YES]; - [[e->tv textContainer] setHeightTracksTextView:NO]; - - // NSLayoutManager properties: - [[e->tv layoutManager] setAllowsNonContiguousLayout:YES]; - - // now just to be safe; this will do some of the above but whatever - disableAutocorrect(e->tv); - - // see https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/TextUILayer/Tasks/TextInScrollView.html - // notice we don't use the Auto Layout code; see scrollview.m for more details - [e->tv setMaxSize:NSMakeSize(CGFLOAT_MAX, CGFLOAT_MAX)]; - [e->tv setVerticallyResizable:YES]; - [e->tv setHorizontallyResizable:hscroll]; - if (hscroll) { - [e->tv setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)]; - [[e->tv textContainer] setWidthTracksTextView:NO]; - } else { - [e->tv setAutoresizingMask:NSViewWidthSizable]; - [[e->tv textContainer] setWidthTracksTextView:YES]; - } - [[e->tv textContainer] setContainerSize:NSMakeSize(CGFLOAT_MAX, CGFLOAT_MAX)]; - - // don't use uiDarwinSetControlFont() directly; we have to do a little extra work to set the font - font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]]; - [e->tv setTypingAttributes:[NSDictionary - dictionaryWithObject:font - forKey:NSFontAttributeName]]; - // e->tv font from Interface Builder is nil, but setFont:nil throws an exception - // let's just set it to the standard control font anyway, just to be safe - [e->tv setFont:font]; - - memset(&p, 0, sizeof (struct scrollViewCreateParams)); - p.DocumentView = e->tv; - // this is what Interface Builder sets it to - p.BackgroundColor = [NSColor colorWithCalibratedWhite:1.0 alpha:1.0]; - p.DrawsBackground = YES; - p.Bordered = YES; - p.HScroll = hscroll; - p.VScroll = YES; - e->sv = mkScrollView(&p, &(e->d)); - - uiMultilineEntryOnChanged(e, defaultOnChanged, NULL); - - return e; -} - -uiMultilineEntry *uiNewMultilineEntry(void) -{ - return finishMultilineEntry(NO); -} - -uiMultilineEntry *uiNewNonWrappingMultilineEntry(void) -{ - return finishMultilineEntry(YES); -} diff --git a/src/libui_sdl/libui/darwin/progressbar.m b/src/libui_sdl/libui/darwin/progressbar.m deleted file mode 100644 index b538228..0000000 --- a/src/libui_sdl/libui/darwin/progressbar.m +++ /dev/null @@ -1,78 +0,0 @@ -// 14 august 2015 -#import "uipriv_darwin.h" - -// NSProgressIndicator has no intrinsic width by default; use the default width in Interface Builder -#define progressIndicatorWidth 100 - -@interface intrinsicWidthNSProgressIndicator : NSProgressIndicator -@end - -@implementation intrinsicWidthNSProgressIndicator - -- (NSSize)intrinsicContentSize -{ - NSSize s; - - s = [super intrinsicContentSize]; - s.width = progressIndicatorWidth; - return s; -} - -@end - -struct uiProgressBar { - uiDarwinControl c; - NSProgressIndicator *pi; -}; - -uiDarwinControlAllDefaults(uiProgressBar, pi) - -int uiProgressBarValue(uiProgressBar *p) -{ - if ([p->pi isIndeterminate]) - return -1; - return [p->pi doubleValue]; -} - -void uiProgressBarSetValue(uiProgressBar *p, int value) -{ - if (value == -1) { - [p->pi setIndeterminate:YES]; - [p->pi startAnimation:p->pi]; - return; - } - - if ([p->pi isIndeterminate]) { - [p->pi setIndeterminate:NO]; - [p->pi stopAnimation:p->pi]; - } - - if (value < 0 || value > 100) - userbug("Value %d out of range for a uiProgressBar.", value); - - // on 10.8 there's an animation when the progress bar increases, just like with Aero - if (value == 100) { - [p->pi setMaxValue:101]; - [p->pi setDoubleValue:101]; - [p->pi setDoubleValue:100]; - [p->pi setMaxValue:100]; - return; - } - [p->pi setDoubleValue:((double) (value + 1))]; - [p->pi setDoubleValue:((double) value)]; -} - -uiProgressBar *uiNewProgressBar(void) -{ - uiProgressBar *p; - - uiDarwinNewControl(uiProgressBar, p); - - p->pi = [[intrinsicWidthNSProgressIndicator alloc] initWithFrame:NSZeroRect]; - [p->pi setControlSize:NSRegularControlSize]; - [p->pi setBezeled:YES]; - [p->pi setStyle:NSProgressIndicatorBarStyle]; - [p->pi setIndeterminate:NO]; - - return p; -} diff --git a/src/libui_sdl/libui/darwin/radiobuttons.m b/src/libui_sdl/libui/darwin/radiobuttons.m deleted file mode 100644 index 25d773c..0000000 --- a/src/libui_sdl/libui/darwin/radiobuttons.m +++ /dev/null @@ -1,207 +0,0 @@ -// 14 august 2015 -#import "uipriv_darwin.h" - -// TODO resizing the controlgallery vertically causes the third button to still resize :| - -// In the old days you would use a NSMatrix for this; as of OS X 10.8 this was deprecated and now you need just a bunch of NSButtons with the same superview AND same action method. -// This is documented on the NSMatrix page, but the rest of the OS X documentation says to still use NSMatrix. -// NSMatrix has weird quirks anyway... - -// LONGTERM 6 units of spacing between buttons, as suggested by Interface Builder? - -@interface radioButtonsDelegate : NSObject { - uiRadioButtons *libui_r; -} -- (id)initWithR:(uiRadioButtons *)r; -- (IBAction)onClicked:(id)sender; -@end - -struct uiRadioButtons { - uiDarwinControl c; - NSView *view; - NSMutableArray *buttons; - NSMutableArray *constraints; - NSLayoutConstraint *lastv; - radioButtonsDelegate *delegate; - void (*onSelected)(uiRadioButtons *, void *); - void *onSelectedData; -}; - -@implementation radioButtonsDelegate - -- (id)initWithR:(uiRadioButtons *)r -{ - self = [super init]; - if (self) - self->libui_r = r; - return self; -} - -- (IBAction)onClicked:(id)sender -{ - uiRadioButtons *r = self->libui_r; - - (*(r->onSelected))(r, r->onSelectedData); -} - -@end - -uiDarwinControlAllDefaultsExceptDestroy(uiRadioButtons, view) - -static void defaultOnSelected(uiRadioButtons *r, void *data) -{ - // do nothing -} - -static void uiRadioButtonsDestroy(uiControl *c) -{ - uiRadioButtons *r = uiRadioButtons(c); - NSButton *b; - - // drop the constraints - [r->view removeConstraints:r->constraints]; - [r->constraints release]; - if (r->lastv != nil) - [r->lastv release]; - // destroy the buttons - for (b in r->buttons) { - [b setTarget:nil]; - [b removeFromSuperview]; - } - [r->buttons release]; - // destroy the delegate - [r->delegate release]; - // and destroy ourselves - [r->view release]; - uiFreeControl(uiControl(r)); -} - -static NSButton *buttonAt(uiRadioButtons *r, int n) -{ - return (NSButton *) [r->buttons objectAtIndex:n]; -} - -void uiRadioButtonsAppend(uiRadioButtons *r, const char *text) -{ - NSButton *b, *b2; - NSLayoutConstraint *constraint; - - b = [[NSButton alloc] initWithFrame:NSZeroRect]; - [b setTitle:toNSString(text)]; - [b setButtonType:NSRadioButton]; - // doesn't seem to have an associated bezel style - [b setBordered:NO]; - [b setTransparent:NO]; - uiDarwinSetControlFont(b, NSRegularControlSize); - [b setTranslatesAutoresizingMaskIntoConstraints:NO]; - - [b setTarget:r->delegate]; - [b setAction:@selector(onClicked:)]; - - [r->buttons addObject:b]; - [r->view addSubview:b]; - - // pin horizontally to the edges of the superview - constraint = mkConstraint(b, NSLayoutAttributeLeading, - NSLayoutRelationEqual, - r->view, NSLayoutAttributeLeading, - 1, 0, - @"uiRadioButtons button leading constraint"); - [r->view addConstraint:constraint]; - [r->constraints addObject:constraint]; - constraint = mkConstraint(b, NSLayoutAttributeTrailing, - NSLayoutRelationEqual, - r->view, NSLayoutAttributeTrailing, - 1, 0, - @"uiRadioButtons button trailing constraint"); - [r->view addConstraint:constraint]; - [r->constraints addObject:constraint]; - - // if this is the first view, pin it to the top - // otherwise pin to the bottom of the last - if ([r->buttons count] == 1) - constraint = mkConstraint(b, NSLayoutAttributeTop, - NSLayoutRelationEqual, - r->view, NSLayoutAttributeTop, - 1, 0, - @"uiRadioButtons first button top constraint"); - else { - b2 = buttonAt(r, [r->buttons count] - 2); - constraint = mkConstraint(b, NSLayoutAttributeTop, - NSLayoutRelationEqual, - b2, NSLayoutAttributeBottom, - 1, 0, - @"uiRadioButtons non-first button top constraint"); - } - [r->view addConstraint:constraint]; - [r->constraints addObject:constraint]; - - // if there is a previous bottom constraint, remove it - if (r->lastv != nil) { - [r->view removeConstraint:r->lastv]; - [r->constraints removeObject:r->lastv]; - [r->lastv release]; - } - - // and make the new bottom constraint - r->lastv = mkConstraint(b, NSLayoutAttributeBottom, - NSLayoutRelationEqual, - r->view, NSLayoutAttributeBottom, - 1, 0, - @"uiRadioButtons last button bottom constraint"); - [r->view addConstraint:r->lastv]; - [r->constraints addObject:r->lastv]; - [r->lastv retain]; -} - -int uiRadioButtonsSelected(uiRadioButtons *r) -{ - NSButton *b; - NSUInteger i; - - for (i = 0; i < [r->buttons count]; i++) { - b = (NSButton *) [r->buttons objectAtIndex:i]; - if ([b state] == NSOnState) - return i; - } - return -1; -} - -void uiRadioButtonsSetSelected(uiRadioButtons *r, int n) -{ - NSButton *b; - NSInteger state; - - state = NSOnState; - if (n == -1) { - n = uiRadioButtonsSelected(r); - if (n == -1) // from nothing to nothing; do nothing - return; - state = NSOffState; - } - b = (NSButton *) [r->buttons objectAtIndex:n]; - [b setState:state]; -} - -void uiRadioButtonsOnSelected(uiRadioButtons *r, void (*f)(uiRadioButtons *, void *), void *data) -{ - r->onSelected = f; - r->onSelectedData = data; -} - -uiRadioButtons *uiNewRadioButtons(void) -{ - uiRadioButtons *r; - - uiDarwinNewControl(uiRadioButtons, r); - - r->view = [[NSView alloc] initWithFrame:NSZeroRect]; - r->buttons = [NSMutableArray new]; - r->constraints = [NSMutableArray new]; - - r->delegate = [[radioButtonsDelegate alloc] initWithR:r]; - - uiRadioButtonsOnSelected(r, defaultOnSelected, NULL); - - return r; -} diff --git a/src/libui_sdl/libui/darwin/scrollview.m b/src/libui_sdl/libui/darwin/scrollview.m deleted file mode 100644 index b0b4040..0000000 --- a/src/libui_sdl/libui/darwin/scrollview.m +++ /dev/null @@ -1,61 +0,0 @@ -// 27 may 2016 -#include "uipriv_darwin.h" - -// see http://stackoverflow.com/questions/37979445/how-do-i-properly-set-up-a-scrolling-nstableview-using-auto-layout-what-ive-tr for why we don't use auto layout -// TODO do the same with uiGroup and uiTab? - -struct scrollViewData { - BOOL hscroll; - BOOL vscroll; -}; - -NSScrollView *mkScrollView(struct scrollViewCreateParams *p, struct scrollViewData **dout) -{ - NSScrollView *sv; - NSBorderType border; - struct scrollViewData *d; - - sv = [[NSScrollView alloc] initWithFrame:NSZeroRect]; - if (p->BackgroundColor != nil) - [sv setBackgroundColor:p->BackgroundColor]; - [sv setDrawsBackground:p->DrawsBackground]; - border = NSNoBorder; - if (p->Bordered) - border = NSBezelBorder; - // document view seems to set the cursor properly - [sv setBorderType:border]; - [sv setAutohidesScrollers:YES]; - [sv setHasHorizontalRuler:NO]; - [sv setHasVerticalRuler:NO]; - [sv setRulersVisible:NO]; - [sv setScrollerKnobStyle:NSScrollerKnobStyleDefault]; - // the scroller style is documented as being set by default for us - // LONGTERM verify line and page for programmatically created NSTableView - [sv setScrollsDynamically:YES]; - [sv setFindBarPosition:NSScrollViewFindBarPositionAboveContent]; - [sv setUsesPredominantAxisScrolling:NO]; - [sv setHorizontalScrollElasticity:NSScrollElasticityAutomatic]; - [sv setVerticalScrollElasticity:NSScrollElasticityAutomatic]; - [sv setAllowsMagnification:NO]; - - [sv setDocumentView:p->DocumentView]; - d = uiNew(struct scrollViewData); - scrollViewSetScrolling(sv, d, p->HScroll, p->VScroll); - - *dout = d; - return sv; -} - -// based on http://blog.bjhomer.com/2014/08/nsscrollview-and-autolayout.html because (as pointed out there) Apple's official guide is really only for iOS -void scrollViewSetScrolling(NSScrollView *sv, struct scrollViewData *d, BOOL hscroll, BOOL vscroll) -{ - d->hscroll = hscroll; - [sv setHasHorizontalScroller:d->hscroll]; - d->vscroll = vscroll; - [sv setHasVerticalScroller:d->vscroll]; -} - -void scrollViewFreeData(NSScrollView *sv, struct scrollViewData *d) -{ - uiFree(d); -} diff --git a/src/libui_sdl/libui/darwin/separator.m b/src/libui_sdl/libui/darwin/separator.m deleted file mode 100644 index a37a376..0000000 --- a/src/libui_sdl/libui/darwin/separator.m +++ /dev/null @@ -1,45 +0,0 @@ -// 14 august 2015 -#import "uipriv_darwin.h" - -// TODO make this intrinsic -#define separatorWidth 96 -#define separatorHeight 96 - -struct uiSeparator { - uiDarwinControl c; - NSBox *box; -}; - -uiDarwinControlAllDefaults(uiSeparator, box) - -uiSeparator *uiNewHorizontalSeparator(void) -{ - uiSeparator *s; - - uiDarwinNewControl(uiSeparator, s); - - // make the initial width >= initial height to force horizontal - s->box = [[NSBox alloc] initWithFrame:NSMakeRect(0, 0, 100, 1)]; - [s->box setBoxType:NSBoxSeparator]; - [s->box setBorderType:NSGrooveBorder]; - [s->box setTransparent:NO]; - [s->box setTitlePosition:NSNoTitle]; - - return s; -} - -uiSeparator *uiNewVerticalSeparator(void) -{ - uiSeparator *s; - - uiDarwinNewControl(uiSeparator, s); - - // make the initial height >= initial width to force vertical - s->box = [[NSBox alloc] initWithFrame:NSMakeRect(0, 0, 1, 100)]; - [s->box setBoxType:NSBoxSeparator]; - [s->box setBorderType:NSGrooveBorder]; - [s->box setTransparent:NO]; - [s->box setTitlePosition:NSNoTitle]; - - return s; -} diff --git a/src/libui_sdl/libui/darwin/slider.m b/src/libui_sdl/libui/darwin/slider.m deleted file mode 100644 index f00da50..0000000 --- a/src/libui_sdl/libui/darwin/slider.m +++ /dev/null @@ -1,147 +0,0 @@ -// 14 august 2015 -#import "uipriv_darwin.h" - -// Horizontal sliders have no intrinsic width; we'll use the default Interface Builder width for them. -// This will also be used for the initial frame size, to ensure the slider is always horizontal (see below). -#define sliderWidth 92 - -@interface libui_intrinsicWidthNSSlider : NSSlider -@end - -@implementation libui_intrinsicWidthNSSlider - -- (NSSize)intrinsicContentSize -{ - NSSize s; - - s = [super intrinsicContentSize]; - s.width = sliderWidth; - return s; -} - -@end - -struct uiSlider { - uiDarwinControl c; - NSSlider *slider; - void (*onChanged)(uiSlider *, void *); - void *onChangedData; -}; - -@interface sliderDelegateClass : NSObject { - struct mapTable *sliders; -} -- (IBAction)onChanged:(id)sender; -- (void)registerSlider:(uiSlider *)b; -- (void)unregisterSlider:(uiSlider *)b; -@end - -@implementation sliderDelegateClass - -- (id)init -{ - self = [super init]; - if (self) - self->sliders = newMap(); - return self; -} - -- (void)dealloc -{ - mapDestroy(self->sliders); - [super dealloc]; -} - -- (IBAction)onChanged:(id)sender -{ - uiSlider *s; - - s = (uiSlider *) mapGet(self->sliders, sender); - (*(s->onChanged))(s, s->onChangedData); -} - -- (void)registerSlider:(uiSlider *)s -{ - mapSet(self->sliders, s->slider, s); - [s->slider setTarget:self]; - [s->slider setAction:@selector(onChanged:)]; -} - -- (void)unregisterSlider:(uiSlider *)s -{ - [s->slider setTarget:nil]; - mapDelete(self->sliders, s->slider); -} - -@end - -static sliderDelegateClass *sliderDelegate = nil; - -uiDarwinControlAllDefaultsExceptDestroy(uiSlider, slider) - -static void uiSliderDestroy(uiControl *c) -{ - uiSlider *s = uiSlider(c); - - [sliderDelegate unregisterSlider:s]; - [s->slider release]; - uiFreeControl(uiControl(s)); -} - -int uiSliderValue(uiSlider *s) -{ - return [s->slider integerValue]; -} - -void uiSliderSetValue(uiSlider *s, int value) -{ - [s->slider setIntegerValue:value]; -} - -void uiSliderOnChanged(uiSlider *s, void (*f)(uiSlider *, void *), void *data) -{ - s->onChanged = f; - s->onChangedData = data; -} - -static void defaultOnChanged(uiSlider *s, void *data) -{ - // do nothing -} - -uiSlider *uiNewSlider(int min, int max) -{ - uiSlider *s; - NSSliderCell *cell; - int temp; - - if (min >= max) { - temp = min; - min = max; - max = temp; - } - - uiDarwinNewControl(uiSlider, s); - - // a horizontal slider is defined as one where the width > height, not by a flag - // to be safe, don't use NSZeroRect, but make it horizontal from the get-go - s->slider = [[libui_intrinsicWidthNSSlider alloc] - initWithFrame:NSMakeRect(0, 0, sliderWidth, 2)]; - [s->slider setMinValue:min]; - [s->slider setMaxValue:max]; - [s->slider setAllowsTickMarkValuesOnly:NO]; - [s->slider setNumberOfTickMarks:0]; - [s->slider setTickMarkPosition:NSTickMarkAbove]; - - cell = (NSSliderCell *) [s->slider cell]; - [cell setSliderType:NSLinearSlider]; - - if (sliderDelegate == nil) { - sliderDelegate = [[sliderDelegateClass new] autorelease]; - [delegates addObject:sliderDelegate]; - } - [sliderDelegate registerSlider:s]; - uiSliderOnChanged(s, defaultOnChanged, NULL); - - return s; -} diff --git a/src/libui_sdl/libui/darwin/spinbox.m b/src/libui_sdl/libui/darwin/spinbox.m deleted file mode 100644 index 73474d0..0000000 --- a/src/libui_sdl/libui/darwin/spinbox.m +++ /dev/null @@ -1,214 +0,0 @@ -// 14 august 2015 -#import "uipriv_darwin.h" - -@interface libui_spinbox : NSView { - NSTextField *tf; - NSNumberFormatter *formatter; - NSStepper *stepper; - - NSInteger value; - NSInteger minimum; - NSInteger maximum; - - uiSpinbox *spinbox; -} -- (id)initWithFrame:(NSRect)r spinbox:(uiSpinbox *)sb; -// see https://github.com/andlabs/ui/issues/82 -- (NSInteger)libui_value; -- (void)libui_setValue:(NSInteger)val; -- (void)setMinimum:(NSInteger)min; -- (void)setMaximum:(NSInteger)max; -- (IBAction)stepperClicked:(id)sender; -- (void)controlTextDidChange:(NSNotification *)note; -@end - -struct uiSpinbox { - uiDarwinControl c; - libui_spinbox *spinbox; - void (*onChanged)(uiSpinbox *, void *); - void *onChangedData; -}; - -// yes folks, this varies by operating system! woo! -// 10.10 started drawing the NSStepper one point too low, so we have to fix it up conditionally -// TODO test this; we'll probably have to substitute 10_9 -static CGFloat stepperYDelta(void) -{ - // via https://developer.apple.com/library/mac/releasenotes/AppKit/RN-AppKit/ - if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_9) - return 0; - return -1; -} - -@implementation libui_spinbox - -- (id)initWithFrame:(NSRect)r spinbox:(uiSpinbox *)sb -{ - self = [super initWithFrame:r]; - if (self) { - self->tf = newEditableTextField(); - [self->tf setTranslatesAutoresizingMaskIntoConstraints:NO]; - - self->formatter = [NSNumberFormatter new]; - [self->formatter setFormatterBehavior:NSNumberFormatterBehavior10_4]; - [self->formatter setLocalizesFormat:NO]; - [self->formatter setUsesGroupingSeparator:NO]; - [self->formatter setHasThousandSeparators:NO]; - [self->formatter setAllowsFloats:NO]; - [self->tf setFormatter:self->formatter]; - - self->stepper = [[NSStepper alloc] initWithFrame:NSZeroRect]; - [self->stepper setIncrement:1]; - [self->stepper setValueWraps:NO]; - [self->stepper setAutorepeat:YES]; // hold mouse button to step repeatedly - [self->stepper setTranslatesAutoresizingMaskIntoConstraints:NO]; - - [self->tf setDelegate:self]; - [self->stepper setTarget:self]; - [self->stepper setAction:@selector(stepperClicked:)]; - - [self addSubview:self->tf]; - [self addSubview:self->stepper]; - - [self addConstraint:mkConstraint(self->tf, NSLayoutAttributeLeading, - NSLayoutRelationEqual, - self, NSLayoutAttributeLeading, - 1, 0, - @"uiSpinbox left edge")]; - [self addConstraint:mkConstraint(self->stepper, NSLayoutAttributeTrailing, - NSLayoutRelationEqual, - self, NSLayoutAttributeTrailing, - 1, 0, - @"uiSpinbox right edge")]; - [self addConstraint:mkConstraint(self->tf, NSLayoutAttributeTop, - NSLayoutRelationEqual, - self, NSLayoutAttributeTop, - 1, 0, - @"uiSpinbox top edge text field")]; - [self addConstraint:mkConstraint(self->tf, NSLayoutAttributeBottom, - NSLayoutRelationEqual, - self, NSLayoutAttributeBottom, - 1, 0, - @"uiSpinbox bottom edge text field")]; - [self addConstraint:mkConstraint(self->stepper, NSLayoutAttributeTop, - NSLayoutRelationEqual, - self, NSLayoutAttributeTop, - 1, stepperYDelta(), - @"uiSpinbox top edge stepper")]; - [self addConstraint:mkConstraint(self->stepper, NSLayoutAttributeBottom, - NSLayoutRelationEqual, - self, NSLayoutAttributeBottom, - 1, stepperYDelta(), - @"uiSpinbox bottom edge stepper")]; - [self addConstraint:mkConstraint(self->tf, NSLayoutAttributeTrailing, - NSLayoutRelationEqual, - self->stepper, NSLayoutAttributeLeading, - 1, -3, // arbitrary amount; good enough visually (and it seems to match NSDatePicker too, at least on 10.11, which is even better) - @"uiSpinbox space between text field and stepper")]; - - self->spinbox = sb; - } - return self; -} - -- (void)dealloc -{ - [self->tf setDelegate:nil]; - [self->tf removeFromSuperview]; - [self->tf release]; - [self->formatter release]; - [self->stepper setTarget:nil]; - [self->stepper removeFromSuperview]; - [self->stepper release]; - [super dealloc]; -} - -- (NSInteger)libui_value -{ - return self->value; -} - -- (void)libui_setValue:(NSInteger)val -{ - self->value = val; - if (self->value < self->minimum) - self->value = self->minimum; - if (self->value > self->maximum) - self->value = self->maximum; - [self->tf setIntegerValue:self->value]; - [self->stepper setIntegerValue:self->value]; -} - -- (void)setMinimum:(NSInteger)min -{ - self->minimum = min; - [self->formatter setMinimum:[NSNumber numberWithInteger:self->minimum]]; - [self->stepper setMinValue:((double) (self->minimum))]; -} - -- (void)setMaximum:(NSInteger)max -{ - self->maximum = max; - [self->formatter setMaximum:[NSNumber numberWithInteger:self->maximum]]; - [self->stepper setMaxValue:((double) (self->maximum))]; -} - -- (IBAction)stepperClicked:(id)sender -{ - [self libui_setValue:[self->stepper integerValue]]; - (*(self->spinbox->onChanged))(self->spinbox, self->spinbox->onChangedData); -} - -- (void)controlTextDidChange:(NSNotification *)note -{ - [self libui_setValue:[self->tf integerValue]]; - (*(self->spinbox->onChanged))(self->spinbox, self->spinbox->onChangedData); -} - -@end - -uiDarwinControlAllDefaults(uiSpinbox, spinbox) - -int uiSpinboxValue(uiSpinbox *s) -{ - return [s->spinbox libui_value]; -} - -void uiSpinboxSetValue(uiSpinbox *s, int value) -{ - [s->spinbox libui_setValue:value]; -} - -void uiSpinboxOnChanged(uiSpinbox *s, void (*f)(uiSpinbox *, void *), void *data) -{ - s->onChanged = f; - s->onChangedData = data; -} - -static void defaultOnChanged(uiSpinbox *s, void *data) -{ - // do nothing -} - -uiSpinbox *uiNewSpinbox(int min, int max) -{ - uiSpinbox *s; - int temp; - - if (min >= max) { - temp = min; - min = max; - max = temp; - } - - uiDarwinNewControl(uiSpinbox, s); - - s->spinbox = [[libui_spinbox alloc] initWithFrame:NSZeroRect spinbox:s]; - [s->spinbox setMinimum:min]; - [s->spinbox setMaximum:max]; - [s->spinbox libui_setValue:min]; - - uiSpinboxOnChanged(s, defaultOnChanged, NULL); - - return s; -} diff --git a/src/libui_sdl/libui/darwin/stddialogs.m b/src/libui_sdl/libui/darwin/stddialogs.m deleted file mode 100644 index c826035..0000000 --- a/src/libui_sdl/libui/darwin/stddialogs.m +++ /dev/null @@ -1,123 +0,0 @@ -// 26 june 2015 -#import "uipriv_darwin.h" - -// LONGTERM restructure this whole file -// LONGTERM explicitly document this works as we want -// LONGTERM note that font and color buttons also do this - -#define windowWindow(w) ((NSWindow *) uiControlHandle(uiControl(w))) - -// source of code modal logic: http://stackoverflow.com/questions/604768/wait-for-nsalert-beginsheetmodalforwindow - -// note: whether extensions are actually shown depends on a user setting in Finder; we can't control it here -static void setupSavePanel(NSSavePanel *s) -{ - [s setCanCreateDirectories:YES]; - [s setShowsHiddenFiles:YES]; - [s setExtensionHidden:NO]; - [s setCanSelectHiddenExtension:NO]; - [s setTreatsFilePackagesAsDirectories:YES]; -} - -static char *runSavePanel(NSWindow *parent, NSSavePanel *s) -{ - char *filename; - - [s beginSheetModalForWindow:parent completionHandler:^(NSInteger result) { - [realNSApp() stopModalWithCode:result]; - }]; - if ([realNSApp() runModalForWindow:s] != NSFileHandlingPanelOKButton) - return NULL; - filename = uiDarwinNSStringToText([[s URL] path]); - return filename; -} - -char *uiOpenFile(uiWindow *parent, const char* filter, const char* initpath) -{ - NSOpenPanel *o; - - o = [NSOpenPanel openPanel]; - [o setCanChooseFiles:YES]; - [o setCanChooseDirectories:NO]; - [o setResolvesAliases:NO]; - [o setAllowsMultipleSelection:NO]; - setupSavePanel(o); - // panel is autoreleased - return runSavePanel(windowWindow(parent), o); -} - -char *uiSaveFile(uiWindow *parent, const char* filter, const char* initpath) -{ - NSSavePanel *s; - - s = [NSSavePanel savePanel]; - setupSavePanel(s); - // panel is autoreleased - return runSavePanel(windowWindow(parent), s); -} - -// I would use a completion handler for NSAlert as well, but alas NSAlert's are 10.9 and higher only -@interface libuiCodeModalAlertPanel : NSObject { - NSAlert *panel; - NSWindow *parent; -} -- (id)initWithPanel:(NSAlert *)p parent:(NSWindow *)w; -- (NSInteger)run; -- (void)panelEnded:(NSAlert *)panel result:(NSInteger)result data:(void *)data; -@end - -@implementation libuiCodeModalAlertPanel - -- (id)initWithPanel:(NSAlert *)p parent:(NSWindow *)w -{ - self = [super init]; - if (self) { - self->panel = p; - self->parent = w; - } - return self; -} - -- (NSInteger)run -{ - [self->panel beginSheetModalForWindow:self->parent - modalDelegate:self - didEndSelector:@selector(panelEnded:result:data:) - contextInfo:NULL]; - return [realNSApp() runModalForWindow:[self->panel window]]; -} - -- (void)panelEnded:(NSAlert *)panel result:(NSInteger)result data:(void *)data -{ - [realNSApp() stopModalWithCode:result]; -} - -@end - -static void msgbox(NSWindow *parent, const char *title, const char *description, NSAlertStyle style) -{ - NSAlert *a; - libuiCodeModalAlertPanel *cm; - - a = [NSAlert new]; - [a setAlertStyle:style]; - [a setShowsHelp:NO]; - [a setShowsSuppressionButton:NO]; - [a setMessageText:toNSString(title)]; - [a setInformativeText:toNSString(description)]; - [a addButtonWithTitle:@"OK"]; - cm = [[libuiCodeModalAlertPanel alloc] initWithPanel:a parent:parent]; - [cm run]; - [cm release]; - [a release]; -} - -void uiMsgBox(uiWindow *parent, const char *title, const char *description) -{ - msgbox(windowWindow(parent), title, description, NSInformationalAlertStyle); -} - -void uiMsgBoxError(uiWindow *parent, const char *title, const char *description) -{ - msgbox(windowWindow(parent), title, description, NSCriticalAlertStyle); -} diff --git a/src/libui_sdl/libui/darwin/tab.m b/src/libui_sdl/libui/darwin/tab.m deleted file mode 100644 index 3d2ca9f..0000000 --- a/src/libui_sdl/libui/darwin/tab.m +++ /dev/null @@ -1,292 +0,0 @@ -// 15 august 2015 -#import "uipriv_darwin.h" - -// TODO need to jiggle on tab change too (second page disabled tab label initially ambiguous) - -@interface tabPage : NSObject { - struct singleChildConstraints constraints; - int margined; - NSView *view; // the NSTabViewItem view itself - NSObject *pageID; -} -@property uiControl *c; -@property NSLayoutPriority oldHorzHuggingPri; -@property NSLayoutPriority oldVertHuggingPri; -- (id)initWithView:(NSView *)v pageID:(NSObject *)o; -- (NSView *)childView; -- (void)establishChildConstraints; -- (void)removeChildConstraints; -- (int)isMargined; -- (void)setMargined:(int)m; -@end - -struct uiTab { - uiDarwinControl c; - NSTabView *tabview; - NSMutableArray *pages; - NSLayoutPriority horzHuggingPri; - NSLayoutPriority vertHuggingPri; -}; - -@implementation tabPage - -- (id)initWithView:(NSView *)v pageID:(NSObject *)o -{ - self = [super init]; - if (self != nil) { - self->view = [v retain]; - self->pageID = [o retain]; - } - return self; -} - -- (void)dealloc -{ - [self removeChildConstraints]; - [self->view release]; - [self->pageID release]; - [super dealloc]; -} - -- (NSView *)childView -{ - return (NSView *) uiControlHandle(self.c); -} - -- (void)establishChildConstraints -{ - [self removeChildConstraints]; - if (self.c == NULL) - return; - singleChildConstraintsEstablish(&(self->constraints), - self->view, [self childView], - uiDarwinControlHugsTrailingEdge(uiDarwinControl(self.c)), - uiDarwinControlHugsBottom(uiDarwinControl(self.c)), - self->margined, - @"uiTab page"); -} - -- (void)removeChildConstraints -{ - singleChildConstraintsRemove(&(self->constraints), self->view); -} - -- (int)isMargined -{ - return self->margined; -} - -- (void)setMargined:(int)m -{ - self->margined = m; - singleChildConstraintsSetMargined(&(self->constraints), self->margined); -} - -@end - -static void uiTabDestroy(uiControl *c) -{ - uiTab *t = uiTab(c); - tabPage *page; - - // first remove all tab pages so we can destroy all the children - while ([t->tabview numberOfTabViewItems] != 0) - [t->tabview removeTabViewItem:[t->tabview tabViewItemAtIndex:0]]; - // then destroy all the children - for (page in t->pages) { - [page removeChildConstraints]; - uiControlSetParent(page.c, NULL); - uiDarwinControlSetSuperview(uiDarwinControl(page.c), nil); - uiControlDestroy(page.c); - } - // and finally destroy ourselves - [t->pages release]; - [t->tabview release]; - uiFreeControl(uiControl(t)); -} - -uiDarwinControlDefaultHandle(uiTab, tabview) -uiDarwinControlDefaultParent(uiTab, tabview) -uiDarwinControlDefaultSetParent(uiTab, tabview) -uiDarwinControlDefaultToplevel(uiTab, tabview) -uiDarwinControlDefaultVisible(uiTab, tabview) -uiDarwinControlDefaultShow(uiTab, tabview) -uiDarwinControlDefaultHide(uiTab, tabview) -uiDarwinControlDefaultEnabled(uiTab, tabview) -uiDarwinControlDefaultEnable(uiTab, tabview) -uiDarwinControlDefaultDisable(uiTab, tabview) - -static void uiTabSyncEnableState(uiDarwinControl *c, int enabled) -{ - uiTab *t = uiTab(c); - tabPage *page; - - if (uiDarwinShouldStopSyncEnableState(uiDarwinControl(t), enabled)) - return; - for (page in t->pages) - uiDarwinControlSyncEnableState(uiDarwinControl(page.c), enabled); -} - -uiDarwinControlDefaultSetSuperview(uiTab, tabview) - -static void tabRelayout(uiTab *t) -{ - tabPage *page; - - for (page in t->pages) - [page establishChildConstraints]; - // and this gets rid of some weird issues with regards to box alignment - jiggleViewLayout(t->tabview); -} - -BOOL uiTabHugsTrailingEdge(uiDarwinControl *c) -{ - uiTab *t = uiTab(c); - - return t->horzHuggingPri < NSLayoutPriorityWindowSizeStayPut; -} - -BOOL uiTabHugsBottom(uiDarwinControl *c) -{ - uiTab *t = uiTab(c); - - return t->vertHuggingPri < NSLayoutPriorityWindowSizeStayPut; -} - -static void uiTabChildEdgeHuggingChanged(uiDarwinControl *c) -{ - uiTab *t = uiTab(c); - - tabRelayout(t); -} - -static NSLayoutPriority uiTabHuggingPriority(uiDarwinControl *c, NSLayoutConstraintOrientation orientation) -{ - uiTab *t = uiTab(c); - - if (orientation == NSLayoutConstraintOrientationHorizontal) - return t->horzHuggingPri; - return t->vertHuggingPri; -} - -static void uiTabSetHuggingPriority(uiDarwinControl *c, NSLayoutPriority priority, NSLayoutConstraintOrientation orientation) -{ - uiTab *t = uiTab(c); - - if (orientation == NSLayoutConstraintOrientationHorizontal) - t->horzHuggingPri = priority; - else - t->vertHuggingPri = priority; - uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(t)); -} - -static void uiTabChildVisibilityChanged(uiDarwinControl *c) -{ - uiTab *t = uiTab(c); - - tabRelayout(t); -} - -void uiTabAppend(uiTab *t, const char *name, uiControl *child) -{ - uiTabInsertAt(t, name, [t->pages count], child); -} - -void uiTabInsertAt(uiTab *t, const char *name, int n, uiControl *child) -{ - tabPage *page; - NSView *view; - NSTabViewItem *i; - NSObject *pageID; - - uiControlSetParent(child, uiControl(t)); - - view = [[[NSView alloc] initWithFrame:NSZeroRect] autorelease]; - // note: if we turn off the autoresizing mask, nothing shows up - uiDarwinControlSetSuperview(uiDarwinControl(child), view); - uiDarwinControlSyncEnableState(uiDarwinControl(child), uiControlEnabledToUser(uiControl(t))); - - // the documentation says these can be nil but the headers say these must not be; let's be safe and make them non-nil anyway - pageID = [NSObject new]; - page = [[[tabPage alloc] initWithView:view pageID:pageID] autorelease]; - page.c = child; - - // don't hug, just in case we're a stretchy tab - page.oldHorzHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(page.c), NSLayoutConstraintOrientationHorizontal); - page.oldVertHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(page.c), NSLayoutConstraintOrientationVertical); - uiDarwinControlSetHuggingPriority(uiDarwinControl(page.c), NSLayoutPriorityDefaultLow, NSLayoutConstraintOrientationHorizontal); - uiDarwinControlSetHuggingPriority(uiDarwinControl(page.c), NSLayoutPriorityDefaultLow, NSLayoutConstraintOrientationVertical); - - [t->pages insertObject:page atIndex:n]; - - i = [[[NSTabViewItem alloc] initWithIdentifier:pageID] autorelease]; - [i setLabel:toNSString(name)]; - [i setView:view]; - [t->tabview insertTabViewItem:i atIndex:n]; - - tabRelayout(t); -} - -void uiTabDelete(uiTab *t, int n) -{ - tabPage *page; - uiControl *child; - NSTabViewItem *i; - - page = (tabPage *) [t->pages objectAtIndex:n]; - - uiDarwinControlSetHuggingPriority(uiDarwinControl(page.c), page.oldHorzHuggingPri, NSLayoutConstraintOrientationHorizontal); - uiDarwinControlSetHuggingPriority(uiDarwinControl(page.c), page.oldVertHuggingPri, NSLayoutConstraintOrientationVertical); - - child = page.c; - [page removeChildConstraints]; - [t->pages removeObjectAtIndex:n]; - - uiControlSetParent(child, NULL); - uiDarwinControlSetSuperview(uiDarwinControl(child), nil); - - i = [t->tabview tabViewItemAtIndex:n]; - [t->tabview removeTabViewItem:i]; - - tabRelayout(t); -} - -int uiTabNumPages(uiTab *t) -{ - return [t->pages count]; -} - -int uiTabMargined(uiTab *t, int n) -{ - tabPage *page; - - page = (tabPage *) [t->pages objectAtIndex:n]; - return [page isMargined]; -} - -void uiTabSetMargined(uiTab *t, int n, int margined) -{ - tabPage *page; - - page = (tabPage *) [t->pages objectAtIndex:n]; - [page setMargined:margined]; -} - -uiTab *uiNewTab(void) -{ - uiTab *t; - - uiDarwinNewControl(uiTab, t); - - t->tabview = [[NSTabView alloc] initWithFrame:NSZeroRect]; - // also good for NSTabView (same selector and everything) - uiDarwinSetControlFont((NSControl *) (t->tabview), NSRegularControlSize); - - t->pages = [NSMutableArray new]; - - // default to low hugging to not hug edges - t->horzHuggingPri = NSLayoutPriorityDefaultLow; - t->vertHuggingPri = NSLayoutPriorityDefaultLow; - - return t; -} diff --git a/src/libui_sdl/libui/darwin/text.m b/src/libui_sdl/libui/darwin/text.m deleted file mode 100644 index f0d3dab..0000000 --- a/src/libui_sdl/libui/darwin/text.m +++ /dev/null @@ -1,19 +0,0 @@ -// 10 april 2015 -#import "uipriv_darwin.h" - -char *uiDarwinNSStringToText(NSString *s) -{ - char *out; - - out = strdup([s UTF8String]); - if (out == NULL) { - fprintf(stderr, "memory exhausted in uiDarwinNSStringToText()\n"); - abort(); - } - return out; -} - -void uiFreeText(char *s) -{ - free(s); -} diff --git a/src/libui_sdl/libui/darwin/uipriv_darwin.h b/src/libui_sdl/libui/darwin/uipriv_darwin.h deleted file mode 100644 index 6bca87b..0000000 --- a/src/libui_sdl/libui/darwin/uipriv_darwin.h +++ /dev/null @@ -1,146 +0,0 @@ -// 6 january 2015 -#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_8 -#define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_8 -#import -#import "../ui.h" -#import "../ui_darwin.h" -#import "../common/uipriv.h" - -#if __has_feature(objc_arc) -#error Sorry, libui cannot be compiled with ARC. -#endif - -#define toNSString(str) [NSString stringWithUTF8String:(str)] -#define fromNSString(str) [(str) UTF8String] - -#ifndef NSAppKitVersionNumber10_9 -#define NSAppKitVersionNumber10_9 1265 -#endif - -/*TODO remove this*/typedef struct uiImage uiImage; - -// menu.m -@interface menuManager : NSObject { - struct mapTable *items; - BOOL hasQuit; - BOOL hasPreferences; - BOOL hasAbout; -} -@property (strong) NSMenuItem *quitItem; -@property (strong) NSMenuItem *preferencesItem; -@property (strong) NSMenuItem *aboutItem; -// NSMenuValidation is only informal -- (BOOL)validateMenuItem:(NSMenuItem *)item; -- (NSMenu *)makeMenubar; -@end -extern void finalizeMenus(void); -extern void uninitMenus(void); - -// main.m -@interface applicationClass : NSApplication -@end -// this is needed because NSApp is of type id, confusing clang -#define realNSApp() ((applicationClass *) NSApp) -@interface appDelegate : NSObject -@property (strong) menuManager *menuManager; -@end -#define appDelegate() ((appDelegate *) [realNSApp() delegate]) -struct nextEventArgs { - NSEventMask mask; - NSDate *duration; - // LONGTERM no NSRunLoopMode? - NSString *mode; - BOOL dequeue; -}; -extern int mainStep(struct nextEventArgs *nea, BOOL (^interceptEvent)(NSEvent *)); - -// util.m -extern void disableAutocorrect(NSTextView *); - -// entry.m -extern void finishNewTextField(NSTextField *, BOOL); -extern NSTextField *newEditableTextField(void); - -// window.m -@interface libuiNSWindow : NSWindow -- (void)libui_doMove:(NSEvent *)initialEvent; -- (void)libui_doResize:(NSEvent *)initialEvent on:(uiWindowResizeEdge)edge; -@end -extern uiWindow *windowFromNSWindow(NSWindow *); - -// alloc.m -extern NSMutableArray *delegates; -extern void initAlloc(void); -extern void uninitAlloc(void); - -// autolayout.m -extern NSLayoutConstraint *mkConstraint(id view1, NSLayoutAttribute attr1, NSLayoutRelation relation, id view2, NSLayoutAttribute attr2, CGFloat multiplier, CGFloat c, NSString *desc); -extern void jiggleViewLayout(NSView *view); -struct singleChildConstraints { - NSLayoutConstraint *leadingConstraint; - NSLayoutConstraint *topConstraint; - NSLayoutConstraint *trailingConstraintGreater; - NSLayoutConstraint *trailingConstraintEqual; - NSLayoutConstraint *bottomConstraintGreater; - NSLayoutConstraint *bottomConstraintEqual; -}; -extern void singleChildConstraintsEstablish(struct singleChildConstraints *c, NSView *contentView, NSView *childView, BOOL hugsTrailing, BOOL hugsBottom, int margined, NSString *desc); -extern void singleChildConstraintsRemove(struct singleChildConstraints *c, NSView *cv); -extern void singleChildConstraintsSetMargined(struct singleChildConstraints *c, int margined); - -// map.m -extern struct mapTable *newMap(void); -extern void mapDestroy(struct mapTable *m); -extern void *mapGet(struct mapTable *m, void *key); -extern void mapSet(struct mapTable *m, void *key, void *value); -extern void mapDelete(struct mapTable *m, void *key); -extern void mapWalk(struct mapTable *m, void (*f)(void *key, void *value)); -extern void mapReset(struct mapTable *m); - -// area.m -extern int sendAreaEvents(NSEvent *); - -// areaevents.m -extern BOOL fromKeycode(unsigned short keycode, uiAreaKeyEvent *ke); -extern BOOL keycodeModifier(unsigned short keycode, uiModifiers *mod); - -// draw.m -extern uiDrawContext *newContext(CGContextRef, CGFloat); -extern void freeContext(uiDrawContext *); - -// drawtext.m -extern uiDrawTextFont *mkTextFont(CTFontRef f, BOOL retain); -extern uiDrawTextFont *mkTextFontFromNSFont(NSFont *f); -extern void doDrawText(CGContextRef c, CGFloat cheight, double x, double y, uiDrawTextLayout *layout); - -// fontbutton.m -extern BOOL fontButtonInhibitSendAction(SEL sel, id from, id to); -extern BOOL fontButtonOverrideTargetForAction(SEL sel, id from, id to, id *override); -extern void setupFontPanel(void); - -// colorbutton.m -extern BOOL colorButtonInhibitSendAction(SEL sel, id from, id to); - -// scrollview.m -struct scrollViewCreateParams { - NSView *DocumentView; - NSColor *BackgroundColor; - BOOL DrawsBackground; - BOOL Bordered; - BOOL HScroll; - BOOL VScroll; -}; -struct scrollViewData; -extern NSScrollView *mkScrollView(struct scrollViewCreateParams *p, struct scrollViewData **dout); -extern void scrollViewSetScrolling(NSScrollView *sv, struct scrollViewData *d, BOOL hscroll, BOOL vscroll); -extern void scrollViewFreeData(NSScrollView *sv, struct scrollViewData *d); - -// label.m -extern NSTextField *newLabel(NSString *str); - -// image.m -extern NSImage *imageImage(uiImage *); - -// winmoveresize.m -extern void doManualMove(NSWindow *w, NSEvent *initialEvent); -extern void doManualResize(NSWindow *w, NSEvent *initialEvent, uiWindowResizeEdge edge); diff --git a/src/libui_sdl/libui/darwin/util.m b/src/libui_sdl/libui/darwin/util.m deleted file mode 100644 index ab87390..0000000 --- a/src/libui_sdl/libui/darwin/util.m +++ /dev/null @@ -1,15 +0,0 @@ -// 7 april 2015 -#import "uipriv_darwin.h" - -// LONGTERM do we really want to do this? make it an option? -void disableAutocorrect(NSTextView *tv) -{ - [tv setEnabledTextCheckingTypes:0]; - [tv setAutomaticDashSubstitutionEnabled:NO]; - // don't worry about automatic data detection; it won't change stringValue (thanks pretty_function in irc.freenode.net/#macdev) - [tv setAutomaticSpellingCorrectionEnabled:NO]; - [tv setAutomaticTextReplacementEnabled:NO]; - [tv setAutomaticQuoteSubstitutionEnabled:NO]; - [tv setAutomaticLinkDetectionEnabled:NO]; - [tv setSmartInsertDeleteEnabled:NO]; -} diff --git a/src/libui_sdl/libui/darwin/window.m b/src/libui_sdl/libui/darwin/window.m deleted file mode 100644 index 97c22e6..0000000 --- a/src/libui_sdl/libui/darwin/window.m +++ /dev/null @@ -1,407 +0,0 @@ -// 15 august 2015 -#import "uipriv_darwin.h" - -#define defaultStyleMask (NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask) - -struct uiWindow { - uiDarwinControl c; - NSWindow *window; - uiControl *child; - int margined; - int (*onClosing)(uiWindow *, void *); - void *onClosingData; - struct singleChildConstraints constraints; - void (*onContentSizeChanged)(uiWindow *, void *); - void *onContentSizeChangedData; - BOOL suppressSizeChanged; - int fullscreen; - int borderless; -}; - -@implementation libuiNSWindow - -- (void)libui_doMove:(NSEvent *)initialEvent -{ - doManualMove(self, initialEvent); -} - -- (void)libui_doResize:(NSEvent *)initialEvent on:(uiWindowResizeEdge)edge -{ - doManualResize(self, initialEvent, edge); -} - -@end - -@interface windowDelegateClass : NSObject { - struct mapTable *windows; -} -- (BOOL)windowShouldClose:(id)sender; -- (void)windowDidResize:(NSNotification *)note; -- (void)windowDidEnterFullScreen:(NSNotification *)note; -- (void)windowDidExitFullScreen:(NSNotification *)note; -- (void)registerWindow:(uiWindow *)w; -- (void)unregisterWindow:(uiWindow *)w; -- (uiWindow *)lookupWindow:(NSWindow *)w; -@end - -@implementation windowDelegateClass - -- (id)init -{ - self = [super init]; - if (self) - self->windows = newMap(); - return self; -} - -- (void)dealloc -{ - mapDestroy(self->windows); - [super dealloc]; -} - -- (BOOL)windowShouldClose:(id)sender -{ - uiWindow *w; - - w = [self lookupWindow:((NSWindow *) sender)]; - // w should not be NULL; we are only the delegate of registered windows - if ((*(w->onClosing))(w, w->onClosingData)) - uiControlDestroy(uiControl(w)); - return NO; -} - -- (void)windowDidResize:(NSNotification *)note -{ - uiWindow *w; - - w = [self lookupWindow:((NSWindow *) [note object])]; - if (!w->suppressSizeChanged) - (*(w->onContentSizeChanged))(w, w->onContentSizeChangedData); -} - -- (void)windowDidEnterFullScreen:(NSNotification *)note -{ - uiWindow *w; - - w = [self lookupWindow:((NSWindow *) [note object])]; - if (!w->suppressSizeChanged) - w->fullscreen = 1; -} - -- (void)windowDidExitFullScreen:(NSNotification *)note -{ - uiWindow *w; - - w = [self lookupWindow:((NSWindow *) [note object])]; - if (!w->suppressSizeChanged) - w->fullscreen = 0; -} - -- (void)registerWindow:(uiWindow *)w -{ - mapSet(self->windows, w->window, w); - [w->window setDelegate:self]; -} - -- (void)unregisterWindow:(uiWindow *)w -{ - [w->window setDelegate:nil]; - mapDelete(self->windows, w->window); -} - -- (uiWindow *)lookupWindow:(NSWindow *)w -{ - uiWindow *v; - - v = uiWindow(mapGet(self->windows, w)); - // this CAN (and IS ALLOWED TO) return NULL, just in case we're called with some OS X-provided window as the key window - return v; -} - -@end - -static windowDelegateClass *windowDelegate = nil; - -static void removeConstraints(uiWindow *w) -{ - NSView *cv; - - cv = [w->window contentView]; - singleChildConstraintsRemove(&(w->constraints), cv); -} - -static void uiWindowDestroy(uiControl *c) -{ - uiWindow *w = uiWindow(c); - - // hide the window - [w->window orderOut:w->window]; - removeConstraints(w); - if (w->child != NULL) { - uiControlSetParent(w->child, NULL); - uiDarwinControlSetSuperview(uiDarwinControl(w->child), nil); - uiControlDestroy(w->child); - } - [windowDelegate unregisterWindow:w]; - [w->window release]; - uiFreeControl(uiControl(w)); -} - -uiDarwinControlDefaultHandle(uiWindow, window) - -uiControl *uiWindowParent(uiControl *c) -{ - return NULL; -} - -void uiWindowSetParent(uiControl *c, uiControl *parent) -{ - uiUserBugCannotSetParentOnToplevel("uiWindow"); -} - -static int uiWindowToplevel(uiControl *c) -{ - return 1; -} - -static int uiWindowVisible(uiControl *c) -{ - uiWindow *w = uiWindow(c); - - return [w->window isVisible]; -} - -static void uiWindowShow(uiControl *c) -{ - uiWindow *w = (uiWindow *) c; - - [w->window makeKeyAndOrderFront:w->window]; -} - -static void uiWindowHide(uiControl *c) -{ - uiWindow *w = (uiWindow *) c; - - [w->window orderOut:w->window]; -} - -uiDarwinControlDefaultEnabled(uiWindow, window) -uiDarwinControlDefaultEnable(uiWindow, window) -uiDarwinControlDefaultDisable(uiWindow, window) - -static void uiWindowSyncEnableState(uiDarwinControl *c, int enabled) -{ - uiWindow *w = uiWindow(c); - - if (uiDarwinShouldStopSyncEnableState(uiDarwinControl(w), enabled)) - return; - if (w->child != NULL) - uiDarwinControlSyncEnableState(uiDarwinControl(w->child), enabled); -} - -static void uiWindowSetSuperview(uiDarwinControl *c, NSView *superview) -{ - // TODO -} - -static void windowRelayout(uiWindow *w) -{ - NSView *childView; - NSView *contentView; - - removeConstraints(w); - if (w->child == NULL) - return; - childView = (NSView *) uiControlHandle(w->child); - contentView = [w->window contentView]; - singleChildConstraintsEstablish(&(w->constraints), - contentView, childView, - uiDarwinControlHugsTrailingEdge(uiDarwinControl(w->child)), - uiDarwinControlHugsBottom(uiDarwinControl(w->child)), - w->margined, - @"uiWindow"); -} - -uiDarwinControlDefaultHugsTrailingEdge(uiWindow, window) -uiDarwinControlDefaultHugsBottom(uiWindow, window) - -static void uiWindowChildEdgeHuggingChanged(uiDarwinControl *c) -{ - uiWindow *w = uiWindow(c); - - windowRelayout(w); -} - -// TODO -uiDarwinControlDefaultHuggingPriority(uiWindow, window) -uiDarwinControlDefaultSetHuggingPriority(uiWindow, window) -// end TODO - -static void uiWindowChildVisibilityChanged(uiDarwinControl *c) -{ - uiWindow *w = uiWindow(c); - - windowRelayout(w); -} - -char *uiWindowTitle(uiWindow *w) -{ - return uiDarwinNSStringToText([w->window title]); -} - -void uiWindowSetTitle(uiWindow *w, const char *title) -{ - [w->window setTitle:toNSString(title)]; -} - -void uiWindowContentSize(uiWindow *w, int *width, int *height) -{ - NSRect r; - - r = [w->window contentRectForFrameRect:[w->window frame]]; - *width = r.size.width; - *height = r.size.height; -} - -void uiWindowSetContentSize(uiWindow *w, int width, int height) -{ - w->suppressSizeChanged = YES; - [w->window setContentSize:NSMakeSize(width, height)]; - w->suppressSizeChanged = NO; -} - -int uiWindowFullscreen(uiWindow *w) -{ - return w->fullscreen; -} - -void uiWindowSetFullscreen(uiWindow *w, int fullscreen) -{ - if (w->fullscreen && fullscreen) - return; - if (!w->fullscreen && !fullscreen) - return; - w->fullscreen = fullscreen; - if (w->fullscreen && w->borderless) // borderless doesn't play nice with fullscreen; don't toggle while borderless - return; - w->suppressSizeChanged = YES; - [w->window toggleFullScreen:w->window]; - w->suppressSizeChanged = NO; - if (!w->fullscreen && w->borderless) // borderless doesn't play nice with fullscreen; restore borderless after removing - [w->window setStyleMask:NSBorderlessWindowMask]; -} - -void uiWindowOnContentSizeChanged(uiWindow *w, void (*f)(uiWindow *, void *), void *data) -{ - w->onContentSizeChanged = f; - w->onContentSizeChangedData = data; -} - -void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data) -{ - w->onClosing = f; - w->onClosingData = data; -} - -int uiWindowBorderless(uiWindow *w) -{ - return w->borderless; -} - -void uiWindowSetBorderless(uiWindow *w, int borderless) -{ - w->borderless = borderless; - if (w->borderless) { - // borderless doesn't play nice with fullscreen; wait for later - if (!w->fullscreen) - [w->window setStyleMask:NSBorderlessWindowMask]; - } else { - [w->window setStyleMask:defaultStyleMask]; - // borderless doesn't play nice with fullscreen; restore state - if (w->fullscreen) { - w->suppressSizeChanged = YES; - [w->window toggleFullScreen:w->window]; - w->suppressSizeChanged = NO; - } - } -} - -void uiWindowSetChild(uiWindow *w, uiControl *child) -{ - NSView *childView; - - if (w->child != NULL) { - childView = (NSView *) uiControlHandle(w->child); - [childView removeFromSuperview]; - uiControlSetParent(w->child, NULL); - } - w->child = child; - if (w->child != NULL) { - uiControlSetParent(w->child, uiControl(w)); - childView = (NSView *) uiControlHandle(w->child); - uiDarwinControlSetSuperview(uiDarwinControl(w->child), [w->window contentView]); - uiDarwinControlSyncEnableState(uiDarwinControl(w->child), uiControlEnabledToUser(uiControl(w))); - } - windowRelayout(w); -} - -int uiWindowMargined(uiWindow *w) -{ - return w->margined; -} - -void uiWindowSetMargined(uiWindow *w, int margined) -{ - w->margined = margined; - singleChildConstraintsSetMargined(&(w->constraints), w->margined); -} - -static int defaultOnClosing(uiWindow *w, void *data) -{ - return 0; -} - -static void defaultOnPositionContentSizeChanged(uiWindow *w, void *data) -{ - // do nothing -} - -uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar) -{ - uiWindow *w; - - finalizeMenus(); - - uiDarwinNewControl(uiWindow, w); - - w->window = [[libuiNSWindow alloc] initWithContentRect:NSMakeRect(0, 0, (CGFloat) width, (CGFloat) height) - styleMask:defaultStyleMask - backing:NSBackingStoreBuffered - defer:YES]; - [w->window setTitle:toNSString(title)]; - - // do NOT release when closed - // we manually do this in uiWindowDestroy() above - [w->window setReleasedWhenClosed:NO]; - - if (windowDelegate == nil) { - windowDelegate = [[windowDelegateClass new] autorelease]; - [delegates addObject:windowDelegate]; - } - [windowDelegate registerWindow:w]; - uiWindowOnClosing(w, defaultOnClosing, NULL); - uiWindowOnContentSizeChanged(w, defaultOnPositionContentSizeChanged, NULL); - - return w; -} - -// utility function for menus -uiWindow *windowFromNSWindow(NSWindow *w) -{ - if (w == nil) - return NULL; - if (windowDelegate == nil) // no windows were created yet; we're called with some OS X-provided window - return NULL; - return [windowDelegate lookupWindow:w]; -} diff --git a/src/libui_sdl/libui/darwin/winmoveresize.m b/src/libui_sdl/libui/darwin/winmoveresize.m deleted file mode 100644 index 9145b7b..0000000 --- a/src/libui_sdl/libui/darwin/winmoveresize.m +++ /dev/null @@ -1,253 +0,0 @@ -// 1 november 2016 -#import "uipriv_darwin.h" - -// because we are changing the window frame each time the mouse moves, the successive -[NSEvent locationInWindow]s cannot be meaningfully used together -// make sure they are all following some sort of standard to avoid this problem; the screen is the most obvious possibility since it requires only one conversion (the only one that a NSWindow provides) -static NSPoint makeIndependent(NSPoint p, NSWindow *w) -{ - NSRect r; - - r.origin = p; - // mikeash in irc.freenode.net/#macdev confirms both that any size will do and that we can safely ignore the resultant size - r.size = NSZeroSize; - return [w convertRectToScreen:r].origin; -} - -struct onMoveDragParams { - NSWindow *w; - // using the previous point causes weird issues like the mouse seeming to fall behind the window edge... so do this instead - // TODO will this make things like the menubar and dock easier too? - NSRect initialFrame; - NSPoint initialPoint; -}; - -void onMoveDrag(struct onMoveDragParams *p, NSEvent *e) -{ - NSPoint new; - NSRect frame; - CGFloat offx, offy; - - new = makeIndependent([e locationInWindow], p->w); - frame = p->initialFrame; - - offx = new.x - p->initialPoint.x; - offy = new.y - p->initialPoint.y; - frame.origin.x += offx; - frame.origin.y += offy; - - // TODO handle the menubar - // TODO wait the system does this for us already?! - - [p->w setFrameOrigin:frame.origin]; -} - -void doManualMove(NSWindow *w, NSEvent *initialEvent) -{ - __block struct onMoveDragParams mdp; - struct nextEventArgs nea; - BOOL (^handleEvent)(NSEvent *e); - __block BOOL done; - - // this is only available on 10.11 and newer (LONGTERM FUTURE) - // but use it if available; this lets us use the real OS dragging code, which means we can take advantage of OS features like Spaces - if ([w respondsToSelector:@selector(performWindowDragWithEvent:)]) { - [((id) w) performWindowDragWithEvent:initialEvent]; - return; - } - - mdp.w = w; - mdp.initialFrame = [mdp.w frame]; - mdp.initialPoint = makeIndependent([initialEvent locationInWindow], mdp.w); - - nea.mask = NSLeftMouseDraggedMask | NSLeftMouseUpMask; - nea.duration = [NSDate distantFuture]; - nea.mode = NSEventTrackingRunLoopMode; // nextEventMatchingMask: docs suggest using this for manual mouse tracking - nea.dequeue = YES; - handleEvent = ^(NSEvent *e) { - if ([e type] == NSLeftMouseUp) { - done = YES; - return YES; // do not send - } - onMoveDrag(&mdp, e); - return YES; // do not send - }; - done = NO; - while (mainStep(&nea, handleEvent)) - if (done) - break; -} - -// see http://stackoverflow.com/a/40352996/3408572 -static void minMaxAutoLayoutSizes(NSWindow *w, NSSize *min, NSSize *max) -{ - NSLayoutConstraint *cw, *ch; - NSView *contentView; - NSRect prevFrame; - - // if adding these constraints causes the window to change size somehow, don't show it to the user and change it back afterwards - NSDisableScreenUpdates(); - prevFrame = [w frame]; - - // minimum: encourage the window to be as small as possible - contentView = [w contentView]; - cw = mkConstraint(contentView, NSLayoutAttributeWidth, - NSLayoutRelationEqual, - nil, NSLayoutAttributeNotAnAttribute, - 0, 0, - @"window minimum width finding constraint"); - [cw setPriority:NSLayoutPriorityDragThatCanResizeWindow]; - [contentView addConstraint:cw]; - ch = mkConstraint(contentView, NSLayoutAttributeHeight, - NSLayoutRelationEqual, - nil, NSLayoutAttributeNotAnAttribute, - 0, 0, - @"window minimum height finding constraint"); - [ch setPriority:NSLayoutPriorityDragThatCanResizeWindow]; - [contentView addConstraint:ch]; - *min = [contentView fittingSize]; - [contentView removeConstraint:cw]; - [contentView removeConstraint:ch]; - - // maximum: encourage the window to be as large as possible - contentView = [w contentView]; - cw = mkConstraint(contentView, NSLayoutAttributeWidth, - NSLayoutRelationEqual, - nil, NSLayoutAttributeNotAnAttribute, - 0, CGFLOAT_MAX, - @"window maximum width finding constraint"); - [cw setPriority:NSLayoutPriorityDragThatCanResizeWindow]; - [contentView addConstraint:cw]; - ch = mkConstraint(contentView, NSLayoutAttributeHeight, - NSLayoutRelationEqual, - nil, NSLayoutAttributeNotAnAttribute, - 0, CGFLOAT_MAX, - @"window maximum height finding constraint"); - [ch setPriority:NSLayoutPriorityDragThatCanResizeWindow]; - [contentView addConstraint:ch]; - *max = [contentView fittingSize]; - [contentView removeConstraint:cw]; - [contentView removeConstraint:ch]; - - [w setFrame:prevFrame display:YES]; // TODO really YES? - NSEnableScreenUpdates(); -} - -static void handleResizeLeft(NSRect *frame, NSPoint old, NSPoint new) -{ - frame->origin.x += new.x - old.x; - frame->size.width -= new.x - old.x; -} - -// TODO properly handle the menubar -// TODO wait, OS X does it for us?! -static void handleResizeTop(NSRect *frame, NSPoint old, NSPoint new) -{ - frame->size.height += new.y - old.y; -} - -static void handleResizeRight(NSRect *frame, NSPoint old, NSPoint new) -{ - frame->size.width += new.x - old.x; -} - - -// TODO properly handle the menubar -static void handleResizeBottom(NSRect *frame, NSPoint old, NSPoint new) -{ - frame->origin.y += new.y - old.y; - frame->size.height -= new.y - old.y; -} - -struct onResizeDragParams { - NSWindow *w; - // using the previous point causes weird issues like the mouse seeming to fall behind the window edge... so do this instead - // TODO will this make things like the menubar and dock easier too? - NSRect initialFrame; - NSPoint initialPoint; - uiWindowResizeEdge edge; - NSSize min; - NSSize max; -}; - -static void onResizeDrag(struct onResizeDragParams *p, NSEvent *e) -{ - NSPoint new; - NSRect frame; - - new = makeIndependent([e locationInWindow], p->w); - frame = p->initialFrame; - - // horizontal - switch (p->edge) { - case uiWindowResizeEdgeLeft: - case uiWindowResizeEdgeTopLeft: - case uiWindowResizeEdgeBottomLeft: - handleResizeLeft(&frame, p->initialPoint, new); - break; - case uiWindowResizeEdgeRight: - case uiWindowResizeEdgeTopRight: - case uiWindowResizeEdgeBottomRight: - handleResizeRight(&frame, p->initialPoint, new); - break; - } - // vertical - switch (p->edge) { - case uiWindowResizeEdgeTop: - case uiWindowResizeEdgeTopLeft: - case uiWindowResizeEdgeTopRight: - handleResizeTop(&frame, p->initialPoint, new); - break; - case uiWindowResizeEdgeBottom: - case uiWindowResizeEdgeBottomLeft: - case uiWindowResizeEdgeBottomRight: - handleResizeBottom(&frame, p->initialPoint, new); - break; - } - - // constrain - // TODO should we constrain against anything else as well? minMaxAutoLayoutSizes() already gives us nonnegative sizes, but... - if (frame.size.width < p->min.width) - frame.size.width = p->min.width; - if (frame.size.height < p->min.height) - frame.size.height = p->min.height; - // TODO > or >= ? - if (frame.size.width > p->max.width) - frame.size.width = p->max.width; - if (frame.size.height > p->max.height) - frame.size.height = p->max.height; - - [p->w setFrame:frame display:YES]; // and do reflect the new frame immediately -} - -// TODO do our events get fired with this? *should* they? -void doManualResize(NSWindow *w, NSEvent *initialEvent, uiWindowResizeEdge edge) -{ - __block struct onResizeDragParams rdp; - struct nextEventArgs nea; - BOOL (^handleEvent)(NSEvent *e); - __block BOOL done; - - rdp.w = w; - rdp.initialFrame = [rdp.w frame]; - rdp.initialPoint = makeIndependent([initialEvent locationInWindow], rdp.w); - rdp.edge = edge; - // TODO what happens if these change during the loop? - minMaxAutoLayoutSizes(rdp.w, &(rdp.min), &(rdp.max)); - - nea.mask = NSLeftMouseDraggedMask | NSLeftMouseUpMask; - nea.duration = [NSDate distantFuture]; - nea.mode = NSEventTrackingRunLoopMode; // nextEventMatchingMask: docs suggest using this for manual mouse tracking - nea.dequeue = YES; - handleEvent = ^(NSEvent *e) { - if ([e type] == NSLeftMouseUp) { - done = YES; - return YES; // do not send - } - onResizeDrag(&rdp, e); - return YES; // do not send - }; - done = NO; - while (mainStep(&nea, handleEvent)) - if (done) - break; -} diff --git a/src/libui_sdl/libui/doc/area.md b/src/libui_sdl/libui/doc/area.md deleted file mode 100644 index d14be9c..0000000 --- a/src/libui_sdl/libui/doc/area.md +++ /dev/null @@ -1,53 +0,0 @@ -# uiArea - -uiArea is a uiControl that provides a canvas you can draw on. It receives keyboard and mouse events, supports scrolling, is DPI aware, and has several other useful features. A uiArea consists of the drawing area itself and horizontal and vertical scrollbars. - -## The Area Handler - -A uiArea is driven by an *area handler*. An area handler is an object with several methods that uiArea calls to do certain tasks. To create an area handler, simply have a structure whose first member is of type `uiAreaHandler`: - -```c -struct uiAreaHandler { - void (*Draw)(uiAreaHandler *h, uiArea *a, uiAreaDrawParams *p); - void (*HScrollConfig)(uiAreaHandler *h, uiArea *a, uiAreaScrollConfig *c); - void (*VScrollConfig)(uiAreaHandler *h, uiArea *a, uiAreaScrollConfig *c); -} -``` - -## Drawing - -Unlike drawing canvas controls in other toolkits, uiArea does **not** have a fixed size. The coordinate (0, 0) is always the top-left corner of the drawing area, regardless of how big the uiArea is in the current window or where the scrollbars presently are. Instead, you simulate a size by setting the scrollbar bounds, and you are given the current scrolling positions to base your drawing with. - -The visible drawing area is called the *content area* by the drawing machinery. - -TODO have a diagram. - -When a part of the uiArea needs to be redrawn, the area handler's `Draw()` method is called. It receives the area handler, the uiArea, and a structure of parameters necessary for drawing. - -```c -struct uiAreaDrawParams { - uiDrawContext *context; - - intmax_t contentWidth; - intmax_t contentHeight; - - intmax_t hscrollpos; - intmax_t vscrollpos; - - intmax_t clipX; - intmax_t cilpY; - intmax_t clipWidth; - intmax_t clipHeight; - - TODO dpiX; - TODO dpiY; -}; -``` - -`context` is the drawing context; see drawing.md for details. - -`contentWidth` and `contentHeight` is the current width and height of the content area. `hscrollpos` and `vscrollpos` are the current horizontal and vertical positions of the scrollbars, in units defined by the scrollbar configurations; see below. - -`clipX`, `clipY`, `clipWidth`, and `clipHeight` define a rectangle, in content area coordinates, that the OS has requested to be redrawn. You can use this to optimize your drawing by only drawing where drawing is needed; the OS may choose to drop any drawing done outside the clip rectangle. - -`dpiX` and `dpiY` are the uiArea's current DPI in the X and Y directions, respectively. Do not save these values; they are not guaranteed to stay the same once `Draw()` returns. diff --git a/src/libui_sdl/libui/doc/areahandler b/src/libui_sdl/libui/doc/areahandler deleted file mode 100644 index 4c559db..0000000 --- a/src/libui_sdl/libui/doc/areahandler +++ /dev/null @@ -1 +0,0 @@ -Yes, you keep ownership of the uiAreaHandler. libui only cares about the address you give uiNewArea(); it doesn't copy anything. You can even use the same uiAreaHandler on multiple uiAreas, which is why you get the uiArea as a parameter in each function. diff --git a/src/libui_sdl/libui/doc/draw.md b/src/libui_sdl/libui/doc/draw.md deleted file mode 100644 index ef849fd..0000000 --- a/src/libui_sdl/libui/doc/draw.md +++ /dev/null @@ -1,42 +0,0 @@ -# The Drawing Model - -> Note: This model is not exclusive to libui; it is also applicable to many 2D graphics libraries, such as Direct2D, cairo, and Core Graphics. - -## The Coordinate System and Points - -In the traditional way we think of drawing, we think of rendering onto a plane of pixels. The pixels have a fixed size, and coordinates refer to the entire space that a pixel occupies. - -For instance, in the traditional model, the coordinate system looks like - -TODO image - -and when we say "draw a line from (0, 0) to (5, 5) exclusive", we mean "fill the spaces that are occupied by the pixels at (0, 0), (1, 1), (2, 2), (3, 3), and (4, 4)": - -TODO image - -Ugh. With pixels as big as the ones TODO. - -But now let's pretend we're working in a coordinate system where the point at (x, y) corresponds strictly to the top-left corner of the area that a pixel occupies. - -TODO image - -In this model, when we say "draw a line from (0, 0) to (5, 5)", we mean "draw a straight line filling every pixel that we cross if we traced a line from the top-left corner of what we used to call the pixel at (0, 0 to the top-left corner of what we used to call the pixel at (5, 5)": - -TODO image - -TODO. - -There are both technical and non-technical reasons for following this model. The technical reason is that implementing certain drawing operations, such as filling shapes, is much easier if we do things this way. The [cairo FAQ](http://www.cairographics.org/FAQ/#sharp_lines) explains in more detail. The non-technical reason has to do with DPI independence. - -## DPI Independence vs. DPI Awareness - -An upcoming trend in computing is the high-resolution display. These displays fit more dots in the same area that older screens could. The conventional term for the number of dots that fit in a given area is the "dots per inch", or DPI, measure. - -A naive approach to writing programs for these new displays is to think "well, if I just take the DPI and only use it in calculations where I need to deal with real-world measurements such as inches, rendering pure pixels as I always have, I should be fine". This kind of design is centered around *DPI awareness*. I know, I used to believe this too. But here's a little secret: this is wrong! A common myth about high-resolution monitors among non-technical people is that it makes the stuff on screen smaller. The mindset I just described causes this: TODO - -Instead, what we want out of a high-resolution display is *to show a more detailed view of the same image in the same space*. [The first image on Apple''s discussion of the topic](https://developer.apple.com/library/mac/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Art/backing_store_2x.png) is the perfect example. On the left, you see a low-resolution monitor. Notice how big chunks of the shapes go into the boxes. When the code that maps points to pixels runs, it can't have two colors in one square, so it has to decide what color to use. TODO - -TODO -- talk about how this relates to the OpenGL unit cube -- talk about the various names (point, user space coordinate, device-independent pixel) -- talk about "scaling" diff --git a/src/libui_sdl/libui/doc/drawtext b/src/libui_sdl/libui/doc/drawtext deleted file mode 100644 index 9d37713..0000000 --- a/src/libui_sdl/libui/doc/drawtext +++ /dev/null @@ -1,13 +0,0 @@ -on some unix systems, alpha blending fonts may not be available; this depends on your installed version of pango and is determined at runtime by libui - -uiDrawTextLayoutExtents: document that the extent width can be greater than the requested width if the requested width is small enough that only one character can fit - - -font matching is closest match but the search method is OS defined - - -weight names in libui do not necessarily line up with their OS names - - -uiDrawFontHandle() may not return a unique handle per instance - diff --git a/src/libui_sdl/libui/doc/export/coretext b/src/libui_sdl/libui/doc/export/coretext deleted file mode 100644 index 0888383..0000000 --- a/src/libui_sdl/libui/doc/export/coretext +++ /dev/null @@ -1,5 +0,0 @@ -font features are not provided by the collection and have to be added when asking for a font -it does preserve when going from CTFont to CTFontDescriptor -feature 17 has no flags in the header but can also hold small caps info -if a feature is present, it is ignored; other features will still show up - at least in the case of kLetterCaseTrait and kLowerCaseTrait diff --git a/src/libui_sdl/libui/doc/form b/src/libui_sdl/libui/doc/form deleted file mode 100644 index f24a94d..0000000 --- a/src/libui_sdl/libui/doc/form +++ /dev/null @@ -1 +0,0 @@ -hiding a control also hides its label diff --git a/src/libui_sdl/libui/doc/main b/src/libui_sdl/libui/doc/main deleted file mode 100644 index 9fa9c36..0000000 --- a/src/libui_sdl/libui/doc/main +++ /dev/null @@ -1 +0,0 @@ -after uiQuit or if uiShouldQuit returns nonzero, uiQueueMain's effect is undefined diff --git a/src/libui_sdl/libui/doc/mainsteps b/src/libui_sdl/libui/doc/mainsteps deleted file mode 100644 index f572b21..0000000 --- a/src/libui_sdl/libui/doc/mainsteps +++ /dev/null @@ -1 +0,0 @@ -the function passed to mainsteps must not return until uiQuit itself has been called; otherwise the results are undefined diff --git a/src/libui_sdl/libui/doc/slider b/src/libui_sdl/libui/doc/slider deleted file mode 100644 index 5a6ac04..0000000 --- a/src/libui_sdl/libui/doc/slider +++ /dev/null @@ -1 +0,0 @@ -if min >= max then they are swapped diff --git a/src/libui_sdl/libui/doc/spinbox b/src/libui_sdl/libui/doc/spinbox deleted file mode 100644 index 5a6ac04..0000000 --- a/src/libui_sdl/libui/doc/spinbox +++ /dev/null @@ -1 +0,0 @@ -if min >= max then they are swapped diff --git a/src/libui_sdl/libui/doc/static b/src/libui_sdl/libui/doc/static deleted file mode 100644 index fe1a09c..0000000 --- a/src/libui_sdl/libui/doc/static +++ /dev/null @@ -1,2 +0,0 @@ -comctl6 -libui.res diff --git a/src/libui_sdl/libui/doc/windowmovesize b/src/libui_sdl/libui/doc/windowmovesize deleted file mode 100644 index ec8bd96..0000000 --- a/src/libui_sdl/libui/doc/windowmovesize +++ /dev/null @@ -1,3 +0,0 @@ -you should never need to use these functions -they are provided only for the cases when ABSOLUTELY NECESSARY -the operating system may ignore your requests, for instance, if you are giving it invalid numbers or a size too small to fit; this is all system-defined diff --git a/src/libui_sdl/libui/doc/winstatic b/src/libui_sdl/libui/doc/winstatic deleted file mode 100644 index 5f163cf..0000000 --- a/src/libui_sdl/libui/doc/winstatic +++ /dev/null @@ -1 +0,0 @@ -libui uses resources starting at 29000 diff --git a/src/libui_sdl/libui/examples/CMakeLists.txt b/src/libui_sdl/libui/examples/CMakeLists.txt deleted file mode 100644 index 3a9ec4c..0000000 --- a/src/libui_sdl/libui/examples/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -# 3 june 2016 - -if(WIN32) - set(_EXAMPLE_RESOURCES_RC resources.rc) -endif() - -macro(_add_example _name) - _add_exec(${_name} ${ARGN}) - # because Microsoft's toolchain is dumb - if(MSVC) - set_property(TARGET ${_name} APPEND_STRING PROPERTY - LINK_FLAGS " /ENTRY:mainCRTStartup") - endif() -endmacro() - -_add_example(controlgallery - controlgallery/main.c - ${_EXAMPLE_RESOURCES_RC} -) - -_add_example(histogram - histogram/main.c - ${_EXAMPLE_RESOURCES_RC} -) - -_add_example(cpp-multithread - cpp-multithread/main.cpp - ${_EXAMPLE_RESOURCES_RC} -) -if(NOT WIN32) - target_link_libraries(cpp-multithread pthread) -endif() - -add_custom_target(examples - DEPENDS - controlgallery - histogram - cpp-multithread) diff --git a/src/libui_sdl/libui/examples/controlgallery/darwin.png b/src/libui_sdl/libui/examples/controlgallery/darwin.png deleted file mode 100644 index f61b54b..0000000 Binary files a/src/libui_sdl/libui/examples/controlgallery/darwin.png and /dev/null differ diff --git a/src/libui_sdl/libui/examples/controlgallery/main.c b/src/libui_sdl/libui/examples/controlgallery/main.c deleted file mode 100644 index c0d536c..0000000 --- a/src/libui_sdl/libui/examples/controlgallery/main.c +++ /dev/null @@ -1,540 +0,0 @@ -// 2 september 2015 -#include -#include -#include "../../ui.h" - -static int onClosing(uiWindow *w, void *data) -{ - uiQuit(); - return 1; -} - -static int onShouldQuit(void *data) -{ - uiWindow *mainwin = uiWindow(data); - - uiControlDestroy(uiControl(mainwin)); - return 1; -} - -static uiControl *makeBasicControlsPage(void) -{ - uiBox *vbox; - uiBox *hbox; - uiGroup *group; - uiForm *entryForm; - - vbox = uiNewVerticalBox(); - uiBoxSetPadded(vbox, 1); - - hbox = uiNewHorizontalBox(); - uiBoxSetPadded(hbox, 1); - uiBoxAppend(vbox, uiControl(hbox), 0); - - uiBoxAppend(hbox, - uiControl(uiNewButton("Button")), - 0); - uiBoxAppend(hbox, - uiControl(uiNewCheckbox("Checkbox")), - 0); - - uiBoxAppend(vbox, - uiControl(uiNewLabel("This is a label. Right now, labels can only span one line.")), - 0); - - uiBoxAppend(vbox, - uiControl(uiNewHorizontalSeparator()), - 0); - - group = uiNewGroup("Entries"); - uiGroupSetMargined(group, 1); - uiBoxAppend(vbox, uiControl(group), 1); - - entryForm = uiNewForm(); - uiFormSetPadded(entryForm, 1); - uiGroupSetChild(group, uiControl(entryForm)); - - uiFormAppend(entryForm, - "Entry", - uiControl(uiNewEntry()), - 0); - uiFormAppend(entryForm, - "Password Entry", - uiControl(uiNewPasswordEntry()), - 0); - uiFormAppend(entryForm, - "Search Entry", - uiControl(uiNewSearchEntry()), - 0); - uiFormAppend(entryForm, - "Multiline Entry", - uiControl(uiNewMultilineEntry()), - 1); - uiFormAppend(entryForm, - "Multiline Entry No Wrap", - uiControl(uiNewNonWrappingMultilineEntry()), - 1); - - return uiControl(vbox); -} - -// TODO make these not global -static uiSpinbox *spinbox; -static uiSlider *slider; -static uiProgressBar *pbar; - -static void onSpinboxChanged(uiSpinbox *s, void *data) -{ - uiSliderSetValue(slider, uiSpinboxValue(s)); - uiProgressBarSetValue(pbar, uiSpinboxValue(s)); -} - -static void onSliderChanged(uiSlider *s, void *data) -{ - uiSpinboxSetValue(spinbox, uiSliderValue(s)); - uiProgressBarSetValue(pbar, uiSliderValue(s)); -} - -static uiControl *makeNumbersPage() -{ - uiBox *hbox; - uiGroup *group; - uiBox *vbox; - uiProgressBar *ip; - uiCombobox *cbox; - uiEditableCombobox *ecbox; - uiRadioButtons *rb; - - hbox = uiNewHorizontalBox(); - uiBoxSetPadded(hbox, 1); - - group = uiNewGroup("Numbers"); - uiGroupSetMargined(group, 1); - uiBoxAppend(hbox, uiControl(group), 1); - - vbox = uiNewVerticalBox(); - uiBoxSetPadded(vbox, 1); - uiGroupSetChild(group, uiControl(vbox)); - - spinbox = uiNewSpinbox(0, 100); - slider = uiNewSlider(0, 100); - pbar = uiNewProgressBar(); - uiSpinboxOnChanged(spinbox, onSpinboxChanged, NULL); - uiSliderOnChanged(slider, onSliderChanged, NULL); - uiBoxAppend(vbox, uiControl(spinbox), 0); - uiBoxAppend(vbox, uiControl(slider), 0); - uiBoxAppend(vbox, uiControl(pbar), 0); - - ip = uiNewProgressBar(); - uiProgressBarSetValue(ip, -1); - uiBoxAppend(vbox, uiControl(ip), 0); - - group = uiNewGroup("Lists"); - uiGroupSetMargined(group, 1); - uiBoxAppend(hbox, uiControl(group), 1); - - vbox = uiNewVerticalBox(); - uiBoxSetPadded(vbox, 1); - uiGroupSetChild(group, uiControl(vbox)); - - cbox = uiNewCombobox(); - uiComboboxAppend(cbox, "Combobox Item 1"); - uiComboboxAppend(cbox, "Combobox Item 2"); - uiComboboxAppend(cbox, "Combobox Item 3"); - uiBoxAppend(vbox, uiControl(cbox), 0); - - ecbox = uiNewEditableCombobox(); - uiEditableComboboxAppend(ecbox, "Editable Item 1"); - uiEditableComboboxAppend(ecbox, "Editable Item 2"); - uiEditableComboboxAppend(ecbox, "Editable Item 3"); - uiBoxAppend(vbox, uiControl(ecbox), 0); - - rb = uiNewRadioButtons(); - uiRadioButtonsAppend(rb, "Radio Button 1"); - uiRadioButtonsAppend(rb, "Radio Button 2"); - uiRadioButtonsAppend(rb, "Radio Button 3"); - uiBoxAppend(vbox, uiControl(rb), 0); - - return uiControl(hbox); -} - -// TODO make this not global -static uiWindow *mainwin; - -static void onOpenFileClicked(uiButton *b, void *data) -{ - uiEntry *entry = uiEntry(data); - char *filename; - - filename = uiOpenFile(mainwin); - if (filename == NULL) { - uiEntrySetText(entry, "(cancelled)"); - return; - } - uiEntrySetText(entry, filename); - uiFreeText(filename); -} - -static void onSaveFileClicked(uiButton *b, void *data) -{ - uiEntry *entry = uiEntry(data); - char *filename; - - filename = uiSaveFile(mainwin); - if (filename == NULL) { - uiEntrySetText(entry, "(cancelled)"); - return; - } - uiEntrySetText(entry, filename); - uiFreeText(filename); -} - -static void onMsgBoxClicked(uiButton *b, void *data) -{ - uiMsgBox(mainwin, - "This is a normal message box.", - "More detailed information can be shown here."); -} - -static void onMsgBoxErrorClicked(uiButton *b, void *data) -{ - uiMsgBoxError(mainwin, - "This message box describes an error.", - "More detailed information can be shown here."); -} - -static uiControl *makeDataChoosersPage(void) -{ - uiBox *hbox; - uiBox *vbox; - uiGrid *grid; - uiButton *button; - uiEntry *entry; - uiGrid *msggrid; - - hbox = uiNewHorizontalBox(); - uiBoxSetPadded(hbox, 1); - - vbox = uiNewVerticalBox(); - uiBoxSetPadded(vbox, 1); - uiBoxAppend(hbox, uiControl(vbox), 0); - - uiBoxAppend(vbox, - uiControl(uiNewDatePicker()), - 0); - uiBoxAppend(vbox, - uiControl(uiNewTimePicker()), - 0); - uiBoxAppend(vbox, - uiControl(uiNewDateTimePicker()), - 0); - - uiBoxAppend(vbox, - uiControl(uiNewFontButton()), - 0); - uiBoxAppend(vbox, - uiControl(uiNewColorButton()), - 0); - - uiBoxAppend(hbox, - uiControl(uiNewVerticalSeparator()), - 0); - - vbox = uiNewVerticalBox(); - uiBoxSetPadded(vbox, 1); - uiBoxAppend(hbox, uiControl(vbox), 1); - - grid = uiNewGrid(); - uiGridSetPadded(grid, 1); - uiBoxAppend(vbox, uiControl(grid), 0); - - button = uiNewButton("Open File"); - entry = uiNewEntry(); - uiEntrySetReadOnly(entry, 1); - uiButtonOnClicked(button, onOpenFileClicked, entry); - uiGridAppend(grid, uiControl(button), - 0, 0, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - uiGridAppend(grid, uiControl(entry), - 1, 0, 1, 1, - 1, uiAlignFill, 0, uiAlignFill); - - button = uiNewButton("Save File"); - entry = uiNewEntry(); - uiEntrySetReadOnly(entry, 1); - uiButtonOnClicked(button, onSaveFileClicked, entry); - uiGridAppend(grid, uiControl(button), - 0, 1, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - uiGridAppend(grid, uiControl(entry), - 1, 1, 1, 1, - 1, uiAlignFill, 0, uiAlignFill); - - msggrid = uiNewGrid(); - uiGridSetPadded(msggrid, 1); - uiGridAppend(grid, uiControl(msggrid), - 0, 2, 2, 1, - 0, uiAlignCenter, 0, uiAlignStart); - - button = uiNewButton("Message Box"); - uiButtonOnClicked(button, onMsgBoxClicked, NULL); - uiGridAppend(msggrid, uiControl(button), - 0, 0, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - button = uiNewButton("Error Box"); - uiButtonOnClicked(button, onMsgBoxErrorClicked, NULL); - uiGridAppend(msggrid, uiControl(button), - 1, 0, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - - return uiControl(hbox); -} - -int main(void) -{ - uiInitOptions options; - const char *err; - uiTab *tab; - - memset(&options, 0, sizeof (uiInitOptions)); - err = uiInit(&options); - if (err != NULL) { - fprintf(stderr, "error initializing libui: %s", err); - uiFreeInitError(err); - return 1; - } - - mainwin = uiNewWindow("libui Control Gallery", 640, 480, 1); - uiWindowOnClosing(mainwin, onClosing, NULL); - uiOnShouldQuit(onShouldQuit, mainwin); - - tab = uiNewTab(); - uiWindowSetChild(mainwin, uiControl(tab)); - uiWindowSetMargined(mainwin, 1); - - uiTabAppend(tab, "Basic Controls", makeBasicControlsPage()); - uiTabSetMargined(tab, 0, 1); - - uiTabAppend(tab, "Numbers and Lists", makeNumbersPage()); - uiTabSetMargined(tab, 1, 1); - - uiTabAppend(tab, "Data Choosers", makeDataChoosersPage()); - uiTabSetMargined(tab, 2, 1); - - uiControlShow(uiControl(mainwin)); - uiMain(); - return 0; -} - -#if 0 - -static void openClicked(uiMenuItem *item, uiWindow *w, void *data) -{ - char *filename; - - filename = uiOpenFile(mainwin); - if (filename == NULL) { - uiMsgBoxError(mainwin, "No file selected", "Don't be alarmed!"); - return; - } - uiMsgBox(mainwin, "File selected", filename); - uiFreeText(filename); -} - -static void saveClicked(uiMenuItem *item, uiWindow *w, void *data) -{ - char *filename; - - filename = uiSaveFile(mainwin); - if (filename == NULL) { - uiMsgBoxError(mainwin, "No file selected", "Don't be alarmed!"); - return; - } - uiMsgBox(mainwin, "File selected (don't worry, it's still there)", filename); - uiFreeText(filename); -} - -static uiSpinbox *spinbox; -static uiSlider *slider; -static uiProgressBar *progressbar; - -static void update(int value) -{ - uiSpinboxSetValue(spinbox, value); - uiSliderSetValue(slider, value); - uiProgressBarSetValue(progressbar, value); -} - -static void onSpinboxChanged(uiSpinbox *s, void *data) -{ - update(uiSpinboxValue(spinbox)); -} - -static void onSliderChanged(uiSlider *s, void *data) -{ - update(uiSliderValue(slider)); -} - -int main(void) -{ - uiInitOptions o; - const char *err; - uiMenu *menu; - uiMenuItem *item; - uiBox *box; - uiBox *hbox; - uiGroup *group; - uiBox *inner; - uiBox *inner2; - uiEntry *entry; - uiCombobox *cbox; - uiEditableCombobox *ecbox; - uiRadioButtons *rb; - uiTab *tab; - - memset(&o, 0, sizeof (uiInitOptions)); - err = uiInit(&o); - if (err != NULL) { - fprintf(stderr, "error initializing ui: %s\n", err); - uiFreeInitError(err); - return 1; - } - - menu = uiNewMenu("File"); - item = uiMenuAppendItem(menu, "Open"); - uiMenuItemOnClicked(item, openClicked, NULL); - item = uiMenuAppendItem(menu, "Save"); - uiMenuItemOnClicked(item, saveClicked, NULL); - item = uiMenuAppendQuitItem(menu); - uiOnShouldQuit(shouldQuit, NULL); - - menu = uiNewMenu("Edit"); - item = uiMenuAppendCheckItem(menu, "Checkable Item"); - uiMenuAppendSeparator(menu); - item = uiMenuAppendItem(menu, "Disabled Item"); - uiMenuItemDisable(item); - item = uiMenuAppendPreferencesItem(menu); - - menu = uiNewMenu("Help"); - item = uiMenuAppendItem(menu, "Help"); - item = uiMenuAppendAboutItem(menu); - - mainwin = uiNewWindow("libui Control Gallery", 640, 480, 1); - uiWindowSetMargined(mainwin, 1); - uiWindowOnClosing(mainwin, onClosing, NULL); - - box = uiNewVerticalBox(); - uiBoxSetPadded(box, 1); - uiWindowSetChild(mainwin, uiControl(box)); - - hbox = uiNewHorizontalBox(); - uiBoxSetPadded(hbox, 1); - uiBoxAppend(box, uiControl(hbox), 1); - - group = uiNewGroup("Basic Controls"); - uiGroupSetMargined(group, 1); - uiBoxAppend(hbox, uiControl(group), 0); - - inner = uiNewVerticalBox(); - uiBoxSetPadded(inner, 1); - uiGroupSetChild(group, uiControl(inner)); - - uiBoxAppend(inner, - uiControl(uiNewButton("Button")), - 0); - uiBoxAppend(inner, - uiControl(uiNewCheckbox("Checkbox")), - 0); - entry = uiNewEntry(); - uiEntrySetText(entry, "Entry"); - uiBoxAppend(inner, - uiControl(entry), - 0); - uiBoxAppend(inner, - uiControl(uiNewLabel("Label")), - 0); - - uiBoxAppend(inner, - uiControl(uiNewHorizontalSeparator()), - 0); - - uiBoxAppend(inner, - uiControl(uiNewDatePicker()), - 0); - uiBoxAppend(inner, - uiControl(uiNewTimePicker()), - 0); - uiBoxAppend(inner, - uiControl(uiNewDateTimePicker()), - 0); - - uiBoxAppend(inner, - uiControl(uiNewFontButton()), - 0); - - uiBoxAppend(inner, - uiControl(uiNewColorButton()), - 0); - - inner2 = uiNewVerticalBox(); - uiBoxSetPadded(inner2, 1); - uiBoxAppend(hbox, uiControl(inner2), 1); - - group = uiNewGroup("Numbers"); - uiGroupSetMargined(group, 1); - uiBoxAppend(inner2, uiControl(group), 0); - - inner = uiNewVerticalBox(); - uiBoxSetPadded(inner, 1); - uiGroupSetChild(group, uiControl(inner)); - - spinbox = uiNewSpinbox(0, 100); - uiSpinboxOnChanged(spinbox, onSpinboxChanged, NULL); - uiBoxAppend(inner, uiControl(spinbox), 0); - - slider = uiNewSlider(0, 100); - uiSliderOnChanged(slider, onSliderChanged, NULL); - uiBoxAppend(inner, uiControl(slider), 0); - - progressbar = uiNewProgressBar(); - uiBoxAppend(inner, uiControl(progressbar), 0); - - group = uiNewGroup("Lists"); - uiGroupSetMargined(group, 1); - uiBoxAppend(inner2, uiControl(group), 0); - - inner = uiNewVerticalBox(); - uiBoxSetPadded(inner, 1); - uiGroupSetChild(group, uiControl(inner)); - - cbox = uiNewCombobox(); - uiComboboxAppend(cbox, "Combobox Item 1"); - uiComboboxAppend(cbox, "Combobox Item 2"); - uiComboboxAppend(cbox, "Combobox Item 3"); - uiBoxAppend(inner, uiControl(cbox), 0); - - ecbox = uiNewEditableCombobox(); - uiEditableComboboxAppend(ecbox, "Editable Item 1"); - uiEditableComboboxAppend(ecbox, "Editable Item 2"); - uiEditableComboboxAppend(ecbox, "Editable Item 3"); - uiBoxAppend(inner, uiControl(ecbox), 0); - - rb = uiNewRadioButtons(); - uiRadioButtonsAppend(rb, "Radio Button 1"); - uiRadioButtonsAppend(rb, "Radio Button 2"); - uiRadioButtonsAppend(rb, "Radio Button 3"); - uiBoxAppend(inner, uiControl(rb), 1); - - tab = uiNewTab(); - uiTabAppend(tab, "Page 1", uiControl(uiNewHorizontalBox())); - uiTabAppend(tab, "Page 2", uiControl(uiNewHorizontalBox())); - uiTabAppend(tab, "Page 3", uiControl(uiNewHorizontalBox())); - uiBoxAppend(inner2, uiControl(tab), 1); - - uiControlShow(uiControl(mainwin)); - uiMain(); - uiUninit(); - return 0; -} - -#endif diff --git a/src/libui_sdl/libui/examples/controlgallery/unix.png b/src/libui_sdl/libui/examples/controlgallery/unix.png deleted file mode 100644 index 0c58d09..0000000 Binary files a/src/libui_sdl/libui/examples/controlgallery/unix.png and /dev/null differ diff --git a/src/libui_sdl/libui/examples/controlgallery/windows.png b/src/libui_sdl/libui/examples/controlgallery/windows.png deleted file mode 100644 index 4be832f..0000000 Binary files a/src/libui_sdl/libui/examples/controlgallery/windows.png and /dev/null differ diff --git a/src/libui_sdl/libui/examples/cpp-multithread/main.cpp b/src/libui_sdl/libui/examples/cpp-multithread/main.cpp deleted file mode 100644 index f97bc6f..0000000 --- a/src/libui_sdl/libui/examples/cpp-multithread/main.cpp +++ /dev/null @@ -1,92 +0,0 @@ -// 6 december 2015 -#include -#include -#include -#include -#include -#include -#include -#include "../../ui.h" -using namespace std; - -uiMultilineEntry *e; -condition_variable cv; -mutex m; -unique_lock ourlock(m); -thread *timeThread; - -void sayTime(void *data) -{ - char *s = (char *) data; - - uiMultilineEntryAppend(e, s); - delete s; -} - -void threadproc(void) -{ - ourlock.lock(); - while (cv.wait_for(ourlock, chrono::seconds(1)) == cv_status::timeout) { - time_t t; - char *base; - char *s; - - t = time(NULL); - base = ctime(&t); - s = new char[strlen(base) + 1]; - strcpy(s, base); - uiQueueMain(sayTime, s); - } -} - -int onClosing(uiWindow *w, void *data) -{ - cv.notify_all(); - // C++ throws a hissy fit if you don't do this - // we might as well, to ensure no uiQueueMain() gets in after uiQuit() - timeThread->join(); - uiQuit(); - return 1; -} - -void saySomething(uiButton *b, void *data) -{ - uiMultilineEntryAppend(e, "Saying something\n"); -} - -int main(void) -{ - uiInitOptions o; - uiWindow *w; - uiBox *b; - uiButton *btn; - - memset(&o, 0, sizeof (uiInitOptions)); - if (uiInit(&o) != NULL) - abort(); - - w = uiNewWindow("Hello", 320, 240, 0); - uiWindowSetMargined(w, 1); - - b = uiNewVerticalBox(); - uiBoxSetPadded(b, 1); - uiWindowSetChild(w, uiControl(b)); - - e = uiNewMultilineEntry(); - uiMultilineEntrySetReadOnly(e, 1); - - btn = uiNewButton("Say Something"); - uiButtonOnClicked(btn, saySomething, NULL); - uiBoxAppend(b, uiControl(btn), 0); - - uiBoxAppend(b, uiControl(e), 1); - - // timeThread needs to lock ourlock itself - see http://stackoverflow.com/a/34121629/3408572 - ourlock.unlock(); - timeThread = new thread(threadproc); - - uiWindowOnClosing(w, onClosing, NULL); - uiControlShow(uiControl(w)); - uiMain(); - return 0; -} diff --git a/src/libui_sdl/libui/examples/example.manifest b/src/libui_sdl/libui/examples/example.manifest deleted file mode 100644 index 41e7c9c..0000000 --- a/src/libui_sdl/libui/examples/example.manifest +++ /dev/null @@ -1,20 +0,0 @@ - - - -Your application description here. - - - - - - - - - - - diff --git a/src/libui_sdl/libui/examples/example.static.manifest b/src/libui_sdl/libui/examples/example.static.manifest deleted file mode 100644 index d8e83a8..0000000 --- a/src/libui_sdl/libui/examples/example.static.manifest +++ /dev/null @@ -1,32 +0,0 @@ - - - -Your application description here. - - - - - - - - - - - - - - - - diff --git a/src/libui_sdl/libui/examples/histogram/main.c b/src/libui_sdl/libui/examples/histogram/main.c deleted file mode 100644 index f2b0e79..0000000 --- a/src/libui_sdl/libui/examples/histogram/main.c +++ /dev/null @@ -1,309 +0,0 @@ -// 13 october 2015 -#include -#include -#include -#include -#include "../../ui.h" - -uiWindow *mainwin; -uiArea *histogram; -uiAreaHandler handler; -uiSpinbox *datapoints[10]; -uiColorButton *colorButton; -int currentPoint = -1; - -// some metrics -#define xoffLeft 20 /* histogram margins */ -#define yoffTop 20 -#define xoffRight 20 -#define yoffBottom 20 -#define pointRadius 5 - -// helper to quickly set a brush color -static void setSolidBrush(uiDrawBrush *brush, uint32_t color, double alpha) -{ - uint8_t component; - - brush->Type = uiDrawBrushTypeSolid; - component = (uint8_t) ((color >> 16) & 0xFF); - brush->R = ((double) component) / 255; - component = (uint8_t) ((color >> 8) & 0xFF); - brush->G = ((double) component) / 255; - component = (uint8_t) (color & 0xFF); - brush->B = ((double) component) / 255; - brush->A = alpha; -} - -// and some colors -// names and values from https://msdn.microsoft.com/en-us/library/windows/desktop/dd370907%28v=vs.85%29.aspx -#define colorWhite 0xFFFFFF -#define colorBlack 0x000000 -#define colorDodgerBlue 0x1E90FF - -static void pointLocations(double width, double height, double *xs, double *ys) -{ - double xincr, yincr; - int i, n; - - xincr = width / 9; // 10 - 1 to make the last point be at the end - yincr = height / 100; - - for (i = 0; i < 10; i++) { - // get the value of the point - n = uiSpinboxValue(datapoints[i]); - // because y=0 is the top but n=0 is the bottom, we need to flip - n = 100 - n; - xs[i] = xincr * i; - ys[i] = yincr * n; - } -} - -static uiDrawPath *constructGraph(double width, double height, int extend) -{ - uiDrawPath *path; - double xs[10], ys[10]; - int i; - - pointLocations(width, height, xs, ys); - - path = uiDrawNewPath(uiDrawFillModeWinding); - - uiDrawPathNewFigure(path, xs[0], ys[0]); - for (i = 1; i < 10; i++) - uiDrawPathLineTo(path, xs[i], ys[i]); - - if (extend) { - uiDrawPathLineTo(path, width, height); - uiDrawPathLineTo(path, 0, height); - uiDrawPathCloseFigure(path); - } - - uiDrawPathEnd(path); - return path; -} - -static void graphSize(double clientWidth, double clientHeight, double *graphWidth, double *graphHeight) -{ - *graphWidth = clientWidth - xoffLeft - xoffRight; - *graphHeight = clientHeight - yoffTop - yoffBottom; -} - -static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p) -{ - uiDrawPath *path; - uiDrawBrush brush; - uiDrawStrokeParams sp; - uiDrawMatrix m; - double graphWidth, graphHeight; - double graphR, graphG, graphB, graphA; - - // fill the area with white - setSolidBrush(&brush, colorWhite, 1.0); - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathAddRectangle(path, 0, 0, p->AreaWidth, p->AreaHeight); - uiDrawPathEnd(path); - uiDrawFill(p->Context, path, &brush); - uiDrawFreePath(path); - - // figure out dimensions - graphSize(p->AreaWidth, p->AreaHeight, &graphWidth, &graphHeight); - - // clear sp to avoid passing garbage to uiDrawStroke() - // for example, we don't use dashing - memset(&sp, 0, sizeof (uiDrawStrokeParams)); - - // make a stroke for both the axes and the histogram line - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.Thickness = 2; - sp.MiterLimit = uiDrawDefaultMiterLimit; - - // draw the axes - setSolidBrush(&brush, colorBlack, 1.0); - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(path, - xoffLeft, yoffTop); - uiDrawPathLineTo(path, - xoffLeft, yoffTop + graphHeight); - uiDrawPathLineTo(path, - xoffLeft + graphWidth, yoffTop + graphHeight); - uiDrawPathEnd(path); - uiDrawStroke(p->Context, path, &brush, &sp); - uiDrawFreePath(path); - - // now transform the coordinate space so (0, 0) is the top-left corner of the graph - uiDrawMatrixSetIdentity(&m); - uiDrawMatrixTranslate(&m, xoffLeft, yoffTop); - uiDrawTransform(p->Context, &m); - - // now get the color for the graph itself and set up the brush - uiColorButtonColor(colorButton, &graphR, &graphG, &graphB, &graphA); - brush.Type = uiDrawBrushTypeSolid; - brush.R = graphR; - brush.G = graphG; - brush.B = graphB; - // we set brush->A below to different values for the fill and stroke - - // now create the fill for the graph below the graph line - path = constructGraph(graphWidth, graphHeight, 1); - brush.A = graphA / 2; - uiDrawFill(p->Context, path, &brush); - uiDrawFreePath(path); - - // now draw the histogram line - path = constructGraph(graphWidth, graphHeight, 0); - brush.A = graphA; - uiDrawStroke(p->Context, path, &brush, &sp); - uiDrawFreePath(path); - - // now draw the point being hovered over - if (currentPoint != -1) { - double xs[10], ys[10]; - - pointLocations(graphWidth, graphHeight, xs, ys); - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigureWithArc(path, - xs[currentPoint], ys[currentPoint], - pointRadius, - 0, 6.23, // TODO pi - 0); - uiDrawPathEnd(path); - // use the same brush as for the histogram lines - uiDrawFill(p->Context, path, &brush); - uiDrawFreePath(path); - } -} - -static int inPoint(double x, double y, double xtest, double ytest) -{ - // TODO switch to using a matrix - x -= xoffLeft; - y -= yoffTop; - return (x >= xtest - pointRadius) && - (x <= xtest + pointRadius) && - (y >= ytest - pointRadius) && - (y <= ytest + pointRadius); -} - -static void handlerMouseEvent(uiAreaHandler *a, uiArea *area, uiAreaMouseEvent *e) -{ - double graphWidth, graphHeight; - double xs[10], ys[10]; - int i; - - graphSize(e->AreaWidth, e->AreaHeight, &graphWidth, &graphHeight); - pointLocations(graphWidth, graphHeight, xs, ys); - - for (i = 0; i < 10; i++) - if (inPoint(e->X, e->Y, xs[i], ys[i])) - break; - if (i == 10) // not in a point - i = -1; - - currentPoint = i; - // TODO only redraw the relevant area - uiAreaQueueRedrawAll(histogram); -} - -static void handlerMouseCrossed(uiAreaHandler *ah, uiArea *a, int left) -{ - // do nothing -} - -static void handlerDragBroken(uiAreaHandler *ah, uiArea *a) -{ - // do nothing -} - -static int handlerKeyEvent(uiAreaHandler *ah, uiArea *a, uiAreaKeyEvent *e) -{ - // reject all keys - return 0; -} - -static void onDatapointChanged(uiSpinbox *s, void *data) -{ - uiAreaQueueRedrawAll(histogram); -} - -static void onColorChanged(uiColorButton *b, void *data) -{ - uiAreaQueueRedrawAll(histogram); -} - -static int onClosing(uiWindow *w, void *data) -{ - uiControlDestroy(uiControl(mainwin)); - uiQuit(); - return 0; -} - -static int shouldQuit(void *data) -{ - uiControlDestroy(uiControl(mainwin)); - return 1; -} - -int main(void) -{ - uiInitOptions o; - const char *err; - uiBox *hbox, *vbox; - int i; - uiDrawBrush brush; - - handler.Draw = handlerDraw; - handler.MouseEvent = handlerMouseEvent; - handler.MouseCrossed = handlerMouseCrossed; - handler.DragBroken = handlerDragBroken; - handler.KeyEvent = handlerKeyEvent; - - memset(&o, 0, sizeof (uiInitOptions)); - err = uiInit(&o); - if (err != NULL) { - fprintf(stderr, "error initializing ui: %s\n", err); - uiFreeInitError(err); - return 1; - } - - uiOnShouldQuit(shouldQuit, NULL); - - mainwin = uiNewWindow("libui Histogram Example", 640, 480, 1); - uiWindowSetMargined(mainwin, 1); - uiWindowOnClosing(mainwin, onClosing, NULL); - - hbox = uiNewHorizontalBox(); - uiBoxSetPadded(hbox, 1); - uiWindowSetChild(mainwin, uiControl(hbox)); - - vbox = uiNewVerticalBox(); - uiBoxSetPadded(vbox, 1); - uiBoxAppend(hbox, uiControl(vbox), 0); - - srand(time(NULL)); - for (i = 0; i < 10; i++) { - datapoints[i] = uiNewSpinbox(0, 100); - uiSpinboxSetValue(datapoints[i], rand() % 101); - uiSpinboxOnChanged(datapoints[i], onDatapointChanged, NULL); - uiBoxAppend(vbox, uiControl(datapoints[i]), 0); - } - - colorButton = uiNewColorButton(); - // TODO inline these - setSolidBrush(&brush, colorDodgerBlue, 1.0); - uiColorButtonSetColor(colorButton, - brush.R, - brush.G, - brush.B, - brush.A); - uiColorButtonOnChanged(colorButton, onColorChanged, NULL); - uiBoxAppend(vbox, uiControl(colorButton), 0); - - histogram = uiNewArea(&handler); - uiBoxAppend(hbox, uiControl(histogram), 1); - - uiControlShow(uiControl(mainwin)); - uiMain(); - uiUninit(); - return 0; -} diff --git a/src/libui_sdl/libui/examples/resources.rc b/src/libui_sdl/libui/examples/resources.rc deleted file mode 100644 index 49f486c..0000000 --- a/src/libui_sdl/libui/examples/resources.rc +++ /dev/null @@ -1,13 +0,0 @@ -// 30 may 2015 - -// this is a UTF-8 file -#pragma code_page(65001) - -// this is the Common Controls 6 manifest -// TODO set up the string values here -// 1 is the value of CREATEPROCESS_MANIFEST_RESOURCE_ID and 24 is the value of RT_MANIFEST; we use it directly to avoid needing to share winapi.h with the tests and examples -#ifndef _UI_STATIC -1 24 "example.manifest" -#else -1 24 "example.static.manifest" -#endif diff --git a/src/libui_sdl/libui/nowintable.diff b/src/libui_sdl/libui/nowintable.diff deleted file mode 100644 index cfbab07..0000000 --- a/src/libui_sdl/libui/nowintable.diff +++ /dev/null @@ -1,50 +0,0 @@ -diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt -index 7f70403..e909569 100644 ---- a/common/CMakeLists.txt -+++ b/common/CMakeLists.txt -@@ -6,7 +6,7 @@ list(APPEND _LIBUI_SOURCES - common/debug.c - common/matrix.c - common/shouldquit.c -- common/table.c -+# common/table.c - common/userbugs.c - ) - set(_LIBUI_SOURCES ${_LIBUI_SOURCES} PARENT_SCOPE) -diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt -index b753a7d..a648c64 100644 ---- a/test/CMakeLists.txt -+++ b/test/CMakeLists.txt -@@ -6,7 +6,7 @@ endif() - - _add_exec(tester - drawtests.c -- images.c -+# images.c - main.c - menus.c - page1.c -@@ -27,7 +27,7 @@ _add_exec(tester - page13.c - page14.c - page15.c -- page16.c -+# page16.c - spaced.c - ${_TEST_RESOURCES_RC} - ) -diff --git a/test/main.c b/test/main.c -index f33f30a..18774dc 100644 ---- a/test/main.c -+++ b/test/main.c -@@ -159,8 +159,8 @@ int main(int argc, char *argv[]) - innerTab = newTab(); - uiTabAppend(outerTab, "Pages 16-?", uiControl(innerTab)); - -- page16 = makePage16(); -- uiTabAppend(innerTab, "Page 16", uiControl(page16)); -+// page16 = makePage16(); -+// uiTabAppend(innerTab, "Page 16", uiControl(page16)); - - if (startspaced) - setSpaced(1); diff --git a/src/libui_sdl/libui/oldhaiku.tgz b/src/libui_sdl/libui/oldhaiku.tgz deleted file mode 100644 index a3b9dd7..0000000 Binary files a/src/libui_sdl/libui/oldhaiku.tgz and /dev/null differ diff --git a/src/libui_sdl/libui/test/CMakeLists.txt b/src/libui_sdl/libui/test/CMakeLists.txt deleted file mode 100644 index e4924bb..0000000 --- a/src/libui_sdl/libui/test/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -# 3 june 2016 - -if(WIN32) - set(_TEST_RESOURCES_RC resources.rc) -endif() - -_add_exec(tester - drawtests.c - main.c - menus.c - page1.c - page2.c - page3.c - page4.c - page5.c - page6.c - page7.c - page7a.c - page7b.c - page7c.c - page8.c - page9.c - page10.c - page11.c - page12.c - page13.c - page14.c - page15.c - spaced.c - ${_TEST_RESOURCES_RC} -) -target_include_directories(tester - PRIVATE test -) -set_target_properties(tester PROPERTIES - OUTPUT_NAME test - WIN32_EXECUTABLE FALSE -) diff --git a/src/libui_sdl/libui/test/drawtests.c b/src/libui_sdl/libui/test/drawtests.c deleted file mode 100644 index b6de753..0000000 --- a/src/libui_sdl/libui/test/drawtests.c +++ /dev/null @@ -1,1978 +0,0 @@ -// 9 october 2015 -#include "test.h" - -// TODO -// - test multiple clips -// - test saving and restoring clips - -struct drawtest { - const char *name; - void (*draw)(uiAreaDrawParams *p); - // TODO mouse event -}; - -static void drawOriginal(uiAreaDrawParams *p) -{ - uiDrawPath *path; - uiDrawBrush brush; - uiDrawStrokeParams sp; - - sp.Dashes = NULL; - sp.NumDashes = 0; - sp.DashPhase = 0; - - brush.Type = uiDrawBrushTypeSolid; - brush.A = 1; - - brush.R = 1; - brush.G = 0; - brush.B = 0; - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(path, p->ClipX + 5, p->ClipY + 5); - uiDrawPathLineTo(path, (p->ClipX + p->ClipWidth) - 5, (p->ClipY + p->ClipHeight) - 5); - uiDrawPathEnd(path); - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.Thickness = 1; - sp.MiterLimit = uiDrawDefaultMiterLimit; - uiDrawStroke(p->Context, path, &brush, &sp); - uiDrawFreePath(path); - - brush.R = 0; - brush.G = 0; - brush.B = 0.75; - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(path, p->ClipX, p->ClipY); - uiDrawPathLineTo(path, p->ClipX + p->ClipWidth, p->ClipY); - uiDrawPathLineTo(path, 50, 150); - uiDrawPathLineTo(path, 50, 50); - uiDrawPathCloseFigure(path); - uiDrawPathEnd(path); - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinRound; - sp.Thickness = 5; - uiDrawStroke(p->Context, path, &brush, &sp); - uiDrawFreePath(path); - - brush.R = 0; - brush.G = 0.75; - brush.B = 0; - brush.A = 0.5; - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathAddRectangle(path, 120, 80, 50, 50); - uiDrawPathEnd(path); - uiDrawFill(p->Context, path, &brush); - uiDrawFreePath(path); - brush.A = 1; - - brush.R = 0; - brush.G = 0.5; - brush.B = 0; - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(path, 5.5, 10.5); - uiDrawPathLineTo(path, 5.5, 50.5); - uiDrawPathEnd(path); - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.Thickness = 1; - sp.MiterLimit = uiDrawDefaultMiterLimit; - uiDrawStroke(p->Context, path, &brush, &sp); - uiDrawFreePath(path); - - brush.R = 0.5; - brush.G = 0.75; - brush.B = 0; - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(path, 400, 100); - uiDrawPathArcTo(path, - 400, 100, - 50, - 30. * (uiPi / 180.), - 300. * (uiPi / 180.), - 0); - // the sweep test below doubles as a clockwise test so a checkbox isn't needed anymore - uiDrawPathLineTo(path, 400, 100); - uiDrawPathNewFigureWithArc(path, - 510, 100, - 50, - 30. * (uiPi / 180.), - 300. * (uiPi / 180.), - 0); - uiDrawPathCloseFigure(path); - // and now with 330 to make sure sweeps work properly - uiDrawPathNewFigure(path, 400, 210); - uiDrawPathArcTo(path, - 400, 210, - 50, - 30. * (uiPi / 180.), - 330. * (uiPi / 180.), - 0); - uiDrawPathLineTo(path, 400, 210); - uiDrawPathNewFigureWithArc(path, - 510, 210, - 50, - 30. * (uiPi / 180.), - 330. * (uiPi / 180.), - 0); - uiDrawPathCloseFigure(path); - uiDrawPathEnd(path); - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.Thickness = 1; - sp.MiterLimit = uiDrawDefaultMiterLimit; - uiDrawStroke(p->Context, path, &brush, &sp); - uiDrawFreePath(path); - - brush.R = 0; - brush.G = 0.5; - brush.B = 0.75; - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(path, 300, 300); - uiDrawPathBezierTo(path, - 350, 320, - 310, 390, - 435, 372); - uiDrawPathEnd(path); - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.Thickness = 1; - sp.MiterLimit = uiDrawDefaultMiterLimit; - uiDrawStroke(p->Context, path, &brush, &sp); - uiDrawFreePath(path); -} - -static void drawArcs(uiAreaDrawParams *p) -{ - uiDrawPath *path; - int start = 20; - int step = 20; - int rad = 25; - int x, y; - double angle; - double add; - int i; - uiDrawBrush brush; - uiDrawStrokeParams sp; - - sp.Dashes = NULL; - sp.NumDashes = 0; - sp.DashPhase = 0; - - path = uiDrawNewPath(uiDrawFillModeWinding); - - add = (2.0 * uiPi) / 12; - - x = start + rad; - y = start + rad; - angle = 0; - for (i = 0; i < 13; i++) { - uiDrawPathNewFigureWithArc(path, - x, y, - rad, - 0, angle, - 0); - angle += add; - x += 2 * rad + step; - } - - y += 2 * rad + step; - x = start + rad; - angle = 0; - for (i = 0; i < 13; i++) { - uiDrawPathNewFigure(path, x, y); - uiDrawPathArcTo(path, - x, y, - rad, - 0, angle, - 0); - angle += add; - x += 2 * rad + step; - } - - y += 2 * rad + step; - x = start + rad; - angle = 0; - for (i = 0; i < 13; i++) { - uiDrawPathNewFigureWithArc(path, - x, y, - rad, - (uiPi / 4), angle, - 0); - angle += add; - x += 2 * rad + step; - } - - y += 2 * rad + step; - x = start + rad; - angle = 0; - for (i = 0; i < 13; i++) { - uiDrawPathNewFigure(path, x, y); - uiDrawPathArcTo(path, - x, y, - rad, - (uiPi / 4), angle, - 0); - angle += add; - x += 2 * rad + step; - } - - y += 2 * rad + step; - x = start + rad; - angle = 0; - for (i = 0; i < 13; i++) { - uiDrawPathNewFigureWithArc(path, - x, y, - rad, - uiPi + (uiPi / 5), angle, - 0); - angle += add; - x += 2 * rad + step; - } - - y += 2 * rad + step; - x = start + rad; - angle = 0; - for (i = 0; i < 13; i++) { - uiDrawPathNewFigure(path, x, y); - uiDrawPathArcTo(path, - x, y, - rad, - uiPi + (uiPi / 5), angle, - 0); - angle += add; - x += 2 * rad + step; - } - - uiDrawPathEnd(path); - - brush.Type = uiDrawBrushTypeSolid; - brush.R = 0; - brush.G = 0; - brush.B = 0; - brush.A = 1; - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.Thickness = 1; - sp.MiterLimit = uiDrawDefaultMiterLimit; - uiDrawStroke(p->Context, path, &brush, &sp); - - uiDrawFreePath(path); -} - -// Direct2D Documentation Code - -static void d2dColorToRGB(uint32_t color, double *r, double *g, double *b) -{ - uint8_t rr, gg, bb; - - rr = (color & 0xFF0000) >> 16; - gg = (color & 0x00FF00) >> 8; - bb = color & 0x0000FF; - *r = ((double) rr) / 255.0; - *g = ((double) gg) / 255.0; - *b = ((double) bb) / 255.0; -} -#define d2dBlack 0x000000 -#define d2dLightSlateGray 0x778899 -#define d2dCornflowerBlue 0x6495ED -#define d2dWhite 0xFFFFFF -#define d2dYellowGreen 0x9ACD32 -#define d2dYellow 0xFFFF00 -#define d2dForestGreen 0x228B22 -#define d2dOliveDrab 0x6B8E23 -#define d2dLightSkyBlue 0x87CEFA - -static void d2dSolidBrush(uiDrawBrush *brush, uint32_t color, double alpha) -{ - brush->Type = uiDrawBrushTypeSolid; - d2dColorToRGB(color, &(brush->R), &(brush->G), &(brush->B)); - brush->A = alpha; -} - -static void d2dClear(uiAreaDrawParams *p, uint32_t color, double alpha) -{ - uiDrawPath *path; - uiDrawBrush brush; - - d2dSolidBrush(&brush, color, alpha); - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathAddRectangle(path, 0, 0, p->AreaWidth, p->AreaHeight); - uiDrawPathEnd(path); - uiDrawFill(p->Context, path, &brush); - uiDrawFreePath(path); -} - -// from https://msdn.microsoft.com/en-us/library/windows/desktop/hh780340%28v=vs.85%29.aspx -// also at https://msdn.microsoft.com/en-us/library/windows/desktop/dd535473%28v=vs.85%29.aspx -static void drawD2DW8QS(uiAreaDrawParams *p) -{ - uiDrawPath *path; - uiDrawBrush brush; - - d2dSolidBrush(&brush, d2dBlack, 1.0); - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathAddRectangle(path, - 100, - 100, - (p->AreaWidth - 100) - 100, - (p->AreaHeight - 100) - 100); - uiDrawPathEnd(path); - uiDrawFill(p->Context, path, &brush); - uiDrawFreePath(path); -} - -// from https://msdn.microsoft.com/en-us/library/windows/desktop/dd370994%28v=vs.85%29.aspx -static void drawD2DSimpleApp(uiAreaDrawParams *p) -{ - uiDrawPath *path; - uiDrawBrush lightSlateGray; - uiDrawBrush cornflowerBlue; - uiDrawStrokeParams sp; - int x, y; - - sp.Dashes = NULL; - sp.NumDashes = 0; - sp.DashPhase = 0; - - d2dSolidBrush(&lightSlateGray, d2dLightSlateGray, 1.0); - d2dSolidBrush(&cornflowerBlue, d2dCornflowerBlue, 1.0); - - d2dClear(p, d2dWhite, 1.0); - - sp.Thickness = 0.5; - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.MiterLimit = uiDrawDefaultMiterLimit; - - for (x = 0; x < p->AreaWidth; x += 10) { - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(path, x, 0); - uiDrawPathLineTo(path, x, p->AreaHeight); - uiDrawPathEnd(path); - uiDrawStroke(p->Context, path, &lightSlateGray, &sp); - uiDrawFreePath(path); - } - - for (y = 0; y < p->AreaHeight; y += 10) { - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(path, 0, y); - uiDrawPathLineTo(path, p->AreaWidth, y); - uiDrawPathEnd(path); - uiDrawStroke(p->Context, path, &lightSlateGray, &sp); - uiDrawFreePath(path); - } - - double left, top, right, bottom; - - left = p->AreaWidth / 2.0 - 50.0; - right = p->AreaWidth / 2.0 + 50.0; - top = p->AreaHeight / 2.0 - 50.0; - bottom = p->AreaHeight / 2.0 + 50.0; - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathAddRectangle(path, left, top, right - left, bottom - top); - uiDrawPathEnd(path); - uiDrawFill(p->Context, path, &lightSlateGray); - uiDrawFreePath(path); - - left = p->AreaWidth / 2.0 - 100.0; - right = p->AreaWidth / 2.0 + 100.0; - top = p->AreaHeight / 2.0 - 100.0; - bottom = p->AreaHeight / 2.0 + 100.0; - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathAddRectangle(path, left, top, right - left, bottom - top); - uiDrawPathEnd(path); - sp.Thickness = 1.0; - uiDrawStroke(p->Context, path, &cornflowerBlue, &sp); - uiDrawFreePath(path); -} - -// TODO? https://msdn.microsoft.com/en-us/library/windows/desktop/dd372260(v=vs.85).aspx - -// TODO https://msdn.microsoft.com/en-us/library/windows/desktop/dd756654%28v=vs.85%29.aspx - -// TODO? all subsections too? https://msdn.microsoft.com/en-us/library/windows/desktop/hh973240%28v=vs.85%29.aspx - -// TODO differing examples of? https://msdn.microsoft.com/en-us/library/windows/desktop/dd756651%28v=vs.85%29.aspx - -// from https://msdn.microsoft.com/en-us/library/windows/desktop/dd756680%28v=vs.85%29.aspx -static void drawD2DSolidBrush(uiAreaDrawParams *p) -{ - uiDrawPath *path; - uiDrawBrush black; - uiDrawBrush yellowGreen; - uiDrawStrokeParams sp; - - sp.Dashes = NULL; - sp.NumDashes = 0; - sp.DashPhase = 0; - - d2dSolidBrush(&black, d2dBlack, 1.0); - d2dSolidBrush(&yellowGreen, d2dYellowGreen, 1.0); - - path = uiDrawNewPath(uiDrawFillModeWinding); - // the example doesn't define a rectangle - // 150x150 seems to be right given the other examples though - uiDrawPathAddRectangle(path, 25, 25, 150, 150); - uiDrawPathEnd(path); - - uiDrawFill(p->Context, path, &yellowGreen); - sp.Thickness = 1.0; - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.MiterLimit = uiDrawDefaultMiterLimit; - uiDrawStroke(p->Context, path, &black, &sp); - - uiDrawFreePath(path); -} - -// from https://msdn.microsoft.com/en-us/library/windows/desktop/dd756678%28v=vs.85%29.aspx -static void drawD2DLinearBrush(uiAreaDrawParams *p) -{ - uiDrawPath *path; - uiDrawBrush black; - uiDrawBrush gradient; - uiDrawBrushGradientStop stops[2]; - uiDrawStrokeParams sp; - - uiDrawMatrix m; - - sp.Dashes = NULL; - sp.NumDashes = 0; - sp.DashPhase = 0; - - // leave some room - uiDrawMatrixSetIdentity(&m); - uiDrawMatrixTranslate(&m, 25, 25); - uiDrawTransform(p->Context, &m); - - gradient.Type = uiDrawBrushTypeLinearGradient; - gradient.X0 = 0; - gradient.Y0 = 0; - gradient.X1 = 150; - gradient.Y1 = 150; - stops[0].Pos = 0.0; - d2dColorToRGB(d2dYellow, &(stops[0].R), &(stops[0].G), &(stops[0].B)); - stops[0].A = 1.0; - stops[1].Pos = 1.0; - d2dColorToRGB(d2dForestGreen, &(stops[1].R), &(stops[1].G), &(stops[1].B)); - stops[1].A = 1.0; - gradient.Stops = stops; - gradient.NumStops = 2; - - d2dSolidBrush(&black, d2dBlack, 1.0); - - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathAddRectangle(path, 0, 0, 150, 150); - uiDrawPathEnd(path); - - uiDrawFill(p->Context, path, &gradient); - sp.Thickness = 1.0; - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.MiterLimit = uiDrawDefaultMiterLimit; - uiDrawStroke(p->Context, path, &black, &sp); - - uiDrawFreePath(path); -} - -// from https://msdn.microsoft.com/en-us/library/windows/desktop/dd756679%28v=vs.85%29.aspx -// TODO expand this to change the origin point with a mouse click (not in the original but useful to have) -static void drawD2DRadialBrush(uiAreaDrawParams *p) -{ - uiDrawPath *path; - uiDrawBrush black; - uiDrawBrush gradient; - uiDrawBrushGradientStop stops[2]; - uiDrawStrokeParams sp; - - uiDrawMatrix m; - - sp.Dashes = NULL; - sp.NumDashes = 0; - sp.DashPhase = 0; - - // leave some room - uiDrawMatrixSetIdentity(&m); - uiDrawMatrixTranslate(&m, 25, 25); - uiDrawTransform(p->Context, &m); - - gradient.Type = uiDrawBrushTypeRadialGradient; - gradient.X0 = 75; - gradient.Y0 = 75; - gradient.X1 = 75; - gradient.Y1 = 75; - gradient.OuterRadius = 75; - stops[0].Pos = 0.0; - d2dColorToRGB(d2dYellow, &(stops[0].R), &(stops[0].G), &(stops[0].B)); - stops[0].A = 1.0; - stops[1].Pos = 1.0; - d2dColorToRGB(d2dForestGreen, &(stops[1].R), &(stops[1].G), &(stops[1].B)); - stops[1].A = 1.0; - gradient.Stops = stops; - gradient.NumStops = 2; - - d2dSolidBrush(&black, d2dBlack, 1.0); - - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(path, 150, 75); - uiDrawPathArcTo(path, - 75, 75, - 75, - 0, - 2 * uiPi, - 0); - uiDrawPathEnd(path); - - uiDrawFill(p->Context, path, &gradient); - sp.Thickness = 1.0; - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.MiterLimit = uiDrawDefaultMiterLimit; - uiDrawStroke(p->Context, path, &black, &sp); - - uiDrawFreePath(path); -} - -// TODO https://msdn.microsoft.com/en-us/library/windows/desktop/dd756677%28v=vs.85%29.aspx - -// TODO? other pages have some of these https://msdn.microsoft.com/en-us/library/windows/desktop/dd756653%28v=vs.85%29.aspx - -// from https://msdn.microsoft.com/en-us/library/windows/desktop/ee264309%28v=vs.85%29.aspx -static void drawD2DPathGeometries(uiAreaDrawParams *p) -{ - uiDrawPath *leftMountain; - uiDrawPath *rightMountain; - uiDrawPath *sun; - uiDrawPath *sunRays; - uiDrawPath *river; - uiDrawBrush radial; - uiDrawBrush scene; - uiDrawStrokeParams sp; - uiDrawBrushGradientStop stops[2]; - - sp.Dashes = NULL; - sp.NumDashes = 0; - sp.DashPhase = 0; - - // TODO this is definitely wrong but the example doesn't have the right brush in it - radial.Type = uiDrawBrushTypeRadialGradient; - radial.X0 = 75; - radial.Y0 = 75; - radial.X1 = 75; - radial.Y1 = 75; - radial.OuterRadius = 75; - stops[0].Pos = 0.0; - d2dColorToRGB(d2dYellow, &(stops[0].R), &(stops[0].G), &(stops[0].B)); - stops[0].A = 1.0; - stops[1].Pos = 1.0; - d2dColorToRGB(d2dForestGreen, &(stops[1].R), &(stops[1].G), &(stops[1].B)); - stops[1].A = 1.0; - radial.Stops = stops; - radial.NumStops = 2; - - leftMountain = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(leftMountain, 346, 255); - uiDrawPathLineTo(leftMountain, 267, 177); - uiDrawPathLineTo(leftMountain, 236, 192); - uiDrawPathLineTo(leftMountain, 212, 160); - uiDrawPathLineTo(leftMountain, 156, 255); - uiDrawPathLineTo(leftMountain, 346, 255); - uiDrawPathCloseFigure(leftMountain); - uiDrawPathEnd(leftMountain); - - rightMountain = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(rightMountain, 575, 263); - uiDrawPathLineTo(rightMountain, 481, 146); - uiDrawPathLineTo(rightMountain, 449, 181); - uiDrawPathLineTo(rightMountain, 433, 159); - uiDrawPathLineTo(rightMountain, 401, 214); - uiDrawPathLineTo(rightMountain, 381, 199); - uiDrawPathLineTo(rightMountain, 323, 263); - uiDrawPathLineTo(rightMountain, 575, 263); - uiDrawPathCloseFigure(rightMountain); - uiDrawPathEnd(rightMountain); - - sun = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigureWithArc(sun, - (440.0 - 270.0) / 2 + 270.0, 255, - 85, - uiPi, uiPi, - 0); - uiDrawPathCloseFigure(sun); - uiDrawPathEnd(sun); - - // the original examples had these as hollow figures - // we don't support them, so we'll have to stroke it separately - sunRays = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(sunRays, 299, 182); - uiDrawPathBezierTo(sunRays, - 299, 182, - 294, 176, - 285, 178); - uiDrawPathBezierTo(sunRays, - 276, 179, - 272, 173, - 272, 173); - uiDrawPathNewFigure(sunRays, 354, 156); - uiDrawPathBezierTo(sunRays, - 354, 156, - 358, 149, - 354, 142); - uiDrawPathBezierTo(sunRays, - 349, 134, - 354, 127, - 354, 127); - uiDrawPathNewFigure(sunRays, 322, 164); - uiDrawPathBezierTo(sunRays, - 322, 164, - 322, 156, - 314, 152); - uiDrawPathBezierTo(sunRays, - 306, 149, - 305, 141, - 305, 141); - uiDrawPathNewFigure(sunRays, 385, 164); - uiDrawPathBezierTo(sunRays, - 385, 164, - 392, 161, - 394, 152); - uiDrawPathBezierTo(sunRays, - 395, 144, - 402, 141, - 402, 142); - uiDrawPathNewFigure(sunRays, 408, 182); - uiDrawPathBezierTo(sunRays, - 408, 182, - 416, 184, - 422, 178); - uiDrawPathBezierTo(sunRays, - 428, 171, - 435, 173, - 435, 173); - uiDrawPathEnd(sunRays); - - river = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(river, 183, 392); - uiDrawPathBezierTo(river, - 238, 284, - 472, 345, - 356, 303); - uiDrawPathBezierTo(river, - 237, 261, - 333, 256, - 333, 256); - uiDrawPathBezierTo(river, - 335, 257, - 241, 261, - 411, 306); - uiDrawPathBezierTo(river, - 574, 350, - 288, 324, - 296, 392); - uiDrawPathEnd(river); - - d2dClear(p, d2dWhite, 1.0); - - // TODO draw the grid - - uiDrawFill(p->Context, sun, &radial); - - d2dSolidBrush(&scene, d2dBlack, 1.0); - sp.Thickness = 1.0; - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.MiterLimit = uiDrawDefaultMiterLimit; - uiDrawStroke(p->Context, sun, &scene, &sp); - uiDrawStroke(p->Context, sunRays, &scene, &sp); - - d2dSolidBrush(&scene, d2dOliveDrab, 1.0); - uiDrawFill(p->Context, leftMountain, &scene); - - d2dSolidBrush(&scene, d2dBlack, 1.0); - uiDrawStroke(p->Context, leftMountain, &scene, &sp); - - d2dSolidBrush(&scene, d2dLightSkyBlue, 1.0); - uiDrawFill(p->Context, river, &scene); - - d2dSolidBrush(&scene, d2dBlack, 1.0); - uiDrawStroke(p->Context, river, &scene, &sp); - - d2dSolidBrush(&scene, d2dYellowGreen, 1.0); - uiDrawFill(p->Context, rightMountain, &scene); - - d2dSolidBrush(&scene, d2dBlack, 1.0); - uiDrawStroke(p->Context, rightMountain, &scene, &sp); - - uiDrawFreePath(leftMountain); - uiDrawFreePath(rightMountain); - uiDrawFreePath(sun); - uiDrawFreePath(sunRays); - uiDrawFreePath(river); -} - -// TODO https://msdn.microsoft.com/en-us/library/windows/desktop/dd756690%28v=vs.85%29.aspx - -// from https://msdn.microsoft.com/en-us/library/windows/desktop/dd756681%28v=vs.85%29.aspx -static void drawD2DGeometryGroup(uiAreaDrawParams *p) -{ - uiDrawPath *alternate; - uiDrawPath *winding; - uiDrawBrush fill; - uiDrawBrush stroke; - uiDrawStrokeParams sp; - uiDrawMatrix m; - - sp.Dashes = NULL; - sp.NumDashes = 0; - sp.DashPhase = 0; - - alternate = uiDrawNewPath(uiDrawFillModeAlternate); - uiDrawPathNewFigureWithArc(alternate, - 105, 105, - 25, - 0, 2 * uiPi, - 0); - uiDrawPathNewFigureWithArc(alternate, - 105, 105, - 50, - 0, 2 * uiPi, - 0); - uiDrawPathNewFigureWithArc(alternate, - 105, 105, - 75, - 0, 2 * uiPi, - 0); - uiDrawPathNewFigureWithArc(alternate, - 105, 105, - 100, - 0, 2 * uiPi, - 0); - uiDrawPathEnd(alternate); - - winding = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigureWithArc(winding, - 105, 105, - 25, - 0, 2 * uiPi, - 0); - uiDrawPathNewFigureWithArc(winding, - 105, 105, - 50, - 0, 2 * uiPi, - 0); - uiDrawPathNewFigureWithArc(winding, - 105, 105, - 75, - 0, 2 * uiPi, - 0); - uiDrawPathNewFigureWithArc(winding, - 105, 105, - 100, - 0, 2 * uiPi, - 0); - uiDrawPathEnd(winding); - - d2dClear(p, d2dWhite, 1.0); - - // TODO grid - - // TODO the example doesn't provide these - d2dSolidBrush(&fill, d2dForestGreen, 1.0); - d2dSolidBrush(&stroke, d2dCornflowerBlue, 1.0); - - sp.Thickness = 1.0; - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.MiterLimit = uiDrawDefaultMiterLimit; - - uiDrawFill(p->Context, alternate, &fill); - uiDrawStroke(p->Context, alternate, &stroke, &sp); - // TODO text - - uiDrawMatrixSetIdentity(&m); - uiDrawMatrixTranslate(&m, 300, 0); - uiDrawTransform(p->Context, &m); - uiDrawFill(p->Context, winding, &fill); - uiDrawStroke(p->Context, winding, &stroke, &sp); -// // TODO text - - uiDrawFreePath(winding); - uiDrawFreePath(alternate); -} - -// TODO https://msdn.microsoft.com/en-us/library/windows/desktop/dd756676%28v=vs.85%29.aspx - -// TODO? https://msdn.microsoft.com/en-us/library/windows/desktop/dd370971%28v=vs.85%29.aspx - -// TODO are there even examples here? https://msdn.microsoft.com/en-us/library/windows/desktop/dd370966%28v=vs.85%29.aspx - -// from https://msdn.microsoft.com/en-us/library/windows/desktop/dd756687%28v=vs.85%29.aspx -static void drawD2DRotate(uiAreaDrawParams *p) -{ - uiDrawPath *path; - uiDrawBrush original; - uiDrawBrush fill; - uiDrawBrush transform; - uiDrawStrokeParams originalsp; - uiDrawStrokeParams transformsp; - uiDrawMatrix m; - - originalsp.Dashes = NULL; - originalsp.NumDashes = 0; - originalsp.DashPhase = 0; - transformsp.Dashes = NULL; - transformsp.NumDashes = 0; - transformsp.DashPhase = 0; - - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathAddRectangle(path, 438.0, 301.5, 498.0 - 438.0, 361.5 - 301.5); - uiDrawPathEnd(path); - - // TODO the example doesn't specify what these should be - d2dSolidBrush(&original, d2dBlack, 1.0); - d2dSolidBrush(&fill, d2dWhite, 0.5); - d2dSolidBrush(&transform, d2dForestGreen, 1.0); - // TODO this needs to be dashed - originalsp.Thickness = 1.0; - originalsp.Cap = uiDrawLineCapFlat; - originalsp.Join = uiDrawLineJoinMiter; - originalsp.MiterLimit = uiDrawDefaultMiterLimit; - transformsp.Thickness = 1.0; - transformsp.Cap = uiDrawLineCapFlat; - transformsp.Join = uiDrawLineJoinMiter; - transformsp.MiterLimit = uiDrawDefaultMiterLimit; - - // save for when we do the translated one - uiDrawSave(p->Context); - - uiDrawStroke(p->Context, path, &original, &originalsp); - - uiDrawMatrixSetIdentity(&m); - uiDrawMatrixRotate(&m, - 468.0, 331.5, - 45.0 * (uiPi / 180)); - uiDrawTransform(p->Context, &m); - - uiDrawFill(p->Context, path, &fill); - uiDrawStroke(p->Context, path, &transform, &transformsp); - - uiDrawRestore(p->Context); - - // translate to test the corner axis - uiDrawMatrixSetIdentity(&m); - uiDrawMatrixTranslate(&m, -200, -200); - uiDrawTransform(p->Context, &m); - - uiDrawStroke(p->Context, path, &original, &originalsp); - - uiDrawMatrixSetIdentity(&m); - uiDrawMatrixRotate(&m, - 438.0, 301.5, - 45.0 * (uiPi / 180)); - uiDrawTransform(p->Context, &m); - - uiDrawFill(p->Context, path, &fill); - uiDrawStroke(p->Context, path, &transform, &transformsp); - - uiDrawFreePath(path); -} - -// from https://msdn.microsoft.com/en-us/library/windows/desktop/dd756688%28v=vs.85%29.aspx -static void drawD2DScale(uiAreaDrawParams *p) -{ - uiDrawPath *path; - uiDrawBrush original; - uiDrawBrush fill; - uiDrawBrush transform; - uiDrawStrokeParams originalsp; - uiDrawStrokeParams transformsp; - uiDrawMatrix m; - - originalsp.Dashes = NULL; - originalsp.NumDashes = 0; - originalsp.DashPhase = 0; - transformsp.Dashes = NULL; - transformsp.NumDashes = 0; - transformsp.DashPhase = 0; - - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathAddRectangle(path, 438.0, 80.5, 498.0 - 438.0, 140.5 - 80.5); - uiDrawPathEnd(path); - - // TODO the example doesn't specify what these should be - d2dSolidBrush(&original, d2dBlack, 1.0); - d2dSolidBrush(&fill, d2dWhite, 0.5); - d2dSolidBrush(&transform, d2dForestGreen, 1.0); - // TODO this needs to be dashed - originalsp.Thickness = 1.0; - originalsp.Cap = uiDrawLineCapFlat; - originalsp.Join = uiDrawLineJoinMiter; - originalsp.MiterLimit = uiDrawDefaultMiterLimit; - transformsp.Thickness = 1.0; - transformsp.Cap = uiDrawLineCapFlat; - transformsp.Join = uiDrawLineJoinMiter; - transformsp.MiterLimit = uiDrawDefaultMiterLimit; - - // save for when we do the translated one - uiDrawSave(p->Context); - - uiDrawStroke(p->Context, path, &original, &originalsp); - - uiDrawMatrixSetIdentity(&m); - uiDrawMatrixScale(&m, - 438.0, 80.5, - 1.3, 1.3); - uiDrawTransform(p->Context, &m); - - uiDrawFill(p->Context, path, &fill); - uiDrawStroke(p->Context, path, &transform, &transformsp); - - uiDrawRestore(p->Context); - - // for testing purposes, show what happens if we scale about (0, 0) - uiDrawMatrixSetIdentity(&m); - uiDrawMatrixTranslate(&m, -300, 50); - uiDrawTransform(p->Context, &m); - - uiDrawStroke(p->Context, path, &original, &originalsp); - - uiDrawMatrixSetIdentity(&m); - uiDrawMatrixScale(&m, - 0, 0, - 1.3, 1.3); - uiDrawTransform(p->Context, &m); - - uiDrawFill(p->Context, path, &fill); - uiDrawStroke(p->Context, path, &transform, &transformsp); - - uiDrawFreePath(path); -} - -// from https://msdn.microsoft.com/en-us/library/windows/desktop/dd756689%28v=vs.85%29.aspx -// TODO counterclockwise?! -void drawD2DSkew(uiAreaDrawParams *p) -{ - uiDrawPath *path; - uiDrawBrush original; - uiDrawBrush fill; - uiDrawBrush transform; - uiDrawStrokeParams originalsp; - uiDrawStrokeParams transformsp; - uiDrawMatrix m; - - originalsp.Dashes = NULL; - originalsp.NumDashes = 0; - originalsp.DashPhase = 0; - transformsp.Dashes = NULL; - transformsp.NumDashes = 0; - transformsp.DashPhase = 0; - - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathAddRectangle(path, 126.0, 301.5, 186.0 - 126.0, 361.5 - 301.5); - uiDrawPathEnd(path); - - // TODO the example doesn't specify what these should be - d2dSolidBrush(&original, d2dBlack, 1.0); - d2dSolidBrush(&fill, d2dWhite, 0.5); - d2dSolidBrush(&transform, d2dForestGreen, 1.0); - // TODO this needs to be dashed - originalsp.Thickness = 1.0; - originalsp.Cap = uiDrawLineCapFlat; - originalsp.Join = uiDrawLineJoinMiter; - originalsp.MiterLimit = uiDrawDefaultMiterLimit; - transformsp.Thickness = 1.0; - transformsp.Cap = uiDrawLineCapFlat; - transformsp.Join = uiDrawLineJoinMiter; - transformsp.MiterLimit = uiDrawDefaultMiterLimit; - - // save for when we do the translated one - uiDrawSave(p->Context); - - uiDrawStroke(p->Context, path, &original, &originalsp); - - uiDrawMatrixSetIdentity(&m); - uiDrawMatrixSkew(&m, - 126.0, 301.5, - 45.0 * (uiPi / 180), 0); - uiDrawTransform(p->Context, &m); - - uiDrawFill(p->Context, path, &fill); - uiDrawStroke(p->Context, path, &transform, &transformsp); - - uiDrawRestore(p->Context); - - // for testing purposes, show what happens if we skew about (0, 0) - uiDrawMatrixSetIdentity(&m); - uiDrawMatrixTranslate(&m, 0, -200); - uiDrawTransform(p->Context, &m); - - uiDrawStroke(p->Context, path, &original, &originalsp); - - uiDrawMatrixSetIdentity(&m); - uiDrawMatrixSkew(&m, - 0, 0, - 45.0 * (uiPi / 180), 0); - uiDrawTransform(p->Context, &m); - - uiDrawFill(p->Context, path, &fill); - uiDrawStroke(p->Context, path, &transform, &transformsp); - - uiDrawFreePath(path); -} - -// from https://msdn.microsoft.com/en-us/library/windows/desktop/dd756691%28v=vs.85%29.aspx -static void drawD2DTranslate(uiAreaDrawParams *p) -{ - uiDrawPath *path; - uiDrawBrush original; - uiDrawBrush fill; - uiDrawBrush transform; - uiDrawStrokeParams originalsp; - uiDrawStrokeParams transformsp; - uiDrawMatrix m; - - originalsp.Dashes = NULL; - originalsp.NumDashes = 0; - originalsp.DashPhase = 0; - transformsp.Dashes = NULL; - transformsp.NumDashes = 0; - transformsp.DashPhase = 0; - - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathAddRectangle(path, 126.0, 80.5, 186.0 - 126.0, 140.5 - 80.5); - uiDrawPathEnd(path); - - // TODO the example doesn't specify what these should be - d2dSolidBrush(&original, d2dBlack, 1.0); - d2dSolidBrush(&fill, d2dWhite, 0.5); - d2dSolidBrush(&transform, d2dForestGreen, 1.0); - // TODO this needs to be dashed - originalsp.Thickness = 1.0; - originalsp.Cap = uiDrawLineCapFlat; - originalsp.Join = uiDrawLineJoinMiter; - originalsp.MiterLimit = uiDrawDefaultMiterLimit; - transformsp.Thickness = 1.0; - transformsp.Cap = uiDrawLineCapFlat; - transformsp.Join = uiDrawLineJoinMiter; - transformsp.MiterLimit = uiDrawDefaultMiterLimit; - - uiDrawStroke(p->Context, path, &original, &originalsp); - - uiDrawMatrixSetIdentity(&m); - uiDrawMatrixTranslate(&m, 20, 10); - uiDrawTransform(p->Context, &m); - - uiDrawFill(p->Context, path, &fill); - uiDrawStroke(p->Context, path, &transform, &transformsp); - - uiDrawFreePath(path); -} - -// from https://msdn.microsoft.com/en-us/library/windows/desktop/dd756672%28v=vs.85%29.aspx -// TODO the points seem off -static void drawD2DMultiTransforms(uiAreaDrawParams *p) -{ - uiDrawPath *path; - uiDrawBrush original; - uiDrawBrush fill; - uiDrawBrush transform; - uiDrawStrokeParams originalsp; - uiDrawStrokeParams transformsp; - uiDrawMatrix mtranslate; - uiDrawMatrix mrotate; - - originalsp.Dashes = NULL; - originalsp.NumDashes = 0; - originalsp.DashPhase = 0; - transformsp.Dashes = NULL; - transformsp.NumDashes = 0; - transformsp.DashPhase = 0; - - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathAddRectangle(path, 300.0, 40.0, 360.0 - 300.0, 100.0 - 40.0); - uiDrawPathEnd(path); - - // TODO the example doesn't specify what these should be - d2dSolidBrush(&original, d2dBlack, 1.0); - d2dSolidBrush(&fill, d2dWhite, 0.5); - d2dSolidBrush(&transform, d2dForestGreen, 1.0); - // TODO this needs to be dashed - originalsp.Thickness = 1.0; - originalsp.Cap = uiDrawLineCapFlat; - originalsp.Join = uiDrawLineJoinMiter; - originalsp.MiterLimit = uiDrawDefaultMiterLimit; - transformsp.Thickness = 1.0; - transformsp.Cap = uiDrawLineCapFlat; - transformsp.Join = uiDrawLineJoinMiter; - transformsp.MiterLimit = uiDrawDefaultMiterLimit; - - uiDrawMatrixSetIdentity(&mtranslate); - uiDrawMatrixTranslate(&mtranslate, 20.0, 10.0); - uiDrawMatrixSetIdentity(&mrotate); - uiDrawMatrixRotate(&mrotate, - 330.0, 70.0, - 45.0 * (uiPi / 180)); - - // save for when we do the opposite one - uiDrawSave(p->Context); - - uiDrawStroke(p->Context, path, &original, &originalsp); - - uiDrawTransform(p->Context, &mrotate); - uiDrawTransform(p->Context, &mtranslate); - - uiDrawFill(p->Context, path, &fill); - uiDrawStroke(p->Context, path, &transform, &transformsp); - - uiDrawRestore(p->Context); - uiDrawFreePath(path); - - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathAddRectangle(path, 40.0, 40.0, 100.0 - 40.0, 100.0 - 40.0); - uiDrawPathEnd(path); - - uiDrawMatrixSetIdentity(&mtranslate); - uiDrawMatrixTranslate(&mtranslate, 20.0, 10.0); - uiDrawMatrixSetIdentity(&mrotate); - uiDrawMatrixRotate(&mrotate, - 70.0, 70.0, - 45.0 * (uiPi / 180)); - - uiDrawStroke(p->Context, path, &original, &originalsp); - - uiDrawTransform(p->Context, &mtranslate); - uiDrawTransform(p->Context, &mrotate); - - uiDrawFill(p->Context, path, &fill); - uiDrawStroke(p->Context, path, &transform, &transformsp); - - uiDrawFreePath(path); -} - -// TODO https://msdn.microsoft.com/en-us/library/windows/desktop/dd756675%28v=vs.85%29.aspx - -// TODO https://msdn.microsoft.com/en-us/library/windows/desktop/dd756673%28v=vs.85%29.aspx - -// TODO https://msdn.microsoft.com/en-us/library/windows/desktop/dd756684%28v=vs.85%29.aspx - -// TODO dashing https://msdn.microsoft.com/en-us/library/windows/desktop/dd756683%28v=vs.85%29.aspx - -// from https://msdn.microsoft.com/en-us/library/windows/desktop/dd756682%28v=vs.85%29.aspx -static void drawD2DComplexShape(uiAreaDrawParams *p) -{ - uiDrawPath *path; - uiDrawBrush black; - uiDrawBrush gradient; - uiDrawBrushGradientStop stops[2]; - uiDrawStrokeParams sp; - uiDrawMatrix m; - - sp.Dashes = NULL; - sp.NumDashes = 0; - sp.DashPhase = 0; - - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(path, 0, 0); - uiDrawPathLineTo(path, 200, 0); - uiDrawPathBezierTo(path, - 150, 50, - 150, 150, - 200, 200); - uiDrawPathLineTo(path, 0, 200); - uiDrawPathBezierTo(path, - 50, 150, - 50, 50, - 0, 0); - uiDrawPathCloseFigure(path); - uiDrawPathEnd(path); - - d2dSolidBrush(&black, d2dBlack, 1.0); - - stops[0].Pos =0.0; - stops[0].R = 0.0; - stops[0].G = 1.0; - stops[0].B = 1.0; - stops[0].A = 0.25; - stops[1].Pos = 1.0; - stops[1].R = 0.0; - stops[1].G = 0.0; - stops[1].B = 1.0; - stops[1].A = 1.0; - gradient.Type = uiDrawBrushTypeLinearGradient; - gradient.X0 = 100; - gradient.Y0 = 0; - gradient.X1 = 100; - gradient.Y1 = 200; - gradient.Stops = stops; - gradient.NumStops = 2; - - uiDrawMatrixSetIdentity(&m); - uiDrawMatrixTranslate(&m, 20, 20); - uiDrawTransform(p->Context, &m); - - sp.Thickness = 10.0; - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.MiterLimit = uiDrawDefaultMiterLimit; - - uiDrawStroke(p->Context, path, &black, &sp); - uiDrawFill(p->Context, path, &gradient); - - uiDrawFreePath(path); -} - -// TODO https://msdn.microsoft.com/en-us/library/windows/desktop/dd756692%28v=vs.85%29.aspx - -// TODO https://msdn.microsoft.com/en-us/library/windows/desktop/dd756686%28v=vs.85%29.aspx - -// TODO https://msdn.microsoft.com/en-us/library/windows/desktop/dd756685%28v=vs.85%29.aspx - -// TODO https://msdn.microsoft.com/en-us/library/windows/desktop/dd756674%28v=vs.85%29.aspx - -// TODO? https://msdn.microsoft.com/en-us/library/windows/desktop/ee329947%28v=vs.85%29.aspx - -// TODO https://msdn.microsoft.com/en-us/library/windows/desktop/ff485857%28v=vs.85%29.aspx - -// TODO? https://msdn.microsoft.com/en-us/library/windows/desktop/dd756755%28v=vs.85%29.aspx - -// TODO go through the API reference and spot examples that aren't listed - -// TODO all of these https://msdn.microsoft.com/en-us/library/windows/desktop/dd368187%28v=vs.85%29.aspx - -// cairo Samples Page (http://cairographics.org/samples/) - -static void crsourcergba(uiDrawBrush *brush, double r, double g, double b, double a) -{ - brush->Type = uiDrawBrushTypeSolid; - brush->R = r; - brush->G = g; - brush->B = b; - brush->A = a; -} - -// arc -static void drawCSArc(uiAreaDrawParams *p) -{ - double xc = 128.0; - double yc = 128.0; - double radius = 100.0; - double angle1 = 45.0 * (uiPi / 180.0); - double angle2 = 180.0 * (uiPi / 180.0); - uiDrawBrush source; - uiDrawStrokeParams sp; - uiDrawPath *path; - - crsourcergba(&source, 0, 0, 0, 1); - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.MiterLimit = uiDrawDefaultMiterLimit; - sp.Dashes = NULL; - sp.NumDashes = 0; - sp.DashPhase = 0; - - sp.Thickness = 10.0; - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigureWithArc(path, - xc, yc, - radius, - angle1, - angle2 - angle1, - 0); - uiDrawPathEnd(path); - uiDrawStroke(p->Context, path, &source, &sp); - uiDrawFreePath(path); - - crsourcergba(&source, 1, 0.2, 0.2, 0.6); - sp.Thickness = 6.0; - - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigureWithArc(path, - xc, yc, - 10.0, - 0, 2 * uiPi, - 0); - uiDrawPathEnd(path); - uiDrawFill(p->Context, path, &source); - uiDrawFreePath(path); - - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigureWithArc(path, - xc, yc, - radius, - angle1, 0, - 0); - uiDrawPathLineTo(path, xc, yc); - uiDrawPathNewFigureWithArc(path, - xc, yc, - radius, - angle2, 0, - 0); - uiDrawPathLineTo(path, xc, yc); - uiDrawPathEnd(path); - uiDrawStroke(p->Context, path, &source, &sp); - uiDrawFreePath(path); -} - -// arc negative -static void drawCSArcNegative(uiAreaDrawParams *p) -{ - double xc = 128.0; - double yc = 128.0; - double radius = 100.0; - double angle1 = 45.0 * (uiPi / 180.0); - double angle2 = 180.0 * (uiPi / 180.0); - uiDrawBrush source; - uiDrawStrokeParams sp; - uiDrawPath *path; - - crsourcergba(&source, 0, 0, 0, 1); - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.MiterLimit = uiDrawDefaultMiterLimit; - sp.Dashes = NULL; - sp.NumDashes = 0; - sp.DashPhase = 0; - - sp.Thickness = 10.0; - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigureWithArc(path, - xc, yc, - radius, - angle1, - angle2 - angle1, - 1); - uiDrawPathEnd(path); - uiDrawStroke(p->Context, path, &source, &sp); - uiDrawFreePath(path); - - crsourcergba(&source, 1, 0.2, 0.2, 0.6); - sp.Thickness = 6.0; - - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigureWithArc(path, - xc, yc, - 10.0, - 0, 2 * uiPi, - 0); - uiDrawPathEnd(path); - uiDrawFill(p->Context, path, &source); - uiDrawFreePath(path); - - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigureWithArc(path, - xc, yc, - radius, - angle1, 0, - 0); - uiDrawPathLineTo(path, xc, yc); - uiDrawPathNewFigureWithArc(path, - xc, yc, - radius, - angle2, 0, - 0); - uiDrawPathLineTo(path, xc, yc); - uiDrawPathEnd(path); - uiDrawStroke(p->Context, path, &source, &sp); - uiDrawFreePath(path); -} - -// clip -static void drawCSClip(uiAreaDrawParams *p) -{ - uiDrawBrush source; - uiDrawStrokeParams sp; - uiDrawPath *path; - - crsourcergba(&source, 0, 0, 0, 1); - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.MiterLimit = uiDrawDefaultMiterLimit; - sp.Dashes = NULL; - sp.NumDashes = 0; - sp.DashPhase = 0; - - path = uiDrawNewPath(uiDrawFillModeWinding); - - uiDrawPathNewFigureWithArc(path, - 128.0, 128.0, - 76.8, - 0, 2 * uiPi, - 0); - uiDrawPathEnd(path); - uiDrawClip(p->Context, path); - uiDrawFreePath(path); - - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathAddRectangle(path, 0, 0, 256, 256); - uiDrawPathEnd(path); - uiDrawFill(p->Context, path, &source); - uiDrawFreePath(path); - - crsourcergba(&source, 0, 1, 0, 1); - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(path, 0, 0); - uiDrawPathLineTo(path, 256, 256); - uiDrawPathNewFigure(path, 256, 0); - uiDrawPathLineTo(path, 0, 256); - uiDrawPathEnd(path); - sp.Thickness = 10.0; - uiDrawStroke(p->Context, path, &source, &sp); - uiDrawFreePath(path); -} - -// TODO clip image - -// curve rectangle -static void drawCSCurveRectangle(uiAreaDrawParams *p) -{ - double x0 = 25.6, /* parameters like cairo_rectangle */ - y0 = 25.6, - rect_width = 204.8, - rect_height = 204.8, - radius = 102.4; /* and an approximate curvature radius */ - - double x1,y1; - - uiDrawBrush source; - uiDrawStrokeParams sp; - uiDrawPath *path; - - crsourcergba(&source, 0, 0, 0, 1); - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.MiterLimit = uiDrawDefaultMiterLimit; - sp.Dashes = NULL; - sp.NumDashes = 0; - sp.DashPhase = 0; - - path = uiDrawNewPath(uiDrawFillModeWinding); - - x1=x0+rect_width; - y1=y0+rect_height; - if (!rect_width || !rect_height) - return; - if (rect_width/2 < radius) { - if (rect_height/2Context, path, &source); - crsourcergba(&source, 0.5, 0, 0, 0.5); - sp.Thickness = 10.0; - uiDrawStroke(p->Context, path, &source, &sp); - - uiDrawFreePath(path); -} - -// curve to -static void drawCSCurveTo(uiAreaDrawParams *p) -{ - double x=25.6, y=128.0; - double x1=102.4, y1=230.4, - x2=153.6, y2=25.6, - x3=230.4, y3=128.0; - uiDrawBrush source; - uiDrawStrokeParams sp; - uiDrawPath *path; - - crsourcergba(&source, 0, 0, 0, 1); - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.MiterLimit = uiDrawDefaultMiterLimit; - sp.Dashes = NULL; - sp.NumDashes = 0; - sp.DashPhase = 0; - - path = uiDrawNewPath(uiDrawFillModeWinding); - - uiDrawPathNewFigure(path, x, y); - uiDrawPathBezierTo(path, x1, y1, x2, y2, x3, y3); - uiDrawPathEnd(path); - sp.Thickness = 10.0; - uiDrawStroke(p->Context, path, &source, &sp); - uiDrawFreePath(path); - - crsourcergba(&source, 1, 0.2, 0.2, 0.6); - sp.Thickness = 6.0; - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(path, x, y); - uiDrawPathLineTo(path, x1, y1); - uiDrawPathNewFigure(path, x2, y2); - uiDrawPathLineTo(path, x3, y3); - uiDrawPathEnd(path); - uiDrawStroke(p->Context, path, &source, &sp); - uiDrawFreePath(path); -} - -// dash -static void drawCSDash(uiAreaDrawParams *p) -{ - double dashes[] = { - 50.0, /* ink */ - 10.0, /* skip */ - 10.0, /* ink */ - 10.0 /* skip*/ - }; - int ndash = sizeof (dashes)/sizeof(dashes[0]); - double offset = -50.0; - - uiDrawBrush source; - uiDrawStrokeParams sp; - uiDrawPath *path; - - crsourcergba(&source, 0, 0, 0, 1); - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.MiterLimit = uiDrawDefaultMiterLimit; - sp.Dashes = dashes; - sp.NumDashes = ndash; - sp.DashPhase = offset; - sp.Thickness = 10.0; - - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(path, 128.0, 25.6); - uiDrawPathLineTo(path, 230.4, 230.4); - uiDrawPathLineTo(path, 230.4 -102.4, 230.4 + 0.0); - uiDrawPathBezierTo(path, - 51.2, 230.4, - 51.2, 128.0, - 128.0, 128.0); - uiDrawPathEnd(path); - - uiDrawStroke(p->Context, path, &source, &sp); - uiDrawFreePath(path); -} - -// fill and stroke2 -static void drawCSFillAndStroke2(uiAreaDrawParams *p) -{ - uiDrawBrush source; - uiDrawStrokeParams sp; - uiDrawPath *path; - - crsourcergba(&source, 0, 0, 0, 1); - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.MiterLimit = uiDrawDefaultMiterLimit; - sp.Dashes = NULL; - sp.NumDashes = 0; - sp.DashPhase = 0; - - path = uiDrawNewPath(uiDrawFillModeWinding); - - uiDrawPathNewFigure(path, 128.0, 25.6); - uiDrawPathLineTo(path, 230.4, 230.4); - uiDrawPathLineTo(path, 230.4 - 102.4, 230.4 + 0.0); - uiDrawPathBezierTo(path, 51.2, 230.4, 51.2, 128.0, 128.0, 128.0); - uiDrawPathCloseFigure(path); - - uiDrawPathNewFigure(path, 64.0, 25.6); - uiDrawPathLineTo(path, 64.0 + 51.2, 25.6 + 51.2); - uiDrawPathLineTo(path, 64.0 + 51.2 -51.2, 25.6 + 51.2 + 51.2); - uiDrawPathLineTo(path, 64.0 + 51.2 -51.2 -51.2, 25.6 + 51.2 + 51.2 -51.2); - uiDrawPathCloseFigure(path); - - uiDrawPathEnd(path); - - sp.Thickness = 10.0; - crsourcergba(&source, 0, 0, 1, 1); - uiDrawFill(p->Context, path, &source); - crsourcergba(&source, 0, 0, 0, 1); - uiDrawStroke(p->Context, path, &source, &sp); - uiDrawFreePath(path); -} - -// fill style -static void drawCSFillStyle(uiAreaDrawParams *p) -{ - uiDrawBrush source; - uiDrawStrokeParams sp; - uiDrawPath *path; - uiDrawMatrix m; - - crsourcergba(&source, 0, 0, 0, 1); - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.MiterLimit = uiDrawDefaultMiterLimit; - sp.Dashes = NULL; - sp.NumDashes = 0; - sp.DashPhase = 0; - - sp.Thickness = 6; - - path = uiDrawNewPath(uiDrawFillModeAlternate); - uiDrawPathAddRectangle(path, 12, 12, 232, 70); - uiDrawPathNewFigureWithArc(path, - 64, 64, - 40, - 0, 2*uiPi, - 0); - uiDrawPathNewFigureWithArc(path, - 192, 64, - 40, - 0, -2*uiPi, - 1); - uiDrawPathEnd(path); - - crsourcergba(&source, 0, 0.7, 0, 1); - uiDrawFill(p->Context, path, &source); - crsourcergba(&source, 0, 0, 0, 1); - uiDrawStroke(p->Context, path, &source, &sp); - uiDrawFreePath(path); - - uiDrawMatrixSetIdentity(&m); - uiDrawMatrixTranslate(&m, 0, 128); - uiDrawTransform(p->Context, &m); - - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathAddRectangle(path, 12, 12, 232, 70); - uiDrawPathNewFigureWithArc(path, - 64, 64, - 40, - 0, 2*uiPi, - 0); - uiDrawPathNewFigureWithArc(path, - 192, 64, - 40, - 0, -2*uiPi, - 1); - uiDrawPathEnd(path); - - crsourcergba(&source, 0, 0, 0.9, 1); - uiDrawFill(p->Context, path, &source); - crsourcergba(&source, 0, 0, 0, 1); - uiDrawStroke(p->Context, path, &source, &sp); - uiDrawFreePath(path); -} - -// TOOD gradient (radial gradient with two circles) - -// TODO image - -// TODO imagepattern - -// multi segment caps -static void drawCSMultiCaps(uiAreaDrawParams *p) -{ - uiDrawBrush source; - uiDrawStrokeParams sp; - uiDrawPath *path; - - crsourcergba(&source, 0, 0, 0, 1); - sp.Join = uiDrawLineJoinMiter; - sp.MiterLimit = uiDrawDefaultMiterLimit; - sp.Dashes = NULL; - sp.NumDashes = 0; - sp.DashPhase = 0; - - path = uiDrawNewPath(uiDrawFillModeWinding); - - uiDrawPathNewFigure(path, 50.0, 75.0); - uiDrawPathLineTo(path, 200.0, 75.0); - - uiDrawPathNewFigure(path, 50.0, 125.0); - uiDrawPathLineTo(path, 200.0, 125.0); - - uiDrawPathNewFigure(path, 50.0, 175.0); - uiDrawPathLineTo(path, 200.0, 175.0); - uiDrawPathEnd(path); - - sp.Thickness = 30.0; - sp.Cap = uiDrawLineCapRound; - uiDrawStroke(p->Context, path, &source, &sp); - uiDrawFreePath(path); -} - -// rounded rectangle -static void drawCSRoundRect(uiAreaDrawParams *p) -{ - double x = 25.6, /* parameters like cairo_rectangle */ - y = 25.6, - width = 204.8, - height = 204.8, - aspect = 1.0, /* aspect ratio */ - corner_radius = height / 10.0; /* and corner curvature radius */ - - double radius = corner_radius / aspect; - double degrees = uiPi / 180.0; - - uiDrawBrush source; - uiDrawStrokeParams sp; - uiDrawPath *path; - - crsourcergba(&source, 0, 0, 0, 1); - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.MiterLimit = uiDrawDefaultMiterLimit; - sp.Dashes = NULL; - sp.NumDashes = 0; - sp.DashPhase = 0; - - path = uiDrawNewPath(uiDrawFillModeWinding); - - // top right corner - uiDrawPathNewFigureWithArc(path, - x + width - radius, y + radius, - radius, - -90 * degrees, uiPi / 2, - 0); - // bottom right corner - uiDrawPathArcTo(path, - x + width - radius, y + height - radius, - radius, - 0 * degrees, uiPi / 2, - 0); - // bottom left corner - uiDrawPathArcTo(path, - x + radius, y + height - radius, - radius, - 90 * degrees, uiPi / 2, - 0); - // top left corner - uiDrawPathArcTo(path, - x + radius, y + radius, - radius, - 180 * degrees, uiPi / 2, - 0); - uiDrawPathCloseFigure(path); - uiDrawPathEnd(path); - - crsourcergba(&source, 0.5, 0.5, 1, 1); - uiDrawFill(p->Context, path, &source); - crsourcergba(&source, 0.5, 0, 0, 0.5); - sp.Thickness = 10.0; - uiDrawStroke(p->Context, path, &source, &sp); - uiDrawFreePath(path); -} - -// set line cap -static void drawCSSetLineCap(uiAreaDrawParams *p) -{ - uiDrawBrush source; - uiDrawStrokeParams sp; - uiDrawPath *path; - - crsourcergba(&source, 0, 0, 0, 1); - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.MiterLimit = uiDrawDefaultMiterLimit; - sp.Dashes = NULL; - sp.NumDashes = 0; - sp.DashPhase = 0; - - sp.Thickness = 30.0; - - sp.Cap = uiDrawLineCapFlat; - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(path, 64.0, 50.0); - uiDrawPathLineTo(path, 64.0, 200.0); - uiDrawPathEnd(path); - uiDrawStroke(p->Context, path, &source, &sp); - uiDrawFreePath(path); - - sp.Cap = uiDrawLineCapRound; - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(path, 128.0, 50.0); - uiDrawPathLineTo(path, 128.0, 200.0); - uiDrawPathEnd(path); - uiDrawStroke(p->Context, path, &source, &sp); - uiDrawFreePath(path); - - sp.Cap = uiDrawLineCapSquare; - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(path, 192.0, 50.0); - uiDrawPathLineTo(path, 192.0, 200.0); - uiDrawPathEnd(path); - uiDrawStroke(p->Context, path, &source, &sp); - uiDrawFreePath(path); - - // draw helping lines - // keep the square cap to match the reference picture on the cairo website - crsourcergba(&source, 1, 0.2, 0.2, 1); - sp.Thickness = 2.56; - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(path, 64.0, 50.0); - uiDrawPathLineTo(path, 64.0, 200.0); - uiDrawPathNewFigure(path, 128.0, 50.0); - uiDrawPathLineTo(path, 128.0, 200.0); - uiDrawPathNewFigure(path, 192.0, 50.0); - uiDrawPathLineTo(path, 192.0, 200.0); - uiDrawPathEnd(path); - uiDrawStroke(p->Context, path, &source, &sp); - uiDrawFreePath(path); -} - -// set line join -static void drawCSSetLineJoin(uiAreaDrawParams *p) -{ - uiDrawBrush source; - uiDrawStrokeParams sp; - uiDrawPath *path; - - crsourcergba(&source, 0, 0, 0, 1); - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.MiterLimit = uiDrawDefaultMiterLimit; - sp.Dashes = NULL; - sp.NumDashes = 0; - sp.DashPhase = 0; - - sp.Thickness = 40.96; - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(path, 76.8, 84.48); - uiDrawPathLineTo(path, 76.8 + 51.2, 84.48 -51.2); - uiDrawPathLineTo(path, 76.8 + 51.2 + 51.2, 84.48 - 51.2 + 51.2); - uiDrawPathEnd(path); - sp.Join = uiDrawLineJoinMiter; - uiDrawStroke(p->Context, path, &source, &sp); - uiDrawFreePath(path); - - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(path, 76.8, 161.28); - uiDrawPathLineTo(path, 76.8 + 51.2, 161.28 -51.2); - uiDrawPathLineTo(path, 76.8 + 51.2 + 51.2, 161.28 - 51.2 + 51.2); - uiDrawPathEnd(path); - sp.Join = uiDrawLineJoinBevel; - uiDrawStroke(p->Context, path, &source, &sp); - uiDrawFreePath(path); - - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(path, 76.8, 238.08); - uiDrawPathLineTo(path, 76.8 + 51.2, 238.08 -51.2); - uiDrawPathLineTo(path, 76.8 + 51.2 + 51.2, 238.08 - 51.2 + 51.2); - uiDrawPathEnd(path); - sp.Join = uiDrawLineJoinRound; - uiDrawStroke(p->Context, path, &source, &sp); - uiDrawFreePath(path); -} - -// TODO text - -// TODO text align center - -// TODO text extents - -// Quartz 2D Programming Guide - -static void cgaddrect(uiDrawPath *path, uiAreaDrawParams *p, double x, double y, double width, double height) -{ - uiDrawPathAddRectangle(path, - x, p->AreaHeight - y - height, - width, height); -} - -// Graphics Contexts > Creating a Window Graphics Context in Mac OS X -static void drawQ2DCreateWindowGC(uiAreaDrawParams *p) -{ - uiDrawPath *path; - uiDrawBrush brush; - - crsourcergba(&brush, 1, 0, 0, 1); - path = uiDrawNewPath(uiDrawFillModeWinding); - cgaddrect(path, p, 0, 0, 200, 100); - uiDrawPathEnd(path); - uiDrawFill(p->Context, path, &brush); - uiDrawFreePath(path); - - crsourcergba(&brush, 0, 0, 1, .5); - path = uiDrawNewPath(uiDrawFillModeWinding); - cgaddrect(path, p, 0, 0, 100, 200); - uiDrawPathEnd(path); - uiDrawFill(p->Context, path, &brush); - uiDrawFreePath(path); -} - -// TODO Patterns page? - -// TODO Shadows page? - -// TODO Gradients page (includes some circle-circle radial gradients) - -// TODO Transparency Layers page? - -// TODO Core Graphics Layer Drawing page? - -// Cocoa Drawing Guide - -// TODO Advanced Drawing Techniques page? - -// TODO Text page, if any? - -static const struct drawtest tests[] = { - { "Original uiArea test", drawOriginal }, - { "Arc test", drawArcs }, - { "Direct2D: Direct2D Quickstart for Windows 8", drawD2DW8QS }, - { "Direct2D: Creating a Simple Direct2D Application", drawD2DSimpleApp }, - { "Direct2D: How to Create a Solid Color Brush", drawD2DSolidBrush }, - { "Direct2D: How to Create a Linear Gradient Brush", drawD2DLinearBrush }, - { "Direct2D: How to Create a Radial Gradient Brush", drawD2DRadialBrush }, - { "Direct2D: Path Geometries Overview", drawD2DPathGeometries }, - { "Direct2D: How to Create Geometry Groups", drawD2DGeometryGroup }, - { "Direct2D: How to Rotate an Object", drawD2DRotate }, - { "Direct2D: How to Scale an Object", drawD2DScale }, - { "Direct2D: How to Skew an Object", drawD2DSkew }, - { "Direct2D: How to Translate an Object", drawD2DTranslate }, - { "Direct2D: How to Apply Multiple Transforms to an Object", drawD2DMultiTransforms }, - { "Direct2D: How to Draw and Fill a Complex Shape", drawD2DComplexShape }, - { "cairo samples: arc", drawCSArc }, - { "cairo samples: arc negative", drawCSArcNegative }, - { "cairo samples: clip", drawCSClip }, - { "cairo samples: curve rectangle", drawCSCurveRectangle }, - { "cairo samples: curve to", drawCSCurveTo }, - { "cairo samples: dash", drawCSDash }, - { "cairo samples: fill and stroke2", drawCSFillAndStroke2 }, - { "cairo samples: fill style", drawCSFillStyle }, - { "cairo samples: multi segment caps", drawCSMultiCaps }, - { "cairo samples: rounded rectangle", drawCSRoundRect }, - { "cairo samples: set line cap", drawCSSetLineCap }, - { "cairo samples: set line join", drawCSSetLineJoin }, - { "Quartz 2D PG: Creating a Window Graphics Context in Mac OS X", drawQ2DCreateWindowGC }, - { NULL, NULL }, -}; - -void runDrawTest(int n, uiAreaDrawParams *p) -{ - (*(tests[n].draw))(p); -} - -void populateComboboxWithTests(uiCombobox *c) -{ - size_t i; - - for (i = 0; tests[i].name != NULL; i++) - uiComboboxAppend(c, tests[i].name); -} diff --git a/src/libui_sdl/libui/test/images/andlabs_16x16test_24june2016.png b/src/libui_sdl/libui/test/images/andlabs_16x16test_24june2016.png deleted file mode 100644 index a4c27d9..0000000 Binary files a/src/libui_sdl/libui/test/images/andlabs_16x16test_24june2016.png and /dev/null differ diff --git a/src/libui_sdl/libui/test/images/andlabs_32x32test_24june2016.png b/src/libui_sdl/libui/test/images/andlabs_32x32test_24june2016.png deleted file mode 100644 index e1c33fc..0000000 Binary files a/src/libui_sdl/libui/test/images/andlabs_32x32test_24june2016.png and /dev/null differ diff --git a/src/libui_sdl/libui/test/images/gen.go b/src/libui_sdl/libui/test/images/gen.go deleted file mode 100644 index 910abc7..0000000 --- a/src/libui_sdl/libui/test/images/gen.go +++ /dev/null @@ -1,98 +0,0 @@ -// 25 june 2016 -package main - -import ( - "fmt" - "os" - "image" - "image/draw" - _ "image/png" -) - -type img struct { - filename string - data []byte - width int - height int - stride int -} - -func main() { - if len(os.Args[1:]) == 0 { - panic("no files specified") - } - - images := make([]*img, 0, len(os.Args[1:])) - for _, fn := range os.Args[1:] { - f, err := os.Open(fn) - if err != nil { - panic(err) - } - ii, _, err := image.Decode(f) - if err != nil { - panic(err) - } - f.Close() - - i := image.NewRGBA(ii.Bounds()) - draw.Draw(i, i.Rect, ii, ii.Bounds().Min, draw.Src) - - im := &img{ - filename: fn, - data: i.Pix, - width: i.Rect.Dx(), - height: i.Rect.Dy(), - stride: i.Stride, - } - images = append(images, im) - } - - fmt.Println("// auto-generated by images/gen.go") - fmt.Println("#include \"test.h\"") - fmt.Println() - for i, im := range images { - fmt.Printf("static const uint32_t dat%d[] = {", i) - for j := 0; j < len(im.data); j += 4 { - if (j % (16 * 4)) == 0 { - fmt.Printf("\n\t") - } else { - fmt.Printf(" ") - } - d := uint32(im.data[j + 0]) << 16 - d |= uint32(im.data[j + 1]) << 8 - d |= uint32(im.data[j + 2]) - d |= uint32(im.data[j + 3]) << 24 - fmt.Printf("0x%08X,", d) - - } - fmt.Println("\n};") - fmt.Println() - } - fmt.Println("static const struct {") - fmt.Println(" const char *name;") - fmt.Println(" void *data;") - fmt.Println(" int width;") - fmt.Println(" int height;") - fmt.Println(" int stride;") - fmt.Println("} files[] = {") - for i, im := range images { - fmt.Printf(" { %q, dat%d, %d, %d, %d },\n", - im.filename, i, im.width, im.height, im.stride) - } - fmt.Println("};") - fmt.Println() - fmt.Println("void appendImageNamed(uiImage *img, const char *name)") - fmt.Println("{") - fmt.Println(" int i;") - fmt.Println("") - fmt.Println(" i = 0;") - fmt.Println(" for (;;) {") - fmt.Println(" if (strcmp(name, files[i].name) == 0) {") - fmt.Println(" uiImageAppend(img, files[i].data, files[i].width, files[i].height, files[i].stride);") - fmt.Println(" return;") - fmt.Println(" }") - fmt.Println(" i++;") - fmt.Println(" }") - fmt.Println("}") - fmt.Println() -} diff --git a/src/libui_sdl/libui/test/images/tango-icon-theme-0.8.90_16x16_x-office-spreadsheet.png b/src/libui_sdl/libui/test/images/tango-icon-theme-0.8.90_16x16_x-office-spreadsheet.png deleted file mode 100644 index a6b1268..0000000 Binary files a/src/libui_sdl/libui/test/images/tango-icon-theme-0.8.90_16x16_x-office-spreadsheet.png and /dev/null differ diff --git a/src/libui_sdl/libui/test/images/tango-icon-theme-0.8.90_32x32_x-office-spreadsheet.png b/src/libui_sdl/libui/test/images/tango-icon-theme-0.8.90_32x32_x-office-spreadsheet.png deleted file mode 100644 index c0ccb7a..0000000 Binary files a/src/libui_sdl/libui/test/images/tango-icon-theme-0.8.90_32x32_x-office-spreadsheet.png and /dev/null differ diff --git a/src/libui_sdl/libui/test/main.c b/src/libui_sdl/libui/test/main.c deleted file mode 100644 index 18774dc..0000000 --- a/src/libui_sdl/libui/test/main.c +++ /dev/null @@ -1,180 +0,0 @@ -// 22 april 2015 -#include "test.h" - -// TODOs -// - blank page affects menus negatively on Windows - -void die(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - fprintf(stderr, "[test program] "); - vfprintf(stderr, fmt, ap); - fprintf(stderr, "\n"); - va_end(ap); - abort(); -} - -int onClosing(uiWindow *w, void *data) -{ - printf("in onClosing()\n"); - uiQuit(); - return 1; -} - -int onShouldQuit(void *data) -{ - printf("in onShouldQuit()\n"); - if (uiMenuItemChecked(shouldQuitItem)) { - uiControlDestroy(uiControl(data)); - return 1; - } - return 0; -} - -uiBox *mainBox; -uiTab *mainTab; - -uiBox *(*newhbox)(void); -uiBox *(*newvbox)(void); - -int main(int argc, char *argv[]) -{ - uiInitOptions o; - int i; - const char *err; - uiWindow *w; - uiBox *page2, *page3, *page4, *page5; - uiBox *page6, *page7, *page8, *page9, *page10; - uiBox *page11, *page12, *page13; - uiTab *page14; - uiBox *page15; - uiBox *page16; - uiTab *outerTab; - uiTab *innerTab; - int nomenus = 0; - int startspaced = 0; - int steps = 0; - - newhbox = uiNewHorizontalBox; - newvbox = uiNewVerticalBox; - - memset(&o, 0, sizeof (uiInitOptions)); - for (i = 1; i < argc; i++) - if (strcmp(argv[i], "nomenus") == 0) - nomenus = 1; - else if (strcmp(argv[i], "startspaced") == 0) - startspaced = 1; - else if (strcmp(argv[i], "swaphv") == 0) { - newhbox = uiNewVerticalBox; - newvbox = uiNewHorizontalBox; - } else if (strcmp(argv[i], "steps") == 0) - steps = 1; - else { - fprintf(stderr, "%s: unrecognized option %s\n", argv[0], argv[i]); - return 1; - } - - err = uiInit(&o); - if (err != NULL) { - fprintf(stderr, "error initializing ui: %s\n", err); - uiFreeInitError(err); - return 1; - } - - if (!nomenus) - initMenus(); - - w = newWindow("Main Window", 320, 240, 1); - uiWindowOnClosing(w, onClosing, NULL); - printf("main window %p\n", (void *) w); - - uiOnShouldQuit(onShouldQuit, w); - - mainBox = newHorizontalBox(); - uiWindowSetChild(w, uiControl(mainBox)); - - outerTab = newTab(); - uiBoxAppend(mainBox, uiControl(outerTab), 1); - - mainTab = newTab(); - uiTabAppend(outerTab, "Pages 1-5", uiControl(mainTab)); - - // page 1 uses page 2's uiGroup - page2 = makePage2(); - - makePage1(w); - uiTabAppend(mainTab, "Page 1", uiControl(page1)); - - uiTabAppend(mainTab, "Page 2", uiControl(page2)); - - uiTabAppend(mainTab, "Empty Page", uiControl(uiNewHorizontalBox())); - - page3 = makePage3(); - uiTabAppend(mainTab, "Page 3", uiControl(page3)); - - page4 = makePage4(); - uiTabAppend(mainTab, "Page 4", uiControl(page4)); - - page5 = makePage5(w); - uiTabAppend(mainTab, "Page 5", uiControl(page5)); - - innerTab = newTab(); - uiTabAppend(outerTab, "Pages 6-10", uiControl(innerTab)); - - page6 = makePage6(); - uiTabAppend(innerTab, "Page 6", uiControl(page6)); - - page7 = makePage7(); - uiTabAppend(innerTab, "Page 7", uiControl(page7)); - - page8 = makePage8(); - uiTabAppend(innerTab, "Page 8", uiControl(page8)); - - page9 = makePage9(); - uiTabAppend(innerTab, "Page 9", uiControl(page9)); - - page10 = makePage10(); - uiTabAppend(innerTab, "Page 10", uiControl(page10)); - - innerTab = newTab(); - uiTabAppend(outerTab, "Pages 11-15", uiControl(innerTab)); - -// page11 = makePage11(); -// uiTabAppend(innerTab, "Page 11", uiControl(page11)); - - page12 = makePage12(); - uiTabAppend(innerTab, "Page 12", uiControl(page12)); - - page13 = makePage13(); - uiTabAppend(innerTab, "Page 13", uiControl(page13)); - - page14 = makePage14(); - uiTabAppend(innerTab, "Page 14", uiControl(page14)); - - page15 = makePage15(w); - uiTabAppend(innerTab, "Page 15", uiControl(page15)); - - innerTab = newTab(); - uiTabAppend(outerTab, "Pages 16-?", uiControl(innerTab)); - -// page16 = makePage16(); -// uiTabAppend(innerTab, "Page 16", uiControl(page16)); - - if (startspaced) - setSpaced(1); - - uiControlShow(uiControl(w)); - if (!steps) - uiMain(); - else { - uiMainSteps(); - while (uiMainStep(1)) - ; - } - printf("after uiMain()\n"); - uiUninit(); - printf("after uiUninit()\n"); - return 0; -} diff --git a/src/libui_sdl/libui/test/menus.c b/src/libui_sdl/libui/test/menus.c deleted file mode 100644 index 87ff80a..0000000 --- a/src/libui_sdl/libui/test/menus.c +++ /dev/null @@ -1,112 +0,0 @@ -// 23 april 2015 -#include "test.h" - -uiMenu *fileMenu; -uiMenuItem *newItem; -uiMenuItem *openItem; -uiMenuItem *shouldQuitItem; -uiMenuItem *quitItem; -uiMenu *editMenu; -uiMenuItem *undoItem; -uiMenuItem *checkItem; -uiMenuItem *accelItem; -uiMenuItem *prefsItem; -uiMenu *testMenu; -uiMenuItem *enabledItem; -uiMenuItem *enableThisItem; -uiMenuItem *forceCheckedItem; -uiMenuItem *forceUncheckedItem; -uiMenuItem *whatWindowItem; -uiMenu *moreTestsMenu; -uiMenuItem *quitEnabledItem; -uiMenuItem *prefsEnabledItem; -uiMenuItem *aboutEnabledItem; -uiMenuItem *checkEnabledItem; -uiMenu *multiMenu; -uiMenu *helpMenu; -uiMenuItem *helpItem; -uiMenuItem *aboutItem; - -static void enableItemTest(uiMenuItem *item, uiWindow *w, void *data) -{ - if (uiMenuItemChecked(item)) - uiMenuItemEnable(uiMenuItem(data)); - else - uiMenuItemDisable(uiMenuItem(data)); -} - -static void forceOn(uiMenuItem *item, uiWindow *w, void *data) -{ - uiMenuItemSetChecked(enabledItem, 1); -} - -static void forceOff(uiMenuItem *item, uiWindow *w, void *data) -{ - uiMenuItemSetChecked(enabledItem, 0); -} - -static void whatWindow(uiMenuItem *item, uiWindow *w, void *data) -{ - printf("menu item clicked on window %p\n", (void *) w); -} - -void initMenus(void) -{ - fileMenu = uiNewMenu("File"); - newItem = uiMenuAppendItem(fileMenu, "New"); - openItem = uiMenuAppendItem(fileMenu, "Open"); - uiMenuAppendSeparator(fileMenu); - shouldQuitItem = uiMenuAppendCheckItem(fileMenu, "Should Quit"); - quitItem = uiMenuAppendQuitItem(fileMenu); - - editMenu = uiNewMenu("Edit"); - undoItem = uiMenuAppendItem(editMenu, "Undo"); - uiMenuItemDisable(undoItem); - uiMenuAppendSeparator(editMenu); - checkItem = uiMenuAppendCheckItem(editMenu, "Check Me\tTest"); - accelItem = uiMenuAppendItem(editMenu, "A&ccele&&rator T_es__t"); - prefsItem = uiMenuAppendPreferencesItem(editMenu); - - testMenu = uiNewMenu("Test"); - enabledItem = uiMenuAppendCheckItem(testMenu, "Enable Below Item"); - uiMenuItemSetChecked(enabledItem, 1); - enableThisItem = uiMenuAppendItem(testMenu, "This Will Be Enabled"); - uiMenuItemOnClicked(enabledItem, enableItemTest, enableThisItem); - forceCheckedItem = uiMenuAppendItem(testMenu, "Force Above Checked"); - uiMenuItemOnClicked(forceCheckedItem, forceOn, NULL); - forceUncheckedItem = uiMenuAppendItem(testMenu, "Force Above Unchecked"); - uiMenuItemOnClicked(forceUncheckedItem, forceOff, NULL); - uiMenuAppendSeparator(testMenu); - whatWindowItem = uiMenuAppendItem(testMenu, "What Window?"); - uiMenuItemOnClicked(whatWindowItem, whatWindow, NULL); - - moreTestsMenu = uiNewMenu("More Tests"); - quitEnabledItem = uiMenuAppendCheckItem(moreTestsMenu, "Quit Item Enabled"); - uiMenuItemSetChecked(quitEnabledItem, 1); - prefsEnabledItem = uiMenuAppendCheckItem(moreTestsMenu, "Preferences Item Enabled"); - uiMenuItemSetChecked(prefsEnabledItem, 1); - aboutEnabledItem = uiMenuAppendCheckItem(moreTestsMenu, "About Item Enabled"); - uiMenuItemSetChecked(aboutEnabledItem, 1); - uiMenuAppendSeparator(moreTestsMenu); - checkEnabledItem = uiMenuAppendCheckItem(moreTestsMenu, "Check Me Item Enabled"); - uiMenuItemSetChecked(checkEnabledItem, 1); - - multiMenu = uiNewMenu("Multi"); - uiMenuAppendSeparator(multiMenu); - uiMenuAppendSeparator(multiMenu); - uiMenuAppendItem(multiMenu, "Item && Item && Item"); - uiMenuAppendSeparator(multiMenu); - uiMenuAppendSeparator(multiMenu); - uiMenuAppendItem(multiMenu, "Item __ Item __ Item"); - uiMenuAppendSeparator(multiMenu); - uiMenuAppendSeparator(multiMenu); - - helpMenu = uiNewMenu("Help"); - helpItem = uiMenuAppendItem(helpMenu, "Help"); - aboutItem = uiMenuAppendAboutItem(helpMenu); - - uiMenuItemOnClicked(quitEnabledItem, enableItemTest, quitItem); - uiMenuItemOnClicked(prefsEnabledItem, enableItemTest, prefsItem); - uiMenuItemOnClicked(aboutEnabledItem, enableItemTest, aboutItem); - uiMenuItemOnClicked(checkEnabledItem, enableItemTest, checkItem); -} diff --git a/src/libui_sdl/libui/test/page1.c b/src/libui_sdl/libui/test/page1.c deleted file mode 100644 index 2115ba2..0000000 --- a/src/libui_sdl/libui/test/page1.c +++ /dev/null @@ -1,171 +0,0 @@ -// 29 april 2015 -#include "test.h" - -static uiEntry *entry; -static uiCheckbox *spaced; - -#define TEXT(name, type, getter, setter) \ - static void get ## name ## Text(uiButton *b, void *data) \ - { \ - char *text; \ - text = getter(type(data)); \ - uiEntrySetText(entry, text); \ - uiFreeText(text); \ - } \ - static void set ## name ## Text(uiButton *b, void *data) \ - { \ - char *text; \ - text = uiEntryText(entry); \ - setter(type(data), text); \ - uiFreeText(text); \ - } -TEXT(Window, uiWindow, uiWindowTitle, uiWindowSetTitle) -TEXT(Button, uiButton, uiButtonText, uiButtonSetText) -TEXT(Checkbox, uiCheckbox, uiCheckboxText, uiCheckboxSetText) -TEXT(Label, uiLabel, uiLabelText, uiLabelSetText) -TEXT(Group, uiGroup, uiGroupTitle, uiGroupSetTitle) - -static void onChanged(uiEntry *e, void *data) -{ - printf("onChanged()\n"); -} - -static void toggleSpaced(uiCheckbox *c, void *data) -{ - setSpaced(uiCheckboxChecked(spaced)); -} - -static void forceSpaced(uiButton *b, void *data) -{ - uiCheckboxSetChecked(spaced, data != NULL); -} - -static void showSpaced(uiButton *b, void *data) -{ - char s[12]; - - querySpaced(s); - uiEntrySetText(entry, s); -} - -#define SHED(method, Method) \ - static void method ## Control(uiButton *b, void *data) \ - { \ - uiControl ## Method(uiControl(data)); \ - } -SHED(show, Show) -SHED(hide, Hide) -SHED(enable, Enable) -SHED(disable, Disable) - -uiBox *page1; - -void makePage1(uiWindow *w) -{ - uiButton *getButton, *setButton; - uiBox *hbox; - uiBox *testBox; - uiLabel *label; - - page1 = newVerticalBox(); - - entry = uiNewEntry(); - uiEntryOnChanged(entry, onChanged, NULL); - uiBoxAppend(page1, uiControl(entry), 0); - - spaced = uiNewCheckbox("Spaced"); - uiCheckboxOnToggled(spaced, toggleSpaced, NULL); - label = uiNewLabel("Label"); - - hbox = newHorizontalBox(); - getButton = uiNewButton("Get Window Text"); - uiButtonOnClicked(getButton, getWindowText, w); - setButton = uiNewButton("Set Window Text"); - uiButtonOnClicked(setButton, setWindowText, w); - uiBoxAppend(hbox, uiControl(getButton), 1); - uiBoxAppend(hbox, uiControl(setButton), 1); - uiBoxAppend(page1, uiControl(hbox), 0); - - hbox = newHorizontalBox(); - getButton = uiNewButton("Get Button Text"); - uiButtonOnClicked(getButton, getButtonText, getButton); - setButton = uiNewButton("Set Button Text"); - uiButtonOnClicked(setButton, setButtonText, getButton); - uiBoxAppend(hbox, uiControl(getButton), 1); - uiBoxAppend(hbox, uiControl(setButton), 1); - uiBoxAppend(page1, uiControl(hbox), 0); - - hbox = newHorizontalBox(); - getButton = uiNewButton("Get Checkbox Text"); - uiButtonOnClicked(getButton, getCheckboxText, spaced); - setButton = uiNewButton("Set Checkbox Text"); - uiButtonOnClicked(setButton, setCheckboxText, spaced); - uiBoxAppend(hbox, uiControl(getButton), 1); - uiBoxAppend(hbox, uiControl(setButton), 1); - uiBoxAppend(page1, uiControl(hbox), 0); - - hbox = newHorizontalBox(); - getButton = uiNewButton("Get Label Text"); - uiButtonOnClicked(getButton, getLabelText, label); - setButton = uiNewButton("Set Label Text"); - uiButtonOnClicked(setButton, setLabelText, label); - uiBoxAppend(hbox, uiControl(getButton), 1); - uiBoxAppend(hbox, uiControl(setButton), 1); - uiBoxAppend(page1, uiControl(hbox), 0); - - hbox = newHorizontalBox(); - getButton = uiNewButton("Get Group Text"); - uiButtonOnClicked(getButton, getGroupText, page2group); - setButton = uiNewButton("Set Group Text"); - uiButtonOnClicked(setButton, setGroupText, page2group); - uiBoxAppend(hbox, uiControl(getButton), 1); - uiBoxAppend(hbox, uiControl(setButton), 1); - uiBoxAppend(page1, uiControl(hbox), 0); - - hbox = newHorizontalBox(); - uiBoxAppend(hbox, uiControl(spaced), 1); - getButton = uiNewButton("On"); - uiButtonOnClicked(getButton, forceSpaced, getButton); - uiBoxAppend(hbox, uiControl(getButton), 0); - getButton = uiNewButton("Off"); - uiButtonOnClicked(getButton, forceSpaced, NULL); - uiBoxAppend(hbox, uiControl(getButton), 0); - getButton = uiNewButton("Show"); - uiButtonOnClicked(getButton, showSpaced, NULL); - uiBoxAppend(hbox, uiControl(getButton), 0); - uiBoxAppend(page1, uiControl(hbox), 0); - - testBox = newHorizontalBox(); - setButton = uiNewButton("Button"); - uiBoxAppend(testBox, uiControl(setButton), 1); - getButton = uiNewButton("Show"); - uiButtonOnClicked(getButton, showControl, setButton); - uiBoxAppend(testBox, uiControl(getButton), 0); - getButton = uiNewButton("Hide"); - uiButtonOnClicked(getButton, hideControl, setButton); - uiBoxAppend(testBox, uiControl(getButton), 0); - getButton = uiNewButton("Enable"); - uiButtonOnClicked(getButton, enableControl, setButton); - uiBoxAppend(testBox, uiControl(getButton), 0); - getButton = uiNewButton("Disable"); - uiButtonOnClicked(getButton, disableControl, setButton); - uiBoxAppend(testBox, uiControl(getButton), 0); - uiBoxAppend(page1, uiControl(testBox), 0); - - hbox = newHorizontalBox(); - getButton = uiNewButton("Show Box"); - uiButtonOnClicked(getButton, showControl, testBox); - uiBoxAppend(hbox, uiControl(getButton), 1); - getButton = uiNewButton("Hide Box"); - uiButtonOnClicked(getButton, hideControl, testBox); - uiBoxAppend(hbox, uiControl(getButton), 1); - getButton = uiNewButton("Enable Box"); - uiButtonOnClicked(getButton, enableControl, testBox); - uiBoxAppend(hbox, uiControl(getButton), 1); - getButton = uiNewButton("Disable Box"); - uiButtonOnClicked(getButton, disableControl, testBox); - uiBoxAppend(hbox, uiControl(getButton), 1); - uiBoxAppend(page1, uiControl(hbox), 0); - - uiBoxAppend(page1, uiControl(label), 0); -} diff --git a/src/libui_sdl/libui/test/page10.c b/src/libui_sdl/libui/test/page10.c deleted file mode 100644 index d7f26a7..0000000 --- a/src/libui_sdl/libui/test/page10.c +++ /dev/null @@ -1,185 +0,0 @@ -// 22 december 2015 -#include "test.h" - -static uiEntry *textString; -static uiFontButton *textFontButton; -static uiColorButton *textColorButton; -static uiEntry *textWidth; -static uiButton *textApply; -static uiCheckbox *noZ; -static uiArea *textArea; -static uiAreaHandler textAreaHandler; - -static double entryDouble(uiEntry *e) -{ - char *s; - double d; - - s = uiEntryText(e); - d = atof(s); - uiFreeText(s); - return d; -} - -static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *dp) -{ - uiDrawTextFont *font; - uiDrawTextLayout *layout; - double r, g, b, al; - char surrogates[1 + 4 + 1 + 1]; - char composed[2 + 2 + 2 + 3 + 2 + 1]; - double width, height; - - font = uiFontButtonFont(textFontButton); - - layout = uiDrawNewTextLayout("One two three four", font, -1); - uiDrawTextLayoutSetColor(layout, - 4, 7, - 1, 0, 0, 1); - uiDrawTextLayoutSetColor(layout, - 8, 14, - 1, 0, 0.5, 0.5); - uiColorButtonColor(textColorButton, &r, &g, &b, &al); - uiDrawTextLayoutSetColor(layout, - 14, 18, - r, g, b, al); - uiDrawText(dp->Context, 10, 10, layout); - uiDrawTextLayoutExtents(layout, &width, &height); - uiDrawFreeTextLayout(layout); - - surrogates[0] = 'x'; - surrogates[1] = 0xF0; // surrogates D800 DF08 - surrogates[2] = 0x90; - surrogates[3] = 0x8C; - surrogates[4] = 0x88; - surrogates[5] = 'y'; - surrogates[6] = '\0'; - - layout = uiDrawNewTextLayout(surrogates, font, -1); - uiDrawTextLayoutSetColor(layout, - 1, 2, - 1, 0, 0.5, 0.5); - uiDrawText(dp->Context, 10, 10 + height, layout); - uiDrawFreeTextLayout(layout); - - composed[0] = 'z'; - composed[1] = 'z'; - composed[2] = 0xC3; // 2 - composed[3] = 0xA9; - composed[4] = 'z'; - composed[5] = 'z'; - composed[6] = 0x65; // 5 - composed[7] = 0xCC; - composed[8] = 0x81; - composed[9] = 'z'; - composed[10] = 'z'; - composed[11] = '\0'; - - layout = uiDrawNewTextLayout(composed, font, -1); - uiDrawTextLayoutSetColor(layout, - 2, 3, - 1, 0, 0.5, 0.5); - uiDrawTextLayoutSetColor(layout, - 5, 6, - 1, 0, 0.5, 0.5); - if (!uiCheckboxChecked(noZ)) - uiDrawTextLayoutSetColor(layout, - 6, 7, - 0.5, 0, 1, 0.5); - uiDrawText(dp->Context, 10, 10 + height + height, layout); - uiDrawFreeTextLayout(layout); - - uiDrawFreeTextFont(font); -} - -static void handlerMouseEvent(uiAreaHandler *a, uiArea *area, uiAreaMouseEvent *e) -{ - // do nothing -} - -static void handlerMouseCrossed(uiAreaHandler *ah, uiArea *a, int left) -{ - // do nothing -} - -static void handlerDragBroken(uiAreaHandler *ah, uiArea *a) -{ - // do nothing -} - -static int handlerKeyEvent(uiAreaHandler *ah, uiArea *a, uiAreaKeyEvent *e) -{ - // do nothing - return 0; -} - -static void onFontChanged(uiFontButton *b, void *data) -{ - uiAreaQueueRedrawAll(textArea); -} - -static void onColorChanged(uiColorButton *b, void *data) -{ - uiAreaQueueRedrawAll(textArea); -} - -static void onNoZ(uiCheckbox *b, void *data) -{ - uiAreaQueueRedrawAll(textArea); -} - -uiBox *makePage10(void) -{ - uiBox *page10; - uiBox *vbox; - uiBox *hbox; - - page10 = newVerticalBox(); - vbox = page10; - - hbox = newHorizontalBox(); - uiBoxAppend(vbox, uiControl(hbox), 0); - - textString = uiNewEntry(); - // TODO make it placeholder - uiEntrySetText(textString, "Enter text here"); - uiBoxAppend(hbox, uiControl(textString), 1); - - textFontButton = uiNewFontButton(); - uiFontButtonOnChanged(textFontButton, onFontChanged, NULL); - uiBoxAppend(hbox, uiControl(textFontButton), 1); - - textColorButton = uiNewColorButton(); - uiColorButtonOnChanged(textColorButton, onColorChanged, NULL); - uiBoxAppend(hbox, uiControl(textColorButton), 1); - - hbox = newHorizontalBox(); - uiBoxAppend(vbox, uiControl(hbox), 0); - - textApply = uiNewButton("Apply"); - uiBoxAppend(hbox, uiControl(textApply), 1); - - textWidth = uiNewEntry(); - uiEntrySetText(textWidth, "-1"); - uiBoxAppend(hbox, uiControl(textWidth), 1); - - noZ = uiNewCheckbox("No Z Color"); - uiCheckboxOnToggled(noZ, onNoZ, NULL); - uiBoxAppend(hbox, uiControl(noZ), 0); - - textAreaHandler.Draw = handlerDraw; - textAreaHandler.MouseEvent = handlerMouseEvent; - textAreaHandler.MouseCrossed = handlerMouseCrossed; - textAreaHandler.DragBroken = handlerDragBroken; - textAreaHandler.KeyEvent = handlerKeyEvent; - textArea = uiNewArea(&textAreaHandler); - uiBoxAppend(vbox, uiControl(textArea), 1); - - // dummy objects to test single-activation - hbox = newHorizontalBox(); - uiBoxAppend(vbox, uiControl(hbox), 0); - uiBoxAppend(hbox, uiControl(uiNewFontButton()), 1); - uiBoxAppend(hbox, uiControl(uiNewColorButton()), 1); - - return page10; -} diff --git a/src/libui_sdl/libui/test/page11.c b/src/libui_sdl/libui/test/page11.c deleted file mode 100644 index 02ad213..0000000 --- a/src/libui_sdl/libui/test/page11.c +++ /dev/null @@ -1,54 +0,0 @@ -// 14 may 2016 -#include "test.h" - -// TODO add a test for childless windows -// TODO add tests for contianers with all controls hidden - -static uiGroup *newg(const char *n, int s) -{ - uiGroup *g; - - g = uiNewGroup(n); - if (s) - uiGroupSetChild(g, NULL); - return g; -} - -static uiTab *newt(int tt) -{ - uiTab *t; - - t = uiNewTab(); - if (tt) - uiTabAppend(t, "Test", NULL); - return t; -} - -uiBox *makePage11(void) -{ - uiBox *page11; - uiBox *ns; - uiBox *s; - - page11 = newHorizontalBox(); - - ns = newVerticalBox(); - uiBoxAppend(ns, uiControl(newg("", 0)), 0); - uiBoxAppend(ns, uiControl(newg("", 1)), 0); - uiBoxAppend(ns, uiControl(newg("Group", 0)), 0); - uiBoxAppend(ns, uiControl(newg("Group", 1)), 0); - uiBoxAppend(ns, uiControl(newt(0)), 0); - uiBoxAppend(ns, uiControl(newt(1)), 0); - uiBoxAppend(page11, uiControl(ns), 1); - - s = newVerticalBox(); - uiBoxAppend(s, uiControl(newg("", 0)), 1); - uiBoxAppend(s, uiControl(newg("", 1)), 1); - uiBoxAppend(s, uiControl(newg("Group", 0)), 1); - uiBoxAppend(s, uiControl(newg("Group", 1)), 1); - uiBoxAppend(s, uiControl(newt(0)), 1); - uiBoxAppend(s, uiControl(newt(1)), 1); - uiBoxAppend(page11, uiControl(s), 1); - - return page11; -} diff --git a/src/libui_sdl/libui/test/page12.c b/src/libui_sdl/libui/test/page12.c deleted file mode 100644 index 5a8e963..0000000 --- a/src/libui_sdl/libui/test/page12.c +++ /dev/null @@ -1,60 +0,0 @@ -// 22 may 2016 -#include "test.h" - -// TODO OS X: if the hboxes are empty, the text views don't show up - -static void meChanged(uiMultilineEntry *e, void *data) -{ - printf("%s changed\n", (char *) data); -} - -static void setClicked(uiButton *b, void *data) -{ - uiMultilineEntrySetText(uiMultilineEntry(data), "set"); -} - -static void appendClicked(uiButton *b, void *data) -{ - uiMultilineEntryAppend(uiMultilineEntry(data), "append\n"); -} - -static uiBox *half(uiMultilineEntry *(*mk)(void), const char *which) -{ - uiBox *vbox, *hbox; - uiMultilineEntry *me; - uiButton *button; - - vbox = newVerticalBox(); - - me = (*mk)(); - uiMultilineEntryOnChanged(me, meChanged, (void *) which); - uiBoxAppend(vbox, uiControl(me), 1); - - hbox = newHorizontalBox(); - uiBoxAppend(vbox, uiControl(hbox), 0); - - button = uiNewButton("Set"); - uiButtonOnClicked(button, setClicked, me); - uiBoxAppend(hbox, uiControl(button), 0); - - button = uiNewButton("Append"); - uiButtonOnClicked(button, appendClicked, me); - uiBoxAppend(hbox, uiControl(button), 0); - - return vbox; -} - -uiBox *makePage12(void) -{ - uiBox *page12; - uiBox *b; - - page12 = newHorizontalBox(); - - b = half(uiNewMultilineEntry, "wrap"); - uiBoxAppend(page12, uiControl(b), 1); - b = half(uiNewNonWrappingMultilineEntry, "no wrap"); - uiBoxAppend(page12, uiControl(b), 1); - - return page12; -} diff --git a/src/libui_sdl/libui/test/page13.c b/src/libui_sdl/libui/test/page13.c deleted file mode 100644 index 5e6fd52..0000000 --- a/src/libui_sdl/libui/test/page13.c +++ /dev/null @@ -1,157 +0,0 @@ -// 28 may 2016 -#include "test.h" - -static int winClose(uiWindow *w, void *data) -{ - return 1; -} - -static void openTestWindow(uiBox *(*mkf)(void)) -{ - uiWindow *w; - uiBox *b; - uiCombobox *c; - uiEditableCombobox *e; - uiRadioButtons *r; - - w = uiNewWindow("Test", 100, 100, 0); - uiWindowOnClosing(w, winClose, NULL); - uiWindowSetMargined(w, 1); - b = (*mkf)(); - uiWindowSetChild(w, uiControl(b)); - -#define BA(x) uiBoxAppend(b, uiControl(x), 0) - BA(uiNewButton("")); - BA(uiNewCheckbox("")); - BA(uiNewEntry()); - BA(uiNewLabel("")); - BA(uiNewSpinbox(0, 100)); - BA(uiNewProgressBar()); - BA(uiNewSlider(0, 100)); - BA(uiNewHorizontalSeparator()); - c = uiNewCombobox(); - uiComboboxAppend(c, ""); - BA(c); - e = uiNewEditableCombobox(); - uiEditableComboboxAppend(e, ""); - BA(e); - r = uiNewRadioButtons(); - uiRadioButtonsAppend(r, ""); - BA(r); - BA(uiNewDateTimePicker()); - BA(uiNewDatePicker()); - BA(uiNewTimePicker()); - BA(uiNewMultilineEntry()); - // TODO nonscrolling and scrolling areas? - BA(uiNewFontButton()); - BA(uiNewColorButton()); - BA(uiNewPasswordEntry()); - BA(uiNewSearchEntry()); - BA(uiNewVerticalSeparator()); - - uiControlShow(uiControl(w)); -} - -static void buttonClicked(uiButton *b, void *data) -{ - openTestWindow((uiBox *(*)(void)) data); -} - -static void entryChanged(uiEntry *e, void *data) -{ - char *text; - - text = uiEntryText(e); - printf("%s entry changed: %s\n", (const char *) data, text); - uiFreeText(text); -} - -static void showHide(uiButton *b, void *data) -{ - uiControl *c = uiControl(data); - - if (uiControlVisible(c)) - uiControlHide(c); - else - uiControlShow(c); -} - -static void setIndeterminate(uiButton *b, void *data) -{ - uiProgressBar *p = uiProgressBar(data); - int value; - - value = uiProgressBarValue(p); - if (value == -1) - value = 50; - else - value = -1; - uiProgressBarSetValue(p, value); -} - -static void deleteFirst(uiButton *b, void *data) -{ - uiForm *f = uiForm(data); - - uiFormDelete(f, 0); -} - -uiBox *makePage13(void) -{ - uiBox *page13; - uiRadioButtons *rb; - uiButton *b; - uiForm *f; - uiEntry *e; - uiProgressBar *p; - - page13 = newVerticalBox(); - - rb = uiNewRadioButtons(); - uiRadioButtonsAppend(rb, "Item 1"); - uiRadioButtonsAppend(rb, "Item 2"); - uiRadioButtonsAppend(rb, "Item 3"); - uiBoxAppend(page13, uiControl(rb), 0); - - rb = uiNewRadioButtons(); - uiRadioButtonsAppend(rb, "Item A"); - uiRadioButtonsAppend(rb, "Item B"); - uiBoxAppend(page13, uiControl(rb), 0); - - b = uiNewButton("Horizontal"); - uiButtonOnClicked(b, buttonClicked, uiNewHorizontalBox); - uiBoxAppend(page13, uiControl(b), 0); - - b = uiNewButton("Vertical"); - uiButtonOnClicked(b, buttonClicked, uiNewVerticalBox); - uiBoxAppend(page13, uiControl(b), 0); - - f = newForm(); - - e = uiNewPasswordEntry(); - uiEntryOnChanged(e, entryChanged, "password"); - uiFormAppend(f, "Password Entry", uiControl(e), 0); - - e = uiNewSearchEntry(); - uiEntryOnChanged(e, entryChanged, "search"); - uiFormAppend(f, "Search Box", uiControl(e), 0); - - uiFormAppend(f, "MLE", uiControl(uiNewMultilineEntry()), 1); - - p = uiNewProgressBar(); - uiProgressBarSetValue(p, 50); - uiBoxAppend(page13, uiControl(p), 0); - b = uiNewButton("Toggle Indeterminate"); - uiButtonOnClicked(b, setIndeterminate, p); - uiBoxAppend(page13, uiControl(b), 0); - - b = uiNewButton("Show/Hide"); - uiButtonOnClicked(b, showHide, e); - uiBoxAppend(page13, uiControl(b), 0); - b = uiNewButton("Delete First"); - uiButtonOnClicked(b, deleteFirst, f); - uiBoxAppend(page13, uiControl(b), 0); - uiBoxAppend(page13, uiControl(f), 1); - - return page13; -} diff --git a/src/libui_sdl/libui/test/page14.c b/src/libui_sdl/libui/test/page14.c deleted file mode 100644 index 880534c..0000000 --- a/src/libui_sdl/libui/test/page14.c +++ /dev/null @@ -1,350 +0,0 @@ -// 9 june 2016 -#include "test.h" - -// TODOs: -// - GTK+ - make all expanding controls the same size, to match the other OSs? will they match the other OSs? - -enum { - red, - green, - blue, - yellow, - white, - magenta, - orange, - purple, - cyan, -}; - -static const struct { - double r; - double g; - double b; -} colors[] = { - { 1, 0, 0 }, - { 0, 0.5, 0 }, - { 0, 0, 1 }, - { 1, 1, 0 }, - { 1, 1, 1 }, - { 1, 0, 1 }, - { 1, 0.65, 0 }, - { 0.5, 0, 0.5 }, - { 0, 1, 1 }, -}; - -static uiControl *testControl(const char *label, int color) -{ - uiColorButton *b; - - b = uiNewColorButton(); - uiColorButtonSetColor(b, colors[color].r, colors[color].g, colors[color].b, 1.0); - return uiControl(b); -} - -static uiControl *simpleGrid(void) -{ - uiGrid *g; - uiControl *t4; - - g = newGrid(); - uiGridAppend(g, testControl("1", red), - 0, 0, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - uiGridAppend(g, testControl("2", green), - 1, 0, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - uiGridAppend(g, testControl("3", blue), - 2, 0, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - t4 = testControl("4", green); - uiGridAppend(g, t4, - 0, 1, 1, 1, - 0, uiAlignFill, 1, uiAlignFill); - uiGridInsertAt(g, testControl("5", blue), - t4, uiAtTrailing, 2, 1, - 0, uiAlignFill, 0, uiAlignFill); - uiGridAppend(g, testControl("6", yellow), - -1, 0, 1, 2, - 1, uiAlignFill, 0, uiAlignFill); - return uiControl(g); -} - -static uiControl *boxComparison(void) -{ - uiBox *vbox; - uiGrid *g; - uiBox *hbox; - - vbox = newVerticalBox(); - uiBoxAppend(vbox, uiControl(uiNewLabel("Above")), 0); - uiBoxAppend(vbox, uiControl(uiNewHorizontalSeparator()), 0); - - hbox = newHorizontalBox(); - uiBoxAppend(vbox, uiControl(hbox), 0); - uiBoxAppend(hbox, testControl("1", white), 0); - uiBoxAppend(hbox, uiControl(uiNewLabel("A label")), 1); - uiBoxAppend(hbox, testControl("2", green), 0); - uiBoxAppend(hbox, uiControl(uiNewLabel("Another label")), 1); - uiBoxAppend(hbox, testControl("3", red), 0); - - uiBoxAppend(vbox, uiControl(uiNewHorizontalSeparator()), 0); - - g = newGrid(); - uiBoxAppend(vbox, uiControl(g), 0); - uiGridAppend(g, testControl("1", white), - 0, 0, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - uiGridAppend(g, uiControl(uiNewLabel("A label")), - 1, 0, 1, 1, - 1, uiAlignFill, 0, uiAlignFill); - uiGridAppend(g, testControl("2", green), - 2, 0, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - uiGridAppend(g, uiControl(uiNewLabel("Another label")), - 3, 0, 1, 1, - 1, uiAlignFill, 0, uiAlignFill); - uiGridAppend(g, testControl("3", red), - 4, 0, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - - uiBoxAppend(vbox, uiControl(uiNewHorizontalSeparator()), 0); - uiBoxAppend(vbox, uiControl(uiNewLabel("Below")), 0); - return uiControl(vbox); -} - -static uiControl *emptyLine(void) -{ - uiGrid *g; - - g = newGrid(); - uiGridAppend(g, testControl("(0, 0)", red), - 0, 0, 1, 1, - 1, uiAlignFill, 1, uiAlignFill); - uiGridAppend(g, testControl("(0, 1)", blue), - 0, 1, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - uiGridAppend(g, testControl("(10, 0)", green), - 10, 0, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - uiGridAppend(g, testControl("(10, 1)", magenta), - 10, 1, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - return uiControl(g); -} - -static uiControl *emptyGrid(void) -{ - uiGrid *g; - uiControl *t; - - g = newGrid(); - t = testControl("(0, 0)", red); - uiGridAppend(g, t, - 0, 0, 1, 1, - 1, uiAlignFill, 1, uiAlignFill); - uiControlHide(t); - return uiControl(g); -} - -// TODO insert (need specialized insert/delete) - -static uiControl *spanningGrid(void) -{ - uiGrid *g; - - g = newGrid(); - uiGridAppend(g, testControl("0", blue), - 0, 4, 4, 1, - 1, uiAlignFill, 0, uiAlignFill); - uiGridAppend(g, testControl("1", green), - 4, 0, 1, 4, - 0, uiAlignFill, 1, uiAlignFill); - uiGridAppend(g, testControl("2", red), - 3, 3, 1, 1, - 1, uiAlignFill, 1, uiAlignFill); - uiGridAppend(g, testControl("3", yellow), - 0, 3, 2, 1, - 0, uiAlignFill, 0, uiAlignFill); - uiGridAppend(g, testControl("4", orange), - 3, 0, 1, 2, - 0, uiAlignFill, 0, uiAlignFill); - uiGridAppend(g, testControl("5", purple), - 1, 1, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - uiGridAppend(g, testControl("6", white), - 0, 1, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - uiGridAppend(g, testControl("7", cyan), - 1, 0, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - return uiControl(g); -} - -// TODO make non-global -static uiButton *hideOne, *one, *showOne; - -static void onHideOne(uiButton *b, void *data) -{ - uiControlHide(uiControl(one)); -} - -static void onShowOne(uiButton *b, void *data) -{ - uiControlShow(uiControl(one)); -} - -static void onHideAll(uiButton *b, void *data) -{ - uiControlHide(uiControl(hideOne)); - uiControlHide(uiControl(one)); - uiControlHide(uiControl(showOne)); -} - -static void onShowAll(uiButton *b, void *data) -{ - uiControlShow(uiControl(hideOne)); - uiControlShow(uiControl(one)); - uiControlShow(uiControl(showOne)); -} - -#define AT(x) static void onInsert ## x(uiButton *b, void *data) \ - { \ - uiGrid *g = uiGrid(data); \ - uiGridInsertAt(g, uiControl(uiNewButton("Button")), \ - uiControl(b), uiAt ## x, 1, 1, \ - 0, uiAlignFill, 0, uiAlignFill); \ - } -AT(Leading) -AT(Top) -AT(Trailing) -AT(Bottom) - -static uiControl *assorted(void) -{ - uiGrid *outergrid; - uiGrid *innergrid; - uiButton *b; - - outergrid = newGrid(); - - innergrid = newGrid(); - one = uiNewButton("Test"); - uiGridAppend(innergrid, uiControl(one), - 1, 1, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - hideOne = uiNewButton("Hide One"); - uiButtonOnClicked(hideOne, onHideOne, NULL); - uiGridAppend(innergrid, uiControl(hideOne), - 0, 1, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - showOne = uiNewButton("Show One"); - uiButtonOnClicked(showOne, onShowOne, NULL); - uiGridAppend(innergrid, uiControl(showOne), - 2, 1, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - b = uiNewButton("Hide All"); - uiButtonOnClicked(b, onHideAll, NULL); - uiGridAppend(innergrid, uiControl(b), - 1, 0, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - b = uiNewButton("Show All"); - uiButtonOnClicked(b, onShowAll, NULL); - uiGridAppend(innergrid, uiControl(b), - 1, 2, 1, 1, - 0, uiAlignFill, 0, uiAlignFill); - uiGridAppend(outergrid, uiControl(innergrid), - 0, 0, 1, 1, - 1, uiAlignFill, 1, uiAlignFill); - - innergrid = newGrid(); - b = uiNewButton("Insert Trailing"); - uiButtonOnClicked(b, onInsertTrailing, innergrid); - uiGridAppend(innergrid, uiControl(b), - 0, 0, 1, 1, - 1, uiAlignFill, 0, uiAlignFill); - b = uiNewButton("Insert Bottom"); - uiButtonOnClicked(b, onInsertBottom, innergrid); - uiGridAppend(innergrid, uiControl(b), - 1, 0, 1, 1, - 1, uiAlignFill, 0, uiAlignFill); - b = uiNewButton("Insert Leading"); - uiButtonOnClicked(b, onInsertLeading, innergrid); - uiGridAppend(innergrid, uiControl(b), - 1, 1, 1, 1, - 1, uiAlignFill, 0, uiAlignFill); - b = uiNewButton("Insert Top"); - uiButtonOnClicked(b, onInsertTop, innergrid); - uiGridAppend(innergrid, uiControl(b), - 0, 1, 1, 1, - 1, uiAlignFill, 0, uiAlignFill); - uiGridAppend(outergrid, uiControl(innergrid), - 1, 0, 1, 1, - 1, uiAlignFill, 1, uiAlignFill); - - innergrid = newGrid(); - uiGridAppend(innergrid, uiControl(uiNewColorButton()), - 0, 0, 1, 1, - 1, uiAlignFill, 0, uiAlignFill); - uiGridAppend(innergrid, uiControl(uiNewColorButton()), - 0, 1, 1, 1, - 1, uiAlignStart, 0, uiAlignFill); - uiGridAppend(innergrid, uiControl(uiNewColorButton()), - 0, 2, 1, 1, - 1, uiAlignCenter, 0, uiAlignFill); - uiGridAppend(innergrid, uiControl(uiNewColorButton()), - 0, 3, 1, 1, - 1, uiAlignEnd, 0, uiAlignFill); - uiGridAppend(outergrid, uiControl(innergrid), - 0, 1, 1, 1, - 1, uiAlignFill, 1, uiAlignFill); - - // TODO with only this, wrong size on OS X — expand sizing thing? - innergrid = newGrid(); - uiGridAppend(innergrid, uiControl(uiNewColorButton()), - 0, 0, 1, 1, - 0, uiAlignFill, 1, uiAlignFill); - uiGridAppend(innergrid, uiControl(uiNewColorButton()), - 1, 0, 1, 1, - 0, uiAlignFill, 1, uiAlignStart); - uiGridAppend(innergrid, uiControl(uiNewColorButton()), - 2, 0, 1, 1, - 0, uiAlignFill, 1, uiAlignCenter); - uiGridAppend(innergrid, uiControl(uiNewColorButton()), - 3, 0, 1, 1, - 0, uiAlignFill, 1, uiAlignEnd); - uiGridAppend(outergrid, uiControl(innergrid), - 1, 1, 1, 1, - 1, uiAlignFill, 1, uiAlignFill); - - return uiControl(outergrid); -} - -static const struct { - const char *name; - uiControl *(*f)(void); -} pages[] = { - // based on GTK+ test/testgrid.c - { "Simple Grid", simpleGrid }, - { "Box Comparison", boxComparison }, - { "Empty Line", emptyLine }, - { "Empty Grid", emptyGrid }, - { "Spanning Grid", spanningGrid }, - // my own - { "Assorted", assorted }, - { NULL, NULL }, -}; - -uiTab *makePage14(void) -{ - uiTab *page14; - int i; - - page14 = newTab(); - - for (i = 0; pages[i].name != NULL; i++) - uiTabAppend(page14, - pages[i].name, - (*(pages[i].f))()); - - return page14; -} diff --git a/src/libui_sdl/libui/test/page15.c b/src/libui_sdl/libui/test/page15.c deleted file mode 100644 index e703bee..0000000 --- a/src/libui_sdl/libui/test/page15.c +++ /dev/null @@ -1,260 +0,0 @@ -// 15 june 2016 -#include "test.h" - -static uiAreaHandler borderAH; -static int borderAHInit = 0; -static double lastx = -1, lasty = -1; - -struct trect { - double left; - double top; - double right; - double bottom; - int in; -}; - -#define tsetrect(re, l, t, r, b) re.left = l; re.top = t; re.right = r; re.bottom = b; re.in = lastx >= re.left && lastx < re.right && lasty >= re.top && lasty < re.bottom - -struct tareas { - struct trect move; - struct trect alsomove; - struct trect leftresize; - struct trect topresize; - struct trect rightresize; - struct trect bottomresize; - struct trect topleftresize; - struct trect toprightresize; - struct trect bottomleftresize; - struct trect bottomrightresize; - struct trect close; -}; - -static void filltareas(double awid, double aht, struct tareas *ta) -{ - tsetrect(ta->move, 20, 20, awid - 20, 20 + 30); - tsetrect(ta->alsomove, 30, 200, 100, 270); - tsetrect(ta->leftresize, 5, 20, 15, aht - 20); - tsetrect(ta->topresize, 20, 5, awid - 20, 15); - tsetrect(ta->rightresize, awid - 15, 20, awid - 5, aht - 20); - tsetrect(ta->bottomresize, 20, aht - 15, awid - 20, aht - 5); - tsetrect(ta->topleftresize, 5, 5, 15, 15); - tsetrect(ta->toprightresize, awid - 15, 5, awid - 5, 15); - tsetrect(ta->bottomleftresize, 5, aht - 15, 15, aht - 5); - tsetrect(ta->bottomrightresize, awid - 15, aht - 15, awid - 5, aht - 5); - tsetrect(ta->close, 130, 200, 200, 270); -} - -static void drawtrect(uiDrawContext *c, struct trect tr, double r, double g, double bl) -{ - uiDrawPath *p; - uiDrawBrush b; - - memset(&b, 0, sizeof (uiDrawBrush)); - b.Type = uiDrawBrushTypeSolid; - b.R = r; - b.G = g; - b.B = bl; - b.A = 1.0; - if (tr.in) { - b.R += b.R * 0.75; - b.G += b.G * 0.75; - b.B += b.B * 0.75; - } - p = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathAddRectangle(p, - tr.left, - tr.top, - tr.right - tr.left, - tr.bottom - tr.top); - uiDrawPathEnd(p); - uiDrawFill(c, p, &b); - uiDrawFreePath(p); -} - -static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p) -{ - struct tareas ta; - - filltareas(p->AreaWidth, p->AreaHeight, &ta); - drawtrect(p->Context, ta.move, 0, 0.5, 0); - drawtrect(p->Context, ta.alsomove, 0, 0.5, 0); - drawtrect(p->Context, ta.leftresize, 0, 0, 0.5); - drawtrect(p->Context, ta.topresize, 0, 0, 0.5); - drawtrect(p->Context, ta.rightresize, 0, 0, 0.5); - drawtrect(p->Context, ta.bottomresize, 0, 0, 0.5); - drawtrect(p->Context, ta.topleftresize, 0, 0.5, 0.5); - drawtrect(p->Context, ta.toprightresize, 0, 0.5, 0.5); - drawtrect(p->Context, ta.bottomleftresize, 0, 0.5, 0.5); - drawtrect(p->Context, ta.bottomrightresize, 0, 0.5, 0.5); - drawtrect(p->Context, ta.close, 0.5, 0, 0); - - // TODO add current position prints here -} - -static void handlerMouseEvent(uiAreaHandler *a, uiArea *area, uiAreaMouseEvent *e) -{ - struct tareas ta; - - lastx = e->X; - lasty = e->Y; - filltareas(e->AreaWidth, e->AreaHeight, &ta); - // redraw our highlighted rect - uiAreaQueueRedrawAll(area); - if (e->Down != 1) - return; - if (ta.move.in || ta.alsomove.in) { - uiAreaBeginUserWindowMove(area); - return; - } -#define resize(cond, edge) if (cond) { uiAreaBeginUserWindowResize(area, edge); return; } - resize(ta.leftresize.in, uiWindowResizeEdgeLeft) - resize(ta.topresize.in, uiWindowResizeEdgeTop) - resize(ta.rightresize.in, uiWindowResizeEdgeRight) - resize(ta.bottomresize.in, uiWindowResizeEdgeBottom) - resize(ta.topleftresize.in, uiWindowResizeEdgeTopLeft) - resize(ta.toprightresize.in, uiWindowResizeEdgeTopRight) - resize(ta.bottomleftresize.in, uiWindowResizeEdgeBottomLeft) - resize(ta.bottomrightresize.in, uiWindowResizeEdgeBottomRight) - if (ta.close.in) { - // TODO - return; - } -} - -static void handlerMouseCrossed(uiAreaHandler *ah, uiArea *a, int left) -{ -} - -static void handlerDragBroken(uiAreaHandler *ah, uiArea *a) -{ -} - -static int handlerKeyEvent(uiAreaHandler *ah, uiArea *a, uiAreaKeyEvent *e) -{ - return 0; -} - -static void borderWindowOpen(uiButton *b, void *data) -{ - uiWindow *w; - uiArea *a; - - if (!borderAHInit) { - borderAH.Draw = handlerDraw; - borderAH.MouseEvent = handlerMouseEvent; - borderAH.MouseCrossed = handlerMouseCrossed; - borderAH.DragBroken = handlerDragBroken; - borderAH.KeyEvent = handlerKeyEvent; - borderAHInit = 1; - } - - w = uiNewWindow("Border Resize Test", 300, 500, 0); - uiWindowSetBorderless(w, 1); - - a = uiNewArea(&borderAH); -// uiWindowSetChild(w, uiControl(a)); -{uiBox *b; -b=uiNewHorizontalBox(); -uiBoxAppend(b,uiControl(a),1); -uiWindowSetChild(w,uiControl(b));} -//TODO why is this hack needed? GTK+ issue - - uiControlShow(uiControl(w)); -} - -static uiSpinbox *width, *height; -static uiCheckbox *fullscreen; - -static void sizeWidth(uiSpinbox *s, void *data) -{ - uiWindow *w = uiWindow(data); - int xp, yp; - - uiWindowContentSize(w, &xp, &yp); - xp = uiSpinboxValue(width); - uiWindowSetContentSize(w, xp, yp); -} - -static void sizeHeight(uiSpinbox *s, void *data) -{ - uiWindow *w = uiWindow(data); - int xp, yp; - - uiWindowContentSize(w, &xp, &yp); - yp = uiSpinboxValue(height); - uiWindowSetContentSize(w, xp, yp); -} - -static void updatesize(uiWindow *w) -{ - int xp, yp; - - uiWindowContentSize(w, &xp, &yp); - uiSpinboxSetValue(width, xp); - uiSpinboxSetValue(height, yp); - // TODO on OS X this is updated AFTER sending the size change, not before - uiCheckboxSetChecked(fullscreen, uiWindowFullscreen(w)); -} - -void onSize(uiWindow *w, void *data) -{ - printf("size\n"); - updatesize(w); -} - -void setFullscreen(uiCheckbox *cb, void *data) -{ - uiWindow *w = uiWindow(data); - - uiWindowSetFullscreen(w, uiCheckboxChecked(fullscreen)); - updatesize(w); -} - -static void borderless(uiCheckbox *c, void *data) -{ - uiWindow *w = uiWindow(data); - - uiWindowSetBorderless(w, uiCheckboxChecked(c)); -} - -uiBox *makePage15(uiWindow *w) -{ - uiBox *page15; - uiBox *hbox; - uiButton *button; - uiCheckbox *checkbox; - - page15 = newVerticalBox(); - - hbox = newHorizontalBox(); - uiBoxAppend(page15, uiControl(hbox), 0); - - uiBoxAppend(hbox, uiControl(uiNewLabel("Size")), 0); - width = uiNewSpinbox(INT_MIN, INT_MAX); - uiBoxAppend(hbox, uiControl(width), 1); - height = uiNewSpinbox(INT_MIN, INT_MAX); - uiBoxAppend(hbox, uiControl(height), 1); - fullscreen = uiNewCheckbox("Fullscreen"); - uiBoxAppend(hbox, uiControl(fullscreen), 0); - - uiSpinboxOnChanged(width, sizeWidth, w); - uiSpinboxOnChanged(height, sizeHeight, w); - uiCheckboxOnToggled(fullscreen, setFullscreen, w); - uiWindowOnContentSizeChanged(w, onSize, NULL); - updatesize(w); - - checkbox = uiNewCheckbox("Borderless"); - uiCheckboxOnToggled(checkbox, borderless, w); - uiBoxAppend(page15, uiControl(checkbox), 0); - - button = uiNewButton("Borderless Resizes"); - uiButtonOnClicked(button, borderWindowOpen, NULL); - uiBoxAppend(page15, uiControl(button), 0); - - hbox = newHorizontalBox(); - uiBoxAppend(page15, uiControl(hbox), 1); - - uiBoxAppend(hbox, uiControl(uiNewVerticalSeparator()), 0); - - return page15; -} diff --git a/src/libui_sdl/libui/test/page2.c b/src/libui_sdl/libui/test/page2.c deleted file mode 100644 index abb0648..0000000 --- a/src/libui_sdl/libui/test/page2.c +++ /dev/null @@ -1,215 +0,0 @@ -// 29 april 2015 -#include "test.h" - -uiGroup *page2group; - -static uiLabel *movingLabel; -static uiBox *movingBoxes[2]; -static int movingCurrent; - -static void moveLabel(uiButton *b, void *data) -{ - int from, to; - - from = movingCurrent; - to = 0; - if (from == 0) - to = 1; - uiBoxDelete(movingBoxes[from], 0); - uiBoxAppend(movingBoxes[to], uiControl(movingLabel), 0); - movingCurrent = to; -} - -static int moveBack; -#define moveOutText "Move Page 1 Out" -#define moveBackText "Move Page 1 Back" - -static void movePage1(uiButton *b, void *data) -{ - if (moveBack) { - uiBoxDelete(mainBox, 1); - uiTabInsertAt(mainTab, "Page 1", 0, uiControl(page1)); - uiButtonSetText(b, moveOutText); - moveBack = 0; - return; - } - uiTabDelete(mainTab, 0); - uiBoxAppend(mainBox, uiControl(page1), 1); - uiButtonSetText(b, moveBackText); - moveBack = 1; -} - -static void openAnotherWindow(uiButton *bb, void *data) -{ - uiWindow *w; - uiBox *b; - - w = uiNewWindow("Another Window", 100, 100, data != NULL); - if (data != NULL) { - b = uiNewVerticalBox(); - uiBoxAppend(b, uiControl(uiNewEntry()), 0); - uiBoxAppend(b, uiControl(uiNewButton("Button")), 0); - uiBoxSetPadded(b, 1); - uiWindowSetChild(w, uiControl(b)); - } else - uiWindowSetChild(w, uiControl(makePage6())); - uiWindowSetMargined(w, 1); - uiControlShow(uiControl(w)); -} - -static void openAnotherDisabledWindow(uiButton *b, void *data) -{ - uiWindow *w; - - w = uiNewWindow("Another Window", 100, 100, data != NULL); - uiControlDisable(uiControl(w)); - uiControlShow(uiControl(w)); -} - -#define SHED(method, Method) \ - static void method ## Control(uiButton *b, void *data) \ - { \ - uiControl ## Method(uiControl(data)); \ - } -SHED(show, Show) -SHED(enable, Enable) -SHED(disable, Disable) - -static void echoReadOnlyText(uiEntry *e, void *data) -{ - char *text; - - text = uiEntryText(e); - uiEntrySetText(uiEntry(data), text); - uiFreeText(text); -} - -uiBox *makePage2(void) -{ - uiBox *page2; - uiBox *hbox; - uiGroup *group; - uiBox *vbox; - uiButton *button; - uiBox *nestedBox; - uiBox *innerhbox; - uiBox *innerhbox2; - uiBox *innerhbox3; - uiTab *disabledTab; - uiEntry *entry; - uiEntry *readonly; - uiButton *button2; - - page2 = newVerticalBox(); - - group = newGroup("Moving Label"); - page2group = group; - uiBoxAppend(page2, uiControl(group), 0); - vbox = newVerticalBox(); - uiGroupSetChild(group, uiControl(vbox)); - - hbox = newHorizontalBox(); - button = uiNewButton("Move the Label!"); - uiButtonOnClicked(button, moveLabel, NULL); - uiBoxAppend(hbox, uiControl(button), 1); - // have a blank label for space - uiBoxAppend(hbox, uiControl(uiNewLabel("")), 1); - uiBoxAppend(vbox, uiControl(hbox), 0); - - hbox = newHorizontalBox(); - movingBoxes[0] = newVerticalBox(); - uiBoxAppend(hbox, uiControl(movingBoxes[0]), 1); - movingBoxes[1] = newVerticalBox(); - uiBoxAppend(hbox, uiControl(movingBoxes[1]), 1); - uiBoxAppend(vbox, uiControl(hbox), 0); - - movingCurrent = 0; - movingLabel = uiNewLabel("This label moves!"); - uiBoxAppend(movingBoxes[movingCurrent], uiControl(movingLabel), 0); - - hbox = newHorizontalBox(); - button = uiNewButton(moveOutText); - uiButtonOnClicked(button, movePage1, NULL); - uiBoxAppend(hbox, uiControl(button), 0); - uiBoxAppend(page2, uiControl(hbox), 0); - moveBack = 0; - - hbox = newHorizontalBox(); - uiBoxAppend(hbox, uiControl(uiNewLabel("Label Alignment Test")), 0); - button = uiNewButton("Open Menued Window"); - uiButtonOnClicked(button, openAnotherWindow, button); - uiBoxAppend(hbox, uiControl(button), 0); - button = uiNewButton("Open Menuless Window"); - uiButtonOnClicked(button, openAnotherWindow, NULL); - uiBoxAppend(hbox, uiControl(button), 0); - button = uiNewButton("Disabled Menued"); - uiButtonOnClicked(button, openAnotherDisabledWindow, button); - uiBoxAppend(hbox, uiControl(button), 0); - button = uiNewButton("Disabled Menuless"); - uiButtonOnClicked(button, openAnotherDisabledWindow, NULL); - uiBoxAppend(hbox, uiControl(button), 0); - uiBoxAppend(page2, uiControl(hbox), 0); - - nestedBox = newHorizontalBox(); - innerhbox = newHorizontalBox(); - uiBoxAppend(innerhbox, uiControl(uiNewButton("These")), 0); - button = uiNewButton("buttons"); - uiControlDisable(uiControl(button)); - uiBoxAppend(innerhbox, uiControl(button), 0); - uiBoxAppend(nestedBox, uiControl(innerhbox), 0); - innerhbox = newHorizontalBox(); - uiBoxAppend(innerhbox, uiControl(uiNewButton("are")), 0); - innerhbox2 = newHorizontalBox(); - button = uiNewButton("in"); - uiControlDisable(uiControl(button)); - uiBoxAppend(innerhbox2, uiControl(button), 0); - uiBoxAppend(innerhbox, uiControl(innerhbox2), 0); - uiBoxAppend(nestedBox, uiControl(innerhbox), 0); - innerhbox = newHorizontalBox(); - innerhbox2 = newHorizontalBox(); - uiBoxAppend(innerhbox2, uiControl(uiNewButton("nested")), 0); - innerhbox3 = newHorizontalBox(); - button = uiNewButton("boxes"); - uiControlDisable(uiControl(button)); - uiBoxAppend(innerhbox3, uiControl(button), 0); - uiBoxAppend(innerhbox2, uiControl(innerhbox3), 0); - uiBoxAppend(innerhbox, uiControl(innerhbox2), 0); - uiBoxAppend(nestedBox, uiControl(innerhbox), 0); - uiBoxAppend(page2, uiControl(nestedBox), 0); - - hbox = newHorizontalBox(); - button = uiNewButton("Enable Nested Box"); - uiButtonOnClicked(button, enableControl, nestedBox); - uiBoxAppend(hbox, uiControl(button), 0); - button = uiNewButton("Disable Nested Box"); - uiButtonOnClicked(button, disableControl, nestedBox); - uiBoxAppend(hbox, uiControl(button), 0); - uiBoxAppend(page2, uiControl(hbox), 0); - - disabledTab = newTab(); - uiTabAppend(disabledTab, "Disabled", uiControl(uiNewButton("Button"))); - uiTabAppend(disabledTab, "Tab", uiControl(uiNewLabel("Label"))); - uiControlDisable(uiControl(disabledTab)); - uiBoxAppend(page2, uiControl(disabledTab), 1); - - entry = uiNewEntry(); - readonly = uiNewEntry(); - uiEntryOnChanged(entry, echoReadOnlyText, readonly); - uiEntrySetText(readonly, "If you can see this, uiEntryReadOnly() isn't working properly."); - uiEntrySetReadOnly(readonly, 1); - if (uiEntryReadOnly(readonly)) - uiEntrySetText(readonly, ""); - uiBoxAppend(page2, uiControl(entry), 0); - uiBoxAppend(page2, uiControl(readonly), 0); - - hbox = newHorizontalBox(); - button = uiNewButton("Show Button 2"); - button2 = uiNewButton("Button 2"); - uiButtonOnClicked(button, showControl, button2); - uiControlHide(uiControl(button2)); - uiBoxAppend(hbox, uiControl(button), 1); - uiBoxAppend(hbox, uiControl(button2), 0); - uiBoxAppend(page2, uiControl(hbox), 0); - - return page2; -} diff --git a/src/libui_sdl/libui/test/page3.c b/src/libui_sdl/libui/test/page3.c deleted file mode 100644 index 1f229e9..0000000 --- a/src/libui_sdl/libui/test/page3.c +++ /dev/null @@ -1,69 +0,0 @@ -// 7 may 2015 -#include "test.h" - -static uiBox *makeSet(int omit, int hidden, int stretch) -{ - uiBox *hbox; - uiButton *buttons[4]; - - // don't use newHorizontalBox() - // the point of this test is to test hidden controls and padded - hbox = (*newhbox)(); - uiBoxSetPadded(hbox, 1); - if (omit != 0) { - buttons[0] = uiNewButton("First"); - uiBoxAppend(hbox, uiControl(buttons[0]), stretch); - } - if (omit != 1) { - buttons[1] = uiNewButton("Second"); - uiBoxAppend(hbox, uiControl(buttons[1]), stretch); - } - if (omit != 2) { - buttons[2] = uiNewButton("Third"); - uiBoxAppend(hbox, uiControl(buttons[2]), stretch); - } - if (omit != 3) { - buttons[3] = uiNewButton("Fourth"); - uiBoxAppend(hbox, uiControl(buttons[3]), stretch); - } - if (hidden != -1) - uiControlHide(uiControl(buttons[hidden])); - return hbox; -} - -uiBox *makePage3(void) -{ - uiBox *page3; - uiBox *hbox; - uiBox *hbox2; - uiBox *vbox; - int hidden; - - page3 = newVerticalBox(); - - // first the non-stretchy type - for (hidden = 0; hidden < 4; hidden++) { - // these two must stay unpadded as well, otherwise the test isn't meaningful - hbox2 = (*newhbox)(); - vbox = (*newvbox)(); - // reference set - hbox = makeSet(hidden, -1, 0); - uiBoxAppend(vbox, uiControl(hbox), 0); - // real thing - hbox = makeSet(-1, hidden, 0); - uiBoxAppend(vbox, uiControl(hbox), 0); - // pack vbox in - uiBoxAppend(hbox2, uiControl(vbox), 0); - // and have a button in there for showing right margins - uiBoxAppend(hbox2, uiControl(uiNewButton("Right Margin Test")), 1); - uiBoxAppend(page3, uiControl(hbox2), 0); - } - - // then the stretchy type - for (hidden = 0; hidden < 4; hidden++) { - hbox = makeSet(-1, hidden, 1); - uiBoxAppend(page3, uiControl(hbox), 0); - } - - return page3; -} diff --git a/src/libui_sdl/libui/test/page4.c b/src/libui_sdl/libui/test/page4.c deleted file mode 100644 index ce4a6af..0000000 --- a/src/libui_sdl/libui/test/page4.c +++ /dev/null @@ -1,165 +0,0 @@ -// 19 may 2015 -#include "test.h" - -static uiSpinbox *spinbox; -static uiSlider *slider; -static uiProgressBar *pbar; - -#define CHANGED(what) \ - static void on ## what ## Changed(ui ## what *this, void *data) \ - { \ - int value; \ - printf("on %s changed\n", #what); \ - value = ui ## what ## Value(this); \ - uiSpinboxSetValue(spinbox, value); \ - uiSliderSetValue(slider, value); \ - uiProgressBarSetValue(pbar, value); \ - } -CHANGED(Spinbox) -CHANGED(Slider) - -#define SETTOO(what, name, n) \ - static void set ## what ## Too ## name(uiButton *this, void *data) \ - { \ - ui ## what ## SetValue(ui ## what(data), n); \ - } -SETTOO(Spinbox, Low, -80) -SETTOO(Spinbox, High, 80) -SETTOO(Slider, Low, -80) -SETTOO(Slider, High, 80) - -static uiCombobox *cbox; -static uiEditableCombobox *editable; -static uiRadioButtons *rb; - -static void appendCBRB(uiButton *b, void *data) -{ - uiComboboxAppend(cbox, "New Item"); - uiEditableComboboxAppend(editable, "New Item"); - uiRadioButtonsAppend(rb, "New Item"); -} - -static void onCBChanged(uiCombobox *c, void *data) -{ - printf("%s combobox changed to %d\n", - (char *) data, - (int) uiComboboxSelected(c)); - uiEditableComboboxSetText(editable, "changed"); -} - -static void onECBChanged(uiEditableCombobox *c, void *data) -{ - char *t; - - t = uiEditableComboboxText(c); - printf("%s combobox changed to %s\n", - (char *) data, - t); - uiFreeText(t); -} - -static void onRBSelected(uiRadioButtons *r, void *data) -{ - printf("radio buttons %d\n", uiRadioButtonsSelected(r)); -} - -static void selectSecond(uiButton *b, void *data) -{ - // TODO combobox, editable - uiRadioButtonsSetSelected(rb, 1); -} - -static void selectNone(uiButton *b, void *data) -{ - // TODO combobox, editable - uiRadioButtonsSetSelected(rb, -1); -} - -uiBox *makePage4(void) -{ - uiBox *page4; - uiBox *hbox; - uiSpinbox *xsb; - uiButton *b; - uiSlider *xsl; - - page4 = newVerticalBox(); - - spinbox = uiNewSpinbox(0, 100); - uiSpinboxOnChanged(spinbox, onSpinboxChanged, NULL); - uiBoxAppend(page4, uiControl(spinbox), 0); - - slider = uiNewSlider(0, 100); - uiSliderOnChanged(slider, onSliderChanged, NULL); - uiBoxAppend(page4, uiControl(slider), 0); - - pbar = uiNewProgressBar(); - uiBoxAppend(page4, uiControl(pbar), 0); - - uiBoxAppend(page4, uiControl(uiNewHorizontalSeparator()), 0); - - hbox = newHorizontalBox(); - xsb = uiNewSpinbox(-40, 40); - uiBoxAppend(hbox, uiControl(xsb), 0); - b = uiNewButton("Bad Low"); - uiButtonOnClicked(b, setSpinboxTooLow, xsb); - uiBoxAppend(hbox, uiControl(b), 0); - b = uiNewButton("Bad High"); - uiButtonOnClicked(b, setSpinboxTooHigh, xsb); - uiBoxAppend(hbox, uiControl(b), 0); - uiBoxAppend(page4, uiControl(hbox), 0); - - hbox = newHorizontalBox(); - xsl = uiNewSlider(-40, 40); - uiBoxAppend(hbox, uiControl(xsl), 0); - b = uiNewButton("Bad Low"); - uiButtonOnClicked(b, setSliderTooLow, xsl); - uiBoxAppend(hbox, uiControl(b), 0); - b = uiNewButton("Bad High"); - uiButtonOnClicked(b, setSliderTooHigh, xsl); - uiBoxAppend(hbox, uiControl(b), 0); - uiBoxAppend(page4, uiControl(hbox), 0); - - uiBoxAppend(page4, uiControl(uiNewHorizontalSeparator()), 0); - - cbox = uiNewCombobox(); - uiComboboxAppend(cbox, "Item 1"); - uiComboboxAppend(cbox, "Item 2"); - uiComboboxAppend(cbox, "Item 3"); - uiComboboxOnSelected(cbox, onCBChanged, "noneditable"); - uiBoxAppend(page4, uiControl(cbox), 0); - - editable = uiNewEditableCombobox(); - uiEditableComboboxAppend(editable, "Editable Item 1"); - uiEditableComboboxAppend(editable, "Editable Item 2"); - uiEditableComboboxAppend(editable, "Editable Item 3"); - uiEditableComboboxOnChanged(editable, onECBChanged, "editable"); - uiBoxAppend(page4, uiControl(editable), 0); - - rb = uiNewRadioButtons(); - uiRadioButtonsAppend(rb, "Item 1"); - uiRadioButtonsAppend(rb, "Item 2"); - uiRadioButtonsAppend(rb, "Item 3"); - uiRadioButtonsOnSelected(rb, onRBSelected, NULL); - uiBoxAppend(page4, uiControl(rb), 0); - - hbox = newHorizontalBox(); - b = uiNewButton("Append"); - uiButtonOnClicked(b, appendCBRB, NULL); - uiBoxAppend(hbox, uiControl(b), 0); - b = uiNewButton("Second"); - uiButtonOnClicked(b, selectSecond, NULL); - uiBoxAppend(hbox, uiControl(b), 0); - b = uiNewButton("None"); - uiButtonOnClicked(b, selectNone, NULL); - uiBoxAppend(hbox, uiControl(b), 0); - uiBoxAppend(page4, uiControl(hbox), 0); - - uiBoxAppend(page4, uiControl(uiNewHorizontalSeparator()), 0); - - uiBoxAppend(page4, uiControl(uiNewDateTimePicker()), 0); - uiBoxAppend(page4, uiControl(uiNewDatePicker()), 0); - uiBoxAppend(page4, uiControl(uiNewTimePicker()), 0); - - return page4; -} diff --git a/src/libui_sdl/libui/test/page5.c b/src/libui_sdl/libui/test/page5.c deleted file mode 100644 index 9bc1105..0000000 --- a/src/libui_sdl/libui/test/page5.c +++ /dev/null @@ -1,99 +0,0 @@ -// 22 may 2015 -#include "test.h" - -static uiWindow *parent; - -static void openFile(uiButton *b, void *data) -{ - char *fn; - - fn = uiOpenFile(parent); - if (fn == NULL) - uiLabelSetText(uiLabel(data), "(cancelled)"); - else { - uiLabelSetText(uiLabel(data), fn); - uiFreeText(fn); - } -} - -static void saveFile(uiButton *b, void *data) -{ - char *fn; - - fn = uiSaveFile(parent); - if (fn == NULL) - uiLabelSetText(uiLabel(data), "(cancelled)"); - else { - uiLabelSetText(uiLabel(data), fn); - uiFreeText(fn); - } -} - -static uiEntry *title, *description; - -static void msgBox(uiButton *b, void *data) -{ - char *t, *d; - - t = uiEntryText(title); - d = uiEntryText(description); - uiMsgBox(parent, t, d); - uiFreeText(d); - uiFreeText(t); -} - -static void msgBoxError(uiButton *b, void *data) -{ - char *t, *d; - - t = uiEntryText(title); - d = uiEntryText(description); - uiMsgBoxError(parent, t, d); - uiFreeText(d); - uiFreeText(t); -} - -uiBox *makePage5(uiWindow *pw) -{ - uiBox *page5; - uiBox *hbox; - uiButton *button; - uiLabel *label; - - parent = pw; - - page5 = newVerticalBox(); - -#define D(n, f) \ - hbox = newHorizontalBox(); \ - button = uiNewButton(n); \ - label = uiNewLabel(""); \ - uiButtonOnClicked(button, f, label); \ - uiBoxAppend(hbox, uiControl(button), 0); \ - uiBoxAppend(hbox, uiControl(label), 0); \ - uiBoxAppend(page5, uiControl(hbox), 0); - - D("Open File", openFile); - D("Save File", saveFile); - - title = uiNewEntry(); - uiEntrySetText(title, "Title"); - description = uiNewEntry(); - uiEntrySetText(description, "Description"); - - hbox = newHorizontalBox(); - button = uiNewButton("Message Box"); - uiButtonOnClicked(button, msgBox, NULL); - uiBoxAppend(hbox, uiControl(button), 0); - uiBoxAppend(hbox, uiControl(title), 0); - uiBoxAppend(page5, uiControl(hbox), 0); - - hbox = newHorizontalBox(); - button = uiNewButton("Error Box"); - uiButtonOnClicked(button, msgBoxError, NULL); - uiBoxAppend(hbox, uiControl(button), 0); - uiBoxAppend(hbox, uiControl(description), 0); - uiBoxAppend(page5, uiControl(hbox), 0); - - return page5; -} diff --git a/src/libui_sdl/libui/test/page6.c b/src/libui_sdl/libui/test/page6.c deleted file mode 100644 index 896b3d5..0000000 --- a/src/libui_sdl/libui/test/page6.c +++ /dev/null @@ -1,126 +0,0 @@ -// 8 october 2015 -#include -#include "test.h" - -static uiArea *area; -static uiCombobox *which; -static uiCheckbox *swallowKeys; - -struct handler { - uiAreaHandler ah; -}; - -static struct handler handler; - -static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p) -{ - runDrawTest(uiComboboxSelected(which), p); -} - -static void handlerMouseEvent(uiAreaHandler *a, uiArea *area, uiAreaMouseEvent *e) -{ - printf("mouse (%g,%g):(%g,%g) down:%d up:%d count:%d mods:%x held:0x%" PRIX64 "\n", - e->X, - e->Y, - e->AreaWidth, - e->AreaHeight, - (int) e->Down, - (int) e->Up, - (int) e->Count, - (uint32_t) e->Modifiers, - e->Held1To64); -} - -static void handlerMouseCrossed(uiAreaHandler *ah, uiArea *a, int left) -{ - printf("mouse crossed %d\n", left); -} - -static void handlerDragBroken(uiAreaHandler *ah, uiArea *a) -{ - printf("drag broken\n"); -} - -static int handlerKeyEvent(uiAreaHandler *ah, uiArea *a, uiAreaKeyEvent *e) -{ - char k[4]; - - k[0] = '\''; - k[1] = e->Key; - k[2] = '\''; - k[3] = '\0'; - if (e->Key == 0) { - k[0] = '0'; - k[1] = '\0'; - } - printf("key key:%s extkey:%d mod:%d mods:%d up:%d\n", - k, - (int) e->ExtKey, - (int) e->Modifier, - (int) e->Modifiers, - e->Up); - return uiCheckboxChecked(swallowKeys); -} - -static void shouldntHappen(uiCombobox *c, void *data) -{ - fprintf(stderr, "YOU SHOULD NOT SEE THIS. If you do, uiComboboxSetSelected() is triggering uiComboboxOnSelected(), which it should not.\n"); -} - -static void redraw(uiCombobox *c, void *data) -{ - uiAreaQueueRedrawAll(area); -} - -static void enableArea(uiButton *b, void *data) -{ - if (data != NULL) - uiControlEnable(uiControl(area)); - else - uiControlDisable(uiControl(area)); -} - -uiBox *makePage6(void) -{ - uiBox *page6; - uiBox *hbox; - uiButton *button; - - handler.ah.Draw = handlerDraw; - handler.ah.MouseEvent = handlerMouseEvent; - handler.ah.MouseCrossed = handlerMouseCrossed; - handler.ah.DragBroken = handlerDragBroken; - handler.ah.KeyEvent = handlerKeyEvent; - - page6 = newVerticalBox(); - - hbox = newHorizontalBox(); - uiBoxAppend(page6, uiControl(hbox), 0); - - which = uiNewCombobox(); - populateComboboxWithTests(which); - // this is to make sure that uiComboboxOnSelected() doesn't trigger with uiComboboxSetSelected() - uiComboboxOnSelected(which, shouldntHappen, NULL); - uiComboboxSetSelected(which, 0); - uiComboboxOnSelected(which, redraw, NULL); - uiBoxAppend(hbox, uiControl(which), 0); - - area = uiNewArea((uiAreaHandler *) (&handler)); - uiBoxAppend(page6, uiControl(area), 1); - - hbox = newHorizontalBox(); - uiBoxAppend(page6, uiControl(hbox), 0); - - swallowKeys = uiNewCheckbox("Consider key events handled"); - uiBoxAppend(hbox, uiControl(swallowKeys), 1); - - button = uiNewButton("Enable"); - uiButtonOnClicked(button, enableArea, button); - uiBoxAppend(hbox, uiControl(button), 0); - - button = uiNewButton("Disable"); - uiButtonOnClicked(button, enableArea, NULL); - uiBoxAppend(hbox, uiControl(button), 0); - - return page6; -} diff --git a/src/libui_sdl/libui/test/page7.c b/src/libui_sdl/libui/test/page7.c deleted file mode 100644 index 5cc9114..0000000 --- a/src/libui_sdl/libui/test/page7.c +++ /dev/null @@ -1,25 +0,0 @@ -// 13 october 2015 -#include "test.h" - -uiBox *makePage7(void) -{ - uiBox *page7; - uiGroup *group; - uiBox *box2; - - page7 = newHorizontalBox(); - - group = makePage7a(); - uiBoxAppend(page7, uiControl(group), 1); - - box2 = newVerticalBox(); - uiBoxAppend(page7, uiControl(box2), 1); - - group = makePage7b(); - uiBoxAppend(box2, uiControl(group), 1); - - group = makePage7c(); - uiBoxAppend(box2, uiControl(group), 1); - - return page7; -} diff --git a/src/libui_sdl/libui/test/page7a.c b/src/libui_sdl/libui/test/page7a.c deleted file mode 100644 index 72e0321..0000000 --- a/src/libui_sdl/libui/test/page7a.c +++ /dev/null @@ -1,139 +0,0 @@ -// 13 october 2015 -#include "test.h" - -static uiArea *area; -static uiEntry *startAngle; -static uiEntry *sweep; -static uiCheckbox *negative; -static uiCheckbox *radians; - -struct handler { - uiAreaHandler ah; -}; - -static struct handler handler; - -// based on the cairo arc sample -static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p) -{ - double xc = 128.0; - double yc = 128.0; - double radius = 100.0; - uiDrawBrush source; - uiDrawStrokeParams sp; - uiDrawPath *path; - char *startText; - char *sweepText; - double factor; - - source.Type = uiDrawBrushTypeSolid; - source.R = 0; - source.G = 0; - source.B = 0; - source.A = 1; - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.MiterLimit = uiDrawDefaultMiterLimit; - sp.Dashes = NULL; - sp.NumDashes = 0; - sp.DashPhase = 0; - - startText = uiEntryText(startAngle); - sweepText = uiEntryText(sweep); - - factor = uiPi / 180; - if (uiCheckboxChecked(radians)) - factor = 1; - - sp.Thickness = 10.0; - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(path, xc, yc); - uiDrawPathArcTo(path, - xc, yc, - radius, - atof(startText) * factor, - atof(sweepText) * factor, - uiCheckboxChecked(negative)); - uiDrawPathEnd(path); - uiDrawStroke(p->Context, path, &source, &sp); - uiDrawFreePath(path); - - uiFreeText(startText); - uiFreeText(sweepText); -} - -static void handlerMouseEvent(uiAreaHandler *a, uiArea *area, uiAreaMouseEvent *e) -{ - // do nothing -} - -static void handlerMouseCrossed(uiAreaHandler *ah, uiArea *a, int left) -{ - // do nothing -} - -static void handlerDragBroken(uiAreaHandler *ah, uiArea *a) -{ - // do nothing -} - -static int handlerKeyEvent(uiAreaHandler *ah, uiArea *a, uiAreaKeyEvent *e) -{ - return 0; -} - -static void entryChanged(uiEntry *e, void *data) -{ - uiAreaQueueRedrawAll(area); -} - -static void checkboxToggled(uiCheckbox *c, void *data) -{ - uiAreaQueueRedrawAll(area); -} - -uiGroup *makePage7a(void) -{ - uiGroup *group; - uiBox *box, *box2; - - handler.ah.Draw = handlerDraw; - handler.ah.MouseEvent = handlerMouseEvent; - handler.ah.MouseCrossed = handlerMouseCrossed; - handler.ah.DragBroken = handlerDragBroken; - handler.ah.KeyEvent = handlerKeyEvent; - - group = newGroup("Arc Test"); - - box = newVerticalBox(); - uiGroupSetChild(group, uiControl(box)); - - area = uiNewArea((uiAreaHandler *) (&handler)); - uiBoxAppend(box, uiControl(area), 1); - - box2 = newHorizontalBox(); - uiBoxAppend(box, uiControl(box2), 0); - - uiBoxAppend(box2, uiControl(uiNewLabel("Start Angle")), 0); - startAngle = uiNewEntry(); - uiEntryOnChanged(startAngle, entryChanged, NULL); - uiBoxAppend(box2, uiControl(startAngle), 1); - - box2 = newHorizontalBox(); - uiBoxAppend(box, uiControl(box2), 0); - - uiBoxAppend(box2, uiControl(uiNewLabel("Sweep")), 0); - sweep = uiNewEntry(); - uiEntryOnChanged(sweep, entryChanged, NULL); - uiBoxAppend(box2, uiControl(sweep), 1); - - negative = uiNewCheckbox("Negative"); - uiCheckboxOnToggled(negative, checkboxToggled, NULL); - uiBoxAppend(box, uiControl(negative), 0); - - radians = uiNewCheckbox("Radians"); - uiCheckboxOnToggled(radians, checkboxToggled, NULL); - uiBoxAppend(box, uiControl(radians), 0); - - return group; -} diff --git a/src/libui_sdl/libui/test/page7b.c b/src/libui_sdl/libui/test/page7b.c deleted file mode 100644 index d1f98a7..0000000 --- a/src/libui_sdl/libui/test/page7b.c +++ /dev/null @@ -1,71 +0,0 @@ -// 13 october 2015 -#include "test.h" - -static uiArea *area; -static uiCheckbox *label; - -struct handler { - uiAreaHandler ah; -}; - -static struct handler handler; - -static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p) -{ - // do nothing -} - -static void handlerMouseEvent(uiAreaHandler *a, uiArea *area, uiAreaMouseEvent *e) -{ - char pos[128]; - - // wonderful, vanilla snprintf() isn't in visual studio 2013 - http://blogs.msdn.com/b/vcblog/archive/2013/07/19/c99-library-support-in-visual-studio-2013.aspx - // we can't use _snprintf() in the test suite because that's msvc-only, so oops. sprintf() it is. - sprintf(pos, "X %g Y %g", e->X, e->Y); - uiCheckboxSetText(label, pos); -} - -static void handlerMouseCrossed(uiAreaHandler *ah, uiArea *a, int left) -{ -printf("%d %d\n", left, !left); - uiCheckboxSetChecked(label, !left); -} - -static void handlerDragBroken(uiAreaHandler *ah, uiArea *a) -{ - // do nothing -} - -static int handlerKeyEvent(uiAreaHandler *ah, uiArea *a, uiAreaKeyEvent *e) -{ - if (e->Key == 'h' && !e->Up) { - // TODO hide the widget momentarily on the h key - return 1; - } - return 0; -} - -uiGroup *makePage7b(void) -{ - uiGroup *group; - uiBox *box; - - handler.ah.Draw = handlerDraw; - handler.ah.MouseEvent = handlerMouseEvent; - handler.ah.MouseCrossed = handlerMouseCrossed; - handler.ah.DragBroken = handlerDragBroken; - handler.ah.KeyEvent = handlerKeyEvent; - - group = newGroup("Scrolling Mouse Test"); - - box = newVerticalBox(); - uiGroupSetChild(group, uiControl(box)); - - area = uiNewScrollingArea((uiAreaHandler *) (&handler), 5000, 5000); - uiBoxAppend(box, uiControl(area), 1); - - label = uiNewCheckbox(""); - uiBoxAppend(box, uiControl(label), 0); - - return group; -} diff --git a/src/libui_sdl/libui/test/page7c.c b/src/libui_sdl/libui/test/page7c.c deleted file mode 100644 index ac6a316..0000000 --- a/src/libui_sdl/libui/test/page7c.c +++ /dev/null @@ -1,133 +0,0 @@ -// 13 october 2015 -#include "test.h" - -static uiArea *area; - -struct handler { - uiAreaHandler ah; -}; - -static struct handler handler; - -#define areaSize 250 -#define borderThickness 1 -#define padding 30 -#define circleRadius ((areaSize - padding) / 2) - -static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *dp) -{ - uiDrawPath *path; - uiDrawBrush brush; - uiDrawStrokeParams sp; - uiDrawBrushGradientStop stops[2]; - - memset(&brush, 0, sizeof (uiDrawBrush)); - memset(&sp, 0, sizeof (uiDrawStrokeParams)); - - // add some buffering to detect scrolls that aren't on the dot and draws that are outside the scroll area on Windows - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathAddRectangle(path, - -50, -50, - areaSize + 100, areaSize + 100); - uiDrawPathEnd(path); - brush.Type = uiDrawBrushTypeSolid; - brush.R = 0; - brush.G = 1; - brush.B = 0; - brush.A = 1; - uiDrawFill(dp->Context, path, &brush); - uiDrawFreePath(path); - - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathAddRectangle(path, - 0, 0, - areaSize, areaSize); - uiDrawPathEnd(path); - brush.Type = uiDrawBrushTypeSolid; - brush.R = 1; - brush.G = 1; - brush.B = 1; - brush.A = 1; - uiDrawFill(dp->Context, path, &brush); - brush.Type = uiDrawBrushTypeSolid; - brush.R = 1; - brush.G = 0; - brush.B = 0; - brush.A = 1; - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.Thickness = 1; - sp.MiterLimit = uiDrawDefaultMiterLimit; - uiDrawStroke(dp->Context, path, &brush, &sp); - uiDrawFreePath(path); - - path = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigureWithArc(path, - areaSize / 2, areaSize / 2, - circleRadius, - 0, 2 * uiPi, - 0); - uiDrawPathEnd(path); - stops[0].Pos =0.0; - stops[0].R = 0.0; - stops[0].G = 1.0; - stops[0].B = 1.0; - stops[0].A = 1.0; - stops[1].Pos = 1.0; - stops[1].R = 0.0; - stops[1].G = 0.0; - stops[1].B = 1.0; - stops[1].A = 1.0; - brush.Type = uiDrawBrushTypeLinearGradient; - brush.X0 = areaSize / 2; - brush.Y0 = padding; - brush.X1 = areaSize / 2; - brush.Y1 = areaSize - padding; - brush.Stops = stops; - brush.NumStops = 2; - uiDrawFill(dp->Context, path, &brush); - uiDrawFreePath(path); -} - -static void handlerMouseEvent(uiAreaHandler *a, uiArea *area, uiAreaMouseEvent *e) -{ - // do nothing -} - -static void handlerMouseCrossed(uiAreaHandler *ah, uiArea *a, int left) -{ - // do nothing -} - -static void handlerDragBroken(uiAreaHandler *ah, uiArea *a) -{ - // do nothing -} - -static int handlerKeyEvent(uiAreaHandler *ah, uiArea *a, uiAreaKeyEvent *e) -{ - if (e->Key == 'h' && !e->Up) { - // TODO hide the widget momentarily on the h key - return 1; - } - return 0; -} - -uiGroup *makePage7c(void) -{ - uiGroup *group; - - handler.ah.Draw = handlerDraw; - handler.ah.MouseEvent = handlerMouseEvent; - handler.ah.MouseCrossed = handlerMouseCrossed; - handler.ah.DragBroken = handlerDragBroken; - handler.ah.KeyEvent = handlerKeyEvent; - - group = newGroup("Scrolling Drawing Test"); - - area = uiNewScrollingArea((uiAreaHandler *) (&handler), - areaSize, areaSize); - uiGroupSetChild(group, uiControl(area)); - - return group; -} diff --git a/src/libui_sdl/libui/test/page8.c b/src/libui_sdl/libui/test/page8.c deleted file mode 100644 index 7d85556..0000000 --- a/src/libui_sdl/libui/test/page8.c +++ /dev/null @@ -1,46 +0,0 @@ -// 22 december 2015 -#include "test.h" - -static void onListFonts(uiButton *b, void *data) -{ - uiDrawFontFamilies *ff; - char *this; - int i, n; - - uiMultilineEntrySetText(uiMultilineEntry(data), ""); - ff = uiDrawListFontFamilies(); - n = uiDrawFontFamiliesNumFamilies(ff); - for (i = 0; i < n; i++) { - this = uiDrawFontFamiliesFamily(ff, i); - uiMultilineEntryAppend(uiMultilineEntry(data), this); - uiMultilineEntryAppend(uiMultilineEntry(data), "\n"); - uiFreeText(this); - } - uiDrawFreeFontFamilies(ff); -} - -uiBox *makePage8(void) -{ - uiBox *page8; - uiGroup *group; - uiBox *vbox; - uiMultilineEntry *me; - uiButton *button; - - page8 = newHorizontalBox(); - - group = newGroup("Font Families"); - uiBoxAppend(page8, uiControl(group), 1); - - vbox = newVerticalBox(); - uiGroupSetChild(group, uiControl(vbox)); - - me = uiNewMultilineEntry(); - uiBoxAppend(vbox, uiControl(me), 1); - - button = uiNewButton("List Font Families"); - uiButtonOnClicked(button, onListFonts, me); - uiBoxAppend(vbox, uiControl(button), 0); - - return page8; -} diff --git a/src/libui_sdl/libui/test/page9.c b/src/libui_sdl/libui/test/page9.c deleted file mode 100644 index 65b2d3a..0000000 --- a/src/libui_sdl/libui/test/page9.c +++ /dev/null @@ -1,289 +0,0 @@ -// 22 december 2015 -#include "test.h" - -static uiEntry *textString; -static uiEntry *textFont; -static uiEntry *textSize; -static uiCombobox *textWeight; -static uiCombobox *textItalic; -static uiCheckbox *textSmallCaps; -static uiCombobox *textStretch; -static uiEntry *textWidth; -static uiButton *textApply; -static uiCheckbox *addLeading; -static uiArea *textArea; -static uiAreaHandler textAreaHandler; - -static double entryDouble(uiEntry *e) -{ - char *s; - double d; - - s = uiEntryText(e); - d = atof(s); - uiFreeText(s); - return d; -} - -static void drawGuides(uiDrawContext *c, uiDrawTextFontMetrics *m) -{ - uiDrawPath *p; - uiDrawBrush b; - uiDrawStrokeParams sp; - double leading; - double y; - - leading = 0; - if (uiCheckboxChecked(addLeading)) - leading = m->Leading; - - memset(&b, 0, sizeof (uiDrawBrush)); - b.Type = uiDrawBrushTypeSolid; - memset(&sp, 0, sizeof (uiDrawStrokeParams)); - sp.Cap = uiDrawLineCapFlat; - sp.Join = uiDrawLineJoinMiter; - sp.MiterLimit = uiDrawDefaultMiterLimit; - sp.Thickness = 2; - - uiDrawSave(c); - - p = uiDrawNewPath(uiDrawFillModeWinding); - y = 10; - uiDrawPathNewFigure(p, 8, y); - y += m->Ascent; - uiDrawPathLineTo(p, 8, y); - uiDrawPathEnd(p); - b.R = 0.94; - b.G = 0.5; - b.B = 0.5; - b.A = 1.0; - uiDrawStroke(c, p, &b, &sp); - uiDrawFreePath(p); - - p = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(p, 8, y); - y += m->Descent; - uiDrawPathLineTo(p, 8, y); - uiDrawPathEnd(p); - b.R = 0.12; - b.G = 0.56; - b.B = 1.0; - b.A = 1.0; - uiDrawStroke(c, p, &b, &sp); - uiDrawFreePath(p); - - // and again for the second line - p = uiDrawNewPath(uiDrawFillModeWinding); - y += leading; - uiDrawPathNewFigure(p, 8, y); - y += m->Ascent; - uiDrawPathLineTo(p, 8, y); - uiDrawPathEnd(p); - b.R = 0.94; - b.G = 0.5; - b.B = 0.5; - b.A = 0.75; - uiDrawStroke(c, p, &b, &sp); - uiDrawFreePath(p); - - p = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathNewFigure(p, 8, y); - y += m->Descent; - uiDrawPathLineTo(p, 8, y); - uiDrawPathEnd(p); - b.R = 0.12; - b.G = 0.56; - b.B = 1.0; - b.A = 0.75; - uiDrawStroke(c, p, &b, &sp); - uiDrawFreePath(p); - - // and a box to text layout top-left corners - p = uiDrawNewPath(uiDrawFillModeWinding); - uiDrawPathAddRectangle(p, 0, 0, 10, 10); - uiDrawPathEnd(p); - uiDrawClip(c, p); - b.R = 0.85; - b.G = 0.65; - b.B = 0.13; - b.A = 1.0; - uiDrawStroke(c, p, &b, &sp); - uiDrawFreePath(p); - - uiDrawRestore(c); -} - -static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *dp) -{ - uiDrawTextFontDescriptor desc; - uiDrawTextFont *font; - char *s; - char *family; // make compiler happy - uiDrawTextLayout *layout; - uiDrawTextFontMetrics metrics; - double ypos; - double width; - double height; - - memset(&desc, 0, sizeof (uiDrawTextFontDescriptor)); - family = uiEntryText(textFont); - desc.Family = family; - desc.Size = entryDouble(textSize); - desc.Weight = uiComboboxSelected(textWeight); - desc.Italic = uiComboboxSelected(textItalic); - desc.Stretch = uiComboboxSelected(textStretch); - font = uiDrawLoadClosestFont(&desc); - uiFreeText(family); - uiDrawTextFontGetMetrics(font, &metrics); - - width = entryDouble(textWidth); - - drawGuides(dp->Context, &metrics); - - s = uiEntryText(textString); - layout = uiDrawNewTextLayout(s, font, width); - uiFreeText(s); - if (uiCheckboxChecked(textSmallCaps)) - ; // TODO - ypos = 10; - uiDrawText(dp->Context, 10, ypos, layout); - // TODO make these optional? - uiDrawTextLayoutExtents(layout, &width, &height); - uiDrawFreeTextLayout(layout); - - layout = uiDrawNewTextLayout("This is a second line", font, -1); - if (/*TODO reuse width*/entryDouble(textWidth) < 0) { - double ad; - - ad = metrics.Ascent + metrics.Descent; - printf("ad:%g extent:%g\n", ad, height); - } - ypos += height; - if (uiCheckboxChecked(addLeading)) - ypos += metrics.Leading; - uiDrawText(dp->Context, 10, ypos, layout); - uiDrawFreeTextLayout(layout); - - uiDrawFreeTextFont(font); -} - -static void handlerMouseEvent(uiAreaHandler *a, uiArea *area, uiAreaMouseEvent *e) -{ - // do nothing -} - -static void handlerMouseCrossed(uiAreaHandler *ah, uiArea *a, int left) -{ - // do nothing -} - -static void handlerDragBroken(uiAreaHandler *ah, uiArea *a) -{ - // do nothing -} - -static int handlerKeyEvent(uiAreaHandler *ah, uiArea *a, uiAreaKeyEvent *e) -{ - // do nothing - return 0; -} - -static void onTextApply(uiButton *b, void *data) -{ - uiAreaQueueRedrawAll(textArea); -} - -uiBox *makePage9(void) -{ - uiBox *page9; - uiBox *vbox; - uiBox *hbox; - - page9 = newVerticalBox(); - vbox = page9; - - hbox = newHorizontalBox(); - uiBoxAppend(vbox, uiControl(hbox), 0); - - textString = uiNewEntry(); - // TODO make it placeholder - uiEntrySetText(textString, "Enter text here"); - uiBoxAppend(hbox, uiControl(textString), 1); - - textFont = uiNewEntry(); - uiEntrySetText(textFont, "Arial"); - uiBoxAppend(hbox, uiControl(textFont), 1); - - textSize = uiNewEntry(); - uiEntrySetText(textSize, "10"); - uiBoxAppend(hbox, uiControl(textSize), 1); - - hbox = newHorizontalBox(); - uiBoxAppend(vbox, uiControl(hbox), 0); - - textWeight = uiNewCombobox(); - uiComboboxAppend(textWeight, "Thin"); - uiComboboxAppend(textWeight, "Ultra Light"); - uiComboboxAppend(textWeight, "Light"); - uiComboboxAppend(textWeight, "Book"); - uiComboboxAppend(textWeight, "Normal"); - uiComboboxAppend(textWeight, "Medium"); - uiComboboxAppend(textWeight, "Semi Bold"); - uiComboboxAppend(textWeight, "Bold"); - uiComboboxAppend(textWeight, "Ultra Bold"); - uiComboboxAppend(textWeight, "Heavy"); - uiComboboxAppend(textWeight, "Ultra Heavy"); - uiComboboxSetSelected(textWeight, uiDrawTextWeightNormal); - uiBoxAppend(hbox, uiControl(textWeight), 1); - - textItalic = uiNewCombobox(); - uiComboboxAppend(textItalic, "Normal"); - uiComboboxAppend(textItalic, "Oblique"); - uiComboboxAppend(textItalic, "Italic"); - uiComboboxSetSelected(textItalic, uiDrawTextItalicNormal); - uiBoxAppend(hbox, uiControl(textItalic), 1); - - textSmallCaps = uiNewCheckbox("Small Caps"); - uiBoxAppend(hbox, uiControl(textSmallCaps), 1); - - hbox = newHorizontalBox(); - uiBoxAppend(vbox, uiControl(hbox), 0); - - textStretch = uiNewCombobox(); - uiComboboxAppend(textStretch, "Ultra Condensed"); - uiComboboxAppend(textStretch, "Extra Condensed"); - uiComboboxAppend(textStretch, "Condensed"); - uiComboboxAppend(textStretch, "Semi Condensed"); - uiComboboxAppend(textStretch, "Normal"); - uiComboboxAppend(textStretch, "Semi Expanded"); - uiComboboxAppend(textStretch, "Expanded"); - uiComboboxAppend(textStretch, "Extra Expanded"); - uiComboboxAppend(textStretch, "Ultra Expanded"); - uiComboboxSetSelected(textStretch, uiDrawTextStretchNormal); - uiBoxAppend(hbox, uiControl(textStretch), 1); - - textWidth = uiNewEntry(); - uiEntrySetText(textWidth, "-1"); - uiBoxAppend(hbox, uiControl(textWidth), 1); - - hbox = newHorizontalBox(); - uiBoxAppend(vbox, uiControl(hbox), 0); - - textApply = uiNewButton("Apply"); - uiButtonOnClicked(textApply, onTextApply, NULL); - uiBoxAppend(hbox, uiControl(textApply), 1); - - addLeading = uiNewCheckbox("Add Leading"); - uiCheckboxSetChecked(addLeading, 1); - uiBoxAppend(hbox, uiControl(addLeading), 0); - - textAreaHandler.Draw = handlerDraw; - textAreaHandler.MouseEvent = handlerMouseEvent; - textAreaHandler.MouseCrossed = handlerMouseCrossed; - textAreaHandler.DragBroken = handlerDragBroken; - textAreaHandler.KeyEvent = handlerKeyEvent; - textArea = uiNewArea(&textAreaHandler); - uiBoxAppend(vbox, uiControl(textArea), 1); - - return page9; -} diff --git a/src/libui_sdl/libui/test/resources.rc b/src/libui_sdl/libui/test/resources.rc deleted file mode 100644 index ebc5d6e..0000000 --- a/src/libui_sdl/libui/test/resources.rc +++ /dev/null @@ -1,13 +0,0 @@ -// 30 may 2015 - -// this is a UTF-8 file -#pragma code_page(65001) - -// this is the Common Controls 6 manifest -// TODO set up the string values here -// 1 is the value of CREATEPROCESS_MANIFEST_RESOURCE_ID and 24 is the value of RT_MANIFEST; we use it directly to avoid needing to share winapi.h with the tests and examples -#ifndef _UI_STATIC -1 24 "test.manifest" -#else -1 24 "test.static.manifest" -#endif diff --git a/src/libui_sdl/libui/test/spaced.c b/src/libui_sdl/libui/test/spaced.c deleted file mode 100644 index 02db99a..0000000 --- a/src/libui_sdl/libui/test/spaced.c +++ /dev/null @@ -1,177 +0,0 @@ -// 22 april 2015 -#include "test.h" - -struct thing { - void *ptr; - int type; -}; - -static struct thing *things = NULL; -static size_t len = 0; -static size_t cap = 0; - -#define grow 32 - -static void *append(void *thing, int type) -{ - if (len >= cap) { - cap += grow; - things = (struct thing *) realloc(things, cap * sizeof (struct thing)); - if (things == NULL) - die("reallocating things array in test/spaced.c append()"); - } - things[len].ptr = thing; - things[len].type = type; - len++; - return things[len - 1].ptr; -} - -enum types { - window, - box, - tab, - group, - form, - grid, -}; - -void setSpaced(int spaced) -{ - size_t i; - void *p; - size_t j, n; - - for (i = 0; i < len; i++) { - p = things[i].ptr; - switch (things[i].type) { - case window: - uiWindowSetMargined(uiWindow(p), spaced); - break; - case box: - uiBoxSetPadded(uiBox(p), spaced); - break; - case tab: - n = uiTabNumPages(uiTab(p)); - for (j = 0; j < n; j++) - uiTabSetMargined(uiTab(p), j, spaced); - break; - case group: - uiGroupSetMargined(uiGroup(p), spaced); - break; - case form: - uiFormSetPadded(uiForm(p), spaced); - break; - case grid: - uiGridSetPadded(uiGrid(p), spaced); - break; - } - } -} - -void querySpaced(char out[12]) // more than enough -{ - int m = 0; - int p = 0; - size_t i; - void *pp; - size_t j, n; - - for (i = 0; i < len; i++) { - pp = things[i].ptr; - switch (things[i].type) { - case window: - if (uiWindowMargined(uiWindow(pp))) - m++; - break; - case box: - p = uiBoxPadded(uiBox(pp)); - break; - case tab: - n = uiTabNumPages(uiTab(pp)); - for (j = 0; j < n; j++) - if (uiTabMargined(uiTab(pp), j)) - m++; - break; - case group: - if (uiGroupMargined(uiGroup(pp))) - m++; - break; - // TODO form - // TODO grid - } - } - - out[0] = 'm'; - out[1] = ' '; - out[2] = '0' + m; - out[3] = ' '; - out[4] = 'p'; - out[5] = ' '; - out[6] = '0'; - if (p) - out[6] = '1'; - out[7] = '\0'; -} - -uiWindow *newWindow(const char *title, int width, int height, int hasMenubar) -{ - uiWindow *w; - - w = uiNewWindow(title, width, height, hasMenubar); - append(w, window); - return w; -} - -uiBox *newHorizontalBox(void) -{ - uiBox *b; - - b = (*newhbox)(); - append(b, box); - return b; -} - -uiBox *newVerticalBox(void) -{ - uiBox *b; - - b = (*newvbox)(); - append(b, box); - return b; -} - -uiTab *newTab(void) -{ - uiTab *t; - - t = uiNewTab(); - append(t, tab); - return t; -} - -uiGroup *newGroup(const char *text) -{ - uiGroup *g; - - g = uiNewGroup(text); - append(g, group); - return g; -} - -uiForm *newForm(void) -{ - uiForm *f; - - f = uiNewForm(); - append(f, form); - return f; -} - -uiGrid *newGrid(void) -{ - uiGrid *g; - - g = uiNewGrid(); - append(g, grid); - return g; -} diff --git a/src/libui_sdl/libui/test/test.h b/src/libui_sdl/libui/test/test.h deleted file mode 100644 index 66b1baa..0000000 --- a/src/libui_sdl/libui/test/test.h +++ /dev/null @@ -1,91 +0,0 @@ -// 22 april 2015 -#include -#include -#include -#include -#include -#include -#include -#include "../ui.h" - -// main.c -extern void die(const char *, ...); -extern uiBox *mainBox; -extern uiTab *mainTab; -extern uiBox *(*newhbox)(void); -extern uiBox *(*newvbox)(void); - -// spaced.c -extern void setSpaced(int); -extern void querySpaced(char[12]); -extern uiWindow *newWindow(const char *title, int width, int height, int hasMenubar); -extern uiBox *newHorizontalBox(void); -extern uiBox *newVerticalBox(void); -extern uiTab *newTab(void); -extern uiGroup *newGroup(const char *); -extern uiForm *newForm(void); -extern uiGrid *newGrid(void); - -// menus.c -extern uiMenuItem *shouldQuitItem; -extern void initMenus(void); - -// page1.c -extern uiBox *page1; -extern void makePage1(uiWindow *); - -// page2.c -extern uiGroup *page2group; -extern uiBox *makePage2(void); - -// page3.c -extern uiBox *makePage3(void); - -// page4.c -extern uiBox *makePage4(void); - -// page5.c -extern uiBox *makePage5(uiWindow *); - -// page6.c -extern uiBox *makePage6(void); - -// drawtests.c -extern void runDrawTest(int, uiAreaDrawParams *); -extern void populateComboboxWithTests(uiCombobox *); - -// page7.c -extern uiBox *makePage7(void); - -// page7a.c -extern uiGroup *makePage7a(void); - -// page7b.c -extern uiGroup *makePage7b(void); - -// page7c.c -extern uiGroup *makePage7c(void); - -// page8.c -extern uiBox *makePage8(void); - -// page9.c -extern uiBox *makePage9(void); - -// page10.c -extern uiBox *makePage10(void); - -// page11.c -extern uiBox *makePage11(void); - -// page12.c -extern uiBox *makePage12(void); - -// page13.c -extern uiBox *makePage13(void); - -// page14.c -extern uiTab *makePage14(void); - -// page15.c -extern uiBox *makePage15(uiWindow *); diff --git a/src/libui_sdl/libui/test/test.manifest b/src/libui_sdl/libui/test/test.manifest deleted file mode 100644 index 41e7c9c..0000000 --- a/src/libui_sdl/libui/test/test.manifest +++ /dev/null @@ -1,20 +0,0 @@ - - - -Your application description here. - - - - - - - - - - - diff --git a/src/libui_sdl/libui/test/test.static.manifest b/src/libui_sdl/libui/test/test.static.manifest deleted file mode 100644 index d8e83a8..0000000 --- a/src/libui_sdl/libui/test/test.static.manifest +++ /dev/null @@ -1,32 +0,0 @@ - - - -Your application description here. - - - - - - - - - - - - - - - - diff --git a/src/libui_sdl/libui/ui.h b/src/libui_sdl/libui/ui.h deleted file mode 100644 index 03aef5d..0000000 --- a/src/libui_sdl/libui/ui.h +++ /dev/null @@ -1,763 +0,0 @@ -// 6 april 2015 - -// TODO add a uiVerifyControlType() function that can be used by control implementations to verify controls - -#ifndef __LIBUI_UI_H__ -#define __LIBUI_UI_H__ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -// this macro is generated by cmake -#ifdef libui_EXPORTS -#ifdef _WIN32 -#define _UI_EXTERN __declspec(dllexport) extern -#else -#define _UI_EXTERN __attribute__((visibility("default"))) extern -#endif -#else -// TODO add __declspec(dllimport) on windows, but only if not static -#define _UI_EXTERN extern -#endif - -// C++ is really really really really really really dumb about enums, so screw that and just make them anonymous -// This has the advantage of being ABI-able should we ever need an ABI... -#define _UI_ENUM(s) typedef unsigned int s; enum - -// This constant is provided because M_PI is nonstandard. -// This comes from Go's math.Pi, which in turn comes from http://oeis.org/A000796. -#define uiPi 3.14159265358979323846264338327950288419716939937510582097494459 - -// TODO uiBool? - -typedef struct uiInitOptions uiInitOptions; - -struct uiInitOptions { - size_t Size; -}; - -_UI_EXTERN const char *uiInit(uiInitOptions *options); -_UI_EXTERN void uiUninit(void); -_UI_EXTERN void uiFreeInitError(const char *err); - -_UI_EXTERN void uiMain(void); -_UI_EXTERN void uiMainSteps(void); -_UI_EXTERN int uiMainStep(int wait); -_UI_EXTERN void uiQuit(void); - -_UI_EXTERN void uiQueueMain(void (*f)(void *data), void *data); - -_UI_EXTERN void uiOnShouldQuit(int (*f)(void *data), void *data); - -_UI_EXTERN void uiFreeText(char *text); - -typedef struct uiControl uiControl; - -struct uiControl { - uint32_t Signature; - uint32_t OSSignature; - uint32_t TypeSignature; - void (*Destroy)(uiControl *); - uintptr_t (*Handle)(uiControl *); - uiControl *(*Parent)(uiControl *); - void (*SetParent)(uiControl *, uiControl *); - int (*Toplevel)(uiControl *); - int (*Visible)(uiControl *); - void (*Show)(uiControl *); - void (*Hide)(uiControl *); - int (*Enabled)(uiControl *); - void (*Enable)(uiControl *); - void (*Disable)(uiControl *); - void (*SetFocus)(uiControl *); - void (*SetMinSize)(uiControl*, int, int); - - int MinWidth, MinHeight; - - void* UserData; -}; -// TOOD add argument names to all arguments -#define uiControl(this) ((uiControl *) (this)) -_UI_EXTERN void uiControlDestroy(uiControl *); -_UI_EXTERN uintptr_t uiControlHandle(uiControl *); -_UI_EXTERN uiControl *uiControlParent(uiControl *); -_UI_EXTERN void uiControlSetParent(uiControl *, uiControl *); -_UI_EXTERN int uiControlToplevel(uiControl *); -_UI_EXTERN int uiControlVisible(uiControl *); -_UI_EXTERN void uiControlShow(uiControl *); -_UI_EXTERN void uiControlHide(uiControl *); -_UI_EXTERN int uiControlEnabled(uiControl *); -_UI_EXTERN void uiControlEnable(uiControl *); -_UI_EXTERN void uiControlDisable(uiControl *); -_UI_EXTERN void uiControlSetFocus(uiControl *); -_UI_EXTERN void uiControlSetMinSize(uiControl *, int w, int h); // -1 = no minimum - -_UI_EXTERN uiControl *uiAllocControl(size_t n, uint32_t OSsig, uint32_t typesig, const char *typenamestr); -_UI_EXTERN void uiFreeControl(uiControl *); - -// TODO make sure all controls have these -_UI_EXTERN void uiControlVerifySetParent(uiControl *, uiControl *); -_UI_EXTERN int uiControlEnabledToUser(uiControl *); - -_UI_EXTERN void uiUserBugCannotSetParentOnToplevel(const char *type); - -typedef struct uiWindow uiWindow; -#define uiWindow(this) ((uiWindow *) (this)) -_UI_EXTERN char *uiWindowTitle(uiWindow *w); -_UI_EXTERN void uiWindowSetTitle(uiWindow *w, const char *title); -_UI_EXTERN void uiWindowPosition(uiWindow *w, int *x, int *y); -_UI_EXTERN void uiWindowSetPosition(uiWindow *w, int x, int y); -_UI_EXTERN void uiWindowContentSize(uiWindow *w, int *width, int *height); -_UI_EXTERN void uiWindowSetContentSize(uiWindow *w, int width, int height); -_UI_EXTERN int uiWindowMinimized(uiWindow *w); -_UI_EXTERN void uiWindowSetMinimized(uiWindow *w, int minimized); -_UI_EXTERN int uiWindowMaximized(uiWindow *w); -_UI_EXTERN void uiWindowSetMaximized(uiWindow *w, int maximized); -_UI_EXTERN int uiWindowFullscreen(uiWindow *w); -_UI_EXTERN void uiWindowSetFullscreen(uiWindow *w, int fullscreen); -_UI_EXTERN int uiWindowBorderless(uiWindow *w); -_UI_EXTERN void uiWindowSetBorderless(uiWindow *w, int borderless); -_UI_EXTERN void uiWindowSetChild(uiWindow *w, uiControl *child); -_UI_EXTERN int uiWindowMargined(uiWindow *w); -_UI_EXTERN void uiWindowSetMargined(uiWindow *w, int margined); -_UI_EXTERN void uiWindowSetDropTarget(uiWindow* w, int drop); -_UI_EXTERN uiWindow *uiNewWindow(const char *title, int width, int height, int maximized, int hasMenubar, int resizable); - -_UI_EXTERN void uiWindowOnContentSizeChanged(uiWindow *w, void (*f)(uiWindow *, void *), void *data); -_UI_EXTERN void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *w, void *data), void *data); -_UI_EXTERN void uiWindowOnDropFile(uiWindow *w, void (*f)(uiWindow *w, char *file, void *data), void *data); -_UI_EXTERN void uiWindowOnGetFocus(uiWindow *w, void (*f)(uiWindow *w, void *data), void *data); -_UI_EXTERN void uiWindowOnLoseFocus(uiWindow *w, void (*f)(uiWindow *w, void *data), void *data); - -typedef struct uiButton uiButton; -#define uiButton(this) ((uiButton *) (this)) -_UI_EXTERN char *uiButtonText(uiButton *b); -_UI_EXTERN void uiButtonSetText(uiButton *b, const char *text); -_UI_EXTERN void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *b, void *data), void *data); -_UI_EXTERN uiButton *uiNewButton(const char *text); - -typedef struct uiBox uiBox; -#define uiBox(this) ((uiBox *) (this)) -_UI_EXTERN void uiBoxAppend(uiBox *b, uiControl *child, int stretchy); -_UI_EXTERN void uiBoxDelete(uiBox *b, int index); -_UI_EXTERN int uiBoxPadded(uiBox *b); -_UI_EXTERN void uiBoxSetPadded(uiBox *b, int padded); -_UI_EXTERN uiBox *uiNewHorizontalBox(void); -_UI_EXTERN uiBox *uiNewVerticalBox(void); - -typedef struct uiCheckbox uiCheckbox; -#define uiCheckbox(this) ((uiCheckbox *) (this)) -_UI_EXTERN char *uiCheckboxText(uiCheckbox *c); -_UI_EXTERN void uiCheckboxSetText(uiCheckbox *c, const char *text); -_UI_EXTERN void uiCheckboxOnToggled(uiCheckbox *c, void (*f)(uiCheckbox *c, void *data), void *data); -_UI_EXTERN int uiCheckboxChecked(uiCheckbox *c); -_UI_EXTERN void uiCheckboxSetChecked(uiCheckbox *c, int checked); -_UI_EXTERN uiCheckbox *uiNewCheckbox(const char *text); - -typedef struct uiEntry uiEntry; -#define uiEntry(this) ((uiEntry *) (this)) -_UI_EXTERN char *uiEntryText(uiEntry *e); -_UI_EXTERN void uiEntrySetText(uiEntry *e, const char *text); -_UI_EXTERN void uiEntryOnChanged(uiEntry *e, void (*f)(uiEntry *e, void *data), void *data); -_UI_EXTERN int uiEntryReadOnly(uiEntry *e); -_UI_EXTERN void uiEntrySetReadOnly(uiEntry *e, int readonly); -_UI_EXTERN uiEntry *uiNewEntry(void); -_UI_EXTERN uiEntry *uiNewPasswordEntry(void); -_UI_EXTERN uiEntry *uiNewSearchEntry(void); - -typedef struct uiLabel uiLabel; -#define uiLabel(this) ((uiLabel *) (this)) -_UI_EXTERN char *uiLabelText(uiLabel *l); -_UI_EXTERN void uiLabelSetText(uiLabel *l, const char *text); -_UI_EXTERN uiLabel *uiNewLabel(const char *text); - -typedef struct uiTab uiTab; -#define uiTab(this) ((uiTab *) (this)) -_UI_EXTERN void uiTabAppend(uiTab *t, const char *name, uiControl *c); -_UI_EXTERN void uiTabInsertAt(uiTab *t, const char *name, int before, uiControl *c); -_UI_EXTERN void uiTabDelete(uiTab *t, int index); -_UI_EXTERN int uiTabNumPages(uiTab *t); -_UI_EXTERN int uiTabMargined(uiTab *t, int page); -_UI_EXTERN void uiTabSetMargined(uiTab *t, int page, int margined); -_UI_EXTERN uiTab *uiNewTab(void); - -typedef struct uiGroup uiGroup; -#define uiGroup(this) ((uiGroup *) (this)) -_UI_EXTERN char *uiGroupTitle(uiGroup *g); -_UI_EXTERN void uiGroupSetTitle(uiGroup *g, const char *title); -_UI_EXTERN void uiGroupSetChild(uiGroup *g, uiControl *c); -_UI_EXTERN int uiGroupMargined(uiGroup *g); -_UI_EXTERN void uiGroupSetMargined(uiGroup *g, int margined); -_UI_EXTERN uiGroup *uiNewGroup(const char *title); - -// spinbox/slider rules: -// setting value outside of range will automatically clamp -// initial value is minimum -// complaint if min >= max? - -typedef struct uiSpinbox uiSpinbox; -#define uiSpinbox(this) ((uiSpinbox *) (this)) -_UI_EXTERN int uiSpinboxValue(uiSpinbox *s); -_UI_EXTERN void uiSpinboxSetValue(uiSpinbox *s, int value); -_UI_EXTERN void uiSpinboxOnChanged(uiSpinbox *s, void (*f)(uiSpinbox *s, void *data), void *data); -_UI_EXTERN uiSpinbox *uiNewSpinbox(int min, int max); - -typedef struct uiSlider uiSlider; -#define uiSlider(this) ((uiSlider *) (this)) -_UI_EXTERN int uiSliderValue(uiSlider *s); -_UI_EXTERN void uiSliderSetValue(uiSlider *s, int value); -_UI_EXTERN void uiSliderOnChanged(uiSlider *s, void (*f)(uiSlider *s, void *data), void *data); -_UI_EXTERN uiSlider *uiNewSlider(int min, int max); - -typedef struct uiProgressBar uiProgressBar; -#define uiProgressBar(this) ((uiProgressBar *) (this)) -_UI_EXTERN int uiProgressBarValue(uiProgressBar *p); -_UI_EXTERN void uiProgressBarSetValue(uiProgressBar *p, int n); -_UI_EXTERN uiProgressBar *uiNewProgressBar(void); - -typedef struct uiSeparator uiSeparator; -#define uiSeparator(this) ((uiSeparator *) (this)) -_UI_EXTERN uiSeparator *uiNewHorizontalSeparator(void); -_UI_EXTERN uiSeparator *uiNewVerticalSeparator(void); - -typedef struct uiCombobox uiCombobox; -#define uiCombobox(this) ((uiCombobox *) (this)) -_UI_EXTERN void uiComboboxAppend(uiCombobox *c, const char *text); -_UI_EXTERN int uiComboboxSelected(uiCombobox *c); -_UI_EXTERN void uiComboboxSetSelected(uiCombobox *c, int n); -_UI_EXTERN void uiComboboxOnSelected(uiCombobox *c, void (*f)(uiCombobox *c, void *data), void *data); -_UI_EXTERN uiCombobox *uiNewCombobox(void); - -typedef struct uiEditableCombobox uiEditableCombobox; -#define uiEditableCombobox(this) ((uiEditableCombobox *) (this)) -_UI_EXTERN void uiEditableComboboxAppend(uiEditableCombobox *c, const char *text); -_UI_EXTERN char *uiEditableComboboxText(uiEditableCombobox *c); -_UI_EXTERN void uiEditableComboboxSetText(uiEditableCombobox *c, const char *text); -// TODO what do we call a function that sets the currently selected item and fills the text field with it? editable comboboxes have no consistent concept of selected item -_UI_EXTERN void uiEditableComboboxOnChanged(uiEditableCombobox *c, void (*f)(uiEditableCombobox *c, void *data), void *data); -_UI_EXTERN uiEditableCombobox *uiNewEditableCombobox(void); - -typedef struct uiRadioButtons uiRadioButtons; -#define uiRadioButtons(this) ((uiRadioButtons *) (this)) -_UI_EXTERN void uiRadioButtonsAppend(uiRadioButtons *r, const char *text); -_UI_EXTERN int uiRadioButtonsSelected(uiRadioButtons *r); -_UI_EXTERN void uiRadioButtonsSetSelected(uiRadioButtons *r, int n); -_UI_EXTERN void uiRadioButtonsOnSelected(uiRadioButtons *r, void (*f)(uiRadioButtons *, void *), void *data); -_UI_EXTERN uiRadioButtons *uiNewRadioButtons(void); - -typedef struct uiDateTimePicker uiDateTimePicker; -#define uiDateTimePicker(this) ((uiDateTimePicker *) (this)) -_UI_EXTERN uiDateTimePicker *uiNewDateTimePicker(void); -_UI_EXTERN uiDateTimePicker *uiNewDatePicker(void); -_UI_EXTERN uiDateTimePicker *uiNewTimePicker(void); - -// TODO provide a facility for entering tab stops? -typedef struct uiMultilineEntry uiMultilineEntry; -#define uiMultilineEntry(this) ((uiMultilineEntry *) (this)) -_UI_EXTERN char *uiMultilineEntryText(uiMultilineEntry *e); -_UI_EXTERN void uiMultilineEntrySetText(uiMultilineEntry *e, const char *text); -_UI_EXTERN void uiMultilineEntryAppend(uiMultilineEntry *e, const char *text); -_UI_EXTERN void uiMultilineEntryOnChanged(uiMultilineEntry *e, void (*f)(uiMultilineEntry *e, void *data), void *data); -_UI_EXTERN int uiMultilineEntryReadOnly(uiMultilineEntry *e); -_UI_EXTERN void uiMultilineEntrySetReadOnly(uiMultilineEntry *e, int readonly); -_UI_EXTERN uiMultilineEntry *uiNewMultilineEntry(void); -_UI_EXTERN uiMultilineEntry *uiNewNonWrappingMultilineEntry(void); - -typedef struct uiMenuItem uiMenuItem; -#define uiMenuItem(this) ((uiMenuItem *) (this)) -_UI_EXTERN void uiMenuItemEnable(uiMenuItem *m); -_UI_EXTERN void uiMenuItemDisable(uiMenuItem *m); -_UI_EXTERN void uiMenuItemOnClicked(uiMenuItem *m, void (*f)(uiMenuItem *sender, uiWindow *window, void *data), void *data); -_UI_EXTERN int uiMenuItemChecked(uiMenuItem *m); -_UI_EXTERN void uiMenuItemSetChecked(uiMenuItem *m, int checked); - -typedef struct uiMenu uiMenu; -#define uiMenu(this) ((uiMenu *) (this)) -_UI_EXTERN uiMenuItem *uiMenuAppendItem(uiMenu *m, const char *name); -_UI_EXTERN uiMenuItem *uiMenuAppendCheckItem(uiMenu *m, const char *name); -_UI_EXTERN uiMenuItem *uiMenuAppendQuitItem(uiMenu *m); -_UI_EXTERN uiMenuItem *uiMenuAppendPreferencesItem(uiMenu *m); -_UI_EXTERN uiMenuItem *uiMenuAppendAboutItem(uiMenu *m); -_UI_EXTERN uiMenuItem *uiMenuAppendSubmenu(uiMenu *m, uiMenu* child); -_UI_EXTERN void uiMenuAppendSeparator(uiMenu *m); -_UI_EXTERN uiMenu *uiNewMenu(const char *name); - -_UI_EXTERN char *uiOpenFile(uiWindow *parent, const char* filter, const char* initpath); -_UI_EXTERN char *uiSaveFile(uiWindow *parent, const char* filter, const char* initpath); -_UI_EXTERN void uiMsgBox(uiWindow *parent, const char *title, const char *description); -_UI_EXTERN void uiMsgBoxError(uiWindow *parent, const char *title, const char *description); - -typedef struct uiArea uiArea; -typedef struct uiAreaHandler uiAreaHandler; -typedef struct uiAreaDrawParams uiAreaDrawParams; -typedef struct uiAreaMouseEvent uiAreaMouseEvent; -typedef struct uiAreaKeyEvent uiAreaKeyEvent; - -typedef struct uiDrawContext uiDrawContext; - -// TO CONSIDER: the uiAreaHandler param there seems useless -// (might use individual callbacks instead of handler struct?) -struct uiAreaHandler { - void (*Draw)(uiAreaHandler *, uiArea *, uiAreaDrawParams *); - // TODO document that resizes cause a full redraw for non-scrolling areas; implementation-defined for scrolling areas - void (*MouseEvent)(uiAreaHandler *, uiArea *, uiAreaMouseEvent *); - // TODO document that on first show if the mouse is already in the uiArea then one gets sent with left=0 - // TODO what about when the area is hidden and then shown again? - void (*MouseCrossed)(uiAreaHandler *, uiArea *, int left); - void (*DragBroken)(uiAreaHandler *, uiArea *); - int (*KeyEvent)(uiAreaHandler *, uiArea *, uiAreaKeyEvent *); - void (*Resize)(uiAreaHandler *, uiArea *, int, int); -}; - -// TODO RTL layouts? -// TODO reconcile edge and corner naming -_UI_ENUM(uiWindowResizeEdge) { - uiWindowResizeEdgeLeft, - uiWindowResizeEdgeTop, - uiWindowResizeEdgeRight, - uiWindowResizeEdgeBottom, - uiWindowResizeEdgeTopLeft, - uiWindowResizeEdgeTopRight, - uiWindowResizeEdgeBottomLeft, - uiWindowResizeEdgeBottomRight, - // TODO have one for keyboard resizes? - // TODO GDK doesn't seem to have any others, including for keyboards... - // TODO way to bring up the system menu instead? -}; - -#define uiGLVersion(major, minor) ((major) | ((minor)<<16)) -#define uiGLVerMajor(ver) ((ver) & 0xFFFF) -#define uiGLVerMinor(ver) ((ver) >> 16) - -#define uiArea(this) ((uiArea *) (this)) -// TODO give a better name -// TODO document the types of width and height -_UI_EXTERN void uiAreaSetSize(uiArea *a, int width, int height); -// TODO uiAreaQueueRedraw() -_UI_EXTERN void uiAreaQueueRedrawAll(uiArea *a); -_UI_EXTERN void uiAreaScrollTo(uiArea *a, double x, double y, double width, double height); -// TODO document these can only be called within Mouse() handlers -// TODO should these be allowed on scrolling areas? -// TODO decide which mouse events should be accepted; Down is the only one guaranteed to work right now -// TODO what happens to events after calling this up to and including the next mouse up? -// TODO release capture? -_UI_EXTERN void uiAreaBeginUserWindowMove(uiArea *a); -_UI_EXTERN void uiAreaBeginUserWindowResize(uiArea *a, uiWindowResizeEdge edge); -_UI_EXTERN void uiAreaSetBackgroundColor(uiArea *a, int r, int g, int b); -_UI_EXTERN uiArea *uiNewArea(uiAreaHandler *ah); -_UI_EXTERN uiArea *uiNewGLArea(uiAreaHandler *ah, const unsigned int* req_versions); -_UI_EXTERN uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height); - -struct uiAreaDrawParams { - uiDrawContext *Context; - - // TODO document that this is only defined for nonscrolling areas - double AreaWidth; - double AreaHeight; - - double ClipX; - double ClipY; - double ClipWidth; - double ClipHeight; -}; - -typedef struct uiDrawPath uiDrawPath; -typedef struct uiDrawBrush uiDrawBrush; -typedef struct uiDrawStrokeParams uiDrawStrokeParams; -typedef struct uiDrawMatrix uiDrawMatrix; - -typedef struct uiDrawBrushGradientStop uiDrawBrushGradientStop; - -typedef struct uiDrawBitmap uiDrawBitmap; - -_UI_ENUM(uiDrawBrushType) { - uiDrawBrushTypeSolid, - uiDrawBrushTypeLinearGradient, - uiDrawBrushTypeRadialGradient, - uiDrawBrushTypeImage, -}; - -_UI_ENUM(uiDrawLineCap) { - uiDrawLineCapFlat, - uiDrawLineCapRound, - uiDrawLineCapSquare, -}; - -_UI_ENUM(uiDrawLineJoin) { - uiDrawLineJoinMiter, - uiDrawLineJoinRound, - uiDrawLineJoinBevel, -}; - -// this is the default for botoh cairo and Direct2D (in the latter case, from the C++ helper functions) -// Core Graphics doesn't explicitly specify a default, but NSBezierPath allows you to choose one, and this is the initial value -// so we're good to use it too! -#define uiDrawDefaultMiterLimit 10.0 - -_UI_ENUM(uiDrawFillMode) { - uiDrawFillModeWinding, - uiDrawFillModeAlternate, -}; - -struct uiDrawMatrix { - double M11; - double M12; - double M21; - double M22; - double M31; - double M32; -}; - -struct uiDrawBrush { - uiDrawBrushType Type; - - // solid brushes - double R; - double G; - double B; - double A; - - // gradient brushes - double X0; // linear: start X, radial: start X - double Y0; // linear: start Y, radial: start Y - double X1; // linear: end X, radial: outer circle center X - double Y1; // linear: end Y, radial: outer circle center Y - double OuterRadius; // radial gradients only - uiDrawBrushGradientStop *Stops; - size_t NumStops; - // TODO extend mode - // cairo: none, repeat, reflect, pad; no individual control - // Direct2D: repeat, reflect, pad; no individual control - // Core Graphics: none, pad; before and after individually - // TODO cairo documentation is inconsistent about pad - - // TODO images - - // TODO transforms -}; - -struct uiDrawBrushGradientStop { - double Pos; - double R; - double G; - double B; - double A; -}; - -struct uiDrawStrokeParams { - uiDrawLineCap Cap; - uiDrawLineJoin Join; - // TODO what if this is 0? on windows there will be a crash with dashing - double Thickness; - double MiterLimit; - double *Dashes; - // TOOD what if this is 1 on Direct2D? - // TODO what if a dash is 0 on Cairo or Quartz? - size_t NumDashes; - double DashPhase; -}; - -struct uiRect { - int X; - int Y; - int Width; - int Height; -}; - -typedef struct uiRect uiRect; - -_UI_EXTERN uiDrawPath *uiDrawNewPath(uiDrawFillMode fillMode); -_UI_EXTERN void uiDrawFreePath(uiDrawPath *p); - -_UI_EXTERN void uiDrawPathNewFigure(uiDrawPath *p, double x, double y); -_UI_EXTERN void uiDrawPathNewFigureWithArc(uiDrawPath *p, double xCenter, double yCenter, double radius, double startAngle, double sweep, int negative); -_UI_EXTERN void uiDrawPathLineTo(uiDrawPath *p, double x, double y); -// notes: angles are both relative to 0 and go counterclockwise -// TODO is the initial line segment on cairo and OS X a proper join? -// TODO what if sweep < 0? -_UI_EXTERN void uiDrawPathArcTo(uiDrawPath *p, double xCenter, double yCenter, double radius, double startAngle, double sweep, int negative); -_UI_EXTERN void uiDrawPathBezierTo(uiDrawPath *p, double c1x, double c1y, double c2x, double c2y, double endX, double endY); -// TODO quadratic bezier -_UI_EXTERN void uiDrawPathCloseFigure(uiDrawPath *p); - -// TODO effect of these when a figure is already started -_UI_EXTERN void uiDrawPathAddRectangle(uiDrawPath *p, double x, double y, double width, double height); - -_UI_EXTERN void uiDrawPathEnd(uiDrawPath *p); - -_UI_EXTERN void uiDrawStroke(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b, uiDrawStrokeParams *p); -_UI_EXTERN void uiDrawFill(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b); - -// TODO primitives: -// - rounded rectangles -// - elliptical arcs -// - quadratic bezier curves - -_UI_EXTERN void uiDrawMatrixSetIdentity(uiDrawMatrix *m); -_UI_EXTERN void uiDrawMatrixTranslate(uiDrawMatrix *m, double x, double y); -_UI_EXTERN void uiDrawMatrixScale(uiDrawMatrix *m, double xCenter, double yCenter, double x, double y); -_UI_EXTERN void uiDrawMatrixRotate(uiDrawMatrix *m, double x, double y, double amount); -_UI_EXTERN void uiDrawMatrixSkew(uiDrawMatrix *m, double x, double y, double xamount, double yamount); -_UI_EXTERN void uiDrawMatrixMultiply(uiDrawMatrix *dest, uiDrawMatrix *src); -_UI_EXTERN int uiDrawMatrixInvertible(uiDrawMatrix *m); -_UI_EXTERN int uiDrawMatrixInvert(uiDrawMatrix *m); -_UI_EXTERN void uiDrawMatrixTransformPoint(uiDrawMatrix *m, double *x, double *y); -_UI_EXTERN void uiDrawMatrixTransformSize(uiDrawMatrix *m, double *x, double *y); - -_UI_EXTERN void uiDrawTransform(uiDrawContext *c, uiDrawMatrix *m); - -// TODO add a uiDrawPathStrokeToFill() or something like that -_UI_EXTERN void uiDrawClip(uiDrawContext *c, uiDrawPath *path); - -_UI_EXTERN void uiDrawSave(uiDrawContext *c); -_UI_EXTERN void uiDrawRestore(uiDrawContext *c); - -// bitmap API -_UI_EXTERN uiDrawBitmap* uiDrawNewBitmap(uiDrawContext* c, int width, int height, int alpha); -_UI_EXTERN void uiDrawBitmapUpdate(uiDrawBitmap* bmp, const void* data); -_UI_EXTERN void uiDrawBitmapDraw(uiDrawContext* c, uiDrawBitmap* bmp, uiRect* srcrect, uiRect* dstrect, int filter); -_UI_EXTERN void uiDrawFreeBitmap(uiDrawBitmap* bmp); - -// TODO manage the use of Text, Font, and TextFont, and of the uiDrawText prefix in general - -///// TODO reconsider this -typedef struct uiDrawFontFamilies uiDrawFontFamilies; - -_UI_EXTERN uiDrawFontFamilies *uiDrawListFontFamilies(void); -_UI_EXTERN int uiDrawFontFamiliesNumFamilies(uiDrawFontFamilies *ff); -_UI_EXTERN char *uiDrawFontFamiliesFamily(uiDrawFontFamilies *ff, int n); -_UI_EXTERN void uiDrawFreeFontFamilies(uiDrawFontFamilies *ff); -///// END TODO - -typedef struct uiDrawTextLayout uiDrawTextLayout; -typedef struct uiDrawTextFont uiDrawTextFont; -typedef struct uiDrawTextFontDescriptor uiDrawTextFontDescriptor; -typedef struct uiDrawTextFontMetrics uiDrawTextFontMetrics; - -_UI_ENUM(uiDrawTextWeight) { - uiDrawTextWeightThin, - uiDrawTextWeightUltraLight, - uiDrawTextWeightLight, - uiDrawTextWeightBook, - uiDrawTextWeightNormal, - uiDrawTextWeightMedium, - uiDrawTextWeightSemiBold, - uiDrawTextWeightBold, - uiDrawTextWeightUltraBold, - uiDrawTextWeightHeavy, - uiDrawTextWeightUltraHeavy, -}; - -_UI_ENUM(uiDrawTextItalic) { - uiDrawTextItalicNormal, - uiDrawTextItalicOblique, - uiDrawTextItalicItalic, -}; - -_UI_ENUM(uiDrawTextStretch) { - uiDrawTextStretchUltraCondensed, - uiDrawTextStretchExtraCondensed, - uiDrawTextStretchCondensed, - uiDrawTextStretchSemiCondensed, - uiDrawTextStretchNormal, - uiDrawTextStretchSemiExpanded, - uiDrawTextStretchExpanded, - uiDrawTextStretchExtraExpanded, - uiDrawTextStretchUltraExpanded, -}; - -struct uiDrawTextFontDescriptor { - const char *Family; - double Size; - uiDrawTextWeight Weight; - uiDrawTextItalic Italic; - uiDrawTextStretch Stretch; -}; - -struct uiDrawTextFontMetrics { - double Ascent; - double Descent; - double Leading; - // TODO do these two mean the same across all platforms? - double UnderlinePos; - double UnderlineThickness; -}; - -_UI_EXTERN uiDrawTextFont *uiDrawLoadClosestFont(const uiDrawTextFontDescriptor *desc); -_UI_EXTERN void uiDrawFreeTextFont(uiDrawTextFont *font); -_UI_EXTERN uintptr_t uiDrawTextFontHandle(uiDrawTextFont *font); -_UI_EXTERN void uiDrawTextFontDescribe(uiDrawTextFont *font, uiDrawTextFontDescriptor *desc); -// TODO make copy with given attributes methods? -// TODO yuck this name -_UI_EXTERN void uiDrawTextFontGetMetrics(uiDrawTextFont *font, uiDrawTextFontMetrics *metrics); - -// TODO initial line spacing? and what about leading? -_UI_EXTERN uiDrawTextLayout *uiDrawNewTextLayout(const char *text, uiDrawTextFont *defaultFont, double width); -_UI_EXTERN void uiDrawFreeTextLayout(uiDrawTextLayout *layout); -// TODO get width -_UI_EXTERN void uiDrawTextLayoutSetWidth(uiDrawTextLayout *layout, double width); -_UI_EXTERN void uiDrawTextLayoutExtents(uiDrawTextLayout *layout, double *width, double *height); - -// and the attributes that you can set on a text layout -_UI_EXTERN void uiDrawTextLayoutSetColor(uiDrawTextLayout *layout, int startChar, int endChar, double r, double g, double b, double a); - -_UI_EXTERN void uiDrawText(uiDrawContext *c, double x, double y, uiDrawTextLayout *layout); - - -// OpenGL support - -typedef struct uiGLContext uiGLContext; - -_UI_EXTERN uiGLContext *uiAreaGetGLContext(uiArea* a); -_UI_EXTERN void uiGLMakeContextCurrent(uiGLContext* ctx); -_UI_EXTERN void uiGLBegin(uiGLContext* ctx); -_UI_EXTERN void uiGLEnd(uiGLContext* ctx); -_UI_EXTERN unsigned int uiGLGetVersion(uiGLContext* ctx); -_UI_EXTERN void *uiGLGetProcAddress(const char* proc); -_UI_EXTERN int uiGLGetFramebuffer(uiGLContext* ctx); -_UI_EXTERN float uiGLGetFramebufferScale(uiGLContext* ctx); -_UI_EXTERN void uiGLSwapBuffers(uiGLContext* ctx); -_UI_EXTERN void uiGLSetVSync(int sync); - - -_UI_ENUM(uiModifiers) { - uiModifierCtrl = 1 << 0, - uiModifierAlt = 1 << 1, - uiModifierShift = 1 << 2, - uiModifierSuper = 1 << 3, -}; - -// TODO document drag captures -struct uiAreaMouseEvent { - // TODO document what these mean for scrolling areas - double X; - double Y; - - // TODO see draw above - double AreaWidth; - double AreaHeight; - - int Down; - int Up; - - int Count; - - uiModifiers Modifiers; - - uint64_t Held1To64; -}; - -_UI_ENUM(uiExtKey) { - uiExtKeyEscape = 1, - uiExtKeyInsert, // equivalent to "Help" on Apple keyboards - uiExtKeyDelete, - uiExtKeyHome, - uiExtKeyEnd, - uiExtKeyPageUp, - uiExtKeyPageDown, - uiExtKeyUp, - uiExtKeyDown, - uiExtKeyLeft, - uiExtKeyRight, - uiExtKeyF1, // F1..F12 are guaranteed to be consecutive - uiExtKeyF2, - uiExtKeyF3, - uiExtKeyF4, - uiExtKeyF5, - uiExtKeyF6, - uiExtKeyF7, - uiExtKeyF8, - uiExtKeyF9, - uiExtKeyF10, - uiExtKeyF11, - uiExtKeyF12, - uiExtKeyN0, // numpad keys; independent of Num Lock state - uiExtKeyN1, // N0..N9 are guaranteed to be consecutive - uiExtKeyN2, - uiExtKeyN3, - uiExtKeyN4, - uiExtKeyN5, - uiExtKeyN6, - uiExtKeyN7, - uiExtKeyN8, - uiExtKeyN9, - uiExtKeyNDot, - uiExtKeyNEnter, - uiExtKeyNAdd, - uiExtKeyNSubtract, - uiExtKeyNMultiply, - uiExtKeyNDivide, -}; - -struct uiAreaKeyEvent { - char Key; - uiExtKey ExtKey; - uiModifiers Modifier; - - uiModifiers Modifiers; - - // additional things - int Scancode; // bit0-7: scancode, bit8: ext flag - - int Up; - int Repeat; -}; - -typedef struct uiFontButton uiFontButton; -#define uiFontButton(this) ((uiFontButton *) (this)) -// TODO document this returns a new font -_UI_EXTERN uiDrawTextFont *uiFontButtonFont(uiFontButton *b); -// TOOD SetFont, mechanics -_UI_EXTERN void uiFontButtonOnChanged(uiFontButton *b, void (*f)(uiFontButton *, void *), void *data); -_UI_EXTERN uiFontButton *uiNewFontButton(void); - -typedef struct uiColorButton uiColorButton; -#define uiColorButton(this) ((uiColorButton *) (this)) -_UI_EXTERN void uiColorButtonColor(uiColorButton *b, double *r, double *g, double *bl, double *a); -_UI_EXTERN void uiColorButtonSetColor(uiColorButton *b, double r, double g, double bl, double a); -_UI_EXTERN void uiColorButtonOnChanged(uiColorButton *b, void (*f)(uiColorButton *, void *), void *data); -_UI_EXTERN uiColorButton *uiNewColorButton(void); - -typedef struct uiForm uiForm; -#define uiForm(this) ((uiForm *) (this)) -_UI_EXTERN void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy); -_UI_EXTERN void uiFormDelete(uiForm *f, int index); -_UI_EXTERN int uiFormPadded(uiForm *f); -_UI_EXTERN void uiFormSetPadded(uiForm *f, int padded); -_UI_EXTERN uiForm *uiNewForm(void); - -_UI_ENUM(uiAlign) { - uiAlignFill, - uiAlignStart, - uiAlignCenter, - uiAlignEnd, -}; - -_UI_ENUM(uiAt) { - uiAtLeading, - uiAtTop, - uiAtTrailing, - uiAtBottom, -}; - -typedef struct uiGrid uiGrid; -#define uiGrid(this) ((uiGrid *) (this)) -_UI_EXTERN void uiGridAppend(uiGrid *g, uiControl *c, int left, int top, int xspan, int yspan, int hexpand, uiAlign halign, int vexpand, uiAlign valign); -_UI_EXTERN void uiGridInsertAt(uiGrid *g, uiControl *c, uiControl *existing, uiAt at, int xspan, int yspan, int hexpand, uiAlign halign, int vexpand, uiAlign valign); -_UI_EXTERN int uiGridPadded(uiGrid *g); -_UI_EXTERN void uiGridSetPadded(uiGrid *g, int padded); -_UI_EXTERN uiGrid *uiNewGrid(void); - - -// misc. - -_UI_EXTERN char* uiKeyName(int scancode); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/libui_sdl/libui/ui_darwin.h b/src/libui_sdl/libui/ui_darwin.h deleted file mode 100644 index c9c6ad5..0000000 --- a/src/libui_sdl/libui/ui_darwin.h +++ /dev/null @@ -1,224 +0,0 @@ -// 7 april 2015 - -/* -This file assumes that you have imported and "ui.h" beforehand. It provides API-specific functions for interfacing with foreign controls on Mac OS X. -*/ - -#ifndef __LIBUI_UI_DARWIN_H__ -#define __LIBUI_UI_DARWIN_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct uiDarwinControl uiDarwinControl; -struct uiDarwinControl { - uiControl c; - uiControl *parent; - BOOL enabled; - BOOL visible; - void (*SyncEnableState)(uiDarwinControl *, int); - void (*SetSuperview)(uiDarwinControl *, NSView *); - BOOL (*HugsTrailingEdge)(uiDarwinControl *); - BOOL (*HugsBottom)(uiDarwinControl *); - void (*ChildEdgeHuggingChanged)(uiDarwinControl *); - NSLayoutPriority (*HuggingPriority)(uiDarwinControl *, NSLayoutConstraintOrientation); - void (*SetHuggingPriority)(uiDarwinControl *, NSLayoutPriority, NSLayoutConstraintOrientation); - void (*ChildVisibilityChanged)(uiDarwinControl *); -}; -#define uiDarwinControl(this) ((uiDarwinControl *) (this)) -// TODO document -_UI_EXTERN void uiDarwinControlSyncEnableState(uiDarwinControl *, int); -_UI_EXTERN void uiDarwinControlSetSuperview(uiDarwinControl *, NSView *); -_UI_EXTERN BOOL uiDarwinControlHugsTrailingEdge(uiDarwinControl *); -_UI_EXTERN BOOL uiDarwinControlHugsBottom(uiDarwinControl *); -_UI_EXTERN void uiDarwinControlChildEdgeHuggingChanged(uiDarwinControl *); -_UI_EXTERN NSLayoutPriority uiDarwinControlHuggingPriority(uiDarwinControl *, NSLayoutConstraintOrientation); -_UI_EXTERN void uiDarwinControlSetHuggingPriority(uiDarwinControl *, NSLayoutPriority, NSLayoutConstraintOrientation); -_UI_EXTERN void uiDarwinControlChildVisibilityChanged(uiDarwinControl *); - -#define uiDarwinControlDefaultDestroy(type, handlefield) \ - static void type ## Destroy(uiControl *c) \ - { \ - [type(c)->handlefield release]; \ - uiFreeControl(c); \ - } -#define uiDarwinControlDefaultHandle(type, handlefield) \ - static uintptr_t type ## Handle(uiControl *c) \ - { \ - return (uintptr_t) (type(c)->handlefield); \ - } -#define uiDarwinControlDefaultParent(type, handlefield) \ - static uiControl *type ## Parent(uiControl *c) \ - { \ - return uiDarwinControl(c)->parent; \ - } -#define uiDarwinControlDefaultSetParent(type, handlefield) \ - static void type ## SetParent(uiControl *c, uiControl *parent) \ - { \ - uiControlVerifySetParent(c, parent); \ - uiDarwinControl(c)->parent = parent; \ - } -#define uiDarwinControlDefaultToplevel(type, handlefield) \ - static int type ## Toplevel(uiControl *c) \ - { \ - return 0; \ - } -#define uiDarwinControlDefaultVisible(type, handlefield) \ - static int type ## Visible(uiControl *c) \ - { \ - return uiDarwinControl(c)->visible; \ - } -#define uiDarwinControlDefaultShow(type, handlefield) \ - static void type ## Show(uiControl *c) \ - { \ - uiDarwinControl(c)->visible = YES; \ - [type(c)->handlefield setHidden:NO]; \ - uiDarwinNotifyVisibilityChanged(uiDarwinControl(c)); \ - } -#define uiDarwinControlDefaultHide(type, handlefield) \ - static void type ## Hide(uiControl *c) \ - { \ - uiDarwinControl(c)->visible = NO; \ - [type(c)->handlefield setHidden:YES]; \ - uiDarwinNotifyVisibilityChanged(uiDarwinControl(c)); \ - } -#define uiDarwinControlDefaultEnabled(type, handlefield) \ - static int type ## Enabled(uiControl *c) \ - { \ - return uiDarwinControl(c)->enabled; \ - } -#define uiDarwinControlDefaultEnable(type, handlefield) \ - static void type ## Enable(uiControl *c) \ - { \ - uiDarwinControl(c)->enabled = YES; \ - uiDarwinControlSyncEnableState(uiDarwinControl(c), uiControlEnabledToUser(c)); \ - } -#define uiDarwinControlDefaultDisable(type, handlefield) \ - static void type ## Disable(uiControl *c) \ - { \ - uiDarwinControl(c)->enabled = NO; \ - uiDarwinControlSyncEnableState(uiDarwinControl(c), uiControlEnabledToUser(c)); \ - } -#define uiDarwinControlDefaultSyncEnableState(type, handlefield) \ - static void type ## SyncEnableState(uiDarwinControl *c, int enabled) \ - { \ - if (uiDarwinShouldStopSyncEnableState(c, enabled)) \ - return; \ - if ([type(c)->handlefield respondsToSelector:@selector(setEnabled:)]) \ - [((id) (type(c)->handlefield)) setEnabled:enabled]; /* id cast to make compiler happy; thanks mikeash in irc.freenode.net/#macdev */ \ - } -#define uiDarwinControlDefaultSetSuperview(type, handlefield) \ - static void type ## SetSuperview(uiDarwinControl *c, NSView *superview) \ - { \ - [type(c)->handlefield setTranslatesAutoresizingMaskIntoConstraints:NO]; \ - if (superview == nil) \ - [type(c)->handlefield removeFromSuperview]; \ - else \ - [superview addSubview:type(c)->handlefield]; \ - } -#define uiDarwinControlDefaultHugsTrailingEdge(type, handlefield) \ - static BOOL type ## HugsTrailingEdge(uiDarwinControl *c) \ - { \ - return YES; /* always hug by default */ \ - } -#define uiDarwinControlDefaultHugsBottom(type, handlefield) \ - static BOOL type ## HugsBottom(uiDarwinControl *c) \ - { \ - return YES; /* always hug by default */ \ - } -#define uiDarwinControlDefaultChildEdgeHuggingChanged(type, handlefield) \ - static void type ## ChildEdgeHuggingChanged(uiDarwinControl *c) \ - { \ - /* do nothing */ \ - } -#define uiDarwinControlDefaultHuggingPriority(type, handlefield) \ - static NSLayoutPriority type ## HuggingPriority(uiDarwinControl *c, NSLayoutConstraintOrientation orientation) \ - { \ - return [type(c)->handlefield contentHuggingPriorityForOrientation:orientation]; \ - } -#define uiDarwinControlDefaultSetHuggingPriority(type, handlefield) \ - static void type ## SetHuggingPriority(uiDarwinControl *c, NSLayoutPriority priority, NSLayoutConstraintOrientation orientation) \ - { \ - [type(c)->handlefield setContentHuggingPriority:priority forOrientation:orientation]; \ - } -#define uiDarwinControlDefaultChildVisibilityChanged(type, handlefield) \ - static void type ## ChildVisibilityChanged(uiDarwinControl *c) \ - { \ - /* do nothing */ \ - } - -#define uiDarwinControlAllDefaultsExceptDestroy(type, handlefield) \ - uiDarwinControlDefaultHandle(type, handlefield) \ - uiDarwinControlDefaultParent(type, handlefield) \ - uiDarwinControlDefaultSetParent(type, handlefield) \ - uiDarwinControlDefaultToplevel(type, handlefield) \ - uiDarwinControlDefaultVisible(type, handlefield) \ - uiDarwinControlDefaultShow(type, handlefield) \ - uiDarwinControlDefaultHide(type, handlefield) \ - uiDarwinControlDefaultEnabled(type, handlefield) \ - uiDarwinControlDefaultEnable(type, handlefield) \ - uiDarwinControlDefaultDisable(type, handlefield) \ - uiDarwinControlDefaultSyncEnableState(type, handlefield) \ - uiDarwinControlDefaultSetSuperview(type, handlefield) \ - uiDarwinControlDefaultHugsTrailingEdge(type, handlefield) \ - uiDarwinControlDefaultHugsBottom(type, handlefield) \ - uiDarwinControlDefaultChildEdgeHuggingChanged(type, handlefield) \ - uiDarwinControlDefaultHuggingPriority(type, handlefield) \ - uiDarwinControlDefaultSetHuggingPriority(type, handlefield) \ - uiDarwinControlDefaultChildVisibilityChanged(type, handlefield) - -#define uiDarwinControlAllDefaults(type, handlefield) \ - uiDarwinControlDefaultDestroy(type, handlefield) \ - uiDarwinControlAllDefaultsExceptDestroy(type, handlefield) - -// TODO document -#define uiDarwinNewControl(type, var) \ - var = type(uiDarwinAllocControl(sizeof (type), type ## Signature, #type)); \ - uiControl(var)->Destroy = type ## Destroy; \ - uiControl(var)->Handle = type ## Handle; \ - uiControl(var)->Parent = type ## Parent; \ - uiControl(var)->SetParent = type ## SetParent; \ - uiControl(var)->Toplevel = type ## Toplevel; \ - uiControl(var)->Visible = type ## Visible; \ - uiControl(var)->Show = type ## Show; \ - uiControl(var)->Hide = type ## Hide; \ - uiControl(var)->Enabled = type ## Enabled; \ - uiControl(var)->Enable = type ## Enable; \ - uiControl(var)->Disable = type ## Disable; \ - uiDarwinControl(var)->SyncEnableState = type ## SyncEnableState; \ - uiDarwinControl(var)->SetSuperview = type ## SetSuperview; \ - uiDarwinControl(var)->HugsTrailingEdge = type ## HugsTrailingEdge; \ - uiDarwinControl(var)->HugsBottom = type ## HugsBottom; \ - uiDarwinControl(var)->ChildEdgeHuggingChanged = type ## ChildEdgeHuggingChanged; \ - uiDarwinControl(var)->HuggingPriority = type ## HuggingPriority; \ - uiDarwinControl(var)->SetHuggingPriority = type ## SetHuggingPriority; \ - uiDarwinControl(var)->ChildVisibilityChanged = type ## ChildVisibilityChanged; \ - uiDarwinControl(var)->visible = YES; \ - uiDarwinControl(var)->enabled = YES; -// TODO document -_UI_EXTERN uiDarwinControl *uiDarwinAllocControl(size_t n, uint32_t typesig, const char *typenamestr); - -// Use this function as a shorthand for setting control fonts. -_UI_EXTERN void uiDarwinSetControlFont(NSControl *c, NSControlSize size); - -// You can use this function from within your control implementations to return text strings that can be freed with uiFreeText(). -_UI_EXTERN char *uiDarwinNSStringToText(NSString *); - -// TODO document -_UI_EXTERN BOOL uiDarwinShouldStopSyncEnableState(uiDarwinControl *, BOOL); - -// TODO document -_UI_EXTERN void uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl *); -_UI_EXTERN void uiDarwinNotifyVisibilityChanged(uiDarwinControl *c); - -// TODO document -// TODO document that values should not be cached -_UI_EXTERN CGFloat uiDarwinMarginAmount(void *reserved); -_UI_EXTERN CGFloat uiDarwinPaddingAmount(void *reserved); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/libui_sdl/libui/ui_unix.h b/src/libui_sdl/libui/ui_unix.h deleted file mode 100644 index fac44bc..0000000 --- a/src/libui_sdl/libui/ui_unix.h +++ /dev/null @@ -1,154 +0,0 @@ -// 7 april 2015 - -/* -This file assumes that you have included and "ui.h" beforehand. It provides API-specific functions for interfacing with foreign controls on Unix systems that use GTK+ to provide their UI (currently all except Mac OS X). -*/ - -#ifndef __LIBUI_UI_UNIX_H__ -#define __LIBUI_UI_UNIX_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct uiUnixControl uiUnixControl; -struct uiUnixControl { - uiControl c; - uiControl *parent; - gboolean addedBefore; - void (*SetContainer)(uiUnixControl *, GtkContainer *, gboolean); -}; -#define uiUnixControl(this) ((uiUnixControl *) (this)) -// TODO document -_UI_EXTERN void uiUnixControlSetContainer(uiUnixControl *, GtkContainer *, gboolean); - -#define uiUnixControlDefaultDestroy(type) \ - static void type ## Destroy(uiControl *c) \ - { \ - /* TODO is this safe on floating refs? */ \ - g_object_unref(type(c)->widget); \ - uiFreeControl(c); \ - } -#define uiUnixControlDefaultHandle(type) \ - static uintptr_t type ## Handle(uiControl *c) \ - { \ - return (uintptr_t) (type(c)->widget); \ - } -#define uiUnixControlDefaultParent(type) \ - static uiControl *type ## Parent(uiControl *c) \ - { \ - return uiUnixControl(c)->parent; \ - } -#define uiUnixControlDefaultSetParent(type) \ - static void type ## SetParent(uiControl *c, uiControl *parent) \ - { \ - uiControlVerifySetParent(c, parent); \ - uiUnixControl(c)->parent = parent; \ - } -#define uiUnixControlDefaultToplevel(type) \ - static int type ## Toplevel(uiControl *c) \ - { \ - return 0; \ - } -#define uiUnixControlDefaultVisible(type) \ - static int type ## Visible(uiControl *c) \ - { \ - return gtk_widget_get_visible(type(c)->widget); \ - } -#define uiUnixControlDefaultShow(type) \ - static void type ## Show(uiControl *c) \ - { \ - gtk_widget_show(type(c)->widget); \ - } -#define uiUnixControlDefaultHide(type) \ - static void type ## Hide(uiControl *c) \ - { \ - gtk_widget_hide(type(c)->widget); \ - } -#define uiUnixControlDefaultEnabled(type) \ - static int type ## Enabled(uiControl *c) \ - { \ - return gtk_widget_get_sensitive(type(c)->widget); \ - } -#define uiUnixControlDefaultEnable(type) \ - static void type ## Enable(uiControl *c) \ - { \ - gtk_widget_set_sensitive(type(c)->widget, TRUE); \ - } -#define uiUnixControlDefaultDisable(type) \ - static void type ## Disable(uiControl *c) \ - { \ - gtk_widget_set_sensitive(type(c)->widget, FALSE); \ - } -#define uiUnixControlDefaultSetFocus(type) \ - static void type ## SetFocus(uiControl *c) \ - { \ - gtk_widget_grab_focus(type(c)->widget); \ - } -#define uiUnixControlDefaultSetMinSize(type) \ - static void type ## SetMinSize(uiControl *c, int w, int h) \ - { \ - gtk_widget_set_size_request(type(c)->widget, w, h); \ - } -// TODO this whole addedBefore stuff is a MASSIVE HACK. -#define uiUnixControlDefaultSetContainer(type) \ - static void type ## SetContainer(uiUnixControl *c, GtkContainer *container, gboolean remove) \ - { \ - if (!uiUnixControl(c)->addedBefore) { \ - g_object_ref_sink(type(c)->widget); /* our own reference, which we release in Destroy() */ \ - gtk_widget_show(type(c)->widget); \ - uiUnixControl(c)->addedBefore = TRUE; \ - } \ - if (remove) \ - gtk_container_remove(container, type(c)->widget); \ - else \ - gtk_container_add(container, type(c)->widget); \ - } - -#define uiUnixControlAllDefaultsExceptDestroy(type) \ - uiUnixControlDefaultHandle(type) \ - uiUnixControlDefaultParent(type) \ - uiUnixControlDefaultSetParent(type) \ - uiUnixControlDefaultToplevel(type) \ - uiUnixControlDefaultVisible(type) \ - uiUnixControlDefaultShow(type) \ - uiUnixControlDefaultHide(type) \ - uiUnixControlDefaultEnabled(type) \ - uiUnixControlDefaultEnable(type) \ - uiUnixControlDefaultDisable(type) \ - uiUnixControlDefaultSetFocus(type) \ - uiUnixControlDefaultSetMinSize(type) \ - uiUnixControlDefaultSetContainer(type) - -#define uiUnixControlAllDefaults(type) \ - uiUnixControlDefaultDestroy(type) \ - uiUnixControlAllDefaultsExceptDestroy(type) - -// TODO document -#define uiUnixNewControl(type, var) \ - var = type(uiUnixAllocControl(sizeof (type), type ## Signature, #type)); \ - uiControl(var)->Destroy = type ## Destroy; \ - uiControl(var)->Handle = type ## Handle; \ - uiControl(var)->Parent = type ## Parent; \ - uiControl(var)->SetParent = type ## SetParent; \ - uiControl(var)->Toplevel = type ## Toplevel; \ - uiControl(var)->Visible = type ## Visible; \ - uiControl(var)->Show = type ## Show; \ - uiControl(var)->Hide = type ## Hide; \ - uiControl(var)->Enabled = type ## Enabled; \ - uiControl(var)->Enable = type ## Enable; \ - uiControl(var)->Disable = type ## Disable; \ - uiControl(var)->SetFocus = type ## SetFocus; \ - uiControl(var)->SetMinSize = type ## SetMinSize; \ - uiUnixControl(var)->SetContainer = type ## SetContainer; -// TODO document -_UI_EXTERN uiUnixControl *uiUnixAllocControl(size_t n, uint32_t typesig, const char *typenamestr); - -// uiUnixStrdupText() takes the given string and produces a copy of it suitable for being freed by uiFreeText(). -_UI_EXTERN char *uiUnixStrdupText(const char *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/libui_sdl/libui/ui_windows.h b/src/libui_sdl/libui/ui_windows.h deleted file mode 100644 index 85c3137..0000000 --- a/src/libui_sdl/libui/ui_windows.h +++ /dev/null @@ -1,280 +0,0 @@ -// 21 april 2016 - -/* -This file assumes that you have included and "ui.h" beforehand. It provides API-specific functions for interfacing with foreign controls in Windows. -*/ - -#ifndef __LIBUI_UI_WINDOWS_H__ -#define __LIBUI_UI_WINDOWS_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct uiWindowsSizing uiWindowsSizing; - -typedef struct uiWindowsControl uiWindowsControl; -struct uiWindowsControl { - uiControl c; - uiControl *parent; - // TODO this should be int on both os x and windows - BOOL enabled; - BOOL visible; - void (*SyncEnableState)(uiWindowsControl *, int); - void (*SetParentHWND)(uiWindowsControl *, HWND); - void (*MinimumSize)(uiWindowsControl *, int *, int *); - void (*MinimumSizeChanged)(uiWindowsControl *); - void (*LayoutRect)(uiWindowsControl *c, RECT *r); - void (*AssignControlIDZOrder)(uiWindowsControl *, LONG_PTR *, HWND *); - void (*ChildVisibilityChanged)(uiWindowsControl *); -}; -#define uiWindowsControl(this) ((uiWindowsControl *) (this)) -// TODO document -_UI_EXTERN void uiWindowsControlSyncEnableState(uiWindowsControl *, int); -_UI_EXTERN void uiWindowsControlSetParentHWND(uiWindowsControl *, HWND); -_UI_EXTERN void uiWindowsControlMinimumSize(uiWindowsControl *, int *, int *); -_UI_EXTERN void uiWindowsControlMinimumSizeChanged(uiWindowsControl *); -_UI_EXTERN void uiWindowsControlLayoutRect(uiWindowsControl *, RECT *); -_UI_EXTERN void uiWindowsControlAssignControlIDZOrder(uiWindowsControl *, LONG_PTR *, HWND *); -_UI_EXTERN void uiWindowsControlChildVisibilityChanged(uiWindowsControl *); - -// TODO document -#define uiWindowsControlDefaultDestroy(type) \ - static void type ## Destroy(uiControl *c) \ - { \ - uiWindowsEnsureDestroyWindow(type(c)->hwnd); \ - uiFreeControl(c); \ - } -#define uiWindowsControlDefaultHandle(type) \ - static uintptr_t type ## Handle(uiControl *c) \ - { \ - return (uintptr_t) (type(c)->hwnd); \ - } -#define uiWindowsControlDefaultParent(type) \ - static uiControl *type ## Parent(uiControl *c) \ - { \ - return uiWindowsControl(c)->parent; \ - } -#define uiWindowsControlDefaultSetParent(type) \ - static void type ## SetParent(uiControl *c, uiControl *parent) \ - { \ - uiControlVerifySetParent(c, parent); \ - uiWindowsControl(c)->parent = parent; \ - } -#define uiWindowsControlDefaultToplevel(type) \ - static int type ## Toplevel(uiControl *c) \ - { \ - return 0; \ - } -#define uiWindowsControlDefaultVisible(type) \ - static int type ## Visible(uiControl *c) \ - { \ - return uiWindowsControl(c)->visible; \ - } -#define uiWindowsControlDefaultShow(type) \ - static void type ## Show(uiControl *c) \ - { \ - uiWindowsControl(c)->visible = 1; \ - ShowWindow(type(c)->hwnd, SW_SHOW); \ - uiWindowsControlNotifyVisibilityChanged(uiWindowsControl(c)); \ - } -#define uiWindowsControlDefaultHide(type) \ - static void type ## Hide(uiControl *c) \ - { \ - uiWindowsControl(c)->visible = 0; \ - ShowWindow(type(c)->hwnd, SW_HIDE); \ - uiWindowsControlNotifyVisibilityChanged(uiWindowsControl(c)); \ - } -#define uiWindowsControlDefaultEnabled(type) \ - static int type ## Enabled(uiControl *c) \ - { \ - return uiWindowsControl(c)->enabled; \ - } -#define uiWindowsControlDefaultEnable(type) \ - static void type ## Enable(uiControl *c) \ - { \ - uiWindowsControl(c)->enabled = 1; \ - uiWindowsControlSyncEnableState(uiWindowsControl(c), uiControlEnabledToUser(c)); \ - } -#define uiWindowsControlDefaultDisable(type) \ - static void type ## Disable(uiControl *c) \ - { \ - uiWindowsControl(c)->enabled = 0; \ - uiWindowsControlSyncEnableState(uiWindowsControl(c), uiControlEnabledToUser(c)); \ - } -#define uiWindowsControlDefaultSetFocus(type) \ - static void type ## SetFocus(uiControl *c) \ - { \ - SetFocus(type(c)->hwnd); \ - } -#define uiWindowsControlDefaultSetMinSize(type) \ - static void type ## SetMinSize(uiControl *c, int w, int h) \ - { \ - } -#define uiWindowsControlDefaultSyncEnableState(type) \ - static void type ## SyncEnableState(uiWindowsControl *c, int enabled) \ - { \ - if (uiWindowsShouldStopSyncEnableState(c, enabled)) \ - return; \ - EnableWindow(type(c)->hwnd, enabled); \ - } -#define uiWindowsControlDefaultSetParentHWND(type) \ - static void type ## SetParentHWND(uiWindowsControl *c, HWND parent) \ - { \ - uiWindowsEnsureSetParentHWND(type(c)->hwnd, parent); \ - } -// note that there is no uiWindowsControlDefaultMinimumSize(); you MUST define this yourself! -#define uiWindowsControlDefaultMinimumSizeChanged(type) \ - static void type ## MinimumSizeChanged(uiWindowsControl *c) \ - { \ - if (uiWindowsControlTooSmall(c)) { \ - uiWindowsControlContinueMinimumSizeChanged(c); \ - return; \ - } \ - /* otherwise do nothing; we have no children */ \ - } -#define uiWindowsControlDefaultLayoutRect(type) \ - static void type ## LayoutRect(uiWindowsControl *c, RECT *r) \ - { \ - /* use the window rect as we include the non-client area in the sizes */ \ - uiWindowsEnsureGetWindowRect(type(c)->hwnd, r); \ - } -#define uiWindowsControlDefaultAssignControlIDZOrder(type) \ - static void type ## AssignControlIDZOrder(uiWindowsControl *c, LONG_PTR *controlID, HWND *insertAfter) \ - { \ - uiWindowsEnsureAssignControlIDZOrder(type(c)->hwnd, controlID, insertAfter); \ - } -#define uiWindowsControlDefaultChildVisibilityChanged(type) \ - static void type ## ChildVisibilityChanged(uiWindowsControl *c) \ - { \ - /* do nothing */ \ - } - -#define uiWindowsControlAllDefaultsExceptDestroy(type) \ - uiWindowsControlDefaultHandle(type) \ - uiWindowsControlDefaultParent(type) \ - uiWindowsControlDefaultSetParent(type) \ - uiWindowsControlDefaultToplevel(type) \ - uiWindowsControlDefaultVisible(type) \ - uiWindowsControlDefaultShow(type) \ - uiWindowsControlDefaultHide(type) \ - uiWindowsControlDefaultEnabled(type) \ - uiWindowsControlDefaultEnable(type) \ - uiWindowsControlDefaultDisable(type) \ - uiWindowsControlDefaultSetFocus(type) \ - uiWindowsControlDefaultSetMinSize(type) \ - uiWindowsControlDefaultSyncEnableState(type) \ - uiWindowsControlDefaultSetParentHWND(type) \ - uiWindowsControlDefaultMinimumSizeChanged(type) \ - uiWindowsControlDefaultLayoutRect(type) \ - uiWindowsControlDefaultAssignControlIDZOrder(type) \ - uiWindowsControlDefaultChildVisibilityChanged(type) - -#define uiWindowsControlAllDefaults(type) \ - uiWindowsControlDefaultDestroy(type) \ - uiWindowsControlAllDefaultsExceptDestroy(type) - -// TODO document -#define uiWindowsNewControl(type, var) \ - var = type(uiWindowsAllocControl(sizeof (type), type ## Signature, #type)); \ - uiControl(var)->Destroy = type ## Destroy; \ - uiControl(var)->Handle = type ## Handle; \ - uiControl(var)->Parent = type ## Parent; \ - uiControl(var)->SetParent = type ## SetParent; \ - uiControl(var)->Toplevel = type ## Toplevel; \ - uiControl(var)->Visible = type ## Visible; \ - uiControl(var)->Show = type ## Show; \ - uiControl(var)->Hide = type ## Hide; \ - uiControl(var)->Enabled = type ## Enabled; \ - uiControl(var)->Enable = type ## Enable; \ - uiControl(var)->Disable = type ## Disable; \ - uiControl(var)->SetFocus = type ## SetFocus; \ - uiControl(var)->SetMinSize = type ## SetMinSize; \ - uiWindowsControl(var)->SyncEnableState = type ## SyncEnableState; \ - uiWindowsControl(var)->SetParentHWND = type ## SetParentHWND; \ - uiWindowsControl(var)->MinimumSize = type ## MinimumSize; \ - uiWindowsControl(var)->MinimumSizeChanged = type ## MinimumSizeChanged; \ - uiWindowsControl(var)->LayoutRect = type ## LayoutRect; \ - uiWindowsControl(var)->AssignControlIDZOrder = type ## AssignControlIDZOrder; \ - uiWindowsControl(var)->ChildVisibilityChanged = type ## ChildVisibilityChanged; \ - uiWindowsControl(var)->visible = 1; \ - uiWindowsControl(var)->enabled = 1; -// TODO document -_UI_EXTERN uiWindowsControl *uiWindowsAllocControl(size_t n, uint32_t typesig, const char *typenamestr); - -// TODO document -_UI_EXTERN HWND uiWindowsEnsureCreateControlHWND(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, HINSTANCE hInstance, LPVOID lpParam, BOOL useStandardControlFont); - -// TODO document -_UI_EXTERN void uiWindowsEnsureDestroyWindow(HWND hwnd); - -// TODO document -// TODO document that this should only be used in SetParentHWND() implementations -_UI_EXTERN void uiWindowsEnsureSetParentHWND(HWND hwnd, HWND parent); - -// TODO document -_UI_EXTERN void uiWindowsEnsureAssignControlIDZOrder(HWND hwnd, LONG_PTR *controlID, HWND *insertAfter); - -// TODO document -_UI_EXTERN void uiWindowsEnsureGetClientRect(HWND hwnd, RECT *r); -_UI_EXTERN void uiWindowsEnsureGetWindowRect(HWND hwnd, RECT *r); - -// TODO document -_UI_EXTERN char *uiWindowsWindowText(HWND hwnd); -_UI_EXTERN void uiWindowsSetWindowText(HWND hwnd, const char *text); - -// TODO document -_UI_EXTERN int uiWindowsWindowTextWidth(HWND hwnd); - -// TODO document -// TODO point out this should only be used in a resize cycle -_UI_EXTERN void uiWindowsEnsureMoveWindowDuringResize(HWND hwnd, int x, int y, int width, int height); - -// TODO document -_UI_EXTERN void uiWindowsRegisterWM_COMMANDHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *), uiControl *c); -_UI_EXTERN void uiWindowsUnregisterWM_COMMANDHandler(HWND hwnd); - -// TODO document -_UI_EXTERN void uiWindowsRegisterWM_NOTIFYHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, NMHDR *, LRESULT *), uiControl *c); -_UI_EXTERN void uiWindowsUnregisterWM_NOTIFYHandler(HWND hwnd); - -// TODO document -_UI_EXTERN void uiWindowsRegisterWM_HSCROLLHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *), uiControl *c); -_UI_EXTERN void uiWindowsUnregisterWM_HSCROLLHandler(HWND hwnd); - -// TODO document -_UI_EXTERN void uiWindowsRegisterReceiveWM_WININICHANGE(HWND hwnd); -_UI_EXTERN void uiWindowsUnregisterReceiveWM_WININICHANGE(HWND hwnd); - -// TODO document -typedef struct uiWindowsSizing uiWindowsSizing; -struct uiWindowsSizing { - int BaseX; - int BaseY; - LONG InternalLeading; -}; -_UI_EXTERN void uiWindowsGetSizing(HWND hwnd, uiWindowsSizing *sizing); -_UI_EXTERN void uiWindowsSizingDlgUnitsToPixels(uiWindowsSizing *sizing, int *x, int *y); -_UI_EXTERN void uiWindowsSizingStandardPadding(uiWindowsSizing *sizing, int *x, int *y); - -// TODO document -_UI_EXTERN HWND uiWindowsMakeContainer(uiWindowsControl *c, void (*onResize)(uiWindowsControl *)); - -// TODO document -_UI_EXTERN BOOL uiWindowsControlTooSmall(uiWindowsControl *c); -_UI_EXTERN void uiWindowsControlContinueMinimumSizeChanged(uiWindowsControl *c); - -// TODO document -_UI_EXTERN void uiWindowsControlAssignSoleControlIDZOrder(uiWindowsControl *); - -// TODO document -_UI_EXTERN BOOL uiWindowsShouldStopSyncEnableState(uiWindowsControl *c, int enabled); - -// TODO document -_UI_EXTERN void uiWindowsControlNotifyVisibilityChanged(uiWindowsControl *c); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/libui_sdl/libui/unix/CMakeLists.txt b/src/libui_sdl/libui/unix/CMakeLists.txt deleted file mode 100644 index c69081e..0000000 --- a/src/libui_sdl/libui/unix/CMakeLists.txt +++ /dev/null @@ -1,87 +0,0 @@ -# 3 june 2016 - -find_package(PkgConfig REQUIRED) -pkg_check_modules(GTK REQUIRED gtk+-3.0) - -list(APPEND _LIBUI_SOURCES - unix/alloc.c - unix/area.c - unix/box.c - unix/button.c - unix/cellrendererbutton.c - unix/checkbox.c - unix/child.c - unix/colorbutton.c - unix/combobox.c - unix/control.c - unix/datetimepicker.c - unix/debug.c - unix/draw.c - unix/drawmatrix.c - unix/drawpath.c - unix/drawtext.c - unix/editablecombo.c - unix/entry.c - unix/fontbutton.c - unix/form.c - unix/future.c - unix/graphemes.c - unix/grid.c - unix/group.c - unix/image.c - unix/label.c - unix/main.c - unix/menu.c - unix/multilineentry.c - unix/progressbar.c - unix/radiobuttons.c - unix/separator.c - unix/slider.c - unix/spinbox.c - unix/stddialogs.c - unix/tab.c - unix/text.c - unix/util.c - unix/window.c - unix/gl.c -) -set(_LIBUI_SOURCES ${_LIBUI_SOURCES} PARENT_SCOPE) - -list(APPEND _LIBUI_INCLUDEDIRS - unix -) -set(_LIBUI_INCLUDEDIRS _LIBUI_INCLUDEDIRS PARENT_SCOPE) - -set(_LIBUINAME libui PARENT_SCOPE) -if(NOT BUILD_SHARED_LIBS) - set(_LIBUINAME libui-temporary PARENT_SCOPE) -endif() -macro(_handle_static) - set_target_properties(${_LIBUINAME} PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}") - set(_aname $) - set(_oname libui-combined.o) - add_custom_command( - OUTPUT ${_oname} - DEPENDS ${_LIBUINAME} - COMMAND - ld -r --whole-archive ${_aname} -o ${_oname} - COMMAND - objcopy --localize-hidden ${_oname} - COMMENT "Removing hidden symbols") - add_library(libui STATIC ${_oname}) - # otherwise cmake won't know which linker to use - set_target_properties(libui PROPERTIES - LINKER_LANGUAGE C) - set(_aname) - set(_oname) -endmacro() - -# TODO the other variables don't work? -set(_LIBUI_CFLAGS - ${GTK_CFLAGS} -PARENT_SCOPE) - -set(_LIBUI_LIBS - ${GTK_LDFLAGS} m ${CMAKE_DL_LIBS} -PARENT_SCOPE) diff --git a/src/libui_sdl/libui/unix/alloc.c b/src/libui_sdl/libui/unix/alloc.c deleted file mode 100644 index 2561efa..0000000 --- a/src/libui_sdl/libui/unix/alloc.c +++ /dev/null @@ -1,84 +0,0 @@ -// 7 april 2015 -#include -#include "uipriv_unix.h" - -static GPtrArray *allocations; - -#define UINT8(p) ((uint8_t *) (p)) -#define PVOID(p) ((void *) (p)) -#define EXTRA (sizeof (size_t) + sizeof (const char **)) -#define DATA(p) PVOID(UINT8(p) + EXTRA) -#define BASE(p) PVOID(UINT8(p) - EXTRA) -#define SIZE(p) ((size_t *) (p)) -#define CCHAR(p) ((const char **) (p)) -#define TYPE(p) CCHAR(UINT8(p) + sizeof (size_t)) - -void initAlloc(void) -{ - allocations = g_ptr_array_new(); -} - -static void uninitComplain(gpointer ptr, gpointer data) -{ - char **str = (char **) data; - char *str2; - - if (*str == NULL) - *str = g_strdup_printf(""); - str2 = g_strdup_printf("%s%p %s\n", *str, ptr, *TYPE(ptr)); - g_free(*str); - *str = str2; -} - -void uninitAlloc(void) -{ - char *str = NULL; - - if (allocations->len == 0) { - g_ptr_array_free(allocations, TRUE); - return; - } - g_ptr_array_foreach(allocations, uninitComplain, &str); - userbug("Some data was leaked; either you left a uiControl lying around or there's a bug in libui itself. Leaked data:\n%s", str); - g_free(str); -} - -void *uiAlloc(size_t size, const char *type) -{ - void *out; - - out = g_malloc0(EXTRA + size); - *SIZE(out) = size; - *TYPE(out) = type; - g_ptr_array_add(allocations, out); - return DATA(out); -} - -void *uiRealloc(void *p, size_t new, const char *type) -{ - void *out; - size_t *s; - - if (p == NULL) - return uiAlloc(new, type); - p = BASE(p); - out = g_realloc(p, EXTRA + new); - s = SIZE(out); - if (new <= *s) - memset(((uint8_t *) DATA(out)) + *s, 0, new - *s); - *s = new; - if (g_ptr_array_remove(allocations, p) == FALSE) - implbug("%p not found in allocations array in uiRealloc()", p); - g_ptr_array_add(allocations, out); - return DATA(out); -} - -void uiFree(void *p) -{ - if (p == NULL) - implbug("attempt to uiFree(NULL)"); - p = BASE(p); - g_free(p); - if (g_ptr_array_remove(allocations, p) == FALSE) - implbug("%p not found in allocations array in uiFree()", p); -} diff --git a/src/libui_sdl/libui/unix/area.c b/src/libui_sdl/libui/unix/area.c deleted file mode 100644 index 5734b4b..0000000 --- a/src/libui_sdl/libui/unix/area.c +++ /dev/null @@ -1,853 +0,0 @@ -// 4 september 2015 -#include "uipriv_unix.h" - -extern GThread* gtkthread; - -// notes: -// - G_DECLARE_DERIVABLE/FINAL_INTERFACE() requires glib 2.44 and that's starting with debian stretch (testing) (GTK+ 3.18) and ubuntu 15.04 (GTK+ 3.14) - debian jessie has 2.42 (GTK+ 3.14) -#define areaWidgetType (areaWidget_get_type()) -#define areaWidget(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), areaWidgetType, areaWidget)) -#define isAreaWidget(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), areaWidgetType)) -#define areaWidgetClass(class) (G_TYPE_CHECK_CLASS_CAST((class), areaWidgetType, areaWidgetClass)) -#define isAreaWidgetClass(class) (G_TYPE_CHECK_CLASS_TYPE((class), areaWidget)) -#define getAreaWidgetClass(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), areaWidgetType, areaWidgetClass)) - -typedef struct areaWidget areaWidget; -typedef struct areaWidgetClass areaWidgetClass; - -struct areaWidget { - GtkDrawingArea parent_instance; - uiArea *a; - // construct-only parameters aare not set until after the init() function has returned - // we need this particular object available during init(), so put it here instead of in uiArea - // keep a pointer in uiArea for convenience, though - clickCounter cc; -}; - -struct areaWidgetClass { - GtkDrawingAreaClass parent_class; -}; - -typedef struct uiGLContext uiGLContext; - -struct uiArea { - uiUnixControl c; - GtkWidget *widget; // either swidget or areaWidget depending on whether it is scrolling - - GtkWidget *swidget; - GtkContainer *scontainer; - GtkScrolledWindow *sw; - - GtkWidget *areaWidget; - GtkDrawingArea *drawingArea; - areaWidget *area; - - gboolean opengl; - uiGLContext *glContext; - unsigned int* req_versions; - - int bgR, bgG, bgB; - - uiAreaHandler *ah; - - gboolean scrolling; - int scrollWidth; - int scrollHeight; - - // note that this is a pointer; see above - clickCounter *cc; - - // for user window drags - GdkEventButton *dragevent; -}; - -G_DEFINE_TYPE(areaWidget, areaWidget, GTK_TYPE_DRAWING_AREA) - -int boub(GtkWidget* w) { return isAreaWidget(w); } -void baba(GtkWidget* w) -{ - if (!isAreaWidget(w)) return; - - areaWidget *aw = areaWidget(w); - uiArea *a = aw->a; - if (!a->opengl) return; - - GdkGLContext* oldctx = gdk_gl_context_get_current(); - uiGLMakeContextCurrent(a->glContext); - glFinish(); - gdk_gl_context_make_current(oldctx); -} - -static void areaWidget_init(areaWidget *aw) -{ - // for events - gtk_widget_add_events(GTK_WIDGET(aw), - GDK_POINTER_MOTION_MASK | - GDK_BUTTON_MOTION_MASK | - GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | - GDK_KEY_PRESS_MASK | - GDK_KEY_RELEASE_MASK | - GDK_ENTER_NOTIFY_MASK | - GDK_LEAVE_NOTIFY_MASK); - - gtk_widget_set_can_focus(GTK_WIDGET(aw), TRUE); - - clickCounterReset(&(aw->cc)); -} - -static void areaWidget_dispose(GObject *obj) -{ - // remove any draw order that might still be pending - areaWidget *aw = areaWidget(obj); - while (g_idle_remove_by_data(aw->a)); - - G_OBJECT_CLASS(areaWidget_parent_class)->dispose(obj); -} - -static void areaWidget_finalize(GObject *obj) -{ - G_OBJECT_CLASS(areaWidget_parent_class)->finalize(obj); -} - -static void areaWidget_size_allocate(GtkWidget *w, GtkAllocation *allocation) -{ - areaWidget *aw = areaWidget(w); - uiArea *a = aw->a; - - // GtkDrawingArea has a size_allocate() implementation; we need to call it - // this will call gtk_widget_set_allocation() for us - GTK_WIDGET_CLASS(areaWidget_parent_class)->size_allocate(w, allocation); - - if (!a->scrolling) - // we must redraw everything on resize because Windows requires it - gtk_widget_queue_resize(w); - - a->ah->Resize(a->ah, a, allocation->width, allocation->height); -} - -static void loadAreaSize(uiArea *a, double *width, double *height) -{ - GtkAllocation allocation; - - *width = 0; - *height = 0; - // don't provide size information for scrolling areas - if (!a->scrolling) { - gtk_widget_get_allocation(a->areaWidget, &allocation); - // these are already in drawing space coordinates - // for drawing, the size of drawing space has the same value as the widget allocation - // thanks to tristan in irc.gimp.net/#gtk+ - *width = allocation.width; - *height = allocation.height; - } -} - -static gboolean areaWidget_draw(GtkWidget *w, cairo_t *cr) -{ - areaWidget *aw = areaWidget(w); - uiArea *a = aw->a; - uiAreaDrawParams dp; - double clipX0, clipY0, clipX1, clipY1; - - dp.Context = newContext(cr); - - loadAreaSize(a, &(dp.AreaWidth), &(dp.AreaHeight)); - - if (!a->opengl) - { - cairo_clip_extents(cr, &clipX0, &clipY0, &clipX1, &clipY1); - dp.ClipX = clipX0; - dp.ClipY = clipY0; - dp.ClipWidth = clipX1 - clipX0; - dp.ClipHeight = clipY1 - clipY0; - - if (a->bgR != -1) - { - cairo_set_source_rgb(cr, a->bgR/255.0, a->bgG/255.0, a->bgB/255.0); - cairo_paint(cr); - } - - // no need to save or restore the graphics state to reset transformations; GTK+ does that for us - (*(a->ah->Draw))(a->ah, a, &dp); - } - else - { - areaDrawGL(w, &dp, cr, a->glContext); - } - - freeContext(dp.Context); - return FALSE; -} - -// to do this properly for scrolling areas, we need to -// - return the same value for min and nat -// - call gtk_widget_queue_resize() when the size changes -// thanks to Company in irc.gimp.net/#gtk+ -static void areaWidget_get_preferred_height(GtkWidget *w, gint *min, gint *nat) -{ - areaWidget *aw = areaWidget(w); - uiArea *a = aw->a; - - // always chain up just in case - GTK_WIDGET_CLASS(areaWidget_parent_class)->get_preferred_height(w, min, nat); - if (a->scrolling) { - *min = a->scrollHeight; - *nat = a->scrollHeight; - } - - // TODO: min size -} - -static void areaWidget_get_preferred_width(GtkWidget *w, gint *min, gint *nat) -{ - areaWidget *aw = areaWidget(w); - uiArea *a = aw->a; - - // always chain up just in case - GTK_WIDGET_CLASS(areaWidget_parent_class)->get_preferred_width(w, min, nat); - if (a->scrolling) { - *min = a->scrollWidth; - *nat = a->scrollWidth; - } -} - -static guint translateModifiers(guint state, GdkWindow *window) -{ - GdkModifierType statetype; - - // GDK doesn't initialize the modifier flags fully; we have to explicitly tell it to (thanks to Daniel_S and daniels (two different people) in irc.gimp.net/#gtk+) - statetype = state; - gdk_keymap_add_virtual_modifiers( - gdk_keymap_get_for_display(gdk_window_get_display(window)), - &statetype); - return statetype; -} - -static uiModifiers toModifiers(guint state) -{ - uiModifiers m; - - m = 0; - if ((state & GDK_CONTROL_MASK) != 0) - m |= uiModifierCtrl; - if ((state & GDK_META_MASK) != 0) - m |= uiModifierAlt; - if ((state & GDK_MOD1_MASK) != 0) // GTK+ itself requires this to be Alt (just read through gtkaccelgroup.c) - m |= uiModifierAlt; - if ((state & GDK_SHIFT_MASK) != 0) - m |= uiModifierShift; - if ((state & GDK_SUPER_MASK) != 0) - m |= uiModifierSuper; - return m; -} - -// capture on drag is done automatically on GTK+ -static void finishMouseEvent(uiArea *a, uiAreaMouseEvent *me, guint mb, gdouble x, gdouble y, guint state, GdkWindow *window) -{ - // on GTK+, mouse buttons 4-7 are for scrolling; if we got here, that's a mistake - if (mb >= 4 && mb <= 7) - return; - // if the button ID >= 8, continue counting from 4, as in the MouseEvent spec - if (me->Down >= 8) - me->Down -= 4; - if (me->Up >= 8) - me->Up -= 4; - - state = translateModifiers(state, window); - me->Modifiers = toModifiers(state); - - // the mb != # checks exclude the Up/Down button from Held - me->Held1To64 = 0; - if (mb != 1 && (state & GDK_BUTTON1_MASK) != 0) - me->Held1To64 |= 1 << 0; - if (mb != 2 && (state & GDK_BUTTON2_MASK) != 0) - me->Held1To64 |= 1 << 1; - if (mb != 3 && (state & GDK_BUTTON3_MASK) != 0) - me->Held1To64 |= 1 << 2; - // don't check GDK_BUTTON4_MASK or GDK_BUTTON5_MASK because those are for the scrolling buttons mentioned above - // GDK expressly does not support any more buttons in the GdkModifierType; see https://git.gnome.org/browse/gtk+/tree/gdk/x11/gdkdevice-xi2.c#n763 (thanks mclasen in irc.gimp.net/#gtk+) - - // these are already in drawing space coordinates - // the size of drawing space has the same value as the widget allocation - // thanks to tristan in irc.gimp.net/#gtk+ - me->X = x; - me->Y = y; - - loadAreaSize(a, &(me->AreaWidth), &(me->AreaHeight)); - - (*(a->ah->MouseEvent))(a->ah, a, me); -} - -static gboolean areaWidget_button_press_event(GtkWidget *w, GdkEventButton *e) -{ - areaWidget *aw = areaWidget(w); - uiArea *a = aw->a; - gint maxTime, maxDistance; - GtkSettings *settings; - uiAreaMouseEvent me; - - // clicking doesn't automatically transfer keyboard focus; we must do so manually (thanks tristan in irc.gimp.net/#gtk+) - gtk_widget_grab_focus(w); - - // we handle multiple clicks ourselves here, in the same way as we do on Windows - if (e->type != GDK_BUTTON_PRESS) - // ignore GDK's generated double-clicks and beyond - return GDK_EVENT_PROPAGATE; - settings = gtk_widget_get_settings(w); - g_object_get(settings, - "gtk-double-click-time", &maxTime, - "gtk-double-click-distance", &maxDistance, - NULL); - // don't unref settings; it's transfer-none (thanks gregier in irc.gimp.net/#gtk+) - // e->time is guint32 - // e->x and e->y are floating-point; just make them 32-bit integers - // maxTime and maxDistance... are gint, which *should* fit, hopefully... - me.Count = clickCounterClick(a->cc, me.Down, - e->x, e->y, - e->time, maxTime, - maxDistance, maxDistance); - - me.Down = e->button; - me.Up = 0; - - // and set things up for window drags - a->dragevent = e; - finishMouseEvent(a, &me, e->button, e->x, e->y, e->state, e->window); - a->dragevent = NULL; - return GDK_EVENT_PROPAGATE; -} - -static gboolean areaWidget_button_release_event(GtkWidget *w, GdkEventButton *e) -{ - areaWidget *aw = areaWidget(w); - uiArea *a = aw->a; - uiAreaMouseEvent me; - - me.Down = 0; - me.Up = e->button; - me.Count = 0; - finishMouseEvent(a, &me, e->button, e->x, e->y, e->state, e->window); - return GDK_EVENT_PROPAGATE; -} - -static gboolean areaWidget_motion_notify_event(GtkWidget *w, GdkEventMotion *e) -{ - areaWidget *aw = areaWidget(w); - uiArea *a = aw->a; - uiAreaMouseEvent me; - - me.Down = 0; - me.Up = 0; - me.Count = 0; - finishMouseEvent(a, &me, 0, e->x, e->y, e->state, e->window); - return GDK_EVENT_PROPAGATE; -} - -// we want switching away from the control to reset the double-click counter, like with WM_ACTIVATE on Windows -// according to tristan in irc.gimp.net/#gtk+, doing this on both enter-notify-event and leave-notify-event is correct (and it seems to be true in my own tests; plus the events DO get sent when switching programs with the keyboard (just pointing that out)) -static gboolean onCrossing(areaWidget *aw, int left) -{ - uiArea *a = aw->a; - - (*(a->ah->MouseCrossed))(a->ah, a, left); - clickCounterReset(a->cc); - return GDK_EVENT_PROPAGATE; -} - -static gboolean areaWidget_enter_notify_event(GtkWidget *w, GdkEventCrossing *e) -{ - return onCrossing(areaWidget(w), 0); -} - -static gboolean areaWidget_leave_notify_event(GtkWidget *w, GdkEventCrossing *e) -{ - return onCrossing(areaWidget(w), 1); -} - -// note: there is no equivalent to WM_CAPTURECHANGED on GTK+; there literally is no way to break a grab like that (at least not on X11 and Wayland) -// even if I invoke the task switcher and switch processes, the mouse grab will still be held until I let go of all buttons -// therefore, no DragBroken() - -// we use GDK_KEY_Print as a sentinel because libui will never support the print screen key; that key belongs to the user - -static const struct { - guint keyval; - uiExtKey extkey; -} extKeys[] = { - { GDK_KEY_Escape, uiExtKeyEscape }, - { GDK_KEY_Insert, uiExtKeyInsert }, - { GDK_KEY_Delete, uiExtKeyDelete }, - { GDK_KEY_Home, uiExtKeyHome }, - { GDK_KEY_End, uiExtKeyEnd }, - { GDK_KEY_Page_Up, uiExtKeyPageUp }, - { GDK_KEY_Page_Down, uiExtKeyPageDown }, - { GDK_KEY_Up, uiExtKeyUp }, - { GDK_KEY_Down, uiExtKeyDown }, - { GDK_KEY_Left, uiExtKeyLeft }, - { GDK_KEY_Right, uiExtKeyRight }, - { GDK_KEY_F1, uiExtKeyF1 }, - { GDK_KEY_F2, uiExtKeyF2 }, - { GDK_KEY_F3, uiExtKeyF3 }, - { GDK_KEY_F4, uiExtKeyF4 }, - { GDK_KEY_F5, uiExtKeyF5 }, - { GDK_KEY_F6, uiExtKeyF6 }, - { GDK_KEY_F7, uiExtKeyF7 }, - { GDK_KEY_F8, uiExtKeyF8 }, - { GDK_KEY_F9, uiExtKeyF9 }, - { GDK_KEY_F10, uiExtKeyF10 }, - { GDK_KEY_F11, uiExtKeyF11 }, - { GDK_KEY_F12, uiExtKeyF12 }, - // numpad numeric keys and . are handled in events.c - { GDK_KEY_KP_Enter, uiExtKeyNEnter }, - { GDK_KEY_KP_Add, uiExtKeyNAdd }, - { GDK_KEY_KP_Subtract, uiExtKeyNSubtract }, - { GDK_KEY_KP_Multiply, uiExtKeyNMultiply }, - { GDK_KEY_KP_Divide, uiExtKeyNDivide }, - { GDK_KEY_Print, 0 }, -}; - -static const struct { - guint keyval; - uiModifiers mod; -} modKeys[] = { - { GDK_KEY_Control_L, uiModifierCtrl }, - { GDK_KEY_Control_R, uiModifierCtrl }, - { GDK_KEY_Alt_L, uiModifierAlt }, - { GDK_KEY_Alt_R, uiModifierAlt }, - { GDK_KEY_Meta_L, uiModifierAlt }, - { GDK_KEY_Meta_R, uiModifierAlt }, - { GDK_KEY_Shift_L, uiModifierShift }, - { GDK_KEY_Shift_R, uiModifierShift }, - { GDK_KEY_Super_L, uiModifierSuper }, - { GDK_KEY_Super_R, uiModifierSuper }, - { GDK_KEY_Print, 0 }, -}; - -// http://www.comptechdoc.org/os/linux/howlinuxworks/linux_hlkeycodes.html -int scancode_unix2normal(int scan) -{ - scan -= 8; - - // extended keys get weird scancodes. fix 'em up - switch (scan) - { - case 0x60: return 0x11C; - case 0x61: return 0x11D; - case 0x62: return 0x135; - case 0x63: return 0x137; - case 0x64: return 0x138; - case 0x66: return 0x147; - case 0x67: return 0x148; - case 0x68: return 0x149; - case 0x69: return 0x14B; - case 0x6A: return 0x14D; - case 0x6B: return 0x14F; - case 0x6C: return 0x150; - case 0x6D: return 0x151; - case 0x6E: return 0x152; - case 0x6F: return 0x153; - case 0x77: return 0x45; // PAUSE, this one is weird. check it. - case 0x7D: return 0x15B; // Windows key - case 0x7F: return 0x15D; // context menu key - // TODO: there may be more fancy keys - default: return scan; - } -} - -int scancode_normal2unix(int scan) -{ - // extended keys get weird scancodes. fix 'em up - switch (scan) - { - case 0x11C: return 8+0x60; - case 0x11D: return 8+0x61; - case 0x135: return 8+0x62; - case 0x137: return 8+0x63; - case 0x138: return 8+0x64; - case 0x147: return 8+0x66; - case 0x148: return 8+0x67; - case 0x149: return 8+0x68; - case 0x14B: return 8+0x69; - case 0x14D: return 8+0x6A; - case 0x14F: return 8+0x6B; - case 0x150: return 8+0x6C; - case 0x151: return 8+0x6D; - case 0x152: return 8+0x6E; - case 0x153: return 8+0x6F; - case 0x45: return 8+0x77; // PAUSE, this one is weird. check it. - case 0x15B: return 8+0x7D; // Windows key - case 0x15D: return 8+0x7F; // context menu key - // TODO: there may be more fancy keys - default: return scan + 8; - } -} - -static int areaKeyEvent(uiArea *a, int up, GdkEventKey *e) -{ - uiAreaKeyEvent ke; - guint state; - int i; - - ke.Key = 0; - ke.ExtKey = 0; - ke.Modifier = 0; - - state = translateModifiers(e->state, e->window); - ke.Modifiers = toModifiers(state); - - ke.Up = up; - ke.Repeat = 0; // TODO!!!!! - - ke.Scancode = scancode_unix2normal(e->hardware_keycode); - -#if 0 - for (i = 0; extKeys[i].keyval != GDK_KEY_Print; i++) - if (extKeys[i].keyval == e->keyval) { - ke.ExtKey = extKeys[i].extkey; - goto keyFound; - } - - for (i = 0; modKeys[i].keyval != GDK_KEY_Print; i++) - if (modKeys[i].keyval == e->keyval) { - ke.Modifier = modKeys[i].mod; - // don't include the modifier in ke.Modifiers - ke.Modifiers &= ~ke.Modifier; - goto keyFound; - } - - if (fromScancode(e->hardware_keycode - 8, &ke)) - goto keyFound; - - // no supported key found; treat as unhandled - return 0; - -keyFound: -#endif - return (*(a->ah->KeyEvent))(a->ah, a, &ke); -} - -static gboolean areaWidget_key_press_event(GtkWidget *w, GdkEventKey *e) -{ - areaWidget *aw = areaWidget(w); - uiArea *a = aw->a; - - if (areaKeyEvent(a, 0, e)) - return GDK_EVENT_STOP; - return GDK_EVENT_PROPAGATE; -} - -static gboolean areaWidget_key_release_event(GtkWidget *w, GdkEventKey *e) -{ - areaWidget *aw = areaWidget(w); - uiArea *a = aw->a; - - if (areaKeyEvent(a, 1, e)) - return GDK_EVENT_STOP; - return GDK_EVENT_PROPAGATE; -} - -char* uiKeyName(int scancode) -{ - scancode = scancode_normal2unix(scancode); - - char* ret; - guint* keyvals; int num; - GdkKeymap* keymap = gdk_keymap_get_for_display(gdk_display_get_default()); - if (gdk_keymap_get_entries_for_keycode(keymap, scancode, NULL, &keyvals, &num)) - { - // TODO: pick smarter?? - int keyval = keyvals[0]; - - g_free(keyvals); - - ret = gdk_keyval_name(keyval); - } - else - { - char tmp[16]; - sprintf(tmp, "#%03X", scancode); - ret = tmp; - } - - return uiUnixStrdupText(ret); -} - -enum { - pArea = 1, - nProps, -}; - -static GParamSpec *pspecArea; - -static void areaWidget_set_property(GObject *obj, guint prop, const GValue *value, GParamSpec *pspec) -{ - areaWidget *aw = areaWidget(obj); - - switch (prop) { - case pArea: - aw->a = (uiArea *) g_value_get_pointer(value); - aw->a->cc = &(aw->cc); - return; - } - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop, pspec); -} - -static void areaWidget_get_property(GObject *obj, guint prop, GValue *value, GParamSpec *pspec) -{ - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop, pspec); -} - -static void areaWidget_class_init(areaWidgetClass *class) -{ - G_OBJECT_CLASS(class)->dispose = areaWidget_dispose; - G_OBJECT_CLASS(class)->finalize = areaWidget_finalize; - G_OBJECT_CLASS(class)->set_property = areaWidget_set_property; - G_OBJECT_CLASS(class)->get_property = areaWidget_get_property; - - GTK_WIDGET_CLASS(class)->size_allocate = areaWidget_size_allocate; - GTK_WIDGET_CLASS(class)->draw = areaWidget_draw; - GTK_WIDGET_CLASS(class)->get_preferred_height = areaWidget_get_preferred_height; - GTK_WIDGET_CLASS(class)->get_preferred_width = areaWidget_get_preferred_width; - GTK_WIDGET_CLASS(class)->button_press_event = areaWidget_button_press_event; - GTK_WIDGET_CLASS(class)->button_release_event = areaWidget_button_release_event; - GTK_WIDGET_CLASS(class)->motion_notify_event = areaWidget_motion_notify_event; - GTK_WIDGET_CLASS(class)->enter_notify_event = areaWidget_enter_notify_event; - GTK_WIDGET_CLASS(class)->leave_notify_event = areaWidget_leave_notify_event; - GTK_WIDGET_CLASS(class)->key_press_event = areaWidget_key_press_event; - GTK_WIDGET_CLASS(class)->key_release_event = areaWidget_key_release_event; - - pspecArea = g_param_spec_pointer("libui-area", - "libui-area", - "uiArea.", - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property(G_OBJECT_CLASS(class), pArea, pspecArea); -} - -// control implementation - -uiUnixControlAllDefaultsExceptDestroy(uiArea) - -static void uiAreaDestroy(uiControl *c) -{ - uiArea* a = uiArea(c); - if (a->opengl && a->glContext) freeGLContext(a->glContext); - g_object_unref(uiArea(c)->widget); - uiFreeControl(c); -} - -void uiAreaSetBackgroundColor(uiArea *a, int r, int g, int b) -{ - a->bgR = r; - a->bgG = g; - a->bgB = b; -} - -void uiAreaSetSize(uiArea *a, int width, int height) -{ - if (!a->scrolling) - userbug("You cannot call uiAreaSetSize() on a non-scrolling uiArea. (area: %p)", a); - a->scrollWidth = width; - a->scrollHeight = height; - gtk_widget_queue_resize(a->areaWidget); -} - -gboolean _threadsaferefresh(gpointer data) -{ - uiArea* a = (uiArea*)data; - gtk_widget_queue_draw(a->areaWidget); - return FALSE; -} - -void uiAreaQueueRedrawAll(uiArea *a) -{ - // TODO: figure out how we could generalize the "thread-safe function call" mechanism - if (g_thread_self() != gtkthread) - g_idle_add(_threadsaferefresh, a); - else - gtk_widget_queue_draw(a->areaWidget); -} - -void uiAreaScrollTo(uiArea *a, double x, double y, double width, double height) -{ - // TODO - // TODO adjust adjustments and find source for that -} - -void uiAreaBeginUserWindowMove(uiArea *a) -{ - GtkWidget *toplevel; - - if (a->dragevent == NULL) - userbug("cannot call uiAreaBeginUserWindowMove() outside of a Mouse() with Down != 0"); - // TODO don't we have a libui function for this? did I scrap it? - // TODO widget or areaWidget? - toplevel = gtk_widget_get_toplevel(a->widget); - if (toplevel == NULL) { - // TODO - return; - } - // the docs say to do this - if (!gtk_widget_is_toplevel(toplevel)) { - // TODO - return; - } - if (!GTK_IS_WINDOW(toplevel)) { - // TODO - return; - } - gtk_window_begin_move_drag(GTK_WINDOW(toplevel), - a->dragevent->button, - a->dragevent->x_root, // TODO are these correct? - a->dragevent->y_root, - a->dragevent->time); -} - -static const GdkWindowEdge edges[] = { - [uiWindowResizeEdgeLeft] = GDK_WINDOW_EDGE_WEST, - [uiWindowResizeEdgeTop] = GDK_WINDOW_EDGE_NORTH, - [uiWindowResizeEdgeRight] = GDK_WINDOW_EDGE_EAST, - [uiWindowResizeEdgeBottom] = GDK_WINDOW_EDGE_SOUTH, - [uiWindowResizeEdgeTopLeft] = GDK_WINDOW_EDGE_NORTH_WEST, - [uiWindowResizeEdgeTopRight] = GDK_WINDOW_EDGE_NORTH_EAST, - [uiWindowResizeEdgeBottomLeft] = GDK_WINDOW_EDGE_SOUTH_WEST, - [uiWindowResizeEdgeBottomRight] = GDK_WINDOW_EDGE_SOUTH_EAST, -}; - -void uiAreaBeginUserWindowResize(uiArea *a, uiWindowResizeEdge edge) -{ - GtkWidget *toplevel; - - if (a->dragevent == NULL) - userbug("cannot call uiAreaBeginUserWindowResize() outside of a Mouse() with Down != 0"); - // TODO don't we have a libui function for this? did I scrap it? - // TODO widget or areaWidget? - toplevel = gtk_widget_get_toplevel(a->widget); - if (toplevel == NULL) { - // TODO - return; - } - // the docs say to do this - if (!gtk_widget_is_toplevel(toplevel)) { - // TODO - return; - } - if (!GTK_IS_WINDOW(toplevel)) { - // TODO - return; - } - gtk_window_begin_resize_drag(GTK_WINDOW(toplevel), - edges[edge], - a->dragevent->button, - a->dragevent->x_root, // TODO are these correct? - a->dragevent->y_root, - a->dragevent->time); -} - -uiArea *uiNewArea(uiAreaHandler *ah) -{ - uiArea *a; - - uiUnixNewControl(uiArea, a); - - a->ah = ah; - a->scrolling = FALSE; - a->opengl = FALSE; - - a->areaWidget = GTK_WIDGET(g_object_new(areaWidgetType, - "libui-area", a, - NULL)); - a->drawingArea = GTK_DRAWING_AREA(a->areaWidget); - a->area = areaWidget(a->areaWidget); - - a->widget = a->areaWidget; - - uiAreaSetBackgroundColor(a, -1, -1, -1); - - return a; -} - -void _areaCreateGLContext(GtkWidget* widget, gpointer data) -{ - uiArea* a = (uiArea*)data; - - uiGLContext* ctx = NULL; - for (int i = 0; a->req_versions[i] && !ctx; i++) - { - int major = uiGLVerMajor(a->req_versions[i]); - int minor = uiGLVerMinor(a->req_versions[i]); - - // we cannot support any version older than 3.2 via GDK - if ((major < 3) || (major == 3 && minor < 2)) - break; - - ctx = createGLContext(widget, major, minor); - } - - a->glContext = ctx; -} - -uiArea *uiNewGLArea(uiAreaHandler *ah, const unsigned int* req_versions) -{ - uiArea *a; - - uiUnixNewControl(uiArea, a); - - a->ah = ah; - a->scrolling = FALSE; - a->opengl = TRUE; - - a->glContext = NULL; - a->req_versions = req_versions; - a->areaWidget = GTK_WIDGET(g_object_new(areaWidgetType, - "libui-area", a, - NULL)); - a->area = areaWidget(a->areaWidget); - - a->widget = a->areaWidget; - - g_signal_connect(a->widget, "realize", G_CALLBACK(_areaCreateGLContext), a); - - uiAreaSetBackgroundColor(a, -1, -1, -1); - - return a; -} - -uiGLContext *uiAreaGetGLContext(uiArea* a) -{ - if (!a) return NULL; - return a->glContext; -} - -uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height) -{ - uiArea *a; - - uiUnixNewControl(uiArea, a); - - a->ah = ah; - a->scrolling = TRUE; - a->scrollWidth = width; - a->scrollHeight = height; - a->opengl = FALSE; - - a->swidget = gtk_scrolled_window_new(NULL, NULL); - a->scontainer = GTK_CONTAINER(a->swidget); - a->sw = GTK_SCROLLED_WINDOW(a->swidget); - - a->areaWidget = GTK_WIDGET(g_object_new(areaWidgetType, - "libui-area", a, - NULL)); - a->drawingArea = GTK_DRAWING_AREA(a->areaWidget); - a->area = areaWidget(a->areaWidget); - - a->widget = a->swidget; - - uiAreaSetBackgroundColor(a, -1, -1, -1); - - gtk_container_add(a->scontainer, a->areaWidget); - // and make the area visible; only the scrolled window's visibility is controlled by libui - gtk_widget_show(a->areaWidget); - - return a; -} diff --git a/src/libui_sdl/libui/unix/box.c b/src/libui_sdl/libui/unix/box.c deleted file mode 100644 index 23fb7f7..0000000 --- a/src/libui_sdl/libui/unix/box.c +++ /dev/null @@ -1,159 +0,0 @@ -// 7 april 2015 -#include "uipriv_unix.h" - -struct boxChild { - uiControl *c; - int stretchy; - gboolean oldhexpand; - GtkAlign oldhalign; - gboolean oldvexpand; - GtkAlign oldvalign; -}; - -struct uiBox { - uiUnixControl c; - GtkWidget *widget; - GtkContainer *container; - GtkBox *box; - GArray *controls; - int vertical; - int padded; - GtkSizeGroup *stretchygroup; // ensures all stretchy controls have the same size -}; - -uiUnixControlAllDefaultsExceptDestroy(uiBox) - -#define ctrl(b, i) &g_array_index(b->controls, struct boxChild, i) - -static void uiBoxDestroy(uiControl *c) -{ - uiBox *b = uiBox(c); - struct boxChild *bc; - guint i; - - // kill the size group - g_object_unref(b->stretchygroup); - // free all controls - for (i = 0; i < b->controls->len; i++) { - bc = ctrl(b, i); - uiControlSetParent(bc->c, NULL); - // and make sure the widget itself stays alive - uiUnixControlSetContainer(uiUnixControl(bc->c), b->container, TRUE); - uiControlDestroy(bc->c); - } - g_array_free(b->controls, TRUE); - // and then ourselves - g_object_unref(b->widget); - uiFreeControl(uiControl(b)); -} - -void uiBoxAppend(uiBox *b, uiControl *c, int stretchy) -{ - struct boxChild bc; - GtkWidget *widget; - - bc.c = c; - bc.stretchy = stretchy; - widget = GTK_WIDGET(uiControlHandle(bc.c)); - bc.oldhexpand = gtk_widget_get_hexpand(widget); - bc.oldhalign = gtk_widget_get_halign(widget); - bc.oldvexpand = gtk_widget_get_vexpand(widget); - bc.oldvalign = gtk_widget_get_valign(widget); - - if (bc.stretchy) { - if (b->vertical) { - gtk_widget_set_vexpand(widget, TRUE); - gtk_widget_set_valign(widget, GTK_ALIGN_FILL); - } else { - gtk_widget_set_hexpand(widget, TRUE); - gtk_widget_set_halign(widget, GTK_ALIGN_FILL); - } - gtk_size_group_add_widget(b->stretchygroup, widget); - } else - if (b->vertical) - gtk_widget_set_vexpand(widget, FALSE); - else - gtk_widget_set_hexpand(widget, FALSE); - // and make them fill the opposite direction - if (b->vertical) { - gtk_widget_set_hexpand(widget, TRUE); - gtk_widget_set_halign(widget, GTK_ALIGN_FILL); - } else { - gtk_widget_set_vexpand(widget, TRUE); - gtk_widget_set_valign(widget, GTK_ALIGN_FILL); - } - - uiControlSetParent(bc.c, uiControl(b)); - uiUnixControlSetContainer(uiUnixControl(bc.c), b->container, FALSE); - g_array_append_val(b->controls, bc); -} - -void uiBoxDelete(uiBox *b, int index) -{ - struct boxChild *bc; - GtkWidget *widget; - - bc = ctrl(b, index); - widget = GTK_WIDGET(uiControlHandle(bc->c)); - - uiControlSetParent(bc->c, NULL); - uiUnixControlSetContainer(uiUnixControl(bc->c), b->container, TRUE); - - if (bc->stretchy) - gtk_size_group_remove_widget(b->stretchygroup, widget); - gtk_widget_set_hexpand(widget, bc->oldhexpand); - gtk_widget_set_halign(widget, bc->oldhalign); - gtk_widget_set_vexpand(widget, bc->oldvexpand); - gtk_widget_set_valign(widget, bc->oldvalign); - - g_array_remove_index(b->controls, index); -} - -int uiBoxPadded(uiBox *b) -{ - return b->padded; -} - -void uiBoxSetPadded(uiBox *b, int padded) -{ - b->padded = padded; - if (b->padded) - if (b->vertical) - gtk_box_set_spacing(b->box, gtkYPadding); - else - gtk_box_set_spacing(b->box, gtkXPadding); - else - gtk_box_set_spacing(b->box, 0); -} - -static uiBox *finishNewBox(GtkOrientation orientation) -{ - uiBox *b; - - uiUnixNewControl(uiBox, b); - - b->widget = gtk_box_new(orientation, 0); - b->container = GTK_CONTAINER(b->widget); - b->box = GTK_BOX(b->widget); - - b->vertical = orientation == GTK_ORIENTATION_VERTICAL; - - if (b->vertical) - b->stretchygroup = gtk_size_group_new(GTK_SIZE_GROUP_VERTICAL); - else - b->stretchygroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); - - b->controls = g_array_new(FALSE, TRUE, sizeof (struct boxChild)); - - return b; -} - -uiBox *uiNewHorizontalBox(void) -{ - return finishNewBox(GTK_ORIENTATION_HORIZONTAL); -} - -uiBox *uiNewVerticalBox(void) -{ - return finishNewBox(GTK_ORIENTATION_VERTICAL); -} diff --git a/src/libui_sdl/libui/unix/button.c b/src/libui_sdl/libui/unix/button.c deleted file mode 100644 index b0500e3..0000000 --- a/src/libui_sdl/libui/unix/button.c +++ /dev/null @@ -1,57 +0,0 @@ -// 10 june 2015 -#include "uipriv_unix.h" - -struct uiButton { - uiUnixControl c; - GtkWidget *widget; - GtkButton *button; - void (*onClicked)(uiButton *, void *); - void *onClickedData; -}; - -uiUnixControlAllDefaults(uiButton) - -static void onClicked(GtkButton *button, gpointer data) -{ - uiButton *b = uiButton(data); - - (*(b->onClicked))(b, b->onClickedData); -} - -static void defaultOnClicked(uiButton *b, void *data) -{ - // do nothing -} - -char *uiButtonText(uiButton *b) -{ - return uiUnixStrdupText(gtk_button_get_label(b->button)); -} - -void uiButtonSetText(uiButton *b, const char *text) -{ - gtk_button_set_label(b->button, text); -} - -void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *, void *), void *data) -{ - b->onClicked = f; - b->onClickedData = data; -} - -uiButton *uiNewButton(const char *text) -{ - uiButton *b; - - uiUnixNewControl(uiButton, b); - - b->widget = gtk_button_new_with_label(text); - b->button = GTK_BUTTON(b->widget); - - g_signal_connect(b->widget, "clicked", G_CALLBACK(onClicked), b); - uiButtonOnClicked(b, defaultOnClicked, NULL); - - gtk_widget_set_size_request(b->widget, 64, 1); - - return b; -} diff --git a/src/libui_sdl/libui/unix/cellrendererbutton.c b/src/libui_sdl/libui/unix/cellrendererbutton.c deleted file mode 100644 index e3bbf48..0000000 --- a/src/libui_sdl/libui/unix/cellrendererbutton.c +++ /dev/null @@ -1,299 +0,0 @@ -// 28 june 2016 -#include "uipriv_unix.h" - -// TODOs -// - it's a rather tight fit -// - selected row text color is white -// - resizing a column with a button in it crashes the program -// - accessibility -// - right side too big? - -#define cellRendererButtonType (cellRendererButton_get_type()) -#define cellRendererButton(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), cellRendererButtonType, cellRendererButton)) -#define isCellRendererButton(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), cellRendererButtonType)) -#define cellRendererButtonClass(class) (G_TYPE_CHECK_CLASS_CAST((class), cellRendererButtonType, cellRendererButtonClass)) -#define isCellRendererButtonClass(class) (G_TYPE_CHECK_CLASS_TYPE((class), cellRendererButton)) -#define getCellRendererButtonClass(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), cellRendererButtonType, cellRendererButtonClass)) - -typedef struct cellRendererButton cellRendererButton; -typedef struct cellRendererButtonClass cellRendererButtonClass; - -struct cellRendererButton { - GtkCellRenderer parent_instance; - char *text; -}; - -struct cellRendererButtonClass { - GtkCellRendererClass parent_class; -}; - -G_DEFINE_TYPE(cellRendererButton, cellRendererButton, GTK_TYPE_CELL_RENDERER) - -static void cellRendererButton_init(cellRendererButton *c) -{ - g_object_set(c, "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL); - // the standard cell renderers all do this - gtk_cell_renderer_set_padding(GTK_CELL_RENDERER(c), 2, 2); -} - -static void cellRendererButton_dispose(GObject *obj) -{ - G_OBJECT_CLASS(cellRendererButton_parent_class)->dispose(obj); -} - -static void cellRendererButton_finalize(GObject *obj) -{ - cellRendererButton *c = cellRendererButton(obj); - - if (c->text != NULL) { - g_free(c->text); - c->text = NULL; - } - G_OBJECT_CLASS(cellRendererButton_parent_class)->finalize(obj); -} - -static GtkSizeRequestMode cellRendererButton_get_request_mode(GtkCellRenderer *r) -{ - return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH; -} - -// this is basically what GtkCellRendererToggle did in 3.10 and does in 3.20, as well as what the Foreign Drawing gtk3-demo demo does -static GtkStyleContext *setButtonStyle(GtkWidget *widget) -{ - GtkStyleContext *base, *context; - GtkWidgetPath *path; - - base = gtk_widget_get_style_context(widget); - context = gtk_style_context_new(); - - path = gtk_widget_path_copy(gtk_style_context_get_path(base)); - gtk_widget_path_append_type(path, G_TYPE_NONE); - if (!FUTURE_gtk_widget_path_iter_set_object_name(path, -1, "button")) - // not on 3.20; try the type - gtk_widget_path_iter_set_object_type(path, -1, GTK_TYPE_BUTTON); - - gtk_style_context_set_path(context, path); - gtk_style_context_set_parent(context, base); - // the gtk3-demo example (which says we need to do this) uses gtk_widget_path_iter_get_state(path, -1) but that's not available until 3.14 - // TODO make a future for that too - gtk_style_context_set_state(context, gtk_style_context_get_state(base)); - gtk_widget_path_unref(path); - - // and if the above widget path screwery stil doesn't work, this will - gtk_style_context_add_class(context, GTK_STYLE_CLASS_BUTTON); - - return context; -} - -void unsetButtonStyle(GtkStyleContext *context) -{ - g_object_unref(context); -} - -// this is based on what GtkCellRendererText does -static void cellRendererButton_get_preferred_width(GtkCellRenderer *r, GtkWidget *widget, gint *minimum, gint *natural) -{ - cellRendererButton *c = cellRendererButton(r); - gint xpad; - PangoLayout *layout; - PangoRectangle rect; - gint out; - - gtk_cell_renderer_get_padding(GTK_CELL_RENDERER(c), &xpad, NULL); - - layout = gtk_widget_create_pango_layout(widget, c->text); - pango_layout_set_width(layout, -1); - pango_layout_get_extents(layout, NULL, &rect); - g_object_unref(layout); - - out = 2 * xpad + PANGO_PIXELS_CEIL(rect.width); - if (minimum != NULL) - *minimum = out; - if (natural != NULL) - *natural = out; -} - -// this is based on what GtkCellRendererText does -static void cellRendererButton_get_preferred_height_for_width(GtkCellRenderer *r, GtkWidget *widget, gint width, gint *minimum, gint *natural) -{ - cellRendererButton *c = cellRendererButton(r); - gint xpad, ypad; - PangoLayout *layout; - gint height; - gint out; - - gtk_cell_renderer_get_padding(GTK_CELL_RENDERER(c), &xpad, &ypad); - - layout = gtk_widget_create_pango_layout(widget, c->text); - pango_layout_set_width(layout, ((2 * xpad + width) * PANGO_SCALE)); - pango_layout_get_pixel_size(layout, NULL, &height); - g_object_unref(layout); - - out = 2 * ypad + height; - if (minimum != NULL) - *minimum = out; - if (natural != NULL) - *natural = out; -} - -// this is basically what GtkCellRendererText does -static void cellRendererButton_get_preferred_height(GtkCellRenderer *r, GtkWidget *widget, gint *minimum, gint *natural) -{ - gint width; - - gtk_cell_renderer_get_preferred_width(r, widget, &width, NULL); - gtk_cell_renderer_get_preferred_height_for_width(r, widget, width, minimum, natural); -} - -// this is based on what GtkCellRendererText does -static void cellRendererButton_get_aligned_area(GtkCellRenderer *r, GtkWidget *widget, GtkCellRendererState flags, const GdkRectangle *cell_area, GdkRectangle *aligned_area) -{ - cellRendererButton *c = cellRendererButton(r); - gint xpad, ypad; - PangoLayout *layout; - PangoRectangle rect; - gfloat xalign, yalign; - gint xoffset, yoffset; - - gtk_cell_renderer_get_padding(GTK_CELL_RENDERER(c), &xpad, &ypad); - - layout = gtk_widget_create_pango_layout(widget, c->text); - pango_layout_set_width(layout, -1); - pango_layout_get_pixel_extents(layout, NULL, &rect); - - xoffset = 0; - yoffset = 0; - if (cell_area != NULL) { - gtk_cell_renderer_get_alignment(GTK_CELL_RENDERER(c), &xalign, &yalign); - xoffset = cell_area->width - (2 * xpad + rect.width); - // use explicit casts just to be safe - if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL) - xoffset = ((gdouble) xoffset) * (1.0 - xalign); - else - xoffset *= ((gdouble) xoffset) * xalign; - yoffset = yalign * (cell_area->height - (2 * ypad + rect.height)); - yoffset = MAX(yoffset, 0); - } - - aligned_area->x = cell_area->x + xoffset; - aligned_area->y = cell_area->y + yoffset; - aligned_area->width = 2 * xpad + rect.width; - aligned_area->height = 2 * ypad + rect.height; - - g_object_unref(layout); -} - -// this is based on both what GtkCellRendererText does and what GtkCellRendererToggle does -static void cellRendererButton_render(GtkCellRenderer *r, cairo_t *cr, GtkWidget *widget, const GdkRectangle *background_area, const GdkRectangle *cell_area, GtkCellRendererState flags) -{ - cellRendererButton *c = cellRendererButton(r); - gint xpad, ypad; - GdkRectangle alignedArea; - gint xoffset, yoffset; - GtkStyleContext *context; - PangoLayout *layout; - PangoRectangle rect; - - gtk_cell_renderer_get_padding(GTK_CELL_RENDERER(c), &xpad, &ypad); - gtk_cell_renderer_get_aligned_area(GTK_CELL_RENDERER(c), widget, flags, cell_area, &alignedArea); - xoffset = alignedArea.x - cell_area->x; - yoffset = alignedArea.y - cell_area->y; - - context = setButtonStyle(widget); - layout = gtk_widget_create_pango_layout(widget, c->text); - - gtk_render_background(context, cr, - background_area->x + xoffset + xpad, - background_area->y + yoffset + ypad, - background_area->width - 2 * xpad, - background_area->height - 2 * ypad); - gtk_render_frame(context, cr, - background_area->x + xoffset + xpad, - background_area->y + yoffset + ypad, - background_area->width - 2 * xpad, - background_area->height - 2 * ypad); - - pango_layout_set_width(layout, -1); - pango_layout_get_pixel_extents(layout, NULL, &rect); - xoffset -= rect.x; - gtk_render_layout(context, cr, - cell_area->x + xoffset + xpad, - cell_area->y + yoffset + ypad, - layout); - - g_object_unref(layout); - unsetButtonStyle(context); -} - -static guint clickedSignal; - -static gboolean cellRendererButton_activate(GtkCellRenderer *r, GdkEvent *e, GtkWidget *widget, const gchar *path, const GdkRectangle *background_area, const GdkRectangle *cell_area, GtkCellRendererState flags) -{ - g_signal_emit(r, clickedSignal, 0, path); - return TRUE; -} - -static GParamSpec *props[2] = { NULL, NULL }; - -static void cellRendererButton_set_property(GObject *object, guint prop, const GValue *value, GParamSpec *pspec) -{ - cellRendererButton *c = cellRendererButton(object); - - if (prop != 1) { - G_OBJECT_WARN_INVALID_PROPERTY_ID(c, prop, pspec); - return; - } - if (c->text != NULL) - g_free(c->text); - c->text = g_value_dup_string(value); - // GtkCellRendererText doesn't queue a redraw; we won't either -} - -static void cellRendererButton_get_property(GObject *object, guint prop, GValue *value, GParamSpec *pspec) -{ - cellRendererButton *c = cellRendererButton(object); - - if (prop != 1) { - G_OBJECT_WARN_INVALID_PROPERTY_ID(c, prop, pspec); - return; - } - g_value_set_string(value, c->text); -} - -static void cellRendererButton_class_init(cellRendererButtonClass *class) -{ - G_OBJECT_CLASS(class)->dispose = cellRendererButton_dispose; - G_OBJECT_CLASS(class)->finalize = cellRendererButton_finalize; - G_OBJECT_CLASS(class)->set_property = cellRendererButton_set_property; - G_OBJECT_CLASS(class)->get_property = cellRendererButton_get_property; - GTK_CELL_RENDERER_CLASS(class)->get_request_mode = cellRendererButton_get_request_mode; - GTK_CELL_RENDERER_CLASS(class)->get_preferred_width = cellRendererButton_get_preferred_width; - GTK_CELL_RENDERER_CLASS(class)->get_preferred_height_for_width = cellRendererButton_get_preferred_height_for_width; - GTK_CELL_RENDERER_CLASS(class)->get_preferred_height = cellRendererButton_get_preferred_height; - // don't provide a get_preferred_width_for_height() - GTK_CELL_RENDERER_CLASS(class)->get_aligned_area = cellRendererButton_get_aligned_area; - // don't provide a get_size() - GTK_CELL_RENDERER_CLASS(class)->render = cellRendererButton_render; - GTK_CELL_RENDERER_CLASS(class)->activate = cellRendererButton_activate; - // don't provide a start_editing() - - props[1] = g_param_spec_string("text", - "Text", - "Button text", - "", - G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); - g_object_class_install_properties(G_OBJECT_CLASS(class), 2, props); - - clickedSignal = g_signal_new("clicked", - G_TYPE_FROM_CLASS(class), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, NULL, - G_TYPE_NONE, - 1, G_TYPE_STRING); -} - -GtkCellRenderer *newCellRendererButton(void) -{ - return GTK_CELL_RENDERER(g_object_new(cellRendererButtonType, NULL)); -} diff --git a/src/libui_sdl/libui/unix/checkbox.c b/src/libui_sdl/libui/unix/checkbox.c deleted file mode 100644 index 47f8514..0000000 --- a/src/libui_sdl/libui/unix/checkbox.c +++ /dev/null @@ -1,78 +0,0 @@ -// 10 june 2015 -#include "uipriv_unix.h" - -struct uiCheckbox { - uiUnixControl c; - GtkWidget *widget; - GtkButton *button; - GtkToggleButton *toggleButton; - GtkCheckButton *checkButton; - void (*onToggled)(uiCheckbox *, void *); - void *onToggledData; - gulong onToggledSignal; -}; - -uiUnixControlAllDefaults(uiCheckbox) - -static void onToggled(GtkToggleButton *b, gpointer data) -{ - uiCheckbox *c = uiCheckbox(data); - - (*(c->onToggled))(c, c->onToggledData); -} - -static void defaultOnToggled(uiCheckbox *c, void *data) -{ - // do nothing -} - -char *uiCheckboxText(uiCheckbox *c) -{ - return uiUnixStrdupText(gtk_button_get_label(c->button)); -} - -void uiCheckboxSetText(uiCheckbox *c, const char *text) -{ - gtk_button_set_label(GTK_BUTTON(c->button), text); -} - -void uiCheckboxOnToggled(uiCheckbox *c, void (*f)(uiCheckbox *, void *), void *data) -{ - c->onToggled = f; - c->onToggledData = data; -} - -int uiCheckboxChecked(uiCheckbox *c) -{ - return gtk_toggle_button_get_active(c->toggleButton) != FALSE; -} - -void uiCheckboxSetChecked(uiCheckbox *c, int checked) -{ - gboolean active; - - active = FALSE; - if (checked) - active = TRUE; - // we need to inhibit sending of ::toggled because this WILL send a ::toggled otherwise - g_signal_handler_block(c->toggleButton, c->onToggledSignal); - gtk_toggle_button_set_active(c->toggleButton, active); - g_signal_handler_unblock(c->toggleButton, c->onToggledSignal); -} - -uiCheckbox *uiNewCheckbox(const char *text) -{ - uiCheckbox *c; - - uiUnixNewControl(uiCheckbox, c); - - c->widget = gtk_check_button_new_with_label(text); - c->button = GTK_BUTTON(c->widget); - c->toggleButton = GTK_TOGGLE_BUTTON(c->widget); - c->checkButton = GTK_CHECK_BUTTON(c->widget); - - c->onToggledSignal = g_signal_connect(c->widget, "toggled", G_CALLBACK(onToggled), c); - uiCheckboxOnToggled(c, defaultOnToggled, NULL); - - return c; -} diff --git a/src/libui_sdl/libui/unix/child.c b/src/libui_sdl/libui/unix/child.c deleted file mode 100644 index b4a0967..0000000 --- a/src/libui_sdl/libui/unix/child.c +++ /dev/null @@ -1,120 +0,0 @@ -// 28 august 2015 -#include "uipriv_unix.h" - -// This file contains helpers for managing child controls. - -struct child { - uiControl *c; - GtkWidget *widget; - - gboolean oldhexpand; - GtkAlign oldhalign; - gboolean oldvexpand; - GtkAlign oldvalign; - - // Some children can be boxed; that is, they can have an optionally-margined box around them. - // uiGroup, uiTab, and uiWindow all do this. - GtkWidget *box; - - // If the child is not boxed, this is its parent. - // If the child is boxed, this is the box. - GtkContainer *parent; - - // This flag is for users of these functions. - // For uiBox, this is "spaced". - // For uiTab, this is "margined". (uiGroup and uiWindow have to maintain their margined state themselves, since the margined state is independent of whether there is a child for those two.) - int flag; -}; - -struct child *newChild(uiControl *child, uiControl *parent, GtkContainer *parentContainer) -{ - struct child *c; - - if (child == NULL) - return NULL; - - c = uiNew(struct child); - c->c = child; - c->widget = GTK_WIDGET(uiControlHandle(c->c)); - - c->oldhexpand = gtk_widget_get_hexpand(c->widget); - c->oldhalign = gtk_widget_get_halign(c->widget); - c->oldvexpand = gtk_widget_get_vexpand(c->widget); - c->oldvalign = gtk_widget_get_valign(c->widget); - - uiControlSetParent(c->c, parent); - uiUnixControlSetContainer(uiUnixControl(c->c), parentContainer, FALSE); - c->parent = parentContainer; - - return c; -} - -struct child *newChildWithBox(uiControl *child, uiControl *parent, GtkContainer *parentContainer, int margined) -{ - struct child *c; - GtkWidget *box; - - if (child == NULL) - return NULL; - box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - gtk_widget_show(box); - c = newChild(child, parent, GTK_CONTAINER(box)); - gtk_widget_set_hexpand(c->widget, TRUE); - gtk_widget_set_halign(c->widget, GTK_ALIGN_FILL); - gtk_widget_set_vexpand(c->widget, TRUE); - gtk_widget_set_valign(c->widget, GTK_ALIGN_FILL); - c->box = box; - gtk_container_add(parentContainer, c->box); - childSetMargined(c, margined); - return c; -} - -void childRemove(struct child *c) -{ - uiControlSetParent(c->c, NULL); - uiUnixControlSetContainer(uiUnixControl(c->c), c->parent, TRUE); - - gtk_widget_set_hexpand(c->widget, c->oldhexpand); - gtk_widget_set_halign(c->widget, c->oldhalign); - gtk_widget_set_vexpand(c->widget, c->oldvexpand); - gtk_widget_set_valign(c->widget, c->oldvalign); - - if (c->box != NULL) - gtk_widget_destroy(c->box); - - uiFree(c); -} - -void childDestroy(struct child *c) -{ - uiControl *child; - - child = c->c; - childRemove(c); - uiControlDestroy(child); -} - -GtkWidget *childWidget(struct child *c) -{ - return c->widget; -} - -int childFlag(struct child *c) -{ - return c->flag; -} - -void childSetFlag(struct child *c, int flag) -{ - c->flag = flag; -} - -GtkWidget *childBox(struct child *c) -{ - return c->box; -} - -void childSetMargined(struct child *c, int margined) -{ - setMargined(GTK_CONTAINER(c->box), margined); -} diff --git a/src/libui_sdl/libui/unix/colorbutton.c b/src/libui_sdl/libui/unix/colorbutton.c deleted file mode 100644 index 393b16f..0000000 --- a/src/libui_sdl/libui/unix/colorbutton.c +++ /dev/null @@ -1,80 +0,0 @@ -// 15 may 2016 -#include "uipriv_unix.h" - -struct uiColorButton { - uiUnixControl c; - GtkWidget *widget; - GtkButton *button; - GtkColorButton *cb; - GtkColorChooser *cc; - void (*onChanged)(uiColorButton *, void *); - void *onChangedData; -}; - -uiUnixControlAllDefaults(uiColorButton) - -static void onColorSet(GtkColorButton *button, gpointer data) -{ - uiColorButton *b = uiColorButton(data); - - (*(b->onChanged))(b, b->onChangedData); -} - -static void defaultOnChanged(uiColorButton *b, void *data) -{ - // do nothing -} - -void uiColorButtonColor(uiColorButton *b, double *r, double *g, double *bl, double *a) -{ - GdkRGBA rgba; - - gtk_color_chooser_get_rgba(b->cc, &rgba); - *r = rgba.red; - *g = rgba.green; - *bl = rgba.blue; - *a = rgba.alpha; -} - -void uiColorButtonSetColor(uiColorButton *b, double r, double g, double bl, double a) -{ - GdkRGBA rgba; - - rgba.red = r; - rgba.green = g; - rgba.blue = bl; - rgba.alpha = a; - // no need to inhibit the signal; color-set is documented as only being sent when the user changes the color - gtk_color_chooser_set_rgba(b->cc, &rgba); -} - -void uiColorButtonOnChanged(uiColorButton *b, void (*f)(uiColorButton *, void *), void *data) -{ - b->onChanged = f; - b->onChangedData = data; -} - -uiColorButton *uiNewColorButton(void) -{ - uiColorButton *b; - GdkRGBA black; - - uiUnixNewControl(uiColorButton, b); - - // I'm not sure what the initial color is; set up a real one - black.red = 0.0; - black.green = 0.0; - black.blue = 0.0; - black.alpha = 1.0; - b->widget = gtk_color_button_new_with_rgba(&black); - b->button = GTK_BUTTON(b->widget); - b->cb = GTK_COLOR_BUTTON(b->widget); - b->cc = GTK_COLOR_CHOOSER(b->widget); - - gtk_color_chooser_set_use_alpha(b->cc, TRUE); - - g_signal_connect(b->widget, "color-set", G_CALLBACK(onColorSet), b); - uiColorButtonOnChanged(b, defaultOnChanged, NULL); - - return b; -} diff --git a/src/libui_sdl/libui/unix/combobox.c b/src/libui_sdl/libui/unix/combobox.c deleted file mode 100644 index 6fed804..0000000 --- a/src/libui_sdl/libui/unix/combobox.c +++ /dev/null @@ -1,66 +0,0 @@ -// 11 june 2015 -#include "uipriv_unix.h" - -struct uiCombobox { - uiUnixControl c; - GtkWidget *widget; - GtkComboBox *combobox; - GtkComboBoxText *comboboxText; - void (*onSelected)(uiCombobox *, void *); - void *onSelectedData; - gulong onSelectedSignal; -}; - -uiUnixControlAllDefaults(uiCombobox) - -static void onChanged(GtkComboBox *cbox, gpointer data) -{ - uiCombobox *c = uiCombobox(data); - - (*(c->onSelected))(c, c->onSelectedData); -} - -static void defaultOnSelected(uiCombobox *c, void *data) -{ - // do nothing -} - -void uiComboboxAppend(uiCombobox *c, const char *text) -{ - gtk_combo_box_text_append(c->comboboxText, NULL, text); -} - -int uiComboboxSelected(uiCombobox *c) -{ - return gtk_combo_box_get_active(c->combobox); -} - -void uiComboboxSetSelected(uiCombobox *c, int n) -{ - // we need to inhibit sending of ::changed because this WILL send a ::changed otherwise - g_signal_handler_block(c->combobox, c->onSelectedSignal); - gtk_combo_box_set_active(c->combobox, n); - g_signal_handler_unblock(c->combobox, c->onSelectedSignal); -} - -void uiComboboxOnSelected(uiCombobox *c, void (*f)(uiCombobox *c, void *data), void *data) -{ - c->onSelected = f; - c->onSelectedData = data; -} - -uiCombobox *uiNewCombobox(void) -{ - uiCombobox *c; - - uiUnixNewControl(uiCombobox, c); - - c->widget = gtk_combo_box_text_new(); - c->combobox = GTK_COMBO_BOX(c->widget); - c->comboboxText = GTK_COMBO_BOX_TEXT(c->widget); - - c->onSelectedSignal = g_signal_connect(c->widget, "changed", G_CALLBACK(onChanged), c); - uiComboboxOnSelected(c, defaultOnSelected, NULL); - - return c; -} diff --git a/src/libui_sdl/libui/unix/control.c b/src/libui_sdl/libui/unix/control.c deleted file mode 100644 index f6fdcea..0000000 --- a/src/libui_sdl/libui/unix/control.c +++ /dev/null @@ -1,14 +0,0 @@ -// 16 august 2015 -#include "uipriv_unix.h" - -void uiUnixControlSetContainer(uiUnixControl *c, GtkContainer *container, gboolean remove) -{ - (*(c->SetContainer))(c, container, remove); -} - -#define uiUnixControlSignature 0x556E6978 - -uiUnixControl *uiUnixAllocControl(size_t n, uint32_t typesig, const char *typenamestr) -{ - return uiUnixControl(uiAllocControl(n, uiUnixControlSignature, typesig, typenamestr)); -} diff --git a/src/libui_sdl/libui/unix/datetimepicker.c b/src/libui_sdl/libui/unix/datetimepicker.c deleted file mode 100644 index 19689a2..0000000 --- a/src/libui_sdl/libui/unix/datetimepicker.c +++ /dev/null @@ -1,599 +0,0 @@ -// 4 september 2015 -#include "uipriv_unix.h" - -// LONGTERM imitate gnome-calendar's day/month/year entries above the calendar -// LONGTERM allow entering a 24-hour hour in the hour spinbutton and adjust accordingly - -#define dateTimePickerWidgetType (dateTimePickerWidget_get_type()) -#define dateTimePickerWidget(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), dateTimePickerWidgetType, dateTimePickerWidget)) -#define isDateTimePickerWidget(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), dateTimePickerWidgetType)) -#define dateTimePickerWidgetClass(class) (G_TYPE_CHECK_CLASS_CAST((class), dateTimePickerWidgetType, dateTimePickerWidgetClass)) -#define isDateTimePickerWidgetClass(class) (G_TYPE_CHECK_CLASS_TYPE((class), dateTimePickerWidget)) -#define getDateTimePickerWidgetClass(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), dateTimePickerWidgetType, dateTimePickerWidgetClass)) - -typedef struct dateTimePickerWidget dateTimePickerWidget; -typedef struct dateTimePickerWidgetClass dateTimePickerWidgetClass; - -struct dateTimePickerWidget { - GtkToggleButton parent_instance; - - gulong toggledSignal; - - gboolean hasTime; - gboolean hasDate; - - GtkWidget *window; - GtkWidget *box; - GtkWidget *calendar; - GtkWidget *timebox; - GtkWidget *hours; - GtkWidget *minutes; - GtkWidget *seconds; - GtkWidget *ampm; - - gulong hoursBlock; - gulong minutesBlock; - gulong secondsBlock; - gulong ampmBlock; - - GdkDevice *keyboard; - GdkDevice *mouse; -}; - -struct dateTimePickerWidgetClass { - GtkToggleButtonClass parent_class; -}; - -G_DEFINE_TYPE(dateTimePickerWidget, dateTimePickerWidget, GTK_TYPE_TOGGLE_BUTTON) - -static int realSpinValue(GtkSpinButton *spinButton) -{ - GtkAdjustment *adj; - - adj = gtk_spin_button_get_adjustment(spinButton); - return (int) gtk_adjustment_get_value(adj); -} - -static void setRealSpinValue(GtkSpinButton *spinButton, int value, gulong block) -{ - GtkAdjustment *adj; - - g_signal_handler_block(spinButton, block); - adj = gtk_spin_button_get_adjustment(spinButton); - gtk_adjustment_set_value(adj, value); - g_signal_handler_unblock(spinButton, block); -} - -static GDateTime *selected(dateTimePickerWidget *d) -{ - // choose a day for which all times are likely to be valid for the default date in case we're only dealing with time - guint year = 1970, month = 1, day = 1; - guint hour = 0, minute = 0, second = 0; - - if (d->hasDate) { - gtk_calendar_get_date(GTK_CALENDAR(d->calendar), &year, &month, &day); - month++; // GtkCalendar/GDateTime differences - } - if (d->hasTime) { - hour = realSpinValue(GTK_SPIN_BUTTON(d->hours)); - if (realSpinValue(GTK_SPIN_BUTTON(d->ampm)) != 0) - hour += 12; - minute = realSpinValue(GTK_SPIN_BUTTON(d->minutes)); - second = realSpinValue(GTK_SPIN_BUTTON(d->seconds)); - } - return g_date_time_new_local(year, month, day, hour, minute, second); -} - -static void setLabel(dateTimePickerWidget *d) -{ - GDateTime *dt; - char *fmt; - char *msg; - gboolean free; - - dt = selected(d); - free = FALSE; - if (d->hasDate && d->hasTime) { - // don't use D_T_FMT; that's too verbose - fmt = g_strdup_printf("%s %s", nl_langinfo(D_FMT), nl_langinfo(T_FMT)); - free = TRUE; - } else if (d->hasDate) - fmt = nl_langinfo(D_FMT); - else - fmt = nl_langinfo(T_FMT); - msg = g_date_time_format(dt, fmt); - gtk_button_set_label(GTK_BUTTON(d), msg); - g_free(msg); - if (free) - g_free(fmt); - g_date_time_unref(dt); -} - -static void dateTimeChanged(dateTimePickerWidget *d) -{ - setLabel(d); - // TODO fire event here -} - -// we don't want ::toggled to be sent again -static void setActive(dateTimePickerWidget *d, gboolean active) -{ - g_signal_handler_block(d, d->toggledSignal); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(d), active); - g_signal_handler_unblock(d, d->toggledSignal); -} - -// like startGrab() below, a lot of this is in the order that GtkComboBox does it -static void endGrab(dateTimePickerWidget *d) -{ - if (d->keyboard != NULL) - gdk_device_ungrab(d->keyboard, GDK_CURRENT_TIME); - gdk_device_ungrab(d->mouse, GDK_CURRENT_TIME); - gtk_device_grab_remove(d->window, d->mouse); - d->keyboard = NULL; - d->mouse = NULL; -} - -static void hidePopup(dateTimePickerWidget *d) -{ - endGrab(d); - gtk_widget_hide(d->window); - setActive(d, FALSE); -} - -// this consolidates a good chunk of what GtkComboBox does -static gboolean startGrab(dateTimePickerWidget *d) -{ - GdkDevice *dev; - guint32 time; - GdkWindow *window; - GdkDevice *keyboard, *mouse; - - dev = gtk_get_current_event_device(); - if (dev == NULL) { - // this is what GtkComboBox does - // since no device was set, just use the first available "master device" - GdkDisplay *disp; - GdkDeviceManager *dm; - GList *list; - - disp = gtk_widget_get_display(GTK_WIDGET(d)); - dm = gdk_display_get_device_manager(disp); - list = gdk_device_manager_list_devices(dm, GDK_DEVICE_TYPE_MASTER); - dev = (GdkDevice *) (list->data); - g_list_free(list); - } - - time = gtk_get_current_event_time(); - keyboard = dev; - mouse = gdk_device_get_associated_device(dev); - if (gdk_device_get_source(dev) != GDK_SOURCE_KEYBOARD) { - dev = mouse; - mouse = keyboard; - keyboard = dev; - } - - window = gtk_widget_get_window(d->window); - if (keyboard != NULL) - if (gdk_device_grab(keyboard, window, - GDK_OWNERSHIP_WINDOW, TRUE, - GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK, - NULL, time) != GDK_GRAB_SUCCESS) - return FALSE; - if (mouse != NULL) - if (gdk_device_grab(mouse, window, - GDK_OWNERSHIP_WINDOW, TRUE, - GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK, - NULL, time) != GDK_GRAB_SUCCESS) { - if (keyboard != NULL) - gdk_device_ungrab(keyboard, time); - return FALSE; - } - - gtk_device_grab_add(d->window, mouse, TRUE); - d->keyboard = keyboard; - d->mouse = mouse; - return TRUE; -} - -// based on gtk_combo_box_list_position() in the GTK+ source code -static void allocationToScreen(dateTimePickerWidget *d, gint *x, gint *y) -{ - GdkWindow *window; - GtkAllocation a; - GtkRequisition aWin; - GdkScreen *screen; - GdkRectangle workarea; - int otherY; - - gtk_widget_get_allocation(GTK_WIDGET(d), &a); - gtk_widget_get_preferred_size(d->window, &aWin, NULL); - *x = 0; - *y = 0; - if (!gtk_widget_get_has_window(GTK_WIDGET(d))) { - *x = a.x; - *y = a.y; - } - window = gtk_widget_get_window(GTK_WIDGET(d)); - gdk_window_get_root_coords(window, *x, *y, x, y); - if (gtk_widget_get_direction(GTK_WIDGET(d)) == GTK_TEXT_DIR_RTL) - *x += a.width - aWin.width; - - // now adjust to prevent the box from going offscreen - screen = gtk_widget_get_screen(GTK_WIDGET(d)); - gdk_screen_get_monitor_workarea(screen, - gdk_screen_get_monitor_at_window(screen, window), - &workarea); - if (*x < workarea.x) // too far to the left? - *x = workarea.x; - else if (*x + aWin.width > (workarea.x + workarea.width)) // too far to the right? - *x = (workarea.x + workarea.width) - aWin.width; - // this isn't the same algorithm used by GtkComboBox - // first, get our two choices; *y for down and otherY for up - otherY = *y - aWin.height; - *y += a.height; - // and use otherY if we're too low - if (*y + aWin.height >= workarea.y + workarea.height) - *y = otherY; -} - -static void showPopup(dateTimePickerWidget *d) -{ - GtkWidget *toplevel; - gint x, y; - - // GtkComboBox does it - toplevel = gtk_widget_get_toplevel(GTK_WIDGET(d)); - if (GTK_IS_WINDOW(toplevel)) - gtk_window_group_add_window(gtk_window_get_group(GTK_WINDOW(toplevel)), GTK_WINDOW(d->window)); - - allocationToScreen(d, &x, &y); - gtk_window_move(GTK_WINDOW(d->window), x, y); - - gtk_widget_show(d->window); - setActive(d, TRUE); - - if (!startGrab(d)) - hidePopup(d); -} - -static void onToggled(GtkToggleButton *b, gpointer data) -{ - dateTimePickerWidget *d = dateTimePickerWidget(b); - - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(d))) - showPopup(d); - else - hidePopup(d); -} - -static gboolean grabBroken(GtkWidget *w, GdkEventGrabBroken *e, gpointer data) -{ - dateTimePickerWidget *d = dateTimePickerWidget(data); - - hidePopup(d); - return TRUE; // this is what GtkComboBox does -} - -static gboolean buttonReleased(GtkWidget *w, GdkEventButton *e, gpointer data) -{ - dateTimePickerWidget *d = dateTimePickerWidget(data); - int winx, winy; - GtkAllocation wina; - gboolean in; - - gtk_widget_get_allocation(d->window, &wina); - winx = 0; - winy = 0; - if (!gtk_widget_get_has_window(d->window)) { - winx = wina.x; - winy = wina.y; - } - gdk_window_get_root_coords(gtk_widget_get_window(d->window), winx, winy, &winx, &winy); - in = TRUE; - if (e->x_root < winx) - in = FALSE; - if (e->x_root >= (winx + wina.width)) - in = FALSE; - if (e->y_root < winy) - in = FALSE; - if (e->y_root >= (winy + wina.height)) - in = FALSE; - if (!in) - hidePopup(d); - return TRUE; // this is what GtkComboBox does -} - -static gint hoursSpinboxInput(GtkSpinButton *sb, gpointer ptr, gpointer data) -{ - double *out = (double *) ptr; - const gchar *text; - int value; - - text = gtk_entry_get_text(GTK_ENTRY(sb)); - value = (int) g_strtod(text, NULL); - if (value < 0 || value > 12) - return GTK_INPUT_ERROR; - if (value == 12) // 12 to the user is 0 internally - value = 0; - *out = (double) value; - return TRUE; -} - -static gboolean hoursSpinboxOutput(GtkSpinButton *sb, gpointer data) -{ - gchar *text; - int value; - - value = realSpinValue(sb); - if (value == 0) // 0 internally is 12 to the user - value = 12; - text = g_strdup_printf("%d", value); - gtk_entry_set_text(GTK_ENTRY(sb), text); - g_free(text); - return TRUE; -} - -static gboolean zeroPadSpinbox(GtkSpinButton *sb, gpointer data) -{ - gchar *text; - int value; - - value = realSpinValue(sb); - text = g_strdup_printf("%02d", value); - gtk_entry_set_text(GTK_ENTRY(sb), text); - g_free(text); - return TRUE; -} - -// this is really hacky but we can't use GtkCombobox here :( -static gint ampmSpinboxInput(GtkSpinButton *sb, gpointer ptr, gpointer data) -{ - double *out = (double *) ptr; - const gchar *text; - char firstAM, firstPM; - - text = gtk_entry_get_text(GTK_ENTRY(sb)); - // LONGTERM don't use ASCII here for case insensitivity - firstAM = g_ascii_tolower(nl_langinfo(AM_STR)[0]); - firstPM = g_ascii_tolower(nl_langinfo(PM_STR)[0]); - for (; *text != '\0'; text++) - if (g_ascii_tolower(*text) == firstAM) { - *out = 0; - return TRUE; - } else if (g_ascii_tolower(*text) == firstPM) { - *out = 1; - return TRUE; - } - return GTK_INPUT_ERROR; -} - -static gboolean ampmSpinboxOutput(GtkSpinButton *sb, gpointer data) -{ - int value; - - value = gtk_spin_button_get_value_as_int(sb); - if (value == 0) - gtk_entry_set_text(GTK_ENTRY(sb), nl_langinfo(AM_STR)); - else - gtk_entry_set_text(GTK_ENTRY(sb), nl_langinfo(PM_STR)); - return TRUE; -} - -static void spinboxChanged(GtkSpinButton *sb, gpointer data) -{ - dateTimePickerWidget *d = dateTimePickerWidget(data); - - dateTimeChanged(d); -} - -static GtkWidget *newSpinbox(dateTimePickerWidget *d, int min, int max, gint (*input)(GtkSpinButton *, gpointer, gpointer), gboolean (*output)(GtkSpinButton *, gpointer), gulong *block) -{ - GtkWidget *sb; - - sb = gtk_spin_button_new_with_range(min, max, 1); - gtk_spin_button_set_digits(GTK_SPIN_BUTTON(sb), 0); - gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(sb), TRUE); - gtk_orientable_set_orientation(GTK_ORIENTABLE(sb), GTK_ORIENTATION_VERTICAL); - *block = g_signal_connect(sb, "value-changed", G_CALLBACK(spinboxChanged), d); - if (input != NULL) - g_signal_connect(sb, "input", G_CALLBACK(input), NULL); - if (output != NULL) - g_signal_connect(sb, "output", G_CALLBACK(output), NULL); - return sb; -} - -static void dateChanged(GtkCalendar *c, gpointer data) -{ - dateTimePickerWidget *d = dateTimePickerWidget(data); - - dateTimeChanged(d); -} - -static void setDateOnly(dateTimePickerWidget *d) -{ - d->hasTime = FALSE; - gtk_container_remove(GTK_CONTAINER(d->box), d->timebox); -} - -static void setTimeOnly(dateTimePickerWidget *d) -{ - d->hasDate = FALSE; - gtk_container_remove(GTK_CONTAINER(d->box), d->calendar); -} - -static void dateTimePickerWidget_init(dateTimePickerWidget *d) -{ - GDateTime *dt; - gint year, month, day; - gint hour; - gulong calendarBlock; - - d->window = gtk_window_new(GTK_WINDOW_POPUP); - gtk_window_set_resizable(GTK_WINDOW(d->window), FALSE); - gtk_window_set_attached_to(GTK_WINDOW(d->window), GTK_WIDGET(d)); - gtk_window_set_decorated(GTK_WINDOW(d->window), FALSE); - gtk_window_set_deletable(GTK_WINDOW(d->window), FALSE); - gtk_window_set_type_hint(GTK_WINDOW(d->window), GDK_WINDOW_TYPE_HINT_COMBO); - gtk_window_set_skip_taskbar_hint(GTK_WINDOW(d->window), TRUE); - gtk_window_set_skip_pager_hint(GTK_WINDOW(d->window), TRUE); - gtk_window_set_has_resize_grip(GTK_WINDOW(d->window), FALSE); - gtk_container_set_border_width(GTK_CONTAINER(d->window), 12); - // and make it stand out a bit - gtk_style_context_add_class(gtk_widget_get_style_context(d->window), "frame"); - - d->box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6); - gtk_container_add(GTK_CONTAINER(d->window), d->box); - - d->calendar = gtk_calendar_new(); - calendarBlock = g_signal_connect(d->calendar, "day-selected", G_CALLBACK(dateChanged), d); - gtk_container_add(GTK_CONTAINER(d->box), d->calendar); - - d->timebox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6); - gtk_widget_set_valign(d->timebox, GTK_ALIGN_CENTER); - gtk_container_add(GTK_CONTAINER(d->box), d->timebox); - - d->hours = newSpinbox(d, 0, 11, hoursSpinboxInput, hoursSpinboxOutput, &(d->hoursBlock)); - gtk_container_add(GTK_CONTAINER(d->timebox), d->hours); - - gtk_container_add(GTK_CONTAINER(d->timebox), - gtk_label_new(":")); - - d->minutes = newSpinbox(d, 0, 59, NULL, zeroPadSpinbox, &(d->minutesBlock)); - gtk_container_add(GTK_CONTAINER(d->timebox), d->minutes); - - gtk_container_add(GTK_CONTAINER(d->timebox), - gtk_label_new(":")); - - d->seconds = newSpinbox(d, 0, 59, NULL, zeroPadSpinbox, &(d->secondsBlock)); - gtk_container_add(GTK_CONTAINER(d->timebox), d->seconds); - - // LONGTERM this should be the case, but that interferes with grabs - // switch to it when we can drop GTK+ 3.10 and use popovers -#if 0 - d->ampm = gtk_combo_box_text_new(); - gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(d->ampm), NULL, "AM"); - gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(d->ampm), NULL, "PM"); -#endif - d->ampm = newSpinbox(d, 0, 1, ampmSpinboxInput, ampmSpinboxOutput, &(d->ampmBlock)); - gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(d->ampm), FALSE); - gtk_widget_set_valign(d->ampm, GTK_ALIGN_CENTER); - gtk_container_add(GTK_CONTAINER(d->timebox), d->ampm); - - gtk_widget_show_all(d->box); - - g_signal_connect(d->window, "grab-broken-event", G_CALLBACK(grabBroken), d); - g_signal_connect(d->window, "button-release-event", G_CALLBACK(buttonReleased), d); - - d->toggledSignal = g_signal_connect(d, "toggled", G_CALLBACK(onToggled), NULL); - d->keyboard = NULL; - d->mouse = NULL; - - d->hasTime = TRUE; - d->hasDate = TRUE; - - // set the current date/time - // notice how we block signals from firing - dt = g_date_time_new_now_local(); - g_date_time_get_ymd(dt, &year, &month, &day); - month--; // GDateTime/GtkCalendar differences - g_signal_handler_block(d->calendar, calendarBlock); - gtk_calendar_select_month(GTK_CALENDAR(d->calendar), month, year); - gtk_calendar_select_day(GTK_CALENDAR(d->calendar), day); - g_signal_handler_unblock(d->calendar, calendarBlock); - hour = g_date_time_get_hour(dt); - if (hour >= 12) { - hour -= 12; - setRealSpinValue(GTK_SPIN_BUTTON(d->ampm), 1, d->ampmBlock); - } - setRealSpinValue(GTK_SPIN_BUTTON(d->hours), hour, d->hoursBlock); - setRealSpinValue(GTK_SPIN_BUTTON(d->minutes), g_date_time_get_minute(dt), d->minutesBlock); - setRealSpinValue(GTK_SPIN_BUTTON(d->seconds), g_date_time_get_seconds(dt), d->secondsBlock); - g_date_time_unref(dt); -} - -static void dateTimePickerWidget_dispose(GObject *obj) -{ - dateTimePickerWidget *d = dateTimePickerWidget(obj); - - if (d->window != NULL) { - gtk_widget_destroy(d->window); - d->window = NULL; - } - G_OBJECT_CLASS(dateTimePickerWidget_parent_class)->dispose(obj); -} - -static void dateTimePickerWidget_finalize(GObject *obj) -{ - G_OBJECT_CLASS(dateTimePickerWidget_parent_class)->finalize(obj); -} - -static void dateTimePickerWidget_class_init(dateTimePickerWidgetClass *class) -{ - G_OBJECT_CLASS(class)->dispose = dateTimePickerWidget_dispose; - G_OBJECT_CLASS(class)->finalize = dateTimePickerWidget_finalize; -} - -static GtkWidget *newDTP(void) -{ - GtkWidget *w; - - w = GTK_WIDGET(g_object_new(dateTimePickerWidgetType, "label", "", NULL)); - setLabel(dateTimePickerWidget(w)); - return w; -} - -static GtkWidget *newDP(void) -{ - GtkWidget *w; - - w = GTK_WIDGET(g_object_new(dateTimePickerWidgetType, "label", "", NULL)); - setDateOnly(dateTimePickerWidget(w)); - setLabel(dateTimePickerWidget(w)); - return w; -} - -static GtkWidget *newTP(void) -{ - GtkWidget *w; - - w = GTK_WIDGET(g_object_new(dateTimePickerWidgetType, "label", "", NULL)); - setTimeOnly(dateTimePickerWidget(w)); - setLabel(dateTimePickerWidget(w)); - return w; -} - -struct uiDateTimePicker { - uiUnixControl c; - GtkWidget *widget; - dateTimePickerWidget *d; -}; - -uiUnixControlAllDefaults(uiDateTimePicker) - -uiDateTimePicker *finishNewDateTimePicker(GtkWidget *(*fn)(void)) -{ - uiDateTimePicker *d; - - uiUnixNewControl(uiDateTimePicker, d); - - d->widget = (*fn)(); - d->d = dateTimePickerWidget(d->widget); - - return d; -} - -uiDateTimePicker *uiNewDateTimePicker(void) -{ - return finishNewDateTimePicker(newDTP); -} - -uiDateTimePicker *uiNewDatePicker(void) -{ - return finishNewDateTimePicker(newDP); -} - -uiDateTimePicker *uiNewTimePicker(void) -{ - return finishNewDateTimePicker(newTP); -} diff --git a/src/libui_sdl/libui/unix/debug.c b/src/libui_sdl/libui/unix/debug.c deleted file mode 100644 index c948db6..0000000 --- a/src/libui_sdl/libui/unix/debug.c +++ /dev/null @@ -1,14 +0,0 @@ -// 13 may 2016 -#include "uipriv_unix.h" - -// LONGTERM don't halt on release builds - -void realbug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap) -{ - char *a, *b; - - a = g_strdup_printf("[libui] %s:%s:%s() %s", file, line, func, prefix); - b = g_strdup_vprintf(format, ap); - g_critical("%s%s", a, b); - G_BREAKPOINT(); -} diff --git a/src/libui_sdl/libui/unix/draw.c b/src/libui_sdl/libui/unix/draw.c deleted file mode 100644 index 5befcd3..0000000 --- a/src/libui_sdl/libui/unix/draw.c +++ /dev/null @@ -1,214 +0,0 @@ -// 6 september 2015 -#include "uipriv_unix.h" -#include "draw.h" - -uiDrawContext *newContext(cairo_t *cr) -{ - uiDrawContext *c; - - c = uiNew(uiDrawContext); - c->cr = cr; - return c; -} - -void freeContext(uiDrawContext *c) -{ - uiFree(c); -} - -static cairo_pattern_t *mkbrush(uiDrawBrush *b) -{ - cairo_pattern_t *pat; - size_t i; - - switch (b->Type) { - case uiDrawBrushTypeSolid: - pat = cairo_pattern_create_rgba(b->R, b->G, b->B, b->A); - break; - case uiDrawBrushTypeLinearGradient: - pat = cairo_pattern_create_linear(b->X0, b->Y0, b->X1, b->Y1); - break; - case uiDrawBrushTypeRadialGradient: - // make the start circle radius 0 to make it a point - pat = cairo_pattern_create_radial( - b->X0, b->Y0, 0, - b->X1, b->Y1, b->OuterRadius); - break; -// case uiDrawBrushTypeImage: - } - if (cairo_pattern_status(pat) != CAIRO_STATUS_SUCCESS) - implbug("error creating pattern in mkbrush(): %s", - cairo_status_to_string(cairo_pattern_status(pat))); - switch (b->Type) { - case uiDrawBrushTypeLinearGradient: - case uiDrawBrushTypeRadialGradient: - for (i = 0; i < b->NumStops; i++) - cairo_pattern_add_color_stop_rgba(pat, - b->Stops[i].Pos, - b->Stops[i].R, - b->Stops[i].G, - b->Stops[i].B, - b->Stops[i].A); - } - return pat; -} - -void uiDrawStroke(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b, uiDrawStrokeParams *p) -{ - cairo_pattern_t *pat; - - runPath(path, c->cr); - pat = mkbrush(b); - cairo_set_source(c->cr, pat); - switch (p->Cap) { - case uiDrawLineCapFlat: - cairo_set_line_cap(c->cr, CAIRO_LINE_CAP_BUTT); - break; - case uiDrawLineCapRound: - cairo_set_line_cap(c->cr, CAIRO_LINE_CAP_ROUND); - break; - case uiDrawLineCapSquare: - cairo_set_line_cap(c->cr, CAIRO_LINE_CAP_SQUARE); - break; - } - switch (p->Join) { - case uiDrawLineJoinMiter: - cairo_set_line_join(c->cr, CAIRO_LINE_JOIN_MITER); - cairo_set_miter_limit(c->cr, p->MiterLimit); - break; - case uiDrawLineJoinRound: - cairo_set_line_join(c->cr, CAIRO_LINE_JOIN_ROUND); - break; - case uiDrawLineJoinBevel: - cairo_set_line_join(c->cr, CAIRO_LINE_JOIN_BEVEL); - break; - } - cairo_set_line_width(c->cr, p->Thickness); - cairo_set_dash(c->cr, p->Dashes, p->NumDashes, p->DashPhase); - cairo_stroke(c->cr); - cairo_pattern_destroy(pat); -} - -void uiDrawFill(uiDrawContext *c, uiDrawPath *path, uiDrawBrush *b) -{ - cairo_pattern_t *pat; - - runPath(path, c->cr); - pat = mkbrush(b); - cairo_set_source(c->cr, pat); - switch (pathFillMode(path)) { - case uiDrawFillModeWinding: - cairo_set_fill_rule(c->cr, CAIRO_FILL_RULE_WINDING); - break; - case uiDrawFillModeAlternate: - cairo_set_fill_rule(c->cr, CAIRO_FILL_RULE_EVEN_ODD); - break; - } - cairo_fill(c->cr); - cairo_pattern_destroy(pat); -} - -void uiDrawTransform(uiDrawContext *c, uiDrawMatrix *m) -{ - cairo_matrix_t cm; - - m2c(m, &cm); - cairo_transform(c->cr, &cm); -} - -void uiDrawClip(uiDrawContext *c, uiDrawPath *path) -{ - runPath(path, c->cr); - switch (pathFillMode(path)) { - case uiDrawFillModeWinding: - cairo_set_fill_rule(c->cr, CAIRO_FILL_RULE_WINDING); - break; - case uiDrawFillModeAlternate: - cairo_set_fill_rule(c->cr, CAIRO_FILL_RULE_EVEN_ODD); - break; - } - cairo_clip(c->cr); -} - -void uiDrawSave(uiDrawContext *c) -{ - cairo_save(c->cr); -} - -void uiDrawRestore(uiDrawContext *c) -{ - cairo_restore(c->cr); -} - - -// bitmap API - -uiDrawBitmap* uiDrawNewBitmap(uiDrawContext* c, int width, int height, int alpha) -{ - uiDrawBitmap* bmp; - - bmp = uiNew(uiDrawBitmap); - - bmp->bmp = cairo_image_surface_create(alpha ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24, width, height); - if (cairo_surface_status(bmp->bmp) != CAIRO_STATUS_SUCCESS) - implbug("error creating bitmap: %s", - cairo_status_to_string(cairo_surface_status(bmp->bmp))); - - bmp->Width = width; - bmp->Height = height; - bmp->Stride = cairo_image_surface_get_stride(bmp->bmp); - - return bmp; -} - -void uiDrawBitmapUpdate(uiDrawBitmap* bmp, const void* data) -{ - const unsigned char* src = data; - unsigned char* dst = cairo_image_surface_get_data(bmp->bmp); - - if (bmp->Stride == bmp->Width*4) - { - // stride 'good', can just directly copy all the shit - memcpy(dst, src, bmp->Stride*bmp->Height); - } - else - { - int y; - for (y = 0; y < bmp->Height; y++) - { - memcpy(dst, src, bmp->Width*4); - src += bmp->Width*4; - dst += bmp->Stride; - } - } - - cairo_surface_mark_dirty(bmp->bmp); -} - -void uiDrawBitmapDraw(uiDrawContext* c, uiDrawBitmap* bmp, uiRect* srcrect, uiRect* dstrect, int filter) -{ - cairo_save(c->cr); - cairo_rectangle(c->cr, dstrect->X, dstrect->Y, dstrect->Width, dstrect->Height); - - cairo_translate(c->cr, dstrect->X, dstrect->Y); - if ((dstrect->Width != srcrect->Width) || (dstrect->Height != srcrect->Height)) - { - // scale shit if needed - double sx = dstrect->Width / (double)srcrect->Width; - double sy = dstrect->Height / (double)srcrect->Height; - cairo_scale(c->cr, sx, sy); - } - - cairo_set_source_surface(c->cr, bmp->bmp, -srcrect->X, -srcrect->Y); - cairo_pattern_set_filter(cairo_get_source(c->cr), filter ? CAIRO_FILTER_BILINEAR : CAIRO_FILTER_NEAREST); - cairo_clip(c->cr); - cairo_paint(c->cr); - - cairo_restore(c->cr); -} - -void uiDrawFreeBitmap(uiDrawBitmap* bmp) -{ - cairo_surface_destroy(bmp->bmp); - uiFree(bmp); -} diff --git a/src/libui_sdl/libui/unix/draw.h b/src/libui_sdl/libui/unix/draw.h deleted file mode 100644 index 869acd1..0000000 --- a/src/libui_sdl/libui/unix/draw.h +++ /dev/null @@ -1,21 +0,0 @@ -// 5 may 2016 - -// draw.c -struct uiDrawContext { - cairo_t *cr; -}; - -struct uiDrawBitmap { - int Width; - int Height; - int Stride; - - cairo_surface_t* bmp; -}; - -// drawpath.c -extern void runPath(uiDrawPath *p, cairo_t *cr); -extern uiDrawFillMode pathFillMode(uiDrawPath *path); - -// drawmatrix.c -extern void m2c(uiDrawMatrix *m, cairo_matrix_t *c); diff --git a/src/libui_sdl/libui/unix/drawmatrix.c b/src/libui_sdl/libui/unix/drawmatrix.c deleted file mode 100644 index f12b303..0000000 --- a/src/libui_sdl/libui/unix/drawmatrix.c +++ /dev/null @@ -1,115 +0,0 @@ -// 6 september 2015 -#include "uipriv_unix.h" -#include "draw.h" - -void m2c(uiDrawMatrix *m, cairo_matrix_t *c) -{ - c->xx = m->M11; - c->yx = m->M12; - c->xy = m->M21; - c->yy = m->M22; - c->x0 = m->M31; - c->y0 = m->M32; -} - -static void c2m(cairo_matrix_t *c, uiDrawMatrix *m) -{ - m->M11 = c->xx; - m->M12 = c->yx; - m->M21 = c->xy; - m->M22 = c->yy; - m->M31 = c->x0; - m->M32 = c->y0; -} - -void uiDrawMatrixTranslate(uiDrawMatrix *m, double x, double y) -{ - cairo_matrix_t c; - cairo_matrix_t tmp; - - m2c(m, &c); - cairo_matrix_init_translate(&tmp, x, y); - cairo_matrix_multiply(&c, &c, &tmp); - c2m(&c, m); -} - -void uiDrawMatrixScale(uiDrawMatrix *m, double xCenter, double yCenter, double x, double y) -{ - cairo_matrix_t c; - cairo_matrix_t tmp; - double xt, yt; - - m2c(m, &c); - xt = x; - yt = y; - scaleCenter(xCenter, yCenter, &xt, &yt); - cairo_matrix_init_translate(&tmp, xt, yt); - cairo_matrix_scale(&tmp, x, y); - cairo_matrix_translate(&tmp, -xt, -yt); - cairo_matrix_multiply(&c, &c, &tmp); - c2m(&c, m); -} - -void uiDrawMatrixRotate(uiDrawMatrix *m, double x, double y, double amount) -{ - cairo_matrix_t c; - cairo_matrix_t tmp; - - m2c(m, &c); - cairo_matrix_init_translate(&tmp, x, y); - cairo_matrix_rotate(&tmp, amount); - cairo_matrix_translate(&tmp, -x, -y); - cairo_matrix_multiply(&c, &c, &tmp); - c2m(&c, m); -} - -void uiDrawMatrixSkew(uiDrawMatrix *m, double x, double y, double xamount, double yamount) -{ - fallbackSkew(m, x, y, xamount, yamount); -} - -void uiDrawMatrixMultiply(uiDrawMatrix *dest, uiDrawMatrix *src) -{ - cairo_matrix_t c; - cairo_matrix_t d; - - m2c(dest, &c); - m2c(src, &d); - cairo_matrix_multiply(&c, &c, &d); - c2m(&c, dest); -} - -int uiDrawMatrixInvertible(uiDrawMatrix *m) -{ - cairo_matrix_t c; - - m2c(m, &c); - return cairo_matrix_invert(&c) == CAIRO_STATUS_SUCCESS; -} - -int uiDrawMatrixInvert(uiDrawMatrix *m) -{ - cairo_matrix_t c; - - m2c(m, &c); - if (cairo_matrix_invert(&c) != CAIRO_STATUS_SUCCESS) - return 0; - c2m(&c, m); - return 1; -} - -void uiDrawMatrixTransformPoint(uiDrawMatrix *m, double *x, double *y) -{ - cairo_matrix_t c; - - m2c(m, &c); - cairo_matrix_transform_point(&c, x, y); -} - -void uiDrawMatrixTransformSize(uiDrawMatrix *m, double *x, double *y) -{ - cairo_matrix_t c; - - m2c(m, &c); - cairo_matrix_transform_distance(&c, x, y); -} diff --git a/src/libui_sdl/libui/unix/drawpath.c b/src/libui_sdl/libui/unix/drawpath.c deleted file mode 100644 index a0165fb..0000000 --- a/src/libui_sdl/libui/unix/drawpath.c +++ /dev/null @@ -1,199 +0,0 @@ -// 6 september 2015 -#include "uipriv_unix.h" -#include "draw.h" - -struct uiDrawPath { - GArray *pieces; - uiDrawFillMode fillMode; - gboolean ended; -}; - -struct piece { - int type; - double d[8]; - int b; -}; - -enum { - newFigure, - newFigureArc, - lineTo, - arcTo, - bezierTo, - closeFigure, - addRect, -}; - -uiDrawPath *uiDrawNewPath(uiDrawFillMode mode) -{ - uiDrawPath *p; - - p = uiNew(uiDrawPath); - p->pieces = g_array_new(FALSE, TRUE, sizeof (struct piece)); - p->fillMode = mode; - return p; -} - -void uiDrawFreePath(uiDrawPath *p) -{ - g_array_free(p->pieces, TRUE); - uiFree(p); -} - -static void add(uiDrawPath *p, struct piece *piece) -{ - if (p->ended) - userbug("You cannot modify a uiDrawPath that has been ended. (path: %p)", p); - g_array_append_vals(p->pieces, piece, 1); -} - -void uiDrawPathNewFigure(uiDrawPath *p, double x, double y) -{ - struct piece piece; - - piece.type = newFigure; - piece.d[0] = x; - piece.d[1] = y; - add(p, &piece); -} - -void uiDrawPathNewFigureWithArc(uiDrawPath *p, double xCenter, double yCenter, double radius, double startAngle, double sweep, int negative) -{ - struct piece piece; - - if (sweep > 2 * uiPi) - sweep = 2 * uiPi; - piece.type = newFigureArc; - piece.d[0] = xCenter; - piece.d[1] = yCenter; - piece.d[2] = radius; - piece.d[3] = startAngle; - piece.d[4] = sweep; - piece.b = negative; - add(p, &piece); -} - -void uiDrawPathLineTo(uiDrawPath *p, double x, double y) -{ - struct piece piece; - - piece.type = lineTo; - piece.d[0] = x; - piece.d[1] = y; - add(p, &piece); -} - -void uiDrawPathArcTo(uiDrawPath *p, double xCenter, double yCenter, double radius, double startAngle, double sweep, int negative) -{ - struct piece piece; - - if (sweep > 2 * uiPi) - sweep = 2 * uiPi; - piece.type = arcTo; - piece.d[0] = xCenter; - piece.d[1] = yCenter; - piece.d[2] = radius; - piece.d[3] = startAngle; - piece.d[4] = sweep; - piece.b = negative; - add(p, &piece); -} - -void uiDrawPathBezierTo(uiDrawPath *p, double c1x, double c1y, double c2x, double c2y, double endX, double endY) -{ - struct piece piece; - - piece.type = bezierTo; - piece.d[0] = c1x; - piece.d[1] = c1y; - piece.d[2] = c2x; - piece.d[3] = c2y; - piece.d[4] = endX; - piece.d[5] = endY; - add(p, &piece); -} - -void uiDrawPathCloseFigure(uiDrawPath *p) -{ - struct piece piece; - - piece.type = closeFigure; - add(p, &piece); -} - -void uiDrawPathAddRectangle(uiDrawPath *p, double x, double y, double width, double height) -{ - struct piece piece; - - piece.type = addRect; - piece.d[0] = x; - piece.d[1] = y; - piece.d[2] = width; - piece.d[3] = height; - add(p, &piece); -} - -void uiDrawPathEnd(uiDrawPath *p) -{ - p->ended = TRUE; -} - -void runPath(uiDrawPath *p, cairo_t *cr) -{ - guint i; - struct piece *piece; - void (*arc)(cairo_t *, double, double, double, double, double); - - if (!p->ended) - userbug("You cannot draw with a uiDrawPath that has not been ended. (path: %p)", p); - cairo_new_path(cr); - for (i = 0; i < p->pieces->len; i++) { - piece = &g_array_index(p->pieces, struct piece, i); - switch (piece->type) { - case newFigure: - cairo_move_to(cr, piece->d[0], piece->d[1]); - break; - case newFigureArc: - cairo_new_sub_path(cr); - // fall through - case arcTo: - arc = cairo_arc; - if (piece->b) - arc = cairo_arc_negative; - (*arc)(cr, - piece->d[0], - piece->d[1], - piece->d[2], - piece->d[3], - piece->d[3] + piece->d[4]); - break; - case lineTo: - cairo_line_to(cr, piece->d[0], piece->d[1]); - break; - case bezierTo: - cairo_curve_to(cr, - piece->d[0], - piece->d[1], - piece->d[2], - piece->d[3], - piece->d[4], - piece->d[5]); - break; - case closeFigure: - cairo_close_path(cr); - break; - case addRect: - cairo_rectangle(cr, - piece->d[0], - piece->d[1], - piece->d[2], - piece->d[3]); - break; - } - } -} - -uiDrawFillMode pathFillMode(uiDrawPath *path) -{ - return path->fillMode; -} diff --git a/src/libui_sdl/libui/unix/drawtext.c b/src/libui_sdl/libui/unix/drawtext.c deleted file mode 100644 index 7078e1a..0000000 --- a/src/libui_sdl/libui/unix/drawtext.c +++ /dev/null @@ -1,293 +0,0 @@ -// 6 september 2015 -#include "uipriv_unix.h" -#include "draw.h" - -struct uiDrawFontFamilies { - PangoFontFamily **f; - int n; -}; - -uiDrawFontFamilies *uiDrawListFontFamilies(void) -{ - uiDrawFontFamilies *ff; - PangoFontMap *map; - - ff = uiNew(uiDrawFontFamilies); - map = pango_cairo_font_map_get_default(); - pango_font_map_list_families(map, &(ff->f), &(ff->n)); - // do not free map; it's a shared resource - return ff; -} - -int uiDrawFontFamiliesNumFamilies(uiDrawFontFamilies *ff) -{ - return ff->n; -} - -char *uiDrawFontFamiliesFamily(uiDrawFontFamilies *ff, int n) -{ - PangoFontFamily *f; - - f = ff->f[n]; - return uiUnixStrdupText(pango_font_family_get_name(f)); -} - -void uiDrawFreeFontFamilies(uiDrawFontFamilies *ff) -{ - g_free(ff->f); - uiFree(ff); -} - -struct uiDrawTextFont { - PangoFont *f; -}; - -uiDrawTextFont *mkTextFont(PangoFont *f, gboolean ref) -{ - uiDrawTextFont *font; - - font = uiNew(uiDrawTextFont); - font->f = f; - if (ref) - g_object_ref(font->f); - return font; -} - -static const PangoWeight pangoWeights[] = { - [uiDrawTextWeightThin] = PANGO_WEIGHT_THIN, - [uiDrawTextWeightUltraLight] = PANGO_WEIGHT_ULTRALIGHT, - [uiDrawTextWeightLight] = PANGO_WEIGHT_LIGHT, - [uiDrawTextWeightBook] = PANGO_WEIGHT_BOOK, - [uiDrawTextWeightNormal] = PANGO_WEIGHT_NORMAL, - [uiDrawTextWeightMedium] = PANGO_WEIGHT_MEDIUM, - [uiDrawTextWeightSemiBold] = PANGO_WEIGHT_SEMIBOLD, - [uiDrawTextWeightBold] = PANGO_WEIGHT_BOLD, - [uiDrawTextWeightUltraBold] = PANGO_WEIGHT_ULTRABOLD, - [uiDrawTextWeightHeavy] = PANGO_WEIGHT_HEAVY, - [uiDrawTextWeightUltraHeavy] = PANGO_WEIGHT_ULTRAHEAVY, -}; - -static const PangoStyle pangoItalics[] = { - [uiDrawTextItalicNormal] = PANGO_STYLE_NORMAL, - [uiDrawTextItalicOblique] = PANGO_STYLE_OBLIQUE, - [uiDrawTextItalicItalic] = PANGO_STYLE_ITALIC, -}; - -static const PangoStretch pangoStretches[] = { - [uiDrawTextStretchUltraCondensed] = PANGO_STRETCH_ULTRA_CONDENSED, - [uiDrawTextStretchExtraCondensed] = PANGO_STRETCH_EXTRA_CONDENSED, - [uiDrawTextStretchCondensed] = PANGO_STRETCH_CONDENSED, - [uiDrawTextStretchSemiCondensed] = PANGO_STRETCH_SEMI_CONDENSED, - [uiDrawTextStretchNormal] = PANGO_STRETCH_NORMAL, - [uiDrawTextStretchSemiExpanded] = PANGO_STRETCH_SEMI_EXPANDED, - [uiDrawTextStretchExpanded] = PANGO_STRETCH_EXPANDED, - [uiDrawTextStretchExtraExpanded] = PANGO_STRETCH_EXTRA_EXPANDED, - [uiDrawTextStretchUltraExpanded] = PANGO_STRETCH_ULTRA_EXPANDED, -}; - -// we need a context for a few things -// the documentation suggests creating cairo_t-specific, GdkScreen-specific, or even GtkWidget-specific contexts, but we can't really do that because we want our uiDrawTextFonts and uiDrawTextLayouts to be context-independent -// we could use pango_font_map_create_context(pango_cairo_font_map_get_default()) but that will ignore GDK-specific settings -// so let's use gdk_pango_context_get() instead; even though it's for the default screen only, it's good enough for us -#define mkGenericPangoCairoContext() (gdk_pango_context_get()) - -PangoFont *pangoDescToPangoFont(PangoFontDescription *pdesc) -{ - PangoFont *f; - PangoContext *context; - - // in this case, the context is necessary for the metrics to be correct - context = mkGenericPangoCairoContext(); - f = pango_font_map_load_font(pango_cairo_font_map_get_default(), context, pdesc); - if (f == NULL) { - // LONGTERM - g_error("[libui] no match in pangoDescToPangoFont(); report to andlabs"); - } - g_object_unref(context); - return f; -} - -uiDrawTextFont *uiDrawLoadClosestFont(const uiDrawTextFontDescriptor *desc) -{ - PangoFont *f; - PangoFontDescription *pdesc; - - pdesc = pango_font_description_new(); - pango_font_description_set_family(pdesc, - desc->Family); - pango_font_description_set_size(pdesc, - (gint) (desc->Size * PANGO_SCALE)); - pango_font_description_set_weight(pdesc, - pangoWeights[desc->Weight]); - pango_font_description_set_style(pdesc, - pangoItalics[desc->Italic]); - pango_font_description_set_stretch(pdesc, - pangoStretches[desc->Stretch]); - f = pangoDescToPangoFont(pdesc); - pango_font_description_free(pdesc); - return mkTextFont(f, FALSE); // we hold the initial reference; no need to ref -} - -void uiDrawFreeTextFont(uiDrawTextFont *font) -{ - g_object_unref(font->f); - uiFree(font); -} - -uintptr_t uiDrawTextFontHandle(uiDrawTextFont *font) -{ - return (uintptr_t) (font->f); -} - -void uiDrawTextFontDescribe(uiDrawTextFont *font, uiDrawTextFontDescriptor *desc) -{ - PangoFontDescription *pdesc; - - // this creates a copy; we free it later - pdesc = pango_font_describe(font->f); - - // TODO - - pango_font_description_free(pdesc); -} - -// See https://developer.gnome.org/pango/1.30/pango-Cairo-Rendering.html#pango-Cairo-Rendering.description -// Note that we convert to double before dividing to make sure the floating-point stuff is right -#define pangoToCairo(pango) (((double) (pango)) / PANGO_SCALE) -#define cairoToPango(cairo) ((gint) ((cairo) * PANGO_SCALE)) - -void uiDrawTextFontGetMetrics(uiDrawTextFont *font, uiDrawTextFontMetrics *metrics) -{ - PangoFontMetrics *pm; - - pm = pango_font_get_metrics(font->f, NULL); - metrics->Ascent = pangoToCairo(pango_font_metrics_get_ascent(pm)); - metrics->Descent = pangoToCairo(pango_font_metrics_get_descent(pm)); - // Pango doesn't seem to expose this :( Use 0 and hope for the best. - metrics->Leading = 0; - metrics->UnderlinePos = pangoToCairo(pango_font_metrics_get_underline_position(pm)); - metrics->UnderlineThickness = pangoToCairo(pango_font_metrics_get_underline_thickness(pm)); - pango_font_metrics_unref(pm); -} - -// note: PangoCairoLayouts are tied to a given cairo_t, so we can't store one in this device-independent structure -struct uiDrawTextLayout { - char *s; - ptrdiff_t *graphemes; - PangoFont *defaultFont; - double width; - PangoAttrList *attrs; -}; - -uiDrawTextLayout *uiDrawNewTextLayout(const char *text, uiDrawTextFont *defaultFont, double width) -{ - uiDrawTextLayout *layout; - PangoContext *context; - - layout = uiNew(uiDrawTextLayout); - layout->s = g_strdup(text); - context = mkGenericPangoCairoContext(); - layout->graphemes = graphemes(layout->s, context); - g_object_unref(context); - layout->defaultFont = defaultFont->f; - g_object_ref(layout->defaultFont); // retain a copy - uiDrawTextLayoutSetWidth(layout, width); - layout->attrs = pango_attr_list_new(); - return layout; -} - -void uiDrawFreeTextLayout(uiDrawTextLayout *layout) -{ - pango_attr_list_unref(layout->attrs); - g_object_unref(layout->defaultFont); - uiFree(layout->graphemes); - g_free(layout->s); - uiFree(layout); -} - -void uiDrawTextLayoutSetWidth(uiDrawTextLayout *layout, double width) -{ - layout->width = width; -} - -static void prepareLayout(uiDrawTextLayout *layout, PangoLayout *pl) -{ - PangoFontDescription *desc; - int width; - - pango_layout_set_text(pl, layout->s, -1); - - // again, this makes a copy - desc = pango_font_describe(layout->defaultFont); - // this is safe; the description is copied - pango_layout_set_font_description(pl, desc); - pango_font_description_free(desc); - - width = cairoToPango(layout->width); - if (layout->width < 0) - width = -1; - pango_layout_set_width(pl, width); - - pango_layout_set_attributes(pl, layout->attrs); -} - -void uiDrawTextLayoutExtents(uiDrawTextLayout *layout, double *width, double *height) -{ - PangoContext *context; - PangoLayout *pl; - PangoRectangle logical; - - // in this case, the context is necessary to create the layout - // the layout takes a ref on the context so we can unref it afterward - context = mkGenericPangoCairoContext(); - pl = pango_layout_new(context); - g_object_unref(context); - prepareLayout(layout, pl); - - pango_layout_get_extents(pl, NULL, &logical); - - g_object_unref(pl); - - *width = pangoToCairo(logical.width); - *height = pangoToCairo(logical.height); -} - -void uiDrawText(uiDrawContext *c, double x, double y, uiDrawTextLayout *layout) -{ - PangoLayout *pl; - - pl = pango_cairo_create_layout(c->cr); - prepareLayout(layout, pl); - - cairo_move_to(c->cr, x, y); - pango_cairo_show_layout(c->cr, pl); - - g_object_unref(pl); -} - -static void addAttr(uiDrawTextLayout *layout, PangoAttribute *attr, int startChar, int endChar) -{ - attr->start_index = layout->graphemes[startChar]; - attr->end_index = layout->graphemes[endChar]; - pango_attr_list_insert(layout->attrs, attr); - // pango_attr_list_insert() takes attr; we don't free it -} - -void uiDrawTextLayoutSetColor(uiDrawTextLayout *layout, int startChar, int endChar, double r, double g, double b, double a) -{ - PangoAttribute *attr; - guint16 rr, gg, bb, aa; - - rr = (guint16) (r * 65535); - gg = (guint16) (g * 65535); - bb = (guint16) (b * 65535); - aa = (guint16) (a * 65535); - - attr = pango_attr_foreground_new(rr, gg, bb); - addAttr(layout, attr, startChar, endChar); - - // TODO what if aa == 0? - attr = FUTURE_pango_attr_foreground_alpha_new(aa); - if (attr != NULL) - addAttr(layout, attr, startChar, endChar); -} diff --git a/src/libui_sdl/libui/unix/editablecombo.c b/src/libui_sdl/libui/unix/editablecombo.c deleted file mode 100644 index 7ee3829..0000000 --- a/src/libui_sdl/libui/unix/editablecombo.c +++ /dev/null @@ -1,79 +0,0 @@ -// 11 june 2015 -#include "uipriv_unix.h" - -struct uiEditableCombobox { - uiUnixControl c; - GtkWidget *widget; - GtkBin *bin; - GtkComboBox *combobox; - GtkComboBoxText *comboboxText; - void (*onChanged)(uiEditableCombobox *, void *); - void *onChangedData; - gulong onChangedSignal; -}; - -uiUnixControlAllDefaults(uiEditableCombobox) - -static void onChanged(GtkComboBox *cbox, gpointer data) -{ - uiEditableCombobox *c = uiEditableCombobox(data); - - (*(c->onChanged))(c, c->onChangedData); -} - -static void defaultOnChanged(uiEditableCombobox *c, void *data) -{ - // do nothing -} - -void uiEditableComboboxAppend(uiEditableCombobox *c, const char *text) -{ - gtk_combo_box_text_append(c->comboboxText, NULL, text); -} - -char *uiEditableComboboxText(uiEditableCombobox *c) -{ - char *s; - char *out; - - s = gtk_combo_box_text_get_active_text(c->comboboxText); - // s will always be non-NULL in the case of a combobox with an entry (according to the source code) - out = uiUnixStrdupText(s); - g_free(s); - return out; -} - -void uiEditableComboboxSetText(uiEditableCombobox *c, const char *text) -{ - GtkEntry *e; - - // we need to inhibit sending of ::changed because this WILL send a ::changed otherwise - g_signal_handler_block(c->combobox, c->onChangedSignal); - // since there isn't a gtk_combo_box_text_set_active_text()... - e = GTK_ENTRY(gtk_bin_get_child(c->bin)); - gtk_entry_set_text(e, text); - g_signal_handler_unblock(c->combobox, c->onChangedSignal); -} - -void uiEditableComboboxOnChanged(uiEditableCombobox *c, void (*f)(uiEditableCombobox *c, void *data), void *data) -{ - c->onChanged = f; - c->onChangedData = data; -} - -uiEditableCombobox *uiNewEditableCombobox(void) -{ - uiEditableCombobox *c; - - uiUnixNewControl(uiEditableCombobox, c); - - c->widget = gtk_combo_box_text_new_with_entry(); - c->bin = GTK_BIN(c->widget); - c->combobox = GTK_COMBO_BOX(c->widget); - c->comboboxText = GTK_COMBO_BOX_TEXT(c->widget); - - c->onChangedSignal = g_signal_connect(c->widget, "changed", G_CALLBACK(onChanged), c); - uiEditableComboboxOnChanged(c, defaultOnChanged, NULL); - - return c; -} diff --git a/src/libui_sdl/libui/unix/entry.c b/src/libui_sdl/libui/unix/entry.c deleted file mode 100644 index 4a9a1d0..0000000 --- a/src/libui_sdl/libui/unix/entry.c +++ /dev/null @@ -1,97 +0,0 @@ -// 11 june 2015 -#include "uipriv_unix.h" - -struct uiEntry { - uiUnixControl c; - GtkWidget *widget; - GtkEntry *entry; - GtkEditable *editable; - void (*onChanged)(uiEntry *, void *); - void *onChangedData; - gulong onChangedSignal; -}; - -uiUnixControlAllDefaults(uiEntry) - -static void onChanged(GtkEditable *editable, gpointer data) -{ - uiEntry *e = uiEntry(data); - - (*(e->onChanged))(e, e->onChangedData); -} - -static void defaultOnChanged(uiEntry *e, void *data) -{ - // do nothing -} - -char *uiEntryText(uiEntry *e) -{ - return uiUnixStrdupText(gtk_entry_get_text(e->entry)); -} - -void uiEntrySetText(uiEntry *e, const char *text) -{ - // we need to inhibit sending of ::changed because this WILL send a ::changed otherwise - g_signal_handler_block(e->editable, e->onChangedSignal); - gtk_entry_set_text(e->entry, text); - g_signal_handler_unblock(e->editable, e->onChangedSignal); - // don't queue the control for resize; entry sizes are independent of their contents -} - -void uiEntryOnChanged(uiEntry *e, void (*f)(uiEntry *, void *), void *data) -{ - e->onChanged = f; - e->onChangedData = data; -} - -int uiEntryReadOnly(uiEntry *e) -{ - return gtk_editable_get_editable(e->editable) == FALSE; -} - -void uiEntrySetReadOnly(uiEntry *e, int readonly) -{ - gboolean editable; - - editable = TRUE; - if (readonly) - editable = FALSE; - gtk_editable_set_editable(e->editable, editable); -} - -static uiEntry *finishNewEntry(GtkWidget *w, const gchar *signal) -{ - uiEntry *e; - - uiUnixNewControl(uiEntry, e); - - e->widget = w; - e->entry = GTK_ENTRY(e->widget); - e->editable = GTK_EDITABLE(e->widget); - - e->onChangedSignal = g_signal_connect(e->widget, signal, G_CALLBACK(onChanged), e); - uiEntryOnChanged(e, defaultOnChanged, NULL); - - return e; -} - -uiEntry *uiNewEntry(void) -{ - return finishNewEntry(gtk_entry_new(), "changed"); -} - -uiEntry *uiNewPasswordEntry(void) -{ - GtkWidget *e; - - e = gtk_entry_new(); - gtk_entry_set_visibility(GTK_ENTRY(e), FALSE); - return finishNewEntry(e, "changed"); -} - -// TODO make it use a separate function to be type-safe -uiEntry *uiNewSearchEntry(void) -{ - return finishNewEntry(gtk_search_entry_new(), "search-changed"); -} diff --git a/src/libui_sdl/libui/unix/fontbutton.c b/src/libui_sdl/libui/unix/fontbutton.c deleted file mode 100644 index f8047e0..0000000 --- a/src/libui_sdl/libui/unix/fontbutton.c +++ /dev/null @@ -1,70 +0,0 @@ -// 14 april 2016 -#include "uipriv_unix.h" - -struct uiFontButton { - uiUnixControl c; - GtkWidget *widget; - GtkButton *button; - GtkFontButton *fb; - GtkFontChooser *fc; - void (*onChanged)(uiFontButton *, void *); - void *onChangedData; -}; - -uiUnixControlAllDefaults(uiFontButton) - -// TODO NOTE no need to inhibit the signal; font-set is documented as only being sent when the user changes the font -static void onFontSet(GtkFontButton *button, gpointer data) -{ - uiFontButton *b = uiFontButton(data); - - (*(b->onChanged))(b, b->onChangedData); -} - -static void defaultOnChanged(uiFontButton *b, void *data) -{ - // do nothing -} - -uiDrawTextFont *uiFontButtonFont(uiFontButton *b) -{ - PangoFont *f; - PangoFontDescription *desc; - - desc = gtk_font_chooser_get_font_desc(b->fc); - f = pangoDescToPangoFont(desc); - // desc is transfer-full and thus is a copy - pango_font_description_free(desc); - return mkTextFont(f, FALSE); // we hold the initial reference; no need to ref -} - -void uiFontButtonOnChanged(uiFontButton *b, void (*f)(uiFontButton *, void *), void *data) -{ - b->onChanged = f; - b->onChangedData = data; -} - -uiFontButton *uiNewFontButton(void) -{ - uiFontButton *b; - - uiUnixNewControl(uiFontButton, b); - - b->widget = gtk_font_button_new(); - b->button = GTK_BUTTON(b->widget); - b->fb = GTK_FONT_BUTTON(b->widget); - b->fc = GTK_FONT_CHOOSER(b->widget); - - // match behavior on other platforms - gtk_font_button_set_show_style(b->fb, TRUE); - gtk_font_button_set_show_size(b->fb, TRUE); - gtk_font_button_set_use_font(b->fb, FALSE); - gtk_font_button_set_use_size(b->fb, FALSE); - // other customizations - gtk_font_chooser_set_show_preview_entry(b->fc, TRUE); - - g_signal_connect(b->widget, "font-set", G_CALLBACK(onFontSet), b); - uiFontButtonOnChanged(b, defaultOnChanged, NULL); - - return b; -} diff --git a/src/libui_sdl/libui/unix/form.c b/src/libui_sdl/libui/unix/form.c deleted file mode 100644 index 54422b3..0000000 --- a/src/libui_sdl/libui/unix/form.c +++ /dev/null @@ -1,159 +0,0 @@ -// 8 june 2016 -#include "uipriv_unix.h" - -struct formChild { - uiControl *c; - int stretchy; - GtkWidget *label; - gboolean oldhexpand; - GtkAlign oldhalign; - gboolean oldvexpand; - GtkAlign oldvalign; - GBinding *labelBinding; -}; - -struct uiForm { - uiUnixControl c; - GtkWidget *widget; - GtkContainer *container; - GtkGrid *grid; - GArray *children; - int padded; - GtkSizeGroup *stretchygroup; // ensures all stretchy controls have the same size -}; - -uiUnixControlAllDefaultsExceptDestroy(uiForm) - -#define ctrl(f, i) &g_array_index(f->children, struct formChild, i) - -static void uiFormDestroy(uiControl *c) -{ - uiForm *f = uiForm(c); - struct formChild *fc; - guint i; - - // kill the size group - g_object_unref(f->stretchygroup); - // free all controls - for (i = 0; i < f->children->len; i++) { - fc = ctrl(f, i); - uiControlSetParent(fc->c, NULL); - uiUnixControlSetContainer(uiUnixControl(fc->c), f->container, TRUE); - uiControlDestroy(fc->c); - gtk_widget_destroy(fc->label); - } - g_array_free(f->children, TRUE); - // and then ourselves - g_object_unref(f->widget); - uiFreeControl(uiControl(f)); -} - -void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy) -{ - struct formChild fc; - GtkWidget *widget; - guint row; - - fc.c = c; - widget = GTK_WIDGET(uiControlHandle(fc.c)); - fc.stretchy = stretchy; - fc.oldhexpand = gtk_widget_get_hexpand(widget); - fc.oldhalign = gtk_widget_get_halign(widget); - fc.oldvexpand = gtk_widget_get_vexpand(widget); - fc.oldvalign = gtk_widget_get_valign(widget); - - if (stretchy) { - gtk_widget_set_vexpand(widget, TRUE); - gtk_widget_set_valign(widget, GTK_ALIGN_FILL); - gtk_size_group_add_widget(f->stretchygroup, widget); - } else - gtk_widget_set_vexpand(widget, FALSE); - // and make them fill horizontally - gtk_widget_set_hexpand(widget, TRUE); - gtk_widget_set_halign(widget, GTK_ALIGN_FILL); - - fc.label = gtk_label_new(label); - gtk_widget_set_hexpand(fc.label, FALSE); - gtk_widget_set_halign(fc.label, GTK_ALIGN_END); - gtk_widget_set_vexpand(fc.label, FALSE); - if (GTK_IS_SCROLLED_WINDOW(widget)) - gtk_widget_set_valign(fc.label, GTK_ALIGN_START); - else - gtk_widget_set_valign(fc.label, GTK_ALIGN_CENTER); - gtk_style_context_add_class(gtk_widget_get_style_context(fc.label), "dim-label"); - row = f->children->len; - gtk_grid_attach(f->grid, fc.label, - 0, row, - 1, 1); - // and make them share visibility so if the control is hidden, so is its label - fc.labelBinding = g_object_bind_property(GTK_WIDGET(uiControlHandle(fc.c)), "visible", - fc.label, "visible", - G_BINDING_SYNC_CREATE); - - uiControlSetParent(fc.c, uiControl(f)); - uiUnixControlSetContainer(uiUnixControl(fc.c), f->container, FALSE); - g_array_append_val(f->children, fc); - - // move the widget to the correct place - gtk_container_child_set(f->container, widget, - "left-attach", 1, - "top-attach", row, - NULL); -} - -void uiFormDelete(uiForm *f, int index) -{ - struct formChild *fc; - GtkWidget *widget; - - fc = ctrl(f, index); - widget = GTK_WIDGET(uiControlHandle(fc->c)); - - gtk_widget_destroy(fc->label); - - uiControlSetParent(fc->c, NULL); - uiUnixControlSetContainer(uiUnixControl(fc->c), f->container, TRUE); - - if (fc->stretchy) - gtk_size_group_remove_widget(f->stretchygroup, widget); - gtk_widget_set_hexpand(widget, fc->oldhexpand); - gtk_widget_set_halign(widget, fc->oldhalign); - gtk_widget_set_vexpand(widget, fc->oldvexpand); - gtk_widget_set_valign(widget, fc->oldvalign); - - g_array_remove_index(f->children, index); -} - -int uiFormPadded(uiForm *f) -{ - return f->padded; -} - -void uiFormSetPadded(uiForm *f, int padded) -{ - f->padded = padded; - if (f->padded) { - gtk_grid_set_row_spacing(f->grid, gtkYPadding); - gtk_grid_set_column_spacing(f->grid, gtkXPadding); - } else { - gtk_grid_set_row_spacing(f->grid, 0); - gtk_grid_set_column_spacing(f->grid, 0); - } -} - -uiForm *uiNewForm(void) -{ - uiForm *f; - - uiUnixNewControl(uiForm, f); - - f->widget = gtk_grid_new(); - f->container = GTK_CONTAINER(f->widget); - f->grid = GTK_GRID(f->widget); - - f->stretchygroup = gtk_size_group_new(GTK_SIZE_GROUP_VERTICAL); - - f->children = g_array_new(FALSE, TRUE, sizeof (struct formChild)); - - return f; -} diff --git a/src/libui_sdl/libui/unix/future.c b/src/libui_sdl/libui/unix/future.c deleted file mode 100644 index 1f9f532..0000000 --- a/src/libui_sdl/libui/unix/future.c +++ /dev/null @@ -1,42 +0,0 @@ -// 29 june 2016 -#include "uipriv_unix.h" - -// functions FROM THE FUTURE! -// in some cases, because being held back by LTS releases sucks :/ -// in others, because parts of GTK+ being unstable until recently also sucks :/ - -// added in pango 1.38; we need 1.36 -static PangoAttribute *(*newFGAlphaAttr)(guint16 alpha) = NULL; - -// added in GTK+ 3.20; we need 3.10 -static void (*gwpIterSetObjectName)(GtkWidgetPath *path, gint pos, const char *name) = NULL; - -// note that we treat any error as "the symbols aren't there" (and don't care if dlclose() failed) -void loadFutures(void) -{ - void *handle; - - // dlsym() walks the dependency chain, so opening the current process should be sufficient - handle = dlopen(NULL, RTLD_LAZY); - if (handle == NULL) - return; -#define GET(var, fn) *((void **) (&var)) = dlsym(handle, #fn) - GET(newFGAlphaAttr, pango_attr_foreground_alpha_new); - GET(gwpIterSetObjectName, gtk_widget_path_iter_set_object_name); - dlclose(handle); -} - -PangoAttribute *FUTURE_pango_attr_foreground_alpha_new(guint16 alpha) -{ - if (newFGAlphaAttr == NULL) - return NULL; - return (*newFGAlphaAttr)(alpha); -} - -gboolean FUTURE_gtk_widget_path_iter_set_object_name(GtkWidgetPath *path, gint pos, const char *name) -{ - if (gwpIterSetObjectName == NULL) - return FALSE; - (*gwpIterSetObjectName)(path, pos, name); - return TRUE; -} diff --git a/src/libui_sdl/libui/unix/gl.c b/src/libui_sdl/libui/unix/gl.c deleted file mode 100644 index e15cf4f..0000000 --- a/src/libui_sdl/libui/unix/gl.c +++ /dev/null @@ -1,251 +0,0 @@ -// 26 may 2019 -#include "uipriv_unix.h" - -#include -#include -#include - -extern GThread* gtkthread; -extern GMutex glmutex; - -struct uiGLContext -{ - GtkWidget* widget; - GdkWindow* window; - - GdkGLContext *gctx; - int vermaj, vermin; - - int width, height; - int scale; - GLuint renderbuffer[2][2]; - GLuint framebuffer[2]; - int backbuffer; -}; - -static void areaAllocRenderbuffer(uiGLContext* glctx); - -static PFNGLGENRENDERBUFFERSPROC _glGenRenderbuffers; -static PFNGLDELETERENDERBUFFERSPROC _glDeleteRenderbuffers; -static PFNGLBINDRENDERBUFFERPROC _glBindRenderbuffer; -static PFNGLRENDERBUFFERSTORAGEPROC _glRenderbufferStorage; -static PFNGLGETRENDERBUFFERPARAMETERIVPROC _glGetRenderbufferParameteriv; - -static PFNGLGENRENDERBUFFERSPROC _glGenFramebuffers; -static PFNGLDELETERENDERBUFFERSPROC _glDeleteFramebuffers; -static PFNGLBINDRENDERBUFFERPROC _glBindFramebuffer; -static PFNGLFRAMEBUFFERTEXTUREPROC _glFramebufferTexture; -static PFNGLFRAMEBUFFERRENDERBUFFERPROC _glFramebufferRenderbuffer; -static PFNGLCHECKFRAMEBUFFERSTATUSPROC _glCheckFramebufferStatus; - -static int _procsLoaded = 0; - -static void _loadGLProcs(GdkGLContext* glctx) -{ - if (_procsLoaded) return; - - _glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC)uiGLGetProcAddress("glGenRenderbuffers"); - _glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC)uiGLGetProcAddress("glDeleteRenderbuffers"); - _glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)uiGLGetProcAddress("glBindRenderbuffer"); - _glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC)uiGLGetProcAddress("glRenderbufferStorage"); - _glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC)uiGLGetProcAddress("glGetRenderbufferParameteriv"); - - _glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)uiGLGetProcAddress("glGenFramebuffers"); - _glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)uiGLGetProcAddress("glDeleteFramebuffers"); - _glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)uiGLGetProcAddress("glBindFramebuffer"); - _glFramebufferTexture = (PFNGLFRAMEBUFFERTEXTUREPROC)uiGLGetProcAddress("glFramebufferTexture"); - _glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC)uiGLGetProcAddress("glFramebufferRenderbuffer"); - _glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)uiGLGetProcAddress("glCheckFramebufferStatus"); - - _procsLoaded = 1; -} - -uiGLContext *createGLContext(GtkWidget* widget, int maj, int min) -{ - GdkWindow* gdkwin = gtk_widget_get_window(widget); - - GError* err = NULL; - GdkGLContext* gctx = gdk_window_create_gl_context(gdkwin, &err); - if (err != NULL || gctx == NULL) - { - return NULL; - } - - // TODO: make the set_use_es call conditional (#ifdef or smth) for older versions of gdk? - gdk_gl_context_set_use_es(gctx, FALSE); - gdk_gl_context_set_required_version(gctx, maj, min); - - gboolean res = gdk_gl_context_realize(gctx, &err); - if (err != NULL || res == FALSE) - { - return NULL; - } - - uiGLContext* ctx = uiNew(uiGLContext); - - GtkAllocation allocation; - gtk_widget_get_allocation(widget, &allocation); - int window_scale = gdk_window_get_scale_factor(gdkwin); - ctx->width = allocation.width; - ctx->height = allocation.height; - ctx->scale = window_scale; - - gdk_gl_context_make_current(gctx); - _loadGLProcs(gctx); - areaAllocRenderbuffer(ctx); - ctx->backbuffer = 0; - - ctx->widget = widget; - ctx->window = gdkwin; - ctx->gctx = gctx; - - return ctx; -} - -void freeGLContext(uiGLContext* glctx) -{ - if (glctx == NULL) return; - - gdk_gl_context_make_current(glctx->gctx); - _glDeleteRenderbuffers(4, &glctx->renderbuffer[0][0]); - _glDeleteFramebuffers(2, &glctx->framebuffer[0]); - - gdk_gl_context_clear_current(); - g_object_unref(glctx->gctx); - uiFree(glctx); -} - -static void areaAllocRenderbuffer(uiGLContext* glctx) -{ - // TODO: create textures as a fallback if GL_RGB renderbuffer isn't supported? - // they say GL implementations aren't required to support a GL_RGB renderbuffer - // however, a GL_RGBA one would cause gdk_cairo_draw_from_gl() to fall back to glReadPixels() - - _glGenRenderbuffers(4, &glctx->renderbuffer[0][0]); - _glGenFramebuffers(2, &glctx->framebuffer[0]); - - _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[0][0]); - _glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB, glctx->width*glctx->scale, glctx->height*glctx->scale); - //_glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[0][1]); - //_glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, glctx->width*glctx->scale, glctx->height*glctx->scale); - - _glBindFramebuffer(GL_FRAMEBUFFER, glctx->framebuffer[0]); - _glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, glctx->renderbuffer[0][0]); - _glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, glctx->renderbuffer[0][1]); - - _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[1][0]); - _glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB, glctx->width*glctx->scale, glctx->height*glctx->scale); - //_glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[1][1]); - //_glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, glctx->width*glctx->scale, glctx->height*glctx->scale); - - _glBindFramebuffer(GL_FRAMEBUFFER, glctx->framebuffer[1]); - _glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, glctx->renderbuffer[1][0]); - _glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, glctx->renderbuffer[1][1]); - - //if (_glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) - // printf("FRAMEBUFFER IS BAD!! %04X\n", _glCheckFramebufferStatus(GL_FRAMEBUFFER)); -} - -static void areaReallocRenderbuffer(uiGLContext* glctx) -{ - _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[0][0]); - _glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB, glctx->width*glctx->scale, glctx->height*glctx->scale); - //_glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[0][1]); - //_glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, glctx->width*glctx->scale, glctx->height*glctx->scale); - - _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[1][0]); - _glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB, glctx->width*glctx->scale, glctx->height*glctx->scale); - //_glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[1][1]); - //_glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, glctx->width*glctx->scale, glctx->height*glctx->scale); -} - -void areaDrawGL(GtkWidget* widget, uiAreaDrawParams* dp, cairo_t* cr, uiGLContext* glctx) -{ - int window_scale = gdk_window_get_scale_factor(glctx->window); - - if (glctx->width != dp->AreaWidth || glctx->height != dp->AreaHeight || glctx->scale != window_scale) - { - glctx->width = dp->AreaWidth; - glctx->height = dp->AreaHeight; - glctx->scale = window_scale; - areaReallocRenderbuffer(glctx); - } - else - { - gdk_cairo_draw_from_gl(cr, gtk_widget_get_window(widget), - glctx->renderbuffer[glctx->backbuffer][0], GL_RENDERBUFFER, - 1, 0, 0, glctx->width*glctx->scale, glctx->height*glctx->scale); - } -} - -int uiGLGetFramebuffer(uiGLContext* ctx) -{ - return ctx->framebuffer[ctx->backbuffer]; -} - -float uiGLGetFramebufferScale(uiGLContext* ctx) -{ - return (float)ctx->scale; -} - -void uiGLSwapBuffers(uiGLContext* ctx) -{ - ctx->backbuffer = ctx->backbuffer ? 0 : 1; -} - -void uiGLSetVSync(int sync) -{ - // TODO -} - -void uiGLMakeContextCurrent(uiGLContext* ctx) -{ - if (!ctx) - { - gdk_gl_context_clear_current(); - return; - } - - if (ctx->gctx == gdk_gl_context_get_current()) return; - gdk_gl_context_make_current(ctx->gctx); -} - -void uiGLBegin(uiGLContext* ctx) -{ - if (g_thread_self() != gtkthread) - { - g_mutex_lock(&glmutex); - } -} - -void uiGLEnd(uiGLContext* ctx) -{ - if (g_thread_self() != gtkthread) - { - g_mutex_unlock(&glmutex); - } -} - -void *uiGLGetProcAddress(const char* proc) -{ - // TODO: consider using epoxy or something funny - - void* ptr; - - ptr = glXGetProcAddressARB((const GLubyte*)proc); - if (ptr) return ptr; - - ptr = eglGetProcAddress(proc); - if (ptr) return ptr; - - ptr = dlsym(NULL /* RTLD_DEFAULT */, proc); - if (ptr) return ptr; - - return NULL; -} -unsigned int uiGLGetVersion(uiGLContext* ctx) -{ - if (!ctx) return 0; - return uiGLVersion(ctx->vermaj, ctx->vermin); -} - diff --git a/src/libui_sdl/libui/unix/graphemes.c b/src/libui_sdl/libui/unix/graphemes.c deleted file mode 100644 index a2c47b7..0000000 --- a/src/libui_sdl/libui/unix/graphemes.c +++ /dev/null @@ -1,31 +0,0 @@ -// 25 may 2016 -#include "uipriv_unix.h" - -ptrdiff_t *graphemes(const char *text, PangoContext *context) -{ - size_t len, lenchars; - PangoLogAttr *logattrs; - ptrdiff_t *out; - ptrdiff_t *op; - size_t i; - - len = strlen(text); - lenchars = g_utf8_strlen(text, -1); - logattrs = (PangoLogAttr *) uiAlloc((lenchars + 1) * sizeof (PangoLogAttr), "PangoLogAttr[]"); - pango_get_log_attrs(text, len, - -1, NULL, - logattrs, lenchars + 1); - - // should be more than enough - out = (ptrdiff_t *) uiAlloc((lenchars + 2) * sizeof (ptrdiff_t), "ptrdiff_t[]"); - op = out; - for (i = 0; i < lenchars; i++) - if (logattrs[i].is_cursor_position != 0) - // TODO optimize this - *op++ = g_utf8_offset_to_pointer(text, i) - text; - // and do the last one - *op++ = len; - - uiFree(logattrs); - return out; -} diff --git a/src/libui_sdl/libui/unix/grid.c b/src/libui_sdl/libui/unix/grid.c deleted file mode 100644 index 6d9813b..0000000 --- a/src/libui_sdl/libui/unix/grid.c +++ /dev/null @@ -1,141 +0,0 @@ -// 9 june 2016 -#include "uipriv_unix.h" - -struct gridChild { - uiControl *c; - GtkWidget *label; - gboolean oldhexpand; - GtkAlign oldhalign; - gboolean oldvexpand; - GtkAlign oldvalign; -}; - -struct uiGrid { - uiUnixControl c; - GtkWidget *widget; - GtkContainer *container; - GtkGrid *grid; - GArray *children; - int padded; -}; - -uiUnixControlAllDefaultsExceptDestroy(uiGrid) - -#define ctrl(g, i) &g_array_index(g->children, struct gridChild, i) - -static void uiGridDestroy(uiControl *c) -{ - uiGrid *g = uiGrid(c); - struct gridChild *gc; - guint i; - - // free all controls - for (i = 0; i < g->children->len; i++) { - gc = ctrl(g, i); - uiControlSetParent(gc->c, NULL); - uiUnixControlSetContainer(uiUnixControl(gc->c), g->container, TRUE); - uiControlDestroy(gc->c); - } - g_array_free(g->children, TRUE); - // and then ourselves - g_object_unref(g->widget); - uiFreeControl(uiControl(g)); -} - -#define TODO_MASSIVE_HACK(c) \ - if (!uiUnixControl(c)->addedBefore) { \ - g_object_ref_sink(GTK_WIDGET(uiControlHandle(uiControl(c)))); \ - gtk_widget_show(GTK_WIDGET(uiControlHandle(uiControl(c)))); \ - uiUnixControl(c)->addedBefore = TRUE; \ - } - -static const GtkAlign gtkAligns[] = { - [uiAlignFill] = GTK_ALIGN_FILL, - [uiAlignStart] = GTK_ALIGN_START, - [uiAlignCenter] = GTK_ALIGN_CENTER, - [uiAlignEnd] = GTK_ALIGN_END, -}; - -static const GtkPositionType gtkPositions[] = { - [uiAtLeading] = GTK_POS_LEFT, - [uiAtTop] = GTK_POS_TOP, - [uiAtTrailing] = GTK_POS_RIGHT, - [uiAtBottom] = GTK_POS_BOTTOM, -}; - -static GtkWidget *prepare(struct gridChild *gc, uiControl *c, int hexpand, uiAlign halign, int vexpand, uiAlign valign) -{ - GtkWidget *widget; - - gc->c = c; - widget = GTK_WIDGET(uiControlHandle(gc->c)); - gc->oldhexpand = gtk_widget_get_hexpand(widget); - gc->oldhalign = gtk_widget_get_halign(widget); - gc->oldvexpand = gtk_widget_get_vexpand(widget); - gc->oldvalign = gtk_widget_get_valign(widget); - gtk_widget_set_hexpand(widget, hexpand != 0); - gtk_widget_set_halign(widget, gtkAligns[halign]); - gtk_widget_set_vexpand(widget, vexpand != 0); - gtk_widget_set_valign(widget, gtkAligns[valign]); - return widget; -} - -void uiGridAppend(uiGrid *g, uiControl *c, int left, int top, int xspan, int yspan, int hexpand, uiAlign halign, int vexpand, uiAlign valign) -{ - struct gridChild gc; - GtkWidget *widget; - - widget = prepare(&gc, c, hexpand, halign, vexpand, valign); - uiControlSetParent(gc.c, uiControl(g)); - TODO_MASSIVE_HACK(uiUnixControl(gc.c)); - gtk_grid_attach(g->grid, widget, - left, top, - xspan, yspan); - g_array_append_val(g->children, gc); -} - -void uiGridInsertAt(uiGrid *g, uiControl *c, uiControl *existing, uiAt at, int xspan, int yspan, int hexpand, uiAlign halign, int vexpand, uiAlign valign) -{ - struct gridChild gc; - GtkWidget *widget; - - widget = prepare(&gc, c, hexpand, halign, vexpand, valign); - uiControlSetParent(gc.c, uiControl(g)); - TODO_MASSIVE_HACK(uiUnixControl(gc.c)); - gtk_grid_attach_next_to(g->grid, widget, - GTK_WIDGET(uiControlHandle(existing)), gtkPositions[at], - xspan, yspan); - g_array_append_val(g->children, gc); -} - -int uiGridPadded(uiGrid *g) -{ - return g->padded; -} - -void uiGridSetPadded(uiGrid *g, int padded) -{ - g->padded = padded; - if (g->padded) { - gtk_grid_set_row_spacing(g->grid, gtkYPadding); - gtk_grid_set_column_spacing(g->grid, gtkXPadding); - } else { - gtk_grid_set_row_spacing(g->grid, 0); - gtk_grid_set_column_spacing(g->grid, 0); - } -} - -uiGrid *uiNewGrid(void) -{ - uiGrid *g; - - uiUnixNewControl(uiGrid, g); - - g->widget = gtk_grid_new(); - g->container = GTK_CONTAINER(g->widget); - g->grid = GTK_GRID(g->widget); - - g->children = g_array_new(FALSE, TRUE, sizeof (struct gridChild)); - - return g; -} diff --git a/src/libui_sdl/libui/unix/group.c b/src/libui_sdl/libui/unix/group.c deleted file mode 100644 index 6238a1b..0000000 --- a/src/libui_sdl/libui/unix/group.c +++ /dev/null @@ -1,89 +0,0 @@ -// 11 june 2015 -#include "uipriv_unix.h" - -struct uiGroup { - uiUnixControl c; - GtkWidget *widget; - GtkContainer *container; - GtkBin *bin; - GtkFrame *frame; - - // unfortunately, even though a GtkFrame is a GtkBin, calling gtk_container_set_border_width() on it /includes/ the GtkFrame's label; we don't want tht - struct child *child; - - int margined; -}; - -uiUnixControlAllDefaultsExceptDestroy(uiGroup) - -static void uiGroupDestroy(uiControl *c) -{ - uiGroup *g = uiGroup(c); - - if (g->child != NULL) - childDestroy(g->child); - g_object_unref(g->widget); - uiFreeControl(uiControl(g)); -} - -char *uiGroupTitle(uiGroup *g) -{ - return uiUnixStrdupText(gtk_frame_get_label(g->frame)); -} - -void uiGroupSetTitle(uiGroup *g, const char *text) -{ - gtk_frame_set_label(g->frame, text); -} - -void uiGroupSetChild(uiGroup *g, uiControl *child) -{ - if (g->child != NULL) - childRemove(g->child); - g->child = newChildWithBox(child, uiControl(g), g->container, g->margined); -} - -int uiGroupMargined(uiGroup *g) -{ - return g->margined; -} - -void uiGroupSetMargined(uiGroup *g, int margined) -{ - g->margined = margined; - if (g->child != NULL) - childSetMargined(g->child, g->margined); -} - -uiGroup *uiNewGroup(const char *text) -{ - uiGroup *g; - gfloat yalign; - GtkLabel *label; - PangoAttribute *bold; - PangoAttrList *boldlist; - - uiUnixNewControl(uiGroup, g); - - g->widget = gtk_frame_new(text); - g->container = GTK_CONTAINER(g->widget); - g->bin = GTK_BIN(g->widget); - g->frame = GTK_FRAME(g->widget); - - // with GTK+, groupboxes by default have frames and slightly x-offset regular text - // they should have no frame and fully left-justified, bold text - // preserve default y-alignment - gtk_frame_get_label_align(g->frame, NULL, &yalign); - gtk_frame_set_label_align(g->frame, 0, yalign); - gtk_frame_set_shadow_type(g->frame, GTK_SHADOW_NONE); - label = GTK_LABEL(gtk_frame_get_label_widget(g->frame)); - // this is the boldness level used by GtkPrintUnixDialog - // (it technically uses "bold" but see pango's pango-enum-types.c for the name conversion; GType is weird) - bold = pango_attr_weight_new(PANGO_WEIGHT_BOLD); - boldlist = pango_attr_list_new(); - pango_attr_list_insert(boldlist, bold); - gtk_label_set_attributes(label, boldlist); - pango_attr_list_unref(boldlist); // thanks baedert in irc.gimp.net/#gtk+ - - return g; -} diff --git a/src/libui_sdl/libui/unix/image.c b/src/libui_sdl/libui/unix/image.c deleted file mode 100644 index a79e550..0000000 --- a/src/libui_sdl/libui/unix/image.c +++ /dev/null @@ -1,120 +0,0 @@ -// 27 june 2016 -#include "uipriv_unix.h" - -struct uiImage { - double width; - double height; - GPtrArray *images; -}; - -static void freeImageRep(gpointer item) -{ - cairo_surface_t *cs = (cairo_surface_t *) item; - unsigned char *buf; - - buf = cairo_image_surface_get_data(cs); - cairo_surface_destroy(cs); - uiFree(buf); -} - -uiImage *uiNewImage(double width, double height) -{ - uiImage *i; - - i = uiNew(uiImage); - i->width = width; - i->height = height; - i->images = g_ptr_array_new_with_free_func(freeImageRep); - return i; -} - -void uiFreeImage(uiImage *i) -{ - g_ptr_array_free(i->images, TRUE); - uiFree(i); -} - -void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, int pixelStride) -{ - cairo_surface_t *cs; - unsigned char *buf, *p; - uint8_t *src = (uint8_t *) pixels; - int cstride; - int y; - - cstride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, pixelWidth); - buf = (unsigned char *) uiAlloc((cstride * pixelHeight * 4) * sizeof (unsigned char), "unsigned char[]"); - p = buf; - for (y = 0; y < pixelStride * pixelHeight; y += pixelStride) { - memmove(p, src + y, cstride); - p += cstride; - } - cs = cairo_image_surface_create_for_data(buf, CAIRO_FORMAT_ARGB32, - pixelWidth, pixelHeight, - cstride); - if (cairo_surface_status(cs) != CAIRO_STATUS_SUCCESS) - /* TODO */; - cairo_surface_flush(cs); - g_ptr_array_add(i->images, cs); -} - -struct matcher { - cairo_surface_t *best; - int distX; - int distY; - int targetX; - int targetY; - gboolean foundLarger; -}; - -// TODO is this the right algorithm? -static void match(gpointer surface, gpointer data) -{ - cairo_surface_t *cs = (cairo_surface_t *) surface; - struct matcher *m = (struct matcher *) data; - int x, y; - int x2, y2; - - x = cairo_image_surface_get_width(cs); - y = cairo_image_surface_get_height(cs); - if (m->best == NULL) - goto writeMatch; - - if (x < m->targetX && y < m->targetY) - if (m->foundLarger) - // always prefer larger ones - return; - if (x >= m->targetX && y >= m->targetY && !m->foundLarger) - // we set foundLarger below - goto writeMatch; - - x2 = abs(m->targetX - x); - y2 = abs(m->targetY - y); - if (x2 < m->distX && y2 < m->distY) - goto writeMatch; - - // TODO weight one dimension? threshhold? - return; - -writeMatch: - // must set this here too; otherwise the first image will never have ths set - if (x >= m->targetX && y >= m->targetY && !m->foundLarger) - m->foundLarger = TRUE; - m->best = cs; - m->distX = abs(m->targetX - x); - m->distY = abs(m->targetY - y); -} - -cairo_surface_t *imageAppropriateSurface(uiImage *i, GtkWidget *w) -{ - struct matcher m; - - m.best = NULL; - m.distX = G_MAXINT; - m.distY = G_MAXINT; - m.targetX = i->width * gtk_widget_get_scale_factor(w); - m.targetY = i->height * gtk_widget_get_scale_factor(w); - m.foundLarger = FALSE; - g_ptr_array_foreach(i->images, match, &m); - return m.best; -} diff --git a/src/libui_sdl/libui/unix/label.c b/src/libui_sdl/libui/unix/label.c deleted file mode 100644 index b39fc7c..0000000 --- a/src/libui_sdl/libui/unix/label.c +++ /dev/null @@ -1,36 +0,0 @@ -// 11 june 2015 -#include "uipriv_unix.h" - -struct uiLabel { - uiUnixControl c; - GtkWidget *widget; - GtkMisc *misc; - GtkLabel *label; -}; - -uiUnixControlAllDefaults(uiLabel) - -char *uiLabelText(uiLabel *l) -{ - return uiUnixStrdupText(gtk_label_get_text(l->label)); -} - -void uiLabelSetText(uiLabel *l, const char *text) -{ - gtk_label_set_text(l->label, text); -} - -uiLabel *uiNewLabel(const char *text) -{ - uiLabel *l; - - uiUnixNewControl(uiLabel, l); - - l->widget = gtk_label_new(text); - l->misc = GTK_MISC(l->widget); - l->label = GTK_LABEL(l->widget); - - gtk_misc_set_alignment(l->misc, 0, 0); - - return l; -} diff --git a/src/libui_sdl/libui/unix/main.c b/src/libui_sdl/libui/unix/main.c deleted file mode 100644 index 516bd76..0000000 --- a/src/libui_sdl/libui/unix/main.c +++ /dev/null @@ -1,147 +0,0 @@ -// 6 april 2015 -#include "uipriv_unix.h" - -uiInitOptions options; - -// kind of a hack -GThread* gtkthread; -GMutex glmutex; - -static void _eventfilter(GdkEvent* evt, gpointer data) -{ - if (evt->type == GDK_EXPOSE) - { - g_mutex_lock(&glmutex); - gtk_main_do_event(evt); - g_mutex_unlock(&glmutex); - return; - } - - gtk_main_do_event(evt); -} - -static void _eventfilterdestroy(gpointer data) -{ - printf("DELET\n"); -} - -const char *uiInit(uiInitOptions *o) -{ - GError *err = NULL; - const char *msg; - - options = *o; - if (gtk_init_with_args(NULL, NULL, NULL, NULL, NULL, &err) == FALSE) { - msg = g_strdup(err->message); - g_error_free(err); - return msg; - } - initAlloc(); - loadFutures(); - - gtkthread = g_thread_self(); - g_mutex_init(&glmutex); - - GList* iconlist = NULL; - iconlist = g_list_append(iconlist, gdk_pixbuf_new_from_resource("/org/kuriboland/melonDS/icon/melon_16x16.png", NULL)); - iconlist = g_list_append(iconlist, gdk_pixbuf_new_from_resource("/org/kuriboland/melonDS/icon/melon_32x32.png", NULL)); - iconlist = g_list_append(iconlist, gdk_pixbuf_new_from_resource("/org/kuriboland/melonDS/icon/melon_48x48.png", NULL)); - iconlist = g_list_append(iconlist, gdk_pixbuf_new_from_resource("/org/kuriboland/melonDS/icon/melon_64x64.png", NULL)); - iconlist = g_list_append(iconlist, gdk_pixbuf_new_from_resource("/org/kuriboland/melonDS/icon/melon_128x128.png", NULL)); - - gtk_window_set_default_icon_list(iconlist); - - g_mutex_init(&glmutex); - - gdk_event_handler_set(_eventfilter, NULL, _eventfilterdestroy); - - return NULL; -} - -void uiUninit(void) -{ - uninitMenus(); - uninitAlloc(); -} - -void uiFreeInitError(const char *err) -{ - g_free((gpointer) err); -} - -static gboolean (*iteration)(gboolean) = NULL; - -void uiMain(void) -{ - iteration = gtk_main_iteration_do; - gtk_main(); -} - -static gboolean stepsQuit = FALSE; - -// the only difference is we ignore the return value from gtk_main_iteration_do(), since it will always be TRUE if gtk_main() was never called -// gtk_main_iteration_do() will still run the main loop regardless -static gboolean stepsIteration(gboolean block) -{ - gtk_main_iteration_do(block); - return stepsQuit; -} - -void uiMainSteps(void) -{ - iteration = stepsIteration; -} - -int uiMainStep(int wait) -{ - gboolean block; - - block = FALSE; - if (wait) - block = TRUE; - return (*iteration)(block) == FALSE; -} - -// gtk_main_quit() may run immediately, or it may wait for other pending events; "it depends" (thanks mclasen in irc.gimp.net/#gtk+) -// PostQuitMessage() on Windows always waits, so we must do so too -// we'll do it by using an idle callback -static gboolean quit(gpointer data) -{ - if (iteration == stepsIteration) - stepsQuit = TRUE; - // TODO run a gtk_main() here just to do the cleanup steps of syncing the clipboard and other stuff gtk_main() does before it returns - else - gtk_main_quit(); - return FALSE; -} - -void uiQuit(void) -{ - gdk_threads_add_idle(quit, NULL); -} - -struct queued { - void (*f)(void *); - void *data; -}; - -static gboolean doqueued(gpointer data) -{ - struct queued *q = (struct queued *) data; - - (*(q->f))(q->data); - g_free(q); - return FALSE; -} - -void uiQueueMain(void (*f)(void *data), void *data) -{ - struct queued *q; - - // we have to use g_new0()/g_free() because uiAlloc() is only safe to call on the main thread - // for some reason it didn't affect me, but it did affect krakjoe - q = g_new0(struct queued, 1); - q->f = f; - q->data = data; - gdk_threads_add_idle(doqueued, q); -} diff --git a/src/libui_sdl/libui/unix/menu.c b/src/libui_sdl/libui/unix/menu.c deleted file mode 100644 index d641426..0000000 --- a/src/libui_sdl/libui/unix/menu.c +++ /dev/null @@ -1,432 +0,0 @@ -// 23 april 2015 -#include "uipriv_unix.h" - -static GArray *menus = NULL; -static guint nmenus = 0; -static gboolean menusFinalized = FALSE; -static gboolean hasQuit = FALSE; -static gboolean hasPreferences = FALSE; -static gboolean hasAbout = FALSE; - -struct uiMenu { - char *name; - GArray *items; // []*uiMenuItem - gboolean ischild; - guint id; -}; - -struct uiMenuItem { - char *name; - int type; - void (*onClicked)(uiMenuItem *, uiWindow *, void *); - void *onClickedData; - GType gtype; // template for new instances; kept in sync with everything else - gboolean disabled; - gboolean checked; - GHashTable *windows; // map[GtkMenuItem]*menuItemWindow - uiMenu *popupchild; -}; - -struct menuItemWindow { - uiWindow *w; - gulong signal; -}; - -enum { - typeRegular, - typeCheckbox, - typeQuit, - typePreferences, - typeAbout, - typeSeparator, - typeSubmenu, -}; - -// we do NOT want programmatic updates to raise an ::activated signal -static void singleSetChecked(GtkCheckMenuItem *menuitem, gboolean checked, gulong signal) -{ - g_signal_handler_block(menuitem, signal); - gtk_check_menu_item_set_active(menuitem, checked); - g_signal_handler_unblock(menuitem, signal); -} - -static void setChecked(uiMenuItem *item, gboolean checked) -{ - GHashTableIter iter; - gpointer widget; - gpointer ww; - struct menuItemWindow *w; - - item->checked = checked; - g_hash_table_iter_init(&iter, item->windows); - while (g_hash_table_iter_next(&iter, &widget, &ww)) { - w = (struct menuItemWindow *) ww; - singleSetChecked(GTK_CHECK_MENU_ITEM(widget), item->checked, w->signal); - } -} - -static void onClicked(GtkMenuItem *menuitem, gpointer data) -{ - uiMenuItem *item = uiMenuItem(data); - struct menuItemWindow *w; - - // we need to manually update the checked states of all menu items if one changes - // notice that this is getting the checked state of the menu item that this signal is sent from - if (item->type == typeCheckbox) - setChecked(item, gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem))); - - w = (struct menuItemWindow *) g_hash_table_lookup(item->windows, menuitem); - (*(item->onClicked))(item, w->w, item->onClickedData); -} - -static void defaultOnClicked(uiMenuItem *item, uiWindow *w, void *data) -{ - // do nothing -} - -static void onQuitClicked(uiMenuItem *item, uiWindow *w, void *data) -{ - if (shouldQuit()) - uiQuit(); -} - -static void menuItemEnableDisable(uiMenuItem *item, gboolean enabled) -{ - GHashTableIter iter; - gpointer widget; - - item->disabled = !enabled; - g_hash_table_iter_init(&iter, item->windows); - while (g_hash_table_iter_next(&iter, &widget, NULL)) - gtk_widget_set_sensitive(GTK_WIDGET(widget), enabled); -} - -void uiMenuItemEnable(uiMenuItem *item) -{ - menuItemEnableDisable(item, TRUE); -} - -void uiMenuItemDisable(uiMenuItem *item) -{ - menuItemEnableDisable(item, FALSE); -} - -void uiMenuItemOnClicked(uiMenuItem *item, void (*f)(uiMenuItem *, uiWindow *, void *), void *data) -{ - if (item->type == typeQuit) - userbug("You cannot call uiMenuItemOnClicked() on a Quit item; use uiOnShouldQuit() instead."); - item->onClicked = f; - item->onClickedData = data; -} - -int uiMenuItemChecked(uiMenuItem *item) -{ - return item->checked != FALSE; -} - -void uiMenuItemSetChecked(uiMenuItem *item, int checked) -{ - gboolean c; - - // use explicit values - c = FALSE; - if (checked) - c = TRUE; - setChecked(item, c); -} - -static uiMenuItem *newItem(uiMenu *m, int type, const char *name) -{ - uiMenuItem *item; - - if (menusFinalized) - userbug("You cannot create a new menu item after menus have been finalized."); - - item = uiNew(uiMenuItem); - - g_array_append_val(m->items, item); - - item->type = type; - switch (item->type) { - case typeQuit: - item->name = g_strdup("Quit"); - break; - case typePreferences: - item->name = g_strdup("Preferences..."); - break; - case typeAbout: - item->name = g_strdup("About"); - break; - case typeSeparator: - break; - default: - item->name = g_strdup(name); - break; - } - - if (item->type == typeQuit) { - // can't call uiMenuItemOnClicked() here - item->onClicked = onQuitClicked; - item->onClickedData = NULL; - } else - uiMenuItemOnClicked(item, defaultOnClicked, NULL); - - switch (item->type) { - case typeCheckbox: - item->gtype = GTK_TYPE_CHECK_MENU_ITEM; - break; - case typeSeparator: - item->gtype = GTK_TYPE_SEPARATOR_MENU_ITEM; - break; - default: - item->gtype = GTK_TYPE_MENU_ITEM; - break; - } - - item->windows = g_hash_table_new(g_direct_hash, g_direct_equal); - item->popupchild = NULL; - - return item; -} - -uiMenuItem *uiMenuAppendSubmenu(uiMenu *m, uiMenu* child) -{ - uiMenuItem *item; - - if (menusFinalized) - userbug("You cannot create a new menu item after menus have been finalized."); - - item = uiNew(uiMenuItem); - - g_array_append_val(m->items, item); - - item->type = typeSubmenu; - item->name = child->name; - - uiMenuItemOnClicked(item, defaultOnClicked, NULL); - - // checkme - item->gtype = GTK_TYPE_MENU_ITEM; - - item->windows = g_hash_table_new(g_direct_hash, g_direct_equal); - item->popupchild = child; - child->ischild = TRUE; - - return item; -} - -uiMenuItem *uiMenuAppendItem(uiMenu *m, const char *name) -{ - return newItem(m, typeRegular, name); -} - -uiMenuItem *uiMenuAppendCheckItem(uiMenu *m, const char *name) -{ - return newItem(m, typeCheckbox, name); -} - -uiMenuItem *uiMenuAppendQuitItem(uiMenu *m) -{ - if (hasQuit) - userbug("You cannot have multiple Quit menu items in the same program."); - hasQuit = TRUE; - newItem(m, typeSeparator, NULL); - return newItem(m, typeQuit, NULL); -} - -uiMenuItem *uiMenuAppendPreferencesItem(uiMenu *m) -{ - if (hasPreferences) - userbug("You cannot have multiple Preferences menu items in the same program."); - hasPreferences = TRUE; - newItem(m, typeSeparator, NULL); - return newItem(m, typePreferences, NULL); -} - -uiMenuItem *uiMenuAppendAboutItem(uiMenu *m) -{ - if (hasAbout) - userbug("You cannot have multiple About menu items in the same program."); - hasAbout = TRUE; - newItem(m, typeSeparator, NULL); - return newItem(m, typeAbout, NULL); -} - -void uiMenuAppendSeparator(uiMenu *m) -{ - newItem(m, typeSeparator, NULL); -} - -uiMenu *uiNewMenu(const char *name) -{ - uiMenu *m; - - if (menusFinalized) - userbug("You cannot create a new menu after menus have been finalized."); - if (menus == NULL) - menus = g_array_new(FALSE, TRUE, sizeof (uiMenu *)); - - m = uiNew(uiMenu); - - g_array_append_val(menus, m); - m->id = nmenus; - nmenus++; - - m->name = g_strdup(name); - m->items = g_array_new(FALSE, TRUE, sizeof (uiMenuItem *)); - m->ischild = FALSE; - - return m; -} - -static void appendMenuItem(GtkMenuShell *submenu, uiMenuItem *item, uiWindow *w) -{ - GtkWidget *menuitem; - gulong signal; - struct menuItemWindow *ww; - - menuitem = g_object_new(item->gtype, NULL); - if (item->name != NULL) - gtk_menu_item_set_label(GTK_MENU_ITEM(menuitem), item->name); - if (item->type != typeSeparator) { - signal = g_signal_connect(menuitem, "activate", G_CALLBACK(onClicked), item); - gtk_widget_set_sensitive(menuitem, !item->disabled); - if (item->type == typeCheckbox) - singleSetChecked(GTK_CHECK_MENU_ITEM(menuitem), item->checked, signal); - } - gtk_menu_shell_append(submenu, menuitem); - - ww = uiNew(struct menuItemWindow); - ww->w = w; - ww->signal = signal; - g_hash_table_insert(item->windows, menuitem, ww); - - if (item->popupchild != NULL) - { - int j; - uiMenu* m; - GtkWidget *c_submenu; - - m = item->popupchild; - c_submenu = gtk_menu_new(); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), c_submenu); - for (j = 0; j < m->items->len; j++) - appendMenuItem(GTK_MENU_SHELL(c_submenu), g_array_index(m->items, uiMenuItem *, j), w); - } -} - -GtkWidget *makeMenubar(uiWindow *w) -{ - GtkWidget *menubar; - guint i, j; - uiMenu *m; - GtkWidget *menuitem; - GtkWidget *submenu; - - menusFinalized = TRUE; - - menubar = gtk_menu_bar_new(); - - if (menus != NULL) - for (i = 0; i < menus->len; i++) { - m = g_array_index(menus, uiMenu *, i); - if (m->ischild) continue; - menuitem = gtk_menu_item_new_with_label(m->name); - submenu = gtk_menu_new(); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu); - for (j = 0; j < m->items->len; j++) - appendMenuItem(GTK_MENU_SHELL(submenu), g_array_index(m->items, uiMenuItem *, j), w); - gtk_menu_shell_append(GTK_MENU_SHELL(menubar), menuitem); - } - - gtk_widget_set_hexpand(menubar, TRUE); - gtk_widget_set_halign(menubar, GTK_ALIGN_FILL); - return menubar; -} - -struct freeMenuItemData { - GArray *items; - guint i; - guint* parent_i; -}; - -static void freeMenu(GtkWidget *widget, gpointer data); - -static void freeMenuItem(GtkWidget *widget, gpointer data) -{ - struct freeMenuItemData *fmi = (struct freeMenuItemData *) data; - uiMenuItem *item; - struct menuItemWindow *w; - - item = g_array_index(fmi->items, uiMenuItem *, fmi->i); - if (item->popupchild != NULL) - freeMenu(widget, fmi->parent_i);//&item->popupchild->id); - w = (struct menuItemWindow *) g_hash_table_lookup(item->windows, widget); - if (g_hash_table_remove(item->windows, widget) == FALSE) - implbug("GtkMenuItem %p not in menu item's item/window map", widget); - uiFree(w); - fmi->i++; -} - -static void freeMenu(GtkWidget *widget, gpointer data) -{ - guint *i = (guint *) data; - uiMenu *m; - GtkMenuItem *item; - GtkWidget *submenu; - struct freeMenuItemData fmi; - - m = g_array_index(menus, uiMenu *, *i); - item = GTK_MENU_ITEM(widget); - submenu = gtk_menu_item_get_submenu(item); - fmi.items = m->items; - fmi.i = 0; - (*i)++; - fmi.parent_i = i; - gtk_container_foreach(GTK_CONTAINER(submenu), freeMenuItem, &fmi); - //(*i)++; -} - -void freeMenubar(GtkWidget *mb) -{ - guint i; - - i = 0; - gtk_container_foreach(GTK_CONTAINER(mb), freeMenu, &i); - // no need to worry about destroying any widgets; destruction of the window they're in will do it for us -} - -void _freeMenu(uiMenu* m) -{ - uiMenuItem *item; - guint j; - - g_free(m->name); - for (j = 0; j < m->items->len; j++) { - item = g_array_index(m->items, uiMenuItem *, j); - if (item->popupchild != NULL) _freeMenu(item->popupchild); - if (g_hash_table_size(item->windows) != 0) - // TODO is this really a userbug()? - implbug("menu item %p (%s) still has uiWindows attached; did you forget to destroy some windows?", item, item->name); - if (item->type != typeSubmenu) g_free(item->name); - g_hash_table_destroy(item->windows); - uiFree(item); - } - g_array_free(m->items, TRUE); - uiFree(m); -} - -void uninitMenus(void) -{ - uiMenu *m; - guint i; - - if (menus == NULL) - return; - for (i = 0; i < menus->len; i++) { - m = g_array_index(menus, uiMenu *, i); - if (m->ischild) continue; - _freeMenu(m); - } - g_array_free(menus, TRUE); -} diff --git a/src/libui_sdl/libui/unix/multilineentry.c b/src/libui_sdl/libui/unix/multilineentry.c deleted file mode 100644 index 09ffd46..0000000 --- a/src/libui_sdl/libui/unix/multilineentry.c +++ /dev/null @@ -1,124 +0,0 @@ -// 6 december 2015 -#include "uipriv_unix.h" - -struct uiMultilineEntry { - uiUnixControl c; - GtkWidget *widget; - GtkContainer *scontainer; - GtkScrolledWindow *sw; - GtkWidget *textviewWidget; - GtkTextView *textview; - GtkTextBuffer *textbuf; - void (*onChanged)(uiMultilineEntry *, void *); - void *onChangedData; - gulong onChangedSignal; -}; - -uiUnixControlAllDefaults(uiMultilineEntry) - -static void onChanged(GtkTextBuffer *textbuf, gpointer data) -{ - uiMultilineEntry *e = uiMultilineEntry(data); - - (*(e->onChanged))(e, e->onChangedData); -} - -static void defaultOnChanged(uiMultilineEntry *e, void *data) -{ - // do nothing -} - -char *uiMultilineEntryText(uiMultilineEntry *e) -{ - GtkTextIter start, end; - char *tret, *out; - - gtk_text_buffer_get_start_iter(e->textbuf, &start); - gtk_text_buffer_get_end_iter(e->textbuf, &end); - tret = gtk_text_buffer_get_text(e->textbuf, &start, &end, TRUE); - // theoretically we could just return tret because uiUnixStrdupText() is just g_strdup(), but if that ever changes we can't, so let's do it this way to be safe - out = uiUnixStrdupText(tret); - g_free(tret); - return out; -} - -void uiMultilineEntrySetText(uiMultilineEntry *e, const char *text) -{ - // we need to inhibit sending of ::changed because this WILL send a ::changed otherwise - g_signal_handler_block(e->textbuf, e->onChangedSignal); - gtk_text_buffer_set_text(e->textbuf, text, -1); - g_signal_handler_unblock(e->textbuf, e->onChangedSignal); -} - -// TODO scroll to end? -void uiMultilineEntryAppend(uiMultilineEntry *e, const char *text) -{ - GtkTextIter end; - - gtk_text_buffer_get_end_iter(e->textbuf, &end); - // we need to inhibit sending of ::changed because this WILL send a ::changed otherwise - g_signal_handler_block(e->textbuf, e->onChangedSignal); - gtk_text_buffer_insert(e->textbuf, &end, text, -1); - g_signal_handler_unblock(e->textbuf, e->onChangedSignal); -} - -void uiMultilineEntryOnChanged(uiMultilineEntry *e, void (*f)(uiMultilineEntry *e, void *data), void *data) -{ - e->onChanged = f; - e->onChangedData = data; -} - -int uiMultilineEntryReadOnly(uiMultilineEntry *e) -{ - return gtk_text_view_get_editable(e->textview) == FALSE; -} - -void uiMultilineEntrySetReadOnly(uiMultilineEntry *e, int readonly) -{ - gboolean editable; - - editable = TRUE; - if (readonly) - editable = FALSE; - gtk_text_view_set_editable(e->textview, editable); -} - -static uiMultilineEntry *finishMultilineEntry(GtkPolicyType hpolicy, GtkWrapMode wrapMode) -{ - uiMultilineEntry *e; - - uiUnixNewControl(uiMultilineEntry, e); - - e->widget = gtk_scrolled_window_new(NULL, NULL); - e->scontainer = GTK_CONTAINER(e->widget); - e->sw = GTK_SCROLLED_WINDOW(e->widget); - gtk_scrolled_window_set_policy(e->sw, - hpolicy, - GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(e->sw, GTK_SHADOW_IN); - - e->textviewWidget = gtk_text_view_new(); - e->textview = GTK_TEXT_VIEW(e->textviewWidget); - gtk_text_view_set_wrap_mode(e->textview, wrapMode); - - gtk_container_add(e->scontainer, e->textviewWidget); - // and make the text view visible; only the scrolled window's visibility is controlled by libui - gtk_widget_show(e->textviewWidget); - - e->textbuf = gtk_text_view_get_buffer(e->textview); - - e->onChangedSignal = g_signal_connect(e->textbuf, "changed", G_CALLBACK(onChanged), e); - uiMultilineEntryOnChanged(e, defaultOnChanged, NULL); - - return e; -} - -uiMultilineEntry *uiNewMultilineEntry(void) -{ - return finishMultilineEntry(GTK_POLICY_NEVER, GTK_WRAP_WORD); -} - -uiMultilineEntry *uiNewNonWrappingMultilineEntry(void) -{ - return finishMultilineEntry(GTK_POLICY_AUTOMATIC, GTK_WRAP_NONE); -} diff --git a/src/libui_sdl/libui/unix/progressbar.c b/src/libui_sdl/libui/unix/progressbar.c deleted file mode 100644 index 9b543b0..0000000 --- a/src/libui_sdl/libui/unix/progressbar.c +++ /dev/null @@ -1,71 +0,0 @@ -// 11 june 2015 -#include "uipriv_unix.h" - -struct uiProgressBar { - uiUnixControl c; - GtkWidget *widget; - GtkProgressBar *pbar; - gboolean indeterminate; - guint pulser; -}; - -uiUnixControlAllDefaultsExceptDestroy(uiProgressBar) - -static void uiProgressBarDestroy(uiControl *c) -{ - uiProgressBar *p = uiProgressBar(c); - - // be sure to stop the timeout now - if (p->indeterminate) - g_source_remove(p->pulser); - g_object_unref(p->widget); - uiFreeControl(uiControl(p)); -} - -int uiProgressBarValue(uiProgressBar *p) -{ - if (p->indeterminate) - return -1; - return (int) (gtk_progress_bar_get_fraction(p->pbar) * 100); -} - -static gboolean pulse(void* data) -{ - uiProgressBar *p = uiProgressBar(data); - - gtk_progress_bar_pulse(p->pbar); - return TRUE; -} - -void uiProgressBarSetValue(uiProgressBar *p, int value) -{ - if (value == -1) { - if (!p->indeterminate) { - p->indeterminate = TRUE; - // TODO verify the timeout - p->pulser = g_timeout_add(100, pulse, p); - } - return; - } - if (p->indeterminate) { - p->indeterminate = FALSE; - g_source_remove(p->pulser); - } - - if (value < 0 || value > 100) - userbug("Value %d is out of range for a uiProgressBar.", value); - - gtk_progress_bar_set_fraction(p->pbar, ((gdouble) value) / 100); -} - -uiProgressBar *uiNewProgressBar(void) -{ - uiProgressBar *p; - - uiUnixNewControl(uiProgressBar, p); - - p->widget = gtk_progress_bar_new(); - p->pbar = GTK_PROGRESS_BAR(p->widget); - - return p; -} diff --git a/src/libui_sdl/libui/unix/radiobuttons.c b/src/libui_sdl/libui/unix/radiobuttons.c deleted file mode 100644 index da41107..0000000 --- a/src/libui_sdl/libui/unix/radiobuttons.c +++ /dev/null @@ -1,121 +0,0 @@ -// 11 june 2015 -#include "uipriv_unix.h" - -// on GTK+ a uiRadioButtons is a GtkBox with each of the GtkRadioButtons as children - -struct uiRadioButtons { - uiUnixControl c; - GtkWidget *widget; - GtkContainer *container; - GtkBox *box; - GPtrArray *buttons; - void (*onSelected)(uiRadioButtons *, void *); - void *onSelectedData; - gboolean changing; -}; - -uiUnixControlAllDefaultsExceptDestroy(uiRadioButtons) - -static void defaultOnSelected(uiRadioButtons *r, void *data) -{ - // do nothing -} - -static void onToggled(GtkToggleButton *tb, gpointer data) -{ - uiRadioButtons *r = uiRadioButtons(data); - - // only care if a button is selected - if (!gtk_toggle_button_get_active(tb)) - return; - // ignore programmatic changes - if (r->changing) - return; - (*(r->onSelected))(r, r->onSelectedData); -} - -static void uiRadioButtonsDestroy(uiControl *c) -{ - uiRadioButtons *r = uiRadioButtons(c); - GtkWidget *b; - - while (r->buttons->len != 0) { - b = GTK_WIDGET(g_ptr_array_remove_index(r->buttons, 0)); - gtk_widget_destroy(b); - } - g_ptr_array_free(r->buttons, TRUE); - // and free ourselves - g_object_unref(r->widget); - uiFreeControl(uiControl(r)); -} - -void uiRadioButtonsAppend(uiRadioButtons *r, const char *text) -{ - GtkWidget *rb; - GtkRadioButton *previous; - - previous = NULL; - if (r->buttons->len > 0) - previous = GTK_RADIO_BUTTON(g_ptr_array_index(r->buttons, 0)); - rb = gtk_radio_button_new_with_label_from_widget(previous, text); - g_signal_connect(rb, "toggled", G_CALLBACK(onToggled), r); - gtk_container_add(r->container, rb); - g_ptr_array_add(r->buttons, rb); - gtk_widget_show(rb); -} - -int uiRadioButtonsSelected(uiRadioButtons *r) -{ - GtkToggleButton *tb; - guint i; - - for (i = 0; i < r->buttons->len; i++) { - tb = GTK_TOGGLE_BUTTON(g_ptr_array_index(r->buttons, i)); - if (gtk_toggle_button_get_active(tb)) - return i; - } - return -1; -} - -void uiRadioButtonsSetSelected(uiRadioButtons *r, int n) -{ - GtkToggleButton *tb; - gboolean active; - - active = TRUE; - // TODO this doesn't work - if (n == -1) { - n = uiRadioButtonsSelected(r); - if (n == -1) // no selection; keep it that way - return; - active = FALSE; - } - tb = GTK_TOGGLE_BUTTON(g_ptr_array_index(r->buttons, n)); - // this is easier than remembering all the signals - r->changing = TRUE; - gtk_toggle_button_set_active(tb, active); - r->changing = FALSE; -} - -void uiRadioButtonsOnSelected(uiRadioButtons *r, void (*f)(uiRadioButtons *, void *), void *data) -{ - r->onSelected = f; - r->onSelectedData = data; -} - -uiRadioButtons *uiNewRadioButtons(void) -{ - uiRadioButtons *r; - - uiUnixNewControl(uiRadioButtons, r); - - r->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); - r->container = GTK_CONTAINER(r->widget); - r->box = GTK_BOX(r->widget); - - r->buttons = g_ptr_array_new(); - - uiRadioButtonsOnSelected(r, defaultOnSelected, NULL); - - return r; -} diff --git a/src/libui_sdl/libui/unix/separator.c b/src/libui_sdl/libui/unix/separator.c deleted file mode 100644 index 02c75da..0000000 --- a/src/libui_sdl/libui/unix/separator.c +++ /dev/null @@ -1,34 +0,0 @@ -// 11 june 2015 -#include "uipriv_unix.h" - -struct uiSeparator { - uiUnixControl c; - GtkWidget *widget; - GtkSeparator *separator; -}; - -uiUnixControlAllDefaults(uiSeparator) - -uiSeparator *uiNewHorizontalSeparator(void) -{ - uiSeparator *s; - - uiUnixNewControl(uiSeparator, s); - - s->widget = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); - s->separator = GTK_SEPARATOR(s->widget); - - return s; -} - -uiSeparator *uiNewVerticalSeparator(void) -{ - uiSeparator *s; - - uiUnixNewControl(uiSeparator, s); - - s->widget = gtk_separator_new(GTK_ORIENTATION_VERTICAL); - s->separator = GTK_SEPARATOR(s->widget); - - return s; -} diff --git a/src/libui_sdl/libui/unix/slider.c b/src/libui_sdl/libui/unix/slider.c deleted file mode 100644 index 7f0cc24..0000000 --- a/src/libui_sdl/libui/unix/slider.c +++ /dev/null @@ -1,71 +0,0 @@ -// 11 june 2015 -#include "uipriv_unix.h" - -struct uiSlider { - uiUnixControl c; - GtkWidget *widget; - GtkRange *range; - GtkScale *scale; - void (*onChanged)(uiSlider *, void *); - void *onChangedData; - gulong onChangedSignal; -}; - -uiUnixControlAllDefaults(uiSlider) - -static void onChanged(GtkRange *range, gpointer data) -{ - uiSlider *s = uiSlider(data); - - (*(s->onChanged))(s, s->onChangedData); -} - -static void defaultOnChanged(uiSlider *s, void *data) -{ - // do nothing -} - -int uiSliderValue(uiSlider *s) -{ - return gtk_range_get_value(s->range); -} - -void uiSliderSetValue(uiSlider *s, int value) -{ - // we need to inhibit sending of ::value-changed because this WILL send a ::value-changed otherwise - g_signal_handler_block(s->range, s->onChangedSignal); - gtk_range_set_value(s->range, value); - g_signal_handler_unblock(s->range, s->onChangedSignal); -} - -void uiSliderOnChanged(uiSlider *s, void (*f)(uiSlider *, void *), void *data) -{ - s->onChanged = f; - s->onChangedData = data; -} - -uiSlider *uiNewSlider(int min, int max) -{ - uiSlider *s; - int temp; - - if (min >= max) { - temp = min; - min = max; - max = temp; - } - - uiUnixNewControl(uiSlider, s); - - s->widget = gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, min, max, 1); - s->range = GTK_RANGE(s->widget); - s->scale = GTK_SCALE(s->widget); - - // ensure integers, just to be safe - gtk_scale_set_digits(s->scale, 0); - - s->onChangedSignal = g_signal_connect(s->scale, "value-changed", G_CALLBACK(onChanged), s); - uiSliderOnChanged(s, defaultOnChanged, NULL); - - return s; -} diff --git a/src/libui_sdl/libui/unix/spinbox.c b/src/libui_sdl/libui/unix/spinbox.c deleted file mode 100644 index 90a5d3c..0000000 --- a/src/libui_sdl/libui/unix/spinbox.c +++ /dev/null @@ -1,72 +0,0 @@ -// 11 june 2015 -#include "uipriv_unix.h" - -struct uiSpinbox { - uiUnixControl c; - GtkWidget *widget; - GtkEntry *entry; - GtkSpinButton *spinButton; - void (*onChanged)(uiSpinbox *, void *); - void *onChangedData; - gulong onChangedSignal; -}; - -uiUnixControlAllDefaults(uiSpinbox) - -static void onChanged(GtkSpinButton *sb, gpointer data) -{ - uiSpinbox *s = uiSpinbox(data); - - (*(s->onChanged))(s, s->onChangedData); -} - -static void defaultOnChanged(uiSpinbox *s, void *data) -{ - // do nothing -} - -int uiSpinboxValue(uiSpinbox *s) -{ - return gtk_spin_button_get_value(s->spinButton); -} - -void uiSpinboxSetValue(uiSpinbox *s, int value) -{ - // we need to inhibit sending of ::value-changed because this WILL send a ::value-changed otherwise - g_signal_handler_block(s->spinButton, s->onChangedSignal); - // this clamps for us - gtk_spin_button_set_value(s->spinButton, (gdouble) value); - g_signal_handler_unblock(s->spinButton, s->onChangedSignal); -} - -void uiSpinboxOnChanged(uiSpinbox *s, void (*f)(uiSpinbox *, void *), void *data) -{ - s->onChanged = f; - s->onChangedData = data; -} - -uiSpinbox *uiNewSpinbox(int min, int max) -{ - uiSpinbox *s; - int temp; - - if (min >= max) { - temp = min; - min = max; - max = temp; - } - - uiUnixNewControl(uiSpinbox, s); - - s->widget = gtk_spin_button_new_with_range(min, max, 1); - s->entry = GTK_ENTRY(s->widget); - s->spinButton = GTK_SPIN_BUTTON(s->widget); - - // ensure integers, just to be safe - gtk_spin_button_set_digits(s->spinButton, 0); - - s->onChangedSignal = g_signal_connect(s->spinButton, "value-changed", G_CALLBACK(onChanged), s); - uiSpinboxOnChanged(s, defaultOnChanged, NULL); - - return s; -} diff --git a/src/libui_sdl/libui/unix/stddialogs.c b/src/libui_sdl/libui/unix/stddialogs.c deleted file mode 100644 index 3daeffa..0000000 --- a/src/libui_sdl/libui/unix/stddialogs.c +++ /dev/null @@ -1,116 +0,0 @@ -// 26 june 2015 -#include "uipriv_unix.h" - -// LONGTERM figure out why, and describe, that this is the desired behavior -// LONGTERM also point out that font and color buttons also work like this - -#define windowWindow(w) ((w)?(GTK_WINDOW(uiControlHandle(uiControl(w)))):NULL) - -static char *filedialog(GtkWindow *parent, GtkFileChooserAction mode, const gchar *confirm, const char* filter, const char* initpath) -{ - GtkWidget *fcd; - GtkFileChooser *fc; - gint response; - char *filename; - - fcd = gtk_file_chooser_dialog_new(NULL, parent, mode, - "_Cancel", GTK_RESPONSE_CANCEL, - confirm, GTK_RESPONSE_ACCEPT, - NULL); - fc = GTK_FILE_CHOOSER(fcd); - - // filters - { - gchar _filter[256]; - gchar* fp = &_filter[0]; int s = 0; - gchar* fname; - for (int i = 0; i < 255; i++) - { - if (filter[i] == '|' || filter[i] == '\0') - { - _filter[i] = '\0'; - if (s & 1) - { - GtkFileFilter* filter = gtk_file_filter_new(); - gtk_file_filter_set_name(filter, fname); - - for (gchar* j = fp; ; j++) - { - if (*j == ';') - { - *j = '\0'; - gtk_file_filter_add_pattern(filter, fp); - fp = j+1; - } - else if (*j == '\0') - { - gtk_file_filter_add_pattern(filter, fp); - break; - } - } - - gtk_file_chooser_add_filter(fc, filter); - } - else - { - fname = fp; - } - fp = &_filter[i+1]; - s++; - if (s >= 8) break; - if (filter[i] == '\0') break; - } - else - _filter[i] = filter[i]; - } - } - - gtk_file_chooser_set_local_only(fc, FALSE); - gtk_file_chooser_set_select_multiple(fc, FALSE); - gtk_file_chooser_set_show_hidden(fc, TRUE); - gtk_file_chooser_set_do_overwrite_confirmation(fc, TRUE); - gtk_file_chooser_set_create_folders(fc, TRUE); - if (initpath && strlen(initpath)>0) - gtk_file_chooser_set_current_folder(fc, initpath); - - response = gtk_dialog_run(GTK_DIALOG(fcd)); - if (response != GTK_RESPONSE_ACCEPT) { - gtk_widget_destroy(fcd); - return NULL; - } - filename = uiUnixStrdupText(gtk_file_chooser_get_filename(fc)); - gtk_widget_destroy(fcd); - return filename; -} - -char *uiOpenFile(uiWindow *parent, const char* filter, const char* initpath) -{ - return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_OPEN, "_Open", filter, initpath); -} - -char *uiSaveFile(uiWindow *parent, const char* filter, const char* initpath) -{ - return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_SAVE, "_Save", filter, initpath); -} - -static void msgbox(GtkWindow *parent, const char *title, const char *description, GtkMessageType type, GtkButtonsType buttons) -{ - GtkWidget *md; - - md = gtk_message_dialog_new(parent, GTK_DIALOG_MODAL, - type, buttons, - "%s", title); - gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(md), "%s", description); - gtk_dialog_run(GTK_DIALOG(md)); - gtk_widget_destroy(md); -} - -void uiMsgBox(uiWindow *parent, const char *title, const char *description) -{ - msgbox(windowWindow(parent), title, description, GTK_MESSAGE_OTHER, GTK_BUTTONS_OK); -} - -void uiMsgBoxError(uiWindow *parent, const char *title, const char *description) -{ - msgbox(windowWindow(parent), title, description, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK); -} diff --git a/src/libui_sdl/libui/unix/tab.c b/src/libui_sdl/libui/unix/tab.c deleted file mode 100644 index 552e0e3..0000000 --- a/src/libui_sdl/libui/unix/tab.c +++ /dev/null @@ -1,97 +0,0 @@ -// 11 june 2015 -#include "uipriv_unix.h" - -struct uiTab { - uiUnixControl c; - - GtkWidget *widget; - GtkContainer *container; - GtkNotebook *notebook; - - GArray *pages; // []*struct child -}; - -uiUnixControlAllDefaultsExceptDestroy(uiTab) - -static void uiTabDestroy(uiControl *c) -{ - uiTab *t = uiTab(c); - guint i; - struct child *page; - - for (i = 0; i < t->pages->len; i++) { - page = g_array_index(t->pages, struct child *, i); - childDestroy(page); - } - g_array_free(t->pages, TRUE); - // and free ourselves - g_object_unref(t->widget); - uiFreeControl(uiControl(t)); -} - -void uiTabAppend(uiTab *t, const char *name, uiControl *child) -{ - uiTabInsertAt(t, name, t->pages->len, child); -} - -void uiTabInsertAt(uiTab *t, const char *name, int n, uiControl *child) -{ - struct child *page; - - // this will create a tab, because of gtk_container_add() - page = newChildWithBox(child, uiControl(t), t->container, 0); - - gtk_notebook_set_tab_label_text(t->notebook, childBox(page), name); - gtk_notebook_reorder_child(t->notebook, childBox(page), n); - - g_array_insert_val(t->pages, n, page); -} - -void uiTabDelete(uiTab *t, int n) -{ - struct child *page; - - page = g_array_index(t->pages, struct child *, n); - // this will remove the tab, because gtk_widget_destroy() calls gtk_container_remove() - childRemove(page); - g_array_remove_index(t->pages, n); -} - -int uiTabNumPages(uiTab *t) -{ - return t->pages->len; -} - -int uiTabMargined(uiTab *t, int n) -{ - struct child *page; - - page = g_array_index(t->pages, struct child *, n); - return childFlag(page); -} - -void uiTabSetMargined(uiTab *t, int n, int margined) -{ - struct child *page; - - page = g_array_index(t->pages, struct child *, n); - childSetFlag(page, margined); - childSetMargined(page, childFlag(page)); -} - -uiTab *uiNewTab(void) -{ - uiTab *t; - - uiUnixNewControl(uiTab, t); - - t->widget = gtk_notebook_new(); - t->container = GTK_CONTAINER(t->widget); - t->notebook = GTK_NOTEBOOK(t->widget); - - gtk_notebook_set_scrollable(t->notebook, TRUE); - - t->pages = g_array_new(FALSE, TRUE, sizeof (struct child *)); - - return t; -} diff --git a/src/libui_sdl/libui/unix/text.c b/src/libui_sdl/libui/unix/text.c deleted file mode 100644 index ad92738..0000000 --- a/src/libui_sdl/libui/unix/text.c +++ /dev/null @@ -1,12 +0,0 @@ -// 9 april 2015 -#include "uipriv_unix.h" - -char *uiUnixStrdupText(const char *t) -{ - return g_strdup(t); -} - -void uiFreeText(char *t) -{ - g_free(t); -} diff --git a/src/libui_sdl/libui/unix/uipriv_unix.h b/src/libui_sdl/libui/unix/uipriv_unix.h deleted file mode 100644 index 9b77188..0000000 --- a/src/libui_sdl/libui/unix/uipriv_unix.h +++ /dev/null @@ -1,71 +0,0 @@ -// 22 april 2015 -#define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_40 -#define GLIB_VERSION_MAX_ALLOWED GLIB_VERSION_2_40 -#define GDK_VERSION_MIN_REQUIRED GDK_VERSION_3_10 -#define GDK_VERSION_MAX_ALLOWED GDK_VERSION_3_10 -#include -#include -#include // see drawtext.c, gl.c -#include -#include -#include -#include "../ui.h" -#include "../ui_unix.h" -#include "../common/uipriv.h" - -#define gtkXMargin 12 -#define gtkYMargin 12 -#define gtkXPadding 12 -#define gtkYPadding 6 - -// menu.c -extern GtkWidget *makeMenubar(uiWindow *); -extern void freeMenubar(GtkWidget *); -extern void uninitMenus(void); - -// alloc.c -extern void initAlloc(void); -extern void uninitAlloc(void); - -// util.c -extern void setMargined(GtkContainer *, int); - -// child.c -extern struct child *newChild(uiControl *child, uiControl *parent, GtkContainer *parentContainer); -extern struct child *newChildWithBox(uiControl *child, uiControl *parent, GtkContainer *parentContainer, int margined); -extern void childRemove(struct child *c); -extern void childDestroy(struct child *c); -extern GtkWidget *childWidget(struct child *c); -extern int childFlag(struct child *c); -extern void childSetFlag(struct child *c, int flag); -extern GtkWidget *childBox(struct child *c); -extern void childSetMargined(struct child *c, int margined); - -// draw.c -extern uiDrawContext *newContext(cairo_t *); -extern void freeContext(uiDrawContext *); - -// drawtext.c -extern uiDrawTextFont *mkTextFont(PangoFont *f, gboolean add); -extern PangoFont *pangoDescToPangoFont(PangoFontDescription *pdesc); - -// graphemes.c -extern ptrdiff_t *graphemes(const char *text, PangoContext *context); - -// image.c -/*TODO remove this*/typedef struct uiImage uiImage; -extern cairo_surface_t *imageAppropriateSurface(uiImage *i, GtkWidget *w); - -// cellrendererbutton.c -extern GtkCellRenderer *newCellRendererButton(void); - -// future.c -extern void loadFutures(void); -extern PangoAttribute *FUTURE_pango_attr_foreground_alpha_new(guint16 alpha); -extern gboolean FUTURE_gtk_widget_path_iter_set_object_name(GtkWidgetPath *path, gint pos, const char *name); - -// gl.c -extern uiGLContext *createGLContext(GtkWidget* widget, int maj, int min); -extern void freeGLContext(uiGLContext* glctx); -extern void areaDrawGL(GtkWidget* widget, uiAreaDrawParams* dp, cairo_t* cr, uiGLContext* glctx); - diff --git a/src/libui_sdl/libui/unix/util.c b/src/libui_sdl/libui/unix/util.c deleted file mode 100644 index 7f4f43f..0000000 --- a/src/libui_sdl/libui/unix/util.c +++ /dev/null @@ -1,10 +0,0 @@ -// 18 april 2015 -#include "uipriv_unix.h" - -void setMargined(GtkContainer *c, int margined) -{ - if (margined) - gtk_container_set_border_width(c, gtkXMargin); - else - gtk_container_set_border_width(c, 0); -} diff --git a/src/libui_sdl/libui/unix/window.c b/src/libui_sdl/libui/unix/window.c deleted file mode 100644 index 6d5e2de..0000000 --- a/src/libui_sdl/libui/unix/window.c +++ /dev/null @@ -1,462 +0,0 @@ -// 11 june 2015 -#include "uipriv_unix.h" - -struct uiWindow { - uiUnixControl c; - - GtkWidget *widget; - GtkContainer *container; - GtkWindow *window; - - GtkWidget *vboxWidget; - GtkContainer *vboxContainer; - GtkBox *vbox; - - GtkWidget *childHolderWidget; - GtkContainer *childHolderContainer; - - GtkWidget *menubar; - - uiControl *child; - int margined; - - int width, height; - - int (*onClosing)(uiWindow *, void *); - void *onClosingData; - void (*onContentSizeChanged)(uiWindow *, void *); - void *onContentSizeChangedData; - void (*onDropFile)(uiWindow *, char *, void *); - void *onDropFileData; - void (*onGetFocus)(uiWindow *, void *); - void *onGetFocusData; - void (*onLoseFocus)(uiWindow *, void *); - void *onLoseFocusData; - - gboolean fullscreen; -}; - -static gboolean onClosing(GtkWidget *win, GdkEvent *e, gpointer data) -{ - uiWindow *w = uiWindow(data); - - // manually destroy the window ourselves; don't let the delete-event handler do it - if ((*(w->onClosing))(w, w->onClosingData)) - uiControlDestroy(uiControl(w)); - // don't continue to the default delete-event handler; we destroyed the window by now - return TRUE; -} - -static void onSizeAllocate(GtkWidget *widget, GdkRectangle *allocation, gpointer data) -{ - uiWindow *w = uiWindow(data); - - // TODO deal with spurious size-allocates - (*(w->onContentSizeChanged))(w, w->onContentSizeChangedData); -} - -static gboolean onGetFocus(GtkWidget *win, GdkEvent *e, gpointer data) -{ - uiWindow *w = uiWindow(data); - if (w->onGetFocus) - w->onGetFocus(w, w->onGetFocusData); -} - -static gboolean onLoseFocus(GtkWidget *win, GdkEvent *e, gpointer data) -{ - uiWindow *w = uiWindow(data); - if (w->onLoseFocus) - w->onLoseFocus(w, w->onLoseFocusData); -} - -static int defaultOnClosing(uiWindow *w, void *data) -{ - return 0; -} - -static void defaultOnPositionContentSizeChanged(uiWindow *w, void *data) -{ - // do nothing -} - -static void uiWindowDestroy(uiControl *c) -{ - uiWindow *w = uiWindow(c); - - // first hide ourselves - gtk_widget_hide(w->widget); - // now destroy the child - if (w->child != NULL) { - uiControlSetParent(w->child, NULL); - uiUnixControlSetContainer(uiUnixControl(w->child), w->childHolderContainer, TRUE); - uiControlDestroy(w->child); - } - // now destroy the menus, if any - if (w->menubar != NULL) - freeMenubar(w->menubar); - gtk_widget_destroy(w->childHolderWidget); - gtk_widget_destroy(w->vboxWidget); - // and finally free ourselves - // use gtk_widget_destroy() instead of g_object_unref() because GTK+ has internal references (see #165) - gtk_widget_destroy(w->widget); - uiFreeControl(uiControl(w)); -} - -void uiWindowSetPosition(uiWindow *w, int x, int y) -{ - if (!w) return; - - gtk_window_move(w->window, x, y); -} - -void uiWindowPosition(uiWindow *w, int *x, int *y) -{ - if (!w) return; - - int xx, yy; - gtk_window_get_position(w->window, &xx, &yy); - if (x) *x = xx; - if (y) *y = yy; -} - -uiUnixControlDefaultHandle(uiWindow) - -uiControl *uiWindowParent(uiControl *c) -{ - return NULL; -} - -void uiWindowSetParent(uiControl *c, uiControl *parent) -{ - uiUserBugCannotSetParentOnToplevel("uiWindow"); -} - -static int uiWindowToplevel(uiControl *c) -{ - return 1; -} - -uiUnixControlDefaultVisible(uiWindow) - -static void uiWindowShow(uiControl *c) -{ - uiWindow *w = uiWindow(c); - - // don't use gtk_widget_show_all() as that will show all children, regardless of user settings - // don't use gtk_widget_show(); that doesn't bring to front or give keyboard focus - // (gtk_window_present() does call gtk_widget_show() though) - gtk_window_present(w->window); - - // set the size properly - int width = w->width; - int height = w->height; - if (w->menubar) - { - GtkRequisition min, nat; - int menuheight; - gtk_widget_get_preferred_size(w->menubar, &min, &nat); - menuheight = min.height; - if (nat.height > menuheight) menuheight = nat.height; - height += menuheight; - } - gtk_window_resize(w->window, width, height); -} - -static void uiWindowSetFocus(uiControl* c) -{ - gtk_window_present(GTK_WINDOW(uiWindow(c)->widget)); -} - -uiUnixControlDefaultHide(uiWindow) -uiUnixControlDefaultEnabled(uiWindow) -uiUnixControlDefaultEnable(uiWindow) -uiUnixControlDefaultDisable(uiWindow) -//uiUnixControlDefaultSetFocus(uiWindow) -uiUnixControlDefaultSetMinSize(uiWindow) -// TODO? -uiUnixControlDefaultSetContainer(uiWindow) - -char *uiWindowTitle(uiWindow *w) -{ - return uiUnixStrdupText(gtk_window_get_title(w->window)); -} - -void uiWindowSetTitle(uiWindow *w, const char *title) -{ - gtk_window_set_title(w->window, title); -} - -void uiWindowContentSize(uiWindow *w, int *width, int *height) -{ - GtkAllocation allocation; - - gtk_widget_get_allocation(w->childHolderWidget, &allocation); - *width = allocation.width; - *height = allocation.height; -} - -void uiWindowSetContentSize(uiWindow *w, int width, int height) -{ - GtkAllocation childAlloc; - gint winWidth, winHeight; - - // we need to resize the child holder widget to the given size - // we can't resize that without running the event loop - // but we can do gtk_window_set_size() - // so how do we deal with the differences in sizes? - // simple arithmetic, of course! - - // from what I can tell, the return from gtk_widget_get_allocation(w->window) and gtk_window_get_size(w->window) will be the same - // this is not affected by Wayland and not affected by GTK+ builtin CSD - // so we can safely juse use them to get the real window size! - // since we're using gtk_window_resize(), use the latter - gtk_window_get_size(w->window, &winWidth, &winHeight); - - // now get the child holder widget's current allocation - gtk_widget_get_allocation(w->childHolderWidget, &childAlloc); - // and punch that out of the window size - winWidth -= childAlloc.width; - winHeight -= childAlloc.height; - - // now we just need to add the new size back in - winWidth += width; - winHeight += height; - // and set it - // this will not move the window in my tests, so we're good - gtk_window_resize(w->window, winWidth, winHeight); -} - -int uiWindowMinimized(uiWindow *w) -{ - // TODO!! - return 0; -} - -void uiWindowSetMinimized(uiWindow *w, int minimized) -{ - if (minimized) - gtk_window_iconify(w->window); - else - gtk_window_deiconify(w->window); -} - -int uiWindowMaximized(uiWindow *w) -{ - return gtk_window_is_maximized(w->window); -} - -void uiWindowSetMaximized(uiWindow *w, int maximized) -{ - if (maximized) - gtk_window_maximize(w->window); - else - gtk_window_unmaximize(w->window); -} - - -int uiWindowFullscreen(uiWindow *w) -{ - return w->fullscreen; -} - -// TODO use window-state-event to track -// TODO does this send an extra size changed? -// TODO what behavior do we want? -void uiWindowSetFullscreen(uiWindow *w, int fullscreen) -{ - w->fullscreen = fullscreen; - if (w->fullscreen) - gtk_window_fullscreen(w->window); - else - gtk_window_unfullscreen(w->window); -} - -void uiWindowOnContentSizeChanged(uiWindow *w, void (*f)(uiWindow *, void *), void *data) -{ - w->onContentSizeChanged = f; - w->onContentSizeChangedData = data; -} - -void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data) -{ - w->onClosing = f; - w->onClosingData = data; -} - -void uiWindowOnDropFile(uiWindow *w, void (*f)(uiWindow *, char *, void *), void *data) -{ - w->onDropFile = f; - w->onDropFileData = data; -} - -void uiWindowOnGetFocus(uiWindow *w, void (*f)(uiWindow *, void *), void *data) -{ - w->onGetFocus = f; - w->onGetFocusData = data; -} - -void uiWindowOnLoseFocus(uiWindow *w, void (*f)(uiWindow *, void *), void *data) -{ - w->onLoseFocus = f; - w->onLoseFocusData = data; -} - -int uiWindowBorderless(uiWindow *w) -{ - return gtk_window_get_decorated(w->window) == FALSE; -} - -void uiWindowSetBorderless(uiWindow *w, int borderless) -{ - gtk_window_set_decorated(w->window, borderless == 0); -} - -// TODO save and restore expands and aligns -void uiWindowSetChild(uiWindow *w, uiControl *child) -{ - if (w->child != NULL) { - uiControlSetParent(w->child, NULL); - uiUnixControlSetContainer(uiUnixControl(w->child), w->childHolderContainer, TRUE); - } - w->child = child; - if (w->child != NULL) { - uiControlSetParent(w->child, uiControl(w)); - uiUnixControlSetContainer(uiUnixControl(w->child), w->childHolderContainer, FALSE); - } -} - -int uiWindowMargined(uiWindow *w) -{ - return w->margined; -} - -void uiWindowSetMargined(uiWindow *w, int margined) -{ - w->margined = margined; - setMargined(w->childHolderContainer, w->margined); -} - -static void onDragDataReceived(GtkWidget* widget, GdkDragContext* ctx, gint x, gint y, GtkSelectionData* data, guint info, guint time, gpointer userdata) -{ - uiWindow* w = (uiWindow*)userdata; - - if (gtk_selection_data_get_length(data) > 0 && gtk_selection_data_get_format(data) == 8) - { - gchar** files = gtk_selection_data_get_uris(data); - if (files != NULL && files[0] != NULL) - { - // TODO: multi file support? - - gboolean success = FALSE; - - gchar* file = g_filename_from_uri(files[0], NULL, NULL); - if (file) - { - if (w->onDropFile) - w->onDropFile(w, file, w->onDropFileData); - - success = TRUE; - g_free(file); - } - - - g_strfreev(files); - gtk_drag_finish(ctx, success, FALSE, time); - return; - } - - if (files != NULL) g_strfreev(files); - gtk_drag_finish(ctx, FALSE, FALSE, time); - } -} - -void uiWindowSetDropTarget(uiWindow* w, int drop) -{ - if (!drop) - { - gtk_drag_dest_unset(w->widget); - return; - } - - GtkTargetEntry entry; - entry.target = "text/uri-list"; - entry.flags = GTK_TARGET_OTHER_APP; - entry.info = 1; - - // CHECKME: action copy? - gtk_drag_dest_set(w->widget, GTK_DEST_DEFAULT_ALL, &entry, 1, GDK_ACTION_COPY|GDK_ACTION_MOVE); - - g_signal_connect(w->widget, "drag-data-received", G_CALLBACK(onDragDataReceived), w); -} - -uiWindow *uiNewWindow(const char *title, int width, int height, int maximized, int hasMenubar, int resizable) -{ - uiWindow *w; - - if (!resizable) maximized = 0; - - uiUnixNewControl(uiWindow, w); - - w->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); - w->container = GTK_CONTAINER(w->widget); - w->window = GTK_WINDOW(w->widget); - - gtk_window_set_title(w->window, title); - gtk_window_resize(w->window, width, height); - - w->vboxWidget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); - w->vboxContainer = GTK_CONTAINER(w->vboxWidget); - w->vbox = GTK_BOX(w->vboxWidget); - - // set the vbox as the GtkWindow child - gtk_container_add(w->container, w->vboxWidget); - - if (hasMenubar) { - w->menubar = makeMenubar(uiWindow(w)); - gtk_container_add(w->vboxContainer, w->menubar); - } - else - w->menubar = NULL; - - w->childHolderWidget = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - w->childHolderContainer = GTK_CONTAINER(w->childHolderWidget); - gtk_widget_set_hexpand(w->childHolderWidget, TRUE); - gtk_widget_set_halign(w->childHolderWidget, GTK_ALIGN_FILL); - gtk_widget_set_vexpand(w->childHolderWidget, TRUE); - gtk_widget_set_valign(w->childHolderWidget, GTK_ALIGN_FILL); - gtk_box_set_homogeneous(GTK_BOX(w->childHolderWidget), TRUE); - gtk_container_add(w->vboxContainer, w->childHolderWidget); - - // show everything in the vbox, but not the GtkWindow itself - gtk_widget_show_all(w->vboxWidget); - - // and connect our events - g_signal_connect(w->widget, "delete-event", G_CALLBACK(onClosing), w); - g_signal_connect(w->childHolderWidget, "size-allocate", G_CALLBACK(onSizeAllocate), w); - g_signal_connect(w->widget, "focus-in-event", G_CALLBACK(onGetFocus), w); - g_signal_connect(w->widget, "focus-out-event", G_CALLBACK(onLoseFocus), w); - - uiWindowOnClosing(w, defaultOnClosing, NULL); - uiWindowOnContentSizeChanged(w, defaultOnPositionContentSizeChanged, NULL); - - uiWindowOnDropFile(w, NULL, NULL); - uiWindowOnGetFocus(w, NULL, NULL); - uiWindowOnLoseFocus(w, NULL, NULL); - - // normally it's SetParent() that does this, but we can't call SetParent() on a uiWindow - // TODO we really need to clean this up, especially since see uiWindowDestroy() above - g_object_ref(w->widget); - - gtk_window_set_resizable(w->window, resizable?TRUE:FALSE); - - w->width = width; - w->height = height; - - if (maximized) - gtk_window_maximize(w->window); - else - gtk_window_set_position(w->window, GTK_WIN_POS_CENTER); - - return w; -} - diff --git a/src/libui_sdl/libui/windows/CMakeLists.txt b/src/libui_sdl/libui/windows/CMakeLists.txt deleted file mode 100644 index 24d4ad9..0000000 --- a/src/libui_sdl/libui/windows/CMakeLists.txt +++ /dev/null @@ -1,92 +0,0 @@ -# 3 june 2016 - -list(APPEND _LIBUI_SOURCES - windows/alloc.cpp - windows/area.cpp - windows/areadraw.cpp - windows/areaevents.cpp - windows/areascroll.cpp - windows/areautil.cpp - windows/box.cpp - windows/button.cpp - windows/checkbox.cpp - windows/colorbutton.cpp - windows/colordialog.cpp - windows/combobox.cpp - windows/container.cpp - windows/control.cpp - windows/d2dscratch.cpp - windows/datetimepicker.cpp - windows/debug.cpp - windows/draw.cpp - windows/drawmatrix.cpp - windows/drawpath.cpp - windows/drawtext.cpp - windows/dwrite.cpp - windows/editablecombo.cpp - windows/entry.cpp - windows/events.cpp - windows/fontbutton.cpp - windows/fontdialog.cpp - windows/form.cpp - windows/gl.cpp - windows/graphemes.cpp - windows/grid.cpp - windows/group.cpp - windows/init.cpp - windows/label.cpp - windows/main.cpp - windows/menu.cpp - windows/multilineentry.cpp - windows/parent.cpp - windows/progressbar.cpp - windows/radiobuttons.cpp - windows/separator.cpp - windows/sizing.cpp - windows/slider.cpp - windows/spinbox.cpp - windows/stddialogs.cpp - windows/tab.cpp - windows/tabpage.cpp - windows/text.cpp - windows/utf16.cpp - windows/utilwin.cpp - windows/window.cpp - windows/winpublic.cpp - windows/winutil.cpp - windows/resources.rc -) -set(_LIBUI_SOURCES ${_LIBUI_SOURCES} PARENT_SCOPE) - -list(APPEND _LIBUI_INCLUDEDIRS - windows -) -set(_LIBUI_INCLUDEDIRS _LIBUI_INCLUDEDIRS PARENT_SCOPE) - -# Windows won't link resources in static libraries; we need to provide the libui.res file in this case. -set(_LIBUINAME libui PARENT_SCOPE) -if(NOT BUILD_SHARED_LIBS) - set(_LIBUI_STATIC_RES ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/libui.res PARENT_SCOPE) -endif() -macro(_handle_static) - # TODO this full path feels hacky - add_custom_command( - TARGET libui POST_BUILD - COMMAND - ${CMAKE_COMMAND} -E copy $/CMakeFiles/libui.dir/windows/resources.rc.obj ${_LIBUI_STATIC_RES} - COMMENT "Copying libui.res") -endmacro() - -# notice that usp10 comes before gdi32 -# TODO prune this list -set(_LIBUI_LIBS - user32 kernel32 usp10 gdi32 comctl32 uxtheme msimg32 comdlg32 d2d1 dwrite ole32 oleaut32 oleacc uuid -PARENT_SCOPE) - -if(NOT MSVC) - if(BUILD_SHARED_LIBS) - message(FATAL_ERROR - "Sorry, but libui for Windows can currently only be built as a static library with MinGW. You will need to either build as a static library or switch to MSVC." - ) - endif() -endif() diff --git a/src/libui_sdl/libui/windows/_uipriv_migrate.hpp b/src/libui_sdl/libui/windows/_uipriv_migrate.hpp deleted file mode 100644 index 13d3670..0000000 --- a/src/libui_sdl/libui/windows/_uipriv_migrate.hpp +++ /dev/null @@ -1,61 +0,0 @@ - -// menu.c -extern HMENU makeMenubar(void); -extern const uiMenuItem *menuIDToItem(UINT_PTR); -extern void runMenuEvent(WORD, uiWindow *); -extern void freeMenubar(HMENU); -extern void uninitMenus(void); - -// draw.c -extern HRESULT initDraw(void); -extern void uninitDraw(void); -extern ID2D1HwndRenderTarget *makeHWNDRenderTarget(HWND hwnd); -extern uiDrawContext *newContext(ID2D1RenderTarget *); -extern void freeContext(uiDrawContext *); - -// dwrite.cpp -#ifdef __cplusplus -extern IDWriteFactory *dwfactory; -#endif -extern HRESULT initDrawText(void); -extern void uninitDrawText(void); -#ifdef __cplusplus -struct fontCollection { - IDWriteFontCollection *fonts; - WCHAR userLocale[LOCALE_NAME_MAX_LENGTH]; - int userLocaleSuccess; -}; -extern fontCollection *loadFontCollection(void); -extern WCHAR *fontCollectionFamilyName(fontCollection *fc, IDWriteFontFamily *family); -extern void fontCollectionFree(fontCollection *fc); -extern WCHAR *fontCollectionCorrectString(fontCollection *fc, IDWriteLocalizedStrings *names); -#endif - -// drawtext.cpp -#ifdef __cplusplus -extern uiDrawTextFont *mkTextFont(IDWriteFont *df, BOOL addRef, WCHAR *family, BOOL copyFamily, double size); -struct dwriteAttr { - uiDrawTextWeight weight; - uiDrawTextItalic italic; - uiDrawTextStretch stretch; - DWRITE_FONT_WEIGHT dweight; - DWRITE_FONT_STYLE ditalic; - DWRITE_FONT_STRETCH dstretch; -}; -extern void attrToDWriteAttr(struct dwriteAttr *attr); -extern void dwriteAttrToAttr(struct dwriteAttr *attr); -#endif - -// fontdialog.cpp -#ifdef __cplusplus -struct fontDialogParams { - IDWriteFont *font; - double size; - WCHAR *familyName; - WCHAR *styleName; -}; -extern BOOL showFontDialog(HWND parent, struct fontDialogParams *params); -extern void loadInitialFontDialogParams(struct fontDialogParams *params); -extern void destroyFontDialogParams(struct fontDialogParams *params); -extern WCHAR *fontDialogParamsToString(struct fontDialogParams *params); -#endif diff --git a/src/libui_sdl/libui/windows/alloc.cpp b/src/libui_sdl/libui/windows/alloc.cpp deleted file mode 100644 index cf6bd2e..0000000 --- a/src/libui_sdl/libui/windows/alloc.cpp +++ /dev/null @@ -1,64 +0,0 @@ -// 4 december 2014 -#include "uipriv_windows.hpp" - -typedef std::vector byteArray; - -static std::map heap; -static std::map types; - -void initAlloc(void) -{ - // do nothing -} - -void uninitAlloc(void) -{ - std::ostringstream oss; - std::string ossstr; // keep alive, just to be safe - - if (heap.size() == 0) - return; - for (const auto &alloc : heap) - // note the void * cast; otherwise it'll be treated as a string - oss << (void *) (alloc.first) << " " << types[alloc.second] << "\n"; - ossstr = oss.str(); - printf("data leak: %s\n", ossstr.c_str()); - userbug("Some data was leaked; either you left a uiControl lying around or there's a bug in libui itself. Leaked data:\n%s", ossstr.c_str()); -} - -#define rawBytes(pa) (&((*pa)[0])) - -void *uiAlloc(size_t size, const char *type) -{ - byteArray *out; - - out = new byteArray(size, 0); - heap[rawBytes(out)] = out; - types[out] = type; - return rawBytes(out); -} - -void *uiRealloc(void *_p, size_t size, const char *type) -{ - uint8_t *p = (uint8_t *) _p; - byteArray *arr; - - if (p == NULL) - return uiAlloc(size, type); - arr = heap[p]; - arr->resize(size, 0); - heap.erase(p); - heap[rawBytes(arr)] = arr; - return rawBytes(arr); -} - -void uiFree(void *_p) -{ - uint8_t *p = (uint8_t *) _p; - - if (p == NULL) - implbug("attempt to uiFree(NULL)"); - types.erase(heap[p]); - delete heap[p]; - heap.erase(p); -} diff --git a/src/libui_sdl/libui/windows/area.cpp b/src/libui_sdl/libui/windows/area.cpp deleted file mode 100644 index 72d5145..0000000 --- a/src/libui_sdl/libui/windows/area.cpp +++ /dev/null @@ -1,291 +0,0 @@ -// 8 september 2015 -#include "uipriv_windows.hpp" -#include "area.hpp" - -// TODO handle WM_DESTROY/WM_NCDESTROY -// TODO same for other Direct2D stuff -static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - uiArea *a; - CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam; - RECT client; - WINDOWPOS *wp = (WINDOWPOS *) lParam; - LRESULT lResult; - - a = (uiArea *) GetWindowLongPtrW(hwnd, GWLP_USERDATA); - if (a == NULL) { - if (uMsg == WM_CREATE) { - a = (uiArea *) (cs->lpCreateParams); - // assign a->hwnd here so we can use it immediately - a->hwnd = hwnd; - SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) a); - } - // fall through to DefWindowProcW() anyway - return DefWindowProcW(hwnd, uMsg, wParam, lParam); - } - - // always recreate the render target if necessary - if (!a->openGL) - { - if (a->rt == NULL) - a->rt = makeHWNDRenderTarget(a->hwnd); - } - - if (areaDoDraw(a, uMsg, wParam, lParam, &lResult) != FALSE) - return lResult; - - if (uMsg == WM_WINDOWPOSCHANGED) { - if ((wp->flags & SWP_NOSIZE) != 0) - return DefWindowProcW(hwnd, uMsg, wParam, lParam); - a->width = -1; - a->height = -1; - uiWindowsEnsureGetClientRect(a->hwnd, &client); - areaDrawOnResize(a, &client); - areaScrollOnResize(a, &client); - { - double w, h; - loadAreaSize(a, &w, &h); - a->ah->Resize(a->ah, a, (int)w, (int)h); - } - return 0; - } - - if (areaDoScroll(a, uMsg, wParam, lParam, &lResult) != FALSE) - return lResult; - if (areaDoEvents(a, uMsg, wParam, lParam, &lResult) != FALSE) - return lResult; - - // nothing done - return DefWindowProc(hwnd, uMsg, wParam, lParam); -} - -// control implementation - -uiWindowsControlAllDefaultsExceptDestroy(uiArea) - -static void uiAreaDestroy(uiControl *c) -{ - uiArea* a = uiArea(c); - if (a->openGL && a->glcontext) freeGLContext(a->glcontext); - uiWindowsEnsureDestroyWindow(a->hwnd); - uiFreeControl(c); -} - -static void uiAreaMinimumSize(uiWindowsControl *c, int *width, int *height) -{ - *width = c->c.MinWidth; - if (*width < 1) *width = 1; - - *height = c->c.MinHeight; - if (*height < 1) *height = 1; -} - -ATOM registerAreaClass(HICON hDefaultIcon, HCURSOR hDefaultCursor) -{ - WNDCLASSW wc; - - ZeroMemory(&wc, sizeof (WNDCLASSW)); - wc.lpszClassName = areaClass; - wc.lpfnWndProc = areaWndProc; - wc.hInstance = hInstance; - wc.hIcon = hDefaultIcon; - wc.hCursor = hDefaultCursor; - wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); - // this is just to be safe; see the InvalidateRect() call in the WM_WINDOWPOSCHANGED handler for more details - wc.style = CS_HREDRAW | CS_VREDRAW; - return RegisterClassW(&wc); -} - -void unregisterArea(void) -{ - if (UnregisterClassW(areaClass, hInstance) == 0) - logLastError(L"error unregistering uiArea window class"); -} - -void uiAreaSetSize(uiArea *a, int width, int height) -{ - a->scrollWidth = width; - a->scrollHeight = height; - areaUpdateScroll(a); -} - -void uiAreaQueueRedrawAll(uiArea *a) -{ - // don't erase the background; we do that ourselves in doPaint() - invalidateRect(a->hwnd, NULL, FALSE); -} - -void uiAreaScrollTo(uiArea *a, double x, double y, double width, double height) -{ - // TODO -} - -void uiAreaBeginUserWindowMove(uiArea *a) -{ - HWND toplevel; - - // TODO restrict execution - ReleaseCapture(); // TODO use properly and reset internal data structures - toplevel = parentToplevel(a->hwnd); - if (toplevel == NULL) { - // TODO - return; - } - // see http://stackoverflow.com/questions/40249940/how-do-i-initiate-a-user-mouse-driven-move-or-resize-for-custom-window-borders-o#40250654 - SendMessageW(toplevel, WM_SYSCOMMAND, - SC_MOVE | 2, 0); -} - -void uiAreaBeginUserWindowResize(uiArea *a, uiWindowResizeEdge edge) -{ - HWND toplevel; - WPARAM wParam; - - // TODO restrict execution - ReleaseCapture(); // TODO use properly and reset internal data structures - toplevel = parentToplevel(a->hwnd); - if (toplevel == NULL) { - // TODO - return; - } - // see http://stackoverflow.com/questions/40249940/how-do-i-initiate-a-user-mouse-driven-move-or-resize-for-custom-window-borders-o#40250654 - wParam = SC_SIZE; - switch (edge) { - case uiWindowResizeEdgeLeft: - wParam |= 1; - break; - case uiWindowResizeEdgeTop: - wParam |= 3; - break; - case uiWindowResizeEdgeRight: - wParam |= 2; - break; - case uiWindowResizeEdgeBottom: - wParam |= 6; - break; - case uiWindowResizeEdgeTopLeft: - wParam |= 4; - break; - case uiWindowResizeEdgeTopRight: - wParam |= 5; - break; - case uiWindowResizeEdgeBottomLeft: - wParam |= 7; - break; - case uiWindowResizeEdgeBottomRight: - wParam |= 8; - break; - } - SendMessageW(toplevel, WM_SYSCOMMAND, - wParam, 0); -} - - -void uiAreaSetBackgroundColor(uiArea *a, int r, int g, int b) -{ - a->bgR = r; - a->bgG = g; - a->bgB = b; -} - - -uiArea *uiNewArea(uiAreaHandler *ah) -{ - uiArea *a; - - uiWindowsNewControl(uiArea, a); - - a->width = -1; - a->height = -1; - - a->ah = ah; - a->scrolling = FALSE; - clickCounterReset(&(a->cc)); - - // a->hwnd is assigned in areaWndProc() - uiWindowsEnsureCreateControlHWND(0, - areaClass, L"", - 0, - hInstance, a, - FALSE); - - uiAreaSetBackgroundColor(a, -1, -1, -1); - - a->openGL = 0; - - return a; -} - -uiGLContext *uiAreaGetGLContext(uiArea* a) -{ - if (!a->openGL) userbug("trying to get GL context from non-GL area"); - - return a->glcontext; -} - -uiArea *uiNewGLArea(uiAreaHandler *ah, const unsigned int* req_versions) -{ - uiArea *a; - - uiWindowsNewControl(uiArea, a); - - a->width = -1; - a->height = -1; - - a->ah = ah; - a->scrolling = FALSE; - clickCounterReset(&(a->cc)); - - // a->hwnd is assigned in areaWndProc() - uiWindowsEnsureCreateControlHWND(0, - areaClass, L"", - 0, - hInstance, a, - FALSE); - - uiAreaSetBackgroundColor(a, -1, -1, -1); - - a->openGL = 1; - - for (int i = 0; req_versions[i]; i++) - { - int major = uiGLVerMajor(req_versions[i]); - int minor = uiGLVerMinor(req_versions[i]); - a->glcontext = createGLContext(a, major, minor); - if (a->glcontext) break; - } - - return a; -} - -uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height) -{ - uiArea *a; - - uiWindowsNewControl(uiArea, a); - - a->width = -1; - a->height = -1; - - a->ah = ah; - a->scrolling = TRUE; - a->scrollWidth = width; - a->scrollHeight = height; - clickCounterReset(&(a->cc)); - - // a->hwnd is assigned in areaWndProc() - uiWindowsEnsureCreateControlHWND(0, - areaClass, L"", - WS_HSCROLL | WS_VSCROLL, - hInstance, a, - FALSE); - - uiAreaSetBackgroundColor(a, -1, -1, -1); - - a->openGL = 0; // TODO, eventually??? - - // set initial scrolling parameters - areaUpdateScroll(a); - - return a; -} diff --git a/src/libui_sdl/libui/windows/area.hpp b/src/libui_sdl/libui/windows/area.hpp deleted file mode 100644 index cfc45a4..0000000 --- a/src/libui_sdl/libui/windows/area.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// 18 december 2015 - -// TODOs -// - things look very wrong on initial draw -// - initial scrolling is not set properly -// - should background be inherited from parent control? - -struct uiArea { - uiWindowsControl c; - HWND hwnd; - uiAreaHandler *ah; - - int width, height; - - BOOL scrolling; - int scrollWidth; - int scrollHeight; - int hscrollpos; - int vscrollpos; - int hwheelCarry; - int vwheelCarry; - - clickCounter cc; - BOOL capturing; - - BOOL inside; - BOOL tracking; - - int bgR, bgG, bgB; - - int openGL; - uiGLContext* glcontext; - - ID2D1HwndRenderTarget *rt; -}; - -// areadraw.cpp -extern BOOL areaDoDraw(uiArea *a, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult); -extern void areaDrawOnResize(uiArea *, RECT *); - -// areascroll.cpp -extern BOOL areaDoScroll(uiArea *a, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult); -extern void areaScrollOnResize(uiArea *, RECT *); -extern void areaUpdateScroll(uiArea *a); - -// areaevents.cpp -extern BOOL areaDoEvents(uiArea *a, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult); - -// areautil.cpp -extern void loadAreaSize(uiArea *a, double *width, double *height); -extern void pixelsToDIP(uiArea *a, double *x, double *y); -extern void dipToPixels(uiArea *a, double *x, double *y); - -// gl.cpp -extern uiGLContext* createGLContext(uiArea* a, int vermajor, int verminor); -extern void freeGLContext(uiGLContext* c); diff --git a/src/libui_sdl/libui/windows/areadraw.cpp b/src/libui_sdl/libui/windows/areadraw.cpp deleted file mode 100644 index f369255..0000000 --- a/src/libui_sdl/libui/windows/areadraw.cpp +++ /dev/null @@ -1,170 +0,0 @@ -// 8 september 2015 -#include "uipriv_windows.hpp" -#include "area.hpp" - -static HRESULT doPaint(uiArea *a, ID2D1RenderTarget *rt, RECT *clip) -{ - uiAreaHandler *ah = a->ah; - uiAreaDrawParams dp; - - if (a->openGL) - { - //(*(ah->Draw))(ah, a, &dp); - return S_OK; - } - - COLORREF bgcolorref; - D2D1_COLOR_F bgcolor; - D2D1_MATRIX_3X2_F scrollTransform; - - // no need to save or restore the graphics state to reset transformations; it's handled by resetTarget() in draw.c, called during the following - dp.Context = newContext(rt); - - loadAreaSize(a, &(dp.AreaWidth), &(dp.AreaHeight)); - - dp.ClipX = clip->left; - dp.ClipY = clip->top; - dp.ClipWidth = clip->right - clip->left; - dp.ClipHeight = clip->bottom - clip->top; - if (a->scrolling) { - dp.ClipX += a->hscrollpos; - dp.ClipY += a->vscrollpos; - } - - rt->BeginDraw(); - - { - float dpi_x, dpi_y; - D2D1_MATRIX_3X2_F dm; - rt->GetDpi(&dpi_x, &dpi_y); - ZeroMemory(&dm, sizeof (D2D1_MATRIX_3X2_F)); - dm._11 = 96.f/dpi_x; - dm._22 = 96.f/dpi_y; - rt->SetTransform(&dm); - } - - if (a->scrolling) { - ZeroMemory(&scrollTransform, sizeof (D2D1_MATRIX_3X2_F)); - scrollTransform._11 = 1; - scrollTransform._22 = 1; - // negative because we want nonzero scroll positions to move the drawing area up/left - scrollTransform._31 = -a->hscrollpos; - scrollTransform._32 = -a->vscrollpos; - rt->SetTransform(&scrollTransform); - } - - // TODO push axis aligned clip - - // TODO only clear the clip area - // TODO clear with actual background brush - if (a->bgR != -1) - { - bgcolor.r = ((float) a->bgR) / 255.0; - bgcolor.g = ((float) a->bgG) / 255.0; - bgcolor.b = ((float) a->bgB) / 255.0; - bgcolor.a = 1.0; - } - else - { - bgcolorref = GetSysColor(COLOR_BTNFACE); - bgcolor.r = ((float) GetRValue(bgcolorref)) / 255.0; - // due to utter apathy on Microsoft's part, GetGValue() does not work with MSVC's Run-Time Error Checks - // it has not worked since 2008 and they have *never* fixed it - // TODO now that -RTCc has just been deprecated entirely, should we switch back? - bgcolor.g = ((float) ((BYTE) ((bgcolorref & 0xFF00) >> 8))) / 255.0; - bgcolor.b = ((float) GetBValue(bgcolorref)) / 255.0; - bgcolor.a = 1.0; - } - rt->Clear(&bgcolor); - - (*(ah->Draw))(ah, a, &dp); - - freeContext(dp.Context); - - // TODO pop axis aligned clip - - return rt->EndDraw(NULL, NULL); -} - -static void onWM_PAINT(uiArea *a) -{ - RECT clip; - HRESULT hr; - - // do not clear the update rect; we do that ourselves in doPaint() - if (GetUpdateRect(a->hwnd, &clip, FALSE) == 0) { - // set a zero clip rect just in case GetUpdateRect() didn't change clip - clip.left = 0; - clip.top = 0; - clip.right = 0; - clip.bottom = 0; - } - hr = doPaint(a, a->rt, &clip); - switch (hr) { - case S_OK: - if (ValidateRect(a->hwnd, NULL) == 0) - logLastError(L"error validating rect"); - break; - case D2DERR_RECREATE_TARGET: - // DON'T validate the rect - // instead, simply drop the render target - // we'll get another WM_PAINT and make the render target again - // TODO would this require us to invalidate the entire client area? - a->rt->Release();; - a->rt = NULL; - break; - default: - logHRESULT(L"error painting", hr); - } -} - -static void onWM_PRINTCLIENT(uiArea *a, HDC dc) -{ - // TODO???? - if (a->openGL) return; - - ID2D1DCRenderTarget *rt; - RECT client; - HRESULT hr; - - uiWindowsEnsureGetClientRect(a->hwnd, &client); - rt = makeHDCRenderTarget(dc, &client); - hr = doPaint(a, rt, &client); - if (hr != S_OK) - logHRESULT(L"error printing uiArea client area", hr); - rt->Release(); -} - -BOOL areaDoDraw(uiArea *a, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult) -{ - switch (uMsg) { - case WM_PAINT: - onWM_PAINT(a); - *lResult = 0; - return TRUE; - case WM_PRINTCLIENT: - onWM_PRINTCLIENT(a, (HDC) wParam); - *lResult = 0; - return TRUE; - } - return FALSE; -} - -// TODO only if the render target wasn't just created? -void areaDrawOnResize(uiArea *a, RECT *newClient) -{ - if (!a->openGL) - { - D2D1_SIZE_U size; - - size.width = newClient->right - newClient->left; - size.height = newClient->bottom - newClient->top; - // don't track the error; we'll get that in EndDraw() - // see https://msdn.microsoft.com/en-us/library/windows/desktop/dd370994%28v=vs.85%29.aspx - a->rt->Resize(&size); - } - - // according to Rick Brewster, we must always redraw the entire client area after calling ID2D1RenderTarget::Resize() (see http://stackoverflow.com/a/33222983/3408572) - // we used to have a uiAreaHandler.RedrawOnResize() method to decide this; now you know why we don't anymore - invalidateRect(a->hwnd, NULL, TRUE); -} diff --git a/src/libui_sdl/libui/windows/areaevents.cpp b/src/libui_sdl/libui/windows/areaevents.cpp deleted file mode 100644 index 46d6ab9..0000000 --- a/src/libui_sdl/libui/windows/areaevents.cpp +++ /dev/null @@ -1,435 +0,0 @@ -// 8 september 2015 -#include "uipriv_windows.hpp" -#include "area.hpp" - -static uiModifiers getModifiers(void) -{ - uiModifiers m = 0; - - if ((GetKeyState(VK_CONTROL) & 0x80) != 0) - m |= uiModifierCtrl; - if ((GetKeyState(VK_MENU) & 0x80) != 0) - m |= uiModifierAlt; - if ((GetKeyState(VK_SHIFT) & 0x80) != 0) - m |= uiModifierShift; - if ((GetKeyState(VK_LWIN) & 0x80) != 0) - m |= uiModifierSuper; - if ((GetKeyState(VK_RWIN) & 0x80) != 0) - m |= uiModifierSuper; - return m; -} - -/* -Windows doesn't natively support mouse crossing events. - -TrackMouseEvent() (and its comctl32.dll wrapper _TrackMouseEvent()) both allow for a window to receive the WM_MOUSELEAVE message when the mouse leaves the client area. There's no equivalent WM_MOUSEENTER because it can be simulated (https://blogs.msdn.microsoft.com/oldnewthing/20031013-00/?p=42193). - -Unfortunately, WM_MOUSELEAVE does not get generated while the mouse is captured. We need to capture for drag behavior to work properly, so this isn't going to mix well. - -So what we do: -- on WM_MOUSEMOVE, if we don't have the capture, start tracking - - this will handle the case of the capture being released while still in the area -- on WM_MOUSELEAVE, mark that we are no longer tracking - - Windows has already done the work of that for us; it's just a flag we use for the next part -- when starting capture, stop tracking if we are tracking -- if capturing, manually check if the pointer is in the client rect on each area event -*/ -static void track(uiArea *a, BOOL tracking) -{ - TRACKMOUSEEVENT tm; - - // do nothing if there's no change - if (a->tracking && tracking) - return; - if (!a->tracking && !tracking) - return; - - a->tracking = tracking; - ZeroMemory(&tm, sizeof (TRACKMOUSEEVENT)); - tm.cbSize = sizeof (TRACKMOUSEEVENT); - tm.dwFlags = TME_LEAVE; - if (!a->tracking) - tm.dwFlags |= TME_CANCEL; - tm.hwndTrack = a->hwnd; - if (_TrackMouseEvent(&tm) == 0) - logLastError(L"error setting up mouse tracking"); -} - -static void capture(uiArea *a, BOOL capturing) -{ - // do nothing if there's no change - if (a->capturing && capturing) - return; - if (!a->capturing && !capturing) - return; - - // change flag first as ReleaseCapture() sends WM_CAPTURECHANGED - a->capturing = capturing; - if (a->capturing) { - track(a, FALSE); - SetCapture(a->hwnd); - } else - if (ReleaseCapture() == 0) - logLastError(L"error releasing capture on drag"); -} - -static void areaMouseEvent(uiArea *a, int down, int up, WPARAM wParam, LPARAM lParam) -{ - uiAreaMouseEvent me; - int button; - POINT clientpt; - RECT client; - BOOL inClient; - double xpix, ypix; - - if (a->capturing) { - clientpt.x = GET_X_LPARAM(lParam); - clientpt.y = GET_Y_LPARAM(lParam); - uiWindowsEnsureGetClientRect(a->hwnd, &client); - inClient = PtInRect(&client, clientpt); - if (inClient && !a->inside) { - a->inside = TRUE; - (*(a->ah->MouseCrossed))(a->ah, a, 0); - clickCounterReset(&(a->cc)); - } else if (!inClient && a->inside) { - a->inside = FALSE; - (*(a->ah->MouseCrossed))(a->ah, a, 1); - clickCounterReset(&(a->cc)); - } - } - - xpix = (double) GET_X_LPARAM(lParam); - ypix = (double) GET_Y_LPARAM(lParam); - // these are in pixels; we need points - //pixelsToDIP(a, &xpix, &ypix); - me.X = xpix; - me.Y = ypix; - if (a->scrolling) { - me.X += a->hscrollpos; - me.Y += a->vscrollpos; - } - - loadAreaSize(a, &(me.AreaWidth), &(me.AreaHeight)); - - me.Down = down; - me.Up = up; - me.Count = 0; - if (me.Down != 0) - // GetMessageTime() returns LONG and GetDoubleClckTime() returns UINT, which are int32 and uint32, respectively, but we don't need to worry about the signedness because for the same bit widths and two's complement arithmetic, s1-s2 == u1-u2 if bits(s1)==bits(s2) and bits(u1)==bits(u2) (and Windows requires two's complement: http://blogs.msdn.com/b/oldnewthing/archive/2005/05/27/422551.aspx) - // signedness isn't much of an issue for these calls anyway because http://stackoverflow.com/questions/24022225/what-are-the-sign-extension-rules-for-calling-windows-api-functions-stdcall-t and that we're only using unsigned values (think back to how you (didn't) handle signedness in assembly language) AND because of the above AND because the statistics below (time interval and width/height) really don't make sense if negative - // GetSystemMetrics() returns int, which is int32 - me.Count = clickCounterClick(&(a->cc), me.Down, - me.X, me.Y, - GetMessageTime(), GetDoubleClickTime(), - GetSystemMetrics(SM_CXDOUBLECLK) / 2, - GetSystemMetrics(SM_CYDOUBLECLK) / 2); - - // though wparam will contain control and shift state, let's just one function to get modifiers for both keyboard and mouse events; it'll work the same anyway since we have to do this for alt and windows key (super) - me.Modifiers = getModifiers(); - - button = me.Down; - if (button == 0) - button = me.Up; - me.Held1To64 = 0; - if (button != 1 && (wParam & MK_LBUTTON) != 0) - me.Held1To64 |= 1 << 0; - if (button != 2 && (wParam & MK_MBUTTON) != 0) - me.Held1To64 |= 1 << 1; - if (button != 3 && (wParam & MK_RBUTTON) != 0) - me.Held1To64 |= 1 << 2; - if (button != 4 && (wParam & MK_XBUTTON1) != 0) - me.Held1To64 |= 1 << 3; - if (button != 5 && (wParam & MK_XBUTTON2) != 0) - me.Held1To64 |= 1 << 4; - - // on Windows, we have to capture on drag ourselves - if (me.Down != 0) - capture(a, TRUE); - // only release capture when all buttons released - if (me.Up != 0 && me.Held1To64 == 0) - capture(a, FALSE); - - (*(a->ah->MouseEvent))(a->ah, a, &me); -} - -// TODO genericize this so it can be called above -static void onMouseEntered(uiArea *a) -{ - if (a->inside) - return; - if (a->capturing) // we handle mouse crossing in areaMouseEvent() - return; - track(a, TRUE); - (*(a->ah->MouseCrossed))(a->ah, a, 0); - // TODO figure out why we did this to begin with; either we do it on both GTK+ and Windows or not at all - clickCounterReset(&(a->cc)); -} - -// TODO genericize it so that it can be called above -static void onMouseLeft(uiArea *a) -{ - a->tracking = FALSE; - a->inside = FALSE; - (*(a->ah->MouseCrossed))(a->ah, a, 1); - // TODO figure out why we did this to begin with; either we do it on both GTK+ and Windows or not at all - clickCounterReset(&(a->cc)); -} - -// we use VK_SNAPSHOT as a sentinel because libui will never support the print screen key; that key belongs to the user -struct extkeymap { - WPARAM vk; - uiExtKey extkey; -}; - -// all mappings come from GLFW - https://github.com/glfw/glfw/blob/master/src/win32_window.c#L152 -static const struct extkeymap numpadExtKeys[] = { - { VK_HOME, uiExtKeyN7 }, - { VK_UP, uiExtKeyN8 }, - { VK_PRIOR, uiExtKeyN9 }, - { VK_LEFT, uiExtKeyN4 }, - { VK_CLEAR, uiExtKeyN5 }, - { VK_RIGHT, uiExtKeyN6 }, - { VK_END, uiExtKeyN1 }, - { VK_DOWN, uiExtKeyN2 }, - { VK_NEXT, uiExtKeyN3 }, - { VK_INSERT, uiExtKeyN0 }, - { VK_DELETE, uiExtKeyNDot }, - { VK_SNAPSHOT, 0 }, -}; - -static const struct extkeymap extKeys[] = { - { VK_ESCAPE, uiExtKeyEscape }, - { VK_INSERT, uiExtKeyInsert }, - { VK_DELETE, uiExtKeyDelete }, - { VK_HOME, uiExtKeyHome }, - { VK_END, uiExtKeyEnd }, - { VK_PRIOR, uiExtKeyPageUp }, - { VK_NEXT, uiExtKeyPageDown }, - { VK_UP, uiExtKeyUp }, - { VK_DOWN, uiExtKeyDown }, - { VK_LEFT, uiExtKeyLeft }, - { VK_RIGHT, uiExtKeyRight }, - { VK_F1, uiExtKeyF1 }, - { VK_F2, uiExtKeyF2 }, - { VK_F3, uiExtKeyF3 }, - { VK_F4, uiExtKeyF4 }, - { VK_F5, uiExtKeyF5 }, - { VK_F6, uiExtKeyF6 }, - { VK_F7, uiExtKeyF7 }, - { VK_F8, uiExtKeyF8 }, - { VK_F9, uiExtKeyF9 }, - { VK_F10, uiExtKeyF10 }, - { VK_F11, uiExtKeyF11 }, - { VK_F12, uiExtKeyF12 }, - // numpad numeric keys and . are handled in common/areaevents.c - // numpad enter is handled in code below - { VK_ADD, uiExtKeyNAdd }, - { VK_SUBTRACT, uiExtKeyNSubtract }, - { VK_MULTIPLY, uiExtKeyNMultiply }, - { VK_DIVIDE, uiExtKeyNDivide }, - { VK_SNAPSHOT, 0 }, -}; - -static const struct { - WPARAM vk; - uiModifiers mod; -} modKeys[] = { - // even if the separate left/right aren't necessary, have them here anyway, just to be safe - { VK_CONTROL, uiModifierCtrl }, - { VK_LCONTROL, uiModifierCtrl }, - { VK_RCONTROL, uiModifierCtrl }, - { VK_MENU, uiModifierAlt }, - { VK_LMENU, uiModifierAlt }, - { VK_RMENU, uiModifierAlt }, - { VK_SHIFT, uiModifierShift }, - { VK_LSHIFT, uiModifierShift }, - { VK_RSHIFT, uiModifierShift }, - // there's no combined Windows key virtual-key code as there is with the others - { VK_LWIN, uiModifierSuper }, - { VK_RWIN, uiModifierSuper }, - { VK_SNAPSHOT, 0 }, -}; - -static int areaKeyEvent(uiArea *a, int up, WPARAM wParam, LPARAM lParam) -{ - uiAreaKeyEvent ke; - int righthand; - int i; - - ke.Key = 0; - ke.ExtKey = 0; - ke.Modifier = 0; - - ke.Modifiers = getModifiers(); - - ke.Scancode = (lParam >> 16) & 0x1FF; - - ke.Up = up; - ke.Repeat = (lParam & 0x40000000) ? 1:0; - - // Arisotura note: I don't actually need all this key decoding - // raw scancodes are all I need for this -#if 0 - // the numeric keypad keys when Num Lock is off are considered left-hand keys as the separate navigation buttons were added later - // the numeric keypad Enter, however, is a right-hand key because it has the same virtual-key code as the typewriter Enter - righthand = (lParam & 0x01000000) != 0; - if (righthand) { - if (wParam == VK_RETURN) { - ke.ExtKey = uiExtKeyNEnter; - goto keyFound; - } - } else - // this is special handling for numpad keys to ignore the state of Num Lock and Shift; see http://blogs.msdn.com/b/oldnewthing/archive/2004/09/06/226045.aspx and https://github.com/glfw/glfw/blob/master/src/win32_window.c#L152 - for (i = 0; numpadExtKeys[i].vk != VK_SNAPSHOT; i++) - if (numpadExtKeys[i].vk == wParam) { - ke.ExtKey = numpadExtKeys[i].extkey; - goto keyFound; - } - - // okay, those above cases didn't match anything - // first try the extended keys - for (i = 0; extKeys[i].vk != VK_SNAPSHOT; i++) - if (extKeys[i].vk == wParam) { - ke.ExtKey = extKeys[i].extkey; - goto keyFound; - } - - // then try modifier keys - for (i = 0; modKeys[i].vk != VK_SNAPSHOT; i++) - if (modKeys[i].vk == wParam) { - ke.Modifier = modKeys[i].mod; - // and don't include the key in Modifiers - ke.Modifiers &= ~ke.Modifier; - goto keyFound; - } - - // and finally everything else - if (fromScancode((lParam >> 16) & 0xFF, &ke)) - goto keyFound; - - // not a supported key, assume unhandled - // TODO the original code only did this if ke.Modifiers == 0 - why? - return 0; - -keyFound: -#endif - return (*(a->ah->KeyEvent))(a->ah, a, &ke); -} - -char* uiKeyName(int scancode) -{ - WCHAR tmp[64]; - GetKeyNameText(scancode<<16, tmp, 64); - return toUTF8(tmp); -} - -// We don't handle the standard Windows keyboard messages directly, to avoid both the dialog manager and TranslateMessage(). -// Instead, we set up a message filter and do things there. -// That stuff is later in this file. -enum { - // start at 0x40 to avoid clobbering dialog messages - msgAreaKeyDown = WM_USER + 0x40, - msgAreaKeyUp, -}; - -BOOL areaDoEvents(uiArea *a, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult) -{ - switch (uMsg) { - case WM_ACTIVATE: - // don't keep the double-click timer running if the user switched programs in between clicks - clickCounterReset(&(a->cc)); - *lResult = 0; - return TRUE; - case WM_MOUSEMOVE: - onMouseEntered(a); - areaMouseEvent(a, 0, 0, wParam, lParam); - *lResult = 0; - return TRUE; - case WM_MOUSELEAVE: - onMouseLeft(a); - *lResult = 0; - return TRUE; - case WM_LBUTTONDOWN: - SetFocus(a->hwnd); - areaMouseEvent(a, 1, 0, wParam, lParam); - *lResult = 0; - return TRUE; - case WM_LBUTTONUP: - areaMouseEvent(a, 0, 1, wParam, lParam); - *lResult = 0; - return TRUE; - case WM_MBUTTONDOWN: - SetFocus(a->hwnd); - areaMouseEvent(a, 2, 0, wParam, lParam); - *lResult = 0; - return TRUE; - case WM_MBUTTONUP: - areaMouseEvent(a, 0, 2, wParam, lParam); - *lResult = 0; - return TRUE; - case WM_RBUTTONDOWN: - SetFocus(a->hwnd); - areaMouseEvent(a, 3, 0, wParam, lParam); - *lResult = 0; - return TRUE; - case WM_RBUTTONUP: - areaMouseEvent(a, 0, 3, wParam, lParam); - *lResult = 0; - return TRUE; - case WM_XBUTTONDOWN: - SetFocus(a->hwnd); - // values start at 1; we want them to start at 4 - areaMouseEvent(a, - GET_XBUTTON_WPARAM(wParam) + 3, 0, - GET_KEYSTATE_WPARAM(wParam), lParam); - *lResult = TRUE; // XBUTTON messages are different! - return TRUE; - case WM_XBUTTONUP: - areaMouseEvent(a, - 0, GET_XBUTTON_WPARAM(wParam) + 3, - GET_KEYSTATE_WPARAM(wParam), lParam); - *lResult = TRUE; // XBUTTON messages are different! - return TRUE; - case WM_CAPTURECHANGED: - if (a->capturing) { - a->capturing = FALSE; - (*(a->ah->DragBroken))(a->ah, a); - } - *lResult = 0; - return TRUE; - case msgAreaKeyDown: - *lResult = (LRESULT) areaKeyEvent(a, 0, wParam, lParam); - return TRUE; - case msgAreaKeyUp: - *lResult = (LRESULT) areaKeyEvent(a, 1, wParam, lParam); - return TRUE; - } - return FALSE; -} - -// TODO affect visibility properly -// TODO what did this mean -BOOL areaFilter(MSG *msg) -{ - LRESULT handled; - - // is the recipient an area? - if (msg->hwnd == NULL) // this can happen; for example, WM_TIMER - return FALSE; - if (windowClassOf(msg->hwnd, areaClass, NULL) != 0) - return FALSE; // nope - - handled = 0; - switch (msg->message) { - case WM_KEYDOWN: - case WM_SYSKEYDOWN: - handled = SendMessageW(msg->hwnd, msgAreaKeyDown, msg->wParam, msg->lParam); - break; - case WM_KEYUP: - case WM_SYSKEYUP: - handled = SendMessageW(msg->hwnd, msgAreaKeyUp, msg->wParam, msg->lParam); - break; - // otherwise handled remains 0, as we didn't handle this - } - return (BOOL) handled; -} diff --git a/src/libui_sdl/libui/windows/areascroll.cpp b/src/libui_sdl/libui/windows/areascroll.cpp deleted file mode 100644 index f18d0ad..0000000 --- a/src/libui_sdl/libui/windows/areascroll.cpp +++ /dev/null @@ -1,247 +0,0 @@ -// 8 september 2015 -#include "uipriv_windows.hpp" -#include "area.hpp" - -// TODO -// - move from pixels to points somehow -// - add a function to offset points and rects by scrolling amounts; call it from doPaint() in areadraw.c -// - recalculate scrolling after: -// - creation? -// - resize? -// - recreating the render target? (after moving to points) -// - error if these are called without scrollbars? - -struct scrollParams { - int *pos; - int pagesize; - int length; - int *wheelCarry; - UINT wheelSPIAction; -}; - -static void scrollto(uiArea *a, int which, struct scrollParams *p, int pos) -{ - SCROLLINFO si; - - // note that the pos < 0 check is /after/ the p->length - p->pagesize check - // it used to be /before/; this was actually a bug in Raymond Chen's original algorithm: if there are fewer than a page's worth of items, p->length - p->pagesize will be negative and our content draw at the bottom of the window - // this SHOULD have the same effect with that bug fixed and no others introduced... (thanks to devin on irc.badnik.net for confirming this logic) - if (pos > p->length - p->pagesize) - pos = p->length - p->pagesize; - if (pos < 0) - pos = 0; - - // Direct2D doesn't have a method for scrolling the existing contents of a render target. - // We'll have to just invalidate everything and hope for the best. - invalidateRect(a->hwnd, NULL, FALSE); - - *(p->pos) = pos; - - // now commit our new scrollbar setup... - ZeroMemory(&si, sizeof (SCROLLINFO)); - si.cbSize = sizeof (SCROLLINFO); - si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE; - si.nPage = p->pagesize; - si.nMin = 0; - si.nMax = p->length - 1; // endpoint inclusive - si.nPos = *(p->pos); - SetScrollInfo(a->hwnd, which, &si, TRUE); -} - -static void scrollby(uiArea *a, int which, struct scrollParams *p, int delta) -{ - scrollto(a, which, p, *(p->pos) + delta); -} - -static void scroll(uiArea *a, int which, struct scrollParams *p, WPARAM wParam, LPARAM lParam) -{ - int pos; - SCROLLINFO si; - - pos = *(p->pos); - switch (LOWORD(wParam)) { - case SB_LEFT: // also SB_TOP - pos = 0; - break; - case SB_RIGHT: // also SB_BOTTOM - pos = p->length - p->pagesize; - break; - case SB_LINELEFT: // also SB_LINEUP - pos--; - break; - case SB_LINERIGHT: // also SB_LINEDOWN - pos++; - break; - case SB_PAGELEFT: // also SB_PAGEUP - pos -= p->pagesize; - break; - case SB_PAGERIGHT: // also SB_PAGEDOWN - pos += p->pagesize; - break; - case SB_THUMBPOSITION: - ZeroMemory(&si, sizeof (SCROLLINFO)); - si.cbSize = sizeof (SCROLLINFO); - si.fMask = SIF_POS; - if (GetScrollInfo(a->hwnd, which, &si) == 0) - logLastError(L"error getting thumb position for area"); - pos = si.nPos; - break; - case SB_THUMBTRACK: - ZeroMemory(&si, sizeof (SCROLLINFO)); - si.cbSize = sizeof (SCROLLINFO); - si.fMask = SIF_TRACKPOS; - if (GetScrollInfo(a->hwnd, which, &si) == 0) - logLastError(L"error getting thumb track position for area"); - pos = si.nTrackPos; - break; - } - scrollto(a, which, p, pos); -} - -static void wheelscroll(uiArea *a, int which, struct scrollParams *p, WPARAM wParam, LPARAM lParam) -{ - int delta; - int lines; - UINT scrollAmount; - - delta = GET_WHEEL_DELTA_WPARAM(wParam); - if (SystemParametersInfoW(p->wheelSPIAction, 0, &scrollAmount, 0) == 0) - // TODO use scrollAmount == 3 (for both v and h) instead? - logLastError(L"error getting area wheel scroll amount"); - if (scrollAmount == WHEEL_PAGESCROLL) - scrollAmount = p->pagesize; - if (scrollAmount == 0) // no mouse wheel scrolling (or t->pagesize == 0) - return; - // the rest of this is basically http://blogs.msdn.com/b/oldnewthing/archive/2003/08/07/54615.aspx and http://blogs.msdn.com/b/oldnewthing/archive/2003/08/11/54624.aspx - // see those pages for information on subtleties - delta += *(p->wheelCarry); - lines = delta * ((int) scrollAmount) / WHEEL_DELTA; - *(p->wheelCarry) = delta - lines * WHEEL_DELTA / ((int) scrollAmount); - scrollby(a, which, p, -lines); -} - -static void hscrollParams(uiArea *a, struct scrollParams *p) -{ - RECT r; - - ZeroMemory(p, sizeof (struct scrollParams)); - p->pos = &(a->hscrollpos); - // TODO get rid of these and replace with points - uiWindowsEnsureGetClientRect(a->hwnd, &r); - p->pagesize = r.right - r.left; - p->length = a->scrollWidth; - p->wheelCarry = &(a->hwheelCarry); - p->wheelSPIAction = SPI_GETWHEELSCROLLCHARS; -} - -static void hscrollto(uiArea *a, int pos) -{ - struct scrollParams p; - - hscrollParams(a, &p); - scrollto(a, SB_HORZ, &p, pos); -} - -static void hscrollby(uiArea *a, int delta) -{ - struct scrollParams p; - - hscrollParams(a, &p); - scrollby(a, SB_HORZ, &p, delta); -} - -static void hscroll(uiArea *a, WPARAM wParam, LPARAM lParam) -{ - struct scrollParams p; - - hscrollParams(a, &p); - scroll(a, SB_HORZ, &p, wParam, lParam); -} - -static void hwheelscroll(uiArea *a, WPARAM wParam, LPARAM lParam) -{ - struct scrollParams p; - - hscrollParams(a, &p); - wheelscroll(a, SB_HORZ, &p, wParam, lParam); -} - -static void vscrollParams(uiArea *a, struct scrollParams *p) -{ - RECT r; - - ZeroMemory(p, sizeof (struct scrollParams)); - p->pos = &(a->vscrollpos); - uiWindowsEnsureGetClientRect(a->hwnd, &r); - p->pagesize = r.bottom - r.top; - p->length = a->scrollHeight; - p->wheelCarry = &(a->vwheelCarry); - p->wheelSPIAction = SPI_GETWHEELSCROLLLINES; -} - -static void vscrollto(uiArea *a, int pos) -{ - struct scrollParams p; - - vscrollParams(a, &p); - scrollto(a, SB_VERT, &p, pos); -} - -static void vscrollby(uiArea *a, int delta) -{ - struct scrollParams p; - - vscrollParams(a, &p); - scrollby(a, SB_VERT, &p, delta); -} - -static void vscroll(uiArea *a, WPARAM wParam, LPARAM lParam) -{ - struct scrollParams p; - - vscrollParams(a, &p); - scroll(a, SB_VERT, &p, wParam, lParam); -} - -static void vwheelscroll(uiArea *a, WPARAM wParam, LPARAM lParam) -{ - struct scrollParams p; - - vscrollParams(a, &p); - wheelscroll(a, SB_VERT, &p, wParam, lParam); -} - -BOOL areaDoScroll(uiArea *a, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult) -{ - switch (uMsg) { - case WM_HSCROLL: - hscroll(a, wParam, lParam); - *lResult = 0; - return TRUE; - case WM_MOUSEHWHEEL: - hwheelscroll(a, wParam, lParam); - *lResult = 0; - return TRUE; - case WM_VSCROLL: - vscroll(a, wParam, lParam); - *lResult = 0; - return TRUE; - case WM_MOUSEWHEEL: - vwheelscroll(a, wParam, lParam); - *lResult = 0; - return TRUE; - } - return FALSE; -} - -void areaScrollOnResize(uiArea *a, RECT *client) -{ - areaUpdateScroll(a); -} - -void areaUpdateScroll(uiArea *a) -{ - // use a no-op scroll to simulate scrolling - hscrollby(a, 0); - vscrollby(a, 0); -} diff --git a/src/libui_sdl/libui/windows/areautil.cpp b/src/libui_sdl/libui/windows/areautil.cpp deleted file mode 100644 index ea13221..0000000 --- a/src/libui_sdl/libui/windows/areautil.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// 18 december 2015 -#include "uipriv_windows.hpp" -#include "area.hpp" - -// TODO: make those int rather than double -void loadAreaSize(uiArea *a, double *width, double *height) -{ - D2D1_SIZE_F size; - - if (a->width != -1) - { - *width = (double)a->width; - *height = (double)a->height; - return; - } - - *width = 0; - *height = 0; - if (!a->scrolling) { - /*if (rt == NULL) - rt = a->rt; - size = realGetSize(rt); - *width = size.width; - *height = size.height; - dipToPixels(a, width, height);*/ - RECT rect; - GetWindowRect(a->hwnd, &rect); - *width = (double)(rect.right - rect.left); - *height = (double)(rect.bottom - rect.top); - } - - a->width = (int)*width; - a->height = (int)*height; -} - -void pixelsToDIP(uiArea *a, double *x, double *y) -{ - FLOAT dpix, dpiy; - - a->rt->GetDpi(&dpix, &dpiy); - // see https://msdn.microsoft.com/en-us/library/windows/desktop/dd756649%28v=vs.85%29.aspx (and others; search "direct2d mouse") - *x = (*x * 96) / dpix; - *y = (*y * 96) / dpiy; -} - -void dipToPixels(uiArea *a, double *x, double *y) -{ - FLOAT dpix, dpiy; - - a->rt->GetDpi(&dpix, &dpiy); - *x = (*x * dpix) / 96; - *y = (*y * dpiy) / 96; -} diff --git a/src/libui_sdl/libui/windows/box.cpp b/src/libui_sdl/libui/windows/box.cpp deleted file mode 100644 index 5ed8447..0000000 --- a/src/libui_sdl/libui/windows/box.cpp +++ /dev/null @@ -1,324 +0,0 @@ -// 7 april 2015 -#include "uipriv_windows.hpp" - -struct boxChild { - uiControl *c; - int stretchy; - int width; - int height; -}; - -struct uiBox { - uiWindowsControl c; - HWND hwnd; - std::vector *controls; - int vertical; - int padded; -}; - -static void boxPadding(uiBox *b, int *xpadding, int *ypadding) -{ - uiWindowsSizing sizing; - - *xpadding = 0; - *ypadding = 0; - if (b->padded) { - uiWindowsGetSizing(b->hwnd, &sizing); - uiWindowsSizingStandardPadding(&sizing, xpadding, ypadding); - } -} - -static void boxRelayout(uiBox *b) -{ - RECT r; - int x, y, width, height; - int xpadding, ypadding; - int nStretchy; - int stretchywid, stretchyht; - int i; - int minimumWidth, minimumHeight; - int nVisible; - - if (b->controls->size() == 0) - return; - - uiWindowsEnsureGetClientRect(b->hwnd, &r); - x = r.left; - y = r.top; - width = r.right - r.left; - height = r.bottom - r.top; - - // -1) get this Box's padding - boxPadding(b, &xpadding, &ypadding); - - // 1) get width and height of non-stretchy controls - // this will tell us how much space will be left for stretchy controls - stretchywid = width; - stretchyht = height; - nStretchy = 0; - nVisible = 0; - for (struct boxChild &bc : *(b->controls)) { - if (!uiControlVisible(bc.c)) - continue; - nVisible++; - if (bc.stretchy) { - nStretchy++; - continue; - } - uiWindowsControlMinimumSize(uiWindowsControl(bc.c), &minimumWidth, &minimumHeight); - if (b->vertical) { // all controls have same width - bc.width = width; - bc.height = minimumHeight; - stretchyht -= minimumHeight; - } else { // all controls have same height - bc.width = minimumWidth; - bc.height = height; - stretchywid -= minimumWidth; - } - } - if (nVisible == 0) // nothing to do - return; - - // 2) now inset the available rect by the needed padding - if (b->vertical) { - height -= (nVisible - 1) * ypadding; - stretchyht -= (nVisible - 1) * ypadding; - } else { - width -= (nVisible - 1) * xpadding; - stretchywid -= (nVisible - 1) * xpadding; - } - - // 3) now get the size of stretchy controls - if (nStretchy != 0) { - if (b->vertical) - stretchyht /= nStretchy; - else - stretchywid /= nStretchy; - for (struct boxChild &bc : *(b->controls)) { - if (!uiControlVisible(bc.c)) - continue; - if (bc.stretchy) { - bc.width = stretchywid; - bc.height = stretchyht; - } - } - } - - // 4) now we can position controls - // first, make relative to the top-left corner of the container - x = 0; - y = 0; - for (const struct boxChild &bc : *(b->controls)) { - if (!uiControlVisible(bc.c)) - continue; - uiWindowsEnsureMoveWindowDuringResize((HWND) uiControlHandle(bc.c), x, y, bc.width, bc.height); - if (b->vertical) - y += bc.height + ypadding; - else - x += bc.width + xpadding; - } -} - -static void uiBoxDestroy(uiControl *c) -{ - uiBox *b = uiBox(c); - - for (const struct boxChild &bc : *(b->controls)) { - uiControlSetParent(bc.c, NULL); - uiControlDestroy(bc.c); - } - delete b->controls; - uiWindowsEnsureDestroyWindow(b->hwnd); - uiFreeControl(uiControl(b)); -} - -uiWindowsControlDefaultHandle(uiBox) -uiWindowsControlDefaultParent(uiBox) -uiWindowsControlDefaultSetParent(uiBox) -uiWindowsControlDefaultToplevel(uiBox) -uiWindowsControlDefaultVisible(uiBox) -uiWindowsControlDefaultShow(uiBox) -uiWindowsControlDefaultHide(uiBox) -uiWindowsControlDefaultEnabled(uiBox) -uiWindowsControlDefaultEnable(uiBox) -uiWindowsControlDefaultDisable(uiBox) -uiWindowsControlDefaultSetFocus(uiBox) - -static void uiBoxSyncEnableState(uiWindowsControl *c, int enabled) -{ - uiBox *b = uiBox(c); - - if (uiWindowsShouldStopSyncEnableState(uiWindowsControl(b), enabled)) - return; - for (const struct boxChild &bc : *(b->controls)) - uiWindowsControlSyncEnableState(uiWindowsControl(bc.c), enabled); -} - -uiWindowsControlDefaultSetParentHWND(uiBox) - -static void uiBoxMinimumSize(uiWindowsControl *c, int *width, int *height) -{ - uiBox *b = uiBox(c); - int xpadding, ypadding; - int nStretchy; - // these two contain the largest minimum width and height of all stretchy controls in the box - // all stretchy controls will use this value to determine the final minimum size - int maxStretchyWidth, maxStretchyHeight; - int minimumWidth, minimumHeight; - int nVisible; - - *width = 0; - *height = 0; - if (b->controls->size() == 0) - return; - - // 0) get this Box's padding - boxPadding(b, &xpadding, &ypadding); - - // 1) add in the size of non-stretchy controls and get (but not add in) the largest widths and heights of stretchy controls - // we still add in like direction of stretchy controls - nStretchy = 0; - maxStretchyWidth = 0; - maxStretchyHeight = 0; - nVisible = 0; - for (const struct boxChild &bc : *(b->controls)) { - if (!uiControlVisible(bc.c)) - continue; - nVisible++; - uiWindowsControlMinimumSize(uiWindowsControl(bc.c), &minimumWidth, &minimumHeight); - if (bc.stretchy) { - nStretchy++; - if (maxStretchyWidth < minimumWidth) - maxStretchyWidth = minimumWidth; - if (maxStretchyHeight < minimumHeight) - maxStretchyHeight = minimumHeight; - } - if (b->vertical) { - if (*width < minimumWidth) - *width = minimumWidth; - if (!bc.stretchy) - *height += minimumHeight; - } else { - if (!bc.stretchy) - *width += minimumWidth; - if (*height < minimumHeight) - *height = minimumHeight; - } - } - if (nVisible == 0) // just return 0x0 - return; - - // 2) now outset the desired rect with the needed padding - if (b->vertical) - *height += (nVisible - 1) * ypadding; - else - *width += (nVisible - 1) * xpadding; - - // 3) and now we can add in stretchy controls - if (b->vertical) - *height += nStretchy * maxStretchyHeight; - else - *width += nStretchy * maxStretchyWidth; -} - -static void uiBoxMinimumSizeChanged(uiWindowsControl *c) -{ - uiBox *b = uiBox(c); - - if (uiWindowsControlTooSmall(uiWindowsControl(b))) { - uiWindowsControlContinueMinimumSizeChanged(uiWindowsControl(b)); - return; - } - boxRelayout(b); -} - -static void uiBoxSetMinSize(uiControl *c, int w, int h) -{ - // checkme - uiBoxMinimumSizeChanged(uiWindowsControl(c)); -} - -uiWindowsControlDefaultLayoutRect(uiBox) -uiWindowsControlDefaultAssignControlIDZOrder(uiBox) - -static void uiBoxChildVisibilityChanged(uiWindowsControl *c) -{ - // TODO eliminate the redundancy - uiWindowsControlMinimumSizeChanged(c); -} - -static void boxArrangeChildren(uiBox *b) -{ - LONG_PTR controlID; - HWND insertAfter; - - controlID = 100; - insertAfter = NULL; - for (const struct boxChild &bc : *(b->controls)) - uiWindowsControlAssignControlIDZOrder(uiWindowsControl(bc.c), &controlID, &insertAfter); -} - -void uiBoxAppend(uiBox *b, uiControl *c, int stretchy) -{ - struct boxChild bc; - - bc.c = c; - bc.stretchy = stretchy; - uiControlSetParent(bc.c, uiControl(b)); - uiWindowsControlSetParentHWND(uiWindowsControl(bc.c), b->hwnd); - b->controls->push_back(bc); - boxArrangeChildren(b); - uiWindowsControlMinimumSizeChanged(uiWindowsControl(b)); -} - -void uiBoxDelete(uiBox *b, int index) -{ - uiControl *c; - - c = (*(b->controls))[index].c; - uiControlSetParent(c, NULL); - uiWindowsControlSetParentHWND(uiWindowsControl(c), NULL); - b->controls->erase(b->controls->begin() + index); - boxArrangeChildren(b); - uiWindowsControlMinimumSizeChanged(uiWindowsControl(b)); -} - -int uiBoxPadded(uiBox *b) -{ - return b->padded; -} - -void uiBoxSetPadded(uiBox *b, int padded) -{ - b->padded = padded; - uiWindowsControlMinimumSizeChanged(uiWindowsControl(b)); -} - -static void onResize(uiWindowsControl *c) -{ - boxRelayout(uiBox(c)); -} - -static uiBox *finishNewBox(int vertical) -{ - uiBox *b; - - uiWindowsNewControl(uiBox, b); - - b->hwnd = uiWindowsMakeContainer(uiWindowsControl(b), onResize); - - b->vertical = vertical; - b->controls = new std::vector; - - return b; -} - -uiBox *uiNewHorizontalBox(void) -{ - return finishNewBox(0); -} - -uiBox *uiNewVerticalBox(void) -{ - return finishNewBox(1); -} diff --git a/src/libui_sdl/libui/windows/button.cpp b/src/libui_sdl/libui/windows/button.cpp deleted file mode 100644 index aa34bfc..0000000 --- a/src/libui_sdl/libui/windows/button.cpp +++ /dev/null @@ -1,126 +0,0 @@ -// 7 april 2015 -#include "uipriv_windows.hpp" - -struct uiButton { - uiWindowsControl c; - HWND hwnd; - void (*onClicked)(uiButton *, void *); - void *onClickedData; - - SIZE idealSize; - int idealSizeCached; -}; - -static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult) -{ - uiButton *b = uiButton(c); - - if (code != BN_CLICKED) - return FALSE; - (*(b->onClicked))(b, b->onClickedData); - *lResult = 0; - return TRUE; -} - -static void uiButtonDestroy(uiControl *c) -{ - uiButton *b = uiButton(c); - - uiWindowsUnregisterWM_COMMANDHandler(b->hwnd); - uiWindowsEnsureDestroyWindow(b->hwnd); - uiFreeControl(uiControl(b)); -} - -uiWindowsControlAllDefaultsExceptDestroy(uiButton) - -// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing -#define buttonHeight 14 -#define buttonMinWidth 64 - -static void uiButtonMinimumSize(uiWindowsControl *c, int *width, int *height) -{ - uiButton *b = uiButton(c); - SIZE size; - uiWindowsSizing sizing; - int y; - - if (b->idealSizeCached) - { - *width = b->idealSize.cx; - *height = b->idealSize.cy; - return; - } - - // try the comctl32 version 6 way - size.cx = 0; // explicitly ask for ideal size - size.cy = 0; - if (SendMessageW(b->hwnd, BCM_GETIDEALSIZE, 0, (LPARAM) (&size)) != FALSE) { - *width = size.cx; - if (*width < buttonMinWidth) *width = buttonMinWidth; - *height = size.cy; - b->idealSize.cx = *width; - b->idealSize.cy = *height; - b->idealSizeCached = true; - return; - } - - // that didn't work; fall back to using Microsoft's metrics - // Microsoft says to use a fixed width for all buttons; this isn't good enough - // use the text width instead, with some edge padding - *width = uiWindowsWindowTextWidth(b->hwnd) + (2 * GetSystemMetrics(SM_CXEDGE)); - if (*width < buttonMinWidth) *width = buttonMinWidth; - y = buttonHeight; - uiWindowsGetSizing(b->hwnd, &sizing); - uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, &y); - *height = y; - b->idealSize.cx = *width; - b->idealSize.cy = *height; - b->idealSizeCached = true; -} - -static void defaultOnClicked(uiButton *b, void *data) -{ - // do nothing -} - -char *uiButtonText(uiButton *b) -{ - return uiWindowsWindowText(b->hwnd); -} - -void uiButtonSetText(uiButton *b, const char *text) -{ - uiWindowsSetWindowText(b->hwnd, text); - b->idealSizeCached = 0; - // changing the text might necessitate a change in the button's size - uiWindowsControlMinimumSizeChanged(uiWindowsControl(b)); -} - -void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *, void *), void *data) -{ - b->onClicked = f; - b->onClickedData = data; -} - -uiButton *uiNewButton(const char *text) -{ - uiButton *b; - WCHAR *wtext; - - uiWindowsNewControl(uiButton, b); - - wtext = toUTF16(text); - b->hwnd = uiWindowsEnsureCreateControlHWND(0, - L"button", wtext, - BS_PUSHBUTTON | WS_TABSTOP, - hInstance, NULL, - TRUE); - uiFree(wtext); - - uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b)); - uiButtonOnClicked(b, defaultOnClicked, NULL); - - b->idealSizeCached = 0; - - return b; -} diff --git a/src/libui_sdl/libui/windows/checkbox.cpp b/src/libui_sdl/libui/windows/checkbox.cpp deleted file mode 100644 index be425c0..0000000 --- a/src/libui_sdl/libui/windows/checkbox.cpp +++ /dev/null @@ -1,117 +0,0 @@ -// 7 april 2015 -#include "uipriv_windows.hpp" - -struct uiCheckbox { - uiWindowsControl c; - HWND hwnd; - void (*onToggled)(uiCheckbox *, void *); - void *onToggledData; -}; - -static BOOL onWM_COMMAND(uiControl *cc, HWND hwnd, WORD code, LRESULT *lResult) -{ - uiCheckbox *c = uiCheckbox(cc); - WPARAM check; - - if (code != BN_CLICKED) - return FALSE; - - // we didn't use BS_AUTOCHECKBOX (http://blogs.msdn.com/b/oldnewthing/archive/2014/05/22/10527522.aspx) so we have to manage the check state ourselves - check = BST_CHECKED; - if (SendMessage(c->hwnd, BM_GETCHECK, 0, 0) == BST_CHECKED) - check = BST_UNCHECKED; - SendMessage(c->hwnd, BM_SETCHECK, check, 0); - - (*(c->onToggled))(c, c->onToggledData); - *lResult = 0; - return TRUE; -} - -static void uiCheckboxDestroy(uiControl *cc) -{ - uiCheckbox *c = uiCheckbox(cc); - - uiWindowsUnregisterWM_COMMANDHandler(c->hwnd); - uiWindowsEnsureDestroyWindow(c->hwnd); - uiFreeControl(uiControl(c)); -} - -uiWindowsControlAllDefaultsExceptDestroy(uiCheckbox) - -// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing -#define checkboxHeight 10 -// from http://msdn.microsoft.com/en-us/library/windows/desktop/bb226818%28v=vs.85%29.aspx -#define checkboxXFromLeftOfBoxToLeftOfLabel 12 - -static void uiCheckboxMinimumSize(uiWindowsControl *cc, int *width, int *height) -{ - uiCheckbox *c = uiCheckbox(cc); - uiWindowsSizing sizing; - int x, y; - - x = checkboxXFromLeftOfBoxToLeftOfLabel; - y = checkboxHeight; - uiWindowsGetSizing(c->hwnd, &sizing); - uiWindowsSizingDlgUnitsToPixels(&sizing, &x, &y); - *width = x + uiWindowsWindowTextWidth(c->hwnd); - *height = y; -} - -static void defaultOnToggled(uiCheckbox *c, void *data) -{ - // do nothing -} - -char *uiCheckboxText(uiCheckbox *c) -{ - return uiWindowsWindowText(c->hwnd); -} - -void uiCheckboxSetText(uiCheckbox *c, const char *text) -{ - uiWindowsSetWindowText(c->hwnd, text); - // changing the text might necessitate a change in the checkbox's size - uiWindowsControlMinimumSizeChanged(uiWindowsControl(c)); -} - -void uiCheckboxOnToggled(uiCheckbox *c, void (*f)(uiCheckbox *, void *), void *data) -{ - c->onToggled = f; - c->onToggledData = data; -} - -int uiCheckboxChecked(uiCheckbox *c) -{ - return SendMessage(c->hwnd, BM_GETCHECK, 0, 0) == BST_CHECKED; -} - -void uiCheckboxSetChecked(uiCheckbox *c, int checked) -{ - WPARAM check; - - check = BST_CHECKED; - if (!checked) - check = BST_UNCHECKED; - SendMessage(c->hwnd, BM_SETCHECK, check, 0); -} - -uiCheckbox *uiNewCheckbox(const char *text) -{ - uiCheckbox *c; - WCHAR *wtext; - - uiWindowsNewControl(uiCheckbox, c); - - wtext = toUTF16(text); - c->hwnd = uiWindowsEnsureCreateControlHWND(0, - L"button", wtext, - BS_CHECKBOX | WS_TABSTOP, - hInstance, NULL, - TRUE); - uiFree(wtext); - - uiWindowsRegisterWM_COMMANDHandler(c->hwnd, onWM_COMMAND, uiControl(c)); - uiCheckboxOnToggled(c, defaultOnToggled, NULL); - - return c; -} diff --git a/src/libui_sdl/libui/windows/colorbutton.cpp b/src/libui_sdl/libui/windows/colorbutton.cpp deleted file mode 100644 index c1ba695..0000000 --- a/src/libui_sdl/libui/windows/colorbutton.cpp +++ /dev/null @@ -1,192 +0,0 @@ -// 16 may 2016 -#include "uipriv_windows.hpp" - -struct uiColorButton { - uiWindowsControl c; - HWND hwnd; - double r; - double g; - double b; - double a; - void (*onChanged)(uiColorButton *, void *); - void *onChangedData; -}; - -static void uiColorButtonDestroy(uiControl *c) -{ - uiColorButton *b = uiColorButton(c); - - uiWindowsUnregisterWM_COMMANDHandler(b->hwnd); - uiWindowsUnregisterWM_NOTIFYHandler(b->hwnd); - uiWindowsEnsureDestroyWindow(b->hwnd); - uiFreeControl(uiControl(b)); -} - -static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult) -{ - uiColorButton *b = uiColorButton(c); - HWND parent; - struct colorDialogRGBA rgba; - - if (code != BN_CLICKED) - return FALSE; - - parent = parentToplevel(b->hwnd); - rgba.r = b->r; - rgba.g = b->g; - rgba.b = b->b; - rgba.a = b->a; - if (showColorDialog(parent, &rgba)) { - b->r = rgba.r; - b->g = rgba.g; - b->b = rgba.b; - b->a = rgba.a; - invalidateRect(b->hwnd, NULL, TRUE); - (*(b->onChanged))(b, b->onChangedData); - } - - *lResult = 0; - return TRUE; -} - -static BOOL onWM_NOTIFY(uiControl *c, HWND hwnd, NMHDR *nmhdr, LRESULT *lResult) -{ - uiColorButton *b = uiColorButton(c); - NMCUSTOMDRAW *nm = (NMCUSTOMDRAW *) nmhdr; - RECT client; - ID2D1DCRenderTarget *rt; - D2D1_RECT_F r; - D2D1_COLOR_F color; - D2D1_BRUSH_PROPERTIES bprop; - ID2D1SolidColorBrush *brush; - uiWindowsSizing sizing; - int x, y; - HRESULT hr; - - if (nmhdr->code != NM_CUSTOMDRAW) - return FALSE; - // and allow the button to draw its background - if (nm->dwDrawStage != CDDS_PREPAINT) - return FALSE; - - uiWindowsEnsureGetClientRect(b->hwnd, &client); - rt = makeHDCRenderTarget(nm->hdc, &client); - rt->BeginDraw(); - - uiWindowsGetSizing(b->hwnd, &sizing); - x = 3; // should be enough - y = 3; - uiWindowsSizingDlgUnitsToPixels(&sizing, &x, &y); - r.left = client.left + x; - r.top = client.top + y; - r.right = client.right - x; - r.bottom = client.bottom - y; - - color.r = b->r; - color.g = b->g; - color.b = b->b; - color.a = b->a; - ZeroMemory(&bprop, sizeof (D2D1_BRUSH_PROPERTIES)); - bprop.opacity = 1.0; - bprop.transform._11 = 1; - bprop.transform._22 = 1; - hr = rt->CreateSolidColorBrush(&color, &bprop, &brush); - if (hr != S_OK) - logHRESULT(L"error creating brush for color button", hr); - rt->FillRectangle(&r, brush); - brush->Release(); - - hr = rt->EndDraw(NULL, NULL); - if (hr != S_OK) - logHRESULT(L"error drawing color on color button", hr); - rt->Release(); - - // skip default processing (don't draw text) - *lResult = CDRF_SKIPDEFAULT; - return TRUE; -} - -uiWindowsControlAllDefaultsExceptDestroy(uiColorButton) - -// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing -#define buttonHeight 14 - -// TODO check widths -static void uiColorButtonMinimumSize(uiWindowsControl *c, int *width, int *height) -{ - uiColorButton *b = uiColorButton(c); - SIZE size; - uiWindowsSizing sizing; - int y; - - // try the comctl32 version 6 way - size.cx = 0; // explicitly ask for ideal size - size.cy = 0; - if (SendMessageW(b->hwnd, BCM_GETIDEALSIZE, 0, (LPARAM) (&size)) != FALSE) { - *width = size.cx; - *height = size.cy; - return; - } - - // that didn't work; fall back to using Microsoft's metrics - // Microsoft says to use a fixed width for all buttons; this isn't good enough - // use the text width instead, with some edge padding - *width = uiWindowsWindowTextWidth(b->hwnd) + (2 * GetSystemMetrics(SM_CXEDGE)); - y = buttonHeight; - uiWindowsGetSizing(b->hwnd, &sizing); - uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, &y); - *height = y; -} - -static void defaultOnChanged(uiColorButton *b, void *data) -{ - // do nothing -} - -void uiColorButtonColor(uiColorButton *b, double *r, double *g, double *bl, double *a) -{ - *r = b->r; - *g = b->g; - *bl = b->b; - *a = b->a; -} - -void uiColorButtonSetColor(uiColorButton *b, double r, double g, double bl, double a) -{ - b->r = r; - b->g = g; - b->b = bl; - b->a = a; - invalidateRect(b->hwnd, NULL, TRUE); -} - -void uiColorButtonOnChanged(uiColorButton *b, void (*f)(uiColorButton *, void *), void *data) -{ - b->onChanged = f; - b->onChangedData = data; -} - -uiColorButton *uiNewColorButton(void) -{ - uiColorButton *b; - - uiWindowsNewControl(uiColorButton, b); - - // initial color is black - b->r = 0.0; - b->g = 0.0; - b->b = 0.0; - b->a = 1.0; - - b->hwnd = uiWindowsEnsureCreateControlHWND(0, - L"button", L" ", // TODO; can't use "" TODO - BS_PUSHBUTTON | WS_TABSTOP, - hInstance, NULL, - TRUE); - - uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b)); - uiWindowsRegisterWM_NOTIFYHandler(b->hwnd, onWM_NOTIFY, uiControl(b)); - uiColorButtonOnChanged(b, defaultOnChanged, NULL); - - return b; -} diff --git a/src/libui_sdl/libui/windows/colordialog.cpp b/src/libui_sdl/libui/windows/colordialog.cpp deleted file mode 100644 index 86d046d..0000000 --- a/src/libui_sdl/libui/windows/colordialog.cpp +++ /dev/null @@ -1,1255 +0,0 @@ -// 16 may 2016 -#include "uipriv_windows.hpp" - -// TODO should the d2dscratch programs capture mouse? - -struct colorDialog { - HWND hwnd; - - HWND svChooser; - HWND hSlider; - HWND preview; - HWND opacitySlider; - HWND editH; - HWND editS; - HWND editV; - HWND editRDouble, editRInt; - HWND editGDouble, editGInt; - HWND editBDouble, editBInt; - HWND editADouble, editAInt; - HWND editHex; - - double h; - double s; - double v; - double a; - struct colorDialogRGBA *out; - - BOOL updating; -}; - -// both of these are from the wikipedia page on HSV -// TODO what to do about negative h? -static void rgb2HSV(double r, double g, double b, double *h, double *s, double *v) -{ - double M, m; - int whichmax; - double c; - - M = r; - whichmax = 0; - if (M < g) { - M = g; - whichmax = 1; - } - if (M < b) { - M = b; - whichmax = 2; - } - m = r; - if (m > g) - m = g; - if (m > b) - m = b; - c = M - m; - - if (c == 0) - *h = 0; - else { - switch (whichmax) { - case 0: - *h = ((g - b) / c); - *h = fmod(*h, 6); - break; - case 1: - *h = ((b - r) / c) + 2; - break; - case 2: - *h = ((r - g) / c) + 4; - break; - } - *h /= 6; // put in range [0,1) - } - - *v = M; - - if (c == 0) - *s = 0; - else - *s = c / *v; -} - -// TODO negative R values? -static void hsv2RGB(double h, double s, double v, double *r, double *g, double *b) -{ - double c; - double hPrime; - int h60; - double x; - double m; - - c = v * s; - hPrime = h * 6; - h60 = (int) hPrime; // equivalent to splitting into 60° chunks - x = c * (1.0 - fabs(fmod(hPrime, 2) - 1.0)); - m = v - c; - switch (h60) { - case 0: - *r = c + m; - *g = x + m; - *b = m; - return; - case 1: - *r = x + m; - *g = c + m; - *b = m; - return; - case 2: - *r = m; - *g = c + m; - *b = x + m; - return; - case 3: - *r = m; - *g = x + m; - *b = c + m; - return; - case 4: - *r = x + m; - *g = m; - *b = c + m; - return; - case 5: - *r = c + m; - *g = m; - *b = x + m; - return; - } - // TODO -} - -#define hexd L"0123456789ABCDEF" - -static void rgba2Hex(uint8_t r, uint8_t g, uint8_t b, uint8_t a, WCHAR *buf) -{ - buf[0] = L'#'; - buf[1] = hexd[(a >> 4) & 0xF]; - buf[2] = hexd[a & 0xF]; - buf[3] = hexd[(r >> 4) & 0xF]; - buf[4] = hexd[r & 0xF]; - buf[5] = hexd[(g >> 4) & 0xF]; - buf[6] = hexd[g & 0xF]; - buf[7] = hexd[(b >> 4) & 0xF]; - buf[8] = hexd[b & 0xF]; - buf[9] = L'\0'; -} - -static int convHexDigit(WCHAR c) -{ - if (c >= L'0' && c <= L'9') - return c - L'0'; - if (c >= L'A' && c <= L'F') - return c - L'A' + 0xA; - if (c >= L'a' && c <= L'f') - return c - L'a' + 0xA; - return -1; -} - -// TODO allow #NNN shorthand -static BOOL hex2RGBA(WCHAR *buf, double *r, double *g, double *b, double *a) -{ - uint8_t component; - int i; - - if (*buf == L'#') - buf++; - - component = 0; - i = convHexDigit(*buf++); - if (i < 0) - return FALSE; - component |= ((uint8_t) i) << 4; - i = convHexDigit(*buf++); - if (i < 0) - return FALSE; - component |= ((uint8_t) i); - *a = ((double) component) / 255; - - component = 0; - i = convHexDigit(*buf++); - if (i < 0) - return FALSE; - component |= ((uint8_t) i) << 4; - i = convHexDigit(*buf++); - if (i < 0) - return FALSE; - component |= ((uint8_t) i); - *r = ((double) component) / 255; - - component = 0; - i = convHexDigit(*buf++); - if (i < 0) - return FALSE; - component |= ((uint8_t) i) << 4; - i = convHexDigit(*buf++); - if (i < 0) - return FALSE; - component |= ((uint8_t) i); - *g = ((double) component) / 255; - - if (*buf == L'\0') { // #NNNNNN syntax - *b = *g; - *g = *r; - *r = *a; - *a = 1; - return TRUE; - } - - component = 0; - i = convHexDigit(*buf++); - if (i < 0) - return FALSE; - component |= ((uint8_t) i) << 4; - i = convHexDigit(*buf++); - if (i < 0) - return FALSE; - component |= ((uint8_t) i); - *b = ((double) component) / 255; - - return *buf == L'\0'; -} - -static void updateDouble(HWND hwnd, double d, HWND whichChanged) -{ - WCHAR *str; - - if (whichChanged == hwnd) - return; - str = ftoutf16(d); - setWindowText(hwnd, str); - uiFree(str); -} - -static void updateDialog(struct colorDialog *c, HWND whichChanged) -{ - double r, g, b; - uint8_t rb, gb, bb, ab; - WCHAR *str; - WCHAR hexbuf[16]; // more than enough - - c->updating = TRUE; - - updateDouble(c->editH, c->h, whichChanged); - updateDouble(c->editS, c->s, whichChanged); - updateDouble(c->editV, c->v, whichChanged); - - hsv2RGB(c->h, c->s, c->v, &r, &g, &b); - - updateDouble(c->editRDouble, r, whichChanged); - updateDouble(c->editGDouble, g, whichChanged); - updateDouble(c->editBDouble, b, whichChanged); - updateDouble(c->editADouble, c->a, whichChanged); - - rb = (uint8_t) (r * 255); - gb = (uint8_t) (g * 255); - bb = (uint8_t) (b * 255); - ab = (uint8_t) (c->a * 255); - - if (whichChanged != c->editRInt) { - str = itoutf16(rb); - setWindowText(c->editRInt, str); - uiFree(str); - } - if (whichChanged != c->editGInt) { - str = itoutf16(gb); - setWindowText(c->editGInt, str); - uiFree(str); - } - if (whichChanged != c->editBInt) { - str = itoutf16(bb); - setWindowText(c->editBInt, str); - uiFree(str); - } - if (whichChanged != c->editAInt) { - str = itoutf16(ab); - setWindowText(c->editAInt, str); - uiFree(str); - } - - if (whichChanged != c->editHex) { - rgba2Hex(rb, gb, bb, ab, hexbuf); - setWindowText(c->editHex, hexbuf); - } - - // TODO TRUE? - invalidateRect(c->svChooser, NULL, TRUE); - invalidateRect(c->hSlider, NULL, TRUE); - invalidateRect(c->preview, NULL, TRUE); - invalidateRect(c->opacitySlider, NULL, TRUE); - - c->updating = FALSE; -} - -// this imitates http://blogs.msdn.com/b/wpfsdk/archive/2006/10/26/uncommon-dialogs--font-chooser-and-color-picker-dialogs.aspx -static void drawGrid(ID2D1RenderTarget *rt, D2D1_RECT_F *fillRect) -{ - D2D1_SIZE_F size; - D2D1_PIXEL_FORMAT pformat; - ID2D1BitmapRenderTarget *brt; - D2D1_COLOR_F color; - D2D1_BRUSH_PROPERTIES bprop; - ID2D1SolidColorBrush *brush; - D2D1_RECT_F rect; - ID2D1Bitmap *bitmap; - D2D1_BITMAP_BRUSH_PROPERTIES bbp; - ID2D1BitmapBrush *bb; - HRESULT hr; - - // mind the divisions; they represent the fact the original uses a viewport - size.width = 100 / 10; - size.height = 100 / 10; - // yay more ABI bugs - - pformat = rt->GetPixelFormat(); - - hr = rt->CreateCompatibleRenderTarget(&size, NULL, - &pformat, D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_NONE, - &brt); - if (hr != S_OK) - logHRESULT(L"error creating render target for grid", hr); - - brt->BeginDraw(); - - color.r = 1.0; - color.g = 1.0; - color.b = 1.0; - color.a = 1.0; - brt->Clear(&color); - - color = D2D1::ColorF(D2D1::ColorF::LightGray, 1.0); - ZeroMemory(&bprop, sizeof (D2D1_BRUSH_PROPERTIES)); - bprop.opacity = 1.0; - bprop.transform._11 = 1; - bprop.transform._22 = 1; - hr = brt->CreateSolidColorBrush(&color, &bprop, &brush); - if (hr != S_OK) - logHRESULT(L"error creating brush for grid", hr); - rect.left = 0; - rect.top = 0; - rect.right = 50 / 10; - rect.bottom = 50 / 10; - brt->FillRectangle(&rect, brush); - rect.left = 50 / 10; - rect.top = 50 / 10; - rect.right = 100 / 10; - rect.bottom = 100 / 10; - brt->FillRectangle(&rect, brush); - brush->Release(); - - hr = brt->EndDraw(NULL, NULL); - if (hr != S_OK) - logHRESULT(L"error finalizing render target for grid", hr); - hr = brt->GetBitmap(&bitmap); - if (hr != S_OK) - logHRESULT(L"error getting bitmap for grid", hr); - brt->Release(); - - ZeroMemory(&bbp, sizeof (D2D1_BITMAP_BRUSH_PROPERTIES)); - bbp.extendModeX = D2D1_EXTEND_MODE_WRAP; - bbp.extendModeY = D2D1_EXTEND_MODE_WRAP; - bbp.interpolationMode = D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR; - hr = rt->CreateBitmapBrush(bitmap, &bbp, &bprop, &bb); - if (hr != S_OK) - logHRESULT(L"error creating bitmap brush for grid", hr); - rt->FillRectangle(fillRect, bb); - bb->Release(); - bitmap->Release(); -} - -// this interesting approach comes from http://blogs.msdn.com/b/wpfsdk/archive/2006/10/26/uncommon-dialogs--font-chooser-and-color-picker-dialogs.aspx -static void drawSVChooser(struct colorDialog *c, ID2D1RenderTarget *rt) -{ - D2D1_SIZE_F size; - D2D1_RECT_F rect; - double rTop, gTop, bTop; - D2D1_GRADIENT_STOP stops[2]; - ID2D1GradientStopCollection *collection; - D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES lprop; - D2D1_BRUSH_PROPERTIES bprop; - ID2D1LinearGradientBrush *brush; - ID2D1LinearGradientBrush *opacity; - ID2D1Layer *layer; - D2D1_LAYER_PARAMETERS layerparams; - D2D1_ELLIPSE mparam; - D2D1_COLOR_F mcolor; - ID2D1SolidColorBrush *markerBrush; - HRESULT hr; - - size = realGetSize(rt); - rect.left = 0; - rect.top = 0; - rect.right = size.width; - rect.bottom = size.height; - - drawGrid(rt, &rect); - - // first, draw a vertical gradient from the current hue at max S/V to black - // the source example draws it upside down; let's do so too just to be safe - hsv2RGB(c->h, 1.0, 1.0, &rTop, &gTop, &bTop); - stops[0].position = 0; - stops[0].color.r = 0.0; - stops[0].color.g = 0.0; - stops[0].color.b = 0.0; - stops[0].color.a = 1.0; - stops[1].position = 1; - stops[1].color.r = rTop; - stops[1].color.g = gTop; - stops[1].color.b = bTop; - stops[1].color.a = 1.0; - hr = rt->CreateGradientStopCollection(stops, 2, - D2D1_GAMMA_2_2, D2D1_EXTEND_MODE_CLAMP, - &collection); - if (hr != S_OK) - logHRESULT(L"error making gradient stop collection for first gradient in SV chooser", hr); - ZeroMemory(&lprop, sizeof (D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES)); - lprop.startPoint.x = size.width / 2; - lprop.startPoint.y = size.height; - lprop.endPoint.x = size.width / 2; - lprop.endPoint.y = 0; - // TODO decide what to do about the duplication of this - ZeroMemory(&bprop, sizeof (D2D1_BRUSH_PROPERTIES)); - bprop.opacity = c->a; // note this part; we also use it below for the layer - bprop.transform._11 = 1; - bprop.transform._22 = 1; - hr = rt->CreateLinearGradientBrush(&lprop, &bprop, - collection, &brush); - if (hr != S_OK) - logHRESULT(L"error making gradient brush for first gradient in SV chooser", hr); - rt->FillRectangle(&rect, brush); - brush->Release(); - collection->Release(); - - // second, create an opacity mask for the third step: a horizontal gradientthat goes from opaque to translucent - stops[0].position = 0; - stops[0].color.r = 0.0; - stops[0].color.g = 0.0; - stops[0].color.b = 0.0; - stops[0].color.a = 1.0; - stops[1].position = 1; - stops[1].color.r = 0.0; - stops[1].color.g = 0.0; - stops[1].color.b = 0.0; - stops[1].color.a = 0.0; - hr = rt->CreateGradientStopCollection(stops, 2, - D2D1_GAMMA_2_2, D2D1_EXTEND_MODE_CLAMP, - &collection); - if (hr != S_OK) - logHRESULT(L"error making gradient stop collection for opacity mask gradient in SV chooser", hr); - ZeroMemory(&lprop, sizeof (D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES)); - lprop.startPoint.x = 0; - lprop.startPoint.y = size.height / 2; - lprop.endPoint.x = size.width; - lprop.endPoint.y = size.height / 2; - ZeroMemory(&bprop, sizeof (D2D1_BRUSH_PROPERTIES)); - bprop.opacity = 1.0; - bprop.transform._11 = 1; - bprop.transform._22 = 1; - hr = rt->CreateLinearGradientBrush(&lprop, &bprop, - collection, &opacity); - if (hr != S_OK) - logHRESULT(L"error making gradient brush for opacity mask gradient in SV chooser", hr); - collection->Release(); - - // finally, make a vertical gradient from white at the top to black at the bottom (right side up this time) and with the previous opacity mask - stops[0].position = 0; - stops[0].color.r = 1.0; - stops[0].color.g = 1.0; - stops[0].color.b = 1.0; - stops[0].color.a = 1.0; - stops[1].position = 1; - stops[1].color.r = 0.0; - stops[1].color.g = 0.0; - stops[1].color.b = 0.0; - stops[1].color.a = 1.0; - hr = rt->CreateGradientStopCollection(stops, 2, - D2D1_GAMMA_2_2, D2D1_EXTEND_MODE_CLAMP, - &collection); - if (hr != S_OK) - logHRESULT(L"error making gradient stop collection for second gradient in SV chooser", hr); - ZeroMemory(&lprop, sizeof (D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES)); - lprop.startPoint.x = size.width / 2; - lprop.startPoint.y = 0; - lprop.endPoint.x = size.width / 2; - lprop.endPoint.y = size.height; - ZeroMemory(&bprop, sizeof (D2D1_BRUSH_PROPERTIES)); - bprop.opacity = 1.0; - bprop.transform._11 = 1; - bprop.transform._22 = 1; - hr = rt->CreateLinearGradientBrush(&lprop, &bprop, - collection, &brush); - if (hr != S_OK) - logHRESULT(L"error making gradient brush for second gradient in SV chooser", hr); - // oh but wait we can't use FillRectangle() with an opacity mask - // and we can't use FillGeometry() with both an opacity mask and a non-bitmap - // layers it is! - hr = rt->CreateLayer(&size, &layer); - if (hr != S_OK) - logHRESULT(L"error making layer for second gradient in SV chooser", hr); - ZeroMemory(&layerparams, sizeof (D2D1_LAYER_PARAMETERS)); - layerparams.contentBounds = rect; - // TODO make sure these are right - layerparams.geometricMask = NULL; - layerparams.maskAntialiasMode = D2D1_ANTIALIAS_MODE_PER_PRIMITIVE; - layerparams.maskTransform._11 = 1; - layerparams.maskTransform._22 = 1; - layerparams.opacity = c->a; // here's the other use of c->a to note - layerparams.opacityBrush = opacity; - layerparams.layerOptions = D2D1_LAYER_OPTIONS_NONE; - rt->PushLayer(&layerparams, layer); - rt->FillRectangle(&rect, brush); - rt->PopLayer(); - layer->Release(); - brush->Release(); - collection->Release(); - opacity->Release(); - - // and now we just draw the marker - ZeroMemory(&mparam, sizeof (D2D1_ELLIPSE)); - mparam.point.x = c->s * size.width; - mparam.point.y = (1 - c->v) * size.height; - mparam.radiusX = 7; - mparam.radiusY = 7; - // TODO make the color contrast? - mcolor.r = 1.0; - mcolor.g = 1.0; - mcolor.b = 1.0; - mcolor.a = 1.0; - bprop.opacity = 1.0; // the marker should always be opaque - hr = rt->CreateSolidColorBrush(&mcolor, &bprop, &markerBrush); - if (hr != S_OK) - logHRESULT(L"error creating brush for SV chooser marker", hr); - rt->DrawEllipse(&mparam, markerBrush, 2, NULL); - markerBrush->Release(); -} - -static LRESULT CALLBACK svChooserSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) -{ - ID2D1RenderTarget *rt; - struct colorDialog *c; - D2D1_POINT_2F *pos; - D2D1_SIZE_F *size; - - c = (struct colorDialog *) dwRefData; - switch (uMsg) { - case msgD2DScratchPaint: - rt = (ID2D1RenderTarget *) lParam; - drawSVChooser(c, rt); - return 0; - case msgD2DScratchLButtonDown: - pos = (D2D1_POINT_2F *) wParam; - size = (D2D1_SIZE_F *) lParam; - c->s = pos->x / size->width; - c->v = 1 - (pos->y / size->height); - updateDialog(c, NULL); - return 0; - case WM_NCDESTROY: - if (RemoveWindowSubclass(hwnd, svChooserSubProc, uIdSubclass) == FALSE) - logLastError(L"error removing color dialog SV chooser subclass"); - break; - } - return DefSubclassProc(hwnd, uMsg, wParam, lParam); -} - -static void drawArrow(ID2D1RenderTarget *rt, D2D1_POINT_2F center, double hypot) -{ - double leg; - D2D1_RECT_F rect; - D2D1_MATRIX_3X2_F oldtf, rotate; - D2D1_COLOR_F color; - D2D1_BRUSH_PROPERTIES bprop; - ID2D1SolidColorBrush *brush; - HRESULT hr; - - // to avoid needing a geometry, this will just be a rotated square - // compute the length of each side; the diagonal of the square is 2 * offset to gradient - // a^2 + a^2 = c^2 -> 2a^2 = c^2 - // a = sqrt(c^2/2) - hypot *= hypot; - hypot /= 2; - leg = sqrt(hypot); - rect.left = center.x - leg; - rect.top = center.y - leg; - rect.right = center.x + leg; - rect.bottom = center.y + leg; - - // now we need to rotate the render target 45° (either way works) about the center point - rt->GetTransform(&oldtf); - rotate = oldtf * D2D1::Matrix3x2F::Rotation(45, center); - rt->SetTransform(&rotate); - - // and draw - color.r = 0.0; - color.g = 0.0; - color.b = 0.0; - color.a = 1.0; - ZeroMemory(&bprop, sizeof (D2D1_BRUSH_PROPERTIES)); - bprop.opacity = 1.0; - bprop.transform._11 = 1; - bprop.transform._22 = 1; - hr = rt->CreateSolidColorBrush(&color, &bprop, &brush); - if (hr != S_OK) - logHRESULT(L"error creating brush for arrow", hr); - rt->FillRectangle(&rect, brush); - brush->Release(); - - // clean up - rt->SetTransform(&oldtf); -} - -// the gradient stuff also comes from http://blogs.msdn.com/b/wpfsdk/archive/2006/10/26/uncommon-dialogs--font-chooser-and-color-picker-dialogs.aspx -#define nStops (30) -#define degPerStop (360 / nStops) -#define stopIncr (1.0 / ((double) nStops)) - -static void drawHSlider(struct colorDialog *c, ID2D1RenderTarget *rt) -{ - D2D1_SIZE_F size; - D2D1_RECT_F rect; - D2D1_GRADIENT_STOP stops[nStops]; - double r, g, b; - int i; - double h; - ID2D1GradientStopCollection *collection; - D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES lprop; - D2D1_BRUSH_PROPERTIES bprop; - ID2D1LinearGradientBrush *brush; - double hypot; - D2D1_POINT_2F center; - HRESULT hr; - - size = realGetSize(rt); - rect.left = size.width / 6; // leftmost sixth for arrow - rect.top = 0; - rect.right = size.width; - rect.bottom = size.height; - - for (i = 0; i < nStops; i++) { - h = ((double) (i * degPerStop)) / 360.0; - if (i == (nStops - 1)) - h = 0; - hsv2RGB(h, 1.0, 1.0, &r, &g, &b); - stops[i].position = ((double) i) * stopIncr; - stops[i].color.r = r; - stops[i].color.g = g; - stops[i].color.b = b; - stops[i].color.a = 1.0; - } - // and pin the last one - stops[i - 1].position = 1.0; - - hr = rt->CreateGradientStopCollection(stops, nStops, - // note that in this case this gamma is explicitly specified by the original - D2D1_GAMMA_2_2, D2D1_EXTEND_MODE_CLAMP, - &collection); - if (hr != S_OK) - logHRESULT(L"error creating stop collection for H slider gradient", hr); - ZeroMemory(&lprop, sizeof (D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES)); - lprop.startPoint.x = (rect.right - rect.left) / 2; - lprop.startPoint.y = 0; - lprop.endPoint.x = (rect.right - rect.left) / 2; - lprop.endPoint.y = size.height; - ZeroMemory(&bprop, sizeof (D2D1_BRUSH_PROPERTIES)); - bprop.opacity = 1.0; - bprop.transform._11 = 1; - bprop.transform._22 = 1; - hr = rt->CreateLinearGradientBrush(&lprop, &bprop, - collection, &brush); - if (hr != S_OK) - logHRESULT(L"error creating gradient brush for H slider", hr); - rt->FillRectangle(&rect, brush); - brush->Release(); - collection->Release(); - - // now draw a black arrow - center.x = 0; - center.y = c->h * size.height; - hypot = rect.left; - drawArrow(rt, center, hypot); -} - -static LRESULT CALLBACK hSliderSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) -{ - ID2D1RenderTarget *rt; - struct colorDialog *c; - D2D1_POINT_2F *pos; - D2D1_SIZE_F *size; - - c = (struct colorDialog *) dwRefData; - switch (uMsg) { - case msgD2DScratchPaint: - rt = (ID2D1RenderTarget *) lParam; - drawHSlider(c, rt); - return 0; - case msgD2DScratchLButtonDown: - pos = (D2D1_POINT_2F *) wParam; - size = (D2D1_SIZE_F *) lParam; - c->h = pos->y / size->height; - updateDialog(c, NULL); - return 0; - case WM_NCDESTROY: - if (RemoveWindowSubclass(hwnd, hSliderSubProc, uIdSubclass) == FALSE) - logLastError(L"error removing color dialog H slider subclass"); - break; - } - return DefSubclassProc(hwnd, uMsg, wParam, lParam); -} - -static void drawPreview(struct colorDialog *c, ID2D1RenderTarget *rt) -{ - D2D1_SIZE_F size; - D2D1_RECT_F rect; - double r, g, b; - D2D1_COLOR_F color; - D2D1_BRUSH_PROPERTIES bprop; - ID2D1SolidColorBrush *brush; - HRESULT hr; - - size = realGetSize(rt); - rect.left = 0; - rect.top = 0; - rect.right = size.width; - rect.bottom = size.height; - - drawGrid(rt, &rect); - - hsv2RGB(c->h, c->s, c->v, &r, &g, &b); - color.r = r; - color.g = g; - color.b = b; - color.a = c->a; - ZeroMemory(&bprop, sizeof (D2D1_BRUSH_PROPERTIES)); - bprop.opacity = 1.0; - bprop.transform._11 = 1; - bprop.transform._22 = 1; - hr = rt->CreateSolidColorBrush(&color, &bprop, &brush); - if (hr != S_OK) - logHRESULT(L"error creating brush for preview", hr); - rt->FillRectangle(&rect, brush); - brush->Release(); -} - -static LRESULT CALLBACK previewSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) -{ - ID2D1RenderTarget *rt; - struct colorDialog *c; - - c = (struct colorDialog *) dwRefData; - switch (uMsg) { - case msgD2DScratchPaint: - rt = (ID2D1RenderTarget *) lParam; - drawPreview(c, rt); - return 0; - case WM_NCDESTROY: - if (RemoveWindowSubclass(hwnd, previewSubProc, uIdSubclass) == FALSE) - logLastError(L"error removing color dialog previewer subclass"); - break; - } - return DefSubclassProc(hwnd, uMsg, wParam, lParam); -} - -// once again, this is based on the Microsoft sample above -static void drawOpacitySlider(struct colorDialog *c, ID2D1RenderTarget *rt) -{ - D2D1_SIZE_F size; - D2D1_RECT_F rect; - D2D1_GRADIENT_STOP stops[2]; - ID2D1GradientStopCollection *collection; - D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES lprop; - D2D1_BRUSH_PROPERTIES bprop; - ID2D1LinearGradientBrush *brush; - double hypot; - D2D1_POINT_2F center; - HRESULT hr; - - size = realGetSize(rt); - rect.left = 0; - rect.top = 0; - rect.right = size.width; - rect.bottom = size.height * (5.0 / 6.0); // bottommost sixth for arrow - - drawGrid(rt, &rect); - - stops[0].position = 0.0; - stops[0].color.r = 0.0; - stops[0].color.g = 0.0; - stops[0].color.b = 0.0; - stops[0].color.a = 1.0; - stops[1].position = 1.0; - stops[1].color.r = 1.0; // this is the XAML color Transparent, as in the source - stops[1].color.g = 1.0; - stops[1].color.b = 1.0; - stops[1].color.a = 0.0; - hr = rt->CreateGradientStopCollection(stops, 2, - // note that in this case this gamma is explicitly specified by the original - D2D1_GAMMA_2_2, D2D1_EXTEND_MODE_CLAMP, - &collection); - if (hr != S_OK) - logHRESULT(L"error creating stop collection for opacity slider gradient", hr); - ZeroMemory(&lprop, sizeof (D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES)); - lprop.startPoint.x = 0; - lprop.startPoint.y = (rect.bottom - rect.top) / 2; - lprop.endPoint.x = size.width; - lprop.endPoint.y = (rect.bottom - rect.top) / 2; - ZeroMemory(&bprop, sizeof (D2D1_BRUSH_PROPERTIES)); - bprop.opacity = 1.0; - bprop.transform._11 = 1; - bprop.transform._22 = 1; - hr = rt->CreateLinearGradientBrush(&lprop, &bprop, - collection, &brush); - if (hr != S_OK) - logHRESULT(L"error creating gradient brush for opacity slider", hr); - rt->FillRectangle(&rect, brush); - brush->Release(); - collection->Release(); - - // now draw a black arrow - center.x = (1 - c->a) * size.width; - center.y = size.height; - hypot = size.height - rect.bottom; - drawArrow(rt, center, hypot); -} - -static LRESULT CALLBACK opacitySliderSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) -{ - ID2D1RenderTarget *rt; - struct colorDialog *c; - D2D1_POINT_2F *pos; - D2D1_SIZE_F *size; - - c = (struct colorDialog *) dwRefData; - switch (uMsg) { - case msgD2DScratchPaint: - rt = (ID2D1RenderTarget *) lParam; - drawOpacitySlider(c, rt); - return 0; - case msgD2DScratchLButtonDown: - pos = (D2D1_POINT_2F *) wParam; - size = (D2D1_SIZE_F *) lParam; - c->a = 1 - (pos->x / size->width); - updateDialog(c, NULL); - return 0; - case WM_NCDESTROY: - if (RemoveWindowSubclass(hwnd, opacitySliderSubProc, uIdSubclass) == FALSE) - logLastError(L"error removing color dialog opacity slider subclass"); - break; - } - return DefSubclassProc(hwnd, uMsg, wParam, lParam); -} - -// TODO extract into d2dscratch.cpp, use in font dialog -HWND replaceWithD2DScratch(HWND parent, int id, SUBCLASSPROC subproc, void *data) -{ - HWND replace; - RECT r; - - replace = getDlgItem(parent, id); - uiWindowsEnsureGetWindowRect(replace, &r); - mapWindowRect(NULL, parent, &r); - uiWindowsEnsureDestroyWindow(replace); - return newD2DScratch(parent, &r, (HMENU) id, subproc, (DWORD_PTR) data); - // TODO preserve Z-order -} - -// a few issues: -// - some controls are positioned wrong; see http://stackoverflow.com/questions/37263267/why-are-some-of-my-controls-positioned-slightly-off-in-a-dialog-template-in-a-re -// - labels are too low; need to adjust them by the font's internal leading -// fixupControlPositions() and the following helper routines fix that for us - -static LONG offsetTo(HWND a, HWND b) -{ - RECT ra, rb; - - uiWindowsEnsureGetWindowRect(a, &ra); - uiWindowsEnsureGetWindowRect(b, &rb); - return rb.top - ra.bottom; -} - -static void moveWindowsUp(struct colorDialog *c, LONG by, ...) -{ - va_list ap; - HWND cur; - RECT r; - - va_start(ap, by); - for (;;) { - cur = va_arg(ap, HWND); - if (cur == NULL) - break; - uiWindowsEnsureGetWindowRect(cur, &r); - mapWindowRect(NULL, c->hwnd, &r); - r.top -= by; - r.bottom -= by; - // TODO this isn't technically during a resize - uiWindowsEnsureMoveWindowDuringResize(cur, - r.left, r.top, - r.right - r.left, r.bottom - r.top); - } - va_end(ap); -} - -static void fixupControlPositions(struct colorDialog *c) -{ - HWND labelH; - HWND labelS; - HWND labelV; - HWND labelR; - HWND labelG; - HWND labelB; - HWND labelA; - HWND labelHex; - LONG offset; - uiWindowsSizing sizing; - - labelH = getDlgItem(c->hwnd, rcHLabel); - labelS = getDlgItem(c->hwnd, rcSLabel); - labelV = getDlgItem(c->hwnd, rcVLabel); - labelR = getDlgItem(c->hwnd, rcRLabel); - labelG = getDlgItem(c->hwnd, rcGLabel); - labelB = getDlgItem(c->hwnd, rcBLabel); - labelA = getDlgItem(c->hwnd, rcALabel); - labelHex = getDlgItem(c->hwnd, rcHexLabel); - - offset = offsetTo(c->editH, c->editS); - moveWindowsUp(c, offset, - labelS, c->editS, - labelG, c->editGDouble, c->editGInt, - NULL); - offset = offsetTo(c->editS, c->editV); - moveWindowsUp(c, offset, - labelV, c->editV, - labelB, c->editBDouble, c->editBInt, - NULL); - offset = offsetTo(c->editBDouble, c->editADouble); - moveWindowsUp(c, offset, - labelA, c->editADouble, c->editAInt, - NULL); - - getSizing(c->hwnd, &sizing, (HFONT) SendMessageW(labelH, WM_GETFONT, 0, 0)); - offset = sizing.InternalLeading; - moveWindowsUp(c, offset, - labelH, labelS, labelV, - labelR, labelG, labelB, labelA, - labelHex, - NULL); -} - -static struct colorDialog *beginColorDialog(HWND hwnd, LPARAM lParam) -{ - struct colorDialog *c; - - c = uiNew(struct colorDialog); - c->hwnd = hwnd; - c->out = (struct colorDialogRGBA *) lParam; - // load initial values now - rgb2HSV(c->out->r, c->out->g, c->out->b, &(c->h), &(c->s), &(c->v)); - c->a = c->out->a; - - // TODO set up d2dscratches - - // TODO prefix all these with rcColor instead of just rc - c->editH = getDlgItem(c->hwnd, rcH); - c->editS = getDlgItem(c->hwnd, rcS); - c->editV = getDlgItem(c->hwnd, rcV); - c->editRDouble = getDlgItem(c->hwnd, rcRDouble); - c->editRInt = getDlgItem(c->hwnd, rcRInt); - c->editGDouble = getDlgItem(c->hwnd, rcGDouble); - c->editGInt = getDlgItem(c->hwnd, rcGInt); - c->editBDouble = getDlgItem(c->hwnd, rcBDouble); - c->editBInt = getDlgItem(c->hwnd, rcBInt); - c->editADouble = getDlgItem(c->hwnd, rcADouble); - c->editAInt = getDlgItem(c->hwnd, rcAInt); - c->editHex = getDlgItem(c->hwnd, rcHex); - - c->svChooser = replaceWithD2DScratch(c->hwnd, rcColorSVChooser, svChooserSubProc, c); - c->hSlider = replaceWithD2DScratch(c->hwnd, rcColorHSlider, hSliderSubProc, c); - c->preview = replaceWithD2DScratch(c->hwnd, rcPreview, previewSubProc, c); - c->opacitySlider = replaceWithD2DScratch(c->hwnd, rcOpacitySlider, opacitySliderSubProc, c); - - fixupControlPositions(c); - - // and get the ball rolling - updateDialog(c, NULL); - return c; -} - -static void endColorDialog(struct colorDialog *c, INT_PTR code) -{ - if (EndDialog(c->hwnd, code) == 0) - logLastError(L"error ending color dialog"); - uiFree(c); -} - -// TODO make this void on the font dialog too -static void tryFinishDialog(struct colorDialog *c, WPARAM wParam) -{ - // cancelling - if (LOWORD(wParam) != IDOK) { - endColorDialog(c, 1); - return; - } - - // OK - hsv2RGB(c->h, c->s, c->v, &(c->out->r), &(c->out->g), &(c->out->b)); - c->out->a = c->a; - endColorDialog(c, 2); -} - -static double editDouble(HWND hwnd) -{ - WCHAR *s; - double d; - - s = windowText(hwnd); - d = _wtof(s); - uiFree(s); - return d; -} - -static void hChanged(struct colorDialog *c) -{ - double h; - - h = editDouble(c->editH); - if (h < 0 || h >= 1.0) // note the >= - return; - c->h = h; - updateDialog(c, c->editH); -} - -static void sChanged(struct colorDialog *c) -{ - double s; - - s = editDouble(c->editS); - if (s < 0 || s > 1) - return; - c->s = s; - updateDialog(c, c->editS); -} - -static void vChanged(struct colorDialog *c) -{ - double v; - - v = editDouble(c->editV); - if (v < 0 || v > 1) - return; - c->v = v; - updateDialog(c, c->editV); -} - -static void rDoubleChanged(struct colorDialog *c) -{ - double r, g, b; - - hsv2RGB(c->h, c->s, c->v, &r, &g, &b); - r = editDouble(c->editRDouble); - if (r < 0 || r > 1) - return; - rgb2HSV(r, g, b, &(c->h), &(c->s), &(c->v)); - updateDialog(c, c->editRDouble); -} - -static void gDoubleChanged(struct colorDialog *c) -{ - double r, g, b; - - hsv2RGB(c->h, c->s, c->v, &r, &g, &b); - g = editDouble(c->editGDouble); - if (g < 0 || g > 1) - return; - rgb2HSV(r, g, b, &(c->h), &(c->s), &(c->v)); - updateDialog(c, c->editGDouble); -} - -static void bDoubleChanged(struct colorDialog *c) -{ - double r, g, b; - - hsv2RGB(c->h, c->s, c->v, &r, &g, &b); - b = editDouble(c->editBDouble); - if (b < 0 || b > 1) - return; - rgb2HSV(r, g, b, &(c->h), &(c->s), &(c->v)); - updateDialog(c, c->editBDouble); -} - -static void aDoubleChanged(struct colorDialog *c) -{ - double a; - - a = editDouble(c->editADouble); - if (a < 0 || a > 1) - return; - c->a = a; - updateDialog(c, c->editADouble); -} - -static int editInt(HWND hwnd) -{ - WCHAR *s; - int i; - - s = windowText(hwnd); - i = _wtoi(s); - uiFree(s); - return i; -} - -static void rIntChanged(struct colorDialog *c) -{ - double r, g, b; - int i; - - hsv2RGB(c->h, c->s, c->v, &r, &g, &b); - i = editInt(c->editRInt); - if (i < 0 || i > 255) - return; - r = ((double) i) / 255.0; - rgb2HSV(r, g, b, &(c->h), &(c->s), &(c->v)); - updateDialog(c, c->editRInt); -} - -static void gIntChanged(struct colorDialog *c) -{ - double r, g, b; - int i; - - hsv2RGB(c->h, c->s, c->v, &r, &g, &b); - i = editInt(c->editGInt); - if (i < 0 || i > 255) - return; - g = ((double) i) / 255.0; - rgb2HSV(r, g, b, &(c->h), &(c->s), &(c->v)); - updateDialog(c, c->editGInt); -} - -static void bIntChanged(struct colorDialog *c) -{ - double r, g, b; - int i; - - hsv2RGB(c->h, c->s, c->v, &r, &g, &b); - i = editInt(c->editBInt); - if (i < 0 || i > 255) - return; - b = ((double) i) / 255.0; - rgb2HSV(r, g, b, &(c->h), &(c->s), &(c->v)); - updateDialog(c, c->editBInt); -} - -static void aIntChanged(struct colorDialog *c) -{ - int a; - - a = editInt(c->editAInt); - if (a < 0 || a > 255) - return; - c->a = ((double) a) / 255; - updateDialog(c, c->editAInt); -} - -static void hexChanged(struct colorDialog *c) -{ - WCHAR *buf; - double r, g, b, a; - BOOL is; - - buf = windowText(c->editHex); - is = hex2RGBA(buf, &r, &g, &b, &a); - uiFree(buf); - if (!is) - return; - rgb2HSV(r, g, b, &(c->h), &(c->s), &(c->v)); - c->a = a; - updateDialog(c, c->editHex); -} - -// TODO change fontdialog to use this -// note that if we make this const, we get lots of weird compiler errors -static std::map changed = { - { rcH, hChanged }, - { rcS, sChanged }, - { rcV, vChanged }, - { rcRDouble, rDoubleChanged }, - { rcGDouble, gDoubleChanged }, - { rcBDouble, bDoubleChanged }, - { rcADouble, aDoubleChanged }, - { rcRInt, rIntChanged }, - { rcGInt, gIntChanged }, - { rcBInt, bIntChanged }, - { rcAInt, aIntChanged }, - { rcHex, hexChanged }, -}; - -static INT_PTR CALLBACK colorDialogDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - struct colorDialog *c; - - c = (struct colorDialog *) GetWindowLongPtrW(hwnd, DWLP_USER); - if (c == NULL) { - if (uMsg == WM_INITDIALOG) { - c = beginColorDialog(hwnd, lParam); - SetWindowLongPtrW(hwnd, DWLP_USER, (LONG_PTR) c); - return TRUE; - } - return FALSE; - } - - switch (uMsg) { - case WM_COMMAND: - SetWindowLongPtrW(c->hwnd, DWLP_MSGRESULT, 0); // just in case - switch (LOWORD(wParam)) { - case IDOK: - case IDCANCEL: - if (HIWORD(wParam) != BN_CLICKED) - return FALSE; - tryFinishDialog(c, wParam); - return TRUE; - case rcH: - case rcS: - case rcV: - case rcRDouble: - case rcGDouble: - case rcBDouble: - case rcADouble: - case rcRInt: - case rcGInt: - case rcBInt: - case rcAInt: - case rcHex: - if (HIWORD(wParam) != EN_CHANGE) - return FALSE; - if (c->updating) // prevent infinite recursion during an update - return FALSE; - (*(changed[LOWORD(wParam)]))(c); - return TRUE; - } - return FALSE; - } - return FALSE; -} - -BOOL showColorDialog(HWND parent, struct colorDialogRGBA *c) -{ - switch (DialogBoxParamW(hInstance, MAKEINTRESOURCE(rcColorDialog), parent, colorDialogDlgProc, (LPARAM) c)) { - case 1: // cancel - return FALSE; - case 2: // ok - // make the compiler happy by putting the return after the switch - break; - default: - logLastError(L"error running color dialog"); - } - return TRUE; -} diff --git a/src/libui_sdl/libui/windows/combobox.cpp b/src/libui_sdl/libui/windows/combobox.cpp deleted file mode 100644 index 87c999e..0000000 --- a/src/libui_sdl/libui/windows/combobox.cpp +++ /dev/null @@ -1,110 +0,0 @@ -// 20 may 2015 -#include "uipriv_windows.hpp" - -// we as Common Controls 6 users don't need to worry about the height of comboboxes; see http://blogs.msdn.com/b/oldnewthing/archive/2006/03/10/548537.aspx - -struct uiCombobox { - uiWindowsControl c; - HWND hwnd; - void (*onSelected)(uiCombobox *, void *); - void *onSelectedData; -}; - -static BOOL onWM_COMMAND(uiControl *cc, HWND hwnd, WORD code, LRESULT *lResult) -{ - uiCombobox *c = uiCombobox(cc); - - if (code != CBN_SELCHANGE) - return FALSE; - (*(c->onSelected))(c, c->onSelectedData); - *lResult = 0; - return TRUE; -} - -void uiComboboxDestroy(uiControl *cc) -{ - uiCombobox *c = uiCombobox(cc); - - uiWindowsUnregisterWM_COMMANDHandler(c->hwnd); - uiWindowsEnsureDestroyWindow(c->hwnd); - uiFreeControl(uiControl(c)); -} - -uiWindowsControlAllDefaultsExceptDestroy(uiCombobox) - -// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing -#define comboboxWidth 107 /* this is actually the shorter progress bar width, but Microsoft only indicates as wide as necessary; LONGTERM */ -#define comboboxHeight 14 /* LONGTERM: is this too high? */ - -static void uiComboboxMinimumSize(uiWindowsControl *cc, int *width, int *height) -{ - uiCombobox *c = uiCombobox(cc); - uiWindowsSizing sizing; - int x, y; - - x = comboboxWidth; - y = comboboxHeight; - uiWindowsGetSizing(c->hwnd, &sizing); - uiWindowsSizingDlgUnitsToPixels(&sizing, &x, &y); - *width = x; - *height = y; -} - -static void defaultOnSelected(uiCombobox *c, void *data) -{ - // do nothing -} - -void uiComboboxAppend(uiCombobox *c, const char *text) -{ - WCHAR *wtext; - LRESULT res; - - wtext = toUTF16(text); - res = SendMessageW(c->hwnd, CB_ADDSTRING, 0, (LPARAM) wtext); - if (res == (LRESULT) CB_ERR) - logLastError(L"error appending item to uiCombobox"); - else if (res == (LRESULT) CB_ERRSPACE) - logLastError(L"memory exhausted appending item to uiCombobox"); - uiFree(wtext); -} - -int uiComboboxSelected(uiCombobox *c) -{ - LRESULT n; - - n = SendMessage(c->hwnd, CB_GETCURSEL, 0, 0); - if (n == (LRESULT) CB_ERR) - return -1; - return n; -} - -void uiComboboxSetSelected(uiCombobox *c, int n) -{ - // TODO error check - SendMessageW(c->hwnd, CB_SETCURSEL, (WPARAM) n, 0); -} - -void uiComboboxOnSelected(uiCombobox *c, void (*f)(uiCombobox *c, void *data), void *data) -{ - c->onSelected = f; - c->onSelectedData = data; -} - -uiCombobox *uiNewCombobox(void) -{ - uiCombobox *c; - - uiWindowsNewControl(uiCombobox, c); - - c->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE, - L"combobox", L"", - CBS_DROPDOWNLIST | WS_TABSTOP, - hInstance, NULL, - TRUE); - - uiWindowsRegisterWM_COMMANDHandler(c->hwnd, onWM_COMMAND, uiControl(c)); - uiComboboxOnSelected(c, defaultOnSelected, NULL); - - return c; -} diff --git a/src/libui_sdl/libui/windows/compilerver.hpp b/src/libui_sdl/libui/windows/compilerver.hpp deleted file mode 100644 index 6c9e6b8..0000000 --- a/src/libui_sdl/libui/windows/compilerver.hpp +++ /dev/null @@ -1,13 +0,0 @@ -// 9 june 2015 - -// Visual Studio (Microsoft's compilers) -// VS2013 is needed for va_copy(). -#ifdef _MSC_VER -#if _MSC_VER < 1800 -#error Visual Studio 2013 or higher is required to build libui. -#endif -#endif - -// LONGTERM MinGW - -// other compilers can be added here as necessary diff --git a/src/libui_sdl/libui/windows/container.cpp b/src/libui_sdl/libui/windows/container.cpp deleted file mode 100644 index 9ec1e28..0000000 --- a/src/libui_sdl/libui/windows/container.cpp +++ /dev/null @@ -1,110 +0,0 @@ -// 26 april 2015 -#include "uipriv_windows.hpp" - -// Code for the HWND of the following uiControls: -// - uiBox -// - uiRadioButtons -// - uiSpinbox -// - uiTab -// - uiForm -// - uiGrid - -struct containerInit { - uiWindowsControl *c; - void (*onResize)(uiWindowsControl *); -}; - -static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - RECT r; - HDC dc; - PAINTSTRUCT ps; - CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam; - WINDOWPOS *wp = (WINDOWPOS *) lParam; - MINMAXINFO *mmi = (MINMAXINFO *) lParam; - struct containerInit *init; - uiWindowsControl *c; - void (*onResize)(uiWindowsControl *); - int minwid, minht; - LRESULT lResult; - - if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE) - return lResult; - switch (uMsg) { - case WM_CREATE: - init = (struct containerInit *) (cs->lpCreateParams); - SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) (init->onResize)); - SetWindowLongPtrW(hwnd, 0, (LONG_PTR) (init->c)); - break; // defer to DefWindowProc() - case WM_WINDOWPOSCHANGED: - if ((wp->flags & SWP_NOSIZE) != 0) - break; // defer to DefWindowProc(); - onResize = (void (*)(uiWindowsControl *)) GetWindowLongPtrW(hwnd, GWLP_USERDATA); - c = (uiWindowsControl *) GetWindowLongPtrW(hwnd, 0); - (*(onResize))(c); - return 0; - case WM_GETMINMAXINFO: - lResult = DefWindowProcW(hwnd, uMsg, wParam, lParam); - c = (uiWindowsControl *) GetWindowLongPtrW(hwnd, 0); - uiWindowsControlMinimumSize(c, &minwid, &minht); - mmi->ptMinTrackSize.x = minwid; - mmi->ptMinTrackSize.y = minht; - return lResult; - case WM_PAINT: - dc = BeginPaint(hwnd, &ps); - if (dc == NULL) { - logLastError(L"error beginning container paint"); - // bail out; hope DefWindowProc() catches us - break; - } - r = ps.rcPaint; - paintContainerBackground(hwnd, dc, &r); - EndPaint(hwnd, &ps); - return 0; - // tab controls use this to draw the background of the tab area - case WM_PRINTCLIENT: - uiWindowsEnsureGetClientRect(hwnd, &r); - paintContainerBackground(hwnd, (HDC) wParam, &r); - return 0; - case WM_ERASEBKGND: - // avoid some flicker - // we draw the whole update area anyway - return 1; - } - return DefWindowProcW(hwnd, uMsg, wParam, lParam); -} - -ATOM initContainer(HICON hDefaultIcon, HCURSOR hDefaultCursor) -{ - WNDCLASSW wc; - - ZeroMemory(&wc, sizeof (WNDCLASSW)); - wc.lpszClassName = containerClass; - wc.lpfnWndProc = containerWndProc; - wc.hInstance = hInstance; - wc.hIcon = hDefaultIcon; - wc.hCursor = hDefaultCursor; - wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); - wc.cbWndExtra = sizeof (void *); - return RegisterClassW(&wc); -} - -void uninitContainer(void) -{ - if (UnregisterClassW(containerClass, hInstance) == 0) - logLastError(L"error unregistering container window class"); -} - -HWND uiWindowsMakeContainer(uiWindowsControl *c, void (*onResize)(uiWindowsControl *)) -{ - struct containerInit init; - - // TODO onResize cannot be NULL - init.c = c; - init.onResize = onResize; - return uiWindowsEnsureCreateControlHWND(WS_EX_CONTROLPARENT, - containerClass, L"", - 0, - hInstance, (LPVOID) (&init), - FALSE); -} diff --git a/src/libui_sdl/libui/windows/control.cpp b/src/libui_sdl/libui/windows/control.cpp deleted file mode 100644 index ce953cf..0000000 --- a/src/libui_sdl/libui/windows/control.cpp +++ /dev/null @@ -1,121 +0,0 @@ -// 16 august 2015 -#include "uipriv_windows.hpp" - -void uiWindowsControlSyncEnableState(uiWindowsControl *c, int enabled) -{ - (*(c->SyncEnableState))(c, enabled); -} - -void uiWindowsControlSetParentHWND(uiWindowsControl *c, HWND parent) -{ - (*(c->SetParentHWND))(c, parent); -} - -void uiWindowsControlMinimumSize(uiWindowsControl *c, int *width, int *height) -{ - (*(c->MinimumSize))(c, width, height); -} - -void uiWindowsControlMinimumSizeChanged(uiWindowsControl *c) -{ - (*(c->MinimumSizeChanged))(c); -} - -// TODO get rid of this -void uiWindowsControlLayoutRect(uiWindowsControl *c, RECT *r) -{ - (*(c->LayoutRect))(c, r); -} - -void uiWindowsControlAssignControlIDZOrder(uiWindowsControl *c, LONG_PTR *controlID, HWND *insertAfter) -{ - (*(c->AssignControlIDZOrder))(c, controlID, insertAfter); -} - -void uiWindowsControlChildVisibilityChanged(uiWindowsControl *c) -{ - (*(c->ChildVisibilityChanged))(c); -} - -HWND uiWindowsEnsureCreateControlHWND(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, HINSTANCE hInstance, LPVOID lpParam, BOOL useStandardControlFont) -{ - HWND hwnd; - - // don't let using the arrow keys in a uiRadioButtons leave the radio buttons - if ((dwStyle & WS_TABSTOP) != 0) - dwStyle |= WS_GROUP; - hwnd = CreateWindowExW(dwExStyle, - lpClassName, lpWindowName, - dwStyle | WS_CHILD | WS_VISIBLE, - 0, 0, - // use a nonzero initial size just in case some control breaks with a zero initial size - 100, 100, - utilWindow, NULL, hInstance, lpParam); - if (hwnd == NULL) { - logLastError(L"error creating window"); - // TODO return a decoy window - } - if (useStandardControlFont) - SendMessageW(hwnd, WM_SETFONT, (WPARAM) hMessageFont, (LPARAM) TRUE); - return hwnd; -} - -// choose a value distinct from uiWindowSignature -#define uiWindowsControlSignature 0x4D53576E - -uiWindowsControl *uiWindowsAllocControl(size_t n, uint32_t typesig, const char *typenamestr) -{ - return uiWindowsControl(uiAllocControl(n, uiWindowsControlSignature, typesig, typenamestr)); -} - -BOOL uiWindowsShouldStopSyncEnableState(uiWindowsControl *c, BOOL enabled) -{ - int ce; - - ce = uiControlEnabled(uiControl(c)); - // only stop if we're going from disabled back to enabled; don't stop under any other condition - // (if we stop when going from enabled to disabled then enabled children of a disabled control won't get disabled at the OS level) - if (!ce && enabled) - return TRUE; - return FALSE; -} - -void uiWindowsControlAssignSoleControlIDZOrder(uiWindowsControl *c) -{ - LONG_PTR controlID; - HWND insertAfter; - - controlID = 100; - insertAfter = NULL; - uiWindowsControlAssignControlIDZOrder(c, &controlID, &insertAfter); -} - -BOOL uiWindowsControlTooSmall(uiWindowsControl *c) -{ - RECT r; - int width, height; - - uiWindowsControlLayoutRect(c, &r); - uiWindowsControlMinimumSize(c, &width, &height); - if ((r.right - r.left) < width) - return TRUE; - if ((r.bottom - r.top) < height) - return TRUE; - return FALSE; -} - -void uiWindowsControlContinueMinimumSizeChanged(uiWindowsControl *c) -{ - uiControl *parent; - - parent = uiControlParent(uiControl(c)); - if (parent != NULL) - uiWindowsControlMinimumSizeChanged(uiWindowsControl(parent)); -} - -// TODO rename this nad the OS X this and hugging ones to NotifyChild -void uiWindowsControlNotifyVisibilityChanged(uiWindowsControl *c) -{ - // TODO we really need to figure this out; the duplication is a mess - uiWindowsControlContinueMinimumSizeChanged(c); -} diff --git a/src/libui_sdl/libui/windows/d2dscratch.cpp b/src/libui_sdl/libui/windows/d2dscratch.cpp deleted file mode 100644 index 6dc2ba5..0000000 --- a/src/libui_sdl/libui/windows/d2dscratch.cpp +++ /dev/null @@ -1,166 +0,0 @@ -// 17 april 2016 -#include "uipriv_windows.hpp" - -// The Direct2D scratch window is a utility for libui internal use to do quick things with Direct2D. -// To use, call newD2DScratch() passing in a subclass procedure. This subclass procedure should handle the msgD2DScratchPaint message, which has the following usage: -// - wParam - 0 -// - lParam - ID2D1RenderTarget * -// - lResult - 0 -// You can optionally also handle msgD2DScratchLButtonDown, which is sent when the left mouse button is either pressed for the first time or held while the mouse is moving. -// - wParam - position in DIPs, as D2D1_POINT_2F * -// - lParam - size of render target in DIPs, as D2D1_SIZE_F * -// - lResult - 0 -// Other messages can also be handled here. - -// TODO allow resize - -#define d2dScratchClass L"libui_d2dScratchClass" - -// TODO clip rect -static HRESULT d2dScratchDoPaint(HWND hwnd, ID2D1RenderTarget *rt) -{ - COLORREF bgcolorref; - D2D1_COLOR_F bgcolor; - - rt->BeginDraw(); - - // TODO only clear the clip area - // TODO clear with actual background brush - bgcolorref = GetSysColor(COLOR_BTNFACE); - bgcolor.r = ((float) GetRValue(bgcolorref)) / 255.0; - // due to utter apathy on Microsoft's part, GetGValue() does not work with MSVC's Run-Time Error Checks - // it has not worked since 2008 and they have *never* fixed it - // TODO now that -RTCc has just been deprecated entirely, should we switch back? - bgcolor.g = ((float) ((BYTE) ((bgcolorref & 0xFF00) >> 8))) / 255.0; - bgcolor.b = ((float) GetBValue(bgcolorref)) / 255.0; - bgcolor.a = 1.0; - rt->Clear(&bgcolor); - - SendMessageW(hwnd, msgD2DScratchPaint, 0, (LPARAM) rt); - - return rt->EndDraw(NULL, NULL); -} - -static void d2dScratchDoLButtonDown(HWND hwnd, ID2D1RenderTarget *rt, LPARAM lParam) -{ - double xpix, ypix; - FLOAT dpix, dpiy; - D2D1_POINT_2F pos; - D2D1_SIZE_F size; - - xpix = (double) GET_X_LPARAM(lParam); - ypix = (double) GET_Y_LPARAM(lParam); - // these are in pixels; we need points - // TODO separate the function from areautil.cpp? - rt->GetDpi(&dpix, &dpiy); - pos.x = (xpix * 96) / dpix; - pos.y = (ypix * 96) / dpiy; - - size = realGetSize(rt); - - SendMessageW(hwnd, msgD2DScratchLButtonDown, (WPARAM) (&pos), (LPARAM) (&size)); -} - -static LRESULT CALLBACK d2dScratchWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - LONG_PTR init; - ID2D1HwndRenderTarget *rt; - ID2D1DCRenderTarget *dcrt; - RECT client; - HRESULT hr; - - init = GetWindowLongPtrW(hwnd, 0); - if (!init) { - if (uMsg == WM_CREATE) - SetWindowLongPtrW(hwnd, 0, (LONG_PTR) TRUE); - return DefWindowProcW(hwnd, uMsg, wParam, lParam); - } - - rt = (ID2D1HwndRenderTarget *) GetWindowLongPtrW(hwnd, GWLP_USERDATA); - if (rt == NULL) { - rt = makeHWNDRenderTarget(hwnd); - SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) rt); - } - - switch (uMsg) { - case WM_DESTROY: - rt->Release(); - SetWindowLongPtrW(hwnd, 0, (LONG_PTR) FALSE); - break; - case WM_PAINT: - hr = d2dScratchDoPaint(hwnd, rt); - switch (hr) { - case S_OK: - if (ValidateRect(hwnd, NULL) == 0) - logLastError(L"error validating D2D scratch control rect"); - break; - case D2DERR_RECREATE_TARGET: - // DON'T validate the rect - // instead, simply drop the render target - // we'll get another WM_PAINT and make the render target again - // TODO would this require us to invalidate the entire client area? - rt->Release(); - SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) NULL); - break; - default: - logHRESULT(L"error drawing D2D scratch window", hr); - } - return 0; - case WM_PRINTCLIENT: - uiWindowsEnsureGetClientRect(hwnd, &client); - dcrt = makeHDCRenderTarget((HDC) wParam, &client); - hr = d2dScratchDoPaint(hwnd, dcrt); - if (hr != S_OK) - logHRESULT(L"error printing D2D scratch window client area", hr); - dcrt->Release(); - return 0; - case WM_LBUTTONDOWN: - d2dScratchDoLButtonDown(hwnd, rt, lParam); - return 0; - case WM_MOUSEMOVE: - // also send LButtonDowns when dragging - if ((wParam & MK_LBUTTON) != 0) - d2dScratchDoLButtonDown(hwnd, rt, lParam); - return 0; - } - return DefWindowProcW(hwnd, uMsg, wParam, lParam); -} - -ATOM registerD2DScratchClass(HICON hDefaultIcon, HCURSOR hDefaultCursor) -{ - WNDCLASSW wc; - - ZeroMemory(&wc, sizeof (WNDCLASSW)); - wc.lpszClassName = d2dScratchClass; - wc.lpfnWndProc = d2dScratchWndProc; - wc.hInstance = hInstance; - wc.hIcon = hDefaultIcon; - wc.hCursor = hDefaultCursor; - wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); - wc.cbWndExtra = sizeof (LONG_PTR); // for the init status - return RegisterClassW(&wc); -} - -void unregisterD2DScratchClass(void) -{ - if (UnregisterClassW(d2dScratchClass, hInstance) == 0) - logLastError(L"error unregistering D2D scratch window class"); -} - -HWND newD2DScratch(HWND parent, RECT *rect, HMENU controlID, SUBCLASSPROC subclass, DWORD_PTR subclassData) -{ - HWND hwnd; - - hwnd = CreateWindowExW(0, - d2dScratchClass, L"", - WS_CHILD | WS_VISIBLE, - rect->left, rect->top, - rect->right - rect->left, rect->bottom - rect->top, - parent, controlID, hInstance, NULL); - if (hwnd == NULL) - // TODO return decoy window - logLastError(L"error creating D2D scratch window"); - if (SetWindowSubclass(hwnd, subclass, 0, subclassData) == FALSE) - logLastError(L"error subclassing D2D scratch window"); - return hwnd; -} diff --git a/src/libui_sdl/libui/windows/datetimepicker.cpp b/src/libui_sdl/libui/windows/datetimepicker.cpp deleted file mode 100644 index e105c2f..0000000 --- a/src/libui_sdl/libui/windows/datetimepicker.cpp +++ /dev/null @@ -1,191 +0,0 @@ -// 22 may 2015 -#include "uipriv_windows.hpp" - -struct uiDateTimePicker { - uiWindowsControl c; - HWND hwnd; -}; - -// utility functions - -#define GLI(what, buf, n) GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, what, buf, n) - -// The real date/time picker does a manual replacement of "yy" with "yyyy" for DTS_SHORTDATECENTURYFORMAT. -// Because we're also duplicating its functionality (see below), we have to do it too. -static WCHAR *expandYear(WCHAR *dts, int n) -{ - WCHAR *out; - WCHAR *p, *q; - int ny = 0; - - // allocate more than we need to be safe - out = (WCHAR *) uiAlloc((n * 3) * sizeof (WCHAR), "WCHAR[]"); - q = out; - for (p = dts; *p != L'\0'; p++) { - // first, if the current character is a y, increment the number of consecutive ys - // otherwise, stop counting, and if there were only two, add two more to make four - if (*p != L'y') { - if (ny == 2) { - *q++ = L'y'; - *q++ = L'y'; - } - ny = 0; - } else - ny++; - // next, handle quoted blocks - // we do this AFTER the above so yy'abc' becomes yyyy'abc' and not yy'abc'yy - // this handles the case of 'a''b' elegantly as well - if (*p == L'\'') { - // copy the opening quote - *q++ = *p; - // copy the contents - for (;;) { - p++; - if (*p == L'\'') - break; - if (*p == L'\0') - implbug("unterminated quote in system-provided locale date string in expandYear()"); - *q++ = *p; - } - // and fall through to copy the closing quote - } - // copy the current character - *q++ = *p; - } - // handle trailing yy - if (ny == 2) { - *q++ = L'y'; - *q++ = L'y'; - } - *q++ = L'\0'; - return out; -} - -// Windows has no combined date/time prebuilt constant; we have to build the format string ourselves -// TODO use a default format if one fails -static void setDateTimeFormat(HWND hwnd) -{ - WCHAR *unexpandedDate, *date; - WCHAR *time; - WCHAR *datetime; - int ndate, ntime; - - ndate = GLI(LOCALE_SSHORTDATE, NULL, 0); - if (ndate == 0) - logLastError(L"error getting date string length"); - date = (WCHAR *) uiAlloc(ndate * sizeof (WCHAR), "WCHAR[]"); - if (GLI(LOCALE_SSHORTDATE, date, ndate) == 0) - logLastError(L"error geting date string"); - unexpandedDate = date; // so we can free it - date = expandYear(unexpandedDate, ndate); - uiFree(unexpandedDate); - - ntime = GLI(LOCALE_STIMEFORMAT, NULL, 0); - if (ndate == 0) - logLastError(L"error getting time string length"); - time = (WCHAR *) uiAlloc(ntime * sizeof (WCHAR), "WCHAR[]"); - if (GLI(LOCALE_STIMEFORMAT, time, ntime) == 0) - logLastError(L"error geting time string"); - - datetime = strf(L"%s %s", date, time); - if (SendMessageW(hwnd, DTM_SETFORMAT, 0, (LPARAM) datetime) == 0) - logLastError(L"error applying format string to date/time picker"); - - uiFree(datetime); - uiFree(time); - uiFree(date); -} - -// control implementation - -static void uiDateTimePickerDestroy(uiControl *c) -{ - uiDateTimePicker *d = uiDateTimePicker(c); - - uiWindowsUnregisterReceiveWM_WININICHANGE(d->hwnd); - uiWindowsEnsureDestroyWindow(d->hwnd); - uiFreeControl(uiControl(d)); -} - -uiWindowsControlAllDefaultsExceptDestroy(uiDateTimePicker) - -// the height returned from DTM_GETIDEALSIZE is unreliable; see http://stackoverflow.com/questions/30626549/what-is-the-proper-use-of-dtm-getidealsize-treating-the-returned-size-as-pixels -// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing -#define entryHeight 14 - -static void uiDateTimePickerMinimumSize(uiWindowsControl *c, int *width, int *height) -{ - uiDateTimePicker *d = uiDateTimePicker(c); - SIZE s; - uiWindowsSizing sizing; - int y; - - s.cx = 0; - s.cy = 0; - SendMessageW(d->hwnd, DTM_GETIDEALSIZE, 0, (LPARAM) (&s)); - *width = s.cx; - - y = entryHeight; - uiWindowsGetSizing(d->hwnd, &sizing); - uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, &y); - *height = y; -} - -static uiDateTimePicker *finishNewDateTimePicker(DWORD style) -{ - uiDateTimePicker *d; - - uiWindowsNewControl(uiDateTimePicker, d); - - d->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE, - DATETIMEPICK_CLASSW, L"", - style | WS_TABSTOP, - hInstance, NULL, - TRUE); - - // automatically update date/time format when user changes locale settings - // for the standard styles, this is in the date-time picker itself - // for our date/time mode, we do it in a subclass assigned in uiNewDateTimePicker() - uiWindowsRegisterReceiveWM_WININICHANGE(d->hwnd); - - return d; -} - -static LRESULT CALLBACK datetimepickerSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) -{ - switch (uMsg) { - case WM_WININICHANGE: - // we can optimize this by only doing it when the real date/time picker does it - // unfortunately, I don't know when that is :/ - // hopefully this won't hurt - setDateTimeFormat(hwnd); - return 0; - case WM_NCDESTROY: - if (RemoveWindowSubclass(hwnd, datetimepickerSubProc, uIdSubclass) == FALSE) - logLastError(L"error removing date-time picker locale change handling subclass"); - break; - } - return DefSubclassProc(hwnd, uMsg, wParam, lParam); -} - -uiDateTimePicker *uiNewDateTimePicker(void) -{ - uiDateTimePicker *d; - - d = finishNewDateTimePicker(0); - setDateTimeFormat(d->hwnd); - if (SetWindowSubclass(d->hwnd, datetimepickerSubProc, 0, (DWORD_PTR) d) == FALSE) - logLastError(L"error subclassing date-time-picker to assist in locale change handling"); - // TODO set a suitable default in this case - return d; -} - -uiDateTimePicker *uiNewDatePicker(void) -{ - return finishNewDateTimePicker(DTS_SHORTDATECENTURYFORMAT); -} - -uiDateTimePicker *uiNewTimePicker(void) -{ - return finishNewDateTimePicker(DTS_TIMEFORMAT); -} diff --git a/src/libui_sdl/libui/windows/debug.cpp b/src/libui_sdl/libui/windows/debug.cpp deleted file mode 100644 index cfafffd..0000000 --- a/src/libui_sdl/libui/windows/debug.cpp +++ /dev/null @@ -1,84 +0,0 @@ -// 25 february 2015 -#include "uipriv_windows.hpp" - -// LONGTERM disable logging and stopping on no-debug builds - -static void printDebug(const WCHAR *msg) -{ - OutputDebugStringW(msg); -} - -HRESULT _logLastError(debugargs, const WCHAR *s) -{ - DWORD le; - WCHAR *msg; - WCHAR *formatted; - BOOL useFormatted; - - le = GetLastError(); - - useFormatted = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, le, 0, (LPWSTR) (&formatted), 0, NULL) != 0; - if (!useFormatted) - formatted = L"\n"; - msg = strf(L"[libui] %s:%s:%s() %s: GetLastError() == %I32u %s", - file, line, func, - s, le, formatted); - if (useFormatted) - LocalFree(formatted); // ignore error - printDebug(msg); - uiFree(msg); - DebugBreak(); - - SetLastError(le); - // a function does not have to set a last error - // if the last error we get is actually 0, then HRESULT_FROM_WIN32(0) will return S_OK (0 cast to an HRESULT, since 0 <= 0), which we don't want - // prevent this by returning E_FAIL - if (le == 0) - return E_FAIL; - return HRESULT_FROM_WIN32(le); -} - -HRESULT _logHRESULT(debugargs, const WCHAR *s, HRESULT hr) -{ - WCHAR *msg; - WCHAR *formatted; - BOOL useFormatted; - - useFormatted = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, hr, 0, (LPWSTR) (&formatted), 0, NULL) != 0; - if (!useFormatted) - formatted = L"\n"; - msg = strf(L"[libui] %s:%s:%s() %s: HRESULT == 0x%08I32X %s", - file, line, func, - s, hr, formatted); - if (useFormatted) - LocalFree(formatted); // ignore error - printDebug(msg); - uiFree(msg); - DebugBreak(); - - return hr; -} - -void realbug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap) -{ - va_list ap2; - char *msg; - size_t n; - WCHAR *final; - - va_copy(ap2, ap); - n = _vscprintf(format, ap2); - va_end(ap2); - n++; // terminating '\0' - - msg = (char *) uiAlloc(n * sizeof (char), "char[]"); - // includes terminating '\0' according to example in https://msdn.microsoft.com/en-us/library/xa1a1a6z.aspx - vsprintf_s(msg, n, format, ap); - - final = strf(L"[libui] %hs:%hs:%hs() %hs%hs\n", file, line, func, prefix, msg); - uiFree(msg); - printDebug(final); - uiFree(final); - - DebugBreak(); -} diff --git a/src/libui_sdl/libui/windows/draw.cpp b/src/libui_sdl/libui/windows/draw.cpp deleted file mode 100644 index 9a815b9..0000000 --- a/src/libui_sdl/libui/windows/draw.cpp +++ /dev/null @@ -1,578 +0,0 @@ -// 7 september 2015 -#include "uipriv_windows.hpp" -#include "draw.hpp" - -ID2D1Factory *d2dfactory = NULL; - -HRESULT initDraw(void) -{ - D2D1_FACTORY_OPTIONS opts; - - ZeroMemory(&opts, sizeof (D2D1_FACTORY_OPTIONS)); - // TODO make this an option - opts.debugLevel = D2D1_DEBUG_LEVEL_NONE; - return D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, - IID_ID2D1Factory, - &opts, - (void **) (&d2dfactory)); -} - -void uninitDraw(void) -{ - d2dfactory->Release(); -} - -ID2D1HwndRenderTarget *makeHWNDRenderTarget(HWND hwnd) -{ - D2D1_RENDER_TARGET_PROPERTIES props; - D2D1_HWND_RENDER_TARGET_PROPERTIES hprops; - HDC dc; - RECT r; - ID2D1HwndRenderTarget *rt; - HRESULT hr; - - // we need a DC for the DPI - // we *could* just use the screen DPI but why when we have a window handle and its DC has a DPI - dc = GetDC(hwnd); - if (dc == NULL) - logLastError(L"error getting DC to find DPI"); - - ZeroMemory(&props, sizeof (D2D1_RENDER_TARGET_PROPERTIES)); - props.type = D2D1_RENDER_TARGET_TYPE_HARDWARE;//DEFAULT; - props.pixelFormat.format = DXGI_FORMAT_UNKNOWN; - props.pixelFormat.alphaMode = D2D1_ALPHA_MODE_UNKNOWN; - props.dpiX = GetDeviceCaps(dc, LOGPIXELSX); - props.dpiY = GetDeviceCaps(dc, LOGPIXELSY); - props.usage = D2D1_RENDER_TARGET_USAGE_NONE; - props.minLevel = D2D1_FEATURE_LEVEL_DEFAULT; - - if (ReleaseDC(hwnd, dc) == 0) - logLastError(L"error releasing DC for finding DPI"); - - uiWindowsEnsureGetClientRect(hwnd, &r); - - ZeroMemory(&hprops, sizeof (D2D1_HWND_RENDER_TARGET_PROPERTIES)); - hprops.hwnd = hwnd; - hprops.pixelSize.width = r.right - r.left; - hprops.pixelSize.height = r.bottom - r.top; - // according to Rick Brewster, some drivers will misbehave if we don't specify this (see http://stackoverflow.com/a/33222983/3408572) - hprops.presentOptions = D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS; - - hr = d2dfactory->CreateHwndRenderTarget( - &props, - &hprops, - &rt); - if (hr != S_OK) - { - props.type = D2D1_RENDER_TARGET_TYPE_DEFAULT; - hr = d2dfactory->CreateHwndRenderTarget( - &props, - &hprops, - &rt); - if (hr != S_OK) - logHRESULT(L"error creating HWND render target", hr); - } - - return rt; -} - -ID2D1DCRenderTarget *makeHDCRenderTarget(HDC dc, RECT *r) -{ - D2D1_RENDER_TARGET_PROPERTIES props; - ID2D1DCRenderTarget *rt; - HRESULT hr; - - ZeroMemory(&props, sizeof (D2D1_RENDER_TARGET_PROPERTIES)); - props.type = D2D1_RENDER_TARGET_TYPE_DEFAULT; - props.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM; - props.pixelFormat.alphaMode = D2D1_ALPHA_MODE_PREMULTIPLIED; - props.dpiX = GetDeviceCaps(dc, LOGPIXELSX); - props.dpiY = GetDeviceCaps(dc, LOGPIXELSY); - props.usage = D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE; - props.minLevel = D2D1_FEATURE_LEVEL_DEFAULT; - - hr = d2dfactory->CreateDCRenderTarget(&props, &rt); - if (hr != S_OK) - logHRESULT(L"error creating DC render target", hr); - hr = rt->BindDC(dc, r); - if (hr != S_OK) - logHRESULT(L"error binding DC to DC render target", hr); - return rt; -} - -static void resetTarget(ID2D1RenderTarget *rt) -{ - D2D1_MATRIX_3X2_F dm; - - // transformations persist - // reset to the identity matrix - ZeroMemory(&dm, sizeof (D2D1_MATRIX_3X2_F)); - dm._11 = 1; - dm._22 = 1; - rt->SetTransform(&dm); -} - -uiDrawContext *newContext(ID2D1RenderTarget *rt) -{ - uiDrawContext *c; - - c = uiNew(uiDrawContext); - c->rt = rt; - c->states = new std::vector; - resetTarget(c->rt); - return c; -} - -void freeContext(uiDrawContext *c) -{ - if (c->currentClip != NULL) - c->currentClip->Release(); - if (c->states->size() != 0) - // TODO do this on other platforms - userbug("You did not balance uiDrawSave() and uiDrawRestore() calls."); - delete c->states; - uiFree(c); -} - -static ID2D1Brush *makeSolidBrush(uiDrawBrush *b, ID2D1RenderTarget *rt, D2D1_BRUSH_PROPERTIES *props) -{ - D2D1_COLOR_F color; - ID2D1SolidColorBrush *brush; - HRESULT hr; - - color.r = b->R; - color.g = b->G; - color.b = b->B; - color.a = b->A; - - hr = rt->CreateSolidColorBrush( - &color, - props, - &brush); - if (hr != S_OK) - logHRESULT(L"error creating solid brush", hr); - return brush; -} - -static ID2D1GradientStopCollection *mkstops(uiDrawBrush *b, ID2D1RenderTarget *rt) -{ - ID2D1GradientStopCollection *s; - D2D1_GRADIENT_STOP *stops; - size_t i; - HRESULT hr; - - stops = (D2D1_GRADIENT_STOP *) uiAlloc(b->NumStops * sizeof (D2D1_GRADIENT_STOP), "D2D1_GRADIENT_STOP[]"); - for (i = 0; i < b->NumStops; i++) { - stops[i].position = b->Stops[i].Pos; - stops[i].color.r = b->Stops[i].R; - stops[i].color.g = b->Stops[i].G; - stops[i].color.b = b->Stops[i].B; - stops[i].color.a = b->Stops[i].A; - } - - hr = rt->CreateGradientStopCollection( - stops, - b->NumStops, - D2D1_GAMMA_2_2, // this is the default for the C++-only overload of ID2D1RenderTarget::GradientStopCollection() - D2D1_EXTEND_MODE_CLAMP, - &s); - if (hr != S_OK) - logHRESULT(L"error creating stop collection", hr); - - uiFree(stops); - return s; -} - -static ID2D1Brush *makeLinearBrush(uiDrawBrush *b, ID2D1RenderTarget *rt, D2D1_BRUSH_PROPERTIES *props) -{ - ID2D1LinearGradientBrush *brush; - D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES gprops; - ID2D1GradientStopCollection *stops; - HRESULT hr; - - ZeroMemory(&gprops, sizeof (D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES)); - gprops.startPoint.x = b->X0; - gprops.startPoint.y = b->Y0; - gprops.endPoint.x = b->X1; - gprops.endPoint.y = b->Y1; - - stops = mkstops(b, rt); - - hr = rt->CreateLinearGradientBrush( - &gprops, - props, - stops, - &brush); - if (hr != S_OK) - logHRESULT(L"error creating gradient brush", hr); - - // the example at https://msdn.microsoft.com/en-us/library/windows/desktop/dd756682%28v=vs.85%29.aspx says this is safe to do now - stops->Release(); - return brush; -} - -static ID2D1Brush *makeRadialBrush(uiDrawBrush *b, ID2D1RenderTarget *rt, D2D1_BRUSH_PROPERTIES *props) -{ - ID2D1RadialGradientBrush *brush; - D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES gprops; - ID2D1GradientStopCollection *stops; - HRESULT hr; - - ZeroMemory(&gprops, sizeof (D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES)); - gprops.gradientOriginOffset.x = b->X0 - b->X1; - gprops.gradientOriginOffset.y = b->Y0 - b->Y1; - gprops.center.x = b->X1; - gprops.center.y = b->Y1; - gprops.radiusX = b->OuterRadius; - gprops.radiusY = b->OuterRadius; - - stops = mkstops(b, rt); - - hr = rt->CreateRadialGradientBrush( - &gprops, - props, - stops, - &brush); - if (hr != S_OK) - logHRESULT(L"error creating gradient brush", hr); - - stops->Release(); - return brush; -} - -static ID2D1Brush *makeBrush(uiDrawBrush *b, ID2D1RenderTarget *rt) -{ - D2D1_BRUSH_PROPERTIES props; - - ZeroMemory(&props, sizeof (D2D1_BRUSH_PROPERTIES)); - props.opacity = 1.0; - // identity matrix - props.transform._11 = 1; - props.transform._22 = 1; - - switch (b->Type) { - case uiDrawBrushTypeSolid: - return makeSolidBrush(b, rt, &props); - case uiDrawBrushTypeLinearGradient: - return makeLinearBrush(b, rt, &props); - case uiDrawBrushTypeRadialGradient: - return makeRadialBrush(b, rt, &props); -// case uiDrawBrushTypeImage: -// TODO - } - - // TODO do this on all platforms - userbug("Invalid brush type %d given to drawing operation.", b->Type); - // TODO dummy brush? - return NULL; // make compiler happy -} - -// how clipping works: -// every fill and stroke is done on a temporary layer with the clip geometry applied to it -// this is really the only way to clip in Direct2D that doesn't involve opacity images -// reference counting: -// - initially the clip is NULL, which means do not use a layer -// - the first time uiDrawClip() is called, we take a reference on the path passed in (this is also why uiPathEnd() is needed) -// - every successive time, we create a new PathGeometry and merge the current clip with the new path, releasing the reference we took earlier and taking a reference to the new one -// - in Save, we take another reference; in Restore we drop the refernece to the existing path geometry and transfer that saved ref to the new path geometry over to the context -// uiDrawFreePath() doesn't destroy the path geometry, it just drops the reference count, so a clip can exist independent of its path - -static ID2D1Layer *applyClip(uiDrawContext *c) -{ - ID2D1Layer *layer; - D2D1_LAYER_PARAMETERS params; - HRESULT hr; - - // if no clip, don't do anything - if (c->currentClip == NULL) - return NULL; - - // create a layer for clipping - // we have to explicitly make the layer because we're still targeting Windows 7 - hr = c->rt->CreateLayer(NULL, &layer); - if (hr != S_OK) - logHRESULT(L"error creating clip layer", hr); - - // apply it as the clip - ZeroMemory(¶ms, sizeof (D2D1_LAYER_PARAMETERS)); - // this is the equivalent of InfiniteRect() in d2d1helper.h - params.contentBounds.left = -FLT_MAX; - params.contentBounds.top = -FLT_MAX; - params.contentBounds.right = FLT_MAX; - params.contentBounds.bottom = FLT_MAX; - params.geometricMask = (ID2D1Geometry *) (c->currentClip); - // TODO is this correct? - params.maskAntialiasMode = c->rt->GetAntialiasMode(); - // identity matrix - params.maskTransform._11 = 1; - params.maskTransform._22 = 1; - params.opacity = 1.0; - params.opacityBrush = NULL; - params.layerOptions = D2D1_LAYER_OPTIONS_NONE; - // TODO is this correct? - if (c->rt->GetTextAntialiasMode() == D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE) - params.layerOptions = D2D1_LAYER_OPTIONS_INITIALIZE_FOR_CLEARTYPE; - c->rt->PushLayer(¶ms, layer); - - // return the layer so it can be freed later - return layer; -} - -static void unapplyClip(uiDrawContext *c, ID2D1Layer *layer) -{ - if (layer == NULL) - return; - c->rt->PopLayer(); - layer->Release(); -} - -void uiDrawStroke(uiDrawContext *c, uiDrawPath *p, uiDrawBrush *b, uiDrawStrokeParams *sp) -{ - ID2D1Brush *brush; - ID2D1StrokeStyle *style; - D2D1_STROKE_STYLE_PROPERTIES dsp; - FLOAT *dashes; - size_t i; - ID2D1Layer *cliplayer; - HRESULT hr; - - brush = makeBrush(b, c->rt); - - ZeroMemory(&dsp, sizeof (D2D1_STROKE_STYLE_PROPERTIES)); - switch (sp->Cap) { - case uiDrawLineCapFlat: - dsp.startCap = D2D1_CAP_STYLE_FLAT; - dsp.endCap = D2D1_CAP_STYLE_FLAT; - dsp.dashCap = D2D1_CAP_STYLE_FLAT; - break; - case uiDrawLineCapRound: - dsp.startCap = D2D1_CAP_STYLE_ROUND; - dsp.endCap = D2D1_CAP_STYLE_ROUND; - dsp.dashCap = D2D1_CAP_STYLE_ROUND; - break; - case uiDrawLineCapSquare: - dsp.startCap = D2D1_CAP_STYLE_SQUARE; - dsp.endCap = D2D1_CAP_STYLE_SQUARE; - dsp.dashCap = D2D1_CAP_STYLE_SQUARE; - break; - } - switch (sp->Join) { - case uiDrawLineJoinMiter: - dsp.lineJoin = D2D1_LINE_JOIN_MITER_OR_BEVEL; - dsp.miterLimit = sp->MiterLimit; - break; - case uiDrawLineJoinRound: - dsp.lineJoin = D2D1_LINE_JOIN_ROUND; - break; - case uiDrawLineJoinBevel: - dsp.lineJoin = D2D1_LINE_JOIN_BEVEL; - break; - } - dsp.dashStyle = D2D1_DASH_STYLE_SOLID; - dashes = NULL; - // note that dash widths and the dash phase are scaled up by the thickness by Direct2D - // TODO be sure to formally document this - if (sp->NumDashes != 0) { - dsp.dashStyle = D2D1_DASH_STYLE_CUSTOM; - dashes = (FLOAT *) uiAlloc(sp->NumDashes * sizeof (FLOAT), "FLOAT[]"); - for (i = 0; i < sp->NumDashes; i++) - dashes[i] = sp->Dashes[i] / sp->Thickness; - } - dsp.dashOffset = sp->DashPhase / sp->Thickness; - hr = d2dfactory->CreateStrokeStyle( - &dsp, - dashes, - sp->NumDashes, - &style); - if (hr != S_OK) - logHRESULT(L"error creating stroke style", hr); - if (sp->NumDashes != 0) - uiFree(dashes); - - cliplayer = applyClip(c); - c->rt->DrawGeometry( - pathGeometry(p), - brush, - sp->Thickness, - style); - unapplyClip(c, cliplayer); - - style->Release(); - brush->Release(); -} - -void uiDrawFill(uiDrawContext *c, uiDrawPath *p, uiDrawBrush *b) -{ - ID2D1Brush *brush; - ID2D1Layer *cliplayer; - - brush = makeBrush(b, c->rt); - cliplayer = applyClip(c); - c->rt->FillGeometry( - pathGeometry(p), - brush, - NULL); - unapplyClip(c, cliplayer); - brush->Release(); -} - -void uiDrawTransform(uiDrawContext *c, uiDrawMatrix *m) -{ - D2D1_MATRIX_3X2_F dm, cur; - - c->rt->GetTransform(&cur); - m2d(m, &dm); - // you would think we have to do already * m, right? - // WRONG! we have to do m * already - // why? a few reasons - // a) this lovely comment in cairo's source - http://cgit.freedesktop.org/cairo/tree/src/cairo-matrix.c?id=0537479bd1d4c5a3bc0f6f41dec4deb98481f34a#n330 - // Direct2D uses column vectors and I don't know if this is even documented - // b) that's what Core Graphics does - // TODO see if Microsoft says to do this - dm = dm * cur; // for whatever reason operator * is defined but not operator *= - c->rt->SetTransform(&dm); -} - -void uiDrawClip(uiDrawContext *c, uiDrawPath *path) -{ - ID2D1PathGeometry *newPath; - ID2D1GeometrySink *newSink; - HRESULT hr; - - // if there's no current clip, borrow the path - if (c->currentClip == NULL) { - c->currentClip = pathGeometry(path); - // we have to take our own reference to that clip - c->currentClip->AddRef(); - return; - } - - // otherwise we have to intersect the current path with the new one - // we do that into a new path, and then replace c->currentClip with that new path - hr = d2dfactory->CreatePathGeometry(&newPath); - if (hr != S_OK) - logHRESULT(L"error creating new path", hr); - hr = newPath->Open(&newSink); - if (hr != S_OK) - logHRESULT(L"error opening new path", hr); - hr = c->currentClip->CombineWithGeometry( - pathGeometry(path), - D2D1_COMBINE_MODE_INTERSECT, - NULL, - // TODO is this correct or can this be set per target? - D2D1_DEFAULT_FLATTENING_TOLERANCE, - newSink); - if (hr != S_OK) - logHRESULT(L"error intersecting old path with new path", hr); - hr = newSink->Close(); - if (hr != S_OK) - logHRESULT(L"error closing new path", hr); - newSink->Release(); - - // okay we have the new clip; we just need to replace the old one with it - c->currentClip->Release(); - c->currentClip = newPath; - // we have a reference already; no need for another -} - -struct drawState { - ID2D1DrawingStateBlock *dsb; - ID2D1PathGeometry *clip; -}; - -void uiDrawSave(uiDrawContext *c) -{ - struct drawState state; - HRESULT hr; - - hr = d2dfactory->CreateDrawingStateBlock( - // TODO verify that these are correct - NULL, - NULL, - &(state.dsb)); - if (hr != S_OK) - logHRESULT(L"error creating drawing state block", hr); - c->rt->SaveDrawingState(state.dsb); - - // if we have a clip, we need to hold another reference to it - if (c->currentClip != NULL) - c->currentClip->AddRef(); - state.clip = c->currentClip; // even if NULL assign it - - c->states->push_back(state); -} - -void uiDrawRestore(uiDrawContext *c) -{ - struct drawState state; - - state = (*(c->states))[c->states->size() - 1]; - c->states->pop_back(); - - c->rt->RestoreDrawingState(state.dsb); - state.dsb->Release(); - - // if we have a current clip, we need to drop it - if (c->currentClip != NULL) - c->currentClip->Release(); - // no need to explicitly addref or release; just transfer the ref - c->currentClip = state.clip; -} - - -// bitmap API - -uiDrawBitmap* uiDrawNewBitmap(uiDrawContext* c, int width, int height, int alpha) -{ - uiDrawBitmap* bmp; - HRESULT hr; - - bmp = uiNew(uiDrawBitmap); - - D2D1_BITMAP_PROPERTIES bp2 = D2D1::BitmapProperties(); - bp2.dpiX = 0; - bp2.dpiY = 0; - bp2.pixelFormat = D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, - alpha ? D2D1_ALPHA_MODE_PREMULTIPLIED : D2D1_ALPHA_MODE_IGNORE); - - //c->rt->BeginDraw(); - - hr = c->rt->CreateBitmap(D2D1::SizeU(width,height), NULL, 0, &bp2, &bmp->bmp); - if (hr != S_OK) - logHRESULT(L"error creating bitmap", hr); - - //c->rt->EndDraw(); - - bmp->Width = width; - bmp->Height = height; - bmp->Stride = width*4; - - return bmp; -} - -void uiDrawBitmapUpdate(uiDrawBitmap* bmp, const void* data) -{ - D2D1_RECT_U rekt = D2D1::RectU(0, 0, bmp->Width, bmp->Height); - bmp->bmp->CopyFromMemory(&rekt, data, bmp->Stride); -} - -void uiDrawBitmapDraw(uiDrawContext* c, uiDrawBitmap* bmp, uiRect* srcrect, uiRect* dstrect, int filter) -{ - D2D_RECT_F _srcrect = D2D1::RectF(srcrect->X, srcrect->Y, srcrect->X+srcrect->Width, srcrect->Y+srcrect->Height); - D2D_RECT_F _dstrect = D2D1::RectF(dstrect->X, dstrect->Y, dstrect->X+dstrect->Width, dstrect->Y+dstrect->Height); - - float dpix, dpiy; - c->rt->GetDpi(&dpix, &dpiy); - _srcrect.left = (_srcrect.left * 96.0f) / dpix; - _srcrect.top = (_srcrect.top * 96.0f) / dpiy; - _srcrect.right = (_srcrect.right * 96.0f) / dpix; - _srcrect.bottom = (_srcrect.bottom * 96.0f) / dpiy; - - c->rt->DrawBitmap(bmp->bmp, &_dstrect, 1.0f, filter ? D2D1_BITMAP_INTERPOLATION_MODE_LINEAR : D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, &_srcrect); -} - -void uiDrawFreeBitmap(uiDrawBitmap* bmp) -{ - bmp->bmp->Release(); - uiFree(bmp); -} diff --git a/src/libui_sdl/libui/windows/draw.hpp b/src/libui_sdl/libui/windows/draw.hpp deleted file mode 100644 index 992d050..0000000 --- a/src/libui_sdl/libui/windows/draw.hpp +++ /dev/null @@ -1,24 +0,0 @@ -// 5 may 2016 - -// draw.cpp -extern ID2D1Factory *d2dfactory; -struct uiDrawContext { - ID2D1RenderTarget *rt; - // TODO find out how this works - std::vector *states; - ID2D1PathGeometry *currentClip; -}; - -struct uiDrawBitmap { - int Width; - int Height; - int Stride; - - ID2D1Bitmap* bmp; -}; - -// drawpath.cpp -extern ID2D1PathGeometry *pathGeometry(uiDrawPath *p); - -// drawmatrix.cpp -extern void m2d(uiDrawMatrix *m, D2D1_MATRIX_3X2_F *d); diff --git a/src/libui_sdl/libui/windows/drawmatrix.cpp b/src/libui_sdl/libui/windows/drawmatrix.cpp deleted file mode 100644 index 090972a..0000000 --- a/src/libui_sdl/libui/windows/drawmatrix.cpp +++ /dev/null @@ -1,117 +0,0 @@ -// 7 september 2015 -#include "uipriv_windows.hpp" -#include "draw.hpp" - -void m2d(uiDrawMatrix *m, D2D1_MATRIX_3X2_F *d) -{ - d->_11 = m->M11; - d->_12 = m->M12; - d->_21 = m->M21; - d->_22 = m->M22; - d->_31 = m->M31; - d->_32 = m->M32; -} - -static void d2m(D2D1_MATRIX_3X2_F *d, uiDrawMatrix *m) -{ - m->M11 = d->_11; - m->M12 = d->_12; - m->M21 = d->_21; - m->M22 = d->_22; - m->M31 = d->_31; - m->M32 = d->_32; -} - -void uiDrawMatrixTranslate(uiDrawMatrix *m, double x, double y) -{ - D2D1_MATRIX_3X2_F dm; - - m2d(m, &dm); - dm = dm * D2D1::Matrix3x2F::Translation(x, y); - d2m(&dm, m); -} - -void uiDrawMatrixScale(uiDrawMatrix *m, double xCenter, double yCenter, double x, double y) -{ - D2D1_MATRIX_3X2_F dm; - D2D1_POINT_2F center; - - m2d(m, &dm); - center.x = xCenter; - center.y = yCenter; - dm = dm * D2D1::Matrix3x2F::Scale(x, y, center); - d2m(&dm, m); -} - -#define r2d(x) (x * (180.0 / uiPi)) - -void uiDrawMatrixRotate(uiDrawMatrix *m, double x, double y, double amount) -{ - D2D1_MATRIX_3X2_F dm; - D2D1_POINT_2F center; - - m2d(m, &dm); - center.x = x; - center.y = y; - dm = dm * D2D1::Matrix3x2F::Rotation(r2d(amount), center); - d2m(&dm, m); -} - -void uiDrawMatrixSkew(uiDrawMatrix *m, double x, double y, double xamount, double yamount) -{ - D2D1_MATRIX_3X2_F dm; - D2D1_POINT_2F center; - - m2d(m, &dm); - center.x = x; - center.y = y; - dm = dm * D2D1::Matrix3x2F::Skew(r2d(xamount), r2d(yamount), center); - d2m(&dm, m); -} - -void uiDrawMatrixMultiply(uiDrawMatrix *dest, uiDrawMatrix *src) -{ - D2D1_MATRIX_3X2_F c, d; - - m2d(dest, &c); - m2d(src, &d); - c = c * d; - d2m(&c, dest); -} - -int uiDrawMatrixInvertible(uiDrawMatrix *m) -{ - D2D1_MATRIX_3X2_F d; - - m2d(m, &d); - return D2D1IsMatrixInvertible(&d) != FALSE; -} - -int uiDrawMatrixInvert(uiDrawMatrix *m) -{ - D2D1_MATRIX_3X2_F d; - - m2d(m, &d); - if (D2D1InvertMatrix(&d) == FALSE) - return 0; - d2m(&d, m); - return 1; -} - -void uiDrawMatrixTransformPoint(uiDrawMatrix *m, double *x, double *y) -{ - D2D1::Matrix3x2F dm; - D2D1_POINT_2F pt; - - m2d(m, &dm); - pt.x = *x; - pt.y = *y; - pt = dm.TransformPoint(pt); - *x = pt.x; - *y = pt.y; -} - -void uiDrawMatrixTransformSize(uiDrawMatrix *m, double *x, double *y) -{ - fallbackTransformSize(m, x, y); -} diff --git a/src/libui_sdl/libui/windows/drawpath.cpp b/src/libui_sdl/libui/windows/drawpath.cpp deleted file mode 100644 index 49855be..0000000 --- a/src/libui_sdl/libui/windows/drawpath.cpp +++ /dev/null @@ -1,246 +0,0 @@ -// 7 september 2015 -#include "uipriv_windows.hpp" -#include "draw.hpp" - -// TODO -// - write a test for transform followed by clip and clip followed by transform to make sure they work the same as on gtk+ and cocoa -// - write a test for nested transforms for gtk+ - -struct uiDrawPath { - ID2D1PathGeometry *path; - ID2D1GeometrySink *sink; - BOOL inFigure; -}; - -uiDrawPath *uiDrawNewPath(uiDrawFillMode fillmode) -{ - uiDrawPath *p; - HRESULT hr; - - p = uiNew(uiDrawPath); - hr = d2dfactory->CreatePathGeometry(&(p->path)); - if (hr != S_OK) - logHRESULT(L"error creating path", hr); - hr = p->path->Open(&(p->sink)); - if (hr != S_OK) - logHRESULT(L"error opening path", hr); - switch (fillmode) { - case uiDrawFillModeWinding: - p->sink->SetFillMode(D2D1_FILL_MODE_WINDING); - break; - case uiDrawFillModeAlternate: - p->sink->SetFillMode(D2D1_FILL_MODE_ALTERNATE); - break; - } - return p; -} - -void uiDrawFreePath(uiDrawPath *p) -{ - if (p->inFigure) - p->sink->EndFigure(D2D1_FIGURE_END_OPEN); - if (p->sink != NULL) - // TODO close sink first? - p->sink->Release(); - p->path->Release(); - uiFree(p); -} - -void uiDrawPathNewFigure(uiDrawPath *p, double x, double y) -{ - D2D1_POINT_2F pt; - - if (p->inFigure) - p->sink->EndFigure(D2D1_FIGURE_END_OPEN); - pt.x = x; - pt.y = y; - p->sink->BeginFigure(pt, D2D1_FIGURE_BEGIN_FILLED); - p->inFigure = TRUE; -} - -// Direct2D arcs require a little explanation. -// An arc in Direct2D is defined by the chord between the endpoints. -// There are four possible arcs with the same two endpoints that you can draw this way. -// See https://www.youtube.com/watch?v=ATS0ANW1UxQ for a demonstration. -// There is a property rotationAngle which deals with the rotation /of the entire ellipse that forms an ellpitical arc/ - it's effectively a transformation on the arc. -// That is to say, it's NOT THE SWEEP. -// The sweep is defined by the start and end points and whether the arc is "large". -// As a result, this design does not allow for full circles or ellipses with a single arc; they have to be simulated with two. - -struct arc { - double xCenter; - double yCenter; - double radius; - double startAngle; - double sweep; - int negative; -}; - -// this is used for the comparison below -// if it falls apart it can be changed later -#define aerMax 6 * DBL_EPSILON - -static void drawArc(uiDrawPath *p, struct arc *a, void (*startFunction)(uiDrawPath *, double, double)) -{ - double sinx, cosx; - double startX, startY; - double endX, endY; - D2D1_ARC_SEGMENT as; - BOOL fullCircle; - double absSweep; - - // as above, we can't do a full circle with one arc - // simulate it with two half-circles - // of course, we have a dragon: equality on floating-point values! - // I've chosen to do the AlmostEqualRelative() technique in https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ - fullCircle = FALSE; - // use the absolute value to tackle both ≥2Ď€ and ≤-2Ď€ at the same time - absSweep = fabs(a->sweep); - if (absSweep > (2 * uiPi)) // this part is easy - fullCircle = TRUE; - else { - double aerDiff; - - aerDiff = fabs(absSweep - (2 * uiPi)); - // if we got here then we know a->sweep is larger (or the same!) - fullCircle = aerDiff <= absSweep * aerMax; - } - // TODO make sure this works right for the negative direction - if (fullCircle) { - a->sweep = uiPi; - drawArc(p, a, startFunction); - a->startAngle += uiPi; - drawArc(p, a, NULL); - return; - } - - // first, figure out the arc's endpoints - // unfortunately D2D1SinCos() is only defined on Windows 8 and newer - // the MSDN page doesn't say this, but says it requires d2d1_1.h, which is listed as only supported on Windows 8 and newer elsewhere on MSDN - // so we must use sin() and cos() and hope it's right... - sinx = sin(a->startAngle); - cosx = cos(a->startAngle); - startX = a->xCenter + a->radius * cosx; - startY = a->yCenter + a->radius * sinx; - sinx = sin(a->startAngle + a->sweep); - cosx = cos(a->startAngle + a->sweep); - endX = a->xCenter + a->radius * cosx; - endY = a->yCenter + a->radius * sinx; - - // now do the initial step to get the current point to be the start point - // this is either creating a new figure, drawing a line, or (in the case of our full circle code above) doing nothing - if (startFunction != NULL) - (*startFunction)(p, startX, startY); - - // now we can draw the arc - as.point.x = endX; - as.point.y = endY; - as.size.width = a->radius; - as.size.height = a->radius; - as.rotationAngle = 0; // as above, not relevant for circles - if (a->negative) - as.sweepDirection = D2D1_SWEEP_DIRECTION_COUNTER_CLOCKWISE; - else - as.sweepDirection = D2D1_SWEEP_DIRECTION_CLOCKWISE; - // TODO explain the outer if - if (!a->negative) - if (a->sweep > uiPi) - as.arcSize = D2D1_ARC_SIZE_LARGE; - else - as.arcSize = D2D1_ARC_SIZE_SMALL; - else - // TODO especially this part - if (a->sweep > uiPi) - as.arcSize = D2D1_ARC_SIZE_SMALL; - else - as.arcSize = D2D1_ARC_SIZE_LARGE; - p->sink->AddArc(&as); -} - -void uiDrawPathNewFigureWithArc(uiDrawPath *p, double xCenter, double yCenter, double radius, double startAngle, double sweep, int negative) -{ - struct arc a; - - a.xCenter = xCenter; - a.yCenter = yCenter; - a.radius = radius; - a.startAngle = startAngle; - a.sweep = sweep; - a.negative = negative; - drawArc(p, &a, uiDrawPathNewFigure); -} - -void uiDrawPathLineTo(uiDrawPath *p, double x, double y) -{ - D2D1_POINT_2F pt; - - pt.x = x; - pt.y = y; - p->sink->AddLine(pt); -} - -void uiDrawPathArcTo(uiDrawPath *p, double xCenter, double yCenter, double radius, double startAngle, double sweep, int negative) -{ - struct arc a; - - a.xCenter = xCenter; - a.yCenter = yCenter; - a.radius = radius; - a.startAngle = startAngle; - a.sweep = sweep; - a.negative = negative; - drawArc(p, &a, uiDrawPathLineTo); -} - -void uiDrawPathBezierTo(uiDrawPath *p, double c1x, double c1y, double c2x, double c2y, double endX, double endY) -{ - D2D1_BEZIER_SEGMENT s; - - s.point1.x = c1x; - s.point1.y = c1y; - s.point2.x = c2x; - s.point2.y = c2y; - s.point3.x = endX; - s.point3.y = endY; - p->sink->AddBezier(&s); -} - -void uiDrawPathCloseFigure(uiDrawPath *p) -{ - p->sink->EndFigure(D2D1_FIGURE_END_CLOSED); - p->inFigure = FALSE; -} - -void uiDrawPathAddRectangle(uiDrawPath *p, double x, double y, double width, double height) -{ - // this is the same algorithm used by cairo and Core Graphics, according to their documentations - uiDrawPathNewFigure(p, x, y); - uiDrawPathLineTo(p, x + width, y); - uiDrawPathLineTo(p, x + width, y + height); - uiDrawPathLineTo(p, x, y + height); - uiDrawPathCloseFigure(p); -} - -void uiDrawPathEnd(uiDrawPath *p) -{ - HRESULT hr; - - if (p->inFigure) { - p->sink->EndFigure(D2D1_FIGURE_END_OPEN); - // needed for uiDrawFreePath() - p->inFigure = FALSE; - } - hr = p->sink->Close(); - if (hr != S_OK) - logHRESULT(L"error closing path", hr); - p->sink->Release(); - // also needed for uiDrawFreePath() - p->sink = NULL; -} - -ID2D1PathGeometry *pathGeometry(uiDrawPath *p) -{ - if (p->sink != NULL) - userbug("You cannot draw with a uiDrawPath that was not ended. (path: %p)", p); - return p->path; -} diff --git a/src/libui_sdl/libui/windows/drawtext.cpp b/src/libui_sdl/libui/windows/drawtext.cpp deleted file mode 100644 index 05a24f6..0000000 --- a/src/libui_sdl/libui/windows/drawtext.cpp +++ /dev/null @@ -1,531 +0,0 @@ -// 22 december 2015 -#include "uipriv_windows.hpp" -#include "draw.hpp" -// TODO really migrate - -// notes: -// only available in windows 8 and newer: -// - character spacing -// - kerning control -// - justficiation (how could I possibly be making this up?!) -// - vertical text (SERIOUSLY?! WHAT THE ACTUAL FUCK, MICROSOFT?!?!?!? DID YOU NOT THINK ABOUT THIS THE FIRST TIME, TRYING TO IMPROVE THE INTERNATIONALIZATION OF WINDOWS 7?!?!?! bonus: some parts of MSDN even say 8.1 and up only!) - -struct uiDrawFontFamilies { - fontCollection *fc; -}; - -uiDrawFontFamilies *uiDrawListFontFamilies(void) -{ - struct uiDrawFontFamilies *ff; - - ff = uiNew(struct uiDrawFontFamilies); - ff->fc = loadFontCollection(); - return ff; -} - -int uiDrawFontFamiliesNumFamilies(uiDrawFontFamilies *ff) -{ - return ff->fc->fonts->GetFontFamilyCount(); -} - -char *uiDrawFontFamiliesFamily(uiDrawFontFamilies *ff, int n) -{ - IDWriteFontFamily *family; - WCHAR *wname; - char *name; - HRESULT hr; - - hr = ff->fc->fonts->GetFontFamily(n, &family); - if (hr != S_OK) - logHRESULT(L"error getting font out of collection", hr); - wname = fontCollectionFamilyName(ff->fc, family); - name = toUTF8(wname); - uiFree(wname); - family->Release(); - return name; -} - -void uiDrawFreeFontFamilies(uiDrawFontFamilies *ff) -{ - fontCollectionFree(ff->fc); - uiFree(ff); -} - -struct uiDrawTextFont { - IDWriteFont *f; - WCHAR *family; // save for convenience in uiDrawNewTextLayout() - double size; -}; - -uiDrawTextFont *mkTextFont(IDWriteFont *df, BOOL addRef, WCHAR *family, BOOL copyFamily, double size) -{ - uiDrawTextFont *font; - WCHAR *copy; - HRESULT hr; - - font = uiNew(uiDrawTextFont); - font->f = df; - if (addRef) - font->f->AddRef(); - if (copyFamily) { - copy = (WCHAR *) uiAlloc((wcslen(family) + 1) * sizeof (WCHAR), "WCHAR[]"); - wcscpy(copy, family); - font->family = copy; - } else - font->family = family; - font->size = size; - return font; -} - -// TODO consider moving these all to dwrite.cpp - -// TODO MinGW-w64 is missing this one -#define DWRITE_FONT_WEIGHT_SEMI_LIGHT (DWRITE_FONT_WEIGHT(350)) -static const struct { - bool lastOne; - uiDrawTextWeight uival; - DWRITE_FONT_WEIGHT dwval; -} dwriteWeights[] = { - { false, uiDrawTextWeightThin, DWRITE_FONT_WEIGHT_THIN }, - { false, uiDrawTextWeightUltraLight, DWRITE_FONT_WEIGHT_ULTRA_LIGHT }, - { false, uiDrawTextWeightLight, DWRITE_FONT_WEIGHT_LIGHT }, - { false, uiDrawTextWeightBook, DWRITE_FONT_WEIGHT_SEMI_LIGHT }, - { false, uiDrawTextWeightNormal, DWRITE_FONT_WEIGHT_NORMAL }, - { false, uiDrawTextWeightMedium, DWRITE_FONT_WEIGHT_MEDIUM }, - { false, uiDrawTextWeightSemiBold, DWRITE_FONT_WEIGHT_SEMI_BOLD }, - { false, uiDrawTextWeightBold, DWRITE_FONT_WEIGHT_BOLD }, - { false, uiDrawTextWeightUltraBold, DWRITE_FONT_WEIGHT_ULTRA_BOLD }, - { false, uiDrawTextWeightHeavy, DWRITE_FONT_WEIGHT_HEAVY }, - { true, uiDrawTextWeightUltraHeavy, DWRITE_FONT_WEIGHT_ULTRA_BLACK, }, -}; - -static const struct { - bool lastOne; - uiDrawTextItalic uival; - DWRITE_FONT_STYLE dwval; -} dwriteItalics[] = { - { false, uiDrawTextItalicNormal, DWRITE_FONT_STYLE_NORMAL }, - { false, uiDrawTextItalicOblique, DWRITE_FONT_STYLE_OBLIQUE }, - { true, uiDrawTextItalicItalic, DWRITE_FONT_STYLE_ITALIC }, -}; - -static const struct { - bool lastOne; - uiDrawTextStretch uival; - DWRITE_FONT_STRETCH dwval; -} dwriteStretches[] = { - { false, uiDrawTextStretchUltraCondensed, DWRITE_FONT_STRETCH_ULTRA_CONDENSED }, - { false, uiDrawTextStretchExtraCondensed, DWRITE_FONT_STRETCH_EXTRA_CONDENSED }, - { false, uiDrawTextStretchCondensed, DWRITE_FONT_STRETCH_CONDENSED }, - { false, uiDrawTextStretchSemiCondensed, DWRITE_FONT_STRETCH_SEMI_CONDENSED }, - { false, uiDrawTextStretchNormal, DWRITE_FONT_STRETCH_NORMAL }, - { false, uiDrawTextStretchSemiExpanded, DWRITE_FONT_STRETCH_SEMI_EXPANDED }, - { false, uiDrawTextStretchExpanded, DWRITE_FONT_STRETCH_EXPANDED }, - { false, uiDrawTextStretchExtraExpanded, DWRITE_FONT_STRETCH_EXTRA_EXPANDED }, - { true, uiDrawTextStretchUltraExpanded, DWRITE_FONT_STRETCH_ULTRA_EXPANDED }, -}; - -void attrToDWriteAttr(struct dwriteAttr *attr) -{ - bool found; - int i; - - found = false; - for (i = 0; ; i++) { - if (dwriteWeights[i].uival == attr->weight) { - attr->dweight = dwriteWeights[i].dwval; - found = true; - break; - } - if (dwriteWeights[i].lastOne) - break; - } - if (!found) - userbug("Invalid text weight %d passed to text function.", attr->weight); - - found = false; - for (i = 0; ; i++) { - if (dwriteItalics[i].uival == attr->italic) { - attr->ditalic = dwriteItalics[i].dwval; - found = true; - break; - } - if (dwriteItalics[i].lastOne) - break; - } - if (!found) - userbug("Invalid text italic %d passed to text function.", attr->italic); - - found = false; - for (i = 0; ; i++) { - if (dwriteStretches[i].uival == attr->stretch) { - attr->dstretch = dwriteStretches[i].dwval; - found = true; - break; - } - if (dwriteStretches[i].lastOne) - break; - } - if (!found) - // TODO on other platforms too - userbug("Invalid text stretch %d passed to text function.", attr->stretch); -} - -void dwriteAttrToAttr(struct dwriteAttr *attr) -{ - int weight, against, n; - int curdiff, curindex; - bool found; - int i; - - // weight is scaled; we need to test to see what's nearest - weight = (int) (attr->dweight); - against = (int) (dwriteWeights[0].dwval); - curdiff = abs(against - weight); - curindex = 0; - for (i = 1; ; i++) { - against = (int) (dwriteWeights[i].dwval); - n = abs(against - weight); - if (n < curdiff) { - curdiff = n; - curindex = i; - } - if (dwriteWeights[i].lastOne) - break; - } - attr->weight = dwriteWeights[i].uival; - - // italic and stretch are simple values; we can just do a matching search - found = false; - for (i = 0; ; i++) { - if (dwriteItalics[i].dwval == attr->ditalic) { - attr->italic = dwriteItalics[i].uival; - found = true; - break; - } - if (dwriteItalics[i].lastOne) - break; - } - if (!found) - // these are implbug()s because users shouldn't be able to get here directly; TODO? - implbug("invalid italic %d passed to dwriteAttrToAttr()", attr->ditalic); - - found = false; - for (i = 0; ; i++) { - if (dwriteStretches[i].dwval == attr->dstretch) { - attr->stretch = dwriteStretches[i].uival; - found = true; - break; - } - if (dwriteStretches[i].lastOne) - break; - } - if (!found) - implbug("invalid stretch %d passed to dwriteAttrToAttr()", attr->dstretch); -} - -uiDrawTextFont *uiDrawLoadClosestFont(const uiDrawTextFontDescriptor *desc) -{ - uiDrawTextFont *font; - IDWriteFontCollection *collection; - UINT32 index; - BOOL exists; - struct dwriteAttr attr; - IDWriteFontFamily *family; - WCHAR *wfamily; - IDWriteFont *match; - HRESULT hr; - - // always get the latest available font information - hr = dwfactory->GetSystemFontCollection(&collection, TRUE); - if (hr != S_OK) - logHRESULT(L"error getting system font collection", hr); - - wfamily = toUTF16(desc->Family); - hr = collection->FindFamilyName(wfamily, &index, &exists); - if (hr != S_OK) - logHRESULT(L"error finding font family", hr); - if (!exists) - implbug("LONGTERM family not found in uiDrawLoadClosestFont()", hr); - hr = collection->GetFontFamily(index, &family); - if (hr != S_OK) - logHRESULT(L"error loading font family", hr); - - attr.weight = desc->Weight; - attr.italic = desc->Italic; - attr.stretch = desc->Stretch; - attrToDWriteAttr(&attr); - hr = family->GetFirstMatchingFont( - attr.dweight, - attr.dstretch, - attr.ditalic, - &match); - if (hr != S_OK) - logHRESULT(L"error loading font", hr); - - font = mkTextFont(match, - FALSE, // we own the initial reference; no need to add another one - wfamily, FALSE, // will be freed with font - desc->Size); - - family->Release(); - collection->Release(); - - return font; -} - -void uiDrawFreeTextFont(uiDrawTextFont *font) -{ - font->f->Release(); - uiFree(font->family); - uiFree(font); -} - -uintptr_t uiDrawTextFontHandle(uiDrawTextFont *font) -{ - return (uintptr_t) (font->f); -} - -void uiDrawTextFontDescribe(uiDrawTextFont *font, uiDrawTextFontDescriptor *desc) -{ - // TODO - - desc->Size = font->size; - - // TODO -} - -// text sizes are 1/72 of an inch -// points in Direct2D are 1/96 of an inch (https://msdn.microsoft.com/en-us/library/windows/desktop/ff684173%28v=vs.85%29.aspx, https://msdn.microsoft.com/en-us/library/windows/desktop/hh447022%28v=vs.85%29.aspx) -// As for the actual conversion from design units, see: -// - http://cboard.cprogramming.com/windows-programming/136733-directwrite-font-height-issues.html -// - https://sourceforge.net/p/vstgui/mailman/message/32483143/ -// - http://xboxforums.create.msdn.com/forums/t/109445.aspx -// - https://msdn.microsoft.com/en-us/library/dd183564%28v=vs.85%29.aspx -// - http://www.fontbureau.com/blog/the-em/ -// TODO make points here about how DIPs in DirectWrite == DIPs in Direct2D; if not, figure out what they really are? for the width and layout functions later -static double scaleUnits(double what, double designUnitsPerEm, double size) -{ - return (what / designUnitsPerEm) * (size * (96.0 / 72.0)); -} - -void uiDrawTextFontGetMetrics(uiDrawTextFont *font, uiDrawTextFontMetrics *metrics) -{ - DWRITE_FONT_METRICS dm; - - font->f->GetMetrics(&dm); - metrics->Ascent = scaleUnits(dm.ascent, dm.designUnitsPerEm, font->size); - metrics->Descent = scaleUnits(dm.descent, dm.designUnitsPerEm, font->size); - // TODO what happens if dm.xxx is negative? - // TODO remember what this was for - metrics->Leading = scaleUnits(dm.lineGap, dm.designUnitsPerEm, font->size); - metrics->UnderlinePos = scaleUnits(dm.underlinePosition, dm.designUnitsPerEm, font->size); - metrics->UnderlineThickness = scaleUnits(dm.underlineThickness, dm.designUnitsPerEm, font->size); -} - -// some attributes, such as foreground color, can't be applied until after we establish a Direct2D context :/ so we have to prepare all attributes in advance -// also since there's no way to clear the attributes from a layout en masse (apart from overwriting them all), we'll play it safe by creating a new layout each time -enum layoutAttrType { - layoutAttrColor, -}; - -struct layoutAttr { - enum layoutAttrType type; - int start; - int end; - double components[4]; -}; - -struct uiDrawTextLayout { - WCHAR *text; - size_t textlen; - size_t *graphemes; - double width; - IDWriteTextFormat *format; - std::vector *attrs; -}; - -uiDrawTextLayout *uiDrawNewTextLayout(const char *text, uiDrawTextFont *defaultFont, double width) -{ - uiDrawTextLayout *layout; - HRESULT hr; - - layout = uiNew(uiDrawTextLayout); - - hr = dwfactory->CreateTextFormat(defaultFont->family, - NULL, - defaultFont->f->GetWeight(), - defaultFont->f->GetStyle(), - defaultFont->f->GetStretch(), - // typographic points are 1/72 inch; this parameter is 1/96 inch - // fortunately Microsoft does this too, in https://msdn.microsoft.com/en-us/library/windows/desktop/dd371554%28v=vs.85%29.aspx - defaultFont->size * (96.0 / 72.0), - // see http://stackoverflow.com/questions/28397971/idwritefactorycreatetextformat-failing and https://msdn.microsoft.com/en-us/library/windows/desktop/dd368203.aspx - // TODO use the current locale again? - L"", - &(layout->format)); - if (hr != S_OK) - logHRESULT(L"error creating IDWriteTextFormat", hr); - - layout->text = toUTF16(text); - layout->textlen = wcslen(layout->text); - layout->graphemes = graphemes(layout->text); - - uiDrawTextLayoutSetWidth(layout, width); - - layout->attrs = new std::vector; - - return layout; -} - -void uiDrawFreeTextLayout(uiDrawTextLayout *layout) -{ - delete layout->attrs; - layout->format->Release(); - uiFree(layout->graphemes); - uiFree(layout->text); - uiFree(layout); -} - -static ID2D1SolidColorBrush *mkSolidBrush(ID2D1RenderTarget *rt, double r, double g, double b, double a) -{ - D2D1_BRUSH_PROPERTIES props; - D2D1_COLOR_F color; - ID2D1SolidColorBrush *brush; - HRESULT hr; - - ZeroMemory(&props, sizeof (D2D1_BRUSH_PROPERTIES)); - props.opacity = 1.0; - // identity matrix - props.transform._11 = 1; - props.transform._22 = 1; - color.r = r; - color.g = g; - color.b = b; - color.a = a; - hr = rt->CreateSolidColorBrush( - &color, - &props, - &brush); - if (hr != S_OK) - logHRESULT(L"error creating solid brush", hr); - return brush; -} - -IDWriteTextLayout *prepareLayout(uiDrawTextLayout *layout, ID2D1RenderTarget *rt) -{ - IDWriteTextLayout *dl; - DWRITE_TEXT_RANGE range; - IUnknown *unkBrush; - DWRITE_WORD_WRAPPING wrap; - FLOAT maxWidth; - HRESULT hr; - - hr = dwfactory->CreateTextLayout(layout->text, layout->textlen, - layout->format, - // FLOAT is float, not double, so this should work... TODO - FLT_MAX, FLT_MAX, - &dl); - if (hr != S_OK) - logHRESULT(L"error creating IDWriteTextLayout", hr); - - for (const struct layoutAttr &attr : *(layout->attrs)) { - range.startPosition = layout->graphemes[attr.start]; - range.length = layout->graphemes[attr.end] - layout->graphemes[attr.start]; - switch (attr.type) { - case layoutAttrColor: - if (rt == NULL) // determining extents, not drawing - break; - unkBrush = mkSolidBrush(rt, - attr.components[0], - attr.components[1], - attr.components[2], - attr.components[3]); - hr = dl->SetDrawingEffect(unkBrush, range); - unkBrush->Release(); // associated with dl - break; - default: - hr = E_FAIL; - logHRESULT(L"invalid text attribute type", hr); - } - if (hr != S_OK) - logHRESULT(L"error adding attribute to text layout", hr); - } - - // and set the width - // this is the only wrapping mode (apart from "no wrap") available prior to Windows 8.1 - wrap = DWRITE_WORD_WRAPPING_WRAP; - maxWidth = layout->width; - if (layout->width < 0) { - wrap = DWRITE_WORD_WRAPPING_NO_WRAP; - // setting the max width in this case technically isn't needed since the wrap mode will simply ignore the max width, but let's do it just to be safe - maxWidth = FLT_MAX; // see TODO above - } - hr = dl->SetWordWrapping(wrap); - if (hr != S_OK) - logHRESULT(L"error setting word wrapping mode", hr); - hr = dl->SetMaxWidth(maxWidth); - if (hr != S_OK) - logHRESULT(L"error setting max layout width", hr); - - return dl; -} - - -void uiDrawTextLayoutSetWidth(uiDrawTextLayout *layout, double width) -{ - layout->width = width; -} - -// TODO for a single line the height includes the leading; it should not -void uiDrawTextLayoutExtents(uiDrawTextLayout *layout, double *width, double *height) -{ - IDWriteTextLayout *dl; - DWRITE_TEXT_METRICS metrics; - HRESULT hr; - - dl = prepareLayout(layout, NULL); - hr = dl->GetMetrics(&metrics); - if (hr != S_OK) - logHRESULT(L"error getting layout metrics", hr); - *width = metrics.width; - // TODO make sure the behavior of this on empty strings is the same on all platforms - *height = metrics.height; - dl->Release(); -} - -void uiDrawText(uiDrawContext *c, double x, double y, uiDrawTextLayout *layout) -{ - IDWriteTextLayout *dl; - D2D1_POINT_2F pt; - ID2D1Brush *black; - HRESULT hr; - - // TODO document that fully opaque black is the default text color; figure out whether this is upheld in various scenarios on other platforms - black = mkSolidBrush(c->rt, 0.0, 0.0, 0.0, 1.0); - - dl = prepareLayout(layout, c->rt); - pt.x = x; - pt.y = y; - // TODO D2D1_DRAW_TEXT_OPTIONS_NO_SNAP? - // TODO D2D1_DRAW_TEXT_OPTIONS_CLIP? - // TODO when setting 8.1 as minimum, D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT? - c->rt->DrawTextLayout(pt, dl, black, D2D1_DRAW_TEXT_OPTIONS_NONE); - dl->Release(); - - black->Release(); -} - -void uiDrawTextLayoutSetColor(uiDrawTextLayout *layout, int startChar, int endChar, double r, double g, double b, double a) -{ - struct layoutAttr attr; - - attr.type = layoutAttrColor; - attr.start = startChar; - attr.end = endChar; - attr.components[0] = r; - attr.components[1] = g; - attr.components[2] = b; - attr.components[3] = a; - layout->attrs->push_back(attr); -} diff --git a/src/libui_sdl/libui/windows/dwrite.cpp b/src/libui_sdl/libui/windows/dwrite.cpp deleted file mode 100644 index 9156f17..0000000 --- a/src/libui_sdl/libui/windows/dwrite.cpp +++ /dev/null @@ -1,88 +0,0 @@ -// 14 april 2016 -#include "uipriv_windows.hpp" -// TODO really migrate? - -IDWriteFactory *dwfactory = NULL; - -HRESULT initDrawText(void) -{ - // TOOD use DWRITE_FACTORY_TYPE_ISOLATED instead? - return DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, - __uuidof (IDWriteFactory), - (IUnknown **) (&dwfactory)); -} - -void uninitDrawText(void) -{ - dwfactory->Release(); -} - -fontCollection *loadFontCollection(void) -{ - fontCollection *fc; - HRESULT hr; - - fc = uiNew(fontCollection); - // always get the latest available font information - hr = dwfactory->GetSystemFontCollection(&(fc->fonts), TRUE); - if (hr != S_OK) - logHRESULT(L"error getting system font collection", hr); - fc->userLocaleSuccess = GetUserDefaultLocaleName(fc->userLocale, LOCALE_NAME_MAX_LENGTH); - return fc; -} - -WCHAR *fontCollectionFamilyName(fontCollection *fc, IDWriteFontFamily *family) -{ - IDWriteLocalizedStrings *names; - WCHAR *str; - HRESULT hr; - - hr = family->GetFamilyNames(&names); - if (hr != S_OK) - logHRESULT(L"error getting names of font out", hr); - str = fontCollectionCorrectString(fc, names); - names->Release(); - return str; -} - -WCHAR *fontCollectionCorrectString(fontCollection *fc, IDWriteLocalizedStrings *names) -{ - UINT32 index; - BOOL exists; - UINT32 length; - WCHAR *wname; - HRESULT hr; - - // this is complex, but we ignore failure conditions to allow fallbacks - // 1) If the user locale name was successfully retrieved, try it - // 2) If the user locale name was not successfully retrieved, or that locale's string does not exist, or an error occurred, try L"en-us", the US English locale - // 3) And if that fails, assume the first one - // This algorithm is straight from MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/dd368214%28v=vs.85%29.aspx - // For step 2 to work, start by setting hr to S_OK and exists to FALSE. - // TODO does it skip step 2 entirely if step 1 fails? rewrite it to be a more pure conversion of the MSDN code? - hr = S_OK; - exists = FALSE; - if (fc->userLocaleSuccess != 0) - hr = names->FindLocaleName(fc->userLocale, &index, &exists); - if (hr != S_OK || (hr == S_OK && !exists)) - hr = names->FindLocaleName(L"en-us", &index, &exists); - if (!exists) - index = 0; - - hr = names->GetStringLength(index, &length); - if (hr != S_OK) - logHRESULT(L"error getting length of font name", hr); - // GetStringLength() does not include the null terminator, but GetString() does - wname = (WCHAR *) uiAlloc((length + 1) * sizeof (WCHAR), "WCHAR[]"); - hr = names->GetString(index, wname, length + 1); - if (hr != S_OK) - logHRESULT(L"error getting font name", hr); - - return wname; -} - -void fontCollectionFree(fontCollection *fc) -{ - fc->fonts->Release(); - uiFree(fc); -} diff --git a/src/libui_sdl/libui/windows/editablecombo.cpp b/src/libui_sdl/libui/windows/editablecombo.cpp deleted file mode 100644 index 9e1fdbf..0000000 --- a/src/libui_sdl/libui/windows/editablecombo.cpp +++ /dev/null @@ -1,115 +0,0 @@ -// 20 may 2015 -#include "uipriv_windows.hpp" - -// we as Common Controls 6 users don't need to worry about the height of comboboxes; see http://blogs.msdn.com/b/oldnewthing/archive/2006/03/10/548537.aspx - -struct uiEditableCombobox { - uiWindowsControl c; - HWND hwnd; - void (*onChanged)(uiEditableCombobox *, void *); - void *onChangedData; -}; - -static BOOL onWM_COMMAND(uiControl *cc, HWND hwnd, WORD code, LRESULT *lResult) -{ - uiEditableCombobox *c = uiEditableCombobox(cc); - - if (code == CBN_SELCHANGE) { - // like on OS X, this is sent before the edit has been updated :( - if (PostMessage(parentOf(hwnd), - WM_COMMAND, - MAKEWPARAM(GetWindowLongPtrW(hwnd, GWLP_ID), CBN_EDITCHANGE), - (LPARAM) hwnd) == 0) - logLastError(L"error posting CBN_EDITCHANGE after CBN_SELCHANGE"); - *lResult = 0; - return TRUE; - } - if (code != CBN_EDITCHANGE) - return FALSE; - (*(c->onChanged))(c, c->onChangedData); - *lResult = 0; - return TRUE; -} - -void uiEditableComboboxDestroy(uiControl *cc) -{ - uiEditableCombobox *c = uiEditableCombobox(cc); - - uiWindowsUnregisterWM_COMMANDHandler(c->hwnd); - uiWindowsEnsureDestroyWindow(c->hwnd); - uiFreeControl(uiControl(c)); -} - -uiWindowsControlAllDefaultsExceptDestroy(uiEditableCombobox) - -// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing -#define comboboxWidth 107 /* this is actually the shorter progress bar width, but Microsoft only indicates as wide as necessary; LONGTERM */ -#define comboboxHeight 14 /* LONGTERM: is this too high? */ - -static void uiEditableComboboxMinimumSize(uiWindowsControl *cc, int *width, int *height) -{ - uiEditableCombobox *c = uiEditableCombobox(cc); - uiWindowsSizing sizing; - int x, y; - - x = comboboxWidth; - y = comboboxHeight; - uiWindowsGetSizing(c->hwnd, &sizing); - uiWindowsSizingDlgUnitsToPixels(&sizing, &x, &y); - *width = x; - *height = y; -} - -static void defaultOnChanged(uiEditableCombobox *c, void *data) -{ - // do nothing -} - -void uiEditableComboboxAppend(uiEditableCombobox *c, const char *text) -{ - WCHAR *wtext; - LRESULT res; - - wtext = toUTF16(text); - res = SendMessageW(c->hwnd, CB_ADDSTRING, 0, (LPARAM) wtext); - if (res == (LRESULT) CB_ERR) - logLastError(L"error appending item to uiEditableCombobox"); - else if (res == (LRESULT) CB_ERRSPACE) - logLastError(L"memory exhausted appending item to uiEditableCombobox"); - uiFree(wtext); -} - -char *uiEditableComboboxText(uiEditableCombobox *c) -{ - return uiWindowsWindowText(c->hwnd); -} - -void uiEditableComboboxSetText(uiEditableCombobox *c, const char *text) -{ - // does not trigger any notifications - uiWindowsSetWindowText(c->hwnd, text); -} - -void uiEditableComboboxOnChanged(uiEditableCombobox *c, void (*f)(uiEditableCombobox *c, void *data), void *data) -{ - c->onChanged = f; - c->onChangedData = data; -} - -uiEditableCombobox *uiNewEditableCombobox(void) -{ - uiEditableCombobox *c; - - uiWindowsNewControl(uiEditableCombobox, c); - - c->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE, - L"combobox", L"", - CBS_DROPDOWN | WS_TABSTOP, - hInstance, NULL, - TRUE); - - uiWindowsRegisterWM_COMMANDHandler(c->hwnd, onWM_COMMAND, uiControl(c)); - uiEditableComboboxOnChanged(c, defaultOnChanged, NULL); - - return c; -} diff --git a/src/libui_sdl/libui/windows/entry.cpp b/src/libui_sdl/libui/windows/entry.cpp deleted file mode 100644 index a7a077f..0000000 --- a/src/libui_sdl/libui/windows/entry.cpp +++ /dev/null @@ -1,134 +0,0 @@ -// 8 april 2015 -#include "uipriv_windows.hpp" - -struct uiEntry { - uiWindowsControl c; - HWND hwnd; - void (*onChanged)(uiEntry *, void *); - void *onChangedData; - BOOL inhibitChanged; -}; - -static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult) -{ - uiEntry *e = uiEntry(c); - - if (code != EN_CHANGE) - return FALSE; - if (e->inhibitChanged) - return FALSE; - (*(e->onChanged))(e, e->onChangedData); - *lResult = 0; - return TRUE; -} - -static void uiEntryDestroy(uiControl *c) -{ - uiEntry *e = uiEntry(c); - - uiWindowsUnregisterWM_COMMANDHandler(e->hwnd); - uiWindowsEnsureDestroyWindow(e->hwnd); - uiFreeControl(uiControl(e)); -} - -uiWindowsControlAllDefaultsExceptDestroy(uiEntry) - -// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing -#define entryWidth 107 /* this is actually the shorter progress bar width, but Microsoft only indicates as wide as necessary */ -#define entryHeight 14 - -static void uiEntryMinimumSize(uiWindowsControl *c, int *width, int *height) -{ - uiEntry *e = uiEntry(c); - uiWindowsSizing sizing; - int x, y; - - x = entryWidth; - y = entryHeight; - uiWindowsGetSizing(e->hwnd, &sizing); - uiWindowsSizingDlgUnitsToPixels(&sizing, &x, &y); - *width = x; - *height = y; -} - -static void defaultOnChanged(uiEntry *e, void *data) -{ - // do nothing -} - -char *uiEntryText(uiEntry *e) -{ - return uiWindowsWindowText(e->hwnd); -} - -void uiEntrySetText(uiEntry *e, const char *text) -{ - // doing this raises an EN_CHANGED - e->inhibitChanged = TRUE; - uiWindowsSetWindowText(e->hwnd, text); - e->inhibitChanged = FALSE; - // don't queue the control for resize; entry sizes are independent of their contents -} - -void uiEntryOnChanged(uiEntry *e, void (*f)(uiEntry *, void *), void *data) -{ - e->onChanged = f; - e->onChangedData = data; -} - -int uiEntryReadOnly(uiEntry *e) -{ - return (getStyle(e->hwnd) & ES_READONLY) != 0; -} - -void uiEntrySetReadOnly(uiEntry *e, int readonly) -{ - WPARAM ro; - - ro = (WPARAM) FALSE; - if (readonly) - ro = (WPARAM) TRUE; - if (SendMessage(e->hwnd, EM_SETREADONLY, ro, 0) == 0) - logLastError(L"error making uiEntry read-only"); -} - -static uiEntry *finishNewEntry(DWORD style) -{ - uiEntry *e; - - uiWindowsNewControl(uiEntry, e); - - e->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE, - L"edit", L"", - style | ES_AUTOHSCROLL | ES_LEFT | ES_NOHIDESEL | WS_TABSTOP, - hInstance, NULL, - TRUE); - - uiWindowsRegisterWM_COMMANDHandler(e->hwnd, onWM_COMMAND, uiControl(e)); - uiEntryOnChanged(e, defaultOnChanged, NULL); - - return e; -} - -uiEntry *uiNewEntry(void) -{ - return finishNewEntry(0); -} - -uiEntry *uiNewPasswordEntry(void) -{ - return finishNewEntry(ES_PASSWORD); -} - -uiEntry *uiNewSearchEntry(void) -{ - uiEntry *e; - HRESULT hr; - - e = finishNewEntry(0); - // TODO this is from ThemeExplorer; is it documented anywhere? - // TODO SearchBoxEditComposited has no border - hr = SetWindowTheme(e->hwnd, L"SearchBoxEdit", NULL); - // TODO will hr be S_OK if themes are disabled? - return e; -} diff --git a/src/libui_sdl/libui/windows/events.cpp b/src/libui_sdl/libui/windows/events.cpp deleted file mode 100644 index 45e8d43..0000000 --- a/src/libui_sdl/libui/windows/events.cpp +++ /dev/null @@ -1,151 +0,0 @@ -// 20 may 2015 -#include "uipriv_windows.hpp" - -struct handler { - BOOL (*commandHandler)(uiControl *, HWND, WORD, LRESULT *); - BOOL (*notifyHandler)(uiControl *, HWND, NMHDR *, LRESULT *); - BOOL (*hscrollHandler)(uiControl *, HWND, WORD, LRESULT *); - uiControl *c; - - // just to ensure handlers[new HWND] initializes properly - // TODO gcc can't handle a struct keyword here? or is that a MSVC extension? - handler() - { - this->commandHandler = NULL; - this->notifyHandler = NULL; - this->hscrollHandler = NULL; - this->c = NULL; - } -}; - -static std::map handlers; - -void uiWindowsRegisterWM_COMMANDHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *), uiControl *c) -{ - if (handlers[hwnd].commandHandler != NULL) - implbug("already registered a WM_COMMAND handler to window handle %p", hwnd); - handlers[hwnd].commandHandler = handler; - handlers[hwnd].c = c; -} - -void uiWindowsRegisterWM_NOTIFYHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, NMHDR *, LRESULT *), uiControl *c) -{ - if (handlers[hwnd].notifyHandler != NULL) - implbug("already registered a WM_NOTIFY handler to window handle %p", hwnd); - handlers[hwnd].notifyHandler = handler; - handlers[hwnd].c = c; -} - -void uiWindowsRegisterWM_HSCROLLHandler(HWND hwnd, BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *), uiControl *c) -{ - if (handlers[hwnd].hscrollHandler != NULL) - implbug("already registered a WM_HSCROLL handler to window handle %p", hwnd); - handlers[hwnd].hscrollHandler = handler; - handlers[hwnd].c = c; -} - -void uiWindowsUnregisterWM_COMMANDHandler(HWND hwnd) -{ - if (handlers[hwnd].commandHandler == NULL) - implbug("window handle %p not registered to receive WM_COMMAND events", hwnd); - handlers[hwnd].commandHandler = NULL; -} - -void uiWindowsUnregisterWM_NOTIFYHandler(HWND hwnd) -{ - if (handlers[hwnd].notifyHandler == NULL) - implbug("window handle %p not registered to receive WM_NOTIFY events", hwnd); - handlers[hwnd].notifyHandler = NULL; -} - -void uiWindowsUnregisterWM_HSCROLLHandler(HWND hwnd) -{ - if (handlers[hwnd].hscrollHandler == NULL) - implbug("window handle %p not registered to receive WM_HSCROLL events", hwnd); - handlers[hwnd].hscrollHandler = NULL; -} - -template -static BOOL shouldRun(HWND hwnd, T method) -{ - // not from a window - if (hwnd == NULL) - return FALSE; - // don't bounce back if to the utility window, in which case act as if the message was ignored - if (IsChild(utilWindow, hwnd) != 0) - return FALSE; - // registered? - return method != NULL; -} - -BOOL runWM_COMMAND(WPARAM wParam, LPARAM lParam, LRESULT *lResult) -{ - HWND hwnd; - WORD arg3; - BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *); - uiControl *c; - - hwnd = (HWND) lParam; - arg3 = HIWORD(wParam); - handler = handlers[hwnd].commandHandler; - c = handlers[hwnd].c; - if (shouldRun(hwnd, handler)) - return (*handler)(c, hwnd, arg3, lResult); - return FALSE; -} - -BOOL runWM_NOTIFY(WPARAM wParam, LPARAM lParam, LRESULT *lResult) -{ - HWND hwnd; - NMHDR *arg3; - BOOL (*handler)(uiControl *, HWND, NMHDR *, LRESULT *); - uiControl *c; - - arg3 = (NMHDR *) lParam; - hwnd = arg3->hwndFrom; - handler = handlers[hwnd].notifyHandler; - c = handlers[hwnd].c; - if (shouldRun(hwnd, handler)) - return (*handler)(c, hwnd, arg3, lResult); - return FALSE; -} - -BOOL runWM_HSCROLL(WPARAM wParam, LPARAM lParam, LRESULT *lResult) -{ - HWND hwnd; - WORD arg3; - BOOL (*handler)(uiControl *, HWND, WORD, LRESULT *); - uiControl *c; - - hwnd = (HWND) lParam; - arg3 = LOWORD(wParam); - handler = handlers[hwnd].hscrollHandler; - c = handlers[hwnd].c; - if (shouldRun(hwnd, handler)) - return (*handler)(c, hwnd, arg3, lResult); - return FALSE; -} - -static std::map wininichanges; - -void uiWindowsRegisterReceiveWM_WININICHANGE(HWND hwnd) -{ - if (wininichanges[hwnd]) - implbug("window handle %p already subscribed to receive WM_WINICHANGEs", hwnd); - wininichanges[hwnd] = true; -} - -void uiWindowsUnregisterReceiveWM_WININICHANGE(HWND hwnd) -{ - if (!wininichanges[hwnd]) - implbug("window handle %p not registered to receive WM_WININICHANGEs", hwnd); - wininichanges[hwnd] = false; -} - -void issueWM_WININICHANGE(WPARAM wParam, LPARAM lParam) -{ - struct wininichange *ch; - - for (const auto &iter : wininichanges) - SendMessageW(iter.first, WM_WININICHANGE, wParam, lParam); -} diff --git a/src/libui_sdl/libui/windows/fontbutton.cpp b/src/libui_sdl/libui/windows/fontbutton.cpp deleted file mode 100644 index d2d4dab..0000000 --- a/src/libui_sdl/libui/windows/fontbutton.cpp +++ /dev/null @@ -1,122 +0,0 @@ -// 14 april 2016 -#include "uipriv_windows.hpp" - -struct uiFontButton { - uiWindowsControl c; - HWND hwnd; - struct fontDialogParams params; - BOOL already; - void (*onChanged)(uiFontButton *, void *); - void *onChangedData; -}; - -static void uiFontButtonDestroy(uiControl *c) -{ - uiFontButton *b = uiFontButton(c); - - uiWindowsUnregisterWM_COMMANDHandler(b->hwnd); - destroyFontDialogParams(&(b->params)); - uiWindowsEnsureDestroyWindow(b->hwnd); - uiFreeControl(uiControl(b)); -} - -static void updateFontButtonLabel(uiFontButton *b) -{ - WCHAR *text; - - text = fontDialogParamsToString(&(b->params)); - setWindowText(b->hwnd, text); - uiFree(text); - - // changing the text might necessitate a change in the button's size - uiWindowsControlMinimumSizeChanged(uiWindowsControl(b)); -} - -static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult) -{ - uiFontButton *b = uiFontButton(c); - HWND parent; - - if (code != BN_CLICKED) - return FALSE; - - parent = parentToplevel(b->hwnd); - if (showFontDialog(parent, &(b->params))) { - updateFontButtonLabel(b); - (*(b->onChanged))(b, b->onChangedData); - } - - *lResult = 0; - return TRUE; -} - -uiWindowsControlAllDefaultsExceptDestroy(uiFontButton) - -// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing -#define buttonHeight 14 - -static void uiFontButtonMinimumSize(uiWindowsControl *c, int *width, int *height) -{ - uiFontButton *b = uiFontButton(c); - SIZE size; - uiWindowsSizing sizing; - int y; - - // try the comctl32 version 6 way - size.cx = 0; // explicitly ask for ideal size - size.cy = 0; - if (SendMessageW(b->hwnd, BCM_GETIDEALSIZE, 0, (LPARAM) (&size)) != FALSE) { - *width = size.cx; - *height = size.cy; - return; - } - - // that didn't work; fall back to using Microsoft's metrics - // Microsoft says to use a fixed width for all buttons; this isn't good enough - // use the text width instead, with some edge padding - *width = uiWindowsWindowTextWidth(b->hwnd) + (2 * GetSystemMetrics(SM_CXEDGE)); - y = buttonHeight; - uiWindowsGetSizing(b->hwnd, &sizing); - uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, &y); - *height = y; -} - -static void defaultOnChanged(uiFontButton *b, void *data) -{ - // do nothing -} - -uiDrawTextFont *uiFontButtonFont(uiFontButton *b) -{ - // we don't own b->params.font; we have to add a reference - // we don't own b->params.familyName either; we have to copy it - return mkTextFont(b->params.font, TRUE, b->params.familyName, TRUE, b->params.size); -} - -void uiFontButtonOnChanged(uiFontButton *b, void (*f)(uiFontButton *, void *), void *data) -{ - b->onChanged = f; - b->onChangedData = data; -} - -uiFontButton *uiNewFontButton(void) -{ - uiFontButton *b; - - uiWindowsNewControl(uiFontButton, b); - - b->hwnd = uiWindowsEnsureCreateControlHWND(0, - L"button", L"you should not be seeing this", - BS_PUSHBUTTON | WS_TABSTOP, - hInstance, NULL, - TRUE); - - loadInitialFontDialogParams(&(b->params)); - - uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b)); - uiFontButtonOnChanged(b, defaultOnChanged, NULL); - - updateFontButtonLabel(b); - - return b; -} diff --git a/src/libui_sdl/libui/windows/fontdialog.cpp b/src/libui_sdl/libui/windows/fontdialog.cpp deleted file mode 100644 index 603a17d..0000000 --- a/src/libui_sdl/libui/windows/fontdialog.cpp +++ /dev/null @@ -1,686 +0,0 @@ -// 14 april 2016 -#include "uipriv_windows.hpp" - -// TODOs -// - quote the Choose Font sample here for reference -// - the Choose Font sample defaults to Regular/Italic/Bold/Bold Italic in some case (no styles?); do we? find out what the case is -// - do we set initial family and style topmost as well? -// - this should probably just handle IDWriteFonts - -struct fontDialog { - HWND hwnd; - HWND familyCombobox; - HWND styleCombobox; - HWND sizeCombobox; - - struct fontDialogParams *params; - - fontCollection *fc; - - RECT sampleRect; - HWND sampleBox; - - // we store the current selections in case an invalid string is typed in (partial or nonexistent or invalid number) - // on OK, these are what are read - LRESULT curFamily; - LRESULT curStyle; - double curSize; - - // these are finding the style that's closest to the previous one (these fields) when changing a font - DWRITE_FONT_WEIGHT weight; - DWRITE_FONT_STYLE style; - DWRITE_FONT_STRETCH stretch; -}; - -static LRESULT cbAddString(HWND cb, const WCHAR *str) -{ - LRESULT lr; - - lr = SendMessageW(cb, CB_ADDSTRING, 0, (LPARAM) str); - if (lr == (LRESULT) CB_ERR || lr == (LRESULT) CB_ERRSPACE) - logLastError(L"error adding item to combobox"); - return lr; -} - -static LRESULT cbInsertString(HWND cb, const WCHAR *str, WPARAM pos) -{ - LRESULT lr; - - lr = SendMessageW(cb, CB_INSERTSTRING, pos, (LPARAM) str); - if (lr != (LRESULT) pos) - logLastError(L"error inserting item to combobox"); - return lr; -} - -static LRESULT cbGetItemData(HWND cb, WPARAM item) -{ - LRESULT data; - - data = SendMessageW(cb, CB_GETITEMDATA, item, 0); - if (data == (LRESULT) CB_ERR) - logLastError(L"error getting combobox item data for font dialog"); - return data; -} - -static void cbSetItemData(HWND cb, WPARAM item, LPARAM data) -{ - if (SendMessageW(cb, CB_SETITEMDATA, item, data) == (LRESULT) CB_ERR) - logLastError(L"error setting combobox item data"); -} - -static BOOL cbGetCurSel(HWND cb, LRESULT *sel) -{ - LRESULT n; - - n = SendMessageW(cb, CB_GETCURSEL, 0, 0); - if (n == (LRESULT) CB_ERR) - return FALSE; - if (sel != NULL) - *sel = n; - return TRUE; -} - -static void cbSetCurSel(HWND cb, WPARAM item) -{ - if (SendMessageW(cb, CB_SETCURSEL, item, 0) != (LRESULT) item) - logLastError(L"error selecting combobox item"); -} - -static LRESULT cbGetCount(HWND cb) -{ - LRESULT n; - - n = SendMessageW(cb, CB_GETCOUNT, 0, 0); - if (n == (LRESULT) CB_ERR) - logLastError(L"error getting combobox item count"); - return n; -} - -static void cbWipeAndReleaseData(HWND cb) -{ - IUnknown *obj; - LRESULT i, n; - - n = cbGetCount(cb); - for (i = 0; i < n; i++) { - obj = (IUnknown *) cbGetItemData(cb, (WPARAM) i); - obj->Release(); - } - SendMessageW(cb, CB_RESETCONTENT, 0, 0); -} - -static WCHAR *cbGetItemText(HWND cb, WPARAM item) -{ - LRESULT len; - WCHAR *text; - - // note: neither message includes the terminating L'\0' - len = SendMessageW(cb, CB_GETLBTEXTLEN, item, 0); - if (len == (LRESULT) CB_ERR) - logLastError(L"error getting item text length from combobox"); - text = (WCHAR *) uiAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]"); - if (SendMessageW(cb, CB_GETLBTEXT, item, (LPARAM) text) != len) - logLastError(L"error getting item text from combobox"); - return text; -} - -static BOOL cbTypeToSelect(HWND cb, LRESULT *posOut, BOOL restoreAfter) -{ - WCHAR *text; - LRESULT pos; - DWORD selStart, selEnd; - - // start by saving the current selection as setting the item will change the selection - SendMessageW(cb, CB_GETEDITSEL, (WPARAM) (&selStart), (LPARAM) (&selEnd)); - text = windowText(cb); - pos = SendMessageW(cb, CB_FINDSTRINGEXACT, (WPARAM) (-1), (LPARAM) text); - if (pos == (LRESULT) CB_ERR) { - uiFree(text); - return FALSE; - } - cbSetCurSel(cb, (WPARAM) pos); - if (posOut != NULL) - *posOut = pos; - if (restoreAfter) - if (SendMessageW(cb, WM_SETTEXT, 0, (LPARAM) text) != (LRESULT) TRUE) - logLastError(L"error restoring old combobox text"); - uiFree(text); - // and restore the selection like above - // TODO isn't there a 32-bit version of this - if (SendMessageW(cb, CB_SETEDITSEL, 0, MAKELPARAM(selStart, selEnd)) != (LRESULT) TRUE) - logLastError(L"error restoring combobox edit selection"); - return TRUE; -} - -static void wipeStylesBox(struct fontDialog *f) -{ - cbWipeAndReleaseData(f->styleCombobox); -} - -static WCHAR *fontStyleName(struct fontCollection *fc, IDWriteFont *font) -{ - IDWriteLocalizedStrings *str; - WCHAR *wstr; - HRESULT hr; - - hr = font->GetFaceNames(&str); - if (hr != S_OK) - logHRESULT(L"error getting font style name for font dialog", hr); - wstr = fontCollectionCorrectString(fc, str); - str->Release(); - return wstr; -} - -static void queueRedrawSampleText(struct fontDialog *f) -{ - // TODO TRUE? - invalidateRect(f->sampleBox, NULL, TRUE); -} - -static void styleChanged(struct fontDialog *f) -{ - LRESULT pos; - BOOL selected; - IDWriteFont *font; - - selected = cbGetCurSel(f->styleCombobox, &pos); - if (!selected) // on deselect, do nothing - return; - f->curStyle = pos; - - font = (IDWriteFont *) cbGetItemData(f->styleCombobox, (WPARAM) (f->curStyle)); - // these are for the nearest match when changing the family; see below - f->weight = font->GetWeight(); - f->style = font->GetStyle(); - f->stretch = font->GetStretch(); - - queueRedrawSampleText(f); -} - -static void styleEdited(struct fontDialog *f) -{ - if (cbTypeToSelect(f->styleCombobox, &(f->curStyle), FALSE)) - styleChanged(f); -} - -static void familyChanged(struct fontDialog *f) -{ - LRESULT pos; - BOOL selected; - IDWriteFontFamily *family; - IDWriteFont *font, *matchFont; - DWRITE_FONT_WEIGHT weight; - DWRITE_FONT_STYLE style; - DWRITE_FONT_STRETCH stretch; - UINT32 i, n; - UINT32 matching; - WCHAR *label; - HRESULT hr; - - selected = cbGetCurSel(f->familyCombobox, &pos); - if (!selected) // on deselect, do nothing - return; - f->curFamily = pos; - - family = (IDWriteFontFamily *) cbGetItemData(f->familyCombobox, (WPARAM) (f->curFamily)); - - // for the nearest style match - // when we select a new family, we want the nearest style to the previously selected one to be chosen - // this is how the Choose Font sample does it - hr = family->GetFirstMatchingFont( - f->weight, - f->stretch, - f->style, - &matchFont); - if (hr != S_OK) - logHRESULT(L"error finding first matching font to previous style in font dialog", hr); - // we can't just compare pointers; a "newly created" object comes out - // the Choose Font sample appears to do this instead - weight = matchFont->GetWeight(); - style = matchFont->GetStyle(); - stretch = matchFont->GetStretch(); - matchFont->Release(); - - // TODO test mutliple streteches; all the fonts I have have only one stretch value? - wipeStylesBox(f); - n = family->GetFontCount(); - matching = 0; // a safe/suitable default just in case - for (i = 0; i < n; i++) { - hr = family->GetFont(i, &font); - if (hr != S_OK) - logHRESULT(L"error getting font for filling styles box", hr); - label = fontStyleName(f->fc, font); - pos = cbAddString(f->styleCombobox, label); - uiFree(label); - cbSetItemData(f->styleCombobox, (WPARAM) pos, (LPARAM) font); - if (font->GetWeight() == weight && - font->GetStyle() == style && - font->GetStretch() == stretch) - matching = i; - } - - // and now, load the match - cbSetCurSel(f->styleCombobox, (WPARAM) matching); - styleChanged(f); -} - -// TODO search language variants like the sample does -static void familyEdited(struct fontDialog *f) -{ - if (cbTypeToSelect(f->familyCombobox, &(f->curFamily), FALSE)) - familyChanged(f); -} - -static const struct { - const WCHAR *text; - double value; -} defaultSizes[] = { - { L"8", 8 }, - { L"9", 9 }, - { L"10", 10 }, - { L"11", 11 }, - { L"12", 12 }, - { L"14", 14 }, - { L"16", 16 }, - { L"18", 18 }, - { L"20", 20 }, - { L"22", 22 }, - { L"24", 24 }, - { L"26", 26 }, - { L"28", 28 }, - { L"36", 36 }, - { L"48", 48 }, - { L"72", 72 }, - { NULL, 0 }, -}; - -static void sizeChanged(struct fontDialog *f) -{ - LRESULT pos; - BOOL selected; - - selected = cbGetCurSel(f->sizeCombobox, &pos); - if (!selected) // on deselect, do nothing - return; - f->curSize = defaultSizes[pos].value; - queueRedrawSampleText(f); -} - -static void sizeEdited(struct fontDialog *f) -{ - WCHAR *wsize; - double size; - - // handle type-to-selection - if (cbTypeToSelect(f->sizeCombobox, NULL, FALSE)) { - sizeChanged(f); - return; - } - // selection not chosen, try to parse the typing - wsize = windowText(f->sizeCombobox); - // this is what the Choose Font dialog does; it swallows errors while the real ChooseFont() is not lenient (and only checks on OK) - size = wcstod(wsize, NULL); - if (size <= 0) // don't change on invalid size - return; - f->curSize = size; - queueRedrawSampleText(f); -} - -static void fontDialogDrawSampleText(struct fontDialog *f, ID2D1RenderTarget *rt) -{ - D2D1_COLOR_F color; - D2D1_BRUSH_PROPERTIES props; - ID2D1SolidColorBrush *black; - IDWriteFont *font; - IDWriteLocalizedStrings *sampleStrings; - BOOL exists; - WCHAR *sample; - WCHAR *family; - IDWriteTextFormat *format; - D2D1_RECT_F rect; - HRESULT hr; - - color.r = 0.0; - color.g = 0.0; - color.b = 0.0; - color.a = 1.0; - ZeroMemory(&props, sizeof (D2D1_BRUSH_PROPERTIES)); - props.opacity = 1.0; - // identity matrix - props.transform._11 = 1; - props.transform._22 = 1; - hr = rt->CreateSolidColorBrush( - &color, - &props, - &black); - if (hr != S_OK) - logHRESULT(L"error creating solid brush", hr); - - font = (IDWriteFont *) cbGetItemData(f->styleCombobox, (WPARAM) f->curStyle); - hr = font->GetInformationalStrings(DWRITE_INFORMATIONAL_STRING_SAMPLE_TEXT, &sampleStrings, &exists); - if (hr != S_OK) - exists = FALSE; - if (exists) { - sample = fontCollectionCorrectString(f->fc, sampleStrings); - sampleStrings->Release(); - } else - sample = L"The quick brown fox jumps over the lazy dog."; - - // DirectWrite doesn't allow creating a text format from a font; we need to get this ourselves - family = cbGetItemText(f->familyCombobox, f->curFamily); - hr = dwfactory->CreateTextFormat(family, - NULL, - font->GetWeight(), - font->GetStyle(), - font->GetStretch(), - // typographic points are 1/72 inch; this parameter is 1/96 inch - // fortunately Microsoft does this too, in https://msdn.microsoft.com/en-us/library/windows/desktop/dd371554%28v=vs.85%29.aspx - f->curSize * (96.0 / 72.0), - // see http://stackoverflow.com/questions/28397971/idwritefactorycreatetextformat-failing and https://msdn.microsoft.com/en-us/library/windows/desktop/dd368203.aspx - // TODO use the current locale again? - L"", - &format); - if (hr != S_OK) - logHRESULT(L"error creating IDWriteTextFormat", hr); - uiFree(family); - - rect.left = 0; - rect.top = 0; - rect.right = realGetSize(rt).width; - rect.bottom = realGetSize(rt).height; - rt->DrawText(sample, wcslen(sample), - format, - &rect, - black, - // TODO really? - D2D1_DRAW_TEXT_OPTIONS_NONE, - DWRITE_MEASURING_MODE_NATURAL); - - format->Release(); - if (exists) - uiFree(sample); - black->Release(); -} - -static LRESULT CALLBACK fontDialogSampleSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) -{ - ID2D1RenderTarget *rt; - struct fontDialog *f; - - switch (uMsg) { - case msgD2DScratchPaint: - rt = (ID2D1RenderTarget *) lParam; - f = (struct fontDialog *) dwRefData; - fontDialogDrawSampleText(f, rt); - return 0; - case WM_NCDESTROY: - if (RemoveWindowSubclass(hwnd, fontDialogSampleSubProc, uIdSubclass) == FALSE) - logLastError(L"error removing font dialog sample text subclass"); - break; - } - return DefSubclassProc(hwnd, uMsg, wParam, lParam); -} - -static void setupInitialFontDialogState(struct fontDialog *f) -{ - WCHAR wsize[512]; // this should be way more than enough - LRESULT pos; - - // first let's load the size - // the real font dialog: - // - if the chosen font size is in the list, it selects that item AND makes it topmost - // - if the chosen font size is not in the list, don't bother - // we'll simulate it by setting the text to a %f representation, then pretending as if it was entered - // TODO is 512 the correct number to pass to _snwprintf()? - // TODO will this revert to scientific notation? - _snwprintf(wsize, 512, L"%g", f->params->size); - // TODO make this a setWindowText() - if (SendMessageW(f->sizeCombobox, WM_SETTEXT, 0, (LPARAM) wsize) != (LRESULT) TRUE) - logLastError(L"error setting size combobox to initial font size"); - sizeEdited(f); - if (cbGetCurSel(f->sizeCombobox, &pos)) - if (SendMessageW(f->sizeCombobox, CB_SETTOPINDEX, (WPARAM) pos, 0) != 0) - logLastError(L"error making chosen size topmost in the size combobox"); - - // now we set the family and style - // we do this by first setting the previous style attributes, then simulating a font entered - f->weight = f->params->font->GetWeight(); - f->style = f->params->font->GetStyle(); - f->stretch = f->params->font->GetStretch(); - if (SendMessageW(f->familyCombobox, WM_SETTEXT, 0, (LPARAM) (f->params->familyName)) != (LRESULT) TRUE) - logLastError(L"error setting family combobox to initial font family"); - familyEdited(f); -} - -static struct fontDialog *beginFontDialog(HWND hwnd, LPARAM lParam) -{ - struct fontDialog *f; - UINT32 i, nFamilies; - IDWriteFontFamily *family; - WCHAR *wname; - LRESULT pos; - HWND samplePlacement; - HRESULT hr; - - f = uiNew(struct fontDialog); - f->hwnd = hwnd; - f->params = (struct fontDialogParams *) lParam; - - f->familyCombobox = getDlgItem(f->hwnd, rcFontFamilyCombobox); - f->styleCombobox = getDlgItem(f->hwnd, rcFontStyleCombobox); - f->sizeCombobox = getDlgItem(f->hwnd, rcFontSizeCombobox); - - f->fc = loadFontCollection(); - nFamilies = f->fc->fonts->GetFontFamilyCount(); - for (i = 0; i < nFamilies; i++) { - hr = f->fc->fonts->GetFontFamily(i, &family); - if (hr != S_OK) - logHRESULT(L"error getting font family", hr); - wname = fontCollectionFamilyName(f->fc, family); - pos = cbAddString(f->familyCombobox, wname); - uiFree(wname); - cbSetItemData(f->familyCombobox, (WPARAM) pos, (LPARAM) family); - } - - for (i = 0; defaultSizes[i].text != NULL; i++) - cbInsertString(f->sizeCombobox, defaultSizes[i].text, (WPARAM) i); - - samplePlacement = getDlgItem(f->hwnd, rcFontSamplePlacement); - uiWindowsEnsureGetWindowRect(samplePlacement, &(f->sampleRect)); - mapWindowRect(NULL, f->hwnd, &(f->sampleRect)); - uiWindowsEnsureDestroyWindow(samplePlacement); - f->sampleBox = newD2DScratch(f->hwnd, &(f->sampleRect), (HMENU) rcFontSamplePlacement, fontDialogSampleSubProc, (DWORD_PTR) f); - - setupInitialFontDialogState(f); - return f; -} - -static void endFontDialog(struct fontDialog *f, INT_PTR code) -{ - wipeStylesBox(f); - cbWipeAndReleaseData(f->familyCombobox); - fontCollectionFree(f->fc); - if (EndDialog(f->hwnd, code) == 0) - logLastError(L"error ending font dialog"); - uiFree(f); -} - -static INT_PTR tryFinishDialog(struct fontDialog *f, WPARAM wParam) -{ - IDWriteFontFamily *family; - - // cancelling - if (LOWORD(wParam) != IDOK) { - endFontDialog(f, 1); - return TRUE; - } - - // OK - destroyFontDialogParams(f->params); - f->params->font = (IDWriteFont *) cbGetItemData(f->styleCombobox, f->curStyle); - // we need to save font from being destroyed with the combobox - f->params->font->AddRef(); - f->params->size = f->curSize; - family = (IDWriteFontFamily *) cbGetItemData(f->familyCombobox, f->curFamily); - f->params->familyName = fontCollectionFamilyName(f->fc, family); - f->params->styleName = fontStyleName(f->fc, f->params->font); - endFontDialog(f, 2); - return TRUE; -} - -static INT_PTR CALLBACK fontDialogDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - struct fontDialog *f; - - f = (struct fontDialog *) GetWindowLongPtrW(hwnd, DWLP_USER); - if (f == NULL) { - if (uMsg == WM_INITDIALOG) { - f = beginFontDialog(hwnd, lParam); - SetWindowLongPtrW(hwnd, DWLP_USER, (LONG_PTR) f); - return TRUE; - } - return FALSE; - } - - switch (uMsg) { - case WM_COMMAND: - SetWindowLongPtrW(f->hwnd, DWLP_MSGRESULT, 0); // just in case - switch (LOWORD(wParam)) { - case IDOK: - case IDCANCEL: - if (HIWORD(wParam) != BN_CLICKED) - return FALSE; - return tryFinishDialog(f, wParam); - case rcFontFamilyCombobox: - if (HIWORD(wParam) == CBN_SELCHANGE) { - familyChanged(f); - return TRUE; - } - if (HIWORD(wParam) == CBN_EDITCHANGE) { - familyEdited(f); - return TRUE; - } - return FALSE; - case rcFontStyleCombobox: - if (HIWORD(wParam) == CBN_SELCHANGE) { - styleChanged(f); - return TRUE; - } - if (HIWORD(wParam) == CBN_EDITCHANGE) { - styleEdited(f); - return TRUE; - } - return FALSE; - case rcFontSizeCombobox: - if (HIWORD(wParam) == CBN_SELCHANGE) { - sizeChanged(f); - return TRUE; - } - if (HIWORD(wParam) == CBN_EDITCHANGE) { - sizeEdited(f); - return TRUE; - } - return FALSE; - } - return FALSE; - } - return FALSE; -} - -BOOL showFontDialog(HWND parent, struct fontDialogParams *params) -{ - switch (DialogBoxParamW(hInstance, MAKEINTRESOURCE(rcFontDialog), parent, fontDialogDlgProc, (LPARAM) params)) { - case 1: // cancel - return FALSE; - case 2: // ok - // make the compiler happy by putting the return after the switch - break; - default: - logLastError(L"error running font dialog"); - } - return TRUE; -} - -static IDWriteFontFamily *tryFindFamily(IDWriteFontCollection *fc, const WCHAR *name) -{ - UINT32 index; - BOOL exists; - IDWriteFontFamily *family; - HRESULT hr; - - hr = fc->FindFamilyName(name, &index, &exists); - if (hr != S_OK) - logHRESULT(L"error finding font family for font dialog", hr); - if (!exists) - return NULL; - hr = fc->GetFontFamily(index, &family); - if (hr != S_OK) - logHRESULT(L"error extracting found font family for font dialog", hr); - return family; -} - -void loadInitialFontDialogParams(struct fontDialogParams *params) -{ - struct fontCollection *fc; - IDWriteFontFamily *family; - IDWriteFont *font; - HRESULT hr; - - // Our preferred font is Arial 10 Regular. - // 10 comes from the official font dialog. - // Arial Regular is a reasonable, if arbitrary, default; it's similar to the defaults on other systems. - // If Arial isn't found, we'll use Helvetica and then MS Sans Serif as fallbacks, and if not, we'll just grab the first font family in the collection. - - // We need the correct localized name for Regular (and possibly Arial too? let's say yes to be safe), so let's grab the strings from DirectWrite instead of hardcoding them. - fc = loadFontCollection(); - family = tryFindFamily(fc->fonts, L"Arial"); - if (family == NULL) { - family = tryFindFamily(fc->fonts, L"Helvetica"); - if (family == NULL) { - family = tryFindFamily(fc->fonts, L"MS Sans Serif"); - if (family == NULL) { - hr = fc->fonts->GetFontFamily(0, &family); - if (hr != S_OK) - logHRESULT(L"error getting first font out of font collection (worst case scenario)", hr); - } - } - } - - // next part is simple: just get the closest match to regular - hr = family->GetFirstMatchingFont( - DWRITE_FONT_WEIGHT_NORMAL, - DWRITE_FONT_STRETCH_NORMAL, - DWRITE_FONT_STYLE_NORMAL, - &font); - if (hr != S_OK) - logHRESULT(L"error getting Regular font from Arial", hr); - - params->font = font; - params->size = 10; - params->familyName = fontCollectionFamilyName(fc, family); - params->styleName = fontStyleName(fc, font); - - // don't release font; we still need it - family->Release(); - fontCollectionFree(fc); -} - -void destroyFontDialogParams(struct fontDialogParams *params) -{ - params->font->Release(); - uiFree(params->familyName); - uiFree(params->styleName); -} - -WCHAR *fontDialogParamsToString(struct fontDialogParams *params) -{ - WCHAR *text; - - // TODO dynamically allocate - text = (WCHAR *) uiAlloc(512 * sizeof (WCHAR), "WCHAR[]"); - _snwprintf(text, 512, L"%s %s %g", - params->familyName, - params->styleName, - params->size); - return text; -} diff --git a/src/libui_sdl/libui/windows/form.cpp b/src/libui_sdl/libui/windows/form.cpp deleted file mode 100644 index 65ef539..0000000 --- a/src/libui_sdl/libui/windows/form.cpp +++ /dev/null @@ -1,326 +0,0 @@ -// 8 june 2016 -#include "uipriv_windows.hpp" - -struct formChild { - uiControl *c; - HWND label; - int stretchy; - int height; -}; - -struct uiForm { - uiWindowsControl c; - HWND hwnd; - std::vector *controls; - int padded; -}; - -static void formPadding(uiForm *f, int *xpadding, int *ypadding) -{ - uiWindowsSizing sizing; - - *xpadding = 0; - *ypadding = 0; - if (f->padded) { - uiWindowsGetSizing(f->hwnd, &sizing); - uiWindowsSizingStandardPadding(&sizing, xpadding, ypadding); - } -} - -// via http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing -#define labelHeight 8 -#define labelYOffset 3 - -static void formRelayout(uiForm *f) -{ - RECT r; - int x, y, width, height; - int xpadding, ypadding; - int nStretchy; - int labelwid, stretchyht; - int thiswid; - int i; - int minimumWidth, minimumHeight; - uiWindowsSizing sizing; - int labelht, labelyoff; - int nVisible; - - if (f->controls->size() == 0) - return; - - uiWindowsEnsureGetClientRect(f->hwnd, &r); - x = r.left; - y = r.top; - width = r.right - r.left; - height = r.bottom - r.top; - - // 0) get this Form's padding - formPadding(f, &xpadding, &ypadding); - - // 1) get width of labels and height of non-stretchy controls - // this will tell us how much space will be left for controls - labelwid = 0; - stretchyht = height; - nStretchy = 0; - nVisible = 0; - for (struct formChild &fc : *(f->controls)) { - if (!uiControlVisible(fc.c)) { - ShowWindow(fc.label, SW_HIDE); - continue; - } - ShowWindow(fc.label, SW_SHOW); - nVisible++; - thiswid = uiWindowsWindowTextWidth(fc.label); - if (labelwid < thiswid) - labelwid = thiswid; - if (fc.stretchy) { - nStretchy++; - continue; - } - uiWindowsControlMinimumSize(uiWindowsControl(fc.c), &minimumWidth, &minimumHeight); - fc.height = minimumHeight; - stretchyht -= minimumHeight; - } - if (nVisible == 0) // nothing to do - return; - - // 2) inset the available rect by the needed padding - width -= xpadding; - height -= (nVisible - 1) * ypadding; - stretchyht -= (nVisible - 1) * ypadding; - - // 3) now get the width of controls and the height of stretchy controls - width -= labelwid; - if (nStretchy != 0) { - stretchyht /= nStretchy; - for (struct formChild &fc : *(f->controls)) { - if (!uiControlVisible(fc.c)) - continue; - if (fc.stretchy) - fc.height = stretchyht; - } - } - - // 4) get the y offset - labelyoff = labelYOffset; - uiWindowsGetSizing(f->hwnd, &sizing); - uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, &labelyoff); - - // 5) now we can position controls - // first, make relative to the top-left corner of the container - // also prefer left alignment on Windows - x = labelwid + xpadding; - y = 0; - for (const struct formChild &fc : *(f->controls)) { - if (!uiControlVisible(fc.c)) - continue; - labelht = labelHeight; - uiWindowsGetSizing(f->hwnd, &sizing); - uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, &labelht); - uiWindowsEnsureMoveWindowDuringResize(fc.label, 0, y + labelyoff - sizing.InternalLeading, labelwid, labelht); - uiWindowsEnsureMoveWindowDuringResize((HWND) uiControlHandle(fc.c), x, y, width, fc.height); - y += fc.height + ypadding; - } -} - -static void uiFormDestroy(uiControl *c) -{ - uiForm *f = uiForm(c); - - for (const struct formChild &fc : *(f->controls)) { - uiControlSetParent(fc.c, NULL); - uiControlDestroy(fc.c); - uiWindowsEnsureDestroyWindow(fc.label); - } - delete f->controls; - uiWindowsEnsureDestroyWindow(f->hwnd); - uiFreeControl(uiControl(f)); -} - -uiWindowsControlDefaultHandle(uiForm) -uiWindowsControlDefaultParent(uiForm) -uiWindowsControlDefaultSetParent(uiForm) -uiWindowsControlDefaultToplevel(uiForm) -uiWindowsControlDefaultVisible(uiForm) -uiWindowsControlDefaultShow(uiForm) -uiWindowsControlDefaultHide(uiForm) -uiWindowsControlDefaultEnabled(uiForm) -uiWindowsControlDefaultEnable(uiForm) -uiWindowsControlDefaultDisable(uiForm) -uiWindowsControlDefaultSetFocus(uiForm) - -static void uiFormSyncEnableState(uiWindowsControl *c, int enabled) -{ - uiForm *f = uiForm(c); - - if (uiWindowsShouldStopSyncEnableState(uiWindowsControl(f), enabled)) - return; - for (const struct formChild &fc : *(f->controls)) - uiWindowsControlSyncEnableState(uiWindowsControl(fc.c), enabled); -} - -uiWindowsControlDefaultSetParentHWND(uiForm) - -static void uiFormMinimumSize(uiWindowsControl *c, int *width, int *height) -{ - uiForm *f = uiForm(c); - int xpadding, ypadding; - int nStretchy; - // these two contain the largest minimum width and height of all stretchy controls in the form - // all stretchy controls will use this value to determine the final minimum size - int maxLabelWidth, maxControlWidth; - int maxStretchyHeight; - int labelwid; - int i; - int minimumWidth, minimumHeight; - int nVisible; - uiWindowsSizing sizing; - - *width = 0; - *height = 0; - if (f->controls->size() == 0) - return; - - // 0) get this Form's padding - formPadding(f, &xpadding, &ypadding); - - // 1) determine the longest width of all controls and labels; add in the height of non-stretchy controls and get (but not add in) the largest heights of stretchy controls - // we still add in like direction of stretchy controls - nStretchy = 0; - maxLabelWidth = 0; - maxControlWidth = 0; - maxStretchyHeight = 0; - nVisible = 0; - for (const struct formChild &fc : *(f->controls)) { - if (!uiControlVisible(fc.c)) - continue; - nVisible++; - labelwid = uiWindowsWindowTextWidth(fc.label); - if (maxLabelWidth < labelwid) - maxLabelWidth = labelwid; - uiWindowsControlMinimumSize(uiWindowsControl(fc.c), &minimumWidth, &minimumHeight); - if (fc.stretchy) { - nStretchy++; - if (maxStretchyHeight < minimumHeight) - maxStretchyHeight = minimumHeight; - } - if (maxControlWidth < minimumWidth) - maxControlWidth = minimumWidth; - if (!fc.stretchy) - *height += minimumHeight; - } - if (nVisible == 0) // nothing to show; return 0x0 - return; - *width += maxLabelWidth + maxControlWidth; - - // 2) outset the desired rect with the needed padding - *width += xpadding; - *height += (nVisible - 1) * ypadding; - - // 3) and now we can add in stretchy controls - *height += nStretchy * maxStretchyHeight; -} - -static void uiFormMinimumSizeChanged(uiWindowsControl *c) -{ - uiForm *f = uiForm(c); - - if (uiWindowsControlTooSmall(uiWindowsControl(f))) { - uiWindowsControlContinueMinimumSizeChanged(uiWindowsControl(f)); - return; - } - formRelayout(f); -} - -static void uiFormSetMinSize(uiControl *c, int w, int h) -{ - // checkme - uiFormMinimumSizeChanged(uiWindowsControl(c)); -} - -uiWindowsControlDefaultLayoutRect(uiForm) -uiWindowsControlDefaultAssignControlIDZOrder(uiForm) - -static void uiFormChildVisibilityChanged(uiWindowsControl *c) -{ - // TODO eliminate the redundancy - uiWindowsControlMinimumSizeChanged(c); -} - -static void formArrangeChildren(uiForm *f) -{ - LONG_PTR controlID; - HWND insertAfter; - int i; - - controlID = 100; - insertAfter = NULL; - for (const struct formChild &fc : *(f->controls)) { - // TODO assign label ID and z-order - uiWindowsControlAssignControlIDZOrder(uiWindowsControl(fc.c), &controlID, &insertAfter); - } -} - -void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy) -{ - struct formChild fc; - WCHAR *wlabel; - - fc.c = c; - wlabel = toUTF16(label); - fc.label = uiWindowsEnsureCreateControlHWND(0, - L"STATIC", wlabel, - SS_LEFT | SS_NOPREFIX, - hInstance, NULL, - TRUE); - uiFree(wlabel); - uiWindowsEnsureSetParentHWND(fc.label, f->hwnd); - fc.stretchy = stretchy; - uiControlSetParent(fc.c, uiControl(f)); - uiWindowsControlSetParentHWND(uiWindowsControl(fc.c), f->hwnd); - f->controls->push_back(fc); - formArrangeChildren(f); - uiWindowsControlMinimumSizeChanged(uiWindowsControl(f)); -} - -void uiFormDelete(uiForm *f, int index) -{ - struct formChild fc; - - fc = (*(f->controls))[index]; - uiControlSetParent(fc.c, NULL); - uiWindowsControlSetParentHWND(uiWindowsControl(fc.c), NULL); - uiWindowsEnsureDestroyWindow(fc.label); - f->controls->erase(f->controls->begin() + index); - formArrangeChildren(f); - uiWindowsControlMinimumSizeChanged(uiWindowsControl(f)); -} - -int uiFormPadded(uiForm *f) -{ - return f->padded; -} - -void uiFormSetPadded(uiForm *f, int padded) -{ - f->padded = padded; - uiWindowsControlMinimumSizeChanged(uiWindowsControl(f)); -} - -static void onResize(uiWindowsControl *c) -{ - formRelayout(uiForm(c)); -} - -uiForm *uiNewForm(void) -{ - uiForm *f; - - uiWindowsNewControl(uiForm, f); - - f->hwnd = uiWindowsMakeContainer(uiWindowsControl(f), onResize); - - f->controls = new std::vector; - - return f; -} diff --git a/src/libui_sdl/libui/windows/gl.cpp b/src/libui_sdl/libui/windows/gl.cpp deleted file mode 100644 index 07ef19b..0000000 --- a/src/libui_sdl/libui/windows/gl.cpp +++ /dev/null @@ -1,196 +0,0 @@ -// 31 march 2019 -#include "uipriv_windows.hpp" -#include "area.hpp" - -#include -#include -#include - -struct uiGLContext -{ - uiArea* a; - - HWND hwnd; - HDC dc; - HGLRC rc; - - unsigned int version; -}; - - -uiGLContext* createGLContext(uiArea* a, int vermajor, int verminor) -{ - uiGLContext* ctx; - BOOL res; - - ctx = uiNew(uiGLContext); - - ctx->a = a; - ctx->hwnd = a->hwnd; - - PIXELFORMATDESCRIPTOR pfd; - memset(&pfd, 0, sizeof(pfd)); - pfd.nSize = sizeof(pfd); - pfd.nVersion = 1; - pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; - pfd.iPixelType = PFD_TYPE_RGBA; - pfd.cColorBits = 24; - pfd.cAlphaBits = 8; - pfd.cDepthBits = 24; - pfd.cStencilBits = 8; - pfd.iLayerType = PFD_MAIN_PLANE; - - ctx->dc = GetDC(ctx->hwnd); - if (!ctx->dc) - { - uiFree(ctx); - return NULL; - } - - int pixelformat = ChoosePixelFormat(ctx->dc, &pfd); - res = SetPixelFormat(ctx->dc, pixelformat, &pfd); - if (!res) - { - ReleaseDC(ctx->hwnd, ctx->dc); - uiFree(ctx); - return NULL; - } - - ctx->rc = wglCreateContext(ctx->dc); - if (!ctx->rc) - { - ReleaseDC(ctx->hwnd, ctx->dc); - uiFree(ctx); - return NULL; - } - - wglMakeCurrent(ctx->dc, ctx->rc); - - if (vermajor >= 3) - { - HGLRC (*wglCreateContextAttribsARB)(HDC,HGLRC,const int*); - HGLRC rc_better = NULL; - - wglCreateContextAttribsARB = (HGLRC(*)(HDC,HGLRC,const int*))wglGetProcAddress("wglCreateContextAttribsARB"); - if (wglCreateContextAttribsARB) - { - int attribs[15]; - int i = 0; - - attribs[i++] = WGL_CONTEXT_MAJOR_VERSION_ARB; - attribs[i++] = vermajor; - attribs[i++] = WGL_CONTEXT_MINOR_VERSION_ARB; - attribs[i++] = verminor; - - attribs[i] = 0; - rc_better = wglCreateContextAttribsARB(ctx->dc, NULL, attribs); - } - - wglMakeCurrent(NULL, NULL); - wglDeleteContext(ctx->rc); - - if (!rc_better) - { - ReleaseDC(ctx->hwnd, ctx->dc); - uiFree(ctx); - return NULL; - } - - ctx->version = uiGLVersion(vermajor, verminor); - ctx->rc = rc_better; - wglMakeCurrent(ctx->dc, ctx->rc); - } - - return ctx; -} - -void freeGLContext(uiGLContext* ctx) -{ - if (ctx == NULL) return; - wglMakeCurrent(NULL, NULL); - wglDeleteContext(ctx->rc); - ReleaseDC(ctx->hwnd, ctx->dc); - uiFree(ctx); -} - -void uiGLMakeContextCurrent(uiGLContext* ctx) -{ - if (ctx == NULL) - { - wglMakeCurrent(NULL, NULL); - return; - } - - if (wglGetCurrentContext() == ctx->rc) return; - int res = wglMakeCurrent(ctx->dc, ctx->rc); -} - -unsigned int uiGLGetVersion(uiGLContext* ctx) -{ - if (ctx == NULL) return 0; - return ctx->version; -} - -void *uiGLGetProcAddress(const char* proc) -{ - return (void*)wglGetProcAddress(proc); -} - -void uiGLBegin(uiGLContext* ctx) -{ -} - -void uiGLEnd(uiGLContext* ctx) -{ -} - -void uiGLSwapBuffers(uiGLContext* ctx) -{ - if (ctx == NULL) return; - SwapBuffers(ctx->dc); -} - -int uiGLGetFramebuffer(uiGLContext* ctx) -{ - return 0; -} - -float uiGLGetFramebufferScale(uiGLContext* ctx) -{ - // TODO - return 1; -} - -void uiGLSetVSync(int sync) -{ - static PFNWGLSWAPINTERVALEXTPROC _wglSwapIntervalEXT = NULL; - static bool symloaded = false; - - if (!symloaded) - { - PFNGLGETSTRINGIPROC _glGetStringi = (PFNGLGETSTRINGIPROC)wglGetProcAddress("glGetStringi"); - if (_glGetStringi == NULL) return; - - GLint numext; - glGetIntegerv(GL_NUM_EXTENSIONS, &numext); - - bool hasswapctrl = false; - for (GLint i = 0; i < numext; i++) - { - const char* ext = (const char*)_glGetStringi(GL_EXTENSIONS, i); - if (!stricmp(ext, "WGL_EXT_swap_control")) - { - hasswapctrl = true; - break; - } - } - - if (hasswapctrl) - _wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT"); - - symloaded = true; - } - - if (_wglSwapIntervalEXT) - _wglSwapIntervalEXT(sync); -} diff --git a/src/libui_sdl/libui/windows/graphemes.cpp b/src/libui_sdl/libui/windows/graphemes.cpp deleted file mode 100644 index 355e403..0000000 --- a/src/libui_sdl/libui/windows/graphemes.cpp +++ /dev/null @@ -1,80 +0,0 @@ -// 25 may 2016 -#include "uipriv_windows.hpp" - -// We could use CharNext() to generate grapheme cluster boundaries, but it doesn't handle surrogate pairs properly (see http://archives.miloush.net/michkap/archive/2008/12/16/9223301.html). -// So let's use Uniscribe (see http://archives.miloush.net/michkap/archive/2005/01/14/352802.html) -// See also http://www.catch22.net/tuts/uniscribe-mysteries and http://www.catch22.net/tuts/keyboard-navigation for more details. - -static HRESULT itemize(WCHAR *msg, size_t len, SCRIPT_ITEM **out, int *outn) -{ - SCRIPT_CONTROL sc; - SCRIPT_STATE ss; - SCRIPT_ITEM *items; - size_t maxItems; - int n; - HRESULT hr; - - // make sure these are zero-initialized to avoid mangling the text - ZeroMemory(&sc, sizeof (SCRIPT_CONTROL)); - ZeroMemory(&ss, sizeof (SCRIPT_STATE)); - - maxItems = len + 2; - for (;;) { - items = new SCRIPT_ITEM[maxItems]; - hr = ScriptItemize(msg, len, - maxItems, - &sc, &ss, - items, &n); - if (hr == S_OK) - break; - // otherwise either an error or not enough room - delete[] items; - if (hr != E_OUTOFMEMORY) - return hr; - maxItems *= 2; // add some more and try again - } - - *out = items; - *outn = n; - return S_OK; -} - -size_t *graphemes(WCHAR *msg) -{ - size_t len; - SCRIPT_ITEM *items; - int i, n; - size_t *out; - size_t *op; - SCRIPT_LOGATTR *logattr; - int j, nn; - HRESULT hr; - - len = wcslen(msg); - hr = itemize(msg, len, &items, &n); - if (hr != S_OK) - logHRESULT(L"error itemizing string for finding grapheme cluster boundaries", hr); - - // should be enough; 2 more just to be safe - out = (size_t *) uiAlloc((len + 2) * sizeof (size_t), "size_t[]"); - op = out; - - // note that there are actually n + 1 elements in items - for (i = 0; i < n; i++) { - nn = items[i + 1].iCharPos - items[i].iCharPos; - logattr = new SCRIPT_LOGATTR[nn]; - hr = ScriptBreak(msg + items[i].iCharPos, nn, - &(items[i].a), logattr); - if (hr != S_OK) - logHRESULT(L"error breaking string for finding grapheme cluster boundaries", hr); - for (j = 0; j < nn; j++) - if (logattr[j].fCharStop != 0) - *op++ = items[i].iCharPos + j; - delete[] logattr; - } - // and handle the last item for the end of the string - *op++ = items[i].iCharPos; - - delete[] items; - return out; -} diff --git a/src/libui_sdl/libui/windows/grid.cpp b/src/libui_sdl/libui/windows/grid.cpp deleted file mode 100644 index 0a854c5..0000000 --- a/src/libui_sdl/libui/windows/grid.cpp +++ /dev/null @@ -1,665 +0,0 @@ -// 10 june 2016 -#include "uipriv_windows.hpp" - -// TODO compare with GTK+: -// - what happens if you call InsertAt() twice? -// - what happens if you call Append() twice? - -// TODOs -// - the Assorted page has clipping and repositioning issues - -struct gridChild { - uiControl *c; - int left; - int top; - int xspan; - int yspan; - int hexpand; - uiAlign halign; - int vexpand; - uiAlign valign; - - // have these here so they don't need to be reallocated each relayout - int finalx, finaly; - int finalwidth, finalheight; - int minwidth, minheight; -}; - -struct uiGrid { - uiWindowsControl c; - HWND hwnd; - std::vector *children; - std::map *indexof; - int padded; - - int xmin, ymin; - int xmax, ymax; -}; - -static bool gridRecomputeMinMax(uiGrid *g) -{ - bool first = true; - - for (struct gridChild *gc : *(g->children)) { - // this is important; we want g->xmin/g->ymin to satisfy gridLayoutData::visibleRow()/visibleColumn() - if (!uiControlVisible(gc->c)) - continue; - if (first) { - g->xmin = gc->left; - g->ymin = gc->top; - g->xmax = gc->left + gc->xspan; - g->ymax = gc->top + gc->yspan; - first = false; - continue; - } - if (g->xmin > gc->left) - g->xmin = gc->left; - if (g->ymin > gc->top) - g->ymin = gc->top; - if (g->xmax < (gc->left + gc->xspan)) - g->xmax = gc->left + gc->xspan; - if (g->ymax < (gc->top + gc->yspan)) - g->ymax = gc->top + gc->yspan; - } - return first != false; -} - -#define xcount(g) ((g)->xmax - (g)->xmin) -#define ycount(g) ((g)->ymax - (g)->ymin) -#define toxindex(g, x) ((x) - (g)->xmin) -#define toyindex(g, y) ((y) - (g)->ymin) - -class gridLayoutData { - int ycount; -public: - int **gg; // topological map gg[y][x] = control index - int *colwidths; - int *rowheights; - bool *hexpand; - bool *vexpand; - int nVisibleRows; - int nVisibleColumns; - - bool noVisible; - - gridLayoutData(uiGrid *g) - { - size_t i; - int x, y; - - this->noVisible = gridRecomputeMinMax(g); - - this->gg = new int *[ycount(g)]; - for (y = 0; y < ycount(g); y++) { - this->gg[y] = new int[xcount(g)]; - for (x = 0; x < xcount(g); x++) - this->gg[y][x] = -1; - } - - for (i = 0; i < g->children->size(); i++) { - struct gridChild *gc; - - gc = (*(g->children))[i]; - if (!uiControlVisible(gc->c)) - continue; - for (y = gc->top; y < gc->top + gc->yspan; y++) - for (x = gc->left; x < gc->left + gc->xspan; x++) - this->gg[toyindex(g, y)][toxindex(g, x)] = i; - } - - this->colwidths = new int[xcount(g)]; - ZeroMemory(this->colwidths, xcount(g) * sizeof (int)); - this->rowheights = new int[ycount(g)]; - ZeroMemory(this->rowheights, ycount(g) * sizeof (int)); - this->hexpand = new bool[xcount(g)]; - ZeroMemory(this->hexpand, xcount(g) * sizeof (bool)); - this->vexpand = new bool[ycount(g)]; - ZeroMemory(this->vexpand, ycount(g) * sizeof (bool)); - - this->ycount = ycount(g); - - // if a row or column only contains emptys and spanning cells of a opposite-direction spannings, it is invisible and should not be considered for padding amount calculations - // note that the first row and column will always be visible because gridRecomputeMinMax() computed a smallest fitting rectangle - if (this->noVisible) - return; - this->nVisibleRows = 0; - for (y = 0; y < this->ycount; y++) - if (this->visibleRow(g, y)) - this->nVisibleRows++; - this->nVisibleColumns = 0; - for (x = 0; x < xcount(g); x++) - if (this->visibleColumn(g, x)) - this->nVisibleColumns++; - } - - ~gridLayoutData() - { - size_t y; - - delete[] this->hexpand; - delete[] this->vexpand; - delete[] this->colwidths; - delete[] this->rowheights; - for (y = 0; y < this->ycount; y++) - delete[] this->gg[y]; - delete[] this->gg; - } - - bool visibleRow(uiGrid *g, int y) - { - int x; - struct gridChild *gc; - - for (x = 0; x < xcount(g); x++) - if (this->gg[y][x] != -1) { - gc = (*(g->children))[this->gg[y][x]]; - if (gc->yspan == 1 || gc->top - g->ymin == y) - return true; - } - return false; - } - - bool visibleColumn(uiGrid *g, int x) - { - int y; - struct gridChild *gc; - - for (y = 0; y < this->ycount; y++) - if (this->gg[y][x] != -1) { - gc = (*(g->children))[this->gg[y][x]]; - if (gc->xspan == 1 || gc->left - g->xmin == x) - return true; - } - return false; - } -}; - -static void gridPadding(uiGrid *g, int *xpadding, int *ypadding) -{ - uiWindowsSizing sizing; - - *xpadding = 0; - *ypadding = 0; - if (g->padded) { - uiWindowsGetSizing(g->hwnd, &sizing); - uiWindowsSizingStandardPadding(&sizing, xpadding, ypadding); - } -} - -static void gridRelayout(uiGrid *g) -{ - RECT r; - int x, y, width, height; - gridLayoutData *ld; - int xpadding, ypadding; - int ix, iy; - int iwidth, iheight; - int i; - struct gridChild *gc; - int nhexpand, nvexpand; - - if (g->children->size() == 0) - return; // nothing to do - - uiWindowsEnsureGetClientRect(g->hwnd, &r); - x = r.left; - y = r.top; - width = r.right - r.left; - height = r.bottom - r.top; - - gridPadding(g, &xpadding, &ypadding); - ld = new gridLayoutData(g); - if (ld->noVisible) { // nothing to do - delete ld; - return; - } - - // 0) discount padding from width/height - width -= (ld->nVisibleColumns - 1) * xpadding; - height -= (ld->nVisibleRows - 1) * ypadding; - - // 1) compute colwidths and rowheights before handling expansion - // we only count non-spanning controls to avoid weirdness - for (iy = 0; iy < ycount(g); iy++) - for (ix = 0; ix < xcount(g); ix++) { - i = ld->gg[iy][ix]; - if (i == -1) - continue; - gc = (*(g->children))[i]; - uiWindowsControlMinimumSize(uiWindowsControl(gc->c), &iwidth, &iheight); - if (gc->xspan == 1) - if (ld->colwidths[ix] < iwidth) - ld->colwidths[ix] = iwidth; - if (gc->yspan == 1) - if (ld->rowheights[iy] < iheight) - ld->rowheights[iy] = iheight; - // save these for step 6 - gc->minwidth = iwidth; - gc->minheight = iheight; - } - - // 2) figure out which rows/columns expand but not span - // we need to know which expanding rows/columns don't span before we can handle the ones that do - for (i = 0; i < g->children->size(); i++) { - gc = (*(g->children))[i]; - if (!uiControlVisible(gc->c)) - continue; - if (gc->hexpand && gc->xspan == 1) - ld->hexpand[toxindex(g, gc->left)] = true; - if (gc->vexpand && gc->yspan == 1) - ld->vexpand[toyindex(g, gc->top)] = true; - } - - // 3) figure out which rows/columns expand that do span - // the way we handle this is simple: if none of the spanned rows/columns expand, make all rows/columns expand - for (i = 0; i < g->children->size(); i++) { - gc = (*(g->children))[i]; - if (!uiControlVisible(gc->c)) - continue; - if (gc->hexpand && gc->xspan != 1) { - bool doit = true; - - for (ix = gc->left; ix < gc->left + gc->xspan; ix++) - if (ld->hexpand[toxindex(g, ix)]) { - doit = false; - break; - } - if (doit) - for (ix = gc->left; ix < gc->left + gc->xspan; ix++) - ld->hexpand[toxindex(g, ix)] = true; - } - if (gc->vexpand && gc->yspan != 1) { - bool doit = true; - - for (iy = gc->top; iy < gc->top + gc->yspan; iy++) - if (ld->vexpand[toyindex(g, iy)]) { - doit = false; - break; - } - if (doit) - for (iy = gc->top; iy < gc->top + gc->yspan; iy++) - ld->vexpand[toyindex(g, iy)] = true; - } - } - - // 4) compute and assign expanded widths/heights - nhexpand = 0; - nvexpand = 0; - for (i = 0; i < xcount(g); i++) - if (ld->hexpand[i]) - nhexpand++; - else - width -= ld->colwidths[i]; - for (i = 0; i < ycount(g); i++) - if (ld->vexpand[i]) - nvexpand++; - else - height -= ld->rowheights[i]; - for (i = 0; i < xcount(g); i++) - if (ld->hexpand[i]) - ld->colwidths[i] = width / nhexpand; - for (i = 0; i < ycount(g); i++) - if (ld->vexpand[i]) - ld->rowheights[i] = height / nvexpand; - - // 5) reset the final coordinates for the next step - for (i = 0; i < g->children->size(); i++) { - gc = (*(g->children))[i]; - if (!uiControlVisible(gc->c)) - continue; - gc->finalx = 0; - gc->finaly = 0; - gc->finalwidth = 0; - gc->finalheight = 0; - } - - // 6) compute cell positions and sizes - for (iy = 0; iy < ycount(g); iy++) { - int curx; - int prev; - - curx = 0; - prev = -1; - for (ix = 0; ix < xcount(g); ix++) { - if (!ld->visibleColumn(g, ix)) - continue; - i = ld->gg[iy][ix]; - if (i != -1) { - gc = (*(g->children))[i]; - if (iy == toyindex(g, gc->top)) { // don't repeat this step if the control spans vertically - if (i != prev) - gc->finalx = curx; - else - gc->finalwidth += xpadding; - gc->finalwidth += ld->colwidths[ix]; - } - } - curx += ld->colwidths[ix] + xpadding; - prev = i; - } - } - for (ix = 0; ix < xcount(g); ix++) { - int cury; - int prev; - - cury = 0; - prev = -1; - for (iy = 0; iy < ycount(g); iy++) { - if (!ld->visibleRow(g, iy)) - continue; - i = ld->gg[iy][ix]; - if (i != -1) { - gc = (*(g->children))[i]; - if (ix == toxindex(g, gc->left)) { // don't repeat this step if the control spans horizontally - if (i != prev) - gc->finaly = cury; - else - gc->finalheight += ypadding; - gc->finalheight += ld->rowheights[iy]; - } - } - cury += ld->rowheights[iy] + ypadding; - prev = i; - } - } - - // 7) everything as it stands now is set for xalign == Fill yalign == Fill; set the correct alignments - // this is why we saved minwidth/minheight above - for (i = 0; i < g->children->size(); i++) { - gc = (*(g->children))[i]; - if (!uiControlVisible(gc->c)) - continue; - if (gc->halign != uiAlignFill) { - switch (gc->halign) { - case uiAlignEnd: - gc->finalx += gc->finalwidth - gc->minwidth; - break; - case uiAlignCenter: - gc->finalx += (gc->finalwidth - gc->minwidth) / 2; - break; - } - gc->finalwidth = gc->minwidth; // for all three - } - if (gc->valign != uiAlignFill) { - switch (gc->valign) { - case uiAlignEnd: - gc->finaly += gc->finalheight - gc->minheight; - break; - case uiAlignCenter: - gc->finaly += (gc->finalheight - gc->minheight) / 2; - break; - } - gc->finalheight = gc->minheight; // for all three - } - } - - // 8) and FINALLY we resize - for (iy = 0; iy < ycount(g); iy++) - for (ix = 0; ix < xcount(g); ix++) { - i = ld->gg[iy][ix]; - if (i != -1) { // treat empty cells like spaces - gc = (*(g->children))[i]; - uiWindowsEnsureMoveWindowDuringResize( - (HWND) uiControlHandle(gc->c), - gc->finalx,//TODO + x, - gc->finaly,//TODO + y, - gc->finalwidth, - gc->finalheight); - } - } - - delete ld; -} - -static void uiGridDestroy(uiControl *c) -{ - uiGrid *g = uiGrid(c); - - for (struct gridChild *gc : *(g->children)) { - uiControlSetParent(gc->c, NULL); - uiControlDestroy(gc->c); - uiFree(gc); - } - delete g->indexof; - delete g->children; - uiWindowsEnsureDestroyWindow(g->hwnd); - uiFreeControl(uiControl(g)); -} - -uiWindowsControlDefaultHandle(uiGrid) -uiWindowsControlDefaultParent(uiGrid) -uiWindowsControlDefaultSetParent(uiGrid) -uiWindowsControlDefaultToplevel(uiGrid) -uiWindowsControlDefaultVisible(uiGrid) -uiWindowsControlDefaultShow(uiGrid) -uiWindowsControlDefaultHide(uiGrid) -uiWindowsControlDefaultEnabled(uiGrid) -uiWindowsControlDefaultEnable(uiGrid) -uiWindowsControlDefaultDisable(uiGrid) -uiWindowsControlDefaultSetFocus(uiGrid) - -static void uiGridSyncEnableState(uiWindowsControl *c, int enabled) -{ - uiGrid *g = uiGrid(c); - - if (uiWindowsShouldStopSyncEnableState(uiWindowsControl(g), enabled)) - return; - for (const struct gridChild *gc : *(g->children)) - uiWindowsControlSyncEnableState(uiWindowsControl(gc->c), enabled); -} - -uiWindowsControlDefaultSetParentHWND(uiGrid) - -static void uiGridMinimumSize(uiWindowsControl *c, int *width, int *height) -{ - uiGrid *g = uiGrid(c); - int xpadding, ypadding; - gridLayoutData *ld; - int x, y; - int i; - struct gridChild *gc; - int minwid, minht; - int colwidth, rowheight; - - *width = 0; - *height = 0; - if (g->children->size() == 0) - return; // nothing to do - - gridPadding(g, &xpadding, &ypadding); - ld = new gridLayoutData(g); - if (ld->noVisible) { // nothing to do; return 0x0 - delete ld; - return; - } - - // 1) compute colwidths and rowheights before handling expansion - // TODO put this in its own function (but careful about the spanning calculation in gridRelayout()) - for (y = 0; y < ycount(g); y++) - for (x = 0; x < xcount(g); x++) { - i = ld->gg[y][x]; - if (i == -1) - continue; - gc = (*(g->children))[i]; - uiWindowsControlMinimumSize(uiWindowsControl(gc->c), &minwid, &minht); - // allot equal space in the presence of spanning to keep things sane - if (ld->colwidths[x] < minwid / gc->xspan) - ld->colwidths[x] = minwid / gc->xspan; - if (ld->rowheights[y] < minht / gc->yspan) - ld->rowheights[y] = minht / gc->yspan; - // save these for step 6 - gc->minwidth = minwid; - gc->minheight = minht; - } - - // 2) compute total column width/row height - colwidth = 0; - rowheight = 0; - for (x = 0; x < xcount(g); x++) - colwidth += ld->colwidths[x]; - for (y = 0; y < ycount(g); y++) - rowheight += ld->rowheights[y]; - - // and that's it; just account for padding - *width = colwidth + (ld->nVisibleColumns - 1) * xpadding; - *height = rowheight + (ld->nVisibleRows - 1) * ypadding; -} - -static void uiGridMinimumSizeChanged(uiWindowsControl *c) -{ - uiGrid *g = uiGrid(c); - - if (uiWindowsControlTooSmall(uiWindowsControl(g))) { - uiWindowsControlContinueMinimumSizeChanged(uiWindowsControl(g)); - return; - } - gridRelayout(g); -} - -static void uiGridSetMinSize(uiControl *c, int w, int h) -{ - // checkme - uiGridMinimumSizeChanged(uiWindowsControl(c)); -} - -uiWindowsControlDefaultLayoutRect(uiGrid) -uiWindowsControlDefaultAssignControlIDZOrder(uiGrid) - -static void uiGridChildVisibilityChanged(uiWindowsControl *c) -{ - // TODO eliminate the redundancy - uiWindowsControlMinimumSizeChanged(c); -} - -// must have called gridRecomputeMinMax() first -static void gridArrangeChildren(uiGrid *g) -{ - LONG_PTR controlID; - HWND insertAfter; - gridLayoutData *ld; - bool *visited; - int x, y; - int i; - struct gridChild *gc; - - if (g->children->size() == 0) - return; // nothing to do - ld = new gridLayoutData(g); - controlID = 100; - insertAfter = NULL; - visited = new bool[g->children->size()]; - ZeroMemory(visited, g->children->size() * sizeof (bool)); - for (y = 0; y < ycount(g); y++) - for (x = 0; x < xcount(g); x++) { - i = ld->gg[y][x]; - if (i == -1) - continue; - if (visited[i]) - continue; - visited[i] = true; - gc = (*(g->children))[i]; - uiWindowsControlAssignControlIDZOrder(uiWindowsControl(gc->c), &controlID, &insertAfter); - } - delete[] visited; - delete ld; -} - -static struct gridChild *toChild(uiControl *c, int xspan, int yspan, int hexpand, uiAlign halign, int vexpand, uiAlign valign) -{ - struct gridChild *gc; - - if (xspan < 0) - userbug("You cannot have a negative xspan in a uiGrid cell."); - if (yspan < 0) - userbug("You cannot have a negative yspan in a uiGrid cell."); - gc = uiNew(struct gridChild); - gc->c = c; - gc->xspan = xspan; - gc->yspan = yspan; - gc->hexpand = hexpand; - gc->halign = halign; - gc->vexpand = vexpand; - gc->valign = valign; - return gc; -} - -static void add(uiGrid *g, struct gridChild *gc) -{ - uiControlSetParent(gc->c, uiControl(g)); - uiWindowsControlSetParentHWND(uiWindowsControl(gc->c), g->hwnd); - g->children->push_back(gc); - (*(g->indexof))[gc->c] = g->children->size() - 1; - gridRecomputeMinMax(g); - gridArrangeChildren(g); - uiWindowsControlMinimumSizeChanged(uiWindowsControl(g)); -} - -void uiGridAppend(uiGrid *g, uiControl *c, int left, int top, int xspan, int yspan, int hexpand, uiAlign halign, int vexpand, uiAlign valign) -{ - struct gridChild *gc; - - gc = toChild(c, xspan, yspan, hexpand, halign, vexpand, valign); - gc->left = left; - gc->top = top; - add(g, gc); -} - -// TODO decide what happens if existing is NULL -void uiGridInsertAt(uiGrid *g, uiControl *c, uiControl *existing, uiAt at, int xspan, int yspan, int hexpand, uiAlign halign, int vexpand, uiAlign valign) -{ - struct gridChild *gc; - struct gridChild *other; - - gc = toChild(c, xspan, yspan, hexpand, halign, vexpand, valign); - other = (*(g->children))[(*(g->indexof))[existing]]; - switch (at) { - case uiAtLeading: - gc->left = other->left - gc->xspan; - gc->top = other->top; - break; - case uiAtTop: - gc->left = other->left; - gc->top = other->top - gc->yspan; - break; - case uiAtTrailing: - gc->left = other->left + other->xspan; - gc->top = other->top; - break; - case uiAtBottom: - gc->left = other->left; - gc->top = other->top + other->yspan; - break; - // TODO add error checks to ALL enums - } - add(g, gc); -} - -int uiGridPadded(uiGrid *g) -{ - return g->padded; -} - -void uiGridSetPadded(uiGrid *g, int padded) -{ - g->padded = padded; - uiWindowsControlMinimumSizeChanged(uiWindowsControl(g)); -} - -static void onResize(uiWindowsControl *c) -{ - gridRelayout(uiGrid(c)); -} - -uiGrid *uiNewGrid(void) -{ - uiGrid *g; - - uiWindowsNewControl(uiGrid, g); - - g->hwnd = uiWindowsMakeContainer(uiWindowsControl(g), onResize); - - g->children = new std::vector; - g->indexof = new std::map; - - return g; -} diff --git a/src/libui_sdl/libui/windows/group.cpp b/src/libui_sdl/libui/windows/group.cpp deleted file mode 100644 index 9c36da1..0000000 --- a/src/libui_sdl/libui/windows/group.cpp +++ /dev/null @@ -1,224 +0,0 @@ -// 16 may 2015 -#include "uipriv_windows.hpp" - -struct uiGroup { - uiWindowsControl c; - HWND hwnd; - struct uiControl *child; - int margined; -}; - -// from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing -#define groupXMargin 6 -#define groupYMarginTop 11 /* note this value /includes/ the groupbox label */ -#define groupYMarginBottom 7 - -// unfortunately because the client area of a groupbox includes the frame and caption text, we have to apply some margins ourselves, even if we don't want "any" -// these were deduced by hand based on the standard DLU conversions; the X and Y top margins are the width and height, respectively, of one character cell -// they can be fine-tuned later -#define groupUnmarginedXMargin 4 -#define groupUnmarginedYMarginTop 8 -#define groupUnmarginedYMarginBottom 3 - -static void groupMargins(uiGroup *g, int *mx, int *mtop, int *mbottom) -{ - uiWindowsSizing sizing; - - *mx = groupUnmarginedXMargin; - *mtop = groupUnmarginedYMarginTop; - *mbottom = groupUnmarginedYMarginBottom; - if (g->margined) { - *mx = groupXMargin; - *mtop = groupYMarginTop; - *mbottom = groupYMarginBottom; - } - uiWindowsGetSizing(g->hwnd, &sizing); - uiWindowsSizingDlgUnitsToPixels(&sizing, mx, mtop); - uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, mbottom); -} - -static void groupRelayout(uiGroup *g) -{ - RECT r; - int mx, mtop, mbottom; - - if (g->child == NULL) - return; - uiWindowsEnsureGetClientRect(g->hwnd, &r); - groupMargins(g, &mx, &mtop, &mbottom); - r.left += mx; - r.top += mtop; - r.right -= mx; - r.bottom -= mbottom; - uiWindowsEnsureMoveWindowDuringResize((HWND) uiControlHandle(g->child), r.left, r.top, r.right - r.left, r.bottom - r.top); -} - -static void uiGroupDestroy(uiControl *c) -{ - uiGroup *g = uiGroup(c); - - if (g->child != NULL) { - uiControlSetParent(g->child, NULL); - uiControlDestroy(g->child); - } - uiWindowsEnsureDestroyWindow(g->hwnd); - uiFreeControl(uiControl(g)); -} - -uiWindowsControlDefaultHandle(uiGroup) -uiWindowsControlDefaultParent(uiGroup) -uiWindowsControlDefaultSetParent(uiGroup) -uiWindowsControlDefaultToplevel(uiGroup) -uiWindowsControlDefaultVisible(uiGroup) -uiWindowsControlDefaultShow(uiGroup) -uiWindowsControlDefaultHide(uiGroup) -uiWindowsControlDefaultEnabled(uiGroup) -uiWindowsControlDefaultEnable(uiGroup) -uiWindowsControlDefaultDisable(uiGroup) -uiWindowsControlDefaultSetFocus(uiGroup) - -static void uiGroupSyncEnableState(uiWindowsControl *c, int enabled) -{ - uiGroup *g = uiGroup(c); - - if (uiWindowsShouldStopSyncEnableState(uiWindowsControl(g), enabled)) - return; - EnableWindow(g->hwnd, enabled); - if (g->child != NULL) - uiWindowsControlSyncEnableState(uiWindowsControl(g->child), enabled); -} - -uiWindowsControlDefaultSetParentHWND(uiGroup) - -static void uiGroupMinimumSize(uiWindowsControl *c, int *width, int *height) -{ - uiGroup *g = uiGroup(c); - int mx, mtop, mbottom; - int labelWidth; - - *width = 0; - *height = 0; - if (g->child != NULL) - uiWindowsControlMinimumSize(uiWindowsControl(g->child), width, height); - labelWidth = uiWindowsWindowTextWidth(g->hwnd); - if (*width < labelWidth) // don't clip the label; it doesn't ellipsize - *width = labelWidth; - groupMargins(g, &mx, &mtop, &mbottom); - *width += 2 * mx; - *height += mtop + mbottom; -} - -static void uiGroupMinimumSizeChanged(uiWindowsControl *c) -{ - uiGroup *g = uiGroup(c); - - if (uiWindowsControlTooSmall(uiWindowsControl(g))) { - uiWindowsControlContinueMinimumSizeChanged(uiWindowsControl(g)); - return; - } - groupRelayout(g); -} - -static void uiGroupSetMinSize(uiControl *c, int w, int h) -{ - // checkme - uiGroupMinimumSizeChanged(uiWindowsControl(c)); -} - -uiWindowsControlDefaultLayoutRect(uiGroup) -uiWindowsControlDefaultAssignControlIDZOrder(uiGroup) - -static void uiGroupChildVisibilityChanged(uiWindowsControl *c) -{ - // TODO eliminate the redundancy - uiWindowsControlMinimumSizeChanged(c); -} - -char *uiGroupTitle(uiGroup *g) -{ - return uiWindowsWindowText(g->hwnd); -} - -void uiGroupSetTitle(uiGroup *g, const char *text) -{ - uiWindowsSetWindowText(g->hwnd, text); - // changing the text might necessitate a change in the groupbox's size - uiWindowsControlMinimumSizeChanged(uiWindowsControl(g)); -} - -void uiGroupSetChild(uiGroup *g, uiControl *child) -{ - if (g->child != NULL) { - uiControlSetParent(g->child, NULL); - uiWindowsControlSetParentHWND(uiWindowsControl(g->child), NULL); - } - g->child = child; - if (g->child != NULL) { - uiControlSetParent(g->child, uiControl(g)); - uiWindowsControlSetParentHWND(uiWindowsControl(g->child), g->hwnd); - uiWindowsControlAssignSoleControlIDZOrder(uiWindowsControl(g->child)); - uiWindowsControlMinimumSizeChanged(uiWindowsControl(g)); - } -} - -int uiGroupMargined(uiGroup *g) -{ - return g->margined; -} - -void uiGroupSetMargined(uiGroup *g, int margined) -{ - g->margined = margined; - uiWindowsControlMinimumSizeChanged(uiWindowsControl(g)); -} - -static LRESULT CALLBACK groupSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) -{ - uiGroup *g = uiGroup(dwRefData); - WINDOWPOS *wp = (WINDOWPOS *) lParam; - MINMAXINFO *mmi = (MINMAXINFO *) lParam; - int minwid, minht; - LRESULT lResult; - - if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE) - return lResult; - switch (uMsg) { - case WM_WINDOWPOSCHANGED: - if ((wp->flags & SWP_NOSIZE) != 0) - break; - groupRelayout(g); - return 0; - case WM_GETMINMAXINFO: - lResult = DefWindowProcW(hwnd, uMsg, wParam, lParam); - uiWindowsControlMinimumSize(uiWindowsControl(g), &minwid, &minht); - mmi->ptMinTrackSize.x = minwid; - mmi->ptMinTrackSize.y = minht; - return lResult; - case WM_NCDESTROY: - if (RemoveWindowSubclass(hwnd, groupSubProc, uIdSubclass) == FALSE) - logLastError(L"error removing groupbox subclass"); - break; - } - return DefSubclassProc(hwnd, uMsg, wParam, lParam); -} - -uiGroup *uiNewGroup(const char *text) -{ - uiGroup *g; - WCHAR *wtext; - - uiWindowsNewControl(uiGroup, g); - - wtext = toUTF16(text); - g->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CONTROLPARENT, - L"button", wtext, - BS_GROUPBOX, - hInstance, NULL, - TRUE); - uiFree(wtext); - - if (SetWindowSubclass(g->hwnd, groupSubProc, 0, (DWORD_PTR) g) == FALSE) - logLastError(L"error subclassing groupbox to handle parent messages"); - - return g; -} diff --git a/src/libui_sdl/libui/windows/init.cpp b/src/libui_sdl/libui/windows/init.cpp deleted file mode 100644 index 5b4fe1d..0000000 --- a/src/libui_sdl/libui/windows/init.cpp +++ /dev/null @@ -1,167 +0,0 @@ -// 6 april 2015 -#include "uipriv_windows.hpp" - -HINSTANCE hInstance; -int nCmdShow; - -HFONT hMessageFont; - -// LONGTERM needed? -HBRUSH hollowBrush; - -// the returned pointer is actually to the second character -// if the first character is - then free, otherwise don't -static const char *initerr(const char *message, const WCHAR *label, DWORD value) -{ - WCHAR *sysmsg; - BOOL hassysmsg; - WCHAR *wmessage; - WCHAR *wout; - char *out; - - hassysmsg = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, value, 0, (LPWSTR) (&sysmsg), 0, NULL) != 0; - if (!hassysmsg) - sysmsg = L""; - wmessage = toUTF16(message + 1); - wout = strf(L"-error initializing libui: %s; code %I32d (0x%08I32X) %s", - wmessage, - value, value, - sysmsg); - uiFree(wmessage); - if (hassysmsg) - LocalFree(sysmsg); // ignore error - out = toUTF8(wout); - uiFree(wout); - return out + 1; -} - -#define ieLastErr(msg) initerr("=" msg, L"GetLastError() ==", GetLastError()) -#define ieHRESULT(msg, hr) initerr("=" msg, L"HRESULT", (DWORD) hr) - -// LONGTERM make common -uiInitOptions options; - -#define wantedICCClasses ( \ - ICC_STANDARD_CLASSES | /* user32.dll controls */ \ - ICC_PROGRESS_CLASS | /* progress bars */ \ - ICC_TAB_CLASSES | /* tabs */ \ - ICC_LISTVIEW_CLASSES | /* table headers */ \ - ICC_UPDOWN_CLASS | /* spinboxes */ \ - ICC_BAR_CLASSES | /* trackbar */ \ - ICC_DATE_CLASSES | /* date/time picker */ \ - 0) - -const char *uiInit(uiInitOptions *o) -{ - STARTUPINFOW si; - const char *ce; - HICON hDefaultIcon; - HCURSOR hDefaultCursor; - NONCLIENTMETRICSW ncm; - INITCOMMONCONTROLSEX icc; - HRESULT hr; - - options = *o; - - initAlloc(); - - nCmdShow = SW_SHOWDEFAULT; - GetStartupInfoW(&si); - if ((si.dwFlags & STARTF_USESHOWWINDOW) != 0) - nCmdShow = si.wShowWindow; - - SetProcessDPIAware(); - - hDefaultIcon = LoadIconW(NULL, IDI_APPLICATION); - if (hDefaultIcon == NULL) - return ieLastErr("loading default icon for window classes"); - hDefaultCursor = LoadCursorW(NULL, IDC_ARROW); - if (hDefaultCursor == NULL) - return ieLastErr("loading default cursor for window classes"); - - ce = initUtilWindow(hDefaultIcon, hDefaultCursor); - if (ce != NULL) - return initerr(ce, L"GetLastError() ==", GetLastError()); - - if (registerWindowClass(hDefaultIcon, hDefaultCursor) == 0) - return ieLastErr("registering uiWindow window class"); - - ZeroMemory(&ncm, sizeof (NONCLIENTMETRICSW)); - ncm.cbSize = sizeof (NONCLIENTMETRICSW); - if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof (NONCLIENTMETRICSW), &ncm, sizeof (NONCLIENTMETRICSW)) == 0) - return ieLastErr("getting default fonts"); - hMessageFont = CreateFontIndirectW(&(ncm.lfMessageFont)); - if (hMessageFont == NULL) - return ieLastErr("loading default messagebox font; this is the default UI font"); - - if (initContainer(hDefaultIcon, hDefaultCursor) == 0) - return ieLastErr("initializing uiWindowsMakeContainer() window class"); - - hollowBrush = (HBRUSH) GetStockObject(HOLLOW_BRUSH); - if (hollowBrush == NULL) - return ieLastErr("getting hollow brush"); - - ZeroMemory(&icc, sizeof (INITCOMMONCONTROLSEX)); - icc.dwSize = sizeof (INITCOMMONCONTROLSEX); - icc.dwICC = wantedICCClasses; - if (InitCommonControlsEx(&icc) == 0) - return ieLastErr("initializing Common Controls"); - - hr = CoInitialize(NULL); - if (hr != S_OK && hr != S_FALSE) - return ieHRESULT("initializing COM", hr); - // LONGTERM initialize COM security - // LONGTERM (windows vista) turn off COM exception handling - - hr = initDraw(); - if (hr != S_OK) - return ieHRESULT("initializing Direct2D", hr); - - hr = initDrawText(); - if (hr != S_OK) - return ieHRESULT("initializing DirectWrite", hr); - - if (registerAreaClass(hDefaultIcon, hDefaultCursor) == 0) - return ieLastErr("registering uiArea window class"); - - if (registerMessageFilter() == 0) - return ieLastErr("registering libui message filter"); - - if (registerD2DScratchClass(hDefaultIcon, hDefaultCursor) == 0) - return ieLastErr("initializing D2D scratch window class"); - - return NULL; -} - -void uiUninit(void) -{ - uninitMenus(); - unregisterD2DScratchClass(); - unregisterMessageFilter(); - unregisterArea(); - uninitDrawText(); - uninitDraw(); - CoUninitialize(); - if (DeleteObject(hollowBrush) == 0) - logLastError(L"error freeing hollow brush"); - uninitContainer(); - if (DeleteObject(hMessageFont) == 0) - logLastError(L"error deleting control font"); - unregisterWindowClass(); - // no need to delete the default icon or cursor; see http://stackoverflow.com/questions/30603077/ - uninitUtilWindow(); - uninitAlloc(); -} - -void uiFreeInitError(const char *err) -{ - if (*(err - 1) == '-') - uiFree((void *) (err - 1)); -} - -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) -{ - if (fdwReason == DLL_PROCESS_ATTACH) - hInstance = hinstDLL; - return TRUE; -} diff --git a/src/libui_sdl/libui/windows/label.cpp b/src/libui_sdl/libui/windows/label.cpp deleted file mode 100644 index d74b7d1..0000000 --- a/src/libui_sdl/libui/windows/label.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// 11 april 2015 -#include "uipriv_windows.hpp" - -struct uiLabel { - uiWindowsControl c; - HWND hwnd; -}; - -uiWindowsControlAllDefaults(uiLabel) - -// via http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing -#define labelHeight 8 - -static void uiLabelMinimumSize(uiWindowsControl *c, int *width, int *height) -{ - uiLabel *l = uiLabel(c); - uiWindowsSizing sizing; - int y; - - *width = uiWindowsWindowTextWidth(l->hwnd); - y = labelHeight; - uiWindowsGetSizing(l->hwnd, &sizing); - uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, &y); - *height = y; -} - -char *uiLabelText(uiLabel *l) -{ - return uiWindowsWindowText(l->hwnd); -} - -void uiLabelSetText(uiLabel *l, const char *text) -{ - uiWindowsSetWindowText(l->hwnd, text); - // changing the text might necessitate a change in the label's size - uiWindowsControlMinimumSizeChanged(uiWindowsControl(l)); -} - -uiLabel *uiNewLabel(const char *text) -{ - uiLabel *l; - WCHAR *wtext; - - uiWindowsNewControl(uiLabel, l); - - wtext = toUTF16(text); - l->hwnd = uiWindowsEnsureCreateControlHWND(0, - L"static", wtext, - // SS_LEFTNOWORDWRAP clips text past the end; SS_NOPREFIX avoids accelerator translation - // controls are vertically aligned to the top by default (thanks Xeek in irc.freenode.net/#winapi) - SS_LEFTNOWORDWRAP | SS_NOPREFIX, - hInstance, NULL, - TRUE); - uiFree(wtext); - - return l; -} diff --git a/src/libui_sdl/libui/windows/libui.manifest b/src/libui_sdl/libui/windows/libui.manifest deleted file mode 100644 index 8beb6cf..0000000 --- a/src/libui_sdl/libui/windows/libui.manifest +++ /dev/null @@ -1,31 +0,0 @@ - - - -Your application description here. - - - - - - - - - - - - - - - diff --git a/src/libui_sdl/libui/windows/main.cpp b/src/libui_sdl/libui/windows/main.cpp deleted file mode 100644 index eb6d849..0000000 --- a/src/libui_sdl/libui/windows/main.cpp +++ /dev/null @@ -1,130 +0,0 @@ -// 6 april 2015 -#include "uipriv_windows.hpp" - -static HHOOK filter; - -static LRESULT CALLBACK filterProc(int code, WPARAM wParam, LPARAM lParam) -{ - MSG *msg = (MSG *) lParam; - - if (code < 0) - goto callNext; - - if (areaFilter(msg)) // don't continue to our IsDialogMessage() hack if the area handled it - goto discard; - - // TODO IsDialogMessage() hack here - - // otherwise keep going - goto callNext; - -discard: - // we handled it; discard the message so the dialog manager doesn't see it - return 1; - -callNext: - return CallNextHookEx(filter, code, wParam, lParam); -} - -int registerMessageFilter(void) -{ - filter = SetWindowsHookExW(WH_MSGFILTER, - filterProc, - hInstance, - GetCurrentThreadId()); - return filter != NULL; -} - -void unregisterMessageFilter(void) -{ - if (UnhookWindowsHookEx(filter) == 0) - logLastError(L"error unregistering libui message filter"); -} - -// LONGTERM http://blogs.msdn.com/b/oldnewthing/archive/2005/04/08/406509.aspx when adding accelerators, TranslateAccelerators() before IsDialogMessage() - -static void processMessage(MSG *msg) -{ - HWND correctParent; - - if (msg->hwnd != NULL) - correctParent = parentToplevel(msg->hwnd); - else // just to be safe - correctParent = GetActiveWindow(); - if (correctParent != NULL) - // this calls our mesage filter above for us - if (IsDialogMessage(correctParent, msg) != 0) - return; - TranslateMessage(msg); - DispatchMessageW(msg); -} - -static int waitMessage(MSG *msg) -{ - int res; - - res = GetMessageW(msg, NULL, 0, 0); - if (res < 0) { - logLastError(L"error calling GetMessage()"); - return 0; // bail out on error - } - return res != 0; // returns false on WM_QUIT -} - -void uiMain(void) -{ - while (uiMainStep(1)) - ; -} - -void uiMainSteps(void) -{ - // don't need to do anything here -} - -static int peekMessage(MSG *msg) -{ - BOOL res; - - res = PeekMessageW(msg, NULL, 0, 0, PM_REMOVE); - if (res == 0) - return 2; // no message available - if (msg->message != WM_QUIT) - return 1; // a message - return 0; // WM_QUIT -} - -int uiMainStep(int wait) -{ - MSG msg; - - if (wait) { - if (!waitMessage(&msg)) - return 0; - processMessage(&msg); - return 1; - } - - // don't wait for a message - switch (peekMessage(&msg)) { - case 0: // quit - // TODO PostQuitMessage() again? - return 0; - case 1: // process a message - processMessage(&msg); - // fall out to the case for no message - } - return 1; // no message -} - -void uiQuit(void) -{ - PostQuitMessage(0); -} - -void uiQueueMain(void (*f)(void *data), void *data) -{ - if (PostMessageW(utilWindow, msgQueued, (WPARAM) f, (LPARAM) data) == 0) - // LONGTERM this is likely not safe to call across threads (allocates memory) - logLastError(L"error queueing function to run on main thread"); -} diff --git a/src/libui_sdl/libui/windows/menu.cpp b/src/libui_sdl/libui/windows/menu.cpp deleted file mode 100644 index ccf5c9c..0000000 --- a/src/libui_sdl/libui/windows/menu.cpp +++ /dev/null @@ -1,420 +0,0 @@ -// 24 april 2015 -#include "uipriv_windows.hpp" - -// LONGTERM migrate to std::vector - -static uiMenu **menus = NULL; -static size_t len = 0; -static size_t cap = 0; -static BOOL menusFinalized = FALSE; -static WORD curID = 100; // start somewhere safe -static BOOL hasQuit = FALSE; -static BOOL hasPreferences = FALSE; -static BOOL hasAbout = FALSE; - -struct uiMenu { - WCHAR *name; - HMENU handle; - uiMenuItem **items; - BOOL ischild; - size_t len; - size_t cap; -}; - -struct uiMenuItem { - WCHAR *name; - int type; - WORD id; - void (*onClicked)(uiMenuItem *, uiWindow *, void *); - void *onClickedData; - BOOL disabled; // template for new instances; kept in sync with everything else - BOOL checked; - HMENU *hmenus; - uiMenu* popupchild; - size_t len; - size_t cap; -}; - -enum { - typeRegular, - typeCheckbox, - typeQuit, - typePreferences, - typeAbout, - typeSeparator, - typeSubmenu, -}; - -#define grow 32 - -static void sync(uiMenuItem *item) -{ - size_t i; - MENUITEMINFOW mi; - - ZeroMemory(&mi, sizeof (MENUITEMINFOW)); - mi.cbSize = sizeof (MENUITEMINFOW); - mi.fMask = MIIM_STATE; - if (item->disabled) - mi.fState |= MFS_DISABLED; - if (item->checked) - mi.fState |= MFS_CHECKED; - - for (i = 0; i < item->len; i++) - if (SetMenuItemInfo(item->hmenus[i], item->id, FALSE, &mi) == 0) - logLastError(L"error synchronizing menu items"); -} - -static void defaultOnClicked(uiMenuItem *item, uiWindow *w, void *data) -{ - // do nothing -} - -static void onQuitClicked(uiMenuItem *item, uiWindow *w, void *data) -{ - if (shouldQuit()) - uiQuit(); -} - -void uiMenuItemEnable(uiMenuItem *i) -{ - i->disabled = FALSE; - sync(i); -} - -void uiMenuItemDisable(uiMenuItem *i) -{ - i->disabled = TRUE; - sync(i); -} - -void uiMenuItemOnClicked(uiMenuItem *i, void (*f)(uiMenuItem *, uiWindow *, void *), void *data) -{ - if (i->type == typeQuit) - userbug("You can not call uiMenuItemOnClicked() on a Quit item; use uiOnShouldQuit() instead."); - i->onClicked = f; - i->onClickedData = data; -} - -int uiMenuItemChecked(uiMenuItem *i) -{ - return i->checked != FALSE; -} - -void uiMenuItemSetChecked(uiMenuItem *i, int checked) -{ - // use explicit values - i->checked = FALSE; - if (checked) - i->checked = TRUE; - sync(i); -} - -static uiMenuItem *newItem(uiMenu *m, int type, const char *name) -{ - uiMenuItem *item; - - if (menusFinalized) - userbug("You can not create a new menu item after menus have been finalized."); - - if (m->len >= m->cap) { - m->cap += grow; - m->items = (uiMenuItem **) uiRealloc(m->items, m->cap * sizeof (uiMenuItem *), "uiMenuitem *[]"); - } - - item = uiNew(uiMenuItem); - - m->items[m->len] = item; - m->len++; - - item->type = type; - switch (item->type) { - case typeQuit: - item->name = toUTF16("Quit"); - break; - case typePreferences: - item->name = toUTF16("Preferences..."); - break; - case typeAbout: - item->name = toUTF16("About"); - break; - case typeSeparator: - break; - default: - item->name = toUTF16(name); - break; - } - item->popupchild = NULL; - - if (item->type != typeSeparator) { - item->id = curID; - curID++; - } - - if (item->type == typeQuit) { - // can't call uiMenuItemOnClicked() here - item->onClicked = onQuitClicked; - item->onClickedData = NULL; - } else - uiMenuItemOnClicked(item, defaultOnClicked, NULL); - - return item; -} - -uiMenuItem *uiMenuAppendSubmenu(uiMenu *m, uiMenu* child) -{ - uiMenuItem *item; - - if (menusFinalized) - userbug("You can not create a new menu item after menus have been finalized."); - - if (m->len >= m->cap) { - m->cap += grow; - m->items = (uiMenuItem **) uiRealloc(m->items, m->cap * sizeof (uiMenuItem *), "uiMenuitem *[]"); - } - - item = uiNew(uiMenuItem); - - m->items[m->len] = item; - m->len++; - - item->type = typeSubmenu; - item->name = child->name; - - item->popupchild = child; - child->ischild = TRUE; - - uiMenuItemOnClicked(item, defaultOnClicked, NULL); - - return item; -} - -uiMenuItem *uiMenuAppendItem(uiMenu *m, const char *name) -{ - return newItem(m, typeRegular, name); -} - -uiMenuItem *uiMenuAppendCheckItem(uiMenu *m, const char *name) -{ - return newItem(m, typeCheckbox, name); -} - -uiMenuItem *uiMenuAppendQuitItem(uiMenu *m) -{ - if (hasQuit) - userbug("You can not have multiple Quit menu items in a program."); - hasQuit = TRUE; - newItem(m, typeSeparator, NULL); - return newItem(m, typeQuit, NULL); -} - -uiMenuItem *uiMenuAppendPreferencesItem(uiMenu *m) -{ - if (hasPreferences) - userbug("You can not have multiple Preferences menu items in a program."); - hasPreferences = TRUE; - newItem(m, typeSeparator, NULL); - return newItem(m, typePreferences, NULL); -} - -uiMenuItem *uiMenuAppendAboutItem(uiMenu *m) -{ - if (hasAbout) - // TODO place these userbug strings in a header - userbug("You can not have multiple About menu items in a program."); - hasAbout = TRUE; - newItem(m, typeSeparator, NULL); - return newItem(m, typeAbout, NULL); -} - -void uiMenuAppendSeparator(uiMenu *m) -{ - newItem(m, typeSeparator, NULL); -} - -uiMenu *uiNewMenu(const char *name) -{ - uiMenu *m; - - if (menusFinalized) - userbug("You can not create a new menu after menus have been finalized."); - if (len >= cap) { - cap += grow; - menus = (uiMenu **) uiRealloc(menus, cap * sizeof (uiMenu *), "uiMenu *[]"); - } - - m = uiNew(uiMenu); - - menus[len] = m; - len++; - - m->name = toUTF16(name); - m->ischild = FALSE; - - return m; -} - -static HMENU makeMenu(uiMenu *m); - -static void appendMenuItem(HMENU menu, uiMenuItem *item) -{ - UINT uFlags; - UINT_PTR id = item->id; - - uFlags = MF_SEPARATOR; - if (item->type != typeSeparator) { - uFlags = MF_STRING; - if (item->disabled) - uFlags |= MF_DISABLED | MF_GRAYED; - if (item->checked) - uFlags |= MF_CHECKED; - if (item->popupchild) - { - uFlags |= MF_POPUP; - id = (UINT_PTR)makeMenu(item->popupchild); - } - } - if (AppendMenuW(menu, uFlags, id, item->name) == 0) - logLastError(L"error appending menu item"); - - if (item->len >= item->cap) { - item->cap += grow; - item->hmenus = (HMENU *) uiRealloc(item->hmenus, item->cap * sizeof (HMENU), "HMENU[]"); - } - item->hmenus[item->len] = menu; - item->len++; -} - -static HMENU makeMenu(uiMenu *m) -{ - HMENU menu; - size_t i; - - menu = CreatePopupMenu(); - if (menu == NULL) - logLastError(L"error creating menu"); - m->handle = menu; - for (i = 0; i < m->len; i++) - appendMenuItem(menu, m->items[i]); - return menu; -} - -HMENU makeMenubar(void) -{ - HMENU menubar; - HMENU menu; - size_t i; - - menusFinalized = TRUE; - - menubar = CreateMenu(); - if (menubar == NULL) - logLastError(L"error creating menubar"); - - for (i = 0; i < len; i++) { - if (menus[i]->ischild) continue; - menu = makeMenu(menus[i]); - if (AppendMenuW(menubar, MF_POPUP | MF_STRING, (UINT_PTR) menu, menus[i]->name) == 0) - logLastError(L"error appending menu to menubar"); - } - - return menubar; -} - -void runMenuEvent(WORD id, uiWindow *w) -{ - uiMenu *m; - uiMenuItem *item; - size_t i, j; - - // this isn't optimal, but it works, and it should be just fine for most cases - for (i = 0; i < len; i++) { - m = menus[i]; - for (j = 0; j < m->len; j++) { - item = m->items[j]; - if (item->id == id) - goto found; - } - } - // no match - implbug("unknown menu ID %hu in runMenuEvent()", id); - -found: - // first toggle checkboxes, if any - if (item->type == typeCheckbox) - uiMenuItemSetChecked(item, !uiMenuItemChecked(item)); - - // then run the event - (*(item->onClicked))(item, w, item->onClickedData); -} - -static void freeMenu(uiMenu *m, HMENU submenu) -{ - size_t i; - uiMenuItem *item; - size_t j; - - for (i = 0; i < m->len; i++) { - item = m->items[i]; - for (j = 0; j < item->len; j++) - if (item->hmenus[j] == submenu) - break; - if (j >= item->len) - implbug("submenu handle %p not found in freeMenu()", submenu); - for (; j < item->len - 1; j++) - item->hmenus[j] = item->hmenus[j + 1]; - item->hmenus[j] = NULL; - item->len--; - - if (item->popupchild) - freeMenu(item->popupchild, item->popupchild->handle); - } -} - -void freeMenubar(HMENU menubar) -{ - size_t i; - size_t j = 0; - MENUITEMINFOW mi; - - for (i = 0; i < len; i++) - { - if (menus[i]->ischild) continue; - ZeroMemory(&mi, sizeof (MENUITEMINFOW)); - mi.cbSize = sizeof (MENUITEMINFOW); - mi.fMask = MIIM_SUBMENU; - if (GetMenuItemInfoW(menubar, j, TRUE, &mi) == 0) - logLastError(L"error getting menu to delete item references from"); - freeMenu(menus[i], mi.hSubMenu); - j++; - } - // no need to worry about destroying any menus; destruction of the window they're in will do it for us -} - -void uninitMenus(void) -{ - uiMenu *m; - uiMenuItem *item; - size_t i, j; - - for (i = 0; i < len; i++) { - m = menus[i]; - uiFree(m->name); - for (j = 0; j < m->len; j++) { - item = m->items[j]; - if (item->len != 0) - // LONGTERM userbug()? - implbug("menu item %p (%ws) still has uiWindows attached; did you forget to destroy some windows?", item, item->name); - if (item->type != typeSubmenu && item->name != NULL) - uiFree(item->name); - if (item->hmenus != NULL) - uiFree(item->hmenus); - uiFree(item); - } - if (m->items != NULL) - uiFree(m->items); - uiFree(m); - } - if (menus != NULL) - uiFree(menus); -} diff --git a/src/libui_sdl/libui/windows/multilineentry.cpp b/src/libui_sdl/libui/windows/multilineentry.cpp deleted file mode 100644 index a32960c..0000000 --- a/src/libui_sdl/libui/windows/multilineentry.cpp +++ /dev/null @@ -1,152 +0,0 @@ -// 8 april 2015 -#include "uipriv_windows.hpp" - -// TODO there's alpha darkening of text going on in read-only ones; something is up in our parent logic - -struct uiMultilineEntry { - uiWindowsControl c; - HWND hwnd; - void (*onChanged)(uiMultilineEntry *, void *); - void *onChangedData; - BOOL inhibitChanged; -}; - -static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult) -{ - uiMultilineEntry *e = uiMultilineEntry(c); - - if (code != EN_CHANGE) - return FALSE; - if (e->inhibitChanged) - return FALSE; - (*(e->onChanged))(e, e->onChangedData); - *lResult = 0; - return TRUE; -} - -static void uiMultilineEntryDestroy(uiControl *c) -{ - uiMultilineEntry *e = uiMultilineEntry(c); - - uiWindowsUnregisterWM_COMMANDHandler(e->hwnd); - uiWindowsEnsureDestroyWindow(e->hwnd); - uiFreeControl(uiControl(e)); -} - -uiWindowsControlAllDefaultsExceptDestroy(uiMultilineEntry) - -// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing -#define entryWidth 107 /* this is actually the shorter progress bar width, but Microsoft only indicates as wide as necessary */ -// LONGTERM change this for multiline text boxes (longterm because how?) -#define entryHeight 14 - -static void uiMultilineEntryMinimumSize(uiWindowsControl *c, int *width, int *height) -{ - uiMultilineEntry *e = uiMultilineEntry(c); - uiWindowsSizing sizing; - int x, y; - - x = entryWidth; - y = entryHeight; - uiWindowsGetSizing(e->hwnd, &sizing); - uiWindowsSizingDlgUnitsToPixels(&sizing, &x, &y); - *width = x; - *height = y; -} - -static void defaultOnChanged(uiMultilineEntry *e, void *data) -{ - // do nothing -} - -char *uiMultilineEntryText(uiMultilineEntry *e) -{ - char *out; - - out = uiWindowsWindowText(e->hwnd); - CRLFtoLF(out); - return out; -} - -void uiMultilineEntrySetText(uiMultilineEntry *e, const char *text) -{ - char *crlf; - - // doing this raises an EN_CHANGED - e->inhibitChanged = TRUE; - crlf = LFtoCRLF(text); - uiWindowsSetWindowText(e->hwnd, text); - uiFree(crlf); - e->inhibitChanged = FALSE; - // don't queue the control for resize; entry sizes are independent of their contents -} - -void uiMultilineEntryAppend(uiMultilineEntry *e, const char *text) -{ - LRESULT n; - char *crlf; - WCHAR *wtext; - - // doing this raises an EN_CHANGED - e->inhibitChanged = TRUE; - // TODO preserve selection? caret? what if caret used to be at end? - // TODO scroll to bottom? - n = SendMessageW(e->hwnd, WM_GETTEXTLENGTH, 0, 0); - SendMessageW(e->hwnd, EM_SETSEL, n, n); - crlf = LFtoCRLF(text); - wtext = toUTF16(crlf); - uiFree(crlf); - SendMessageW(e->hwnd, EM_REPLACESEL, FALSE, (LPARAM) wtext); - uiFree(wtext); - e->inhibitChanged = FALSE; -} - -void uiMultilineEntryOnChanged(uiMultilineEntry *e, void (*f)(uiMultilineEntry *, void *), void *data) -{ - e->onChanged = f; - e->onChangedData = data; -} - -int uiMultilineEntryReadOnly(uiMultilineEntry *e) -{ - return (getStyle(e->hwnd) & ES_READONLY) != 0; -} - -void uiMultilineEntrySetReadOnly(uiMultilineEntry *e, int readonly) -{ - WPARAM ro; - - ro = (WPARAM) FALSE; - if (readonly) - ro = (WPARAM) TRUE; - if (SendMessage(e->hwnd, EM_SETREADONLY, ro, 0) == 0) - logLastError(L"error making uiMultilineEntry read-only"); -} - -static uiMultilineEntry *finishMultilineEntry(DWORD style) -{ - uiMultilineEntry *e; - - uiWindowsNewControl(uiMultilineEntry, e); - - e->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE, - L"edit", L"", - ES_AUTOVSCROLL | ES_LEFT | ES_MULTILINE | ES_NOHIDESEL | ES_WANTRETURN | WS_TABSTOP | WS_VSCROLL | style, - hInstance, NULL, - TRUE); - - uiWindowsRegisterWM_COMMANDHandler(e->hwnd, onWM_COMMAND, uiControl(e)); - uiMultilineEntryOnChanged(e, defaultOnChanged, NULL); - - return e; -} - -uiMultilineEntry *uiNewMultilineEntry(void) -{ - return finishMultilineEntry(0); -} - -uiMultilineEntry *uiNewNonWrappingMultilineEntry(void) -{ - return finishMultilineEntry(WS_HSCROLL | ES_AUTOHSCROLL); -} diff --git a/src/libui_sdl/libui/windows/notes b/src/libui_sdl/libui/windows/notes deleted file mode 100644 index f554dd2..0000000 --- a/src/libui_sdl/libui/windows/notes +++ /dev/null @@ -1,3 +0,0 @@ -DIALOGS -do not accelerate OK and Cancel buttons in dialogs - http://blogs.msdn.com/b/oldnewthing/archive/2008/05/08/8467905.aspx diff --git a/src/libui_sdl/libui/windows/parent.cpp b/src/libui_sdl/libui/windows/parent.cpp deleted file mode 100644 index bde6fb9..0000000 --- a/src/libui_sdl/libui/windows/parent.cpp +++ /dev/null @@ -1,144 +0,0 @@ -// 26 april 2015 -#include "uipriv_windows.hpp" - -// This contains code used by all uiControls that contain other controls. -// It also contains the code to draw the background of a container.c container, as that is a variant of the WM_CTLCOLORxxx handler code. - -static HBRUSH parentBrush = NULL; - -static HWND parentWithBackground(HWND hwnd) -{ - HWND parent; - int cls; - - parent = hwnd; - for (;;) { - parent = parentOf(parent); - // skip groupboxes; they're (supposed to be) transparent - // skip uiContainers; they don't draw anything - cls = windowClassOf(parent, L"button", containerClass, NULL); - if (cls != 0 && cls != 1) - break; - } - return parent; -} - -struct parentDraw { - HDC cdc; - HBITMAP bitmap; - HBITMAP prevbitmap; -}; - -static HRESULT parentDraw(HDC dc, HWND parent, struct parentDraw *pd) -{ - RECT r; - - uiWindowsEnsureGetClientRect(parent, &r); - pd->cdc = CreateCompatibleDC(dc); - if (pd->cdc == NULL) - return logLastError(L"error creating compatible DC"); - pd->bitmap = CreateCompatibleBitmap(dc, r.right - r.left, r.bottom - r.top); - if (pd->bitmap == NULL) - return logLastError(L"error creating compatible bitmap"); - pd->prevbitmap = (HBITMAP) SelectObject(pd->cdc, pd->bitmap); - if (pd->prevbitmap == NULL) - return logLastError(L"error selecting bitmap into compatible DC"); - SendMessageW(parent, WM_PRINTCLIENT, (WPARAM) (pd->cdc), PRF_CLIENT); - return S_OK; -} - -static void endParentDraw(struct parentDraw *pd) -{ - // continue in case of any error - if (pd->prevbitmap != NULL) - if (((HBITMAP) SelectObject(pd->cdc, pd->prevbitmap)) != pd->bitmap) - logLastError(L"error selecting previous bitmap back into compatible DC"); - if (pd->bitmap != NULL) - if (DeleteObject(pd->bitmap) == 0) - logLastError(L"error deleting compatible bitmap"); - if (pd->cdc != NULL) - if (DeleteDC(pd->cdc) == 0) - logLastError(L"error deleting compatible DC"); -} - -// see http://www.codeproject.com/Articles/5978/Correctly-drawn-themed-dialogs-in-WinXP -static HBRUSH getControlBackgroundBrush(HWND hwnd, HDC dc) -{ - HWND parent; - RECT hwndScreenRect; - struct parentDraw pd; - HBRUSH brush; - HRESULT hr; - - parent = parentWithBackground(hwnd); - - hr = parentDraw(dc, parent, &pd); - if (hr != S_OK) - return NULL; - brush = CreatePatternBrush(pd.bitmap); - if (brush == NULL) { - logLastError(L"error creating pattern brush"); - endParentDraw(&pd); - return NULL; - } - endParentDraw(&pd); - - // now figure out where the control is relative to the parent so we can align the brush properly - // if anything fails, give up and return the brush as-is - uiWindowsEnsureGetWindowRect(hwnd, &hwndScreenRect); - // this will be in screen coordinates; convert to parent coordinates - mapWindowRect(NULL, parent, &hwndScreenRect); - if (SetBrushOrgEx(dc, -hwndScreenRect.left, -hwndScreenRect.top, NULL) == 0) - logLastError(L"error setting brush origin"); - - return brush; -} - -void paintContainerBackground(HWND hwnd, HDC dc, RECT *paintRect) -{ - HWND parent; - RECT paintRectParent; - struct parentDraw pd; - HRESULT hr; - - parent = parentWithBackground(hwnd); - hr = parentDraw(dc, parent, &pd); - if (hr != S_OK) // we couldn't get it; draw nothing - return; - - paintRectParent = *paintRect; - mapWindowRect(hwnd, parent, &paintRectParent); - if (BitBlt(dc, paintRect->left, paintRect->top, paintRect->right - paintRect->left, paintRect->bottom - paintRect->top, - pd.cdc, paintRectParent.left, paintRectParent.top, - SRCCOPY) == 0) - logLastError(L"error drawing parent background over uiContainer"); - - endParentDraw(&pd); -} - -// TODO make this public if we want custom containers -// why have this to begin with? http://blogs.msdn.com/b/oldnewthing/archive/2010/03/16/9979112.aspx -BOOL handleParentMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult) -{ - switch (uMsg) { - case WM_COMMAND: - return runWM_COMMAND(wParam, lParam, lResult); - case WM_NOTIFY: - return runWM_NOTIFY(wParam, lParam, lResult); - case WM_HSCROLL: - return runWM_HSCROLL(wParam, lParam, lResult); - case WM_CTLCOLORSTATIC: - case WM_CTLCOLORBTN: - if (parentBrush != NULL) - if (DeleteObject(parentBrush) == 0) - logLastError(L"error deleting old background brush()"); // but continue anyway; we will leak a brush but whatever - if (SetBkMode((HDC) wParam, TRANSPARENT) == 0) - logLastError(L"error setting transparent background mode to controls"); // but continue anyway; text will be wrong - parentBrush = getControlBackgroundBrush((HWND) lParam, (HDC) wParam); - if (parentBrush == NULL) // failed; just do default behavior - return FALSE; - *lResult = (LRESULT) parentBrush; - return TRUE; - } - return FALSE; -} diff --git a/src/libui_sdl/libui/windows/progressbar.cpp b/src/libui_sdl/libui/windows/progressbar.cpp deleted file mode 100644 index 3750eb6..0000000 --- a/src/libui_sdl/libui/windows/progressbar.cpp +++ /dev/null @@ -1,83 +0,0 @@ -// 19 may 2015 -#include "uipriv_windows.hpp" - -struct uiProgressBar { - uiWindowsControl c; - HWND hwnd; -}; - -uiWindowsControlAllDefaults(uiProgressBar) - -// via http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing -#define pbarWidth 237 -#define pbarHeight 8 - -static void uiProgressBarMinimumSize(uiWindowsControl *c, int *width, int *height) -{ - uiProgressBar *p = uiProgressBar(c); - uiWindowsSizing sizing; - int x, y; - - x = pbarWidth; - y = pbarHeight; - uiWindowsGetSizing(p->hwnd, &sizing); - uiWindowsSizingDlgUnitsToPixels(&sizing, &x, &y); - *width = x; - *height = y; -} - -#define indeterminate(p) ((getStyle(p->hwnd) & PBS_MARQUEE) != 0) - -int uiProgressBarValue(uiProgressBar *p) -{ - if (indeterminate(p)) - return -1; - return SendMessage(p->hwnd, PBM_GETPOS, 0, 0); -} - -// unfortunately, as of Vista progress bars have a forced animation on increase -// we have to set the progress bar to value + 1 and decrease it back to value if we want an "instant" change -// see http://stackoverflow.com/questions/2217688/windows-7-aero-theme-progress-bar-bug -// it's not ideal/perfect, but it will have to do -void uiProgressBarSetValue(uiProgressBar *p, int value) -{ - if (value == -1) { - if (!indeterminate(p)) { - setStyle(p->hwnd, getStyle(p->hwnd) | PBS_MARQUEE); - SendMessageW(p->hwnd, PBM_SETMARQUEE, (WPARAM) TRUE, 0); - } - return; - } - if (indeterminate(p)) { - SendMessageW(p->hwnd, PBM_SETMARQUEE, (WPARAM) FALSE, 0); - setStyle(p->hwnd, getStyle(p->hwnd) & ~PBS_MARQUEE); - } - - if (value < 0 || value > 100) - userbug("Value %d is out of range for uiProgressBars.", value); - - if (value == 100) { // because we can't 101 - SendMessageW(p->hwnd, PBM_SETRANGE32, 0, 101); - SendMessageW(p->hwnd, PBM_SETPOS, 101, 0); - SendMessageW(p->hwnd, PBM_SETPOS, 100, 0); - SendMessageW(p->hwnd, PBM_SETRANGE32, 0, 100); - return; - } - SendMessageW(p->hwnd, PBM_SETPOS, (WPARAM) (value + 1), 0); - SendMessageW(p->hwnd, PBM_SETPOS, (WPARAM) value, 0); -} - -uiProgressBar *uiNewProgressBar(void) -{ - uiProgressBar *p; - - uiWindowsNewControl(uiProgressBar, p); - - p->hwnd = uiWindowsEnsureCreateControlHWND(0, - PROGRESS_CLASSW, L"", - PBS_SMOOTH, - hInstance, NULL, - FALSE); - - return p; -} diff --git a/src/libui_sdl/libui/windows/radiobuttons.cpp b/src/libui_sdl/libui/windows/radiobuttons.cpp deleted file mode 100644 index 29cd2e6..0000000 --- a/src/libui_sdl/libui/windows/radiobuttons.cpp +++ /dev/null @@ -1,196 +0,0 @@ -// 20 may 2015 -#include "uipriv_windows.hpp" - -// desired behavior: -// - tab moves between the radio buttons and the adjacent controls -// - arrow keys navigate between radio buttons -// - arrow keys do not leave the radio buttons (this is done in control.c) -// - arrow keys wrap around bare groups (if the previous control has WS_GROUP but the first radio button doesn't, then it doesn't; since our radio buttons are all in their own child window we can't do that) -// - clicking on a radio button draws a focus rect (TODO) - -struct uiRadioButtons { - uiWindowsControl c; - HWND hwnd; // of the container - std::vector *hwnds; // of the buttons - void (*onSelected)(uiRadioButtons *, void *); - void *onSelectedData; -}; - -static BOOL onWM_COMMAND(uiControl *c, HWND clicked, WORD code, LRESULT *lResult) -{ - uiRadioButtons *r = uiRadioButtons(c); - WPARAM check; - - if (code != BN_CLICKED) - return FALSE; - for (const HWND &hwnd : *(r->hwnds)) { - check = BST_UNCHECKED; - if (clicked == hwnd) - check = BST_CHECKED; - SendMessage(hwnd, BM_SETCHECK, check, 0); - } - (*(r->onSelected))(r, r->onSelectedData); - *lResult = 0; - return TRUE; -} - -static void defaultOnSelected(uiRadioButtons *r, void *data) -{ - // do nothing -} - -static void uiRadioButtonsDestroy(uiControl *c) -{ - uiRadioButtons *r = uiRadioButtons(c); - - for (const HWND &hwnd : *(r->hwnds)) { - uiWindowsUnregisterWM_COMMANDHandler(hwnd); - uiWindowsEnsureDestroyWindow(hwnd); - } - delete r->hwnds; - uiWindowsEnsureDestroyWindow(r->hwnd); - uiFreeControl(uiControl(r)); -} - -// TODO SyncEnableState -uiWindowsControlAllDefaultsExceptDestroy(uiRadioButtons) - -// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing -#define radiobuttonHeight 10 -// from http://msdn.microsoft.com/en-us/library/windows/desktop/bb226818%28v=vs.85%29.aspx -#define radiobuttonXFromLeftOfBoxToLeftOfLabel 12 - -static void uiRadioButtonsMinimumSize(uiWindowsControl *c, int *width, int *height) -{ - uiRadioButtons *r = uiRadioButtons(c); - int wid, maxwid; - uiWindowsSizing sizing; - int x, y; - - if (r->hwnds->size() == 0) { - *width = 0; - *height = 0; - return; - } - maxwid = 0; - for (const HWND &hwnd : *(r->hwnds)) { - wid = uiWindowsWindowTextWidth(hwnd); - if (maxwid < wid) - maxwid = wid; - } - - x = radiobuttonXFromLeftOfBoxToLeftOfLabel; - y = radiobuttonHeight; - uiWindowsGetSizing((*(r->hwnds))[0], &sizing); - uiWindowsSizingDlgUnitsToPixels(&sizing, &x, &y); - - *width = x + maxwid; - *height = y * r->hwnds->size(); -} - -static void radiobuttonsRelayout(uiRadioButtons *r) -{ - RECT client; - int x, y, width, height; - int height1; - uiWindowsSizing sizing; - - if (r->hwnds->size() == 0) - return; - uiWindowsEnsureGetClientRect(r->hwnd, &client); - x = client.left; - y = client.top; - width = client.right - client.left; - height1 = radiobuttonHeight; - uiWindowsGetSizing((*(r->hwnds))[0], &sizing); - uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, &height1); - height = height1; - for (const HWND &hwnd : *(r->hwnds)) { - uiWindowsEnsureMoveWindowDuringResize(hwnd, x, y, width, height); - y += height; - } -} - -static void radiobuttonsArrangeChildren(uiRadioButtons *r) -{ - LONG_PTR controlID; - HWND insertAfter; - - controlID = 100; - insertAfter = NULL; - for (const HWND &hwnd : *(r->hwnds)) - uiWindowsEnsureAssignControlIDZOrder(hwnd, &controlID, &insertAfter); -} - -void uiRadioButtonsAppend(uiRadioButtons *r, const char *text) -{ - HWND hwnd; - WCHAR *wtext; - DWORD groupTabStop; - - // the first radio button gets both WS_GROUP and WS_TABSTOP - // successive radio buttons get *neither* - groupTabStop = 0; - if (r->hwnds->size() == 0) - groupTabStop = WS_GROUP | WS_TABSTOP; - - wtext = toUTF16(text); - hwnd = uiWindowsEnsureCreateControlHWND(0, - L"button", wtext, - BS_RADIOBUTTON | groupTabStop, - hInstance, NULL, - TRUE); - uiFree(wtext); - uiWindowsEnsureSetParentHWND(hwnd, r->hwnd); - uiWindowsRegisterWM_COMMANDHandler(hwnd, onWM_COMMAND, uiControl(r)); - r->hwnds->push_back(hwnd); - radiobuttonsArrangeChildren(r); - uiWindowsControlMinimumSizeChanged(uiWindowsControl(r)); -} - -int uiRadioButtonsSelected(uiRadioButtons *r) -{ - size_t i; - - for (i = 0; i < r->hwnds->size(); i++) - if (SendMessage((*(r->hwnds))[i], BM_GETCHECK, 0, 0) == BST_CHECKED) - return i; - return -1; -} - -void uiRadioButtonsSetSelected(uiRadioButtons *r, int n) -{ - int m; - - m = uiRadioButtonsSelected(r); - if (m != -1) - SendMessage((*(r->hwnds))[m], BM_SETCHECK, BST_UNCHECKED, 0); - if (n != -1) - SendMessage((*(r->hwnds))[n], BM_SETCHECK, BST_CHECKED, 0); -} - -void uiRadioButtonsOnSelected(uiRadioButtons *r, void (*f)(uiRadioButtons *, void *), void *data) -{ - r->onSelected = f; - r->onSelectedData = data; -} - -static void onResize(uiWindowsControl *c) -{ - radiobuttonsRelayout(uiRadioButtons(c)); -} - -uiRadioButtons *uiNewRadioButtons(void) -{ - uiRadioButtons *r; - - uiWindowsNewControl(uiRadioButtons, r); - - r->hwnd = uiWindowsMakeContainer(uiWindowsControl(r), onResize); - - r->hwnds = new std::vector; - - uiRadioButtonsOnSelected(r, defaultOnSelected, NULL); - - return r; -} diff --git a/src/libui_sdl/libui/windows/resources.hpp b/src/libui_sdl/libui/windows/resources.hpp deleted file mode 100644 index 4ae5472..0000000 --- a/src/libui_sdl/libui/windows/resources.hpp +++ /dev/null @@ -1,37 +0,0 @@ -// 30 may 2015 - -#define rcTabPageDialog 29000 -#define rcFontDialog 29001 -#define rcColorDialog 29002 - -// TODO normalize these - -#define rcFontFamilyCombobox 1000 -#define rcFontStyleCombobox 1001 -#define rcFontSizeCombobox 1002 -#define rcFontSamplePlacement 1003 - -#define rcColorSVChooser 1100 -#define rcColorHSlider 1101 -#define rcPreview 1102 -#define rcOpacitySlider 1103 -#define rcH 1104 -#define rcS 1105 -#define rcV 1106 -#define rcRDouble 1107 -#define rcRInt 1108 -#define rcGDouble 1109 -#define rcGInt 1110 -#define rcBDouble 1111 -#define rcBInt 1112 -#define rcADouble 1113 -#define rcAInt 1114 -#define rcHex 1115 -#define rcHLabel 1116 -#define rcSLabel 1117 -#define rcVLabel 1118 -#define rcRLabel 1119 -#define rcGLabel 1120 -#define rcBLabel 1121 -#define rcALabel 1122 -#define rcHexLabel 1123 diff --git a/src/libui_sdl/libui/windows/resources.rc b/src/libui_sdl/libui/windows/resources.rc deleted file mode 100644 index 989dfc9..0000000 --- a/src/libui_sdl/libui/windows/resources.rc +++ /dev/null @@ -1,96 +0,0 @@ -// 30 may 2015 -#include "winapi.hpp" -#include "resources.hpp" - -// this is a UTF-8 file -#pragma code_page(65001) - -// this is the Common Controls 6 manifest -// we only define it in a shared build; static builds have to include the appropriate parts of the manifest in the output executable -// LONGTERM set up the string values here -#ifndef _UI_STATIC -ISOLATIONAWARE_MANIFEST_RESOURCE_ID RT_MANIFEST "libui.manifest" -#endif - -// this is the dialog template used by tab pages; see windows/tabpage.c for details -rcTabPageDialog DIALOGEX 0, 0, 100, 100 -STYLE DS_CONTROL | WS_CHILD | WS_VISIBLE -EXSTYLE WS_EX_CONTROLPARENT -BEGIN - // nothing -END - -// this is for our custom DirectWrite-based font dialog (see fontdialog.cpp) -// this is based on the "New Font Dialog with Syslink" in Microsoft's font.dlg -// LONGTERM look at localization -// LONGTERM make it look tighter and nicer like the real one, including the actual heights of the font family and style comboboxes -rcFontDialog DIALOGEX 13, 54, 243, 200 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_3DLOOK -CAPTION "Font" -FONT 9, "Segoe UI" -BEGIN - LTEXT "&Font:", -1, 7, 7, 98, 9 - COMBOBOX rcFontFamilyCombobox, 7, 16, 98, 76, - CBS_SIMPLE | CBS_AUTOHSCROLL | CBS_DISABLENOSCROLL | - CBS_SORT | WS_VSCROLL | WS_TABSTOP | CBS_HASSTRINGS - - LTEXT "Font st&yle:", -1, 114, 7, 74, 9 - COMBOBOX rcFontStyleCombobox, 114, 16, 74, 76, - CBS_SIMPLE | CBS_AUTOHSCROLL | CBS_DISABLENOSCROLL | - WS_VSCROLL | WS_TABSTOP | CBS_HASSTRINGS - - LTEXT "&Size:", -1, 198, 7, 36, 9 - COMBOBOX rcFontSizeCombobox, 198, 16, 36, 76, - CBS_SIMPLE | CBS_AUTOHSCROLL | CBS_DISABLENOSCROLL | - CBS_SORT | WS_VSCROLL | WS_TABSTOP | CBS_HASSTRINGS - - GROUPBOX "Sample", -1, 7, 97, 227, 70, WS_GROUP - CTEXT "AaBbYyZz", rcFontSamplePlacement, 9, 106, 224, 60, SS_NOPREFIX | NOT WS_VISIBLE - - DEFPUSHBUTTON "OK", IDOK, 141, 181, 45, 14, WS_GROUP - PUSHBUTTON "Cancel", IDCANCEL, 190, 181, 45, 14, WS_GROUP -END - -rcColorDialog DIALOGEX 13, 54, 344, 209 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_3DLOOK -CAPTION "Color" -FONT 9, "Segoe UI" -BEGIN - // this size should be big enough to get at least 256x256 on font sizes >= 8 pt - CTEXT "AaBbYyZz", rcColorSVChooser, 7, 7, 195, 195, SS_NOPREFIX | SS_BLACKRECT - - // width is the suggested slider height since this is vertical - CTEXT "AaBbYyZz", rcColorHSlider, 206, 7, 15, 195, SS_NOPREFIX | SS_BLACKRECT - - LTEXT "Preview:", -1, 230, 7, 107, 9, SS_NOPREFIX - CTEXT "AaBbYyZz", rcPreview, 230, 16, 107, 20, SS_NOPREFIX | SS_BLACKRECT - - LTEXT "Opacity:", -1, 230, 45, 107, 9, SS_NOPREFIX - CTEXT "AaBbYyZz", rcOpacitySlider, 230, 54, 107, 15, SS_NOPREFIX | SS_BLACKRECT - - LTEXT "&H:", rcHLabel, 230, 81, 8, 8 - EDITTEXT rcH, 238, 78, 30, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE - LTEXT "&S:", rcSLabel, 230, 95, 8, 8 - EDITTEXT rcS, 238, 92, 30, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE - LTEXT "&V:", rcVLabel, 230, 109, 8, 8 - EDITTEXT rcV, 238, 106, 30, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE - - LTEXT "&R:", rcRLabel, 277, 81, 8, 8 - EDITTEXT rcRDouble, 285, 78, 30, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE - EDITTEXT rcRInt, 315, 78, 20, 14, ES_LEFT | ES_AUTOHSCROLL | ES_NUMBER | WS_TABSTOP, WS_EX_CLIENTEDGE - LTEXT "&G:", rcGLabel, 277, 95, 8, 8 - EDITTEXT rcGDouble, 285, 92, 30, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE - EDITTEXT rcGInt, 315, 92, 20, 14, ES_LEFT | ES_AUTOHSCROLL | ES_NUMBER | WS_TABSTOP, WS_EX_CLIENTEDGE - LTEXT "&B:", rcBLabel, 277, 109, 8, 8 - EDITTEXT rcBDouble, 285, 106, 30, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE - EDITTEXT rcBInt, 315, 106, 20, 14, ES_LEFT | ES_AUTOHSCROLL | ES_NUMBER | WS_TABSTOP, WS_EX_CLIENTEDGE - LTEXT "&A:", rcALabel, 277, 123, 8, 8 - EDITTEXT rcADouble, 285, 120, 30, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE - EDITTEXT rcAInt, 315, 120, 20, 14, ES_LEFT | ES_AUTOHSCROLL | ES_NUMBER | WS_TABSTOP, WS_EX_CLIENTEDGE - - LTEXT "He&x:", rcHexLabel, 269, 146, 16, 8 - EDITTEXT rcHex, 285, 143, 50, 14, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP, WS_EX_CLIENTEDGE - - DEFPUSHBUTTON "OK", IDOK, 243, 188, 45, 14, WS_GROUP - PUSHBUTTON "Cancel", IDCANCEL, 292, 188, 45, 14, WS_GROUP -END diff --git a/src/libui_sdl/libui/windows/separator.cpp b/src/libui_sdl/libui/windows/separator.cpp deleted file mode 100644 index e123e27..0000000 --- a/src/libui_sdl/libui/windows/separator.cpp +++ /dev/null @@ -1,69 +0,0 @@ -// 20 may 2015 -#include "uipriv_windows.hpp" - -// references: -// - http://stackoverflow.com/questions/2892703/how-do-i-draw-separators -// - https://msdn.microsoft.com/en-us/library/windows/desktop/dn742405%28v=vs.85%29.aspx - -struct uiSeparator { - uiWindowsControl c; - HWND hwnd; - BOOL vertical; -}; - -uiWindowsControlAllDefaults(uiSeparator) - -// via https://msdn.microsoft.com/en-us/library/windows/desktop/bb226818%28v=vs.85%29.aspx -#define separatorHeight 1 - -// TODO -#define separatorWidth 1 - -static void uiSeparatorMinimumSize(uiWindowsControl *c, int *width, int *height) -{ - uiSeparator *s = uiSeparator(c); - uiWindowsSizing sizing; - int x, y; - - *width = 1; // TODO - *height = 1; - x = separatorWidth; - y = separatorHeight; - uiWindowsGetSizing(s->hwnd, &sizing); - uiWindowsSizingDlgUnitsToPixels(&sizing, &x, &y); - if (s->vertical) - *width = x; - else - *height = y; -} - -uiSeparator *uiNewHorizontalSeparator(void) -{ - uiSeparator *s; - - uiWindowsNewControl(uiSeparator, s); - - s->hwnd = uiWindowsEnsureCreateControlHWND(0, - L"static", L"", - SS_ETCHEDHORZ, - hInstance, NULL, - TRUE); - - return s; -} - -uiSeparator *uiNewVerticalSeparator(void) -{ - uiSeparator *s; - - uiWindowsNewControl(uiSeparator, s); - - s->hwnd = uiWindowsEnsureCreateControlHWND(0, - L"static", L"", - SS_ETCHEDHORZ, - hInstance, NULL, - TRUE); - s->vertical = TRUE; - - return s; -} diff --git a/src/libui_sdl/libui/windows/sizing.cpp b/src/libui_sdl/libui/windows/sizing.cpp deleted file mode 100644 index a6d25d6..0000000 --- a/src/libui_sdl/libui/windows/sizing.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// 14 may 2015 -#include "uipriv_windows.hpp" - -// TODO rework the error handling -void getSizing(HWND hwnd, uiWindowsSizing *sizing, HFONT font) -{ - HDC dc; - HFONT prevfont; - TEXTMETRICW tm; - SIZE size; - - dc = GetDC(hwnd); - if (dc == NULL) - logLastError(L"error getting DC"); - prevfont = (HFONT) SelectObject(dc, font); - if (prevfont == NULL) - logLastError(L"error loading control font into device context"); - - ZeroMemory(&tm, sizeof (TEXTMETRICW)); - if (GetTextMetricsW(dc, &tm) == 0) - logLastError(L"error getting text metrics"); - if (GetTextExtentPoint32W(dc, L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 52, &size) == 0) - logLastError(L"error getting text extent point"); - - sizing->BaseX = (int) ((size.cx / 26 + 1) / 2); - sizing->BaseY = (int) tm.tmHeight; - sizing->InternalLeading = tm.tmInternalLeading; - - if (SelectObject(dc, prevfont) != font) - logLastError(L"error restoring previous font into device context"); - if (ReleaseDC(hwnd, dc) == 0) - logLastError(L"error releasing DC"); -} - -void uiWindowsGetSizing(HWND hwnd, uiWindowsSizing *sizing) -{ - return getSizing(hwnd, sizing, hMessageFont); -} - -#define dlgUnitsToX(dlg, baseX) MulDiv((dlg), (baseX), 4) -#define dlgUnitsToY(dlg, baseY) MulDiv((dlg), (baseY), 8) - -void uiWindowsSizingDlgUnitsToPixels(uiWindowsSizing *sizing, int *x, int *y) -{ - if (x != NULL) - *x = dlgUnitsToX(*x, sizing->BaseX); - if (y != NULL) - *y = dlgUnitsToY(*y, sizing->BaseY); -} - -// from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing and https://msdn.microsoft.com/en-us/library/windows/desktop/bb226818%28v=vs.85%29.aspx -// this X value is really only for buttons but I don't see a better one :/ -#define winXPadding 4 -#define winYPadding 4 - -void uiWindowsSizingStandardPadding(uiWindowsSizing *sizing, int *x, int *y) -{ - if (x != NULL) - *x = dlgUnitsToX(winXPadding, sizing->BaseX); - if (y != NULL) - *y = dlgUnitsToY(winYPadding, sizing->BaseY); -} diff --git a/src/libui_sdl/libui/windows/slider.cpp b/src/libui_sdl/libui/windows/slider.cpp deleted file mode 100644 index 5c671dd..0000000 --- a/src/libui_sdl/libui/windows/slider.cpp +++ /dev/null @@ -1,98 +0,0 @@ -// 20 may 2015 -#include "uipriv_windows.hpp" - -struct uiSlider { - uiWindowsControl c; - HWND hwnd; - void (*onChanged)(uiSlider *, void *); - void *onChangedData; -}; - -static BOOL onWM_HSCROLL(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult) -{ - uiSlider *s = uiSlider(c); - - (*(s->onChanged))(s, s->onChangedData); - *lResult = 0; - return TRUE; -} - -static void uiSliderDestroy(uiControl *c) -{ - uiSlider *s = uiSlider(c); - - uiWindowsUnregisterWM_HSCROLLHandler(s->hwnd); - uiWindowsEnsureDestroyWindow(s->hwnd); - uiFreeControl(uiControl(s)); -} - -uiWindowsControlAllDefaultsExceptDestroy(uiSlider); - -// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing -#define sliderWidth 107 /* this is actually the shorter progress bar width, but Microsoft doesn't indicate a width */ -#define sliderHeight 15 - -static void uiSliderMinimumSize(uiWindowsControl *c, int *width, int *height) -{ - uiSlider *s = uiSlider(c); - uiWindowsSizing sizing; - int x, y; - - x = sliderWidth; - y = sliderHeight; - uiWindowsGetSizing(s->hwnd, &sizing); - uiWindowsSizingDlgUnitsToPixels(&sizing, &x, &y); - *width = x; - *height = y; -} - -static void defaultOnChanged(uiSlider *s, void *data) -{ - // do nothing -} - -int uiSliderValue(uiSlider *s) -{ - return SendMessageW(s->hwnd, TBM_GETPOS, 0, 0); -} - -void uiSliderSetValue(uiSlider *s, int value) -{ - // don't use TBM_SETPOSNOTIFY; that triggers an event - SendMessageW(s->hwnd, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) value); -} - -void uiSliderOnChanged(uiSlider *s, void (*f)(uiSlider *, void *), void *data) -{ - s->onChanged = f; - s->onChangedData = data; -} - -uiSlider *uiNewSlider(int min, int max) -{ - uiSlider *s; - int temp; - - if (min >= max) { - temp = min; - min = max; - max = temp; - } - - uiWindowsNewControl(uiSlider, s); - - s->hwnd = uiWindowsEnsureCreateControlHWND(0, - TRACKBAR_CLASSW, L"", - TBS_HORZ | TBS_TOOLTIPS | TBS_TRANSPARENTBKGND | WS_TABSTOP, - hInstance, NULL, - TRUE); - - uiWindowsRegisterWM_HSCROLLHandler(s->hwnd, onWM_HSCROLL, uiControl(s)); - uiSliderOnChanged(s, defaultOnChanged, NULL); - - SendMessageW(s->hwnd, TBM_SETRANGEMIN, (WPARAM) TRUE, (LPARAM) min); - SendMessageW(s->hwnd, TBM_SETRANGEMAX, (WPARAM) TRUE, (LPARAM) max); - SendMessageW(s->hwnd, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) min); - - return s; -} diff --git a/src/libui_sdl/libui/windows/spinbox.cpp b/src/libui_sdl/libui/windows/spinbox.cpp deleted file mode 100644 index 2b6af66..0000000 --- a/src/libui_sdl/libui/windows/spinbox.cpp +++ /dev/null @@ -1,215 +0,0 @@ -// 8 april 2015 -#include "uipriv_windows.hpp" - -struct uiSpinbox { - uiWindowsControl c; - HWND hwnd; - HWND edit; - HWND updown; - void (*onChanged)(uiSpinbox *, void *); - void *onChangedData; - BOOL inhibitChanged; -}; - -// utility functions - -static int value(uiSpinbox *s) -{ - BOOL neededCap = FALSE; - LRESULT val; - - // This verifies the value put in, capping it automatically. - // We don't need to worry about checking for an error; that flag should really be called "did we have to cap?". - // We DO need to set the value in case of a cap though. - val = SendMessageW(s->updown, UDM_GETPOS32, 0, (LPARAM) (&neededCap)); - if (neededCap) { - s->inhibitChanged = TRUE; - SendMessageW(s->updown, UDM_SETPOS32, 0, (LPARAM) val); - s->inhibitChanged = FALSE; - } - return val; -} - -// control implementation - -static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult) -{ - uiSpinbox *s = (uiSpinbox *) c; - WCHAR *wtext; - - if (code != EN_CHANGE) - return FALSE; - if (s->inhibitChanged) - return FALSE; - // We want to allow typing negative numbers; the natural way to do so is to start with a -. - // However, if we just have the code below, the up-down will catch the bare - and reject it. - // Let's fix that. - // This won't handle leading spaces, but spaces aren't allowed *anyway*. - wtext = windowText(s->edit); - if (wcscmp(wtext, L"-") == 0) { - uiFree(wtext); - return TRUE; - } - uiFree(wtext); - // value() does the work for us - value(s); - (*(s->onChanged))(s, s->onChangedData); - return TRUE; -} - -static void uiSpinboxDestroy(uiControl *c) -{ - uiSpinbox *s = uiSpinbox(c); - - uiWindowsUnregisterWM_COMMANDHandler(s->edit); - uiWindowsEnsureDestroyWindow(s->updown); - uiWindowsEnsureDestroyWindow(s->edit); - uiWindowsEnsureDestroyWindow(s->hwnd); - uiFreeControl(uiControl(s)); -} - -// TODO SyncEnableState -uiWindowsControlAllDefaultsExceptDestroy(uiSpinbox) - -// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing -// TODO reduce this? -#define entryWidth 107 /* this is actually the shorter progress bar width, but Microsoft only indicates as wide as necessary */ -#define entryHeight 14 - -static void uiSpinboxMinimumSize(uiWindowsControl *c, int *width, int *height) -{ - uiSpinbox *s = uiSpinbox(c); - uiWindowsSizing sizing; - int x, y; - - x = entryWidth; - y = entryHeight; - // note that we go by the edit here - uiWindowsGetSizing(s->edit, &sizing); - uiWindowsSizingDlgUnitsToPixels(&sizing, &x, &y); - *width = x; - *height = y; -} - -static void spinboxArrangeChildren(uiSpinbox *s) -{ - LONG_PTR controlID; - HWND insertAfter; - - controlID = 100; - insertAfter = NULL; - uiWindowsEnsureAssignControlIDZOrder(s->edit, &controlID, &insertAfter); - uiWindowsEnsureAssignControlIDZOrder(s->updown, &controlID, &insertAfter); -} - -// an up-down control will only properly position itself the first time -// stupidly, there are no messages to force a size calculation, nor can I seem to reset the buddy window to force a new position -// alas, we have to make a new up/down control each time :( -static void recreateUpDown(uiSpinbox *s) -{ - BOOL preserve = FALSE; - int current; - // Microsoft's commctrl.h says to use this type - INT min, max; - - if (s->updown != NULL) { - preserve = TRUE; - current = value(s); - SendMessageW(s->updown, UDM_GETRANGE32, (WPARAM) (&min), (LPARAM) (&max)); - uiWindowsEnsureDestroyWindow(s->updown); - } - s->inhibitChanged = TRUE; - s->updown = CreateWindowExW(0, - UPDOWN_CLASSW, L"", - // no WS_VISIBLE; we set visibility ourselves - // up-down control should not be a tab stop - WS_CHILD | UDS_ALIGNRIGHT | UDS_ARROWKEYS | UDS_HOTTRACK | UDS_NOTHOUSANDS | UDS_SETBUDDYINT, - // this is important; it's necessary for autosizing to work - 0, 0, 0, 0, - s->hwnd, NULL, hInstance, NULL); - if (s->updown == NULL) - logLastError(L"error creating updown"); - SendMessageW(s->updown, UDM_SETBUDDY, (WPARAM) (s->edit), 0); - if (preserve) { - SendMessageW(s->updown, UDM_SETRANGE32, (WPARAM) min, (LPARAM) max); - SendMessageW(s->updown, UDM_SETPOS32, 0, (LPARAM) current); - } - // preserve the Z-order - spinboxArrangeChildren(s); - // TODO properly show/enable - ShowWindow(s->updown, SW_SHOW); - s->inhibitChanged = FALSE; -} - -static void spinboxRelayout(uiSpinbox *s) -{ - RECT r; - - // make the edit fill the container first; the new updown will resize it - uiWindowsEnsureGetClientRect(s->hwnd, &r); - uiWindowsEnsureMoveWindowDuringResize(s->edit, r.left, r.top, r.right - r.left, r.bottom - r.top); - recreateUpDown(s); -} - -static void defaultOnChanged(uiSpinbox *s, void *data) -{ - // do nothing -} - -int uiSpinboxValue(uiSpinbox *s) -{ - return value(s); -} - -void uiSpinboxSetValue(uiSpinbox *s, int value) -{ - s->inhibitChanged = TRUE; - SendMessageW(s->updown, UDM_SETPOS32, 0, (LPARAM) value); - s->inhibitChanged = FALSE; -} - -void uiSpinboxOnChanged(uiSpinbox *s, void (*f)(uiSpinbox *, void *), void *data) -{ - s->onChanged = f; - s->onChangedData = data; -} - -static void onResize(uiWindowsControl *c) -{ - spinboxRelayout(uiSpinbox(c)); -} - -uiSpinbox *uiNewSpinbox(int min, int max) -{ - uiSpinbox *s; - int temp; - - if (min >= max) { - temp = min; - min = max; - max = temp; - } - - uiWindowsNewControl(uiSpinbox, s); - - s->hwnd = uiWindowsMakeContainer(uiWindowsControl(s), onResize); - - s->edit = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE, - L"edit", L"", - // don't use ES_NUMBER; it doesn't allow typing in a leading - - ES_AUTOHSCROLL | ES_LEFT | ES_NOHIDESEL | WS_TABSTOP, - hInstance, NULL, - TRUE); - uiWindowsEnsureSetParentHWND(s->edit, s->hwnd); - - uiWindowsRegisterWM_COMMANDHandler(s->edit, onWM_COMMAND, uiControl(s)); - uiSpinboxOnChanged(s, defaultOnChanged, NULL); - - recreateUpDown(s); - s->inhibitChanged = TRUE; - SendMessageW(s->updown, UDM_SETRANGE32, (WPARAM) min, (LPARAM) max); - SendMessageW(s->updown, UDM_SETPOS32, 0, (LPARAM) min); - s->inhibitChanged = FALSE; - - return s; -} diff --git a/src/libui_sdl/libui/windows/stddialogs.cpp b/src/libui_sdl/libui/windows/stddialogs.cpp deleted file mode 100644 index d0fd506..0000000 --- a/src/libui_sdl/libui/windows/stddialogs.cpp +++ /dev/null @@ -1,167 +0,0 @@ -// 22 may 2015 -#include "uipriv_windows.hpp" - -// TODO document all this is what we want -// TODO do the same for font and color buttons - -// notes: -// - FOS_SUPPORTSTREAMABLEITEMS doesn't seem to be supported on windows vista, or at least not with the flags we use -// - even with FOS_NOVALIDATE the dialogs will reject invalid filenames (at least on Vista, anyway) -// - lack of FOS_NOREADONLYRETURN doesn't seem to matter on Windows 7 - -// TODO -// - http://blogs.msdn.com/b/wpfsdk/archive/2006/10/26/uncommon-dialogs--font-chooser-and-color-picker-dialogs.aspx -// - when a dialog is active, tab navigation in other windows stops working -// - when adding uiOpenFolder(), use IFileDialog as well - https://msdn.microsoft.com/en-us/library/windows/desktop/bb762115%28v=vs.85%29.aspx - -#define windowHWND(w) (w ? (HWND) uiControlHandle(uiControl(w)) : NULL) - -char *commonItemDialog(HWND parent, REFCLSID clsid, REFIID iid, const char* filter, const char* initpath, FILEOPENDIALOGOPTIONS optsadd) -{ - IFileDialog *d = NULL; - FILEOPENDIALOGOPTIONS opts; - IShellItem *result = NULL; - WCHAR *wname = NULL; - char *name = NULL; - HRESULT hr; - - hr = CoCreateInstance(clsid, - NULL, CLSCTX_INPROC_SERVER, - iid, (LPVOID *) (&d)); - if (hr != S_OK) { - logHRESULT(L"error creating common item dialog", hr); - // always return NULL on error - goto out; - } - hr = d->GetOptions(&opts); - if (hr != S_OK) { - logHRESULT(L"error getting current options", hr); - goto out; - } - opts |= optsadd; - // the other platforms don't check read-only; we won't either - opts &= ~FOS_NOREADONLYRETURN; - hr = d->SetOptions(opts); - if (hr != S_OK) { - logHRESULT(L"error setting options", hr); - goto out; - } - - // filters - { - COMDLG_FILTERSPEC filterspec[8]; - wchar_t _filter[256]; - wchar_t* fp = &_filter[0]; int s = 0; - wchar_t* fname; - for (int i = 0; i < 255; i++) - { - if (filter[i] == '|' || filter[i] == '\0') - { - _filter[i] = '\0'; - if (s & 1) - { - filterspec[s>>1].pszName = fname; - filterspec[s>>1].pszSpec = fp; - } - else - { - fname = fp; - } - fp = &_filter[i+1]; - s++; - if (s >= 8) break; - if (filter[i] == '\0') break; - } - else - _filter[i] = filter[i]; - } - d->SetFileTypes(s>>1, filterspec); - } - - hr = d->Show(parent); - if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)) - // cancelled; return NULL like we have ready - goto out; - if (hr != S_OK) { - logHRESULT(L"error showing dialog", hr); - goto out; - } - hr = d->GetResult(&result); - if (hr != S_OK) { - logHRESULT(L"error getting dialog result", hr); - goto out; - } - hr = result->GetDisplayName(SIGDN_FILESYSPATH, &wname); - if (hr != S_OK) { - logHRESULT(L"error getting filename", hr); - goto out; - } - name = toUTF8(wname); - -out: - if (wname != NULL) - CoTaskMemFree(wname); - if (result != NULL) - result->Release(); - if (d != NULL) - d->Release(); - return name; -} - -char *uiOpenFile(uiWindow *parent, const char* filter, const char* initpath) -{ - char *res; - - disableAllWindowsExcept(parent); - res = commonItemDialog(windowHWND(parent), - CLSID_FileOpenDialog, IID_IFileOpenDialog, - filter, initpath, - FOS_NOCHANGEDIR | FOS_FORCEFILESYSTEM | FOS_NOVALIDATE | FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE); - enableAllWindowsExcept(parent); - return res; -} - -char *uiSaveFile(uiWindow *parent, const char* filter, const char* initpath) -{ - char *res; - - disableAllWindowsExcept(parent); - res = commonItemDialog(windowHWND(parent), - CLSID_FileSaveDialog, IID_IFileSaveDialog, - filter, initpath, - FOS_OVERWRITEPROMPT | FOS_NOCHANGEDIR | FOS_FORCEFILESYSTEM | FOS_NOVALIDATE | FOS_SHAREAWARE | FOS_NOTESTFILECREATE | FOS_FORCESHOWHIDDEN | FOS_DEFAULTNOMINIMODE); - enableAllWindowsExcept(parent); - return res; -} - -// TODO switch to TaskDialogIndirect()? - -static void msgbox(HWND parent, const char *title, const char *description, TASKDIALOG_COMMON_BUTTON_FLAGS buttons, PCWSTR icon) -{ - WCHAR *wtitle, *wdescription; - HRESULT hr; - - wtitle = toUTF16(title); - wdescription = toUTF16(description); - - hr = TaskDialog(parent, NULL, NULL, wtitle, wdescription, buttons, icon, NULL); - if (hr != S_OK) - logHRESULT(L"error showing task dialog", hr); - - uiFree(wdescription); - uiFree(wtitle); -} - -void uiMsgBox(uiWindow *parent, const char *title, const char *description) -{ - disableAllWindowsExcept(parent); - msgbox(windowHWND(parent), title, description, TDCBF_OK_BUTTON, NULL); - enableAllWindowsExcept(parent); -} - -void uiMsgBoxError(uiWindow *parent, const char *title, const char *description) -{ - disableAllWindowsExcept(parent); - msgbox(windowHWND(parent), title, description, TDCBF_OK_BUTTON, TD_ERROR_ICON); - enableAllWindowsExcept(parent); -} diff --git a/src/libui_sdl/libui/windows/tab.cpp b/src/libui_sdl/libui/windows/tab.cpp deleted file mode 100644 index 93373b0..0000000 --- a/src/libui_sdl/libui/windows/tab.cpp +++ /dev/null @@ -1,294 +0,0 @@ -// 16 may 2015 -#include "uipriv_windows.hpp" - -// You don't add controls directly to a tab control on Windows; instead you make them siblings and swap between them on a TCN_SELCHANGING/TCN_SELCHANGE notification pair. -// In addition, you use dialogs because they can be textured properly; other controls cannot. (Things will look wrong if the tab background in the current theme is fancy if you just use the tab background by itself; see http://stackoverflow.com/questions/30087540/why-are-my-programss-tab-controls-rendering-their-background-in-a-blocky-way-b.) - -struct uiTab { - uiWindowsControl c; - HWND hwnd; // of the outer container - HWND tabHWND; // of the tab control itself - std::vector *pages; - HWND parent; -}; - -// utility functions - -static LRESULT curpage(uiTab *t) -{ - return SendMessageW(t->tabHWND, TCM_GETCURSEL, 0, 0); -} - -static struct tabPage *tabPage(uiTab *t, int i) -{ - return (*(t->pages))[i]; -} - -static void tabPageRect(uiTab *t, RECT *r) -{ - // this rect needs to be in parent window coordinates, but TCM_ADJUSTRECT wants a window rect, which is screen coordinates - // because we have each page as a sibling of the tab, use the tab's own rect as the input rect - uiWindowsEnsureGetWindowRect(t->tabHWND, r); - SendMessageW(t->tabHWND, TCM_ADJUSTRECT, (WPARAM) FALSE, (LPARAM) r); - // and get it in terms of the container instead of the screen - mapWindowRect(NULL, t->hwnd, r); -} - -static void tabRelayout(uiTab *t) -{ - struct tabPage *page; - RECT r; - - // first move the tab control itself - uiWindowsEnsureGetClientRect(t->hwnd, &r); - uiWindowsEnsureMoveWindowDuringResize(t->tabHWND, r.left, r.top, r.right - r.left, r.bottom - r.top); - - // then the current page - if (t->pages->size() == 0) - return; - page = tabPage(t, curpage(t)); - tabPageRect(t, &r); - uiWindowsEnsureMoveWindowDuringResize(page->hwnd, r.left, r.top, r.right - r.left, r.bottom - r.top); -} - -static void showHidePage(uiTab *t, LRESULT which, int hide) -{ - struct tabPage *page; - - if (which == (LRESULT) (-1)) - return; - page = tabPage(t, which); - if (hide) - ShowWindow(page->hwnd, SW_HIDE); - else { - ShowWindow(page->hwnd, SW_SHOW); - // we only resize the current page, so we have to resize it; before we can do that, we need to make sure we are of the right size - uiWindowsControlMinimumSizeChanged(uiWindowsControl(t)); - } -} - -// control implementation - -static BOOL onWM_NOTIFY(uiControl *c, HWND hwnd, NMHDR *nm, LRESULT *lResult) -{ - uiTab *t = uiTab(c); - - if (nm->code != TCN_SELCHANGING && nm->code != TCN_SELCHANGE) - return FALSE; - showHidePage(t, curpage(t), nm->code == TCN_SELCHANGING); - *lResult = 0; - if (nm->code == TCN_SELCHANGING) - *lResult = FALSE; - return TRUE; -} - -static void uiTabDestroy(uiControl *c) -{ - uiTab *t = uiTab(c); - uiControl *child; - - for (struct tabPage *&page : *(t->pages)) { - child = page->child; - tabPageDestroy(page); - if (child != NULL) { - uiControlSetParent(child, NULL); - uiControlDestroy(child); - } - } - delete t->pages; - uiWindowsUnregisterWM_NOTIFYHandler(t->tabHWND); - uiWindowsEnsureDestroyWindow(t->tabHWND); - uiWindowsEnsureDestroyWindow(t->hwnd); - uiFreeControl(uiControl(t)); -} - -uiWindowsControlDefaultHandle(uiTab) -uiWindowsControlDefaultParent(uiTab) -uiWindowsControlDefaultSetParent(uiTab) -uiWindowsControlDefaultToplevel(uiTab) -uiWindowsControlDefaultVisible(uiTab) -uiWindowsControlDefaultShow(uiTab) -uiWindowsControlDefaultHide(uiTab) -uiWindowsControlDefaultEnabled(uiTab) -uiWindowsControlDefaultEnable(uiTab) -uiWindowsControlDefaultDisable(uiTab) -uiWindowsControlDefaultSetFocus(uiTab) - -static void uiTabSyncEnableState(uiWindowsControl *c, int enabled) -{ - uiTab *t = uiTab(c); - - if (uiWindowsShouldStopSyncEnableState(uiWindowsControl(t), enabled)) - return; - EnableWindow(t->tabHWND, enabled); - for (struct tabPage *&page : *(t->pages)) - if (page->child != NULL) - uiWindowsControlSyncEnableState(uiWindowsControl(page->child), enabled); -} - -uiWindowsControlDefaultSetParentHWND(uiTab) - -static void uiTabMinimumSize(uiWindowsControl *c, int *width, int *height) -{ - uiTab *t = uiTab(c); - int pagewid, pageht; - struct tabPage *page; - RECT r; - - // only consider the current page - pagewid = 0; - pageht = 0; - if (t->pages->size() != 0) { - page = tabPage(t, curpage(t)); - tabPageMinimumSize(page, &pagewid, &pageht); - } - - r.left = 0; - r.top = 0; - r.right = pagewid; - r.bottom = pageht; - // this also includes the tabs themselves - SendMessageW(t->tabHWND, TCM_ADJUSTRECT, (WPARAM) TRUE, (LPARAM) (&r)); - *width = r.right - r.left; - *height = r.bottom - r.top; -} - -static void uiTabMinimumSizeChanged(uiWindowsControl *c) -{ - uiTab *t = uiTab(c); - - if (uiWindowsControlTooSmall(uiWindowsControl(t))) { - uiWindowsControlContinueMinimumSizeChanged(uiWindowsControl(t)); - return; - } - tabRelayout(t); -} - -static void uiTabSetMinSize(uiControl *c, int w, int h) -{ - // checkme - uiTabMinimumSizeChanged(uiWindowsControl(c)); -} - -uiWindowsControlDefaultLayoutRect(uiTab) -uiWindowsControlDefaultAssignControlIDZOrder(uiTab) - -static void uiTabChildVisibilityChanged(uiWindowsControl *c) -{ - // TODO eliminate the redundancy - uiWindowsControlMinimumSizeChanged(c); -} - -static void tabArrangePages(uiTab *t) -{ - LONG_PTR controlID = 100; - HWND insertAfter = NULL; - - // TODO is this first or last? - uiWindowsEnsureAssignControlIDZOrder(t->tabHWND, &controlID, &insertAfter); - for (struct tabPage *&page : *(t->pages)) - uiWindowsEnsureAssignControlIDZOrder(page->hwnd, &controlID, &insertAfter); -} - -void uiTabAppend(uiTab *t, const char *name, uiControl *child) -{ - uiTabInsertAt(t, name, t->pages->size(), child); -} - -void uiTabInsertAt(uiTab *t, const char *name, int n, uiControl *child) -{ - struct tabPage *page; - LRESULT hide, show; - TCITEMW item; - WCHAR *wname; - - // see below - hide = curpage(t); - - if (child != NULL) - uiControlSetParent(child, uiControl(t)); - - page = newTabPage(child); - uiWindowsEnsureSetParentHWND(page->hwnd, t->hwnd); - t->pages->insert(t->pages->begin() + n, page); - tabArrangePages(t); - - ZeroMemory(&item, sizeof (TCITEMW)); - item.mask = TCIF_TEXT; - wname = toUTF16(name); - item.pszText = wname; - if (SendMessageW(t->tabHWND, TCM_INSERTITEM, (WPARAM) n, (LPARAM) (&item)) == (LRESULT) -1) - logLastError(L"error adding tab to uiTab"); - uiFree(wname); - - // we need to do this because adding the first tab doesn't send a TCN_SELCHANGE; it just shows the page - show = curpage(t); - if (show != hide) { - showHidePage(t, hide, 1); - showHidePage(t, show, 0); - } -} - -void uiTabDelete(uiTab *t, int n) -{ - struct tabPage *page; - - // first delete the tab from the tab control - // if this is the current tab, no tab will be selected, which is good - if (SendMessageW(t->tabHWND, TCM_DELETEITEM, (WPARAM) n, 0) == FALSE) - logLastError(L"error deleting uiTab tab"); - - // now delete the page itself - page = tabPage(t, n); - if (page->child != NULL) - uiControlSetParent(page->child, NULL); - tabPageDestroy(page); - t->pages->erase(t->pages->begin() + n); -} - -int uiTabNumPages(uiTab *t) -{ - return t->pages->size(); -} - -int uiTabMargined(uiTab *t, int n) -{ - return tabPage(t, n)->margined; -} - -void uiTabSetMargined(uiTab *t, int n, int margined) -{ - struct tabPage *page; - - page = tabPage(t, n); - page->margined = margined; - // even if the page doesn't have a child it might still have a new minimum size with margins; this is the easiest way to verify it - uiWindowsControlMinimumSizeChanged(uiWindowsControl(t)); -} - -static void onResize(uiWindowsControl *c) -{ - tabRelayout(uiTab(c)); -} - -uiTab *uiNewTab(void) -{ - uiTab *t; - - uiWindowsNewControl(uiTab, t); - - t->hwnd = uiWindowsMakeContainer(uiWindowsControl(t), onResize); - - t->tabHWND = uiWindowsEnsureCreateControlHWND(0, - WC_TABCONTROLW, L"", - TCS_TOOLTIPS | WS_TABSTOP, - hInstance, NULL, - TRUE); - uiWindowsEnsureSetParentHWND(t->tabHWND, t->hwnd); - - uiWindowsRegisterWM_NOTIFYHandler(t->tabHWND, onWM_NOTIFY, uiControl(t)); - - t->pages = new std::vector; - - return t; -} diff --git a/src/libui_sdl/libui/windows/tabpage.cpp b/src/libui_sdl/libui/windows/tabpage.cpp deleted file mode 100644 index 5283ce7..0000000 --- a/src/libui_sdl/libui/windows/tabpage.cpp +++ /dev/null @@ -1,131 +0,0 @@ -// 30 may 2015 -#include "uipriv_windows.hpp" - -// TODO refine error handling - -// from http://msdn.microsoft.com/en-us/library/windows/desktop/bb226818%28v=vs.85%29.aspx -#define tabMargin 7 - -static void tabPageMargins(struct tabPage *tp, int *mx, int *my) -{ - uiWindowsSizing sizing; - - *mx = 0; - *my = 0; - if (!tp->margined) - return; - uiWindowsGetSizing(tp->hwnd, &sizing); - *mx = tabMargin; - *my = tabMargin; - uiWindowsSizingDlgUnitsToPixels(&sizing, mx, my); -} - -static void tabPageRelayout(struct tabPage *tp) -{ - RECT r; - int mx, my; - HWND child; - - if (tp->child == NULL) - return; - uiWindowsEnsureGetClientRect(tp->hwnd, &r); - tabPageMargins(tp, &mx, &my); - r.left += mx; - r.top += my; - r.right -= mx; - r.bottom -= my; - child = (HWND) uiControlHandle(tp->child); - uiWindowsEnsureMoveWindowDuringResize(child, r.left, r.top, r.right - r.left, r.bottom - r.top); -} - -// dummy dialog procedure; see below for details -// let's handle parent messages here to avoid needing to subclass -// TODO do we need to handle DM_GETDEFID/DM_SETDEFID here too because of the ES_WANTRETURN stuff at http://blogs.msdn.com/b/oldnewthing/archive/2007/08/20/4470527.aspx? what about multiple default buttons (TODO)? -// TODO we definitely need to do something about edit message handling; it does a fake close of our parent on pressing escape, causing uiWindow to stop responding to maximizes but still respond to events and then die horribly on destruction -static INT_PTR CALLBACK dlgproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - struct tabPage *tp; - LRESULT lResult; - - if (uMsg == WM_INITDIALOG) { - tp = (struct tabPage *) lParam; - tp->hwnd = hwnd; - SetWindowLongPtrW(hwnd, DWLP_USER, (LONG_PTR) tp); - return TRUE; - } - if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE) { - SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (LONG_PTR) lResult); - return TRUE; - } - if (uMsg == WM_WINDOWPOSCHANGED) { - tp = (struct tabPage *) GetWindowLongPtrW(hwnd, DWLP_USER); - tabPageRelayout(tp); - // pretend the dialog hasn't handled this just in case it needs to do something special - return FALSE; - } - - // unthemed dialogs don't respond to WM_PRINTCLIENT - // fortunately they don't have any special painting - if (uMsg == WM_PRINTCLIENT) { - // don't worry about the return value; hopefully DefWindowProcW() caught it (if not the dialog procedure itself) - // we COULD paint the dialog background brush ourselves but meh, it works - SendMessageW(hwnd, WM_ERASEBKGND, wParam, lParam); - // and pretend we did nothing just so the themed dialog can still paint its content - // TODO see if w ecan avoid erasing the background in this case in the first place, or if we even need to - return FALSE; - } - - return FALSE; -} - -struct tabPage *newTabPage(uiControl *child) -{ - struct tabPage *tp; - HRESULT hr; - - tp = uiNew(struct tabPage); - - // unfortunately this needs to be a proper dialog for EnableThemeDialogTexture() to work; CreateWindowExW() won't suffice - if (CreateDialogParamW(hInstance, MAKEINTRESOURCE(rcTabPageDialog), - utilWindow, dlgproc, (LPARAM) tp) == NULL) - logLastError(L"error creating tab page"); - - tp->child = child; - if (tp->child != NULL) { - uiWindowsEnsureSetParentHWND((HWND) uiControlHandle(tp->child), tp->hwnd); - uiWindowsControlAssignSoleControlIDZOrder(uiWindowsControl(tp->child)); - } - - hr = EnableThemeDialogTexture(tp->hwnd, ETDT_ENABLE | ETDT_USETABTEXTURE | ETDT_ENABLETAB); - if (hr != S_OK) - logHRESULT(L"error setting tab page background", hr); - // continue anyway; it'll look wrong but eh - - // and start the tab page hidden - ShowWindow(tp->hwnd, SW_HIDE); - - return tp; -} - -void tabPageDestroy(struct tabPage *tp) -{ - // don't destroy the child with the page - if (tp->child != NULL) - uiWindowsControlSetParentHWND(uiWindowsControl(tp->child), NULL); - // don't call EndDialog(); that's for the DialogBox() family of functions instead of CreateDialog() - uiWindowsEnsureDestroyWindow(tp->hwnd); - uiFree(tp); -} - -void tabPageMinimumSize(struct tabPage *tp, int *width, int *height) -{ - int mx, my; - - *width = 0; - *height = 0; - if (tp->child != NULL) - uiWindowsControlMinimumSize(uiWindowsControl(tp->child), width, height); - tabPageMargins(tp, &mx, &my); - *width += 2 * mx; - *height += 2 * my; -} diff --git a/src/libui_sdl/libui/windows/text.cpp b/src/libui_sdl/libui/windows/text.cpp deleted file mode 100644 index a52af10..0000000 --- a/src/libui_sdl/libui/windows/text.cpp +++ /dev/null @@ -1,106 +0,0 @@ -// 9 april 2015 -#include "uipriv_windows.hpp" - -WCHAR *windowTextAndLen(HWND hwnd, LRESULT *len) -{ - LRESULT n; - WCHAR *text; - - n = SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0); - if (len != NULL) - *len = n; - // WM_GETTEXTLENGTH does not include the null terminator - text = (WCHAR *) uiAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]"); - // note the comparison: the size includes the null terminator, but the return does not - if (GetWindowTextW(hwnd, text, n + 1) != n) { - logLastError(L"error getting window text"); - // on error, return an empty string to be safe - *text = L'\0'; - if (len != NULL) - *len = 0; - } - return text; -} - -WCHAR *windowText(HWND hwnd) -{ - return windowTextAndLen(hwnd, NULL); -} - -void setWindowText(HWND hwnd, WCHAR *wtext) -{ - SetWindowTextW(hwnd, wtext); -} - -void uiFreeText(char *text) -{ - uiFree(text); -} - -int uiWindowsWindowTextWidth(HWND hwnd) -{ - LRESULT len; - WCHAR *text; - HDC dc; - HFONT prevfont; - SIZE size; - - size.cx = 0; - size.cy = 0; - - text = windowTextAndLen(hwnd, &len); - if (len == 0) // no text; nothing to do - goto noTextOrError; - - // now we can do the calculations - dc = GetDC(hwnd); - if (dc == NULL) { - logLastError(L"error getting DC"); - // on any error, assume no text - goto noTextOrError; - } - prevfont = (HFONT) SelectObject(dc, hMessageFont); - if (prevfont == NULL) { - logLastError(L"error loading control font into device context"); - ReleaseDC(hwnd, dc); - goto noTextOrError; - } - if (GetTextExtentPoint32W(dc, text, len, &size) == 0) { - logLastError(L"error getting text extent point"); - // continue anyway, assuming size is 0 - size.cx = 0; - size.cy = 0; - } - // continue on errors; we got what we want - if (SelectObject(dc, prevfont) != hMessageFont) - logLastError(L"error restoring previous font into device context"); - if (ReleaseDC(hwnd, dc) == 0) - logLastError(L"error releasing DC"); - - uiFree(text); - return size.cx; - -noTextOrError: - uiFree(text); - return 0; -} - -char *uiWindowsWindowText(HWND hwnd) -{ - WCHAR *wtext; - char *text; - - wtext = windowText(hwnd); - text = toUTF8(wtext); - uiFree(wtext); - return text; -} - -void uiWindowsSetWindowText(HWND hwnd, const char *text) -{ - WCHAR *wtext; - - wtext = toUTF16(text); - setWindowText(hwnd, wtext); - uiFree(wtext); -} diff --git a/src/libui_sdl/libui/windows/uipriv_windows.hpp b/src/libui_sdl/libui/windows/uipriv_windows.hpp deleted file mode 100644 index 6ffe09f..0000000 --- a/src/libui_sdl/libui/windows/uipriv_windows.hpp +++ /dev/null @@ -1,164 +0,0 @@ -// 21 april 2016 -#include "winapi.hpp" -#include "../ui.h" -#include "../ui_windows.h" -#include "../common/uipriv.h" -#include "resources.hpp" -#include "compilerver.hpp" - -// ui internal window messages -enum { - // redirected WM_COMMAND and WM_NOTIFY - msgCOMMAND = WM_APP + 0x40, // start offset just to be safe - msgNOTIFY, - msgHSCROLL, - msgQueued, - msgD2DScratchPaint, - msgD2DScratchLButtonDown, -}; - -// alloc.cpp -extern void initAlloc(void); -extern void uninitAlloc(void); - -// events.cpp -extern BOOL runWM_COMMAND(WPARAM wParam, LPARAM lParam, LRESULT *lResult); -extern BOOL runWM_NOTIFY(WPARAM wParam, LPARAM lParam, LRESULT *lResult); -extern BOOL runWM_HSCROLL(WPARAM wParam, LPARAM lParam, LRESULT *lResult); -extern void issueWM_WININICHANGE(WPARAM wParam, LPARAM lParam); - -// utf16.cpp -#define emptyUTF16() ((WCHAR *) uiAlloc(1 * sizeof (WCHAR), "WCHAR[]")) -#define emptyUTF8() ((char *) uiAlloc(1 * sizeof (char), "char[]")) -extern WCHAR *toUTF16(const char *str); -extern char *toUTF8(const WCHAR *wstr); -extern WCHAR *utf16dup(const WCHAR *orig); -extern WCHAR *strf(const WCHAR *format, ...); -extern WCHAR *vstrf(const WCHAR *format, va_list ap); -extern char *LFtoCRLF(const char *lfonly); -extern void CRLFtoLF(char *s); -extern WCHAR *ftoutf16(double d); -extern WCHAR *itoutf16(int i); - -// debug.cpp -// see http://stackoverflow.com/questions/14421656/is-there-widely-available-wide-character-variant-of-file -// we turn __LINE__ into a string because PRIiMAX can't be converted to a wide string in MSVC (it seems to be defined as "ll" "i" according to the compiler errors) -// also note the use of __FUNCTION__ here; __func__ doesn't seem to work for some reason -#define _ws2(m) L ## m -#define _ws(m) _ws2(m) -#define _ws2n(m) L ## #m -#define _wsn(m) _ws2n(m) -#define debugargs const WCHAR *file, const WCHAR *line, const WCHAR *func -extern HRESULT _logLastError(debugargs, const WCHAR *s); -#ifdef _MSC_VER -#define logLastError(s) _logLastError(_ws(__FILE__), _wsn(__LINE__), _ws(__FUNCTION__), s) -#else -#define logLastError(s) _logLastError(_ws(__FILE__), _wsn(__LINE__), L"TODO none of the function name macros are macros in MinGW", s) -#endif -extern HRESULT _logHRESULT(debugargs, const WCHAR *s, HRESULT hr); -#ifdef _MSC_VER -#define logHRESULT(s, hr) _logHRESULT(_ws(__FILE__), _wsn(__LINE__), _ws(__FUNCTION__), s, hr) -#else -#define logHRESULT(s, hr) _logHRESULT(_ws(__FILE__), _wsn(__LINE__), L"TODO none of the function name macros are macros in MinGW", s, hr) -#endif - -// winutil.cpp -extern int windowClassOf(HWND hwnd, ...); -extern void mapWindowRect(HWND from, HWND to, RECT *r); -extern DWORD getStyle(HWND hwnd); -extern void setStyle(HWND hwnd, DWORD style); -extern DWORD getExStyle(HWND hwnd); -extern void setExStyle(HWND hwnd, DWORD exstyle); -extern void clientSizeToWindowSize(HWND hwnd, int *width, int *height, BOOL hasMenubar); -extern HWND parentOf(HWND child); -extern HWND parentToplevel(HWND child); -extern void setWindowInsertAfter(HWND hwnd, HWND insertAfter); -extern HWND getDlgItem(HWND hwnd, int id); -extern void invalidateRect(HWND hwnd, RECT *r, BOOL erase); - -// text.cpp -extern WCHAR *windowTextAndLen(HWND hwnd, LRESULT *len); -extern WCHAR *windowText(HWND hwnd); -extern void setWindowText(HWND hwnd, WCHAR *wtext); - -// init.cpp -extern HINSTANCE hInstance; -extern int nCmdShow; -extern HFONT hMessageFont; -extern HBRUSH hollowBrush; -extern uiInitOptions options; - -// utilwin.cpp -extern HWND utilWindow; -extern const char *initUtilWindow(HICON hDefaultIcon, HCURSOR hDefaultCursor); -extern void uninitUtilWindow(void); - -// main.cpp -extern int registerMessageFilter(void); -extern void unregisterMessageFilter(void); - -// parent.cpp -extern void paintContainerBackground(HWND hwnd, HDC dc, RECT *paintRect); -extern BOOL handleParentMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult); - -// d2dscratch.cpp -extern ATOM registerD2DScratchClass(HICON hDefaultIcon, HCURSOR hDefaultCursor); -extern void unregisterD2DScratchClass(void); -extern HWND newD2DScratch(HWND parent, RECT *rect, HMENU controlID, SUBCLASSPROC subclass, DWORD_PTR subclassData); - -// area.cpp -#define areaClass L"libui_uiAreaClass" -extern ATOM registerAreaClass(HICON, HCURSOR); -extern void unregisterArea(void); - -// areaevents.cpp -extern BOOL areaFilter(MSG *); - -// window.cpp -extern ATOM registerWindowClass(HICON, HCURSOR); -extern void unregisterWindowClass(void); -extern void ensureMinimumWindowSize(uiWindow *); -extern void disableAllWindowsExcept(uiWindow *which); -extern void enableAllWindowsExcept(uiWindow *which); - -// container.cpp -#define containerClass L"libui_uiContainerClass" -extern ATOM initContainer(HICON, HCURSOR); -extern void uninitContainer(void); - -// tabpage.cpp -struct tabPage { - HWND hwnd; - uiControl *child; - BOOL margined; -}; -extern struct tabPage *newTabPage(uiControl *child); -extern void tabPageDestroy(struct tabPage *tp); -extern void tabPageMinimumSize(struct tabPage *tp, int *width, int *height); - -// colordialog.cpp -struct colorDialogRGBA { - double r; - double g; - double b; - double a; -}; -extern BOOL showColorDialog(HWND parent, struct colorDialogRGBA *c); - -// sizing.cpp -extern void getSizing(HWND hwnd, uiWindowsSizing *sizing, HFONT font); - -// graphemes.cpp -extern size_t *graphemes(WCHAR *msg); - -// TODO move into a dedicated file abibugs.cpp when we rewrite the drawing code -extern D2D1_SIZE_F realGetSize(ID2D1RenderTarget *rt); - - - - -// TODO -#include "_uipriv_migrate.hpp" - -// draw.cpp -extern ID2D1DCRenderTarget *makeHDCRenderTarget(HDC dc, RECT *r); diff --git a/src/libui_sdl/libui/windows/utf16.cpp b/src/libui_sdl/libui/windows/utf16.cpp deleted file mode 100644 index 98954d0..0000000 --- a/src/libui_sdl/libui/windows/utf16.cpp +++ /dev/null @@ -1,153 +0,0 @@ -// 21 april 2016 -#include "uipriv_windows.hpp" - -// see http://stackoverflow.com/a/29556509/3408572 - -#define MBTWC(str, wstr, bufsiz) MultiByteToWideChar(CP_UTF8, 0, str, -1, wstr, bufsiz) - -WCHAR *toUTF16(const char *str) -{ - WCHAR *wstr; - int n; - - if (*str == '\0') // empty string - return emptyUTF16(); - n = MBTWC(str, NULL, 0); - if (n == 0) { - logLastError(L"error figuring out number of characters to convert to"); - return emptyUTF16(); - } - wstr = (WCHAR *) uiAlloc(n * sizeof (WCHAR), "WCHAR[]"); - if (MBTWC(str, wstr, n) != n) { - logLastError(L"error converting from UTF-8 to UTF-16"); - // and return an empty string - *wstr = L'\0'; - } - return wstr; -} - -#define WCTMB(wstr, str, bufsiz) WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, bufsiz, NULL, NULL) - -char *toUTF8(const WCHAR *wstr) -{ - char *str; - int n; - - if (*wstr == L'\0') // empty string - return emptyUTF8(); - n = WCTMB(wstr, NULL, 0); - if (n == 0) { - logLastError(L"error figuring out number of characters to convert to"); - return emptyUTF8(); - } - str = (char *) uiAlloc(n * sizeof (char), "char[]"); - if (WCTMB(wstr, str, n) != n) { - logLastError(L"error converting from UTF-16 to UTF-8"); - // and return an empty string - *str = '\0'; - } - return str; -} - -WCHAR *utf16dup(const WCHAR *orig) -{ - WCHAR *out; - size_t len; - - len = wcslen(orig); - out = (WCHAR *) uiAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]"); - wcscpy_s(out, len + 1, orig); - return out; -} - -WCHAR *strf(const WCHAR *format, ...) -{ - va_list ap; - WCHAR *str; - - va_start(ap, format); - str = vstrf(format, ap); - va_end(ap); - return str; -} - -WCHAR *vstrf(const WCHAR *format, va_list ap) -{ - va_list ap2; - WCHAR *buf; - size_t n; - - if (*format == L'\0') - return emptyUTF16(); - - va_copy(ap2, ap); - n = _vscwprintf(format, ap2); - va_end(ap2); - n++; // terminating L'\0' - - buf = (WCHAR *) uiAlloc(n * sizeof (WCHAR), "WCHAR[]"); - // includes terminating L'\0' according to example in https://msdn.microsoft.com/en-us/library/xa1a1a6z.aspx - vswprintf_s(buf, n, format, ap); - - return buf; -} - -// Let's shove these utility routines here too. -// Prerequisite: lfonly is UTF-8. -char *LFtoCRLF(const char *lfonly) -{ - char *crlf; - size_t i, len; - char *out; - - len = strlen(lfonly); - crlf = (char *) uiAlloc((len * 2 + 1) * sizeof (char), "char[]"); - out = crlf; - for (i = 0; i < len; i++) { - if (*lfonly == '\n') - *crlf++ = '\r'; - *crlf++ = *lfonly++; - } - *crlf = '\0'; - return out; -} - -// Prerequisite: s is UTF-8. -void CRLFtoLF(char *s) -{ - char *t = s; - - for (; *s != '\0'; s++) { - // be sure to preserve \rs that are genuinely there - if (*s == '\r' && *(s + 1) == '\n') - continue; - *t++ = *s; - } - *t = '\0'; - // pad out the rest of t, just to be safe - while (t != s) - *t++ = '\0'; -} - -// std::to_string() always uses %f; we want %g -// fortunately std::iostream seems to use %g by default so -WCHAR *ftoutf16(double d) -{ - std::wostringstream ss; - std::wstring s; - - ss << d; - s = ss.str(); // to be safe - return utf16dup(s.c_str()); -} - -// to complement the above -WCHAR *itoutf16(int i) -{ - std::wostringstream ss; - std::wstring s; - - ss << i; - s = ss.str(); // to be safe - return utf16dup(s.c_str()); -} diff --git a/src/libui_sdl/libui/windows/utilwin.cpp b/src/libui_sdl/libui/windows/utilwin.cpp deleted file mode 100644 index 414ae83..0000000 --- a/src/libui_sdl/libui/windows/utilwin.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// 14 may 2015 -#include "uipriv_windows.hpp" - -// The utility window is a special window that performs certain tasks internal to libui. -// It is not a message-only window, and it is always hidden and disabled. -// Its roles: -// - It is the initial parent of all controls. When a control loses its parent, it also becomes that control's parent. -// - It handles WM_QUERYENDSESSION and console end session requests. -// - It handles WM_WININICHANGE and forwards the message to any child windows that request it. -// - It handles executing functions queued to run by uiQueueMain(). - -#define utilWindowClass L"libui_utilWindowClass" - -HWND utilWindow; - -static LRESULT CALLBACK utilWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - void (*qf)(void *); - LRESULT lResult; - - if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE) - return lResult; - switch (uMsg) { - case WM_QUERYENDSESSION: - // TODO block handler - if (shouldQuit()) { - uiQuit(); - return TRUE; - } - return FALSE; - case WM_WININICHANGE: - issueWM_WININICHANGE(wParam, lParam); - return 0; - case msgQueued: - qf = (void (*)(void *)) wParam; - (*qf)((void *) lParam); - return 0; - } - return DefWindowProcW(hwnd, uMsg, wParam, lParam); -} - -const char *initUtilWindow(HICON hDefaultIcon, HCURSOR hDefaultCursor) -{ - WNDCLASSW wc; - - ZeroMemory(&wc, sizeof (WNDCLASSW)); - wc.lpszClassName = utilWindowClass; - wc.lpfnWndProc = utilWindowWndProc; - wc.hInstance = hInstance; - wc.hIcon = hDefaultIcon; - wc.hCursor = hDefaultCursor; - wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); - if (RegisterClass(&wc) == 0) - // see init.cpp for an explanation of the =s - return "=registering utility window class"; - - utilWindow = CreateWindowExW(0, - utilWindowClass, L"libui utility window", - WS_OVERLAPPEDWINDOW, - 0, 0, 100, 100, - NULL, NULL, hInstance, NULL); - if (utilWindow == NULL) - return "=creating utility window"; - // and just to be safe - EnableWindow(utilWindow, FALSE); - - return NULL; -} - -void uninitUtilWindow(void) -{ - if (DestroyWindow(utilWindow) == 0) - logLastError(L"error destroying utility window"); - if (UnregisterClass(utilWindowClass, hInstance) == 0) - logLastError(L"error unregistering utility window class"); -} diff --git a/src/libui_sdl/libui/windows/winapi.hpp b/src/libui_sdl/libui/windows/winapi.hpp deleted file mode 100644 index d31547a..0000000 --- a/src/libui_sdl/libui/windows/winapi.hpp +++ /dev/null @@ -1,55 +0,0 @@ -// 31 may 2015 -#define UNICODE -#define _UNICODE -#define STRICT -#define STRICT_TYPED_ITEMIDS - -// see https://github.com/golang/go/issues/9916#issuecomment-74812211 -// TODO get rid of this -#define INITGUID - -// for the manifest -#ifndef _UI_STATIC -#define ISOLATION_AWARE_ENABLED 1 -#endif - -// get Windows version right; right now Windows Vista -// unless otherwise stated, all values from Microsoft's sdkddkver.h -// TODO is all of this necessary? how is NTDDI_VERSION used? -// TODO plaform update sp2 -#define WINVER 0x0600 /* from Microsoft's winnls.h */ -#define _WIN32_WINNT 0x0600 -#define _WIN32_WINDOWS 0x0600 /* from Microsoft's pdh.h */ -#define _WIN32_IE 0x0700 -#define NTDDI_VERSION 0x06000000 - -#include - -// Microsoft's resource compiler will segfault if we feed it headers it was not designed to handle -#ifndef RC_INVOKED -#include -#include -#include -#include -// workaround for MinGW builds -> https://stackoverflow.com/questions/27888109/rendertarget-getsize-not-working -#ifdef __MINGW32__ -#define WIDL_EXPLICIT_AGGREGATE_RETURNS -#endif -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#endif diff --git a/src/libui_sdl/libui/windows/window.cpp b/src/libui_sdl/libui/windows/window.cpp deleted file mode 100644 index a8f7f23..0000000 --- a/src/libui_sdl/libui/windows/window.cpp +++ /dev/null @@ -1,665 +0,0 @@ -// 27 april 2015 -#include "uipriv_windows.hpp" - -#define windowClass L"libui_uiWindowClass" - -struct uiWindow { - uiWindowsControl c; - HWND hwnd; - HMENU menubar; - uiControl *child; - BOOL shownOnce; - int visible; - int margined; - BOOL hasMenubar; - BOOL changingSize; - int maximized; - int fullscreen; - WINDOWPLACEMENT fsPrevPlacement; - int borderless; - - int (*onClosing)(uiWindow *, void *); - void *onClosingData; - void (*onContentSizeChanged)(uiWindow *, void *); - void *onContentSizeChangedData; - void (*onDropFile)(uiWindow *, char *, void *); - void *onDropFileData; - void (*onGetFocus)(uiWindow *, void *); - void *onGetFocusData; - void (*onLoseFocus)(uiWindow *, void *); - void *onLoseFocusData; -}; - -// from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing -#define windowMargin 7 - -static void windowMargins(uiWindow *w, int *mx, int *my) -{ - uiWindowsSizing sizing; - - *mx = 0; - *my = 0; - if (!w->margined) - return; - uiWindowsGetSizing(w->hwnd, &sizing); - *mx = windowMargin; - *my = windowMargin; - uiWindowsSizingDlgUnitsToPixels(&sizing, mx, my); -} - -static void windowRelayout(uiWindow *w) -{ - int x, y, width, height; - RECT r; - int mx, my; - HWND child; - - if (w->child == NULL) - return; - x = 0; - y = 0; - uiWindowsEnsureGetClientRect(w->hwnd, &r); - width = r.right - r.left; - height = r.bottom - r.top; - windowMargins(w, &mx, &my); - x += mx; - y += my; - width -= 2 * mx; - height -= 2 * my; - child = (HWND) uiControlHandle(w->child); - uiWindowsEnsureMoveWindowDuringResize(child, x, y, width, height); -} - -static LRESULT CALLBACK windowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - LONG_PTR ww; - uiWindow *w; - CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam; - WINDOWPOS *wp = (WINDOWPOS *) lParam; - MINMAXINFO *mmi = (MINMAXINFO *) lParam; - int width, height; - LRESULT lResult; - - ww = GetWindowLongPtrW(hwnd, GWLP_USERDATA); - if (ww == 0) { - if (uMsg == WM_CREATE) - SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) (cs->lpCreateParams)); - // fall through to DefWindowProc() anyway - return DefWindowProcW(hwnd, uMsg, wParam, lParam); - } - w = uiWindow((void *) ww); - if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE) - return lResult; - switch (uMsg) { - case WM_COMMAND: - // not a menu - if (lParam != 0) - break; - if (HIWORD(wParam) != 0 || LOWORD(wParam) <= IDCANCEL) - break; - runMenuEvent(LOWORD(wParam), uiWindow(w)); - return 0; - case WM_WINDOWPOSCHANGED: - if ((wp->flags & SWP_NOSIZE) != 0) - break; - if (w->onContentSizeChanged != NULL) // TODO figure out why this is happening too early - if (!w->changingSize) - (*(w->onContentSizeChanged))(w, w->onContentSizeChangedData); - windowRelayout(w); - return 0; - case WM_GETMINMAXINFO: - // ensure the user cannot resize the window smaller than its minimum size - lResult = DefWindowProcW(hwnd, uMsg, wParam, lParam); - uiWindowsControlMinimumSize(uiWindowsControl(w), &width, &height); - // width and height are in client coordinates; ptMinTrackSize is in window coordinates - clientSizeToWindowSize(w->hwnd, &width, &height, w->hasMenubar); - mmi->ptMinTrackSize.x = width; - mmi->ptMinTrackSize.y = height; - return lResult; - - case WM_DROPFILES: - if (w->onDropFile) - { - HDROP eggdrop = (HDROP)wParam; - WCHAR filename[1024]; - DragQueryFile(eggdrop, 0, filename, 1024); - - char* filename8 = toUTF8(filename); - w->onDropFile(w, filename8, w->onDropFileData); - uiFreeText(filename8); - - DragFinish(eggdrop); - } - break; - - case WM_SETFOCUS: - if (w->onGetFocus) - { - w->onGetFocus(w, w->onGetFocusData); - return 0; - } - break; - case WM_KILLFOCUS: - if (w->onLoseFocus) - { - w->onLoseFocus(w, w->onLoseFocusData); - return 0; - } - break; - - case WM_PRINTCLIENT: - // we do no special painting; just erase the background - // don't worry about the return value; we let DefWindowProcW() handle this message - SendMessageW(hwnd, WM_ERASEBKGND, wParam, lParam); - return 0; - case WM_CLOSE: - if ((*(w->onClosing))(w, w->onClosingData)) - uiControlDestroy(uiControl(w)); - return 0; // we destroyed it already - } - return DefWindowProcW(hwnd, uMsg, wParam, lParam); -} - -ATOM registerWindowClass(HICON hDefaultIcon, HCURSOR hDefaultCursor) -{ - WNDCLASSW wc; - - ZeroMemory(&wc, sizeof (WNDCLASSW)); - wc.lpszClassName = windowClass; - wc.lpfnWndProc = windowWndProc; - wc.hInstance = hInstance; - wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(100)); - wc.hCursor = hDefaultCursor; - wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); - return RegisterClassW(&wc); -} - -void unregisterWindowClass(void) -{ - if (UnregisterClassW(windowClass, hInstance) == 0) - logLastError(L"error unregistering uiWindow window class"); -} - -static int defaultOnClosing(uiWindow *w, void *data) -{ - return 0; -} - -static void defaultOnPositionContentSizeChanged(uiWindow *w, void *data) -{ - // do nothing -} - -static std::map windows; - -static void uiWindowDestroy(uiControl *c) -{ - uiWindow *w = uiWindow(c); - - // first hide ourselves - ShowWindow(w->hwnd, SW_HIDE); - // now destroy the child - if (w->child != NULL) { - uiControlSetParent(w->child, NULL); - uiControlDestroy(w->child); - } - // now free the menubar, if any - if (w->menubar != NULL) - freeMenubar(w->menubar); - // and finally free ourselves - windows.erase(w); - uiWindowsEnsureDestroyWindow(w->hwnd); - uiFreeControl(uiControl(w)); -} - -uiWindowsControlDefaultHandle(uiWindow) - -uiControl *uiWindowParent(uiControl *c) -{ - return NULL; -} - -void uiWindowSetParent(uiControl *c, uiControl *parent) -{ - uiUserBugCannotSetParentOnToplevel("uiWindow"); -} - -static int uiWindowToplevel(uiControl *c) -{ - return 1; -} - -// TODO initial state of windows is hidden; ensure this here and make it so on other platforms -static int uiWindowVisible(uiControl *c) -{ - uiWindow *w = uiWindow(c); - - return w->visible; -} - -static void uiWindowShow(uiControl *c) -{ - uiWindow *w = uiWindow(c); - - w->visible = 1; - // just in case the window's minimum size wasn't recalculated already - ensureMinimumWindowSize(w); - if (w->shownOnce) { - ShowWindow(w->hwnd, SW_SHOW); - return; - } - w->shownOnce = TRUE; - - int cmd; - if (w->maximized) - cmd = SW_SHOWMAXIMIZED; - else - cmd = SW_SHOWDEFAULT; - - // make sure the child is the correct size - uiWindowsControlMinimumSizeChanged(uiWindowsControl(w)); - ShowWindow(w->hwnd, cmd);//nCmdShow); - if (UpdateWindow(w->hwnd) == 0) - logLastError(L"error calling UpdateWindow() after showing uiWindow for the first time"); -} - -static void uiWindowHide(uiControl *c) -{ - uiWindow *w = uiWindow(c); - - w->visible = 0; - ShowWindow(w->hwnd, SW_HIDE); -} - -// TODO we don't want the window to be disabled completely; that would prevent it from being moved! ...would it? -uiWindowsControlDefaultEnabled(uiWindow) -uiWindowsControlDefaultEnable(uiWindow) -uiWindowsControlDefaultDisable(uiWindow) -uiWindowsControlDefaultSetFocus(uiWindow) -// TODO we need to do something about undocumented fields in the OS control types -uiWindowsControlDefaultSyncEnableState(uiWindow) -// TODO -uiWindowsControlDefaultSetParentHWND(uiWindow) - -static void uiWindowMinimumSize(uiWindowsControl *c, int *width, int *height) -{ - uiWindow *w = uiWindow(c); - int mx, my; - - *width = 0; - *height = 0; - if (w->child != NULL) - uiWindowsControlMinimumSize(uiWindowsControl(w->child), width, height); - windowMargins(w, &mx, &my); - *width += 2 * mx; - *height += 2 * my; -} - -static void uiWindowMinimumSizeChanged(uiWindowsControl *c) -{ - uiWindow *w = uiWindow(c); - - if (uiWindowsControlTooSmall(uiWindowsControl(w))) { - // TODO figure out what to do with this function - // maybe split it into two so WM_GETMINMAXINFO can use it? - ensureMinimumWindowSize(w); - return; - } - // otherwise we only need to re-layout everything - windowRelayout(w); -} - -static void uiWindowLayoutRect(uiWindowsControl *c, RECT *r) -{ - uiWindow *w = uiWindow(c); - - // the layout rect is the client rect in this case - uiWindowsEnsureGetClientRect(w->hwnd, r); -} - -static void uiWindowSetMinSize(uiControl *c, int w, int h) -{ - // TODO: relayout, eventually -} - -uiWindowsControlDefaultAssignControlIDZOrder(uiWindow) - -static void uiWindowChildVisibilityChanged(uiWindowsControl *c) -{ - // TODO eliminate the redundancy - uiWindowsControlMinimumSizeChanged(c); -} - -char *uiWindowTitle(uiWindow *w) -{ - return uiWindowsWindowText(w->hwnd); -} - -void uiWindowSetTitle(uiWindow *w, const char *title) -{ - uiWindowsSetWindowText(w->hwnd, title); - // don't queue resize; the caption isn't part of what affects layout and sizing of the client area (it'll be ellipsized if too long) -} - -// this is used for both fullscreening and centering -// see also https://blogs.msdn.microsoft.com/oldnewthing/20100412-00/?p=14353 and https://blogs.msdn.microsoft.com/oldnewthing/20050505-04/?p=35703 -static void windowMonitorRect(HWND hwnd, RECT *r) -{ - HMONITOR monitor; - MONITORINFO mi; - - monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY); - ZeroMemory(&mi, sizeof (MONITORINFO)); - mi.cbSize = sizeof (MONITORINFO); - if (GetMonitorInfoW(monitor, &mi) == 0) { - logLastError(L"error getting window monitor rect"); - // default to SM_CXSCREEN x SM_CYSCREEN to be safe - r->left = 0; - r->top = 0; - r->right = GetSystemMetrics(SM_CXSCREEN); - r->bottom = GetSystemMetrics(SM_CYSCREEN); - return; - } - *r = mi.rcMonitor; -} - -void uiWindowPosition(uiWindow *w, int *x, int *y) -{ - RECT rect; - if (GetWindowRect(w->hwnd, &rect) == 0) - logLastError(L"error getting window position"); - *x = rect.left; - *y = rect.top; -} - -void uiWindowSetPosition(uiWindow *w, int x, int y) -{ - if (SetWindowPos(w->hwnd, NULL, x, y, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_NOZORDER) == 0) - logLastError(L"error moving window"); -} - -void uiWindowContentSize(uiWindow *w, int *width, int *height) -{ - RECT r; - - uiWindowsEnsureGetClientRect(w->hwnd, &r); - *width = r.right - r.left; - *height = r.bottom - r.top; -} - -// TODO should this disallow too small? -void uiWindowSetContentSize(uiWindow *w, int width, int height) -{ - w->changingSize = TRUE; - clientSizeToWindowSize(w->hwnd, &width, &height, w->hasMenubar); - if (SetWindowPos(w->hwnd, NULL, 0, 0, width, height, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER) == 0) - logLastError(L"error resizing window"); - w->changingSize = FALSE; -} - -int uiWindowMinimized(uiWindow *w) -{ - return IsIconic(w->hwnd); -} - -void uiWindowSetMinimized(uiWindow *w, int minimized) -{ - if (minimized) - ShowWindow(w->hwnd, SW_MINIMIZE); - else if (w->maximized) - ShowWindow(w->hwnd, SW_MAXIMIZE); - else - ShowWindow(w->hwnd, SW_RESTORE); -} - -int uiWindowMaximized(uiWindow *w) -{ - return IsZoomed(w->hwnd); -} - -void uiWindowSetMaximized(uiWindow *w, int maximized) -{ - w->maximized = maximized; - if (maximized) - ShowWindow(w->hwnd, SW_MAXIMIZE); - else - ShowWindow(w->hwnd, SW_RESTORE); -} - - -int uiWindowFullscreen(uiWindow *w) -{ - return w->fullscreen; -} - -void uiWindowSetFullscreen(uiWindow *w, int fullscreen) -{ - RECT r; - - if (w->fullscreen && fullscreen) - return; - if (!w->fullscreen && !fullscreen) - return; - w->fullscreen = fullscreen; - w->changingSize = TRUE; - if (w->fullscreen) { - ZeroMemory(&(w->fsPrevPlacement), sizeof (WINDOWPLACEMENT)); - w->fsPrevPlacement.length = sizeof (WINDOWPLACEMENT); - if (GetWindowPlacement(w->hwnd, &(w->fsPrevPlacement)) == 0) - logLastError(L"error getting old window placement"); - windowMonitorRect(w->hwnd, &r); - setStyle(w->hwnd, getStyle(w->hwnd) & ~WS_OVERLAPPEDWINDOW); - if (SetWindowPos(w->hwnd, HWND_TOP, - r.left, r.top, - r.right - r.left, r.bottom - r.top, - SWP_FRAMECHANGED | SWP_NOOWNERZORDER) == 0) - logLastError(L"error making window fullscreen"); - } else { - if (!w->borderless) // keep borderless until that is turned off - setStyle(w->hwnd, getStyle(w->hwnd) | WS_OVERLAPPEDWINDOW); - if (SetWindowPlacement(w->hwnd, &(w->fsPrevPlacement)) == 0) - logLastError(L"error leaving fullscreen"); - if (SetWindowPos(w->hwnd, NULL, - 0, 0, 0, 0, - SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER) == 0) - logLastError(L"error restoring window border after fullscreen"); - } - w->changingSize = FALSE; -} - -void uiWindowOnContentSizeChanged(uiWindow *w, void (*f)(uiWindow *, void *), void *data) -{ - w->onContentSizeChanged = f; - w->onContentSizeChangedData = data; -} - -void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data) -{ - w->onClosing = f; - w->onClosingData = data; -} - -void uiWindowOnDropFile(uiWindow *w, void (*f)(uiWindow *, char *, void *), void *data) -{ - w->onDropFile = f; - w->onDropFileData = data; -} - -void uiWindowOnGetFocus(uiWindow *w, void (*f)(uiWindow *, void *), void *data) -{ - w->onGetFocus = f; - w->onGetFocusData = data; -} - -void uiWindowOnLoseFocus(uiWindow *w, void (*f)(uiWindow *, void *), void *data) -{ - w->onLoseFocus = f; - w->onLoseFocusData = data; -} - -int uiWindowBorderless(uiWindow *w) -{ - return w->borderless; -} - -// TODO window should move to the old client position and should not have the extra space the borders left behind -// TODO extract the relevant styles from WS_OVERLAPPEDWINDOW? -void uiWindowSetBorderless(uiWindow *w, int borderless) -{ - w->borderless = borderless; - if (w->borderless) - setStyle(w->hwnd, getStyle(w->hwnd) & ~WS_OVERLAPPEDWINDOW); - else - if (!w->fullscreen) // keep borderless until leaving fullscreen - setStyle(w->hwnd, getStyle(w->hwnd) | WS_OVERLAPPEDWINDOW); -} - -void uiWindowSetChild(uiWindow *w, uiControl *child) -{ - if (w->child != NULL) { - uiControlSetParent(w->child, NULL); - uiWindowsControlSetParentHWND(uiWindowsControl(w->child), NULL); - } - w->child = child; - if (w->child != NULL) { - uiControlSetParent(w->child, uiControl(w)); - uiWindowsControlSetParentHWND(uiWindowsControl(w->child), w->hwnd); - uiWindowsControlAssignSoleControlIDZOrder(uiWindowsControl(w->child)); - windowRelayout(w); - } -} - -int uiWindowMargined(uiWindow *w) -{ - return w->margined; -} - -void uiWindowSetMargined(uiWindow *w, int margined) -{ - w->margined = margined; - windowRelayout(w); -} - - -void uiWindowSetDropTarget(uiWindow* w, int drop) -{ - DragAcceptFiles(w->hwnd, drop?TRUE:FALSE); -} - -// see http://blogs.msdn.com/b/oldnewthing/archive/2003/09/11/54885.aspx and http://blogs.msdn.com/b/oldnewthing/archive/2003/09/13/54917.aspx -// TODO use clientSizeToWindowSize() -static void setClientSize(uiWindow *w, int width, int height, BOOL hasMenubar, DWORD style, DWORD exstyle) -{ - RECT window; - - window.left = 0; - window.top = 0; - window.right = width; - window.bottom = height; - if (AdjustWindowRectEx(&window, style, hasMenubar, exstyle) == 0) - logLastError(L"error getting real window coordinates"); - if (hasMenubar) { - RECT temp; - - temp = window; - temp.bottom = 0x7FFF; // infinite height - SendMessageW(w->hwnd, WM_NCCALCSIZE, (WPARAM) FALSE, (LPARAM) (&temp)); - window.bottom += temp.top; - } - if (SetWindowPos(w->hwnd, NULL, 0, 0, window.right - window.left, window.bottom - window.top, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER) == 0) - logLastError(L"error resizing window"); -} - -uiWindow *uiNewWindow(const char *title, int width, int height, int maximized, int hasMenubar, int resizable) -{ - uiWindow *w; - WCHAR *wtitle; - BOOL hasMenubarBOOL; - - if (!resizable) maximized = 0; - - uiWindowsNewControl(uiWindow, w); - - hasMenubarBOOL = FALSE; - if (hasMenubar) - hasMenubarBOOL = TRUE; - w->hasMenubar = hasMenubarBOOL; - - int style = WS_OVERLAPPEDWINDOW; - int exstyle = 0; - - if (!resizable) - style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX); - - wtitle = toUTF16(title); - w->hwnd = CreateWindowExW(exstyle, - windowClass, wtitle, - style, - CW_USEDEFAULT, CW_USEDEFAULT, - // use the raw width and height for now - // this will get CW_USEDEFAULT (hopefully) predicting well - // even if it doesn't, we're adjusting it later - width, height, - NULL, NULL, hInstance, w); - if (w->hwnd == NULL) - logLastError(L"error creating window"); - uiFree(wtitle); - - if (hasMenubar) { - w->menubar = makeMenubar(); - if (SetMenu(w->hwnd, w->menubar) == 0) - logLastError(L"error giving menu to window"); - } - - // and use the proper size - setClientSize(w, width, height, hasMenubarBOOL, style, exstyle); - - w->maximized = maximized; - - uiWindowOnClosing(w, defaultOnClosing, NULL); - uiWindowOnContentSizeChanged(w, defaultOnPositionContentSizeChanged, NULL); - - uiWindowOnDropFile(w, NULL, NULL); - uiWindowOnGetFocus(w, NULL, NULL); - uiWindowOnLoseFocus(w, NULL, NULL); - - windows[w] = true; - return w; -} - -// this cannot queue a resize because it's called by the resize handler -void ensureMinimumWindowSize(uiWindow *w) -{ - int width, height; - RECT r; - - uiWindowsControlMinimumSize(uiWindowsControl(w), &width, &height); - uiWindowsEnsureGetClientRect(w->hwnd, &r); - if (width < (r.right - r.left)) // preserve width if larger - width = r.right - r.left; - if (height < (r.bottom - r.top)) // preserve height if larger - height = r.bottom - r.top; - clientSizeToWindowSize(w->hwnd, &width, &height, w->hasMenubar); - if (SetWindowPos(w->hwnd, NULL, 0, 0, width, height, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER) == 0) - logLastError(L"error resizing window"); -} - -void disableAllWindowsExcept(uiWindow *which) -{ - for (auto &w : windows) { - if (w.first == which) - continue; - EnableWindow(w.first->hwnd, FALSE); - } -} - -void enableAllWindowsExcept(uiWindow *which) -{ - for (auto &w : windows) { - if (w.first == which) - continue; - if (!uiControlEnabled(uiControl(w.first))) - continue; - EnableWindow(w.first->hwnd, TRUE); - } -} diff --git a/src/libui_sdl/libui/windows/winpublic.cpp b/src/libui_sdl/libui/windows/winpublic.cpp deleted file mode 100644 index 397a3b5..0000000 --- a/src/libui_sdl/libui/windows/winpublic.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// 6 april 2015 -#include "uipriv_windows.hpp" - -void uiWindowsEnsureDestroyWindow(HWND hwnd) -{ - if (DestroyWindow(hwnd) == 0) - logLastError(L"error destroying window"); -} - -void uiWindowsEnsureSetParentHWND(HWND hwnd, HWND parent) -{ - if (parent == NULL) - parent = utilWindow; - if (SetParent(hwnd, parent) == 0) - logLastError(L"error setting window parent"); -} - -void uiWindowsEnsureAssignControlIDZOrder(HWND hwnd, LONG_PTR *controlID, HWND *insertAfter) -{ - SetWindowLongPtrW(hwnd, GWLP_ID, *controlID); - (*controlID)++; - setWindowInsertAfter(hwnd, *insertAfter); - *insertAfter = hwnd; -} - -void uiWindowsEnsureMoveWindowDuringResize(HWND hwnd, int x, int y, int width, int height) -{ - RECT r; - - r.left = x; - r.top = y; - r.right = x + width; - r.bottom = y + height; - if (SetWindowPos(hwnd, NULL, r.left, r.top, r.right - r.left, r.bottom - r.top, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER) == 0) - logLastError(L"error moving window"); -} - -// do these function even error out in any case other than invalid parameters?! I thought all windows had rects -void uiWindowsEnsureGetClientRect(HWND hwnd, RECT *r) -{ - if (GetClientRect(hwnd, r) == 0) { - logLastError(L"error getting window client rect"); - // zero out the rect on error just to be safe - r->left = 0; - r->top = 0; - r->right = 0; - r->bottom = 0; - } -} - -void uiWindowsEnsureGetWindowRect(HWND hwnd, RECT *r) -{ - if (GetWindowRect(hwnd, r) == 0) { - logLastError(L"error getting window rect"); - // zero out the rect on error just to be safe - r->left = 0; - r->top = 0; - r->right = 0; - r->bottom = 0; - } -} diff --git a/src/libui_sdl/libui/windows/winutil.cpp b/src/libui_sdl/libui/windows/winutil.cpp deleted file mode 100644 index 2552893..0000000 --- a/src/libui_sdl/libui/windows/winutil.cpp +++ /dev/null @@ -1,143 +0,0 @@ -// 6 april 2015 -#include "uipriv_windows.hpp" - -// this is a helper function that takes the logic of determining window classes and puts it all in one place -// there are a number of places where we need to know what window class an arbitrary handle has -// theoretically we could use the class atom to avoid a _wcsicmp() -// however, raymond chen advises against this - http://blogs.msdn.com/b/oldnewthing/archive/2004/10/11/240744.aspx (and we're not in control of the Tab class, before you say anything) -// usage: windowClassOf(hwnd, L"class 1", L"class 2", ..., NULL) -int windowClassOf(HWND hwnd, ...) -{ -// MSDN says 256 is the maximum length of a class name; add a few characters just to be safe (because it doesn't say whether this includes the terminating null character) -#define maxClassName 260 - WCHAR classname[maxClassName + 1]; - va_list ap; - WCHAR *curname; - int i; - - if (GetClassNameW(hwnd, classname, maxClassName) == 0) { - logLastError(L"error getting name of window class"); - // assume no match on error, just to be safe - return -1; - } - va_start(ap, hwnd); - i = 0; - for (;;) { - curname = va_arg(ap, WCHAR *); - if (curname == NULL) - break; - if (_wcsicmp(classname, curname) == 0) { - va_end(ap); - return i; - } - i++; - } - // no match - va_end(ap); - return -1; -} - -// wrapper around MapWindowRect() that handles the complex error handling -void mapWindowRect(HWND from, HWND to, RECT *r) -{ - RECT prevr; - DWORD le; - - prevr = *r; - SetLastError(0); - if (MapWindowRect(from, to, r) == 0) { - le = GetLastError(); - SetLastError(le); // just to be safe - if (le != 0) { - logLastError(L"error calling MapWindowRect()"); - // restore original rect on error, just in case - *r = prevr; - } - } -} - -DWORD getStyle(HWND hwnd) -{ - return (DWORD) GetWindowLongPtrW(hwnd, GWL_STYLE); -} - -void setStyle(HWND hwnd, DWORD style) -{ - SetWindowLongPtrW(hwnd, GWL_STYLE, (LONG_PTR) style); -} - -DWORD getExStyle(HWND hwnd) -{ - return (DWORD) GetWindowLongPtrW(hwnd, GWL_EXSTYLE); -} - -void setExStyle(HWND hwnd, DWORD exstyle) -{ - SetWindowLongPtrW(hwnd, GWL_EXSTYLE, (LONG_PTR) exstyle); -} - -// see http://blogs.msdn.com/b/oldnewthing/archive/2003/09/11/54885.aspx and http://blogs.msdn.com/b/oldnewthing/archive/2003/09/13/54917.aspx -void clientSizeToWindowSize(HWND hwnd, int *width, int *height, BOOL hasMenubar) -{ - RECT window; - - window.left = 0; - window.top = 0; - window.right = *width; - window.bottom = *height; - if (AdjustWindowRectEx(&window, getStyle(hwnd), hasMenubar, getExStyle(hwnd)) == 0) { - logLastError(L"error getting adjusted window rect"); - // on error, don't give up; the window will be smaller but whatever - window.left = 0; - window.top = 0; - window.right = *width; - window.bottom = *height; - } - if (hasMenubar) { - RECT temp; - - temp = window; - temp.bottom = 0x7FFF; // infinite height - SendMessageW(hwnd, WM_NCCALCSIZE, (WPARAM) FALSE, (LPARAM) (&temp)); - window.bottom += temp.top; - } - *width = window.right - window.left; - *height = window.bottom - window.top; -} - -HWND parentOf(HWND child) -{ - return GetAncestor(child, GA_PARENT); -} - -HWND parentToplevel(HWND child) -{ - return GetAncestor(child, GA_ROOT); -} - -void setWindowInsertAfter(HWND hwnd, HWND insertAfter) -{ - if (SetWindowPos(hwnd, insertAfter, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOSIZE) == 0) - logLastError(L"error reordering window"); -} - -HWND getDlgItem(HWND hwnd, int id) -{ - HWND out; - - out = GetDlgItem(hwnd, id); - if (out == NULL) - logLastError(L"error getting dialog item handle"); - return out; -} - -void invalidateRect(HWND hwnd, RECT *r, BOOL erase) -{ - if (InvalidateRect(hwnd, r, erase) == 0) - logLastError(L"error invalidating window rect"); -} - -D2D1_SIZE_F realGetSize(ID2D1RenderTarget *rt) -{ - return rt->GetSize(); -} diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp deleted file mode 100644 index 64bc532..0000000 --- a/src/libui_sdl/main.cpp +++ /dev/null @@ -1,3029 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#include -#include -#include -#include - -#ifndef __WIN32__ -#include -#endif - -#include -#include "libui/ui.h" - -#include "../OpenGLSupport.h" -#include "main_shaders.h" - -#include "../types.h" -#include "../version.h" -#include "PlatformConfig.h" - -#include "DlgEmuSettings.h" -#include "DlgInputConfig.h" -#include "DlgVideoSettings.h" -#include "DlgAudioSettings.h" -#include "DlgWifiSettings.h" - -#include "../NDS.h" -#include "../GBACart.h" -#include "../GPU.h" -#include "../SPU.h" -#include "../Wifi.h" -#include "../Platform.h" -#include "../Config.h" - -#include "../Savestate.h" - -#include "OSD.h" - -#ifdef MELONCAP -#include "MelonCap.h" -#endif // MELONCAP - - -// savestate slot mapping -// 1-8: regular slots (quick access) -// '9': load/save arbitrary file -const int kSavestateNum[9] = {1, 2, 3, 4, 5, 6, 7, 8, 0}; - -const int kScreenSize[4] = {1, 2, 3, 4}; -const int kScreenRot[4] = {0, 1, 2, 3}; -const int kScreenGap[6] = {0, 1, 8, 64, 90, 128}; -const int kScreenLayout[3] = {0, 1, 2}; -const int kScreenSizing[4] = {0, 1, 2, 3}; - - -char* EmuDirectory; - - -uiWindow* MainWindow; -uiArea* MainDrawArea; -uiAreaHandler MainDrawAreaHandler; - -const u32 kGLVersions[] = {uiGLVersion(3,2), uiGLVersion(3,1), 0}; -uiGLContext* GLContext; - -int WindowWidth, WindowHeight; - -uiMenuItem* MenuItem_SaveState; -uiMenuItem* MenuItem_LoadState; -uiMenuItem* MenuItem_UndoStateLoad; - -uiMenuItem* MenuItem_SaveStateSlot[9]; -uiMenuItem* MenuItem_LoadStateSlot[9]; - -uiMenuItem* MenuItem_Pause; -uiMenuItem* MenuItem_Reset; -uiMenuItem* MenuItem_Stop; - -uiMenuItem* MenuItem_SavestateSRAMReloc; - -uiMenuItem* MenuItem_ScreenRot[4]; -uiMenuItem* MenuItem_ScreenGap[6]; -uiMenuItem* MenuItem_ScreenLayout[3]; -uiMenuItem* MenuItem_ScreenSizing[4]; - -uiMenuItem* MenuItem_ScreenFilter; -uiMenuItem* MenuItem_LimitFPS; -uiMenuItem* MenuItem_AudioSync; -uiMenuItem* MenuItem_ShowOSD; - -SDL_Thread* EmuThread; -int EmuRunning; -volatile int EmuStatus; - -bool RunningSomething; -char ROMPath[2][1024]; -char SRAMPath[2][1024]; -char PrevSRAMPath[2][1024]; // for savestate 'undo load' - -bool SavestateLoaded; - -bool Screen_UseGL; - -bool ScreenDrawInited = false; -uiDrawBitmap* ScreenBitmap[2] = {NULL,NULL}; - -GLuint GL_ScreenShader[3]; -GLuint GL_ScreenShaderAccel[3]; -GLuint GL_ScreenShaderOSD[3]; -struct -{ - float uScreenSize[2]; - u32 u3DScale; - u32 uFilterMode; - -} GL_ShaderConfig; -GLuint GL_ShaderConfigUBO; -GLuint GL_ScreenVertexArrayID, GL_ScreenVertexBufferID; -float GL_ScreenVertices[2 * 3*2 * 4]; // position/texcoord -GLuint GL_ScreenTexture; -bool GL_ScreenSizeDirty; - -int GL_3DScale; - -bool GL_VSyncStatus; - -int ScreenGap = 0; -int ScreenLayout = 0; -int ScreenSizing = 0; -int ScreenRotation = 0; - -int MainScreenPos[3]; -int AutoScreenSizing; - -uiRect TopScreenRect; -uiRect BottomScreenRect; -uiDrawMatrix TopScreenTrans; -uiDrawMatrix BottomScreenTrans; - -bool Touching = false; - -u32 KeyInputMask, JoyInputMask; -u32 KeyHotkeyMask, JoyHotkeyMask; -u32 HotkeyMask, LastHotkeyMask; -u32 HotkeyPress, HotkeyRelease; - -#define HotkeyDown(hk) (HotkeyMask & (1<<(hk))) -#define HotkeyPressed(hk) (HotkeyPress & (1<<(hk))) -#define HotkeyReleased(hk) (HotkeyRelease & (1<<(hk))) - -bool LidStatus; - -int JoystickID; -SDL_Joystick* Joystick; - -int AudioFreq; -float AudioSampleFrac; -SDL_AudioDeviceID AudioDevice, MicDevice; - -SDL_cond* AudioSync; -SDL_mutex* AudioSyncLock; - -u32 MicBufferLength = 2048; -s16 MicBuffer[2048]; -u32 MicBufferReadPos, MicBufferWritePos; - -u32 MicWavLength; -s16* MicWavBuffer; - -void SetupScreenRects(int width, int height); - -void TogglePause(void* blarg); -void Reset(void* blarg); - -void SetupSRAMPath(int slot); - -void SaveState(int slot); -void LoadState(int slot); -void UndoStateLoad(); -void GetSavestateName(int slot, char* filename, int len); - -void CreateMainWindow(bool opengl); -void DestroyMainWindow(); -void RecreateMainWindow(bool opengl); - - - -bool GLScreen_InitShader(GLuint* shader, const char* fs) -{ - if (!OpenGL_BuildShaderProgram(kScreenVS, fs, shader, "ScreenShader")) - return false; - - glBindAttribLocation(shader[2], 0, "vPosition"); - glBindAttribLocation(shader[2], 1, "vTexcoord"); - glBindFragDataLocation(shader[2], 0, "oColor"); - - if (!OpenGL_LinkShaderProgram(shader)) - return false; - - GLuint uni_id; - - uni_id = glGetUniformBlockIndex(shader[2], "uConfig"); - glUniformBlockBinding(shader[2], uni_id, 16); - - glUseProgram(shader[2]); - uni_id = glGetUniformLocation(shader[2], "ScreenTex"); - glUniform1i(uni_id, 0); - uni_id = glGetUniformLocation(shader[2], "_3DTex"); - glUniform1i(uni_id, 1); - - return true; -} - -bool GLScreen_InitOSDShader(GLuint* shader) -{ - if (!OpenGL_BuildShaderProgram(kScreenVS_OSD, kScreenFS_OSD, shader, "ScreenShaderOSD")) - return false; - - glBindAttribLocation(shader[2], 0, "vPosition"); - glBindFragDataLocation(shader[2], 0, "oColor"); - - if (!OpenGL_LinkShaderProgram(shader)) - return false; - - GLuint uni_id; - - uni_id = glGetUniformBlockIndex(shader[2], "uConfig"); - glUniformBlockBinding(shader[2], uni_id, 16); - - glUseProgram(shader[2]); - uni_id = glGetUniformLocation(shader[2], "OSDTex"); - glUniform1i(uni_id, 0); - - return true; -} - -bool GLScreen_Init() -{ - GL_VSyncStatus = Config::ScreenVSync; - - // TODO: consider using epoxy? - if (!OpenGL_Init()) - return false; - - const GLubyte* renderer = glGetString(GL_RENDERER); // get renderer string - const GLubyte* version = glGetString(GL_VERSION); // version as a string - printf("OpenGL: renderer: %s\n", renderer); - printf("OpenGL: version: %s\n", version); - - if (!GLScreen_InitShader(GL_ScreenShader, kScreenFS)) - return false; - if (!GLScreen_InitShader(GL_ScreenShaderAccel, kScreenFS_Accel)) - return false; - if (!GLScreen_InitOSDShader(GL_ScreenShaderOSD)) - return false; - - memset(&GL_ShaderConfig, 0, sizeof(GL_ShaderConfig)); - - glGenBuffers(1, &GL_ShaderConfigUBO); - glBindBuffer(GL_UNIFORM_BUFFER, GL_ShaderConfigUBO); - glBufferData(GL_UNIFORM_BUFFER, sizeof(GL_ShaderConfig), &GL_ShaderConfig, GL_STATIC_DRAW); - glBindBufferBase(GL_UNIFORM_BUFFER, 16, GL_ShaderConfigUBO); - - glGenBuffers(1, &GL_ScreenVertexBufferID); - glBindBuffer(GL_ARRAY_BUFFER, GL_ScreenVertexBufferID); - glBufferData(GL_ARRAY_BUFFER, sizeof(GL_ScreenVertices), NULL, GL_STATIC_DRAW); - - glGenVertexArrays(1, &GL_ScreenVertexArrayID); - glBindVertexArray(GL_ScreenVertexArrayID); - glEnableVertexAttribArray(0); // position - glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4*4, (void*)(0)); - glEnableVertexAttribArray(1); // texcoord - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4*4, (void*)(2*4)); - - glGenTextures(1, &GL_ScreenTexture); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, GL_ScreenTexture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 256*3 + 1, 192*2, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, NULL); - - GL_ScreenSizeDirty = true; - - return true; -} - -void GLScreen_DeInit() -{ - glDeleteTextures(1, &GL_ScreenTexture); - - glDeleteVertexArrays(1, &GL_ScreenVertexArrayID); - glDeleteBuffers(1, &GL_ScreenVertexBufferID); - - OpenGL_DeleteShaderProgram(GL_ScreenShader); - OpenGL_DeleteShaderProgram(GL_ScreenShaderAccel); - OpenGL_DeleteShaderProgram(GL_ScreenShaderOSD); -} - -void GLScreen_DrawScreen() -{ - bool vsync = Config::ScreenVSync && !HotkeyDown(HK_FastForward); - if (vsync != GL_VSyncStatus) - { - GL_VSyncStatus = vsync; - uiGLSetVSync(vsync); - } - - float scale = uiGLGetFramebufferScale(GLContext); - - glBindFramebuffer(GL_FRAMEBUFFER, uiGLGetFramebuffer(GLContext)); - - if (GL_ScreenSizeDirty) - { - GL_ScreenSizeDirty = false; - - GL_ShaderConfig.uScreenSize[0] = WindowWidth; - GL_ShaderConfig.uScreenSize[1] = WindowHeight; - GL_ShaderConfig.u3DScale = GL_3DScale; - - glBindBuffer(GL_UNIFORM_BUFFER, GL_ShaderConfigUBO); - void* unibuf = glMapBuffer(GL_UNIFORM_BUFFER, GL_WRITE_ONLY); - if (unibuf) memcpy(unibuf, &GL_ShaderConfig, sizeof(GL_ShaderConfig)); - glUnmapBuffer(GL_UNIFORM_BUFFER); - - float scwidth, scheight; - - float x0, y0, x1, y1; - float s0, s1, s2, s3; - float t0, t1, t2, t3; - -#define SETVERTEX(i, x, y, s, t) \ - GL_ScreenVertices[4*(i) + 0] = x; \ - GL_ScreenVertices[4*(i) + 1] = y; \ - GL_ScreenVertices[4*(i) + 2] = s; \ - GL_ScreenVertices[4*(i) + 3] = t; - - x0 = TopScreenRect.X; - y0 = TopScreenRect.Y; - x1 = TopScreenRect.X + TopScreenRect.Width; - y1 = TopScreenRect.Y + TopScreenRect.Height; - - scwidth = 256; - scheight = 192; - - switch (ScreenRotation) - { - case 0: - s0 = 0; t0 = 0; - s1 = scwidth; t1 = 0; - s2 = 0; t2 = scheight; - s3 = scwidth; t3 = scheight; - break; - - case 1: - s0 = 0; t0 = scheight; - s1 = 0; t1 = 0; - s2 = scwidth; t2 = scheight; - s3 = scwidth; t3 = 0; - break; - - case 2: - s0 = scwidth; t0 = scheight; - s1 = 0; t1 = scheight; - s2 = scwidth; t2 = 0; - s3 = 0; t3 = 0; - break; - - case 3: - s0 = scwidth; t0 = 0; - s1 = scwidth; t1 = scheight; - s2 = 0; t2 = 0; - s3 = 0; t3 = scheight; - break; - } - - SETVERTEX(0, x0, y0, s0, t0); - SETVERTEX(1, x1, y1, s3, t3); - SETVERTEX(2, x1, y0, s1, t1); - SETVERTEX(3, x0, y0, s0, t0); - SETVERTEX(4, x0, y1, s2, t2); - SETVERTEX(5, x1, y1, s3, t3); - - x0 = BottomScreenRect.X; - y0 = BottomScreenRect.Y; - x1 = BottomScreenRect.X + BottomScreenRect.Width; - y1 = BottomScreenRect.Y + BottomScreenRect.Height; - - scwidth = 256; - scheight = 192; - - switch (ScreenRotation) - { - case 0: - s0 = 0; t0 = 192; - s1 = scwidth; t1 = 192; - s2 = 0; t2 = 192+scheight; - s3 = scwidth; t3 = 192+scheight; - break; - - case 1: - s0 = 0; t0 = 192+scheight; - s1 = 0; t1 = 192; - s2 = scwidth; t2 = 192+scheight; - s3 = scwidth; t3 = 192; - break; - - case 2: - s0 = scwidth; t0 = 192+scheight; - s1 = 0; t1 = 192+scheight; - s2 = scwidth; t2 = 192; - s3 = 0; t3 = 192; - break; - - case 3: - s0 = scwidth; t0 = 192; - s1 = scwidth; t1 = 192+scheight; - s2 = 0; t2 = 192; - s3 = 0; t3 = 192+scheight; - break; - } - - SETVERTEX(6, x0, y0, s0, t0); - SETVERTEX(7, x1, y1, s3, t3); - SETVERTEX(8, x1, y0, s1, t1); - SETVERTEX(9, x0, y0, s0, t0); - SETVERTEX(10, x0, y1, s2, t2); - SETVERTEX(11, x1, y1, s3, t3); - -#undef SETVERTEX - - glBindBuffer(GL_ARRAY_BUFFER, GL_ScreenVertexBufferID); - glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(GL_ScreenVertices), GL_ScreenVertices); - } - - glDisable(GL_DEPTH_TEST); - glDisable(GL_STENCIL_TEST); - glDisable(GL_BLEND); - glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - - glViewport(0, 0, WindowWidth*scale, WindowHeight*scale); - - if (GPU3D::Renderer == 0) - OpenGL_UseShaderProgram(GL_ScreenShader); - else - OpenGL_UseShaderProgram(GL_ScreenShaderAccel); - - glClearColor(0, 0, 0, 1); - glClear(GL_COLOR_BUFFER_BIT); - - if (RunningSomething) - { - int frontbuf = GPU::FrontBuffer; - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, GL_ScreenTexture); - - if (GPU::Framebuffer[frontbuf][0] && GPU::Framebuffer[frontbuf][1]) - { - if (GPU3D::Renderer == 0) - { - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 192, GL_RGBA_INTEGER, - GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][0]); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 192, 256, 192, GL_RGBA_INTEGER, - GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][1]); - } - else - { - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256*3 + 1, 192, GL_RGBA_INTEGER, - GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][0]); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 192, 256*3 + 1, 192, GL_RGBA_INTEGER, - GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][1]); - } - } - - glActiveTexture(GL_TEXTURE1); - if (GPU3D::Renderer != 0) - GPU3D::GLRenderer::SetupAccelFrame(); - - glBindBuffer(GL_ARRAY_BUFFER, GL_ScreenVertexBufferID); - glBindVertexArray(GL_ScreenVertexArrayID); - glDrawArrays(GL_TRIANGLES, 0, 4*3); - } - - OpenGL_UseShaderProgram(GL_ScreenShaderOSD); - OSD::Update(true, NULL); - - glFlush(); - uiGLSwapBuffers(GLContext); -} - -void MicLoadWav(char* name) -{ - SDL_AudioSpec format; - memset(&format, 0, sizeof(SDL_AudioSpec)); - - if (MicWavBuffer) delete[] MicWavBuffer; - MicWavBuffer = NULL; - MicWavLength = 0; - - u8* buf; - u32 len; - if (!SDL_LoadWAV(name, &format, &buf, &len)) - return; - - const u64 dstfreq = 44100; - - if (format.format == AUDIO_S16 || format.format == AUDIO_U16) - { - int srcinc = format.channels; - len /= (2 * srcinc); - - MicWavLength = (len * dstfreq) / format.freq; - if (MicWavLength < 735) MicWavLength = 735; - MicWavBuffer = new s16[MicWavLength]; - - float res_incr = len / (float)MicWavLength; - float res_timer = 0; - int res_pos = 0; - - for (int i = 0; i < MicWavLength; i++) - { - u16 val = ((u16*)buf)[res_pos]; - if (SDL_AUDIO_ISUNSIGNED(format.format)) val ^= 0x8000; - - MicWavBuffer[i] = val; - - res_timer += res_incr; - while (res_timer >= 1.0) - { - res_timer -= 1.0; - res_pos += srcinc; - } - } - } - else if (format.format == AUDIO_S8 || format.format == AUDIO_U8) - { - int srcinc = format.channels; - len /= srcinc; - - MicWavLength = (len * dstfreq) / format.freq; - if (MicWavLength < 735) MicWavLength = 735; - MicWavBuffer = new s16[MicWavLength]; - - float res_incr = len / (float)MicWavLength; - float res_timer = 0; - int res_pos = 0; - - for (int i = 0; i < MicWavLength; i++) - { - u16 val = buf[res_pos] << 8; - if (SDL_AUDIO_ISUNSIGNED(format.format)) val ^= 0x8000; - - MicWavBuffer[i] = val; - - res_timer += res_incr; - while (res_timer >= 1.0) - { - res_timer -= 1.0; - res_pos += srcinc; - } - } - } - else - printf("bad WAV format %08X\n", format.format); - - SDL_FreeWAV(buf); -} - -void AudioCallback(void* data, Uint8* stream, int len) -{ - len /= (sizeof(s16) * 2); - - // resample incoming audio to match the output sample rate - - float f_len_in = (len * 32823.6328125) / (float)AudioFreq; - f_len_in += AudioSampleFrac; - int len_in = (int)floor(f_len_in); - AudioSampleFrac = f_len_in - len_in; - - s16 buf_in[1024*2]; - s16* buf_out = (s16*)stream; - - int num_in; - int num_out = len; - - SDL_LockMutex(AudioSyncLock); - num_in = SPU::ReadOutput(buf_in, len_in); - SDL_CondSignal(AudioSync); - SDL_UnlockMutex(AudioSyncLock); - - if (num_in < 1) - { - memset(stream, 0, len*sizeof(s16)*2); - return; - } - - int margin = 6; - if (num_in < len_in-margin) - { - int last = num_in-1; - if (last < 0) last = 0; - - for (int i = num_in; i < len_in-margin; i++) - ((u32*)buf_in)[i] = ((u32*)buf_in)[last]; - - num_in = len_in-margin; - } - - float res_incr = num_in / (float)num_out; - float res_timer = 0; - int res_pos = 0; - - int volume = Config::AudioVolume; - - for (int i = 0; i < len; i++) - { - buf_out[i*2 ] = (buf_in[res_pos*2 ] * volume) >> 8; - buf_out[i*2+1] = (buf_in[res_pos*2+1] * volume) >> 8; - - /*s16 s_l = buf_in[res_pos*2 ]; - s16 s_r = buf_in[res_pos*2+1]; - - float a = res_timer; - float b = 1.0 - a; - s_l = (s_l * a) + (buf_in[(res_pos-1)*2 ] * b); - s_r = (s_r * a) + (buf_in[(res_pos-1)*2+1] * b); - - buf_out[i*2 ] = (s_l * volume) >> 8; - buf_out[i*2+1] = (s_r * volume) >> 8;*/ - - res_timer += res_incr; - while (res_timer >= 1.0) - { - res_timer -= 1.0; - res_pos++; - } - } -} - -void MicCallback(void* data, Uint8* stream, int len) -{ - if (Config::MicInputType != 1) return; - - s16* input = (s16*)stream; - len /= sizeof(s16); - - if ((MicBufferWritePos + len) > MicBufferLength) - { - u32 len1 = MicBufferLength - MicBufferWritePos; - memcpy(&MicBuffer[MicBufferWritePos], &input[0], len1*sizeof(s16)); - memcpy(&MicBuffer[0], &input[len1], (len - len1)*sizeof(s16)); - MicBufferWritePos = len - len1; - } - else - { - memcpy(&MicBuffer[MicBufferWritePos], input, len*sizeof(s16)); - MicBufferWritePos += len; - } -} - -void FeedMicInput() -{ - int type = Config::MicInputType; - bool cmd = HotkeyDown(HK_Mic); - - if ((type != 1 && !cmd) || - (type == 1 && MicBufferLength == 0) || - (type == 3 && MicWavBuffer == NULL)) - { - type = 0; - MicBufferReadPos = 0; - } - - switch (type) - { - case 0: // no mic - NDS::MicInputFrame(NULL, 0); - break; - - case 1: // host mic - if ((MicBufferReadPos + 735) > MicBufferLength) - { - s16 tmp[735]; - u32 len1 = MicBufferLength - MicBufferReadPos; - memcpy(&tmp[0], &MicBuffer[MicBufferReadPos], len1*sizeof(s16)); - memcpy(&tmp[len1], &MicBuffer[0], (735 - len1)*sizeof(s16)); - - NDS::MicInputFrame(tmp, 735); - MicBufferReadPos = 735 - len1; - } - else - { - NDS::MicInputFrame(&MicBuffer[MicBufferReadPos], 735); - MicBufferReadPos += 735; - } - break; - - case 2: // white noise - { - s16 tmp[735]; - for (int i = 0; i < 735; i++) tmp[i] = rand() & 0xFFFF; - NDS::MicInputFrame(tmp, 735); - } - break; - - case 3: // WAV - if ((MicBufferReadPos + 735) > MicWavLength) - { - s16 tmp[735]; - u32 len1 = MicWavLength - MicBufferReadPos; - memcpy(&tmp[0], &MicWavBuffer[MicBufferReadPos], len1*sizeof(s16)); - memcpy(&tmp[len1], &MicWavBuffer[0], (735 - len1)*sizeof(s16)); - - NDS::MicInputFrame(tmp, 735); - MicBufferReadPos = 735 - len1; - } - else - { - NDS::MicInputFrame(&MicWavBuffer[MicBufferReadPos], 735); - MicBufferReadPos += 735; - } - break; - } -} - -void OpenJoystick() -{ - if (Joystick) SDL_JoystickClose(Joystick); - - int num = SDL_NumJoysticks(); - if (num < 1) - { - Joystick = NULL; - return; - } - - if (JoystickID >= num) - JoystickID = 0; - - Joystick = SDL_JoystickOpen(JoystickID); -} - -bool JoystickButtonDown(int val) -{ - if (val == -1) return false; - - bool hasbtn = ((val & 0xFFFF) != 0xFFFF); - - if (hasbtn) - { - if (val & 0x100) - { - int hatnum = (val >> 4) & 0xF; - int hatdir = val & 0xF; - Uint8 hatval = SDL_JoystickGetHat(Joystick, hatnum); - - bool pressed = false; - if (hatdir == 0x1) pressed = (hatval & SDL_HAT_UP); - else if (hatdir == 0x4) pressed = (hatval & SDL_HAT_DOWN); - else if (hatdir == 0x2) pressed = (hatval & SDL_HAT_RIGHT); - else if (hatdir == 0x8) pressed = (hatval & SDL_HAT_LEFT); - - if (pressed) return true; - } - else - { - int btnnum = val & 0xFFFF; - Uint8 btnval = SDL_JoystickGetButton(Joystick, btnnum); - - if (btnval) return true; - } - } - - if (val & 0x10000) - { - int axisnum = (val >> 24) & 0xF; - int axisdir = (val >> 20) & 0xF; - Sint16 axisval = SDL_JoystickGetAxis(Joystick, axisnum); - - switch (axisdir) - { - case 0: // positive - if (axisval > 16384) return true; - break; - - case 1: // negative - if (axisval < -16384) return true; - break; - - case 2: // trigger - if (axisval > 0) return true; - break; - } - } - - return false; -} - -void ProcessInput() -{ - SDL_JoystickUpdate(); - - if (Joystick) - { - if (!SDL_JoystickGetAttached(Joystick)) - { - SDL_JoystickClose(Joystick); - Joystick = NULL; - } - } - if (!Joystick && (SDL_NumJoysticks() > 0)) - { - JoystickID = Config::JoystickID; - OpenJoystick(); - } - - JoyInputMask = 0xFFF; - for (int i = 0; i < 12; i++) - if (JoystickButtonDown(Config::JoyMapping[i])) - JoyInputMask &= ~(1<> 4); - - bool pressed = false; - if (btnid == 0x101) // up - pressed = (hat & SDL_HAT_UP); - else if (btnid == 0x104) // down - pressed = (hat & SDL_HAT_DOWN); - else if (btnid == 0x102) // right - pressed = (hat & SDL_HAT_RIGHT); - else if (btnid == 0x108) // left - pressed = (hat & SDL_HAT_LEFT); - else if (btnid < njoybuttons) - pressed = (joybuttons[btnid] & ~(joybuttons[btnid] >> 1)) & 0x01; - - return pressed; -} - -bool JoyButtonHeld(int btnid, int njoybuttons, Uint8* joybuttons, Uint32 hat) -{ - if (btnid < 0) return false; - - bool pressed = false; - if (btnid == 0x101) // up - pressed = (hat & SDL_HAT_UP); - else if (btnid == 0x104) // down - pressed = (hat & SDL_HAT_DOWN); - else if (btnid == 0x102) // right - pressed = (hat & SDL_HAT_RIGHT); - else if (btnid == 0x108) // left - pressed = (hat & SDL_HAT_LEFT); - else if (btnid < njoybuttons) - pressed = joybuttons[btnid] & 0x01; - - return pressed; -} - -void UpdateWindowTitle(void* data) -{ - if (EmuStatus == 0) return; - void** dataarray = (void**)data; - SDL_LockMutex((SDL_mutex*)dataarray[1]); - uiWindowSetTitle(MainWindow, (const char*)dataarray[0]); - SDL_UnlockMutex((SDL_mutex*)dataarray[1]); -} - -void UpdateFPSLimit(void* data) -{ - uiMenuItemSetChecked(MenuItem_LimitFPS, Config::LimitFPS==1); -} - -int EmuThreadFunc(void* burp) -{ - NDS::Init(); - - MainScreenPos[0] = 0; - MainScreenPos[1] = 0; - MainScreenPos[2] = 0; - AutoScreenSizing = 0; - - if (Screen_UseGL) - { - uiGLMakeContextCurrent(GLContext); - GPU3D::InitRenderer(true); - uiGLMakeContextCurrent(NULL); - } - else - { - GPU3D::InitRenderer(false); - } - - Touching = false; - KeyInputMask = 0xFFF; - JoyInputMask = 0xFFF; - KeyHotkeyMask = 0; - JoyHotkeyMask = 0; - HotkeyMask = 0; - LastHotkeyMask = 0; - LidStatus = false; - - u32 nframes = 0; - u32 starttick = SDL_GetTicks(); - u32 lasttick = starttick; - u32 lastmeasuretick = lasttick; - u32 fpslimitcount = 0; - u64 perfcount = SDL_GetPerformanceCounter(); - u64 perffreq = SDL_GetPerformanceFrequency(); - float samplesleft = 0; - u32 nsamples = 0; - - char melontitle[100]; - SDL_mutex* titlemutex = SDL_CreateMutex(); - void* titledata[2] = {melontitle, titlemutex}; - - while (EmuRunning != 0) - { - ProcessInput(); - - if (HotkeyPressed(HK_FastForwardToggle)) - { - Config::LimitFPS = !Config::LimitFPS; - uiQueueMain(UpdateFPSLimit, NULL); - } - // TODO: similar hotkeys for video/audio sync? - - if (HotkeyPressed(HK_Pause)) uiQueueMain(TogglePause, NULL); - if (HotkeyPressed(HK_Reset)) uiQueueMain(Reset, NULL); - - if (GBACart::CartInserted && GBACart::HasSolarSensor) - { - if (HotkeyPressed(HK_SolarSensorDecrease)) - { - if (GBACart_SolarSensor::LightLevel > 0) GBACart_SolarSensor::LightLevel--; - char msg[64]; - sprintf(msg, "Solar sensor level set to %d", GBACart_SolarSensor::LightLevel); - OSD::AddMessage(0, msg); - } - if (HotkeyPressed(HK_SolarSensorIncrease)) - { - if (GBACart_SolarSensor::LightLevel < 10) GBACart_SolarSensor::LightLevel++; - char msg[64]; - sprintf(msg, "Solar sensor level set to %d", GBACart_SolarSensor::LightLevel); - OSD::AddMessage(0, msg); - } - } - - if (EmuRunning == 1) - { - EmuStatus = 1; - - // process input and hotkeys - NDS::SetKeyMask(KeyInputMask & JoyInputMask); - - if (HotkeyPressed(HK_Lid)) - { - LidStatus = !LidStatus; - NDS::SetLidClosed(LidStatus); - OSD::AddMessage(0, LidStatus ? "Lid closed" : "Lid opened"); - } - - // microphone input - FeedMicInput(); - - if (Screen_UseGL) - { - uiGLBegin(GLContext); - uiGLMakeContextCurrent(GLContext); - } - - // auto screen layout - { - MainScreenPos[2] = MainScreenPos[1]; - MainScreenPos[1] = MainScreenPos[0]; - MainScreenPos[0] = NDS::PowerControl9 >> 15; - - int guess; - if (MainScreenPos[0] == MainScreenPos[2] && - MainScreenPos[0] != MainScreenPos[1]) - { - // constant flickering, likely displaying 3D on both screens - // TODO: when both screens are used for 2D only...??? - guess = 0; - } - else - { - if (MainScreenPos[0] == 1) - guess = 1; - else - guess = 2; - } - - if (guess != AutoScreenSizing) - { - AutoScreenSizing = guess; - SetupScreenRects(WindowWidth, WindowHeight); - } - } - - // emulate - u32 nlines = NDS::RunFrame(); - -#ifdef MELONCAP - MelonCap::Update(); -#endif // MELONCAP - - if (EmuRunning == 0) break; - - if (Screen_UseGL) - { - GLScreen_DrawScreen(); - uiGLEnd(GLContext); - } - uiAreaQueueRedrawAll(MainDrawArea); - - bool fastforward = HotkeyDown(HK_FastForward); - - if (Config::AudioSync && !fastforward) - { - SDL_LockMutex(AudioSyncLock); - while (SPU::GetOutputSize() > 1024) - { - int ret = SDL_CondWaitTimeout(AudioSync, AudioSyncLock, 500); - if (ret == SDL_MUTEX_TIMEDOUT) break; - } - SDL_UnlockMutex(AudioSyncLock); - } - else - { - // ensure the audio FIFO doesn't overflow - //SPU::TrimOutput(); - } - - float framerate = (1000.0f * nlines) / (60.0f * 263.0f); - - { - u32 curtick = SDL_GetTicks(); - u32 delay = curtick - lasttick; - - bool limitfps = Config::LimitFPS && !fastforward; - if (limitfps) - { - float wantedtickF = starttick + (framerate * (fpslimitcount+1)); - u32 wantedtick = (u32)ceil(wantedtickF); - if (curtick < wantedtick) SDL_Delay(wantedtick - curtick); - - lasttick = SDL_GetTicks(); - fpslimitcount++; - if ((abs(wantedtickF - (float)wantedtick) < 0.001312) || (fpslimitcount > 60)) - { - fpslimitcount = 0; - nsamples = 0; - starttick = lasttick; - } - } - else - { - if (delay < 1) SDL_Delay(1); - lasttick = SDL_GetTicks(); - } - } - - nframes++; - if (nframes >= 30) - { - u32 tick = SDL_GetTicks(); - u32 diff = tick - lastmeasuretick; - lastmeasuretick = tick; - - u32 fps; - if (diff < 1) fps = 77777; - else fps = (nframes * 1000) / diff; - nframes = 0; - - float fpstarget; - if (framerate < 1) fpstarget = 999; - else fpstarget = 1000.0f/framerate; - - SDL_LockMutex(titlemutex); - sprintf(melontitle, "[%d/%.0f] melonDS " MELONDS_VERSION, fps, fpstarget); - SDL_UnlockMutex(titlemutex); - uiQueueMain(UpdateWindowTitle, titledata); - } - } - else - { - // paused - nframes = 0; - lasttick = SDL_GetTicks(); - starttick = lasttick; - lastmeasuretick = lasttick; - fpslimitcount = 0; - - if (EmuRunning == 2) - { - if (Screen_UseGL) - { - uiGLBegin(GLContext); - uiGLMakeContextCurrent(GLContext); - GLScreen_DrawScreen(); - uiGLEnd(GLContext); - } - uiAreaQueueRedrawAll(MainDrawArea); - } - - if (Screen_UseGL) uiGLMakeContextCurrent(NULL); - - EmuStatus = EmuRunning; - - SDL_Delay(100); - } - } - - EmuStatus = 0; - - SDL_DestroyMutex(titlemutex); - - if (Screen_UseGL) uiGLMakeContextCurrent(GLContext); - - NDS::DeInit(); - Platform::LAN_DeInit(); - - if (Screen_UseGL) - { - OSD::DeInit(true); - GLScreen_DeInit(); - } - else - OSD::DeInit(false); - - if (Screen_UseGL) uiGLMakeContextCurrent(NULL); - - return 44203; -} - -void StopEmuThread() -{ - EmuRunning = 0; - SDL_WaitThread(EmuThread, NULL); -} - - -void OnAreaDraw(uiAreaHandler* handler, uiArea* area, uiAreaDrawParams* params) -{ - if (!ScreenDrawInited) - { - if (ScreenBitmap[0]) uiDrawFreeBitmap(ScreenBitmap[0]); - if (ScreenBitmap[1]) uiDrawFreeBitmap(ScreenBitmap[1]); - - ScreenDrawInited = true; - ScreenBitmap[0] = uiDrawNewBitmap(params->Context, 256, 192, 0); - ScreenBitmap[1] = uiDrawNewBitmap(params->Context, 256, 192, 0); - } - - int frontbuf = GPU::FrontBuffer; - if (!ScreenBitmap[0] || !ScreenBitmap[1]) return; - if (!GPU::Framebuffer[frontbuf][0] || !GPU::Framebuffer[frontbuf][1]) return; - - uiRect top = {0, 0, 256, 192}; - uiRect bot = {0, 0, 256, 192}; - - uiDrawBitmapUpdate(ScreenBitmap[0], GPU::Framebuffer[frontbuf][0]); - uiDrawBitmapUpdate(ScreenBitmap[1], GPU::Framebuffer[frontbuf][1]); - - uiDrawSave(params->Context); - uiDrawTransform(params->Context, &TopScreenTrans); - uiDrawBitmapDraw(params->Context, ScreenBitmap[0], &top, &TopScreenRect, Config::ScreenFilter==1); - uiDrawRestore(params->Context); - - uiDrawSave(params->Context); - uiDrawTransform(params->Context, &BottomScreenTrans); - uiDrawBitmapDraw(params->Context, ScreenBitmap[1], &bot, &BottomScreenRect, Config::ScreenFilter==1); - uiDrawRestore(params->Context); - - OSD::Update(false, params); -} - -void OnAreaMouseEvent(uiAreaHandler* handler, uiArea* area, uiAreaMouseEvent* evt) -{ - int x = (int)evt->X; - int y = (int)evt->Y; - - if (Touching && (evt->Up == 1)) - { - Touching = false; - NDS::ReleaseKey(16+6); - NDS::ReleaseScreen(); - } - else if (!Touching && (evt->Down == 1) && - (x >= BottomScreenRect.X) && (y >= BottomScreenRect.Y) && - (x < (BottomScreenRect.X+BottomScreenRect.Width)) && (y < (BottomScreenRect.Y+BottomScreenRect.Height))) - { - Touching = true; - NDS::PressKey(16+6); - } - - if (Touching) - { - x -= BottomScreenRect.X; - y -= BottomScreenRect.Y; - - if (ScreenRotation == 0 || ScreenRotation == 2) - { - if (BottomScreenRect.Width != 256) - x = (x * 256) / BottomScreenRect.Width; - if (BottomScreenRect.Height != 192) - y = (y * 192) / BottomScreenRect.Height; - - if (ScreenRotation == 2) - { - x = 255 - x; - y = 191 - y; - } - } - else - { - if (BottomScreenRect.Width != 192) - x = (x * 192) / BottomScreenRect.Width; - if (BottomScreenRect.Height != 256) - y = (y * 256) / BottomScreenRect.Height; - - if (ScreenRotation == 1) - { - int tmp = x; - x = y; - y = 191 - tmp; - } - else - { - int tmp = x; - x = 255 - y; - y = tmp; - } - } - - // clamp - if (x < 0) x = 0; - else if (x > 255) x = 255; - if (y < 0) y = 0; - else if (y > 191) y = 191; - - // TODO: take advantage of possible extra precision when possible? (scaled window for example) - NDS::TouchScreen(x, y); - } -} - -void OnAreaMouseCrossed(uiAreaHandler* handler, uiArea* area, int left) -{ -} - -void OnAreaDragBroken(uiAreaHandler* handler, uiArea* area) -{ -} - -bool EventMatchesKey(uiAreaKeyEvent* evt, int val, bool checkmod) -{ - if (val == -1) return false; - - int key = val & 0xFFFF; - int mod = val >> 16; - return evt->Scancode == key && (!checkmod || evt->Modifiers == mod); -} - -int OnAreaKeyEvent(uiAreaHandler* handler, uiArea* area, uiAreaKeyEvent* evt) -{ - // TODO: release all keys if the window loses focus? or somehow global key input? - if (evt->Scancode == 0x38) // ALT - return 0; - if (evt->Modifiers == 0x2) // ALT+key - return 0; - - if (evt->Up) - { - for (int i = 0; i < 12; i++) - if (EventMatchesKey(evt, Config::KeyMapping[i], false)) - KeyInputMask |= (1<Repeat) - { - // TODO, eventually: make savestate keys configurable? - // F keys: 3B-44, 57-58 | SHIFT: mod. 0x4 - if (evt->Scancode >= 0x3B && evt->Scancode <= 0x42) // F1-F8, quick savestate - { - if (evt->Modifiers == 0x4) SaveState(1 + (evt->Scancode - 0x3B)); - else if (evt->Modifiers == 0x0) LoadState(1 + (evt->Scancode - 0x3B)); - } - else if (evt->Scancode == 0x43) // F9, savestate from/to file - { - if (evt->Modifiers == 0x4) SaveState(0); - else if (evt->Modifiers == 0x0) LoadState(0); - } - else if (evt->Scancode == 0x58) // F12, undo savestate - { - if (evt->Modifiers == 0x0) UndoStateLoad(); - } - - for (int i = 0; i < 12; i++) - if (EventMatchesKey(evt, Config::KeyMapping[i], false)) - KeyInputMask &= ~(1<Scancode == 0x57) // F11 - // NDS::debug(0); - } - - return 1; -} - -void SetupScreenRects(int width, int height) -{ - bool horizontal = false; - bool sideways = false; - - if (ScreenRotation == 1 || ScreenRotation == 3) - sideways = true; - - if (ScreenLayout == 2) horizontal = true; - else if (ScreenLayout == 0) - { - if (sideways) - horizontal = true; - } - - int sizemode; - if (ScreenSizing == 3) - sizemode = AutoScreenSizing; - else - sizemode = ScreenSizing; - - int screenW, screenH, gap; - if (sideways) - { - screenW = 192; - screenH = 256; - } - else - { - screenW = 256; - screenH = 192; - } - - gap = ScreenGap; - - uiRect *topscreen, *bottomscreen; - if (ScreenRotation == 1 || ScreenRotation == 2) - { - topscreen = &BottomScreenRect; - bottomscreen = &TopScreenRect; - } - else - { - topscreen = &TopScreenRect; - bottomscreen = &BottomScreenRect; - } - - if (horizontal) - { - // side-by-side - - int heightreq; - int startX = 0; - - width -= gap; - - if (sizemode == 0) // even - { - heightreq = (width * screenH) / (screenW*2); - if (heightreq > height) - { - int newwidth = (height * width) / heightreq; - startX = (width - newwidth) / 2; - heightreq = height; - width = newwidth; - } - } - else // emph. top/bottom - { - heightreq = ((width - screenW) * screenH) / screenW; - if (heightreq > height) - { - int newwidth = ((height * (width - screenW)) / heightreq) + screenW; - startX = (width - newwidth) / 2; - heightreq = height; - width = newwidth; - } - } - - if (sizemode == 2) - { - topscreen->Width = screenW; - topscreen->Height = screenH; - } - else - { - topscreen->Width = (sizemode==0) ? (width / 2) : (width - screenW); - topscreen->Height = heightreq; - } - topscreen->X = startX; - topscreen->Y = ((height - heightreq) / 2) + (heightreq - topscreen->Height); - - bottomscreen->X = topscreen->X + topscreen->Width + gap; - - if (sizemode == 1) - { - bottomscreen->Width = screenW; - bottomscreen->Height = screenH; - } - else - { - bottomscreen->Width = width - topscreen->Width; - bottomscreen->Height = heightreq; - } - bottomscreen->Y = ((height - heightreq) / 2) + (heightreq - bottomscreen->Height); - } - else - { - // top then bottom - - int widthreq; - int startY = 0; - - height -= gap; - - if (sizemode == 0) // even - { - widthreq = (height * screenW) / (screenH*2); - if (widthreq > width) - { - int newheight = (width * height) / widthreq; - startY = (height - newheight) / 2; - widthreq = width; - height = newheight; - } - } - else // emph. top/bottom - { - widthreq = ((height - screenH) * screenW) / screenH; - if (widthreq > width) - { - int newheight = ((width * (height - screenH)) / widthreq) + screenH; - startY = (height - newheight) / 2; - widthreq = width; - height = newheight; - } - } - - if (sizemode == 2) - { - topscreen->Width = screenW; - topscreen->Height = screenH; - } - else - { - topscreen->Width = widthreq; - topscreen->Height = (sizemode==0) ? (height / 2) : (height - screenH); - } - topscreen->Y = startY; - topscreen->X = (width - topscreen->Width) / 2; - - bottomscreen->Y = topscreen->Y + topscreen->Height + gap; - - if (sizemode == 1) - { - bottomscreen->Width = screenW; - bottomscreen->Height = screenH; - } - else - { - bottomscreen->Width = widthreq; - bottomscreen->Height = height - topscreen->Height; - } - bottomscreen->X = (width - bottomscreen->Width) / 2; - } - - // setup matrices for potential rotation - - uiDrawMatrixSetIdentity(&TopScreenTrans); - uiDrawMatrixSetIdentity(&BottomScreenTrans); - - switch (ScreenRotation) - { - case 1: // 90° - { - uiDrawMatrixTranslate(&TopScreenTrans, -TopScreenRect.X, -TopScreenRect.Y); - uiDrawMatrixRotate(&TopScreenTrans, 0, 0, M_PI/2.0f); - uiDrawMatrixScale(&TopScreenTrans, 0, 0, - TopScreenRect.Width/(double)TopScreenRect.Height, - TopScreenRect.Height/(double)TopScreenRect.Width); - uiDrawMatrixTranslate(&TopScreenTrans, TopScreenRect.X+TopScreenRect.Width, TopScreenRect.Y); - - uiDrawMatrixTranslate(&BottomScreenTrans, -BottomScreenRect.X, -BottomScreenRect.Y); - uiDrawMatrixRotate(&BottomScreenTrans, 0, 0, M_PI/2.0f); - uiDrawMatrixScale(&BottomScreenTrans, 0, 0, - BottomScreenRect.Width/(double)BottomScreenRect.Height, - BottomScreenRect.Height/(double)BottomScreenRect.Width); - uiDrawMatrixTranslate(&BottomScreenTrans, BottomScreenRect.X+BottomScreenRect.Width, BottomScreenRect.Y); - } - break; - - case 2: // 180° - { - uiDrawMatrixTranslate(&TopScreenTrans, -TopScreenRect.X, -TopScreenRect.Y); - uiDrawMatrixRotate(&TopScreenTrans, 0, 0, M_PI); - uiDrawMatrixTranslate(&TopScreenTrans, TopScreenRect.X+TopScreenRect.Width, TopScreenRect.Y+TopScreenRect.Height); - - uiDrawMatrixTranslate(&BottomScreenTrans, -BottomScreenRect.X, -BottomScreenRect.Y); - uiDrawMatrixRotate(&BottomScreenTrans, 0, 0, M_PI); - uiDrawMatrixTranslate(&BottomScreenTrans, BottomScreenRect.X+BottomScreenRect.Width, BottomScreenRect.Y+BottomScreenRect.Height); - } - break; - - case 3: // 270° - { - uiDrawMatrixTranslate(&TopScreenTrans, -TopScreenRect.X, -TopScreenRect.Y); - uiDrawMatrixRotate(&TopScreenTrans, 0, 0, -M_PI/2.0f); - uiDrawMatrixScale(&TopScreenTrans, 0, 0, - TopScreenRect.Width/(double)TopScreenRect.Height, - TopScreenRect.Height/(double)TopScreenRect.Width); - uiDrawMatrixTranslate(&TopScreenTrans, TopScreenRect.X, TopScreenRect.Y+TopScreenRect.Height); - - uiDrawMatrixTranslate(&BottomScreenTrans, -BottomScreenRect.X, -BottomScreenRect.Y); - uiDrawMatrixRotate(&BottomScreenTrans, 0, 0, -M_PI/2.0f); - uiDrawMatrixScale(&BottomScreenTrans, 0, 0, - BottomScreenRect.Width/(double)BottomScreenRect.Height, - BottomScreenRect.Height/(double)BottomScreenRect.Width); - uiDrawMatrixTranslate(&BottomScreenTrans, BottomScreenRect.X, BottomScreenRect.Y+BottomScreenRect.Height); - } - break; - } - - GL_ScreenSizeDirty = true; -} - -void SetMinSize(int w, int h) -{ - int cw, ch; - uiWindowContentSize(MainWindow, &cw, &ch); - - uiControlSetMinSize(uiControl(MainDrawArea), w, h); - if ((cw < w) || (ch < h)) - { - if (cw < w) cw = w; - if (ch < h) ch = h; - uiWindowSetContentSize(MainWindow, cw, ch); - } -} - -void OnAreaResize(uiAreaHandler* handler, uiArea* area, int width, int height) -{ - SetupScreenRects(width, height); - - // TODO: - // should those be the size of the uiArea, or the size of the window client area? - // for now the uiArea fills the whole window anyway - // but... we never know, I guess - WindowWidth = width; - WindowHeight = height; - - int ismax = uiWindowMaximized(MainWindow); - int ismin = uiWindowMinimized(MainWindow); - - Config::WindowMaximized = ismax; - if (!ismax && !ismin) - { - Config::WindowWidth = width; - Config::WindowHeight = height; - } - - OSD::WindowResized(Screen_UseGL); -} - - -void Run() -{ - EmuRunning = 1; - RunningSomething = true; - - SPU::InitOutput(); - AudioSampleFrac = 0; - SDL_PauseAudioDevice(AudioDevice, 0); - SDL_PauseAudioDevice(MicDevice, 0); - - uiMenuItemEnable(MenuItem_SaveState); - uiMenuItemEnable(MenuItem_LoadState); - - if (SavestateLoaded) - uiMenuItemEnable(MenuItem_UndoStateLoad); - else - uiMenuItemDisable(MenuItem_UndoStateLoad); - - for (int i = 0; i < 8; i++) - { - char ssfile[1024]; - GetSavestateName(i+1, ssfile, 1024); - if (Platform::FileExists(ssfile)) uiMenuItemEnable(MenuItem_LoadStateSlot[i]); - else uiMenuItemDisable(MenuItem_LoadStateSlot[i]); - } - - for (int i = 0; i < 9; i++) uiMenuItemEnable(MenuItem_SaveStateSlot[i]); - uiMenuItemEnable(MenuItem_LoadStateSlot[8]); - - uiMenuItemEnable(MenuItem_Pause); - uiMenuItemEnable(MenuItem_Reset); - uiMenuItemEnable(MenuItem_Stop); - uiMenuItemSetChecked(MenuItem_Pause, 0); -} - -void TogglePause(void* blarg) -{ - if (!RunningSomething) return; - - if (EmuRunning == 1) - { - // enable pause - EmuRunning = 2; - uiMenuItemSetChecked(MenuItem_Pause, 1); - - SPU::DrainOutput(); - SDL_PauseAudioDevice(AudioDevice, 1); - SDL_PauseAudioDevice(MicDevice, 1); - - OSD::AddMessage(0, "Paused"); - } - else - { - // disable pause - EmuRunning = 1; - uiMenuItemSetChecked(MenuItem_Pause, 0); - - SPU::InitOutput(); - AudioSampleFrac = 0; - SDL_PauseAudioDevice(AudioDevice, 0); - SDL_PauseAudioDevice(MicDevice, 0); - - OSD::AddMessage(0, "Resumed"); - } -} - -void Reset(void* blarg) -{ - if (!RunningSomething) return; - - EmuRunning = 2; - while (EmuStatus != 2); - - SavestateLoaded = false; - uiMenuItemDisable(MenuItem_UndoStateLoad); - - if (ROMPath[0][0] == '\0') - NDS::LoadBIOS(); - else - { - SetupSRAMPath(0); - NDS::LoadROM(ROMPath[0], SRAMPath[0], Config::DirectBoot); - } - - if (ROMPath[1][0] != '\0') - { - SetupSRAMPath(1); - NDS::LoadGBAROM(ROMPath[1], SRAMPath[1]); - } - - Run(); - - OSD::AddMessage(0, "Reset"); -} - -void Stop(bool internal) -{ - EmuRunning = 2; - if (!internal) // if shutting down from the UI thread, wait till the emu thread has stopped - while (EmuStatus != 2); - RunningSomething = false; - - // eject any inserted GBA cartridge - GBACart::Eject(); - ROMPath[1][0] = '\0'; - - uiWindowSetTitle(MainWindow, "melonDS " MELONDS_VERSION); - - for (int i = 0; i < 9; i++) uiMenuItemDisable(MenuItem_SaveStateSlot[i]); - for (int i = 0; i < 9; i++) uiMenuItemDisable(MenuItem_LoadStateSlot[i]); - uiMenuItemDisable(MenuItem_UndoStateLoad); - - uiMenuItemDisable(MenuItem_Pause); - uiMenuItemDisable(MenuItem_Reset); - uiMenuItemDisable(MenuItem_Stop); - uiMenuItemSetChecked(MenuItem_Pause, 0); - - uiAreaQueueRedrawAll(MainDrawArea); - - SPU::DrainOutput(); - SDL_PauseAudioDevice(AudioDevice, 1); - SDL_PauseAudioDevice(MicDevice, 1); - - OSD::AddMessage(0xFFC040, "Shutdown"); -} - -void SetupSRAMPath(int slot) -{ - strncpy(SRAMPath[slot], ROMPath[slot], 1023); - SRAMPath[slot][1023] = '\0'; - strncpy(SRAMPath[slot] + strlen(ROMPath[slot]) - 3, "sav", 3); -} - -void TryLoadROM(char* file, int slot, int prevstatus) -{ - char oldpath[1024]; - char oldsram[1024]; - strncpy(oldpath, ROMPath[slot], 1024); - strncpy(oldsram, SRAMPath[slot], 1024); - - strncpy(ROMPath[slot], file, 1023); - ROMPath[slot][1023] = '\0'; - - SetupSRAMPath(0); - SetupSRAMPath(1); - - if (slot == 0 && NDS::LoadROM(ROMPath[slot], SRAMPath[slot], Config::DirectBoot)) - { - SavestateLoaded = false; - uiMenuItemDisable(MenuItem_UndoStateLoad); - - // Reload the inserted GBA cartridge (if any) - if (ROMPath[1][0] != '\0') NDS::LoadGBAROM(ROMPath[1], SRAMPath[1]); - - strncpy(PrevSRAMPath[slot], SRAMPath[slot], 1024); // safety - Run(); - } - else if (slot == 1 && NDS::LoadGBAROM(ROMPath[slot], SRAMPath[slot])) - { - SavestateLoaded = false; - uiMenuItemDisable(MenuItem_UndoStateLoad); - - strncpy(PrevSRAMPath[slot], SRAMPath[slot], 1024); // safety - if (RunningSomething) Run(); // do not start just from a GBA cart - } - else - { - uiMsgBoxError(MainWindow, - "Failed to load the ROM", - "Make sure the file can be accessed and isn't opened in another application."); - - strncpy(ROMPath[slot], oldpath, 1024); - strncpy(SRAMPath[slot], oldsram, 1024); - EmuRunning = prevstatus; - } -} - - -// SAVESTATE TODO -// * configurable paths. not everyone wants their ROM directory to be polluted, I guess. - -void GetSavestateName(int slot, char* filename, int len) -{ - int pos; - - if (ROMPath[0][0] == '\0') // running firmware, no ROM - { - strcpy(filename, "firmware"); - pos = 8; - } - else - { - int l = strlen(ROMPath[0]); - pos = l; - while (ROMPath[0][pos] != '.' && pos > 0) pos--; - if (pos == 0) pos = l; - - // avoid buffer overflow. shoddy - if (pos > len-5) pos = len-5; - - strncpy(&filename[0], ROMPath[0], pos); - } - strcpy(&filename[pos], ".ml"); - filename[pos+3] = '0'+slot; - filename[pos+4] = '\0'; -} - -void LoadState(int slot) -{ - int prevstatus = EmuRunning; - EmuRunning = 2; - while (EmuStatus != 2); - - char filename[1024]; - - if (slot > 0) - { - GetSavestateName(slot, filename, 1024); - } - else - { - char* file = uiOpenFile(MainWindow, "melonDS savestate (any)|*.ml1;*.ml2;*.ml3;*.ml4;*.ml5;*.ml6;*.ml7;*.ml8;*.mln", Config::LastROMFolder); - if (!file) - { - EmuRunning = prevstatus; - return; - } - - strncpy(filename, file, 1023); - filename[1023] = '\0'; - uiFreeText(file); - } - - if (!Platform::FileExists(filename)) - { - char msg[64]; - if (slot > 0) sprintf(msg, "State slot %d is empty", slot); - else sprintf(msg, "State file does not exist"); - OSD::AddMessage(0xFFA0A0, msg); - - EmuRunning = prevstatus; - return; - } - - u32 oldGBACartCRC = GBACart::CartCRC; - - // backup - Savestate* backup = new Savestate("timewarp.mln", true); - NDS::DoSavestate(backup); - delete backup; - - bool failed = false; - - Savestate* state = new Savestate(filename, false); - if (state->Error) - { - delete state; - - uiMsgBoxError(MainWindow, "Error", "Could not load savestate file."); - - // current state might be crapoed, so restore from sane backup - state = new Savestate("timewarp.mln", false); - failed = true; - } - - NDS::DoSavestate(state); - delete state; - - if (!failed) - { - if (Config::SavestateRelocSRAM && ROMPath[0][0]!='\0') - { - strncpy(PrevSRAMPath[0], SRAMPath[0], 1024); - - strncpy(SRAMPath[0], filename, 1019); - int len = strlen(SRAMPath[0]); - strcpy(&SRAMPath[0][len], ".sav"); - SRAMPath[0][len+4] = '\0'; - - NDS::RelocateSave(SRAMPath[0], false); - } - - bool loadedPartialGBAROM = false; - - // in case we have a GBA cart inserted, and the GBA ROM changes - // due to having loaded a save state, we do not want to reload - // the previous cartridge on reset, or commit writes to any - // loaded save file. therefore, their paths are "nulled". - if (GBACart::CartInserted && GBACart::CartCRC != oldGBACartCRC) - { - ROMPath[1][0] = '\0'; - SRAMPath[1][0] = '\0'; - loadedPartialGBAROM = true; - } - - char msg[64]; - if (slot > 0) sprintf(msg, "State loaded from slot %d%s", - slot, loadedPartialGBAROM ? " (GBA ROM header only)" : ""); - else sprintf(msg, "State loaded from file%s", - loadedPartialGBAROM ? " (GBA ROM header only)" : ""); - OSD::AddMessage(0, msg); - - SavestateLoaded = true; - uiMenuItemEnable(MenuItem_UndoStateLoad); - } - - EmuRunning = prevstatus; -} - -void SaveState(int slot) -{ - int prevstatus = EmuRunning; - EmuRunning = 2; - while (EmuStatus != 2); - - char filename[1024]; - - if (slot > 0) - { - GetSavestateName(slot, filename, 1024); - } - else - { - char* file = uiSaveFile(MainWindow, "melonDS savestate (*.mln)|*.mln", Config::LastROMFolder); - if (!file) - { - EmuRunning = prevstatus; - return; - } - - strncpy(filename, file, 1023); - filename[1023] = '\0'; - uiFreeText(file); - } - - Savestate* state = new Savestate(filename, true); - if (state->Error) - { - delete state; - - uiMsgBoxError(MainWindow, "Error", "Could not save state."); - } - else - { - NDS::DoSavestate(state); - delete state; - - if (slot > 0) - uiMenuItemEnable(MenuItem_LoadStateSlot[slot-1]); - - if (Config::SavestateRelocSRAM && ROMPath[0][0]!='\0') - { - strncpy(SRAMPath[0], filename, 1019); - int len = strlen(SRAMPath[0]); - strcpy(&SRAMPath[0][len], ".sav"); - SRAMPath[0][len+4] = '\0'; - - NDS::RelocateSave(SRAMPath[0], true); - } - } - - char msg[64]; - if (slot > 0) sprintf(msg, "State saved to slot %d", slot); - else sprintf(msg, "State saved to file"); - OSD::AddMessage(0, msg); - - EmuRunning = prevstatus; -} - -void UndoStateLoad() -{ - if (!SavestateLoaded) return; - - int prevstatus = EmuRunning; - EmuRunning = 2; - while (EmuStatus != 2); - - // pray that this works - // what do we do if it doesn't??? - // but it should work. - Savestate* backup = new Savestate("timewarp.mln", false); - NDS::DoSavestate(backup); - delete backup; - - if (ROMPath[0][0]!='\0') - { - strncpy(SRAMPath[0], PrevSRAMPath[0], 1024); - NDS::RelocateSave(SRAMPath[0], false); - } - - OSD::AddMessage(0, "State load undone"); - - EmuRunning = prevstatus; -} - - -void CloseAllDialogs() -{ - DlgAudioSettings::Close(); - DlgEmuSettings::Close(); - DlgInputConfig::Close(0); - DlgInputConfig::Close(1); - DlgVideoSettings::Close(); - DlgWifiSettings::Close(); -} - - -int OnCloseWindow(uiWindow* window, void* blarg) -{ - EmuRunning = 3; - while (EmuStatus != 3); - - CloseAllDialogs(); - StopEmuThread(); - uiQuit(); - return 1; -} - -void OnDropFile(uiWindow* window, char* file, void* blarg) -{ - char* ext = &file[strlen(file)-3]; - int prevstatus = EmuRunning; - - if (!strcasecmp(ext, "nds") || !strcasecmp(ext, "srl")) - { - if (RunningSomething) - { - EmuRunning = 2; - while (EmuStatus != 2); - } - - TryLoadROM(file, 0, prevstatus); - } - else if (!strcasecmp(ext, "gba")) - { - TryLoadROM(file, 1, prevstatus); - } -} - -void OnGetFocus(uiWindow* window, void* blarg) -{ - uiControlSetFocus(uiControl(MainDrawArea)); -} - -void OnLoseFocus(uiWindow* window, void* blarg) -{ - // TODO: shit here? -} - -void OnCloseByMenu(uiMenuItem* item, uiWindow* window, void* blarg) -{ - EmuRunning = 3; - while (EmuStatus != 3); - - CloseAllDialogs(); - StopEmuThread(); - DestroyMainWindow(); - uiQuit(); -} - -void OnOpenFile(uiMenuItem* item, uiWindow* window, void* blarg) -{ - int prevstatus = EmuRunning; - EmuRunning = 2; - while (EmuStatus != 2); - - char* file = uiOpenFile(window, "DS ROM (*.nds)|*.nds;*.srl|GBA ROM (*.gba)|*.gba|Any file|*.*", Config::LastROMFolder); - if (!file) - { - EmuRunning = prevstatus; - return; - } - - int pos = strlen(file)-1; - while (file[pos] != '/' && file[pos] != '\\' && pos > 0) pos--; - strncpy(Config::LastROMFolder, file, pos); - Config::LastROMFolder[pos] = '\0'; - char* ext = &file[strlen(file)-3]; - - if (!strcasecmp(ext, "gba")) - { - TryLoadROM(file, 1, prevstatus); - } - else - { - TryLoadROM(file, 0, prevstatus); - } - - uiFreeText(file); -} - -void OnSaveState(uiMenuItem* item, uiWindow* window, void* param) -{ - int slot = *(int*)param; - SaveState(slot); -} - -void OnLoadState(uiMenuItem* item, uiWindow* window, void* param) -{ - int slot = *(int*)param; - LoadState(slot); -} - -void OnUndoStateLoad(uiMenuItem* item, uiWindow* window, void* param) -{ - UndoStateLoad(); -} - -void OnRun(uiMenuItem* item, uiWindow* window, void* blarg) -{ - if (!RunningSomething) - { - ROMPath[0][0] = '\0'; - NDS::LoadBIOS(); - - if (ROMPath[1][0] != '\0') - { - SetupSRAMPath(1); - NDS::LoadGBAROM(ROMPath[1], SRAMPath[1]); - } - } - - Run(); -} - -void OnPause(uiMenuItem* item, uiWindow* window, void* blarg) -{ - TogglePause(NULL); -} - -void OnReset(uiMenuItem* item, uiWindow* window, void* blarg) -{ - Reset(NULL); -} - -void OnStop(uiMenuItem* item, uiWindow* window, void* blarg) -{ - if (!RunningSomething) return; - - Stop(false); -} - -void OnOpenEmuSettings(uiMenuItem* item, uiWindow* window, void* blarg) -{ - DlgEmuSettings::Open(); -} - -void OnOpenInputConfig(uiMenuItem* item, uiWindow* window, void* blarg) -{ - DlgInputConfig::Open(0); -} - -void OnOpenHotkeyConfig(uiMenuItem* item, uiWindow* window, void* blarg) -{ - DlgInputConfig::Open(1); -} - -void OnOpenVideoSettings(uiMenuItem* item, uiWindow* window, void* blarg) -{ - DlgVideoSettings::Open(); -} - -void OnOpenAudioSettings(uiMenuItem* item, uiWindow* window, void* blarg) -{ - DlgAudioSettings::Open(); -} - -void OnOpenWifiSettings(uiMenuItem* item, uiWindow* window, void* blarg) -{ - DlgWifiSettings::Open(); -} - - -void OnSetSavestateSRAMReloc(uiMenuItem* item, uiWindow* window, void* param) -{ - Config::SavestateRelocSRAM = uiMenuItemChecked(item) ? 1:0; -} - - -void EnsureProperMinSize() -{ - bool isHori = (ScreenRotation == 1 || ScreenRotation == 3); - - int w0 = 256; - int h0 = 192; - int w1 = 256; - int h1 = 192; - - if (ScreenLayout == 0) // natural - { - if (isHori) - SetMinSize(h0+ScreenGap+h1, std::max(w0,w1)); - else - SetMinSize(std::max(w0,w1), h0+ScreenGap+h1); - } - else if (ScreenLayout == 1) // vertical - { - if (isHori) - SetMinSize(std::max(h0,h1), w0+ScreenGap+w1); - else - SetMinSize(std::max(w0,w1), h0+ScreenGap+h1); - } - else // horizontal - { - if (isHori) - SetMinSize(h0+ScreenGap+h1, std::max(w0,w1)); - else - SetMinSize(w0+ScreenGap+w1, std::max(h0,h1)); - } -} - -void OnSetScreenSize(uiMenuItem* item, uiWindow* window, void* param) -{ - int factor = *(int*)param; - bool isHori = (ScreenRotation == 1 || ScreenRotation == 3); - - int w = 256*factor; - int h = 192*factor; - - // FIXME - - if (ScreenLayout == 0) // natural - { - if (isHori) - uiWindowSetContentSize(window, (h*2)+ScreenGap, w); - else - uiWindowSetContentSize(window, w, (h*2)+ScreenGap); - } - else if (ScreenLayout == 1) // vertical - { - if (isHori) - uiWindowSetContentSize(window, h, (w*2)+ScreenGap); - else - uiWindowSetContentSize(window, w, (h*2)+ScreenGap); - } - else // horizontal - { - if (isHori) - uiWindowSetContentSize(window, (h*2)+ScreenGap, w); - else - uiWindowSetContentSize(window, (w*2)+ScreenGap, h); - } -} - -void OnSetScreenRotation(uiMenuItem* item, uiWindow* window, void* param) -{ - int rot = *(int*)param; - - int oldrot = ScreenRotation; - ScreenRotation = rot; - - int w, h; - uiWindowContentSize(window, &w, &h); - - bool isHori = (rot == 1 || rot == 3); - bool wasHori = (oldrot == 1 || oldrot == 3); - - EnsureProperMinSize(); - - if (ScreenLayout == 0) // natural - { - if (isHori ^ wasHori) - { - int blarg = h; - h = w; - w = blarg; - - uiWindowSetContentSize(window, w, h); - } - } - - SetupScreenRects(w, h); - - for (int i = 0; i < 4; i++) - uiMenuItemSetChecked(MenuItem_ScreenRot[i], i==ScreenRotation); -} - -void OnSetScreenGap(uiMenuItem* item, uiWindow* window, void* param) -{ - int gap = *(int*)param; - - //int oldgap = ScreenGap; - ScreenGap = gap; - - EnsureProperMinSize(); - SetupScreenRects(WindowWidth, WindowHeight); - - for (int i = 0; i < 6; i++) - uiMenuItemSetChecked(MenuItem_ScreenGap[i], kScreenGap[i]==ScreenGap); -} - -void OnSetScreenLayout(uiMenuItem* item, uiWindow* window, void* param) -{ - int layout = *(int*)param; - ScreenLayout = layout; - - EnsureProperMinSize(); - SetupScreenRects(WindowWidth, WindowHeight); - - for (int i = 0; i < 3; i++) - uiMenuItemSetChecked(MenuItem_ScreenLayout[i], i==ScreenLayout); -} - -void OnSetScreenSizing(uiMenuItem* item, uiWindow* window, void* param) -{ - int sizing = *(int*)param; - ScreenSizing = sizing; - - SetupScreenRects(WindowWidth, WindowHeight); - - for (int i = 0; i < 4; i++) - uiMenuItemSetChecked(MenuItem_ScreenSizing[i], i==ScreenSizing); -} - -void OnSetScreenFiltering(uiMenuItem* item, uiWindow* window, void* blarg) -{ - int chk = uiMenuItemChecked(item); - if (chk != 0) Config::ScreenFilter = 1; - else Config::ScreenFilter = 0; -} - -void OnSetLimitFPS(uiMenuItem* item, uiWindow* window, void* blarg) -{ - int chk = uiMenuItemChecked(item); - if (chk != 0) Config::LimitFPS = true; - else Config::LimitFPS = false; -} - -void OnSetAudioSync(uiMenuItem* item, uiWindow* window, void* blarg) -{ - int chk = uiMenuItemChecked(item); - if (chk != 0) Config::AudioSync = true; - else Config::AudioSync = false; -} - -void OnSetShowOSD(uiMenuItem* item, uiWindow* window, void* blarg) -{ - int chk = uiMenuItemChecked(item); - if (chk != 0) Config::ShowOSD = true; - else Config::ShowOSD = false; -} - -void ApplyNewSettings(int type) -{ - if (!RunningSomething) - { - if (type == 1) return; - } - - int prevstatus = EmuRunning; - EmuRunning = 3; - while (EmuStatus != 3); - - if (type == 0) // 3D renderer settings - { - if (Screen_UseGL) uiGLMakeContextCurrent(GLContext); - GPU3D::UpdateRendererConfig(); - if (Screen_UseGL) uiGLMakeContextCurrent(NULL); - - GL_3DScale = Config::GL_ScaleFactor; // dorp - GL_ScreenSizeDirty = true; - } - else if (type == 1) // wifi settings - { - if (Wifi::MPInited) - { - Platform::MP_DeInit(); - Platform::MP_Init(); - } - - Platform::LAN_DeInit(); - Platform::LAN_Init(); - } - else if (type == 2) // video output method - { - bool usegl = Config::ScreenUseGL || (Config::_3DRenderer != 0); - if (usegl != Screen_UseGL) - { - if (Screen_UseGL) uiGLMakeContextCurrent(GLContext); - GPU3D::DeInitRenderer(); - OSD::DeInit(Screen_UseGL); - if (Screen_UseGL) uiGLMakeContextCurrent(NULL); - - Screen_UseGL = usegl; - RecreateMainWindow(usegl); - - if (Screen_UseGL) uiGLMakeContextCurrent(GLContext); - GPU3D::InitRenderer(Screen_UseGL); - if (Screen_UseGL) uiGLMakeContextCurrent(NULL); - } - } - else if (type == 3) // 3D renderer - { - if (Screen_UseGL) uiGLMakeContextCurrent(GLContext); - GPU3D::DeInitRenderer(); - GPU3D::InitRenderer(Screen_UseGL); - if (Screen_UseGL) uiGLMakeContextCurrent(NULL); - } - /*else if (type == 4) // vsync - { - if (Screen_UseGL) - { - uiGLMakeContextCurrent(GLContext); - uiGLSetVSync(Config::ScreenVSync); - uiGLMakeContextCurrent(NULL); - } - else - { - // TODO eventually: VSync for non-GL screen? - } - }*/ - - EmuRunning = prevstatus; -} - - -void CreateMainWindowMenu() -{ - uiMenu* menu; - uiMenuItem* menuitem; - - menu = uiNewMenu("File"); - menuitem = uiMenuAppendItem(menu, "Open ROM..."); - uiMenuItemOnClicked(menuitem, OnOpenFile, NULL); - uiMenuAppendSeparator(menu); - { - uiMenu* submenu = uiNewMenu("Save state"); - - for (int i = 0; i < 9; i++) - { - char name[32]; - if (i < 8) - sprintf(name, "%d\tShift+F%d", kSavestateNum[i], kSavestateNum[i]); - else - strcpy(name, "File...\tShift+F9"); - - uiMenuItem* ssitem = uiMenuAppendItem(submenu, name); - uiMenuItemOnClicked(ssitem, OnSaveState, (void*)&kSavestateNum[i]); - - MenuItem_SaveStateSlot[i] = ssitem; - } - - MenuItem_SaveState = uiMenuAppendSubmenu(menu, submenu); - } - { - uiMenu* submenu = uiNewMenu("Load state"); - - for (int i = 0; i < 9; i++) - { - char name[32]; - if (i < 8) - sprintf(name, "%d\tF%d", kSavestateNum[i], kSavestateNum[i]); - else - strcpy(name, "File...\tF9"); - - uiMenuItem* ssitem = uiMenuAppendItem(submenu, name); - uiMenuItemOnClicked(ssitem, OnLoadState, (void*)&kSavestateNum[i]); - - MenuItem_LoadStateSlot[i] = ssitem; - } - - MenuItem_LoadState = uiMenuAppendSubmenu(menu, submenu); - } - menuitem = uiMenuAppendItem(menu, "Undo state load\tF12"); - uiMenuItemOnClicked(menuitem, OnUndoStateLoad, NULL); - MenuItem_UndoStateLoad = menuitem; - uiMenuAppendSeparator(menu); - menuitem = uiMenuAppendItem(menu, "Quit"); - uiMenuItemOnClicked(menuitem, OnCloseByMenu, NULL); - - menu = uiNewMenu("System"); - menuitem = uiMenuAppendItem(menu, "Run"); - uiMenuItemOnClicked(menuitem, OnRun, NULL); - menuitem = uiMenuAppendCheckItem(menu, "Pause"); - uiMenuItemOnClicked(menuitem, OnPause, NULL); - MenuItem_Pause = menuitem; - uiMenuAppendSeparator(menu); - menuitem = uiMenuAppendItem(menu, "Reset"); - uiMenuItemOnClicked(menuitem, OnReset, NULL); - MenuItem_Reset = menuitem; - menuitem = uiMenuAppendItem(menu, "Stop"); - uiMenuItemOnClicked(menuitem, OnStop, NULL); - MenuItem_Stop = menuitem; - - menu = uiNewMenu("Config"); - { - menuitem = uiMenuAppendItem(menu, "Emu settings"); - uiMenuItemOnClicked(menuitem, OnOpenEmuSettings, NULL); - menuitem = uiMenuAppendItem(menu, "Input config"); - uiMenuItemOnClicked(menuitem, OnOpenInputConfig, NULL); - menuitem = uiMenuAppendItem(menu, "Hotkey config"); - uiMenuItemOnClicked(menuitem, OnOpenHotkeyConfig, NULL); - menuitem = uiMenuAppendItem(menu, "Video settings"); - uiMenuItemOnClicked(menuitem, OnOpenVideoSettings, NULL); - menuitem = uiMenuAppendItem(menu, "Audio settings"); - uiMenuItemOnClicked(menuitem, OnOpenAudioSettings, NULL); - menuitem = uiMenuAppendItem(menu, "Wifi settings"); - uiMenuItemOnClicked(menuitem, OnOpenWifiSettings, NULL); - } - uiMenuAppendSeparator(menu); - { - uiMenu* submenu = uiNewMenu("Savestate settings"); - - MenuItem_SavestateSRAMReloc = uiMenuAppendCheckItem(submenu, "Separate savefiles"); - uiMenuItemOnClicked(MenuItem_SavestateSRAMReloc, OnSetSavestateSRAMReloc, NULL); - - uiMenuAppendSubmenu(menu, submenu); - } - uiMenuAppendSeparator(menu); - { - uiMenu* submenu = uiNewMenu("Screen size"); - - for (int i = 0; i < 4; i++) - { - char name[32]; - sprintf(name, "%dx", kScreenSize[i]); - uiMenuItem* item = uiMenuAppendItem(submenu, name); - uiMenuItemOnClicked(item, OnSetScreenSize, (void*)&kScreenSize[i]); - } - - uiMenuAppendSubmenu(menu, submenu); - } - { - uiMenu* submenu = uiNewMenu("Screen rotation"); - - for (int i = 0; i < 4; i++) - { - char name[32]; - sprintf(name, "%d", kScreenRot[i]*90); - MenuItem_ScreenRot[i] = uiMenuAppendCheckItem(submenu, name); - uiMenuItemOnClicked(MenuItem_ScreenRot[i], OnSetScreenRotation, (void*)&kScreenRot[i]); - } - - uiMenuAppendSubmenu(menu, submenu); - } - { - uiMenu* submenu = uiNewMenu("Mid-screen gap"); - - //for (int i = 0; kScreenGap[i] != -1; i++) - for (int i = 0; i < 6; i++) - { - char name[32]; - sprintf(name, "%d pixels", kScreenGap[i]); - MenuItem_ScreenGap[i] = uiMenuAppendCheckItem(submenu, name); - uiMenuItemOnClicked(MenuItem_ScreenGap[i], OnSetScreenGap, (void*)&kScreenGap[i]); - } - - uiMenuAppendSubmenu(menu, submenu); - } - { - uiMenu* submenu = uiNewMenu("Screen layout"); - - MenuItem_ScreenLayout[0] = uiMenuAppendCheckItem(submenu, "Natural"); - uiMenuItemOnClicked(MenuItem_ScreenLayout[0], OnSetScreenLayout, (void*)&kScreenLayout[0]); - MenuItem_ScreenLayout[1] = uiMenuAppendCheckItem(submenu, "Vertical"); - uiMenuItemOnClicked(MenuItem_ScreenLayout[1], OnSetScreenLayout, (void*)&kScreenLayout[1]); - MenuItem_ScreenLayout[2] = uiMenuAppendCheckItem(submenu, "Horizontal"); - uiMenuItemOnClicked(MenuItem_ScreenLayout[2], OnSetScreenLayout, (void*)&kScreenLayout[2]); - - uiMenuAppendSubmenu(menu, submenu); - } - { - uiMenu* submenu = uiNewMenu("Screen sizing"); - - MenuItem_ScreenSizing[0] = uiMenuAppendCheckItem(submenu, "Even"); - uiMenuItemOnClicked(MenuItem_ScreenSizing[0], OnSetScreenSizing, (void*)&kScreenSizing[0]); - MenuItem_ScreenSizing[1] = uiMenuAppendCheckItem(submenu, "Emphasize top"); - uiMenuItemOnClicked(MenuItem_ScreenSizing[1], OnSetScreenSizing, (void*)&kScreenSizing[1]); - MenuItem_ScreenSizing[2] = uiMenuAppendCheckItem(submenu, "Emphasize bottom"); - uiMenuItemOnClicked(MenuItem_ScreenSizing[2], OnSetScreenSizing, (void*)&kScreenSizing[2]); - MenuItem_ScreenSizing[3] = uiMenuAppendCheckItem(submenu, "Auto"); - uiMenuItemOnClicked(MenuItem_ScreenSizing[3], OnSetScreenSizing, (void*)&kScreenSizing[3]); - - uiMenuAppendSubmenu(menu, submenu); - } - - MenuItem_ScreenFilter = uiMenuAppendCheckItem(menu, "Screen filtering"); - uiMenuItemOnClicked(MenuItem_ScreenFilter, OnSetScreenFiltering, NULL); - - MenuItem_ShowOSD = uiMenuAppendCheckItem(menu, "Show OSD"); - uiMenuItemOnClicked(MenuItem_ShowOSD, OnSetShowOSD, NULL); - - uiMenuAppendSeparator(menu); - - MenuItem_LimitFPS = uiMenuAppendCheckItem(menu, "Limit framerate"); - uiMenuItemOnClicked(MenuItem_LimitFPS, OnSetLimitFPS, NULL); - - MenuItem_AudioSync = uiMenuAppendCheckItem(menu, "Audio sync"); - uiMenuItemOnClicked(MenuItem_AudioSync, OnSetAudioSync, NULL); -} - -void CreateMainWindow(bool opengl) -{ - MainWindow = uiNewWindow("melonDS " MELONDS_VERSION, - WindowWidth, WindowHeight, - Config::WindowMaximized, 1, 1); - uiWindowOnClosing(MainWindow, OnCloseWindow, NULL); - - uiWindowSetDropTarget(MainWindow, 1); - uiWindowOnDropFile(MainWindow, OnDropFile, NULL); - - uiWindowOnGetFocus(MainWindow, OnGetFocus, NULL); - uiWindowOnLoseFocus(MainWindow, OnLoseFocus, NULL); - - ScreenDrawInited = false; - bool opengl_good = opengl; - - if (!opengl) MainDrawArea = uiNewArea(&MainDrawAreaHandler); - else MainDrawArea = uiNewGLArea(&MainDrawAreaHandler, kGLVersions); - - uiWindowSetChild(MainWindow, uiControl(MainDrawArea)); - uiControlSetMinSize(uiControl(MainDrawArea), 256, 384); - uiAreaSetBackgroundColor(MainDrawArea, 0, 0, 0); - - uiControlShow(uiControl(MainWindow)); - uiControlSetFocus(uiControl(MainDrawArea)); - - if (opengl_good) - { - GLContext = uiAreaGetGLContext(MainDrawArea); - if (!GLContext) opengl_good = false; - } - if (opengl_good) - { - uiGLMakeContextCurrent(GLContext); - uiGLSetVSync(Config::ScreenVSync); - if (!GLScreen_Init()) opengl_good = false; - if (opengl_good) - { - OpenGL_UseShaderProgram(GL_ScreenShaderOSD); - OSD::Init(true); - } - uiGLMakeContextCurrent(NULL); - } - - if (opengl && !opengl_good) - { - printf("OpenGL: initialization failed\n"); - RecreateMainWindow(false); - Screen_UseGL = false; - } - - if (!opengl) OSD::Init(false); -} - -void DestroyMainWindow() -{ - uiControlDestroy(uiControl(MainWindow)); - - if (ScreenBitmap[0]) uiDrawFreeBitmap(ScreenBitmap[0]); - if (ScreenBitmap[1]) uiDrawFreeBitmap(ScreenBitmap[1]); - - ScreenBitmap[0] = NULL; - ScreenBitmap[1] = NULL; -} - -void RecreateMainWindow(bool opengl) -{ - int winX, winY, maxi; - uiWindowPosition(MainWindow, &winX, &winY); - maxi = uiWindowMaximized(MainWindow); - DestroyMainWindow(); - CreateMainWindow(opengl); - uiWindowSetPosition(MainWindow, winX, winY); - uiWindowSetMaximized(MainWindow, maxi); -} - - -int ___main(int argc, char** argv) -{ - srand(time(NULL)); - - printf("melonDS " MELONDS_VERSION "\n"); - printf(MELONDS_URL "\n"); - -#if defined(__WIN32__) || defined(UNIX_PORTABLE) - if (argc > 0 && strlen(argv[0]) > 0) - { - int len = strlen(argv[0]); - while (len > 0) - { - if (argv[0][len] == '/') break; - if (argv[0][len] == '\\') break; - len--; - } - if (len > 0) - { - EmuDirectory = new char[len+1]; - strncpy(EmuDirectory, argv[0], len); - EmuDirectory[len] = '\0'; - } - else - { - EmuDirectory = new char[2]; - strcpy(EmuDirectory, "."); - } - } - else - { - EmuDirectory = new char[2]; - strcpy(EmuDirectory, "."); - } -#else - const char* confdir = g_get_user_config_dir(); - const char* confname = "/melonDS"; - EmuDirectory = new char[strlen(confdir) + strlen(confname) + 1]; - strcat(EmuDirectory, confdir); - strcat(EmuDirectory, confname); -#endif - - // http://stackoverflow.com/questions/14543333/joystick-wont-work-using-sdl - SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); - - if (SDL_Init(SDL_INIT_HAPTIC) < 0) - { - printf("SDL couldn't init rumble\n"); - } - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0) - { - printf("SDL shat itself :(\n"); - return 1; - } - - SDL_JoystickEventState(SDL_ENABLE); - - uiInitOptions ui_opt; - memset(&ui_opt, 0, sizeof(uiInitOptions)); - const char* ui_err = uiInit(&ui_opt); - if (ui_err != NULL) - { - printf("libui shat itself :( %s\n", ui_err); - uiFreeInitError(ui_err); - return 1; - } - - Config::Load(); - - if (Config::AudioVolume < 0) Config::AudioVolume = 0; - else if (Config::AudioVolume > 256) Config::AudioVolume = 256; - - if (!Platform::LocalFileExists("bios7.bin") || - !Platform::LocalFileExists("bios9.bin") || - !Platform::LocalFileExists("firmware.bin")) - { -#if defined(__WIN32__) || defined(UNIX_PORTABLE) - const char* locationName = "the directory you run melonDS from"; -#else - char* locationName = EmuDirectory; -#endif - char msgboxtext[512]; - sprintf(msgboxtext, - "One or more of the following required files don't exist or couldn't be accessed:\n\n" - "bios7.bin -- ARM7 BIOS\n" - "bios9.bin -- ARM9 BIOS\n" - "firmware.bin -- firmware image\n\n" - "Dump the files from your DS and place them in %s.\n" - "Make sure that the files can be accessed.", - locationName - ); - - uiMsgBoxError(NULL, "BIOS/Firmware not found", msgboxtext); - - uiUninit(); - SDL_Quit(); - return 0; - } - if (!Platform::LocalFileExists("firmware.bin.bak")) - { - // verify the firmware - // - // there are dumps of an old hacked firmware floating around on the internet - // and those are problematic - // the hack predates WFC, and, due to this, any game that alters the WFC - // access point data will brick that firmware due to it having critical - // data in the same area. it has the same problem on hardware. - // - // but this should help stop users from reporting that issue over and over - // again, when the issue is not from melonDS but from their firmware dump. - // - // I don't know about all the firmware hacks in existence, but the one I - // looked at has 0x180 bytes from the header repeated at 0x3FC80, but - // bytes 0x0C-0x14 are different. - - FILE* f = Platform::OpenLocalFile("firmware.bin", "rb"); - u8 chk1[0x180], chk2[0x180]; - - fseek(f, 0, SEEK_SET); - fread(chk1, 1, 0x180, f); - fseek(f, -0x380, SEEK_END); - fread(chk2, 1, 0x180, f); - - memset(&chk1[0x0C], 0, 8); - memset(&chk2[0x0C], 0, 8); - - fclose(f); - - if (!memcmp(chk1, chk2, 0x180)) - { - uiMsgBoxError(NULL, - "Problematic firmware dump", - "You are using an old hacked firmware dump.\n" - "Firmware boot will stop working if you run any game that alters WFC settings.\n\n" - "Note that the issue is not from melonDS, it would also happen on an actual DS."); - } - } - { - const char* romlist_missing = "Save memory type detection will not work correctly.\n\n" - "You should use the latest version of romlist.bin (provided in melonDS release packages)."; -#if !defined(UNIX_PORTABLE) && !defined(__WIN32__) - std::string missingstr = std::string(romlist_missing) + - "\n\nThe ROM list should be placed in " + g_get_user_data_dir() + "/melonds/, otherwise " - "melonDS will search for it in the current working directory."; - const char* romlist_missing_text = missingstr.c_str(); -#else - const char* romlist_missing_text = romlist_missing; -#endif - - FILE* f = Platform::OpenDataFile("romlist.bin"); - if (f) - { - u32 data; - fread(&data, 4, 1, f); - fclose(f); - - if ((data >> 24) == 0) // old CRC-based list - { - uiMsgBoxError(NULL, "Your version of romlist.bin is outdated.", romlist_missing_text); - } - } - else - { - uiMsgBoxError(NULL, "romlist.bin not found.", romlist_missing_text); - } - } - - CreateMainWindowMenu(); - - MainDrawAreaHandler.Draw = OnAreaDraw; - MainDrawAreaHandler.MouseEvent = OnAreaMouseEvent; - MainDrawAreaHandler.MouseCrossed = OnAreaMouseCrossed; - MainDrawAreaHandler.DragBroken = OnAreaDragBroken; - MainDrawAreaHandler.KeyEvent = OnAreaKeyEvent; - MainDrawAreaHandler.Resize = OnAreaResize; - - WindowWidth = Config::WindowWidth; - WindowHeight = Config::WindowHeight; - - Screen_UseGL = Config::ScreenUseGL || (Config::_3DRenderer != 0); - - GL_3DScale = Config::GL_ScaleFactor; - if (GL_3DScale < 1) GL_3DScale = 1; - else if (GL_3DScale > 8) GL_3DScale = 8; - - CreateMainWindow(Screen_UseGL); - - ScreenRotation = Config::ScreenRotation; - ScreenGap = Config::ScreenGap; - ScreenLayout = Config::ScreenLayout; - ScreenSizing = Config::ScreenSizing; - -#define SANITIZE(var, min, max) if ((var < min) || (var > max)) var = 0; - SANITIZE(ScreenRotation, 0, 3); - SANITIZE(ScreenLayout, 0, 2); - SANITIZE(ScreenSizing, 0, 3); -#undef SANITIZE - - for (int i = 0; i < 9; i++) uiMenuItemDisable(MenuItem_SaveStateSlot[i]); - for (int i = 0; i < 9; i++) uiMenuItemDisable(MenuItem_LoadStateSlot[i]); - uiMenuItemDisable(MenuItem_UndoStateLoad); - - uiMenuItemDisable(MenuItem_Pause); - uiMenuItemDisable(MenuItem_Reset); - uiMenuItemDisable(MenuItem_Stop); - - uiMenuItemSetChecked(MenuItem_SavestateSRAMReloc, Config::SavestateRelocSRAM?1:0); - - uiMenuItemSetChecked(MenuItem_ScreenRot[ScreenRotation], 1); - uiMenuItemSetChecked(MenuItem_ScreenLayout[ScreenLayout], 1); - uiMenuItemSetChecked(MenuItem_ScreenSizing[ScreenSizing], 1); - - for (int i = 0; i < 6; i++) - { - if (ScreenGap == kScreenGap[i]) - uiMenuItemSetChecked(MenuItem_ScreenGap[i], 1); - } - - OnSetScreenRotation(MenuItem_ScreenRot[ScreenRotation], MainWindow, (void*)&kScreenRot[ScreenRotation]); - - uiMenuItemSetChecked(MenuItem_ScreenFilter, Config::ScreenFilter==1); - uiMenuItemSetChecked(MenuItem_LimitFPS, Config::LimitFPS==1); - uiMenuItemSetChecked(MenuItem_AudioSync, Config::AudioSync==1); - uiMenuItemSetChecked(MenuItem_ShowOSD, Config::ShowOSD==1); - -#ifdef MELONCAP - MelonCap::Init(); -#endif // MELONCAP - - AudioSync = SDL_CreateCond(); - AudioSyncLock = SDL_CreateMutex(); - - AudioFreq = 48000; // TODO: make configurable? - SDL_AudioSpec whatIwant, whatIget; - memset(&whatIwant, 0, sizeof(SDL_AudioSpec)); - whatIwant.freq = AudioFreq; - whatIwant.format = AUDIO_S16LSB; - whatIwant.channels = 2; - whatIwant.samples = 1024; - whatIwant.callback = AudioCallback; - AudioDevice = SDL_OpenAudioDevice(NULL, 0, &whatIwant, &whatIget, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE); - if (!AudioDevice) - { - printf("Audio init failed: %s\n", SDL_GetError()); - } - else - { - AudioFreq = whatIget.freq; - printf("Audio output frequency: %d Hz\n", AudioFreq); - SDL_PauseAudioDevice(AudioDevice, 1); - } - - memset(&whatIwant, 0, sizeof(SDL_AudioSpec)); - whatIwant.freq = 44100; - whatIwant.format = AUDIO_S16LSB; - whatIwant.channels = 1; - whatIwant.samples = 1024; - whatIwant.callback = MicCallback; - MicDevice = SDL_OpenAudioDevice(NULL, 1, &whatIwant, &whatIget, 0); - if (!MicDevice) - { - printf("Mic init failed: %s\n", SDL_GetError()); - MicBufferLength = 0; - } - else - { - SDL_PauseAudioDevice(MicDevice, 1); - } - - memset(MicBuffer, 0, sizeof(MicBuffer)); - MicBufferReadPos = 0; - MicBufferWritePos = 0; - - MicWavBuffer = NULL; - if (Config::MicInputType == 3) MicLoadWav(Config::MicWavPath); - - JoystickID = Config::JoystickID; - Joystick = NULL; - OpenJoystick(); - - EmuRunning = 2; - RunningSomething = false; - EmuThread = SDL_CreateThread(EmuThreadFunc, "melonDS magic", NULL); - - if (argc > 1) - { - char* file = argv[1]; - char* ext = &file[strlen(file)-3]; - - if (!strcasecmp(ext, "nds") || !strcasecmp(ext, "srl")) - { - strncpy(ROMPath[0], file, 1023); - ROMPath[0][1023] = '\0'; - - SetupSRAMPath(0); - - if (NDS::LoadROM(ROMPath[0], SRAMPath[0], Config::DirectBoot)) - Run(); - } - - if (argc > 2) - { - file = argv[2]; - ext = &file[strlen(file)-3]; - - if (!strcasecmp(ext, "gba")) - { - strncpy(ROMPath[1], file, 1023); - ROMPath[1][1023] = '\0'; - - SetupSRAMPath(1); - - NDS::LoadGBAROM(ROMPath[1], SRAMPath[1]); - } - } - } - - uiMain(); - - if (Joystick) SDL_JoystickClose(Joystick); - if (AudioDevice) SDL_CloseAudioDevice(AudioDevice); - if (MicDevice) SDL_CloseAudioDevice(MicDevice); - - SDL_DestroyCond(AudioSync); - SDL_DestroyMutex(AudioSyncLock); - - if (MicWavBuffer) delete[] MicWavBuffer; - -#ifdef MELONCAP - MelonCap::DeInit(); -#endif // MELONCAP - - if (ScreenBitmap[0]) uiDrawFreeBitmap(ScreenBitmap[0]); - if (ScreenBitmap[1]) uiDrawFreeBitmap(ScreenBitmap[1]); - - Config::ScreenRotation = ScreenRotation; - Config::ScreenGap = ScreenGap; - Config::ScreenLayout = ScreenLayout; - Config::ScreenSizing = ScreenSizing; - - Config::Save(); - - uiUninit(); - SDL_Quit(); - delete[] EmuDirectory; - return 0; -} - - diff --git a/src/libui_sdl/main_shaders.h b/src/libui_sdl/main_shaders.h deleted file mode 100644 index 22d4dd9..0000000 --- a/src/libui_sdl/main_shaders.h +++ /dev/null @@ -1,250 +0,0 @@ -/* - Copyright 2016-2020 Arisotura - - This file is part of melonDS. - - melonDS 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 3 of the License, or (at your option) - any later version. - - melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#ifndef MAIN_SHADERS_H -#define MAIN_SHADERS_H - -const char* kScreenVS = R"(#version 140 - -layout(std140) uniform uConfig -{ - vec2 uScreenSize; - uint u3DScale; - uint uFilterMode; -}; - -in vec2 vPosition; -in vec2 vTexcoord; - -smooth out vec2 fTexcoord; - -void main() -{ - vec4 fpos; - fpos.xy = ((vPosition * 2.0) / uScreenSize) - 1.0; - fpos.y *= -1; - fpos.z = 0.0; - fpos.w = 1.0; - - gl_Position = fpos; - fTexcoord = vTexcoord; -} -)"; - -const char* kScreenFS = R"(#version 140 - -layout(std140) uniform uConfig -{ - vec2 uScreenSize; - uint u3DScale; - uint uFilterMode; -}; - -uniform usampler2D ScreenTex; - -smooth in vec2 fTexcoord; - -out vec4 oColor; - -void main() -{ - ivec4 pixel = ivec4(texelFetch(ScreenTex, ivec2(fTexcoord), 0)); - - // TODO: filters - - oColor = vec4(vec3(pixel.bgr) / 255.0, 1.0); -} -)"; - -const char* kScreenFS_Accel = R"(#version 140 - -layout(std140) uniform uConfig -{ - vec2 uScreenSize; - uint u3DScale; - uint uFilterMode; -}; - -uniform usampler2D ScreenTex; -uniform sampler2D _3DTex; - -smooth in vec2 fTexcoord; - -out vec4 oColor; - -void main() -{ - ivec4 pixel = ivec4(texelFetch(ScreenTex, ivec2(fTexcoord), 0)); - - ivec4 mbright = ivec4(texelFetch(ScreenTex, ivec2(256*3, int(fTexcoord.y)), 0)); - int dispmode = mbright.b & 0x3; - - if (dispmode == 1) - { - ivec4 val1 = pixel; - ivec4 val2 = ivec4(texelFetch(ScreenTex, ivec2(fTexcoord) + ivec2(256,0), 0)); - ivec4 val3 = ivec4(texelFetch(ScreenTex, ivec2(fTexcoord) + ivec2(512,0), 0)); - - int compmode = val3.a & 0xF; - int eva, evb, evy; - - if (compmode == 4) - { - // 3D on top, blending - - float xpos = val3.r + fract(fTexcoord.x); - float ypos = mod(fTexcoord.y, 192); - ivec4 _3dpix = ivec4(texelFetch(_3DTex, ivec2(vec2(xpos, ypos)*u3DScale), 0).bgra - * vec4(63,63,63,31)); - - if (_3dpix.a > 0) - { - eva = (_3dpix.a & 0x1F) + 1; - evb = 32 - eva; - - val1 = ((_3dpix * eva) + (val1 * evb)) >> 5; - if (eva <= 16) val1 += ivec4(1,1,1,0); - val1 = min(val1, 0x3F); - } - else - val1 = val2; - } - else if (compmode == 1) - { - // 3D on bottom, blending - - float xpos = val3.r + fract(fTexcoord.x); - float ypos = mod(fTexcoord.y, 192); - ivec4 _3dpix = ivec4(texelFetch(_3DTex, ivec2(vec2(xpos, ypos)*u3DScale), 0).bgra - * vec4(63,63,63,31)); - - if (_3dpix.a > 0) - { - eva = val3.g; - evb = val3.b; - - val1 = ((val1 * eva) + (_3dpix * evb)) >> 4; - val1 = min(val1, 0x3F); - } - else - val1 = val2; - } - else if (compmode <= 3) - { - // 3D on top, normal/fade - - float xpos = val3.r + fract(fTexcoord.x); - float ypos = mod(fTexcoord.y, 192); - ivec4 _3dpix = ivec4(texelFetch(_3DTex, ivec2(vec2(xpos, ypos)*u3DScale), 0).bgra - * vec4(63,63,63,31)); - - if (_3dpix.a > 0) - { - evy = val3.g; - - val1 = _3dpix; - if (compmode == 2) val1 += ((ivec4(0x3F,0x3F,0x3F,0) - val1) * evy) >> 4; - else if (compmode == 3) val1 -= (val1 * evy) >> 4; - } - else - val1 = val2; - } - - pixel = val1; - } - - if (dispmode != 0) - { - int brightmode = mbright.g >> 6; - if (brightmode == 1) - { - // up - int evy = mbright.r & 0x1F; - if (evy > 16) evy = 16; - - pixel += ((ivec4(0x3F,0x3F,0x3F,0) - pixel) * evy) >> 4; - } - else if (brightmode == 2) - { - // down - int evy = mbright.r & 0x1F; - if (evy > 16) evy = 16; - - pixel -= (pixel * evy) >> 4; - } - } - - pixel.rgb <<= 2; - pixel.rgb |= (pixel.rgb >> 6); - - // TODO: filters - - oColor = vec4(vec3(pixel.rgb) / 255.0, 1.0); -} -)"; - - -const char* kScreenVS_OSD = R"(#version 140 - -layout(std140) uniform uConfig -{ - vec2 uScreenSize; - uint u3DScale; - uint uFilterMode; -}; - -uniform ivec2 uOSDPos; -uniform ivec2 uOSDSize; - -in vec2 vPosition; - -smooth out vec2 fTexcoord; - -void main() -{ - vec4 fpos; - - vec2 osdpos = (vPosition * vec2(uOSDSize)); - fTexcoord = osdpos; - osdpos += uOSDPos; - - fpos.xy = ((osdpos * 2.0) / uScreenSize) - 1.0; - fpos.y *= -1; - fpos.z = 0.0; - fpos.w = 1.0; - - gl_Position = fpos; -} -)"; - -const char* kScreenFS_OSD = R"(#version 140 - -uniform sampler2D OSDTex; - -smooth in vec2 fTexcoord; - -out vec4 oColor; - -void main() -{ - vec4 pixel = texelFetch(OSDTex, ivec2(fTexcoord), 0); - oColor = pixel.bgra; -} -)"; - -#endif // MAIN_SHADERS_H -- cgit v1.2.3 From d58c9d4b53162c0e41fb084d7d8218f6672cc8ab Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 25 Apr 2020 18:56:39 +0200 Subject: blarg --- CMakeLists.txt | 6 ---- src/frontend/qt_sdl/CMakeLists.txt | 73 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 src/frontend/qt_sdl/CMakeLists.txt (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index 048dd44..98c653a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,14 +32,8 @@ endif() add_compile_options(-fno-pic) add_link_options(-no-pie) -option(BUILD_LIBUI "Build libui frontend" ON) - add_subdirectory(src) -if (BUILD_LIBUI) - add_subdirectory(src/libui_sdl) -endif() - configure_file( ${CMAKE_SOURCE_DIR}/romlist.bin ${CMAKE_BINARY_DIR}/romlist.bin COPYONLY) diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt new file mode 100644 index 0000000..e95d24b --- /dev/null +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -0,0 +1,73 @@ +project(qt_sdl) + +SET(SOURCES_LIBUI + main.cpp + Platform.cpp + PlatformConfig.cpp + LAN_Socket.cpp + LAN_PCap.cpp + DlgAudioSettings.cpp + DlgEmuSettings.cpp + DlgInputConfig.cpp + DlgVideoSettings.cpp + DlgWifiSettings.cpp + OSD.cpp +) + +if (WIN32) + set(CMAKE_RC_COMPILE_OBJECT " -i -o ") +endif() + +option(BUILD_SHARED_LIBS "Whether to build libui as a shared library or a static library" ON) +set(BUILD_SHARED_LIBS OFF) +add_subdirectory(libui) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(SDL2 REQUIRED sdl2) + +add_executable(melonDS ${SOURCES_LIBUI}) +target_include_directories(melonDS PRIVATE ${SDL2_INCLUDE_DIRS}) +target_link_libraries(melonDS core libui ${SDL2_LIBRARIES}) + +if (UNIX) + option(UNIX_PORTABLE "Make a portable build that looks for its configuration in the current directory" OFF) + if (UNIX_PORTABLE) + add_definitions(-DUNIX_PORTABLE) + endif() + + find_package(PkgConfig REQUIRED) + pkg_check_modules(GTK3 REQUIRED gtk+-3.0) + + target_include_directories(melonDS PRIVATE ${GTK3_INCLUDE_DIRS}) + target_link_libraries(melonDS ${GTK3_LIBRARIES}) + + ADD_DEFINITIONS(${GTK3_CFLAGS_OTHER}) + + add_custom_command(OUTPUT melon_grc.c + COMMAND glib-compile-resources --sourcedir=${CMAKE_SOURCE_DIR} + --target=${CMAKE_CURRENT_BINARY_DIR}/melon_grc.c + --generate-source "${CMAKE_SOURCE_DIR}/melon_grc.xml" + COMMAND glib-compile-resources --sourcedir=${CMAKE_SOURCE_DIR} + --target=${CMAKE_CURRENT_BINARY_DIR}/melon_grc.h + --generate-header "${CMAKE_SOURCE_DIR}/melon_grc.xml") + + if (CMAKE_SYSTEM_NAME STREQUAL "Linux") + target_link_libraries(melonDS dl) + endif () + + target_sources(melonDS PUBLIC melon_grc.c) +elseif (WIN32) + target_sources(melonDS PUBLIC "${CMAKE_SOURCE_DIR}/melon.rc") + target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..") + target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32) +endif () + +install(FILES ../../net.kuribo64.melonDS.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) +install(FILES ../../icon/melon_16x16.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/16x16/apps RENAME net.kuribo64.melonDS.png) +install(FILES ../../icon/melon_32x32.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/32x32/apps RENAME net.kuribo64.melonDS.png) +install(FILES ../../icon/melon_48x48.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/48x48/apps RENAME net.kuribo64.melonDS.png) +install(FILES ../../icon/melon_64x64.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/64x64/apps RENAME net.kuribo64.melonDS.png) +install(FILES ../../icon/melon_128x128.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/128x128/apps RENAME net.kuribo64.melonDS.png) +install(FILES ../../icon/melon_256x256.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/256x256/apps RENAME net.kuribo64.melonDS.png) +install(FILES ../../romlist.bin DESTINATION ${CMAKE_INSTALL_PREFIX}/share/melonDS) +install(TARGETS melonDS RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) -- cgit v1.2.3 From 0bdafb62951234eab93ea46ba82ea9e2a0fc1277 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 25 Apr 2020 19:31:19 +0200 Subject: finally get this going, I guess --- CMakeLists.txt | 6 ++++++ src/frontend/qt_sdl/CMakeLists.txt | 27 ++++++++------------------- 2 files changed, 14 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index 98c653a..488da81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,8 +32,14 @@ endif() add_compile_options(-fno-pic) add_link_options(-no-pie) +option(BUILD_QT_SDL "Build Qt/SDL frontend" ON) + add_subdirectory(src) +if (BUILD_QT_SDL) + add_subdirectory(src/frontend/qt_sdl) +endif() + configure_file( ${CMAKE_SOURCE_DIR}/romlist.bin ${CMAKE_BINARY_DIR}/romlist.bin COPYONLY) diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index e95d24b..ff2ed09 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -1,33 +1,22 @@ project(qt_sdl) -SET(SOURCES_LIBUI +SET(SOURCES_QT_SDL main.cpp - Platform.cpp - PlatformConfig.cpp - LAN_Socket.cpp - LAN_PCap.cpp - DlgAudioSettings.cpp - DlgEmuSettings.cpp - DlgInputConfig.cpp - DlgVideoSettings.cpp - DlgWifiSettings.cpp - OSD.cpp ) if (WIN32) set(CMAKE_RC_COMPILE_OBJECT " -i -o ") endif() -option(BUILD_SHARED_LIBS "Whether to build libui as a shared library or a static library" ON) -set(BUILD_SHARED_LIBS OFF) -add_subdirectory(libui) +find_package(Qt5 COMPONENTS Core REQUIRED) +find_package(Qt5 COMPONENTS Widgets REQUIRED) find_package(PkgConfig REQUIRED) pkg_check_modules(SDL2 REQUIRED sdl2) -add_executable(melonDS ${SOURCES_LIBUI}) +add_executable(melonDS ${SOURCES_QT_SDL}) target_include_directories(melonDS PRIVATE ${SDL2_INCLUDE_DIRS}) -target_link_libraries(melonDS core libui ${SDL2_LIBRARIES}) +target_link_libraries(melonDS core ${SDL2_LIBRARIES}) if (UNIX) option(UNIX_PORTABLE "Make a portable build that looks for its configuration in the current directory" OFF) @@ -52,14 +41,14 @@ if (UNIX) --generate-header "${CMAKE_SOURCE_DIR}/melon_grc.xml") if (CMAKE_SYSTEM_NAME STREQUAL "Linux") - target_link_libraries(melonDS dl) + target_link_libraries(melonDS dl Qt5::Core Qt5::Widgets) endif () target_sources(melonDS PUBLIC melon_grc.c) elseif (WIN32) target_sources(melonDS PUBLIC "${CMAKE_SOURCE_DIR}/melon.rc") - target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..") - target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32) + target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../..") + target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32 Qt5::Core Qt5::Widgets) endif () install(FILES ../../net.kuribo64.melonDS.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) -- cgit v1.2.3 From 439ca1b2b557040f6d5a2fe1e70dd0f5e4d74484 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 25 Apr 2020 20:43:09 +0200 Subject: get a Qt window showing up. 'tis a start, I guess. --- src/frontend/qt_sdl/CMakeLists.txt | 7 +++++-- src/frontend/qt_sdl/main.cpp | 27 ++++++++++++++++++++------- src/frontend/qt_sdl/main.h | 14 +++++++++++++- 3 files changed, 38 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index ff2ed09..1ee7629 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -9,8 +9,11 @@ if (WIN32) endif() find_package(Qt5 COMPONENTS Core REQUIRED) +find_package(Qt5 COMPONENTS Gui REQUIRED) find_package(Qt5 COMPONENTS Widgets REQUIRED) +set(CMAKE_AUTOMOC ON) + find_package(PkgConfig REQUIRED) pkg_check_modules(SDL2 REQUIRED sdl2) @@ -41,14 +44,14 @@ if (UNIX) --generate-header "${CMAKE_SOURCE_DIR}/melon_grc.xml") if (CMAKE_SYSTEM_NAME STREQUAL "Linux") - target_link_libraries(melonDS dl Qt5::Core Qt5::Widgets) + target_link_libraries(melonDS dl Qt5::Core Qt5::Gui Qt5::Widgets) endif () target_sources(melonDS PUBLIC melon_grc.c) elseif (WIN32) target_sources(melonDS PUBLIC "${CMAKE_SOURCE_DIR}/melon.rc") target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../..") - target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32 Qt5::Core Qt5::Widgets) + target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32 Qt5::Core Qt5::Gui Qt5::Widgets) endif () install(FILES ../../net.kuribo64.melonDS.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 0b9d15e..0eb84a5 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -21,15 +21,26 @@ #include #include -// Qt includes and shit here, I guess -#include +#include +#include #include "main.h" #include "../../version.h" -// +MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) +{ + setWindowTitle("melonDS - assfucking Qt version"); + + // burp + QWidget *centralWidget = new QWidget(this); + setCentralWidget(centralWidget); +} + +MainWindow::~MainWindow() +{ +} int main(int argc, char** argv) @@ -39,10 +50,12 @@ int main(int argc, char** argv) printf("melonDS " MELONDS_VERSION "\n"); printf(MELONDS_URL "\n"); - printf("Arisotura hereby admits defeat\n"); - printf("NI DIEU NI MAITRE\n"); + QApplication melon(argc, argv); + + MainWindow win; + win.show(); - return 0; + return melon.exec(); } #ifdef __WIN32__ @@ -59,7 +72,7 @@ int CALLBACK WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int cmdsho for (int i = 0; i < argc; i++) { int len = WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1, NULL, 0, NULL, NULL); - if (len < 1) return NULL; + if (len < 1) { argv[i] = nullarg; continue; } argv[i] = new char[len]; int res = WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1, argv[i], len, NULL, NULL); if (res != len) { delete[] argv[i]; argv[i] = nullarg; } diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 65d6518..ad795ef 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -19,6 +19,18 @@ #ifndef MAIN_H #define MAIN_H -// put the class shit here +#include + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget* parent = nullptr); + ~MainWindow(); + +private: + // private shit goes here +}; #endif // MAIN_H -- cgit v1.2.3 From 690f9f38744ddda7fd65c299288227767e4b03f0 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 27 Apr 2020 12:06:44 +0200 Subject: get some of the shit going, I guess atleast the emuthread is going and we have its control system down and other fun shit, too --- src/CMakeLists.txt | 1 + src/frontend/qt_sdl/CMakeLists.txt | 2 + src/frontend/qt_sdl/Platform.cpp | 558 ++++++++++++++++++++++++++++++++ src/frontend/qt_sdl/PlatformConfig.cpp | 151 +++++++++ src/frontend/qt_sdl/PlatformConfig.h | 82 +++++ src/frontend/qt_sdl/main.cpp | 570 ++++++++++++++++++++++++++++++++- src/frontend/qt_sdl/main.h | 42 ++- 7 files changed, 1397 insertions(+), 9 deletions(-) create mode 100644 src/frontend/qt_sdl/Platform.cpp create mode 100644 src/frontend/qt_sdl/PlatformConfig.cpp create mode 100644 src/frontend/qt_sdl/PlatformConfig.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5537e6d..64d922c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,6 +21,7 @@ add_library(core STATIC NDS.cpp NDSCart.cpp OpenGLSupport.cpp + Platform.h RTC.cpp Savestate.cpp SPI.cpp diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index 1ee7629..f24464d 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -2,6 +2,8 @@ project(qt_sdl) SET(SOURCES_QT_SDL main.cpp + Platform.cpp + PlatformConfig.cpp ) if (WIN32) diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp new file mode 100644 index 0000000..31b5277 --- /dev/null +++ b/src/frontend/qt_sdl/Platform.cpp @@ -0,0 +1,558 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include +#include +#include +#include +#include "Platform.h" +#include "PlatformConfig.h" +//#include "LAN_Socket.h" +//#include "LAN_PCap.h" +#include + +#ifdef __WIN32__ + #define NTDDI_VERSION 0x06000000 // GROSS FUCKING HACK + #include + //#include // FUCK THAT SHIT + extern "C" const GUID DECLSPEC_SELECTANY FOLDERID_RoamingAppData = {0x3eb685db, 0x65f9, 0x4cf6, {0xa0, 0x3a, 0xe3, 0xef, 0x65, 0x72, 0x9f, 0x3d}}; + #include + #include + #include + #define socket_t SOCKET + #define sockaddr_t SOCKADDR +#else + #include + #include + #include + #include + #include + #include + #define socket_t int + #define sockaddr_t struct sockaddr + #define closesocket close +#endif + +#ifndef INVALID_SOCKET +#define INVALID_SOCKET (socket_t)-1 +#endif + + +extern char* EmuDirectory; + +void Stop(bool internal); + + +namespace Platform +{ + + +typedef struct +{ + SDL_Thread* ID; + void (*Func)(); + +} ThreadData; + +int ThreadEntry(void* data) +{ + ThreadData* thread = (ThreadData*)data; + thread->Func(); + return 0; +} + + +socket_t MPSocket; +sockaddr_t MPSendAddr; +u8 PacketBuffer[2048]; + +#define NIFI_VER 1 + + +void StopEmu() +{ + //Stop(true); +} + + +FILE* OpenFile(const char* path, const char* mode, bool mustexist) +{ + FILE* ret; + +#ifdef __WIN32__ + + int len = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0); + if (len < 1) return NULL; + WCHAR* fatpath = new WCHAR[len]; + int res = MultiByteToWideChar(CP_UTF8, 0, path, -1, fatpath, len); + if (res != len) { delete[] fatpath; return NULL; } // checkme? + + // this will be more than enough + WCHAR fatmode[4]; + fatmode[0] = mode[0]; + fatmode[1] = mode[1]; + fatmode[2] = mode[2]; + fatmode[3] = 0; + + if (mustexist) + { + ret = _wfopen(fatpath, L"rb"); + if (ret) ret = _wfreopen(fatpath, fatmode, ret); + } + else + ret = _wfopen(fatpath, fatmode); + + delete[] fatpath; + +#else + + if (mustexist) + { + ret = fopen(path, "rb"); + if (ret) ret = freopen(path, mode, ret); + } + else + ret = fopen(path, mode); + +#endif + + return ret; +} + +#if !defined(UNIX_PORTABLE) && !defined(__WIN32__) + +FILE* OpenLocalFile(const char* path, const char* mode) +{ + std::string fullpath; + if (path[0] == '/') + { + // If it's an absolute path, just open that. + fullpath = std::string(path); + } + else + { + // Check user configuration directory + std::string confpath = std::string(g_get_user_config_dir()) + "/melonDS/"; + g_mkdir_with_parents(confpath.c_str(), 0755); + fullpath = confpath + path; + } + + return OpenFile(fullpath.c_str(), mode, mode[0] != 'w'); +} + +FILE* OpenDataFile(const char* path) +{ + const char* melondir = "melonDS"; + const char* const* sys_dirs = g_get_system_data_dirs(); + const char* user_dir = g_get_user_data_dir(); + + // First check the user's data directory + char* fullpath = g_build_path("/", user_dir, melondir, path, NULL); + if (access(fullpath, R_OK) == 0) + { + FILE* f = fopen(fullpath, "r"); + g_free(fullpath); + return f; + } + free(fullpath); + + // Then check the system data directories + for (size_t i = 0; sys_dirs[i] != NULL; i++) + { + const char* dir = sys_dirs[i]; + char* fullpath = g_build_path("/", dir, melondir, path, NULL); + + if (access(fullpath, R_OK) == 0) + { + FILE* f = fopen(fullpath, "r"); + g_free(fullpath); + return f; + } + free(fullpath); + } + + FILE* f = fopen(path, "rb"); + if (f) return f; + + return NULL; +} + +#else + +FILE* OpenLocalFile(const char* path, const char* mode) +{ + bool relpath = false; + int pathlen = strlen(path); + +#ifdef __WIN32__ + if (pathlen > 3) + { + if (path[1] == ':' && path[2] == '\\') + return OpenFile(path, mode); + } +#else + if (pathlen > 1) + { + if (path[0] == '/') + return OpenFile(path, mode); + } +#endif + + if (pathlen >= 3) + { + if (path[0] == '.' && path[1] == '.' && (path[2] == '/' || path[2] == '\\')) + relpath = true; + } + + int emudirlen = strlen(EmuDirectory); + char* emudirpath; + if (emudirlen) + { + int len = emudirlen + 1 + pathlen + 1; + emudirpath = new char[len]; + strncpy(&emudirpath[0], EmuDirectory, emudirlen); + emudirpath[emudirlen] = '/'; + strncpy(&emudirpath[emudirlen+1], path, pathlen); + emudirpath[emudirlen+1+pathlen] = '\0'; + } + else + { + emudirpath = new char[pathlen+1]; + strncpy(&emudirpath[0], path, pathlen); + emudirpath[pathlen] = '\0'; + } + + // Locations are application directory, and AppData/melonDS on Windows or XDG_CONFIG_HOME/melonDS on Linux + + FILE* f; + + // First check current working directory + f = OpenFile(path, mode, true); + if (f) { delete[] emudirpath; return f; } + + // then emu directory + f = OpenFile(emudirpath, mode, true); + if (f) { delete[] emudirpath; return f; } + +#ifdef __WIN32__ + + // a path relative to AppData wouldn't make much sense + if (!relpath) + { + // Now check AppData + PWSTR appDataPath = NULL; + SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &appDataPath); + if (!appDataPath) + { + delete[] emudirpath; + return NULL; + } + + // this will be more than enough + WCHAR fatperm[4]; + fatperm[0] = mode[0]; + fatperm[1] = mode[1]; + fatperm[2] = mode[2]; + fatperm[3] = 0; + + int fnlen = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0); + if (fnlen < 1) { delete[] emudirpath; return NULL; } + WCHAR* wfileName = new WCHAR[fnlen]; + int res = MultiByteToWideChar(CP_UTF8, 0, path, -1, wfileName, fnlen); + if (res != fnlen) { delete[] wfileName; delete[] emudirpath; return NULL; } // checkme? + + const WCHAR* appdir = L"\\melonDS\\"; + + int pos = wcslen(appDataPath); + void* ptr = CoTaskMemRealloc(appDataPath, (pos+wcslen(appdir)+fnlen+1)*sizeof(WCHAR)); + if (!ptr) { delete[] wfileName; delete[] emudirpath; return NULL; } // oh well + appDataPath = (PWSTR)ptr; + + wcscpy(&appDataPath[pos], appdir); pos += wcslen(appdir); + wcscpy(&appDataPath[pos], wfileName); + + f = _wfopen(appDataPath, L"rb"); + if (f) f = _wfreopen(appDataPath, fatperm, f); + CoTaskMemFree(appDataPath); + delete[] wfileName; + if (f) { delete[] emudirpath; return f; } + } + +#else + + if (!relpath) + { + // Now check XDG_CONFIG_HOME + // TODO: check for memory leak there + std::string fullpath = std::string(g_get_user_config_dir()) + "/melonDS/" + path; + f = OpenFile(fullpath.c_str(), mode, true); + if (f) { delete[] emudirpath; return f; } + } + +#endif + + if (mode[0] != 'r') + { + f = OpenFile(emudirpath, mode); + if (f) { delete[] emudirpath; return f; } + } + + delete[] emudirpath; + return NULL; +} + +FILE* OpenDataFile(const char* path) +{ + return OpenLocalFile(path, "rb"); +} + +#endif + + +void* Thread_Create(void (*func)()) +{ + ThreadData* data = new ThreadData; + data->Func = func; + data->ID = SDL_CreateThread(ThreadEntry, "melonDS core thread", data); + return data; +} + +void Thread_Free(void* thread) +{ + delete (ThreadData*)thread; +} + +void Thread_Wait(void* thread) +{ + SDL_WaitThread((SDL_Thread*)((ThreadData*)thread)->ID, NULL); +} + + +void* Semaphore_Create() +{ + return SDL_CreateSemaphore(0); +} + +void Semaphore_Free(void* sema) +{ + SDL_DestroySemaphore((SDL_sem*)sema); +} + +void Semaphore_Reset(void* sema) +{ + while (SDL_SemTryWait((SDL_sem*)sema) == 0); +} + +void Semaphore_Wait(void* sema) +{ + SDL_SemWait((SDL_sem*)sema); +} + +void Semaphore_Post(void* sema) +{ + SDL_SemPost((SDL_sem*)sema); +} + + +void* GL_GetProcAddress(const char* proc) +{ + return NULL;//uiGLGetProcAddress(proc); +} + + +bool MP_Init() +{ + int opt_true = 1; + int res; + +#ifdef __WIN32__ + WSADATA wsadata; + if (WSAStartup(MAKEWORD(2, 2), &wsadata) != 0) + { + return false; + } +#endif // __WIN32__ + + MPSocket = socket(AF_INET, SOCK_DGRAM, 0); + if (MPSocket < 0) + { + return false; + } + + res = setsockopt(MPSocket, SOL_SOCKET, SO_REUSEADDR, (const char*)&opt_true, sizeof(int)); + if (res < 0) + { + closesocket(MPSocket); + MPSocket = INVALID_SOCKET; + return false; + } + + sockaddr_t saddr; + saddr.sa_family = AF_INET; + *(u32*)&saddr.sa_data[2] = htonl(Config::SocketBindAnyAddr ? INADDR_ANY : INADDR_LOOPBACK); + *(u16*)&saddr.sa_data[0] = htons(7064); + res = bind(MPSocket, &saddr, sizeof(sockaddr_t)); + if (res < 0) + { + closesocket(MPSocket); + MPSocket = INVALID_SOCKET; + return false; + } + + res = setsockopt(MPSocket, SOL_SOCKET, SO_BROADCAST, (const char*)&opt_true, sizeof(int)); + if (res < 0) + { + closesocket(MPSocket); + MPSocket = INVALID_SOCKET; + return false; + } + + MPSendAddr.sa_family = AF_INET; + *(u32*)&MPSendAddr.sa_data[2] = htonl(INADDR_BROADCAST); + *(u16*)&MPSendAddr.sa_data[0] = htons(7064); + + return true; +} + +void MP_DeInit() +{ + if (MPSocket >= 0) + closesocket(MPSocket); + +#ifdef __WIN32__ + WSACleanup(); +#endif // __WIN32__ +} + +int MP_SendPacket(u8* data, int len) +{ + if (MPSocket < 0) + return 0; + + if (len > 2048-8) + { + printf("MP_SendPacket: error: packet too long (%d)\n", len); + return 0; + } + + *(u32*)&PacketBuffer[0] = htonl(0x4946494E); // NIFI + PacketBuffer[4] = NIFI_VER; + PacketBuffer[5] = 0; + *(u16*)&PacketBuffer[6] = htons(len); + memcpy(&PacketBuffer[8], data, len); + + int slen = sendto(MPSocket, (const char*)PacketBuffer, len+8, 0, &MPSendAddr, sizeof(sockaddr_t)); + if (slen < 8) return 0; + return slen - 8; +} + +int MP_RecvPacket(u8* data, bool block) +{ + if (MPSocket < 0) + return 0; + + fd_set fd; + struct timeval tv; + + FD_ZERO(&fd); + FD_SET(MPSocket, &fd); + tv.tv_sec = 0; + tv.tv_usec = block ? 5000 : 0; + + if (!select(MPSocket+1, &fd, 0, 0, &tv)) + { + return 0; + } + + sockaddr_t fromAddr; + socklen_t fromLen = sizeof(sockaddr_t); + int rlen = recvfrom(MPSocket, (char*)PacketBuffer, 2048, 0, &fromAddr, &fromLen); + if (rlen < 8+24) + { + return 0; + } + rlen -= 8; + + if (ntohl(*(u32*)&PacketBuffer[0]) != 0x4946494E) + { + return 0; + } + + if (PacketBuffer[4] != NIFI_VER) + { + return 0; + } + + if (ntohs(*(u16*)&PacketBuffer[6]) != rlen) + { + return 0; + } + + memcpy(data, &PacketBuffer[8], rlen); + return rlen; +} + + + +bool LAN_Init() +{ + /*if (Config::DirectLAN) + { + if (!LAN_PCap::Init(true)) + return false; + } + else + { + if (!LAN_Socket::Init()) + return false; + }*/ + + return true; +} + +void LAN_DeInit() +{ + // checkme. blarg + //if (Config::DirectLAN) + // LAN_PCap::DeInit(); + //else + // LAN_Socket::DeInit(); + /*LAN_PCap::DeInit(); + LAN_Socket::DeInit();*/ +} + +int LAN_SendPacket(u8* data, int len) +{ + /*if (Config::DirectLAN) + return LAN_PCap::SendPacket(data, len); + else + return LAN_Socket::SendPacket(data, len);*/ + return 0; +} + +int LAN_RecvPacket(u8* data) +{ + /*if (Config::DirectLAN) + return LAN_PCap::RecvPacket(data); + else + return LAN_Socket::RecvPacket(data);*/ + return 0; +} + + +} diff --git a/src/frontend/qt_sdl/PlatformConfig.cpp b/src/frontend/qt_sdl/PlatformConfig.cpp new file mode 100644 index 0000000..f78b195 --- /dev/null +++ b/src/frontend/qt_sdl/PlatformConfig.cpp @@ -0,0 +1,151 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include +#include +#include +#include "PlatformConfig.h" + +namespace Config +{ + +int KeyMapping[12]; +int JoyMapping[12]; + +int HKKeyMapping[HK_MAX]; +int HKJoyMapping[HK_MAX]; + +int JoystickID; + +int WindowWidth; +int WindowHeight; +int WindowMaximized; + +int ScreenRotation; +int ScreenGap; +int ScreenLayout; +int ScreenSizing; +int ScreenFilter; + +int ScreenUseGL; +int ScreenVSync; +int ScreenRatio; + +int LimitFPS; +int AudioSync; +int ShowOSD; + +int DirectBoot; + +int SocketBindAnyAddr; +char LANDevice[128]; +int DirectLAN; + +int SavestateRelocSRAM; + +int AudioVolume; +int MicInputType; +char MicWavPath[512]; + +char LastROMFolder[512]; + + +ConfigEntry PlatformConfigFile[] = +{ + {"Key_A", 0, &KeyMapping[0], 32, NULL, 0}, + {"Key_B", 0, &KeyMapping[1], 31, NULL, 0}, + {"Key_Select", 0, &KeyMapping[2], 57, NULL, 0}, + {"Key_Start", 0, &KeyMapping[3], 28, NULL, 0}, + {"Key_Right", 0, &KeyMapping[4], 333, NULL, 0}, + {"Key_Left", 0, &KeyMapping[5], 331, NULL, 0}, + {"Key_Up", 0, &KeyMapping[6], 328, NULL, 0}, + {"Key_Down", 0, &KeyMapping[7], 336, NULL, 0}, + {"Key_R", 0, &KeyMapping[8], 54, NULL, 0}, + {"Key_L", 0, &KeyMapping[9], 86, NULL, 0}, + {"Key_X", 0, &KeyMapping[10], 17, NULL, 0}, + {"Key_Y", 0, &KeyMapping[11], 30, NULL, 0}, + + {"Joy_A", 0, &JoyMapping[0], -1, NULL, 0}, + {"Joy_B", 0, &JoyMapping[1], -1, NULL, 0}, + {"Joy_Select", 0, &JoyMapping[2], -1, NULL, 0}, + {"Joy_Start", 0, &JoyMapping[3], -1, NULL, 0}, + {"Joy_Right", 0, &JoyMapping[4], -1, NULL, 0}, + {"Joy_Left", 0, &JoyMapping[5], -1, NULL, 0}, + {"Joy_Up", 0, &JoyMapping[6], -1, NULL, 0}, + {"Joy_Down", 0, &JoyMapping[7], -1, NULL, 0}, + {"Joy_R", 0, &JoyMapping[8], -1, NULL, 0}, + {"Joy_L", 0, &JoyMapping[9], -1, NULL, 0}, + {"Joy_X", 0, &JoyMapping[10], -1, NULL, 0}, + {"Joy_Y", 0, &JoyMapping[11], -1, NULL, 0}, + + {"HKKey_Lid", 0, &HKKeyMapping[HK_Lid], 0x0D, NULL, 0}, + {"HKKey_Mic", 0, &HKKeyMapping[HK_Mic], 0x35, NULL, 0}, + {"HKKey_Pause", 0, &HKKeyMapping[HK_Pause], -1, NULL, 0}, + {"HKKey_Reset", 0, &HKKeyMapping[HK_Reset], -1, NULL, 0}, + {"HKKey_FastForward", 0, &HKKeyMapping[HK_FastForward], 0x0F, NULL, 0}, + {"HKKey_FastForwardToggle", 0, &HKKeyMapping[HK_FastForwardToggle], -1, NULL, 0}, + {"HKKey_SolarSensorDecrease", 0, &HKKeyMapping[HK_SolarSensorDecrease], 0x4B, NULL, 0}, + {"HKKey_SolarSensorIncrease", 0, &HKKeyMapping[HK_SolarSensorIncrease], 0x4D, NULL, 0}, + + {"HKJoy_Lid", 0, &HKJoyMapping[HK_Lid], -1, NULL, 0}, + {"HKJoy_Mic", 0, &HKJoyMapping[HK_Mic], -1, NULL, 0}, + {"HKJoy_Pause", 0, &HKJoyMapping[HK_Pause], -1, NULL, 0}, + {"HKJoy_Reset", 0, &HKJoyMapping[HK_Reset], -1, NULL, 0}, + {"HKJoy_FastForward", 0, &HKJoyMapping[HK_FastForward], -1, NULL, 0}, + {"HKJoy_FastForwardToggle", 0, &HKJoyMapping[HK_FastForwardToggle], -1, NULL, 0}, + {"HKJoy_SolarSensorDecrease", 0, &HKJoyMapping[HK_SolarSensorDecrease], -1, NULL, 0}, + {"HKJoy_SolarSensorIncrease", 0, &HKJoyMapping[HK_SolarSensorIncrease], -1, NULL, 0}, + + {"JoystickID", 0, &JoystickID, 0, NULL, 0}, + + {"WindowWidth", 0, &WindowWidth, 256, NULL, 0}, + {"WindowHeight", 0, &WindowHeight, 384, NULL, 0}, + {"WindowMax", 0, &WindowMaximized, 0, NULL, 0}, + + {"ScreenRotation", 0, &ScreenRotation, 0, NULL, 0}, + {"ScreenGap", 0, &ScreenGap, 0, NULL, 0}, + {"ScreenLayout", 0, &ScreenLayout, 0, NULL, 0}, + {"ScreenSizing", 0, &ScreenSizing, 0, NULL, 0}, + {"ScreenFilter", 0, &ScreenFilter, 1, NULL, 0}, + + {"ScreenUseGL", 0, &ScreenUseGL, 1, NULL, 0}, + {"ScreenVSync", 0, &ScreenVSync, 0, NULL, 0}, + {"ScreenRatio", 0, &ScreenRatio, 0, NULL, 0}, + + {"LimitFPS", 0, &LimitFPS, 0, NULL, 0}, + {"AudioSync", 0, &AudioSync, 1, NULL, 0}, + {"ShowOSD", 0, &ShowOSD, 1, NULL, 0}, + + {"DirectBoot", 0, &DirectBoot, 1, NULL, 0}, + + {"SockBindAnyAddr", 0, &SocketBindAnyAddr, 0, NULL, 0}, + {"LANDevice", 1, LANDevice, 0, "", 127}, + {"DirectLAN", 0, &DirectLAN, 0, NULL, 0}, + + {"SavStaRelocSRAM", 0, &SavestateRelocSRAM, 0, NULL, 0}, + + {"AudioVolume", 0, &AudioVolume, 256, NULL, 0}, + {"MicInputType", 0, &MicInputType, 1, NULL, 0}, + {"MicWavPath", 1, MicWavPath, 0, "", 511}, + + {"LastROMFolder", 1, LastROMFolder, 0, "", 511}, + + {"", -1, NULL, 0, NULL, 0} +}; + +} diff --git a/src/frontend/qt_sdl/PlatformConfig.h b/src/frontend/qt_sdl/PlatformConfig.h new file mode 100644 index 0000000..d0f765b --- /dev/null +++ b/src/frontend/qt_sdl/PlatformConfig.h @@ -0,0 +1,82 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef PLATFORMCONFIG_H +#define PLATFORMCONFIG_H + +#include "Config.h" + +enum +{ + HK_Lid = 0, + HK_Mic, + HK_Pause, + HK_Reset, + HK_FastForward, + HK_FastForwardToggle, + HK_SolarSensorDecrease, + HK_SolarSensorIncrease, + HK_MAX +}; + +namespace Config +{ + +extern int KeyMapping[12]; +extern int JoyMapping[12]; + +extern int HKKeyMapping[HK_MAX]; +extern int HKJoyMapping[HK_MAX]; + +extern int JoystickID; + +extern int WindowWidth; +extern int WindowHeight; +extern int WindowMaximized; + +extern int ScreenRotation; +extern int ScreenGap; +extern int ScreenLayout; +extern int ScreenSizing; +extern int ScreenFilter; + +extern int ScreenUseGL; +extern int ScreenVSync; +extern int ScreenRatio; + +extern int LimitFPS; +extern int AudioSync; +extern int ShowOSD; + +extern int DirectBoot; + +extern int SocketBindAnyAddr; +extern char LANDevice[128]; +extern int DirectLAN; + +extern int SavestateRelocSRAM; + +extern int AudioVolume; +extern int MicInputType; +extern char MicWavPath[512]; + +extern char LastROMFolder[512]; + +} + +#endif // PLATFORMCONFIG_H diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 0eb84a5..9192685 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -22,20 +22,364 @@ #include #include -#include +#include +#include +#include +#include +#include + +#include #include "main.h" -#include "../../version.h" +#include "types.h" +#include "version.h" + +#include "NDS.h" +#include "GBACart.h" +#include "GPU.h" +#include "SPU.h" +#include "Wifi.h" +#include "Platform.h" +#include "Config.h" + +#include "Savestate.h" + + +char* EmuDirectory; + +bool RunningSomething; +char ROMPath[2][1024]; +char SRAMPath[2][1024]; +char PrevSRAMPath[2][1024]; // for savestate 'undo load' + +bool SavestateLoaded; + +MainWindow* mainWindow; +EmuThread* emuThread; + + +EmuThread::EmuThread(QObject* parent) : QThread(parent) +{ + EmuStatus = 0; + EmuRunning = 2; +} + +void EmuThread::run() +{ + NDS::Init(); + + /*MainScreenPos[0] = 0; + MainScreenPos[1] = 0; + MainScreenPos[2] = 0; + AutoScreenSizing = 0;*/ + + /*if (Screen_UseGL) + { + uiGLMakeContextCurrent(GLContext); + GPU3D::InitRenderer(true); + uiGLMakeContextCurrent(NULL); + } + else*/ + { + GPU3D::InitRenderer(false); + } + + /*Touching = false; + KeyInputMask = 0xFFF; + JoyInputMask = 0xFFF; + KeyHotkeyMask = 0; + JoyHotkeyMask = 0; + HotkeyMask = 0; + LastHotkeyMask = 0; + LidStatus = false;*/ + + u32 nframes = 0; + u32 starttick = SDL_GetTicks(); + u32 lasttick = starttick; + u32 lastmeasuretick = lasttick; + u32 fpslimitcount = 0; + u64 perfcount = SDL_GetPerformanceCounter(); + u64 perffreq = SDL_GetPerformanceFrequency(); + float samplesleft = 0; + u32 nsamples = 0; + + char melontitle[100]; + SDL_mutex* titlemutex = SDL_CreateMutex(); + void* titledata[2] = {melontitle, titlemutex}; +printf("emu thread start: %d\n", EmuRunning); + while (EmuRunning != 0) + { + /*ProcessInput(); + + if (HotkeyPressed(HK_FastForwardToggle)) + { + Config::LimitFPS = !Config::LimitFPS; + uiQueueMain(UpdateFPSLimit, NULL); + } + // TODO: similar hotkeys for video/audio sync? + + if (HotkeyPressed(HK_Pause)) uiQueueMain(TogglePause, NULL); + if (HotkeyPressed(HK_Reset)) uiQueueMain(Reset, NULL); + + if (GBACart::CartInserted && GBACart::HasSolarSensor) + { + if (HotkeyPressed(HK_SolarSensorDecrease)) + { + if (GBACart_SolarSensor::LightLevel > 0) GBACart_SolarSensor::LightLevel--; + char msg[64]; + sprintf(msg, "Solar sensor level set to %d", GBACart_SolarSensor::LightLevel); + OSD::AddMessage(0, msg); + } + if (HotkeyPressed(HK_SolarSensorIncrease)) + { + if (GBACart_SolarSensor::LightLevel < 10) GBACart_SolarSensor::LightLevel++; + char msg[64]; + sprintf(msg, "Solar sensor level set to %d", GBACart_SolarSensor::LightLevel); + OSD::AddMessage(0, msg); + } + }*/ + + if (EmuRunning == 1) + { + EmuStatus = 1; + + // process input and hotkeys + NDS::SetKeyMask(0xFFF); + /*NDS::SetKeyMask(KeyInputMask & JoyInputMask); + + if (HotkeyPressed(HK_Lid)) + { + LidStatus = !LidStatus; + NDS::SetLidClosed(LidStatus); + OSD::AddMessage(0, LidStatus ? "Lid closed" : "Lid opened"); + }*/ + + // microphone input + /*FeedMicInput(); + + if (Screen_UseGL) + { + uiGLBegin(GLContext); + uiGLMakeContextCurrent(GLContext); + }*/ + + // auto screen layout + /*{ + MainScreenPos[2] = MainScreenPos[1]; + MainScreenPos[1] = MainScreenPos[0]; + MainScreenPos[0] = NDS::PowerControl9 >> 15; + + int guess; + if (MainScreenPos[0] == MainScreenPos[2] && + MainScreenPos[0] != MainScreenPos[1]) + { + // constant flickering, likely displaying 3D on both screens + // TODO: when both screens are used for 2D only...??? + guess = 0; + } + else + { + if (MainScreenPos[0] == 1) + guess = 1; + else + guess = 2; + } + + if (guess != AutoScreenSizing) + { + AutoScreenSizing = guess; + SetupScreenRects(WindowWidth, WindowHeight); + } + }*/ + + // emulate + u32 nlines = NDS::RunFrame(); + +#ifdef MELONCAP + MelonCap::Update(); +#endif // MELONCAP + + if (EmuRunning == 0) break; + + /*if (Screen_UseGL) + { + GLScreen_DrawScreen(); + uiGLEnd(GLContext); + } + uiAreaQueueRedrawAll(MainDrawArea);*/ + + /*bool fastforward = HotkeyDown(HK_FastForward); + + if (Config::AudioSync && !fastforward) + { + SDL_LockMutex(AudioSyncLock); + while (SPU::GetOutputSize() > 1024) + { + int ret = SDL_CondWaitTimeout(AudioSync, AudioSyncLock, 500); + if (ret == SDL_MUTEX_TIMEDOUT) break; + } + SDL_UnlockMutex(AudioSyncLock); + } + + float framerate = (1000.0f * nlines) / (60.0f * 263.0f); + + { + u32 curtick = SDL_GetTicks(); + u32 delay = curtick - lasttick; + + bool limitfps = Config::LimitFPS && !fastforward; + if (limitfps) + { + float wantedtickF = starttick + (framerate * (fpslimitcount+1)); + u32 wantedtick = (u32)ceil(wantedtickF); + if (curtick < wantedtick) SDL_Delay(wantedtick - curtick); + + lasttick = SDL_GetTicks(); + fpslimitcount++; + if ((abs(wantedtickF - (float)wantedtick) < 0.001312) || (fpslimitcount > 60)) + { + fpslimitcount = 0; + nsamples = 0; + starttick = lasttick; + } + } + else + { + if (delay < 1) SDL_Delay(1); + lasttick = SDL_GetTicks(); + } + } + + nframes++; + if (nframes >= 30) + { + u32 tick = SDL_GetTicks(); + u32 diff = tick - lastmeasuretick; + lastmeasuretick = tick; + + u32 fps; + if (diff < 1) fps = 77777; + else fps = (nframes * 1000) / diff; + nframes = 0; + + float fpstarget; + if (framerate < 1) fpstarget = 999; + else fpstarget = 1000.0f/framerate; + + SDL_LockMutex(titlemutex); + sprintf(melontitle, "[%d/%.0f] melonDS " MELONDS_VERSION, fps, fpstarget); + SDL_UnlockMutex(titlemutex); + uiQueueMain(UpdateWindowTitle, titledata); + }*/ + } + else + { + // paused + nframes = 0; + lasttick = SDL_GetTicks(); + starttick = lasttick; + lastmeasuretick = lasttick; + fpslimitcount = 0; + + if (EmuRunning == 2) + { + /*if (Screen_UseGL) + { + uiGLBegin(GLContext); + uiGLMakeContextCurrent(GLContext); + GLScreen_DrawScreen(); + uiGLEnd(GLContext); + } + uiAreaQueueRedrawAll(MainDrawArea);*/ + } + + //if (Screen_UseGL) uiGLMakeContextCurrent(NULL); + + EmuStatus = EmuRunning; + + SDL_Delay(100); + } + printf("ran iteration: status=%d run=%d\n", EmuStatus, EmuRunning); + } + + EmuStatus = 0; + + SDL_DestroyMutex(titlemutex); + + //if (Screen_UseGL) uiGLMakeContextCurrent(GLContext); + + NDS::DeInit(); + //Platform::LAN_DeInit(); + + /*if (Screen_UseGL) + { + OSD::DeInit(true); + GLScreen_DeInit(); + } + else + OSD::DeInit(false);*/ + + //if (Screen_UseGL) uiGLMakeContextCurrent(NULL); +} + +void EmuThread::emuRun() +{ + EmuRunning = 1; +} + +void EmuThread::emuPause(bool refresh) +{ + int status = refresh ? 2:3; + PrevEmuStatus = EmuRunning; + EmuRunning = status;printf("emuPause %d -> %d %d\n", PrevEmuStatus, EmuRunning, EmuStatus); + while (EmuStatus != status);printf("wait done\n"); +} + +void EmuThread::emuUnpause() +{ + EmuRunning = PrevEmuStatus; +} + +void EmuThread::emuStop() +{ + EmuRunning = 0; +} + + +MainWindowPanel::MainWindowPanel(QWidget* parent) : QWidget(parent) +{ +} + +MainWindowPanel::~MainWindowPanel() +{ +} + +void MainWindowPanel::paintEvent(QPaintEvent* event) +{ + QPainter painter(this); + + //painter. +} MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { setWindowTitle("melonDS - assfucking Qt version"); - // burp - QWidget *centralWidget = new QWidget(this); - setCentralWidget(centralWidget); + QMenuBar* menubar = new QMenuBar(); + { + QMenu* menu = menubar->addMenu("File"); + QAction* act; + + act = menu->addAction("Open file..."); + connect(act, &QAction::triggered, this, &MainWindow::onOpenFile); + } + setMenuBar(menubar); + + panel = new MainWindowPanel(this); + setCentralWidget(panel); + panel->setMinimumSize(256, 384); } MainWindow::~MainWindow() @@ -43,6 +387,13 @@ MainWindow::~MainWindow() } +void MainWindow::onOpenFile() +{ + QString filename = QFileDialog::getOpenFileName(this, "Open ROM", "", "DS ROMs (*.nds *.srl);;Any file (*.*)"); + printf("fark: %p %d %s\n", filename, filename.isEmpty(), filename.toStdString().c_str()); +} + + int main(int argc, char** argv) { srand(time(NULL)); @@ -50,12 +401,212 @@ int main(int argc, char** argv) printf("melonDS " MELONDS_VERSION "\n"); printf(MELONDS_URL "\n"); +#if defined(__WIN32__) || defined(UNIX_PORTABLE) + if (argc > 0 && strlen(argv[0]) > 0) + { + int len = strlen(argv[0]); + while (len > 0) + { + if (argv[0][len] == '/') break; + if (argv[0][len] == '\\') break; + len--; + } + if (len > 0) + { + EmuDirectory = new char[len+1]; + strncpy(EmuDirectory, argv[0], len); + EmuDirectory[len] = '\0'; + } + else + { + EmuDirectory = new char[2]; + strcpy(EmuDirectory, "."); + } + } + else + { + EmuDirectory = new char[2]; + strcpy(EmuDirectory, "."); + } +#else + const char* confdir = g_get_user_config_dir(); + const char* confname = "/melonDS"; + EmuDirectory = new char[strlen(confdir) + strlen(confname) + 1]; + strcat(EmuDirectory, confdir); + strcat(EmuDirectory, confname); +#endif + QApplication melon(argc, argv); - MainWindow win; - win.show(); + // http://stackoverflow.com/questions/14543333/joystick-wont-work-using-sdl + SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); + + if (SDL_Init(SDL_INIT_HAPTIC) < 0) + { + printf("SDL couldn't init rumble\n"); + } + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0) + { + QMessageBox::critical(NULL, "melonDS", "SDL shat itself :("); + return 1; + } + + SDL_JoystickEventState(SDL_ENABLE); + + Config::Load(); + + //if (Config::AudioVolume < 0) Config::AudioVolume = 0; + //else if (Config::AudioVolume > 256) Config::AudioVolume = 256; - return melon.exec(); + // TODO: those should be checked before running anything + // (as to let the user specify their own BIOS/firmware path etc) +#if 0 + if (!Platform::LocalFileExists("bios7.bin") || + !Platform::LocalFileExists("bios9.bin") || + !Platform::LocalFileExists("firmware.bin")) + { +#if defined(__WIN32__) || defined(UNIX_PORTABLE) + const char* locationName = "the directory you run melonDS from"; +#else + char* locationName = EmuDirectory; +#endif + char msgboxtext[512]; + sprintf(msgboxtext, + "One or more of the following required files don't exist or couldn't be accessed:\n\n" + "bios7.bin -- ARM7 BIOS\n" + "bios9.bin -- ARM9 BIOS\n" + "firmware.bin -- firmware image\n\n" + "Dump the files from your DS and place them in %s.\n" + "Make sure that the files can be accessed.", + locationName + ); + + uiMsgBoxError(NULL, "BIOS/Firmware not found", msgboxtext); + + uiUninit(); + SDL_Quit(); + return 0; + } + if (!Platform::LocalFileExists("firmware.bin.bak")) + { + // verify the firmware + // + // there are dumps of an old hacked firmware floating around on the internet + // and those are problematic + // the hack predates WFC, and, due to this, any game that alters the WFC + // access point data will brick that firmware due to it having critical + // data in the same area. it has the same problem on hardware. + // + // but this should help stop users from reporting that issue over and over + // again, when the issue is not from melonDS but from their firmware dump. + // + // I don't know about all the firmware hacks in existence, but the one I + // looked at has 0x180 bytes from the header repeated at 0x3FC80, but + // bytes 0x0C-0x14 are different. + + FILE* f = Platform::OpenLocalFile("firmware.bin", "rb"); + u8 chk1[0x180], chk2[0x180]; + + fseek(f, 0, SEEK_SET); + fread(chk1, 1, 0x180, f); + fseek(f, -0x380, SEEK_END); + fread(chk2, 1, 0x180, f); + + memset(&chk1[0x0C], 0, 8); + memset(&chk2[0x0C], 0, 8); + + fclose(f); + + if (!memcmp(chk1, chk2, 0x180)) + { + uiMsgBoxError(NULL, + "Problematic firmware dump", + "You are using an old hacked firmware dump.\n" + "Firmware boot will stop working if you run any game that alters WFC settings.\n\n" + "Note that the issue is not from melonDS, it would also happen on an actual DS."); + } + } + { + const char* romlist_missing = "Save memory type detection will not work correctly.\n\n" + "You should use the latest version of romlist.bin (provided in melonDS release packages)."; +#if !defined(UNIX_PORTABLE) && !defined(__WIN32__) + std::string missingstr = std::string(romlist_missing) + + "\n\nThe ROM list should be placed in " + g_get_user_data_dir() + "/melonds/, otherwise " + "melonDS will search for it in the current working directory."; + const char* romlist_missing_text = missingstr.c_str(); +#else + const char* romlist_missing_text = romlist_missing; +#endif + + FILE* f = Platform::OpenDataFile("romlist.bin"); + if (f) + { + u32 data; + fread(&data, 4, 1, f); + fclose(f); + + if ((data >> 24) == 0) // old CRC-based list + { + uiMsgBoxError(NULL, "Your version of romlist.bin is outdated.", romlist_missing_text); + } + } + else + { + uiMsgBoxError(NULL, "romlist.bin not found.", romlist_missing_text); + } + } +#endif + + mainWindow = new MainWindow(); + mainWindow->show(); + + emuThread = new EmuThread(); + emuThread->start(); + emuThread->emuPause(true); + + if (argc > 1) + { + char* file = argv[1]; + char* ext = &file[strlen(file)-3]; + + if (!strcasecmp(ext, "nds") || !strcasecmp(ext, "srl")) + { + strncpy(ROMPath[0], file, 1023); + ROMPath[0][1023] = '\0'; + + //SetupSRAMPath(0); + + //if (NDS::LoadROM(ROMPath[0], SRAMPath[0], Config::DirectBoot)) + // Run(); + } + + if (argc > 2) + { + file = argv[2]; + ext = &file[strlen(file)-3]; + + if (!strcasecmp(ext, "gba")) + { + strncpy(ROMPath[1], file, 1023); + ROMPath[1][1023] = '\0'; + + //SetupSRAMPath(1); + + //NDS::LoadGBAROM(ROMPath[1], SRAMPath[1]); + } + } + } + + int ret = melon.exec(); +printf("melon over\n"); + emuThread->emuStop();printf("STOP\n"); + emuThread->wait();printf("farked\n"); + + Config::Save(); + + SDL_Quit(); + delete[] EmuDirectory; + return ret; } #ifdef __WIN32__ @@ -71,6 +622,7 @@ int CALLBACK WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int cmdsho char** argv = new char*[argc]; for (int i = 0; i < argc; i++) { + if (!argv_w) { argv[i] = nullarg; continue; } int len = WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1, NULL, 0, NULL, NULL); if (len < 1) { argv[i] = nullarg; continue; } argv[i] = new char[len]; @@ -78,6 +630,8 @@ int CALLBACK WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int cmdsho if (res != len) { delete[] argv[i]; argv[i] = nullarg; } } + if (argv_w) LocalFree(argv_w); + if (AttachConsole(ATTACH_PARENT_PROCESS)) { freopen("CONOUT$", "w", stdout); diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index ad795ef..92b1846 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -19,8 +19,45 @@ #ifndef MAIN_H #define MAIN_H +#include +#include #include + +class EmuThread : public QThread +{ + Q_OBJECT + void run() override; + +public: + explicit EmuThread(QObject* parent = nullptr); + + // to be called from the UI thread + void emuRun(); + void emuPause(bool refresh); + void emuUnpause(); + void emuStop(); + +private: + volatile int EmuStatus; + int PrevEmuStatus; + int EmuRunning; +}; + + +class MainWindowPanel : public QWidget +{ + Q_OBJECT + +public: + explicit MainWindowPanel(QWidget* parent); + ~MainWindowPanel(); + +protected: + void paintEvent(QPaintEvent* event) override; +}; + + class MainWindow : public QMainWindow { Q_OBJECT @@ -29,8 +66,11 @@ public: explicit MainWindow(QWidget* parent = nullptr); ~MainWindow(); +private slots: + void onOpenFile(); + private: - // private shit goes here + MainWindowPanel* panel; }; #endif // MAIN_H -- cgit v1.2.3 From d9c55a4f1f269de2fd17fe214403f13a9cf6f341 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 27 Apr 2020 15:59:52 +0200 Subject: fix dumb include path shit. --- src/frontend/qt_sdl/CMakeLists.txt | 2 +- src/frontend/qt_sdl/main.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index f24464d..baa4be2 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -21,6 +21,7 @@ pkg_check_modules(SDL2 REQUIRED sdl2) add_executable(melonDS ${SOURCES_QT_SDL}) target_include_directories(melonDS PRIVATE ${SDL2_INCLUDE_DIRS}) +target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../..") target_link_libraries(melonDS core ${SDL2_LIBRARIES}) if (UNIX) @@ -52,7 +53,6 @@ if (UNIX) target_sources(melonDS PUBLIC melon_grc.c) elseif (WIN32) target_sources(melonDS PUBLIC "${CMAKE_SOURCE_DIR}/melon.rc") - target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../..") target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32 Qt5::Core Qt5::Gui Qt5::Widgets) endif () diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 9192685..4999d94 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -208,6 +208,7 @@ printf("emu thread start: %d\n", EmuRunning); uiGLEnd(GLContext); } uiAreaQueueRedrawAll(MainDrawArea);*/ + mainWindow->update(); /*bool fastforward = HotkeyDown(HK_FastForward); @@ -292,6 +293,7 @@ printf("emu thread start: %d\n", EmuRunning); uiGLEnd(GLContext); } uiAreaQueueRedrawAll(MainDrawArea);*/ + mainWindow->update(); } //if (Screen_UseGL) uiGLMakeContextCurrent(NULL); @@ -359,7 +361,10 @@ void MainWindowPanel::paintEvent(QPaintEvent* event) { QPainter painter(this); - //painter. + // fill background + painter.fillRect(event->rect(), QColor::fromRgb(0, 0, 0)); + + painter.fillRect(0, 0, 256, 192, QColor::fromRgb(0, 255, 255)); } -- cgit v1.2.3 From d6efb03248e3c7751b0c7e5d3b6398ea671325b0 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 27 Apr 2020 20:59:11 +0200 Subject: HARK HARK HARK --- src/frontend/FrontendUtil.h | 31 +++++++++++++++++++++++++++++++ src/frontend/Util_ROM.cpp | 17 +++++++++++++++++ src/frontend/qt_sdl/CMakeLists.txt | 4 ++++ 3 files changed, 52 insertions(+) create mode 100644 src/frontend/FrontendUtil.h create mode 100644 src/frontend/Util_ROM.cpp (limited to 'src') diff --git a/src/frontend/FrontendUtil.h b/src/frontend/FrontendUtil.h new file mode 100644 index 0000000..6a199b7 --- /dev/null +++ b/src/frontend/FrontendUtil.h @@ -0,0 +1,31 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef FRONTENDUTIL_H +#define FRONTENDUTIL_H + +#include "types.h" + +namespace FrontendUtil +{ + +// + +} + +#endif // FRONTENDUTIL_H diff --git a/src/frontend/Util_ROM.cpp b/src/frontend/Util_ROM.cpp new file mode 100644 index 0000000..b3077f7 --- /dev/null +++ b/src/frontend/Util_ROM.cpp @@ -0,0 +1,17 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index baa4be2..fb9f547 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -4,6 +4,9 @@ SET(SOURCES_QT_SDL main.cpp Platform.cpp PlatformConfig.cpp + + ../Util_ROM.cpp + ../FrontendUtil.h ) if (WIN32) @@ -21,6 +24,7 @@ pkg_check_modules(SDL2 REQUIRED sdl2) add_executable(melonDS ${SOURCES_QT_SDL}) target_include_directories(melonDS PRIVATE ${SDL2_INCLUDE_DIRS}) +target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..") target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../..") target_link_libraries(melonDS core ${SDL2_LIBRARIES}) -- cgit v1.2.3 From 931da1c66fb50138109f8bf4cb157db8f1e79c64 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 27 Apr 2020 22:02:45 +0200 Subject: add a bunch of code --- src/CMakeLists.txt | 2 + src/Config.h | 2 + src/frontend/FrontendUtil.h | 38 ++++++- src/frontend/Util_ROM.cpp | 236 +++++++++++++++++++++++++++++++++++++++++++ src/frontend/qt_sdl/main.cpp | 19 ++-- 5 files changed, 284 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 64d922c..dca0ca9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,6 +26,8 @@ add_library(core STATIC Savestate.cpp SPI.cpp SPU.cpp + types.h + version.h Wifi.cpp WifiAP.cpp ) diff --git a/src/Config.h b/src/Config.h index 84fd57b..0aeab85 100644 --- a/src/Config.h +++ b/src/Config.h @@ -19,6 +19,8 @@ #ifndef CONFIG_H #define CONFIG_H +#include + #include "types.h" namespace Config diff --git a/src/frontend/FrontendUtil.h b/src/frontend/FrontendUtil.h index 6a199b7..7e171ce 100644 --- a/src/frontend/FrontendUtil.h +++ b/src/frontend/FrontendUtil.h @@ -21,10 +21,44 @@ #include "types.h" -namespace FrontendUtil +namespace Frontend { -// +enum +{ + ROMSlot_NDS = 0, + ROMSlot_GBA, + + ROMSlot_MAX +}; + +extern char ROMPath [ROMSlot_MAX][1024]; +extern char SRAMPath[ROMSlot_MAX][1024]; +extern bool SavestateLoaded; + + +// initialize the ROM handling utility +void Init_ROM(); + +// load a ROM file to the specified cart slot +// note: loading a ROM to the NDS slot resets emulation +bool LoadROM(char* file, int slot); + +// get the filename associated with the given savestate slot +void GetSavestateName(int slot, char* filename, int len); + +// determine whether the given savestate slot does contain a savestate +bool SavestateExists(int slot); + +// load the given savestate file +// if successful, emulation will continue from the savestate's point +bool LoadState(const char* filename); + +// save the current emulator state to the given file +bool SaveState(const char* filename); + +// undo the latest savestate load +void UndoStateLoad(); } diff --git a/src/frontend/Util_ROM.cpp b/src/frontend/Util_ROM.cpp index b3077f7..574148b 100644 --- a/src/frontend/Util_ROM.cpp +++ b/src/frontend/Util_ROM.cpp @@ -15,3 +15,239 @@ You should have received a copy of the GNU General Public License along with melonDS. If not, see http://www.gnu.org/licenses/. */ + +#include +#include + +#include "FrontendUtil.h" +#include "Config.h" +#include "qt_sdl/PlatformConfig.h" // FIXME!!! +#include "Platform.h" + +#include "NDS.h" +#include "GBACart.h" + + +namespace Frontend +{ + +char ROMPath [ROMSlot_MAX][1024]; +char SRAMPath [ROMSlot_MAX][1024]; +char PrevSRAMPath[ROMSlot_MAX][1024]; // for savestate 'undo load' + +bool SavestateLoaded; + + +void Init_ROM() +{ + SavestateLoaded = false; + + memset(ROMPath[ROMSlot_NDS], 0, 1024); + memset(ROMPath[ROMSlot_GBA], 0, 1024); + memset(SRAMPath[ROMSlot_NDS], 0, 1024); + memset(SRAMPath[ROMSlot_GBA], 0, 1024); + memset(PrevSRAMPath[ROMSlot_NDS], 0, 1024); + memset(PrevSRAMPath[ROMSlot_GBA], 0, 1024); +} + +void SetupSRAMPath(int slot) +{ + strncpy(SRAMPath[slot], ROMPath[slot], 1023); + SRAMPath[slot][1023] = '\0'; + strncpy(SRAMPath[slot] + strlen(ROMPath[slot]) - 3, "sav", 3); +} + +bool LoadROM(char* file, int slot) +{ + char oldpath[1024]; + char oldsram[1024]; + strncpy(oldpath, ROMPath[slot], 1024); + strncpy(oldsram, SRAMPath[slot], 1024); + + strncpy(ROMPath[slot], file, 1023); + ROMPath[slot][1023] = '\0'; + + SetupSRAMPath(0); + SetupSRAMPath(1); + + if (slot == ROMSlot_NDS && NDS::LoadROM(ROMPath[slot], SRAMPath[slot], Config::DirectBoot)) + { + SavestateLoaded = false; + + // Reload the inserted GBA cartridge (if any) + if (ROMPath[ROMSlot_GBA][0] != '\0') NDS::LoadGBAROM(ROMPath[ROMSlot_GBA], SRAMPath[ROMSlot_GBA]); + + strncpy(PrevSRAMPath[slot], SRAMPath[slot], 1024); // safety + return true; + } + else if (slot == ROMSlot_GBA && NDS::LoadGBAROM(ROMPath[slot], SRAMPath[slot])) + { + SavestateLoaded = false; + + strncpy(PrevSRAMPath[slot], SRAMPath[slot], 1024); // safety + return true; + } + else + { + strncpy(ROMPath[slot], oldpath, 1024); + strncpy(SRAMPath[slot], oldsram, 1024); + return false; + } +} + + +// SAVESTATE TODO +// * configurable paths. not everyone wants their ROM directory to be polluted, I guess. + +void GetSavestateName(int slot, char* filename, int len) +{ + int pos; + + if (ROMPath[ROMSlot_NDS][0] == '\0') // running firmware, no ROM + { + strcpy(filename, "firmware"); + pos = 8; + } + else + { + int l = strlen(ROMPath[ROMSlot_NDS]); + pos = l; + while (ROMPath[ROMSlot_NDS][pos] != '.' && pos > 0) pos--; + if (pos == 0) pos = l; + + // avoid buffer overflow. shoddy + if (pos > len-5) pos = len-5; + + strncpy(&filename[0], ROMPath[ROMSlot_NDS], pos); + } + strcpy(&filename[pos], ".ml"); + filename[pos+3] = '0'+slot; + filename[pos+4] = '\0'; +} + +bool SavestateExists(int slot) +{ + char ssfile[1024]; + GetSavestateName(slot, ssfile, 1024); + return Platform::FileExists(ssfile); +} + +bool LoadState(const char* filename) +{ + u32 oldGBACartCRC = GBACart::CartCRC; + + // backup + Savestate* backup = new Savestate("timewarp.mln", true); + NDS::DoSavestate(backup); + delete backup; + + bool failed = false; + + Savestate* state = new Savestate(filename, false); + if (state->Error) + { + delete state; + + //uiMsgBoxError(MainWindow, "Error", "Could not load savestate file."); + + // current state might be crapoed, so restore from sane backup + state = new Savestate("timewarp.mln", false); + failed = true; + } + + NDS::DoSavestate(state); + delete state; + + if (!failed) + { + if (Config::SavestateRelocSRAM && ROMPath[ROMSlot_NDS][0]!='\0') + { + strncpy(PrevSRAMPath[ROMSlot_NDS], SRAMPath[0], 1024); + + strncpy(SRAMPath[ROMSlot_NDS], filename, 1019); + int len = strlen(SRAMPath[ROMSlot_NDS]); + strcpy(&SRAMPath[ROMSlot_NDS][len], ".sav"); + SRAMPath[ROMSlot_NDS][len+4] = '\0'; + + NDS::RelocateSave(SRAMPath[ROMSlot_NDS], false); + } + + bool loadedPartialGBAROM = false; + + // in case we have a GBA cart inserted, and the GBA ROM changes + // due to having loaded a save state, we do not want to reload + // the previous cartridge on reset, or commit writes to any + // loaded save file. therefore, their paths are "nulled". + if (GBACart::CartInserted && GBACart::CartCRC != oldGBACartCRC) + { + ROMPath[ROMSlot_GBA][0] = '\0'; + SRAMPath[ROMSlot_GBA][0] = '\0'; + loadedPartialGBAROM = true; + } + + // TODO forward this to user in a meaningful way!! + /*char msg[64]; + if (slot > 0) sprintf(msg, "State loaded from slot %d%s", + slot, loadedPartialGBAROM ? " (GBA ROM header only)" : ""); + else sprintf(msg, "State loaded from file%s", + loadedPartialGBAROM ? " (GBA ROM header only)" : ""); + OSD::AddMessage(0, msg);*/ + + SavestateLoaded = true; + } + + return !failed; +} + +bool SaveState(const char* filename) +{ + Savestate* state = new Savestate(filename, true); + if (state->Error) + { + delete state; + return false; + } + else + { + NDS::DoSavestate(state); + delete state; + + if (Config::SavestateRelocSRAM && ROMPath[ROMSlot_NDS][0]!='\0') + { + strncpy(SRAMPath[ROMSlot_NDS], filename, 1019); + int len = strlen(SRAMPath[ROMSlot_NDS]); + strcpy(&SRAMPath[ROMSlot_NDS][len], ".sav"); + SRAMPath[ROMSlot_NDS][len+4] = '\0'; + + NDS::RelocateSave(SRAMPath[ROMSlot_NDS], true); + } + } + + /*char msg[64]; + if (slot > 0) sprintf(msg, "State saved to slot %d", slot); + else sprintf(msg, "State saved to file"); + OSD::AddMessage(0, msg);*/ + return true; +} + +void UndoStateLoad() +{ + if (!SavestateLoaded) return; + + // pray that this works + // what do we do if it doesn't??? + // but it should work. + Savestate* backup = new Savestate("timewarp.mln", false); + NDS::DoSavestate(backup); + delete backup; + + if (ROMPath[ROMSlot_NDS][0]!='\0') + { + strncpy(SRAMPath[ROMSlot_NDS], PrevSRAMPath[ROMSlot_NDS], 1024); + NDS::RelocateSave(SRAMPath[ROMSlot_NDS], false); + } + + //OSD::AddMessage(0, "State load undone"); +} + +} diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 4999d94..648cd99 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -49,11 +49,6 @@ char* EmuDirectory; bool RunningSomething; -char ROMPath[2][1024]; -char SRAMPath[2][1024]; -char PrevSRAMPath[2][1024]; // for savestate 'undo load' - -bool SavestateLoaded; MainWindow* mainWindow; EmuThread* emuThread; @@ -334,8 +329,8 @@ void EmuThread::emuPause(bool refresh) { int status = refresh ? 2:3; PrevEmuStatus = EmuRunning; - EmuRunning = status;printf("emuPause %d -> %d %d\n", PrevEmuStatus, EmuRunning, EmuStatus); - while (EmuStatus != status);printf("wait done\n"); + EmuRunning = status; + while (EmuStatus != status); } void EmuThread::emuUnpause() @@ -370,7 +365,7 @@ void MainWindowPanel::paintEvent(QPaintEvent* event) MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { - setWindowTitle("melonDS - assfucking Qt version"); + setWindowTitle("melonDS " MELONDS_VERSION); QMenuBar* menubar = new QMenuBar(); { @@ -569,6 +564,7 @@ int main(int argc, char** argv) emuThread->start(); emuThread->emuPause(true); + #if 0 if (argc > 1) { char* file = argv[1]; @@ -601,11 +597,12 @@ int main(int argc, char** argv) } } } + #endif int ret = melon.exec(); -printf("melon over\n"); - emuThread->emuStop();printf("STOP\n"); - emuThread->wait();printf("farked\n"); + + emuThread->emuStop(); + emuThread->wait(); Config::Save(); -- cgit v1.2.3 From 3c883a2152c699b432c951b3498a1adc3d4c21b1 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 27 Apr 2020 22:32:33 +0200 Subject: hey look, it runs shit now! --- src/frontend/FrontendUtil.h | 2 +- src/frontend/Util_ROM.cpp | 2 +- src/frontend/qt_sdl/main.cpp | 60 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 58 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/frontend/FrontendUtil.h b/src/frontend/FrontendUtil.h index 7e171ce..91f3cdd 100644 --- a/src/frontend/FrontendUtil.h +++ b/src/frontend/FrontendUtil.h @@ -42,7 +42,7 @@ void Init_ROM(); // load a ROM file to the specified cart slot // note: loading a ROM to the NDS slot resets emulation -bool LoadROM(char* file, int slot); +bool LoadROM(const char* file, int slot); // get the filename associated with the given savestate slot void GetSavestateName(int slot, char* filename, int len); diff --git a/src/frontend/Util_ROM.cpp b/src/frontend/Util_ROM.cpp index 574148b..ffee69a 100644 --- a/src/frontend/Util_ROM.cpp +++ b/src/frontend/Util_ROM.cpp @@ -57,7 +57,7 @@ void SetupSRAMPath(int slot) strncpy(SRAMPath[slot] + strlen(ROMPath[slot]) - 3, "sav", 3); } -bool LoadROM(char* file, int slot) +bool LoadROM(const char* file, int slot) { char oldpath[1024]; char oldsram[1024]; diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 648cd99..6b4c873 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -35,13 +35,15 @@ #include "types.h" #include "version.h" +#include "FrontendUtil.h" + #include "NDS.h" -#include "GBACart.h" #include "GPU.h" #include "SPU.h" #include "Wifi.h" #include "Platform.h" #include "Config.h" +#include "PlatformConfig.h" #include "Savestate.h" @@ -102,7 +104,7 @@ void EmuThread::run() char melontitle[100]; SDL_mutex* titlemutex = SDL_CreateMutex(); void* titledata[2] = {melontitle, titlemutex}; -printf("emu thread start: %d\n", EmuRunning); + while (EmuRunning != 0) { /*ProcessInput(); @@ -389,8 +391,56 @@ MainWindow::~MainWindow() void MainWindow::onOpenFile() { - QString filename = QFileDialog::getOpenFileName(this, "Open ROM", "", "DS ROMs (*.nds *.srl);;Any file (*.*)"); - printf("fark: %p %d %s\n", filename, filename.isEmpty(), filename.toStdString().c_str()); + emuThread->emuPause(true); + + QString filename = QFileDialog::getOpenFileName(this, + "Open ROM", + Config::LastROMFolder, + "DS ROMs (*.nds *.srl);;GBA ROMs (*.gba);;Any file (*.*)"); + if (filename.isEmpty()) + { + emuThread->emuUnpause(); + return; + } + + // this shit is stupid + char file[1024]; + strncpy(file, filename.toStdString().c_str(), 1023); file[1023] = '\0'; + + int pos = strlen(file)-1; + while (file[pos] != '/' && file[pos] != '\\' && pos > 0) pos--; + strncpy(Config::LastROMFolder, file, pos); + Config::LastROMFolder[pos] = '\0'; + char* ext = &file[strlen(file)-3]; + + int slot; bool res; + if (!strcasecmp(ext, "gba")) + { + slot = 1; + res = Frontend::LoadROM(file, Frontend::ROMSlot_GBA); + } + else + { + slot = 0; + res = Frontend::LoadROM(file, Frontend::ROMSlot_NDS); + } + + if (!res) + { + QMessageBox::critical(this, + "melonDS", + "Failed to load the ROM.\n\nMake sure the file is accessible and isn't used by another application."); + emuThread->emuUnpause(); + } + else if (slot == 1) + { + // checkme + emuThread->emuUnpause(); + } + else + { + emuThread->emuRun(); + } } @@ -557,6 +607,8 @@ int main(int argc, char** argv) } #endif + RunningSomething = false; + mainWindow = new MainWindow(); mainWindow->show(); -- cgit v1.2.3 From a8aa834c16d5044c25f6d313f88a470cb79ffbfa Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 27 Apr 2020 22:42:07 +0200 Subject: now with display! --- src/frontend/qt_sdl/main.cpp | 20 ++++++++++++++++++-- src/frontend/qt_sdl/main.h | 4 ++++ 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 6b4c873..33dad2b 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -299,7 +299,6 @@ void EmuThread::run() SDL_Delay(100); } - printf("ran iteration: status=%d run=%d\n", EmuStatus, EmuRunning); } EmuStatus = 0; @@ -325,6 +324,7 @@ void EmuThread::run() void EmuThread::emuRun() { EmuRunning = 1; + RunningSomething = true; } void EmuThread::emuPause(bool refresh) @@ -348,10 +348,14 @@ void EmuThread::emuStop() MainWindowPanel::MainWindowPanel(QWidget* parent) : QWidget(parent) { + screen[0] = new QImage(256, 192, QImage::Format_RGB32); + screen[1] = new QImage(256, 192, QImage::Format_RGB32); } MainWindowPanel::~MainWindowPanel() { + delete screen[0]; + delete screen[1]; } void MainWindowPanel::paintEvent(QPaintEvent* event) @@ -361,7 +365,19 @@ void MainWindowPanel::paintEvent(QPaintEvent* event) // fill background painter.fillRect(event->rect(), QColor::fromRgb(0, 0, 0)); - painter.fillRect(0, 0, 256, 192, QColor::fromRgb(0, 255, 255)); + int frontbuf = GPU::FrontBuffer; + if (!GPU::Framebuffer[frontbuf][0] || !GPU::Framebuffer[frontbuf][1]) return; + + memcpy(screen[0]->scanLine(0), GPU::Framebuffer[frontbuf][0], 256*192*4); + memcpy(screen[1]->scanLine(0), GPU::Framebuffer[frontbuf][1], 256*192*4); + + QRect src = QRect(0, 0, 256, 192); + + QRect dstTop = QRect(0, 0, 256, 192); // TODO + QRect dstBot = QRect(0, 192, 256, 192); // TODO + + painter.drawImage(dstTop, *screen[0]); + painter.drawImage(dstBot, *screen[1]); } diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 92b1846..fb35fa5 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -22,6 +22,7 @@ #include #include #include +#include class EmuThread : public QThread @@ -55,6 +56,9 @@ public: protected: void paintEvent(QPaintEvent* event) override; + +private: + QImage* screen[2]; }; -- cgit v1.2.3 From 0913576ef598bee4d2ea3c4268a6a6f163cd90ef Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 27 Apr 2020 23:58:29 +0200 Subject: FPS counter is back --- src/frontend/qt_sdl/main.cpp | 32 +++++++++++++++++++++----------- src/frontend/qt_sdl/main.h | 7 +++++++ 2 files changed, 28 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 33dad2b..e9b9122 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -60,6 +60,9 @@ EmuThread::EmuThread(QObject* parent) : QThread(parent) { EmuStatus = 0; EmuRunning = 2; + RunningSomething = false; + + connect(this, SIGNAL(windowTitleChange(QString)), mainWindow, SLOT(onTitleUpdate(QString))); } void EmuThread::run() @@ -102,8 +105,6 @@ void EmuThread::run() u32 nsamples = 0; char melontitle[100]; - SDL_mutex* titlemutex = SDL_CreateMutex(); - void* titledata[2] = {melontitle, titlemutex}; while (EmuRunning != 0) { @@ -207,6 +208,7 @@ void EmuThread::run() uiAreaQueueRedrawAll(MainDrawArea);*/ mainWindow->update(); + bool fastforward = false; /*bool fastforward = HotkeyDown(HK_FastForward); if (Config::AudioSync && !fastforward) @@ -218,7 +220,7 @@ void EmuThread::run() if (ret == SDL_MUTEX_TIMEDOUT) break; } SDL_UnlockMutex(AudioSyncLock); - } + }*/ float framerate = (1000.0f * nlines) / (60.0f * 263.0f); @@ -265,11 +267,9 @@ void EmuThread::run() if (framerate < 1) fpstarget = 999; else fpstarget = 1000.0f/framerate; - SDL_LockMutex(titlemutex); sprintf(melontitle, "[%d/%.0f] melonDS " MELONDS_VERSION, fps, fpstarget); - SDL_UnlockMutex(titlemutex); - uiQueueMain(UpdateWindowTitle, titledata); - }*/ + changeWindowTitle(melontitle); + } } else { @@ -297,14 +297,15 @@ void EmuThread::run() EmuStatus = EmuRunning; + sprintf(melontitle, "melonDS " MELONDS_VERSION); + changeWindowTitle(melontitle); + SDL_Delay(100); } } EmuStatus = 0; - SDL_DestroyMutex(titlemutex); - //if (Screen_UseGL) uiGLMakeContextCurrent(GLContext); NDS::DeInit(); @@ -321,6 +322,11 @@ void EmuThread::run() //if (Screen_UseGL) uiGLMakeContextCurrent(NULL); } +void EmuThread::changeWindowTitle(char* title) +{ + emit windowTitleChange(QString(title)); +} + void EmuThread::emuRun() { EmuRunning = 1; @@ -460,6 +466,12 @@ void MainWindow::onOpenFile() } +void MainWindow::onTitleUpdate(QString title) +{ + setWindowTitle(title); +} + + int main(int argc, char** argv) { srand(time(NULL)); @@ -623,8 +635,6 @@ int main(int argc, char** argv) } #endif - RunningSomething = false; - mainWindow = new MainWindow(); mainWindow->show(); diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index fb35fa5..a1093fe 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -33,12 +33,17 @@ class EmuThread : public QThread public: explicit EmuThread(QObject* parent = nullptr); + void changeWindowTitle(char* title); + // to be called from the UI thread void emuRun(); void emuPause(bool refresh); void emuUnpause(); void emuStop(); +signals: + void windowTitleChange(QString title); + private: volatile int EmuStatus; int PrevEmuStatus; @@ -73,6 +78,8 @@ public: private slots: void onOpenFile(); + void onTitleUpdate(QString title); + private: MainWindowPanel* panel; }; -- cgit v1.2.3 From 63efc2e02aa51c44c9cb5abc621624aa1d7bf1e5 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 28 Apr 2020 22:45:11 +0200 Subject: add menu items for running the firmware and for quitting. --- src/frontend/FrontendUtil.h | 3 +++ src/frontend/Util_ROM.cpp | 16 ++++++++++++++++ src/frontend/qt_sdl/main.cpp | 44 +++++++++++++++++++++++++++++++++++++++++--- src/frontend/qt_sdl/main.h | 9 +++++++++ 4 files changed, 69 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/frontend/FrontendUtil.h b/src/frontend/FrontendUtil.h index 91f3cdd..eb4cb38 100644 --- a/src/frontend/FrontendUtil.h +++ b/src/frontend/FrontendUtil.h @@ -40,6 +40,9 @@ extern bool SavestateLoaded; // initialize the ROM handling utility void Init_ROM(); +// load the BIOS/firmware and boot from it +bool LoadBIOS(); + // load a ROM file to the specified cart slot // note: loading a ROM to the NDS slot resets emulation bool LoadROM(const char* file, int slot); diff --git a/src/frontend/Util_ROM.cpp b/src/frontend/Util_ROM.cpp index ffee69a..cf40a78 100644 --- a/src/frontend/Util_ROM.cpp +++ b/src/frontend/Util_ROM.cpp @@ -57,6 +57,22 @@ void SetupSRAMPath(int slot) strncpy(SRAMPath[slot] + strlen(ROMPath[slot]) - 3, "sav", 3); } +bool LoadBIOS() +{ + // TODO: + // original code in the libui frontend called NDS::LoadGBAROM() if needed + // should this be carried over here? + // is that behavior consistent with that of LoadROM() below? + + ROMPath[ROMSlot_NDS][0] = '\0'; + SRAMPath[ROMSlot_NDS][0] = '\0'; + + NDS::LoadBIOS(); + + // TODO: error reporting? + return true; +} + bool LoadROM(const char* file, int slot) { char oldpath[1024]; diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index e9b9122..cadcec9 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -394,10 +394,17 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) QMenuBar* menubar = new QMenuBar(); { QMenu* menu = menubar->addMenu("File"); - QAction* act; - act = menu->addAction("Open file..."); - connect(act, &QAction::triggered, this, &MainWindow::onOpenFile); + actOpenROM = menu->addAction("Open file..."); + connect(actOpenROM, &QAction::triggered, this, &MainWindow::onOpenFile); + + actBootFirmware = menu->addAction("Launch DS menu"); + connect(actBootFirmware, &QAction::triggered, this, &MainWindow::onBootFirmware); + + menu->addSeparator(); + + actQuit = menu->addAction("Quit"); + connect(actQuit, &QAction::triggered, this, &MainWindow::onQuit); } setMenuBar(menubar); @@ -411,6 +418,12 @@ MainWindow::~MainWindow() } +void MainWindow::keyPressEvent(QKeyEvent* event) +{ + printf("key press. %d %d %08X %08X\n", event->key(), event->nativeScanCode(), event->modifiers(), event->nativeModifiers()); +} + + void MainWindow::onOpenFile() { emuThread->emuPause(true); @@ -465,6 +478,31 @@ void MainWindow::onOpenFile() } } +void MainWindow::onBootFirmware() +{ + // TODO: ensure the firmware is actually bootable!! + // TODO: check the whole GBA cart shito + + emuThread->emuPause(true); + + bool res = Frontend::LoadBIOS(); + if (!res) + { + // TODO! + + emuThread->emuUnpause(); + } + else + { + emuThread->emuRun(); + } +} + +void MainWindow::onQuit() +{ + QApplication::quit(); +} + void MainWindow::onTitleUpdate(QString title) { diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index a1093fe..9ccbddd 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -75,13 +75,22 @@ public: explicit MainWindow(QWidget* parent = nullptr); ~MainWindow(); +protected: + void keyPressEvent(QKeyEvent* event) override; + private slots: void onOpenFile(); + void onBootFirmware(); + void onQuit(); void onTitleUpdate(QString title); private: MainWindowPanel* panel; + + QAction* actOpenROM; + QAction* actBootFirmware; + QAction* actQuit; }; #endif // MAIN_H -- cgit v1.2.3 From 47ff012f5ed743d30d994a10de48e07b650f706b Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 28 Apr 2020 22:46:31 +0200 Subject: blarg --- src/frontend/qt_sdl/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index cadcec9..af4fd4b 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -398,7 +398,8 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) actOpenROM = menu->addAction("Open file..."); connect(actOpenROM, &QAction::triggered, this, &MainWindow::onOpenFile); - actBootFirmware = menu->addAction("Launch DS menu"); + //actBootFirmware = menu->addAction("Launch DS menu"); + actBootFirmware = menu->addAction("Boot firmware"); connect(actBootFirmware, &QAction::triggered, this, &MainWindow::onBootFirmware); menu->addSeparator(); -- cgit v1.2.3 From 5fbad464c27fd5290c837d78a72378215ee8e77f Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 29 Apr 2020 00:50:23 +0200 Subject: hook up savestate shito --- src/frontend/FrontendUtil.h | 2 +- src/frontend/Util_ROM.cpp | 2 + src/frontend/qt_sdl/main.cpp | 141 ++++++++++++++++++++++++++++++++++++++++++- src/frontend/qt_sdl/main.h | 6 ++ 4 files changed, 149 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/frontend/FrontendUtil.h b/src/frontend/FrontendUtil.h index eb4cb38..d9f5c58 100644 --- a/src/frontend/FrontendUtil.h +++ b/src/frontend/FrontendUtil.h @@ -47,7 +47,7 @@ bool LoadBIOS(); // note: loading a ROM to the NDS slot resets emulation bool LoadROM(const char* file, int slot); -// get the filename associated with the given savestate slot +// get the filename associated with the given savestate slot (1-8) void GetSavestateName(int slot, char* filename, int len); // determine whether the given savestate slot does contain a savestate diff --git a/src/frontend/Util_ROM.cpp b/src/frontend/Util_ROM.cpp index cf40a78..19c8eb9 100644 --- a/src/frontend/Util_ROM.cpp +++ b/src/frontend/Util_ROM.cpp @@ -69,6 +69,8 @@ bool LoadBIOS() NDS::LoadBIOS(); + SavestateLoaded = false; + // TODO: error reporting? return true; } diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index af4fd4b..a6a1423 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -395,7 +395,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { QMenu* menu = menubar->addMenu("File"); - actOpenROM = menu->addAction("Open file..."); + actOpenROM = menu->addAction("Open ROM..."); connect(actOpenROM, &QAction::triggered, this, &MainWindow::onOpenFile); //actBootFirmware = menu->addAction("Launch DS menu"); @@ -404,6 +404,49 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) menu->addSeparator(); + { + QMenu* submenu = menu->addMenu("Save state"); + + for (int i = 1; i < 9; i++) + { + char title[16]; + sprintf(title, "%d", i); + actSaveState[i] = submenu->addAction(title); + actSaveState[i]->setShortcut(QKeySequence(Qt::ShiftModifier | (Qt::Key_F1+i-1))); + actSaveState[i]->setData(QVariant(i)); + connect(actSaveState[i], &QAction::triggered, this, &MainWindow::onSaveState); + } + + actSaveState[0] = submenu->addAction("File..."); + actSaveState[0]->setShortcut(QKeySequence(Qt::ShiftModifier | Qt::Key_F9)); + actSaveState[0]->setData(QVariant(0)); + connect(actSaveState[0], &QAction::triggered, this, &MainWindow::onSaveState); + } + { + QMenu* submenu = menu->addMenu("Load state"); + + for (int i = 1; i < 9; i++) + { + char title[16]; + sprintf(title, "%d", i); + actLoadState[i] = submenu->addAction(title); + actLoadState[i]->setShortcut(QKeySequence(Qt::Key_F1+i-1)); + actLoadState[i]->setData(QVariant(i)); + connect(actLoadState[i], &QAction::triggered, this, &MainWindow::onLoadState); + } + + actLoadState[0] = submenu->addAction("File..."); + actLoadState[0]->setShortcut(QKeySequence(Qt::Key_F9)); + actLoadState[0]->setData(QVariant(0)); + connect(actLoadState[0], &QAction::triggered, this, &MainWindow::onLoadState); + } + + actUndoStateLoad = menu->addAction("Undo state load"); + actUndoStateLoad->setShortcut(QKeySequence(Qt::Key_F12)); + connect(actUndoStateLoad, &QAction::triggered, this, &MainWindow::onUndoStateLoad); + + menu->addSeparator(); + actQuit = menu->addAction("Quit"); connect(actQuit, &QAction::triggered, this, &MainWindow::onQuit); } @@ -499,6 +542,102 @@ void MainWindow::onBootFirmware() } } +void MainWindow::onSaveState() +{ + int slot = ((QAction*)sender())->data().toInt(); + + emuThread->emuPause(true); + + char filename[1024]; + if (slot > 0) + { + Frontend::GetSavestateName(slot, filename, 1024); + } + else + { + // TODO: specific 'last directory' for savestate files? + QString qfilename = QFileDialog::getSaveFileName(this, + "Save state", + Config::LastROMFolder, + "melonDS savestates (*.mln);;Any file (*.*)"); + if (qfilename.isEmpty()) + { + emuThread->emuUnpause(); + return; + } + + strncpy(filename, qfilename.toStdString().c_str(), 1023); filename[1023] = '\0'; + } + + if (Frontend::SaveState(filename)) + { + // TODO: OSD message + } + else + { + // TODO: OSD error message? + } + + emuThread->emuUnpause(); +} + +void MainWindow::onLoadState() +{ + int slot = ((QAction*)sender())->data().toInt(); + + emuThread->emuPause(true); + + char filename[1024]; + if (slot > 0) + { + Frontend::GetSavestateName(slot, filename, 1024); + } + else + { + // TODO: specific 'last directory' for savestate files? + QString qfilename = QFileDialog::getOpenFileName(this, + "Load state", + Config::LastROMFolder, + "melonDS savestates (*.ml*);;Any file (*.*)"); + if (qfilename.isEmpty()) + { + emuThread->emuUnpause(); + return; + } + + strncpy(filename, qfilename.toStdString().c_str(), 1023); filename[1023] = '\0'; + } + + if (!Platform::FileExists(filename)) + { + /*char msg[64]; + if (slot > 0) sprintf(msg, "State slot %d is empty", slot); + else sprintf(msg, "State file does not exist"); + OSD::AddMessage(0xFFA0A0, msg);*/ + + emuThread->emuUnpause(); + return; + } + + if (Frontend::LoadState(filename)) + { + // TODO: OSD message + } + else + { + // TODO: OSD error message? + } + + emuThread->emuUnpause(); +} + +void MainWindow::onUndoStateLoad() +{ + emuThread->emuPause(true); + Frontend::UndoStateLoad(); + emuThread->emuUnpause(); +} + void MainWindow::onQuit() { QApplication::quit(); diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 9ccbddd..8694838 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -81,6 +81,9 @@ protected: private slots: void onOpenFile(); void onBootFirmware(); + void onSaveState(); + void onLoadState(); + void onUndoStateLoad(); void onQuit(); void onTitleUpdate(QString title); @@ -90,6 +93,9 @@ private: QAction* actOpenROM; QAction* actBootFirmware; + QAction* actSaveState[9]; + QAction* actLoadState[9]; + QAction* actUndoStateLoad; QAction* actQuit; }; -- cgit v1.2.3 From 7f3e67c12a6b7687467c4b56d79e4770cc32ae43 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 30 Apr 2020 01:02:17 +0200 Subject: some more UI work --- src/frontend/qt_sdl/main.cpp | 93 ++++++++++++++++++++++++++++++++++++++++++++ src/frontend/qt_sdl/main.h | 19 +++++++++ 2 files changed, 112 insertions(+) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index a6a1423..5cc4826 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -63,6 +63,10 @@ EmuThread::EmuThread(QObject* parent) : QThread(parent) RunningSomething = false; connect(this, SIGNAL(windowTitleChange(QString)), mainWindow, SLOT(onTitleUpdate(QString))); + connect(this, SIGNAL(windowEmuStart()), mainWindow, SLOT(onEmuStart())); + connect(this, SIGNAL(windowEmuStop()), mainWindow, SLOT(onEmuStop())); + + emit windowEmuStop(); } void EmuThread::run() @@ -331,6 +335,9 @@ void EmuThread::emuRun() { EmuRunning = 1; RunningSomething = true; + + // checkme + emit windowEmuStart(); } void EmuThread::emuPause(bool refresh) @@ -339,11 +346,15 @@ void EmuThread::emuPause(bool refresh) PrevEmuStatus = EmuRunning; EmuRunning = status; while (EmuStatus != status); + + //emit windowEmuPause(); } void EmuThread::emuUnpause() { EmuRunning = PrevEmuStatus; + + //emit windowEmuUnpause(); } void EmuThread::emuStop() @@ -351,6 +362,11 @@ void EmuThread::emuStop() EmuRunning = 0; } +bool EmuThread::emuIsRunning() +{ + return (EmuRunning == 1); +} + MainWindowPanel::MainWindowPanel(QWidget* parent) : QWidget(parent) { @@ -450,6 +466,19 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) actQuit = menu->addAction("Quit"); connect(actQuit, &QAction::triggered, this, &MainWindow::onQuit); } + { + QMenu* menu = menubar->addMenu("System"); + + actPause = menu->addAction("Pause"); + actPause->setCheckable(true); + connect(actPause, &QAction::triggered, this, &MainWindow::onPause); + + actReset = menu->addAction("Reset"); + connect(actReset, &QAction::triggered, this, &MainWindow::onReset); + + actStop = menu->addAction("Stop"); + connect(actStop, &QAction::triggered, this, &MainWindow::onStop); + } setMenuBar(menubar); panel = new MainWindowPanel(this); @@ -644,11 +673,75 @@ void MainWindow::onQuit() } +void MainWindow::onPause(bool checked) +{ + if (emuThread->emuIsRunning()) + { + emuThread->emuPause(true); + } + else + { + emuThread->emuUnpause(); + } +} + +void MainWindow::onReset() +{ + // +} + +void MainWindow::onStop() +{ + // +} + + void MainWindow::onTitleUpdate(QString title) { setWindowTitle(title); } +void MainWindow::onEmuStart() +{ + for (int i = 1; i < 9; i++) + { + actSaveState[i]->setEnabled(true); + actLoadState[i]->setEnabled(Frontend::SavestateExists(i)); + } + actSaveState[0]->setEnabled(true); + actLoadState[0]->setEnabled(true); + actUndoStateLoad->setEnabled(true); + + actPause->setEnabled(true); + actPause->setChecked(false); + actReset->setEnabled(true); + actStop->setEnabled(true); +} + +void MainWindow::onEmuStop() +{ + for (int i = 0; i < 9; i++) + { + actSaveState[i]->setEnabled(false); + actLoadState[i]->setEnabled(false); + } + actUndoStateLoad->setEnabled(false); + + actPause->setEnabled(false); + actReset->setEnabled(false); + actStop->setEnabled(false); +} + +void MainWindow::onEmuPause() +{ + // +} + +void MainWindow::onEmuUnpause() +{ + // +} + int main(int argc, char** argv) { diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 8694838..30cef1f 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -41,9 +41,15 @@ public: void emuUnpause(); void emuStop(); + bool emuIsRunning(); + signals: void windowTitleChange(QString title); + void windowEmuStart(); + void windowEmuStop(); + void windowPauseToggle(); + private: volatile int EmuStatus; int PrevEmuStatus; @@ -86,8 +92,17 @@ private slots: void onUndoStateLoad(); void onQuit(); + void onPause(bool checked); + void onReset(); + void onStop(); + void onTitleUpdate(QString title); + void onEmuStart(); + void onEmuStop(); + void onEmuPause(); + void onEmuUnpause(); + private: MainWindowPanel* panel; @@ -97,6 +112,10 @@ private: QAction* actLoadState[9]; QAction* actUndoStateLoad; QAction* actQuit; + + QAction* actPause; + QAction* actReset; + QAction* actStop; }; #endif // MAIN_H -- cgit v1.2.3 From 690f39ca3382f1e82a27c8a16dde1a4379f978f8 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 2 May 2020 19:41:03 +0200 Subject: enable savestate slots when saving a new savestate --- src/frontend/qt_sdl/main.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 5cc4826..bdf68bd 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -601,6 +601,8 @@ void MainWindow::onSaveState() if (Frontend::SaveState(filename)) { // TODO: OSD message + + actLoadState[slot]->setEnabled(true); } else { -- cgit v1.2.3 From aa4344e249d855bfc2ddd52af61d3213d9e99db3 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 2 May 2020 20:25:39 +0200 Subject: add audio output. HARK HARK HARK --- src/CMakeLists.txt | 3 ++ src/frontend/FrontendUtil.h | 13 ++++++ src/frontend/Util_Audio.cpp | 77 ++++++++++++++++++++++++++++++ src/frontend/qt_sdl/CMakeLists.txt | 1 + src/frontend/qt_sdl/main.cpp | 96 +++++++++++++++++++++++++++++++++++--- 5 files changed, 184 insertions(+), 6 deletions(-) create mode 100644 src/frontend/Util_Audio.cpp (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dca0ca9..245e6a2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,6 +4,7 @@ add_library(core STATIC ARCodeList.cpp AREngine.cpp ARM.cpp + ARM_InstrTable.h ARMInterpreter.cpp ARMInterpreter_ALU.cpp ARMInterpreter_Branch.cpp @@ -12,11 +13,13 @@ add_library(core STATIC CP15.cpp CRC32.cpp DMA.cpp + FIFO.h GBACart.cpp GPU.cpp GPU2D.cpp GPU3D.cpp GPU3D_OpenGL.cpp + GPU3D_OpenGL_shaders.h GPU3D_Soft.cpp NDS.cpp NDSCart.cpp diff --git a/src/frontend/FrontendUtil.h b/src/frontend/FrontendUtil.h index d9f5c58..32f28d1 100644 --- a/src/frontend/FrontendUtil.h +++ b/src/frontend/FrontendUtil.h @@ -63,6 +63,19 @@ bool SaveState(const char* filename); // undo the latest savestate load void UndoStateLoad(); + +// initialize the audio utility +void Init_Audio(int outputfreq); + +// get how many samples to read from the core audio output +// based on how many are needed by the frontend (outlen in samples) +int AudioOut_GetNumSamples(int outlen); + +// resample audio from the core audio output to match the frontend's +// output frequency, and apply user-specified volume +// note: this assumes the output buffer is interleaved stereo +void AudioOut_Resample(s16* inbuf, int inlen, s16* outbuf, int outlen); + } #endif // FRONTENDUTIL_H diff --git a/src/frontend/Util_Audio.cpp b/src/frontend/Util_Audio.cpp new file mode 100644 index 0000000..fe0ecab --- /dev/null +++ b/src/frontend/Util_Audio.cpp @@ -0,0 +1,77 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include +#include +#include + +#include "FrontendUtil.h" +#include "Config.h" +#include "qt_sdl/PlatformConfig.h" // FIXME!!! +#include "Platform.h" + +#include "NDS.h" +#include "GBACart.h" + + +namespace Frontend +{ + +int AudioOut_Freq; +float AudioOut_SampleFrac; + + +void Init_Audio(int outputfreq) +{ + AudioOut_Freq = outputfreq; + AudioOut_SampleFrac = 0; +} + +int AudioOut_GetNumSamples(int outlen) +{ + float f_len_in = (outlen * 32823.6328125) / (float)AudioOut_Freq; + f_len_in += AudioOut_SampleFrac; + int len_in = (int)floor(f_len_in); + AudioOut_SampleFrac = f_len_in - len_in; + + return len_in; +} + +void AudioOut_Resample(s16* inbuf, int inlen, s16* outbuf, int outlen) +{ + float res_incr = inlen / (float)outlen; + float res_timer = 0; + int res_pos = 0; + + int volume = Config::AudioVolume; + + for (int i = 0; i < outlen; i++) + { + outbuf[i*2 ] = (inbuf[res_pos*2 ] * volume) >> 8; + outbuf[i*2+1] = (inbuf[res_pos*2+1] * volume) >> 8; + + res_timer += res_incr; + while (res_timer >= 1.0) + { + res_timer -= 1.0; + res_pos++; + } + } +} + +} diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index fb9f547..05a4029 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -6,6 +6,7 @@ SET(SOURCES_QT_SDL PlatformConfig.cpp ../Util_ROM.cpp + ../Util_Audio.cpp ../FrontendUtil.h ) diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index bdf68bd..80c25b5 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -48,6 +48,8 @@ #include "Savestate.h" +// TODO: uniform variable spelling + char* EmuDirectory; bool RunningSomething; @@ -55,6 +57,48 @@ bool RunningSomething; MainWindow* mainWindow; EmuThread* emuThread; +SDL_AudioDeviceID audioDevice; +int audioFreq; +SDL_cond* audioSync; +SDL_mutex* audioSyncLock; + + +void audioCallback(void* data, Uint8* stream, int len) +{ + len /= (sizeof(s16) * 2); + + // resample incoming audio to match the output sample rate + + int len_in = Frontend::AudioOut_GetNumSamples(len); + s16 buf_in[1024*2]; + int num_in; + + SDL_LockMutex(audioSyncLock); + num_in = SPU::ReadOutput(buf_in, len_in); + SDL_CondSignal(audioSync); + SDL_UnlockMutex(audioSyncLock); + + if (num_in < 1) + { + memset(stream, 0, len*sizeof(s16)*2); + return; + } + + int margin = 6; + if (num_in < len_in-margin) + { + int last = num_in-1; + if (last < 0) last = 0; + + for (int i = num_in; i < len_in-margin; i++) + ((u32*)buf_in)[i] = ((u32*)buf_in)[last]; + + num_in = len_in-margin; + } + + Frontend::AudioOut_Resample(buf_in, num_in, (s16*)stream, len); +} + EmuThread::EmuThread(QObject* parent) : QThread(parent) { @@ -213,18 +257,18 @@ void EmuThread::run() mainWindow->update(); bool fastforward = false; - /*bool fastforward = HotkeyDown(HK_FastForward); + //bool fastforward = HotkeyDown(HK_FastForward); - if (Config::AudioSync && !fastforward) + if (Config::AudioSync && (!fastforward) && audioDevice) { - SDL_LockMutex(AudioSyncLock); + SDL_LockMutex(audioSyncLock); while (SPU::GetOutputSize() > 1024) { - int ret = SDL_CondWaitTimeout(AudioSync, AudioSyncLock, 500); + int ret = SDL_CondWaitTimeout(audioSync, audioSyncLock, 500); if (ret == SDL_MUTEX_TIMEDOUT) break; } - SDL_UnlockMutex(AudioSyncLock); - }*/ + SDL_UnlockMutex(audioSyncLock); + } float framerate = (1000.0f * nlines) / (60.0f * 263.0f); @@ -338,6 +382,7 @@ void EmuThread::emuRun() // checkme emit windowEmuStart(); + if (audioDevice) SDL_PauseAudioDevice(audioDevice, 0); } void EmuThread::emuPause(bool refresh) @@ -348,6 +393,7 @@ void EmuThread::emuPause(bool refresh) while (EmuStatus != status); //emit windowEmuPause(); + if (audioDevice) SDL_PauseAudioDevice(audioDevice, 1); } void EmuThread::emuUnpause() @@ -355,11 +401,14 @@ void EmuThread::emuUnpause() EmuRunning = PrevEmuStatus; //emit windowEmuUnpause(); + if (audioDevice) SDL_PauseAudioDevice(audioDevice, 0); } void EmuThread::emuStop() { EmuRunning = 0; + + if (audioDevice) SDL_PauseAudioDevice(audioDevice, 1); } bool EmuThread::emuIsRunning() @@ -908,6 +957,32 @@ int main(int argc, char** argv) } #endif + audioSync = SDL_CreateCond(); + audioSyncLock = SDL_CreateMutex(); + + audioFreq = 48000; // TODO: make configurable? + SDL_AudioSpec whatIwant, whatIget; + memset(&whatIwant, 0, sizeof(SDL_AudioSpec)); + whatIwant.freq = audioFreq; + whatIwant.format = AUDIO_S16LSB; + whatIwant.channels = 2; + whatIwant.samples = 1024; + whatIwant.callback = audioCallback; + audioDevice = SDL_OpenAudioDevice(NULL, 0, &whatIwant, &whatIget, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE); + if (!audioDevice) + { + printf("Audio init failed: %s\n", SDL_GetError()); + } + else + { + audioFreq = whatIget.freq; + printf("Audio output frequency: %d Hz\n", audioFreq); + SDL_PauseAudioDevice(audioDevice, 1); + } + + Frontend::Init_ROM(); + Frontend::Init_Audio(audioFreq); + mainWindow = new MainWindow(); mainWindow->show(); @@ -955,6 +1030,15 @@ int main(int argc, char** argv) emuThread->emuStop(); emuThread->wait(); + //if (Joystick) SDL_JoystickClose(Joystick); + if (audioDevice) SDL_CloseAudioDevice(audioDevice); + //if (MicDevice) SDL_CloseAudioDevice(MicDevice); + + SDL_DestroyCond(audioSync); + SDL_DestroyMutex(audioSyncLock); + + //if (MicWavBuffer) delete[] MicWavBuffer; + Config::Save(); SDL_Quit(); -- cgit v1.2.3 From 9432a9f3822f024e97185ac4b0a9df5c07987dd1 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 3 May 2020 15:05:52 +0200 Subject: remove useless variables --- src/frontend/qt_sdl/main.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 80c25b5..643cf90 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -147,10 +147,6 @@ void EmuThread::run() u32 lasttick = starttick; u32 lastmeasuretick = lasttick; u32 fpslimitcount = 0; - u64 perfcount = SDL_GetPerformanceCounter(); - u64 perffreq = SDL_GetPerformanceFrequency(); - float samplesleft = 0; - u32 nsamples = 0; char melontitle[100]; @@ -288,7 +284,6 @@ void EmuThread::run() if ((abs(wantedtickF - (float)wantedtick) < 0.001312) || (fpslimitcount > 60)) { fpslimitcount = 0; - nsamples = 0; starttick = lasttick; } } -- cgit v1.2.3 From ffe20c1236d4f8140d25c7548ab452e7b35064bd Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Thu, 30 Apr 2020 03:20:18 +0200 Subject: Use Qt abstractions instead of glib's for paths on Linux --- src/frontend/qt_sdl/CMakeLists.txt | 18 ------------- src/frontend/qt_sdl/Platform.cpp | 53 +++++++++++++++++--------------------- src/frontend/qt_sdl/main.cpp | 9 +++---- 3 files changed, 27 insertions(+), 53 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index 05a4029..f03cad2 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -35,27 +35,9 @@ if (UNIX) add_definitions(-DUNIX_PORTABLE) endif() - find_package(PkgConfig REQUIRED) - pkg_check_modules(GTK3 REQUIRED gtk+-3.0) - - target_include_directories(melonDS PRIVATE ${GTK3_INCLUDE_DIRS}) - target_link_libraries(melonDS ${GTK3_LIBRARIES}) - - ADD_DEFINITIONS(${GTK3_CFLAGS_OTHER}) - - add_custom_command(OUTPUT melon_grc.c - COMMAND glib-compile-resources --sourcedir=${CMAKE_SOURCE_DIR} - --target=${CMAKE_CURRENT_BINARY_DIR}/melon_grc.c - --generate-source "${CMAKE_SOURCE_DIR}/melon_grc.xml" - COMMAND glib-compile-resources --sourcedir=${CMAKE_SOURCE_DIR} - --target=${CMAKE_CURRENT_BINARY_DIR}/melon_grc.h - --generate-header "${CMAKE_SOURCE_DIR}/melon_grc.xml") - if (CMAKE_SYSTEM_NAME STREQUAL "Linux") target_link_libraries(melonDS dl Qt5::Core Qt5::Gui Qt5::Widgets) endif () - - target_sources(melonDS PUBLIC melon_grc.c) elseif (WIN32) target_sources(melonDS PUBLIC "${CMAKE_SOURCE_DIR}/melon.rc") target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32 Qt5::Core Qt5::Gui Qt5::Widgets) diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index 31b5277..de8db93 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -37,7 +37,8 @@ #define socket_t SOCKET #define sockaddr_t SOCKADDR #else - #include + #include + #include #include #include #include @@ -139,6 +140,7 @@ FILE* OpenFile(const char* path, const char* mode, bool mustexist) FILE* OpenLocalFile(const char* path, const char* mode) { std::string fullpath; + if (path[0] == '/') { // If it's an absolute path, just open that. @@ -147,9 +149,10 @@ FILE* OpenLocalFile(const char* path, const char* mode) else { // Check user configuration directory - std::string confpath = std::string(g_get_user_config_dir()) + "/melonDS/"; - g_mkdir_with_parents(confpath.c_str(), 0755); - fullpath = confpath + path; + QString confpath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/melonDS/"; + confpath.append(path); + + fullpath = confpath.toStdString(); } return OpenFile(fullpath.c_str(), mode, mode[0] != 'w'); @@ -157,37 +160,27 @@ FILE* OpenLocalFile(const char* path, const char* mode) FILE* OpenDataFile(const char* path) { - const char* melondir = "melonDS"; - const char* const* sys_dirs = g_get_system_data_dirs(); - const char* user_dir = g_get_user_data_dir(); + QString melondir = "melonDS"; + QStringList sys_dirs = QStandardPaths::standardLocations(QStandardPaths::DataLocation); + QString sep = QDir::separator(); - // First check the user's data directory - char* fullpath = g_build_path("/", user_dir, melondir, path, NULL); - if (access(fullpath, R_OK) == 0) - { - FILE* f = fopen(fullpath, "r"); - g_free(fullpath); - return f; - } - free(fullpath); + const char* found = NULL; - // Then check the system data directories - for (size_t i = 0; sys_dirs[i] != NULL; i++) - { - const char* dir = sys_dirs[i]; - char* fullpath = g_build_path("/", dir, melondir, path, NULL); + for (int i = 0; i < sys_dirs.size(); i++) { + QString f = sys_dirs.at(i) + sep + melondir + sep + QString(path); - if (access(fullpath, R_OK) == 0) - { - FILE* f = fopen(fullpath, "r"); - g_free(fullpath); - return f; + if (QFile::exists(f)) { + found = f.toStdString().c_str(); + break; } - free(fullpath); } - FILE* f = fopen(path, "rb"); - if (f) return f; + if (found == NULL) + return NULL; + + FILE* f = fopen(found, "rb"); + if (f) + return f; return NULL; } @@ -299,7 +292,7 @@ FILE* OpenLocalFile(const char* path, const char* mode) { // Now check XDG_CONFIG_HOME // TODO: check for memory leak there - std::string fullpath = std::string(g_get_user_config_dir()) + "/melonDS/" + path; + std::string fullpath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation).toStdString() + "/melonDS/" + path; f = OpenFile(fullpath.c_str(), mode, true); if (f) { delete[] emudirpath; return f; } } diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 643cf90..81fa16f 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include @@ -824,11 +825,9 @@ int main(int argc, char** argv) strcpy(EmuDirectory, "."); } #else - const char* confdir = g_get_user_config_dir(); - const char* confname = "/melonDS"; - EmuDirectory = new char[strlen(confdir) + strlen(confname) + 1]; - strcat(EmuDirectory, confdir); - strcat(EmuDirectory, confname); + QString confdir = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/melonDS"; + EmuDirectory = new char[confdir.length() + 1]; + strcat(EmuDirectory, confdir.toStdString().c_str()); #endif QApplication melon(argc, argv); -- cgit v1.2.3 From 6cfe4faa56f4c7c34bf42cd600c66a2ed7966062 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 6 May 2020 02:36:47 +0200 Subject: Use Qt abstractions for file I/O and threading on both Windows and Linux. --- src/frontend/qt_sdl/CMakeLists.txt | 13 +- src/frontend/qt_sdl/Platform.cpp | 537 +++++++++++++------------------------ 2 files changed, 191 insertions(+), 359 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index f03cad2..0b39a1c 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -17,6 +17,7 @@ endif() find_package(Qt5 COMPONENTS Core REQUIRED) find_package(Qt5 COMPONENTS Gui REQUIRED) find_package(Qt5 COMPONENTS Widgets REQUIRED) +find_package(Threads REQUIRED) set(CMAKE_AUTOMOC ON) @@ -27,22 +28,24 @@ add_executable(melonDS ${SOURCES_QT_SDL}) target_include_directories(melonDS PRIVATE ${SDL2_INCLUDE_DIRS}) target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..") target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../..") -target_link_libraries(melonDS core ${SDL2_LIBRARIES}) +target_link_libraries(melonDS core ${SDL2_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) if (UNIX) - option(UNIX_PORTABLE "Make a portable build that looks for its configuration in the current directory" OFF) - if (UNIX_PORTABLE) - add_definitions(-DUNIX_PORTABLE) - endif() + option(PORTABLE "Make a portable build that looks for its configuration in the current directory" OFF) if (CMAKE_SYSTEM_NAME STREQUAL "Linux") target_link_libraries(melonDS dl Qt5::Core Qt5::Gui Qt5::Widgets) endif () elseif (WIN32) + option(PORTABLE "Make a portable build that looks for its configuration in the current directory" ON) target_sources(melonDS PUBLIC "${CMAKE_SOURCE_DIR}/melon.rc") target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32 Qt5::Core Qt5::Gui Qt5::Widgets) endif () +if (PORTABLE) + add_definitions(-DPORTABLE) +endif() + install(FILES ../../net.kuribo64.melonDS.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) install(FILES ../../icon/melon_16x16.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/16x16/apps RENAME net.kuribo64.melonDS.png) install(FILES ../../icon/melon_32x32.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/32x32/apps RENAME net.kuribo64.melonDS.png) diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index de8db93..ddf48e9 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -19,34 +19,36 @@ #include #include #include -#include +#include +#include +#include +#include +#include + #include "Platform.h" #include "PlatformConfig.h" //#include "LAN_Socket.h" //#include "LAN_PCap.h" -#include #ifdef __WIN32__ - #define NTDDI_VERSION 0x06000000 // GROSS FUCKING HACK - #include - //#include // FUCK THAT SHIT - extern "C" const GUID DECLSPEC_SELECTANY FOLDERID_RoamingAppData = {0x3eb685db, 0x65f9, 0x4cf6, {0xa0, 0x3a, 0xe3, 0xef, 0x65, 0x72, 0x9f, 0x3d}}; - #include - #include - #include - #define socket_t SOCKET - #define sockaddr_t SOCKADDR +#define NTDDI_VERSION 0x06000000 // GROSS FUCKING HACK +#include +//#include // FUCK THAT SHIT +#include +#include +#include +#define socket_t SOCKET +#define sockaddr_t SOCKADDR #else - #include - #include - #include - #include - #include - #include - #include - #define socket_t int - #define sockaddr_t struct sockaddr - #define closesocket close + +#include +#include +#include +#include + +#define socket_t int +#define sockaddr_t struct sockaddr +#define closesocket close #endif #ifndef INVALID_SOCKET @@ -62,22 +64,6 @@ void Stop(bool internal); namespace Platform { - -typedef struct -{ - SDL_Thread* ID; - void (*Func)(); - -} ThreadData; - -int ThreadEntry(void* data) -{ - ThreadData* thread = (ThreadData*)data; - thread->Func(); - return 0; -} - - socket_t MPSocket; sockaddr_t MPSendAddr; u8 PacketBuffer[2048]; @@ -87,307 +73,151 @@ u8 PacketBuffer[2048]; void StopEmu() { - //Stop(true); + //Stop(true); } - FILE* OpenFile(const char* path, const char* mode, bool mustexist) { - FILE* ret; - -#ifdef __WIN32__ + QFile f(path); - int len = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0); - if (len < 1) return NULL; - WCHAR* fatpath = new WCHAR[len]; - int res = MultiByteToWideChar(CP_UTF8, 0, path, -1, fatpath, len); - if (res != len) { delete[] fatpath; return NULL; } // checkme? - - // this will be more than enough - WCHAR fatmode[4]; - fatmode[0] = mode[0]; - fatmode[1] = mode[1]; - fatmode[2] = mode[2]; - fatmode[3] = 0; - - if (mustexist) - { - ret = _wfopen(fatpath, L"rb"); - if (ret) ret = _wfreopen(fatpath, fatmode, ret); - } - else - ret = _wfopen(fatpath, fatmode); - - delete[] fatpath; + if (!mustexist && !f.exists()) + return nullptr; -#else - - if (mustexist) - { - ret = fopen(path, "rb"); - if (ret) ret = freopen(path, mode, ret); - } - else - ret = fopen(path, mode); + f.open(QIODevice::ReadOnly); + FILE* file = fdopen(dup(f.handle()), mode); + f.close(); -#endif - - return ret; + return file; } -#if !defined(UNIX_PORTABLE) && !defined(__WIN32__) - FILE* OpenLocalFile(const char* path, const char* mode) { - std::string fullpath; - - if (path[0] == '/') - { - // If it's an absolute path, just open that. - fullpath = std::string(path); - } - else - { - // Check user configuration directory - QString confpath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/melonDS/"; - confpath.append(path); - - fullpath = confpath.toStdString(); - } - - return OpenFile(fullpath.c_str(), mode, mode[0] != 'w'); -} - -FILE* OpenDataFile(const char* path) -{ - QString melondir = "melonDS"; - QStringList sys_dirs = QStandardPaths::standardLocations(QStandardPaths::DataLocation); - QString sep = QDir::separator(); - - const char* found = NULL; - - for (int i = 0; i < sys_dirs.size(); i++) { - QString f = sys_dirs.at(i) + sep + melondir + sep + QString(path); + QString fullpath; - if (QFile::exists(f)) { - found = f.toStdString().c_str(); - break; - } - } - - if (found == NULL) - return NULL; - - FILE* f = fopen(found, "rb"); - if (f) - return f; + if (path[0] == '/') + { + // If it's an absolute path, just open that. + fullpath = path; + } + else + { +#ifdef PORTABLE + fullpath = QString("./") + path; +#else + // Check user configuration directory + fullpath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/melonDS/"; + fullpath.append(path); +#endif + } - return NULL; + return OpenFile(fullpath.toUtf8(), mode, mode[0] != 'w'); } -#else - -FILE* OpenLocalFile(const char* path, const char* mode) +FILE* OpenDataFile(const char* path) { - bool relpath = false; - int pathlen = strlen(path); - -#ifdef __WIN32__ - if (pathlen > 3) - { - if (path[1] == ':' && path[2] == '\\') - return OpenFile(path, mode); - } +#ifdef PORTABLE + return OpenLocalFile(path); #else - if (pathlen > 1) - { - if (path[0] == '/') - return OpenFile(path, mode); - } -#endif + QString melondir = "/melonDS/"; + QStringList sys_dirs = QStandardPaths::standardLocations(QStandardPaths::DataLocation); + QString found = nullptr; - if (pathlen >= 3) - { - if (path[0] == '.' && path[1] == '.' && (path[2] == '/' || path[2] == '\\')) - relpath = true; - } - - int emudirlen = strlen(EmuDirectory); - char* emudirpath; - if (emudirlen) - { - int len = emudirlen + 1 + pathlen + 1; - emudirpath = new char[len]; - strncpy(&emudirpath[0], EmuDirectory, emudirlen); - emudirpath[emudirlen] = '/'; - strncpy(&emudirpath[emudirlen+1], path, pathlen); - emudirpath[emudirlen+1+pathlen] = '\0'; - } - else - { - emudirpath = new char[pathlen+1]; - strncpy(&emudirpath[0], path, pathlen); - emudirpath[pathlen] = '\0'; - } - - // Locations are application directory, and AppData/melonDS on Windows or XDG_CONFIG_HOME/melonDS on Linux - - FILE* f; - - // First check current working directory - f = OpenFile(path, mode, true); - if (f) { delete[] emudirpath; return f; } - - // then emu directory - f = OpenFile(emudirpath, mode, true); - if (f) { delete[] emudirpath; return f; } + for (int i = 0; i < sys_dirs.size(); i++) + { + QString f = sys_dirs.at(i) + melondir + path; -#ifdef __WIN32__ + if (QFile::exists(f)) + { + found = f; + break; + } + } - // a path relative to AppData wouldn't make much sense - if (!relpath) - { - // Now check AppData - PWSTR appDataPath = NULL; - SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &appDataPath); - if (!appDataPath) - { - delete[] emudirpath; - return NULL; - } - - // this will be more than enough - WCHAR fatperm[4]; - fatperm[0] = mode[0]; - fatperm[1] = mode[1]; - fatperm[2] = mode[2]; - fatperm[3] = 0; - - int fnlen = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0); - if (fnlen < 1) { delete[] emudirpath; return NULL; } - WCHAR* wfileName = new WCHAR[fnlen]; - int res = MultiByteToWideChar(CP_UTF8, 0, path, -1, wfileName, fnlen); - if (res != fnlen) { delete[] wfileName; delete[] emudirpath; return NULL; } // checkme? - - const WCHAR* appdir = L"\\melonDS\\"; - - int pos = wcslen(appDataPath); - void* ptr = CoTaskMemRealloc(appDataPath, (pos+wcslen(appdir)+fnlen+1)*sizeof(WCHAR)); - if (!ptr) { delete[] wfileName; delete[] emudirpath; return NULL; } // oh well - appDataPath = (PWSTR)ptr; - - wcscpy(&appDataPath[pos], appdir); pos += wcslen(appdir); - wcscpy(&appDataPath[pos], wfileName); - - f = _wfopen(appDataPath, L"rb"); - if (f) f = _wfreopen(appDataPath, fatperm, f); - CoTaskMemFree(appDataPath); - delete[] wfileName; - if (f) { delete[] emudirpath; return f; } - } + if (found == nullptr) + return nullptr; -#else - - if (!relpath) - { - // Now check XDG_CONFIG_HOME - // TODO: check for memory leak there - std::string fullpath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation).toStdString() + "/melonDS/" + path; - f = OpenFile(fullpath.c_str(), mode, true); - if (f) { delete[] emudirpath; return f; } - } + FILE* f = OpenFile(found.toUtf8(), "rb", false); + if (f) + return f; + return nullptr; #endif - - if (mode[0] != 'r') - { - f = OpenFile(emudirpath, mode); - if (f) { delete[] emudirpath; return f; } - } - - delete[] emudirpath; - return NULL; } -FILE* OpenDataFile(const char* path) +void* Thread_Create(void (* func)()) { - return OpenLocalFile(path, "rb"); -} - -#endif - - -void* Thread_Create(void (*func)()) -{ - ThreadData* data = new ThreadData; - data->Func = func; - data->ID = SDL_CreateThread(ThreadEntry, "melonDS core thread", data); - return data; + QThread* t = QThread::create(func); + t->start(); + return (void*) t; } void Thread_Free(void* thread) { - delete (ThreadData*)thread; + QThread* t = (QThread*) thread; + t->terminate(); + delete t; } void Thread_Wait(void* thread) { - SDL_WaitThread((SDL_Thread*)((ThreadData*)thread)->ID, NULL); + ((QThread*) thread)->wait(); } void* Semaphore_Create() { - return SDL_CreateSemaphore(0); + return new QSemaphore(); } void Semaphore_Free(void* sema) { - SDL_DestroySemaphore((SDL_sem*)sema); + delete (QSemaphore*) sema; } void Semaphore_Reset(void* sema) { - while (SDL_SemTryWait((SDL_sem*)sema) == 0); + QSemaphore* s = (QSemaphore*) sema; + + s->acquire(s->available()); } void Semaphore_Wait(void* sema) { - SDL_SemWait((SDL_sem*)sema); + ((QSemaphore*) sema)->acquire(); } void Semaphore_Post(void* sema) { - SDL_SemPost((SDL_sem*)sema); + ((QSemaphore*) sema)->release(); } void* GL_GetProcAddress(const char* proc) { - return NULL;//uiGLGetProcAddress(proc); + return (void*) QOpenGLContext::globalShareContext()->getProcAddress(proc); } bool MP_Init() { - int opt_true = 1; - int res; + int opt_true = 1; + int res; #ifdef __WIN32__ - WSADATA wsadata; - if (WSAStartup(MAKEWORD(2, 2), &wsadata) != 0) - { - return false; - } + WSADATA wsadata; + if (WSAStartup(MAKEWORD(2, 2), &wsadata) != 0) + { + return false; + } #endif // __WIN32__ - MPSocket = socket(AF_INET, SOCK_DGRAM, 0); + MPSocket = socket(AF_INET, SOCK_DGRAM, 0); if (MPSocket < 0) { return false; } - res = setsockopt(MPSocket, SOL_SOCKET, SO_REUSEADDR, (const char*)&opt_true, sizeof(int)); + res = setsockopt(MPSocket, SOL_SOCKET, SO_REUSEADDR, (const char*) &opt_true, sizeof(int)); if (res < 0) { closesocket(MPSocket); @@ -397,8 +227,8 @@ bool MP_Init() sockaddr_t saddr; saddr.sa_family = AF_INET; - *(u32*)&saddr.sa_data[2] = htonl(Config::SocketBindAnyAddr ? INADDR_ANY : INADDR_LOOPBACK); - *(u16*)&saddr.sa_data[0] = htons(7064); + *(u32*) &saddr.sa_data[2] = htonl(Config::SocketBindAnyAddr ? INADDR_ANY : INADDR_LOOPBACK); + *(u16*) &saddr.sa_data[0] = htons(7064); res = bind(MPSocket, &saddr, sizeof(sockaddr_t)); if (res < 0) { @@ -407,7 +237,7 @@ bool MP_Init() return false; } - res = setsockopt(MPSocket, SOL_SOCKET, SO_BROADCAST, (const char*)&opt_true, sizeof(int)); + res = setsockopt(MPSocket, SOL_SOCKET, SO_BROADCAST, (const char*) &opt_true, sizeof(int)); if (res < 0) { closesocket(MPSocket); @@ -416,50 +246,50 @@ bool MP_Init() } MPSendAddr.sa_family = AF_INET; - *(u32*)&MPSendAddr.sa_data[2] = htonl(INADDR_BROADCAST); - *(u16*)&MPSendAddr.sa_data[0] = htons(7064); + *(u32*) &MPSendAddr.sa_data[2] = htonl(INADDR_BROADCAST); + *(u16*) &MPSendAddr.sa_data[0] = htons(7064); return true; } void MP_DeInit() { - if (MPSocket >= 0) - closesocket(MPSocket); + if (MPSocket >= 0) + closesocket(MPSocket); #ifdef __WIN32__ - WSACleanup(); + WSACleanup(); #endif // __WIN32__ } int MP_SendPacket(u8* data, int len) { - if (MPSocket < 0) - return 0; - - if (len > 2048-8) - { - printf("MP_SendPacket: error: packet too long (%d)\n", len); - return 0; - } - - *(u32*)&PacketBuffer[0] = htonl(0x4946494E); // NIFI - PacketBuffer[4] = NIFI_VER; - PacketBuffer[5] = 0; - *(u16*)&PacketBuffer[6] = htons(len); - memcpy(&PacketBuffer[8], data, len); - - int slen = sendto(MPSocket, (const char*)PacketBuffer, len+8, 0, &MPSendAddr, sizeof(sockaddr_t)); - if (slen < 8) return 0; - return slen - 8; + if (MPSocket < 0) + return 0; + + if (len > 2048 - 8) + { + printf("MP_SendPacket: error: packet too long (%d)\n", len); + return 0; + } + + *(u32*) &PacketBuffer[0] = htonl(0x4946494E); // NIFI + PacketBuffer[4] = NIFI_VER; + PacketBuffer[5] = 0; + *(u16*) &PacketBuffer[6] = htons(len); + memcpy(&PacketBuffer[8], data, len); + + int slen = sendto(MPSocket, (const char*) PacketBuffer, len + 8, 0, &MPSendAddr, sizeof(sockaddr_t)); + if (slen < 8) return 0; + return slen - 8; } int MP_RecvPacket(u8* data, bool block) { - if (MPSocket < 0) - return 0; + if (MPSocket < 0) + return 0; - fd_set fd; + fd_set fd; struct timeval tv; FD_ZERO(&fd); @@ -467,84 +297,83 @@ int MP_RecvPacket(u8* data, bool block) tv.tv_sec = 0; tv.tv_usec = block ? 5000 : 0; - if (!select(MPSocket+1, &fd, 0, 0, &tv)) - { - return 0; - } - - sockaddr_t fromAddr; - socklen_t fromLen = sizeof(sockaddr_t); - int rlen = recvfrom(MPSocket, (char*)PacketBuffer, 2048, 0, &fromAddr, &fromLen); - if (rlen < 8+24) - { - return 0; - } - rlen -= 8; - - if (ntohl(*(u32*)&PacketBuffer[0]) != 0x4946494E) - { - return 0; - } - - if (PacketBuffer[4] != NIFI_VER) - { - return 0; - } - - if (ntohs(*(u16*)&PacketBuffer[6]) != rlen) - { - return 0; - } - - memcpy(data, &PacketBuffer[8], rlen); - return rlen; -} + if (!select(MPSocket + 1, &fd, 0, 0, &tv)) + { + return 0; + } + sockaddr_t fromAddr; + socklen_t fromLen = sizeof(sockaddr_t); + int rlen = recvfrom(MPSocket, (char*) PacketBuffer, 2048, 0, &fromAddr, &fromLen); + if (rlen < 8 + 24) + { + return 0; + } + rlen -= 8; + + if (ntohl(*(u32*) &PacketBuffer[0]) != 0x4946494E) + { + return 0; + } + + if (PacketBuffer[4] != NIFI_VER) + { + return 0; + } + + if (ntohs(*(u16*) &PacketBuffer[6]) != rlen) + { + return 0; + } + + memcpy(data, &PacketBuffer[8], rlen); + return rlen; +} bool LAN_Init() { - /*if (Config::DirectLAN) - { - if (!LAN_PCap::Init(true)) - return false; - } - else - { - if (!LAN_Socket::Init()) - return false; - }*/ - - return true; + /*if (Config::DirectLAN) + { + if (!LAN_PCap::Init(true)) + return false; + } + else + { + if (!LAN_Socket::Init()) + return false; + }*/ + + return true; } void LAN_DeInit() { - // checkme. blarg - //if (Config::DirectLAN) - // LAN_PCap::DeInit(); - //else - // LAN_Socket::DeInit(); - /*LAN_PCap::DeInit(); - LAN_Socket::DeInit();*/ + // checkme. blarg + //if (Config::DirectLAN) + // LAN_PCap::DeInit(); + //else + // LAN_Socket::DeInit(); + /*LAN_PCap::DeInit(); + LAN_Socket::DeInit();*/ } int LAN_SendPacket(u8* data, int len) { - /*if (Config::DirectLAN) - return LAN_PCap::SendPacket(data, len); - else - return LAN_Socket::SendPacket(data, len);*/ - return 0; + /*if (Config::DirectLAN) + return LAN_PCap::SendPacket(data, len); + else + return LAN_Socket::SendPacket(data, len);*/ + return 0; } int LAN_RecvPacket(u8* data) { - /*if (Config::DirectLAN) - return LAN_PCap::RecvPacket(data); - else - return LAN_Socket::RecvPacket(data);*/ - return 0; + /*if (Config::DirectLAN) + return LAN_PCap::RecvPacket(data); + else + return LAN_Socket::RecvPacket(data);*/ + return 0; } -- cgit v1.2.3 From beb3b20d5e85f9d58017684dc0abc39a0352f2f4 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 6 May 2020 03:49:20 +0200 Subject: Fix crash with nonexistent config directory or writable files. --- src/frontend/qt_sdl/Platform.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index ddf48e9..7ce70ab 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -80,10 +80,12 @@ FILE* OpenFile(const char* path, const char* mode, bool mustexist) { QFile f(path); - if (!mustexist && !f.exists()) + if (mustexist && !f.exists()) + { return nullptr; + } - f.open(QIODevice::ReadOnly); + f.open(QIODevice::ReadWrite); FILE* file = fdopen(dup(f.handle()), mode); f.close(); @@ -105,7 +107,9 @@ FILE* OpenLocalFile(const char* path, const char* mode) fullpath = QString("./") + path; #else // Check user configuration directory - fullpath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/melonDS/"; + QDir config(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)); + config.mkdir("melonDS"); + fullpath = config.absolutePath() + "/melonDS/"; fullpath.append(path); #endif } -- cgit v1.2.3 From b746c0b7279d1f5b4bcfd02c115b09d583e9df4f Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 6 May 2020 03:53:05 +0200 Subject: Only initially open files as writable if they actually should be. --- src/frontend/qt_sdl/Platform.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index 7ce70ab..125e7ea 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -85,7 +85,9 @@ FILE* OpenFile(const char* path, const char* mode, bool mustexist) return nullptr; } - f.open(QIODevice::ReadWrite); + QIODevice::OpenMode qmode = mode[0] == 'w' ? QIODevice::ReadWrite : QIODevice::ReadOnly; + + f.open(qmode); FILE* file = fdopen(dup(f.handle()), mode); f.close(); -- cgit v1.2.3 From 978212e3e0b2d910ff3ca95464ad855f5872e500 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 16 May 2020 17:43:35 +0200 Subject: accept mouse events --- src/frontend/qt_sdl/main.cpp | 22 ++++++++++++++++++++++ src/frontend/qt_sdl/main.h | 4 ++++ 2 files changed, 26 insertions(+) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 643cf90..11602a6 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -447,6 +447,28 @@ void MainWindowPanel::paintEvent(QPaintEvent* event) } +void MainWindowPanel::mousePressEvent(QMouseEvent* event) +{ + event->accept(); + + printf("mouse press %d,%d\n", event->pos().x(), event->pos().y()); +} + +void MainWindowPanel::mouseReleaseEvent(QMouseEvent* event) +{ + event->accept(); + + printf("mouse release %d,%d\n", event->pos().x(), event->pos().y()); +} + +void MainWindowPanel::mouseMoveEvent(QMouseEvent* event) +{ + event->accept(); + + printf("mouse move %d,%d %08X\n", event->pos().x(), event->pos().y(), event->buttons()); +} + + MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { setWindowTitle("melonDS " MELONDS_VERSION); diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 30cef1f..f8ad9a3 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -68,6 +68,10 @@ public: protected: void paintEvent(QPaintEvent* event) override; + void mousePressEvent(QMouseEvent* event) override; + void mouseReleaseEvent(QMouseEvent* event) override; + void mouseMoveEvent(QMouseEvent* event) override; + private: QImage* screen[2]; }; -- cgit v1.2.3 From 2afa70b8172339266feabbb9a93f2f165521f7d8 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 17 May 2020 02:37:23 +0200 Subject: miserable little attempt at adding a dialog --- src/frontend/qt_sdl/CMakeLists.txt | 3 + src/frontend/qt_sdl/EmuSettingsDialog.cpp | 31 +++++ src/frontend/qt_sdl/EmuSettingsDialog.h | 38 ++++++ src/frontend/qt_sdl/EmuSettingsDialog.ui | 201 ++++++++++++++++++++++++++++++ src/frontend/qt_sdl/main.cpp | 15 +++ src/frontend/qt_sdl/main.h | 4 + 6 files changed, 292 insertions(+) create mode 100644 src/frontend/qt_sdl/EmuSettingsDialog.cpp create mode 100644 src/frontend/qt_sdl/EmuSettingsDialog.h create mode 100644 src/frontend/qt_sdl/EmuSettingsDialog.ui (limited to 'src') diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index 05a4029..a6aeb0e 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -2,6 +2,7 @@ project(qt_sdl) SET(SOURCES_QT_SDL main.cpp + EmuSettingsDialog.cpp Platform.cpp PlatformConfig.cpp @@ -19,6 +20,8 @@ find_package(Qt5 COMPONENTS Gui REQUIRED) find_package(Qt5 COMPONENTS Widgets REQUIRED) set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTORCC ON) find_package(PkgConfig REQUIRED) pkg_check_modules(SDL2 REQUIRED sdl2) diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.cpp b/src/frontend/qt_sdl/EmuSettingsDialog.cpp new file mode 100644 index 0000000..c64f192 --- /dev/null +++ b/src/frontend/qt_sdl/EmuSettingsDialog.cpp @@ -0,0 +1,31 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include "EmuSettingsDialog.h" +#include "ui_EmuSettingsDialog.h" + + +EmuSettingsDialog::EmuSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::EmuSettingsDialog) +{ + ui->setupUi(this); +} + +EmuSettingsDialog::~EmuSettingsDialog() +{ + delete ui; +} diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.h b/src/frontend/qt_sdl/EmuSettingsDialog.h new file mode 100644 index 0000000..eb21aaa --- /dev/null +++ b/src/frontend/qt_sdl/EmuSettingsDialog.h @@ -0,0 +1,38 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef EMUSETTINGSDIALOG_H +#define EMUSETTINGSDIALOG_H + +#include + +namespace Ui { class EmuSettingsDialog; } + +class EmuSettingsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit EmuSettingsDialog(QWidget* parent); + ~EmuSettingsDialog(); + +private: + Ui::EmuSettingsDialog* ui; +}; + +#endif // EMUSETTINGSDIALOG_H diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.ui b/src/frontend/qt_sdl/EmuSettingsDialog.ui new file mode 100644 index 0000000..e4deaba --- /dev/null +++ b/src/frontend/qt_sdl/EmuSettingsDialog.ui @@ -0,0 +1,201 @@ + + + EmuSettingsDialog + + + + 0 + 0 + 490 + 243 + + + + + 0 + 0 + + + + Emu settings - melonDS + + + + QLayout::SetFixedSize + + + + + DS mode + + + + + + + 0 + 0 + + + + + 290 + 0 + + + + + + + <html><head/><body><p>DS-mode ARM9 BIOS</p><p>Size should be 4 KB</p></body></html> + + + + + + + DS firmware: + + + + + + + DS ARM7 BIOS: + + + + + + + DS ARM9 BIOS: + + + + + + + + 0 + 0 + + + + Browse... + + + true + + + + + + + <html><head/><body><p>DS-mode ARM7 BIOS</p><p>Size should be 16 KB</p></body></html> + + + + + + + Browse... + + + + + + + <html><head/><body><p>DS-mode firmware</p><p><br/></p><p>Possible firmwares:</p><p>* 128 KB: DS-mode firmware from a DSi or 3DS. Not bootable.</p><p>* 256 KB: regular DS firmware.</p><p>* 512 KB: iQue DS firmware.</p></body></html> + + + + + + + Browse... + + + + + + + + + + Startup + + + + + + <html><head/><body><p>When loading a ROM, completely skip the regular boot process (&quot;Nintendo DS&quot; screen) to boot the ROM directly.</p><p><br/></p><p>Note: if your firmware dump isn't bootable, the ROM will be booted directly regardless of this setting.</p></body></html> + + + Boot game directly + + + + + + + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + EmuSettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + EmuSettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 11602a6..3986876 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -31,6 +31,7 @@ #include #include "main.h" +#include "EmuSettingsDialog.h" #include "types.h" #include "version.h" @@ -545,6 +546,12 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) actStop = menu->addAction("Stop"); connect(actStop, &QAction::triggered, this, &MainWindow::onStop); } + { + QMenu* menu = menubar->addMenu("Config"); + + actEmuSettings = menu->addAction("Emu settings"); + connect(actEmuSettings, &QAction::triggered, this, &MainWindow::onOpenEmuSettings); + } setMenuBar(menubar); panel = new MainWindowPanel(this); @@ -811,6 +818,14 @@ void MainWindow::onEmuUnpause() } +void MainWindow::onOpenEmuSettings() +{ + // TODO keep track of this pointer!! + EmuSettingsDialog* dlg = new EmuSettingsDialog(this); + dlg->show(); +} + + int main(int argc, char** argv) { srand(time(NULL)); diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index f8ad9a3..bb5e903 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -107,6 +107,8 @@ private slots: void onEmuPause(); void onEmuUnpause(); + void onOpenEmuSettings(); + private: MainWindowPanel* panel; @@ -120,6 +122,8 @@ private: QAction* actPause; QAction* actReset; QAction* actStop; + + QAction* actEmuSettings; }; #endif // MAIN_H -- cgit v1.2.3 From 492a4b4b464b4b48bd821c126475c791e66b5c6d Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 17 May 2020 03:02:42 +0200 Subject: add config entries for BIOS/firmware paths --- src/frontend/qt_sdl/PlatformConfig.cpp | 16 ++++++++++++---- src/frontend/qt_sdl/PlatformConfig.h | 8 ++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/PlatformConfig.cpp b/src/frontend/qt_sdl/PlatformConfig.cpp index f78b195..fba649c 100644 --- a/src/frontend/qt_sdl/PlatformConfig.cpp +++ b/src/frontend/qt_sdl/PlatformConfig.cpp @@ -60,9 +60,13 @@ int SavestateRelocSRAM; int AudioVolume; int MicInputType; -char MicWavPath[512]; +char MicWavPath[1024]; -char LastROMFolder[512]; +char LastROMFolder[1024]; + +char BIOS9Path[1024]; +char BIOS7Path[1024]; +char FirmwarePath[1024]; ConfigEntry PlatformConfigFile[] = @@ -141,9 +145,13 @@ ConfigEntry PlatformConfigFile[] = {"AudioVolume", 0, &AudioVolume, 256, NULL, 0}, {"MicInputType", 0, &MicInputType, 1, NULL, 0}, - {"MicWavPath", 1, MicWavPath, 0, "", 511}, + {"MicWavPath", 1, MicWavPath, 0, "", 1023}, + + {"LastROMFolder", 1, LastROMFolder, 0, "", 1023}, - {"LastROMFolder", 1, LastROMFolder, 0, "", 511}, + {"BIOS9Path", 1, BIOS9Path, 0, "", 1023}, + {"BIOS7Path", 1, BIOS7Path, 0, "", 1023}, + {"FirmwarePath", 1, FirmwarePath, 0, "", 1023}, {"", -1, NULL, 0, NULL, 0} }; diff --git a/src/frontend/qt_sdl/PlatformConfig.h b/src/frontend/qt_sdl/PlatformConfig.h index d0f765b..e104015 100644 --- a/src/frontend/qt_sdl/PlatformConfig.h +++ b/src/frontend/qt_sdl/PlatformConfig.h @@ -73,9 +73,13 @@ extern int SavestateRelocSRAM; extern int AudioVolume; extern int MicInputType; -extern char MicWavPath[512]; +extern char MicWavPath[1024]; -extern char LastROMFolder[512]; +extern char LastROMFolder[1024]; + +extern char BIOS9Path[1024]; +extern char BIOS7Path[1024]; +extern char FirmwarePath[1024]; } -- cgit v1.2.3 From 60ba163f08e0af4272c8de6141583238eb283fe8 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 17 May 2020 04:02:16 +0200 Subject: take this somewhere --- src/frontend/qt_sdl/EmuSettingsDialog.cpp | 70 +++++++++++++++++++++++++++++++ src/frontend/qt_sdl/EmuSettingsDialog.h | 26 ++++++++++++ src/frontend/qt_sdl/main.cpp | 4 +- 3 files changed, 97 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.cpp b/src/frontend/qt_sdl/EmuSettingsDialog.cpp index c64f192..34cafb5 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.cpp +++ b/src/frontend/qt_sdl/EmuSettingsDialog.cpp @@ -16,16 +16,86 @@ with melonDS. If not, see http://www.gnu.org/licenses/. */ +#include + +#include "types.h" +#include "Config.h" +#include "PlatformConfig.h" + #include "EmuSettingsDialog.h" #include "ui_EmuSettingsDialog.h" +EmuSettingsDialog* EmuSettingsDialog::currentDlg = nullptr; + +extern char* EmuDirectory; + + EmuSettingsDialog::EmuSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::EmuSettingsDialog) { ui->setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + + ui->txtBIOS9Path->setText(Config::BIOS9Path); + ui->txtBIOS7Path->setText(Config::BIOS7Path); + ui->txtFirmwarePath->setText(Config::FirmwarePath); + ui->chkDirectBoot->setChecked(Config::DirectBoot != 0); } EmuSettingsDialog::~EmuSettingsDialog() { delete ui; } + +void EmuSettingsDialog::on_EmuSettingsDialog_accepted() +{ + strncpy(Config::BIOS9Path, ui->txtBIOS9Path->text().toStdString().c_str(), 1023); Config::BIOS9Path[1023] = '\0'; + strncpy(Config::BIOS7Path, ui->txtBIOS7Path->text().toStdString().c_str(), 1023); Config::BIOS7Path[1023] = '\0'; + strncpy(Config::FirmwarePath, ui->txtFirmwarePath->text().toStdString().c_str(), 1023); Config::FirmwarePath[1023] = '\0'; + Config::DirectBoot = ui->chkDirectBoot->isChecked() ? 1:0; + + closeDlg(); +} + +void EmuSettingsDialog::on_EmuSettingsDialog_rejected() +{ + closeDlg(); +} + +void EmuSettingsDialog::on_btnBIOS9Browse_clicked() +{ + QString file = QFileDialog::getOpenFileName(this, + "Select DS-mode ARM9 BIOS...", + EmuDirectory, + "BIOS files (*.bin *.rom);;Any file (*.*)"); + + if (file.isEmpty()) return; + + ui->txtBIOS9Path->setText(file); +} + +void EmuSettingsDialog::on_btnBIOS7Browse_clicked() +{ + QString file = QFileDialog::getOpenFileName(this, + "Select DS-mode ARM7 BIOS...", + EmuDirectory, + "BIOS files (*.bin *.rom);;Any file (*.*)"); + + if (file.isEmpty()) return; + + ui->txtBIOS7Path->setText(file); +} + +void EmuSettingsDialog::on_btnFirmwareBrowse_clicked() +{ + QString file = QFileDialog::getOpenFileName(this, + "Select DS-mode firmware...", + EmuDirectory, + "Firmware files (*.bin *.rom);;Any file (*.*)"); + + if (file.isEmpty()) return; + + // TODO: check for shitty hacked firmware here? + + ui->txtFirmwarePath->setText(file); +} diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.h b/src/frontend/qt_sdl/EmuSettingsDialog.h index eb21aaa..471e0fb 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.h +++ b/src/frontend/qt_sdl/EmuSettingsDialog.h @@ -22,6 +22,7 @@ #include namespace Ui { class EmuSettingsDialog; } +class EmuSettingsDialog; class EmuSettingsDialog : public QDialog { @@ -31,6 +32,31 @@ public: explicit EmuSettingsDialog(QWidget* parent); ~EmuSettingsDialog(); + static EmuSettingsDialog* currentDlg; + static void openDlg(QWidget* parent) + { + if (currentDlg) + { + currentDlg->activateWindow(); + return; + } + + currentDlg = new EmuSettingsDialog(parent); + currentDlg->show(); + } + static void closeDlg() + { + currentDlg = nullptr; + } + +private slots: + void on_EmuSettingsDialog_accepted(); + void on_EmuSettingsDialog_rejected(); + + void on_btnBIOS9Browse_clicked(); + void on_btnBIOS7Browse_clicked(); + void on_btnFirmwareBrowse_clicked(); + private: Ui::EmuSettingsDialog* ui; }; diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 3986876..8b97320 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -820,9 +820,7 @@ void MainWindow::onEmuUnpause() void MainWindow::onOpenEmuSettings() { - // TODO keep track of this pointer!! - EmuSettingsDialog* dlg = new EmuSettingsDialog(this); - dlg->show(); + EmuSettingsDialog::openDlg(this); } -- cgit v1.2.3 From 17d30e91f01ea015caf5e28afe8ddca4aede45b1 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 17 May 2020 04:37:44 +0200 Subject: actually hook this up --- src/Config.cpp | 8 +++++ src/Config.h | 4 +++ src/NDS.cpp | 4 +-- src/SPI.cpp | 16 +++++++--- src/frontend/qt_sdl/EmuSettingsDialog.cpp | 49 +++++++++++++++++++++++++++++-- src/frontend/qt_sdl/EmuSettingsDialog.h | 2 ++ src/frontend/qt_sdl/PlatformConfig.cpp | 8 ----- src/frontend/qt_sdl/PlatformConfig.h | 4 --- 8 files changed, 75 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/Config.cpp b/src/Config.cpp index f558ef6..7604785 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -28,6 +28,10 @@ namespace Config const char* kConfigFile = "melonDS.ini"; +char BIOS9Path[1024]; +char BIOS7Path[1024]; +char FirmwarePath[1024]; + int _3DRenderer; int Threaded3D; @@ -36,6 +40,10 @@ int GL_Antialias; ConfigEntry ConfigFile[] = { + {"BIOS9Path", 1, BIOS9Path, 0, "", 1023}, + {"BIOS7Path", 1, BIOS7Path, 0, "", 1023}, + {"FirmwarePath", 1, FirmwarePath, 0, "", 1023}, + {"3DRenderer", 0, &_3DRenderer, 1, NULL, 0}, {"Threaded3D", 0, &Threaded3D, 1, NULL, 0}, diff --git a/src/Config.h b/src/Config.h index 0aeab85..05b9b8b 100644 --- a/src/Config.h +++ b/src/Config.h @@ -42,6 +42,10 @@ bool HasConfigFile(const char* fileName); void Load(); void Save(); +extern char BIOS9Path[1024]; +extern char BIOS7Path[1024]; +extern char FirmwarePath[1024]; + extern int _3DRenderer; extern int Threaded3D; diff --git a/src/NDS.cpp b/src/NDS.cpp index a2ab6ce..1d425a8 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -416,7 +416,7 @@ void Reset() RunningGame = false; LastSysClockCycles = 0; - f = Platform::OpenLocalFile("bios9.bin", "rb"); + f = Platform::OpenLocalFile(Config::BIOS9Path, "rb"); if (!f) { printf("ARM9 BIOS not found\n"); @@ -433,7 +433,7 @@ void Reset() fclose(f); } - f = Platform::OpenLocalFile("bios7.bin", "rb"); + f = Platform::OpenLocalFile(Config::BIOS7Path, "rb"); if (!f) { printf("ARM7 BIOS not found\n"); diff --git a/src/SPI.cpp b/src/SPI.cpp index 1a5873e..056e8d5 100644 --- a/src/SPI.cpp +++ b/src/SPI.cpp @@ -28,6 +28,7 @@ namespace SPI_Firmware { +char FirmwarePath[1024]; u8* Firmware; u32 FirmwareLength; u32 FirmwareMask; @@ -76,6 +77,7 @@ bool VerifyCRC16(u32 start, u32 offset, u32 len, u32 crcoffset) bool Init() { + memset(FirmwarePath, 0, sizeof(FirmwarePath)); Firmware = NULL; return true; } @@ -90,10 +92,12 @@ void Reset() if (Firmware) delete[] Firmware; Firmware = NULL; - FILE* f = Platform::OpenLocalFile("firmware.bin", "rb"); + strncpy(FirmwarePath, Config::FirmwarePath, 1023); + + FILE* f = Platform::OpenLocalFile(FirmwarePath, "rb"); if (!f) { - printf("firmware.bin not found\n"); + printf("Firmware not found\n"); // TODO: generate default firmware return; @@ -129,7 +133,11 @@ void Reset() fclose(f); // take a backup - const char* firmbkp = "firmware.bin.bak"; + char firmbkp[1028]; + int fplen = strlen(FirmwarePath); + strncpy(&firmbkp[0], FirmwarePath, fplen); + strncpy(&firmbkp[fplen], ".bak", 1028-fplen); + firmbkp[fplen+4] = '\0'; f = Platform::OpenLocalFile(firmbkp, "rb"); if (f) fclose(f); else @@ -325,7 +333,7 @@ void Write(u8 val, u32 hold) if (!hold && (CurCmd == 0x02 || CurCmd == 0x0A)) { - FILE* f = Platform::OpenLocalFile("firmware.bin", "r+b"); + FILE* f = Platform::OpenLocalFile(FirmwarePath, "r+b"); if (f) { u32 cutoff = 0x7FA00 & FirmwareMask; diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.cpp b/src/frontend/qt_sdl/EmuSettingsDialog.cpp index 34cafb5..bce5513 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.cpp +++ b/src/frontend/qt_sdl/EmuSettingsDialog.cpp @@ -16,9 +16,12 @@ with melonDS. If not, see http://www.gnu.org/licenses/. */ +#include #include +#include #include "types.h" +#include "Platform.h" #include "Config.h" #include "PlatformConfig.h" @@ -47,8 +50,52 @@ EmuSettingsDialog::~EmuSettingsDialog() delete ui; } +void EmuSettingsDialog::verifyFirmware() +{ + // verify the firmware + // + // there are dumps of an old hacked firmware floating around on the internet + // and those are problematic + // the hack predates WFC, and, due to this, any game that alters the WFC + // access point data will brick that firmware due to it having critical + // data in the same area. it has the same problem on hardware. + // + // but this should help stop users from reporting that issue over and over + // again, when the issue is not from melonDS but from their firmware dump. + // + // I don't know about all the firmware hacks in existence, but the one I + // looked at has 0x180 bytes from the header repeated at 0x3FC80, but + // bytes 0x0C-0x14 are different. + + char filename[1024]; + strncpy(filename, ui->txtFirmwarePath->text().toStdString().c_str(), 1023); filename[1023] = '\0'; + FILE* f = Platform::OpenLocalFile(filename, "rb"); + u8 chk1[0x180], chk2[0x180]; + + fseek(f, 0, SEEK_SET); + fread(chk1, 1, 0x180, f); + fseek(f, -0x380, SEEK_END); + fread(chk2, 1, 0x180, f); + + memset(&chk1[0x0C], 0, 8); + memset(&chk2[0x0C], 0, 8); + + fclose(f); + + if (!memcmp(chk1, chk2, 0x180)) + { + QMessageBox::warning(this, + "Problematic firmware dump", + "You are using an old hacked firmware dump.\n" + "Firmware boot will stop working if you run any game that alters WFC settings.\n\n" + "Note that the issue is not from melonDS, it would also happen on an actual DS."); + } +} + void EmuSettingsDialog::on_EmuSettingsDialog_accepted() { + verifyFirmware(); + strncpy(Config::BIOS9Path, ui->txtBIOS9Path->text().toStdString().c_str(), 1023); Config::BIOS9Path[1023] = '\0'; strncpy(Config::BIOS7Path, ui->txtBIOS7Path->text().toStdString().c_str(), 1023); Config::BIOS7Path[1023] = '\0'; strncpy(Config::FirmwarePath, ui->txtFirmwarePath->text().toStdString().c_str(), 1023); Config::FirmwarePath[1023] = '\0'; @@ -95,7 +142,5 @@ void EmuSettingsDialog::on_btnFirmwareBrowse_clicked() if (file.isEmpty()) return; - // TODO: check for shitty hacked firmware here? - ui->txtFirmwarePath->setText(file); } diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.h b/src/frontend/qt_sdl/EmuSettingsDialog.h index 471e0fb..ce64145 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.h +++ b/src/frontend/qt_sdl/EmuSettingsDialog.h @@ -58,6 +58,8 @@ private slots: void on_btnFirmwareBrowse_clicked(); private: + void verifyFirmware(); + Ui::EmuSettingsDialog* ui; }; diff --git a/src/frontend/qt_sdl/PlatformConfig.cpp b/src/frontend/qt_sdl/PlatformConfig.cpp index fba649c..1f6a873 100644 --- a/src/frontend/qt_sdl/PlatformConfig.cpp +++ b/src/frontend/qt_sdl/PlatformConfig.cpp @@ -64,10 +64,6 @@ char MicWavPath[1024]; char LastROMFolder[1024]; -char BIOS9Path[1024]; -char BIOS7Path[1024]; -char FirmwarePath[1024]; - ConfigEntry PlatformConfigFile[] = { @@ -149,10 +145,6 @@ ConfigEntry PlatformConfigFile[] = {"LastROMFolder", 1, LastROMFolder, 0, "", 1023}, - {"BIOS9Path", 1, BIOS9Path, 0, "", 1023}, - {"BIOS7Path", 1, BIOS7Path, 0, "", 1023}, - {"FirmwarePath", 1, FirmwarePath, 0, "", 1023}, - {"", -1, NULL, 0, NULL, 0} }; diff --git a/src/frontend/qt_sdl/PlatformConfig.h b/src/frontend/qt_sdl/PlatformConfig.h index e104015..3704d14 100644 --- a/src/frontend/qt_sdl/PlatformConfig.h +++ b/src/frontend/qt_sdl/PlatformConfig.h @@ -77,10 +77,6 @@ extern char MicWavPath[1024]; extern char LastROMFolder[1024]; -extern char BIOS9Path[1024]; -extern char BIOS7Path[1024]; -extern char FirmwarePath[1024]; - } #endif // PLATFORMCONFIG_H -- cgit v1.2.3 From 49b24ea2b3b730b2d4acb20231989d1ace84a59b Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 17 May 2020 04:42:15 +0200 Subject: this might be betterer --- src/frontend/qt_sdl/EmuSettingsDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.cpp b/src/frontend/qt_sdl/EmuSettingsDialog.cpp index bce5513..6264d91 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.cpp +++ b/src/frontend/qt_sdl/EmuSettingsDialog.cpp @@ -84,7 +84,7 @@ void EmuSettingsDialog::verifyFirmware() if (!memcmp(chk1, chk2, 0x180)) { - QMessageBox::warning(this, + QMessageBox::warning((QWidget*)this->parent(), "Problematic firmware dump", "You are using an old hacked firmware dump.\n" "Firmware boot will stop working if you run any game that alters WFC settings.\n\n" -- cgit v1.2.3 From c5c9434ac9abaa0ae9c3125ee6e8bc4653846ebd Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 17 May 2020 05:42:09 +0200 Subject: verify BIOS and firmware before booting games/firmware --- src/NDS.cpp | 2 +- src/frontend/FrontendUtil.h | 22 +++++++++- src/frontend/Util_ROM.cpp | 100 +++++++++++++++++++++++++++++++++++++++---- src/frontend/qt_sdl/main.cpp | 41 +++++++++++++++--- src/frontend/qt_sdl/main.h | 2 + 5 files changed, 149 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/NDS.cpp b/src/NDS.cpp index 1d425a8..745ed28 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -587,7 +587,7 @@ bool DoSavestate_Scheduler(Savestate* file) } if (funcid == -1) { - printf("savestate: VERY BAD!!!!! FUNCTION POINTER FOR EVENT %d NOT IN HACKY LIST. CANNOT SAVE. SMACK STAPLEBUTTER.\n", i); + printf("savestate: VERY BAD!!!!! FUNCTION POINTER FOR EVENT %d NOT IN HACKY LIST. CANNOT SAVE. SMACK ARISOTURA.\n", i); return false; } } diff --git a/src/frontend/FrontendUtil.h b/src/frontend/FrontendUtil.h index 32f28d1..f4f6850 100644 --- a/src/frontend/FrontendUtil.h +++ b/src/frontend/FrontendUtil.h @@ -32,6 +32,24 @@ enum ROMSlot_MAX }; +enum +{ + Load_OK = 0, + + Load_BIOS9Missing, + Load_BIOS9Bad, + + Load_BIOS7Missing, + Load_BIOS7Bad, + + Load_FirmwareMissing, + Load_FirmwareBad, + Load_FirmwareNotBootable, + + // TODO: more precise errors for ROM loading + Load_ROMLoadError, +}; + extern char ROMPath [ROMSlot_MAX][1024]; extern char SRAMPath[ROMSlot_MAX][1024]; extern bool SavestateLoaded; @@ -41,11 +59,11 @@ extern bool SavestateLoaded; void Init_ROM(); // load the BIOS/firmware and boot from it -bool LoadBIOS(); +int LoadBIOS(); // load a ROM file to the specified cart slot // note: loading a ROM to the NDS slot resets emulation -bool LoadROM(const char* file, int slot); +int LoadROM(const char* file, int slot); // get the filename associated with the given savestate slot (1-8) void GetSavestateName(int slot, char* filename, int len); diff --git a/src/frontend/Util_ROM.cpp b/src/frontend/Util_ROM.cpp index 19c8eb9..3200de4 100644 --- a/src/frontend/Util_ROM.cpp +++ b/src/frontend/Util_ROM.cpp @@ -57,8 +57,77 @@ void SetupSRAMPath(int slot) strncpy(SRAMPath[slot] + strlen(ROMPath[slot]) - 3, "sav", 3); } -bool LoadBIOS() +int VerifyDSBIOS() { + FILE* f; + long len; + + f = Platform::OpenLocalFile(Config::BIOS9Path, "rb"); + if (!f) return Load_BIOS9Missing; + + fseek(f, 0, SEEK_END); + len = ftell(f); + if (len != 0x1000) + { + fclose(f); + return Load_BIOS9Bad; + } + + fclose(f); + + f = Platform::OpenLocalFile(Config::BIOS7Path, "rb"); + if (!f) return Load_BIOS7Missing; + + fseek(f, 0, SEEK_END); + len = ftell(f); + if (len != 0x4000) + { + fclose(f); + return Load_BIOS7Bad; + } + + fclose(f); + + return Load_OK; +} + +int VerifyDSFirmware() +{ + FILE* f; + long len; + + f = Platform::OpenLocalFile(Config::FirmwarePath, "rb"); + if (!f) return Load_FirmwareMissing; + + fseek(f, 0, SEEK_END); + len = ftell(f); + if (len == 0x20000) + { + // 128KB firmware, not bootable + fclose(f); + return Load_FirmwareNotBootable; + } + else if (len != 0x40000 && len != 0x80000) + { + fclose(f); + return Load_FirmwareBad; + } + + fclose(f); + + return Load_OK; +} + +int LoadBIOS() +{ + int res; + + res = VerifyDSBIOS(); + if (res != Load_OK) return res; + + res = VerifyDSFirmware(); + if (res != Load_OK) return res; + // TODO: // original code in the libui frontend called NDS::LoadGBAROM() if needed // should this be carried over here? @@ -71,12 +140,26 @@ bool LoadBIOS() SavestateLoaded = false; - // TODO: error reporting? - return true; + return Load_OK; } -bool LoadROM(const char* file, int slot) +int LoadROM(const char* file, int slot) { + int res; + bool directboot = Config::DirectBoot != 0; + + res = VerifyDSBIOS(); + if (res != Load_OK) return res; + + res = VerifyDSFirmware(); + if (res != Load_OK) + { + if (res == Load_FirmwareNotBootable) + directboot = true; + else + return res; + } + char oldpath[1024]; char oldsram[1024]; strncpy(oldpath, ROMPath[slot], 1024); @@ -88,28 +171,29 @@ bool LoadROM(const char* file, int slot) SetupSRAMPath(0); SetupSRAMPath(1); - if (slot == ROMSlot_NDS && NDS::LoadROM(ROMPath[slot], SRAMPath[slot], Config::DirectBoot)) + if (slot == ROMSlot_NDS && NDS::LoadROM(ROMPath[slot], SRAMPath[slot], directboot)) { SavestateLoaded = false; // Reload the inserted GBA cartridge (if any) + // TODO: report failure there?? if (ROMPath[ROMSlot_GBA][0] != '\0') NDS::LoadGBAROM(ROMPath[ROMSlot_GBA], SRAMPath[ROMSlot_GBA]); strncpy(PrevSRAMPath[slot], SRAMPath[slot], 1024); // safety - return true; + return Load_OK; } else if (slot == ROMSlot_GBA && NDS::LoadGBAROM(ROMPath[slot], SRAMPath[slot])) { SavestateLoaded = false; strncpy(PrevSRAMPath[slot], SRAMPath[slot], 1024); // safety - return true; + return Load_OK; } else { strncpy(ROMPath[slot], oldpath, 1024); strncpy(SRAMPath[slot], oldsram, 1024); - return false; + return Load_ROMLoadError; } } diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 8b97320..ec4b04b 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -570,6 +570,27 @@ void MainWindow::keyPressEvent(QKeyEvent* event) } +QString MainWindow::loadErrorStr(int error) +{ + switch (error) + { + case Frontend::Load_BIOS9Missing: return "DS ARM9 BIOS was not found or could not be accessed."; + case Frontend::Load_BIOS9Bad: return "DS ARM9 BIOS is not a valid BIOS dump."; + + case Frontend::Load_BIOS7Missing: return "DS ARM7 BIOS was not found or could not be accessed."; + case Frontend::Load_BIOS7Bad: return "DS ARM7 BIOS is not a valid BIOS dump."; + + case Frontend::Load_FirmwareMissing: return "DS firmware was not found or could not be accessed."; + case Frontend::Load_FirmwareBad: return "DS firmware is not a valid firmware dump."; + case Frontend::Load_FirmwareNotBootable: return "DS firmware is not bootable."; + + case Frontend::Load_ROMLoadError: return "Failed to load the ROM. Make sure the file is accessible and isn't used by another application."; + + default: return "Unknown error during launch; smack Arisotura."; + } +} + + void MainWindow::onOpenFile() { emuThread->emuPause(true); @@ -584,6 +605,11 @@ void MainWindow::onOpenFile() return; } + // TODO: validate the input file!! + // * check that it is a proper ROM + // * ensure the binary offsets are sane + // * etc + // this shit is stupid char file[1024]; strncpy(file, filename.toStdString().c_str(), 1023); file[1023] = '\0'; @@ -594,7 +620,7 @@ void MainWindow::onOpenFile() Config::LastROMFolder[pos] = '\0'; char* ext = &file[strlen(file)-3]; - int slot; bool res; + int slot; int res; if (!strcasecmp(ext, "gba")) { slot = 1; @@ -606,11 +632,11 @@ void MainWindow::onOpenFile() res = Frontend::LoadROM(file, Frontend::ROMSlot_NDS); } - if (!res) + if (res != Frontend::Load_OK) { QMessageBox::critical(this, "melonDS", - "Failed to load the ROM.\n\nMake sure the file is accessible and isn't used by another application."); + loadErrorStr(res)); emuThread->emuUnpause(); } else if (slot == 1) @@ -631,11 +657,12 @@ void MainWindow::onBootFirmware() emuThread->emuPause(true); - bool res = Frontend::LoadBIOS(); - if (!res) + int res = Frontend::LoadBIOS(); + if (res != Frontend::Load_OK) { - // TODO! - + QMessageBox::critical(this, + "melonDS", + loadErrorStr(res)); emuThread->emuUnpause(); } else diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index bb5e903..ee0094f 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -110,6 +110,8 @@ private slots: void onOpenEmuSettings(); private: + QString loadErrorStr(int error); + MainWindowPanel* panel; QAction* actOpenROM; -- cgit v1.2.3 From 0566c9e34c36f7f1841765b02147fd4c890e8550 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 17 May 2020 13:04:02 +0200 Subject: minor fix --- src/NDSCart.cpp | 5 +++ src/frontend/qt_sdl/Platform.cpp | 2 +- src/frontend/qt_sdl/main.cpp | 68 +--------------------------------------- 3 files changed, 7 insertions(+), 68 deletions(-) (limited to 'src') diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index 5a2a0d0..585eadf 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -867,6 +867,11 @@ bool ReadROMParams(u32 gamecode, u32* params) void DecryptSecureArea(u8* out) { + // TODO: source decryption data from different possible sources + // * original DS-mode ARM7 BIOS has the key data at 0x30 + // * .srl ROMs (VC dumps) have encrypted secure areas but have precomputed + // decryption data at 0x1000 (and at the beginning of the DSi region if any) + u32 gamecode = *(u32*)&CartROM[0x0C]; u32 arm9base = *(u32*)&CartROM[0x20]; diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index 31b5277..fea9166 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -202,7 +202,7 @@ FILE* OpenLocalFile(const char* path, const char* mode) #ifdef __WIN32__ if (pathlen > 3) { - if (path[1] == ':' && path[2] == '\\') + if (path[1] == ':' && (path[2] == '\\' || path[2] == '/')) return OpenFile(path, mode); } #else diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index ec4b04b..67eb3d8 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -915,74 +915,8 @@ int main(int argc, char** argv) //if (Config::AudioVolume < 0) Config::AudioVolume = 0; //else if (Config::AudioVolume > 256) Config::AudioVolume = 256; - // TODO: those should be checked before running anything - // (as to let the user specify their own BIOS/firmware path etc) + // TODO: this should be checked before running anything #if 0 - if (!Platform::LocalFileExists("bios7.bin") || - !Platform::LocalFileExists("bios9.bin") || - !Platform::LocalFileExists("firmware.bin")) - { -#if defined(__WIN32__) || defined(UNIX_PORTABLE) - const char* locationName = "the directory you run melonDS from"; -#else - char* locationName = EmuDirectory; -#endif - char msgboxtext[512]; - sprintf(msgboxtext, - "One or more of the following required files don't exist or couldn't be accessed:\n\n" - "bios7.bin -- ARM7 BIOS\n" - "bios9.bin -- ARM9 BIOS\n" - "firmware.bin -- firmware image\n\n" - "Dump the files from your DS and place them in %s.\n" - "Make sure that the files can be accessed.", - locationName - ); - - uiMsgBoxError(NULL, "BIOS/Firmware not found", msgboxtext); - - uiUninit(); - SDL_Quit(); - return 0; - } - if (!Platform::LocalFileExists("firmware.bin.bak")) - { - // verify the firmware - // - // there are dumps of an old hacked firmware floating around on the internet - // and those are problematic - // the hack predates WFC, and, due to this, any game that alters the WFC - // access point data will brick that firmware due to it having critical - // data in the same area. it has the same problem on hardware. - // - // but this should help stop users from reporting that issue over and over - // again, when the issue is not from melonDS but from their firmware dump. - // - // I don't know about all the firmware hacks in existence, but the one I - // looked at has 0x180 bytes from the header repeated at 0x3FC80, but - // bytes 0x0C-0x14 are different. - - FILE* f = Platform::OpenLocalFile("firmware.bin", "rb"); - u8 chk1[0x180], chk2[0x180]; - - fseek(f, 0, SEEK_SET); - fread(chk1, 1, 0x180, f); - fseek(f, -0x380, SEEK_END); - fread(chk2, 1, 0x180, f); - - memset(&chk1[0x0C], 0, 8); - memset(&chk2[0x0C], 0, 8); - - fclose(f); - - if (!memcmp(chk1, chk2, 0x180)) - { - uiMsgBoxError(NULL, - "Problematic firmware dump", - "You are using an old hacked firmware dump.\n" - "Firmware boot will stop working if you run any game that alters WFC settings.\n\n" - "Note that the issue is not from melonDS, it would also happen on an actual DS."); - } - } { const char* romlist_missing = "Save memory type detection will not work correctly.\n\n" "You should use the latest version of romlist.bin (provided in melonDS release packages)."; -- cgit v1.2.3 From c9a76edf210410dbf95d100690bad9c86aa5bd84 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 17 May 2020 14:23:06 +0200 Subject: probably fix some pretty bad issue good one, Generic --- src/frontend/qt_sdl/main.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 67eb3d8..a7388a0 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -888,9 +888,12 @@ int main(int argc, char** argv) #else const char* confdir = g_get_user_config_dir(); const char* confname = "/melonDS"; - EmuDirectory = new char[strlen(confdir) + strlen(confname) + 1]; - strcat(EmuDirectory, confdir); - strcat(EmuDirectory, confname); + int cdlen = strlen(confdir); + int cnlen = strlen(confname); + EmuDirectory = new char[cdlen + cnlen + 1]; + strncpy(&EmuDirectory[0], confdir, cdlen); + strncpy(&EmuDirectory[cdlen], confname, cnlen); + EmuDirectory[cdlen+cnlen] = '\0'; #endif QApplication melon(argc, argv); -- cgit v1.2.3 From 19566178ba7ee1fcd4207139286707cc3896493a Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 17 May 2020 18:33:03 +0200 Subject: begin adding input dialog --- src/frontend/qt_sdl/CMakeLists.txt | 1 + src/frontend/qt_sdl/EmuSettingsDialog.h | 5 +- src/frontend/qt_sdl/InputConfigDialog.cpp | 53 +++++++++++++ src/frontend/qt_sdl/InputConfigDialog.h | 63 +++++++++++++++ src/frontend/qt_sdl/InputConfigDialog.ui | 126 ++++++++++++++++++++++++++++++ src/frontend/qt_sdl/main.cpp | 21 ++++- src/frontend/qt_sdl/main.h | 3 + 7 files changed, 268 insertions(+), 4 deletions(-) create mode 100644 src/frontend/qt_sdl/InputConfigDialog.cpp create mode 100644 src/frontend/qt_sdl/InputConfigDialog.h create mode 100644 src/frontend/qt_sdl/InputConfigDialog.ui (limited to 'src') diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index a6aeb0e..da3bb1d 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -3,6 +3,7 @@ project(qt_sdl) SET(SOURCES_QT_SDL main.cpp EmuSettingsDialog.cpp + InputConfigDialog.cpp Platform.cpp PlatformConfig.cpp diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.h b/src/frontend/qt_sdl/EmuSettingsDialog.h index ce64145..7378641 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.h +++ b/src/frontend/qt_sdl/EmuSettingsDialog.h @@ -33,16 +33,17 @@ public: ~EmuSettingsDialog(); static EmuSettingsDialog* currentDlg; - static void openDlg(QWidget* parent) + static EmuSettingsDialog* openDlg(QWidget* parent) { if (currentDlg) { currentDlg->activateWindow(); - return; + return currentDlg; } currentDlg = new EmuSettingsDialog(parent); currentDlg->show(); + return currentDlg; } static void closeDlg() { diff --git a/src/frontend/qt_sdl/InputConfigDialog.cpp b/src/frontend/qt_sdl/InputConfigDialog.cpp new file mode 100644 index 0000000..f7c0ab2 --- /dev/null +++ b/src/frontend/qt_sdl/InputConfigDialog.cpp @@ -0,0 +1,53 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +// + +#include "types.h" +#include "Config.h" +#include "PlatformConfig.h" + +#include "InputConfigDialog.h" +#include "ui_InputConfigDialog.h" + + +InputConfigDialog* InputConfigDialog::currentDlg = nullptr; + + +InputConfigDialog::InputConfigDialog(QWidget* parent) : QDialog(parent), ui(new Ui::InputConfigDialog) +{ + ui->setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + + // +} + +InputConfigDialog::~InputConfigDialog() +{ + delete ui; +} + +void InputConfigDialog::on_InputConfigDialog_accepted() +{ + closeDlg(); +} + +void InputConfigDialog::on_InputConfigDialog_rejected() +{ + closeDlg(); +} diff --git a/src/frontend/qt_sdl/InputConfigDialog.h b/src/frontend/qt_sdl/InputConfigDialog.h new file mode 100644 index 0000000..2af73db --- /dev/null +++ b/src/frontend/qt_sdl/InputConfigDialog.h @@ -0,0 +1,63 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef INPUTCONFIGDIALOG_H +#define INPUTCONFIGDIALOG_H + +#include + +namespace Ui { class InputConfigDialog; } +class InputConfigDialog; + +class InputConfigDialog : public QDialog +{ + Q_OBJECT + +public: + explicit InputConfigDialog(QWidget* parent); + ~InputConfigDialog(); + + static InputConfigDialog* currentDlg; + static InputConfigDialog* openDlg(QWidget* parent) + { + if (currentDlg) + { + currentDlg->activateWindow(); + return currentDlg; + } + + currentDlg = new InputConfigDialog(parent); + currentDlg->open(); + return currentDlg; + } + static void closeDlg() + { + currentDlg = nullptr; + } + +private slots: + void on_InputConfigDialog_accepted(); + void on_InputConfigDialog_rejected(); + + // + +private: + Ui::InputConfigDialog* ui; +}; + +#endif // INPUTCONFIGDIALOG_H diff --git a/src/frontend/qt_sdl/InputConfigDialog.ui b/src/frontend/qt_sdl/InputConfigDialog.ui new file mode 100644 index 0000000..c1422e9 --- /dev/null +++ b/src/frontend/qt_sdl/InputConfigDialog.ui @@ -0,0 +1,126 @@ + + + InputConfigDialog + + + + 0 + 0 + 488 + 365 + + + + TDAH + + + + QLayout::SetFixedSize + + + + + 1 + + + + DS input + + + + + General hotkeys + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + Joystick: + + + + + + + + 0 + 0 + + + + <html><head/><body><p>Selects which joystick will be used for joystick input, if any is present.</p></body></html> + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + InputConfigDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + InputConfigDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index a7388a0..cd7849d 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -32,6 +32,7 @@ #include "main.h" #include "EmuSettingsDialog.h" +#include "InputConfigDialog.h" #include "types.h" #include "version.h" @@ -551,6 +552,9 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) actEmuSettings = menu->addAction("Emu settings"); connect(actEmuSettings, &QAction::triggered, this, &MainWindow::onOpenEmuSettings); + + actInputConfig = menu->addAction("Input and hotkeys"); + connect(actInputConfig, &QAction::triggered, this, &MainWindow::onOpenInputConfig); } setMenuBar(menubar); @@ -850,6 +854,19 @@ void MainWindow::onOpenEmuSettings() EmuSettingsDialog::openDlg(this); } +void MainWindow::onOpenInputConfig() +{ + emuThread->emuPause(true); + + InputConfigDialog* dlg = InputConfigDialog::openDlg(this); + connect(dlg, &InputConfigDialog::finished, this, &MainWindow::onInputConfigFinished); +} + +void MainWindow::onInputConfigFinished() +{printf("FARTO\n"); + emuThread->emuUnpause(); +} + int main(int argc, char** argv) { @@ -915,8 +932,8 @@ int main(int argc, char** argv) Config::Load(); - //if (Config::AudioVolume < 0) Config::AudioVolume = 0; - //else if (Config::AudioVolume > 256) Config::AudioVolume = 256; + if (Config::AudioVolume < 0) Config::AudioVolume = 0; + else if (Config::AudioVolume > 256) Config::AudioVolume = 256; // TODO: this should be checked before running anything #if 0 diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index ee0094f..0324ecf 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -108,6 +108,8 @@ private slots: void onEmuUnpause(); void onOpenEmuSettings(); + void onOpenInputConfig(); + void onInputConfigFinished(); private: QString loadErrorStr(int error); @@ -126,6 +128,7 @@ private: QAction* actStop; QAction* actEmuSettings; + QAction* actInputConfig; }; #endif // MAIN_H -- cgit v1.2.3 From 7026bb15f6688d4148932a7624baf2f3d5d22d8f Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 19 May 2020 12:06:25 +0200 Subject: input dialog progress. --- src/frontend/qt_sdl/InputConfigDialog.cpp | 245 +++++++++++++++++++++++++++++- src/frontend/qt_sdl/InputConfigDialog.h | 32 ++++ src/frontend/qt_sdl/InputConfigDialog.ui | 11 +- src/frontend/qt_sdl/main.cpp | 4 +- src/frontend/qt_sdl/main.h | 2 +- 5 files changed, 286 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/InputConfigDialog.cpp b/src/frontend/qt_sdl/InputConfigDialog.cpp index f7c0ab2..3b006fd 100644 --- a/src/frontend/qt_sdl/InputConfigDialog.cpp +++ b/src/frontend/qt_sdl/InputConfigDialog.cpp @@ -16,7 +16,9 @@ with melonDS. If not, see http://www.gnu.org/licenses/. */ -// +#include +#include +#include #include "types.h" #include "Config.h" @@ -28,13 +30,68 @@ InputConfigDialog* InputConfigDialog::currentDlg = nullptr; +const int dskeyorder[12] = {0, 1, 10, 11, 5, 4, 6, 7, 9, 8, 2, 3}; +const char* dskeylabels[12] = {"A", "B", "X", "Y", "Left", "Right", "Up", "Down", "L", "R", "Select", "Start"}; + +const int hk_addons[] = +{ + HK_SolarSensorIncrease, + HK_SolarSensorDecrease, +}; + +const char* hk_addons_labels[] = +{ + "[Boktai] Sunlight + ", + "[Boktai] Sunlight - ", +}; + +const int hk_general[] = +{ + HK_Pause, + HK_Reset, + HK_FastForward, + HK_FastForwardToggle, + HK_Lid, + HK_Mic, +}; + +const char* hk_general_labels[] = +{ + "Pause/resume", + "Reset", + "Fast forward", + "Toggle FPS limit", + "Close/open lid", + "Microphone", +}; + InputConfigDialog::InputConfigDialog(QWidget* parent) : QDialog(parent), ui(new Ui::InputConfigDialog) { ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); - // + for (int i = 0; i < 12; i++) + { + keypadKeyMap[i] = Config::KeyMapping[dskeyorder[i]]; + keypadJoyMap[i] = Config::JoyMapping[dskeyorder[i]]; + } + + for (int i = 0; i < 2; i++) + { + addonsKeyMap[i] = Config::HKKeyMapping[hk_addons[i]]; + addonsJoyMap[i] = Config::HKJoyMapping[hk_addons[i]]; + } + + for (int i = 0; i < 6; i++) + { + hkGeneralKeyMap[i] = Config::HKKeyMapping[hk_general[i]]; + hkGeneralJoyMap[i] = Config::HKJoyMapping[hk_general[i]]; + } + + populatePage(ui->tabInput, 12, dskeylabels, keypadKeyMap, keypadJoyMap); + populatePage(ui->tabAddons, 2, hk_addons_labels, addonsKeyMap, addonsJoyMap); + populatePage(ui->tabHotkeysGeneral, 6, hk_general_labels, hkGeneralKeyMap, hkGeneralJoyMap); } InputConfigDialog::~InputConfigDialog() @@ -42,6 +99,109 @@ InputConfigDialog::~InputConfigDialog() delete ui; } +void InputConfigDialog::populatePage(QWidget* page, int num, const char** labels, int* keymap, int* joymap) +{ + // kind of a hack + bool ishotkey = (page != ui->tabInput); + + QHBoxLayout* main_layout = new QHBoxLayout(); + + QGroupBox* group; + QGridLayout* group_layout; + + group = new QGroupBox("Keyboard mappings:"); + main_layout->addWidget(group); + group_layout = new QGridLayout(); + group_layout->setSpacing(1); + for (int i = 0; i < num; i++) + { + QLabel* label = new QLabel(QString(labels[i])+":"); + KeyMapButton* btn = new KeyMapButton(nullptr, &keymap[i], ishotkey); + + group_layout->addWidget(label, i, 0); + group_layout->addWidget(btn, i, 1); + } + group_layout->setRowStretch(num, 1); + group->setLayout(group_layout); + group->setMinimumWidth(275); + + group = new QGroupBox("Joystick mappings:"); + main_layout->addWidget(group); + group_layout = new QGridLayout(); + group_layout->setSpacing(1); + for (int i = 0; i < num; i++) + { + QLabel* label = new QLabel(QString(labels[i])+":"); + QPushButton* btn = new QPushButton(); + + group_layout->addWidget(label, i, 0); + group_layout->addWidget(btn, i, 1); + + btn->setText(joyMappingName(joymap[i])); + + //btn->setProperty("mapping", QVariant(&joymap[i])); + //btn->setProperty("isHotkey", QVariant(ishotkey)); + } + group_layout->setRowStretch(num, 1); + group->setLayout(group_layout); + group->setMinimumWidth(275); + + page->setLayout(main_layout); +} + +QString InputConfigDialog::joyMappingName(int id) +{ + if (id < 0) + { + return "None"; + } + + bool hasbtn = ((id & 0xFFFF) != 0xFFFF); + QString str; + + if (hasbtn) + { + if (id & 0x100) + { + int hatnum = ((id >> 4) & 0xF) + 1; + + switch (id & 0xF) + { + case 0x1: str = "Hat %1 up"; break; + case 0x2: str = "Hat %1 right"; break; + case 0x4: str = "Hat %1 down"; break; + case 0x8: str = "Hat %1 left"; break; + } + + str = str.arg(hatnum); + } + else + { + str = QString("Button %1").arg((id & 0xFFFF) + 1); + } + } + else + { + str = ""; + } + + if (id & 0x10000) + { + int axisnum = ((id >> 24) & 0xF) + 1; + + if (hasbtn) str += " / "; + + switch ((id >> 20) & 0xF) + { + case 0: str += QString("Axis %1 +").arg(axisnum); break; + case 1: str += QString("Axis %1 -").arg(axisnum); break; + case 2: str += QString("Trigger %1").arg(axisnum); break; + } + } + + return str; +} + void InputConfigDialog::on_InputConfigDialog_accepted() { closeDlg(); @@ -51,3 +211,84 @@ void InputConfigDialog::on_InputConfigDialog_rejected() { closeDlg(); } + + +KeyMapButton::KeyMapButton(QWidget* parent, int* mapping, bool hotkey) : QPushButton(parent) +{ + this->mapping = mapping; + this->isHotkey = hotkey; + + setCheckable(true); + setText(mappingText()); + + connect(this, &KeyMapButton::clicked, this, &KeyMapButton::onClick); +} + +KeyMapButton::~KeyMapButton() +{ +} + +void KeyMapButton::keyPressEvent(QKeyEvent* event) +{ + if (!isChecked()) return QPushButton::keyPressEvent(event); +printf("KEY PRESSED = %08X %08X | %08X %08X %08X | %08X\n", event->key(), event->modifiers(), event->nativeVirtualKey(), event->nativeModifiers(), event->nativeScanCode(), Qt::SHIFT); + int key = event->key(); + bool ismod = (key == Qt::Key_Control || + key == Qt::Key_Alt || + key == Qt::Key_Shift || + key == Qt::Key_Meta); + + if (isHotkey) + { + if (ismod) + return; + } + + if (!ismod) + key |= event->modifiers(); + + *mapping = key; + click(); +} + +void KeyMapButton::focusOutEvent(QFocusEvent* event) +{ + if (isChecked()) + { + // if we lost the focus while mapping, consider it 'done' + click(); + } + + QPushButton::focusOutEvent(event); +} + +void KeyMapButton::onClick() +{ + if (isChecked()) + { + setText("[press key]"); + } + else + { + setText(mappingText()); + } +} + +QString KeyMapButton::mappingText() +{ + int key = *mapping; + + switch (key) + { + case -1: return "None"; + + case Qt::Key_Control: return "Ctrl"; + case Qt::Key_Alt: return "Alt"; + case Qt::Key_Shift: return "Shift"; + case Qt::Key_Meta: return "Meta"; + } + + QKeySequence seq(key); + QString ret = seq.toString(); + return ret.replace("&", "&&"); +} diff --git a/src/frontend/qt_sdl/InputConfigDialog.h b/src/frontend/qt_sdl/InputConfigDialog.h index 2af73db..b2ca3f2 100644 --- a/src/frontend/qt_sdl/InputConfigDialog.h +++ b/src/frontend/qt_sdl/InputConfigDialog.h @@ -20,6 +20,7 @@ #define INPUTCONFIGDIALOG_H #include +#include namespace Ui { class InputConfigDialog; } class InputConfigDialog; @@ -57,7 +58,38 @@ private slots: // private: + void populatePage(QWidget* page, int num, const char** labels, int* keymap, int* joymap); + + QString joyMappingName(int id); + Ui::InputConfigDialog* ui; + + int keypadKeyMap[12], keypadJoyMap[12]; + int addonsKeyMap[2], addonsJoyMap[2]; + int hkGeneralKeyMap[6], hkGeneralJoyMap[6]; +}; + + +class KeyMapButton : public QPushButton +{ + Q_OBJECT + +public: + explicit KeyMapButton(QWidget* parent, int* mapping, bool hotkey); + ~KeyMapButton(); + +protected: + void keyPressEvent(QKeyEvent* event) override; + void focusOutEvent(QFocusEvent* event) override; + +private slots: + void onClick(); + +private: + QString mappingText(); + + int* mapping; + bool isHotkey; }; #endif // INPUTCONFIGDIALOG_H diff --git a/src/frontend/qt_sdl/InputConfigDialog.ui b/src/frontend/qt_sdl/InputConfigDialog.ui index c1422e9..655da16 100644 --- a/src/frontend/qt_sdl/InputConfigDialog.ui +++ b/src/frontend/qt_sdl/InputConfigDialog.ui @@ -11,7 +11,7 @@ - TDAH + Input and hotkeys - melonDS @@ -20,11 +20,16 @@ - 1 + 0 - DS input + DS keypad + + + + + Add-ons diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index cd7849d..d664172 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -862,8 +862,8 @@ void MainWindow::onOpenInputConfig() connect(dlg, &InputConfigDialog::finished, this, &MainWindow::onInputConfigFinished); } -void MainWindow::onInputConfigFinished() -{printf("FARTO\n"); +void MainWindow::onInputConfigFinished(int res) +{ emuThread->emuUnpause(); } diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 0324ecf..4553875 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -109,7 +109,7 @@ private slots: void onOpenEmuSettings(); void onOpenInputConfig(); - void onInputConfigFinished(); + void onInputConfigFinished(int res); private: QString loadErrorStr(int error); -- cgit v1.2.3 From 7d69699d648b93d76f14024705c4a86f5929ba3d Mon Sep 17 00:00:00 2001 From: StapleButter Date: Tue, 19 May 2020 14:37:54 +0200 Subject: fix Linux build error --- src/frontend/qt_sdl/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index d664172..9d4c274 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -868,6 +868,11 @@ void MainWindow::onInputConfigFinished(int res) } +// FIXME!!!! +#if (!defined(__WIN32__) && !defined(UNIX_PORTABLE)) +#include +#endif + int main(int argc, char** argv) { srand(time(NULL)); -- cgit v1.2.3 From 9fbf9b997bb950a667d0af4583fd68098a7ed717 Mon Sep 17 00:00:00 2001 From: StapleButter Date: Tue, 19 May 2020 13:28:46 +0200 Subject: this might be a good idea --- src/frontend/qt_sdl/main.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 9d4c274..7b50af4 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -1045,6 +1045,7 @@ int main(int argc, char** argv) emuThread->emuStop(); emuThread->wait(); + delete emuThread; //if (Joystick) SDL_JoystickClose(Joystick); if (audioDevice) SDL_CloseAudioDevice(audioDevice); -- cgit v1.2.3 From 2a7027f794267effe651b242956ed669c242e9ca Mon Sep 17 00:00:00 2001 From: StapleButter Date: Tue, 19 May 2020 13:46:31 +0200 Subject: add AltGr, weak attempt at blocking garbage key names --- src/frontend/qt_sdl/InputConfigDialog.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/frontend/qt_sdl/InputConfigDialog.cpp b/src/frontend/qt_sdl/InputConfigDialog.cpp index 3b006fd..54251a1 100644 --- a/src/frontend/qt_sdl/InputConfigDialog.cpp +++ b/src/frontend/qt_sdl/InputConfigDialog.cpp @@ -235,6 +235,7 @@ printf("KEY PRESSED = %08X %08X | %08X %08X %08X | %08X\n", event->key(), event- int key = event->key(); bool ismod = (key == Qt::Key_Control || key == Qt::Key_Alt || + key == Qt::Key_AltGr || key == Qt::Key_Shift || key == Qt::Key_Meta); @@ -284,11 +285,17 @@ QString KeyMapButton::mappingText() case Qt::Key_Control: return "Ctrl"; case Qt::Key_Alt: return "Alt"; + case Qt::Key_AltGr: return "AltGr"; case Qt::Key_Shift: return "Shift"; case Qt::Key_Meta: return "Meta"; } QKeySequence seq(key); QString ret = seq.toString(); + + // weak attempt at detecting garbage key names + if (ret.length() == 2 && ret[0].unicode() > 0xFF) + return QString("[%1]").arg(key, 8, 16); + return ret.replace("&", "&&"); } -- cgit v1.2.3 From 23cc8c71a2c0ab3389b5208f49a25df0efc05a2e Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 19 May 2020 14:15:11 +0200 Subject: distinguish left/right Ctrl and Shift --- src/frontend/qt_sdl/InputConfigDialog.cpp | 22 +++++++++++++++------- src/frontend/qt_sdl/main.h | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/InputConfigDialog.cpp b/src/frontend/qt_sdl/InputConfigDialog.cpp index 54251a1..0ef29bb 100644 --- a/src/frontend/qt_sdl/InputConfigDialog.cpp +++ b/src/frontend/qt_sdl/InputConfigDialog.cpp @@ -24,6 +24,7 @@ #include "Config.h" #include "PlatformConfig.h" +#include "main.h" #include "InputConfigDialog.h" #include "ui_InputConfigDialog.h" @@ -231,7 +232,9 @@ KeyMapButton::~KeyMapButton() void KeyMapButton::keyPressEvent(QKeyEvent* event) { if (!isChecked()) return QPushButton::keyPressEvent(event); -printf("KEY PRESSED = %08X %08X | %08X %08X %08X | %08X\n", event->key(), event->modifiers(), event->nativeVirtualKey(), event->nativeModifiers(), event->nativeScanCode(), Qt::SHIFT); + + printf("KEY PRESSED = %08X %08X | %08X %08X %08X\n", event->key(), event->modifiers(), event->nativeVirtualKey(), event->nativeModifiers(), event->nativeScanCode()); + int key = event->key(); bool ismod = (key == Qt::Key_Control || key == Qt::Key_Alt || @@ -247,6 +250,8 @@ printf("KEY PRESSED = %08X %08X | %08X %08X %08X | %08X\n", event->key(), event- if (!ismod) key |= event->modifiers(); + else if (IsRightModKey(event)) + key |= (1<<31); *mapping = key; click(); @@ -279,23 +284,26 @@ QString KeyMapButton::mappingText() { int key = *mapping; + if (key == -1) return "None"; + + QString isright = (key & (1<<31)) ? "Right " : "Left "; + key &= ~(1<<31); + switch (key) { - case -1: return "None"; - - case Qt::Key_Control: return "Ctrl"; + case Qt::Key_Control: return isright + "Ctrl"; case Qt::Key_Alt: return "Alt"; case Qt::Key_AltGr: return "AltGr"; - case Qt::Key_Shift: return "Shift"; + case Qt::Key_Shift: return isright + "Shift"; case Qt::Key_Meta: return "Meta"; } QKeySequence seq(key); QString ret = seq.toString(); - + // weak attempt at detecting garbage key names if (ret.length() == 2 && ret[0].unicode() > 0xFF) return QString("[%1]").arg(key, 8, 16); - + return ret.replace("&", "&&"); } diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 4553875..5d6638c 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -23,6 +23,7 @@ #include #include #include +#include class EmuThread : public QThread @@ -131,4 +132,24 @@ private: QAction* actInputConfig; }; + +// TODO: MacOS version of this! +// distinguish between left and right modifier keys (Ctrl, Alt, Shift) +// Qt provides no real cross-platform way to do this, so here we go +// for Windows and Linux we can distinguish via scancodes (but both +// provide different scancodes) +#ifdef __WIN32__ +inline bool IsRightModKey(QKeyEvent* event) +{ + quint32 scan = event->nativeScanCode(); + return (scan == 0x11D || scan == 0x138 || scan == 0x36); +} +#else +inline bool IsRightModKey(QKeyEvent* event) +{ + quint32 scan = event->nativeScanCode(); + return (scan == 0x69 || scan == 0x6C || scan == 0x3E); +} +#endif + #endif // MAIN_H -- cgit v1.2.3 From 04d38e5e66cee768e32864b37a5cf37d8109d481 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 19 May 2020 14:16:35 +0200 Subject: axe the default key mappings (not too cross-platform and blargy) --- src/frontend/qt_sdl/PlatformConfig.cpp | 40 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/PlatformConfig.cpp b/src/frontend/qt_sdl/PlatformConfig.cpp index 1f6a873..3b4b4aa 100644 --- a/src/frontend/qt_sdl/PlatformConfig.cpp +++ b/src/frontend/qt_sdl/PlatformConfig.cpp @@ -67,18 +67,18 @@ char LastROMFolder[1024]; ConfigEntry PlatformConfigFile[] = { - {"Key_A", 0, &KeyMapping[0], 32, NULL, 0}, - {"Key_B", 0, &KeyMapping[1], 31, NULL, 0}, - {"Key_Select", 0, &KeyMapping[2], 57, NULL, 0}, - {"Key_Start", 0, &KeyMapping[3], 28, NULL, 0}, - {"Key_Right", 0, &KeyMapping[4], 333, NULL, 0}, - {"Key_Left", 0, &KeyMapping[5], 331, NULL, 0}, - {"Key_Up", 0, &KeyMapping[6], 328, NULL, 0}, - {"Key_Down", 0, &KeyMapping[7], 336, NULL, 0}, - {"Key_R", 0, &KeyMapping[8], 54, NULL, 0}, - {"Key_L", 0, &KeyMapping[9], 86, NULL, 0}, - {"Key_X", 0, &KeyMapping[10], 17, NULL, 0}, - {"Key_Y", 0, &KeyMapping[11], 30, NULL, 0}, + {"Key_A", 0, &KeyMapping[0], -1, NULL, 0}, + {"Key_B", 0, &KeyMapping[1], -1, NULL, 0}, + {"Key_Select", 0, &KeyMapping[2], -1, NULL, 0}, + {"Key_Start", 0, &KeyMapping[3], -1, NULL, 0}, + {"Key_Right", 0, &KeyMapping[4], -1, NULL, 0}, + {"Key_Left", 0, &KeyMapping[5], -1, NULL, 0}, + {"Key_Up", 0, &KeyMapping[6], -1, NULL, 0}, + {"Key_Down", 0, &KeyMapping[7], -1, NULL, 0}, + {"Key_R", 0, &KeyMapping[8], -1, NULL, 0}, + {"Key_L", 0, &KeyMapping[9], -1, NULL, 0}, + {"Key_X", 0, &KeyMapping[10], -1, NULL, 0}, + {"Key_Y", 0, &KeyMapping[11], -1, NULL, 0}, {"Joy_A", 0, &JoyMapping[0], -1, NULL, 0}, {"Joy_B", 0, &JoyMapping[1], -1, NULL, 0}, @@ -93,14 +93,14 @@ ConfigEntry PlatformConfigFile[] = {"Joy_X", 0, &JoyMapping[10], -1, NULL, 0}, {"Joy_Y", 0, &JoyMapping[11], -1, NULL, 0}, - {"HKKey_Lid", 0, &HKKeyMapping[HK_Lid], 0x0D, NULL, 0}, - {"HKKey_Mic", 0, &HKKeyMapping[HK_Mic], 0x35, NULL, 0}, - {"HKKey_Pause", 0, &HKKeyMapping[HK_Pause], -1, NULL, 0}, - {"HKKey_Reset", 0, &HKKeyMapping[HK_Reset], -1, NULL, 0}, - {"HKKey_FastForward", 0, &HKKeyMapping[HK_FastForward], 0x0F, NULL, 0}, - {"HKKey_FastForwardToggle", 0, &HKKeyMapping[HK_FastForwardToggle], -1, NULL, 0}, - {"HKKey_SolarSensorDecrease", 0, &HKKeyMapping[HK_SolarSensorDecrease], 0x4B, NULL, 0}, - {"HKKey_SolarSensorIncrease", 0, &HKKeyMapping[HK_SolarSensorIncrease], 0x4D, NULL, 0}, + {"HKKey_Lid", 0, &HKKeyMapping[HK_Lid], -1, NULL, 0}, + {"HKKey_Mic", 0, &HKKeyMapping[HK_Mic], -1, NULL, 0}, + {"HKKey_Pause", 0, &HKKeyMapping[HK_Pause], -1, NULL, 0}, + {"HKKey_Reset", 0, &HKKeyMapping[HK_Reset], -1, NULL, 0}, + {"HKKey_FastForward", 0, &HKKeyMapping[HK_FastForward], -1, NULL, 0}, + {"HKKey_FastForwardToggle", 0, &HKKeyMapping[HK_FastForwardToggle], -1, NULL, 0}, + {"HKKey_SolarSensorDecrease", 0, &HKKeyMapping[HK_SolarSensorDecrease], -1, NULL, 0}, + {"HKKey_SolarSensorIncrease", 0, &HKKeyMapping[HK_SolarSensorIncrease], -1, NULL, 0}, {"HKJoy_Lid", 0, &HKJoyMapping[HK_Lid], -1, NULL, 0}, {"HKJoy_Mic", 0, &HKJoyMapping[HK_Mic], -1, NULL, 0}, -- cgit v1.2.3 From 4b038f5d370c961803666f418ebfeb775cfa2d2a Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 19 May 2020 14:24:57 +0200 Subject: re-add old special keys for mapping (Esc=cancel, Backspace=clear) --- src/frontend/qt_sdl/InputConfigDialog.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/InputConfigDialog.cpp b/src/frontend/qt_sdl/InputConfigDialog.cpp index 0ef29bb..93204aa 100644 --- a/src/frontend/qt_sdl/InputConfigDialog.cpp +++ b/src/frontend/qt_sdl/InputConfigDialog.cpp @@ -236,12 +236,19 @@ void KeyMapButton::keyPressEvent(QKeyEvent* event) printf("KEY PRESSED = %08X %08X | %08X %08X %08X\n", event->key(), event->modifiers(), event->nativeVirtualKey(), event->nativeModifiers(), event->nativeScanCode()); int key = event->key(); + int mod = event->modifiers(); bool ismod = (key == Qt::Key_Control || key == Qt::Key_Alt || key == Qt::Key_AltGr || key == Qt::Key_Shift || key == Qt::Key_Meta); + if (!mod) + { + if (key == Qt::Key_Escape) { click(); return; } + if (key == Qt::Key_Backspace) { *mapping = -1; click(); return; } + } + if (isHotkey) { if (ismod) @@ -249,7 +256,7 @@ void KeyMapButton::keyPressEvent(QKeyEvent* event) } if (!ismod) - key |= event->modifiers(); + key |= mod; else if (IsRightModKey(event)) key |= (1<<31); -- cgit v1.2.3 From 920ff9778d3fbdd18576ab473cca6212ee387cb1 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 19 May 2020 15:11:34 +0200 Subject: blarg --- src/Config.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Config.cpp b/src/Config.cpp index 7604785..84c83d8 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -90,7 +90,8 @@ void Load() while (!feof(f)) { fgets(linebuf, 1024, f); - int ret = sscanf(linebuf, "%32[A-Za-z_0-9]=%[^\t\n]", entryname, entryval); + int ret = sscanf(linebuf, "%31[A-Za-z_0-9]=%[^\t\n]", entryname, entryval); + entryname[31] = '\0'; if (ret < 2) continue; ConfigEntry* entry = &ConfigFile[0]; -- cgit v1.2.3 From 34506ff2bb1be880cf260e0c1b09efede14ac0d8 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 19 May 2020 20:48:52 +0200 Subject: actually complete the input config dialog --- src/frontend/qt_sdl/CMakeLists.txt | 1 + src/frontend/qt_sdl/Input.cpp | 119 +++++++++++++ src/frontend/qt_sdl/Input.h | 40 +++++ src/frontend/qt_sdl/InputConfigDialog.cpp | 283 ++++++++++++++++++++++++------ src/frontend/qt_sdl/InputConfigDialog.h | 32 +++- src/frontend/qt_sdl/main.cpp | 15 +- src/frontend/qt_sdl/main.h | 21 --- 7 files changed, 425 insertions(+), 86 deletions(-) create mode 100644 src/frontend/qt_sdl/Input.cpp create mode 100644 src/frontend/qt_sdl/Input.h (limited to 'src') diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index da3bb1d..42cf912 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -4,6 +4,7 @@ SET(SOURCES_QT_SDL main.cpp EmuSettingsDialog.cpp InputConfigDialog.cpp + Input.cpp Platform.cpp PlatformConfig.cpp diff --git a/src/frontend/qt_sdl/Input.cpp b/src/frontend/qt_sdl/Input.cpp new file mode 100644 index 0000000..7caf24a --- /dev/null +++ b/src/frontend/qt_sdl/Input.cpp @@ -0,0 +1,119 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include +#include + +#include "Input.h" +#include "PlatformConfig.h" + + +namespace Input +{ + +int JoystickID; +SDL_Joystick* Joystick = nullptr; + +u32 KeyInputMask, JoyInputMask; +u32 KeyHotkeyMask, JoyHotkeyMask; +u32 HotkeyMask, LastHotkeyMask; +u32 HotkeyPress, HotkeyRelease; + + +void OpenJoystick() +{ + if (Joystick) SDL_JoystickClose(Joystick); + + int num = SDL_NumJoysticks(); + if (num < 1) + { + Joystick = nullptr; + return; + } + + if (JoystickID >= num) + JoystickID = 0; + + Joystick = SDL_JoystickOpen(JoystickID); +} + +void CloseJoystick() +{ + if (Joystick) + { + SDL_JoystickClose(Joystick); + Joystick = nullptr; + } +} + + +void Process() +{ + SDL_JoystickUpdate(); + + if (Joystick) + { + if (!SDL_JoystickGetAttached(Joystick)) + { + SDL_JoystickClose(Joystick); + Joystick = NULL; + } + } + if (!Joystick && (SDL_NumJoysticks() > 0)) + { + JoystickID = Config::JoystickID; + OpenJoystick(); + } + + /*JoyInputMask = 0xFFF; + for (int i = 0; i < 12; i++) + if (JoystickButtonDown(Config::JoyMapping[i])) + JoyInputMask &= ~(1<nativeScanCode(); + return (scan == 0x11D || scan == 0x138 || scan == 0x36); +} +#else +bool IsRightModKey(QKeyEvent* event) +{ + quint32 scan = event->nativeScanCode(); + return (scan == 0x69 || scan == 0x6C || scan == 0x3E); +} +#endif + +} diff --git a/src/frontend/qt_sdl/Input.h b/src/frontend/qt_sdl/Input.h new file mode 100644 index 0000000..24ec3a7 --- /dev/null +++ b/src/frontend/qt_sdl/Input.h @@ -0,0 +1,40 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef INPUT_H +#define INPUT_H + +#include "types.h" + +namespace Input +{ + +extern int JoystickID; +extern SDL_Joystick* Joystick; + +// set joystickID before calling openJoystick() +void OpenJoystick(); +void CloseJoystick(); + +void Process(); + +bool IsRightModKey(QKeyEvent* event); + +} + +#endif // INPUT_H diff --git a/src/frontend/qt_sdl/InputConfigDialog.cpp b/src/frontend/qt_sdl/InputConfigDialog.cpp index 93204aa..2c0afc4 100644 --- a/src/frontend/qt_sdl/InputConfigDialog.cpp +++ b/src/frontend/qt_sdl/InputConfigDialog.cpp @@ -20,11 +20,13 @@ #include #include +#include + #include "types.h" #include "Config.h" #include "PlatformConfig.h" -#include "main.h" +#include "Input.h" #include "InputConfigDialog.h" #include "ui_InputConfigDialog.h" @@ -93,6 +95,22 @@ InputConfigDialog::InputConfigDialog(QWidget* parent) : QDialog(parent), ui(new populatePage(ui->tabInput, 12, dskeylabels, keypadKeyMap, keypadJoyMap); populatePage(ui->tabAddons, 2, hk_addons_labels, addonsKeyMap, addonsJoyMap); populatePage(ui->tabHotkeysGeneral, 6, hk_general_labels, hkGeneralKeyMap, hkGeneralJoyMap); + + int njoy = SDL_NumJoysticks(); + if (njoy > 0) + { + for (int i = 0; i < njoy; i++) + { + const char* name = SDL_JoystickNameForIndex(i); + ui->cbxJoystick->addItem(QString(name)); + } + ui->cbxJoystick->setCurrentIndex(Input::JoystickID); + } + else + { + ui->cbxJoystick->addItem("(no joysticks available)"); + ui->cbxJoystick->setEnabled(false); + } } InputConfigDialog::~InputConfigDialog() @@ -117,7 +135,7 @@ void InputConfigDialog::populatePage(QWidget* page, int num, const char** labels for (int i = 0; i < num; i++) { QLabel* label = new QLabel(QString(labels[i])+":"); - KeyMapButton* btn = new KeyMapButton(nullptr, &keymap[i], ishotkey); + KeyMapButton* btn = new KeyMapButton(&keymap[i], ishotkey); group_layout->addWidget(label, i, 0); group_layout->addWidget(btn, i, 1); @@ -133,15 +151,10 @@ void InputConfigDialog::populatePage(QWidget* page, int num, const char** labels for (int i = 0; i < num; i++) { QLabel* label = new QLabel(QString(labels[i])+":"); - QPushButton* btn = new QPushButton(); + JoyMapButton* btn = new JoyMapButton(&joymap[i], ishotkey); group_layout->addWidget(label, i, 0); group_layout->addWidget(btn, i, 1); - - btn->setText(joyMappingName(joymap[i])); - - //btn->setProperty("mapping", QVariant(&joymap[i])); - //btn->setProperty("isHotkey", QVariant(ishotkey)); } group_layout->setRowStretch(num, 1); group->setLayout(group_layout); @@ -150,71 +163,48 @@ void InputConfigDialog::populatePage(QWidget* page, int num, const char** labels page->setLayout(main_layout); } -QString InputConfigDialog::joyMappingName(int id) +void InputConfigDialog::on_InputConfigDialog_accepted() { - if (id < 0) + for (int i = 0; i < 12; i++) { - return "None"; + Config::KeyMapping[dskeyorder[i]] = keypadKeyMap[i]; + Config::JoyMapping[dskeyorder[i]] = keypadJoyMap[i]; } - bool hasbtn = ((id & 0xFFFF) != 0xFFFF); - QString str; - - if (hasbtn) - { - if (id & 0x100) - { - int hatnum = ((id >> 4) & 0xF) + 1; - - switch (id & 0xF) - { - case 0x1: str = "Hat %1 up"; break; - case 0x2: str = "Hat %1 right"; break; - case 0x4: str = "Hat %1 down"; break; - case 0x8: str = "Hat %1 left"; break; - } - - str = str.arg(hatnum); - } - else - { - str = QString("Button %1").arg((id & 0xFFFF) + 1); - } - } - else + for (int i = 0; i < 2; i++) { - str = ""; + Config::HKKeyMapping[hk_addons[i]] = addonsKeyMap[i]; + Config::HKJoyMapping[hk_addons[i]] = addonsJoyMap[i]; } - if (id & 0x10000) + for (int i = 0; i < 6; i++) { - int axisnum = ((id >> 24) & 0xF) + 1; - - if (hasbtn) str += " / "; - - switch ((id >> 20) & 0xF) - { - case 0: str += QString("Axis %1 +").arg(axisnum); break; - case 1: str += QString("Axis %1 -").arg(axisnum); break; - case 2: str += QString("Trigger %1").arg(axisnum); break; - } + Config::HKKeyMapping[hk_general[i]] = hkGeneralKeyMap[i]; + Config::HKJoyMapping[hk_general[i]] = hkGeneralJoyMap[i]; } - return str; -} + Config::JoystickID = Input::JoystickID; + Config::Save(); -void InputConfigDialog::on_InputConfigDialog_accepted() -{ closeDlg(); } void InputConfigDialog::on_InputConfigDialog_rejected() { + Input::JoystickID = Config::JoystickID; + Input::OpenJoystick(); + closeDlg(); } +void InputConfigDialog::on_cbxJoystick_currentIndexChanged(int id) +{ + Input::JoystickID = id; + Input::OpenJoystick(); +} + -KeyMapButton::KeyMapButton(QWidget* parent, int* mapping, bool hotkey) : QPushButton(parent) +KeyMapButton::KeyMapButton(int* mapping, bool hotkey) : QPushButton() { this->mapping = mapping; this->isHotkey = hotkey; @@ -257,7 +247,7 @@ void KeyMapButton::keyPressEvent(QKeyEvent* event) if (!ismod) key |= mod; - else if (IsRightModKey(event)) + else if (Input::IsRightModKey(event)) key |= (1<<31); *mapping = key; @@ -314,3 +304,188 @@ QString KeyMapButton::mappingText() return ret.replace("&", "&&"); } + + +JoyMapButton::JoyMapButton(int* mapping, bool hotkey) : QPushButton() +{ + this->mapping = mapping; + this->isHotkey = hotkey; + + setCheckable(true); + setText(mappingText()); + + connect(this, &JoyMapButton::clicked, this, &JoyMapButton::onClick); + + timerID = 0; +} + +JoyMapButton::~JoyMapButton() +{ +} + +void JoyMapButton::keyPressEvent(QKeyEvent* event) +{ + if (!isChecked()) return QPushButton::keyPressEvent(event); + + int key = event->key(); + int mod = event->modifiers(); + + if (!mod) + { + if (key == Qt::Key_Escape) { click(); return; } + if (key == Qt::Key_Backspace) { *mapping = -1; click(); return; } + } +} + +void JoyMapButton::focusOutEvent(QFocusEvent* event) +{ + if (isChecked()) + { + // if we lost the focus while mapping, consider it 'done' + click(); + } + + QPushButton::focusOutEvent(event); +} + +void JoyMapButton::timerEvent(QTimerEvent* event) +{ + SDL_Joystick* joy = Input::Joystick; + if (!joy) { click(); return; } + if (!SDL_JoystickGetAttached(joy)) { click(); return; } + + int oldmap; + if (*mapping == -1) oldmap = 0xFFFF; + else oldmap = *mapping; + + int nbuttons = SDL_JoystickNumButtons(joy); + for (int i = 0; i < nbuttons; i++) + { + if (SDL_JoystickGetButton(joy, i)) + { + *mapping = (oldmap & 0xFFFF0000) | i; + click(); + return; + } + } + + int nhats = SDL_JoystickNumHats(joy); + if (nhats > 16) nhats = 16; + for (int i = 0; i < nhats; i++) + { + Uint8 blackhat = SDL_JoystickGetHat(joy, i); + if (blackhat) + { + if (blackhat & 0x1) blackhat = 0x1; + else if (blackhat & 0x2) blackhat = 0x2; + else if (blackhat & 0x4) blackhat = 0x4; + else blackhat = 0x8; + + *mapping = (oldmap & 0xFFFF0000) | 0x100 | blackhat | (i << 4); + click(); + return; + } + } + + int naxes = SDL_JoystickNumAxes(joy); + if (naxes > 16) naxes = 16; + for (int i = 0; i < naxes; i++) + { + Sint16 axisval = SDL_JoystickGetAxis(joy, i); + int diff = abs(axisval - axesRest[i]); + + if (axesRest[i] < -16384 && axisval >= 0) + { + *mapping = (oldmap & 0xFFFF) | 0x10000 | (2 << 20) | (i << 24); + click(); + return; + } + else if (diff > 16384) + { + int axistype; + if (axisval > 0) axistype = 0; + else axistype = 1; + + *mapping = (oldmap & 0xFFFF) | 0x10000 | (axistype << 20) | (i << 24); + click(); + return; + } + } +} + +void JoyMapButton::onClick() +{ + if (isChecked()) + { + setText("[press button/axis]"); + timerID = startTimer(50); + + memset(axesRest, 0, sizeof(axesRest)); + if (Input::Joystick && SDL_JoystickGetAttached(Input::Joystick)) + { + int naxes = SDL_JoystickNumAxes(Input::Joystick); + if (naxes > 16) naxes = 16; + for (int a = 0; a < naxes; a++) + { + axesRest[a] = SDL_JoystickGetAxis(Input::Joystick, a); + } + } + } + else + { + setText(mappingText()); + if (timerID) { killTimer(timerID); timerID = 0; } + } +} + +QString JoyMapButton::mappingText() +{ + int id = *mapping; + + if (id == -1) return "None"; + + bool hasbtn = ((id & 0xFFFF) != 0xFFFF); + QString str; + + if (hasbtn) + { + if (id & 0x100) + { + int hatnum = ((id >> 4) & 0xF) + 1; + + switch (id & 0xF) + { + case 0x1: str = "Hat %1 up"; break; + case 0x2: str = "Hat %1 right"; break; + case 0x4: str = "Hat %1 down"; break; + case 0x8: str = "Hat %1 left"; break; + } + + str = str.arg(hatnum); + } + else + { + str = QString("Button %1").arg((id & 0xFFFF) + 1); + } + } + else + { + str = ""; + } + + if (id & 0x10000) + { + int axisnum = ((id >> 24) & 0xF) + 1; + + if (hasbtn) str += " / "; + + switch ((id >> 20) & 0xF) + { + case 0: str += QString("Axis %1 +").arg(axisnum); break; + case 1: str += QString("Axis %1 -").arg(axisnum); break; + case 2: str += QString("Trigger %1").arg(axisnum); break; + } + } + + return str; +} diff --git a/src/frontend/qt_sdl/InputConfigDialog.h b/src/frontend/qt_sdl/InputConfigDialog.h index b2ca3f2..82e37bc 100644 --- a/src/frontend/qt_sdl/InputConfigDialog.h +++ b/src/frontend/qt_sdl/InputConfigDialog.h @@ -55,13 +55,11 @@ private slots: void on_InputConfigDialog_accepted(); void on_InputConfigDialog_rejected(); - // + void on_cbxJoystick_currentIndexChanged(int id); private: void populatePage(QWidget* page, int num, const char** labels, int* keymap, int* joymap); - QString joyMappingName(int id); - Ui::InputConfigDialog* ui; int keypadKeyMap[12], keypadJoyMap[12]; @@ -75,7 +73,7 @@ class KeyMapButton : public QPushButton Q_OBJECT public: - explicit KeyMapButton(QWidget* parent, int* mapping, bool hotkey); + explicit KeyMapButton(int* mapping, bool hotkey); ~KeyMapButton(); protected: @@ -92,4 +90,30 @@ private: bool isHotkey; }; +class JoyMapButton : public QPushButton +{ + Q_OBJECT + +public: + explicit JoyMapButton(int* mapping, bool hotkey); + ~JoyMapButton(); + +protected: + void keyPressEvent(QKeyEvent* event) override; + void focusOutEvent(QFocusEvent* event) override; + void timerEvent(QTimerEvent* event) override; + +private slots: + void onClick(); + +private: + QString mappingText(); + + int* mapping; + bool isHotkey; + + int timerID; + int axesRest[16]; +}; + #endif // INPUTCONFIGDIALOG_H diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 7b50af4..8fe776e 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -27,10 +27,12 @@ #include #include #include +#include #include #include "main.h" +#include "Input.h" #include "EmuSettingsDialog.h" #include "InputConfigDialog.h" @@ -136,12 +138,6 @@ void EmuThread::run() } /*Touching = false; - KeyInputMask = 0xFFF; - JoyInputMask = 0xFFF; - KeyHotkeyMask = 0; - JoyHotkeyMask = 0; - HotkeyMask = 0; - LastHotkeyMask = 0; LidStatus = false;*/ u32 nframes = 0; @@ -154,6 +150,7 @@ void EmuThread::run() while (EmuRunning != 0) { + Input::Process(); /*ProcessInput(); if (HotkeyPressed(HK_FastForwardToggle)) @@ -999,6 +996,9 @@ int main(int argc, char** argv) Frontend::Init_ROM(); Frontend::Init_Audio(audioFreq); + Input::JoystickID = Config::JoystickID; + Input::OpenJoystick(); + mainWindow = new MainWindow(); mainWindow->show(); @@ -1047,7 +1047,8 @@ int main(int argc, char** argv) emuThread->wait(); delete emuThread; - //if (Joystick) SDL_JoystickClose(Joystick); + Input::CloseJoystick(); + if (audioDevice) SDL_CloseAudioDevice(audioDevice); //if (MicDevice) SDL_CloseAudioDevice(MicDevice); diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 5d6638c..4553875 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -23,7 +23,6 @@ #include #include #include -#include class EmuThread : public QThread @@ -132,24 +131,4 @@ private: QAction* actInputConfig; }; - -// TODO: MacOS version of this! -// distinguish between left and right modifier keys (Ctrl, Alt, Shift) -// Qt provides no real cross-platform way to do this, so here we go -// for Windows and Linux we can distinguish via scancodes (but both -// provide different scancodes) -#ifdef __WIN32__ -inline bool IsRightModKey(QKeyEvent* event) -{ - quint32 scan = event->nativeScanCode(); - return (scan == 0x11D || scan == 0x138 || scan == 0x36); -} -#else -inline bool IsRightModKey(QKeyEvent* event) -{ - quint32 scan = event->nativeScanCode(); - return (scan == 0x69 || scan == 0x6C || scan == 0x3E); -} -#endif - #endif // MAIN_H -- cgit v1.2.3 From 9df8d91bdc12ab2e65569e26dc7c57246e384a8f Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 19 May 2020 21:34:24 +0200 Subject: keep the ugliness confined in Platform.cpp --- src/Platform.h | 3 +++ src/frontend/qt_sdl/Platform.cpp | 49 +++++++++++++++++++++++++++++++++++++++- src/frontend/qt_sdl/main.cpp | 47 ++------------------------------------ 3 files changed, 53 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/Platform.h b/src/Platform.h index b6effdc..fea98dd 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -24,6 +24,9 @@ namespace Platform { +void Init(int argc, char** argv); +void DeInit(); + void StopEmu(); // fopen() wrappers diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index fea9166..6a5b466 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -53,7 +53,7 @@ #endif -extern char* EmuDirectory; +char* EmuDirectory; void Stop(bool internal); @@ -84,6 +84,53 @@ u8 PacketBuffer[2048]; #define NIFI_VER 1 +void Init(int argc, char** argv) +{ +#if defined(__WIN32__) || defined(UNIX_PORTABLE) + if (argc > 0 && strlen(argv[0]) > 0) + { + int len = strlen(argv[0]); + while (len > 0) + { + if (argv[0][len] == '/') break; + if (argv[0][len] == '\\') break; + len--; + } + if (len > 0) + { + EmuDirectory = new char[len+1]; + strncpy(EmuDirectory, argv[0], len); + EmuDirectory[len] = '\0'; + } + else + { + EmuDirectory = new char[2]; + strcpy(EmuDirectory, "."); + } + } + else + { + EmuDirectory = new char[2]; + strcpy(EmuDirectory, "."); + } +#else + const char* confdir = g_get_user_config_dir(); + const char* confname = "/melonDS"; + int cdlen = strlen(confdir); + int cnlen = strlen(confname); + EmuDirectory = new char[cdlen + cnlen + 1]; + strncpy(&EmuDirectory[0], confdir, cdlen); + strncpy(&EmuDirectory[cdlen], confname, cnlen); + EmuDirectory[cdlen+cnlen] = '\0'; +#endif +} + +void DeInit() +{ + delete[] EmuDirectory; +} + + void StopEmu() { //Stop(true); diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 8fe776e..a68f933 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -54,8 +54,6 @@ // TODO: uniform variable spelling -char* EmuDirectory; - bool RunningSomething; MainWindow* mainWindow; @@ -865,11 +863,6 @@ void MainWindow::onInputConfigFinished(int res) } -// FIXME!!!! -#if (!defined(__WIN32__) && !defined(UNIX_PORTABLE)) -#include -#endif - int main(int argc, char** argv) { srand(time(NULL)); @@ -877,43 +870,7 @@ int main(int argc, char** argv) printf("melonDS " MELONDS_VERSION "\n"); printf(MELONDS_URL "\n"); -#if defined(__WIN32__) || defined(UNIX_PORTABLE) - if (argc > 0 && strlen(argv[0]) > 0) - { - int len = strlen(argv[0]); - while (len > 0) - { - if (argv[0][len] == '/') break; - if (argv[0][len] == '\\') break; - len--; - } - if (len > 0) - { - EmuDirectory = new char[len+1]; - strncpy(EmuDirectory, argv[0], len); - EmuDirectory[len] = '\0'; - } - else - { - EmuDirectory = new char[2]; - strcpy(EmuDirectory, "."); - } - } - else - { - EmuDirectory = new char[2]; - strcpy(EmuDirectory, "."); - } -#else - const char* confdir = g_get_user_config_dir(); - const char* confname = "/melonDS"; - int cdlen = strlen(confdir); - int cnlen = strlen(confname); - EmuDirectory = new char[cdlen + cnlen + 1]; - strncpy(&EmuDirectory[0], confdir, cdlen); - strncpy(&EmuDirectory[cdlen], confname, cnlen); - EmuDirectory[cdlen+cnlen] = '\0'; -#endif + Platform::Init(argc, argv); QApplication melon(argc, argv); @@ -1060,7 +1017,7 @@ int main(int argc, char** argv) Config::Save(); SDL_Quit(); - delete[] EmuDirectory; + Platform::DeInit(); return ret; } -- cgit v1.2.3 From b262313816b9fac581353f74dd71e1dde1f23013 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 19 May 2020 22:22:21 +0200 Subject: actually hook up input to the core also unbotch CMakeLists.txt --- CMakeLists.txt | 8 +++ src/frontend/qt_sdl/Input.cpp | 124 +++++++++++++++++++++++++++++++++++++++++- src/frontend/qt_sdl/Input.h | 7 +++ src/frontend/qt_sdl/main.cpp | 14 ++++- src/frontend/qt_sdl/main.h | 1 + 5 files changed, 150 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index ee021d9..e640a48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,14 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() +if (CMAKE_BUILD_TYPE STREQUAL Debug) + add_compile_options(-Og) +endif() + +if (CMAKE_BUILD_TYPE STREQUAL Release) + add_compile_options(-O3) +endif() + add_compile_options(-fno-pic) add_link_options(-no-pie) diff --git a/src/frontend/qt_sdl/Input.cpp b/src/frontend/qt_sdl/Input.cpp index 7caf24a..d60271c 100644 --- a/src/frontend/qt_sdl/Input.cpp +++ b/src/frontend/qt_sdl/Input.cpp @@ -34,6 +34,21 @@ u32 KeyHotkeyMask, JoyHotkeyMask; u32 HotkeyMask, LastHotkeyMask; u32 HotkeyPress, HotkeyRelease; +u32 InputMask; + + +void Init() +{ + KeyInputMask = 0xFFF; + JoyInputMask = 0xFFF; + InputMask = 0xFFF; + + KeyHotkeyMask = 0; + JoyHotkeyMask = 0; + HotkeyMask = 0; + LastHotkeyMask = 0; +} + void OpenJoystick() { @@ -62,6 +77,109 @@ void CloseJoystick() } +int GetEventKeyVal(QKeyEvent* event) +{ + int key = event->key(); + int mod = event->modifiers(); + bool ismod = (key == Qt::Key_Control || + key == Qt::Key_Alt || + key == Qt::Key_AltGr || + key == Qt::Key_Shift || + key == Qt::Key_Meta); + + if (!ismod) + key |= mod; + else if (Input::IsRightModKey(event)) + key |= (1<<31); + + return key; +} + +void KeyPress(QKeyEvent* event) +{ + int keyHK = GetEventKeyVal(event); + int keyKP = keyHK & ~event->modifiers(); + + for (int i = 0; i < 12; i++) + if (keyKP == Config::KeyMapping[i]) + KeyInputMask &= ~(1<modifiers(); + + for (int i = 0; i < 12; i++) + if (keyKP == Config::KeyMapping[i]) + KeyInputMask |= (1<> 4) & 0xF; + int hatdir = val & 0xF; + Uint8 hatval = SDL_JoystickGetHat(Joystick, hatnum); + + bool pressed = false; + if (hatdir == 0x1) pressed = (hatval & SDL_HAT_UP); + else if (hatdir == 0x4) pressed = (hatval & SDL_HAT_DOWN); + else if (hatdir == 0x2) pressed = (hatval & SDL_HAT_RIGHT); + else if (hatdir == 0x8) pressed = (hatval & SDL_HAT_LEFT); + + if (pressed) return true; + } + else + { + int btnnum = val & 0xFFFF; + Uint8 btnval = SDL_JoystickGetButton(Joystick, btnnum); + + if (btnval) return true; + } + } + + if (val & 0x10000) + { + int axisnum = (val >> 24) & 0xF; + int axisdir = (val >> 20) & 0xF; + Sint16 axisval = SDL_JoystickGetAxis(Joystick, axisnum); + + switch (axisdir) + { + case 0: // positive + if (axisval > 16384) return true; + break; + + case 1: // negative + if (axisval < -16384) return true; + break; + + case 2: // trigger + if (axisval > 0) return true; + break; + } + } + + return false; +} + void Process() { SDL_JoystickUpdate(); @@ -80,11 +198,13 @@ void Process() OpenJoystick(); } - /*JoyInputMask = 0xFFF; + JoyInputMask = 0xFFF; for (int i = 0; i < 12; i++) if (JoystickButtonDown(Config::JoyMapping[i])) JoyInputMask &= ~(1<key(), event->nativeScanCode(), event->modifiers(), event->nativeModifiers()); + if (event->isAutoRepeat()) return; + + Input::KeyPress(event); +} + +void MainWindow::keyReleaseEvent(QKeyEvent* event) +{ + if (event->isAutoRepeat()) return; + + Input::KeyRelease(event); } diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 4553875..a3125cc 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -87,6 +87,7 @@ public: protected: void keyPressEvent(QKeyEvent* event) override; + void keyReleaseEvent(QKeyEvent* event) override; private slots: void onOpenFile(); -- cgit v1.2.3 From 95f9698077fe50d2567aacd8728ff2625f88f228 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 19 May 2020 22:37:48 +0200 Subject: add back some hotkeys. remove some legacy cruft from NDS.cpp. --- src/NDS.cpp | 18 ++++++++-------- src/NDS.h | 3 +-- src/frontend/qt_sdl/Input.cpp | 5 +++++ src/frontend/qt_sdl/Input.h | 4 ++++ src/frontend/qt_sdl/main.cpp | 48 ++++++++++++++++++++----------------------- 5 files changed, 40 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/NDS.cpp b/src/NDS.cpp index 745ed28..e89aa66 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -951,23 +951,15 @@ void CancelEvent(u32 id) } -void PressKey(u32 key) -{ - KeyInput &= ~(1 << key); -} - -void ReleaseKey(u32 key) -{ - KeyInput |= (1 << key); -} - void TouchScreen(u16 x, u16 y) { + KeyInput &= ~(1<<22); SPI_TSC::SetTouchCoords(x, y); } void ReleaseScreen() { + KeyInput |= (1<<22); SPI_TSC::SetTouchCoords(0x000, 0xFFF); } @@ -981,6 +973,12 @@ void SetKeyMask(u32 mask) KeyInput |= key_lo | (key_hi << 16); } +bool IsLidClosed() +{ + if (KeyInput & (1<<23)) return true; + return false; +} + void SetLidClosed(bool closed) { if (closed) diff --git a/src/NDS.h b/src/NDS.h index c7b455e..daeadc4 100644 --- a/src/NDS.h +++ b/src/NDS.h @@ -142,13 +142,12 @@ void RelocateSave(const char* path, bool write); u32 RunFrame(); -void PressKey(u32 key); -void ReleaseKey(u32 key); void TouchScreen(u16 x, u16 y); void ReleaseScreen(); void SetKeyMask(u32 mask); +bool IsLidClosed(); void SetLidClosed(bool closed); void MicInputFrame(s16* data, int samples); diff --git a/src/frontend/qt_sdl/Input.cpp b/src/frontend/qt_sdl/Input.cpp index d60271c..84d20ad 100644 --- a/src/frontend/qt_sdl/Input.cpp +++ b/src/frontend/qt_sdl/Input.cpp @@ -217,6 +217,11 @@ void Process() } +bool HotkeyDown(int id) { return HotkeyMask & (1< 0) GBACart_SolarSensor::LightLevel--; - char msg[64]; - sprintf(msg, "Solar sensor level set to %d", GBACart_SolarSensor::LightLevel); - OSD::AddMessage(0, msg); + //char msg[64]; + //sprintf(msg, "Solar sensor level set to %d", GBACart_SolarSensor::LightLevel); + //OSD::AddMessage(0, msg); } - if (HotkeyPressed(HK_SolarSensorIncrease)) + if (Input::HotkeyPressed(HK_SolarSensorIncrease)) { if (GBACart_SolarSensor::LightLevel < 10) GBACart_SolarSensor::LightLevel++; - char msg[64]; - sprintf(msg, "Solar sensor level set to %d", GBACart_SolarSensor::LightLevel); - OSD::AddMessage(0, msg); + //char msg[64]; + //sprintf(msg, "Solar sensor level set to %d", GBACart_SolarSensor::LightLevel); + //OSD::AddMessage(0, msg); } - }*/ + } if (EmuRunning == 1) { @@ -186,14 +184,13 @@ void EmuThread::run() // process input and hotkeys NDS::SetKeyMask(Input::InputMask); - /*NDS::SetKeyMask(KeyInputMask & JoyInputMask); - if (HotkeyPressed(HK_Lid)) + if (Input::HotkeyPressed(HK_Lid)) { - LidStatus = !LidStatus; - NDS::SetLidClosed(LidStatus); - OSD::AddMessage(0, LidStatus ? "Lid closed" : "Lid opened"); - }*/ + bool lid = !NDS::IsLidClosed(); + NDS::SetLidClosed(lid); + //OSD::AddMessage(0, lid ? "Lid closed" : "Lid opened"); + } // microphone input /*FeedMicInput(); @@ -250,8 +247,7 @@ void EmuThread::run() uiAreaQueueRedrawAll(MainDrawArea);*/ mainWindow->update(); - bool fastforward = false; - //bool fastforward = HotkeyDown(HK_FastForward); + bool fastforward = Input::HotkeyDown(HK_FastForward); if (Config::AudioSync && (!fastforward) && audioDevice) { -- cgit v1.2.3 From 68a7865096a17b7a10a9dc521c99c7eb042582ec Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 19 May 2020 22:57:15 +0200 Subject: basic touchscreen support --- src/frontend/qt_sdl/main.cpp | 42 +++++++++++++++++++++++++++++++++++++++--- src/frontend/qt_sdl/main.h | 3 +++ 2 files changed, 42 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 67ac92c..3b0b35d 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -410,6 +410,8 @@ MainWindowPanel::MainWindowPanel(QWidget* parent) : QWidget(parent) { screen[0] = new QImage(256, 192, QImage::Format_RGB32); screen[1] = new QImage(256, 192, QImage::Format_RGB32); + + touching = false; } MainWindowPanel::~MainWindowPanel() @@ -441,25 +443,59 @@ void MainWindowPanel::paintEvent(QPaintEvent* event) } +void MainWindowPanel::transformTSCoords(int& x, int& y) +{ + // TODO: actual screen de-transform taking screen layout/rotation/etc into account + + y -= 192; + + // clamp to screen range + if (x < 0) x = 0; + else if (x > 255) x = 255; + if (y < 0) y = 0; + else if (y > 191) y = 191; +} + void MainWindowPanel::mousePressEvent(QMouseEvent* event) { event->accept(); + if (event->button() != Qt::LeftButton) return; + + int x = event->pos().x(); + int y = event->pos().y(); - printf("mouse press %d,%d\n", event->pos().x(), event->pos().y()); + if (x >= 0 && x < 256 && y >= 192 && y < 384) + { + touching = true; + + transformTSCoords(x, y); + NDS::TouchScreen(x, y); + } } void MainWindowPanel::mouseReleaseEvent(QMouseEvent* event) { event->accept(); + if (event->button() != Qt::LeftButton) return; - printf("mouse release %d,%d\n", event->pos().x(), event->pos().y()); + if (touching) + { + touching = false; + NDS::ReleaseScreen(); + } } void MainWindowPanel::mouseMoveEvent(QMouseEvent* event) { event->accept(); + if (!(event->buttons() & Qt::LeftButton)) return; + if (!touching) return; + + int x = event->pos().x(); + int y = event->pos().y(); - printf("mouse move %d,%d %08X\n", event->pos().x(), event->pos().y(), event->buttons()); + transformTSCoords(x, y); + NDS::TouchScreen(x, y); } diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index a3125cc..5443780 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -74,6 +74,9 @@ protected: private: QImage* screen[2]; + bool touching; + + void transformTSCoords(int& x, int& y); }; -- cgit v1.2.3 From 34133ef75c8f6f735604d7368a79a54724f06b99 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 20 May 2020 01:09:58 +0200 Subject: make it able to map the Tab key --- src/NDSCart.cpp | 1 + src/frontend/qt_sdl/InputConfigDialog.h | 4 ++++ 2 files changed, 5 insertions(+) (limited to 'src') diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index 585eadf..8ced842 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -903,6 +903,7 @@ bool LoadROM(const char* path, const char* sram, bool direct) { // TODO: streaming mode? for really big ROMs or systems with limited RAM // for now we're lazy + // also TODO: validate what we're loading!! FILE* f = Platform::OpenFile(path, "rb"); if (!f) diff --git a/src/frontend/qt_sdl/InputConfigDialog.h b/src/frontend/qt_sdl/InputConfigDialog.h index 82e37bc..de57414 100644 --- a/src/frontend/qt_sdl/InputConfigDialog.h +++ b/src/frontend/qt_sdl/InputConfigDialog.h @@ -80,6 +80,8 @@ protected: void keyPressEvent(QKeyEvent* event) override; void focusOutEvent(QFocusEvent* event) override; + bool focusNextPrevChild(bool next) override { return false; } + private slots: void onClick(); @@ -103,6 +105,8 @@ protected: void focusOutEvent(QFocusEvent* event) override; void timerEvent(QTimerEvent* event) override; + bool focusNextPrevChild(bool next) override { return false; } + private slots: void onClick(); -- cgit v1.2.3 From a2f9472e5dff77039d66783ffda9ee0fc2de77f8 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 20 May 2020 01:11:57 +0200 Subject: might help fix crashes on exit? --- src/frontend/qt_sdl/main.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 3b0b35d..70a6ec1 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -502,6 +502,7 @@ void MainWindowPanel::mouseMoveEvent(QMouseEvent* event) MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { setWindowTitle("melonDS " MELONDS_VERSION); + setAttribute(Qt::WA_DeleteOnClose); QMenuBar* menubar = new QMenuBar(); { -- cgit v1.2.3 From 4dae6d8928b57792c4ba746a7078c9f7dcac44af Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 20 May 2020 01:49:40 +0200 Subject: load shit from command line --- src/frontend/qt_sdl/main.cpp | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 70a6ec1..0cd9f70 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -1006,7 +1006,6 @@ int main(int argc, char** argv) emuThread->start(); emuThread->emuPause(true); - #if 0 if (argc > 1) { char* file = argv[1]; @@ -1014,32 +1013,25 @@ int main(int argc, char** argv) if (!strcasecmp(ext, "nds") || !strcasecmp(ext, "srl")) { - strncpy(ROMPath[0], file, 1023); - ROMPath[0][1023] = '\0'; + int res = Frontend::LoadROM(file, Frontend::ROMSlot_NDS); - //SetupSRAMPath(0); - - //if (NDS::LoadROM(ROMPath[0], SRAMPath[0], Config::DirectBoot)) - // Run(); - } - - if (argc > 2) - { - file = argv[2]; - ext = &file[strlen(file)-3]; - - if (!strcasecmp(ext, "gba")) + if (res == Frontend::Load_OK) { - strncpy(ROMPath[1], file, 1023); - ROMPath[1][1023] = '\0'; + if (argc > 2) + { + file = argv[2]; + ext = &file[strlen(file)-3]; - //SetupSRAMPath(1); + if (!strcasecmp(ext, "gba")) + { + Frontend::LoadROM(file, Frontend::ROMSlot_GBA); + } + } - //NDS::LoadGBAROM(ROMPath[1], SRAMPath[1]); + emuThread->emuRun(); } } } - #endif int ret = melon.exec(); -- cgit v1.2.3 From 5ed87a634afcff941aad2769496784249a568723 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 20 May 2020 02:36:48 +0200 Subject: add drag-drop support --- src/frontend/qt_sdl/main.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++ src/frontend/qt_sdl/main.h | 3 +++ 2 files changed, 65 insertions(+) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 0cd9f70..d38a73e 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -503,6 +504,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { setWindowTitle("melonDS " MELONDS_VERSION); setAttribute(Qt::WA_DeleteOnClose); + setAcceptDrops(true); QMenuBar* menubar = new QMenuBar(); { @@ -612,6 +614,66 @@ void MainWindow::keyReleaseEvent(QKeyEvent* event) } +void MainWindow::dragEnterEvent(QDragEnterEvent* event) +{ + if (!event->mimeData()->hasUrls()) return; + + QList urls = event->mimeData()->urls(); + if (urls.count() > 1) return; // not handling more than one file at once + + QString filename = urls.at(0).toLocalFile(); + QString ext = filename.right(3); + + if (ext == "nds" || ext == "srl" || (ext == "gba" && RunningSomething)) + event->acceptProposedAction(); +} + +void MainWindow::dropEvent(QDropEvent* event) +{ + if (!event->mimeData()->hasUrls()) return; + + QList urls = event->mimeData()->urls(); + if (urls.count() > 1) return; // not handling more than one file at once + + emuThread->emuPause(true); + + QString filename = urls.at(0).toLocalFile(); + QString ext = filename.right(3); + + char _filename[1024]; + strncpy(_filename, filename.toStdString().c_str(), 1023); _filename[1023] = '\0'; + + int slot; int res; + if (ext == "gba") + { + slot = 1; + res = Frontend::LoadROM(_filename, Frontend::ROMSlot_GBA); + } + else + { + slot = 0; + res = Frontend::LoadROM(_filename, Frontend::ROMSlot_NDS); + } + + if (res != Frontend::Load_OK) + { + QMessageBox::critical(this, + "melonDS", + loadErrorStr(res)); + emuThread->emuUnpause(); + } + else if (slot == 1) + { + // checkme + emuThread->emuUnpause(); + } + else + { + emuThread->emuRun(); + } +} + + QString MainWindow::loadErrorStr(int error) { switch (error) diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 5443780..83777bd 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -92,6 +92,9 @@ protected: void keyPressEvent(QKeyEvent* event) override; void keyReleaseEvent(QKeyEvent* event) override; + void dragEnterEvent(QDragEnterEvent* event) override; + void dropEvent(QDropEvent* event) override; + private slots: void onOpenFile(); void onBootFirmware(); -- cgit v1.2.3 From 700b1a8b9dfb3cb7502a2f0941cea0090ddbdf44 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 20 May 2020 03:01:09 +0200 Subject: add window icon --- melon.qrc | 6 ++++++ src/frontend/qt_sdl/CMakeLists.txt | 18 ++++++++++-------- src/frontend/qt_sdl/main.cpp | 1 + 3 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 melon.qrc (limited to 'src') diff --git a/melon.qrc b/melon.qrc new file mode 100644 index 0000000..b1ea364 --- /dev/null +++ b/melon.qrc @@ -0,0 +1,6 @@ + + + + icon/melon_32x32.png + + \ No newline at end of file diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index 42cf912..c3d0959 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -11,6 +11,8 @@ SET(SOURCES_QT_SDL ../Util_ROM.cpp ../Util_Audio.cpp ../FrontendUtil.h + + ../../../melon.qrc ) if (WIN32) @@ -66,12 +68,12 @@ elseif (WIN32) target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32 Qt5::Core Qt5::Gui Qt5::Widgets) endif () -install(FILES ../../net.kuribo64.melonDS.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) -install(FILES ../../icon/melon_16x16.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/16x16/apps RENAME net.kuribo64.melonDS.png) -install(FILES ../../icon/melon_32x32.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/32x32/apps RENAME net.kuribo64.melonDS.png) -install(FILES ../../icon/melon_48x48.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/48x48/apps RENAME net.kuribo64.melonDS.png) -install(FILES ../../icon/melon_64x64.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/64x64/apps RENAME net.kuribo64.melonDS.png) -install(FILES ../../icon/melon_128x128.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/128x128/apps RENAME net.kuribo64.melonDS.png) -install(FILES ../../icon/melon_256x256.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/256x256/apps RENAME net.kuribo64.melonDS.png) -install(FILES ../../romlist.bin DESTINATION ${CMAKE_INSTALL_PREFIX}/share/melonDS) +install(FILES ../../../net.kuribo64.melonDS.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) +install(FILES ../../../icon/melon_16x16.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/16x16/apps RENAME net.kuribo64.melonDS.png) +install(FILES ../../../icon/melon_32x32.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/32x32/apps RENAME net.kuribo64.melonDS.png) +install(FILES ../../../icon/melon_48x48.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/48x48/apps RENAME net.kuribo64.melonDS.png) +install(FILES ../../../icon/melon_64x64.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/64x64/apps RENAME net.kuribo64.melonDS.png) +install(FILES ../../../icon/melon_128x128.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/128x128/apps RENAME net.kuribo64.melonDS.png) +install(FILES ../../../icon/melon_256x256.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/256x256/apps RENAME net.kuribo64.melonDS.png) +install(FILES ../../../romlist.bin DESTINATION ${CMAKE_INSTALL_PREFIX}/share/melonDS) install(TARGETS melonDS RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index d38a73e..b81fc86 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -978,6 +978,7 @@ int main(int argc, char** argv) Platform::Init(argc, argv); QApplication melon(argc, argv); + melon.setWindowIcon(QIcon(":/melon-icon")); // http://stackoverflow.com/questions/14543333/joystick-wont-work-using-sdl SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); -- cgit v1.2.3 From 7be662b2dd1e7f99cf5a31c18c115c1106300964 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 20 May 2020 20:57:12 +0200 Subject: finish fleshing out the menus --- src/frontend/qt_sdl/main.cpp | 256 +++++++++++++++++++++++++++++++++++++------ src/frontend/qt_sdl/main.h | 41 ++++++- 2 files changed, 258 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index b81fc86..7ab7f0e 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -524,9 +524,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) for (int i = 1; i < 9; i++) { - char title[16]; - sprintf(title, "%d", i); - actSaveState[i] = submenu->addAction(title); + actSaveState[i] = submenu->addAction(QString("%1").arg(i)); actSaveState[i]->setShortcut(QKeySequence(Qt::ShiftModifier | (Qt::Key_F1+i-1))); actSaveState[i]->setData(QVariant(i)); connect(actSaveState[i], &QAction::triggered, this, &MainWindow::onSaveState); @@ -542,9 +540,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) for (int i = 1; i < 9; i++) { - char title[16]; - sprintf(title, "%d", i); - actLoadState[i] = submenu->addAction(title); + actLoadState[i] = submenu->addAction(QString("%1").arg(i)); actLoadState[i]->setShortcut(QKeySequence(Qt::Key_F1+i-1)); actLoadState[i]->setData(QVariant(i)); connect(actLoadState[i], &QAction::triggered, this, &MainWindow::onLoadState); @@ -586,6 +582,125 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) actInputConfig = menu->addAction("Input and hotkeys"); connect(actInputConfig, &QAction::triggered, this, &MainWindow::onOpenInputConfig); + + actVideoSettings = menu->addAction("Video settings"); + connect(actVideoSettings, &QAction::triggered, this, &MainWindow::onOpenVideoSettings); + + actAudioSettings = menu->addAction("Audio settings"); + connect(actAudioSettings, &QAction::triggered, this, &MainWindow::onOpenAudioSettings); + + actWifiSettings = menu->addAction("Wifi settings"); + connect(actWifiSettings, &QAction::triggered, this, &MainWindow::onOpenWifiSettings); + + { + QMenu* submenu = menu->addMenu("Savestate settings"); + + actSavestateSRAMReloc = submenu->addAction("Separate savefiles"); + actSavestateSRAMReloc->setCheckable(true); + connect(actSavestateSRAMReloc, &QAction::triggered, this, &MainWindow::onChangeSavestateSRAMReloc); + } + + menu->addSeparator(); + + { + QMenu* submenu = menu->addMenu("Screen size"); + + for (int i = 0; i < 4; i++) + { + int data = i+1; + actScreenSize[i] = submenu->addAction(QString("%1x").arg(data)); + actScreenSize[i]->setData(QVariant(data)); + connect(actScreenSize[i], &QAction::triggered, this, &MainWindow::onChangeScreenSize); + } + } + { + QMenu* submenu = menu->addMenu("Screen rotation"); + grpScreenRotation = new QActionGroup(submenu); + + for (int i = 0; i < 4; i++) + { + int data = i*90; + actScreenRotation[i] = submenu->addAction(QString("%1°").arg(data)); + actScreenRotation[i]->setActionGroup(grpScreenRotation); + actScreenRotation[i]->setData(QVariant(data)); + actScreenRotation[i]->setCheckable(true); + } + + connect(grpScreenRotation, &QActionGroup::triggered, this, &MainWindow::onChangeScreenRotation); + } + { + QMenu* submenu = menu->addMenu("Screen gap"); + grpScreenGap = new QActionGroup(submenu); + + const int screengap[] = {0, 1, 8, 64, 90, 128}; + + for (int i = 0; i < 6; i++) + { + int data = screengap[i]; + actScreenGap[i] = submenu->addAction(QString("%1 px").arg(data)); + actScreenGap[i]->setActionGroup(grpScreenGap); + actScreenGap[i]->setData(QVariant(data)); + actScreenGap[i]->setCheckable(true); + } + + connect(grpScreenGap, &QActionGroup::triggered, this, &MainWindow::onChangeScreenGap); + } + { + QMenu* submenu = menu->addMenu("Screen layout"); + grpScreenLayout = new QActionGroup(submenu); + + const char* screenlayout[] = {"Natural", "Vertical", "Horizontal"}; + + for (int i = 0; i < 3; i++) + { + actScreenLayout[i] = submenu->addAction(QString(screenlayout[i])); + actScreenLayout[i]->setActionGroup(grpScreenLayout); + actScreenLayout[i]->setData(QVariant(i)); + actScreenLayout[i]->setCheckable(true); + } + + connect(grpScreenLayout, &QActionGroup::triggered, this, &MainWindow::onChangeScreenLayout); + } + { + QMenu* submenu = menu->addMenu("Screen sizing"); + grpScreenSizing = new QActionGroup(submenu); + + const char* screensizing[] = {"Even", "Emphasize top", "Emphasize bottom", "Auto"}; + + for (int i = 0; i < 4; i++) + { + actScreenSizing[i] = submenu->addAction(QString(screensizing[i])); + actScreenSizing[i]->setActionGroup(grpScreenSizing); + actScreenSizing[i]->setData(QVariant(i)); + actScreenSizing[i]->setCheckable(true); + } + + connect(grpScreenSizing, &QActionGroup::triggered, this, &MainWindow::onChangeScreenSizing); + + submenu->addSeparator(); + + actIntegerScaling = submenu->addAction("Force integer scaling"); + actIntegerScaling->setCheckable(true); + connect(actIntegerScaling, &QAction::triggered, this, &MainWindow::onChangeIntegerScaling); + } + + actScreenFiltering = menu->addAction("Screen filtering"); + actScreenFiltering->setCheckable(true); + connect(actScreenFiltering, &QAction::triggered, this, &MainWindow::onChangeScreenFiltering); + + actShowOSD = menu->addAction("Show OSD"); + actShowOSD->setCheckable(true); + connect(actShowOSD, &QAction::triggered, this, &MainWindow::onChangeShowOSD); + + menu->addSeparator(); + + actLimitFramerate = menu->addAction("Limit framerate"); + actLimitFramerate->setCheckable(true); + connect(actLimitFramerate, &QAction::triggered, this, &MainWindow::onChangeLimitFramerate); + + actAudioSync = menu->addAction("Audio sync"); + actAudioSync->setCheckable(true); + connect(actAudioSync, &QAction::triggered, this, &MainWindow::onChangeAudioSync); } setMenuBar(menubar); @@ -756,7 +871,6 @@ void MainWindow::onOpenFile() void MainWindow::onBootFirmware() { - // TODO: ensure the firmware is actually bootable!! // TODO: check the whole GBA cart shito emuThread->emuPause(true); @@ -902,6 +1016,106 @@ void MainWindow::onStop() } +void MainWindow::onEmuPause() +{ + // +} + +void MainWindow::onEmuUnpause() +{ + // +} + + +void MainWindow::onOpenEmuSettings() +{ + EmuSettingsDialog::openDlg(this); +} + +void MainWindow::onOpenInputConfig() +{ + emuThread->emuPause(true); + + InputConfigDialog* dlg = InputConfigDialog::openDlg(this); + connect(dlg, &InputConfigDialog::finished, this, &MainWindow::onInputConfigFinished); +} + +void MainWindow::onInputConfigFinished(int res) +{ + emuThread->emuUnpause(); +} + +void MainWindow::onOpenVideoSettings() +{ + // +} + +void MainWindow::onOpenAudioSettings() +{ + // +} + +void MainWindow::onOpenWifiSettings() +{ + // +} + +void MainWindow::onChangeSavestateSRAMReloc(bool checked) +{ + // +} + +void MainWindow::onChangeScreenSize() +{ + // +} + +void MainWindow::onChangeScreenRotation(QAction* act) +{ + printf("DATABOTTE %p\n", act); +} + +void MainWindow::onChangeScreenGap(QAction* act) +{ + // +} + +void MainWindow::onChangeScreenLayout(QAction* act) +{ + // +} + +void MainWindow::onChangeScreenSizing(QAction* act) +{ + // +} + +void MainWindow::onChangeIntegerScaling(bool checked) +{ + // +} + +void MainWindow::onChangeScreenFiltering(bool checked) +{ + // +} + +void MainWindow::onChangeShowOSD(bool checked) +{ + // +} + +void MainWindow::onChangeLimitFramerate(bool checked) +{ + // +} + +void MainWindow::onChangeAudioSync(bool checked) +{ + // +} + + void MainWindow::onTitleUpdate(QString title) { setWindowTitle(title); @@ -938,34 +1152,6 @@ void MainWindow::onEmuStop() actStop->setEnabled(false); } -void MainWindow::onEmuPause() -{ - // -} - -void MainWindow::onEmuUnpause() -{ - // -} - - -void MainWindow::onOpenEmuSettings() -{ - EmuSettingsDialog::openDlg(this); -} - -void MainWindow::onOpenInputConfig() -{ - emuThread->emuPause(true); - - InputConfigDialog* dlg = InputConfigDialog::openDlg(this); - connect(dlg, &InputConfigDialog::finished, this, &MainWindow::onInputConfigFinished); -} - -void MainWindow::onInputConfigFinished(int res) -{ - emuThread->emuUnpause(); -} int main(int argc, char** argv) diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 83777bd..b478f4e 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -23,6 +23,7 @@ #include #include #include +#include class EmuThread : public QThread @@ -107,6 +108,24 @@ private slots: void onReset(); void onStop(); + void onOpenEmuSettings(); + void onOpenInputConfig(); + void onInputConfigFinished(int res); + void onOpenVideoSettings(); + void onOpenAudioSettings(); + void onOpenWifiSettings(); + void onChangeSavestateSRAMReloc(bool checked); + void onChangeScreenSize(); + void onChangeScreenRotation(QAction* act); + void onChangeScreenGap(QAction* act); + void onChangeScreenLayout(QAction* act); + void onChangeScreenSizing(QAction* act); + void onChangeIntegerScaling(bool checked); + void onChangeScreenFiltering(bool checked); + void onChangeShowOSD(bool checked); + void onChangeLimitFramerate(bool checked); + void onChangeAudioSync(bool checked); + void onTitleUpdate(QString title); void onEmuStart(); @@ -114,10 +133,6 @@ private slots: void onEmuPause(); void onEmuUnpause(); - void onOpenEmuSettings(); - void onOpenInputConfig(); - void onInputConfigFinished(int res); - private: QString loadErrorStr(int error); @@ -136,6 +151,24 @@ private: QAction* actEmuSettings; QAction* actInputConfig; + QAction* actVideoSettings; + QAction* actAudioSettings; + QAction* actWifiSettings; + QAction* actSavestateSRAMReloc; + QAction* actScreenSize[4]; + QActionGroup* grpScreenRotation; + QAction* actScreenRotation[4]; + QActionGroup* grpScreenGap; + QAction* actScreenGap[6]; + QActionGroup* grpScreenLayout; + QAction* actScreenLayout[3]; + QActionGroup* grpScreenSizing; + QAction* actScreenSizing[4]; + QAction* actIntegerScaling; + QAction* actScreenFiltering; + QAction* actShowOSD; + QAction* actLimitFramerate; + QAction* actAudioSync; }; #endif // MAIN_H -- cgit v1.2.3 From d761db005694899342beee101b12aaa6d6cbf711 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 20 May 2020 21:19:04 +0200 Subject: populate the menus with the config data --- src/frontend/qt_sdl/PlatformConfig.cpp | 4 ++-- src/frontend/qt_sdl/PlatformConfig.h | 2 +- src/frontend/qt_sdl/main.cpp | 33 +++++++++++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/PlatformConfig.cpp b/src/frontend/qt_sdl/PlatformConfig.cpp index 3b4b4aa..28c224d 100644 --- a/src/frontend/qt_sdl/PlatformConfig.cpp +++ b/src/frontend/qt_sdl/PlatformConfig.cpp @@ -40,11 +40,11 @@ int ScreenRotation; int ScreenGap; int ScreenLayout; int ScreenSizing; +int IntegerScaling; int ScreenFilter; int ScreenUseGL; int ScreenVSync; -int ScreenRatio; int LimitFPS; int AudioSync; @@ -121,11 +121,11 @@ ConfigEntry PlatformConfigFile[] = {"ScreenGap", 0, &ScreenGap, 0, NULL, 0}, {"ScreenLayout", 0, &ScreenLayout, 0, NULL, 0}, {"ScreenSizing", 0, &ScreenSizing, 0, NULL, 0}, + {"IntegerScaling", 0, &IntegerScaling, 0, NULL, 0}, {"ScreenFilter", 0, &ScreenFilter, 1, NULL, 0}, {"ScreenUseGL", 0, &ScreenUseGL, 1, NULL, 0}, {"ScreenVSync", 0, &ScreenVSync, 0, NULL, 0}, - {"ScreenRatio", 0, &ScreenRatio, 0, NULL, 0}, {"LimitFPS", 0, &LimitFPS, 0, NULL, 0}, {"AudioSync", 0, &AudioSync, 1, NULL, 0}, diff --git a/src/frontend/qt_sdl/PlatformConfig.h b/src/frontend/qt_sdl/PlatformConfig.h index 3704d14..539f9a4 100644 --- a/src/frontend/qt_sdl/PlatformConfig.h +++ b/src/frontend/qt_sdl/PlatformConfig.h @@ -53,11 +53,11 @@ extern int ScreenRotation; extern int ScreenGap; extern int ScreenLayout; extern int ScreenSizing; +extern int IntegerScaling; extern int ScreenFilter; extern int ScreenUseGL; extern int ScreenVSync; -extern int ScreenRatio; extern int LimitFPS; extern int AudioSync; diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 7ab7f0e..af95c49 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -707,6 +707,30 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) panel = new MainWindowPanel(this); setCentralWidget(panel); panel->setMinimumSize(256, 384); + + + actSavestateSRAMReloc->setChecked(Config::SavestateRelocSRAM != 0); + + actScreenRotation[Config::ScreenRotation]->setChecked(true); + + for (int i = 0; i < 6; i++) + { + if (actScreenGap[i]->data().toInt() == Config::ScreenGap) + { + actScreenGap[i]->setChecked(true); + break; + } + } + + actScreenLayout[Config::ScreenLayout]->setChecked(true); + actScreenSizing[Config::ScreenSizing]->setChecked(true); + actIntegerScaling->setChecked(Config::IntegerScaling != 0); + + actScreenFiltering->setChecked(Config::ScreenFilter != 0); + actShowOSD->setChecked(Config::ShowOSD != 0); + + actLimitFramerate->setChecked(Config::LimitFPS != 0); + actAudioSync->setChecked(Config::AudioSync != 0); } MainWindow::~MainWindow() @@ -1183,8 +1207,13 @@ int main(int argc, char** argv) Config::Load(); - if (Config::AudioVolume < 0) Config::AudioVolume = 0; - else if (Config::AudioVolume > 256) Config::AudioVolume = 256; +#define SANITIZE(var, min, max) { if (var < min) var = min; else if (var > max) var = max; } + SANITIZE(Config::AudioVolume, 0, 256); + SANITIZE(Config::ScreenRotation, 0, 3); + SANITIZE(Config::ScreenGap, 0, 500); + SANITIZE(Config::ScreenLayout, 0, 2); + SANITIZE(Config::ScreenSizing, 0, 3); +#undef SANITIZE // TODO: this should be checked before running anything #if 0 -- cgit v1.2.3 From 26dcc95c20b13eac0c2c55529507cf0ab881cb0a Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 20 May 2020 21:23:15 +0200 Subject: do the easy menus --- src/frontend/qt_sdl/main.cpp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index af95c49..35eac70 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -1040,17 +1040,6 @@ void MainWindow::onStop() } -void MainWindow::onEmuPause() -{ - // -} - -void MainWindow::onEmuUnpause() -{ - // -} - - void MainWindow::onOpenEmuSettings() { EmuSettingsDialog::openDlg(this); @@ -1086,7 +1075,7 @@ void MainWindow::onOpenWifiSettings() void MainWindow::onChangeSavestateSRAMReloc(bool checked) { - // + Config::SavestateRelocSRAM = checked?1:0; } void MainWindow::onChangeScreenSize() @@ -1096,7 +1085,7 @@ void MainWindow::onChangeScreenSize() void MainWindow::onChangeScreenRotation(QAction* act) { - printf("DATABOTTE %p\n", act); + // } void MainWindow::onChangeScreenGap(QAction* act) @@ -1121,22 +1110,22 @@ void MainWindow::onChangeIntegerScaling(bool checked) void MainWindow::onChangeScreenFiltering(bool checked) { - // + Config::ScreenFilter = checked?1:0; } void MainWindow::onChangeShowOSD(bool checked) { - // + Config::ShowOSD = checked?1:0; } void MainWindow::onChangeLimitFramerate(bool checked) { - // + Config::LimitFPS = checked?1:0; } void MainWindow::onChangeAudioSync(bool checked) { - // + Config::AudioSync = checked?1:0; } @@ -1176,6 +1165,16 @@ void MainWindow::onEmuStop() actStop->setEnabled(false); } +void MainWindow::onEmuPause() +{ + // +} + +void MainWindow::onEmuUnpause() +{ + // +} + int main(int argc, char** argv) -- cgit v1.2.3 From 2ebb21ce3bcf1a445dce7b13f64e44d6098a3acd Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 20 May 2020 22:22:22 +0200 Subject: hook up pause and reset, w/ relevant hotkeys --- src/frontend/FrontendUtil.h | 3 ++ src/frontend/Util_ROM.cpp | 47 +++++++++++++++++++++- src/frontend/qt_sdl/main.cpp | 93 +++++++++++++++++++++++--------------------- src/frontend/qt_sdl/main.h | 10 +++-- 4 files changed, 104 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/frontend/FrontendUtil.h b/src/frontend/FrontendUtil.h index f4f6850..d838b63 100644 --- a/src/frontend/FrontendUtil.h +++ b/src/frontend/FrontendUtil.h @@ -65,6 +65,9 @@ int LoadBIOS(); // note: loading a ROM to the NDS slot resets emulation int LoadROM(const char* file, int slot); +// reset execution of the current ROM +int Reset(); + // get the filename associated with the given savestate slot (1-8) void GetSavestateName(int slot, char* filename, int len); diff --git a/src/frontend/Util_ROM.cpp b/src/frontend/Util_ROM.cpp index 3200de4..e13eb2c 100644 --- a/src/frontend/Util_ROM.cpp +++ b/src/frontend/Util_ROM.cpp @@ -50,6 +50,11 @@ void Init_ROM() memset(PrevSRAMPath[ROMSlot_GBA], 0, 1024); } +// TODO: currently, when failing to load a ROM for whatever reason, we attempt +// to revert to the previous state and resume execution; this may not be a very +// good thing, depending on what state the core was left in. +// should we do a better state revert (via the savestate system)? completely stop? + void SetupSRAMPath(int slot) { strncpy(SRAMPath[slot], ROMPath[slot], 1023); @@ -184,7 +189,7 @@ int LoadROM(const char* file, int slot) } else if (slot == ROMSlot_GBA && NDS::LoadGBAROM(ROMPath[slot], SRAMPath[slot])) { - SavestateLoaded = false; + SavestateLoaded = false; // checkme?? strncpy(PrevSRAMPath[slot], SRAMPath[slot], 1024); // safety return Load_OK; @@ -197,6 +202,46 @@ int LoadROM(const char* file, int slot) } } +int Reset() +{ + int res; + bool directboot = Config::DirectBoot != 0; + + res = VerifyDSBIOS(); + if (res != Load_OK) return res; + + res = VerifyDSFirmware(); + if (res != Load_OK) + { + if (res == Load_FirmwareNotBootable) + directboot = true; + else + return res; + } + + SavestateLoaded = false; + + if (ROMPath[ROMSlot_NDS][0] == '\0') + { + NDS::LoadBIOS(); + } + else + { + SetupSRAMPath(0); + if (!NDS::LoadROM(ROMPath[ROMSlot_NDS], SRAMPath[ROMSlot_NDS], directboot)) + return Load_ROMLoadError; + } + + if (ROMPath[ROMSlot_GBA][0] != '\0') + { + SetupSRAMPath(1); + if (!NDS::LoadGBAROM(ROMPath[ROMSlot_GBA], SRAMPath[ROMSlot_GBA])) + return Load_ROMLoadError; + } + + return Load_OK; +} + // SAVESTATE TODO // * configurable paths. not everyone wants their ROM directory to be polluted, I guess. diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 35eac70..a73362d 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -113,6 +113,8 @@ EmuThread::EmuThread(QObject* parent) : QThread(parent) connect(this, SIGNAL(windowTitleChange(QString)), mainWindow, SLOT(onTitleUpdate(QString))); connect(this, SIGNAL(windowEmuStart()), mainWindow, SLOT(onEmuStart())); connect(this, SIGNAL(windowEmuStop()), mainWindow, SLOT(onEmuStop())); + connect(this, SIGNAL(windowEmuPause()), mainWindow->actPause, SLOT(trigger())); + connect(this, SIGNAL(windowEmuReset()), mainWindow->actReset, SLOT(trigger())); emit windowEmuStop(); } @@ -152,14 +154,10 @@ void EmuThread::run() { Input::Process(); - /*if (Input::HotkeyPressed(HK_FastForwardToggle)) - { - Config::LimitFPS = !Config::LimitFPS; - // TODO: reflect in UI! - }*/ + if (Input::HotkeyPressed(HK_FastForwardToggle)) emit windowLimitFPSChange(); - //if (Input::HotkeyPressed(HK_Pause)) uiQueueMain(TogglePause, NULL); - //if (Input::HotkeyPressed(HK_Reset)) uiQueueMain(Reset, NULL); + if (Input::HotkeyPressed(HK_Pause)) emit windowEmuPause(); + if (Input::HotkeyPressed(HK_Reset)) emit windowEmuReset(); if (GBACart::CartInserted && GBACart::HasSolarSensor) { @@ -318,18 +316,15 @@ void EmuThread::run() lastmeasuretick = lasttick; fpslimitcount = 0; - if (EmuRunning == 2) + /*if (Screen_UseGL) { - /*if (Screen_UseGL) - { - uiGLBegin(GLContext); - uiGLMakeContextCurrent(GLContext); - GLScreen_DrawScreen(); - uiGLEnd(GLContext); - } - uiAreaQueueRedrawAll(MainDrawArea);*/ - mainWindow->update(); + uiGLBegin(GLContext); + uiGLMakeContextCurrent(GLContext); + GLScreen_DrawScreen(); + uiGLEnd(GLContext); } + uiAreaQueueRedrawAll(MainDrawArea);*/ + mainWindow->update(); //if (Screen_UseGL) uiGLMakeContextCurrent(NULL); @@ -338,7 +333,7 @@ void EmuThread::run() sprintf(melontitle, "melonDS " MELONDS_VERSION); changeWindowTitle(melontitle); - SDL_Delay(100); + SDL_Delay(75); } } @@ -375,12 +370,11 @@ void EmuThread::emuRun() if (audioDevice) SDL_PauseAudioDevice(audioDevice, 0); } -void EmuThread::emuPause(bool refresh) +void EmuThread::emuPause() { - int status = refresh ? 2:3; PrevEmuStatus = EmuRunning; - EmuRunning = status; - while (EmuStatus != status); + EmuRunning = 2; + while (EmuStatus != 2); //emit windowEmuPause(); if (audioDevice) SDL_PauseAudioDevice(audioDevice, 1); @@ -774,7 +768,7 @@ void MainWindow::dropEvent(QDropEvent* event) QList urls = event->mimeData()->urls(); if (urls.count() > 1) return; // not handling more than one file at once - emuThread->emuPause(true); + emuThread->emuPause(); QString filename = urls.at(0).toLocalFile(); QString ext = filename.right(3); @@ -836,7 +830,7 @@ QString MainWindow::loadErrorStr(int error) void MainWindow::onOpenFile() { - emuThread->emuPause(true); + emuThread->emuPause(); QString filename = QFileDialog::getOpenFileName(this, "Open ROM", @@ -897,7 +891,7 @@ void MainWindow::onBootFirmware() { // TODO: check the whole GBA cart shito - emuThread->emuPause(true); + emuThread->emuPause(); int res = Frontend::LoadBIOS(); if (res != Frontend::Load_OK) @@ -917,7 +911,7 @@ void MainWindow::onSaveState() { int slot = ((QAction*)sender())->data().toInt(); - emuThread->emuPause(true); + emuThread->emuPause(); char filename[1024]; if (slot > 0) @@ -958,7 +952,7 @@ void MainWindow::onLoadState() { int slot = ((QAction*)sender())->data().toInt(); - emuThread->emuPause(true); + emuThread->emuPause(); char filename[1024]; if (slot > 0) @@ -1006,7 +1000,7 @@ void MainWindow::onLoadState() void MainWindow::onUndoStateLoad() { - emuThread->emuPause(true); + emuThread->emuPause(); Frontend::UndoStateLoad(); emuThread->emuUnpause(); } @@ -1019,9 +1013,11 @@ void MainWindow::onQuit() void MainWindow::onPause(bool checked) { - if (emuThread->emuIsRunning()) + if (!RunningSomething) return; + + if (checked) { - emuThread->emuPause(true); + emuThread->emuPause(); } else { @@ -1031,7 +1027,26 @@ void MainWindow::onPause(bool checked) void MainWindow::onReset() { - // + if (!RunningSomething) return; + + emuThread->emuPause(); + + actUndoStateLoad->setEnabled(false); + + int res = Frontend::Reset(); + if (res != Frontend::Load_OK) + { + QMessageBox::critical(this, + "melonDS", + loadErrorStr(res)); + emuThread->emuUnpause(); + } + else + { + // OSD::AddMessage(0, "Reset"); + + emuThread->emuRun(); + } } void MainWindow::onStop() @@ -1047,7 +1062,7 @@ void MainWindow::onOpenEmuSettings() void MainWindow::onOpenInputConfig() { - emuThread->emuPause(true); + emuThread->emuPause(); InputConfigDialog* dlg = InputConfigDialog::openDlg(this); connect(dlg, &InputConfigDialog::finished, this, &MainWindow::onInputConfigFinished); @@ -1143,7 +1158,7 @@ void MainWindow::onEmuStart() } actSaveState[0]->setEnabled(true); actLoadState[0]->setEnabled(true); - actUndoStateLoad->setEnabled(true); + actUndoStateLoad->setEnabled(false); actPause->setEnabled(true); actPause->setChecked(false); @@ -1165,16 +1180,6 @@ void MainWindow::onEmuStop() actStop->setEnabled(false); } -void MainWindow::onEmuPause() -{ - // -} - -void MainWindow::onEmuUnpause() -{ - // -} - int main(int argc, char** argv) @@ -1281,7 +1286,7 @@ int main(int argc, char** argv) emuThread = new EmuThread(); emuThread->start(); - emuThread->emuPause(true); + emuThread->emuPause(); if (argc > 1) { diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index b478f4e..22f045f 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -38,7 +38,7 @@ public: // to be called from the UI thread void emuRun(); - void emuPause(bool refresh); + void emuPause(); void emuUnpause(); void emuStop(); @@ -49,7 +49,10 @@ signals: void windowEmuStart(); void windowEmuStop(); - void windowPauseToggle(); + void windowEmuPause(); + void windowEmuReset(); + + void windowLimitFPSChange(); private: volatile int EmuStatus; @@ -130,14 +133,13 @@ private slots: void onEmuStart(); void onEmuStop(); - void onEmuPause(); - void onEmuUnpause(); private: QString loadErrorStr(int error); MainWindowPanel* panel; +public: QAction* actOpenROM; QAction* actBootFirmware; QAction* actSaveState[9]; -- cgit v1.2.3 From a9b275bc253510d77b8b6fcd80e6d24b56bc8680 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 20 May 2020 22:58:04 +0200 Subject: reimplement Stop --- src/SPU.cpp | 3 +++ src/frontend/FrontendUtil.h | 4 ++++ src/frontend/Util_ROM.cpp | 14 ++++++++++++++ src/frontend/qt_sdl/Platform.cpp | 4 ++-- src/frontend/qt_sdl/main.cpp | 37 +++++++++++++++++++++++++++++++------ 5 files changed, 54 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/SPU.cpp b/src/SPU.cpp index 710533e..1ebfd4c 100644 --- a/src/SPU.cpp +++ b/src/SPU.cpp @@ -116,6 +116,9 @@ void Reset() void Stop() { memset(OutputBuffer, 0, 2*OutputBufferSize*2); + + OutputReadOffset = 0; + OutputWriteOffset = 0; } void DoSavestate(Savestate* file) diff --git a/src/frontend/FrontendUtil.h b/src/frontend/FrontendUtil.h index d838b63..faa29de 100644 --- a/src/frontend/FrontendUtil.h +++ b/src/frontend/FrontendUtil.h @@ -65,6 +65,10 @@ int LoadBIOS(); // note: loading a ROM to the NDS slot resets emulation int LoadROM(const char* file, int slot); +// unload the ROM loaded in the specified cart slot +// simulating ejection of the cartridge +void UnloadROM(int slot); + // reset execution of the current ROM int Reset(); diff --git a/src/frontend/Util_ROM.cpp b/src/frontend/Util_ROM.cpp index e13eb2c..ec3186a 100644 --- a/src/frontend/Util_ROM.cpp +++ b/src/frontend/Util_ROM.cpp @@ -202,6 +202,20 @@ int LoadROM(const char* file, int slot) } } +void UnloadROM(int slot) +{ + if (slot == ROMSlot_NDS) + { + // TODO! + } + else if (slot == ROMSlot_GBA) + { + GBACart::Eject(); + } + + ROMPath[slot][0] = '\0'; +} + int Reset() { int res; diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index 6a5b466..dd838d7 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -55,7 +55,7 @@ char* EmuDirectory; -void Stop(bool internal); +void emuStop(); namespace Platform @@ -133,7 +133,7 @@ void DeInit() void StopEmu() { - //Stop(true); + emuStop(); } diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index a73362d..67272af 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -115,8 +115,6 @@ EmuThread::EmuThread(QObject* parent) : QThread(parent) connect(this, SIGNAL(windowEmuStop()), mainWindow, SLOT(onEmuStop())); connect(this, SIGNAL(windowEmuPause()), mainWindow->actPause, SLOT(trigger())); connect(this, SIGNAL(windowEmuReset()), mainWindow->actReset, SLOT(trigger())); - - emit windowEmuStop(); } void EmuThread::run() @@ -140,7 +138,6 @@ void EmuThread::run() } Input::Init(); - /*Touching = false;*/ u32 nframes = 0; u32 starttick = SDL_GetTicks(); @@ -376,7 +373,6 @@ void EmuThread::emuPause() EmuRunning = 2; while (EmuStatus != 2); - //emit windowEmuPause(); if (audioDevice) SDL_PauseAudioDevice(audioDevice, 1); } @@ -384,7 +380,6 @@ void EmuThread::emuUnpause() { EmuRunning = PrevEmuStatus; - //emit windowEmuUnpause(); if (audioDevice) SDL_PauseAudioDevice(audioDevice, 0); } @@ -703,6 +698,18 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) panel->setMinimumSize(256, 384); + for (int i = 0; i < 9; i++) + { + actSaveState[i]->setEnabled(false); + actLoadState[i]->setEnabled(false); + } + actUndoStateLoad->setEnabled(false); + + actPause->setEnabled(false); + actReset->setEnabled(false); + actStop->setEnabled(false); + + actSavestateSRAMReloc->setChecked(Config::SavestateRelocSRAM != 0); actScreenRotation[Config::ScreenRotation]->setChecked(true); @@ -1051,7 +1058,10 @@ void MainWindow::onReset() void MainWindow::onStop() { - // + if (!RunningSomething) return; + + emuThread->emuPause(); + NDS::Stop(); } @@ -1168,6 +1178,8 @@ void MainWindow::onEmuStart() void MainWindow::onEmuStop() { + emuThread->emuPause(); + for (int i = 0; i < 9; i++) { actSaveState[i]->setEnabled(false); @@ -1181,6 +1193,19 @@ void MainWindow::onEmuStop() } +void emuStop() +{ + RunningSomething = false; + + Frontend::UnloadROM(Frontend::ROMSlot_NDS); + Frontend::UnloadROM(Frontend::ROMSlot_GBA); + + emit emuThread->windowEmuStop(); + + //OSD::AddMessage(0xFFC040, "Shutdown"); +} + + int main(int argc, char** argv) { -- cgit v1.2.3 From 9e43c85b4d86cdb79242045c5fcf3929e3568322 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 20 May 2020 23:55:18 +0200 Subject: hook up microphone shit. I did my best. --- src/frontend/FrontendUtil.h | 11 +++ src/frontend/Util_Audio.cpp | 64 +++++++++++++++- src/frontend/qt_sdl/main.cpp | 177 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 247 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/frontend/FrontendUtil.h b/src/frontend/FrontendUtil.h index faa29de..6a6f8ea 100644 --- a/src/frontend/FrontendUtil.h +++ b/src/frontend/FrontendUtil.h @@ -101,6 +101,17 @@ int AudioOut_GetNumSamples(int outlen); // note: this assumes the output buffer is interleaved stereo void AudioOut_Resample(s16* inbuf, int inlen, s16* outbuf, int outlen); +// feed silence to the microphone input +void Mic_FeedSilence(); + +// feed random noise to the microphone input +void Mic_FeedNoise(); + +// feed an external buffer to the microphone input +// buffer should be mono +void Mic_FeedExternalBuffer(); +void Mic_SetExternalBuffer(s16* buffer, u32 len); + } #endif // FRONTENDUTIL_H diff --git a/src/frontend/Util_Audio.cpp b/src/frontend/Util_Audio.cpp index fe0ecab..2088efe 100644 --- a/src/frontend/Util_Audio.cpp +++ b/src/frontend/Util_Audio.cpp @@ -17,6 +17,7 @@ */ #include +#include #include #include @@ -26,7 +27,6 @@ #include "Platform.h" #include "NDS.h" -#include "GBACart.h" namespace Frontend @@ -35,13 +35,22 @@ namespace Frontend int AudioOut_Freq; float AudioOut_SampleFrac; +s16* MicBuffer; +u32 MicBufferLength; +u32 MicBufferReadPos; + void Init_Audio(int outputfreq) { AudioOut_Freq = outputfreq; AudioOut_SampleFrac = 0; + + MicBuffer = nullptr; + MicBufferLength = 0; + MicBufferReadPos = 0; } + int AudioOut_GetNumSamples(int outlen) { float f_len_in = (outlen * 32823.6328125) / (float)AudioOut_Freq; @@ -74,4 +83,57 @@ void AudioOut_Resample(s16* inbuf, int inlen, s16* outbuf, int outlen) } } + +void Mic_FeedSilence() +{ + MicBufferReadPos = 0; + NDS::MicInputFrame(NULL, 0); +} + +void Mic_FeedNoise() +{ + // note: DS games seem to expect very saturated 'blowing into mic' noise + + s16 tmp[735]; + + for (int i = 0; i < 735; i++) + { + int val = rand() >> 8; + if (val < -0x8000) val = -0x8000; + else if (val > 0x7FFF) val = 0x7FFF; + + tmp[i] = val; + } + + NDS::MicInputFrame(tmp, 735); +} + +void Mic_FeedExternalBuffer() +{ + if (!MicBuffer) return Mic_FeedSilence(); + + if ((MicBufferReadPos + 735) > MicBufferLength) + { + s16 tmp[735]; + u32 len1 = MicBufferLength - MicBufferReadPos; + memcpy(&tmp[0], &MicBuffer[MicBufferReadPos], len1*sizeof(s16)); + memcpy(&tmp[len1], &MicBuffer[0], (735 - len1)*sizeof(s16)); + + NDS::MicInputFrame(tmp, 735); + MicBufferReadPos = 735 - len1; + } + else + { + NDS::MicInputFrame(&MicBuffer[MicBufferReadPos], 735); + MicBufferReadPos += 735; + } +} + +void Mic_SetExternalBuffer(s16* buffer, u32 len) +{ + MicBuffer = buffer; + MicBufferLength = len; + MicBufferReadPos = 0; +} + } diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 67272af..1615fa3 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -66,6 +66,13 @@ int audioFreq; SDL_cond* audioSync; SDL_mutex* audioSyncLock; +SDL_AudioDeviceID micDevice; +s16 micExtBuffer[2048]; +u32 micExtBufferWritePos; + +u32 micWavLength; +s16* micWavBuffer; + void audioCallback(void* data, Uint8* stream, int len) { @@ -104,6 +111,133 @@ void audioCallback(void* data, Uint8* stream, int len) } +void micLoadWav(const char* name) +{ + SDL_AudioSpec format; + memset(&format, 0, sizeof(SDL_AudioSpec)); + + if (micWavBuffer) delete[] micWavBuffer; + micWavBuffer = nullptr; + micWavLength = 0; + + u8* buf; + u32 len; + if (!SDL_LoadWAV(name, &format, &buf, &len)) + return; + + const u64 dstfreq = 44100; + + if (format.format == AUDIO_S16 || format.format == AUDIO_U16) + { + int srcinc = format.channels; + len /= (2 * srcinc); + + micWavLength = (len * dstfreq) / format.freq; + if (micWavLength < 735) micWavLength = 735; + micWavBuffer = new s16[micWavLength]; + + float res_incr = len / (float)micWavLength; + float res_timer = 0; + int res_pos = 0; + + for (int i = 0; i < micWavLength; i++) + { + u16 val = ((u16*)buf)[res_pos]; + if (SDL_AUDIO_ISUNSIGNED(format.format)) val ^= 0x8000; + + micWavBuffer[i] = val; + + res_timer += res_incr; + while (res_timer >= 1.0) + { + res_timer -= 1.0; + res_pos += srcinc; + } + } + } + else if (format.format == AUDIO_S8 || format.format == AUDIO_U8) + { + int srcinc = format.channels; + len /= srcinc; + + micWavLength = (len * dstfreq) / format.freq; + if (micWavLength < 735) micWavLength = 735; + micWavBuffer = new s16[micWavLength]; + + float res_incr = len / (float)micWavLength; + float res_timer = 0; + int res_pos = 0; + + for (int i = 0; i < micWavLength; i++) + { + u16 val = buf[res_pos] << 8; + if (SDL_AUDIO_ISUNSIGNED(format.format)) val ^= 0x8000; + + micWavBuffer[i] = val; + + res_timer += res_incr; + while (res_timer >= 1.0) + { + res_timer -= 1.0; + res_pos += srcinc; + } + } + } + else + printf("bad WAV format %08X\n", format.format); + + SDL_FreeWAV(buf); +} + +void micCallback(void* data, Uint8* stream, int len) +{ + s16* input = (s16*)stream; + len /= sizeof(s16); + + int maxlen = sizeof(micExtBuffer) / sizeof(s16); + + if ((micExtBufferWritePos + len) > maxlen) + { + u32 len1 = maxlen - micExtBufferWritePos; + memcpy(&micExtBuffer[micExtBufferWritePos], &input[0], len1*sizeof(s16)); + memcpy(&micExtBuffer[0], &input[len1], (len - len1)*sizeof(s16)); + micExtBufferWritePos = len - len1; + } + else + { + memcpy(&micExtBuffer[micExtBufferWritePos], input, len*sizeof(s16)); + micExtBufferWritePos += len; + } +} + +void micProcess() +{ + int type = Config::MicInputType; + bool cmd = Input::HotkeyDown(HK_Mic); + + if (type != 1 && !cmd) + { + type = 0; + } + + switch (type) + { + case 0: // no mic + Frontend::Mic_FeedSilence(); + break; + + case 1: // host mic + case 3: // WAV + Frontend::Mic_FeedExternalBuffer(); + break; + + case 2: // white noise + Frontend::Mic_FeedNoise(); + break; + } +} + + EmuThread::EmuThread(QObject* parent) : QThread(parent) { EmuStatus = 0; @@ -189,9 +323,9 @@ void EmuThread::run() } // microphone input - /*FeedMicInput(); + micProcess(); - if (Screen_UseGL) + /*if (Screen_UseGL) { uiGLBegin(GLContext); uiGLMakeContextCurrent(GLContext); @@ -365,6 +499,7 @@ void EmuThread::emuRun() // checkme emit windowEmuStart(); if (audioDevice) SDL_PauseAudioDevice(audioDevice, 0); + if (micDevice) SDL_PauseAudioDevice(micDevice, 0); } void EmuThread::emuPause() @@ -374,6 +509,7 @@ void EmuThread::emuPause() while (EmuStatus != 2); if (audioDevice) SDL_PauseAudioDevice(audioDevice, 1); + if (micDevice) SDL_PauseAudioDevice(micDevice, 1); } void EmuThread::emuUnpause() @@ -381,6 +517,7 @@ void EmuThread::emuUnpause() EmuRunning = PrevEmuStatus; if (audioDevice) SDL_PauseAudioDevice(audioDevice, 0); + if (micDevice) SDL_PauseAudioDevice(micDevice, 0); } void EmuThread::emuStop() @@ -388,6 +525,7 @@ void EmuThread::emuStop() EmuRunning = 0; if (audioDevice) SDL_PauseAudioDevice(audioDevice, 1); + if (micDevice) SDL_PauseAudioDevice(micDevice, 1); } bool EmuThread::emuIsRunning() @@ -1300,9 +1438,40 @@ int main(int argc, char** argv) SDL_PauseAudioDevice(audioDevice, 1); } + memset(&whatIwant, 0, sizeof(SDL_AudioSpec)); + whatIwant.freq = 44100; + whatIwant.format = AUDIO_S16LSB; + whatIwant.channels = 1; + whatIwant.samples = 1024; + whatIwant.callback = micCallback; + micDevice = SDL_OpenAudioDevice(NULL, 1, &whatIwant, &whatIget, 0); + if (!micDevice) + { + printf("Mic init failed: %s\n", SDL_GetError()); + } + else + { + SDL_PauseAudioDevice(micDevice, 1); + } + + + memset(micExtBuffer, 0, sizeof(micExtBuffer)); + micExtBufferWritePos = 0; + micWavBuffer = nullptr; + Frontend::Init_ROM(); Frontend::Init_Audio(audioFreq); + if (Config::MicInputType == 1) + { + Frontend::Mic_SetExternalBuffer(micExtBuffer, sizeof(micExtBuffer)/sizeof(s16)); + } + else if (Config::MicInputType == 3) + { + micLoadWav(Config::MicWavPath); + Frontend::Mic_SetExternalBuffer(micWavBuffer, micWavLength); + } + Input::JoystickID = Config::JoystickID; Input::OpenJoystick(); @@ -1349,12 +1518,12 @@ int main(int argc, char** argv) Input::CloseJoystick(); if (audioDevice) SDL_CloseAudioDevice(audioDevice); - //if (MicDevice) SDL_CloseAudioDevice(MicDevice); + if (micDevice) SDL_CloseAudioDevice(micDevice); SDL_DestroyCond(audioSync); SDL_DestroyMutex(audioSyncLock); - //if (MicWavBuffer) delete[] MicWavBuffer; + if (micWavBuffer) delete[] micWavBuffer; Config::Save(); -- cgit v1.2.3 From 108647e03320788729bcfa229d81c0f7678fe1fb Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 21 May 2020 01:39:41 +0200 Subject: * add audio settings dialog * attempt at betterer mic noise that doesn't work worth a damn --- src/frontend/Util_Audio.cpp | 8 +- src/frontend/qt_sdl/AudioSettingsDialog.cpp | 103 ++++++++++++++++++ src/frontend/qt_sdl/AudioSettingsDialog.h | 69 ++++++++++++ src/frontend/qt_sdl/AudioSettingsDialog.ui | 162 ++++++++++++++++++++++++++++ src/frontend/qt_sdl/CMakeLists.txt | 1 + src/frontend/qt_sdl/EmuSettingsDialog.cpp | 1 + src/frontend/qt_sdl/EmuSettingsDialog.ui | 15 +-- src/frontend/qt_sdl/main.cpp | 24 ++++- src/frontend/qt_sdl/main.h | 1 + 9 files changed, 366 insertions(+), 18 deletions(-) create mode 100644 src/frontend/qt_sdl/AudioSettingsDialog.cpp create mode 100644 src/frontend/qt_sdl/AudioSettingsDialog.h create mode 100644 src/frontend/qt_sdl/AudioSettingsDialog.ui (limited to 'src') diff --git a/src/frontend/Util_Audio.cpp b/src/frontend/Util_Audio.cpp index 2088efe..3f03810 100644 --- a/src/frontend/Util_Audio.cpp +++ b/src/frontend/Util_Audio.cpp @@ -93,14 +93,16 @@ void Mic_FeedSilence() void Mic_FeedNoise() { // note: DS games seem to expect very saturated 'blowing into mic' noise + s16 noisesample[8] = {-0x8000, -0x8000, 0x7FFF, -0x8000, 0x7FFF, 0x7FFF, -0x8000, 0x7FFF}; + int j = 0; s16 tmp[735]; for (int i = 0; i < 735; i++) { - int val = rand() >> 8; - if (val < -0x8000) val = -0x8000; - else if (val > 0x7FFF) val = 0x7FFF; + int val = noisesample[j]; + j++; + if (j >= 8) j = rand() & 7; tmp[i] = val; } diff --git a/src/frontend/qt_sdl/AudioSettingsDialog.cpp b/src/frontend/qt_sdl/AudioSettingsDialog.cpp new file mode 100644 index 0000000..2ff5307 --- /dev/null +++ b/src/frontend/qt_sdl/AudioSettingsDialog.cpp @@ -0,0 +1,103 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include +#include + +#include "types.h" +#include "Platform.h" +#include "Config.h" +#include "PlatformConfig.h" + +#include "AudioSettingsDialog.h" +#include "ui_AudioSettingsDialog.h" + + +AudioSettingsDialog* AudioSettingsDialog::currentDlg = nullptr; + +extern char* EmuDirectory; + + +AudioSettingsDialog::AudioSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::AudioSettingsDialog) +{ + ui->setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + + oldVolume = Config::AudioVolume; + + ui->slVolume->setValue(Config::AudioVolume); + + grpMicMode = new QButtonGroup(this); + grpMicMode->addButton(ui->rbMicNone, 0); + grpMicMode->addButton(ui->rbMicExternal, 1); + grpMicMode->addButton(ui->rbMicNoise, 2); + grpMicMode->addButton(ui->rbMicWav, 3); + connect(grpMicMode, SIGNAL(buttonClicked(int)), this, SLOT(onChangeMicMode(int))); + grpMicMode->button(Config::MicInputType)->setChecked(true); + + ui->txtMicWavPath->setText(Config::MicWavPath); + + bool iswav = (Config::MicInputType == 3); + ui->txtMicWavPath->setEnabled(iswav); + ui->btnMicWavBrowse->setEnabled(iswav); +} + +AudioSettingsDialog::~AudioSettingsDialog() +{ + delete ui; +} + +void AudioSettingsDialog::on_AudioSettingsDialog_accepted() +{ + Config::MicInputType = grpMicMode->checkedId(); + strncpy(Config::MicWavPath, ui->txtMicWavPath->text().toStdString().c_str(), 1023); Config::MicWavPath[1023] = '\0'; + Config::Save(); + + closeDlg(); +} + +void AudioSettingsDialog::on_AudioSettingsDialog_rejected() +{ + Config::AudioVolume = oldVolume; + + closeDlg(); +} + +void AudioSettingsDialog::on_slVolume_valueChanged(int val) +{ + Config::AudioVolume = val; +} + +void AudioSettingsDialog::onChangeMicMode(int mode) +{ + bool iswav = (mode == 3); + ui->txtMicWavPath->setEnabled(iswav); + ui->btnMicWavBrowse->setEnabled(iswav); +} + +void AudioSettingsDialog::on_btnMicWavBrowse_clicked() +{ + QString file = QFileDialog::getOpenFileName(this, + "Select WAV file...", + EmuDirectory, + "WAV files (*.wav);;Any file (*.*)"); + + if (file.isEmpty()) return; + + ui->txtMicWavPath->setText(file); +} diff --git a/src/frontend/qt_sdl/AudioSettingsDialog.h b/src/frontend/qt_sdl/AudioSettingsDialog.h new file mode 100644 index 0000000..3bafa30 --- /dev/null +++ b/src/frontend/qt_sdl/AudioSettingsDialog.h @@ -0,0 +1,69 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef AUDIOSETTINGSDIALOG_H +#define AUDIOSETTINGSDIALOG_H + +#include +#include + +namespace Ui { class AudioSettingsDialog; } +class AudioSettingsDialog; + +class AudioSettingsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit AudioSettingsDialog(QWidget* parent); + ~AudioSettingsDialog(); + + static AudioSettingsDialog* currentDlg; + static AudioSettingsDialog* openDlg(QWidget* parent) + { + if (currentDlg) + { + currentDlg->activateWindow(); + return currentDlg; + } + + currentDlg = new AudioSettingsDialog(parent); + currentDlg->show(); + return currentDlg; + } + static void closeDlg() + { + currentDlg = nullptr; + } + +private slots: + void on_AudioSettingsDialog_accepted(); + void on_AudioSettingsDialog_rejected(); + + void on_slVolume_valueChanged(int val); + void onChangeMicMode(int mode); + void on_btnMicWavBrowse_clicked(); + +private: + Ui::AudioSettingsDialog* ui; + + int oldVolume; + QButtonGroup* grpMicMode; +}; + +#endif // AUDIOSETTINGSDIALOG_H diff --git a/src/frontend/qt_sdl/AudioSettingsDialog.ui b/src/frontend/qt_sdl/AudioSettingsDialog.ui new file mode 100644 index 0000000..b6c215e --- /dev/null +++ b/src/frontend/qt_sdl/AudioSettingsDialog.ui @@ -0,0 +1,162 @@ + + + AudioSettingsDialog + + + + 0 + 0 + 482 + 230 + + + + Audio settings - melonDS + + + + + + Audio output + + + + + + Volume: + + + + + + + <html><head/><body><p>Controls the volume of the audio output.</p></body></html> + + + 256 + + + 16 + + + Qt::Horizontal + + + + + + + + + + Microphone input + + + + + + + 290 + 0 + + + + + + + + <html><head/><body><p>Forward a WAV file to the emulated microphone.</p></body></html> + + + WAV file: + + + + + + + Browse... + + + + + + + <html><head/><body><p>Input from an external microphone, if available, will be forwarded to the emulated microphone.</p></body></html> + + + External microphone + + + + + + + <html><head/><body><p>Noise will be forwarded to the emulated microphone, simulating blowing into the microphone.</p></body></html> + + + White noise + + + + + + + <html><head/><body><p>No microphone input.</p></body></html> + + + None + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + AudioSettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AudioSettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index c3d0959..caa78e9 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -4,6 +4,7 @@ SET(SOURCES_QT_SDL main.cpp EmuSettingsDialog.cpp InputConfigDialog.cpp + AudioSettingsDialog.cpp Input.cpp Platform.cpp PlatformConfig.cpp diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.cpp b/src/frontend/qt_sdl/EmuSettingsDialog.cpp index 6264d91..5c2efc0 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.cpp +++ b/src/frontend/qt_sdl/EmuSettingsDialog.cpp @@ -100,6 +100,7 @@ void EmuSettingsDialog::on_EmuSettingsDialog_accepted() strncpy(Config::BIOS7Path, ui->txtBIOS7Path->text().toStdString().c_str(), 1023); Config::BIOS7Path[1023] = '\0'; strncpy(Config::FirmwarePath, ui->txtFirmwarePath->text().toStdString().c_str(), 1023); Config::FirmwarePath[1023] = '\0'; Config::DirectBoot = ui->chkDirectBoot->isChecked() ? 1:0; + Config::Save(); closeDlg(); } diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.ui b/src/frontend/qt_sdl/EmuSettingsDialog.ui index e4deaba..c70c3a2 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.ui +++ b/src/frontend/qt_sdl/EmuSettingsDialog.ui @@ -7,7 +7,7 @@ 0 0 490 - 243 + 217 @@ -138,19 +138,6 @@ - - - - Qt::Vertical - - - - 20 - 20 - - - - diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 1615fa3..245324f 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -36,6 +36,7 @@ #include "Input.h" #include "EmuSettingsDialog.h" #include "InputConfigDialog.h" +#include "AudioSettingsDialog.h" #include "types.h" #include "version.h" @@ -1228,7 +1229,27 @@ void MainWindow::onOpenVideoSettings() void MainWindow::onOpenAudioSettings() { - // + AudioSettingsDialog* dlg = AudioSettingsDialog::openDlg(this); + connect(dlg, &AudioSettingsDialog::finished, this, &MainWindow::onAudioSettingsFinished); +} + +void MainWindow::onAudioSettingsFinished(int res) +{ + if (Config::MicInputType == 3) + { + micLoadWav(Config::MicWavPath); + Frontend::Mic_SetExternalBuffer(micWavBuffer, micWavLength); + } + else + { + delete[] micWavBuffer; + micWavBuffer = nullptr; + + if (Config::MicInputType == 1) + Frontend::Mic_SetExternalBuffer(micExtBuffer, sizeof(micExtBuffer)/sizeof(s16)); + else + Frontend::Mic_SetExternalBuffer(NULL, 0); + } } void MainWindow::onOpenWifiSettings() @@ -1376,6 +1397,7 @@ int main(int argc, char** argv) #define SANITIZE(var, min, max) { if (var < min) var = min; else if (var > max) var = max; } SANITIZE(Config::AudioVolume, 0, 256); + SANITIZE(Config::MicInputType, 0, 3); SANITIZE(Config::ScreenRotation, 0, 3); SANITIZE(Config::ScreenGap, 0, 500); SANITIZE(Config::ScreenLayout, 0, 2); diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 22f045f..7051a08 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -116,6 +116,7 @@ private slots: void onInputConfigFinished(int res); void onOpenVideoSettings(); void onOpenAudioSettings(); + void onAudioSettingsFinished(int res); void onOpenWifiSettings(); void onChangeSavestateSRAMReloc(bool checked); void onChangeScreenSize(); -- cgit v1.2.3 From f79583bf1697b4c6a5b40c1e727e2a40c789757d Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 21 May 2020 02:33:48 +0200 Subject: add actual blow-into-mic sample that actually works --- src/frontend/Util_Audio.cpp | 15 +- src/frontend/mic_blow.h | 5539 ++++++++++++++++++++++++++++ src/frontend/qt_sdl/AudioSettingsDialog.ui | 2 +- src/frontend/qt_sdl/CMakeLists.txt | 1 + 4 files changed, 5548 insertions(+), 9 deletions(-) create mode 100644 src/frontend/mic_blow.h (limited to 'src') diff --git a/src/frontend/Util_Audio.cpp b/src/frontend/Util_Audio.cpp index 3f03810..d4c3333 100644 --- a/src/frontend/Util_Audio.cpp +++ b/src/frontend/Util_Audio.cpp @@ -28,6 +28,8 @@ #include "NDS.h" +#include "mic_blow.h" + namespace Frontend { @@ -92,19 +94,16 @@ void Mic_FeedSilence() void Mic_FeedNoise() { - // note: DS games seem to expect very saturated 'blowing into mic' noise - s16 noisesample[8] = {-0x8000, -0x8000, 0x7FFF, -0x8000, 0x7FFF, 0x7FFF, -0x8000, 0x7FFF}; - int j = 0; + int sample_len = sizeof(mic_blow) / sizeof(u16); + static int sample_pos = 0; s16 tmp[735]; for (int i = 0; i < 735; i++) { - int val = noisesample[j]; - j++; - if (j >= 8) j = rand() & 7; - - tmp[i] = val; + tmp[i] = mic_blow[sample_pos]; + sample_pos++; + if (sample_pos >= sample_len) sample_pos = 0; } NDS::MicInputFrame(tmp, 735); diff --git a/src/frontend/mic_blow.h b/src/frontend/mic_blow.h new file mode 100644 index 0000000..cee92fe --- /dev/null +++ b/src/frontend/mic_blow.h @@ -0,0 +1,5539 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef MIC_BLOW_H +#define MIC_BLOW_H + +const u16 mic_blow[] = +{ + 0x1840, 0x1EF0, 0x24F0, 0x2A60, 0x2F60, 0x33F0, 0x3800, 0x3BC0, 0x3FB0, 0x43E0, 0x48A0, 0x4EC0, 0x5490, 0x5A30, 0x6040, 0x6490, + 0x6960, 0x6E40, 0x7220, 0x76B0, 0x79B0, 0x7CA0, 0x7E60, 0x7F00, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7EC0, 0x7F30, + 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7EE0, 0x7F30, 0x7EF0, 0x7F20, 0x7EF0, 0x7F10, 0x7F60, 0x7F00, + 0x7F10, 0x7F10, 0x7F20, 0x7F60, 0x7EF0, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F50, 0x7EF0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F60, 0x7EE0, 0x7E90, + 0x7F10, 0x7F00, 0x7EF0, 0x7EF0, 0x7EA0, 0x7EE0, 0x7EF0, 0x7F30, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F10, 0x7EB0, 0x7F20, + 0x7EE0, 0x7EF0, 0x7F30, 0x7F20, 0x7F60, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F80, 0x7EB0, 0x7220, 0x66D0, 0x5BD0, 0x5190, 0x4680, + 0x3D70, 0x3470, 0x2C70, 0x2640, 0x2090, 0x1D00, 0x1A40, 0x1910, 0x1810, 0x17A0, 0x1860, 0x19C0, 0x1C10, 0x1F30, 0x22E0, 0x2930, + 0x2FA0, 0x3720, 0x3EC0, 0x46B0, 0x4E80, 0x5660, 0x5ED0, 0x6710, 0x7000, 0x7720, 0x7D10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, + 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, + 0x7F20, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7E80, 0x7D30, 0x7C00, 0x7AA0, 0x7890, + 0x7610, 0x73F0, 0x71A0, 0x6F60, 0x6CD0, 0x6970, 0x6670, 0x6310, 0x5F90, 0x5D10, 0x5A20, 0x5720, 0x5410, 0x4FB0, 0x4AC0, 0x4670, + 0x4250, 0x3E40, 0x39F0, 0x3540, 0x2FB0, 0x28E0, 0x2260, 0x1BB0, 0x15F0, 0x10B0, 0x0C60, 0x08B0, 0x05B0, 0x0300, 0x00F0, 0xFEB0, + 0xFC00, 0xF8E0, 0xF570, 0xF170, 0xED60, 0xE8E0, 0xE4C0, 0xDFF0, 0xDB90, 0xD650, 0xD090, 0xCAB0, 0xC570, 0xC0C0, 0xBD00, 0xBA30, + 0xB790, 0xB4C0, 0xB1B0, 0xAF40, 0xAD00, 0xAC10, 0xAB70, 0xAA70, 0xA9C0, 0xA800, 0xA640, 0xA520, 0xA420, 0xA2C0, 0xA1D0, 0xA000, + 0x9E60, 0x9CF0, 0x9B80, 0x9A10, 0x97F0, 0x9550, 0x9340, 0x9170, 0x8F80, 0x8DA0, 0x8C40, 0x8B10, 0x89E0, 0x8890, 0x87B0, 0x86F0, + 0x8660, 0x8640, 0x8600, 0x85F0, 0x85D0, 0x85B0, 0x8580, 0x8560, 0x8550, 0x8550, 0x8540, 0x8530, 0x8530, 0x8520, 0x8510, 0x8510, + 0x8500, 0x8500, 0x8500, 0x8500, 0x84F0, 0x84F0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x8510, 0x84E0, 0x84E0, 0x8500, 0x84F0, + 0x84F0, 0x84C0, 0x84F0, 0x8500, 0x8500, 0x8510, 0x8520, 0x8530, 0x8550, 0x8580, 0x8590, 0x85D0, 0x8610, 0x8690, 0x8730, 0x8820, + 0x8970, 0x8BC0, 0x8E40, 0x9190, 0x9560, 0x9990, 0x9E30, 0xA1E0, 0xA540, 0xA890, 0xAAB0, 0xADB0, 0xB0E0, 0xB370, 0xB5E0, 0xB860, + 0xBB30, 0xBEB0, 0xC230, 0xC5E0, 0xC930, 0xCD20, 0xCFA0, 0xD130, 0xD310, 0xD530, 0xD8C0, 0xDC80, 0xE0D0, 0xE520, 0xE880, 0xEBF0, + 0xEEB0, 0xF160, 0xF460, 0xF6F0, 0xF970, 0xFBC0, 0xFE90, 0x0250, 0x04C0, 0x06E0, 0x0910, 0x0AB0, 0x0C90, 0x0DA0, 0x0F80, 0x1210, + 0x1400, 0x1550, 0x1680, 0x1770, 0x18A0, 0x1A10, 0x1C90, 0x1E80, 0x2060, 0x22B0, 0x2360, 0x2540, 0x2600, 0x26C0, 0x2920, 0x2B40, + 0x2D50, 0x2EF0, 0x30C0, 0x31D0, 0x3210, 0x3330, 0x33E0, 0x35C0, 0x36F0, 0x37D0, 0x38A0, 0x3990, 0x39F0, 0x39C0, 0x39C0, 0x3950, + 0x3820, 0x3730, 0x36A0, 0x3610, 0x35A0, 0x3490, 0x3270, 0x30B0, 0x2E20, 0x2C60, 0x2A90, 0x2890, 0x2760, 0x2490, 0x2330, 0x20C0, + 0x1F20, 0x1E10, 0x1D30, 0x1D70, 0x1D20, 0x1D10, 0x1E40, 0x1F00, 0x2010, 0x2110, 0x21B0, 0x23C0, 0x25E0, 0x2810, 0x2A20, 0x2C10, + 0x2DF0, 0x2E20, 0x2E60, 0x2F10, 0x2FB0, 0x30F0, 0x3200, 0x31F0, 0x31B0, 0x3070, 0x2F50, 0x2DC0, 0x2BD0, 0x29F0, 0x27C0, 0x2650, + 0x2470, 0x2290, 0x2090, 0x1DF0, 0x1B60, 0x18C0, 0x1670, 0x1490, 0x1220, 0x10E0, 0x0EA0, 0x0D60, 0x0C90, 0x0B10, 0x09B0, 0x0860, + 0x06C0, 0x0630, 0x0520, 0x0520, 0x04F0, 0x0430, 0x0340, 0x0180, 0x0150, 0x0100, 0xFFE0, 0x00A0, 0xFFC0, 0xFFF0, 0xFFF0, 0xFFF0, + 0x00B0, 0x00C0, 0x0150, 0x0190, 0x00D0, 0x0170, 0x01F0, 0x0330, 0x03F0, 0x0480, 0x0510, 0x0580, 0x0570, 0x05C0, 0x0630, 0x06E0, + 0x0810, 0x0910, 0x0A50, 0x0B20, 0x0BD0, 0x0CD0, 0x0E70, 0x1070, 0x1280, 0x1520, 0x17B0, 0x18F0, 0x2120, 0x2240, 0x2340, 0x23B0, + 0x2560, 0x2640, 0x27F0, 0x29F0, 0x2AB0, 0x2BC0, 0x2C50, 0x2CE0, 0x2E20, 0x2F50, 0x3150, 0x3360, 0x33E0, 0x3510, 0x3500, 0x3520, + 0x34F0, 0x33B0, 0x3320, 0x3200, 0x3210, 0x3150, 0x30E0, 0x3010, 0x2ED0, 0x2DE0, 0x2D20, 0x2AF0, 0x2A50, 0x28D0, 0x2760, 0x26C0, + 0x2560, 0x2540, 0x2460, 0x2350, 0x2290, 0x2170, 0x21A0, 0x2110, 0x2090, 0x2000, 0x1F50, 0x1F80, 0x1F40, 0x21A0, 0x21D0, 0x21B0, + 0x21E0, 0x21C0, 0x2260, 0x2370, 0x24F0, 0x2630, 0x2700, 0x2760, 0x2810, 0x2930, 0x2AE0, 0x2C40, 0x2D20, 0x2D80, 0x2DF0, 0x2F00, + 0x30A0, 0x31F0, 0x3510, 0x36B0, 0x3950, 0x3AB0, 0x3B70, 0x3DA0, 0x3F90, 0x4310, 0x4640, 0x4840, 0x4B10, 0x4D20, 0x4FE0, 0x5270, + 0x5590, 0x5900, 0x5C00, 0x5ED0, 0x6110, 0x63A0, 0x66F0, 0x69A0, 0x6CA0, 0x6F40, 0x7090, 0x7290, 0x7440, 0x75F0, 0x7800, 0x79C0, + 0x7BA0, 0x7C90, 0x7D90, 0x7E00, 0x7E70, 0x7ED0, 0x7EF0, 0x7F70, 0x7EF0, 0x7F10, 0x7F00, 0x7F00, 0x7F70, 0x7F10, 0x7EB0, 0x7EA0, + 0x7E40, 0x7C70, 0x7AA0, 0x7890, 0x76F0, 0x74E0, 0x71F0, 0x6EC0, 0x6A00, 0x6630, 0x61E0, 0x5D10, 0x5A30, 0x5560, 0x5160, 0x4D50, + 0x4990, 0x46E0, 0x4400, 0x4130, 0x3DE0, 0x3A00, 0x3790, 0x3480, 0x31E0, 0x2F80, 0x2CD0, 0x2B30, 0x27C0, 0x24D0, 0x2220, 0x2020, + 0x1F00, 0x1D10, 0x1B10, 0x1830, 0x1520, 0x12F0, 0x1160, 0x10A0, 0x0FC0, 0x0E30, 0x0BB0, 0x0900, 0x05F0, 0x0350, 0x00E0, 0xFF50, + 0xFD70, 0xFA30, 0xF600, 0xF1C0, 0xEE10, 0xEA30, 0xE5E0, 0xE1F0, 0xDDB0, 0xD8C0, 0xD3C0, 0xCE10, 0xC850, 0xC2C0, 0xBD40, 0xB720, + 0xAFF0, 0xA880, 0xA0D0, 0x99A0, 0x9250, 0x8C50, 0x88B0, 0x86A0, 0x85B0, 0x8540, 0x8510, 0x84F0, 0x84E0, 0x84D0, 0x84D0, 0x84C0, + 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84C0, 0x84F0, 0x84F0, + 0x84D0, 0x84D0, 0x8490, 0x84F0, 0x84F0, 0x8500, 0x8500, 0x8510, 0x8520, 0x8540, 0x8560, 0x8590, 0x85E0, 0x8630, 0x8680, 0x8700, + 0x87C0, 0x88C0, 0x89D0, 0x8BA0, 0x8DF0, 0x9050, 0x9320, 0x9620, 0x9930, 0x9BE0, 0x9E30, 0xA0F0, 0xA300, 0xA5B0, 0xA8C0, 0xABC0, + 0xAE30, 0xB140, 0xB3E0, 0xB660, 0xB7B0, 0xB990, 0xBB30, 0xBDC0, 0xBF70, 0xC0A0, 0xC200, 0xC310, 0xC410, 0xC5A0, 0xC710, 0xC7F0, + 0xC910, 0xC960, 0xCA30, 0xCA70, 0xCB70, 0xCB90, 0xCBF0, 0xCCB0, 0xCD00, 0xCE40, 0xCEA0, 0xCEF0, 0xD010, 0xD0F0, 0xD2F0, 0xD360, + 0xD470, 0xD570, 0xD660, 0xD740, 0xD7B0, 0xD820, 0xD820, 0xD880, 0xD810, 0xD910, 0xDA60, 0xDB80, 0xDC90, 0xDD20, 0xDD40, 0xDDA0, + 0xDE00, 0xDE90, 0xDF60, 0xDFD0, 0xE030, 0xE070, 0xE010, 0xE070, 0xE130, 0xE1F0, 0xE240, 0xE1C0, 0xE1A0, 0xE1C0, 0xE1C0, 0xE210, + 0xE270, 0xE1E0, 0xE1D0, 0xE1A0, 0xE0E0, 0xE0A0, 0xDFF0, 0xE010, 0xDFC0, 0xDF60, 0xDEB0, 0xDDB0, 0xDC70, 0xDC10, 0xDB70, 0xDA80, + 0xD990, 0xD8B0, 0xD790, 0xD7E0, 0xD860, 0xD800, 0xD7B0, 0xD650, 0xD580, 0xD470, 0xD3F0, 0xD380, 0xD3D0, 0xD3D0, 0xD300, 0xD1B0, + 0xD030, 0xCFA0, 0xCF60, 0xCF10, 0xCF30, 0xCEE0, 0xCEE0, 0xCEA0, 0xCEF0, 0xCEE0, 0xCF10, 0xCF80, 0xD030, 0xD0A0, 0xD150, 0xD230, + 0xD2A0, 0xD3E0, 0xD4F0, 0xD5E0, 0xD6C0, 0xD7C0, 0xD9C0, 0xDC50, 0xDDE0, 0xDF70, 0xDFD0, 0xDFF0, 0xDFB0, 0xE020, 0xE070, 0xE130, + 0xE280, 0xE3B0, 0xE480, 0xE530, 0xE500, 0xE4D0, 0xE3F0, 0xE370, 0xE270, 0xE1C0, 0xE110, 0xE170, 0xE240, 0xE2F0, 0xE310, 0xE260, + 0xE0C0, 0xDF00, 0xDCB0, 0xDB60, 0xDA20, 0xD950, 0xD730, 0xD550, 0xD290, 0xCE90, 0xCBB0, 0xC980, 0xC750, 0xC4E0, 0xC210, 0xBED0, + 0xBC10, 0xBA10, 0xB8A0, 0xB780, 0xB690, 0xB520, 0xB410, 0xB240, 0xB110, 0xB100, 0xB0D0, 0xB140, 0xB180, 0xB290, 0xB320, 0xB460, + 0xB680, 0xB8C0, 0xBB70, 0xBCE0, 0xBF30, 0xC140, 0xC3D0, 0xC750, 0xCA50, 0xCD20, 0xCFA0, 0xD1A0, 0xD370, 0xD530, 0xD710, 0xD930, + 0xDB50, 0xDCA0, 0xDD30, 0xDCF0, 0xDD00, 0xDDF0, 0xDE50, 0xDDB0, 0xDC70, 0xD9E0, 0xD660, 0xD250, 0xCDB0, 0xC8D0, 0xC410, 0xBE00, + 0xB810, 0xB180, 0xAB00, 0xA410, 0x9DB0, 0x9650, 0x8FB0, 0x8AE0, 0x87D0, 0x8670, 0x85D0, 0x8590, 0x8580, 0x8580, 0x85A0, 0x85D0, + 0x8640, 0x8730, 0x8950, 0x8E80, 0x9630, 0x9E10, 0xA5B0, 0xAD40, 0xB370, 0xB8D0, 0xBE30, 0xC2E0, 0xC740, 0xCBF0, 0xD040, 0xD470, + 0xDA20, 0xDEE0, 0xE3C0, 0xE770, 0xEA30, 0xED30, 0xEFC0, 0xF250, 0xF480, 0xF720, 0xF9F0, 0xFC00, 0xFE60, 0x0060, 0x0210, 0x03B0, + 0x04E0, 0x0600, 0x0790, 0x07B0, 0x08A0, 0x08E0, 0x08D0, 0x08E0, 0x0940, 0x0950, 0x08B0, 0x0780, 0x0700, 0x05D0, 0x0590, 0x05E0, + 0x05C0, 0x0640, 0x0580, 0x0540, 0x0490, 0x0490, 0x0420, 0x0410, 0x0510, 0x0550, 0x05F0, 0x06F0, 0x0730, 0x07A0, 0x0700, 0x0630, + 0x0580, 0x03C0, 0x0350, 0x0290, 0x0160, 0x00B0, 0x0010, 0xFF60, 0xFDC0, 0xFC40, 0xFA80, 0xF880, 0xF740, 0xF5F0, 0xF450, 0xF270, + 0xF090, 0xEEF0, 0xEDE0, 0xEC60, 0xEC20, 0xEAF0, 0xE8E0, 0xE720, 0xE450, 0xE290, 0xDFE0, 0xDDC0, 0xDA50, 0xD710, 0xD330, 0xCEE0, + 0xCA80, 0xC640, 0xC1C0, 0xBCD0, 0xB7D0, 0xB240, 0xAC90, 0xA620, 0xA0B0, 0x9AE0, 0x93F0, 0x8EA0, 0x8A40, 0x87A0, 0x8610, 0x8560, + 0x8510, 0x84F0, 0x84E0, 0x84C0, 0x84C0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x84B0, + 0x8490, 0x8470, 0x8470, 0x8450, 0x8470, 0x8470, 0x84A0, 0x8480, 0x84B0, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, + 0x8490, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84D0, 0x84D0, 0x84E0, 0x84F0, 0x84F0, 0x8500, 0x8510, 0x8530, 0x8530, 0x8550, + 0x8560, 0x8570, 0x8590, 0x8590, 0x8590, 0x85B0, 0x85C0, 0x85E0, 0x85F0, 0x8660, 0x86D0, 0x8750, 0x87C0, 0x8800, 0x8860, 0x88C0, + 0x88E0, 0x88F0, 0x8940, 0x8920, 0x88C0, 0x8800, 0x8740, 0x86A0, 0x8600, 0x8580, 0x8550, 0x8500, 0x84E0, 0x84F0, 0x84B0, 0x84A0, + 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x8490, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8470, + 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8440, + 0x8430, 0x8430, 0x8420, 0x8420, 0x8410, 0x8410, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83C0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, + 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83B0, 0x83B0, 0x83C0, 0x83A0, 0x83C0, 0x83C0, 0x83F0, + 0x83F0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, + 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, + 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8490, 0x8490, 0x8490, + 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84C0, 0x84C0, 0x84E0, 0x84F0, 0x8510, 0x8540, 0x85B0, 0x8680, 0x88E0, 0x8F80, 0x9A70, 0xA590, + 0xB2D0, 0xC030, 0xCE40, 0xDD10, 0xEAF0, 0xF910, 0x0560, 0x1130, 0x1B90, 0x2650, 0x2F70, 0x3730, 0x3E60, 0x4460, 0x49D0, 0x4EF0, + 0x5380, 0x5800, 0x5CB0, 0x6030, 0x6400, 0x6740, 0x6AC0, 0x6EB0, 0x7280, 0x7710, 0x7B10, 0x7E40, 0x7EF0, 0x7F10, 0x7F00, 0x7EE0, + 0x7F50, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F60, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7ED0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F70, + 0x7F00, 0x7EA0, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7E90, 0x7F00, 0x7EE0, 0x7EF0, 0x7F10, 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7F20, + 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7F60, 0x7F00, 0x7F10, 0x7F30, 0x7F20, 0x7F80, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, + 0x7F80, 0x7EF0, 0x7F20, 0x7ED0, 0x7F10, 0x7F70, 0x7F20, 0x7ED0, 0x7EF0, 0x7EE0, 0x7F50, 0x7F10, 0x7EB0, 0x7EE0, 0x7ED0, 0x7F30, + 0x7F20, 0x7EC0, 0x7ED0, 0x7F00, 0x7F30, 0x7F10, 0x7E90, 0x7EB0, 0x7EA0, 0x7EF0, 0x7F10, 0x7EB0, 0x7ED0, 0x7F10, 0x7F20, 0x7F20, + 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7F00, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F60, 0x7F10, 0x7F10, 0x7F20, 0x7F10, + 0x7F30, 0x7EF0, 0x7F00, 0x7F20, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, + 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F00, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7EF0, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F00, 0x7F30, + 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7C80, 0x70C0, 0x65B0, 0x5AD0, 0x5000, 0x4640, 0x3E30, 0x3790, + 0x3330, 0x2FB0, 0x2D80, 0x2B70, 0x2980, 0x2A40, 0x2D00, 0x3230, 0x39A0, 0x43C0, 0x5030, 0x5BE0, 0x66C0, 0x7150, 0x7A30, 0x7EF0, + 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, + 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, + 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F10, + 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F10, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F00, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7EF0, 0x7F30, + 0x7F20, 0x7F20, 0x7F30, 0x7F00, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F20, + 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F40, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, + 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7EF0, 0x7F30, 0x7F20, + 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F90, 0x7F10, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F30, 0x7F20, 0x7E80, + 0x7F10, 0x7F00, 0x7F20, 0x7F00, 0x7E90, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EA0, 0x7EC0, 0x7EF0, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, + 0x7F00, 0x7F00, 0x7EF0, 0x7E90, 0x7F00, 0x7EE0, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, 0x7F10, 0x7F00, 0x7F10, 0x7F30, 0x7EF0, + 0x7F20, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F20, 0x7F30, 0x7F00, 0x7F30, 0x7EF0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F30, 0x7EE0, 0x7ED0, + 0x7EF0, 0x7F20, 0x7F60, 0x7ED0, 0x7E90, 0x7F00, 0x7EE0, 0x7F30, 0x7EE0, 0x7E70, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7EC0, 0x7F10, + 0x7F00, 0x7F10, 0x7F10, 0x7EB0, 0x7F20, 0x7EF0, 0x7F10, 0x7F30, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F70, 0x7EF0, + 0x7F10, 0x7EF0, 0x7EF0, 0x7F70, 0x7EF0, 0x7F20, 0x7F20, 0x7F00, 0x7F90, 0x7F10, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F60, 0x7EF0, 0x7ED0, + 0x7EF0, 0x7F00, 0x7F40, 0x7F10, 0x7EE0, 0x7EE0, 0x7ED0, 0x7F10, 0x7F00, 0x7E70, 0x7ED0, 0x7F10, 0x7F20, 0x7EF0, 0x7E90, 0x7F00, + 0x7F20, 0x7F10, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F30, 0x7F40, + 0x7F10, 0x7F10, 0x7EE0, 0x7F50, 0x7EF0, 0x7F20, 0x7F20, 0x7F00, 0x7F70, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F60, 0x7EE0, 0x7EC0, + 0x7F10, 0x7EF0, 0x7F70, 0x7EF0, 0x7EC0, 0x7F00, 0x7ED0, 0x7F10, 0x7EE0, 0x7EA0, 0x7EF0, 0x7F00, 0x7F20, 0x7ED0, 0x7EB0, 0x7F20, + 0x7F20, 0x7F10, 0x7F10, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7EC0, 0x7F30, 0x7F10, 0x7F20, 0x7F10, 0x7F00, 0x7F40, 0x7F10, + 0x7F10, 0x7F20, 0x7EE0, 0x7F70, 0x7EF0, 0x7F20, 0x7EF0, 0x7EF0, 0x7F90, 0x7F20, 0x7F10, 0x7EF0, 0x7EF0, 0x7F60, 0x7F10, 0x7EF0, + 0x7EF0, 0x7F20, 0x7F10, 0x7F10, 0x7F60, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7F10, 0x7F20, 0x7F00, 0x7EF0, 0x7F50, 0x7F00, + 0x7EC0, 0x7ED0, 0x7EF0, 0x7F30, 0x7EF0, 0x7ED0, 0x7F00, 0x7EE0, 0x7F30, 0x7F10, 0x7E90, 0x7EC0, 0x7EF0, 0x7F30, 0x7EE0, 0x7E90, + 0x7ED0, 0x7F20, 0x7F20, 0x7F10, 0x7EB0, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F20, + 0x7F20, 0x7F40, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7EF0, 0x7F50, 0x7F10, 0x7F20, 0x75F0, 0x6B10, 0x60B0, 0x5570, + 0x4AC0, 0x3EF0, 0x33B0, 0x29C0, 0x2050, 0x1890, 0x1230, 0x0B40, 0x03D0, 0xFC70, 0xF320, 0xEB50, 0xE4B0, 0xDF20, 0xDA40, 0xD4D0, + 0xCFB0, 0xC940, 0xC240, 0xB9A0, 0xB050, 0xA640, 0x9B60, 0x90F0, 0x89C0, 0x8690, 0x8560, 0x8510, 0x84E0, 0x84D0, 0x84C0, 0x84C0, + 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84D0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, + 0x84B0, 0x84B0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84F0, 0x84D0, 0x84C0, 0x84C0, 0x8460, 0x84D0, 0x84E0, + 0x8500, 0x8510, 0x8530, 0x8580, 0x8600, 0x86F0, 0x8850, 0x8A40, 0x8CC0, 0x9010, 0x9360, 0x9730, 0x9B10, 0xA020, 0xA4A0, 0xA7D0, + 0xAA70, 0xAC90, 0xAFD0, 0xB350, 0xB710, 0xBB50, 0xBEA0, 0xC240, 0xC4A0, 0xC7C0, 0xCA60, 0xCD30, 0xD0D0, 0xD4C0, 0xD7F0, 0xDAD0, + 0xDD30, 0xDFA0, 0xE250, 0xE4F0, 0xE860, 0xEAE0, 0xECF0, 0xEF70, 0xF130, 0xF3A0, 0xF450, 0xF5B0, 0xF560, 0xF3F0, 0xF310, 0xF170, + 0xF120, 0xF190, 0xF1B0, 0xF1E0, 0xF1C0, 0xF0C0, 0xEEA0, 0xEC10, 0xE950, 0xE680, 0xE360, 0xDFA0, 0xDA40, 0xD500, 0xCF20, 0xC8C0, + 0xC250, 0xBB70, 0xB440, 0xAC40, 0xA3E0, 0x9C10, 0x94D0, 0x8ED0, 0x89D0, 0x8710, 0x85E0, 0x8500, 0x84F0, 0x84E0, 0x84E0, 0x84D0, + 0x84C0, 0x84C0, 0x84C0, 0x84D0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84D0, 0x84D0, 0x84D0, 0x84E0, 0x84E0, 0x84E0, + 0x84E0, 0x84F0, 0x84F0, 0x8510, 0x8500, 0x8510, 0x8520, 0x8570, 0x8550, 0x8570, 0x8590, 0x85B0, 0x85E0, 0x8600, 0x8650, 0x86C0, + 0x8730, 0x87C0, 0x8850, 0x88A0, 0x88F0, 0x89C0, 0x8A70, 0x8B80, 0x8C20, 0x8D00, 0x8DC0, 0x8E60, 0x8F80, 0x9080, 0x9240, 0x9400, + 0x9530, 0x96C0, 0x97A0, 0x9980, 0x9BA0, 0x9ED0, 0xA240, 0xA600, 0xA920, 0xACC0, 0xAFE0, 0xB370, 0xB650, 0xB8C0, 0xBA90, 0xBB80, + 0xBBD0, 0xBBD0, 0xBB80, 0xBBE0, 0xBB10, 0xBA40, 0xB960, 0xB8B0, 0xB710, 0xB5D0, 0xB400, 0xB1C0, 0xAEF0, 0xABC0, 0xA930, 0xA7A0, + 0xA6E0, 0xA610, 0xA440, 0xA230, 0xA080, 0x9EC0, 0x9CE0, 0x9C00, 0x9AB0, 0x9A30, 0x9A40, 0x9A90, 0x9A80, 0x9A50, 0x9A60, 0x9A50, + 0x9AE0, 0x9C10, 0x9D60, 0x9E30, 0x9EF0, 0x9F50, 0x9FA0, 0x9FF0, 0xA000, 0xA030, 0xA140, 0xA210, 0xA260, 0xA260, 0xA250, 0xA1F0, + 0xA190, 0xA1B0, 0xA260, 0xA290, 0xA310, 0xA2D0, 0xA2F0, 0xA200, 0xA1A0, 0xA210, 0xA1B0, 0xA190, 0xA110, 0xA050, 0x9FE0, 0x9FF0, + 0xA0C0, 0xA200, 0xA310, 0xA330, 0xA340, 0xA330, 0xA370, 0xA500, 0xA730, 0xA930, 0xABB0, 0xADF0, 0xB030, 0xB2D0, 0xB560, 0xB7E0, + 0xBA50, 0xBC50, 0xBDC0, 0xBFE0, 0xC310, 0xC5E0, 0xC900, 0xCC50, 0xCF60, 0xD1D0, 0xD4E0, 0xD780, 0xDAA0, 0xDE10, 0xE0E0, 0xE3F0, + 0xE630, 0xE910, 0xEC00, 0xEF10, 0xF270, 0xF580, 0xF800, 0xFA70, 0xFB90, 0xFD30, 0xFF20, 0x01E0, 0x04F0, 0x07F0, 0x09C0, 0x0B50, + 0x0B90, 0x0C50, 0x0DA0, 0x0F90, 0x11D0, 0x1400, 0x1610, 0x17B0, 0x18F0, 0x1A60, 0x1BC0, 0x1D00, 0x1EA0, 0x2000, 0x2120, 0x2200, + 0x22D0, 0x2360, 0x23D0, 0x22B0, 0x2120, 0x1FD0, 0x1DF0, 0x1C80, 0x1AA0, 0x18D0, 0x16D0, 0x1430, 0x1170, 0x0DF0, 0x0AB0, 0x0860, + 0x0680, 0x0500, 0x0380, 0x01B0, 0x0060, 0xFF40, 0xFF70, 0x00A0, 0x02A0, 0x0600, 0x0AD0, 0x1100, 0x1820, 0x20D0, 0x2A10, 0x34C0, + 0x3FF0, 0x4BD0, 0x5830, 0x64A0, 0x7140, 0x7C80, 0x7F00, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7EE0, 0x7F10, 0x7F30, 0x7F20, 0x7F20, + 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F70, 0x7EF0, 0x7EB0, 0x7F20, 0x7F40, 0x7F40, + 0x7ED0, 0x7E70, 0x7EF0, 0x7F10, 0x7EF0, 0x7E70, 0x7E60, 0x7EF0, 0x7EF0, 0x7F20, 0x7F20, 0x7EC0, 0x7F00, 0x7F10, 0x7F10, 0x7BF0, + 0x6A00, 0x5660, 0x3CF0, 0x1E60, 0xFDE0, 0xDB20, 0xC030, 0xACE0, 0xA1C0, 0xA010, 0xA950, 0xBD40, 0xDC30, 0x0280, 0x32B0, 0x5F20, + 0x7ED0, 0x7F10, 0x7F20, 0x7F00, 0x7EF0, 0x7F30, 0x7EF0, 0x7F10, 0x7F10, 0x7EE0, 0x7F40, 0x7EF0, 0x7EB0, 0x7EF0, 0x7EE0, 0x7F10, + 0x7F00, 0x7EC0, 0x7ED0, 0x7EB0, 0x7F10, 0x7EF0, 0x7E90, 0x7EF0, 0x7F20, 0x7E50, 0x7A90, 0x7900, 0x79A0, 0x7B90, 0x7C90, 0x7DA0, + 0x7E00, 0x7EE0, 0x7F00, 0x7F00, 0x7EF0, 0x7F00, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7EF0, 0x7F40, 0x7F10, 0x7F20, 0x7F00, 0x7EF0, + 0x7F50, 0x7F00, 0x7F20, 0x74D0, 0x6630, 0x5CA0, 0x5540, 0x4F50, 0x4970, 0x41E0, 0x3950, 0x2E50, 0x2180, 0x12F0, 0x0550, 0xF8E0, + 0xF020, 0xEAC0, 0xE880, 0xE6D0, 0xE3A0, 0xDE80, 0xD430, 0xC620, 0xB530, 0xA1C0, 0x8E40, 0x8600, 0x84E0, 0x84B0, 0x8480, 0x8470, + 0x8450, 0x8440, 0x8430, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x83F0, 0x83F0, 0x83E0, 0x8410, + 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83F0, 0x8400, 0x8430, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, + 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8480, 0x8460, 0x8470, 0x8480, 0x8490, + 0x8490, 0x84B0, 0x84D0, 0x84E0, 0x8520, 0x85C0, 0x8800, 0x8E80, 0x98F0, 0xA360, 0xAC50, 0xB560, 0xBD90, 0xC520, 0xCBB0, 0xCFE0, + 0xD3C0, 0xD570, 0xD5D0, 0xD670, 0xD6A0, 0xD650, 0xD550, 0xD320, 0xD060, 0xCCD0, 0xC9E0, 0xC680, 0xC2F0, 0xBF70, 0xBA80, 0xB400, + 0xAD50, 0xA690, 0xA050, 0x88A0, 0x8670, 0x8590, 0x8530, 0x8510, 0x8500, 0x8510, 0x84F0, 0x84F0, 0x84E0, 0x84F0, 0x8510, 0x8530, + 0x8560, 0x85B0, 0x8640, 0x8750, 0x88F0, 0x8BA0, 0x9020, 0x9490, 0x9740, 0x9920, 0x99E0, 0x9B50, 0x9C60, 0x9E30, 0xA040, 0xA1E0, + 0xA340, 0xA3B0, 0xA3A0, 0xA3B0, 0xA4F0, 0xA620, 0xA790, 0xA870, 0xAA50, 0xAC90, 0xB120, 0xB720, 0xBEF0, 0xC790, 0xD030, 0xDAC0, + 0xE540, 0xF220, 0xFE50, 0x0A30, 0x1590, 0x1E70, 0x2510, 0x2A80, 0x2E70, 0x3130, 0x31D0, 0x2FB0, 0x2B60, 0x2470, 0x1CF0, 0x14E0, + 0x0C40, 0x05A0, 0xFEF0, 0xF860, 0xF0E0, 0xE870, 0xE050, 0xD7E0, 0xCF90, 0xC7B0, 0xBF90, 0xB770, 0xAEF0, 0xA800, 0xA1B0, 0x9C00, + 0x9720, 0x92B0, 0x8E60, 0x8AB0, 0x8800, 0x8680, 0x85C0, 0x85A0, 0x8550, 0x8540, 0x8550, 0x8590, 0x85B0, 0x8620, 0x8730, 0x8930, + 0x8CA0, 0x90C0, 0x9610, 0x9BD0, 0xA290, 0xAA90, 0xB2D0, 0xBC70, 0xC500, 0xCE90, 0xD810, 0xE260, 0xEC00, 0xF5F0, 0xFFD0, 0x0900, + 0x12D0, 0x1C10, 0x24D0, 0x2E60, 0x37B0, 0x4070, 0x4970, 0x5160, 0x59D0, 0x6230, 0x68E0, 0x6F50, 0x7430, 0x79A0, 0x7D60, 0x7EF0, + 0x7F10, 0x7EA0, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F30, 0x7F00, 0x7F20, 0x7F40, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F20, + 0x7F00, 0x7F80, 0x7F10, 0x7F20, 0x7EF0, 0x7D30, 0x78B0, 0x7360, 0x6CC0, 0x64D0, 0x5C00, 0x50E0, 0x4520, 0x3830, 0x2D40, 0x22A0, + 0x1950, 0x1100, 0x09E0, 0x0410, 0xFEB0, 0xF8F0, 0xF250, 0xE970, 0xDF70, 0xD250, 0xC330, 0xB1D0, 0x9E20, 0x8B50, 0x8580, 0x84E0, + 0x84C0, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8460, 0x8470, 0x8470, 0x8480, 0x8490, + 0x84A0, 0x84B0, 0x84C0, 0x84D0, 0x84F0, 0x8530, 0x8650, 0x8DA0, 0xA210, 0xB6B0, 0xCBF0, 0xDF70, 0xF270, 0x0360, 0x13F0, 0x22D0, + 0x3130, 0x3E60, 0x4960, 0x5470, 0x5C70, 0x62F0, 0x6850, 0x6B10, 0x6DB0, 0x6F10, 0x6F50, 0x6F90, 0x6EC0, 0x6E80, 0x6DA0, 0x6C60, + 0x6BE0, 0x6AD0, 0x6990, 0x6720, 0x6320, 0x5D70, 0x55C0, 0x4E10, 0x4600, 0x3EB0, 0x3920, 0x3540, 0x33D0, 0x33B0, 0x3400, 0x35F0, + 0x3860, 0x3CB0, 0x4240, 0x4890, 0x5030, 0x5700, 0x5D60, 0x6410, 0x68C0, 0x6D20, 0x6F90, 0x70B0, 0x7160, 0x70C0, 0x6F50, 0x6DE0, + 0x6AF0, 0x6880, 0x6530, 0x6260, 0x5FE0, 0x5ED0, 0x6210, 0x6800, 0x7370, 0x7E70, 0x7F30, 0x7EF0, 0x7E90, 0x7ED0, 0x7F00, 0x7F00, + 0x7F10, 0x7E90, 0x7ED0, 0x7EF0, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x1390, 0xF4A0, 0xD8C0, 0xC0E0, 0xACE0, 0x9B10, + 0x8CE0, 0x86C0, 0x8530, 0x84F0, 0x84D0, 0x84C0, 0x84B0, 0x84A0, 0x8490, 0x8480, 0x8480, 0x8460, 0x8450, 0x8440, 0x8430, 0x8430, + 0x8420, 0x8430, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83E0, 0x83E0, 0x83D0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8410, 0x8410, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8420, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, + 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, + 0x8400, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8470, 0x8450, + 0x8450, 0x8450, 0x8460, 0x8470, 0x8470, 0x84B0, 0x84A0, 0x84C0, 0x84F0, 0x8580, 0x88C0, 0x9930, 0xAA80, 0xB8D0, 0xC600, 0xD160, + 0xDA50, 0xE3B0, 0xEC10, 0xF470, 0xFD80, 0x0600, 0x0EB0, 0x1890, 0x2130, 0x2930, 0x30A0, 0x3620, 0x3AF0, 0x3E30, 0x4100, 0x4360, + 0x4630, 0x4900, 0x4A60, 0x4A70, 0x49F0, 0x4870, 0x4640, 0x4390, 0x4030, 0x3CE0, 0x3890, 0x33F0, 0x2F50, 0x2AE0, 0x26E0, 0x2290, + 0x1E70, 0x1A50, 0x14D0, 0x0F50, 0x0960, 0x03F0, 0xFE10, 0xF890, 0xF2E0, 0xECE0, 0xE670, 0xDEE0, 0xD780, 0xCFF0, 0xC7D0, 0xC070, + 0xBA50, 0xB580, 0xB1F0, 0xB0D0, 0xB0F0, 0xB290, 0xB5C0, 0xB9E0, 0xBDF0, 0xC1D0, 0xC5C0, 0xCA60, 0xCFA0, 0xD650, 0xDC60, 0xE2E0, + 0xE950, 0xEE50, 0xF370, 0xF7C0, 0xFB40, 0xFE10, 0xFFF0, 0x0250, 0x0540, 0x0710, 0x08A0, 0x0A00, 0x0AD0, 0x0A70, 0x0960, 0x07B0, + 0x0630, 0x0620, 0x05C0, 0x0610, 0x06D0, 0x0720, 0x0940, 0x0C50, 0x11A0, 0x17C0, 0x1F90, 0x2870, 0x3240, 0x3C90, 0x4780, 0x5170, + 0x5BA0, 0x64F0, 0x6BB0, 0x70A0, 0x73C0, 0x75D0, 0x77F0, 0x7A20, 0x7CA0, 0x7E40, 0x7F00, 0x7EF0, 0x7EF0, 0x7F00, 0x7EA0, 0x7F20, + 0x7F10, 0x7F10, 0x7F00, 0x7E90, 0x7F10, 0x7EF0, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7F00, 0x7F10, 0x7F20, 0x7F00, 0x7F80, 0x7F10, + 0x7F20, 0x7EF0, 0x7EF0, 0x7F90, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F80, 0x7F10, 0x7EF0, 0x7EE0, 0x7EE0, 0x7F50, 0x7F00, 0x7EE0, + 0x7ED0, 0x7EF0, 0x7F60, 0x7F20, 0x7E90, 0x7EB0, 0x7EE0, 0x7F30, 0x7F10, 0x7E70, 0x7EC0, 0x7EF0, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, + 0x7F00, 0x7F00, 0x7F10, 0x7EB0, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F50, 0x7F10, + 0x7F20, 0x7EF0, 0x7F00, 0x7F40, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, 0x7F80, 0x7EF0, 0x7EE0, 0x7F10, 0x7F10, 0x7F70, 0x7EE0, 0x7ED0, + 0x7F10, 0x7F10, 0x7F60, 0x7EE0, 0x7EE0, 0x7F00, 0x7F10, 0x7F30, 0x7EB0, 0x7E70, 0x7EF0, 0x7EF0, 0x7F30, 0x7ED0, 0x7E90, 0x7F10, + 0x7F20, 0x7F10, 0x7F10, 0x7EB0, 0x7F20, 0x7EF0, 0x6610, 0x45A0, 0x2240, 0xFEF0, 0xDFA0, 0xC6D0, 0xB8F0, 0xB570, 0xBD60, 0xCD60, + 0xDF10, 0xEEF0, 0xF900, 0xFD00, 0xFBF0, 0xF830, 0xF470, 0xF300, 0xF530, 0xFAB0, 0x0180, 0x0940, 0x0F10, 0x1270, 0x1400, 0x1290, + 0x10F0, 0x0EC0, 0x0D50, 0x0C90, 0x0CD0, 0x0E40, 0x0E90, 0x0DD0, 0x0CB0, 0x0B00, 0x0980, 0x08E0, 0x0920, 0x0A40, 0x0C30, 0x1060, + 0x1520, 0x1BC0, 0x24B0, 0x3000, 0x3B40, 0x6860, 0x70C0, 0x7760, 0x7C40, 0x7ED0, 0x7E90, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EA0, + 0x7ED0, 0x7F00, 0x7F20, 0x7F20, 0x7EC0, 0x7F10, 0x7F00, 0x7F00, 0x7EF0, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F50, + 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F30, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F60, 0x7F00, 0x7F20, 0x7F20, 0x7F10, 0x7F90, 0x7EF0, + 0x7EE0, 0x7EF0, 0x7EF0, 0x7F70, 0x7EE0, 0x7ED0, 0x7F10, 0x7F20, 0x7F50, 0x7ED0, 0x7EB0, 0x7F00, 0x7EF0, 0x7EB0, 0x7CE0, 0x79C0, + 0x7780, 0x7590, 0x7370, 0x72E0, 0x7100, 0x6F10, 0x6C20, 0x6910, 0x6730, 0x6460, 0x61C0, 0x5E80, 0x5AF0, 0x5860, 0x55A0, 0x51D0, + 0x4E60, 0x49A0, 0x4510, 0x3F10, 0x38B0, 0x31A0, 0x29F0, 0x22F0, 0x1B20, 0x1380, 0x0C90, 0x0540, 0xFEE0, 0xF850, 0xF1B0, 0xEB00, + 0xE4E0, 0xDEF0, 0xD930, 0xD340, 0xCCC0, 0xC5D0, 0xBF30, 0xB740, 0xAEF0, 0xA670, 0x9CD0, 0x9460, 0x8D20, 0x8850, 0x8620, 0x8550, + 0x8500, 0x84D0, 0x84C0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84F0, 0x8540, 0x8660, 0x8B40, + 0x98D0, 0xA700, 0xB570, 0xC2F0, 0xCFC0, 0xDC10, 0xE730, 0xF1F0, 0xFAF0, 0x0250, 0x0740, 0x0A40, 0x0B10, 0x0870, 0x0400, 0xFCC0, + 0xF260, 0xE690, 0xD980, 0xCC80, 0xBFD0, 0xB5E0, 0xAF70, 0xAC90, 0xAEE0, 0xB5D0, 0xBFF0, 0xCC60, 0xDB00, 0xEBA0, 0xFC80, 0x0DF0, + 0x2000, 0x30D0, 0x4280, 0x51E0, 0x6140, 0x6EF0, 0x7AB0, 0x7EF0, 0x7EF0, 0x7F90, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F70, 0x7F10, + 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, 0x7F00, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F70, 0x7F20, 0x7EC0, 0x7ED0, 0x7EB0, 0x7F50, 0x7F10, 0x7EB0, + 0x7EB0, 0x7EE0, 0x7F10, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F20, 0x7F20, 0x7EC0, 0x7F10, 0x7F00, 0x7F00, 0x7EF0, 0x7F00, 0x7F00, + 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7EE0, 0x7F10, 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, 0x7F60, 0x7EF0, + 0x7EF0, 0x7F00, 0x7F10, 0x7F70, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F60, 0x7EE0, 0x7EF0, 0x7F00, 0x7F00, 0x7F50, 0x7ED0, 0x7EA0, + 0x7EE0, 0x7EF0, 0x7F30, 0x7EE0, 0x7E90, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7F00, 0x7EC0, 0x7F40, + 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F80, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F00, + 0x7EF0, 0x7EF0, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7EF0, + 0x7590, 0x6980, 0x5C20, 0x4D80, 0x3DC0, 0x2DD0, 0x1DA0, 0x0BF0, 0xFCB0, 0xEDA0, 0xDE80, 0xD010, 0xC190, 0xB440, 0xA720, 0x9AF0, + 0x8F40, 0x88D0, 0x8630, 0x8530, 0x8500, 0x84E0, 0x84D0, 0x84C0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x8490, 0x8490, + 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84C0, 0x84C0, 0x84D0, 0x84F0, 0x8500, 0x8520, 0x8560, 0x85D0, + 0x8670, 0x8770, 0x8900, 0x8B20, 0x8E20, 0x90C0, 0x9330, 0x94C0, 0x94E0, 0x92B0, 0x91E0, 0x90D0, 0x8FF0, 0x8E10, 0x8BD0, 0x8A20, + 0x8890, 0x8750, 0x8680, 0x85D0, 0x8590, 0x8550, 0x8530, 0x8510, 0x8500, 0x84F0, 0x84E0, 0x84F0, 0x84E0, 0x8510, 0x84E0, 0x84F0, + 0x8520, 0x8520, 0x8540, 0x8570, 0x85B0, 0x8610, 0x86C0, 0x8780, 0x8870, 0x8930, 0x8990, 0x8970, 0x8890, 0x87B0, 0x8720, 0x86E0, + 0x86D0, 0x8720, 0x87F0, 0x8940, 0x8BB0, 0x8F70, 0x9520, 0x9BA0, 0xA230, 0xA950, 0xB130, 0xB840, 0xBF40, 0xC630, 0xCDC0, 0xD540, + 0xDDC0, 0xE690, 0xF000, 0xFB50, 0x0670, 0x1290, 0x1F50, 0x2C30, 0x3980, 0x4700, 0x5460, 0x6200, 0x6F70, 0x7A70, 0x7F10, 0x7F30, + 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, + 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7FA0, 0x7F10, 0x7F20, 0x7F30, + 0x7EF0, 0x7F50, 0x7F20, 0x7F00, 0x7F00, 0x7F10, 0x7F30, 0x7EE0, 0x7EC0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EF0, 0x7EE0, 0x7F00, + 0x7F10, 0x7F00, 0x7EE0, 0x7ED0, 0x7EB0, 0x7F20, 0x7F40, 0x7E80, 0x7EF0, 0x7F00, 0x7F00, 0x7F30, 0x7EA0, 0x7EC0, 0x7ED0, 0x7F10, + 0x7EF0, 0x7E80, 0x7EF0, 0x7F10, 0x7EE0, 0x7EF0, 0x7EB0, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7EF0, 0x7F40, 0x7F10, 0x7F00, 0x7F20, + 0x7EF0, 0x7F50, 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F60, 0x7F10, 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, 0x7EF0, 0x7F00, 0x7F00, 0x7B90, + 0x62B0, 0x59F0, 0x5C90, 0x64D0, 0x6C30, 0x6EF0, 0x6CC0, 0x6580, 0x5E20, 0x5B70, 0x5FB0, 0x6BB0, 0x7A70, 0x7F00, 0x7F10, 0x7F10, + 0x7F00, 0x7E90, 0x7F10, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F20, 0x7F00, 0x7F10, 0x7F20, 0x7F00, 0x7F30, 0x7F10, 0x7F00, 0x7F20, + 0x7EF0, 0x7F80, 0x7F00, 0x7EF0, 0x7F30, 0x7F20, 0x7F80, 0x7F10, 0x7F10, 0x7EF0, 0x7EE0, 0x7F70, 0x7EF0, 0x7F00, 0x7EF0, 0x7EF0, + 0x7F60, 0x7F00, 0x7E10, 0x7D10, 0x7BB0, 0x7B50, 0x7B10, 0x79B0, 0x77A0, 0x71F0, 0x6530, 0x5240, 0x36A0, 0x14D0, 0xED70, 0xC8C0, + 0xA790, 0x8D80, 0x85F0, 0x8510, 0x84F0, 0x84C0, 0x84B0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, + 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84E0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, + 0x84B0, 0x84D0, 0x84B0, 0x84B0, 0x84A0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x8480, 0x8490, 0x8490, 0x8490, 0x8490, + 0x8490, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84D0, 0x84F0, 0x8510, 0x8550, 0x85F0, 0x8720, 0x89C0, 0x8FA0, 0x9730, 0x9F70, + 0xA670, 0xACF0, 0xB380, 0xB9C0, 0xC0B0, 0xC710, 0xCE90, 0xE950, 0xF110, 0xF940, 0x01A0, 0x0B00, 0x13C0, 0x1CD0, 0x2630, 0x2EE0, + 0x38E0, 0x4190, 0x48B0, 0x4ED0, 0x52B0, 0x5570, 0x5720, 0x56F0, 0x5710, 0x55E0, 0x54E0, 0x5200, 0x4F00, 0x4C00, 0x4740, 0x41F0, + 0x3B30, 0x33C0, 0x2BB0, 0x22D0, 0x1A90, 0x10C0, 0x0750, 0xFE00, 0xF460, 0xEA50, 0xDF90, 0xD410, 0xC7F0, 0xBB80, 0xADC0, 0xA0A0, + 0x9390, 0x89F0, 0x8620, 0x8530, 0x84F0, 0x84C0, 0x84B0, 0x84A0, 0x8490, 0x8480, 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, + 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8450, 0x8460, + 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x8490, 0x84A0, 0x84B0, + 0x84B0, 0x84C0, 0x84C0, 0x84D0, 0x8500, 0x84E0, 0x84F0, 0x84E0, 0x8510, 0x8520, 0x8530, 0x8540, 0x8540, 0x8550, 0x8550, 0x8570, + 0x8580, 0x85B0, 0x85E0, 0x8630, 0x8670, 0x8700, 0x8780, 0x8860, 0x89B0, 0x8BB0, 0x8EF0, 0x9320, 0x9900, 0x9F60, 0xA590, 0xAC70, + 0xB2C0, 0xB830, 0xBDA0, 0xC210, 0xC5D0, 0xC950, 0xCD50, 0xD0F0, 0xD490, 0xD780, 0xD9C0, 0xDAC0, 0xDBF0, 0xDC30, 0xDC60, 0xDBB0, + 0xD9F0, 0xD7E0, 0xD560, 0xD1F0, 0xCDA0, 0xC7E0, 0xC1A0, 0xBA50, 0xB280, 0xA9A0, 0xA070, 0x97F0, 0x8FB0, 0x8A00, 0x86F0, 0x85C0, + 0x8550, 0x8510, 0x8500, 0x84E0, 0x84D0, 0x84D0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x8490, + 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84B0, + 0x84B0, 0x84B0, 0x84A0, 0x84B0, 0x84C0, 0x84C0, 0x84D0, 0x84E0, 0x84F0, 0x84F0, 0x8500, 0x8520, 0x8530, 0x8540, 0x8560, 0x8580, + 0x85B0, 0x85F0, 0x8630, 0x8670, 0x86D0, 0x8700, 0x8720, 0x8710, 0x8780, 0x87A0, 0x87D0, 0x8790, 0x8770, 0x8730, 0x8720, 0x86B0, + 0x8680, 0x8670, 0x8660, 0x8640, 0x8630, 0x8620, 0x8620, 0x8600, 0x8610, 0x8620, 0x8630, 0x8620, 0x8660, 0x8630, 0x8660, 0x8690, + 0x86E0, 0x8740, 0x87A0, 0x87F0, 0x8840, 0x8850, 0x8880, 0x88C0, 0x8970, 0x8A80, 0x8BA0, 0x8C50, 0x8C90, 0x8C10, 0x8B10, 0x8990, + 0x8880, 0x87A0, 0x86E0, 0x8650, 0x85D0, 0x8590, 0x8560, 0x8540, 0x8530, 0x8530, 0x8530, 0x8530, 0x8530, 0x8540, 0x8560, 0x85A0, + 0x85D0, 0x85F0, 0x85F0, 0x85E0, 0x85D0, 0x85D0, 0x85D0, 0x85F0, 0x8610, 0x8610, 0x8600, 0x85F0, 0x85C0, 0x8590, 0x8560, 0x8530, + 0x8510, 0x8500, 0x84F0, 0x84E0, 0x84D0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, + 0x84A0, 0x84A0, 0x84A0, 0x84E0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84D0, + 0x84D0, 0x84D0, 0x84D0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84F0, 0x84F0, 0x84F0, 0x8500, 0x8500, 0x8510, 0x8520, 0x8530, + 0x8530, 0x8540, 0x8550, 0x8550, 0x8550, 0x8560, 0x8580, 0x85C0, 0x8600, 0x8640, 0x8670, 0x86B0, 0x86D0, 0x8730, 0x87D0, 0x88C0, + 0x89F0, 0x8B40, 0x8CE0, 0x8E30, 0x9010, 0x9190, 0x9350, 0x9420, 0x9550, 0x96B0, 0x9850, 0x9A40, 0x9BD0, 0x9D30, 0x9E40, 0x9E50, + 0x9D70, 0x9D10, 0x9CF0, 0x9DE0, 0x9F80, 0xA0F0, 0xA270, 0xA2D0, 0xA310, 0xA330, 0xA3D0, 0xA4A0, 0xA4E0, 0xA4C0, 0xA3A0, 0xA2D0, + 0xA260, 0xA250, 0xA320, 0xA460, 0xA4E0, 0xA480, 0xA3E0, 0xA310, 0xA2B0, 0xA210, 0xA250, 0xA290, 0xA180, 0xA0B0, 0xA000, 0x9F90, + 0xA040, 0xA130, 0xA220, 0xA2C0, 0xA2E0, 0xA260, 0xA220, 0xA240, 0xA340, 0xA3A0, 0xA330, 0xA2C0, 0xA1D0, 0xA110, 0xA110, 0xA0A0, + 0x9FD0, 0x9EC0, 0x9DB0, 0x9C40, 0x9AC0, 0x9900, 0x97C0, 0x9740, 0x97B0, 0x9850, 0x98F0, 0x9960, 0x9A30, 0x9B60, 0x9D70, 0x9F40, + 0xA120, 0xA3D0, 0xA650, 0xAAB0, 0xB070, 0xB650, 0xBC50, 0xC1F0, 0xD5D0, 0xDB30, 0xE040, 0xE450, 0xE7E0, 0xEA00, 0xEC30, 0xEDD0, + 0xEEB0, 0xEFA0, 0xEF70, 0xEF20, 0xEE50, 0xED40, 0xEBC0, 0xE8F0, 0xE550, 0xE090, 0xDB20, 0xD480, 0xCDE0, 0xC6B0, 0xBF70, 0xB700, + 0xAD50, 0xA270, 0x9690, 0x8BE0, 0x86B0, 0x8550, 0x8500, 0x84D0, 0x84C0, 0x84A0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8450, 0x8440, + 0x8430, 0x8430, 0x8420, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83E0, 0x83F0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, + 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8430, + 0x8430, 0x8430, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8460, 0x8470, 0x8480, 0x8490, 0x84B0, 0x84D0, 0x8500, 0x8560, 0x8660, + 0x8870, 0x8B90, 0x8DF0, 0x8EF0, 0x8E00, 0x8C40, 0x8A70, 0x88C0, 0x8780, 0x8670, 0x85D0, 0x8570, 0x8540, 0x8520, 0x8500, 0x84F0, + 0x84E0, 0x84D0, 0x84D0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, + 0x8480, 0x8480, 0x8490, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84C0, 0x84E0, 0x8500, + 0x8540, 0x85E0, 0x8790, 0x8D30, 0x96C0, 0xA0B0, 0xAA10, 0xB380, 0xBC30, 0xC440, 0xC9C0, 0xCEB0, 0xD3E0, 0xD950, 0xDFF0, 0xE7C0, + 0xF080, 0xF880, 0xFFC0, 0x0460, 0x0680, 0x06C0, 0x0490, 0x0230, 0xFE70, 0xF9E0, 0xF5A0, 0xF0D0, 0xEDC0, 0xEA90, 0xE890, 0xE830, + 0xE8A0, 0xE9D0, 0xEBF0, 0xEDE0, 0xF0F0, 0xF3D0, 0xF720, 0xFAE0, 0xFE90, 0x02D0, 0x06B0, 0x0AA0, 0x0EA0, 0x1280, 0x1620, 0x17B0, + 0x1830, 0x1730, 0x14E0, 0x11C0, 0x0C90, 0x07C0, 0x0210, 0xFB90, 0xF630, 0xF140, 0xECE0, 0xE950, 0xE520, 0xE180, 0xDDE0, 0xD9B0, + 0xD6B0, 0xD2D0, 0xD000, 0xCD00, 0xCA80, 0xC890, 0xC750, 0xC720, 0xC6F0, 0xC710, 0xC790, 0xC840, 0xCA50, 0xCC70, 0xCFA0, 0xD3E0, + 0xD820, 0xDF00, 0xE5F0, 0xEDF0, 0xF600, 0xFD70, 0x03E0, 0x0840, 0x0B90, 0x15A0, 0x1850, 0x1B70, 0x1EB0, 0x2140, 0x2350, 0x2520, + 0x26C0, 0x2750, 0x2890, 0x2930, 0x2A40, 0x2C10, 0x2D30, 0x2F20, 0x30D0, 0x3160, 0x3220, 0x3240, 0x31D0, 0x3230, 0x3320, 0x35E0, + 0x37F0, 0x3960, 0x3A80, 0x3AD0, 0x3BB0, 0x3C20, 0x3CE0, 0x3D90, 0x3E30, 0x3F70, 0x4050, 0x4110, 0x4170, 0x4170, 0x4180, 0x3FF0, + 0x3EA0, 0x3CC0, 0x3A90, 0x3900, 0x3780, 0x3590, 0x3330, 0x30A0, 0x2E20, 0x2AF0, 0x27D0, 0x24E0, 0x20D0, 0x1CC0, 0x17E0, 0x1240, + 0x0D90, 0x09D0, 0x06E0, 0x04C0, 0x0240, 0x0170, 0x00E0, 0x02C0, 0x06D0, 0x0CA0, 0x1460, 0x1C10, 0x2230, 0x2590, 0x24A0, 0x21B0, + 0x1C00, 0x1400, 0x0B90, 0x02F0, 0xFCF0, 0xF990, 0xF9B0, 0xFDE0, 0x0460, 0x0EA0, 0x1A30, 0x26B0, 0x3320, 0x4070, 0x4DF0, 0x5B30, + 0x6870, 0x7350, 0x7BF0, 0x7F00, 0x7F00, 0x7F90, 0x7EF0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F60, 0x7EE0, 0x7EC0, 0x7F10, 0x7F20, 0x7F40, + 0x7ED0, 0x7E90, 0x7F00, 0x7F10, 0x7F10, 0x7EE0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7F40, 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7F10, + 0x7F00, 0x7F40, 0x7EF0, 0x7F30, 0x7F20, 0x7EF0, 0x7F50, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F70, 0x7EE0, 0x7F10, 0x7F10, 0x7EE0, + 0x7F70, 0x7F10, 0x7F00, 0x7F00, 0x7EF0, 0x7F50, 0x7F20, 0x7EF0, 0x7EF0, 0x7EE0, 0x7F60, 0x7EF0, 0x7EB0, 0x7ED0, 0x7F00, 0x7F50, + 0x7F20, 0x7EA0, 0x7ED0, 0x7ED0, 0x7F00, 0x7EF0, 0x7E90, 0x7F10, 0x7EE0, 0x7EF0, 0x7F10, 0x7EB0, 0x7F20, 0x7F40, 0x7F10, 0x7F10, + 0x7EE0, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7F10, 0x7F60, 0x7F20, 0x7F40, 0x7F10, 0x7F20, 0x7F60, 0x7F10, 0x7F10, 0x7EE0, 0x7EF0, + 0x7F50, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F60, 0x7F00, 0x7ED0, 0x7F00, 0x7EF0, 0x7F50, 0x7ED0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F30, + 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7ED0, 0x7EA0, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F20, 0x7F20, + 0x7F00, 0x7F20, 0x7EE0, 0x7EF0, 0x7F30, 0x7F10, 0x7F60, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F90, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, + 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7F00, 0x7F70, 0x7F10, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F70, 0x7F00, 0x7EC0, 0x7ED0, 0x7EF0, 0x7F30, + 0x7F20, 0x7E90, 0x7F00, 0x7EE0, 0x7F10, 0x7F10, 0x7E70, 0x7E60, 0x7D90, 0x7C10, 0x7AE0, 0x7800, 0x75B0, 0x7260, 0x6E00, 0x6A50, + 0x6600, 0x61E0, 0x5E40, 0x59D0, 0x55B0, 0x5240, 0x4ED0, 0x4BF0, 0x48A0, 0x4570, 0x4290, 0x4130, 0x4060, 0x3ED0, 0x3E90, 0x3EE0, + 0x3F70, 0x4260, 0x4520, 0x4830, 0x4BE0, 0x4F20, 0x5240, 0x55B0, 0x59E0, 0x5E20, 0x6120, 0x6410, 0x66C0, 0x6850, 0x69D0, 0x6A90, + 0x6B40, 0x6B40, 0x6B10, 0x6A70, 0x69E0, 0x6850, 0x6710, 0x6620, 0x64E0, 0x6390, 0x61D0, 0x5FF0, 0x5D80, 0x5B50, 0x5860, 0x5560, + 0x51D0, 0x4D60, 0x48A0, 0x4400, 0x3E70, 0x37F0, 0x30B0, 0x27B0, 0x1E70, 0x1420, 0x0A60, 0x00D0, 0xF710, 0xEEA0, 0xE630, 0xDD50, + 0xD400, 0xCB40, 0xC260, 0xB980, 0xB0B0, 0xA8B0, 0xA120, 0x9A50, 0x93C0, 0x8D90, 0x89F0, 0x87D0, 0x86A0, 0x85E0, 0x8580, 0x8540, + 0x8520, 0x84F0, 0x8500, 0x8500, 0x8500, 0x8500, 0x8500, 0x8510, 0x8520, 0x8520, 0x8560, 0x8540, 0x8550, 0x8570, 0x8580, 0x8590, + 0x85A0, 0x85B0, 0x85D0, 0x85F0, 0x8600, 0x8620, 0x8620, 0x8620, 0x8630, 0x8640, 0x8640, 0x8650, 0x8660, 0x8680, 0x86A0, 0x86A0, + 0x86C0, 0x86C0, 0x86D0, 0x86F0, 0x8700, 0x8730, 0x8770, 0x8790, 0x87F0, 0x8880, 0x8940, 0x89B0, 0x8A60, 0x8B70, 0x8C90, 0x8E40, + 0x8FB0, 0x9170, 0x93F0, 0x9680, 0x9930, 0x9C70, 0xA030, 0xA3B0, 0xA780, 0xAB70, 0xAF50, 0xB2B0, 0xB6E0, 0xBAF0, 0xBEC0, 0xC2F0, + 0xC650, 0xC9F0, 0xCD60, 0xD0E0, 0xD3B0, 0xD660, 0xD8C0, 0xDAC0, 0xDCE0, 0xDE70, 0xE000, 0xE130, 0xE1E0, 0xE1B0, 0xE080, 0xDE60, + 0xDC70, 0xDA00, 0xD810, 0xD620, 0xD470, 0xD2E0, 0xD090, 0xCE40, 0xCBC0, 0xC990, 0xC800, 0xC6D0, 0xC6B0, 0xC700, 0xC850, 0xCAA0, + 0xCCA0, 0xCF90, 0xD220, 0xD510, 0xD840, 0xDB60, 0xDF00, 0xE340, 0xE7B0, 0xEC30, 0xF0E0, 0xF4B0, 0xF840, 0xFC30, 0x0050, 0x03F0, + 0x06B0, 0x0930, 0x0BC0, 0x0EF0, 0x1280, 0x1570, 0x18C0, 0x1BE0, 0x1DF0, 0x2120, 0x2300, 0x2530, 0x27F0, 0x2A70, 0x2E20, 0x3050, + 0x33A0, 0x35C0, 0x3870, 0x3AF0, 0x3C80, 0x3F00, 0x4090, 0x4230, 0x44A0, 0x4690, 0x49B0, 0x4D00, 0x4FE0, 0x5390, 0x56A0, 0x59C0, + 0x5C90, 0x5E90, 0x61A0, 0x6500, 0x6840, 0x6BB0, 0x6F20, 0x7340, 0x7680, 0x79B0, 0x7C60, 0x7E50, 0x7F10, 0x7F20, 0x7F60, 0x7F10, + 0x7F10, 0x7F20, 0x7EF0, 0x7F50, 0x7EF0, 0x7F00, 0x7F40, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7F50, 0x7F10, 0x7F20, + 0x7EF0, 0x7F10, 0x7F80, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7F70, 0x7F10, 0x7F10, 0x7EF0, 0x7EE0, 0x7F50, 0x7F10, 0x7EB0, 0x7EE0, + 0x7ED0, 0x7F70, 0x7F20, 0x7EC0, 0x7ED0, 0x7ED0, 0x7F00, 0x7F20, 0x7E90, 0x7EB0, 0x7EC0, 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, + 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7F00, 0x7F30, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F50, 0x7F10, 0x7F20, + 0x7F00, 0x7EF0, 0x7F50, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, 0x7F60, 0x7F00, 0x7EF0, 0x7EF0, 0x7EE0, 0x7F50, 0x7EF0, 0x7EE0, 0x7EF0, + 0x7F10, 0x7F70, 0x7F00, 0x7EC0, 0x7F10, 0x7F20, 0x7F50, 0x7ED0, 0x7EA0, 0x7EE0, 0x7EF0, 0x7F30, 0x7F10, 0x7EC0, 0x7F10, 0x7F10, + 0x7F20, 0x7F10, 0x7EB0, 0x7F10, 0x7EF0, 0x7460, 0x63F0, 0x4FC0, 0x3C70, 0x2950, 0x1710, 0x06A0, 0xF600, 0xE5D0, 0xD510, 0xC3C0, + 0xB160, 0xA000, 0x8F40, 0x86F0, 0x8520, 0x84E0, 0x84C0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, + 0x8480, 0x8480, 0x84A0, 0x8480, 0x8490, 0x8490, 0x8490, 0x84A0, 0x8460, 0x84C0, 0x84F0, 0x8500, 0x8540, 0x85B0, 0x8700, 0x8A40, + 0x90B0, 0x97F0, 0x9F90, 0xA5A0, 0xAB80, 0xAF30, 0xB2C0, 0xB420, 0xB5B0, 0xB600, 0xB580, 0xB7C0, 0xB990, 0xBB40, 0xBCC0, 0xBE80, + 0xC100, 0xC410, 0xC7E0, 0xCB60, 0xCE90, 0xD1D0, 0xD410, 0xD710, 0xDA40, 0xDDB0, 0xE1A0, 0xE4D0, 0xE830, 0xEAC0, 0xED70, 0xF090, + 0xF330, 0xF6C0, 0xF9C0, 0xFB50, 0xFD40, 0xFDE0, 0xFED0, 0xFFD0, 0x00D0, 0x01C0, 0x0250, 0x0280, 0x01C0, 0x00F0, 0x01C0, 0x02C0, + 0x04E0, 0x0690, 0x0830, 0x09B0, 0x0AF0, 0x0D10, 0x1020, 0x1360, 0x16F0, 0x1A00, 0x1C80, 0x1F80, 0x22D0, 0x2770, 0x2B60, 0x3000, + 0x33D0, 0x36A0, 0x3960, 0x3AD0, 0x3B50, 0x3BA0, 0x3A90, 0x3A10, 0x38E0, 0x3760, 0x3710, 0x3710, 0x38F0, 0x3990, 0x3990, 0x3A20, + 0x39A0, 0x38B0, 0x3750, 0x3560, 0x3390, 0x30B0, 0x2D50, 0x2920, 0x2440, 0x1EB0, 0x1820, 0x1160, 0x0A30, 0x0260, 0xFAA0, 0xF2C0, + 0xEBB0, 0xE490, 0xDC00, 0xD1D0, 0xC630, 0xB920, 0xA8D0, 0x95B0, 0x8830, 0x8520, 0x84D0, 0x84A0, 0x8480, 0x8470, 0x8470, 0x8450, + 0x8440, 0x8430, 0x8420, 0x8410, 0x8410, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83D0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, + 0x83F0, 0x8400, 0x8440, 0x8440, 0x8430, 0x8440, 0x8460, 0x8450, 0x8460, 0x8470, 0x8480, 0x8480, 0x8490, 0x84D0, 0x84C0, 0x84B0, + 0x84C0, 0x84D0, 0x84E0, 0x8500, 0x8540, 0x8610, 0x8890, 0x91B0, 0x9E60, 0xA910, 0xB1B0, 0xB760, 0xBC40, 0xC060, 0xC400, 0xC7C0, + 0xCBD0, 0xD010, 0xD560, 0xDA20, 0xDF60, 0xE580, 0xEAE0, 0xEFD0, 0xF430, 0xF8B0, 0xFDE0, 0x0370, 0x0960, 0x0F00, 0x1440, 0x19B0, + 0x1F00, 0x2620, 0x2DD0, 0x35F0, 0x3E80, 0x4640, 0x4E90, 0x55B0, 0x5BF0, 0x62D0, 0x68B0, 0x6F00, 0x7440, 0x78B0, 0x7BA0, 0x7CE0, + 0x7D90, 0x7DB0, 0x7D70, 0x7CE0, 0x7B50, 0x7980, 0x76F0, 0x73D0, 0x71B0, 0x6E40, 0x6B60, 0x6680, 0x6030, 0x5960, 0x5180, 0x49D0, + 0x4320, 0x3C10, 0x3610, 0x2EA0, 0x26A0, 0x1DC0, 0x13D0, 0x0A00, 0xFE40, 0xF3F0, 0xE9E0, 0xE040, 0xD8A0, 0xD290, 0xCDF0, 0xCAA0, + 0xC870, 0xC6B0, 0xC520, 0xC3E0, 0xC290, 0xC2B0, 0xC350, 0xC3A0, 0xC420, 0xC530, 0xC600, 0xC800, 0xCB30, 0xCF70, 0xD500, 0xDA90, + 0xE050, 0xE640, 0xECC0, 0xF4F0, 0xFC60, 0x04F0, 0x0D90, 0x1630, 0x1F40, 0x2780, 0x3090, 0x39B0, 0x4350, 0x4C50, 0x5470, 0x5CE0, + 0x6480, 0x6B80, 0x7360, 0x7A80, 0x7EF0, 0x7F10, 0x7F20, 0x7F40, 0x7F00, 0x7F30, 0x7EE0, 0x7EF0, 0x7F30, 0x7F10, 0x7F50, 0x7F10, + 0x7F20, 0x7F20, 0x7F10, 0x7F90, 0x7F00, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F60, 0x7EF0, 0x7EF0, 0x7F00, 0x7F00, 0x7F70, 0x7F10, 0x7EB0, + 0x7EF0, 0x7ED0, 0x7F10, 0x7EF0, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, + 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, + 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, + 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F10, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F00, 0x7F30, 0x7F30, 0x7F20, + 0x7F20, 0x7EF0, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F00, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, + 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7DD0, 0x7080, 0x6040, 0x4E90, 0x3C70, 0x2B20, 0x1D10, 0x1450, 0x1270, 0x1700, 0x2120, + 0x2FA0, 0x3F80, 0x4F20, 0x5DD0, 0x6A90, 0x74A0, 0x7B60, 0x7E90, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, + 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, + 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, + 0x7F20, 0x7F30, 0x7E60, 0x6A60, 0x5640, 0x4150, 0x2AE0, 0x16F0, 0x0280, 0xED80, 0xD8F0, 0xC560, 0xB460, 0xA5A0, 0x9B00, 0x92D0, + 0x8E00, 0x8A70, 0x8800, 0x8660, 0x8570, 0x8510, 0x84E0, 0x84C0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84C0, + 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84A0, 0x84C0, 0x84C0, 0x84C0, 0x84D0, 0x84D0, 0x84E0, 0x84D0, 0x84D0, + 0x84E0, 0x8480, 0x84F0, 0x8500, 0x8530, 0x8520, 0x8530, 0x8560, 0x8520, 0x85D0, 0x8630, 0x86C0, 0x8790, 0x8870, 0x89B0, 0x8B30, + 0x8D70, 0x8F50, 0x9210, 0x94D0, 0x97D0, 0x9A90, 0x9E30, 0xA2C0, 0xA770, 0xABF0, 0xB160, 0xB5F0, 0xBAD0, 0xBF60, 0xC370, 0xC670, + 0xC8D0, 0xCB80, 0xCC90, 0xCDB0, 0xCDD0, 0xCD40, 0xCD70, 0xCC60, 0xCBA0, 0xCA90, 0xC8A0, 0xC770, 0xC690, 0xC4C0, 0xC2D0, 0xC030, + 0xBEF0, 0xBDB0, 0xBCE0, 0xBCC0, 0xBC50, 0xBC90, 0xBC30, 0xBC20, 0xBC40, 0xBB20, 0xBAA0, 0xB8A0, 0xB730, 0xB570, 0xB3E0, 0xB1D0, + 0xAFE0, 0xAE70, 0xABF0, 0xA940, 0xA730, 0xA580, 0xA440, 0xA2D0, 0xA230, 0xA220, 0xA250, 0xA3B0, 0xA560, 0xA7D0, 0xAB70, 0xAEF0, + 0xB320, 0xB760, 0xBC10, 0xC270, 0xCA20, 0xD1B0, 0xD9D0, 0xE1E0, 0xEA20, 0xF190, 0xF8B0, 0x00A0, 0x06F0, 0x0D00, 0x1120, 0x1370, + 0x1510, 0x14B0, 0x1420, 0x1280, 0x0EF0, 0x0B20, 0x0500, 0xFE90, 0xF730, 0xEF00, 0xE740, 0xDEA0, 0xD5B0, 0xCD60, 0xC3C0, 0xBA00, + 0xB120, 0xA880, 0xA010, 0x9880, 0x9240, 0x8D10, 0x85C0, 0x8560, 0x8530, 0x8560, 0x8500, 0x8500, 0x8500, 0x8500, 0x8500, 0x8510, + 0x8520, 0x8530, 0x8550, 0x8570, 0x85B0, 0x8610, 0x86B0, 0x87C0, 0x8910, 0x8AF0, 0x8DE0, 0x9200, 0x95A0, 0x9990, 0x9C50, 0x9E60, + 0xA110, 0xA310, 0xA4E0, 0xA6C0, 0xA8C0, 0xAAC0, 0xACC0, 0xAEC0, 0xB0A0, 0xB1B0, 0xB370, 0xB460, 0xB590, 0xB750, 0xB840, 0xBA60, + 0xBB50, 0xBC70, 0xBD40, 0xBD60, 0xBDD0, 0xBCC0, 0xBB00, 0xB9B0, 0xB830, 0xB6A0, 0xB480, 0xB150, 0xADF0, 0xA9F0, 0xA5E0, 0xA110, + 0x9D70, 0x99E0, 0x95D0, 0x9260, 0x8F30, 0x8C80, 0x8A70, 0x88B0, 0x8780, 0x86C0, 0x8640, 0x85F0, 0x85A0, 0x8570, 0x8530, 0x8510, + 0x8510, 0x8500, 0x8500, 0x8500, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84D0, 0x84D0, + 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, + 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84E0, 0x84E0, 0x84E0, 0x84F0, 0x84F0, 0x8500, 0x8500, 0x8510, 0x8520, 0x8530, 0x8540, + 0x8550, 0x8570, 0x8590, 0x85D0, 0x8610, 0x8680, 0x86F0, 0x8790, 0x8850, 0x8950, 0x8A60, 0x8BC0, 0x8DD0, 0x9080, 0x9340, 0x95A0, + 0x97D0, 0x9A60, 0x9CB0, 0x9F20, 0xA200, 0xA4A0, 0xA7C0, 0xAA00, 0xAC40, 0xAE70, 0xB070, 0xB2C0, 0xB580, 0xB840, 0xBB30, 0xBC60, + 0xBDA0, 0xBF20, 0xC0B0, 0xC250, 0xC370, 0xC4B0, 0xC550, 0xC5C0, 0xC5C0, 0xC4F0, 0xC4E0, 0xC450, 0xC380, 0xC200, 0xC070, 0xBE60, + 0xBBF0, 0xBA20, 0xB8E0, 0xB690, 0xB3A0, 0xB080, 0xADA0, 0xAB00, 0xA770, 0xA3C0, 0xA090, 0x9CE0, 0x98F0, 0x94F0, 0x91E0, 0x8EB0, + 0x8C30, 0x8A00, 0x8840, 0x8700, 0x8630, 0x85B0, 0x8580, 0x8550, 0x8530, 0x8530, 0x8500, 0x8510, 0x8500, 0x8500, 0x8500, 0x8500, + 0x8500, 0x8500, 0x8500, 0x8500, 0x8500, 0x8510, 0x8510, 0x8520, 0x8520, 0x8530, 0x8550, 0x8570, 0x8580, 0x85C0, 0x8610, 0x8650, + 0x86A0, 0x86F0, 0x8750, 0x8770, 0x87F0, 0x8820, 0x87E0, 0x8760, 0x86E0, 0x8670, 0x8610, 0x85C0, 0x8580, 0x8560, 0x8530, 0x8520, + 0x8500, 0x8500, 0x8510, 0x84F0, 0x84F0, 0x84E0, 0x84E0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84E0, 0x84F0, 0x8500, 0x8520, 0x8580, + 0x86C0, 0x8D60, 0x9D40, 0xAE70, 0xC1B0, 0xD710, 0xEE00, 0x06C0, 0x20E0, 0x3B20, 0x5790, 0x6FA0, 0x7F60, 0x7F10, 0x7F10, 0x7EF0, + 0x7EE0, 0x7F60, 0x7F10, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F70, 0x7F20, 0x7EC0, 0x7ED0, 0x7EB0, 0x7F00, 0x7F10, 0x7EA0, 0x7EC0, 0x7EC0, + 0x7F10, 0x7F20, 0x7EA0, 0x7F00, 0x7F10, 0x7F20, 0x7F10, 0x7E90, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7930, 0x6C80, + 0x5F20, 0x4F40, 0x3ED0, 0x2EB0, 0x1E70, 0x1060, 0x02F0, 0xF860, 0xF120, 0xEBF0, 0xEAB0, 0xEA60, 0xEA50, 0xEA10, 0xE7F0, 0xE340, + 0xDB80, 0xD290, 0xC800, 0xBE60, 0xB4D0, 0xAB60, 0xA0E0, 0x9680, 0x8D60, 0x8820, 0x8630, 0x8590, 0x8560, 0x8570, 0x85E0, 0x8730, + 0x8CC0, 0x9A90, 0xA8C0, 0xB550, 0xC060, 0xC9F0, 0xD310, 0xDC00, 0xE660, 0xF0E0, 0xFB50, 0x0670, 0x0F00, 0x1710, 0x1E30, 0x23C0, + 0x29E0, 0x2E50, 0x3310, 0x3770, 0x3C80, 0x42E0, 0x4780, 0x4BD0, 0x4FA0, 0x5340, 0x5690, 0x5960, 0x5C80, 0x6050, 0x63F0, 0x67A0, + 0x6B20, 0x6D50, 0x6F90, 0x7160, 0x72D0, 0x7510, 0x76F0, 0x78A0, 0x7A00, 0x7B50, 0x7C90, 0x7D30, 0x7E00, 0x7E30, 0x7EA0, 0x7EC0, + 0x7E90, 0x7E90, 0x7E60, 0x7E40, 0x7E70, 0x7EA0, 0x7ED0, 0x7EF0, 0x7EF0, 0x7EF0, 0x7EE0, 0x7F10, 0x7F30, 0x7F30, 0x7F40, 0x7F30, + 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, + 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, + 0x7EF0, 0x7F30, 0x7F20, 0x7F10, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F00, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F10, + 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, + 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, + 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, + 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F30, + 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F30, 0x7F30, + 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F10, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F70, 0x7F30, 0x7F00, 0x7F00, 0x7F10, 0x7F30, + 0x7F20, 0x7F00, 0x7F10, 0x7EF0, 0x7F00, 0x7EE0, 0x7EC0, 0x7EC0, 0x7EF0, 0x7F50, 0x7F00, 0x7EC0, 0x7F00, 0x7F10, 0x7F30, 0x7EE0, + 0x7ED0, 0x7F10, 0x7F00, 0x7F20, 0x7EF0, 0x7EB0, 0x7F30, 0x7F00, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7EF0, 0x7F00, 0x7F00, 0x7EC0, + 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7F50, 0x7F00, 0x7F00, 0x7F50, 0x7F10, 0x7F60, + 0x7F20, 0x7F10, 0x7EF0, 0x7EF0, 0x7F90, 0x7F10, 0x7F00, 0x7EE0, 0x7EE0, 0x7F70, 0x7730, 0x6AA0, 0x5F60, 0x5280, 0x4660, 0x3B50, + 0x30D0, 0x2850, 0x2130, 0x1B90, 0x1790, 0x13D0, 0x1140, 0x0EF0, 0x0DD0, 0x0E60, 0x0F20, 0x1230, 0x1620, 0x1AA0, 0x1FC0, 0x2530, + 0x2AC0, 0x3070, 0x3550, 0x3A50, 0x3EE0, 0x4380, 0x4810, 0x4CF0, 0x53C0, 0x59D0, 0x6010, 0x66B0, 0x6CF0, 0x73D0, 0x79D0, 0x7E30, + 0x7F00, 0x7F30, 0x7F20, 0x7F20, 0x7F50, 0x7EF0, 0x7EF0, 0x7EF0, 0x7EF0, 0x7F70, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F60, 0x7ED0, + 0x7E90, 0x7EF0, 0x7EE0, 0x7F30, 0x7EB0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7EC0, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, + 0x7F20, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F30, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F60, 0x7EE0, 0x7EF0, 0x7F10, 0x7EF0, 0x7F60, + 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F90, 0x7F00, 0x7EE0, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7ED0, 0x7F00, 0x7300, 0x46D0, 0x2030, + 0xFC80, 0xE380, 0xD1B0, 0xC5B0, 0xBF00, 0xB9A0, 0xB4C0, 0xAF40, 0xA8B0, 0xA1D0, 0x9A40, 0x92B0, 0x8BB0, 0x8760, 0x85A0, 0x8510, + 0x84E0, 0x84C0, 0x84B0, 0x84A0, 0x8490, 0x8480, 0x8480, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, + 0x8440, 0x8440, 0x8410, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8400, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, + 0x8410, 0x8410, 0x8410, 0x8420, 0x8410, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8410, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, + 0x8450, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, + 0x84D0, 0x84E0, 0x84F0, 0x8510, 0x8530, 0x8560, 0x85B0, 0x8630, 0x86E0, 0x87B0, 0x88F0, 0x89F0, 0x8AB0, 0x8B90, 0x8C10, 0x8DC0, + 0x9020, 0x9350, 0x9820, 0x9E50, 0xA5B0, 0xADC0, 0xB5C0, 0xBD80, 0xC3D0, 0xCA60, 0xD020, 0xD5F0, 0xDBF0, 0xE130, 0xE680, 0xEB40, + 0xEF70, 0xF300, 0xF580, 0xF910, 0xFBE0, 0xFE90, 0x0170, 0x0250, 0x0260, 0x0010, 0xFD90, 0xFA20, 0xF5C0, 0xF090, 0xEA20, 0xE370, + 0xDC90, 0xD670, 0xCFE0, 0xC950, 0xC290, 0xBCD0, 0xB650, 0xAFC0, 0xAA30, 0xA500, 0xA0D0, 0x9C90, 0x9A10, 0x9810, 0x95F0, 0x9450, + 0x9270, 0x9140, 0x8F50, 0x8D60, 0x8BD0, 0x8A20, 0x8930, 0x8910, 0x8950, 0x8AA0, 0x8CF0, 0x90E0, 0x95A0, 0x9A30, 0x9E90, 0xA300, + 0xA7A0, 0xAB70, 0xAF60, 0xB2E0, 0xB4A0, 0xB650, 0xB7A0, 0xB8E0, 0xBAD0, 0xBD00, 0xBFD0, 0xC380, 0xC750, 0xCD20, 0xD2E0, 0xD8F0, + 0xDEF0, 0xE460, 0xE900, 0xECD0, 0xEFD0, 0xF240, 0xF420, 0xF610, 0xF8A0, 0xFA70, 0xFBE0, 0xFCF0, 0xFE60, 0xFFF0, 0x0170, 0x0310, + 0x04C0, 0x06E0, 0x0990, 0x0B00, 0x0DE0, 0x0F30, 0x1160, 0x13C0, 0x15B0, 0x18B0, 0x1B60, 0x1E70, 0x2140, 0x2380, 0x2620, 0x2800, + 0x2900, 0x2A20, 0x2B60, 0x2E00, 0x3090, 0x32E0, 0x34C0, 0x3580, 0x3660, 0x3670, 0x3710, 0x38B0, 0x3A40, 0x3D70, 0x3FD0, 0x41D0, + 0x4400, 0x46D0, 0x4AB0, 0x4E70, 0x5160, 0x5410, 0x55D0, 0x5780, 0x5840, 0x5890, 0x5A20, 0x5BA0, 0x5D90, 0x5FB0, 0x61F0, 0x65C0, + 0x68F0, 0x6E30, 0x7460, 0x7A50, 0x7EB0, 0x7EA0, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7EA0, 0x7F10, 0x7F00, 0x7EF0, 0x7EF0, 0x7EB0, + 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7EF0, 0x7F70, 0x7D30, 0x6E40, 0x5DF0, 0x4B70, 0x3AC0, + 0x2A60, 0x1B80, 0x0EA0, 0x03E0, 0xFBA0, 0xF810, 0xF920, 0xFE60, 0x04C0, 0x09D0, 0x0C60, 0x0B40, 0x05F0, 0xFBD0, 0xED90, 0xDC80, + 0xC800, 0xB130, 0x9860, 0x87C0, 0x8500, 0x84D0, 0x84B0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8470, 0x8470, + 0x8460, 0x8460, 0x8450, 0x8440, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8420, 0x8420, 0x8420, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8470, + 0x8470, 0x8470, 0x8470, 0x84A0, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8450, + 0x8450, 0x8450, 0x8430, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8470, 0x8480, 0x8490, 0x84B0, 0x84E0, 0x8560, 0x88B0, + 0x9A10, 0xADA0, 0xBDF0, 0xCC40, 0xD8C0, 0xE430, 0xEF00, 0xF970, 0x0310, 0x0B30, 0x1200, 0x1660, 0x17F0, 0x1870, 0x17A0, 0x1670, + 0x1510, 0x1380, 0x1180, 0x0E10, 0x0980, 0x03E0, 0xFDA0, 0xF7B0, 0xF180, 0xEBA0, 0xE580, 0xDF40, 0xD970, 0xD3C0, 0xCF00, 0xCB40, + 0xC800, 0xC510, 0xC2E0, 0xC170, 0xBFD0, 0xBEF0, 0xBF80, 0xC030, 0xC1B0, 0xC450, 0xC6C0, 0xC9B0, 0xCE00, 0xD360, 0xD940, 0xDF30, + 0xE650, 0xEEE0, 0xF850, 0x0250, 0x0D70, 0x18C0, 0x2230, 0x2C60, 0x3560, 0x3E10, 0x4610, 0x4D90, 0x5520, 0x5C80, 0x6380, 0x6A90, + 0x71F0, 0x7880, 0x7D60, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7EB0, 0x7F20, + 0x7EF0, 0x7EF0, 0x7EF0, 0x7E70, 0x7EF0, 0x7EF0, 0x7F00, 0x7EE0, 0x7EC0, 0x7EF0, 0x7EB0, 0x7F40, 0x7F10, 0x7EC0, 0x7F40, 0x7EF0, + 0x7F30, 0x7F20, 0x7F00, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F10, 0x7EE0, 0x7EF0, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F00, + 0x7F00, 0x7F10, 0x7F50, 0x7EB0, 0x7E70, 0x7EF0, 0x7F00, 0x7F20, 0x7ED0, 0x7EB0, 0x7F20, 0x7F00, 0x7F40, 0x7ED0, 0x7EA0, 0x7F10, + 0x7F10, 0x7F20, 0x7EE0, 0x7E90, 0x7F10, 0x7F10, 0x7F20, 0x7F40, 0x7EB0, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, + 0x7F20, 0x7F40, 0x7F00, 0x7F60, 0x7F20, 0x7F40, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F10, 0x7EF0, 0x7EF0, 0x7F90, 0x7F10, 0x7F00, + 0x7F00, 0x7ED0, 0x7F30, 0x7F00, 0x7EF0, 0x7EF0, 0x7EE0, 0x7F40, 0x7EF0, 0x7EB0, 0x7EE0, 0x7F00, 0x7F30, 0x7F20, 0x7EC0, 0x7C90, + 0x7650, 0x6EE0, 0x6920, 0x6410, 0x61B0, 0x60C0, 0x6050, 0x6210, 0x6480, 0x6800, 0x6A50, 0x6C30, 0x6DB0, 0x6DE0, 0x6BD0, 0x68B0, + 0x63A0, 0x5E00, 0x5750, 0x5010, 0x47C0, 0x3E40, 0x3470, 0x28C0, 0x1DC0, 0x1270, 0x0670, 0xFAA0, 0xEED0, 0xE3D0, 0xDA30, 0xD270, + 0xCC10, 0xC7A0, 0xC540, 0xC390, 0xC1F0, 0xC070, 0xBFC0, 0xC020, 0xC140, 0xC300, 0xC560, 0xC800, 0xCAF0, 0xCEE0, 0xD3B0, 0xD9C0, + 0xE050, 0xE660, 0xEDB0, 0xF300, 0xF820, 0xFCA0, 0x0090, 0x0590, 0x0880, 0x09F0, 0x0A50, 0x0900, 0x07A0, 0x0590, 0x0310, 0xFF20, + 0xFA70, 0xF440, 0xED20, 0xE5E0, 0xDDE0, 0xD5D0, 0xCE40, 0xC660, 0xBD80, 0xB380, 0xA7E0, 0x9B80, 0x8FA0, 0x8810, 0x85A0, 0x8510, + 0x84E0, 0x84C0, 0x84B0, 0x84A0, 0x8490, 0x8480, 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, + 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84D0, 0x8500, + 0x8580, 0x87C0, 0x92F0, 0xA430, 0xB5A0, 0xC5F0, 0xD6B0, 0xE400, 0xEF00, 0xF590, 0xF830, 0xF5E0, 0xEF50, 0xE5B0, 0xD9C0, 0xCB70, + 0xBFB0, 0xB590, 0xAFB0, 0xAD40, 0xAF10, 0xB3B0, 0xB930, 0xBE70, 0xC370, 0xC6B0, 0xC890, 0xC910, 0xC9B0, 0xC960, 0xC8D0, 0xC950, + 0xC9F0, 0xCBA0, 0xCB50, 0xC8B0, 0xC300, 0xB870, 0xAB30, 0x9A80, 0x8BD0, 0x8630, 0x8510, 0x84F0, 0x84D0, 0x84C0, 0x84B0, 0x84A0, + 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8470, + 0x8490, 0x8480, 0x8480, 0x8470, 0x8480, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, + 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8470, 0x8450, 0x8450, 0x8450, 0x8460, 0x8450, + 0x8460, 0x8460, 0x84A0, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x84A0, 0x84B0, 0x84D0, 0x8530, 0x85C0, 0x87C0, 0x8C90, 0x9270, + 0x9750, 0x9BE0, 0xA060, 0xA4F0, 0xA830, 0xA8A0, 0xA350, 0x9560, 0x87A0, 0x8510, 0x84D0, 0x8480, 0x8460, 0x8480, 0x8440, 0x8430, + 0x8430, 0x8450, 0x8420, 0x8410, 0x8420, 0x8400, 0x83F0, 0x83F0, 0x83D0, 0x83D0, 0x83D0, 0x83F0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, + 0x83C0, 0x83C0, 0x83F0, 0x83C0, 0x83D0, 0x83D0, 0x83F0, 0x83E0, 0x8400, 0x8400, 0x8420, 0x8430, 0x8440, 0x8410, 0x8460, 0x8460, + 0x8470, 0x8470, 0x8470, 0x8470, 0x84A0, 0x8490, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84A0, 0x84A0, 0x84A0, + 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84B0, 0x84C0, 0x84C0, 0x84E0, 0x8520, 0x8620, 0x8C10, 0x9DB0, 0xB020, 0xBEF0, 0xCC10, + 0xD700, 0xE0A0, 0xEA10, 0xF470, 0x0070, 0x0D20, 0x1AD0, 0x2790, 0x31E0, 0x3810, 0x39D0, 0x36A0, 0x2E30, 0x1FE0, 0x0CB0, 0xF400, + 0xDB90, 0xC530, 0xB1D0, 0xA370, 0x9970, 0x9280, 0x8DB0, 0x8AE0, 0x88A0, 0x8780, 0x86C0, 0x8630, 0x85E0, 0x85C0, 0x85D0, 0x85E0, + 0x85F0, 0x8610, 0x8640, 0x8690, 0x8760, 0x8930, 0x8DE0, 0x9600, 0xA080, 0xAB00, 0xB5D0, 0xBE20, 0xC4C0, 0xC9E0, 0xCE10, 0xD1E0, + 0xD5E0, 0xDAA0, 0xE0F0, 0xE840, 0xEF50, 0xF680, 0xFC60, 0x0160, 0x04C0, 0x0600, 0x03A0, 0xFE90, 0xF750, 0xED60, 0xE220, 0xD5D0, + 0xC890, 0xBB00, 0xACE0, 0x9C40, 0x8CF0, 0x8610, 0x84E0, 0x84B0, 0x8490, 0x8470, 0x8460, 0x8450, 0x8440, 0x8440, 0x8430, 0x8430, + 0x8420, 0x8430, 0x8410, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, + 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8420, 0x8420, 0x8430, + 0x8430, 0x8440, 0x8450, 0x8460, 0x8480, 0x8490, 0x84B0, 0x84D0, 0x84F0, 0x8520, 0x85A0, 0x86F0, 0x8B10, 0x9640, 0xA3A0, 0xB1D0, + 0xBFD0, 0xCDB0, 0xDBB0, 0xE8E0, 0xF6E0, 0x0240, 0x0B90, 0x13E0, 0x1A40, 0x1FF0, 0x2420, 0x2880, 0x2C40, 0x2F10, 0x3110, 0x3260, + 0x33A0, 0x3590, 0x3930, 0x3F30, 0x4900, 0x5650, 0x6770, 0x7810, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F20, 0x7F40, + 0x7F30, 0x7F30, 0x7F00, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F20, + 0x7F10, 0x7F20, 0x7F20, 0x7EF0, 0x66D0, 0x4E00, 0x36C0, 0x21C0, 0x1030, 0x00E0, 0xF090, 0xDED0, 0xC7D0, 0xAB10, 0x8C00, 0x84F0, + 0x84A0, 0x8480, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8490, 0x84A0, 0x84F0, 0x84E0, 0x8520, 0x85F0, + 0x8990, 0x96D0, 0xA570, 0xB2B0, 0xBEA0, 0xCA80, 0xD410, 0xDC70, 0xE500, 0xEE10, 0xF790, 0x01B0, 0x0B50, 0x14D0, 0x1D60, 0x2500, + 0x2B10, 0x3050, 0x3690, 0x3BA0, 0x41C0, 0x4840, 0x4E30, 0x5620, 0x5C90, 0x6300, 0x6820, 0x6BC0, 0x6ED0, 0x7070, 0x72A0, 0x74F0, + 0x7770, 0x7AA0, 0x7D00, 0x7ED0, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F30, 0x7F00, 0x7F10, 0x7EB0, 0x7EC0, 0x7ED0, 0x7EB0, 0x7EE0, + 0x7F10, 0x7EA0, 0x7EA0, 0x7ED0, 0x7F10, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7E70, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, + 0x7F00, 0x7F10, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F50, 0x7F10, 0x7F10, 0x7EE0, 0x7EF0, 0x7F50, 0x7EF0, 0x7F20, 0x7EF0, 0x7F10, + 0x7F70, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7F80, 0x7EF0, 0x7EB0, 0x7F00, 0x7EF0, 0x7F50, 0x7EE0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F40, + 0x7EE0, 0x7E90, 0x7F00, 0x7EE0, 0x7EF0, 0x7F10, 0x7E70, 0x7EF0, 0x7EF0, 0x7F20, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F00, + 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F50, 0x7F00, 0x7F40, 0x7F40, 0x7F10, 0x7F70, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F00, + 0x7F60, 0x7F10, 0x7F20, 0x7F00, 0x7F00, 0x7F70, 0x7F10, 0x7EB0, 0x7EE0, 0x7ED0, 0x7F30, 0x7F00, 0x7EC0, 0x7ED0, 0x7EE0, 0x7F20, + 0x7F10, 0x7E90, 0x7EB0, 0x7ED0, 0x7F10, 0x7F00, 0x7E80, 0x7ED0, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F00, 0x7F20, 0x7F10, 0x7F10, + 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7EE0, 0x7F40, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7EF0, 0x7F10, 0x7EE0, + 0x7F50, 0x7EF0, 0x7F20, 0x7F00, 0x7F10, 0x7F70, 0x7EB0, 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7EE0, 0x7EB0, 0x7F10, 0x7F20, 0x7F40, + 0x7F00, 0x7EC0, 0x7F10, 0x7F00, 0x7F20, 0x7ED0, 0x7EB0, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7EB0, 0x7F20, 0x7F10, 0x7F10, 0x7F10, + 0x7F00, 0x7F40, 0x7F00, 0x7F00, 0x7F10, 0x7F00, 0x7F60, 0x7E90, 0x7F00, 0x7EF0, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F00, 0x7F10, + 0x7F20, 0x7EF0, 0x7F80, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F70, 0x7EE0, 0x7F10, 0x7EF0, 0x7EE0, 0x7F70, 0x7F10, 0x7F00, 0x7F00, + 0x7EE0, 0x7F50, 0x7F00, 0x7EE0, 0x7ED0, 0x7EB0, 0x7F30, 0x7EF0, 0x7E90, 0x7ED0, 0x7F00, 0x7F30, 0x7F20, 0x7EA0, 0x7ED0, 0x7F10, + 0x7F10, 0x7F00, 0x7EC0, 0x7F10, 0x7EF0, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F10, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F00, + 0x7EF0, 0x7F10, 0x7F60, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7EE0, 0x7EF0, 0x7F80, 0x7F00, 0x7EE0, 0x7EF0, + 0x7F10, 0x7F70, 0x7F00, 0x7ED0, 0x7F10, 0x7EF0, 0x7F20, 0x7ED0, 0x7EC0, 0x7EF0, 0x7F10, 0x7F30, 0x7EE0, 0x7EC0, 0x7F10, 0x7F00, + 0x7EF0, 0x7ED0, 0x7E90, 0x7F00, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F30, 0x7F00, 0x7F00, + 0x7EF0, 0x7F10, 0x7F80, 0x7EF0, 0x7F20, 0x7F20, 0x7F00, 0x7F90, 0x7EF0, 0x7F00, 0x7EE0, 0x7EF0, 0x7F70, 0x7EE0, 0x7EF0, 0x7EF0, + 0x7F00, 0x7F60, 0x7F10, 0x7EB0, 0x7EB0, 0x7EF0, 0x7F60, 0x7EF0, 0x7EC0, 0x7ED0, 0x7F00, 0x7F20, 0x7F10, 0x7E90, 0x7EE0, 0x7EE0, + 0x7F10, 0x7F10, 0x7E90, 0x7E60, 0x7EF0, 0x7F10, 0x7F20, 0x7E90, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F20, 0x7EE0, 0x7EF0, + 0x7F00, 0x7EE0, 0x7F40, 0x7EF0, 0x7F20, 0x7F40, 0x7EC0, 0x7F10, 0x7EF0, 0x7F10, 0x7F00, 0x7EC0, 0x7EF0, 0x7F10, 0x7F20, 0x7F40, + 0x7F00, 0x7F30, 0x7EF0, 0x7F20, 0x7F20, 0x7F00, 0x7F90, 0x7F10, 0x7F10, 0x7EF0, 0x7EF0, 0x7F70, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, + 0x7F60, 0x7F10, 0x7EB0, 0x7EB0, 0x7EF0, 0x7F60, 0x7EF0, 0x7ED0, 0x7EF0, 0x7F00, 0x7F40, 0x7EF0, 0x7E90, 0x7EE0, 0x7EE0, 0x7F10, + 0x7F10, 0x7E70, 0x7EC0, 0x7EF0, 0x7F10, 0x7F20, 0x7E90, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F20, 0x7F20, 0x7EF0, 0x7F10, + 0x7EC0, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F50, 0x7F10, 0x7F40, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7A60, + 0x7140, 0x67E0, 0x5F90, 0x57B0, 0x4FF0, 0x47C0, 0x4070, 0x3830, 0x3160, 0x29E0, 0x21E0, 0x1A40, 0x1190, 0x0890, 0xFE70, 0xF3D0, + 0xEA50, 0xE040, 0xD6C0, 0xCD30, 0xC470, 0xBC40, 0xB410, 0xACF0, 0xA6E0, 0xA110, 0x9D60, 0x99F0, 0x9830, 0x9720, 0x96D0, 0x97E0, + 0x9960, 0x9BC0, 0x9ED0, 0xA200, 0xA520, 0xA8C0, 0xAC90, 0xB100, 0xB500, 0xB950, 0xBD30, 0xC080, 0xC550, 0xC900, 0xCBD0, 0xCE10, + 0xD090, 0xD240, 0xD3F0, 0xD5D0, 0xD750, 0xD8C0, 0xD9F0, 0xDAD0, 0xDBC0, 0xDC40, 0xDD00, 0xDDD0, 0xDF10, 0xE080, 0xE210, 0xE380, + 0xE5B0, 0xE760, 0xE8C0, 0xEAF0, 0xED60, 0xF140, 0xF540, 0xF990, 0xFDC0, 0x0110, 0x0480, 0x0820, 0x0B40, 0x0E30, 0x1090, 0x12A0, + 0x15C0, 0x1800, 0x1990, 0x1BA0, 0x1D80, 0x1E90, 0x1F50, 0x2000, 0x20F0, 0x2180, 0x2240, 0x2370, 0x23A0, 0x23B0, 0x2400, 0x24C0, + 0x24D0, 0x2470, 0x24C0, 0x2490, 0x2430, 0x2490, 0x2340, 0x21E0, 0x1FD0, 0x1CD0, 0x19E0, 0x1650, 0x1290, 0x0EE0, 0x0980, 0x0310, + 0xFBF0, 0xF3C0, 0xEAC0, 0xE0E0, 0xD820, 0xD050, 0xC900, 0xC2A0, 0xBCA0, 0xB6E0, 0xB110, 0xABB0, 0xA700, 0xA250, 0x9E40, 0x9950, + 0x94E0, 0x90C0, 0x8D70, 0x8AE0, 0x88B0, 0x8790, 0x8680, 0x85E0, 0x8590, 0x8540, 0x8520, 0x8500, 0x84F0, 0x84E0, 0x84D0, 0x84D0, + 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x8480, 0x8480, 0x8480, 0x8480, + 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, + 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8470, 0x8470, 0x8470, 0x8470, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, 0x8470, + 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, + 0x8460, 0x8460, 0x8460, 0x8450, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, + 0x8460, 0x8460, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8470, 0x8480, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, + 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8450, 0x8460, + 0x8450, 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8430, 0x8440, 0x8470, 0x8430, 0x8430, 0x8430, 0x8470, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8450, 0x8460, 0x8420, 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8400, + 0x8400, 0x8400, 0x8400, 0x83F0, 0x8400, 0x83F0, 0x83E0, 0x83E0, 0x8400, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x8410, 0x83C0, 0x83C0, + 0x83C0, 0x83A0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, + 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8450, + 0x8450, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84E0, 0x84F0, 0x8520, 0x85A0, 0x86E0, + 0x8A40, 0x93B0, 0x9F50, 0xA8D0, 0xB1D0, 0xBA40, 0xC200, 0xC8F0, 0xD020, 0xD5A0, 0xD980, 0xDD20, 0xDF70, 0xE190, 0xE240, 0xE120, + 0xDE30, 0xD7A0, 0xD050, 0xC480, 0xB4B0, 0xA1F0, 0x8D30, 0x8580, 0x84D0, 0x84A0, 0x8480, 0x8470, 0x8470, 0x8460, 0x8450, 0x8450, + 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8460, 0x8460, 0x8480, 0x8490, 0x84C0, 0x8530, 0x89C0, + 0xA990, 0xC7D0, 0xE3D0, 0xFDF0, 0x12E0, 0x2440, 0x3190, 0x3D00, 0x4470, 0x48F0, 0x4BF0, 0x4D30, 0x4DF0, 0x4E10, 0x4DD0, 0x4EC0, + 0x4F40, 0x5150, 0x5490, 0x5760, 0x5C00, 0x60A0, 0x65F0, 0x6BA0, 0x7180, 0x7880, 0x7DA0, 0x7F40, 0x7F10, 0x7F10, 0x7F40, 0x7F00, + 0x7F30, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7F70, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F70, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F00, 0x7F60, + 0x7EF0, 0x7F10, 0x7F00, 0x7F00, 0x7F70, 0x7F10, 0x7EB0, 0x7EC0, 0x7ED0, 0x7F30, 0x7F20, 0x7E90, 0x7ED0, 0x7EE0, 0x7F20, 0x7F10, + 0x7E90, 0x7EE0, 0x7EE0, 0x7F10, 0x7F10, 0x7E70, 0x7EE0, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F00, + 0x7F20, 0x7EF0, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7F20, 0x7EF0, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7F00, 0x7F60, + 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7F80, 0x7F00, 0x7F10, 0x7EF0, 0x7EF0, 0x7F60, 0x7ED0, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7EF0, + 0x7EA0, 0x7F00, 0x7F10, 0x7F30, 0x7EE0, 0x7EC0, 0x7F10, 0x7F10, 0x7EF0, 0x7F10, 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F00, + 0x7F40, 0x7F10, 0x7F00, 0x7F20, 0x7EF0, 0x7F70, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F60, 0x7F10, 0x7F10, 0x7EF0, 0x7EE0, 0x7F80, + 0x7F10, 0x7F00, 0x7F00, 0x7F00, 0x7F80, 0x7F10, 0x7EF0, 0x7EE0, 0x7EE0, 0x7F50, 0x7F10, 0x7EA0, 0x7EE0, 0x7ED0, 0x7F30, 0x7F20, + 0x7EC0, 0x7ED0, 0x7EF0, 0x7F00, 0x7EF0, 0x7E90, 0x7EB0, 0x7ED0, 0x7F10, 0x7F20, 0x7EC0, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7340, + 0x5A80, 0x4030, 0x2540, 0x0B50, 0xF2D0, 0xDC30, 0xC6C0, 0xB1A0, 0xA050, 0x91F0, 0x8990, 0x86B0, 0x85D0, 0x85A0, 0x85C0, 0x8650, + 0x88E0, 0x91F0, 0xA270, 0xB5A0, 0xCB70, 0xE250, 0xF9B0, 0x1150, 0x26A0, 0x3BB0, 0x4C10, 0x5960, 0x63D0, 0x6AD0, 0x6FF0, 0x7340, + 0x73D0, 0x7390, 0x71C0, 0x6DD0, 0x69B0, 0x6400, 0x5DF0, 0x5680, 0x4DB0, 0x4520, 0x3C00, 0x3350, 0x2BA0, 0x2460, 0x1ED0, 0x1900, + 0x1420, 0x0E70, 0xF610, 0xEF50, 0xE8A0, 0xE400, 0xE090, 0xDFB0, 0xE2E0, 0xE820, 0xEF40, 0xF720, 0xFD40, 0x0190, 0x0380, 0x0390, + 0x02F0, 0x0240, 0x02D0, 0x0450, 0x06F0, 0x0B40, 0x11C0, 0x19D0, 0x2160, 0x29E0, 0x3140, 0x3830, 0x3FE0, 0x4820, 0x4F90, 0x5770, + 0x60B0, 0x6990, 0x7170, 0x7840, 0x7D40, 0x7EB0, 0x7F00, 0x7F00, 0x7F40, 0x7EF0, 0x7EB0, 0x7F00, 0x7F10, 0x7F10, 0x7EF0, 0x7F00, + 0x7F00, 0x7EF0, 0x7ED0, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F20, + 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F50, 0x7F30, 0x7F30, 0x7F20, 0x7F40, + 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, + 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, + 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F30, 0x7F20, + 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F10, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, + 0x7F30, 0x7F30, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, + 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F40, 0x7F20, 0x7F30, 0x7F30, 0x7F20, + 0x7F50, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, + 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F40, + 0x7F30, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, + 0x7F20, 0x7F20, 0x7ED0, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F00, 0x7F40, 0x7F00, 0x7F10, 0x7EF0, 0x7EC0, 0x7ED0, 0x7EB0, 0x7F20, + 0x7EC0, 0x7EF0, 0x65D0, 0x4360, 0x1E80, 0xF5A0, 0xCFE0, 0xA960, 0x8A20, 0x84F0, 0x84B0, 0x8490, 0x8480, 0x8490, 0x8460, 0x8460, + 0x8470, 0x8460, 0x8450, 0x8460, 0x8490, 0x8470, 0x8480, 0x8490, 0x84A0, 0x84C0, 0x8500, 0x85F0, 0x8E80, 0xA650, 0xBBF0, 0xCF30, + 0xE1B0, 0xF1B0, 0xFFB0, 0x0CE0, 0x1A00, 0x25B0, 0x3120, 0x3B80, 0x4450, 0x4CB0, 0x52C0, 0x5800, 0x5B40, 0x5DB0, 0x5F30, 0x5FE0, + 0x6090, 0x6110, 0x60F0, 0x6130, 0x6120, 0x61C0, 0x60F0, 0x6050, 0x6030, 0x5F70, 0x5FD0, 0x5EB0, 0x5CE0, 0x5A90, 0x5710, 0x5360, + 0x4EA0, 0x4950, 0x4350, 0x3CE0, 0x36C0, 0x3050, 0x2A30, 0x2440, 0x1CE0, 0x1650, 0x0F30, 0x0780, 0x00F0, 0xF9A0, 0xF420, 0xEEA0, + 0xEA10, 0xE6B0, 0xE2A0, 0xDF60, 0xDB30, 0xD670, 0xD200, 0xCD80, 0xC9A0, 0xC670, 0xC320, 0xC030, 0xBC80, 0xB960, 0xB6D0, 0xB380, + 0xB170, 0xAF00, 0xAC00, 0xA950, 0xA580, 0xA280, 0x9FE0, 0x9DC0, 0x9B10, 0x98A0, 0x9670, 0x9450, 0x9240, 0x90E0, 0x8F90, 0x8E60, + 0x8D20, 0x8BF0, 0x8BA0, 0x8B10, 0x8B30, 0x8B50, 0x8B50, 0x8BB0, 0x8BB0, 0x8B90, 0x8BB0, 0x8C10, 0x8D20, 0x8EA0, 0x8FD0, 0x9050, + 0x90A0, 0x91C0, 0x9270, 0x9470, 0x9630, 0x97A0, 0x9980, 0x9AF0, 0x9D00, 0x9FB0, 0xA210, 0xA510, 0xA880, 0xABC0, 0xAE40, 0xB160, + 0xB580, 0xB9C0, 0xBE70, 0xC2B0, 0xC670, 0xCB20, 0xCFB0, 0xD410, 0xD8F0, 0xDD80, 0xE230, 0xE690, 0xEA90, 0xEF20, 0xF3D0, 0xF830, + 0xFBE0, 0xFF60, 0x0350, 0x0770, 0x0B20, 0x0E70, 0x11F0, 0x15B0, 0x18E0, 0x1C30, 0x1EF0, 0x2170, 0x24C0, 0x2790, 0x2C50, 0x3100, + 0x3610, 0x3A70, 0x3D60, 0x4150, 0x4510, 0x4900, 0x4E20, 0x5380, 0x58D0, 0x5D70, 0x60A0, 0x6C80, 0x6F70, 0x71F0, 0x7360, 0x7550, + 0x7690, 0x7730, 0x7840, 0x7880, 0x7890, 0x78A0, 0x77B0, 0x7800, 0x7740, 0x7750, 0x7710, 0x75F0, 0x7520, 0x73C0, 0x7300, 0x7240, + 0x70C0, 0x6F30, 0x6D20, 0x6B80, 0x69E0, 0x67D0, 0x66F0, 0x6520, 0x6350, 0x6130, 0x5F60, 0x5D80, 0x5B80, 0x59B0, 0x5840, 0x5740, + 0x56D0, 0x5560, 0x53F0, 0x5310, 0x52B0, 0x5300, 0x5260, 0x51D0, 0x50F0, 0x4F70, 0x4DF0, 0x4D00, 0x4B70, 0x4B10, 0x4A10, 0x49B0, + 0x4960, 0x47E0, 0x46F0, 0x4540, 0x4490, 0x43A0, 0x4180, 0x4010, 0x3D90, 0x3B20, 0x3800, 0x3570, 0x32F0, 0x2FB0, 0x2C30, 0x2820, + 0x23C0, 0x1FF0, 0x1BC0, 0x1780, 0x1390, 0x0EA0, 0x0AA0, 0x0690, 0x0350, 0x0020, 0xFD40, 0xFB90, 0xF9E0, 0xF860, 0xF770, 0xF730, + 0xF7F0, 0xF940, 0xFB30, 0xFE90, 0x01E0, 0x0620, 0x0AF0, 0x10C0, 0x1680, 0x1B10, 0x2100, 0x26E0, 0x2BF0, 0x31F0, 0x3730, 0x3E00, + 0x43F0, 0x49B0, 0x4FA0, 0x5400, 0x5810, 0x5BB0, 0x5F60, 0x6380, 0x6680, 0x6960, 0x6B80, 0x6CD0, 0x6F10, 0x6FA0, 0x70C0, 0x7190, + 0x7230, 0x72C0, 0x7280, 0x7380, 0x7420, 0x7500, 0x76F0, 0x7890, 0x7930, 0x7940, 0x78D0, 0x7870, 0x7800, 0x7610, 0x7270, 0x6C60, + 0x65A0, 0x5D90, 0x5690, 0x4F60, 0x4770, 0x40A0, 0x38E0, 0x3070, 0x27E0, 0x2060, 0x1B70, 0x1910, 0x19F0, 0x1D60, 0x21D0, 0x2630, + 0x28B0, 0x2970, 0x2950, 0x2790, 0x25E0, 0x2320, 0x20B0, 0x1F60, 0x1D20, 0x1AD0, 0x1690, 0x10F0, 0x0960, 0xFF80, 0xF410, 0xE570, + 0xD570, 0xC510, 0xB380, 0xA140, 0x8F50, 0x86D0, 0x8510, 0x84D0, 0x84B0, 0x8490, 0x84B0, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, + 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, + 0x8460, 0x8450, 0x8450, 0x8440, 0x8440, 0x8470, 0x8430, 0x8430, 0x8430, 0x8410, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, + 0x8430, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8410, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, + 0x83F0, 0x83F0, 0x83E0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, + 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, 0x8410, 0x8450, 0x8450, 0x8460, + 0x8460, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84D0, 0x84E0, 0x8500, + 0x8530, 0x8590, 0x8640, 0x8890, 0x8C90, 0x9340, 0x9AC0, 0xA190, 0xA8C0, 0xAFA0, 0xB5C0, 0xBCA0, 0xC2B0, 0xC870, 0xCDA0, 0xD1E0, + 0xD5C0, 0xD9A0, 0xDDE0, 0xE230, 0xE6B0, 0xEAA0, 0xED70, 0xF010, 0xF1F0, 0xF3D0, 0xF520, 0xF6A0, 0xF780, 0xF830, 0xF8A0, 0xF8F0, + 0xF960, 0xFA60, 0xF990, 0xF7F0, 0xF760, 0xF6F0, 0xF6C0, 0xF7F0, 0xFA30, 0xFBF0, 0xFEA0, 0x0030, 0x01C0, 0x0320, 0x03D0, 0x03E0, + 0x0300, 0x0240, 0x00D0, 0xFF70, 0xFEA0, 0xFDC0, 0xFCD0, 0xFBA0, 0xFA90, 0xFAA0, 0xFB60, 0xFBE0, 0xFCF0, 0xFDD0, 0xFEB0, 0xFEE0, + 0xFF80, 0xFF70, 0xFF10, 0xFF40, 0xFFD0, 0x01D0, 0x05B0, 0x0BE0, 0x1360, 0x1C10, 0x24A0, 0x2B70, 0x3050, 0x3400, 0x37B0, 0x3AD0, + 0x3E90, 0x4380, 0x48C0, 0x4E90, 0x53B0, 0x5760, 0x5B10, 0x5F50, 0x62B0, 0x6620, 0x69F0, 0x6E70, 0x7270, 0x75C0, 0x7870, 0x7AB0, + 0x7CE0, 0x7E60, 0x7F10, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, + 0x7F40, 0x7F30, 0x7BE0, 0x7320, 0x6A60, 0x5FF0, 0x53F0, 0x44C0, 0x3470, 0x2150, 0x0B50, 0xF260, 0xD6C0, 0xB8F0, 0x99E0, 0x86E0, + 0x84E0, 0x84B0, 0x8490, 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, + 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84B0, 0x84C0, 0x84C0, 0x84D0, 0x84E0, 0x84F0, 0x8500, 0x8510, 0x8540, 0x8580, + 0x85E0, 0x8660, 0x8750, 0x8820, 0x8990, 0x8B10, 0x8C40, 0x8CC0, 0x8D20, 0x8CD0, 0x8B70, 0x8A00, 0x8850, 0x86E0, 0x85E0, 0x8540, + 0x8500, 0x84D0, 0x84D0, 0x84A0, 0x8490, 0x8480, 0x8460, 0x8450, 0x8450, 0x8440, 0x8430, 0x8430, 0x8420, 0x8420, 0x8420, 0x8410, + 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, + 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8480, 0x8430, 0x8430, 0x8440, 0x8430, 0x8440, + 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8480, 0x8450, 0x8450, 0x8450, + 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, + 0x8490, 0x8490, 0x84B0, 0x84B0, 0x84C0, 0x84E0, 0x8510, 0x8570, 0x8690, 0x8A20, 0x9430, 0x9F80, 0xAA10, 0xB350, 0xBCA0, 0xC500, + 0xCC40, 0xD430, 0xDC00, 0xE300, 0xEB20, 0xF220, 0xFA30, 0x01D0, 0x0930, 0x11C0, 0x1A00, 0x21B0, 0x29C0, 0x3270, 0x3BF0, 0x4480, + 0x4C80, 0x5440, 0x5B10, 0x6210, 0x67B0, 0x6CE0, 0x7270, 0x76A0, 0x7AE0, 0x7E40, 0x7F70, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F60, + 0x7F10, 0x7F10, 0x7F00, 0x7EE0, 0x7F70, 0x7EF0, 0x7EE0, 0x7F00, 0x7F10, 0x7F70, 0x7F00, 0x7ED0, 0x7F10, 0x7F00, 0x7F20, 0x7ED0, + 0x7EB0, 0x7EF0, 0x7F10, 0x7F30, 0x7EE0, 0x7E90, 0x7F10, 0x7F00, 0x7EF0, 0x7F10, 0x7E90, 0x7F00, 0x7EF0, 0x7EF0, 0x7F20, 0x7F00, + 0x7F40, 0x7ED0, 0x7F10, 0x7F40, 0x7F00, 0x7F30, 0x7EF0, 0x7F00, 0x7EF0, 0x7F10, 0x7F80, 0x7F00, 0x7F10, 0x7F00, 0x7F10, 0x7F10, + 0x7EC0, 0x7F30, 0x7F00, 0x7F20, 0x7F40, 0x7F00, 0x7F60, 0x7EE0, 0x7F10, 0x7F20, 0x7EF0, 0x7F80, 0x7F10, 0x7F20, 0x7F00, 0x7EF0, + 0x7F70, 0x7EF0, 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, 0x7EF0, 0x7EF0, 0x7F00, 0x7EE0, 0x7F50, 0x7F10, 0x7C90, 0x5530, 0x33E0, 0x16D0, + 0xFE10, 0xE650, 0xCDA0, 0xB100, 0x8E60, 0x8510, 0x84B0, 0x8490, 0x8480, 0x8470, 0x8480, 0x8480, 0x8490, 0x84A0, 0x84C0, 0x84E0, + 0x8510, 0x8580, 0x8660, 0x8850, 0x8D90, 0x97C0, 0xA3F0, 0xAF10, 0xB760, 0xBB10, 0xB740, 0xAE30, 0xA000, 0x8FA0, 0x8700, 0x8520, + 0x84E0, 0x84C0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, + 0x84A0, 0x84B0, 0x84C0, 0x84F0, 0x8510, 0x8550, 0x85F0, 0x8760, 0x8B70, 0x9400, 0x9F80, 0xAB40, 0xB780, 0xC370, 0xCF90, 0xDD00, + 0xEB40, 0xFB50, 0x0CD0, 0x1DF0, 0x2D50, 0x3A80, 0x4600, 0x4F70, 0x5800, 0x60C0, 0x68D0, 0x70B0, 0x7880, 0x7DA0, 0x7F20, 0x7F20, + 0x7F50, 0x7F10, 0x7F00, 0x7EE0, 0x7EF0, 0x7F70, 0x7EE0, 0x7EF0, 0x7F00, 0x7F00, 0x7F60, 0x7F10, 0x7EB0, 0x7EB0, 0x7EF0, 0x7F30, + 0x7F00, 0x7EA0, 0x7ED0, 0x7ED0, 0x7F20, 0x7F20, 0x7E90, 0x7EE0, 0x7ED0, 0x7F10, 0x7F00, 0x7E80, 0x7ED0, 0x7F10, 0x7F20, 0x7F20, + 0x7E90, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7F00, 0x7F10, 0x7F00, 0x7EE0, 0x7F40, 0x7F20, 0x7F20, 0x7F10, 0x7F10, + 0x7F30, 0x7EE0, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F70, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F60, + 0x7ED0, 0x7EB0, 0x7F00, 0x7F20, 0x7F50, 0x7EF0, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EA0, 0x7EF0, 0x7F00, 0x7EF0, 0x7EF0, + 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7EF0, 0x7F60, 0x7F00, 0x7F40, 0x7F10, 0x7F20, + 0x7F60, 0x7EF0, 0x7F10, 0x7EF0, 0x7EE0, 0x7F80, 0x7F10, 0x7F00, 0x7F20, 0x7F00, 0x7F80, 0x7F10, 0x7EF0, 0x7EE0, 0x7EE0, 0x7F50, + 0x7F10, 0x7EE0, 0x7EE0, 0x7ED0, 0x7F30, 0x7F20, 0x7EC0, 0x7ED0, 0x7EF0, 0x7F00, 0x7F10, 0x7E90, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, + 0x7EA0, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7EC0, 0x7F10, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7F60, 0x7F10, 0x7F20, 0x7F20, 0x7F00, + 0x7F50, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F50, 0x7EF0, 0x7F20, 0x7F00, 0x7F10, 0x7F50, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F70, + 0x7EE0, 0x7ED0, 0x7EF0, 0x7F10, 0x7F20, 0x7F10, 0x7F00, 0x7EF0, 0x7EF0, 0x7EE0, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7340, + 0x56F0, 0x3D50, 0x2850, 0x1980, 0x0FE0, 0x0AF0, 0x0A60, 0x0C10, 0x0FC0, 0x14F0, 0x1B80, 0x2360, 0x2C50, 0x35F0, 0x3FF0, 0x4A40, + 0x5500, 0x5DA0, 0x65A0, 0x6B30, 0x70B0, 0x75B0, 0x79D0, 0x7C90, 0x7E80, 0x7F10, 0x7F30, 0x7F00, 0x7E40, 0x7BB0, 0x77B0, 0x7300, + 0x6EA0, 0x6AC0, 0x6710, 0x62B0, 0x5D00, 0x5510, 0x4A90, 0x3C70, 0x2B20, 0x1760, 0x02F0, 0xECA0, 0xD880, 0xC530, 0xB3F0, 0xA430, + 0x95C0, 0x8B80, 0x8710, 0x8590, 0x8520, 0x84F0, 0x84E0, 0x8460, 0x84D0, 0x84D0, 0x84D0, 0x84F0, 0x8520, 0x85C0, 0x87F0, 0x9090, + 0x9D60, 0xA950, 0xB470, 0xBF80, 0xCA00, 0xD3B0, 0xDC90, 0xE300, 0xE860, 0xEC90, 0xF000, 0xF0F0, 0xF040, 0xEDF0, 0xE930, 0xE180, + 0xD8F0, 0xD020, 0xC780, 0xBFF0, 0xB980, 0xB450, 0xB060, 0xAE50, 0xAE20, 0xAF90, 0xB230, 0xB510, 0xB8F0, 0xBD70, 0xC350, 0xC940, + 0xE1A0, 0xE850, 0xEEB0, 0xF530, 0xFC00, 0x0240, 0x0830, 0x0E00, 0x12E0, 0x1710, 0x1B20, 0x1FA0, 0x23E0, 0x2730, 0x29F0, 0x2CA0, + 0x2EE0, 0x3110, 0x3270, 0x3370, 0x3570, 0x3620, 0x3740, 0x3930, 0x3BD0, 0x3F70, 0x43A0, 0x48B0, 0x4E20, 0x53C0, 0x5910, 0x5EB0, + 0x6570, 0x6B70, 0x7140, 0x76D0, 0x7AF0, 0x7DA0, 0x7EB0, 0x7EF0, 0x7EE0, 0x7E70, 0x7D30, 0x7A30, 0x7620, 0x7110, 0x6AD0, 0x6300, + 0x5A20, 0x50D0, 0x4730, 0x3DE0, 0x3500, 0x2D60, 0x2680, 0x20B0, 0x1C60, 0x18D0, 0x1590, 0x12A0, 0x1070, 0x0F50, 0x1020, 0x11A0, + 0x1400, 0x1710, 0x1B30, 0x2000, 0x2670, 0x2DB0, 0x3570, 0x3C20, 0x4340, 0x49C0, 0x5170, 0x58E0, 0x5F50, 0x6610, 0x6C20, 0x7240, + 0x7740, 0x7AD0, 0x7DB0, 0x7E50, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7F10, 0x7F10, 0x7F30, 0x7F20, 0x7F50, 0x7F10, + 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7D80, 0x7A40, 0x7710, 0x7330, 0x6F40, 0x6BD0, 0x6730, 0x6330, 0x5F00, 0x5AE0, 0x5770, 0x5440, + 0x5200, 0x5090, 0x4F30, 0x4EC0, 0x4D40, 0x4CB0, 0x4BB0, 0x4A50, 0x4A10, 0x49A0, 0x49E0, 0x4990, 0x48C0, 0x49E0, 0x4AC0, 0x4CC0, + 0x4E40, 0x4ED0, 0x4FD0, 0x5000, 0x5120, 0x5150, 0x5290, 0x5590, 0x5800, 0x5A10, 0x5B90, 0x5C80, 0x5DE0, 0x5F40, 0x6080, 0x62A0, + 0x63C0, 0x64F0, 0x66A0, 0x6840, 0x69C0, 0x6AD0, 0x6CB0, 0x6DF0, 0x6E60, 0x6E90, 0x6E70, 0x6F80, 0x70F0, 0x72B0, 0x7420, 0x7520, + 0x7650, 0x7650, 0x7670, 0x76C0, 0x7730, 0x7860, 0x7940, 0x79D0, 0x7AF0, 0x7B70, 0x7CC0, 0x7DD0, 0x7E80, 0x7EA0, 0x7E90, 0x7F10, + 0x7F20, 0x7F20, 0x7F10, 0x7ED0, 0x7F20, 0x7EE0, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, 0x7F20, 0x7F20, 0x7F00, 0x7F90, 0x7F20, + 0x7F40, 0x7F10, 0x7F10, 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7F00, 0x7F90, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F70, 0x7F00, 0x7EC0, + 0x7ED0, 0x7EE0, 0x7F80, 0x7F10, 0x7EE0, 0x7EE0, 0x7ED0, 0x7F30, 0x7F00, 0x7E70, 0x7ED0, 0x7EB0, 0x7F10, 0x7F00, 0x7E90, 0x7EF0, + 0x7F20, 0x7F20, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7F00, 0x7F30, 0x7F20, + 0x7F40, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7F10, 0x7F00, 0x7EF0, 0x7F50, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F70, 0x7EF0, 0x7F10, + 0x7EE0, 0x7EF0, 0x7F90, 0x7F00, 0x7EE0, 0x7F10, 0x7F10, 0x7F70, 0x7F00, 0x7EC0, 0x7EF0, 0x7F00, 0x7F40, 0x7ED0, 0x7EB0, 0x7F10, + 0x7ED0, 0x7EF0, 0x7EE0, 0x7F50, 0x7ED0, 0x7EC0, 0x7EF0, 0x7F00, 0x7F20, 0x7EE0, 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7EF0, 0x7E90, + 0x7F00, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F70, + 0x7F10, 0x7F10, 0x7EF0, 0x7EE0, 0x7F70, 0x7F10, 0x7F00, 0x7F00, 0x7ED0, 0x7F70, 0x7F20, 0x7ED0, 0x7ED0, 0x7EE0, 0x7EF0, 0x7EF0, + 0x7EB0, 0x7EC0, 0x7ED0, 0x7F30, 0x7F20, 0x7EC0, 0x7ED0, 0x7F10, 0x7F00, 0x7A60, 0x72C0, 0x6BA0, 0x65E0, 0x6050, 0x5C90, 0x5920, + 0x5740, 0x5580, 0x53B0, 0x52F0, 0x5130, 0x51B0, 0x51E0, 0x5210, 0x5310, 0x5400, 0x5440, 0x5490, 0x5410, 0x53E0, 0x5360, 0x5270, + 0x5130, 0x4E00, 0x4970, 0x42C0, 0x3A90, 0x3160, 0x25B0, 0x1990, 0x0BE0, 0xFD60, 0xED90, 0xDCF0, 0xCB60, 0xB800, 0xA2C0, 0x8D00, + 0x85B0, 0x84E0, 0x84B0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8460, 0x8450, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8420, + 0x8410, 0x8420, 0x8410, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, + 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8480, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x84C0, 0x84A0, 0x84A0, 0x84B0, 0x84C0, 0x84C0, 0x84C0, 0x84E0, + 0x84F0, 0x84F0, 0x8510, 0x8560, 0x8560, 0x85D0, 0x85F0, 0x8670, 0x8750, 0x88F0, 0x8B90, 0x8EC0, 0x91B0, 0x94F0, 0x9890, 0x9CA0, + 0xA170, 0xA6D0, 0xAC20, 0xAFF0, 0xB450, 0xB880, 0xBD00, 0xC1F0, 0xC740, 0xCD30, 0xD300, 0xD8D0, 0xDD70, 0xE1E0, 0xE700, 0xEAC0, + 0xEE00, 0xF0D0, 0xF270, 0xF3F0, 0xF500, 0xF6D0, 0xF840, 0xF920, 0xF8F0, 0xF830, 0xF6C0, 0xF5D0, 0xF490, 0xF390, 0xF140, 0xEE40, + 0xEAD0, 0xE710, 0xE400, 0xE140, 0xDEB0, 0xDCB0, 0xDA00, 0xD7F0, 0xD660, 0xD4C0, 0xD310, 0xD210, 0xD0B0, 0xCFE0, 0xCDB0, 0xCC70, + 0xCB00, 0xCB40, 0xCC20, 0xCD30, 0xCF20, 0xD010, 0xD170, 0xD390, 0xD660, 0xD950, 0xDBE0, 0xDE60, 0xE0C0, 0xE350, 0xE660, 0xE940, + 0xEC50, 0xEFC0, 0xF2E0, 0xF5E0, 0xF7B0, 0xF920, 0xF9A0, 0xF910, 0xF8F0, 0xF7D0, 0xF600, 0xF3C0, 0xF0C0, 0xEEC0, 0xEC60, 0xEA90, + 0xE930, 0xE7B0, 0xE710, 0xE5F0, 0xE560, 0xE570, 0xE5F0, 0xE7B0, 0xE9D0, 0xEB80, 0xEE40, 0xF110, 0xF430, 0xF770, 0xFB00, 0xFD90, + 0xFFF0, 0x0230, 0x0540, 0x08D0, 0x0CC0, 0x1140, 0x1580, 0x19D0, 0x1E60, 0x2350, 0x2910, 0x30E0, 0x38E0, 0x4180, 0x4B10, 0x5590, + 0x6020, 0x6BC0, 0x76D0, 0x7E90, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F20, 0x7F40, + 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F40, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F40, 0x7F40, 0x7F30, + 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7B70, 0x74B0, 0x6D30, + 0x6560, 0x5CF0, 0x5490, 0x4C60, 0x44C0, 0x3E30, 0x3880, 0x3330, 0x2E70, 0x2AD0, 0x26F0, 0x2440, 0x2200, 0x2070, 0x2010, 0x2100, + 0x2250, 0x24D0, 0x28F0, 0x2E30, 0x3390, 0x3940, 0x3E90, 0x4370, 0x45E0, 0x46C0, 0x4540, 0x4240, 0x3D90, 0x3830, 0x32E0, 0x2DD0, + 0x28A0, 0x2440, 0x2000, 0x1C60, 0x1920, 0x15E0, 0x1320, 0x1080, 0x0DF0, 0x0AE0, 0x0830, 0x0530, 0x02F0, 0x0080, 0xFDF0, 0xFA50, + 0xF690, 0xF230, 0xEDE0, 0xE950, 0xE550, 0xE120, 0xDD80, 0xD9F0, 0xD7A0, 0xD5D0, 0xD480, 0xD350, 0xD260, 0xD1A0, 0xD0D0, 0xD030, + 0xCFA0, 0xCF20, 0xCDD0, 0xCC80, 0xCA40, 0xC750, 0xC450, 0xC000, 0xBBC0, 0xB6F0, 0xB250, 0xAD00, 0xA800, 0xA280, 0x9D70, 0x98B0, + 0x94F0, 0x91E0, 0x8FC0, 0x8E00, 0x8CC0, 0x8BF0, 0x8BF0, 0x8C10, 0x8C90, 0x8DF0, 0x8EB0, 0x8F90, 0x9040, 0x90F0, 0x90E0, 0x90D0, + 0x8FC0, 0x8E60, 0x8D50, 0x8C00, 0x8A80, 0x8940, 0x8820, 0x8720, 0x8640, 0x85A0, 0x8540, 0x8540, 0x84F0, 0x84E0, 0x84D0, 0x84B0, + 0x84B0, 0x84A0, 0x84A0, 0x8490, 0x8480, 0x8480, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8450, 0x8430, 0x8430, 0x8430, 0x8420, 0x8430, + 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8440, + 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, + 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84E0, + 0x8500, 0x8540, 0x85B0, 0x8670, 0x8750, 0x8800, 0x88A0, 0x89F0, 0x8C00, 0x9010, 0x9400, 0x96E0, 0x9880, 0x9810, 0x95F0, 0x91A0, + 0x8C20, 0x87F0, 0x8600, 0x8530, 0x84F0, 0x8500, 0x84F0, 0x84B0, 0x84B0, 0x84D0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8470, + 0x8470, 0x8480, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8480, 0x84A0, 0x8490, 0x8490, 0x8490, + 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8480, 0x8490, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, + 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84C0, 0x84D0, 0x84D0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84F0, 0x84F0, 0x84F0, + 0x84F0, 0x8500, 0x8500, 0x8500, 0x84F0, 0x84F0, 0x84E0, 0x84E0, 0x84D0, 0x84D0, 0x84E0, 0x84C0, 0x84D0, 0x84B0, 0x84A0, 0x84A0, + 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, + 0x8470, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x84C0, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, + 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84D0, 0x84E0, 0x84E0, 0x8500, 0x8510, 0x8530, 0x8570, 0x85C0, 0x8670, 0x8760, + 0x88A0, 0x8A90, 0x8D00, 0x8FC0, 0x92D0, 0x95D0, 0x9980, 0x9CD0, 0x9FF0, 0xA2E0, 0xA620, 0xA960, 0xAC70, 0xAF40, 0xB1D0, 0xB3B0, + 0xB5B0, 0xB7A0, 0xB970, 0xBC30, 0xBEB0, 0xC1A0, 0xC430, 0xC6B0, 0xC8C0, 0xCA30, 0xCBD0, 0xCD70, 0xCE40, 0xCF00, 0xCFD0, 0xD130, + 0xD270, 0xD330, 0xD460, 0xD540, 0xD640, 0xD750, 0xD730, 0xD820, 0xD780, 0xD7F0, 0xD820, 0xD8A0, 0xD8F0, 0xD860, 0xD760, 0xD670, + 0xD510, 0xD430, 0xD2C0, 0xD150, 0xCFE0, 0xCD70, 0xCB70, 0xC910, 0xC680, 0xC430, 0xC1C0, 0xC010, 0xBEC0, 0xBD10, 0xBBF0, 0xBB30, + 0xBB10, 0xB9F0, 0xB930, 0xB8A0, 0xB8E0, 0xB9E0, 0xBAC0, 0xBC20, 0xBDF0, 0xBE80, 0xBF40, 0xBF30, 0xBF30, 0xBFB0, 0xC010, 0xC180, + 0xC170, 0xC130, 0xBFB0, 0xBDD0, 0xBBE0, 0xB8F0, 0xB610, 0xB3B0, 0xB110, 0xAE20, 0xAAF0, 0xA8D0, 0xA730, 0xA560, 0xA3D0, 0xA2E0, + 0xA270, 0xA2C0, 0xA2B0, 0xA380, 0xA4C0, 0xA620, 0xA780, 0xA940, 0xABB0, 0xAD00, 0xAF10, 0xB1C0, 0xB460, 0xB710, 0xBA50, 0xBDB0, + 0xC160, 0xC5B0, 0xC970, 0xCE60, 0xD2E0, 0xD7B0, 0xDCA0, 0xE160, 0xE640, 0xEAD0, 0xF070, 0xF5D0, 0xFB30, 0x0060, 0x0520, 0x09C0, + 0x0E80, 0x1390, 0x18E0, 0x1DE0, 0x2340, 0x2800, 0x2D30, 0x3270, 0x3800, 0x3E10, 0x4350, 0x47F0, 0x4D80, 0x5190, 0x5630, 0x59A0, + 0x5D40, 0x6150, 0x6500, 0x6800, 0x6AC0, 0x6CB0, 0x6FA0, 0x7220, 0x7540, 0x7790, 0x79E0, 0x7C20, 0x7DF0, 0x7ED0, 0x7F20, 0x7F40, + 0x7F10, 0x7F10, 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, 0x7F70, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F70, 0x7EE0, 0x7EF0, 0x7F10, + 0x7EF0, 0x7F60, 0x7EF0, 0x7ED0, 0x7F20, 0x7F00, 0x7F50, 0x7ED0, 0x7EA0, 0x7F10, 0x7F10, 0x7F30, 0x7EC0, 0x7EC0, 0x7F10, 0x7F20, + 0x7F20, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F20, 0x7F10, 0x7F00, 0x7F30, 0x7F20, 0x7F10, + 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F00, 0x7EF0, 0x7F10, 0x7F80, 0x7F00, 0x7F10, 0x7EF0, 0x7EF0, 0x7F60, 0x7F10, 0x7F10, 0x7EF0, + 0x7EE0, 0x7F60, 0x7F10, 0x7EB0, 0x7EE0, 0x7EE0, 0x7F70, 0x7F20, 0x7EC0, 0x7ED0, 0x7EF0, 0x7EF0, 0x7F00, 0x7EF0, 0x7EF0, 0x7F10, + 0x7F20, 0x7F20, 0x7580, 0x65B0, 0x5630, 0x4680, 0x3910, 0x2D30, 0x2230, 0x18B0, 0x10B0, 0x0A00, 0x0470, 0xFFC0, 0xFBB0, 0xF860, + 0xF550, 0xF250, 0xEFA0, 0xECB0, 0xEA20, 0xE6D0, 0xE380, 0xE050, 0xDD30, 0xDAB0, 0xD940, 0xD810, 0xD820, 0xD840, 0xD890, 0xD950, + 0xD970, 0xD840, 0xD6A0, 0xD370, 0xCF40, 0xCB10, 0xC630, 0xC160, 0xBCB0, 0xB9E0, 0xB8A0, 0xBA30, 0xBEF0, 0xC620, 0xCF90, 0xDAB0, + 0xE660, 0xF390, 0x0200, 0x0FB0, 0x1D80, 0x2B40, 0x38B0, 0x4730, 0x5670, 0x6620, 0x7660, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, + 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x6EA0, 0x3E70, 0x0940, 0xD030, 0x95D0, 0x84E0, 0x8490, 0x8470, 0x8450, 0x8440, + 0x8430, 0x8420, 0x8420, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, 0x83E0, + 0x8440, 0x8450, 0x8450, 0x8460, 0x8460, 0x8490, 0x8470, 0x8480, 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84C0, 0x84D0, 0x84F0, 0x8500, + 0x8500, 0x8510, 0x8510, 0x8510, 0x8500, 0x84F0, 0x84E0, 0x84E0, 0x84D0, 0x84D0, 0x84C0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, + 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84F0, 0x8500, 0x8530, 0x8570, 0x85F0, + 0x86F0, 0x8870, 0x8B30, 0x8DF0, 0x9050, 0x91F0, 0x9200, 0x90D0, 0x8E90, 0x8BD0, 0x8930, 0x8760, 0x8660, 0x85B0, 0x8570, 0x8530, + 0x8510, 0x84F0, 0x84E0, 0x84C0, 0x84F0, 0x84B0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84D0, 0x84F0, + 0x8570, 0x8780, 0x9360, 0xA3A0, 0xB000, 0xB7C0, 0xB9F0, 0xB630, 0xAD40, 0xA080, 0x93D0, 0x8A70, 0x8690, 0x8560, 0x8500, 0x84E0, + 0x84C0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x8490, + 0x84C0, 0x84B0, 0x8480, 0x8480, 0x84A0, 0x8460, 0x8460, 0x8410, 0x8450, 0x8440, 0x8440, 0x8430, 0x8430, 0x8420, 0x8420, 0x8440, + 0x8410, 0x8400, 0x8400, 0x83A0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8400, 0x83C0, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, + 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8460, 0x8460, 0x8470, + 0x8470, 0x8470, 0x8490, 0x84A0, 0x84C0, 0x84E0, 0x8510, 0x8660, 0x8F50, 0xA5B0, 0xBB30, 0xD020, 0xE410, 0xF770, 0x0710, 0x14E0, + 0x2140, 0x2BC0, 0x3350, 0x3940, 0x3D00, 0x3F90, 0x41A0, 0x42E0, 0x4450, 0x44B0, 0x44E0, 0x4470, 0x4480, 0x4650, 0x4900, 0x4C50, + 0x4FA0, 0x5240, 0x55D0, 0x5930, 0x5CB0, 0x5FE0, 0x61D0, 0x62B0, 0x60F0, 0x5C40, 0x5540, 0x4A90, 0x3D20, 0x2C20, 0x17F0, 0x0280, + 0xEC60, 0xD680, 0xC5B0, 0xB8D0, 0xB220, 0xAE90, 0xAE60, 0xAE50, 0xAB20, 0xA3D0, 0x95D0, 0x8900, 0x8530, 0x84D0, 0x84B0, 0x84A0, + 0x8490, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84E0, 0x8530, 0x87C0, 0x9CA0, 0xB6E0, 0xCCA0, 0xDF40, 0xF040, + 0x0040, 0x10B0, 0x21F0, 0x3340, 0x4560, 0x5910, 0x69B0, 0x7860, 0x7EE0, 0x7F80, 0x7F10, 0x7F00, 0x7F00, 0x7EF0, 0x7F70, 0x7F00, + 0x7ED0, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F00, 0x7F60, 0x7F10, 0x7F10, 0x7EF0, 0x7EE0, 0x7F50, 0x7F10, 0x7EE0, 0x7EE0, 0x7ED0, 0x7F70, + 0x7F20, 0x7EC0, 0x7ED0, 0x7EB0, 0x7F00, 0x7F10, 0x7EA0, 0x7EE0, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, 0x7F20, 0x7F00, 0x7EF0, + 0x7ED0, 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F60, 0x7F10, 0x7F10, 0x7F00, 0x7EE0, 0x7F50, 0x7F10, 0x7F20, 0x7F00, 0x7F10, + 0x7F60, 0x7F00, 0x7F10, 0x7F10, 0x7EF0, 0x7F60, 0x7ED0, 0x7EB0, 0x7F00, 0x7EF0, 0x7F70, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, + 0x7EE0, 0x7E90, 0x7EF0, 0x7EF0, 0x7F30, 0x7F00, 0x7EC0, 0x7F10, 0x7F00, 0x7F00, 0x7F00, 0x7E90, 0x7F10, 0x7F00, 0x7EF0, 0x7F10, + 0x7F00, 0x7F40, 0x7F00, 0x7F10, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F90, 0x7F20, 0x7F10, 0x7EF0, 0x7F10, + 0x7F70, 0x7F00, 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, 0x7EF0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F70, 0x7F20, 0x7EC0, 0x7EB0, 0x7EB0, 0x7F50, + 0x7F10, 0x7E90, 0x7EB0, 0x7EE0, 0x7F10, 0x7F10, 0x7EA0, 0x7F00, 0x7EB0, 0x7700, 0x70C0, 0x6B80, 0x68B0, 0x6760, 0x6740, 0x6980, + 0x6D20, 0x7260, 0x7810, 0x7D60, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F40, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, + 0x7F60, 0x7F10, 0x7EF0, 0x7F10, 0x7F10, 0x7F40, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F70, 0x7EF0, 0x7EF0, 0x7F00, 0x7F00, 0x7F50, + 0x7C30, 0x7670, 0x7160, 0x6C50, 0x66F0, 0x62C0, 0x5E90, 0x5CA0, 0x5A70, 0x58E0, 0x58D0, 0x5930, 0x5AB0, 0x5BE0, 0x5CF0, 0x5EE0, + 0x6000, 0x6250, 0x6390, 0x6360, 0x6300, 0x6200, 0x5FF0, 0x5D20, 0x5940, 0x55B0, 0x5030, 0x49C0, 0x42C0, 0x3AE0, 0x3330, 0x2B60, + 0x23A0, 0x1C90, 0x1490, 0x0D70, 0x06E0, 0x00D0, 0xFB10, 0xF4E0, 0xEF00, 0xE7F0, 0xE110, 0xDA80, 0xD480, 0xCF70, 0xCAD0, 0xC5F0, + 0xC220, 0xBD70, 0xB860, 0xB3A0, 0xAEB0, 0xAA10, 0xA4E0, 0x9FC0, 0x9B00, 0x9630, 0x9290, 0x8F10, 0x8C50, 0x8A50, 0x88F0, 0x8820, + 0x8770, 0x8700, 0x86D0, 0x86C0, 0x86D0, 0x86F0, 0x8730, 0x8790, 0x8840, 0x8990, 0x8BA0, 0x8F10, 0x9480, 0x9A30, 0x9F90, 0xA680, + 0xAD50, 0xB560, 0xBCF0, 0xC590, 0xCD70, 0xD570, 0xDE90, 0xE790, 0xF0C0, 0xFAC0, 0x04B0, 0x0F70, 0x19E0, 0x24C0, 0x2EF0, 0x39F0, + 0x44C0, 0x4ED0, 0x59B0, 0x6360, 0x6C40, 0x7510, 0x7B80, 0x7F00, 0x7F10, 0x7F30, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F00, + 0x7F00, 0x7EF0, 0x7EF0, 0x7F20, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F10, 0x7EF0, 0x7F20, 0x7F20, 0x7F00, + 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F30, 0x7F10, 0x7F00, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, + 0x7F10, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, + 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F30, 0x7F40, 0x7F40, 0x7F30, 0x7F30, 0x7B70, 0x6A40, 0x5870, 0x4380, 0x3080, 0x1EC0, + 0x0E50, 0x0090, 0xF4D0, 0xEBE0, 0xE6A0, 0xE450, 0xE4F0, 0xE7A0, 0xEBF0, 0xF0C0, 0xF4D0, 0xF7D0, 0xF9E0, 0xFAB0, 0xFC40, 0xFD50, + 0xFFB0, 0x01A0, 0x0380, 0x0410, 0x0480, 0x03B0, 0x02A0, 0x0200, 0x01A0, 0x0300, 0x0480, 0x0730, 0x0B20, 0x0FE0, 0x1520, 0x1A00, + 0x1E10, 0x21D0, 0x2500, 0x2950, 0x2D80, 0x3270, 0x36E0, 0x3BC0, 0x4010, 0x44D0, 0x49F0, 0x4E40, 0x52C0, 0x56D0, 0x5AB0, 0x5E20, + 0x6120, 0x6410, 0x6730, 0x69C0, 0x6BD0, 0x6D30, 0x6E40, 0x6E60, 0x6E90, 0x6E90, 0x6E00, 0x6D20, 0x6B90, 0x6A00, 0x67B0, 0x65E0, + 0x63C0, 0x61B0, 0x5F30, 0x5CC0, 0x59A0, 0x55C0, 0x51A0, 0x4DB0, 0x4A10, 0x4660, 0x4340, 0x4040, 0x3D10, 0x3A60, 0x3710, 0x3490, + 0x31E0, 0x2F30, 0x2CC0, 0x2B10, 0x29D0, 0x2920, 0x2860, 0x2730, 0x2610, 0x2520, 0x2440, 0x2410, 0x24F0, 0x25A0, 0x26C0, 0x2770, + 0x2800, 0x2870, 0x28D0, 0x2960, 0x29C0, 0x2AC0, 0x2A50, 0x29B0, 0x2890, 0x2730, 0x2510, 0x2360, 0x21A0, 0x1FD0, 0x1DD0, 0x1C00, + 0x19A0, 0x1760, 0x1420, 0x10F0, 0x0D10, 0x08B0, 0x03C0, 0xFF00, 0xF8F0, 0xF2D0, 0xECC0, 0xE6A0, 0xE110, 0xDC00, 0xD7D0, 0xD420, + 0xD0C0, 0xCE30, 0xCC30, 0xCA00, 0xC7D0, 0xC5B0, 0xC460, 0xC330, 0xC240, 0xC210, 0xC190, 0xC130, 0xC100, 0xC160, 0xC240, 0xC360, + 0xC550, 0xC760, 0xC9B0, 0xCCC0, 0xD000, 0xD430, 0xD980, 0xDDD0, 0xE210, 0xE600, 0xE980, 0xEC90, 0xEF30, 0xF2E0, 0xF550, 0xF8E0, + 0xFB90, 0xFF70, 0x0450, 0x0900, 0x0EB0, 0x1480, 0x1A60, 0x2140, 0x2880, 0x2ED0, 0x3560, 0x3B20, 0x4200, 0x4990, 0x5070, 0x5820, + 0x5ED0, 0x65F0, 0x6BA0, 0x70F0, 0x7680, 0x7A80, 0x7E40, 0x7EF0, 0x7F70, 0x7F00, 0x7F20, 0x7EF0, 0x7EF0, 0x7F60, 0x7EE0, 0x7ED0, + 0x7EF0, 0x7F00, 0x7F20, 0x7F20, 0x7EC0, 0x7EE0, 0x7ED0, 0x7F30, 0x7F00, 0x7E90, 0x7ED0, 0x7F10, 0x7EF0, 0x7EF0, 0x7EB0, 0x7F00, + 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F40, 0x7F40, + 0x7F10, 0x7F00, 0x7EE0, 0x7F50, 0x7F10, 0x7F20, 0x7F00, 0x7EF0, 0x7F60, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7F60, 0x7EE0, 0x7ED0, + 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7ED0, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7E90, 0x7EF0, 0x7EE0, 0x7DC0, 0x79B0, 0x7430, 0x6E20, + 0x6700, 0x5E50, 0x5540, 0x4C40, 0x43F0, 0x3CB0, 0x35E0, 0x3160, 0x2D00, 0x2A80, 0x2820, 0x26F0, 0x2750, 0x27C0, 0x2940, 0x2A80, + 0x2AF0, 0x2C10, 0x2C40, 0x2CD0, 0x2E20, 0x2EE0, 0x3090, 0x3280, 0x34E0, 0x36E0, 0x3940, 0x3C90, 0x3EA0, 0x4040, 0x3E50, 0x3BD0, + 0x3900, 0x3610, 0x3390, 0x3020, 0x2C40, 0x2A10, 0x26E0, 0x2330, 0x1FF0, 0x1C40, 0x1950, 0x1630, 0x13A0, 0x11F0, 0x1030, 0x0F10, + 0x0DC0, 0x0BF0, 0x0A10, 0x07B0, 0x0530, 0x0240, 0xFE50, 0xF920, 0xF280, 0xEAB0, 0xE2E0, 0xDAD0, 0xD3C0, 0xCCE0, 0xC670, 0xBFA0, + 0xB840, 0xB0D0, 0xA7E0, 0xA000, 0x9790, 0x8F90, 0x8520, 0x84F0, 0x84E0, 0x84C0, 0x84C0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x8490, + 0x8490, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x84B0, 0x8490, 0x8490, 0x8490, 0x8490, + 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x8490, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84B0, 0x84C0, 0x84C0, 0x84B0, 0x84C0, 0x84C0, + 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84F0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84E0, 0x84E0, 0x84E0, + 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84E0, 0x84D0, 0x84C0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8480, + 0x8470, 0x8470, 0x8470, 0x8460, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83D0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, + 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83B0, 0x8360, 0x83B0, 0x83A0, 0x83A0, 0x8360, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8380, + 0x8380, 0x8380, 0x8380, 0x8380, 0x8380, 0x8380, 0x8380, 0x8370, 0x8380, 0x83A0, 0x8370, 0x8370, 0x8370, 0x8380, 0x8380, 0x8390, + 0x8390, 0x8390, 0x8390, 0x83A0, 0x83A0, 0x8390, 0x83A0, 0x83A0, 0x83A0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, + 0x83C0, 0x83D0, 0x83C0, 0x83C0, 0x83D0, 0x83C0, 0x83C0, 0x83D0, 0x8360, 0x83D0, 0x83D0, 0x83E0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, + 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, + 0x83E0, 0x83E0, 0x83F0, 0x8400, 0x8400, 0x8410, 0x8410, 0x8420, 0x8430, 0x8440, 0x8450, 0x8460, 0x8470, 0x8480, 0x84A0, 0x84D0, + 0x84E0, 0x8530, 0x8610, 0x87A0, 0x89A0, 0x8A70, 0x8A00, 0x8900, 0x8770, 0x8660, 0x8590, 0x84E0, 0x8500, 0x84E0, 0x84E0, 0x84D0, + 0x8500, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84F0, 0x84F0, 0x8510, 0x8580, 0x8900, 0xA060, 0xBBC0, 0xD580, 0xEB70, 0xFB20, 0x0860, + 0x1400, 0x2100, 0x3210, 0x4300, 0x5360, 0x6140, 0x69D0, 0x6E30, 0x6D00, 0x6780, 0x5DD0, 0x4F20, 0x3EC0, 0x2B80, 0x15D0, 0xFFE0, + 0xEA00, 0xD620, 0xC240, 0xAD20, 0x93C0, 0x8690, 0x84F0, 0x84B0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8460, 0x8470, 0x84C0, 0x8490, + 0x84A0, 0x84B0, 0x84D0, 0x8500, 0x8600, 0x8DC0, 0xAAA0, 0xC790, 0xE670, 0x06B0, 0x27B0, 0x4900, 0x6820, 0x7ED0, 0x7F30, 0x7F30, + 0x7F50, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, + 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, + 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, + 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F20, 0x7F40, + 0x7F30, 0x7F30, 0x7F00, 0x7F40, 0x7ED0, 0x73F0, 0x6920, 0x5CF0, 0x5190, 0x46A0, 0x3CE0, 0x3450, 0x2D90, 0x2840, 0x24E0, 0x2290, + 0x2260, 0x2340, 0x2490, 0x2660, 0x2860, 0x2A10, 0x2B50, 0x2CD0, 0x2DA0, 0x2E50, 0x2E40, 0x2E50, 0x2D40, 0x2C60, 0x2BD0, 0x2C00, + 0x2C60, 0x2DE0, 0x2F30, 0x3030, 0x30C0, 0x3090, 0x3020, 0x2FE0, 0x30E0, 0x32A0, 0x3510, 0x39A0, 0x3FE0, 0x46D0, 0x4F60, 0x57A0, + 0x6040, 0x68C0, 0x7090, 0x7740, 0x7D40, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F30, 0x7F30, + 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, + 0x7F30, 0x7F20, 0x7EC0, 0x7F10, 0x7F20, 0x7F00, 0x7EF0, 0x7E40, 0x7530, 0x6C70, 0x62F0, 0x5990, 0x4F40, 0x4640, 0x3E80, 0x3630, + 0x2F20, 0x2840, 0x2300, 0x1DA0, 0x18C0, 0x1590, 0x1290, 0x0FF0, 0x0F10, 0x0F10, 0x1160, 0x1560, 0x1A60, 0x2130, 0x2A10, 0x3550, + 0x4360, 0x5340, 0x6530, 0x7860, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7ED0, 0x7F10, 0x7EF0, 0x7F30, 0x7EF0, 0x7EA0, 0x7F20, 0x7EF0, + 0x7F30, 0x7EE0, 0x7EC0, 0x7F10, 0x7F10, 0x7F40, 0x7ED0, 0x7E90, 0x7F20, 0x7EF0, 0x7EF0, 0x7F20, 0x7F00, 0x7F40, 0x7F20, 0x7F20, + 0x7F10, 0x7F00, 0x7F20, 0x7EE0, 0x7EF0, 0x7F30, 0x7F20, 0x7F40, 0x7EF0, 0x7F30, 0x7F30, 0x7F00, 0x7F80, 0x7F10, 0x7F00, 0x7F00, + 0x7F10, 0x7F70, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F00, 0x7F60, 0x7F10, 0x7EB0, 0x7F00, 0x7EF0, 0x7F50, 0x7F00, 0x7E70, 0x7EC0, 0x7ED0, + 0x7F20, 0x7F20, 0x7EB0, 0x7EE0, 0x7EE0, 0x7F10, 0x7F10, 0x7E90, 0x7E60, 0x7EF0, 0x7F10, 0x7EF0, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, + 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7EE0, 0x7F40, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F30, 0x7F20, 0x7F10, 0x7F10, + 0x7F00, 0x7F40, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, 0x7F50, 0x7F00, 0x7F00, 0x7F00, 0x7F10, 0x7F30, 0x7EE0, 0x7EA0, 0x7EF0, 0x7EE0, + 0x7F50, 0x7EF0, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7EE0, 0x7E70, 0x7F10, 0x7EF0, 0x7EF0, 0x7EF0, 0x7E80, 0x7F10, 0x7F00, 0x7F20, + 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7F50, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F60, 0x7F00, 0x7F10, 0x7F10, + 0x7EF0, 0x7F60, 0x7EF0, 0x7F00, 0x7EF0, 0x7EF0, 0x7F80, 0x7F20, 0x7F00, 0x7ED0, 0x7ED0, 0x7F30, 0x7F10, 0x7EE0, 0x7EE0, 0x7ED0, + 0x7F30, 0x7F20, 0x7EC0, 0x7ED0, 0x7ED0, 0x7F30, 0x7F20, 0x7E90, 0x7EB0, 0x7EF0, 0x7EE0, 0x7F00, 0x7F60, 0x7F10, 0x7E90, 0x7EB0, + 0x7EC0, 0x7EF0, 0x7F10, 0x7E90, 0x7ED0, 0x7F00, 0x7F00, 0x7EF0, 0x7EC0, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7F40, + 0x7F10, 0x7F10, 0x7EE0, 0x7F50, 0x7EF0, 0x7F20, 0x7EF0, 0x7EF0, 0x7F70, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F60, 0x7EE0, 0x7F10, + 0x7F30, 0x7F00, 0x7F80, 0x7F10, 0x7F10, 0x7EE0, 0x7EF0, 0x7F70, 0x7EF0, 0x7EF0, 0x7EF0, 0x7F00, 0x7F60, 0x7F10, 0x7ED0, 0x7EB0, + 0x7EE0, 0x7F60, 0x7F00, 0x7E90, 0x7EB0, 0x7EB0, 0x7EF0, 0x7EF0, 0x7EA0, 0x7F00, 0x7EE0, 0x7F10, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, + 0x7F10, 0x7F00, 0x7EE0, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7F00, 0x7F80, 0x7F10, 0x7F20, + 0x7EF0, 0x7EF0, 0x7F50, 0x7F00, 0x7F00, 0x7F10, 0x7F20, 0x7F60, 0x7EF0, 0x7EF0, 0x7EF0, 0x7EE0, 0x7F50, 0x7EF0, 0x7EE0, 0x7EF0, + 0x7F10, 0x7F60, 0x7EE0, 0x7E90, 0x7F10, 0x7F00, 0x7EF0, 0x7ED0, 0x7EA0, 0x7EE0, 0x7EF0, 0x7F30, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, + 0x7ED0, 0x7D10, 0x7AA0, 0x79C0, 0x78C0, 0x77B0, 0x7860, 0x7900, 0x7A50, 0x7BD0, 0x7D60, 0x7EC0, 0x7F10, 0x7F80, 0x7F00, 0x7F00, + 0x7EF0, 0x7F10, 0x7F60, 0x7EF0, 0x7F30, 0x7F20, 0x7F20, 0x7F80, 0x7F10, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F70, 0x7EE0, 0x7ED0, 0x7EF0, + 0x7F00, 0x7F40, 0x7F10, 0x7E90, 0x7EE0, 0x7ED0, 0x7F10, 0x7F00, 0x7E70, 0x7ED0, 0x7F10, 0x7F20, 0x7F40, 0x7EA0, 0x7ED0, 0x7F10, + 0x7F10, 0x7F00, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7EF0, 0x7480, 0x4BE0, 0x28C0, 0x0B60, 0xF590, 0xE570, 0xD9E0, 0xD300, 0xD000, + 0xD120, 0xD710, 0xE290, 0xF480, 0x0D80, 0x2C80, 0x4F90, 0x71B0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7EE0, 0x7ED0, 0x7F10, + 0x7F00, 0x7F70, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7EC0, 0x7E90, 0x7F10, 0x7EE0, 0x7EF0, 0x7EF0, 0x71A0, 0x34A0, 0xF7D0, + 0xBB00, 0x88A0, 0x84B0, 0x8480, 0x8460, 0x8450, 0x8440, 0x8440, 0x8430, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8420, + 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8430, + 0x8430, 0x8430, 0x8440, 0x8450, 0x8450, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84E0, 0x8500, + 0x8580, 0x8690, 0x8950, 0x8FD0, 0x98C0, 0xA070, 0xA7D0, 0xAF10, 0xB710, 0xBFE0, 0xC6D0, 0xCD40, 0xD390, 0xD900, 0xDDC0, 0xE290, + 0xE7F0, 0xECD0, 0xF1B0, 0xF570, 0xF970, 0xFC60, 0xFF10, 0x01D0, 0x0410, 0x05F0, 0x0780, 0x0890, 0x0920, 0x0A40, 0x0A50, 0x0A10, + 0x0970, 0x0850, 0x06F0, 0x04B0, 0x0280, 0x0080, 0xFE30, 0xFB40, 0xF900, 0xF5B0, 0xF2B0, 0xEFF0, 0xEE10, 0xED10, 0xEC60, 0xEBE0, + 0xEC50, 0xED30, 0xEE80, 0xF020, 0xF230, 0xF4A0, 0xF780, 0xFA90, 0xFDF0, 0x0220, 0x0620, 0x0A10, 0x0D90, 0x11E0, 0x16E0, 0x1D70, + 0x2500, 0x2EC0, 0x3970, 0x44F0, 0x5060, 0x5B40, 0x6550, 0x6F10, 0x7730, 0x7CE0, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, + 0x7F30, 0x7F20, 0x7F30, 0x7E00, 0x7550, 0x6A60, 0x5CF0, 0x4D10, 0x3B00, 0x2620, 0x0CA0, 0xF2B0, 0xD690, 0xBA90, 0x9FA0, 0x8AF0, + 0x8590, 0x84F0, 0x84D0, 0x84C0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84D0, 0x8500, 0x8570, 0x87A0, 0x9AA0, 0xB2C0, 0xCB10, 0xE070, + 0xF170, 0xFB60, 0xFD30, 0xF5F0, 0xE5F0, 0xCDA0, 0xB200, 0x9550, 0x86B0, 0x8500, 0x84D0, 0x84C0, 0x84B0, 0x84A0, 0x84A0, 0x8490, + 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, + 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8490, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84B0, + 0x84C0, 0x84C0, 0x84D0, 0x84E0, 0x84F0, 0x8500, 0x8520, 0x8550, 0x8590, 0x85E0, 0x8620, 0x86D0, 0x8770, 0x8870, 0x8A90, 0x8D80, + 0x9150, 0x95B0, 0x99E0, 0x9E50, 0xA410, 0xAA80, 0xB280, 0xBB00, 0xC3E0, 0xCD50, 0xD610, 0xDFA0, 0xE8E0, 0xF3A0, 0xFDA0, 0x0650, + 0x0FB0, 0x17E0, 0x2040, 0x2810, 0x2F80, 0x3760, 0x3E10, 0x4490, 0x49B0, 0x4E70, 0x5400, 0x5880, 0x5D80, 0x61E0, 0x6680, 0x6AB0, + 0x6E80, 0x7260, 0x7600, 0x7970, 0x7CA0, 0x7EC0, 0x7F40, 0x7F10, 0x7EF0, 0x7EF0, 0x7F10, 0x7F60, 0x7F10, 0x7F10, 0x7F10, 0x7EF0, + 0x7F40, 0x7EF0, 0x7F00, 0x7F40, 0x7EF0, 0x7F30, 0x7F00, 0x7EE0, 0x7F10, 0x7F10, 0x7F50, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F30, + 0x7F00, 0x7EC0, 0x7F10, 0x7F20, 0x7F40, 0x7EF0, 0x7E90, 0x7F00, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7EF0, 0x7EF0, 0x7F20, 0x7F20, + 0x7F00, 0x7F10, 0x7EF0, 0x7F00, 0x7F20, 0x7F00, 0x7F30, 0x7EE0, 0x7EF0, 0x7F30, 0x7F20, 0x7F80, 0x4240, 0xED50, 0x9040, 0x84A0, + 0x8470, 0x8450, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8460, 0x8460, 0x8450, 0x8460, 0x8490, 0x8480, 0x84C0, + 0x84B0, 0x84D0, 0x8500, 0x85F0, 0x8A50, 0x97D0, 0xA3A0, 0xACF0, 0xB460, 0xBA50, 0xBED0, 0xC180, 0xC1F0, 0xC0B0, 0xBEB0, 0xBD40, + 0xBC60, 0xBD90, 0xC0D0, 0xC5E0, 0xCCD0, 0xD500, 0xDE60, 0xE8C0, 0xF470, 0x0200, 0x1060, 0x2180, 0x30E0, 0x3E90, 0x4AD0, 0x53A0, + 0x58E0, 0x5AE0, 0x5B90, 0x5D70, 0x60E0, 0x66C0, 0x6EF0, 0x77D0, 0x7EA0, 0x7F10, 0x7F50, 0x7EB0, 0x7E70, 0x7F10, 0x7F00, 0x7F60, + 0x7ED0, 0x7EB0, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7EA0, 0x7F10, 0x7F10, 0x7F20, 0x7E70, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7F10, + 0x7EB0, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, 0x7EF0, 0x7F30, 0x7F20, 0x7F60, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, + 0x7F80, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7F90, 0x7F10, 0x7F00, 0x7EF0, 0x7ED0, 0x7F60, 0x7F10, 0x7ED0, 0x7EF0, 0x7F20, 0x7F40, + 0x7F10, 0x7F90, 0x7F00, 0x7F00, 0x7EF0, 0x7EF0, 0x7F70, 0x7EF0, 0x7F10, 0x7F00, 0x7F00, 0x7F70, 0x7F10, 0x7EB0, 0x7EC0, 0x7EC0, + 0x7F30, 0x7F00, 0x7EC0, 0x7ED0, 0x7EE0, 0x7F20, 0x7F10, 0x7E90, 0x7EB0, 0x7EE0, 0x7F10, 0x7F10, 0x7E70, 0x7EF0, 0x7F10, 0x7F20, + 0x7F20, 0x7F00, 0x7EA0, 0x7F10, 0x7F10, 0x7F10, 0x7EC0, 0x7F10, 0x7390, 0x6630, 0x5CA0, 0x5480, 0x4F00, 0x4BA0, 0x48C0, 0x4690, + 0x4470, 0x41B0, 0x3E70, 0x3A50, 0x36E0, 0x3370, 0x30C0, 0x2E90, 0x2DB0, 0x2EC0, 0x3080, 0x3330, 0x3760, 0x3B50, 0x4030, 0x4530, + 0x4A60, 0x4F40, 0x52D0, 0x54A0, 0x5460, 0x51F0, 0x4F70, 0x4B80, 0x4800, 0x4490, 0x4120, 0x3EE0, 0x3CF0, 0x3CF0, 0x3DB0, 0x3F90, + 0x4360, 0x46C0, 0x4BD0, 0x50F0, 0x55A0, 0x5B20, 0x6040, 0x6520, 0x6A30, 0x6DE0, 0x7240, 0x7580, 0x78B0, 0x7BA0, 0x7D70, 0x7EF0, + 0x7F10, 0x7F50, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F90, 0x7F20, 0x7F00, 0x7EF0, 0x7F10, 0x7F30, 0x7F40, 0x7F10, 0x7F10, 0x7EE0, + 0x7F60, 0x7F10, 0x7F20, 0x7F00, 0x7EF0, 0x7F70, 0x7F00, 0x7F40, 0x7F10, 0x7F00, 0x7F60, 0x7EE0, 0x7F10, 0x7F00, 0x7EF0, 0x7F90, + 0x7F00, 0x7EE0, 0x7F00, 0x7F10, 0x7F30, 0x7EF0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F70, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F30, 0x7F00, + 0x7EA0, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7EC0, 0x7F30, 0x7F00, 0x7F00, 0x7F00, 0x7F00, 0x7F30, 0x7F00, 0x7F40, 0x7F10, 0x7F10, + 0x7F50, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7F90, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F70, 0x7F00, 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, + 0x7F10, 0x7EB0, 0x7EE0, 0x7ED0, 0x7F70, 0x7F20, 0x7EC0, 0x7ED0, 0x7EB0, 0x7F00, 0x7EF0, 0x7E70, 0x7ED0, 0x7ED0, 0x7F20, 0x7F20, + 0x7EC0, 0x7EF0, 0x7F00, 0x7F00, 0x7F10, 0x7E90, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F20, 0x7F20, 0x7F20, 0x7F00, + 0x7F50, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F60, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F60, 0x7F00, 0x7EF0, 0x7F00, 0x7EF0, 0x7F30, + 0x74C0, 0x4FC0, 0x29C0, 0x0160, 0xD6F0, 0xABE0, 0x88C0, 0x84E0, 0x84A0, 0x8480, 0x8480, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, + 0x8460, 0x8450, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8420, 0x8410, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, + 0x8410, 0x8430, 0x8430, 0x8440, 0x8440, 0x8450, 0x8450, 0x8460, 0x8470, 0x8470, 0x8480, 0x8490, 0x84A0, 0x84C0, 0x84C0, 0x84E0, + 0x8500, 0x8540, 0x8670, 0x8930, 0x8FA0, 0x9770, 0x9EE0, 0xA590, 0xABE0, 0xB280, 0xBAE0, 0xC380, 0xCC90, 0xD410, 0xDB20, 0xE040, + 0xE350, 0xE480, 0xE420, 0xE240, 0xDF30, 0xD9B0, 0xD340, 0xCCE0, 0xC7A0, 0xC3B0, 0xC240, 0xC320, 0xC4A0, 0xC5B0, 0xC530, 0xC230, + 0xBBF0, 0xB1A0, 0xA570, 0x98D0, 0x8DB0, 0x87C0, 0x85B0, 0x8510, 0x84E0, 0x84C0, 0x84B0, 0x8490, 0x8470, 0x8460, 0x8440, 0x8440, + 0x8420, 0x8410, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, + 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83F0, 0x83D0, 0x83D0, 0x8410, 0x83E0, 0x83E0, 0x83E0, 0x83E0, + 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83B0, + 0x83C0, 0x83C0, 0x83C0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, + 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83E0, 0x8400, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, + 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, + 0x8410, 0x8430, 0x8430, 0x8430, 0x8470, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, + 0x8430, 0x8430, 0x8430, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8450, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8470, 0x8460, 0x8460, + 0x8460, 0x8450, 0x8460, 0x8460, 0x8470, 0x8450, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, + 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84B0, 0x84C0, 0x84D0, 0x84D0, 0x84E0, 0x84F0, 0x8510, 0x8540, + 0x85C0, 0x8710, 0x8BC0, 0x9860, 0xA810, 0xB7C0, 0xC690, 0xD3F0, 0xDF90, 0xE900, 0xEF90, 0xF430, 0xF620, 0xF7B0, 0xF7D0, 0xF920, + 0xFAE0, 0xFD90, 0x02B0, 0x08C0, 0x10C0, 0x1910, 0x2020, 0x26E0, 0x2CC0, 0x31B0, 0x3760, 0x3BA0, 0x4110, 0x4610, 0x4A70, 0x4E90, + 0x50D0, 0x52E0, 0x5340, 0x5390, 0x53B0, 0x53E0, 0x54C0, 0x5510, 0x55D0, 0x5650, 0x56A0, 0x57E0, 0x58E0, 0x5990, 0x5A90, 0x5A70, + 0x5B70, 0x5B10, 0x5A70, 0x5920, 0x5660, 0x5310, 0x4EE0, 0x4AE0, 0x4780, 0x4450, 0x4340, 0x42C0, 0x4330, 0x4530, 0x46E0, 0x49C0, + 0x4C90, 0x4F30, 0x5300, 0x5600, 0x5910, 0x5C00, 0x5EE0, 0x6250, 0x64B0, 0x65A0, 0x64C0, 0x6250, 0x5EE0, 0x59C0, 0x5390, 0x4D50, + 0x46A0, 0x3FA0, 0x3870, 0x3230, 0x2D60, 0x29B0, 0x28B0, 0x2960, 0x2B50, 0x2EA0, 0x3160, 0x3470, 0x34B0, 0x32B0, 0x2F20, 0x2980, + 0x2540, 0x23F0, 0x26E0, 0x2FC0, 0x3C90, 0x4D10, 0x5E40, 0x6EF0, 0x7C50, 0x7EA0, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7EA0, 0x7EF0, + 0x7F00, 0x7F00, 0x7EF0, 0x7EC0, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7EF0, 0x7F50, 0x7F20, + 0x7F20, 0x7F10, 0x7F10, 0x7F60, 0x7F00, 0x7F10, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F80, 0x7F00, 0x7EE0, + 0x7F10, 0x7F10, 0x7F30, 0x7EC0, 0x7EB0, 0x7EF0, 0x7EE0, 0x7F30, 0x7EF0, 0x7EA0, 0x7F20, 0x7F10, 0x7F10, 0x7EE0, 0x7EC0, 0x7F10, + 0x7ED0, 0x7F00, 0x7EF0, 0x7F30, 0x7EE0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7E90, 0x7F10, 0x7F20, 0x7F40, 0x7ED0, 0x7EA0, + 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F40, 0x7F00, 0x7F30, 0x7EE0, 0x7F00, 0x7F20, 0x7F00, 0x7F50, + 0x7F20, 0x7F40, 0x7EF0, 0x7F10, 0x7F70, 0x7EF0, 0x7F00, 0x7F10, 0x7F10, 0x7F70, 0x7F00, 0x7F10, 0x7EF0, 0x7EE0, 0x7F80, 0x7F20, + 0x7F00, 0x7EF0, 0x7EB0, 0x7F30, 0x7EF0, 0x7E90, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EB0, 0x7EE0, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, + 0x7ED0, 0x7F00, 0x7F00, 0x7EF0, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7F50, + 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F60, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F10, 0x7EF0, 0x7F10, 0x7F60, 0x7F00, + 0x7EF0, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F50, 0x7EE0, 0x7EA0, 0x7F00, 0x7EF0, 0x7F30, 0x7EE0, 0x7EC0, + 0x7F10, 0x7EF0, 0x7EF0, 0x7F10, 0x7EB0, 0x7F20, 0x7EF0, 0x7EF0, 0x7F20, 0x7F00, 0x7F40, 0x7EF0, 0x7F10, 0x7F20, 0x7EF0, 0x7F30, + 0x7EE0, 0x7EF0, 0x7F30, 0x7F20, 0x7F70, 0x7F10, 0x7F10, 0x7EF0, 0x7F00, 0x7F90, 0x7F10, 0x7F00, 0x7EE0, 0x7EF0, 0x7F70, 0x7F20, + 0x7EE0, 0x7EF0, 0x7F00, 0x7F60, 0x7F10, 0x7EB0, 0x7EB0, 0x7EC0, 0x7EF0, 0x7F10, 0x7E70, 0x7ED0, 0x7ED0, 0x7F20, 0x7F20, 0x7EC0, + 0x7ED0, 0x7F00, 0x7F00, 0x7F10, 0x7EA0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F10, 0x7EB0, 0x7F20, + 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F50, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7F60, 0x7F00, + 0x7F40, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F20, 0x7F00, 0x7F00, 0x7F60, 0x7EF0, 0x7F10, 0x7F00, 0x7F00, 0x7F50, 0x7F10, 0x7CB0, + 0x6470, 0x4910, 0x2E70, 0x1310, 0xF660, 0xD8B0, 0xB990, 0x9A30, 0x8740, 0x84F0, 0x84B0, 0x84A0, 0x8490, 0x8480, 0x8470, 0x8470, + 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8480, 0x8480, 0x8450, 0x8460, 0x8420, 0x8470, 0x8470, 0x84B0, 0x8480, 0x8490, + 0x84A0, 0x84B0, 0x84C0, 0x84D0, 0x84F0, 0x8550, 0x8640, 0x8940, 0x92D0, 0x9F10, 0xAA90, 0xB690, 0xC230, 0xCDF0, 0xD980, 0xE380, + 0xEC50, 0xF590, 0xFE70, 0x0720, 0x0F50, 0x18B0, 0x2040, 0x2810, 0x2F80, 0x34E0, 0x3A20, 0x3ED0, 0x4270, 0x46E0, 0x4B40, 0x4EF0, + 0x5300, 0x55B0, 0x5840, 0x5A00, 0x5BB0, 0x5E00, 0x5F50, 0x6060, 0x6160, 0x62F0, 0x6450, 0x6560, 0x66A0, 0x6780, 0x6790, 0x6750, + 0x66E0, 0x6690, 0x6710, 0x67B0, 0x68C0, 0x69C0, 0x6AD0, 0x6C00, 0x6DA0, 0x7020, 0x7240, 0x7510, 0x7810, 0x7AA0, 0x7D20, 0x7EB0, + 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, + 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, + 0x7F20, 0x7F40, 0x7F30, 0x7F10, 0x7F20, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F10, 0x7F20, 0x7F20, + 0x7F30, 0x7F30, 0x7F00, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F00, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7EF0, 0x7F30, 0x7F20, 0x7F40, + 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F40, 0x7F40, 0x7F30, 0x7F10, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F30, + 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, + 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, + 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, + 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F10, 0x7F20, 0x7F20, + 0x7F30, 0x7F30, 0x7EF0, 0x7E90, 0x7D10, 0x7B60, 0x79A0, 0x7850, 0x7630, 0x73B0, 0x7260, 0x7150, 0x6F70, 0x6E30, 0x6CA0, 0x6BE0, + 0x6B90, 0x6AA0, 0x6B00, 0x69D0, 0x68C0, 0x6810, 0x6790, 0x67A0, 0x6820, 0x69D0, 0x6B80, 0x6D00, 0x6E00, 0x6E10, 0x6F10, 0x6F80, + 0x7020, 0x7050, 0x7000, 0x6FA0, 0x6EA0, 0x6C90, 0x6BE0, 0x6A40, 0x6910, 0x6830, 0x66A0, 0x6560, 0x6480, 0x6450, 0x64A0, 0x6540, + 0x6730, 0x68A0, 0x6A20, 0x6BE0, 0x6D90, 0x7090, 0x72A0, 0x7480, 0x7720, 0x7880, 0x7A90, 0x7BB0, 0x7CF0, 0x7DE0, 0x7E90, 0x7EF0, + 0x7EE0, 0x7F40, 0x7E80, 0x7E20, 0x7D20, 0x7C20, 0x7A90, 0x7950, 0x7700, 0x7560, 0x7290, 0x6FF0, 0x6D20, 0x6910, 0x65B0, 0x61B0, + 0x5D60, 0x5950, 0x54B0, 0x5060, 0x4B90, 0x45B0, 0x3FE0, 0x3900, 0x32D0, 0x2BB0, 0x2480, 0x1EA0, 0x1730, 0x1020, 0x0940, 0x0240, + 0xFC30, 0xF5D0, 0xEF20, 0xE830, 0xE0B0, 0xD7E0, 0xD040, 0xC930, 0xC2C0, 0xBC40, 0xB5B0, 0xAED0, 0xA8A0, 0xA260, 0x9B80, 0x9660, + 0x91C0, 0x8DE0, 0x8B40, 0x8990, 0x88C0, 0x8850, 0x8830, 0x8850, 0x88C0, 0x8920, 0x8960, 0x89D0, 0x8AE0, 0x8C70, 0x8FA0, 0x9430, + 0x9880, 0x9CE0, 0xA060, 0xA3F0, 0xA730, 0xAA60, 0xAE20, 0xB0C0, 0xB3B0, 0xB820, 0xBB60, 0xBF50, 0xC300, 0xC6C0, 0xCAA0, 0xCD50, + 0xD060, 0xD370, 0xD6F0, 0xDA20, 0xDCC0, 0xDFB0, 0xE300, 0xE5A0, 0xE8F0, 0xEAD0, 0xEDB0, 0xEFC0, 0xF1B0, 0xF430, 0xF5A0, 0xF770, + 0xF870, 0xF960, 0xFB40, 0xFD00, 0xFEE0, 0x00A0, 0x01F0, 0x0350, 0x04F0, 0x05C0, 0x0720, 0x0870, 0x0A60, 0x0B30, 0x0C20, 0x0DD0, + 0x0EB0, 0x1060, 0x1110, 0x1250, 0x1250, 0x1170, 0x1010, 0x0EB0, 0x0E60, 0x0CF0, 0x0B10, 0x08A0, 0x0500, 0x0100, 0xFC30, 0xF670, + 0xF160, 0xEBD0, 0xE630, 0xDFB0, 0xD8B0, 0xD210, 0xCB50, 0xC530, 0xBF00, 0xB8F0, 0xB3E0, 0xAE70, 0xAA10, 0xA700, 0xA530, 0xA4B0, + 0xA480, 0xA530, 0xAE10, 0xB150, 0xB4C0, 0xB8E0, 0xBCA0, 0xC0B0, 0xC4E0, 0xC860, 0xCC30, 0xCF40, 0xD210, 0xD360, 0xD410, 0xD450, + 0xD4A0, 0xD580, 0xD730, 0xD8A0, 0xD890, 0xD760, 0xD430, 0xCE40, 0xC6A0, 0xBCE0, 0xB270, 0xA6D0, 0x9A40, 0x8EC0, 0x87E0, 0x8580, + 0x84F0, 0x84C0, 0x84B0, 0x8490, 0x8480, 0x8470, 0x8470, 0x8460, 0x8450, 0x8450, 0x8440, 0x8430, 0x8440, 0x8430, 0x8430, 0x8420, + 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8410, 0x8430, 0x8420, 0x8410, + 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, + 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8420, 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, + 0x8470, 0x8460, 0x8480, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84B0, + 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, + 0x84C0, 0x84C0, 0x84C0, 0x84B0, 0x84E0, 0x84C0, 0x84B0, 0x84B0, 0x84D0, 0x84C0, 0x84B0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, + 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, + 0x84B0, 0x84A0, 0x84B0, 0x84B0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84A0, + 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x8480, 0x84C0, + 0x84C0, 0x84C0, 0x84C0, 0x84D0, 0x84D0, 0x84D0, 0x84E0, 0x84E0, 0x84F0, 0x8500, 0x8510, 0x8530, 0x8550, 0x8580, 0x8600, 0x86E0, + 0x8870, 0x8BD0, 0x91C0, 0x9860, 0x9FB0, 0xA6F0, 0xAE90, 0xB6A0, 0xBDF0, 0xC5B0, 0xCDB0, 0xD520, 0xDC90, 0xE4E0, 0xECC0, 0xF410, + 0xFAF0, 0x00F0, 0x0700, 0x0C70, 0x1250, 0x1920, 0x1FF0, 0x2660, 0x2C10, 0x3280, 0x38F0, 0x3F70, 0x4620, 0x4BD0, 0x5130, 0x5670, + 0x5B40, 0x6090, 0x6600, 0x6B00, 0x6FF0, 0x72F0, 0x7710, 0x79E0, 0x7CF0, 0x7ED0, 0x7F20, 0x7F40, 0x7F10, 0x7F50, 0x7F00, 0x7F20, + 0x7EF0, 0x7F10, 0x7F70, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F70, 0x7F10, 0x7F10, 0x7F00, 0x7EE0, 0x7F50, 0x7F10, 0x7F20, 0x7F10, + 0x7F10, 0x7F30, 0x7EE0, 0x7EF0, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, + 0x7EF0, 0x7F10, 0x7F20, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F30, 0x7F20, + 0x7F20, 0x7F40, 0x7F30, 0x5F70, 0x3700, 0x11C0, 0xF510, 0xDC00, 0xC420, 0xAB50, 0x9200, 0x8630, 0x84E0, 0x84B0, 0x8490, 0x8490, + 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, + 0x8440, 0x8430, 0x8440, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8440, 0x8400, 0x8400, 0x8410, 0x8410, 0x8400, + 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, + 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8480, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, + 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8440, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, + 0x84B0, 0x84C0, 0x84E0, 0x8520, 0x8640, 0x90E0, 0xA7F0, 0xBEE0, 0xD580, 0xEA70, 0xFD30, 0x0CA0, 0x1A50, 0x2530, 0x2EF0, 0x3760, + 0x3D50, 0x4210, 0x4480, 0x42C0, 0x3ED0, 0x3690, 0x2C30, 0x1DD0, 0x0EE0, 0x0030, 0xF160, 0xE2D0, 0xD430, 0xC3F0, 0xB180, 0x99A0, + 0x8660, 0x84C0, 0x8480, 0x8460, 0x8450, 0x8440, 0x8430, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, + 0x8430, 0x8430, 0x8440, 0x8440, 0x8450, 0x8460, 0x8460, 0x8470, 0x8480, 0x8490, 0x84B0, 0x84E0, 0x8530, 0x8690, 0x8DC0, 0x9EC0, + 0xAE70, 0xBE00, 0xCC20, 0xD9C0, 0xE930, 0xF6E0, 0x0390, 0x1030, 0x1B70, 0x26D0, 0x3200, 0x3DE0, 0x49A0, 0x5490, 0x5ED0, 0x6800, + 0x70E0, 0x7880, 0x7DD0, 0x7F10, 0x7F00, 0x7F50, 0x7F00, 0x7F00, 0x7F20, 0x7EF0, 0x7F80, 0x7F20, 0x7F40, 0x7F10, 0x7EF0, 0x7F80, + 0x7F10, 0x7F10, 0x7EF0, 0x7EE0, 0x7F50, 0x7F10, 0x7EE0, 0x7F00, 0x7F00, 0x7F60, 0x7F00, 0x7ED0, 0x7ED0, 0x7EB0, 0x7EF0, 0x7EF0, + 0x7EB0, 0x7ED0, 0x7EF0, 0x7F30, 0x7F20, 0x7E90, 0x7EB0, 0x7F00, 0x7F00, 0x7EF0, 0x7E70, 0x7D20, 0x7B60, 0x78F0, 0x7730, 0x7500, + 0x7340, 0x7210, 0x7090, 0x6FC0, 0x6F10, 0x6E30, 0x6DE0, 0x6C40, 0x6B40, 0x6990, 0x68A0, 0x6800, 0x6750, 0x6820, 0x6AA0, 0x6E60, + 0x7390, 0x79F0, 0x7EA0, 0x7EE0, 0x7F70, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F70, 0x7EF0, 0x7ED0, 0x7F00, 0x7EE0, 0x7F70, 0x7ED0, + 0x7EB0, 0x7EE0, 0x7EF0, 0x7F30, 0x7F00, 0x7EA0, 0x7F10, 0x7F20, 0x7F40, 0x7EF0, 0x7E90, 0x7F00, 0x7EE0, 0x7DC0, 0x7230, 0x64A0, + 0x54E0, 0x45B0, 0x35C0, 0x26C0, 0x1700, 0x0590, 0xF3B0, 0xDFF0, 0xCC00, 0xB5E0, 0xA2B0, 0x9110, 0x87D0, 0x8580, 0x8500, 0x84E0, + 0x84D0, 0x84C0, 0x84B0, 0x84B0, 0x84A0, 0x8490, 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, + 0x8440, 0x8440, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84B0, + 0x84B0, 0x84B0, 0x84C0, 0x84B0, 0x84D0, 0x84E0, 0x84F0, 0x8500, 0x8510, 0x8540, 0x8590, 0x8630, 0x8790, 0x8A90, 0x9050, 0x9790, + 0x9E90, 0xA570, 0xAC60, 0xB330, 0xBA70, 0xC170, 0xC870, 0xCF00, 0xD540, 0xDA90, 0xDFA0, 0xE470, 0xE8F0, 0xED60, 0xF240, 0xF690, + 0xFA50, 0xFD90, 0x0040, 0x0210, 0x02F0, 0x0290, 0x0050, 0xFD00, 0xF9E0, 0xF630, 0xF2F0, 0xF100, 0xF090, 0xF2B0, 0xF6F0, 0xFE20, + 0x0620, 0x0E90, 0x17D0, 0x1FB0, 0x2520, 0x2970, 0x2B40, 0x2B20, 0x28F0, 0x2410, 0x1EC0, 0x18C0, 0x1410, 0x1150, 0x1040, 0x1160, + 0x12D0, 0x14E0, 0x1500, 0x13D0, 0x11D0, 0x0E30, 0x09E0, 0x0440, 0xFED0, 0xF960, 0xF350, 0xEDC0, 0xE630, 0xDB70, 0xCCC0, 0xB8D0, + 0xA170, 0x8BA0, 0x8560, 0x84D0, 0x84B0, 0x84A0, 0x84A0, 0x8470, 0x8470, 0x8460, 0x8470, 0x8470, 0x8420, 0x8470, 0x8470, 0x8470, + 0x8480, 0x8490, 0x84A0, 0x84E0, 0x85C0, 0x9BC0, 0xBD20, 0xDBE0, 0xF830, 0x1220, 0x2C40, 0x4440, 0x5B90, 0x6F80, 0x7DE0, 0x7EF0, + 0x7F00, 0x7F30, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7F10, 0x7F20, 0x7EE0, 0x7EF0, 0x7F50, 0x7F00, 0x7F20, 0x7F10, 0x4A50, + 0x01E0, 0xBD80, 0x8700, 0x8490, 0x8460, 0x8440, 0x8420, 0x83F0, 0x83E0, 0x83D0, 0x83C0, 0x83B0, 0x83A0, 0x8390, 0x8390, 0x8380, + 0x8380, 0x8370, 0x8370, 0x8370, 0x8360, 0x8360, 0x8360, 0x8320, 0x8370, 0x8360, 0x8370, 0x8390, 0x8370, 0x8370, 0x8310, 0x8380, + 0x8380, 0x8380, 0x8390, 0x8390, 0x8390, 0x8350, 0x83A0, 0x8390, 0x83A0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, + 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8400, 0x8420, 0x8420, + 0x8420, 0x8400, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8460, 0x8460, + 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, + 0x8490, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84C0, 0x84E0, 0x84F0, 0x8520, 0x8580, 0x86D0, 0x8FF0, 0xA1F0, 0xB4E0, 0xCB10, + 0xE2A0, 0xFB90, 0x1550, 0x2F30, 0x47A0, 0x5EF0, 0x7560, 0x7EF0, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7F10, + 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, + 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, + 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F40, 0x7F20, 0x7F10, 0x7F20, + 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, + 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, + 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, + 0x7F20, 0x7F10, 0x7F30, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F10, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F00, 0x7F20, + 0x7F30, 0x7F30, 0x7F20, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F30, 0x7F20, 0x7F10, + 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, + 0x7F20, 0x7F30, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F40, 0x7F90, 0x7F30, + 0x7F00, 0x7F00, 0x7EF0, 0x7F50, 0x7F20, 0x7F00, 0x7F00, 0x7EB0, 0x7F20, 0x7EE0, 0x7EF0, 0x7EB0, 0x7EE0, 0x7F50, 0x7F00, 0x7F00, + 0x7EE0, 0x7EF0, 0x7F30, 0x7F00, 0x7EB0, 0x7EF0, 0x7EE0, 0x7F30, 0x7F30, 0x7EA0, 0x7F00, 0x7ED0, 0x7AB0, 0x70A0, 0x6840, 0x62D0, + 0x5E30, 0x5B20, 0x5960, 0x5880, 0x5840, 0x5830, 0x56D0, 0x5580, 0x51A0, 0x4D00, 0x4790, 0x4130, 0x3A60, 0x32C0, 0x2A70, 0x2200, + 0x1BA0, 0x1870, 0x18B0, 0x1BA0, 0x21F0, 0x2800, 0x2D90, 0x3130, 0x3330, 0x34F0, 0x3690, 0x38E0, 0x3AF0, 0x3E30, 0x4230, 0x4760, + 0x4DF0, 0x5700, 0x5FD0, 0x6890, 0x7120, 0x7970, 0x7E90, 0x7F30, 0x7F00, 0x7EC0, 0x7EF0, 0x7F10, 0x7F30, 0x7EE0, 0x7EC0, 0x7F10, + 0x7EF0, 0x7EF0, 0x7F10, 0x7E70, 0x7EF0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7F00, 0x7F30, 0x7EF0, + 0x7F00, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F90, 0x7F00, 0x7EF0, 0x7EF0, 0x7EF0, 0x7F70, 0x7EE0, 0x7EF0, + 0x7F10, 0x7F00, 0x7F60, 0x7F10, 0x7EB0, 0x7EB0, 0x7EC0, 0x7F30, 0x7F00, 0x7E70, 0x7ED0, 0x7ED0, 0x7F20, 0x7F40, 0x7E90, 0x7ED0, + 0x7EE0, 0x7F10, 0x7F10, 0x7E90, 0x7EC0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F00, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F20, 0x7F20, + 0x7EF0, 0x7F10, 0x7ED0, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F30, 0x7EF0, 0x7EF0, 0x7F10, 0x7EF0, 0x7F40, 0x7EF0, 0x7F10, + 0x7F00, 0x7F00, 0x7F50, 0x7ED0, 0x7F00, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7E90, 0x7F10, 0x7F10, 0x7F40, 0x7ED0, 0x7EB0, 0x7F00, + 0x7F10, 0x7F10, 0x7F00, 0x7EA0, 0x7EF0, 0x7EF0, 0x7F20, 0x7EF0, 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, + 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7F00, 0x7F10, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7F80, + 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F90, 0x7F10, 0x7F10, 0x7F00, 0x76A0, 0x66D0, 0x57E0, 0x4740, 0x3840, 0x29D0, 0x1C90, 0x0EB0, + 0x01F0, 0xF6A0, 0xEB90, 0xE090, 0xD660, 0xCC10, 0xC310, 0xB9F0, 0xB110, 0xA8F0, 0xA0B0, 0x98A0, 0x9250, 0x8DD0, 0x8B50, 0x8970, + 0x8850, 0x87F0, 0x87D0, 0x8800, 0x88A0, 0x89F0, 0x8CC0, 0x9160, 0x9740, 0x9D60, 0xA440, 0xAB90, 0xB370, 0xBB80, 0xC3B0, 0xCBE0, + 0xD350, 0xDB10, 0xE300, 0xEBE0, 0xF400, 0xFB80, 0x0350, 0x0B20, 0x11F0, 0x1860, 0x1E10, 0x23F0, 0x2A40, 0x2EF0, 0x33D0, 0x3870, + 0x3C60, 0x4150, 0x4630, 0x4A70, 0x4F20, 0x5320, 0x5740, 0x5A90, 0x5DB0, 0x6140, 0x6400, 0x67B0, 0x6AA0, 0x6DF0, 0x71D0, 0x7490, + 0x7830, 0x7B60, 0x7DD0, 0x7EF0, 0x7F00, 0x7F40, 0x7F00, 0x7F20, 0x7F20, 0x7F00, 0x7F50, 0x7F00, 0x7F20, 0x7F20, 0x7EF0, 0x7F90, + 0x7EE0, 0x7EF0, 0x7F10, 0x7F10, 0x7F70, 0x7F10, 0x7F10, 0x7EF0, 0x7EE0, 0x7F70, 0x7F00, 0x7EF0, 0x7EF0, 0x7F00, 0x7F70, 0x7F20, + 0x7ED0, 0x7EB0, 0x7F00, 0x7F60, 0x7F10, 0x7E90, 0x7EB0, 0x7EC0, 0x7EF0, 0x7F10, 0x7EA0, 0x7ED0, 0x7EF0, 0x7F20, 0x7F20, 0x7EC0, + 0x7F10, 0x7F00, 0x7F00, 0x7EF0, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7F10, 0x7F00, 0x7F30, + 0x7EF0, 0x7F10, 0x7F10, 0x7F20, 0x7F40, 0x7EF0, 0x7F40, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F70, 0x7EF0, + 0x7EF0, 0x7F00, 0x7F00, 0x7F70, 0x7ED0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F30, 0x7EA0, 0x7AC0, 0x7610, 0x6FA0, 0x6820, 0x5FD0, 0x5590, + 0x4A90, 0x3CD0, 0x2EB0, 0x2030, 0x1060, 0xFFC0, 0xEDD0, 0xDBA0, 0xC980, 0xB560, 0x9E60, 0x8B50, 0x8570, 0x84E0, 0x84B0, 0x8490, + 0x8480, 0x8470, 0x8460, 0x8460, 0x8450, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8420, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8400, 0x8410, 0x8410, + 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8450, 0x8440, 0x8450, 0x8450, 0x8450, + 0x8450, 0x8450, 0x8460, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x84A0, 0x8480, 0x8480, 0x8490, 0x84A0, 0x84B0, + 0x84D0, 0x8510, 0x85C0, 0x8940, 0x99C0, 0xAB80, 0xBE30, 0xCFE0, 0xE090, 0xF170, 0x0060, 0x0FC0, 0x1AF0, 0x2330, 0x2B10, 0x2F10, + 0x30E0, 0x3040, 0x2E10, 0x2AF0, 0x2640, 0x2190, 0x1CC0, 0x1730, 0x10C0, 0x0950, 0x0040, 0xF6E0, 0xED30, 0xE4D0, 0xDC20, 0xD3C0, + 0xCBB0, 0xC400, 0xBD00, 0xB590, 0xAFA0, 0xAB00, 0xA7A0, 0xA610, 0xA570, 0xA530, 0xA580, 0xA660, 0xA7A0, 0xAAD0, 0xB0F0, 0xBB10, + 0xCA10, 0xDEE0, 0xF8E0, 0x1650, 0x3490, 0x5400, 0x6D50, 0x7E30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F30, 0x7F30, + 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, + 0x7F30, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7EF0, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, + 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, + 0x7F30, 0x7F30, 0x7F00, 0x7F40, 0x7F40, 0x7F30, 0x7F30, 0x7EF0, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7DB0, 0x6EF0, + 0x6280, 0x57C0, 0x4E70, 0x4680, 0x3E40, 0x3640, 0x2EE0, 0x2A20, 0x2740, 0x26D0, 0x2810, 0x2B70, 0x2FC0, 0x33D0, 0x3650, 0x37E0, + 0x39A0, 0x3AD0, 0x3B90, 0x3D30, 0x4040, 0x43F0, 0x48D0, 0x5930, 0x5BE0, 0x5CF0, 0x5D90, 0x5D30, 0x5C40, 0x5AF0, 0x58D0, 0x5620, + 0x52C0, 0x4DC0, 0x47A0, 0x4130, 0x39F0, 0x31E0, 0x2980, 0x2040, 0x1690, 0x0CA0, 0x0260, 0xF6D0, 0xEBB0, 0xE010, 0xD400, 0xC800, + 0xBC00, 0xB130, 0xA620, 0x9C20, 0x91F0, 0x8BC0, 0x8840, 0x86A0, 0x85E0, 0x85D0, 0x8580, 0x8590, 0x85D0, 0x8660, 0x8780, 0x89B0, + 0x8D40, 0x9260, 0x9690, 0x9A90, 0x9DA0, 0x9F90, 0xA270, 0xA500, 0xA850, 0xACE0, 0xB1C0, 0xB760, 0xBC90, 0xC2E0, 0xC8B0, 0xCDB0, + 0xD1F0, 0xD550, 0xD900, 0xDCE0, 0xDF60, 0xE160, 0xE2C0, 0xE3B0, 0xE430, 0xE350, 0xE1A0, 0xDDE0, 0xD930, 0xD310, 0xCBE0, 0xC420, + 0xBCA0, 0xB3C0, 0xAB90, 0xA330, 0x9A50, 0x9040, 0x88D0, 0x8600, 0x8520, 0x84E0, 0x84C0, 0x84B0, 0x84A0, 0x8490, 0x84C0, 0x8480, + 0x8470, 0x8460, 0x8490, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8430, 0x8410, 0x8430, 0x8430, 0x8430, + 0x8450, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, + 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84F0, 0x84D0, 0x84F0, 0x8510, 0x8570, 0x8670, + 0x89B0, 0x9250, 0x9DE0, 0xA830, 0xB1F0, 0xBC00, 0xC610, 0xD060, 0xDB80, 0xE650, 0xF150, 0xFBC0, 0x05A0, 0x1000, 0x19D0, 0x24B0, + 0x2F60, 0x39C0, 0x43B0, 0x4D80, 0x58D0, 0x62D0, 0x6BB0, 0x7440, 0x7B40, 0x7ED0, 0x7EF0, 0x7F60, 0x7EF0, 0x7EF0, 0x7EE0, 0x7EE0, + 0x7F50, 0x7F20, 0x7EA0, 0x7ED0, 0x7ED0, 0x7F10, 0x7F10, 0x7E90, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, 0x7F20, 0x7F20, + 0x7F10, 0x7E90, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F00, 0x7F10, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7F10, 0x7F00, + 0x7EF0, 0x7F30, 0x7EF0, 0x7F20, 0x7ED0, 0x7BF0, 0x77F0, 0x73C0, 0x6F50, 0x6BB0, 0x6800, 0x6510, 0x61B0, 0x5EB0, 0x5C60, 0x5990, + 0x56A0, 0x5420, 0x5100, 0x4F30, 0x4D30, 0x4C40, 0x4BD0, 0x4B90, 0x4BC0, 0x4850, 0x4740, 0x45E0, 0x44D0, 0x4430, 0x4320, 0x4240, + 0x4150, 0x3FF0, 0x3F80, 0x3E10, 0x3D00, 0x3B70, 0x3940, 0x36F0, 0x3400, 0x3260, 0x3040, 0x2EF0, 0x2E00, 0x2D00, 0x2C30, 0x2A30, + 0x2740, 0x24E0, 0x2140, 0x1D90, 0x1A50, 0x1770, 0x1560, 0x12F0, 0x1090, 0x0E00, 0x0B60, 0x0840, 0x0480, 0x00B0, 0xFD80, 0xFB00, + 0xF870, 0xF580, 0xF250, 0xEF50, 0xEAA0, 0xE760, 0xE490, 0xE1B0, 0xDF30, 0xDC70, 0xDA30, 0xD6F0, 0xD3D0, 0xD0A0, 0xCC40, 0xC8A0, + 0xC5C0, 0xC2E0, 0xC0B0, 0xBEB0, 0xBCB0, 0xBA60, 0xB790, 0xB4F0, 0xB180, 0xAEB0, 0xAC10, 0xA870, 0xA620, 0xA420, 0xA270, 0x9FF0, + 0x9CE0, 0x9A10, 0x96E0, 0x9330, 0x9060, 0x8DD0, 0x8BB0, 0x89F0, 0x8890, 0x8760, 0x86A0, 0x8610, 0x85D0, 0x8590, 0x8570, 0x8550, + 0x8530, 0x8520, 0x8510, 0x8500, 0x84F0, 0x84F0, 0x84E0, 0x84E0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, + 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x84C0, + 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8430, 0x8480, 0x8470, 0x8470, 0x8430, 0x8480, 0x8480, 0x8470, + 0x8480, 0x8480, 0x8480, 0x8480, 0x8470, 0x8480, 0x8480, 0x8480, 0x84B0, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, + 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x8490, 0x84B0, 0x84B0, 0x84C0, 0x8510, 0x8500, + 0x8530, 0x85C0, 0x8750, 0x8D40, 0x9980, 0xA690, 0xB4A0, 0xC1C0, 0xCEE0, 0xDC90, 0xE9B0, 0xF720, 0x0590, 0x12D0, 0x1F30, 0x2A60, + 0x34D0, 0x3D90, 0x4460, 0x48C0, 0x4AD0, 0x4AB0, 0x4540, 0x3CD0, 0x2F10, 0x1D20, 0x07E0, 0xEDD0, 0xD030, 0xB0B0, 0x8E10, 0x8530, + 0x84C0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8440, 0x8450, 0x8450, + 0x8460, 0x8460, 0x8470, 0x8480, 0x84A0, 0x84C0, 0x8590, 0xA040, 0xD550, 0x0E70, 0x4100, 0x6BB0, 0x7F10, 0x7F70, 0x7EE0, 0x7EF0, + 0x7F10, 0x7F00, 0x7F80, 0x7F10, 0x7F20, 0x7F00, 0x7EF0, 0x7F70, 0x7F00, 0x7EC0, 0x7ED0, 0x7E90, 0x4DE0, 0x11C0, 0xBDE0, 0x84B0, + 0x8440, 0x8410, 0x8410, 0x83C0, 0x83B0, 0x83A0, 0x8390, 0x83C0, 0x83A0, 0x83C0, 0x83A0, 0x83A0, 0x83B0, 0x83B0, 0x8380, 0x83B0, + 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x8430, 0x83F0, 0x83F0, 0x8400, 0x8400, + 0x8430, 0x8400, 0x8400, 0x83E0, 0x8400, 0x8400, 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, 0x8430, 0x8440, 0x8450, 0x8460, 0x8470, + 0x8490, 0x84B0, 0x8510, 0x88C0, 0xA830, 0xC6F0, 0xE3D0, 0xFDE0, 0x1810, 0x2EB0, 0x4380, 0x5800, 0x6C40, 0x7DB0, 0x7F20, 0x7F40, + 0x7F40, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F50, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, + 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F20, + 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, + 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, + 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F10, 0x7F20, 0x7F20, 0x7F10, + 0x7F30, 0x7F00, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7EF0, 0x7F20, 0x7F10, 0x7F10, 0x7F30, + 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F40, + 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F30, + 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, + 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F60, 0x7F10, 0x7E90, 0x7F00, 0x7EE0, 0x7F10, 0x7F10, 0x7E70, 0x7EE0, 0x7ED0, 0x7EF0, + 0x7EE0, 0x7E80, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7E90, 0x7F00, 0x7F00, 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F20, 0x7F00, + 0x7F00, 0x7F10, 0x7EF0, 0x7F20, 0x7EF0, 0x7EF0, 0x7EF0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7EF0, 0x7F00, 0x7F40, 0x7F00, + 0x7F10, 0x7EE0, 0x7EF0, 0x7F30, 0x7F20, 0x7F60, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F30, 0x7F20, 0x7F00, 0x7F90, + 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7F10, 0x7EB0, 0x7EB0, 0x7EC0, 0x7F50, 0x7F10, 0x7EA0, 0x7EC0, 0x7ED0, 0x7F10, 0x7F20, + 0x7EA0, 0x7EF0, 0x7F00, 0x7F00, 0x7F10, 0x7E90, 0x7E70, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F00, + 0x7F30, 0x7F20, 0x7F20, 0x7EF0, 0x7F00, 0x7F40, 0x7EF0, 0x6B50, 0x5A00, 0x4B00, 0x3FF0, 0x3770, 0x31A0, 0x2FB0, 0x3110, 0x3640, + 0x3E90, 0x49A0, 0x57D0, 0x66C0, 0x75F0, 0x7ED0, 0x7F00, 0x7F00, 0x7F10, 0x7F50, 0x7EE0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F30, 0x7ED0, + 0x7EB0, 0x7F00, 0x7F20, 0x7F40, 0x7EF0, 0x7EA0, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7F40, 0x7F00, + 0x7F30, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7F40, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7F80, 0x7F00, 0x7F40, 0x7F20, 0x7F10, 0x7F70, + 0x7EE0, 0x7EF0, 0x7EF0, 0x7EE0, 0x7F70, 0x6E00, 0x54F0, 0x3DE0, 0x26A0, 0x0EF0, 0xF730, 0xDD70, 0xC1D0, 0xA950, 0x9450, 0x8960, + 0x8670, 0x85E0, 0x85E0, 0x8640, 0x8710, 0x8840, 0x8A10, 0x8D30, 0x95F0, 0xA610, 0xBC40, 0xD9A0, 0xFAB0, 0x1A60, 0x3630, 0x4160, + 0x3D20, 0x2A50, 0x0CB0, 0xECC0, 0xCF00, 0xB840, 0xA9E0, 0xA1F0, 0x9EF0, 0x9CE0, 0x9850, 0x8510, 0x84E0, 0x84D0, 0x84C0, 0x84A0, + 0x84B0, 0x84A0, 0x84A0, 0x84B0, 0x8490, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8470, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8490, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, 0x8470, + 0x8470, 0x8480, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, + 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8470, 0x8440, + 0x8440, 0x8440, 0x8440, 0x8430, 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x83E0, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, + 0x8450, 0x8460, 0x8440, 0x8440, 0x8440, 0x8400, 0x8430, 0x8430, 0x8430, 0x83D0, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, + 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8420, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, + 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, + 0x8440, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8410, 0x8420, 0x83C0, + 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, + 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, + 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x8410, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, + 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8410, 0x8410, 0x8420, 0x8430, 0x8430, 0x8440, 0x8450, 0x8450, + 0x8460, 0x8470, 0x8490, 0x84A0, 0x84D0, 0x8530, 0x86C0, 0x9120, 0xA2F0, 0xB150, 0xBBF0, 0xC300, 0xC5B0, 0xC3A0, 0xBC00, 0xAFC0, + 0x9F00, 0x8C10, 0x8590, 0x84E0, 0x84B0, 0x8490, 0x8470, 0x8460, 0x8450, 0x8450, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8450, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, 0x8410, 0x8410, 0x8400, 0x8400, 0x83F0, + 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8410, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, 0x8460, + 0x8440, 0x8440, 0x8450, 0x8460, 0x8470, 0x8480, 0x8490, 0x84B0, 0x84E0, 0x8540, 0x8720, 0x92D0, 0xA470, 0xB540, 0xC4C0, 0xD330, + 0xE170, 0xECF0, 0xF770, 0x0120, 0x0A20, 0x1340, 0x1AF0, 0x2140, 0x2690, 0x2B30, 0x2EA0, 0x3280, 0x35F0, 0x38D0, 0x3B70, 0x3C40, + 0x3C60, 0x3B90, 0x38A0, 0x33D0, 0x2DB0, 0x26B0, 0x2060, 0x1A50, 0x1650, 0x1430, 0x13E0, 0x1560, 0x1750, 0x1870, 0x19C0, 0x1A80, + 0x1B50, 0x1C60, 0x1F00, 0x2300, 0x27E0, 0x2E20, 0x3590, 0x3E30, 0x4710, 0x5050, 0x5970, 0x6270, 0x6B30, 0x7420, 0x7C40, 0x7F10, + 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F20, + 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F10, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7EF0, + 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7EF0, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, + 0x7F20, 0x7F10, 0x7F30, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F50, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, + 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F40, 0x7F20, 0x7F10, 0x7F30, 0x7F10, 0x7F30, 0x7EE0, 0x7EF0, 0x7EF0, 0x7EE0, 0x7EF0, + 0x7EF0, 0x7F20, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7EF0, 0x7EF0, 0x7F00, 0x7F60, 0x7EF0, 0x7EF0, 0x7F00, 0x7F00, 0x7F40, 0x7F50, + 0x7EF0, 0x7EF0, 0x7EB0, 0x7F60, 0x7F40, 0x7E90, 0x7EC0, 0x7F00, 0x7F10, 0x7F30, 0x7EA0, 0x7EE0, 0x7F00, 0x7F10, 0x7F00, 0x7EA0, + 0x7EF0, 0x7F10, 0x7F00, 0x7EF0, 0x7EC0, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7F50, + 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F60, 0x7F10, 0x7F10, 0x7F10, 0x7EF0, 0x7F60, 0x7ED0, 0x7EF0, 0x7F00, 0x7F10, 0x7F60, 0x7F00, + 0x7ED0, 0x7F00, 0x7EF0, 0x7F50, 0x7ED0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F30, 0x7EE0, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7E90, + 0x7F10, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F20, 0x7F00, 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7F80, + 0x7F10, 0x7EF0, 0x7F30, 0x7F20, 0x7F80, 0x7F40, 0x7F10, 0x7F10, 0x7EE0, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7F00, 0x7F40, 0x7F40, + 0x7F10, 0x7F10, 0x7EE0, 0x7F60, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, 0x7EF0, 0x7F10, 0x7F10, 0x7F60, 0x7F00, 0x7ED0, + 0x7F10, 0x7EF0, 0x7F60, 0x7ED0, 0x7EB0, 0x7F10, 0x7F20, 0x7F60, 0x7EF0, 0x7EB0, 0x7F00, 0x7EE0, 0x7F40, 0x7EF0, 0x7E90, 0x7F10, + 0x7EF0, 0x7EF0, 0x7EF0, 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7F50, 0x7F10, + 0x7F00, 0x7F10, 0x7F10, 0x7F80, 0x7F00, 0x7F40, 0x7F10, 0x7EF0, 0x7F60, 0x7830, 0x6D70, 0x6360, 0x5810, 0x4C50, 0x4120, 0x35C0, + 0x2B60, 0x2230, 0x18A0, 0x1150, 0x0990, 0x02D0, 0xFCC0, 0xF790, 0xF490, 0xF310, 0xF310, 0xF510, 0xF910, 0x26A0, 0x36F0, 0x4800, + 0x57E0, 0x67E0, 0x7580, 0x7ED0, 0x7F10, 0x7E70, 0x7EC0, 0x7ED0, 0x7F60, 0x7EF0, 0x7EB0, 0x7EE0, 0x7EE0, 0x7F10, 0x7F10, 0x7EA0, + 0x7EE0, 0x7ED0, 0x7F10, 0x7F00, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F40, + 0x7EF0, 0x7F30, 0x7F20, 0x7EF0, 0x7F50, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7EF0, 0x7F00, 0x7EE0, 0x7F50, 0x7F10, + 0x7F00, 0x7F00, 0x7F10, 0x7F50, 0x7EB0, 0x7EF0, 0x7F00, 0x7EE0, 0x7F50, 0x7BB0, 0x7230, 0x6780, 0x5B90, 0x4E90, 0x4100, 0x3320, + 0x2550, 0x16F0, 0x0730, 0xF800, 0xE890, 0xD920, 0xCA50, 0xB970, 0xA960, 0x9970, 0x8BF0, 0x8660, 0x8520, 0x84E0, 0x84D0, 0x84B0, + 0x84A0, 0x8490, 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x83F0, 0x8440, 0x8430, 0x8440, + 0x8430, 0x8430, 0x8440, 0x8420, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, 0x84A0, 0x8450, 0x8450, 0x8450, + 0x8460, 0x8450, 0x8450, 0x8480, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8460, 0x8450, 0x8450, + 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8440, 0x8470, 0x8430, 0x8440, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, + 0x8450, 0x8470, 0x8470, 0x8480, 0x84C0, 0x8490, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8460, 0x8460, 0x8450, 0x8440, 0x8420, 0x8420, + 0x8410, 0x8400, 0x8400, 0x83F0, 0x83E0, 0x83E0, 0x83D0, 0x83C0, 0x83C0, 0x83B0, 0x83B0, 0x83B0, 0x83A0, 0x83A0, 0x83A0, 0x8390, + 0x8390, 0x8390, 0x8390, 0x83B0, 0x83A0, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x83C0, 0x8390, + 0x8390, 0x8350, 0x83A0, 0x8390, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83D0, 0x83A0, 0x83D0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, + 0x83E0, 0x83A0, 0x83B0, 0x8360, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, + 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x8400, 0x8410, 0x8420, 0x8430, 0x8440, 0x8450, 0x8470, 0x8480, 0x8490, 0x8490, + 0x84A0, 0x84B0, 0x84C0, 0x84D0, 0x84D0, 0x84E0, 0x84F0, 0x84F0, 0x84F0, 0x84E0, 0x84D0, 0x84C0, 0x84B0, 0x84A0, 0x8480, 0x8470, + 0x8460, 0x8450, 0x8440, 0x8430, 0x8470, 0x8410, 0x8400, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83D0, 0x83C0, 0x83D0, 0x83C0, 0x83C0, + 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8410, + 0x8420, 0x8420, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8470, 0x8490, 0x8560, 0xB1A0, 0xF1A0, 0x29D0, 0x58D0, 0x7A70, + 0x7F20, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, + 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F00, 0x7F10, 0x7F30, + 0x7F30, 0x7F20, 0x7EF0, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F10, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, + 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F40, 0x7F20, 0x7F10, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F20, + 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F20, + 0x7F10, 0x7F30, 0x7F10, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, + 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, + 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F00, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F00, 0x7F10, 0x7F20, + 0x7F20, 0x7F10, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F90, 0x7F40, 0x7EF0, 0x7F30, 0x7F20, 0x7F60, 0x7F40, 0x7EB0, 0x7EB0, + 0x7EF0, 0x7F30, 0x7EE0, 0x7E90, 0x7EB0, 0x7F10, 0x7F20, 0x7EF0, 0x7E90, 0x7EB0, 0x7F20, 0x7F40, 0x7ED0, 0x7E90, 0x7EE0, 0x7EF0, + 0x7F10, 0x7F30, 0x7F00, 0x7F30, 0x7F00, 0x7F00, 0x7F10, 0x7F00, 0x7F30, 0x7EE0, 0x7EF0, 0x7EF0, 0x7EC0, 0x7F40, 0x7EF0, 0x7F20, + 0x7F20, 0x7F00, 0x7F90, 0x7F10, 0x7F00, 0x7F50, 0x7F10, 0x7F30, 0x7EE0, 0x7EF0, 0x7F30, 0x7F00, 0x7F60, 0x7F10, 0x7F20, 0x7F10, + 0x7EF0, 0x7F60, 0x7EE0, 0x7ED0, 0x7EF0, 0x7F00, 0x7F30, 0x7EF0, 0x7EB0, 0x7EE0, 0x7EE0, 0x7F10, 0x7F10, 0x7E70, 0x7EC0, 0x7EF0, + 0x7F00, 0x7EF0, 0x7E90, 0x7F00, 0x7F20, 0x7F00, 0x7F10, 0x7EB0, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7EE0, 0x7F40, 0x7EF0, 0x7F20, + 0x7F20, 0x7F00, 0x7F40, 0x7F20, 0x7F10, 0x7F10, 0x7EF0, 0x7F40, 0x7EF0, 0x7F10, 0x7F10, 0x7EE0, 0x7F50, 0x7F00, 0x7F00, 0x7F00, + 0x7F10, 0x7F50, 0x7EE0, 0x7E70, 0x7F10, 0x7F00, 0x7F60, 0x7ED0, 0x7EB0, 0x7F00, 0x7F00, 0x7F40, 0x7EF0, 0x7EC0, 0x7F10, 0x7F10, + 0x7F20, 0x7F20, 0x7E90, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7EB0, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, 0x7EF0, + 0x7F30, 0x7F00, 0x7F60, 0x7F00, 0x7F10, 0x7F10, 0x7EE0, 0x7F70, 0x7F10, 0x7F10, 0x7EF0, 0x7EF0, 0x7F80, 0x7F10, 0x7F00, 0x7EE0, + 0x7ED0, 0x7F60, 0x7F00, 0x7ED0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7EB0, 0x7EE0, 0x7ED0, 0x7F30, 0x7F20, 0x7EC0, 0x7ED0, 0x7EF0, + 0x7F00, 0x7EE0, 0x7E90, 0x7EB0, 0x7E70, 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7E90, 0x7F00, 0x7F00, 0x7EF0, + 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7ED0, 0x7E90, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F20, 0x7EC0, 0x7F10, 0x7EF0, 0x7EF0, 0x7F10, + 0x7F10, 0x7ED0, 0x7E70, 0x7EE0, 0x7EF0, 0x7F30, 0x7F20, 0x7EC0, 0x7F10, 0x7EF0, 0x7F00, 0x7F10, 0x7EB0, 0x7F20, 0x7EE0, 0x7EF0, + 0x7F30, 0x7F20, 0x7F60, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F60, 0x7EF0, 0x7F10, 0x7F30, 0x7F00, 0x7F80, 0x7EF0, 0x7F20, 0x7F10, + 0x7F00, 0x7F90, 0x7F10, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F60, 0x7EF0, 0x7ED0, 0x7EF0, 0x7F00, 0x7F40, 0x7F10, 0x7E90, 0x7EB0, 0x7ED0, + 0x7F10, 0x7F00, 0x7E70, 0x7ED0, 0x7F10, 0x7F20, 0x7F20, 0x7EC0, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F20, + 0x7F20, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7EE0, 0x7F50, 0x7EF0, 0x7F20, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7F00, + 0x7EF0, 0x7F50, 0x7F00, 0x7F10, 0x7F00, 0x7EE0, 0x7F70, 0x7EF0, 0x7EE0, 0x7F00, 0x7D10, 0x7190, 0x65B0, 0x5960, 0x4B80, 0x3A50, + 0x26B0, 0x1160, 0xFA80, 0xE550, 0xD510, 0xCCA0, 0xCE00, 0xD850, 0xE920, 0xFDD0, 0x12B0, 0x2690, 0x37A0, 0x4600, 0x54B0, 0x61A0, + 0x6F10, 0x7B00, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F90, 0x7F20, 0x7F20, 0x7EF0, + 0x7F10, 0x7F90, 0x6F70, 0x54E0, 0x3800, 0x1850, 0xF6B0, 0xD480, 0xB160, 0x8E50, 0x8530, 0x84C0, 0x84B0, 0x8490, 0x8490, 0x8490, + 0x84A0, 0x8490, 0x84C0, 0x84D0, 0x84D0, 0x84D0, 0x84C0, 0x84B0, 0x8470, 0x8490, 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, + 0x8460, 0x8450, 0x8450, 0x8450, 0x8440, 0x8430, 0x8420, 0x8420, 0x8410, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83D0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, + 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x83D0, 0x8420, 0x8420, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, + 0x8490, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84C0, 0x84D0, 0x84E0, 0x84E0, 0x84F0, 0x84F0, 0x8500, 0x84E0, 0x8510, + 0x8510, 0x8520, 0x8550, 0x8550, 0x8530, 0x8540, 0x8530, 0x85A0, 0x8610, 0x8700, 0x88F0, 0x8D80, 0x94C0, 0x9D80, 0xA630, 0xAEF0, + 0xB880, 0xC250, 0xCC70, 0xD6F0, 0xE130, 0xEBE0, 0xF510, 0xFFA0, 0x07A0, 0x0F50, 0x1710, 0x2060, 0x2A80, 0x35C0, 0x40B0, 0x4AB0, + 0x5520, 0x5D70, 0x6520, 0x6BE0, 0x71C0, 0x7600, 0x79D0, 0x7CB0, 0x7E70, 0x7F10, 0x7EF0, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F40, + 0x7F40, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F50, 0x7F30, + 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7EF0, 0x7E10, 0x7CD0, 0x7BC0, 0x7AF0, 0x7AA0, + 0x7AA0, 0x7B20, 0x7BF0, 0x7C90, 0x7CE0, 0x7D40, 0x7DD0, 0x7E20, 0x7E40, 0x7E90, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F10, + 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, + 0x7F10, 0x7EE0, 0x7E00, 0x7CD0, 0x7B30, 0x7970, 0x7840, 0x77B0, 0x77B0, 0x77D0, 0x7770, 0x7750, 0x7780, 0x7770, 0x77C0, 0x7850, + 0x7890, 0x7830, 0x77A0, 0x7730, 0x7720, 0x7750, 0x7890, 0x7A30, 0x7B20, 0x7BD0, 0x7BF0, 0x7C10, 0x7C60, 0x7CC0, 0x7D10, 0x7D70, + 0x7D60, 0x7D20, 0x7CF0, 0x7D10, 0x7D60, 0x7D30, 0x7CB0, 0x7B60, 0x7A20, 0x78C0, 0x7790, 0x76E0, 0x7620, 0x75E0, 0x75E0, 0x75E0, + 0x7610, 0x7650, 0x7610, 0x7560, 0x7490, 0x72D0, 0x7030, 0x6DD0, 0x6C30, 0x6A90, 0x68B0, 0x6640, 0x6310, 0x5F10, 0x5A20, 0x5500, + 0x4EE0, 0x49E0, 0x4430, 0x3DF0, 0x3680, 0x2EC0, 0x26C0, 0x1F30, 0x1890, 0x11C0, 0x0B10, 0x0580, 0x00A0, 0xFC70, 0xFA50, 0xF980, + 0xFA10, 0xFC20, 0x0050, 0x0510, 0x0A80, 0x1060, 0x16C0, 0x1CA0, 0x20B0, 0x2320, 0x2460, 0x2310, 0x2000, 0x1AE0, 0x12D0, 0x0930, + 0xFD30, 0xEFC0, 0xE1F0, 0xD490, 0xC7D0, 0xBC90, 0xB200, 0xA7F0, 0x9E80, 0x9540, 0x8D50, 0x8830, 0x85F0, 0x8520, 0x84E0, 0x84D0, + 0x84B0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8470, 0x8460, 0x8460, 0x8450, 0x8440, 0x8430, 0x8430, 0x8420, 0x8410, + 0x8410, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83F0, + 0x83D0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, + 0x83C0, 0x83C0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, + 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, + 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x8400, 0x83E0, + 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8410, + 0x8410, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8440, 0x8460, 0x8450, 0x8450, 0x8460, 0x8470, 0x8470, 0x8480, 0x8490, 0x8490, + 0x84A0, 0x84B0, 0x84C0, 0x84D0, 0x84F0, 0x8510, 0x8550, 0x85B0, 0x8660, 0x87A0, 0x8970, 0x8BA0, 0x8E60, 0x9190, 0x9440, 0x9730, + 0x9A80, 0x9D50, 0xA0A0, 0xA430, 0xA7F0, 0xAC10, 0xB110, 0xB4B0, 0xB9D0, 0xBE00, 0xC1E0, 0xC680, 0xCAE0, 0xCFB0, 0xD460, 0xD8B0, + 0xDCC0, 0xE060, 0xE4F0, 0xEA50, 0xF060, 0xF670, 0xFCD0, 0x0410, 0x0B00, 0x1190, 0x1880, 0x1F80, 0x2760, 0x2ED0, 0x35B0, 0x3CB0, + 0x4170, 0x4690, 0x4B00, 0x4F60, 0x6430, 0x69F0, 0x6FE0, 0x7610, 0x7BF0, 0x7ED0, 0x7F70, 0x7F10, 0x7E90, 0x7EB0, 0x7EE0, 0x7F50, + 0x7F10, 0x7EA0, 0x7EC0, 0x7ED0, 0x7F10, 0x7F20, 0x7EC0, 0x7ED0, 0x7F00, 0x7F40, 0x7F10, 0x7E90, 0x7F00, 0x7F20, 0x7EF0, 0x7F10, + 0x7EA0, 0x7F00, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, + 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, 0x7EF0, 0x7F00, 0x7F00, 0x7F70, 0x7EF0, 0x7EF0, 0x7EF0, 0x7EE0, 0x7F50, + 0x7EF0, 0x7EB0, 0x7F00, 0x7F00, 0x7F60, 0x7ED0, 0x7F10, 0x7F00, 0x7F00, 0x7F50, 0x7F00, 0x7EC0, 0x7ED0, 0x7EF0, 0x7F50, 0x7F00, + 0x7EA0, 0x7ED0, 0x7ED0, 0x7F20, 0x7F00, 0x7E90, 0x7ED0, 0x7EE0, 0x7F00, 0x7F10, 0x7E90, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7E90, + 0x7F00, 0x7F20, 0x7F00, 0x7F10, 0x7F00, 0x7F20, 0x7F20, 0x7EF0, 0x7F10, 0x7EE0, 0x7F40, 0x7EF0, 0x7F30, 0x7F20, 0x7F00, 0x7F50, + 0x7EF0, 0x7F40, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F00, 0x7F00, 0x7F00, 0x7F50, 0x7EB0, + 0x7E70, 0x7EE0, 0x7EF0, 0x7F40, 0x7ED0, 0x7E90, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7EA0, 0x7F00, 0x7F00, 0x7EF0, 0x7EF0, 0x7EB0, + 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F10, 0x7F20, 0x7EF0, 0x7F80, + 0x7F00, 0x7F20, 0x7F10, 0x7EF0, 0x7F70, 0x7EF0, 0x7EE0, 0x7EF0, 0x7EE0, 0x7F60, 0x7F10, 0x7EF0, 0x7F00, 0x7EE0, 0x7EF0, 0x7F10, + 0x7ED0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7EB0, 0x7EE0, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, 0x7EE0, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, + 0x7EF0, 0x7F10, 0x7EF0, 0x7EF0, 0x7F00, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7EF0, 0x7F60, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7F70, + 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F60, 0x7F10, 0x7F10, 0x7F00, 0x7EE0, 0x7F70, 0x7EF0, 0x7EE0, 0x7F00, 0x7F20, 0x7F70, 0x7EF0, + 0x7EB0, 0x7EF0, 0x7EE0, 0x7F50, 0x7ED0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F30, 0x7F00, 0x7EA0, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7E90, + 0x7F00, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F50, 0x7F00, 0x7F20, 0x7DE0, 0x6980, 0x5530, + 0x4040, 0x2930, 0x15E0, 0x0370, 0xF150, 0xE030, 0xCEE0, 0xBDC0, 0xABC0, 0x9800, 0x88C0, 0x8540, 0x84E0, 0x84B0, 0x84D0, 0x8480, + 0x8470, 0x8460, 0x8450, 0x8430, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8420, 0x8440, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8440, 0x8470, 0x8450, 0x8490, 0x8470, 0x8480, 0x84B0, 0x84E0, 0x8610, 0x9C90, 0xBD70, 0xDEE0, 0xFFF0, + 0x2040, 0x3F30, 0x5B20, 0x72A0, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F30, + 0x7F20, 0x7F40, 0x7F30, 0x7F10, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F00, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x6AB0, 0x4970, + 0x26C0, 0x0890, 0xED60, 0xD580, 0xC1C0, 0xB1A0, 0xA530, 0x9C30, 0x95C0, 0x92D0, 0x92B0, 0x9600, 0x9D60, 0xA840, 0xB590, 0xC5C0, + 0xD6E0, 0xE880, 0xFA10, 0x0800, 0x12F0, 0x1B80, 0x21B0, 0x25A0, 0x2890, 0x2930, 0x27B0, 0x23B0, 0x1C60, 0x1290, 0x06B0, 0xF9F0, + 0xEBF0, 0xDBE0, 0xCA30, 0xB610, 0x9D50, 0x89D0, 0x8520, 0x84C0, 0x84A0, 0x8480, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8440, + 0x8440, 0x8440, 0x8430, 0x8430, 0x8420, 0x8430, 0x8430, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8460, 0x8440, 0x8450, 0x8450, 0x8460, 0x8470, 0x8480, 0x8490, 0x84A0, 0x84D0, 0x8520, 0x86A0, 0x8FE0, 0xA240, 0xB2D0, 0xC2D0, + 0xD250, 0xE1D0, 0xEF90, 0xFC80, 0x07E0, 0x11F0, 0x19B0, 0x1FD0, 0x2480, 0x2740, 0x29B0, 0x2B60, 0x2D50, 0x2F10, 0x3150, 0x33A0, + 0x3680, 0x3990, 0x3C00, 0x3DF0, 0x3F90, 0x4030, 0x3FE0, 0x3EC0, 0x3AF0, 0x35D0, 0x2EC0, 0x26A0, 0x1B70, 0x0EC0, 0xFFE0, 0xEE70, + 0xDC10, 0xC840, 0xB430, 0x9F70, 0x8DC0, 0x8630, 0x8510, 0x84D0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8470, 0x8470, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84E0, + 0x8510, 0x8580, 0x86B0, 0x8A70, 0x92F0, 0x9D70, 0xA750, 0xB010, 0xB8C0, 0xC140, 0xC840, 0xCDC0, 0xD290, 0xD700, 0xDAF0, 0xDF10, + 0xE250, 0xE4C0, 0xE720, 0xE890, 0xE9D0, 0xEA70, 0xEAC0, 0xEA80, 0xE9D0, 0xE950, 0xE8E0, 0xE790, 0xE5F0, 0xE3A0, 0xE180, 0xDF10, + 0xDCD0, 0xDB80, 0xD9E0, 0xD8F0, 0xD7A0, 0xD650, 0xD520, 0xD330, 0xD110, 0xCFC0, 0xCD90, 0xCBB0, 0xC9E0, 0xC860, 0xC710, 0xC610, + 0xC530, 0xC3A0, 0xC250, 0xC160, 0xBFF0, 0xBF10, 0xBE20, 0xBD40, 0xBCD0, 0xBC10, 0xBC00, 0xBB70, 0xBB30, 0xBBD0, 0xBC00, 0xBD90, + 0xBF00, 0xC030, 0xC280, 0xC490, 0xC730, 0xC9A0, 0xCD60, 0xD220, 0xD8C0, 0xDEE0, 0xE4B0, 0xEA90, 0xF0A0, 0xF680, 0xFDD0, 0x0590, + 0x0DE0, 0x16D0, 0x1F10, 0x2720, 0x2F00, 0x3640, 0x3E90, 0x4620, 0x4D00, 0x5390, 0x5A80, 0x6090, 0x6630, 0x6C20, 0x71C0, 0x7680, + 0x7AB0, 0x7DA0, 0x7F50, 0x7EF0, 0x7F20, 0x7F00, 0x7F00, 0x7F70, 0x7F10, 0x7EB0, 0x7EC0, 0x7ED0, 0x7F60, 0x7EF0, 0x7ED0, 0x7EF0, + 0x7EE0, 0x7F20, 0x7F10, 0x7E90, 0x7EE0, 0x7ED0, 0x7F10, 0x7F10, 0x7E70, 0x7EE0, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F00, 0x7F20, + 0x7F10, 0x7F10, 0x7EC0, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7F20, + 0x7F10, 0x7F00, 0x7F40, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F90, 0x7ED0, 0x7F00, 0x7ED0, 0x7F10, 0x7F60, 0x7EE0, 0x7EC0, 0x7F10, + 0x7F20, 0x7F40, 0x7EF0, 0x7EB0, 0x7F00, 0x7F10, 0x7F10, 0x7EF0, 0x7EA0, 0x7EF0, 0x7D10, 0x7750, 0x7320, 0x6E20, 0x6960, 0x6510, + 0x5FF0, 0x5B70, 0x5660, 0x51D0, 0x4D50, 0x49E0, 0x4190, 0x40F0, 0x41B0, 0x42C0, 0x4500, 0x4730, 0x4950, 0x4BC0, 0x4EA0, 0x5280, + 0x5650, 0x5A90, 0x5E30, 0x6100, 0x63C0, 0x6640, 0x6810, 0x6AC0, 0x6CE0, 0x6ED0, 0x70B0, 0x7120, 0x71F0, 0x7380, 0x74B0, 0x75B0, + 0x76A0, 0x7790, 0x7780, 0x7740, 0x7650, 0x7500, 0x7380, 0x7140, 0x6D90, 0x6910, 0x6230, 0x5AA0, 0x5110, 0x46B0, 0x3B00, 0x2CF0, + 0x1E50, 0x0E50, 0xFE60, 0xEE60, 0xDF10, 0xCEE0, 0xC090, 0xB210, 0xA450, 0x97A0, 0x8CC0, 0x8790, 0x85B0, 0x8520, 0x84F0, 0x84D0, + 0x84C0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8490, 0x8480, 0x84B0, 0x8490, 0x8470, 0x8470, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8490, 0x84A0, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8490, + 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84D0, 0x84E0, 0x8500, 0x8530, 0x85B0, 0x8690, 0x8880, 0x8DD0, 0x94F0, 0x9D30, 0xA4D0, 0xACB0, + 0xB470, 0xBA50, 0xC140, 0xC700, 0xCE10, 0xD550, 0xDC30, 0xE380, 0xE950, 0xEDD0, 0xF260, 0xF6E0, 0xFAC0, 0xFF80, 0x03C0, 0x0880, + 0x0B80, 0x0F30, 0x1320, 0x17E0, 0x1D30, 0x22B0, 0x2990, 0x3030, 0x3670, 0x3D00, 0x4440, 0x4C10, 0x53B0, 0x5AE0, 0x6240, 0x6850, + 0x6E90, 0x74B0, 0x7F60, 0x7F10, 0x7F10, 0x7F00, 0x7EE0, 0x7F50, 0x7F10, 0x7F10, 0x7F00, 0x7EE0, 0x7F80, 0x7F00, 0x7F00, 0x7F10, + 0x7F10, 0x7F80, 0x7F00, 0x7ED0, 0x7EF0, 0x7F00, 0x7F30, 0x7ED0, 0x7EB0, 0x7F00, 0x7F20, 0x7F60, 0x7ED0, 0x7EB0, 0x7F00, 0x7EF0, + 0x7EF0, 0x7F10, 0x7EA0, 0x7F10, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, + 0x7F20, 0x7EF0, 0x7F90, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, 0x7EF0, 0x7EF0, 0x7EE0, + 0x7EF0, 0x7F70, 0x7F20, 0x7EC0, 0x7ED0, 0x7EB0, 0x7F10, 0x7F10, 0x7EB0, 0x7EB0, 0x7EC0, 0x7EF0, 0x7F10, 0x7EA0, 0x6F60, 0x5750, + 0x3B50, 0x2290, 0x0A60, 0xF3C0, 0xDF20, 0xCBD0, 0xBCF0, 0xB120, 0xA8C0, 0xA240, 0x9E20, 0x9C10, 0x99F0, 0x9800, 0x9630, 0x9490, + 0x9370, 0x9240, 0x91E0, 0x92C0, 0x94F0, 0x98F0, 0x9E00, 0xA340, 0xA980, 0xAEA0, 0xB420, 0xBA10, 0xC0B0, 0xC830, 0xD060, 0xD980, + 0xE230, 0xEAB0, 0xF2C0, 0xFA70, 0x0300, 0x0A00, 0x10F0, 0x1880, 0x1FE0, 0x2800, 0x2F50, 0x3610, 0x3D60, 0x4440, 0x4A10, 0x4E90, + 0x51F0, 0x5700, 0x5A50, 0x5F70, 0x6420, 0x6840, 0x6DB0, 0x7260, 0x77A0, 0x7D50, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7F40, + 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7350, 0x64B0, 0x5360, 0x4020, 0x29E0, + 0x13E0, 0xFC60, 0xE380, 0xC950, 0xAED0, 0x9550, 0x8780, 0x8550, 0x84E0, 0x84D0, 0x84C0, 0x84C0, 0x84D0, 0x84E0, 0x84F0, 0x8500, + 0x8500, 0x8500, 0x84F0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x8500, 0x84E0, 0x84E0, 0x84E0, 0x84F0, + 0x84F0, 0x8510, 0x8530, 0x8570, 0x85F0, 0x8690, 0x8790, 0x88C0, 0x8AA0, 0x8CF0, 0x90E0, 0x9500, 0x98B0, 0x9B80, 0x9D70, 0x9E60, + 0x9E70, 0x9D10, 0x9C20, 0x9AF0, 0x9930, 0x97A0, 0x9680, 0x9710, 0x9A60, 0xA080, 0xA810, 0xB0F0, 0xBA00, 0xC360, 0xCCC0, 0xD490, + 0xDAD0, 0xDF80, 0xE0F0, 0xDE50, 0xD6B0, 0xCAD0, 0xBBE0, 0xA9F0, 0x99F0, 0x8CB0, 0x86D0, 0x8580, 0x84F0, 0x84D0, 0x84C0, 0x84B0, + 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x84B0, 0x8490, 0x84C0, 0x84A0, 0x84B0, 0x84C0, 0x84D0, 0x84E0, 0x84F0, + 0x8500, 0x8510, 0x8550, 0x85F0, 0x8850, 0x90E0, 0x9E20, 0xABF0, 0xB9F0, 0xC880, 0xD7D0, 0xE6C0, 0xF4D0, 0x02A0, 0x0DA0, 0x16F0, + 0x1F90, 0x27B0, 0x2EE0, 0x34F0, 0x3970, 0x3BB0, 0x3B40, 0x3890, 0x3360, 0x2D00, 0x25A0, 0x1D50, 0x1500, 0x0CD0, 0x0560, 0xFE30, + 0xF880, 0xF570, 0xF3F0, 0xF3A0, 0xF520, 0xF780, 0xFB80, 0x0140, 0x0870, 0x1080, 0x1930, 0x2300, 0x2D80, 0x3850, 0x44D0, 0x5190, + 0x5D70, 0x6A30, 0x74B0, 0x7D60, 0x7EF0, 0x7F30, 0x7F20, 0x7EC0, 0x7F20, 0x7F10, 0x7F20, 0x7F00, 0x7EC0, 0x7ED0, 0x7F10, 0x7F30, + 0x7EE0, 0x7E90, 0x7EF0, 0x7EF0, 0x7C50, 0x6A00, 0x50C0, 0x31D0, 0x0EF0, 0xEBB0, 0xCC50, 0xB220, 0x9D00, 0x8F80, 0x8880, 0x8600, + 0x8530, 0x84F0, 0x84F0, 0x84F0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84F0, 0x84D0, 0x84E0, 0x8500, 0x8530, 0x85C0, + 0x8720, 0x8AE0, 0x9370, 0x9D90, 0xA810, 0xB2C0, 0xBE80, 0xCBB0, 0xD8F0, 0xE730, 0xF630, 0x0580, 0x1410, 0x2250, 0x3030, 0x3E10, + 0x4F30, 0x5EE0, 0x6DF0, 0x7AD0, 0x7F30, 0x7F20, 0x7EC0, 0x7ED0, 0x7F00, 0x7F40, 0x7F10, 0x7E90, 0x7E90, 0x7F00, 0x7EF0, 0x7F10, + 0x7F00, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F30, 0x7F20, 0x7F20, 0x7EF0, 0x7F10, 0x7220, 0x5A40, 0x3A00, 0x1510, 0xEC80, + 0xC3F0, 0x9D90, 0x8740, 0x84F0, 0x84C0, 0x84B0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8470, + 0x8470, 0x8490, 0x8460, 0x8460, 0x8410, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8480, 0x8460, 0x8480, 0x8440, + 0x8460, 0x8450, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8490, 0x84A0, 0x84D0, + 0x84B0, 0x84D0, 0x84E0, 0x8510, 0x8550, 0x8600, 0x8810, 0x8E50, 0x9A10, 0xA590, 0xB260, 0xBDB0, 0xC830, 0xD160, 0xD9B0, 0xE1F0, + 0xEA30, 0xF160, 0xF870, 0xFF30, 0x0540, 0x0AD0, 0x0F10, 0x1330, 0x1760, 0x1B60, 0x1F90, 0x2290, 0x25B0, 0x2790, 0x2930, 0x2B70, + 0x2D00, 0x2ED0, 0x3020, 0x3120, 0x3250, 0x3300, 0x3360, 0x33A0, 0x3310, 0x33B0, 0x3370, 0x33C0, 0x3410, 0x34B0, 0x3630, 0x3710, + 0x37C0, 0x3800, 0x37B0, 0x37B0, 0x3800, 0x37C0, 0x36F0, 0x3690, 0x31C0, 0x2F60, 0x2E60, 0x2C80, 0x2B00, 0x29F0, 0x2970, 0x2B80, + 0x2EC0, 0x3430, 0x3A50, 0x4210, 0x4BB0, 0x5460, 0x5BE0, 0x6210, 0x6680, 0x6AA0, 0x6D20, 0x6F10, 0x70B0, 0x7230, 0x73A0, 0x7440, + 0x73C0, 0x7230, 0x6F00, 0x6AE0, 0x64D0, 0x5EF0, 0x5850, 0x5150, 0x4A70, 0x43C0, 0x3CD0, 0x3730, 0x31D0, 0x2EC0, 0x2CC0, 0x2A70, + 0x28B0, 0x2700, 0x2690, 0x26D0, 0x27A0, 0x2A80, 0x2E40, 0x3310, 0x3880, 0x3C80, 0x4130, 0x44B0, 0x4720, 0x48D0, 0x4850, 0x4550, + 0x3EE0, 0x3490, 0x27E0, 0x1920, 0x0980, 0xF910, 0xE960, 0xDB80, 0xCF30, 0xC5D0, 0xBDE0, 0xB7F0, 0xB470, 0xB280, 0xB300, 0xB3B0, + 0xB4B0, 0xB5E0, 0xB640, 0xB470, 0xB1B0, 0xAD10, 0xA830, 0xA1D0, 0x9B60, 0x9470, 0x8EA0, 0x8AA0, 0x8810, 0x86E0, 0x8640, 0x85F0, + 0x85B0, 0x8570, 0x8560, 0x8540, 0x8530, 0x8520, 0x8510, 0x8500, 0x8500, 0x84F0, 0x84F0, 0x84E0, 0x8530, 0x84E0, 0x84E0, 0x84F0, + 0x8500, 0x8510, 0x8540, 0x8590, 0x8630, 0x8770, 0x89E0, 0x90E0, 0x99C0, 0xA390, 0xAE00, 0xB8E0, 0xC420, 0xCF50, 0xDAF0, 0xE760, + 0xF470, 0x00C0, 0x0BD0, 0x1730, 0x20B0, 0x2970, 0x3180, 0x37B0, 0x3E20, 0x43C0, 0x48B0, 0x4E20, 0x51E0, 0x5650, 0x5A10, 0x5C70, + 0x5EA0, 0x5F80, 0x60C0, 0x60E0, 0x6090, 0x6030, 0x5E60, 0x5D40, 0x5B50, 0x59B0, 0x5920, 0x5940, 0x5B90, 0x5EB0, 0x6260, 0x66F0, + 0x69F0, 0x6B60, 0x6960, 0x63F0, 0x5B00, 0x4F50, 0x4150, 0x3270, 0x23C0, 0x1710, 0x0BB0, 0x01F0, 0xF8C0, 0xEEA0, 0xE510, 0xDB00, + 0xD020, 0xC480, 0xB8E0, 0xAD40, 0xA110, 0x9580, 0x8C60, 0x8810, 0x86A0, 0x85E0, 0x8590, 0x8580, 0x8590, 0x8580, 0x85A0, 0x85F0, + 0x8680, 0x87D0, 0x8A80, 0x9020, 0x9850, 0xA280, 0xAC20, 0xB650, 0xC180, 0xCB80, 0xD550, 0xDD90, 0xE570, 0xEC70, 0xF210, 0xF790, + 0xFBE0, 0x0020, 0x02C0, 0x04C0, 0x0750, 0x0980, 0x0B70, 0x0CA0, 0x0CB0, 0x0D00, 0x0CE0, 0x0B70, 0x0930, 0x05B0, 0x0120, 0xF9D0, + 0xEFD0, 0xBD00, 0xAFC0, 0xA3C0, 0x9AB0, 0x9310, 0x8D50, 0x8980, 0x8740, 0x85F0, 0x8550, 0x8510, 0x84E0, 0x84D0, 0x84C0, 0x84B0, + 0x84D0, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, + 0x8490, 0x8490, 0x8450, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, + 0x8490, 0x84A0, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, + 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x84C0, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84D0, + 0x8500, 0x8500, 0x8520, 0x8550, 0x85B0, 0x8640, 0x8750, 0x8950, 0x8D10, 0x92C0, 0x9920, 0x9DE0, 0xA1C0, 0xA5E0, 0xA9D0, 0xAC90, + 0xAFB0, 0xB2D0, 0xB5F0, 0xB8B0, 0xBAC0, 0xBCD0, 0xBDE0, 0xBF30, 0xBFD0, 0xBF80, 0xBEE0, 0xBE30, 0xBD50, 0xBC30, 0xBAA0, 0xB940, + 0xB760, 0xB5B0, 0xB440, 0xB3D0, 0xB270, 0xB1D0, 0xB1C0, 0xB1B0, 0xB0D0, 0xB020, 0xAFC0, 0xAED0, 0xAE80, 0xAEE0, 0xAF00, 0xAEE0, + 0xAE10, 0xAC80, 0xAA70, 0xA890, 0xA780, 0xA720, 0xA6F0, 0xA630, 0xA620, 0xA6C0, 0xA740, 0xA7A0, 0xA7F0, 0xA7E0, 0xA820, 0xA870, + 0xA9D0, 0xABA0, 0xADF0, 0xB030, 0xB200, 0xB330, 0xB440, 0xB540, 0xB6B0, 0xB940, 0xBBC0, 0xBE30, 0xBFF0, 0xC100, 0xC210, 0xC310, + 0xC3F0, 0xC580, 0xC760, 0xC940, 0xCAC0, 0xCBC0, 0xCCF0, 0xCE80, 0xD000, 0xD250, 0xD450, 0xD760, 0xD9D0, 0xDBF0, 0xDEB0, 0xE160, + 0xE460, 0xE6F0, 0xE990, 0xEC60, 0xEFD0, 0xF380, 0xF760, 0xFAE0, 0xFDD0, 0x0030, 0x01C0, 0x02F0, 0x04B0, 0x0730, 0x0900, 0x0AD0, + 0x0C10, 0x0C90, 0x0C00, 0x0B40, 0x0950, 0x0850, 0x0710, 0x0600, 0x0560, 0x0580, 0x05D0, 0x06A0, 0x0750, 0x08D0, 0x0B00, 0x0E20, + 0x1330, 0x1960, 0x2100, 0x2A10, 0x3410, 0x3EA0, 0x49E0, 0x54F0, 0x6090, 0x6BE0, 0x76F0, 0x7E90, 0x7F30, 0x7F20, 0x7F20, 0x7F30, + 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, + 0x7F60, 0x7F40, 0x7F70, 0x7F20, 0x7EE0, 0x7F10, 0x7F10, 0x7EF0, 0x7EF0, 0x7E80, 0x7F00, 0x7F00, 0x7EF0, 0x7EF0, 0x7E90, 0x7F00, + 0x7F00, 0x7F10, 0x7F10, 0x7E70, 0x7EE0, 0x7EE0, 0x79E0, 0x7040, 0x6430, 0x5700, 0x4820, 0x3900, 0x2B30, 0x1E40, 0x1240, 0x0890, + 0xFF30, 0xF660, 0xEDA0, 0xE450, 0xDCA0, 0xD4A0, 0xCC80, 0xC3C0, 0xBB80, 0xB2F0, 0xAA00, 0xA110, 0x9800, 0x8FC0, 0x8A80, 0x8780, + 0x8630, 0x85A0, 0x8550, 0x8530, 0x8510, 0x8500, 0x8500, 0x84F0, 0x84F0, 0x84E0, 0x84E0, 0x84D0, 0x84D0, 0x84F0, 0x84D0, 0x84D0, + 0x84D0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84A0, 0x8460, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8470, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, + 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84D0, 0x84D0, 0x84E0, 0x84F0, + 0x84F0, 0x8500, 0x8510, 0x8510, 0x8520, 0x8530, 0x8530, 0x8540, 0x8550, 0x8550, 0x8580, 0x8590, 0x85B0, 0x85C0, 0x85E0, 0x85F0, + 0x85D0, 0x85B0, 0x85D0, 0x8590, 0x85B0, 0x8580, 0x8580, 0x8580, 0x8560, 0x8550, 0x8540, 0x8530, 0x8530, 0x8530, 0x8540, 0x8540, + 0x8550, 0x8580, 0x85C0, 0x8650, 0x8780, 0x8A70, 0x91D0, 0x9C50, 0xA6E0, 0xB220, 0xBD60, 0xC8F0, 0xD440, 0xDE60, 0xE690, 0xEDF0, + 0xF480, 0xF880, 0xFBF0, 0xFD80, 0xFD70, 0xF890, 0xF180, 0xE6E0, 0xDA50, 0xCC40, 0xBE60, 0xB150, 0xA5F0, 0x9C00, 0x9300, 0x8CC0, + 0x88D0, 0x86F0, 0x8600, 0x8580, 0x8540, 0x8520, 0x8500, 0x8500, 0x8500, 0x8530, 0x8500, 0x8500, 0x8500, 0x84E0, 0x8510, 0x8510, + 0x8530, 0x8530, 0x8550, 0x8570, 0x85A0, 0x85F0, 0x86A0, 0x8810, 0x8AE0, 0x8F50, 0xA150, 0xA4A0, 0xA7A0, 0xA9C0, 0xAA50, 0xA920, + 0xA4E0, 0x9F10, 0x9740, 0x8DC0, 0x87E0, 0x8580, 0x84F0, 0x84C0, 0x84A0, 0x8490, 0x8480, 0x8480, 0x8470, 0x8460, 0x8460, 0x8460, + 0x8460, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8460, 0x8470, 0x8470, 0x8480, 0x84A0, 0x8480, 0x8490, + 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84E0, 0x84D0, 0x84E0, 0x84E0, 0x8500, 0x84F0, + 0x84F0, 0x8500, 0x84B0, 0x8500, 0x8500, 0x8510, 0x8520, 0x8530, 0x8550, 0x8570, 0x8590, 0x85B0, 0x85E0, 0x8630, 0x86B0, 0x8790, + 0x8920, 0x8B10, 0x8DE0, 0x9280, 0x9820, 0x9F60, 0xA640, 0xAD80, 0xB6B0, 0xC020, 0xCA30, 0xD4D0, 0xDFB0, 0xEB90, 0xF780, 0x02B0, + 0x0CD0, 0x1470, 0x1B60, 0x2080, 0x23B0, 0x2520, 0x2440, 0x2380, 0x2200, 0x2180, 0x2110, 0x2030, 0x2020, 0x1E90, 0x1CC0, 0x1B90, + 0x1BC0, 0x1E80, 0x21F0, 0x2680, 0x2BA0, 0x30E0, 0x3610, 0x3BB0, 0x41A0, 0x4890, 0x4EC0, 0x54C0, 0x59C0, 0x5EB0, 0x6440, 0x69C0, + 0x6F90, 0x7530, 0x79F0, 0x7D90, 0x7E90, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EB0, 0x7F00, 0x7ED0, 0x7ED0, 0x76C0, 0x6A40, 0x5BD0, + 0x4A00, 0x34E0, 0x1EE0, 0x06C0, 0xECA0, 0xD490, 0xBDF0, 0xA9C0, 0x9840, 0x8C50, 0x87B0, 0x8650, 0x85E0, 0x85B0, 0x85B0, 0x8590, + 0x8560, 0x8530, 0x8510, 0x8500, 0x84F0, 0x84E0, 0x84E0, 0x8500, 0x84E0, 0x84F0, 0x8500, 0x8520, 0x8550, 0x85E0, 0x8780, 0x8CD0, + 0x97E0, 0xA3C0, 0xAFD0, 0xBB80, 0xC570, 0xCD30, 0xD1C0, 0xD2B0, 0xD140, 0xCC80, 0xC580, 0xBCF0, 0xB3C0, 0xA980, 0x9F90, 0x9540, + 0x8D30, 0x88B0, 0x86D0, 0x8600, 0x85B0, 0x8580, 0x8580, 0x85B0, 0x85F0, 0x8670, 0x8780, 0x8890, 0x89D0, 0x8AC0, 0x8BA0, 0x8CC0, + 0x8DC0, 0x8E60, 0x8DA0, 0x8C00, 0x8A40, 0x88A0, 0x8780, 0x8690, 0x8600, 0x8590, 0x8550, 0x8520, 0x8510, 0x8500, 0x84F0, 0x84F0, + 0x84F0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84F0, 0x8500, 0x8500, 0x8520, 0x8530, 0x8550, 0x8590, 0x85F0, 0x8690, 0x87E0, 0x8A60, + 0x8F70, 0x9680, 0x9E70, 0xA5E0, 0xADC0, 0xB580, 0xBD10, 0xC540, 0xCCA0, 0xD3E0, 0xDB50, 0xE310, 0xEAA0, 0xF1A0, 0xF7F0, 0xFDA0, + 0x0320, 0x08A0, 0x0ED0, 0x1510, 0x1AE0, 0x1FE0, 0x2550, 0x29D0, 0x2DE0, 0x31D0, 0x35B0, 0x3A40, 0x3DE0, 0x40D0, 0x4370, 0x4520, + 0x47C0, 0x4A50, 0x4C60, 0x4ED0, 0x50D0, 0x52E0, 0x54A0, 0x5660, 0x5890, 0x5A10, 0x5CA0, 0x5E10, 0x5E80, 0x5F00, 0x5F10, 0x5FD0, + 0x60B0, 0x6200, 0x64D0, 0x6670, 0x67C0, 0x68C0, 0x69B0, 0x6AB0, 0x6C00, 0x6D40, 0x6F50, 0x71B0, 0x7440, 0x7690, 0x78A0, 0x7AC0, + 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F20, 0x7EE0, 0x7E40, 0x7CD0, 0x7A90, 0x7760, 0x73D0, 0x7050, 0x6D40, 0x6A20, + 0x66D0, 0x6260, 0x5E70, 0x5910, 0x5290, 0x4AE0, 0x42C0, 0x3860, 0x2FE0, 0x2910, 0x2250, 0x1C00, 0x16A0, 0x1110, 0x0C90, 0x0960, + 0x0840, 0x0860, 0x0A00, 0x0C40, 0x1020, 0x1550, 0x1C50, 0x2490, 0x2DE0, 0x3830, 0x4090, 0x4880, 0x4FF0, 0x5730, 0x5E90, 0x6660, + 0x6E00, 0x7450, 0x7A30, 0x7D60, 0x7E50, 0x7E30, 0x7B30, 0x7460, 0x6890, 0x5940, 0x45B0, 0x2ED0, 0x1890, 0x02C0, 0xECD0, 0xD7A0, + 0xC3E0, 0xB180, 0xA070, 0x92E0, 0x8A30, 0x8740, 0x8640, 0x8600, 0x8620, 0x8690, 0x88B0, 0x8DC0, 0x95B0, 0x9E60, 0xA470, 0xA9B0, + 0xAD90, 0xB040, 0xB280, 0xB380, 0xB270, 0xAF50, 0xA990, 0xA1B0, 0x97C0, 0x8DB0, 0x8800, 0x85D0, 0x8520, 0x84F0, 0x84D0, 0x84C0, + 0x84B0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8470, 0x8480, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8480, + 0x8490, 0x8490, 0x8490, 0x84A0, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84D0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, + 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84F0, 0x84E0, + 0x8530, 0x8550, 0x85F0, 0x8800, 0x8E90, 0x9980, 0xA420, 0xAEA0, 0xB720, 0xBDD0, 0xC2D0, 0xC740, 0xCAB0, 0xCDF0, 0xD010, 0xD2A0, + 0xD430, 0xD4E0, 0xD560, 0xD590, 0xD610, 0xD5C0, 0xD480, 0xD370, 0xD2B0, 0xD2D0, 0xD2D0, 0xD220, 0xD140, 0xCFF0, 0xCDD0, 0xCB90, + 0xC970, 0xC890, 0xC6C0, 0xC5C0, 0xC400, 0xC230, 0xC0E0, 0xBF00, 0xBD40, 0xBAE0, 0xB8F0, 0xB6C0, 0xB4D0, 0xB300, 0xB140, 0xAF80, + 0xAE10, 0xAC80, 0xAB10, 0xA9E0, 0xA920, 0xA8F0, 0xAA00, 0xABA0, 0xAE00, 0xB000, 0xB390, 0xB750, 0xBD00, 0xC2C0, 0xC970, 0xD0B0, + 0xD890, 0xE0F0, 0xE990, 0xF270, 0xFD00, 0x06C0, 0x1230, 0x1DC0, 0x2890, 0x3470, 0x3F70, 0x4B40, 0x55F0, 0x6050, 0x69F0, 0x7240, + 0x77F0, 0x7D00, 0x7EC0, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7E90, 0x7F00, 0x7EE0, 0x7F50, 0x7ED0, 0x7EB0, 0x7F00, 0x7F10, 0x7F10, + 0x7F10, 0x7E90, 0x7F00, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F20, + 0x7EF0, 0x7F80, 0x7F10, 0x7EF0, 0x7F30, 0x7F10, 0x7F60, 0x7F10, 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, 0x7F10, 0x7F00, 0x7EE0, 0x7EF0, + 0x7F70, 0x7F20, 0x7EC0, 0x7EE0, 0x7ED0, 0x7F70, 0x7F10, 0x7EB0, 0x7EE0, 0x7C80, 0x7250, 0x68B0, 0x5D60, 0x5280, 0x46D0, 0x3C20, + 0x33A0, 0x2A60, 0x21D0, 0x1900, 0x1120, 0x0B20, 0x0650, 0x0440, 0x0480, 0x06D0, 0x0C70, 0x1320, 0x1B00, 0x21D0, 0x27A0, 0x2B70, + 0x2D30, 0x2E30, 0x2DE0, 0x2B80, 0x2850, 0x22D0, 0x1C70, 0x1590, 0x0F50, 0x0B20, 0x0A60, 0x0B90, 0x0E00, 0x10A0, 0x12E0, 0x1310, + 0x1170, 0x0E60, 0x09B0, 0x04E0, 0xFFC0, 0xFA90, 0xF6B0, 0xF360, 0xF140, 0xEFD0, 0xEF90, 0xF120, 0xF160, 0xF1D0, 0xF0D0, 0xEEE0, + 0xED70, 0xEB30, 0xE9B0, 0xE800, 0xE6F0, 0xE820, 0xE980, 0xEC40, 0xEFF0, 0xF350, 0xF800, 0xFC00, 0x00D0, 0x1EC0, 0x2810, 0x3080, + 0x3860, 0x40C0, 0x4900, 0x50E0, 0x5710, 0x5AB0, 0x5E80, 0x60E0, 0x62F0, 0x64D0, 0x6770, 0x6AD0, 0x6DD0, 0x7030, 0x7340, 0x75E0, + 0x7980, 0x7CB0, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F90, 0x7F10, 0x7EE0, 0x7EE0, 0x7ED0, 0x7F30, 0x7EF0, 0x7ED0, 0x7EE0, + 0x7F00, 0x7F50, 0x7F10, 0x7EA0, 0x7EC0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7EB0, 0x7EE0, 0x7F20, 0x7F10, 0x7F10, 0x7EA0, 0x7F00, 0x7EE0, + 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F00, 0x7EA0, 0x7BE0, 0x7790, 0x72D0, 0x6D00, 0x66E0, 0x6050, 0x5990, + 0x5310, 0x4C60, 0x4680, 0x4080, 0x3AA0, 0x34C0, 0x2F10, 0x2A70, 0x2730, 0x24A0, 0x2370, 0x2300, 0x22F0, 0x2400, 0x2550, 0x2700, + 0x2960, 0x2B90, 0x2F10, 0x3260, 0x3640, 0x3910, 0x3A90, 0x3C00, 0x3B80, 0x3AF0, 0x39B0, 0x37A0, 0x3630, 0x3400, 0x3140, 0x2E10, + 0x29F0, 0x2680, 0x2240, 0x1EE0, 0x1B80, 0x1890, 0x1710, 0x15A0, 0x15C0, 0x16D0, 0x1880, 0x1BF0, 0x2020, 0x25D0, 0x2D10, 0x33B0, + 0x3BC0, 0x42F0, 0x4B30, 0x5280, 0x5940, 0x5FD0, 0x6550, 0x6AC0, 0x6E10, 0x6FB0, 0x70F0, 0x7040, 0x6D90, 0x69B0, 0x6520, 0x6000, + 0x5890, 0x4FF0, 0x4740, 0x3DC0, 0x33D0, 0x28F0, 0x1DA0, 0x12E0, 0x0730, 0xFB00, 0xEF50, 0xE3D0, 0xD980, 0xCE50, 0xC490, 0xBB10, + 0xB2A0, 0xAB00, 0xA320, 0x9D70, 0x98B0, 0x9580, 0x9410, 0x9480, 0x9670, 0x9830, 0x9A50, 0x9BF0, 0x9DF0, 0xA000, 0xA2F0, 0xA620, + 0xA9A0, 0xAC90, 0xAF80, 0xB1A0, 0xB3E0, 0xB690, 0xB830, 0xB920, 0xBA10, 0xBA90, 0xBB60, 0xBC10, 0xBCA0, 0xBE70, 0xBFB0, 0xC0D0, + 0xC230, 0xC310, 0xC480, 0xC590, 0xC790, 0xC9E0, 0xCC30, 0xCE60, 0xCFC0, 0xD0E0, 0xD220, 0xD330, 0xD3C0, 0xD460, 0xD4F0, 0xD4E0, + 0xD4B0, 0xD4D0, 0xD450, 0xD480, 0xD440, 0xD3B0, 0xD3D0, 0xD460, 0xD480, 0xD510, 0xD580, 0xD680, 0xD6B0, 0xD690, 0xD560, 0xD420, + 0xD3D0, 0xD3C0, 0xD470, 0xD470, 0xD4C0, 0xD530, 0xD580, 0xD550, 0xD5D0, 0xD680, 0xD710, 0xD6F0, 0xD630, 0xD640, 0xD5D0, 0xD630, + 0xD6F0, 0xD700, 0xD740, 0xD700, 0xD750, 0xD710, 0xD7E0, 0xD960, 0xDA80, 0xDB20, 0xDB70, 0xDB00, 0xDB80, 0xDBE0, 0xDCA0, 0xDD40, + 0xDDF0, 0xDEF0, 0xDEA0, 0xDE70, 0xDDE0, 0xDDB0, 0xDDD0, 0xDD60, 0xDD40, 0xDCD0, 0xDC20, 0xDC90, 0xDCD0, 0xDCD0, 0xDCC0, 0xDD30, + 0xDDB0, 0xDE30, 0xE020, 0xE350, 0xE6D0, 0xEB00, 0xEE60, 0xF170, 0xF3A0, 0xF670, 0xFA90, 0xFF10, 0x03F0, 0x0940, 0x0D90, 0x11F0, + 0x13A0, 0x1540, 0x1610, 0x16A0, 0x1680, 0x16B0, 0x1670, 0x1560, 0x13C0, 0x11F0, 0x0F60, 0x0CC0, 0x0900, 0x0550, 0x0160, 0xFE40, + 0xFA90, 0xF720, 0xF2E0, 0xEE00, 0xE8D0, 0xE310, 0xDDA0, 0xD890, 0xD340, 0xCE20, 0xC960, 0xC460, 0xBEF0, 0xB9E0, 0xB5A0, 0xB1E0, + 0xAE90, 0xAB70, 0xA860, 0xA5B0, 0xA450, 0xA3F0, 0xA3A0, 0xA4A0, 0xA5B0, 0xA770, 0xA940, 0xAB40, 0xADB0, 0xB080, 0xB470, 0xB8F0, + 0xBE00, 0xC320, 0xC840, 0xCD90, 0xD410, 0xDA30, 0xDFB0, 0xE580, 0xEAD0, 0xF010, 0xF4C0, 0xF960, 0xFF40, 0x04D0, 0x0950, 0x0CE0, + 0x1050, 0x12F0, 0x1530, 0x17A0, 0x1AC0, 0x1DD0, 0x20B0, 0x2310, 0x24C0, 0x2650, 0x2770, 0x2820, 0x2810, 0x2780, 0x26B0, 0x2500, + 0x22F0, 0x20F0, 0x1EA0, 0x1AE0, 0x1710, 0x1280, 0x0E50, 0x0A00, 0x05B0, 0x01E0, 0xFEE0, 0xFC70, 0xFB30, 0xFA10, 0xF9A0, 0xFA70, + 0xFBD0, 0xFD90, 0x0060, 0x03A0, 0x0730, 0x0B30, 0x0F00, 0x12C0, 0x15D0, 0x17F0, 0x19E0, 0x1BE0, 0x1E40, 0x20F0, 0x23B0, 0x2760, + 0x2AE0, 0x2D80, 0x2FB0, 0x31D0, 0x3490, 0x3790, 0x3B60, 0x3EB0, 0x4240, 0x4540, 0x4890, 0x4D20, 0x52A0, 0x5A50, 0x6290, 0x6B30, + 0x7440, 0x7C10, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7EE0, 0x7100, 0x6210, 0x5390, 0x4560, + 0x3910, 0x2D70, 0x2000, 0x11A0, 0x0050, 0xED50, 0xD8B0, 0xC460, 0xAFD0, 0xA070, 0x9500, 0x8EC0, 0x8C30, 0x8C60, 0x9060, 0x9A40, + 0xA690, 0xB780, 0xC7C0, 0xD760, 0xE5F0, 0xF1C0, 0xFC40, 0x0380, 0x0890, 0x0BF0, 0x0E80, 0x1010, 0x1160, 0x12E0, 0x1580, 0x17A0, + 0x1A30, 0x1CC0, 0x1F90, 0x2300, 0x2660, 0x2AC0, 0x2FC0, 0x3610, 0x3CF0, 0x4360, 0x4A80, 0x5180, 0x5830, 0x5DE0, 0x61D0, 0x6590, + 0x6800, 0x69A0, 0x6AF0, 0x6BB0, 0x6BB0, 0x6A50, 0x6860, 0x6400, 0x5DC0, 0x5650, 0x4CC0, 0x43A0, 0x3B00, 0x3230, 0x2960, 0x2060, + 0x1680, 0x0D10, 0x0310, 0xFA40, 0xF1F0, 0xE9D0, 0xE330, 0xDD60, 0xDA50, 0xD920, 0xD9C0, 0xDC40, 0xDEF0, 0xE2B0, 0xE530, 0xE7C0, + 0xEAB0, 0xED60, 0xF050, 0xF2F0, 0xF550, 0xF7A0, 0xFA40, 0xFCD0, 0x0070, 0x0540, 0x0B10, 0x10D0, 0x1700, 0x1DC0, 0x2550, 0x2E50, + 0x3820, 0x4300, 0x4E60, 0x5840, 0x6290, 0x6C30, 0x7600, 0x7D40, 0x7F10, 0x7F10, 0x7F00, 0x7F00, 0x7F10, 0x7F20, 0x7F20, 0x7F00, + 0x7F50, 0x7F10, 0x7F00, 0x7EF0, 0x7EB0, 0x73E0, 0x6660, 0x56F0, 0x47B0, 0x37F0, 0x2940, 0x1C50, 0x1070, 0x0570, 0xFC50, 0xF480, + 0xEE10, 0xE920, 0xE570, 0xE2B0, 0xE1B0, 0xE1A0, 0xE210, 0xE2F0, 0xE460, 0xE5D0, 0xE790, 0xE950, 0xEB60, 0xECA0, 0xECA0, 0xECA0, + 0xEBD0, 0xEAD0, 0xE9A0, 0xE7F0, 0xE6D0, 0xE520, 0xE360, 0xE0F0, 0xDE80, 0xDBF0, 0xD9A0, 0xD710, 0xD500, 0xD3A0, 0xD360, 0xD390, + 0xD510, 0xD870, 0xDB90, 0xE090, 0xE5C0, 0xEB10, 0xF050, 0xF5A0, 0xFB90, 0x00E0, 0x0670, 0x0B30, 0x0F00, 0x1280, 0x1590, 0x1830, + 0x1A40, 0x1AF0, 0x1BD0, 0x1B50, 0x19D0, 0x1830, 0x1600, 0x1480, 0x1290, 0x11B0, 0x1160, 0x1220, 0x1450, 0x17B0, 0x1C00, 0x2210, + 0x28B0, 0x30B0, 0x3920, 0x4220, 0x4C90, 0x5800, 0x6280, 0x6C90, 0x74B0, 0x7BB0, 0x7EC0, 0x7F40, 0x7F30, 0x7F20, 0x7F10, 0x7F00, + 0x7F40, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7D80, 0x78E0, 0x74F0, 0x7080, 0x6C90, 0x67F0, 0x6380, 0x5FD0, 0x5B90, 0x56F0, + 0x5290, 0x4DF0, 0x49E0, 0x44D0, 0x3FF0, 0x3AA0, 0x3570, 0x30D0, 0x2CD0, 0x28F0, 0x2610, 0x22D0, 0x2000, 0x1C30, 0x1820, 0x0EC0, + 0x0D80, 0x0D10, 0x0C90, 0x0CB0, 0x0CE0, 0x0CD0, 0x0D10, 0x0D30, 0x0DB0, 0x0E00, 0x0EA0, 0x1000, 0x1060, 0x11C0, 0x11E0, 0x1090, + 0x0FB0, 0x0E00, 0x0C20, 0x0AD0, 0x0890, 0x05E0, 0x0300, 0xFFF0, 0xFBB0, 0xF660, 0xF1D0, 0xEC80, 0xE750, 0xE1E0, 0xDC90, 0xD6F0, + 0xD0E0, 0xCA70, 0xC330, 0xBC30, 0xB5E0, 0xAF90, 0xAA60, 0xA5D0, 0xA1E0, 0x9F30, 0x9CA0, 0x9B20, 0x9AA0, 0x9B50, 0x9D00, 0x9F30, + 0xA2F0, 0xA6C0, 0xAAC0, 0xAF10, 0xB4B0, 0xBA20, 0xC0D0, 0xC730, 0xCE20, 0xD430, 0xD930, 0xDF90, 0xE490, 0xEB00, 0xF090, 0xF570, + 0xFAE0, 0xFF90, 0x0480, 0x0990, 0x0EA0, 0x1400, 0x1900, 0x1D80, 0x2210, 0x2650, 0x2BD0, 0x3170, 0x37A0, 0x3D50, 0x4310, 0x49C0, + 0x50E0, 0x57D0, 0x5EF0, 0x6630, 0x6DE0, 0x74D0, 0x7B70, 0x7EE0, 0x7F30, 0x7F00, 0x7F00, 0x7F90, 0x7EF0, 0x7EB0, 0x7EE0, 0x7EF0, + 0x7F30, 0x7EE0, 0x7EC0, 0x7EF0, 0x7F10, 0x7F30, 0x7EE0, 0x7E90, 0x7910, 0x6860, 0x54D0, 0x4210, 0x2F60, 0x1E00, 0x0D50, 0xFE30, + 0xF0B0, 0xE520, 0xDAB0, 0xD170, 0xCAC0, 0xC690, 0xC380, 0xC1F0, 0xC2A0, 0xC4F0, 0xC980, 0xCF70, 0xD810, 0xE1F0, 0xED70, 0xFAB0, + 0x07D0, 0x1530, 0x2230, 0x2DF0, 0x38F0, 0x41F0, 0x4840, 0x4D10, 0x5040, 0x52A0, 0x54D0, 0x5770, 0x59A0, 0x5AC0, 0x5A90, 0x56F0, + 0x4FF0, 0x4740, 0x3BB0, 0x3030, 0x2400, 0x1770, 0x0C50, 0x00A0, 0xF7C0, 0xEF40, 0xE750, 0xE070, 0xD900, 0xD140, 0xC980, 0xC1C0, + 0xB9E0, 0xB200, 0xAA90, 0xA370, 0x9BF0, 0x9530, 0x8EE0, 0x8A80, 0x87E0, 0x8650, 0x85E0, 0x8550, 0x8550, 0x8500, 0x84F0, 0x84F0, + 0x84E0, 0x84E0, 0x84E0, 0x84D0, 0x84E0, 0x84D0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84F0, 0x84D0, 0x84F0, 0x8500, + 0x8510, 0x8530, 0x8540, 0x8580, 0x85E0, 0x8660, 0x8770, 0x8970, 0x8D10, 0x92C0, 0x9890, 0x9E80, 0xA4A0, 0xAB40, 0xB100, 0xB710, + 0xBD80, 0xC410, 0xCAA0, 0xD150, 0xD850, 0xDF50, 0xE5D0, 0xEB70, 0xF0B0, 0xF4E0, 0xF980, 0xFDE0, 0x02B0, 0x06E0, 0x0A40, 0x0E60, + 0x10A0, 0x1280, 0x1490, 0x1610, 0x1930, 0x1BA0, 0x1CD0, 0x1E50, 0x1EF0, 0x2090, 0x22B0, 0x2560, 0x2840, 0x2BB0, 0x2EF0, 0x3220, + 0x35F0, 0x3A70, 0x3F70, 0x4590, 0x4C50, 0x53B0, 0x5C20, 0x6410, 0x6CB0, 0x74F0, 0x7C70, 0x7F10, 0x7EA0, 0x7EC0, 0x7E80, 0x7F10, + 0x7F20, 0x7F00, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7E30, 0x7150, 0x6500, + 0x5800, 0x4A90, 0x3CF0, 0x2EA0, 0x2190, 0x1370, 0x07A0, 0xFB10, 0xF250, 0xEB00, 0xE4D0, 0xDFB0, 0xDB50, 0xD6B0, 0xD220, 0xCC80, + 0xC5D0, 0xBFC0, 0xB990, 0xB390, 0xAD40, 0xA7C0, 0xA300, 0x9EC0, 0x9C60, 0x9AB0, 0x9B10, 0x9C60, 0x9DC0, 0x9F00, 0x9F30, 0x9F80, + 0x9FB0, 0x9F10, 0x9DD0, 0x9B60, 0x98F0, 0x9520, 0x9040, 0x8C20, 0x8910, 0x8720, 0x8630, 0x85A0, 0x8550, 0x8530, 0x8510, 0x8500, + 0x84F0, 0x8500, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, + 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x8500, 0x8500, 0x8500, 0x8510, 0x8510, 0x8520, 0x8530, 0x8550, 0x8560, 0x8580, 0x85B0, 0x8610, + 0x86A0, 0x8790, 0x88D0, 0x8AC0, 0x8C30, 0x8D20, 0x8D40, 0x8C70, 0x8B30, 0x8980, 0x8810, 0x86E0, 0x8600, 0x8580, 0x8540, 0x8510, + 0x84F0, 0x84E0, 0x84E0, 0x84D0, 0x84C0, 0x84C0, 0x84A0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, + 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84D0, 0x84D0, 0x84E0, 0x84F0, 0x8500, 0x8510, 0x8520, 0x8530, 0x8540, + 0x8550, 0x8570, 0x8590, 0x85B0, 0x85D0, 0x85E0, 0x85E0, 0x85E0, 0x85E0, 0x8600, 0x85E0, 0x85D0, 0x85C0, 0x85B0, 0x8590, 0x8570, + 0x8560, 0x8550, 0x8540, 0x8530, 0x8530, 0x8530, 0x8520, 0x8550, 0x8520, 0x8520, 0x8520, 0x8510, 0x8510, 0x8510, 0x8510, 0x8510, + 0x8520, 0x8520, 0x8520, 0x8530, 0x8530, 0x8550, 0x8560, 0x8580, 0x85B0, 0x85F0, 0x8640, 0x86C0, 0x8780, 0x88F0, 0x9320, 0x96C0, + 0x9A90, 0x9EB0, 0xA3C0, 0xA970, 0xAF20, 0xB4B0, 0xBA70, 0xBFB0, 0xC480, 0xC940, 0xCEC0, 0xD390, 0xD910, 0xDDE0, 0xE310, 0xE8F0, + 0xEE30, 0xF300, 0xF680, 0xF990, 0xFC50, 0xFF30, 0x0270, 0x0580, 0x08E0, 0x0BB0, 0x0EB0, 0x11F0, 0x13E0, 0x15F0, 0x1950, 0x1C30, + 0x1F30, 0x2190, 0x2490, 0x27F0, 0x2AE0, 0x2DD0, 0x3210, 0x3530, 0x3970, 0x3C50, 0x3FB0, 0x41F0, 0x4370, 0x4690, 0x4870, 0x4B70, + 0x4E00, 0x4FD0, 0x5280, 0x5410, 0x5610, 0x5780, 0x57C0, 0x5860, 0x5840, 0x5830, 0x58C0, 0x5890, 0x5860, 0x5780, 0x5660, 0x5550, + 0x53B0, 0x52C0, 0x51E0, 0x5140, 0x5130, 0x5090, 0x50E0, 0x5160, 0x51C0, 0x53D0, 0x56B0, 0x5B20, 0x5FC0, 0x6490, 0x6A30, 0x6FA0, + 0x75E0, 0x7B10, 0x7EF0, 0x7F00, 0x7EC0, 0x7ED0, 0x7EF0, 0x7F60, 0x7ED0, 0x7EB0, 0x7EE0, 0x7EE0, 0x7ED0, 0x7F10, 0x7E70, 0x7EC0, + 0x7ED0, 0x7F10, 0x7EE0, 0x7E90, 0x7F00, 0x7EA0, 0x75C0, 0x6D90, 0x64C0, 0x5C00, 0x5410, 0x4C50, 0x45E0, 0x4040, 0x3C80, 0x3AD0, + 0x3B90, 0x3EC0, 0x4380, 0x4840, 0x4C90, 0x5110, 0x5620, 0x59E0, 0x5C80, 0x5DB0, 0x5D20, 0x5BA0, 0x5840, 0x5330, 0x4C20, 0x44E0, + 0x3DF0, 0x37B0, 0x3320, 0x3240, 0x3510, 0x3C30, 0x4640, 0x5240, 0x5FB0, 0x6C20, 0x77C0, 0x7E80, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, + 0x7F00, 0x7F20, 0x7EE0, 0x7E90, 0x7E30, 0x7B20, 0x7990, 0x7AE0, 0x7D60, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7ED0, 0x7F50, 0x7F00, + 0x7F00, 0x7F10, 0x7F00, 0x7F60, 0x7F00, 0x7F10, 0x7F10, 0x7EF0, 0x7F80, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F90, 0x7F20, 0x7F00, + 0x7D50, 0x7400, 0x6860, 0x5AC0, 0x4C50, 0x4170, 0x39C0, 0x3670, 0x3690, 0x3820, 0x3A50, 0x3A70, 0x3760, 0x31C0, 0x2850, 0x1D90, + 0x1070, 0x0240, 0xF5D0, 0xE9C0, 0xE1D0, 0xDC90, 0xDAA0, 0xDBE0, 0xDE90, 0xE2F0, 0xE8A0, 0xEEA0, 0xF610, 0xFD10, 0x0460, 0x0A20, + 0x0E40, 0x01E0, 0xF810, 0xEB50, 0xDA00, 0xC400, 0xA930, 0x8C50, 0x8500, 0x84A0, 0x8480, 0x8460, 0x8450, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8440, 0x8450, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, 0x8470, 0x8460, 0x8470, 0x8450, + 0x8440, 0x8430, 0x8440, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, 0x8430, + 0x8470, 0x8440, 0x8440, 0x8450, 0x8450, 0x8460, 0x8460, 0x8450, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, + 0x8490, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84D0, 0x84E0, 0x84F0, 0x8510, 0x8530, 0x8550, 0x8580, 0x85B0, 0x85F0, 0x8630, 0x86C0, + 0x87B0, 0x8910, 0x8B50, 0x8DF0, 0x9090, 0x9290, 0x9580, 0x9870, 0x9B50, 0x9F70, 0xA2D0, 0xA650, 0xA9E0, 0xAC90, 0xB090, 0xB430, + 0xB860, 0xBC80, 0xBFA0, 0xC260, 0xC490, 0xC630, 0xC900, 0xCBC0, 0xCFD0, 0xD260, 0xD480, 0xD620, 0xD7C0, 0xDA20, 0xDBE0, 0xDDD0, + 0xDFF0, 0xE130, 0xE360, 0xE590, 0xE850, 0xEB60, 0xEE10, 0xF0A0, 0xF200, 0xF2F0, 0xF330, 0xF3A0, 0xF500, 0xF690, 0xF7F0, 0xF940, + 0xF9A0, 0xFA10, 0xFAA0, 0xFA70, 0xFA40, 0xFAB0, 0xFB90, 0xFB20, 0xFA70, 0xFB10, 0xFBC0, 0xFCE0, 0xFE90, 0xFF90, 0x00C0, 0x00C0, + 0x00B0, 0x00A0, 0x0060, 0x00F0, 0x00C0, 0x00D0, 0x0160, 0x0040, 0x0010, 0xFF80, 0xFE30, 0xFCD0, 0xFAA0, 0xF8A0, 0xF610, 0xF350, + 0xF0E0, 0xEED0, 0xED70, 0xEB80, 0xE9E0, 0xE850, 0xE710, 0xE550, 0xE350, 0xE0C0, 0xDF80, 0xDCE0, 0xDB40, 0xD980, 0xD860, 0xD7E0, + 0xD690, 0xD550, 0xD380, 0xD120, 0xCF40, 0xCDB0, 0xCC60, 0xCA90, 0xC8B0, 0xC6B0, 0xC420, 0xC280, 0xC0E0, 0xBEE0, 0xBE10, 0xBCC0, + 0xBB90, 0xB9B0, 0xB870, 0xB710, 0xB5B0, 0xB560, 0xB5A0, 0xB610, 0xB6C0, 0xB7D0, 0xB8F0, 0xBB00, 0xBDC0, 0xC1B0, 0xC580, 0xC9D0, + 0xCE80, 0xD310, 0xD890, 0xDDA0, 0xE270, 0xE850, 0xEE40, 0xF4A0, 0xFAF0, 0x00A0, 0x05C0, 0x0AB0, 0x0FD0, 0x14C0, 0x1960, 0x1D50, + 0x2170, 0x2570, 0x2890, 0x2B90, 0x2E40, 0x3060, 0x32D0, 0x3470, 0x35B0, 0x3860, 0x39B0, 0x3BA0, 0x3C80, 0x3C50, 0x3D10, 0x3C70, + 0x3C60, 0x3C80, 0x3BB0, 0x3C60, 0x3D00, 0x3DC0, 0x3DC0, 0x3CD0, 0x3C70, 0x3C00, 0x3C60, 0x3DD0, 0x4080, 0x4520, 0x4980, 0x5010, + 0x57E0, 0x5FA0, 0x6880, 0x7110, 0x7990, 0x7E70, 0x7F10, 0x7F30, 0x7F00, 0x7F70, 0x7EF0, 0x7F20, 0x7F00, 0x7F00, 0x7F90, 0x7F10, + 0x7F20, 0x7F00, 0x7EF0, 0x7F30, 0x7F00, 0x7EC0, 0x7ED0, 0x7EB0, 0x7C90, 0x7A60, 0x7980, 0x7990, 0x7B00, 0x7D20, 0x7ED0, 0x7F10, + 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F40, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F20, + 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F40, 0x7F40, 0x7F30, 0x7F40, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, + 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, + 0x7F30, 0x7F20, 0x7EF0, 0x7F50, 0x7730, 0x67E0, 0x5840, 0x4850, 0x3840, 0x2860, 0x1A90, 0x0DB0, 0x03A0, 0xFB90, 0xF610, 0xF2A0, + 0xF010, 0xEE00, 0xEC50, 0xEAD0, 0xE950, 0xE840, 0xE6F0, 0xE620, 0xE540, 0xE4D0, 0xE400, 0xE450, 0xE520, 0xE650, 0xE7B0, 0xE830, + 0xE920, 0xEA00, 0xEA90, 0xEB50, 0xECE0, 0xEF10, 0xF0C0, 0xF220, 0xF3A0, 0xF4E0, 0xF680, 0xF7E0, 0xF9D0, 0xFBD0, 0xFD00, 0xFE80, + 0x0000, 0x01F0, 0x03E0, 0x0590, 0x0690, 0x07E0, 0x08B0, 0x09A0, 0x0B10, 0x0C70, 0x0DD0, 0x0F60, 0x1050, 0x1110, 0x11C0, 0x1200, + 0x12B0, 0x12B0, 0x1340, 0x1370, 0x1390, 0x12C0, 0x11C0, 0x1110, 0x1020, 0x0F20, 0x0E20, 0x0C90, 0x0B00, 0x08C0, 0x07C0, 0x0720, + 0x06E0, 0x05C0, 0x04C0, 0x0320, 0x01B0, 0x0050, 0xFF80, 0xFF00, 0xFEB0, 0xFE50, 0xFD60, 0xFD00, 0xFC40, 0xFC40, 0xFBB0, 0xFB20, + 0xFA40, 0xF950, 0xF830, 0xF740, 0xF660, 0xF600, 0xF5D0, 0xF5C0, 0xF510, 0xF430, 0xF390, 0xF360, 0xF2C0, 0xF1C0, 0xF0D0, 0xEFE0, + 0xEEF0, 0xEE90, 0xEE90, 0xEE40, 0xEDA0, 0xED50, 0xEC30, 0xEAC0, 0xE900, 0xE5B0, 0xE2E0, 0xDFF0, 0xDCB0, 0xD880, 0xD4C0, 0xD1B0, + 0xCDF0, 0xCB10, 0xC760, 0xC420, 0xC0F0, 0xBD30, 0xBA70, 0xB740, 0xB5C0, 0xB340, 0xB160, 0xB030, 0xAF50, 0xAE30, 0xAD10, 0xABF0, + 0xAB10, 0xAA90, 0xA960, 0xA850, 0xA6E0, 0xA6C0, 0xA620, 0xA540, 0xA4B0, 0xA460, 0xA450, 0xA4D0, 0xA530, 0xA620, 0xA670, 0xA690, + 0xA6A0, 0xA740, 0xA7B0, 0xA7D0, 0xA8A0, 0xA920, 0xAA20, 0xAB70, 0xACE0, 0xAE30, 0xAF70, 0xB0C0, 0xB1B0, 0xB2D0, 0xB4C0, 0xB5A0, + 0xB690, 0xB880, 0xBA40, 0xBC70, 0xBE50, 0xBFB0, 0xC1F0, 0xC380, 0xC4E0, 0xC690, 0xC7E0, 0xC980, 0xCB20, 0xD360, 0xD530, 0xD610, + 0xD7E0, 0xD910, 0xDB10, 0xDC30, 0xDC60, 0xDD30, 0xDD90, 0xDE40, 0xDEF0, 0xDFB0, 0xE080, 0xE160, 0xE260, 0xE2C0, 0xE350, 0xE4A0, + 0xE560, 0xE670, 0xE750, 0xE7A0, 0xE8D0, 0xEA30, 0xEBC0, 0xED60, 0xEF50, 0xF170, 0xF320, 0xF440, 0xF5D0, 0xF760, 0xF9C0, 0xFC60, + 0xFF10, 0x0180, 0x0360, 0x0590, 0x06D0, 0x08C0, 0x0B10, 0x0D30, 0x0FE0, 0x11D0, 0x12D0, 0x1560, 0x16A0, 0x1840, 0x1A30, 0x1BB0, + 0x1D80, 0x1E80, 0x1FD0, 0x20E0, 0x2220, 0x2450, 0x2580, 0x26A0, 0x2740, 0x27B0, 0x28B0, 0x2940, 0x2A90, 0x2BB0, 0x2BE0, 0x2CA0, + 0x2D10, 0x2E70, 0x2FE0, 0x3160, 0x3370, 0x3470, 0x35C0, 0x3610, 0x36F0, 0x37C0, 0x3A40, 0x3C90, 0x3F50, 0x41A0, 0x4510, 0x4830, + 0x4AA0, 0x4D00, 0x4F40, 0x5180, 0x5350, 0x5630, 0x5870, 0x5B60, 0x5EC0, 0x6200, 0x6430, 0x66C0, 0x6850, 0x6A10, 0x6B40, 0x6C60, + 0x6E50, 0x6FB0, 0x71E0, 0x7360, 0x74B0, 0x7640, 0x76E0, 0x7810, 0x7980, 0x79E0, 0x79E0, 0x7940, 0x7930, 0x7940, 0x7990, 0x7A70, + 0x7A60, 0x7AA0, 0x7A40, 0x7930, 0x7900, 0x7840, 0x7830, 0x77E0, 0x7700, 0x7680, 0x7590, 0x7470, 0x7400, 0x7340, 0x7330, 0x7280, + 0x71A0, 0x7040, 0x6EC0, 0x6EA0, 0x6EC0, 0x6F90, 0x7060, 0x7100, 0x7240, 0x7310, 0x74B0, 0x7560, 0x75E0, 0x76D0, 0x7880, 0x7AC0, + 0x7C60, 0x7D90, 0x7E30, 0x7E60, 0x7EC0, 0x7ED0, 0x7F70, 0x7F10, 0x7EB0, 0x7EE0, 0x7ED0, 0x7F10, 0x7F10, 0x7E70, 0x7ED0, 0x7ED0, + 0x7F30, 0x7F20, 0x7EA0, 0x7ED0, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7EC0, 0x7F40, 0x7F30, 0x7F20, + 0x7F20, 0x7EF0, 0x7F50, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F30, 0x7E60, 0x7B10, 0x76B0, 0x7260, 0x6D50, 0x6850, 0x63D0, 0x6100, + 0x5F50, 0x5EB0, 0x5EF0, 0x5FD0, 0x6210, 0x6470, 0x6770, 0x6BD0, 0x7000, 0x7500, 0x79A0, 0x7CC0, 0x7EA0, 0x7EA0, 0x7F10, 0x7F10, + 0x7F20, 0x7EE0, 0x7EC0, 0x7F10, 0x7F00, 0x7F30, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7EE0, 0x7F30, 0x7F00, 0x7EF0, + 0x7F10, 0x7F10, 0x7F60, 0x7F00, 0x7F10, 0x7F10, 0x7EF0, 0x7F90, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F90, 0x7F20, 0x7F00, 0x7EF0, + 0x7F00, 0x7F60, 0x7F10, 0x7ED0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7EB0, 0x7ED0, 0x7EF0, 0x7F30, 0x7F20, 0x7EC0, 0x7EB0, 0x7EF0, + 0x7EE0, 0x7EF0, 0x7E90, 0x7EB0, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F20, 0x7F00, + 0x7EF0, 0x7F10, 0x7F60, 0x7F20, 0x7F20, 0x7F20, 0x7F00, 0x7A40, 0x7190, 0x6860, 0x5F40, 0x55D0, 0x4C80, 0x4270, 0x3A90, 0x33B0, + 0x2CE0, 0x27C0, 0x22E0, 0x1DB0, 0x19B0, 0x15A0, 0x1190, 0x0F00, 0x0CD0, 0x0BF0, 0x0B70, 0x0BC0, 0x0C40, 0x0D30, 0x0F10, 0x1160, + 0x1440, 0x1810, 0x1B30, 0x2020, 0x24F0, 0x2990, 0x2F90, 0x3500, 0x3B70, 0x4120, 0x4700, 0x4E00, 0x5440, 0x5A10, 0x5F60, 0x63C0, + 0x6850, 0x6CC0, 0x7040, 0x7350, 0x7590, 0x77E0, 0x79C0, 0x7B90, 0x7CF0, 0x7E20, 0x7ED0, 0x7EB0, 0x7F60, 0x7EF0, 0x7F10, 0x7F00, + 0x7F00, 0x7F70, 0x7F10, 0x7F10, 0x7EF0, 0x7EF0, 0x7F60, 0x7EF0, 0x7EB0, 0x7EA0, 0x7E60, 0x7E30, 0x7E10, 0x7E10, 0x7EA0, 0x7EE0, + 0x7F10, 0x7F10, 0x7E70, 0x7EE0, 0x7F10, 0x7F00, 0x7EF0, 0x7E90, 0x7E90, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7F10, + 0x7F10, 0x7EE0, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F40, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, 0x7F10, 0x7F00, + 0x7EF0, 0x7650, 0x6980, 0x5C60, 0x4F40, 0x41B0, 0x3490, 0x28B0, 0x1C80, 0x1110, 0x06F0, 0xFE60, 0xF650, 0xEF10, 0xE880, 0xE280, + 0xDD10, 0xD850, 0xD310, 0xCFA0, 0xCD90, 0xCD20, 0xCEC0, 0xD200, 0xD6B0, 0xDC80, 0xE2A0, 0xEB30, 0xF260, 0xFAB0, 0x03C0, 0x0DF0, + 0x1900, 0x24E0, 0x3210, 0x3E40, 0x49F0, 0x5540, 0x6130, 0x6E00, 0x7A60, 0x7EF0, 0x7F20, 0x7F00, 0x7F10, 0x7F20, 0x7F20, 0x7F20, + 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7950, 0x5B30, + 0x3E20, 0x20E0, 0x03F0, 0xE6F0, 0xCA90, 0xAEC0, 0x9210, 0x8660, 0x84F0, 0x84C0, 0x84A0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8450, + 0x8450, 0x8440, 0x8430, 0x8440, 0x8440, 0x8450, 0x8460, 0x8470, 0x8480, 0x8490, 0x84B0, 0x84E0, 0x8530, 0x85D0, 0x86C0, 0x8740, + 0x86B0, 0x85C0, 0x8530, 0x84F0, 0x84E0, 0x84D0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84D0, 0x8510, + 0x8520, 0x85C0, 0x87E0, 0x8FB0, 0x9930, 0xA070, 0xA4A0, 0xA630, 0xA440, 0x9F50, 0x9760, 0x8EC0, 0x8840, 0x85F0, 0x8540, 0x8500, + 0x84F0, 0x84E0, 0x84E0, 0x84D0, 0x84D0, 0x84C0, 0x84C0, 0x84B0, 0x84D0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8470, + 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8430, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8440, 0x8430, 0x8440, 0x8450, 0x8460, 0x8470, 0x8480, 0x84A0, 0x84E0, 0x8680, 0x9AA0, 0xAFB0, 0xBB90, 0xBF80, 0xBE00, 0xB9A0, + 0xB400, 0xADD0, 0xA6B0, 0x9F60, 0x9650, 0x8D30, 0x8760, 0x8550, 0x84E0, 0x84D0, 0x84B0, 0x8490, 0x8480, 0x8410, 0x8470, 0x8460, + 0x8450, 0x8440, 0x8440, 0x8430, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, + 0x8430, 0x8440, 0x8440, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8410, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8420, 0x8460, 0x8460, 0x8460, 0x8470, 0x8450, 0x8450, 0x8420, 0x8440, + 0x8430, 0x8430, 0x8420, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8420, 0x8430, 0x8430, + 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, + 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8470, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84E0, 0x8500, 0x8550, 0x8650, + 0x8970, 0x92B0, 0x9E50, 0xA8B0, 0xB2C0, 0xBC10, 0xC5B0, 0xD070, 0xDA60, 0xE520, 0xF080, 0xFCE0, 0x0980, 0x1710, 0x25E0, 0x3560, + 0x45A0, 0x5380, 0x5ED0, 0x66A0, 0x6960, 0x66C0, 0x5C90, 0x4AB0, 0x3240, 0x1140, 0xEDB0, 0xC7D0, 0xA1F0, 0x87C0, 0x84E0, 0x84B0, + 0x8450, 0x8490, 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, + 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8480, 0x84A0, 0x8490, 0x8490, + 0x8490, 0x8490, 0x8490, 0x84A0, 0x84C0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, + 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84D0, 0x84E0, 0x8500, 0x8530, 0x8590, 0x8650, 0x8780, 0x8920, 0x8AB0, 0x8C90, 0x8E50, 0x90E0, + 0x9410, 0x9680, 0x98C0, 0x9A70, 0x9A80, 0x9930, 0x96E0, 0x9370, 0x8FC0, 0x8C30, 0x8990, 0x87A0, 0x8690, 0x8620, 0x8660, 0x8690, + 0x87F0, 0x8B10, 0x9190, 0x9890, 0x9D10, 0x9E40, 0x9750, 0x99A0, 0x9D40, 0xA1F0, 0xA730, 0xABE0, 0xAF90, 0xB2F0, 0xB520, 0xB870, + 0xBC80, 0xC2D0, 0xCAF0, 0xD4E0, 0xE1C0, 0xF000, 0xFE90, 0x0D70, 0x1A70, 0x2650, 0x2FC0, 0x3760, 0x3D90, 0x42E0, 0x47F0, 0x4CC0, + 0x50C0, 0x53B0, 0x5500, 0x54D0, 0x5210, 0x4E10, 0x4860, 0x40F0, 0x3950, 0x31A0, 0x2A30, 0x22E0, 0x1B30, 0x16A0, 0x1320, 0x1190, + 0x1210, 0x1400, 0x1840, 0x1CD0, 0x2210, 0x2960, 0x3010, 0x3770, 0x3F40, 0x4640, 0x4D90, 0x5400, 0x5970, 0x5E40, 0x62E0, 0x6820, + 0x6C80, 0x71C0, 0x7680, 0x7A60, 0x7DA0, 0x7ED0, 0x7F30, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7F50, 0x7F20, 0x7F20, 0x7F10, 0x7F10, + 0x7F60, 0x7F20, 0x7F40, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7EF0, 0x7F10, 0x7EF0, 0x7F80, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F30, + 0x7EE0, 0x7EC0, 0x7F10, 0x7F00, 0x7F40, 0x7ED0, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7EC0, 0x7F10, 0x7F10, 0x7EF0, 0x7F00, + 0x7EC0, 0x7F20, 0x7F00, 0x7F20, 0x7F20, 0x7EC0, 0x7F10, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F60, 0x7F00, 0x7F20, 0x7F40, 0x7F00, + 0x7F30, 0x7EE0, 0x7EF0, 0x7F30, 0x7F10, 0x7F70, 0x7EF0, 0x7F00, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7ED0, 0x7ED0, 0x7EB0, 0x7F60, + 0x7F10, 0x7EB0, 0x7EB0, 0x7EC0, 0x7EF0, 0x7F10, 0x7EA0, 0x7EE0, 0x7ED0, 0x7F20, 0x7F20, 0x7E90, 0x7ED0, 0x7F00, 0x7EE0, 0x7EF0, + 0x7EC0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7F00, 0x7F20, 0x7F20, 0x7EF0, 0x7F10, 0x7F10, + 0x7F60, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F30, 0x7F20, 0x7EF0, 0x7F10, 0x7F10, 0x7F60, 0x7EF0, 0x7F10, 0x7F00, 0x7F20, 0x7F80, + 0x7ED0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F30, 0x7EE0, 0x7EC0, 0x7EF0, 0x7F10, 0x7F20, 0x7EE0, 0x7E90, 0x7F10, 0x7EF0, 0x7F40, 0x7F10, + 0x7EA0, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7F20, 0x7F20, 0x7F10, 0x7800, 0x6E70, 0x6520, 0x5B50, 0x52B0, 0x4880, + 0x3BF0, 0x2DB0, 0x1CA0, 0x0A40, 0xF510, 0xDD80, 0xC520, 0xAC00, 0x93D0, 0x86E0, 0x8510, 0x84D0, 0x84C0, 0x84B0, 0x84A0, 0x8490, + 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, + 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, + 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84E0, 0x84B0, 0x84B0, 0x84D0, 0x84C0, 0x84D0, 0x84F0, + 0x8500, 0x8550, 0x8640, 0x8BA0, 0xA1F0, 0xC010, 0xE500, 0x10B0, 0x4530, 0x7520, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F20, 0x7F30, + 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x58A0, 0xDF50, 0x8790, 0x8490, 0x8470, 0x8460, 0x8470, 0x8470, 0x8480, 0x84A0, 0x84D0, + 0x8500, 0x8520, 0x8510, 0x84E0, 0x84B0, 0x8490, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x84A0, 0x84F0, + 0x9330, 0xD740, 0x10F0, 0x3AA0, 0x4CC0, 0x44B0, 0x2660, 0xF820, 0xC090, 0x8B90, 0x84C0, 0x8490, 0x8470, 0x8450, 0x8450, 0x8440, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8460, 0x8470, 0x8470, 0x8490, 0x84B0, 0x84E0, 0x8580, 0x8A60, + 0xA360, 0xBAC0, 0xD370, 0xECB0, 0x0570, 0x1C70, 0x2EC0, 0x3B10, 0x4190, 0x4260, 0x4040, 0x3CF0, 0x3A80, 0x3A60, 0x3D40, 0x4250, + 0x4AB0, 0x54A0, 0x60A0, 0x6AE0, 0x7270, 0x7650, 0x75B0, 0x6FE0, 0x6420, 0x53F0, 0x4130, 0x2EA0, 0x1FF0, 0x1530, 0x0DB0, 0x0920, + 0x05D0, 0x0400, 0x04B0, 0x07B0, 0x0EC0, 0x1830, 0x23E0, 0x2FA0, 0x3AF0, 0x44B0, 0x4D60, 0x5500, 0x5C00, 0x6150, 0x6330, 0x60A0, + 0x57C0, 0x4890, 0x3480, 0x1EB0, 0x0A30, 0xFA40, 0xF070, 0xEDB0, 0xF030, 0xF630, 0xFDB0, 0x05A0, 0x0CB0, 0x12B0, 0x15E0, 0x1660, + 0x1330, 0x0D00, 0x0470, 0xFAE0, 0xF050, 0xE5D0, 0xDAC0, 0xCF20, 0xC170, 0xB400, 0xA700, 0x9A90, 0x8FD0, 0x8980, 0x86B0, 0x85B0, + 0x8540, 0x8510, 0x8500, 0x8500, 0x8500, 0x8510, 0x8530, 0x8560, 0x85F0, 0x8710, 0x89F0, 0x8EC0, 0x9230, 0x93E0, 0x9380, 0x9190, + 0x8ED0, 0x8C20, 0x8A20, 0x8860, 0x8760, 0x86C0, 0x8660, 0x8640, 0x8650, 0x8690, 0x8700, 0x87C0, 0x8920, 0x8C40, 0x9220, 0x9B50, + 0xA600, 0xB330, 0xC140, 0xD000, 0xE030, 0xF200, 0x0460, 0x1750, 0x2AD0, 0x3EE0, 0x5270, 0x6550, 0x75D0, 0x7F20, 0x7ED0, 0x7EB0, + 0x7F30, 0x7F00, 0x7F10, 0x7EB0, 0x7EA0, 0x7F00, 0x7EF0, 0x7F20, 0x7EC0, 0x7E90, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F00, 0x7F20, + 0x7F00, 0x7F00, 0x7F00, 0x7F00, 0x7F30, 0x7F00, 0x7F40, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7F80, 0x7F10, + 0x7F20, 0x7F00, 0x7F10, 0x7F80, 0x7F00, 0x7F10, 0x7EF0, 0x7EF0, 0x7F60, 0x7EF0, 0x7ED0, 0x7EE0, 0x7EE0, 0x7F50, 0x7F10, 0x7EB0, + 0x7EE0, 0x7ED0, 0x7F10, 0x7F00, 0x7E90, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EA0, 0x78A0, 0x70D0, 0x68B0, 0x60E0, 0x5980, 0x5390, + 0x4F70, 0x4CA0, 0x4C20, 0x4C80, 0x4D30, 0x4EE0, 0x50D0, 0x5490, 0x5880, 0x5CC0, 0x60B0, 0x6390, 0x6660, 0x67A0, 0x68F0, 0x6A30, + 0x6AF0, 0x6C50, 0x6D90, 0x6E80, 0x7020, 0x7140, 0x7230, 0x7330, 0x73D0, 0x7510, 0x75B0, 0x7740, 0x7890, 0x7A30, 0x7C00, 0x7D20, + 0x7DD0, 0x7E40, 0x7ED0, 0x7E90, 0x7E30, 0x7EC0, 0x7EF0, 0x7F10, 0x7F00, 0x7EC0, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7EC0, 0x7F10, + 0x7F00, 0x7EF0, 0x7F10, 0x7EA0, 0x7F20, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F80, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F60, 0x7EE0, + 0x7EF0, 0x7F20, 0x7F00, 0x7F60, 0x7F10, 0x7F20, 0x7F00, 0x7EF0, 0x7F70, 0x7F00, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F30, 0x7F10, 0x7F00, + 0x7F00, 0x7EF0, 0x7F30, 0x7F00, 0x7720, 0x6890, 0x5950, 0x4970, 0x3C60, 0x3050, 0x2630, 0x12C0, 0x13B0, 0x1530, 0x1740, 0x19A0, + 0x1C50, 0x1FE0, 0x2360, 0x2690, 0x2A90, 0x2D90, 0x30A0, 0x3260, 0x3360, 0x34D0, 0x34B0, 0x34E0, 0x3640, 0x39F0, 0x4030, 0x46C0, + 0x4DC0, 0x5380, 0x57E0, 0x5B80, 0x5D90, 0x6060, 0x62A0, 0x63E0, 0x6490, 0x6400, 0x6230, 0x6040, 0x5C60, 0x5910, 0x5500, 0x50E0, + 0x4BE0, 0x4650, 0x4190, 0x3C20, 0x3640, 0x30D0, 0x2B80, 0x2730, 0x2340, 0x20A0, 0x1F40, 0x1D50, 0x1D90, 0x1D60, 0x1CA0, 0x1C50, + 0x1BF0, 0x1C00, 0x1C00, 0x1BF0, 0x1CB0, 0x1BF0, 0x1BC0, 0x1A90, 0x1930, 0x1820, 0x1680, 0x1580, 0x1440, 0x12A0, 0x1150, 0x0F30, + 0x0E20, 0x0D40, 0x0BE0, 0x0BB0, 0x0A10, 0x0950, 0x08D0, 0x07D0, 0x07C0, 0x0710, 0x0790, 0x06B0, 0x0640, 0x0710, 0x0800, 0x0940, + 0x0AE0, 0x0C30, 0x0DD0, 0x0EC0, 0x1050, 0x1270, 0x1500, 0x1870, 0x1AE0, 0x1E10, 0x2150, 0x2430, 0x27A0, 0x2AC0, 0x2EF0, 0x33B0, + 0x3780, 0x3BC0, 0x3FF0, 0x43F0, 0x48E0, 0x4DE0, 0x52D0, 0x5730, 0x5BF0, 0x6040, 0x6480, 0x6920, 0x6D00, 0x7090, 0x7430, 0x7760, + 0x7AC0, 0x7D30, 0x7E70, 0x7EC0, 0x7E90, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, + 0x7F10, 0x7F20, 0x7F40, 0x7F00, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F60, 0x7EF0, 0x7F10, 0x7F20, 0x7EF0, 0x7F90, 0x7F10, + 0x7F20, 0x7F00, 0x7EF0, 0x7F70, 0x7F00, 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, 0x7F10, 0x7EB0, 0x7EE0, 0x7EE0, 0x7ED0, 0x7F20, 0x7EC0, + 0x7ED0, 0x7EB0, 0x7F00, 0x7F00, 0x7E90, 0x7F00, 0x7F20, 0x7F10, 0x7F20, 0x7EC0, 0x7EF0, 0x7F10, 0x7F00, 0x7F00, 0x7EC0, 0x7F30, + 0x7F00, 0x7F00, 0x7EF0, 0x7F00, 0x7F40, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F50, 0x7EE0, + 0x7A60, 0x7490, 0x6DF0, 0x6840, 0x62C0, 0x5E10, 0x5AB0, 0x57E0, 0x5570, 0x5410, 0x5360, 0x53D0, 0x5390, 0x52F0, 0x51F0, 0x5010, + 0x4EB0, 0x4CB0, 0x4AF0, 0x49C0, 0x4870, 0x47D0, 0x4700, 0x45C0, 0x4600, 0x45C0, 0x46F0, 0x4820, 0x49A0, 0x4B90, 0x4DA0, 0x5020, + 0x52A0, 0x53D0, 0x55E0, 0x5760, 0x58E0, 0x5990, 0x5B00, 0x5D00, 0x5E00, 0x5E90, 0x5EE0, 0x5EE0, 0x5ED0, 0x5E20, 0x5D20, 0x5C40, + 0x5A90, 0x59E0, 0x58A0, 0x5890, 0x59D0, 0x5CB0, 0x5FE0, 0x6370, 0x6670, 0x6960, 0x6AC0, 0x6BB0, 0x6B60, 0x69F0, 0x6910, 0x6730, + 0x6720, 0x66D0, 0x66F0, 0x67B0, 0x6770, 0x6780, 0x6690, 0x6580, 0x64A0, 0x6280, 0x6180, 0x6000, 0x5D60, 0x5B90, 0x5910, 0x5670, + 0x5280, 0x4EE0, 0x4BA0, 0x4880, 0x45B0, 0x42A0, 0x3FC0, 0x3D50, 0x3A80, 0x37B0, 0x3510, 0x31D0, 0x2F30, 0x2C40, 0x2920, 0x2630, + 0x2390, 0x2230, 0x2140, 0x2230, 0x24A0, 0x27F0, 0x2C90, 0x30B0, 0x33A0, 0x3590, 0x36C0, 0x37B0, 0x3840, 0x3900, 0x38F0, 0x3880, + 0x3870, 0x3840, 0x38B0, 0x3990, 0x3AE0, 0x3CE0, 0x3E50, 0x3F30, 0x3ED0, 0x3D70, 0x3BE0, 0x3A60, 0x3A30, 0x3AF0, 0x3CC0, 0x4070, + 0x45E0, 0x4CB0, 0x5560, 0x5EC0, 0x6910, 0x72B0, 0x7B20, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F50, 0x7F30, 0x79E0, 0x6D60, 0x6040, + 0x5370, 0x4AA0, 0x4480, 0x42B0, 0x4490, 0x4A20, 0x5240, 0x5AD0, 0x63B0, 0x6CC0, 0x7350, 0x7910, 0x7DA0, 0x7F10, 0x7F10, 0x7F30, + 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, + 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7B40, 0x6510, 0x4E50, 0x36A0, 0x1EF0, 0x07F0, 0xF5B0, 0xE6D0, + 0xDB10, 0xD2F0, 0xCDC0, 0xCBA0, 0xCCD0, 0xD090, 0xD850, 0xE250, 0xEE20, 0xFAF0, 0x07D0, 0x1510, 0x20D0, 0x2C40, 0x35C0, 0x3ED0, + 0x46A0, 0x4DA0, 0x5560, 0x5CB0, 0x6290, 0x67B0, 0x6BC0, 0x6E10, 0x6EB0, 0x6D20, 0x6940, 0x6410, 0x5E00, 0x56C0, 0x5010, 0x4A00, + 0x44D0, 0x3F00, 0x3910, 0x32F0, 0x2C00, 0x23C0, 0x1B30, 0x1170, 0x0730, 0xFD70, 0xF290, 0xE940, 0xE100, 0xD9D0, 0xD3A0, 0xCF20, + 0xCC50, 0xCA10, 0xC8C0, 0xC7B0, 0xC780, 0xC8B0, 0xCB10, 0xCE80, 0xD3B0, 0xDA00, 0xE070, 0xE6B0, 0xEBC0, 0xEE30, 0xEF60, 0xEED0, + 0xED60, 0xEAF0, 0xE870, 0xE4A0, 0xDFF0, 0xDCD0, 0xDBE0, 0xDBF0, 0xDF30, 0xE310, 0xE560, 0xE4B0, 0xDE20, 0xD150, 0xBB10, 0x9F60, + 0x87F0, 0x84E0, 0x84D0, 0x8490, 0x8470, 0x8470, 0x84A0, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, + 0x84A0, 0x84A0, 0x84B0, 0x84C0, 0x84D0, 0x8510, 0x8500, 0x8530, 0x85A0, 0x8630, 0x8730, 0x88D0, 0x8AE0, 0x8D50, 0x8F10, 0x8FC0, + 0x8FB0, 0x8E50, 0x8C30, 0x8A20, 0x8820, 0x86D0, 0x85E0, 0x8560, 0x8520, 0x8500, 0x84F0, 0x84D0, 0x84C0, 0x84C0, 0x84B0, 0x84A0, + 0x8490, 0x84C0, 0x8490, 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8490, 0x8470, 0x8460, 0x8460, 0x8460, + 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, + 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84C0, 0x84E0, 0x8500, 0x8550, 0x85E0, 0x8710, 0x89C0, 0x8E70, 0x9420, + 0x99B0, 0x9EF0, 0xA490, 0xA9B0, 0xAE10, 0xB120, 0xB270, 0xB2B0, 0xB0B0, 0xAD80, 0xA940, 0xA510, 0xA0C0, 0x9C30, 0x97C0, 0x9310, + 0x8E20, 0x8A70, 0x87E0, 0x8680, 0x85F0, 0x85A0, 0x8590, 0x8590, 0x85C0, 0x8620, 0x86E0, 0x8870, 0x8C10, 0x9250, 0x9930, 0xA190, + 0xAA40, 0xB300, 0xBB10, 0xC320, 0xC9A0, 0xCF80, 0xD380, 0xD6C0, 0xD990, 0xDBE0, 0xDEE0, 0xE080, 0xE190, 0xE1D0, 0xE120, 0xE040, + 0xDF90, 0xDEC0, 0xDE20, 0xDD30, 0xDC90, 0xDBB0, 0xDA60, 0xD950, 0xD990, 0xDA70, 0xDC10, 0xDD70, 0xDF70, 0xE130, 0xE4D0, 0xE810, + 0xECC0, 0xF180, 0xF630, 0xFB00, 0x00A0, 0x04C0, 0x09D0, 0x0E40, 0x1320, 0x1790, 0x1B10, 0x1E80, 0x20D0, 0x2310, 0x2530, 0x2760, + 0x2910, 0x2A50, 0x2B40, 0x2C10, 0x2BE0, 0x2BA0, 0x2AD0, 0x2990, 0x2850, 0x2660, 0x24F0, 0x23F0, 0x2320, 0x1EA0, 0x1D00, 0x1B90, + 0x1970, 0x1860, 0x1640, 0x1470, 0x1380, 0x1260, 0x11B0, 0x10F0, 0x0F50, 0x0EB0, 0x0DA0, 0x0CD0, 0x0B80, 0x0A30, 0x0A40, 0x0A10, + 0x0B50, 0x0CB0, 0x0EA0, 0x1170, 0x1360, 0x1750, 0x1B00, 0x1EA0, 0x2240, 0x24B0, 0x2840, 0x2A60, 0x2CB0, 0x2F00, 0x3050, 0x31B0, + 0x3130, 0x2FA0, 0x2F80, 0x2E90, 0x2E20, 0x2D80, 0x2C90, 0x2C10, 0x2B00, 0x2A00, 0x2990, 0x2A30, 0x2B90, 0x2C90, 0x2DB0, 0x2E20, + 0x2E90, 0x2F30, 0x30E0, 0x33E0, 0x3800, 0x3D10, 0x4260, 0x4800, 0x4D50, 0x5330, 0x5920, 0x5FC0, 0x65D0, 0x6C30, 0x71F0, 0x76F0, + 0x7C20, 0x7EE0, 0x7F70, 0x7EF0, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F60, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F70, 0x7ED0, 0x7EA0, 0x7EE0, + 0x7F10, 0x7F30, 0x7EB0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7EC0, 0x7F20, 0x7F00, 0x7F70, 0x7F10, 0x7EA0, 0x7EC0, 0x7ED0, + 0x7F30, 0x7F20, 0x7EA0, 0x7ED0, 0x7EE0, 0x7F20, 0x7F10, 0x7E90, 0x7EB0, 0x7F00, 0x7F10, 0x7F10, 0x7E90, 0x7F00, 0x7F00, 0x7F10, + 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F30, 0x7F20, 0x7F20, 0x7EF0, 0x7F10, 0x7F60, 0x7EF0, 0x7F30, 0x7F20, + 0x7F10, 0x7F50, 0x7EF0, 0x7F00, 0x7EF0, 0x7ED0, 0x7F10, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7F70, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F10, + 0x7F30, 0x7EE0, 0x7E90, 0x7F10, 0x7F20, 0x7EC0, 0x7910, 0x7130, 0x68E0, 0x60D0, 0x59B0, 0x5500, 0x5040, 0x4BF0, 0x4710, 0x4100, + 0x3A20, 0x3140, 0x27A0, 0x1C80, 0x1040, 0x0340, 0xF420, 0xE2E0, 0xD050, 0xBCC0, 0xA670, 0x9110, 0x8680, 0x84F0, 0x84C0, 0x8480, + 0x8490, 0x8480, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8450, + 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8460, 0x8470, 0x84A0, 0x8470, 0x84A0, 0x8470, 0x8470, 0x8480, 0x8470, 0x8480, + 0x84B0, 0x84B0, 0x8480, 0x8480, 0x8440, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8480, 0x8480, + 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8480, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, + 0x8490, 0x8480, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x8490, 0x8480, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x8430, + 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, + 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, + 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x84C0, 0x8490, + 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84D0, 0x84D0, 0x84E0, 0x84F0, 0x8510, + 0x8550, 0x8550, 0x85A0, 0x8620, 0x8710, 0x88A0, 0x8B30, 0x8EF0, 0x9390, 0x9820, 0x9C40, 0xA090, 0xA560, 0xA930, 0xACF0, 0xB150, + 0xB530, 0xB8C0, 0xBCE0, 0xC090, 0xC3E0, 0xC640, 0xC860, 0xCA80, 0xCC50, 0xCE90, 0xD160, 0xD320, 0xD530, 0xD6E0, 0xD8A0, 0xD9D0, + 0xDB80, 0xDD80, 0xDEC0, 0xE040, 0xE110, 0xE220, 0xE3B0, 0xE4D0, 0xE6A0, 0xE810, 0xE910, 0xE9E0, 0xEAB0, 0xEBE0, 0xED50, 0xEEF0, + 0xEFA0, 0xF050, 0xF050, 0xF100, 0xF1F0, 0xF2C0, 0xF3D0, 0xF500, 0xF690, 0xF710, 0xF7A0, 0xF7B0, 0xF890, 0xF990, 0xFB10, 0xFCB0, + 0xFE40, 0xFF50, 0xFFB0, 0xFFB0, 0x00A0, 0x0150, 0x0230, 0x02E0, 0x03E0, 0x0450, 0x04C0, 0x0520, 0x0550, 0x0550, 0x04E0, 0x04A0, + 0x04C0, 0x0500, 0x05F0, 0x0720, 0x0790, 0x0870, 0x0860, 0x0820, 0x0850, 0x0810, 0x0860, 0x08E0, 0x0900, 0x0930, 0x0960, 0x0960, + 0x0950, 0x09E0, 0x0AA0, 0x0B00, 0x0B10, 0x0AF0, 0x0AC0, 0x0AD0, 0x0AF0, 0x0AE0, 0x0B60, 0x0B90, 0x0BD0, 0x0C20, 0x0D40, 0x0E70, + 0x0EE0, 0x0F50, 0x0F50, 0x0F90, 0x0F90, 0x0F60, 0x1030, 0x1190, 0x1310, 0x13D0, 0x1460, 0x1500, 0x1680, 0x17F0, 0x1930, 0x1B00, + 0x1BC0, 0x1C10, 0x1C30, 0x1CE0, 0x1E40, 0x1FB0, 0x2130, 0x22C0, 0x23C0, 0x25B0, 0x2620, 0x2710, 0x2810, 0x2930, 0x2B20, 0x2C20, + 0x2DD0, 0x3000, 0x3210, 0x3450, 0x3660, 0x3940, 0x3AB0, 0x3BD0, 0x3D60, 0x3EE0, 0x4080, 0x4250, 0x43E0, 0x4640, 0x4790, 0x4930, + 0x4AE0, 0x4B40, 0x4D70, 0x4F60, 0x5110, 0x5320, 0x5400, 0x5550, 0x5680, 0x5860, 0x5B10, 0x5D80, 0x6020, 0x6220, 0x63C0, 0x65D0, + 0x6790, 0x6A20, 0x6CA0, 0x6EF0, 0x7150, 0x72C0, 0x7580, 0x7730, 0x7870, 0x7A10, 0x7A50, 0x7B20, 0x7B70, 0x7B40, 0x7BD0, 0x7B30, + 0x7C00, 0x7BD0, 0x7B50, 0x7B60, 0x7B00, 0x7B40, 0x7B90, 0x7C10, 0x7CB0, 0x7CB0, 0x7D00, 0x7D40, 0x7D10, 0x7DE0, 0x7E20, 0x7EC0, + 0x7ED0, 0x7EB0, 0x7EC0, 0x7EC0, 0x7F10, 0x7EF0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F80, 0x7EE0, 0x7F10, 0x7F10, 0x7F20, 0x7F80, 0x7EF0, + 0x7EB0, 0x7EE0, 0x7EF0, 0x7F30, 0x7EE0, 0x7EC0, 0x7ED0, 0x7E30, 0x7D20, 0x7C00, 0x7AC0, 0x79B0, 0x78C0, 0x7690, 0x74B0, 0x7220, + 0x70C0, 0x6F50, 0x6E00, 0x6DA0, 0x6C80, 0x6C20, 0x6B40, 0x6AD0, 0x6B30, 0x6BA0, 0x6CE0, 0x6E10, 0x6F50, 0x7160, 0x73C0, 0x7640, + 0x7920, 0x7C40, 0x7EC0, 0x7F10, 0x7F70, 0x7F00, 0x7EF0, 0x7F30, 0x7F00, 0x7F70, 0x7EF0, 0x7F20, 0x7F00, 0x7F00, 0x7F70, 0x7F10, + 0x7F00, 0x7EF0, 0x7EF0, 0x7F60, 0x7EF0, 0x7E90, 0x7ED0, 0x7EE0, 0x7F10, 0x7F10, 0x7EA0, 0x7EE0, 0x7ED0, 0x7F10, 0x7F00, 0x7EA0, + 0x7ED0, 0x7F10, 0x7F10, 0x7F20, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7EE0, 0x7F30, + 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F40, 0x7BF0, 0x7390, 0x6BE0, 0x6400, 0x5DC0, 0x57B0, 0x52E0, 0x4F80, 0x4D50, 0x4B60, 0x4F50, + 0x5280, 0x5650, 0x5950, 0x5D70, 0x60E0, 0x6430, 0x6730, 0x6920, 0x6BC0, 0x6D50, 0x6EE0, 0x6FF0, 0x70F0, 0x72B0, 0x7460, 0x7690, + 0x7910, 0x7C10, 0x7E70, 0x7F10, 0x7F70, 0x7EE0, 0x7EC0, 0x7EF0, 0x7F10, 0x7F30, 0x7EE0, 0x7E90, 0x7F10, 0x7F10, 0x7F30, 0x7EC0, + 0x7E90, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7EF0, 0x7F10, 0x7F00, 0x7EC0, + 0x7F30, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F70, 0x7F20, 0x7F10, 0x7F30, 0x7EE0, 0x7F70, 0x7EF0, 0x7F20, 0x7F00, 0x7F00, 0x7F70, + 0x7F20, 0x7F10, 0x7EF0, 0x7EF0, 0x7DF0, 0x7090, 0x64D0, 0x5B60, 0x5300, 0x49A0, 0x41C0, 0x3930, 0x3170, 0x2930, 0x20C0, 0x1850, + 0x0EB0, 0x05F0, 0xFBC0, 0xF1E0, 0xE8B0, 0xE010, 0xD710, 0xCEB0, 0xC680, 0xBF50, 0xB820, 0xB130, 0xAC20, 0xA810, 0xA560, 0xA3B0, + 0xA270, 0xA1B0, 0xA030, 0x9E00, 0x9B80, 0x9870, 0x9580, 0x9240, 0x8F30, 0x8BE0, 0x8970, 0x87B0, 0x8680, 0x85E0, 0x8590, 0x8560, + 0x8550, 0x8530, 0x8530, 0x8520, 0x8520, 0x8520, 0x8520, 0x8520, 0x8520, 0x8520, 0x8520, 0x8510, 0x8510, 0x8510, 0x8500, 0x8500, + 0x84F0, 0x84F0, 0x84E0, 0x84E0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84C0, 0x84D0, 0x84F0, 0x84C0, 0x84D0, 0x84E0, + 0x84D0, 0x84D0, 0x84D0, 0x84E0, 0x84F0, 0x84F0, 0x84F0, 0x8510, 0x8510, 0x8520, 0x8530, 0x8530, 0x8520, 0x8510, 0x8530, 0x8520, + 0x8500, 0x84F0, 0x8500, 0x84D0, 0x84C0, 0x84C0, 0x84B0, 0x84C0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, + 0x84A0, 0x84A0, 0x84F0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84D0, 0x8500, 0x84D0, 0x84E0, 0x84E0, 0x84F0, 0x8500, + 0x8510, 0x8520, 0x8530, 0x8530, 0x8550, 0x8550, 0x8570, 0x8580, 0x85C0, 0x85F0, 0x8610, 0x8650, 0x8680, 0x86F0, 0x8760, 0x8820, + 0x8900, 0x89E0, 0x8AF0, 0x8C10, 0x8D00, 0x8EF0, 0x9160, 0x9470, 0x9720, 0x9980, 0x9C70, 0x9E80, 0xA140, 0xA440, 0xA770, 0xAB20, + 0xADF0, 0xB0F0, 0xB420, 0xB680, 0xB8F0, 0xBB80, 0xBE30, 0xC010, 0xC190, 0xC390, 0xC500, 0xC740, 0xC960, 0xCBC0, 0xCE00, 0xCF60, + 0xD080, 0xD1A0, 0xD2E0, 0xD430, 0xD520, 0xD5A0, 0xD5C0, 0xD5C0, 0xD5F0, 0xD5C0, 0xD610, 0xD600, 0xD550, 0xD430, 0xD320, 0xD280, + 0xD230, 0xD1F0, 0xD1B0, 0xD070, 0xCF10, 0xCDD0, 0xCCA0, 0xCC90, 0xCC80, 0xCD70, 0xCD50, 0xCCC0, 0xCC90, 0xCB90, 0xCAF0, 0xCA50, + 0xCA00, 0xCA20, 0xCA30, 0xC920, 0xC820, 0xC750, 0xC720, 0xC710, 0xC710, 0xC700, 0xC720, 0xC6A0, 0xC630, 0xC600, 0xC5C0, 0xC610, + 0xC750, 0xC840, 0xC8F0, 0xC8F0, 0xC910, 0xC8F0, 0xC8E0, 0xC880, 0xC850, 0xC840, 0xC870, 0xC900, 0xC920, 0xC8C0, 0xC8E0, 0xC910, + 0xC960, 0xC9A0, 0xC9D0, 0xC9E0, 0xCA40, 0xCA70, 0xCB20, 0xCBD0, 0xCCF0, 0xCE20, 0xCF40, 0xD070, 0xD190, 0xD2F0, 0xD440, 0xD570, + 0xD6E0, 0xD8B0, 0xD9C0, 0xDB70, 0xDD80, 0xDF10, 0xE120, 0xE2F0, 0xE510, 0xE730, 0xE990, 0xEC40, 0xEE90, 0xF140, 0xF3F0, 0xF5F0, + 0xF910, 0xFC30, 0xFEA0, 0x0110, 0x03E0, 0x0710, 0x09D0, 0x0CB0, 0x0FA0, 0x12F0, 0x1590, 0x1790, 0x19C0, 0x1C70, 0x1F10, 0x2150, + 0x2370, 0x2560, 0x2760, 0x28F0, 0x2B10, 0x2CC0, 0x2F00, 0x3120, 0x33C0, 0x35D0, 0x37B0, 0x3900, 0x3A40, 0x3B70, 0x3D70, 0x3FB0, + 0x41E0, 0x4410, 0x4610, 0x4740, 0x4920, 0x4A90, 0x4B70, 0x4CB0, 0x4EA0, 0x5000, 0x5150, 0x52C0, 0x54D0, 0x5730, 0x5950, 0x5B20, + 0x5D40, 0x5EC0, 0x5FF0, 0x6120, 0x6330, 0x6530, 0x6690, 0x6800, 0x68A0, 0x6990, 0x6A60, 0x6C40, 0x6E10, 0x6F30, 0x7040, 0x7070, + 0x7050, 0x70D0, 0x7160, 0x71C0, 0x71A0, 0x70F0, 0x7090, 0x6FB0, 0x6E60, 0x6D20, 0x6BF0, 0x69B0, 0x6720, 0x64C0, 0x6250, 0x6030, + 0x5E20, 0x5B40, 0x5800, 0x54D0, 0x5160, 0x4DE0, 0x4A10, 0x46A0, 0x42E0, 0x3F40, 0x3BB0, 0x37B0, 0x3460, 0x31D0, 0x2FF0, 0x2F30, + 0x2DE0, 0x2CD0, 0x2AF0, 0x2A00, 0x29F0, 0x2A60, 0x2C90, 0x2EF0, 0x3240, 0x3580, 0x38D0, 0x3D00, 0x41C0, 0x4690, 0x4C10, 0x51B0, + 0x57A0, 0x5E50, 0x64B0, 0x6AA0, 0x71D0, 0x7850, 0x7D70, 0x7F20, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F50, 0x7E90, 0x7EB0, 0x7EF0, + 0x7EE0, 0x7EF0, 0x7E80, 0x7E70, 0x7EF0, 0x7F20, 0x7F00, 0x7F00, 0x7ED0, 0x7F00, 0x7F20, 0x7F00, 0x7F00, 0x7F20, 0x7F20, 0x7F10, + 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7ED0, 0x7C30, 0x72E0, 0x6A70, 0x6380, 0x5D90, 0x5860, 0x54A0, 0x51A0, 0x50A0, + 0x4FE0, 0x50D0, 0x5270, 0x54F0, 0x5970, 0x5EF0, 0x6430, 0x6AE0, 0x7000, 0x74F0, 0x79A0, 0x7CC0, 0x7E80, 0x7E90, 0x7F10, 0x7F20, + 0x7F10, 0x7EB0, 0x7C40, 0x78F0, 0x74B0, 0x6F00, 0x69C0, 0x63C0, 0x5E80, 0x5900, 0x5540, 0x53B0, 0x5400, 0x5560, 0x5750, 0x5990, + 0x5CE0, 0x5FC0, 0x6390, 0x67B0, 0x6B60, 0x7040, 0x73D0, 0x7710, 0x7920, 0x7B40, 0x7C80, 0x7CC0, 0x7C60, 0x7B50, 0x7970, 0x77A0, + 0x7600, 0x74D0, 0x7430, 0x7360, 0x7290, 0x71E0, 0x7070, 0x7040, 0x6FD0, 0x7030, 0x7040, 0x6F90, 0x6F10, 0x6E20, 0x6DD0, 0x6CB0, + 0x6BB0, 0x6B70, 0x6A80, 0x6A90, 0x6BA0, 0x6C40, 0x6ED0, 0x7080, 0x7260, 0x7440, 0x7590, 0x77B0, 0x7960, 0x7B40, 0x7D10, 0x7E20, + 0x7ED0, 0x7ED0, 0x7F30, 0x7F20, 0x7F10, 0x7EF0, 0x7EB0, 0x7EE0, 0x7E30, 0x7CB0, 0x7A60, 0x7850, 0x75D0, 0x7330, 0x7020, 0x6DC0, + 0x6AD0, 0x6760, 0x63A0, 0x6080, 0x5E30, 0x5C20, 0x59B0, 0x5750, 0x5430, 0x5200, 0x4F80, 0x4D70, 0x4C60, 0x4A90, 0x4950, 0x4720, + 0x44F0, 0x43C0, 0x4110, 0x3F60, 0x3DC0, 0x3A70, 0x3700, 0x3160, 0x2BE0, 0x2610, 0x1F60, 0x18E0, 0x1090, 0x0A10, 0x0360, 0xFD40, + 0xF890, 0xF4E0, 0xF160, 0xEE00, 0xEA70, 0xE6A0, 0xE3E0, 0xE200, 0xE0B0, 0xDF10, 0xDD30, 0xDA10, 0xD620, 0xD1D0, 0xCC50, 0xC810, + 0xC280, 0xBBB0, 0xB380, 0xAA80, 0xA060, 0x95A0, 0x8C80, 0x8790, 0x85C0, 0x8520, 0x84F0, 0x84D0, 0x84C0, 0x84B0, 0x84B0, 0x84A0, + 0x84A0, 0x8490, 0x8490, 0x8490, 0x84D0, 0x8490, 0x8490, 0x8490, 0x8490, 0x8480, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, + 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, + 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8480, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, + 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, + 0x84C0, 0x84C0, 0x84C0, 0x84D0, 0x84D0, 0x84E0, 0x84E0, 0x84E0, 0x8500, 0x8510, 0x8520, 0x8530, 0x8560, 0x8590, 0x85C0, 0x8620, + 0x8680, 0x8710, 0x8790, 0x8830, 0x8960, 0x8AA0, 0x8BD0, 0x8D10, 0x8E20, 0x8FB0, 0x9180, 0x93B0, 0x94F0, 0x95B0, 0x9580, 0x9530, + 0x95C0, 0x9680, 0x9780, 0x98A0, 0x98A0, 0x98D0, 0x9830, 0x9760, 0x9710, 0x96C0, 0x9710, 0x96A0, 0x9610, 0x9580, 0x9500, 0x9480, + 0x9430, 0x9490, 0x94C0, 0x9410, 0x93C0, 0x93C0, 0x9410, 0x94D0, 0x9520, 0x9580, 0x95A0, 0x9580, 0x9600, 0x9600, 0x9680, 0x96F0, + 0x9630, 0x95C0, 0x9460, 0x9390, 0x92F0, 0x9280, 0x9300, 0x92C0, 0x91D0, 0x9060, 0x8F10, 0x8DD0, 0x8D70, 0x8D20, 0x8C80, 0x8BA0, + 0x8AD0, 0x89E0, 0x88D0, 0x8830, 0x87C0, 0x8770, 0x8730, 0x86C0, 0x8660, 0x8620, 0x85E0, 0x85C0, 0x85C0, 0x8570, 0x8570, 0x8560, + 0x8550, 0x8520, 0x8550, 0x8530, 0x8530, 0x8520, 0x8510, 0x8510, 0x8500, 0x8500, 0x8500, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84E0, + 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84C0, 0x84D0, 0x8460, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, + 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, + 0x84B0, 0x84B0, 0x84B0, 0x8450, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, + 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, + 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, + 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84D0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, + 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, + 0x84C0, 0x84C0, 0x84E0, 0x84D0, 0x84D0, 0x84E0, 0x84F0, 0x8500, 0x8510, 0x8530, 0x8580, 0x85F0, 0x8710, 0x8930, 0x8CE0, 0x91F0, + 0x9840, 0x9E70, 0xA4D0, 0xAB60, 0xB0C0, 0xB610, 0xBA80, 0xBE00, 0xC1A0, 0xC570, 0xC900, 0xCC90, 0xD010, 0xD260, 0xD440, 0xD5A0, + 0xD690, 0xD830, 0xDA40, 0xDC40, 0xDE70, 0xDFB0, 0xE060, 0xE150, 0xE1C0, 0xE270, 0xE330, 0xE350, 0xE3D0, 0xE450, 0xE500, 0xE630, + 0xE710, 0xE790, 0xE740, 0xE6A0, 0xE630, 0xE590, 0xE530, 0xE5C0, 0xE5E0, 0xE620, 0xE5A0, 0xE4A0, 0xE380, 0xE2A0, 0xE240, 0xE200, + 0xE190, 0xE190, 0xE0B0, 0xE0D0, 0xE160, 0xE1A0, 0xE270, 0xE250, 0xE2B0, 0xE370, 0xE430, 0xE570, 0xE780, 0xE9E0, 0xEC90, 0xEF10, + 0xF1A0, 0xF3B0, 0xF6B0, 0xF980, 0xFD80, 0x0190, 0x0590, 0x09B0, 0x0E40, 0x1300, 0x1790, 0x1C80, 0x2180, 0x2650, 0x2B20, 0x2FA0, + 0x34D0, 0x3980, 0x3EE0, 0x4420, 0x4940, 0x4D90, 0x51E0, 0x5610, 0x5A90, 0x5E80, 0x62A0, 0x65E0, 0x68F0, 0x6BE0, 0x6DE0, 0x6FC0, + 0x71F0, 0x7420, 0x75A0, 0x76D0, 0x7780, 0x77D0, 0x77D0, 0x7850, 0x78D0, 0x7940, 0x7950, 0x78D0, 0x7750, 0x7600, 0x7560, 0x7580, + 0x75A0, 0x75A0, 0x7550, 0x7510, 0x74A0, 0x7520, 0x75F0, 0x76F0, 0x7820, 0x7950, 0x7A10, 0x7B90, 0x7CC0, 0x7E40, 0x7EF0, 0x7F00, + 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7EE0, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, + 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7ED0, 0x7E10, 0x7D30, 0x7C00, 0x7BC0, 0x7B50, 0x7950, 0x7860, 0x77D0, 0x7690, 0x7610, 0x75A0, + 0x75C0, 0x75F0, 0x7630, 0x76A0, 0x7680, 0x75E0, 0x7560, 0x7540, 0x7580, 0x7630, 0x7760, 0x78F0, 0x7A80, 0x7C80, 0x7DE0, 0x7ED0, + 0x7F00, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F00, 0x7EF0, 0x7EF0, 0x7EF0, 0x7F60, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F50, 0x7F10, + 0x7F00, 0x7F10, 0x7EF0, 0x7F30, 0x7EF0, 0x7E90, 0x7F00, 0x7F00, 0x7F00, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7E80, + 0x7EF0, 0x7F10, 0x7EF0, 0x7ED0, 0x7EB0, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F60, + 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F60, 0x7EF0, 0x7F10, 0x7EF0, 0x7EE0, 0x7F50, 0x7F00, 0x7F00, 0x7F00, 0x7F10, 0x7F70, 0x7F00, + 0x7ED0, 0x7F10, 0x7F00, 0x7F40, 0x7E90, 0x7C50, 0x7920, 0x7510, 0x70B0, 0x6D10, 0x6940, 0x6680, 0x6350, 0x6030, 0x5DA0, 0x5970, + 0x5660, 0x5370, 0x5090, 0x4F00, 0x4E00, 0x4D60, 0x4C40, 0x4C90, 0x4E00, 0x4F10, 0x5110, 0x5270, 0x5360, 0x5450, 0x5490, 0x5530, + 0x5660, 0x5660, 0x56E0, 0x5720, 0x5670, 0x5600, 0x54A0, 0x5440, 0x5240, 0x4FF0, 0x4D70, 0x4B10, 0x4980, 0x4760, 0x4500, 0x4350, + 0x4150, 0x3FA0, 0x3D60, 0x3B30, 0x3A00, 0x38A0, 0x37C0, 0x36F0, 0x3670, 0x3660, 0x3510, 0x3490, 0x32C0, 0x3090, 0x2F50, 0x2D00, + 0x2C00, 0x2940, 0x26D0, 0x2410, 0x2060, 0x1D80, 0x1A60, 0x16C0, 0x13D0, 0x1050, 0x0C60, 0x08C0, 0x0450, 0x00C0, 0xFCE0, 0xF940, + 0xF610, 0xF230, 0xEF60, 0xEBF0, 0xE830, 0xE490, 0xE070, 0xDC30, 0xD7F0, 0xD470, 0xD140, 0xCEA0, 0xCC60, 0xCA90, 0xC8F0, 0xC7D0, + 0xC600, 0xC4B0, 0xC370, 0xC340, 0xC2A0, 0xC250, 0xC310, 0xC3E0, 0xC540, 0xC700, 0xC9F0, 0xCD20, 0xD030, 0xD290, 0xD580, 0xD780, + 0xDA00, 0xDD00, 0xE040, 0xED40, 0xEFE0, 0xF2D0, 0xF5E0, 0xF8B0, 0xFB50, 0xFD60, 0x0000, 0x0180, 0x03F0, 0x06C0, 0x0950, 0x0BB0, + 0x0D00, 0x0EF0, 0x0FD0, 0x1090, 0x10A0, 0x0F90, 0x0EF0, 0x0D90, 0x0B50, 0x0A30, 0x0860, 0x06E0, 0x0520, 0x0250, 0xFFB0, 0xFC00, + 0xF820, 0xF450, 0xF0C0, 0xEE50, 0xEBF0, 0xEA30, 0xE7E0, 0xE460, 0xE110, 0xDDF0, 0xDB60, 0xD9A0, 0xD7F0, 0xD740, 0xD5D0, 0xD3F0, + 0xD2D0, 0xD1D0, 0xD1F0, 0xD1B0, 0xD230, 0xD330, 0xD3A0, 0xD460, 0xD4D0, 0xD550, 0xD6D0, 0xD800, 0xDA10, 0xDB90, 0xDCF0, 0xDEF0, + 0xE060, 0xE210, 0xE400, 0xE5C0, 0xE7A0, 0xE8E0, 0xEA40, 0xEBC0, 0xEDD0, 0xEFE0, 0xF160, 0xF2A0, 0xF450, 0xF5E0, 0xF910, 0xFBA0, + 0xFED0, 0x0180, 0x0340, 0x0510, 0x06B0, 0x0940, 0x0B70, 0x0E00, 0x10E0, 0x1350, 0x1550, 0x1750, 0x18C0, 0x1B10, 0x1CB0, 0x1E70, + 0x1F40, 0x2090, 0x2230, 0x23E0, 0x2550, 0x2710, 0x2890, 0x2A40, 0x2B80, 0x2B70, 0x2BE0, 0x2C40, 0x2D90, 0x2EA0, 0x2F20, 0x2FC0, + 0x2F50, 0x2EB0, 0x2F50, 0x2FB0, 0x30B0, 0x30C0, 0x30F0, 0x3050, 0x2F20, 0x2FC0, 0x3000, 0x3070, 0x3100, 0x3110, 0x3200, 0x3200, + 0x32C0, 0x32C0, 0x3370, 0x3430, 0x3440, 0x33B0, 0x33D0, 0x3340, 0x33F0, 0x34F0, 0x3500, 0x35C0, 0x3540, 0x3570, 0x34E0, 0x33F0, + 0x33F0, 0x3370, 0x3360, 0x3250, 0x3090, 0x2F30, 0x2D30, 0x2C30, 0x2A30, 0x2950, 0x27C0, 0x24D0, 0x2290, 0x2060, 0x1E00, 0x1C70, + 0x1A40, 0x1940, 0x1770, 0x1540, 0x1460, 0x1290, 0x1130, 0x0F90, 0x0C90, 0x0B10, 0x0900, 0x0740, 0x0590, 0x0490, 0x0420, 0x03A0, + 0x0280, 0x01A0, 0x0020, 0xFFB0, 0xFF50, 0xFF80, 0xFFE0, 0x0040, 0x0130, 0x0130, 0x0190, 0x0180, 0x0190, 0x02C0, 0x03C0, 0x0410, + 0x04A0, 0x0470, 0x04D0, 0x05A0, 0x06C0, 0x0800, 0x08F0, 0x0A40, 0x0A40, 0x0AF0, 0x0C30, 0x0CA0, 0x0E10, 0x0ED0, 0x0EE0, 0x0F40, + 0x0F80, 0x1030, 0x1130, 0x11F0, 0x12D0, 0x1300, 0x1380, 0x1310, 0x1310, 0x13A0, 0x13C0, 0x1450, 0x1450, 0x1520, 0x1530, 0x15B0, + 0x15E0, 0x1640, 0x15D0, 0x1630, 0x1610, 0x1670, 0x1710, 0x17B0, 0x1920, 0x1990, 0x1980, 0x19C0, 0x18E0, 0x1950, 0x19B0, 0x19E0, + 0x1A10, 0x19B0, 0x1960, 0x1900, 0x1840, 0x1820, 0x1740, 0x16A0, 0x15D0, 0x1520, 0x14E0, 0x1430, 0x1470, 0x1400, 0x1420, 0x14F0, + 0x14E0, 0x1590, 0x1550, 0x1530, 0x1560, 0x1520, 0x1590, 0x1510, 0x14E0, 0x1460, 0x1340, 0x12F0, 0x1240, 0x1110, 0x1060, 0x0F80, + 0x0EC0, 0x0DB0, 0x0CB0, 0x0BB0, 0x0980, 0x0860, 0x0640, 0x03A0, 0x0180, 0xFF10, 0xFD00, 0xFA40, 0xF7B0, 0xF450, 0xF180, 0xEEC0, + 0xEC50, 0xE960, 0xE6C0, 0xE490, 0xE2A0, 0xDFE0, 0xDD80, 0xDB20, 0xD930, 0xD750, 0xD620, 0xD530, 0xD490, 0xD3F0, 0xD2F0, 0xD240, + 0xD160, 0xD0C0, 0xD070, 0xD040, 0xD060, 0xD0F0, 0xD150, 0xD1A0, 0xD280, 0xD340, 0xD400, 0xD4A0, 0xD440, 0xD3F0, 0xD390, 0xD3D0, + 0xD480, 0xD520, 0xD620, 0xD680, 0xD6E0, 0xD610, 0xD530, 0xD330, 0xD2F0, 0xD2D0, 0xD290, 0xD2D0, 0xD310, 0xD2F0, 0xD340, 0xD2D0, + 0xD250, 0xD1B0, 0xD170, 0xD190, 0xD1E0, 0xD140, 0xD0D0, 0xD030, 0xCFC0, 0xCF30, 0xCF10, 0xCED0, 0xCED0, 0xCF60, 0xCFE0, 0xD000, + 0xCFF0, 0xD010, 0xD050, 0xD030, 0xD040, 0xD050, 0xD000, 0xD010, 0xD120, 0xD130, 0xD180, 0xD210, 0xD220, 0xD230, 0xD1F0, 0xD1A0, + 0xD1F0, 0xD300, 0xD410, 0xD4C0, 0xD550, 0xD5A0, 0xD600, 0xD5C0, 0xD5B0, 0xD5A0, 0xD560, 0xD5C0, 0xD5C0, 0xD5A0, 0xD580, 0xD550, + 0xD530, 0xD500, 0xD4C0, 0xD450, 0xD450, 0xD400, 0xD440, 0xD4C0, 0xD520, 0xD570, 0xD5D0, 0xD510, 0xD590, 0xD5C0, 0xD650, 0xD710, + 0xD730, 0xD790, 0xD710, 0xD710, 0xD6A0, 0xD6E0, 0xD6B0, 0xD6D0, 0xD730, 0xD7C0, 0xD850, 0xD8C0, 0xD990, 0xDA40, 0xDA70, 0xDAD0, + 0xDB50, 0xDBF0, 0xDC90, 0xDCC0, 0xDDD0, 0xDE70, 0xDED0, 0xDF00, 0xDFA0, 0xDF70, 0xDFF0, 0xE0C0, 0xE130, 0xE1C0, 0xE2B0, 0xE370, + 0xE490, 0xE530, 0xE570, 0xE590, 0xE560, 0xE510, 0xE5C0, 0xE6D0, 0xE7D0, 0xE900, 0xEA60, 0xEB00, 0xEB10, 0xEAF0, 0xEAD0, 0xEAE0, + 0xEC00, 0xECE0, 0xEEE0, 0xF080, 0xF250, 0xF320, 0xF380, 0xF430, 0xF490, 0xF470, 0xF4B0, 0xF610, 0xF750, 0xF870, 0xFA10, 0xFAD0, + 0xFC40, 0xFD70, 0xFE40, 0xFF80, 0xFFF0, 0x0100, 0x0100, 0x0150, 0x0200, 0x02B0, 0x0390, 0x03D0, 0x0440, 0x04C0, 0x04F0, 0x05E0, + 0x0660, 0x0670, 0x06E0, 0x06C0, 0x06C0, 0x0750, 0x0790, 0x0820, 0x0840, 0x0910, 0x0930, 0x0940, 0x09B0, 0x0980, 0x09A0, 0x0A10, + 0x09D0, 0x0A30, 0x0A60, 0x0A40, 0x0AA0, 0x0AA0, 0x0B40, 0x0B50, 0x0AC0, 0x0AC0, 0x0AC0, 0x0AB0, 0x0A70, 0x09B0, 0x09D0, 0x0990, + 0x0970, 0x0990, 0x08F0, 0x0920, 0x08C0, 0x0880, 0x0900, 0x0940, 0x0940, 0x08D0, 0x0830, 0x0800, 0x07F0, 0x07D0, 0x07D0, 0x0810, + 0x07E0, 0x07B0, 0x0870, 0x0840, 0x0910, 0x08B0, 0x07E0, 0x07D0, 0x06E0, 0x0700, 0x06C0, 0x0630, 0x0630, 0x0600, 0x0600, 0x0610, + 0x0570, 0x0640, 0x0600, 0x05A0, 0x05C0, 0x0470, 0x0430, 0x0430, 0x0440, 0x0470, 0x0470, 0x04C0, 0x03E0, 0x0250, 0x01E0, 0x00A0, + 0x0040, 0xFF70, 0xFEE0, 0xFDF0, 0xFD50, 0xFD50, 0xFC60, 0xFBC0, 0xFBB0, 0xFAF0, 0xFAC0, 0xF940, 0xF7F0, 0xF700, 0xF640, 0xF5D0, + 0xF5F0, 0xF5C0, 0xF5D0, 0xF4D0, 0xF430, 0xF3C0, 0xF2B0, 0xF1F0, 0xF140, 0xF090, 0xF000, 0xEF00, 0xEF60, 0xEF80, 0xEF80, 0xEF80, + 0xEEF0, 0xEE50, 0xEDA0, 0xED20, 0xED50, 0xEDB0, 0xEE70, 0xEEE0, 0xEE80, 0xEEA0, 0xEE40, 0xEEB0, 0xEEF0, 0xEF50, 0xF070, 0xF0F0, + 0xF1B0, 0xF2C0, 0xF410, 0xF5E0, 0xF7E0, 0xFAC0, 0xFCC0, 0xFF80, 0x0270, 0x0590, 0x09D0, 0x0E20, 0x12F0, 0x1790, 0x1BA0, 0x2000, + 0x2500, 0x2970, 0x2F60, 0x3460, 0x3A50, 0x3F90, 0x4420, 0x4960, 0x4DC0, 0x5280, 0x5640, 0x5980, 0x5CB0, 0x5E40, 0x6020, 0x6180, + 0x6230, 0x6370, 0x6380, 0x63F0, 0x6460, 0x63A0, 0x6380, 0x6280, 0x60C0, 0x5E60, 0x5B90, 0x58B0, 0x55B0, 0x5280, 0x4F70, 0x4B30, + 0x4780, 0x4310, 0x3DB0, 0x37A0, 0x3100, 0x1400, 0x0B40, 0x0310, 0xFAB0, 0xF360, 0xED00, 0xE750, 0xE270, 0xDD60, 0xD810, 0xD150, + 0xCA70, 0xC340, 0xBB00, 0xB290, 0xA970, 0xA1D0, 0x9D30, 0x9BE0, 0x9EF0, 0xA6C0, 0xB0A0, 0xBB00, 0xC300, 0xC870, 0xC8C0, 0xC4D0, + 0xBCD0, 0xB250, 0xA590, 0x97A0, 0x8AB0, 0x85A0, 0x84E0, 0x84B0, 0x8490, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, + 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x84A0, 0x84A0, 0x84B0, 0x84C0, 0x84D0, 0x84F0, + 0x8520, 0x8550, 0x85B0, 0x8690, 0x8860, 0x8BF0, 0x9130, 0x96C0, 0x9BB0, 0xA150, 0xA620, 0xAA70, 0xADE0, 0xB1F0, 0xB5E0, 0xB8A0, + 0xBC30, 0xC010, 0xC400, 0xC9D0, 0xD000, 0xD740, 0xDFD0, 0xE8B0, 0xF300, 0xFD80, 0x08C0, 0x1450, 0x1E20, 0x27D0, 0x3000, 0x3730, + 0x3D70, 0x42C0, 0x4880, 0x4D00, 0x5160, 0x5590, 0x5860, 0x5B00, 0x5C40, 0x5DB0, 0x5F20, 0x60E0, 0x6310, 0x6490, 0x65E0, 0x6670, + 0x6610, 0x66B0, 0x67E0, 0x6990, 0x6AB0, 0x6B30, 0x6B70, 0x6B10, 0x6A60, 0x69A0, 0x6880, 0x6890, 0x6780, 0x65E0, 0x6550, 0x64D0, + 0x6640, 0x6890, 0x6A90, 0x6E30, 0x7200, 0x7650, 0x7AB0, 0x7DA0, 0x7F00, 0x7EB0, 0x7F20, 0x7F00, 0x7E10, 0x79B0, 0x7440, 0x6EC0, + 0x6990, 0x63B0, 0x5EE0, 0x5980, 0x5510, 0x5180, 0x4E20, 0x4B90, 0x4970, 0x4730, 0x4540, 0x42B0, 0x4220, 0x4260, 0x4250, 0x42D0, + 0x4340, 0x4420, 0x4530, 0x46F0, 0x4A00, 0x4D10, 0x5210, 0x55F0, 0x59F0, 0x5E90, 0x62D0, 0x6900, 0x6EC0, 0x7590, 0x7BA0, 0x7E80, + 0x7ED0, 0x7EB0, 0x7F00, 0x7F00, 0x7E90, 0x7F10, 0x7EE0, 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EE0, 0x7F10, + 0x7F00, 0x7F00, 0x7EF0, 0x7F00, 0x7F60, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7F20, 0x7EF0, 0x7F50, 0x7F00, + 0x7F00, 0x7F10, 0x7F20, 0x7F60, 0x7F00, 0x7EF0, 0x7F00, 0x7EE0, 0x7F60, 0x7A90, 0x7120, 0x6CC0, 0x6AF0, 0x6BF0, 0x6FC0, 0x74D0, + 0x7B50, 0x7EF0, 0x7F20, 0x7ED0, 0x7EA0, 0x7F00, 0x7EF0, 0x7EF0, 0x7F20, 0x7EC0, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7EC0, 0x7F10, + 0x7EE0, 0x7EF0, 0x7F40, 0x7F10, 0x7F60, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7F80, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F60, 0x7EF0, + 0x7F10, 0x7F10, 0x7F00, 0x7F70, 0x7F10, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F70, 0x7F00, 0x7EC0, 0x7ED0, 0x7EF0, 0x7F30, 0x7F20, 0x7E90, + 0x7F00, 0x7EE0, 0x7EF0, 0x7F10, 0x7E70, 0x7EC0, 0x6B40, 0x4E30, 0x2F40, 0x0BE0, 0xEB50, 0xC9F0, 0xA7B0, 0x86C0, 0x84C0, 0x8490, + 0x8470, 0x8450, 0x8430, 0x8420, 0x8410, 0x8400, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, + 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, + 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, + 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8430, 0x8460, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8460, + 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8480, 0x8480, 0x8480, + 0x8480, 0x8470, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8470, 0x8470, 0x8480, 0x8470, 0x8470, 0x8480, 0x8470, 0x8470, + 0x8480, 0x8490, 0x8490, 0x84B0, 0x84D0, 0x8500, 0x9B90, 0xA6F0, 0xB010, 0xB8B0, 0xBFF0, 0xC6A0, 0xCD00, 0xD2C0, 0xD640, 0xD870, + 0xD920, 0xD970, 0xD950, 0xD9E0, 0xDAD0, 0xDBD0, 0xDC60, 0xDC00, 0xDAE0, 0xD850, 0xD4F0, 0xD040, 0xCB30, 0xC4D0, 0xBF90, 0xBA60, + 0xB630, 0xB410, 0xB390, 0xB4F0, 0xB740, 0xB9C0, 0xBCF0, 0xC060, 0xC430, 0xC9A0, 0xCF00, 0xD500, 0xDAF0, 0xE210, 0xE9E0, 0xF2D0, + 0xFBF0, 0x05C0, 0x0E70, 0x16B0, 0x1EB0, 0x2600, 0x2C00, 0x30D0, 0x3350, 0x3350, 0x31F0, 0x2F70, 0x2C50, 0x29A0, 0x25A0, 0x20B0, + 0x1B30, 0x1470, 0x0DC0, 0x06D0, 0x00B0, 0xFBE0, 0xF6F0, 0xF350, 0xEF70, 0xEBA0, 0xE840, 0xE4B0, 0xE180, 0xDF10, 0xDC50, 0xD950, + 0xD4E0, 0xD0C0, 0xCB40, 0xC550, 0xC040, 0xB9B0, 0xB230, 0xAAC0, 0xA250, 0x99C0, 0x9140, 0x8AD0, 0x8760, 0x85D0, 0x8540, 0x8500, + 0x84E0, 0x84D0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84E0, 0x8520, 0x8620, 0x8B20, 0x9A70, + 0xAA60, 0xB800, 0xC430, 0xCF10, 0xD920, 0xE270, 0xEB10, 0xF3E0, 0xFB60, 0x02F0, 0x0940, 0x0D60, 0x1050, 0x1200, 0x1350, 0x14C0, + 0x1580, 0x1740, 0x1820, 0x1800, 0x1740, 0x1580, 0x1320, 0x10C0, 0x0DB0, 0x0BF0, 0x0A70, 0x0A70, 0x0BB0, 0x0DB0, 0x11F0, 0x16F0, + 0x1C90, 0x2340, 0x2A50, 0x32B0, 0x3B60, 0x4340, 0x4A10, 0x4FB0, 0x5520, 0x5940, 0x5D50, 0x6120, 0x6420, 0x6810, 0x6AB0, 0x6CF0, + 0x6E90, 0x6F90, 0x70F0, 0x71E0, 0x7240, 0x7350, 0x7320, 0x7400, 0x74D0, 0x74B0, 0x74C0, 0x7400, 0x7350, 0x72B0, 0x71E0, 0x71B0, + 0x7030, 0x6FA0, 0x6E60, 0x6CD0, 0x6C10, 0x6B40, 0x6AE0, 0x6AD0, 0x6A40, 0x6A40, 0x6990, 0x6900, 0x6870, 0x67C0, 0x6890, 0x68E0, + 0x6930, 0x6990, 0x69E0, 0x6AE0, 0x6C40, 0x6DD0, 0x7030, 0x7220, 0x7440, 0x7650, 0x7870, 0x7A60, 0x7C50, 0x7E70, 0x7F00, 0x7F70, + 0x7ED0, 0x7EB0, 0x7EF0, 0x7F10, 0x7F30, 0x7EE0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7EC0, 0x7F00, 0x7F00, 0x7F10, 0x7F10, + 0x7EA0, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F60, 0x7EE0, 0x7F10, 0x7F20, 0x7EF0, + 0x7F80, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F70, 0x7F00, 0x7F10, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7EF0, 0x7F00, 0x7EE0, 0x7F50, + 0x7F20, 0x7EE0, 0x7ED0, 0x7ED0, 0x7F30, 0x7EF0, 0x7E90, 0x7ED0, 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, 0x7EF0, 0x7EB0, 0x7EE0, 0x7ED0, + 0x7F10, 0x77A0, 0x6DA0, 0x64C0, 0x5B90, 0x52A0, 0x4B70, 0x4400, 0x3E70, 0x38E0, 0x33B0, 0x2FD0, 0x2C80, 0x2A80, 0x2950, 0x2950, + 0x2C00, 0x2E40, 0x3290, 0x3880, 0x3E40, 0x4580, 0x4C90, 0x5220, 0x5670, 0x59D0, 0x5C30, 0x5DE0, 0x5F30, 0x5F90, 0x5F70, 0x5FA0, + 0x5EF0, 0x5DF0, 0x5CA0, 0x5B40, 0x5A90, 0x5A30, 0x5A70, 0x5B20, 0x5B90, 0x5D50, 0x5EE0, 0x61F0, 0x66E0, 0x6C60, 0x7350, 0x7A00, + 0x7E70, 0x7EE0, 0x7EC0, 0x7F10, 0x7EE0, 0x7EF0, 0x7EF0, 0x7EB0, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7F10, 0x7F00, 0x7F00, + 0x7F10, 0x7F00, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F00, 0x7F60, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7F50, 0x7F10, 0x7F20, 0x7EF0, + 0x7F10, 0x7F70, 0x7F00, 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, 0x7EF0, 0x7EF0, 0x7EE0, 0x7ED0, 0x7F70, 0x7F20, 0x7EA0, 0x7ED0, 0x7ED0, + 0x7F00, 0x7F10, 0x7E90, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F20, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, + 0x7EF0, 0x7EF0, 0x7F30, 0x7F00, 0x7F10, 0x7F20, 0x7F20, 0x7F50, 0x7ED0, 0x6110, 0x4370, 0x25F0, 0x0830, 0xEEF0, 0xD720, 0xC150, + 0xADF0, 0x9BD0, 0x8E90, 0x88A0, 0x86F0, 0x86C0, 0x8790, 0x8AA0, 0x92B0, 0x9DF0, 0xA910, 0xB410, 0xBE70, 0xC790, 0xD050, 0xD830, + 0xDEE0, 0xE590, 0xEBF0, 0xF220, 0xF780, 0xFB50, 0xFFF0, 0x02C0, 0x0510, 0x06E0, 0x0840, 0x09F0, 0x0AB0, 0x0B50, 0x0BE0, 0x0C60, + 0x0E30, 0x0FA0, 0x11A0, 0x1430, 0x16B0, 0x1AA0, 0x1EC0, 0x23D0, 0x29F0, 0x3020, 0x3650, 0x3B30, 0x3FF0, 0x4420, 0x4790, 0x4B10, + 0x4D20, 0x4DF0, 0x4D90, 0x4B70, 0x4940, 0x4640, 0x43F0, 0x42A0, 0x40E0, 0x40F0, 0x4190, 0x4320, 0x4650, 0x4A90, 0x50C0, 0x57C0, + 0x5F90, 0x68B0, 0x7100, 0x7960, 0x7E90, 0x7F30, 0x7F00, 0x7E90, 0x7ED0, 0x7F10, 0x7F20, 0x7F10, 0x7EB0, 0x7F00, 0x7F10, 0x7F10, + 0x7F10, 0x7EC0, 0x7F00, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7E10, 0x5E70, 0x3AF0, 0x1490, 0xEAE0, + 0xC400, 0x9D90, 0x8660, 0x84C0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8450, 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, 0x8430, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, + 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8420, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, 0x8430, 0x8440, + 0x8480, 0x8460, 0x8470, 0x8480, 0x8480, 0x84B0, 0x84E0, 0x8530, 0x86A0, 0x8DB0, 0x9D20, 0xAB40, 0xB7F0, 0xC4C0, 0xD130, 0xDD30, + 0xE8D0, 0xF3B0, 0xFE00, 0x06A0, 0x0E10, 0x1420, 0x19C0, 0x1F30, 0x2310, 0x2570, 0x2790, 0x2830, 0x27F0, 0x2540, 0x2150, 0x1AE0, + 0x12E0, 0x0890, 0xFD50, 0xF0A0, 0xE460, 0xD8B0, 0xCD10, 0xC1D0, 0xB660, 0xAB80, 0xA180, 0x98E0, 0x9180, 0x8BD0, 0x8870, 0x86C0, + 0x85F0, 0x8590, 0x8570, 0x8570, 0x8570, 0x85C0, 0x85E0, 0x8680, 0x8820, 0x8C40, 0x95F0, 0xA030, 0xAAB0, 0xB510, 0xBFB0, 0xCA30, + 0xD440, 0xDCD0, 0xE380, 0xE900, 0xEC90, 0xF030, 0xF390, 0xF7E0, 0xFC70, 0x00D0, 0x04C0, 0x0860, 0x0BD0, 0x0EA0, 0x1170, 0x1430, + 0x1650, 0x18E0, 0x1BD0, 0x1F80, 0x22B0, 0x2640, 0x28C0, 0x2A50, 0x2BA0, 0x2C60, 0x2D70, 0x2E50, 0x30B0, 0x3360, 0x36D0, 0x3990, + 0x3BC0, 0x3E10, 0x3FF0, 0x42B0, 0x4640, 0x4A20, 0x4D80, 0x5160, 0x54E0, 0x58D0, 0x5D30, 0x6120, 0x65A0, 0x69C0, 0x6DF0, 0x71B0, + 0x75F0, 0x78D0, 0x7BD0, 0x7DF0, 0x7EF0, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, + 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, + 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F00, 0x7F30, 0x7F30, 0x7F40, 0x7F40, 0x7F10, + 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F70, 0x7F20, 0x7EF0, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7EB0, 0x7EF0, 0x7EE0, 0x7EF0, 0x7EB0, + 0x7EA0, 0x7ED0, 0x7F30, 0x7F30, 0x7F00, 0x7F10, 0x7F10, 0x7EF0, 0x7F40, 0x7F40, 0x7ED0, 0x7F00, 0x7EF0, 0x7F30, 0x7F30, 0x7E70, + 0x7ED0, 0x7EE0, 0x7F10, 0x7F30, 0x7E70, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F00, + 0x7F10, 0x7F10, 0x7F30, 0x7F00, 0x7F40, 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7EF0, 0x7F00, 0x7EF0, 0x7F00, 0x7F40, 0x7EF0, + 0x7F10, 0x7F00, 0x7F20, 0x7F80, 0x7EF0, 0x7EB0, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7EC0, 0x7F10, 0x7F20, 0x7F40, 0x7EF0, 0x7EB0, + 0x7F00, 0x7F10, 0x7F10, 0x7EE0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7EF0, 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F20, + 0x7EF0, 0x7F00, 0x7F00, 0x7EE0, 0x7F50, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F70, 0x7F10, 0x7F10, 0x7F10, 0x7EE0, 0x7F70, 0x7F10, + 0x7F10, 0x7F00, 0x7EF0, 0x7F70, 0x7F00, 0x7F00, 0x7EF0, 0x7EB0, 0x7F60, 0x7EF0, 0x7E90, 0x7EE0, 0x7EE0, 0x7F50, 0x7F20, 0x7EA0, + 0x7ED0, 0x7ED0, 0x7F10, 0x7F00, 0x7EA0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7EC0, 0x7F10, + 0x7F10, 0x7F00, 0x7EF0, 0x7EF0, 0x7F50, 0x7F20, 0x7F40, 0x7F20, 0x7F20, 0x7F60, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7F50, 0x7F10, + 0x7F10, 0x7EF0, 0x7F10, 0x7F60, 0x7F00, 0x7EF0, 0x7F10, 0x7EE0, 0x7F60, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F30, 0x7F00, 0x7EC0, + 0x7F10, 0x7F10, 0x7EF0, 0x7E10, 0x7D30, 0x7D20, 0x7CC0, 0x7BF0, 0x7B60, 0x7A00, 0x7880, 0x76B0, 0x7500, 0x73E0, 0x7230, 0x71B0, + 0x7170, 0x7110, 0x7190, 0x7250, 0x7340, 0x74C0, 0x7630, 0x7840, 0x7A40, 0x7BD0, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7F40, 0x7F00, + 0x7F30, 0x7EF0, 0x7F10, 0x7F30, 0x7F20, 0x7F90, 0x7F10, 0x7F10, 0x7EE0, 0x7EF0, 0x7F80, 0x7F00, 0x7EF0, 0x7EF0, 0x7F00, 0x7F70, + 0x7F20, 0x7ED0, 0x7EB0, 0x7EE0, 0x7F50, 0x7F10, 0x7E70, 0x7ED0, 0x7ED0, 0x7F30, 0x7F20, 0x7EC0, 0x7ED0, 0x7EE0, 0x7F10, 0x7F10, + 0x7E90, 0x7EB0, 0x7F00, 0x7F10, 0x7F20, 0x7F00, 0x7EF0, 0x7F20, 0x7F20, 0x7F20, 0x7F00, 0x7F30, 0x7F20, 0x7F20, 0x7EF0, 0x7EE0, + 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F60, + 0x7EF0, 0x7F00, 0x7F00, 0x7F10, 0x7F30, 0x7EE0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F30, 0x7ED0, 0x7EB0, 0x7F00, 0x7F00, 0x7F40, 0x7F10, + 0x7E00, 0x6EE0, 0x5E70, 0x4C30, 0x3BC0, 0x2A90, 0x1AD0, 0x0C00, 0xFDC0, 0xF090, 0xE300, 0xD590, 0xC750, 0xB980, 0xACE0, 0xA110, + 0x9730, 0x8F50, 0x8A50, 0x8800, 0x8720, 0x86E0, 0x8710, 0x8790, 0x8860, 0x89A0, 0x8B10, 0x8D40, 0x9030, 0x9460, 0x9930, 0x9CF0, + 0xA100, 0xA460, 0xA700, 0xA990, 0xAC70, 0xAF40, 0xB1C0, 0xB410, 0xB540, 0xB630, 0xB770, 0xB830, 0xB8C0, 0xB980, 0xBA50, 0xBB00, + 0xBAB0, 0xBAC0, 0xBA80, 0xBAC0, 0xBB40, 0xBB80, 0xBC20, 0xBB80, 0xBAE0, 0xBB40, 0xBC40, 0xBDE0, 0xBFB0, 0xC200, 0xC4E0, 0xC770, + 0xCA80, 0xCDB0, 0xD180, 0xD5E0, 0xDA20, 0xDE40, 0xE340, 0xE830, 0xEE00, 0xF3F0, 0xF9D0, 0xFF90, 0x0370, 0x07A0, 0x0B50, 0x0F30, + 0x1320, 0x1660, 0x1990, 0x1D30, 0x2070, 0x2390, 0x2670, 0x2980, 0x2C00, 0x2DF0, 0x30A0, 0x3260, 0x3440, 0x3710, 0x3830, 0x3A80, + 0x3B50, 0x3AF0, 0x3930, 0x3660, 0x32D0, 0x2F00, 0x2A60, 0x24F0, 0x1ED0, 0x1840, 0x1140, 0x0A10, 0x03F0, 0xFDE0, 0xF840, 0xF120, + 0xEA90, 0xE440, 0xDE80, 0xDB10, 0xD860, 0xD840, 0xD990, 0xDC70, 0xE0E0, 0xE680, 0xED30, 0xF520, 0xFD40, 0x06C0, 0x0FD0, 0x18F0, + 0x2340, 0x2E30, 0x38E0, 0x4440, 0x4F40, 0x5A50, 0x63B0, 0x6D20, 0x7550, 0x7C10, 0x7EE0, 0x7EC0, 0x7ED0, 0x7EE0, 0x7F20, 0x7F10, + 0x7E90, 0x7EB0, 0x7F00, 0x7F10, 0x7F10, 0x7E70, 0x7EE0, 0x7F10, 0x7F20, 0x7EA0, 0x7A80, 0x7600, 0x6F60, 0x6880, 0x6180, 0x59A0, + 0x5220, 0x4B70, 0x44D0, 0x3F50, 0x3960, 0x3380, 0x2ED0, 0x2AA0, 0x2840, 0x2510, 0x2270, 0x1FA0, 0x1C00, 0x1880, 0x1330, 0x0E50, + 0x0990, 0x06D0, 0x05E0, 0x0780, 0x0BB0, 0x11B0, 0x1900, 0x20F0, 0x27B0, 0x2CF0, 0x3160, 0x34B0, 0x3890, 0x3C00, 0x3F60, 0x4310, + 0x44A0, 0x4550, 0x4360, 0x3FA0, 0x3AF0, 0x35D0, 0x3040, 0x2B90, 0x2880, 0x2560, 0x22C0, 0x20D0, 0x1F30, 0x1E30, 0x1E80, 0x2030, + 0x2200, 0x2470, 0x2650, 0x2840, 0x29C0, 0x2B00, 0x2B80, 0x2BF0, 0x2BC0, 0x2AD0, 0x2980, 0x2870, 0x2700, 0x25B0, 0x2450, 0x2310, + 0x2230, 0x2160, 0x20E0, 0x2140, 0x2220, 0x2340, 0x2490, 0x25E0, 0x27A0, 0x2970, 0x2BB0, 0x2D40, 0x2F90, 0x3190, 0x3380, 0x35E0, + 0x3800, 0x3A80, 0x3C70, 0x3E90, 0x3FF0, 0x4130, 0x42B0, 0x4480, 0x4680, 0x4890, 0x4A20, 0x4AF0, 0x4B10, 0x4B50, 0x4B20, 0x4B80, + 0x4BF0, 0x4CB0, 0x4D70, 0x4D80, 0x4CD0, 0x4C70, 0x4C80, 0x4C80, 0x4CD0, 0x4C40, 0x4B40, 0x4910, 0x4680, 0x43B0, 0x4150, 0x3EB0, + 0x3C10, 0x3940, 0x3640, 0x32F0, 0x2F30, 0x2B30, 0x27D0, 0x24B0, 0x21A0, 0x1EA0, 0x1C10, 0x1A30, 0x1870, 0x1730, 0x1650, 0x1490, + 0x1270, 0x0F70, 0x0C70, 0x09E0, 0x0760, 0x05D0, 0x03F0, 0x0230, 0xFF20, 0xFC40, 0xF9F0, 0xF730, 0xF580, 0xF390, 0xF180, 0xEF20, + 0xEC20, 0xE9C0, 0xE7A0, 0xE4C0, 0xE230, 0xDE90, 0xDB00, 0xD860, 0xD680, 0xD530, 0xD510, 0xD470, 0xD340, 0xD210, 0xD130, 0xD090, + 0xD0C0, 0xD270, 0xD4A0, 0xD7C0, 0xDB80, 0xDEF0, 0xE140, 0xE3C0, 0xE5F0, 0xE7A0, 0xE870, 0xE8F0, 0xE8B0, 0xE7C0, 0xE800, 0xE890, + 0xE990, 0xEBB0, 0xEDC0, 0xF030, 0xF250, 0xF440, 0xF6D0, 0xF900, 0xFB20, 0xFC80, 0xFD60, 0xFE80, 0xFFF0, 0x0160, 0x02C0, 0x0300, + 0x0230, 0xFFA0, 0xFC10, 0xF7F0, 0xF480, 0xF140, 0xED70, 0xEA30, 0xE6A0, 0xE2C0, 0xDDB0, 0xD910, 0xD4F0, 0xD0A0, 0xCC90, 0xC8F0, + 0xC5E0, 0xC2F0, 0xC0B0, 0xBEA0, 0xBD50, 0xBC20, 0xBA40, 0xB920, 0xB7C0, 0xB780, 0xB850, 0xB880, 0xB8C0, 0xB880, 0xB7C0, 0xB6C0, + 0xB590, 0xB580, 0xB570, 0xB560, 0xB5B0, 0xB520, 0xB4F0, 0xB460, 0xB450, 0xB590, 0xB630, 0xB820, 0xB890, 0xB960, 0xBAA0, 0xBC50, + 0xBEB0, 0xC180, 0xC4C0, 0xC700, 0xC950, 0xCBD0, 0xCDC0, 0xCF30, 0xD100, 0xD1F0, 0xD220, 0xD1B0, 0xD090, 0xCFF0, 0xCF90, 0xD060, + 0xD0E0, 0xD190, 0xD280, 0xD320, 0xD400, 0xD560, 0xD710, 0xDAC0, 0xDE50, 0xE3C0, 0xE9B0, 0xF0E0, 0xF9C0, 0x0340, 0x0DA0, 0x1960, + 0x2600, 0x32B0, 0x3E80, 0x49C0, 0x53D0, 0x5B90, 0x61F0, 0x65C0, 0x6750, 0x6860, 0x6920, 0x6AD0, 0x6BF0, 0x6DC0, 0x6FE0, 0x7150, + 0x73F0, 0x7720, 0x7B90, 0x7EB0, 0x7F00, 0x7EE0, 0x7ED0, 0x7F70, 0x7F20, 0x7EC0, 0x7ED0, 0x7F00, 0x7F60, 0x7F10, 0x7EB0, 0x7EB0, + 0x7EC0, 0x7EF0, 0x7F10, 0x7EA0, 0x7F20, 0x7F10, 0x7F30, 0x7EE0, 0x7EA0, 0x7EF0, 0x7F00, 0x78C0, 0x7080, 0x6710, 0x5CB0, 0x5190, + 0x44E0, 0x3890, 0x2B30, 0x1EB0, 0x1280, 0x06F0, 0xFC90, 0xF390, 0xED60, 0xE8F0, 0xE600, 0xE520, 0xE560, 0xE650, 0xE780, 0xE8A0, + 0xEA50, 0xEB10, 0xECB0, 0xEEF0, 0xF180, 0xF470, 0xF670, 0xF8E0, 0xFBF0, 0xFF00, 0x02A0, 0x05D0, 0x0A10, 0x0DD0, 0x10A0, 0x1320, + 0x14B0, 0x1520, 0x1510, 0x1340, 0x1150, 0x0EA0, 0x0A70, 0x0630, 0x00F0, 0xFAE0, 0xF360, 0xE830, 0xDC40, 0xCE30, 0xC080, 0xB3B0, + 0xA830, 0x9EF0, 0x97B0, 0x9410, 0x93E0, 0x9690, 0x9C00, 0xA280, 0xA8E0, 0xAE50, 0xB160, 0xB2F0, 0xB220, 0xB030, 0xAD20, 0xA890, + 0xA250, 0x99F0, 0x8F70, 0x8840, 0x8590, 0x8500, 0x84D0, 0x84B0, 0x84A0, 0x8490, 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8450, + 0x8450, 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, + 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8440, 0x8450, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, + 0x8460, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, + 0x8470, 0x8470, 0x8470, 0x84A0, 0x8470, 0x8470, 0x84B0, 0x84B0, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x8480, + 0x8490, 0x8490, 0x8490, 0x8490, 0x84C0, 0x8490, 0x8490, 0x8490, 0x84A0, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, + 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84D0, 0x84A0, 0x84A0, 0x84B0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84A0, 0x84B0, 0x84B0, + 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84D0, 0x84B0, 0x84B0, + 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84B0, + 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84E0, 0x84C0, 0x84C0, 0x84F0, 0x84F0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, + 0x84C0, 0x84C0, 0x84B0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84E0, 0x84D0, 0x84F0, 0x8510, 0x8550, 0x8590, 0x8630, 0x8780, 0x89D0, + 0x8E30, 0x9460, 0x9C00, 0xA330, 0xAAD0, 0xB320, 0xBB50, 0xC270, 0xC9B0, 0xD030, 0xD680, 0xDCB0, 0xE300, 0xE9C0, 0xEF80, 0xF710, + 0xFEC0, 0x0630, 0x0DD0, 0x1480, 0x1B20, 0x21D0, 0x2880, 0x3090, 0x39C0, 0x4240, 0x4B00, 0x52A0, 0x5A10, 0x6010, 0x6670, 0x6C70, + 0x71F0, 0x7870, 0x7CE0, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F90, 0x7EF0, 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7ED0, + 0x7F10, 0x7F20, 0x7F50, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7E90, 0x7F10, 0x7F10, 0x7EF0, 0x7EF0, 0x7EB0, 0x7F20, + 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7F00, 0x7F00, 0x7F10, 0x7F00, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F50, 0x7F10, + 0x7F10, 0x7F20, 0x7EF0, 0x7F90, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F70, 0x7F00, 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, 0x7EF0, 0x7EB0, + 0x7EE0, 0x7ED0, 0x7F70, 0x7F20, 0x7EC0, 0x7ED0, 0x7EB0, 0x7F00, 0x7F00, 0x7E90, 0x7EB0, 0x7EC0, 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, + 0x7F10, 0x7F10, 0x7F00, 0x7E90, 0x7F00, 0x7F00, 0x7EF0, 0x7EF0, 0x7F00, 0x7F40, 0x7F20, 0x7F10, 0x7F20, 0x7F00, 0x7F50, 0x7F10, + 0x7F20, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7320, + 0x6620, 0x58D0, 0x4D30, 0x4270, 0x38C0, 0x2FF0, 0x26B0, 0x1D80, 0x1400, 0x0AD0, 0x0330, 0xFCC0, 0xF690, 0xF1B0, 0xEDD0, 0xE9D0, + 0xE550, 0xE060, 0xDB30, 0xD6C0, 0xD2F0, 0xD110, 0xD110, 0xD250, 0xD3A0, 0xD4E0, 0xD4C0, 0xD3E0, 0xD3A0, 0xD4C0, 0xD870, 0xDEF0, + 0xE560, 0xEA70, 0xEC00, 0xE9F0, 0xE440, 0xDD50, 0xD630, 0xD110, 0xCED0, 0xCF30, 0xD1B0, 0xD680, 0xDDE0, 0xE940, 0xF850, 0x0A70, + 0x1D60, 0x30B0, 0x3E50, 0x4620, 0x4840, 0x4650, 0x4130, 0x3BE0, 0x3760, 0x3450, 0x32A0, 0x3210, 0x3040, 0x2D80, 0x28A0, 0x21A0, + 0x18F0, 0x0F10, 0x0550, 0xFCC0, 0xF6B0, 0xF130, 0xEC40, 0xE6C0, 0xE010, 0xD920, 0xD270, 0xCC00, 0xC730, 0xC460, 0xC3A0, 0xC4D0, + 0xC7F0, 0xCC10, 0xD180, 0xD750, 0xDCD0, 0xE210, 0xE6B0, 0xEAD0, 0xEFB0, 0xF5E0, 0xFD20, 0x0410, 0x0AE0, 0x0FB0, 0x1330, 0x1490, + 0x1360, 0x0F20, 0x08F0, 0x00C0, 0xF700, 0xEDA0, 0xE5A0, 0xDEC0, 0xDA00, 0xD670, 0xD310, 0xD070, 0xCE20, 0xCB70, 0xC990, 0xC890, + 0xC7A0, 0xC750, 0xC650, 0xC5B0, 0xC500, 0xC4D0, 0xC4F0, 0xC500, 0xC580, 0xC580, 0xC620, 0xC720, 0xC820, 0xC9F0, 0xCC00, 0xCE60, + 0xD150, 0xD2E0, 0xD510, 0xD640, 0xD650, 0xD670, 0xD560, 0xD2A0, 0xCE80, 0xC800, 0xBFE0, 0xB550, 0xAAC0, 0xA050, 0x9580, 0x8C90, + 0x87E0, 0x8600, 0x8560, 0x8520, 0x8500, 0x84F0, 0x84F0, 0x84E0, 0x84F0, 0x84D0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, + 0x84A0, 0x84A0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84B0, + 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8490, 0x8480, 0x84B0, 0x8480, 0x8480, 0x8480, 0x8470, 0x8470, 0x8470, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8490, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, + 0x8470, 0x8470, 0x8470, 0x8470, 0x84A0, 0x8470, 0x8470, 0x8480, 0x8470, 0x8470, 0x8470, 0x8490, 0x8480, 0x8470, 0x8480, 0x8490, + 0x8480, 0x8480, 0x84B0, 0x8490, 0x8480, 0x8480, 0x8410, 0x8480, 0x8480, 0x8490, 0x8490, 0x8480, 0x8490, 0x8460, 0x8490, 0x8480, + 0x84A0, 0x8490, 0x8490, 0x8490, 0x84A0, 0x8490, 0x8490, 0x84A0, 0x8440, 0x84A0, 0x84A0, 0x84D0, 0x84A0, 0x84A0, 0x84A0, 0x84E0, + 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84B0, 0x84A0, 0x84A0, 0x84B0, 0x8450, 0x84B0, 0x84B0, + 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84D0, + 0x84D0, 0x84D0, 0x84E0, 0x84E0, 0x84F0, 0x8500, 0x84E0, 0x8530, 0x8540, 0x8570, 0x85B0, 0x8610, 0x86F0, 0x8890, 0x8C10, 0x9300, + 0x9A20, 0xA190, 0xAA10, 0xB2F0, 0xBCE0, 0xC760, 0xD300, 0xDF70, 0xEE40, 0xFD40, 0x0B90, 0x18B0, 0x2300, 0x29E0, 0x2CF0, 0x2CB0, + 0x2C60, 0x2B00, 0x2BD0, 0x37E0, 0x3A70, 0x3CD0, 0x3D60, 0x3CE0, 0x3AD0, 0x38B0, 0x3A00, 0x4070, 0x5010, 0x63B0, 0x74C0, 0x7D50, + 0x7D70, 0x7470, 0x5FF0, 0x4380, 0x2730, 0x0B90, 0xF200, 0xDA60, 0xC240, 0xAB30, 0x93E0, 0x8720, 0x8500, 0x84C0, 0x8460, 0x8450, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8430, 0x8440, 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8460, 0x8470, + 0x8480, 0x84A0, 0x84E0, 0x8540, 0x8730, 0x90F0, 0xA020, 0xAD80, 0xBA30, 0xC670, 0xD0B0, 0xD9F0, 0xDF10, 0xE050, 0xE010, 0xDDA0, + 0xDA90, 0xD7B0, 0xD4C0, 0xD180, 0xCCA0, 0xC650, 0xBE00, 0xB4D0, 0xAA00, 0x9D30, 0x8FB0, 0x8730, 0x8520, 0x84D0, 0x84A0, 0x8480, + 0x8470, 0x8460, 0x8450, 0x8440, 0x8430, 0x8420, 0x8410, 0x8410, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, + 0x8400, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83E0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, + 0x83C0, 0x83D0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83C0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, + 0x8410, 0x8410, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8430, 0x8420, 0x8420, 0x8420, 0x8450, 0x8430, 0x8430, + 0x8430, 0x8450, 0x8440, 0x8450, 0x8410, 0x8450, 0x8460, 0x8480, 0x8470, 0x8480, 0x8490, 0x84C0, 0x84F0, 0x85C0, 0x9040, 0xAD20, + 0xCAB0, 0xE560, 0xFEC0, 0x1780, 0x2E50, 0x4530, 0x5A40, 0x6D40, 0x7C90, 0x7F00, 0x7F10, 0x7F00, 0x7F30, 0x7F00, 0x7F40, 0x7F10, + 0x7F00, 0x7F60, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7F90, 0x7F10, 0x7F20, 0x7F00, 0x7EF0, 0x7F70, 0x7F00, 0x7F10, 0x7EF0, 0x7EE0, + 0x7F60, 0x7F10, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F70, 0x7F20, 0x7EC0, 0x7ED0, 0x7EB0, 0x7F00, 0x7EF0, 0x7E90, 0x7EB0, 0x7EE0, 0x7F10, + 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F00, 0x7F00, 0x7F00, 0x7EF0, 0x7F00, 0x7F40, 0x7F20, 0x7F10, 0x7F20, + 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F50, 0x7860, 0x6CD0, 0x6210, 0x55B0, 0x4820, 0x3AD0, 0x2DB0, 0x2250, 0x18C0, + 0x11D0, 0x0DF0, 0x0D20, 0x0F10, 0x13F0, 0x1AB0, 0x2300, 0x2B90, 0x3570, 0x3F60, 0x48B0, 0x5250, 0x5C00, 0x66C0, 0x70D0, 0x7A90, + 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7EB0, 0x7F10, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F40, + 0x7F10, 0x7F80, 0x7F00, 0x7F20, 0x7EF0, 0x7F00, 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7F00, 0x7F80, 0x7F10, 0x7EF0, 0x7F10, 0x7EF0, + 0x7F30, 0x7F00, 0x7EE0, 0x7ED0, 0x7EF0, 0x7F20, 0x7F10, 0x7F00, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, + 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, + 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, + 0x7F10, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F00, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7EF0, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F00, + 0x7F20, 0x7F40, 0x7F30, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, + 0x7F20, 0x7F30, 0x7F30, 0x7F40, 0x7F20, 0x7F30, 0x7F20, 0x7F40, 0x7F50, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F40, + 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F20, + 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, + 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7980, + 0x6EC0, 0x61F0, 0x5490, 0x4880, 0x3E20, 0x34F0, 0x2D90, 0x28A0, 0x2420, 0x1F10, 0x1980, 0x12A0, 0x0B80, 0x0470, 0xFDA0, 0xF850, + 0xF450, 0xF0D0, 0xECD0, 0xE8E0, 0xE3D0, 0xDEB0, 0xDA60, 0xD510, 0xD100, 0xCD50, 0xC9E0, 0xC7B0, 0xC5D0, 0xC5F0, 0xC730, 0xC9C0, + 0xCE10, 0xD210, 0xD5A0, 0xD990, 0xDD40, 0xE0B0, 0xE420, 0xE780, 0xEB10, 0xEF20, 0xF280, 0xF580, 0xF7B0, 0xF8A0, 0xF8E0, 0xF6D0, + 0xF3F0, 0xF1E0, 0xEF80, 0xEDD0, 0xEBC0, 0xE940, 0xE640, 0xE370, 0xDFD0, 0xDD10, 0xDA40, 0xD8A0, 0xD730, 0xD620, 0xD560, 0xD510, + 0xD500, 0xD600, 0xD800, 0xDB10, 0xDDF0, 0xE0F0, 0xE3E0, 0xE6A0, 0xEA10, 0xED20, 0xF080, 0xF3F0, 0xF740, 0xFA10, 0xFDA0, 0x01E0, + 0x0610, 0x0AB0, 0x0E60, 0x10F0, 0x13D0, 0x15B0, 0x1870, 0x1AD0, 0x1D20, 0x1FA0, 0x20A0, 0x2190, 0x21B0, 0x21B0, 0x2160, 0x2030, + 0x1FB0, 0x1F40, 0x1D40, 0x1C70, 0x1B60, 0x1AC0, 0x1A30, 0x1930, 0x1860, 0x1730, 0x15E0, 0x1520, 0x14A0, 0x14F0, 0x1550, 0x15E0, + 0x1610, 0x1600, 0x1770, 0x18A0, 0x1A50, 0x1D50, 0x2030, 0x2320, 0x25B0, 0x27B0, 0x2A40, 0x2C70, 0x2F90, 0x3370, 0x3650, 0x39D0, + 0x3CD0, 0x4030, 0x4340, 0x4630, 0x4970, 0x4C00, 0x4EF0, 0x50D0, 0x5220, 0x5440, 0x55C0, 0x5730, 0x57C0, 0x5770, 0x57B0, 0x5700, + 0x5720, 0x5780, 0x5710, 0x5780, 0x5780, 0x5730, 0x56C0, 0x5680, 0x5780, 0x5890, 0x59B0, 0x5A40, 0x5A50, 0x5A90, 0x5A60, 0x5A50, + 0x5AB0, 0x5A60, 0x5B40, 0x5B90, 0x5B30, 0x5B70, 0x5B70, 0x5DB0, 0x5F60, 0x60E0, 0x6280, 0x6390, 0x6520, 0x6700, 0x68D0, 0x6B90, + 0x6DE0, 0x7090, 0x7290, 0x7470, 0x7760, 0x7950, 0x7BD0, 0x7E20, 0x7F00, 0x7F10, 0x7EA0, 0x7EE0, 0x7F10, 0x7F10, 0x7F10, 0x7EA0, + 0x7EF0, 0x7F10, 0x7F00, 0x7EF0, 0x7EC0, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7F50, + 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F60, 0x7F10, 0x7F10, 0x7F00, 0x7EE0, 0x7F70, 0x7EF0, 0x7EF0, 0x7F20, 0x7F10, 0x7F80, 0x7F00, + 0x7ED0, 0x7F10, 0x7F00, 0x7F30, 0x7ED0, 0x7E90, 0x7EE0, 0x7EF0, 0x7F30, 0x7F00, 0x7EA0, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7E90, + 0x7F00, 0x7EF0, 0x7EF0, 0x7F20, 0x7F50, 0x7ED0, 0x7EB0, 0x7F00, 0x7EF0, 0x7EF0, 0x7F10, 0x7EA0, 0x7F20, 0x7F00, 0x7F00, 0x7F10, + 0x7F00, 0x7F30, 0x7F00, 0x7F40, 0x7F10, 0x7F00, 0x7F60, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7F90, 0x7F10, 0x7F20, 0x7F00, 0x7F10, + 0x7F70, 0x7F10, 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, 0x7F10, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F70, 0x7F20, 0x7EC0, 0x7ED0, 0x7EB0, 0x7F00, + 0x7EF0, 0x7E90, 0x7EF0, 0x7EE0, 0x7F50, 0x7F00, 0x7440, 0x3C80, 0x0310, 0xC930, 0x90A0, 0x84F0, 0x84A0, 0x8480, 0x8470, 0x8470, + 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x84A0, 0x8470, + 0x8470, 0x8470, 0x8460, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84E0, 0x84F0, 0x8550, 0x8720, 0x92F0, 0xA780, 0xB6C0, + 0xC2F0, 0xCA30, 0xCE00, 0xCC70, 0xC790, 0xC030, 0xB690, 0xAB30, 0x9F80, 0x9470, 0x8BC0, 0x8750, 0x85D0, 0x8540, 0x8500, 0x84E0, + 0x84B0, 0x84A0, 0x8480, 0x8480, 0x8470, 0x8470, 0x8450, 0x8460, 0x8450, 0x8450, 0x8440, 0x8410, 0x8440, 0x8430, 0x8430, 0x8430, + 0x8420, 0x8430, 0x8420, 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, + 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8450, 0x8460, 0x8460, + 0x8470, 0x8470, 0x8480, 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84D0, 0x84F0, 0x8520, 0x8560, 0x8600, 0x8740, 0x8A70, 0x9170, 0x9A40, + 0xA170, 0xA890, 0xAD80, 0xB1E0, 0xB450, 0xB5E0, 0xB560, 0xB360, 0xB050, 0xAD90, 0xAB80, 0xACC0, 0xB160, 0xB9A0, 0xC3D0, 0xCF10, + 0xD8B0, 0xDF10, 0xE300, 0xE4E0, 0xE640, 0xE7D0, 0xEA60, 0xEF40, 0xF460, 0xFA90, 0x0240, 0x0800, 0x0DD0, 0x1280, 0x1660, 0x1980, + 0x1C70, 0x2080, 0x2460, 0x2890, 0x2D30, 0x3260, 0x3840, 0x3E10, 0x4370, 0x48E0, 0x4CE0, 0x50B0, 0x5400, 0x55F0, 0x5850, 0x5A00, + 0x5C00, 0x5DC0, 0x5E10, 0x5F10, 0x5E40, 0x5B90, 0x5830, 0x52A0, 0x4B60, 0x4290, 0x38A0, 0x2D20, 0x2050, 0x13B0, 0x0500, 0xF6C0, + 0xE8B0, 0xDAA0, 0xCD70, 0xC0A0, 0xB480, 0xA9D0, 0xA090, 0x9910, 0x9470, 0x91F0, 0x9180, 0x91E0, 0x9440, 0x9770, 0x9BC0, 0xA110, + 0xA6F0, 0xAD40, 0xB410, 0xB9F0, 0xC0E0, 0xC780, 0xCE10, 0xD3F0, 0xD8B0, 0xDD70, 0xE150, 0xE5A0, 0xE940, 0xEC70, 0xF030, 0xF280, + 0xF540, 0xF850, 0xFB70, 0xFEE0, 0x0280, 0x05B0, 0x0940, 0x0CD0, 0x1200, 0x15E0, 0x1950, 0x1CB0, 0x20D0, 0x2500, 0x2940, 0x2DD0, + 0x3200, 0x3640, 0x3A70, 0x3F30, 0x4360, 0x4800, 0x4D50, 0x52F0, 0x5860, 0x5D70, 0x6240, 0x6720, 0x6BE0, 0x7060, 0x7530, 0x79A0, + 0x7CE0, 0x7ED0, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F40, + 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F30, + 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7EF0, 0x7F30, + 0x7F20, 0x7F10, 0x7F30, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, + 0x7F40, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F40, 0x7F30, 0x7F20, 0x7A60, 0x73F0, 0x6DA0, 0x6800, 0x61D0, + 0x5BB0, 0x5670, 0x5160, 0x4D40, 0x4A00, 0x46A0, 0x4370, 0x40B0, 0x3DD0, 0x3B60, 0x38A0, 0x3610, 0x33B0, 0x31B0, 0x2F70, 0x2C90, + 0x29B0, 0x2660, 0x22E0, 0x1F50, 0x1B70, 0x1760, 0x13E0, 0x0FB0, 0x0BE0, 0x0900, 0x0570, 0x01B0, 0xFE00, 0xFAA0, 0xF690, 0xF3F0, + 0xF0E0, 0xEE90, 0xEBF0, 0xE870, 0xE470, 0xE040, 0xDC50, 0xD830, 0xD4A0, 0xD130, 0xCEE0, 0xCBD0, 0xC8C0, 0xC5B0, 0xC280, 0xBF90, + 0xBD50, 0xBA50, 0xB7B0, 0xB500, 0xB220, 0xAF60, 0xABE0, 0xA920, 0xA590, 0xA240, 0x9EC0, 0x9A50, 0x96D0, 0x92A0, 0x8ED0, 0x8B60, + 0x88F0, 0x8770, 0x8690, 0x8600, 0x85B0, 0x8580, 0x8550, 0x8530, 0x8520, 0x8520, 0x8510, 0x8510, 0x8520, 0x8520, 0x8530, 0x8530, + 0x8530, 0x8540, 0x8550, 0x8550, 0x8560, 0x8570, 0x8570, 0x8570, 0x8580, 0x8570, 0x8580, 0x8590, 0x85B0, 0x85D0, 0x85F0, 0x8610, + 0x8630, 0x8640, 0x8670, 0x8670, 0x8680, 0x86C0, 0x86F0, 0x8720, 0x8740, 0x8760, 0x87B0, 0x87C0, 0x87F0, 0x8810, 0x8850, 0x8890, + 0x88D0, 0x8980, 0x8A10, 0x8AF0, 0x8BF0, 0x8D20, 0x8F10, 0x9140, 0x93B0, 0x96F0, 0x9A00, 0x9CF0, 0x9F50, 0xA0F0, 0xA340, 0xA550, + 0xA7A0, 0xA9C0, 0xAC10, 0xAEB0, 0xB040, 0xB2E0, 0xB4A0, 0xB6D0, 0xB8F0, 0xBB90, 0xBE50, 0xC160, 0xC450, 0xC710, 0xC960, 0xCBF0, + 0xCE50, 0xD030, 0xD270, 0xD390, 0xD5D0, 0xD7E0, 0xD990, 0xDBF0, 0xDDA0, 0xDEB0, 0xDFF0, 0xE040, 0xE010, 0xE000, 0xDFD0, 0xE010, + 0xE070, 0xE110, 0xE150, 0xE110, 0xE0C0, 0xE0A0, 0xE090, 0xE0C0, 0xE110, 0xE180, 0xE130, 0xE160, 0xE0E0, 0xE070, 0xDF50, 0xDEC0, + 0xDE50, 0xDE90, 0xDEA0, 0xDF20, 0xDEF0, 0xDF90, 0xE0E0, 0xE250, 0xE480, 0xE720, 0xE8C0, 0xE970, 0xEAB0, 0xEC00, 0xED90, 0xF010, + 0xF300, 0xF670, 0xFBB0, 0x0110, 0x07E0, 0x0DF0, 0x1410, 0x1A80, 0x1F60, 0x22F0, 0x2650, 0x2930, 0x2C40, 0x2F10, 0x31D0, 0x33B0, + 0x3300, 0x3110, 0x2D30, 0x27A0, 0x1FF0, 0x17F0, 0x0F60, 0x0400, 0xF710, 0xE8D0, 0xD810, 0xC500, 0xAE90, 0x9320, 0x8610, 0x84D0, + 0x84A0, 0x8480, 0x8470, 0x8460, 0x8450, 0x8450, 0x8440, 0x8430, 0x8430, 0x8430, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, + 0x8420, 0x8460, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, + 0x8440, 0x8440, 0x8450, 0x8430, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, + 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8490, 0x84A0, 0x84A0, 0x84B0, 0x84C0, 0x84B0, 0x84B0, 0x84D0, 0x84C0, 0x84C0, 0x84C0, + 0x84D0, 0x84E0, 0x84F0, 0x8510, 0x8540, 0x8520, 0x8530, 0x8510, 0x8570, 0x85B0, 0x8630, 0x8690, 0x8740, 0x8860, 0x8A70, 0x8C40, + 0x8DE0, 0x8EF0, 0x8F90, 0x90A0, 0x9280, 0x9560, 0x98A0, 0x9B60, 0x9D70, 0x9F70, 0xA130, 0xA360, 0xA4B0, 0xA5F0, 0xA720, 0xA870, + 0xA9F0, 0xAC80, 0xB0B0, 0xB610, 0xBBD0, 0xC210, 0xC880, 0xCF70, 0xD7A0, 0xDFF0, 0xE9E0, 0xF4A0, 0x01A0, 0x1000, 0x1E20, 0x2D40, + 0x3CF0, 0x4D70, 0x5D00, 0x6AF0, 0x7750, 0x7E80, 0x7EF0, 0x7EF0, 0x7F70, 0x7F20, 0x7ED0, 0x7ED0, 0x7EB0, 0x7F30, 0x7EF0, 0x7EB0, + 0x7EE0, 0x7ED0, 0x7F30, 0x7F20, 0x7EA0, 0x7ED0, 0x7F10, 0x7F10, 0x7F10, 0x7E90, 0x7EB0, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F20, + 0x7F40, 0x7F20, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7EF0, 0x7F70, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F60, 0x7F10, + 0x7F10, 0x7EF0, 0x7EE0, 0x7F30, 0x7EE0, 0x7F00, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7ED0, 0x7EF0, 0x7F00, 0x7F50, 0x7EF0, 0x7EB0, + 0x7EE0, 0x7EF0, 0x7F90, 0x7F20, 0x7F00, 0x7F20, 0x7F00, 0x7F90, 0x7F10, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F70, 0x7F20, 0x7EE0, 0x7EE0, + 0x7ED0, 0x7F30, 0x7F20, 0x7EC0, 0x7ED0, 0x7EB0, 0x7F00, 0x7F10, 0x7E90, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EA0, 0x7E00, 0x5DF0, + 0x3E20, 0x2360, 0x0C00, 0xF7D0, 0xE790, 0xDB20, 0xD3D0, 0xD090, 0xD190, 0xD4C0, 0xD790, 0xD9F0, 0xD890, 0xD360, 0xCA10, 0xBDE0, + 0xB1F0, 0xA550, 0x9A70, 0x92E0, 0x8D50, 0x8980, 0x8770, 0x8640, 0x85B0, 0x8580, 0x8590, 0x8600, 0x8730, 0x8B20, 0x9440, 0x9CE0, + 0xA200, 0xA3D0, 0xA310, 0x9F40, 0x9980, 0x9360, 0x8D30, 0x8950, 0x86F0, 0x85E0, 0x8570, 0x8530, 0x8510, 0x84F0, 0x84E0, 0x84D0, + 0x84D0, 0x84C0, 0x84C0, 0x84B0, 0x84C0, 0x84B0, 0x84C0, 0x84C0, 0x84E0, 0x8510, 0x85E0, 0x8AE0, 0x9D60, 0xB050, 0xC290, 0xD5B0, + 0xE610, 0xF420, 0xFE80, 0x0550, 0x0690, 0x0460, 0xFEE0, 0xF7E0, 0xF2A0, 0xF100, 0xF450, 0xFC10, 0x0730, 0x1420, 0x20E0, 0x2C10, + 0x3480, 0x39F0, 0x3D30, 0x3E70, 0x3F00, 0x3F40, 0x3FB0, 0x4190, 0x42A0, 0x44C0, 0x46B0, 0x4920, 0x4C80, 0x5000, 0x53E0, 0x5800, + 0x5B40, 0x5E00, 0x5F00, 0x5F80, 0x5E50, 0x5A70, 0x5420, 0x49E0, 0x3C50, 0x2C90, 0x1B20, 0x0980, 0xF630, 0xE550, 0xD5C0, 0xC750, + 0xBA70, 0xAFD0, 0xA680, 0x9F20, 0x9920, 0x94C0, 0x9200, 0x90D0, 0x9070, 0x90B0, 0x9200, 0x93C0, 0x95F0, 0x9930, 0x9E10, 0xA4C0, + 0xAD90, 0xB850, 0xC490, 0xD320, 0xE4D0, 0xF620, 0x07C0, 0x19C0, 0x2A30, 0x38A0, 0x4570, 0x4F90, 0x57F0, 0x5F40, 0x6470, 0x68B0, + 0x6C00, 0x6E10, 0x6FB0, 0x7030, 0x7070, 0x7120, 0x7190, 0x7200, 0x7290, 0x7290, 0x7170, 0x6FC0, 0x6DC0, 0x6C30, 0x6B70, 0x6C10, + 0x6E70, 0x72B0, 0x7790, 0x7C20, 0x7EE0, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7C70, 0x7480, 0x6AC0, 0x5F10, 0x5230, 0x44D0, 0x3810, + 0x2B70, 0x1EA0, 0x1390, 0x0890, 0xFDB0, 0xF3E0, 0xEB00, 0xE390, 0xDD30, 0xD790, 0xD1D0, 0xCCB0, 0xC7E0, 0xC2E0, 0xBE70, 0xBA70, + 0xB6B0, 0xB3B0, 0xB110, 0xADF0, 0xAB90, 0xA910, 0xA720, 0xA4F0, 0xA3C0, 0xA230, 0xA250, 0xA3D0, 0xA7E0, 0xAC90, 0xB2F0, 0xB9D0, + 0xC1A0, 0xC910, 0xD140, 0xD930, 0xE140, 0xEA50, 0xF330, 0xFC70, 0x0560, 0x0EC0, 0x1780, 0x1FC0, 0x2790, 0x2F50, 0x3700, 0x3DE0, + 0x44D0, 0x4B50, 0x5160, 0x5600, 0x59C0, 0x5C30, 0x5D80, 0x5E10, 0x5E10, 0x5D50, 0x5B40, 0x58E0, 0x5580, 0x51E0, 0x4DB0, 0x4970, + 0x4470, 0x4030, 0x3CA0, 0x3880, 0x3490, 0x3160, 0x2E20, 0x2B50, 0x2980, 0x27F0, 0x2710, 0x2530, 0x23D0, 0x20E0, 0x1D40, 0x1850, + 0x12D0, 0x0D00, 0x0600, 0xFED0, 0xF780, 0xF060, 0xE940, 0xE190, 0xDAD0, 0xD400, 0xCD50, 0xC660, 0xC0C0, 0xBB80, 0xB6E0, 0xB320, + 0xB070, 0xAD70, 0xAAC0, 0xA830, 0xA630, 0xA4E0, 0xA400, 0xA3E0, 0xA380, 0xA350, 0xA2C0, 0xA300, 0xA310, 0xA370, 0xA4B0, 0xA580, + 0xA5F0, 0xA660, 0xA6C0, 0xA740, 0xA7C0, 0xA820, 0xA8A0, 0xA9A0, 0xAA90, 0xAB50, 0xAC30, 0xACB0, 0xAE40, 0xB020, 0xB1A0, 0xB370, + 0xB590, 0xB7F0, 0xBAE0, 0xBE90, 0xC230, 0xC5A0, 0xC920, 0xCBC0, 0xCF80, 0xD280, 0xD6C0, 0xDAB0, 0xDEF0, 0xE2A0, 0xE5A0, 0xE990, + 0xED00, 0xF140, 0xF530, 0xF870, 0xFB60, 0xFD80, 0xFFD0, 0x0260, 0x04A0, 0x07D0, 0x0B00, 0x0D60, 0x0ED0, 0x0F80, 0x10B0, 0x1160, + 0x1150, 0x1190, 0x1100, 0x1070, 0x0FB0, 0x0F70, 0x0EC0, 0x0E40, 0x0E60, 0x0D60, 0x0CE0, 0x0C50, 0x0B20, 0x0B20, 0x0B90, 0x0BF0, + 0x0C70, 0x0C60, 0x0C80, 0x0D30, 0x0E20, 0x0F90, 0x10A0, 0x1230, 0x1360, 0x13D0, 0x1600, 0x1700, 0x1920, 0x1B30, 0x1CB0, 0x1E40, + 0x1F10, 0x2070, 0x21F0, 0x2420, 0x2790, 0x2A90, 0x2DF0, 0x3010, 0x3330, 0x36E0, 0x3A40, 0x3F40, 0x4580, 0x4B60, 0x5240, 0x5880, + 0x5E80, 0x6440, 0x6910, 0x6FB0, 0x75E0, 0x7BE0, 0x7ED0, 0x7F20, 0x7F00, 0x7EF0, 0x7F90, 0x7F20, 0x7F20, 0x7EF0, 0x7EF0, 0x7F60, + 0x7EE0, 0x7ED0, 0x7EE0, 0x7EE0, 0x7F50, 0x7F10, 0x7EB0, 0x7EE0, 0x7ED0, 0x7F10, 0x7F10, 0x7EC0, 0x7EB0, 0x7EB0, 0x7EF0, 0x7EF0, + 0x7EB0, 0x7F00, 0x7F20, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F00, 0x7ED0, 0x7F30, 0x7F20, 0x7EF0, 0x7F10, 0x7F00, + 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7EE0, 0x7F50, 0x7F20, 0x7F00, 0x7EF0, 0x7F10, 0x7F60, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F50, + 0x7EF0, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F70, 0x7F00, 0x7EC0, 0x7F10, 0x7F20, 0x7F60, 0x7EF0, 0x7EB0, 0x7EF0, 0x7EE0, 0x7EF0, 0x7EF0, + 0x7EB0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7EC0, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7EA0, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7F40, + 0x7F50, 0x7C30, 0x6F70, 0x5F80, 0x4DD0, 0x3A30, 0x2520, 0x1040, 0xFB70, 0xE900, 0xD840, 0xC9F0, 0xBD30, 0xB480, 0xAE20, 0xA930, + 0xA750, 0xA620, 0xA5D0, 0xA4D0, 0xA3B0, 0xA260, 0xA0E0, 0xA080, 0xA0A0, 0xA1E0, 0xA3B0, 0xA6F0, 0xAA90, 0xAFC0, 0xB590, 0xBB30, + 0xC1A0, 0xC740, 0xCD30, 0xD220, 0xD680, 0xD930, 0xDA20, 0xD950, 0xD820, 0xD590, 0xD370, 0xD050, 0xCD90, 0xCBA0, 0xCA40, 0xC900, + 0xCA00, 0xCB70, 0xCDF0, 0xD140, 0xD4B0, 0xD860, 0xDB30, 0xDE00, 0xE160, 0xE5B0, 0xEAD0, 0xEFC0, 0xF560, 0xFB50, 0x0100, 0x0730, + 0x0CC0, 0x1220, 0x1850, 0x1E50, 0x25F0, 0x2D90, 0x37E0, 0x4270, 0x4D50, 0x5990, 0x6520, 0x6F60, 0x7790, 0x7D70, 0x7EF0, 0x7F10, + 0x7F30, 0x7EF0, 0x7EF0, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7C10, 0x6CC0, 0x5B60, 0x47F0, 0x3430, 0x1F70, 0x0BC0, 0xF880, 0xE670, + 0xD660, 0xC5C0, 0xB700, 0xA960, 0x9B50, 0x8EC0, 0x87F0, 0x85B0, 0x8510, 0x84F0, 0x84D0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84A0, + 0x84A0, 0x8490, 0x8490, 0x8470, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x8490, 0x84C0, + 0x84E0, 0x8530, 0x8620, 0x89F0, 0x9440, 0x9D20, 0xA120, 0xA050, 0x9B40, 0x9190, 0x8910, 0x85C0, 0x8500, 0x84D0, 0x84C0, 0x84B0, + 0x8490, 0x84B0, 0x84A0, 0x84B0, 0x84A0, 0x84B0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84D0, 0x84D0, 0x84E0, 0x84E0, 0x84E0, 0x84F0, + 0x8500, 0x8520, 0x8540, 0x8580, 0x85E0, 0x8690, 0x8800, 0x8B90, 0x9410, 0xA290, 0xB290, 0xC3E0, 0xD610, 0xE710, 0xF680, 0x0360, + 0x0CC0, 0x1350, 0x1640, 0x16F0, 0x1490, 0x0FF0, 0x0920, 0x01C0, 0xFA70, 0xF3B0, 0xEDE0, 0xE890, 0xE480, 0xE0A0, 0xDC40, 0xD690, + 0xCFB0, 0xC750, 0xBE00, 0xB2F0, 0xA7C0, 0x9E70, 0x95B0, 0x8E30, 0x8980, 0x8700, 0x85E0, 0x8550, 0x8510, 0x84F0, 0x84E0, 0x84D0, + 0x84C0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, + 0x84F0, 0x8500, 0x8510, 0x8510, 0x8520, 0x8540, 0x8550, 0x8580, 0x85A0, 0x85C0, 0x85A0, 0x8560, 0x8520, 0x84F0, 0x84C0, 0x84B0, + 0x8490, 0x8480, 0x8470, 0x8460, 0x8450, 0x8440, 0x8430, 0x8430, 0x8420, 0x8460, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8400, 0x8410, 0x8410, 0x8400, 0x8410, 0x8410, 0x8420, 0x8470, 0x8420, 0x83F0, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8460, 0x8460, 0x8470, 0x84C0, 0x8480, 0x8490, + 0x8480, 0x84A0, 0x84B0, 0x84C0, 0x84D0, 0x84F0, 0x8510, 0x8590, 0x86E0, 0x8B70, 0x9610, 0xA0B0, 0xADF0, 0xB8A0, 0xC300, 0xCE20, + 0xDAB0, 0xE990, 0xF9D0, 0x0AC0, 0x1C10, 0x2C30, 0x3A60, 0x4410, 0x4AB0, 0x4F40, 0x5220, 0x5480, 0x56F0, 0x5A30, 0x5DA0, 0x6090, + 0x62B0, 0x63A0, 0x63D0, 0x62F0, 0x6280, 0x6320, 0x6560, 0x6A50, 0x7160, 0x79C0, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, + 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7D00, 0x7540, 0x6E50, 0x6830, 0x63E0, + 0x61D0, 0x61D0, 0x63C0, 0x67B0, 0x6AB0, 0x6D50, 0x6EA0, 0x6C70, 0x6570, 0x5920, 0x4780, 0x3480, 0x20A0, 0x1180, 0x05E0, 0xFE00, + 0xF890, 0xF520, 0xF200, 0xEE10, 0xEA10, 0xE710, 0xE670, 0xE890, 0xEE40, 0xF880, 0x06F0, 0x1870, 0x2B20, 0x3E20, 0x51B0, 0x6230, + 0x7040, 0x7B90, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F50, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, + 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F40, + 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7840, 0x68F0, 0x5730, 0x4330, 0x3000, 0x1EC0, 0x0FF0, 0x0800, 0x0440, 0x03F0, 0x0530, + 0x06A0, 0x08E0, 0x0C90, 0x12F0, 0x1EA0, 0x2DB0, 0x3EB0, 0x4D20, 0x5640, 0x57D0, 0x5310, 0x4AB0, 0x42C0, 0x3DB0, 0x3CF0, 0x40A0, + 0x46D0, 0x4D80, 0x5420, 0x59A0, 0x5EE0, 0x6330, 0x67A0, 0x6A80, 0x6D70, 0x7010, 0x71F0, 0x73C0, 0x74B0, 0x7530, 0x7520, 0x74D0, + 0x7370, 0x72A0, 0x7340, 0x7580, 0x7850, 0x7BE0, 0x7E40, 0x7F10, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, + 0x7F30, 0x7F70, 0x7F10, 0x7E90, 0x7F20, 0x7F20, 0x7EF0, 0x7EF0, 0x7EA0, 0x7F40, 0x7F10, 0x7F00, 0x7EC0, 0x7E90, 0x7EB0, 0x7EB0, + 0x7F00, 0x7EF0, 0x7F00, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F00, 0x7F00, 0x7F20, 0x7EE0, 0x7F10, + 0x7D30, 0x6D60, 0x5DF0, 0x4DC0, 0x3C90, 0x2A50, 0x1940, 0x08B0, 0xFB90, 0xF0F0, 0xEB50, 0xE9C0, 0xEBC0, 0xF100, 0xF7B0, 0xFD60, + 0x01A0, 0x03F0, 0x0710, 0x09C0, 0x0DC0, 0x1250, 0x1630, 0x1A60, 0x1C30, 0x1DE0, 0x1F00, 0x2090, 0x2550, 0x2BB0, 0x3520, 0x4060, + 0x4C70, 0x56A0, 0x5B60, 0x5990, 0x4DB0, 0x37E0, 0x1BD0, 0xFD30, 0xE170, 0xCAD0, 0xBD10, 0xB630, 0xB300, 0xB1A0, 0xB110, 0xB0B0, + 0xB060, 0xB150, 0xB450, 0xB820, 0xBD40, 0xC2D0, 0xC8B0, 0xCE30, 0xD340, 0xD580, 0xD770, 0xD800, 0xD7F0, 0xD850, 0xDA10, 0xDCA0, + 0xE050, 0xE4F0, 0xE970, 0xECD0, 0xF060, 0xF270, 0xF450, 0xF690, 0xF8B0, 0xFCA0, 0xFF40, 0x0230, 0x05B0, 0x0810, 0x0A30, 0x0AB0, + 0x0A40, 0x0A40, 0x0910, 0x08A0, 0x08C0, 0x0840, 0x0980, 0x0A00, 0x0B10, 0x0B80, 0x0BE0, 0x0CC0, 0x0D40, 0x0D90, 0x0E60, 0x0F50, + 0x1010, 0x1090, 0x1260, 0x13F0, 0x15B0, 0x1850, 0x1A70, 0x1C30, 0x1F70, 0x22A0, 0x2740, 0x2BD0, 0x2FF0, 0x3540, 0x3910, 0x3DF0, + 0x41F0, 0x45D0, 0x4990, 0x4CB0, 0x50E0, 0x53D0, 0x5590, 0x5700, 0x55C0, 0x5430, 0x5070, 0x4A90, 0x4390, 0x3B30, 0x32E0, 0x2A40, + 0x2210, 0x1BF0, 0x1600, 0x11D0, 0x0E90, 0x0C40, 0x0AE0, 0x0A10, 0x09B0, 0x09D0, 0x0870, 0x07B0, 0x0600, 0x03E0, 0x0190, 0xFEC0, + 0xFBC0, 0xF800, 0xF3F0, 0xEF30, 0xE920, 0xE2D0, 0xDCB0, 0xD670, 0xD060, 0xC9D0, 0xC330, 0xBB90, 0xB2C0, 0xA970, 0x9FD0, 0x9800, + 0x9120, 0x8D10, 0x8B30, 0x8A90, 0x8B30, 0x8D30, 0x8FA0, 0x9340, 0x9670, 0x98B0, 0x9530, 0x93C0, 0x9230, 0x90E0, 0x8F90, 0x8E40, + 0x8CD0, 0x8B20, 0x8990, 0x8870, 0x87C0, 0x8760, 0x8710, 0x86E0, 0x86C0, 0x86B0, 0x8690, 0x8680, 0x8670, 0x8670, 0x8670, 0x8670, + 0x8690, 0x86D0, 0x8750, 0x8820, 0x8980, 0x8C30, 0x8FC0, 0x9360, 0x9670, 0x98F0, 0x9AE0, 0x9C20, 0x9E70, 0xA0B0, 0xA3A0, 0xA6D0, + 0xAA30, 0xADE0, 0xB150, 0xB430, 0xB6B0, 0xBA10, 0xBDA0, 0xC250, 0xC750, 0xCCC0, 0xD220, 0xD790, 0xDD00, 0xE240, 0xE8F0, 0xEF30, + 0xF5B0, 0xFD10, 0x02F0, 0x08F0, 0x0F40, 0x1610, 0x1D20, 0x23F0, 0x2BE0, 0x32D0, 0x3A60, 0x4080, 0x4670, 0x4C70, 0x5170, 0x57C0, + 0x5D90, 0x6330, 0x69E0, 0x7030, 0x7620, 0x7BA0, 0x7E90, 0x7F10, 0x7EB0, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F30, 0x7F20, + 0x7F20, 0x7F10, 0x7F10, 0x7F30, 0x7EF0, 0x7F10, 0x7F00, 0x7EE0, 0x7F50, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F90, 0x7F00, 0x7F10, + 0x7F10, 0x7F00, 0x7F60, 0x7EE0, 0x7ED0, 0x7F10, 0x7F20, 0x7F70, 0x7DF0, 0x7AA0, 0x78E0, 0x7790, 0x76B0, 0x7720, 0x7800, 0x7A50, + 0x7CE0, 0x7E90, 0x7ED0, 0x7EB0, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7F10, 0x7F00, 0x7F00, 0x7F10, 0x7F00, 0x7F30, 0x7F20, + 0x7F40, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7F90, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7F10, + 0x7EF0, 0x7EE0, 0x7F60, 0x7EF0, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F70, 0x7F20, 0x7EC0, 0x7ED0, 0x7EB0, 0x7F10, 0x7F10, 0x7E90, 0x7EB0, + 0x7EE0, 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F20, 0x7E60, 0x6E40, 0x5F50, 0x50B0, 0x4120, 0x3380, 0x2680, 0x1A60, 0x0F90, + 0x06B0, 0x0010, 0xFB20, 0xF8F0, 0xF950, 0xFB60, 0x0000, 0x0580, 0x0D30, 0x1500, 0x1D10, 0x2600, 0x2D80, 0x3460, 0x3A10, 0x3EB0, + 0x42A0, 0x4580, 0x47F0, 0x49A0, 0x4B80, 0x4D80, 0x4E80, 0x4EF0, 0x4F80, 0x4F70, 0x4EC0, 0x4BE0, 0x47B0, 0x4290, 0x3CA0, 0x3720, + 0x3080, 0x2930, 0x21B0, 0x18D0, 0x1130, 0x0930, 0x0250, 0xFCD0, 0xF850, 0xF430, 0xF060, 0xEC40, 0xE8E0, 0xE540, 0xE050, 0xDAE0, + 0xD330, 0xCAD0, 0xC1C0, 0xB8D0, 0xB030, 0xA770, 0x9FD0, 0x9880, 0x9210, 0x8D30, 0x89A0, 0x87C0, 0x86A0, 0x8600, 0x85A0, 0x8550, + 0x8520, 0x8500, 0x84F0, 0x84E0, 0x84C0, 0x84C0, 0x84B0, 0x8490, 0x8490, 0x8480, 0x8470, 0x8470, 0x8460, 0x8450, 0x8440, 0x8430, + 0x8430, 0x8420, 0x8410, 0x8400, 0x83F0, 0x83D0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, + 0x83D0, 0x83C0, 0x83C0, 0x83D0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, + 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83C0, + 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, + 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8420, 0x8410, 0x8410, 0x8420, 0x8420, + 0x8410, 0x8430, 0x8430, 0x8450, 0x8430, 0x8440, 0x8450, 0x8460, 0x8470, 0x8480, 0x84B0, 0x8520, 0x8C20, 0xB580, 0xDB30, 0xFF20, + 0x2000, 0x3EC0, 0x5B10, 0x7540, 0x7F20, 0x7EF0, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F40, + 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F40, 0x7F30, + 0x7F30, 0x7F20, 0x7F40, 0x7EF0, 0x6CD0, 0x57F0, 0x4040, 0x2350, 0x0660, 0xE7E0, 0xC930, 0xAB30, 0x9050, 0x8620, 0x84F0, 0x84C0, + 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x84A0, 0x84D0, 0x8530, 0x8B10, 0xB130, + 0xD720, 0xFD70, 0x24E0, 0x46E0, 0x6470, 0x7BB0, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, + 0x7F30, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7EB0, 0x7F20, 0x7EF0, 0x7EF0, 0x7F00, 0x7F00, 0x7F40, 0x7EF0, 0x7F20, 0x7F00, 0x7ED0, + 0x7ED0, 0x7EE0, 0x7F40, 0x7EF0, 0x7F10, 0x7F60, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F40, + 0x7F10, 0x7ED0, 0x7F00, 0x7F00, 0x7F40, 0x7F10, 0x7EB0, 0x7EE0, 0x7F10, 0x7F30, 0x7EC0, 0x7E90, 0x7F10, 0x7F20, 0x7F20, 0x6740, + 0x4E00, 0x32E0, 0x1A10, 0x0050, 0xE860, 0xD1C0, 0xBF40, 0xAF10, 0xA280, 0x9840, 0x8F10, 0x89B0, 0x8730, 0x8610, 0x85A0, 0x8580, + 0x8590, 0x85D0, 0x8670, 0x8810, 0x8B40, 0x90E0, 0x98E0, 0xA1C0, 0xAB30, 0xB520, 0xBE60, 0xC6E0, 0xCFD0, 0xD750, 0xDDC0, 0xE2F0, + 0xE7D0, 0xEBF0, 0xF080, 0xF490, 0xF970, 0x0080, 0x07D0, 0x1250, 0x1E90, 0x2CB0, 0x3B80, 0x4800, 0x50B0, 0x5160, 0x4610, 0x30B0, + 0x0F40, 0xE7A0, 0xBCA0, 0x92C0, 0x8540, 0x84C0, 0x84A0, 0x8490, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, + 0x8480, 0x84A0, 0x84B0, 0x8580, 0x94C0, 0xB5F0, 0xCF30, 0xDFF0, 0xE7D0, 0xE6E0, 0xDF90, 0xD4B0, 0xC960, 0xC170, 0xBF00, 0xC210, + 0xCB50, 0xD960, 0xEC20, 0xFF70, 0x1580, 0x2C90, 0x4550, 0x5F60, 0x7720, 0x7F30, 0x7ED0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F30, 0x7F00, + 0x7EC0, 0x7F10, 0x7F00, 0x7F00, 0x7EF0, 0x7EA0, 0x7EE0, 0x7EF0, 0x62D0, 0x3D80, 0x1500, 0xE850, 0xB7B0, 0x8880, 0x84C0, 0x8480, + 0x8460, 0x8460, 0x8440, 0x8440, 0x8430, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8430, 0x8440, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8460, 0x8470, 0x8480, 0x84A0, 0x84D0, 0x8560, 0x8D30, 0xAD50, + 0xC890, 0xE290, 0xF6F0, 0x06B0, 0x1460, 0x1D40, 0x2450, 0x2990, 0x2C30, 0x2CC0, 0x2A00, 0x2500, 0x1670, 0x1970, 0x1D30, 0x2020, + 0x2360, 0x2450, 0x2590, 0x2600, 0x2640, 0x2840, 0x2A10, 0x2D40, 0x2F90, 0x3230, 0x3500, 0x3800, 0x3B80, 0x3FB0, 0x4370, 0x48A0, + 0x4D50, 0x52A0, 0x56E0, 0x58F0, 0x59B0, 0x5720, 0x52E0, 0x4DD0, 0x49B0, 0x4740, 0x4630, 0x46B0, 0x46E0, 0x4690, 0x46C0, 0x46D0, + 0x4720, 0x4810, 0x4AE0, 0x4E60, 0x5280, 0x5770, 0x5C90, 0x6120, 0x6440, 0x6250, 0x59B0, 0x4910, 0x3390, 0x1BF0, 0x0580, 0xF350, + 0xE710, 0xE020, 0xDEF0, 0xE1A0, 0xE850, 0xF1A0, 0xFB90, 0x06B0, 0x1100, 0x19C0, 0x2190, 0x2880, 0x2FA0, 0x3770, 0x3EB0, 0x4660, + 0x4C40, 0x50D0, 0x54B0, 0x57E0, 0x5D40, 0x6280, 0x67E0, 0x6C80, 0x6FD0, 0x7230, 0x7270, 0x71A0, 0x6FC0, 0x6C80, 0x6920, 0x6410, + 0x5FF0, 0x5C70, 0x58A0, 0x5690, 0x5470, 0x5330, 0x52F0, 0x5340, 0x54B0, 0x5870, 0x5E50, 0x6580, 0x6C20, 0x7300, 0x77C0, 0x7910, + 0x7870, 0x7390, 0x6CB0, 0x6260, 0x54C0, 0x44C0, 0x3190, 0x1C80, 0x0500, 0xEB50, 0xD0A0, 0xB700, 0x9E00, 0x8A40, 0x8550, 0x84E0, + 0x84C0, 0x84A0, 0x8490, 0x8480, 0x8480, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, + 0x8460, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x84A0, 0x84B0, 0x84C0, 0x84D0, 0x8500, 0x8550, 0x8680, 0x8B90, 0x9990, 0xA650, + 0xB160, 0xBA90, 0xC260, 0xC970, 0xD0D0, 0xD8B0, 0xE030, 0xE780, 0xEBE0, 0xEE70, 0xEF60, 0xEE10, 0xEBF0, 0xE7A0, 0xE0C0, 0xD850, + 0xCB20, 0xBD70, 0xAD70, 0x9CA0, 0x8CD0, 0x8620, 0x84F0, 0x84C0, 0x84A0, 0x8480, 0x8470, 0x8460, 0x8450, 0x8440, 0x8430, 0x8430, + 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8450, 0x8460, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, + 0x84C0, 0x84F0, 0x8590, 0x8970, 0x9C30, 0xAEB0, 0xC120, 0xD070, 0xDDD0, 0xEA10, 0xF560, 0x0060, 0x0D90, 0x1D00, 0x2F60, 0x44B0, + 0x5970, 0x6C60, 0x7B80, 0x7F10, 0x7F00, 0x7F60, 0x7EE0, 0x7ED0, 0x7EE0, 0x7EF0, 0x7F80, 0x7F00, 0x7EE0, 0x7F00, 0x7F10, 0x7F30, + 0x7EE0, 0x7EB0, 0x7F00, 0x7EE0, 0x7F30, 0x7ED0, 0x7EB0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, 0x7F00, 0x7F00, 0x7F00, + 0x7EC0, 0x7F30, 0x7F00, 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7F80, 0x7EE0, 0x7EF0, 0x7F10, 0x7F10, + 0x7F70, 0x7F00, 0x7F10, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F00, + 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F10, 0x7F10, + 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, + 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F00, + 0x7F20, 0x7F30, 0x7F20, 0x7F40, 0x7EF0, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, + 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F20, 0x7F40, + 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F30, + 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, + 0x7F20, 0x7F30, 0x7F30, 0x7F00, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F00, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, + 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F50, 0x7F30, 0x7F20, 0x7F40, + 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F30, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F10, 0x7F30, + 0x7F30, 0x7F20, 0x7F20, 0x7FB0, 0x7F30, 0x7F00, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7ED0, 0x7EF0, 0x7F20, 0x7F40, 0x7F40, 0x7EB0, + 0x7F00, 0x7F00, 0x7F30, 0x7F30, 0x7EB0, 0x7EC0, 0x7EF0, 0x7F20, 0x7F00, 0x7ED0, 0x7EE0, 0x7F00, 0x7F10, 0x7F30, 0x7E90, 0x7EE0, + 0x7EE0, 0x7EF0, 0x7F20, 0x7E80, 0x7ED0, 0x7F00, 0x7F20, 0x7F10, 0x7EC0, 0x7F10, 0x7F00, 0x7F10, 0x7F00, 0x7EC0, 0x7F00, 0x7F10, + 0x7F20, 0x7F40, 0x7F00, 0x7F50, 0x7F20, 0x7F40, 0x7F30, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F30, 0x7F20, 0x7F50, 0x7F00, 0x7F20, + 0x7F00, 0x7F10, 0x7F70, 0x7EE0, 0x7EC0, 0x7EF0, 0x7F00, 0x7F60, 0x7ED0, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7EB0, 0x7E70, 0x7F10, + 0x7F10, 0x7F20, 0x7EE0, 0x7E90, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7EA0, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7EE0, 0x7F40, 0x7F10, + 0x7F20, 0x7F10, 0x7F00, 0x7F40, 0x7F00, 0x7EF0, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7F20, 0x7EF0, 0x7EF0, 0x7F90, 0x7F20, 0x7F20, + 0x7EF0, 0x7EF0, 0x7F60, 0x7F10, 0x7EF0, 0x7EE0, 0x7EE0, 0x7F50, 0x7F10, 0x7E30, 0x7B00, 0x7790, 0x73F0, 0x7180, 0x6ED0, 0x6CB0, + 0x6A30, 0x6720, 0x65C0, 0x64D0, 0x6540, 0x6640, 0x67B0, 0x69F0, 0x6CA0, 0x6F90, 0x72B0, 0x7570, 0x7920, 0x7BC0, 0x7E60, 0x7EE0, + 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7F40, 0x7F10, 0x7F10, 0x7F10, 0x7F50, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F60, 0x7F00, 0x7F10, + 0x7F20, 0x7F20, 0x7F70, 0x7EF0, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F70, 0x7F00, 0x7EE0, 0x7F10, 0x7F10, 0x7F60, 0x7EE0, 0x7E90, 0x7F00, + 0x7EE0, 0x7EF0, 0x7EB0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7EC0, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, 0x7F20, 0x7EF0, + 0x7F10, 0x7F30, 0x7F20, 0x7F80, 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F60, 0x7F20, 0x7EF0, 0x7F10, 0x7F00, 0x7F80, 0x7EC0, 0x7F10, + 0x7F10, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7F00, 0x7F10, 0x7F30, 0x7EF0, 0x7F60, 0x7F00, 0x7F20, 0x7EF0, 0x7F10, 0x7F90, 0x7F20, + 0x7F10, 0x7EF0, 0x7EF0, 0x7F80, 0x7ED0, 0x7DB0, 0x7C00, 0x7A40, 0x78F0, 0x77B0, 0x75E0, 0x74E0, 0x73B0, 0x72E0, 0x7310, 0x7290, + 0x7370, 0x7400, 0x7440, 0x75C0, 0x7630, 0x7760, 0x7890, 0x79E0, 0x7BE0, 0x7C90, 0x7E00, 0x7EB0, 0x7EE0, 0x7EF0, 0x7EA0, 0x7F00, + 0x7F00, 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F30, 0x7EF0, 0x7F10, 0x7F10, 0x7F10, 0x7F60, 0x7F00, + 0x7F20, 0x7F20, 0x7F10, 0x7F50, 0x7EF0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F70, 0x7EF0, 0x7EF0, 0x7F10, 0x7F20, 0x7F70, 0x7ED0, 0x7EB0, + 0x7EE0, 0x7EF0, 0x7F30, 0x7EE0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7E90, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, 0x7F00, + 0x7EF0, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F60, 0x7EF0, 0x7F10, 0x7F30, 0x7600, 0x5D80, 0x4380, + 0x2940, 0x1040, 0xF810, 0xE1B0, 0xCBF0, 0xB770, 0xA0B0, 0x8CC0, 0x85B0, 0x84E0, 0x84B0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8450, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8410, 0x8430, 0x8430, 0x8430, 0x8460, 0x8430, 0x8430, + 0x8430, 0x8440, 0x8430, 0x8430, 0x8460, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, + 0x8450, 0x8450, 0x8450, 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8440, 0x8450, 0x8440, 0x8440, 0x8440, 0x8430, + 0x8430, 0x8430, 0x8450, 0x8430, 0x8420, 0x8410, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, + 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, + 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, + 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8410, + 0x8400, 0x8400, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, + 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, + 0x8440, 0x8430, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8460, 0x8440, 0x8460, 0x8460, + 0x8460, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8430, 0x8470, 0x8430, 0x8430, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8440, 0x8440, 0x8480, 0x8460, 0x8460, 0x84B0, 0x8490, 0x84A0, 0x84D0, 0x8530, 0x8810, 0x9CB0, 0xB390, 0xC420, 0xCD90, 0xCF10, + 0xC810, 0xB9A0, 0xA4F0, 0x8FB0, 0x8660, 0x8500, 0x84D0, 0x84C0, 0x84B0, 0x84A0, 0x8490, 0x8480, 0x8480, 0x8460, 0x8450, 0x83E0, + 0x8430, 0x8420, 0x8420, 0x8420, 0x8430, 0x8460, 0x8440, 0x8460, 0x8480, 0x84A0, 0x84F0, 0x85B0, 0x8950, 0x9530, 0xA2D0, 0xB180, + 0xC2A0, 0xD230, 0xDF20, 0xE770, 0xEA10, 0xE6A0, 0xDAE0, 0xC4C0, 0xA010, 0x8550, 0x84A0, 0x8470, 0x8460, 0x8450, 0x8450, 0x8440, + 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8470, 0x8490, 0x84D0, 0x8780, 0xB350, 0xDE50, 0x0290, 0x2130, + 0x3B80, 0x5290, 0x67D0, 0x7AA0, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F40, + 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x62D0, 0x5B20, 0x57B0, + 0x5910, 0x5DE0, 0x6420, 0x6AC0, 0x7130, 0x7720, 0x7BC0, 0x7EB0, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, + 0x7F40, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F50, 0x7F10, 0x7EA0, 0x7F20, 0x7EF0, 0x7EF0, 0x7EE0, 0x7E80, 0x7EF0, 0x7F20, 0x7F00, + 0x7F00, 0x7E80, 0x7EB0, 0x7EA0, 0x7F10, 0x7EB0, 0x7EA0, 0x7EE0, 0x7EF0, 0x7F30, 0x7F30, 0x7F00, 0x7F90, 0x7F20, 0x7F40, 0x7F10, + 0x7F10, 0x7F30, 0x7EF0, 0x7EF0, 0x7F00, 0x7F00, 0x7F80, 0x7F00, 0x7EE0, 0x7D60, 0x7C80, 0x7CB0, 0x7D70, 0x7E40, 0x7ED0, 0x7EE0, + 0x7F60, 0x7EF0, 0x7EB0, 0x7F00, 0x7EE0, 0x7F10, 0x7F10, 0x7E70, 0x7ED0, 0x7EB0, 0x7F00, 0x7EE0, 0x7E90, 0x7F10, 0x7F20, 0x7F00, + 0x7ED0, 0x7300, 0x6700, 0x5A10, 0x4D10, 0x42B0, 0x3B40, 0x3840, 0x3980, 0x3E70, 0x4800, 0x5140, 0x59E0, 0x6160, 0x66F0, 0x6B30, + 0x6D30, 0x6E30, 0x6E40, 0x6CB0, 0x6BA0, 0x6940, 0x6790, 0x66E0, 0x67A0, 0x6B10, 0x7050, 0x7730, 0x7E40, 0x7F10, 0x7F00, 0x7EF0, + 0x7F60, 0x7EF0, 0x7EB0, 0x7F00, 0x7F10, 0x7F60, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7E90, 0x7F10, 0x7EF0, 0x7EF0, + 0x7EB0, 0x7EC0, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7F10, 0x7EF0, 0x7EF0, 0x7F40, 0x72E0, 0x5EA0, 0x4960, 0x33D0, 0x2090, + 0x0CC0, 0xFBD0, 0xEDB0, 0xE260, 0xD960, 0xD380, 0xD030, 0xCF90, 0xD060, 0xD340, 0xD5C0, 0xD7C0, 0xD940, 0xDAB0, 0xDC30, 0xDE20, + 0xDF50, 0xE0B0, 0xE160, 0xE2C0, 0xE430, 0xE4B0, 0xE610, 0xE6D0, 0xE790, 0xE780, 0xE670, 0xE550, 0xE460, 0xE460, 0xE500, 0xE530, + 0xE820, 0xEB60, 0xF110, 0xF870, 0x01C0, 0x0BD0, 0x1710, 0x2300, 0x2FC0, 0x3CC0, 0x4A80, 0x5720, 0x6340, 0x6F20, 0x7820, 0x7E70, + 0x7F10, 0x7F50, 0x7EF0, 0x7F20, 0x7EF0, 0x7F10, 0x7F60, 0x7EF0, 0x7F30, 0x7F20, 0x7F00, 0x7F80, 0x7EF0, 0x7EE0, 0x7EE0, 0x7F10, + 0x7F70, 0x7EE0, 0x7ED0, 0x7F10, 0x7F20, 0x7F60, 0x7EE0, 0x7E90, 0x7F00, 0x7F10, 0x7F30, 0x7EB0, 0x7E70, 0x7EF0, 0x7F10, 0x7F20, + 0x7EE0, 0x7F30, 0x7EE0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F40, 0x7ED0, 0x7E90, 0x7F00, 0x7EE0, 0x7EF0, 0x7F20, 0x7F00, 0x7F40, 0x7F20, + 0x7F20, 0x7F40, 0x7F00, 0x7F30, 0x7EE0, 0x7EF0, 0x7F30, 0x7F10, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F90, 0x7F00, 0x7F00, + 0x7E60, 0x7AB0, 0x7740, 0x7380, 0x6F90, 0x6C70, 0x6960, 0x66F0, 0x64D0, 0x6310, 0x6100, 0x5E50, 0x5A30, 0x56E0, 0x52F0, 0x5090, + 0x4D60, 0x4980, 0x46A0, 0x41F0, 0x3F40, 0x3BE0, 0x3810, 0x34B0, 0x30A0, 0x2CC0, 0x28C0, 0x2500, 0x21E0, 0x1FC0, 0x1E30, 0x1CC0, + 0x1A80, 0x1850, 0x1620, 0x1440, 0x1240, 0x1010, 0x0F20, 0x0E00, 0x0DB0, 0x0D20, 0x0C60, 0x0CF0, 0x0CC0, 0x0BF0, 0x0B10, 0x0AD0, + 0x0B10, 0x0B20, 0x0BC0, 0x0C50, 0x0CA0, 0x0D70, 0x0DF0, 0x0F30, 0x10E0, 0x1360, 0x17B0, 0x1CB0, 0x2130, 0x25F0, 0x2AC0, 0x3100, + 0x3770, 0x3D50, 0x4400, 0x49A0, 0x4F50, 0x53D0, 0x56F0, 0x5AA0, 0x5CC0, 0x5FB0, 0x6260, 0x63C0, 0x65D0, 0x6700, 0x67C0, 0x6850, + 0x68D0, 0x69F0, 0x6A80, 0x6B10, 0x6C90, 0x6E60, 0x7170, 0x7450, 0x77D0, 0x7B20, 0x7D80, 0x7F10, 0x7F20, 0x7F80, 0x7F10, 0x7F10, + 0x7EF0, 0x7EF0, 0x7F80, 0x7F10, 0x7F10, 0x7EF0, 0x7F10, 0x7F70, 0x7F10, 0x7ED0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F00, 0x7EE0, 0x7EE0, + 0x7ED0, 0x7F30, 0x7F20, 0x7E60, 0x7CD0, 0x7B30, 0x7990, 0x78D0, 0x77B0, 0x77E0, 0x7820, 0x78C0, 0x7A90, 0x7C00, 0x7D20, 0x7E60, + 0x7EE0, 0x7F10, 0x7EC0, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F50, 0x7EF0, 0x7F20, + 0x7EF0, 0x7EF0, 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, 0x7F80, 0x7EF0, 0x7EB0, 0x7F10, 0x7F10, 0x7F70, 0x7EE0, 0x7EC0, 0x7EF0, + 0x7F10, 0x7F30, 0x7EE0, 0x7EB0, 0x7F00, 0x7F10, 0x7F10, 0x7EB0, 0x7E70, 0x7EF0, 0x7EF0, 0x7F20, 0x7EE0, 0x7E90, 0x7F10, 0x7F20, + 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7EF0, 0x7F10, 0x7F20, 0x7EC0, 0x7F40, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F70, 0x7F00, 0x7F10, + 0x7F30, 0x7EF0, 0x7F70, 0x7EF0, 0x7F20, 0x7F00, 0x7F00, 0x7F90, 0x7F20, 0x7F10, 0x7EF0, 0x7EF0, 0x7F60, 0x7EF0, 0x7ED0, 0x7EE0, + 0x7EE0, 0x7F50, 0x7F10, 0x7EA0, 0x7EE0, 0x7ED0, 0x7F10, 0x7F00, 0x7EA0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EB0, 0x7F00, 0x7F20, + 0x7F10, 0x7F10, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F00, 0x7ED0, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, + 0x7F00, 0x7EE0, 0x7F50, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7F10, 0x7F10, + 0x7F20, 0x7F00, 0x7F40, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7B50, 0x75B0, 0x6EF0, 0x6880, 0x61E0, 0x5B70, + 0x5540, 0x4FB0, 0x4CD0, 0x4BB0, 0x4D20, 0x5180, 0x56A0, 0x5D60, 0x6350, 0x6870, 0x6B50, 0x6AE0, 0x66C0, 0x5EB0, 0x5270, 0x4490, + 0x3600, 0x27E0, 0x1B00, 0x1030, 0x06C0, 0xFE80, 0xF520, 0xEA50, 0xDF60, 0xD460, 0xC950, 0xBED0, 0xB670, 0xAFE0, 0xAAE0, 0xA7D0, + 0xA520, 0xA3D0, 0xA240, 0xA050, 0x9DB0, 0x99A0, 0x9510, 0x9020, 0x8C80, 0x8A30, 0x8930, 0x88F0, 0x8940, 0x89A0, 0x8AA0, 0x8C10, + 0x8DF0, 0x90F0, 0x9530, 0x99C0, 0x9ED0, 0xA340, 0xA770, 0xABD0, 0xAF50, 0xB370, 0xB790, 0xBBA0, 0xBF60, 0xC2B0, 0xC580, 0xC840, + 0xCAA0, 0xCD40, 0xCFD0, 0xD220, 0xD3D0, 0xD530, 0xD640, 0xD800, 0xD9D0, 0xDBF0, 0xDDD0, 0xDFB0, 0xE040, 0xE090, 0xE0D0, 0xE140, + 0xE180, 0xE200, 0xE2A0, 0xE1D0, 0xE0D0, 0xE060, 0xE070, 0xE080, 0xE090, 0xE0B0, 0xE0C0, 0xE080, 0xDFD0, 0xDFF0, 0xE070, 0xE190, + 0xE230, 0xE2D0, 0xE3C0, 0xE450, 0xE470, 0xE5A0, 0xE640, 0xE660, 0xE540, 0xE300, 0xE090, 0xDE10, 0xDBF0, 0xDA50, 0xD8C0, 0xD600, + 0xD2A0, 0xCDB0, 0xC900, 0xC530, 0xC260, 0xBF40, 0xBBB0, 0xB850, 0xB4D0, 0xB0F0, 0xAE50, 0xAC50, 0xAA20, 0xA780, 0xA410, 0xA0E0, + 0x9DE0, 0x9B80, 0x9A10, 0x98C0, 0x97C0, 0x95C0, 0x9340, 0x90A0, 0x8E30, 0x8C50, 0x8B00, 0x89F0, 0x8900, 0x8850, 0x87C0, 0x8730, + 0x86D0, 0x8690, 0x8660, 0x8620, 0x8620, 0x85C0, 0x8590, 0x8570, 0x8560, 0x8550, 0x8540, 0x8530, 0x8520, 0x8520, 0x8510, 0x8510, + 0x8510, 0x8500, 0x8500, 0x84F0, 0x84F0, 0x84F0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84C0, 0x84D0, + 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84D0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84D0, 0x84C0, 0x84B0, 0x84C0, + 0x84C0, 0x84C0, 0x84B0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, + 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, + 0x84C0, 0x84E0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84B0, 0x84C0, + 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84E0, 0x84E0, 0x84D0, 0x84F0, 0x84F0, 0x8500, + 0x8500, 0x8510, 0x8530, 0x8540, 0x8560, 0x8590, 0x85D0, 0x8600, 0x8660, 0x86B0, 0x8740, 0x87D0, 0x8860, 0x88E0, 0x8940, 0x89C0, + 0x8A50, 0x8B60, 0x8C10, 0x8C90, 0x8D10, 0x8D60, 0x8E00, 0x8E30, 0x8E90, 0x8F30, 0x8FC0, 0x8FE0, 0x9020, 0x9090, 0x9130, 0x9200, + 0x92F0, 0x93F0, 0x9480, 0x9520, 0x95C0, 0x96F0, 0x9920, 0x9BB0, 0x9E30, 0xA070, 0xA320, 0xA640, 0xAA80, 0xAF70, 0xB550, 0xBC70, + 0xC400, 0xCBD0, 0xD3F0, 0xDBF0, 0xE460, 0xEC60, 0xF3D0, 0xFCD0, 0x0360, 0x0930, 0x0E50, 0x11E0, 0x1520, 0x16D0, 0x1870, 0x18F0, + 0x1890, 0x1770, 0x14A0, 0x10A0, 0x0BD0, 0x05B0, 0xFF30, 0xF6C0, 0xEC90, 0xE1C0, 0xD680, 0xCA50, 0xBDB0, 0xB070, 0xA360, 0x95F0, + 0x8B20, 0x8670, 0x8520, 0x84F0, 0x84D0, 0x84C0, 0x84A0, 0x84A0, 0x8490, 0x8480, 0x8480, 0x8470, 0x8460, 0x8440, 0x8450, 0x8440, + 0x8430, 0x8420, 0x8400, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83B0, 0x83B0, 0x83B0, + 0x83B0, 0x83A0, 0x83A0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83D0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, + 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8440, 0x8450, 0x8460, + 0x8470, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8470, 0x8470, 0x8460, 0x8450, 0x8450, 0x8460, + 0x8430, 0x8430, 0x8460, 0x8420, 0x8430, 0x8410, 0x8410, 0x8420, 0x8420, 0x8410, 0x8420, 0x8420, 0x8420, 0x8450, 0x8430, 0x8420, + 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8440, 0x8450, 0x8450, 0x8470, 0x8460, 0x8470, 0x8480, 0x8480, 0x8490, 0x84B0, + 0x84D0, 0x8500, 0x8570, 0x86C0, 0x89E0, 0x8EE0, 0x93C0, 0x97E0, 0x9B80, 0x9EF0, 0xA0F0, 0xA310, 0xA510, 0xA780, 0xAAD0, 0xB070, + 0xB820, 0xC330, 0xD0C0, 0xE1D0, 0xF3A0, 0x07F0, 0x19F0, 0x2AC0, 0x3BA0, 0x4BF0, 0x5C70, 0x6C30, 0x79E0, 0x7EF0, 0x7F00, 0x7F60, + 0x7EF0, 0x7EB0, 0x7F00, 0x7F00, 0x7F50, 0x7ED0, 0x7EA0, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7E90, 0x7F10, 0x7F20, 0x7F00, 0x7F10, + 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F40, 0x7F10, 0x7F20, 0x7F10, 0x7F00, 0x7F40, 0x7F00, 0x7F10, 0x7F10, 0x7F00, + 0x7F60, 0x7EF0, 0x7F20, 0x7EF0, 0x7EF0, 0x7F90, 0x7F00, 0x7F20, 0x7F10, 0x7EF0, 0x7F70, 0x7F10, 0x7F10, 0x7EF0, 0x7EE0, 0x7F70, + 0x7F10, 0x7EB0, 0x7EE0, 0x7EF0, 0x72A0, 0x5FE0, 0x4B50, 0x3610, 0x1FE0, 0x0900, 0xF3D0, 0xE030, 0xD020, 0xC2C0, 0xB930, 0xB2F0, + 0xAD90, 0xA750, 0xA110, 0x99C0, 0x92A0, 0x8BD0, 0x87D0, 0x8630, 0x8580, 0x8510, 0x84F0, 0x8510, 0x84C0, 0x84B0, 0x84A0, 0x84A0, + 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8470, 0x8490, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, + 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8480, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8490, 0x84A0, 0x84A0, 0x8500, 0x84D0, + 0x84E0, 0x8500, 0x8530, 0x85B0, 0x86D0, 0x8A30, 0x9240, 0x9B80, 0xA4D0, 0xADB0, 0xB690, 0xBF90, 0xC8E0, 0xD2F0, 0xDE10, 0xE8D0, + 0xF3D0, 0xFF30, 0x0B00, 0x1640, 0x20F0, 0x2C30, 0x3660, 0x4050, 0x48D0, 0x4F50, 0x56F0, 0x5BC0, 0x5FA0, 0x62B0, 0x64A0, 0x65C0, + 0x6690, 0x6750, 0x6760, 0x6720, 0x66E0, 0x6650, 0x6620, 0x6690, 0x67D0, 0x6990, 0x6C80, 0x70E0, 0x75B0, 0x7B10, 0x7EB0, 0x7F30, + 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, + 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F10, 0x7D20, + 0x6AF0, 0x5A30, 0x49D0, 0x39F0, 0x2B30, 0x1D30, 0x0F40, 0x0270, 0xF660, 0xEBA0, 0xE220, 0xDB70, 0xD6D0, 0xD400, 0xD280, 0xD130, + 0xCF80, 0xCD00, 0xCA20, 0xC6C0, 0xC320, 0xBFD0, 0xBDA0, 0xBAF0, 0xB8A0, 0xB6A0, 0xB490, 0xB260, 0xB090, 0xAEB0, 0xACD0, 0xAB20, + 0xA8A0, 0xA5B0, 0xA110, 0x9AF0, 0x9470, 0x8E50, 0x8A00, 0x8790, 0x86B0, 0x8650, 0x8660, 0x8690, 0x8710, 0x87C0, 0x88B0, 0x89E0, + 0x8BB0, 0x8D90, 0x9070, 0x93C0, 0x9890, 0x9E40, 0xA560, 0xADD0, 0xB7A0, 0xC3A0, 0xCF90, 0xDCA0, 0xE9F0, 0xF7D0, 0x0600, 0x14A0, + 0x22C0, 0x3180, 0x4130, 0x4FC0, 0x5D90, 0x6A10, 0x7560, 0x7DF0, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F20, + 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, + 0x7F30, 0x7F20, 0x7F30, 0x7EF0, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F00, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F20, + 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7EB0, 0x7F20, + 0x7F40, 0x7F30, 0x7F10, 0x7EC0, 0x7F10, 0x7EF0, 0x7EB0, 0x7EE0, 0x7E80, 0x7ED0, 0x7E70, 0x7EF0, 0x7EF0, 0x7F00, 0x7F20, 0x7F00, + 0x7F10, 0x7F30, 0x7EE0, 0x7F50, 0x7F00, 0x7F20, 0x7EF0, 0x7EF0, 0x7F60, 0x7F20, 0x7F10, 0x7F00, 0x7F00, 0x7F70, 0x7F10, 0x7EF0, + 0x7EE0, 0x7EE0, 0x7F50, 0x7F10, 0x7EA0, 0x7EF0, 0x7F00, 0x7F60, 0x7F10, 0x7E90, 0x7EB0, 0x7EC0, 0x7EF0, 0x7EF0, 0x7E70, 0x7ED0, + 0x7ED0, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F10, 0x7E90, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, + 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7EF0, 0x7F20, 0x7EF0, 0x7F10, 0x7F40, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F50, 0x7EF0, 0x7EF0, + 0x7EE0, 0x7EF0, 0x7F60, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F60, 0x7ED0, 0x7EB0, 0x7F00, 0x7F10, 0x7F30, 0x7EB0, 0x7EA0, 0x7EF0, + 0x7B50, 0x7430, 0x6DC0, 0x6710, 0x6260, 0x5F60, 0x5CD0, 0x5B50, 0x5760, 0x5140, 0x4800, 0x3C50, 0x2FA0, 0x2150, 0x1510, 0x09D0, + 0xFF80, 0xF750, 0xEFB0, 0xE830, 0xDFE0, 0xD550, 0xC7F0, 0xB990, 0xA850, 0x96E0, 0x89C0, 0x84C0, 0x84B0, 0x84A0, 0x8490, 0x8490, + 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8470, 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84E0, 0x8520, 0x85B0, 0x87B0, 0x8E00, + 0x97B0, 0xA1A0, 0xA970, 0xB020, 0xB5B0, 0xBA70, 0xBD10, 0xBE20, 0xBCB0, 0xBA80, 0xB6B0, 0xB320, 0xB060, 0xAD40, 0xAA10, 0xA7E0, + 0xA660, 0xA5B0, 0xA5F0, 0xA7A0, 0xAA10, 0xAC70, 0xAF60, 0xB1A0, 0xB510, 0xB940, 0xBE10, 0xC340, 0xC800, 0xCC90, 0xD0C0, 0xD2D0, + 0xD550, 0xD680, 0xD6B0, 0xD5C0, 0xD400, 0xD1D0, 0xCEE0, 0xCCF0, 0xCB80, 0xCA20, 0xC910, 0xC730, 0xC4A0, 0xC120, 0xBD30, 0xBA20, + 0xB730, 0xB3D0, 0xB170, 0xAE00, 0x9E70, 0x9B90, 0x9900, 0x9670, 0x9380, 0x9150, 0x8F80, 0x8EB0, 0x8F00, 0x9060, 0x9350, 0x9720, + 0x9BB0, 0xA180, 0xA990, 0xB320, 0xBE60, 0xCB70, 0xD7F0, 0xE420, 0xF210, 0xFF90, 0x0D90, 0x1B00, 0x2740, 0x33F0, 0x40B0, 0x4D00, + 0x5850, 0x62B0, 0x6D60, 0x7660, 0x7D90, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, + 0x7F20, 0x7EF0, 0x7EF0, 0x7F70, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F70, 0x7ED0, 0x7F10, 0x7F00, 0x7EE0, 0x7F80, 0x7EF0, 0x7EE0, + 0x7F00, 0x7F10, 0x7F70, 0x7F00, 0x7ED0, 0x7EF0, 0x7F00, 0x7F20, 0x7ED0, 0x7EB0, 0x7F20, 0x7EF0, 0x7F30, 0x7F00, 0x7EA0, 0x7F10, + 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F00, 0x7EF0, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F30, 0x7F00, + 0x7F00, 0x7EF0, 0x7F10, 0x7F80, 0x7F20, 0x7F10, 0x7F20, 0x7F00, 0x7F90, 0x7F10, 0x7F00, 0x7EE0, 0x7EF0, 0x7F70, 0x7F20, 0x7EF0, + 0x7EF0, 0x7F00, 0x7F60, 0x7F10, 0x7EB0, 0x7EB0, 0x7EC0, 0x7EF0, 0x7F00, 0x7EC0, 0x7EC0, 0x7ED0, 0x7E80, 0x7D60, 0x7B80, 0x7A10, + 0x7930, 0x7780, 0x7690, 0x7500, 0x7440, 0x73D0, 0x7350, 0x73B0, 0x7400, 0x7440, 0x74B0, 0x74A0, 0x75A0, 0x7680, 0x77F0, 0x79E0, + 0x7AD0, 0x7BF0, 0x7D10, 0x7DE0, 0x7E90, 0x7F00, 0x7F00, 0x7F10, 0x7F50, 0x7EF0, 0x7F00, 0x7EF0, 0x7F00, 0x7F40, 0x7EF0, 0x7EF0, + 0x7F10, 0x7F20, 0x7F70, 0x7ED0, 0x7EB0, 0x7F00, 0x7F10, 0x7F30, 0x7EE0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7EB0, 0x7F00, + 0x7F10, 0x7F10, 0x7F10, 0x7EA0, 0x7F00, 0x7EF0, 0x7F20, 0x7EF0, 0x7E00, 0x7BB0, 0x79B0, 0x7780, 0x7610, 0x7460, 0x71E0, 0x6EF0, + 0x6C30, 0x6A40, 0x6800, 0x65D0, 0x6370, 0x6100, 0x5FA0, 0x5E10, 0x5C30, 0x5A80, 0x5790, 0x5570, 0x5330, 0x4FE0, 0x4D50, 0x49B0, + 0x46C0, 0x4400, 0x40F0, 0x3E60, 0x3C00, 0x3AD0, 0x3B50, 0x3CF0, 0x4040, 0x42C0, 0x45B0, 0x4800, 0x4A10, 0x4DB0, 0x5180, 0x5640, + 0x5AD0, 0x5E90, 0x62B0, 0x66A0, 0x6B30, 0x7030, 0x7460, 0x7950, 0x7D10, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F10, 0x7F10, + 0x7F00, 0x7EF0, 0x7EF0, 0x7F70, 0x7F20, 0x7F40, 0x7F10, 0x7F20, 0x7F60, 0x7F10, 0x7F10, 0x7F00, 0x7EE0, 0x7F70, 0x7F00, 0x7F00, + 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7ED0, 0x7EF0, 0x7F00, 0x7F30, 0x7EF0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F30, 0x7F00, 0x7EC0, 0x7F10, + 0x7BF0, 0x69E0, 0x5A10, 0x48B0, 0x38A0, 0x29A0, 0x1BF0, 0x1100, 0x06A0, 0xFE40, 0xF690, 0xF0A0, 0xEAD0, 0xE770, 0xE550, 0xE3F0, + 0xE3F0, 0xE570, 0xE8C0, 0xECF0, 0xF220, 0xF780, 0xFC70, 0x00C0, 0x0410, 0x06C0, 0x0930, 0x0A30, 0x0AB0, 0x09F0, 0x0830, 0x04F0, + 0x00D0, 0xFAE0, 0xF3B0, 0xECE0, 0xE610, 0xE000, 0xD930, 0xD1D0, 0xC790, 0xB900, 0xA320, 0x8940, 0x84E0, 0x8490, 0x8470, 0x8450, + 0x8440, 0x8430, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, + 0x8420, 0x8430, 0x8440, 0x8460, 0x8470, 0x8490, 0x84C0, 0x84E0, 0x8500, 0x8520, 0x8550, 0x85E0, 0x8790, 0x8DE0, 0x9840, 0x9F50, + 0x9F10, 0x9950, 0x8F70, 0x8830, 0x8590, 0x8510, 0x84F0, 0x84D0, 0x84C0, 0x84C0, 0x84C0, 0x84B0, 0x84C0, 0x84B0, 0x84A0, 0x84A0, + 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84A0, 0x84B0, 0x84B0, 0x84A0, 0x84C0, 0x84C0, 0x84D0, + 0x84F0, 0x8510, 0x8540, 0x85D0, 0x86F0, 0x8950, 0x8DC0, 0x9250, 0x96B0, 0x98B0, 0x99A0, 0x9900, 0x9720, 0x9540, 0x93B0, 0x92F0, + 0x9250, 0x9240, 0x9270, 0x9230, 0x9200, 0x9160, 0x90D0, 0x9090, 0x9000, 0x8FE0, 0x8FC0, 0x9060, 0x9080, 0x9100, 0x9060, 0x8F40, + 0x8DE0, 0x8BA0, 0x89A0, 0x8840, 0x8760, 0x86D0, 0x8650, 0x85F0, 0x85A0, 0x8590, 0x8530, 0x8510, 0x84F0, 0x84F0, 0x84E0, 0x84D0, + 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, + 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8440, 0x8470, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, + 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x84A0, 0x8480, 0x8470, 0x8480, 0x8480, 0x8480, 0x8490, + 0x8490, 0x84B0, 0x8490, 0x84A0, 0x8470, 0x84B0, 0x84C0, 0x84F0, 0x84E0, 0x8500, 0x8520, 0x8590, 0x85E0, 0x86F0, 0x88D0, 0x8CB0, + 0x91F0, 0x9760, 0x9D40, 0xA230, 0xA780, 0xACB0, 0xB180, 0xB540, 0xB8B0, 0xBB60, 0xBE80, 0xC1D0, 0xC5E0, 0xCA40, 0xCE50, 0xD300, + 0xD6E0, 0xDB10, 0xDF00, 0xE260, 0xE680, 0xE9F0, 0xED50, 0xF160, 0xF440, 0xF7D0, 0xFA30, 0xFCC0, 0xFD90, 0xFDF0, 0xFF10, 0x0020, + 0x0060, 0x00F0, 0x0020, 0xFEF0, 0xFCF0, 0xFA90, 0xF8A0, 0xF690, 0xF530, 0xF3E0, 0xF240, 0xF1E0, 0xEFF0, 0xEDE0, 0xEAF0, 0xE890, + 0xE770, 0xE560, 0xE490, 0xE410, 0xE400, 0xE420, 0xE350, 0xE360, 0xE3E0, 0xE3A0, 0xE520, 0xE700, 0xE960, 0xECC0, 0xF010, 0xF4C0, + 0xF900, 0xFEB0, 0x0430, 0x0A20, 0x1050, 0x1710, 0x1DF0, 0x25C0, 0x2C10, 0x33F0, 0x3BC0, 0x42F0, 0x4A10, 0x50E0, 0x5800, 0x5EF0, + 0x65E0, 0x6BA0, 0x7190, 0x76F0, 0x7BB0, 0x7EE0, 0x7EF0, 0x7EB0, 0x7EF0, 0x7F10, 0x7F70, 0x7EE0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F30, + 0x7EE0, 0x7EC0, 0x7F20, 0x7F20, 0x7F40, 0x7ED0, 0x7EA0, 0x7F20, 0x7EF0, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, + 0x7F00, 0x7F30, 0x7EE0, 0x7EF0, 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F80, 0x7F00, 0x7F40, 0x7F10, 0x7EF0, + 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7F00, 0x7F70, 0x7F10, 0x7F00, 0x7F00, 0x7EF0, 0x7F30, 0x7F00, 0x7EC0, 0x7ED0, 0x7EE0, 0x7F50, + 0x7F10, 0x7EB0, 0x7EE0, 0x7EE0, 0x7F10, 0x7F10, 0x7E70, 0x7E80, 0x7EB0, 0x7F00, 0x7EF0, 0x7E90, 0x7F00, 0x7F20, 0x7F10, 0x7F10, + 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EE0, 0x7F40, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7ED0, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, + 0x7EE0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7F10, 0x7EB0, 0x7F20, 0x7F10, 0x7F20, 0x7F40, 0x7F00, 0x7F30, 0x7EE0, 0x7F10, 0x7F30, + 0x7F10, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F90, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7F60, 0x7EF0, 0x7EF0, 0x7F00, 0x7F00, + 0x7F70, 0x7F10, 0x7EB0, 0x7F00, 0x7B90, 0x7530, 0x6F70, 0x68A0, 0x6210, 0x5A80, 0x5070, 0x4580, 0x3720, 0x28C0, 0x1940, 0x0770, + 0xF650, 0xE330, 0xD090, 0xBD80, 0xAB20, 0x9960, 0x8C70, 0x86D0, 0x8560, 0x8500, 0x84E0, 0x84D0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, + 0x84B0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8470, 0x8480, 0x8480, + 0x8480, 0x8470, 0x8470, 0x8480, 0x8470, 0x8470, 0x8480, 0x8470, 0x8470, 0x8470, 0x8490, 0x8480, 0x8480, 0x8480, 0x84B0, 0x8480, + 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, 0x8490, + 0x8490, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84D0, 0x84E0, 0x8500, 0x8510, 0x8560, 0x85F0, 0x8770, 0x8B00, + 0x9250, 0x9AA0, 0xA1D0, 0xA910, 0xB020, 0xB760, 0xBED0, 0xC430, 0xC9A0, 0xCCF0, 0xD050, 0xD370, 0xD610, 0xD900, 0xDB50, 0xDD60, + 0xDF60, 0xE110, 0xE3D0, 0xE620, 0xE850, 0xEAF0, 0xED80, 0xF140, 0xF550, 0xF9D0, 0xFF40, 0x0490, 0x0A50, 0x10A0, 0x1570, 0x1AF0, + 0x1FD0, 0x25A0, 0x2B60, 0x3180, 0x37A0, 0x3D20, 0x42D0, 0x47D0, 0x4C10, 0x50E0, 0x5450, 0x57B0, 0x59A0, 0x5AF0, 0x5C50, 0x5D30, + 0x5E60, 0x5F80, 0x5F90, 0x6000, 0x5F40, 0x5EB0, 0x5E20, 0x5D60, 0x5D40, 0x5CF0, 0x5C30, 0x5C00, 0x5AF0, 0x5AE0, 0x5AC0, 0x59D0, + 0x5990, 0x5830, 0x56E0, 0x54C0, 0x5250, 0x5060, 0x4DC0, 0x4B90, 0x49D0, 0x47E0, 0x4790, 0x4780, 0x4910, 0x4B00, 0x4CF0, 0x4F30, + 0x5040, 0x5150, 0x5250, 0x53E0, 0x5700, 0x59C0, 0x5CD0, 0x5F20, 0x60D0, 0x6350, 0x6670, 0x6970, 0x6CE0, 0x7030, 0x7310, 0x74E0, + 0x76B0, 0x77E0, 0x7900, 0x7A00, 0x79D0, 0x7930, 0x77E0, 0x7590, 0x7350, 0x7070, 0x6DD0, 0x6A80, 0x6660, 0x62C0, 0x5E50, 0x59D0, + 0x55A0, 0x5020, 0x4B10, 0x45E0, 0x4000, 0x3A80, 0x3480, 0x2F00, 0x2A40, 0x2530, 0x20D0, 0x1BA0, 0x1680, 0x1190, 0x0C70, 0x08E0, + 0x0490, 0xFFF0, 0xFC30, 0xF870, 0xF4F0, 0xF200, 0xF040, 0xEEE0, 0xED80, 0xEE30, 0xEEE0, 0xEE40, 0xEEF0, 0xEF50, 0xF0A0, 0xF1F0, + 0xF3A0, 0xF590, 0xF790, 0xF9C0, 0xFC10, 0xFED0, 0x00E0, 0x02D0, 0x0450, 0x0610, 0x07A0, 0x0910, 0x0AF0, 0x0C00, 0x0CE0, 0x0DB0, + 0x0E80, 0x1030, 0x1260, 0x1510, 0x1750, 0x1950, 0x1A50, 0x1AF0, 0x1C20, 0x1DA0, 0x1F10, 0x20F0, 0x2300, 0x2560, 0x27F0, 0x2980, + 0x2B20, 0x2CD0, 0x2E10, 0x2EB0, 0x2EB0, 0x2E90, 0x2E30, 0x2DE0, 0x2DE0, 0x2E50, 0x2E70, 0x2E30, 0x2DD0, 0x2CB0, 0x2D00, 0x2C60, + 0x2B10, 0x29B0, 0x2800, 0x2620, 0x23F0, 0x2230, 0x21B0, 0x21E0, 0x2150, 0x21B0, 0x2250, 0x2350, 0x2450, 0x2560, 0x2680, 0x27D0, + 0x2910, 0x2A70, 0x2C00, 0x2E50, 0x3050, 0x31A0, 0x3310, 0x3410, 0x33B0, 0x3340, 0x3270, 0x3160, 0x3010, 0x2E70, 0x2C40, 0x29F0, + 0x2710, 0x2400, 0x20E0, 0x1DD0, 0x19E0, 0x1650, 0x1350, 0x1070, 0x0E70, 0x0CC0, 0x0C10, 0x0BB0, 0x0B00, 0x0A90, 0x0A70, 0x09A0, + 0x0900, 0x0870, 0x07A0, 0x06A0, 0x0500, 0x0350, 0x0040, 0xFD40, 0xFAD0, 0xF870, 0xF680, 0xF470, 0xF230, 0xEFD0, 0xECD0, 0xE990, + 0xE610, 0xE230, 0xDE90, 0xDA90, 0xD630, 0xD1D0, 0xCD00, 0xC880, 0xC3E0, 0xBF00, 0xBAE0, 0xB5E0, 0xB180, 0xAD70, 0xA960, 0xA5A0, + 0xA1B0, 0x9E60, 0x9B40, 0x9990, 0x9880, 0x98C0, 0x99D0, 0x9A80, 0x9B90, 0x9BF0, 0x9CB0, 0x9D80, 0x9EA0, 0xA090, 0xA2E0, 0xA530, + 0xA800, 0xAB10, 0xAD90, 0xB060, 0xB360, 0xB580, 0xB860, 0xBAA0, 0xBCA0, 0xBED0, 0xC180, 0xC400, 0xC6B0, 0xC790, 0xC7B0, 0xC7A0, + 0xC6F0, 0xC650, 0xC5F0, 0xC580, 0xC4E0, 0xC460, 0xC380, 0xC250, 0xC110, 0xBFB0, 0xBEE0, 0xBD80, 0xBC60, 0xBB30, 0xB950, 0xB7D0, + 0xB5C0, 0xB400, 0xB1F0, 0xAEF0, 0xAC60, 0xA970, 0xA6B0, 0xA350, 0x9FB0, 0x9BA0, 0x96A0, 0x9170, 0x8CB0, 0x8940, 0x8740, 0x8610, + 0x8580, 0x8540, 0x8510, 0x84F0, 0x84E0, 0x84D0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x8490, 0x8490, + 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8480, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, + 0x8480, 0x8470, 0x8480, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, + 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, + 0x8460, 0x8480, 0x8470, 0x84A0, 0x8480, 0x8490, 0x8490, 0x84A0, 0x8490, 0x84D0, 0x84F0, 0x8530, 0x85C0, 0x88C0, 0x90F0, 0x9CB0, + 0xA680, 0xB010, 0xB7D0, 0xBF50, 0xC530, 0xCA50, 0xCED0, 0xD200, 0xD530, 0xD7D0, 0xDA20, 0xDC90, 0xDE00, 0xDFE0, 0xE1A0, 0xE2E0, + 0xE510, 0xE6A0, 0xE7E0, 0xEA80, 0xEC30, 0xEEE0, 0xF1E0, 0xF3B0, 0xF660, 0xF840, 0xFA70, 0xFC30, 0xFE20, 0x00B0, 0x0310, 0x0690, + 0x0920, 0x0B50, 0x0D10, 0x0DA0, 0x0DC0, 0x0E00, 0x0D50, 0x0CC0, 0x0B10, 0x08F0, 0x0670, 0x0370, 0x0140, 0xFF50, 0xFDA0, 0xFCE0, + 0xFBD0, 0xFBB0, 0xFAA0, 0xF9D0, 0xF850, 0xF7B0, 0xF760, 0xF690, 0xF5E0, 0xF580, 0xF550, 0xF5C0, 0xF650, 0xF720, 0xF900, 0xFB30, + 0xFDC0, 0x00E0, 0x04B0, 0x08B0, 0x0CF0, 0x11C0, 0x1650, 0x1AB0, 0x1FA0, 0x24D0, 0x2A80, 0x2F60, 0x3410, 0x3A00, 0x3F30, 0x44A0, + 0x4A50, 0x4ED0, 0x5470, 0x5900, 0x5D50, 0x61E0, 0x65E0, 0x6A60, 0x6E10, 0x71B0, 0x7530, 0x7810, 0x7AB0, 0x7C70, 0x7E40, 0x7ED0, + 0x7F20, 0x7F20, 0x7F00, 0x7F90, 0x7F20, 0x7F40, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7EF0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F60, + 0x7EF0, 0x7F10, 0x7F00, 0x7EF0, 0x7F70, 0x7F00, 0x7EC0, 0x7ED0, 0x7EE0, 0x7F30, 0x7F20, 0x7EB0, 0x7EE0, 0x7EE0, 0x7F10, 0x7F10, + 0x7EA0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EF0, 0x7E90, 0x7F00, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7EC0, + 0x7F40, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F40, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F50, + 0x7F00, 0x7F20, 0x7ED0, 0x7F10, 0x7F60, 0x7EE0, 0x7EC0, 0x7F10, 0x7EF0, 0x7F70, 0x7EF0, 0x7EB0, 0x7EC0, 0x7E10, 0x7CB0, 0x7C20, + 0x7B40, 0x7B50, 0x7AF0, 0x7AA0, 0x7AD0, 0x7A00, 0x79C0, 0x79E0, 0x7910, 0x76B0, 0x75B0, 0x74E0, 0x7400, 0x7280, 0x7220, 0x70C0, + 0x70D0, 0x70B0, 0x7070, 0x7110, 0x7100, 0x7290, 0x73B0, 0x7520, 0x77C0, 0x7A40, 0x7D00, 0x7EA0, 0x7F10, 0x7F10, 0x7F10, 0x7F60, + 0x7F10, 0x7F10, 0x7F00, 0x7EE0, 0x7F50, 0x7EF0, 0x7F20, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7E40, 0x79D0, 0x7530, 0x6FE0, 0x6A10, + 0x6330, 0x5C00, 0x5310, 0x48D0, 0x3DD0, 0x31E0, 0x25C0, 0x18F0, 0x0A20, 0xFBD0, 0xED10, 0xE000, 0xD360, 0xC7B0, 0xBCC0, 0xB2B0, + 0xA8A0, 0x9F30, 0x9660, 0x8E90, 0x8980, 0x86D0, 0x85B0, 0x8530, 0x8500, 0x84F0, 0x84E0, 0x84D0, 0x84D0, 0x84D0, 0x84C0, 0x84C0, + 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84B0, 0x84C0, 0x84C0, + 0x84C0, 0x84C0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84E0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x8500, 0x8500, 0x8500, 0x8530, 0x8510, + 0x8510, 0x8520, 0x84F0, 0x8530, 0x8520, 0x8520, 0x84C0, 0x8500, 0x84F0, 0x8500, 0x84F0, 0x84E0, 0x84E0, 0x8490, 0x84F0, 0x84E0, + 0x84F0, 0x84D0, 0x84C0, 0x84C0, 0x84D0, 0x84B0, 0x8490, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x84A0, 0x8490, 0x8490, 0x8490, 0x84B0, + 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84C0, 0x84E0, 0x84B0, 0x84B0, 0x84F0, 0x84C0, 0x84D0, 0x84E0, 0x8510, 0x84E0, + 0x84F0, 0x84F0, 0x8510, 0x8520, 0x8530, 0x8550, 0x8560, 0x8570, 0x8580, 0x8590, 0x8590, 0x8580, 0x85A0, 0x8570, 0x8560, 0x8550, + 0x8550, 0x8530, 0x8530, 0x8520, 0x8510, 0x8510, 0x8500, 0x8500, 0x8500, 0x8500, 0x8500, 0x8500, 0x8500, 0x8500, 0x8510, 0x8530, + 0x8550, 0x85A0, 0x8640, 0x87B0, 0x8BD0, 0x94C0, 0x9FE0, 0xABE0, 0xB9E0, 0xC750, 0xD560, 0xE300, 0xF070, 0xFCD0, 0x08D0, 0x1400, + 0x1EE0, 0x2D30, 0x3940, 0x4620, 0x5270, 0x5E80, 0x69E0, 0x7410, 0x7CF0, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, + 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, + 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7EF0, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F10, 0x7F20, 0x7F40, + 0x7F30, 0x7F30, 0x7F30, 0x7F40, 0x7F40, 0x7F30, 0x7F40, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F50, 0x7F30, 0x7F40, 0x7F30, + 0x7F30, 0x7F40, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, + 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x76A0, 0x6B60, 0x5F90, 0x54E0, 0x4AC0, 0x4180, 0x39D0, 0x34D0, 0x3220, + 0x3180, 0x3200, 0x3230, 0x3140, 0x2E50, 0x29D0, 0x2520, 0x2070, 0x1CD0, 0x1990, 0x1640, 0x1320, 0x0F50, 0x0B00, 0x0630, 0x01F0, + 0xFC40, 0xF7D0, 0xF510, 0xF420, 0xF6B0, 0xFBF0, 0x01A0, 0x0680, 0x09D0, 0x0990, 0x0760, 0x0320, 0xFE00, 0xF920, 0xF5F0, 0xF3D0, + 0xF230, 0xF0D0, 0xEF70, 0xED90, 0xEBC0, 0xE9B0, 0xE810, 0xE660, 0xE600, 0xE700, 0xEA00, 0xED50, 0xEFF0, 0xEFC0, 0xEB60, 0xE230, + 0xD690, 0xC960, 0xBD40, 0xB230, 0xA9D0, 0xA460, 0x9FC0, 0x9D70, 0x9CD0, 0x9E30, 0xA000, 0xA2B0, 0xA640, 0xA910, 0xABF0, 0xAE80, + 0xB180, 0xB450, 0xB710, 0xB900, 0xBA50, 0xBAD0, 0xBB50, 0xBC60, 0xBD80, 0xBF70, 0xC2E0, 0xC6A0, 0xCA60, 0xCD20, 0xCF10, 0xCFA0, + 0xCE30, 0xCAF0, 0xC5B0, 0xBDB0, 0xB310, 0xA530, 0x9500, 0x8870, 0x8540, 0x84E0, 0x84B0, 0x84A0, 0x8490, 0x8480, 0x8480, 0x8470, + 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8470, 0x8450, 0x8440, 0x8450, 0x8440, 0x8450, 0x8440, 0x8440, 0x83E0, 0x8440, 0x8440, + 0x8450, 0x8440, 0x8440, 0x8440, 0x8430, 0x8440, 0x8430, 0x8460, 0x8440, 0x8440, 0x8440, 0x8460, 0x8440, 0x8440, 0x8430, 0x8440, + 0x8430, 0x8430, 0x83E0, 0x8430, 0x8430, 0x8430, 0x83E0, 0x8430, 0x8430, 0x8440, 0x8430, 0x8430, 0x8430, 0x8400, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8450, 0x8440, 0x8430, 0x8430, 0x8440, 0x8440, 0x8450, 0x8420, 0x8440, 0x8430, 0x8430, 0x83F0, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8440, 0x8430, 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8410, + 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, + 0x8450, 0x8450, 0x8450, 0x8460, 0x8470, 0x8480, 0x8490, 0x84B0, 0x84F0, 0x8560, 0x8970, 0x94E0, 0x9C40, 0x9E50, 0x9C20, 0x95B0, + 0x8D60, 0x87C0, 0x8590, 0x8500, 0x84D0, 0x84C0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, + 0x8480, 0x8490, 0x84A0, 0x84A0, 0x84C0, 0x84F0, 0x8590, 0x8910, 0x9D10, 0xB280, 0xC670, 0xD860, 0xE820, 0xF510, 0x00E0, 0x0980, + 0x10C0, 0x1650, 0x1A60, 0x1D20, 0x2010, 0x2230, 0x2360, 0x2480, 0x24F0, 0x2520, 0x25A0, 0x2570, 0x2630, 0x2620, 0x2760, 0x2830, + 0x28E0, 0x2A40, 0x2B50, 0x2C90, 0x2E30, 0x3040, 0x3390, 0x3780, 0x3BF0, 0x4140, 0x4630, 0x4B80, 0x5060, 0x5510, 0x62C0, 0x6600, + 0x6880, 0x6A20, 0x6CC0, 0x6EC0, 0x7110, 0x7360, 0x75F0, 0x7910, 0x7B20, 0x7CA0, 0x7D80, 0x7E30, 0x7E70, 0x7EC0, 0x7F50, 0x7F10, + 0x7F00, 0x7EF0, 0x7EF0, 0x7F70, 0x7F20, 0x7ED0, 0x7ED0, 0x7EB0, 0x7F20, 0x7F10, 0x7EB0, 0x7EC0, 0x7ED0, 0x7F30, 0x7F20, 0x7EC0, + 0x7ED0, 0x7F10, 0x7F00, 0x7F10, 0x7E90, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F10, + 0x7F20, 0x7F20, 0x7EF0, 0x7F10, 0x7F20, 0x7EF0, 0x7F30, 0x7F20, 0x7F20, 0x7F50, 0x7EF0, 0x7F10, 0x7F00, 0x7F10, 0x7F30, 0x7EE0, + 0x7EF0, 0x7F10, 0x7F20, 0x7F60, 0x7EF0, 0x7EB0, 0x7F00, 0x7F10, 0x7F70, 0x7EE0, 0x7E70, 0x7EF0, 0x7F10, 0x7F30, 0x7F00, 0x7EB0, + 0x7F00, 0x7F20, 0x7F40, 0x7EF0, 0x7EA0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EE0, 0x7EC0, 0x7F10, 0x7F00, 0x7F20, 0x7F40, 0x7F00, 0x7F30, + 0x7EE0, 0x7F10, 0x7F20, 0x7EE0, 0x7F50, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F90, 0x7F00, 0x7F40, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, + 0x7EF0, 0x7F00, 0x7F00, 0x7F90, 0x7F10, 0x7F00, 0x7EF0, 0x7ED0, 0x7F30, 0x7F00, 0x7EA0, 0x7ED0, 0x7EE0, 0x6FC0, 0x5AB0, 0x4400, + 0x2E20, 0x1860, 0x03F0, 0xF230, 0xE1E0, 0xD330, 0xC790, 0xBDF0, 0xB780, 0xB330, 0xB1C0, 0xB440, 0xB9A0, 0xC1B0, 0xCD40, 0xDA90, + 0xE940, 0xF850, 0x07A0, 0x1580, 0x2110, 0x2AB0, 0x3220, 0x3850, 0x4610, 0x4920, 0x4BA0, 0x4D90, 0x5020, 0x5180, 0x5340, 0x53B0, + 0x5460, 0x55C0, 0x56C0, 0x5890, 0x5B40, 0x5D40, 0x6010, 0x6230, 0x6440, 0x66A0, 0x6880, 0x6AB0, 0x6CE0, 0x6E70, 0x7010, 0x70B0, + 0x7120, 0x70E0, 0x7060, 0x6F80, 0x6DC0, 0x6C30, 0x6A70, 0x68F0, 0x6800, 0x65F0, 0x64A0, 0x61D0, 0x5E90, 0x5B00, 0x55E0, 0x5160, + 0x4BD0, 0x45B0, 0x4030, 0x3A10, 0x33A0, 0x2D20, 0x2740, 0x2240, 0x1CA0, 0x1720, 0x1250, 0x0D10, 0x0890, 0x0340, 0xFF10, 0xFB90, + 0xF7E0, 0xF550, 0xF290, 0xF090, 0xEE40, 0xEBA0, 0xE9B0, 0xE800, 0xE650, 0xE580, 0xE460, 0xE4C0, 0xE550, 0xE680, 0xE790, 0xE8E0, + 0xEA00, 0xEB30, 0xEC40, 0xED20, 0xEF50, 0xF290, 0xF5A0, 0xF850, 0xFBA0, 0xFD60, 0xFF10, 0x00B0, 0x01E0, 0x0420, 0x0660, 0x08C0, + 0x0AF0, 0x0CF0, 0x0E70, 0x0F10, 0x1070, 0x1240, 0x1480, 0x1730, 0x1980, 0x1BE0, 0x1DB0, 0x1EA0, 0x2020, 0x2190, 0x2370, 0x2460, + 0x2540, 0x2670, 0x26C0, 0x27C0, 0x2750, 0x25B0, 0x2440, 0x2250, 0x2070, 0x1EB0, 0x1CC0, 0x1BA0, 0x1930, 0x1760, 0x1650, 0x15C0, + 0x1770, 0x1A60, 0x1ED0, 0x2770, 0x3010, 0x39D0, 0x4520, 0x50E0, 0x5C40, 0x66D0, 0x6FB0, 0x7620, 0x7AE0, 0x7DC0, 0x7ED0, 0x7F00, + 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F40, 0x7F30, + 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, + 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, + 0x7F20, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F30, 0x7F30, 0x7F20, 0x7F40, + 0x7F50, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F40, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F60, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, + 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, + 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, + 0x7E60, 0x7A30, 0x7670, 0x7340, 0x7040, 0x6CB0, 0x6820, 0x6240, 0x5AB0, 0x5290, 0x4AD0, 0x45F0, 0x42F0, 0x4220, 0x4300, 0x44F0, + 0x47B0, 0x4B00, 0x4EA0, 0x5330, 0x5740, 0x5C40, 0x6120, 0x6590, 0x6AB0, 0x6F40, 0x7360, 0x76D0, 0x7960, 0x7A40, 0x7970, 0x7710, + 0x7360, 0x6F40, 0x6A30, 0x64F0, 0x5F60, 0x5880, 0x5230, 0x4B90, 0x44C0, 0x3E00, 0x36B0, 0x3010, 0x29E0, 0x2540, 0x2100, 0x1EC0, + 0x1D90, 0x1D80, 0x1DB0, 0x1EC0, 0x20A0, 0x2350, 0x2650, 0x28C0, 0x29D0, 0x2890, 0x24D0, 0x1FE0, 0x1990, 0x12D0, 0x0BB0, 0x0320, + 0xF950, 0xED30, 0xE060, 0xD230, 0xC330, 0xB520, 0xA720, 0x9A50, 0x8FD0, 0x8920, 0x86A0, 0x85B0, 0x8540, 0x8500, 0x84E0, 0x84D0, + 0x84C0, 0x84B0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, + 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84D0, 0x84F0, 0x8510, 0x8550, 0x85D0, 0x8700, 0x89C0, 0x8F90, 0x96F0, 0x9EA0, 0xA5A0, 0xACD0, + 0xB490, 0xBB20, 0xC110, 0xC620, 0xC980, 0xCDC0, 0xD110, 0xD4C0, 0xD880, 0xDAB0, 0xDD80, 0xDF30, 0xE0F0, 0xE240, 0xE350, 0xE640, + 0xE8C0, 0xEB40, 0xEF20, 0xF2C0, 0xF790, 0xFC90, 0x02D0, 0x0900, 0x0FD0, 0x16D0, 0x1D40, 0x23C0, 0x2AD0, 0x3130, 0x3820, 0x3DC0, + 0x4370, 0x4960, 0x4DF0, 0x53B0, 0x58B0, 0x5D60, 0x6190, 0x64F0, 0x67B0, 0x6960, 0x69F0, 0x6A00, 0x67E0, 0x6590, 0x6130, 0x5B30, + 0x5470, 0x4C00, 0x43D0, 0x3B00, 0x30B0, 0x2750, 0x1E60, 0x15C0, 0x0EE0, 0x0890, 0x0460, 0x0100, 0xFDD0, 0xFC20, 0xFB20, 0xFA70, + 0xFAA0, 0xFA60, 0xFA60, 0xF9E0, 0xF9B0, 0xF900, 0xF850, 0xF880, 0xF880, 0xF9A0, 0xF9B0, 0xF990, 0xFAB0, 0xFBA0, 0xFDD0, 0x0020, + 0x0300, 0x0680, 0x0950, 0x0D30, 0x11A0, 0x16D0, 0x1C50, 0x2270, 0x2940, 0x2F80, 0x35E0, 0x3C80, 0x4340, 0x4A30, 0x5190, 0x5760, + 0x5D80, 0x61B0, 0x65A0, 0x6890, 0x6AC0, 0x6D00, 0x6E00, 0x6E50, 0x6E90, 0x6DC0, 0x6D80, 0x6C90, 0x6C00, 0x6A70, 0x6890, 0x67B0, + 0x6620, 0x6500, 0x64D0, 0x64C0, 0x6720, 0x68F0, 0x6C50, 0x7070, 0x75C0, 0x7C40, 0x7EF0, 0x7F60, 0x7EF0, 0x7F30, 0x7F20, 0x7F20, + 0x7F80, 0x7EF0, 0x7EF0, 0x7EE0, 0x7F10, 0x7F70, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F20, 0x7F60, 0x7EE0, 0x7E90, 0x7F00, 0x7F10, 0x7F30, + 0x7EF0, 0x7F60, 0x7F00, 0x7F10, 0x7F00, 0x7EE0, 0x7F70, 0x7EF0, 0x7EB0, 0x7F00, 0x7F10, 0x7F70, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, + 0x7F20, 0x7EE0, 0x7E90, 0x7EE0, 0x7EF0, 0x7F30, 0x7AE0, 0x6E40, 0x61D0, 0x5490, 0x46B0, 0x3A70, 0x2D30, 0x22A0, 0x1960, 0x10C0, + 0x0990, 0x0420, 0x0060, 0xFE40, 0xFC80, 0xFBA0, 0xFBA0, 0xFC80, 0xFD50, 0xFD70, 0xFD50, 0xFB70, 0xF870, 0xF440, 0xEE60, 0xE920, + 0xE320, 0xDDE0, 0xD9F0, 0xD7B0, 0xD6E0, 0xD7C0, 0xD910, 0xDA60, 0xDB40, 0xDB60, 0xDB30, 0xDBC0, 0xDBE0, 0xDC50, 0xDDD0, 0xE060, + 0xE2B0, 0xE600, 0xE910, 0xED40, 0xF110, 0xF560, 0xFA00, 0xFE10, 0x02D0, 0x0640, 0x08D0, 0x0BF0, 0x0E00, 0x0FA0, 0x10C0, 0x1050, + 0x1060, 0x0FC0, 0x0EA0, 0x0CA0, 0x0A00, 0x0790, 0x05F0, 0x02E0, 0x0060, 0xFD30, 0xFA50, 0xF6A0, 0xF2B0, 0xEF30, 0xEC20, 0xE940, + 0xE610, 0xE3F0, 0xE260, 0xE0E0, 0xDFB0, 0xDEA0, 0xDD90, 0xDC70, 0xDB10, 0xD940, 0xD5E0, 0xD270, 0xD000, 0xCE20, 0xCD50, 0xCF10, + 0xD1A0, 0xD500, 0xD8C0, 0xDCE0, 0xDF40, 0xE210, 0xE590, 0xE920, 0xEDF0, 0xF3D0, 0xFA30, 0x0170, 0x0840, 0x0EF0, 0x14F0, 0x19A0, + 0x1D10, 0x2000, 0x21F0, 0x2500, 0x2850, 0x2CF0, 0x3260, 0x3870, 0x3FF0, 0x4670, 0x4D90, 0x5490, 0x5A60, 0x5FC0, 0x6460, 0x6990, + 0x6E70, 0x73A0, 0x7790, 0x7B10, 0x7DA0, 0x7EC0, 0x7F50, 0x7F20, 0x7EE0, 0x7EF0, 0x7F00, 0x7F60, 0x7F10, 0x7E90, 0x7D90, 0x7C60, + 0x7BF0, 0x7C90, 0x7D80, 0x7EC0, 0x7ED0, 0x7F30, 0x7F20, 0x7EC0, 0x7ED0, 0x7F10, 0x7F00, 0x7EF0, 0x7EA0, 0x7EE0, 0x7EF0, 0x7B30, + 0x7790, 0x7400, 0x70E0, 0x6E10, 0x6BB0, 0x6A00, 0x6900, 0x6830, 0x6770, 0x66C0, 0x6710, 0x67A0, 0x6920, 0x6A50, 0x6BA0, 0x6D40, + 0x6EF0, 0x70B0, 0x71B0, 0x7260, 0x72D0, 0x7250, 0x7130, 0x6F90, 0x6CF0, 0x6A90, 0x67E0, 0x6480, 0x6150, 0x5D70, 0x59A0, 0x54C0, + 0x4EF0, 0x4B60, 0x4790, 0x45B0, 0x4500, 0x45F0, 0x4990, 0x5000, 0x5770, 0x5F90, 0x6530, 0x6930, 0x6AC0, 0x6BC0, 0x6B50, 0x6A60, + 0x6A00, 0x6980, 0x68A0, 0x67A0, 0x6450, 0x6050, 0x59A0, 0x2DA0, 0x1E80, 0x1000, 0x0360, 0xF590, 0xE990, 0xDE30, 0xD2D0, 0xC700, + 0xBA10, 0xACE0, 0x9F90, 0x9420, 0x8C30, 0x8860, 0x86F0, 0x8610, 0x85D0, 0x85B0, 0x8590, 0x8590, 0x8560, 0x8540, 0x8540, 0x8530, + 0x8530, 0x8530, 0x8530, 0x8540, 0x8540, 0x8550, 0x8560, 0x8560, 0x8570, 0x8570, 0x8570, 0x8560, 0x8550, 0x8540, 0x8530, 0x8520, + 0x8510, 0x8500, 0x84F0, 0x84E0, 0x84D0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, + 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8470, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, + 0x8480, 0x8480, 0x8490, 0x8480, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, + 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, + 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84C0, + 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84B0, 0x84B0, 0x84D0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84D0, + 0x84D0, 0x84D0, 0x84D0, 0x84E0, 0x84F0, 0x84F0, 0x8500, 0x8520, 0x8530, 0x8560, 0x8590, 0x85E0, 0x8640, 0x86F0, 0x87D0, 0x88E0, + 0x8A60, 0x8C20, 0x8E50, 0x9050, 0x9240, 0x93D0, 0x9520, 0x9660, 0x97B0, 0x98C0, 0x9940, 0x9930, 0x9930, 0x9890, 0x9880, 0x97D0, + 0x97A0, 0x9780, 0x9760, 0x96B0, 0x9560, 0x94E0, 0x9460, 0x93D0, 0x93E0, 0x93B0, 0x93E0, 0x93B0, 0x9410, 0x94A0, 0x95B0, 0x96C0, + 0x98B0, 0x99E0, 0x9BA0, 0x9D70, 0x9FC0, 0xA250, 0xA5B0, 0xA8A0, 0xAB80, 0xAE00, 0xB150, 0xB520, 0xB970, 0xBDC0, 0xC110, 0xC440, + 0xC690, 0xC890, 0xCA30, 0xCD20, 0xCFA0, 0xD2F0, 0xD600, 0xD940, 0xDC30, 0xDE60, 0xE0E0, 0xE310, 0xE530, 0xE7E0, 0xEA60, 0xEC80, + 0xEDD0, 0xEE60, 0xEE70, 0xEDD0, 0xEC70, 0xEA70, 0xE7B0, 0xE430, 0xE010, 0xDB80, 0xD5D0, 0xD0C0, 0xCBB0, 0xC760, 0xC380, 0xBE70, + 0xB8D0, 0xB350, 0xAD40, 0xA6A0, 0xA0F0, 0x9BD0, 0x9690, 0x9200, 0x8DB0, 0x8AA0, 0x88A0, 0x8750, 0x8680, 0x8600, 0x85B0, 0x8580, + 0x8560, 0x8540, 0x8530, 0x8530, 0x8530, 0x8520, 0x8520, 0x8530, 0x8530, 0x8530, 0x8530, 0x8540, 0x8550, 0x8550, 0x8570, 0x8590, + 0x85C0, 0x85E0, 0x8620, 0x8660, 0x86B0, 0x8710, 0x87C0, 0x8880, 0x89E0, 0x8B80, 0x8D30, 0x8F80, 0x9210, 0x9590, 0x98F0, 0x9CC0, + 0xA100, 0xA4C0, 0xA990, 0xAE50, 0xB3F0, 0xBA50, 0xC0B0, 0xC790, 0xCE00, 0xD500, 0xDB40, 0xE130, 0xE770, 0xECD0, 0xF1E0, 0xF6F0, + 0xFAF0, 0xFF30, 0x0340, 0x06B0, 0x0A10, 0x0C80, 0x0F90, 0x1190, 0x1370, 0x1660, 0x1980, 0x1DF0, 0x22E0, 0x26B0, 0x2A80, 0x2DA0, + 0x3180, 0x34C0, 0x36D0, 0x38E0, 0x3940, 0x38D0, 0x3760, 0x3520, 0x31F0, 0x2E00, 0x2A40, 0x25E0, 0x2010, 0x1B00, 0x1560, 0x0FD0, + 0x0A50, 0x0530, 0x0040, 0xFA40, 0xF410, 0xEDD0, 0xE680, 0xE070, 0xD980, 0xD220, 0xCAB0, 0xC2B0, 0xBB80, 0xB3A0, 0xACA0, 0xA670, + 0xA110, 0x9C70, 0x9800, 0x9460, 0x9120, 0x8ED0, 0x8D50, 0x8CE0, 0x8D10, 0x8DB0, 0x8E70, 0x9050, 0x9240, 0x94E0, 0x9800, 0x9B00, + 0x9DD0, 0xA120, 0xA430, 0xA850, 0xABD0, 0xB040, 0xB3D0, 0xB6F0, 0xBA70, 0xBD80, 0xC080, 0xC420, 0xC780, 0xCB60, 0xCE90, 0xD1A0, + 0xD4A0, 0xD710, 0xDA60, 0xDD60, 0xDFF0, 0xE1B0, 0xE2A0, 0xE380, 0xE3A0, 0xE3D0, 0xE4B0, 0xE4E0, 0xE580, 0xE550, 0xE570, 0xE530, + 0xE530, 0xE580, 0xE580, 0xE4C0, 0xE410, 0xE2C0, 0xE1B0, 0xE170, 0xE090, 0xDFF0, 0xDDB0, 0xDBE0, 0xDA00, 0xD7E0, 0xD680, 0xD550, + 0xD480, 0xD350, 0xD180, 0xCF50, 0xCC60, 0xCA90, 0xC880, 0xC720, 0xC5F0, 0xC510, 0xC4D0, 0xC520, 0xC770, 0xCC60, 0xD320, 0xDE40, + 0xEC70, 0xFC30, 0x5030, 0x6230, 0x72F0, 0x7D70, 0x7EC0, 0x7EF0, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7E90, + 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7F60, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F50, 0x7EF0, 0x7F00, 0x7EF0, 0x7F10, 0x7F60, + 0x7EF0, 0x7F30, 0x7F20, 0x7F00, 0x7F50, 0x7EF0, 0x7EF0, 0x7EE0, 0x7F10, 0x7F60, 0x7EE0, 0x7ED0, 0x7F10, 0x7F20, 0x7F60, 0x7ED0, + 0x7E90, 0x7F00, 0x7F10, 0x7F30, 0x7EB0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, + 0x7F20, 0x7EF0, 0x7F10, 0x7F00, 0x7EC0, 0x7F30, 0x7EB0, 0x7B80, 0x78C0, 0x7590, 0x7290, 0x7040, 0x6C30, 0x69B0, 0x66C0, 0x63F0, + 0x6180, 0x5E40, 0x5BA0, 0x5710, 0x51D0, 0x4BC0, 0x4550, 0x3FF0, 0x3A30, 0x34F0, 0x30F0, 0x2CA0, 0x29A0, 0x2760, 0x2550, 0x2410, + 0x22E0, 0x2180, 0x2030, 0x1E70, 0x1DC0, 0x1D10, 0x1D80, 0x1E60, 0x1F50, 0x20E0, 0x2180, 0x2380, 0x2550, 0x26B0, 0x28B0, 0x2A00, + 0x2A80, 0x2AB0, 0x2A20, 0x2A10, 0x2A40, 0x2A80, 0x29F0, 0x2810, 0x2610, 0x2200, 0x1E50, 0x1AB0, 0x1660, 0x1250, 0x0D80, 0x07F0, + 0x0270, 0xFD40, 0xF920, 0xF520, 0xF0F0, 0xEC90, 0xE750, 0xE1C0, 0xDBC0, 0xD590, 0xCF80, 0xC7F0, 0xBFE0, 0xB6A0, 0xACF0, 0xA240, + 0x9690, 0x8C50, 0x8730, 0x8570, 0x8500, 0x8490, 0x84C0, 0x84B0, 0x84A0, 0x8430, 0x8490, 0x8480, 0x8480, 0x8480, 0x8470, 0x8470, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x84B0, + 0x84A0, 0x84A0, 0x84B0, 0x84A0, 0x84C0, 0x84D0, 0x84E0, 0x84E0, 0x84F0, 0x8500, 0x8510, 0x8550, 0x8590, 0x85E0, 0x8650, 0x86F0, + 0x8790, 0x8850, 0x8930, 0x8A30, 0x8BA0, 0x8D10, 0x8EC0, 0x90E0, 0x92F0, 0x9560, 0x9810, 0x9BC0, 0x9ED0, 0xA1F0, 0xA520, 0xA850, + 0xAB50, 0xADB0, 0xB030, 0xB290, 0xB420, 0xB5A0, 0xB650, 0xB690, 0xB670, 0xB640, 0xB5A0, 0xB4E0, 0xB340, 0xB110, 0xAEC0, 0xAC60, + 0xAA80, 0xA810, 0xA610, 0xA330, 0xA070, 0x9CD0, 0x98B0, 0x9580, 0x9280, 0x8F80, 0x8CE0, 0x8B30, 0x8A20, 0x8930, 0x8850, 0x87A0, + 0x8710, 0x86B0, 0x8670, 0x8650, 0x8630, 0x8630, 0x8640, 0x8650, 0x8660, 0x86B0, 0x8700, 0x8760, 0x87A0, 0x8810, 0x88C0, 0x8930, + 0x8A40, 0x8B30, 0x8C00, 0x8D10, 0x8E60, 0x8FC0, 0x9190, 0x9330, 0x9500, 0x9650, 0x9820, 0x9990, 0x9B20, 0x9CF0, 0x9F50, 0xA120, + 0xA330, 0xA500, 0xA680, 0xA890, 0xA9D0, 0xABB0, 0xAD00, 0xADF0, 0xAE20, 0xAE30, 0xAE70, 0xAE50, 0xAE90, 0xAE10, 0xADE0, 0xAD60, + 0xAD00, 0xACD0, 0xAD10, 0xAD60, 0xAD70, 0xADC0, 0xAE70, 0xAF00, 0xB040, 0xB1A0, 0xB370, 0xB5D0, 0xB880, 0xBAE0, 0xBEA0, 0xC2A0, + 0xC7C0, 0xCDD0, 0xD440, 0xDBE0, 0xE3F0, 0xEB40, 0x06E0, 0x0DF0, 0x1410, 0x1A60, 0x2130, 0x2790, 0x2EE0, 0x36F0, 0x3ED0, 0x46C0, + 0x4F10, 0x5750, 0x5EE0, 0x6720, 0x6F50, 0x7670, 0x7C90, 0x7F10, 0x7F30, 0x7F40, 0x7F40, 0x7F50, 0x7F30, 0x7F40, 0x7F40, 0x7F30, + 0x7F40, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F30, 0x7F10, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, + 0x7F40, 0x7F30, 0x7CA0, 0x7360, 0x6AB0, 0x6230, 0x5A30, 0x5260, 0x4B90, 0x44F0, 0x3D60, 0x36C0, 0x3070, 0x2B20, 0x2740, 0x24C0, + 0x22F0, 0x21F0, 0x2140, 0x2180, 0x2190, 0x2280, 0x2340, 0x23F0, 0x2490, 0x25C0, 0x2750, 0x2910, 0x2B20, 0x2D40, 0x2F30, 0x3170, + 0x3360, 0x3560, 0x3680, 0x37D0, 0x38C0, 0x3970, 0x39E0, 0x39F0, 0x3A80, 0x3AF0, 0x3B90, 0x3BE0, 0x3C40, 0x3C80, 0x3C00, 0x3A40, + 0x3800, 0x3480, 0x2FF0, 0x2980, 0x2090, 0x1640, 0x0A10, 0xFBF0, 0xEE70, 0xE0D0, 0xD420, 0xC7F0, 0xBD10, 0xB270, 0xA830, 0x9F60, + 0x9630, 0x8F30, 0x8A90, 0x8800, 0x86A0, 0x85F0, 0x8590, 0x8550, 0x8530, 0x8510, 0x8500, 0x8500, 0x8500, 0x8500, 0x8500, 0x8500, + 0x8510, 0x8510, 0x8530, 0x8510, 0x8510, 0x8510, 0x8530, 0x8530, 0x8540, 0x8570, 0x85C0, 0x8660, 0x8750, 0x88E0, 0x8BF0, 0x9040, + 0x9560, 0x9A40, 0x9F30, 0xA4B0, 0xAAA0, 0xB010, 0xB4D0, 0xB920, 0xBCF0, 0xC070, 0xC3A0, 0xC700, 0xC970, 0xCCE0, 0xCE70, 0xCF70, + 0xCEB0, 0xCD00, 0xCB80, 0xC9E0, 0xC870, 0xC700, 0xC520, 0xC3B0, 0xC190, 0xBF60, 0xBCE0, 0xBA40, 0xB780, 0xB480, 0xB1C0, 0xAF20, + 0xAD70, 0xAC90, 0xABF0, 0xAD00, 0xAEA0, 0xB100, 0xB520, 0xBA30, 0xC030, 0xC5B0, 0xCB60, 0xD1E0, 0xD7C0, 0xDDD0, 0xE490, 0xEAA0, + 0xF110, 0xF780, 0xFD00, 0x0140, 0x0460, 0x0720, 0x0860, 0x0880, 0x0870, 0x0730, 0x06A0, 0x06B0, 0x0830, 0x0BE0, 0x1040, 0x1480, + 0x1750, 0x1720, 0x1480, 0x0EF0, 0x0820, 0x0220, 0xFDF0, 0xFC00, 0xFD30, 0x00C0, 0x0480, 0x07B0, 0x0950, 0x07D0, 0x03A0, 0xFD00, + 0xF490, 0xEB90, 0xE1F0, 0xD860, 0xCF90, 0xC720, 0xC0E0, 0xBCF0, 0xBAD0, 0xB990, 0xB7F0, 0xB7B0, 0xB790, 0xB780, 0xB8D0, 0xBB40, + 0xBF70, 0xC4A0, 0xC9D0, 0xCF10, 0xD330, 0xD720, 0xD940, 0xDB70, 0xDDE0, 0xE0D0, 0xE530, 0xEB60, 0xF2B0, 0xFB20, 0x0390, 0x0C30, + 0x14C0, 0x1B90, 0x2130, 0x2580, 0x2940, 0x2B10, 0x2BB0, 0x2B70, 0x2970, 0x25B0, 0x1FF0, 0x17F0, 0x0DD0, 0x01D0, 0xF6E0, 0xED10, + 0xE6D0, 0xE510, 0xE810, 0xEEF0, 0xF830, 0x0170, 0x0AC0, 0x1150, 0x1750, 0x1B00, 0x1D50, 0x1FF0, 0x2140, 0x2220, 0x23D0, 0x2530, + 0x2730, 0x2940, 0x2B50, 0x2D20, 0x2E80, 0x3080, 0x31C0, 0x32E0, 0x33D0, 0x3430, 0x3530, 0x3520, 0x35A0, 0x3610, 0x3640, 0x38B0, + 0x3B10, 0x3DD0, 0x4100, 0x4390, 0x4510, 0x4430, 0x4080, 0x3B10, 0x3370, 0x2DE0, 0x28D0, 0x25F0, 0x2530, 0x2570, 0x2690, 0x26B0, + 0x2560, 0x21D0, 0x1D70, 0x1750, 0x0F80, 0x0540, 0xFA90, 0xEE60, 0xE210, 0xD650, 0xCB00, 0xC020, 0xB600, 0xAC10, 0xA180, 0x9790, + 0x8FB0, 0x8A20, 0x8780, 0x8670, 0x85B0, 0x8580, 0x8560, 0x8540, 0x8530, 0x8520, 0x8510, 0x8500, 0x84F0, 0x84F0, 0x84F0, 0x84E0, + 0x84E0, 0x84F0, 0x84D0, 0x84D0, 0x84C0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, + 0x84C0, 0x84C0, 0x84C0, 0x84D0, 0x84D0, 0x84E0, 0x84F0, 0x84F0, 0x8500, 0x8500, 0x8500, 0x8510, 0x8510, 0x8510, 0x8500, 0x8500, + 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84D0, + 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84F0, 0x84E0, 0x84E0, + 0x84F0, 0x8500, 0x8530, 0x8550, 0x85B0, 0x86A0, 0x8840, 0x8C20, 0x92A0, 0x9A90, 0xA1E0, 0xA8F0, 0xB020, 0xB610, 0xBB90, 0xC160, + 0xC6C0, 0xCAF0, 0xCF20, 0xD320, 0xD6C0, 0xDA30, 0xDCE0, 0xDF00, 0xDF90, 0xDF80, 0xDDC0, 0xDAF0, 0xD630, 0xCF80, 0xC6C0, 0xBBA0, + 0xAD80, 0x9D40, 0x8E50, 0x8700, 0x8530, 0x84E0, 0x84D0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8470, 0x8470, 0x8470, + 0x8470, 0x8460, 0x8470, 0x8470, 0x84B0, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x84A0, 0x84B0, 0x84D0, 0x84F0, 0x8550, + 0x8670, 0x8A60, 0x9470, 0x9E10, 0xA6B0, 0xADF0, 0xB2F0, 0xB750, 0xBB10, 0xBDE0, 0xBF80, 0xC210, 0xC560, 0xC920, 0xD030, 0xD720, + 0xDEC0, 0xE7C0, 0xF100, 0xFB00, 0x05C0, 0x1000, 0x1B50, 0x27C0, 0x33D0, 0x4030, 0x4D20, 0x5AE0, 0x6750, 0x7320, 0x7BC0, 0x7F10, + 0x7F20, 0x7F20, 0x7F60, 0x7F10, 0x7F20, 0x7F00, 0x7EF0, 0x7F50, 0x7EF0, 0x7390, 0x6670, 0x5860, 0x4B60, 0x3FD0, 0x3610, 0x2FD0, + 0x2C00, 0x2A40, 0x2B00, 0x2DA0, 0x3210, 0x3710, 0x3DB0, 0x46C0, 0x51C0, 0x5F50, 0x6E00, 0x7C50, 0x7ED0, 0x7EA0, 0x7EE0, 0x7EF0, + 0x7F10, 0x7F20, 0x7EC0, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7EB0, 0x7F20, 0x7EE0, 0x7EF0, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F20, + 0x7F40, 0x7F10, 0x7F90, 0x7F00, 0x7F20, 0x7EF0, 0x7F00, 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7F00, 0x7F80, 0x7F10, 0x7EB0, 0x7F10, + 0x7EF0, 0x7F70, 0x7F20, 0x7ED0, 0x7ED0, 0x7EE0, 0x7F30, 0x7F10, 0x7EB0, 0x7EE0, 0x7ED0, 0x7F10, 0x7F00, 0x7E70, 0x7ED0, 0x7F10, + 0x7F20, 0x7EF0, 0x7E90, 0x7F00, 0x7F20, 0x7F10, 0x7E90, 0x6200, 0x4A60, 0x3740, 0x2710, 0x1C70, 0x1200, 0x08C0, 0x0080, 0xF900, + 0xF4E0, 0xF200, 0xF0F0, 0xF0A0, 0xEFF0, 0xEE60, 0xEA80, 0xE490, 0xDCF0, 0xD2C0, 0xC660, 0xB780, 0xA4A0, 0x9160, 0x86D0, 0x8510, + 0x84D0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, + 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84E0, 0x8510, 0x85C0, 0x8840, 0x91A0, 0x9DA0, 0xA7F0, 0xB220, 0xBB50, + 0xC520, 0xCF70, 0xDB20, 0xE6F0, 0xF420, 0x00D0, 0x0DF0, 0x1B80, 0x27A0, 0x3390, 0x3FD0, 0x4B60, 0x5770, 0x63E0, 0x7010, 0x7A50, + 0x7F00, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7910, 0x6DF0, 0x61B0, 0x5740, 0x4BB0, 0x4140, 0x36C0, 0x2C10, 0x2100, 0x15B0, 0x09A0, + 0xFD70, 0xF160, 0xE440, 0xD920, 0xCE50, 0xC350, 0xB880, 0xACE0, 0xA170, 0x9680, 0x8D80, 0x87F0, 0x8600, 0x8550, 0x8510, 0x8530, + 0x84E0, 0x84E0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84E0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, + 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x8500, 0x8500, 0x8510, 0x8520, 0x8540, 0x8560, 0x85A0, 0x8600, 0x8680, 0x8760, 0x8890, 0x8AA0, + 0x8D70, 0x9180, 0x9600, 0x9A90, 0x9F10, 0xAC50, 0xAF40, 0xB290, 0xB5C0, 0xB840, 0xBA80, 0xBC30, 0xBDA0, 0xBE40, 0xBEA0, 0xBE70, + 0xBDD0, 0xBCF0, 0xBAD0, 0xB9A0, 0xB7D0, 0xB620, 0xB570, 0xB4F0, 0xB5E0, 0xB6B0, 0xB790, 0xB870, 0xB9B0, 0xBA20, 0xBA10, 0xB980, + 0xB990, 0xB950, 0xB8F0, 0xB8D0, 0xB820, 0xB790, 0xB620, 0xB4C0, 0xB2E0, 0xB190, 0xAFF0, 0xAE80, 0xACA0, 0xAB50, 0xAB20, 0xAAF0, + 0xAAD0, 0xAAE0, 0xAAF0, 0xAAE0, 0xAAA0, 0xAB30, 0xABA0, 0xAC90, 0xADB0, 0xAEA0, 0xAF60, 0xB050, 0xB120, 0xB200, 0xB370, 0xB4F0, + 0xB620, 0xB620, 0xB650, 0xB650, 0xB650, 0xB5F0, 0xB4F0, 0xB440, 0xB2A0, 0xB140, 0xAFC0, 0xAE40, 0xAD80, 0xACD0, 0xABB0, 0xAA10, + 0xA8C0, 0xA600, 0xA3E0, 0xA1F0, 0xA010, 0x9DC0, 0x9B10, 0x9760, 0x93C0, 0x9030, 0x8C90, 0x8A00, 0x8800, 0x86B0, 0x85D0, 0x8560, + 0x8520, 0x84F0, 0x84E0, 0x84D0, 0x84C0, 0x84E0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8480, + 0x8480, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x8490, 0x8490, + 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x8490, 0x8490, 0x84A0, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, + 0x84B0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84A0, 0x84B0, 0x84B0, + 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x8480, 0x84C0, + 0x84C0, 0x84C0, 0x8490, 0x84D0, 0x84E0, 0x84E0, 0x8510, 0x84F0, 0x8500, 0x8540, 0x8530, 0x8560, 0x85A0, 0x8620, 0x86F0, 0x8800, + 0x8990, 0x8BD0, 0x8ED0, 0x91C0, 0x9390, 0x9550, 0x9610, 0x9490, 0x91B0, 0x8D30, 0x8970, 0x86E0, 0x85A0, 0x8530, 0x8500, 0x84D0, + 0x84D0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84D0, 0x84F0, 0x8520, 0x85C0, 0x87E0, 0x9030, + 0x9D90, 0xAC30, 0xB8B0, 0xC410, 0xCF70, 0xD8B0, 0xE0A0, 0xE780, 0xEED0, 0xF5D0, 0xFC80, 0x0310, 0x09D0, 0x1010, 0x16C0, 0x1D00, + 0x2350, 0x2A40, 0x3160, 0x3B10, 0x4440, 0x4F00, 0x5A70, 0x6600, 0x72B0, 0x7C70, 0x7F50, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F60, + 0x7F00, 0x7F10, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F70, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F60, 0x7ED0, + 0x7E90, 0x7F00, 0x7EE0, 0x7EF0, 0x7F10, 0x7EA0, 0x7F40, 0x74F0, 0x71A0, 0x7340, 0x7910, 0x7EB0, 0x7E90, 0x7F10, 0x7EF0, 0x7EF0, + 0x7F10, 0x7EA0, 0x6000, 0x3B80, 0x1650, 0xF320, 0xD640, 0xBBD0, 0xA370, 0x8D10, 0x8590, 0x84E0, 0x84A0, 0x8490, 0x8470, 0x8460, + 0x8460, 0x8450, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8450, 0x8450, 0x8470, 0x8480, 0x84A0, + 0x84D0, 0x8510, 0x85A0, 0x8760, 0x8D50, 0x9A80, 0xAA50, 0xBC20, 0xCF10, 0xE290, 0xF390, 0x03B0, 0x11A0, 0x1E20, 0x2A00, 0x3480, + 0x3F70, 0x4980, 0x5410, 0x5D00, 0x6440, 0x6B70, 0x7040, 0x7480, 0x7760, 0x7890, 0x7990, 0x7840, 0x75C0, 0x71D0, 0x6B60, 0x6460, + 0x5C50, 0x53B0, 0x49F0, 0x4060, 0x3690, 0x2E70, 0x26A0, 0x1FE0, 0x1A10, 0x1570, 0x11A0, 0x0D40, 0x0910, 0x0300, 0xFCC0, 0xF5B0, + 0xEE30, 0xE660, 0xDD60, 0xD580, 0xCD80, 0xC660, 0xBFA0, 0xB9E0, 0xB4C0, 0xAFB0, 0xAA70, 0xA6A0, 0xA400, 0xA390, 0xA4C0, 0xA940, + 0xAF90, 0xB760, 0xBE80, 0xC490, 0xC8F0, 0xCC10, 0xCD40, 0xCCF0, 0xCBB0, 0xCA20, 0xC8D0, 0xC7B0, 0xC7A0, 0xC6A0, 0xC3D0, 0xBE90, + 0xB7B0, 0xAED0, 0xA680, 0x9FB0, 0x9A60, 0x9680, 0x9270, 0x8FD0, 0x8D80, 0x8C00, 0x8B30, 0x8B00, 0x8B60, 0x8CB0, 0x8F80, 0x9520, + 0x9E00, 0xA9C0, 0xB6B0, 0xC680, 0xD3F0, 0xE0B0, 0xEC20, 0xF6A0, 0x00D0, 0x0A30, 0x11B0, 0x17C0, 0x1930, 0x17E0, 0x1380, 0x0CB0, + 0x05A0, 0xFF40, 0xF9C0, 0xF5B0, 0xF290, 0xF260, 0xF380, 0xF5D0, 0xF900, 0xFC80, 0x00D0, 0x0580, 0x0AC0, 0x1140, 0x1900, 0x2100, + 0x2840, 0x2ED0, 0x3570, 0x3AC0, 0x4080, 0x4610, 0x4BB0, 0x51C0, 0x5650, 0x5AF0, 0x5FA0, 0x63F0, 0x6810, 0x6C30, 0x7100, 0x74E0, + 0x78B0, 0x7B70, 0x7DC0, 0x7EF0, 0x7F10, 0x7F60, 0x7EE0, 0x7E90, 0x7F00, 0x7F10, 0x7F30, 0x7EB0, 0x7E70, 0x7EF0, 0x7F10, 0x7F30, + 0x7F20, 0x7EC0, 0x7F10, 0x7F20, 0x7F30, 0x7F10, 0x7EB0, 0x7F20, 0x7EF0, 0x7F10, 0x7F30, 0x7EC0, 0x7F30, 0x7F10, 0x7F20, 0x7F40, + 0x7F10, 0x7F70, 0x7EE0, 0x7F10, 0x7F20, 0x7F00, 0x7F70, 0x7EF0, 0x7F20, 0x7F10, 0x7F00, 0x7F90, 0x7F00, 0x7F40, 0x7EF0, 0x7EF0, + 0x7F60, 0x7EF0, 0x7ED0, 0x7EF0, 0x7F00, 0x7F50, 0x7F10, 0x7EE0, 0x7EE0, 0x7ED0, 0x7F30, 0x7F00, 0x7E90, 0x7ED0, 0x7F10, 0x7EF0, + 0x7F10, 0x7EB0, 0x7EE0, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F00, 0x7EF0, 0x7EC0, 0x7F20, 0x7F20, 0x7F40, 0x7F10, + 0x7F10, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7F50, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F60, 0x7F00, 0x7ED0, 0x7F00, 0x7EF0, + 0x7EF0, 0x7EF0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7EF0, + 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7EE0, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F30, + 0x7F30, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F50, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F40, 0x7F40, 0x7F30, + 0x7F30, 0x7F20, 0x7F30, 0x7B50, 0x7570, 0x6FE0, 0x6A80, 0x6690, 0x63A0, 0x6240, 0x6180, 0x6190, 0x6320, 0x6540, 0x6750, 0x6A30, + 0x6CE0, 0x7030, 0x72B0, 0x75B0, 0x7800, 0x79C0, 0x7B10, 0x7BF0, 0x7C60, 0x7C70, 0x7BF0, 0x7B60, 0x7AC0, 0x7A50, 0x79F0, 0x7940, + 0x7840, 0x7790, 0x76E0, 0x7600, 0x7550, 0x7530, 0x7530, 0x7440, 0x73D0, 0x7350, 0x72E0, 0x7290, 0x7250, 0x72E0, 0x7320, 0x73C0, + 0x7450, 0x74B0, 0x74E0, 0x7590, 0x7610, 0x76E0, 0x77E0, 0x7990, 0x7AF0, 0x7C60, 0x7DA0, 0x7E50, 0x7EE0, 0x7F20, 0x7F30, 0x7F10, + 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F00, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7EF0, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F00, 0x7F20, + 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F40, 0x7F30, 0x7DA0, 0x7740, 0x7050, 0x6930, 0x62A0, 0x5C00, + 0x5490, 0x4DB0, 0x4740, 0x4160, 0x3B70, 0x3570, 0x2F60, 0x28E0, 0x21C0, 0x1940, 0x11A0, 0x0A90, 0x0430, 0xFEB0, 0xF970, 0xF450, + 0xEF90, 0xE9E0, 0xE420, 0xDF10, 0xD990, 0xD470, 0xD080, 0xCC50, 0xC950, 0xC600, 0xC350, 0xC0B0, 0xBE30, 0xBB90, 0xB910, 0xB6B0, + 0xB570, 0xB540, 0xB4C0, 0xB4A0, 0xB8D0, 0xBA60, 0xBCE0, 0xBFB0, 0xC230, 0xC520, 0xC770, 0xCAC0, 0xCDC0, 0xD150, 0xD4E0, 0xD720, + 0xD950, 0xDB70, 0xDBE0, 0xDD00, 0xDD20, 0xDD10, 0xDC80, 0xDB80, 0xDB50, 0xDAE0, 0xDC00, 0xDC80, 0xDCE0, 0xDDE0, 0xDDE0, 0xDDE0, + 0xDD40, 0xDD00, 0xDDF0, 0xDEB0, 0xDF30, 0xE010, 0xE110, 0xE230, 0xE310, 0xE330, 0xE3C0, 0xE300, 0xE2B0, 0xE150, 0xDF90, 0xDD20, + 0xDA00, 0xD690, 0xD220, 0xCD80, 0xC840, 0xC260, 0xBD20, 0xB7F0, 0xB310, 0xAEA0, 0xAA10, 0xA5F0, 0xA200, 0x9E90, 0x9A90, 0x9760, + 0x9530, 0x9340, 0x9120, 0x8FE0, 0x8FC0, 0x8F90, 0x8FD0, 0x9070, 0x91D0, 0x9310, 0x9490, 0x9690, 0x99A0, 0x9D70, 0xA120, 0xA550, + 0xA9B0, 0xAE80, 0xB370, 0xB900, 0xBE90, 0xC530, 0xCB60, 0xD120, 0xD640, 0xDBA0, 0xE0A0, 0xE590, 0xEB30, 0xF070, 0xF670, 0xFBB0, + 0xFFE0, 0x04A0, 0x0970, 0x0DB0, 0x11F0, 0x15A0, 0x1970, 0x1C90, 0x1FF0, 0x2280, 0x2530, 0x2790, 0x28E0, 0x29D0, 0x2AD0, 0x2AC0, + 0x2B00, 0x2A90, 0x2960, 0x27C0, 0x25F0, 0x2450, 0x21B0, 0x1EC0, 0x1C40, 0x1890, 0x1500, 0x1090, 0x0CB0, 0x0980, 0x0640, 0x03F0, + 0x01B0, 0xFF00, 0xFCC0, 0xF950, 0xF700, 0xF3F0, 0xF170, 0xF070, 0xEF00, 0xEDF0, 0xED50, 0xEC30, 0xEB80, 0xEA80, 0xEA10, 0xEA20, + 0xE980, 0xE910, 0xE890, 0xE860, 0xE830, 0xE860, 0xE8D0, 0xE8D0, 0xE8D0, 0xE8D0, 0xE830, 0xE840, 0xE7D0, 0xE680, 0xE540, 0xE440, + 0xE3E0, 0xE340, 0xE230, 0xE170, 0xDFB0, 0xDEE0, 0xDD20, 0xDB30, 0xDAA0, 0xD910, 0xD920, 0xD920, 0xD940, 0xD940, 0xD8D0, 0xD910, + 0xD950, 0xD9D0, 0xDAE0, 0xDBA0, 0xDCC0, 0xDE10, 0xDF30, 0xE060, 0xE160, 0xE230, 0xE260, 0xE1F0, 0xE1B0, 0xE130, 0xE100, 0xE0D0, + 0xE0A0, 0xE0C0, 0xDFF0, 0xDF70, 0xDE40, 0xDC90, 0xDB70, 0xDAA0, 0xD940, 0xD560, 0xD4A0, 0xD440, 0xD310, 0xD2A0, 0xD210, 0xD120, + 0xD010, 0xCE40, 0xCD30, 0xCC70, 0xCB70, 0xCAA0, 0xC9C0, 0xC980, 0xC880, 0xC7E0, 0xC7B0, 0xC720, 0xC730, 0xC6E0, 0xC740, 0xC8A0, + 0xC9D0, 0xCBA0, 0xCDE0, 0xD040, 0xD360, 0xD5D0, 0xD870, 0xDB60, 0xDE90, 0xE310, 0xE780, 0xEC90, 0xF190, 0xF620, 0xFB20, 0xFF80, + 0x04F0, 0x0B20, 0x10A0, 0x1790, 0x1EC0, 0x2580, 0x2C80, 0x32B0, 0x39B0, 0x4000, 0x45D0, 0x4B30, 0x50A0, 0x56F0, 0x5B70, 0x5F60, + 0x6260, 0x6490, 0x6670, 0x66A0, 0x65C0, 0x6490, 0x62E0, 0x61E0, 0x6040, 0x5EF0, 0x5DC0, 0x5BD0, 0x5A50, 0x5890, 0x5660, 0x5450, + 0x51F0, 0x5070, 0x4EF0, 0x4D10, 0x4C00, 0x4A40, 0x49D0, 0x48C0, 0x4740, 0x4660, 0x44B0, 0x4380, 0x41C0, 0x4090, 0x40D0, 0x4180, + 0x42C0, 0x4500, 0x4690, 0x4980, 0x4C00, 0x4F10, 0x5230, 0x5500, 0x5810, 0x5B10, 0x5E20, 0x6140, 0x63F0, 0x6700, 0x6980, 0x6CB0, + 0x6F90, 0x71A0, 0x7470, 0x77B0, 0x7AE0, 0x7D60, 0x7ED0, 0x7F10, 0x7F20, 0x7F70, 0x7EF0, 0x7EB0, 0x7F00, 0x7F10, 0x7F30, 0x7EE0, + 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7EF0, 0x7EA0, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7EC0, + 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F10, 0x7F20, 0x7EF0, 0x7F50, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F70, + 0x7F10, 0x7F10, 0x7F10, 0x7EE0, 0x7F70, 0x7F10, 0x7F00, 0x7F00, 0x7EF0, 0x7F70, 0x7F20, 0x7EF0, 0x7ED0, 0x7EB0, 0x7F30, 0x7EF0, + 0x7EB0, 0x7ED0, 0x7ED0, 0x7F30, 0x7F20, 0x7EA0, 0x7ED0, 0x7F10, 0x7F00, 0x7F00, 0x7EC0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, + 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, 0x7F20, 0x7F00, 0x7EF0, 0x7F10, 0x7F60, 0x7F20, 0x7F10, 0x7F20, 0x7F00, 0x7F50, + 0x7EF0, 0x7F20, 0x7EE0, 0x7EF0, 0x7F80, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7F80, 0x7ED0, 0x7EB0, 0x7EF0, 0x7EF0, 0x7F50, 0x7EE0, + 0x7EC0, 0x7EF0, 0x7F10, 0x7F30, 0x7EE0, 0x7E90, 0x7E70, 0x6C20, 0x5750, 0x42B0, 0x2CE0, 0x16A0, 0xFF90, 0xE850, 0xD400, 0xC160, + 0xB3D0, 0xA920, 0xA380, 0xA340, 0xA630, 0xACC0, 0xB790, 0xC590, 0xD750, 0xEB20, 0x0250, 0x1830, 0x2D00, 0x3F40, 0x4C10, 0x5170, + 0x4E20, 0x40F0, 0x2CD0, 0x12E0, 0xFA00, 0xE510, 0xD380, 0xC590, 0xB820, 0xA990, 0x9980, 0x8BB0, 0x8610, 0x8520, 0x84F0, 0x84E0, + 0x84D0, 0x84D0, 0x84C0, 0x84B0, 0x84A0, 0x84C0, 0x84C0, 0x8480, 0x8470, 0x8490, 0x8480, 0x8490, 0x84B0, 0x8510, 0x8540, 0x8630, + 0x8810, 0x8A00, 0x89F0, 0x88F0, 0x87A0, 0x8690, 0x85D0, 0x8540, 0x8510, 0x84F0, 0x84E0, 0x84D0, 0x84E0, 0x8500, 0x8570, 0x8630, + 0x8A20, 0x95C0, 0xA100, 0xA910, 0xAEA0, 0xB220, 0xB610, 0xBAD0, 0xC1A0, 0xCA20, 0xD380, 0xDCC0, 0xE3D0, 0xE790, 0xE830, 0xE550, + 0xE100, 0xDD30, 0xDB00, 0xDB90, 0xDED0, 0xE4F0, 0xED60, 0xF760, 0x0400, 0x1080, 0x1D40, 0x2A00, 0x35D0, 0x41F0, 0x4DC0, 0x5910, + 0x6350, 0x6C20, 0x7240, 0x75D0, 0x7840, 0x79D0, 0x7B10, 0x7C00, 0x7C70, 0x7CC0, 0x7BF0, 0x7AA0, 0x77C0, 0x72D0, 0x6C90, 0x6470, + 0x5AA0, 0x5090, 0x45B0, 0x3B00, 0x3240, 0x2A80, 0x2520, 0x20E0, 0x1E50, 0x1E00, 0x1F90, 0x21F0, 0x23F0, 0x2530, 0x2470, 0x2240, + 0x1DD0, 0x17F0, 0x1160, 0x09E0, 0x0110, 0xF5A0, 0xE960, 0xDA40, 0xC810, 0xB4F0, 0xA1D0, 0x9080, 0x8810, 0x85D0, 0x8540, 0x8520, + 0x8500, 0x84E0, 0x84D0, 0x84B0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, + 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84D0, 0x84D0, 0x84E0, 0x84F0, 0x8500, 0x8520, 0x8550, 0x8590, 0x8630, 0x8770, + 0x89A0, 0x8E80, 0x96D0, 0x9E40, 0xA600, 0xAF00, 0xB710, 0xBFD0, 0xC720, 0xCE60, 0xD440, 0xD8D0, 0xDBF0, 0xDEE0, 0xE240, 0xE590, + 0xE9A0, 0xEEC0, 0xF480, 0xFAF0, 0x0320, 0x0A70, 0x1040, 0x1490, 0x1640, 0x1540, 0x12E0, 0x0ED0, 0x0AA0, 0x06C0, 0x0400, 0x0230, + 0x00E0, 0xFE40, 0xFAB0, 0xF520, 0xEEA0, 0xE770, 0xDF40, 0xD880, 0xD220, 0xCCF0, 0xC960, 0xC6A0, 0xC4F0, 0xC410, 0xC3D0, 0xC4C0, + 0xC570, 0xC650, 0xC760, 0xC900, 0xCB70, 0xCED0, 0xD250, 0xD6A0, 0xDB20, 0xDF50, 0xE320, 0xE730, 0xEAB0, 0xEE00, 0xF120, 0xF440, + 0xF790, 0xFB60, 0xFE40, 0x00D0, 0x0220, 0x02A0, 0x0290, 0x0210, 0x02B0, 0x0400, 0x0790, 0x0C00, 0x10E0, 0x1710, 0x1C10, 0x2100, + 0x25C0, 0x2AD0, 0x3030, 0x35F0, 0x3B10, 0x3FF0, 0x4410, 0x4860, 0x4B70, 0x4F10, 0x5300, 0x55E0, 0x59B0, 0x5BA0, 0x5DC0, 0x5E50, + 0x5ED0, 0x6020, 0x60C0, 0x6200, 0x6390, 0x64C0, 0x6610, 0x6580, 0x6460, 0x63A0, 0x6180, 0x60B0, 0x6030, 0x5FE0, 0x5FF0, 0x5FF0, + 0x6070, 0x5F50, 0x5D30, 0x5A20, 0x5580, 0x5050, 0x4A10, 0x41E0, 0x3910, 0x30B0, 0x27E0, 0x1DE0, 0x12C0, 0x06A0, 0xF880, 0xE920, + 0xD580, 0xC160, 0xAC30, 0x84F0, 0x84D0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, + 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x8480, 0x84C0, 0x84C0, 0x84D0, 0x84E0, 0x8500, 0x8510, 0x8530, + 0x8550, 0x8590, 0x8600, 0x86B0, 0x87F0, 0x8A50, 0x8E60, 0x9420, 0x99D0, 0x9F00, 0xA500, 0xAB00, 0xB120, 0xB7C0, 0xBD60, 0xC300, + 0xC830, 0xCD70, 0xD210, 0xD710, 0xDCD0, 0xE270, 0xE8B0, 0xEEF0, 0xF4A0, 0xFA80, 0x00B0, 0x0670, 0x0D40, 0x13B0, 0x1AF0, 0x2160, + 0x2750, 0x2CB0, 0x3120, 0x35F0, 0x3A80, 0x3D30, 0x4020, 0x4240, 0x44B0, 0x44E0, 0x4510, 0x4550, 0x4530, 0x4520, 0x4470, 0x4450, + 0x4410, 0x43C0, 0x4410, 0x4460, 0x4460, 0x45C0, 0x4650, 0x4710, 0x4820, 0x48E0, 0x4990, 0x4900, 0x48A0, 0x47C0, 0x46F0, 0x4700, + 0x4680, 0x4590, 0x4490, 0x4180, 0x3F90, 0x3CB0, 0x3A30, 0x38E0, 0x36F0, 0x3610, 0x3500, 0x3320, 0x31D0, 0x3100, 0x30D0, 0x3090, + 0x3130, 0x3230, 0x3360, 0x3550, 0x3830, 0x3BE0, 0x4010, 0x44F0, 0x4B00, 0x5180, 0x5890, 0x7700, 0x7D80, 0x7F00, 0x7F00, 0x7EF0, + 0x7ED0, 0x7F30, 0x7F00, 0x7EB0, 0x7EE0, 0x7EE0, 0x7F10, 0x7F10, 0x7E70, 0x7520, 0x6960, 0x5BB0, 0x4E30, 0x4200, 0x3750, 0x2DD0, + 0x22B0, 0x1820, 0x0BC0, 0xFE00, 0xEE20, 0xDA30, 0xC750, 0xB3A0, 0xA0A0, 0x9110, 0x88E0, 0x8650, 0x85A0, 0x8570, 0x8570, 0x8580, + 0x85D0, 0x8670, 0x8820, 0x8CC0, 0x9540, 0x9EF0, 0xA820, 0xB190, 0xBA50, 0xC270, 0xCA70, 0xD270, 0xD9F0, 0xE240, 0xE9C0, 0xF050, + 0xF500, 0xF6A0, 0xF530, 0xF060, 0xE960, 0xE280, 0xDC80, 0xD930, 0xD9C0, 0xDDF0, 0xE430, 0xEBF0, 0xF380, 0xF8F0, 0xFB10, 0xF880, + 0xF1C0, 0xE810, 0xDA20, 0xCCC0, 0xC0D0, 0xB5B0, 0xAD60, 0xA690, 0xA110, 0x9BE0, 0x9680, 0x9110, 0x8D00, 0x8A30, 0x88D0, 0x8840, + 0x88D0, 0x8A80, 0x8E20, 0x93F0, 0x9B70, 0xA300, 0xAAE0, 0xB2A0, 0xB9E0, 0xC190, 0xC990, 0xD110, 0xD7F0, 0xDF50, 0xE580, 0xEB20, + 0xF040, 0xF4F0, 0xFA90, 0x0020, 0x06F0, 0x0D30, 0x13A0, 0x19F0, 0x1E90, 0x22F0, 0x26A0, 0x2950, 0x2CD0, 0x3000, 0x3400, 0x38F0, + 0x3D40, 0x4200, 0x45C0, 0x49B0, 0x4C20, 0x4D00, 0x4E90, 0x4ED0, 0x4E70, 0x4D80, 0x4C80, 0x4B80, 0x4B80, 0x4D80, 0x5070, 0x5520, + 0x5A60, 0x6010, 0x64B0, 0x68A0, 0x6AF0, 0x6CD0, 0x6DC0, 0x6EC0, 0x6F90, 0x7110, 0x73E0, 0x7650, 0x7930, 0x7BB0, 0x7D40, 0x7E40, + 0x7E80, 0x7D30, 0x79F0, 0x7390, 0x6BA0, 0x6160, 0x5510, 0x4930, 0x3CE0, 0x3180, 0x26D0, 0x1BF0, 0x12A0, 0x0950, 0x0060, 0xF680, + 0xEC40, 0xE1C0, 0xD730, 0xCC20, 0xC040, 0xB290, 0xA410, 0x9420, 0x8870, 0x8540, 0x84E0, 0x84E0, 0x84A0, 0x8490, 0x8480, 0x8470, + 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8490, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, + 0x8490, 0x84A0, 0x84A0, 0x84F0, 0x84C0, 0x84D0, 0x84F0, 0x8540, 0x8610, 0x8800, 0x8BC0, 0x90E0, 0x92A0, 0x9240, 0x8FB0, 0x8CD0, + 0x8A40, 0x8830, 0x8710, 0x8670, 0x8620, 0x85F0, 0x8600, 0x8630, 0x86B0, 0x87B0, 0x89F0, 0x8EE0, 0x9670, 0x9F90, 0xA7D0, 0xAFA0, + 0xB560, 0xB9D0, 0xBC60, 0xBCE0, 0xBBF0, 0xB9A0, 0xB5E0, 0xB1D0, 0xAD70, 0xA8B0, 0xA460, 0x9FB0, 0x9B10, 0x96C0, 0x92E0, 0x8F10, + 0x8C30, 0x89F0, 0x88B0, 0x87F0, 0x8790, 0x8780, 0x87B0, 0x8820, 0x88D0, 0x89A0, 0x8A90, 0x8C30, 0x8E50, 0x9170, 0x9590, 0x9940, + 0x9E40, 0xA260, 0xA530, 0xA840, 0xA9F0, 0xAAE0, 0xABF0, 0xADC0, 0xB020, 0xB2B0, 0xB530, 0xB840, 0xBB40, 0xBDF0, 0xC0B0, 0xC370, + 0xC5F0, 0xC870, 0xCB20, 0xCDD0, 0xD080, 0xD3C0, 0xD7D0, 0xDBF0, 0xDFF0, 0xE370, 0xE660, 0xE810, 0xE910, 0xE9A0, 0xE9E0, 0xE980, + 0xE930, 0xE8A0, 0xE850, 0xE7E0, 0xE780, 0xE730, 0xE6E0, 0xE590, 0xE4B0, 0xE3E0, 0xE380, 0xE3B0, 0xE490, 0xE510, 0xE680, 0xE680, + 0xE680, 0xE650, 0xE680, 0xE630, 0xE560, 0xE4D0, 0xE480, 0xE440, 0xE3A0, 0xE310, 0xE330, 0xE3D0, 0xE4C0, 0xE610, 0xE720, 0xE830, + 0xE930, 0xEA80, 0xEBC0, 0xED00, 0xEDB0, 0xEDD0, 0xEE20, 0xEDD0, 0xEDD0, 0xED90, 0xECC0, 0xEBD0, 0xEA90, 0xE990, 0xE870, 0xE770, + 0xE6D0, 0xE5C0, 0xE4C0, 0xE450, 0xE3D0, 0xE3E0, 0xE400, 0xE4D0, 0xE580, 0xE660, 0xE750, 0xE870, 0xE9E0, 0xEBE0, 0xEDB0, 0xF080, + 0xF2D0, 0xF620, 0xF980, 0xFD90, 0x00C0, 0x0490, 0x0830, 0x0BB0, 0x0EE0, 0x1260, 0x16F0, 0x1AA0, 0x1E70, 0x2270, 0x25B0, 0x27A0, + 0x29C0, 0x2BB0, 0x2D30, 0x2EE0, 0x3090, 0x31E0, 0x3340, 0x3480, 0x35F0, 0x36D0, 0x37E0, 0x3A00, 0x3C90, 0x3F80, 0x4420, 0x4980, + 0x4F50, 0x5670, 0x5DB0, 0x64F0, 0x6B90, 0x71E0, 0x7690, 0x7A00, 0x7B70, 0x7BB0, 0x7A80, 0x7740, 0x7230, 0x6B70, 0x6250, 0x58B0, + 0x4D40, 0x4220, 0x36C0, 0x2C50, 0x2280, 0x1AA0, 0x13A0, 0x0CE0, 0x06C0, 0xFF20, 0xF650, 0xEB20, 0xDCE0, 0xCAC0, 0xB470, 0x9A80, + 0x86E0, 0x84E0, 0x84A0, 0x8480, 0x8490, 0x8460, 0x8450, 0x8440, 0x8430, 0x8430, 0x8420, 0x8410, 0x8400, 0x8400, 0x83F0, 0x83E0, + 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83B0, 0x83B0, 0x83B0, 0x83A0, 0x83A0, 0x8390, 0x8390, 0x83A0, 0x8380, + 0x8380, 0x8370, 0x8370, 0x8370, 0x8360, 0x8390, 0x8360, 0x8360, 0x8360, 0x8370, 0x8360, 0x8360, 0x8360, 0x8360, 0x8360, 0x8360, + 0x8390, 0x83A0, 0x8370, 0x8380, 0x83B0, 0x8390, 0x8380, 0x8390, 0x8390, 0x8380, 0x8380, 0x83B0, 0x8380, 0x8380, 0x8380, 0x8390, + 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x83A0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, + 0x83D0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8410, 0x8410, 0x8420, 0x8420, 0x8470, 0x8430, 0x8430, 0x8440, + 0x8430, 0x8440, 0x8450, 0x8460, 0x8460, 0x8470, 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84D0, 0x84D0, 0x84D0, 0x84C0, 0x84C0, 0x84D0, + 0x84E0, 0x84E0, 0x8500, 0x8550, 0x86B0, 0x94F0, 0xAFF0, 0xCBD0, 0xE440, 0xF480, 0xFAF0, 0xF8E0, 0xF170, 0xEA90, 0xE560, 0xE4F0, + 0xE8F0, 0xEEF0, 0xF6E0, 0xFE40, 0x03D0, 0x0810, 0x09A0, 0x0A30, 0x08D0, 0x0760, 0x05E0, 0x04D0, 0x05E0, 0x0900, 0x0E40, 0x1650, + 0x2000, 0x2B80, 0x3910, 0x46B0, 0x5660, 0x6650, 0x7590, 0x7EE0, 0x7F20, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F00, + 0x7F50, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F70, 0x7F20, 0x7F40, 0x7F10, 0x7EF0, 0x7F60, 0x7F10, 0x7F10, 0x7EF0, 0x7EF0, 0x7F80, + 0x7F10, 0x7F00, 0x7F00, 0x7F10, 0x7F30, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F70, 0x7EF0, + 0x7EB0, 0x7EF0, 0x7EF0, 0x7F50, 0x7EF0, 0x7EA0, 0x7F00, 0x7F10, 0x7F30, 0x7EE0, 0x7E90, 0x7F00, 0x7EF0, 0x7EF0, 0x7F10, 0x7F00, + 0x7F00, 0x7EF0, 0x7EF0, 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F30, 0x7EF0, 0x7F00, 0x7F10, 0x7F20, 0x7F10, + 0x7EB0, 0x7F20, 0x7EE0, 0x7EF0, 0x7F30, 0x7F20, 0x7F60, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F90, 0x7F00, 0x7F00, 0x7EF0, 0x7EF0, + 0x7F80, 0x7F10, 0x7EF0, 0x7EE0, 0x7EE0, 0x7F50, 0x7F10, 0x7EA0, 0x7EC0, 0x7EF0, 0x7F60, 0x7F20, 0x7E90, 0x7EB0, 0x7EE0, 0x7EF0, + 0x7EF0, 0x7EB0, 0x7EC0, 0x7ED0, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7F10, + 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7F10, 0x7F30, 0x7EF0, 0x7F00, 0x7ED0, 0x7F10, 0x7F60, 0x7F00, 0x7F30, 0x7F00, 0x7F00, + 0x7F50, 0x7EF0, 0x7EE0, 0x7EE0, 0x7ED0, 0x7F70, 0x7EE0, 0x7ED0, 0x7F10, 0x7F20, 0x7F60, 0x7ED0, 0x7E90, 0x7EE0, 0x7EF0, 0x7F30, + 0x7EC0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7EC0, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, 0x7F00, 0x7EF0, 0x7F20, 0x7F20, + 0x7F10, 0x7F30, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7EF0, 0x7F90, 0x7F10, 0x7F20, 0x7F00, 0x7EF0, + 0x7F70, 0x7F00, 0x7EE0, 0x7EF0, 0x7EE0, 0x7F70, 0x7F10, 0x7EE0, 0x7F00, 0x7EE0, 0x7F30, 0x7F10, 0x7ED0, 0x7ED0, 0x7EB0, 0x7F20, + 0x7EF0, 0x7E90, 0x7EE0, 0x7F20, 0x7E60, 0x7890, 0x7160, 0x6A80, 0x6380, 0x5CB0, 0x57C0, 0x5300, 0x5010, 0x4DB0, 0x4BE0, 0x4C50, + 0x4B80, 0x4B80, 0x4B00, 0x4910, 0x4830, 0x4670, 0x4460, 0x41B0, 0x3FB0, 0x3E60, 0x3C50, 0x39F0, 0x3770, 0x3500, 0x32D0, 0x30B0, + 0x2EC0, 0x2D50, 0x2AB0, 0x2840, 0x2560, 0x2230, 0x1E90, 0x1B20, 0x1840, 0x1390, 0x1040, 0x0D80, 0x0AF0, 0x0910, 0x0740, 0x05C0, + 0x0550, 0x0530, 0x0590, 0x0590, 0x0570, 0x0620, 0x06B0, 0x0750, 0x07F0, 0x08C0, 0x0A40, 0x0C00, 0x0E60, 0x0FF0, 0x1190, 0x1380, + 0x15E0, 0x1890, 0x1AD0, 0x1C70, 0x1E80, 0x1F60, 0x1EA0, 0x1C20, 0x1770, 0x1110, 0x0890, 0xFF60, 0xF4D0, 0xE830, 0xDC40, 0xCF00, + 0xC090, 0xB190, 0xA1A0, 0x9250, 0x8850, 0x8570, 0x84F0, 0x84D0, 0x84B0, 0x84A0, 0x84A0, 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, + 0x8460, 0x8470, 0x8450, 0x8450, 0x8450, 0x8460, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, + 0x84E0, 0x84B0, 0x84C0, 0x84E0, 0x8520, 0x85D0, 0x8980, 0x9930, 0xAAE0, 0xBCE0, 0xCFD0, 0xE110, 0xF2B0, 0x0420, 0x16B0, 0x2930, + 0x3BF0, 0x4E60, 0x60D0, 0x7500, 0x7EE0, 0x7F50, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7ED0, 0x7EF0, 0x7EE0, 0x7F50, + 0x7ED0, 0x7EB0, 0x7F00, 0x7F10, 0x7F10, 0x7EF0, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, + 0x7F20, 0x7F10, 0x7F10, 0x5FF0, 0x3260, 0x0190, 0xD6B0, 0xAE80, 0x8C40, 0x8500, 0x84B0, 0x8490, 0x8470, 0x8470, 0x8460, 0x8460, + 0x8450, 0x8460, 0x8460, 0x8470, 0x8480, 0x8490, 0x84B0, 0x84C0, 0x84F0, 0x8530, 0x8620, 0x8A00, 0x9670, 0xA1E0, 0xAAE0, 0xB280, + 0xBC70, 0xC970, 0xDC30, 0xF4C0, 0x1260, 0x33A0, 0x5350, 0x6D10, 0x7B90, 0x7EC0, 0x7A50, 0x67B0, 0x4A40, 0x2740, 0x0180, 0xDA90, + 0xAE80, 0x8750, 0x84B0, 0x8470, 0x8450, 0x8440, 0x8430, 0x8420, 0x8420, 0x8410, 0x8410, 0x8400, 0x83F0, 0x83F0, 0x83E0, 0x83E0, + 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, + 0x83F0, 0x8400, 0x8400, 0x8410, 0x83F0, 0x8410, 0x8410, 0x8400, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8430, 0x83F0, 0x8430, + 0x8440, 0x83F0, 0x8450, 0x8450, 0x8460, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84D0, 0x8520, 0x86F0, + 0x9880, 0xB440, 0xCE20, 0xE650, 0xFD20, 0x1260, 0x2630, 0x38C0, 0x4A90, 0x59D0, 0x6840, 0x7500, 0x7E30, 0x7F30, 0x7F20, 0x7F20, + 0x7F10, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F10, 0x7F30, + 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, + 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F00, 0x7F50, 0x7F30, 0x7F20, 0x7F10, 0x7F10, 0x7F30, + 0x7F40, 0x7F10, 0x7EB0, 0x7EB0, 0x7EE0, 0x7ED0, 0x7F30, 0x7F00, 0x7F00, 0x7F30, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F60, 0x7EE0, + 0x7ED0, 0x7F10, 0x7EF0, 0x7F50, 0x7F20, 0x7EC0, 0x7F20, 0x7EF0, 0x7F10, 0x7EE0, 0x7E70, 0x7F10, 0x7EE0, 0x7F20, 0x7ED0, 0x7EB0, + 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F00, 0x7EC0, 0x7F30, 0x7F00, 0x7F20, 0x7F20, 0x7F00, 0x7F40, + 0x7ED0, 0x7F10, 0x7F30, 0x7EE0, 0x7F80, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, 0x7F10, + 0x7EF0, 0x7EE0, 0x7EF0, 0x7F50, 0x7F20, 0x7EC0, 0x7ED0, 0x7EB0, 0x7F60, 0x7F10, 0x7EB0, 0x7EB0, 0x7EC0, 0x7F10, 0x7F20, 0x7EA0, + 0x7F00, 0x7EF0, 0x7F20, 0x7F20, 0x7E90, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F50, + 0x7F10, 0x7F20, 0x7EF0, 0x7F00, 0x7F20, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, + 0x7EF0, 0x7EF0, 0x7F10, 0x7F60, 0x7F00, 0x7F00, 0x7F00, 0x7F10, 0x7F50, 0x7EB0, 0x7E70, 0x7EF0, 0x7EF0, 0x7F30, 0x7ED0, 0x7E90, + 0x7F10, 0x7F20, 0x7F40, 0x7ED0, 0x7EB0, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7F40, 0x7F00, 0x7F30, + 0x7F10, 0x7F10, 0x7F30, 0x7F00, 0x7F40, 0x7EF0, 0x7F20, 0x7F20, 0x7F00, 0x7F80, 0x7F00, 0x7F40, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, + 0x7ED0, 0x7F00, 0x7EE0, 0x7F80, 0x7F10, 0x7F00, 0x7F00, 0x7ED0, 0x7F30, 0x7F00, 0x7EA0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7EB0, + 0x7EC0, 0x7F00, 0x7F10, 0x7F10, 0x7EC0, 0x7ED0, 0x7F10, 0x7F00, 0x7EF0, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F40, + 0x7F10, 0x7F10, 0x7EF0, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F00, 0x7EE0, 0x7F40, 0x7F40, 0x7F10, 0x7F10, 0x7EE0, + 0x7F60, 0x7ED0, 0x7F20, 0x7F00, 0x7EF0, 0x7F50, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F70, 0x7EE0, 0x7EC0, 0x7EF0, 0x7EE0, 0x7F70, + 0x7EF0, 0x7F20, 0x7F20, 0x7EF0, 0x7F70, 0x7EE0, 0x7F10, 0x7EF0, 0x7EF0, 0x7F70, 0x7F10, 0x7F00, 0x7F00, 0x7EF0, 0x7F30, 0x7F10, + 0x7F00, 0x7F00, 0x7EF0, 0x7F30, 0x7F00, 0x7EA0, 0x7ED0, 0x7EF0, 0x7F30, 0x7EF0, 0x7EB0, 0x7EE0, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, + 0x7F00, 0x7F10, 0x7F00, 0x7F20, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7EE0, 0x7F50, + 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F70, 0x7F20, 0x7F40, 0x7F10, 0x7F00, 0x7F60, 0x7EE0, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F90, 0x7F00, + 0x7EE0, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7EB0, 0x7EF0, 0x7EE0, 0x7F30, 0x7ED0, 0x7EB0, 0x7F00, 0x7F10, 0x7F10, 0x79E0, 0x7110, + 0x6680, 0x5990, 0x4920, 0x3850, 0x2580, 0x11A0, 0xFBE0, 0xE2F0, 0xCA50, 0xAF80, 0x9470, 0x8660, 0x84E0, 0x84B0, 0x8490, 0x8480, + 0x8480, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8440, 0x8430, 0x83E0, 0x8430, 0x8420, 0x8420, 0x8410, 0x8400, 0x8400, 0x83B0, + 0x8400, 0x8400, 0x8420, 0x8410, 0x8410, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8450, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8460, 0x8460, 0x8470, 0x8480, + 0x84D0, 0x84A0, 0x84B0, 0x84D0, 0x84F0, 0x85B0, 0x88F0, 0x9530, 0xA320, 0xB0A0, 0xBBA0, 0xC530, 0xCCB0, 0xD120, 0xD390, 0xD470, + 0xD360, 0xD220, 0xD010, 0xCD30, 0xCA90, 0xC830, 0xC710, 0xC200, 0xB060, 0x8FE0, 0x84E0, 0x8490, 0x8460, 0x8430, 0x8430, 0x8420, + 0x8410, 0x8400, 0x8400, 0x83E0, 0x8400, 0x83E0, 0x83E0, 0x83D0, 0x83F0, 0x83C0, 0x83C0, 0x83A0, 0x83B0, 0x83C0, 0x83C0, 0x83B0, + 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83A0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83D0, 0x83E0, 0x83F0, + 0x83F0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8420, + 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x83E0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83D0, + 0x83C0, 0x83C0, 0x83B0, 0x83B0, 0x83B0, 0x83D0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83D0, 0x83D0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, + 0x8400, 0x8400, 0x8400, 0x8410, 0x8420, 0x8420, 0x8430, 0x8440, 0x8440, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8480, 0x84B0, + 0x84B0, 0x84C0, 0x84F0, 0x8530, 0x85C0, 0x87B0, 0x8F00, 0x9D10, 0xAB20, 0xB880, 0xC430, 0xCF00, 0xD640, 0xDB10, 0xDDB0, 0xDEE0, + 0xDFE0, 0xE0A0, 0xE150, 0xE0F0, 0xDE50, 0xD7F0, 0xCD20, 0xBCE0, 0xA810, 0x9000, 0x85A0, 0x84D0, 0x84A0, 0x8490, 0x8480, 0x8480, + 0x8470, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8460, 0x8490, 0x8470, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84D0, + 0x8510, 0x8670, 0x9510, 0xB180, 0xCF10, 0xEE60, 0x0FA0, 0x32B0, 0x5900, 0x7760, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, + 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, + 0x7F40, 0x7F30, 0x7F30, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F00, 0x7F40, 0x7F30, + 0x7F30, 0x7F20, 0x7F00, 0x7F10, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, + 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F50, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F30, + 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, + 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F30, 0x7F70, 0x7F20, 0x7EC0, 0x7F00, + 0x7F10, 0x7EF0, 0x7EF0, 0x7E70, 0x7EF0, 0x7EC0, 0x7EE0, 0x7ED0, 0x7E80, 0x7EE0, 0x7F00, 0x7F10, 0x7F10, 0x7EC0, 0x7ED0, 0x7F10, + 0x7F00, 0x7EF0, 0x7F00, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F30, 0x7F10, 0x7F10, 0x7EE0, 0x7EF0, 0x7F10, 0x7F10, 0x7EF0, + 0x7EF0, 0x7F10, 0x7F60, 0x7F00, 0x7F10, 0x7F00, 0x7EE0, 0x7F40, 0x7EF0, 0x7EE0, 0x7F40, 0x7F10, 0x7F40, 0x7F00, 0x7EC0, 0x7EF0, + 0x7F00, 0x7F50, 0x7ED0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7EA0, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7E90, 0x7F00, 0x7EE0, + 0x7EF0, 0x7F10, 0x7F00, 0x7EF0, 0x7EF0, 0x7F20, 0x7F20, 0x7F00, 0x7F50, 0x7F00, 0x7F20, 0x7EF0, 0x7F00, 0x7F40, 0x7EF0, 0x7F30, + 0x7F20, 0x7F00, 0x7F90, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F70, 0x7EE0, 0x73F0, 0x6290, 0x50E0, 0x3EF0, 0x2D50, 0x19F0, 0x09A0, + 0xFA40, 0xECB0, 0xE230, 0xD960, 0xD340, 0xCD90, 0xC9D0, 0xC810, 0xC650, 0xC630, 0xC660, 0xC660, 0xC6F0, 0xC750, 0xC800, 0xC860, + 0xC810, 0xC820, 0xC760, 0xC6D0, 0xC6C0, 0xC6E0, 0xC8E0, 0xCB40, 0xCE30, 0xD1C0, 0xD440, 0xD730, 0xD9E0, 0xDBC0, 0xDD50, 0xDED0, + 0xE0E0, 0xE2E0, 0xE5D0, 0xE910, 0xEC50, 0xEF90, 0xF200, 0xF3A0, 0xF4B0, 0xF480, 0xF3E0, 0xF2C0, 0xF0F0, 0xEF60, 0xECE0, 0xEA80, + 0xE7F0, 0xE4A0, 0xE1F0, 0xDEC0, 0xDB90, 0xD800, 0xD4D0, 0xD180, 0xCE10, 0xCBA0, 0xC8E0, 0xC5D0, 0xC360, 0xBFA0, 0xBD80, 0xBB10, + 0xB8E0, 0xB6D0, 0xB4A0, 0xB310, 0xB120, 0xAF10, 0xACD0, 0xAAE0, 0xA8D0, 0xA6F0, 0xA510, 0xA320, 0x9FF0, 0x9C70, 0x9900, 0x94F0, + 0x9140, 0x8D70, 0x8A10, 0x87E0, 0x8680, 0x85C0, 0x8560, 0x8520, 0x8500, 0x8520, 0x84E0, 0x84E0, 0x84C0, 0x84C0, 0x84C0, 0x84D0, + 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84D0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84C0, 0x84B0, + 0x84B0, 0x84C0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84C0, 0x84E0, 0x84C0, 0x84C0, 0x84C0, 0x84D0, 0x84E0, 0x84D0, 0x8500, 0x8530, + 0x8580, 0x8650, 0x8830, 0x8CA0, 0x9400, 0x9CB0, 0xA430, 0xAC10, 0xB370, 0xBA90, 0xC390, 0xCBD0, 0xD580, 0xDEC0, 0xE840, 0xF210, + 0xFC10, 0x06B0, 0x1140, 0x1CB0, 0x26A0, 0x2FC0, 0x39F0, 0x4290, 0x4A70, 0x5260, 0x58D0, 0x5F30, 0x6480, 0x6890, 0x6C90, 0x7020, + 0x7440, 0x7890, 0x7BB0, 0x7E30, 0x7EC0, 0x7F10, 0x7F20, 0x7F40, 0x7E90, 0x7EB0, 0x7F00, 0x7EF0, 0x7EF0, 0x7F20, 0x7EC0, 0x7F10, + 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F00, 0x7F20, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F30, 0x7F20, 0x7F00, 0x7F50, 0x7F10, + 0x7F40, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7EF0, 0x7EF0, 0x7F00, 0x7F60, 0x7F10, 0x7F00, 0x7EE0, 0x7ED0, 0x7F30, 0x7F00, 0x7EA0, + 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7ED0, 0x7F00, 0x7EE0, 0x7F50, 0x7EF0, 0x7EB0, 0x7F00, 0x7F10, 0x7F70, 0x7ED0, 0x7EB0, 0x7F00, + 0x7EF0, 0x7F30, 0x7F00, 0x7EC0, 0x7F10, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7F40, 0x7F10, + 0x7F10, 0x7F20, 0x7EF0, 0x7F90, 0x7F10, 0x7F20, 0x7F10, 0x7F00, 0x7F70, 0x7F10, 0x7F10, 0x7EF0, 0x7EE0, 0x7F70, 0x7F10, 0x7EE0, + 0x7EF0, 0x7EF0, 0x7F70, 0x7F00, 0x7ED0, 0x7EB0, 0x7EB0, 0x7EF0, 0x7EF0, 0x7E70, 0x7EC0, 0x7ED0, 0x7F10, 0x7F20, 0x7EC0, 0x7ED0, + 0x7F10, 0x7F00, 0x7F10, 0x7E90, 0x7EE0, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F30, 0x7F20, + 0x7F20, 0x7EF0, 0x7F10, 0x7F60, 0x7F10, 0x7F30, 0x7F20, 0x7F00, 0x7F50, 0x7EF0, 0x7F00, 0x7EF0, 0x7ED0, 0x7F30, 0x7EE0, 0x7EF0, + 0x7F10, 0x7F20, 0x7F70, 0x7ED0, 0x7EB0, 0x7EF0, 0x7F10, 0x7F30, 0x7EE0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7E90, 0x7F00, + 0x7F10, 0x7F10, 0x7F00, 0x7EA0, 0x7EF0, 0x7EF0, 0x7F20, 0x7F20, 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, + 0x7F10, 0x7F20, 0x7EF0, 0x7F50, 0x7F10, 0x7F20, 0x7F30, 0x7F10, 0x7F70, 0x7D20, 0x5D10, 0x40B0, 0x2400, 0x0840, 0xEE30, 0xD660, + 0xC1C0, 0xAF00, 0x9F50, 0x9250, 0x8B60, 0x8820, 0x86D0, 0x85F0, 0x85D0, 0x8580, 0x8550, 0x8510, 0x84F0, 0x84D0, 0x84F0, 0x84B0, + 0x84A0, 0x8490, 0x84B0, 0x8480, 0x8470, 0x8430, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, + 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84E0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, + 0x8490, 0x84A0, 0x8490, 0x8480, 0x8480, 0x8460, 0x8470, 0x8470, 0x8480, 0x8470, 0x8460, 0x8460, 0x8450, 0x8460, 0x8490, 0x8410, + 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8440, 0x8470, 0x8440, 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, + 0x8450, 0x8450, 0x8450, 0x8460, 0x8470, 0x8470, 0x8470, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84E0, 0x8520, 0x85B0, + 0x87B0, 0x8E70, 0x9950, 0xA330, 0xAAD0, 0xB040, 0xB350, 0xB4B0, 0xB570, 0xB470, 0xB260, 0xAF80, 0xABD0, 0xA810, 0xA2B0, 0x9D40, + 0x96B0, 0x9070, 0x8B90, 0x8860, 0x86D0, 0x8600, 0x85D0, 0x8570, 0x8560, 0x8560, 0x8590, 0x85C0, 0x8650, 0x87A0, 0x8B40, 0x9380, + 0x9F10, 0xAAB0, 0xB620, 0xC0D0, 0xC940, 0xCF80, 0xD360, 0xD4B0, 0xD360, 0xCFB0, 0xCA90, 0xC3B0, 0xBAE0, 0xB010, 0xA330, 0x94A0, + 0x89A0, 0x85B0, 0x84F0, 0x84D0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8480, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, + 0x8460, 0x8460, 0x8460, 0x8470, 0x8480, 0x8490, 0x84B0, 0x84F0, 0x8670, 0x9DC0, 0xBF90, 0xE0F0, 0x03B0, 0x2A70, 0x4E90, 0x6FD0, + 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F70, 0x7F20, 0x7F10, 0x7F30, + 0x7F00, 0x7F50, 0x7EF0, 0x7F00, 0x7F20, 0x7F10, 0x7F30, 0x7F10, 0x7F10, 0x7ED0, 0x7EB0, 0x7F20, 0x7EF0, 0x7F10, 0x7F00, 0x7F20, + 0x7F60, 0x7F10, 0x7F20, 0x7F10, 0x7EF0, 0x7F30, 0x7F30, 0x7EC0, 0x7ED0, 0x7EE0, 0x7F40, 0x7F50, 0x7EB0, 0x7F00, 0x7EE0, 0x7B80, + 0x6630, 0x4E00, 0x3540, 0x1B30, 0x0420, 0xEFA0, 0xDC00, 0xC950, 0xB610, 0xA220, 0x8FB0, 0x8710, 0x8530, 0x84F0, 0x84E0, 0x84E0, + 0x84E0, 0x84F0, 0x8530, 0x8570, 0x8600, 0x8730, 0x8900, 0x8BE0, 0x8E70, 0x90B0, 0x9230, 0x9310, 0x92D0, 0x9180, 0x8FF0, 0x8E30, + 0x8D40, 0x8C70, 0x8C10, 0x8C20, 0x8BD0, 0x8B80, 0x8B70, 0x8BB0, 0x8C20, 0x8CA0, 0x8D70, 0x8F10, 0x90C0, 0x9300, 0x9530, 0x9680, + 0x97B0, 0x9880, 0x99F0, 0x9B50, 0x9CB0, 0x9E20, 0x9FA0, 0xA0B0, 0xA1D0, 0xA220, 0xA290, 0xA2E0, 0xA370, 0xA3F0, 0xA300, 0xA160, + 0x9F00, 0x9B60, 0x96B0, 0x9150, 0x8BC0, 0x87E0, 0x85E0, 0x8530, 0x84F0, 0x84D0, 0x84C0, 0x84B0, 0x8490, 0x8490, 0x8480, 0x8470, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, 0x8470, 0x8470, 0x8480, 0x84A0, 0x84E0, 0x8790, 0xB3E0, 0xE6B0, 0x1220, 0x37F0, + 0x5850, 0x7100, 0x7E70, 0x7EF0, 0x7F10, 0x7F20, 0x7EC0, 0x7ED0, 0x7F10, 0x7F20, 0x7F10, 0x7E90, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, + 0x7EA0, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F50, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7F00, + 0x7F80, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F70, 0x7EE0, 0x7ED0, 0x7F10, 0x7F20, 0x7F70, 0x7EF0, 0x7BB0, 0x4AA0, 0x1F10, 0xF790, + 0xD690, 0xBB30, 0xA890, 0x9D10, 0x9B60, 0xA110, 0xAB60, 0xB7E0, 0xC2A0, 0xCAA0, 0xCE90, 0xCCA0, 0xC730, 0xC110, 0xBB30, 0xB9E0, + 0xBCE0, 0xC510, 0xD2E0, 0xE370, 0xF380, 0x0080, 0x0800, 0x12E0, 0x1A70, 0x24E0, 0x31C0, 0x4090, 0x4F10, 0x5D30, 0x6960, 0x7390, + 0x7C80, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F50, 0x7F00, 0x7F20, 0x7EF0, 0x7F00, 0x7F60, 0x7EF0, 0x7F30, 0x7F20, + 0x7F00, 0x7F90, 0x7F10, 0x7EF0, 0x7F10, 0x7EF0, 0x7F70, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F00, 0x7F60, 0x7F10, 0x7EE0, 0x7F00, 0x7EF0, + 0x7F30, 0x7F00, 0x7E70, 0x7EC0, 0x7EF0, 0x7F10, 0x7EF0, 0x7E90, 0x7ED0, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, + 0x7F00, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F30, 0x7F40, 0x7F10, 0x7F10, 0x7EE0, 0x7F50, 0x7F10, 0x7F20, 0x7F20, + 0x7F10, 0x7F70, 0x7F00, 0x7F40, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7EF0, 0x7F10, 0x7EF0, 0x7F80, 0x7F00, 0x7EE0, 0x7F00, 0x7F10, + 0x7F30, 0x7EE0, 0x7EA0, 0x7EF0, 0x7E20, 0x7C40, 0x7A50, 0x7800, 0x75E0, 0x7440, 0x7210, 0x7100, 0x6F20, 0x6DD0, 0x6CB0, 0x6B70, + 0x6B20, 0x6A00, 0x6910, 0x6820, 0x6700, 0x6650, 0x6520, 0x63C0, 0x6290, 0x60B0, 0x5F70, 0x5D60, 0x5AD0, 0x58B0, 0x54E0, 0x5190, + 0x4D30, 0x4820, 0x4340, 0x3DD0, 0x38B0, 0x32E0, 0x2D20, 0x2730, 0x20E0, 0x1B10, 0x1490, 0x0F30, 0x09A0, 0x04A0, 0x00D0, 0xFCD0, + 0xF790, 0xF250, 0xEBF0, 0xE5F0, 0xDED0, 0xD6F0, 0xD050, 0xC880, 0xC0C0, 0xB780, 0xAE90, 0xA650, 0x9DB0, 0x95C0, 0x8E60, 0x8960, + 0x86C0, 0x85B0, 0x8530, 0x8500, 0x84E0, 0x84E0, 0x84D0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84D0, 0x84E0, 0x8500, 0x8530, + 0x85E0, 0x8800, 0x8F90, 0x9BF0, 0xA910, 0xB400, 0xBBF0, 0xC1F0, 0xC5F0, 0xC820, 0xC760, 0xC4E0, 0xC0F0, 0xBAB0, 0xB450, 0x9DA0, + 0x9A10, 0x99F0, 0x9BA0, 0xA080, 0xA7D0, 0xB060, 0xBBE0, 0xC770, 0xD500, 0xE250, 0xF090, 0xFFB0, 0x0EC0, 0x1E70, 0x2E00, 0x3E90, + 0x4E50, 0x5C70, 0x69C0, 0x7410, 0x7BB0, 0x7F00, 0x7EC0, 0x7EC0, 0x7EE0, 0x7F30, 0x7F10, 0x7E90, 0x7EB0, 0x7EF0, 0x7EF0, 0x7F10, + 0x7F00, 0x7ED0, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F10, 0x7F00, 0x7F00, 0x7EF0, 0x7EC0, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F00, + 0x7F50, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F30, 0x7EF0, 0x7EF0, 0x7F10, 0x7F00, 0x7F70, 0x7EF0, 0x7F20, 0x7F00, 0x7F10, 0x7F70, + 0x7EE0, 0x7EC0, 0x7EF0, 0x7F10, 0x7F30, 0x7ED0, 0x7EB0, 0x7F00, 0x7F00, 0x7F50, 0x7ED0, 0x7EA0, 0x7EE0, 0x7EF0, 0x7F20, 0x7EE0, + 0x7E90, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7EE0, 0x7EF0, 0x7F20, 0x7F10, 0x7F10, 0x7F20, + 0x7F00, 0x7F10, 0x7F30, 0x7F20, 0x7F10, 0x7F10, 0x7EB0, 0x63E0, 0x4780, 0x2A10, 0x0D20, 0xF1F0, 0xD980, 0xC490, 0xB480, 0xA5F0, + 0x99A0, 0x8EC0, 0x87D0, 0x8590, 0x8510, 0x84E0, 0x84D0, 0x84D0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84C0, 0x84B0, 0x8490, 0x8480, + 0x8470, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8430, 0x8430, 0x8420, + 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x83E0, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, + 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84C0, 0x84E0, 0x8500, 0x8550, + 0x8680, 0x8AB0, 0x9790, 0xA740, 0xB7D0, 0xC880, 0xDA50, 0xEC20, 0xFD00, 0x0D50, 0x1B80, 0x2760, 0x31F0, 0x3B10, 0x4470, 0x4DC0, + 0x5810, 0x6310, 0x6E40, 0x7820, 0x7E90, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F40, + 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, + 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, + 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F80, 0x7F20, + 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7EF0, 0x7EE0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7EE0, 0x7EC0, 0x7EF0, 0x7F20, 0x7F20, 0x7EF0, + 0x7ED0, 0x7F10, 0x7F20, 0x7EF0, 0x7EB0, 0x7F20, 0x7EF0, 0x7F30, 0x7F20, 0x7EC0, 0x7C40, 0x6680, 0x4C30, 0x3370, 0x1AB0, 0x0580, + 0xF3A0, 0xE4D0, 0xDA50, 0xD220, 0xCC10, 0xC650, 0xC180, 0xBC50, 0xB5C0, 0xADD0, 0xA560, 0x9CC0, 0x9520, 0x8EA0, 0x89F0, 0x8790, + 0x8640, 0x85B0, 0x84F0, 0x8530, 0x8520, 0x8510, 0x8540, 0x8510, 0x8510, 0x8530, 0x8570, 0x85B0, 0x86B0, 0x8980, 0x90A0, 0x9A40, + 0xA450, 0xAD50, 0xB630, 0xBE70, 0xC660, 0xCF10, 0xD7F0, 0xE0E0, 0xE940, 0xF1D0, 0xF8D0, 0xFE80, 0x0310, 0x0750, 0x0B30, 0x0EE0, + 0x10F0, 0x1250, 0x1400, 0x1450, 0x1470, 0x13E0, 0x11C0, 0x0F90, 0x0D30, 0x0B00, 0x0960, 0x0830, 0x0890, 0x09A0, 0x0B80, 0x0EA0, + 0x1230, 0x16C0, 0x1B80, 0x2010, 0x24E0, 0x28F0, 0x2DB0, 0x3250, 0x36A0, 0x3B50, 0x3FF0, 0x4570, 0x49C0, 0x4D90, 0x5070, 0x5300, + 0x56C0, 0x59F0, 0x5D70, 0x6100, 0x6440, 0x67B0, 0x6AE0, 0x6D90, 0x70B0, 0x7340, 0x7680, 0x7980, 0x7BB0, 0x7DE0, 0x7E70, 0x7F10, + 0x7F00, 0x7F20, 0x7ED0, 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F00, 0x7ED0, 0x7F30, 0x7F00, + 0x7F40, 0x7F30, 0x7F00, 0x7F60, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7F80, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7F10, + 0x7EF0, 0x7EE0, 0x7F60, 0x7F10, 0x7EE0, 0x7EE0, 0x7ED0, 0x7F70, 0x7F20, 0x7EC0, 0x7ED0, 0x7EB0, 0x7F60, 0x7EF0, 0x7E90, 0x7EB0, + 0x7EE0, 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, 0x7F00, 0x7F20, 0x7F20, 0x7E90, 0x7F00, 0x7F00, 0x7F00, 0x7EF0, 0x7F00, 0x7F00, 0x7F10, + 0x7F20, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F60, 0x7EB0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F30, + 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7F50, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F60, 0x7F00, + 0x7F10, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7EB0, 0x7EF0, 0x7EF0, 0x7F70, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7EB0, + 0x7EE0, 0x7EF0, 0x7F30, 0x7F00, 0x7EA0, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7E90, 0x7F10, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, + 0x7F10, 0x7D60, 0x70A0, 0x62E0, 0x5510, 0x4760, 0x3A20, 0x2DF0, 0x2110, 0x1520, 0x06F0, 0xF880, 0xE770, 0xD2C0, 0xBB10, 0xA190, + 0x8AB0, 0x84F0, 0x84D0, 0x84B0, 0x84A0, 0x8490, 0x8480, 0x8480, 0x8480, 0x84B0, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, 0x8480, + 0x8480, 0x8470, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8430, 0x8430, 0x8420, 0x8420, 0x8410, 0x8400, + 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, 0x8400, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8450, 0x8460, 0x8470, 0x8480, 0x8490, 0x84A0, 0x84C0, 0x84D0, 0x8500, 0x8570, 0x8760, + 0x9100, 0x9F00, 0xA8E0, 0xAE20, 0xAE30, 0xA9D0, 0xA180, 0x9750, 0x8D00, 0x8720, 0x8550, 0x84F0, 0x84C0, 0x84C0, 0x8490, 0x8490, + 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8480, 0x8450, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, 0x8410, 0x8410, + 0x8400, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, + 0x8430, 0x8430, 0x8420, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, + 0x8490, 0x8480, 0x84A0, 0x84B0, 0x84C0, 0x84D0, 0x84E0, 0x8500, 0x8520, 0x8580, 0x8650, 0x8830, 0x8CF0, 0x93F0, 0x9BC0, 0xA250, + 0xA920, 0xAE40, 0xB340, 0xB830, 0xBC30, 0xC090, 0xC3F0, 0xC710, 0xCA40, 0xCC10, 0xCD50, 0xCDE0, 0xCDF0, 0xCED0, 0xCFD0, 0xD100, + 0xD230, 0xD330, 0xD450, 0xD560, 0xD600, 0xD5D0, 0xD4C0, 0xD400, 0xD280, 0xD130, 0xCFC0, 0xCEF0, 0xCE30, 0xCCB0, 0xC7E0, 0xC660, + 0xC550, 0xC480, 0xC340, 0xC280, 0xC2E0, 0xC320, 0xC4B0, 0xC580, 0xC6E0, 0xC820, 0xC8A0, 0xCA00, 0xCB20, 0xCC90, 0xCF80, 0xD270, + 0xD540, 0xD7B0, 0xDA50, 0xDCB0, 0xDF60, 0xE210, 0xE5B0, 0xEA30, 0xEE60, 0xF300, 0xF660, 0xF890, 0xFA30, 0xFB30, 0xFAB0, 0xFA50, + 0xF9A0, 0xF990, 0xFB40, 0xFE40, 0x0270, 0x0700, 0x0B90, 0x0F90, 0x1190, 0x1250, 0x10E0, 0x0D90, 0x0880, 0x0240, 0xFBD0, 0xF450, + 0xEC80, 0xE3C0, 0xDB00, 0xD180, 0xC6E0, 0xBC00, 0xAFA0, 0xA200, 0x92F0, 0x8850, 0x8550, 0x84E0, 0x84B0, 0x84A0, 0x8490, 0x8480, + 0x8480, 0x8470, 0x8470, 0x8470, 0x8440, 0x8470, 0x8470, 0x8450, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84C0, + 0x84E0, 0x8500, 0x8540, 0x8600, 0x8810, 0x8E30, 0x9850, 0xA180, 0xAAB0, 0xB260, 0xB930, 0xBF30, 0xC590, 0xCB00, 0xD000, 0xD530, + 0xDA30, 0xDF80, 0xE3D0, 0xE7B0, 0xEB00, 0xEE80, 0xF210, 0xF610, 0xFA30, 0xFE00, 0x01B0, 0x0520, 0x0880, 0x0BB0, 0x0DE0, 0x0F70, + 0x1070, 0x1120, 0x11D0, 0x1280, 0x1330, 0x1440, 0x1580, 0x1670, 0x16B0, 0x1750, 0x1810, 0x1890, 0x1980, 0x1AB0, 0x1C00, 0x1D70, + 0x1F50, 0x2110, 0x2270, 0x2450, 0x25A0, 0x2770, 0x2970, 0x2BB0, 0x2DB0, 0x3040, 0x3320, 0x3590, 0x3800, 0x3AE0, 0x3DD0, 0x4130, + 0x4500, 0x48C0, 0x4C10, 0x4F30, 0x5190, 0x54C0, 0x5730, 0x5A30, 0x5CE0, 0x5F50, 0x6150, 0x6310, 0x6470, 0x65A0, 0x6690, 0x67B0, + 0x68A0, 0x6930, 0x68F0, 0x68B0, 0x68E0, 0x68F0, 0x68D0, 0x6860, 0x67D0, 0x6780, 0x6700, 0x66A0, 0x6600, 0x65D0, 0x6550, 0x6440, + 0x63D0, 0x62E0, 0x6240, 0x6210, 0x6230, 0x6320, 0x6500, 0x6630, 0x66F0, 0x6770, 0x67C0, 0x6770, 0x6750, 0x6790, 0x6820, 0x68D0, + 0x6B30, 0x6E30, 0x7150, 0x75B0, 0x7980, 0x7D00, 0x7EC0, 0x7F10, 0x7EF0, 0x7EF0, 0x7F20, 0x7ED0, 0x7F10, 0x7EB0, 0x7EE0, 0x7F10, + 0x7F20, 0x7F20, 0x7F00, 0x7F10, 0x7F60, 0x7F10, 0x7EF0, 0x7EF0, 0x7EE0, 0x7F40, 0x7F50, 0x7EB0, 0x7F00, 0x7ED0, 0x7F30, 0x7F40, + 0x7EC0, 0x7ED0, 0x7EB0, 0x7F00, 0x7F20, 0x7E90, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7E90, + 0x7F10, 0x7F00, 0x7F00, 0x7F10, 0x7F00, 0x7F30, 0x7F20, 0x7F10, 0x7F20, 0x7F00, 0x7F50, 0x7EF0, 0x7F20, 0x7EE0, 0x7EF0, 0x7F50, + 0x7F00, 0x7F30, 0x7F20, 0x7F00, 0x7F50, 0x7EF0, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F70, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F60, 0x7EE0, + 0x7E90, 0x7EF0, 0x7EF0, 0x7F30, 0x7EB0, 0x7EA0, 0x7EE0, 0x7EF0, 0x7F30, 0x7F20, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7EB0, + 0x7F20, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F90, 0x7F00, 0x7F20, 0x7EF0, 0x7EF0, 0x7F80, + 0x7F10, 0x7F20, 0x7F00, 0x7ED0, 0x7F30, 0x7F00, 0x7EE0, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7ED0, 0x7EF0, 0x7F00, 0x7F40, 0x7F10, + 0x7C60, 0x7A40, 0x7A50, 0x7BF0, 0x7EA0, 0x7EA0, 0x7ED0, 0x7F10, 0x7F20, 0x7F00, 0x7EC0, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F00, + 0x7F20, 0x7840, 0x6DB0, 0x6740, 0x6280, 0x6130, 0x63F0, 0x6980, 0x7110, 0x7810, 0x7D70, 0x7F20, 0x7F10, 0x7F10, 0x7EF0, 0x7F50, + 0x7EF0, 0x7F20, 0x7F20, 0x7F00, 0x7F60, 0x7EC0, 0x7840, 0x6ED0, 0x6430, 0x57F0, 0x4AC0, 0x3C90, 0x2F30, 0x20C0, 0x15F0, 0x0F90, + 0x0F40, 0x1580, 0x2090, 0x2F70, 0x41E0, 0x5550, 0x6AB0, 0x7B70, 0x7EF0, 0x7EF0, 0x7EB0, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7E90, + 0x7F00, 0x7EF0, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F00, 0x7F10, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7EF0, 0x7F10, 0x7E60, 0x7900, + 0x7380, 0x6FB0, 0x6D30, 0x6CC0, 0x6ED0, 0x7230, 0x7710, 0x7C30, 0x7EB0, 0x7EF0, 0x7EF0, 0x7F90, 0x7F20, 0x7F00, 0x7EF0, 0x7F10, + 0x7F70, 0x7F00, 0x7ED0, 0x7EF0, 0x7EE0, 0x7F40, 0x7EF0, 0x7EB0, 0x7EE0, 0x7ED0, 0x7F30, 0x7F20, 0x7EC0, 0x7ED0, 0x7EF0, 0x7F00, + 0x7EF0, 0x7E90, 0x7EB0, 0x7F00, 0x7EF0, 0x7F10, 0x7EB0, 0x7F20, 0x7F40, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7F00, 0x7F00, 0x7EF0, + 0x7F10, 0x7F60, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F60, 0x7F10, 0x7F10, 0x7EE0, 0x7EF0, 0x7F80, 0x7EE0, 0x7EF0, 0x7F10, 0x7F10, + 0x7F70, 0x7F00, 0x7ED0, 0x7F00, 0x7EE0, 0x7F90, 0x7EF0, 0x7EC0, 0x7EF0, 0x7F10, 0x7F30, 0x7EE0, 0x7EC0, 0x7F10, 0x7F00, 0x7F50, + 0x7ED0, 0x7EA0, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, 0x7F20, 0x7ED0, 0x70B0, 0x6130, + 0x4F00, 0x3F90, 0x3280, 0x29A0, 0x2560, 0x25D0, 0x2910, 0x2F20, 0x3640, 0x3EB0, 0x46E0, 0x4F40, 0x5810, 0x60F0, 0x6940, 0x6FA0, + 0x73F0, 0x75B0, 0x73D0, 0x7010, 0x6A30, 0x6270, 0x59E0, 0x5110, 0x48B0, 0x40A0, 0x3910, 0x31B0, 0x2C20, 0x2800, 0x25D0, 0x2470, + 0x2460, 0x24C0, 0x25B0, 0x26B0, 0x26F0, 0x2720, 0x2540, 0x2350, 0x20D0, 0x1DA0, 0x1A70, 0x1600, 0x1160, 0x0D20, 0x08C0, 0x05D0, + 0x02D0, 0x0020, 0xFD90, 0xFB40, 0xF9D0, 0xF820, 0xF640, 0xF3B0, 0xF090, 0xED20, 0xE8C0, 0xE370, 0xDD20, 0xD5F0, 0xCE50, 0xC720, + 0xC020, 0xBA20, 0xB480, 0xB0A0, 0xADD0, 0xAAE0, 0xA7F0, 0xA460, 0xA040, 0x9BB0, 0x96B0, 0x9200, 0x8E10, 0x8B80, 0x89B0, 0x88D0, + 0x88A0, 0x8910, 0x8A40, 0x8C60, 0x9080, 0x9580, 0x9B40, 0xA140, 0xA7C0, 0xADF0, 0xB560, 0xBC30, 0xC2E0, 0xC900, 0xCEC0, 0xD510, + 0xDA80, 0xDF80, 0xE540, 0xE980, 0xEE20, 0xF1D0, 0xF590, 0xF990, 0xFD40, 0x00F0, 0x0420, 0x06B0, 0x0A30, 0x0C30, 0x0EA0, 0x1000, + 0x10D0, 0x10D0, 0x10E0, 0x1190, 0x1290, 0x13C0, 0x1490, 0x1520, 0x1570, 0x14F0, 0x1450, 0x1430, 0x14A0, 0x1690, 0x1850, 0x1A70, + 0x1CC0, 0x1DD0, 0x1F40, 0x2020, 0x20C0, 0x2190, 0x2290, 0x2360, 0x2310, 0x21B0, 0x1FE0, 0x1C60, 0x17C0, 0x1210, 0x0B60, 0x03A0, + 0xFA90, 0xF220, 0xEA20, 0xE190, 0xDA10, 0xD270, 0xCBA0, 0xC590, 0xC0E0, 0xBD80, 0xBB60, 0xBB30, 0xBB40, 0xBC10, 0xBEF0, 0xC2A0, + 0xC7C0, 0xCCC0, 0xD320, 0xD7C0, 0xDB90, 0xDF80, 0xE290, 0xE570, 0xE950, 0xEC00, 0xEEF0, 0xF090, 0xF1D0, 0xF200, 0xF0F0, 0xEF30, + 0xEBD0, 0xE720, 0xE120, 0xD7B0, 0xCED0, 0xC480, 0xB990, 0xAE00, 0xA200, 0x95D0, 0x8BD0, 0x86B0, 0x8550, 0x84F0, 0x84D0, 0x84B0, + 0x84A0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8470, 0x8460, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8470, 0x8460, 0x8470, 0x8470, + 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84B0, 0x84D0, 0x84F0, 0x8530, 0x85C0, 0x87E0, 0x9080, + 0x9D20, 0xA9F0, 0xB740, 0xC430, 0xD0E0, 0xDD70, 0xEA00, 0xF670, 0x0350, 0x0F60, 0x1B10, 0x2630, 0x30C0, 0x54E0, 0x5CC0, 0x63B0, + 0x6A20, 0x70D0, 0x7630, 0x7AA0, 0x7DD0, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F00, 0x7F30, 0x7F30, + 0x7F30, 0x7F40, 0x7F40, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7EE0, 0x7CC0, 0x7990, 0x75E0, 0x7140, 0x6BA0, 0x6690, 0x61F0, 0x5E20, + 0x5B40, 0x58D0, 0x56D0, 0x55A0, 0x55E0, 0x56E0, 0x58C0, 0x5B50, 0x5E30, 0x6170, 0x6470, 0x6820, 0x6B50, 0x6E10, 0x7120, 0x7410, + 0x76D0, 0x7990, 0x7B70, 0x7D80, 0x7EB0, 0x7F10, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, + 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F10, + 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F10, 0x7F20, + 0x7F40, 0x7F10, 0x7F30, 0x7F00, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, + 0x7F30, 0x7F30, 0x7F70, 0x7F40, 0x7EC0, 0x7F10, 0x7F40, 0x7F50, 0x7F10, 0x7E70, 0x7EF0, 0x7EF0, 0x7EF0, 0x7F00, 0x7E80, 0x7EC0, + 0x7F00, 0x7F20, 0x7EE0, 0x7980, 0x7270, 0x6B70, 0x6460, 0x5E80, 0x57A0, 0x52E0, 0x4E10, 0x4900, 0x44A0, 0x3F80, 0x3910, 0x32B0, + 0x2BC0, 0x2450, 0x1D70, 0x1740, 0x12C0, 0x0F30, 0x0E20, 0x0E60, 0x0FD0, 0x1280, 0x15A0, 0x1970, 0x1D30, 0x2120, 0x25E0, 0x2B80, + 0x3330, 0x3BB0, 0x45A0, 0x5160, 0x5C40, 0x66F0, 0x70B0, 0x7930, 0x7EC0, 0x7E90, 0x7EF0, 0x7F00, 0x7EF0, 0x7EF0, 0x7EB0, 0x7EE0, + 0x7EC0, 0x7F10, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F00, 0x7EF0, 0x7EC0, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F40, 0x7F10, + 0x7F10, 0x7F00, 0x7EF0, 0x7F50, 0x7F10, 0x7F20, 0x7F10, 0x7BB0, 0x6DA0, 0x5F10, 0x5010, 0x4220, 0x3420, 0x26E0, 0x1AC0, 0x0F60, + 0x03D0, 0xF9A0, 0xEFA0, 0xE650, 0xDCF0, 0xD2F0, 0xC8B0, 0xBD30, 0xB010, 0x9FD0, 0x8FE0, 0x8720, 0x8520, 0x84E0, 0x84C0, 0x84C0, + 0x84A0, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8470, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84C0, + 0x84E0, 0x8510, 0x8590, 0x8790, 0x9180, 0x9FA0, 0xABC0, 0xB700, 0xC0D0, 0xCA90, 0xD3A0, 0xDC60, 0xE4E0, 0xEE90, 0xF7E0, 0x0110, + 0x0A10, 0x11E0, 0x1840, 0x1DD0, 0x2210, 0x2530, 0x2880, 0x2B90, 0x2FA0, 0x33E0, 0x3A70, 0x4230, 0x4AD0, 0x5440, 0x5C90, 0x6580, + 0x6C20, 0x7150, 0x7610, 0x7960, 0x7C40, 0x7E50, 0x7EF0, 0x7F00, 0x7E90, 0x7ED0, 0x7D60, 0x78A0, 0x72D0, 0x6AD0, 0x61E0, 0x57E0, + 0x4C10, 0x3F40, 0x3380, 0x2800, 0x1CE0, 0x1260, 0x0950, 0x0030, 0xF750, 0xEF20, 0xE690, 0xE030, 0xDA90, 0xD5A0, 0xD290, 0xD110, + 0xD100, 0xD320, 0xD6D0, 0xDE70, 0xE750, 0xF230, 0xFEB0, 0x0C60, 0x1B70, 0x2A40, 0x39E0, 0x4820, 0x55D0, 0x7B20, 0x7ED0, 0x7EF0, + 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F90, 0x7EE0, 0x7EC0, 0x7F10, 0x7F20, 0x7960, 0x6550, 0x4C50, + 0x3100, 0x1480, 0xF650, 0xDB30, 0xC040, 0xA750, 0x9020, 0x8690, 0x8510, 0x84E0, 0x84C0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, + 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84E0, 0x84F0, 0x8510, 0x8550, 0x8600, 0x87D0, 0x8DF0, 0x9850, 0xA390, + 0xADF0, 0xB820, 0xC1F0, 0xCB70, 0xD490, 0xDCC0, 0xE5A0, 0xECC0, 0xF2D0, 0xF850, 0xFC20, 0x00A0, 0x0390, 0x05B0, 0x07A0, 0x0740, + 0x0640, 0x0410, 0x0020, 0xFC80, 0xF790, 0xF250, 0xEC60, 0xE660, 0xDE30, 0xD4A0, 0xCA10, 0xBE10, 0xB0B0, 0xA230, 0x9340, 0x88E0, + 0x85B0, 0x8500, 0x84E0, 0x84C0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8480, 0x8490, 0x8490, 0x8490, 0x84A0, + 0x84A0, 0x84B0, 0x84C0, 0x84F0, 0x8510, 0x8570, 0x86B0, 0x8B50, 0x9690, 0xA2D0, 0xAEE0, 0xBA00, 0xC580, 0xCF80, 0xD920, 0xE210, + 0xEBD0, 0xF570, 0xFFA0, 0x0AC0, 0x1680, 0x2400, 0x2F90, 0x39E0, 0x42B0, 0x4A00, 0x50C0, 0x5510, 0x57A0, 0x5860, 0x5500, 0x4F20, + 0x4480, 0x3690, 0x2730, 0x1660, 0x0500, 0xF4B0, 0xE530, 0xD580, 0xC820, 0xBD20, 0xB340, 0xAAF0, 0xA460, 0x9FE0, 0x9C00, 0x9920, + 0x9780, 0x9670, 0x9630, 0x9510, 0x9500, 0x9520, 0x94A0, 0x9300, 0x8F70, 0x8B70, 0x8840, 0x8650, 0x8570, 0x8510, 0x8520, 0x84D0, + 0x84C0, 0x84B0, 0x84A0, 0x84C0, 0x8490, 0x8480, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, + 0x8470, 0x8470, 0x84A0, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84C0, 0x84E0, 0x8500, 0x8530, 0x8580, 0x8660, + 0x8890, 0x8F70, 0x9AF0, 0xA710, 0xB340, 0xBE80, 0xC970, 0xD0D0, 0xD590, 0xD7D0, 0xD740, 0xD4C0, 0xCF20, 0xC770, 0xBE20, 0xB1F0, + 0xA3F0, 0x9430, 0x88B0, 0x8560, 0x84E0, 0x84C0, 0x84A0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8460, 0x8450, 0x8460, 0x8450, 0x8450, + 0x8460, 0x8450, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84D0, 0x84F0, + 0x8550, 0x8550, 0x85A0, 0x8620, 0x86B0, 0x8710, 0x8780, 0x87B0, 0x87C0, 0x87E0, 0x87B0, 0x8790, 0x8760, 0x8700, 0x86D0, 0x86A0, + 0x8680, 0x8670, 0x8650, 0x8630, 0x8610, 0x85F0, 0x8560, 0x8580, 0x8550, 0x8530, 0x8510, 0x84F0, 0x8500, 0x84D0, 0x84C0, 0x8480, + 0x84A0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8470, 0x8470, 0x8470, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8490, 0x84A0, + 0x84C0, 0x84D0, 0x8500, 0x8540, 0x8610, 0x8810, 0x8D90, 0x9770, 0xA050, 0xA890, 0xB030, 0xB560, 0xB920, 0xBAF0, 0xBC50, 0xBCC0, + 0xBC60, 0xBB10, 0xB980, 0xB6D0, 0xB3F0, 0xAF60, 0xA9C0, 0xA390, 0x9CA0, 0x94E0, 0x8DF0, 0x88F0, 0x8660, 0x8560, 0x8500, 0x84E0, + 0x84C0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x84A0, + 0x84A0, 0x84C0, 0x84D0, 0x8500, 0x8540, 0x85F0, 0x8750, 0x8A20, 0x8E60, 0x9370, 0x9960, 0x9F80, 0xA5F0, 0xACD0, 0xB2A0, 0xB690, + 0xB820, 0xB6D0, 0xB190, 0xA7E0, 0x9B20, 0x8D70, 0x8630, 0x8500, 0x84C0, 0x84B0, 0x8490, 0x8480, 0x8470, 0x8470, 0x8470, 0x8480, + 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8490, 0x84A0, + 0x84B0, 0x84D0, 0x84F0, 0x8530, 0x8600, 0x8730, 0x8AB0, 0x9160, 0x98C0, 0x9F80, 0xA600, 0xAC70, 0xB260, 0xB7F0, 0xBCE0, 0xC1C0, + 0xC670, 0xCB20, 0xCFB0, 0xD400, 0xD820, 0xDBA0, 0xDEB0, 0xE1B0, 0xE500, 0xE780, 0xE8E0, 0xE960, 0xE6E0, 0xE500, 0xE310, 0xE050, + 0xDD10, 0xD930, 0xD4C0, 0xD0D0, 0xCCE0, 0xC880, 0xC560, 0xC2E0, 0xBFE0, 0xBCA0, 0xB9D0, 0xB740, 0xB490, 0xB200, 0xAFD0, 0xAE20, + 0xADE0, 0xADB0, 0xADF0, 0xADF0, 0xAE40, 0xAE90, 0xAEA0, 0xAED0, 0xAFC0, 0xB090, 0xB190, 0xB2C0, 0xB4C0, 0xB6B0, 0xB920, 0xBBA0, + 0xBE00, 0xBFF0, 0xC220, 0xC430, 0xC710, 0xC9F0, 0xCD00, 0xD050, 0xD3F0, 0xD6D0, 0xDA40, 0xDC70, 0xDE80, 0xE0F0, 0xE360, 0xE590, + 0xE750, 0xE9A0, 0xEB80, 0xED80, 0xEFC0, 0xF180, 0xF330, 0xF470, 0xF5E0, 0xF7C0, 0xF930, 0xFAD0, 0xFC60, 0xFCF0, 0xFD30, 0xFD80, + 0xFD60, 0xFD90, 0xFD30, 0xFD90, 0xFDA0, 0xFDB0, 0xFDB0, 0xFCE0, 0xFCD0, 0xFCB0, 0xFC10, 0xFC20, 0xFBC0, 0xFC60, 0xFCD0, 0xFCD0, + 0xFDB0, 0xFE20, 0xFEA0, 0xFE90, 0xFE60, 0xFF60, 0x0040, 0x0190, 0x02A0, 0x0420, 0x0640, 0x0860, 0x0A70, 0x0CC0, 0x0EF0, 0x11F0, + 0x1560, 0x1870, 0x1B70, 0x1F80, 0x23F0, 0x28F0, 0x2EA0, 0x3510, 0x3AD0, 0x4130, 0x4660, 0x4C50, 0x5200, 0x5640, 0x5B60, 0x5F90, + 0x63B0, 0x67A0, 0x6A50, 0x6D30, 0x6F60, 0x7070, 0x71C0, 0x7210, 0x72A0, 0x7300, 0x7210, 0x7150, 0x6F60, 0x6E00, 0x6BB0, 0x68B0, + 0x6660, 0x6340, 0x6080, 0x5DB0, 0x5AD0, 0x5910, 0x5800, 0x5800, 0x5950, 0x5B90, 0x5F70, 0x63C0, 0x68F0, 0x6F20, 0x74E0, 0x7B60, + 0x7ED0, 0x7F60, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F50, 0x7F10, 0x7F10, 0x7EE0, 0x7EF0, 0x7EF0, 0x7280, 0x6460, 0x55C0, 0x44A0, + 0x3560, 0x26F0, 0x1910, 0x0DB0, 0x02E0, 0xFA10, 0xF400, 0xEF60, 0xEC90, 0xEB60, 0xEAB0, 0xEB00, 0xEBD0, 0xED30, 0xEEB0, 0xF020, + 0xF350, 0xF700, 0xFB40, 0x00B0, 0x05E0, 0x0BA0, 0x1090, 0x1610, 0x1BE0, 0x2140, 0x2810, 0x2E80, 0x3570, 0x3B40, 0x40D0, 0x45F0, + 0x49C0, 0x4CD0, 0x4F10, 0x5040, 0x50D0, 0x5010, 0x4E90, 0x4C60, 0x4940, 0x4610, 0x4100, 0x3A70, 0x3270, 0x2910, 0x1E40, 0x1270, + 0x05B0, 0xF920, 0xEC20, 0xDFC0, 0xD450, 0xC8A0, 0xBF20, 0xB610, 0xAE20, 0xA6F0, 0xA020, 0x9B80, 0x9770, 0x9440, 0x9170, 0x8F00, + 0x8D40, 0x8B90, 0x8A80, 0x8990, 0x88F0, 0x88A0, 0x8830, 0x87F0, 0x87D0, 0x8790, 0x8780, 0x8740, 0x8700, 0x86C0, 0x86B0, 0x8710, + 0x8770, 0x87F0, 0x88B0, 0x89E0, 0x8C00, 0x8EE0, 0x9270, 0x9600, 0x98A0, 0x9A70, 0x9B90, 0x9C20, 0x9C30, 0x9BF0, 0x9BF0, 0x9A70, + 0x99B0, 0x9850, 0x9620, 0x9480, 0x9240, 0x90F0, 0x8FA0, 0x8E50, 0x8DA0, 0x8D00, 0x8C40, 0x8B90, 0x8B00, 0x8AA0, 0x8A60, 0x8A50, + 0x8AB0, 0x8B70, 0x8CC0, 0x8F10, 0x9210, 0x95C0, 0x9A10, 0x9EB0, 0xA320, 0xA950, 0xAF30, 0xB4A0, 0xBB60, 0xC150, 0xC800, 0xCEA0, + 0xD470, 0xDAB0, 0xE140, 0xE750, 0xED70, 0xF1D0, 0xF6C0, 0xFAB0, 0xFF30, 0x0450, 0x0920, 0x0F10, 0x13C0, 0x18C0, 0x1DF0, 0x23D0, + 0x2AA0, 0x30C0, 0x36F0, 0x3BB0, 0x3FF0, 0x44B0, 0x4870, 0x4CF0, 0x50D0, 0x5430, 0x5870, 0x5C00, 0x5F70, 0x6330, 0x65C0, 0x68C0, + 0x6B50, 0x6D70, 0x6FE0, 0x7110, 0x72B0, 0x7430, 0x7540, 0x7630, 0x7600, 0x7620, 0x7650, 0x7650, 0x76B0, 0x7640, 0x75C0, 0x7520, + 0x7420, 0x7380, 0x7290, 0x7170, 0x6FE0, 0x6D10, 0x6B80, 0x68A0, 0x6510, 0x62B0, 0x5EB0, 0x5B60, 0x57F0, 0x5490, 0x50B0, 0x4C80, + 0x4890, 0x44F0, 0x4140, 0x3E20, 0x3B80, 0x3980, 0x3760, 0x3590, 0x34F0, 0x33B0, 0x33D0, 0x3390, 0x3430, 0x3540, 0x3590, 0x3710, + 0x38A0, 0x3A40, 0x3C30, 0x3DE0, 0x3F60, 0x4000, 0x40B0, 0x41B0, 0x4240, 0x42D0, 0x4270, 0x4100, 0x3FD0, 0x3E00, 0x3C60, 0x3C10, + 0x3BD0, 0x3CB0, 0x3D60, 0x3E50, 0x3F50, 0x4090, 0x4210, 0x4320, 0x4460, 0x45D0, 0x4710, 0x4770, 0x4660, 0x4470, 0x4230, 0x3EB0, + 0x3B70, 0x3780, 0x3380, 0x2FA0, 0x2C00, 0x28F0, 0x2600, 0x21F0, 0x1F10, 0x1B70, 0x1830, 0x14C0, 0x1150, 0x0DB0, 0x0860, 0x0290, + 0xFB10, 0xF2F0, 0xEB20, 0xE330, 0xDCD0, 0xD820, 0xD4C0, 0xD330, 0xD300, 0xD3B0, 0xD450, 0xD5E0, 0xD8C0, 0xDC60, 0xE0B0, 0xE5B0, + 0xEBC0, 0xF380, 0xFC40, 0x04F0, 0x0E80, 0x1820, 0x22C0, 0x2D90, 0x37F0, 0x4160, 0x48F0, 0x5150, 0x5670, 0x5A60, 0x5CF0, 0x5D90, + 0x5D20, 0x5AA0, 0x55F0, 0x4ED0, 0x4420, 0x39A0, 0x2D50, 0x2030, 0x11E0, 0x01F0, 0xF270, 0xE280, 0xD3A0, 0xC4D0, 0xB840, 0xACB0, + 0xA250, 0x9890, 0x90D0, 0x8B30, 0x8840, 0x86C0, 0x8600, 0x85C0, 0x8590, 0x8590, 0x8550, 0x8590, 0x85B0, 0x85D0, 0x8610, 0x85E0, + 0x85F0, 0x8610, 0x8630, 0x8650, 0x86A0, 0x86C0, 0x86E0, 0x86E0, 0x86C0, 0x86C0, 0x86B0, 0x86A0, 0x8690, 0x8670, 0x8660, 0x8640, + 0x8640, 0x8630, 0x8620, 0x8630, 0x8640, 0x8650, 0x8660, 0x8670, 0x86A0, 0x8700, 0x87B0, 0x88C0, 0x8AB0, 0x8DE0, 0x9200, 0x9730, + 0x9D00, 0xA2F0, 0xA940, 0xB040, 0xB7C0, 0xBF30, 0xC6F0, 0xD150, 0xD930, 0xE140, 0xE880, 0xEF50, 0xF680, 0xFD80, 0x0550, 0x0DD0, + 0x1600, 0x1F00, 0x28F0, 0x3280, 0x3BC0, 0x4520, 0x4EF0, 0x57F0, 0x6060, 0x6840, 0x6F40, 0x7520, 0x7970, 0x7CB0, 0x7E70, 0x7EE0, + 0x7F00, 0x7ED0, 0x7D90, 0x7A20, 0x74D0, 0x6E70, 0x6720, 0x5E40, 0x5430, 0x48B0, 0x3CE0, 0x2FA0, 0x2210, 0x1440, 0x0760, 0xFBD0, + 0xF0D0, 0xE720, 0xDF80, 0xD8F0, 0xD3B0, 0xCF60, 0xCC40, 0xCA70, 0xC960, 0xC910, 0xC910, 0xC9B0, 0xCAC0, 0xCB70, 0xCBD0, 0xCC50, + 0xCBE0, 0xCAD0, 0xCA30, 0xC8B0, 0xC820, 0xC780, 0xC7B0, 0xC810, 0xC7B0, 0xC7B0, 0xC6E0, 0xC600, 0xC580, 0xC4B0, 0xC420, 0xC2C0, + 0xC120, 0xBE90, 0xBC20, 0xBA20, 0xB8D0, 0xB830, 0xB6C0, 0xB530, 0xB310, 0xB090, 0xADE0, 0xAB70, 0xA930, 0xA740, 0xA5A0, 0xA470, + 0xA2E0, 0xA190, 0xA0E0, 0xA0C0, 0xA030, 0x9F50, 0x9E20, 0x9DA0, 0x9D10, 0x9C00, 0x9AF0, 0x98C0, 0x95F0, 0x9360, 0x90A0, 0x8E90, + 0x8D10, 0x8BB0, 0x8AF0, 0x8AD0, 0x8AB0, 0x8A70, 0x8AE0, 0x8BC0, 0x8E60, 0x9320, 0x9A90, 0xA440, 0xAE60, 0xB940, 0xC560, 0xD130, + 0xDC70, 0xE730, 0xF150, 0xFAB0, 0x0340, 0x0AC0, 0x1130, 0x18C0, 0x1FF0, 0x2770, 0x2E00, 0x3340, 0x35B0, 0x3300, 0x29C0, 0x1A80, + 0x0530, 0xEF70, 0xDB20, 0xCB20, 0xBF60, 0xB730, 0xB1C0, 0xAD00, 0xA810, 0xA180, 0x9AE0, 0x93D0, 0x8DD0, 0x89C0, 0x8760, 0x8610, + 0x8580, 0x8530, 0x8500, 0x84E0, 0x84D0, 0x84C0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8470, + 0x8450, 0x8470, 0x8470, 0x8470, 0x8490, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x84A0, 0x84B0, + 0x84C0, 0x84F0, 0x8570, 0x8920, 0x9F80, 0xB7A0, 0xD0A0, 0xE550, 0xF730, 0x0670, 0x1340, 0x1E90, 0x2860, 0x2FC0, 0x35F0, 0x3930, + 0x3900, 0x3590, 0x3010, 0x29B0, 0x2220, 0x19D0, 0x11C0, 0x08A0, 0x0040, 0xF7C0, 0xEE70, 0xCB00, 0xBE20, 0xAFA0, 0x9EE0, 0x8E30, + 0x8630, 0x84F0, 0x84C0, 0x84A0, 0x8490, 0x8480, 0x8470, 0x8480, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, + 0x8480, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8440, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8420, 0x8430, 0x8420, 0x8420, 0x8430, 0x8420, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8490, + 0x8490, 0x84A0, 0x84A0, 0x84B0, 0x84C0, 0x84D0, 0x84F0, 0x8510, 0x8540, 0x85B0, 0x8690, 0x8860, 0x8C40, 0x9260, 0x99A0, 0xA000, + 0xA650, 0xABD0, 0xB020, 0xB400, 0xB710, 0xBAA0, 0xBDC0, 0xC070, 0xC430, 0xC770, 0xC8F0, 0xCA00, 0xC940, 0xC860, 0xC600, 0xC3B0, + 0xC0C0, 0xBE50, 0xBCC0, 0xBB90, 0xB9D0, 0xB870, 0xB770, 0xB6B0, 0xB5C0, 0xB650, 0xB7E0, 0xBB70, 0xBFA0, 0xC4A0, 0xC9E0, 0xCF00, + 0xD400, 0xDA20, 0xE0B0, 0xE770, 0xEEF0, 0xF690, 0xFE90, 0x0570, 0x0BF0, 0x1320, 0x18D0, 0x2000, 0x26C0, 0x2D20, 0x3350, 0x39E0, + 0x4010, 0x45B0, 0x4B70, 0x5160, 0x55C0, 0x5B10, 0x5FD0, 0x6460, 0x6950, 0x6D00, 0x7080, 0x73A0, 0x75D0, 0x7830, 0x79B0, 0x7B20, + 0x7BD0, 0x7C60, 0x7D40, 0x7D90, 0x7DF0, 0x7DC0, 0x7DC0, 0x7D90, 0x7D90, 0x7D40, 0x7C90, 0x7BB0, 0x7AB0, 0x78E0, 0x7650, 0x7310, + 0x6EE0, 0x56F0, 0x4F30, 0x4870, 0x4180, 0x3AB0, 0x3430, 0x2E60, 0x29A0, 0x25C0, 0x2290, 0x1FD0, 0x1CC0, 0x1AE0, 0x19C0, 0x1930, + 0x1AA0, 0x1C40, 0x1F50, 0x2230, 0x2570, 0x2960, 0x2D10, 0x3120, 0x3560, 0x39F0, 0x4100, 0x46A0, 0x4CC0, 0x52D0, 0x58B0, 0x5F20, + 0x6540, 0x6A90, 0x6FF0, 0x7490, 0x78F0, 0x7BC0, 0x7DC0, 0x7EC0, 0x7ED0, 0x7EF0, 0x7EE0, 0x7EF0, 0x7E70, 0x7E20, 0x7E40, 0x7EB0, + 0x7F30, 0x7F00, 0x7F00, 0x7F10, 0x7EF0, 0x7DB0, 0x79A0, 0x7400, 0x6D90, 0x6750, 0x6260, 0x5EA0, 0x5D80, 0x5E80, 0x6120, 0x64C0, + 0x69C0, 0x6F10, 0x7570, 0x7BE0, 0x7EF0, 0x7F00, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7EC0, 0x7F10, 0x7F00, 0x7EF0, 0x7F10, + 0x7EA0, 0x7F20, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F50, 0x7F10, 0x7F10, 0x7F40, 0x7F10, 0x7F60, 0x7EE0, 0x7F10, 0x7F10, 0x7F10, + 0x7F60, 0x7F10, 0x7F40, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7EF0, 0x7F00, 0x7F00, 0x7F60, 0x7F00, 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, + 0x7F10, 0x7EB0, 0x7EE0, 0x7EE0, 0x7F30, 0x7EF0, 0x7E90, 0x7ED0, 0x7F00, 0x7F10, 0x7F10, 0x7E90, 0x7F00, 0x6050, 0x4390, 0x3110, + 0x2800, 0x27C0, 0x2E40, 0x39A0, 0x4900, 0x59D0, 0x6BD0, 0x79E0, 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7EF0, + 0x7F50, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F30, 0x7D20, 0x6360, 0x3EB0, 0x14E0, 0xE7D0, 0xBAD0, 0x9200, 0x8570, 0x84E0, 0x84C0, + 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84D0, 0x84D0, 0x84E0, 0x84F0, 0x8510, 0x8520, 0x8540, 0x8560, 0x8570, 0x8550, 0x8530, 0x8520, + 0x8510, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x8500, 0x8500, 0x8520, 0x8560, 0x85E0, 0x8740, 0x8B20, 0x9540, 0x9F20, 0xA860, 0xAFC0, + 0xB4F0, 0xB8E0, 0xBA80, 0xBB50, 0xBA60, 0xB830, 0xB450, 0xAEF0, 0xA7D0, 0x9F40, 0x95F0, 0x8DD0, 0x88A0, 0x8670, 0x8590, 0x8540, + 0x8520, 0x8500, 0x8500, 0x84F0, 0x84E0, 0x84E0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84E0, 0x84E0, 0x84E0, 0x84F0, 0x84F0, 0x8500, + 0x8510, 0x8520, 0x8550, 0x8580, 0x85E0, 0x8670, 0x8770, 0x8930, 0x8C40, 0x9130, 0x9580, 0x9A80, 0x9F60, 0xA3C0, 0xA8A0, 0xAD80, + 0xB240, 0xB710, 0xBB20, 0xBF10, 0xC200, 0xC510, 0xC820, 0xCAC0, 0xCD40, 0xCF80, 0xD160, 0xD380, 0xD520, 0xD7E0, 0xDA40, 0xDC50, + 0xE000, 0xE3F0, 0xE860, 0xECC0, 0xF230, 0xF780, 0xFC60, 0x0200, 0x07E0, 0x0DC0, 0x1480, 0x1A50, 0x20E0, 0x27F0, 0x2E90, 0x35F0, + 0x3CE0, 0x4450, 0x4BF0, 0x5300, 0x5A40, 0x6040, 0x6760, 0x6DF0, 0x7490, 0x7C00, 0x7ED0, 0x7F10, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, + 0x7F20, 0x7F10, 0x7F30, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F40, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F10, 0x7F20, 0x7F10, + 0x7F10, 0x7F20, 0x7F40, 0x7F40, 0x7F30, 0x78A0, 0x6A30, 0x5AF0, 0x4C30, 0x3E40, 0x3090, 0x2380, 0x16B0, 0x0B20, 0x00E0, 0xF850, + 0xF230, 0xED70, 0xE8F0, 0xE450, 0xDE30, 0xD810, 0xD280, 0xCD40, 0xCA00, 0xC960, 0xCB50, 0xCFF0, 0xD580, 0xDC30, 0xE330, 0xE9E0, + 0xF000, 0xF410, 0xF620, 0xF510, 0xF230, 0xEC30, 0xE440, 0xDB30, 0xD080, 0xC4A0, 0xB880, 0xAAB0, 0x9D70, 0x90A0, 0x88E0, 0x8630, + 0x8560, 0x8520, 0x8500, 0x84F0, 0x84F0, 0x84F0, 0x84E0, 0x84E0, 0x84E0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84E0, 0x84E0, 0x84E0, + 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84C0, 0x84C0, + 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x84D0, 0x8500, 0x84F0, 0x84F0, 0x84B0, 0x8520, 0x8540, 0x8580, 0x85E0, 0x86A0, 0x8800, 0x8AE0, + 0x8FD0, 0x96E0, 0x9D50, 0xA350, 0xA9F0, 0xB080, 0xB640, 0xBBF0, 0xC1D0, 0xC710, 0xCCB0, 0xD310, 0xD870, 0xDD90, 0xE2C0, 0xE740, + 0xEAF0, 0xED80, 0xEFE0, 0xF260, 0xF420, 0xF600, 0xF790, 0xF810, 0xF910, 0xF920, 0xF900, 0xF950, 0xF910, 0xF940, 0xFA40, 0xFB40, + 0xFC20, 0xFD20, 0xFD60, 0xFE10, 0xFF30, 0x0000, 0x00D0, 0x0190, 0x0360, 0x04E0, 0x0640, 0x07F0, 0x08B0, 0x0960, 0x0A00, 0x0A30, + 0x0B60, 0x0C50, 0x0D30, 0x0ED0, 0x1050, 0x12A0, 0x1440, 0x15F0, 0x1810, 0x1A70, 0x1CA0, 0x1F20, 0x22E0, 0x2710, 0x2BB0, 0x31B0, + 0x3760, 0x3D20, 0x4280, 0x4780, 0x4BF0, 0x4FF0, 0x5360, 0x5590, 0x5780, 0x5970, 0x5B70, 0x5DC0, 0x6010, 0x6280, 0x64A0, 0x65A0, + 0x6690, 0x6730, 0x66C0, 0x66D0, 0x6730, 0x6810, 0x68E0, 0x68B0, 0x68B0, 0x6740, 0x6660, 0x6480, 0x62C0, 0x6080, 0x5D10, 0x5A90, + 0x5730, 0x5360, 0x5010, 0x4C10, 0x4780, 0x4280, 0x3C60, 0x36C0, 0x3000, 0x2A50, 0x2420, 0x1D40, 0x1650, 0x0E10, 0x0600, 0xFE40, + 0xF680, 0xF000, 0xE940, 0xE300, 0xDDB0, 0xD790, 0xD1A0, 0xCC50, 0xC730, 0xC2E0, 0xBE60, 0xB9C0, 0xB540, 0xB100, 0xADA0, 0xAA70, + 0xA810, 0xA640, 0xA410, 0xA2D0, 0xA170, 0xA0A0, 0x9F40, 0x9D80, 0x9BA0, 0x9A00, 0x9890, 0x97B0, 0x9700, 0x9760, 0x9720, 0x96E0, + 0x96B0, 0x9570, 0x94B0, 0x9460, 0x94B0, 0x94A0, 0x9440, 0x93E0, 0x9350, 0x92B0, 0x9130, 0x9040, 0x8F00, 0x8DC0, 0x8CA0, 0x8C00, + 0x8B10, 0x8A70, 0x89C0, 0x8940, 0x88E0, 0x8840, 0x87F0, 0x8770, 0x8730, 0x86E0, 0x8660, 0x8640, 0x8620, 0x8600, 0x85E0, 0x85C0, + 0x85A0, 0x8590, 0x8570, 0x8560, 0x8540, 0x8530, 0x8530, 0x8520, 0x8520, 0x8560, 0x8520, 0x8510, 0x8510, 0x8510, 0x8500, 0x8500, + 0x8510, 0x8500, 0x8510, 0x8510, 0x8520, 0x8520, 0x8520, 0x8520, 0x8520, 0x8530, 0x8530, 0x8540, 0x8550, 0x8560, 0x8580, 0x85A0, + 0x85B0, 0x85D0, 0x85D0, 0x85E0, 0x8600, 0x85D0, 0x85E0, 0x85E0, 0x85F0, 0x8610, 0x8630, 0x8660, 0x8680, 0x8680, 0x8690, 0x86B0, + 0x86E0, 0x8710, 0x8760, 0x87D0, 0x8840, 0x88E0, 0x89A0, 0x8A40, 0x8A90, 0x8AB0, 0x8B10, 0x8B60, 0x8C30, 0x8D40, 0x8DB0, 0x8EF0, + 0x8FB0, 0x9010, 0x9090, 0x9120, 0x9230, 0x9350, 0x9410, 0x9560, 0x9680, 0x97A0, 0x9890, 0x9990, 0x9AF0, 0x9B90, 0x9C70, 0x9CD0, + 0x9D10, 0x9D30, 0x9E00, 0x9E40, 0x9D40, 0x9C90, 0x9CD0, 0x9CB0, 0x9C60, 0x9C20, 0x9C10, 0x9BC0, 0x9B70, 0x9B60, 0x9B50, 0x9B60, + 0x9B40, 0x9AD0, 0x9A30, 0x9A20, 0x99B0, 0x99E0, 0x99A0, 0x9930, 0x9810, 0x9720, 0x96C0, 0x9680, 0x96A0, 0x9700, 0x9690, 0x9630, + 0x95C0, 0x94F0, 0x94A0, 0x93A0, 0x9350, 0x9290, 0x91A0, 0x9090, 0x8F50, 0x8E40, 0x8D40, 0x8C90, 0x8C30, 0x8B90, 0x8B40, 0x8AA0, + 0x8A30, 0x89F0, 0x89B0, 0x8970, 0x8940, 0x8930, 0x8980, 0x89D0, 0x8AD0, 0x8BD0, 0x8CC0, 0x8DF0, 0x8EE0, 0x9010, 0x9140, 0x92C0, + 0x9530, 0x9720, 0x9970, 0x9B10, 0x9D20, 0x9F70, 0xA160, 0xA380, 0xA580, 0xA770, 0xA960, 0xAB60, 0xADC0, 0xAF70, 0xB190, 0xB3D0, + 0xB5F0, 0xB840, 0xBA60, 0xBCC0, 0xBF90, 0xC240, 0xC510, 0xC7A0, 0xC910, 0xCBA0, 0xCD70, 0xD060, 0xD2C0, 0xD4F0, 0xD750, 0xDA40, + 0xDCA0, 0xDF30, 0xE1B0, 0xE570, 0xE830, 0xEB90, 0xEF40, 0xF240, 0xF560, 0xF840, 0xFC40, 0xFF50, 0x0390, 0x0870, 0x0CE0, 0x1180, + 0x1630, 0x1A60, 0x1F60, 0x2340, 0x2700, 0x2B40, 0x2FC0, 0x34D0, 0x3960, 0x3D90, 0x41B0, 0x4470, 0x4840, 0x4AF0, 0x4DF0, 0x50E0, + 0x5320, 0x55B0, 0x57B0, 0x59B0, 0x5BC0, 0x5D50, 0x5F30, 0x60E0, 0x61F0, 0x6310, 0x6370, 0x6440, 0x6450, 0x63B0, 0x63C0, 0x6310, + 0x6390, 0x63B0, 0x63A0, 0x63F0, 0x62B0, 0x6220, 0x6140, 0x5FF0, 0x6000, 0x5F20, 0x5E80, 0x5DD0, 0x5C40, 0x5BC0, 0x5A10, 0x5930, + 0x5860, 0x5770, 0x57D0, 0x57A0, 0x5770, 0x5780, 0x56A0, 0x5690, 0x5690, 0x56B0, 0x5760, 0x57C0, 0x5880, 0x58E0, 0x5920, 0x58F0, + 0x57F0, 0x57A0, 0x56A0, 0x55D0, 0x5490, 0x5370, 0x5220, 0x5010, 0x4E70, 0x4D20, 0x4AD0, 0x4980, 0x4780, 0x4540, 0x43D0, 0x4200, + 0x4120, 0x3F10, 0x3D90, 0x3CB0, 0x3BC0, 0x3B40, 0x3A90, 0x3A10, 0x3A40, 0x3A10, 0x3A60, 0x3B20, 0x3B50, 0x3C90, 0x3DA0, 0x3FA0, + 0x40F0, 0x4250, 0x44F0, 0x4700, 0x49A0, 0x4C60, 0x4E10, 0x5170, 0x5460, 0x5860, 0x5C10, 0x5FB0, 0x63B0, 0x6720, 0x6A10, 0x6E30, + 0x71E0, 0x7560, 0x7890, 0x7B70, 0x7DC0, 0x7ED0, 0x7EF0, 0x7EE0, 0x7F60, 0x7EF0, 0x7EB0, 0x7EE0, 0x7EE0, 0x7F50, 0x7F20, 0x7EA0, + 0x7ED0, 0x7ED0, 0x7F10, 0x7F00, 0x7EA0, 0x7EF0, 0x7EC0, 0x7F10, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, + 0x7F10, 0x7F00, 0x7EF0, 0x7EF0, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F20, 0x7F50, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7F50, 0x7F00, + 0x7F20, 0x7F10, 0x7F10, 0x7F60, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7ED0, 0x7EE0, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F10, + 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F20, 0x7F00, 0x7F20, 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7F10, + 0x7F10, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F40, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7970, 0x6FC0, 0x6510, + 0x5AB0, 0x4F70, 0x43C0, 0x3850, 0x2BA0, 0x20D0, 0x1780, 0x0E90, 0x07E0, 0x0200, 0xFDD0, 0xFAF0, 0xF900, 0xF7D0, 0xF790, 0xF7E0, + 0xF7A0, 0xF680, 0xF450, 0xEFB0, 0xE9E0, 0xE250, 0xD820, 0xCE00, 0xC390, 0xB870, 0xAD60, 0xA230, 0x9690, 0x8D20, 0x87F0, 0x8620, + 0x8550, 0x8510, 0x8500, 0x84F0, 0x84E0, 0x84D0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x84B0, 0x8490, 0x8490, 0x8490, + 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84D0, 0x84D0, 0x84E0, 0x84E0, + 0x84F0, 0x8500, 0x8530, 0x8510, 0x8520, 0x8530, 0x8530, 0x8530, 0x8530, 0x8520, 0x8500, 0x8500, 0x84F0, 0x84F0, 0x84F0, 0x8500, + 0x8520, 0x8530, 0x8550, 0x8570, 0x8590, 0x85C0, 0x85E0, 0x8600, 0x8620, 0x8680, 0x8670, 0x8670, 0x8670, 0x8650, 0x8630, 0x8610, + 0x85F0, 0x85E0, 0x85C0, 0x85B0, 0x8590, 0x8580, 0x8570, 0x8560, 0x8560, 0x8560, 0x8560, 0x8570, 0x85C0, 0x85A0, 0x85C0, 0x8600, + 0x8640, 0x86D0, 0x87A0, 0x8920, 0x8B80, 0x8F30, 0x93D0, 0x98D0, 0x9D80, 0xA340, 0xA840, 0xAE00, 0xB330, 0xB820, 0xBCC0, 0xC140, + 0xC4D0, 0xC980, 0xCDD0, 0xD230, 0xD5B0, 0xD900, 0xDBC0, 0xDD40, 0xDED0, 0xE060, 0xE220, 0xE370, 0xE4E0, 0xE6C0, 0xE840, 0xE8E0, + 0xE9A0, 0xEAC0, 0xEAE0, 0xEB40, 0xEAD0, 0xEA30, 0xE9D0, 0xE920, 0xE9D0, 0xEA50, 0xEA20, 0xEA80, 0xEAC0, 0xEB10, 0xEB00, 0xE9F0, + 0xE9C0, 0xE930, 0xE980, 0xE9A0, 0xE9E0, 0xEB10, 0xEC20, 0xEC70, 0xEC50, 0xEC10, 0xEBA0, 0xEB10, 0xEB10, 0xEB50, 0xEBF0, 0xECB0, + 0xEE30, 0xEFF0, 0xF1A0, 0xF250, 0xF3B0, 0xF4D0, 0xF5C0, 0xF710, 0xF800, 0xFA40, 0xFBD0, 0xFD50, 0xFF70, 0x0160, 0x03D0, 0x0650, + 0x08C0, 0x0C00, 0x0DF0, 0x10D0, 0x1310, 0x1570, 0x1840, 0x1A90, 0x1E20, 0x2110, 0x24A0, 0x2890, 0x2C80, 0x3120, 0x3620, 0x3950, + 0x3D50, 0x40B0, 0x4420, 0x4690, 0x4860, 0x4B00, 0x4D80, 0x4F50, 0x5130, 0x5280, 0x5410, 0x54D0, 0x5560, 0x5540, 0x54D0, 0x5510, + 0x5570, 0x5540, 0x5590, 0x5530, 0x5600, 0x56D0, 0x57B0, 0x58E0, 0x5A30, 0x5B30, 0x5C60, 0x5D20, 0x5DD0, 0x5E80, 0x6040, 0x6240, + 0x63F0, 0x6630, 0x6760, 0x68C0, 0x6A00, 0x6AF0, 0x6C70, 0x6D10, 0x6E70, 0x6E70, 0x6F00, 0x6F90, 0x6F30, 0x7000, 0x6FE0, 0x6F80, + 0x6F20, 0x6E80, 0x6D90, 0x6CB0, 0x6C20, 0x6BC0, 0x6A20, 0x68D0, 0x6700, 0x64C0, 0x63B0, 0x6220, 0x6060, 0x5E10, 0x5B90, 0x58E0, + 0x5640, 0x5390, 0x5140, 0x4E90, 0x4CB0, 0x4A70, 0x48F0, 0x4750, 0x4630, 0x46C0, 0x4720, 0x47D0, 0x48B0, 0x48C0, 0x49A0, 0x49D0, + 0x4A70, 0x4B60, 0x4C90, 0x4F10, 0x5240, 0x55C0, 0x5A00, 0x5D70, 0x61E0, 0x6560, 0x6810, 0x6AB0, 0x6C00, 0x6B50, 0x68E0, 0x6340, + 0x5C40, 0x5290, 0x4880, 0x3E00, 0x3320, 0x29D0, 0x2020, 0x1880, 0x1140, 0x0AB0, 0x04E0, 0xFFC0, 0xFB50, 0xF730, 0xF2B0, 0xED00, + 0xE790, 0xE0E0, 0xDA30, 0xD240, 0xCA30, 0xC1C0, 0xB900, 0xB050, 0xA670, 0x89E0, 0x8700, 0x85C0, 0x8540, 0x84F0, 0x84F0, 0x84D0, + 0x84C0, 0x84C0, 0x84B0, 0x84A0, 0x84A0, 0x8490, 0x8480, 0x8480, 0x8480, 0x8470, 0x8470, 0x84C0, 0x8470, 0x8470, 0x8470, 0x8460, + 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, + 0x8450, 0x8450, 0x8480, 0x8460, 0x8480, 0x8460, 0x8460, 0x8470, 0x8480, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, 0x84A0, + 0x84B0, 0x84C0, 0x84D0, 0x84E0, 0x8500, 0x8530, 0x8590, 0x8670, 0x88C0, 0x8EA0, 0x9800, 0xA180, 0xAB90, 0xB460, 0xBC90, 0xC3F0, + 0xCB70, 0xD220, 0xD870, 0xDED0, 0xE4B0, 0xEAB0, 0xEFB0, 0xF4E0, 0xF8E0, 0xFD10, 0x0040, 0x0270, 0x0540, 0x0690, 0x0860, 0x0A70, + 0x0C50, 0x0F30, 0x11B0, 0x1500, 0x1800, 0x1B10, 0x1F60, 0x2440, 0x2B60, 0x32A0, 0x3AA0, 0x4490, 0x4F30, 0x5AB0, 0x6640, 0x7140, + 0x7C00, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F50, 0x7EF0, 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F10, 0x5BE0, + 0x2FC0, 0xFF50, 0xC750, 0x93A0, 0x84F0, 0x84A0, 0x8480, 0x8470, 0x8480, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8480, + 0x8480, 0x8490, 0x84B0, 0x84D0, 0x85A0, 0x9570, 0xBDD0, 0xE830, 0x12B0, 0x37C0, 0x5190, 0x5E30, 0x5D00, 0x4F90, 0x3BD0, 0x2670, + 0x1600, 0x08C0, 0x01D0, 0xFE90, 0xFD00, 0xFA90, 0xF400, 0xE960, 0xD910, 0xC430, 0xAA30, 0x8DC0, 0x8520, 0x84C0, 0x8490, 0x8480, + 0x8470, 0x8470, 0x8470, 0x8480, 0x8490, 0x84B0, 0x84D0, 0x84E0, 0x84B0, 0x8490, 0x8470, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, + 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, + 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, + 0x8470, 0x8410, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84F0, 0x84D0, 0x84D0, 0x84E0, 0x8500, 0x8510, 0x8530, 0x8590, + 0x8590, 0x85C0, 0x85F0, 0x8610, 0x8640, 0x8680, 0x86A0, 0x8700, 0x8780, 0x8870, 0x8AE0, 0x90A0, 0x9B30, 0xA890, 0xB860, 0xC950, + 0xDE10, 0xF080, 0x0260, 0x1240, 0x1F90, 0x2A90, 0x30B0, 0x31E0, 0x2C80, 0x1ED0, 0x0B70, 0xF220, 0xD580, 0xB9B0, 0xA110, 0x8F30, + 0x8810, 0x8610, 0x8580, 0x8540, 0x8510, 0x84F0, 0x84E0, 0x84D0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84D0, 0x84E0, + 0x84F0, 0x8520, 0x8550, 0x85B0, 0x8630, 0x86F0, 0x8840, 0x8A30, 0x8D20, 0x9080, 0x9380, 0x9690, 0x9960, 0x9CA0, 0x9FD0, 0xA3C0, + 0xA960, 0xB0D0, 0xBA10, 0xC520, 0xD140, 0xDD90, 0xEA90, 0xF760, 0x0420, 0x0F90, 0x1910, 0x2120, 0x29A0, 0x3110, 0x3990, 0x4330, + 0x4E60, 0x5A50, 0x66B0, 0x7200, 0x7AA0, 0x7ED0, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x79E0, 0x6D40, + 0x5870, 0x3B10, 0x1860, 0xF340, 0xCF80, 0xB010, 0x95F0, 0x8810, 0x8580, 0x8510, 0x84E0, 0x84D0, 0x84C0, 0x84B0, 0x84A0, 0x84A0, + 0x84A0, 0x84B0, 0x84B0, 0x84D0, 0x84F0, 0x8550, 0x8650, 0x8970, 0x9110, 0x9A50, 0xA030, 0xA380, 0xA390, 0xA100, 0x9B80, 0x9470, + 0x8D10, 0x8850, 0x8650, 0x8590, 0x8540, 0x8530, 0x8530, 0x8520, 0x8520, 0x8520, 0x8520, 0x8520, 0x8520, 0x8520, 0x8540, 0x8580, + 0x8600, 0x86E0, 0x88D0, 0x8CD0, 0x9340, 0x99C0, 0xA000, 0xA570, 0xAA50, 0xAF30, 0xB4D0, 0xBAF0, 0xC0E0, 0xC740, 0xCD60, 0xD350, + 0xD930, 0xDEB0, 0xE520, 0xEC20, 0xF3B0, 0xFBE0, 0x0430, 0x0B90, 0x11F0, 0x1800, 0x1D00, 0x2170, 0x2590, 0x2940, 0x2D50, 0x32C0, + 0x3860, 0x3DB0, 0x41E0, 0x4600, 0x49D0, 0x4C70, 0x4F60, 0x5180, 0x5480, 0x5710, 0x59B0, 0x5BD0, 0x5D40, 0x5D40, 0x5C10, 0x5A60, + 0x5760, 0x5360, 0x4E20, 0x4760, 0x4050, 0x3850, 0x2FB0, 0x2590, 0x1A70, 0x0E90, 0x01C0, 0xF610, 0xEB30, 0xE150, 0xD830, 0xD140, + 0xCB70, 0xC730, 0xC430, 0xC280, 0xC1E0, 0xC1C0, 0xC210, 0xC2F0, 0xC4F0, 0xC7D0, 0xCB20, 0xCF30, 0xD3E0, 0xD8A0, 0xDD50, 0xE1F0, + 0xE750, 0xECC0, 0xF270, 0xF8F0, 0xFF50, 0x0620, 0x0CC0, 0x1270, 0x1880, 0x1E40, 0x23C0, 0x28B0, 0x2DA0, 0x31F0, 0x3690, 0x3AE0, + 0x3DF0, 0x41F0, 0x4480, 0x47C0, 0x4A00, 0x4BF0, 0x4D90, 0x4E20, 0x4E10, 0x4E40, 0x4D30, 0x4CE0, 0x4B40, 0x4A10, 0x48A0, 0x4700, + 0x4480, 0x4210, 0x40A0, 0x3E80, 0x3C80, 0x3AF0, 0x3820, 0x35C0, 0x3340, 0x3070, 0x2F20, 0x2D50, 0x2BF0, 0x2AC0, 0x28E0, 0x26D0, + 0x2490, 0x2300, 0x2130, 0x1FB0, 0x1E70, 0x1D60, 0x1CF0, 0x1C20, 0x1B20, 0x1A80, 0x1830, 0x16E0, 0x1500, 0x1310, 0x11D0, 0x1070, + 0x0FA0, 0x0F10, 0x0D90, 0x0D10, 0x0C40, 0x0B90, 0x0AD0, 0x0A20, 0x0A00, 0x09D0, 0x0A20, 0x0BA0, 0x0BD0, 0x0CE0, 0x0DE0, 0x0F30, + 0x10D0, 0x1190, 0x13C0, 0x15F0, 0x1830, 0x1A90, 0x1CD0, 0x2050, 0x22B0, 0x2560, 0x2750, 0x28F0, 0x2BC0, 0x2DE0, 0x2FD0, 0x3220, + 0x33D0, 0x3670, 0x3870, 0x39F0, 0x3AF0, 0x3B10, 0x3C60, 0x3D40, 0x3DB0, 0x3F30, 0x4040, 0x4200, 0x4290, 0x4370, 0x4440, 0x4440, + 0x44F0, 0x45A0, 0x46C0, 0x4800, 0x4A00, 0x4BE0, 0x4E40, 0x4ED0, 0x50B0, 0x51B0, 0x52D0, 0x5430, 0x5520, 0x5700, 0x5890, 0x5A10, + 0x5B40, 0x5C40, 0x5E10, 0x5FA0, 0x6060, 0x6110, 0x6210, 0x62E0, 0x6340, 0x6390, 0x64B0, 0x65A0, 0x67B0, 0x68C0, 0x69D0, 0x6A30, + 0x6A30, 0x6A60, 0x6AF0, 0x6B30, 0x6CA0, 0x6D40, 0x6EC0, 0x7000, 0x70B0, 0x7240, 0x7290, 0x73F0, 0x7500, 0x75E0, 0x7750, 0x7800, + 0x7940, 0x7A40, 0x7AF0, 0x7C20, 0x7C80, 0x7D90, 0x7E50, 0x7EC0, 0x7F00, 0x7F00, 0x7F30, 0x7F20, 0x7F20, 0x7EF0, 0x7F10, 0x7F60, + 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7F30, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, 0x7F70, 0x7EF0, + 0x7EB0, 0x7EF0, 0x7F10, 0x7F70, 0x7EE0, 0x7EC0, 0x7EF0, 0x7F10, 0x7F30, 0x7EE0, 0x7E90, 0x7F00, 0x7F10, 0x7F10, 0x7EF0, 0x7EA0, + 0x7EF0, 0x7EF0, 0x7F10, 0x7F20, 0x7EB0, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7F10, + 0x7EA0, 0x7F20, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7EE0, 0x7F10, 0x7F10, 0x7F10, 0x7F60, 0x7EF0, 0x7F30, 0x7F20, 0x7F00, + 0x7F90, 0x7F10, 0x7EE0, 0x7EE0, 0x7EE0, 0x7F70, 0x7F10, 0x7F00, 0x7F00, 0x7EF0, 0x7F50, 0x7F10, 0x7E70, 0x7EF0, 0x7ED0, 0x7F30, + 0x7F00, 0x7E90, 0x7ED0, 0x7F00, 0x7F20, 0x7F10, 0x7EB0, 0x7EE0, 0x7F10, 0x7F10, 0x7F10, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7EF0, + 0x7EC0, 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F60, 0x7EF0, 0x7EF0, 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, + 0x7F80, 0x7F20, 0x7F20, 0x7F40, 0x7F00, 0x7F30, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7F50, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F90, + 0x7F00, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F60, 0x7EF0, 0x7F10, 0x7F00, 0x7F00, 0x7F50, 0x7F10, 0x7EB0, 0x7EF0, 0x7EF0, 0x7F30, 0x7EF0, + 0x7E90, 0x7ED0, 0x7EE0, 0x7F00, 0x7F10, 0x7EC0, 0x7EC0, 0x7EB0, 0x7F00, 0x7F00, 0x7E90, 0x7F00, 0x7F20, 0x7F20, 0x7F10, 0x7EB0, + 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7EE0, 0x7F40, 0x7F10, 0x7F00, 0x7EF0, 0x7EF0, 0x7F50, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F30, + 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7F50, 0x7F10, 0x7F00, 0x7F00, 0x7F10, 0x7F60, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7ED0, + 0x7EB0, 0x7DE0, 0x7360, 0x6840, 0x5C40, 0x4E10, 0x3F70, 0x2F20, 0x1F40, 0x10F0, 0x0310, 0xF700, 0xEC10, 0xE2B0, 0xDA80, 0xD240, + 0xCAD0, 0xC390, 0xBBD0, 0xB500, 0xAF30, 0xAC50, 0xAC00, 0xADB0, 0xB120, 0xB4B0, 0xB710, 0xB7E0, 0xB640, 0xB230, 0xAD70, 0xA8F0, + 0xA580, 0xA3E0, 0xA410, 0xA580, 0xA820, 0xA9D0, 0xAA10, 0xA890, 0xA4C0, 0x9EC0, 0x98C0, 0x9330, 0x8EA0, 0x8B20, 0x88E0, 0x8740, + 0x8660, 0x85C0, 0x8560, 0x8520, 0x8510, 0x8500, 0x84F0, 0x84F0, 0x84F0, 0x8500, 0x8520, 0x8540, 0x8580, 0x85D0, 0x8680, 0x8770, + 0x88E0, 0x8B60, 0x8EB0, 0x9310, 0x9810, 0x9DD0, 0xA3E0, 0xAA30, 0xB0B0, 0xB7C0, 0xBFB0, 0xC790, 0xCF20, 0xD740, 0xDEF0, 0xE650, + 0xEE00, 0xF500, 0xFC10, 0x0340, 0x0A10, 0x10D0, 0x16E0, 0x1D90, 0x2350, 0x2890, 0x2C70, 0x2FE0, 0x32B0, 0x33B0, 0x33A0, 0x32F0, + 0x30D0, 0x2E10, 0x2A40, 0x24F0, 0x1F10, 0x1740, 0x0F00, 0x0590, 0xFB70, 0xF170, 0xE6E0, 0xDCD0, 0xD2D0, 0xC960, 0xC080, 0xB980, + 0xB3C0, 0xAF00, 0xAAD0, 0xA7A0, 0xA470, 0xA230, 0xA110, 0xA090, 0xA130, 0xA200, 0xA3D0, 0xA5C0, 0xA840, 0xAAF0, 0xADB0, 0xB030, + 0xB330, 0xB5B0, 0xB870, 0xBB50, 0xBE50, 0xC0E0, 0xC3D0, 0xC6B0, 0xC9D0, 0xCC90, 0xCF50, 0xD230, 0xD4E0, 0xD7E0, 0xDA70, 0xDCE0, + 0xDF70, 0xE170, 0xE3E0, 0xE600, 0xE8A0, 0xEB30, 0xED90, 0xF080, 0xF330, 0xF630, 0xF8E0, 0xFB00, 0xFD10, 0xFE40, 0x0010, 0x0160, + 0x0320, 0x04B0, 0x0670, 0x07A0, 0x0910, 0x0A10, 0x0B10, 0x0C00, 0x0CF0, 0x0DA0, 0x0E10, 0x0ED0, 0x0F90, 0x1000, 0x1160, 0x1270, + 0x13B0, 0x14A0, 0x1560, 0x15F0, 0x16A0, 0x1750, 0x1790, 0x17B0, 0x17E0, 0x17F0, 0x1790, 0x1730, 0x1660, 0x1640, 0x1470, 0x12B0, + 0x1040, 0x0D60, 0x0A50, 0x0650, 0x0250, 0xFF10, 0xFB00, 0xF7A0, 0xF520, 0xF240, 0xEFB0, 0xED90, 0xEBA0, 0xEA20, 0xE8F0, 0xE780, + 0xE6F0, 0xE690, 0xE6B0, 0xE740, 0xE850, 0xE910, 0xE9B0, 0xEA80, 0xEB50, 0xEC00, 0xECB0, 0xED50, 0xEE70, 0xEF90, 0xF0D0, 0xF220, + 0xF440, 0xF5F0, 0xF750, 0xF9B0, 0xFB70, 0xFD60, 0xFF50, 0x0170, 0x0400, 0x06E0, 0x0960, 0x0BF0, 0x0EB0, 0x1140, 0x1390, 0x15B0, + 0x1750, 0x1940, 0x1B10, 0x1BB0, 0x1C40, 0x1C50, 0x1C80, 0x1C30, 0x1C60, 0x1C20, 0x1BB0, 0x1B70, 0x19E0, 0x18C0, 0x1730, 0x1630, + 0x1560, 0x1440, 0x1330, 0x1250, 0x11E0, 0x11B0, 0x1170, 0x10E0, 0x10B0, 0x10B0, 0x10D0, 0x11F0, 0x1310, 0x1490, 0x1720, 0x19C0, + 0x1C50, 0x1F70, 0x22B0, 0x2760, 0x2C50, 0x31B0, 0x3710, 0x3D40, 0x4280, 0x47B0, 0x4BA0, 0x4EC0, 0x5040, 0x4FB0, 0x4E60, 0x4C00, + 0x47D0, 0x4340, 0x3E60, 0x38F0, 0x3280, 0x2C40, 0x2560, 0x1E50, 0x16B0, 0x0DC0, 0x0540, 0xFC70, 0xF3C0, 0xEAC0, 0xE190, 0xD8D0, + 0xD130, 0xC960, 0xC1F0, 0xBCA0, 0xB7E0, 0xB4B0, 0xB2D0, 0xB1A0, 0xB200, 0xB2F0, 0xB520, 0xB890, 0xBBB0, 0xBF40, 0xC2A0, 0xC620, + 0xC9F0, 0xCDB0, 0xD1D0, 0xD520, 0xD8F0, 0xDCF0, 0xE030, 0xE3C0, 0xE680, 0xE950, 0xEB80, 0xEDE0, 0xF080, 0xF300, 0xF560, 0xF840, + 0xFA90, 0xFDE0, 0x0160, 0x0510, 0x09B0, 0x0DB0, 0x1290, 0x1680, 0x1AE0, 0x1F60, 0x2310, 0x2730, 0x2B40, 0x2F70, 0x32F0, 0x3640, + 0x3930, 0x3BD0, 0x3DC0, 0x4060, 0x4210, 0x4530, 0x4770, 0x4A70, 0x4DD0, 0x5030, 0x53A0, 0x5640, 0x58F0, 0x5C60, 0x5F20, 0x6340, + 0x6790, 0x6BE0, 0x7080, 0x7450, 0x7900, 0x7CE0, 0x7EE0, 0x7F10, 0x7EB0, 0x7F20, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F10, + 0x7F00, 0x7F00, 0x7EF0, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7F60, 0x7F10, 0x7F20, 0x7EE0, 0x7F10, 0x7F50, 0x7EF0, 0x7F20, + 0x7EF0, 0x7F10, 0x7F60, 0x7F00, 0x7ED0, 0x7F20, 0x7F00, 0x7F90, 0x7EF0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F30, 0x7F00, 0x7ED0, 0x7F10, + 0x7F20, 0x7F40, 0x7ED0, 0x7E90, 0x7F00, 0x7EE0, 0x7EF0, 0x7EE0, 0x7EC0, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F10, 0x7F00, + 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F70, 0x7F00, 0x7F40, 0x7F40, 0x7F10, 0x7F70, 0x7EF0, 0x7EF0, + 0x7F10, 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F70, 0x7F00, 0x7EC0, 0x7ED0, 0x7EE0, 0x7F60, 0x7EF0, 0x7EB0, 0x7EE0, + 0x7F00, 0x7F10, 0x7F10, 0x7E70, 0x7ED0, 0x7EB0, 0x7E30, 0x7D20, 0x7BC0, 0x7BD0, 0x7C40, 0x7CE0, 0x7E50, 0x7E80, 0x7ED0, 0x7F10, + 0x7F00, 0x7EF0, 0x7F00, 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F00, 0x7F40, 0x7F40, 0x7F10, 0x7F10, 0x7EE0, 0x7F50, 0x7EF0, 0x7F20, + 0x7EF0, 0x7F10, 0x7F60, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7F60, 0x7F10, 0x7EF0, 0x7EF0, 0x7EE0, 0x7F60, 0x7F00, 0x7F70, 0x7EF0, + 0x7F10, 0x7EF0, 0x7EF0, 0x7F80, 0x7F00, 0x7EE0, 0x7F10, 0x7EE0, 0x7F50, 0x7ED0, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, + 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7710, 0x5720, 0x3840, 0x1910, 0xFB70, 0xE0E0, 0xC9C0, 0xB780, + 0xA950, 0x9F70, 0x9920, 0x9560, 0x9300, 0x91F0, 0x9200, 0x92A0, 0x94E0, 0x9880, 0x9E90, 0xA540, 0xAD30, 0xB5C0, 0xBDB0, 0xC610, + 0xCEF0, 0xD820, 0xE0D0, 0xEB60, 0xF520, 0xFE90, 0x0890, 0x1180, 0x18F0, 0x1FF0, 0x2490, 0x28A0, 0x2B50, 0x2C30, 0x2C00, 0x2A60, + 0x2910, 0x26D0, 0x2300, 0x1F20, 0x1990, 0x12C0, 0x0B50, 0x03F0, 0xFCA0, 0xF450, 0xEC70, 0xE4A0, 0xDD00, 0xD5A0, 0xCDB0, 0xC5E0, + 0xBF10, 0xB7D0, 0xB0F0, 0xAA40, 0xA500, 0x9F90, 0x9A30, 0x9640, 0x92B0, 0x8FE0, 0x8D90, 0x8C00, 0x8B30, 0x8A80, 0x8A10, 0x8A60, + 0x8A90, 0x8B30, 0x8C00, 0x8D00, 0x8EB0, 0x9120, 0x9410, 0x9790, 0x9AF0, 0x9F90, 0xA3D0, 0xA930, 0xAE90, 0xB310, 0xB800, 0xBBB0, + 0xBFE0, 0xC3E0, 0xC740, 0xCBD0, 0xCF90, 0xD300, 0xD560, 0xD640, 0xD680, 0xD500, 0xD240, 0xCE70, 0xCA40, 0xC690, 0xC290, 0xBF30, + 0xBB40, 0xB750, 0xB2F0, 0xAE40, 0xA980, 0xA4D0, 0xA020, 0x91D0, 0x8FB0, 0x8E60, 0x8DB0, 0x8DD0, 0x8FB0, 0x92B0, 0x96F0, 0x9AF0, + 0x9ED0, 0xA2A0, 0xA560, 0xA710, 0xA7C0, 0xA7C0, 0xA7C0, 0xA830, 0xA910, 0xAA60, 0xABE0, 0xADA0, 0xAEC0, 0xAF60, 0xAFC0, 0xAF20, + 0xADC0, 0xAB00, 0xA840, 0xA410, 0x9F60, 0x99F0, 0x9390, 0x8D80, 0x88B0, 0x8650, 0x8560, 0x8510, 0x84E0, 0x84D0, 0x84C0, 0x84B0, + 0x84A0, 0x8490, 0x84C0, 0x8480, 0x8470, 0x8470, 0x8440, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, + 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8480, 0x84A0, 0x8490, 0x8490, 0x84A0, 0x84A0, + 0x84B0, 0x84B0, 0x84C0, 0x84D0, 0x84E0, 0x8500, 0x8520, 0x8560, 0x85F0, 0x8710, 0x8990, 0x8ED0, 0x9510, 0x9B00, 0xA040, 0xA450, + 0xA820, 0xAB70, 0xAF30, 0xB2B0, 0xB5D0, 0xB8A0, 0xBB70, 0xBF10, 0xC200, 0xC4B0, 0xC890, 0xCC60, 0xD1A0, 0xD710, 0xDE00, 0xE530, + 0xED30, 0xF4E0, 0xFC50, 0x0350, 0x0A00, 0x0F60, 0x15D0, 0x1B50, 0x2080, 0x24A0, 0x27C0, 0x2AD0, 0x2C80, 0x2DF0, 0x2F70, 0x30B0, + 0x32B0, 0x33A0, 0x3430, 0x34B0, 0x3420, 0x3340, 0x3150, 0x2F30, 0x2D00, 0x2990, 0x2650, 0x2230, 0x1DF0, 0x19D0, 0x14D0, 0x10B0, + 0x0D70, 0x09F0, 0x07A0, 0x07C0, 0x0950, 0x0D10, 0x1250, 0x1960, 0x2310, 0x2F20, 0x3D40, 0x4E40, 0x5EF0, 0x6F20, 0x7C20, 0x7F20, + 0x7F40, 0x7F10, 0x7F00, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F50, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, + 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, + 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7E30, 0x77B0, 0x7570, 0x7780, 0x7D10, 0x7F30, 0x7F30, 0x7F20, + 0x7F40, 0x7F40, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x4170, 0xEA20, 0x8E40, 0x8490, 0x8460, 0x8440, + 0x8430, 0x8420, 0x8440, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, + 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, 0x8440, + 0x83F0, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8480, 0x84A0, 0x8490, 0x8490, + 0x84C0, 0x84B0, 0x84B0, 0x84C0, 0x84D0, 0x84F0, 0x8530, 0x85F0, 0x87D0, 0x9130, 0x9F90, 0xAE10, 0xBCF0, 0xCAA0, 0xD7C0, 0xE3D0, + 0xEE30, 0xF750, 0xFED0, 0x0460, 0x0860, 0x0BB0, 0x0DD0, 0x0ED0, 0x0F20, 0x0E60, 0x0D30, 0x0C30, 0x0B30, 0x09F0, 0x0910, 0x0810, + 0x05A0, 0x0260, 0xFFE0, 0xFCF0, 0xF9B0, 0xF6F0, 0xF4A0, 0xF2A0, 0xF080, 0xEEB0, 0xEC90, 0xE9A0, 0xE620, 0xE180, 0xDC60, 0xD610, + 0xCE80, 0xC5B0, 0xBB10, 0xAEC0, 0xA020, 0x9180, 0x8760, 0x8530, 0x84D0, 0x84B0, 0x84A0, 0x84B0, 0x8480, 0x8470, 0x8470, 0x8460, + 0x8460, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8490, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, 0x8420, 0x8420, + 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8460, 0x8440, 0x8440, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, + 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, + 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8490, 0x8470, 0x8480, 0x8480, 0x84C0, 0x8490, 0x84A0, 0x84B0, + 0x84D0, 0x8500, 0x8570, 0x8730, 0x9040, 0xA0D0, 0xB020, 0xBE70, 0xCC40, 0xD990, 0xE570, 0xF0B0, 0xFB60, 0x0530, 0x0F10, 0x18C0, + 0x2180, 0x2A50, 0x3320, 0x3A90, 0x4250, 0x4990, 0x5100, 0x5960, 0x6180, 0x6B10, 0x7400, 0x7CD0, 0x7F00, 0x7F20, 0x7F00, 0x7F10, + 0x7F70, 0x7EE0, 0x7EC0, 0x7EF0, 0x7EF0, 0x7F60, 0x7EF0, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7EB0, 0x7E70, 0x7EF0, 0x7EE0, 0x7EF0, + 0x7ED0, 0x7EB0, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7EC0, 0x7F30, 0x7F10, 0x7F20, 0x7F10, + 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F80, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F90, 0x7F00, 0x7F00, 0x7EF0, 0x7EF0, + 0x7F60, 0x7F10, 0x7F00, 0x7EE0, 0x7EF0, 0x7F70, 0x7F20, 0x5160, 0x2380, 0xFD30, 0xDDA0, 0xCA30, 0xBD80, 0xB790, 0xB3E0, 0xB1E0, + 0xB190, 0xB190, 0xB300, 0xB5D0, 0xBA50, 0xBFA0, 0xC5A0, 0xCB00, 0xCF50, 0xD100, 0xD0A0, 0xCDA0, 0xC830, 0xC200, 0xBB90, 0xB060, + 0xB0E0, 0xB300, 0xB530, 0xBA10, 0xC090, 0xCA10, 0xD610, 0xE330, 0xF260, 0x0410, 0x1490, 0x24F0, 0x34C0, 0x4380, 0x5030, 0x5A60, + 0x62C0, 0x6850, 0x6C20, 0x6F00, 0x7050, 0x7200, 0x72B0, 0x72E0, 0x71F0, 0x7000, 0x6D20, 0x6950, 0x6560, 0x6170, 0x5DC0, 0x5A90, + 0x57B0, 0x55B0, 0x5370, 0x5110, 0x4F70, 0x4DD0, 0x4D00, 0x4CC0, 0x4CD0, 0x4D10, 0x4CB0, 0x4BE0, 0x4B10, 0x4990, 0x48D0, 0x46E0, + 0x4460, 0x42C0, 0x4050, 0x3E70, 0x3C60, 0x3A50, 0x3950, 0x3800, 0x36E0, 0x3650, 0x3530, 0x35A0, 0x35C0, 0x3600, 0x3780, 0x3860, + 0x3A50, 0x3B80, 0x3D20, 0x3E80, 0x3FD0, 0x4290, 0x4520, 0x48A0, 0x4CA0, 0x5060, 0x5510, 0x5950, 0x5E20, 0x6260, 0x6650, 0x6A30, + 0x6D60, 0x6F80, 0x7190, 0x7290, 0x73A0, 0x73A0, 0x72F0, 0x7230, 0x6FE0, 0x6DC0, 0x6A10, 0x6660, 0x61D0, 0x5BD0, 0x5670, 0x5040, + 0x4A10, 0x4490, 0x3EE0, 0x39C0, 0x33F0, 0x2E30, 0x2940, 0x2400, 0x2010, 0x1BB0, 0x17E0, 0x1540, 0x1290, 0x10B0, 0x0EF0, 0x0D90, + 0x0CB0, 0x0BC0, 0x0B80, 0x0B90, 0x0B60, 0x0B80, 0x0B20, 0x0B40, 0x0A50, 0x0A10, 0x0A80, 0x0A60, 0x0AF0, 0x0B10, 0x0B00, 0x0B20, + 0x0A70, 0x0A70, 0x0A50, 0x0A60, 0x0AE0, 0x0BD0, 0x0D50, 0x0ED0, 0x1110, 0x1380, 0x1600, 0x1890, 0x1B80, 0x1E00, 0x20E0, 0x23C0, + 0x2630, 0x29C0, 0x2C60, 0x3010, 0x3370, 0x35F0, 0x3940, 0x3B90, 0x3EB0, 0x40F0, 0x4350, 0x46F0, 0x49C0, 0x4D90, 0x51F0, 0x55A0, + 0x5A40, 0x5E40, 0x6260, 0x6610, 0x6910, 0x6D00, 0x6FC0, 0x72F0, 0x75B0, 0x77A0, 0x79A0, 0x7B40, 0x7CC0, 0x7D80, 0x7E20, 0x7EC0, + 0x7ED0, 0x7F30, 0x7EE0, 0x7EE0, 0x7EF0, 0x7EE0, 0x7F40, 0x7ED0, 0x7E50, 0x7DA0, 0x7CA0, 0x7AD0, 0x78D0, 0x75C0, 0x7310, 0x7030, + 0x6CF0, 0x69E0, 0x65C0, 0x6230, 0x5D80, 0x57C0, 0x5220, 0x4B40, 0x4610, 0x4090, 0x3AA0, 0x3540, 0x2E40, 0x2800, 0x2130, 0x19A0, + 0x13F0, 0x0E40, 0x09C0, 0x0620, 0x0210, 0xFF10, 0xF510, 0xF340, 0xF190, 0xF070, 0xEFC0, 0xEF00, 0xEE80, 0xEDA0, 0xEC70, 0xEB70, + 0xE9D0, 0xE8A0, 0xE760, 0xE5C0, 0xE4C0, 0xE3B0, 0xE2E0, 0xE240, 0xE130, 0xE060, 0xDEF0, 0xDD50, 0xDC80, 0xDBD0, 0xDB60, 0xDA80, + 0xD9F0, 0xD9E0, 0xD960, 0xD8E0, 0xD870, 0xD7F0, 0xD790, 0xD700, 0xD6D0, 0xD730, 0xD6A0, 0xD770, 0xD790, 0xD7E0, 0xD750, 0xD6D0, + 0xD6D0, 0xD6A0, 0xD6D0, 0xD6D0, 0xD670, 0xD700, 0xD730, 0xD780, 0xD800, 0xD770, 0xD7E0, 0xD800, 0xD820, 0xD8B0, 0xD8B0, 0xD960, + 0xD950, 0xD930, 0xD8F0, 0xD870, 0xD870, 0xD810, 0xD7B0, 0xD770, 0xD730, 0xD750, 0xD720, 0xD700, 0xD6B0, 0xD6B0, 0xD6D0, 0xD6C0, + 0xD6A0, 0xD5D0, 0xD550, 0xD560, 0xD560, 0xD630, 0xD730, 0xD6F0, 0xD790, 0xD720, 0xD740, 0xD770, 0xD7A0, 0xD810, 0xD8D0, 0xD990, + 0xDA30, 0xDB00, 0xDBB0, 0xDC20, 0xDCB0, 0xDD20, 0xDE40, 0xDE90, 0xDFB0, 0xE1E0, 0xE380, 0xE4D0, 0xE690, 0xE900, 0xEAE0, 0xED10, + 0xEF40, 0xF0E0, 0xF320, 0xF4F0, 0xF740, 0xF9A0, 0xFC90, 0xFF50, 0x0240, 0x0570, 0x0870, 0x0C60, 0x1020, 0x1390, 0x16E0, 0x1A30, + 0x1D80, 0x2040, 0x2330, 0x25C0, 0x28C0, 0x2B20, 0x2DC0, 0x3000, 0x3230, 0x3470, 0x3640, 0x3890, 0x39F0, 0x3C00, 0x3D60, 0x3EF0, + 0x40D0, 0x42B0, 0x4480, 0x4640, 0x4870, 0x4A70, 0x4CE0, 0x4F10, 0x5130, 0x5360, 0x55E0, 0x5850, 0x5A90, 0x5D00, 0x5FE0, 0x62F0, + 0x65B0, 0x68B0, 0x6BC0, 0x6E50, 0x70D0, 0x73A0, 0x76C0, 0x7A50, 0x7DC0, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, + 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F00, + 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7EF0, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, + 0x7F20, 0x7F30, 0x7F30, 0x7F40, 0x7F40, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F20, 0x7F30, + 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, + 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F50, 0x7F20, 0x7F90, 0x7F30, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F30, + 0x7E70, 0x7EE0, 0x7EC0, 0x7EF0, 0x7EF0, 0x7EE0, 0x7F00, 0x7F00, 0x7F30, 0x7F00, 0x7E70, 0x7ED0, 0x7ED0, 0x7F10, 0x7F00, 0x7E90, + 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7EA0, 0x7F20, 0x7F00, 0x7F10, 0x7EF0, 0x7EA0, 0x7F00, 0x7F10, 0x7F20, 0x7EE0, 0x7EC0, 0x7F10, + 0x7F20, 0x70C0, 0x5B90, 0x4510, 0x30B0, 0x1DF0, 0x0B70, 0xFC20, 0xED20, 0xDDC0, 0xCCC0, 0xBAD0, 0xA840, 0x9690, 0x8A40, 0x8600, + 0x8530, 0x8500, 0x84E0, 0x84D0, 0x84C0, 0x84B0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, + 0x8480, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84D0, 0x84E0, 0x84F0, 0x8510, 0x8540, 0x8580, 0x85E0, + 0x86B0, 0x87C0, 0x8980, 0x8C00, 0x8ED0, 0x9260, 0x9540, 0x9800, 0x9A10, 0x9AF0, 0x9C30, 0x9D00, 0x9DD0, 0x9E40, 0x9E80, 0x9EF0, + 0x9EA0, 0x9EF0, 0x9E50, 0x9DC0, 0x9D50, 0x9C30, 0x9BB0, 0x9AE0, 0x9A10, 0x99E0, 0x9900, 0x98A0, 0x97E0, 0x9760, 0x96F0, 0x96A0, + 0x9650, 0x9630, 0x96C0, 0x9720, 0x9750, 0x97C0, 0x98E0, 0x9A40, 0x9B90, 0x9C90, 0x9DC0, 0x9EE0, 0x9FF0, 0xA1E0, 0xA3C0, 0xA650, + 0xA8C0, 0xAA70, 0xAC40, 0xAE40, 0xB050, 0xB2E0, 0xB560, 0xB890, 0xBAD0, 0xBD20, 0xC000, 0xC1E0, 0xC430, 0xC620, 0xC910, 0xCB00, + 0xCD10, 0xCF40, 0xD190, 0xD3F0, 0xD5A0, 0xD710, 0xD940, 0xDAE0, 0xDC70, 0xDF20, 0xE0B0, 0xE2D0, 0xE480, 0xE5F0, 0xE770, 0xE8A0, + 0xEA20, 0xEB40, 0xEC50, 0xEE20, 0xEED0, 0xF090, 0xF180, 0xF1E0, 0xF290, 0xF2B0, 0xF2F0, 0xF2E0, 0xF2C0, 0xF370, 0xF340, 0xF330, + 0xF350, 0xF2A0, 0xF280, 0xF2D0, 0xF250, 0xF290, 0xF2B0, 0xF390, 0xF420, 0xF480, 0xF5A0, 0xF650, 0xF870, 0xFA00, 0xFBD0, 0xFE70, + 0x00C0, 0x0E10, 0x1200, 0x16B0, 0x1AC0, 0x1F80, 0x2510, 0x2AF0, 0x3170, 0x3750, 0x3D50, 0x4300, 0x4840, 0x4DF0, 0x5340, 0x5820, + 0x5D40, 0x6130, 0x6670, 0x6AC0, 0x6E90, 0x7270, 0x74E0, 0x7780, 0x7980, 0x7AE0, 0x7BE0, 0x7BF0, 0x7C90, 0x7CE0, 0x7C90, 0x7C30, + 0x7AE0, 0x79E0, 0x77D0, 0x7530, 0x73B0, 0x7160, 0x6F90, 0x6E00, 0x6C90, 0x6BE0, 0x6A70, 0x6A10, 0x6910, 0x6860, 0x6870, 0x6900, + 0x6A50, 0x6C30, 0x6D20, 0x6EE0, 0x6F00, 0x7030, 0x7180, 0x7240, 0x7350, 0x7460, 0x7580, 0x76B0, 0x77B0, 0x7940, 0x7A50, 0x7B70, + 0x7C00, 0x7C60, 0x7C50, 0x7C10, 0x7AB0, 0x77C0, 0x7390, 0x6F00, 0x6900, 0x61E0, 0x5B10, 0x53E0, 0x4D60, 0x4690, 0x3FB0, 0x3820, + 0x2F40, 0x2690, 0x1D70, 0x1350, 0x09B0, 0x0050, 0xF800, 0xEF70, 0xE770, 0xE090, 0xD8E0, 0xD180, 0xC960, 0xC150, 0xBA60, 0xB350, + 0xACB0, 0xA630, 0xA080, 0x9AE0, 0x9610, 0x91B0, 0x8E00, 0x8B70, 0x8A00, 0x88F0, 0x8840, 0x87E0, 0x87A0, 0x8790, 0x8780, 0x87A0, + 0x87D0, 0x8820, 0x88D0, 0x89F0, 0x8BD0, 0x8ED0, 0x9250, 0x96D0, 0x9BA0, 0xA090, 0xA630, 0xAC50, 0xB3B0, 0xBA40, 0xC040, 0xC610, + 0xCBB0, 0xD1F0, 0xD640, 0xDB50, 0xE0B0, 0xE550, 0xEA40, 0xEE00, 0xF190, 0xF540, 0xF830, 0xFA70, 0xFBE0, 0xFCF0, 0xFE70, 0xFF60, + 0x0050, 0x0150, 0x01F0, 0x02C0, 0x03A0, 0x0510, 0x0680, 0x0740, 0x0910, 0x09F0, 0x0B90, 0x0C60, 0x0C90, 0x0D60, 0x0D80, 0x0CF0, + 0x0BD0, 0x0A50, 0x0870, 0x05E0, 0x0280, 0xFFC0, 0xFB90, 0xF770, 0xF2A0, 0xEDE0, 0xE900, 0xE410, 0xE030, 0xDC60, 0xD830, 0xD400, + 0xCFF0, 0xCCA0, 0xC8E0, 0xC610, 0xC410, 0xC270, 0xC0F0, 0xBF10, 0xBD10, 0xBB20, 0xB8E0, 0xB5F0, 0xB360, 0xB090, 0xADD0, 0xAA80, + 0xA6B0, 0xA2F0, 0x9EA0, 0x9AD0, 0x96F0, 0x9350, 0x8FF0, 0x8D30, 0x8AF0, 0x8940, 0x8840, 0x8780, 0x86E0, 0x86A0, 0x86A0, 0x8640, + 0x8630, 0x8600, 0x85F0, 0x85F0, 0x85E0, 0x85C0, 0x85D0, 0x85C0, 0x85C0, 0x85B0, 0x85D0, 0x85D0, 0x85F0, 0x85F0, 0x8600, 0x8630, + 0x8660, 0x8670, 0x86B0, 0x8700, 0x8770, 0x87E0, 0x8870, 0x8900, 0x89B0, 0x8AE0, 0x8C30, 0x8DC0, 0x8FD0, 0x91E0, 0x93D0, 0x9610, + 0x98C0, 0x9AB0, 0x9DA0, 0xA050, 0xA380, 0xA5C0, 0xA8E0, 0xAB10, 0xAD60, 0xAF50, 0xB100, 0xB300, 0xB4A0, 0xB680, 0xB7F0, 0xB9C0, + 0xBAD0, 0xBBF0, 0xBD80, 0xBE60, 0xBFD0, 0xC130, 0xC270, 0xC440, 0xC5C0, 0xC760, 0xC890, 0xC990, 0xCAB0, 0xCBE0, 0xCCD0, 0xCDD0, + 0xCED0, 0xD060, 0xD190, 0xD250, 0xD330, 0xD350, 0xD380, 0xD350, 0xD240, 0xD0F0, 0xCF70, 0xCE80, 0xCDD0, 0xCCF0, 0xCBD0, 0xCA90, + 0xC8F0, 0xC7A0, 0xC5C0, 0xC3F0, 0xC260, 0xBBE0, 0xBA30, 0xB7D0, 0xB5F0, 0xB400, 0xB180, 0xAF50, 0xAD20, 0xAB00, 0xA8E0, 0xA6D0, + 0xA520, 0xA340, 0xA140, 0x9FA0, 0x9E80, 0x9DE0, 0x9D20, 0x9BF0, 0x9B30, 0x9A50, 0x9A00, 0x99A0, 0x98F0, 0x9910, 0x9890, 0x98B0, + 0x9870, 0x9960, 0x99D0, 0x9A50, 0x9AE0, 0x9BA0, 0x9B60, 0x9C00, 0x9CB0, 0x9D70, 0x9D70, 0x9DB0, 0x9DE0, 0x9E40, 0x9E80, 0x9F70, + 0xA000, 0xA000, 0x9F80, 0x9F00, 0x9E50, 0x9DB0, 0x9D20, 0x9C60, 0x9CB0, 0x9CD0, 0x9D00, 0x9CC0, 0x9CF0, 0x9CE0, 0x9D10, 0x9C50, + 0x9BA0, 0x9B60, 0x9B60, 0x9BB0, 0x9BB0, 0x9BE0, 0x9C80, 0x9CA0, 0x9CE0, 0x9CD0, 0x9CD0, 0x9DB0, 0x9F00, 0xA0A0, 0xA300, 0xA570, + 0xA870, 0xAB40, 0xADF0, 0xB0D0, 0xB480, 0xB800, 0xBBF0, 0xBFF0, 0xC450, 0xC850, 0xCD10, 0xD1B0, 0xD5F0, 0xDA10, 0xDE90, 0xE340, + 0xE8B0, 0xEE10, 0xF390, 0xF8C0, 0xFE30, 0x02A0, 0x0700, 0x0B90, 0x0FD0, 0x1430, 0x1840, 0x1C70, 0x2070, 0x24D0, 0x2920, 0x2D80, + 0x31B0, 0x3550, 0x3940, 0x3CE0, 0x4050, 0x4350, 0x45F0, 0x4850, 0x4B30, 0x4DA0, 0x4FA0, 0x51D0, 0x5370, 0x5400, 0x53A0, 0x5230, + 0x50F0, 0x4FB0, 0x4E20, 0x4C10, 0x4A90, 0x4830, 0x4500, 0x41D0, 0x3DA0, 0x3970, 0x3540, 0x3130, 0x2D20, 0x28C0, 0x24C0, 0x2100, + 0x1D70, 0x19C0, 0x16A0, 0x13D0, 0x1100, 0x0E10, 0x0B60, 0x0910, 0x0780, 0x0570, 0x03D0, 0x0230, 0x0120, 0x0010, 0xFFD0, 0xFFF0, + 0x0020, 0x00C0, 0x00E0, 0x0170, 0x0140, 0x0190, 0x0230, 0x0370, 0x0500, 0x06D0, 0x0890, 0x09D0, 0x0B40, 0x0C90, 0x0DB0, 0x0F60, + 0x10C0, 0x1290, 0x1530, 0x1750, 0x18F0, 0x19A0, 0x1A80, 0x1A80, 0x1B10, 0x1B00, 0x1A60, 0x1B10, 0x1B10, 0x1AE0, 0x1A10, 0x1930, + 0x17E0, 0x1620, 0x1440, 0x1230, 0x0F90, 0x0D40, 0x0AA0, 0x0830, 0x0680, 0x0440, 0x0190, 0xFF00, 0xFC40, 0xFA20, 0xF7A0, 0xF590, + 0xF420, 0xF2F0, 0xF230, 0xF150, 0xF160, 0xF0F0, 0xF070, 0xF070, 0xF0F0, 0xF170, 0xF260, 0xF340, 0xF500, 0xF610, 0xF810, 0xF960, + 0xFA50, 0xFBA0, 0xFC10, 0xFCA0, 0xFCC0, 0xFC50, 0xFCF0, 0xFD20, 0xFE60, 0xFF50, 0x0100, 0x0220, 0x0290, 0x0350, 0x0370, 0x02C0, + 0x0360, 0x0350, 0x03F0, 0x0520, 0x0670, 0x0790, 0x0860, 0x0920, 0x09B0, 0x09A0, 0x0A60, 0x0AE0, 0x0B90, 0x0C70, 0x0D00, 0x0ED0, + 0x10B0, 0x12A0, 0x1420, 0x1560, 0x1730, 0x1930, 0x1C30, 0x1EB0, 0x2160, 0x2490, 0x2810, 0x2AB0, 0x2DA0, 0x2F60, 0x3200, 0x3320, + 0x34E0, 0x3640, 0x3770, 0x3A00, 0x3BE0, 0x3CF0, 0x3E70, 0x3F40, 0x4050, 0x40F0, 0x4110, 0x4200, 0x4110, 0x4150, 0x4100, 0x3FC0, + 0x3EF0, 0x3DA0, 0x3CA0, 0x3B50, 0x3A00, 0x3940, 0x3800, 0x3680, 0x35B0, 0x34B0, 0x3480, 0x33D0, 0x33A0, 0x33A0, 0x32C0, 0x31F0, + 0x3110, 0x2F40, 0x2E10, 0x2CA0, 0x2BD0, 0x2AF0, 0x29A0, 0x2770, 0x2390, 0x1F20, 0x1830, 0x0FE0, 0x0580, 0xFB50, 0xF180, 0xE880, + 0xE090, 0xD9D0, 0xD3A0, 0xCE60, 0xC8C0, 0xC270, 0xBC20, 0xB540, 0xAF00, 0xA870, 0xA290, 0x9D40, 0x9870, 0x9430, 0x9150, 0x8F80, + 0x8F00, 0x8E60, 0x8DC0, 0x8CE0, 0x8B20, 0x8970, 0x87A0, 0x8640, 0x8590, 0x8530, 0x8500, 0x84E0, 0x84D0, 0x84C0, 0x84C0, 0x84B0, + 0x84B0, 0x8450, 0x84B0, 0x84A0, 0x84A0, 0x84D0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84C0, 0x84D0, 0x84E0, 0x84F0, + 0x8510, 0x8530, 0x8570, 0x85F0, 0x8B00, 0x8BC0, 0x8B80, 0x8A60, 0x8930, 0x8830, 0x8790, 0x8720, 0x86E0, 0x86D0, 0x86C0, 0x86A0, + 0x86A0, 0x8680, 0x8690, 0x8680, 0x8690, 0x8690, 0x86A0, 0x86B0, 0x8700, 0x8720, 0x8700, 0x86C0, 0x8660, 0x85E0, 0x8560, 0x8510, + 0x84F0, 0x84D0, 0x84B0, 0x84A0, 0x8490, 0x8480, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x84A0, 0x84C0, + 0x8500, 0x85C0, 0x8B80, 0xA2E0, 0xB7D0, 0xCC30, 0xDEF0, 0xEFA0, 0xFDD0, 0x0970, 0x1260, 0x1880, 0x1D50, 0x20A0, 0x2340, 0x2650, + 0x28B0, 0x2AB0, 0x2C40, 0x2C30, 0x2BF0, 0x28E0, 0x2490, 0x1FF0, 0x1960, 0x1300, 0x0B50, 0x0230, 0xF770, 0xE9C0, 0xD730, 0xC270, + 0xAAA0, 0x9290, 0x8690, 0x8500, 0x84C0, 0x84A0, 0x8490, 0x8480, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8450, 0x84D0, 0x8550, + 0x8900, 0x9280, 0x9360, 0x8D00, 0x8700, 0x8520, 0x8500, 0x84B0, 0x84A0, 0x8470, 0x8460, 0x8450, 0x8440, 0x8440, 0x8420, 0x8410, + 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8420, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, + 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8470, 0x8450, 0x8450, + 0x8400, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84D0, 0x84E0, 0x84F0, + 0x8500, 0x8510, 0x8510, 0x8510, 0x8510, 0x8510, 0x8500, 0x8500, 0x8500, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x8500, + 0x8500, 0x8510, 0x8520, 0x8530, 0x8550, 0x85B0, 0x8650, 0x87E0, 0x8BD0, 0x9350, 0x9C70, 0xA4F0, 0xADD0, 0xB6D0, 0xC030, 0xC890, + 0xD120, 0xD940, 0xE140, 0xE990, 0xF090, 0xF6B0, 0xFC80, 0x0180, 0x0590, 0x08B0, 0x09E0, 0x0B40, 0x0B50, 0x0AB0, 0x0A40, 0x0920, + 0x07F0, 0x06E0, 0x05A0, 0x04D0, 0x03B0, 0x0360, 0x0370, 0x03F0, 0x05B0, 0x0830, 0x0C80, 0x1170, 0x1880, 0x2210, 0x2D30, 0x3A40, + 0x4650, 0x50F0, 0x5A00, 0x5EE0, 0x61C0, 0x63D0, 0x66F0, 0x6BC0, 0x7150, 0x7850, 0x7DB0, 0x7F30, 0x7F10, 0x7EA0, 0x7EC0, 0x7EF0, + 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7EB0, 0x7F00, 0x7F20, 0x7EF0, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F00, + 0x7EF0, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F10, 0x7C00, 0x79E0, 0x7A70, 0x7DA0, 0x7EF0, + 0x7F30, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x6630, 0x4A70, 0x32C0, 0x2300, 0x1C90, 0x1ED0, 0x26C0, 0x3250, 0x3D50, 0x4610, + 0x4B50, 0x4CC0, 0x4BC0, 0x4A60, 0x48B0, 0x4840, 0x4880, 0x47F0, 0x46C0, 0x44D0, 0x42B0, 0x40D0, 0x3F40, 0x3F80, 0x4030, 0x4260, + 0x4500, 0x4850, 0x4AF0, 0x4C10, 0x4CD0, 0x4C90, 0x4BF0, 0x4A10, 0x48E0, 0x4750, 0x4680, 0x4600, 0x45D0, 0x4600, 0x46E0, 0x4760, + 0x47D0, 0x4830, 0x48E0, 0x4A00, 0x4B90, 0x4DE0, 0x4F70, 0x5180, 0x5350, 0x5530, 0x57E0, 0x5A40, 0x5CF0, 0x6000, 0x62A0, 0x6600, + 0x6880, 0x6B70, 0x6DA0, 0x6F80, 0x7340, 0x7370, 0x7370, 0x7320, 0x72B0, 0x71D0, 0x70C0, 0x7000, 0x6EB0, 0x6DB0, 0x6CC0, 0x6B80, + 0x69D0, 0x6900, 0x6840, 0x68C0, 0x69B0, 0x6AB0, 0x6D00, 0x6E90, 0x7040, 0x7190, 0x7230, 0x71F0, 0x70C0, 0x6EB0, 0x6BF0, 0x68B0, + 0x6460, 0x5F50, 0x5AA0, 0x5570, 0x5070, 0x4B70, 0x4660, 0x4120, 0x3C40, 0x36D0, 0x3120, 0x2B40, 0x2590, 0x1FD0, 0x1A60, 0x1510, + 0x0FD0, 0x0A90, 0x0500, 0xFE80, 0xF8A0, 0xF2E0, 0xEDE0, 0xE910, 0xE4A0, 0xE0C0, 0xDD10, 0xDAD0, 0xD880, 0xD660, 0xD4C0, 0xD3D0, + 0xD290, 0xD220, 0xD140, 0xD0C0, 0xD080, 0xD000, 0xCF60, 0xCEB0, 0xCDB0, 0xCCE0, 0xCCA0, 0xCCD0, 0xCD50, 0xCE40, 0xCEC0, 0xCEF0, + 0xCFA0, 0xCF30, 0xCD70, 0xCAC0, 0xC710, 0xC270, 0xBE00, 0xB910, 0xB4F0, 0xB1C0, 0xAE90, 0xAC40, 0xAB00, 0xA930, 0xA880, 0xA900, + 0xAA70, 0xAD80, 0xB030, 0xB270, 0xB270, 0xAEC0, 0xA740, 0x9B30, 0x8D50, 0x8630, 0x8500, 0x84D0, 0x84B0, 0x84A0, 0x8490, 0x8480, + 0x8480, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84D0, 0x84F0, + 0x8500, 0x8530, 0x8590, 0x8620, 0x8780, 0x89C0, 0x8D30, 0x9110, 0x9440, 0x9820, 0x9AE0, 0x9DC0, 0xA0B0, 0xA460, 0xA9B0, 0xAF60, + 0xB5F0, 0xBDB0, 0xC6E0, 0xD160, 0xDD40, 0xEA10, 0xF9A0, 0x08C0, 0x1930, 0x2A00, 0x3B20, 0x4BF0, 0x5B90, 0x6AA0, 0x76E0, 0x7EF0, + 0x7F00, 0x7EE0, 0x7EE0, 0x7ED0, 0x7F30, 0x7F20, 0x7EC0, 0x7ED0, 0x7EE0, 0x7F50, 0x7F10, 0x7EA0, 0x7EC0, 0x7EE0, 0x7F10, 0x7F20, + 0x7EC0, 0x7EE0, 0x7EE0, 0x7F10, 0x7F10, 0x7EA0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F00, + 0x7F50, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, 0x7F70, 0x7EF0, 0x7F20, 0x7F10, 0x7F10, 0x7F30, + 0x7EE0, 0x7ED0, 0x7EF0, 0x7F10, 0x7F60, 0x7F00, 0x7EE0, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7ED0, + 0x7E90, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7EB0, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F30, 0x7F10, 0x7F20, 0x7F40, 0x7F10, + 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7F70, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F80, 0x7F00, 0x7F10, 0x7EF0, 0x7EF0, 0x7F60, + 0x7EF0, 0x7ED0, 0x7EF0, 0x7F00, 0x7F70, 0x7F00, 0x7ED0, 0x7ED0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7EB0, 0x7EB0, 0x7EC0, 0x7EF0, 0x7F10, + 0x7EA0, 0x7EE0, 0x7F10, 0x7F10, 0x7F20, 0x7E90, 0x7EF0, 0x7F00, 0x7F00, 0x7EF0, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F20, 0x7F00, + 0x7F40, 0x7C50, 0x77F0, 0x7470, 0x7140, 0x6DF0, 0x6500, 0x63D0, 0x6230, 0x6070, 0x5F60, 0x5D00, 0x5B60, 0x5990, 0x57F0, 0x5740, + 0x5640, 0x5590, 0x55B0, 0x5570, 0x56C0, 0x5780, 0x5890, 0x59E0, 0x5B40, 0x5D90, 0x5F90, 0x6130, 0x63A0, 0x6530, 0x66A0, 0x6780, + 0x6890, 0x69B0, 0x6AA0, 0x6C80, 0x6ED0, 0x70B0, 0x7360, 0x75D0, 0x7910, 0x7C00, 0x7E60, 0x7F10, 0x7EB0, 0x7F20, 0x7F00, 0x7F30, + 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7F80, 0x7EF0, 0x7F10, 0x7F30, 0x7F20, 0x7F80, 0x7F10, 0x7F10, 0x7EF0, + 0x7EE0, 0x7F70, 0x7EF0, 0x7F20, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7ED0, 0x7EF0, 0x7EF0, 0x7F70, 0x7F00, 0x7EE0, 0x7ED0, 0x7EF0, + 0x7F60, 0x7F20, 0x7E90, 0x7EF0, 0x7F00, 0x7F30, 0x7F10, 0x7E90, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EA0, 0x7ED0, 0x7F10, 0x7F20, + 0x7F20, 0x7EC0, 0x7F10, 0x7F00, 0x7F00, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F50, 0x7EF0, 0x7F20, 0x7F10, + 0x7F10, 0x7F30, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F60, 0x7F20, 0x7F40, 0x7F10, 0x7F00, 0x7F60, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, + 0x7F70, 0x7EF0, 0x7EB0, 0x7F00, 0x7F10, 0x7F30, 0x7EB0, 0x7E70, 0x7EF0, 0x7F00, 0x7F20, 0x7ED0, 0x7EB0, 0x7F10, 0x7F20, 0x7F10, + 0x7F10, 0x7EB0, 0x7F00, 0x7C40, 0x6E50, 0x6130, 0x5440, 0x4620, 0x38D0, 0x2B00, 0x1DF0, 0x0EC0, 0x01C0, 0xF440, 0xE7B0, 0xDCA0, + 0xD270, 0xCA50, 0xC370, 0xBEA0, 0xBB20, 0xB8D0, 0xB7C0, 0xB7E0, 0xB860, 0xBAB0, 0xBD70, 0xC190, 0xC610, 0xCA50, 0xCE20, 0xD060, + 0xD0C0, 0xD0D0, 0xCF90, 0xCD80, 0xCA70, 0xC6D0, 0xC300, 0xBE10, 0xB9B0, 0xB4B0, 0xAE80, 0xA8A0, 0xA130, 0x9A20, 0x92D0, 0x8C00, + 0x8870, 0x8680, 0x85A0, 0x8530, 0x8500, 0x84E0, 0x84D0, 0x84C0, 0x84B0, 0x84A0, 0x84A0, 0x8440, 0x8490, 0x8480, 0x8480, 0x8410, + 0x8480, 0x8480, 0x8480, 0x8490, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84C0, 0x84D0, + 0x84D0, 0x84E0, 0x84E0, 0x84D0, 0x84E0, 0x84E0, 0x84F0, 0x84E0, 0x84E0, 0x84D0, 0x84C0, 0x84B0, 0x84C0, 0x8490, 0x8490, 0x84A0, + 0x84C0, 0x84E0, 0x8520, 0x8570, 0x8540, 0x84E0, 0x84B0, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84C0, 0x8510, 0x8850, 0xA6D0, + 0xCB80, 0xF420, 0x20E0, 0x4FD0, 0x79B0, 0x7F00, 0x7F80, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F70, 0x7F00, 0x7EE0, 0x7EF0, 0x7EF0, + 0x7F60, 0x7EF0, 0x7ED0, 0x62B0, 0x4260, 0x20D0, 0xFFD0, 0xDE30, 0xBDE0, 0x9D10, 0x88E0, 0x8540, 0x84E0, 0x84D0, 0x84C0, 0x84C0, + 0x84D0, 0x84D0, 0x84E0, 0x84E0, 0x84F0, 0x8520, 0x8560, 0x8600, 0x87C0, 0x8BE0, 0x9360, 0x9B00, 0xA240, 0xA920, 0xAFA0, 0xB660, + 0xBDB0, 0xC670, 0xCF70, 0xD990, 0xE450, 0xEEE0, 0xF9C0, 0x0310, 0x0BD0, 0x1340, 0x19D0, 0x1E30, 0x21C0, 0x23C0, 0x23F0, 0x2270, + 0x1F70, 0x1AE0, 0x1450, 0x0C10, 0x0360, 0xFA60, 0xF1B0, 0xE910, 0xE1C0, 0xDB20, 0xD610, 0xD200, 0xCF10, 0xCDC0, 0xCDF0, 0xCF60, + 0xD230, 0xD750, 0xDDB0, 0xE600, 0xF0E0, 0xFCB0, 0x0850, 0x1460, 0x1F40, 0x2930, 0x3180, 0x3800, 0x3D00, 0x40C0, 0x43C0, 0x4580, + 0x4680, 0x46F0, 0x4720, 0x4670, 0x4440, 0x3FF0, 0x3B30, 0x3550, 0x3000, 0x2BA0, 0x2840, 0x25E0, 0x2370, 0x2010, 0x1B80, 0x15C0, + 0x0E80, 0x0860, 0x0370, 0x0070, 0x0000, 0x0220, 0x06B0, 0x0D80, 0x15B0, 0x1FC0, 0x28B0, 0x3170, 0x3960, 0x3FF0, 0x4580, 0x49A0, + 0x4CC0, 0x4ED0, 0x4F70, 0x4F90, 0x4EC0, 0x4D50, 0x4B80, 0x4990, 0x4600, 0x42D0, 0x3EC0, 0x39C0, 0x34E0, 0x2F90, 0x2A10, 0x24A0, + 0x1F50, 0x1A50, 0x15B0, 0x1160, 0x0DB0, 0x0A70, 0x08A0, 0x0760, 0x06C0, 0x06D0, 0x06D0, 0x06E0, 0x0740, 0x07F0, 0x08C0, 0x0A30, + 0x0BD0, 0x0E30, 0x1160, 0x14E0, 0x1950, 0x1D00, 0x2110, 0x2430, 0x2760, 0x2AA0, 0x2DB0, 0x30B0, 0x33C0, 0x3660, 0x38D0, 0x3B30, + 0x3D00, 0x3E20, 0x3E90, 0x3E90, 0x3D00, 0x3B90, 0x3950, 0x3630, 0x3300, 0x3000, 0x2C90, 0x2920, 0x2630, 0x2350, 0x1FF0, 0x1DB0, + 0x1B40, 0x1910, 0x1630, 0x0B10, 0x0820, 0x06C0, 0x05F0, 0x05F0, 0x0740, 0x09C0, 0x0E50, 0x1370, 0x19D0, 0x20B0, 0x2960, 0x3140, + 0x39B0, 0x4230, 0x49F0, 0x5230, 0x58C0, 0x5F80, 0x6550, 0x6A10, 0x6F70, 0x7340, 0x76D0, 0x7A80, 0x7D40, 0x7ED0, 0x7EA0, 0x7EC0, + 0x7F10, 0x7F10, 0x7F10, 0x7EA0, 0x7F00, 0x7EE0, 0x7EF0, 0x7D50, 0x7880, 0x7280, 0x6B80, 0x62F0, 0x59F0, 0x4F00, 0x4200, 0x3550, + 0x2810, 0x1B20, 0x0E00, 0x0140, 0xF4F0, 0xE9E0, 0xE100, 0xD860, 0xD1F0, 0xCD70, 0xCA70, 0xC9E0, 0xCA20, 0xCC30, 0xCFE0, 0xD560, + 0xDD40, 0xE540, 0xEEB0, 0xF970, 0x0440, 0x0F90, 0x1A10, 0x2370, 0x2C70, 0x3530, 0x3D60, 0x4540, 0x4C30, 0x53D0, 0x5A60, 0x60A0, + 0x6550, 0x6890, 0x6BC0, 0x6CD0, 0x6EB0, 0x6FE0, 0x7060, 0x7190, 0x7200, 0x72B0, 0x72C0, 0x71B0, 0x7160, 0x6FC0, 0x6E10, 0x6B90, + 0x6830, 0x65C0, 0x61D0, 0x5E50, 0x5A80, 0x56D0, 0x5440, 0x5210, 0x5040, 0x4F90, 0x4F60, 0x5050, 0x5150, 0x5330, 0x5560, 0x57C0, + 0x5B50, 0x6080, 0x66A0, 0x6EC0, 0x7790, 0x7E90, 0x7F00, 0x7F50, 0x7F10, 0x7EA0, 0x7ED0, 0x7ED0, 0x7F30, 0x7F20, 0x7EC0, 0x7ED0, + 0x7EE0, 0x7F20, 0x7F20, 0x7EB0, 0x7EF0, 0x7F00, 0x7EF0, 0x7F10, 0x7E90, 0x7EF0, 0x7F20, 0x7F20, 0x7F20, 0x7E10, 0x77F0, 0x7060, + 0x6790, 0x5E50, 0x5520, 0x4C00, 0x4350, 0x3A00, 0x31A0, 0x28C0, 0x1F10, 0x1510, 0x09A0, 0xFFD0, 0xF600, 0xECD0, 0xE440, 0xDBD0, + 0xD450, 0xCD30, 0xC620, 0xC030, 0xBAF0, 0xB6D0, 0xB300, 0xAFB0, 0xADB0, 0xABB0, 0xAAB0, 0xAA10, 0xA960, 0xAA10, 0xAA30, 0xAB00, + 0xAB80, 0xABB0, 0xAC90, 0xAD80, 0xAFC0, 0xB270, 0xB650, 0xBC20, 0xC300, 0xCB30, 0xD420, 0xDE00, 0xE7F0, 0xF120, 0xFA80, 0x0290, + 0x0910, 0x0F30, 0x1460, 0x19C0, 0x1E30, 0x21B0, 0x24E0, 0x2620, 0x25E0, 0x2400, 0x2050, 0x1AB0, 0x1360, 0x0940, 0xFD10, 0xEE20, + 0xDC40, 0xC950, 0xB590, 0xA1D0, 0x8F10, 0x86B0, 0x8520, 0x84E0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84C0, + 0x84D0, 0x84F0, 0x8510, 0x8570, 0x8650, 0x88C0, 0x8EF0, 0x9760, 0x9D60, 0xA220, 0xA450, 0xA510, 0xA310, 0x9FD0, 0x9C50, 0x98D0, + 0x96F0, 0x9710, 0x9A50, 0xA030, 0xA910, 0xB410, 0xC0B0, 0xCCF0, 0xD990, 0xE610, 0xF170, 0xFC20, 0x0500, 0x0E30, 0x1590, 0x1AE0, + 0x1D80, 0x1D90, 0x1CF0, 0x1A30, 0x1660, 0x12E0, 0x0FD0, 0x0F00, 0x0FC0, 0x1220, 0x14F0, 0x18C0, 0x1C50, 0x1F20, 0x1FF0, 0x1FC0, + 0x1DD0, 0x1B30, 0x16A0, 0x0FF0, 0x0880, 0xFF10, 0xF4E0, 0xE990, 0xDCB0, 0xCFA0, 0xC200, 0xB620, 0xAB30, 0xA280, 0x9EC0, 0x9D90, + 0x9DE0, 0x9E70, 0x9EF0, 0x9F40, 0x9E60, 0x9CA0, 0x9A30, 0x9700, 0x94B0, 0x91B0, 0x8F60, 0x8D90, 0x8C70, 0x8CA0, 0x8DF0, 0x91C0, + 0x97B0, 0x9E90, 0xA660, 0xADB0, 0xB440, 0xB9F0, 0xBF70, 0xC510, 0xCAB0, 0xCFF0, 0xD590, 0xD9B0, 0xDD70, 0xDF10, 0xDF30, 0xDEF0, + 0xDD90, 0xDD40, 0xDDD0, 0xDEB0, 0xE1C0, 0xE570, 0xEA90, 0xF120, 0xF870, 0x0110, 0x0C00, 0x1860, 0x2620, 0x3550, 0x44F0, 0x52A0, + 0x5E20, 0x6690, 0x6C50, 0x7060, 0x7140, 0x7150, 0x6FB0, 0x6C60, 0x67D0, 0x60C0, 0x57B0, 0x4C40, 0x3E10, 0x30B0, 0x2320, 0x1750, + 0x0C10, 0x0290, 0xFAC0, 0xF3D0, 0xEE30, 0xEA20, 0xE900, 0xEAB0, 0xEEF0, 0xF560, 0xFDC0, 0x06F0, 0x10B0, 0x18E0, 0x1FD0, 0x24B0, + 0x27A0, 0x2980, 0x2980, 0x28B0, 0x27C0, 0x2670, 0x25B0, 0x25A0, 0x2570, 0x2590, 0x2550, 0x2500, 0x2460, 0x2350, 0x2260, 0x20A0, + 0x1F10, 0x1C10, 0x17E0, 0x1370, 0x0D50, 0x06B0, 0xFF00, 0xF5C0, 0xEB50, 0xDE00, 0xCF70, 0xBE90, 0xA990, 0x9230, 0x8620, 0x84E0, + 0x84B0, 0x84B0, 0x8470, 0x8460, 0x8450, 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, + 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, 0x8470, + 0x8470, 0x8440, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8470, 0x8480, 0x8480, 0x8480, + 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8480, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, + 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x84B0, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, + 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x8490, 0x8490, 0x8490, 0x84A0, 0x8490, 0x84A0, 0x8490, 0x84A0, + 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84D0, 0x84D0, 0x84E0, 0x84E0, 0x84F0, 0x8500, + 0x8520, 0x8540, 0x8580, 0x85E0, 0x8670, 0x8790, 0x88D0, 0x8B70, 0x8F70, 0x9420, 0x98C0, 0x9D70, 0xA270, 0xA710, 0xAC90, 0xB150, + 0xB5F0, 0xBAE0, 0xBFF0, 0xC510, 0xCA50, 0xCFA0, 0xD4F0, 0xDAB0, 0xE000, 0xE590, 0xEB30, 0xF0E0, 0xF6E0, 0xFD40, 0x0380, 0x0A50, + 0x1120, 0x1740, 0x1D50, 0x2370, 0x2910, 0x2E40, 0x3390, 0x37A0, 0x3BF0, 0x4020, 0x43F0, 0x4740, 0x4A20, 0x4CF0, 0x4FD0, 0x51B0, + 0x5360, 0x54D0, 0x5610, 0x5720, 0x5840, 0x5940, 0x5A30, 0x5BA0, 0x5CC0, 0x5E10, 0x5E50, 0x5EC0, 0x5ED0, 0x5EE0, 0x5E70, 0x5DC0, + 0x5D50, 0x5C30, 0x5B30, 0x59C0, 0x5810, 0x5610, 0x5460, 0x52A0, 0x4FD0, 0x4D30, 0x4B70, 0x49C0, 0x4880, 0x4720, 0x45E0, 0x4410, + 0x4230, 0x4090, 0x3F20, 0x3E00, 0x3CB0, 0x3C70, 0x3BF0, 0x3C10, 0x3C20, 0x3C60, 0x3C60, 0x3C80, 0x3C90, 0x3CE0, 0x3DA0, 0x3E60, + 0x3FE0, 0x4140, 0x4310, 0x44D0, 0x4630, 0x4780, 0x48C0, 0x4990, 0x4AF0, 0x4C30, 0x4DA0, 0x4F20, 0x5140, 0x52B0, 0x54D0, 0x5680, + 0x5910, 0x5AF0, 0x5DE0, 0x60E0, 0x6450, 0x67D0, 0x6B80, 0x6F20, 0x7240, 0x75B0, 0x78A0, 0x7B00, 0x7CD0, 0x7E50, 0x7F00, 0x7F20, + 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F30, + 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F00, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7EF0, 0x7F30, 0x7F30, + 0x7F20, 0x7F40, 0x7F50, 0x7F30, 0x7EF0, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7ED0, 0x7EF0, 0x7F20, 0x7F60, 0x7F10, 0x7E90, 0x7EB0, + 0x7F20, 0x7F40, 0x7EF0, 0x7E70, 0x7EE0, 0x7EF0, 0x7F30, 0x7F00, 0x7EC0, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7EA0, 0x7F20, 0x7EF0, + 0x7EF0, 0x7F10, 0x7EC0, 0x7EF0, 0x7EF0, 0x7F20, 0x7F20, 0x7F00, 0x7F50, 0x7EF0, 0x7F20, 0x7F10, 0x7230, 0x6260, 0x5570, 0x4AB0, + 0x43B0, 0x4020, 0x3F10, 0x4050, 0x4260, 0x4490, 0x4510, 0x45A0, 0x4740, 0x4B40, 0x5450, 0x61B0, 0x72F0, 0x7F10, 0x7F00, 0x7F00, + 0x7EF0, 0x7F30, 0x7EF0, 0x7F00, 0x7EF0, 0x7F10, 0x7F50, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7EF0, 0x7F10, 0x7F10, + 0x7F70, 0x7EB0, 0x48A0, 0x1010, 0xD570, 0x9B30, 0x8500, 0x84A0, 0x8470, 0x8460, 0x8450, 0x8440, 0x8440, 0x8430, 0x8420, 0x8430, + 0x8430, 0x8430, 0x8440, 0x8450, 0x8450, 0x8470, 0x8480, 0x8480, 0x8490, 0x84A0, 0x84B0, 0x84E0, 0x84E0, 0x8510, 0x8570, 0x8690, + 0x8980, 0x8EB0, 0x9480, 0x98D0, 0x9C20, 0x9E70, 0x9F80, 0x9FD0, 0x9ED0, 0x9E30, 0x9C30, 0x9960, 0x95D0, 0x9270, 0x8EF0, 0x8BF0, + 0x8990, 0x87F0, 0x86C0, 0x8600, 0x8580, 0x8530, 0x8510, 0x84F0, 0x84E0, 0x84D0, 0x84C0, 0x84C0, 0x84B0, 0x84A0, 0x84D0, 0x84A0, + 0x8490, 0x8490, 0x84B0, 0x84A0, 0x8480, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, + 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, + 0x84C0, 0x84C0, 0x84D0, 0x84E0, 0x84F0, 0x8500, 0x8510, 0x8530, 0x8550, 0x85A0, 0x8610, 0x8710, 0x88B0, 0x8BD0, 0x9080, 0x95B0, + 0x9B00, 0xA0E0, 0xA690, 0xAD90, 0xB4B0, 0xBC90, 0xC470, 0xCBE0, 0xD310, 0xDA30, 0xF230, 0xF630, 0xF9B0, 0xFC40, 0xFE50, 0xFFB0, + 0x0140, 0x0340, 0x0580, 0x07E0, 0x0A70, 0x0D40, 0x1090, 0x1350, 0x15C0, 0x1720, 0x1750, 0x16E0, 0x14D0, 0x1190, 0x0D20, 0x0770, + 0x0140, 0xFA50, 0xF3A0, 0xED90, 0xE810, 0xE3C0, 0xDFE0, 0xDC90, 0xD9B0, 0xD7B0, 0xD680, 0xD650, 0xD6B0, 0xD890, 0xDB90, 0xE060, + 0xE690, 0xEEF0, 0xFA00, 0x0610, 0x1320, 0x20A0, 0x2F10, 0x3CB0, 0x48C0, 0x5430, 0x5EB0, 0x6740, 0x6FA0, 0x7600, 0x7B10, 0x7E40, + 0x7ED0, 0x7F10, 0x7F00, 0x7F20, 0x7EF0, 0x7F30, 0x7F20, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F20, + 0x7F20, 0x7EF0, 0x7F50, 0x7F10, 0x7DA0, 0x6440, 0x4690, 0x24F0, 0x01A0, 0xDD00, 0xB6E0, 0x9590, 0x8640, 0x8530, 0x84B0, 0x84A0, + 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84A0, + 0x84A0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8430, + 0x8430, 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, + 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84E0, 0x8500, 0x8540, 0x85D0, 0x86C0, 0x8810, + 0x89D0, 0x8B60, 0x8C60, 0x8CA0, 0x8D00, 0x8CA0, 0x8C60, 0x8C10, 0x8BF0, 0x8C50, 0x8D10, 0x8F10, 0x9080, 0x91D0, 0x9310, 0x94E0, + 0x9680, 0x9800, 0x9970, 0x9B40, 0x9CD0, 0x9E60, 0x9EF0, 0x9ED0, 0x9DD0, 0x9BF0, 0x98D0, 0x9500, 0x9160, 0x8EE0, 0x8CD0, 0x8BF0, + 0x8BA0, 0x8C00, 0x8DB0, 0x9040, 0x9510, 0x9AA0, 0xA220, 0xAA70, 0xB310, 0xBD20, 0xC6A0, 0xD000, 0xD9F0, 0xE300, 0xEB20, 0xF2A0, + 0xF850, 0xFE30, 0x0280, 0x0620, 0x0850, 0x08B0, 0x08E0, 0x07C0, 0x05F0, 0x0380, 0x0080, 0xFE50, 0xFBD0, 0xFA60, 0xFA10, 0xFA70, + 0xFB10, 0xFBC0, 0xFC30, 0xFE00, 0xFFA0, 0x01E0, 0x04D0, 0x0770, 0x0AE0, 0x0D70, 0x1020, 0x1260, 0x13D0, 0x1590, 0x1640, 0x1760, + 0x1790, 0x17B0, 0x1870, 0x1890, 0x19A0, 0x1AD0, 0x1B70, 0x1D50, 0x1F00, 0x2140, 0x2330, 0x2510, 0x2800, 0x2A50, 0x2D50, 0x30B0, + 0x3420, 0x37C0, 0x3B00, 0x3EB0, 0x4240, 0x45D0, 0x4A60, 0x4DC0, 0x5190, 0x5510, 0x5860, 0x5BA0, 0x5F10, 0x6250, 0x65B0, 0x68E0, + 0x6C50, 0x6F80, 0x7270, 0x7520, 0x7750, 0x7A00, 0x7BB0, 0x7D30, 0x7E00, 0x7E70, 0x7ED0, 0x7F10, 0x7F70, 0x7F00, 0x7ED0, 0x7F10, + 0x7F20, 0x7F40, 0x7F20, 0x7F20, 0x7EF0, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7EF0, 0x7F30, 0x7F20, 0x7F20, 0x7F10, + 0x7EF0, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F40, + 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x76A0, 0x6AF0, 0x5D50, 0x4ED0, 0x3EB0, 0x2D40, + 0x1970, 0x02F0, 0xE9F0, 0xCC70, 0xAE00, 0x8FB0, 0x8570, 0x84C0, 0x84A0, 0x8480, 0x8480, 0x8470, 0x8460, 0x8450, 0x8450, 0x8440, + 0x8440, 0x8440, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8460, 0x8460, 0x8470, 0x8480, 0x8490, 0x84E0, 0x84C0, 0x84E0, + 0x8510, 0x8580, 0x86B0, 0x89F0, 0x9090, 0x9890, 0x9F50, 0xA4E0, 0xA880, 0xAA80, 0xAB40, 0xABD0, 0xAC70, 0xAE50, 0xB110, 0xB500, + 0xB8D0, 0xB870, 0xB0B0, 0x9FB0, 0x8AE0, 0x8530, 0x84D0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84E0, 0x8520, 0x8570, 0x8610, 0x86B0, + 0x8790, 0x8940, 0x8D60, 0x93D0, 0x9C00, 0xA420, 0xAA60, 0xAFC0, 0xB3C0, 0xB770, 0xBA60, 0xBD50, 0xC030, 0xC3A0, 0xC6B0, 0xC9C0, + 0xCC30, 0xCD80, 0xCD90, 0xCCD0, 0xCB00, 0xC8E0, 0xC8B0, 0xC9C0, 0xCC60, 0xD150, 0xD710, 0xDDF0, 0xE640, 0xF1D0, 0xFD10, 0x0920, + 0x1500, 0x2050, 0x2A90, 0x32E0, 0x39C0, 0x3EF0, 0x4320, 0x4530, 0x4610, 0x4530, 0x42F0, 0x3EF0, 0x3990, 0x3320, 0x2AC0, 0x2050, + 0x1560, 0x0920, 0xFC40, 0xEF00, 0xE1F0, 0xD6B0, 0xCD20, 0xC690, 0xC160, 0xBE40, 0xBBD0, 0xB880, 0xB550, 0xB0C0, 0xAC80, 0xA820, + 0xA470, 0xA170, 0x9FC0, 0x9F40, 0x9FC0, 0xA160, 0xA2F0, 0xA510, 0xA6A0, 0xA770, 0xA770, 0xA650, 0xA4E0, 0xA2B0, 0x9F70, 0x9C20, + 0x9820, 0x93C0, 0x8F90, 0x8B40, 0x8900, 0x8770, 0x8680, 0x8600, 0x85A0, 0x8570, 0x8550, 0x8540, 0x8540, 0x8540, 0x8550, 0x8580, + 0x85C0, 0x8660, 0x8820, 0x8CB0, 0x9670, 0xA170, 0xAB60, 0xB470, 0xBC60, 0xC3C0, 0xCA40, 0xD060, 0xD660, 0xDCC0, 0xE350, 0xE980, + 0xEFB0, 0xF510, 0xF990, 0xFCF0, 0xFF70, 0x02A0, 0x05B0, 0x0A20, 0x0EF0, 0x1590, 0x1DE0, 0x2740, 0x3290, 0x3E30, 0x49B0, 0x56C0, + 0x6410, 0x7210, 0x7D70, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F40, 0x7F00, 0x7F30, 0x7F00, 0x7F20, 0x7EF0, 0x7F10, + 0x7F60, 0x7F00, 0x7F10, 0x7F20, 0x7F00, 0x7F90, 0x7F10, 0x7F10, 0x7EE0, 0x7EF0, 0x7F80, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, + 0x7F10, 0x7EB0, 0x7EB0, 0x7EC0, 0x7F30, 0x7EF0, 0x7ED0, 0x7EF0, 0x7F00, 0x7F30, 0x7ED0, 0x7090, 0x5E00, 0x4460, 0x2710, 0x0830, + 0xE800, 0xC880, 0xAA80, 0x8FE0, 0x85F0, 0x84E0, 0x84B0, 0x84A0, 0x8490, 0x8480, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, + 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84E0, 0x8500, 0x8520, 0x8580, 0x8630, + 0x8810, 0xA710, 0xB130, 0xBA00, 0xC250, 0xCB60, 0xD450, 0xDD00, 0xE510, 0xEC70, 0xF330, 0xF930, 0xFE30, 0x0220, 0x03C0, 0x0410, + 0x01E0, 0xFDD0, 0xF7B0, 0xF010, 0xE700, 0xDDA0, 0xD590, 0xCEB0, 0xC930, 0xC5C0, 0xC410, 0xC560, 0xC890, 0xCEA0, 0xD6B0, 0xDF00, + 0xE7B0, 0xF060, 0xF7E0, 0xFFC0, 0x06C0, 0x0D00, 0x12E0, 0x1700, 0x1BB0, 0x1F30, 0x2280, 0x2560, 0x2780, 0x2AB0, 0x2D00, 0x2EB0, + 0x3060, 0x3180, 0x3290, 0x33B0, 0x3460, 0x3480, 0x33F0, 0x33B0, 0x3360, 0x3260, 0x3130, 0x2EF0, 0x22F0, 0x1FF0, 0x1D60, 0x1B10, + 0x1A30, 0x1970, 0x18C0, 0x1980, 0x1AF0, 0x1C30, 0x1F50, 0x22B0, 0x2670, 0x2A70, 0x2E10, 0x31B0, 0x34A0, 0x3790, 0x3950, 0x3AA0, + 0x3B60, 0x3A50, 0x39D0, 0x3770, 0x34A0, 0x31C0, 0x2D40, 0x28C0, 0x2390, 0x1F90, 0x1CA0, 0x1A00, 0x18F0, 0x19B0, 0x1B70, 0x1EE0, + 0x2150, 0x2200, 0x1F00, 0x17C0, 0x0DA0, 0xFF00, 0xED40, 0xD9F0, 0xC400, 0xACB0, 0x9250, 0x8640, 0x84E0, 0x84B0, 0x8490, 0x8480, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8460, 0x84B0, 0x8500, 0x8590, 0x8E30, 0xA810, 0xB9E0, 0xBF20, 0xB600, 0x9BF0, + 0x8590, 0x8490, 0x8460, 0x8440, 0x8410, 0x8400, 0x83F0, 0x83E0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8420, 0x8430, 0x8410, 0x8430, 0x8440, 0x8440, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8470, 0x8450, 0x8440, 0x8440, 0x8470, 0x8440, 0x8440, + 0x8440, 0x8460, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, + 0x8480, 0x8480, 0x8490, 0x84B0, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84D0, 0x84F0, 0x8510, 0x8580, 0x86C0, 0x8AE0, 0x94E0, 0x9FD0, + 0xAA20, 0xB3F0, 0xBE10, 0xCA30, 0xD7E0, 0xE770, 0xF9E0, 0x0AB0, 0x1B50, 0x29D0, 0x3630, 0x4100, 0x4990, 0x5250, 0x5A30, 0x61D0, + 0x6950, 0x7000, 0x76E0, 0x7C40, 0x7ED0, 0x7F20, 0x7EC0, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7EB0, 0x7F10, 0x7F00, 0x7EF0, 0x7F10, + 0x7F20, 0x7F10, 0x7F20, 0x7F40, 0x7E50, 0x76B0, 0x6D20, 0x6150, 0x5210, 0x41B0, 0x2E60, 0x1CB0, 0x0BB0, 0xFD10, 0xF1E0, 0xE980, + 0xE450, 0xE100, 0xDF10, 0xDE00, 0xDD30, 0xDBE0, 0xDB00, 0xD970, 0xD900, 0xD860, 0xD940, 0xD980, 0xDA10, 0xDB20, 0xDBB0, 0xDC90, + 0xDDA0, 0xDE40, 0xDFA0, 0xE0F0, 0xE2C0, 0xE580, 0xE830, 0xEC20, 0xF0D0, 0xF630, 0xFCB0, 0x0380, 0x0AC0, 0x11B0, 0x1870, 0x1DE0, + 0x21C0, 0x2480, 0x2640, 0x2680, 0x2730, 0x2710, 0x26E0, 0x2640, 0x2510, 0x2460, 0x22F0, 0x21D0, 0x2110, 0x1FE0, 0x1F00, 0x1E50, + 0x1CE0, 0x1B60, 0x1950, 0x1870, 0x1660, 0x1420, 0x11F0, 0x0E90, 0x0B00, 0x05E0, 0x0030, 0xF9D0, 0xF270, 0xEB90, 0xE4F0, 0xDF30, + 0xDBD0, 0xD8C0, 0xD7A0, 0xD740, 0xD7B0, 0xD870, 0xD920, 0xD890, 0xD5B0, 0xD090, 0xCA40, 0xC110, 0xB890, 0xAF50, 0xA770, 0xA110, + 0x9D80, 0x9C80, 0x9DC0, 0xA1D0, 0xA900, 0xAE70, 0xB320, 0xB610, 0xB760, 0xB790, 0xB7B0, 0xB7F0, 0xB930, 0xBBF0, 0xC020, 0xC620, + 0xCDF0, 0xD6B0, 0xE070, 0xEA50, 0xF5B0, 0xFFD0, 0x0A60, 0x1560, 0x2040, 0x2B50, 0x36B0, 0x41C0, 0x4C40, 0x5730, 0x6000, 0x68C0, + 0x7110, 0x78A0, 0x7E60, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, + 0x7F20, 0x7F40, 0x7F30, 0x7F50, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, + 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, + 0x7F30, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, + 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, + 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F00, 0x7F10, 0x7F20, 0x7F20, 0x7F30, 0x7F10, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7EF0, + 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F00, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F00, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, + 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F40, 0x7F30, + 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, + 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F70, 0x7F10, 0x7EE0, 0x7F20, 0x7F20, 0x7F30, 0x7F40, + 0x7EC0, 0x7F10, 0x7EF0, 0x7EF0, 0x7EE0, 0x7E50, 0x7ED0, 0x7F00, 0x7EF0, 0x7F10, 0x7EA0, 0x7EC0, 0x7F10, 0x7F10, 0x7F10, 0x7EA0, + 0x7F40, 0x7EE0, 0x7EF0, 0x7F30, 0x7EA0, 0x7F40, 0x7F00, 0x7290, 0x6410, 0x55E0, 0x46C0, 0x3A30, 0x2EE0, 0x2660, 0x1ED0, 0x1910, + 0x14C0, 0x10C0, 0x0CD0, 0x0700, 0xFFC0, 0xF6B0, 0xEB30, 0xDDC0, 0xCDC0, 0xBCD0, 0xAA30, 0x97C0, 0x8980, 0x8590, 0x8500, 0x84D0, + 0x84C0, 0x84B0, 0x84A0, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, + 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8480, 0x8450, 0x8460, 0x8460, + 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, + 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84D0, 0x84D0, 0x84E0, 0x84F0, 0x8510, 0x8530, 0x8580, 0x8640, 0x8850, 0x8D00, 0x9690, 0xA180, + 0xAC50, 0xB890, 0xC530, 0xD200, 0xDF00, 0xEA90, 0xF5C0, 0x0010, 0x0B10, 0x1540, 0x1DE0, 0x25F0, 0x2BD0, 0x30C0, 0x3340, 0x3480, + 0x3330, 0x2DE0, 0x2650, 0x1A50, 0x0990, 0xF460, 0xD9B0, 0xBF60, 0xA520, 0x8DF0, 0x8600, 0x8500, 0x8480, 0x84B0, 0x8490, 0x8490, + 0x8480, 0x8470, 0x8470, 0x84B0, 0x8460, 0x8450, 0x8450, 0x8490, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8430, + 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8470, 0x8450, 0x8450, + 0x8460, 0x8470, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8480, 0x8490, 0x84A0, 0x84C0, 0x8500, 0x8550, 0x86F0, 0x9110, + 0xA350, 0xEC50, 0xFD60, 0x0F90, 0x2130, 0x3370, 0x4520, 0x55F0, 0x6530, 0x71F0, 0x7AE0, 0x7ED0, 0x7ED0, 0x7EB0, 0x7EE0, 0x7EF0, + 0x5FF0, 0x57F0, 0x5240, 0x4D90, 0x4B10, 0x4A00, 0x4A20, 0x4C90, 0x4FA0, 0x53F0, 0x5A00, 0x6030, 0x6720, 0x6DC0, 0x72B0, 0x77A0, + 0x7AD0, 0x7D90, 0x7EB0, 0x7EF0, 0x7F10, 0x7EC0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7F00, + 0x7F30, 0x7F00, 0x7F20, 0x7EF0, 0x7F10, 0x7F80, 0x7F00, 0x7F10, 0x7F20, 0x7F00, 0x7F90, 0x7F10, 0x7F00, 0x7EE0, 0x7EF0, 0x7F70, + 0x7F20, 0x7EC0, 0x7E60, 0x7E20, 0x7DF0, 0x7E10, 0x7E30, 0x7EA0, 0x7EC0, 0x7EF0, 0x7F00, 0x7EA0, 0x7ED0, 0x7EE0, 0x7F20, 0x7F20, + 0x7E90, 0x7EB0, 0x7F00, 0x7F10, 0x7F00, 0x7EA0, 0x7ED0, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F00, + 0x7F20, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, 0x7F50, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7EF0, 0x7EF0, 0x7EF0, 0x7F00, 0x7F40, + 0x7EF0, 0x7F10, 0x7F00, 0x7F00, 0x7F70, 0x7ED0, 0x7EA0, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7EC0, 0x7F10, 0x7F20, 0x7F40, 0x7F00, + 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7E90, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F00, + 0x7F40, 0x7ED0, 0x7F00, 0x7F20, 0x7EF0, 0x7F70, 0x7F00, 0x7F40, 0x7EF0, 0x7EF0, 0x7F70, 0x7F00, 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, + 0x7EF0, 0x7EF0, 0x7F00, 0x7EE0, 0x7F70, 0x7F00, 0x7ED0, 0x7ED0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7EB0, 0x7EC0, 0x7EC0, 0x7F30, 0x7F20, + 0x7EA0, 0x7EC0, 0x7ED0, 0x7F10, 0x7F00, 0x7EC0, 0x7EB0, 0x7F00, 0x7EF0, 0x7EF0, 0x7EB0, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F00, + 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7EF0, 0x7F60, 0x7F20, 0x7F40, 0x7F10, 0x7F20, 0x7F60, 0x7EF0, 0x7F10, 0x7EF0, 0x7EE0, 0x7F80, + 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F80, 0x7F10, 0x7690, 0x68E0, 0x5940, 0x48B0, 0x3710, 0x25A0, 0x1540, 0x04D0, 0xF490, 0xE3F0, + 0xD1A0, 0xBD30, 0xA6F0, 0x8F00, 0x8610, 0x84F0, 0x84C0, 0x84B0, 0x8490, 0x8490, 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, + 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84C0, + 0x84E0, 0x8500, 0x8560, 0x8660, 0x8960, 0x91B0, 0x9C00, 0xA5D0, 0xAF90, 0xB830, 0xBFE0, 0xC5D0, 0xCAF0, 0xCE90, 0xD0E0, 0xD310, + 0xD3E0, 0xD560, 0xD600, 0xD690, 0xD750, 0xD6F0, 0xD630, 0xD440, 0xD240, 0xCFB0, 0xCD20, 0xCA60, 0xC7C0, 0xC5D0, 0xC420, 0xC2D0, + 0xC100, 0xBF10, 0xBDC0, 0xBC00, 0xB9F0, 0xB760, 0xB450, 0xB080, 0xAC20, 0xA7A0, 0xA290, 0x9E60, 0x9830, 0x9330, 0x8E10, 0x8A40, + 0x8790, 0x8630, 0x8580, 0x8540, 0x8510, 0x8500, 0x84F0, 0x84E0, 0x84E0, 0x84E0, 0x84D0, 0x84D0, 0x84D0, 0x84E0, 0x84E0, 0x84F0, + 0x84F0, 0x8500, 0x8520, 0x8530, 0x8570, 0x85B0, 0x8620, 0x86E0, 0x8800, 0x89C0, 0x8C70, 0x8F80, 0x9230, 0x9640, 0x9A20, 0x9DF0, + 0xA1F0, 0xA490, 0xA790, 0xAA10, 0xAD60, 0xB010, 0xB490, 0xB870, 0xBC30, 0xBF80, 0xC200, 0xC3D0, 0xC610, 0xC870, 0xCB00, 0xCE90, + 0xD160, 0xD4A0, 0xD6C0, 0xD910, 0xDB70, 0xDE80, 0xE1F0, 0xE530, 0xE830, 0xEB20, 0xEE10, 0xF010, 0xF2C0, 0xF560, 0xF880, 0xFAF0, + 0xFED0, 0x02C0, 0x05D0, 0x0920, 0x0C60, 0x0F50, 0x1240, 0x15B0, 0x1920, 0x1CA0, 0x1FD0, 0x22F0, 0x2640, 0x2990, 0x2CB0, 0x3030, + 0x3320, 0x3660, 0x3950, 0x3BB0, 0x3E40, 0x40B0, 0x4260, 0x4400, 0x4640, 0x4850, 0x49D0, 0x4A60, 0x49D0, 0x48F0, 0x47B0, 0x46E0, + 0x4590, 0x44B0, 0x43B0, 0x4300, 0x42E0, 0x4200, 0x40C0, 0x3F10, 0x3DF0, 0x3C90, 0x3B70, 0x3A40, 0x3970, 0x38B0, 0x3880, 0x3800, + 0x37F0, 0x3770, 0x3760, 0x3770, 0x3810, 0x3910, 0x39E0, 0x3A90, 0x3BB0, 0x3D20, 0x3EA0, 0x4040, 0x41F0, 0x42D0, 0x4400, 0x4540, + 0x4610, 0x46B0, 0x4830, 0x49E0, 0x4B10, 0x4CC0, 0x4E00, 0x4FA0, 0x50E0, 0x5210, 0x5370, 0x54A0, 0x5540, 0x55C0, 0x5610, 0x56A0, + 0x5740, 0x58F0, 0x5A90, 0x5C40, 0x5DF0, 0x5F70, 0x6110, 0x6320, 0x66E0, 0x6BD0, 0x7170, 0x7780, 0x7D10, 0x7F10, 0x7F30, 0x7EE0, + 0x7EE0, 0x7EF0, 0x7F10, 0x7F40, 0x7DF0, 0x7780, 0x6EE0, 0x62E0, 0x52D0, 0x3EB0, 0x23E0, 0x0270, 0xDAD0, 0xA990, 0x8740, 0x84C0, + 0x8490, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, + 0x8440, 0x8440, 0x8450, 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8470, 0x8490, 0x8480, 0x8480, 0x8480, 0x8490, + 0x8480, 0x8470, 0x8480, 0x8480, 0x8470, 0x8470, 0x8470, 0x8490, 0x8460, 0x8450, 0x8470, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, + 0x8430, 0x8430, 0x8440, 0x8430, 0x8440, 0x8430, 0x8440, 0x8450, 0x8450, 0x8450, 0x8460, 0x8470, 0x8470, 0x84A0, 0x84C0, 0x8510, + 0x8690, 0x9230, 0xA460, 0xB260, 0xBDD0, 0xC7E0, 0xCF80, 0xD6B0, 0xDC90, 0xE320, 0xE8E0, 0xEE00, 0xF290, 0xF5F0, 0xF950, 0xFBC0, + 0xFD90, 0xFF10, 0x00B0, 0x0260, 0x0420, 0x05D0, 0x08B0, 0x0B90, 0x0DF0, 0x1150, 0x1490, 0x18F0, 0x1D60, 0x21F0, 0x2770, 0x2CE0, + 0x32D0, 0x38B0, 0x3F60, 0x4660, 0x4D50, 0x5590, 0x5CF0, 0x6460, 0x6C50, 0x73E0, 0x7AC0, 0x7E80, 0x7F10, 0x7F20, 0x7EC0, 0x7ED0, + 0x7F10, 0x7F00, 0x7F10, 0x7EB0, 0x7EE0, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7F00, + 0x7F10, 0x7F10, 0x7F20, 0x7F60, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F50, 0x7EF0, 0x7F00, 0x7EE0, 0x7EF0, 0x7F30, 0x7EE0, 0x7F10, + 0x7F10, 0x7F20, 0x7F70, 0x7EF0, 0x7EB0, 0x7F00, 0x7F10, 0x7F50, 0x7EB0, 0x7E70, 0x7EF0, 0x7EF0, 0x7F30, 0x7F00, 0x7EC0, 0x7F00, + 0x7F00, 0x7EF0, 0x7EF0, 0x7EA0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7F40, 0x7F00, 0x7F30, 0x7EF0, + 0x7F20, 0x7F10, 0x7F00, 0x7F40, 0x7EA0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F10, + 0x7F10, 0x7F20, 0x7F40, 0x7EF0, 0x7F80, 0x7DA0, 0x75E0, 0x6FA0, 0x6A20, 0x65E0, 0x6350, 0x6270, 0x6430, 0x67C0, 0x6CC0, 0x7330, + 0x7920, 0x7DF0, 0x7EF0, 0x7F70, 0x7F20, 0x7ED0, 0x7ED0, 0x7EB0, 0x7F20, 0x7F10, 0x7EB0, 0x7EC0, 0x7ED0, 0x7F30, 0x7F20, 0x7EA0, + 0x7DD0, 0x7C50, 0x7A50, 0x79B0, 0x78B0, 0x78C0, 0x7890, 0x77D0, 0x7760, 0x7580, 0x7380, 0x7050, 0x6B10, 0x6500, 0x5C00, 0x5140, + 0x4400, 0x3400, 0x2390, 0x1110, 0xFDF0, 0xEB90, 0xDB90, 0xCF00, 0xC710, 0xC540, 0xCA70, 0xD670, 0xE840, 0xFE90, 0x1530, 0x2B60, + 0x4090, 0x5310, 0x6250, 0x6E60, 0x76C0, 0x7B10, 0x7D60, 0x7D50, 0x7BB0, 0x78B0, 0x75F0, 0x75F0, 0x7810, 0x7C30, 0x7EE0, 0x7EF0, + 0x7ED0, 0x7EB0, 0x7F40, 0x7EF0, 0x7EB0, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EB0, 0x7ED0, 0x72F0, 0x3E90, 0x0520, 0xC380, 0x87B0, + 0x84A0, 0x8470, 0x8440, 0x8440, 0x8430, 0x8430, 0x8450, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8410, + 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8440, 0x8420, 0x8430, 0x8430, + 0x8430, 0x8440, 0x8440, 0x8450, 0x8450, 0x8440, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, + 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84B0, 0x84C0, 0x84E0, 0x8500, 0x8540, 0x85E0, 0x8720, 0x8890, 0x8980, + 0x8930, 0x8800, 0x8730, 0x86D0, 0x8700, 0x87B0, 0x8A30, 0x8F70, 0x9810, 0xA0F0, 0xAA90, 0xB270, 0xB900, 0xBFA0, 0xC600, 0xCBC0, + 0xD250, 0xD9D0, 0xE1A0, 0xEA50, 0xF300, 0xFC20, 0x0540, 0x0F70, 0x1BE0, 0x2900, 0x3750, 0x4550, 0x5250, 0x5DD0, 0x65B0, 0x6C20, + 0x7080, 0x7210, 0x7310, 0x7180, 0x6E80, 0x6A00, 0x63E0, 0x5EA0, 0x5800, 0x51B0, 0x4C20, 0x45C0, 0x40D0, 0x3B90, 0x3690, 0x32B0, + 0x2FA0, 0x2E90, 0x2E50, 0x3030, 0x32F0, 0x3740, 0x3E10, 0x4730, 0x5270, 0x5EC0, 0x6B80, 0x77B0, 0x7EE0, 0x7F80, 0x7EF0, 0x7EB0, + 0x7F10, 0x7F10, 0x7F70, 0x7EE0, 0x7EC0, 0x7EF0, 0x7F10, 0x7F30, 0x7EE0, 0x7EB0, 0x7F00, 0x7F40, 0x7F40, 0x7ED0, 0x7EA0, 0x7EE0, + 0x7EF0, 0x7F10, 0x7EE0, 0x7E90, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7EE0, 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7EF0, + 0x7F30, 0x7F20, 0x7F10, 0x7F90, 0x7B20, 0x6EC0, 0x6390, 0x57F0, 0x4C20, 0x3F10, 0x35D0, 0x2E20, 0x2780, 0x2290, 0x1EB0, 0x1C00, + 0x1A50, 0x1AF0, 0x1D20, 0x2080, 0x25B0, 0x2A90, 0x2FE0, 0x3540, 0x3A70, 0x3F90, 0x4430, 0x48A0, 0x4CF0, 0x5210, 0x56E0, 0x5BF0, + 0x60D0, 0x65A0, 0x6AE0, 0x6F90, 0x73B0, 0x7750, 0x7A50, 0x7C30, 0x7D30, 0x7DA0, 0x7D00, 0x7B50, 0x7890, 0x7400, 0x6E40, 0x6620, + 0x5D80, 0x5290, 0x4530, 0x3680, 0x25E0, 0x1370, 0xFEE0, 0xE860, 0xCE90, 0xB510, 0x9A50, 0x87E0, 0x8500, 0x84C0, 0x84A0, 0x8490, + 0x84B0, 0x8470, 0x8470, 0x8440, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8480, + 0x84A0, 0x84F0, 0x8540, 0x9180, 0xB7B0, 0xD9F0, 0xF900, 0x13C0, 0x2B90, 0x41D0, 0x54E0, 0x63F0, 0x6FB0, 0x76A0, 0x7A80, 0x7BF0, + 0x7B30, 0x7820, 0x72C0, 0x6A10, 0x5ED0, 0x5070, 0x4180, 0x3310, 0x24F0, 0x1680, 0x06C0, 0xF2A0, 0xDAD0, 0xBF60, 0x9F10, 0x8880, + 0x8500, 0x84C0, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84B0, 0x84C0, 0x84E0, 0x8540, 0x8740, + 0x9930, 0xAE50, 0xC1F0, 0xD1C0, 0xDD50, 0xE4C0, 0xE930, 0xEC20, 0xF070, 0xF790, 0x01B0, 0x0EF0, 0x1EA0, 0x3030, 0x41B0, 0x5270, + 0x6150, 0x6E70, 0x7A60, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, + 0x7F30, 0x7F20, 0x7F00, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F00, 0x7390, 0x6770, 0x5B60, + 0x4E60, 0x4150, 0x3460, 0x2740, 0x1A80, 0x0F50, 0x0550, 0xFCA0, 0xF520, 0xECB0, 0xE270, 0xD570, 0xC6A0, 0xB690, 0xA5D0, 0x95D0, + 0x8AF0, 0x86C0, 0x8580, 0x8530, 0x8500, 0x84F0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84F0, 0x8500, 0x8510, 0x8520, 0x8530, 0x8540, + 0x8550, 0x8540, 0x8560, 0x8570, 0x8580, 0x85A0, 0x85B0, 0x85D0, 0x85C0, 0x85B0, 0x85C0, 0x85A0, 0x8590, 0x8580, 0x8570, 0x8560, + 0x8550, 0x8540, 0x8550, 0x8560, 0x8580, 0x85A0, 0x85F0, 0x8670, 0x8700, 0x87B0, 0x8890, 0x8970, 0x8A70, 0x8AF0, 0x8BB0, 0x8CB0, + 0x8DD0, 0x8F70, 0x9100, 0x9280, 0x93F0, 0x94F0, 0x9580, 0x9510, 0x9400, 0x9290, 0x90F0, 0x8F90, 0x8DE0, 0x8BC0, 0x89A0, 0x87C0, + 0x8650, 0x8580, 0x8530, 0x8500, 0x84F0, 0x84E0, 0x84D0, 0x84E0, 0x84E0, 0x84E0, 0x84F0, 0x8500, 0x8500, 0x8510, 0x8510, 0x8510, + 0x8520, 0x8530, 0x8540, 0x8540, 0x8530, 0x8520, 0x84F0, 0x84E0, 0x84C0, 0x84A0, 0x8490, 0x8470, 0x8470, 0x8460, 0x8450, 0x8450, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8450, 0x8450, 0x8440, 0x8430, 0x8450, 0x8430, + 0x8420, 0x8410, 0x8410, 0x8410, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, + 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8430, 0x8450, 0x8450, 0x8460, 0x8470, 0x8490, + 0x84B0, 0x84D0, 0x84F0, 0x8500, 0x84F0, 0x84D0, 0x84C0, 0x8480, 0x84B0, 0x84B0, 0x84C0, 0x84D0, 0x8510, 0x8520, 0x8590, 0x8660, + 0x87B0, 0x8890, 0x87D0, 0x8600, 0x8500, 0x84C0, 0x8490, 0x8470, 0x8460, 0x8450, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, 0x8420, + 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, 0x8410, + 0x8430, 0x8440, 0x8450, 0x8460, 0x8470, 0x8470, 0x84D0, 0x84F0, 0x8510, 0x8550, 0x85E0, 0x8700, 0x8960, 0x8E10, 0x9390, 0x9890, + 0x9C00, 0x9F40, 0xA210, 0xA4E0, 0xA810, 0xAC50, 0xB170, 0xB650, 0xBB00, 0xBEF0, 0xC1F0, 0xC4E0, 0xC6C0, 0xC800, 0xCA90, 0xCD20, + 0xCFF0, 0xD290, 0xD510, 0xD760, 0xD910, 0xD9F0, 0xDBA0, 0xDDD0, 0xDFB0, 0xE210, 0xE420, 0xE650, 0xE890, 0xEB20, 0xEDA0, 0xEFC0, + 0xF2F0, 0xF500, 0xF6C0, 0xF910, 0xFB80, 0xFEB0, 0x0240, 0x06F0, 0x0BE0, 0x1120, 0x1750, 0x1D90, 0x23F0, 0x2B60, 0x33C0, 0x3DD0, + 0x4800, 0x5270, 0x5D90, 0x67A0, 0x7160, 0x7940, 0x7E50, 0x7F20, 0x7EC0, 0x7ED0, 0x7EE0, 0x7F20, 0x7F10, 0x7E90, 0x7E80, 0x7F00, + 0x7EF0, 0x7F00, 0x7E90, 0x7F00, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7EE0, 0x7F40, 0x7EF0, 0x7F30, + 0x7F20, 0x7F00, 0x7F50, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7EF0, 0x7F10, 0x7A20, 0x5900, 0x3D50, 0x2480, 0x0F80, + 0xFC00, 0xE7C0, 0xD150, 0xB790, 0x9BC0, 0x8730, 0x84F0, 0x84C0, 0x84A0, 0x8490, 0x8440, 0x8480, 0x8470, 0x8470, 0x8470, 0x8450, + 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8490, 0x84B0, 0x84D0, 0x84F0, 0x8540, 0x86D0, 0x8F70, 0x9FC0, + 0xAE40, 0xB990, 0xC400, 0xCD60, 0xD6C0, 0xE010, 0xE8F0, 0xF190, 0xFA20, 0x0170, 0x08B0, 0x0E70, 0x1330, 0x1750, 0x1B60, 0x1FA0, + 0x2440, 0x2870, 0x2E10, 0x3270, 0x3730, 0x3B60, 0x3F50, 0x43D0, 0x4830, 0x4D80, 0x5290, 0x57F0, 0x5CC0, 0x60C0, 0x7000, 0x7290, + 0x74F0, 0x76C0, 0x7810, 0x7A20, 0x7B60, 0x7C70, 0x7CE0, 0x7D40, 0x7DD0, 0x7E30, 0x7EB0, 0x7EC0, 0x7EB0, 0x7F10, 0x7EF0, 0x7F30, + 0x7ED0, 0x7EB0, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7EA0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F30, + 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7F80, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F90, 0x7F20, 0x7F00, 0x7EF0, 0x7EF0, + 0x7F30, 0x7F10, 0x7EF0, 0x7EE0, 0x7EE0, 0x7F50, 0x7F10, 0x7EA0, 0x7EE0, 0x7ED0, 0x7F60, 0x7F20, 0x7E90, 0x7EB0, 0x7EB0, 0x7F00, + 0x7EF0, 0x7EA0, 0x7F00, 0x7ED0, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, + 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F30, 0x7EF0, 0x7F10, 0x7F10, 0x7F10, 0x7F60, 0x7F00, 0x7F10, 0x7F20, 0x7F10, + 0x7F50, 0x7EF0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F70, 0x7F00, 0x7ED0, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F00, 0x7EF0, 0x7ED0, 0x7EE0, + 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F40, 0x7F40, 0x7F10, + 0x7F10, 0x7F10, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, + 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, + 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F20, 0x7F40, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F20, + 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7520, 0x6750, 0x5980, 0x4A20, + 0x3CF0, 0x2FB0, 0x23A0, 0x1860, 0x0D50, 0x02F0, 0xF9E0, 0xF2D0, 0xECE0, 0xEA10, 0xEA10, 0xEC30, 0xF0A0, 0xF680, 0xFCC0, 0x02E0, + 0x0810, 0x0E20, 0x1370, 0x1990, 0x20A0, 0x2940, 0x3460, 0x4090, 0x4D30, 0x5970, 0x6460, 0x6D10, 0x7490, 0x7A60, 0x7EA0, 0x7F10, + 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, + 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7CA0, 0x73D0, 0x6B80, 0x6330, 0x5B20, 0x5350, 0x4B60, 0x4450, + 0x3D50, 0x3650, 0x2F20, 0x2790, 0x1FB0, 0x17E0, 0x0FC0, 0x07A0, 0xFF90, 0xF830, 0xEFC0, 0xE710, 0xDE30, 0xD550, 0xCBB0, 0xC2A0, + 0xB890, 0xAED0, 0xA4D0, 0x9B00, 0x9130, 0x8A70, 0x8710, 0x85C0, 0x8540, 0x8500, 0x84F0, 0x84E0, 0x84D0, 0x84D0, 0x84D0, 0x84C0, + 0x84C0, 0x84C0, 0x84D0, 0x84D0, 0x84E0, 0x84F0, 0x8500, 0x8530, 0x85B0, 0x86F0, 0x8A80, 0x94C0, 0x9F00, 0xA8F0, 0xB180, 0xB8A0, + 0xBF30, 0xC490, 0xCA10, 0xCF20, 0xD3F0, 0xD830, 0xDC30, 0xE060, 0xE340, 0xE5F0, 0xE700, 0xE5A0, 0xE240, 0xDAA0, 0xCFA0, 0xC1C0, + 0xB070, 0x9C90, 0x8B00, 0x85A0, 0x84F0, 0x84D0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84C0, 0x84D0, 0x84E0, + 0x8500, 0x8540, 0x85F0, 0x8900, 0x96D0, 0xA910, 0xBA80, 0xCA10, 0xD5A0, 0xD980, 0xD4F0, 0xC820, 0xB3D0, 0x9B00, 0x8820, 0x8500, + 0x84C0, 0x8490, 0x8480, 0x8460, 0x8450, 0x8440, 0x8430, 0x8430, 0x8420, 0x8410, 0x8420, 0x8410, 0x8400, 0x8410, 0x8410, 0x8410, + 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83C0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83B0, 0x83F0, 0x83E0, 0x83E0, 0x83F0, + 0x83C0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8420, 0x8410, + 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8430, 0x8400, 0x8410, 0x8400, 0x83F0, 0x83F0, 0x83E0, + 0x8410, 0x83E0, 0x83E0, 0x83D0, 0x83F0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83E0, + 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, + 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8480, 0x8450, 0x8460, 0x8430, 0x8470, 0x8460, 0x8490, 0x84A0, 0x84C0, + 0x84E0, 0x8520, 0x8580, 0x86B0, 0x8950, 0x8DB0, 0x9260, 0x9740, 0xAE30, 0xB190, 0xB570, 0xBAD0, 0xC2C0, 0xCC80, 0xD6D0, 0xE0D0, + 0xE840, 0xEDD0, 0xF0A0, 0xF210, 0xF450, 0xF850, 0xFFD0, 0x0A30, 0x17A0, 0x2820, 0x38E0, 0x48F0, 0x55E0, 0x5EA0, 0x6480, 0x6730, + 0x6820, 0x6750, 0x66D0, 0x67B0, 0x69E0, 0x6E60, 0x74F0, 0x7C20, 0x7EF0, 0x7EF0, 0x7F70, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, + 0x7EE0, 0x7EC0, 0x7EF0, 0x7F10, 0x7F30, 0x7F00, 0x7EC0, 0x7F10, 0x7F00, 0x7F00, 0x7F10, 0x7E90, 0x7F10, 0x7EE0, 0x7EF0, 0x7F10, + 0x7F00, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F50, 0x7EF0, 0x7F20, 0x7EF0, 0x7EF0, 0x7F90, 0x7EE0, 0x7F10, 0x7F30, 0x7F00, + 0x7F80, 0x7F10, 0x7F10, 0x7EE0, 0x7EE0, 0x7F70, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F00, 0x7F60, 0x7F10, 0x7E90, 0x7EB0, 0x7EF0, 0x7F30, + 0x7EE0, 0x7EC0, 0x7ED0, 0x7EE0, 0x7F00, 0x7F10, 0x7E90, 0x7EE0, 0x7F00, 0x7F10, 0x7F10, 0x7E90, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, + 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F30, 0x7EF0, 0x7F10, 0x7F10, 0x7EF0, 0x7F40, 0x7EF0, 0x7F30, 0x7F20, 0x7F00, + 0x7F50, 0x7EF0, 0x7F40, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7EF0, 0x7F10, 0x7F20, 0x7F70, 0x7F00, 0x7EE0, 0x7F00, 0x7F10, 0x7F30, + 0x7EE0, 0x7E70, 0x7EF0, 0x7F10, 0x7F30, 0x7ED0, 0x7EB0, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7EA0, 0x7F20, 0x7F10, 0x7F00, 0x7F00, + 0x7EC0, 0x7F30, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7F80, 0x7F10, 0x7F20, 0x7F00, 0x7F20, + 0x7F80, 0x7F10, 0x7F10, 0x7EF0, 0x7EE0, 0x7F80, 0x7F10, 0x7F00, 0x7EF0, 0x7EF0, 0x7F70, 0x7F20, 0x7EE0, 0x7ED0, 0x7EB0, 0x7F30, + 0x7EF0, 0x7EB0, 0x7EC0, 0x7EC0, 0x7EF0, 0x7F10, 0x7EA0, 0x7ED0, 0x7F10, 0x7F10, 0x7F00, 0x7E90, 0x7EB0, 0x7F00, 0x7EF0, 0x7EF0, + 0x7F00, 0x7F20, 0x7F40, 0x7F20, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F70, 0x7F10, 0x7F20, 0x7F20, 0x7F10, + 0x7F50, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F30, 0x7F00, 0x7EF0, 0x7F10, 0x7F10, 0x7F60, 0x7EF0, 0x7ED0, 0x7EF0, 0x7F10, 0x7F70, + 0x7EE0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F30, 0x7EE0, 0x7EC0, 0x7F10, 0x7F20, 0x7F40, 0x7EF0, 0x7E90, 0x7F00, 0x7EE0, 0x7EF0, 0x7F10, + 0x7EA0, 0x7EC0, 0x7ED0, 0x7F10, 0x7F00, 0x7E90, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7EC0, 0x7EF0, 0x7F20, 0x7F20, 0x7F20, 0x7F00, + 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F40, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, 0x7F60, 0x7F10, 0x7F40, 0x7F00, 0x7EE0, 0x7EF0, + 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7C50, 0x7A30, 0x78F0, 0x7900, 0x7AA0, 0x7CD0, 0x7EB0, 0x7F10, 0x7F20, + 0x7F40, 0x7F10, 0x7F10, 0x7EE0, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F00, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F10, 0x7F30, 0x7F30, + 0x7F40, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F40, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F50, 0x7F40, 0x7F30, 0x7F30, + 0x7F30, 0x7F40, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7DB0, 0x7B60, 0x7880, 0x7480, 0x7030, 0x6BE0, 0x6720, 0x6250, + 0x5D80, 0x57E0, 0x5290, 0x4D90, 0x4920, 0x4480, 0x4010, 0x3AD0, 0x3570, 0x2FE0, 0x2A00, 0x24B0, 0x1FF0, 0x1C40, 0x1950, 0x1710, + 0x15C0, 0x1520, 0x14C0, 0x1400, 0x1380, 0x1210, 0x1010, 0x1030, 0x1160, 0x14E0, 0x1A40, 0x2190, 0x2AF0, 0x34E0, 0x3F60, 0x49C0, + 0x5490, 0x5F30, 0x6900, 0x7200, 0x79C0, 0x7E90, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7A70, 0x6E20, + 0x6280, 0x5830, 0x5170, 0x4CA0, 0x48B0, 0x4370, 0x3BD0, 0x2F40, 0x1FB0, 0x0C30, 0xF600, 0xDF40, 0xC700, 0xAFE0, 0x9900, 0x88F0, + 0x8520, 0x84D0, 0x84D0, 0x8490, 0x8470, 0x8460, 0x8450, 0x8440, 0x8440, 0x8430, 0x8430, 0x8420, 0x8410, 0x8410, 0x8400, 0x8400, + 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, + 0x83E0, 0x83E0, 0x83E0, 0x83D0, 0x83F0, 0x83F0, 0x8420, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, + 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, + 0x83C0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x8350, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83A0, + 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, + 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x8410, 0x8400, 0x8410, 0x8410, 0x8420, 0x8430, 0x8440, + 0x8460, 0x8460, 0x8470, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8470, 0x8470, 0x8470, 0x8470, + 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84C0, 0x84E0, 0x8530, 0x86D0, 0x9220, 0xA740, 0xBC00, + 0xD030, 0xE410, 0xF4A0, 0x0250, 0x0C60, 0x1180, 0x13C0, 0x1240, 0x0E30, 0x0870, 0x01E0, 0xFB90, 0xF4D0, 0xEF00, 0xEB70, 0xEB80, + 0xEEA0, 0xF460, 0xFD10, 0x0650, 0x0F30, 0x17C0, 0x1F50, 0x2630, 0x2DF0, 0x3720, 0x42B0, 0x4FD0, 0x5EB0, 0x6E60, 0x7C10, 0x7F00, + 0x7F10, 0x7F30, 0x7EB0, 0x7E70, 0x7EF0, 0x7EF0, 0x7F30, 0x7F20, 0x7EB0, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7EA0, 0x7F10, 0x7EF0, + 0x7F20, 0x7F00, 0x7EC0, 0x7F30, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F70, 0x7EE0, 0x7F10, 0x7F20, 0x7F00, 0x7F70, 0x7EF0, 0x7F20, + 0x7F20, 0x7F00, 0x7F90, 0x7F20, 0x7F20, 0x7EF0, 0x7EF0, 0x7F60, 0x7EE0, 0x7ED0, 0x7EF0, 0x7F10, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, + 0x7EF0, 0x7F00, 0x7ED0, 0x7F30, 0x7F00, 0x7EC0, 0x7ED0, 0x7EE0, 0x7F20, 0x7F00, 0x7EB0, 0x7EB0, 0x7EE0, 0x7F10, 0x7F10, 0x7E90, + 0x7EE0, 0x7EF0, 0x7F10, 0x7EF0, 0x7E90, 0x7F00, 0x7F20, 0x7F00, 0x7F10, 0x7F00, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7EE0, 0x7F40, + 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F50, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F50, 0x7F00, + 0x7F00, 0x7F00, 0x7F10, 0x7F30, 0x7EE0, 0x7EA0, 0x7EF0, 0x7EE0, 0x7F50, 0x7ED0, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, + 0x7EF0, 0x7EF0, 0x7EF0, 0x7EF0, 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7EC0, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7F50, + 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F60, 0x7F00, 0x7F10, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7F20, 0x7EF0, 0x7EF0, 0x7F80, 0x7F20, + 0x7F00, 0x7EF0, 0x7ED0, 0x7F30, 0x7F10, 0x7EB0, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EA0, 0x7EC0, 0x7ED0, 0x7F50, 0x7F10, 0x7E90, + 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7EF0, 0x7F00, + 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F60, 0x7F10, 0x7F10, 0x7EF0, 0x7F10, 0x7F50, 0x7EF0, 0x7F20, 0x7EF0, 0x7EF0, 0x7F80, 0x7F00, + 0x7EE0, 0x7F00, 0x7F00, 0x7F90, 0x7EF0, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F30, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7E90, + 0x7F00, 0x7EF0, 0x7EF0, 0x7EB0, 0x7E70, 0x7EF0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7F20, + 0x7EF0, 0x7F10, 0x7F30, 0x7F20, 0x7F80, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F70, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F00, 0x7F90, 0x7F10, + 0x7F20, 0x7F10, 0x7EF0, 0x7F70, 0x7F00, 0x7EC0, 0x7ED0, 0x7EF0, 0x7F60, 0x7EF0, 0x7EB0, 0x7EE0, 0x7EE0, 0x7F10, 0x7F10, 0x7E90, + 0x7ED0, 0x7ED0, 0x7F10, 0x7F00, 0x7E90, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7EB0, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7EE0, 0x7F40, + 0x7F10, 0x7F30, 0x7EF0, 0x7F00, 0x7F30, 0x7F20, 0x7F00, 0x7550, 0x6A30, 0x5DF0, 0x5140, 0x4300, 0x35C0, 0x2880, 0x1AA0, 0x0CE0, + 0xFF10, 0xF1B0, 0xE390, 0xD540, 0xC680, 0xB900, 0xAB90, 0x9E60, 0x91D0, 0x8950, 0x8610, 0x8560, 0x84F0, 0x84D0, 0x84C0, 0x84B0, + 0x84A0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, + 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84B0, + 0x84C0, 0x84C0, 0x84D0, 0x84D0, 0x84E0, 0x84F0, 0x84F0, 0x84F0, 0x8500, 0x84F0, 0x8500, 0x8500, 0x84E0, 0x84D0, 0x84D0, 0x84D0, + 0x84E0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84A0, 0x84B0, 0x8490, 0x8480, 0x8480, 0x8470, 0x8470, 0x8440, 0x8460, 0x8450, 0x8450, + 0x8450, 0x8440, 0x8440, 0x8430, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, + 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, + 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83E0, 0x83E0, + 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, + 0x8410, 0x8420, 0x8420, 0x8460, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8460, 0x8460, 0x8470, 0x8480, 0x8490, 0x8490, + 0x84B0, 0x84C0, 0x84E0, 0x8530, 0x8680, 0x8FA0, 0xA270, 0xB450, 0xC540, 0xD480, 0xE140, 0xEC80, 0xF3C0, 0xF840, 0xF990, 0xF7B0, + 0xF350, 0xECE0, 0xE4B0, 0xDBB0, 0xD170, 0xC6D0, 0xBC80, 0xB2F0, 0xAAC0, 0xA380, 0x9C40, 0x9590, 0x8E80, 0x88D0, 0x85E0, 0x8500, + 0x84C0, 0x84A0, 0x8480, 0x8470, 0x8460, 0x8450, 0x8450, 0x8470, 0x8430, 0x8430, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, + 0x8480, 0x8490, 0x8490, 0x84B0, 0x84B0, 0x84D0, 0x84F0, 0x8540, 0x8600, 0x88C0, 0x9170, 0x9DF0, 0xA9F0, 0xB690, 0xC1E0, 0xCCB0, + 0xD770, 0xE130, 0xEB20, 0xF450, 0xFD10, 0x05C0, 0x0DE0, 0x15C0, 0x1DF0, 0x25F0, 0x2F20, 0x3780, 0x4050, 0x4960, 0x51E0, 0x5C10, + 0x6520, 0x6E80, 0x76D0, 0x7D70, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F30, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, + 0x7F60, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F50, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F50, 0x7F00, 0x7F00, 0x7F00, 0x7F10, 0x7F30, + 0x7EE0, 0x7E70, 0x7EF0, 0x7F10, 0x7F30, 0x7EC0, 0x7E90, 0x7F00, 0x7F00, 0x7F20, 0x7F10, 0x7EB0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, + 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7EC0, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F60, 0x7EE0, 0x7EF0, 0x7F20, 0x7EF0, + 0x7F80, 0x7F20, 0x7F20, 0x7F10, 0x7EF0, 0x7F70, 0x7EE0, 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, 0x7EF0, 0x7ED0, 0x7EE0, 0x7EE0, 0x7F30, + 0x7F00, 0x7EC0, 0x7ED0, 0x7ED0, 0x7F10, 0x7F00, 0x7E90, 0x7ED0, 0x7F10, 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, + 0x7EC0, 0x7F10, 0x7F00, 0x7F20, 0x7EF0, 0x7F00, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7F10, + 0x7F60, 0x7F00, 0x7F20, 0x7EF0, 0x7F10, 0x7F60, 0x7F00, 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, 0x7EF0, 0x7EB0, 0x7EF0, 0x7EF0, 0x7F70, + 0x7F00, 0x7EC0, 0x7EF0, 0x7F10, 0x7F20, 0x7EC0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7EA0, 0x7F00, 0x7EB0, 0x7EE0, 0x7EF0, + 0x7F30, 0x7EE0, 0x7EC0, 0x7ED0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F00, + 0x7F20, 0x7EF0, 0x7F80, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F80, 0x7F10, 0x7F10, 0x7EF0, 0x7EE0, 0x7F80, 0x7F10, 0x7F00, 0x7F20, + 0x7F00, 0x7F80, 0x7F10, 0x7EF0, 0x7EE0, 0x7EE0, 0x7F50, 0x7F10, 0x7F10, 0x7F00, 0x7F00, 0x7F50, 0x7F10, 0x7EA0, 0x7EC0, 0x7ED0, + 0x7F10, 0x7F10, 0x7E90, 0x7EB0, 0x7EF0, 0x7F10, 0x7F20, 0x7EC0, 0x7F00, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F20, + 0x7EF0, 0x7EF0, 0x7DB0, 0x7A40, 0x7640, 0x72F0, 0x6F00, 0x6B20, 0x6690, 0x6200, 0x5DB0, 0x5940, 0x53B0, 0x4EA0, 0x48F0, 0x4490, + 0x3F30, 0x3A60, 0x3540, 0x3050, 0x2C70, 0x27C0, 0x23F0, 0x2110, 0x1D70, 0x1B00, 0x1890, 0x15F0, 0x14A0, 0x1360, 0x12E0, 0x12C0, + 0x12B0, 0x13A0, 0x1460, 0x15E0, 0x1710, 0x18F0, 0x1BC0, 0x1E40, 0x2170, 0x2470, 0x2720, 0x2B50, 0x2EB0, 0x32B0, 0x3670, 0x3A00, + 0x3E00, 0x4080, 0x42D0, 0x4550, 0x46E0, 0x49A0, 0x4B10, 0x4D70, 0x4F10, 0x50C0, 0x5250, 0x5370, 0x5430, 0x54E0, 0x5490, 0x54B0, + 0x54A0, 0x5460, 0x5420, 0x5380, 0x53D0, 0x53B0, 0x53A0, 0x5420, 0x53C0, 0x5450, 0x54A0, 0x54E0, 0x54D0, 0x5430, 0x5340, 0x5180, + 0x4E90, 0x4C90, 0x4A00, 0x47C0, 0x4570, 0x42F0, 0x4120, 0x3D90, 0x39D0, 0x34C0, 0x2E80, 0x2810, 0x1FB0, 0x1580, 0x0A80, 0xFE70, + 0xF1A0, 0xE2E0, 0xD3C0, 0xC370, 0xB270, 0xA170, 0x8F60, 0x8720, 0x8530, 0x84E0, 0x84C0, 0x84B0, 0x84B0, 0x8490, 0x84A0, 0x84B0, + 0x84B0, 0x84D0, 0x84F0, 0x8530, 0x85D0, 0x8790, 0x8B90, 0x92C0, 0x9A70, 0xA1B0, 0xA810, 0xAE50, 0xB470, 0xB960, 0xBCF0, 0xBE10, + 0xBC90, 0xB7B0, 0xB090, 0xA6F0, 0x9BF0, 0x9090, 0x8900, 0x85F0, 0x8510, 0x84D0, 0x84B0, 0x8490, 0x8480, 0x8470, 0x8470, 0x8460, + 0x8460, 0x8460, 0x8450, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8480, + 0x8490, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84D0, 0x84B0, 0x84C0, 0x84D0, 0x84D0, 0x84E0, 0x84F0, 0x8510, 0x8530, 0x8560, 0x85B0, + 0x8620, 0x86D0, 0x87E0, 0x8940, 0x8B10, 0x8CE0, 0x8FB0, 0x9360, 0x9820, 0x9E20, 0xA5C0, 0xAEE0, 0xB8C0, 0xC450, 0xD140, 0xDF00, + 0xEFF0, 0xFFC0, 0x1050, 0x20B0, 0x3080, 0x3FA0, 0x4D90, 0x5AD0, 0x6630, 0x7100, 0x7A00, 0x7EB0, 0x7F60, 0x7EF0, 0x7F10, 0x7F10, + 0x7F20, 0x7F60, 0x7F10, 0x7F20, 0x7F10, 0x7F00, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F10, + 0x7EF0, 0x7F30, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x6050, 0x2690, 0xF290, 0xC6B0, 0xA370, 0x9090, 0x8AC0, 0x8C60, 0x9630, + 0xA670, 0xB800, 0xC930, 0xD780, 0xE2C0, 0xEA60, 0xEE50, 0xF130, 0xF4C0, 0xFAB0, 0x0310, 0x0EB0, 0x1B40, 0x27B0, 0x3060, 0x3580, + 0x3750, 0x3730, 0x3620, 0x3540, 0x3480, 0x33B0, 0x3380, 0x32E0, 0x3110, 0x2E10, 0x29E0, 0x25C0, 0x2110, 0x1D10, 0x1970, 0x1620, + 0x13D0, 0x1110, 0x0D70, 0x0A40, 0x06B0, 0x0250, 0xFE20, 0xFB00, 0xF7A0, 0xF4A0, 0xF140, 0xEE20, 0xEB50, 0xE7D0, 0xE4B0, 0xE240, + 0xE100, 0xE0B0, 0xE210, 0xE3A0, 0xE620, 0xE920, 0xEC20, 0xEFB0, 0xF230, 0xF470, 0xF6C0, 0xF840, 0xF960, 0xF9A0, 0xFA10, 0xF990, + 0xF830, 0xF670, 0xF350, 0xF0B0, 0xEDF0, 0xEC60, 0xEBF0, 0xEC80, 0xEEC0, 0xF2A0, 0xF6D0, 0xFB30, 0xFF00, 0x01C0, 0x02D0, 0x02A0, + 0x0140, 0xFF70, 0xFCF0, 0xFAF0, 0xF970, 0xF7D0, 0xF670, 0xF4E0, 0xF440, 0xF450, 0xF580, 0x0B90, 0x1820, 0x2810, 0x3A10, 0x4BA0, + 0x5BA0, 0x6800, 0x7050, 0x7520, 0x7780, 0x7910, 0x7B10, 0x7DA0, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, + 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, + 0x7F10, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7EF0, + 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F90, 0x7F30, 0x7EE0, 0x7F20, 0x7F10, 0x7F50, 0x7F20, 0x7EA0, 0x7F10, 0x7F10, 0x7F40, 0x7F00, + 0x7E90, 0x7E90, 0x7EE0, 0x7EF0, 0x7ED0, 0x7EA0, 0x7F00, 0x7F10, 0x7F30, 0x7F00, 0x7EC0, 0x7F10, 0x7F00, 0x7F00, 0x7F10, 0x7F00, + 0x7F20, 0x7EF0, 0x7F10, 0x7F00, 0x7F00, 0x7D40, 0x78B0, 0x71B0, 0x6970, 0x5E00, 0x51C0, 0x43D0, 0x34B0, 0x24B0, 0x1400, 0x02F0, + 0xF250, 0xE0A0, 0xCF60, 0xC000, 0xB2A0, 0xA7B0, 0xA100, 0x9EA0, 0xA130, 0xA970, 0xB700, 0xC950, 0xDD40, 0xF2A0, 0x06D0, 0x1970, + 0x2860, 0x34E0, 0x3DD0, 0x43E0, 0x4840, 0x4AA0, 0x4BD0, 0x4D20, 0x4DA0, 0x4F10, 0x5080, 0x5270, 0x5420, 0x5430, 0x5270, 0x4D00, + 0x4790, 0x43E0, 0x44C0, 0x4BC0, 0x53F0, 0x59F0, 0x5860, 0x4D40, 0x3950, 0x1EA0, 0x0100, 0xE270, 0xC550, 0xAA30, 0x9040, 0x8580, + 0x84D0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8440, 0x8430, 0x8410, 0x83F0, 0x83E0, 0x83C0, 0x83A0, + 0x8390, 0x8380, 0x8370, 0x8370, 0x8370, 0x8370, 0x8370, 0x8380, 0x8380, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x83A0, 0x83A0, + 0x83A0, 0x83A0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x8400, 0x83D0, 0x83D0, 0x83E0, + 0x83A0, 0x83E0, 0x83E0, 0x83F0, 0x8380, 0x8400, 0x8400, 0x8410, 0x8420, 0x8410, 0x8410, 0x8430, 0x8440, 0x8410, 0x8420, 0x8420, + 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x83F0, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8450, 0x8450, 0x8450, + 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8450, + 0x8450, 0x8450, 0x8470, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, + 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, + 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8430, 0x8480, 0x8480, 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, + 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8460, 0x8440, 0x8440, 0x8440, 0x8460, 0x8440, 0x8440, 0x8440, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8480, 0x8450, 0x8460, 0x8460, 0x8440, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, + 0x84A0, 0x84B0, 0x84E0, 0x8530, 0x8690, 0x9090, 0xA450, 0xB7A0, 0xCB60, 0xDE10, 0xF040, 0x0300, 0x14D0, 0x2700, 0x3860, 0x4B40, + 0x5C80, 0x6E40, 0x7BD0, 0x7F10, 0x7F10, 0x7EE0, 0x7F50, 0x7F10, 0x7F20, 0x7F20, 0x7EF0, 0x7F70, 0x7F00, 0x7F40, 0x7F10, 0x7F10, + 0x7F60, 0x7EE0, 0x7ED0, 0x7EE0, 0x7EF0, 0x7F80, 0x7F00, 0x7EE0, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F30, + 0x7EE0, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7E90, 0x7F10, 0x7EF0, 0x7EF0, 0x7F10, 0x7F00, 0x7F20, 0x7F00, 0x7F10, 0x7F20, + 0x7F00, 0x7F10, 0x7EF0, 0x7F00, 0x7F20, 0x7EF0, 0x7F80, 0x7EE0, 0x7F10, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7F10, 0x7EF0, 0x7EE0, + 0x7F70, 0x7EF0, 0x7EF0, 0x7EF0, 0x7F00, 0x7F70, 0x7F00, 0x7ED0, 0x7EB0, 0x7F00, 0x7F70, 0x7F10, 0x7EB0, 0x7EC0, 0x7EC0, 0x7EF0, + 0x7F20, 0x7EA0, 0x7ED0, 0x7EE0, 0x7F20, 0x7F10, 0x7E90, 0x7EF0, 0x7F00, 0x7EF0, 0x7EF0, 0x7E70, 0x7EE0, 0x7F10, 0x7F10, 0x7F20, + 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7F00, 0x7F20, 0x7EF0, 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F40, 0x7F10, 0x7F00, + 0x7F30, 0x7EE0, 0x7F10, 0x7F10, 0x7F00, 0x7F70, 0x7EF0, 0x7F10, 0x7F00, 0x7F10, 0x7F50, 0x7EB0, 0x7E70, 0x7EE0, 0x7EF0, 0x7F30, + 0x7EC0, 0x7EB0, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, 0x7E90, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7F40, + 0x7F00, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, 0x7F30, 0x7F20, 0x7F00, 0x7F60, 0x7F10, 0x7F10, 0x7F10, 0x7EE0, + 0x7F70, 0x7F10, 0x7F20, 0x7F20, 0x7EF0, 0x7F90, 0x7F20, 0x6280, 0x3EC0, 0x16D0, 0xEC60, 0xC040, 0x90E0, 0x8500, 0x84B0, 0x8480, + 0x8470, 0x8460, 0x8480, 0x8450, 0x8440, 0x8440, 0x8440, 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, + 0x8440, 0x8450, 0x8440, 0x8440, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, 0x8420, + 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8420, + 0x8430, 0x8430, 0x8430, 0x8440, 0x8450, 0x8450, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84D0, 0x84C0, + 0x84D0, 0x84D0, 0x84C0, 0x84B0, 0x84A0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8450, 0x8440, 0x8440, 0x8430, 0x8430, 0x8420, 0x8420, + 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, 0x8430, 0x8440, + 0x8440, 0x8450, 0x8450, 0x8460, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84A0, 0x84A0, + 0x84A0, 0x84A0, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84D0, 0x84E0, 0x84E0, 0x84F0, + 0x8500, 0x8510, 0x8530, 0x8560, 0x85A0, 0x8610, 0x86F0, 0x8840, 0x8A20, 0x8CC0, 0x8F90, 0x9270, 0x9540, 0x97A0, 0x9990, 0x9B10, + 0x9CD0, 0x9E40, 0x9F80, 0xA070, 0xA0D0, 0xA170, 0xA2F0, 0xA450, 0xA5E0, 0xA7E0, 0xA9C0, 0xABE0, 0xADE0, 0xB0B0, 0xB460, 0xB8D0, + 0xBD70, 0xC1F0, 0xC700, 0xCC80, 0xD1C0, 0xD760, 0xDD50, 0xE430, 0xEAA0, 0xF110, 0xF7A0, 0xFE00, 0x03F0, 0x0A30, 0x1150, 0x1820, + 0x1F10, 0x2530, 0x2AE0, 0x30C0, 0x3650, 0x3BB0, 0x4130, 0x4700, 0x4C50, 0x5240, 0x5740, 0x5B70, 0x6110, 0x65E0, 0x69D0, 0x6E50, + 0x7180, 0x7500, 0x77C0, 0x7970, 0x7B90, 0x7BE0, 0x7C80, 0x7CD0, 0x7C70, 0x7BF0, 0x7460, 0x7150, 0x6D90, 0x68B0, 0x6400, 0x5E10, + 0x5910, 0x5320, 0x4BF0, 0x4550, 0x3DB0, 0x3680, 0x2EE0, 0x2640, 0x1ED0, 0x16A0, 0x0F60, 0x0870, 0x0230, 0xFD70, 0xF8C0, 0xF580, + 0xF290, 0xF090, 0xF020, 0xEF80, 0xEFD0, 0xEF60, 0xEF20, 0xEED0, 0xEDF0, 0xEC60, 0xEA40, 0xE6F0, 0xE3B0, 0xDF30, 0xDA10, 0xD4C0, + 0xCE80, 0xC8F0, 0xC2E0, 0xBCD0, 0xB670, 0xAFD0, 0xA850, 0xA0D0, 0x9980, 0x9160, 0x8BA0, 0x8820, 0x8650, 0x8580, 0x8530, 0x8500, + 0x84E0, 0x84D0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x8490, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8490, + 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x8490, 0x8490, + 0x8490, 0x8480, 0x8480, 0x8480, 0x8470, 0x8460, 0x8450, 0x8440, 0x8440, 0x8450, 0x8430, 0x8420, 0x8410, 0x8420, 0x8410, 0x8410, + 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8420, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, + 0x8420, 0x8420, 0x8430, 0x8440, 0x8450, 0x8460, 0x8470, 0x8490, 0x84A0, 0x84A0, 0x84F0, 0x8580, 0x8910, 0x99C0, 0xAAC0, 0xB990, + 0xC570, 0xCF20, 0xD6A0, 0xDC10, 0xDFE0, 0xE2A0, 0xE560, 0xE790, 0xE870, 0xE8C0, 0xE770, 0xE450, 0xDF20, 0xD7B0, 0xCF10, 0xC4B0, + 0xB9C0, 0xAD00, 0x9EF0, 0x90B0, 0x87B0, 0x8530, 0x84D0, 0x84B0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8450, 0x8450, 0x8440, 0x8430, + 0x8430, 0x8430, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, + 0x8430, 0x8440, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8470, 0x8480, 0x8480, 0x8490, 0x84B0, 0x84C0, 0x84F0, 0x8550, 0x86A0, + 0x8BF0, 0x97D0, 0xA370, 0xAE50, 0xB880, 0xC250, 0xCAC0, 0xD1F0, 0xD700, 0xDAF0, 0xDE40, 0xE120, 0xE490, 0xE910, 0xECC0, 0xF290, + 0xF770, 0xFD20, 0x02E0, 0x0830, 0x0E00, 0x1320, 0x1960, 0x1FD0, 0x2770, 0x2F40, 0x3710, 0x3FF0, 0x47E0, 0x4F70, 0x5800, 0x5E80, + 0x6560, 0x6C60, 0x71F0, 0x7790, 0x7C10, 0x7EC0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7F80, + 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F70, 0x7F00, 0x7F10, 0x7F10, 0x7EE0, 0x7F60, 0x7EF0, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F70, 0x7F20, + 0x7EC0, 0x7ED0, 0x7ED0, 0x7F30, 0x7F20, 0x7EB0, 0x7EE0, 0x7EC0, 0x7EF0, 0x7F10, 0x7EA0, 0x7EC0, 0x7F10, 0x7F10, 0x7F10, 0x7E90, + 0x7EA0, 0x7E80, 0x7F10, 0x7F10, 0x7EC0, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7EE0, 0x7EF0, 0x7F50, + 0x7F20, 0x7EF0, 0x7EF0, 0x7F10, 0x7F60, 0x7F10, 0x7F10, 0x7EF0, 0x7EF0, 0x7F50, 0x7EF0, 0x7EF0, 0x7EF0, 0x7EF0, 0x7F70, 0x7F00, + 0x7EC0, 0x7EF0, 0x7F00, 0x7F50, 0x7EB0, 0x7EA0, 0x7EF0, 0x7EF0, 0x7F30, 0x7EE0, 0x7EC0, 0x7EF0, 0x7F10, 0x7F20, 0x7EE0, 0x7E90, + 0x7F00, 0x7EE0, 0x7EF0, 0x7F10, 0x7E70, 0x7EF0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7F10, 0x7F00, 0x7F40, + 0x7EF0, 0x7F10, 0x7F30, 0x7F00, 0x7F80, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F70, 0x7EF0, 0x7EF0, 0x7EF0, 0x7F00, 0x7F60, 0x7F00, + 0x7F00, 0x7EF0, 0x7EF0, 0x7F30, 0x7F20, 0x7EC0, 0x7ED0, 0x7EE0, 0x7F40, 0x7EF0, 0x7EB0, 0x7EE0, 0x7EE0, 0x7F10, 0x7F10, 0x7EA0, + 0x7EE0, 0x7ED0, 0x7F00, 0x7F20, 0x7E90, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7F40, + 0x7EF0, 0x7F30, 0x7F20, 0x7F00, 0x7F60, 0x7EA0, 0x79D0, 0x7490, 0x6E30, 0x6760, 0x5FC0, 0x5790, 0x4ED0, 0x4610, 0x3C60, 0x31F0, + 0x2610, 0x1930, 0x0B30, 0xFC20, 0xEC70, 0xDA80, 0xCAD0, 0xBAB0, 0xAB70, 0x9D40, 0x91A0, 0x8A90, 0x8780, 0x8660, 0x85D0, 0x8580, + 0x8530, 0x84F0, 0x84D0, 0x84C0, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, + 0x8480, 0x8480, 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84C0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, + 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8480, + 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84C0, 0x84C0, 0x84D0, 0x84E0, 0x8500, 0x8530, 0x8570, + 0x85C0, 0x8700, 0x88E0, 0x8C50, 0x9210, 0x97E0, 0x9E00, 0xA460, 0xAA90, 0xB0E0, 0xB790, 0xBDC0, 0xC330, 0xC950, 0xCED0, 0xD4B0, + 0xDA60, 0xE140, 0xE7F0, 0xEF30, 0xF740, 0xFF40, 0x0820, 0x1170, 0x1AE0, 0x2530, 0x2EE0, 0x38D0, 0x4290, 0x4CC0, 0x56F0, 0x61B0, + 0x6B70, 0x7590, 0x7D90, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F30, + 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F20, + 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F30, + 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F20, + 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, + 0x7F40, 0x7F30, 0x73B0, 0x6620, 0x5840, 0x49B0, 0x3B50, 0x2D20, 0x1FA0, 0x10F0, 0x03A0, 0xF640, 0xE880, 0xDB20, 0xCD40, 0xBFE0, + 0xB2F0, 0xA6C0, 0x9A50, 0x8F40, 0x88B0, 0x8600, 0x8530, 0x84E0, 0x84D0, 0x84C0, 0x84B0, 0x84A0, 0x8490, 0x84A0, 0x8480, 0x8470, + 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8440, 0x8450, 0x8450, 0x8440, 0x8450, 0x8440, 0x8480, 0x8450, + 0x8460, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8440, 0x8430, 0x8430, 0x8410, + 0x8400, 0x83F0, 0x83E0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83B0, 0x83C0, 0x83C0, 0x83C0, 0x83B0, 0x83B0, 0x83B0, + 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x8390, 0x8390, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83B0, 0x83B0, + 0x83C0, 0x83C0, 0x83D0, 0x83E0, 0x83F0, 0x83F0, 0x8400, 0x8410, 0x8410, 0x8420, 0x8430, 0x8430, 0x8450, 0x8460, 0x8480, 0x8480, + 0x8490, 0x84C0, 0x84E0, 0x8520, 0x8580, 0x85B0, 0x85F0, 0x85B0, 0x85A0, 0x8590, 0x8540, 0x85C0, 0x85F0, 0x8660, 0x86F0, 0x87B0, + 0x8840, 0x88D0, 0x8930, 0x8970, 0x89D0, 0x89F0, 0x8970, 0x88E0, 0x87B0, 0x8510, 0x84F0, 0x84F0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, + 0x8490, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, + 0x8480, 0x8470, 0x8450, 0x8400, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8460, 0x8470, 0x8490, 0x84B0, 0x8520, 0x8A30, 0xA9D0, 0xC2F0, 0xD340, 0xDF30, + 0xE870, 0xF160, 0xFA70, 0x05A0, 0x1160, 0x1D50, 0x2B30, 0x36A0, 0x4270, 0x4DD0, 0x5930, 0x6580, 0x7180, 0x7CD0, 0x7F10, 0x7F40, + 0x7F10, 0x7EB0, 0x7F00, 0x7EF0, 0x7EF0, 0x7F30, 0x7F00, 0x7F40, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7EF0, 0x7F10, 0x7F30, + 0x7F20, 0x7F40, 0x7EF0, 0x7F20, 0x7F20, 0x7F00, 0x7F90, 0x7F10, 0x7F00, 0x7EE0, 0x7F10, 0x7F60, 0x7EF0, 0x7EF0, 0x7EF0, 0x7F00, + 0x7F60, 0x7F10, 0x7E90, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7F70, 0x7F00, 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, 0x7F10, 0x7EE0, 0x7F00, + 0x7EF0, 0x7F70, 0x7F20, 0x7EC0, 0x7ED0, 0x7EB0, 0x7F30, 0x7EF0, 0x7E90, 0x7EB0, 0x7EC0, 0x7EF0, 0x7F10, 0x7EA0, 0x7EE0, 0x7F10, + 0x7F10, 0x7F10, 0x7E90, 0x7EC0, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7D30, 0x65E0, 0x4F80, 0x37D0, 0x2010, 0x0830, + 0xF240, 0xDE10, 0xCBB0, 0xBBB0, 0xAC50, 0xA140, 0x99E0, 0x9730, 0x9A90, 0xA470, 0xB530, 0xCA70, 0xE2D0, 0xFDE0, 0x1640, 0x2C20, + 0x4090, 0x53B0, 0x6520, 0x7480, 0x7E90, 0x7F00, 0x7F90, 0x7ED0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F30, 0x7F00, 0x7EC0, 0x7F10, 0x7F00, + 0x7F10, 0x7EB0, 0x7E70, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F40, 0x7E00, 0x6F10, 0x61E0, 0x5570, + 0x4B90, 0x4340, 0x3E40, 0x39C0, 0x3620, 0x32A0, 0x2E20, 0x2950, 0x2590, 0x2370, 0x2540, 0x29B0, 0x2FF0, 0x36A0, 0x3960, 0x37B0, + 0x2F10, 0x1F60, 0x09F0, 0xED30, 0xD020, 0xB130, 0x9380, 0x8610, 0x84E0, 0x84B0, 0x84A0, 0x8480, 0x8480, 0x8470, 0x8480, 0x8480, + 0x8480, 0x8490, 0x84B0, 0x84D0, 0x8570, 0x8EE0, 0xADF0, 0xC8C0, 0xDF00, 0xF0B0, 0xFD20, 0x05E0, 0x0A90, 0x0CB0, 0x0CC0, 0x0B30, + 0x0970, 0x0760, 0x0600, 0x0610, 0x0870, 0x0C70, 0x11E0, 0x1990, 0x2240, 0x2BE0, 0x3790, 0x4430, 0x5320, 0x62A0, 0x72C0, 0x7EB0, + 0x7EF0, 0x7F60, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F60, 0x7EE0, 0x7EB0, 0x7F00, 0x7EF0, 0x7F50, 0x7ED0, 0x7EB0, 0x7F00, 0x7F00, + 0x7F10, 0x7F10, 0x7EC0, 0x7F10, 0x7EF0, 0x7EF0, 0x7F00, 0x7EC0, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, + 0x7F20, 0x7EE0, 0x7F50, 0x7F10, 0x7EF0, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7F10, 0x7EF0, 0x7EF0, 0x7F60, 0x7EE0, 0x7EF0, 0x7EF0, + 0x7F00, 0x7F70, 0x7F00, 0x7EF0, 0x7EF0, 0x7EE0, 0x7F70, 0x7F10, 0x7EB0, 0x7EE0, 0x7EC0, 0x7EF0, 0x7F10, 0x7EA0, 0x7EC0, 0x7EE0, + 0x7F30, 0x7F00, 0x7E90, 0x7EB0, 0x7F00, 0x7EF0, 0x7EF0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, + 0x7F00, 0x7EB0, 0x7F20, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F50, 0x7EF0, 0x7F00, 0x7EE0, + 0x7EF0, 0x7F80, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7F60, 0x7ED0, 0x7EB0, 0x7EF0, 0x7EE0, 0x7F30, 0x7EE0, 0x7EA0, 0x7EF0, 0x7F10, + 0x7F30, 0x7EE0, 0x7E90, 0x7F10, 0x7EF0, 0x7F40, 0x7EF0, 0x7EA0, 0x7F20, 0x7EF0, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F20, + 0x7EF0, 0x7F10, 0x7F20, 0x7F40, 0x7F40, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F10, 0x7EF0, 0x7F10, 0x7F10, 0x7F30, 0x7F20, + 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, + 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F40, 0x7F40, 0x7F30, 0x7F30, + 0x7F20, 0x7F40, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7740, 0x6BF0, 0x5FB0, 0x5230, 0x4440, + 0x34F0, 0x2550, 0x14B0, 0x0300, 0xEF80, 0xDCB0, 0xC960, 0xB520, 0xA090, 0x8CF0, 0x85D0, 0x84F0, 0x84B0, 0x8490, 0x8480, 0x8470, + 0x8460, 0x8460, 0x8450, 0x8450, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8420, + 0x8420, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x8420, 0x8410, 0x8410, 0x8410, + 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8420, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8410, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8440, 0x8440, + 0x8450, 0x8450, 0x8460, 0x8470, 0x8480, 0x8490, 0x84B0, 0x84E0, 0x85A0, 0x8C00, 0xA450, 0xBB10, 0xD010, 0xE380, 0xF770, 0x0910, + 0x1A30, 0x2B10, 0x3B90, 0x4B30, 0x59E0, 0x6840, 0x7510, 0x7E70, 0x7F20, 0x7F40, 0x7F30, 0x7F10, 0x7F20, 0x7F40, 0x7F50, 0x7F30, + 0x7F80, 0x7F30, 0x7F00, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F20, 0x7F00, 0x7F40, 0x7EF0, 0x7F20, 0x7F00, 0x7EF0, 0x7ED0, 0x7F10, 0x7F40, + 0x7ED0, 0x7E90, 0x7EE0, 0x7EF0, 0x7F50, 0x7EE0, 0x7EA0, 0x7F40, 0x7F10, 0x7F10, 0x7EF0, 0x7E90, 0x7F20, 0x7EE0, 0x7EF0, 0x7F10, + 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x75F0, 0x6A80, 0x5D90, + 0x5050, 0x42F0, 0x3540, 0x2850, 0x1C10, 0x10B0, 0x0700, 0x0010, 0xFB80, 0xF900, 0xF8D0, 0xFB50, 0xFF30, 0x06A0, 0x0F20, 0x1A90, + 0x2730, 0x3460, 0x4360, 0x52F0, 0x6270, 0x7220, 0x7D90, 0x7ED0, 0x7F00, 0x7F30, 0x7F10, 0x7EB0, 0x7EA0, 0x7EC0, 0x7F10, 0x7F10, + 0x7EC0, 0x7ED0, 0x7F20, 0x7F20, 0x7F10, 0x7EB0, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7EF0, + 0x7F30, 0x7EF0, 0x7F10, 0x7F10, 0x7EE0, 0x7F40, 0x7EF0, 0x7F20, 0x7F00, 0x7F00, 0x7F80, 0x7EF0, 0x7F10, 0x7F10, 0x7EF0, 0x7F60, + 0x7EE0, 0x7ED0, 0x7F00, 0x7F00, 0x7F50, 0x7EF0, 0x7EB0, 0x7F00, 0x7F10, 0x7F10, 0x7EB0, 0x7E70, 0x7EF0, 0x7EF0, 0x7F10, 0x7ED0, + 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, 0x7F20, 0x7F10, 0x7F00, 0x7F20, 0x7EC0, 0x7F30, 0x7F00, 0x7F20, 0x7F40, 0x7F10, + 0x7F60, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F80, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F70, 0x7F00, 0x7F10, 0x7EF0, 0x7EF0, 0x7F60, + 0x7EF0, 0x7EB0, 0x7EE0, 0x7EE0, 0x7F50, 0x7F10, 0x7EA0, 0x7ED0, 0x7F10, 0x7F70, 0x7EE0, 0x7EF0, 0x7F10, 0x7F10, 0x7F60, 0x7ED0, + 0x7EB0, 0x7EE0, 0x7EF0, 0x7F30, 0x7EE0, 0x7E90, 0x7EE0, 0x7EF0, 0x7F30, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7EC0, + 0x7F10, 0x7EF0, 0x7F00, 0x7F10, 0x7F00, 0x7F60, 0x7E90, 0x7F00, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F20, + 0x7EF0, 0x7F80, 0x7F10, 0x7F20, 0x7F10, 0x7F20, 0x7FA0, 0x7EF0, 0x7B50, 0x7570, 0x6F60, 0x6850, 0x60B0, 0x5830, 0x4F10, 0x45C0, + 0x3B70, 0x3130, 0x2610, 0x1B00, 0x0FA0, 0x0450, 0xF990, 0xEE10, 0xE450, 0xDAC0, 0xD0F0, 0xC7F0, 0xBE30, 0xB5A0, 0xAD30, 0xA5C0, + 0x9EF0, 0x98C0, 0x93E0, 0x9060, 0x8DF0, 0x8CC0, 0x8C30, 0x8D10, 0x8F60, 0x9320, 0x9890, 0x9F00, 0xA690, 0xAF70, 0xB910, 0xC370, + 0xCDD0, 0xD860, 0xE3C0, 0xEE10, 0xF8C0, 0x02C0, 0x0CF0, 0x16F0, 0x2070, 0x2A60, 0x32F0, 0x3BB0, 0x4340, 0x49F0, 0x50F0, 0x56B0, + 0x5BF0, 0x60F0, 0x6590, 0x69B0, 0x6D90, 0x7050, 0x7260, 0x73E0, 0x7550, 0x75D0, 0x75B0, 0x75A0, 0x7500, 0x7440, 0x72F0, 0x7130, + 0x6FE0, 0x6DC0, 0x6BD0, 0x6980, 0x65A0, 0x6300, 0x5E80, 0x5B00, 0x5720, 0x5300, 0x4F90, 0x4B00, 0x46A0, 0x4180, 0x3B30, 0x3500, + 0x2E40, 0x2750, 0x2000, 0x1720, 0x0F40, 0x05F0, 0xFC10, 0xF1A0, 0xE520, 0xD9D0, 0xCDD0, 0xC1C0, 0xB5A0, 0xA910, 0x9C90, 0x9090, + 0x88D0, 0x85D0, 0x8510, 0x84E0, 0x84C0, 0x84B0, 0x84A0, 0x8490, 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8470, + 0x8440, 0x8440, 0x8440, 0x8430, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8450, 0x8450, + 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, + 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, + 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, + 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8430, 0x8420, 0x8430, 0x8420, 0x8430, + 0x8430, 0x8440, 0x83E0, 0x8440, 0x8450, 0x8440, 0x8450, 0x8460, 0x8450, 0x8450, 0x8410, 0x8460, 0x8460, 0x8450, 0x8460, 0x8460, + 0x8460, 0x83F0, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8410, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, + 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8460, 0x8480, 0x8480, 0x8490, 0x8490, 0x84C0, + 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8470, 0x8470, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x84A0, 0x8450, 0x8450, + 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8490, 0x8460, + 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x84B0, 0x84C0, 0x8500, 0x85E0, 0x8C10, 0xA140, 0xB4F0, 0xC8F0, + 0xDA20, 0xE8F0, 0xF720, 0x0320, 0x0EE0, 0x1990, 0x2360, 0x2BE0, 0x3440, 0x3AD0, 0x4100, 0x4720, 0x4BD0, 0x5050, 0x5480, 0x5820, + 0x5B70, 0x5E70, 0x6120, 0x6340, 0x6510, 0x6630, 0x66B0, 0x66A0, 0x64D0, 0x6210, 0x5E60, 0x5A00, 0x54D0, 0x4F70, 0x4960, 0x4340, + 0x3CB0, 0x35D0, 0x2E60, 0x2690, 0x1F00, 0x1820, 0x1110, 0x0930, 0x0110, 0xF7C0, 0xECD0, 0xDFF0, 0xCFA0, 0xBEE0, 0xAE00, 0x9C30, + 0x8D30, 0x8690, 0x8530, 0x84E0, 0x84C0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, + 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8460, 0x8480, 0x8480, + 0x8480, 0x8490, 0x8490, 0x84B0, 0x84C0, 0x84E0, 0x8530, 0x8650, 0x8BF0, 0x9E90, 0xAF70, 0xC050, 0xD030, 0xDFB0, 0xEEF0, 0xFE40, + 0x0D50, 0x1D00, 0x2D40, 0x3C10, 0x4B00, 0x5880, 0x65C0, 0x7150, 0x7AB0, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, + 0x7F10, 0x7F20, 0x7F10, 0x7F30, 0x7E70, 0x7EE0, 0x7EF0, 0x7F00, 0x7F00, 0x7F00, 0x7F10, 0x7ED0, 0x7F00, 0x7EB0, 0x7E60, 0x7EC0, + 0x7ED0, 0x7F30, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7EF0, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7EF0, + 0x7F20, 0x7F00, 0x7F00, 0x7F50, 0x7F10, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F70, 0x7EE0, 0x7ED0, 0x7F10, 0x7F10, 0x7F40, 0x7ED0, 0x7E90, + 0x7F10, 0x7F10, 0x7F30, 0x7EB0, 0x7E70, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7EC0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, + 0x7F10, 0x7F20, 0x7F40, 0x7EC0, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F60, 0x7EE0, 0x7F10, 0x7F20, 0x7EF0, 0x7F80, 0x7F10, + 0x7F20, 0x7F10, 0x7F10, 0x77F0, 0x6E60, 0x63C0, 0x5B50, 0x53B0, 0x4DA0, 0x49C0, 0x4750, 0x4780, 0x4970, 0x4D70, 0x5340, 0x5940, + 0x6090, 0x68F0, 0x7130, 0x7940, 0x7E00, 0x7ED0, 0x7F00, 0x7EF0, 0x7F10, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, 0x7F00, + 0x7F10, 0x7F00, 0x7F00, 0x70C0, 0x5750, 0x3DA0, 0x2040, 0xFCD0, 0xD0B0, 0x95B0, 0x84D0, 0x84A0, 0x8470, 0x8450, 0x8470, 0x8440, + 0x8440, 0x8440, 0x8430, 0x8420, 0x8420, 0x8410, 0x8400, 0x83F0, 0x8400, 0x83E0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83B0, 0x8390, + 0x83A0, 0x83A0, 0x83A0, 0x8390, 0x8390, 0x8390, 0x8390, 0x83B0, 0x83A0, 0x83A0, 0x83A0, 0x8390, 0x83B0, 0x83C0, 0x83D0, 0x83D0, + 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8410, 0x8400, 0x8400, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83E0, 0x83C0, 0x83B0, 0x83B0, + 0x83E0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83B0, 0x83E0, 0x83C0, 0x83C0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, + 0x8400, 0x8410, 0x8410, 0x8420, 0x8430, 0x8430, 0x8450, 0x8460, 0x8490, 0x8490, 0x84A0, 0x84D0, 0x85B0, 0x8B50, 0xA8F0, 0xC4E0, + 0xE1D0, 0xFB60, 0x12C0, 0x2990, 0x3E00, 0x51C0, 0x63E0, 0x73C0, 0x7E70, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F70, + 0x7F00, 0x7F20, 0x7F20, 0x7F10, 0x7F50, 0x7EF0, 0x7F20, 0x7F20, 0x7F00, 0x7F60, 0x7F00, 0x7F10, 0x7F20, 0x7F00, 0x7F50, 0x7F10, + 0x7F20, 0x7EF0, 0x7EF0, 0x7F80, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F80, 0x7F20, 0x7F10, 0x7EF0, 0x7EF0, 0x7F70, 0x7F00, 0x7EF0, + 0x7ED0, 0x7EB0, 0x7EF0, 0x7EF0, 0x7E90, 0x7ED0, 0x7ED0, 0x7F30, 0x7F20, 0x7EA0, 0x7ED0, 0x7F10, 0x7F00, 0x7F00, 0x7EC0, 0x7EB0, + 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F20, 0x7DE0, 0x73D0, 0x6830, 0x5890, 0x48B0, 0x36E0, 0x2320, 0x0EB0, 0xF800, 0xE020, 0xC6B0, + 0xAB70, 0x8F30, 0x85B0, 0x8500, 0x84A0, 0x8480, 0x84A0, 0x8460, 0x8450, 0x8450, 0x8440, 0x8430, 0x8430, 0x8450, 0x8420, 0x8410, + 0x8410, 0x8450, 0x8410, 0x8410, 0x8410, 0x8430, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8430, 0x8430, 0x8430, 0x8460, + 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8460, 0x8450, 0x8450, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, + 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, + 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, + 0x8440, 0x8440, 0x8450, 0x8450, 0x8460, 0x8460, 0x8470, 0x8480, 0x8490, 0x84A0, 0x84C0, 0x84F0, 0x85A0, 0x8E80, 0xA990, 0xC530, + 0xE260, 0x0100, 0x1FB0, 0x3DB0, 0x5C40, 0x73B0, 0x7EF0, 0x7EE0, 0x7F50, 0x7EF0, 0x7F10, 0x7F00, 0x7F10, 0x7F60, 0x7F00, 0x7F10, + 0x7F10, 0x7EF0, 0x7F60, 0x7EE0, 0x7EB0, 0x7F10, 0x7EF0, 0x7F70, 0x7F00, 0x7EC0, 0x7EF0, 0x7EF0, 0x7F20, 0x7ED0, 0x7E90, 0x7EF0, + 0x7EE0, 0x7EF0, 0x7EF0, 0x7EA0, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7EC0, 0x7F10, 0x7EF0, 0x7EE0, 0x7F10, 0x7F00, 0x7F30, 0x7F00, + 0x7F10, 0x7F20, 0x7F00, 0x7F50, 0x7EF0, 0x7F10, 0x7EF0, 0x7EF0, 0x7F90, 0x7F00, 0x7EF0, 0x7EF0, 0x7F00, 0x7F60, 0x7F10, 0x7EF0, + 0x7EB0, 0x7EE0, 0x7F50, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F00, 0x7F60, 0x7F10, 0x7E90, 0x7EB0, 0x7EC0, 0x7F50, 0x7F10, 0x7E70, 0x7EC0, + 0x7F00, 0x7F00, 0x7F10, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F20, + 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F30, 0x7F30, + 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, + 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F00, 0x7F30, 0x7F30, 0x7F30, 0x7F30, 0x7F00, 0x7F20, 0x7F30, 0x7F30, 0x7F20, + 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F40, + 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F40, 0x7F30, + 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F10, + 0x7F00, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, + 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7150, 0x5A60, 0x4260, + 0x2B10, 0x13D0, 0xFAD0, 0xE4D0, 0xCF30, 0xBB00, 0xA880, 0x97E0, 0x8C50, 0x8770, 0x8600, 0x85A0, 0x85C0, 0x85E0, 0x86B0, 0x88E0, + 0x8E30, 0x96E0, 0x9E70, 0xA3E0, 0xA710, 0xA6A0, 0xA450, 0x9ED0, 0x9760, 0x8F10, 0x88F0, 0x8600, 0x8520, 0x84D0, 0x84B0, 0x84A0, + 0x8480, 0x8470, 0x8470, 0x8460, 0x8450, 0x8420, 0x8440, 0x8430, 0x8430, 0x8420, 0x8420, 0x8420, 0x8410, 0x8400, 0x8400, 0x83F0, + 0x8400, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83A0, 0x83A0, 0x83A0, + 0x83A0, 0x83A0, 0x83C0, 0x83B0, 0x83A0, 0x83B0, 0x83D0, 0x83C0, 0x83E0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x8410, 0x83F0, 0x83F0, + 0x83F0, 0x8400, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, 0x8430, 0x8440, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8430, 0x8440, 0x8450, 0x8450, 0x8460, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, + 0x8480, 0x8480, 0x8470, 0x8480, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, + 0x84B0, 0x84C0, 0x84E0, 0x8570, 0x8A10, 0xA5E0, 0xC170, 0xDB00, 0xF170, 0x0370, 0x1080, 0x1980, 0x1FB0, 0x22A0, 0x22E0, 0x2190, + 0x1CC0, 0x1590, 0x0A50, 0xFD60, 0xEED0, 0xDE80, 0xCD10, 0xBAE0, 0xA7F0, 0x9550, 0x8890, 0x8540, 0x84E0, 0x84B0, 0x84A0, 0x8480, + 0x8470, 0x8470, 0x8460, 0x8450, 0x8440, 0x8440, 0x8430, 0x8430, 0x8420, 0x8420, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x83F0, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8410, 0x8420, 0x8430, + 0x8410, 0x8450, 0x8470, 0x8480, 0x8490, 0x84B0, 0x84C0, 0x8500, 0x8610, 0x93D0, 0xB140, 0xCDE0, 0xE9B0, 0x0350, 0x1B80, 0x3270, + 0x4890, 0x5ED0, 0x7160, 0x7ED0, 0x7F10, 0x7F70, 0x7EE0, 0x7ED0, 0x7F10, 0x7F10, 0x7F70, 0x7EF0, 0x7ED0, 0x7F00, 0x7F10, 0x7F30, + 0x7EB0, 0x7E70, 0x7EF0, 0x7EE0, 0x7F30, 0x7ED0, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, 0x7EC0, 0x7EF0, 0x7F10, + 0x7F50, 0x7ED0, 0x7E70, 0x7EE0, 0x7EF0, 0x7F30, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F10, 0x7EF0, 0x7E70, 0x7EF0, 0x7EF0, 0x7F10, + 0x7F20, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F30, 0x7F10, 0x7F20, 0x7F40, 0x7EE0, 0x7F50, 0x7F10, 0x7F20, 0x7F20, + 0x7F10, 0x7F90, 0x7EF0, 0x7EE0, 0x7F10, 0x7EF0, 0x7F70, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F00, 0x7F60, 0x7F10, 0x7EE0, 0x7F00, 0x7EF0, + 0x7F30, 0x7F10, 0x7E70, 0x7EC0, 0x7EF0, 0x7F20, 0x7EF0, 0x7E90, 0x7EE0, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F00, + 0x7EE0, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F30, 0x7F10, 0x7F00, 0x7300, 0x5A00, 0x4780, 0x3820, 0x29E0, 0x1DD0, + 0x1690, 0x1740, 0x22A0, 0x37D0, 0x5670, 0x75B0, 0x7F60, 0x7EF0, 0x7EF0, 0x7F20, 0x7EF0, 0x7F90, 0x7F00, 0x7EE0, 0x7EF0, 0x7F10, + 0x7F30, 0x7EC0, 0x7EC0, 0x5410, 0x1730, 0xD8B0, 0xA040, 0x8600, 0x84E0, 0x84D0, 0x84E0, 0x8510, 0x8610, 0x8A80, 0x9360, 0x9740, + 0x96F0, 0x9440, 0x92C0, 0x93C0, 0x96A0, 0x9CD0, 0xADB0, 0xAEA0, 0xAEB0, 0xAD30, 0xAD30, 0xAD60, 0xADB0, 0xAEC0, 0xAF90, 0xB0C0, + 0xB110, 0xB150, 0xB1A0, 0xB170, 0xB160, 0xB150, 0xB200, 0xB2C0, 0xB370, 0xB470, 0xB4C0, 0xB510, 0xB450, 0xB340, 0xB120, 0xAE00, + 0xAA20, 0xA5D0, 0xA030, 0x9A80, 0x94B0, 0x8E10, 0x8930, 0x8680, 0x8560, 0x8500, 0x84D0, 0x8450, 0x84A0, 0x8490, 0x8480, 0x8430, + 0x8470, 0x8460, 0x8450, 0x8440, 0x8440, 0x8430, 0x8420, 0x8420, 0x8410, 0x8410, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, + 0x83E0, 0x83D0, 0x83D0, 0x83F0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, + 0x83D0, 0x8400, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, + 0x8430, 0x8440, 0x8450, 0x8450, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84B0, + 0x84B0, 0x84C0, 0x84C0, 0x84D0, 0x84E0, 0x84F0, 0x8500, 0x8530, 0x8570, 0x85E0, 0x8660, 0x8690, 0x8630, 0x8590, 0x8520, 0x84E0, + 0x84C0, 0x84B0, 0x8490, 0x8480, 0x8430, 0x8470, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8470, 0x8450, 0x8440, 0x8440, + 0x83F0, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8430, 0x8450, 0x8450, 0x8450, 0x8450, + 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8430, 0x8430, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, + 0x8420, 0x8430, 0x8430, 0x8440, 0x8440, 0x8450, 0x8470, 0x8490, 0x84D0, 0x92F0, 0xDA30, 0x1BC0, 0x5750, 0x7ED0, 0x7F30, 0x7F20, + 0x7F40, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, + 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, + 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F00, 0x7F20, 0x7F30, 0x7F20, 0x7F40, 0x7EF0, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, + 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, + 0x7F30, 0x7F30, 0x7F40, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F20, + 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F40, 0x7F20, 0x7F20, 0x7F30, 0x7F30, + 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x75C0, 0x66F0, 0x5830, 0x4960, 0x3B40, 0x2E10, 0x2180, 0x1720, + 0x0EC0, 0x07F0, 0x0360, 0xFF20, 0xFC60, 0xF9C0, 0xF690, 0xF300, 0xEFB0, 0xEBD0, 0xE810, 0xE460, 0xE090, 0xDD90, 0xDAF0, 0xD970, + 0xD7B0, 0xD690, 0xD4B0, 0xD210, 0xCE40, 0xC960, 0xC390, 0xBD10, 0xB7D0, 0xB290, 0xB020, 0xAE70, 0xAF60, 0xB1F0, 0xB5A0, 0xBA40, + 0xBF50, 0xC4F0, 0xCAD0, 0xCF70, 0xD360, 0xD5F0, 0xD6A0, 0xD490, 0xCFF0, 0xC8B0, 0xBE40, 0xAF30, 0x9D00, 0x8A60, 0x8530, 0x84C0, + 0x8490, 0x8470, 0x8460, 0x8440, 0x8430, 0x8420, 0x8410, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, + 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8410, + 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, + 0x8440, 0x8450, 0x8480, 0x8460, 0x8460, 0x8470, 0x8430, 0x8490, 0x84A0, 0x84B0, 0x84F0, 0x85E0, 0x90C0, 0xADB0, 0xCA10, 0xE730, + 0x0340, 0x1E60, 0x3A30, 0x5640, 0x6D50, 0x7E30, 0x7F00, 0x7EF0, 0x7EF0, 0x7F50, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F60, 0x7F20, + 0x7F10, 0x7F10, 0x7EF0, 0x7F60, 0x7ED0, 0x7F20, 0x7EF0, 0x7EF0, 0x7F70, 0x7F00, 0x7EE0, 0x7EF0, 0x7F10, 0x7F30, 0x7EF0, 0x7EB0, + 0x7EE0, 0x7EF0, 0x7F30, 0x7EE0, 0x7EA0, 0x7F00, 0x7EF0, 0x7F30, 0x7EE0, 0x7EC0, 0x7F10, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F20, + 0x7F10, 0x7F20, 0x7F20, 0x7ED0, 0x7F20, 0x7EE0, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F30, 0x7F20, 0x7F80, 0x7F10, + 0x7F10, 0x7EF0, 0x7F10, 0x7F70, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F00, 0x7F70, 0x7F20, 0x7ED0, 0x7030, 0x6020, 0x4F40, 0x3F30, 0x2E30, + 0x1EA0, 0x0ED0, 0xFED0, 0xF080, 0xE220, 0xD980, 0xD610, 0xD820, 0xE2C0, 0xF350, 0x09B0, 0x22E0, 0x3D50, 0x5910, 0x6F70, 0x7E80, + 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7F10, 0x7F00, 0x7F20, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, 0x7F60, 0x7EA0, + 0x7F00, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7EF0, 0x7F20, 0x7EF0, 0x7F10, 0x7F60, 0x7F00, 0x7EF0, 0x7F20, 0x7F00, 0x7F50, + 0x7EF0, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F70, 0x7EE0, 0x7ED0, 0x7F10, 0x7F00, 0x7F60, 0x7ED0, 0x7E90, 0x7F00, 0x7EE0, 0x7EF0, 0x7EB0, + 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7EC0, 0x7F10, 0x7F00, 0x72B0, 0x6420, 0x56C0, 0x4BF0, 0x4190, 0x3700, 0x2DD0, 0x24C0, + 0x1C70, 0x1500, 0x0F10, 0x0B90, 0x0A10, 0x0B40, 0x1040, 0x18D0, 0x2610, 0x3560, 0x4690, 0x5660, 0x63C0, 0x6F80, 0x77D0, 0x7DF0, + 0x7EE0, 0x7EE0, 0x7EF0, 0x7EE0, 0x7F60, 0x7F10, 0x7EE0, 0x7F00, 0x7EE0, 0x7F30, 0x7F10, 0x7E70, 0x7ED0, 0x7EB0, 0x7F30, 0x7EF0, + 0x7EB0, 0x7EE0, 0x7F20, 0x7F10, 0x7F10, 0x7E90, 0x7EB0, 0x7F00, 0x7EF0, 0x7EF0, 0x7EB0, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7E90, + 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7ED0, 0x7940, 0x71C0, 0x67F0, 0x5C20, 0x4EE0, 0x4090, 0x3230, 0x2270, 0x12E0, + 0x0250, 0xF2E0, 0xE470, 0xD5D0, 0xC6F0, 0xB700, 0xA660, 0x95F0, 0x8970, 0x8570, 0x84F0, 0x84C0, 0x84B0, 0x84A0, 0x8490, 0x8480, + 0x8470, 0x8470, 0x8460, 0x8450, 0x8450, 0x8440, 0x8430, 0x8430, 0x8420, 0x8420, 0x8410, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, + 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83F0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83B0, + 0x83B0, 0x83B0, 0x8390, 0x83B0, 0x83B0, 0x83B0, 0x83A0, 0x83A0, 0x83B0, 0x83B0, 0x83A0, 0x83A0, 0x83B0, 0x83A0, 0x83A0, 0x8380, + 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83B0, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, + 0x83A0, 0x83D0, 0x83E0, 0x83B0, 0x83C0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8420, + 0x83D0, 0x8420, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8450, 0x8460, 0x8480, 0x84A0, 0x84E0, 0x88F0, 0xBCD0, 0xE9A0, 0x1150, + 0x30A0, 0x48A0, 0x5980, 0x63F0, 0x6C20, 0x7140, 0x7610, 0x7930, 0x7B70, 0x7CC0, 0x7C30, 0x7B10, 0x78C0, 0x7590, 0x72F0, 0x70A0, + 0x7080, 0x7200, 0x7400, 0x7820, 0x7C00, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7EE0, 0x7F50, + 0x7EF0, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7F10, 0x7F10, 0x7EF0, 0x7F20, 0x7F50, 0x7EF0, 0x7F00, 0x7EE0, 0x7EF0, 0x7F80, 0x7F00, + 0x7EE0, 0x7EF0, 0x7EF0, 0x7F00, 0x7F10, 0x7EE0, 0x7EF0, 0x7EF0, 0x7EF0, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7EF0, 0x7F10, 0x7F10, + 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7EF0, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, + 0x7F30, 0x7F50, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, + 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, + 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F20, + 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, + 0x7F30, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F00, 0x7F10, 0x7F30, + 0x7F30, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F30, 0x7EF0, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, + 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F20, + 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, + 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F20, + 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F50, 0x7F10, 0x7EB0, 0x7EF0, 0x7EF0, 0x7EF0, 0x7F30, 0x7E70, 0x7ED0, 0x7EF0, + 0x7EF0, 0x7F00, 0x7E80, 0x7EC0, 0x7EB0, 0x7F10, 0x7EF0, 0x7E90, 0x7EB0, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7F20, 0x7F20, + 0x7F20, 0x7F10, 0x7F50, 0x7EF0, 0x7F00, 0x7EE0, 0x7EF0, 0x7F30, 0x7EE0, 0x7F10, 0x7F00, 0x7F00, 0x7F60, 0x7EF0, 0x7EF0, 0x7F00, + 0x7EF0, 0x7F60, 0x7EE0, 0x7EF0, 0x7F30, 0x7F20, 0x7F40, 0x7ED0, 0x7E90, 0x7EF0, 0x7F00, 0x7F30, 0x7EB0, 0x7E70, 0x7F20, 0x7EF0, + 0x7F30, 0x7F20, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7EB0, 0x7F20, 0x7EE0, 0x7EF0, 0x7F30, 0x7EC0, 0x7F40, 0x7F10, 0x7520, + 0x5EC0, 0x4840, 0x3310, 0x1F30, 0x0CB0, 0xF9F0, 0xE910, 0xD8C0, 0xC950, 0xB900, 0xA970, 0x9960, 0x8B80, 0x8630, 0x8500, 0x84D0, + 0x84B0, 0x84C0, 0x8480, 0x8480, 0x8460, 0x8450, 0x8440, 0x8430, 0x8420, 0x83F0, 0x8400, 0x83F0, 0x83E0, 0x83D0, 0x83D0, 0x83C0, + 0x83B0, 0x83A0, 0x8390, 0x8390, 0x8380, 0x8380, 0x8370, 0x8370, 0x8360, 0x8360, 0x8360, 0x8360, 0x8360, 0x8360, 0x8360, 0x8360, + 0x8370, 0x8370, 0x8370, 0x8370, 0x8370, 0x8370, 0x8370, 0x8370, 0x8370, 0x8370, 0x8370, 0x8380, 0x8370, 0x8380, 0x8380, 0x8380, + 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x83A0, 0x83A0, 0x83A0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, + 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, + 0x8430, 0x8440, 0x8450, 0x8470, 0x8480, 0x8490, 0x84C0, 0x84E0, 0x85B0, 0x8BA0, 0xA340, 0xBA50, 0xD210, 0xE9E0, 0x0220, 0x1A90, + 0x3250, 0x4C20, 0x6310, 0x7790, 0x7EE0, 0x7EE0, 0x7F50, 0x7F10, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F60, 0x7F20, 0x7E90, 0x7EB0, 0x7EB0, + 0x7EF0, 0x7F00, 0x7F60, 0x7F10, 0x7EB0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F20, 0x7EC0, 0x7ED0, 0x7EF0, 0x7F00, 0x7EF0, 0x7EC0, 0x7F10, + 0x7F20, 0x7EF0, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7EE0, 0x7F50, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7F60, 0x7F00, + 0x7F10, 0x7F10, 0x7F00, 0x7F30, 0x7EF0, 0x7F20, 0x7EF0, 0x7F10, 0x7F60, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F80, 0x7EF0, 0x7EB0, + 0x7EF0, 0x7EF0, 0x7F50, 0x7EF0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F30, 0x7EE0, 0x7EC0, 0x7F10, 0x7EF0, 0x7EF0, 0x7EF0, 0x7E90, 0x7F00, + 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7EE0, 0x7EF0, 0x7F10, 0x7F10, 0x7F60, 0x7F00, + 0x7F10, 0x7F20, 0x7F00, 0x7F90, 0x7F10, 0x7F10, 0x7EE0, 0x7EF0, 0x7F70, 0x7F00, 0x7EF0, 0x7EF0, 0x7F00, 0x7F60, 0x7F10, 0x7EB0, + 0x7EB0, 0x7EE0, 0x7F50, 0x7F00, 0x7E70, 0x7ED0, 0x7ED0, 0x7F10, 0x7F20, 0x7EC0, 0x7ED0, 0x7EE0, 0x7F00, 0x7F10, 0x7E90, 0x7EE0, + 0x7F00, 0x7ED0, 0x7F10, 0x7F00, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7EE0, 0x7F40, 0x7F10, + 0x7F20, 0x7F20, 0x7F10, 0x7F50, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7F10, 0x7F10, 0x7F20, 0x7F70, 0x7ED0, 0x7F00, + 0x7F00, 0x7F10, 0x7F50, 0x7EB0, 0x7E70, 0x7EF0, 0x7F10, 0x7F20, 0x7ED0, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7EF0, 0x7EA0, 0x7EE0, + 0x7EF0, 0x7EF0, 0x7EF0, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, 0x7F10, 0x7F20, 0x7EE0, 0x7F50, 0x7F10, + 0x7F20, 0x7F20, 0x7F10, 0x7F60, 0x7F00, 0x7F10, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7F10, 0x7F00, 0x7EE0, 0x7F80, 0x7F10, 0x7F00, + 0x7F00, 0x7ED0, 0x7F30, 0x7F00, 0x7E70, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EB0, 0x6DE0, 0x4EC0, 0x2E30, 0x0E30, 0xEAF0, 0xCAD0, + 0xABD0, 0x8ED0, 0x8590, 0x84D0, 0x84B0, 0x8490, 0x8480, 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, + 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8420, 0x8420, 0x8410, 0x8410, 0x8420, 0x8400, 0x83F0, 0x83F0, + 0x8430, 0x83E0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8410, + 0x8410, 0x8420, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8450, 0x8460, 0x8460, 0x8470, 0x8490, 0x84A0, 0x84D0, 0x8520, 0x8730, + 0x98F0, 0xB1D0, 0xC970, 0xE120, 0x29D0, 0x38A0, 0x4830, 0x5310, 0x5C20, 0x6450, 0x6A90, 0x7030, 0x7460, 0x7820, 0x7A90, 0x7C90, + 0x7DE0, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F20, + 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F00, 0x7F40, 0x7F30, 0x7F30, 0x7F30, + 0x7F40, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F40, + 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, + 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F20, 0x6410, + 0x3FF0, 0x1AD0, 0xF5C0, 0xD150, 0xAD90, 0x8D60, 0x8520, 0x84B0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8450, 0x8440, 0x8430, 0x8420, + 0x8410, 0x8400, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, 0x83E0, 0x83D0, + 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8420, 0x8400, 0x8400, 0x8410, 0x8420, + 0x8420, 0x8430, 0x8440, 0x8450, 0x8460, 0x8470, 0x8490, 0x8500, 0x8600, 0xA2A0, 0xCC70, 0xF550, 0x1DD0, 0x49D0, 0x6E70, 0x7F40, + 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F50, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, + 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F60, 0x7EF0, 0x7EF0, 0x7F00, 0x7F20, + 0x7F40, 0x7F20, 0x7F00, 0x7F00, 0x7ED0, 0x7F10, 0x7EE0, 0x7ED0, 0x7ED0, 0x7F00, 0x7F40, 0x7EF0, 0x7EF0, 0x7EE0, 0x7EE0, 0x7F10, + 0x7F10, 0x7E70, 0x7EE0, 0x7EB0, 0x7EF0, 0x7F20, 0x7E90, 0x7EF0, 0x7F00, 0x7F20, 0x7F10, 0x7E90, 0x7F00, 0x7F00, 0x7F10, 0x7EF0, + 0x7EA0, 0x7EE0, 0x7F10, 0x7F20, 0x7F00, 0x7F00, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7EF0, 0x7F20, 0x7EF0, 0x7F10, 0x7F10, 0x7F00, + 0x7F30, 0x7F00, 0x7F10, 0x7F10, 0x7EF0, 0x7F40, 0x7EF0, 0x7F10, 0x7EF0, 0x7EE0, 0x7F70, 0x7EF0, 0x7EE0, 0x7F00, 0x7F10, 0x7F30, + 0x7F00, 0x7ED0, 0x7EF0, 0x7EF0, 0x7F20, 0x7ED0, 0x7EB0, 0x7F00, 0x7F00, 0x7F30, 0x7F00, 0x7EA0, 0x7F10, 0x7F10, 0x7F10, 0x7F00, + 0x7EC0, 0x7F30, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7EF0, 0x7F10, 0x7F30, 0x7F20, + 0x7F80, 0x7EF0, 0x7F10, 0x7EF0, 0x7B60, 0x73D0, 0x6D30, 0x65F0, 0x5FA0, 0x58F0, 0x53B0, 0x4FA0, 0x4D40, 0x4E10, 0x5030, 0x54A0, + 0x5AF0, 0x61B0, 0x68E0, 0x7000, 0x75D0, 0x7B90, 0x7E60, 0x7EC0, 0x7ED0, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F10, + 0x7EA0, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F30, 0x7F20, 0x7F20, 0x7ED0, 0x7F10, + 0x7F60, 0x7EF0, 0x7F30, 0x7F20, 0x7F00, 0x7F50, 0x7EF0, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F30, 0x7EE0, 0x7EF0, 0x7F10, 0x7C70, 0x71F0, + 0x6810, 0x5C90, 0x5100, 0x42C0, 0x3490, 0x2570, 0x1570, 0x0580, 0xF550, 0xE410, 0xD320, 0xC190, 0xAE30, 0x9BF0, 0x8C40, 0x8640, + 0x8510, 0x84D0, 0x84B0, 0x8490, 0x8490, 0x8480, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8440, 0x8450, 0x8440, + 0x8440, 0x8450, 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8470, 0x8460, 0x8450, 0x8450, 0x8470, 0x8440, 0x8440, + 0x8440, 0x8410, 0x8430, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8420, 0x8430, 0x8440, 0x8430, + 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, 0x8430, 0x8450, 0x8460, 0x8470, 0x8480, 0x84A0, 0x84C0, 0x8530, 0x89B0, 0xA7C0, + 0xC710, 0xE030, 0xF720, 0x0B40, 0x1C50, 0x2C60, 0x3A60, 0x4770, 0x5390, 0x5F50, 0x68A0, 0x7120, 0x7740, 0x7B90, 0x7DB0, 0x7EA0, + 0x7EE0, 0x7F50, 0x7EF0, 0x7F10, 0x7F00, 0x7F20, 0x7F70, 0x7EF0, 0x7EE0, 0x7F00, 0x7F10, 0x7F80, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, + 0x7F30, 0x7EE0, 0x7E90, 0x7F10, 0x7EE0, 0x77D0, 0x6B50, 0x5C70, 0x4B40, 0x37D0, 0x2200, 0x0B30, 0xF200, 0xD590, 0xBA20, 0x9DB0, + 0x8900, 0x8510, 0x84C0, 0x84A0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8450, 0x8450, 0x8440, 0x8430, 0x8430, 0x8420, 0x8410, 0x8410, + 0x8410, 0x8440, 0x8400, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x8400, 0x83F0, 0x8400, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8410, 0x8410, 0x8410, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x83D0, 0x8400, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, + 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8410, 0x8420, 0x8430, 0x8430, 0x8440, 0x8440, + 0x8450, 0x8450, 0x8460, 0x8470, 0x8490, 0x84C0, 0x8540, 0x8AF0, 0xA910, 0xC0D0, 0xD480, 0xE470, 0xF2A0, 0xFE10, 0x09C0, 0x11C0, + 0x16B0, 0x19B0, 0x18E0, 0x1660, 0x10C0, 0x09B0, 0x0140, 0xF850, 0xF090, 0xE900, 0xE140, 0xDA70, 0xD1A0, 0xC770, 0xBBA0, 0xAD50, + 0x9D50, 0x8EB0, 0x8710, 0x8530, 0x84E0, 0x84C0, 0x84A0, 0x8490, 0x8480, 0x8470, 0x8470, 0x8460, 0x8450, 0x8450, 0x8450, 0x8440, + 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8410, 0x8450, + 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84B0, 0x84C0, 0x84C0, + 0x84D0, 0x84E0, 0x84F0, 0x8500, 0x8510, 0x8510, 0x8510, 0x8500, 0x8500, 0x84F0, 0x84F0, 0x84F0, 0x84E0, 0x84E0, 0x84D0, 0x84D0, + 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x8460, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, + 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84B0, 0x84D0, 0x84F0, 0x8510, 0x8570, 0x8610, 0x8720, 0x87E0, 0x87C0, 0x86A0, + 0x8580, 0x84F0, 0x84C0, 0x8490, 0x8480, 0x8460, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8420, 0x8420, 0x8410, + 0x8410, 0x8400, 0x8410, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8420, 0x8440, 0x8430, 0x8430, 0x8440, 0x8450, 0x8470, 0x8490, + 0x84E0, 0x8680, 0x98E0, 0xAA00, 0xB670, 0xC210, 0xD0A0, 0xE450, 0xF900, 0x0C50, 0x1B90, 0x24C0, 0x2760, 0x2410, 0x1CC0, 0x1350, + 0x0880, 0xFF00, 0xF630, 0xD4E0, 0xCBB0, 0xC400, 0xBEC0, 0xBC80, 0xBDE0, 0xC340, 0xCAC0, 0xD530, 0xE0E0, 0xEE30, 0xFC10, 0x09E0, + 0x18C0, 0x26D0, 0x3640, 0x4570, 0x5510, 0x6480, 0x7340, 0x7E40, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, + 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F10, 0x7F20, 0x7F30, 0x7F10, 0x7F20, + 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7D20, 0x69E0, 0x5950, 0x4A80, 0x3F00, 0x3740, 0x3150, 0x2DE0, 0x2BD0, + 0x2AB0, 0x29F0, 0x2940, 0x2870, 0x26F0, 0x2430, 0x1FD0, 0x1920, 0x0E90, 0x0330, 0xF5A0, 0xE710, 0xD7D0, 0xC8D0, 0xBA00, 0xABF0, + 0x9E30, 0x9100, 0x88D0, 0x85C0, 0x8500, 0x84D0, 0x84B0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8450, 0x8440, 0x8430, 0x8430, 0x8420, + 0x8410, 0x8410, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8440, 0x8460, 0x8470, + 0x8480, 0x8480, 0x8490, 0x84A0, 0x84B0, 0x84D0, 0x84F0, 0x8560, 0x8690, 0x8A40, 0x9160, 0x97A0, 0x9CC0, 0xA160, 0xA5A0, 0xAAA0, + 0xB1A0, 0xB8E0, 0xBFF0, 0xC730, 0xCE00, 0xD3C0, 0xD900, 0xDD90, 0xE120, 0xE540, 0xE830, 0xEAC0, 0xED20, 0xEDD0, 0xEE30, 0xEDB0, + 0xED20, 0xEC90, 0xEC00, 0xEC80, 0xECD0, 0xEFB0, 0xF300, 0xF6A0, 0xFB50, 0x0030, 0x05E0, 0x0BF0, 0x1130, 0x1760, 0x1D20, 0x22B0, + 0x27F0, 0x2C80, 0x3140, 0x3390, 0x3520, 0x3540, 0x3350, 0x3110, 0x2D30, 0x2940, 0x23B0, 0x1F60, 0x1B20, 0x1640, 0x1310, 0x1100, + 0x0F80, 0x10D0, 0x1370, 0x18A0, 0x1F60, 0x27D0, 0x32A0, 0x3C20, 0x44F0, 0x4C10, 0x5160, 0x5500, 0x5650, 0x55B0, 0x5400, 0x5010, + 0x4C10, 0x48A0, 0x4660, 0x47C0, 0x4BA0, 0x5380, 0x5CC0, 0x6550, 0x6CA0, 0x7040, 0x7290, 0x7510, 0x7A60, 0x7F00, 0x7ED0, 0x7F30, + 0x7F20, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7F80, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7F80, 0x7F20, + 0x7F10, 0x7EF0, 0x7EE0, 0x7F70, 0x7EF0, 0x7EF0, 0x7EE0, 0x7ED0, 0x7F50, 0x7F10, 0x7EA0, 0x7ED0, 0x7F00, 0x7F60, 0x7F10, 0x7E90, + 0x7EB0, 0x7EC0, 0x7EF0, 0x7F10, 0x7EA0, 0x7EC0, 0x7ED0, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, 0x7F00, 0x7F00, 0x7EF0, 0x7EA0, 0x7F00, + 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F30, 0x7EF0, 0x7F10, 0x7F10, 0x7F10, 0x7F60, 0x7F00, + 0x7F20, 0x7F00, 0x7F10, 0x7F50, 0x7EF0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F70, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F60, 0x7ED0, 0x5FB0, + 0x3A00, 0x10C0, 0xE0F0, 0xB2F0, 0x8950, 0x84C0, 0x8430, 0x8420, 0x8410, 0x8410, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, + 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8410, 0x8420, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8460, 0x8460, + 0x8460, 0x8470, 0x84A0, 0x8490, 0x84B0, 0x84D0, 0x84E0, 0x84E0, 0x84D0, 0x84D0, 0x84B0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8470, + 0x8470, 0x8490, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8490, 0x8460, 0x8470, 0x8480, 0x8440, 0x84C0, 0x8510, 0x8720, 0x9A00, + 0xAE70, 0xBFB0, 0xCCD0, 0xD5C0, 0xDAD0, 0xDC70, 0xDAE0, 0xD620, 0xCF40, 0xC860, 0xC130, 0xBAB0, 0xB580, 0xB200, 0xB080, 0xB080, + 0xB310, 0xB6B0, 0xBC10, 0xC170, 0xC8B0, 0xD080, 0xD8A0, 0xE1A0, 0xEB40, 0xF550, 0x01B0, 0x0D00, 0x18F0, 0x2470, 0x2FE0, 0x3C70, + 0x4850, 0x5580, 0x6280, 0x7150, 0x7D90, 0x7EA0, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7F40, 0x7EF0, 0x7EF0, 0x7F10, 0x7F00, + 0x7F60, 0x7F00, 0x7F10, 0x7F10, 0x7EF0, 0x7F50, 0x7EF0, 0x7F10, 0x7EF0, 0x7EF0, 0x7F90, 0x7F00, 0x7F00, 0x7EF0, 0x7F00, 0x7F60, + 0x7F10, 0x7EF0, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EB0, 0x7ED0, 0x7ED0, 0x7F30, 0x7F20, 0x7EC0, 0x7ED0, 0x7EB0, 0x7F00, 0x7EF0, + 0x7E90, 0x7EA0, 0x7EE0, 0x7F10, 0x7F20, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7E90, 0x7F10, 0x7F00, 0x7EF0, 0x7EF0, 0x7F00, + 0x7F60, 0x7F20, 0x7F20, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, 0x7F60, + 0x7ED0, 0x7EF0, 0x7EF0, 0x7EE0, 0x7F70, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F60, 0x7EE0, 0x7E90, 0x7F10, 0x7F00, 0x7F30, 0x7EB0, + 0x7EA0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7EB0, 0x7F20, 0x7F20, 0x7EF0, 0x7F30, 0x7EC0, + 0x7F40, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F90, 0x7F00, 0x7F20, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7F00, 0x7F70, + 0x7F10, 0x7F20, 0x7F10, 0x7EF0, 0x7F30, 0x7F00, 0x7EC0, 0x7ED0, 0x7EE0, 0x7F30, 0x7F10, 0x7EB0, 0x7F00, 0x7EE0, 0x7F10, 0x7F10, + 0x7E70, 0x7EC0, 0x7ED0, 0x7F00, 0x7F00, 0x7B90, 0x7230, 0x6720, 0x5AA0, 0x4D80, 0x3F10, 0x30A0, 0x1FD0, 0x1070, 0x0170, 0xF2C0, + 0xE3D0, 0xD520, 0xC640, 0xB7C0, 0xA8D0, 0x99D0, 0x8DE0, 0x87B0, 0x85D0, 0x8530, 0x8500, 0x84E0, 0x84D0, 0x84D0, 0x84C0, 0x84B0, + 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84F0, 0x84F0, 0x8520, 0x8590, 0x8700, 0x8BF0, + 0x9750, 0xA330, 0xAF20, 0xBC00, 0xC800, 0xD490, 0xE140, 0xEF50, 0xFCF0, 0x09F0, 0x1760, 0x24E0, 0x3290, 0x40A0, 0x4E60, 0x5C40, + 0x6A30, 0x75E0, 0x7E40, 0x7F30, 0x7F30, 0x7F30, 0x7F40, 0x7F50, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, + 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, + 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, + 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F10, + 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7EF0, 0x7F30, + 0x7F30, 0x7F40, 0x7F30, 0x7F00, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F30, + 0x7F20, 0x7F40, 0x7F50, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F50, 0x7F30, 0x7F20, 0x7F20, + 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F30, + 0x7F20, 0x7F20, 0x7F30, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7EF0, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F70, 0x7F10, 0x7EF0, + 0x7F20, 0x7F40, 0x7F50, 0x7F30, 0x7EA0, 0x7EE0, 0x7EF0, 0x7F30, 0x7F00, 0x7E60, 0x7EB0, 0x7F20, 0x7F20, 0x7EF0, 0x7E90, 0x7EB0, + 0x7EE0, 0x7EF0, 0x7F10, 0x7E70, 0x7EF0, 0x7F10, 0x7F20, 0x7F40, 0x7EC0, 0x7F30, 0x7EF0, 0x7EF0, 0x7EF0, 0x7EA0, 0x7F20, 0x7EF0, + 0x7F10, 0x7F20, 0x7F20, 0x7F80, 0x7950, 0x6FC0, 0x6790, 0x5F70, 0x5790, 0x50A0, 0x4950, 0x4310, 0x3D10, 0x37C0, 0x32F0, 0x2E60, + 0x2BA0, 0x2840, 0x2510, 0x2270, 0x1FA0, 0x1CF0, 0x1A10, 0x1720, 0x1450, 0x10F0, 0x0E30, 0x0BA0, 0x08D0, 0x06B0, 0x03E0, 0x0100, + 0xFDB0, 0xFA10, 0xF770, 0xF450, 0xF120, 0xEE20, 0xEB70, 0xE910, 0xE680, 0xE3D0, 0xE110, 0xDE70, 0xDCA0, 0xDA60, 0xD8C0, 0xD6D0, + 0xD450, 0xD2C0, 0xD030, 0xCE20, 0xCCC0, 0xCB10, 0xCB50, 0xCB40, 0xCBE0, 0xCC70, 0xCD70, 0xCF00, 0xD000, 0xD110, 0xD220, 0xD2A0, + 0xD390, 0xD510, 0xD6B0, 0xD8F0, 0xDB10, 0xDDF0, 0xE0E0, 0xE2F0, 0xE5F0, 0xE840, 0xEB20, 0xED90, 0xF0B0, 0xF400, 0xF6F0, 0xFB00, + 0xFE20, 0x01C0, 0x0520, 0x0870, 0x0BA0, 0x0F00, 0x12B0, 0x16A0, 0x1A40, 0x1E10, 0x2280, 0x2600, 0x2AA0, 0x2E80, 0x32B0, 0x3740, + 0x3A80, 0x3EE0, 0x41E0, 0x4500, 0x4790, 0x4A50, 0x4DB0, 0x5070, 0x5330, 0x5620, 0x5870, 0x5BD0, 0x5EB0, 0x6120, 0x63C0, 0x6650, + 0x6990, 0x6C80, 0x6EF0, 0x7170, 0x7300, 0x74F0, 0x7600, 0x76F0, 0x7770, 0x77D0, 0x7850, 0x7900, 0x7940, 0x7910, 0x77F0, 0x77E0, + 0x7760, 0x7650, 0x76B0, 0x75F0, 0x7690, 0x7730, 0x7760, 0x78E0, 0x7980, 0x7AB0, 0x7C00, 0x7CC0, 0x7DB0, 0x7E20, 0x7EC0, 0x7F10, + 0x7F20, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7F40, 0x7F10, 0x7F00, 0x7F30, 0x7EF0, 0x7F40, 0x7F10, 0x7F00, 0x7F00, 0x7D30, 0x7A60, + 0x7740, 0x72D0, 0x6DF0, 0x6860, 0x61E0, 0x5A50, 0x5160, 0x45E0, 0x0B40, 0xFB40, 0xE9D0, 0xD6C0, 0xC340, 0xAD50, 0x95A0, 0x8720, + 0x84F0, 0x84B0, 0x8490, 0x8470, 0x8460, 0x8450, 0x8440, 0x8430, 0x8420, 0x8410, 0x8430, 0x8400, 0x83F0, 0x83F0, 0x83E0, 0x83D0, + 0x83D0, 0x83E0, 0x83C0, 0x83B0, 0x83B0, 0x83B0, 0x83A0, 0x83A0, 0x83D0, 0x8390, 0x8390, 0x8390, 0x83B0, 0x8390, 0x8390, 0x8390, + 0x83C0, 0x8380, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x83C0, 0x83A0, 0x83B0, 0x83A0, 0x83A0, 0x83B0, + 0x83A0, 0x8340, 0x83B0, 0x83A0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, + 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83B0, 0x83C0, 0x83C0, + 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, + 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x8420, 0x8400, 0x8410, 0x8410, 0x8420, 0x8430, + 0x8430, 0x8440, 0x8450, 0x8460, 0x84B0, 0x8480, 0x84A0, 0x84C0, 0x84E0, 0x8560, 0x8760, 0x90B0, 0x9E90, 0xAAA0, 0xB490, 0xBC90, + 0xC310, 0xC7D0, 0xCC10, 0xCE70, 0xD090, 0xD260, 0xD410, 0xD630, 0xD800, 0xD9E0, 0xDB80, 0xDC30, 0xDC60, 0xDB90, 0xDA10, 0xD750, + 0xD400, 0xD060, 0xCC30, 0xC730, 0xC1A0, 0xBB90, 0xB650, 0xB070, 0xAA90, 0xA500, 0x9F30, 0x98F0, 0x9170, 0x8A40, 0x86A0, 0x8550, + 0x84F0, 0x84D0, 0x84C0, 0x84B0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, + 0x8490, 0x8480, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84B0, 0x84C0, 0x84D0, 0x84D0, 0x84E0, 0x84F0, 0x8500, 0x8510, 0x8520, + 0x8530, 0x8520, 0x8510, 0x8500, 0x84E0, 0x84C0, 0x84B0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8460, 0x8450, 0x8440, 0x8430, 0x8420, + 0x8420, 0x8410, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, + 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8410, + 0x8410, 0x8420, 0x8430, 0x8440, 0x8450, 0x8450, 0x8470, 0x8480, 0x8490, 0x84B0, 0x84E0, 0x8550, 0x8780, 0x9380, 0xA410, 0xB1F0, + 0xBF60, 0xCAD0, 0xD590, 0xDF20, 0xE6C0, 0xED30, 0xF1D0, 0xF430, 0xF6A0, 0xF790, 0xF8A0, 0xF920, 0xFA10, 0xFB30, 0xFC30, 0xFDA0, + 0xFFF0, 0x0200, 0x0490, 0x06F0, 0x0930, 0x0AE0, 0x0CC0, 0x0F10, 0x1190, 0x1460, 0x1730, 0x1A30, 0x1D40, 0x2040, 0x22B0, 0x23F0, + 0x2510, 0x2530, 0x24B0, 0x2490, 0x2500, 0x2620, 0x26C0, 0x2730, 0x2800, 0x2790, 0x26F0, 0x2570, 0x2380, 0x2160, 0x1D80, 0x1870, + 0x11E0, 0x08D0, 0xFE30, 0xF130, 0xE210, 0xD3A0, 0xC500, 0xB7A0, 0xABF0, 0xA270, 0x9A60, 0x94A0, 0x8FB0, 0x8BC0, 0x8900, 0x8700, + 0x85C0, 0x8540, 0x8500, 0x84D0, 0x84C0, 0x84A0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8480, 0x8440, 0x8430, 0x8430, 0x8420, 0x8410, + 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83B0, 0x83B0, 0x8370, 0x83B0, 0x83B0, + 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x8390, 0x8390, 0x8390, 0x8390, + 0x8340, 0x8390, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, + 0x83B0, 0x83C0, 0x83C0, 0x83B0, 0x83B0, 0x83A0, 0x83A0, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x83A0, 0x83B0, + 0x83B0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x8430, 0x8400, 0x8400, 0x8410, 0x8410, 0x8420, 0x8430, + 0x8430, 0x8440, 0x8440, 0x8450, 0x8470, 0x8480, 0x8490, 0x84A0, 0x84C0, 0x84F0, 0x8530, 0x8640, 0x8A10, 0x9580, 0xA250, 0xAF70, + 0xBD60, 0xCBD0, 0xDDB0, 0xF040, 0x04C0, 0x1AF0, 0x32B0, 0x4B00, 0x62A0, 0x76F0, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, + 0x7F30, 0x7F30, 0x7FA0, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7EB0, 0x7EF0, 0x7F40, 0x7EB0, 0x7EE0, 0x7EC0, + 0x7ED0, 0x7F30, 0x7F40, 0x7EF0, 0x7ED0, 0x7F00, 0x7F70, 0x7F10, 0x7EB0, 0x7EE0, 0x7ED0, 0x7F30, 0x7F30, 0x7EA0, 0x7EF0, 0x7EE0, + 0x7F30, 0x7F50, 0x7E90, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F30, 0x7EA0, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, + 0x7F10, 0x7E90, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, 0x7F00, 0x7EF0, 0x7F10, 0x7F40, 0x7EC0, 0x7F40, 0x7EF0, 0x7F20, 0x7F40, + 0x7F10, 0x7F80, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7F80, 0x7EF0, 0x7EF0, 0x7EF0, 0x7F00, 0x7F60, 0x7F00, 0x7F00, 0x7F00, 0x7F00, + 0x7F50, 0x7F10, 0x7EA0, 0x7EC0, 0x7ED0, 0x7F30, 0x7EF0, 0x7EB0, 0x7EE0, 0x7EE0, 0x7F10, 0x7F10, 0x7E90, 0x7EE0, 0x7EF0, 0x7F10, + 0x7F00, 0x7EC0, 0x7EB0, 0x7F10, 0x7F20, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7EE0, 0x7F40, 0x7F10, 0x7F20, 0x7F20, + 0x7EE0, 0x6B50, 0x5520, 0x3A80, 0x1E30, 0xFF90, 0xE070, 0xC160, 0xA390, 0x8BB0, 0x8550, 0x84E0, 0x84C0, 0x84B0, 0x84C0, 0x84B0, + 0x84E0, 0x8570, 0x90C0, 0xC3B0, 0xFAC0, 0x39F0, 0x7810, 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7ED0, 0x7EC0, 0x7ED0, 0x7F10, 0x7F20, + 0x7EE0, 0x7E90, 0x7F10, 0x7F00, 0x7F00, 0x7F10, 0x7EA0, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7F40, 0x7F10, 0x7EE0, 0x7F10, + 0x7F00, 0x7F60, 0x7F00, 0x7F10, 0x7EF0, 0x7EF0, 0x7F60, 0x7EF0, 0x7F10, 0x7EE0, 0x7EF0, 0x7F80, 0x7F00, 0x7F00, 0x7EF0, 0x7ED0, + 0x7F60, 0x7F10, 0x7ED0, 0x7EB0, 0x7EC0, 0x7EF0, 0x7F10, 0x7EA0, 0x7EC0, 0x7ED0, 0x7F30, 0x7F00, 0x7E90, 0x7EB0, 0x7EE0, 0x7EE0, + 0x7EF0, 0x7E90, 0x7EC0, 0x7ED0, 0x7F10, 0x7F10, 0x7EC0, 0x7F00, 0x7F10, 0x7F00, 0x7ED0, 0x7F00, 0x7F00, 0x7E90, 0x7ED0, 0x7F00, + 0x7EF0, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7EF0, 0x7EE0, 0x7F50, 0x7F10, 0x7F00, 0x7EE0, 0x7EF0, 0x7F60, 0x7F00, 0x7F20, + 0x7F10, 0x7EF0, 0x7F50, 0x7EF0, 0x7F10, 0x7EE0, 0x7EF0, 0x7F80, 0x7EF0, 0x7EE0, 0x7F00, 0x7F10, 0x7F60, 0x7EE0, 0x7EB0, 0x7EF0, + 0x7EE0, 0x7F20, 0x7ED0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F30, 0x7F00, 0x7EC0, 0x7F10, 0x7EF0, 0x7EF0, 0x7F00, 0x7E90, 0x7EF0, 0x7EE0, + 0x7ED0, 0x7F10, 0x7F00, 0x7F40, 0x7ED0, 0x7F10, 0x7F40, 0x7F00, 0x7F30, 0x7EE0, 0x7F00, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7F20, + 0x7F20, 0x7F00, 0x7F90, 0x7EF0, 0x7EF0, 0x7EE0, 0x7ED0, 0x7F70, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F00, 0x7F60, 0x7F10, 0x7E90, 0x7EB0, + 0x7EC0, 0x7F30, 0x7F00, 0x7E70, 0x7ED0, 0x7ED0, 0x7F20, 0x7F20, 0x7E90, 0x7E90, 0x7EE0, 0x7F10, 0x7F10, 0x7EA0, 0x7EE0, 0x7EF0, + 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F30, 0x7F20, 0x7F10, 0x7F10, 0x7EE0, 0x7F40, 0x7F30, 0x7F20, + 0x7F00, 0x7F10, 0x7F50, 0x7EF0, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, 0x78D0, 0x6A50, 0x5860, 0x4580, + 0x30D0, 0x1AF0, 0x0440, 0xEAF0, 0xD0D0, 0xB560, 0x9960, 0x8710, 0x84F0, 0x84D0, 0x84C0, 0x8480, 0x8470, 0x8470, 0x8450, 0x8450, + 0x8440, 0x8460, 0x8430, 0x8420, 0x83C0, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x83F0, 0x8430, 0x83F0, 0x83F0, 0x83F0, 0x83E0, + 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83F0, 0x83D0, 0x83D0, 0x83C0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, + 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83D0, 0x83C0, 0x83D0, 0x83D0, 0x83C0, 0x83D0, 0x83D0, + 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8410, 0x8410, 0x8420, 0x8430, 0x8430, 0x8440, 0x8450, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, + 0x8470, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x8490, 0x8490, + 0x8480, 0x8470, 0x8460, 0x8450, 0x8450, 0x8440, 0x8440, 0x8430, 0x8430, 0x8420, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x83F0, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83D0, + 0x83D0, 0x83C0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, + 0x83E0, 0x83D0, 0x83E0, 0x83E0, 0x83F0, 0x83E0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8410, 0x8460, 0x8420, 0x8430, 0x8420, + 0x8440, 0x8440, 0x8450, 0x84A0, 0x8460, 0x8470, 0x8480, 0x8490, 0x84A0, 0x84C0, 0x84E0, 0x8550, 0x87F0, 0x9910, 0xAED0, 0xC520, + 0xDB80, 0xF570, 0x0DE0, 0x2700, 0x4080, 0x5A30, 0x70D0, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, + 0x7EF0, 0x7F10, 0x7F30, 0x7F20, 0x7F10, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, + 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F50, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F50, 0x7F20, 0x7F40, 0x7A10, 0x5F20, 0x4070, 0x2210, + 0x02B0, 0xE220, 0xC0F0, 0x9E90, 0x8740, 0x84E0, 0x84D0, 0x8480, 0x8470, 0x8460, 0x8450, 0x8440, 0x8430, 0x8430, 0x8420, 0x8420, + 0x8410, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, 0x83E0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, + 0x83C0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83B0, + 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83F0, 0x83D0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8400, + 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x8430, 0x8400, + 0x8410, 0x8420, 0x8430, 0x8430, 0x8440, 0x8450, 0x8460, 0x8470, 0x8480, 0x84A0, 0x8550, 0x85F0, 0xA040, 0xC580, 0xE180, 0xF450, + 0xFDB0, 0x0030, 0xFEB0, 0xFDB0, 0xFF40, 0x04D0, 0x0EF0, 0x1CB0, 0x2C40, 0x3D00, 0x4B40, 0x55C0, 0x5C90, 0x6050, 0x6430, 0x6920, + 0x6F50, 0x7790, 0x7EA0, 0x7EF0, 0x7F10, 0x7F80, 0x7F00, 0x7F40, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7F10, 0x7F00, 0x7EF0, 0x7F70, + 0x7F10, 0x7EE0, 0x7F10, 0x7ED0, 0x7F30, 0x7F00, 0x7ED0, 0x7EF0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7EA0, 0x7F00, 0x7F00, 0x7F10, 0x7F20, + 0x7EC0, 0x7ED0, 0x7F10, 0x7F00, 0x7EF0, 0x7EC0, 0x7F10, 0x7EF0, 0x7EF0, 0x7F10, 0x7F00, 0x7160, 0x5290, 0x3970, 0x2790, 0x1D20, + 0x1B50, 0x23A0, 0x3460, 0x4D50, 0x6AF0, 0x7F60, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F50, 0x7EF0, 0x7F10, 0x7EE0, 0x7EF0, 0x7F80, + 0x7F00, 0x7EC0, 0x7EF0, 0x7F00, 0x7F60, 0x7EF0, 0x7EB0, 0x7EF0, 0x7EE0, 0x7EF0, 0x7ED0, 0x7E70, 0x7EF0, 0x7EF0, 0x7F30, 0x7EE0, + 0x7EC0, 0x7EF0, 0x7EF0, 0x7EF0, 0x7ED0, 0x7E90, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F20, 0x7F00, 0x7F40, 0x7EF0, 0x7F00, 0x7F20, 0x7F00, + 0x7EB0, 0x7E70, 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, 0x7F00, 0x7F00, 0x7F00, 0x7E90, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F10, + 0x7F00, 0x7EE0, 0x7EF0, 0x7F00, 0x7F60, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F50, 0x7EF0, 0x7F00, 0x7EE0, 0x7EF0, 0x7F50, 0x7F00, + 0x7F00, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7ED0, 0x7EF0, 0x7EE0, 0x7F50, 0x7ED0, 0x7EC0, 0x7EF0, 0x7F10, 0x7F30, 0x7EE0, 0x7EC0, + 0x7F10, 0x7F00, 0x7EF0, 0x7EF0, 0x7EA0, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F20, 0x7F10, 0x7F00, 0x7F30, + 0x7EE0, 0x7EF0, 0x7F30, 0x7F10, 0x7F70, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F90, 0x7F00, 0x7F20, 0x7F10, 0x7F20, 0x7F40, 0x7F10, + 0x7F70, 0x7EF0, 0x7F00, 0x7F30, 0x7F00, 0x7F80, 0x7F10, 0x7F10, 0x7EE0, 0x7EE0, 0x7F70, 0x7F10, 0x7EE0, 0x7ED0, 0x7EF0, 0x7F60, + 0x7F20, 0x7EC0, 0x7EB0, 0x7EB0, 0x7EF0, 0x7F10, 0x7E70, 0x7EC0, 0x7ED0, 0x7F10, 0x7B00, 0x5E80, 0x43D0, 0x2AB0, 0x1240, 0x00C0, + 0xF200, 0xE570, 0xDAE0, 0xD280, 0xCD90, 0xCB60, 0xCDA0, 0xD2E0, 0xDAC0, 0xE440, 0xEDE0, 0xF5D0, 0xFB20, 0xFC20, 0xFAF0, 0xF6C0, + 0xF240, 0xEE80, 0xECE0, 0xEDC0, 0xF0C0, 0xF610, 0xFD50, 0x0410, 0x0A40, 0x0E70, 0x0E30, 0x0A60, 0x0210, 0xF710, 0xE960, 0xDAA0, + 0xCB50, 0xBB80, 0xAA60, 0x9A70, 0x8BC0, 0x8610, 0x8500, 0x84D0, 0x84B0, 0x8490, 0x8490, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, + 0x8440, 0x8440, 0x8450, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8460, 0x8430, 0x8430, 0x8430, 0x83C0, 0x8430, 0x8430, 0x8460, + 0x8430, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8460, 0x8470, 0x8470, 0x8490, 0x84A0, 0x84D0, 0x8550, 0x8A40, 0xA760, + 0xC390, 0xE090, 0xFB20, 0x1420, 0x2CE0, 0x4490, 0x5BB0, 0x7120, 0x7EC0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7EE0, + 0x7F40, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F60, 0x7F00, 0x7ED0, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7F00, 0x7EE0, 0x7EF0, 0x7F80, + 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F30, 0x7EF0, 0x7EB0, 0x7EF0, 0x7F20, 0x7EF0, 0x7ED0, 0x7EA0, 0x7F00, 0x7F00, 0x7F30, 0x7F00, + 0x7EC0, 0x7F10, 0x7EF0, 0x7EF0, 0x7EF0, 0x7F00, 0x7F30, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, + 0x7F30, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7F10, 0x7EF0, 0x7F00, 0x7F90, 0x7F10, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F70, + 0x7F20, 0x7EC0, 0x7EF0, 0x7F00, 0x7F60, 0x7F10, 0x7E90, 0x7EB0, 0x7EC0, 0x7EF0, 0x7F10, 0x7E70, 0x7ED0, 0x7ED0, 0x7F00, 0x7F00, + 0x7E90, 0x7E90, 0x7F00, 0x7F20, 0x7F10, 0x7EA0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F20, 0x7F10, 0x7F00, + 0x7F30, 0x7F20, 0x7EF0, 0x7EF0, 0x7F10, 0x7F60, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F50, 0x7EF0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F40, + 0x7EF0, 0x7EF0, 0x7F10, 0x7F20, 0x7F70, 0x7ED0, 0x7EB0, 0x7EE0, 0x7F10, 0x7F30, 0x7EE0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, + 0x7E90, 0x7F00, 0x7F00, 0x7F10, 0x7EE0, 0x7EF0, 0x7F10, 0x7EF0, 0x7ED0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F00, + 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, + 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F30, + 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7AA0, 0x6270, 0x4B00, 0x3240, + 0x1850, 0xFDB0, 0xE1C0, 0xC600, 0xAA40, 0x90E0, 0x8620, 0x8500, 0x84D0, 0x84D0, 0x84D0, 0x84F0, 0x8530, 0x8650, 0x8B80, 0x9590, + 0x9700, 0x8F00, 0x86C0, 0x84F0, 0x84B0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8450, 0x8440, 0x8450, 0x8430, 0x8420, 0x8420, 0x8410, + 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, 0x8440, 0x8450, 0x8460, 0x8480, 0x8490, 0x84B0, 0x84F0, 0x86B0, 0xA680, 0xD0B0, 0xFB60, + 0x2500, 0x4C40, 0x6D50, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, + 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, + 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F30, + 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7E20, 0x6F90, 0x6090, 0x50A0, 0x3F60, 0x2CB0, 0x1850, + 0x02D0, 0xEB40, 0xCFE0, 0xB430, 0x96A0, 0x8620, 0x84B0, 0x84A0, 0x8480, 0x8460, 0x8460, 0x8440, 0x8460, 0x8430, 0x8420, 0x8410, + 0x8410, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83B0, 0x83C0, + 0x83C0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83F0, + 0x83E0, 0x83F0, 0x83E0, 0x83F0, 0x8400, 0x8400, 0x83F0, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8420, 0x8410, 0x8420, 0x8420, + 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8460, 0x8470, + 0x8480, 0x8490, 0x84C0, 0x8500, 0x8650, 0x9710, 0xB330, 0xCCD0, 0xE540, 0xFB60, 0x0F40, 0x20B0, 0x30C0, 0x3DF0, 0x48B0, 0x52E0, + 0x5B40, 0x6250, 0x6A10, 0x7030, 0x7740, 0x7D30, 0x7F00, 0x7F00, 0x7EC0, 0x7F10, 0x7F00, 0x7F20, 0x7EF0, 0x7F00, 0x7EE0, 0x7F10, + 0x7F10, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7F10, 0x7F00, 0x7F10, 0x7F30, 0x7EF0, 0x7F10, 0x7F10, 0x7F10, 0x7F60, 0x7F00, 0x7F10, + 0x7F20, 0x7F00, 0x7F50, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7F60, 0x7ED0, 0x7E90, 0x7F00, + 0x7EE0, 0x7EF0, 0x7EE0, 0x7E70, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7EC0, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, 0x7F20, 0x7EF0, + 0x7F10, 0x7F20, 0x7F20, 0x7F50, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F60, 0x7EE0, 0x7F10, 0x7EF0, 0x7F10, 0x7F70, 0x7F10, 0x7F20, + 0x7F20, 0x7F00, 0x7F90, 0x7F10, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F60, 0x7F10, 0x7ED0, 0x7EF0, 0x7F00, 0x7F50, 0x7F10, 0x7E90, 0x7EE0, + 0x7ED0, 0x7F30, 0x7F00, 0x7E80, 0x7ED0, 0x7F10, 0x7F20, 0x7F20, 0x7EB0, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, 0x7EC0, + 0x7F10, 0x7F00, 0x7EF0, 0x7D50, 0x7500, 0x6DC0, 0x6750, 0x6190, 0x5D40, 0x5980, 0x5680, 0x54A0, 0x5470, 0x55E0, 0x5900, 0x5F40, + 0x6750, 0x7170, 0x7C60, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x6710, 0x4210, 0x1820, 0xEC80, 0xC310, 0x9CE0, 0x86D0, 0x84E0, + 0x8490, 0x8490, 0x8480, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, + 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8470, + 0x8470, 0x8460, 0x8470, 0x8470, 0x8480, 0x8480, 0x84B0, 0x84B0, 0x8480, 0x8490, 0x84C0, 0x8490, 0x84D0, 0x84B0, 0x84C0, 0x84B0, + 0x84C0, 0x8490, 0x84E0, 0x8510, 0x85A0, 0x8830, 0x94F0, 0xA720, 0xB640, 0xC250, 0xCBD0, 0xD1F0, 0xD500, 0xD560, 0xD470, 0xD270, + 0xD0F0, 0xD010, 0xD090, 0xD1F0, 0xD350, 0xD4D0, 0xD630, 0xD6F0, 0xD6C0, 0xD580, 0xD440, 0xD2C0, 0xD170, 0xD210, 0xD360, 0xD7A0, + 0xDD10, 0xE4B0, 0xEEE0, 0xF9C0, 0x0600, 0x12E0, 0x1FE0, 0x2D10, 0x3900, 0x43A0, 0x4D40, 0x55B0, 0x5D60, 0x6300, 0x6790, 0x6B60, + 0x6DA0, 0x6EE0, 0x6E50, 0x6C30, 0x6960, 0x6550, 0x61F0, 0x5D00, 0x5760, 0x5180, 0x4A50, 0x4330, 0x3B40, 0x30B0, 0x2600, 0x1AC0, + 0x0E50, 0x0010, 0xF090, 0xE0A0, 0xCEF0, 0xBD50, 0xA980, 0x9650, 0x88D0, 0x8540, 0x84D0, 0x84B0, 0x8490, 0x8480, 0x8470, 0x8460, + 0x8450, 0x8410, 0x8440, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, + 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, + 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8420, 0x8400, 0x8400, + 0x8400, 0x8420, 0x8420, 0x8440, 0x8480, 0x8460, 0x8470, 0x8490, 0x84B0, 0x84E0, 0x8550, 0x8820, 0x9A70, 0xAF30, 0xC340, 0xD580, + 0xE770, 0xF560, 0x00F0, 0x09D0, 0x1090, 0x15A0, 0x1770, 0x16F0, 0x14E0, 0x0E70, 0x05B0, 0xF9C0, 0xEA40, 0xD840, 0xC370, 0xADF0, + 0x9740, 0x8840, 0x8520, 0x84D0, 0x84B0, 0x84A0, 0x8480, 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8480, + 0x8450, 0x8450, 0x8400, 0x8450, 0x8450, 0x8470, 0x8440, 0x8440, 0x8450, 0x8450, 0x8440, 0x8450, 0x8460, 0x8450, 0x8450, 0x8450, + 0x8450, 0x8450, 0x8460, 0x8460, 0x84A0, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x84A0, 0x84A0, 0x84B0, 0x84C0, 0x84E0, 0x84F0, + 0x8510, 0x8530, 0x8570, 0x85B0, 0x8600, 0x8670, 0x8760, 0x8A00, 0x90F0, 0x9C80, 0xAA40, 0xB8E0, 0xC760, 0xD4F0, 0xE160, 0xEB80, + 0xF4B0, 0xFBA0, 0x0180, 0x05E0, 0x0960, 0x0B40, 0x0BA0, 0x0A20, 0x07C0, 0x0470, 0x0060, 0xFC00, 0xF780, 0xF290, 0xEE60, 0xEAB0, + 0xE6D0, 0xE360, 0xDFD0, 0xDC70, 0xD8F0, 0xD530, 0xD150, 0xCD40, 0xC890, 0xC360, 0xBE40, 0xB890, 0xB270, 0xAC80, 0xA620, 0x9FE0, + 0x9880, 0x90A0, 0x89B0, 0x8650, 0x8530, 0x84E0, 0x84F0, 0x84A0, 0x8480, 0x8470, 0x8460, 0x8450, 0x8440, 0x8430, 0x8420, 0x8420, + 0x8410, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, + 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83D0, 0x83E0, 0x83E0, 0x83F0, 0x83E0, 0x83F0, 0x8400, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8420, + 0x8420, 0x8430, 0x8440, 0x8450, 0x8460, 0x8470, 0x8480, 0x84A0, 0x84D0, 0x8500, 0x8610, 0x8E90, 0xA4A0, 0xB8B0, 0xCC80, 0xDE90, + 0xF050, 0x00E0, 0x1060, 0x2030, 0x2E70, 0x3B20, 0x46A0, 0x5110, 0x5A60, 0x6220, 0x6900, 0x6F30, 0x7520, 0x79E0, 0x7D50, 0x7EF0, + 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F90, 0x7F20, 0x7EE0, 0x7F10, 0x7F00, + 0x7F20, 0x7EF0, 0x7ED0, 0x7F20, 0x7F00, 0x7F10, 0x7E10, 0x7CC0, 0x7B80, 0x7A50, 0x78F0, 0x7760, 0x7490, 0x71D0, 0x6D90, 0x6800, + 0x6150, 0x5930, 0x5100, 0x47C0, 0x3D30, 0x32D0, 0x2700, 0x1B10, 0x0E90, 0x00A0, 0xF3D0, 0xE5D0, 0xD7F0, 0xC940, 0xB9E0, 0xAA80, + 0x9BA0, 0x8E10, 0x8710, 0x8550, 0x84F0, 0x84D0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, + 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x8400, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8430, 0x8400, 0x8400, + 0x8410, 0x8400, 0x8410, 0x8410, 0x8430, 0x8410, 0x8410, 0x8420, 0x8440, 0x8420, 0x8420, 0x8450, 0x8450, 0x8430, 0x8440, 0x8470, + 0x8450, 0x8450, 0x8470, 0x84A0, 0x8480, 0x8490, 0x84C0, 0x8500, 0x86D0, 0x9C90, 0xBBD0, 0xD790, 0xF290, 0x0B70, 0x2210, 0x36B0, + 0x49F0, 0x5A20, 0x68D0, 0x7600, 0x7E30, 0x7F10, 0x7E90, 0x7EB0, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7ED0, 0x7F10, 0x7F20, 0x7F20, + 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F60, 0x7F10, 0x7F10, 0x7F20, 0x7F10, + 0x7F30, 0x7EF0, 0x7F00, 0x7EF0, 0x7F10, 0x7F60, 0x7F00, 0x7F10, 0x7F20, 0x7F00, 0x7F90, 0x7EF0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F30, + 0x7EE0, 0x7EC0, 0x7F10, 0x7F20, 0x7F40, 0x7ED0, 0x7E90, 0x7F00, 0x7EE0, 0x7F10, 0x7EE0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, + 0x7F00, 0x7F30, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, 0x7F10, 0x7F30, 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7F30, 0x7F10, + 0x7F70, 0x7EE0, 0x7EF0, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F60, 0x7EF0, 0x7F20, 0x7F20, 0x7F00, 0x7F90, 0x7F10, 0x7EF0, 0x7EE0, + 0x7ED0, 0x7F70, 0x7EF0, 0x7EF0, 0x7F00, 0x7F00, 0x7F60, 0x7F10, 0x6C30, 0x55C0, 0x3CE0, 0x2070, 0x06B0, 0xECA0, 0xD1F0, 0xB5E0, + 0x97B0, 0x86A0, 0x84D0, 0x84A0, 0x8480, 0x8470, 0x8450, 0x8440, 0x8440, 0x8430, 0x8410, 0x8410, 0x8400, 0x8400, 0x83F0, 0x83F0, + 0x83E0, 0x83F0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, + 0x8420, 0x8420, 0x8430, 0x8430, 0x8440, 0x8440, 0x8450, 0x8450, 0x8460, 0x8470, 0x8480, 0x8490, 0x84B0, 0x8500, 0x85D0, 0x91F0, + 0xB130, 0xD040, 0xF090, 0x1280, 0x3860, 0x5CF0, 0x7B90, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7EF0, 0x7F60, 0x7F10, 0x7F10, 0x7F00, + 0x7EE0, 0x7F50, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F60, 0x7F00, 0x7F10, 0x7F10, 0x7EF0, 0x7F60, 0x7ED0, 0x7EB0, 0x7F00, 0x7EF0, + 0x7F70, 0x7F00, 0x7EC0, 0x7F00, 0x7F10, 0x7F20, 0x7EE0, 0x7E90, 0x7EF0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7EB0, 0x7F20, 0x7F10, 0x7F10, + 0x7EA0, 0x6980, 0x5A10, 0x4D90, 0x4400, 0x3F60, 0x3D80, 0x3FD0, 0x45E0, 0x4EC0, 0x5D00, 0x6C00, 0x7C00, 0x7F10, 0x7F10, 0x7F20, + 0x7EF0, 0x7F90, 0x7F10, 0x7F10, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, 0x7F00, 0x7EE0, 0x7EE0, 0x7ED0, + 0x7F30, 0x7F20, 0x7EC0, 0x7ED0, 0x7EB0, 0x7F50, 0x7F10, 0x7E90, 0x7EB0, 0x7EE0, 0x7F10, 0x7F10, 0x7EA0, 0x7F00, 0x7F00, 0x7F20, + 0x7F20, 0x7EC0, 0x7F00, 0x7F00, 0x7EF0, 0x7EF0, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7EF0, + 0x7F10, 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, 0x7F60, 0x7EF0, 0x7EF0, 0x7F00, 0x7F10, 0x7F50, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F10, + 0x7F60, 0x7F00, 0x7ED0, 0x7F00, 0x7F00, 0x7F50, 0x7ED0, 0x7EA0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EE0, 0x7E90, 0x7F10, 0x7F20, 0x7F20, + 0x7F10, 0x7EB0, 0x7F10, 0x7EE0, 0x7F10, 0x7F10, 0x7EC0, 0x7F10, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7F80, 0x7F00, 0x7F10, 0x7F10, + 0x7F00, 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7F00, 0x7F80, 0x7F00, 0x7F20, 0x7F00, 0x7EF0, 0x7F30, 0x7EF0, 0x7EC0, 0x7ED0, 0x7EE0, + 0x7F60, 0x7EF0, 0x7EB0, 0x7EE0, 0x7EE0, 0x7F10, 0x7F10, 0x7E70, 0x7ED0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F00, 0x7F10, 0x7F20, + 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F20, + 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, + 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F00, + 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7EF0, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F20, + 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F50, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F30, + 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, + 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, + 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x72D0, 0x4900, 0x1BA0, 0xEB90, 0xBA70, 0x8D10, 0x84E0, 0x84A0, 0x8480, 0x8470, 0x8460, + 0x8450, 0x8440, 0x8440, 0x8430, 0x8430, 0x8420, 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x83B0, 0x8410, 0x8410, 0x8410, 0x8400, + 0x8400, 0x8400, 0x8400, 0x8400, 0x83F0, 0x8400, 0x8400, 0x8420, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83F0, 0x83E0, + 0x83E0, 0x83E0, 0x83E0, 0x8400, 0x83E0, 0x83F0, 0x83F0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8410, 0x8400, 0x8400, + 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, + 0x83C0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83A0, 0x8390, 0x8390, 0x8380, 0x8370, 0x8370, 0x8360, 0x8350, 0x8370, 0x8350, 0x8350, + 0x8350, 0x8380, 0x8350, 0x8360, 0x8310, 0x8370, 0x8370, 0x8370, 0x8380, 0x8380, 0x8380, 0x83C0, 0x8390, 0x8390, 0x8390, 0x8390, + 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x83A0, 0x83A0, 0x83A0, 0x83B0, 0x83C0, 0x83C0, 0x83D0, 0x83F0, 0x8400, 0x8410, 0x8430, + 0x8450, 0x8470, 0x84B0, 0x86E0, 0xBE00, 0xF710, 0x2C80, 0x5C80, 0x7E60, 0x7EE0, 0x7E90, 0x7F10, 0x7F10, 0x7F30, 0x7EB0, 0x7E70, + 0x7EF0, 0x7EF0, 0x7F20, 0x7F20, 0x7EC0, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7EE0, 0x7EF0, 0x7F30, 0x7EC0, 0x7F40, + 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F70, 0x7EF0, 0x7F00, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7F10, 0x7F00, 0x7F00, 0x7F80, 0x7F10, + 0x7F00, 0x7EF0, 0x7EF0, 0x7F30, 0x7F00, 0x7EC0, 0x7ED0, 0x7EE0, 0x7F20, 0x7F10, 0x7EB0, 0x7EE0, 0x7ED0, 0x7F10, 0x7F10, 0x7E70, + 0x7ED0, 0x7F10, 0x7F00, 0x7EF0, 0x7E90, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7EB0, 0x7F20, 0x7F10, 0x7F10, 0x7EF0, 0x7EC0, 0x7F40, + 0x7F20, 0x7F20, 0x7F00, 0x7F10, 0x7F40, 0x7F20, 0x7F10, 0x7F10, 0x7EF0, 0x7F40, 0x7EF0, 0x7F10, 0x7F10, 0x7EF0, 0x7F50, 0x7F00, + 0x7F00, 0x7F10, 0x7F10, 0x7F60, 0x7EE0, 0x7EC0, 0x7EF0, 0x7EE0, 0x7F50, 0x7EF0, 0x7EB0, 0x7F20, 0x7F10, 0x7F10, 0x7EB0, 0x7EC0, + 0x7F10, 0x7F00, 0x7F20, 0x7EF0, 0x7EB0, 0x7F20, 0x6890, 0x5130, 0x3720, 0x1AD0, 0xFF50, 0xE350, 0xC900, 0xB080, 0x9A90, 0x8B20, + 0x8610, 0x8520, 0x84E0, 0x84C0, 0x84B0, 0x8490, 0x8480, 0x8470, 0x8470, 0x8480, 0x8450, 0x8440, 0x8420, 0x8430, 0x8420, 0x8410, + 0x8410, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, + 0x83D0, 0x83E0, 0x83E0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x8410, 0x83F0, 0x83F0, 0x83F0, 0x83F0, + 0x83F0, 0x8400, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x83E0, 0x8400, 0x8400, 0x8400, 0x83F0, 0x8400, 0x8400, + 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8420, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, + 0x8450, 0x8450, 0x8440, 0x8450, 0x8440, 0x8440, 0x8490, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8420, 0x8420, 0x8420, 0x8420, 0x8460, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8460, 0x8460, 0x8470, 0x8480, + 0x8490, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8E20, 0xBB50, 0xE9E0, + 0x17E0, 0x4640, 0x6E50, 0x7F20, 0x7EE0, 0x7E90, 0x7F10, 0x7EF0, 0x7F30, 0x7F00, 0x7EC0, 0x7F10, 0x7F00, 0x7EF0, 0x7F00, 0x7EC0, + 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7F60, 0x7EF0, 0x7F10, 0x7F20, 0x7EF0, 0x7F80, 0x7F00, 0x7F20, 0x7F10, 0x7EF0, 0x7F70, + 0x7F20, 0x7EF0, 0x7EF0, 0x7EE0, 0x7F70, 0x7F10, 0x7F00, 0x7F00, 0x7EF0, 0x7F30, 0x7F00, 0x7ED0, 0x7ED0, 0x7EB0, 0x7EF0, 0x7EF0, + 0x7E90, 0x7ED0, 0x7F00, 0x7F10, 0x7F20, 0x7EA0, 0x7ED0, 0x7F10, 0x7F00, 0x7F00, 0x7EC0, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F00, + 0x7F20, 0x7850, 0x6A10, 0x5F30, 0x55E0, 0x4F10, 0x4A30, 0x4800, 0x49C0, 0x4D70, 0x53E0, 0x5D60, 0x68E0, 0x7690, 0x7EF0, 0x7F70, + 0x7F10, 0x7F10, 0x7EF0, 0x7EF0, 0x7F80, 0x7F00, 0x7EE0, 0x7F00, 0x7F10, 0x7F70, 0x7EF0, 0x7ED0, 0x7EF0, 0x7EF0, 0x7F30, 0x7ED0, + 0x7EB0, 0x7EF0, 0x7EF0, 0x7F30, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F00, 0x7E90, 0x7F00, 0x7EF0, 0x7EF0, 0x7F20, 0x7F00, + 0x7F40, 0x7F10, 0x7F10, 0x7F40, 0x7F00, 0x7F30, 0x7EF0, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7F10, 0x7F20, 0x7EE0, 0x7EF0, 0x7F10, + 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F20, + 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F20, 0x7F20, + 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, + 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, + 0x7F20, 0x7F20, 0x7F10, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F30, + 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, + 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F10, + 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, + 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F20, + 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F10, 0x7F30, 0x7F10, 0x7F20, + 0x7F40, 0x7F30, 0x7F30, 0x7EE0, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7EF0, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F70, 0x7F20, 0x7EF0, + 0x7F30, 0x7F30, 0x7F30, 0x7EF0, 0x7E90, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7E80, 0x7D80, 0x4F00, 0x2090, 0xF470, 0xCC20, 0xAB70, + 0x9120, 0x8730, 0x8550, 0x84F0, 0x84D0, 0x8470, 0x84A0, 0x8480, 0x8480, 0x8470, 0x8470, 0x8460, 0x8410, 0x8460, 0x8460, 0x8460, + 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8420, 0x8430, 0x8420, 0x8420, 0x8420, 0x8440, 0x8420, 0x8410, 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, + 0x8420, 0x8410, 0x8410, 0x8410, 0x83E0, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8410, 0x8430, + 0x8410, 0x8410, 0x83C0, 0x8410, 0x8410, 0x8410, 0x83F0, 0x8420, 0x8420, 0x8420, 0x8450, 0x8420, 0x8420, 0x8410, 0x8430, 0x8420, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8450, 0x8430, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8450, 0x8440, 0x8430, 0x8430, 0x8460, + 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8460, 0x8490, 0x8480, 0x8470, 0x8480, 0x84A0, 0x8490, 0x8490, 0x8490, 0x84D0, 0x84A0, + 0x84B0, 0x84C0, 0x84C0, 0x84B0, 0x84C0, 0x84D0, 0x84E0, 0x84E0, 0x84E0, 0x84D0, 0x84B0, 0x84A0, 0x8480, 0x8470, 0x8470, 0x8470, + 0x8450, 0x8440, 0x8430, 0x8440, 0x8410, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x8410, 0x83F0, 0x83E0, 0x83E0, 0x8400, 0x83E0, + 0x83E0, 0x83E0, 0x83F0, 0x83D0, 0x83D0, 0x8370, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83B0, 0x83B0, 0x8380, 0x83B0, 0x83B0, 0x83B0, + 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83A0, 0x83B0, 0x83A0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, + 0x83A0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x8360, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, + 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, + 0x83F0, 0x8410, 0x8400, 0x8400, 0x83B0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8390, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, + 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, + 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83B0, 0x83C0, 0x83B0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, 0x8430, 0x8440, 0x8450, 0x8460, 0x8470, + 0x8480, 0x8490, 0x84A0, 0x84B0, 0x84D0, 0x84E0, 0x8520, 0x85A0, 0x8730, 0x8D90, 0x9B30, 0xA9A0, 0xB860, 0xC790, 0xD820, 0xE800, + 0xF880, 0x0A10, 0x1D60, 0x33C0, 0x4D00, 0x6850, 0x7E60, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, 0x7F20, 0x7F20, 0x7F00, 0x7F90, + 0x7F00, 0x7F20, 0x7EF0, 0x7EF0, 0x7F70, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F80, 0x7F10, 0x7F20, 0x7F00, 0x7EF0, 0x7F50, 0x7F00, + 0x7EA0, 0x7ED0, 0x7EE0, 0x7F40, 0x7EF0, 0x7EB0, 0x7EE0, 0x7EE0, 0x7F10, 0x7F10, 0x7E90, 0x7ED0, 0x7ED0, 0x7F00, 0x7EE0, 0x7E90, + 0x7F00, 0x7F00, 0x7F00, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EE0, 0x7F40, 0x7F30, 0x7F20, 0x7EF0, 0x7F00, 0x7F40, + 0x7F40, 0x7F10, 0x7F10, 0x7EF0, 0x7F40, 0x7EF0, 0x7F20, 0x7EE0, 0x7EF0, 0x7F50, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F60, 0x7EF0, + 0x7EF0, 0x7830, 0x5070, 0x2950, 0x01D0, 0xDAE0, 0xB4C0, 0x8FE0, 0x8510, 0x84D0, 0x8490, 0x8470, 0x8460, 0x8480, 0x8450, 0x8450, + 0x8440, 0x8470, 0x8440, 0x8450, 0x8420, 0x8450, 0x8450, 0x8450, 0x8420, 0x8450, 0x8450, 0x8460, 0x8450, 0x8440, 0x8440, 0x8440, + 0x8440, 0x8430, 0x8430, 0x8440, 0x8440, 0x8480, 0x8460, 0x8480, 0x84B0, 0x8530, 0x91F0, 0xB790, 0xD450, 0xE980, 0xFC20, 0x0F10, + 0x23F0, 0x3D30, 0x5720, 0x6FE0, 0x7ED0, 0x7F20, 0x7EF0, 0x7F10, 0x7F60, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F00, + 0x7EE0, 0x7EF0, 0x7F80, 0x7F00, 0x7EC0, 0x7F00, 0x7F10, 0x7F60, 0x7EF0, 0x7EB0, 0x7F00, 0x7EE0, 0x7EF0, 0x7F20, 0x7F00, 0x7F10, + 0x7F10, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F00, 0x7F20, 0x7F10, + 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, + 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, + 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F30, + 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F30, + 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7EF0, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F00, 0x7F20, 0x7F30, 0x7F30, + 0x7F20, 0x7EF0, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, + 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F10, + 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F30, + 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, + 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, + 0x7F40, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7EE0, 0x7F20, 0x7EF0, 0x7ED0, 0x7F00, 0x7EC0, 0x7EC0, 0x7EE0, 0x7F20, 0x7EC0, + 0x7F10, 0x7F30, 0x7EC0, 0x7EF0, 0x7F10, 0x7EE0, 0x7F40, 0x7ED0, 0x7F00, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7EE0, 0x7F10, 0x7EF0, + 0x7F30, 0x7EE0, 0x7E90, 0x7F30, 0x7F00, 0x7F20, 0x7EE0, 0x7EA0, 0x7F00, 0x7ED0, 0x7F10, 0x7F00, 0x7EA0, 0x7F10, 0x7F10, 0x7EF0, + 0x7EF0, 0x7EB0, 0x7F30, 0x7F00, 0x7F10, 0x7F30, 0x7EE0, 0x7F20, 0x7F10, 0x7F00, 0x7F20, 0x7EF0, 0x7F80, 0x7F00, 0x7F40, 0x7EF0, + 0x7EF0, 0x7F60, 0x7F10, 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, 0x7F10, 0x7EF0, 0x7F00, 0x7EF0, 0x7F60, 0x7F20, 0x7ED0, 0x7ED0, 0x7EB0, + 0x7EF0, 0x7EF0, 0x7E90, 0x7EE0, 0x7EC0, 0x7F30, 0x7F20, 0x7EA0, 0x7ED0, 0x7F10, 0x7F10, 0x7F00, 0x7E90, 0x7EB0, 0x7F00, 0x7EF0, + 0x7F10, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F70, 0x7960, 0x6450, 0x4DE0, + 0x3320, 0x15F0, 0xF6D0, 0xD580, 0xB410, 0x9110, 0x8530, 0x84B0, 0x8480, 0x8460, 0x8460, 0x8450, 0x8440, 0x8410, 0x8420, 0x8420, + 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, + 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83C0, 0x83C0, 0x83B0, 0x83C0, 0x83B0, 0x83B0, + 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x8390, 0x8390, 0x83C0, 0x8390, 0x83A0, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, + 0x83B0, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, + 0x83A0, 0x83A0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83D0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, + 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8420, 0x8400, 0x8400, 0x8410, + 0x8400, 0x8400, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, + 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, + 0x8420, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8440, 0x8420, 0x8420, 0x8420, 0x8470, 0x8420, 0x8420, 0x8410, + 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8430, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8440, 0x8410, 0x8410, 0x8440, 0x8410, 0x8430, 0x8420, 0x8420, + 0x8430, 0x8430, 0x8440, 0x8440, 0x8450, 0x8460, 0x8470, 0x8490, 0x84C0, 0x8540, 0x9210, 0xBC50, 0xE680, 0x0B60, 0x2F80, 0x51B0, + 0x7030, 0x7E70, 0x7EC0, 0x7F10, 0x7F10, 0x7EF0, 0x7F10, 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F00, + 0x7F20, 0x7EF0, 0x7F60, 0x7F00, 0x7F40, 0x7F10, 0x7EF0, 0x7F80, 0x7F10, 0x7F10, 0x7EF0, 0x7EE0, 0x7F70, 0x7F10, 0x7F00, 0x7F00, + 0x7F00, 0x7F60, 0x7F00, 0x7ED0, 0x7EB0, 0x7EB0, 0x7EF0, 0x7EF0, 0x7EB0, 0x7EE0, 0x7ED0, 0x7F30, 0x7F20, 0x7EA0, 0x7ED0, 0x7EF0, + 0x7F00, 0x7EE0, 0x7E90, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7F00, 0x7F00, + 0x7EF0, 0x7F10, 0x7F60, 0x7F40, 0x7F10, 0x7F20, 0x7F00, 0x7F50, 0x7EF0, 0x7F10, 0x7EE0, 0x7EF0, 0x7F80, 0x7EE0, 0x7EF0, 0x7F10, + 0x7F10, 0x7F70, 0x7EF0, 0x7ED0, 0x7EF0, 0x7EE0, 0x7F70, 0x7EE0, 0x7EC0, 0x7EF0, 0x7F10, 0x7F30, 0x7EE0, 0x7EC0, 0x7F10, 0x7F00, + 0x7F40, 0x7ED0, 0x7EA0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F40, 0x7F00, 0x7F30, 0x7EF0, 0x7F00, + 0x7F40, 0x7F00, 0x7F40, 0x7EF0, 0x7F20, 0x7F20, 0x7F00, 0x7F90, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F70, 0x7EF0, 0x7EF0, 0x7F10, + 0x7F00, 0x7F20, 0x7F10, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F20, + 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F40, + 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F50, 0x7F40, + 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7890, 0x6BB0, 0x5DE0, 0x4F80, 0x3FF0, 0x2FD0, 0x1F70, 0x0DE0, + 0xFB10, 0xE5F0, 0xD170, 0xBCD0, 0xA760, 0x9290, 0x8740, 0x8510, 0x84D0, 0x84D0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8460, 0x8450, + 0x8450, 0x8440, 0x8430, 0x8430, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, + 0x83F0, 0x83E0, 0x83F0, 0x83E0, 0x83D0, 0x8380, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83B0, 0x83E0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, + 0x83C0, 0x83C0, 0x8400, 0x83D0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, + 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8440, 0x8450, 0x8440, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8490, 0x84A0, + 0x84C0, 0x84E0, 0x8540, 0x86E0, 0x9320, 0xA5E0, 0xB910, 0xCC50, 0xDF50, 0xF2E0, 0x0680, 0x19F0, 0x2DB0, 0x4340, 0x5710, 0x6990, + 0x79D0, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7ED0, 0x7EF0, 0x7F00, 0x7EF0, 0x7EF0, 0x7E90, 0x7F00, 0x7F00, 0x7F00, 0x7F00, + 0x7E80, 0x7ED0, 0x7EF0, 0x7F10, 0x7EF0, 0x7E80, 0x7F00, 0x7F20, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F00, 0x7F10, 0x7F10, 0x7EE0, + 0x7EF0, 0x7F00, 0x7F00, 0x7EF0, 0x7EF0, 0x7F30, 0x7F00, 0x7F40, 0x7F10, 0x7EB0, 0x4110, 0x16D0, 0xFCB0, 0xF4A0, 0xFBE0, 0x0CF0, + 0x23F0, 0x3B80, 0x51C0, 0x64B0, 0x72A0, 0x7CA0, 0x7ED0, 0x7F10, 0x7EF0, 0x7F30, 0x7ED0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F30, 0x7C00, + 0x7960, 0x7C50, 0x7EF0, 0x7F20, 0x7F00, 0x7EB0, 0x7F00, 0x7EF0, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F40, 0x7F00, + 0x7F30, 0x7EF0, 0x7F00, 0x7EF0, 0x7F10, 0x7F80, 0x7F00, 0x7F20, 0x7F20, 0x7F20, 0x7F90, 0x7EF0, 0x7F10, 0x7EE0, 0x7EF0, 0x7F70, + 0x7F20, 0x7EF0, 0x7EF0, 0x7F00, 0x7F60, 0x7F10, 0x7EB0, 0x7EB0, 0x7EE0, 0x7F50, 0x7F00, 0x7EA0, 0x7ED0, 0x7ED0, 0x7F30, 0x7F20, + 0x7EC0, 0x7ED0, 0x7EE0, 0x7F10, 0x7F10, 0x7EA0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F00, 0x7F20, 0x7F20, 0x7F10, 0x6390, + 0x36E0, 0x04E0, 0xCE10, 0x9550, 0x84E0, 0x8480, 0x8480, 0x8450, 0x8430, 0x8430, 0x8420, 0x8410, 0x8410, 0x8400, 0x8400, 0x83F0, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8410, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, + 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x8400, 0x8400, 0x83F0, 0x83F0, + 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, + 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, + 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, + 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8410, 0x8400, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, + 0x8430, 0x8440, 0x8440, 0x8450, 0x8450, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x84B0, 0x84C0, + 0x84F0, 0x8540, 0x8670, 0x8D80, 0x9BC0, 0xA8A0, 0xB380, 0xBB50, 0xC0E0, 0xC420, 0xC570, 0xC520, 0xC2E0, 0xC030, 0xBB90, 0xB660, + 0xB0D0, 0xAAB0, 0xA410, 0x9D20, 0x9530, 0x8E50, 0x89D0, 0x87C0, 0x86D0, 0x8690, 0x86D0, 0x87D0, 0x8B00, 0x93B0, 0xA100, 0xAFA0, + 0xBEE0, 0xCE30, 0xDD00, 0xEAE0, 0xF830, 0x0500, 0x1260, 0x2210, 0x3120, 0x42C0, 0x5500, 0x6710, 0x77F0, 0x7F20, 0x7EF0, 0x7EF0, + 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, 0x7F60, 0x7EF0, 0x7EF0, 0x7F00, 0x7F10, 0x7F70, 0x7EE0, 0x7EE0, 0x7ED0, 0x7F10, 0x7F60, + 0x7EE0, 0x7E90, 0x7F20, 0x7F20, 0x6D70, 0x4A30, 0x2330, 0xFB70, 0xD4A0, 0xB0F0, 0x9280, 0x8670, 0x8500, 0x84D0, 0x84C0, 0x84E0, + 0x84B0, 0x84B0, 0x84B0, 0x84D0, 0x84F0, 0x8540, 0x86B0, 0x8F50, 0xA3C0, 0xBA40, 0xD1F0, 0xEBF0, 0x07B0, 0x2650, 0x4370, 0x5EE0, + 0x7660, 0x7EF0, 0x7F30, 0x7F20, 0x7F00, 0x7F80, 0x7F20, 0x7F20, 0x7F10, 0x7EF0, 0x7F60, 0x7EE0, 0x7ED0, 0x7EF0, 0x7EE0, 0x7F50, + 0x7F10, 0x7EC0, 0x7EE0, 0x7ED0, 0x7F10, 0x7F00, 0x7E70, 0x7EC0, 0x7EB0, 0x7EF0, 0x7EF0, 0x7E90, 0x7EE0, 0x7F20, 0x7F10, 0x7F10, + 0x7EA0, 0x7EF0, 0x7F10, 0x7F00, 0x7EE0, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F40, 0x7F40, 0x7F10, 0x7EF0, 0x7EE0, + 0x7F50, 0x7EF0, 0x7F20, 0x7EF0, 0x7EF0, 0x7F60, 0x7F00, 0x7F10, 0x7F10, 0x7EF0, 0x7F60, 0x7EE0, 0x7F00, 0x7EE0, 0x7EF0, 0x7F70, + 0x7EF0, 0x7EB0, 0x7F00, 0x7F10, 0x7F10, 0x7EE0, 0x7E90, 0x7EF0, 0x7EF0, 0x7EF0, 0x7ED0, 0x7EB0, 0x7F00, 0x7F00, 0x7F30, 0x7F00, + 0x7EC0, 0x7F10, 0x7EF0, 0x7F00, 0x7EF0, 0x7F00, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F00, 0x7F10, 0x7F30, 0x7F00, 0x7F10, + 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, + 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F10, 0x53F0, 0x2AD0, 0x01E0, 0xD960, 0xB0B0, 0x8C80, 0x8510, + 0x84B0, 0x8480, 0x8470, 0x8460, 0x8450, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, + 0x8440, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8430, + 0x8430, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8450, 0x8450, 0x8460, 0x8470, 0x8470, 0x8490, 0x84A0, 0x84D0, + 0x8500, 0x8550, 0x8560, 0x84E0, 0x84C0, 0x8490, 0x8480, 0x8480, 0x8490, 0x84B0, 0x94D0, 0xB0B0, 0xCD30, 0xEA60, 0x05E0, 0x1BF0, + 0x28B0, 0x26C0, 0x1340, 0xED10, 0xB420, 0x8570, 0x8480, 0x8450, 0x8430, 0x8410, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, + 0x8400, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x8430, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, + 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, + 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, + 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83D0, 0x83E0, 0x8390, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, + 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8440, 0x8410, 0x8410, 0x8410, 0x8410, 0x8430, 0x8420, 0x8440, + 0x8420, 0x8430, 0x8430, 0x8430, 0x8450, 0x8400, 0x8460, 0x8480, 0x84B0, 0x84D0, 0x85B0, 0x9400, 0xB1E0, 0xCC00, 0xE330, 0xF8A0, + 0x0980, 0x17F0, 0x22A0, 0x2A40, 0x2DF0, 0x2D50, 0x2A20, 0x23E0, 0x1A10, 0x0EE0, 0x0160, 0xF290, 0xE2B0, 0xD230, 0xC180, 0xB1D0, + 0xA330, 0x9680, 0x8DD0, 0x8940, 0x8730, 0x8640, 0x85E0, 0x85B0, 0x85B0, 0x85C0, 0x8610, 0x86C0, 0x8820, 0x8B30, 0x9080, 0x9750, + 0x9E40, 0xA650, 0xAE90, 0xB740, 0xBE40, 0xC370, 0xC540, 0xC480, 0xC140, 0xBD40, 0xBA40, 0xB9E0, 0xBDD0, 0xC7D0, 0xD750, 0xEC50, + 0x0720, 0x2840, 0x4CC0, 0x7180, 0x7F10, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7F00, 0x7F10, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7F20, + 0x7EF0, 0x7ED0, 0x7F80, 0x7F00, 0x7F00, 0x7ED0, 0x7EF0, 0x7F70, 0x7F10, 0x7EF0, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EB0, 0x7EC0, + 0x7EE0, 0x7F30, 0x7F00, 0x7E90, 0x7EB0, 0x7EE0, 0x7EE0, 0x7EF0, 0x7EA0, 0x7EC0, 0x7EF0, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, + 0x7F00, 0x7EE0, 0x7EB0, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7F10, 0x7F10, 0x7F00, 0x7F10, 0x7F30, 0x7EF0, 0x7F00, + 0x7EF0, 0x7F10, 0x7F60, 0x7F00, 0x7F20, 0x7F20, 0x7F00, 0x7F80, 0x7EF0, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F50, 0x7EE0, 0x7ED0, 0x7F10, + 0x7F20, 0x7F50, 0x7ED0, 0x7E90, 0x7F00, 0x7EE0, 0x7F30, 0x7EE0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7EC0, 0x7F10, 0x7E90, + 0x7D90, 0x7B00, 0x7960, 0x7A80, 0x7C30, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7F30, + 0x7EE0, 0x7EF0, 0x7F30, 0x7F10, 0x7F80, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F90, 0x7F00, 0x7F00, 0x7EF0, 0x7EF0, 0x7F70, 0x7EF0, + 0x7F10, 0x7F00, 0x7F00, 0x7F70, 0x7F10, 0x7EB0, 0x7EC0, 0x7ED0, 0x7F30, 0x7EE0, 0x7EA0, 0x7ED0, 0x7EE0, 0x7F20, 0x7F10, 0x7E90, + 0x7EF0, 0x7EE0, 0x7F10, 0x7F10, 0x7E70, 0x7EE0, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F20, + 0x7EF0, 0x7F10, 0x7F10, 0x7EE0, 0x7F50, 0x7F30, 0x7F20, 0x76C0, 0x6BF0, 0x6070, 0x52C0, 0x4360, 0x30F0, 0x1D70, 0x0760, 0xEE80, + 0xD420, 0xB900, 0x9C40, 0x87F0, 0x8500, 0x84C0, 0x84A0, 0x8490, 0x8480, 0x8470, 0x8470, 0x8470, 0x8460, 0x8450, 0x8450, 0x8450, + 0x8450, 0x8450, 0x8440, 0x8430, 0x8450, 0x8440, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8460, 0x8450, 0x8430, 0x8420, 0x8410, + 0x8400, 0x83F0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83F0, 0x8400, 0x8410, 0x8420, 0x8440, 0x8450, 0x8470, + 0x8480, 0x84A0, 0x84D0, 0x8530, 0x88C0, 0xA340, 0xBDA0, 0xD370, 0xE2E0, 0xEC90, 0xF090, 0xF0F0, 0xEF90, 0xEF30, 0xF120, 0xF6A0, + 0xFF50, 0x0BB0, 0x19A0, 0x28F0, 0x3910, 0x4700, 0x5370, 0x5D40, 0x65B0, 0x6D00, 0x73C0, 0x79C0, 0x7DB0, 0x7F00, 0x7EC0, 0x7F10, + 0x7F20, 0x7F00, 0x7EF0, 0x7F10, 0x7F60, 0x7F20, 0x7F20, 0x7F20, 0x7F00, 0x7F50, 0x7EF0, 0x7F20, 0x7EE0, 0x7EF0, 0x7F80, 0x7EE0, + 0x7EF0, 0x7F10, 0x7F20, 0x7F70, 0x7EF0, 0x7ED0, 0x7EF0, 0x7EE0, 0x7F70, 0x7EE0, 0x7EC0, 0x7EF0, 0x7F10, 0x7F30, 0x7EE0, 0x7EC0, + 0x7F10, 0x7F00, 0x7F40, 0x7ED0, 0x7EA0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F40, 0x7F00, 0x7F30, + 0x7EE0, 0x7EF0, 0x7F30, 0x7F00, 0x6D10, 0x4A50, 0x27D0, 0x0770, 0xE920, 0xCC50, 0xB070, 0x9530, 0x8640, 0x84E0, 0x84B0, 0x84A0, + 0x8480, 0x8480, 0x8480, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8470, + 0x8470, 0x8460, 0x8450, 0x8450, 0x8440, 0x8430, 0x8430, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, 0x8440, + 0x8460, 0x8470, 0x84A0, 0x8500, 0x87C0, 0x9FA0, 0xB360, 0xC390, 0xD290, 0xE5A0, 0xFA80, 0x1350, 0x2EB0, 0x4BE0, 0x68F0, 0x7E90, + 0x7F20, 0x7F20, 0x7F10, 0x7F60, 0x7F00, 0x7F00, 0x7F00, 0x7EE0, 0x7F10, 0x7F00, 0x7EF0, 0x7EF0, 0x7F10, 0x7F00, 0x7F20, 0x7F10, + 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7EE0, 0x7F10, 0x7F10, 0x7F20, + 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F20, + 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F40, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F10, 0x7F30, + 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F30, + 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, + 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7F10, + 0x7F30, 0x7F30, 0x7F00, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7EF0, 0x7F20, 0x7F10, 0x7F30, + 0x7F20, 0x7F00, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F20, + 0x7F40, 0x7B30, 0x4570, 0x0FE0, 0xD6C0, 0x9A20, 0x84F0, 0x8480, 0x8450, 0x8440, 0x8420, 0x8410, 0x8400, 0x83F0, 0x83E0, 0x83D0, + 0x8390, 0x83C0, 0x83C0, 0x83E0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, + 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83F0, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8400, 0x8400, + 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8400, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8420, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8460, 0x8460, + 0x8460, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8470, + 0x8470, 0x8480, 0x8490, 0x84A0, 0x84C0, 0x8500, 0x85C0, 0x8B10, 0x9DA0, 0xAD60, 0xBA20, 0xC3D0, 0xCA90, 0xCF20, 0xD190, 0xD460, + 0xD6D0, 0xD8E0, 0xDB60, 0xDCE0, 0xDD30, 0xD8C0, 0xCF20, 0xC050, 0xABE0, 0x9330, 0x8620, 0x84E0, 0x84C0, 0x8490, 0x8480, 0x8470, + 0x8470, 0x8470, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8430, 0x8450, 0x8430, 0x8430, 0x8420, 0x8420, + 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8460, 0x8420, 0x8410, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83E0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83B0, 0x83B0, 0x83B0, + 0x83B0, 0x83B0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x8390, 0x8390, 0x8390, 0x8390, 0x83D0, 0x8390, 0x8390, 0x8390, 0x8390, 0x8380, + 0x8380, 0x8360, 0x8380, 0x8380, 0x8380, 0x8380, 0x8380, 0x8380, 0x8380, 0x8380, 0x8380, 0x8380, 0x8380, 0x8390, 0x8380, 0x8380, + 0x8380, 0x8380, 0x8380, 0x8380, 0x8380, 0x8380, 0x8380, 0x8380, 0x8380, 0x8380, 0x83D0, 0x8380, 0x8380, 0x8380, 0x8380, 0x8380, + 0x8370, 0x8370, 0x8370, 0x8380, 0x8370, 0x8380, 0x8380, 0x8380, 0x8390, 0x8390, 0x8340, 0x83A0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, + 0x83D0, 0x83E0, 0x8440, 0x8400, 0x8410, 0x8430, 0x8450, 0x8470, 0x84A0, 0x8640, 0xC110, 0x02F0, 0x4240, 0x76F0, 0x7F10, 0x7F00, + 0x7EF0, 0x7EF0, 0x7EA0, 0x7EE0, 0x7EF0, 0x7F30, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F10, 0x7EB0, 0x7F00, 0x7EE0, 0x7EF0, + 0x7F10, 0x7F00, 0x7F60, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F50, 0x7EF0, 0x7F00, 0x7EF0, 0x7EF0, 0x7F70, 0x7EF0, 0x7F10, 0x7F00, + 0x7F00, 0x7F80, 0x7F10, 0x7EB0, 0x7EE0, 0x7ED0, 0x7F30, 0x7EE0, 0x7ED0, 0x7ED0, 0x7EE0, 0x7F40, 0x7F10, 0x7E90, 0x7EB0, 0x7ED0, + 0x7F10, 0x7F00, 0x7E70, 0x7EC0, 0x7EF0, 0x7F10, 0x7F20, 0x7EC0, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7EA0, 0x7F00, 0x7F00, 0x7EF0, + 0x7F10, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F30, 0x7EF0, 0x7F00, 0x7F10, 0x7EF0, 0x7F40, 0x7EF0, 0x7F10, 0x7F00, + 0x7F00, 0x7F80, 0x7EF0, 0x7F20, 0x7F10, 0x7EF0, 0x7F60, 0x7EE0, 0x7ED0, 0x7F10, 0x7F20, 0x7F40, 0x7EF0, 0x7EB0, 0x7F00, 0x7F10, + 0x7F30, 0x7EB0, 0x7E70, 0x7EF0, 0x7F10, 0x7F20, 0x7ED0, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, 0x7F20, 0x7EF0, 0x7F00, + 0x7F00, 0x7EC0, 0x7F30, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7F70, 0x7EF0, 0x7F20, 0x7F00, + 0x7EF0, 0x7F80, 0x7F00, 0x7F10, 0x7EF0, 0x7EF0, 0x7F60, 0x7EF0, 0x7ED0, 0x7EE0, 0x7EE0, 0x7F70, 0x7F10, 0x7EB0, 0x7EE0, 0x7ED0, + 0x7F10, 0x7F00, 0x7E90, 0x7EB0, 0x7EB0, 0x7EF0, 0x7EF0, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, + 0x7F00, 0x7EC0, 0x7F30, 0x7F20, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F40, 0x7F10, 0x7F00, 0x7EE0, 0x7F50, 0x7EF0, 0x7F20, 0x7EF0, + 0x7EF0, 0x7F50, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F60, 0x7EF0, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F70, 0x7EF0, 0x7EA0, 0x7F00, 0x7F10, + 0x7F60, 0x7EE0, 0x7E90, 0x7EF0, 0x7EF0, 0x7EF0, 0x7EF0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F30, 0x7EA0, 0x7EC0, 0x7F10, 0x7EF0, 0x7F00, + 0x7F20, 0x7E90, 0x7F10, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F50, 0x7EF0, 0x7F00, 0x7EF0, + 0x7EF0, 0x7F80, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F80, 0x7F10, 0x7EB0, 0x7EE0, 0x7ED0, 0x7F50, 0x7EE0, 0x7EE0, 0x7ED0, 0x7EE0, + 0x7F30, 0x7F00, 0x7E90, 0x7EB0, 0x7EE0, 0x7F10, 0x7F10, 0x7E70, 0x7EC0, 0x7F00, 0x7F00, 0x7F10, 0x7F00, 0x7F00, 0x7F10, 0x7F10, + 0x7F10, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F00, + 0x7F10, 0x7F10, 0x7F30, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F10, + 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F00, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F00, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, + 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F40, 0x7F10, + 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F30, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, + 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F10, + 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F20, + 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F30, + 0x7F10, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F00, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7EF0, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F00, + 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7EF0, 0x7F30, 0x7F30, 0x7C20, 0x6A70, 0x59D0, 0x48F0, 0x3860, 0x2820, 0x1790, 0x0800, 0xF960, + 0xEB60, 0xDE10, 0xD170, 0xC550, 0xB9E0, 0xAF40, 0xA610, 0x9D20, 0x9130, 0x8780, 0x8500, 0x84B0, 0x8490, 0x8480, 0x8470, 0x8460, + 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8460, 0x8460, 0x8450, 0x8450, 0x8440, 0x8440, 0x8430, 0x8430, 0x8420, 0x8410, 0x8450, + 0x83F0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83D0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, + 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8410, 0x8410, 0x8420, 0x8430, 0x8420, 0x8450, 0x8460, 0x8480, 0x84B0, + 0x8510, 0x8E10, 0xBAA0, 0xE380, 0x09C0, 0x3040, 0x5110, 0x6D30, 0x7EE0, 0x7EE0, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F00, 0x7F60, + 0x7F20, 0x7F10, 0x7F10, 0x7EF0, 0x7F40, 0x7EF0, 0x7F10, 0x7EE0, 0x7EC0, 0x7F30, 0x7F00, 0x7F40, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, + 0x7F00, 0x7F20, 0x7F10, 0x7F80, 0x7F00, 0x7F40, 0x7F10, 0x7EF0, 0x7F60, 0x7F00, 0x7F00, 0x7F00, 0x7EF0, 0x7F30, 0x7EE0, 0x7EC0, + 0x7ED0, 0x7EE0, 0x7F50, 0x7F10, 0x7EB0, 0x7EE0, 0x7ED0, 0x7F10, 0x7F00, 0x7E70, 0x7EC0, 0x7EB0, 0x7EF0, 0x7EF0, 0x7EB0, 0x7F00, + 0x7F00, 0x7F10, 0x7F10, 0x7EA0, 0x7E90, 0x7F10, 0x7F10, 0x7EE0, 0x7EC0, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F40, 0x7F40, + 0x7F10, 0x7F10, 0x7EE0, 0x7F50, 0x7EF0, 0x7F20, 0x7EF0, 0x7F10, 0x7F60, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7EE0, 0x7F00, + 0x7EE0, 0x7EF0, 0x7F70, 0x7F00, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7EE0, 0x7E90, 0x7EF0, 0x7EE0, 0x7EF0, 0x7ED0, 0x7EB0, 0x7F00, + 0x7F00, 0x7F30, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F00, 0x7ED0, 0x7F30, 0x7EF0, 0x7EF0, 0x7F20, 0x7F00, 0x7F40, 0x7F10, + 0x7F10, 0x7EF0, 0x7EE0, 0x7F30, 0x7EF0, 0x7F00, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7ED0, 0x7EF0, 0x7F00, 0x7F90, 0x7EF0, 0x7EE0, + 0x7EE0, 0x7ED0, 0x7F50, 0x7F10, 0x7F70, 0x7EF0, 0x7EF0, 0x7EF0, 0x7EF0, 0x7F70, 0x7F10, 0x7EB0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, + 0x7EA0, 0x7EC0, 0x7F00, 0x7F30, 0x7F20, 0x7E90, 0x7EB0, 0x7EA0, 0x7EE0, 0x7EF0, 0x7EB0, 0x7F20, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, + 0x7F10, 0x7F10, 0x7F00, 0x7F00, 0x7EF0, 0x7F20, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7F10, 0x7F10, 0x7EF0, 0x7F10, 0x7F50, + 0x7EF0, 0x7F20, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7ED0, 0x7F10, 0x7F20, 0x7F80, 0x7EF0, 0x7EB0, 0x7F20, 0x7EF0, 0x7F30, 0x7EE0, + 0x7EC0, 0x7F10, 0x7F10, 0x7F40, 0x7ED0, 0x7E90, 0x7F00, 0x7EE0, 0x7EF0, 0x7EE0, 0x7E70, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F00, + 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, 0x7F10, 0x7F30, 0x7F20, 0x7F90, 0x7F20, 0x7F40, 0x7F40, 0x7F10, 0x7F70, + 0x7EE0, 0x7EF0, 0x7EF0, 0x7F00, 0x7F80, 0x7C10, 0x6C20, 0x5CC0, 0x4AD0, 0x37F0, 0x24B0, 0x1060, 0xFC40, 0xE470, 0xCDE0, 0xB780, + 0xA000, 0x8BB0, 0x8580, 0x84D0, 0x84B0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8450, 0x8450, 0x8410, 0x8430, 0x8450, 0x8430, 0x8410, + 0x8410, 0x8400, 0x8400, 0x83F0, 0x8400, 0x83F0, 0x83E0, 0x83E0, 0x83F0, 0x83D0, 0x83D0, 0x8380, 0x83C0, 0x83C0, 0x83C0, 0x8340, + 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83B0, 0x83B0, 0x8350, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83B0, 0x83B0, + 0x83B0, 0x8340, 0x83C0, 0x83C0, 0x83E0, 0x83C0, 0x83C0, 0x83C0, 0x83F0, 0x83C0, 0x83D0, 0x83C0, 0x83F0, 0x83B0, 0x83C0, 0x8380, + 0x83B0, 0x83B0, 0x83B0, 0x8350, 0x83B0, 0x83B0, 0x83C0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83B0, 0x83C0, 0x83C0, 0x83B0, + 0x83C0, 0x83F0, 0x83C0, 0x83F0, 0x83C0, 0x83C0, 0x83C0, 0x83B0, 0x83E0, 0x83C0, 0x83B0, 0x83B0, 0x83E0, 0x83B0, 0x83B0, 0x83B0, + 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x8400, 0x83F0, + 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, 0x8470, 0x8480, 0x8460, 0x8470, 0x8480, 0x8490, 0x84A0, + 0x84D0, 0x84E0, 0x8520, 0x8600, 0x88C0, 0x8F10, 0x96B0, 0x9E60, 0xA510, 0xACF0, 0xB640, 0xC1D0, 0xD020, 0xE220, 0xF520, 0x0940, + 0x1E90, 0x35E0, 0x4D00, 0x6370, 0x77D0, 0x7EA0, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7E90, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7EB0, + 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7EC0, 0x7F40, 0x7EF0, 0x7F20, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F10, 0x7F10, + 0x7F00, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F40, 0x7F20, 0x7F20, 0x7F30, 0x7F10, 0x7F30, 0x7F20, 0x7EF0, 0x7F20, 0x7F00, + 0x6E30, 0x5BF0, 0x4870, 0x34E0, 0x2090, 0x0C20, 0xF7A0, 0xE2C0, 0xCE90, 0xB910, 0xA500, 0x9200, 0x8770, 0x8540, 0x84E0, 0x84B0, + 0x84A0, 0x8490, 0x8470, 0x8470, 0x8460, 0x8450, 0x8440, 0x8430, 0x8430, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8400, 0x83F0, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8410, 0x8400, 0x8410, 0x8400, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8430, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x8400, 0x83F0, 0x83F0, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8430, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, 0x8370, 0x83E0, 0x83E0, 0x83E0, + 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83B0, + 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x8400, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83B0, 0x83B0, 0x83B0, 0x8350, + 0x83A0, 0x83A0, 0x83A0, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8380, 0x83A0, 0x83A0, 0x83A0, 0x83B0, + 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83B0, 0x83C0, 0x83B0, 0x83B0, 0x83B0, + 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, + 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, + 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83D0, 0x83D0, 0x83C0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, + 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, + 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x8400, 0x8430, 0x8410, 0x8410, 0x8400, 0x8420, 0x8420, + 0x8430, 0x8420, 0x8440, 0x8440, 0x8450, 0x8450, 0x8460, 0x8470, 0x8460, 0x8480, 0x8490, 0x84B0, 0x84C0, 0x84F0, 0x8550, 0x8640, + 0x8850, 0x8BC0, 0x8F70, 0x9160, 0x9220, 0x9110, 0x8ED0, 0x8BF0, 0x8910, 0x86F0, 0x85B0, 0x8520, 0x84F0, 0x84C0, 0x84D0, 0x84A0, + 0x8490, 0x8490, 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8440, 0x8470, 0x8440, 0x8440, 0x8430, + 0x8430, 0x8430, 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8420, 0x8430, 0x8440, 0x8460, + 0x8470, 0x8480, 0x84C0, 0x8500, 0x8750, 0xA400, 0xC9D0, 0xF3D0, 0x1FE0, 0x4BE0, 0x7200, 0x7F30, 0x7EF0, 0x7F10, 0x7F10, 0x7EF0, + 0x7F60, 0x7ED0, 0x7EF0, 0x7F00, 0x7F00, 0x7F50, 0x7F00, 0x7EE0, 0x7F10, 0x7F10, 0x7F30, 0x7EC0, 0x7E90, 0x7F10, 0x7F20, 0x7F30, + 0x7ED0, 0x7EB0, 0x7F20, 0x7F10, 0x7F10, 0x7EF0, 0x7F50, 0x7EE0, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7EE0, 0x7E90, 0x7F10, 0x7F20, + 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7EE0, 0x7F10, 0x7F00, 0x7EC0, 0x7F30, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F70, 0x7EE0, 0x7F10, + 0x7F10, 0x7EE0, 0x7F70, 0x7EF0, 0x7F20, 0x7F00, 0x7F00, 0x7F50, 0x7F00, 0x7F00, 0x7EF0, 0x7EF0, 0x7F60, 0x7EE0, 0x7EC0, 0x7ED0, + 0x7EE0, 0x7F50, 0x7F10, 0x7EA0, 0x7EC0, 0x7ED0, 0x7F10, 0x7F00, 0x7E70, 0x7ED0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7E90, 0x7F00, 0x7F20, + 0x7F10, 0x7F10, 0x7EB0, 0x7F00, 0x7F10, 0x7F00, 0x7F20, 0x7EC0, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, + 0x7EF0, 0x7EE0, 0x7F40, 0x7EF0, 0x7F10, 0x7EF0, 0x7EF0, 0x7F30, 0x7F00, 0x7F00, 0x7EF0, 0x7EF0, 0x7F60, 0x7ED0, 0x7EF0, 0x7EE0, + 0x7EF0, 0x7F50, 0x7EE0, 0x7EA0, 0x7F00, 0x7EF0, 0x7F10, 0x7EE0, 0x7E90, 0x7EF0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7EA0, 0x7F20, 0x7F00, + 0x7F20, 0x7F20, 0x7EC0, 0x7F10, 0x7EF0, 0x7F00, 0x7F00, 0x7EF0, 0x7F60, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F60, 0x7F10, 0x7F10, + 0x7EF0, 0x7EF0, 0x7F70, 0x7EE0, 0x7F10, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7EF0, 0x7EF0, 0x7F00, 0x7F80, 0x7F10, 0x7EE0, 0x7EE0, + 0x7ED0, 0x7F30, 0x7F20, 0x7EC0, 0x7EF0, 0x7EE0, 0x7F40, 0x7F10, 0x7E90, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7E80, 0x7EC0, 0x7F00, + 0x7F20, 0x7F20, 0x7EC0, 0x7F10, 0x7F00, 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F50, 0x7EF0, 0x7F20, + 0x7EF0, 0x7F10, 0x7F30, 0x7EF0, 0x7EF0, 0x7F10, 0x7F20, 0x7F60, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F70, 0x7EE0, 0x7EC0, 0x7EF0, + 0x7F10, 0x7F60, 0x7EF0, 0x7EB0, 0x7F00, 0x7F00, 0x7EF0, 0x7EB0, 0x7E70, 0x7EE0, 0x7EF0, 0x7F30, 0x7EC0, 0x7E90, 0x7F10, 0x7F00, + 0x7F00, 0x7F10, 0x7EB0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F30, 0x7F00, 0x7F10, + 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F10, 0x7EF0, 0x7EF0, 0x7F90, 0x7F00, 0x7F40, 0x7EF0, 0x7EF0, 0x7F70, 0x7EE0, 0x7F10, 0x7EF0, + 0x7EE0, 0x7F70, 0x7F10, 0x7EB0, 0x7EE0, 0x7ED0, 0x7F10, 0x7F20, 0x7EC0, 0x7ED0, 0x7EB0, 0x7F00, 0x7EF0, 0x7E90, 0x7F00, 0x7F20, + 0x7F10, 0x7F20, 0x7EA0, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F40, 0x7F00, 0x7470, 0x5D80, 0x4500, 0x2C60, 0x1380, 0xFA40, + 0xE270, 0xCAA0, 0xB1E0, 0x9CA0, 0x8A90, 0x8580, 0x8530, 0x84C0, 0x84A0, 0x8490, 0x84B0, 0x8470, 0x8460, 0x8460, 0x8480, 0x8450, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, 0x8420, 0x8420, + 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8490, 0x8450, 0x8460, 0x8470, 0x8480, 0x8490, 0x84B0, 0x84D0, 0x84E0, 0x8500, 0x84E0, + 0x8510, 0x8530, 0x8500, 0x8500, 0x8500, 0x84F0, 0x84D0, 0x84C0, 0x84A0, 0x8490, 0x8480, 0x8480, 0x8470, 0x8470, 0x8470, 0x8470, + 0x8470, 0x8470, 0x8480, 0x8470, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84B0, 0x84C0, + 0x84C0, 0x84C0, 0x84C0, 0x84D0, 0x84C0, 0x84C0, 0x84C0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8470, 0x8460, 0x8460, 0x8450, + 0x8460, 0x8430, 0x8430, 0x8420, 0x8410, 0x8410, 0x8400, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83B0, + 0x83B0, 0x83B0, 0x83A0, 0x83A0, 0x8390, 0x8390, 0x8390, 0x8380, 0x83B0, 0x8380, 0x8380, 0x8370, 0x8370, 0x8370, 0x8370, 0x8370, + 0x8370, 0x8370, 0x8360, 0x8350, 0x8360, 0x8360, 0x8380, 0x8360, 0x8360, 0x8370, 0x8370, 0x8360, 0x8370, 0x8370, 0x8370, 0x8380, + 0x8380, 0x8380, 0x83B0, 0x8390, 0x8390, 0x8390, 0x8390, 0x83A0, 0x83A0, 0x83A0, 0x83B0, 0x83B0, 0x83D0, 0x83B0, 0x83C0, 0x83C0, + 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83B0, 0x83B0, 0x83A0, 0x83A0, 0x8390, 0x8380, + 0x8380, 0x8380, 0x8370, 0x8360, 0x8360, 0x8360, 0x8350, 0x8350, 0x8350, 0x8350, 0x8340, 0x8340, 0x8340, 0x8340, 0x8340, 0x8340, + 0x8340, 0x8340, 0x8340, 0x8340, 0x8350, 0x8350, 0x8350, 0x8350, 0x8350, 0x8360, 0x8360, 0x8360, 0x8360, 0x8360, 0x8360, 0x8360, + 0x8360, 0x8360, 0x8360, 0x8360, 0x8360, 0x8360, 0x8360, 0x8360, 0x8360, 0x8360, 0x8360, 0x8360, 0x8370, 0x8370, 0x8370, 0x8380, + 0x8380, 0x8380, 0x8380, 0x8390, 0x8390, 0x83A0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, + 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8410, 0x8420, 0x8430, 0x8430, 0x8450, 0x8460, 0x8480, 0x84A0, 0x84F0, 0x8840, 0xB250, 0xE0E0, + 0x1110, 0x4450, 0x7500, 0x7F20, 0x7EF0, 0x7EA0, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7EC0, 0x7F20, 0x7EF0, 0x7EE0, 0x7EF0, 0x7ED0, + 0x7F30, 0x7F00, 0x7F10, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7F10, 0x7EF0, 0x7EF0, 0x7F80, 0x7F00, 0x7F20, 0x7EF0, 0x7ED0, 0x7F60, + 0x7F00, 0x7EF0, 0x7EB0, 0x7EE0, 0x7F50, 0x7EF0, 0x7EB0, 0x7EE0, 0x7ED0, 0x7F30, 0x7F00, 0x7EA0, 0x7EB0, 0x7EB0, 0x7EE0, 0x7EF0, + 0x7E90, 0x7EA0, 0x7EC0, 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F00, 0x7EE0, 0x7E90, 0x7EE0, 0x7F00, 0x7EF0, 0x7EF0, 0x7F00, + 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7F00, 0x7F30, 0x7EF0, 0x7F00, 0x7EF0, 0x7EF0, 0x7F30, 0x7F00, 0x7F10, 0x7F00, 0x7F00, 0x7F50, + 0x7ED0, 0x7EF0, 0x7EE0, 0x7EE0, 0x7F50, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F60, 0x7EE0, 0x7E90, 0x7F00, 0x7EE0, 0x7F50, 0x7EB0, + 0x7E70, 0x7EE0, 0x7EF0, 0x7F20, 0x7F00, 0x7EC0, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7EB0, 0x7F00, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, + 0x7EF0, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7EF0, 0x7F00, 0x7EF0, 0x7EF0, 0x7F60, 0x7EF0, 0x7F10, 0x7F10, 0x7F00, 0x7F80, + 0x7EF0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F60, 0x7EE0, 0x7ED0, 0x7EF0, 0x7F00, 0x7F40, 0x7EF0, 0x7F60, 0x7EF0, 0x7EF0, 0x7F00, 0x7F00, + 0x7F50, 0x7F00, 0x7EA0, 0x7ED0, 0x7ED0, 0x7F30, 0x7F20, 0x7EC0, 0x6BD0, 0x3AC0, 0x0FD0, 0xE790, 0xC2E0, 0xA170, 0x8960, 0x8510, + 0x84C0, 0x84A0, 0x8490, 0x8480, 0x8470, 0x8470, 0x8460, 0x8470, 0x8400, 0x8460, 0x8460, 0x8460, 0x8440, 0x8450, 0x8460, 0x8460, + 0x8460, 0x8470, 0x8470, 0x8470, 0x84A0, 0x84B0, 0x84F0, 0x85F0, 0x93E0, 0xB320, 0xD0C0, 0xEE40, 0x09A0, 0x2480, 0x3D00, 0x5380, + 0x6790, 0x78F0, 0x7F20, 0x7EF0, 0x7EF0, 0x7F80, 0x7EF0, 0x7F10, 0x7F10, 0x7F00, 0x7F80, 0x7F10, 0x7EF0, 0x7EE0, 0x7EE0, 0x7F70, + 0x7F00, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F60, 0x7F20, 0x7E90, 0x7EB0, 0x7EE0, 0x7F30, 0x7F10, 0x7E70, 0x7EC0, 0x7ED0, 0x7EF0, 0x6860, + 0x4A40, 0x24A0, 0xFCE0, 0xD100, 0xA410, 0x8670, 0x84C0, 0x8490, 0x8470, 0x8460, 0x8450, 0x8470, 0x8440, 0x8430, 0x8420, 0x8420, + 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8420, 0x8420, 0x8420, 0x8430, 0x8450, 0x8460, 0x8470, 0x8480, 0x8490, 0x84A0, 0x84B0, 0x84D0, + 0x84F0, 0x8520, 0x8580, 0x85C0, 0x85C0, 0x8580, 0x8560, 0x8500, 0x84D0, 0x84D0, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8470, + 0x8490, 0x8490, 0x8460, 0x8460, 0x8480, 0x8450, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x83E0, 0x8440, 0x8430, 0x8440, 0x8400, + 0x8430, 0x8430, 0x8460, 0x8420, 0x8450, 0x8430, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8470, 0x8450, 0x8450, + 0x8460, 0x8470, 0x8490, 0x84B0, 0x8540, 0x9770, 0xC440, 0xED20, 0x0FC0, 0x2AD0, 0x3CC0, 0x4580, 0x4800, 0x4610, 0x4830, 0x50A0, + 0x6250, 0x7970, 0x7F20, 0x7F00, 0x7EF0, 0x7F50, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F60, 0x7F00, 0x7F10, 0x7EF0, 0x7EE0, 0x7F50, + 0x7EF0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F70, 0x7F00, 0x7EC0, 0x7EF0, 0x7F00, 0x7F70, 0x7ED0, 0x7E90, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F00, + 0x7EA0, 0x7EF0, 0x7F00, 0x7F20, 0x7F00, 0x7E90, 0x7F10, 0x7EE0, 0x7EF0, 0x7F10, 0x7EA0, 0x7EF0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, + 0x7F50, 0x7EF0, 0x7F00, 0x7F10, 0x7EF0, 0x7F60, 0x7EE0, 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7F10, 0x7F20, 0x7F00, 0x7EF0, 0x7F70, + 0x7EE0, 0x7EE0, 0x7ED0, 0x7EE0, 0x7F60, 0x7EF0, 0x7EE0, 0x7EE0, 0x7EE0, 0x7F50, 0x7EF0, 0x7E70, 0x7EC0, 0x7ED0, 0x7EF0, 0x7EF0, + 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F20, 0x7F20, + 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, + 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, + 0x7F20, 0x7F30, 0x7F30, 0x7F00, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F00, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7EF0, 0x7F20, 0x7F20, + 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F40, 0x7F30, 0x7F30, 0x7AC0, 0x3B30, 0x00F0, 0xC340, 0x89C0, + 0x84B0, 0x8470, 0x8450, 0x8460, 0x8420, 0x8400, 0x83F0, 0x83F0, 0x83D0, 0x83C0, 0x83C0, 0x83B0, 0x83A0, 0x8390, 0x8390, 0x8390, + 0x8390, 0x8390, 0x83A0, 0x83A0, 0x83B0, 0x83B0, 0x83E0, 0x83C0, 0x83D0, 0x8370, 0x83C0, 0x83C0, 0x83B0, 0x83B0, 0x83A0, 0x83A0, + 0x8390, 0x8390, 0x8380, 0x8380, 0x8380, 0x8380, 0x8380, 0x8380, 0x8380, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, + 0x8390, 0x8390, 0x8390, 0x83A0, 0x83A0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83E0, + 0x83B0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83C0, 0x83D0, 0x83D0, 0x83F0, + 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8400, 0x8400, 0x8410, 0x8420, 0x8420, 0x8430, 0x8440, 0x8450, 0x8460, 0x8470, 0x8490, 0x84D0, 0x86E0, 0xB6C0, 0xEFC0, 0x29C0, + 0x6360, 0x7F00, 0x7F00, 0x7F40, 0x7EF0, 0x7F10, 0x7F20, 0x7EE0, 0x7F80, 0x7F10, 0x7F00, 0x7EF0, 0x7F10, 0x7F60, 0x7F00, 0x7F10, + 0x7EF0, 0x7EE0, 0x7F40, 0x7EF0, 0x7EF0, 0x7EE0, 0x7ED0, 0x7F70, 0x7F00, 0x7EC0, 0x7ED0, 0x7EB0, 0x7F60, 0x7F10, 0x7E90, 0x7EE0, + 0x7EC0, 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, 0x7EE0, 0x7F00, 0x7F00, 0x7E90, 0x7F10, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x6960, 0x33C0, + 0xFCD0, 0xC740, 0x9470, 0x84F0, 0x84B0, 0x8490, 0x8480, 0x8470, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, + 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84A0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, + 0x8450, 0x8450, 0x8450, 0x8460, 0x8470, 0x8470, 0x8490, 0x84A0, 0x84D0, 0x8510, 0x85E0, 0x87D0, 0x8890, 0x8750, 0x85D0, 0x8550, + 0x8520, 0x8540, 0x85C0, 0x8850, 0x9810, 0xAB50, 0xBF30, 0xD3A0, 0xE990, 0x0090, 0x1740, 0x2E40, 0x4190, 0x5260, 0x5EC0, 0x66D0, + 0x6E30, 0x75A0, 0x7DA0, 0x7EF0, 0x7EF0, 0x7F00, 0x7EF0, 0x7F80, 0x7F20, 0x7EE0, 0x7EF0, 0x7ED0, 0x7F30, 0x7EF0, 0x7E90, 0x7EB0, + 0x7EE0, 0x7EF0, 0x7F10, 0x7EA0, 0x7EC0, 0x7F00, 0x7F10, 0x7F10, 0x7E90, 0x7ED0, 0x7F00, 0x7EE0, 0x7EF0, 0x7EB0, 0x7F20, 0x7F20, + 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7EE0, 0x7EF0, 0x7F50, 0x7F20, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7F10, 0x7F10, + 0x7F00, 0x7EE0, 0x7F50, 0x7EF0, 0x7EF0, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7ED0, 0x7F10, 0x7F00, 0x7F80, 0x7EF0, 0x7EB0, 0x7EE0, + 0x7EF0, 0x7F30, 0x7EE0, 0x7D20, 0x5710, 0x2BF0, 0x0070, 0xD200, 0xA150, 0x8570, 0x84D0, 0x8470, 0x83F0, 0x8400, 0x83F0, 0x83F0, + 0x8410, 0x83D0, 0x83C0, 0x8360, 0x83B0, 0x83A0, 0x8390, 0x8350, 0x8380, 0x83B0, 0x8370, 0x8370, 0x8360, 0x8360, 0x8350, 0x8350, + 0x8350, 0x8350, 0x8350, 0x8340, 0x8350, 0x8350, 0x8350, 0x8350, 0x8350, 0x8340, 0x8350, 0x8350, 0x8340, 0x8350, 0x8350, 0x8350, + 0x8350, 0x8360, 0x8360, 0x8360, 0x8370, 0x8350, 0x8380, 0x8380, 0x8390, 0x8390, 0x83A0, 0x83B0, 0x83A0, 0x83C0, 0x83D0, 0x83E0, + 0x83E0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, + 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, + 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83E0, 0x83F0, 0x83F0, 0x8400, + 0x8410, 0x8410, 0x8430, 0x8440, 0x8450, 0x84D0, 0x85F0, 0xA270, 0xCC20, 0xF470, 0x1B70, 0x4120, 0x6470, 0x7E90, 0x7EB0, 0x7F00, + 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7EF0, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7F50, 0x7F10, + 0x7F20, 0x7F00, 0x7F00, 0x7F60, 0x7EF0, 0x7F10, 0x7EF0, 0x7EE0, 0x7F70, 0x7EF0, 0x7EB0, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7EC0, + 0x7EF0, 0x7EF0, 0x7F20, 0x7ED0, 0x7EA0, 0x7EE0, 0x7EF0, 0x7F30, 0x7F00, 0x7EC0, 0x7F10, 0x7EF0, 0x7F00, 0x7EF0, 0x7E90, 0x7F00, + 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F30, 0x7EF0, 0x7EF0, 0x7EF0, 0x7EF0, 0x7F80, 0x7EF0, + 0x7F10, 0x7F20, 0x7F00, 0x7F80, 0x7F10, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F70, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F00, 0x7F60, 0x7F10, 0x7E90, + 0x7EB0, 0x7EF0, 0x4D90, 0x0FF0, 0xD240, 0x9590, 0x84E0, 0x8490, 0x8460, 0x8490, 0x8430, 0x8420, 0x8410, 0x8400, 0x8400, 0x83F0, + 0x83D0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, + 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83F0, 0x83F0, 0x8400, 0x8420, 0x8420, + 0x8440, 0x8460, 0x8480, 0x84C0, 0x8700, 0xC400, 0x0640, 0x4DB0, 0x7EB0, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, + 0x7EF0, 0x7EF0, 0x7F10, 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7EE0, 0x7F10, 0x7EF0, 0x7F00, 0x7F00, 0x7EF0, 0x7F80, 0x7F00, + 0x7F20, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7F10, + 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, + 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, + 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7F30, + 0x7F30, 0x7F20, 0x7EF0, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7EF0, 0x7F20, 0x7F10, 0x7F10, + 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F40, 0x7F20, 0x7F30, 0x7F30, 0x7F20, + 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F20, + 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F30, + 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, + 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, + 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7EE0, 0x7F10, 0x7F10, 0x7F30, 0x7F20, 0x7EF0, 0x7F30, 0x7F20, 0x7F20, + 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F60, 0x7EF0, 0x7EB0, 0x7F10, 0x7F40, 0x7F10, 0x7ED0, 0x7E80, 0x7F40, 0x7F10, + 0x7EB0, 0x7E70, 0x7E60, 0x7EF0, 0x7EF0, 0x7F20, 0x7ED0, 0x7E90, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7EC0, 0x7F40, 0x7EF0, 0x7EE0, + 0x7EF0, 0x7ED0, 0x7F30, 0x7F00, 0x7F20, 0x7F10, 0x7EF0, 0x7F30, 0x7EF0, 0x7F10, 0x7EF0, 0x7EE0, 0x7F80, 0x7F10, 0x7F20, 0x7F00, + 0x7EF0, 0x7F60, 0x7F00, 0x7F10, 0x7F10, 0x7EE0, 0x7F40, 0x7EF0, 0x7EB0, 0x7EF0, 0x7ED0, 0x7F30, 0x7F20, 0x7EC0, 0x7ED0, 0x7EB0, + 0x7960, 0x5D40, 0x4F90, 0x4DB0, 0x5260, 0x5840, 0x5D90, 0x5E00, 0x5B40, 0x54D0, 0x4C30, 0x4460, 0x3C40, 0x3680, 0x3120, 0x2A20, + 0x22F0, 0x1A40, 0x10A0, 0x05F0, 0xFB90, 0xF240, 0xEAE0, 0xE570, 0xE190, 0xDE30, 0xDBF0, 0xD890, 0xD510, 0xD0C0, 0xCAD0, 0xC5D0, + 0xC0C0, 0xBCB0, 0xB9D0, 0xB810, 0xB810, 0xB8B0, 0xB9B0, 0xBB60, 0xBB90, 0xB980, 0xB4B0, 0xAC20, 0x9FD0, 0x90C0, 0x8750, 0x8520, + 0x84D0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84C0, 0x8530, 0x8CB0, 0xAD10, 0xC270, 0xC760, 0xBAC0, 0x9E70, 0x8660, + 0x84C0, 0x8490, 0x8470, 0x8460, 0x8460, 0x8460, 0x8450, 0x8460, 0x8470, 0x8470, 0x8490, 0x84B0, 0x84F0, 0x8580, 0x8700, 0x8940, + 0x8C00, 0x9150, 0x9D30, 0xAFB0, 0xC8F0, 0xE260, 0xFB00, 0x10C0, 0x2230, 0x30B0, 0x3C40, 0x4650, 0x50B0, 0x5B00, 0x6490, 0x6D10, + 0x7470, 0x7B20, 0x7E60, 0x7ED0, 0x7F00, 0x7F20, 0x7F10, 0x7EB0, 0x7EE0, 0x7F10, 0x7F10, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F00, + 0x7EF0, 0x7EC0, 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F60, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7F50, 0x7F20, 0x7F20, 0x7F10, + 0x7F10, 0x7F60, 0x7F10, 0x7F10, 0x7F00, 0x7EE0, 0x7F70, 0x7EF0, 0x7EE0, 0x7F00, 0x7F10, 0x7F80, 0x7F00, 0x7ED0, 0x6A90, 0x2140, + 0x1530, 0x0EC0, 0x0A70, 0x08C0, 0x0870, 0x0A70, 0x0CA0, 0x0F50, 0x1300, 0x1660, 0x1B40, 0x1F70, 0x2230, 0x23A0, 0x2180, 0x1CB0, + 0x13B0, 0x05D0, 0xF690, 0xE5B0, 0xD3B0, 0xC080, 0xAC50, 0x9820, 0x88F0, 0x8550, 0x84E0, 0x84B0, 0x84C0, 0x8490, 0x8480, 0x8480, + 0x8470, 0x8470, 0x8470, 0x8490, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84D0, 0x8500, + 0x85B0, 0x8950, 0x9A70, 0xAE60, 0xC020, 0xD1D0, 0xDF30, 0xE920, 0xF060, 0xF350, 0xF390, 0xEFF0, 0xE8A0, 0xDE60, 0xD050, 0xC2F0, + 0xB6D0, 0xAEE0, 0xACE0, 0xB0A0, 0xB980, 0xC680, 0xD590, 0xE810, 0xF900, 0x0A60, 0x1AC0, 0x2910, 0x35F0, 0x3F60, 0x4600, 0x4990, + 0x4940, 0x46D0, 0x3FD0, 0x3560, 0x26B0, 0x1400, 0xFEC0, 0xE590, 0xC980, 0xA8B0, 0x8C30, 0x8520, 0x84C0, 0x84A0, 0x8490, 0x8480, + 0x8470, 0x8470, 0x8410, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8480, 0x8490, 0x84A0, 0x84C0, 0x84F0, 0x85E0, 0x8FE0, + 0xA8A0, 0xBEA0, 0xD1F0, 0xE200, 0xF0E0, 0xFB50, 0x0350, 0x0A00, 0x0E80, 0x10D0, 0x1170, 0x0EE0, 0x0B80, 0x0510, 0xFDC0, 0xF5F0, + 0xEC50, 0xE2B0, 0xD890, 0xCDE0, 0xC2F0, 0xB7E0, 0xABC0, 0x9FB0, 0x9300, 0x8A30, 0x8660, 0x8540, 0x84F0, 0x84D0, 0x84E0, 0x84B0, + 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84D0, 0x8500, 0x8570, 0x8830, 0x9EC0, 0xBA90, 0xD830, 0xF620, 0x1360, 0x2E40, 0x4430, 0x5700, + 0x6460, 0x6E90, 0x7600, 0x7A80, 0x7E00, 0x7F10, 0x7F00, 0x7F00, 0x7EC0, 0x7F10, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, + 0x7F10, 0x7F00, 0x7EE0, 0x7F10, 0x7F00, 0x7EF0, 0x7F10, 0x7EB0, 0x7F20, 0x7F10, 0x6F50, 0x5080, 0x2A10, 0x0230, 0xD520, 0xA540, + 0x8690, 0x84C0, 0x84A0, 0x8490, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, 0x8470, 0x8470, 0x8470, 0x8470, 0x8490, 0x8460, 0x8460, + 0x8470, 0x8470, 0x8470, 0x8480, 0x8490, 0x8490, 0x84B0, 0x84D0, 0x8530, 0x8AE0, 0xB430, 0xE0F0, 0x1160, 0x4170, 0x6DC0, 0x7ED0, + 0x7F30, 0x7F20, 0x7E90, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, + 0x7EF0, 0x7EF0, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7F10, 0x7F10, 0x7EF0, 0x7F10, 0x7F30, 0x7EF0, 0x7F00, 0x7EF0, + 0x7F10, 0x7F60, 0x7F00, 0x7ED0, 0x7F00, 0x7F00, 0x7F90, 0x7EF0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F30, 0x7EE0, 0x7ED0, 0x7F00, 0x7F20, + 0x7F50, 0x7ED0, 0x7E90, 0x7F00, 0x7F10, 0x7EE0, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, 0x7F40, + 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F50, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7F30, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, + 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, + 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, + 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, + 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F10, 0x7F20, 0x7F30, 0x7F20, 0x7F20, + 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, + 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F50, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F40, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, + 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, + 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, + 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F10, + 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F30, 0x7F60, 0x7F40, 0x7F20, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7EF0, 0x7EE0, 0x7EF0, + 0x7EF0, 0x6120, 0x30C0, 0xFD30, 0xC530, 0x8CB0, 0x84C0, 0x8480, 0x8450, 0x8440, 0x8420, 0x8410, 0x8400, 0x83F0, 0x83F0, 0x83E0, + 0x83E0, 0x83D0, 0x83D0, 0x8390, 0x83D0, 0x83D0, 0x83D0, 0x83B0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83A0, 0x83B0, + 0x83A0, 0x83A0, 0x8380, 0x8390, 0x83C0, 0x8380, 0x83A0, 0x8380, 0x8380, 0x8390, 0x83A0, 0x8370, 0x8380, 0x8310, 0x8380, 0x8380, + 0x83B0, 0x8390, 0x8390, 0x83A0, 0x83B0, 0x83B0, 0x83B0, 0x83F0, 0x83D0, 0x83D0, 0x83D0, 0x8370, 0x83E0, 0x83E0, 0x83F0, 0x83F0, + 0x8430, 0x8410, 0x8410, 0x8420, 0x8430, 0x8440, 0x8450, 0x8460, 0x8470, 0x8490, 0x84A0, 0x84D0, 0x8520, 0x86C0, 0x9370, 0xA810, + 0xBAA0, 0xCC60, 0xDF40, 0xEF30, 0xFF20, 0x0D50, 0x1B00, 0x27F0, 0x3300, 0x3E60, 0x48F0, 0x5360, 0x5D40, 0x6600, 0x6FB0, 0x7860, + 0x7EE0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F60, 0x7F20, 0x7F40, 0x7F10, 0x7F00, 0x7F30, 0x7EE0, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F80, + 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7ED0, 0x7EF0, 0x7EE0, 0x7F50, 0x7ED0, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7EE0, + 0x7EC0, 0x7F10, 0x7EF0, 0x7EF0, 0x7EF0, 0x7EC0, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, 0x7F10, 0x7F20, 0x7EF0, + 0x7F80, 0x7EF0, 0x7EF0, 0x7F10, 0x7F20, 0x7F70, 0x7F00, 0x7F10, 0x7EF0, 0x7EE0, 0x7F90, 0x7EF0, 0x7F00, 0x7EE0, 0x7EF0, 0x7F70, + 0x7F00, 0x7EE0, 0x7ED0, 0x7F00, 0x7F60, 0x7F10, 0x7EB0, 0x7EE0, 0x7EC0, 0x7EF0, 0x7F10, 0x7EA0, 0x7ED0, 0x7ED0, 0x7F20, 0x7F20, + 0x7E90, 0x7EB0, 0x7F00, 0x7EF0, 0x7EF0, 0x7E70, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F10, 0x7EB0, + 0x7F20, 0x7EB0, 0x7ED0, 0x7ED0, 0x7F00, 0x7F00, 0x7E90, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, + 0x7EE0, 0x7F40, 0x7F30, 0x7F20, 0x7EF0, 0x7F10, 0x7F60, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F20, 0x7EE0, 0x7EF0, + 0x7F70, 0x7F00, 0x7F00, 0x7F10, 0x7ED0, 0x78F0, 0x7140, 0x6910, 0x61E0, 0x59F0, 0x51A0, 0x48F0, 0x4010, 0x3760, 0x2E00, 0x23F0, + 0x1AE0, 0x1140, 0x0810, 0xFEA0, 0xF560, 0xED00, 0xE4D0, 0xDDD0, 0xD6E0, 0xD010, 0xC9A0, 0xC310, 0xBCE0, 0xB6D0, 0xB1B0, 0xADA0, + 0xAAE0, 0xA970, 0xA890, 0xA830, 0xA870, 0xA8E0, 0xA920, 0xA9E0, 0xAA90, 0xAB80, 0xACD0, 0xADD0, 0xAFB0, 0xB150, 0xB2A0, 0xB3C0, + 0xB450, 0xB540, 0xB560, 0xB530, 0xB3D0, 0xB1F0, 0xB030, 0xAD80, 0xAAF0, 0xA820, 0xA5D0, 0xA450, 0xA320, 0xA260, 0xA200, 0xA220, + 0xA360, 0xA530, 0xA900, 0xAD80, 0xB3F0, 0xBCE0, 0xC600, 0xD140, 0xDBF0, 0xE7D0, 0xF4C0, 0x01C0, 0x0FC0, 0x1EB0, 0x2E40, 0x3D80, + 0x4BB0, 0x59E0, 0x6660, 0x7140, 0x7AF0, 0x7F00, 0x7F60, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7EF0, 0x7F00, 0x7EF0, 0x7F10, + 0x7F50, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7F90, 0x7D70, 0x7560, 0x6DA0, 0x6430, 0x5AB0, 0x5120, 0x4690, 0x3D10, 0x32C0, 0x27D0, + 0x1E10, 0x1400, 0x09F0, 0x0180, 0xFA30, 0xF4E0, 0xF020, 0xED40, 0xEBA0, 0xEAB0, 0xEB00, 0xEBB0, 0xED40, 0xEF20, 0xF0D0, 0xF3B0, + 0xF620, 0xF970, 0xFCF0, 0xFF50, 0x0140, 0x0040, 0xFD10, 0xF760, 0xEF50, 0xE630, 0xDC90, 0xD2E0, 0xCAC0, 0xC3E0, 0xBF40, 0xBD00, + 0xBDA0, 0xC190, 0xC890, 0xD2D0, 0xDE90, 0xEB10, 0xF740, 0xFFB0, 0x0500, 0x06C0, 0x0490, 0x00D0, 0xFA80, 0xF320, 0xE9F0, 0xDDF0, + 0xD040, 0xBF80, 0xABF0, 0x9560, 0x8720, 0x8500, 0x84B0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8450, 0x8440, 0x8440, 0x8430, 0x8430, + 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, + 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, + 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8410, 0x8430, 0x8420, 0x8420, 0x8420, 0x8420, 0x8450, 0x8430, 0x8430, 0x8440, 0x8430, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8430, 0x8440, 0x8430, 0x8420, 0x8420, 0x8420, 0x8420, 0x8410, + 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x8400, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83D0, + 0x83C0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, + 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, + 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, + 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8410, 0x8410, + 0x8410, 0x8420, 0x8430, 0x8430, 0x8440, 0x8450, 0x8440, 0x8460, 0x8470, 0x8480, 0x8490, 0x84B0, 0x84D0, 0x8500, 0x8590, 0x8820, + 0x9220, 0xA120, 0xAD70, 0xB760, 0xBF60, 0xC570, 0xC8D0, 0xC9C0, 0xC9C0, 0xC830, 0xC610, 0xC470, 0xC2B0, 0xC180, 0xBF30, 0xBC50, + 0xB710, 0xAF70, 0xA570, 0x9860, 0x8BB0, 0x8600, 0x84F0, 0x84C0, 0x84A0, 0x8480, 0x8470, 0x8460, 0x8450, 0x8440, 0x8440, 0x8430, + 0x8450, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8440, 0x8450, 0x8460, 0x8460, 0x84A0, 0x8470, 0x8490, 0x8480, 0x8490, 0x8490, + 0x84A0, 0x84B0, 0x84B0, 0x84D0, 0x84E0, 0x8500, 0x8560, 0x8690, 0x8B00, 0x9820, 0xA6A0, 0xB4D0, 0xC190, 0xCD90, 0xD850, 0xE1B0, + 0xEAD0, 0xF230, 0xF990, 0x0170, 0x09C0, 0x12E0, 0x1C90, 0x26D0, 0x3120, 0x3CF0, 0x47F0, 0x53A0, 0x5E70, 0x6970, 0x72F0, 0x7B40, + 0x7F00, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F90, 0x7F30, 0x7F00, 0x7F40, 0x7F30, 0x7F50, 0x7F40, 0x7EE0, + 0x7F10, 0x7F10, 0x7EF0, 0x7EF0, 0x7EB0, 0x7470, 0x6620, 0x5590, 0x4370, 0x2E30, 0x1800, 0xFEC0, 0xE330, 0xC380, 0xA440, 0x8970, + 0x84F0, 0x84B0, 0x8490, 0x8470, 0x8460, 0x8450, 0x8440, 0x8430, 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x8400, 0x8400, 0x83F0, + 0x83F0, 0x83E0, 0x83E0, 0x83D0, 0x83C0, 0x83C0, 0x83B0, 0x83A0, 0x8390, 0x8390, 0x8380, 0x8370, 0x8360, 0x8360, 0x8350, 0x8350, + 0x8350, 0x8340, 0x8340, 0x8340, 0x8340, 0x8340, 0x8340, 0x8340, 0x8340, 0x8340, 0x8340, 0x8340, 0x8340, 0x8340, 0x8340, 0x8350, + 0x8350, 0x8350, 0x8350, 0x8360, 0x8360, 0x8360, 0x8360, 0x8370, 0x8370, 0x8370, 0x8370, 0x8370, 0x8370, 0x8380, 0x8380, 0x8380, + 0x8380, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x83A0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83D0, 0x83E0, 0x83E0, 0x83F0, 0x8400, + 0x8410, 0x8420, 0x8430, 0x8440, 0x8450, 0x8470, 0x8480, 0x84A0, 0x84C0, 0x8510, 0x8700, 0x9830, 0xAD10, 0xBE50, 0xCD10, 0xD900, + 0xE450, 0xEDF0, 0xF6E0, 0xFF80, 0x0850, 0x1260, 0x1BA0, 0x2680, 0x3180, 0x3EA0, 0x4C90, 0x5B30, 0x6B70, 0x7A00, 0x7F20, 0x7F10, + 0x7F20, 0x7F20, 0x7ED0, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F30, 0x7EF0, 0x7F10, 0x7EF0, 0x7EF0, 0x7F50, 0x7F00, 0x7F20, + 0x7F00, 0x7F10, 0x7F70, 0x7EE0, 0x7F10, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, + 0x7F10, 0x7F20, 0x7EE0, 0x7E90, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7E60, 0x68E0, 0x5310, 0x3D10, 0x2870, 0x1500, 0x0290, 0xF120, + 0xE1A0, 0xD4D0, 0xC9A0, 0xC030, 0xB820, 0xB150, 0xAC80, 0xA860, 0xA580, 0xA3B0, 0xA260, 0xA1A0, 0xA100, 0xA080, 0x9FF0, 0x9E60, + 0x9C10, 0x9860, 0x9340, 0x8560, 0x8500, 0x84E0, 0x84C0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84C0, 0x84D0, 0x84F0, 0x8550, 0x8800, + 0x9DE0, 0xBB00, 0xD950, 0xF7B0, 0x15A0, 0x31C0, 0x4CC0, 0x67A0, 0x7BC0, 0x7EF0, 0x7ED0, 0x7F00, 0x7EE0, 0x7F30, 0x7F10, 0x7E70, + 0x7ED0, 0x7EB0, 0x7F10, 0x7EF0, 0x7E90, 0x7ED0, 0x7F00, 0x7F00, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, + 0x7F10, 0x7F20, 0x7EF0, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7F10, 0x7EE0, 0x7EF0, 0x7F50, 0x7F10, + 0x7F20, 0x7F10, 0x7F10, 0x7F70, 0x7EF0, 0x7F10, 0x7EF0, 0x7F20, 0x7F70, 0x7EF0, 0x7EB0, 0x7F00, 0x7F10, 0x7F70, 0x7F00, 0x7EC0, + 0x7EF0, 0x7EF0, 0x7F20, 0x7ED0, 0x7E90, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7EA0, 0x7F00, 0x7F10, 0x7F00, 0x7F00, 0x7EC0, 0x7F00, + 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F50, 0x7EF0, 0x7F00, 0x7EF0, 0x7EF0, 0x7F80, 0x7F00, + 0x7F10, 0x7F20, 0x7F00, 0x7F80, 0x7EF0, 0x7EF0, 0x7EE0, 0x7EE0, 0x7F50, 0x7F10, 0x7EE0, 0x7ED0, 0x7EF0, 0x7F60, 0x7F00, 0x7E90, + 0x7EB0, 0x7EB0, 0x7EF0, 0x7F00, 0x7E70, 0x7EC0, 0x7ED0, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F10, 0x7E90, 0x7EE0, + 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F20, 0x7F00, 0x7ED0, 0x7F30, 0x7EF0, 0x7F00, 0x7EF0, 0x7F10, 0x7F40, 0x7EF0, + 0x7F20, 0x7F00, 0x7F00, 0x7F50, 0x7EF0, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F30, 0x7EE0, 0x7ED0, 0x7F10, 0x7F00, 0x7F60, 0x7ED0, 0x7E90, + 0x7F00, 0x7F10, 0x7F30, 0x7EB0, 0x7E70, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, 0x7F20, + 0x7EF0, 0x7F10, 0x7EE0, 0x7EC0, 0x7F10, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7EE0, 0x7F10, 0x7F10, 0x7EE0, 0x7F60, 0x7EF0, + 0x7F20, 0x7F00, 0x7F00, 0x7F50, 0x7F00, 0x7F10, 0x7EF0, 0x7EF0, 0x7F60, 0x7EE0, 0x7ED0, 0x7EF0, 0x7EE0, 0x7F70, 0x7F10, 0x7EE0, + 0x7EE0, 0x7ED0, 0x7F30, 0x7EF0, 0x7E70, 0x7EC0, 0x7EB0, 0x7EF0, 0x7EF0, 0x7E90, 0x7EE0, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, 0x7ED0, + 0x7F10, 0x7F00, 0x7EE0, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F40, 0x7F40, 0x6780, 0x4630, 0x28A0, 0x0CA0, 0xEF90, + 0xCF00, 0xA5A0, 0x86C0, 0x84C0, 0x8480, 0x8470, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8470, + 0x8480, 0x84D0, 0x8FB0, 0xEAA0, 0x3190, 0x6730, 0x7EB0, 0x7F20, 0x7ED0, 0x7EB0, 0x7F20, 0x7F10, 0x7EB0, 0x7EF0, 0x7EF0, 0x7F10, + 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x63C0, 0x3AB0, 0x0D30, 0xDFD0, 0xB580, 0x8F10, 0x8500, 0x84B0, 0x84B0, 0x8470, + 0x8450, 0x8440, 0x8430, 0x8420, 0x8410, 0x8400, 0x8400, 0x83F0, 0x83E0, 0x83C0, 0x83C0, 0x83A0, 0x8390, 0x8390, 0x8390, 0x8390, + 0x8390, 0x8390, 0x8390, 0x8380, 0x8380, 0x8380, 0x8390, 0x8390, 0x8390, 0x83A0, 0x83A0, 0x83A0, 0x83E0, 0x83A0, 0x8390, 0x8390, + 0x8390, 0x8390, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83E0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, + 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8390, 0x83F0, 0x83F0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8410, 0x8420, + 0x8450, 0x8440, 0x8450, 0x8460, 0x8480, 0x8490, 0x84B0, 0x84E0, 0x8650, 0xA820, 0xDE50, 0x1F90, 0x6820, 0x7F10, 0x7F30, 0x7F20, + 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, + 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F20, + 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7EF0, + 0x7F20, 0x7F00, 0x7F20, 0x7F20, 0x7F20, 0x7F20, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F20, + 0x7F00, 0x7F10, 0x7F30, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F30, 0x7F20, 0x7EA0, 0x7F10, 0x7F20, 0x7F40, + 0x7EF0, 0x7E90, 0x7EF0, 0x7EF0, 0x7EF0, 0x7EF0, 0x7E80, 0x7EA0, 0x7ED0, 0x7F20, 0x7F00, 0x7EC0, 0x7F00, 0x7EB0, 0x7F20, 0x7F20, + 0x7F00, 0x7F20, 0x7EF0, 0x7F10, 0x7F30, 0x7F20, 0x7F60, 0x7EF0, 0x7F10, 0x7F00, 0x7F10, 0x7F30, 0x7EE0, 0x7EF0, 0x7ED0, 0x7EF0, + 0x7F60, 0x7F00, 0x7F10, 0x7F20, 0x7F00, 0x7F70, 0x7F10, 0x7EB0, 0x7EF0, 0x7ED0, 0x7F10, 0x7EE0, 0x7EC0, 0x7EF0, 0x7EE0, 0x7F20, + 0x7F10, 0x7E90, 0x7EF0, 0x7EE0, 0x7F10, 0x7F00, 0x7E70, 0x7ED0, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F10, 0x7F20, 0x7F10, 0x7F10, + 0x7F00, 0x7F20, 0x7EF0, 0x7F10, 0x7F10, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F30, 0x7EF0, 0x7EF0, 0x7EF0, 0x7EE0, + 0x7F50, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7F70, 0x7EB0, 0x7A40, 0x7550, 0x7060, 0x6B70, 0x6680, 0x6000, 0x5920, 0x5100, 0x4810, + 0x3F50, 0x3580, 0x2CF0, 0x2470, 0x1BE0, 0x1420, 0x0CF0, 0x0610, 0xFF90, 0xF9A0, 0xF3C0, 0xEE70, 0xEAE0, 0xE780, 0xE410, 0xE1A0, + 0xDF40, 0xDDC0, 0xDC90, 0xDB60, 0xDAF0, 0xDAC0, 0xDAE0, 0xDB00, 0xDC20, 0xDD90, 0xDF10, 0xE170, 0xE480, 0xE770, 0xEB70, 0xEDC0, + 0xF030, 0xF2D0, 0xF500, 0xF780, 0xFAB0, 0xFDA0, 0x0020, 0x01B0, 0x0310, 0x0360, 0x0350, 0x0310, 0x0130, 0xFF60, 0xFC80, 0xF930, + 0xF560, 0xF0A0, 0xEB50, 0xE530, 0xDEC0, 0xD860, 0xD140, 0xC900, 0xC020, 0xB6A0, 0xAD60, 0xA360, 0x9930, 0x8FE0, 0x8940, 0x8640, + 0x8540, 0x84F0, 0x84D0, 0x84C0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8480, 0x8480, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, + 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8490, 0x84A0, 0x84B0, 0x84D0, 0x84F0, 0x8530, + 0x85A0, 0x85F0, 0x8600, 0x85D0, 0x85D0, 0xB680, 0xCEF0, 0xE410, 0xF290, 0xFBF0, 0x0370, 0x0E60, 0x1E00, 0x2E30, 0x3760, 0x2AD0, + 0xFE30, 0xA990, 0x84B0, 0x8460, 0x8440, 0x8420, 0x8410, 0x8400, 0x83F0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83E0, 0x83F0, 0x8400, + 0x8420, 0x8440, 0x8460, 0x8470, 0x8480, 0x8490, 0x84A0, 0x84B0, 0x84E0, 0x8520, 0x8520, 0x84E0, 0x84A0, 0x8470, 0x8460, 0x8440, + 0x8430, 0x8420, 0x8420, 0x8410, 0x8410, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, + 0x83E0, 0x83E0, 0x83D0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, + 0x83E0, 0x83D0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, + 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, + 0x83A0, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8350, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8390, 0x8330, 0x8390, 0x8390, + 0x8390, 0x8390, 0x8390, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83B0, 0x83B0, 0x83A0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x8370, + 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83A0, 0x83A0, 0x8370, 0x83A0, 0x83A0, 0x83A0, 0x8390, 0x8390, + 0x8390, 0x83C0, 0x83B0, 0x8380, 0x8380, 0x8390, 0x8380, 0x8370, 0x8370, 0x8350, 0x8360, 0x8360, 0x8370, 0x8350, 0x8350, 0x8350, + 0x8360, 0x8340, 0x8340, 0x8340, 0x8350, 0x8340, 0x8340, 0x8370, 0x8360, 0x8340, 0x8340, 0x8380, 0x8350, 0x8350, 0x8350, 0x8380, + 0x8350, 0x8360, 0x8380, 0x8370, 0x8380, 0x8390, 0x8390, 0x8390, 0x83A0, 0x83D0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, + 0x8390, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8410, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8420, 0x8430, + 0x8430, 0x8440, 0x8450, 0x8460, 0x8470, 0x8490, 0x84A0, 0x84D0, 0x8520, 0x8670, 0x8F20, 0xA190, 0xB330, 0xC370, 0xD2E0, 0xE080, + 0xECF0, 0xF7F0, 0x0410, 0x0F20, 0x1C20, 0x2A40, 0x3950, 0x4890, 0x56A0, 0x6410, 0x7080, 0x7C60, 0x7EF0, 0x7EF0, 0x7F00, 0x7F00, + 0x7F70, 0x7F10, 0x7EB0, 0x7EC0, 0x7ED0, 0x7F30, 0x7F00, 0x7EA0, 0x7ED0, 0x7EE0, 0x7F20, 0x7F20, 0x7E90, 0x7EE0, 0x7EE0, 0x7F10, + 0x7F10, 0x7E70, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7E90, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F00, 0x7EF0, 0x7F20, 0x7F20, + 0x7F10, 0x7F10, 0x7F10, 0x7C00, 0x6F50, 0x6410, 0x59B0, 0x5020, 0x46F0, 0x3E30, 0x3580, 0x2D20, 0x2620, 0x2190, 0x21B0, 0x27D0, + 0x3590, 0x4C30, 0x69F0, 0x7EF0, 0x7F30, 0x7F00, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F00, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F40, + 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F50, 0x7F30, + 0x7F20, 0x7F20, 0x7F30, 0x7F40, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, + 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F10, + 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F10, 0x48C0, 0x16C0, 0xEEC0, 0xD730, 0xD1D0, 0xDED0, 0xFA00, + 0x20F0, 0x4740, 0x6880, 0x7E50, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F30, + 0x7F10, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F00, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F00, + 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F20, + 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7560, 0x6310, 0x4E30, 0x3670, 0x1D20, 0x02A0, 0xE730, 0xCC50, 0xAF20, + 0x9450, 0x8690, 0x84E0, 0x84C0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8450, 0x8440, 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, + 0x8460, 0x8430, 0x8440, 0x8490, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8490, 0x8450, 0x8450, 0x8460, 0x8460, 0x8470, + 0x8470, 0x8480, 0x84B0, 0x84A0, 0x84B0, 0x84C0, 0x84E0, 0x8520, 0x85F0, 0x8C10, 0xA380, 0xBDB0, 0xDA90, 0xF5B0, 0x0FE0, 0x27C0, + 0x3D50, 0x5030, 0x5F70, 0x6CA0, 0x7610, 0x7DE0, 0x7EF0, 0x7F10, 0x7F00, 0x7EA0, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7E90, 0x7F30, + 0x7EF0, 0x7EF0, 0x7F10, 0x7F00, 0x7F20, 0x7D40, 0x7590, 0x6E20, 0x66C0, 0x5F80, 0x5870, 0x5030, 0x4920, 0x4210, 0x3B90, 0x35E0, + 0x3080, 0x2BF0, 0x2740, 0x2180, 0x1A10, 0x0FB0, 0x0130, 0xEF70, 0xDAC0, 0xC380, 0xAEC0, 0x9D00, 0x8F30, 0x8870, 0x8630, 0x85B0, + 0x8510, 0x84F0, 0x84C0, 0x84C0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84C0, 0x84C0, 0x84D0, 0x84F0, + 0x8510, 0x8530, 0x8580, 0x8610, 0x8730, 0x8990, 0x8CB0, 0x90D0, 0x9420, 0x9770, 0x9B30, 0x9F30, 0xA510, 0xACD0, 0xB630, 0xC250, + 0xD080, 0xE060, 0xF160, 0x0450, 0x1990, 0x2FF0, 0x49D0, 0x6130, 0x76F0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F60, 0x7ED0, 0x7EE0, + 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7ED0, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, 0x7F00, + 0x7EF0, 0x7F00, 0x7F00, 0x7EC0, 0x7F20, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7F50, 0x7F00, + 0x7F20, 0x7F00, 0x7EF0, 0x7F70, 0x7F00, 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, 0x7EF0, 0x7ED0, 0x7EE0, 0x7ED0, 0x7F60, 0x7F00, 0x7EC0, + 0x7ED0, 0x7ED0, 0x7EF0, 0x7F00, 0x7E90, 0x7EB0, 0x7EC0, 0x7EF0, 0x7F10, 0x7EA0, 0x7EE0, 0x7F00, 0x7F10, 0x7F00, 0x7E90, 0x7ED0, + 0x7F00, 0x7EE0, 0x7EF0, 0x7EC0, 0x7F20, 0x7F20, 0x7F10, 0x7EE0, 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F00, 0x7EE0, 0x7EC0, + 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7EF0, 0x7F40, 0x7F20, 0x7F10, 0x7EF0, 0x7EE0, 0x7F40, 0x7EF0, 0x7F10, 0x7F00, 0x7EF0, 0x7F50, + 0x7F00, 0x7F10, 0x7EF0, 0x7EF0, 0x7F60, 0x7ED0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F50, 0x7EF0, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7EE0, + 0x7E90, 0x7EF0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7EF0, 0x7F00, 0x7F00, 0x7EE0, + 0x7F50, 0x7F00, 0x7F10, 0x7F20, 0x7F20, 0x7F60, 0x7F10, 0x7F10, 0x7EF0, 0x7EE0, 0x7F80, 0x7EF0, 0x7F00, 0x7EF0, 0x7F10, 0x7F70, + 0x7F00, 0x7DD0, 0x3C90, 0xFB60, 0xB160, 0x8580, 0x8490, 0x8470, 0x8450, 0x8440, 0x8440, 0x8440, 0x8450, 0x8470, 0x8490, 0x84F0, + 0x9370, 0xD410, 0x0D20, 0x4250, 0x7200, 0x7EA0, 0x7ED0, 0x7F10, 0x7F20, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7EA0, + 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7F30, 0x7EF0, 0x7EF0, 0x7EF0, 0x7F10, 0x7F60, + 0x7F00, 0x7F20, 0x7F00, 0x7F00, 0x7F90, 0x7EF0, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F30, 0x7EE0, 0x7ED0, 0x7F10, 0x7F00, 0x7F40, 0x7ED0, + 0x7E90, 0x7EF0, 0x7EE0, 0x7F30, 0x7EE0, 0x7EA0, 0x7ED0, 0x7F10, 0x7F20, 0x7F20, 0x7E90, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F00, + 0x7F20, 0x7EF0, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F00, 0x7F40, 0x7F40, 0x7F10, 0x7F70, 0x7EE0, 0x7EF0, 0x7F10, 0x7EF0, 0x7F80, + 0x7F10, 0x7F20, 0x7F00, 0x7A10, 0x6F90, 0x64F0, 0x5920, 0x4C30, 0x3FB0, 0x32C0, 0x25C0, 0x18C0, 0x0CC0, 0x01C0, 0xF830, 0xF0D0, + 0xEBC0, 0xEA10, 0xEB80, 0xEF50, 0xF770, 0x0040, 0x0C10, 0x18A0, 0x2660, 0x36F0, 0x45B0, 0x54E0, 0x63D0, 0x7110, 0x7C30, 0x7EC0, + 0x7F40, 0x7F10, 0x7F20, 0x7EF0, 0x7F00, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F00, 0x7F60, 0x7F10, 0x7F20, 0x7F00, 0x7EF0, 0x7F50, + 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F60, 0x7F00, 0x7F10, 0x7F00, 0x7EE0, 0x7F70, 0x7EF0, 0x7EB0, 0x7F00, 0x7F10, 0x7F70, 0x7F00, + 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, 0x7E90, 0x7EE0, 0x7EF0, 0x7F10, 0x7F10, 0x7EA0, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7E90, + 0x7F10, 0x7EF0, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, 0x7F00, 0x7F10, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F90, + 0x7F20, 0x7F10, 0x7F20, 0x7F00, 0x7F80, 0x7F10, 0x7EF0, 0x7EE0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F20, 0x7F10, + 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F10, 0x7F20, + 0x7EF0, 0x7F10, 0x7F00, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F30, + 0x7F30, 0x7EE0, 0x5370, 0x2A50, 0x02D0, 0xE320, 0xC800, 0xAFF0, 0x9B90, 0x8BE0, 0x8630, 0x8540, 0x84E0, 0x84B0, 0x84A0, 0x8490, + 0x8480, 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8440, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8440, + 0x8440, 0x8440, 0x8440, 0x8470, 0x8440, 0x8440, 0x8450, 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8400, 0x8440, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, 0x8410, 0x8400, 0x8400, + 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83E0, 0x83E0, 0x83F0, + 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x83F0, + 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, + 0x83D0, 0x83E0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83E0, 0x8390, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, + 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8470, 0x8490, + 0x8490, 0x8480, 0x8480, 0x8440, 0x84A0, 0x84A0, 0x84C0, 0x84D0, 0x84F0, 0x8530, 0x85D0, 0x8840, 0x9210, 0xA0C0, 0xB000, 0xC030, + 0xF970, 0x0860, 0x1820, 0x27C0, 0x3700, 0x4740, 0x5600, 0x6530, 0x7400, 0x7E10, 0x7F00, 0x7EE0, 0x7F30, 0x7F30, 0x7F20, 0x7F40, + 0x7F10, 0x7F40, 0x7EF0, 0x7F20, 0x7F40, 0x7F00, 0x7F10, 0x7EF0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F60, 0x7EF0, 0x7EF0, 0x7F00, 0x7F20, + 0x7F60, 0x7ED0, 0x7EB0, 0x7F00, 0x7F10, 0x7F30, 0x7EE0, 0x7E90, 0x7EF0, 0x7F10, 0x7F20, 0x7F10, 0x7EB0, 0x7F00, 0x7F10, 0x7F10, + 0x7F10, 0x7EA0, 0x7F10, 0x7EF0, 0x7F20, 0x7F00, 0x7EC0, 0x7F30, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F60, 0x7EE0, 0x7F10, 0x7F20, + 0x7EF0, 0x7F80, 0x7F10, 0x7F20, 0x7F10, 0x7ED0, 0x7F70, 0x7F00, 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, 0x7EF0, 0x7EE0, 0x7EE0, 0x7EE0, + 0x7F70, 0x7F20, 0x7EC0, 0x7ED0, 0x7EB0, 0x7F30, 0x7EF0, 0x7E90, 0x7ED0, 0x7EC0, 0x7EF0, 0x7F10, 0x7EA0, 0x7EE0, 0x7F10, 0x7F10, + 0x7F00, 0x7EC0, 0x7EF0, 0x7F00, 0x7EF0, 0x7EF0, 0x7F00, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7EE0, + 0x7EF0, 0x7F70, 0x7F00, 0x7F20, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F10, 0x7F00, 0x7EE0, 0x7F50, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F10, + 0x7F70, 0x7F00, 0x7ED0, 0x7F10, 0x7F00, 0x7F30, 0x7EF0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F30, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F40, + 0x7F00, 0x7EB0, 0x7F00, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F30, 0x7F00, 0x7F20, 0x7EF0, + 0x7F10, 0x7F40, 0x7EF0, 0x7F30, 0x7F30, 0x7F00, 0x7F90, 0x7F10, 0x7F10, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7F90, 0x7730, 0x6600, + 0x5650, 0x47A0, 0x3AE0, 0x3050, 0x2730, 0x1FA0, 0x17E0, 0x0F40, 0x0570, 0xF960, 0xEC70, 0xDE40, 0xCF70, 0xC120, 0xB3A0, 0xA740, + 0x9CC0, 0x9190, 0x8A40, 0x8660, 0x8530, 0x84E0, 0x84C0, 0x84A0, 0x8490, 0x8480, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, + 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, 0x8410, 0x8410, + 0x8410, 0x8410, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, + 0x83E0, 0x83E0, 0x83E0, 0x83D0, 0x83E0, 0x83E0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8410, + 0x8420, 0x8430, 0x8430, 0x8440, 0x8450, 0x8460, 0x8470, 0x8490, 0x84A0, 0x84E0, 0x8560, 0x88B0, 0x9A70, 0xACC0, 0xBD40, 0xCB60, + 0xD830, 0xE2A0, 0xEBF0, 0xF360, 0xF980, 0xFED0, 0x0300, 0x0620, 0x08C0, 0x0A30, 0x0C30, 0x0DE0, 0x0ED0, 0x1010, 0x1080, 0x11D0, + 0x11D0, 0x1110, 0x10F0, 0x1000, 0x0F10, 0x0D70, 0x0BE0, 0x0BB0, 0x0AE0, 0x0AC0, 0x0A60, 0x09C0, 0x08F0, 0x0740, 0x0510, 0x0230, + 0xFE60, 0xFA40, 0xF600, 0xF150, 0xEC30, 0xE5E0, 0xDF30, 0xD880, 0xD160, 0xC9D0, 0xC250, 0xBAE0, 0xB2C0, 0xAAB0, 0xA290, 0x99C0, + 0x9250, 0x8C50, 0x8880, 0x8680, 0x8590, 0x8530, 0x8500, 0x84E0, 0x84D0, 0x84B0, 0x84A0, 0x84A0, 0x8490, 0x8480, 0x8480, 0x8460, + 0x8450, 0x8440, 0x8430, 0x8420, 0x8410, 0x8410, 0x8400, 0x8400, 0x83F0, 0x8410, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, + 0x83C0, 0x83E0, 0x83C0, 0x83C0, 0x83D0, 0x83C0, 0x83D0, 0x83F0, 0x8400, 0x83D0, 0x83E0, 0x8390, 0x83E0, 0x83F0, 0x8400, 0x83F0, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, + 0x8420, 0x8420, 0x8430, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, + 0x8450, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8450, + 0x8450, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83D0, + 0x83C0, 0x83B0, 0x83B0, 0x83B0, 0x83A0, 0x83A0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83D0, 0x83D0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, + 0x8420, 0x8400, 0x8410, 0x8420, 0x8420, 0x8430, 0x8440, 0x8450, 0x8450, 0x8460, 0x8470, 0x8480, 0x8480, 0x8480, 0x8480, 0x8490, + 0x8490, 0x8490, 0x8490, 0x8490, 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8450, 0x8440, 0x8440, 0x8430, 0x8430, 0x8420, 0x8410, + 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, + 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, + 0x8430, 0x8430, 0x8460, 0x8440, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, + 0x8450, 0x8460, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8480, 0x8470, 0x84A0, + 0x84B0, 0x84D0, 0x8510, 0x8620, 0x9000, 0xA780, 0xBE40, 0xD390, 0xE950, 0xFC10, 0x0C70, 0x1C40, 0x2AE0, 0x37E0, 0x43B0, 0x4EA0, + 0x58C0, 0x6150, 0x6860, 0x6DD0, 0x7280, 0x7610, 0x78B0, 0x7B20, 0x7C40, 0x7D50, 0x7DC0, 0x7E10, 0x7E50, 0x7E90, 0x7EA0, 0x7EC0, + 0x7EB0, 0x7EB0, 0x7E70, 0x7E40, 0x7DF0, 0x7D20, 0x7CA0, 0x7C30, 0x7C30, 0x7C90, 0x7D40, 0x7E40, 0x7F00, 0x7F20, 0x7F20, 0x7EF0, + 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, + 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F00, 0x7F50, 0x7F30, 0x7EF0, 0x7EF0, 0x7EE0, 0x7F30, 0x7F20, 0x7F00, 0x7F00, 0x7EB0, + 0x7F00, 0x7ED0, 0x7F10, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F60, 0x7F00, 0x7ED0, 0x7EF0, 0x7F00, 0x7F40, + 0x7EF0, 0x7EB0, 0x7EF0, 0x7EF0, 0x7F30, 0x7F20, 0x7EC0, 0x7F40, 0x7F10, 0x7F20, 0x7EE0, 0x7E90, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F10, + 0x7EB0, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7C10, 0x71B0, 0x67E0, 0x5F80, 0x56F0, 0x4FE0, 0x49E0, 0x4450, 0x4090, 0x3D60, + 0x3A80, 0x3830, 0x35B0, 0x33E0, 0x3240, 0x2FF0, 0x2E60, 0x2B20, 0x2890, 0x24C0, 0x2040, 0x1C40, 0x1790, 0x12F0, 0x0DF0, 0x0850, + 0x03B0, 0xFEE0, 0xF8F0, 0xF350, 0xEDB0, 0xE900, 0xE4B0, 0xE180, 0xDEA0, 0xDCF0, 0xDD10, 0xDE10, 0xE0A0, 0xE440, 0xE910, 0xEEA0, + 0xF520, 0xFC90, 0x0330, 0x0900, 0x0E50, 0x12D0, 0x16E0, 0x19E0, 0x1CA0, 0x1F70, 0x21C0, 0x2400, 0x25D0, 0x27A0, 0x29F0, 0x3760, + 0x3DB0, 0x4470, 0x4BA0, 0x5410, 0x5B00, 0x6100, 0x6680, 0x6A30, 0x6DA0, 0x6F40, 0x7130, 0x72E0, 0x7460, 0x7740, 0x7A40, 0x7D80, + 0x7EE0, 0x7F00, 0x7EF0, 0x7F10, 0x7F80, 0x7EF0, 0x7F30, 0x7F20, 0x7F00, 0x7F80, 0x7F10, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F70, 0x7EF0, + 0x7EF0, 0x7EF0, 0x7F00, 0x7F60, 0x7F00, 0x7ED0, 0x7EB0, 0x7EE0, 0x7F50, 0x7F10, 0x7E70, 0x7EC0, 0x7ED0, 0x7F10, 0x7F20, 0x7EC0, + 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7E90, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7EA0, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F30, + 0x7F20, 0x7F20, 0x7F10, 0x7EF0, 0x7F40, 0x7EF0, 0x7F30, 0x7F00, 0x7A40, 0x7610, 0x7290, 0x6E20, 0x69D0, 0x63F0, 0x5CA0, 0x53A0, + 0x4890, 0x3F30, 0x34C0, 0x2A70, 0x1FF0, 0x15A0, 0x0BE0, 0x02D0, 0xF970, 0xF0A0, 0xE7E0, 0xDFA0, 0xB9E0, 0xB030, 0xA5D0, 0x9AA0, + 0x9040, 0x88E0, 0x85E0, 0x8520, 0x84E0, 0x84C0, 0x84A0, 0x8490, 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8480, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8460, 0x8470, 0x8480, 0x8490, 0x84C0, 0x8530, 0x8AF0, + 0xAE50, 0xCF10, 0xEC50, 0x0560, 0x19C0, 0x2950, 0x35C0, 0x3DF0, 0x4550, 0x4C70, 0x5430, 0x5D60, 0x6690, 0x70A0, 0x79E0, 0x7F50, + 0x7F10, 0x7EC0, 0x7EE0, 0x7ED0, 0x7F10, 0x7F00, 0x7EA0, 0x7ED0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7F10, + 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7EC0, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, 0x7F10, 0x7F00, 0x7EE0, + 0x7F50, 0x7F10, 0x7F20, 0x7EF0, 0x7D30, 0x6DF0, 0x5DF0, 0x4CF0, 0x3C30, 0x2A90, 0x18F0, 0x07C0, 0xF560, 0xE540, 0xD5A0, 0xC6B0, + 0xB920, 0xABB0, 0x9E90, 0x9170, 0x88C0, 0x85C0, 0x84F0, 0x84D0, 0x84B0, 0x8490, 0x8490, 0x8480, 0x8470, 0x8460, 0x8460, 0x8450, + 0x8490, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, + 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8450, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8400, 0x8420, 0x8420, + 0x8430, 0x8420, 0x8430, 0x8430, 0x8440, 0x8440, 0x8450, 0x8450, 0x84A0, 0x8470, 0x8470, 0x8470, 0x8490, 0x84B0, 0x84D0, 0x8510, + 0x8610, 0x8C40, 0x9F60, 0xB150, 0xC400, 0xD3C0, 0xE330, 0xF180, 0xFE00, 0x09C0, 0x13D0, 0x1C30, 0x22B0, 0x2810, 0x2BD0, 0x2EF0, + 0x32A0, 0x36D0, 0x3CD0, 0x44B0, 0x4EA0, 0x5A50, 0x66A0, 0x71C0, 0x7B50, 0x7EF0, 0x7F60, 0x7EE0, 0x7ED0, 0x7F10, 0x7F20, 0x7F80, + 0x7EF0, 0x7EE0, 0x7F00, 0x7F10, 0x7F30, 0x7EB0, 0x7EA0, 0x7890, 0x6C70, 0x60F0, 0x56C0, 0x4DB0, 0x47A0, 0x43A0, 0x40B0, 0x3F00, + 0x3D00, 0x3A10, 0x3610, 0x31A0, 0x2E60, 0x2A80, 0x28B0, 0x27B0, 0x2860, 0x29E0, 0x2A40, 0x2960, 0x2650, 0x1FF0, 0x18B0, 0x0FE0, + 0x0670, 0xFDD0, 0xF5E0, 0xEE90, 0xE830, 0xE230, 0xDCA0, 0xD690, 0xD080, 0xCA70, 0xC570, 0xC1A0, 0xBEE0, 0xBD40, 0xBDE0, 0xBF80, + 0xC380, 0xC820, 0xCE50, 0xD5B0, 0xDD90, 0xE710, 0xF0B0, 0xFB30, 0x0660, 0x1140, 0x1C80, 0x26E0, 0x30A0, 0x3950, 0x40B0, 0x4740, + 0x4C10, 0x5110, 0x5530, 0x5840, 0x5BC0, 0x5E00, 0x60B0, 0x63C0, 0x65D0, 0x68E0, 0x6B80, 0x6E80, 0x7190, 0x73F0, 0x7670, 0x78C0, + 0x7B00, 0x7CE0, 0x7E40, 0x7F00, 0x7F00, 0x7F10, 0x7F00, 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7EF0, + 0x7EB0, 0x7E10, 0x7D40, 0x7C80, 0x7BF0, 0x7B70, 0x7B20, 0x7A90, 0x7A70, 0x7AA0, 0x7B90, 0x7C40, 0x7D70, 0x7E60, 0x7EE0, 0x7F30, + 0x7F30, 0x7F40, 0x7F30, 0x7F00, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F20, 0x7F40, 0x7F40, 0x7F30, 0x7F30, + 0x7F20, 0x7F40, 0x7F50, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F40, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F50, 0x7F30, 0x7F20, 0x7F20, + 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, 0x7F20, 0x7F20, 0x6790, 0x48A0, 0x2A70, 0x0E50, 0xF480, 0xDD60, 0xC6D0, 0xB480, + 0xA360, 0x93C0, 0x8990, 0x85F0, 0x8520, 0x84E0, 0x84C0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8480, 0x84C0, + 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x84D0, 0x84B0, 0x84E0, 0x8530, 0x8690, 0x8EB0, 0xA060, 0xB150, 0xC2D0, 0xD4B0, 0xE7B0, + 0xFC30, 0x11E0, 0x29E0, 0x3F70, 0x50E0, 0x5C90, 0x5FB0, 0x5920, 0x46C0, 0x2810, 0xFEF0, 0xCAC0, 0x9860, 0x8530, 0x84B0, 0x8490, + 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8410, 0x8470, 0x8480, 0x84B0, 0x8520, 0x91E0, 0xBC50, 0xD5C0, 0xE310, + 0xE710, 0xE560, 0xE220, 0xE040, 0xE0D0, 0xE3A0, 0xE780, 0xEA50, 0xEB70, 0xE770, 0xDDD0, 0xCD40, 0xB5B0, 0x98F0, 0x86C0, 0x8500, + 0x84A0, 0x8480, 0x8470, 0x8460, 0x8450, 0x8440, 0x8430, 0x8430, 0x8420, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8420, 0x8430, 0x8440, 0x8450, 0x8460, 0x8480, + 0x84A0, 0x84D0, 0x8550, 0x8EE0, 0xB030, 0xD000, 0xF050, 0x10E0, 0x3090, 0x4E50, 0x6930, 0x7CA0, 0x7F10, 0x7F00, 0x7EA0, 0x7EF0, + 0x7EF0, 0x7F20, 0x7F20, 0x7EC0, 0x7F10, 0x7F00, 0x7ED0, 0x7EF0, 0x7EA0, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F20, + 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F30, 0x7EE0, 0x7F40, 0x7F10, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7EE0, 0x7EC0, + 0x7EF0, 0x7EF0, 0x7F60, 0x7ED0, 0x7ED0, 0x7F00, 0x7F00, 0x7F50, 0x7ED0, 0x7EC0, 0x7F10, 0x7F10, 0x7F30, 0x7EC0, 0x7E90, 0x7EF0, + 0x7F10, 0x7F20, 0x7ED0, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7EC0, 0x7F10, 0x7EF0, 0x7EE0, 0x7F10, 0x7F00, 0x7F30, 0x7F00, + 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7EF0, 0x7F10, 0x7EF0, 0x7EF0, 0x7F80, 0x7F10, 0x7F20, 0x7F00, 0x7EF0, 0x7F70, 0x7F00, 0x7F10, + 0x7EF0, 0x7EE0, 0x7F60, 0x7EF0, 0x7EB0, 0x7EE0, 0x7ED0, 0x7F70, 0x7F20, 0x7EC0, 0x7ED0, 0x7EB0, 0x7F10, 0x7EF0, 0x7E90, 0x7EB0, + 0x7EC0, 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7E90, 0x7F00, 0x7F00, 0x7EF0, 0x7EF0, 0x7F00, 0x7F20, 0x7F20, + 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F20, 0x7EE0, 0x7EF0, 0x7F50, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7ED0, 0x7F10, + 0x7EF0, 0x7EE0, 0x7F50, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7EC0, 0x7EF0, 0x7F00, 0x7F50, 0x7ED0, 0x7EA0, 0x7EE0, + 0x7EF0, 0x7F30, 0x7F00, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7EB0, 0x7F00, 0x7EE0, 0x7EF0, 0x7F30, 0x7F00, 0x7EE0, 0x7F10, + 0x7F10, 0x7F00, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F10, 0x7F20, 0x7F20, 0x7ED0, 0x7F00, 0x7F40, 0x7EB0, 0x7F00, + 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7F00, 0x7F00, 0x7EF0, 0x7F00, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F00, 0x7F40, 0x7F10, + 0x7F10, 0x7F00, 0x7EF0, 0x7F50, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F60, 0x7E80, 0x7C90, 0x7A30, 0x77A0, 0x74A0, 0x7150, 0x6DB0, + 0x69F0, 0x6650, 0x6270, 0x5EA0, 0x5A10, 0x55D0, 0x5120, 0x4BB0, 0x46E0, 0x4000, 0x39B0, 0x3290, 0x2AF0, 0x23F0, 0x1D00, 0x15C0, + 0x0EF0, 0x0710, 0xFFB0, 0xF880, 0xF170, 0xEB20, 0xE4F0, 0xDF90, 0xDAC0, 0xD5B0, 0xD1C0, 0xCD30, 0xC970, 0xC5C0, 0xC1D0, 0xBE60, + 0xBA00, 0xB6A0, 0xB2F0, 0xAF60, 0xAB90, 0xA7D0, 0xA450, 0xA0B0, 0x9CC0, 0x9930, 0x9530, 0x9160, 0x8D70, 0x8A50, 0x8860, 0x8700, + 0x8640, 0x85C0, 0x8570, 0x8540, 0x8520, 0x8510, 0x8500, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, + 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x84F0, 0x8520, 0x84D0, 0x84C0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, + 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84A0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84D0, 0x84E0, 0x84F0, 0x8520, 0x8580, + 0x8670, 0x8940, 0x9190, 0x9F20, 0xAC70, 0xBAC0, 0xC990, 0xD870, 0xE720, 0xF440, 0x0090, 0x0B80, 0x1670, 0x2050, 0x2850, 0x3000, + 0x3480, 0x35D0, 0x3510, 0x3100, 0x2BA0, 0x24B0, 0x1E50, 0x18A0, 0x1400, 0x1190, 0x1170, 0x13C0, 0x1880, 0x1F90, 0x2800, 0x2F90, + 0x3670, 0x3D40, 0x4260, 0x4650, 0x48F0, 0x4960, 0x48C0, 0x4410, 0x3D20, 0x3440, 0x29B0, 0x1F90, 0x1420, 0x0840, 0xFC10, 0xEF70, + 0xE090, 0xD110, 0xC090, 0xAEE0, 0x9B40, 0x8A60, 0x8550, 0x84D0, 0x84B0, 0x8490, 0x8470, 0x8460, 0x8450, 0x8440, 0x8430, 0x8420, + 0x8410, 0x8410, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8420, + 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8460, 0x8450, 0x8460, 0x8470, 0x8470, 0x8480, + 0x84A0, 0x84D0, 0x8550, 0x8C10, 0xAB40, 0xC8B0, 0xE510, 0xFC50, 0x0FB0, 0x1EF0, 0x2AA0, 0x32C0, 0x3790, 0x3A80, 0x3AC0, 0x3960, + 0x3540, 0x2EF0, 0x2610, 0x19B0, 0x0B00, 0xF870, 0xE2F0, 0xCC60, 0xB210, 0x98B0, 0x87D0, 0x8500, 0x84C0, 0x8490, 0x8480, 0x8470, + 0x8450, 0x8450, 0x8440, 0x8430, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8450, + 0x8450, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x8490, 0x84A0, 0x8490, 0x8490, 0x8480, + 0x84A0, 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8450, 0x8450, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, 0x8420, 0x8420, 0x8420, + 0x8420, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8450, 0x8440, + 0x8440, 0x8460, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8480, 0x8480, 0x8480, + 0x8480, 0x8480, 0x8480, 0x8480, 0x8470, 0x8470, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8450, 0x8460, + 0x8450, 0x8450, 0x8450, 0x8450, 0x8480, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8440, + 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, + 0x8440, 0x8440, 0x8490, 0x8450, 0x8450, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, + 0x8450, 0x8450, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, + 0x8440, 0x8440, 0x8460, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8460, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, + 0x84B0, 0x84D0, 0x84F0, 0x8540, 0x8630, 0x8960, 0x9230, 0x9DB0, 0xA810, 0xB270, 0xBBD0, 0xC560, 0xCE70, 0xD8C0, 0xE260, 0xEBD0, + 0xF5C0, 0xFE90, 0x0690, 0x0CB0, 0x1130, 0x1560, 0x1930, 0x1D70, 0x21C0, 0x2570, 0x2980, 0x2D60, 0x3140, 0x33B0, 0x3510, 0x3620, + 0x3500, 0x3270, 0x2DA0, 0x26C0, 0x1E90, 0x1400, 0x0800, 0xFB40, 0xEB80, 0xDD90, 0xCF10, 0xC0E0, 0xB3A0, 0xA700, 0x9B50, 0x90A0, + 0x8900, 0x85C0, 0x8500, 0x84C0, 0x84A0, 0x8480, 0x8470, 0x8460, 0x8450, 0x8440, 0x8430, 0x8430, 0x8420, 0x8410, 0x8400, 0x8400, + 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, + 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x8400, 0x8400, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x83F0, 0x8400, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8400, 0x83C0, 0x8410, 0x8410, 0x8410, 0x8440, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8440, 0x8430, 0x8440, 0x8450, + 0x8450, 0x8460, 0x8470, 0x8470, 0x8490, 0x84A0, 0x84C0, 0x8500, 0x85C0, 0x8730, 0x8B90, 0x9360, 0x9A90, 0xA260, 0xAB90, 0xB6D0, + 0xC420, 0xD270, 0xE120, 0xEEF0, 0xFB60, 0x03C0, 0x0810, 0x0770, 0x0360, 0xFBE0, 0xF1B0, 0xE570, 0xD790, 0xC890, 0xBF00, 0xBDF0, + 0xCA50, 0xE430, 0x0B90, 0x39A0, 0x66C0, 0x7EF0, 0x7EA0, 0x7EC0, 0x7EC0, 0x7F10, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F10, + 0x7EA0, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F30, 0x7EF0, 0x7F00, 0x7EF0, 0x7F00, + 0x7F60, 0x7EF0, 0x7F20, 0x7F00, 0x7F00, 0x7F90, 0x7EF0, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F60, 0x7EE0, 0x7ED0, 0x7F10, 0x7F00, 0x7F40, + 0x7EC0, 0x7E90, 0x7EF0, 0x7EF0, 0x7F00, 0x7F00, 0x7F50, 0x7ED0, 0x7E70, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7EC0, 0x7F10, 0x7EF0, + 0x7EE0, 0x7EF0, 0x7EA0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7EF0, 0x7F00, 0x7F10, 0x7F00, 0x7F30, 0x7EE0, 0x7EF0, + 0x7F30, 0x7F10, 0x7F60, 0x7F10, 0x7F20, 0x7F20, 0x7EF0, 0x7F70, 0x7EF0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F60, 0x7EF0, 0x7F10, 0x7F00, + 0x7F00, 0x7F50, 0x7F10, 0x7EA0, 0x7EC0, 0x7ED0, 0x7F30, 0x7EE0, 0x7E90, 0x7ED0, 0x7EE0, 0x7F20, 0x7F10, 0x7ED0, 0x7EF0, 0x7EE0, + 0x7EF0, 0x7ED0, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7EE0, 0x7E90, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, + 0x7F40, 0x7EB0, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7EE0, 0x7F50, 0x7EF0, 0x7F20, 0x7F20, 0x7EF0, 0x7F80, 0x7F10, 0x7F20, 0x7F10, + 0x7EF0, 0x7F70, 0x7F00, 0x7F10, 0x7EF0, 0x7EE0, 0x7F60, 0x7F10, 0x7D30, 0x6860, 0x56E0, 0x4670, 0x3700, 0x29F0, 0x1EF0, 0x1430, + 0x09B0, 0x0040, 0xF740, 0xEF10, 0xE720, 0xDF70, 0xD9E0, 0xD460, 0xD0A0, 0xCCD0, 0xC970, 0xC620, 0xC2C0, 0xBEC0, 0xB9E0, 0xB4E0, + 0xB040, 0xAB20, 0xA6F0, 0xA460, 0xA270, 0xA2D0, 0xA3A0, 0xA630, 0xAA30, 0xAF90, 0xB700, 0xC180, 0xCEF0, 0xDF80, 0xF340, 0x0A40, + 0x24C0, 0x3EC0, 0x5690, 0x6990, 0x77E0, 0x7E70, 0x7F70, 0x7EF0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7ED0, 0x7F10, 0x7F00, + 0x7F30, 0x7ED0, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F30, 0x7F00, 0x7EA0, 0x7F10, 0x7E10, 0x6C70, 0x5D90, 0x5200, 0x4890, 0x4260, 0x3E50, + 0x3D50, 0x3E10, 0x4140, 0x4560, 0x4A00, 0x4F40, 0x5340, 0x5590, 0x5630, 0x5470, 0x5260, 0x4F50, 0x4C30, 0x49F0, 0x48F0, 0x4A10, + 0x4BC0, 0x4DE0, 0x5110, 0x5370, 0x56A0, 0x5940, 0x5CB0, 0x6070, 0x6540, 0x6B10, 0x70F0, 0x7740, 0x7CC0, 0x7E90, 0x7EB0, 0x7EF0, + 0x7F50, 0x7F10, 0x7E70, 0x7EC0, 0x7ED0, 0x7F10, 0x7F20, 0x7EC0, 0x7ED0, 0x7F00, 0x7F00, 0x7010, 0x5E00, 0x4B20, 0x3900, 0x2850, + 0x1C90, 0x1340, 0x0F40, 0x0E90, 0x1120, 0x1600, 0x1BD0, 0x22B0, 0x2960, 0x2E60, 0x31B0, 0x3270, 0x30C0, 0x2D50, 0x2A10, 0x2860, + 0x2960, 0x2D90, 0x37F0, 0x4900, 0x5D50, 0x7200, 0x7F20, 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F60, 0x7F00, 0x7F00, 0x7F00, 0x7ED0, + 0x7F30, 0x7EE0, 0x7EA0, 0x7EF0, 0x7F10, 0x7F40, 0x7ED0, 0x7EB0, 0x7F00, 0x7F00, 0x7F10, 0x7E90, 0x7EA0, 0x7F00, 0x7F10, 0x7F20, + 0x7EE0, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F20, 0x7F10, 0x7F20, 0x7EF0, 0x7EF0, 0x7F10, 0x7EF0, 0x7F30, 0x7F20, + 0x7F00, 0x7590, 0x6B50, 0x61F0, 0x5AE0, 0x57C0, 0x5A10, 0x6170, 0x6C60, 0x7890, 0x7EF0, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F20, + 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, + 0x7F30, 0x7F20, 0x7200, 0x6030, 0x4F20, 0x3F70, 0x32A0, 0x28D0, 0x2130, 0x1C60, 0x1970, 0x18B0, 0x1A10, 0x1D30, 0x2350, 0x2C30, + 0x3860, 0x4760, 0x57A0, 0x68C0, 0x7660, 0x7E80, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7F30, 0x7F20, + 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F10, 0x7F20, 0x7F40, 0x7F40, 0x7F30, 0x7EC0, + 0x7210, 0x63F0, 0x5470, 0x4480, 0x34E0, 0x2530, 0x1660, 0x07B0, 0xFB50, 0xF080, 0xE650, 0xDD70, 0xD550, 0xCD60, 0xC560, 0xBD70, + 0xB480, 0xABA0, 0xA1C0, 0x9630, 0x8B30, 0x8620, 0x8500, 0x84C0, 0x84B0, 0x8480, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8450, + 0x8450, 0x8440, 0x8430, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8410, 0x8430, + 0x8420, 0x8420, 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, + 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8410, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, + 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, 0x8440, 0x8440, 0x8450, 0x8460, 0x8460, + 0x8470, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, 0x84B0, 0x84C0, 0x84C0, 0x84D0, + 0x84E0, 0x84F0, 0x8510, 0x8510, 0x8520, 0x8520, 0x8520, 0x8540, 0x8570, 0x8620, 0x8830, 0x8F00, 0x99A0, 0x9F60, 0xA220, 0xA020, + 0x9C50, 0x96C0, 0x9190, 0x8D80, 0x8B00, 0x89D0, 0x8990, 0x89C0, 0x8AF0, 0x8D30, 0x92A0, 0x9B90, 0xA6F0, 0xB5B0, 0xC700, 0xD7F0, + 0xE850, 0xF830, 0x0670, 0x1390, 0x1FF0, 0x2CE0, 0x38C0, 0x4690, 0x52C0, 0x5E40, 0x68B0, 0x71B0, 0x7970, 0x7E40, 0x7F50, 0x7F20, + 0x7EF0, 0x7EF0, 0x7F00, 0x7F60, 0x7F10, 0x7E90, 0x7EB0, 0x7EC0, 0x7EF0, 0x7F10, 0x7E70, 0x7EC0, 0x7ED0, 0x7F10, 0x7F20, 0x7EC0, + 0x7F10, 0x7F10, 0x7F10, 0x7F10, 0x7EB0, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F40, 0x7F30, 0x7E00, 0x7540, 0x6B10, 0x5FF0, + 0x5360, 0x44C0, 0x35F0, 0x2520, 0x1240, 0xFF50, 0xEAB0, 0xD670, 0xC070, 0xAA80, 0x9450, 0x8750, 0x8510, 0x84D0, 0x84A0, 0x8490, + 0x8480, 0x8470, 0x8460, 0x8450, 0x8440, 0x8440, 0x8430, 0x8420, 0x8420, 0x8410, 0x8400, 0x8400, 0x83F0, 0x83E0, 0x8400, 0x83D0, + 0x83C0, 0x83D0, 0x83C0, 0x83B0, 0x83B0, 0x83E0, 0x83B0, 0x83C0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83F0, 0x83C0, + 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83C0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83B0, 0x83A0, 0x83B0, + 0x83A0, 0x83A0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, + 0x8400, 0x8410, 0x8410, 0x8420, 0x8430, 0x8430, 0x8440, 0x8450, 0x8460, 0x8470, 0x8480, 0x8490, 0x84B0, 0x84D0, 0x8520, 0x8640, + 0x8C30, 0x9C40, 0xAA60, 0xB710, 0xC240, 0xEB00, 0xF3D0, 0xFBF0, 0x0380, 0x0C40, 0x1530, 0x1F60, 0x2A30, 0x3590, 0x4310, 0x5160, + 0x5FF0, 0x6E30, 0x7AB0, 0x7F00, 0x7F10, 0x7F60, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F60, 0x7EE0, 0x7E90, 0x7F10, 0x7EF0, 0x7F70, + 0x7F00, 0x7EA0, 0x7F00, 0x7F10, 0x7F20, 0x7EE0, 0x7EA0, 0x7EF0, 0x7F00, 0x7EF0, 0x7EF0, 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7F10, + 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7EF0, 0x7F50, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F60, 0x7F10, 0x7F10, 0x7F10, 0x7EE0, + 0x7F80, 0x7F10, 0x7F20, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7EF0, 0x7EF0, 0x7EE0, 0x7F40, 0x7F10, 0x7EE0, 0x7EE0, 0x7ED0, 0x7F50, + 0x7F20, 0x7EC0, 0x7ED0, 0x7ED0, 0x7F40, 0x7F10, 0x7E90, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, 0x7E90, 0x7F10, 0x7F20, + 0x7EC0, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7EF0, 0x7F00, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7F60, 0x7F10, 0x7F10, 0x7EF0, 0x7F10, + 0x7F30, 0x7EF0, 0x7F00, 0x7EF0, 0x7F10, 0x7F60, 0x7F00, 0x7EF0, 0x7F20, 0x7F10, 0x7F90, 0x7EF0, 0x7EE0, 0x7EE0, 0x7EF0, 0x7F30, + 0x7F00, 0x7ED0, 0x7A80, 0x6A20, 0x5970, 0x4850, 0x3630, 0x23E0, 0x1140, 0xFE30, 0xE9B0, 0xD640, 0x8E50, 0x8670, 0x8500, 0x84D0, + 0x84B0, 0x84A0, 0x84B0, 0x8480, 0x8470, 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, + 0x8460, 0x8460, 0x8470, 0x8460, 0x8470, 0x8470, 0x84A0, 0x8470, 0x8480, 0x8480, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x84B0, 0x84B0, + 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84C0, 0x84B0, 0x84B0, 0x84C0, 0x84B0, 0x84C0, 0x84C0, 0x84C0, 0x84D0, 0x84D0, 0x84E0, 0x8530, + 0x8520, 0x8570, 0x8630, 0x87A0, 0x8B70, 0x9260, 0x9AC0, 0xA240, 0xA9B0, 0xB2A0, 0xBA20, 0xC1F0, 0xC960, 0xD060, 0xD810, 0xE000, + 0xE8A0, 0xF1A0, 0xFBF0, 0x06E0, 0x1240, 0x1ED0, 0x2C30, 0x3A60, 0x4AC0, 0x5A50, 0x6970, 0x77C0, 0x7EF0, 0x7F10, 0x7F00, 0x7F60, + 0x7EF0, 0x7F30, 0x7F20, 0x7F00, 0x7F90, 0x7F00, 0x7F40, 0x7F10, 0x7EF0, 0x7F70, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F00, 0x7F50, 0x7F10, + 0x7EE0, 0x7F00, 0x7EF0, 0x7F30, 0x7F00, 0x7E70, 0x7ED0, 0x7EB0, 0x7F20, 0x7EF0, 0x7E90, 0x7EB0, 0x7F00, 0x7F10, 0x7F10, 0x7EA0, + 0x7ED0, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7F60, + 0x7EF0, 0x7F20, 0x7EF0, 0x7EF0, 0x7F70, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F00, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7EF0, 0x7F00, + 0x7F00, 0x7F10, 0x7F10, 0x7EF0, 0x7F20, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7F20, 0x7F20, 0x7F10, 0x7EF0, 0x7F00, 0x7F30, + 0x7F10, 0x7F30, 0x7F30, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F40, 0x7F20, 0x7F20, 0x7F30, + 0x7F30, 0x7F40, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F50, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F20, + 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F10, 0x7F20, + 0x7F10, 0x7F10, 0x7F00, 0x7F00, 0x7F10, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F30, 0x7F20, 0x7F40, + 0x7F30, 0x7F30, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F30, + 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7EE0, 0x7F10, 0x7F30, 0x7F30, 0x7F20, 0x7EF0, 0x7F30, 0x7F20, + 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F40, 0x7F30, 0x7460, 0x5E10, 0x42A0, 0x2420, 0x02E0, 0xDFC0, 0xBB80, 0x9760, 0x8580, + 0x84C0, 0x8490, 0x8470, 0x8460, 0x8450, 0x8440, 0x8430, 0x8430, 0x8410, 0x8410, 0x8420, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83E0, + 0x83E0, 0x83E0, 0x83E0, 0x8410, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x83F0, 0x83F0, 0x83F0, 0x83F0, + 0x83E0, 0x83F0, 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83B0, 0x83B0, 0x83A0, 0x83A0, 0x83A0, 0x8390, 0x8390, 0x8380, + 0x8390, 0x8390, 0x83A0, 0x83A0, 0x83A0, 0x83A0, 0x83B0, 0x83C0, 0x83C0, 0x83D0, 0x83E0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, + 0x8410, 0x8410, 0x8420, 0x8430, 0x8430, 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8470, 0x8480, 0x8490, 0x84A0, + 0x84D0, 0x8570, 0x92F0, 0xB400, 0xD110, 0xE9B0, 0xFDC0, 0x0DB0, 0x1AB0, 0x26A0, 0x3260, 0x3FF0, 0x4F00, 0x5E00, 0x6CF0, 0x7A30, + 0x7F00, 0x7F20, 0x7F00, 0x7F50, 0x7EF0, 0x7F10, 0x7F30, 0x7F20, 0x7F60, 0x7F10, 0x7F10, 0x7EF0, 0x62A0, 0x3C70, 0x1460, 0xE820, + 0xB980, 0x8C80, 0x84E0, 0x84A0, 0x8480, 0x8470, 0x8460, 0x8460, 0x8460, 0x8460, 0x8460, 0x8470, 0x8470, 0x8470, 0x8490, 0x84B0, + 0x84F0, 0x8880, 0xB970, 0xEC10, 0x1C00, 0x46A0, 0x6800, 0x7E00, 0x7EA0, 0x7ED0, 0x7EB0, 0x7F20, 0x7F10, 0x7E90, 0x7F10, 0x7F00, + 0x7EF0, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F50, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F60, 0x7EF0, 0x7F10, + 0x7F10, 0x7F00, 0x7F60, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F70, 0x7EE0, 0x7EC0, 0x7EF0, 0x7F10, 0x7F60, 0x7ED0, 0x7ED0, 0x7F00, + 0x7F00, 0x7F10, 0x7EB0, 0x7E70, 0x7EE0, 0x7EF0, 0x7F30, 0x7EC0, 0x7E90, 0x7F10, 0x7F00, 0x7F00, 0x7F10, 0x7EB0, 0x7F00, 0x7F10, + 0x7F10, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7F40, 0x7F00, 0x7F20, 0x7F00, 0x7F10, 0x7F10, 0x7EF0, 0x7F60, 0x7EF0, 0x7F10, + 0x7EF0, 0x7EF0, 0x7F80, 0x7F00, 0x7F20, 0x7EF0, 0x7EF0, 0x7F60, 0x7EE0, 0x7F10, 0x7EE0, 0x7EE0, 0x7F50, 0x7F10, 0x7EB0, 0x7EE0, + 0x7ED0, 0x7F10, 0x7F00, 0x7EC0, 0x7EB0, 0x7EB0, 0x7EF0, 0x7F00, 0x7F60, 0x7F10, 0x7EB0, 0x7EB0, 0x7EC0, 0x7EF0, 0x7F10, 0x7EA0, + 0x7ED0, 0x7ED0, 0x7F00, 0x7EE0, 0x7E90, 0x7F00, 0x7F20, 0x7F20, 0x7F10, 0x7EA0, 0x7F00, 0x7F10, 0x7F10, 0x7F00, 0x7EE0, 0x7F40, + 0x7F10, 0x7F20, 0x7EF0, 0x7F00, 0x7F60, 0x7F20, 0x7F10, 0x7F10, 0x7EF0, 0x7F40, 0x7EF0, 0x7F10, 0x7EE0, 0x7EF0, 0x7F50, 0x7F00, + 0x7F00, 0x7F10, 0x7F10, 0x7F30, 0x7EF0, 0x7ED0, 0x7EF0, 0x7EE0, 0x7F50, 0x7ED0, 0x7EA0, 0x7F00, 0x7F10, 0x7F30, 0x7EE0, 0x7EC0, + 0x7EF0, 0x7F00, 0x7EF0, 0x7EF0, 0x7EB0, 0x7F20, 0x7EF0, 0x7F10, 0x7F20, 0x7EC0, 0x7F40, 0x7F10, 0x7F10, 0x7F20, 0x7EF0, 0x7F20, + 0x7EE0, 0x7EF0, 0x7F30, 0x7F20, 0x7F60, 0x7F10, 0x7F10, 0x7C30, 0x6F60, 0x63F0, 0x5930, 0x4E20, 0x4440, 0x3A10, 0x2FF0, 0x26E0, + 0x1CE0, 0x1380, 0x0A00, 0x0140, 0xF8D0, 0xF030, 0xE860, 0xE0D0, 0xD990, 0xD400, 0xCE90, 0xCAB0, 0xC7D0, 0xC660, 0xC680, 0xC7D0, + 0xCA80, 0xCD10, 0xD0C0, 0xD570, 0xD920, 0xDCC0, 0xDF70, 0xE020, 0xDFE0, 0xDCC0, 0xD7D0, 0xD060, 0xC4E0, 0xB810, 0xA730, 0x93E0, + 0x8710, 0x84F0, 0x84B0, 0x8480, 0x8470, 0x8450, 0x8430, 0x8420, 0x8410, 0x83F0, 0x83F0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83C0, + 0x83C0, 0x83C0, 0x83C0, 0x83D0, 0x83D0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, + 0x8410, 0x8410, 0x8410, 0x8420, 0x8430, 0x8430, 0x8440, 0x8440, 0x8450, 0x8460, 0x8470, 0x8480, 0x8490, 0x84B0, 0x84C0, 0x84E0, + 0x8520, 0x8580, 0x8690, 0x8890, 0x8C50, 0x9140, 0x96C0, 0x9C20, 0xA150, 0xA640, 0xAB20, 0xB050, 0xB510, 0xB980, 0xBE10, 0xC320, + 0xC800, 0xCDC0, 0xD310, 0xD960, 0xE0C0, 0xE890, 0xF150, 0xFAB0, 0x0520, 0x10D0, 0x1C70, 0x29A0, 0x3720, 0x4670, 0x54C0, 0x62C0, + 0x7090, 0x7C10, 0x7F00, 0x7EF0, 0x7E90, 0x7F00, 0x7ED0, 0x7F10, 0x7F20, 0x7EA0, 0x7F00, 0x7F10, 0x7F30, 0x7EE0, 0x7EA0, 0x7EF0, + 0x7F10, 0x7F20, 0x7F10, 0x7E90, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7EE0, 0x7EF0, 0x7F30, 0x7F20, 0x7F60, 0x7F10, + 0x7F10, 0x7F10, 0x7F00, 0x7F50, 0x7EF0, 0x7F20, 0x7EF0, 0x7EF0, 0x7F80, 0x7F00, 0x7F00, 0x7F10, 0x7F00, 0x7F70, 0x7F10, 0x7EB0, + 0x7EE0, 0x7ED0, 0x7F50, 0x7F20, 0x7ED0, 0x7ED0, 0x7EE0, 0x7F30, 0x7F10, 0x7E90, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7E70, 0x7EC0, + 0x7F10, 0x7F20, 0x7F20, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7EB0, 0x7F20, 0x7F00, 0x7F10, 0x7F20, 0x7F10, 0x7F10, 0x7F00, + 0x7EF0, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F20, 0x7EF0, 0x7F10, 0x7F20, + 0x7F10, 0x7F10, 0x7F10, 0x7F20, 0x7F40, 0x7F30, 0x7F30, 0x7F00, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F10, 0x7F30, 0x7F20, 0x7F40, + 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F50, 0x7F30, 0x7F30, 0x7F30, 0x7F30, 0x7F30, 0x7F30, 0x7F40, 0x7F40, 0x7F30, + 0x75F0, 0x6AC0, 0x6080, 0x5750, 0x5100, 0x4BD0, 0x4710, 0x41D0, 0x3BC0, 0x34C0, 0x2CD0, 0x24A0, 0x1B50, 0x1300, 0x0B10, 0x0400, + 0xFD80, 0xF790, 0xF270, 0xEDD0, 0xEA10, 0xE6D0, 0xE460, 0xE250, 0xE0F0, 0xDF30, 0xDD50, 0xDB60, 0xD8A0, 0xD490, 0xCDF0, 0xC5A0, + 0xBAD0, 0xAD50, 0x9D00, 0x8C90, 0x85F0, 0x84F0, 0x84B0, 0x8490, 0x8480, 0x8470, 0x8460, 0x8450, 0x8450, 0x8440, 0x8430, 0x8430, + 0x8420, 0x8420, 0x8410, 0x8400, 0x8410, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, 0x8400, + 0x8410, 0x8410, 0x8430, 0x8420, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, 0x8460, 0x8460, 0x8460, 0x84A0, 0x8480, 0x84B0, 0x8490, + 0x84B0, 0x84C0, 0x84E0, 0x8510, 0x85D0, 0x8840, 0x9170, 0x9F60, 0xAC30, 0xB920, 0xC600, 0xD2A0, 0xDF50, 0xED00, 0xF9A0, 0x0650, + 0x12F0, 0x1F70, 0x2BF0, 0x37E0, 0x4350, 0x4EF0, 0x5A40, 0x6550, 0x6F30, 0x7870, 0x7EA0, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F30, + 0x7F30, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7F10, 0x7F20, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7F20, 0x7F40, 0x7F50, + 0x7F30, 0x7FC0, 0x7F40, 0x7EF0, 0x7EF0, 0x7EF0, 0x7EF0, 0x7F30, 0x7E90, 0x7F00, 0x7EF0, 0x7F30, 0x7F00, 0x7EA0, 0x7EC0, 0x7EF0, + 0x7F10, 0x7EF0, 0x7E90, 0x7EB0, 0x7EE0, 0x7EF0, 0x7F10, 0x7EA0, 0x7F40, 0x7F10, 0x7F10, 0x7EF0, 0x7E90, 0x7F10, 0x7EE0, 0x7EE0, + 0x7EF0, 0x7F00, 0x7F30, 0x7F00, 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F20, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7EF0, 0x7F30, + 0x7F00, 0x7F40, 0x7EF0, 0x7F10, 0x7F20, 0x7EE0, 0x7F40, 0x7EE0, 0x7F00, 0x7EF0, 0x7F10, 0x7F70, 0x7F00, 0x7EC0, 0x7EF0, 0x7EF0, + 0x7F70, 0x7ED0, 0x7EA0, 0x7EE0, 0x7EF0, 0x7F10, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7F10, 0x7EB0, 0x7F10, 0x7EE0, 0x7EF0, + 0x7F10, 0x7F00, 0x7EF0, 0x7F10, 0x7F20, 0x7F20, 0x7F00, 0x7F50, 0x7EF0, 0x7F20, 0x7EF0, 0x7F00, 0x7F60, 0x7EF0, 0x7F10, 0x7F20, + 0x7F20, 0x7F80, 0x7F10, 0x7EF0, 0x7F10, 0x7F10, 0x7F70, 0x7EF0, 0x7EE0, 0x7EF0, 0x7EF0, 0x7F60, 0x7F20, 0x6C80, 0x5570, 0x3F10, + 0x2BF0, 0x1DB0, 0x12E0, 0x0CA0, 0x0890, 0x0600, 0x0370, 0x0090, 0xFE00, 0xFB20, 0xF900, 0xF870, 0xFAB0, 0xFFA0, 0x06C0, 0x1050, + 0x1B20, 0x2680, 0x3230, 0x3D30, 0x46E0, 0x5060, 0x57C0, 0x5EB0, 0x6400, 0x6850, 0x6D30, 0x7160, 0x75C0, 0x7A10, 0x7DE0, 0x7F00, + 0x7F00, 0x7F70, 0x7F20, 0x7F40, 0x7ED0, 0x7F10, 0x7F60, 0x7EE0, 0x7ED0, 0x7F10, 0x7EF0, 0x7F50, 0x7F00, 0x7EE0, 0x7F00, 0x7D80, + 0x77F0, 0x7270, 0x6CE0, 0x6830, 0x64B0, 0x61F0, 0x5FF0, 0x5CF0, 0x59E0, 0x5540, 0x4E50, 0x4710, 0x3CC0, 0x32D0, 0x2780, 0x1BB0, + 0x1040, 0x0580, 0xFB90, 0xF3D0, 0xEE20, 0xEB30, 0xEB00, 0xEC40, 0xEE10, 0xEFF0, 0xF0B0, 0xEE40, 0xE9D0, 0xE310, 0xD8C0, 0xCE90, + 0xC210, 0xB520, 0xA890, 0x9C70, 0x92F0, 0x8CA0, 0x8970, 0x8820, 0x87B0, 0x86F0, 0x86F0, 0x8750, 0x87C0, 0x8890, 0x89E0, 0x8AF0, + 0x8BA0, 0x8B30, 0x8A20, 0x8910, 0x87B0, 0x86F0, 0x8650, 0x85D0, 0x8590, 0x8560, 0x8530, 0x8510, 0x8500, 0x84F0, 0x84E0, 0x84D0, + 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84A0, 0x84C0, 0x84A0, 0x84A0, 0x84A0, 0x8470, + 0x84B0, 0x84B0, 0x84C0, 0x84C0, 0x84C0, 0x84D0, 0x84C0, 0x84D0, 0x84D0, 0x84E0, 0x84E0, 0x84E0, 0x84E0, 0x84D0, 0x84E0, 0x84E0, + 0x84F0, 0x84F0, 0x8500, 0x8510, 0x8520, 0x8530, 0x8560, 0x85A0, 0x8620, 0x86B0, 0x87D0, 0x8940, 0x8B40, 0x8E00, 0x9140, 0x9450, + 0x9850, 0x9B70, 0x9F40, 0xA290, 0xA630, 0xA930, 0xAA90, 0xAC30, 0xACC0, 0xAC20, 0xAB50, 0xA970, 0xA7B0, 0xA5C0, 0xA590, 0xA460, + 0xA360, 0xA1E0, 0x9EC0, 0x98F0, 0x9030, 0x87E0, 0x8530, 0x84C0, 0x8490, 0x8480, 0x8460, 0x8440, 0x8430, 0x8420, 0x8410, 0x8400, + 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8450, 0x8450, 0x8420, + 0x8440, 0x8440, 0x8440, 0x8450, 0x8490, 0x8460, 0x8490, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x84A0, 0x84B0, 0x84C0, 0x84C0, + 0x84D0, 0x84D0, 0x84E0, 0x84C0, 0x84D0, 0x84C0, 0x84C0, 0x84B0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8490, 0x8480, 0x8470, + 0x8470, 0x8470, 0x8460, 0x8460, 0x8460, 0x8450, 0x8470, 0x8450, 0x8450, 0x8440, 0x8440, 0x8440, 0x8440, 0x8430, 0x8430, 0x8430, + 0x8430, 0x8420, 0x8420, 0x8420, 0x8410, 0x8410, 0x8410, 0x8410, 0x8400, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x83E0, 0x83E0, + 0x83E0, 0x83D0, 0x83D0, 0x83D0, 0x83C0, 0x83C0, 0x83B0, 0x83B0, 0x83A0, 0x83A0, 0x8390, 0x8380, 0x8380, 0x8370, 0x8370, 0x8370, + 0x8370, 0x8370, 0x8360, 0x8370, 0x8370, 0x8370, 0x8380, 0x8380, 0x8390, 0x8390, 0x8390, 0x83A0, 0x83B0, 0x83B0, 0x83B0, 0x83C0, + 0x83C0, 0x83D0, 0x83D0, 0x83E0, 0x83E0, 0x83F0, 0x83F0, 0x8400, 0x8400, 0x8400, 0x8400, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, + 0x8410, 0x8410, 0x83F0, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8410, 0x8420, 0x8420, 0x8430, 0x8430, 0x8430, 0x8440, 0x8440, + 0x8440, 0x8440, 0x8450, 0x8450, 0x8450, 0x8460, 0x8460, 0x8470, 0x8470, 0x8480, 0x8480, 0x8490, 0x8490, 0x8490, 0x84A0, 0x84A0, + 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84B0, 0x84A0, 0x8490, 0x8490, 0x8490, 0x8480, 0x8480, 0x8470, 0x8470, 0x8460, + 0x8460, 0x8450, 0x8460, 0x8450, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, 0x8440, + 0x8450, 0x8450, 0x8460, 0x8470, 0x8480, 0x8490, 0x8490, 0x84B0, 0x84C0, 0x84E0, 0x8500, 0x8550, 0x85F0, 0x8770, 0x8AE0, 0x91C0, + 0x9950, 0xA140, 0xA940, 0xB210, 0xBC20, 0xC660, 0xD0D0, 0xDC90, 0xE8C0, 0xF580, 0x02C0, 0x1010, 0x1DF0, 0x2D40, 0x3B90, 0x49F0, + 0x5940, 0x67C0, 0x7530, 0x7E90, 0x7F20, 0x7F00, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F10, 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7EF0, + 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7B00, 0x61B0, 0x4950, 0x3100, 0x1890, 0x0380, 0xEFE0, 0xDDD0, 0xCC60, 0xBC10, 0xAC80, 0x9D60, + 0x8F90, 0x8740, 0x8540, 0x84E0, 0x84B0, 0x8490, 0x8490, 0x8470, 0x8470, 0x8460, 0x8460, 0x8470, 0x8460, 0x8460, 0x8460, 0x8450, + 0x8450, 0x8440, 0x8430, 0x8430, 0x8420, 0x8410, 0x8410, 0x8400, 0x8400, 0x83F0, 0x83F0, 0x83F0, 0x8400, 0x8410, 0x8420, 0x8430, + 0x8430, 0x8440, 0x8450, 0x8450, 0x8460, 0x84A0, 0x8470, 0x8490, 0x84B0, 0x8500, 0x87A0, 0x9FE0, 0xB640, 0xC630, 0xD170, 0xD810, + 0xDC20, 0xDDF0, 0xDED0, 0xDEA0, 0xDDA0, 0xDCC0, 0xDDA0, 0xE1C0, 0xEA50, 0xF930, 0x0CA0, 0x24C0, 0x3FF0, 0x5B60, 0x73B0, 0x7F40, + 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F30, 0x7F20, 0x7EF0, 0x7F30, 0x7F30, 0x7F20, 0x7F20, 0x7EF0, + 0x7F30, 0x7F20, 0x7F30, 0x7F30, 0x7F00, 0x7F20, 0x7F10, 0x7F30, 0x7F20, 0x7F40, 0x7F20, 0x7F30, 0x7F20, 0x7F40, 0x7F30, 0x7F30, + 0x7F20, 0x7F20, 0x7F30, 0x7F30, 0x7EF0, 0x7E90, 0x7F30, 0x7F20, 0x7F20, 0x7F00, 0x7E90, 0x7F10, 0x7EB0, 0x7EF0, 0x7EB0, 0x7E60, + 0x7ED0, 0x7ED0, 0x7F30, 0x7F20, 0x7F00, 0x7F50, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F40, + 0x7F00, 0x7F20, 0x7F00, 0x7EF0, 0x7F30, 0x7F00, 0x7EE0, 0x7EC0, 0x7EE0, 0x7F60, 0x7EF0, 0x7EF0, 0x7F00, 0x7EE0, 0x7EF0, 0x7EF0, + 0x7E70, 0x7F10, 0x7EB0, 0x7F30, 0x7EE0, 0x7E90, 0x7ED0, 0x7F00, 0x7F00, 0x7F10, 0x7EA0, 0x7EC0, 0x7EC0, 0x7F10, 0x7F00, 0x7EA0, + 0x7EF0, 0x7F10, 0x7F20, 0x7EF0, 0x7EB0, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7EF0, 0x7F10, 0x7EF0, 0x7EF0, 0x7F70, + 0x7F10, 0x7F40, 0x7F10, 0x7F10, 0x7F30, 0x7F10, 0x7F10, 0x7F00, 0x7EE0, 0x7F70, 0x7EF0, 0x7EE0, 0x7F00, 0x7F10, 0x7F70, 0x7F00, + 0x7ED0, 0x7F10, 0x7F00, 0x7F30, 0x7ED0, 0x7E90, 0x7F00, 0x7EF0, 0x7F30, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7EC0, + 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F30, 0x7F00, 0x7F00, 0x7EF0, 0x7F10, 0x7F80, + 0x7F00, 0x7F40, 0x7F30, 0x7F00, 0x7F90, 0x7F10, 0x7F10, 0x7EE0, 0x7EF0, 0x7F50, 0x7F10, 0x7EF0, 0x7EF0, 0x7F00, 0x7F60, 0x7F10, + 0x7EB0, 0x7EB0, 0x7EC0, 0x7EF0, 0x7F10, 0x7E70, 0x7ED0, 0x7ED0, 0x7F20, 0x7F20, 0x7EC0, 0x7ED0, 0x7F00, 0x7F10, 0x7F10, 0x7EB0, + 0x7EE0, 0x7EF0, 0x7F10, 0x7F20, 0x7F00, 0x7F40, 0x7F20, 0x7F20, 0x7F10, 0x7F00, 0x7F20, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F40, + 0x7F10, 0x7F20, 0x7F20, 0x7F10, 0x7F50, 0x7EF0, 0x7F00, 0x7EF0, 0x7F00, 0x7F40, 0x7EF0, 0x7F10, 0x7F00, 0x7F20, 0x7F70, 0x7ED0, + 0x7EB0, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7EC0, 0x7F10, 0x7F20, 0x7F40, 0x7EC0, 0x7A30, 0x7740, 0x74B0, 0x76C0, 0x7A10, 0x7D20, + 0x7EC0, 0x7ED0, 0x7F10, 0x7F00, 0x7F40, 0x7ED0, 0x7EB0, 0x7EF0, 0x7F10, 0x7F30, 0x7F00, 0x7EC0, 0x7F10, 0x7F10, 0x7F20, 0x7F00, + 0x7EA0, 0x7F00, 0x7EF0, 0x7EF0, 0x7F20, 0x7F00, 0x7F40, 0x7F10, 0x7F10, 0x7F40, 0x7F00, 0x7F30, 0x7F00, 0x7F00, 0x7F40, 0x7F10, + 0x7F70, 0x7F00, 0x7F20, 0x7F20, 0x7F00, 0x7F90, 0x7F00, 0x7F20, 0x7EF0, 0x7ED0, 0x7F70, 0x7EF0, 0x7F10, 0x7F10, 0x7F00, 0x7F70, + 0x7F10, 0x7EB0, 0x7EB0, 0x7EE0, 0x7F30, 0x7F00, 0x7EC0, 0x7ED0, 0x7ED0, 0x7F20, 0x7F20, 0x7E90, 0x7EB0, 0x7EE0, 0x7F10, 0x7F10, + 0x7E70, 0x7EE0, 0x7F10, 0x7F10, 0x7F20, 0x7F00, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F00, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7EE0, + 0x7F40, 0x7F30, 0x7F20, 0x7F10, 0x7F10, 0x7F30, 0x7EE0, 0x7EF0, 0x7F10, 0x7EE0, 0x7F50, 0x7EF0, 0x7F20, 0x7F20, 0x7F10, 0x7F90, + 0x7EF0, 0x7F10, 0x7F10, 0x7F10, 0x7F60, 0x7EE0, 0x7EB0, 0x7F10, 0x7F20, 0x7F40, 0x7F00, 0x7EA0, 0x7F10, 0x7F10, 0x7F20, 0x7EE0, + 0x7EC0, 0x7F10, 0x7F10, 0x7EF0, 0x7F10, 0x7EB0, 0x7F20, 0x7F10, 0x7F10, 0x7F10, 0x7F00, 0x7F40, 0x7F00, 0x7F00, 0x7F10, 0x7F00, + 0x7F60, 0x7F20, 0x7F40, 0x7F10, 0x7F00, 0x7F80, 0x7F10, 0x7F10, 0x7F00, 0x7EF0, 0x7F90, 0x7F10, 0x7F20, 0x7F00, 0x7F10, 0x7F70, + 0x7F10, 0x7EF0, 0x7EB0, 0x7B20, 0x72F0, 0x6A50, 0x6030, 0x5570, 0x4A50, 0x3F30, 0x3500, 0x29F0, 0x1FB0, 0x14D0, 0x0A30, 0x0050, + 0xF4F0, 0xEA40, 0xDFB0, 0xD4D0, 0xCA60, 0xC000, 0xB560, 0xAB10, 0xA170, 0x97B0, 0x9010, 0x8AB0, 0x8800, 0x86A0, 0x8600, 0x85B0, + 0x8580, 0x8580, 0x8590, 0x8580, 0x8610, 0x8690, 0x8790, 0x8970, 0x8CC0, 0x9260, 0x9910, 0xA0A0, 0xA830, 0xB070, 0xB880, 0xC040, + 0xC8B0, 0xD0E0, 0xD9F0, 0xE270, 0xEBE0, 0xF500, 0xFE20, 0x0770, 0x1050, 0x1960, 0x2190, 0x29B0, 0x3260, 0x3AD0, 0x41F0, 0x4970, + 0x5000, 0x5680, 0x5CB0, 0x61F0, 0x6720, 0x6C00, 0x7120, 0x7500, 0x7890, 0x7C30, 0x7E00, 0x7F00, 0x7EF0, 0x7F10, 0x7F30, 0x7EC0, + 0x7F30, 0x7F20, 0x7F20, 0x7F40, 0x7F10, 0x7F70, 0x7EE0, 0x7EF0, 0x7F20, 0x7EE0, 0x7F80, 0x7F10, 0x7F20, 0x7F00, 0x7EF0, 0x7F50, + 0x7F00, 0x7F10, 0x7EF0, 0x7EF0, 0x7F60, 0x7EF0, 0x7ED0, 0x7F00, 0x7F00, 0x7F30, 0x7F20, 0x7EC0, 0x7ED0, 0x7ED0, 0x7F30, 0x7F00, + 0x7E80, 0x7AF0, 0x75E0, 0x6EF0, 0x68F0, 0x6230, 0x5BC0, 0x5490, 0x4D30, 0x4630, 0x3EC0, 0x3740, 0x2FA0, 0x27E0, 0x20F0, 0x1980, + 0x1220, 0x0AE0, 0x0390, 0xFA70, 0xF400, 0xED20, 0xE760, 0xE100, 0xDB80, 0xD650, 0xD0C0, 0xCC00, 0xC710, 0xC2D0, 0xBEB0, 0xBAE0, + 0xB7C0, 0xB4F0, 0xB230, 0xAFD0, 0xADE0, 0xAB90, 0xA9E0, 0xA8C0, 0xA850, 0xA7A0, 0xA780, 0xA750, 0xA7E0, 0xA7F0, 0xA9A0, 0xAA90, + 0xAC00, 0xADB0, 0xAFB0, 0xB270, 0xB510, 0xB800, 0xBB70, 0xBF60, 0xC3E0, 0xC790, 0xCCA0, 0xD130, 0xD640, 0xDBE0, 0xE130, 0xE710, + 0xEDA0, 0xF3F0, 0xFAA0, 0x0150, 0x07B0, 0x0EA0, 0x1570, 0x1BF0, 0x2340, 0x2AC0, 0x31D0, 0x3870, 0x3F40, 0x4590, 0x4B30, 0x5100, + 0x5640, 0x5AF0, 0x5FA0, 0x6330, 0x6670, 0x68D0, 0x6AE0, 0x6CA0, 0x6E20, 0x6F10, 0x6FB0, 0x7000, 0x7070, 0x7090, 0x6FE0, 0x6F80, + 0x6ED0, 0x6EB0, 0x6DD0, 0x6D80, 0x6CB0, 0x6C00, 0x6B60, 0x6AC0, 0x6A50, 0x6780, 0x66C0, 0x6640, 0x6550, 0x64C0, 0x6410, 0x6390, + 0x62E0, 0x6200, 0x6190, 0x6070, 0x5FC0, 0x5EC0, 0x5D50, 0x5C10, 0x5A70, 0x58A0, 0x56C0, 0x54D0, 0x52B0, 0x5060, 0x4E50, 0x4AD0, + 0x4790, 0x44A0, 0x40E0, 0x3D70, 0x3950, 0x35E0, 0x3240, 0x2ED0, 0x2AA0, 0x2780, 0x2350, 0x2090, 0x1D00, 0x1A40, 0x1750, 0x14D0, + 0x1210, 0x0FA0, 0x0D10, 0x0A30, 0x0840, 0x05C0, 0x03B0, 0x0170, 0xFF20, 0xFCC0, 0xF9B0, 0xF6E0, 0xF3C0, 0xF110, 0xEE30, 0xEB50, + 0xE8A0, 0xE610, 0xE450, 0xE300, 0xE1B0, 0xE110, 0xE070, 0xE0C0, 0xE0A0, 0xE110, 0xE1B0, 0xE300, 0xE480, 0xE610, 0xE7E0, 0xEA30, + 0xEC50, 0xEE40, 0xF000, 0xF260, 0xF440, 0xF620, 0xF7E0, 0xF950, 0xFAD0, 0xFBB0, 0xFCF0, 0xFDC0, 0xFE80, 0xFED0, 0xFF20, 0xFF90, + 0x0010, 0x0050, 0x0120, 0x0210, 0x02D0, 0x03D0, 0x04E0, 0x05D0, 0x0710, 0x08A0, 0x09C0, 0x0BA0, 0x0D80, 0x0F40, 0x11A0, 0x12F0, + 0x1540, 0x1700, 0x18F0, 0x1AD0, 0x1C70, 0x1EF0, 0x2140, 0x2350, 0x2540, 0x2840, 0x2AB0, 0x2CA0, 0x2E60, 0x30C0, 0x3270, 0x3470, + 0x36E0, 0x3870, 0x3B30, 0x3CC0, 0x3F10, 0x40F0, 0x41F0, 0x4460, 0x45D0, 0x4790, 0x4960, 0x4A50, 0x4C70, 0x4DB0, 0x4F20, 0x5050, + 0x5130, 0x5220, 0x5300, 0x53D0, 0x54B0, 0x54C0, 0x5590, 0x5680, 0x56B0, 0x57A0, 0x57C0, 0x58B0, 0x5940, 0x5980, 0x59D0, 0x59C0, + 0x5A60, 0x59D0, 0x59F0, 0x5A20, 0x5960, 0x5940, 0x5920, 0x58C0, 0x5840, 0x57B0, 0x5820, 0x5760, 0x5710, 0x5730, 0x5670, 0x5680, + 0x5630, 0x55F0, 0x5660, 0x55F0, 0x5660, 0x5600, 0x5550, 0x5590, 0x54E0, 0x54E0, 0x5480, 0x5370, 0x52F0, 0x51C0, 0x5140, 0x5000, + 0x4E60, 0x4E10, 0x4CB0, 0x4CA0, 0x4BA0, 0x4AC0, 0x4A50, 0x4980, 0x4840, 0x4780, 0x45F0, 0x4520, 0x4440, 0x4350, 0x41C0, 0x4020, + 0x3F30, 0x3DB0, 0x3C30, 0x3A70, 0x3870, 0x3730, 0x35A0, 0x3410, 0x32F0, 0x30E0, 0x2FE0, 0x2E80, 0x2C40, 0x2B40, 0x2910, 0x27D0, + 0x25F0, 0x23E0, 0x22C0, 0x20A0, 0x1F70, 0x1D90, 0x1B90, 0x1A20, 0x1840, 0x1750, 0x1590, 0x13E0, 0x1240, 0x1040, 0x0E70, 0x0CC0, + 0x0A10, 0x0890, 0x0650, 0x0500, 0x0310, 0x0130, 0xFFF0, 0xFE50, 0xFCF0, 0xFBE0, 0xFA60, 0xF9D0, 0xF860, 0xF720, 0xF5E0, 0xF550, + 0xF460, 0xF420, 0xF2D0, 0xF210, 0xF230, 0xF250, 0xF150, 0xF170, 0xF130, 0xF120, 0xF180, 0xF130, 0xF160, 0xF180, 0xF190, 0xF1D0, + 0xF220, 0xF2A0, 0xF2E0, 0xF3C0, 0xF3E0, 0xF3F0, 0xF430, 0xF4C0, 0xF4F0, 0xF530, 0xF590, 0xF570, 0xF5D0, 0xF5A0, 0xF670, 0xF680, + 0xF630, 0xF720, 0xF700, 0xF740, 0xF6C0, 0xF780, 0xF800, 0xF810, 0xF830, 0xF920, 0xF870, 0xF8D0, 0xF8C0, 0xF960, 0xFB50, 0xFBB0, + 0xFC80, 0xFCF0, 0xFDC0, 0xFE30, 0xFEC0, 0xFF90, 0x0010, 0x0120, 0x0180, 0x0200, 0x0270, 0x02C0, 0x0370, 0x0390, 0x03C0, 0x0400, + 0x0460, 0x0530, 0x05B0, 0x0680, 0x0710, 0x0790, 0x0860, 0x0940, 0x09F0, 0x0A90, 0x0B40, 0x0C40, 0x0CB0, 0x0D60, 0x0E20, 0x0ED0, + 0x0FE0, 0x10C0, 0x1150, 0x11F0, 0x12B0, 0x1390, 0x13D0, 0x1440, 0x1500, 0x1550, 0x1650, 0x1700, 0x1740, 0x1810, 0x1820, 0x1920, + 0x1990, 0x19B0, 0x1A20, 0x1A60, 0x1AD0, 0x1AF0, 0x1B60, 0x1B80, 0x1C10, 0x1C60, 0x1CA0, 0x1C40, 0x1CC0, 0x1C80, 0x1C60, 0x1C90, + 0x1BC0, 0x1BE0, 0x1BD0, 0x1B90, 0x1B10, 0x1AC0, 0x1A90, 0x1A70, 0x19C0, 0x1990, 0x19B0, 0x1960, 0x18A0, 0x1850, 0x17D0, 0x16F0, + 0x16A0, 0x1580, 0x1470, 0x1400, 0x12C0, 0x1270, 0x1170, 0x10E0, 0x0F80, 0x0E70, 0x0D60, 0x0BD0, 0x0A70, 0x0970, 0x0860, 0x0750, + 0x0630, 0x0460, 0x0440, 0x0200, 0x00B0, 0xFF40, 0xFDB0, 0xFCF0, 0xFC00, 0xFAA0, 0xF9C0, 0xF880, 0xF700, 0xF580, 0xF430, 0xF2B0, + 0xF140, 0xF000, 0xEE50, 0xECC0, 0xEBA0, 0xE9D0, 0xE880, 0xE6F0, 0xE5A0, 0xE3F0, 0xE280, 0xE1C0, 0xDFF0, 0xDF30, 0xDE40, 0xDCD0, + 0xDC60, 0xDB60, 0xDA40, 0xD910, 0xD7D0, 0xD6B0, 0xD560, 0xD430, 0xD2F0, 0xD1F0, 0xD150, 0xD030, 0xCF30, 0xCE60, 0xCD50, 0xCC30, + 0xCB40, 0xC990, 0xC880, 0xC7B0, 0xC700, 0xC5E0, 0xC510, 0xC4A0, 0xC3E0, 0xC2F0, 0xC1B0, 0xC0C0, 0xC060, 0xBFC0, 0xBF00, 0xBEA0, + 0xBD90, 0xBD00, 0xBC20, 0xBB50, 0xBAB0, 0xB970, 0xB910, 0xB830, 0xB770, 0xB6A0, 0xB5C0, 0xB540, 0xB460, 0xB360, 0xB200, 0xB0D0, + 0xB030, 0xAEF0, 0xAD70, 0xAC90, 0xABC0, 0xAAD0, 0xA9A0, 0xA870, 0xA780, 0xA660, 0xA550, 0xA420, 0xA2F0, 0xA250, 0xA160, 0xA040, + 0x9F40, 0x9DE0, 0x9CD0, 0x9BD0, 0x9A80, 0x99D0, 0x9890, 0x97D0, 0x9690, 0x95F0, 0x94C0, 0x9350, 0x9200, 0x90E0, 0x8F90, 0x8E90, + 0x8D80, 0x8CF0, 0x8C70, 0x8BB0, 0x8B60, 0x8AB0, 0x8A50, 0x89B0, 0x8950, 0x88D0, 0x8890, 0x8840, 0x87F0, 0x87C0, 0x8790, 0x8760, + 0x8730, 0x86F0, 0x86D0, 0x8680, 0x86A0, 0x8690, 0x8690, 0x8680, 0x8670, 0x8670, 0x8650, 0x8650, 0x8650, 0x8650, 0x8640, 0x8650, + 0x8660, 0x8640, 0x8650, 0x8640, 0x8640, 0x8680, 0x8660, 0x8640, 0x8640, 0x8660, 0x8640, 0x8640, 0x8650, 0x8660, 0x8660, 0x8660, + 0x8670, 0x8680, 0x8670, 0x8670, 0x8680, 0x8670, 0x8680, 0x8670, 0x8680, 0x8680, 0x8670, 0x8670, 0x8670, 0x8680, 0x8660, 0x8650, + 0x8660, 0x8650, 0x8640, 0x8630, 0x8630, 0x8630, 0x8620, 0x8620, 0x8620, 0x8610, 0x8610, 0x8600, 0x8600, 0x8600, 0x8600, 0x8600, + 0x8610, 0x8630, 0x8600, 0x8600, 0x85F0, 0x85F0, 0x85F0, 0x85F0, 0x85F0, 0x8600, 0x8600, 0x8610, 0x8620, 0x8630, 0x8640, 0x8640, + 0x8640, 0x8650, 0x8650, 0x8670, 0x8680, 0x86A0, 0x86B0, 0x86D0, 0x8710, 0x8700, 0x8720, 0x8730, 0x8760, 0x8790, 0x87B0, 0x87E0, + 0x8800, 0x8810, 0x8850, 0x8860, 0x88B0, 0x8900, 0x8970, 0x8A10, 0x8A70, 0x8AF0, 0x8B90, 0x8C30, 0x8CC0, 0x8D40, 0x8DC0, 0x8E90, + 0x8F00, 0x8F70, 0x9030, 0x9120, 0x9200, 0x92B0, 0x93E0, 0x9450, 0x9510, 0x9600, 0x96C0, 0x9770, 0x98B0, 0x99A0, 0x9AB0, 0x9BC0, + 0x9C80, 0x9D50, 0x9DC0, 0x9E80, 0x9EF0, 0xA030, 0xA130, 0xA210, 0xA2E0, 0xA470, 0xA540, 0xA680, 0xA7A0, 0xA880, 0xA990, 0xAAB0, + 0xAB80, 0xAC80, 0xAD40, 0xAE40, 0xAF20, 0xAFD0, 0xB0E0, 0xB1A0, 0xB2B0, 0xB320, 0xB420, 0xB4C0, 0xB5A0, 0xB610, 0xB6D0, 0xB790, + 0xB830, 0xB8E0, 0xB9A0, 0xBA70, 0xBB40, 0xBC40, 0xBD20, 0xBDB0, 0xBEA0, 0xBF80, 0xBFE0, 0xC020, 0xC0D0, 0xC110, 0xC1B0, 0xC230, + 0xC240, 0xC2C0, 0xC330, 0xC3A0, 0xC440, 0xC4D0, 0xC570, 0xC620, 0xC6E0, 0xC710, 0xC750, 0xC780, 0xC850, 0xC8A0, 0xC910, 0xC970, + 0xC9F0, 0xCA50, 0xCAE0, 0xCB30, 0xCB40, 0xCB70, 0xCBE0, 0xCC70, 0xCCC0, 0xCD60, 0xCD90, 0xCE40, 0xCDD0, 0xCE70, 0xCE90, 0xCE50, + 0xCE80, 0xCEF0, 0xCEF0, 0xCF60, 0xCF70, 0xCF60, 0xCF80, 0xD010, 0xD090, 0xD0E0, 0xD130, 0xD150, 0xD130, 0xD130, 0xD130, 0xD170, + 0xD1B0, 0xD1B0, 0xD1F0, 0xD1B0, 0xD220, 0xD290, 0xD2C0, 0xD2D0, 0xD3A0, 0xD3D0, 0xD3F0, 0xD430, 0xD420, 0xD410, 0xD410, 0xD430, + 0xD460, 0xD440, 0xD440, 0xD430, 0xD3E0, 0xD3E0, 0xD3B0, 0xD3D0, 0xD420, 0xD3D0, 0xD410, 0xD460, 0xD450, 0xD430, 0xD3B0, 0xD400, + 0xD390, 0xD360, 0xD370, 0xD320, 0xD330, 0xD320, 0xD300, 0xD310, 0xD330, 0xD2D0, 0xD2C0, 0xD2C0, 0xD2F0, 0xD250, 0xD270, 0xD1D0, + 0xD1B0, 0xD190, 0xD0B0, 0xD0A0, 0xD030, 0xD000, 0xCFB0, 0xCF60, 0xCF00, 0xCF00, 0xCED0, 0xCE40, 0xCD80, 0xCDC0, 0xCD20, 0xCD80, + 0xCCD0, 0xCC40, 0xCC40, 0xCBB0, 0xCB60, 0xCAF0, 0xCA50, 0xCA30, 0xC9A0, 0xC990, 0xC8F0, 0xC8D0, 0xC8A0, 0xC810, 0xC790, 0xC6E0, + 0xC630, 0xC5C0, 0xC510, 0xC490, 0xC410, 0xC3D0, 0xC350, 0xC2F0, 0xC270, 0xC200, 0xC190, 0xC1A0, 0xC140, 0xC010, 0xBFF0, 0xBF20, + 0xBEE0, 0xBD90, 0xBCE0, 0xBCA0, 0xBC30, 0xBBB0, 0xBB40, 0xBA40, 0xB9C0, 0xB920, 0xB820, 0xB790, 0xB710, 0xB670, 0xB610, 0xB570, + 0xB570, 0xB510, 0xB500, 0xB440, 0xB3F0, 0xB3B0, 0xB2F0, 0xB280, 0xB240, 0xB190, 0xB110, 0xB020, 0xAFF0, 0xAF30, 0xAE50, 0xADE0, + 0xAD80, 0xAD30, 0xAC70, 0xABC0, 0xABA0, 0xAAF0, 0xAB20, 0xAAB0, 0xAA30, 0xAA50, 0xAA50, 0xA9B0, 0xA940, 0xA910, 0xA8C0, 0xA840, + 0xA820, 0xA7E0, 0xA790, 0xA6F0, 0xA710, 0xA630, 0xA5A0, 0xA4C0, 0xA4B0, 0xA450, 0xA430, 0xA400, 0xA3F0, 0xA3B0, 0xA2F0, 0xA280, + 0xA270, 0xA150, 0xA160, 0xA0E0, 0xA0A0, 0xA030, 0xA020, 0xA040, 0xA000, 0x9FB0, 0x9FB0, 0x9F70, 0x9EE0, 0x9EF0, 0x9E90, 0x9E00, + 0x9D50, 0x9D40, 0x9C80, 0x9C40, 0x9C30, 0x9BA0, 0x9B90, 0x9B70, 0x9AC0, 0x9AB0, 0x9A30, 0x99E0, 0x99E0, 0x9970, 0x9960, 0x9970, + 0x9950, 0x9920, 0x9850, 0x9880, 0x9810, 0x97B0, 0x9770, 0x9700, 0x9730, 0x96E0, 0x96C0, 0x9680, 0x9600, 0x95E0, 0x95A0, 0x9580, + 0x9510, 0x94E0, 0x9500, 0x94B0, 0x94E0, 0x94A0, 0x94B0, 0x9470, 0x9430, 0x9440, 0x9400, 0x9430, 0x9400, 0x93D0, 0x9440, 0x9420, + 0x9440, 0x9450, 0x9430, 0x9460, 0x9480, 0x9480, 0x9490, 0x9420, 0x9470, 0x9430, 0x9410, 0x9410, 0x9420, 0x9470, 0x9450, 0x9410, + 0x9470, 0x93F0, 0x9450, 0x94A0, 0x94A0, 0x9460, 0x9490, 0x94B0, 0x94E0, 0x94D0, 0x9510, 0x9520, 0x9530, 0x9550, 0x9590, 0x95C0, + 0x95D0, 0x95C0, 0x9550, 0x9510, 0x9570, 0x95A0, 0x9580, 0x95C0, 0x9650, 0x96F0, 0x96F0, 0x96F0, 0x9700, 0x9700, 0x96F0, 0x9720, + 0x9710, 0x9720, 0x9720, 0x97D0, 0x98A0, 0x98F0, 0x9930, 0x9910, 0x9960, 0x98D0, 0x9890, 0x98B0, 0x9890, 0x98D0, 0x9900, 0x9920, + 0x9960, 0x9940, 0x9A10, 0x9A30, 0x9A60, 0x9A70, 0x9A80, 0x9A80, 0x9A40, 0x9A40, 0x9AC0, 0x9AF0, 0x9B70, 0x9B40, 0x9B30, 0x9B50, + 0x9B60, 0x9B80, 0x9B50, 0x9B30, 0x9BA0, 0x9C00, 0x9CB0, 0x9CD0, 0x9D40, 0x9DC0, 0x9DD0, 0x9E20, 0x9E10, 0x9DC0, 0x9E20, 0x9E60, + 0x9E50, 0x9EB0, 0x9ED0, 0x9EC0, 0x9F10, 0x9ED0, 0x9F60, 0x9F40, 0x9F90, 0x9FD0, 0x9FF0, 0xA030, 0xA050, 0xA110, 0xA120, 0xA170, + 0xA1A0, 0xA1E0, 0xA270, 0xA2A0, 0xA340, 0xA390, 0xA3B0, 0xA420, 0xA470, 0xA480, 0xA4E0, 0xA4C0, 0xA4C0, 0xA4D0, 0xA4C0, 0xA4F0, + 0xA510, 0xA580, 0xA530, 0xA540, 0xA570, 0xA580, 0xA5B0, 0xA5E0, 0xA600, 0xA6E0, 0xA740, 0xA810, 0xA860, 0xA910, 0xA980, 0xAA00, + 0xAA10, 0xAA90, 0xAA70, 0xAAE0, 0xAB60, 0xABA0, 0xAC00, 0xABD0, 0xABB0, 0xABA0, 0xAB80, 0xABA0, 0xABB0, 0xABC0, 0xABF0, 0xAC10, + 0xAC80, 0xAC60, 0xACF0, 0xACE0, 0xACF0, 0xAD00, 0xAD50, 0xAE20, 0xAE40, 0xAED0, 0xAF30, 0xAFA0, 0xAFF0, 0xB030, 0xAFD0, 0xB080, + 0xB050, 0xB060, 0xB0D0, 0xB070, 0xB0F0, 0xB0E0, 0xB160, 0xB1B0, 0xB1B0, 0xB260, 0xB200, 0xB230, 0xB230, 0xB200, 0xB1E0, 0xB230, + 0xB220, 0xB280, 0xB230, 0xB330, 0xB300, 0xB300, 0xB310, 0xB300, 0xB3A0, 0xB390, 0xB380, 0xB3C0, 0xB3B0, 0xB400, 0xB400, 0xB3A0, + 0xB3D0, 0xB3C0, 0xB3C0, 0xB3D0, 0xB3B0, 0xB400, 0xB3A0, 0xB440, 0xB410, 0xB430, 0xB4B0, 0xB4A0, 0xB4D0, 0xB500, 0xB530, 0xB5C0, + 0xB5B0, 0xB660, 0xB670, 0xB630, 0xB650, 0xB5F0, 0xB650, 0xB670, 0xB630, 0xB6C0, 0xB6E0, 0xB710, 0xB770, 0xB780, 0xB7F0, 0xB7C0, + 0xB800, 0xB840, 0xB7F0, 0xB810, 0xB800, 0xB800, 0xB7F0, 0xB7F0, 0xB7D0, 0xB820, 0xB810, 0xB820, 0xB870, 0xB900, 0xB8F0, 0xB8F0, + 0xB9B0, 0xBA20, 0xBAC0, 0xBB50, 0xBB70, 0xBBD0, 0xBBE0, 0xBB80, 0xBB60, 0xBB50, 0xBAC0, 0xBA70, 0xBA60, 0xBA40, 0xBA30, 0xBA50, + 0xBA60, 0xBA90, 0xBA30, 0xBA80, 0xBAE0, 0xBA80, 0xBB10, 0xBB20, 0xBB60, 0xBB60, 0xBB90, 0xBBA0, 0xBBA0, 0xBBD0, 0xBBF0, 0xBC00, + 0xBC70, 0xBCD0, 0xBD70, 0xBDA0, 0xBDB0, 0xBDA0, 0xBD60, 0xBD90, 0xBDB0, 0xBDA0, 0xBE20, 0xBE80, 0xBEE0, 0xBEF0, 0xBED0, 0xBF10, + 0xBF60, 0xBF40, 0xBFD0, 0xC010, 0xC040, 0xC080, 0xC0F0, 0xC110, 0xC140, 0xC170, 0xC1E0, 0xC1B0, 0xC1F0, 0xC220, 0xC280, 0xC2E0, + 0xC2D0, 0xC2C0, 0xC2E0, 0xC2D0, 0xC340, 0xC380, 0xC3C0, 0xC430, 0xC480, 0xC4B0, 0xC4D0, 0xC520, 0xC550, 0xC5E0, 0xC5B0, 0xC600, + 0xC650, 0xC670, 0xC6C0, 0xC6A0, 0xC6B0, 0xC6E0, 0xC6E0, 0xC6D0, 0xC7A0, 0xC780, 0xC7D0, 0xC810, 0xC820, 0xC850, 0xC830, 0xC810, + 0xC830, 0xC810, 0xC840, 0xC820, 0xC830, 0xC830, 0xC860, 0xC840, 0xC890, 0xC8E0, 0xC8A0, 0xC860, 0xC880, 0xC8C0, 0xC8F0, 0xC8F0, + 0xC910, 0xC910, 0xC960, 0xC8F0, 0xC950, 0xC920, 0xC930, 0xC940, 0xC930, 0xC930, 0xC960, 0xC960, 0xC940, 0xC9B0, 0xC990, 0xC980, + 0xC9D0, 0xC9A0, 0xC990, 0xCA00, 0xCA10, 0xCA20, 0xCA10, 0xC9D0, 0xC9E0, 0xC9F0, 0xC9F0, 0xC9F0, 0xC9F0, 0xCA50, 0xCA30, 0xCA00, + 0xC9E0, 0xC9E0, 0xC980, 0xC940, 0xC990, 0xC980, 0xC900, 0xC9B0, 0xC9D0, 0xCA50, 0xCA20, 0xCA30, 0xCAA0, 0xCA50, 0xCAC0, 0xCAA0, + 0xCAE0, 0xCAD0, 0xCAB0, 0xCB40, 0xCB30, 0xCB30, 0xCB00, 0xCAC0, 0xCAB0, 0xCAB0, 0xCA80, 0xCA80, 0xCA80, 0xCA40, 0xC9D0, 0xC9D0, + 0xCA00, 0xC9E0, 0xC9A0, 0xC990, 0xC9F0, 0xCA40, 0xCAA0, 0xCAE0, 0xCAE0, 0xCAE0, 0xCBB0, 0xCBD0, 0xCB70, 0xCC40, 0xCBE0, 0xCC30, + 0xCC40, 0xCBC0, 0xCC50, 0xCC00, 0xCC60, 0xCC90, 0xCC50, 0xCC50, 0xCC20, 0xCC70, 0xCC40, 0xCC20, 0xCC40, 0xCCC0, 0xCD40, 0xCD70, + 0xCD50, 0xCDB0, 0xCDD0, 0xCDD0, 0xCDE0, 0xCDB0, 0xCDE0, 0xCE10, 0xCDF0, 0xCE00, 0xCDA0, 0xCE30, 0xCE70, 0xCEA0, 0xCE80, 0xCE90, + 0xCEC0, 0xCEB0, 0xCEC0, 0xCE60, 0xCE30, 0xCE60, 0xCE70, 0xCE60, 0xCEF0, 0xCE60, 0xCEE0, 0xCED0, 0xCED0, 0xCF20, 0xCF10, 0xCF70, + 0xCF80, 0xCF40, 0xCF70, 0xCF00, 0xCF70, 0xCF80, 0xCF50, 0xD050, 0xD050, 0xD040, 0xD050, 0xD030, 0xD100, 0xD080, 0xD0D0, 0xD100, + 0xD0E0, 0xD130, 0xD100, 0xD140, 0xD160, 0xD190, 0xD1A0, 0xD190, 0xD180, 0xD180, 0xD110, 0xD190, 0xD160, 0xD190, 0xD1A0, 0xD1B0, + 0xD1F0, 0xD210, 0xD1E0, 0xD1E0, 0xD170, 0xD1F0, 0xD1E0, 0xD180, 0xD190, 0xD180, 0xD1B0, 0xD1C0, 0xD190, 0xD1E0, 0xD1C0, 0xD1F0, + 0xD1F0, 0xD1D0, 0xD240, 0xD260, 0xD2F0, 0xD2D0, 0xD2D0, 0xD300, 0xD310, 0xD370, 0xD320, 0xD2F0, 0xD300, 0xD2D0, 0xD310, 0xD300, + 0xD2D0, 0xD320, 0xD310, 0xD370, 0xD360, 0xD360, 0xD380, 0xD3A0, 0xD3C0, 0xD3D0, 0xD3A0, 0xD440, 0xD450, 0xD450, 0xD490, 0xD470, + 0xD4A0, 0xD470, 0xD430, 0xD480, 0xD3E0, 0xD430, 0xD470, 0xD4F0, 0xD500, 0xD540, 0xD580, 0xD500, 0xD530, 0xD520, 0xD4F0, 0xD580, + 0xD520, 0xD560, 0xD550, 0xD570, 0xD580, 0xD5C0, 0xD570, 0xD5A0, 0xD580, 0xD580, 0xD5F0, 0xD570, 0xD640, 0xD5D0, 0xD600, 0xD600, + 0xD5A0, 0xD5D0, 0xD590, 0xD590, 0xD510, 0xD490, 0xD510, 0xD4E0, 0xD4F0, 0xD4A0, 0xD450, 0xD4C0, 0xD500, 0xD520, 0xD520, 0xD4F0, + 0xD580, 0xD5A0, 0xD580, 0xD5C0, 0xD540, 0xD590, 0xD590, 0xD5A0, 0xD580, 0xD4C0, 0xD510, 0xD4D0, 0xD4F0, 0xD4C0, 0xD4C0, 0xD4D0, + 0xD4B0, 0xD480, 0xD490, 0xD480, 0xD490, 0xD480, 0xD4D0, 0xD4E0, 0xD4A0, 0xD480, 0xD470, 0xD490, 0xD430, 0xD3F0, 0xD440, 0xD3C0, + 0xD3D0, 0xD3B0, 0xD320, 0xD390, 0xD380, 0xD370, 0xD340, 0xD2B0, 0xD2C0, 0xD2A0, 0xD280, 0xD250, 0xD250, 0xD290, 0xD270, 0xD260, + 0xD260, 0xD250, 0xD240, 0xD210, 0xD240, 0xD230, 0xD1D0, 0xD1D0, 0xD180, 0xD150, 0xD180, 0xD100, 0xD0D0, 0xD0C0, 0xD0B0, 0xD0A0, + 0xCFA0, 0xCFC0, 0xCF60, 0xCFE0, 0xCFB0, 0xCF60, 0xD010, 0xD000, 0xCFF0, 0xD010, 0xCF70, 0xCF40, 0xCF20, 0xCEA0, 0xCE50, 0xCE90, + 0xCE90, 0xCE20, 0xCDB0, 0xCDF0, 0xCDD0, 0xCD80, 0xCD50, 0xCDB0, 0xCDA0, 0xCD90, 0xCD90, 0xCD00, 0xCCB0, 0xCCF0, 0xCC90, 0xCC70, + 0xCC90, 0xCC50, 0xCC90, 0xCC90, 0xCCD0, 0xCCB0, 0xCD00, 0xCCF0, 0xCCC0, 0xCC60, 0xCC80, 0xCC30, 0xCC20, 0xCB40, 0xCB20, 0xCAD0, + 0xCA30, 0xCAC0, 0xC9F0, 0xC9C0, 0xC960, 0xC950, 0xC9E0, 0xC990, 0xC9B0, 0xC980, 0xC980, 0xC9F0, 0xC9A0, 0xC9D0, 0xC990, 0xC970, + 0xC9A0, 0xC950, 0xC9B0, 0xC970, 0xC940, 0xC930, 0xC920, 0xC930, 0xC940, 0xC890, 0xC890, 0xC840, 0xC810, 0xC870, 0xC840, 0xC860, + 0xC890, 0xC7D0, 0xC820, 0xC830, 0xC890, 0xC860, 0xC850, 0xC8B0, 0xC880, 0xC8B0, 0xC920, 0xC8D0, 0xC990, 0xC940, 0xC950, 0xC910, + 0xC8F0, 0xC8F0, 0xC8F0, 0xC890, 0xC8C0, 0xC880, 0xC890, 0xC8B0, 0xC8A0, 0xC900, 0xC8B0, 0xC8D0, 0xC8E0, 0xC8C0, 0xC8B0, 0xC880, + 0xC8F0, 0xC8F0, 0xC910, 0xC970, 0xC950, 0xC9B0, 0xC9D0, 0xC9D0, 0xCA20, 0xC9F0, 0xCA80, 0xCA80, 0xCAA0, 0xCB40, 0xCB90, 0xCB90, + 0xCBB0, 0xCC40, 0xCBD0, 0xCBE0, 0xCC00, 0xCC30, 0xCBD0, 0xCC30, 0xCBD0, 0xCC80, 0xCC30, 0xCC00, 0xCC70, 0xCC80, 0xCCD0, 0xCCC0, + 0xCCB0, 0xCDA0, 0xCDA0, 0xCE20, 0xCDF0, 0xCD90, 0xCE00, 0xCE00, 0xCE50, 0xCE10, 0xCE10, 0xCE80, 0xCE70, 0xCEE0, 0xCEE0, 0xCF40, + 0xCFD0, 0xD030, 0xD040, 0xD050, 0xD0B0, 0xD070, 0xD080, 0xD0E0, 0xD0E0, 0xD0F0, 0xD150, 0xD140, 0xD0F0, 0xD110, 0xD170, 0xD180, + 0xD160, 0xD150, 0xD170, 0xD1C0, 0xD1C0, 0xD1D0, 0xD1F0, 0xD2A0, 0xD290, 0xD2E0, 0xD300, 0xD310, 0xD350, 0xD390, 0xD3A0, 0xD3F0, + 0xD3C0, 0xD430, 0xD400, 0xD440, 0xD450, 0xD420, 0xD470, 0xD470, 0xD470, 0xD4A0, 0xD490, 0xD4F0, 0xD530, 0xD520, 0xD510, 0xD520, + 0xD550, 0xD5C0, 0xD5B0, 0xD620, 0xD660, 0xD650, 0xD670, 0xD660, 0xD660, 0xD5F0, 0xD610, 0xD640, 0xD630, 0xD6B0, 0xD690, 0xD6E0, + 0xD740, 0xD710, 0xD7B0, 0xD790, 0xD780, 0xD7D0, 0xD730, 0xD7A0, 0xD7C0, 0xD7E0, 0xD7E0, 0xD830, 0xD870, 0xD8C0, 0xD860, 0xD870, + 0xD810, 0xD7A0, 0xD790, 0xD780, 0xD760, 0xD780, 0xD740, 0xD790, 0xD7D0, 0xD7C0, 0xD790, 0xD750, 0xD730, 0xD720, 0xD7D0, 0xD780, + 0xD7D0, 0xD7C0, 0xD7B0, 0xD7F0, 0xD850, 0xD850, 0xD8C0, 0xD8D0, 0xD920, 0xD960, 0xD970, 0xD930, 0xD9F0, 0xDA00, 0xDA20, 0xDA30, + 0xDA10, 0xDA10, 0xD9E0, 0xD9B0, 0xDA00, 0xDA20, 0xD9E0, 0xDA30, 0xDA20, 0xDA40, 0xDA40, 0xDA50, 0xDA60, 0xDA60, 0xDAB0, 0xDA80, + 0xDAF0, 0xDAE0, 0xDB10, 0xDB30, 0xDB20, 0xDB50, 0xDB40, 0xDBB0, 0xDC50, 0xDC20, 0xDCD0, 0xDD20, 0xDCE0, 0xDCD0, 0xDD40, 0xDD20, + 0xDD20, 0xDD20, 0xDCF0, 0xDCB0, 0xDD00, 0xDCC0, 0xDCC0, 0xDC70, 0xDC90, 0xDCA0, 0xDC50, 0xDC90, 0xDCB0, 0xDC70, 0xDC70, 0xDC70, + 0xDC80, 0xDC90, 0xDC50, 0xDC40, 0xDC70, 0xDC30, 0xDC50, 0xDCA0, 0xDCD0, 0xDD10, 0xDD70, 0xDD80, 0xDD80, 0xDE00, 0xDE00, 0xDE90, + 0xDE50, 0xDEC0, 0xDE60, 0xDE50, 0xDE70, 0xDE80, 0xDE20, 0xDE50, 0xDEA0, 0xDEC0, 0xDEC0, 0xDED0, 0xDEE0, 0xDEF0, 0xDF10, 0xDEA0, + 0xDE60, 0xDEA0, 0xDEE0, 0xDEF0, 0xDF60, 0xDF40, 0xDFA0, 0xDFD0, 0xE000, 0xE020, 0xE030, 0xE080, 0xE0A0, 0xE0C0, 0xE0C0, 0xE110, + 0xE150, 0xE170, 0xE150, 0xE130, 0xE150, 0xE0E0, 0xE100, 0xE110, 0xE0C0, 0xE0F0, 0xE130, 0xE1C0, 0xE1F0, 0xE250, 0xE290, 0xE2A0, + 0xE350, 0xE340, 0xE310, 0xE330, 0xE390, 0xE3A0, 0xE3A0, 0xE3D0, 0xE350, 0xE340, 0xE2F0, 0xE2F0, 0xE2D0, 0xE2E0, 0xE2E0, 0xE2C0, + 0xE300, 0xE360, 0xE340, 0xE340, 0xE340, 0xE380, 0xE390, 0xE390, 0xE3B0, 0xE3E0, 0xE460, 0xE3D0, 0xE3F0, 0xE450, 0xE440, 0xE480, + 0xE4D0, 0xE530, 0xE5C0, 0xE650, 0xE6F0, 0xE7A0, 0xE7E0, 0xE880, 0xE870, 0xE870, 0xE830, 0xE8B0, 0xE860, 0xE860, 0xE870, 0xE7D0, + 0xE7E0, 0xE7E0, 0xE790, 0xE7E0, 0xE7B0, 0xE7D0, 0xE870, 0xE830, 0xE900, 0xE8B0, 0xE870, 0xE8C0, 0xE8A0, 0xE910, 0xE920, 0xE940, + 0xE9B0, 0xE950, 0xE9F0, 0xE9D0, 0xE950, 0xE960, 0xE940, 0xE940, 0xE940, 0xE930, 0xE9A0, 0xE9A0, 0xE9B0, 0xE9A0, 0xE9C0, 0xEA10, + 0xEA20, 0xEA60, 0xEA50, 0xEA80, 0xEB20, 0xEB50, 0xEBF0, 0xEBF0, 0xEC40, 0xEC50, 0xEC00, 0xEBE0, 0xEBA0, 0xEBB0, 0xEBE0, 0xEC20, + 0xEC20, 0xEC70, 0xECA0, 0xEC40, 0xECA0, 0xEC50, 0xEC70, 0xEC70, 0xECD0, 0xECB0, 0xECD0, 0xED60, 0xED00, 0xED90, 0xED80, 0xED90, + 0xEDB0, 0xED60, 0xEDC0, 0xED90, 0xED70, 0xEDA0, 0xEDA0, 0xEDF0, 0xEDF0, 0xEDB0, 0xEE00, 0xEE20, 0xEE70, 0xEEC0, 0xEE90, 0xEF30, + 0xEF30, 0xEF90, 0xEFF0, 0xF010, 0xF050, 0xF080, 0xF0C0, 0xF090, 0xF070, 0xF070, 0xF060, 0xF010, 0xF090, 0xF060, 0xF020, 0xF000, + 0xF020, 0xEFF0, 0xEFE0, 0xF050, 0xEFF0, 0xEFE0, 0xF010, 0xF030, 0xF0A0, 0xF0A0, 0xF090, 0xF060, 0xF0A0, 0xF0F0, 0xF150, 0xF130, + 0xF1B0, 0xF1A0, 0xF250, 0xF250, 0xF1A0, 0xF1C0, 0xF220, 0xF250, 0xF290, 0xF210, 0xF2B0, 0xF210, 0xF260, 0xF210, 0xF1D0, 0xF220, + 0xF220, 0xF250, 0xF280, 0xF250, 0xF2E0, 0xF350, 0xF3B0, 0xF3E0, 0xF3C0, 0xF400, 0xF3B0, 0xF3F0, 0xF420, 0xF3C0, 0xF470, 0xF430, + 0xF3E0, 0xF420, 0xF420, 0xF470, 0xF470, 0xF4A0, 0xF480, 0xF440, 0xF480, 0xF470, 0xF440, 0xF4A0, 0xF480, 0xF4E0, 0xF540, 0xF550, + 0xF5E0, 0xF5B0, 0xF5F0, 0xF5D0, 0xF5B0, 0xF5E0, 0xF5C0, 0xF630, 0xF680, 0xF600, 0xF680, 0xF6B0, 0xF6B0, 0xF680, 0xF650, 0xF670, + 0xF640, 0xF680, 0xF670, 0xF660, 0xF600, 0xF630, 0xF660, 0xF640, 0xF6C0, 0xF6B0, 0xF6C0, 0xF750, 0xF760, 0xF760, 0xF750, 0xF700, + 0xF700, 0xF720, 0xF710, 0xF730, 0xF720, 0xF760, 0xF710, 0xF760, 0xF730, 0xF770, 0xF750, 0xF7A0, 0xF7B0, 0xF7D0, 0xF7A0, 0xF800, + 0xF7F0, 0xF850, 0xF810, 0xF800, 0xF790, 0xF790, 0xF770, 0xF7A0, 0xF730, 0xF7A0, 0xF7A0, 0xF790, 0xF880, 0xF890, 0xF900, 0xF910, + 0xF890, 0xF8E0, 0xF840, 0xF800, 0xF860, 0xF870, 0xF8E0, 0xF900, 0xF900, 0xF920, 0xF8D0, 0xF8F0, 0xF880, 0xF8E0, 0xF890, 0xF860, + 0xF900, 0xF900, 0xF8F0, 0xF900, 0xF820, 0xF890, 0xF870, 0xF850, 0xF860, 0xF840, 0xF8D0, 0xF8D0, 0xF930, 0xF960, 0xF940, 0xF950, + 0xF950, 0xF970, 0xF9C0, 0xF990, 0xFA30, 0xFA20, 0xF9C0, 0xFA30, 0xFA10, 0xFA60, 0xFA20, 0xF9C0, 0xF9E0, 0xF980, 0xF990, 0xF9B0, + 0xF960, 0xFA20, 0xFA00, 0xF9E0, 0xF9B0, 0xF970, 0xF950, 0xF960, 0xF9A0, 0xF950, 0xF950, 0xF9F0, 0xFA60, 0xFA40, 0xFA80, 0xFA50, + 0xFB40, 0xFB00, 0xFB20, 0xFB40, 0xFA40, 0xFAB0, 0xFAA0, 0xFAA0, 0xFA70, 0xFA50, 0xFAD0, 0xFB00, 0xFB20, 0xFB50, 0xFB30, 0xFB60, + 0xFB40, 0xFB70, 0xFB30, 0xFB00, 0xFB00, 0xFB10, 0xFA90, 0xFAB0, 0xFAA0, 0xFB40, 0xFB90, 0xFB60, 0xFBD0, 0xFC30, 0xFC30, 0xFC20, + 0xFC00, 0xFBF0, 0xFBF0, 0xFC00, 0xFC10, 0xFB90, 0xFBE0, 0xFBC0, 0xFB90, 0xFB90, 0xFB60, 0xFB50, 0xFB20, 0xFB30, 0xFB80, 0xFB90, +}; + +#endif // MIC_BLOW_H diff --git a/src/frontend/qt_sdl/AudioSettingsDialog.ui b/src/frontend/qt_sdl/AudioSettingsDialog.ui index b6c215e..c4e993e 100644 --- a/src/frontend/qt_sdl/AudioSettingsDialog.ui +++ b/src/frontend/qt_sdl/AudioSettingsDialog.ui @@ -95,7 +95,7 @@ <html><head/><body><p>Noise will be forwarded to the emulated microphone, simulating blowing into the microphone.</p></body></html> - White noise + Blow noise diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index caa78e9..ffd7d17 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -12,6 +12,7 @@ SET(SOURCES_QT_SDL ../Util_ROM.cpp ../Util_Audio.cpp ../FrontendUtil.h + ../mic_blow.h ../../../melon.qrc ) -- cgit v1.2.3 From 8f9369beebf60f3b10d75f50507b194f2ccdaceb Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 21 May 2020 18:43:07 +0200 Subject: add screen layout system --- src/frontend/FrontendUtil.h | 26 +++ src/frontend/Util_Video.cpp | 334 +++++++++++++++++++++++++++++++++++++ src/frontend/qt_sdl/CMakeLists.txt | 1 + src/frontend/qt_sdl/main.cpp | 213 ++++++++++++++++++----- src/frontend/qt_sdl/main.h | 17 +- 5 files changed, 545 insertions(+), 46 deletions(-) create mode 100644 src/frontend/Util_Video.cpp (limited to 'src') diff --git a/src/frontend/FrontendUtil.h b/src/frontend/FrontendUtil.h index 6a6f8ea..1fd7329 100644 --- a/src/frontend/FrontendUtil.h +++ b/src/frontend/FrontendUtil.h @@ -89,6 +89,32 @@ bool SaveState(const char* filename); void UndoStateLoad(); +// setup the display layout based on the provided display size and parameters +// * screenWidth/screenHeight: size of the host display +// * screenLayout: how the DS screens are laid out +// 0 = natural (top screen above bottom screen always) +// 1 = vertical +// 2 = horizontal +// * rotation: angle at which the DS screens are presented: 0/1/2/3 = 0/90/180/270 +// * sizing: how the display size is shared between the two screens +// 0 = even (both screens get same size) +// 1 = emphasize top screen (make top screen as big as possible, fit bottom screen in remaining space) +// 2 = emphasize bottom screen +// * screenGap: size of the gap between the two screens +// * integerScale: force screens to be scaled up at integer scaling factors +void SetupScreenLayout(int screenWidth, int screenHeight, int screenLayout, int rotation, int sizing, int screenGap, bool integerScale); + +// get a 2x3 transform matrix for the given screen (0=top, 1=bottom) +// note: the transform assumes an origin point at the top left of the display, +// X going left and Y going down +// for each screen the source coordinates should be (0,0) and (256,192) +float* GetScreenTransform(int screen); + +// de-transform the provided host display coordinates to get coordinates +// on the bottom screen +void GetTouchCoords(int& x, int& y); + + // initialize the audio utility void Init_Audio(int outputfreq); diff --git a/src/frontend/Util_Video.cpp b/src/frontend/Util_Video.cpp new file mode 100644 index 0000000..cd4e21c --- /dev/null +++ b/src/frontend/Util_Video.cpp @@ -0,0 +1,334 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include +#include +#include +#include +#include + +#include "FrontendUtil.h" + + +namespace Frontend +{ + +float TopScreenMtx[6]; +float BotScreenMtx[6]; +float TouchMtx[6]; + + +void M23_Identity(float* m) +{ + m[0] = 1; m[1] = 0; + m[2] = 0; m[3] = 1; + m[4] = 0; m[5] = 0; +} + +void M23_Scale(float* m, float s) +{ + m[0] *= s; m[1] *= s; + m[2] *= s; m[3] *= s; + m[4] *= s; m[5] *= s; +} + +void M23_RotateFast(float* m, int angle) +{ + if (angle == 0) return; + + float temp[4]; memcpy(temp, m, sizeof(float)*4); + + switch (angle) + { + case 1: // 90 + m[0] = temp[2]; + m[1] = temp[3]; + m[2] = -temp[0]; + m[3] = -temp[1]; + break; + + case 2: // 180 + m[0] = -temp[0]; + m[1] = -temp[1]; + m[2] = -temp[2]; + m[3] = -temp[3]; + break; + + case 3: // 270 + m[0] = -temp[2]; + m[1] = -temp[3]; + m[2] = temp[0]; + m[3] = temp[1]; + break; + } +} + +void M23_Translate(float* m, float tx, float ty) +{ + m[4] += tx; + m[5] += ty; +} + +void M23_Multiply(float* m, float* _a, float* _b) +{ + float a[6]; memcpy(a, _a, 6*sizeof(float)); + float b[6]; memcpy(b, _b, 6*sizeof(float)); + + m[0] = (a[0] * b[0]) + (a[2] * b[1]); + m[1] = (a[1] * b[0]) + (a[3] * b[1]); + + m[2] = (a[0] * b[2]) + (a[2] * b[3]); + m[3] = (a[1] * b[2]) + (a[3] * b[3]); + + m[4] = (a[0] * b[4]) + (a[2] * b[5]) + a[4]; + m[5] = (a[1] * b[4]) + (a[3] * b[5]) + a[5]; +} + +void M23_Transform(float* m, float& x, float& y) +{ + float vx = x; + float vy = y; + + x = (vx * m[0]) + (vy * m[2]) + m[4]; + y = (vx * m[1]) + (vy * m[3]) + m[5]; +} + + +void SetupScreenLayout(int screenWidth, int screenHeight, int screenLayout, int rotation, int sizing, int screenGap, bool integerScale) +{ + float refpoints[4][2] = + { + {0, 0}, {256, 192}, + {0, 0}, {256, 192} + }; + + int layout = screenLayout == 0 + ? ((rotation % 2 == 0) ? 0 : 1) + : screenLayout - 1; + + float botScale = 1; + float botTrans[4] = {0}; + + M23_Identity(TopScreenMtx); + M23_Identity(BotScreenMtx); + + M23_Translate(TopScreenMtx, -256/2, -192/2); + M23_Translate(BotScreenMtx, -256/2, -192/2); + + // rotation + { + float rotmtx[6]; + M23_Identity(rotmtx); + + M23_RotateFast(rotmtx, rotation); + M23_Multiply(TopScreenMtx, rotmtx, TopScreenMtx); + M23_Multiply(BotScreenMtx, rotmtx, BotScreenMtx); + + M23_Transform(TopScreenMtx, refpoints[0][0], refpoints[0][1]); + M23_Transform(TopScreenMtx, refpoints[1][0], refpoints[1][1]); + M23_Transform(BotScreenMtx, refpoints[2][0], refpoints[2][1]); + M23_Transform(BotScreenMtx, refpoints[3][0], refpoints[3][1]); + } + + // move screens apart + { + int idx = layout == 0 ? 1 : 0; + float offset = + (((layout == 0 && (rotation % 2 == 0)) || (layout == 1 && (rotation % 2 == 1)) + ? 192.f : 256.f) + + screenGap) / 2.f; + if (rotation == 1 || rotation == 2) + offset *= -1.f; + + M23_Translate(TopScreenMtx, (idx==0)?-offset:0, (idx==1)?-offset:0); + M23_Translate(BotScreenMtx, (idx==0)?offset:0, (idx==1)?offset:0); + + refpoints[0][idx] -= offset; + refpoints[1][idx] -= offset; + refpoints[2][idx] += offset; + refpoints[3][idx] += offset; + + botTrans[idx] = offset; + } + + // scale + { + if (sizing == 0) + { + float minX = refpoints[0][0], maxX = minX; + float minY = refpoints[0][1], maxY = minY; + + for (int i = 1; i < 4; i++) + { + minX = std::min(minX, refpoints[i][0]); + minY = std::min(minY, refpoints[i][1]); + maxX = std::max(maxX, refpoints[i][0]); + maxY = std::max(maxY, refpoints[i][1]); + } + + float hSize = maxX - minX; + float vSize = maxY - minY; + + // scale evenly + float scale = std::min(screenWidth / hSize, screenHeight / vSize); + + if (integerScale) + scale = floor(scale); + + M23_Scale(TopScreenMtx, scale); + M23_Scale(BotScreenMtx, scale); + + for (int i = 0; i < 4; i++) + { + refpoints[i][0] *= scale; + refpoints[i][1] *= scale; + } + + botScale = scale; + } + else + { + int primOffset = (sizing == 1) ? 0 : 2; + int secOffset = (sizing == 1) ? 2 : 0; + float* primMtx = (sizing == 1) ? TopScreenMtx : BotScreenMtx; + float* secMtx = (sizing == 1) ? BotScreenMtx : TopScreenMtx; + + float primMinX = refpoints[primOffset][0], primMaxX = primMinX; + float primMinY = refpoints[primOffset][1], primMaxY = primMinY; + float secMinX = refpoints[secOffset][0], secMaxX = secMinX; + float secMinY = refpoints[secOffset][1], secMaxY = secMinY; + + primMinX = std::min(primMinX, refpoints[primOffset+1][0]); + primMinY = std::min(primMinY, refpoints[primOffset+1][1]); + primMaxX = std::max(primMaxX, refpoints[primOffset+1][0]); + primMaxY = std::max(primMaxY, refpoints[primOffset+1][1]); + + secMinX = std::min(secMinX, refpoints[secOffset+1][0]); + secMinY = std::min(secMinY, refpoints[secOffset+1][1]); + secMaxX = std::max(secMaxX, refpoints[secOffset+1][0]); + secMaxY = std::max(secMaxY, refpoints[secOffset+1][1]); + + float primHSize = layout == 1 ? std::max(primMaxX, -primMinX) : primMaxX - primMinX; + float primVSize = layout == 0 ? std::max(primMaxY, -primMinY) : primMaxY - primMinY; + + float secHSize = layout == 1 ? std::max(secMaxX, -secMinX) : secMaxX - secMinX; + float secVSize = layout == 0 ? std::max(secMaxY, -secMinY) : secMaxY - secMinY; + + float primScale = std::min(screenWidth / primHSize, screenHeight / primVSize); + float secScale = 1.f; + + if (layout == 0) + { + if (screenHeight - primVSize * primScale < secVSize) + primScale = std::min((screenWidth - secHSize) / primHSize, (screenHeight - secVSize) / primVSize); + else + secScale = std::min((screenHeight - primVSize * primScale) / secVSize, screenWidth / secHSize); + } + else + { + if (screenWidth - primHSize * primScale < secHSize) + primScale = std::min((screenWidth - secHSize) / primHSize, (screenHeight - secVSize) / primVSize); + else + secScale = std::min((screenWidth - primHSize * primScale) / secHSize, screenHeight / secVSize); + } + + if (integerScale) + { + primScale = floor(primScale); + secScale = floor(secScale); + } + + M23_Scale(primMtx, primScale); + M23_Scale(secMtx, secScale); + + refpoints[primOffset+0][0] *= primScale; + refpoints[primOffset+0][1] *= primScale; + refpoints[primOffset+1][0] *= primScale; + refpoints[primOffset+1][1] *= primScale; + refpoints[secOffset+0][0] *= secScale; + refpoints[secOffset+0][1] *= secScale; + refpoints[secOffset+1][0] *= secScale; + refpoints[secOffset+1][1] *= secScale; + + botScale = (sizing == 1) ? secScale : primScale; + } + } + + // position + { + float minX = refpoints[0][0], maxX = minX; + float minY = refpoints[0][1], maxY = minY; + + for (int i = 1; i < 4; i++) + { + minX = std::min(minX, refpoints[i][0]); + minY = std::min(minY, refpoints[i][1]); + maxX = std::max(maxX, refpoints[i][0]); + maxY = std::max(maxY, refpoints[i][1]); + } + + float width = maxX - minX; + float height = maxY - minY; + + float tx = (screenWidth/2) - (width/2) - minX; + float ty = (screenHeight/2) - (height/2) - minY; + + M23_Translate(TopScreenMtx, tx, ty); + M23_Translate(BotScreenMtx, tx, ty); + + botTrans[2] = tx; botTrans[3] = ty; + } + + // prepare a 'reverse' matrix for the touchscreen + // this matrix undoes the transforms applied to the bottom screen + // and can be used to calculate touchscreen coords from host screen coords + { + M23_Identity(TouchMtx); + + M23_Translate(TouchMtx, -botTrans[2], -botTrans[3]); + M23_Scale(TouchMtx, 1.f / botScale); + M23_Translate(TouchMtx, -botTrans[0], -botTrans[1]); + + float rotmtx[6]; + M23_Identity(rotmtx); + M23_RotateFast(rotmtx, (4-rotation) & 3); + M23_Multiply(TouchMtx, rotmtx, TouchMtx); + + M23_Translate(TouchMtx, 256/2, 192/2); + } +} + +float* GetScreenTransform(int screen) +{ + if (screen == 0) return TopScreenMtx; + else return BotScreenMtx; +} + +void GetTouchCoords(int& x, int& y) +{ + float vx = x; + float vy = y; + + M23_Transform(TouchMtx, vx, vy); + + x = (int)vx; + y = (int)vy; +} + +} + diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index ffd7d17..7bc81f0 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -10,6 +10,7 @@ SET(SOURCES_QT_SDL PlatformConfig.cpp ../Util_ROM.cpp + ../Util_Video.cpp ../Util_Audio.cpp ../FrontendUtil.h ../mic_blow.h diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 245324f..0d10378 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -62,6 +62,8 @@ bool RunningSomething; MainWindow* mainWindow; EmuThread* emuThread; +int autoScreenSizing = 0; + SDL_AudioDeviceID audioDevice; int audioFreq; SDL_cond* audioSync; @@ -250,16 +252,19 @@ EmuThread::EmuThread(QObject* parent) : QThread(parent) connect(this, SIGNAL(windowEmuStop()), mainWindow, SLOT(onEmuStop())); connect(this, SIGNAL(windowEmuPause()), mainWindow->actPause, SLOT(trigger())); connect(this, SIGNAL(windowEmuReset()), mainWindow->actReset, SLOT(trigger())); + connect(this, SIGNAL(screenLayoutChange()), mainWindow->panel, SLOT(onScreenLayoutChanged())); } void EmuThread::run() { + u32 mainScreenPos[3]; + NDS::Init(); - /*MainScreenPos[0] = 0; - MainScreenPos[1] = 0; - MainScreenPos[2] = 0; - AutoScreenSizing = 0;*/ + mainScreenPos[0] = 0; + mainScreenPos[1] = 0; + mainScreenPos[2] = 0; + autoScreenSizing = 0; /*if (Screen_UseGL) { @@ -333,14 +338,14 @@ void EmuThread::run() }*/ // auto screen layout - /*{ - MainScreenPos[2] = MainScreenPos[1]; - MainScreenPos[1] = MainScreenPos[0]; - MainScreenPos[0] = NDS::PowerControl9 >> 15; + { + mainScreenPos[2] = mainScreenPos[1]; + mainScreenPos[1] = mainScreenPos[0]; + mainScreenPos[0] = NDS::PowerControl9 >> 15; int guess; - if (MainScreenPos[0] == MainScreenPos[2] && - MainScreenPos[0] != MainScreenPos[1]) + if (mainScreenPos[0] == mainScreenPos[2] && + mainScreenPos[0] != mainScreenPos[1]) { // constant flickering, likely displaying 3D on both screens // TODO: when both screens are used for 2D only...??? @@ -348,18 +353,18 @@ void EmuThread::run() } else { - if (MainScreenPos[0] == 1) + if (mainScreenPos[0] == 1) guess = 1; else guess = 2; } - if (guess != AutoScreenSizing) + if (guess != autoScreenSizing) { - AutoScreenSizing = guess; - SetupScreenRects(WindowWidth, WindowHeight); + autoScreenSizing = guess; + emit screenLayoutChange(); } - }*/ + } // emulate u32 nlines = NDS::RunFrame(); @@ -540,6 +545,9 @@ MainWindowPanel::MainWindowPanel(QWidget* parent) : QWidget(parent) screen[0] = new QImage(256, 192, QImage::Format_RGB32); screen[1] = new QImage(256, 192, QImage::Format_RGB32); + screenTrans[0].reset(); + screenTrans[1].reset(); + touching = false; } @@ -549,6 +557,64 @@ MainWindowPanel::~MainWindowPanel() delete screen[1]; } +void MainWindowPanel::ensureProperMinSize() +{ + bool isHori = (Config::ScreenRotation == 1 || Config::ScreenRotation == 3); + int gap = Config::ScreenGap; + + int w = 256; + int h = 192; + + if (Config::ScreenLayout == 0) // natural + { + if (isHori) + setMinimumSize(h+gap+h, w); + else + setMinimumSize(w, h+gap+h); + } + else if (Config::ScreenLayout == 1) // vertical + { + if (isHori) + setMinimumSize(h, w+gap+w); + else + setMinimumSize(w, h+gap+h); + } + else // horizontal + { + if (isHori) + setMinimumSize(h+gap+h, w); + else + setMinimumSize(w+gap+w, h); + } +} + +void MainWindowPanel::setupScreenLayout() +{ + int w = width(); + int h = height(); + float* mtx; + + int sizing = Config::ScreenSizing; + if (sizing == 3) sizing = autoScreenSizing; + + Frontend::SetupScreenLayout(w, h, + Config::ScreenLayout, + Config::ScreenRotation, + sizing, + Config::ScreenGap, + Config::IntegerScaling != 0); + + mtx = Frontend::GetScreenTransform(0); + screenTrans[0].setMatrix(mtx[0], mtx[1], 0.f, + mtx[2], mtx[3], 0.f, + mtx[4], mtx[5], 1.f); + + mtx = Frontend::GetScreenTransform(1); + screenTrans[1].setMatrix(mtx[0], mtx[1], 0.f, + mtx[2], mtx[3], 0.f, + mtx[4], mtx[5], 1.f); +} + void MainWindowPanel::paintEvent(QPaintEvent* event) { QPainter painter(this); @@ -562,27 +628,18 @@ void MainWindowPanel::paintEvent(QPaintEvent* event) memcpy(screen[0]->scanLine(0), GPU::Framebuffer[frontbuf][0], 256*192*4); memcpy(screen[1]->scanLine(0), GPU::Framebuffer[frontbuf][1], 256*192*4); - QRect src = QRect(0, 0, 256, 192); + QRect screenrc = QRect(0, 0, 256, 192); - QRect dstTop = QRect(0, 0, 256, 192); // TODO - QRect dstBot = QRect(0, 192, 256, 192); // TODO + painter.setTransform(screenTrans[0]); + painter.drawImage(screenrc, *screen[0]); - painter.drawImage(dstTop, *screen[0]); - painter.drawImage(dstBot, *screen[1]); + painter.setTransform(screenTrans[1]); + painter.drawImage(screenrc, *screen[1]); } - -void MainWindowPanel::transformTSCoords(int& x, int& y) +void MainWindowPanel::resizeEvent(QResizeEvent* event) { - // TODO: actual screen de-transform taking screen layout/rotation/etc into account - - y -= 192; - - // clamp to screen range - if (x < 0) x = 0; - else if (x > 255) x = 255; - if (y < 0) y = 0; - else if (y > 191) y = 191; + setupScreenLayout(); } void MainWindowPanel::mousePressEvent(QMouseEvent* event) @@ -593,11 +650,11 @@ void MainWindowPanel::mousePressEvent(QMouseEvent* event) int x = event->pos().x(); int y = event->pos().y(); - if (x >= 0 && x < 256 && y >= 192 && y < 384) + Frontend::GetTouchCoords(x, y); + + if (x >= 0 && x < 256 && y >= 0 && y < 192) { touching = true; - - transformTSCoords(x, y); NDS::TouchScreen(x, y); } } @@ -623,10 +680,22 @@ void MainWindowPanel::mouseMoveEvent(QMouseEvent* event) int x = event->pos().x(); int y = event->pos().y(); - transformTSCoords(x, y); + Frontend::GetTouchCoords(x, y); + + // clamp to screen range + if (x < 0) x = 0; + else if (x > 255) x = 255; + if (y < 0) y = 0; + else if (y > 191) y = 191; + NDS::TouchScreen(x, y); } +void MainWindowPanel::onScreenLayoutChanged() +{ + setupScreenLayout(); +} + MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { @@ -750,7 +819,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) int data = i*90; actScreenRotation[i] = submenu->addAction(QString("%1°").arg(data)); actScreenRotation[i]->setActionGroup(grpScreenRotation); - actScreenRotation[i]->setData(QVariant(data)); + actScreenRotation[i]->setData(QVariant(i)); actScreenRotation[i]->setCheckable(true); } @@ -834,8 +903,9 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) panel = new MainWindowPanel(this); setCentralWidget(panel); - panel->setMinimumSize(256, 384); + panel->ensureProperMinSize(); + resize(Config::WindowWidth, Config::WindowHeight); for (int i = 0; i < 9; i++) { @@ -877,6 +947,16 @@ MainWindow::~MainWindow() { } +void MainWindow::resizeEvent(QResizeEvent* event) +{ + int w = event->size().width(); + int h = event->size().height(); + + Config::WindowWidth = w; + Config::WindowHeight = h; + + // TODO: detect when the window gets maximized! +} void MainWindow::keyPressEvent(QKeyEvent* event) { @@ -1264,32 +1344,79 @@ void MainWindow::onChangeSavestateSRAMReloc(bool checked) void MainWindow::onChangeScreenSize() { - // + int factor = ((QAction*)sender())->data().toInt(); + + bool isHori = (Config::ScreenRotation == 1 || Config::ScreenRotation == 3); + int gap = Config::ScreenGap; + + int w = 256*factor; + int h = 192*factor; + + QSize diff = size() - panel->size(); + + if (Config::ScreenLayout == 0) // natural + { + if (isHori) + resize(QSize(h+gap+h, w) + diff); + else + resize(QSize(w, h+gap+h) + diff); + } + else if (Config::ScreenLayout == 1) // vertical + { + if (isHori) + resize(QSize(h, w+gap+w) + diff); + else + resize(QSize(w, h+gap+h) + diff); + } + else // horizontal + { + if (isHori) + resize(QSize(h+gap+h, w) + diff); + else + resize(QSize(w+gap+w, h) + diff); + } } void MainWindow::onChangeScreenRotation(QAction* act) { - // + int rot = act->data().toInt(); + Config::ScreenRotation = rot; + + panel->ensureProperMinSize(); + panel->setupScreenLayout(); } void MainWindow::onChangeScreenGap(QAction* act) { - // + int gap = act->data().toInt(); + Config::ScreenGap = gap; + + panel->ensureProperMinSize(); + panel->setupScreenLayout(); } void MainWindow::onChangeScreenLayout(QAction* act) { - // + int layout = act->data().toInt(); + Config::ScreenLayout = layout; + + panel->ensureProperMinSize(); + panel->setupScreenLayout(); } void MainWindow::onChangeScreenSizing(QAction* act) { - // + int sizing = act->data().toInt(); + Config::ScreenSizing = sizing; + + panel->setupScreenLayout(); } void MainWindow::onChangeIntegerScaling(bool checked) { - // + Config::IntegerScaling = checked?1:0; + + panel->setupScreenLayout(); } void MainWindow::onChangeScreenFiltering(bool checked) diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 7051a08..2d14eea 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -54,6 +54,8 @@ signals: void windowLimitFPSChange(); + void screenLayoutChange(); + private: volatile int EmuStatus; int PrevEmuStatus; @@ -69,18 +71,25 @@ public: explicit MainWindowPanel(QWidget* parent); ~MainWindowPanel(); + void ensureProperMinSize(); + void setupScreenLayout(); + protected: void paintEvent(QPaintEvent* event) override; + void resizeEvent(QResizeEvent* event) override; + void mousePressEvent(QMouseEvent* event) override; void mouseReleaseEvent(QMouseEvent* event) override; void mouseMoveEvent(QMouseEvent* event) override; +private slots: + void onScreenLayoutChanged(); + private: QImage* screen[2]; + QTransform screenTrans[2]; bool touching; - - void transformTSCoords(int& x, int& y); }; @@ -93,6 +102,8 @@ public: ~MainWindow(); protected: + void resizeEvent(QResizeEvent* event) override; + void keyPressEvent(QKeyEvent* event) override; void keyReleaseEvent(QKeyEvent* event) override; @@ -138,9 +149,9 @@ private slots: private: QString loadErrorStr(int error); +public: MainWindowPanel* panel; -public: QAction* actOpenROM; QAction* actBootFirmware; QAction* actSaveState[9]; -- cgit v1.2.3 From 5dcf57e86dc8e768d33406fb446f25bf186eef4d Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 21 May 2020 18:49:34 +0200 Subject: add screen filtering --- src/frontend/qt_sdl/main.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 0d10378..36a3b8e 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -628,6 +628,8 @@ void MainWindowPanel::paintEvent(QPaintEvent* event) memcpy(screen[0]->scanLine(0), GPU::Framebuffer[frontbuf][0], 256*192*4); memcpy(screen[1]->scanLine(0), GPU::Framebuffer[frontbuf][1], 256*192*4); + painter.setRenderHint(QPainter::SmoothPixmapTransform, Config::ScreenFilter!=0); + QRect screenrc = QRect(0, 0, 256, 192); painter.setTransform(screenTrans[0]); -- cgit v1.2.3 From ffd9c61bf79852f2364166c4770719146500f4b9 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Thu, 21 May 2020 19:45:33 +0200 Subject: fix screen layout with emphasis --- src/frontend/Util_Video.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/frontend/Util_Video.cpp b/src/frontend/Util_Video.cpp index cd4e21c..0f5ff66 100644 --- a/src/frontend/Util_Video.cpp +++ b/src/frontend/Util_Video.cpp @@ -235,14 +235,14 @@ void SetupScreenLayout(int screenWidth, int screenHeight, int screenLayout, int if (layout == 0) { if (screenHeight - primVSize * primScale < secVSize) - primScale = std::min((screenWidth - secHSize) / primHSize, (screenHeight - secVSize) / primVSize); + primScale = std::min(screenWidth / primHSize, (screenHeight - secVSize) / primVSize); else secScale = std::min((screenHeight - primVSize * primScale) / secVSize, screenWidth / secHSize); } else { if (screenWidth - primHSize * primScale < secHSize) - primScale = std::min((screenWidth - secHSize) / primHSize, (screenHeight - secVSize) / primVSize); + primScale = std::min((screenWidth - secHSize) / primHSize, screenHeight / primVSize); else secScale = std::min((screenWidth - primHSize * primScale) / secHSize, screenHeight / secVSize); } -- cgit v1.2.3 From f69f3fcb7a6f5eabe07de3db58409aee036348ea Mon Sep 17 00:00:00 2001 From: Arisotura Date: Fri, 22 May 2020 13:54:29 +0200 Subject: * safer window update * only do auto screen sizing if needed --- src/frontend/qt_sdl/main.cpp | 9 ++++++--- src/frontend/qt_sdl/main.h | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 36a3b8e..922206f 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -247,6 +247,8 @@ EmuThread::EmuThread(QObject* parent) : QThread(parent) EmuRunning = 2; RunningSomething = false; + connect(this, SIGNAL(windowUpdate()), mainWindow, SLOT(update())); + //connect(this, SIGNAL(windowUpdate()), mainWindow, SLOT(repaint())); connect(this, SIGNAL(windowTitleChange(QString)), mainWindow, SLOT(onTitleUpdate(QString))); connect(this, SIGNAL(windowEmuStart()), mainWindow, SLOT(onEmuStart())); connect(this, SIGNAL(windowEmuStop()), mainWindow, SLOT(onEmuStop())); @@ -338,6 +340,7 @@ void EmuThread::run() }*/ // auto screen layout + if (Config::ScreenSizing == 3) { mainScreenPos[2] = mainScreenPos[1]; mainScreenPos[1] = mainScreenPos[0]; @@ -381,7 +384,7 @@ void EmuThread::run() uiGLEnd(GLContext); } uiAreaQueueRedrawAll(MainDrawArea);*/ - mainWindow->update(); + emit windowUpdate(); bool fastforward = Input::HotkeyDown(HK_FastForward); @@ -461,7 +464,7 @@ void EmuThread::run() uiGLEnd(GLContext); } uiAreaQueueRedrawAll(MainDrawArea);*/ - mainWindow->update(); + emit windowUpdate(); //if (Screen_UseGL) uiGLMakeContextCurrent(NULL); @@ -630,7 +633,7 @@ void MainWindowPanel::paintEvent(QPaintEvent* event) painter.setRenderHint(QPainter::SmoothPixmapTransform, Config::ScreenFilter!=0); - QRect screenrc = QRect(0, 0, 256, 192); + QRect screenrc(0, 0, 256, 192); painter.setTransform(screenTrans[0]); painter.drawImage(screenrc, *screen[0]); diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 2d14eea..c0dc465 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -45,6 +45,7 @@ public: bool emuIsRunning(); signals: + void windowUpdate(); void windowTitleChange(QString title); void windowEmuStart(); -- cgit v1.2.3 From 16252a85e70feaa1bd10312a357ac74bd677ade3 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 24 May 2020 23:16:56 +0200 Subject: separate screen handling shit to a specialized class --- src/frontend/FrontendUtil.h | 5 +- src/frontend/Util_Video.cpp | 6 +- src/frontend/qt_sdl/main.cpp | 168 +++++++++++++++++++++++++------------------ src/frontend/qt_sdl/main.h | 22 +++++- 4 files changed, 122 insertions(+), 79 deletions(-) (limited to 'src') diff --git a/src/frontend/FrontendUtil.h b/src/frontend/FrontendUtil.h index 1fd7329..359018f 100644 --- a/src/frontend/FrontendUtil.h +++ b/src/frontend/FrontendUtil.h @@ -104,11 +104,12 @@ void UndoStateLoad(); // * integerScale: force screens to be scaled up at integer scaling factors void SetupScreenLayout(int screenWidth, int screenHeight, int screenLayout, int rotation, int sizing, int screenGap, bool integerScale); -// get a 2x3 transform matrix for the given screen (0=top, 1=bottom) +// get a 2x3 transform matrix for each screen // note: the transform assumes an origin point at the top left of the display, // X going left and Y going down // for each screen the source coordinates should be (0,0) and (256,192) -float* GetScreenTransform(int screen); +// 'top' and 'bot' should point each to an array of 6 floats +void GetScreenTransforms(float* top, float* bot); // de-transform the provided host display coordinates to get coordinates // on the bottom screen diff --git a/src/frontend/Util_Video.cpp b/src/frontend/Util_Video.cpp index 0f5ff66..87cb9b5 100644 --- a/src/frontend/Util_Video.cpp +++ b/src/frontend/Util_Video.cpp @@ -313,10 +313,10 @@ void SetupScreenLayout(int screenWidth, int screenHeight, int screenLayout, int } } -float* GetScreenTransform(int screen) +void GetScreenTransforms(float* top, float* bot) { - if (screen == 0) return TopScreenMtx; - else return BotScreenMtx; + memcpy(top, TopScreenMtx, 6*sizeof(float)); + memcpy(bot, BotScreenMtx, 6*sizeof(float)); } void GetTouchCoords(int& x, int& y) diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 922206f..0e0a21b 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -543,24 +543,22 @@ bool EmuThread::emuIsRunning() } -MainWindowPanel::MainWindowPanel(QWidget* parent) : QWidget(parent) +void ScreenHandler::screenSetupLayout(int w, int h) { - screen[0] = new QImage(256, 192, QImage::Format_RGB32); - screen[1] = new QImage(256, 192, QImage::Format_RGB32); - - screenTrans[0].reset(); - screenTrans[1].reset(); + int sizing = Config::ScreenSizing; + if (sizing == 3) sizing = autoScreenSizing; - touching = false; -} + Frontend::SetupScreenLayout(w, h, + Config::ScreenLayout, + Config::ScreenRotation, + sizing, + Config::ScreenGap, + Config::IntegerScaling != 0); -MainWindowPanel::~MainWindowPanel() -{ - delete screen[0]; - delete screen[1]; + Frontend::GetScreenTransforms(screenMatrix[0], screenMatrix[1]); } -void MainWindowPanel::ensureProperMinSize() +QSize ScreenHandler::screenGetMinSize() { bool isHori = (Config::ScreenRotation == 1 || Config::ScreenRotation == 3); int gap = Config::ScreenGap; @@ -571,48 +569,110 @@ void MainWindowPanel::ensureProperMinSize() if (Config::ScreenLayout == 0) // natural { if (isHori) - setMinimumSize(h+gap+h, w); + return QSize(h+gap+h, w); else - setMinimumSize(w, h+gap+h); + return QSize(w, h+gap+h); } else if (Config::ScreenLayout == 1) // vertical { if (isHori) - setMinimumSize(h, w+gap+w); + return QSize(h, w+gap+w); else - setMinimumSize(w, h+gap+h); + return QSize(w, h+gap+h); } else // horizontal { if (isHori) - setMinimumSize(h+gap+h, w); + return QSize(h+gap+h, w); else - setMinimumSize(w+gap+w, h); + return QSize(w+gap+w, h); + } +} + +void ScreenHandler::screenOnMousePress(QMouseEvent* event) +{ + event->accept(); + if (event->button() != Qt::LeftButton) return; + + int x = event->pos().x(); + int y = event->pos().y(); + + Frontend::GetTouchCoords(x, y); + + if (x >= 0 && x < 256 && y >= 0 && y < 192) + { + touching = true; + NDS::TouchScreen(x, y); + } +} + +void ScreenHandler::screenOnMouseRelease(QMouseEvent* event) +{ + event->accept(); + if (event->button() != Qt::LeftButton) return; + + if (touching) + { + touching = false; + NDS::ReleaseScreen(); } } +void ScreenHandler::screenOnMouseMove(QMouseEvent* event) +{ + event->accept(); + if (!(event->buttons() & Qt::LeftButton)) return; + if (!touching) return; + + int x = event->pos().x(); + int y = event->pos().y(); + + Frontend::GetTouchCoords(x, y); + + // clamp to screen range + if (x < 0) x = 0; + else if (x > 255) x = 255; + if (y < 0) y = 0; + else if (y > 191) y = 191; + + NDS::TouchScreen(x, y); +} + + +MainWindowPanel::MainWindowPanel(QWidget* parent) : QWidget(parent) +{ + screen[0] = QImage(256, 192, QImage::Format_RGB32); + screen[1] = QImage(256, 192, QImage::Format_RGB32); + + screenTrans[0].reset(); + screenTrans[1].reset(); + + touching = false; +} + +MainWindowPanel::~MainWindowPanel() +{ +} + +void MainWindowPanel::ensureProperMinSize() +{ + setMinimumSize(screenGetMinSize()); +} + void MainWindowPanel::setupScreenLayout() { int w = width(); int h = height(); float* mtx; - int sizing = Config::ScreenSizing; - if (sizing == 3) sizing = autoScreenSizing; - - Frontend::SetupScreenLayout(w, h, - Config::ScreenLayout, - Config::ScreenRotation, - sizing, - Config::ScreenGap, - Config::IntegerScaling != 0); + screenSetupLayout(w, h); - mtx = Frontend::GetScreenTransform(0); + mtx = screenMatrix[0]; screenTrans[0].setMatrix(mtx[0], mtx[1], 0.f, mtx[2], mtx[3], 0.f, mtx[4], mtx[5], 1.f); - mtx = Frontend::GetScreenTransform(1); + mtx = screenMatrix[1]; screenTrans[1].setMatrix(mtx[0], mtx[1], 0.f, mtx[2], mtx[3], 0.f, mtx[4], mtx[5], 1.f); @@ -628,18 +688,18 @@ void MainWindowPanel::paintEvent(QPaintEvent* event) int frontbuf = GPU::FrontBuffer; if (!GPU::Framebuffer[frontbuf][0] || !GPU::Framebuffer[frontbuf][1]) return; - memcpy(screen[0]->scanLine(0), GPU::Framebuffer[frontbuf][0], 256*192*4); - memcpy(screen[1]->scanLine(0), GPU::Framebuffer[frontbuf][1], 256*192*4); + memcpy(screen[0].scanLine(0), GPU::Framebuffer[frontbuf][0], 256*192*4); + memcpy(screen[1].scanLine(0), GPU::Framebuffer[frontbuf][1], 256*192*4); painter.setRenderHint(QPainter::SmoothPixmapTransform, Config::ScreenFilter!=0); QRect screenrc(0, 0, 256, 192); painter.setTransform(screenTrans[0]); - painter.drawImage(screenrc, *screen[0]); + painter.drawImage(screenrc, screen[0]); painter.setTransform(screenTrans[1]); - painter.drawImage(screenrc, *screen[1]); + painter.drawImage(screenrc, screen[1]); } void MainWindowPanel::resizeEvent(QResizeEvent* event) @@ -649,51 +709,17 @@ void MainWindowPanel::resizeEvent(QResizeEvent* event) void MainWindowPanel::mousePressEvent(QMouseEvent* event) { - event->accept(); - if (event->button() != Qt::LeftButton) return; - - int x = event->pos().x(); - int y = event->pos().y(); - - Frontend::GetTouchCoords(x, y); - - if (x >= 0 && x < 256 && y >= 0 && y < 192) - { - touching = true; - NDS::TouchScreen(x, y); - } + screenOnMousePress(event); } void MainWindowPanel::mouseReleaseEvent(QMouseEvent* event) { - event->accept(); - if (event->button() != Qt::LeftButton) return; - - if (touching) - { - touching = false; - NDS::ReleaseScreen(); - } + screenOnMouseRelease(event); } void MainWindowPanel::mouseMoveEvent(QMouseEvent* event) { - event->accept(); - if (!(event->buttons() & Qt::LeftButton)) return; - if (!touching) return; - - int x = event->pos().x(); - int y = event->pos().y(); - - Frontend::GetTouchCoords(x, y); - - // clamp to screen range - if (x < 0) x = 0; - else if (x > 255) x = 255; - if (y < 0) y = 0; - else if (y > 191) y = 191; - - NDS::TouchScreen(x, y); + screenOnMouseMove(event); } void MainWindowPanel::onScreenLayoutChanged() diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index c0dc465..1121da1 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -64,7 +64,24 @@ private: }; -class MainWindowPanel : public QWidget +class ScreenHandler +{ +protected: + void screenSetupLayout(int w, int h); + + QSize screenGetMinSize(); + + void screenOnMousePress(QMouseEvent* event); + void screenOnMouseRelease(QMouseEvent* event); + void screenOnMouseMove(QMouseEvent* event); + + float screenMatrix[2][6]; + + bool touching; +}; + + +class MainWindowPanel : public QWidget, public ScreenHandler { Q_OBJECT @@ -88,9 +105,8 @@ private slots: void onScreenLayoutChanged(); private: - QImage* screen[2]; + QImage screen[2]; QTransform screenTrans[2]; - bool touching; }; -- cgit v1.2.3 From bc4a83abca991effe082f76f81cd6b4eef6ef0ba Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 24 May 2020 23:47:11 +0200 Subject: make frontend-util audio module config-agnostic --- src/frontend/FrontendUtil.h | 4 ++-- src/frontend/Util_Audio.cpp | 7 +------ src/frontend/qt_sdl/main.cpp | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/frontend/FrontendUtil.h b/src/frontend/FrontendUtil.h index 359018f..6b83cbc 100644 --- a/src/frontend/FrontendUtil.h +++ b/src/frontend/FrontendUtil.h @@ -124,9 +124,9 @@ void Init_Audio(int outputfreq); int AudioOut_GetNumSamples(int outlen); // resample audio from the core audio output to match the frontend's -// output frequency, and apply user-specified volume +// output frequency, and apply specified volume // note: this assumes the output buffer is interleaved stereo -void AudioOut_Resample(s16* inbuf, int inlen, s16* outbuf, int outlen); +void AudioOut_Resample(s16* inbuf, int inlen, s16* outbuf, int outlen, int volume); // feed silence to the microphone input void Mic_FeedSilence(); diff --git a/src/frontend/Util_Audio.cpp b/src/frontend/Util_Audio.cpp index d4c3333..fc80c90 100644 --- a/src/frontend/Util_Audio.cpp +++ b/src/frontend/Util_Audio.cpp @@ -22,9 +22,6 @@ #include #include "FrontendUtil.h" -#include "Config.h" -#include "qt_sdl/PlatformConfig.h" // FIXME!!! -#include "Platform.h" #include "NDS.h" @@ -63,14 +60,12 @@ int AudioOut_GetNumSamples(int outlen) return len_in; } -void AudioOut_Resample(s16* inbuf, int inlen, s16* outbuf, int outlen) +void AudioOut_Resample(s16* inbuf, int inlen, s16* outbuf, int outlen, int volume) { float res_incr = inlen / (float)outlen; float res_timer = 0; int res_pos = 0; - int volume = Config::AudioVolume; - for (int i = 0; i < outlen; i++) { outbuf[i*2 ] = (inbuf[res_pos*2 ] * volume) >> 8; diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 0e0a21b..fac4709 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -110,7 +110,7 @@ void audioCallback(void* data, Uint8* stream, int len) num_in = len_in-margin; } - Frontend::AudioOut_Resample(buf_in, num_in, (s16*)stream, len); + Frontend::AudioOut_Resample(buf_in, num_in, (s16*)stream, len, Config::AudioVolume); } -- cgit v1.2.3 From 4e34359a80833c21ef6a8fabd35c4d26babcaaab Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 25 May 2020 03:12:09 +0200 Subject: get the GL shit going --- src/frontend/qt_sdl/CMakeLists.txt | 1 + src/frontend/qt_sdl/main.cpp | 91 ++++++++++++++++++++------- src/frontend/qt_sdl/main.h | 49 ++++++++++++--- src/frontend/qt_sdl/main_shaders.h | 124 +++++++++++++++++++++++++++++++++++++ 4 files changed, 234 insertions(+), 31 deletions(-) create mode 100644 src/frontend/qt_sdl/main_shaders.h (limited to 'src') diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index 7bc81f0..5778b40 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -2,6 +2,7 @@ project(qt_sdl) SET(SOURCES_QT_SDL main.cpp + main_shaders.h EmuSettingsDialog.cpp InputConfigDialog.cpp AudioSettingsDialog.cpp diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index fac4709..b11dd10 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -639,7 +639,7 @@ void ScreenHandler::screenOnMouseMove(QMouseEvent* event) } -MainWindowPanel::MainWindowPanel(QWidget* parent) : QWidget(parent) +ScreenPanelNative::ScreenPanelNative(QWidget* parent) : QWidget(parent) { screen[0] = QImage(256, 192, QImage::Format_RGB32); screen[1] = QImage(256, 192, QImage::Format_RGB32); @@ -650,16 +650,11 @@ MainWindowPanel::MainWindowPanel(QWidget* parent) : QWidget(parent) touching = false; } -MainWindowPanel::~MainWindowPanel() +ScreenPanelNative::~ScreenPanelNative() { } -void MainWindowPanel::ensureProperMinSize() -{ - setMinimumSize(screenGetMinSize()); -} - -void MainWindowPanel::setupScreenLayout() +void ScreenPanelNative::setupScreenLayout() { int w = width(); int h = height(); @@ -678,7 +673,7 @@ void MainWindowPanel::setupScreenLayout() mtx[4], mtx[5], 1.f); } -void MainWindowPanel::paintEvent(QPaintEvent* event) +void ScreenPanelNative::paintEvent(QPaintEvent* event) { QPainter painter(this); @@ -702,28 +697,78 @@ void MainWindowPanel::paintEvent(QPaintEvent* event) painter.drawImage(screenrc, screen[1]); } -void MainWindowPanel::resizeEvent(QResizeEvent* event) +void ScreenPanelNative::resizeEvent(QResizeEvent* event) +{ + setupScreenLayout(); +} + +void ScreenPanelNative::mousePressEvent(QMouseEvent* event) +{ + screenOnMousePress(event); +} + +void ScreenPanelNative::mouseReleaseEvent(QMouseEvent* event) +{ + screenOnMouseRelease(event); +} + +void ScreenPanelNative::mouseMoveEvent(QMouseEvent* event) +{ + screenOnMouseMove(event); +} + +void ScreenPanelNative::onScreenLayoutChanged() +{ + setMinimumSize(screenGetMinSize()); + setupScreenLayout(); +} + + +ScreenPanelGL::ScreenPanelGL(QWidget* parent) : QOpenGLWidget(parent) +{ + // +} + +ScreenPanelGL::~ScreenPanelGL() +{ +} + +void ScreenPanelGL::setupScreenLayout() +{ + int w = width(); + int h = height(); + + screenSetupLayout(w, h); +} + +void ScreenPanelGL::paintEvent(QPaintEvent* event) +{ + // TODO? +} + +void ScreenPanelGL::resizeEvent(QResizeEvent* event) { setupScreenLayout(); } -void MainWindowPanel::mousePressEvent(QMouseEvent* event) +void ScreenPanelGL::mousePressEvent(QMouseEvent* event) { screenOnMousePress(event); } -void MainWindowPanel::mouseReleaseEvent(QMouseEvent* event) +void ScreenPanelGL::mouseReleaseEvent(QMouseEvent* event) { screenOnMouseRelease(event); } -void MainWindowPanel::mouseMoveEvent(QMouseEvent* event) +void ScreenPanelGL::mouseMoveEvent(QMouseEvent* event) { screenOnMouseMove(event); } -void MainWindowPanel::onScreenLayoutChanged() +void ScreenPanelGL::onScreenLayoutChanged() { + setMinimumSize(screenGetMinSize()); setupScreenLayout(); } @@ -932,9 +977,10 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) } setMenuBar(menubar); - panel = new MainWindowPanel(this); + panel = new ScreenPanelNative(this); setCentralWidget(panel); - panel->ensureProperMinSize(); + connect(this, SIGNAL(screenLayoutChange()), panel, SLOT(onScreenLayoutChanged())); + emit screenLayoutChange(); resize(Config::WindowWidth, Config::WindowHeight); @@ -1413,8 +1459,7 @@ void MainWindow::onChangeScreenRotation(QAction* act) int rot = act->data().toInt(); Config::ScreenRotation = rot; - panel->ensureProperMinSize(); - panel->setupScreenLayout(); + emit screenLayoutChange(); } void MainWindow::onChangeScreenGap(QAction* act) @@ -1422,8 +1467,7 @@ void MainWindow::onChangeScreenGap(QAction* act) int gap = act->data().toInt(); Config::ScreenGap = gap; - panel->ensureProperMinSize(); - panel->setupScreenLayout(); + emit screenLayoutChange(); } void MainWindow::onChangeScreenLayout(QAction* act) @@ -1431,8 +1475,7 @@ void MainWindow::onChangeScreenLayout(QAction* act) int layout = act->data().toInt(); Config::ScreenLayout = layout; - panel->ensureProperMinSize(); - panel->setupScreenLayout(); + emit screenLayoutChange(); } void MainWindow::onChangeScreenSizing(QAction* act) @@ -1440,14 +1483,14 @@ void MainWindow::onChangeScreenSizing(QAction* act) int sizing = act->data().toInt(); Config::ScreenSizing = sizing; - panel->setupScreenLayout(); + emit screenLayoutChange(); } void MainWindow::onChangeIntegerScaling(bool checked) { Config::IntegerScaling = checked?1:0; - panel->setupScreenLayout(); + emit screenLayoutChange(); } void MainWindow::onChangeScreenFiltering(bool checked) diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 1121da1..a244907 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -24,6 +24,7 @@ #include #include #include +#include class EmuThread : public QThread @@ -66,6 +67,11 @@ private: class ScreenHandler { + Q_GADGET + +public: + virtual ~ScreenHandler() {} + protected: void screenSetupLayout(int w, int h); @@ -81,16 +87,13 @@ protected: }; -class MainWindowPanel : public QWidget, public ScreenHandler +class ScreenPanelNative : public QWidget, public ScreenHandler { Q_OBJECT public: - explicit MainWindowPanel(QWidget* parent); - ~MainWindowPanel(); - - void ensureProperMinSize(); - void setupScreenLayout(); + explicit ScreenPanelNative(QWidget* parent); + ~ScreenPanelNative(); protected: void paintEvent(QPaintEvent* event) override; @@ -105,11 +108,40 @@ private slots: void onScreenLayoutChanged(); private: + void setupScreenLayout(); + QImage screen[2]; QTransform screenTrans[2]; }; +class ScreenPanelGL : public QOpenGLWidget, public ScreenHandler +{ + Q_OBJECT + +public: + explicit ScreenPanelGL(QWidget* parent); + ~ScreenPanelGL(); + +protected: + void paintEvent(QPaintEvent* event) override; + + void resizeEvent(QResizeEvent* event) override; + + void mousePressEvent(QMouseEvent* event) override; + void mouseReleaseEvent(QMouseEvent* event) override; + void mouseMoveEvent(QMouseEvent* event) override; + +private slots: + void onScreenLayoutChanged(); + +private: + void setupScreenLayout(); + + // +}; + + class MainWindow : public QMainWindow { Q_OBJECT @@ -127,6 +159,9 @@ protected: void dragEnterEvent(QDragEnterEvent* event) override; void dropEvent(QDropEvent* event) override; +signals: + void screenLayoutChange(); + private slots: void onOpenFile(); void onBootFirmware(); @@ -167,7 +202,7 @@ private: QString loadErrorStr(int error); public: - MainWindowPanel* panel; + QWidget* panel; QAction* actOpenROM; QAction* actBootFirmware; diff --git a/src/frontend/qt_sdl/main_shaders.h b/src/frontend/qt_sdl/main_shaders.h new file mode 100644 index 0000000..7c4feec --- /dev/null +++ b/src/frontend/qt_sdl/main_shaders.h @@ -0,0 +1,124 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef MAIN_SHADERS_H +#define MAIN_SHADERS_H + +const char* kScreenVS = R"(#version 140 + +layout(std140) uniform uConfig +{ + vec2 uScreenSize; + uint u3DScale; + uint uFilterMode; +}; + +in vec2 vPosition; +in vec2 vTexcoord; + +smooth out vec2 fTexcoord; + +void main() +{ + vec4 fpos; + fpos.xy = ((vPosition * 2.0) / uScreenSize) - 1.0; + fpos.y *= -1; + fpos.z = 0.0; + fpos.w = 1.0; + + gl_Position = fpos; + fTexcoord = vTexcoord; +} +)"; + +const char* kScreenFS = R"(#version 140 + +layout(std140) uniform uConfig +{ + vec2 uScreenSize; + uint u3DScale; + uint uFilterMode; +}; + +uniform usampler2D ScreenTex; + +smooth in vec2 fTexcoord; + +out vec4 oColor; + +void main() +{ + ivec4 pixel = ivec4(texelFetch(ScreenTex, ivec2(fTexcoord), 0)); + + // TODO: filters + + oColor = vec4(vec3(pixel.bgr) / 255.0, 1.0); +} +)"; + + + +const char* kScreenVS_OSD = R"(#version 140 + +layout(std140) uniform uConfig +{ + vec2 uScreenSize; + uint u3DScale; + uint uFilterMode; +}; + +uniform ivec2 uOSDPos; +uniform ivec2 uOSDSize; + +in vec2 vPosition; + +smooth out vec2 fTexcoord; + +void main() +{ + vec4 fpos; + + vec2 osdpos = (vPosition * vec2(uOSDSize)); + fTexcoord = osdpos; + osdpos += uOSDPos; + + fpos.xy = ((osdpos * 2.0) / uScreenSize) - 1.0; + fpos.y *= -1; + fpos.z = 0.0; + fpos.w = 1.0; + + gl_Position = fpos; +} +)"; + +const char* kScreenFS_OSD = R"(#version 140 + +uniform sampler2D OSDTex; + +smooth in vec2 fTexcoord; + +out vec4 oColor; + +void main() +{ + vec4 pixel = texelFetch(OSDTex, ivec2(fTexcoord), 0); + oColor = pixel.bgra; +} +)"; + +#endif // MAIN_SHADERS_H -- cgit v1.2.3 From 10f9eda58a7bbc9becb186ea2bdf1c9b7d2c1bc1 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 25 May 2020 14:59:26 +0200 Subject: get the whole OpenGL shit going --- src/frontend/qt_sdl/main.cpp | 127 +++++++++++++++++++++++++++++++++++-- src/frontend/qt_sdl/main.h | 17 ++++- src/frontend/qt_sdl/main_shaders.h | 28 +++----- 3 files changed, 145 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index b11dd10..bb08a87 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -54,6 +54,8 @@ #include "Savestate.h" +#include "main_shaders.h" + // TODO: uniform variable spelling @@ -247,7 +249,8 @@ EmuThread::EmuThread(QObject* parent) : QThread(parent) EmuRunning = 2; RunningSomething = false; - connect(this, SIGNAL(windowUpdate()), mainWindow, SLOT(update())); + //connect(this, SIGNAL(windowUpdate()), mainWindow, SLOT(update())); + connect(this, SIGNAL(windowUpdate()), mainWindow->panel, SLOT(update())); //connect(this, SIGNAL(windowUpdate()), mainWindow, SLOT(repaint())); connect(this, SIGNAL(windowTitleChange(QString)), mainWindow, SLOT(onTitleUpdate(QString))); connect(this, SIGNAL(windowEmuStart()), mainWindow, SLOT(onEmuStart())); @@ -726,11 +729,18 @@ void ScreenPanelNative::onScreenLayoutChanged() ScreenPanelGL::ScreenPanelGL(QWidget* parent) : QOpenGLWidget(parent) { - // + QSurfaceFormat format; + format.setDepthBufferSize(24); + format.setStencilBufferSize(8); + format.setVersion(3, 2); + format.setProfile(QSurfaceFormat::CoreProfile); + setFormat(format); } ScreenPanelGL::~ScreenPanelGL() { + // CHECKME!!!! + delete screenShader; } void ScreenPanelGL::setupScreenLayout() @@ -741,14 +751,120 @@ void ScreenPanelGL::setupScreenLayout() screenSetupLayout(w, h); } -void ScreenPanelGL::paintEvent(QPaintEvent* event) +void ScreenPanelGL::initializeGL() { - // TODO? + initializeOpenGLFunctions(); + + glClearColor(0, 0, 0, 1); + + screenShader = new QOpenGLShaderProgram(this); + screenShader->addShaderFromSourceCode(QOpenGLShader::Vertex, kScreenVS); + screenShader->addShaderFromSourceCode(QOpenGLShader::Fragment, kScreenFS); + + GLuint pid = screenShader->programId(); + printf("program: %d\n", pid); + glBindAttribLocation(pid, 0, "vPosition"); + glBindAttribLocation(pid, 1, "vTexcoord"); + glBindFragDataLocation(pid, 0, "oColor"); + + screenShader->link(); + + screenShader->bind(); + screenShader->setUniformValue("ScreenTex", (GLint)0); + screenShader->release(); + + + float vertices[] = + { + 0, 0, 0, 0, + 0, 192, 0, 0.5, + 256, 192, 1, 0.5, + 0, 0, 0, 0, + 256, 192, 1, 0.5, + 256, 0, 1, 0, + + 0, 0, 0, 0.5, + 0, 192, 0, 1, + 256, 192, 1, 1, + 0, 0, 0, 0.5, + 256, 192, 1, 1, + 256, 0, 1, 0.5 + }; + + glGenBuffers(1, &screenVertexBuffer); + glBindBuffer(GL_ARRAY_BUFFER, screenVertexBuffer); + glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); + + glGenVertexArrays(1, &screenVertexArray); + glBindVertexArray(screenVertexArray); + glEnableVertexAttribArray(0); // position + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4*4, (void*)(0)); + glEnableVertexAttribArray(1); // texcoord + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4*4, (void*)(2*4)); + + glGenTextures(1, &screenTexture); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, screenTexture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 192*2, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); +} + +void ScreenPanelGL::paintGL() +{ + int w = width(); + int h = height(); + + glClear(GL_COLOR_BUFFER_BIT); + + // TODO: check hiDPI compliance of this + glViewport(0, 0, w, h); + + screenShader->bind(); + + screenShader->setUniformValue("uScreenSize", (float)w, (float)h); + + int frontbuf = GPU::FrontBuffer; + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, screenTexture); + + if (GPU::Framebuffer[frontbuf][0] && GPU::Framebuffer[frontbuf][1]) + { + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 192, GL_RGBA, + GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][0]); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 192, 256, 192, GL_RGBA, + GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][1]); + } + + GLint filter = Config::ScreenFilter ? GL_LINEAR : GL_NEAREST; + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); + + glBindBuffer(GL_ARRAY_BUFFER, screenVertexBuffer); + glBindVertexArray(screenVertexArray); + + GLint transloc = screenShader->uniformLocation("uTransform"); + + glUniformMatrix2x3fv(transloc, 1, GL_TRUE, screenMatrix[0]); + glDrawArrays(GL_TRIANGLES, 0, 2*3); + + glUniformMatrix2x3fv(transloc, 1, GL_TRUE, screenMatrix[1]); + glDrawArrays(GL_TRIANGLES, 2*3, 2*3); + + screenShader->release(); } void ScreenPanelGL::resizeEvent(QResizeEvent* event) { setupScreenLayout(); + + QOpenGLWidget::resizeEvent(event); +} + +void ScreenPanelGL::resizeGL(int w, int h) +{ } void ScreenPanelGL::mousePressEvent(QMouseEvent* event) @@ -977,7 +1093,8 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) } setMenuBar(menubar); - panel = new ScreenPanelNative(this); + //panel = new ScreenPanelNative(this); + panel = new ScreenPanelGL(this); setCentralWidget(panel); connect(this, SIGNAL(screenLayoutChange()), panel, SLOT(onScreenLayoutChanged())); emit screenLayoutChange(); diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index a244907..8a8c041 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -24,7 +24,12 @@ #include #include #include + #include +#include +#include +#include +#include class EmuThread : public QThread @@ -115,7 +120,7 @@ private: }; -class ScreenPanelGL : public QOpenGLWidget, public ScreenHandler +class ScreenPanelGL : public QOpenGLWidget, public ScreenHandler, protected QOpenGLFunctions_3_2_Core { Q_OBJECT @@ -124,9 +129,12 @@ public: ~ScreenPanelGL(); protected: - void paintEvent(QPaintEvent* event) override; + void initializeGL() override; + + void paintGL() override; void resizeEvent(QResizeEvent* event) override; + void resizeGL(int w, int h) override; void mousePressEvent(QMouseEvent* event) override; void mouseReleaseEvent(QMouseEvent* event) override; @@ -138,7 +146,10 @@ private slots: private: void setupScreenLayout(); - // + QOpenGLShaderProgram* screenShader; + GLuint screenVertexBuffer; + GLuint screenVertexArray; + GLuint screenTexture; }; diff --git a/src/frontend/qt_sdl/main_shaders.h b/src/frontend/qt_sdl/main_shaders.h index 7c4feec..2e57e59 100644 --- a/src/frontend/qt_sdl/main_shaders.h +++ b/src/frontend/qt_sdl/main_shaders.h @@ -21,12 +21,8 @@ const char* kScreenVS = R"(#version 140 -layout(std140) uniform uConfig -{ - vec2 uScreenSize; - uint u3DScale; - uint uFilterMode; -}; +uniform vec2 uScreenSize; +uniform mat2x3 uTransform; in vec2 vPosition; in vec2 vTexcoord; @@ -36,7 +32,10 @@ smooth out vec2 fTexcoord; void main() { vec4 fpos; - fpos.xy = ((vPosition * 2.0) / uScreenSize) - 1.0; + + fpos.xy = vec3(vPosition, 1.0) * uTransform; + + fpos.xy = ((fpos.xy * 2.0) / uScreenSize) - 1.0; fpos.y *= -1; fpos.z = 0.0; fpos.w = 1.0; @@ -48,14 +47,7 @@ void main() const char* kScreenFS = R"(#version 140 -layout(std140) uniform uConfig -{ - vec2 uScreenSize; - uint u3DScale; - uint uFilterMode; -}; - -uniform usampler2D ScreenTex; +uniform sampler2D ScreenTex; smooth in vec2 fTexcoord; @@ -63,11 +55,9 @@ out vec4 oColor; void main() { - ivec4 pixel = ivec4(texelFetch(ScreenTex, ivec2(fTexcoord), 0)); - - // TODO: filters + vec4 pixel = texture2D(ScreenTex, fTexcoord); - oColor = vec4(vec3(pixel.bgr) / 255.0, 1.0); + oColor = vec4(pixel.bgr, 1.0); } )"; -- cgit v1.2.3 From 36f4cdbbbf1904c1a0455bf45d9720f03872e1bd Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 25 May 2020 18:25:50 +0200 Subject: get the OpenGL renderer going. sorta. (also make the blackmagic_II branch obsolete in the process) --- src/CMakeLists.txt | 2 + src/GPU.cpp | 2 + src/GPU.h | 14 + src/GPU2D.cpp | 2 + src/GPU3D.cpp | 2 +- src/GPU3D_OpenGL.cpp | 31 +- src/GPU_OpenGL.cpp | 207 ++++++++++ src/GPU_OpenGL_shaders.h | 867 +++++++++++++++++++++++++++++++++++++++ src/OpenGLSupport.cpp | 14 +- src/OpenGLSupport.h | 30 +- src/frontend/qt_sdl/Platform.cpp | 3 +- src/frontend/qt_sdl/main.cpp | 96 ++++- src/frontend/qt_sdl/main.h | 11 + 13 files changed, 1240 insertions(+), 41 deletions(-) create mode 100644 src/GPU_OpenGL.cpp create mode 100644 src/GPU_OpenGL_shaders.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 245e6a2..56bb3cb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,6 +16,8 @@ add_library(core STATIC FIFO.h GBACart.cpp GPU.cpp + GPU_OpenGL.cpp + GPU_OpenGL_shaders.h GPU2D.cpp GPU3D.cpp GPU3D_OpenGL.cpp diff --git a/src/GPU.cpp b/src/GPU.cpp index 42bfc56..993086e 100644 --- a/src/GPU.cpp +++ b/src/GPU.cpp @@ -985,6 +985,8 @@ void StartScanline(u32 line) GPU2D_A->VBlank(); GPU2D_B->VBlank(); GPU3D::VBlank(); + + if (Accelerated) GLCompositor::RenderFrame(); } else if (VCount == 144) { diff --git a/src/GPU.h b/src/GPU.h index 661a7d9..e85a5b4 100644 --- a/src/GPU.h +++ b/src/GPU.h @@ -422,6 +422,20 @@ void SetDispStat(u32 cpu, u16 val); void SetVCount(u16 val); +namespace GLCompositor +{ + +bool Init(); +void DeInit(); +void Reset(); + +void UpdateDisplaySettings(); + +void RenderFrame(); +void BindOutputTexture(); + +} + } #endif diff --git a/src/GPU2D.cpp b/src/GPU2D.cpp index 1c6cf0c..6f950b7 100644 --- a/src/GPU2D.cpp +++ b/src/GPU2D.cpp @@ -728,6 +728,8 @@ u32 GPU2D::ColorComposite(int i, u32 val1, u32 val2) case 3: return ColorBrightnessDown(val1, EVY); case 4: return ColorBlend5(val1, val2); } + + return val1; } diff --git a/src/GPU3D.cpp b/src/GPU3D.cpp index 4f146ae..e687e37 100644 --- a/src/GPU3D.cpp +++ b/src/GPU3D.cpp @@ -616,7 +616,7 @@ int InitRenderer(bool hasGL) if (!GLRenderer::Init()) renderer = 0; } - +printf("renderer: %d\n", renderer); if (renderer == 0) SoftRenderer::Init(); Renderer = renderer; diff --git a/src/GPU3D_OpenGL.cpp b/src/GPU3D_OpenGL.cpp index b1bcaa1..dcc4b6b 100644 --- a/src/GPU3D_OpenGL.cpp +++ b/src/GPU3D_OpenGL.cpp @@ -29,6 +29,8 @@ namespace GPU3D namespace GLRenderer { +using namespace OpenGL; + // GL version requirements // * texelFetch: 3.0 (GLSL 1.30) (3.2/1.50 for MS) // * UBO: 3.1 @@ -142,7 +144,7 @@ bool BuildRenderShader(u32 flags, const char* vs, const char* fs) strcpy(&fsbuf[headerlen], kRenderFSCommon); strcpy(&fsbuf[headerlen + fsclen], fs); - bool ret = OpenGL_BuildShaderProgram(vsbuf, fsbuf, RenderShader[flags], shadername); + bool ret = OpenGL::BuildShaderProgram(vsbuf, fsbuf, RenderShader[flags], shadername); delete[] vsbuf; delete[] fsbuf; @@ -158,7 +160,7 @@ bool BuildRenderShader(u32 flags, const char* vs, const char* fs) glBindFragDataLocation(prog, 0, "oColor"); glBindFragDataLocation(prog, 1, "oAttr"); - if (!OpenGL_LinkShaderProgram(RenderShader[flags])) + if (!OpenGL::LinkShaderProgram(RenderShader[flags])) return false; GLint uni_id = glGetUniformBlockIndex(prog, "uConfig"); @@ -202,14 +204,14 @@ bool Init() glClearDepth(1.0); - if (!OpenGL_BuildShaderProgram(kClearVS, kClearFS, ClearShaderPlain, "ClearShader")) + if (!OpenGL::BuildShaderProgram(kClearVS, kClearFS, ClearShaderPlain, "ClearShader")) return false; glBindAttribLocation(ClearShaderPlain[2], 0, "vPosition"); glBindFragDataLocation(ClearShaderPlain[2], 0, "oColor"); glBindFragDataLocation(ClearShaderPlain[2], 1, "oAttr"); - if (!OpenGL_LinkShaderProgram(ClearShaderPlain)) + if (!OpenGL::LinkShaderProgram(ClearShaderPlain)) return false; ClearUniformLoc[0] = glGetUniformLocation(ClearShaderPlain[2], "uColor"); @@ -237,15 +239,15 @@ bool Init() kRenderVS_W, kRenderFS_WSM)) return false; - if (!OpenGL_BuildShaderProgram(kFinalPassVS, kFinalPassEdgeFS, FinalPassEdgeShader, "FinalPassEdgeShader")) + if (!OpenGL::BuildShaderProgram(kFinalPassVS, kFinalPassEdgeFS, FinalPassEdgeShader, "FinalPassEdgeShader")) return false; - if (!OpenGL_BuildShaderProgram(kFinalPassVS, kFinalPassFogFS, FinalPassFogShader, "FinalPassFogShader")) + if (!OpenGL::BuildShaderProgram(kFinalPassVS, kFinalPassFogFS, FinalPassFogShader, "FinalPassFogShader")) return false; glBindAttribLocation(FinalPassEdgeShader[2], 0, "vPosition"); glBindFragDataLocation(FinalPassEdgeShader[2], 0, "oColor"); - if (!OpenGL_LinkShaderProgram(FinalPassEdgeShader)) + if (!OpenGL::LinkShaderProgram(FinalPassEdgeShader)) return false; uni_id = glGetUniformBlockIndex(FinalPassEdgeShader[2], "uConfig"); @@ -261,7 +263,7 @@ bool Init() glBindAttribLocation(FinalPassFogShader[2], 0, "vPosition"); glBindFragDataLocation(FinalPassFogShader[2], 0, "oColor"); - if (!OpenGL_LinkShaderProgram(FinalPassFogShader)) + if (!OpenGL::LinkShaderProgram(FinalPassFogShader)) return false; uni_id = glGetUniformBlockIndex(FinalPassFogShader[2], "uConfig"); @@ -371,11 +373,19 @@ bool Init() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB5_A1, 1024, 48, 0, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, NULL); + if (!GPU::GLCompositor::Init()) + { + // TODO: clean up things? fail more gracefully?? + return false; + } + return true; } void DeInit() { + GPU::GLCompositor::DeInit(); + glDeleteTextures(1, &TexMemID); glDeleteTextures(1, &TexPalMemID); @@ -392,12 +402,13 @@ void DeInit() for (int i = 0; i < 16; i++) { if (!RenderShader[i][2]) continue; - OpenGL_DeleteShaderProgram(RenderShader[i]); + OpenGL::DeleteShaderProgram(RenderShader[i]); } } void Reset() { + GPU::GLCompositor::Reset(); } void UpdateDisplaySettings() @@ -480,6 +491,8 @@ void UpdateDisplaySettings() //glLineWidth(scale); //glLineWidth(1.5); + + GPU::GLCompositor::UpdateDisplaySettings(); } diff --git a/src/GPU_OpenGL.cpp b/src/GPU_OpenGL.cpp new file mode 100644 index 0000000..c9d31f1 --- /dev/null +++ b/src/GPU_OpenGL.cpp @@ -0,0 +1,207 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include +#include +#include "NDS.h" +#include "GPU.h" +#include "Config.h" +#include "OpenGLSupport.h" +#include "GPU_OpenGL_shaders.h" + +namespace GPU +{ +namespace GLCompositor +{ + +using namespace OpenGL; + +int Scale; +int ScreenH, ScreenW; + +GLuint CompShader[1][3]; +GLuint CompScaleLoc[1]; + +GLuint CompVertexBufferID; +GLuint CompVertexArrayID; +float CompVertices[2 * 3*2 * 2]; // position + +GLuint CompScreenInputTex; +GLuint CompScreenOutputTex; +GLuint CompScreenOutputFB; + + +bool Init() +{ + if (!OpenGL::BuildShaderProgram(kCompositorVS, kCompositorFS_Nearest, CompShader[0], "CompositorShader")) + //if (!OpenGL::BuildShaderProgram(kCompositorVS, kCompositorFS_Linear, CompShader[0], "CompositorShader")) + //if (!OpenGL::BuildShaderProgram(kCompositorVS_xBRZ, kCompositorFS_xBRZ, CompShader[0], "CompositorShader")) + return false; + + for (int i = 0; i < 1; i++) + { + GLint uni_id; + + glBindAttribLocation(CompShader[i][2], 0, "vPosition"); + glBindFragDataLocation(CompShader[i][2], 0, "oColor"); + + if (!OpenGL::LinkShaderProgram(CompShader[i])) + return false; + + CompScaleLoc[i] = glGetUniformLocation(CompShader[i][2], "u3DScale"); + + glUseProgram(CompShader[i][2]); + uni_id = glGetUniformLocation(CompShader[i][2], "ScreenTex"); + glUniform1i(uni_id, 0); + uni_id = glGetUniformLocation(CompShader[i][2], "_3DTex"); + glUniform1i(uni_id, 1); + } + +#define SETVERTEX(i, x, y) \ + CompVertices[2*(i) + 0] = x; \ + CompVertices[2*(i) + 1] = y; + + // top screen + SETVERTEX(0, -1, 1); + SETVERTEX(1, 1, 0); + SETVERTEX(2, 1, 1); + SETVERTEX(3, -1, 1); + SETVERTEX(4, -1, 0); + SETVERTEX(5, 1, 0); + + // bottom screen + SETVERTEX(6, -1, 0); + SETVERTEX(7, 1, -1); + SETVERTEX(8, 1, 0); + SETVERTEX(9, -1, 0); + SETVERTEX(10, -1, -1); + SETVERTEX(11, 1, -1); + +#undef SETVERTEX + + glGenBuffers(1, &CompVertexBufferID); + glBindBuffer(GL_ARRAY_BUFFER, CompVertexBufferID); + glBufferData(GL_ARRAY_BUFFER, sizeof(CompVertices), CompVertices, GL_STATIC_DRAW); + + glGenVertexArrays(1, &CompVertexArrayID); + glBindVertexArray(CompVertexArrayID); + glEnableVertexAttribArray(0); // position + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2*4, (void*)(0)); + + glGenFramebuffers(1, &CompScreenOutputFB); + + glGenTextures(1, &CompScreenInputTex); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, CompScreenInputTex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 256*3 + 1, 192*2, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, NULL); + + glGenTextures(1, &CompScreenOutputTex); + glBindTexture(GL_TEXTURE_2D, CompScreenOutputTex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + return true; +} + +void DeInit() +{ + glDeleteFramebuffers(1, &CompScreenOutputFB); + glDeleteTextures(1, &CompScreenInputTex); + glDeleteTextures(1, &CompScreenOutputTex); + + glDeleteVertexArrays(1, &CompVertexArrayID); + glDeleteBuffers(1, &CompVertexBufferID); + + for (int i = 0; i < 1; i++) + OpenGL::DeleteShaderProgram(CompShader[i]); +} + +void Reset() +{ +} + + +void UpdateDisplaySettings() +{ + int scale = Config::GL_ScaleFactor; + + Scale = scale; + ScreenW = 256 * scale; + ScreenH = 384 * scale; + + glBindTexture(GL_TEXTURE_2D, CompScreenOutputTex); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ScreenW, ScreenH, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + + GLenum fbassign[] = {GL_COLOR_ATTACHMENT0}; + glBindFramebuffer(GL_FRAMEBUFFER, CompScreenOutputFB); + glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, CompScreenOutputTex, 0); + glDrawBuffers(1, fbassign); +} + + +void RenderFrame() +{ + glBindFramebuffer(GL_FRAMEBUFFER, CompScreenOutputFB); + + glDisable(GL_DEPTH_TEST); + glDisable(GL_STENCIL_TEST); + glDisable(GL_BLEND); + glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + + glViewport(0, 0, ScreenW, ScreenH); + + // TODO: select more shaders (filtering, etc) + OpenGL::UseShaderProgram(CompShader[0]); + glUniform1ui(CompScaleLoc[0], Scale); + + //if (RunningSomething) + { + int frontbuf = GPU::FrontBuffer; + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, CompScreenInputTex); + + if (GPU::Framebuffer[frontbuf][0] && GPU::Framebuffer[frontbuf][1]) + { + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256*3 + 1, 192, GL_RGBA_INTEGER, + GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][0]); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 192, 256*3 + 1, 192, GL_RGBA_INTEGER, + GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][1]); + } + + glActiveTexture(GL_TEXTURE1); + GPU3D::GLRenderer::SetupAccelFrame(); + + glBindBuffer(GL_ARRAY_BUFFER, CompVertexBufferID); + glBindVertexArray(CompVertexArrayID); + glDrawArrays(GL_TRIANGLES, 0, 4*3); + } +} + +void BindOutputTexture() +{ + glBindTexture(GL_TEXTURE_2D, CompScreenOutputTex); +} + +} +} diff --git a/src/GPU_OpenGL_shaders.h b/src/GPU_OpenGL_shaders.h new file mode 100644 index 0000000..ec975ed --- /dev/null +++ b/src/GPU_OpenGL_shaders.h @@ -0,0 +1,867 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef GPU_OPENGL_SHADERS_H +#define GPU_OPENGL_SHADERS_H + +const char* kCompositorVS = R"(#version 140 + +in vec2 vPosition; + +smooth out vec2 fTexcoord; + +void main() +{ + vec4 fpos; + fpos.xy = vPosition; + fpos.z = 0.0; + fpos.w = 1.0; + + gl_Position = fpos; + fTexcoord = (vPosition + vec2(1.0, 1.0)) * (vec2(256.0, 384.0) / 2.0); +} +)"; + +const char* kCompositorFS_Nearest = R"(#version 140 + +uniform uint u3DScale; + +uniform usampler2D ScreenTex; +uniform sampler2D _3DTex; + +smooth in vec2 fTexcoord; + +out vec4 oColor; + +void main() +{ + ivec4 pixel = ivec4(texelFetch(ScreenTex, ivec2(fTexcoord), 0)); + + ivec4 mbright = ivec4(texelFetch(ScreenTex, ivec2(256*3, int(fTexcoord.y)), 0)); + int dispmode = mbright.b & 0x3; + + if (dispmode == 1) + { + ivec4 val1 = pixel; + ivec4 val2 = ivec4(texelFetch(ScreenTex, ivec2(fTexcoord) + ivec2(256,0), 0)); + ivec4 val3 = ivec4(texelFetch(ScreenTex, ivec2(fTexcoord) + ivec2(512,0), 0)); + + int compmode = val3.a & 0xF; + int eva, evb, evy; + + if (compmode == 4) + { + // 3D on top, blending + + float xpos = val3.r + fract(fTexcoord.x); + float ypos = mod(fTexcoord.y, 192); + ivec4 _3dpix = ivec4(texelFetch(_3DTex, ivec2(vec2(xpos, ypos)*u3DScale), 0).bgra + * vec4(63,63,63,31)); + + if (_3dpix.a > 0) + { + eva = (_3dpix.a & 0x1F) + 1; + evb = 32 - eva; + + val1 = ((_3dpix * eva) + (val1 * evb)) >> 5; + if (eva <= 16) val1 += ivec4(1,1,1,0); + val1 = min(val1, 0x3F); + } + else + val1 = val2; + } + else if (compmode == 1) + { + // 3D on bottom, blending + + float xpos = val3.r + fract(fTexcoord.x); + float ypos = mod(fTexcoord.y, 192); + ivec4 _3dpix = ivec4(texelFetch(_3DTex, ivec2(vec2(xpos, ypos)*u3DScale), 0).bgra + * vec4(63,63,63,31)); + + if (_3dpix.a > 0) + { + eva = val3.g; + evb = val3.b; + + val1 = ((val1 * eva) + (_3dpix * evb)) >> 4; + val1 = min(val1, 0x3F); + } + else + val1 = val2; + } + else if (compmode <= 3) + { + // 3D on top, normal/fade + + float xpos = val3.r + fract(fTexcoord.x); + float ypos = mod(fTexcoord.y, 192); + ivec4 _3dpix = ivec4(texelFetch(_3DTex, ivec2(vec2(xpos, ypos)*u3DScale), 0).bgra + * vec4(63,63,63,31)); + + if (_3dpix.a > 0) + { + evy = val3.g; + + val1 = _3dpix; + if (compmode == 2) val1 += ((ivec4(0x3F,0x3F,0x3F,0) - val1) * evy) >> 4; + else if (compmode == 3) val1 -= (val1 * evy) >> 4; + } + else + val1 = val2; + } + + pixel = val1; + } + + if (dispmode != 0) + { + int brightmode = mbright.g >> 6; + if (brightmode == 1) + { + // up + int evy = mbright.r & 0x1F; + if (evy > 16) evy = 16; + + pixel += ((ivec4(0x3F,0x3F,0x3F,0) - pixel) * evy) >> 4; + } + else if (brightmode == 2) + { + // down + int evy = mbright.r & 0x1F; + if (evy > 16) evy = 16; + + pixel -= (pixel * evy) >> 4; + } + } + + pixel.rgb <<= 2; + pixel.rgb |= (pixel.rgb >> 6); + + // TODO: filters + + oColor = vec4(vec3(pixel.rgb) / 255.0, 1.0); +} +)"; + + + +const char* kCompositorFS_Linear = R"(#version 140 + +uniform uint u3DScale; + +uniform usampler2D ScreenTex; +uniform sampler2D _3DTex; + +smooth in vec2 fTexcoord; + +out vec4 oColor; + +ivec4 Get3DPixel(vec2 pos) +{ + return ivec4(texelFetch(_3DTex, ivec2(pos*u3DScale), 0).bgra + * vec4(63,63,63,31)); +} + +ivec4 GetFullPixel(ivec4 val1, ivec4 val2, ivec4 val3, ivec4 _3dpix) +{ + int compmode = val3.a & 0xF; + int eva, evb, evy; + + if (compmode == 4) + { + // 3D on top, blending + + if (_3dpix.a > 0) + { + eva = (_3dpix.a & 0x1F) + 1; + evb = 32 - eva; + + val1 = ((_3dpix * eva) + (val1 * evb)) >> 5; + if (eva <= 16) val1 += ivec4(1,1,1,0); + val1 = min(val1, 0x3F); + } + else + val1 = val2; + } + else if (compmode == 1) + { + // 3D on bottom, blending + + if (_3dpix.a > 0) + { + eva = val3.g; + evb = val3.b; + + val1 = ((val1 * eva) + (_3dpix * evb)) >> 4; + val1 = min(val1, 0x3F); + } + else + val1 = val2; + } + else if (compmode <= 3) + { + // 3D on top, normal/fade + + if (_3dpix.a > 0) + { + evy = val3.g; + + val1 = _3dpix; + if (compmode == 2) val1 += ((ivec4(0x3F,0x3F,0x3F,0) - val1) * evy) >> 4; + else if (compmode == 3) val1 -= (val1 * evy) >> 4; + } + else + val1 = val2; + } + + return val1; +} + +ivec4 imix(ivec4 a, ivec4 b, float x) +{ + return ivec4(vec4(a)*(1-x) + vec4(b)*x); +} + +void main() +{ + ivec4 pixel = ivec4(texelFetch(ScreenTex, ivec2(fTexcoord), 0)); + + ivec4 mbright = ivec4(texelFetch(ScreenTex, ivec2(256*3, int(fTexcoord.y)), 0)); + int dispmode = mbright.b & 0x3; + + if (dispmode == 1) + { + ivec4 val1 = pixel; + ivec4 val2 = ivec4(texelFetch(ScreenTex, ivec2(fTexcoord) + ivec2(256,0), 0)); + ivec4 val3 = ivec4(texelFetch(ScreenTex, ivec2(fTexcoord) + ivec2(512,0), 0)); + + float xfract = fract(fTexcoord.x); + float yfract = fract(fTexcoord.y); + + float xpos = val3.r + xfract; + float ypos = mod(fTexcoord.y, 192); + ivec4 _3dpix = Get3DPixel(vec2(xpos,ypos)); + + ivec4 p00 = GetFullPixel(val1, val2, val3, _3dpix); + + int xdisp = 1 - int(step(255, fTexcoord.x)); + int ydisp = 1 - int(step(191, ypos)); + + ivec4 p01 = GetFullPixel(ivec4(texelFetch(ScreenTex, ivec2(fTexcoord) + ivec2(xdisp+0 ,0), 0)), + ivec4(texelFetch(ScreenTex, ivec2(fTexcoord) + ivec2(xdisp+256,0), 0)), + ivec4(texelFetch(ScreenTex, ivec2(fTexcoord) + ivec2(xdisp+512,0), 0)), + _3dpix); + + ivec4 p10 = GetFullPixel(ivec4(texelFetch(ScreenTex, ivec2(fTexcoord) + ivec2(0+0 ,ydisp), 0)), + ivec4(texelFetch(ScreenTex, ivec2(fTexcoord) + ivec2(0+256,ydisp), 0)), + ivec4(texelFetch(ScreenTex, ivec2(fTexcoord) + ivec2(0+512,ydisp), 0)), + _3dpix); + + ivec4 p11 = GetFullPixel(ivec4(texelFetch(ScreenTex, ivec2(fTexcoord) + ivec2(xdisp+0 ,ydisp), 0)), + ivec4(texelFetch(ScreenTex, ivec2(fTexcoord) + ivec2(xdisp+256,ydisp), 0)), + ivec4(texelFetch(ScreenTex, ivec2(fTexcoord) + ivec2(xdisp+512,ydisp), 0)), + _3dpix); + + ivec4 pa = imix(p00, p01, xfract); + ivec4 pb = imix(p10, p11, xfract); + + pixel = imix(pa, pb, yfract); + } + + if (dispmode != 0) + { + int brightmode = mbright.g >> 6; + if (brightmode == 1) + { + // up + int evy = mbright.r & 0x1F; + if (evy > 16) evy = 16; + + pixel += ((ivec4(0x3F,0x3F,0x3F,0) - pixel) * evy) >> 4; + } + else if (brightmode == 2) + { + // down + int evy = mbright.r & 0x1F; + if (evy > 16) evy = 16; + + pixel -= (pixel * evy) >> 4; + } + } + + pixel.rgb <<= 2; + pixel.rgb |= (pixel.rgb >> 6); + + // TODO: filters + + oColor = vec4(vec3(pixel.rgb) / 255.0, 1.0); +} +)"; + + + + + + +// HUGE TEST ZONE ARRLGD + +const char* kCompositorVS_xBRZ = R"(#version 140 + +#define BLEND_NONE 0 +#define BLEND_NORMAL 1 +#define BLEND_DOMINANT 2 +#define LUMINANCE_WEIGHT 1.0 +#define EQUAL_COLOR_TOLERANCE 30.0/255.0 +#define STEEP_DIRECTION_THRESHOLD 2.2 +#define DOMINANT_DIRECTION_THRESHOLD 3.6 + +#if __VERSION__ >= 130 +#define COMPAT_VARYING out +#define COMPAT_ATTRIBUTE in +#define COMPAT_TEXTURE texture +#else +#define COMPAT_VARYING varying +#define COMPAT_ATTRIBUTE attribute +#define COMPAT_TEXTURE texture2D +#endif + +#ifdef GL_ES +#define COMPAT_PRECISION mediump +#else +#define COMPAT_PRECISION +#endif + +COMPAT_ATTRIBUTE vec2 vPosition; +COMPAT_VARYING vec4 TEX0; +COMPAT_VARYING vec4 t1; +COMPAT_VARYING vec4 t2; +COMPAT_VARYING vec4 t3; +COMPAT_VARYING vec4 t4; +COMPAT_VARYING vec4 t5; +COMPAT_VARYING vec4 t6; +COMPAT_VARYING vec4 t7; + +uniform COMPAT_PRECISION int FrameDirection; +uniform COMPAT_PRECISION int FrameCount; +uniform COMPAT_PRECISION vec2 OutputSize; +uniform COMPAT_PRECISION vec2 TextureSize; +uniform COMPAT_PRECISION vec2 InputSize; + +// vertex compatibility #defines +#define vTexCoord TEX0.xy +#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize +#define outsize vec4(OutputSize, 1.0 / OutputSize) + +void main() +{ + vec4 fpos; + fpos.xy = vPosition; + fpos.z = 0.0; + fpos.w = 1.0; + + gl_Position = fpos; + vec2 TexCoord = (vPosition + vec2(1.0, 1.0)) * (vec2(256.0, 384.0) / 2.0); + + + //gl_Position = MVPMatrix * VertexCoord; + //COL0 = COLOR; + TEX0.xy = TexCoord.xy; + vec2 ps = vec2(1,1);//vec2(SourceSize.z, SourceSize.w); + float dx = ps.x; + float dy = ps.y; + + // A1 B1 C1 + // A0 A B C C4 + // D0 D E F F4 + // G0 G H I I4 + // G5 H5 I5 + + t1 = vTexCoord.xxxy + vec4( -dx, 0.0, dx,-2.0*dy); // A1 B1 C1 + t2 = vTexCoord.xxxy + vec4( -dx, 0.0, dx, -dy); // A B C + t3 = vTexCoord.xxxy + vec4( -dx, 0.0, dx, 0.0); // D E F + t4 = vTexCoord.xxxy + vec4( -dx, 0.0, dx, dy); // G H I + t5 = vTexCoord.xxxy + vec4( -dx, 0.0, dx, 2.0*dy); // G5 H5 I5 + t6 = vTexCoord.xyyy + vec4(-2.0*dx,-dy, 0.0, dy); // A0 D0 G0 + t7 = vTexCoord.xyyy + vec4( 2.0*dx,-dy, 0.0, dy); // C4 F4 I4 +} +)"; + +const char* kCompositorFS_xBRZ = R"(#version 140 + +#define BLEND_NONE 0 +#define BLEND_NORMAL 1 +#define BLEND_DOMINANT 2 +#define LUMINANCE_WEIGHT 1.0 +#define EQUAL_COLOR_TOLERANCE 30.0/255.0 +#define STEEP_DIRECTION_THRESHOLD 2.2 +#define DOMINANT_DIRECTION_THRESHOLD 3.6 + +#if __VERSION__ >= 130 +#define COMPAT_VARYING in +//#define COMPAT_TEXTURE texture +#define FragColor oColor +#else +#define COMPAT_VARYING varying +#define FragColor gl_FragColor +//#define COMPAT_TEXTURE texture2D +#endif + +#ifdef GL_ES +#ifdef GL_FRAGMENT_PRECISION_HIGH +precision highp float; +#else +precision mediump float; +#endif +#define COMPAT_PRECISION mediump +#else +#define COMPAT_PRECISION +#endif + +uniform uint u3DScale; + +uniform usampler2D ScreenTex; +uniform sampler2D _3DTex; + +smooth in vec2 fTexcoord; + +out vec4 oColor; + +//uniform COMPAT_PRECISION vec2 OutputSize; +//uniform COMPAT_PRECISION vec2 TextureSize; +#define TextureSize vec2(256,384) +//uniform COMPAT_PRECISION vec2 InputSize; +//uniform sampler2D Texture; +#define Texture 1312 +COMPAT_VARYING vec4 TEX0; +COMPAT_VARYING vec4 t1; +COMPAT_VARYING vec4 t2; +COMPAT_VARYING vec4 t3; +COMPAT_VARYING vec4 t4; +COMPAT_VARYING vec4 t5; +COMPAT_VARYING vec4 t6; +COMPAT_VARYING vec4 t7; + +// fragment compatibility #defines +#define Source Texture +#define vTexCoord TEX0.xy + +#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize +#define outsize vec4(OutputSize, 1.0 / OutputSize) + + const float one_sixth = 1.0 / 6.0; + const float two_sixth = 2.0 / 6.0; + const float four_sixth = 4.0 / 6.0; + const float five_sixth = 5.0 / 6.0; + +vec4 Get2DPixel(vec2 texcoord, int level) +{ + ivec4 pixel = ivec4(texelFetch(ScreenTex, ivec2(texcoord) + ivec2(level*256,0), 0)); + + return vec4(pixel) / vec4(63.0, 63.0, 63.0, 31.0); +} + +ivec4 Get3DPixel(vec2 pos) +{ + return ivec4(texelFetch(_3DTex, ivec2(pos*u3DScale), 0).bgra + * vec4(63,63,63,31)); +} + +float reduce(const vec3 color) +{ + return dot(color, vec3(65536.0, 256.0, 1.0)); +} + +float DistYCbCr(const vec3 pixA, const vec3 pixB) +{ + const vec3 w = vec3(0.2627, 0.6780, 0.0593); + const float scaleB = 0.5 / (1.0 - w.b); + const float scaleR = 0.5 / (1.0 - w.r); + vec3 diff = pixA - pixB; + float Y = dot(diff, w); + float Cb = scaleB * (diff.b - Y); + float Cr = scaleR * (diff.r - Y); + + return sqrt( ((LUMINANCE_WEIGHT * Y) * (LUMINANCE_WEIGHT * Y)) + (Cb * Cb) + (Cr * Cr) ); +} + +bool IsPixEqual(const vec3 pixA, const vec3 pixB) +{ + return (DistYCbCr(pixA, pixB) < EQUAL_COLOR_TOLERANCE); +} + +bool IsBlendingNeeded(const ivec4 blend) +{ + return any(notEqual(blend, ivec4(BLEND_NONE))); +} + +//--------------------------------------- +// Input Pixel Mapping: --|21|22|23|-- +// 19|06|07|08|09 +// 18|05|00|01|10 +// 17|04|03|02|11 +// --|15|14|13|-- +// +// Output Pixel Mapping: 20|21|22|23|24|25 +// 19|06|07|08|09|26 +// 18|05|00|01|10|27 +// 17|04|03|02|11|28 +// 16|15|14|13|12|29 +// 35|34|33|32|31|30 + +ivec4 GetFiltered2DPixel(int level) +{ + vec2 f = fract(vTexCoord.xy);// * SourceSize.xy); + + //--------------------------------------- + // Input Pixel Mapping: 20|21|22|23|24 + // 19|06|07|08|09 + // 18|05|00|01|10 + // 17|04|03|02|11 + // 16|15|14|13|12 + + vec3 src[25]; + + src[21] = Get2DPixel(t1.xw, level).rgb; + src[22] = Get2DPixel(t1.yw, level).rgb; + src[23] = Get2DPixel(t1.zw, level).rgb; + src[ 6] = Get2DPixel(t2.xw, level).rgb; + src[ 7] = Get2DPixel(t2.yw, level).rgb; + src[ 8] = Get2DPixel(t2.zw, level).rgb; + src[ 5] = Get2DPixel(t3.xw, level).rgb; + src[ 0] = Get2DPixel(t3.yw, level).rgb; + src[ 1] = Get2DPixel(t3.zw, level).rgb; + src[ 4] = Get2DPixel(t4.xw, level).rgb; + src[ 3] = Get2DPixel(t4.yw, level).rgb; + src[ 2] = Get2DPixel(t4.zw, level).rgb; + src[15] = Get2DPixel(t5.xw, level).rgb; + src[14] = Get2DPixel(t5.yw, level).rgb; + src[13] = Get2DPixel(t5.zw, level).rgb; + src[19] = Get2DPixel(t6.xy, level).rgb; + src[18] = Get2DPixel(t6.xz, level).rgb; + src[17] = Get2DPixel(t6.xw, level).rgb; + src[ 9] = Get2DPixel(t7.xy, level).rgb; + src[10] = Get2DPixel(t7.xz, level).rgb; + src[11] = Get2DPixel(t7.xw, level).rgb; + + float v[9]; + v[0] = reduce(src[0]); + v[1] = reduce(src[1]); + v[2] = reduce(src[2]); + v[3] = reduce(src[3]); + v[4] = reduce(src[4]); + v[5] = reduce(src[5]); + v[6] = reduce(src[6]); + v[7] = reduce(src[7]); + v[8] = reduce(src[8]); + + ivec4 blendResult = ivec4(BLEND_NONE); + + // Preprocess corners + // Pixel Tap Mapping: --|--|--|--|-- + // --|--|07|08|-- + // --|05|00|01|10 + // --|04|03|02|11 + // --|--|14|13|-- + // Corner (1, 1) + if ( ((v[0] == v[1] && v[3] == v[2]) || (v[0] == v[3] && v[1] == v[2])) == false) + { + float dist_03_01 = DistYCbCr(src[ 4], src[ 0]) + DistYCbCr(src[ 0], src[ 8]) + DistYCbCr(src[14], src[ 2]) + DistYCbCr(src[ 2], src[10]) + (4.0 * DistYCbCr(src[ 3], src[ 1])); + float dist_00_02 = DistYCbCr(src[ 5], src[ 3]) + DistYCbCr(src[ 3], src[13]) + DistYCbCr(src[ 7], src[ 1]) + DistYCbCr(src[ 1], src[11]) + (4.0 * DistYCbCr(src[ 0], src[ 2])); + bool dominantGradient = (DOMINANT_DIRECTION_THRESHOLD * dist_03_01) < dist_00_02; + blendResult[2] = ((dist_03_01 < dist_00_02) && (v[0] != v[1]) && (v[0] != v[3])) ? ((dominantGradient) ? BLEND_DOMINANT : BLEND_NORMAL) : BLEND_NONE; + } + + // Pixel Tap Mapping: --|--|--|--|-- + // --|06|07|--|-- + // 18|05|00|01|-- + // 17|04|03|02|-- + // --|15|14|--|-- + // Corner (0, 1) + if ( ((v[5] == v[0] && v[4] == v[3]) || (v[5] == v[4] && v[0] == v[3])) == false) + { + float dist_04_00 = DistYCbCr(src[17], src[ 5]) + DistYCbCr(src[ 5], src[ 7]) + DistYCbCr(src[15], src[ 3]) + DistYCbCr(src[ 3], src[ 1]) + (4.0 * DistYCbCr(src[ 4], src[ 0])); + float dist_05_03 = DistYCbCr(src[18], src[ 4]) + DistYCbCr(src[ 4], src[14]) + DistYCbCr(src[ 6], src[ 0]) + DistYCbCr(src[ 0], src[ 2]) + (4.0 * DistYCbCr(src[ 5], src[ 3])); + bool dominantGradient = (DOMINANT_DIRECTION_THRESHOLD * dist_05_03) < dist_04_00; + blendResult[3] = ((dist_04_00 > dist_05_03) && (v[0] != v[5]) && (v[0] != v[3])) ? ((dominantGradient) ? BLEND_DOMINANT : BLEND_NORMAL) : BLEND_NONE; + } + + // Pixel Tap Mapping: --|--|22|23|-- + // --|06|07|08|09 + // --|05|00|01|10 + // --|--|03|02|-- + // --|--|--|--|-- + // Corner (1, 0) + if ( ((v[7] == v[8] && v[0] == v[1]) || (v[7] == v[0] && v[8] == v[1])) == false) + { + float dist_00_08 = DistYCbCr(src[ 5], src[ 7]) + DistYCbCr(src[ 7], src[23]) + DistYCbCr(src[ 3], src[ 1]) + DistYCbCr(src[ 1], src[ 9]) + (4.0 * DistYCbCr(src[ 0], src[ 8])); + float dist_07_01 = DistYCbCr(src[ 6], src[ 0]) + DistYCbCr(src[ 0], src[ 2]) + DistYCbCr(src[22], src[ 8]) + DistYCbCr(src[ 8], src[10]) + (4.0 * DistYCbCr(src[ 7], src[ 1])); + bool dominantGradient = (DOMINANT_DIRECTION_THRESHOLD * dist_07_01) < dist_00_08; + blendResult[1] = ((dist_00_08 > dist_07_01) && (v[0] != v[7]) && (v[0] != v[1])) ? ((dominantGradient) ? BLEND_DOMINANT : BLEND_NORMAL) : BLEND_NONE; + } + + // Pixel Tap Mapping: --|21|22|--|-- + // 19|06|07|08|-- + // 18|05|00|01|-- + // --|04|03|--|-- + // --|--|--|--|-- + // Corner (0, 0) + if ( ((v[6] == v[7] && v[5] == v[0]) || (v[6] == v[5] && v[7] == v[0])) == false) + { + float dist_05_07 = DistYCbCr(src[18], src[ 6]) + DistYCbCr(src[ 6], src[22]) + DistYCbCr(src[ 4], src[ 0]) + DistYCbCr(src[ 0], src[ 8]) + (4.0 * DistYCbCr(src[ 5], src[ 7])); + float dist_06_00 = DistYCbCr(src[19], src[ 5]) + DistYCbCr(src[ 5], src[ 3]) + DistYCbCr(src[21], src[ 7]) + DistYCbCr(src[ 7], src[ 1]) + (4.0 * DistYCbCr(src[ 6], src[ 0])); + bool dominantGradient = (DOMINANT_DIRECTION_THRESHOLD * dist_05_07) < dist_06_00; + blendResult[0] = ((dist_05_07 < dist_06_00) && (v[0] != v[5]) && (v[0] != v[7])) ? ((dominantGradient) ? BLEND_DOMINANT : BLEND_NORMAL) : BLEND_NONE; + } + + vec3 dst[16]; + dst[ 0] = src[0]; + dst[ 1] = src[0]; + dst[ 2] = src[0]; + dst[ 3] = src[0]; + dst[ 4] = src[0]; + dst[ 5] = src[0]; + dst[ 6] = src[0]; + dst[ 7] = src[0]; + dst[ 8] = src[0]; + dst[ 9] = src[0]; + dst[10] = src[0]; + dst[11] = src[0]; + dst[12] = src[0]; + dst[13] = src[0]; + dst[14] = src[0]; + dst[15] = src[0]; + + // Scale pixel + if (IsBlendingNeeded(blendResult) == true) + { + float dist_01_04 = DistYCbCr(src[1], src[4]); + float dist_03_08 = DistYCbCr(src[3], src[8]); + bool haveShallowLine = (STEEP_DIRECTION_THRESHOLD * dist_01_04 <= dist_03_08) && (v[0] != v[4]) && (v[5] != v[4]); + bool haveSteepLine = (STEEP_DIRECTION_THRESHOLD * dist_03_08 <= dist_01_04) && (v[0] != v[8]) && (v[7] != v[8]); + bool needBlend = (blendResult[2] != BLEND_NONE); + bool doLineBlend = ( blendResult[2] >= BLEND_DOMINANT || + ((blendResult[1] != BLEND_NONE && !IsPixEqual(src[0], src[4])) || + (blendResult[3] != BLEND_NONE && !IsPixEqual(src[0], src[8])) || + (IsPixEqual(src[4], src[3]) && IsPixEqual(src[3], src[2]) && IsPixEqual(src[2], src[1]) && IsPixEqual(src[1], src[8]) && IsPixEqual(src[0], src[2]) == false) ) == false ); + + vec3 blendPix = ( DistYCbCr(src[0], src[1]) <= DistYCbCr(src[0], src[3]) ) ? src[1] : src[3]; + dst[ 2] = mix(dst[ 2], blendPix, (needBlend && doLineBlend) ? ((haveShallowLine) ? ((haveSteepLine) ? 1.0/3.0 : 0.25) : ((haveSteepLine) ? 0.25 : 0.00)) : 0.00); + dst[ 9] = mix(dst[ 9], blendPix, (needBlend && doLineBlend && haveSteepLine) ? 0.25 : 0.00); + dst[10] = mix(dst[10], blendPix, (needBlend && doLineBlend && haveSteepLine) ? 0.75 : 0.00); + dst[11] = mix(dst[11], blendPix, (needBlend) ? ((doLineBlend) ? ((haveSteepLine) ? 1.00 : ((haveShallowLine) ? 0.75 : 0.50)) : 0.08677704501) : 0.00); + dst[12] = mix(dst[12], blendPix, (needBlend) ? ((doLineBlend) ? 1.00 : 0.6848532563) : 0.00); + dst[13] = mix(dst[13], blendPix, (needBlend) ? ((doLineBlend) ? ((haveShallowLine) ? 1.00 : ((haveSteepLine) ? 0.75 : 0.50)) : 0.08677704501) : 0.00); + dst[14] = mix(dst[14], blendPix, (needBlend && doLineBlend && haveShallowLine) ? 0.75 : 0.00); + dst[15] = mix(dst[15], blendPix, (needBlend && doLineBlend && haveShallowLine) ? 0.25 : 0.00); + + dist_01_04 = DistYCbCr(src[7], src[2]); + dist_03_08 = DistYCbCr(src[1], src[6]); + haveShallowLine = (STEEP_DIRECTION_THRESHOLD * dist_01_04 <= dist_03_08) && (v[0] != v[2]) && (v[3] != v[2]); + haveSteepLine = (STEEP_DIRECTION_THRESHOLD * dist_03_08 <= dist_01_04) && (v[0] != v[6]) && (v[5] != v[6]); + needBlend = (blendResult[1] != BLEND_NONE); + doLineBlend = ( blendResult[1] >= BLEND_DOMINANT || + !((blendResult[0] != BLEND_NONE && !IsPixEqual(src[0], src[2])) || + (blendResult[2] != BLEND_NONE && !IsPixEqual(src[0], src[6])) || + (IsPixEqual(src[2], src[1]) && IsPixEqual(src[1], src[8]) && IsPixEqual(src[8], src[7]) && IsPixEqual(src[7], src[6]) && !IsPixEqual(src[0], src[8])) ) ); + + blendPix = ( DistYCbCr(src[0], src[7]) <= DistYCbCr(src[0], src[1]) ) ? src[7] : src[1]; + dst[ 1] = mix(dst[ 1], blendPix, (needBlend && doLineBlend) ? ((haveShallowLine) ? ((haveSteepLine) ? 1.0/3.0 : 0.25) : ((haveSteepLine) ? 0.25 : 0.00)) : 0.00); + dst[ 6] = mix(dst[ 6], blendPix, (needBlend && doLineBlend && haveSteepLine) ? 0.25 : 0.00); + dst[ 7] = mix(dst[ 7], blendPix, (needBlend && doLineBlend && haveSteepLine) ? 0.75 : 0.00); + dst[ 8] = mix(dst[ 8], blendPix, (needBlend) ? ((doLineBlend) ? ((haveSteepLine) ? 1.00 : ((haveShallowLine) ? 0.75 : 0.50)) : 0.08677704501) : 0.00); + dst[ 9] = mix(dst[ 9], blendPix, (needBlend) ? ((doLineBlend) ? 1.00 : 0.6848532563) : 0.00); + dst[10] = mix(dst[10], blendPix, (needBlend) ? ((doLineBlend) ? ((haveShallowLine) ? 1.00 : ((haveSteepLine) ? 0.75 : 0.50)) : 0.08677704501) : 0.00); + dst[11] = mix(dst[11], blendPix, (needBlend && doLineBlend && haveShallowLine) ? 0.75 : 0.00); + dst[12] = mix(dst[12], blendPix, (needBlend && doLineBlend && haveShallowLine) ? 0.25 : 0.00); + + dist_01_04 = DistYCbCr(src[5], src[8]); + dist_03_08 = DistYCbCr(src[7], src[4]); + haveShallowLine = (STEEP_DIRECTION_THRESHOLD * dist_01_04 <= dist_03_08) && (v[0] != v[8]) && (v[1] != v[8]); + haveSteepLine = (STEEP_DIRECTION_THRESHOLD * dist_03_08 <= dist_01_04) && (v[0] != v[4]) && (v[3] != v[4]); + needBlend = (blendResult[0] != BLEND_NONE); + doLineBlend = ( blendResult[0] >= BLEND_DOMINANT || + !((blendResult[3] != BLEND_NONE && !IsPixEqual(src[0], src[8])) || + (blendResult[1] != BLEND_NONE && !IsPixEqual(src[0], src[4])) || + (IsPixEqual(src[8], src[7]) && IsPixEqual(src[7], src[6]) && IsPixEqual(src[6], src[5]) && IsPixEqual(src[5], src[4]) && !IsPixEqual(src[0], src[6])) ) ); + + blendPix = ( DistYCbCr(src[0], src[5]) <= DistYCbCr(src[0], src[7]) ) ? src[5] : src[7]; + dst[ 0] = mix(dst[ 0], blendPix, (needBlend && doLineBlend) ? ((haveShallowLine) ? ((haveSteepLine) ? 1.0/3.0 : 0.25) : ((haveSteepLine) ? 0.25 : 0.00)) : 0.00); + dst[15] = mix(dst[15], blendPix, (needBlend && doLineBlend && haveSteepLine) ? 0.25 : 0.00); + dst[ 4] = mix(dst[ 4], blendPix, (needBlend && doLineBlend && haveSteepLine) ? 0.75 : 0.00); + dst[ 5] = mix(dst[ 5], blendPix, (needBlend) ? ((doLineBlend) ? ((haveSteepLine) ? 1.00 : ((haveShallowLine) ? 0.75 : 0.50)) : 0.08677704501) : 0.00); + dst[ 6] = mix(dst[ 6], blendPix, (needBlend) ? ((doLineBlend) ? 1.00 : 0.6848532563) : 0.00); + dst[ 7] = mix(dst[ 7], blendPix, (needBlend) ? ((doLineBlend) ? ((haveShallowLine) ? 1.00 : ((haveSteepLine) ? 0.75 : 0.50)) : 0.08677704501) : 0.00); + dst[ 8] = mix(dst[ 8], blendPix, (needBlend && doLineBlend && haveShallowLine) ? 0.75 : 0.00); + dst[ 9] = mix(dst[ 9], blendPix, (needBlend && doLineBlend && haveShallowLine) ? 0.25 : 0.00); + + + dist_01_04 = DistYCbCr(src[3], src[6]); + dist_03_08 = DistYCbCr(src[5], src[2]); + haveShallowLine = (STEEP_DIRECTION_THRESHOLD * dist_01_04 <= dist_03_08) && (v[0] != v[6]) && (v[7] != v[6]); + haveSteepLine = (STEEP_DIRECTION_THRESHOLD * dist_03_08 <= dist_01_04) && (v[0] != v[2]) && (v[1] != v[2]); + needBlend = (blendResult[3] != BLEND_NONE); + doLineBlend = ( blendResult[3] >= BLEND_DOMINANT || + !((blendResult[2] != BLEND_NONE && !IsPixEqual(src[0], src[6])) || + (blendResult[0] != BLEND_NONE && !IsPixEqual(src[0], src[2])) || + (IsPixEqual(src[6], src[5]) && IsPixEqual(src[5], src[4]) && IsPixEqual(src[4], src[3]) && IsPixEqual(src[3], src[2]) && !IsPixEqual(src[0], src[4])) ) ); + + blendPix = ( DistYCbCr(src[0], src[3]) <= DistYCbCr(src[0], src[5]) ) ? src[3] : src[5]; + dst[ 3] = mix(dst[ 3], blendPix, (needBlend && doLineBlend) ? ((haveShallowLine) ? ((haveSteepLine) ? 1.0/3.0 : 0.25) : ((haveSteepLine) ? 0.25 : 0.00)) : 0.00); + dst[12] = mix(dst[12], blendPix, (needBlend && doLineBlend && haveSteepLine) ? 0.25 : 0.00); + dst[13] = mix(dst[13], blendPix, (needBlend && doLineBlend && haveSteepLine) ? 0.75 : 0.00); + dst[14] = mix(dst[14], blendPix, (needBlend) ? ((doLineBlend) ? ((haveSteepLine) ? 1.00 : ((haveShallowLine) ? 0.75 : 0.50)) : 0.08677704501) : 0.00); + dst[15] = mix(dst[15], blendPix, (needBlend) ? ((doLineBlend) ? 1.00 : 0.6848532563) : 0.00); + dst[ 4] = mix(dst[ 4], blendPix, (needBlend) ? ((doLineBlend) ? ((haveShallowLine) ? 1.00 : ((haveSteepLine) ? 0.75 : 0.50)) : 0.08677704501) : 0.00); + dst[ 5] = mix(dst[ 5], blendPix, (needBlend && doLineBlend && haveShallowLine) ? 0.75 : 0.00); + dst[ 6] = mix(dst[ 6], blendPix, (needBlend && doLineBlend && haveShallowLine) ? 0.25 : 0.00); + } + + vec3 res = mix( mix( mix( mix(dst[ 6], dst[ 7], step(0.25, f.x)), mix(dst[ 8], dst[ 9], step(0.75, f.x)), step(0.50, f.x)), + mix( mix(dst[ 5], dst[ 0], step(0.25, f.x)), mix(dst[ 1], dst[10], step(0.75, f.x)), step(0.50, f.x)), step(0.25, f.y)), + mix( mix( mix(dst[ 4], dst[ 3], step(0.25, f.x)), mix(dst[ 2], dst[11], step(0.75, f.x)), step(0.50, f.x)), + mix( mix(dst[15], dst[14], step(0.25, f.x)), mix(dst[13], dst[12], step(0.75, f.x)), step(0.50, f.x)), step(0.75, f.y)), + step(0.50, f.y)); + + return ivec4(res * vec3(63,63,63), 0); +} + + +void main() +{ + vec2 fTexcoord = vTexCoord.xy; + + ivec4 pixel;// = ivec4(texelFetch(ScreenTex, ivec2(fTexcoord), 0)); + + ivec4 mbright = ivec4(texelFetch(ScreenTex, ivec2(256*3, int(fTexcoord.y)), 0)); + int dispmode = mbright.b & 0x3; + + if (dispmode == 1) + { + ivec4 val1;// = pixel; + //ivec4 val2 = ivec4(texelFetch(ScreenTex, ivec2(fTexcoord) + ivec2(256,0), 0)); + ivec4 val3 = ivec4(texelFetch(ScreenTex, ivec2(fTexcoord) + ivec2(512,0), 0)); + + int compmode = val3.a & 0xF; + int eva, evb, evy; + + float xpos = val3.r + fract(fTexcoord.x); + float ypos = mod(fTexcoord.y, 192); + ivec4 _3dpix = Get3DPixel(vec2(xpos, ypos)); + + if (compmode == 4) + { + // 3D on top, blending + + if (_3dpix.a > 0) + { + eva = (_3dpix.a & 0x1F) + 1; + if (eva == 32) + { + val1 = _3dpix; + } + else + { + evb = 32 - eva; + + val1 = GetFiltered2DPixel(0); + + val1 = ((_3dpix * eva) + (val1 * evb)) >> 5; + if (eva <= 16) val1 += ivec4(1,1,1,0); + val1 = min(val1, 0x3F); + } + } + else + val1 = GetFiltered2DPixel(1); + } + else if (compmode == 1) + { + // 3D on bottom, blending + + if (_3dpix.a > 0) + { + eva = val3.g; + evb = val3.b; + + val1 = GetFiltered2DPixel(0); + + val1 = ((val1 * eva) + (_3dpix * evb)) >> 4; + val1 = min(val1, 0x3F); + } + else + val1 = GetFiltered2DPixel(1); + } + else if (compmode <= 3) + { + // 3D on top, normal/fade + + if (_3dpix.a > 0) + { + evy = val3.g; + + val1 = _3dpix; + if (compmode == 2) val1 += ((ivec4(0x3F,0x3F,0x3F,0) - val1) * evy) >> 4; + else if (compmode == 3) val1 -= (val1 * evy) >> 4; + } + else + val1 = GetFiltered2DPixel(1); + } + else + val1 = GetFiltered2DPixel(0); + + pixel = val1; + } + else + { + pixel = GetFiltered2DPixel(0); + } + + if (dispmode != 0) + { + int brightmode = mbright.g >> 6; + if (brightmode == 1) + { + // up + int evy = mbright.r & 0x1F; + if (evy > 16) evy = 16; + + pixel += ((ivec4(0x3F,0x3F,0x3F,0) - pixel) * evy) >> 4; + } + else if (brightmode == 2) + { + // down + int evy = mbright.r & 0x1F; + if (evy > 16) evy = 16; + + pixel -= (pixel * evy) >> 4; + } + } + + pixel.rgb <<= 2; + pixel.rgb |= (pixel.rgb >> 6); + + FragColor = vec4(vec3(pixel.rgb) / 255.0, 1.0); +} +)"; + + + + + + +#endif // GPU_OPENGL_SHADERS_H diff --git a/src/OpenGLSupport.cpp b/src/OpenGLSupport.cpp index f91af9b..27b1480 100644 --- a/src/OpenGLSupport.cpp +++ b/src/OpenGLSupport.cpp @@ -19,18 +19,20 @@ #include "OpenGLSupport.h" +namespace OpenGL +{ DO_PROCLIST(DECLPROC); -bool OpenGL_Init() +bool Init() { DO_PROCLIST(LOADPROC); return true; } -bool OpenGL_BuildShaderProgram(const char* vs, const char* fs, GLuint* ids, const char* name) +bool BuildShaderProgram(const char* vs, const char* fs, GLuint* ids, const char* name) { int len; int res; @@ -89,7 +91,7 @@ bool OpenGL_BuildShaderProgram(const char* vs, const char* fs, GLuint* ids, cons return true; } -bool OpenGL_LinkShaderProgram(GLuint* ids) +bool LinkShaderProgram(GLuint* ids) { int res; @@ -115,14 +117,16 @@ bool OpenGL_LinkShaderProgram(GLuint* ids) return true; } -void OpenGL_DeleteShaderProgram(GLuint* ids) +void DeleteShaderProgram(GLuint* ids) { glDeleteShader(ids[0]); glDeleteShader(ids[1]); glDeleteProgram(ids[2]); } -void OpenGL_UseShaderProgram(GLuint* ids) +void UseShaderProgram(GLuint* ids) { glUseProgram(ids[2]); } + +} diff --git a/src/OpenGLSupport.h b/src/OpenGLSupport.h index 5f92580..360d215 100644 --- a/src/OpenGLSupport.h +++ b/src/OpenGLSupport.h @@ -21,6 +21,8 @@ #include #include + +// TODO: different includes for each platform #include #include @@ -45,23 +47,11 @@ // if you need more OpenGL functions, add them to the macronator here -// TODO: handle conditionally loading certain functions for different GL versions - -#ifndef __WIN32__ - -#define DO_PROCLIST_1_3(func) -#else -#define DO_PROCLIST_1_3(func) \ +#define DO_PROCLIST(func) \ func(GLACTIVETEXTURE, glActiveTexture); \ func(GLBLENDCOLOR, glBlendColor); \ - -#endif - - -#define DO_PROCLIST(func) \ - DO_PROCLIST_1_3(func) \ \ func(GLGENFRAMEBUFFERS, glGenFramebuffers); \ func(GLDELETEFRAMEBUFFERS, glDeleteFramebuffers); \ @@ -122,14 +112,18 @@ func(GLGETSTRINGI, glGetStringi); \ +namespace OpenGL +{ + DO_PROCLIST(DECLPROC_EXT); +bool Init(); -bool OpenGL_Init(); +bool BuildShaderProgram(const char* vs, const char* fs, GLuint* ids, const char* name); +bool LinkShaderProgram(GLuint* ids); +void DeleteShaderProgram(GLuint* ids); +void UseShaderProgram(GLuint* ids); -bool OpenGL_BuildShaderProgram(const char* vs, const char* fs, GLuint* ids, const char* name); -bool OpenGL_LinkShaderProgram(GLuint* ids); -void OpenGL_DeleteShaderProgram(GLuint* ids); -void OpenGL_UseShaderProgram(GLuint* ids); +} #endif // OPENGLSUPPORT_H diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index dd838d7..6b256e0 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -56,6 +56,7 @@ char* EmuDirectory; void emuStop(); +void* oglGetProcAddress(const char* proc); namespace Platform @@ -418,7 +419,7 @@ void Semaphore_Post(void* sema) void* GL_GetProcAddress(const char* proc) { - return NULL;//uiGLGetProcAddress(proc); + return oglGetProcAddress(proc); } diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index bb08a87..096b91c 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -45,6 +45,7 @@ #include "NDS.h" #include "GBACart.h" +#include "OpenGLSupport.h" #include "GPU.h" #include "SPU.h" #include "Wifi.h" @@ -258,6 +259,54 @@ EmuThread::EmuThread(QObject* parent) : QThread(parent) connect(this, SIGNAL(windowEmuPause()), mainWindow->actPause, SLOT(trigger())); connect(this, SIGNAL(windowEmuReset()), mainWindow->actReset, SLOT(trigger())); connect(this, SIGNAL(screenLayoutChange()), mainWindow->panel, SLOT(onScreenLayoutChanged())); + + initOpenGL(); +} + +void EmuThread::initOpenGL() +{ + QOpenGLContext* windowctx = mainWindow->getOGLContext(); + QSurfaceFormat format = windowctx->format(); + + oglSurface = new QOffscreenSurface(); + oglSurface->setFormat(format); + oglSurface->create(); + if (!oglSurface->isValid()) + { + // TODO handle this! + printf("oglSurface shat itself :(\n"); + delete oglSurface; + return; + } + + oglContext = new QOpenGLContext();//oglSurface); + oglContext->setFormat(oglSurface->format()); + oglContext->setShareContext(windowctx); + if (!oglContext->create()) + { + // TODO handle this! + printf("oglContext shat itself :(\n"); + delete oglContext; + delete oglSurface; + return; + } + + oglContext->moveToThread(this); +} + +void deinitOpenGL() +{ + // TODO!! +} + +void* oglGetProcAddress(const char* proc) +{ + return emuThread->oglGetProcAddress(proc); +} + +void* EmuThread::oglGetProcAddress(const char* proc) +{ + return (void*)oglContext->getProcAddress(proc); } void EmuThread::run() @@ -279,7 +328,11 @@ void EmuThread::run() } else*/ { - GPU3D::InitRenderer(false); + //GPU3D::InitRenderer(false); + bool res = oglContext->makeCurrent(oglSurface); + printf("good? %d\n", res); + OpenGL::Init(); + GPU3D::InitRenderer(res); } Input::Init(); @@ -755,6 +808,11 @@ void ScreenPanelGL::initializeGL() { initializeOpenGLFunctions(); + const GLubyte* renderer = glGetString(GL_RENDERER); // get renderer string + const GLubyte* version = glGetString(GL_VERSION); // version as a string + printf("OpenGL: renderer: %s\n", renderer); + printf("OpenGL: version: %s\n", version); + glClearColor(0, 0, 0, 1); screenShader = new QOpenGLShaderProgram(this); @@ -828,14 +886,24 @@ void ScreenPanelGL::paintGL() int frontbuf = GPU::FrontBuffer; glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, screenTexture); - if (GPU::Framebuffer[frontbuf][0] && GPU::Framebuffer[frontbuf][1]) + if (true) + { + // hardware-accelerated render + GPU::GLCompositor::BindOutputTexture(); + } + else { - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 192, GL_RGBA, - GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][0]); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 192, 256, 192, GL_RGBA, - GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][1]); + // regular render + glBindTexture(GL_TEXTURE_2D, screenTexture); + + if (GPU::Framebuffer[frontbuf][0] && GPU::Framebuffer[frontbuf][1]) + { + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 192, GL_RGBA, + GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][0]); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 192, 256, 192, GL_RGBA, + GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][1]); + } } GLint filter = Config::ScreenFilter ? GL_LINEAR : GL_NEAREST; @@ -1141,6 +1209,13 @@ MainWindow::~MainWindow() { } +QOpenGLContext* MainWindow::getOGLContext() +{ + // TODO: check whether we can actually pull this! + QOpenGLWidget* glpanel = (QOpenGLWidget*)panel; + return glpanel->context(); +} + void MainWindow::resizeEvent(QResizeEvent* event) { int w = event->size().width(); @@ -1755,6 +1830,13 @@ int main(int argc, char** argv) } #endif + QSurfaceFormat format; + format.setDepthBufferSize(24); + format.setStencilBufferSize(8); + format.setVersion(3, 2); + format.setProfile(QSurfaceFormat::CoreProfile); + QSurfaceFormat::setDefaultFormat(format); + audioSync = SDL_CreateCond(); audioSyncLock = SDL_CreateMutex(); diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 8a8c041..67c93d0 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -40,6 +41,11 @@ class EmuThread : public QThread public: explicit EmuThread(QObject* parent = nullptr); + void initOpenGL(); + void deinitOpenGL(); + + void* oglGetProcAddress(const char* proc); + void changeWindowTitle(char* title); // to be called from the UI thread @@ -67,6 +73,9 @@ private: volatile int EmuStatus; int PrevEmuStatus; int EmuRunning; + + QOffscreenSurface* oglSurface; + QOpenGLContext* oglContext; }; @@ -161,6 +170,8 @@ public: explicit MainWindow(QWidget* parent = nullptr); ~MainWindow(); + QOpenGLContext* getOGLContext(); + protected: void resizeEvent(QResizeEvent* event) override; -- cgit v1.2.3 From 24de8de5030c3a5a69c4df3c27db8076d3d0275d Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 25 May 2020 18:28:11 +0200 Subject: flushing the john makes it a bit better --- src/GPU_OpenGL.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/GPU_OpenGL.cpp b/src/GPU_OpenGL.cpp index c9d31f1..99eb845 100644 --- a/src/GPU_OpenGL.cpp +++ b/src/GPU_OpenGL.cpp @@ -196,6 +196,8 @@ void RenderFrame() glBindVertexArray(CompVertexArrayID); glDrawArrays(GL_TRIANGLES, 0, 4*3); } + + glFlush(); } void BindOutputTexture() -- cgit v1.2.3 From 4135ea374b37577694e2fe1b1346523d9255158c Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 25 May 2020 18:38:10 +0200 Subject: fix colors --- src/GPU_OpenGL_shaders.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/GPU_OpenGL_shaders.h b/src/GPU_OpenGL_shaders.h index ec975ed..20ac767 100644 --- a/src/GPU_OpenGL_shaders.h +++ b/src/GPU_OpenGL_shaders.h @@ -155,7 +155,7 @@ void main() // TODO: filters - oColor = vec4(vec3(pixel.rgb) / 255.0, 1.0); + oColor = vec4(vec3(pixel.bgr) / 255.0, 1.0); } )"; @@ -310,7 +310,7 @@ void main() // TODO: filters - oColor = vec4(vec3(pixel.rgb) / 255.0, 1.0); + oColor = vec4(vec3(pixel.bgr) / 255.0, 1.0); } )"; @@ -855,7 +855,7 @@ void main() pixel.rgb <<= 2; pixel.rgb |= (pixel.rgb >> 6); - FragColor = vec4(vec3(pixel.rgb) / 255.0, 1.0); + FragColor = vec4(vec3(pixel.bgr) / 255.0, 1.0); } )"; -- cgit v1.2.3 From 256360aebba709d7b8565cd35bd9d42473219fd5 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 27 May 2020 19:18:45 +0200 Subject: texture2D -> texture Intel driver threw a fit about it --- src/frontend/qt_sdl/main_shaders.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/main_shaders.h b/src/frontend/qt_sdl/main_shaders.h index 2e57e59..96b9ecd 100644 --- a/src/frontend/qt_sdl/main_shaders.h +++ b/src/frontend/qt_sdl/main_shaders.h @@ -55,7 +55,7 @@ out vec4 oColor; void main() { - vec4 pixel = texture2D(ScreenTex, fTexcoord); + vec4 pixel = texture(ScreenTex, fTexcoord); oColor = vec4(pixel.bgr, 1.0); } -- cgit v1.2.3 From ef2802ae31c4af965457216a190535b41efe749d Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 27 May 2020 21:29:47 +0200 Subject: * use GL shim window instead of offscreen surface * disable vsync by default (we'll take care of it later) --- src/frontend/qt_sdl/main.cpp | 19 +++++++++++++++++-- src/frontend/qt_sdl/main.h | 13 ++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 096b91c..8f2a61e 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -268,7 +268,7 @@ void EmuThread::initOpenGL() QOpenGLContext* windowctx = mainWindow->getOGLContext(); QSurfaceFormat format = windowctx->format(); - oglSurface = new QOffscreenSurface(); + /*oglSurface = new QOffscreenSurface(); oglSurface->setFormat(format); oglSurface->create(); if (!oglSurface->isValid()) @@ -277,7 +277,8 @@ void EmuThread::initOpenGL() printf("oglSurface shat itself :(\n"); delete oglSurface; return; - } + }*/ + oglSurface = new GLShim(format); oglContext = new QOpenGLContext();//oglSurface); oglContext->setFormat(oglSurface->format()); @@ -957,6 +958,19 @@ void ScreenPanelGL::onScreenLayoutChanged() } +GLShim::GLShim(QSurfaceFormat& format) : QWindow() +{ + setSurfaceType(QSurface::OpenGLSurface); + setFormat(format); + create(); + hide(); +} + +GLShim::~GLShim() +{ +} + + MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { setWindowTitle("melonDS " MELONDS_VERSION); @@ -1835,6 +1849,7 @@ int main(int argc, char** argv) format.setStencilBufferSize(8); format.setVersion(3, 2); format.setProfile(QSurfaceFormat::CoreProfile); + format.setSwapInterval(0); QSurfaceFormat::setDefaultFormat(format); audioSync = SDL_CreateCond(); diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 67c93d0..2a24960 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -74,7 +75,7 @@ private: int PrevEmuStatus; int EmuRunning; - QOffscreenSurface* oglSurface; + QSurface* oglSurface; QOpenGLContext* oglContext; }; @@ -162,6 +163,16 @@ private: }; +class GLShim : public QWindow +{ + Q_OBJECT + +public: + explicit GLShim(QSurfaceFormat& format); + ~GLShim(); +}; + + class MainWindow : public QMainWindow { Q_OBJECT -- cgit v1.2.3 From e8849db78abe4db518c7f324323b88f478acc69a Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 27 May 2020 21:40:02 +0200 Subject: we don't need a GLShim. blarg. I don't understand this anymore. --- src/GPU3D_OpenGL.cpp | 1 - src/frontend/qt_sdl/main.cpp | 18 ++---------------- src/frontend/qt_sdl/main.h | 12 +----------- 3 files changed, 3 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/GPU3D_OpenGL.cpp b/src/GPU3D_OpenGL.cpp index dcc4b6b..74760e5 100644 --- a/src/GPU3D_OpenGL.cpp +++ b/src/GPU3D_OpenGL.cpp @@ -199,7 +199,6 @@ bool Init() glEnable(GL_DEPTH_TEST); glEnable(GL_STENCIL_TEST); - glDepthRange(0, 1); glClearDepth(1.0); diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 8f2a61e..f282310 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -268,7 +268,7 @@ void EmuThread::initOpenGL() QOpenGLContext* windowctx = mainWindow->getOGLContext(); QSurfaceFormat format = windowctx->format(); - /*oglSurface = new QOffscreenSurface(); + oglSurface = new QOffscreenSurface(); oglSurface->setFormat(format); oglSurface->create(); if (!oglSurface->isValid()) @@ -277,8 +277,7 @@ void EmuThread::initOpenGL() printf("oglSurface shat itself :(\n"); delete oglSurface; return; - }*/ - oglSurface = new GLShim(format); + } oglContext = new QOpenGLContext();//oglSurface); oglContext->setFormat(oglSurface->format()); @@ -958,19 +957,6 @@ void ScreenPanelGL::onScreenLayoutChanged() } -GLShim::GLShim(QSurfaceFormat& format) : QWindow() -{ - setSurfaceType(QSurface::OpenGLSurface); - setFormat(format); - create(); - hide(); -} - -GLShim::~GLShim() -{ -} - - MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { setWindowTitle("melonDS " MELONDS_VERSION); diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 2a24960..8759e95 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -75,7 +75,7 @@ private: int PrevEmuStatus; int EmuRunning; - QSurface* oglSurface; + QOffscreenSurface* oglSurface; QOpenGLContext* oglContext; }; @@ -163,16 +163,6 @@ private: }; -class GLShim : public QWindow -{ - Q_OBJECT - -public: - explicit GLShim(QSurfaceFormat& format); - ~GLShim(); -}; - - class MainWindow : public QMainWindow { Q_OBJECT -- cgit v1.2.3 From 0a68eb78039a7a27b16d389844beeebed139f864 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 28 May 2020 11:52:12 +0200 Subject: make it hiDPI compliant (I hope) also misc tweaks --- src/GPU3D_OpenGL.cpp | 2 +- src/OpenGLSupport.h | 5 +++++ src/frontend/qt_sdl/AudioSettingsDialog.ui | 7 +++++-- src/frontend/qt_sdl/main.cpp | 6 +++--- 4 files changed, 14 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/GPU3D_OpenGL.cpp b/src/GPU3D_OpenGL.cpp index 74760e5..9a78504 100644 --- a/src/GPU3D_OpenGL.cpp +++ b/src/GPU3D_OpenGL.cpp @@ -1236,7 +1236,7 @@ void RenderFrame() glBlitFramebuffer(0, 0, ScreenW, ScreenH, 0, 0, ScreenW/2, ScreenH/2, GL_COLOR_BUFFER_BIT, GL_LINEAR); } - glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[FrontBuffer]); + //glBindFramebuffer(GL_FRAMEBUFFER, FramebufferID[FrontBuffer]); FrontBuffer = FrontBuffer ? 0 : 1; } diff --git a/src/OpenGLSupport.h b/src/OpenGLSupport.h index 360d215..edf7eda 100644 --- a/src/OpenGLSupport.h +++ b/src/OpenGLSupport.h @@ -102,6 +102,11 @@ func(GLGETUNIFORMLOCATION, glGetUniformLocation); \ func(GLGETUNIFORMBLOCKINDEX, glGetUniformBlockIndex); \ \ + func(GLFENCESYNC, glFenceSync); \ + func(GLDELETESYNC, glDeleteSync); \ + func(GLWAITSYNC, glWaitSync); \ + func(GLCLIENTWAITSYNC, glClientWaitSync); \ + \ func(GLDRAWBUFFERS, glDrawBuffers); \ \ func(GLBLENDFUNCSEPARATE, glBlendFuncSeparate); \ diff --git a/src/frontend/qt_sdl/AudioSettingsDialog.ui b/src/frontend/qt_sdl/AudioSettingsDialog.ui index c4e993e..9ae8baa 100644 --- a/src/frontend/qt_sdl/AudioSettingsDialog.ui +++ b/src/frontend/qt_sdl/AudioSettingsDialog.ui @@ -60,12 +60,15 @@ 0 + + <html><head/><body><p>Forward a WAV file to the emulated microphone.</p><p>This input mode is activated by holding the microphone hotkey (see Input and Hotkeys).</p></body></html> + - <html><head/><body><p>Forward a WAV file to the emulated microphone.</p></body></html> + <html><head/><body><p>Forward a WAV file to the emulated microphone.</p><p>This input mode is activated by holding the microphone hotkey (see Input and Hotkeys).</p></body></html> WAV file: @@ -92,7 +95,7 @@ - <html><head/><body><p>Noise will be forwarded to the emulated microphone, simulating blowing into the microphone.</p></body></html> + <html><head/><body><p>Noise will be forwarded to the emulated microphone, simulating blowing into the microphone.</p><p>This input mode is activated by holding the microphone hotkey (see Input and Hotkeys).</p></body></html> Blow noise diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index f282310..20084ff 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -874,15 +874,15 @@ void ScreenPanelGL::paintGL() { int w = width(); int h = height(); + float factor = devicePixelRatioF(); glClear(GL_COLOR_BUFFER_BIT); - // TODO: check hiDPI compliance of this - glViewport(0, 0, w, h); + glViewport(0, 0, w*factor, h*factor); screenShader->bind(); - screenShader->setUniformValue("uScreenSize", (float)w, (float)h); + screenShader->setUniformValue("uScreenSize", (float)w*factor, (float)h*factor); int frontbuf = GPU::FrontBuffer; glActiveTexture(GL_TEXTURE0); -- cgit v1.2.3 From 695839bb0ef8173ad2a549dd7766186fa65e949a Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 28 May 2020 12:32:50 +0200 Subject: lay base for video settings dialog --- src/frontend/qt_sdl/CMakeLists.txt | 1 + src/frontend/qt_sdl/VideoSettingsDialog.cpp | 67 +++++++++ src/frontend/qt_sdl/VideoSettingsDialog.h | 67 +++++++++ src/frontend/qt_sdl/VideoSettingsDialog.ui | 220 ++++++++++++++++++++++++++++ src/frontend/qt_sdl/main.cpp | 3 +- 5 files changed, 357 insertions(+), 1 deletion(-) create mode 100644 src/frontend/qt_sdl/VideoSettingsDialog.cpp create mode 100644 src/frontend/qt_sdl/VideoSettingsDialog.h create mode 100644 src/frontend/qt_sdl/VideoSettingsDialog.ui (limited to 'src') diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index 5778b40..a4bb5f5 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -5,6 +5,7 @@ SET(SOURCES_QT_SDL main_shaders.h EmuSettingsDialog.cpp InputConfigDialog.cpp + VideoSettingsDialog.cpp AudioSettingsDialog.cpp Input.cpp Platform.cpp diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp new file mode 100644 index 0000000..c0ec42a --- /dev/null +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -0,0 +1,67 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include +#include + +#include "types.h" +#include "Platform.h" +#include "Config.h" +#include "PlatformConfig.h" + +#include "VideoSettingsDialog.h" +#include "ui_VideoSettingsDialog.h" + + +VideoSettingsDialog* VideoSettingsDialog::currentDlg = nullptr; + + +VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::VideoSettingsDialog) +{ + ui->setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + + // + + grp3DRenderer = new QButtonGroup(this); + grp3DRenderer->addButton(ui->rb3DSoftware, 0); + grp3DRenderer->addButton(ui->rb3DOpenGL, 1); + //connect(grp3DRenderer, SIGNAL(buttonClicked(int)), this, SLOT(onChange3DRenderer(int))); +} + +VideoSettingsDialog::~VideoSettingsDialog() +{ + delete ui; +} + +void VideoSettingsDialog::on_VideoSettingsDialog_accepted() +{ + // + Config::Save(); + + closeDlg(); +} + +void VideoSettingsDialog::on_VideoSettingsDialog_rejected() +{ + // + + closeDlg(); +} + +// diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.h b/src/frontend/qt_sdl/VideoSettingsDialog.h new file mode 100644 index 0000000..d64cee2 --- /dev/null +++ b/src/frontend/qt_sdl/VideoSettingsDialog.h @@ -0,0 +1,67 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef VIDEOSETTINGSDIALOG_H +#define VIDEOSETTINGSDIALOG_H + +#include +#include + +namespace Ui { class VideoSettingsDialog; } +class VideoSettingsDialog; + +class VideoSettingsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit VideoSettingsDialog(QWidget* parent); + ~VideoSettingsDialog(); + + static VideoSettingsDialog* currentDlg; + static VideoSettingsDialog* openDlg(QWidget* parent) + { + if (currentDlg) + { + currentDlg->activateWindow(); + return currentDlg; + } + + currentDlg = new VideoSettingsDialog(parent); + currentDlg->show(); + return currentDlg; + } + static void closeDlg() + { + currentDlg = nullptr; + } + +private slots: + void on_VideoSettingsDialog_accepted(); + void on_VideoSettingsDialog_rejected(); + + // + +private: + Ui::VideoSettingsDialog* ui; + + QButtonGroup* grp3DRenderer; +}; + +#endif // VIDEOSETTINGSDIALOG_H + diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.ui b/src/frontend/qt_sdl/VideoSettingsDialog.ui new file mode 100644 index 0000000..06670e5 --- /dev/null +++ b/src/frontend/qt_sdl/VideoSettingsDialog.ui @@ -0,0 +1,220 @@ + + + VideoSettingsDialog + + + + 0 + 0 + 482 + 237 + + + + Video settings - melonDS + + + + + + OpenGL renderer + + + + + + Internal resolution: + + + + + + + <html><head/><body><p>The resolution at which the 3D graphics will be rendered. Higher resolutions improve graphics quality when the main window is enlarged, but may also cause glitches.</p></body></html> + + + + + + + + + + Software renderer + + + + + + <html><head/><body><p>Run the software renderer on a separate thread. Yields better performance on multi-core CPUs.</p></body></html> + + + Use separate thread + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Display settings + + + + + + + 0 + 0 + + + + <html><head/><body><p>The interval at which to synchronize to the monitor's refresh rate. Set to 1 for a 60Hz monitor, 2 for 120Hz, ...</p></body></html> + + + VSync interval: + + + + + + + <html><head/><body><p>The interval at which to synchronize to the monitor's refresh rate. Set to 1 for a 60Hz monitor, 2 for 120Hz, ...</p></body></html> + + + 1 + + + 20 + + + + + + + <html><head/><body><p>Use OpenGL to draw the DS screens to the main window. May result in better frame pacing. Mandatory when using the OpenGL 3D renderer.</p></body></html> + + + OpenGL display + + + + + + + <html><head/><body><p>When using OpenGL, synchronize the video output to your monitor's refresh rate.</p></body></html> + + + VSync + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + <html><head/><body><p>The OpenGL renderer may be faster than software and supports graphical enhancements, but is more prone to glitches.</p></body></html> + + + OpenGL + + + + + + + <html><head/><body><p>The software renderer is more accurate and less prone to rendering glitches, but requires more CPU power.</p></body></html> + + + Software + + + + + + + 3D renderer: + + + + + + + + + + + + buttonBox + accepted() + VideoSettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + VideoSettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 20084ff..ae4bcf3 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -36,6 +36,7 @@ #include "Input.h" #include "EmuSettingsDialog.h" #include "InputConfigDialog.h" +#include "VideoSettingsDialog.h" #include "AudioSettingsDialog.h" #include "types.h" @@ -1573,7 +1574,7 @@ void MainWindow::onInputConfigFinished(int res) void MainWindow::onOpenVideoSettings() { - // + VideoSettingsDialog* dlg = VideoSettingsDialog::openDlg(this); } void MainWindow::onOpenAudioSettings() -- cgit v1.2.3 From 5005a7c3f0f78c4684dbdcde0d88ae48050ab6fe Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 28 May 2020 13:21:25 +0200 Subject: populate the dialog. also add setting for vsync interval. --- src/frontend/qt_sdl/PlatformConfig.cpp | 6 ++++-- src/frontend/qt_sdl/PlatformConfig.h | 1 + src/frontend/qt_sdl/VideoSettingsDialog.cpp | 19 ++++++++++++++++++- src/frontend/qt_sdl/VideoSettingsDialog.h | 7 +++++++ 4 files changed, 30 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/PlatformConfig.cpp b/src/frontend/qt_sdl/PlatformConfig.cpp index 28c224d..03fd2ac 100644 --- a/src/frontend/qt_sdl/PlatformConfig.cpp +++ b/src/frontend/qt_sdl/PlatformConfig.cpp @@ -45,6 +45,7 @@ int ScreenFilter; int ScreenUseGL; int ScreenVSync; +int ScreenVSyncInterval; int LimitFPS; int AudioSync; @@ -124,8 +125,9 @@ ConfigEntry PlatformConfigFile[] = {"IntegerScaling", 0, &IntegerScaling, 0, NULL, 0}, {"ScreenFilter", 0, &ScreenFilter, 1, NULL, 0}, - {"ScreenUseGL", 0, &ScreenUseGL, 1, NULL, 0}, - {"ScreenVSync", 0, &ScreenVSync, 0, NULL, 0}, + {"ScreenUseGL", 0, &ScreenUseGL, 1, NULL, 0}, + {"ScreenVSync", 0, &ScreenVSync, 0, NULL, 0}, + {"ScreenVSyncInterval", 0, &ScreenVSyncInterval, 1, NULL, 0}, {"LimitFPS", 0, &LimitFPS, 0, NULL, 0}, {"AudioSync", 0, &AudioSync, 1, NULL, 0}, diff --git a/src/frontend/qt_sdl/PlatformConfig.h b/src/frontend/qt_sdl/PlatformConfig.h index 539f9a4..cc288b6 100644 --- a/src/frontend/qt_sdl/PlatformConfig.h +++ b/src/frontend/qt_sdl/PlatformConfig.h @@ -58,6 +58,7 @@ extern int ScreenFilter; extern int ScreenUseGL; extern int ScreenVSync; +extern int ScreenVSyncInterval; extern int LimitFPS; extern int AudioSync; diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp index c0ec42a..0aeb154 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.cpp +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -36,12 +36,29 @@ VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui( ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); - // + oldRenderer = Config::_3DRenderer; + oldGLDisplay = Config::ScreenUseGL; + oldVSync = Config::ScreenVSync; + oldVSyncInterval = Config::ScreenVSyncInterval; + oldSoftThreaded = Config::Threaded3D; + oldGLScale = Config::GL_ScaleFactor; grp3DRenderer = new QButtonGroup(this); grp3DRenderer->addButton(ui->rb3DSoftware, 0); grp3DRenderer->addButton(ui->rb3DOpenGL, 1); //connect(grp3DRenderer, SIGNAL(buttonClicked(int)), this, SLOT(onChange3DRenderer(int))); + grp3DRenderer->button(Config::_3DRenderer)->setChecked(true); + + ui->cbGLDisplay->setChecked(Config::ScreenUseGL != 0); + + ui->cbVSync->setChecked(Config::ScreenVSync != 0); + ui->sbVSyncInterval->setValue(Config::ScreenVSyncInterval); + + ui->cbSoftwareThreaded->setChecked(Config::Threaded3D != 0); + + for (int i = 1; i <= 16; i++) + ui->cbxGLResolution->addItem(QString("%1x native (%2x%3)").arg(i).arg(256*i).arg(192*i), QVariant(i)); + ui->cbxGLResolution->setCurrentIndex(Config::GL_ScaleFactor); } VideoSettingsDialog::~VideoSettingsDialog() diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.h b/src/frontend/qt_sdl/VideoSettingsDialog.h index d64cee2..05dfecb 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.h +++ b/src/frontend/qt_sdl/VideoSettingsDialog.h @@ -61,6 +61,13 @@ private: Ui::VideoSettingsDialog* ui; QButtonGroup* grp3DRenderer; + + int oldRenderer; + int oldGLDisplay; + int oldVSync; + int oldVSyncInterval; + int oldSoftThreaded; + int oldGLScale; }; #endif // VIDEOSETTINGSDIALOG_H -- cgit v1.2.3 From 0804ab3c783363e28229a2028dc70b4238cb1802 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 28 May 2020 15:53:32 +0200 Subject: * rework GPU's settings interface, make it config-agnostic * make video settings dialog functional, sorta * fix dialogs that were resizable --- src/GPU.cpp | 78 +++++++++++++- src/GPU.h | 22 +++- src/GPU2D.cpp | 14 +-- src/GPU2D.h | 2 +- src/GPU3D.cpp | 57 +---------- src/GPU3D.h | 7 +- src/GPU3D_OpenGL.cpp | 17 +--- src/GPU3D_Soft.cpp | 10 +- src/GPU_OpenGL.cpp | 39 ++++--- src/frontend/qt_sdl/AudioSettingsDialog.ui | 9 ++ src/frontend/qt_sdl/VideoSettingsDialog.cpp | 79 +++++++++++++-- src/frontend/qt_sdl/VideoSettingsDialog.h | 9 +- src/frontend/qt_sdl/VideoSettingsDialog.ui | 9 ++ src/frontend/qt_sdl/main.cpp | 152 +++++++++++++++++++--------- src/frontend/qt_sdl/main.h | 5 + 15 files changed, 342 insertions(+), 167 deletions(-) (limited to 'src') diff --git a/src/GPU.cpp b/src/GPU.cpp index 993086e..56db0e2 100644 --- a/src/GPU.cpp +++ b/src/GPU.cpp @@ -78,6 +78,7 @@ u8* VRAMPtr_BOBJ[0x8]; int FrontBuffer; u32* Framebuffer[2][2]; +int Renderer; bool Accelerated; GPU2D* GPU2D_A; @@ -93,8 +94,8 @@ bool Init() FrontBuffer = 0; Framebuffer[0][0] = NULL; Framebuffer[0][1] = NULL; Framebuffer[1][0] = NULL; Framebuffer[1][1] = NULL; + Renderer = 0; Accelerated = false; - SetDisplaySettings(false); return true; } @@ -182,6 +183,8 @@ void Reset() int backbuf = FrontBuffer ? 0 : 1; GPU2D_A->SetFramebuffer(Framebuffer[backbuf][1]); GPU2D_B->SetFramebuffer(Framebuffer[backbuf][0]); + + ResetRenderer(); } void Stop() @@ -274,8 +277,65 @@ void AssignFramebuffers() } } -void SetDisplaySettings(bool accel) +void InitRenderer(int renderer) +{ + if (renderer == 1) + { + if (!GLCompositor::Init()) + { + renderer = 0; + } + else if (!GPU3D::GLRenderer::Init()) + { + GLCompositor::DeInit(); + renderer = 0; + } + } + + if (renderer == 0) + { + GPU3D::SoftRenderer::Init(); + } + + Renderer = renderer; + Accelerated = renderer != 0; +} + +void DeInitRenderer() +{ + if (Renderer == 0) + { + GPU3D::SoftRenderer::DeInit(); + } + else + { + GPU3D::GLRenderer::DeInit(); + GLCompositor::DeInit(); + } +} + +void ResetRenderer() { + if (Renderer == 0) + { + GPU3D::SoftRenderer::Reset(); + } + else + { + GLCompositor::Reset(); + GPU3D::GLRenderer::Reset(); + } +} + +void SetRenderSettings(int renderer, RenderSettings& settings) +{ + if (renderer != Renderer) + { + DeInitRenderer(); + InitRenderer(renderer); + } + + bool accel = Accelerated; int fbsize; if (accel) fbsize = (256*3 + 1) * 192; else fbsize = 256 * 192; @@ -296,10 +356,18 @@ void SetDisplaySettings(bool accel) AssignFramebuffers(); - GPU2D_A->SetDisplaySettings(accel); - GPU2D_B->SetDisplaySettings(accel); + GPU2D_A->SetRenderSettings(accel); + GPU2D_B->SetRenderSettings(accel); - Accelerated = accel; + if (Renderer == 0) + { + GPU3D::SoftRenderer::SetRenderSettings(settings); + } + else + { + GLCompositor::SetRenderSettings(settings); + GPU3D::GLRenderer::SetRenderSettings(settings); + } } diff --git a/src/GPU.h b/src/GPU.h index e85a5b4..039e065 100644 --- a/src/GPU.h +++ b/src/GPU.h @@ -20,7 +20,6 @@ #define GPU_H #include "GPU2D.h" -#include "GPU3D.h" namespace GPU { @@ -72,6 +71,17 @@ extern u32* Framebuffer[2][2]; extern GPU2D* GPU2D_A; extern GPU2D* GPU2D_B; +extern int Renderer; + + +typedef struct +{ + bool Soft_Threaded; + + int GL_ScaleFactor; + +} RenderSettings; + bool Init(); void DeInit(); @@ -80,7 +90,11 @@ void Stop(); void DoSavestate(Savestate* file); -void SetDisplaySettings(bool accel); +void InitRenderer(int renderer); +void DeInitRenderer(); +void ResetRenderer(); + +void SetRenderSettings(int renderer, RenderSettings& settings); u8* GetUniqueBankPtr(u32 mask, u32 offset); @@ -429,7 +443,7 @@ bool Init(); void DeInit(); void Reset(); -void UpdateDisplaySettings(); +void SetRenderSettings(RenderSettings& settings); void RenderFrame(); void BindOutputTexture(); @@ -438,4 +452,6 @@ void BindOutputTexture(); } +#include "GPU3D.h" + #endif diff --git a/src/GPU2D.cpp b/src/GPU2D.cpp index 6f950b7..604a4ee 100644 --- a/src/GPU2D.cpp +++ b/src/GPU2D.cpp @@ -202,16 +202,8 @@ void GPU2D::DoSavestate(Savestate* file) file->Var32(&CaptureCnt); } - if (file->IsAtleastVersion(2, 1)) - { - file->Var32(&Win0Active); - file->Var32(&Win1Active); - } - else - { - Win0Active = 0; - Win1Active = 0; - } + file->Var32(&Win0Active); + file->Var32(&Win1Active); if (!file->Saving) { @@ -232,7 +224,7 @@ void GPU2D::SetFramebuffer(u32* buf) Framebuffer = buf; } -void GPU2D::SetDisplaySettings(bool accel) +void GPU2D::SetRenderSettings(bool accel) { Accelerated = accel; diff --git a/src/GPU2D.h b/src/GPU2D.h index c4bd2f9..521adf0 100644 --- a/src/GPU2D.h +++ b/src/GPU2D.h @@ -31,7 +31,7 @@ public: void SetEnabled(bool enable) { Enabled = enable; } void SetFramebuffer(u32* buf); - void SetDisplaySettings(bool accel); + void SetRenderSettings(bool accel); u8 Read8(u32 addr); u16 Read16(u32 addr); diff --git a/src/GPU3D.cpp b/src/GPU3D.cpp index e687e37..bd27783 100644 --- a/src/GPU3D.cpp +++ b/src/GPU3D.cpp @@ -157,8 +157,6 @@ u32 NumCommands, CurCommand, ParamCount, TotalParams; bool GeometryEnabled; bool RenderingEnabled; -int Renderer; - u32 DispCnt; u8 AlphaRefVal, AlphaRef; @@ -280,17 +278,11 @@ bool Init() CmdStallQueue = new FIFO(64); - Renderer = -1; - // SetRenderer() will be called to set it up later - return true; } void DeInit() { - if (Renderer == 0) SoftRenderer::DeInit(); - else GLRenderer::DeInit(); - delete CmdFIFO; delete CmdPIPE; @@ -391,8 +383,6 @@ void Reset() FlushAttributes = 0; ResetRenderingState(); - if (Renderer == 0) SoftRenderer::Reset(); - else GLRenderer::Reset(); } void DoSavestate(Savestate* file) @@ -607,43 +597,6 @@ void SetEnabled(bool geometry, bool rendering) } -int InitRenderer(bool hasGL) -{ - int renderer = hasGL ? Config::_3DRenderer : 0; - - if (renderer == 1) - { - if (!GLRenderer::Init()) - renderer = 0; - } -printf("renderer: %d\n", renderer); - if (renderer == 0) SoftRenderer::Init(); - - Renderer = renderer; - UpdateRendererConfig(); - GPU::SetDisplaySettings(Renderer != 0); - return renderer; -} - -void DeInitRenderer() -{ - if (Renderer == 0) SoftRenderer::DeInit(); - else GLRenderer::DeInit(); -} - -void UpdateRendererConfig() -{ - if (Renderer == 0) - { - SoftRenderer::SetupRenderThread(); - } - else - { - GLRenderer::UpdateDisplaySettings(); - } -} - - void MatrixLoadIdentity(s32* m) { @@ -2470,7 +2423,7 @@ void CheckFIFODMA() void VCount144() { - if (Renderer == 0) SoftRenderer::VCount144(); + if (GPU::Renderer == 0) SoftRenderer::VCount144(); } @@ -2552,14 +2505,14 @@ void VBlank() void VCount215() { - if (Renderer == 0) SoftRenderer::RenderFrame(); - else GLRenderer::RenderFrame(); + if (GPU::Renderer == 0) SoftRenderer::RenderFrame(); + else GLRenderer::RenderFrame(); } u32* GetLine(int line) { - if (Renderer == 0) return SoftRenderer::GetLine(line); - else return GLRenderer::GetLine(line); + if (GPU::Renderer == 0) return SoftRenderer::GetLine(line); + else return GLRenderer::GetLine(line); } diff --git a/src/GPU3D.h b/src/GPU3D.h index 1fd3383..71f069d 100644 --- a/src/GPU3D.h +++ b/src/GPU3D.h @@ -102,10 +102,6 @@ void DoSavestate(Savestate* file); void SetEnabled(bool geometry, bool rendering); -int InitRenderer(bool hasGL); -void DeInitRenderer(); -void UpdateRendererConfig(); - void ExecuteCommand(); s32 CyclesToRunFor(); @@ -134,6 +130,7 @@ bool Init(); void DeInit(); void Reset(); +void SetRenderSettings(GPU::RenderSettings& settings); void SetupRenderThread(); void VCount144(); @@ -149,7 +146,7 @@ bool Init(); void DeInit(); void Reset(); -void UpdateDisplaySettings(); +void SetRenderSettings(GPU::RenderSettings& settings); void RenderFrame(); void PrepareCaptureFrame(); diff --git a/src/GPU3D_OpenGL.cpp b/src/GPU3D_OpenGL.cpp index 9a78504..8a06874 100644 --- a/src/GPU3D_OpenGL.cpp +++ b/src/GPU3D_OpenGL.cpp @@ -372,19 +372,11 @@ bool Init() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB5_A1, 1024, 48, 0, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, NULL); - if (!GPU::GLCompositor::Init()) - { - // TODO: clean up things? fail more gracefully?? - return false; - } - return true; } void DeInit() { - GPU::GLCompositor::DeInit(); - glDeleteTextures(1, &TexMemID); glDeleteTextures(1, &TexPalMemID); @@ -407,13 +399,12 @@ void DeInit() void Reset() { - GPU::GLCompositor::Reset(); } -void UpdateDisplaySettings() +void SetRenderSettings(GPU::RenderSettings& settings) { - int scale = Config::GL_ScaleFactor; - bool antialias = false; //Config::GL_Antialias; + int scale = settings.GL_ScaleFactor; + bool antialias = false; // REMOVE ME! if (antialias) scale *= 2; @@ -490,8 +481,6 @@ void UpdateDisplaySettings() //glLineWidth(scale); //glLineWidth(1.5); - - GPU::GLCompositor::UpdateDisplaySettings(); } diff --git a/src/GPU3D_Soft.cpp b/src/GPU3D_Soft.cpp index 8397898..e9d8e75 100644 --- a/src/GPU3D_Soft.cpp +++ b/src/GPU3D_Soft.cpp @@ -60,6 +60,7 @@ bool Enabled; // threading +bool Threaded; void* RenderThread; bool RenderThreadRunning; bool RenderThreadRendering; @@ -83,7 +84,7 @@ void StopRenderThread() void SetupRenderThread() { - if (Config::Threaded3D) + if (Threaded) { if (!RenderThreadRunning) { @@ -112,6 +113,7 @@ bool Init() Sema_RenderDone = Platform::Semaphore_Create(); Sema_ScanlineCount = Platform::Semaphore_Create(); + Threaded = false; RenderThreadRunning = false; RenderThreadRendering = false; @@ -138,6 +140,12 @@ void Reset() SetupRenderThread(); } +void SetRenderSettings(GPU::RenderSettings& settings) +{ + Threaded = settings.Soft_Threaded; + SetupRenderThread(); +} + // Notes on the interpolator: diff --git a/src/GPU_OpenGL.cpp b/src/GPU_OpenGL.cpp index 99eb845..1cb6864 100644 --- a/src/GPU_OpenGL.cpp +++ b/src/GPU_OpenGL.cpp @@ -142,9 +142,9 @@ void Reset() } -void UpdateDisplaySettings() +void SetRenderSettings(RenderSettings& settings) { - int scale = Config::GL_ScaleFactor; + int scale = settings.GL_ScaleFactor; Scale = scale; ScreenW = 256 * scale; @@ -175,28 +175,25 @@ void RenderFrame() OpenGL::UseShaderProgram(CompShader[0]); glUniform1ui(CompScaleLoc[0], Scale); - //if (RunningSomething) + int frontbuf = GPU::FrontBuffer; + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, CompScreenInputTex); + + if (GPU::Framebuffer[frontbuf][0] && GPU::Framebuffer[frontbuf][1]) { - int frontbuf = GPU::FrontBuffer; - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, CompScreenInputTex); - - if (GPU::Framebuffer[frontbuf][0] && GPU::Framebuffer[frontbuf][1]) - { - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256*3 + 1, 192, GL_RGBA_INTEGER, - GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][0]); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 192, 256*3 + 1, 192, GL_RGBA_INTEGER, - GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][1]); - } - - glActiveTexture(GL_TEXTURE1); - GPU3D::GLRenderer::SetupAccelFrame(); - - glBindBuffer(GL_ARRAY_BUFFER, CompVertexBufferID); - glBindVertexArray(CompVertexArrayID); - glDrawArrays(GL_TRIANGLES, 0, 4*3); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256*3 + 1, 192, GL_RGBA_INTEGER, + GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][0]); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 192, 256*3 + 1, 192, GL_RGBA_INTEGER, + GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][1]); } + glActiveTexture(GL_TEXTURE1); + GPU3D::GLRenderer::SetupAccelFrame(); + + glBindBuffer(GL_ARRAY_BUFFER, CompVertexBufferID); + glBindVertexArray(CompVertexArrayID); + glDrawArrays(GL_TRIANGLES, 0, 4*3); + glFlush(); } diff --git a/src/frontend/qt_sdl/AudioSettingsDialog.ui b/src/frontend/qt_sdl/AudioSettingsDialog.ui index 9ae8baa..bcaf937 100644 --- a/src/frontend/qt_sdl/AudioSettingsDialog.ui +++ b/src/frontend/qt_sdl/AudioSettingsDialog.ui @@ -10,10 +10,19 @@ 230 + + + 0 + 0 + + Audio settings - melonDS + + QLayout::SetFixedSize + diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp index 0aeb154..09f1ab4 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.cpp +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -46,7 +46,7 @@ VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui( grp3DRenderer = new QButtonGroup(this); grp3DRenderer->addButton(ui->rb3DSoftware, 0); grp3DRenderer->addButton(ui->rb3DOpenGL, 1); - //connect(grp3DRenderer, SIGNAL(buttonClicked(int)), this, SLOT(onChange3DRenderer(int))); + connect(grp3DRenderer, SIGNAL(buttonClicked(int)), this, SLOT(onChange3DRenderer(int))); grp3DRenderer->button(Config::_3DRenderer)->setChecked(true); ui->cbGLDisplay->setChecked(Config::ScreenUseGL != 0); @@ -57,8 +57,21 @@ VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui( ui->cbSoftwareThreaded->setChecked(Config::Threaded3D != 0); for (int i = 1; i <= 16; i++) - ui->cbxGLResolution->addItem(QString("%1x native (%2x%3)").arg(i).arg(256*i).arg(192*i), QVariant(i)); - ui->cbxGLResolution->setCurrentIndex(Config::GL_ScaleFactor); + ui->cbxGLResolution->addItem(QString("%1x native (%2x%3)").arg(i).arg(256*i).arg(192*i)); + ui->cbxGLResolution->setCurrentIndex(Config::GL_ScaleFactor-1); + + if (Config::_3DRenderer == 0) + { + ui->cbGLDisplay->setEnabled(true); + ui->cbSoftwareThreaded->setEnabled(true); + ui->cbxGLResolution->setEnabled(false); + } + else + { + ui->cbGLDisplay->setEnabled(false); + ui->cbSoftwareThreaded->setEnabled(false); + ui->cbxGLResolution->setEnabled(true); + } } VideoSettingsDialog::~VideoSettingsDialog() @@ -68,7 +81,6 @@ VideoSettingsDialog::~VideoSettingsDialog() void VideoSettingsDialog::on_VideoSettingsDialog_accepted() { - // Config::Save(); closeDlg(); @@ -76,9 +88,64 @@ void VideoSettingsDialog::on_VideoSettingsDialog_accepted() void VideoSettingsDialog::on_VideoSettingsDialog_rejected() { - // + bool old_gl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); + + Config::_3DRenderer = oldRenderer; + Config::ScreenUseGL = oldGLDisplay; + Config::ScreenVSync = oldVSync; + Config::ScreenVSyncInterval = oldVSyncInterval; + Config::Threaded3D = oldSoftThreaded; + Config::GL_ScaleFactor = oldGLScale; + + bool new_gl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); + emit updateVideoSettings(old_gl != new_gl); closeDlg(); } -// +void VideoSettingsDialog::onChange3DRenderer(int renderer) +{ + bool old_gl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); + + Config::_3DRenderer = renderer; + + if (renderer == 0) + { + ui->cbGLDisplay->setEnabled(true); + ui->cbSoftwareThreaded->setEnabled(true); + ui->cbxGLResolution->setEnabled(false); + } + else + { + ui->cbGLDisplay->setEnabled(false); + ui->cbSoftwareThreaded->setEnabled(false); + ui->cbxGLResolution->setEnabled(true); + } + + bool new_gl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); + emit updateVideoSettings(old_gl != new_gl); +} + +void VideoSettingsDialog::on_cbGLDisplay_stateChanged(int state) +{ + bool old_gl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); + + Config::ScreenUseGL = (state != 0); + + bool new_gl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); + emit updateVideoSettings(old_gl != new_gl); +} + +void VideoSettingsDialog::on_cbSoftwareThreaded_stateChanged(int state) +{ + Config::Threaded3D = (state != 0); + + emit updateVideoSettings(false); +} + +void VideoSettingsDialog::on_cbxGLResolution_currentIndexChanged(int idx) +{ + Config::GL_ScaleFactor = idx+1; + + emit updateVideoSettings(false); +} diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.h b/src/frontend/qt_sdl/VideoSettingsDialog.h index 05dfecb..2f6d17c 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.h +++ b/src/frontend/qt_sdl/VideoSettingsDialog.h @@ -51,11 +51,18 @@ public: currentDlg = nullptr; } +signals: + void updateVideoSettings(bool glchange); + private slots: void on_VideoSettingsDialog_accepted(); void on_VideoSettingsDialog_rejected(); - // + void onChange3DRenderer(int renderer); + void on_cbGLDisplay_stateChanged(int state); + void on_cbxGLResolution_currentIndexChanged(int idx); + + void on_cbSoftwareThreaded_stateChanged(int state); private: Ui::VideoSettingsDialog* ui; diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.ui b/src/frontend/qt_sdl/VideoSettingsDialog.ui index 06670e5..6cdd5d8 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.ui +++ b/src/frontend/qt_sdl/VideoSettingsDialog.ui @@ -10,10 +10,19 @@ 237 + + + 0 + 0 + + Video settings - melonDS + + QLayout::SetFixedSize + diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index ae4bcf3..658ae8b 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -68,6 +68,10 @@ EmuThread* emuThread; int autoScreenSizing = 0; +int videoRenderer; +GPU::RenderSettings videoSettings; +bool videoSettingsDirty; + SDL_AudioDeviceID audioDevice; int audioFreq; SDL_cond* audioSync; @@ -251,9 +255,7 @@ EmuThread::EmuThread(QObject* parent) : QThread(parent) EmuRunning = 2; RunningSomething = false; - //connect(this, SIGNAL(windowUpdate()), mainWindow, SLOT(update())); connect(this, SIGNAL(windowUpdate()), mainWindow->panel, SLOT(update())); - //connect(this, SIGNAL(windowUpdate()), mainWindow, SLOT(repaint())); connect(this, SIGNAL(windowTitleChange(QString)), mainWindow, SLOT(onTitleUpdate(QString))); connect(this, SIGNAL(windowEmuStart()), mainWindow, SLOT(onEmuStart())); connect(this, SIGNAL(windowEmuStop()), mainWindow, SLOT(onEmuStop())); @@ -312,6 +314,7 @@ void* EmuThread::oglGetProcAddress(const char* proc) void EmuThread::run() { + bool hasOGL = mainWindow->hasOGL; u32 mainScreenPos[3]; NDS::Init(); @@ -321,20 +324,20 @@ void EmuThread::run() mainScreenPos[2] = 0; autoScreenSizing = 0; - /*if (Screen_UseGL) - { - uiGLMakeContextCurrent(GLContext); - GPU3D::InitRenderer(true); - uiGLMakeContextCurrent(NULL); - } - else*/ + videoSettingsDirty = false; + videoSettings.Soft_Threaded = Config::Threaded3D != 0; + videoSettings.GL_ScaleFactor = Config::GL_ScaleFactor; + + if (hasOGL) { - //GPU3D::InitRenderer(false); - bool res = oglContext->makeCurrent(oglSurface); - printf("good? %d\n", res); - OpenGL::Init(); - GPU3D::InitRenderer(res); + oglContext->makeCurrent(oglSurface); + videoRenderer = OpenGL::Init() ? Config::_3DRenderer : 0; } + else + videoRenderer = 0; + + GPU::InitRenderer(videoRenderer); + GPU::SetRenderSettings(videoRenderer, videoSettings); Input::Init(); @@ -377,6 +380,29 @@ void EmuThread::run() { EmuStatus = 1; + // update render settings if needed + if (videoSettingsDirty) + { + if (hasOGL != mainWindow->hasOGL) + { + hasOGL = mainWindow->hasOGL; + if (hasOGL) + { + oglContext->makeCurrent(oglSurface); + videoRenderer = OpenGL::Init() ? Config::_3DRenderer : 0; + } + else + videoRenderer = 0; + } + else + videoRenderer = hasOGL ? Config::_3DRenderer : 0; + + videoSettingsDirty = false; + videoSettings.Soft_Threaded = Config::Threaded3D != 0; + videoSettings.GL_ScaleFactor = Config::GL_ScaleFactor; + GPU::SetRenderSettings(videoRenderer, videoSettings); + } + // process input and hotkeys NDS::SetKeyMask(Input::InputMask); @@ -390,12 +416,6 @@ void EmuThread::run() // microphone input micProcess(); - /*if (Screen_UseGL) - { - uiGLBegin(GLContext); - uiGLMakeContextCurrent(GLContext); - }*/ - // auto screen layout if (Config::ScreenSizing == 3) { @@ -435,12 +455,6 @@ void EmuThread::run() if (EmuRunning == 0) break; - /*if (Screen_UseGL) - { - GLScreen_DrawScreen(); - uiGLEnd(GLContext); - } - uiAreaQueueRedrawAll(MainDrawArea);*/ emit windowUpdate(); bool fastforward = Input::HotkeyDown(HK_FastForward); @@ -513,18 +527,8 @@ void EmuThread::run() lastmeasuretick = lasttick; fpslimitcount = 0; - /*if (Screen_UseGL) - { - uiGLBegin(GLContext); - uiGLMakeContextCurrent(GLContext); - GLScreen_DrawScreen(); - uiGLEnd(GLContext); - } - uiAreaQueueRedrawAll(MainDrawArea);*/ emit windowUpdate(); - //if (Screen_UseGL) uiGLMakeContextCurrent(NULL); - EmuStatus = EmuRunning; sprintf(melontitle, "melonDS " MELONDS_VERSION); @@ -536,8 +540,7 @@ void EmuThread::run() EmuStatus = 0; - //if (Screen_UseGL) uiGLMakeContextCurrent(GLContext); - + GPU::DeInitRenderer(); NDS::DeInit(); //Platform::LAN_DeInit(); @@ -549,7 +552,8 @@ void EmuThread::run() else OSD::DeInit(false);*/ - //if (Screen_UseGL) uiGLMakeContextCurrent(NULL); + if (hasOGL) + oglContext->doneCurrent(); } void EmuThread::changeWindowTitle(char* title) @@ -794,6 +798,7 @@ ScreenPanelGL::ScreenPanelGL(QWidget* parent) : QOpenGLWidget(parent) ScreenPanelGL::~ScreenPanelGL() { // CHECKME!!!! + // ALSO TODO: CLEANUP delete screenShader; } @@ -888,7 +893,7 @@ void ScreenPanelGL::paintGL() int frontbuf = GPU::FrontBuffer; glActiveTexture(GL_TEXTURE0); - if (true) + if (GPU::Renderer != 0) { // hardware-accelerated render GPU::GLCompositor::BindOutputTexture(); @@ -1162,11 +1167,8 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) } setMenuBar(menubar); - //panel = new ScreenPanelNative(this); - panel = new ScreenPanelGL(this); - setCentralWidget(panel); - connect(this, SIGNAL(screenLayoutChange()), panel, SLOT(onScreenLayoutChanged())); - emit screenLayoutChange(); + show(); + createScreenPanel(); resize(Config::WindowWidth, Config::WindowHeight); @@ -1210,9 +1212,45 @@ MainWindow::~MainWindow() { } +void MainWindow::createScreenPanel() +{ + hasOGL = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0); + + if (hasOGL) + { + ScreenPanelGL* panelGL = new ScreenPanelGL(this); + panelGL->show(); + + if (!panelGL->isValid()) + hasOGL = false; + else + { + QSurfaceFormat fmt = panelGL->format(); + if (fmt.majorVersion() < 3 || (fmt.majorVersion() == 3 && fmt.minorVersion() < 2)) + hasOGL = false; + } + + if (!hasOGL) + delete panelGL; + else + panel = panelGL; + } + + if (!hasOGL) + { + panel = new ScreenPanelNative(this); + panel->show(); + } + + setCentralWidget(panel); + connect(this, SIGNAL(screenLayoutChange()), panel, SLOT(onScreenLayoutChanged())); + emit screenLayoutChange(); +} + QOpenGLContext* MainWindow::getOGLContext() { - // TODO: check whether we can actually pull this! + if (!hasOGL) return nullptr; + QOpenGLWidget* glpanel = (QOpenGLWidget*)panel; return glpanel->context(); } @@ -1575,6 +1613,7 @@ void MainWindow::onInputConfigFinished(int res) void MainWindow::onOpenVideoSettings() { VideoSettingsDialog* dlg = VideoSettingsDialog::openDlg(this); + connect(dlg, &VideoSettingsDialog::updateVideoSettings, this, &MainWindow::onUpdateVideoSettings); } void MainWindow::onOpenAudioSettings() @@ -1745,6 +1784,23 @@ void MainWindow::onEmuStop() actStop->setEnabled(false); } +void MainWindow::onUpdateVideoSettings(bool glchange) +{ + if (glchange) + { + emuThread->emuPause(); + + delete panel; + createScreenPanel(); + connect(emuThread, SIGNAL(windowUpdate()), panel, SLOT(update())); + } + + videoSettingsDirty = true; + + if (glchange) + emuThread->emuUnpause(); +} + void emuStop() { @@ -1790,6 +1846,9 @@ int main(int argc, char** argv) Config::Load(); #define SANITIZE(var, min, max) { if (var < min) var = min; else if (var > max) var = max; } + SANITIZE(Config::_3DRenderer, 0, 1); + SANITIZE(Config::ScreenVSyncInterval, 1, 20); + SANITIZE(Config::GL_ScaleFactor, 1, 16); SANITIZE(Config::AudioVolume, 0, 256); SANITIZE(Config::MicInputType, 0, 3); SANITIZE(Config::ScreenRotation, 0, 3); @@ -1900,7 +1959,6 @@ int main(int argc, char** argv) Input::OpenJoystick(); mainWindow = new MainWindow(); - mainWindow->show(); emuThread = new EmuThread(); emuThread->start(); diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 8759e95..ef51158 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -171,6 +171,7 @@ public: explicit MainWindow(QWidget* parent = nullptr); ~MainWindow(); + bool hasOGL; QOpenGLContext* getOGLContext(); protected: @@ -221,7 +222,11 @@ private slots: void onEmuStart(); void onEmuStop(); + void onUpdateVideoSettings(bool glchange); + private: + void createScreenPanel(); + QString loadErrorStr(int error); public: -- cgit v1.2.3 From f7e53c6f71c3bf6f082d1e5857f474f79f992602 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 28 May 2020 15:58:18 +0200 Subject: so you can't resize() before show()ing?? bullshit. --- src/frontend/qt_sdl/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 658ae8b..b6282fe 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -1167,11 +1167,11 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) } setMenuBar(menubar); + resize(Config::WindowWidth, Config::WindowHeight); + show(); createScreenPanel(); - resize(Config::WindowWidth, Config::WindowHeight); - for (int i = 0; i < 9; i++) { actSaveState[i]->setEnabled(false); -- cgit v1.2.3 From d25dc40e70e9a1c25966db8e16a5efd5284fd336 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 28 May 2020 16:04:22 +0200 Subject: make it a bit better --- src/frontend/qt_sdl/VideoSettingsDialog.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp index 09f1ab4..9645a3d 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.cpp +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -59,7 +59,7 @@ VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui( for (int i = 1; i <= 16; i++) ui->cbxGLResolution->addItem(QString("%1x native (%2x%3)").arg(i).arg(256*i).arg(192*i)); ui->cbxGLResolution->setCurrentIndex(Config::GL_ScaleFactor-1); - +printf("GL scale = %d\n", Config::GL_ScaleFactor); if (Config::_3DRenderer == 0) { ui->cbGLDisplay->setEnabled(true); @@ -145,6 +145,9 @@ void VideoSettingsDialog::on_cbSoftwareThreaded_stateChanged(int state) void VideoSettingsDialog::on_cbxGLResolution_currentIndexChanged(int idx) { + // prevent a spurious change + if (ui->cbxGLResolution->count() < 16) return; + Config::GL_ScaleFactor = idx+1; emit updateVideoSettings(false); -- cgit v1.2.3 From d1d572210fdcef0932aaa2f0c6df71f6f2161c75 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 28 May 2020 16:07:34 +0200 Subject: fix that bug here too --- src/frontend/qt_sdl/InputConfigDialog.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/frontend/qt_sdl/InputConfigDialog.cpp b/src/frontend/qt_sdl/InputConfigDialog.cpp index 2c0afc4..81baa65 100644 --- a/src/frontend/qt_sdl/InputConfigDialog.cpp +++ b/src/frontend/qt_sdl/InputConfigDialog.cpp @@ -199,6 +199,9 @@ void InputConfigDialog::on_InputConfigDialog_rejected() void InputConfigDialog::on_cbxJoystick_currentIndexChanged(int id) { + // prevent a spurious change + if (ui->cbxJoystick->count() < 2) return; + Input::JoystickID = id; Input::OpenJoystick(); } -- cgit v1.2.3 From 2912a07b8babb602aaf315e62667044a07adf8e7 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 28 May 2020 17:00:25 +0200 Subject: fix bugs, clean up some of the shit --- src/GPU.cpp | 8 ++++---- src/frontend/qt_sdl/VideoSettingsDialog.cpp | 2 +- src/frontend/qt_sdl/main.cpp | 14 +++++++++++--- 3 files changed, 16 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/GPU.cpp b/src/GPU.cpp index 56db0e2..60f863e 100644 --- a/src/GPU.cpp +++ b/src/GPU.cpp @@ -339,10 +339,10 @@ void SetRenderSettings(int renderer, RenderSettings& settings) int fbsize; if (accel) fbsize = (256*3 + 1) * 192; else fbsize = 256 * 192; - if (Framebuffer[0][0]) delete[] Framebuffer[0][0]; - if (Framebuffer[1][0]) delete[] Framebuffer[1][0]; - if (Framebuffer[0][1]) delete[] Framebuffer[0][1]; - if (Framebuffer[1][1]) delete[] Framebuffer[1][1]; + if (Framebuffer[0][0]) { delete[] Framebuffer[0][0]; Framebuffer[0][0] = nullptr; } + if (Framebuffer[1][0]) { delete[] Framebuffer[1][0]; Framebuffer[1][0] = nullptr; } + if (Framebuffer[0][1]) { delete[] Framebuffer[0][1]; Framebuffer[0][1] = nullptr; } + if (Framebuffer[1][1]) { delete[] Framebuffer[1][1]; Framebuffer[1][1] = nullptr; } Framebuffer[0][0] = new u32[fbsize]; Framebuffer[1][0] = new u32[fbsize]; diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp index 9645a3d..efb5051 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.cpp +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -59,7 +59,7 @@ VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui( for (int i = 1; i <= 16; i++) ui->cbxGLResolution->addItem(QString("%1x native (%2x%3)").arg(i).arg(256*i).arg(192*i)); ui->cbxGLResolution->setCurrentIndex(Config::GL_ScaleFactor-1); -printf("GL scale = %d\n", Config::GL_ScaleFactor); + if (Config::_3DRenderer == 0) { ui->cbGLDisplay->setEnabled(true); diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index b6282fe..de71da9 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -282,7 +282,7 @@ void EmuThread::initOpenGL() return; } - oglContext = new QOpenGLContext();//oglSurface); + oglContext = new QOpenGLContext(); oglContext->setFormat(oglSurface->format()); oglContext->setShareContext(windowctx); if (!oglContext->create()) @@ -797,9 +797,16 @@ ScreenPanelGL::ScreenPanelGL(QWidget* parent) : QOpenGLWidget(parent) ScreenPanelGL::~ScreenPanelGL() { - // CHECKME!!!! - // ALSO TODO: CLEANUP + makeCurrent(); + + glDeleteTextures(1, &screenTexture); + + glDeleteVertexArrays(1, &screenVertexArray); + glDeleteBuffers(1, &screenVertexBuffer); + delete screenShader; + + doneCurrent(); } void ScreenPanelGL::setupScreenLayout() @@ -1793,6 +1800,7 @@ void MainWindow::onUpdateVideoSettings(bool glchange) delete panel; createScreenPanel(); connect(emuThread, SIGNAL(windowUpdate()), panel, SLOT(update())); + if (hasOGL) emuThread->initOpenGL(); } videoSettingsDirty = true; -- cgit v1.2.3 From 79d4183ccdac6d0b2a82f99ad169b7fe6349febc Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 28 May 2020 18:11:41 +0200 Subject: re-add OSD system --- src/frontend/qt_sdl/CMakeLists.txt | 3 + src/frontend/qt_sdl/OSD.cpp | 474 +++++++++++++++++++++++++++++++++++++ src/frontend/qt_sdl/OSD.h | 36 +++ src/frontend/qt_sdl/OSD_shaders.h | 65 +++++ src/frontend/qt_sdl/font.h | 135 +++++++++++ src/frontend/qt_sdl/main.cpp | 18 +- src/frontend/qt_sdl/main_shaders.h | 50 ---- 7 files changed, 730 insertions(+), 51 deletions(-) create mode 100644 src/frontend/qt_sdl/OSD.cpp create mode 100644 src/frontend/qt_sdl/OSD.h create mode 100644 src/frontend/qt_sdl/OSD_shaders.h create mode 100644 src/frontend/qt_sdl/font.h (limited to 'src') diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index a4bb5f5..0b7fa54 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -8,6 +8,9 @@ SET(SOURCES_QT_SDL VideoSettingsDialog.cpp AudioSettingsDialog.cpp Input.cpp + OSD.cpp + OSD_shaders.h + font.h Platform.cpp PlatformConfig.cpp diff --git a/src/frontend/qt_sdl/OSD.cpp b/src/frontend/qt_sdl/OSD.cpp new file mode 100644 index 0000000..4e4e40f --- /dev/null +++ b/src/frontend/qt_sdl/OSD.cpp @@ -0,0 +1,474 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include +#include +#include +#include +#include "../types.h" + +#include "main.h" +#include + +#include "OSD.h" +#include "OSD_shaders.h" +#include "font.h" + +#include "PlatformConfig.h" + +extern MainWindow* mainWindow; + +namespace OSD +{ + +const u32 kOSDMargin = 6; + +struct Item +{ + Uint32 Timestamp; + char Text[256]; + u32 Color; + + u32 Width, Height; + u32* Bitmap; + + bool NativeBitmapLoaded; + QImage NativeBitmap; + + bool GLTextureLoaded; + GLuint GLTexture; + +}; + +std::deque ItemQueue; + +QOpenGLShaderProgram* Shader; +GLint uScreenSize, uOSDPos, uOSDSize; +GLuint OSDVertexArray; +GLuint OSDVertexBuffer; + +volatile bool Rendering; + + +bool Init(QOpenGLFunctions_3_2_Core* f) +{ + if (f) + { + Shader = new QOpenGLShaderProgram(); + Shader->addShaderFromSourceCode(QOpenGLShader::Vertex, kScreenVS_OSD); + Shader->addShaderFromSourceCode(QOpenGLShader::Fragment, kScreenFS_OSD); + + GLuint pid = Shader->programId(); + f->glBindAttribLocation(pid, 0, "vPosition"); + f->glBindFragDataLocation(pid, 0, "oColor"); + + Shader->link(); + + Shader->bind(); + Shader->setUniformValue("OSDTex", (GLint)0); + Shader->release(); + + uScreenSize = Shader->uniformLocation("uScreenSize"); + uOSDPos = Shader->uniformLocation("uOSDPos"); + uOSDSize = Shader->uniformLocation("uOSDSize"); + + float vertices[6*2] = + { + 0, 0, + 1, 1, + 1, 0, + 0, 0, + 0, 1, + 1, 1 + }; + + f->glGenBuffers(1, &OSDVertexBuffer); + f->glBindBuffer(GL_ARRAY_BUFFER, OSDVertexBuffer); + f->glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); + + f->glGenVertexArrays(1, &OSDVertexArray); + f->glBindVertexArray(OSDVertexArray); + f->glEnableVertexAttribArray(0); // position + f->glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (void*)(0)); + } + + return true; +} + +void DeInit(QOpenGLFunctions_3_2_Core* f) +{ + for (auto it = ItemQueue.begin(); it != ItemQueue.end(); ) + { + Item& item = *it; + + if (item.GLTextureLoaded && f) f->glDeleteTextures(1, &item.GLTexture); + if (item.Bitmap) delete[] item.Bitmap; + + it = ItemQueue.erase(it); + } + + if (f) delete Shader; +} + + +int FindBreakPoint(const char* text, int i) +{ + // i = character that went out of bounds + + for (int j = i; j >= 0; j--) + { + if (text[j] == ' ') + return j; + } + + return i; +} + +void LayoutText(const char* text, u32* width, u32* height, int* breaks) +{ + u32 w = 0; + u32 h = 14; + u32 totalw = 0; + u32 maxw = mainWindow->panel->width() - (kOSDMargin*2); + int lastbreak = -1; + int numbrk = 0; + u16* ptr; + + memset(breaks, 0, sizeof(int)*64); + + for (int i = 0; text[i] != '\0'; ) + { + int glyphsize; + if (text[i] == ' ') + { + glyphsize = 6; + } + else + { + u32 ch = text[i]; + if (ch < 0x10 || ch > 0x7E) ch = 0x7F; + + ptr = &font[(ch-0x10) << 4]; + glyphsize = ptr[0]; + if (!glyphsize) glyphsize = 6; + else glyphsize += 2; // space around the character + } + + w += glyphsize; + if (w > maxw) + { + // wrap shit as needed + if (text[i] == ' ') + { + if (numbrk >= 64) break; + breaks[numbrk++] = i; + i++; + } + else + { + int brk = FindBreakPoint(text, i); + if (brk != lastbreak) i = brk; + + if (numbrk >= 64) break; + breaks[numbrk++] = i; + + lastbreak = brk; + } + + w = 0; + h += 14; + } + else + i++; + + if (w > totalw) totalw = w; + } + + *width = totalw; + *height = h; +} + +u32 RainbowColor(u32 inc) +{ + // inspired from Acmlmboard + + if (inc < 100) return 0xFFFF9B9B + (inc << 8); + else if (inc < 200) return 0xFFFFFF9B - ((inc-100) << 16); + else if (inc < 300) return 0xFF9BFF9B + (inc-200); + else if (inc < 400) return 0xFF9BFFFF - ((inc-300) << 8); + else if (inc < 500) return 0xFF9B9BFF + ((inc-400) << 16); + else return 0xFFFF9BFF - (inc-500); +} + +void RenderText(u32 color, const char* text, Item* item) +{ + u32 w, h; + int breaks[64]; + + bool rainbow = (color == 0); + u32 rainbowinc = ((text[0] * 17) + (SDL_GetTicks() * 13)) % 600; + + color |= 0xFF000000; + const u32 shadow = 0xE0000000; + + LayoutText(text, &w, &h, breaks); + + item->Width = w; + item->Height = h; + item->Bitmap = new u32[w*h]; + memset(item->Bitmap, 0, w*h*sizeof(u32)); + + u32 x = 0, y = 1; + u32 maxw = mainWindow->panel->width() - (kOSDMargin*2); + int curline = 0; + u16* ptr; + + for (int i = 0; text[i] != '\0'; ) + { + int glyphsize; + if (text[i] == ' ') + { + x += 6; + } + else + { + u32 ch = text[i]; + if (ch < 0x10 || ch > 0x7E) ch = 0x7F; + + ptr = &font[(ch-0x10) << 4]; + int glyphsize = ptr[0]; + if (!glyphsize) x += 6; + else + { + x++; + + if (rainbow) + { + color = RainbowColor(rainbowinc); + rainbowinc = (rainbowinc + 30) % 600; + } + + // draw character + for (int cy = 0; cy < 12; cy++) + { + u16 val = ptr[4+cy]; + + for (int cx = 0; cx < glyphsize; cx++) + { + if (val & (1<Bitmap[((y+cy) * w) + x+cx] = color; + } + } + + x += glyphsize; + x++; + } + } + + i++; + if (breaks[curline] && i >= breaks[curline]) + { + i = breaks[curline++]; + if (text[i] == ' ') i++; + + x = 0; + y += 14; + } + } + + // shadow + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + u32 val; + + val = item->Bitmap[(y * w) + x]; + if ((val >> 24) == 0xFF) continue; + + if (x > 0) val = item->Bitmap[(y * w) + x-1]; + if (x < w-1) val |= item->Bitmap[(y * w) + x+1]; + if (y > 0) + { + if (x > 0) val |= item->Bitmap[((y-1) * w) + x-1]; + val |= item->Bitmap[((y-1) * w) + x]; + if (x < w-1) val |= item->Bitmap[((y-1) * w) + x+1]; + } + if (y < h-1) + { + if (x > 0) val |= item->Bitmap[((y+1) * w) + x-1]; + val |= item->Bitmap[((y+1) * w) + x]; + if (x < w-1) val |= item->Bitmap[((y+1) * w) + x+1]; + } + + if ((val >> 24) == 0xFF) + item->Bitmap[(y * w) + x] = shadow; + } + } +} + + +void AddMessage(u32 color, const char* text) +{ + if (!Config::ShowOSD) return; + + while (Rendering); + + Item item; + + item.Timestamp = SDL_GetTicks(); + strncpy(item.Text, text, 255); item.Text[255] = '\0'; + item.Color = color; + item.Bitmap = nullptr; + + item.NativeBitmapLoaded = false; + item.GLTextureLoaded = false; + + ItemQueue.push_back(item); +} + +void Update(QOpenGLFunctions_3_2_Core* f) +{ + if (!Config::ShowOSD) + { + Rendering = true; + for (auto it = ItemQueue.begin(); it != ItemQueue.end(); ) + { + Item& item = *it; + + if (item.GLTextureLoaded && f) f->glDeleteTextures(1, &item.GLTexture); + if (item.Bitmap) delete[] item.Bitmap; + + it = ItemQueue.erase(it); + } + Rendering = false; + return; + } + + Rendering = true; + + Uint32 tick_now = SDL_GetTicks(); + Uint32 tick_min = tick_now - 2500; + + for (auto it = ItemQueue.begin(); it != ItemQueue.end(); ) + { + Item& item = *it; + + if (item.Timestamp < tick_min) + { + if (item.GLTextureLoaded) f->glDeleteTextures(1, &item.GLTexture); + if (item.Bitmap) delete[] item.Bitmap; + + it = ItemQueue.erase(it); + continue; + } + + if (!item.Bitmap) + { + RenderText(item.Color, item.Text, &item); + } + + it++; + } + + Rendering = false; +} + +void DrawNative(QPainter& painter) +{ + if (!Config::ShowOSD) return; + + Rendering = true; + + u32 y = kOSDMargin; + + painter.resetTransform(); + + for (auto it = ItemQueue.begin(); it != ItemQueue.end(); ) + { + Item& item = *it; + + if (!item.NativeBitmapLoaded) + { + item.NativeBitmap = QImage((const uchar*)item.Bitmap, item.Width, item.Height, QImage::Format_ARGB32_Premultiplied); + item.NativeBitmapLoaded = true; + } + + painter.drawImage(kOSDMargin, y, item.NativeBitmap); + + y += item.Height; + it++; + } + + Rendering = false; +} + +void DrawGL(QOpenGLFunctions_3_2_Core* f, float w, float h) +{ + if (!Config::ShowOSD) return; + if (!mainWindow || !mainWindow->panel) return; + + Rendering = true; + + u32 y = kOSDMargin; + + Shader->bind(); + + f->glUniform2f(uScreenSize, w, h); + + f->glBindBuffer(GL_ARRAY_BUFFER, OSDVertexBuffer); + f->glBindVertexArray(OSDVertexArray); + + f->glActiveTexture(GL_TEXTURE0); + + f->glEnable(GL_BLEND); + f->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + + for (auto it = ItemQueue.begin(); it != ItemQueue.end(); ) + { + Item& item = *it; + + if (!item.GLTextureLoaded) + { + f->glGenTextures(1, &item.GLTexture); + f->glBindTexture(GL_TEXTURE_2D, item.GLTexture); + f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + f->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, item.Width, item.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, item.Bitmap); + + item.GLTextureLoaded = true; + } + + f->glBindTexture(GL_TEXTURE_2D, item.GLTexture); + f->glUniform2i(uOSDPos, kOSDMargin, y); + f->glUniform2i(uOSDSize, item.Width, item.Height); + f->glDrawArrays(GL_TRIANGLES, 0, 2*3); + + y += item.Height; + it++; + } + + f->glDisable(GL_BLEND); + Shader->release(); + + Rendering = false; +} + +} diff --git a/src/frontend/qt_sdl/OSD.h b/src/frontend/qt_sdl/OSD.h new file mode 100644 index 0000000..79d9df0 --- /dev/null +++ b/src/frontend/qt_sdl/OSD.h @@ -0,0 +1,36 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef OSD_H +#define OSD_H + +namespace OSD +{ + +bool Init(QOpenGLFunctions_3_2_Core* f); +void DeInit(QOpenGLFunctions_3_2_Core* f); + +void AddMessage(u32 color, const char* text); + +void Update(QOpenGLFunctions_3_2_Core* f); +void DrawNative(QPainter& painter); +void DrawGL(QOpenGLFunctions_3_2_Core* f, float w, float h); + +} + +#endif // OSD_H diff --git a/src/frontend/qt_sdl/OSD_shaders.h b/src/frontend/qt_sdl/OSD_shaders.h new file mode 100644 index 0000000..5a64f66 --- /dev/null +++ b/src/frontend/qt_sdl/OSD_shaders.h @@ -0,0 +1,65 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef OSD_SHADERS_H +#define OSD_SHADERS_H + +const char* kScreenVS_OSD = R"(#version 140 + +uniform vec2 uScreenSize; + +uniform ivec2 uOSDPos; +uniform ivec2 uOSDSize; + +in vec2 vPosition; + +smooth out vec2 fTexcoord; + +void main() +{ + vec4 fpos; + + vec2 osdpos = (vPosition * vec2(uOSDSize)); + fTexcoord = osdpos; + osdpos += uOSDPos; + + fpos.xy = ((osdpos * 2.0) / uScreenSize) - 1.0; + fpos.y *= -1; + fpos.z = 0.0; + fpos.w = 1.0; + + gl_Position = fpos; +} +)"; + +const char* kScreenFS_OSD = R"(#version 140 + +uniform sampler2D OSDTex; + +smooth in vec2 fTexcoord; + +out vec4 oColor; + +void main() +{ + vec4 pixel = texelFetch(OSDTex, ivec2(fTexcoord), 0); + oColor = pixel.bgra; +} +)"; + +#endif // OSD_SHADERS_H diff --git a/src/frontend/qt_sdl/font.h b/src/frontend/qt_sdl/font.h new file mode 100644 index 0000000..f2e4f87 --- /dev/null +++ b/src/frontend/qt_sdl/font.h @@ -0,0 +1,135 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef FONT_H +#define FONT_H +unsigned short font[] = { + 12, 0, 0, 0,0x0C03, 0x0E07, 0x070E, 0x039C, 0x01F8, 0x00F0, 0x00F0, 0x01F8, 0x039C, 0x070E, 0x0E07, 0x0C03, + 12, 0, 0, 0,0x01C0, 0x00E0, 0x0060, 0x0860, 0x0C60, 0x0FE0, 0x07F0, 0x0038, 0x001C, 0x000E, 0x0007, 0x0003, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 12, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 2, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000, 0x0003, 0x0003, 0x0000, 0x0000, + 9, 0, 0, 0,0x01EF, 0x01EF, 0x018C, 0x01CE, 0x00E7, 0x0063, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 10, 0, 0, 0,0x00CC, 0x00CC, 0x03FF, 0x03FF, 0x00CC, 0x00CC, 0x03FF, 0x03FF, 0x00CC, 0x00CC, 0x0000, 0x0000, + 8, 0, 0, 0,0x0018, 0x00FE, 0x00FF, 0x001B, 0x007F, 0x00FE, 0x00D8, 0x00FF, 0x007F, 0x0018, 0x0000, 0x0000, + 10, 0, 0, 0,0x0306, 0x038F, 0x01CF, 0x00E6, 0x0070, 0x0038, 0x019C, 0x03CE, 0x03C7, 0x0183, 0x0000, 0x0000, + 10, 0, 0, 0,0x007C, 0x00FE, 0x00C6, 0x00EE, 0x007C, 0x037E, 0x03E7, 0x01F3, 0x03BF, 0x031E, 0x0000, 0x0000, + 4, 0, 0, 0,0x000F, 0x000F, 0x000C, 0x000E, 0x0007, 0x0003, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 4, 0, 0, 0,0x000C, 0x000E, 0x0007, 0x0003, 0x0003, 0x0003, 0x0003, 0x0007, 0x000E, 0x000C, 0x0000, 0x0000, + 4, 0, 0, 0,0x0003, 0x0007, 0x000E, 0x000C, 0x000C, 0x000C, 0x000C, 0x000E, 0x0007, 0x0003, 0x0000, 0x0000, + 10, 0, 0, 0,0x0030, 0x0333, 0x03B7, 0x01FE, 0x00FC, 0x00FC, 0x01FE, 0x03B7, 0x0333, 0x0030, 0x0000, 0x0000, + 10, 0, 0, 0,0x0030, 0x0030, 0x0030, 0x0030, 0x03FF, 0x03FF, 0x0030, 0x0030, 0x0030, 0x0030, 0x0000, 0x0000, + 4, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x000F, 0x000F, 0x000C, 0x000E, 0x0007, 0x0003, + 10, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x03FF, 0x03FF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 3, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0007, 0x0007, 0x0007, 0x0000, 0x0000, + 10, 0, 0, 0,0x0300, 0x0380, 0x01C0, 0x00E0, 0x0070, 0x0038, 0x001C, 0x000E, 0x0007, 0x0003, 0x0000, 0x0000, + 8, 0, 0, 0,0x007E, 0x00FF, 0x00C3, 0x00C3, 0x00C3, 0x00C3, 0x00C3, 0x00C3, 0x00FF, 0x007E, 0x0000, 0x0000, + 4, 0, 0, 0,0x0006, 0x0007, 0x0007, 0x0006, 0x0006, 0x0006, 0x0006, 0x0006, 0x000F, 0x000F, 0x0000, 0x0000, + 8, 0, 0, 0,0x007E, 0x00FF, 0x00C3, 0x00C0, 0x00FE, 0x007F, 0x0003, 0x0003, 0x00FF, 0x00FF, 0x0000, 0x0000, + 8, 0, 0, 0,0x007F, 0x00FF, 0x00C0, 0x00C0, 0x007C, 0x00FC, 0x00C0, 0x00C0, 0x00FF, 0x007F, 0x0000, 0x0000, + 8, 0, 0, 0,0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x00FF, 0x00FE, 0x0060, 0x0060, 0x0000, 0x0000, + 8, 0, 0, 0,0x00FF, 0x00FF, 0x0003, 0x0003, 0x007F, 0x00FF, 0x00C0, 0x00C0, 0x00FF, 0x007F, 0x0000, 0x0000, + 8, 0, 0, 0,0x007E, 0x007F, 0x0003, 0x0003, 0x007F, 0x00FF, 0x00C3, 0x00C3, 0x00FF, 0x007E, 0x0000, 0x0000, + 8, 0, 0, 0,0x00FF, 0x00FF, 0x00C0, 0x00E0, 0x0070, 0x0038, 0x001C, 0x000C, 0x000C, 0x000C, 0x0000, 0x0000, + 8, 0, 0, 0,0x007E, 0x00FF, 0x00C3, 0x00C3, 0x007E, 0x00FF, 0x00C3, 0x00C3, 0x00FF, 0x007E, 0x0000, 0x0000, + 8, 0, 0, 0,0x007E, 0x00FF, 0x00C3, 0x00C3, 0x00FF, 0x00FE, 0x00C0, 0x00C0, 0x00FE, 0x007E, 0x0000, 0x0000, + 3, 0, 0, 0,0x0000, 0x0000, 0x0007, 0x0007, 0x0000, 0x0000, 0x0000, 0x0007, 0x0007, 0x0000, 0x0000, 0x0000, + 4, 0, 0, 0,0x0000, 0x0000, 0x000E, 0x000E, 0x0000, 0x0000, 0x000C, 0x000E, 0x0007, 0x0003, 0x0000, 0x0000, + 6, 0, 0, 0,0x0030, 0x0038, 0x001C, 0x000E, 0x0007, 0x0007, 0x000E, 0x001C, 0x0038, 0x0030, 0x0000, 0x0000, + 7, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x007F, 0x007F, 0x0000, 0x0000, 0x007F, 0x007F, 0x0000, 0x0000, 0x0000, + 6, 0, 0, 0,0x0003, 0x0007, 0x000E, 0x001C, 0x0038, 0x0038, 0x001C, 0x000E, 0x0007, 0x0003, 0x0000, 0x0000, + 8, 0, 0, 0,0x007E, 0x00FF, 0x00C3, 0x00C3, 0x00F0, 0x0078, 0x0018, 0x0000, 0x0018, 0x0018, 0x0000, 0x0000, + 10, 0, 0, 0,0x00FC, 0x01FE, 0x0387, 0x0333, 0x037B, 0x03FB, 0x01F3, 0x0007, 0x03FE, 0x03FC, 0x0000, 0x0000, + 9, 0, 0, 0,0x00FE, 0x01FF, 0x0183, 0x0183, 0x0183, 0x01FF, 0x01FF, 0x0183, 0x0183, 0x0183, 0x0000, 0x0000, + 9, 0, 0, 0,0x00FF, 0x01FF, 0x0183, 0x0183, 0x00FF, 0x01FF, 0x0183, 0x0183, 0x01FF, 0x00FF, 0x0000, 0x0000, + 8, 0, 0, 0,0x00FE, 0x00FF, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x00FF, 0x00FE, 0x0000, 0x0000, + 9, 0, 0, 0,0x007F, 0x00FF, 0x01C3, 0x0183, 0x0183, 0x0183, 0x0183, 0x01C3, 0x00FF, 0x007F, 0x0000, 0x0000, + 9, 0, 0, 0,0x01FF, 0x01FF, 0x0003, 0x0003, 0x00FF, 0x00FF, 0x0003, 0x0003, 0x01FF, 0x01FF, 0x0000, 0x0000, + 9, 0, 0, 0,0x01FF, 0x01FF, 0x0003, 0x0003, 0x00FF, 0x00FF, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000, + 9, 0, 0, 0,0x01FE, 0x01FF, 0x0003, 0x0003, 0x01F3, 0x01F3, 0x0183, 0x0183, 0x01FF, 0x00FE, 0x0000, 0x0000, + 9, 0, 0, 0,0x0183, 0x0183, 0x0183, 0x0183, 0x01FF, 0x01FF, 0x0183, 0x0183, 0x0183, 0x0183, 0x0000, 0x0000, + 6, 0, 0, 0,0x003F, 0x003F, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x003F, 0x003F, 0x0000, 0x0000, + 9, 0, 0, 0,0x01F0, 0x01F0, 0x00C0, 0x00C0, 0x00C0, 0x00C0, 0x00C3, 0x00C3, 0x00FF, 0x007E, 0x0000, 0x0000, + 9, 0, 0, 0,0x0183, 0x01C3, 0x00E3, 0x0073, 0x003F, 0x003F, 0x0073, 0x00E3, 0x01C3, 0x0183, 0x0000, 0x0000, + 7, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x007F, 0x007F, 0x0000, 0x0000, + 10, 0, 0, 0,0x0303, 0x0387, 0x03CF, 0x03FF, 0x037B, 0x0333, 0x0303, 0x0303, 0x0303, 0x0303, 0x0000, 0x0000, + 10, 0, 0, 0,0x0303, 0x0307, 0x030F, 0x031F, 0x033B, 0x0373, 0x03E3, 0x03C3, 0x0383, 0x0303, 0x0000, 0x0000, + 10, 0, 0, 0,0x01FE, 0x03FF, 0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x03FF, 0x01FE, 0x0000, 0x0000, + 9, 0, 0, 0,0x00FF, 0x01FF, 0x0183, 0x0183, 0x01FF, 0x00FF, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000, + 10, 0, 0, 0,0x01FE, 0x03FF, 0x0303, 0x0303, 0x0333, 0x0373, 0x03E3, 0x01C3, 0x03FF, 0x037E, 0x0000, 0x0000, + 9, 0, 0, 0,0x00FF, 0x01FF, 0x0183, 0x0183, 0x01FF, 0x00FF, 0x0073, 0x00E3, 0x01C3, 0x0183, 0x0000, 0x0000, + 10, 0, 0, 0,0x01FE, 0x01FF, 0x0003, 0x0003, 0x01FF, 0x03FE, 0x0300, 0x0300, 0x03FE, 0x01FE, 0x0000, 0x0000, + 10, 0, 0, 0,0x03FF, 0x03FF, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0000, 0x0000, + 9, 0, 0, 0,0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x0183, 0x01FF, 0x00FE, 0x0000, 0x0000, + 10, 0, 0, 0,0x0303, 0x0303, 0x0303, 0x0303, 0x0303, 0x0387, 0x01CE, 0x00FC, 0x0078, 0x0030, 0x0000, 0x0000, + 10, 0, 0, 0,0x0303, 0x0303, 0x0303, 0x0303, 0x0333, 0x037B, 0x03FF, 0x03CF, 0x0387, 0x0303, 0x0000, 0x0000, + 10, 0, 0, 0,0x0303, 0x0387, 0x01CE, 0x00FC, 0x0078, 0x0078, 0x00FC, 0x01CE, 0x0387, 0x0303, 0x0000, 0x0000, + 10, 0, 0, 0,0x0303, 0x0387, 0x01CE, 0x00FC, 0x0078, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0000, 0x0000, + 10, 0, 0, 0,0x03FF, 0x03FF, 0x01C0, 0x00E0, 0x0070, 0x0038, 0x001C, 0x000E, 0x03FF, 0x03FF, 0x0000, 0x0000, + 4, 0, 0, 0,0x000F, 0x000F, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x000F, 0x000F, 0x0000, 0x0000, + 10, 0, 0, 0,0x0003, 0x0007, 0x000E, 0x001C, 0x0038, 0x0070, 0x00E0, 0x01C0, 0x0380, 0x0300, 0x0000, 0x0000, + 4, 0, 0, 0,0x000F, 0x000F, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x000C, 0x000F, 0x000F, 0x0000, 0x0000, + 8, 0, 0, 0,0x0018, 0x003C, 0x007E, 0x00E7, 0x00C3, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 10, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03FF, 0x03FF, + 4, 0, 0, 0,0x000F, 0x000F, 0x0003, 0x0007, 0x000E, 0x000C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 7, 0, 0, 0,0x0000, 0x0000, 0x003E, 0x007E, 0x0060, 0x007E, 0x007F, 0x0063, 0x007F, 0x007E, 0x0000, 0x0000, + 7, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x003F, 0x007F, 0x0063, 0x0063, 0x0063, 0x007F, 0x003F, 0x0000, 0x0000, + 7, 0, 0, 0,0x0000, 0x0000, 0x007E, 0x007F, 0x0003, 0x0003, 0x0003, 0x0003, 0x007F, 0x007E, 0x0000, 0x0000, + 7, 0, 0, 0,0x0060, 0x0060, 0x0060, 0x007E, 0x007F, 0x0063, 0x0063, 0x0063, 0x007F, 0x007E, 0x0000, 0x0000, + 7, 0, 0, 0,0x0000, 0x0000, 0x003E, 0x007F, 0x0063, 0x007F, 0x003F, 0x0003, 0x003F, 0x003E, 0x0000, 0x0000, + 6, 0, 0, 0,0x003C, 0x003E, 0x0006, 0x0006, 0x001F, 0x001F, 0x0006, 0x0006, 0x0006, 0x0006, 0x0000, 0x0000, + 7, 0, 0, 0,0x0000, 0x0000, 0x007E, 0x007F, 0x0063, 0x0063, 0x007F, 0x007E, 0x0060, 0x0060, 0x007E, 0x003E, + 7, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x003F, 0x007F, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x0000, 0x0000, + 2, 0, 0, 0,0x0003, 0x0003, 0x0000, 0x0000, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000, + 7, 0, 0, 0,0x0060, 0x0060, 0x0000, 0x0000, 0x0060, 0x0060, 0x0060, 0x0060, 0x0060, 0x0063, 0x007F, 0x003E, + 8, 0, 0, 0,0x0003, 0x0003, 0x00E3, 0x0073, 0x003B, 0x001F, 0x001F, 0x003B, 0x0073, 0x00E3, 0x0000, 0x0000, + 4, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x000F, 0x000E, 0x0000, 0x0000, + 10, 0, 0, 0,0x0000, 0x0000, 0x01FF, 0x03FF, 0x0333, 0x0333, 0x0333, 0x0333, 0x0333, 0x0333, 0x0000, 0x0000, + 7, 0, 0, 0,0x0000, 0x0000, 0x003F, 0x007F, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x0000, 0x0000, + 8, 0, 0, 0,0x0000, 0x0000, 0x007E, 0x00FF, 0x00C3, 0x00C3, 0x00C3, 0x00C3, 0x00FF, 0x007E, 0x0000, 0x0000, + 7, 0, 0, 0,0x0000, 0x0000, 0x003F, 0x007F, 0x0063, 0x0063, 0x007F, 0x003F, 0x0003, 0x0003, 0x0003, 0x0003, + 7, 0, 0, 0,0x0000, 0x0000, 0x007E, 0x007F, 0x0063, 0x0063, 0x007F, 0x007E, 0x0060, 0x0060, 0x0060, 0x0060, + 7, 0, 0, 0,0x0000, 0x0000, 0x003B, 0x007F, 0x0067, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000, + 8, 0, 0, 0,0x0000, 0x0000, 0x007E, 0x007F, 0x0003, 0x007F, 0x00FE, 0x00C0, 0x00FE, 0x007E, 0x0000, 0x0000, + 6, 0, 0, 0,0x0006, 0x0006, 0x003F, 0x003F, 0x0006, 0x0006, 0x0006, 0x0006, 0x003E, 0x003C, 0x0000, 0x0000, + 7, 0, 0, 0,0x0000, 0x0000, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x0063, 0x007F, 0x007E, 0x0000, 0x0000, + 10, 0, 0, 0,0x0000, 0x0000, 0x0303, 0x0303, 0x0303, 0x0387, 0x01CE, 0x00FC, 0x0078, 0x0030, 0x0000, 0x0000, + 10, 0, 0, 0,0x0000, 0x0000, 0x0303, 0x0303, 0x0333, 0x037B, 0x03FF, 0x03CF, 0x0387, 0x0303, 0x0000, 0x0000, + 8, 0, 0, 0,0x0000, 0x0000, 0x00C3, 0x00E7, 0x007E, 0x003C, 0x003C, 0x007E, 0x00E7, 0x00C3, 0x0000, 0x0000, + 10, 0, 0, 0,0x0000, 0x0000, 0x0303, 0x0307, 0x038E, 0x01DC, 0x00F8, 0x0070, 0x0038, 0x001C, 0x000E, 0x0006, + 8, 0, 0, 0,0x0000, 0x0000, 0x00FF, 0x00FF, 0x0070, 0x0038, 0x001C, 0x000E, 0x00FF, 0x00FF, 0x0000, 0x0000, + 6, 0, 0, 0,0x0038, 0x003C, 0x000C, 0x000C, 0x000F, 0x000F, 0x000C, 0x000C, 0x003C, 0x0038, 0x0000, 0x0000, + 2, 0, 0, 0,0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0000, 0x0000, + 6, 0, 0, 0,0x0007, 0x000F, 0x000C, 0x000C, 0x003C, 0x003C, 0x000C, 0x000C, 0x000F, 0x0007, 0x0000, 0x0000, + 10, 0, 0, 0,0x0000, 0x0000, 0x0000, 0x031C, 0x03BE, 0x01F7, 0x00E3, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 11, 0, 0, 0,0x0555, 0x0000, 0x0401, 0x0000, 0x0401, 0x0000, 0x0401, 0x0000, 0x0401, 0x0000, 0x0555, 0x0000, +}; +#endif diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index de71da9..78f64f6 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -43,6 +43,7 @@ #include "version.h" #include "FrontendUtil.h" +#include "OSD.h" #include "NDS.h" #include "GBACart.h" @@ -263,7 +264,7 @@ EmuThread::EmuThread(QObject* parent) : QThread(parent) connect(this, SIGNAL(windowEmuReset()), mainWindow->actReset, SLOT(trigger())); connect(this, SIGNAL(screenLayoutChange()), mainWindow->panel, SLOT(onScreenLayoutChanged())); - initOpenGL(); + if (mainWindow->hasOGL) initOpenGL(); } void EmuThread::initOpenGL() @@ -709,10 +710,13 @@ ScreenPanelNative::ScreenPanelNative(QWidget* parent) : QWidget(parent) screenTrans[1].reset(); touching = false; + + OSD::Init(nullptr); } ScreenPanelNative::~ScreenPanelNative() { + OSD::DeInit(nullptr); } void ScreenPanelNative::setupScreenLayout() @@ -756,6 +760,9 @@ void ScreenPanelNative::paintEvent(QPaintEvent* event) painter.setTransform(screenTrans[1]); painter.drawImage(screenrc, screen[1]); + + OSD::Update(nullptr); + OSD::DrawNative(painter); } void ScreenPanelNative::resizeEvent(QResizeEvent* event) @@ -793,12 +800,16 @@ ScreenPanelGL::ScreenPanelGL(QWidget* parent) : QOpenGLWidget(parent) format.setVersion(3, 2); format.setProfile(QSurfaceFormat::CoreProfile); setFormat(format); + + touching = false; } ScreenPanelGL::~ScreenPanelGL() { makeCurrent(); + OSD::DeInit(this); + glDeleteTextures(1, &screenTexture); glDeleteVertexArrays(1, &screenVertexArray); @@ -881,6 +892,8 @@ void ScreenPanelGL::initializeGL() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 192*2, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + + OSD::Init(this); } void ScreenPanelGL::paintGL() @@ -935,6 +948,9 @@ void ScreenPanelGL::paintGL() glDrawArrays(GL_TRIANGLES, 2*3, 2*3); screenShader->release(); + + OSD::Update(this); + OSD::DrawGL(this, w*factor, h*factor); } void ScreenPanelGL::resizeEvent(QResizeEvent* event) diff --git a/src/frontend/qt_sdl/main_shaders.h b/src/frontend/qt_sdl/main_shaders.h index 96b9ecd..c55f79e 100644 --- a/src/frontend/qt_sdl/main_shaders.h +++ b/src/frontend/qt_sdl/main_shaders.h @@ -61,54 +61,4 @@ void main() } )"; - - -const char* kScreenVS_OSD = R"(#version 140 - -layout(std140) uniform uConfig -{ - vec2 uScreenSize; - uint u3DScale; - uint uFilterMode; -}; - -uniform ivec2 uOSDPos; -uniform ivec2 uOSDSize; - -in vec2 vPosition; - -smooth out vec2 fTexcoord; - -void main() -{ - vec4 fpos; - - vec2 osdpos = (vPosition * vec2(uOSDSize)); - fTexcoord = osdpos; - osdpos += uOSDPos; - - fpos.xy = ((osdpos * 2.0) / uScreenSize) - 1.0; - fpos.y *= -1; - fpos.z = 0.0; - fpos.w = 1.0; - - gl_Position = fpos; -} -)"; - -const char* kScreenFS_OSD = R"(#version 140 - -uniform sampler2D OSDTex; - -smooth in vec2 fTexcoord; - -out vec4 oColor; - -void main() -{ - vec4 pixel = texelFetch(OSDTex, ivec2(fTexcoord), 0); - oColor = pixel.bgra; -} -)"; - #endif // MAIN_SHADERS_H -- cgit v1.2.3 From a2004785a4d49f02f8257a38489eb57a29ce4e91 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 28 May 2020 18:22:02 +0200 Subject: re-add all old OSD messages --- src/frontend/Util_ROM.cpp | 6 ------ src/frontend/qt_sdl/main.cpp | 41 +++++++++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/frontend/Util_ROM.cpp b/src/frontend/Util_ROM.cpp index ec3186a..3f64b9d 100644 --- a/src/frontend/Util_ROM.cpp +++ b/src/frontend/Util_ROM.cpp @@ -384,10 +384,6 @@ bool SaveState(const char* filename) } } - /*char msg[64]; - if (slot > 0) sprintf(msg, "State saved to slot %d", slot); - else sprintf(msg, "State saved to file"); - OSD::AddMessage(0, msg);*/ return true; } @@ -407,8 +403,6 @@ void UndoStateLoad() strncpy(SRAMPath[ROMSlot_NDS], PrevSRAMPath[ROMSlot_NDS], 1024); NDS::RelocateSave(SRAMPath[ROMSlot_NDS], false); } - - //OSD::AddMessage(0, "State load undone"); } } diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 78f64f6..bea33b0 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -364,16 +364,16 @@ void EmuThread::run() if (Input::HotkeyPressed(HK_SolarSensorDecrease)) { if (GBACart_SolarSensor::LightLevel > 0) GBACart_SolarSensor::LightLevel--; - //char msg[64]; - //sprintf(msg, "Solar sensor level set to %d", GBACart_SolarSensor::LightLevel); - //OSD::AddMessage(0, msg); + char msg[64]; + sprintf(msg, "Solar sensor level set to %d", GBACart_SolarSensor::LightLevel); + OSD::AddMessage(0, msg); } if (Input::HotkeyPressed(HK_SolarSensorIncrease)) { if (GBACart_SolarSensor::LightLevel < 10) GBACart_SolarSensor::LightLevel++; - //char msg[64]; - //sprintf(msg, "Solar sensor level set to %d", GBACart_SolarSensor::LightLevel); - //OSD::AddMessage(0, msg); + char msg[64]; + sprintf(msg, "Solar sensor level set to %d", GBACart_SolarSensor::LightLevel); + OSD::AddMessage(0, msg); } } @@ -411,7 +411,7 @@ void EmuThread::run() { bool lid = !NDS::IsLidClosed(); NDS::SetLidClosed(lid); - //OSD::AddMessage(0, lid ? "Lid closed" : "Lid opened"); + OSD::AddMessage(0, lid ? "Lid closed" : "Lid opened"); } // microphone input @@ -1493,13 +1493,16 @@ void MainWindow::onSaveState() if (Frontend::SaveState(filename)) { - // TODO: OSD message + char msg[64]; + if (slot > 0) sprintf(msg, "State saved to slot %d", slot); + else sprintf(msg, "State saved to file"); + OSD::AddMessage(0, msg); actLoadState[slot]->setEnabled(true); } else { - // TODO: OSD error message? + OSD::AddMessage(0xFFA0A0, "State save failed"); } emuThread->emuUnpause(); @@ -1534,10 +1537,10 @@ void MainWindow::onLoadState() if (!Platform::FileExists(filename)) { - /*char msg[64]; + char msg[64]; if (slot > 0) sprintf(msg, "State slot %d is empty", slot); else sprintf(msg, "State file does not exist"); - OSD::AddMessage(0xFFA0A0, msg);*/ + OSD::AddMessage(0xFFA0A0, msg); emuThread->emuUnpause(); return; @@ -1545,11 +1548,14 @@ void MainWindow::onLoadState() if (Frontend::LoadState(filename)) { - // TODO: OSD message + char msg[64]; + if (slot > 0) sprintf(msg, "State loaded from slot %d", slot); + else sprintf(msg, "State loaded from file"); + OSD::AddMessage(0, msg); } else { - // TODO: OSD error message? + OSD::AddMessage(0xFFA0A0, "State load failed"); } emuThread->emuUnpause(); @@ -1560,6 +1566,8 @@ void MainWindow::onUndoStateLoad() emuThread->emuPause(); Frontend::UndoStateLoad(); emuThread->emuUnpause(); + + OSD::AddMessage(0, "State load undone"); } void MainWindow::onQuit() @@ -1575,10 +1583,12 @@ void MainWindow::onPause(bool checked) if (checked) { emuThread->emuPause(); + OSD::AddMessage(0, "Paused"); } else { emuThread->emuUnpause(); + OSD::AddMessage(0, "Resumed"); } } @@ -1600,8 +1610,7 @@ void MainWindow::onReset() } else { - // OSD::AddMessage(0, "Reset"); - + OSD::AddMessage(0, "Reset"); emuThread->emuRun(); } } @@ -1835,7 +1844,7 @@ void emuStop() emit emuThread->windowEmuStop(); - //OSD::AddMessage(0xFFC040, "Shutdown"); + OSD::AddMessage(0xFFC040, "Shutdown"); } -- cgit v1.2.3 From b7946c1384ce7c44172036f0a04410a9c04ed78c Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 28 May 2020 22:21:36 +0200 Subject: * flesh out design for wifi settings dialog * move the pcap shit to a betterer place --- src/frontend/qt_sdl/LAN_PCap.cpp | 387 ++++++++ src/frontend/qt_sdl/LAN_PCap.h | 53 ++ src/frontend/qt_sdl/LAN_Socket.cpp | 1145 ++++++++++++++++++++++++ src/frontend/qt_sdl/LAN_Socket.h | 38 + src/frontend/qt_sdl/WifiSettingsDialog.ui | 165 ++++ src/frontend/qt_sdl/pcap/bluetooth.h | 56 ++ src/frontend/qt_sdl/pcap/bpf.h | 270 ++++++ src/frontend/qt_sdl/pcap/can_socketcan.h | 56 ++ src/frontend/qt_sdl/pcap/compiler-tests.h | 152 ++++ src/frontend/qt_sdl/pcap/dlt.h | 1389 +++++++++++++++++++++++++++++ src/frontend/qt_sdl/pcap/funcattrs.h | 242 +++++ src/frontend/qt_sdl/pcap/ipnet.h | 43 + src/frontend/qt_sdl/pcap/namedb.h | 85 ++ src/frontend/qt_sdl/pcap/nflog.h | 94 ++ src/frontend/qt_sdl/pcap/pcap-inttypes.h | 117 +++ src/frontend/qt_sdl/pcap/pcap.h | 966 ++++++++++++++++++++ src/frontend/qt_sdl/pcap/sll.h | 131 +++ src/frontend/qt_sdl/pcap/usb.h | 143 +++ src/frontend/qt_sdl/pcap/vlan.h | 46 + src/pcap/bluetooth.h | 56 -- src/pcap/bpf.h | 270 ------ src/pcap/can_socketcan.h | 56 -- src/pcap/compiler-tests.h | 152 ---- src/pcap/dlt.h | 1389 ----------------------------- src/pcap/funcattrs.h | 242 ----- src/pcap/ipnet.h | 43 - src/pcap/namedb.h | 85 -- src/pcap/nflog.h | 94 -- src/pcap/pcap-inttypes.h | 117 --- src/pcap/pcap.h | 966 -------------------- src/pcap/sll.h | 131 --- src/pcap/usb.h | 143 --- src/pcap/vlan.h | 46 - 33 files changed, 5578 insertions(+), 3790 deletions(-) create mode 100644 src/frontend/qt_sdl/LAN_PCap.cpp create mode 100644 src/frontend/qt_sdl/LAN_PCap.h create mode 100644 src/frontend/qt_sdl/LAN_Socket.cpp create mode 100644 src/frontend/qt_sdl/LAN_Socket.h create mode 100644 src/frontend/qt_sdl/WifiSettingsDialog.ui create mode 100644 src/frontend/qt_sdl/pcap/bluetooth.h create mode 100644 src/frontend/qt_sdl/pcap/bpf.h create mode 100644 src/frontend/qt_sdl/pcap/can_socketcan.h create mode 100644 src/frontend/qt_sdl/pcap/compiler-tests.h create mode 100644 src/frontend/qt_sdl/pcap/dlt.h create mode 100644 src/frontend/qt_sdl/pcap/funcattrs.h create mode 100644 src/frontend/qt_sdl/pcap/ipnet.h create mode 100644 src/frontend/qt_sdl/pcap/namedb.h create mode 100644 src/frontend/qt_sdl/pcap/nflog.h create mode 100644 src/frontend/qt_sdl/pcap/pcap-inttypes.h create mode 100644 src/frontend/qt_sdl/pcap/pcap.h create mode 100644 src/frontend/qt_sdl/pcap/sll.h create mode 100644 src/frontend/qt_sdl/pcap/usb.h create mode 100644 src/frontend/qt_sdl/pcap/vlan.h delete mode 100644 src/pcap/bluetooth.h delete mode 100644 src/pcap/bpf.h delete mode 100644 src/pcap/can_socketcan.h delete mode 100644 src/pcap/compiler-tests.h delete mode 100644 src/pcap/dlt.h delete mode 100644 src/pcap/funcattrs.h delete mode 100644 src/pcap/ipnet.h delete mode 100644 src/pcap/namedb.h delete mode 100644 src/pcap/nflog.h delete mode 100644 src/pcap/pcap-inttypes.h delete mode 100644 src/pcap/pcap.h delete mode 100644 src/pcap/sll.h delete mode 100644 src/pcap/usb.h delete mode 100644 src/pcap/vlan.h (limited to 'src') diff --git a/src/frontend/qt_sdl/LAN_PCap.cpp b/src/frontend/qt_sdl/LAN_PCap.cpp new file mode 100644 index 0000000..ce278bc --- /dev/null +++ b/src/frontend/qt_sdl/LAN_PCap.cpp @@ -0,0 +1,387 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +// direct LAN interface. Currently powered by libpcap, may change. + +#include +#include +#include +#include +#include +#include "../Wifi.h" +#include "LAN_PCap.h" +#include "PlatformConfig.h" + +#ifdef __WIN32__ + #include +#else + #include + #include + #include + #include +#endif + + +// welp +#ifndef PCAP_OPENFLAG_PROMISCUOUS +#define PCAP_OPENFLAG_PROMISCUOUS 1 +#endif + + +#define DECL_PCAP_FUNC(ret, name, args, args2) \ + typedef ret (*type_##name) args; \ + type_##name ptr_##name = NULL; \ + ret name args { return ptr_##name args2; } + +DECL_PCAP_FUNC(int, pcap_findalldevs, (pcap_if_t** alldevs, char* errbuf), (alldevs,errbuf)) +DECL_PCAP_FUNC(void, pcap_freealldevs, (pcap_if_t* alldevs), (alldevs)) +DECL_PCAP_FUNC(pcap_t*, pcap_open_live, (const char* src, int snaplen, int flags, int readtimeout, char* errbuf), (src,snaplen,flags,readtimeout,errbuf)) +DECL_PCAP_FUNC(void, pcap_close, (pcap_t* dev), (dev)) +DECL_PCAP_FUNC(int, pcap_setnonblock, (pcap_t* dev, int nonblock, char* errbuf), (dev,nonblock,errbuf)) +DECL_PCAP_FUNC(int, pcap_sendpacket, (pcap_t* dev, const u_char* data, int len), (dev,data,len)) +DECL_PCAP_FUNC(int, pcap_dispatch, (pcap_t* dev, int num, pcap_handler callback, u_char* data), (dev,num,callback,data)) +DECL_PCAP_FUNC(const u_char*, pcap_next, (pcap_t* dev, struct pcap_pkthdr* hdr), (dev,hdr)) + + +namespace LAN_PCap +{ + +const char* PCapLibNames[] = +{ +#ifdef __WIN32__ + // TODO: name for npcap in non-WinPCap mode + "wpcap.dll", +#else + // Linux lib names + "libpcap.so.1", + "libpcap.so", +#endif + NULL +}; + +AdapterData* Adapters = NULL; +int NumAdapters = 0; + +void* PCapLib = NULL; +pcap_t* PCapAdapter = NULL; +AdapterData* PCapAdapterData; + +u8 PacketBuffer[2048]; +int PacketLen; +volatile int RXNum; + + +#define LOAD_PCAP_FUNC(sym) \ + ptr_##sym = (type_##sym)SDL_LoadFunction(lib, #sym); \ + if (!ptr_##sym) return false; + +bool TryLoadPCap(void* lib) +{ + LOAD_PCAP_FUNC(pcap_findalldevs) + LOAD_PCAP_FUNC(pcap_freealldevs) + LOAD_PCAP_FUNC(pcap_open_live) + LOAD_PCAP_FUNC(pcap_close) + LOAD_PCAP_FUNC(pcap_setnonblock) + LOAD_PCAP_FUNC(pcap_sendpacket) + LOAD_PCAP_FUNC(pcap_dispatch) + LOAD_PCAP_FUNC(pcap_next) + + return true; +} + +bool Init(bool open_adapter) +{ + // TODO: how to deal with cases where an adapter is unplugged or changes config?? + if (!PCapLib) + { + PCapLib = NULL; + + for (int i = 0; PCapLibNames[i]; i++) + { + void* lib = SDL_LoadObject(PCapLibNames[i]); + if (!lib) continue; + + if (!TryLoadPCap(lib)) + { + SDL_UnloadObject(lib); + continue; + } + + printf("PCap: lib %s, init successful\n", PCapLibNames[i]); + PCapLib = lib; + break; + } + + if (PCapLib == NULL) + { + printf("PCap: init failed\n"); + return false; + } + } + + PCapAdapter = NULL; + PacketLen = 0; + RXNum = 0; + + NumAdapters = 0; + + char errbuf[PCAP_ERRBUF_SIZE]; + int ret; + + pcap_if_t* alldevs; + ret = pcap_findalldevs(&alldevs, errbuf); + if (ret < 0 || alldevs == NULL) + { + printf("PCap: no devices available\n"); + return false; + } + + pcap_if_t* dev = alldevs; + while (dev) { NumAdapters++; dev = dev->next; } + + Adapters = new AdapterData[NumAdapters]; + memset(Adapters, 0, sizeof(AdapterData)*NumAdapters); + + AdapterData* adata = &Adapters[0]; + dev = alldevs; + while (dev) + { + adata->Internal = dev; + +#ifdef __WIN32__ + // hax + int len = strlen(dev->name); + len -= 12; if (len > 127) len = 127; + strncpy(adata->DeviceName, &dev->name[12], len); + adata->DeviceName[len] = '\0'; +#else + strncpy(adata->DeviceName, dev->name, 127); + adata->DeviceName[127] = '\0'; + + strncpy(adata->FriendlyName, adata->DeviceName, 127); + adata->FriendlyName[127] = '\0'; +#endif // __WIN32__ + + dev = dev->next; + adata++; + } + +#ifdef __WIN32__ + + ULONG bufsize = 16384; + IP_ADAPTER_ADDRESSES* buf = (IP_ADAPTER_ADDRESSES*)HeapAlloc(GetProcessHeap(), 0, bufsize); + ULONG uret = GetAdaptersAddresses(AF_INET, 0, NULL, buf, &bufsize); + if (uret == ERROR_BUFFER_OVERFLOW) + { + HeapFree(GetProcessHeap(), 0, buf); + buf = (IP_ADAPTER_ADDRESSES*)HeapAlloc(GetProcessHeap(), 0, bufsize); + uret = GetAdaptersAddresses(AF_INET, 0, NULL, buf, &bufsize); + } + if (uret != ERROR_SUCCESS) + { + printf("GetAdaptersAddresses() shat itself: %08X\n", uret); + return false; + } + + for (int i = 0; i < NumAdapters; i++) + { + adata = &Adapters[i]; + IP_ADAPTER_ADDRESSES* addr = buf; + while (addr) + { + if (strcmp(addr->AdapterName, adata->DeviceName)) + { + addr = addr->Next; + continue; + } + + WideCharToMultiByte(CP_UTF8, 0, addr->FriendlyName, 127, adata->FriendlyName, 127, NULL, NULL); + adata->FriendlyName[127] = '\0'; + + WideCharToMultiByte(CP_UTF8, 0, addr->Description, 127, adata->Description, 127, NULL, NULL); + adata->Description[127] = '\0'; + + if (addr->PhysicalAddressLength != 6) + { + printf("weird MAC addr length %d for %s\n", addr->PhysicalAddressLength, addr->AdapterName); + } + else + memcpy(adata->MAC, addr->PhysicalAddress, 6); + + IP_ADAPTER_UNICAST_ADDRESS* ipaddr = addr->FirstUnicastAddress; + while (ipaddr) + { + SOCKADDR* sa = ipaddr->Address.lpSockaddr; + if (sa->sa_family == AF_INET) + { + struct in_addr sa4 = ((sockaddr_in*)sa)->sin_addr; + memcpy(adata->IP_v4, &sa4, 4); + } + + ipaddr = ipaddr->Next; + } + + break; + } + } + + HeapFree(GetProcessHeap(), 0, buf); + +#else + + struct ifaddrs* addrs; + if (getifaddrs(&addrs) != 0) + { + printf("getifaddrs() shat itself :(\n"); + return false; + } + + for (int i = 0; i < NumAdapters; i++) + { + adata = &Adapters[i]; + struct ifaddrs* curaddr = addrs; + while (curaddr) + { + if (strcmp(curaddr->ifa_name, adata->DeviceName)) + { + curaddr = curaddr->ifa_next; + continue; + } + + if (!curaddr->ifa_addr) + { + printf("Device (%s) does not have an address :/\n", curaddr->ifa_name); + curaddr = curaddr->ifa_next; + continue; + } + + u16 af = curaddr->ifa_addr->sa_family; + if (af == AF_INET) + { + struct sockaddr_in* sa = (sockaddr_in*)curaddr->ifa_addr; + memcpy(adata->IP_v4, &sa->sin_addr, 4); + } + else if (af == AF_PACKET) + { + struct sockaddr_ll* sa = (sockaddr_ll*)curaddr->ifa_addr; + if (sa->sll_halen != 6) + printf("weird MAC length %d for %s\n", sa->sll_halen, curaddr->ifa_name); + else + memcpy(adata->MAC, sa->sll_addr, 6); + } + + curaddr = curaddr->ifa_next; + } + } + + freeifaddrs(addrs); + +#endif // __WIN32__ + + if (!open_adapter) return true; + if (PCapAdapter) pcap_close(PCapAdapter); + + // open pcap device + PCapAdapterData = &Adapters[0]; + for (int i = 0; i < NumAdapters; i++) + { + if (!strncmp(Adapters[i].DeviceName, Config::LANDevice, 128)) + PCapAdapterData = &Adapters[i]; + } + + dev = (pcap_if_t*)PCapAdapterData->Internal; + PCapAdapter = pcap_open_live(dev->name, 2048, PCAP_OPENFLAG_PROMISCUOUS, 1, errbuf); + if (!PCapAdapter) + { + printf("PCap: failed to open adapter %s\n", errbuf); + return false; + } + + pcap_freealldevs(alldevs); + + if (pcap_setnonblock(PCapAdapter, 1, errbuf) < 0) + { + printf("PCap: failed to set nonblocking mode\n"); + pcap_close(PCapAdapter); PCapAdapter = NULL; + return false; + } + + return true; +} + +void DeInit() +{ + if (PCapLib) + { + if (PCapAdapter) + { + pcap_close(PCapAdapter); + PCapAdapter = NULL; + } + + SDL_UnloadObject(PCapLib); + PCapLib = NULL; + } +} + + +void RXCallback(u_char* blarg, const struct pcap_pkthdr* header, const u_char* data) +{ + while (RXNum > 0); + + if (header->len > 2048-64) return; + + PacketLen = header->len; + memcpy(PacketBuffer, data, PacketLen); + RXNum = 1; +} + +int SendPacket(u8* data, int len) +{ + if (PCapAdapter == NULL) + return 0; + + if (len > 2048) + { + printf("LAN_SendPacket: error: packet too long (%d)\n", len); + return 0; + } + + pcap_sendpacket(PCapAdapter, data, len); + // TODO: check success + return len; +} + +int RecvPacket(u8* data) +{ + if (PCapAdapter == NULL) + return 0; + + int ret = 0; + if (RXNum > 0) + { + memcpy(data, PacketBuffer, PacketLen); + ret = PacketLen; + RXNum = 0; + } + + pcap_dispatch(PCapAdapter, 1, RXCallback, NULL); + return ret; +} + +} diff --git a/src/frontend/qt_sdl/LAN_PCap.h b/src/frontend/qt_sdl/LAN_PCap.h new file mode 100644 index 0000000..250b8e9 --- /dev/null +++ b/src/frontend/qt_sdl/LAN_PCap.h @@ -0,0 +1,53 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef LAN_PCAP_H +#define LAN_PCAP_H + +#include "../types.h" + +namespace LAN_PCap +{ + +typedef struct +{ + char DeviceName[128]; + char FriendlyName[128]; + char Description[128]; + + u8 MAC[6]; + u8 IP_v4[4]; + + void* Internal; + +} AdapterData; + + +extern AdapterData* Adapters; +extern int NumAdapters; + + +bool Init(bool open_adapter); +void DeInit(); + +int SendPacket(u8* data, int len); +int RecvPacket(u8* data); + +} + +#endif // LAN_PCAP_H diff --git a/src/frontend/qt_sdl/LAN_Socket.cpp b/src/frontend/qt_sdl/LAN_Socket.cpp new file mode 100644 index 0000000..c6fbd4b --- /dev/null +++ b/src/frontend/qt_sdl/LAN_Socket.cpp @@ -0,0 +1,1145 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +// indirect LAN interface, powered by BSD sockets. + +#include +#include +#include +#include "../Wifi.h" +#include "LAN_Socket.h" +#include "../Config.h" + +#ifdef __WIN32__ + #include + #include + #define socket_t SOCKET + #define sockaddr_t SOCKADDR +#else + #include + #include + #include + #include + #include + #include + #include + #define socket_t int + #define sockaddr_t struct sockaddr + #define closesocket close +#endif + +#ifndef INVALID_SOCKET +#define INVALID_SOCKET (socket_t)-1 +#endif + + +namespace LAN_Socket +{ + +const u32 kSubnet = 0x0A400000; +const u32 kServerIP = kSubnet | 0x01; +const u32 kDNSIP = kSubnet | 0x02; +const u32 kClientIP = kSubnet | 0x10; + +const u8 kServerMAC[6] = {0x00, 0xAB, 0x33, 0x28, 0x99, 0x44}; +const u8 kDNSMAC[6] = {0x00, 0xAB, 0x33, 0x28, 0x99, 0x55}; + +u8 PacketBuffer[2048]; +int PacketLen; +volatile int RXNum; + +u16 IPv4ID; + + +// TODO: UDP sockets +// * use FIFO list +// * assign new socket when seeing new IP/port + + +typedef struct +{ + u8 DestIP[4]; + u16 SourcePort; + u16 DestPort; + + u32 SeqNum; // sequence number for incoming frames + u32 AckNum; + + // 0: unused + // 1: connected + u8 Status; + + socket_t Backend; + +} TCPSocket; + +typedef struct +{ + u8 DestIP[4]; + u16 SourcePort; + u16 DestPort; + + socket_t Backend; + struct sockaddr_in BackendAddr; + +} UDPSocket; + +TCPSocket TCPSocketList[16]; +UDPSocket UDPSocketList[4]; + +int UDPSocketID = 0; + + +bool Init() +{ + // TODO: how to deal with cases where an adapter is unplugged or changes config?? + //if (PCapLib) return true; + + //Lib = NULL; + PacketLen = 0; + RXNum = 0; + + IPv4ID = 1; + + memset(TCPSocketList, 0, sizeof(TCPSocketList)); + memset(UDPSocketList, 0, sizeof(UDPSocketList)); + + UDPSocketID = 0; + + return true; +} + +void DeInit() +{ + for (int i = 0; i < (sizeof(TCPSocketList)/sizeof(TCPSocket)); i++) + { + TCPSocket* sock = &TCPSocketList[i]; + if (sock->Backend) closesocket(sock->Backend); + } + + for (int i = 0; i < (sizeof(UDPSocketList)/sizeof(UDPSocket)); i++) + { + UDPSocket* sock = &UDPSocketList[i]; + if (sock->Backend) closesocket(sock->Backend); + } +} + + +void FinishUDPFrame(u8* data, int len) +{ + u8* ipheader = &data[0xE]; + u8* udpheader = &data[0x22]; + + // lengths + *(u16*)&ipheader[2] = htons(len - 0xE); + *(u16*)&udpheader[4] = htons(len - (0xE + 0x14)); + + // IP checksum + u32 tmp = 0; + + for (int i = 0; i < 20; i += 2) + tmp += ntohs(*(u16*)&ipheader[i]); + while (tmp >> 16) + tmp = (tmp & 0xFFFF) + (tmp >> 16); + tmp ^= 0xFFFF; + *(u16*)&ipheader[10] = htons(tmp); + + // UDP checksum + // (note: normally not mandatory, but some older sgIP versions require it) + tmp = 0; + tmp += ntohs(*(u16*)&ipheader[12]); + tmp += ntohs(*(u16*)&ipheader[14]); + tmp += ntohs(*(u16*)&ipheader[16]); + tmp += ntohs(*(u16*)&ipheader[18]); + tmp += ntohs(0x1100); + tmp += (len-0x22); + for (u8* i = udpheader; i < &udpheader[len-0x23]; i += 2) + tmp += ntohs(*(u16*)i); + if (len & 1) + tmp += ntohs((u_short)udpheader[len-0x23]); + while (tmp >> 16) + tmp = (tmp & 0xFFFF) + (tmp >> 16); + tmp ^= 0xFFFF; + if (tmp == 0) tmp = 0xFFFF; + *(u16*)&udpheader[6] = htons(tmp); +} + +void FinishTCPFrame(u8* data, int len) +{ + u8* ipheader = &data[0xE]; + u8* tcpheader = &data[0x22]; + + // lengths + *(u16*)&ipheader[2] = htons(len - 0xE); + + // IP checksum + u32 tmp = 0; + + for (int i = 0; i < 20; i += 2) + tmp += ntohs(*(u16*)&ipheader[i]); + while (tmp >> 16) + tmp = (tmp & 0xFFFF) + (tmp >> 16); + tmp ^= 0xFFFF; + *(u16*)&ipheader[10] = htons(tmp); + + u32 tcplen = ntohs(*(u16*)&ipheader[2]) - 0x14; + + // TCP checksum + tmp = 0; + tmp += ntohs(*(u16*)&ipheader[12]); + tmp += ntohs(*(u16*)&ipheader[14]); + tmp += ntohs(*(u16*)&ipheader[16]); + tmp += ntohs(*(u16*)&ipheader[18]); + tmp += ntohs(0x0600); + tmp += tcplen; + for (u8* i = tcpheader; i < &tcpheader[tcplen-1]; i += 2) + tmp += ntohs(*(u16*)i); + if (tcplen & 1) + tmp += ntohs((u_short)tcpheader[tcplen-1]); + while (tmp >> 16) + tmp = (tmp & 0xFFFF) + (tmp >> 16); + tmp ^= 0xFFFF; + *(u16*)&tcpheader[16] = htons(tmp); +} + + +void HandleDHCPFrame(u8* data, int len) +{ + u8 type = 0xFF; + + u32 transid = *(u32*)&data[0x2E]; + + u8* options = &data[0x11A]; + for (;;) + { + if (options >= &data[len]) break; + u8 opt = *options++; + if (opt == 255) break; + + u8 len = *options++; + switch (opt) + { + case 53: // frame type + type = options[0]; + break; + } + + options += len; + } + + if (type == 0xFF) + { + printf("DHCP: bad frame\n"); + return; + } + + printf("DHCP: frame type %d, transid %08X\n", type, transid); + + if (type == 1 || // discover + type == 3) // request + { + u8 resp[512]; + u8* out = &resp[0]; + + // ethernet + memcpy(out, &data[6], 6); out += 6; + memcpy(out, kServerMAC, 6); out += 6; + *(u16*)out = htons(0x0800); out += 2; + + // IP + u8* ipheader = out; + *out++ = 0x45; + *out++ = 0x00; + *(u16*)out = 0; out += 2; // total length + *(u16*)out = htons(IPv4ID); out += 2; IPv4ID++; + *out++ = 0x00; + *out++ = 0x00; + *out++ = 0x80; // TTL + *out++ = 0x11; // protocol (UDP) + *(u16*)out = 0; out += 2; // checksum + *(u32*)out = htonl(kServerIP); out += 4; // source IP + if (type == 1) + { + *(u32*)out = htonl(0xFFFFFFFF); out += 4; // destination IP + } + else if (type == 3) + { + *(u32*)out = htonl(kClientIP); out += 4; // destination IP + } + + // UDP + u8* udpheader = out; + *(u16*)out = htons(67); out += 2; // source port + *(u16*)out = htons(68); out += 2; // destination port + *(u16*)out = 0; out += 2; // length + *(u16*)out = 0; out += 2; // checksum + + // DHCP + u8* body = out; + *out++ = 0x02; + *out++ = 0x01; + *out++ = 0x06; + *out++ = 0x00; + *(u32*)out = transid; out += 4; + *(u16*)out = 0; out += 2; // seconds elapsed + *(u16*)out = 0; out += 2; + *(u32*)out = htonl(0x00000000); out += 4; // client IP + *(u32*)out = htonl(kClientIP); out += 4; // your IP + *(u32*)out = htonl(kServerIP); out += 4; // server IP + *(u32*)out = htonl(0x00000000); out += 4; // gateway IP + memcpy(out, &data[6], 6); out += 6; + memset(out, 0, 10); out += 10; + memset(out, 0, 192); out += 192; + *(u32*)out = 0x63538263; out += 4; // DHCP magic + + // DHCP options + *out++ = 53; *out++ = 1; + *out++ = (type==1) ? 2 : 5; // DHCP type: offer/ack + *out++ = 1; *out++ = 4; + *(u32*)out = htonl(0xFFFFFF00); out += 4; // subnet mask + *out++ = 3; *out++ = 4; + *(u32*)out = htonl(kServerIP); out += 4; // router + *out++ = 51; *out++ = 4; + *(u32*)out = htonl(442030); out += 4; // lease time + *out++ = 54; *out++ = 4; + *(u32*)out = htonl(kServerIP); out += 4; // DHCP server + *out++ = 6; *out++ = 4; + *(u32*)out = htonl(kDNSIP); out += 4; // DNS (hax) + + *out++ = 0xFF; + memset(out, 0, 20); out += 20; + + u32 framelen = (u32)(out - &resp[0]); + if (framelen & 1) { *out++ = 0; framelen++; } + FinishUDPFrame(resp, framelen); + + // TODO: if there is already a packet queued, this will overwrite it + // that being said, this will only happen during DHCP setup, so probably + // not a big deal + + PacketLen = framelen; + memcpy(PacketBuffer, resp, PacketLen); + RXNum = 1; + } +} + +void HandleDNSFrame(u8* data, int len) +{ + u8* ipheader = &data[0xE]; + u8* udpheader = &data[0x22]; + u8* dnsbody = &data[0x2A]; + + u32 srcip = ntohl(*(u32*)&ipheader[12]); + u16 srcport = ntohs(*(u16*)&udpheader[0]); + + u16 id = ntohs(*(u16*)&dnsbody[0]); + u16 flags = ntohs(*(u16*)&dnsbody[2]); + u16 numquestions = ntohs(*(u16*)&dnsbody[4]); + u16 numanswers = ntohs(*(u16*)&dnsbody[6]); + u16 numauth = ntohs(*(u16*)&dnsbody[8]); + u16 numadd = ntohs(*(u16*)&dnsbody[10]); + + printf("DNS: ID=%04X, flags=%04X, Q=%d, A=%d, auth=%d, add=%d\n", + id, flags, numquestions, numanswers, numauth, numadd); + + // for now we only take 'simple' DNS requests + if (flags & 0x8000) return; + if (numquestions != 1 || numanswers != 0) return; + + u8 resp[1024]; + u8* out = &resp[0]; + + // ethernet + memcpy(out, &data[6], 6); out += 6; + memcpy(out, kServerMAC, 6); out += 6; + *(u16*)out = htons(0x0800); out += 2; + + // IP + u8* resp_ipheader = out; + *out++ = 0x45; + *out++ = 0x00; + *(u16*)out = 0; out += 2; // total length + *(u16*)out = htons(IPv4ID); out += 2; IPv4ID++; + *out++ = 0x00; + *out++ = 0x00; + *out++ = 0x80; // TTL + *out++ = 0x11; // protocol (UDP) + *(u16*)out = 0; out += 2; // checksum + *(u32*)out = htonl(kDNSIP); out += 4; // source IP + *(u32*)out = htonl(srcip); out += 4; // destination IP + + // UDP + u8* resp_udpheader = out; + *(u16*)out = htons(53); out += 2; // source port + *(u16*)out = htons(srcport); out += 2; // destination port + *(u16*)out = 0; out += 2; // length + *(u16*)out = 0; out += 2; // checksum + + // DNS + u8* resp_body = out; + *(u16*)out = htons(id); out += 2; // ID + *(u16*)out = htons(0x8000); out += 2; // flags + *(u16*)out = htons(numquestions); out += 2; // num questions + *(u16*)out = htons(numquestions); out += 2; // num answers + *(u16*)out = 0; out += 2; // num authority + *(u16*)out = 0; out += 2; // num additional + + u32 curoffset = 12; + for (u16 i = 0; i < numquestions; i++) + { + if (curoffset >= (len-0x2A)) return; + + u8 bitlength = 0; + while ((bitlength = dnsbody[curoffset++]) != 0) + curoffset += bitlength; + + curoffset += 4; + } + + u32 qlen = curoffset-12; + if (qlen > 512) return; + memcpy(out, &dnsbody[12], qlen); out += qlen; + + curoffset = 12; + for (u16 i = 0; i < numquestions; i++) + { + // assemble the requested domain name + u8 bitlength = 0; + char domainname[256] = ""; int o = 0; + while ((bitlength = dnsbody[curoffset++]) != 0) + { + if ((o+bitlength) >= 255) + { + // welp. atleast try not to explode. + domainname[o++] = '\0'; + break; + } + + strncpy(&domainname[o], (const char *)&dnsbody[curoffset], bitlength); + o += bitlength; + + curoffset += bitlength; + if (dnsbody[curoffset] != 0) + domainname[o++] = '.'; + else + domainname[o++] = '\0'; + } + + u16 type = ntohs(*(u16*)&dnsbody[curoffset]); + u16 cls = ntohs(*(u16*)&dnsbody[curoffset+2]); + + printf("- q%d: %04X %04X %s", i, type, cls, domainname); + + // get answer + struct addrinfo dns_hint; + struct addrinfo* dns_res; + u32 addr_res; + + memset(&dns_hint, 0, sizeof(dns_hint)); + dns_hint.ai_family = AF_INET; // TODO: other address types (INET6, etc) + if (getaddrinfo(domainname, "0", &dns_hint, &dns_res) == 0) + { + struct addrinfo* p = dns_res; + while (p) + { + struct sockaddr_in* addr = (struct sockaddr_in*)p->ai_addr; + /*printf(" -> %d.%d.%d.%d", + addr->sin_addr.S_un.S_un_b.s_b1, addr->sin_addr.S_un.S_un_b.s_b2, + addr->sin_addr.S_un.S_un_b.s_b3, addr->sin_addr.S_un.S_un_b.s_b4);*/ + + //addr_res = addr->sin_addr.S_un.S_addr; + addr_res = *(u32*)&addr->sin_addr; + p = p->ai_next; + } + } + else + { + printf(" shat itself :("); + addr_res = 0; + } + + printf("\n"); + curoffset += 4; + + // TODO: betterer support + // (under which conditions does the C00C marker work?) + *(u16*)out = htons(0xC00C); out += 2; + *(u16*)out = htons(type); out += 2; + *(u16*)out = htons(cls); out += 2; + *(u32*)out = htonl(3600); out += 4; // TTL (hardcoded for now) + *(u16*)out = htons(4); out += 2; // address length + *(u32*)out = addr_res; out += 4; // address + } + + u32 framelen = (u32)(out - &resp[0]); + if (framelen & 1) { *out++ = 0; framelen++; } + FinishUDPFrame(resp, framelen); + + // TODO: if there is already a packet queued, this will overwrite it + // that being said, this will only happen during DHCP setup, so probably + // not a big deal + + PacketLen = framelen; + memcpy(PacketBuffer, resp, PacketLen); + RXNum = 1; +} + +void UDP_BuildIncomingFrame(UDPSocket* sock, u8* data, int len) +{ + u8 resp[2048]; + u8* out = &resp[0]; + + if (len > 1536) return; + + // ethernet + memcpy(out, Wifi::GetMAC(), 6); out += 6; // hurf + memcpy(out, kServerMAC, 6); out += 6; + *(u16*)out = htons(0x0800); out += 2; + + // IP + u8* resp_ipheader = out; + *out++ = 0x45; + *out++ = 0x00; + *(u16*)out = 0; out += 2; // total length + *(u16*)out = htons(IPv4ID); out += 2; IPv4ID++; + *out++ = 0x00; + *out++ = 0x00; + *out++ = 0x80; // TTL + *out++ = 0x11; // protocol (UDP) + *(u16*)out = 0; out += 2; // checksum + memcpy(out, sock->DestIP, 4); out += 4; // source IP + *(u32*)out = htonl(kClientIP); out += 4; // destination IP + + // UDP + u8* resp_tcpheader = out; + *(u16*)out = htons(sock->DestPort); out += 2; // source port + *(u16*)out = htons(sock->SourcePort); out += 2; // destination port + *(u16*)out = htons(len+8); out += 2; // length of header+data + *(u16*)out = 0; out += 2; // checksum + + memcpy(out, data, len); out += len; + + u32 framelen = (u32)(out - &resp[0]); + FinishUDPFrame(resp, framelen); + + // TODO: if there is already a packet queued, this will overwrite it + // that being said, this will only happen during DHCP setup, so probably + // not a big deal + + PacketLen = framelen; + memcpy(PacketBuffer, resp, PacketLen); + RXNum = 1; +} + +void HandleUDPFrame(u8* data, int len) +{ + u8* ipheader = &data[0xE]; + u8* udpheader = &data[0x22]; + + // debug + /*for (int j = 0; j < len; j += 16) + { + int rem = len - j; + if (rem > 16) rem = 16; + for (int i = 0; i < rem; i++) + { + printf("%02X ", data[i+j]); + } + printf("\n"); + }*/ + + u16 srcport = ntohs(*(u16*)&udpheader[0]); + u16 dstport = ntohs(*(u16*)&udpheader[2]); + + int sockid = -1; + UDPSocket* sock; + for (int i = 0; i < (sizeof(UDPSocketList)/sizeof(UDPSocket)); i++) + { + sock = &UDPSocketList[i]; + if (sock->Backend != 0 && !memcmp(&sock->DestIP, &ipheader[16], 4) && + sock->SourcePort == srcport && sock->DestPort == dstport) + { + sockid = i; + break; + } + } + + if (sockid == -1) + { + sockid = UDPSocketID; + sock = &UDPSocketList[sockid]; + + UDPSocketID++; + if (UDPSocketID >= (sizeof(UDPSocketList)/sizeof(UDPSocket))) + UDPSocketID = 0; + + if (sock->Backend != 0) + { + printf("LANMAGIC: closing previous UDP socket #%d\n", sockid); + closesocket(sock->Backend); + } + + sock->Backend = socket(AF_INET, SOCK_DGRAM, 0); + + memcpy(sock->DestIP, &ipheader[16], 4); + sock->SourcePort = srcport; + sock->DestPort = dstport; + + memset(&sock->BackendAddr, 0, sizeof(sock->BackendAddr)); + sock->BackendAddr.sin_family = AF_INET; + sock->BackendAddr.sin_port = htons(dstport); + memcpy(&sock->BackendAddr.sin_addr, &ipheader[16], 4); + /*if (bind(sock->Backend, (struct sockaddr*)&sock->BackendAddr, sizeof(sock->BackendAddr)) == -1) + { + printf("bind() shat itself :(\n"); + }*/ + + printf("LANMAGIC: opening UDP socket #%d to %d.%d.%d.%d:%d, srcport %d\n", + sockid, + ipheader[16], ipheader[17], ipheader[18], ipheader[19], + dstport, srcport); + } + + u16 udplen = ntohs(*(u16*)&udpheader[4]) - 8; + + printf("UDP: socket %d sending %d bytes\n", sockid, udplen); + sendto(sock->Backend, (char*)&udpheader[8], udplen, 0, + (struct sockaddr*)&sock->BackendAddr, sizeof(sock->BackendAddr)); +} + +void TCP_SYNACK(TCPSocket* sock, u8* data, int len) +{ + u8 resp[128]; + u8* out = &resp[0]; + + u8* ipheader = &data[0xE]; + u8* tcpheader = &data[0x22]; + + u32 seqnum = htonl(*(u32*)&tcpheader[4]); + seqnum++; + sock->AckNum = seqnum; + + //printf("SYNACK SEQ=%08X|%08X\n", sock->SeqNum, sock->AckNum); + + // ethernet + memcpy(out, &data[6], 6); out += 6; + memcpy(out, kServerMAC, 6); out += 6; + *(u16*)out = htons(0x0800); out += 2; + + // IP + u8* resp_ipheader = out; + *out++ = 0x45; + *out++ = 0x00; + *(u16*)out = 0; out += 2; // total length + *(u16*)out = htons(IPv4ID); out += 2; IPv4ID++; + *out++ = 0x00; + *out++ = 0x00; + *out++ = 0x80; // TTL + *out++ = 0x06; // protocol (TCP) + *(u16*)out = 0; out += 2; // checksum + *(u32*)out = *(u32*)&ipheader[16]; out += 4; // source IP + *(u32*)out = *(u32*)&ipheader[12]; out += 4; // destination IP + + // TCP + u8* resp_tcpheader = out; + *(u16*)out = *(u16*)&tcpheader[2]; out += 2; // source port + *(u16*)out = *(u16*)&tcpheader[0]; out += 2; // destination port + *(u32*)out = htonl(sock->SeqNum); out += 4; sock->SeqNum++; // seq number + *(u32*)out = htonl(seqnum); out += 4; // ack seq number + *(u16*)out = htons(0x8012); out += 2; // flags (SYN+ACK) + *(u16*)out = htons(0x7000); out += 2; // window size (uuuh) + *(u16*)out = 0; out += 2; // checksum + *(u16*)out = 0; out += 2; // urgent pointer + + // TCP options + *out++ = 0x02; *out++ = 0x04; // max segment size + *(u16*)out = htons(0x05B4); out += 2; + *out++ = 0x01; + *out++ = 0x01; + *out++ = 0x04; *out++ = 0x02; // SACK permitted + *out++ = 0x01; + *out++ = 0x03; *out++ = 0x03; // window size + *out++ = 0x08; + + u32 framelen = (u32)(out - &resp[0]); + //if (framelen & 1) { *out++ = 0; framelen++; } + FinishTCPFrame(resp, framelen); + + // TODO: if there is already a packet queued, this will overwrite it + // that being said, this will only happen during DHCP setup, so probably + // not a big deal + + PacketLen = framelen; + memcpy(PacketBuffer, resp, PacketLen); + RXNum = 1; +} + +void TCP_ACK(TCPSocket* sock, bool fin) +{ + u8 resp[64]; + u8* out = &resp[0]; + + u16 flags = 0x5010; + if (fin) flags |= 0x0001; + + //printf("%sACK SEQ=%08X|%08X\n", fin?"FIN":" ", sock->SeqNum, sock->AckNum); + + // ethernet + memcpy(out, Wifi::GetMAC(), 6); out += 6; + memcpy(out, kServerMAC, 6); out += 6; + *(u16*)out = htons(0x0800); out += 2; + + // IP + u8* resp_ipheader = out; + *out++ = 0x45; + *out++ = 0x00; + *(u16*)out = 0; out += 2; // total length + *(u16*)out = htons(IPv4ID); out += 2; IPv4ID++; + *out++ = 0x00; + *out++ = 0x00; + *out++ = 0x80; // TTL + *out++ = 0x06; // protocol (TCP) + *(u16*)out = 0; out += 2; // checksum + *(u32*)out = *(u32*)&sock->DestIP; out += 4; // source IP + *(u32*)out = htonl(kClientIP); out += 4; // destination IP + + // TCP + u8* resp_tcpheader = out; + *(u16*)out = htonl(sock->DestPort); out += 2; // source port + *(u16*)out = htonl(sock->SourcePort); out += 2; // destination port + *(u32*)out = htonl(sock->SeqNum); out += 4; // seq number + *(u32*)out = htonl(sock->AckNum); out += 4; // ack seq number + *(u16*)out = htons(flags); out += 2; // flags + *(u16*)out = htons(0x7000); out += 2; // window size (uuuh) + *(u16*)out = 0; out += 2; // checksum + *(u16*)out = 0; out += 2; // urgent pointer + + u32 framelen = (u32)(out - &resp[0]); + //if (framelen & 1) { *out++ = 0; framelen++; } + FinishTCPFrame(resp, framelen); + + // TODO: if there is already a packet queued, this will overwrite it + // that being said, this will only happen during DHCP setup, so probably + // not a big deal + + PacketLen = framelen; + memcpy(PacketBuffer, resp, PacketLen); + RXNum = 1; +} + +void TCP_BuildIncomingFrame(TCPSocket* sock, u8* data, int len) +{ + u8 resp[2048]; + u8* out = &resp[0]; + + if (len > 1536) return; +//printf("INCOMING SEQ=%08X|%08X\n", sock->SeqNum, sock->AckNum); + // ethernet + memcpy(out, Wifi::GetMAC(), 6); out += 6; // hurf + memcpy(out, kServerMAC, 6); out += 6; + *(u16*)out = htons(0x0800); out += 2; + + // IP + u8* resp_ipheader = out; + *out++ = 0x45; + *out++ = 0x00; + *(u16*)out = 0; out += 2; // total length + *(u16*)out = htons(IPv4ID); out += 2; IPv4ID++; + *out++ = 0x00; + *out++ = 0x00; + *out++ = 0x80; // TTL + *out++ = 0x06; // protocol (TCP) + *(u16*)out = 0; out += 2; // checksum + memcpy(out, sock->DestIP, 4); out += 4; // source IP + *(u32*)out = htonl(kClientIP); out += 4; // destination IP + + // TCP + u8* resp_tcpheader = out; + *(u16*)out = htons(sock->DestPort); out += 2; // source port + *(u16*)out = htons(sock->SourcePort); out += 2; // destination port + *(u32*)out = htonl(sock->SeqNum); out += 4; // seq number + *(u32*)out = htonl(sock->AckNum); out += 4; // ack seq number + *(u16*)out = htons(0x5018); out += 2; // flags (ACK, PSH) + *(u16*)out = htons(0x7000); out += 2; // window size (uuuh) + *(u16*)out = 0; out += 2; // checksum + *(u16*)out = 0; out += 2; // urgent pointer + + memcpy(out, data, len); out += len; + + u32 framelen = (u32)(out - &resp[0]); + FinishTCPFrame(resp, framelen); + + // TODO: if there is already a packet queued, this will overwrite it + // that being said, this will only happen during DHCP setup, so probably + // not a big deal + + PacketLen = framelen; + memcpy(PacketBuffer, resp, PacketLen); + RXNum = 1; + + sock->SeqNum += len; +} + +void HandleTCPFrame(u8* data, int len) +{ + u8* ipheader = &data[0xE]; + u8* tcpheader = &data[0x22]; + + u16 srcport = ntohs(*(u16*)&tcpheader[0]); + u16 dstport = ntohs(*(u16*)&tcpheader[2]); + u16 flags = ntohs(*(u16*)&tcpheader[12]); + + u32 tcpheaderlen = 4 * (flags >> 12); + u32 tcplen = ntohs(*(u16*)&ipheader[2]) - 0x14; + u32 tcpdatalen = tcplen - tcpheaderlen; + + /*printf("tcpflags=%04X header=%d data=%d seq=%08X|%08X\n", + flags, tcpheaderlen, tcpdatalen, + ntohl(*(u32*)&tcpheader[4]), + ntohl(*(u32*)&tcpheader[8]));*/ + + if (flags & 0x002) // SYN + { + int sockid = -1; + TCPSocket* sock; + for (int i = 0; i < (sizeof(TCPSocketList)/sizeof(TCPSocket)); i++) + { + sock = &TCPSocketList[i]; + if (sock->Status != 0 && !memcmp(&sock->DestIP, &ipheader[16], 4) && + sock->SourcePort == srcport && sock->DestPort == dstport) + { + printf("LANMAGIC: duplicate TCP socket\n"); + sockid = i; + break; + } + } + + if (sockid == -1) + { + for (int i = 0; i < (sizeof(TCPSocketList)/sizeof(TCPSocket)); i++) + { + sock = &TCPSocketList[i]; + if (sock->Status == 0) + { + sockid = i; + break; + } + } + } + + if (sockid == -1) + { + printf("LANMAGIC: !! TCP SOCKET LIST FULL\n"); + return; + } + + printf("LANMAGIC: opening TCP socket #%d to %d.%d.%d.%d:%d, srcport %d\n", + sockid, + ipheader[16], ipheader[17], ipheader[18], ipheader[19], + dstport, srcport); + + // keep track of it + sock->Status = 1; + memcpy(sock->DestIP, &ipheader[16], 4); + sock->DestPort = dstport; + sock->SourcePort = srcport; + sock->SeqNum = 0x13370000; + sock->AckNum = 0; + + // open backend socket + if (!sock->Backend) + { + sock->Backend = socket(AF_INET, SOCK_STREAM, 0); + } + + struct sockaddr_in conn_addr; + memset(&conn_addr, 0, sizeof(conn_addr)); + conn_addr.sin_family = AF_INET; + memcpy(&conn_addr.sin_addr, &ipheader[16], 4); + conn_addr.sin_port = htons(dstport); + if (connect(sock->Backend, (sockaddr*)&conn_addr, sizeof(conn_addr)) == -1) + { + printf("connect() shat itself :(\n"); + } + else + { + // acknowledge it + TCP_SYNACK(sock, data, len); + } + } + else + { + int sockid = -1; + TCPSocket* sock; + for (int i = 0; i < (sizeof(TCPSocketList)/sizeof(TCPSocket)); i++) + { + sock = &TCPSocketList[i]; + if (sock->Status != 0 && !memcmp(&sock->DestIP, &ipheader[16], 4) && + sock->SourcePort == srcport && sock->DestPort == dstport) + { + sockid = i; + break; + } + } + + if (sockid == -1) + { + printf("LANMAGIC: bad TCP packet\n"); + return; + } + + // TODO: check those + u32 seqnum = ntohl(*(u32*)&tcpheader[4]); + u32 acknum = ntohl(*(u32*)&tcpheader[8]); + sock->SeqNum = acknum; + sock->AckNum = seqnum + tcpdatalen; + + // send data over the socket + if (tcpdatalen > 0) + { + u8* tcpdata = &tcpheader[tcpheaderlen]; + + printf("TCP: socket %d sending %d bytes (flags=%04X)\n", sockid, tcpdatalen, flags); + send(sock->Backend, (char*)tcpdata, tcpdatalen, 0); + + // kind of a hack, there + TCP_ACK(sock, false); + } + + if (flags & 0x001) // FIN + { + // TODO: timeout etc + printf("TCP: socket %d closing\n", sockid); + + sock->Status = 0; + closesocket(sock->Backend); + sock->Backend = 0; + } + } +} + +void HandleARPFrame(u8* data, int len) +{ + u16 protocol = ntohs(*(u16*)&data[0x10]); + if (protocol != 0x0800) return; + + u16 op = ntohs(*(u16*)&data[0x14]); + u32 targetip = ntohl(*(u32*)&data[0x26]); + + // TODO: handle ARP to the client + // this only handles ARP to the DHCP/router + + if (op == 1) + { + // opcode 1=req 2=reply + // sender MAC + // sender IP + // target MAC + // target IP + + const u8* targetmac; + if (targetip == kServerIP) targetmac = kServerMAC; + else if (targetip == kDNSIP) targetmac = kDNSMAC; + else return; + + u8 resp[64]; + u8* out = &resp[0]; + + // ethernet + memcpy(out, &data[6], 6); out += 6; + memcpy(out, kServerMAC, 6); out += 6; + *(u16*)out = htons(0x0806); out += 2; + + // ARP + *(u16*)out = htons(0x0001); out += 2; // hardware type + *(u16*)out = htons(0x0800); out += 2; // protocol + *out++ = 6; // MAC address size + *out++ = 4; // IP address size + *(u16*)out = htons(0x0002); out += 2; // opcode + memcpy(out, targetmac, 6); out += 6; + *(u32*)out = htonl(targetip); out += 4; + memcpy(out, &data[0x16], 6+4); out += 6+4; + + u32 framelen = (u32)(out - &resp[0]); + + // TODO: if there is already a packet queued, this will overwrite it + // that being said, this will only happen during DHCP setup, so probably + // not a big deal + + PacketLen = framelen; + memcpy(PacketBuffer, resp, PacketLen); + RXNum = 1; + } + else + { + printf("wat??\n"); + } +} + +void HandlePacket(u8* data, int len) +{ + u16 ethertype = ntohs(*(u16*)&data[0xC]); + + if (ethertype == 0x0800) // IPv4 + { + u8 protocol = data[0x17]; + if (protocol == 0x11) // UDP + { + u16 srcport = ntohs(*(u16*)&data[0x22]); + u16 dstport = ntohs(*(u16*)&data[0x24]); + if (srcport == 68 && dstport == 67) // DHCP + { + printf("LANMAGIC: DHCP packet\n"); + return HandleDHCPFrame(data, len); + } + else if (dstport == 53 && htonl(*(u32*)&data[0x1E]) == kDNSIP) // DNS + { + printf("LANMAGIC: DNS packet\n"); + return HandleDNSFrame(data, len); + } + + printf("LANMAGIC: UDP packet %d->%d\n", srcport, dstport); + return HandleUDPFrame(data, len); + } + else if (protocol == 0x06) // TCP + { + printf("LANMAGIC: TCP packet\n"); + return HandleTCPFrame(data, len); + } + else + printf("LANMAGIC: unsupported IP protocol %02X\n", protocol); + } + else if (ethertype == 0x0806) // ARP + { + printf("LANMAGIC: ARP packet\n"); + return HandleARPFrame(data, len); + } + else + printf("LANMAGIC: unsupported ethernet type %04X\n", ethertype); +} + +int SendPacket(u8* data, int len) +{ + if (len > 2048) + { + printf("LAN_SendPacket: error: packet too long (%d)\n", len); + return 0; + } + + HandlePacket(data, len); + return len; +} + +int RecvPacket(u8* data) +{ + int ret = 0; + if (RXNum > 0) + { + memcpy(data, PacketBuffer, PacketLen); + ret = PacketLen; + RXNum = 0; + } + + for (int i = 0; i < (sizeof(TCPSocketList)/sizeof(TCPSocket)); i++) + { + TCPSocket* sock = &TCPSocketList[i]; + if (sock->Status != 1) continue; + + fd_set fd; + struct timeval tv; + + FD_ZERO(&fd); + FD_SET(sock->Backend, &fd); + tv.tv_sec = 0; + tv.tv_usec = 0; + + if (!select(sock->Backend+1, &fd, 0, 0, &tv)) + { + continue; + } + + u8 recvbuf[1024]; + int recvlen = recv(sock->Backend, (char*)recvbuf, 1024, 0); + if (recvlen < 1) + { + if (recvlen == 0) + { + // socket has closed from the other side + printf("TCP: socket %d closed from other side\n", i); + sock->Status = 2; + TCP_ACK(sock, true); + } + continue; + } + + printf("TCP: socket %d receiving %d bytes\n", i, recvlen); + TCP_BuildIncomingFrame(sock, recvbuf, recvlen); + + // debug + /*for (int j = 0; j < recvlen; j += 16) + { + int rem = recvlen - j; + if (rem > 16) rem = 16; + for (int k = 0; k < rem; k++) + { + printf("%02X ", recvbuf[k+j]); + } + printf("\n"); + }*/ + + //recvlen = recv(sock->Backend, (char*)recvbuf, 1024, 0); + //if (recvlen == 0) printf("it closed immediately after\n"); + } + + for (int i = 0; i < (sizeof(UDPSocketList)/sizeof(UDPSocket)); i++) + { + UDPSocket* sock = &UDPSocketList[i]; + if (sock->Backend == 0) continue; + + fd_set fd; + struct timeval tv; + + FD_ZERO(&fd); + FD_SET(sock->Backend, &fd); + tv.tv_sec = 0; + tv.tv_usec = 0; + + if (!select(sock->Backend+1, &fd, 0, 0, &tv)) + { + continue; + } + + u8 recvbuf[1024]; + sockaddr_t fromAddr; + socklen_t fromLen = sizeof(sockaddr_t); + int recvlen = recvfrom(sock->Backend, (char*)recvbuf, 1024, 0, &fromAddr, &fromLen); + if (recvlen < 1) continue; + + if (fromAddr.sa_family != AF_INET) continue; + struct sockaddr_in* fromAddrIn = (struct sockaddr_in*)&fromAddr; + if (memcmp(&fromAddrIn->sin_addr, sock->DestIP, 4)) continue; + if (ntohs(fromAddrIn->sin_port) != sock->DestPort) continue; + + printf("UDP: socket %d receiving %d bytes\n", i, recvlen); + UDP_BuildIncomingFrame(sock, recvbuf, recvlen); + } + + return ret; +} + +} diff --git a/src/frontend/qt_sdl/LAN_Socket.h b/src/frontend/qt_sdl/LAN_Socket.h new file mode 100644 index 0000000..8453a5f --- /dev/null +++ b/src/frontend/qt_sdl/LAN_Socket.h @@ -0,0 +1,38 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef LAN_SOCKET_H +#define LAN_SOCKET_H + +#include "../types.h" + +namespace LAN_Socket +{ + +// + + +bool Init(); +void DeInit(); + +int SendPacket(u8* data, int len); +int RecvPacket(u8* data); + +} + +#endif // LAN_SOCKET_H diff --git a/src/frontend/qt_sdl/WifiSettingsDialog.ui b/src/frontend/qt_sdl/WifiSettingsDialog.ui new file mode 100644 index 0000000..bfee1fd --- /dev/null +++ b/src/frontend/qt_sdl/WifiSettingsDialog.ui @@ -0,0 +1,165 @@ + + + WifiSettingsDialog + + + + 0 + 0 + 479 + 217 + + + + + 0 + 0 + + + + Wifi settings - melonDS + + + + QLayout::SetFixedSize + + + + + Local + + + + + + <html><head/><body><p>Enabling this allows (theoretically) playing local multiplayer games over a local network. It may or may not help make for a better connection in general.</p></body></html> + + + Bind socket to any address + + + + + + + + + + Online + + + + + + MAC address: + + + + + + + <html><head/><body><p>Direct mode directly routes network traffic to the host network. It is the most reliable, but requires an ethernet connection.</p><p><br/></p><p>Non-direct mode uses a layer of emulation to get around this, but is more prone to problems.</p></body></html> + + + Direct mode [TEXT PLACEHOLDER] + + + + + + + + 0 + 0 + + + + + 350 + 0 + + + + <html><head/><body><p>Selects the network adapter through which to route network traffic under direct mode.</p></body></html> + + + + + + + Network adapter: + + + + + + + IP address: + + + + + + + [PLACEHOLDER] + + + + + + + [PLACEHOLDER] + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + WifiSettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + WifiSettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/frontend/qt_sdl/pcap/bluetooth.h b/src/frontend/qt_sdl/pcap/bluetooth.h new file mode 100644 index 0000000..15dc5a8 --- /dev/null +++ b/src/frontend/qt_sdl/pcap/bluetooth.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2006 Paolo Abeni (Italy) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * bluetooth data struct + * By Paolo Abeni + */ + +#ifndef lib_pcap_bluetooth_h +#define lib_pcap_bluetooth_h + +#include + +/* + * Header prepended libpcap to each bluetooth h4 frame, + * fields are in network byte order + */ +typedef struct _pcap_bluetooth_h4_header { + uint32_t direction; /* if first bit is set direction is incoming */ +} pcap_bluetooth_h4_header; + +/* + * Header prepended libpcap to each bluetooth linux monitor frame, + * fields are in network byte order + */ +typedef struct _pcap_bluetooth_linux_monitor_header { + uint16_t adapter_id; + uint16_t opcode; +} pcap_bluetooth_linux_monitor_header; + +#endif diff --git a/src/frontend/qt_sdl/pcap/bpf.h b/src/frontend/qt_sdl/pcap/bpf.h new file mode 100644 index 0000000..1a953a9 --- /dev/null +++ b/src/frontend/qt_sdl/pcap/bpf.h @@ -0,0 +1,270 @@ +/*- + * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from the Stanford/CMU enet packet filter, + * (net/enet.c) distributed as part of 4.3BSD, and code contributed + * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence + * Berkeley Laboratory. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)bpf.h 7.1 (Berkeley) 5/7/91 + */ + +/* + * This is libpcap's cut-down version of bpf.h; it includes only + * the stuff needed for the code generator and the userland BPF + * interpreter, and the libpcap APIs for setting filters, etc.. + * + * "pcap-bpf.c" will include the native OS version, as it deals with + * the OS's BPF implementation. + * + * At least two programs found by Google Code Search explicitly includes + * (even though / includes it for you), + * so moving that stuff to would break the build for some + * programs. + */ + +/* + * If we've already included , don't re-define this stuff. + * We assume BSD-style multiple-include protection in , + * which is true of all but the oldest versions of FreeBSD and NetBSD, + * or Tru64 UNIX-style multiple-include protection (or, at least, + * Tru64 UNIX 5.x-style; I don't have earlier versions available to check), + * or AIX-style multiple-include protection (or, at least, AIX 5.x-style; + * I don't have earlier versions available to check), or QNX-style + * multiple-include protection (as per GitHub pull request #394). + * + * We do not check for BPF_MAJOR_VERSION, as that's defined by + * , which is directly or indirectly included in some + * programs that also include pcap.h, and doesn't + * define stuff we need. + * + * This also provides our own multiple-include protection. + */ +#if !defined(_NET_BPF_H_) && !defined(_NET_BPF_H_INCLUDED) && !defined(_BPF_H_) && !defined(_H_BPF) && !defined(lib_pcap_bpf_h) +#define lib_pcap_bpf_h + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* BSD style release date */ +#define BPF_RELEASE 199606 + +#ifdef MSDOS /* must be 32-bit */ +typedef long bpf_int32; +typedef unsigned long bpf_u_int32; +#else +typedef int bpf_int32; +typedef u_int bpf_u_int32; +#endif + +/* + * Alignment macros. BPF_WORDALIGN rounds up to the next + * even multiple of BPF_ALIGNMENT. + * + * Tcpdump's print-pflog.c uses this, so we define it here. + */ +#ifndef __NetBSD__ +#define BPF_ALIGNMENT sizeof(bpf_int32) +#else +#define BPF_ALIGNMENT sizeof(long) +#endif +#define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1)) + +/* + * Structure for "pcap_compile()", "pcap_setfilter()", etc.. + */ +struct bpf_program { + u_int bf_len; + struct bpf_insn *bf_insns; +}; + +#include + +/* + * The instruction encodings. + * + * Please inform tcpdump-workers@lists.tcpdump.org if you use any + * of the reserved values, so that we can note that they're used + * (and perhaps implement it in the reference BPF implementation + * and encourage its implementation elsewhere). + */ + +/* + * The upper 8 bits of the opcode aren't used. BSD/OS used 0x8000. + */ + +/* instruction classes */ +#define BPF_CLASS(code) ((code) & 0x07) +#define BPF_LD 0x00 +#define BPF_LDX 0x01 +#define BPF_ST 0x02 +#define BPF_STX 0x03 +#define BPF_ALU 0x04 +#define BPF_JMP 0x05 +#define BPF_RET 0x06 +#define BPF_MISC 0x07 + +/* ld/ldx fields */ +#define BPF_SIZE(code) ((code) & 0x18) +#define BPF_W 0x00 +#define BPF_H 0x08 +#define BPF_B 0x10 +/* 0x18 reserved; used by BSD/OS */ +#define BPF_MODE(code) ((code) & 0xe0) +#define BPF_IMM 0x00 +#define BPF_ABS 0x20 +#define BPF_IND 0x40 +#define BPF_MEM 0x60 +#define BPF_LEN 0x80 +#define BPF_MSH 0xa0 +/* 0xc0 reserved; used by BSD/OS */ +/* 0xe0 reserved; used by BSD/OS */ + +/* alu/jmp fields */ +#define BPF_OP(code) ((code) & 0xf0) +#define BPF_ADD 0x00 +#define BPF_SUB 0x10 +#define BPF_MUL 0x20 +#define BPF_DIV 0x30 +#define BPF_OR 0x40 +#define BPF_AND 0x50 +#define BPF_LSH 0x60 +#define BPF_RSH 0x70 +#define BPF_NEG 0x80 +#define BPF_MOD 0x90 +#define BPF_XOR 0xa0 +/* 0xb0 reserved */ +/* 0xc0 reserved */ +/* 0xd0 reserved */ +/* 0xe0 reserved */ +/* 0xf0 reserved */ + +#define BPF_JA 0x00 +#define BPF_JEQ 0x10 +#define BPF_JGT 0x20 +#define BPF_JGE 0x30 +#define BPF_JSET 0x40 +/* 0x50 reserved; used on BSD/OS */ +/* 0x60 reserved */ +/* 0x70 reserved */ +/* 0x80 reserved */ +/* 0x90 reserved */ +/* 0xa0 reserved */ +/* 0xb0 reserved */ +/* 0xc0 reserved */ +/* 0xd0 reserved */ +/* 0xe0 reserved */ +/* 0xf0 reserved */ +#define BPF_SRC(code) ((code) & 0x08) +#define BPF_K 0x00 +#define BPF_X 0x08 + +/* ret - BPF_K and BPF_X also apply */ +#define BPF_RVAL(code) ((code) & 0x18) +#define BPF_A 0x10 +/* 0x18 reserved */ + +/* misc */ +#define BPF_MISCOP(code) ((code) & 0xf8) +#define BPF_TAX 0x00 +/* 0x08 reserved */ +/* 0x10 reserved */ +/* 0x18 reserved */ +/* #define BPF_COP 0x20 NetBSD "coprocessor" extensions */ +/* 0x28 reserved */ +/* 0x30 reserved */ +/* 0x38 reserved */ +/* #define BPF_COPX 0x40 NetBSD "coprocessor" extensions */ +/* also used on BSD/OS */ +/* 0x48 reserved */ +/* 0x50 reserved */ +/* 0x58 reserved */ +/* 0x60 reserved */ +/* 0x68 reserved */ +/* 0x70 reserved */ +/* 0x78 reserved */ +#define BPF_TXA 0x80 +/* 0x88 reserved */ +/* 0x90 reserved */ +/* 0x98 reserved */ +/* 0xa0 reserved */ +/* 0xa8 reserved */ +/* 0xb0 reserved */ +/* 0xb8 reserved */ +/* 0xc0 reserved; used on BSD/OS */ +/* 0xc8 reserved */ +/* 0xd0 reserved */ +/* 0xd8 reserved */ +/* 0xe0 reserved */ +/* 0xe8 reserved */ +/* 0xf0 reserved */ +/* 0xf8 reserved */ + +/* + * The instruction data structure. + */ +struct bpf_insn { + u_short code; + u_char jt; + u_char jf; + bpf_u_int32 k; +}; + +/* + * Auxiliary data, for use when interpreting a filter intended for the + * Linux kernel when the kernel rejects the filter (requiring us to + * run it in userland). It contains VLAN tag information. + */ +struct bpf_aux_data { + u_short vlan_tag_present; + u_short vlan_tag; +}; + +/* + * Macros for insn array initializers. + */ +#define BPF_STMT(code, k) { (u_short)(code), 0, 0, k } +#define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k } + +PCAP_API int bpf_validate(const struct bpf_insn *, int); +PCAP_API u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int); +extern u_int bpf_filter_with_aux_data(const struct bpf_insn *, const u_char *, u_int, u_int, const struct bpf_aux_data *); + +/* + * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST). + */ +#define BPF_MEMWORDS 16 + +#ifdef __cplusplus +} +#endif + +#endif /* !defined(_NET_BPF_H_) && !defined(_BPF_H_) && !defined(_H_BPF) && !defined(lib_pcap_bpf_h) */ diff --git a/src/frontend/qt_sdl/pcap/can_socketcan.h b/src/frontend/qt_sdl/pcap/can_socketcan.h new file mode 100644 index 0000000..332d9ff --- /dev/null +++ b/src/frontend/qt_sdl/pcap/can_socketcan.h @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from the Stanford/CMU enet packet filter, + * (net/enet.c) distributed as part of 4.3BSD, and code contributed + * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence + * Berkeley Laboratory. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lib_pcap_can_socketcan_h +#define lib_pcap_can_socketcan_h + +#include + +/* + * SocketCAN header, as per Documentation/networking/can.txt in the + * Linux source. + */ +typedef struct { + uint32_t can_id; + uint8_t payload_length; + uint8_t pad; + uint8_t reserved1; + uint8_t reserved2; +} pcap_can_socketcan_hdr; + +#endif diff --git a/src/frontend/qt_sdl/pcap/compiler-tests.h b/src/frontend/qt_sdl/pcap/compiler-tests.h new file mode 100644 index 0000000..8876c67 --- /dev/null +++ b/src/frontend/qt_sdl/pcap/compiler-tests.h @@ -0,0 +1,152 @@ +/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */ +/* + * Copyright (c) 1993, 1994, 1995, 1996, 1997 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Computer Systems + * Engineering Group at Lawrence Berkeley Laboratory. + * 4. Neither the name of the University nor of the Laboratory may be used + * to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lib_pcap_compiler_tests_h +#define lib_pcap_compiler_tests_h + + +/* + * This was introduced by Clang: + * + * http://clang.llvm.org/docs/LanguageExtensions.html#has-attribute + * + * in some version (which version?); it has been picked up by GCC 5.0. + */ +#ifndef __has_attribute + /* + * It's a macro, so you can check whether it's defined to check + * whether it's supported. + * + * If it's not, define it to always return 0, so that we move on to + * the fallback checks. + */ + #define __has_attribute(x) 0 +#endif + +/* + * Note that the C90 spec's "6.8.1 Conditional inclusion" and the + * C99 spec's and C11 spec's "6.10.1 Conditional inclusion" say: + * + * Prior to evaluation, macro invocations in the list of preprocessing + * tokens that will become the controlling constant expression are + * replaced (except for those macro names modified by the defined unary + * operator), just as in normal text. If the token "defined" is + * generated as a result of this replacement process or use of the + * "defined" unary operator does not match one of the two specified + * forms prior to macro replacement, the behavior is undefined. + * + * so you shouldn't use defined() in a #define that's used in #if or + * #elif. Some versions of Clang, for example, will warn about this. + * + * Instead, we check whether the pre-defined macros for particular + * compilers are defined and, if not, define the "is this version XXX + * or a later version of this compiler" macros as 0. + */ + +/* + * Check whether this is GCC major.minor or a later release, or some + * compiler that claims to be "just like GCC" of that version or a + * later release. + */ + +#if ! defined(__GNUC__) +#define PCAP_IS_AT_LEAST_GNUC_VERSION(major, minor) 0 +#else +#define PCAP_IS_AT_LEAST_GNUC_VERSION(major, minor) \ + (__GNUC__ > (major) || \ + (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) +#endif + +/* + * Check whether this is Sun C/SunPro C/Oracle Studio major.minor + * or a later release. + * + * The version number in __SUNPRO_C is encoded in hex BCD, with the + * uppermost hex digit being the major version number, the next + * one or two hex digits being the minor version number, and + * the last digit being the patch version. + * + * It represents the *compiler* version, not the product version; + * see + * + * https://sourceforge.net/p/predef/wiki/Compilers/ + * + * for a partial mapping, which we assume continues for later + * 12.x product releases. + */ + +#if ! defined(__SUNPRO_C) +#define PCAP_IS_AT_LEAST_SUNC_VERSION(major,minor) 0 +#else +#define PCAP_SUNPRO_VERSION_TO_BCD(major, minor) \ + (((minor) >= 10) ? \ + (((major) << 12) | (((minor)/10) << 8) | (((minor)%10) << 4)) : \ + (((major) << 8) | ((minor) << 4))) +#define PCAP_IS_AT_LEAST_SUNC_VERSION(major,minor) \ + (__SUNPRO_C >= PCAP_SUNPRO_VERSION_TO_BCD((major), (minor))) +#endif + +/* + * Check whether this is IBM XL C major.minor or a later release. + * + * The version number in __xlC__ has the major version in the + * upper 8 bits and the minor version in the lower 8 bits. + */ + +#if ! defined(__xlC__) +#define PCAP_IS_AT_LEAST_XL_C_VERSION(major,minor) 0 +#else +#define PCAP_IS_AT_LEAST_XL_C_VERSION(major, minor) \ + (__xlC__ >= (((major) << 8) | (minor))) +#endif + +/* + * Check whether this is HP aC++/HP C major.minor or a later release. + * + * The version number in __HP_aCC is encoded in zero-padded decimal BCD, + * with the "A." stripped off, the uppermost two decimal digits being + * the major version number, the next two decimal digits being the minor + * version number, and the last two decimal digits being the patch version. + * (Strip off the A., remove the . between the major and minor version + * number, and add two digits of patch.) + */ + +#if ! defined(__HP_aCC) +#define PCAP_IS_AT_LEAST_HP_C_VERSION(major,minor) 0 +#else +#define PCAP_IS_AT_LEAST_HP_C_VERSION(major,minor) \ + (__HP_aCC >= ((major)*10000 + (minor)*100)) +#endif + +#endif /* lib_pcap_funcattrs_h */ diff --git a/src/frontend/qt_sdl/pcap/dlt.h b/src/frontend/qt_sdl/pcap/dlt.h new file mode 100644 index 0000000..609bcaf --- /dev/null +++ b/src/frontend/qt_sdl/pcap/dlt.h @@ -0,0 +1,1389 @@ +/*- + * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from the Stanford/CMU enet packet filter, + * (net/enet.c) distributed as part of 4.3BSD, and code contributed + * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence + * Berkeley Laboratory. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)bpf.h 7.1 (Berkeley) 5/7/91 + */ + +#ifndef lib_pcap_dlt_h +#define lib_pcap_dlt_h + +/* + * Link-layer header type codes. + * + * Do *NOT* add new values to this list without asking + * "tcpdump-workers@lists.tcpdump.org" for a value. Otherwise, you run + * the risk of using a value that's already being used for some other + * purpose, and of having tools that read libpcap-format captures not + * being able to handle captures with your new DLT_ value, with no hope + * that they will ever be changed to do so (as that would destroy their + * ability to read captures using that value for that other purpose). + * + * See + * + * http://www.tcpdump.org/linktypes.html + * + * for detailed descriptions of some of these link-layer header types. + */ + +/* + * These are the types that are the same on all platforms, and that + * have been defined by for ages. + */ +#define DLT_NULL 0 /* BSD loopback encapsulation */ +#define DLT_EN10MB 1 /* Ethernet (10Mb) */ +#define DLT_EN3MB 2 /* Experimental Ethernet (3Mb) */ +#define DLT_AX25 3 /* Amateur Radio AX.25 */ +#define DLT_PRONET 4 /* Proteon ProNET Token Ring */ +#define DLT_CHAOS 5 /* Chaos */ +#define DLT_IEEE802 6 /* 802.5 Token Ring */ +#define DLT_ARCNET 7 /* ARCNET, with BSD-style header */ +#define DLT_SLIP 8 /* Serial Line IP */ +#define DLT_PPP 9 /* Point-to-point Protocol */ +#define DLT_FDDI 10 /* FDDI */ + +/* + * These are types that are different on some platforms, and that + * have been defined by for ages. We use #ifdefs to + * detect the BSDs that define them differently from the traditional + * libpcap + * + * XXX - DLT_ATM_RFC1483 is 13 in BSD/OS, and DLT_RAW is 14 in BSD/OS, + * but I don't know what the right #define is for BSD/OS. + */ +#define DLT_ATM_RFC1483 11 /* LLC-encapsulated ATM */ + +#ifdef __OpenBSD__ +#define DLT_RAW 14 /* raw IP */ +#else +#define DLT_RAW 12 /* raw IP */ +#endif + +/* + * Given that the only OS that currently generates BSD/OS SLIP or PPP + * is, well, BSD/OS, arguably everybody should have chosen its values + * for DLT_SLIP_BSDOS and DLT_PPP_BSDOS, which are 15 and 16, but they + * didn't. So it goes. + */ +#if defined(__NetBSD__) || defined(__FreeBSD__) +#ifndef DLT_SLIP_BSDOS +#define DLT_SLIP_BSDOS 13 /* BSD/OS Serial Line IP */ +#define DLT_PPP_BSDOS 14 /* BSD/OS Point-to-point Protocol */ +#endif +#else +#define DLT_SLIP_BSDOS 15 /* BSD/OS Serial Line IP */ +#define DLT_PPP_BSDOS 16 /* BSD/OS Point-to-point Protocol */ +#endif + +/* + * 17 was used for DLT_PFLOG in OpenBSD; it no longer is. + * + * It was DLT_LANE8023 in SuSE 6.3, so we defined LINKTYPE_PFLOG + * as 117 so that pflog captures would use a link-layer header type + * value that didn't collide with any other values. On all + * platforms other than OpenBSD, we defined DLT_PFLOG as 117, + * and we mapped between LINKTYPE_PFLOG and DLT_PFLOG. + * + * OpenBSD eventually switched to using 117 for DLT_PFLOG as well. + * + * Don't use 17 for anything else. + */ + +/* + * 18 is used for DLT_PFSYNC in OpenBSD, NetBSD, DragonFly BSD and + * Mac OS X; don't use it for anything else. (FreeBSD uses 121, + * which collides with DLT_HHDLC, even though it doesn't use 18 + * for anything and doesn't appear to have ever used it for anything.) + * + * We define it as 18 on those platforms; it is, unfortunately, used + * for DLT_CIP in Suse 6.3, so we don't define it as DLT_PFSYNC + * in general. As the packet format for it, like that for + * DLT_PFLOG, is not only OS-dependent but OS-version-dependent, + * we don't support printing it in tcpdump except on OSes that + * have the relevant header files, so it's not that useful on + * other platforms. + */ +#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__APPLE__) +#define DLT_PFSYNC 18 +#endif + +#define DLT_ATM_CLIP 19 /* Linux Classical-IP over ATM */ + +/* + * Apparently Redback uses this for its SmartEdge 400/800. I hope + * nobody else decided to use it, too. + */ +#define DLT_REDBACK_SMARTEDGE 32 + +/* + * These values are defined by NetBSD; other platforms should refrain from + * using them for other purposes, so that NetBSD savefiles with link + * types of 50 or 51 can be read as this type on all platforms. + */ +#define DLT_PPP_SERIAL 50 /* PPP over serial with HDLC encapsulation */ +#define DLT_PPP_ETHER 51 /* PPP over Ethernet */ + +/* + * The Axent Raptor firewall - now the Symantec Enterprise Firewall - uses + * a link-layer type of 99 for the tcpdump it supplies. The link-layer + * header has 6 bytes of unknown data, something that appears to be an + * Ethernet type, and 36 bytes that appear to be 0 in at least one capture + * I've seen. + */ +#define DLT_SYMANTEC_FIREWALL 99 + +/* + * Values between 100 and 103 are used in capture file headers as + * link-layer header type LINKTYPE_ values corresponding to DLT_ types + * that differ between platforms; don't use those values for new DLT_ + * new types. + */ + +/* + * Values starting with 104 are used for newly-assigned link-layer + * header type values; for those link-layer header types, the DLT_ + * value returned by pcap_datalink() and passed to pcap_open_dead(), + * and the LINKTYPE_ value that appears in capture files, are the + * same. + * + * DLT_MATCHING_MIN is the lowest such value; DLT_MATCHING_MAX is + * the highest such value. + */ +#define DLT_MATCHING_MIN 104 + +/* + * This value was defined by libpcap 0.5; platforms that have defined + * it with a different value should define it here with that value - + * a link type of 104 in a save file will be mapped to DLT_C_HDLC, + * whatever value that happens to be, so programs will correctly + * handle files with that link type regardless of the value of + * DLT_C_HDLC. + * + * The name DLT_C_HDLC was used by BSD/OS; we use that name for source + * compatibility with programs written for BSD/OS. + * + * libpcap 0.5 defined it as DLT_CHDLC; we define DLT_CHDLC as well, + * for source compatibility with programs written for libpcap 0.5. + */ +#define DLT_C_HDLC 104 /* Cisco HDLC */ +#define DLT_CHDLC DLT_C_HDLC + +#define DLT_IEEE802_11 105 /* IEEE 802.11 wireless */ + +/* + * 106 is reserved for Linux Classical IP over ATM; it's like DLT_RAW, + * except when it isn't. (I.e., sometimes it's just raw IP, and + * sometimes it isn't.) We currently handle it as DLT_LINUX_SLL, + * so that we don't have to worry about the link-layer header.) + */ + +/* + * Frame Relay; BSD/OS has a DLT_FR with a value of 11, but that collides + * with other values. + * DLT_FR and DLT_FRELAY packets start with the Q.922 Frame Relay header + * (DLCI, etc.). + */ +#define DLT_FRELAY 107 + +/* + * OpenBSD DLT_LOOP, for loopback devices; it's like DLT_NULL, except + * that the AF_ type in the link-layer header is in network byte order. + * + * DLT_LOOP is 12 in OpenBSD, but that's DLT_RAW in other OSes, so + * we don't use 12 for it in OSes other than OpenBSD. + */ +#ifdef __OpenBSD__ +#define DLT_LOOP 12 +#else +#define DLT_LOOP 108 +#endif + +/* + * Encapsulated packets for IPsec; DLT_ENC is 13 in OpenBSD, but that's + * DLT_SLIP_BSDOS in NetBSD, so we don't use 13 for it in OSes other + * than OpenBSD. + */ +#ifdef __OpenBSD__ +#define DLT_ENC 13 +#else +#define DLT_ENC 109 +#endif + +/* + * Values between 110 and 112 are reserved for use in capture file headers + * as link-layer types corresponding to DLT_ types that might differ + * between platforms; don't use those values for new DLT_ types + * other than the corresponding DLT_ types. + */ + +/* + * This is for Linux cooked sockets. + */ +#define DLT_LINUX_SLL 113 + +/* + * Apple LocalTalk hardware. + */ +#define DLT_LTALK 114 + +/* + * Acorn Econet. + */ +#define DLT_ECONET 115 + +/* + * Reserved for use with OpenBSD ipfilter. + */ +#define DLT_IPFILTER 116 + +/* + * OpenBSD DLT_PFLOG. + */ +#define DLT_PFLOG 117 + +/* + * Registered for Cisco-internal use. + */ +#define DLT_CISCO_IOS 118 + +/* + * For 802.11 cards using the Prism II chips, with a link-layer + * header including Prism monitor mode information plus an 802.11 + * header. + */ +#define DLT_PRISM_HEADER 119 + +/* + * Reserved for Aironet 802.11 cards, with an Aironet link-layer header + * (see Doug Ambrisko's FreeBSD patches). + */ +#define DLT_AIRONET_HEADER 120 + +/* + * Sigh. + * + * 121 was reserved for Siemens HiPath HDLC on 2002-01-25, as + * requested by Tomas Kukosa. + * + * On 2004-02-25, a FreeBSD checkin to sys/net/bpf.h was made that + * assigned 121 as DLT_PFSYNC. In current versions, its libpcap + * does DLT_ <-> LINKTYPE_ mapping, mapping DLT_PFSYNC to a + * LINKTYPE_PFSYNC value of 246, so it should write out DLT_PFSYNC + * dump files with 246 as the link-layer header type. (Earlier + * versions might not have done mapping, in which case they would + * have written them out with a link-layer header type of 121.) + * + * OpenBSD, from which pf came, however, uses 18 for DLT_PFSYNC; + * its libpcap does no DLT_ <-> LINKTYPE_ mapping, so it would + * write out DLT_PFSYNC dump files with use 18 as the link-layer + * header type. + * + * NetBSD, DragonFly BSD, and Darwin also use 18 for DLT_PFSYNC; in + * current versions, their libpcaps do DLT_ <-> LINKTYPE_ mapping, + * mapping DLT_PFSYNC to a LINKTYPE_PFSYNC value of 246, so they + * should write out DLT_PFSYNC dump files with 246 as the link-layer + * header type. (Earlier versions might not have done mapping, + * in which case they'd work the same way OpenBSD does, writing + * them out with a link-layer header type of 18.) + * + * We'll define DLT_PFSYNC as: + * + * 18 on NetBSD, OpenBSD, DragonFly BSD, and Darwin; + * + * 121 on FreeBSD; + * + * 246 everywhere else. + * + * We'll define DLT_HHDLC as 121 on everything except for FreeBSD; + * anybody who wants to compile, on FreeBSD, code that uses DLT_HHDLC + * is out of luck. + * + * We'll define LINKTYPE_PFSYNC as 246 on *all* platforms, so that + * savefiles written using *this* code won't use 18 or 121 for PFSYNC, + * they'll all use 246. + * + * Code that uses pcap_datalink() to determine the link-layer header + * type of a savefile won't, when built and run on FreeBSD, be able + * to distinguish between LINKTYPE_PFSYNC and LINKTYPE_HHDLC capture + * files, as pcap_datalink() will give 121 for both of them. Code + * that doesn't, such as the code in Wireshark, will be able to + * distinguish between them. + * + * FreeBSD's libpcap won't map a link-layer header type of 18 - i.e., + * DLT_PFSYNC files from OpenBSD and possibly older versions of NetBSD, + * DragonFly BSD, and OS X - to DLT_PFSYNC, so code built with FreeBSD's + * libpcap won't treat those files as DLT_PFSYNC files. + * + * Other libpcaps won't map a link-layer header type of 121 to DLT_PFSYNC; + * this means they can read DLT_HHDLC files, if any exist, but won't + * treat pcap files written by any older versions of FreeBSD libpcap that + * didn't map to 246 as DLT_PFSYNC files. + */ +#ifdef __FreeBSD__ +#define DLT_PFSYNC 121 +#else +#define DLT_HHDLC 121 +#endif + +/* + * This is for RFC 2625 IP-over-Fibre Channel. + * + * This is not for use with raw Fibre Channel, where the link-layer + * header starts with a Fibre Channel frame header; it's for IP-over-FC, + * where the link-layer header starts with an RFC 2625 Network_Header + * field. + */ +#define DLT_IP_OVER_FC 122 + +/* + * This is for Full Frontal ATM on Solaris with SunATM, with a + * pseudo-header followed by an AALn PDU. + * + * There may be other forms of Full Frontal ATM on other OSes, + * with different pseudo-headers. + * + * If ATM software returns a pseudo-header with VPI/VCI information + * (and, ideally, packet type information, e.g. signalling, ILMI, + * LANE, LLC-multiplexed traffic, etc.), it should not use + * DLT_ATM_RFC1483, but should get a new DLT_ value, so tcpdump + * and the like don't have to infer the presence or absence of a + * pseudo-header and the form of the pseudo-header. + */ +#define DLT_SUNATM 123 /* Solaris+SunATM */ + +/* + * Reserved as per request from Kent Dahlgren + * for private use. + */ +#define DLT_RIO 124 /* RapidIO */ +#define DLT_PCI_EXP 125 /* PCI Express */ +#define DLT_AURORA 126 /* Xilinx Aurora link layer */ + +/* + * Header for 802.11 plus a number of bits of link-layer information + * including radio information, used by some recent BSD drivers as + * well as the madwifi Atheros driver for Linux. + */ +#define DLT_IEEE802_11_RADIO 127 /* 802.11 plus radiotap radio header */ + +/* + * Reserved for the TZSP encapsulation, as per request from + * Chris Waters + * TZSP is a generic encapsulation for any other link type, + * which includes a means to include meta-information + * with the packet, e.g. signal strength and channel + * for 802.11 packets. + */ +#define DLT_TZSP 128 /* Tazmen Sniffer Protocol */ + +/* + * BSD's ARCNET headers have the source host, destination host, + * and type at the beginning of the packet; that's what's handed + * up to userland via BPF. + * + * Linux's ARCNET headers, however, have a 2-byte offset field + * between the host IDs and the type; that's what's handed up + * to userland via PF_PACKET sockets. + * + * We therefore have to have separate DLT_ values for them. + */ +#define DLT_ARCNET_LINUX 129 /* ARCNET */ + +/* + * Juniper-private data link types, as per request from + * Hannes Gredler . The DLT_s are used + * for passing on chassis-internal metainformation such as + * QOS profiles, etc.. + */ +#define DLT_JUNIPER_MLPPP 130 +#define DLT_JUNIPER_MLFR 131 +#define DLT_JUNIPER_ES 132 +#define DLT_JUNIPER_GGSN 133 +#define DLT_JUNIPER_MFR 134 +#define DLT_JUNIPER_ATM2 135 +#define DLT_JUNIPER_SERVICES 136 +#define DLT_JUNIPER_ATM1 137 + +/* + * Apple IP-over-IEEE 1394, as per a request from Dieter Siegmund + * . The header that's presented is an Ethernet-like + * header: + * + * #define FIREWIRE_EUI64_LEN 8 + * struct firewire_header { + * u_char firewire_dhost[FIREWIRE_EUI64_LEN]; + * u_char firewire_shost[FIREWIRE_EUI64_LEN]; + * u_short firewire_type; + * }; + * + * with "firewire_type" being an Ethernet type value, rather than, + * for example, raw GASP frames being handed up. + */ +#define DLT_APPLE_IP_OVER_IEEE1394 138 + +/* + * Various SS7 encapsulations, as per a request from Jeff Morriss + * and subsequent discussions. + */ +#define DLT_MTP2_WITH_PHDR 139 /* pseudo-header with various info, followed by MTP2 */ +#define DLT_MTP2 140 /* MTP2, without pseudo-header */ +#define DLT_MTP3 141 /* MTP3, without pseudo-header or MTP2 */ +#define DLT_SCCP 142 /* SCCP, without pseudo-header or MTP2 or MTP3 */ + +/* + * DOCSIS MAC frames. + */ +#define DLT_DOCSIS 143 + +/* + * Linux-IrDA packets. Protocol defined at http://www.irda.org. + * Those packets include IrLAP headers and above (IrLMP...), but + * don't include Phy framing (SOF/EOF/CRC & byte stuffing), because Phy + * framing can be handled by the hardware and depend on the bitrate. + * This is exactly the format you would get capturing on a Linux-IrDA + * interface (irdaX), but not on a raw serial port. + * Note the capture is done in "Linux-cooked" mode, so each packet include + * a fake packet header (struct sll_header). This is because IrDA packet + * decoding is dependant on the direction of the packet (incomming or + * outgoing). + * When/if other platform implement IrDA capture, we may revisit the + * issue and define a real DLT_IRDA... + * Jean II + */ +#define DLT_LINUX_IRDA 144 + +/* + * Reserved for IBM SP switch and IBM Next Federation switch. + */ +#define DLT_IBM_SP 145 +#define DLT_IBM_SN 146 + +/* + * Reserved for private use. If you have some link-layer header type + * that you want to use within your organization, with the capture files + * using that link-layer header type not ever be sent outside your + * organization, you can use these values. + * + * No libpcap release will use these for any purpose, nor will any + * tcpdump release use them, either. + * + * Do *NOT* use these in capture files that you expect anybody not using + * your private versions of capture-file-reading tools to read; in + * particular, do *NOT* use them in products, otherwise you may find that + * people won't be able to use tcpdump, or snort, or Ethereal, or... to + * read capture files from your firewall/intrusion detection/traffic + * monitoring/etc. appliance, or whatever product uses that DLT_ value, + * and you may also find that the developers of those applications will + * not accept patches to let them read those files. + * + * Also, do not use them if somebody might send you a capture using them + * for *their* private type and tools using them for *your* private type + * would have to read them. + * + * Instead, ask "tcpdump-workers@lists.tcpdump.org" for a new DLT_ value, + * as per the comment above, and use the type you're given. + */ +#define DLT_USER0 147 +#define DLT_USER1 148 +#define DLT_USER2 149 +#define DLT_USER3 150 +#define DLT_USER4 151 +#define DLT_USER5 152 +#define DLT_USER6 153 +#define DLT_USER7 154 +#define DLT_USER8 155 +#define DLT_USER9 156 +#define DLT_USER10 157 +#define DLT_USER11 158 +#define DLT_USER12 159 +#define DLT_USER13 160 +#define DLT_USER14 161 +#define DLT_USER15 162 + +/* + * For future use with 802.11 captures - defined by AbsoluteValue + * Systems to store a number of bits of link-layer information + * including radio information: + * + * http://www.shaftnet.org/~pizza/software/capturefrm.txt + * + * but it might be used by some non-AVS drivers now or in the + * future. + */ +#define DLT_IEEE802_11_RADIO_AVS 163 /* 802.11 plus AVS radio header */ + +/* + * Juniper-private data link type, as per request from + * Hannes Gredler . The DLT_s are used + * for passing on chassis-internal metainformation such as + * QOS profiles, etc.. + */ +#define DLT_JUNIPER_MONITOR 164 + +/* + * BACnet MS/TP frames. + */ +#define DLT_BACNET_MS_TP 165 + +/* + * Another PPP variant as per request from Karsten Keil . + * + * This is used in some OSes to allow a kernel socket filter to distinguish + * between incoming and outgoing packets, on a socket intended to + * supply pppd with outgoing packets so it can do dial-on-demand and + * hangup-on-lack-of-demand; incoming packets are filtered out so they + * don't cause pppd to hold the connection up (you don't want random + * input packets such as port scans, packets from old lost connections, + * etc. to force the connection to stay up). + * + * The first byte of the PPP header (0xff03) is modified to accomodate + * the direction - 0x00 = IN, 0x01 = OUT. + */ +#define DLT_PPP_PPPD 166 + +/* + * Names for backwards compatibility with older versions of some PPP + * software; new software should use DLT_PPP_PPPD. + */ +#define DLT_PPP_WITH_DIRECTION DLT_PPP_PPPD +#define DLT_LINUX_PPP_WITHDIRECTION DLT_PPP_PPPD + +/* + * Juniper-private data link type, as per request from + * Hannes Gredler . The DLT_s are used + * for passing on chassis-internal metainformation such as + * QOS profiles, cookies, etc.. + */ +#define DLT_JUNIPER_PPPOE 167 +#define DLT_JUNIPER_PPPOE_ATM 168 + +#define DLT_GPRS_LLC 169 /* GPRS LLC */ +#define DLT_GPF_T 170 /* GPF-T (ITU-T G.7041/Y.1303) */ +#define DLT_GPF_F 171 /* GPF-F (ITU-T G.7041/Y.1303) */ + +/* + * Requested by Oolan Zimmer for use in Gcom's T1/E1 line + * monitoring equipment. + */ +#define DLT_GCOM_T1E1 172 +#define DLT_GCOM_SERIAL 173 + +/* + * Juniper-private data link type, as per request from + * Hannes Gredler . The DLT_ is used + * for internal communication to Physical Interface Cards (PIC) + */ +#define DLT_JUNIPER_PIC_PEER 174 + +/* + * Link types requested by Gregor Maier of Endace + * Measurement Systems. They add an ERF header (see + * http://www.endace.com/support/EndaceRecordFormat.pdf) in front of + * the link-layer header. + */ +#define DLT_ERF_ETH 175 /* Ethernet */ +#define DLT_ERF_POS 176 /* Packet-over-SONET */ + +/* + * Requested by Daniele Orlandi for raw LAPD + * for vISDN (http://www.orlandi.com/visdn/). Its link-layer header + * includes additional information before the LAPD header, so it's + * not necessarily a generic LAPD header. + */ +#define DLT_LINUX_LAPD 177 + +/* + * Juniper-private data link type, as per request from + * Hannes Gredler . + * The DLT_ are used for prepending meta-information + * like interface index, interface name + * before standard Ethernet, PPP, Frelay & C-HDLC Frames + */ +#define DLT_JUNIPER_ETHER 178 +#define DLT_JUNIPER_PPP 179 +#define DLT_JUNIPER_FRELAY 180 +#define DLT_JUNIPER_CHDLC 181 + +/* + * Multi Link Frame Relay (FRF.16) + */ +#define DLT_MFR 182 + +/* + * Juniper-private data link type, as per request from + * Hannes Gredler . + * The DLT_ is used for internal communication with a + * voice Adapter Card (PIC) + */ +#define DLT_JUNIPER_VP 183 + +/* + * Arinc 429 frames. + * DLT_ requested by Gianluca Varenni . + * Every frame contains a 32bit A429 label. + * More documentation on Arinc 429 can be found at + * http://www.condoreng.com/support/downloads/tutorials/ARINCTutorial.pdf + */ +#define DLT_A429 184 + +/* + * Arinc 653 Interpartition Communication messages. + * DLT_ requested by Gianluca Varenni . + * Please refer to the A653-1 standard for more information. + */ +#define DLT_A653_ICM 185 + +/* + * This used to be "USB packets, beginning with a USB setup header; + * requested by Paolo Abeni ." + * + * However, that header didn't work all that well - it left out some + * useful information - and was abandoned in favor of the DLT_USB_LINUX + * header. + * + * This is now used by FreeBSD for its BPF taps for USB; that has its + * own headers. So it is written, so it is done. + * + * For source-code compatibility, we also define DLT_USB to have this + * value. We do it numerically so that, if code that includes this + * file (directly or indirectly) also includes an OS header that also + * defines DLT_USB as 186, we don't get a redefinition warning. + * (NetBSD 7 does that.) + */ +#define DLT_USB_FREEBSD 186 +#define DLT_USB 186 + +/* + * Bluetooth HCI UART transport layer (part H:4); requested by + * Paolo Abeni. + */ +#define DLT_BLUETOOTH_HCI_H4 187 + +/* + * IEEE 802.16 MAC Common Part Sublayer; requested by Maria Cruz + * . + */ +#define DLT_IEEE802_16_MAC_CPS 188 + +/* + * USB packets, beginning with a Linux USB header; requested by + * Paolo Abeni . + */ +#define DLT_USB_LINUX 189 + +/* + * Controller Area Network (CAN) v. 2.0B packets. + * DLT_ requested by Gianluca Varenni . + * Used to dump CAN packets coming from a CAN Vector board. + * More documentation on the CAN v2.0B frames can be found at + * http://www.can-cia.org/downloads/?269 + */ +#define DLT_CAN20B 190 + +/* + * IEEE 802.15.4, with address fields padded, as is done by Linux + * drivers; requested by Juergen Schimmer. + */ +#define DLT_IEEE802_15_4_LINUX 191 + +/* + * Per Packet Information encapsulated packets. + * DLT_ requested by Gianluca Varenni . + */ +#define DLT_PPI 192 + +/* + * Header for 802.16 MAC Common Part Sublayer plus a radiotap radio header; + * requested by Charles Clancy. + */ +#define DLT_IEEE802_16_MAC_CPS_RADIO 193 + +/* + * Juniper-private data link type, as per request from + * Hannes Gredler . + * The DLT_ is used for internal communication with a + * integrated service module (ISM). + */ +#define DLT_JUNIPER_ISM 194 + +/* + * IEEE 802.15.4, exactly as it appears in the spec (no padding, no + * nothing); requested by Mikko Saarnivala . + * For this one, we expect the FCS to be present at the end of the frame; + * if the frame has no FCS, DLT_IEEE802_15_4_NOFCS should be used. + */ +#define DLT_IEEE802_15_4 195 + +/* + * Various link-layer types, with a pseudo-header, for SITA + * (http://www.sita.aero/); requested by Fulko Hew (fulko.hew@gmail.com). + */ +#define DLT_SITA 196 + +/* + * Various link-layer types, with a pseudo-header, for Endace DAG cards; + * encapsulates Endace ERF records. Requested by Stephen Donnelly + * . + */ +#define DLT_ERF 197 + +/* + * Special header prepended to Ethernet packets when capturing from a + * u10 Networks board. Requested by Phil Mulholland + * . + */ +#define DLT_RAIF1 198 + +/* + * IPMB packet for IPMI, beginning with the I2C slave address, followed + * by the netFn and LUN, etc.. Requested by Chanthy Toeung + * . + */ +#define DLT_IPMB 199 + +/* + * Juniper-private data link type, as per request from + * Hannes Gredler . + * The DLT_ is used for capturing data on a secure tunnel interface. + */ +#define DLT_JUNIPER_ST 200 + +/* + * Bluetooth HCI UART transport layer (part H:4), with pseudo-header + * that includes direction information; requested by Paolo Abeni. + */ +#define DLT_BLUETOOTH_HCI_H4_WITH_PHDR 201 + +/* + * AX.25 packet with a 1-byte KISS header; see + * + * http://www.ax25.net/kiss.htm + * + * as per Richard Stearn . + */ +#define DLT_AX25_KISS 202 + +/* + * LAPD packets from an ISDN channel, starting with the address field, + * with no pseudo-header. + * Requested by Varuna De Silva . + */ +#define DLT_LAPD 203 + +/* + * Variants of various link-layer headers, with a one-byte direction + * pseudo-header prepended - zero means "received by this host", + * non-zero (any non-zero value) means "sent by this host" - as per + * Will Barker . + */ +#define DLT_PPP_WITH_DIR 204 /* PPP - don't confuse with DLT_PPP_WITH_DIRECTION */ +#define DLT_C_HDLC_WITH_DIR 205 /* Cisco HDLC */ +#define DLT_FRELAY_WITH_DIR 206 /* Frame Relay */ +#define DLT_LAPB_WITH_DIR 207 /* LAPB */ + +/* + * 208 is reserved for an as-yet-unspecified proprietary link-layer + * type, as requested by Will Barker. + */ + +/* + * IPMB with a Linux-specific pseudo-header; as requested by Alexey Neyman + * . + */ +#define DLT_IPMB_LINUX 209 + +/* + * FlexRay automotive bus - http://www.flexray.com/ - as requested + * by Hannes Kaelber . + */ +#define DLT_FLEXRAY 210 + +/* + * Media Oriented Systems Transport (MOST) bus for multimedia + * transport - http://www.mostcooperation.com/ - as requested + * by Hannes Kaelber . + */ +#define DLT_MOST 211 + +/* + * Local Interconnect Network (LIN) bus for vehicle networks - + * http://www.lin-subbus.org/ - as requested by Hannes Kaelber + * . + */ +#define DLT_LIN 212 + +/* + * X2E-private data link type used for serial line capture, + * as requested by Hannes Kaelber . + */ +#define DLT_X2E_SERIAL 213 + +/* + * X2E-private data link type used for the Xoraya data logger + * family, as requested by Hannes Kaelber . + */ +#define DLT_X2E_XORAYA 214 + +/* + * IEEE 802.15.4, exactly as it appears in the spec (no padding, no + * nothing), but with the PHY-level data for non-ASK PHYs (4 octets + * of 0 as preamble, one octet of SFD, one octet of frame length+ + * reserved bit, and then the MAC-layer data, starting with the + * frame control field). + * + * Requested by Max Filippov . + */ +#define DLT_IEEE802_15_4_NONASK_PHY 215 + +/* + * David Gibson requested this for + * captures from the Linux kernel /dev/input/eventN devices. This + * is used to communicate keystrokes and mouse movements from the + * Linux kernel to display systems, such as Xorg. + */ +#define DLT_LINUX_EVDEV 216 + +/* + * GSM Um and Abis interfaces, preceded by a "gsmtap" header. + * + * Requested by Harald Welte . + */ +#define DLT_GSMTAP_UM 217 +#define DLT_GSMTAP_ABIS 218 + +/* + * MPLS, with an MPLS label as the link-layer header. + * Requested by Michele Marchetto on behalf + * of OpenBSD. + */ +#define DLT_MPLS 219 + +/* + * USB packets, beginning with a Linux USB header, with the USB header + * padded to 64 bytes; required for memory-mapped access. + */ +#define DLT_USB_LINUX_MMAPPED 220 + +/* + * DECT packets, with a pseudo-header; requested by + * Matthias Wenzel . + */ +#define DLT_DECT 221 + +/* + * From: "Lidwa, Eric (GSFC-582.0)[SGT INC]" + * Date: Mon, 11 May 2009 11:18:30 -0500 + * + * DLT_AOS. We need it for AOS Space Data Link Protocol. + * I have already written dissectors for but need an OK from + * legal before I can submit a patch. + * + */ +#define DLT_AOS 222 + +/* + * Wireless HART (Highway Addressable Remote Transducer) + * From the HART Communication Foundation + * IES/PAS 62591 + * + * Requested by Sam Roberts . + */ +#define DLT_WIHART 223 + +/* + * Fibre Channel FC-2 frames, beginning with a Frame_Header. + * Requested by Kahou Lei . + */ +#define DLT_FC_2 224 + +/* + * Fibre Channel FC-2 frames, beginning with an encoding of the + * SOF, and ending with an encoding of the EOF. + * + * The encodings represent the frame delimiters as 4-byte sequences + * representing the corresponding ordered sets, with K28.5 + * represented as 0xBC, and the D symbols as the corresponding + * byte values; for example, SOFi2, which is K28.5 - D21.5 - D1.2 - D21.2, + * is represented as 0xBC 0xB5 0x55 0x55. + * + * Requested by Kahou Lei . + */ +#define DLT_FC_2_WITH_FRAME_DELIMS 225 + +/* + * Solaris ipnet pseudo-header; requested by Darren Reed . + * + * The pseudo-header starts with a one-byte version number; for version 2, + * the pseudo-header is: + * + * struct dl_ipnetinfo { + * uint8_t dli_version; + * uint8_t dli_family; + * uint16_t dli_htype; + * uint32_t dli_pktlen; + * uint32_t dli_ifindex; + * uint32_t dli_grifindex; + * uint32_t dli_zsrc; + * uint32_t dli_zdst; + * }; + * + * dli_version is 2 for the current version of the pseudo-header. + * + * dli_family is a Solaris address family value, so it's 2 for IPv4 + * and 26 for IPv6. + * + * dli_htype is a "hook type" - 0 for incoming packets, 1 for outgoing + * packets, and 2 for packets arriving from another zone on the same + * machine. + * + * dli_pktlen is the length of the packet data following the pseudo-header + * (so the captured length minus dli_pktlen is the length of the + * pseudo-header, assuming the entire pseudo-header was captured). + * + * dli_ifindex is the interface index of the interface on which the + * packet arrived. + * + * dli_grifindex is the group interface index number (for IPMP interfaces). + * + * dli_zsrc is the zone identifier for the source of the packet. + * + * dli_zdst is the zone identifier for the destination of the packet. + * + * A zone number of 0 is the global zone; a zone number of 0xffffffff + * means that the packet arrived from another host on the network, not + * from another zone on the same machine. + * + * An IPv4 or IPv6 datagram follows the pseudo-header; dli_family indicates + * which of those it is. + */ +#define DLT_IPNET 226 + +/* + * CAN (Controller Area Network) frames, with a pseudo-header as supplied + * by Linux SocketCAN, and with multi-byte numerical fields in that header + * in big-endian byte order. + * + * See Documentation/networking/can.txt in the Linux source. + * + * Requested by Felix Obenhuber . + */ +#define DLT_CAN_SOCKETCAN 227 + +/* + * Raw IPv4/IPv6; different from DLT_RAW in that the DLT_ value specifies + * whether it's v4 or v6. Requested by Darren Reed . + */ +#define DLT_IPV4 228 +#define DLT_IPV6 229 + +/* + * IEEE 802.15.4, exactly as it appears in the spec (no padding, no + * nothing), and with no FCS at the end of the frame; requested by + * Jon Smirl . + */ +#define DLT_IEEE802_15_4_NOFCS 230 + +/* + * Raw D-Bus: + * + * http://www.freedesktop.org/wiki/Software/dbus + * + * messages: + * + * http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-messages + * + * starting with the endianness flag, followed by the message type, etc., + * but without the authentication handshake before the message sequence: + * + * http://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol + * + * Requested by Martin Vidner . + */ +#define DLT_DBUS 231 + +/* + * Juniper-private data link type, as per request from + * Hannes Gredler . + */ +#define DLT_JUNIPER_VS 232 +#define DLT_JUNIPER_SRX_E2E 233 +#define DLT_JUNIPER_FIBRECHANNEL 234 + +/* + * DVB-CI (DVB Common Interface for communication between a PC Card + * module and a DVB receiver). See + * + * http://www.kaiser.cx/pcap-dvbci.html + * + * for the specification. + * + * Requested by Martin Kaiser . + */ +#define DLT_DVB_CI 235 + +/* + * Variant of 3GPP TS 27.010 multiplexing protocol (similar to, but + * *not* the same as, 27.010). Requested by Hans-Christoph Schemmel + * . + */ +#define DLT_MUX27010 236 + +/* + * STANAG 5066 D_PDUs. Requested by M. Baris Demiray + * . + */ +#define DLT_STANAG_5066_D_PDU 237 + +/* + * Juniper-private data link type, as per request from + * Hannes Gredler . + */ +#define DLT_JUNIPER_ATM_CEMIC 238 + +/* + * NetFilter LOG messages + * (payload of netlink NFNL_SUBSYS_ULOG/NFULNL_MSG_PACKET packets) + * + * Requested by Jakub Zawadzki + */ +#define DLT_NFLOG 239 + +/* + * Hilscher Gesellschaft fuer Systemautomation mbH link-layer type + * for Ethernet packets with a 4-byte pseudo-header and always + * with the payload including the FCS, as supplied by their + * netANALYZER hardware and software. + * + * Requested by Holger P. Frommer + */ +#define DLT_NETANALYZER 240 + +/* + * Hilscher Gesellschaft fuer Systemautomation mbH link-layer type + * for Ethernet packets with a 4-byte pseudo-header and FCS and + * with the Ethernet header preceded by 7 bytes of preamble and + * 1 byte of SFD, as supplied by their netANALYZER hardware and + * software. + * + * Requested by Holger P. Frommer + */ +#define DLT_NETANALYZER_TRANSPARENT 241 + +/* + * IP-over-InfiniBand, as specified by RFC 4391. + * + * Requested by Petr Sumbera . + */ +#define DLT_IPOIB 242 + +/* + * MPEG-2 transport stream (ISO 13818-1/ITU-T H.222.0). + * + * Requested by Guy Martin . + */ +#define DLT_MPEG_2_TS 243 + +/* + * ng4T GmbH's UMTS Iub/Iur-over-ATM and Iub/Iur-over-IP format as + * used by their ng40 protocol tester. + * + * Requested by Jens Grimmer . + */ +#define DLT_NG40 244 + +/* + * Pseudo-header giving adapter number and flags, followed by an NFC + * (Near-Field Communications) Logical Link Control Protocol (LLCP) PDU, + * as specified by NFC Forum Logical Link Control Protocol Technical + * Specification LLCP 1.1. + * + * Requested by Mike Wakerly . + */ +#define DLT_NFC_LLCP 245 + +/* + * 246 is used as LINKTYPE_PFSYNC; do not use it for any other purpose. + * + * DLT_PFSYNC has different values on different platforms, and all of + * them collide with something used elsewhere. On platforms that + * don't already define it, define it as 246. + */ +#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__) && !defined(__APPLE__) +#define DLT_PFSYNC 246 +#endif + +/* + * Raw InfiniBand packets, starting with the Local Routing Header. + * + * Requested by Oren Kladnitsky . + */ +#define DLT_INFINIBAND 247 + +/* + * SCTP, with no lower-level protocols (i.e., no IPv4 or IPv6). + * + * Requested by Michael Tuexen . + */ +#define DLT_SCTP 248 + +/* + * USB packets, beginning with a USBPcap header. + * + * Requested by Tomasz Mon + */ +#define DLT_USBPCAP 249 + +/* + * Schweitzer Engineering Laboratories "RTAC" product serial-line + * packets. + * + * Requested by Chris Bontje . + */ +#define DLT_RTAC_SERIAL 250 + +/* + * Bluetooth Low Energy air interface link-layer packets. + * + * Requested by Mike Kershaw . + */ +#define DLT_BLUETOOTH_LE_LL 251 + +/* + * DLT type for upper-protocol layer PDU saves from wireshark. + * + * the actual contents are determined by two TAGs stored with each + * packet: + * EXP_PDU_TAG_LINKTYPE the link type (LINKTYPE_ value) of the + * original packet. + * + * EXP_PDU_TAG_PROTO_NAME the name of the wireshark dissector + * that can make sense of the data stored. + */ +#define DLT_WIRESHARK_UPPER_PDU 252 + +/* + * DLT type for the netlink protocol (nlmon devices). + */ +#define DLT_NETLINK 253 + +/* + * Bluetooth Linux Monitor headers for the BlueZ stack. + */ +#define DLT_BLUETOOTH_LINUX_MONITOR 254 + +/* + * Bluetooth Basic Rate/Enhanced Data Rate baseband packets, as + * captured by Ubertooth. + */ +#define DLT_BLUETOOTH_BREDR_BB 255 + +/* + * Bluetooth Low Energy link layer packets, as captured by Ubertooth. + */ +#define DLT_BLUETOOTH_LE_LL_WITH_PHDR 256 + +/* + * PROFIBUS data link layer. + */ +#define DLT_PROFIBUS_DL 257 + +/* + * Apple's DLT_PKTAP headers. + * + * Sadly, the folks at Apple either had no clue that the DLT_USERn values + * are for internal use within an organization and partners only, and + * didn't know that the right way to get a link-layer header type is to + * ask tcpdump.org for one, or knew and didn't care, so they just + * used DLT_USER2, which causes problems for everything except for + * their version of tcpdump. + * + * So I'll just give them one; hopefully this will show up in a + * libpcap release in time for them to get this into 10.10 Big Sur + * or whatever Mavericks' successor is called. LINKTYPE_PKTAP + * will be 258 *even on OS X*; that is *intentional*, so that + * PKTAP files look the same on *all* OSes (different OSes can have + * different numerical values for a given DLT_, but *MUST NOT* have + * different values for what goes in a file, as files can be moved + * between OSes!). + * + * When capturing, on a system with a Darwin-based OS, on a device + * that returns 149 (DLT_USER2 and Apple's DLT_PKTAP) with this + * version of libpcap, the DLT_ value for the pcap_t will be DLT_PKTAP, + * and that will continue to be DLT_USER2 on Darwin-based OSes. That way, + * binary compatibility with Mavericks is preserved for programs using + * this version of libpcap. This does mean that if you were using + * DLT_USER2 for some capture device on OS X, you can't do so with + * this version of libpcap, just as you can't with Apple's libpcap - + * on OS X, they define DLT_PKTAP to be DLT_USER2, so programs won't + * be able to distinguish between PKTAP and whatever you were using + * DLT_USER2 for. + * + * If the program saves the capture to a file using this version of + * libpcap's pcap_dump code, the LINKTYPE_ value in the file will be + * LINKTYPE_PKTAP, which will be 258, even on Darwin-based OSes. + * That way, the file will *not* be a DLT_USER2 file. That means + * that the latest version of tcpdump, when built with this version + * of libpcap, and sufficiently recent versions of Wireshark will + * be able to read those files and interpret them correctly; however, + * Apple's version of tcpdump in OS X 10.9 won't be able to handle + * them. (Hopefully, Apple will pick up this version of libpcap, + * and the corresponding version of tcpdump, so that tcpdump will + * be able to handle the old LINKTYPE_USER2 captures *and* the new + * LINKTYPE_PKTAP captures.) + */ +#ifdef __APPLE__ +#define DLT_PKTAP DLT_USER2 +#else +#define DLT_PKTAP 258 +#endif + +/* + * Ethernet packets preceded by a header giving the last 6 octets + * of the preamble specified by 802.3-2012 Clause 65, section + * 65.1.3.2 "Transmit". + */ +#define DLT_EPON 259 + +/* + * IPMI trace packets, as specified by Table 3-20 "Trace Data Block Format" + * in the PICMG HPM.2 specification. + */ +#define DLT_IPMI_HPM_2 260 + +/* + * per Joshua Wright , formats for Zwave captures. + */ +#define DLT_ZWAVE_R1_R2 261 +#define DLT_ZWAVE_R3 262 + +/* + * per Steve Karg , formats for Wattstopper + * Digital Lighting Management room bus serial protocol captures. + */ +#define DLT_WATTSTOPPER_DLM 263 + +/* + * ISO 14443 contactless smart card messages. + */ +#define DLT_ISO_14443 264 + +/* + * Radio data system (RDS) groups. IEC 62106. + * Per Jonathan Brucker . + */ +#define DLT_RDS 265 + +/* + * USB packets, beginning with a Darwin (macOS, etc.) header. + */ +#define DLT_USB_DARWIN 266 + +/* + * OpenBSD DLT_OPENFLOW. + */ +#define DLT_OPENFLOW 267 + +/* + * SDLC frames containing SNA PDUs. + */ +#define DLT_SDLC 268 + +/* + * per "Selvig, Bjorn" used for + * TI protocol sniffer. + */ +#define DLT_TI_LLN_SNIFFER 269 + +/* + * per: Erik de Jong for + * https://github.com/eriknl/LoRaTap/releases/tag/v0.1 + */ +#define DLT_LORATAP 270 + +/* + * per: Stefanha at gmail.com for + * http://lists.sandelman.ca/pipermail/tcpdump-workers/2017-May/000772.html + * and: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/vsockmon.h + * for: http://qemu-project.org/Features/VirtioVsock + */ +#define DLT_VSOCK 271 + +/* + * Nordic Semiconductor Bluetooth LE sniffer. + */ +#define DLT_NORDIC_BLE 272 + +/* + * Excentis DOCSIS 3.1 RF sniffer (XRA-31) + * per: bruno.verstuyft at excentis.com + * http://www.xra31.com/xra-header + */ +#define DLT_DOCSIS31_XRA31 273 + +/* + * mPackets, as specified by IEEE 802.3br Figure 99-4, starting + * with the preamble and always ending with a CRC field. + */ +#define DLT_ETHERNET_MPACKET 274 + +/* + * In case the code that includes this file (directly or indirectly) + * has also included OS files that happen to define DLT_MATCHING_MAX, + * with a different value (perhaps because that OS hasn't picked up + * the latest version of our DLT definitions), we undefine the + * previous value of DLT_MATCHING_MAX. + */ +#ifdef DLT_MATCHING_MAX +#undef DLT_MATCHING_MAX +#endif +#define DLT_MATCHING_MAX 274 /* highest value in the "matching" range */ + +/* + * DLT and savefile link type values are split into a class and + * a member of that class. A class value of 0 indicates a regular + * DLT_/LINKTYPE_ value. + */ +#define DLT_CLASS(x) ((x) & 0x03ff0000) + +/* + * NetBSD-specific generic "raw" link type. The class value indicates + * that this is the generic raw type, and the lower 16 bits are the + * address family we're dealing with. Those values are NetBSD-specific; + * do not assume that they correspond to AF_ values for your operating + * system. + */ +#define DLT_CLASS_NETBSD_RAWAF 0x02240000 +#define DLT_NETBSD_RAWAF(af) (DLT_CLASS_NETBSD_RAWAF | (af)) +#define DLT_NETBSD_RAWAF_AF(x) ((x) & 0x0000ffff) +#define DLT_IS_NETBSD_RAWAF(x) (DLT_CLASS(x) == DLT_CLASS_NETBSD_RAWAF) + +#endif /* !defined(lib_pcap_dlt_h) */ diff --git a/src/frontend/qt_sdl/pcap/funcattrs.h b/src/frontend/qt_sdl/pcap/funcattrs.h new file mode 100644 index 0000000..d1cc2bf --- /dev/null +++ b/src/frontend/qt_sdl/pcap/funcattrs.h @@ -0,0 +1,242 @@ +/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */ +/* + * Copyright (c) 1993, 1994, 1995, 1996, 1997 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Computer Systems + * Engineering Group at Lawrence Berkeley Laboratory. + * 4. Neither the name of the University nor of the Laboratory may be used + * to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lib_pcap_funcattrs_h +#define lib_pcap_funcattrs_h + +#include + +/* + * Attributes to apply to functions and their arguments, using various + * compiler-specific extensions. + */ + +/* + * PCAP_API_DEF must be used when defining *data* exported from + * libpcap. It can be used when defining *functions* exported + * from libpcap, but it doesn't have to be used there. It + * should not be used in declarations in headers. + * + * PCAP_API must be used when *declaring* data or functions + * exported from libpcap; PCAP_API_DEF won't work on all platforms. + */ + +#if defined(_WIN32) + /* + * For Windows: + * + * when building libpcap: + * + * if we're building it as a DLL, we have to declare API + * functions with __declspec(dllexport); + * + * if we're building it as a static library, we don't want + * to do so. + * + * when using libpcap: + * + * if we're using the DLL, calls to its functions are a + * little more efficient if they're declared with + * __declspec(dllimport); + * + * if we're not using the dll, we don't want to declare + * them that way. + * + * So: + * + * if pcap_EXPORTS is defined, we define PCAP_API_DEF as + * __declspec(dllexport); + * + * if PCAP_DLL is defined, we define PCAP_API_DEF as + * __declspec(dllimport); + * + * otherwise, we define PCAP_API_DEF as nothing. + */ + #if defined(pcap_EXPORTS) + /* + * We're compiling libpcap, so we should export functions in our + * API. + */ + #define PCAP_API_DEF __declspec(dllexport) + #elif defined(PCAP_DLL) + #define PCAP_API_DEF __declspec(dllimport) + #else + #define PCAP_API_DEF + #endif +#elif defined(MSDOS) + /* XXX - does this need special treatment? */ + #define PCAP_API_DEF +#else /* UN*X */ + #ifdef pcap_EXPORTS + /* + * We're compiling libpcap, so we should export functions in our API. + * The compiler might be configured not to export functions from a + * shared library by default, so we might have to explicitly mark + * functions as exported. + */ + #if PCAP_IS_AT_LEAST_GNUC_VERSION(3,4) \ + || PCAP_IS_AT_LEAST_XL_C_VERSION(12,0) + /* + * GCC 3.4 or later, or some compiler asserting compatibility with + * GCC 3.4 or later, or XL C 13.0 or later, so we have + * __attribute__((visibility()). + */ + #define PCAP_API_DEF __attribute__((visibility("default"))) + #elif PCAP_IS_AT_LEAST_SUNC_VERSION(5,5) + /* + * Sun C 5.5 or later, so we have __global. + * (Sun C 5.9 and later also have __attribute__((visibility()), + * but there's no reason to prefer it with Sun C.) + */ + #define PCAP_API_DEF __global + #else + /* + * We don't have anything to say. + */ + #define PCAP_API_DEF + #endif + #else + /* + * We're not building libpcap. + */ + #define PCAP_API_DEF + #endif +#endif /* _WIN32/MSDOS/UN*X */ + +#define PCAP_API PCAP_API_DEF extern + +/* + * PCAP_NORETURN, before a function declaration, means "this function + * never returns". (It must go before the function declaration, e.g. + * "extern PCAP_NORETURN func(...)" rather than after the function + * declaration, as the MSVC version has to go before the declaration.) + */ +#if __has_attribute(noreturn) \ + || PCAP_IS_AT_LEAST_GNUC_VERSION(2,5) \ + || PCAP_IS_AT_LEAST_SUNC_VERSION(5,9) \ + || PCAP_IS_AT_LEAST_XL_C_VERSION(10,1) \ + || PCAP_IS_AT_LEAST_HP_C_VERSION(6,10) + /* + * Compiler with support for __attribute((noreturn)), or GCC 2.5 and + * later, or Solaris Studio 12 (Sun C 5.9) and later, or IBM XL C 10.1 + * and later (do any earlier versions of XL C support this?), or + * HP aCC A.06.10 and later. + */ + #define PCAP_NORETURN __attribute((noreturn)) +#elif defined(_MSC_VER) + /* + * MSVC. + */ + #define PCAP_NORETURN __declspec(noreturn) +#else + #define PCAP_NORETURN +#endif + +/* + * PCAP_PRINTFLIKE(x,y), after a function declaration, means "this function + * does printf-style formatting, with the xth argument being the format + * string and the yth argument being the first argument for the format + * string". + */ +#if __has_attribute(__format__) \ + || PCAP_IS_AT_LEAST_GNUC_VERSION(2,3) \ + || PCAP_IS_AT_LEAST_XL_C_VERSION(10,1) \ + || PCAP_IS_AT_LEAST_HP_C_VERSION(6,10) + /* + * Compiler with support for it, or GCC 2.3 and later, or IBM XL C 10.1 + * and later (do any earlier versions of XL C support this?), + * or HP aCC A.06.10 and later. + */ + #define PCAP_PRINTFLIKE(x,y) __attribute__((__format__(__printf__,x,y))) +#else + #define PCAP_PRINTFLIKE(x,y) +#endif + +/* + * PCAP_DEPRECATED(func, msg), after a function declaration, marks the + * function as deprecated. + * + * The first argument is the name of the function; the second argument is + * a string giving the warning message to use if the compiler supports that. + * + * (Thank you, Microsoft, for requiring the function name.) + */ +#if __has_attribute(deprecated) \ + || PCAP_IS_AT_LEAST_GNUC_VERSION(4,5) \ + || PCAP_IS_AT_LEAST_SUNC_VERSION(5,13) + /* + * Compiler that supports __has_attribute and __attribute__((deprecated)), + * or GCC 4.5 and later, or Sun/Oracle C 12.4 (Sun C 5.13) or later. + * + * Those support __attribute__((deprecated(msg))) (we assume, perhaps + * incorrectly, that anything that supports __has_attribute() is + * recent enough to support __attribute__((deprecated(msg)))). + */ + #define PCAP_DEPRECATED(func, msg) __attribute__((deprecated(msg))) +#elif PCAP_IS_AT_LEAST_GNUC_VERSION(3,1) + /* + * GCC 3.1 through 4.4. + * + * Those support __attribute__((deprecated)) but not + * __attribute__((deprecated(msg))). + */ + #define PCAP_DEPRECATED(func, msg) __attribute__((deprecated)) +#elif (defined(_MSC_VER) && (_MSC_VER >= 1500)) && !defined(pcap_EXPORTS) + /* + * MSVC from Visual Studio 2008 or later, and we're not building + * libpcap itself. + * + * If we *are* building libpcap, we don't want this, as it'll warn + * us even if we *define* the function. + */ + #define PCAP_DEPRECATED(func, msg) __pragma(deprecated(func)) +#else + #define PCAP_DEPRECATED(func, msg) +#endif + +/* + * For flagging arguments as format strings in MSVC. + */ +#ifdef _MSC_VER + #include + #if _MSC_VER > 1400 + #define PCAP_FORMAT_STRING(p) _Printf_format_string_ p + #else + #define PCAP_FORMAT_STRING(p) __format_string p + #endif +#else + #define PCAP_FORMAT_STRING(p) p +#endif + +#endif /* lib_pcap_funcattrs_h */ diff --git a/src/frontend/qt_sdl/pcap/ipnet.h b/src/frontend/qt_sdl/pcap/ipnet.h new file mode 100644 index 0000000..5330847 --- /dev/null +++ b/src/frontend/qt_sdl/pcap/ipnet.h @@ -0,0 +1,43 @@ +/*- + * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from the Stanford/CMU enet packet filter, + * (net/enet.c) distributed as part of 4.3BSD, and code contributed + * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence + * Berkeley Laboratory. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#define IPH_AF_INET 2 /* Matches Solaris's AF_INET */ +#define IPH_AF_INET6 26 /* Matches Solaris's AF_INET6 */ + +#define IPNET_OUTBOUND 1 +#define IPNET_INBOUND 2 diff --git a/src/frontend/qt_sdl/pcap/namedb.h b/src/frontend/qt_sdl/pcap/namedb.h new file mode 100644 index 0000000..73fb40a --- /dev/null +++ b/src/frontend/qt_sdl/pcap/namedb.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 1994, 1996 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Computer Systems + * Engineering Group at Lawrence Berkeley Laboratory. + * 4. Neither the name of the University nor of the Laboratory may be used + * to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lib_pcap_namedb_h +#define lib_pcap_namedb_h + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * As returned by the pcap_next_etherent() + * XXX this stuff doesn't belong in this interface, but this + * library already must do name to address translation, so + * on systems that don't have support for /etc/ethers, we + * export these hooks since they're already being used by + * some applications (such as tcpdump) and already being + * marked as exported in some OSes offering libpcap (such + * as Debian). + */ +struct pcap_etherent { + u_char addr[6]; + char name[122]; +}; +#ifndef PCAP_ETHERS_FILE +#define PCAP_ETHERS_FILE "/etc/ethers" +#endif +PCAP_API struct pcap_etherent *pcap_next_etherent(FILE *); +PCAP_API u_char *pcap_ether_hostton(const char*); +PCAP_API u_char *pcap_ether_aton(const char *); + +PCAP_API bpf_u_int32 **pcap_nametoaddr(const char *); +#ifdef INET6 +PCAP_API struct addrinfo *pcap_nametoaddrinfo(const char *); +#endif +PCAP_API bpf_u_int32 pcap_nametonetaddr(const char *); + +PCAP_API int pcap_nametoport(const char *, int *, int *); +PCAP_API int pcap_nametoportrange(const char *, int *, int *, int *); +PCAP_API int pcap_nametoproto(const char *); +PCAP_API int pcap_nametoeproto(const char *); +PCAP_API int pcap_nametollc(const char *); +/* + * If a protocol is unknown, PROTO_UNDEF is returned. + * Also, pcap_nametoport() returns the protocol along with the port number. + * If there are ambiguous entried in /etc/services (i.e. domain + * can be either tcp or udp) PROTO_UNDEF is returned. + */ +#define PROTO_UNDEF -1 + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/frontend/qt_sdl/pcap/nflog.h b/src/frontend/qt_sdl/pcap/nflog.h new file mode 100644 index 0000000..29a71d2 --- /dev/null +++ b/src/frontend/qt_sdl/pcap/nflog.h @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2013, Petar Alilovic, + * Faculty of Electrical Engineering and Computing, University of Zagreb + * All rights reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + */ + +#ifndef lib_pcap_nflog_h +#define lib_pcap_nflog_h + +#include + +/* + * Structure of an NFLOG header and TLV parts, as described at + * http://www.tcpdump.org/linktypes/LINKTYPE_NFLOG.html + * + * The NFLOG header is big-endian. + * + * The TLV length and type are in host byte order. The value is either + * big-endian or is an array of bytes in some externally-specified byte + * order (text string, link-layer address, link-layer header, packet + * data, etc.). + */ +typedef struct nflog_hdr { + uint8_t nflog_family; /* address family */ + uint8_t nflog_version; /* version */ + uint16_t nflog_rid; /* resource ID */ +} nflog_hdr_t; + +typedef struct nflog_tlv { + uint16_t tlv_length; /* tlv length */ + uint16_t tlv_type; /* tlv type */ + /* value follows this */ +} nflog_tlv_t; + +typedef struct nflog_packet_hdr { + uint16_t hw_protocol; /* hw protocol */ + uint8_t hook; /* netfilter hook */ + uint8_t pad; /* padding to 32 bits */ +} nflog_packet_hdr_t; + +typedef struct nflog_hwaddr { + uint16_t hw_addrlen; /* address length */ + uint16_t pad; /* padding to 32-bit boundary */ + uint8_t hw_addr[8]; /* address, up to 8 bytes */ +} nflog_hwaddr_t; + +typedef struct nflog_timestamp { + uint64_t sec; + uint64_t usec; +} nflog_timestamp_t; + +/* + * TLV types. + */ +#define NFULA_PACKET_HDR 1 /* nflog_packet_hdr_t */ +#define NFULA_MARK 2 /* packet mark from skbuff */ +#define NFULA_TIMESTAMP 3 /* nflog_timestamp_t for skbuff's time stamp */ +#define NFULA_IFINDEX_INDEV 4 /* ifindex of device on which packet received (possibly bridge group) */ +#define NFULA_IFINDEX_OUTDEV 5 /* ifindex of device on which packet transmitted (possibly bridge group) */ +#define NFULA_IFINDEX_PHYSINDEV 6 /* ifindex of physical device on which packet received (not bridge group) */ +#define NFULA_IFINDEX_PHYSOUTDEV 7 /* ifindex of physical device on which packet transmitted (not bridge group) */ +#define NFULA_HWADDR 8 /* nflog_hwaddr_t for hardware address */ +#define NFULA_PAYLOAD 9 /* packet payload */ +#define NFULA_PREFIX 10 /* text string - null-terminated, count includes NUL */ +#define NFULA_UID 11 /* UID owning socket on which packet was sent/received */ +#define NFULA_SEQ 12 /* sequence number of packets on this NFLOG socket */ +#define NFULA_SEQ_GLOBAL 13 /* sequence number of pakets on all NFLOG sockets */ +#define NFULA_GID 14 /* GID owning socket on which packet was sent/received */ +#define NFULA_HWTYPE 15 /* ARPHRD_ type of skbuff's device */ +#define NFULA_HWHEADER 16 /* skbuff's MAC-layer header */ +#define NFULA_HWLEN 17 /* length of skbuff's MAC-layer header */ + +#endif diff --git a/src/frontend/qt_sdl/pcap/pcap-inttypes.h b/src/frontend/qt_sdl/pcap/pcap-inttypes.h new file mode 100644 index 0000000..af2c23c --- /dev/null +++ b/src/frontend/qt_sdl/pcap/pcap-inttypes.h @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2002 - 2005 NetGroup, Politecnico di Torino (Italy) + * Copyright (c) 2005 - 2009 CACE Technologies, Inc. Davis (California) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Politecnico di Torino nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef pcap_pcap_inttypes_h +#define pcap_pcap_inttypes_h + +/* + * Get the integer types and PRi[doux]64 values from C99 + * defined, by hook or by crook. + */ +#if defined(_MSC_VER) + /* + * Compiler is MSVC. + */ + #if _MSC_VER >= 1800 + /* + * VS 2013 or newer; we have . + */ + #include + #else + /* + * Earlier VS; we have to define this stuff ourselves. + */ + typedef unsigned char uint8_t; + typedef signed char int8_t; + typedef unsigned short uint16_t; + typedef signed short int16_t; + typedef unsigned int uint32_t; + typedef signed int int32_t; + #ifdef _MSC_EXTENSIONS + typedef unsigned _int64 uint64_t; + typedef _int64 int64_t; + #else /* _MSC_EXTENSIONS */ + typedef unsigned long long uint64_t; + typedef long long int64_t; + #endif + #endif + + /* + * These may be defined by . + * + * XXX - for MSVC, we always want the _MSC_EXTENSIONS versions. + * What about other compilers? If, as the MinGW Web site says MinGW + * does, the other compilers just use Microsoft's run-time library, + * then they should probably use the _MSC_EXTENSIONS even if the + * compiler doesn't define _MSC_EXTENSIONS. + * + * XXX - we currently aren't using any of these, but this allows + * their use in the future. + */ + #ifndef PRId64 + #ifdef _MSC_EXTENSIONS + #define PRId64 "I64d" + #else + #define PRId64 "lld" + #endif + #endif /* PRId64 */ + + #ifndef PRIo64 + #ifdef _MSC_EXTENSIONS + #define PRIo64 "I64o" + #else + #define PRIo64 "llo" + #endif + #endif /* PRIo64 */ + + #ifndef PRIx64 + #ifdef _MSC_EXTENSIONS + #define PRIx64 "I64x" + #else + #define PRIx64 "llx" + #endif + #endif + + #ifndef PRIu64 + #ifdef _MSC_EXTENSIONS + #define PRIu64 "I64u" + #else + #define PRIu64 "llu" + #endif + #endif +#elif defined(__MINGW32__) || !defined(_WIN32) + /* + * Compiler is MinGW or target is UN*X or MS-DOS. Just use + * . + */ + #include +#endif + +#endif /* pcap/pcap-inttypes.h */ diff --git a/src/frontend/qt_sdl/pcap/pcap.h b/src/frontend/qt_sdl/pcap/pcap.h new file mode 100644 index 0000000..d32e2a9 --- /dev/null +++ b/src/frontend/qt_sdl/pcap/pcap.h @@ -0,0 +1,966 @@ +/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */ +/* + * Copyright (c) 1993, 1994, 1995, 1996, 1997 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Computer Systems + * Engineering Group at Lawrence Berkeley Laboratory. + * 4. Neither the name of the University nor of the Laboratory may be used + * to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Remote packet capture mechanisms and extensions from WinPcap: + * + * Copyright (c) 2002 - 2003 + * NetGroup, Politecnico di Torino (Italy) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Politecnico di Torino nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef lib_pcap_pcap_h +#define lib_pcap_pcap_h + +#include + +#include + +#if defined(_WIN32) + #include /* u_int, u_char etc. */ + #include /* _get_osfhandle() */ +#elif defined(MSDOS) + #include /* u_int, u_char etc. */ + #include +#else /* UN*X */ + #include /* u_int, u_char etc. */ + #include +#endif /* _WIN32/MSDOS/UN*X */ + +#ifndef PCAP_DONT_INCLUDE_PCAP_BPF_H +#include +#endif + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Version number of the current version of the pcap file format. + * + * NOTE: this is *NOT* the version number of the libpcap library. + * To fetch the version information for the version of libpcap + * you're using, use pcap_lib_version(). + */ +#define PCAP_VERSION_MAJOR 2 +#define PCAP_VERSION_MINOR 4 + +#define PCAP_ERRBUF_SIZE 256 + +/* + * Compatibility for systems that have a bpf.h that + * predates the bpf typedefs for 64-bit support. + */ +#if BPF_RELEASE - 0 < 199406 +typedef int bpf_int32; +typedef u_int bpf_u_int32; +#endif + +typedef struct pcap pcap_t; +typedef struct pcap_dumper pcap_dumper_t; +typedef struct pcap_if pcap_if_t; +typedef struct pcap_addr pcap_addr_t; + +/* + * The first record in the file contains saved values for some + * of the flags used in the printout phases of tcpdump. + * Many fields here are 32 bit ints so compilers won't insert unwanted + * padding; these files need to be interchangeable across architectures. + * + * Do not change the layout of this structure, in any way (this includes + * changes that only affect the length of fields in this structure). + * + * Also, do not change the interpretation of any of the members of this + * structure, in any way (this includes using values other than + * LINKTYPE_ values, as defined in "savefile.c", in the "linktype" + * field). + * + * Instead: + * + * introduce a new structure for the new format, if the layout + * of the structure changed; + * + * send mail to "tcpdump-workers@lists.tcpdump.org", requesting + * a new magic number for your new capture file format, and, when + * you get the new magic number, put it in "savefile.c"; + * + * use that magic number for save files with the changed file + * header; + * + * make the code in "savefile.c" capable of reading files with + * the old file header as well as files with the new file header + * (using the magic number to determine the header format). + * + * Then supply the changes by forking the branch at + * + * https://github.com/the-tcpdump-group/libpcap/issues + * + * and issuing a pull request, so that future versions of libpcap and + * programs that use it (such as tcpdump) will be able to read your new + * capture file format. + */ +struct pcap_file_header { + bpf_u_int32 magic; + u_short version_major; + u_short version_minor; + bpf_int32 thiszone; /* gmt to local correction */ + bpf_u_int32 sigfigs; /* accuracy of timestamps */ + bpf_u_int32 snaplen; /* max length saved portion of each pkt */ + bpf_u_int32 linktype; /* data link type (LINKTYPE_*) */ +}; + +/* + * Macros for the value returned by pcap_datalink_ext(). + * + * If LT_FCS_LENGTH_PRESENT(x) is true, the LT_FCS_LENGTH(x) macro + * gives the FCS length of packets in the capture. + */ +#define LT_FCS_LENGTH_PRESENT(x) ((x) & 0x04000000) +#define LT_FCS_LENGTH(x) (((x) & 0xF0000000) >> 28) +#define LT_FCS_DATALINK_EXT(x) ((((x) & 0xF) << 28) | 0x04000000) + +typedef enum { + PCAP_D_INOUT = 0, + PCAP_D_IN, + PCAP_D_OUT +} pcap_direction_t; + +/* + * Generic per-packet information, as supplied by libpcap. + * + * The time stamp can and should be a "struct timeval", regardless of + * whether your system supports 32-bit tv_sec in "struct timeval", + * 64-bit tv_sec in "struct timeval", or both if it supports both 32-bit + * and 64-bit applications. The on-disk format of savefiles uses 32-bit + * tv_sec (and tv_usec); this structure is irrelevant to that. 32-bit + * and 64-bit versions of libpcap, even if they're on the same platform, + * should supply the appropriate version of "struct timeval", even if + * that's not what the underlying packet capture mechanism supplies. + */ +struct pcap_pkthdr { + struct timeval ts; /* time stamp */ + bpf_u_int32 caplen; /* length of portion present */ + bpf_u_int32 len; /* length this packet (off wire) */ +}; + +/* + * As returned by the pcap_stats() + */ +struct pcap_stat { + u_int ps_recv; /* number of packets received */ + u_int ps_drop; /* number of packets dropped */ + u_int ps_ifdrop; /* drops by interface -- only supported on some platforms */ +#ifdef _WIN32 + u_int ps_capt; /* number of packets that reach the application */ + u_int ps_sent; /* number of packets sent by the server on the network */ + u_int ps_netdrop; /* number of packets lost on the network */ +#endif /* _WIN32 */ +}; + +#ifdef MSDOS +/* + * As returned by the pcap_stats_ex() + */ +struct pcap_stat_ex { + u_long rx_packets; /* total packets received */ + u_long tx_packets; /* total packets transmitted */ + u_long rx_bytes; /* total bytes received */ + u_long tx_bytes; /* total bytes transmitted */ + u_long rx_errors; /* bad packets received */ + u_long tx_errors; /* packet transmit problems */ + u_long rx_dropped; /* no space in Rx buffers */ + u_long tx_dropped; /* no space available for Tx */ + u_long multicast; /* multicast packets received */ + u_long collisions; + + /* detailed rx_errors: */ + u_long rx_length_errors; + u_long rx_over_errors; /* receiver ring buff overflow */ + u_long rx_crc_errors; /* recv'd pkt with crc error */ + u_long rx_frame_errors; /* recv'd frame alignment error */ + u_long rx_fifo_errors; /* recv'r fifo overrun */ + u_long rx_missed_errors; /* recv'r missed packet */ + + /* detailed tx_errors */ + u_long tx_aborted_errors; + u_long tx_carrier_errors; + u_long tx_fifo_errors; + u_long tx_heartbeat_errors; + u_long tx_window_errors; + }; +#endif + +/* + * Item in a list of interfaces. + */ +struct pcap_if { + struct pcap_if *next; + char *name; /* name to hand to "pcap_open_live()" */ + char *description; /* textual description of interface, or NULL */ + struct pcap_addr *addresses; + bpf_u_int32 flags; /* PCAP_IF_ interface flags */ +}; + +#define PCAP_IF_LOOPBACK 0x00000001 /* interface is loopback */ +#define PCAP_IF_UP 0x00000002 /* interface is up */ +#define PCAP_IF_RUNNING 0x00000004 /* interface is running */ + +/* + * Representation of an interface address. + */ +struct pcap_addr { + struct pcap_addr *next; + struct sockaddr *addr; /* address */ + struct sockaddr *netmask; /* netmask for that address */ + struct sockaddr *broadaddr; /* broadcast address for that address */ + struct sockaddr *dstaddr; /* P2P destination address for that address */ +}; + +typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *, + const u_char *); + +/* + * Error codes for the pcap API. + * These will all be negative, so you can check for the success or + * failure of a call that returns these codes by checking for a + * negative value. + */ +#define PCAP_ERROR -1 /* generic error code */ +#define PCAP_ERROR_BREAK -2 /* loop terminated by pcap_breakloop */ +#define PCAP_ERROR_NOT_ACTIVATED -3 /* the capture needs to be activated */ +#define PCAP_ERROR_ACTIVATED -4 /* the operation can't be performed on already activated captures */ +#define PCAP_ERROR_NO_SUCH_DEVICE -5 /* no such device exists */ +#define PCAP_ERROR_RFMON_NOTSUP -6 /* this device doesn't support rfmon (monitor) mode */ +#define PCAP_ERROR_NOT_RFMON -7 /* operation supported only in monitor mode */ +#define PCAP_ERROR_PERM_DENIED -8 /* no permission to open the device */ +#define PCAP_ERROR_IFACE_NOT_UP -9 /* interface isn't up */ +#define PCAP_ERROR_CANTSET_TSTAMP_TYPE -10 /* this device doesn't support setting the time stamp type */ +#define PCAP_ERROR_PROMISC_PERM_DENIED -11 /* you don't have permission to capture in promiscuous mode */ +#define PCAP_ERROR_TSTAMP_PRECISION_NOTSUP -12 /* the requested time stamp precision is not supported */ + +/* + * Warning codes for the pcap API. + * These will all be positive and non-zero, so they won't look like + * errors. + */ +#define PCAP_WARNING 1 /* generic warning code */ +#define PCAP_WARNING_PROMISC_NOTSUP 2 /* this device doesn't support promiscuous mode */ +#define PCAP_WARNING_TSTAMP_TYPE_NOTSUP 3 /* the requested time stamp type is not supported */ + +/* + * Value to pass to pcap_compile() as the netmask if you don't know what + * the netmask is. + */ +#define PCAP_NETMASK_UNKNOWN 0xffffffff + +/* + * We're deprecating pcap_lookupdev() for various reasons (not + * thread-safe, can behave weirdly with WinPcap). Callers + * should use pcap_findalldevs() and use the first device. + */ +PCAP_API char *pcap_lookupdev(char *) +PCAP_DEPRECATED(pcap_lookupdev, "use 'pcap_findalldevs' and use the first device"); + +PCAP_API int pcap_lookupnet(const char *, bpf_u_int32 *, bpf_u_int32 *, char *); + +PCAP_API pcap_t *pcap_create(const char *, char *); +PCAP_API int pcap_set_snaplen(pcap_t *, int); +PCAP_API int pcap_set_promisc(pcap_t *, int); +PCAP_API int pcap_can_set_rfmon(pcap_t *); +PCAP_API int pcap_set_rfmon(pcap_t *, int); +PCAP_API int pcap_set_timeout(pcap_t *, int); +PCAP_API int pcap_set_tstamp_type(pcap_t *, int); +PCAP_API int pcap_set_immediate_mode(pcap_t *, int); +PCAP_API int pcap_set_buffer_size(pcap_t *, int); +PCAP_API int pcap_set_tstamp_precision(pcap_t *, int); +PCAP_API int pcap_get_tstamp_precision(pcap_t *); +PCAP_API int pcap_activate(pcap_t *); + +PCAP_API int pcap_list_tstamp_types(pcap_t *, int **); +PCAP_API void pcap_free_tstamp_types(int *); +PCAP_API int pcap_tstamp_type_name_to_val(const char *); +PCAP_API const char *pcap_tstamp_type_val_to_name(int); +PCAP_API const char *pcap_tstamp_type_val_to_description(int); + +#ifdef __linux__ +PCAP_API int pcap_set_protocol(pcap_t *, int); +#endif + +/* + * Time stamp types. + * Not all systems and interfaces will necessarily support all of these. + * + * A system that supports PCAP_TSTAMP_HOST is offering time stamps + * provided by the host machine, rather than by the capture device, + * but not committing to any characteristics of the time stamp; + * it will not offer any of the PCAP_TSTAMP_HOST_ subtypes. + * + * PCAP_TSTAMP_HOST_LOWPREC is a time stamp, provided by the host machine, + * that's low-precision but relatively cheap to fetch; it's normally done + * using the system clock, so it's normally synchronized with times you'd + * fetch from system calls. + * + * PCAP_TSTAMP_HOST_HIPREC is a time stamp, provided by the host machine, + * that's high-precision; it might be more expensive to fetch. It might + * or might not be synchronized with the system clock, and might have + * problems with time stamps for packets received on different CPUs, + * depending on the platform. + * + * PCAP_TSTAMP_ADAPTER is a high-precision time stamp supplied by the + * capture device; it's synchronized with the system clock. + * + * PCAP_TSTAMP_ADAPTER_UNSYNCED is a high-precision time stamp supplied by + * the capture device; it's not synchronized with the system clock. + * + * Note that time stamps synchronized with the system clock can go + * backwards, as the system clock can go backwards. If a clock is + * not in sync with the system clock, that could be because the + * system clock isn't keeping accurate time, because the other + * clock isn't keeping accurate time, or both. + * + * Note that host-provided time stamps generally correspond to the + * time when the time-stamping code sees the packet; this could + * be some unknown amount of time after the first or last bit of + * the packet is received by the network adapter, due to batching + * of interrupts for packet arrival, queueing delays, etc.. + */ +#define PCAP_TSTAMP_HOST 0 /* host-provided, unknown characteristics */ +#define PCAP_TSTAMP_HOST_LOWPREC 1 /* host-provided, low precision */ +#define PCAP_TSTAMP_HOST_HIPREC 2 /* host-provided, high precision */ +#define PCAP_TSTAMP_ADAPTER 3 /* device-provided, synced with the system clock */ +#define PCAP_TSTAMP_ADAPTER_UNSYNCED 4 /* device-provided, not synced with the system clock */ + +/* + * Time stamp resolution types. + * Not all systems and interfaces will necessarily support all of these + * resolutions when doing live captures; all of them can be requested + * when reading a savefile. + */ +#define PCAP_TSTAMP_PRECISION_MICRO 0 /* use timestamps with microsecond precision, default */ +#define PCAP_TSTAMP_PRECISION_NANO 1 /* use timestamps with nanosecond precision */ + +PCAP_API pcap_t *pcap_open_live(const char *, int, int, int, char *); +PCAP_API pcap_t *pcap_open_dead(int, int); +PCAP_API pcap_t *pcap_open_dead_with_tstamp_precision(int, int, u_int); +PCAP_API pcap_t *pcap_open_offline_with_tstamp_precision(const char *, u_int, char *); +PCAP_API pcap_t *pcap_open_offline(const char *, char *); +#ifdef _WIN32 + PCAP_API pcap_t *pcap_hopen_offline_with_tstamp_precision(intptr_t, u_int, char *); + PCAP_API pcap_t *pcap_hopen_offline(intptr_t, char *); + /* + * If we're building libpcap, these are internal routines in savefile.c, + * so we must not define them as macros. + * + * If we're not building libpcap, given that the version of the C runtime + * with which libpcap was built might be different from the version + * of the C runtime with which an application using libpcap was built, + * and that a FILE structure may differ between the two versions of the + * C runtime, calls to _fileno() must use the version of _fileno() in + * the C runtime used to open the FILE *, not the version in the C + * runtime with which libpcap was built. (Maybe once the Universal CRT + * rules the world, this will cease to be a problem.) + */ + #ifndef BUILDING_PCAP + #define pcap_fopen_offline_with_tstamp_precision(f,p,b) \ + pcap_hopen_offline_with_tstamp_precision(_get_osfhandle(_fileno(f)), p, b) + #define pcap_fopen_offline(f,b) \ + pcap_hopen_offline(_get_osfhandle(_fileno(f)), b) + #endif +#else /*_WIN32*/ + PCAP_API pcap_t *pcap_fopen_offline_with_tstamp_precision(FILE *, u_int, char *); + PCAP_API pcap_t *pcap_fopen_offline(FILE *, char *); +#endif /*_WIN32*/ + +PCAP_API void pcap_close(pcap_t *); +PCAP_API int pcap_loop(pcap_t *, int, pcap_handler, u_char *); +PCAP_API int pcap_dispatch(pcap_t *, int, pcap_handler, u_char *); +PCAP_API const u_char *pcap_next(pcap_t *, struct pcap_pkthdr *); +PCAP_API int pcap_next_ex(pcap_t *, struct pcap_pkthdr **, const u_char **); +PCAP_API void pcap_breakloop(pcap_t *); +PCAP_API int pcap_stats(pcap_t *, struct pcap_stat *); +PCAP_API int pcap_setfilter(pcap_t *, struct bpf_program *); +PCAP_API int pcap_setdirection(pcap_t *, pcap_direction_t); +PCAP_API int pcap_getnonblock(pcap_t *, char *); +PCAP_API int pcap_setnonblock(pcap_t *, int, char *); +PCAP_API int pcap_inject(pcap_t *, const void *, size_t); +PCAP_API int pcap_sendpacket(pcap_t *, const u_char *, int); +PCAP_API const char *pcap_statustostr(int); +PCAP_API const char *pcap_strerror(int); +PCAP_API char *pcap_geterr(pcap_t *); +PCAP_API void pcap_perror(pcap_t *, const char *); +PCAP_API int pcap_compile(pcap_t *, struct bpf_program *, const char *, int, + bpf_u_int32); +PCAP_API int pcap_compile_nopcap(int, int, struct bpf_program *, + const char *, int, bpf_u_int32); +PCAP_API void pcap_freecode(struct bpf_program *); +PCAP_API int pcap_offline_filter(const struct bpf_program *, + const struct pcap_pkthdr *, const u_char *); +PCAP_API int pcap_datalink(pcap_t *); +PCAP_API int pcap_datalink_ext(pcap_t *); +PCAP_API int pcap_list_datalinks(pcap_t *, int **); +PCAP_API int pcap_set_datalink(pcap_t *, int); +PCAP_API void pcap_free_datalinks(int *); +PCAP_API int pcap_datalink_name_to_val(const char *); +PCAP_API const char *pcap_datalink_val_to_name(int); +PCAP_API const char *pcap_datalink_val_to_description(int); +PCAP_API int pcap_snapshot(pcap_t *); +PCAP_API int pcap_is_swapped(pcap_t *); +PCAP_API int pcap_major_version(pcap_t *); +PCAP_API int pcap_minor_version(pcap_t *); +PCAP_API int pcap_bufsize(pcap_t *); + +/* XXX */ +PCAP_API FILE *pcap_file(pcap_t *); +PCAP_API int pcap_fileno(pcap_t *); + +#ifdef _WIN32 + PCAP_API int pcap_wsockinit(void); +#endif + +PCAP_API pcap_dumper_t *pcap_dump_open(pcap_t *, const char *); +PCAP_API pcap_dumper_t *pcap_dump_fopen(pcap_t *, FILE *fp); +PCAP_API pcap_dumper_t *pcap_dump_open_append(pcap_t *, const char *); +PCAP_API FILE *pcap_dump_file(pcap_dumper_t *); +PCAP_API long pcap_dump_ftell(pcap_dumper_t *); +PCAP_API int64_t pcap_dump_ftell64(pcap_dumper_t *); +PCAP_API int pcap_dump_flush(pcap_dumper_t *); +PCAP_API void pcap_dump_close(pcap_dumper_t *); +PCAP_API void pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *); + +PCAP_API int pcap_findalldevs(pcap_if_t **, char *); +PCAP_API void pcap_freealldevs(pcap_if_t *); + +/* + * We return a pointer to the version string, rather than exporting the + * version string directly. + * + * On at least some UNIXes, if you import data from a shared library into + * an program, the data is bound into the program binary, so if the string + * in the version of the library with which the program was linked isn't + * the same as the string in the version of the library with which the + * program is being run, various undesirable things may happen (warnings, + * the string being the one from the version of the library with which the + * program was linked, or even weirder things, such as the string being the + * one from the library but being truncated). + * + * On Windows, the string is constructed at run time. + */ +PCAP_API const char *pcap_lib_version(void); + +/* + * On at least some versions of NetBSD and QNX, we don't want to declare + * bpf_filter() here, as it's also be declared in , with a + * different signature, but, on other BSD-flavored UN*Xes, it's not + * declared in , so we *do* want to declare it here, so it's + * declared when we build pcap-bpf.c. + */ +#if !defined(__NetBSD__) && !defined(__QNX__) + PCAP_API u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int); +#endif +PCAP_API int bpf_validate(const struct bpf_insn *f, int len); +PCAP_API char *bpf_image(const struct bpf_insn *, int); +PCAP_API void bpf_dump(const struct bpf_program *, int); + +#if defined(_WIN32) + + /* + * Win32 definitions + */ + + /*! + \brief A queue of raw packets that will be sent to the network with pcap_sendqueue_transmit(). + */ + struct pcap_send_queue + { + u_int maxlen; /* Maximum size of the queue, in bytes. This + variable contains the size of the buffer field. */ + u_int len; /* Current size of the queue, in bytes. */ + char *buffer; /* Buffer containing the packets to be sent. */ + }; + + typedef struct pcap_send_queue pcap_send_queue; + + /*! + \brief This typedef is a support for the pcap_get_airpcap_handle() function + */ + #if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_) + #define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_ + typedef struct _AirpcapHandle *PAirpcapHandle; + #endif + + PCAP_API int pcap_setbuff(pcap_t *p, int dim); + PCAP_API int pcap_setmode(pcap_t *p, int mode); + PCAP_API int pcap_setmintocopy(pcap_t *p, int size); + + PCAP_API HANDLE pcap_getevent(pcap_t *p); + + PCAP_API int pcap_oid_get_request(pcap_t *, bpf_u_int32, void *, size_t *); + PCAP_API int pcap_oid_set_request(pcap_t *, bpf_u_int32, const void *, size_t *); + + PCAP_API pcap_send_queue* pcap_sendqueue_alloc(u_int memsize); + + PCAP_API void pcap_sendqueue_destroy(pcap_send_queue* queue); + + PCAP_API int pcap_sendqueue_queue(pcap_send_queue* queue, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data); + + PCAP_API u_int pcap_sendqueue_transmit(pcap_t *p, pcap_send_queue* queue, int sync); + + PCAP_API struct pcap_stat *pcap_stats_ex(pcap_t *p, int *pcap_stat_size); + + PCAP_API int pcap_setuserbuffer(pcap_t *p, int size); + + PCAP_API int pcap_live_dump(pcap_t *p, char *filename, int maxsize, int maxpacks); + + PCAP_API int pcap_live_dump_ended(pcap_t *p, int sync); + + PCAP_API int pcap_start_oem(char* err_str, int flags); + + PCAP_API PAirpcapHandle pcap_get_airpcap_handle(pcap_t *p); + + #define MODE_CAPT 0 + #define MODE_STAT 1 + #define MODE_MON 2 + +#elif defined(MSDOS) + + /* + * MS-DOS definitions + */ + + PCAP_API int pcap_stats_ex (pcap_t *, struct pcap_stat_ex *); + PCAP_API void pcap_set_wait (pcap_t *p, void (*yield)(void), int wait); + PCAP_API u_long pcap_mac_packets (void); + +#else /* UN*X */ + + /* + * UN*X definitions + */ + + PCAP_API int pcap_get_selectable_fd(pcap_t *); + +#endif /* _WIN32/MSDOS/UN*X */ + +/* + * Remote capture definitions. + * + * These routines are only present if libpcap has been configured to + * include remote capture support. + */ + +/* + * The maximum buffer size in which address, port, interface names are kept. + * + * In case the adapter name or such is larger than this value, it is truncated. + * This is not used by the user; however it must be aware that an hostname / interface + * name longer than this value will be truncated. + */ +#define PCAP_BUF_SIZE 1024 + +/* + * The type of input source, passed to pcap_open(). + */ +#define PCAP_SRC_FILE 2 /* local savefile */ +#define PCAP_SRC_IFLOCAL 3 /* local network interface */ +#define PCAP_SRC_IFREMOTE 4 /* interface on a remote host, using RPCAP */ + +/* + * The formats allowed by pcap_open() are the following: + * - file://path_and_filename [opens a local file] + * - rpcap://devicename [opens the selected device devices available on the local host, without using the RPCAP protocol] + * - rpcap://host/devicename [opens the selected device available on a remote host] + * - rpcap://host:port/devicename [opens the selected device available on a remote host, using a non-standard port for RPCAP] + * - adaptername [to open a local adapter; kept for compability, but it is strongly discouraged] + * - (NULL) [to open the first local adapter; kept for compability, but it is strongly discouraged] + * + * The formats allowed by the pcap_findalldevs_ex() are the following: + * - file://folder/ [lists all the files in the given folder] + * - rpcap:// [lists all local adapters] + * - rpcap://host:port/ [lists the devices available on a remote host] + * + * Referring to the 'host' and 'port' parameters, they can be either numeric or literal. Since + * IPv6 is fully supported, these are the allowed formats: + * + * - host (literal): e.g. host.foo.bar + * - host (numeric IPv4): e.g. 10.11.12.13 + * - host (numeric IPv4, IPv6 style): e.g. [10.11.12.13] + * - host (numeric IPv6): e.g. [1:2:3::4] + * - port: can be either numeric (e.g. '80') or literal (e.g. 'http') + * + * Here you find some allowed examples: + * - rpcap://host.foo.bar/devicename [everything literal, no port number] + * - rpcap://host.foo.bar:1234/devicename [everything literal, with port number] + * - rpcap://10.11.12.13/devicename [IPv4 numeric, no port number] + * - rpcap://10.11.12.13:1234/devicename [IPv4 numeric, with port number] + * - rpcap://[10.11.12.13]:1234/devicename [IPv4 numeric with IPv6 format, with port number] + * - rpcap://[1:2:3::4]/devicename [IPv6 numeric, no port number] + * - rpcap://[1:2:3::4]:1234/devicename [IPv6 numeric, with port number] + * - rpcap://[1:2:3::4]:http/devicename [IPv6 numeric, with literal port number] + */ + +/* + * URL schemes for capture source. + */ +/* + * This string indicates that the user wants to open a capture from a + * local file. + */ +#define PCAP_SRC_FILE_STRING "file://" +/* + * This string indicates that the user wants to open a capture from a + * network interface. This string does not necessarily involve the use + * of the RPCAP protocol. If the interface required resides on the local + * host, the RPCAP protocol is not involved and the local functions are used. + */ +#define PCAP_SRC_IF_STRING "rpcap://" + +/* + * Flags to pass to pcap_open(). + */ + +/* + * Specifies whether promiscuous mode is to be used. + */ +#define PCAP_OPENFLAG_PROMISCUOUS 0x00000001 + +/* + * Specifies, for an RPCAP capture, whether the data transfer (in + * case of a remote capture) has to be done with UDP protocol. + * + * If it is '1' if you want a UDP data connection, '0' if you want + * a TCP data connection; control connection is always TCP-based. + * A UDP connection is much lighter, but it does not guarantee that all + * the captured packets arrive to the client workstation. Moreover, + * it could be harmful in case of network congestion. + * This flag is meaningless if the source is not a remote interface. + * In that case, it is simply ignored. + */ +#define PCAP_OPENFLAG_DATATX_UDP 0x00000002 + +/* + * Specifies wheether the remote probe will capture its own generated + * traffic. + * + * In case the remote probe uses the same interface to capture traffic + * and to send data back to the caller, the captured traffic includes + * the RPCAP traffic as well. If this flag is turned on, the RPCAP + * traffic is excluded from the capture, so that the trace returned + * back to the collector is does not include this traffic. + * + * Has no effect on local interfaces or savefiles. + */ +#define PCAP_OPENFLAG_NOCAPTURE_RPCAP 0x00000004 + +/* + * Specifies whether the local adapter will capture its own generated traffic. + * + * This flag tells the underlying capture driver to drop the packets + * that were sent by itself. This is useful when building applications + * such as bridges that should ignore the traffic they just sent. + * + * Supported only on Windows. + */ +#define PCAP_OPENFLAG_NOCAPTURE_LOCAL 0x00000008 + +/* + * This flag configures the adapter for maximum responsiveness. + * + * In presence of a large value for nbytes, WinPcap waits for the arrival + * of several packets before copying the data to the user. This guarantees + * a low number of system calls, i.e. lower processor usage, i.e. better + * performance, which is good for applications like sniffers. If the user + * sets the PCAP_OPENFLAG_MAX_RESPONSIVENESS flag, the capture driver will + * copy the packets as soon as the application is ready to receive them. + * This is suggested for real time applications (such as, for example, + * a bridge) that need the best responsiveness. + * + * The equivalent with pcap_create()/pcap_activate() is "immediate mode". + */ +#define PCAP_OPENFLAG_MAX_RESPONSIVENESS 0x00000010 + +/* + * Remote authentication methods. + * These are used in the 'type' member of the pcap_rmtauth structure. + */ + +/* + * NULL authentication. + * + * The 'NULL' authentication has to be equal to 'zero', so that old + * applications can just put every field of struct pcap_rmtauth to zero, + * and it does work. + */ +#define RPCAP_RMTAUTH_NULL 0 +/* + * Username/password authentication. + * + * With this type of authentication, the RPCAP protocol will use the username/ + * password provided to authenticate the user on the remote machine. If the + * authentication is successful (and the user has the right to open network + * devices) the RPCAP connection will continue; otherwise it will be dropped. + * + * *******NOTE********: the username and password are sent over the network + * to the capture server *IN CLEAR TEXT*. Don't use this on a network + * that you don't completely control! (And be *really* careful in your + * definition of "completely"!) + */ +#define RPCAP_RMTAUTH_PWD 1 + +/* + * This structure keeps the information needed to autheticate the user + * on a remote machine. + * + * The remote machine can either grant or refuse the access according + * to the information provided. + * In case the NULL authentication is required, both 'username' and + * 'password' can be NULL pointers. + * + * This structure is meaningless if the source is not a remote interface; + * in that case, the functions which requires such a structure can accept + * a NULL pointer as well. + */ +struct pcap_rmtauth +{ + /* + * \brief Type of the authentication required. + * + * In order to provide maximum flexibility, we can support different types + * of authentication based on the value of this 'type' variable. The currently + * supported authentication methods are defined into the + * \link remote_auth_methods Remote Authentication Methods Section\endlink. + */ + int type; + /* + * \brief Zero-terminated string containing the username that has to be + * used on the remote machine for authentication. + * + * This field is meaningless in case of the RPCAP_RMTAUTH_NULL authentication + * and it can be NULL. + */ + char *username; + /* + * \brief Zero-terminated string containing the password that has to be + * used on the remote machine for authentication. + * + * This field is meaningless in case of the RPCAP_RMTAUTH_NULL authentication + * and it can be NULL. + */ + char *password; +}; + +/* + * This routine can open a savefile, a local device, or a device on + * a remote machine running an RPCAP server. + * + * For opening a savefile, the pcap_open_offline routines can be used, + * and will work just as well; code using them will work on more + * platforms than code using pcap_open() to open savefiles. + * + * For opening a local device, pcap_open_live() can be used; it supports + * most of the capabilities that pcap_open() supports, and code using it + * will work on more platforms than code using pcap_open(). pcap_create() + * and pcap_activate() can also be used; they support all capabilities + * that pcap_open() supports, except for the Windows-only + * PCAP_OPENFLAG_NOCAPTURE_LOCAL, and support additional capabilities. + * + * For opening a remote capture, pcap_open() is currently the only + * API available. + */ +PCAP_API pcap_t *pcap_open(const char *source, int snaplen, int flags, + int read_timeout, struct pcap_rmtauth *auth, char *errbuf); +PCAP_API int pcap_createsrcstr(char *source, int type, const char *host, + const char *port, const char *name, char *errbuf); +PCAP_API int pcap_parsesrcstr(const char *source, int *type, char *host, + char *port, char *name, char *errbuf); + +/* + * This routine can scan a directory for savefiles, list local capture + * devices, or list capture devices on a remote machine running an RPCAP + * server. + * + * For scanning for savefiles, it can be used on both UN*X systems and + * Windows systems; for each directory entry it sees, it tries to open + * the file as a savefile using pcap_open_offline(), and only includes + * it in the list of files if the open succeeds, so it filters out + * files for which the user doesn't have read permission, as well as + * files that aren't valid savefiles readable by libpcap. + * + * For listing local capture devices, it's just a wrapper around + * pcap_findalldevs(); code using pcap_findalldevs() will work on more + * platforms than code using pcap_findalldevs_ex(). + * + * For listing remote capture devices, pcap_findalldevs_ex() is currently + * the only API available. + */ +PCAP_API int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, + pcap_if_t **alldevs, char *errbuf); + +/* + * Sampling methods. + * + * These allow pcap_loop(), pcap_dispatch(), pcap_next(), and pcap_next_ex() + * to see only a sample of packets, rather than all packets. + * + * Currently, they work only on Windows local captures. + */ + +/* + * Specifies that no sampling is to be done on the current capture. + * + * In this case, no sampling algorithms are applied to the current capture. + */ +#define PCAP_SAMP_NOSAMP 0 + +/* + * Specifies that only 1 out of N packets must be returned to the user. + * + * In this case, the 'value' field of the 'pcap_samp' structure indicates the + * number of packets (minus 1) that must be discarded before one packet got + * accepted. + * In other words, if 'value = 10', the first packet is returned to the + * caller, while the following 9 are discarded. + */ +#define PCAP_SAMP_1_EVERY_N 1 + +/* + * Specifies that we have to return 1 packet every N milliseconds. + * + * In this case, the 'value' field of the 'pcap_samp' structure indicates + * the 'waiting time' in milliseconds before one packet got accepted. + * In other words, if 'value = 10', the first packet is returned to the + * caller; the next returned one will be the first packet that arrives + * when 10ms have elapsed. + */ +#define PCAP_SAMP_FIRST_AFTER_N_MS 2 + +/* + * This structure defines the information related to sampling. + * + * In case the sampling is requested, the capturing device should read + * only a subset of the packets coming from the source. The returned packets + * depend on the sampling parameters. + * + * WARNING: The sampling process is applied *after* the filtering process. + * In other words, packets are filtered first, then the sampling process + * selects a subset of the 'filtered' packets and it returns them to the + * caller. + */ +struct pcap_samp +{ + /* + * Method used for sampling; see above. + */ + int method; + + /* + * This value depends on the sampling method defined. + * For its meaning, see above. + */ + int value; +}; + +/* + * New functions. + */ +PCAP_API struct pcap_samp *pcap_setsampling(pcap_t *p); + +/* + * RPCAP active mode. + */ + +/* Maximum length of an host name (needed for the RPCAP active mode) */ +#define RPCAP_HOSTLIST_SIZE 1024 + +/* + * Some minor differences between UN*X sockets and and Winsock sockets. + */ +#ifndef _WIN32 + /*! + * \brief In Winsock, a socket handle is of type SOCKET; in UN*X, it's + * a file descriptor, and therefore a signed integer. + * We define SOCKET to be a signed integer on UN*X, so that it can + * be used on both platforms. + */ + #define SOCKET int + + /*! + * \brief In Winsock, the error return if socket() fails is INVALID_SOCKET; + * in UN*X, it's -1. + * We define INVALID_SOCKET to be -1 on UN*X, so that it can be used on + * both platforms. + */ + #define INVALID_SOCKET -1 +#endif + +PCAP_API SOCKET pcap_remoteact_accept(const char *address, const char *port, + const char *hostlist, char *connectinghost, + struct pcap_rmtauth *auth, char *errbuf); +PCAP_API int pcap_remoteact_list(char *hostlist, char sep, int size, + char *errbuf); +PCAP_API int pcap_remoteact_close(const char *host, char *errbuf); +PCAP_API void pcap_remoteact_cleanup(void); + +#ifdef __cplusplus +} +#endif + +#endif /* lib_pcap_pcap_h */ diff --git a/src/frontend/qt_sdl/pcap/sll.h b/src/frontend/qt_sdl/pcap/sll.h new file mode 100644 index 0000000..c4d0886 --- /dev/null +++ b/src/frontend/qt_sdl/pcap/sll.h @@ -0,0 +1,131 @@ +/*- + * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from the Stanford/CMU enet packet filter, + * (net/enet.c) distributed as part of 4.3BSD, and code contributed + * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence + * Berkeley Laboratory. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * For captures on Linux cooked sockets, we construct a fake header + * that includes: + * + * a 2-byte "packet type" which is one of: + * + * LINUX_SLL_HOST packet was sent to us + * LINUX_SLL_BROADCAST packet was broadcast + * LINUX_SLL_MULTICAST packet was multicast + * LINUX_SLL_OTHERHOST packet was sent to somebody else + * LINUX_SLL_OUTGOING packet was sent *by* us; + * + * a 2-byte Ethernet protocol field; + * + * a 2-byte link-layer type; + * + * a 2-byte link-layer address length; + * + * an 8-byte source link-layer address, whose actual length is + * specified by the previous value. + * + * All fields except for the link-layer address are in network byte order. + * + * DO NOT change the layout of this structure, or change any of the + * LINUX_SLL_ values below. If you must change the link-layer header + * for a "cooked" Linux capture, introduce a new DLT_ type (ask + * "tcpdump-workers@lists.tcpdump.org" for one, so that you don't give it + * a value that collides with a value already being used), and use the + * new header in captures of that type, so that programs that can + * handle DLT_LINUX_SLL captures will continue to handle them correctly + * without any change, and so that capture files with different headers + * can be told apart and programs that read them can dissect the + * packets in them. + */ + +#ifndef lib_pcap_sll_h +#define lib_pcap_sll_h + +/* + * A DLT_LINUX_SLL fake link-layer header. + */ +#define SLL_HDR_LEN 16 /* total header length */ +#define SLL_ADDRLEN 8 /* length of address field */ + +#include + +struct sll_header { + uint16_t sll_pkttype; /* packet type */ + uint16_t sll_hatype; /* link-layer address type */ + uint16_t sll_halen; /* link-layer address length */ + uint8_t sll_addr[SLL_ADDRLEN]; /* link-layer address */ + uint16_t sll_protocol; /* protocol */ +}; + +/* + * The LINUX_SLL_ values for "sll_pkttype"; these correspond to the + * PACKET_ values on Linux, but are defined here so that they're + * available even on systems other than Linux, and so that they + * don't change even if the PACKET_ values change. + */ +#define LINUX_SLL_HOST 0 +#define LINUX_SLL_BROADCAST 1 +#define LINUX_SLL_MULTICAST 2 +#define LINUX_SLL_OTHERHOST 3 +#define LINUX_SLL_OUTGOING 4 + +/* + * The LINUX_SLL_ values for "sll_protocol"; these correspond to the + * ETH_P_ values on Linux, but are defined here so that they're + * available even on systems other than Linux. We assume, for now, + * that the ETH_P_ values won't change in Linux; if they do, then: + * + * if we don't translate them in "pcap-linux.c", capture files + * won't necessarily be readable if captured on a system that + * defines ETH_P_ values that don't match these values; + * + * if we do translate them in "pcap-linux.c", that makes life + * unpleasant for the BPF code generator, as the values you test + * for in the kernel aren't the values that you test for when + * reading a capture file, so the fixup code run on BPF programs + * handed to the kernel ends up having to do more work. + * + * Add other values here as necessary, for handling packet types that + * might show up on non-Ethernet, non-802.x networks. (Not all the ones + * in the Linux "if_ether.h" will, I suspect, actually show up in + * captures.) + */ +#define LINUX_SLL_P_802_3 0x0001 /* Novell 802.3 frames without 802.2 LLC header */ +#define LINUX_SLL_P_802_2 0x0004 /* 802.2 frames (not D/I/X Ethernet) */ +#define LINUX_SLL_P_CAN 0x000C /* CAN frames, with SocketCAN pseudo-headers */ +#define LINUX_SLL_P_CANFD 0x000D /* CAN FD frames, with SocketCAN pseudo-headers */ + +#endif diff --git a/src/frontend/qt_sdl/pcap/usb.h b/src/frontend/qt_sdl/pcap/usb.h new file mode 100644 index 0000000..e485ec8 --- /dev/null +++ b/src/frontend/qt_sdl/pcap/usb.h @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2006 Paolo Abeni (Italy) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Basic USB data struct + * By Paolo Abeni + */ + +#ifndef lib_pcap_usb_h +#define lib_pcap_usb_h + +#include + +/* + * possible transfer mode + */ +#define URB_TRANSFER_IN 0x80 +#define URB_ISOCHRONOUS 0x0 +#define URB_INTERRUPT 0x1 +#define URB_CONTROL 0x2 +#define URB_BULK 0x3 + +/* + * possible event type + */ +#define URB_SUBMIT 'S' +#define URB_COMPLETE 'C' +#define URB_ERROR 'E' + +/* + * USB setup header as defined in USB specification. + * Appears at the front of each Control S-type packet in DLT_USB captures. + */ +typedef struct _usb_setup { + uint8_t bmRequestType; + uint8_t bRequest; + uint16_t wValue; + uint16_t wIndex; + uint16_t wLength; +} pcap_usb_setup; + +/* + * Information from the URB for Isochronous transfers. + */ +typedef struct _iso_rec { + int32_t error_count; + int32_t numdesc; +} iso_rec; + +/* + * Header prepended by linux kernel to each event. + * Appears at the front of each packet in DLT_USB_LINUX captures. + */ +typedef struct _usb_header { + uint64_t id; + uint8_t event_type; + uint8_t transfer_type; + uint8_t endpoint_number; + uint8_t device_address; + uint16_t bus_id; + char setup_flag;/*if !=0 the urb setup header is not present*/ + char data_flag; /*if !=0 no urb data is present*/ + int64_t ts_sec; + int32_t ts_usec; + int32_t status; + uint32_t urb_len; + uint32_t data_len; /* amount of urb data really present in this event*/ + pcap_usb_setup setup; +} pcap_usb_header; + +/* + * Header prepended by linux kernel to each event for the 2.6.31 + * and later kernels; for the 2.6.21 through 2.6.30 kernels, the + * "iso_rec" information, and the fields starting with "interval" + * are zeroed-out padding fields. + * + * Appears at the front of each packet in DLT_USB_LINUX_MMAPPED captures. + */ +typedef struct _usb_header_mmapped { + uint64_t id; + uint8_t event_type; + uint8_t transfer_type; + uint8_t endpoint_number; + uint8_t device_address; + uint16_t bus_id; + char setup_flag;/*if !=0 the urb setup header is not present*/ + char data_flag; /*if !=0 no urb data is present*/ + int64_t ts_sec; + int32_t ts_usec; + int32_t status; + uint32_t urb_len; + uint32_t data_len; /* amount of urb data really present in this event*/ + union { + pcap_usb_setup setup; + iso_rec iso; + } s; + int32_t interval; /* for Interrupt and Isochronous events */ + int32_t start_frame; /* for Isochronous events */ + uint32_t xfer_flags; /* copy of URB's transfer flags */ + uint32_t ndesc; /* number of isochronous descriptors */ +} pcap_usb_header_mmapped; + +/* + * Isochronous descriptors; for isochronous transfers there might be + * one or more of these at the beginning of the packet data. The + * number of descriptors is given by the "ndesc" field in the header; + * as indicated, in older kernels that don't put the descriptors at + * the beginning of the packet, that field is zeroed out, so that field + * can be trusted even in captures from older kernels. + */ +typedef struct _usb_isodesc { + int32_t status; + uint32_t offset; + uint32_t len; + uint8_t pad[4]; +} usb_isodesc; + +#endif diff --git a/src/frontend/qt_sdl/pcap/vlan.h b/src/frontend/qt_sdl/pcap/vlan.h new file mode 100644 index 0000000..b29dd73 --- /dev/null +++ b/src/frontend/qt_sdl/pcap/vlan.h @@ -0,0 +1,46 @@ +/*- + * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lib_pcap_vlan_h +#define lib_pcap_vlan_h + +#include + +struct vlan_tag { + uint16_t vlan_tpid; /* ETH_P_8021Q */ + uint16_t vlan_tci; /* VLAN TCI */ +}; + +#define VLAN_TAG_LEN 4 + +#endif diff --git a/src/pcap/bluetooth.h b/src/pcap/bluetooth.h deleted file mode 100644 index 15dc5a8..0000000 --- a/src/pcap/bluetooth.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2006 Paolo Abeni (Italy) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * bluetooth data struct - * By Paolo Abeni - */ - -#ifndef lib_pcap_bluetooth_h -#define lib_pcap_bluetooth_h - -#include - -/* - * Header prepended libpcap to each bluetooth h4 frame, - * fields are in network byte order - */ -typedef struct _pcap_bluetooth_h4_header { - uint32_t direction; /* if first bit is set direction is incoming */ -} pcap_bluetooth_h4_header; - -/* - * Header prepended libpcap to each bluetooth linux monitor frame, - * fields are in network byte order - */ -typedef struct _pcap_bluetooth_linux_monitor_header { - uint16_t adapter_id; - uint16_t opcode; -} pcap_bluetooth_linux_monitor_header; - -#endif diff --git a/src/pcap/bpf.h b/src/pcap/bpf.h deleted file mode 100644 index 1a953a9..0000000 --- a/src/pcap/bpf.h +++ /dev/null @@ -1,270 +0,0 @@ -/*- - * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from the Stanford/CMU enet packet filter, - * (net/enet.c) distributed as part of 4.3BSD, and code contributed - * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence - * Berkeley Laboratory. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)bpf.h 7.1 (Berkeley) 5/7/91 - */ - -/* - * This is libpcap's cut-down version of bpf.h; it includes only - * the stuff needed for the code generator and the userland BPF - * interpreter, and the libpcap APIs for setting filters, etc.. - * - * "pcap-bpf.c" will include the native OS version, as it deals with - * the OS's BPF implementation. - * - * At least two programs found by Google Code Search explicitly includes - * (even though / includes it for you), - * so moving that stuff to would break the build for some - * programs. - */ - -/* - * If we've already included , don't re-define this stuff. - * We assume BSD-style multiple-include protection in , - * which is true of all but the oldest versions of FreeBSD and NetBSD, - * or Tru64 UNIX-style multiple-include protection (or, at least, - * Tru64 UNIX 5.x-style; I don't have earlier versions available to check), - * or AIX-style multiple-include protection (or, at least, AIX 5.x-style; - * I don't have earlier versions available to check), or QNX-style - * multiple-include protection (as per GitHub pull request #394). - * - * We do not check for BPF_MAJOR_VERSION, as that's defined by - * , which is directly or indirectly included in some - * programs that also include pcap.h, and doesn't - * define stuff we need. - * - * This also provides our own multiple-include protection. - */ -#if !defined(_NET_BPF_H_) && !defined(_NET_BPF_H_INCLUDED) && !defined(_BPF_H_) && !defined(_H_BPF) && !defined(lib_pcap_bpf_h) -#define lib_pcap_bpf_h - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* BSD style release date */ -#define BPF_RELEASE 199606 - -#ifdef MSDOS /* must be 32-bit */ -typedef long bpf_int32; -typedef unsigned long bpf_u_int32; -#else -typedef int bpf_int32; -typedef u_int bpf_u_int32; -#endif - -/* - * Alignment macros. BPF_WORDALIGN rounds up to the next - * even multiple of BPF_ALIGNMENT. - * - * Tcpdump's print-pflog.c uses this, so we define it here. - */ -#ifndef __NetBSD__ -#define BPF_ALIGNMENT sizeof(bpf_int32) -#else -#define BPF_ALIGNMENT sizeof(long) -#endif -#define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1)) - -/* - * Structure for "pcap_compile()", "pcap_setfilter()", etc.. - */ -struct bpf_program { - u_int bf_len; - struct bpf_insn *bf_insns; -}; - -#include - -/* - * The instruction encodings. - * - * Please inform tcpdump-workers@lists.tcpdump.org if you use any - * of the reserved values, so that we can note that they're used - * (and perhaps implement it in the reference BPF implementation - * and encourage its implementation elsewhere). - */ - -/* - * The upper 8 bits of the opcode aren't used. BSD/OS used 0x8000. - */ - -/* instruction classes */ -#define BPF_CLASS(code) ((code) & 0x07) -#define BPF_LD 0x00 -#define BPF_LDX 0x01 -#define BPF_ST 0x02 -#define BPF_STX 0x03 -#define BPF_ALU 0x04 -#define BPF_JMP 0x05 -#define BPF_RET 0x06 -#define BPF_MISC 0x07 - -/* ld/ldx fields */ -#define BPF_SIZE(code) ((code) & 0x18) -#define BPF_W 0x00 -#define BPF_H 0x08 -#define BPF_B 0x10 -/* 0x18 reserved; used by BSD/OS */ -#define BPF_MODE(code) ((code) & 0xe0) -#define BPF_IMM 0x00 -#define BPF_ABS 0x20 -#define BPF_IND 0x40 -#define BPF_MEM 0x60 -#define BPF_LEN 0x80 -#define BPF_MSH 0xa0 -/* 0xc0 reserved; used by BSD/OS */ -/* 0xe0 reserved; used by BSD/OS */ - -/* alu/jmp fields */ -#define BPF_OP(code) ((code) & 0xf0) -#define BPF_ADD 0x00 -#define BPF_SUB 0x10 -#define BPF_MUL 0x20 -#define BPF_DIV 0x30 -#define BPF_OR 0x40 -#define BPF_AND 0x50 -#define BPF_LSH 0x60 -#define BPF_RSH 0x70 -#define BPF_NEG 0x80 -#define BPF_MOD 0x90 -#define BPF_XOR 0xa0 -/* 0xb0 reserved */ -/* 0xc0 reserved */ -/* 0xd0 reserved */ -/* 0xe0 reserved */ -/* 0xf0 reserved */ - -#define BPF_JA 0x00 -#define BPF_JEQ 0x10 -#define BPF_JGT 0x20 -#define BPF_JGE 0x30 -#define BPF_JSET 0x40 -/* 0x50 reserved; used on BSD/OS */ -/* 0x60 reserved */ -/* 0x70 reserved */ -/* 0x80 reserved */ -/* 0x90 reserved */ -/* 0xa0 reserved */ -/* 0xb0 reserved */ -/* 0xc0 reserved */ -/* 0xd0 reserved */ -/* 0xe0 reserved */ -/* 0xf0 reserved */ -#define BPF_SRC(code) ((code) & 0x08) -#define BPF_K 0x00 -#define BPF_X 0x08 - -/* ret - BPF_K and BPF_X also apply */ -#define BPF_RVAL(code) ((code) & 0x18) -#define BPF_A 0x10 -/* 0x18 reserved */ - -/* misc */ -#define BPF_MISCOP(code) ((code) & 0xf8) -#define BPF_TAX 0x00 -/* 0x08 reserved */ -/* 0x10 reserved */ -/* 0x18 reserved */ -/* #define BPF_COP 0x20 NetBSD "coprocessor" extensions */ -/* 0x28 reserved */ -/* 0x30 reserved */ -/* 0x38 reserved */ -/* #define BPF_COPX 0x40 NetBSD "coprocessor" extensions */ -/* also used on BSD/OS */ -/* 0x48 reserved */ -/* 0x50 reserved */ -/* 0x58 reserved */ -/* 0x60 reserved */ -/* 0x68 reserved */ -/* 0x70 reserved */ -/* 0x78 reserved */ -#define BPF_TXA 0x80 -/* 0x88 reserved */ -/* 0x90 reserved */ -/* 0x98 reserved */ -/* 0xa0 reserved */ -/* 0xa8 reserved */ -/* 0xb0 reserved */ -/* 0xb8 reserved */ -/* 0xc0 reserved; used on BSD/OS */ -/* 0xc8 reserved */ -/* 0xd0 reserved */ -/* 0xd8 reserved */ -/* 0xe0 reserved */ -/* 0xe8 reserved */ -/* 0xf0 reserved */ -/* 0xf8 reserved */ - -/* - * The instruction data structure. - */ -struct bpf_insn { - u_short code; - u_char jt; - u_char jf; - bpf_u_int32 k; -}; - -/* - * Auxiliary data, for use when interpreting a filter intended for the - * Linux kernel when the kernel rejects the filter (requiring us to - * run it in userland). It contains VLAN tag information. - */ -struct bpf_aux_data { - u_short vlan_tag_present; - u_short vlan_tag; -}; - -/* - * Macros for insn array initializers. - */ -#define BPF_STMT(code, k) { (u_short)(code), 0, 0, k } -#define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k } - -PCAP_API int bpf_validate(const struct bpf_insn *, int); -PCAP_API u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int); -extern u_int bpf_filter_with_aux_data(const struct bpf_insn *, const u_char *, u_int, u_int, const struct bpf_aux_data *); - -/* - * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST). - */ -#define BPF_MEMWORDS 16 - -#ifdef __cplusplus -} -#endif - -#endif /* !defined(_NET_BPF_H_) && !defined(_BPF_H_) && !defined(_H_BPF) && !defined(lib_pcap_bpf_h) */ diff --git a/src/pcap/can_socketcan.h b/src/pcap/can_socketcan.h deleted file mode 100644 index 332d9ff..0000000 --- a/src/pcap/can_socketcan.h +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from the Stanford/CMU enet packet filter, - * (net/enet.c) distributed as part of 4.3BSD, and code contributed - * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence - * Berkeley Laboratory. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lib_pcap_can_socketcan_h -#define lib_pcap_can_socketcan_h - -#include - -/* - * SocketCAN header, as per Documentation/networking/can.txt in the - * Linux source. - */ -typedef struct { - uint32_t can_id; - uint8_t payload_length; - uint8_t pad; - uint8_t reserved1; - uint8_t reserved2; -} pcap_can_socketcan_hdr; - -#endif diff --git a/src/pcap/compiler-tests.h b/src/pcap/compiler-tests.h deleted file mode 100644 index 8876c67..0000000 --- a/src/pcap/compiler-tests.h +++ /dev/null @@ -1,152 +0,0 @@ -/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */ -/* - * Copyright (c) 1993, 1994, 1995, 1996, 1997 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the Computer Systems - * Engineering Group at Lawrence Berkeley Laboratory. - * 4. Neither the name of the University nor of the Laboratory may be used - * to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lib_pcap_compiler_tests_h -#define lib_pcap_compiler_tests_h - - -/* - * This was introduced by Clang: - * - * http://clang.llvm.org/docs/LanguageExtensions.html#has-attribute - * - * in some version (which version?); it has been picked up by GCC 5.0. - */ -#ifndef __has_attribute - /* - * It's a macro, so you can check whether it's defined to check - * whether it's supported. - * - * If it's not, define it to always return 0, so that we move on to - * the fallback checks. - */ - #define __has_attribute(x) 0 -#endif - -/* - * Note that the C90 spec's "6.8.1 Conditional inclusion" and the - * C99 spec's and C11 spec's "6.10.1 Conditional inclusion" say: - * - * Prior to evaluation, macro invocations in the list of preprocessing - * tokens that will become the controlling constant expression are - * replaced (except for those macro names modified by the defined unary - * operator), just as in normal text. If the token "defined" is - * generated as a result of this replacement process or use of the - * "defined" unary operator does not match one of the two specified - * forms prior to macro replacement, the behavior is undefined. - * - * so you shouldn't use defined() in a #define that's used in #if or - * #elif. Some versions of Clang, for example, will warn about this. - * - * Instead, we check whether the pre-defined macros for particular - * compilers are defined and, if not, define the "is this version XXX - * or a later version of this compiler" macros as 0. - */ - -/* - * Check whether this is GCC major.minor or a later release, or some - * compiler that claims to be "just like GCC" of that version or a - * later release. - */ - -#if ! defined(__GNUC__) -#define PCAP_IS_AT_LEAST_GNUC_VERSION(major, minor) 0 -#else -#define PCAP_IS_AT_LEAST_GNUC_VERSION(major, minor) \ - (__GNUC__ > (major) || \ - (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) -#endif - -/* - * Check whether this is Sun C/SunPro C/Oracle Studio major.minor - * or a later release. - * - * The version number in __SUNPRO_C is encoded in hex BCD, with the - * uppermost hex digit being the major version number, the next - * one or two hex digits being the minor version number, and - * the last digit being the patch version. - * - * It represents the *compiler* version, not the product version; - * see - * - * https://sourceforge.net/p/predef/wiki/Compilers/ - * - * for a partial mapping, which we assume continues for later - * 12.x product releases. - */ - -#if ! defined(__SUNPRO_C) -#define PCAP_IS_AT_LEAST_SUNC_VERSION(major,minor) 0 -#else -#define PCAP_SUNPRO_VERSION_TO_BCD(major, minor) \ - (((minor) >= 10) ? \ - (((major) << 12) | (((minor)/10) << 8) | (((minor)%10) << 4)) : \ - (((major) << 8) | ((minor) << 4))) -#define PCAP_IS_AT_LEAST_SUNC_VERSION(major,minor) \ - (__SUNPRO_C >= PCAP_SUNPRO_VERSION_TO_BCD((major), (minor))) -#endif - -/* - * Check whether this is IBM XL C major.minor or a later release. - * - * The version number in __xlC__ has the major version in the - * upper 8 bits and the minor version in the lower 8 bits. - */ - -#if ! defined(__xlC__) -#define PCAP_IS_AT_LEAST_XL_C_VERSION(major,minor) 0 -#else -#define PCAP_IS_AT_LEAST_XL_C_VERSION(major, minor) \ - (__xlC__ >= (((major) << 8) | (minor))) -#endif - -/* - * Check whether this is HP aC++/HP C major.minor or a later release. - * - * The version number in __HP_aCC is encoded in zero-padded decimal BCD, - * with the "A." stripped off, the uppermost two decimal digits being - * the major version number, the next two decimal digits being the minor - * version number, and the last two decimal digits being the patch version. - * (Strip off the A., remove the . between the major and minor version - * number, and add two digits of patch.) - */ - -#if ! defined(__HP_aCC) -#define PCAP_IS_AT_LEAST_HP_C_VERSION(major,minor) 0 -#else -#define PCAP_IS_AT_LEAST_HP_C_VERSION(major,minor) \ - (__HP_aCC >= ((major)*10000 + (minor)*100)) -#endif - -#endif /* lib_pcap_funcattrs_h */ diff --git a/src/pcap/dlt.h b/src/pcap/dlt.h deleted file mode 100644 index 609bcaf..0000000 --- a/src/pcap/dlt.h +++ /dev/null @@ -1,1389 +0,0 @@ -/*- - * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from the Stanford/CMU enet packet filter, - * (net/enet.c) distributed as part of 4.3BSD, and code contributed - * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence - * Berkeley Laboratory. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)bpf.h 7.1 (Berkeley) 5/7/91 - */ - -#ifndef lib_pcap_dlt_h -#define lib_pcap_dlt_h - -/* - * Link-layer header type codes. - * - * Do *NOT* add new values to this list without asking - * "tcpdump-workers@lists.tcpdump.org" for a value. Otherwise, you run - * the risk of using a value that's already being used for some other - * purpose, and of having tools that read libpcap-format captures not - * being able to handle captures with your new DLT_ value, with no hope - * that they will ever be changed to do so (as that would destroy their - * ability to read captures using that value for that other purpose). - * - * See - * - * http://www.tcpdump.org/linktypes.html - * - * for detailed descriptions of some of these link-layer header types. - */ - -/* - * These are the types that are the same on all platforms, and that - * have been defined by for ages. - */ -#define DLT_NULL 0 /* BSD loopback encapsulation */ -#define DLT_EN10MB 1 /* Ethernet (10Mb) */ -#define DLT_EN3MB 2 /* Experimental Ethernet (3Mb) */ -#define DLT_AX25 3 /* Amateur Radio AX.25 */ -#define DLT_PRONET 4 /* Proteon ProNET Token Ring */ -#define DLT_CHAOS 5 /* Chaos */ -#define DLT_IEEE802 6 /* 802.5 Token Ring */ -#define DLT_ARCNET 7 /* ARCNET, with BSD-style header */ -#define DLT_SLIP 8 /* Serial Line IP */ -#define DLT_PPP 9 /* Point-to-point Protocol */ -#define DLT_FDDI 10 /* FDDI */ - -/* - * These are types that are different on some platforms, and that - * have been defined by for ages. We use #ifdefs to - * detect the BSDs that define them differently from the traditional - * libpcap - * - * XXX - DLT_ATM_RFC1483 is 13 in BSD/OS, and DLT_RAW is 14 in BSD/OS, - * but I don't know what the right #define is for BSD/OS. - */ -#define DLT_ATM_RFC1483 11 /* LLC-encapsulated ATM */ - -#ifdef __OpenBSD__ -#define DLT_RAW 14 /* raw IP */ -#else -#define DLT_RAW 12 /* raw IP */ -#endif - -/* - * Given that the only OS that currently generates BSD/OS SLIP or PPP - * is, well, BSD/OS, arguably everybody should have chosen its values - * for DLT_SLIP_BSDOS and DLT_PPP_BSDOS, which are 15 and 16, but they - * didn't. So it goes. - */ -#if defined(__NetBSD__) || defined(__FreeBSD__) -#ifndef DLT_SLIP_BSDOS -#define DLT_SLIP_BSDOS 13 /* BSD/OS Serial Line IP */ -#define DLT_PPP_BSDOS 14 /* BSD/OS Point-to-point Protocol */ -#endif -#else -#define DLT_SLIP_BSDOS 15 /* BSD/OS Serial Line IP */ -#define DLT_PPP_BSDOS 16 /* BSD/OS Point-to-point Protocol */ -#endif - -/* - * 17 was used for DLT_PFLOG in OpenBSD; it no longer is. - * - * It was DLT_LANE8023 in SuSE 6.3, so we defined LINKTYPE_PFLOG - * as 117 so that pflog captures would use a link-layer header type - * value that didn't collide with any other values. On all - * platforms other than OpenBSD, we defined DLT_PFLOG as 117, - * and we mapped between LINKTYPE_PFLOG and DLT_PFLOG. - * - * OpenBSD eventually switched to using 117 for DLT_PFLOG as well. - * - * Don't use 17 for anything else. - */ - -/* - * 18 is used for DLT_PFSYNC in OpenBSD, NetBSD, DragonFly BSD and - * Mac OS X; don't use it for anything else. (FreeBSD uses 121, - * which collides with DLT_HHDLC, even though it doesn't use 18 - * for anything and doesn't appear to have ever used it for anything.) - * - * We define it as 18 on those platforms; it is, unfortunately, used - * for DLT_CIP in Suse 6.3, so we don't define it as DLT_PFSYNC - * in general. As the packet format for it, like that for - * DLT_PFLOG, is not only OS-dependent but OS-version-dependent, - * we don't support printing it in tcpdump except on OSes that - * have the relevant header files, so it's not that useful on - * other platforms. - */ -#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__APPLE__) -#define DLT_PFSYNC 18 -#endif - -#define DLT_ATM_CLIP 19 /* Linux Classical-IP over ATM */ - -/* - * Apparently Redback uses this for its SmartEdge 400/800. I hope - * nobody else decided to use it, too. - */ -#define DLT_REDBACK_SMARTEDGE 32 - -/* - * These values are defined by NetBSD; other platforms should refrain from - * using them for other purposes, so that NetBSD savefiles with link - * types of 50 or 51 can be read as this type on all platforms. - */ -#define DLT_PPP_SERIAL 50 /* PPP over serial with HDLC encapsulation */ -#define DLT_PPP_ETHER 51 /* PPP over Ethernet */ - -/* - * The Axent Raptor firewall - now the Symantec Enterprise Firewall - uses - * a link-layer type of 99 for the tcpdump it supplies. The link-layer - * header has 6 bytes of unknown data, something that appears to be an - * Ethernet type, and 36 bytes that appear to be 0 in at least one capture - * I've seen. - */ -#define DLT_SYMANTEC_FIREWALL 99 - -/* - * Values between 100 and 103 are used in capture file headers as - * link-layer header type LINKTYPE_ values corresponding to DLT_ types - * that differ between platforms; don't use those values for new DLT_ - * new types. - */ - -/* - * Values starting with 104 are used for newly-assigned link-layer - * header type values; for those link-layer header types, the DLT_ - * value returned by pcap_datalink() and passed to pcap_open_dead(), - * and the LINKTYPE_ value that appears in capture files, are the - * same. - * - * DLT_MATCHING_MIN is the lowest such value; DLT_MATCHING_MAX is - * the highest such value. - */ -#define DLT_MATCHING_MIN 104 - -/* - * This value was defined by libpcap 0.5; platforms that have defined - * it with a different value should define it here with that value - - * a link type of 104 in a save file will be mapped to DLT_C_HDLC, - * whatever value that happens to be, so programs will correctly - * handle files with that link type regardless of the value of - * DLT_C_HDLC. - * - * The name DLT_C_HDLC was used by BSD/OS; we use that name for source - * compatibility with programs written for BSD/OS. - * - * libpcap 0.5 defined it as DLT_CHDLC; we define DLT_CHDLC as well, - * for source compatibility with programs written for libpcap 0.5. - */ -#define DLT_C_HDLC 104 /* Cisco HDLC */ -#define DLT_CHDLC DLT_C_HDLC - -#define DLT_IEEE802_11 105 /* IEEE 802.11 wireless */ - -/* - * 106 is reserved for Linux Classical IP over ATM; it's like DLT_RAW, - * except when it isn't. (I.e., sometimes it's just raw IP, and - * sometimes it isn't.) We currently handle it as DLT_LINUX_SLL, - * so that we don't have to worry about the link-layer header.) - */ - -/* - * Frame Relay; BSD/OS has a DLT_FR with a value of 11, but that collides - * with other values. - * DLT_FR and DLT_FRELAY packets start with the Q.922 Frame Relay header - * (DLCI, etc.). - */ -#define DLT_FRELAY 107 - -/* - * OpenBSD DLT_LOOP, for loopback devices; it's like DLT_NULL, except - * that the AF_ type in the link-layer header is in network byte order. - * - * DLT_LOOP is 12 in OpenBSD, but that's DLT_RAW in other OSes, so - * we don't use 12 for it in OSes other than OpenBSD. - */ -#ifdef __OpenBSD__ -#define DLT_LOOP 12 -#else -#define DLT_LOOP 108 -#endif - -/* - * Encapsulated packets for IPsec; DLT_ENC is 13 in OpenBSD, but that's - * DLT_SLIP_BSDOS in NetBSD, so we don't use 13 for it in OSes other - * than OpenBSD. - */ -#ifdef __OpenBSD__ -#define DLT_ENC 13 -#else -#define DLT_ENC 109 -#endif - -/* - * Values between 110 and 112 are reserved for use in capture file headers - * as link-layer types corresponding to DLT_ types that might differ - * between platforms; don't use those values for new DLT_ types - * other than the corresponding DLT_ types. - */ - -/* - * This is for Linux cooked sockets. - */ -#define DLT_LINUX_SLL 113 - -/* - * Apple LocalTalk hardware. - */ -#define DLT_LTALK 114 - -/* - * Acorn Econet. - */ -#define DLT_ECONET 115 - -/* - * Reserved for use with OpenBSD ipfilter. - */ -#define DLT_IPFILTER 116 - -/* - * OpenBSD DLT_PFLOG. - */ -#define DLT_PFLOG 117 - -/* - * Registered for Cisco-internal use. - */ -#define DLT_CISCO_IOS 118 - -/* - * For 802.11 cards using the Prism II chips, with a link-layer - * header including Prism monitor mode information plus an 802.11 - * header. - */ -#define DLT_PRISM_HEADER 119 - -/* - * Reserved for Aironet 802.11 cards, with an Aironet link-layer header - * (see Doug Ambrisko's FreeBSD patches). - */ -#define DLT_AIRONET_HEADER 120 - -/* - * Sigh. - * - * 121 was reserved for Siemens HiPath HDLC on 2002-01-25, as - * requested by Tomas Kukosa. - * - * On 2004-02-25, a FreeBSD checkin to sys/net/bpf.h was made that - * assigned 121 as DLT_PFSYNC. In current versions, its libpcap - * does DLT_ <-> LINKTYPE_ mapping, mapping DLT_PFSYNC to a - * LINKTYPE_PFSYNC value of 246, so it should write out DLT_PFSYNC - * dump files with 246 as the link-layer header type. (Earlier - * versions might not have done mapping, in which case they would - * have written them out with a link-layer header type of 121.) - * - * OpenBSD, from which pf came, however, uses 18 for DLT_PFSYNC; - * its libpcap does no DLT_ <-> LINKTYPE_ mapping, so it would - * write out DLT_PFSYNC dump files with use 18 as the link-layer - * header type. - * - * NetBSD, DragonFly BSD, and Darwin also use 18 for DLT_PFSYNC; in - * current versions, their libpcaps do DLT_ <-> LINKTYPE_ mapping, - * mapping DLT_PFSYNC to a LINKTYPE_PFSYNC value of 246, so they - * should write out DLT_PFSYNC dump files with 246 as the link-layer - * header type. (Earlier versions might not have done mapping, - * in which case they'd work the same way OpenBSD does, writing - * them out with a link-layer header type of 18.) - * - * We'll define DLT_PFSYNC as: - * - * 18 on NetBSD, OpenBSD, DragonFly BSD, and Darwin; - * - * 121 on FreeBSD; - * - * 246 everywhere else. - * - * We'll define DLT_HHDLC as 121 on everything except for FreeBSD; - * anybody who wants to compile, on FreeBSD, code that uses DLT_HHDLC - * is out of luck. - * - * We'll define LINKTYPE_PFSYNC as 246 on *all* platforms, so that - * savefiles written using *this* code won't use 18 or 121 for PFSYNC, - * they'll all use 246. - * - * Code that uses pcap_datalink() to determine the link-layer header - * type of a savefile won't, when built and run on FreeBSD, be able - * to distinguish between LINKTYPE_PFSYNC and LINKTYPE_HHDLC capture - * files, as pcap_datalink() will give 121 for both of them. Code - * that doesn't, such as the code in Wireshark, will be able to - * distinguish between them. - * - * FreeBSD's libpcap won't map a link-layer header type of 18 - i.e., - * DLT_PFSYNC files from OpenBSD and possibly older versions of NetBSD, - * DragonFly BSD, and OS X - to DLT_PFSYNC, so code built with FreeBSD's - * libpcap won't treat those files as DLT_PFSYNC files. - * - * Other libpcaps won't map a link-layer header type of 121 to DLT_PFSYNC; - * this means they can read DLT_HHDLC files, if any exist, but won't - * treat pcap files written by any older versions of FreeBSD libpcap that - * didn't map to 246 as DLT_PFSYNC files. - */ -#ifdef __FreeBSD__ -#define DLT_PFSYNC 121 -#else -#define DLT_HHDLC 121 -#endif - -/* - * This is for RFC 2625 IP-over-Fibre Channel. - * - * This is not for use with raw Fibre Channel, where the link-layer - * header starts with a Fibre Channel frame header; it's for IP-over-FC, - * where the link-layer header starts with an RFC 2625 Network_Header - * field. - */ -#define DLT_IP_OVER_FC 122 - -/* - * This is for Full Frontal ATM on Solaris with SunATM, with a - * pseudo-header followed by an AALn PDU. - * - * There may be other forms of Full Frontal ATM on other OSes, - * with different pseudo-headers. - * - * If ATM software returns a pseudo-header with VPI/VCI information - * (and, ideally, packet type information, e.g. signalling, ILMI, - * LANE, LLC-multiplexed traffic, etc.), it should not use - * DLT_ATM_RFC1483, but should get a new DLT_ value, so tcpdump - * and the like don't have to infer the presence or absence of a - * pseudo-header and the form of the pseudo-header. - */ -#define DLT_SUNATM 123 /* Solaris+SunATM */ - -/* - * Reserved as per request from Kent Dahlgren - * for private use. - */ -#define DLT_RIO 124 /* RapidIO */ -#define DLT_PCI_EXP 125 /* PCI Express */ -#define DLT_AURORA 126 /* Xilinx Aurora link layer */ - -/* - * Header for 802.11 plus a number of bits of link-layer information - * including radio information, used by some recent BSD drivers as - * well as the madwifi Atheros driver for Linux. - */ -#define DLT_IEEE802_11_RADIO 127 /* 802.11 plus radiotap radio header */ - -/* - * Reserved for the TZSP encapsulation, as per request from - * Chris Waters - * TZSP is a generic encapsulation for any other link type, - * which includes a means to include meta-information - * with the packet, e.g. signal strength and channel - * for 802.11 packets. - */ -#define DLT_TZSP 128 /* Tazmen Sniffer Protocol */ - -/* - * BSD's ARCNET headers have the source host, destination host, - * and type at the beginning of the packet; that's what's handed - * up to userland via BPF. - * - * Linux's ARCNET headers, however, have a 2-byte offset field - * between the host IDs and the type; that's what's handed up - * to userland via PF_PACKET sockets. - * - * We therefore have to have separate DLT_ values for them. - */ -#define DLT_ARCNET_LINUX 129 /* ARCNET */ - -/* - * Juniper-private data link types, as per request from - * Hannes Gredler . The DLT_s are used - * for passing on chassis-internal metainformation such as - * QOS profiles, etc.. - */ -#define DLT_JUNIPER_MLPPP 130 -#define DLT_JUNIPER_MLFR 131 -#define DLT_JUNIPER_ES 132 -#define DLT_JUNIPER_GGSN 133 -#define DLT_JUNIPER_MFR 134 -#define DLT_JUNIPER_ATM2 135 -#define DLT_JUNIPER_SERVICES 136 -#define DLT_JUNIPER_ATM1 137 - -/* - * Apple IP-over-IEEE 1394, as per a request from Dieter Siegmund - * . The header that's presented is an Ethernet-like - * header: - * - * #define FIREWIRE_EUI64_LEN 8 - * struct firewire_header { - * u_char firewire_dhost[FIREWIRE_EUI64_LEN]; - * u_char firewire_shost[FIREWIRE_EUI64_LEN]; - * u_short firewire_type; - * }; - * - * with "firewire_type" being an Ethernet type value, rather than, - * for example, raw GASP frames being handed up. - */ -#define DLT_APPLE_IP_OVER_IEEE1394 138 - -/* - * Various SS7 encapsulations, as per a request from Jeff Morriss - * and subsequent discussions. - */ -#define DLT_MTP2_WITH_PHDR 139 /* pseudo-header with various info, followed by MTP2 */ -#define DLT_MTP2 140 /* MTP2, without pseudo-header */ -#define DLT_MTP3 141 /* MTP3, without pseudo-header or MTP2 */ -#define DLT_SCCP 142 /* SCCP, without pseudo-header or MTP2 or MTP3 */ - -/* - * DOCSIS MAC frames. - */ -#define DLT_DOCSIS 143 - -/* - * Linux-IrDA packets. Protocol defined at http://www.irda.org. - * Those packets include IrLAP headers and above (IrLMP...), but - * don't include Phy framing (SOF/EOF/CRC & byte stuffing), because Phy - * framing can be handled by the hardware and depend on the bitrate. - * This is exactly the format you would get capturing on a Linux-IrDA - * interface (irdaX), but not on a raw serial port. - * Note the capture is done in "Linux-cooked" mode, so each packet include - * a fake packet header (struct sll_header). This is because IrDA packet - * decoding is dependant on the direction of the packet (incomming or - * outgoing). - * When/if other platform implement IrDA capture, we may revisit the - * issue and define a real DLT_IRDA... - * Jean II - */ -#define DLT_LINUX_IRDA 144 - -/* - * Reserved for IBM SP switch and IBM Next Federation switch. - */ -#define DLT_IBM_SP 145 -#define DLT_IBM_SN 146 - -/* - * Reserved for private use. If you have some link-layer header type - * that you want to use within your organization, with the capture files - * using that link-layer header type not ever be sent outside your - * organization, you can use these values. - * - * No libpcap release will use these for any purpose, nor will any - * tcpdump release use them, either. - * - * Do *NOT* use these in capture files that you expect anybody not using - * your private versions of capture-file-reading tools to read; in - * particular, do *NOT* use them in products, otherwise you may find that - * people won't be able to use tcpdump, or snort, or Ethereal, or... to - * read capture files from your firewall/intrusion detection/traffic - * monitoring/etc. appliance, or whatever product uses that DLT_ value, - * and you may also find that the developers of those applications will - * not accept patches to let them read those files. - * - * Also, do not use them if somebody might send you a capture using them - * for *their* private type and tools using them for *your* private type - * would have to read them. - * - * Instead, ask "tcpdump-workers@lists.tcpdump.org" for a new DLT_ value, - * as per the comment above, and use the type you're given. - */ -#define DLT_USER0 147 -#define DLT_USER1 148 -#define DLT_USER2 149 -#define DLT_USER3 150 -#define DLT_USER4 151 -#define DLT_USER5 152 -#define DLT_USER6 153 -#define DLT_USER7 154 -#define DLT_USER8 155 -#define DLT_USER9 156 -#define DLT_USER10 157 -#define DLT_USER11 158 -#define DLT_USER12 159 -#define DLT_USER13 160 -#define DLT_USER14 161 -#define DLT_USER15 162 - -/* - * For future use with 802.11 captures - defined by AbsoluteValue - * Systems to store a number of bits of link-layer information - * including radio information: - * - * http://www.shaftnet.org/~pizza/software/capturefrm.txt - * - * but it might be used by some non-AVS drivers now or in the - * future. - */ -#define DLT_IEEE802_11_RADIO_AVS 163 /* 802.11 plus AVS radio header */ - -/* - * Juniper-private data link type, as per request from - * Hannes Gredler . The DLT_s are used - * for passing on chassis-internal metainformation such as - * QOS profiles, etc.. - */ -#define DLT_JUNIPER_MONITOR 164 - -/* - * BACnet MS/TP frames. - */ -#define DLT_BACNET_MS_TP 165 - -/* - * Another PPP variant as per request from Karsten Keil . - * - * This is used in some OSes to allow a kernel socket filter to distinguish - * between incoming and outgoing packets, on a socket intended to - * supply pppd with outgoing packets so it can do dial-on-demand and - * hangup-on-lack-of-demand; incoming packets are filtered out so they - * don't cause pppd to hold the connection up (you don't want random - * input packets such as port scans, packets from old lost connections, - * etc. to force the connection to stay up). - * - * The first byte of the PPP header (0xff03) is modified to accomodate - * the direction - 0x00 = IN, 0x01 = OUT. - */ -#define DLT_PPP_PPPD 166 - -/* - * Names for backwards compatibility with older versions of some PPP - * software; new software should use DLT_PPP_PPPD. - */ -#define DLT_PPP_WITH_DIRECTION DLT_PPP_PPPD -#define DLT_LINUX_PPP_WITHDIRECTION DLT_PPP_PPPD - -/* - * Juniper-private data link type, as per request from - * Hannes Gredler . The DLT_s are used - * for passing on chassis-internal metainformation such as - * QOS profiles, cookies, etc.. - */ -#define DLT_JUNIPER_PPPOE 167 -#define DLT_JUNIPER_PPPOE_ATM 168 - -#define DLT_GPRS_LLC 169 /* GPRS LLC */ -#define DLT_GPF_T 170 /* GPF-T (ITU-T G.7041/Y.1303) */ -#define DLT_GPF_F 171 /* GPF-F (ITU-T G.7041/Y.1303) */ - -/* - * Requested by Oolan Zimmer for use in Gcom's T1/E1 line - * monitoring equipment. - */ -#define DLT_GCOM_T1E1 172 -#define DLT_GCOM_SERIAL 173 - -/* - * Juniper-private data link type, as per request from - * Hannes Gredler . The DLT_ is used - * for internal communication to Physical Interface Cards (PIC) - */ -#define DLT_JUNIPER_PIC_PEER 174 - -/* - * Link types requested by Gregor Maier of Endace - * Measurement Systems. They add an ERF header (see - * http://www.endace.com/support/EndaceRecordFormat.pdf) in front of - * the link-layer header. - */ -#define DLT_ERF_ETH 175 /* Ethernet */ -#define DLT_ERF_POS 176 /* Packet-over-SONET */ - -/* - * Requested by Daniele Orlandi for raw LAPD - * for vISDN (http://www.orlandi.com/visdn/). Its link-layer header - * includes additional information before the LAPD header, so it's - * not necessarily a generic LAPD header. - */ -#define DLT_LINUX_LAPD 177 - -/* - * Juniper-private data link type, as per request from - * Hannes Gredler . - * The DLT_ are used for prepending meta-information - * like interface index, interface name - * before standard Ethernet, PPP, Frelay & C-HDLC Frames - */ -#define DLT_JUNIPER_ETHER 178 -#define DLT_JUNIPER_PPP 179 -#define DLT_JUNIPER_FRELAY 180 -#define DLT_JUNIPER_CHDLC 181 - -/* - * Multi Link Frame Relay (FRF.16) - */ -#define DLT_MFR 182 - -/* - * Juniper-private data link type, as per request from - * Hannes Gredler . - * The DLT_ is used for internal communication with a - * voice Adapter Card (PIC) - */ -#define DLT_JUNIPER_VP 183 - -/* - * Arinc 429 frames. - * DLT_ requested by Gianluca Varenni . - * Every frame contains a 32bit A429 label. - * More documentation on Arinc 429 can be found at - * http://www.condoreng.com/support/downloads/tutorials/ARINCTutorial.pdf - */ -#define DLT_A429 184 - -/* - * Arinc 653 Interpartition Communication messages. - * DLT_ requested by Gianluca Varenni . - * Please refer to the A653-1 standard for more information. - */ -#define DLT_A653_ICM 185 - -/* - * This used to be "USB packets, beginning with a USB setup header; - * requested by Paolo Abeni ." - * - * However, that header didn't work all that well - it left out some - * useful information - and was abandoned in favor of the DLT_USB_LINUX - * header. - * - * This is now used by FreeBSD for its BPF taps for USB; that has its - * own headers. So it is written, so it is done. - * - * For source-code compatibility, we also define DLT_USB to have this - * value. We do it numerically so that, if code that includes this - * file (directly or indirectly) also includes an OS header that also - * defines DLT_USB as 186, we don't get a redefinition warning. - * (NetBSD 7 does that.) - */ -#define DLT_USB_FREEBSD 186 -#define DLT_USB 186 - -/* - * Bluetooth HCI UART transport layer (part H:4); requested by - * Paolo Abeni. - */ -#define DLT_BLUETOOTH_HCI_H4 187 - -/* - * IEEE 802.16 MAC Common Part Sublayer; requested by Maria Cruz - * . - */ -#define DLT_IEEE802_16_MAC_CPS 188 - -/* - * USB packets, beginning with a Linux USB header; requested by - * Paolo Abeni . - */ -#define DLT_USB_LINUX 189 - -/* - * Controller Area Network (CAN) v. 2.0B packets. - * DLT_ requested by Gianluca Varenni . - * Used to dump CAN packets coming from a CAN Vector board. - * More documentation on the CAN v2.0B frames can be found at - * http://www.can-cia.org/downloads/?269 - */ -#define DLT_CAN20B 190 - -/* - * IEEE 802.15.4, with address fields padded, as is done by Linux - * drivers; requested by Juergen Schimmer. - */ -#define DLT_IEEE802_15_4_LINUX 191 - -/* - * Per Packet Information encapsulated packets. - * DLT_ requested by Gianluca Varenni . - */ -#define DLT_PPI 192 - -/* - * Header for 802.16 MAC Common Part Sublayer plus a radiotap radio header; - * requested by Charles Clancy. - */ -#define DLT_IEEE802_16_MAC_CPS_RADIO 193 - -/* - * Juniper-private data link type, as per request from - * Hannes Gredler . - * The DLT_ is used for internal communication with a - * integrated service module (ISM). - */ -#define DLT_JUNIPER_ISM 194 - -/* - * IEEE 802.15.4, exactly as it appears in the spec (no padding, no - * nothing); requested by Mikko Saarnivala . - * For this one, we expect the FCS to be present at the end of the frame; - * if the frame has no FCS, DLT_IEEE802_15_4_NOFCS should be used. - */ -#define DLT_IEEE802_15_4 195 - -/* - * Various link-layer types, with a pseudo-header, for SITA - * (http://www.sita.aero/); requested by Fulko Hew (fulko.hew@gmail.com). - */ -#define DLT_SITA 196 - -/* - * Various link-layer types, with a pseudo-header, for Endace DAG cards; - * encapsulates Endace ERF records. Requested by Stephen Donnelly - * . - */ -#define DLT_ERF 197 - -/* - * Special header prepended to Ethernet packets when capturing from a - * u10 Networks board. Requested by Phil Mulholland - * . - */ -#define DLT_RAIF1 198 - -/* - * IPMB packet for IPMI, beginning with the I2C slave address, followed - * by the netFn and LUN, etc.. Requested by Chanthy Toeung - * . - */ -#define DLT_IPMB 199 - -/* - * Juniper-private data link type, as per request from - * Hannes Gredler . - * The DLT_ is used for capturing data on a secure tunnel interface. - */ -#define DLT_JUNIPER_ST 200 - -/* - * Bluetooth HCI UART transport layer (part H:4), with pseudo-header - * that includes direction information; requested by Paolo Abeni. - */ -#define DLT_BLUETOOTH_HCI_H4_WITH_PHDR 201 - -/* - * AX.25 packet with a 1-byte KISS header; see - * - * http://www.ax25.net/kiss.htm - * - * as per Richard Stearn . - */ -#define DLT_AX25_KISS 202 - -/* - * LAPD packets from an ISDN channel, starting with the address field, - * with no pseudo-header. - * Requested by Varuna De Silva . - */ -#define DLT_LAPD 203 - -/* - * Variants of various link-layer headers, with a one-byte direction - * pseudo-header prepended - zero means "received by this host", - * non-zero (any non-zero value) means "sent by this host" - as per - * Will Barker . - */ -#define DLT_PPP_WITH_DIR 204 /* PPP - don't confuse with DLT_PPP_WITH_DIRECTION */ -#define DLT_C_HDLC_WITH_DIR 205 /* Cisco HDLC */ -#define DLT_FRELAY_WITH_DIR 206 /* Frame Relay */ -#define DLT_LAPB_WITH_DIR 207 /* LAPB */ - -/* - * 208 is reserved for an as-yet-unspecified proprietary link-layer - * type, as requested by Will Barker. - */ - -/* - * IPMB with a Linux-specific pseudo-header; as requested by Alexey Neyman - * . - */ -#define DLT_IPMB_LINUX 209 - -/* - * FlexRay automotive bus - http://www.flexray.com/ - as requested - * by Hannes Kaelber . - */ -#define DLT_FLEXRAY 210 - -/* - * Media Oriented Systems Transport (MOST) bus for multimedia - * transport - http://www.mostcooperation.com/ - as requested - * by Hannes Kaelber . - */ -#define DLT_MOST 211 - -/* - * Local Interconnect Network (LIN) bus for vehicle networks - - * http://www.lin-subbus.org/ - as requested by Hannes Kaelber - * . - */ -#define DLT_LIN 212 - -/* - * X2E-private data link type used for serial line capture, - * as requested by Hannes Kaelber . - */ -#define DLT_X2E_SERIAL 213 - -/* - * X2E-private data link type used for the Xoraya data logger - * family, as requested by Hannes Kaelber . - */ -#define DLT_X2E_XORAYA 214 - -/* - * IEEE 802.15.4, exactly as it appears in the spec (no padding, no - * nothing), but with the PHY-level data for non-ASK PHYs (4 octets - * of 0 as preamble, one octet of SFD, one octet of frame length+ - * reserved bit, and then the MAC-layer data, starting with the - * frame control field). - * - * Requested by Max Filippov . - */ -#define DLT_IEEE802_15_4_NONASK_PHY 215 - -/* - * David Gibson requested this for - * captures from the Linux kernel /dev/input/eventN devices. This - * is used to communicate keystrokes and mouse movements from the - * Linux kernel to display systems, such as Xorg. - */ -#define DLT_LINUX_EVDEV 216 - -/* - * GSM Um and Abis interfaces, preceded by a "gsmtap" header. - * - * Requested by Harald Welte . - */ -#define DLT_GSMTAP_UM 217 -#define DLT_GSMTAP_ABIS 218 - -/* - * MPLS, with an MPLS label as the link-layer header. - * Requested by Michele Marchetto on behalf - * of OpenBSD. - */ -#define DLT_MPLS 219 - -/* - * USB packets, beginning with a Linux USB header, with the USB header - * padded to 64 bytes; required for memory-mapped access. - */ -#define DLT_USB_LINUX_MMAPPED 220 - -/* - * DECT packets, with a pseudo-header; requested by - * Matthias Wenzel . - */ -#define DLT_DECT 221 - -/* - * From: "Lidwa, Eric (GSFC-582.0)[SGT INC]" - * Date: Mon, 11 May 2009 11:18:30 -0500 - * - * DLT_AOS. We need it for AOS Space Data Link Protocol. - * I have already written dissectors for but need an OK from - * legal before I can submit a patch. - * - */ -#define DLT_AOS 222 - -/* - * Wireless HART (Highway Addressable Remote Transducer) - * From the HART Communication Foundation - * IES/PAS 62591 - * - * Requested by Sam Roberts . - */ -#define DLT_WIHART 223 - -/* - * Fibre Channel FC-2 frames, beginning with a Frame_Header. - * Requested by Kahou Lei . - */ -#define DLT_FC_2 224 - -/* - * Fibre Channel FC-2 frames, beginning with an encoding of the - * SOF, and ending with an encoding of the EOF. - * - * The encodings represent the frame delimiters as 4-byte sequences - * representing the corresponding ordered sets, with K28.5 - * represented as 0xBC, and the D symbols as the corresponding - * byte values; for example, SOFi2, which is K28.5 - D21.5 - D1.2 - D21.2, - * is represented as 0xBC 0xB5 0x55 0x55. - * - * Requested by Kahou Lei . - */ -#define DLT_FC_2_WITH_FRAME_DELIMS 225 - -/* - * Solaris ipnet pseudo-header; requested by Darren Reed . - * - * The pseudo-header starts with a one-byte version number; for version 2, - * the pseudo-header is: - * - * struct dl_ipnetinfo { - * uint8_t dli_version; - * uint8_t dli_family; - * uint16_t dli_htype; - * uint32_t dli_pktlen; - * uint32_t dli_ifindex; - * uint32_t dli_grifindex; - * uint32_t dli_zsrc; - * uint32_t dli_zdst; - * }; - * - * dli_version is 2 for the current version of the pseudo-header. - * - * dli_family is a Solaris address family value, so it's 2 for IPv4 - * and 26 for IPv6. - * - * dli_htype is a "hook type" - 0 for incoming packets, 1 for outgoing - * packets, and 2 for packets arriving from another zone on the same - * machine. - * - * dli_pktlen is the length of the packet data following the pseudo-header - * (so the captured length minus dli_pktlen is the length of the - * pseudo-header, assuming the entire pseudo-header was captured). - * - * dli_ifindex is the interface index of the interface on which the - * packet arrived. - * - * dli_grifindex is the group interface index number (for IPMP interfaces). - * - * dli_zsrc is the zone identifier for the source of the packet. - * - * dli_zdst is the zone identifier for the destination of the packet. - * - * A zone number of 0 is the global zone; a zone number of 0xffffffff - * means that the packet arrived from another host on the network, not - * from another zone on the same machine. - * - * An IPv4 or IPv6 datagram follows the pseudo-header; dli_family indicates - * which of those it is. - */ -#define DLT_IPNET 226 - -/* - * CAN (Controller Area Network) frames, with a pseudo-header as supplied - * by Linux SocketCAN, and with multi-byte numerical fields in that header - * in big-endian byte order. - * - * See Documentation/networking/can.txt in the Linux source. - * - * Requested by Felix Obenhuber . - */ -#define DLT_CAN_SOCKETCAN 227 - -/* - * Raw IPv4/IPv6; different from DLT_RAW in that the DLT_ value specifies - * whether it's v4 or v6. Requested by Darren Reed . - */ -#define DLT_IPV4 228 -#define DLT_IPV6 229 - -/* - * IEEE 802.15.4, exactly as it appears in the spec (no padding, no - * nothing), and with no FCS at the end of the frame; requested by - * Jon Smirl . - */ -#define DLT_IEEE802_15_4_NOFCS 230 - -/* - * Raw D-Bus: - * - * http://www.freedesktop.org/wiki/Software/dbus - * - * messages: - * - * http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-messages - * - * starting with the endianness flag, followed by the message type, etc., - * but without the authentication handshake before the message sequence: - * - * http://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol - * - * Requested by Martin Vidner . - */ -#define DLT_DBUS 231 - -/* - * Juniper-private data link type, as per request from - * Hannes Gredler . - */ -#define DLT_JUNIPER_VS 232 -#define DLT_JUNIPER_SRX_E2E 233 -#define DLT_JUNIPER_FIBRECHANNEL 234 - -/* - * DVB-CI (DVB Common Interface for communication between a PC Card - * module and a DVB receiver). See - * - * http://www.kaiser.cx/pcap-dvbci.html - * - * for the specification. - * - * Requested by Martin Kaiser . - */ -#define DLT_DVB_CI 235 - -/* - * Variant of 3GPP TS 27.010 multiplexing protocol (similar to, but - * *not* the same as, 27.010). Requested by Hans-Christoph Schemmel - * . - */ -#define DLT_MUX27010 236 - -/* - * STANAG 5066 D_PDUs. Requested by M. Baris Demiray - * . - */ -#define DLT_STANAG_5066_D_PDU 237 - -/* - * Juniper-private data link type, as per request from - * Hannes Gredler . - */ -#define DLT_JUNIPER_ATM_CEMIC 238 - -/* - * NetFilter LOG messages - * (payload of netlink NFNL_SUBSYS_ULOG/NFULNL_MSG_PACKET packets) - * - * Requested by Jakub Zawadzki - */ -#define DLT_NFLOG 239 - -/* - * Hilscher Gesellschaft fuer Systemautomation mbH link-layer type - * for Ethernet packets with a 4-byte pseudo-header and always - * with the payload including the FCS, as supplied by their - * netANALYZER hardware and software. - * - * Requested by Holger P. Frommer - */ -#define DLT_NETANALYZER 240 - -/* - * Hilscher Gesellschaft fuer Systemautomation mbH link-layer type - * for Ethernet packets with a 4-byte pseudo-header and FCS and - * with the Ethernet header preceded by 7 bytes of preamble and - * 1 byte of SFD, as supplied by their netANALYZER hardware and - * software. - * - * Requested by Holger P. Frommer - */ -#define DLT_NETANALYZER_TRANSPARENT 241 - -/* - * IP-over-InfiniBand, as specified by RFC 4391. - * - * Requested by Petr Sumbera . - */ -#define DLT_IPOIB 242 - -/* - * MPEG-2 transport stream (ISO 13818-1/ITU-T H.222.0). - * - * Requested by Guy Martin . - */ -#define DLT_MPEG_2_TS 243 - -/* - * ng4T GmbH's UMTS Iub/Iur-over-ATM and Iub/Iur-over-IP format as - * used by their ng40 protocol tester. - * - * Requested by Jens Grimmer . - */ -#define DLT_NG40 244 - -/* - * Pseudo-header giving adapter number and flags, followed by an NFC - * (Near-Field Communications) Logical Link Control Protocol (LLCP) PDU, - * as specified by NFC Forum Logical Link Control Protocol Technical - * Specification LLCP 1.1. - * - * Requested by Mike Wakerly . - */ -#define DLT_NFC_LLCP 245 - -/* - * 246 is used as LINKTYPE_PFSYNC; do not use it for any other purpose. - * - * DLT_PFSYNC has different values on different platforms, and all of - * them collide with something used elsewhere. On platforms that - * don't already define it, define it as 246. - */ -#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__) && !defined(__APPLE__) -#define DLT_PFSYNC 246 -#endif - -/* - * Raw InfiniBand packets, starting with the Local Routing Header. - * - * Requested by Oren Kladnitsky . - */ -#define DLT_INFINIBAND 247 - -/* - * SCTP, with no lower-level protocols (i.e., no IPv4 or IPv6). - * - * Requested by Michael Tuexen . - */ -#define DLT_SCTP 248 - -/* - * USB packets, beginning with a USBPcap header. - * - * Requested by Tomasz Mon - */ -#define DLT_USBPCAP 249 - -/* - * Schweitzer Engineering Laboratories "RTAC" product serial-line - * packets. - * - * Requested by Chris Bontje . - */ -#define DLT_RTAC_SERIAL 250 - -/* - * Bluetooth Low Energy air interface link-layer packets. - * - * Requested by Mike Kershaw . - */ -#define DLT_BLUETOOTH_LE_LL 251 - -/* - * DLT type for upper-protocol layer PDU saves from wireshark. - * - * the actual contents are determined by two TAGs stored with each - * packet: - * EXP_PDU_TAG_LINKTYPE the link type (LINKTYPE_ value) of the - * original packet. - * - * EXP_PDU_TAG_PROTO_NAME the name of the wireshark dissector - * that can make sense of the data stored. - */ -#define DLT_WIRESHARK_UPPER_PDU 252 - -/* - * DLT type for the netlink protocol (nlmon devices). - */ -#define DLT_NETLINK 253 - -/* - * Bluetooth Linux Monitor headers for the BlueZ stack. - */ -#define DLT_BLUETOOTH_LINUX_MONITOR 254 - -/* - * Bluetooth Basic Rate/Enhanced Data Rate baseband packets, as - * captured by Ubertooth. - */ -#define DLT_BLUETOOTH_BREDR_BB 255 - -/* - * Bluetooth Low Energy link layer packets, as captured by Ubertooth. - */ -#define DLT_BLUETOOTH_LE_LL_WITH_PHDR 256 - -/* - * PROFIBUS data link layer. - */ -#define DLT_PROFIBUS_DL 257 - -/* - * Apple's DLT_PKTAP headers. - * - * Sadly, the folks at Apple either had no clue that the DLT_USERn values - * are for internal use within an organization and partners only, and - * didn't know that the right way to get a link-layer header type is to - * ask tcpdump.org for one, or knew and didn't care, so they just - * used DLT_USER2, which causes problems for everything except for - * their version of tcpdump. - * - * So I'll just give them one; hopefully this will show up in a - * libpcap release in time for them to get this into 10.10 Big Sur - * or whatever Mavericks' successor is called. LINKTYPE_PKTAP - * will be 258 *even on OS X*; that is *intentional*, so that - * PKTAP files look the same on *all* OSes (different OSes can have - * different numerical values for a given DLT_, but *MUST NOT* have - * different values for what goes in a file, as files can be moved - * between OSes!). - * - * When capturing, on a system with a Darwin-based OS, on a device - * that returns 149 (DLT_USER2 and Apple's DLT_PKTAP) with this - * version of libpcap, the DLT_ value for the pcap_t will be DLT_PKTAP, - * and that will continue to be DLT_USER2 on Darwin-based OSes. That way, - * binary compatibility with Mavericks is preserved for programs using - * this version of libpcap. This does mean that if you were using - * DLT_USER2 for some capture device on OS X, you can't do so with - * this version of libpcap, just as you can't with Apple's libpcap - - * on OS X, they define DLT_PKTAP to be DLT_USER2, so programs won't - * be able to distinguish between PKTAP and whatever you were using - * DLT_USER2 for. - * - * If the program saves the capture to a file using this version of - * libpcap's pcap_dump code, the LINKTYPE_ value in the file will be - * LINKTYPE_PKTAP, which will be 258, even on Darwin-based OSes. - * That way, the file will *not* be a DLT_USER2 file. That means - * that the latest version of tcpdump, when built with this version - * of libpcap, and sufficiently recent versions of Wireshark will - * be able to read those files and interpret them correctly; however, - * Apple's version of tcpdump in OS X 10.9 won't be able to handle - * them. (Hopefully, Apple will pick up this version of libpcap, - * and the corresponding version of tcpdump, so that tcpdump will - * be able to handle the old LINKTYPE_USER2 captures *and* the new - * LINKTYPE_PKTAP captures.) - */ -#ifdef __APPLE__ -#define DLT_PKTAP DLT_USER2 -#else -#define DLT_PKTAP 258 -#endif - -/* - * Ethernet packets preceded by a header giving the last 6 octets - * of the preamble specified by 802.3-2012 Clause 65, section - * 65.1.3.2 "Transmit". - */ -#define DLT_EPON 259 - -/* - * IPMI trace packets, as specified by Table 3-20 "Trace Data Block Format" - * in the PICMG HPM.2 specification. - */ -#define DLT_IPMI_HPM_2 260 - -/* - * per Joshua Wright , formats for Zwave captures. - */ -#define DLT_ZWAVE_R1_R2 261 -#define DLT_ZWAVE_R3 262 - -/* - * per Steve Karg , formats for Wattstopper - * Digital Lighting Management room bus serial protocol captures. - */ -#define DLT_WATTSTOPPER_DLM 263 - -/* - * ISO 14443 contactless smart card messages. - */ -#define DLT_ISO_14443 264 - -/* - * Radio data system (RDS) groups. IEC 62106. - * Per Jonathan Brucker . - */ -#define DLT_RDS 265 - -/* - * USB packets, beginning with a Darwin (macOS, etc.) header. - */ -#define DLT_USB_DARWIN 266 - -/* - * OpenBSD DLT_OPENFLOW. - */ -#define DLT_OPENFLOW 267 - -/* - * SDLC frames containing SNA PDUs. - */ -#define DLT_SDLC 268 - -/* - * per "Selvig, Bjorn" used for - * TI protocol sniffer. - */ -#define DLT_TI_LLN_SNIFFER 269 - -/* - * per: Erik de Jong for - * https://github.com/eriknl/LoRaTap/releases/tag/v0.1 - */ -#define DLT_LORATAP 270 - -/* - * per: Stefanha at gmail.com for - * http://lists.sandelman.ca/pipermail/tcpdump-workers/2017-May/000772.html - * and: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/vsockmon.h - * for: http://qemu-project.org/Features/VirtioVsock - */ -#define DLT_VSOCK 271 - -/* - * Nordic Semiconductor Bluetooth LE sniffer. - */ -#define DLT_NORDIC_BLE 272 - -/* - * Excentis DOCSIS 3.1 RF sniffer (XRA-31) - * per: bruno.verstuyft at excentis.com - * http://www.xra31.com/xra-header - */ -#define DLT_DOCSIS31_XRA31 273 - -/* - * mPackets, as specified by IEEE 802.3br Figure 99-4, starting - * with the preamble and always ending with a CRC field. - */ -#define DLT_ETHERNET_MPACKET 274 - -/* - * In case the code that includes this file (directly or indirectly) - * has also included OS files that happen to define DLT_MATCHING_MAX, - * with a different value (perhaps because that OS hasn't picked up - * the latest version of our DLT definitions), we undefine the - * previous value of DLT_MATCHING_MAX. - */ -#ifdef DLT_MATCHING_MAX -#undef DLT_MATCHING_MAX -#endif -#define DLT_MATCHING_MAX 274 /* highest value in the "matching" range */ - -/* - * DLT and savefile link type values are split into a class and - * a member of that class. A class value of 0 indicates a regular - * DLT_/LINKTYPE_ value. - */ -#define DLT_CLASS(x) ((x) & 0x03ff0000) - -/* - * NetBSD-specific generic "raw" link type. The class value indicates - * that this is the generic raw type, and the lower 16 bits are the - * address family we're dealing with. Those values are NetBSD-specific; - * do not assume that they correspond to AF_ values for your operating - * system. - */ -#define DLT_CLASS_NETBSD_RAWAF 0x02240000 -#define DLT_NETBSD_RAWAF(af) (DLT_CLASS_NETBSD_RAWAF | (af)) -#define DLT_NETBSD_RAWAF_AF(x) ((x) & 0x0000ffff) -#define DLT_IS_NETBSD_RAWAF(x) (DLT_CLASS(x) == DLT_CLASS_NETBSD_RAWAF) - -#endif /* !defined(lib_pcap_dlt_h) */ diff --git a/src/pcap/funcattrs.h b/src/pcap/funcattrs.h deleted file mode 100644 index d1cc2bf..0000000 --- a/src/pcap/funcattrs.h +++ /dev/null @@ -1,242 +0,0 @@ -/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */ -/* - * Copyright (c) 1993, 1994, 1995, 1996, 1997 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the Computer Systems - * Engineering Group at Lawrence Berkeley Laboratory. - * 4. Neither the name of the University nor of the Laboratory may be used - * to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lib_pcap_funcattrs_h -#define lib_pcap_funcattrs_h - -#include - -/* - * Attributes to apply to functions and their arguments, using various - * compiler-specific extensions. - */ - -/* - * PCAP_API_DEF must be used when defining *data* exported from - * libpcap. It can be used when defining *functions* exported - * from libpcap, but it doesn't have to be used there. It - * should not be used in declarations in headers. - * - * PCAP_API must be used when *declaring* data or functions - * exported from libpcap; PCAP_API_DEF won't work on all platforms. - */ - -#if defined(_WIN32) - /* - * For Windows: - * - * when building libpcap: - * - * if we're building it as a DLL, we have to declare API - * functions with __declspec(dllexport); - * - * if we're building it as a static library, we don't want - * to do so. - * - * when using libpcap: - * - * if we're using the DLL, calls to its functions are a - * little more efficient if they're declared with - * __declspec(dllimport); - * - * if we're not using the dll, we don't want to declare - * them that way. - * - * So: - * - * if pcap_EXPORTS is defined, we define PCAP_API_DEF as - * __declspec(dllexport); - * - * if PCAP_DLL is defined, we define PCAP_API_DEF as - * __declspec(dllimport); - * - * otherwise, we define PCAP_API_DEF as nothing. - */ - #if defined(pcap_EXPORTS) - /* - * We're compiling libpcap, so we should export functions in our - * API. - */ - #define PCAP_API_DEF __declspec(dllexport) - #elif defined(PCAP_DLL) - #define PCAP_API_DEF __declspec(dllimport) - #else - #define PCAP_API_DEF - #endif -#elif defined(MSDOS) - /* XXX - does this need special treatment? */ - #define PCAP_API_DEF -#else /* UN*X */ - #ifdef pcap_EXPORTS - /* - * We're compiling libpcap, so we should export functions in our API. - * The compiler might be configured not to export functions from a - * shared library by default, so we might have to explicitly mark - * functions as exported. - */ - #if PCAP_IS_AT_LEAST_GNUC_VERSION(3,4) \ - || PCAP_IS_AT_LEAST_XL_C_VERSION(12,0) - /* - * GCC 3.4 or later, or some compiler asserting compatibility with - * GCC 3.4 or later, or XL C 13.0 or later, so we have - * __attribute__((visibility()). - */ - #define PCAP_API_DEF __attribute__((visibility("default"))) - #elif PCAP_IS_AT_LEAST_SUNC_VERSION(5,5) - /* - * Sun C 5.5 or later, so we have __global. - * (Sun C 5.9 and later also have __attribute__((visibility()), - * but there's no reason to prefer it with Sun C.) - */ - #define PCAP_API_DEF __global - #else - /* - * We don't have anything to say. - */ - #define PCAP_API_DEF - #endif - #else - /* - * We're not building libpcap. - */ - #define PCAP_API_DEF - #endif -#endif /* _WIN32/MSDOS/UN*X */ - -#define PCAP_API PCAP_API_DEF extern - -/* - * PCAP_NORETURN, before a function declaration, means "this function - * never returns". (It must go before the function declaration, e.g. - * "extern PCAP_NORETURN func(...)" rather than after the function - * declaration, as the MSVC version has to go before the declaration.) - */ -#if __has_attribute(noreturn) \ - || PCAP_IS_AT_LEAST_GNUC_VERSION(2,5) \ - || PCAP_IS_AT_LEAST_SUNC_VERSION(5,9) \ - || PCAP_IS_AT_LEAST_XL_C_VERSION(10,1) \ - || PCAP_IS_AT_LEAST_HP_C_VERSION(6,10) - /* - * Compiler with support for __attribute((noreturn)), or GCC 2.5 and - * later, or Solaris Studio 12 (Sun C 5.9) and later, or IBM XL C 10.1 - * and later (do any earlier versions of XL C support this?), or - * HP aCC A.06.10 and later. - */ - #define PCAP_NORETURN __attribute((noreturn)) -#elif defined(_MSC_VER) - /* - * MSVC. - */ - #define PCAP_NORETURN __declspec(noreturn) -#else - #define PCAP_NORETURN -#endif - -/* - * PCAP_PRINTFLIKE(x,y), after a function declaration, means "this function - * does printf-style formatting, with the xth argument being the format - * string and the yth argument being the first argument for the format - * string". - */ -#if __has_attribute(__format__) \ - || PCAP_IS_AT_LEAST_GNUC_VERSION(2,3) \ - || PCAP_IS_AT_LEAST_XL_C_VERSION(10,1) \ - || PCAP_IS_AT_LEAST_HP_C_VERSION(6,10) - /* - * Compiler with support for it, or GCC 2.3 and later, or IBM XL C 10.1 - * and later (do any earlier versions of XL C support this?), - * or HP aCC A.06.10 and later. - */ - #define PCAP_PRINTFLIKE(x,y) __attribute__((__format__(__printf__,x,y))) -#else - #define PCAP_PRINTFLIKE(x,y) -#endif - -/* - * PCAP_DEPRECATED(func, msg), after a function declaration, marks the - * function as deprecated. - * - * The first argument is the name of the function; the second argument is - * a string giving the warning message to use if the compiler supports that. - * - * (Thank you, Microsoft, for requiring the function name.) - */ -#if __has_attribute(deprecated) \ - || PCAP_IS_AT_LEAST_GNUC_VERSION(4,5) \ - || PCAP_IS_AT_LEAST_SUNC_VERSION(5,13) - /* - * Compiler that supports __has_attribute and __attribute__((deprecated)), - * or GCC 4.5 and later, or Sun/Oracle C 12.4 (Sun C 5.13) or later. - * - * Those support __attribute__((deprecated(msg))) (we assume, perhaps - * incorrectly, that anything that supports __has_attribute() is - * recent enough to support __attribute__((deprecated(msg)))). - */ - #define PCAP_DEPRECATED(func, msg) __attribute__((deprecated(msg))) -#elif PCAP_IS_AT_LEAST_GNUC_VERSION(3,1) - /* - * GCC 3.1 through 4.4. - * - * Those support __attribute__((deprecated)) but not - * __attribute__((deprecated(msg))). - */ - #define PCAP_DEPRECATED(func, msg) __attribute__((deprecated)) -#elif (defined(_MSC_VER) && (_MSC_VER >= 1500)) && !defined(pcap_EXPORTS) - /* - * MSVC from Visual Studio 2008 or later, and we're not building - * libpcap itself. - * - * If we *are* building libpcap, we don't want this, as it'll warn - * us even if we *define* the function. - */ - #define PCAP_DEPRECATED(func, msg) __pragma(deprecated(func)) -#else - #define PCAP_DEPRECATED(func, msg) -#endif - -/* - * For flagging arguments as format strings in MSVC. - */ -#ifdef _MSC_VER - #include - #if _MSC_VER > 1400 - #define PCAP_FORMAT_STRING(p) _Printf_format_string_ p - #else - #define PCAP_FORMAT_STRING(p) __format_string p - #endif -#else - #define PCAP_FORMAT_STRING(p) p -#endif - -#endif /* lib_pcap_funcattrs_h */ diff --git a/src/pcap/ipnet.h b/src/pcap/ipnet.h deleted file mode 100644 index 5330847..0000000 --- a/src/pcap/ipnet.h +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from the Stanford/CMU enet packet filter, - * (net/enet.c) distributed as part of 4.3BSD, and code contributed - * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence - * Berkeley Laboratory. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#define IPH_AF_INET 2 /* Matches Solaris's AF_INET */ -#define IPH_AF_INET6 26 /* Matches Solaris's AF_INET6 */ - -#define IPNET_OUTBOUND 1 -#define IPNET_INBOUND 2 diff --git a/src/pcap/namedb.h b/src/pcap/namedb.h deleted file mode 100644 index 73fb40a..0000000 --- a/src/pcap/namedb.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 1994, 1996 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the Computer Systems - * Engineering Group at Lawrence Berkeley Laboratory. - * 4. Neither the name of the University nor of the Laboratory may be used - * to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lib_pcap_namedb_h -#define lib_pcap_namedb_h - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * As returned by the pcap_next_etherent() - * XXX this stuff doesn't belong in this interface, but this - * library already must do name to address translation, so - * on systems that don't have support for /etc/ethers, we - * export these hooks since they're already being used by - * some applications (such as tcpdump) and already being - * marked as exported in some OSes offering libpcap (such - * as Debian). - */ -struct pcap_etherent { - u_char addr[6]; - char name[122]; -}; -#ifndef PCAP_ETHERS_FILE -#define PCAP_ETHERS_FILE "/etc/ethers" -#endif -PCAP_API struct pcap_etherent *pcap_next_etherent(FILE *); -PCAP_API u_char *pcap_ether_hostton(const char*); -PCAP_API u_char *pcap_ether_aton(const char *); - -PCAP_API bpf_u_int32 **pcap_nametoaddr(const char *); -#ifdef INET6 -PCAP_API struct addrinfo *pcap_nametoaddrinfo(const char *); -#endif -PCAP_API bpf_u_int32 pcap_nametonetaddr(const char *); - -PCAP_API int pcap_nametoport(const char *, int *, int *); -PCAP_API int pcap_nametoportrange(const char *, int *, int *, int *); -PCAP_API int pcap_nametoproto(const char *); -PCAP_API int pcap_nametoeproto(const char *); -PCAP_API int pcap_nametollc(const char *); -/* - * If a protocol is unknown, PROTO_UNDEF is returned. - * Also, pcap_nametoport() returns the protocol along with the port number. - * If there are ambiguous entried in /etc/services (i.e. domain - * can be either tcp or udp) PROTO_UNDEF is returned. - */ -#define PROTO_UNDEF -1 - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/pcap/nflog.h b/src/pcap/nflog.h deleted file mode 100644 index 29a71d2..0000000 --- a/src/pcap/nflog.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2013, Petar Alilovic, - * Faculty of Electrical Engineering and Computing, University of Zagreb - * All rights reserved - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - */ - -#ifndef lib_pcap_nflog_h -#define lib_pcap_nflog_h - -#include - -/* - * Structure of an NFLOG header and TLV parts, as described at - * http://www.tcpdump.org/linktypes/LINKTYPE_NFLOG.html - * - * The NFLOG header is big-endian. - * - * The TLV length and type are in host byte order. The value is either - * big-endian or is an array of bytes in some externally-specified byte - * order (text string, link-layer address, link-layer header, packet - * data, etc.). - */ -typedef struct nflog_hdr { - uint8_t nflog_family; /* address family */ - uint8_t nflog_version; /* version */ - uint16_t nflog_rid; /* resource ID */ -} nflog_hdr_t; - -typedef struct nflog_tlv { - uint16_t tlv_length; /* tlv length */ - uint16_t tlv_type; /* tlv type */ - /* value follows this */ -} nflog_tlv_t; - -typedef struct nflog_packet_hdr { - uint16_t hw_protocol; /* hw protocol */ - uint8_t hook; /* netfilter hook */ - uint8_t pad; /* padding to 32 bits */ -} nflog_packet_hdr_t; - -typedef struct nflog_hwaddr { - uint16_t hw_addrlen; /* address length */ - uint16_t pad; /* padding to 32-bit boundary */ - uint8_t hw_addr[8]; /* address, up to 8 bytes */ -} nflog_hwaddr_t; - -typedef struct nflog_timestamp { - uint64_t sec; - uint64_t usec; -} nflog_timestamp_t; - -/* - * TLV types. - */ -#define NFULA_PACKET_HDR 1 /* nflog_packet_hdr_t */ -#define NFULA_MARK 2 /* packet mark from skbuff */ -#define NFULA_TIMESTAMP 3 /* nflog_timestamp_t for skbuff's time stamp */ -#define NFULA_IFINDEX_INDEV 4 /* ifindex of device on which packet received (possibly bridge group) */ -#define NFULA_IFINDEX_OUTDEV 5 /* ifindex of device on which packet transmitted (possibly bridge group) */ -#define NFULA_IFINDEX_PHYSINDEV 6 /* ifindex of physical device on which packet received (not bridge group) */ -#define NFULA_IFINDEX_PHYSOUTDEV 7 /* ifindex of physical device on which packet transmitted (not bridge group) */ -#define NFULA_HWADDR 8 /* nflog_hwaddr_t for hardware address */ -#define NFULA_PAYLOAD 9 /* packet payload */ -#define NFULA_PREFIX 10 /* text string - null-terminated, count includes NUL */ -#define NFULA_UID 11 /* UID owning socket on which packet was sent/received */ -#define NFULA_SEQ 12 /* sequence number of packets on this NFLOG socket */ -#define NFULA_SEQ_GLOBAL 13 /* sequence number of pakets on all NFLOG sockets */ -#define NFULA_GID 14 /* GID owning socket on which packet was sent/received */ -#define NFULA_HWTYPE 15 /* ARPHRD_ type of skbuff's device */ -#define NFULA_HWHEADER 16 /* skbuff's MAC-layer header */ -#define NFULA_HWLEN 17 /* length of skbuff's MAC-layer header */ - -#endif diff --git a/src/pcap/pcap-inttypes.h b/src/pcap/pcap-inttypes.h deleted file mode 100644 index af2c23c..0000000 --- a/src/pcap/pcap-inttypes.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2002 - 2005 NetGroup, Politecnico di Torino (Italy) - * Copyright (c) 2005 - 2009 CACE Technologies, Inc. Davis (California) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Politecnico di Torino nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef pcap_pcap_inttypes_h -#define pcap_pcap_inttypes_h - -/* - * Get the integer types and PRi[doux]64 values from C99 - * defined, by hook or by crook. - */ -#if defined(_MSC_VER) - /* - * Compiler is MSVC. - */ - #if _MSC_VER >= 1800 - /* - * VS 2013 or newer; we have . - */ - #include - #else - /* - * Earlier VS; we have to define this stuff ourselves. - */ - typedef unsigned char uint8_t; - typedef signed char int8_t; - typedef unsigned short uint16_t; - typedef signed short int16_t; - typedef unsigned int uint32_t; - typedef signed int int32_t; - #ifdef _MSC_EXTENSIONS - typedef unsigned _int64 uint64_t; - typedef _int64 int64_t; - #else /* _MSC_EXTENSIONS */ - typedef unsigned long long uint64_t; - typedef long long int64_t; - #endif - #endif - - /* - * These may be defined by . - * - * XXX - for MSVC, we always want the _MSC_EXTENSIONS versions. - * What about other compilers? If, as the MinGW Web site says MinGW - * does, the other compilers just use Microsoft's run-time library, - * then they should probably use the _MSC_EXTENSIONS even if the - * compiler doesn't define _MSC_EXTENSIONS. - * - * XXX - we currently aren't using any of these, but this allows - * their use in the future. - */ - #ifndef PRId64 - #ifdef _MSC_EXTENSIONS - #define PRId64 "I64d" - #else - #define PRId64 "lld" - #endif - #endif /* PRId64 */ - - #ifndef PRIo64 - #ifdef _MSC_EXTENSIONS - #define PRIo64 "I64o" - #else - #define PRIo64 "llo" - #endif - #endif /* PRIo64 */ - - #ifndef PRIx64 - #ifdef _MSC_EXTENSIONS - #define PRIx64 "I64x" - #else - #define PRIx64 "llx" - #endif - #endif - - #ifndef PRIu64 - #ifdef _MSC_EXTENSIONS - #define PRIu64 "I64u" - #else - #define PRIu64 "llu" - #endif - #endif -#elif defined(__MINGW32__) || !defined(_WIN32) - /* - * Compiler is MinGW or target is UN*X or MS-DOS. Just use - * . - */ - #include -#endif - -#endif /* pcap/pcap-inttypes.h */ diff --git a/src/pcap/pcap.h b/src/pcap/pcap.h deleted file mode 100644 index d32e2a9..0000000 --- a/src/pcap/pcap.h +++ /dev/null @@ -1,966 +0,0 @@ -/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */ -/* - * Copyright (c) 1993, 1994, 1995, 1996, 1997 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the Computer Systems - * Engineering Group at Lawrence Berkeley Laboratory. - * 4. Neither the name of the University nor of the Laboratory may be used - * to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * Remote packet capture mechanisms and extensions from WinPcap: - * - * Copyright (c) 2002 - 2003 - * NetGroup, Politecnico di Torino (Italy) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Politecnico di Torino nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef lib_pcap_pcap_h -#define lib_pcap_pcap_h - -#include - -#include - -#if defined(_WIN32) - #include /* u_int, u_char etc. */ - #include /* _get_osfhandle() */ -#elif defined(MSDOS) - #include /* u_int, u_char etc. */ - #include -#else /* UN*X */ - #include /* u_int, u_char etc. */ - #include -#endif /* _WIN32/MSDOS/UN*X */ - -#ifndef PCAP_DONT_INCLUDE_PCAP_BPF_H -#include -#endif - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Version number of the current version of the pcap file format. - * - * NOTE: this is *NOT* the version number of the libpcap library. - * To fetch the version information for the version of libpcap - * you're using, use pcap_lib_version(). - */ -#define PCAP_VERSION_MAJOR 2 -#define PCAP_VERSION_MINOR 4 - -#define PCAP_ERRBUF_SIZE 256 - -/* - * Compatibility for systems that have a bpf.h that - * predates the bpf typedefs for 64-bit support. - */ -#if BPF_RELEASE - 0 < 199406 -typedef int bpf_int32; -typedef u_int bpf_u_int32; -#endif - -typedef struct pcap pcap_t; -typedef struct pcap_dumper pcap_dumper_t; -typedef struct pcap_if pcap_if_t; -typedef struct pcap_addr pcap_addr_t; - -/* - * The first record in the file contains saved values for some - * of the flags used in the printout phases of tcpdump. - * Many fields here are 32 bit ints so compilers won't insert unwanted - * padding; these files need to be interchangeable across architectures. - * - * Do not change the layout of this structure, in any way (this includes - * changes that only affect the length of fields in this structure). - * - * Also, do not change the interpretation of any of the members of this - * structure, in any way (this includes using values other than - * LINKTYPE_ values, as defined in "savefile.c", in the "linktype" - * field). - * - * Instead: - * - * introduce a new structure for the new format, if the layout - * of the structure changed; - * - * send mail to "tcpdump-workers@lists.tcpdump.org", requesting - * a new magic number for your new capture file format, and, when - * you get the new magic number, put it in "savefile.c"; - * - * use that magic number for save files with the changed file - * header; - * - * make the code in "savefile.c" capable of reading files with - * the old file header as well as files with the new file header - * (using the magic number to determine the header format). - * - * Then supply the changes by forking the branch at - * - * https://github.com/the-tcpdump-group/libpcap/issues - * - * and issuing a pull request, so that future versions of libpcap and - * programs that use it (such as tcpdump) will be able to read your new - * capture file format. - */ -struct pcap_file_header { - bpf_u_int32 magic; - u_short version_major; - u_short version_minor; - bpf_int32 thiszone; /* gmt to local correction */ - bpf_u_int32 sigfigs; /* accuracy of timestamps */ - bpf_u_int32 snaplen; /* max length saved portion of each pkt */ - bpf_u_int32 linktype; /* data link type (LINKTYPE_*) */ -}; - -/* - * Macros for the value returned by pcap_datalink_ext(). - * - * If LT_FCS_LENGTH_PRESENT(x) is true, the LT_FCS_LENGTH(x) macro - * gives the FCS length of packets in the capture. - */ -#define LT_FCS_LENGTH_PRESENT(x) ((x) & 0x04000000) -#define LT_FCS_LENGTH(x) (((x) & 0xF0000000) >> 28) -#define LT_FCS_DATALINK_EXT(x) ((((x) & 0xF) << 28) | 0x04000000) - -typedef enum { - PCAP_D_INOUT = 0, - PCAP_D_IN, - PCAP_D_OUT -} pcap_direction_t; - -/* - * Generic per-packet information, as supplied by libpcap. - * - * The time stamp can and should be a "struct timeval", regardless of - * whether your system supports 32-bit tv_sec in "struct timeval", - * 64-bit tv_sec in "struct timeval", or both if it supports both 32-bit - * and 64-bit applications. The on-disk format of savefiles uses 32-bit - * tv_sec (and tv_usec); this structure is irrelevant to that. 32-bit - * and 64-bit versions of libpcap, even if they're on the same platform, - * should supply the appropriate version of "struct timeval", even if - * that's not what the underlying packet capture mechanism supplies. - */ -struct pcap_pkthdr { - struct timeval ts; /* time stamp */ - bpf_u_int32 caplen; /* length of portion present */ - bpf_u_int32 len; /* length this packet (off wire) */ -}; - -/* - * As returned by the pcap_stats() - */ -struct pcap_stat { - u_int ps_recv; /* number of packets received */ - u_int ps_drop; /* number of packets dropped */ - u_int ps_ifdrop; /* drops by interface -- only supported on some platforms */ -#ifdef _WIN32 - u_int ps_capt; /* number of packets that reach the application */ - u_int ps_sent; /* number of packets sent by the server on the network */ - u_int ps_netdrop; /* number of packets lost on the network */ -#endif /* _WIN32 */ -}; - -#ifdef MSDOS -/* - * As returned by the pcap_stats_ex() - */ -struct pcap_stat_ex { - u_long rx_packets; /* total packets received */ - u_long tx_packets; /* total packets transmitted */ - u_long rx_bytes; /* total bytes received */ - u_long tx_bytes; /* total bytes transmitted */ - u_long rx_errors; /* bad packets received */ - u_long tx_errors; /* packet transmit problems */ - u_long rx_dropped; /* no space in Rx buffers */ - u_long tx_dropped; /* no space available for Tx */ - u_long multicast; /* multicast packets received */ - u_long collisions; - - /* detailed rx_errors: */ - u_long rx_length_errors; - u_long rx_over_errors; /* receiver ring buff overflow */ - u_long rx_crc_errors; /* recv'd pkt with crc error */ - u_long rx_frame_errors; /* recv'd frame alignment error */ - u_long rx_fifo_errors; /* recv'r fifo overrun */ - u_long rx_missed_errors; /* recv'r missed packet */ - - /* detailed tx_errors */ - u_long tx_aborted_errors; - u_long tx_carrier_errors; - u_long tx_fifo_errors; - u_long tx_heartbeat_errors; - u_long tx_window_errors; - }; -#endif - -/* - * Item in a list of interfaces. - */ -struct pcap_if { - struct pcap_if *next; - char *name; /* name to hand to "pcap_open_live()" */ - char *description; /* textual description of interface, or NULL */ - struct pcap_addr *addresses; - bpf_u_int32 flags; /* PCAP_IF_ interface flags */ -}; - -#define PCAP_IF_LOOPBACK 0x00000001 /* interface is loopback */ -#define PCAP_IF_UP 0x00000002 /* interface is up */ -#define PCAP_IF_RUNNING 0x00000004 /* interface is running */ - -/* - * Representation of an interface address. - */ -struct pcap_addr { - struct pcap_addr *next; - struct sockaddr *addr; /* address */ - struct sockaddr *netmask; /* netmask for that address */ - struct sockaddr *broadaddr; /* broadcast address for that address */ - struct sockaddr *dstaddr; /* P2P destination address for that address */ -}; - -typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *, - const u_char *); - -/* - * Error codes for the pcap API. - * These will all be negative, so you can check for the success or - * failure of a call that returns these codes by checking for a - * negative value. - */ -#define PCAP_ERROR -1 /* generic error code */ -#define PCAP_ERROR_BREAK -2 /* loop terminated by pcap_breakloop */ -#define PCAP_ERROR_NOT_ACTIVATED -3 /* the capture needs to be activated */ -#define PCAP_ERROR_ACTIVATED -4 /* the operation can't be performed on already activated captures */ -#define PCAP_ERROR_NO_SUCH_DEVICE -5 /* no such device exists */ -#define PCAP_ERROR_RFMON_NOTSUP -6 /* this device doesn't support rfmon (monitor) mode */ -#define PCAP_ERROR_NOT_RFMON -7 /* operation supported only in monitor mode */ -#define PCAP_ERROR_PERM_DENIED -8 /* no permission to open the device */ -#define PCAP_ERROR_IFACE_NOT_UP -9 /* interface isn't up */ -#define PCAP_ERROR_CANTSET_TSTAMP_TYPE -10 /* this device doesn't support setting the time stamp type */ -#define PCAP_ERROR_PROMISC_PERM_DENIED -11 /* you don't have permission to capture in promiscuous mode */ -#define PCAP_ERROR_TSTAMP_PRECISION_NOTSUP -12 /* the requested time stamp precision is not supported */ - -/* - * Warning codes for the pcap API. - * These will all be positive and non-zero, so they won't look like - * errors. - */ -#define PCAP_WARNING 1 /* generic warning code */ -#define PCAP_WARNING_PROMISC_NOTSUP 2 /* this device doesn't support promiscuous mode */ -#define PCAP_WARNING_TSTAMP_TYPE_NOTSUP 3 /* the requested time stamp type is not supported */ - -/* - * Value to pass to pcap_compile() as the netmask if you don't know what - * the netmask is. - */ -#define PCAP_NETMASK_UNKNOWN 0xffffffff - -/* - * We're deprecating pcap_lookupdev() for various reasons (not - * thread-safe, can behave weirdly with WinPcap). Callers - * should use pcap_findalldevs() and use the first device. - */ -PCAP_API char *pcap_lookupdev(char *) -PCAP_DEPRECATED(pcap_lookupdev, "use 'pcap_findalldevs' and use the first device"); - -PCAP_API int pcap_lookupnet(const char *, bpf_u_int32 *, bpf_u_int32 *, char *); - -PCAP_API pcap_t *pcap_create(const char *, char *); -PCAP_API int pcap_set_snaplen(pcap_t *, int); -PCAP_API int pcap_set_promisc(pcap_t *, int); -PCAP_API int pcap_can_set_rfmon(pcap_t *); -PCAP_API int pcap_set_rfmon(pcap_t *, int); -PCAP_API int pcap_set_timeout(pcap_t *, int); -PCAP_API int pcap_set_tstamp_type(pcap_t *, int); -PCAP_API int pcap_set_immediate_mode(pcap_t *, int); -PCAP_API int pcap_set_buffer_size(pcap_t *, int); -PCAP_API int pcap_set_tstamp_precision(pcap_t *, int); -PCAP_API int pcap_get_tstamp_precision(pcap_t *); -PCAP_API int pcap_activate(pcap_t *); - -PCAP_API int pcap_list_tstamp_types(pcap_t *, int **); -PCAP_API void pcap_free_tstamp_types(int *); -PCAP_API int pcap_tstamp_type_name_to_val(const char *); -PCAP_API const char *pcap_tstamp_type_val_to_name(int); -PCAP_API const char *pcap_tstamp_type_val_to_description(int); - -#ifdef __linux__ -PCAP_API int pcap_set_protocol(pcap_t *, int); -#endif - -/* - * Time stamp types. - * Not all systems and interfaces will necessarily support all of these. - * - * A system that supports PCAP_TSTAMP_HOST is offering time stamps - * provided by the host machine, rather than by the capture device, - * but not committing to any characteristics of the time stamp; - * it will not offer any of the PCAP_TSTAMP_HOST_ subtypes. - * - * PCAP_TSTAMP_HOST_LOWPREC is a time stamp, provided by the host machine, - * that's low-precision but relatively cheap to fetch; it's normally done - * using the system clock, so it's normally synchronized with times you'd - * fetch from system calls. - * - * PCAP_TSTAMP_HOST_HIPREC is a time stamp, provided by the host machine, - * that's high-precision; it might be more expensive to fetch. It might - * or might not be synchronized with the system clock, and might have - * problems with time stamps for packets received on different CPUs, - * depending on the platform. - * - * PCAP_TSTAMP_ADAPTER is a high-precision time stamp supplied by the - * capture device; it's synchronized with the system clock. - * - * PCAP_TSTAMP_ADAPTER_UNSYNCED is a high-precision time stamp supplied by - * the capture device; it's not synchronized with the system clock. - * - * Note that time stamps synchronized with the system clock can go - * backwards, as the system clock can go backwards. If a clock is - * not in sync with the system clock, that could be because the - * system clock isn't keeping accurate time, because the other - * clock isn't keeping accurate time, or both. - * - * Note that host-provided time stamps generally correspond to the - * time when the time-stamping code sees the packet; this could - * be some unknown amount of time after the first or last bit of - * the packet is received by the network adapter, due to batching - * of interrupts for packet arrival, queueing delays, etc.. - */ -#define PCAP_TSTAMP_HOST 0 /* host-provided, unknown characteristics */ -#define PCAP_TSTAMP_HOST_LOWPREC 1 /* host-provided, low precision */ -#define PCAP_TSTAMP_HOST_HIPREC 2 /* host-provided, high precision */ -#define PCAP_TSTAMP_ADAPTER 3 /* device-provided, synced with the system clock */ -#define PCAP_TSTAMP_ADAPTER_UNSYNCED 4 /* device-provided, not synced with the system clock */ - -/* - * Time stamp resolution types. - * Not all systems and interfaces will necessarily support all of these - * resolutions when doing live captures; all of them can be requested - * when reading a savefile. - */ -#define PCAP_TSTAMP_PRECISION_MICRO 0 /* use timestamps with microsecond precision, default */ -#define PCAP_TSTAMP_PRECISION_NANO 1 /* use timestamps with nanosecond precision */ - -PCAP_API pcap_t *pcap_open_live(const char *, int, int, int, char *); -PCAP_API pcap_t *pcap_open_dead(int, int); -PCAP_API pcap_t *pcap_open_dead_with_tstamp_precision(int, int, u_int); -PCAP_API pcap_t *pcap_open_offline_with_tstamp_precision(const char *, u_int, char *); -PCAP_API pcap_t *pcap_open_offline(const char *, char *); -#ifdef _WIN32 - PCAP_API pcap_t *pcap_hopen_offline_with_tstamp_precision(intptr_t, u_int, char *); - PCAP_API pcap_t *pcap_hopen_offline(intptr_t, char *); - /* - * If we're building libpcap, these are internal routines in savefile.c, - * so we must not define them as macros. - * - * If we're not building libpcap, given that the version of the C runtime - * with which libpcap was built might be different from the version - * of the C runtime with which an application using libpcap was built, - * and that a FILE structure may differ between the two versions of the - * C runtime, calls to _fileno() must use the version of _fileno() in - * the C runtime used to open the FILE *, not the version in the C - * runtime with which libpcap was built. (Maybe once the Universal CRT - * rules the world, this will cease to be a problem.) - */ - #ifndef BUILDING_PCAP - #define pcap_fopen_offline_with_tstamp_precision(f,p,b) \ - pcap_hopen_offline_with_tstamp_precision(_get_osfhandle(_fileno(f)), p, b) - #define pcap_fopen_offline(f,b) \ - pcap_hopen_offline(_get_osfhandle(_fileno(f)), b) - #endif -#else /*_WIN32*/ - PCAP_API pcap_t *pcap_fopen_offline_with_tstamp_precision(FILE *, u_int, char *); - PCAP_API pcap_t *pcap_fopen_offline(FILE *, char *); -#endif /*_WIN32*/ - -PCAP_API void pcap_close(pcap_t *); -PCAP_API int pcap_loop(pcap_t *, int, pcap_handler, u_char *); -PCAP_API int pcap_dispatch(pcap_t *, int, pcap_handler, u_char *); -PCAP_API const u_char *pcap_next(pcap_t *, struct pcap_pkthdr *); -PCAP_API int pcap_next_ex(pcap_t *, struct pcap_pkthdr **, const u_char **); -PCAP_API void pcap_breakloop(pcap_t *); -PCAP_API int pcap_stats(pcap_t *, struct pcap_stat *); -PCAP_API int pcap_setfilter(pcap_t *, struct bpf_program *); -PCAP_API int pcap_setdirection(pcap_t *, pcap_direction_t); -PCAP_API int pcap_getnonblock(pcap_t *, char *); -PCAP_API int pcap_setnonblock(pcap_t *, int, char *); -PCAP_API int pcap_inject(pcap_t *, const void *, size_t); -PCAP_API int pcap_sendpacket(pcap_t *, const u_char *, int); -PCAP_API const char *pcap_statustostr(int); -PCAP_API const char *pcap_strerror(int); -PCAP_API char *pcap_geterr(pcap_t *); -PCAP_API void pcap_perror(pcap_t *, const char *); -PCAP_API int pcap_compile(pcap_t *, struct bpf_program *, const char *, int, - bpf_u_int32); -PCAP_API int pcap_compile_nopcap(int, int, struct bpf_program *, - const char *, int, bpf_u_int32); -PCAP_API void pcap_freecode(struct bpf_program *); -PCAP_API int pcap_offline_filter(const struct bpf_program *, - const struct pcap_pkthdr *, const u_char *); -PCAP_API int pcap_datalink(pcap_t *); -PCAP_API int pcap_datalink_ext(pcap_t *); -PCAP_API int pcap_list_datalinks(pcap_t *, int **); -PCAP_API int pcap_set_datalink(pcap_t *, int); -PCAP_API void pcap_free_datalinks(int *); -PCAP_API int pcap_datalink_name_to_val(const char *); -PCAP_API const char *pcap_datalink_val_to_name(int); -PCAP_API const char *pcap_datalink_val_to_description(int); -PCAP_API int pcap_snapshot(pcap_t *); -PCAP_API int pcap_is_swapped(pcap_t *); -PCAP_API int pcap_major_version(pcap_t *); -PCAP_API int pcap_minor_version(pcap_t *); -PCAP_API int pcap_bufsize(pcap_t *); - -/* XXX */ -PCAP_API FILE *pcap_file(pcap_t *); -PCAP_API int pcap_fileno(pcap_t *); - -#ifdef _WIN32 - PCAP_API int pcap_wsockinit(void); -#endif - -PCAP_API pcap_dumper_t *pcap_dump_open(pcap_t *, const char *); -PCAP_API pcap_dumper_t *pcap_dump_fopen(pcap_t *, FILE *fp); -PCAP_API pcap_dumper_t *pcap_dump_open_append(pcap_t *, const char *); -PCAP_API FILE *pcap_dump_file(pcap_dumper_t *); -PCAP_API long pcap_dump_ftell(pcap_dumper_t *); -PCAP_API int64_t pcap_dump_ftell64(pcap_dumper_t *); -PCAP_API int pcap_dump_flush(pcap_dumper_t *); -PCAP_API void pcap_dump_close(pcap_dumper_t *); -PCAP_API void pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *); - -PCAP_API int pcap_findalldevs(pcap_if_t **, char *); -PCAP_API void pcap_freealldevs(pcap_if_t *); - -/* - * We return a pointer to the version string, rather than exporting the - * version string directly. - * - * On at least some UNIXes, if you import data from a shared library into - * an program, the data is bound into the program binary, so if the string - * in the version of the library with which the program was linked isn't - * the same as the string in the version of the library with which the - * program is being run, various undesirable things may happen (warnings, - * the string being the one from the version of the library with which the - * program was linked, or even weirder things, such as the string being the - * one from the library but being truncated). - * - * On Windows, the string is constructed at run time. - */ -PCAP_API const char *pcap_lib_version(void); - -/* - * On at least some versions of NetBSD and QNX, we don't want to declare - * bpf_filter() here, as it's also be declared in , with a - * different signature, but, on other BSD-flavored UN*Xes, it's not - * declared in , so we *do* want to declare it here, so it's - * declared when we build pcap-bpf.c. - */ -#if !defined(__NetBSD__) && !defined(__QNX__) - PCAP_API u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int); -#endif -PCAP_API int bpf_validate(const struct bpf_insn *f, int len); -PCAP_API char *bpf_image(const struct bpf_insn *, int); -PCAP_API void bpf_dump(const struct bpf_program *, int); - -#if defined(_WIN32) - - /* - * Win32 definitions - */ - - /*! - \brief A queue of raw packets that will be sent to the network with pcap_sendqueue_transmit(). - */ - struct pcap_send_queue - { - u_int maxlen; /* Maximum size of the queue, in bytes. This - variable contains the size of the buffer field. */ - u_int len; /* Current size of the queue, in bytes. */ - char *buffer; /* Buffer containing the packets to be sent. */ - }; - - typedef struct pcap_send_queue pcap_send_queue; - - /*! - \brief This typedef is a support for the pcap_get_airpcap_handle() function - */ - #if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_) - #define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_ - typedef struct _AirpcapHandle *PAirpcapHandle; - #endif - - PCAP_API int pcap_setbuff(pcap_t *p, int dim); - PCAP_API int pcap_setmode(pcap_t *p, int mode); - PCAP_API int pcap_setmintocopy(pcap_t *p, int size); - - PCAP_API HANDLE pcap_getevent(pcap_t *p); - - PCAP_API int pcap_oid_get_request(pcap_t *, bpf_u_int32, void *, size_t *); - PCAP_API int pcap_oid_set_request(pcap_t *, bpf_u_int32, const void *, size_t *); - - PCAP_API pcap_send_queue* pcap_sendqueue_alloc(u_int memsize); - - PCAP_API void pcap_sendqueue_destroy(pcap_send_queue* queue); - - PCAP_API int pcap_sendqueue_queue(pcap_send_queue* queue, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data); - - PCAP_API u_int pcap_sendqueue_transmit(pcap_t *p, pcap_send_queue* queue, int sync); - - PCAP_API struct pcap_stat *pcap_stats_ex(pcap_t *p, int *pcap_stat_size); - - PCAP_API int pcap_setuserbuffer(pcap_t *p, int size); - - PCAP_API int pcap_live_dump(pcap_t *p, char *filename, int maxsize, int maxpacks); - - PCAP_API int pcap_live_dump_ended(pcap_t *p, int sync); - - PCAP_API int pcap_start_oem(char* err_str, int flags); - - PCAP_API PAirpcapHandle pcap_get_airpcap_handle(pcap_t *p); - - #define MODE_CAPT 0 - #define MODE_STAT 1 - #define MODE_MON 2 - -#elif defined(MSDOS) - - /* - * MS-DOS definitions - */ - - PCAP_API int pcap_stats_ex (pcap_t *, struct pcap_stat_ex *); - PCAP_API void pcap_set_wait (pcap_t *p, void (*yield)(void), int wait); - PCAP_API u_long pcap_mac_packets (void); - -#else /* UN*X */ - - /* - * UN*X definitions - */ - - PCAP_API int pcap_get_selectable_fd(pcap_t *); - -#endif /* _WIN32/MSDOS/UN*X */ - -/* - * Remote capture definitions. - * - * These routines are only present if libpcap has been configured to - * include remote capture support. - */ - -/* - * The maximum buffer size in which address, port, interface names are kept. - * - * In case the adapter name or such is larger than this value, it is truncated. - * This is not used by the user; however it must be aware that an hostname / interface - * name longer than this value will be truncated. - */ -#define PCAP_BUF_SIZE 1024 - -/* - * The type of input source, passed to pcap_open(). - */ -#define PCAP_SRC_FILE 2 /* local savefile */ -#define PCAP_SRC_IFLOCAL 3 /* local network interface */ -#define PCAP_SRC_IFREMOTE 4 /* interface on a remote host, using RPCAP */ - -/* - * The formats allowed by pcap_open() are the following: - * - file://path_and_filename [opens a local file] - * - rpcap://devicename [opens the selected device devices available on the local host, without using the RPCAP protocol] - * - rpcap://host/devicename [opens the selected device available on a remote host] - * - rpcap://host:port/devicename [opens the selected device available on a remote host, using a non-standard port for RPCAP] - * - adaptername [to open a local adapter; kept for compability, but it is strongly discouraged] - * - (NULL) [to open the first local adapter; kept for compability, but it is strongly discouraged] - * - * The formats allowed by the pcap_findalldevs_ex() are the following: - * - file://folder/ [lists all the files in the given folder] - * - rpcap:// [lists all local adapters] - * - rpcap://host:port/ [lists the devices available on a remote host] - * - * Referring to the 'host' and 'port' parameters, they can be either numeric or literal. Since - * IPv6 is fully supported, these are the allowed formats: - * - * - host (literal): e.g. host.foo.bar - * - host (numeric IPv4): e.g. 10.11.12.13 - * - host (numeric IPv4, IPv6 style): e.g. [10.11.12.13] - * - host (numeric IPv6): e.g. [1:2:3::4] - * - port: can be either numeric (e.g. '80') or literal (e.g. 'http') - * - * Here you find some allowed examples: - * - rpcap://host.foo.bar/devicename [everything literal, no port number] - * - rpcap://host.foo.bar:1234/devicename [everything literal, with port number] - * - rpcap://10.11.12.13/devicename [IPv4 numeric, no port number] - * - rpcap://10.11.12.13:1234/devicename [IPv4 numeric, with port number] - * - rpcap://[10.11.12.13]:1234/devicename [IPv4 numeric with IPv6 format, with port number] - * - rpcap://[1:2:3::4]/devicename [IPv6 numeric, no port number] - * - rpcap://[1:2:3::4]:1234/devicename [IPv6 numeric, with port number] - * - rpcap://[1:2:3::4]:http/devicename [IPv6 numeric, with literal port number] - */ - -/* - * URL schemes for capture source. - */ -/* - * This string indicates that the user wants to open a capture from a - * local file. - */ -#define PCAP_SRC_FILE_STRING "file://" -/* - * This string indicates that the user wants to open a capture from a - * network interface. This string does not necessarily involve the use - * of the RPCAP protocol. If the interface required resides on the local - * host, the RPCAP protocol is not involved and the local functions are used. - */ -#define PCAP_SRC_IF_STRING "rpcap://" - -/* - * Flags to pass to pcap_open(). - */ - -/* - * Specifies whether promiscuous mode is to be used. - */ -#define PCAP_OPENFLAG_PROMISCUOUS 0x00000001 - -/* - * Specifies, for an RPCAP capture, whether the data transfer (in - * case of a remote capture) has to be done with UDP protocol. - * - * If it is '1' if you want a UDP data connection, '0' if you want - * a TCP data connection; control connection is always TCP-based. - * A UDP connection is much lighter, but it does not guarantee that all - * the captured packets arrive to the client workstation. Moreover, - * it could be harmful in case of network congestion. - * This flag is meaningless if the source is not a remote interface. - * In that case, it is simply ignored. - */ -#define PCAP_OPENFLAG_DATATX_UDP 0x00000002 - -/* - * Specifies wheether the remote probe will capture its own generated - * traffic. - * - * In case the remote probe uses the same interface to capture traffic - * and to send data back to the caller, the captured traffic includes - * the RPCAP traffic as well. If this flag is turned on, the RPCAP - * traffic is excluded from the capture, so that the trace returned - * back to the collector is does not include this traffic. - * - * Has no effect on local interfaces or savefiles. - */ -#define PCAP_OPENFLAG_NOCAPTURE_RPCAP 0x00000004 - -/* - * Specifies whether the local adapter will capture its own generated traffic. - * - * This flag tells the underlying capture driver to drop the packets - * that were sent by itself. This is useful when building applications - * such as bridges that should ignore the traffic they just sent. - * - * Supported only on Windows. - */ -#define PCAP_OPENFLAG_NOCAPTURE_LOCAL 0x00000008 - -/* - * This flag configures the adapter for maximum responsiveness. - * - * In presence of a large value for nbytes, WinPcap waits for the arrival - * of several packets before copying the data to the user. This guarantees - * a low number of system calls, i.e. lower processor usage, i.e. better - * performance, which is good for applications like sniffers. If the user - * sets the PCAP_OPENFLAG_MAX_RESPONSIVENESS flag, the capture driver will - * copy the packets as soon as the application is ready to receive them. - * This is suggested for real time applications (such as, for example, - * a bridge) that need the best responsiveness. - * - * The equivalent with pcap_create()/pcap_activate() is "immediate mode". - */ -#define PCAP_OPENFLAG_MAX_RESPONSIVENESS 0x00000010 - -/* - * Remote authentication methods. - * These are used in the 'type' member of the pcap_rmtauth structure. - */ - -/* - * NULL authentication. - * - * The 'NULL' authentication has to be equal to 'zero', so that old - * applications can just put every field of struct pcap_rmtauth to zero, - * and it does work. - */ -#define RPCAP_RMTAUTH_NULL 0 -/* - * Username/password authentication. - * - * With this type of authentication, the RPCAP protocol will use the username/ - * password provided to authenticate the user on the remote machine. If the - * authentication is successful (and the user has the right to open network - * devices) the RPCAP connection will continue; otherwise it will be dropped. - * - * *******NOTE********: the username and password are sent over the network - * to the capture server *IN CLEAR TEXT*. Don't use this on a network - * that you don't completely control! (And be *really* careful in your - * definition of "completely"!) - */ -#define RPCAP_RMTAUTH_PWD 1 - -/* - * This structure keeps the information needed to autheticate the user - * on a remote machine. - * - * The remote machine can either grant or refuse the access according - * to the information provided. - * In case the NULL authentication is required, both 'username' and - * 'password' can be NULL pointers. - * - * This structure is meaningless if the source is not a remote interface; - * in that case, the functions which requires such a structure can accept - * a NULL pointer as well. - */ -struct pcap_rmtauth -{ - /* - * \brief Type of the authentication required. - * - * In order to provide maximum flexibility, we can support different types - * of authentication based on the value of this 'type' variable. The currently - * supported authentication methods are defined into the - * \link remote_auth_methods Remote Authentication Methods Section\endlink. - */ - int type; - /* - * \brief Zero-terminated string containing the username that has to be - * used on the remote machine for authentication. - * - * This field is meaningless in case of the RPCAP_RMTAUTH_NULL authentication - * and it can be NULL. - */ - char *username; - /* - * \brief Zero-terminated string containing the password that has to be - * used on the remote machine for authentication. - * - * This field is meaningless in case of the RPCAP_RMTAUTH_NULL authentication - * and it can be NULL. - */ - char *password; -}; - -/* - * This routine can open a savefile, a local device, or a device on - * a remote machine running an RPCAP server. - * - * For opening a savefile, the pcap_open_offline routines can be used, - * and will work just as well; code using them will work on more - * platforms than code using pcap_open() to open savefiles. - * - * For opening a local device, pcap_open_live() can be used; it supports - * most of the capabilities that pcap_open() supports, and code using it - * will work on more platforms than code using pcap_open(). pcap_create() - * and pcap_activate() can also be used; they support all capabilities - * that pcap_open() supports, except for the Windows-only - * PCAP_OPENFLAG_NOCAPTURE_LOCAL, and support additional capabilities. - * - * For opening a remote capture, pcap_open() is currently the only - * API available. - */ -PCAP_API pcap_t *pcap_open(const char *source, int snaplen, int flags, - int read_timeout, struct pcap_rmtauth *auth, char *errbuf); -PCAP_API int pcap_createsrcstr(char *source, int type, const char *host, - const char *port, const char *name, char *errbuf); -PCAP_API int pcap_parsesrcstr(const char *source, int *type, char *host, - char *port, char *name, char *errbuf); - -/* - * This routine can scan a directory for savefiles, list local capture - * devices, or list capture devices on a remote machine running an RPCAP - * server. - * - * For scanning for savefiles, it can be used on both UN*X systems and - * Windows systems; for each directory entry it sees, it tries to open - * the file as a savefile using pcap_open_offline(), and only includes - * it in the list of files if the open succeeds, so it filters out - * files for which the user doesn't have read permission, as well as - * files that aren't valid savefiles readable by libpcap. - * - * For listing local capture devices, it's just a wrapper around - * pcap_findalldevs(); code using pcap_findalldevs() will work on more - * platforms than code using pcap_findalldevs_ex(). - * - * For listing remote capture devices, pcap_findalldevs_ex() is currently - * the only API available. - */ -PCAP_API int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, - pcap_if_t **alldevs, char *errbuf); - -/* - * Sampling methods. - * - * These allow pcap_loop(), pcap_dispatch(), pcap_next(), and pcap_next_ex() - * to see only a sample of packets, rather than all packets. - * - * Currently, they work only on Windows local captures. - */ - -/* - * Specifies that no sampling is to be done on the current capture. - * - * In this case, no sampling algorithms are applied to the current capture. - */ -#define PCAP_SAMP_NOSAMP 0 - -/* - * Specifies that only 1 out of N packets must be returned to the user. - * - * In this case, the 'value' field of the 'pcap_samp' structure indicates the - * number of packets (minus 1) that must be discarded before one packet got - * accepted. - * In other words, if 'value = 10', the first packet is returned to the - * caller, while the following 9 are discarded. - */ -#define PCAP_SAMP_1_EVERY_N 1 - -/* - * Specifies that we have to return 1 packet every N milliseconds. - * - * In this case, the 'value' field of the 'pcap_samp' structure indicates - * the 'waiting time' in milliseconds before one packet got accepted. - * In other words, if 'value = 10', the first packet is returned to the - * caller; the next returned one will be the first packet that arrives - * when 10ms have elapsed. - */ -#define PCAP_SAMP_FIRST_AFTER_N_MS 2 - -/* - * This structure defines the information related to sampling. - * - * In case the sampling is requested, the capturing device should read - * only a subset of the packets coming from the source. The returned packets - * depend on the sampling parameters. - * - * WARNING: The sampling process is applied *after* the filtering process. - * In other words, packets are filtered first, then the sampling process - * selects a subset of the 'filtered' packets and it returns them to the - * caller. - */ -struct pcap_samp -{ - /* - * Method used for sampling; see above. - */ - int method; - - /* - * This value depends on the sampling method defined. - * For its meaning, see above. - */ - int value; -}; - -/* - * New functions. - */ -PCAP_API struct pcap_samp *pcap_setsampling(pcap_t *p); - -/* - * RPCAP active mode. - */ - -/* Maximum length of an host name (needed for the RPCAP active mode) */ -#define RPCAP_HOSTLIST_SIZE 1024 - -/* - * Some minor differences between UN*X sockets and and Winsock sockets. - */ -#ifndef _WIN32 - /*! - * \brief In Winsock, a socket handle is of type SOCKET; in UN*X, it's - * a file descriptor, and therefore a signed integer. - * We define SOCKET to be a signed integer on UN*X, so that it can - * be used on both platforms. - */ - #define SOCKET int - - /*! - * \brief In Winsock, the error return if socket() fails is INVALID_SOCKET; - * in UN*X, it's -1. - * We define INVALID_SOCKET to be -1 on UN*X, so that it can be used on - * both platforms. - */ - #define INVALID_SOCKET -1 -#endif - -PCAP_API SOCKET pcap_remoteact_accept(const char *address, const char *port, - const char *hostlist, char *connectinghost, - struct pcap_rmtauth *auth, char *errbuf); -PCAP_API int pcap_remoteact_list(char *hostlist, char sep, int size, - char *errbuf); -PCAP_API int pcap_remoteact_close(const char *host, char *errbuf); -PCAP_API void pcap_remoteact_cleanup(void); - -#ifdef __cplusplus -} -#endif - -#endif /* lib_pcap_pcap_h */ diff --git a/src/pcap/sll.h b/src/pcap/sll.h deleted file mode 100644 index c4d0886..0000000 --- a/src/pcap/sll.h +++ /dev/null @@ -1,131 +0,0 @@ -/*- - * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from the Stanford/CMU enet packet filter, - * (net/enet.c) distributed as part of 4.3BSD, and code contributed - * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence - * Berkeley Laboratory. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * For captures on Linux cooked sockets, we construct a fake header - * that includes: - * - * a 2-byte "packet type" which is one of: - * - * LINUX_SLL_HOST packet was sent to us - * LINUX_SLL_BROADCAST packet was broadcast - * LINUX_SLL_MULTICAST packet was multicast - * LINUX_SLL_OTHERHOST packet was sent to somebody else - * LINUX_SLL_OUTGOING packet was sent *by* us; - * - * a 2-byte Ethernet protocol field; - * - * a 2-byte link-layer type; - * - * a 2-byte link-layer address length; - * - * an 8-byte source link-layer address, whose actual length is - * specified by the previous value. - * - * All fields except for the link-layer address are in network byte order. - * - * DO NOT change the layout of this structure, or change any of the - * LINUX_SLL_ values below. If you must change the link-layer header - * for a "cooked" Linux capture, introduce a new DLT_ type (ask - * "tcpdump-workers@lists.tcpdump.org" for one, so that you don't give it - * a value that collides with a value already being used), and use the - * new header in captures of that type, so that programs that can - * handle DLT_LINUX_SLL captures will continue to handle them correctly - * without any change, and so that capture files with different headers - * can be told apart and programs that read them can dissect the - * packets in them. - */ - -#ifndef lib_pcap_sll_h -#define lib_pcap_sll_h - -/* - * A DLT_LINUX_SLL fake link-layer header. - */ -#define SLL_HDR_LEN 16 /* total header length */ -#define SLL_ADDRLEN 8 /* length of address field */ - -#include - -struct sll_header { - uint16_t sll_pkttype; /* packet type */ - uint16_t sll_hatype; /* link-layer address type */ - uint16_t sll_halen; /* link-layer address length */ - uint8_t sll_addr[SLL_ADDRLEN]; /* link-layer address */ - uint16_t sll_protocol; /* protocol */ -}; - -/* - * The LINUX_SLL_ values for "sll_pkttype"; these correspond to the - * PACKET_ values on Linux, but are defined here so that they're - * available even on systems other than Linux, and so that they - * don't change even if the PACKET_ values change. - */ -#define LINUX_SLL_HOST 0 -#define LINUX_SLL_BROADCAST 1 -#define LINUX_SLL_MULTICAST 2 -#define LINUX_SLL_OTHERHOST 3 -#define LINUX_SLL_OUTGOING 4 - -/* - * The LINUX_SLL_ values for "sll_protocol"; these correspond to the - * ETH_P_ values on Linux, but are defined here so that they're - * available even on systems other than Linux. We assume, for now, - * that the ETH_P_ values won't change in Linux; if they do, then: - * - * if we don't translate them in "pcap-linux.c", capture files - * won't necessarily be readable if captured on a system that - * defines ETH_P_ values that don't match these values; - * - * if we do translate them in "pcap-linux.c", that makes life - * unpleasant for the BPF code generator, as the values you test - * for in the kernel aren't the values that you test for when - * reading a capture file, so the fixup code run on BPF programs - * handed to the kernel ends up having to do more work. - * - * Add other values here as necessary, for handling packet types that - * might show up on non-Ethernet, non-802.x networks. (Not all the ones - * in the Linux "if_ether.h" will, I suspect, actually show up in - * captures.) - */ -#define LINUX_SLL_P_802_3 0x0001 /* Novell 802.3 frames without 802.2 LLC header */ -#define LINUX_SLL_P_802_2 0x0004 /* 802.2 frames (not D/I/X Ethernet) */ -#define LINUX_SLL_P_CAN 0x000C /* CAN frames, with SocketCAN pseudo-headers */ -#define LINUX_SLL_P_CANFD 0x000D /* CAN FD frames, with SocketCAN pseudo-headers */ - -#endif diff --git a/src/pcap/usb.h b/src/pcap/usb.h deleted file mode 100644 index e485ec8..0000000 --- a/src/pcap/usb.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2006 Paolo Abeni (Italy) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Basic USB data struct - * By Paolo Abeni - */ - -#ifndef lib_pcap_usb_h -#define lib_pcap_usb_h - -#include - -/* - * possible transfer mode - */ -#define URB_TRANSFER_IN 0x80 -#define URB_ISOCHRONOUS 0x0 -#define URB_INTERRUPT 0x1 -#define URB_CONTROL 0x2 -#define URB_BULK 0x3 - -/* - * possible event type - */ -#define URB_SUBMIT 'S' -#define URB_COMPLETE 'C' -#define URB_ERROR 'E' - -/* - * USB setup header as defined in USB specification. - * Appears at the front of each Control S-type packet in DLT_USB captures. - */ -typedef struct _usb_setup { - uint8_t bmRequestType; - uint8_t bRequest; - uint16_t wValue; - uint16_t wIndex; - uint16_t wLength; -} pcap_usb_setup; - -/* - * Information from the URB for Isochronous transfers. - */ -typedef struct _iso_rec { - int32_t error_count; - int32_t numdesc; -} iso_rec; - -/* - * Header prepended by linux kernel to each event. - * Appears at the front of each packet in DLT_USB_LINUX captures. - */ -typedef struct _usb_header { - uint64_t id; - uint8_t event_type; - uint8_t transfer_type; - uint8_t endpoint_number; - uint8_t device_address; - uint16_t bus_id; - char setup_flag;/*if !=0 the urb setup header is not present*/ - char data_flag; /*if !=0 no urb data is present*/ - int64_t ts_sec; - int32_t ts_usec; - int32_t status; - uint32_t urb_len; - uint32_t data_len; /* amount of urb data really present in this event*/ - pcap_usb_setup setup; -} pcap_usb_header; - -/* - * Header prepended by linux kernel to each event for the 2.6.31 - * and later kernels; for the 2.6.21 through 2.6.30 kernels, the - * "iso_rec" information, and the fields starting with "interval" - * are zeroed-out padding fields. - * - * Appears at the front of each packet in DLT_USB_LINUX_MMAPPED captures. - */ -typedef struct _usb_header_mmapped { - uint64_t id; - uint8_t event_type; - uint8_t transfer_type; - uint8_t endpoint_number; - uint8_t device_address; - uint16_t bus_id; - char setup_flag;/*if !=0 the urb setup header is not present*/ - char data_flag; /*if !=0 no urb data is present*/ - int64_t ts_sec; - int32_t ts_usec; - int32_t status; - uint32_t urb_len; - uint32_t data_len; /* amount of urb data really present in this event*/ - union { - pcap_usb_setup setup; - iso_rec iso; - } s; - int32_t interval; /* for Interrupt and Isochronous events */ - int32_t start_frame; /* for Isochronous events */ - uint32_t xfer_flags; /* copy of URB's transfer flags */ - uint32_t ndesc; /* number of isochronous descriptors */ -} pcap_usb_header_mmapped; - -/* - * Isochronous descriptors; for isochronous transfers there might be - * one or more of these at the beginning of the packet data. The - * number of descriptors is given by the "ndesc" field in the header; - * as indicated, in older kernels that don't put the descriptors at - * the beginning of the packet, that field is zeroed out, so that field - * can be trusted even in captures from older kernels. - */ -typedef struct _usb_isodesc { - int32_t status; - uint32_t offset; - uint32_t len; - uint8_t pad[4]; -} usb_isodesc; - -#endif diff --git a/src/pcap/vlan.h b/src/pcap/vlan.h deleted file mode 100644 index b29dd73..0000000 --- a/src/pcap/vlan.h +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lib_pcap_vlan_h -#define lib_pcap_vlan_h - -#include - -struct vlan_tag { - uint16_t vlan_tpid; /* ETH_P_8021Q */ - uint16_t vlan_tci; /* VLAN TCI */ -}; - -#define VLAN_TAG_LEN 4 - -#endif -- cgit v1.2.3 From 590ab2ac2bdc79e536c0f332cf9f1a4d700fffe9 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 28 May 2020 22:37:37 +0200 Subject: fix things --- src/frontend/qt_sdl/CMakeLists.txt | 4 ++++ src/frontend/qt_sdl/main.cpp | 21 +++++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index 0b7fa54..dbc1e3a 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -7,7 +7,10 @@ SET(SOURCES_QT_SDL InputConfigDialog.cpp VideoSettingsDialog.cpp AudioSettingsDialog.cpp + WifiSettingsDialog.cpp Input.cpp + LAN_PCap.cpp + LAN_Socket.cpp OSD.cpp OSD_shaders.h font.h @@ -40,6 +43,7 @@ pkg_check_modules(SDL2 REQUIRED sdl2) add_executable(melonDS ${SOURCES_QT_SDL}) target_include_directories(melonDS PRIVATE ${SDL2_INCLUDE_DIRS}) +target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..") target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../..") target_link_libraries(melonDS core ${SDL2_LIBRARIES}) diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index bea33b0..e60a58d 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -38,6 +38,7 @@ #include "InputConfigDialog.h" #include "VideoSettingsDialog.h" #include "AudioSettingsDialog.h" +#include "WifiSettingsDialog.h" #include "types.h" #include "version.h" @@ -298,9 +299,10 @@ void EmuThread::initOpenGL() oglContext->moveToThread(this); } -void deinitOpenGL() +void EmuThread::deinitOpenGL() { - // TODO!! + delete oglContext; + delete oglSurface; } void* oglGetProcAddress(const char* proc) @@ -545,16 +547,11 @@ void EmuThread::run() NDS::DeInit(); //Platform::LAN_DeInit(); - /*if (Screen_UseGL) - { - OSD::DeInit(true); - GLScreen_DeInit(); - } - else - OSD::DeInit(false);*/ - if (hasOGL) + { oglContext->doneCurrent(); + deinitOpenGL(); + } } void EmuThread::changeWindowTitle(char* title) @@ -844,7 +841,6 @@ void ScreenPanelGL::initializeGL() screenShader->addShaderFromSourceCode(QOpenGLShader::Fragment, kScreenFS); GLuint pid = screenShader->programId(); - printf("program: %d\n", pid); glBindAttribLocation(pid, 0, "vPosition"); glBindAttribLocation(pid, 1, "vTexcoord"); glBindFragDataLocation(pid, 0, "oColor"); @@ -1675,7 +1671,7 @@ void MainWindow::onAudioSettingsFinished(int res) void MainWindow::onOpenWifiSettings() { - // + WifiSettingsDialog::openDlg(this); } void MainWindow::onChangeSavestateSRAMReloc(bool checked) @@ -1822,6 +1818,7 @@ void MainWindow::onUpdateVideoSettings(bool glchange) { emuThread->emuPause(); + if (hasOGL) emuThread->deinitOpenGL(); delete panel; createScreenPanel(); connect(emuThread, SIGNAL(windowUpdate()), panel, SLOT(update())); -- cgit v1.2.3 From a38b20484d72d9d03ac7c807323343c8576c2c35 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 28 May 2020 23:12:21 +0200 Subject: finish the wifi dialog also guess who the idiot is who forgot to add their files --- src/frontend/qt_sdl/Platform.cpp | 22 +++-- src/frontend/qt_sdl/WifiSettingsDialog.cpp | 140 +++++++++++++++++++++++++++++ src/frontend/qt_sdl/WifiSettingsDialog.h | 68 ++++++++++++++ src/frontend/qt_sdl/main.cpp | 19 +++- src/frontend/qt_sdl/main.h | 1 + 5 files changed, 237 insertions(+), 13 deletions(-) create mode 100644 src/frontend/qt_sdl/WifiSettingsDialog.cpp create mode 100644 src/frontend/qt_sdl/WifiSettingsDialog.h (limited to 'src') diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index 6b256e0..edc8d45 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -22,8 +22,8 @@ #include #include "Platform.h" #include "PlatformConfig.h" -//#include "LAN_Socket.h" -//#include "LAN_PCap.h" +#include "LAN_Socket.h" +#include "LAN_PCap.h" #include #ifdef __WIN32__ @@ -559,7 +559,7 @@ int MP_RecvPacket(u8* data, bool block) bool LAN_Init() { - /*if (Config::DirectLAN) + if (Config::DirectLAN) { if (!LAN_PCap::Init(true)) return false; @@ -568,7 +568,7 @@ bool LAN_Init() { if (!LAN_Socket::Init()) return false; - }*/ + } return true; } @@ -580,26 +580,24 @@ void LAN_DeInit() // LAN_PCap::DeInit(); //else // LAN_Socket::DeInit(); - /*LAN_PCap::DeInit(); - LAN_Socket::DeInit();*/ + LAN_PCap::DeInit(); + LAN_Socket::DeInit(); } int LAN_SendPacket(u8* data, int len) { - /*if (Config::DirectLAN) + if (Config::DirectLAN) return LAN_PCap::SendPacket(data, len); else - return LAN_Socket::SendPacket(data, len);*/ - return 0; + return LAN_Socket::SendPacket(data, len); } int LAN_RecvPacket(u8* data) { - /*if (Config::DirectLAN) + if (Config::DirectLAN) return LAN_PCap::RecvPacket(data); else - return LAN_Socket::RecvPacket(data);*/ - return 0; + return LAN_Socket::RecvPacket(data); } diff --git a/src/frontend/qt_sdl/WifiSettingsDialog.cpp b/src/frontend/qt_sdl/WifiSettingsDialog.cpp new file mode 100644 index 0000000..457a78d --- /dev/null +++ b/src/frontend/qt_sdl/WifiSettingsDialog.cpp @@ -0,0 +1,140 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include +#include + +#include "types.h" +#include "Platform.h" +#include "Config.h" +#include "PlatformConfig.h" + +#include "LAN_Socket.h" +#include "LAN_PCap.h" +#include "Wifi.h" + +#include "WifiSettingsDialog.h" +#include "ui_WifiSettingsDialog.h" + + +#ifdef __WIN32__ +#define PCAP_NAME "winpcap/npcap" +#else +#define PCAP_NAME "libpcap" +#endif + + +WifiSettingsDialog* WifiSettingsDialog::currentDlg = nullptr; + + +WifiSettingsDialog::WifiSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::WifiSettingsDialog) +{ + ui->setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + + LAN_Socket::Init(); + haspcap = LAN_PCap::Init(false); + + ui->cbDirectMode->setText("Direct mode (requires " PCAP_NAME " and ethernet connection)"); + + ui->cbBindAnyAddr->setChecked(Config::SocketBindAnyAddr != 0); + + int sel = 0; + for (int i = 0; i < LAN_PCap::NumAdapters; i++) + { + LAN_PCap::AdapterData* adapter = &LAN_PCap::Adapters[i]; + + ui->cbxDirectAdapter->addItem(QString(adapter->FriendlyName)); + + if (!strncmp(adapter->DeviceName, Config::LANDevice, 128)) + sel = i; + } + ui->cbxDirectAdapter->setCurrentIndex(sel); + + ui->cbDirectMode->setChecked(Config::DirectLAN != 0); + if (!haspcap) ui->cbDirectMode->setEnabled(false); + + updateAdapterControls(); +} + +WifiSettingsDialog::~WifiSettingsDialog() +{ + delete ui; +} + +void WifiSettingsDialog::on_WifiSettingsDialog_accepted() +{ + Config::SocketBindAnyAddr = ui->cbBindAnyAddr->isChecked() ? 1:0; + Config::DirectLAN = ui->cbDirectMode->isChecked() ? 1:0; + + int sel = ui->cbxDirectAdapter->currentIndex(); + if (sel < 0 || sel >= LAN_PCap::NumAdapters) sel = 0; + if (LAN_PCap::NumAdapters < 1) + { + Config::LANDevice[0] = '\0'; + } + else + { + strncpy(Config::LANDevice, LAN_PCap::Adapters[sel].DeviceName, 127); + Config::LANDevice[127] = '\0'; + } + + Config::Save(); + + closeDlg(); +} + +void WifiSettingsDialog::on_WifiSettingsDialog_rejected() +{ + closeDlg(); +} + +void WifiSettingsDialog::on_cbDirectMode_stateChanged(int state) +{ + updateAdapterControls(); +} + +void WifiSettingsDialog::on_cbxDirectAdapter_currentIndexChanged(int sel) +{ + if (!haspcap) return; + + if (sel < 0 || sel >= LAN_PCap::NumAdapters) return; + if (LAN_PCap::NumAdapters < 1) return; + + LAN_PCap::AdapterData* adapter = &LAN_PCap::Adapters[sel]; + char tmp[64]; + + sprintf(tmp, "MAC: %02X:%02X:%02X:%02X:%02X:%02X", + adapter->MAC[0], adapter->MAC[1], adapter->MAC[2], + adapter->MAC[3], adapter->MAC[4], adapter->MAC[5]); + ui->lblAdapterMAC->setText(QString(tmp)); + + sprintf(tmp, "IP: %d.%d.%d.%d", + adapter->IP_v4[0], adapter->IP_v4[1], + adapter->IP_v4[2], adapter->IP_v4[3]); + ui->lblAdapterIP->setText(QString(tmp)); +} + +void WifiSettingsDialog::updateAdapterControls() +{ + bool enable = haspcap && ui->cbDirectMode->isChecked(); + + ui->cbxDirectAdapter->setEnabled(enable); + ui->lblAdapterMAC->setEnabled(enable); + ui->lblAdapterIP->setEnabled(enable); +} diff --git a/src/frontend/qt_sdl/WifiSettingsDialog.h b/src/frontend/qt_sdl/WifiSettingsDialog.h new file mode 100644 index 0000000..f8aad1b --- /dev/null +++ b/src/frontend/qt_sdl/WifiSettingsDialog.h @@ -0,0 +1,68 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef WIFISETTINGSDIALOG_H +#define WIFISETTINGSDIALOG_H + +#include + +namespace Ui { class WifiSettingsDialog; } +class WifiSettingsDialog; + +class WifiSettingsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit WifiSettingsDialog(QWidget* parent); + ~WifiSettingsDialog(); + + static WifiSettingsDialog* currentDlg; + static WifiSettingsDialog* openDlg(QWidget* parent) + { + if (currentDlg) + { + currentDlg->activateWindow(); + return currentDlg; + } + + currentDlg = new WifiSettingsDialog(parent); + currentDlg->show(); + return currentDlg; + } + static void closeDlg() + { + currentDlg = nullptr; + } + +private slots: + void on_WifiSettingsDialog_accepted(); + void on_WifiSettingsDialog_rejected(); + + void on_cbDirectMode_stateChanged(int state); + void on_cbxDirectAdapter_currentIndexChanged(int sel); + +private: + Ui::WifiSettingsDialog* ui; + + bool haspcap; + + void updateAdapterControls(); +}; + +#endif // WIFISETTINGSDIALOG_H diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index e60a58d..5870d8a 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -1671,7 +1671,24 @@ void MainWindow::onAudioSettingsFinished(int res) void MainWindow::onOpenWifiSettings() { - WifiSettingsDialog::openDlg(this); + WifiSettingsDialog* dlg = WifiSettingsDialog::openDlg(this); + connect(dlg, &WifiSettingsDialog::finished, this, &MainWindow::onWifiSettingsFinished); +} + +void MainWindow::onWifiSettingsFinished(int res) +{ + emuThread->emuPause(); + + if (Wifi::MPInited) + { + Platform::MP_DeInit(); + Platform::MP_Init(); + } + + Platform::LAN_DeInit(); + Platform::LAN_Init(); + + emuThread->emuUnpause(); } void MainWindow::onChangeSavestateSRAMReloc(bool checked) diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index ef51158..279aed8 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -205,6 +205,7 @@ private slots: void onOpenAudioSettings(); void onAudioSettingsFinished(int res); void onOpenWifiSettings(); + void onWifiSettingsFinished(int res); void onChangeSavestateSRAMReloc(bool checked); void onChangeScreenSize(); void onChangeScreenRotation(QAction* act); -- cgit v1.2.3 From 935f121025d6736207adb7d17851fb54ea0f767d Mon Sep 17 00:00:00 2001 From: Arisotura Date: Fri, 29 May 2020 21:03:46 +0200 Subject: * add options for static linking * make the vsync checkbox and shit work to some extent (they don't actually function tho) --- CMakeLists.txt | 7 ++++++- src/frontend/qt_sdl/CMakeLists.txt | 28 +++++++++++++++++++++++----- src/frontend/qt_sdl/VideoSettingsDialog.cpp | 15 +++++++++++++++ src/frontend/qt_sdl/VideoSettingsDialog.h | 3 +++ 4 files changed, 47 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index e640a48..0309725 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) project(melonDS) -if(NOT CMAKE_BUILD_TYPE) +if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() @@ -20,6 +20,7 @@ endif() if (CMAKE_BUILD_TYPE STREQUAL Release) add_compile_options(-O3) + add_link_options(-s) endif() add_compile_options(-fno-pic) @@ -27,6 +28,10 @@ add_link_options(-no-pie) option(BUILD_QT_SDL "Build Qt/SDL frontend" ON) +if (WIN32) + option(BUILD_STATIC "Statically link dependencies" OFF) +endif() + add_subdirectory(src) if (BUILD_QT_SDL) diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index dbc1e3a..8992b50 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -30,9 +30,15 @@ if (WIN32) set(CMAKE_RC_COMPILE_OBJECT " -i -o ") endif() -find_package(Qt5 COMPONENTS Core REQUIRED) -find_package(Qt5 COMPONENTS Gui REQUIRED) -find_package(Qt5 COMPONENTS Widgets REQUIRED) +if (BUILD_STATIC AND QT5_STATIC_DIR) + set(QT5_STATIC_BASE ${QT5_STATIC_DIR}/lib/cmake/Qt5) + set(Qt5_DIR ${QT5_STATIC_BASE}) + set(Qt5Core_DIR ${QT5_STATIC_BASE}Core) + set(Qt5Gui_DIR ${QT5_STATIC_BASE}Gui) + set(Qt5Widgets_DIR ${QT5_STATIC_BASE}Widgets) +endif() + +find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) @@ -46,7 +52,13 @@ target_include_directories(melonDS PRIVATE ${SDL2_INCLUDE_DIRS}) target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..") target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../..") -target_link_libraries(melonDS core ${SDL2_LIBRARIES}) +target_link_libraries(melonDS core) + +if (BUILD_STATIC) + target_link_libraries(melonDS -static ${SDL2_LIBRARIES}) +else() + target_link_libraries(melonDS ${SDL2_LIBRARIES}) +endif() if (UNIX) option(UNIX_PORTABLE "Make a portable build that looks for its configuration in the current directory" OFF) @@ -77,7 +89,13 @@ if (UNIX) target_sources(melonDS PUBLIC melon_grc.c) elseif (WIN32) target_sources(melonDS PUBLIC "${CMAKE_SOURCE_DIR}/melon.rc") - target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32 Qt5::Core Qt5::Gui Qt5::Widgets) + + target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32) + if (BUILD_STATIC) + target_link_libraries(melonDS imm32 winmm version setupapi -static Qt5::Core Qt5::Gui Qt5::Widgets z zstd) + else() + target_link_libraries(melonDS Qt5::Core Qt5::Gui Qt5::Widgets) + endif() endif () install(FILES ../../../net.kuribo64.melonDS.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp index efb5051..ba433c3 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.cpp +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -60,6 +60,9 @@ VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui( ui->cbxGLResolution->addItem(QString("%1x native (%2x%3)").arg(i).arg(256*i).arg(192*i)); ui->cbxGLResolution->setCurrentIndex(Config::GL_ScaleFactor-1); + if (!Config::ScreenVSync) + ui->sbVSyncInterval->setEnabled(false); + if (Config::_3DRenderer == 0) { ui->cbGLDisplay->setEnabled(true); @@ -136,6 +139,18 @@ void VideoSettingsDialog::on_cbGLDisplay_stateChanged(int state) emit updateVideoSettings(old_gl != new_gl); } +void VideoSettingsDialog::on_cbVSync_stateChanged(int state) +{ + bool vsync = (state != 0); + ui->sbVSyncInterval->setEnabled(vsync); + Config::ScreenVSync = vsync; +} + +void VideoSettingsDialog::on_sbVSyncInterval_valueChanged(int val) +{ + Config::ScreenVSyncInterval = val; +} + void VideoSettingsDialog::on_cbSoftwareThreaded_stateChanged(int state) { Config::Threaded3D = (state != 0); diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.h b/src/frontend/qt_sdl/VideoSettingsDialog.h index 2f6d17c..2311d4d 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.h +++ b/src/frontend/qt_sdl/VideoSettingsDialog.h @@ -60,6 +60,9 @@ private slots: void onChange3DRenderer(int renderer); void on_cbGLDisplay_stateChanged(int state); + void on_cbVSync_stateChanged(int state); + void on_sbVSyncInterval_valueChanged(int val); + void on_cbxGLResolution_currentIndexChanged(int idx); void on_cbSoftwareThreaded_stateChanged(int state); -- cgit v1.2.3 From d3dd7bd9880bfd6a5b65f263272742105620ccb3 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Fri, 29 May 2020 21:19:18 +0200 Subject: get rid of console in release builds --- src/frontend/qt_sdl/CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index 8992b50..37a8ff1 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -47,7 +47,12 @@ set(CMAKE_AUTORCC ON) find_package(PkgConfig REQUIRED) pkg_check_modules(SDL2 REQUIRED sdl2) -add_executable(melonDS ${SOURCES_QT_SDL}) +if (WIN32 AND (CMAKE_BUILD_TYPE STREQUAL Release)) + add_executable(melonDS WIN32 ${SOURCES_QT_SDL}) +else() + add_executable(melonDS ${SOURCES_QT_SDL}) +endif() + target_include_directories(melonDS PRIVATE ${SDL2_INCLUDE_DIRS}) target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..") -- cgit v1.2.3 From 9557e18b7cd559679552535e4362115b6d249ab3 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Fri, 29 May 2020 21:27:40 +0200 Subject: fart around --- src/frontend/qt_sdl/main.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 5870d8a..2aaac96 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -273,6 +273,8 @@ void EmuThread::initOpenGL() QOpenGLContext* windowctx = mainWindow->getOGLContext(); QSurfaceFormat format = windowctx->format(); + format.setSwapInterval(0); + oglSurface = new QOffscreenSurface(); oglSurface->setFormat(format); oglSurface->create(); @@ -791,14 +793,9 @@ void ScreenPanelNative::onScreenLayoutChanged() ScreenPanelGL::ScreenPanelGL(QWidget* parent) : QOpenGLWidget(parent) { - QSurfaceFormat format; - format.setDepthBufferSize(24); - format.setStencilBufferSize(8); - format.setVersion(3, 2); - format.setProfile(QSurfaceFormat::CoreProfile); - setFormat(format); - touching = false; + + curVSync = -1; } ScreenPanelGL::~ScreenPanelGL() -- cgit v1.2.3 From 8ddd82ca2c7c8844a1d3c2cc7418d03976c9c52e Mon Sep 17 00:00:00 2001 From: Arisotura Date: Fri, 29 May 2020 21:35:06 +0200 Subject: I'm a derp --- src/frontend/qt_sdl/main.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 2aaac96..68a32c8 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -795,7 +795,6 @@ ScreenPanelGL::ScreenPanelGL(QWidget* parent) : QOpenGLWidget(parent) { touching = false; - curVSync = -1; } ScreenPanelGL::~ScreenPanelGL() -- cgit v1.2.3 From 88823f66cb7f053e1d0f22d2eb0510ab32d8e474 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Fri, 29 May 2020 22:18:21 +0200 Subject: * fix the OpenGL shito under Linux * make the 'BIOS not found' errors a bit more user-friendly --- src/OpenGLSupport.h | 14 +++++++++++++- src/frontend/qt_sdl/main.cpp | 6 +++--- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/OpenGLSupport.h b/src/OpenGLSupport.h index edf7eda..925c0ad 100644 --- a/src/OpenGLSupport.h +++ b/src/OpenGLSupport.h @@ -49,9 +49,21 @@ // if you need more OpenGL functions, add them to the macronator here -#define DO_PROCLIST(func) \ +#ifdef __WIN32__ + +#define DO_PROCLIST_1_3(func) \ func(GLACTIVETEXTURE, glActiveTexture); \ func(GLBLENDCOLOR, glBlendColor); \ + +#else + +#define DO_PROCLIST_1_3(func) + +#endif + + +#define DO_PROCLIST(func) \ + DO_PROCLIST_1_3(func) \ \ func(GLGENFRAMEBUFFERS, glGenFramebuffers); \ func(GLDELETEFRAMEBUFFERS, glDeleteFramebuffers); \ diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 68a32c8..8df6ec8 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -1360,13 +1360,13 @@ QString MainWindow::loadErrorStr(int error) { switch (error) { - case Frontend::Load_BIOS9Missing: return "DS ARM9 BIOS was not found or could not be accessed."; + case Frontend::Load_BIOS9Missing: return "DS ARM9 BIOS was not found or could not be accessed. Check your emu settings."; case Frontend::Load_BIOS9Bad: return "DS ARM9 BIOS is not a valid BIOS dump."; - case Frontend::Load_BIOS7Missing: return "DS ARM7 BIOS was not found or could not be accessed."; + case Frontend::Load_BIOS7Missing: return "DS ARM7 BIOS was not found or could not be accessed. Check your emu settings."; case Frontend::Load_BIOS7Bad: return "DS ARM7 BIOS is not a valid BIOS dump."; - case Frontend::Load_FirmwareMissing: return "DS firmware was not found or could not be accessed."; + case Frontend::Load_FirmwareMissing: return "DS firmware was not found or could not be accessed. Check your emu settings."; case Frontend::Load_FirmwareBad: return "DS firmware is not a valid firmware dump."; case Frontend::Load_FirmwareNotBootable: return "DS firmware is not bootable."; -- cgit v1.2.3 From c45068da0eb4dc5ce25524cc0b0a12cd78ed036a Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 30 May 2020 00:28:21 +0200 Subject: embed romlist.bin --- CMakeLists.txt | 4 - romlist.bin | Bin 108384 -> 0 bytes src/CMakeLists.txt | 1 + src/NDSCart.cpp | 51 +- src/ROMList.h | 6809 ++++++++++++++++++++++++++++++++++++++++++ src/frontend/qt_sdl/main.cpp | 33 - 6 files changed, 6829 insertions(+), 69 deletions(-) delete mode 100644 romlist.bin create mode 100644 src/ROMList.h (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index 0309725..885f0dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,3 @@ add_subdirectory(src) if (BUILD_QT_SDL) add_subdirectory(src/frontend/qt_sdl) endif() - -configure_file( - ${CMAKE_SOURCE_DIR}/romlist.bin - ${CMAKE_BINARY_DIR}/romlist.bin COPYONLY) diff --git a/romlist.bin b/romlist.bin deleted file mode 100644 index 537439e..0000000 Binary files a/romlist.bin and /dev/null differ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 56bb3cb..3dc4243 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,6 +27,7 @@ add_library(core STATIC NDSCart.cpp OpenGLSupport.cpp Platform.h + ROMList.h RTC.cpp Savestate.cpp SPI.cpp diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index 8ced842..a8c6549 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -23,6 +23,7 @@ #include "ARM.h" #include "CRC32.h" #include "Platform.h" +#include "ROMList.h" namespace NDSCart_SRAM @@ -808,34 +809,21 @@ void ApplyDLDIPatch() } -bool ReadROMParams(u32 gamecode, u32* params) +bool ReadROMParams(u32 gamecode, ROMListEntry* params) { - // format for romlist.bin: - // [gamecode] [ROM size] [save type] [reserved] - // list must be sorted by gamecode - - FILE* f = Platform::OpenDataFile("romlist.bin"); - if (!f) return false; - - fseek(f, 0, SEEK_END); - u32 len = (u32)ftell(f); - u32 maxlen = len; - len >>= 4; // 16 bytes per entry + u32 len = sizeof(ROMList) / sizeof(ROMListEntry); u32 offset = 0; u32 chk_size = len >> 1; for (;;) { u32 key = 0; - fseek(f, offset + (chk_size << 4), SEEK_SET); - fread(&key, 4, 1, f); - - printf("chk_size=%d, key=%08X, wanted=%08X, offset=%08X\n", chk_size, key, gamecode, offset); + ROMListEntry* curentry = &ROMList[offset + chk_size]; + key = curentry->GameCode; if (key == gamecode) { - fread(params, 4, 3, f); - fclose(f); + memcpy(params, curentry, sizeof(ROMListEntry)); return true; } else @@ -843,22 +831,20 @@ bool ReadROMParams(u32 gamecode, u32* params) if (key < gamecode) { if (chk_size == 0) - offset += 0x10; + offset++; else - offset += (chk_size << 4); + offset += chk_size; } else if (chk_size == 0) { - fclose(f); return false; } chk_size >>= 1; } - if (offset >= maxlen) + if (offset >= len) { - fclose(f); return false; } } @@ -936,22 +922,23 @@ bool LoadROM(const char* path, const char* sram, bool direct) CartCRC = CRC32(CartROM, CartROMSize); printf("ROM CRC32: %08X\n", CartCRC); - u32 romparams[3]; - if (!ReadROMParams(gamecode, romparams)) + ROMListEntry romparams; + if (!ReadROMParams(gamecode, &romparams)) { // set defaults printf("ROM entry not found\n"); - romparams[0] = CartROMSize; + romparams.GameCode = gamecode; + romparams.ROMSize = CartROMSize; if (*(u32*)&CartROM[0x20] < 0x4000) - romparams[1] = 0; // no saveRAM for homebrew + romparams.SaveMemType = 0; // no saveRAM for homebrew else - romparams[1] = 2; // assume EEPROM 64k (TODO FIXME) + romparams.SaveMemType = 2; // assume EEPROM 64k (TODO FIXME) } else - printf("ROM entry: %08X %08X %08X\n", romparams[0], romparams[1], romparams[2]); + printf("ROM entry: %08X %08X\n", romparams.ROMSize, romparams.SaveMemType); - if (romparams[0] != len) printf("!! bad ROM size %d (expected %d) rounded to %d\n", len, romparams[0], CartROMSize); + if (romparams.ROMSize != len) printf("!! bad ROM size %d (expected %d) rounded to %d\n", len, romparams.ROMSize, CartROMSize); // generate a ROM ID // note: most games don't check the actual value @@ -963,7 +950,7 @@ bool LoadROM(const char* path, const char* sram, bool direct) else CartID |= (0x100 - (CartROMSize >> 28)) << 8; - if (romparams[1] == 8) + if (romparams.SaveMemType == 8) CartID |= 0x08000000; // NAND flag printf("Cart ID: %08X\n", CartID); @@ -1018,7 +1005,7 @@ bool LoadROM(const char* path, const char* sram, bool direct) // save printf("Save file: %s\n", sram); - NDSCart_SRAM::LoadSave(sram, romparams[1]); + NDSCart_SRAM::LoadSave(sram, romparams.SaveMemType); return true; } diff --git a/src/ROMList.h b/src/ROMList.h new file mode 100644 index 0000000..ead3ee4 --- /dev/null +++ b/src/ROMList.h @@ -0,0 +1,6809 @@ +/* + Copyright 2016-2020 Arisotura + + This file is part of melonDS. + + melonDS 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 3 of the License, or (at your option) + any later version. + + melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef ROMLIST_H +#define ROMLIST_H + +typedef struct +{ + u32 GameCode; + u32 ROMSize; + u32 SaveMemType; + +} ROMListEntry; + + +ROMListEntry ROMList[] = +{ + {0x41464141, 0x00800000, 0x00000004}, + {0x414D4155, 0x00800000, 0x00000008}, + {0x43363341, 0x02000000, 0x00000008}, + {0x43443241, 0x02000000, 0x00000002}, + {0x43495941, 0x01000000, 0x00000001}, + {0x434D5341, 0x01000000, 0x00000002}, + {0x434E5341, 0x00800000, 0x00000002}, + {0x43575A41, 0x02000000, 0x00000002}, + {0x44323643, 0x04000000, 0x00000001}, + {0x44324254, 0x04000000, 0x00000002}, + {0x44324C43, 0x00800000, 0x00000001}, + {0x44325542, 0x01000000, 0x00000002}, + {0x44325942, 0x00800000, 0x00000001}, + {0x44334444, 0x02000000, 0x00000001}, + {0x44334542, 0x04000000, 0x00000001}, + {0x44334754, 0x00800000, 0x00000002}, + {0x44334756, 0x02000000, 0x00000002}, + {0x44335141, 0x04000000, 0x00000002}, + {0x44335159, 0x04000000, 0x00000002}, + {0x44335254, 0x02000000, 0x00000001}, + {0x44335742, 0x08000000, 0x00000002}, + {0x44335942, 0x00800000, 0x00000001}, + {0x44343642, 0x00800000, 0x00000001}, + {0x44344259, 0x02000000, 0x00000001}, + {0x44344443, 0x00800000, 0x00000001}, + {0x44345254, 0x02000000, 0x00000001}, + {0x44345542, 0x00800000, 0x00000002}, + {0x44345942, 0x00800000, 0x00000001}, + {0x44353243, 0x02000000, 0x00000002}, + {0x44353642, 0x00800000, 0x00000001}, + {0x44353842, 0x01000000, 0x00000001}, + {0x44354259, 0x02000000, 0x00000002}, + {0x44354442, 0x01000000, 0x00000002}, + {0x44354659, 0x01000000, 0x00000001}, + {0x44354841, 0x02000000, 0x00000002}, + {0x44354C42, 0x01000000, 0x00000002}, + {0x44354C43, 0x00000000, 0x00000001}, + {0x44355342, 0x01000000, 0x00000001}, + {0x44355542, 0x02000000, 0x00000002}, + {0x44355942, 0x00800000, 0x00000001}, + {0x44363243, 0x01000000, 0x00000002}, + {0x44364142, 0x02000000, 0x00000002}, + {0x44364341, 0x01000000, 0x00000002}, + {0x44364843, 0x04000000, 0x00000001}, + {0x44364B43, 0x02000000, 0x00000002}, + {0x44364C42, 0x01000000, 0x00000002}, + {0x44365542, 0x01000000, 0x00000002}, + {0x44374543, 0x02000000, 0x00000002}, + {0x44374959, 0x04000000, 0x00000002}, + {0x44375359, 0x02000000, 0x00000001}, + {0x44384243, 0x02000000, 0x00000001}, + {0x44384A59, 0x01000000, 0x00000002}, + {0x44384F42, 0x01000000, 0x00000001}, + {0x44394259, 0x02000000, 0x00000003}, + {0x44394341, 0x04000000, 0x00000001}, + {0x44394543, 0x01000000, 0x00000003}, + {0x44414441, 0x04000000, 0x00000006}, + {0x44414A42, 0x01000000, 0x00000003}, + {0x44414C59, 0x00800000, 0x00000002}, + {0x44414D56, 0x02000000, 0x00000001}, + {0x44414E43, 0x04000000, 0x00000001}, + {0x44415041, 0x04000000, 0x00000006}, + {0x44415249, 0x10000000, 0x00000006}, + {0x44423542, 0x04000000, 0x00000002}, + {0x44424242, 0x00000000, 0x00000001}, + {0x44424354, 0x08000000, 0x00000001}, + {0x44424542, 0x10000000, 0x00000003}, + {0x44424A42, 0x04000000, 0x00000001}, + {0x44424B42, 0x01000000, 0x00000001}, + {0x44424C54, 0x02000000, 0x00000001}, + {0x44425249, 0x10000000, 0x00000006}, + {0x44425642, 0x02000000, 0x00000002}, + {0x44434343, 0x02000000, 0x00000002}, + {0x44434643, 0x02000000, 0x00000002}, + {0x44434842, 0x01000000, 0x00000001}, + {0x44434A42, 0x04000000, 0x00000002}, + {0x44434C54, 0x01000000, 0x00000001}, + {0x44435159, 0x01000000, 0x00000001}, + {0x44435342, 0x08000000, 0x00000002}, + {0x44435359, 0x01000000, 0x00000001}, + {0x44435559, 0x04000000, 0x00000002}, + {0x44435943, 0x02000000, 0x00000002}, + {0x44444254, 0x04000000, 0x00000002}, + {0x44444842, 0x04000000, 0x00000001}, + {0x44444856, 0x02000000, 0x00000002}, + {0x44445054, 0x08000000, 0x00000001}, + {0x44445249, 0x20000000, 0x00000006}, + {0x44445443, 0x00000000, 0x00000002}, + {0x44445459, 0x02000000, 0x00000002}, + {0x44445641, 0x01000000, 0x00000002}, + {0x44454242, 0x01000000, 0x00000001}, + {0x44454542, 0x10000000, 0x00000003}, + {0x44454559, 0x10000000, 0x00000003}, + {0x44454756, 0x02000000, 0x00000002}, + {0x44454842, 0x02000000, 0x00000002}, + {0x44454D54, 0x00800000, 0x00000002}, + {0x44454E42, 0x02000000, 0x00000001}, + {0x44454E59, 0x02000000, 0x00000002}, + {0x44455143, 0x04000000, 0x00000002}, + {0x44455249, 0x20000000, 0x00000006}, + {0x44455342, 0x01000000, 0x00000001}, + {0x44455642, 0x00800000, 0x00000002}, + {0x44464242, 0x02000000, 0x00000001}, + {0x44464B42, 0x04000000, 0x00000002}, + {0x44464B59, 0x02000000, 0x00000001}, + {0x44464C42, 0x10000000, 0x00000003}, + {0x44465343, 0x00800000, 0x00000001}, + {0x44465359, 0x04000000, 0x00000001}, + {0x44465442, 0x01000000, 0x00000002}, + {0x44473242, 0x04000000, 0x00000001}, + {0x44474B42, 0x00800000, 0x00000002}, + {0x44474C43, 0x04000000, 0x00000001}, + {0x44474D41, 0x01000000, 0x00000001}, + {0x44474D43, 0x04000000, 0x00000001}, + {0x44475049, 0x08000000, 0x00000006}, + {0x44475759, 0x01000000, 0x00000001}, + {0x44483842, 0x04000000, 0x00000002}, + {0x44485142, 0x00800000, 0x00000002}, + {0x44485442, 0x01000000, 0x00000002}, + {0x44493643, 0x00800000, 0x00000001}, + {0x44494243, 0x02000000, 0x00000001}, + {0x44494442, 0x04000000, 0x00000001}, + {0x44494C43, 0x04000000, 0x00000001}, + {0x44495443, 0x00000000, 0x00000002}, + {0x44495742, 0x01000000, 0x00000002}, + {0x444A3343, 0x10000000, 0x00000003}, + {0x444A3443, 0x00800000, 0x00000001}, + {0x444A4542, 0x04000000, 0x00000001}, + {0x444A4742, 0x02000000, 0x00000002}, + {0x444A4F42, 0x04000000, 0x00000002}, + {0x444A5543, 0x00000000, 0x00000002}, + {0x444A5641, 0x04000000, 0x00000002}, + {0x444B3842, 0x02000000, 0x00000002}, + {0x444B4159, 0x08000000, 0x00000002}, + {0x444B4356, 0x08000000, 0x00000002}, + {0x444B4C42, 0x04000000, 0x00000001}, + {0x444B5049, 0x08000000, 0x00000006}, + {0x444C3643, 0x01000000, 0x00000001}, + {0x444C4254, 0x00800000, 0x00000001}, + {0x444C4842, 0x04000000, 0x00000002}, + {0x444C5059, 0x00800000, 0x00000001}, + {0x444C5941, 0x01000000, 0x00000002}, + {0x444D3442, 0x02000000, 0x00000001}, + {0x444D4359, 0x02000000, 0x00000001}, + {0x444D4C54, 0x08000000, 0x00000001}, + {0x444D5642, 0x02000000, 0x00000001}, + {0x444E4242, 0x00800000, 0x00000002}, + {0x444E4259, 0x04000000, 0x00000007}, + {0x444E4641, 0x02000000, 0x00000002}, + {0x444E4C54, 0x00800000, 0x00000002}, + {0x444E4D42, 0x01000000, 0x00000001}, + {0x444F4142, 0x04000000, 0x00000001}, + {0x444F4359, 0x04000000, 0x00000001}, + {0x444F4543, 0x02000000, 0x00000002}, + {0x444F4642, 0x00800000, 0x00000001}, + {0x444F4656, 0x02000000, 0x00000002}, + {0x444F5056, 0x02000000, 0x00000002}, + {0x444F5143, 0x02000000, 0x00000001}, + {0x44504C43, 0x04000000, 0x00000003}, + {0x44505041, 0x01000000, 0x00000002}, + {0x44505342, 0x01000000, 0x00000002}, + {0x44505542, 0x01000000, 0x00000001}, + {0x44505A55, 0x08000000, 0x00000003}, + {0x44513343, 0x04000000, 0x00000002}, + {0x44513443, 0x04000000, 0x00000002}, + {0x44513743, 0x02000000, 0x00000002}, + {0x44514543, 0x04000000, 0x00000002}, + {0x44514A59, 0x01000000, 0x00000001}, + {0x44514C54, 0x00800000, 0x00000002}, + {0x44515142, 0x01000000, 0x00000002}, + {0x44515543, 0x04000000, 0x00000002}, + {0x44515642, 0x02000000, 0x00000002}, + {0x44524642, 0x08000000, 0x00000002}, + {0x44524842, 0x02000000, 0x00000001}, + {0x44525359, 0x00000000, 0x00000005}, + {0x44525642, 0x04000000, 0x00000001}, + {0x44533341, 0x02000000, 0x00000001}, + {0x44534F41, 0x08000000, 0x00000005}, + {0x44535143, 0x02000000, 0x00000001}, + {0x44535342, 0x01000000, 0x00000002}, + {0x44535541, 0x04000000, 0x00000001}, + {0x44535642, 0x02000000, 0x00000002}, + {0x44544442, 0x00800000, 0x00000001}, + {0x44544C59, 0x08000000, 0x00000002}, + {0x44545659, 0x02000000, 0x00000001}, + {0x44545759, 0x01000000, 0x00000001}, + {0x44553243, 0x04000000, 0x00000002}, + {0x44553642, 0x00800000, 0x00000001}, + {0x44554254, 0x02000000, 0x00000001}, + {0x44554259, 0x08000000, 0x00000003}, + {0x44554959, 0x04000000, 0x00000001}, + {0x44554D59, 0x04000000, 0x00000002}, + {0x44555043, 0x08000000, 0x00000006}, + {0x44563442, 0x02000000, 0x00000001}, + {0x44564159, 0x04000000, 0x00000002}, + {0x44564643, 0x02000000, 0x00000002}, + {0x44564859, 0x04000000, 0x00000001}, + {0x44564A59, 0x01000000, 0x00000002}, + {0x44564B43, 0x01000000, 0x00000002}, + {0x44564C42, 0x01000000, 0x00000001}, + {0x44564E43, 0x10000000, 0x00000005}, + {0x44565042, 0x00800000, 0x00000002}, + {0x44565841, 0x04000000, 0x00000003}, + {0x44573742, 0x01000000, 0x00000002}, + {0x44574242, 0x01000000, 0x00000002}, + {0x44574642, 0x00800000, 0x00000001}, + {0x44574943, 0x08000000, 0x00000002}, + {0x44574C41, 0x02000000, 0x00000001}, + {0x44574C42, 0x02000000, 0x00000001}, + {0x44575343, 0x04000000, 0x00000001}, + {0x44584D59, 0x00800000, 0x00000001}, + {0x44593443, 0x00000000, 0x00000001}, + {0x44593642, 0x02000000, 0x00000002}, + {0x44594159, 0x02000000, 0x00000001}, + {0x44594442, 0x04000000, 0x00000002}, + {0x44594641, 0x04000000, 0x00000001}, + {0x44594842, 0x01000000, 0x00000001}, + {0x44594A42, 0x04000000, 0x00000001}, + {0x44594A43, 0x04000000, 0x00000001}, + {0x44594A59, 0x00800000, 0x00000001}, + {0x44594C41, 0x04000000, 0x00000001}, + {0x44594D42, 0x01000000, 0x00000002}, + {0x44595143, 0x01000000, 0x00000001}, + {0x445A3643, 0x01000000, 0x00000001}, + {0x445A3659, 0x08000000, 0x00000000}, + {0x445A4341, 0x01000000, 0x00000001}, + {0x445A4641, 0x04000000, 0x00000001}, + {0x445A5054, 0x04000000, 0x00000002}, + {0x445A5142, 0x00000000, 0x00000002}, + {0x445A5359, 0x08000000, 0x00000001}, + {0x445A5442, 0x02000000, 0x00000001}, + {0x445A5443, 0x02000000, 0x00000003}, + {0x445A5942, 0x02000000, 0x00000002}, + {0x45323241, 0x01000000, 0x00000002}, + {0x45323341, 0x04000000, 0x00000008}, + {0x45323343, 0x04000000, 0x00000003}, + {0x45323542, 0x01000000, 0x00000001}, + {0x45323559, 0x08000000, 0x00000008}, + {0x45323643, 0x04000000, 0x00000001}, + {0x45323741, 0x01000000, 0x00000000}, + {0x45323859, 0x00800000, 0x00000000}, + {0x45324142, 0x04000000, 0x00000001}, + {0x45324143, 0x08000000, 0x00000003}, + {0x45324241, 0x02000000, 0x00000002}, + {0x45324242, 0x04000000, 0x00000002}, + {0x45324259, 0x02000000, 0x00000002}, + {0x45324341, 0x04000000, 0x00000001}, + {0x45324343, 0x01000000, 0x00000001}, + {0x45324354, 0x00800000, 0x00000001}, + {0x45324356, 0x02000000, 0x00000001}, + {0x45324359, 0x04000000, 0x00000006}, + {0x45324441, 0x02000000, 0x00000005}, + {0x45324442, 0x01000000, 0x00000002}, + {0x45324456, 0x04000000, 0x00000001}, + {0x45324459, 0x01000000, 0x00000003}, + {0x45324542, 0x00800000, 0x00000003}, + {0x45324643, 0x01000000, 0x00000001}, + {0x45324654, 0x04000000, 0x00000000}, + {0x45324741, 0x04000000, 0x00000001}, + {0x45324759, 0x01000000, 0x00000001}, + {0x45324842, 0x02000000, 0x00000003}, + {0x45324854, 0x01000000, 0x00000001}, + {0x45324859, 0x02000000, 0x00000003}, + {0x45324941, 0x04000000, 0x00000002}, + {0x45324A42, 0x04000000, 0x00000001}, + {0x45324A59, 0x02000000, 0x00000002}, + {0x45324B41, 0x02000000, 0x00000001}, + {0x45324C41, 0x04000000, 0x00000002}, + {0x45324C59, 0x08000000, 0x00000003}, + {0x45324D56, 0x04000000, 0x00000002}, + {0x45324D59, 0x01000000, 0x00000001}, + {0x45325041, 0x02000000, 0x00000001}, + {0x45325042, 0x02000000, 0x00000001}, + {0x45325043, 0x04000000, 0x00000003}, + {0x45325059, 0x04000000, 0x00000005}, + {0x45325141, 0x02000000, 0x00000002}, + {0x45325242, 0x02000000, 0x00000001}, + {0x45325254, 0x02000000, 0x00000002}, + {0x45325341, 0x01000000, 0x00000001}, + {0x45325342, 0x02000000, 0x00000005}, + {0x45325343, 0x00800000, 0x00000001}, + {0x45325359, 0x04000000, 0x00000005}, + {0x45325442, 0x04000000, 0x00000003}, + {0x45325459, 0x00800000, 0x00000001}, + {0x45325642, 0x02000000, 0x00000001}, + {0x45325741, 0x02000000, 0x00000003}, + {0x45325742, 0x01000000, 0x00000002}, + {0x45325759, 0x04000000, 0x00000005}, + {0x45325841, 0x00800000, 0x00000001}, + {0x45325A43, 0x01000000, 0x00000003}, + {0x45333241, 0x01000000, 0x00000008}, + {0x45333259, 0x04000000, 0x00000008}, + {0x45333441, 0x00800000, 0x00000008}, + {0x45333641, 0x02000000, 0x00000008}, + {0x45333759, 0x08000000, 0x00000008}, + {0x45333842, 0x08000000, 0x00000001}, + {0x45333859, 0x00800000, 0x00000000}, + {0x45334159, 0x00800000, 0x00000001}, + {0x45334241, 0x04000000, 0x00000003}, + {0x45334242, 0x08000000, 0x00000001}, + {0x45334259, 0x04000000, 0x00000005}, + {0x45334341, 0x04000000, 0x00000005}, + {0x45334441, 0x02000000, 0x00000005}, + {0x45334442, 0x04000000, 0x00000001}, + {0x45334443, 0x04000000, 0x00000001}, + {0x45334541, 0x04000000, 0x00000001}, + {0x45334641, 0x00800000, 0x00000001}, + {0x45334643, 0x00800000, 0x00000001}, + {0x45334659, 0x02000000, 0x00000002}, + {0x45334741, 0x02000000, 0x00000005}, + {0x45334743, 0x02000000, 0x00000002}, + {0x45334759, 0x02000000, 0x00000003}, + {0x45334841, 0x04000000, 0x00000003}, + {0x45334943, 0x04000000, 0x00000001}, + {0x45334959, 0x04000000, 0x00000002}, + {0x45334A42, 0x04000000, 0x00000005}, + {0x45334A43, 0x00800000, 0x00000001}, + {0x45334A56, 0x02000000, 0x00000001}, + {0x45334B41, 0x02000000, 0x00000002}, + {0x45334C41, 0x02000000, 0x00000001}, + {0x45334C59, 0x04000000, 0x00000002}, + {0x45334D43, 0x08000000, 0x00000003}, + {0x45334D54, 0x02000000, 0x00000001}, + {0x45334F41, 0x02000000, 0x00000001}, + {0x45335043, 0x08000000, 0x00000005}, + {0x45335141, 0x04000000, 0x00000002}, + {0x45335159, 0x04000000, 0x00000002}, + {0x45335341, 0x02000000, 0x00000001}, + {0x45335342, 0x01000000, 0x00000001}, + {0x45335343, 0x04000000, 0x00000003}, + {0x45335356, 0x08000000, 0x00000005}, + {0x45335359, 0x00800000, 0x00000001}, + {0x45335456, 0x04000000, 0x00000002}, + {0x45335459, 0x04000000, 0x00000003}, + {0x45335541, 0x02000000, 0x00000002}, + {0x45335543, 0x02000000, 0x00000001}, + {0x45335741, 0x04000000, 0x00000001}, + {0x45335743, 0x08000000, 0x00000002}, + {0x45335759, 0x01000000, 0x00000001}, + {0x45343243, 0x08000000, 0x00000003}, + {0x45343459, 0x00800000, 0x00000000}, + {0x45343543, 0x02000000, 0x00000003}, + {0x45343559, 0x01000000, 0x00000000}, + {0x45343842, 0x02000000, 0x00000001}, + {0x45344241, 0x04000000, 0x00000005}, + {0x45344259, 0x02000000, 0x00000001}, + {0x45344341, 0x04000000, 0x00000001}, + {0x45344441, 0x02000000, 0x00000005}, + {0x45344643, 0x00800000, 0x00000001}, + {0x45344659, 0x08000000, 0x00000003}, + {0x45344759, 0x10000000, 0x00000003}, + {0x45344842, 0x00800000, 0x00000001}, + {0x45344843, 0x04000000, 0x00000002}, + {0x45344943, 0x04000000, 0x00000002}, + {0x45344A42, 0x00800000, 0x00000001}, + {0x45344A43, 0x01000000, 0x00000001}, + {0x45344A56, 0x02000000, 0x00000001}, + {0x45344C41, 0x00800000, 0x00000001}, + {0x45344D41, 0x00800000, 0x00000000}, + {0x45344D43, 0x01000000, 0x00000003}, + {0x45344D56, 0x02000000, 0x00000002}, + {0x45344E41, 0x04000000, 0x00000001}, + {0x45345059, 0x04000000, 0x00000002}, + {0x45345141, 0x02000000, 0x00000001}, + {0x45345341, 0x02000000, 0x00000003}, + {0x45345342, 0x01000000, 0x00000001}, + {0x45345456, 0x04000000, 0x00000003}, + {0x45345459, 0x02000000, 0x00000001}, + {0x45345642, 0x01000000, 0x00000001}, + {0x45345643, 0x04000000, 0x00000001}, + {0x45345659, 0x08000000, 0x00000003}, + {0x45345741, 0x02000000, 0x00000002}, + {0x45345742, 0x02000000, 0x00000002}, + {0x45345759, 0x04000000, 0x00000003}, + {0x45345A43, 0x04000000, 0x00000001}, + {0x45353541, 0x01000000, 0x00000008}, + {0x45353542, 0x00800000, 0x00000001}, + {0x45353841, 0x02000000, 0x00000008}, + {0x45353941, 0x04000000, 0x00000008}, + {0x45354143, 0x08000000, 0x00000003}, + {0x45354259, 0x02000000, 0x00000002}, + {0x45354359, 0x00800000, 0x00000008}, + {0x45354441, 0x02000000, 0x00000005}, + {0x45354443, 0x02000000, 0x00000001}, + {0x45354643, 0x00800000, 0x00000002}, + {0x45354741, 0x01000000, 0x00000001}, + {0x45354743, 0x04000000, 0x00000001}, + {0x45354841, 0x02000000, 0x00000002}, + {0x45354943, 0x01000000, 0x00000001}, + {0x45354959, 0x04000000, 0x00000002}, + {0x45354B41, 0x02000000, 0x00000001}, + {0x45354B43, 0x04000000, 0x00000005}, + {0x45354C41, 0x04000000, 0x00000001}, + {0x45354D43, 0x04000000, 0x00000001}, + {0x45354E59, 0x04000000, 0x00000002}, + {0x45354F42, 0x10000000, 0x00000005}, + {0x45355043, 0x02000000, 0x00000001}, + {0x45355059, 0x01000000, 0x00000001}, + {0x45355141, 0x00800000, 0x00000001}, + {0x45355241, 0x02000000, 0x00000001}, + {0x45355243, 0x08000000, 0x00000001}, + {0x45355259, 0x02000000, 0x00000002}, + {0x45355341, 0x01000000, 0x00000001}, + {0x45355342, 0x01000000, 0x00000001}, + {0x45355343, 0x04000000, 0x00000001}, + {0x45355356, 0x02000000, 0x00000002}, + {0x45355359, 0x04000000, 0x00000001}, + {0x45355541, 0x00800000, 0x00000001}, + {0x45355643, 0x02000000, 0x00000001}, + {0x45355659, 0x08000000, 0x00000003}, + {0x45355843, 0x01000000, 0x00000001}, + {0x45355941, 0x08000000, 0x00000003}, + {0x45363241, 0x02000000, 0x00000008}, + {0x45363341, 0x02000000, 0x00000008}, + {0x45363359, 0x01000000, 0x00000008}, + {0x45363442, 0x01000000, 0x00000001}, + {0x45363543, 0x02000000, 0x00000002}, + {0x45363559, 0x04000000, 0x00000008}, + {0x45363642, 0x01000000, 0x00000001}, + {0x45363741, 0x04000000, 0x00000008}, + {0x45363742, 0x02000000, 0x00000001}, + {0x45363842, 0x00800000, 0x00000001}, + {0x45364241, 0x02000000, 0x00000001}, + {0x45364243, 0x02000000, 0x00000002}, + {0x45364254, 0x02000000, 0x00000001}, + {0x45364341, 0x01000000, 0x00000002}, + {0x45364356, 0x02000000, 0x00000002}, + {0x45364542, 0x02000000, 0x00000002}, + {0x45364641, 0x02000000, 0x00000002}, + {0x45364643, 0x04000000, 0x00000002}, + {0x45364742, 0x02000000, 0x00000002}, + {0x45364743, 0x08000000, 0x00000002}, + {0x45364759, 0x04000000, 0x00000002}, + {0x45364841, 0x01000000, 0x00000001}, + {0x45364843, 0x04000000, 0x00000001}, + {0x45364A56, 0x02000000, 0x00000001}, + {0x45364B41, 0x01000000, 0x00000001}, + {0x45364B59, 0x00800000, 0x00000008}, + {0x45364C41, 0x01000000, 0x00000001}, + {0x45364C43, 0x02000000, 0x00000001}, + {0x45364D41, 0x02000000, 0x00000005}, + {0x45364D43, 0x08000000, 0x00000002}, + {0x45364D54, 0x01000000, 0x00000001}, + {0x45364E41, 0x02000000, 0x00000001}, + {0x45364F41, 0x08000000, 0x00000001}, + {0x45365042, 0x01000000, 0x00000001}, + {0x45365241, 0x00800000, 0x00000002}, + {0x45365242, 0x02000000, 0x00000002}, + {0x45365259, 0x02000000, 0x00000002}, + {0x45365342, 0x01000000, 0xFFFFFFFF}, + {0x45365343, 0x04000000, 0x00000002}, + {0x45365359, 0x04000000, 0x00000005}, + {0x45365541, 0x00800000, 0x00000002}, + {0x45365559, 0x02000000, 0x00000002}, + {0x45365642, 0x01000000, 0x00000001}, + {0x45365742, 0x01000000, 0x00000001}, + {0x45365743, 0x04000000, 0x00000002}, + {0x45365941, 0x00800000, 0x00000005}, + {0x45365A42, 0x04000000, 0x00000002}, + {0x45373243, 0x08000000, 0x00000003}, + {0x45373359, 0x01000000, 0x00000001}, + {0x45373442, 0x01000000, 0x00000001}, + {0x45373541, 0x01000000, 0x00000008}, + {0x45373542, 0x00800000, 0xFFFFFFFF}, + {0x45373643, 0x00800000, 0x00000001}, + {0x45374143, 0x02000000, 0x00000002}, + {0x45374159, 0x02000000, 0x00000002}, + {0x45374241, 0x00800000, 0x00000001}, + {0x45374242, 0x02000000, 0x00000002}, + {0x45374243, 0x02000000, 0x00000002}, + {0x45374259, 0x04000000, 0x00000002}, + {0x45374341, 0x00800000, 0x00000002}, + {0x45374342, 0x01000000, 0x00000001}, + {0x45374441, 0x04000000, 0x00000005}, + {0x45374442, 0x00800000, 0x00000001}, + {0x45374542, 0x04000000, 0x00000002}, + {0x45374641, 0x02000000, 0x00000002}, + {0x45374659, 0x01000000, 0x00000002}, + {0x45374741, 0x02000000, 0x00000002}, + {0x45374742, 0x04000000, 0x00000001}, + {0x45374842, 0x00800000, 0x00000001}, + {0x45374943, 0x04000000, 0x00000002}, + {0x45374A42, 0x00800000, 0x00000001}, + {0x45374A43, 0x04000000, 0x00000001}, + {0x45374C41, 0x02000000, 0x00000001}, + {0x45374C43, 0x01000000, 0x00000002}, + {0x45374D41, 0x02000000, 0x00000002}, + {0x45374D43, 0x02000000, 0x00000008}, + {0x45374D59, 0x04000000, 0x00000002}, + {0x45374E41, 0x02000000, 0x00000002}, + {0x45375043, 0x04000000, 0x00000002}, + {0x45375141, 0x00800000, 0x00000002}, + {0x45375143, 0x04000000, 0x00000001}, + {0x45375242, 0x02000000, 0x00000002}, + {0x45375341, 0x08000000, 0x00000003}, + {0x45375359, 0x02000000, 0x00000001}, + {0x45375459, 0x04000000, 0x00000002}, + {0x45375541, 0x02000000, 0x00000002}, + {0x45375643, 0x00800000, 0x00000001}, + {0x45375742, 0x02000000, 0x00000002}, + {0x45375759, 0x04000000, 0x00000001}, + {0x45375842, 0x01000000, 0x00000001}, + {0x45375941, 0x08000000, 0x00000005}, + {0x45375943, 0x04000000, 0x00000002}, + {0x45375A42, 0x00800000, 0x00000001}, + {0x45383259, 0x02000000, 0x00000008}, + {0x45383342, 0x00800000, 0x00000001}, + {0x45383343, 0x04000000, 0x00000005}, + {0x45383541, 0x02000000, 0x00000008}, + {0x45383542, 0x00800000, 0x00000001}, + {0x45383559, 0x00800000, 0x00000000}, + {0x45384142, 0x00800000, 0x00000001}, + {0x45384159, 0x01000000, 0x00000002}, + {0x45384241, 0x02000000, 0x00000001}, + {0x45384242, 0x04000000, 0x00000002}, + {0x45384243, 0x02000000, 0x00000001}, + {0x45384342, 0x00800000, 0x00000001}, + {0x45384359, 0x01000000, 0x00000002}, + {0x45384443, 0x02000000, 0x00000002}, + {0x45384643, 0x04000000, 0x00000002}, + {0x45384659, 0x02000000, 0x00000003}, + {0x45384741, 0x04000000, 0x00000003}, + {0x45384759, 0x08000000, 0x00000005}, + {0x45384841, 0x02000000, 0x00000001}, + {0x45384842, 0x01000000, 0x00000001}, + {0x45384941, 0x02000000, 0x00000002}, + {0x45384959, 0x04000000, 0x00000001}, + {0x45384C41, 0x04000000, 0x00000001}, + {0x45384C43, 0x04000000, 0x00000002}, + {0x45384C59, 0x01000000, 0x00000001}, + {0x45384D41, 0x01000000, 0x00000001}, + {0x45384D42, 0x04000000, 0x00000001}, + {0x45384D43, 0x02000000, 0x00000002}, + {0x45384E41, 0x00800000, 0x00000001}, + {0x45384E42, 0x01000000, 0x00000001}, + {0x45384F41, 0x04000000, 0x00000003}, + {0x45384F59, 0x08000000, 0x00000003}, + {0x45385043, 0x02000000, 0x00000002}, + {0x45385059, 0x01000000, 0x00000001}, + {0x45385141, 0x00800000, 0x00000002}, + {0x45385142, 0x04000000, 0x00000002}, + {0x45385143, 0x01000000, 0x00000001}, + {0x45385243, 0x04000000, 0x00000002}, + {0x45385259, 0x02000000, 0x00000002}, + {0x45385342, 0x04000000, 0x00000002}, + {0x45385359, 0x04000000, 0x00000001}, + {0x45385442, 0x08000000, 0x00000001}, + {0x45385459, 0x02000000, 0x00000002}, + {0x45385542, 0x04000000, 0x00000001}, + {0x45385641, 0x01000000, 0x00000001}, + {0x45385643, 0x04000000, 0x00000002}, + {0x45385741, 0x04000000, 0x00000001}, + {0x45385743, 0x02000000, 0x00000002}, + {0x45385759, 0x08000000, 0x00000005}, + {0x45385841, 0x00800000, 0x00000001}, + {0x45385859, 0x08000000, 0x00000001}, + {0x45385941, 0x01000000, 0x00000001}, + {0x45385942, 0x00800000, 0x00000001}, + {0x45385943, 0x10000000, 0x00000003}, + {0x45385A42, 0x00800000, 0x00000001}, + {0x45393241, 0x00800000, 0x00000008}, + {0x45393341, 0x01000000, 0x00000008}, + {0x45393343, 0x02000000, 0x00000002}, + {0x45393443, 0x04000000, 0x00000005}, + {0x45393459, 0x04000000, 0x00000008}, + {0x45393541, 0x04000000, 0x00000008}, + {0x45393643, 0x04000000, 0x00000002}, + {0x45394241, 0x01000000, 0x00000001}, + {0x45394242, 0x02000000, 0x00000001}, + {0x45394243, 0x08000000, 0x00000005}, + {0x45394259, 0x02000000, 0x00000003}, + {0x45394341, 0x04000000, 0x00000001}, + {0x45394441, 0x02000000, 0x00000003}, + {0x45394542, 0x04000000, 0x00000002}, + {0x45394543, 0x01000000, 0x00000003}, + {0x45394641, 0x00800000, 0x00000001}, + {0x45394643, 0x02000000, 0x00000003}, + {0x45394659, 0x02000000, 0x00000001}, + {0x45394841, 0x04000000, 0x00000005}, + {0x45394856, 0x04000000, 0x00000002}, + {0x45394943, 0x01000000, 0x00000002}, + {0x45394A59, 0x00800000, 0x00000005}, + {0x45394B42, 0x10000000, 0x00000003}, + {0x45394C41, 0x02000000, 0x00000002}, + {0x45394C42, 0x08000000, 0x00000001}, + {0x45394D41, 0x01000000, 0x00000002}, + {0x45394D43, 0x01000000, 0x00000001}, + {0x45394D59, 0x01000000, 0x00000001}, + {0x45394E41, 0x01000000, 0x00000001}, + {0x45395042, 0x04000000, 0x00000002}, + {0x45395056, 0x04000000, 0x00000001}, + {0x45395059, 0x04000000, 0x00000003}, + {0x45395141, 0x04000000, 0x00000001}, + {0x45395259, 0x04000000, 0x00000002}, + {0x45395341, 0x02000000, 0x00000001}, + {0x45395343, 0x02000000, 0x00000001}, + {0x45395459, 0x04000000, 0x00000003}, + {0x45395643, 0x01000000, 0x00000001}, + {0x45395742, 0x08000000, 0x00000002}, + {0x45395743, 0x08000000, 0x00000001}, + {0x45395941, 0x08000000, 0x00000003}, + {0x45395943, 0x04000000, 0x00000002}, + {0x45395A43, 0x04000000, 0x00000002}, + {0x45413541, 0x04000000, 0x00000001}, + {0x45413543, 0x02000000, 0x00000002}, + {0x45413641, 0x02000000, 0x00000005}, + {0x45413642, 0x04000000, 0x00000001}, + {0x45413741, 0x01000000, 0x00000001}, + {0x45413956, 0x02000000, 0x00000000}, + {0x45414143, 0x04000000, 0x00000002}, + {0x45414156, 0x02000000, 0x00000007}, + {0x45414159, 0x04000000, 0x00000002}, + {0x45414241, 0x02000000, 0x00000001}, + {0x45414242, 0x02000000, 0x00000002}, + {0x45414243, 0x02000000, 0x00000001}, + {0x45414254, 0x01000000, 0x00000001}, + {0x45414256, 0x02000000, 0x00000001}, + {0x45414341, 0x00800000, 0x00000001}, + {0x45414356, 0x04000000, 0x00000001}, + {0x45414441, 0x04000000, 0x00000006}, + {0x45414442, 0x04000000, 0x00000001}, + {0x45414443, 0x04000000, 0x00000002}, + {0x45414541, 0x08000000, 0x00000001}, + {0x45414559, 0x02000000, 0x00000003}, + {0x45414641, 0x04000000, 0x00000003}, + {0x45414642, 0x02000000, 0x00000003}, + {0x45414643, 0x08000000, 0x00000002}, + {0x45414941, 0x04000000, 0x00000001}, + {0x45414959, 0x02000000, 0x00000001}, + {0x45414A42, 0x01000000, 0x00000002}, + {0x45414A43, 0x04000000, 0x00000003}, + {0x45414A59, 0x04000000, 0x00000002}, + {0x45414B41, 0x08000000, 0x00000005}, + {0x45414C42, 0x04000000, 0x00000002}, + {0x45414C56, 0x04000000, 0x00000002}, + {0x45414E42, 0x02000000, 0x00000001}, + {0x45414E43, 0x04000000, 0x00000001}, + {0x45415041, 0x04000000, 0x00000006}, + {0x45415042, 0x02000000, 0x00000002}, + {0x45415043, 0x02000000, 0x00000001}, + {0x45415054, 0x02000000, 0x00000001}, + {0x45415141, 0x02000000, 0x00000001}, + {0x45415143, 0x01000000, 0x00000002}, + {0x45415241, 0x02000000, 0x00000001}, + {0x45415243, 0x00800000, 0x00000001}, + {0x45415259, 0x01000000, 0x00000001}, + {0x45415343, 0x01000000, 0x00000001}, + {0x45415359, 0x01000000, 0x00000002}, + {0x45415441, 0x01000000, 0x00000001}, + {0x45415443, 0x04000000, 0x00000001}, + {0x45415543, 0x04000000, 0x00000001}, + {0x45415641, 0x04000000, 0x00000002}, + {0x45415643, 0x01000000, 0x00000001}, + {0x45415741, 0x04000000, 0x00000002}, + {0x45415743, 0x00800000, 0x00000001}, + {0x45415941, 0x00800000, 0x00000002}, + {0x45415942, 0x02000000, 0x00000001}, + {0x45415A42, 0x08000000, 0x00000001}, + {0x45415A43, 0x02000000, 0x00000002}, + {0x45423243, 0x02000000, 0x00000001}, + {0x45423342, 0x04000000, 0x00000001}, + {0x45423343, 0x00800000, 0x00000001}, + {0x45423442, 0x04000000, 0x00000002}, + {0x45423443, 0x02000000, 0x00000003}, + {0x45423542, 0x04000000, 0x00000002}, + {0x45423543, 0x01000000, 0x00000002}, + {0x45423641, 0x02000000, 0x00000005}, + {0x45423642, 0x04000000, 0x00000001}, + {0x45423741, 0x01000000, 0x00000001}, + {0x45423743, 0x02000000, 0x00000002}, + {0x45424143, 0x01000000, 0x00000001}, + {0x45424159, 0x00800000, 0x00000001}, + {0x45424243, 0x01000000, 0x00000002}, + {0x45424341, 0x04000000, 0x00000003}, + {0x45424354, 0x08000000, 0x00000001}, + {0x45424442, 0x04000000, 0x00000002}, + {0x45424443, 0x04000000, 0x00000001}, + {0x45424541, 0x00800000, 0x00000008}, + {0x45424641, 0x00800000, 0x00000001}, + {0x45424642, 0x01000000, 0x00000002}, + {0x45424654, 0x01000000, 0x00000001}, + {0x45424656, 0x02000000, 0x00000001}, + {0x45424743, 0x02000000, 0x00000001}, + {0x45424841, 0x02000000, 0x00000002}, + {0x45424842, 0x00800000, 0x00000001}, + {0x45424942, 0x01000000, 0x00000003}, + {0x45424959, 0x02000000, 0x00000001}, + {0x45424A41, 0x04000000, 0x00000005}, + {0x45424A42, 0x04000000, 0x00000001}, + {0x45424A43, 0x01000000, 0x00000001}, + {0x45424A59, 0x04000000, 0x00000001}, + {0x45424B41, 0x02000000, 0x00000003}, + {0x45424B43, 0x02000000, 0x00000002}, + {0x45424B59, 0x04000000, 0x00000003}, + {0x45424C42, 0x04000000, 0x00000002}, + {0x45424C43, 0x08000000, 0x00000003}, + {0x45424C59, 0x04000000, 0x00000002}, + {0x45424E43, 0x04000000, 0x00000003}, + {0x45425141, 0x00800000, 0x00000001}, + {0x45425143, 0x01000000, 0x00000002}, + {0x45425159, 0x00800000, 0x00000001}, + {0x45425241, 0x02000000, 0x00000001}, + {0x45425243, 0x02000000, 0x00000005}, + {0x45425259, 0x08000000, 0x00000003}, + {0x45425341, 0x04000000, 0x00000002}, + {0x45425442, 0x04000000, 0x00000002}, + {0x45425443, 0x08000000, 0x00000005}, + {0x45425543, 0x04000000, 0x00000003}, + {0x45425559, 0x04000000, 0x00000002}, + {0x45425641, 0x01000000, 0x00000001}, + {0x45425741, 0x00800000, 0x00000001}, + {0x45425742, 0x04000000, 0x00000002}, + {0x45425759, 0x02000000, 0x00000002}, + {0x45425942, 0x01000000, 0x00000001}, + {0x45425943, 0x04000000, 0x00000001}, + {0x45425959, 0x04000000, 0x00000005}, + {0x45433342, 0x04000000, 0x00000002}, + {0x45433441, 0x02000000, 0x00000003}, + {0x45433459, 0x04000000, 0x00000008}, + {0x45433542, 0x00800000, 0x00000001}, + {0x45433641, 0x02000000, 0x00000005}, + {0x45433642, 0x08000000, 0x00000002}, + {0x45433643, 0x10000000, 0x00000005}, + {0x45433741, 0x02000000, 0x00000001}, + {0x45433841, 0x02000000, 0x00000002}, + {0x45433859, 0x00800000, 0x00000008}, + {0x45434156, 0x04000000, 0x00000002}, + {0x45434241, 0x04000000, 0x00000005}, + {0x45434259, 0x02000000, 0x00000002}, + {0x45434341, 0x02000000, 0x00000001}, + {0x45434343, 0x01000000, 0x00000001}, + {0x45434354, 0x00800000, 0x00000001}, + {0x45434441, 0x01000000, 0x00000001}, + {0x45434442, 0x02000000, 0x00000001}, + {0x45434443, 0x04000000, 0x00000003}, + {0x45434459, 0x08000000, 0x00000003}, + {0x45434541, 0x00800000, 0x00000001}, + {0x45434559, 0x02000000, 0x00000001}, + {0x45434642, 0x02000000, 0x00000001}, + {0x45434659, 0x08000000, 0x00000002}, + {0x45434741, 0x04000000, 0x00000003}, + {0x45434759, 0x02000000, 0x00000002}, + {0x45434843, 0x01000000, 0x00000001}, + {0x45434941, 0x01000000, 0x00000001}, + {0x45434943, 0x04000000, 0x00000003}, + {0x45434956, 0x04000000, 0x00000002}, + {0x45434959, 0x04000000, 0x00000002}, + {0x45434A42, 0x03E8823C, 0x00000002}, + {0x45434A43, 0x04000000, 0x00000002}, + {0x45434A56, 0x04000000, 0x00000001}, + {0x45434A59, 0x04000000, 0x00000002}, + {0x45434B42, 0x10000000, 0x00000006}, + {0x45434B43, 0x01000000, 0x00000001}, + {0x45434C42, 0x04000000, 0x00000002}, + {0x45434C56, 0x04000000, 0x00000002}, + {0x45434D41, 0x02000000, 0x00000005}, + {0x45434D56, 0x02000000, 0x00000001}, + {0x45434F43, 0x01000000, 0x00000001}, + {0x45435041, 0x01000000, 0x00000001}, + {0x45435043, 0x00800000, 0x00000002}, + {0x45435159, 0x01000000, 0x00000001}, + {0x45435241, 0x02000000, 0x00000002}, + {0x45435243, 0x02000000, 0x00000001}, + {0x45435341, 0x04000000, 0x00000002}, + {0x45435343, 0x04000000, 0x00000001}, + {0x45435359, 0x01000000, 0x00000001}, + {0x45435441, 0x04000000, 0x00000005}, + {0x45435442, 0x01000000, 0x00000001}, + {0x45435641, 0x04000000, 0x00000005}, + {0x45435741, 0x04000000, 0x00000002}, + {0x45435759, 0x02000000, 0x00000002}, + {0x45435842, 0x01000000, 0x00000001}, + {0x45435943, 0x02000000, 0x00000002}, + {0x45435959, 0x02000000, 0x00000001}, + {0x45443241, 0x02000000, 0x00000002}, + {0x45443343, 0x01000000, 0x00000001}, + {0x45443442, 0x00800000, 0x00000001}, + {0x45443643, 0x02000000, 0x00000001}, + {0x45443659, 0x00800000, 0x00000008}, + {0x45443741, 0x02000000, 0x00000001}, + {0x45443759, 0x08000000, 0x00000008}, + {0x45444154, 0x08000000, 0x00000005}, + {0x45444241, 0x01000000, 0x00000001}, + {0x45444243, 0x04000000, 0x00000002}, + {0x45444343, 0x00800000, 0x00000003}, + {0x45444354, 0x02000000, 0x00000001}, + {0x45444356, 0x04000000, 0x00000002}, + {0x45444441, 0x01000000, 0x00000001}, + {0x45444459, 0x01000000, 0x00000001}, + {0x45444559, 0x00800000, 0x00000001}, + {0x45444641, 0x04000000, 0x00000002}, + {0x45444642, 0x00800000, 0x00000001}, + {0x45444643, 0x08000000, 0x00000002}, + {0x45444743, 0x00800000, 0x00000001}, + {0x45444759, 0x00800000, 0x00000003}, + {0x45444841, 0x04000000, 0x00000002}, + {0x45444842, 0x04000000, 0x00000001}, + {0x45444859, 0x04000000, 0x00000001}, + {0x45444943, 0x02000000, 0x00000003}, + {0x45444956, 0x02000000, 0x00000002}, + {0x45444959, 0x02000000, 0x00000005}, + {0x45444A42, 0x01000000, 0x00000002}, + {0x45444A59, 0x02000000, 0x00000002}, + {0x45444B41, 0x01000000, 0x00000002}, + {0x45444C41, 0x04000000, 0x00000003}, + {0x45444C42, 0x04000000, 0x00000002}, + {0x45444C59, 0x04000000, 0x00000005}, + {0x45444D41, 0x01000000, 0x00000005}, + {0x45444D42, 0x04000000, 0x00000001}, + {0x45444D43, 0x02000000, 0x00000005}, + {0x45444D44, 0x20000000, 0x00000000}, + {0x45444E41, 0x01000000, 0x00000005}, + {0x45444E42, 0x02000000, 0x00000001}, + {0x45444E43, 0x04000000, 0x00000002}, + {0x45444E59, 0x02000000, 0x00000001}, + {0x45445041, 0x01000000, 0x00000002}, + {0x45445042, 0x04000000, 0xFFFFFFFF}, + {0x45445043, 0x02000000, 0x00000001}, + {0x45445054, 0x08000000, 0x00000001}, + {0x45445241, 0x02000000, 0x00000001}, + {0x45445243, 0x01000000, 0x00000001}, + {0x45445341, 0x01000000, 0x00000001}, + {0x45445342, 0x04000000, 0x00000002}, + {0x45445343, 0x01000000, 0x00000001}, + {0x45445441, 0x01000000, 0x00000002}, + {0x45445442, 0x01000000, 0x00000001}, + {0x45445443, 0x04000000, 0x00000002}, + {0x45445542, 0x01000000, 0x00000001}, + {0x45445641, 0x01000000, 0x00000002}, + {0x45445642, 0x00800000, 0x00000001}, + {0x45445741, 0x02000000, 0x00000005}, + {0x45445742, 0x04000000, 0x00000001}, + {0x45445759, 0x01000000, 0x00000002}, + {0x45445842, 0x01000000, 0x00000001}, + {0x45445A41, 0x00800000, 0x00000008}, + {0x45445A42, 0x08000000, 0x00000001}, + {0x45453242, 0x00800000, 0x00000001}, + {0x45453341, 0x00800000, 0x00000002}, + {0x45453442, 0x01000000, 0x00000001}, + {0x45453559, 0x04000000, 0x00000000}, + {0x45453642, 0x02000000, 0x00000001}, + {0x45453741, 0x01000000, 0x00000001}, + {0x45453742, 0x02000000, 0x00000001}, + {0x45454241, 0x00800000, 0x00000001}, + {0x45454254, 0x02000000, 0x00000001}, + {0x45454343, 0x01000000, 0x00000005}, + {0x45454359, 0x02000000, 0x00000002}, + {0x45454442, 0x04000000, 0x00000002}, + {0x45454456, 0x10000000, 0x00000006}, + {0x45454641, 0x04000000, 0x00000003}, + {0x45454659, 0x04000000, 0x00000005}, + {0x45454741, 0x01000000, 0x00000001}, + {0x45454742, 0x04000000, 0x00000001}, + {0x45454743, 0x02000000, 0x00000002}, + {0x45454841, 0x08000000, 0x00000005}, + {0x45454943, 0x04000000, 0x00000002}, + {0x45454A59, 0x01000000, 0x00000001}, + {0x45454B42, 0x04000000, 0x00000002}, + {0x45454C59, 0x02000000, 0x00000001}, + {0x45454D44, 0x20000000, 0x00000000}, + {0x45454D56, 0x02000000, 0x00000001}, + {0x45454F59, 0x01000000, 0x00000005}, + {0x45455056, 0x04000000, 0x00000001}, + {0x45455141, 0x00800000, 0x00000002}, + {0x45455143, 0x04000000, 0x00000002}, + {0x45455241, 0x04000000, 0x00000001}, + {0x45455243, 0x04000000, 0x00000001}, + {0x45455341, 0x04000000, 0x00000002}, + {0x45455456, 0x04000000, 0x00000002}, + {0x45455459, 0x02000000, 0x00000003}, + {0x45455641, 0x01000000, 0x00000001}, + {0x45455642, 0x00800000, 0x00000002}, + {0x45455741, 0x04000000, 0x00000005}, + {0x45455742, 0x04000000, 0x00000001}, + {0x45455743, 0x01000000, 0x00000002}, + {0x45455842, 0x04000000, 0x00000001}, + {0x45455943, 0x08000000, 0x00000002}, + {0x45455A41, 0x04000000, 0x00000006}, + {0x45455A42, 0x00800000, 0x00000001}, + {0x45463242, 0x00800000, 0x00000001}, + {0x45463541, 0x04000000, 0x00000002}, + {0x45463641, 0x08000000, 0x00000003}, + {0x45463642, 0x08000000, 0x00000001}, + {0x45463659, 0x02000000, 0x00000000}, + {0x45463742, 0x01000000, 0xFFFFFFFF}, + {0x45463743, 0x01000000, 0x00000003}, + {0x45463859, 0x08000000, 0x00000008}, + {0x45464159, 0x02000000, 0x00000002}, + {0x45464243, 0x08000000, 0x00000003}, + {0x45464341, 0x04000000, 0x00000002}, + {0x45464343, 0x00800000, 0x00000001}, + {0x45464441, 0x01000000, 0x00000001}, + {0x45464443, 0x04000000, 0x00000002}, + {0x45464541, 0x00800000, 0x00000001}, + {0x45464542, 0x00800000, 0x00000001}, + {0x45464543, 0x01000000, 0x00000001}, + {0x45464641, 0x08000000, 0x00000003}, + {0x45464741, 0x04000000, 0x00000002}, + {0x45464743, 0x00800000, 0x00000001}, + {0x45464759, 0x01000000, 0x00000001}, + {0x45464841, 0x02000000, 0x00000001}, + {0x45464843, 0x02000000, 0x00000002}, + {0x45464859, 0x00800000, 0x00000002}, + {0x45464956, 0x02000000, 0x00000002}, + {0x45464959, 0x04000000, 0x00000002}, + {0x45464B43, 0x02000000, 0x00000001}, + {0x45464B59, 0x02000000, 0x00000001}, + {0x45464C42, 0x10000000, 0x00000003}, + {0x45464C43, 0x02000000, 0x00000001}, + {0x45464D41, 0x01000000, 0x00000001}, + {0x45464D44, 0x02000000, 0xFFFFFFFF}, + {0x45464D59, 0x04000000, 0x00000003}, + {0x45464E41, 0x02000000, 0x00000005}, + {0x45465042, 0x04000000, 0x00000002}, + {0x45465043, 0x00800000, 0x00000002}, + {0x45465054, 0x02000000, 0x00000001}, + {0x45465056, 0x04000000, 0x00000002}, + {0x45465241, 0x08000000, 0x00000003}, + {0x45465242, 0x08000000, 0x00000003}, + {0x45465243, 0x02000000, 0x00000002}, + {0x45465259, 0x02000000, 0x00000002}, + {0x45465341, 0x02000000, 0x00000005}, + {0x45465359, 0x04000000, 0x00000001}, + {0x45465443, 0x04000000, 0x00000001}, + {0x45465541, 0x04000000, 0x00000002}, + {0x45465542, 0x01000000, 0x00000002}, + {0x45465742, 0x04000000, 0x00000001}, + {0x45465743, 0x02000000, 0x00000002}, + {0x45465841, 0x08000000, 0x00000003}, + {0x45465842, 0x04000000, 0x00000001}, + {0x45473241, 0x02000000, 0x00000003}, + {0x45473256, 0x02000000, 0x00000006}, + {0x45473459, 0x01000000, 0x00000008}, + {0x45473541, 0x01000000, 0x00000001}, + {0x45473642, 0x00800000, 0x00000001}, + {0x45473741, 0x02000000, 0x00000001}, + {0x45473743, 0x01000000, 0x00000001}, + {0x45473759, 0x08000000, 0x00000000}, + {0x45473859, 0x02000000, 0x00000000}, + {0x45474142, 0x01000000, 0x00000001}, + {0x45474159, 0x01000000, 0x00000001}, + {0x45474243, 0x02000000, 0x00000005}, + {0x45474254, 0x00800000, 0x00000001}, + {0x45474341, 0x00800000, 0x00000002}, + {0x45474342, 0x04000000, 0x00000002}, + {0x45474354, 0x04000000, 0x00000001}, + {0x45474356, 0x04000000, 0x00000002}, + {0x45474359, 0x00800000, 0x00000001}, + {0x45474441, 0x02000000, 0x00000005}, + {0x45474443, 0x04000000, 0x00000006}, + {0x45474541, 0x04000000, 0x00000001}, + {0x45474542, 0x00800000, 0x00000001}, + {0x45474641, 0x04000000, 0x00000001}, + {0x45474642, 0x04000000, 0x00000003}, + {0x45474742, 0x02000000, 0x00000005}, + {0x45474754, 0x00800000, 0x00000001}, + {0x45474842, 0x02000000, 0x00000001}, + {0x45474942, 0x02000000, 0x00000001}, + {0x45474A59, 0x02000000, 0x00000002}, + {0x45474B41, 0x02000000, 0x00000002}, + {0x45474B56, 0x02000000, 0x00000005}, + {0x45474B59, 0x10000000, 0x00000003}, + {0x45474C43, 0x04000000, 0x00000001}, + {0x45474C59, 0x04000000, 0x00000001}, + {0x45474D41, 0x01000000, 0x00000001}, + {0x45474D42, 0x02000000, 0x00000001}, + {0x45474D43, 0x04000000, 0x00000001}, + {0x45474D56, 0x02000000, 0x00000002}, + {0x45474E43, 0x02000000, 0x00000002}, + {0x45474E59, 0x08000000, 0x00000003}, + {0x45474F59, 0x08000000, 0x00000003}, + {0x45475041, 0x01000000, 0x00000001}, + {0x45475049, 0x08000000, 0x00000006}, + {0x45475059, 0x04000000, 0x00000002}, + {0x45475142, 0x04000000, 0x00000001}, + {0x45475241, 0x02000000, 0x00000005}, + {0x45475256, 0x02000000, 0x00000002}, + {0x45475356, 0x02000000, 0x00000001}, + {0x45475541, 0x02000000, 0x00000002}, + {0x45475542, 0x00800000, 0x00000001}, + {0x45475642, 0x01000000, 0x00000002}, + {0x45475842, 0x04000000, 0x00000002}, + {0x45475843, 0x00800000, 0x00000001}, + {0x45475941, 0x04000000, 0x00000002}, + {0x45475A42, 0x02000000, 0x00000001}, + {0x45483241, 0x01000000, 0x00000001}, + {0x45483341, 0x02000000, 0x00000001}, + {0x45483343, 0x00800000, 0x00000001}, + {0x45483442, 0x02000000, 0x00000001}, + {0x45483541, 0x01000000, 0x00000001}, + {0x45483542, 0x01000000, 0x00000001}, + {0x45483559, 0x02000000, 0x00000000}, + {0x45483741, 0x02000000, 0x00000001}, + {0x45483742, 0x04000000, 0x00000002}, + {0x45483842, 0x04000000, 0x00000002}, + {0x45483959, 0x00800000, 0x00000008}, + {0x45484142, 0x04000000, 0x00000001}, + {0x45484159, 0x04000000, 0x00000002}, + {0x45484241, 0x08000000, 0x00000002}, + {0x45484254, 0x01000000, 0x00000001}, + {0x45484342, 0x00800000, 0x00000001}, + {0x45484459, 0x02000000, 0x00000005}, + {0x45484541, 0x04000000, 0x00000002}, + {0x45484542, 0x01000000, 0x00000002}, + {0x45484659, 0x04000000, 0x00000002}, + {0x45484742, 0x10000000, 0x00000001}, + {0x45484743, 0x02000000, 0x00000002}, + {0x45484759, 0x08000000, 0x00000001}, + {0x45484841, 0x04000000, 0x00000001}, + {0x45484942, 0x04000000, 0x00000002}, + {0x45484943, 0x04000000, 0x00000002}, + {0x45484959, 0x02000000, 0x00000002}, + {0x45484B43, 0x02000000, 0x00000002}, + {0x45484B56, 0x02000000, 0x00000002}, + {0x45484B59, 0x08000000, 0x00000005}, + {0x45484C41, 0x02000000, 0x00000001}, + {0x45484C42, 0x08000000, 0x00000001}, + {0x45484C43, 0x01000000, 0x00000002}, + {0x45484C59, 0x04000000, 0x00000002}, + {0x45484D41, 0x04000000, 0x00000005}, + {0x45484D54, 0x00800000, 0x00000001}, + {0x45485041, 0x02000000, 0x00000005}, + {0x45485043, 0x04000000, 0x00000001}, + {0x45485059, 0x00800000, 0x00000002}, + {0x45485341, 0x02000000, 0x00000002}, + {0x45485342, 0x02000000, 0x00000001}, + {0x45485359, 0x02000000, 0x00000001}, + {0x45485441, 0x02000000, 0x00000001}, + {0x45485442, 0x01000000, 0x00000002}, + {0x45485559, 0x01000000, 0x00000002}, + {0x45485641, 0x04000000, 0x00000002}, + {0x45485642, 0x01000000, 0x00000001}, + {0x45485741, 0x01000000, 0x00000001}, + {0x45485843, 0x02000000, 0x00000001}, + {0x45485942, 0x02000000, 0x00000002}, + {0x45485943, 0x04000000, 0x00000002}, + {0x45485A42, 0x00800000, 0x00000001}, + {0x45485A59, 0x04000000, 0x00000001}, + {0x45493241, 0x01000000, 0x00000001}, + {0x45493242, 0x04000000, 0x00000001}, + {0x45493341, 0x08000000, 0x00000002}, + {0x45493441, 0x02000000, 0x00000001}, + {0x45493459, 0x04000000, 0x00000008}, + {0x45493541, 0x01000000, 0x00000001}, + {0x45493642, 0x04000000, 0x00000002}, + {0x45493741, 0x02000000, 0x00000001}, + {0x45493842, 0x04000000, 0x00000001}, + {0x45493859, 0x01000000, 0x00000000}, + {0x45494159, 0x04000000, 0x00000001}, + {0x45494341, 0x02000000, 0x00000002}, + {0x45494342, 0x02000000, 0x00000002}, + {0x45494359, 0x01000000, 0x00000001}, + {0x45494442, 0x04000000, 0x00000001}, + {0x45494459, 0x04000000, 0x00000002}, + {0x45494643, 0x08000000, 0x00000003}, + {0x45494659, 0x04000000, 0x00000001}, + {0x45494742, 0x04000000, 0x00000001}, + {0x45494942, 0x00800000, 0x00000001}, + {0x45494959, 0x00800000, 0x00000001}, + {0x45494B42, 0x08000000, 0x00000007}, + {0x45494C43, 0x04000000, 0x00000001}, + {0x45494C59, 0x04000000, 0x00000002}, + {0x45494D43, 0x00800000, 0x00000001}, + {0x45494E41, 0x08000000, 0x00000005}, + {0x45494E59, 0x08000000, 0x00000002}, + {0x45495056, 0x02000000, 0x00000002}, + {0x45495059, 0x02000000, 0x00000003}, + {0x45495141, 0x02000000, 0x00000005}, + {0x45495241, 0x01000000, 0x00000001}, + {0x45495243, 0x02000000, 0x00000002}, + {0x45495256, 0x02000000, 0x00000001}, + {0x45495259, 0x04000000, 0x00000002}, + {0x45495341, 0x02000000, 0x00000002}, + {0x45495342, 0x04000000, 0x00000001}, + {0x45495343, 0x01000000, 0x00000002}, + {0x45495441, 0x01000000, 0x00000008}, + {0x45495442, 0x01000000, 0x00000001}, + {0x45495456, 0x02000000, 0x00000001}, + {0x45495541, 0x01000000, 0x00000001}, + {0x45495542, 0x01000000, 0x00000001}, + {0x45495543, 0x02000000, 0x00000002}, + {0x45495559, 0x04000000, 0x00000002}, + {0x45495643, 0x04000000, 0x00000002}, + {0x45495659, 0x08000000, 0x00000003}, + {0x45495741, 0x08000000, 0x00000005}, + {0x45495742, 0x01000000, 0x00000002}, + {0x45495743, 0x01000000, 0x00000001}, + {0x45495941, 0x01000000, 0x00000001}, + {0x45495943, 0x02000000, 0x00000002}, + {0x45495A42, 0x00800000, 0x00000001}, + {0x454A3259, 0x02000000, 0x00000008}, + {0x454A3342, 0x08000000, 0x00000002}, + {0x454A3343, 0x10000000, 0x00000003}, + {0x454A3442, 0x00800000, 0x00000001}, + {0x454A3542, 0x00800000, 0x00000001}, + {0x454A3559, 0x08000000, 0x00000000}, + {0x454A3642, 0x00800000, 0x00000001}, + {0x454A3741, 0x02000000, 0x00000001}, + {0x454A4142, 0x01000000, 0x00000001}, + {0x454A4143, 0x01000000, 0x00000001}, + {0x454A4159, 0x01000000, 0x00000002}, + {0x454A4241, 0x04000000, 0x00000005}, + {0x454A4341, 0x04000000, 0x00000001}, + {0x454A4454, 0x00800000, 0x00000001}, + {0x454A4459, 0x01000000, 0x00000001}, + {0x454A4543, 0x01000000, 0x00000001}, + {0x454A4642, 0x01000000, 0x00000002}, + {0x454A4643, 0x02000000, 0x00000002}, + {0x454A4759, 0x02000000, 0x00000001}, + {0x454A4841, 0x01000000, 0x00000002}, + {0x454A4943, 0x00800000, 0x00000001}, + {0x454A4956, 0x04000000, 0x00000003}, + {0x454A4A42, 0x01000000, 0x00000001}, + {0x454A4A43, 0x00800000, 0x00000001}, + {0x454A4C41, 0x01000000, 0x00000001}, + {0x454A4C42, 0x04000000, 0x00000001}, + {0x454A4C43, 0x08000000, 0x00000002}, + {0x454A4C54, 0x08000000, 0x00000002}, + {0x454A4C59, 0x04000000, 0x00000001}, + {0x454A4D42, 0x00800000, 0x00000001}, + {0x454A4D59, 0x04000000, 0x00000001}, + {0x454A4E41, 0x02000000, 0x00000001}, + {0x454A4E43, 0x02000000, 0x00000001}, + {0x454A4E59, 0x02000000, 0x00000001}, + {0x454A4F41, 0x02000000, 0x00000002}, + {0x454A5043, 0x04000000, 0x00000002}, + {0x454A5141, 0x08000000, 0x00000001}, + {0x454A5143, 0x00800000, 0x00000001}, + {0x454A5242, 0x08000000, 0x00000003}, + {0x454A5243, 0x02000000, 0x00000001}, + {0x454A5341, 0x04000000, 0x00000005}, + {0x454A5342, 0x00800000, 0x00000001}, + {0x454A5441, 0x01000000, 0x00000002}, + {0x454A5442, 0x01000000, 0x00000002}, + {0x454A5459, 0x04000000, 0x00000002}, + {0x454A5541, 0x04000000, 0x00000001}, + {0x454A5542, 0x08000000, 0x00000001}, + {0x454A5641, 0x04000000, 0x00000002}, + {0x454A5642, 0x01000000, 0x00000001}, + {0x454A5659, 0x01000000, 0x00000001}, + {0x454A5743, 0x00800000, 0x00000001}, + {0x454A5759, 0x00800000, 0x00000002}, + {0x454A5841, 0x04000000, 0x00000003}, + {0x454A5959, 0x01000000, 0x00000002}, + {0x454A5A42, 0x02000000, 0x00000001}, + {0x454B3243, 0x00800000, 0x00000003}, + {0x454B3342, 0x01000000, 0x00000001}, + {0x454B3641, 0x08000000, 0x00000003}, + {0x454B3741, 0x02000000, 0x00000001}, + {0x454B3842, 0x02000000, 0x00000002}, + {0x454B4143, 0x01000000, 0x00000002}, + {0x454B4241, 0x00800000, 0x00000001}, + {0x454B4242, 0x02000000, 0x00000002}, + {0x454B4243, 0x04000000, 0x00000002}, + {0x454B4343, 0x04000000, 0x00000001}, + {0x454B4356, 0x08000000, 0x00000002}, + {0x454B4541, 0x04000000, 0x00000002}, + {0x454B4559, 0x08000000, 0x00000005}, + {0x454B4841, 0x04000000, 0x00000003}, + {0x454B4843, 0x01000000, 0x00000001}, + {0x454B4959, 0x02000000, 0x00000005}, + {0x454B4A43, 0x08000000, 0x00000003}, + {0x454B4A59, 0x08000000, 0x00000002}, + {0x454B4B41, 0x01000000, 0x00000003}, + {0x454B4C41, 0x08000000, 0x00000003}, + {0x454B4C54, 0x08000000, 0x00000002}, + {0x454B4C59, 0x02000000, 0x00000002}, + {0x454B4D42, 0x04000000, 0x00000001}, + {0x454B4E41, 0x00800000, 0x00000001}, + {0x454B4E59, 0x04000000, 0x00000002}, + {0x454B5049, 0x08000000, 0x00000006}, + {0x454B5142, 0x01000000, 0x00000001}, + {0x454B5159, 0x02000000, 0x00000001}, + {0x454B5243, 0x04000000, 0x00000001}, + {0x454B5341, 0x04000000, 0x00000002}, + {0x454B5342, 0x08000000, 0x00000003}, + {0x454B5356, 0x04000000, 0x00000001}, + {0x454B5441, 0x04000000, 0x00000002}, + {0x454B5559, 0x04000000, 0x00000001}, + {0x454B5641, 0x01000000, 0x00000001}, + {0x454B5741, 0x04000000, 0x00000003}, + {0x454B5759, 0x04000000, 0x00000002}, + {0x454B5943, 0x02000000, 0x00000002}, + {0x454B5959, 0x04000000, 0x00000002}, + {0x454B5A41, 0x00800000, 0x00000002}, + {0x454C3241, 0x01000000, 0x00000003}, + {0x454C3259, 0x04000000, 0x00000005}, + {0x454C3541, 0x08000000, 0x00000002}, + {0x454C3642, 0x08000000, 0x00000002}, + {0x454C3741, 0x02000000, 0x00000001}, + {0x454C3742, 0x00800000, 0x00000001}, + {0x454C3859, 0x08000000, 0x00000000}, + {0x454C4143, 0x04000000, 0x00000001}, + {0x454C4156, 0x04000000, 0x00000002}, + {0x454C4241, 0x08000000, 0x00000002}, + {0x454C4242, 0x02000000, 0x00000001}, + {0x454C4243, 0x00800000, 0x00000002}, + {0x454C4256, 0x02000000, 0x00000002}, + {0x454C4259, 0x00800000, 0x00000001}, + {0x454C4341, 0x04000000, 0x00000003}, + {0x454C4342, 0x01000000, 0x00000002}, + {0x454C4354, 0x02000000, 0x00000001}, + {0x454C4441, 0x04000000, 0x00000003}, + {0x454C4442, 0x01000000, 0x00000001}, + {0x454C4443, 0x02000000, 0x00000005}, + {0x454C4459, 0x01000000, 0x00000008}, + {0x454C4556, 0x02000000, 0x00000003}, + {0x454C4641, 0x00800000, 0x00000001}, + {0x454C4642, 0x04000000, 0x00000002}, + {0x454C4741, 0x02000000, 0x00000001}, + {0x454C4742, 0x01000000, 0x00000001}, + {0x454C4759, 0x04000000, 0x00000002}, + {0x454C4859, 0x08000000, 0x00000003}, + {0x454C4A41, 0x04000000, 0x00000001}, + {0x454C4A42, 0x02000000, 0x00000002}, + {0x454C4A59, 0x01000000, 0x00000002}, + {0x454C4B54, 0x02000000, 0x00000002}, + {0x454C4C42, 0x01000000, 0x00000003}, + {0x454C4C54, 0x04000000, 0x00000001}, + {0x454C4D41, 0x02000000, 0x00000002}, + {0x454C4D42, 0x00800000, 0x00000001}, + {0x454C4D43, 0x04000000, 0x00000002}, + {0x454C4D54, 0x04000000, 0x00000002}, + {0x454C4E41, 0x04000000, 0x00000001}, + {0x454C4E42, 0x01000000, 0x00000001}, + {0x454C4E59, 0x04000000, 0x00000001}, + {0x454C4F43, 0x08000000, 0x00000003}, + {0x454C5041, 0x00800000, 0x00000002}, + {0x454C5043, 0x01000000, 0x00000001}, + {0x454C5059, 0x00800000, 0x00000001}, + {0x454C5141, 0x00800000, 0x00000001}, + {0x454C5142, 0x00800000, 0x00000003}, + {0x454C5159, 0x08000000, 0x00000002}, + {0x454C5242, 0x01000000, 0x00000001}, + {0x454C5243, 0x02000000, 0x00000001}, + {0x454C5259, 0x02000000, 0x00000001}, + {0x454C5341, 0x01000000, 0x00000001}, + {0x454C5342, 0x02000000, 0x00000003}, + {0x454C5343, 0x00800000, 0x00000002}, + {0x454C5359, 0x10000000, 0x00000005}, + {0x454C5441, 0x01000000, 0x00000001}, + {0x454C5459, 0x00800000, 0x00000002}, + {0x454C5541, 0x00800000, 0x00000002}, + {0x454C5741, 0x08000000, 0x00000003}, + {0x454C5759, 0x02000000, 0x00000001}, + {0x454C5841, 0x04000000, 0x00000001}, + {0x454C5942, 0x02000000, 0x00000001}, + {0x454C5A41, 0x08000000, 0x00000007}, + {0x454D3241, 0x00800000, 0x00000001}, + {0x454D3243, 0x02000000, 0x00000002}, + {0x454D3259, 0x02000000, 0x00000008}, + {0x454D3341, 0x08000000, 0x00000002}, + {0x454D3342, 0x04000000, 0x00000002}, + {0x454D3442, 0x02000000, 0x00000001}, + {0x454D3443, 0x04000000, 0x00000001}, + {0x454D3542, 0x01000000, 0x00000001}, + {0x454D3543, 0x01000000, 0x00000001}, + {0x454D3643, 0x04000000, 0x00000002}, + {0x454D3741, 0x02000000, 0x00000001}, + {0x454D3742, 0x01000000, 0x00000001}, + {0x454D3743, 0x01000000, 0x00000003}, + {0x454D4143, 0x01000000, 0x00000002}, + {0x454D4154, 0x02000000, 0x00000001}, + {0x454D4159, 0x00800000, 0x00000001}, + {0x454D4241, 0x00800000, 0x00000001}, + {0x454D4242, 0x00800000, 0x00000001}, + {0x454D4243, 0x02000000, 0x00000002}, + {0x454D4341, 0x01000000, 0x00000001}, + {0x454D4342, 0x04000000, 0x00000001}, + {0x454D4343, 0x04000000, 0x00000002}, + {0x454D4354, 0x04000000, 0x00000002}, + {0x454D4356, 0x04000000, 0x00000002}, + {0x454D4359, 0x02000000, 0x00000001}, + {0x454D4441, 0x02000000, 0x00000005}, + {0x454D4459, 0x02000000, 0x00000002}, + {0x454D4643, 0x04000000, 0x00000003}, + {0x454D4659, 0x04000000, 0x00000003}, + {0x454D4742, 0x04000000, 0x00000003}, + {0x454D4843, 0x04000000, 0x00000002}, + {0x454D4943, 0x01000000, 0x00000002}, + {0x454D4959, 0x04000000, 0x00000001}, + {0x454D4A42, 0x04000000, 0x00000002}, + {0x454D4A59, 0x00800000, 0x00000002}, + {0x454D4C54, 0x08000000, 0x00000001}, + {0x454D4D42, 0x00800000, 0x00000001}, + {0x454D4D59, 0x02000000, 0x00000001}, + {0x454D4E41, 0x02000000, 0x00000005}, + {0x454D4E42, 0x04000000, 0x00000001}, + {0x454D4E43, 0x04000000, 0x00000001}, + {0x454D4E59, 0x01000000, 0x00000002}, + {0x454D5042, 0x02000000, 0x00000001}, + {0x454D5043, 0x04000000, 0x00000002}, + {0x454D5141, 0x00800000, 0x00000001}, + {0x454D5241, 0x04000000, 0x00000002}, + {0x454D5242, 0x01000000, 0x00000002}, + {0x454D5259, 0x02000000, 0x00000003}, + {0x454D5341, 0x01000000, 0x00000002}, + {0x454D5342, 0x01000000, 0x00000002}, + {0x454D5459, 0x04000000, 0x00000002}, + {0x454D5642, 0x02000000, 0x00000001}, + {0x454D5643, 0x02000000, 0x00000002}, + {0x454D5741, 0x00800000, 0x00000001}, + {0x454D5842, 0x04000000, 0x00000002}, + {0x454D5843, 0x04000000, 0x00000003}, + {0x454D5A43, 0x02000000, 0x00000001}, + {0x454E3242, 0x02000000, 0x00000001}, + {0x454E3243, 0x01000000, 0x00000002}, + {0x454E3342, 0x02000000, 0x00000001}, + {0x454E3542, 0x01000000, 0x00000001}, + {0x454E3543, 0x01000000, 0x00000001}, + {0x454E3641, 0x08000000, 0x00000003}, + {0x454E3741, 0x02000000, 0x00000001}, + {0x454E3742, 0x08000000, 0x00000003}, + {0x454E3841, 0x02000000, 0x00000005}, + {0x454E4143, 0x02000000, 0x00000005}, + {0x454E4259, 0x04000000, 0x00000007}, + {0x454E4341, 0x01000000, 0x00000002}, + {0x454E4354, 0x01000000, 0x00000001}, + {0x454E4441, 0x04000000, 0x00000003}, + {0x454E4443, 0x08000000, 0x00000001}, + {0x454E4541, 0x04000000, 0x00000002}, + {0x454E4543, 0x02000000, 0x00000003}, + {0x454E4641, 0x02000000, 0x00000002}, + {0x454E4654, 0x04000000, 0x00000002}, + {0x454E4656, 0x02000000, 0x00000002}, + {0x454E4741, 0x02000000, 0x00000001}, + {0x454E4743, 0x04000000, 0x00000002}, + {0x454E4759, 0x04000000, 0x00000002}, + {0x454E4841, 0x04000000, 0x00000001}, + {0x454E4843, 0x02000000, 0x00000002}, + {0x454E4859, 0x04000000, 0x00000003}, + {0x454E4942, 0x00800000, 0x00000001}, + {0x454E4A41, 0x02000000, 0x00000002}, + {0x454E4A43, 0x01000000, 0x00000001}, + {0x454E4B43, 0x08000000, 0x00000002}, + {0x454E4C41, 0x02000000, 0x00000002}, + {0x454E4C59, 0x08000000, 0x00000002}, + {0x454E4D54, 0x01000000, 0x00000002}, + {0x454E4E42, 0x04000000, 0x00000002}, + {0x454E4E59, 0x08000000, 0x00000003}, + {0x454E5041, 0x02000000, 0x00000001}, + {0x454E5042, 0x01000000, 0x00000002}, + {0x454E5059, 0x00800000, 0x00000001}, + {0x454E5142, 0x04000000, 0x00000001}, + {0x454E5159, 0x04000000, 0x00000002}, + {0x454E5241, 0x01000000, 0x00000001}, + {0x454E5341, 0x00800000, 0x00000002}, + {0x454E5342, 0x02000000, 0x00000001}, + {0x454E5356, 0x04000000, 0x00000002}, + {0x454E5442, 0x04000000, 0x00000002}, + {0x454E5642, 0x04000000, 0x00000001}, + {0x454E5643, 0x04000000, 0x00000001}, + {0x454E5842, 0x01000000, 0x00000001}, + {0x454E5A41, 0x01000000, 0x00000002}, + {0x454E5A43, 0x04000000, 0x00000002}, + {0x454F3241, 0x04000000, 0x00000003}, + {0x454F3341, 0x00800000, 0x00000001}, + {0x454F3441, 0x02000000, 0x00000005}, + {0x454F3541, 0x01000000, 0x00000001}, + {0x454F3542, 0x00800000, 0x00000001}, + {0x454F3559, 0x08000000, 0x00000000}, + {0x454F3642, 0x02000000, 0x00000001}, + {0x454F3659, 0x00800000, 0x00000000}, + {0x454F3741, 0x02000000, 0x00000001}, + {0x454F3743, 0x04000000, 0x00000002}, + {0x454F3842, 0x01000000, 0x00000001}, + {0x454F3959, 0x00800000, 0x00000000}, + {0x454F4142, 0x04000000, 0x00000001}, + {0x454F4143, 0x01000000, 0x00000001}, + {0x454F4156, 0x04000000, 0x00000001}, + {0x454F4241, 0x02000000, 0x00000001}, + {0x454F4259, 0x08000000, 0x00000003}, + {0x454F4341, 0x04000000, 0x00000005}, + {0x454F4359, 0x04000000, 0x00000001}, + {0x454F4641, 0x04000000, 0x00000003}, + {0x454F4842, 0x04000000, 0x00000001}, + {0x454F4843, 0x02000000, 0x00000001}, + {0x454F4942, 0x02000000, 0x00000001}, + {0x454F4943, 0x01000000, 0x00000008}, + {0x454F4A42, 0x04000000, 0x00000001}, + {0x454F4A43, 0x04000000, 0x00000002}, + {0x454F4B42, 0x04000000, 0x00000003}, + {0x454F4D41, 0x04000000, 0x00000002}, + {0x454F4D56, 0x02000000, 0x00000003}, + {0x454F4D59, 0x04000000, 0x00000001}, + {0x454F4E41, 0x02000000, 0x00000002}, + {0x454F4F42, 0x08000000, 0x00000002}, + {0x454F4F43, 0x04000000, 0x00000002}, + {0x454F5043, 0x01000000, 0x00000002}, + {0x454F5059, 0x04000000, 0x00000003}, + {0x454F5259, 0x04000000, 0x00000002}, + {0x454F5342, 0x02000000, 0x00000001}, + {0x454F5356, 0x04000000, 0x00000003}, + {0x454F5541, 0x00800000, 0x00000001}, + {0x454F5741, 0x02000000, 0x00000002}, + {0x454F5742, 0x02000000, 0x00000001}, + {0x454F5743, 0x00800000, 0x00000001}, + {0x454F5843, 0x04000000, 0x00000001}, + {0x454F5A42, 0x04000000, 0x00000003}, + {0x454F5A43, 0x02000000, 0x00000001}, + {0x45503342, 0x04000000, 0x00000001}, + {0x45503343, 0x04000000, 0x00000002}, + {0x45503441, 0x02000000, 0x00000002}, + {0x45503541, 0x04000000, 0x00000001}, + {0x45503643, 0x04000000, 0x00000007}, + {0x45503659, 0x04000000, 0x00000000}, + {0x45503741, 0x02000000, 0x00000001}, + {0x45503743, 0x04000000, 0x00000002}, + {0x45503859, 0x00800000, 0x00000008}, + {0x45504143, 0x02000000, 0x00000003}, + {0x45504243, 0x01000000, 0x00000002}, + {0x45504259, 0x02000000, 0x00000001}, + {0x45504341, 0x00800000, 0x00000002}, + {0x45504342, 0x04000000, 0x00000002}, + {0x45504442, 0x00800000, 0x00000001}, + {0x45504443, 0x01000000, 0x00000002}, + {0x45504542, 0x01000000, 0x00000002}, + {0x45504543, 0x08000000, 0x00000002}, + {0x45504643, 0x04000000, 0x00000002}, + {0x45504659, 0x01000000, 0x00000001}, + {0x45504741, 0x04000000, 0x00000002}, + {0x45504743, 0x02000000, 0x00000001}, + {0x45504754, 0x02000000, 0x00000001}, + {0x45504841, 0x04000000, 0x00000001}, + {0x45504941, 0x00800000, 0x00000008}, + {0x45504A41, 0x00800000, 0x00000001}, + {0x45504A43, 0x04000000, 0x00000002}, + {0x45504B41, 0x01000000, 0x00000001}, + {0x45504C41, 0x00800000, 0x00000001}, + {0x45504C42, 0x04000000, 0x00000002}, + {0x45504C43, 0x04000000, 0x00000003}, + {0x45504C54, 0x02000000, 0x00000001}, + {0x45504C59, 0x00800000, 0x00000002}, + {0x45504D41, 0x02000000, 0x00000002}, + {0x45504D43, 0x04000000, 0x00000001}, + {0x45504E41, 0x01000000, 0x00000001}, + {0x45504E59, 0x04000000, 0x00000002}, + {0x45504F41, 0x00800000, 0x00000001}, + {0x45504F43, 0x01000000, 0x00000003}, + {0x45504F59, 0x01000000, 0x00000001}, + {0x45505041, 0x001A68C8, 0x00000002}, + {0x45505043, 0x04000000, 0x00000005}, + {0x45505056, 0x02000000, 0x00000001}, + {0x45505141, 0x02000000, 0x00000002}, + {0x45505143, 0x01000000, 0x00000001}, + {0x45505159, 0x04000000, 0x00000002}, + {0x45505241, 0x04000000, 0x00000001}, + {0x45505242, 0x08000000, 0x00000002}, + {0x45505243, 0x02000000, 0x00000001}, + {0x45505256, 0x02000000, 0x00000001}, + {0x45505341, 0x02000000, 0x00000003}, + {0x45505342, 0x01000000, 0x00000002}, + {0x45505343, 0x10000000, 0x00000003}, + {0x45505356, 0x02000000, 0x00000002}, + {0x45505359, 0x02000000, 0x00000005}, + {0x45505442, 0x04000000, 0x00000002}, + {0x45505642, 0x08000000, 0x00000006}, + {0x45505659, 0x08000000, 0x00000003}, + {0x45505741, 0x01000000, 0x00000001}, + {0x45505742, 0x00800000, 0x00000001}, + {0x45505743, 0x02000000, 0x00000002}, + {0x45505841, 0x02000000, 0x00000005}, + {0x45505843, 0x02000000, 0x00000001}, + {0x45513543, 0x01000000, 0x00000002}, + {0x45513643, 0x08000000, 0x00000001}, + {0x45513741, 0x02000000, 0x00000001}, + {0x45513841, 0x02000000, 0x00000005}, + {0x45514141, 0x00800000, 0x00000000}, + {0x45514242, 0x00800000, 0x00000001}, + {0x45514243, 0x02000000, 0x00000002}, + {0x45514342, 0x01000000, 0x00000001}, + {0x45514359, 0x04000000, 0x00000002}, + {0x45514441, 0x04000000, 0x00000002}, + {0x45514459, 0x10000000, 0x00000003}, + {0x45514559, 0x00800000, 0x00000001}, + {0x45514641, 0x04000000, 0x00000002}, + {0x45514643, 0x01000000, 0x00000001}, + {0x45514741, 0x02000000, 0x00000003}, + {0x45514742, 0x02000000, 0x00000002}, + {0x45514743, 0x04000000, 0x00000003}, + {0x45514759, 0x04000000, 0x00000002}, + {0x45514841, 0x02000000, 0x00000001}, + {0x45514943, 0x02000000, 0x00000002}, + {0x45514A41, 0x01000000, 0x00000002}, + {0x45514A43, 0x00800000, 0x00000002}, + {0x45514A59, 0x01000000, 0x00000001}, + {0x45514B41, 0x02000000, 0x00000001}, + {0x45514B42, 0x04000000, 0x00000001}, + {0x45514B43, 0x02000000, 0x00000001}, + {0x45514C43, 0x04000000, 0x00000001}, + {0x45514D41, 0x04000000, 0x00000005}, + {0x45514E41, 0x00800000, 0x00000002}, + {0x45514E42, 0x02000000, 0x00000001}, + {0x45514F43, 0x04000000, 0x00000002}, + {0x45515042, 0x02000000, 0x00000001}, + {0x45515043, 0x02000000, 0x00000001}, + {0x45515141, 0x02000000, 0x00000002}, + {0x45515242, 0x01000000, 0x00000001}, + {0x45515243, 0x02000000, 0x00000001}, + {0x45515259, 0x02000000, 0x00000001}, + {0x45515341, 0x00800000, 0x00000002}, + {0x45515343, 0x01000000, 0x00000001}, + {0x45515359, 0x02000000, 0x00000002}, + {0x45515442, 0x01000000, 0x00000001}, + {0x45515641, 0x02000000, 0x00000002}, + {0x45515742, 0x01000000, 0x00000001}, + {0x45515743, 0x02000000, 0x00000001}, + {0x45515759, 0x00800000, 0x00000001}, + {0x45515842, 0x02000000, 0x00000001}, + {0x45515941, 0x00800000, 0x00000002}, + {0x45515943, 0x04000000, 0x00000001}, + {0x45515A43, 0x01000000, 0x00000001}, + {0x45523342, 0x08000000, 0x00000005}, + {0x45523442, 0x02000000, 0x00000001}, + {0x45523443, 0x02000000, 0x00000001}, + {0x45523459, 0x04000000, 0x00000008}, + {0x45523542, 0x10000000, 0x00000001}, + {0x45523559, 0x04000000, 0x00000008}, + {0x45523641, 0x04000000, 0x00000003}, + {0x45523642, 0x08000000, 0x00000002}, + {0x45523659, 0x04000000, 0x00000008}, + {0x45523741, 0x02000000, 0x00000001}, + {0x45524141, 0x00800000, 0x00000008}, + {0x45524143, 0x01000000, 0x00000002}, + {0x45524159, 0x01000000, 0x00000001}, + {0x45524241, 0x04000000, 0x00000002}, + {0x45524254, 0x04000000, 0x00000001}, + {0x45524256, 0x02000000, 0x00000001}, + {0x45524259, 0x04000000, 0x00000001}, + {0x45524341, 0x02000000, 0x00000001}, + {0x45524343, 0x00800000, 0x00000002}, + {0x45524354, 0x00800000, 0x00000001}, + {0x45524441, 0x01000000, 0x00000002}, + {0x45524442, 0x04000000, 0x00000005}, + {0x45524443, 0x00800000, 0x00000001}, + {0x45524459, 0x00800000, 0x00000001}, + {0x45524541, 0x01000000, 0x00000002}, + {0x45524542, 0x02000000, 0x00000001}, + {0x45524543, 0x02000000, 0x00000003}, + {0x45524559, 0x04000000, 0x00000003}, + {0x45524641, 0x04000000, 0x00000001}, + {0x45524643, 0x08000000, 0x00000002}, + {0x45524659, 0x01000000, 0x00000001}, + {0x45524756, 0x04000000, 0x00000001}, + {0x45524841, 0x02000000, 0x00000002}, + {0x45524842, 0x02000000, 0x00000001}, + {0x45524859, 0x01000000, 0x00000002}, + {0x45524942, 0x01000000, 0x00000001}, + {0x45524943, 0x04000000, 0x00000002}, + {0x45524959, 0x04000000, 0x00000001}, + {0x45524A41, 0x08000000, 0x00000005}, + {0x45524A42, 0x01000000, 0x00000001}, + {0x45524A43, 0x08000000, 0x00000003}, + {0x45524B42, 0x02000000, 0x00000001}, + {0x45524C42, 0x10000000, 0x00000001}, + {0x45524C43, 0x04000000, 0x00000003}, + {0x45524C54, 0x08000000, 0x00000001}, + {0x45524C59, 0x01000000, 0x00000002}, + {0x45524D43, 0x02000000, 0x00000002}, + {0x45524E42, 0x04000000, 0x00000003}, + {0x45524E43, 0x04000000, 0x00000002}, + {0x45524F55, 0x08000000, 0x00000008}, + {0x45525041, 0x02000000, 0x00000002}, + {0x45525042, 0x00800000, 0x00000001}, + {0x45525043, 0x04000000, 0x00000002}, + {0x45525059, 0x02000000, 0x00000002}, + {0x45525143, 0x04000000, 0x00000002}, + {0x45525241, 0x02000000, 0x00000002}, + {0x45525243, 0x02000000, 0x00000005}, + {0x45525254, 0x01000000, 0x00000001}, + {0x45525259, 0x02000000, 0x00000002}, + {0x45525342, 0x01000000, 0x00000001}, + {0x45525359, 0x01000000, 0x00000005}, + {0x45525441, 0x01000000, 0x00000002}, + {0x45525443, 0x02000000, 0x00000003}, + {0x45525459, 0x04000000, 0x00000001}, + {0x45525542, 0x01000000, 0x00000001}, + {0x45525741, 0x02000000, 0x00000005}, + {0x45525759, 0x04000000, 0x00000001}, + {0x45525843, 0x04000000, 0x00000001}, + {0x45525942, 0x08000000, 0x00000001}, + {0x45525959, 0x04000000, 0x00000001}, + {0x45525A42, 0x00800000, 0x00000001}, + {0x45525A43, 0x02000000, 0x00000001}, + {0x45533241, 0x04000000, 0x00000002}, + {0x45533242, 0x08000000, 0x00000002}, + {0x45533243, 0x08000000, 0x00000004}, + {0x45533341, 0x02000000, 0x00000001}, + {0x45533459, 0x08000000, 0x00000008}, + {0x45533543, 0x08000000, 0x00000001}, + {0x45533559, 0x04000000, 0x00000008}, + {0x45533641, 0x04000000, 0x00000001}, + {0x45533642, 0x04000000, 0x00000001}, + {0x45533741, 0x02000000, 0x00000001}, + {0x45533759, 0x04000000, 0x00000008}, + {0x45533842, 0x04000000, 0x00000002}, + {0x45533859, 0x00800000, 0x00000000}, + {0x45534143, 0x02000000, 0x00000001}, + {0x45534154, 0x01000000, 0x00000001}, + {0x45534242, 0x02000000, 0x00000001}, + {0x45534243, 0x01000000, 0x00000002}, + {0x45534256, 0x02000000, 0x00000001}, + {0x45534342, 0x04000000, 0x00000002}, + {0x45534354, 0x04000000, 0x00000005}, + {0x45534359, 0x00800000, 0x00000001}, + {0x45534443, 0x08000000, 0x00000001}, + {0x45534542, 0x04000000, 0x00000001}, + {0x45534556, 0x04000000, 0x00000001}, + {0x45534641, 0x02000000, 0x00000002}, + {0x45534656, 0x08000000, 0x00000003}, + {0x45534743, 0x08000000, 0x00000001}, + {0x45534754, 0x02000000, 0x00000001}, + {0x45534759, 0x04000000, 0x00000003}, + {0x45534841, 0x02000000, 0x00000002}, + {0x45534844, 0x02000000, 0xFFFFFFFF}, + {0x45534859, 0x02000000, 0x00000003}, + {0x45534941, 0x01000000, 0x00000001}, + {0x45534959, 0x04000000, 0x00000002}, + {0x45534A42, 0x04000000, 0x00000003}, + {0x45534A56, 0x04000000, 0x00000003}, + {0x45534B54, 0x02000000, 0x00000002}, + {0x45534C42, 0x04000000, 0x00000001}, + {0x45534C54, 0x01000000, 0x00000001}, + {0x45534D43, 0x02000000, 0x00000003}, + {0x45534D54, 0x01000000, 0x00000001}, + {0x45534E41, 0x01000000, 0x00000001}, + {0x45534E42, 0x01000000, 0x00000001}, + {0x45534E43, 0x04000000, 0x00000002}, + {0x45534F41, 0x08000000, 0x00000005}, + {0x45534F43, 0x02000000, 0x00000001}, + {0x45535043, 0x04000000, 0x00000002}, + {0x45535143, 0x02000000, 0x00000001}, + {0x45535243, 0x00800000, 0x00000001}, + {0x45535341, 0x04000000, 0x00000002}, + {0x45535342, 0x01000000, 0x00000002}, + {0x45535359, 0x04000000, 0x00000003}, + {0x45535541, 0x04000000, 0x00000001}, + {0x45535543, 0x02000000, 0x00000001}, + {0x45535559, 0x00800000, 0x00000001}, + {0x45535641, 0x02000000, 0x00000002}, + {0x45535643, 0x02000000, 0x00000001}, + {0x45535659, 0x02000000, 0x00000003}, + {0x45535741, 0x01000000, 0x00000002}, + {0x45535759, 0x08000000, 0x00000003}, + {0x45535842, 0x04000000, 0x00000003}, + {0x45535843, 0x01000000, 0x00000001}, + {0x45535943, 0x04000000, 0x00000002}, + {0x45535A42, 0x00800000, 0x00000001}, + {0x45543241, 0x02000000, 0x00000001}, + {0x45543341, 0x02000000, 0x00000002}, + {0x45543343, 0x04000000, 0x00000003}, + {0x45543442, 0x01000000, 0x00000002}, + {0x45543541, 0x02000000, 0x00000005}, + {0x45543542, 0x00800000, 0x00000001}, + {0x45543543, 0x02000000, 0x00000005}, + {0x45543559, 0x00800000, 0x00000008}, + {0x45543641, 0x04000000, 0x00000001}, + {0x45543642, 0x04000000, 0x00000002}, + {0x45543643, 0x01000000, 0x00000002}, + {0x45543741, 0x02000000, 0x00000001}, + {0x45543841, 0x02000000, 0x00000002}, + {0x45544142, 0x04000000, 0x00000002}, + {0x45544143, 0x02000000, 0x00000002}, + {0x45544154, 0x02000000, 0x00000001}, + {0x45544156, 0x02000000, 0x00000001}, + {0x45544159, 0x01000000, 0x00000002}, + {0x45544241, 0x02000000, 0x00000001}, + {0x45544254, 0x01000000, 0x00000001}, + {0x45544256, 0x02000000, 0x00000002}, + {0x45544259, 0x08000000, 0x00000003}, + {0x45544341, 0x02000000, 0x00000001}, + {0x45544359, 0x02000000, 0x00000001}, + {0x45544454, 0x10000000, 0x00000008}, + {0x45544459, 0x04000000, 0x00000003}, + {0x45544559, 0x01000000, 0x00000001}, + {0x45544641, 0x00800000, 0x00000001}, + {0x45544659, 0x04000000, 0x00000005}, + {0x45544742, 0x08000000, 0x00000002}, + {0x45544759, 0x02000000, 0x00000001}, + {0x45544941, 0x00800000, 0x00000001}, + {0x45544943, 0x01000000, 0x00000001}, + {0x45544959, 0x01000000, 0x00000001}, + {0x45544A41, 0x02000000, 0x00000001}, + {0x45544A56, 0x04000000, 0x00000001}, + {0x45544B43, 0x04000000, 0x00000002}, + {0x45544C41, 0x00800000, 0x00000001}, + {0x45544C42, 0x00800000, 0x00000001}, + {0x45544C59, 0x08000000, 0x00000002}, + {0x45544D41, 0x04000000, 0x00000002}, + {0x45544D42, 0x08000000, 0x00000003}, + {0x45544D43, 0x02000000, 0x00000001}, + {0x45544D54, 0x04000000, 0x00000002}, + {0x45544E41, 0x04000000, 0x00000002}, + {0x45545041, 0x01000000, 0x00000002}, + {0x45545054, 0x08000000, 0x00000001}, + {0x45545059, 0x02000000, 0x00000005}, + {0x45545141, 0x01000000, 0x00000002}, + {0x45545143, 0x04000000, 0x00000003}, + {0x45545259, 0x02000000, 0x00000002}, + {0x45545341, 0x02000000, 0x00000001}, + {0x45545343, 0x04000000, 0x00000001}, + {0x45545359, 0x04000000, 0x00000001}, + {0x45545541, 0x01000000, 0x00000001}, + {0x45545543, 0x01000000, 0x00000001}, + {0x45545559, 0x04000000, 0x00000002}, + {0x45545659, 0x02000000, 0x00000001}, + {0x45545741, 0x00800000, 0x00000001}, + {0x45545743, 0x02000000, 0x00000001}, + {0x45545841, 0x00800000, 0x00000001}, + {0x45545942, 0x08000000, 0x00000002}, + {0x45545959, 0x01000000, 0x00000002}, + {0x45545A41, 0x01000000, 0x00000005}, + {0x45545A59, 0x01000000, 0x00000005}, + {0x45553242, 0x02000000, 0x00000001}, + {0x45553342, 0x02000000, 0x00000002}, + {0x45553459, 0x02000000, 0x00000008}, + {0x45553541, 0x02000000, 0x00000005}, + {0x45553542, 0x04000000, 0x00000002}, + {0x45553543, 0x02000000, 0x00000002}, + {0x45553559, 0x01000000, 0x00000000}, + {0x45553659, 0x01000000, 0x00000000}, + {0x45553743, 0x02000000, 0x00000001}, + {0x45554159, 0x04000000, 0x00000003}, + {0x45554241, 0x04000000, 0x00000005}, + {0x45554242, 0x04000000, 0x00000003}, + {0x45554259, 0x08000000, 0x00000003}, + {0x45554341, 0x04000000, 0x00000005}, + {0x45554342, 0x01000000, 0x00000001}, + {0x45554359, 0x00400000, 0x00000003}, + {0x45554442, 0x02000000, 0x00000001}, + {0x45554443, 0x01000000, 0x00000003}, + {0x45554454, 0x00800000, 0x00000001}, + {0x45554543, 0x04000000, 0x00000002}, + {0x45554641, 0x01000000, 0x00000003}, + {0x45554642, 0x01000000, 0x00000001}, + {0x45554854, 0x02000000, 0x00000001}, + {0x45554859, 0x00800000, 0x00000001}, + {0x45554942, 0x01000000, 0x00000001}, + {0x45554943, 0x04000000, 0x00000002}, + {0x45554A59, 0x04000000, 0x00000002}, + {0x45554B41, 0x04000000, 0x00000001}, + {0x45554B42, 0x08000000, 0x00000005}, + {0x45554B56, 0x04000000, 0x00000001}, + {0x45554C54, 0x04000000, 0x00000001}, + {0x45554D41, 0x00800000, 0x00000001}, + {0x45554D42, 0x04000000, 0x00000001}, + {0x45554D43, 0x01000000, 0x00000003}, + {0x45554D59, 0x04000000, 0x00000002}, + {0x45554E41, 0x01000000, 0x00000001}, + {0x45554F43, 0x00800000, 0x00000003}, + {0x45555043, 0x08000000, 0x00000006}, + {0x45555054, 0x01000000, 0x00000001}, + {0x45555159, 0x08000000, 0x00000003}, + {0x45555242, 0x01000000, 0x00000001}, + {0x45555341, 0x04000000, 0x00000003}, + {0x45555343, 0x02000000, 0x00000001}, + {0x45555442, 0x04000000, 0x00000002}, + {0x45555741, 0x02000000, 0x00000001}, + {0x45555742, 0x01000000, 0x00000002}, + {0x45555743, 0x04000000, 0x00000001}, + {0x45555841, 0x02000000, 0x00000001}, + {0x45555843, 0x08000000, 0x00000002}, + {0x45555943, 0x01000000, 0x00000002}, + {0x45555959, 0x04000000, 0x00000001}, + {0x45555A42, 0x02000000, 0x00000002}, + {0x45555A56, 0x02000000, 0x00000002}, + {0x45563241, 0x00800000, 0x00000001}, + {0x45563242, 0x01000000, 0x00000001}, + {0x45563341, 0x04000000, 0x00000003}, + {0x45563342, 0x02000000, 0x00000001}, + {0x45563542, 0x04000000, 0x00000001}, + {0x45563559, 0x00800000, 0x00000008}, + {0x45563642, 0x00800000, 0x00000001}, + {0x45563643, 0x02000000, 0x00000001}, + {0x45563742, 0x00800000, 0x00000001}, + {0x45564142, 0x04000000, 0x00000001}, + {0x45564143, 0x02000000, 0x00000002}, + {0x45564156, 0x04000000, 0x00000001}, + {0x45564159, 0x04000000, 0x00000002}, + {0x45564242, 0x00800000, 0x00000001}, + {0x45564256, 0x02000000, 0x00000001}, + {0x45564259, 0x02000000, 0x00000002}, + {0x45564341, 0x04000000, 0x00000002}, + {0x45564359, 0x01000000, 0x00000003}, + {0x45564441, 0x01000000, 0x00000001}, + {0x45564442, 0x02000000, 0x00000001}, + {0x45564443, 0x01000000, 0x00000001}, + {0x45564454, 0x08000000, 0x00000003}, + {0x45564459, 0x00800000, 0x00000002}, + {0x45564641, 0x04000000, 0x00000001}, + {0x45564643, 0x02000000, 0x00000002}, + {0x45564741, 0x02000000, 0x00000002}, + {0x45564841, 0x01000000, 0x00000001}, + {0x45564842, 0x02000000, 0x00000001}, + {0x45564843, 0x02000000, 0x00000003}, + {0x45564854, 0x04000000, 0x00000001}, + {0x45564942, 0x00800000, 0x00000001}, + {0x45564959, 0x08000000, 0x00000003}, + {0x45564A59, 0x01000000, 0x00000002}, + {0x45564C41, 0x01000000, 0x00000002}, + {0x45564C54, 0x02000000, 0x00000002}, + {0x45564D41, 0x04000000, 0x00000001}, + {0x45564D42, 0x00800000, 0x00000001}, + {0x45564D43, 0x00800000, 0x00000001}, + {0x45564D59, 0x00800000, 0x00000001}, + {0x45564E43, 0x10000000, 0x00000005}, + {0x45564F59, 0x00800000, 0x00000001}, + {0x45565041, 0x00800000, 0x00000002}, + {0x45565042, 0x00800000, 0x00000004}, + {0x45565043, 0x04000000, 0x00000002}, + {0x45565056, 0x04000000, 0x00000002}, + {0x45565059, 0x04000000, 0x00000001}, + {0x45565141, 0x01000000, 0x00000002}, + {0x45565143, 0x04000000, 0x00000001}, + {0x45565159, 0x01000000, 0x00000001}, + {0x45565241, 0x02000000, 0x00000003}, + {0x45565242, 0x01000000, 0x00000002}, + {0x45565259, 0x02000000, 0x00000005}, + {0x45565341, 0x00800000, 0x00000001}, + {0x45565342, 0x02000000, 0x00000001}, + {0x45565343, 0x02000000, 0x00000005}, + {0x45565441, 0x01000000, 0x00000001}, + {0x45565442, 0x02000000, 0x00000002}, + {0x45565459, 0x08000000, 0x00000003}, + {0x45565642, 0x01000000, 0x00000002}, + {0x45565741, 0x01000000, 0x00000001}, + {0x45565742, 0x02000000, 0x00000001}, + {0x45565756, 0x04000000, 0x00000001}, + {0x45565841, 0x04000000, 0x00000003}, + {0x45565842, 0x02000000, 0x00000001}, + {0x45565A41, 0x00800000, 0x00000001}, + {0x45565A42, 0x04000000, 0x00000002}, + {0x45565A43, 0x02000000, 0x00000001}, + {0x45573241, 0x04000000, 0x00000001}, + {0x45573259, 0x04000000, 0x00000008}, + {0x45573341, 0x04000000, 0x00000002}, + {0x45573342, 0x04000000, 0x00000002}, + {0x45573543, 0x01000000, 0x00000002}, + {0x45573641, 0x02000000, 0x00000002}, + {0x45573642, 0x08000000, 0x00000002}, + {0x45573643, 0x02000000, 0x00000002}, + {0x45573742, 0x01000000, 0x00000002}, + {0x45573759, 0x00800000, 0x00000001}, + {0x45574159, 0x04000000, 0x00000002}, + {0x45574259, 0x01000000, 0x00000002}, + {0x45574343, 0x02000000, 0x00000002}, + {0x45574354, 0x02000000, 0x00000001}, + {0x45574356, 0x02000000, 0x00000002}, + {0x45574442, 0x02000000, 0x00000001}, + {0x45574459, 0x02000000, 0x00000005}, + {0x45574542, 0x04000000, 0x00000002}, + {0x45574641, 0x01000000, 0x00000001}, + {0x45574643, 0x01000000, 0x00000001}, + {0x45574659, 0x00800000, 0x00000001}, + {0x45574741, 0x01000000, 0x00000002}, + {0x45574743, 0x00800000, 0x00000001}, + {0x45574759, 0x00800000, 0x00000001}, + {0x45574842, 0x00800000, 0x00000001}, + {0x45574856, 0x04000000, 0x00000002}, + {0x45574859, 0x02000000, 0x00000001}, + {0x45574942, 0x02000000, 0x00000002}, + {0x45574A43, 0x00800000, 0x00000001}, + {0x45574A56, 0x02000000, 0x00000003}, + {0x45574B41, 0x04000000, 0x00000002}, + {0x45574B42, 0x00800000, 0x00000002}, + {0x45574B59, 0x08000000, 0x00000003}, + {0x45574C41, 0x02000000, 0x00000001}, + {0x45574C43, 0x10000000, 0x00000002}, + {0x45574D41, 0x04000000, 0x00000002}, + {0x45574D49, 0x04000000, 0x00000007}, + {0x45574E41, 0x02000000, 0x00000002}, + {0x45574E59, 0x02000000, 0x00000001}, + {0x45574F41, 0x00800000, 0x00000001}, + {0x45575041, 0x02000000, 0x00000001}, + {0x45575042, 0x01000000, 0x00000001}, + {0x45575043, 0x04000000, 0x00000002}, + {0x45575141, 0x01000000, 0x00000001}, + {0x45575243, 0x02000000, 0x00000002}, + {0x45575254, 0x02000000, 0x00000002}, + {0x45575259, 0x02000000, 0x00000005}, + {0x45575341, 0x02000000, 0x00000001}, + {0x45575343, 0x04000000, 0x00000001}, + {0x45575359, 0x00800000, 0x00000001}, + {0x45575441, 0x02000000, 0x00000002}, + {0x45575442, 0x02000000, 0x00000001}, + {0x45575443, 0x08000000, 0x00000001}, + {0x45575641, 0x02000000, 0x00000002}, + {0x45575741, 0x02000000, 0x00000001}, + {0x45575842, 0x00800000, 0x00000001}, + {0x45575941, 0x02000000, 0x00000002}, + {0x45575943, 0x01000000, 0x00000001}, + {0x45575959, 0x02000000, 0x00000001}, + {0x45575A41, 0x02000000, 0x00000002}, + {0x45583242, 0x02000000, 0x00000002}, + {0x45583341, 0x04000000, 0x00000001}, + {0x45583342, 0x01000000, 0x00000001}, + {0x45583659, 0x00800000, 0x00000000}, + {0x45584154, 0x00800000, 0x00000001}, + {0x45584241, 0x02000000, 0x00000002}, + {0x45584242, 0x00800000, 0x00000001}, + {0x45584243, 0x01000000, 0x00000003}, + {0x45584259, 0x00800000, 0x00000001}, + {0x45584341, 0x01000000, 0x00000003}, + {0x45584343, 0x01000000, 0x00000003}, + {0x45584359, 0x02000000, 0x00000002}, + {0x45584456, 0x04000000, 0x00000001}, + {0x45584542, 0x01000000, 0x00000001}, + {0x45584559, 0x02000000, 0x00000002}, + {0x45584641, 0x08000000, 0x00000003}, + {0x45584642, 0x04000000, 0x00000002}, + {0x45584643, 0x01000000, 0x00000001}, + {0x45584659, 0x02000000, 0x00000001}, + {0x45584741, 0x08000000, 0x00000003}, + {0x45584759, 0x08000000, 0x00000002}, + {0x45584841, 0x00800000, 0x00000001}, + {0x45584843, 0x02000000, 0x00000003}, + {0x45584859, 0x01000000, 0x00000001}, + {0x45584A43, 0x01000000, 0x00000001}, + {0x45584B43, 0x01000000, 0x00000001}, + {0x45584C41, 0x02000000, 0x00000001}, + {0x45584C59, 0x00800000, 0x00000001}, + {0x45584D41, 0x01000000, 0x00000001}, + {0x45584D42, 0x02000000, 0x00000001}, + {0x45584D43, 0x01000000, 0x00000001}, + {0x45584D59, 0x00800000, 0x00000001}, + {0x45584E41, 0x02000000, 0x00000001}, + {0x45584E42, 0x04000000, 0x00000002}, + {0x45584E59, 0x00800000, 0x00000002}, + {0x45585159, 0x01000000, 0x00000001}, + {0x45585343, 0x01000000, 0x00000001}, + {0x45585359, 0x01000000, 0x00000001}, + {0x45585441, 0x01000000, 0x00000002}, + {0x45585442, 0x04000000, 0x00000001}, + {0x45585443, 0x01000000, 0x00000001}, + {0x45585543, 0x04000000, 0x00000001}, + {0x45585559, 0x04000000, 0x00000003}, + {0x45585641, 0x01000000, 0x00000001}, + {0x45585643, 0x04000000, 0x00000002}, + {0x45585741, 0x01000000, 0x00000002}, + {0x45585842, 0x02000000, 0x00000001}, + {0x45585859, 0x04000000, 0x00000002}, + {0x45585941, 0x08000000, 0x00000005}, + {0x45585942, 0x10000000, 0x00000003}, + {0x45585943, 0x02000000, 0x00000001}, + {0x45585A42, 0x02000000, 0x00000001}, + {0x45585A59, 0x04000000, 0x00000002}, + {0x45593341, 0x04000000, 0x00000003}, + {0x45593342, 0x02000000, 0x00000001}, + {0x45593459, 0x01000000, 0x00000008}, + {0x45593559, 0x01000000, 0x00000008}, + {0x45593641, 0x01000000, 0x00000002}, + {0x45593742, 0x01000000, 0x00000002}, + {0x45593759, 0x00800000, 0x00000008}, + {0x45594143, 0x02000000, 0x00000001}, + {0x45594159, 0x02000000, 0x00000001}, + {0x45594242, 0x00800000, 0x00000001}, + {0x45594243, 0x02000000, 0x00000001}, + {0x45594259, 0x02000000, 0x00000001}, + {0x45594343, 0x01000000, 0x00000001}, + {0x45594354, 0x04000000, 0x00000002}, + {0x45594359, 0x00800000, 0x00000001}, + {0x45594442, 0x04000000, 0x00000002}, + {0x45594542, 0x01000000, 0x00000001}, + {0x45594543, 0x02000000, 0x00000001}, + {0x45594641, 0x04000000, 0x00000001}, + {0x45594659, 0x04000000, 0x00000005}, + {0x45594741, 0x04000000, 0x00000005}, + {0x45594756, 0x02000000, 0x00000002}, + {0x45594842, 0x01000000, 0x00000001}, + {0x45594843, 0x01000000, 0x00000001}, + {0x45594941, 0x02000000, 0x00000001}, + {0x45594943, 0x04000000, 0x00000002}, + {0x45594959, 0x01000000, 0x00000001}, + {0x45594B41, 0x01000000, 0x00000003}, + {0x45594B42, 0x02000000, 0x00000002}, + {0x45594C41, 0x04000000, 0x00000001}, + {0x45594C59, 0x02000000, 0x00000002}, + {0x45594D42, 0x01000000, 0x00000002}, + {0x45594D56, 0x04000000, 0x00000001}, + {0x45594D59, 0x08000000, 0x00000002}, + {0x45594E41, 0x04000000, 0x00000003}, + {0x45594E42, 0x04000000, 0x00000001}, + {0x45594E43, 0x04000000, 0x00000002}, + {0x45594E59, 0x00800000, 0x00000001}, + {0x45594F41, 0x01000000, 0x00000002}, + {0x45594F43, 0x04000000, 0x00000002}, + {0x45595041, 0x02000000, 0x00000002}, + {0x45595042, 0x00800000, 0x00000001}, + {0x45595142, 0x04000000, 0x00000001}, + {0x45595241, 0x02000000, 0x00000002}, + {0x45595243, 0x01000000, 0x00000001}, + {0x45595254, 0x02000000, 0x00000001}, + {0x45595342, 0x02000000, 0x00000002}, + {0x45595343, 0x01000000, 0x00000001}, + {0x45595344, 0x02000000, 0x00000001}, + {0x45595359, 0x01000000, 0x00000001}, + {0x45595543, 0x02000000, 0x00000001}, + {0x45595642, 0x08000000, 0x00000001}, + {0x45595842, 0x04000000, 0x00000002}, + {0x45595859, 0x00800000, 0x00000001}, + {0x45595941, 0x01000000, 0x00000002}, + {0x45595942, 0x08000000, 0x00000003}, + {0x45595A41, 0x04000000, 0x00000002}, + {0x45595A42, 0x00800000, 0x00000001}, + {0x45595A59, 0x01000000, 0x00000002}, + {0x455A3441, 0x00800000, 0x00000001}, + {0x455A3443, 0x04000000, 0x00000002}, + {0x455A3541, 0x04000000, 0x00000001}, + {0x455A3542, 0x00800000, 0x00000001}, + {0x455A3543, 0x00800000, 0x00000001}, + {0x455A3642, 0x04000000, 0x00000003}, + {0x455A3659, 0x08000000, 0x00000000}, + {0x455A3742, 0x04000000, 0x00000001}, + {0x455A4159, 0x01000000, 0x00000001}, + {0x455A4241, 0x08000000, 0x00000003}, + {0x455A4242, 0x01000000, 0x00000001}, + {0x455A4259, 0x01000000, 0x00000001}, + {0x455A4341, 0x01000000, 0x00000001}, + {0x455A4343, 0x00800000, 0x00000001}, + {0x455A4354, 0x04000000, 0x00000002}, + {0x455A4441, 0x02000000, 0x00000002}, + {0x455A4442, 0x04000000, 0x00000003}, + {0x455A4443, 0x04000000, 0x00000002}, + {0x455A4641, 0x04000000, 0x00000001}, + {0x455A4642, 0x00800000, 0x00000001}, + {0x455A4656, 0x02000000, 0x00000001}, + {0x455A4742, 0x01000000, 0x00000002}, + {0x455A4841, 0x04000000, 0x00000001}, + {0x455A4842, 0x02000000, 0x00000003}, + {0x455A4859, 0x04000000, 0x00000002}, + {0x455A4941, 0x01000000, 0x00000002}, + {0x455A4943, 0x02000000, 0x00000001}, + {0x455A4959, 0x04000000, 0x00000002}, + {0x455A4A59, 0x04000000, 0x00000005}, + {0x455A4B43, 0x01000000, 0x00000005}, + {0x455A4C43, 0x04000000, 0x00000001}, + {0x455A4C59, 0x08000000, 0x00000002}, + {0x455A4D56, 0x04000000, 0x00000001}, + {0x455A4D59, 0x01000000, 0x00000001}, + {0x455A4E41, 0x01000000, 0x00000001}, + {0x455A4E59, 0x04000000, 0x00000002}, + {0x455A4F41, 0x01000000, 0x00000002}, + {0x455A4F42, 0x02000000, 0x00000001}, + {0x455A4F43, 0x08000000, 0x00000002}, + {0x455A5042, 0x00800000, 0x00000001}, + {0x455A5043, 0x02000000, 0x00000002}, + {0x455A5143, 0x02000000, 0x00000001}, + {0x455A5241, 0x04000000, 0x00000002}, + {0x455A5242, 0x04000000, 0x00000003}, + {0x455A5243, 0x00800000, 0x00000002}, + {0x455A5254, 0x02000000, 0x00000002}, + {0x455A5341, 0x01000000, 0x00000001}, + {0x455A5343, 0x02000000, 0x00000005}, + {0x455A5359, 0x08000000, 0x00000001}, + {0x455A5442, 0x02000000, 0x00000001}, + {0x455A5443, 0x02000000, 0x00000003}, + {0x455A5459, 0x02000000, 0x00000001}, + {0x455A5541, 0x04000000, 0x00000005}, + {0x455A5543, 0x04000000, 0x00000001}, + {0x455A5759, 0x04000000, 0x00000001}, + {0x455A5A42, 0x00800000, 0x00000001}, + {0x46323643, 0x04000000, 0x00000001}, + {0x46324543, 0x02000000, 0x00000001}, + {0x46324C42, 0x01000000, 0x00000001}, + {0x46324E42, 0x01000000, 0x00000002}, + {0x46325959, 0x00800000, 0x00000001}, + {0x46334343, 0x01000000, 0x00000001}, + {0x46334E42, 0x01000000, 0x00000002}, + {0x46335141, 0x04000000, 0x00000002}, + {0x46335159, 0x04000000, 0x00000002}, + {0x46335742, 0x08000000, 0x00000002}, + {0x46344259, 0x02000000, 0x00000001}, + {0x46344559, 0x02000000, 0x00000001}, + {0x46344E42, 0x01000000, 0x00000002}, + {0x46354243, 0x01000000, 0x00000001}, + {0x46354841, 0x02000000, 0x00000002}, + {0x46354E42, 0x01000000, 0x00000002}, + {0x46363443, 0x00800000, 0x00000001}, + {0x46364E42, 0x01000000, 0x00000002}, + {0x46373343, 0x02000000, 0x00000001}, + {0x46373443, 0x02000000, 0x00000001}, + {0x46373543, 0x02000000, 0x00000001}, + {0x46373742, 0x00800000, 0x00000001}, + {0x46374559, 0x00800000, 0x00000001}, + {0x46375443, 0x00800000, 0x00000002}, + {0x46375959, 0x01000000, 0x00000001}, + {0x46383643, 0x02000000, 0x00000001}, + {0x46383742, 0x00800000, 0x00000001}, + {0x46384343, 0x02000000, 0x00000001}, + {0x46384543, 0x02000000, 0x00000001}, + {0x46384C59, 0x01000000, 0x00000001}, + {0x46394341, 0x04000000, 0x00000001}, + {0x46394343, 0x02000000, 0x00000001}, + {0x46394943, 0x01000000, 0x00000002}, + {0x46395342, 0x00800000, 0x00000001}, + {0x46395942, 0x00800000, 0x00000001}, + {0x46413343, 0x00800000, 0x00000001}, + {0x46414441, 0x04000000, 0x00000006}, + {0x46414759, 0x01000000, 0x00000001}, + {0x46414C59, 0x00800000, 0x00000002}, + {0x46414E43, 0x02000000, 0x00000001}, + {0x46414F43, 0x00800000, 0x00000001}, + {0x46415041, 0x04000000, 0x00000006}, + {0x46415249, 0x10000000, 0x00000006}, + {0x46415843, 0x00800000, 0x00000001}, + {0x46423542, 0x04000000, 0x00000002}, + {0x46424354, 0x08000000, 0x00000001}, + {0x46424542, 0x10000000, 0x00000003}, + {0x46424659, 0x01000000, 0x00000001}, + {0x46424A42, 0x04000000, 0x00000001}, + {0x46424D43, 0x01000000, 0x00000001}, + {0x46424F43, 0x00800000, 0x00000001}, + {0x46425042, 0x01000000, 0x00000001}, + {0x46425043, 0x01000000, 0x00000001}, + {0x46425249, 0x10000000, 0x00000006}, + {0x46425254, 0x00800000, 0x00000001}, + {0x46425843, 0x00800000, 0x00000001}, + {0x46433243, 0x00800000, 0x00000001}, + {0x46434143, 0x01000000, 0x00000002}, + {0x46434A42, 0x04000000, 0x00000002}, + {0x46435843, 0x00800000, 0x00000001}, + {0x46435943, 0x02000000, 0x00000002}, + {0x46444143, 0x01000000, 0x00000002}, + {0x46444359, 0x02000000, 0x00000001}, + {0x46445054, 0x08000000, 0x00000001}, + {0x46445249, 0x20000000, 0x00000006}, + {0x46445443, 0x04000000, 0x00000002}, + {0x46445641, 0x01000000, 0x00000002}, + {0x46445843, 0x00800000, 0x00000001}, + {0x46454143, 0x01000000, 0x00000002}, + {0x46454542, 0x10000000, 0x00000003}, + {0x46454543, 0x00800000, 0x00000001}, + {0x46454559, 0x10000000, 0x00000003}, + {0x46454741, 0x01000000, 0x00000001}, + {0x46454959, 0x02000000, 0x00000002}, + {0x46455249, 0x20000000, 0x00000006}, + {0x46455542, 0x02000000, 0x00000001}, + {0x46455843, 0x00800000, 0x00000001}, + {0x46464143, 0x01000000, 0x00000001}, + {0x46464459, 0x01000000, 0x00000001}, + {0x46464A43, 0x01000000, 0x00000001}, + {0x46464B59, 0x02000000, 0x00000001}, + {0x46464C42, 0x10000000, 0x00000003}, + {0x46464D43, 0x00800000, 0x00000001}, + {0x46465059, 0x02000000, 0x00000001}, + {0x46465359, 0x04000000, 0x00000001}, + {0x46465843, 0x00800000, 0x00000001}, + {0x46465959, 0x00800000, 0x00000001}, + {0x46474D41, 0x01000000, 0x00000001}, + {0x46474D43, 0x04000000, 0x00000001}, + {0x46475049, 0x08000000, 0x00000006}, + {0x46483842, 0x04000000, 0x00000002}, + {0x46484143, 0x00800000, 0x00000001}, + {0x46484259, 0x02000000, 0x00000002}, + {0x46484A42, 0x01000000, 0x00000001}, + {0x46495443, 0x02000000, 0x00000002}, + {0x464A3343, 0x10000000, 0x00000003}, + {0x464A3743, 0x00800000, 0x00000001}, + {0x464A4754, 0x00800000, 0x00000001}, + {0x464A4959, 0x04000000, 0x00000002}, + {0x464A4F41, 0x02000000, 0x00000002}, + {0x464A4F42, 0x04000000, 0x00000002}, + {0x464A4F43, 0x00800000, 0x00000001}, + {0x464A5641, 0x04000000, 0x00000002}, + {0x464A5759, 0x00800000, 0x00000002}, + {0x464B4159, 0x08000000, 0x00000002}, + {0x464B4356, 0x08000000, 0x00000002}, + {0x464B4841, 0x04000000, 0x00000003}, + {0x464B5049, 0x08000000, 0x00000006}, + {0x464C4343, 0x02000000, 0x00000002}, + {0x464C4359, 0x01000000, 0x00000002}, + {0x464C4842, 0x04000000, 0x00000002}, + {0x464C4D59, 0x00800000, 0x00000001}, + {0x464C4F41, 0x00800000, 0x00000001}, + {0x464D4443, 0x00800000, 0x00000001}, + {0x464D4C54, 0x08000000, 0x00000001}, + {0x464D5141, 0x00800000, 0x00000001}, + {0x464E4243, 0x02000000, 0x00000001}, + {0x464E4259, 0x04000000, 0x00000007}, + {0x464E5243, 0x01000000, 0x00000001}, + {0x464E5759, 0x02000000, 0x00000001}, + {0x464F4359, 0x04000000, 0x00000001}, + {0x46504242, 0x00800000, 0x00000001}, + {0x46504A59, 0x01000000, 0x00000001}, + {0x46504B43, 0x02000000, 0x00000001}, + {0x46504C43, 0x04000000, 0x00000003}, + {0x46504F42, 0x01000000, 0x00000001}, + {0x46505041, 0x01000000, 0x00000002}, + {0x46505942, 0x02000000, 0x00000001}, + {0x46505A55, 0x08000000, 0x00000003}, + {0x46514343, 0x02000000, 0x00000001}, + {0x46514C59, 0x04000000, 0x00000001}, + {0x46514D43, 0x02000000, 0x00000001}, + {0x46524359, 0x02000000, 0x00000001}, + {0x46525141, 0x01000000, 0x00000002}, + {0x46525359, 0x01000000, 0x00000005}, + {0x46533341, 0x02000000, 0x00000001}, + {0x46534343, 0x02000000, 0x00000001}, + {0x46534959, 0x02000000, 0x00000002}, + {0x46534F41, 0x08000000, 0x00000005}, + {0x46535541, 0x04000000, 0x00000001}, + {0x46543242, 0x00800000, 0x00000001}, + {0x46543743, 0x01000000, 0x00000002}, + {0x46544159, 0x01000000, 0x00000002}, + {0x46544443, 0x02000000, 0x00000001}, + {0x46544C43, 0x00800000, 0x00000001}, + {0x46544C59, 0x08000000, 0x00000002}, + {0x46545643, 0x02000000, 0x00000001}, + {0x46554243, 0x01000000, 0x00000001}, + {0x46554259, 0x08000000, 0x00000003}, + {0x46554559, 0x01000000, 0x00000001}, + {0x46554743, 0x01000000, 0x00000002}, + {0x46554F59, 0x02000000, 0x00000001}, + {0x46555043, 0x08000000, 0x00000006}, + {0x46555643, 0x01000000, 0x00000001}, + {0x46563742, 0x01000000, 0x00000001}, + {0x46564559, 0x01000000, 0x00000001}, + {0x46564643, 0x02000000, 0x00000002}, + {0x46564859, 0x04000000, 0x00000001}, + {0x46564E43, 0x10000000, 0x00000005}, + {0x46565841, 0x04000000, 0x00000003}, + {0x46573743, 0x00800000, 0x00000001}, + {0x46574243, 0x02000000, 0x00000001}, + {0x46574356, 0x02000000, 0x00000002}, + {0x46574959, 0x04000000, 0x00000001}, + {0x46575959, 0x02000000, 0x00000001}, + {0x46583543, 0x02000000, 0x00000001}, + {0x46583743, 0x00800000, 0x00000001}, + {0x46585059, 0x00800000, 0x00000003}, + {0x46585441, 0x01000000, 0x00000002}, + {0x46585959, 0x01000000, 0x00000001}, + {0x46593743, 0x00800000, 0x00000001}, + {0x46594342, 0x04000000, 0x00000001}, + {0x46594442, 0x04000000, 0x00000002}, + {0x46594443, 0x02000000, 0x00000002}, + {0x46594641, 0x04000000, 0x00000001}, + {0x46594642, 0x01000000, 0x00000001}, + {0x46594A59, 0x00800000, 0x00000001}, + {0x46594C41, 0x04000000, 0x00000001}, + {0x46595559, 0x00800000, 0x00000001}, + {0x46595A41, 0x04000000, 0x00000002}, + {0x465A3659, 0x08000000, 0x00000008}, + {0x465A3743, 0x00800000, 0x00000001}, + {0x465A4142, 0x04000000, 0x00000001}, + {0x465A4641, 0x04000000, 0x00000001}, + {0x465A4F41, 0x01000000, 0x00000002}, + {0x465A5359, 0x08000000, 0x00000001}, + {0x474C4443, 0x02000000, 0x00000004}, + {0x47595543, 0x02000000, 0x00000001}, + {0x48334B54, 0x01000000, 0x00000001}, + {0x48335159, 0x04000000, 0x00000002}, + {0x48344259, 0x02000000, 0x00000001}, + {0x48344559, 0x02000000, 0x00000001}, + {0x48354841, 0x02000000, 0x00000002}, + {0x48373642, 0x01000000, 0x00000002}, + {0x48374E43, 0x01000000, 0x00000002}, + {0x48384C59, 0x01000000, 0x00000001}, + {0x48414B54, 0x02000000, 0x00000001}, + {0x48414C59, 0x00800000, 0x00000002}, + {0x48434842, 0x01000000, 0x00000001}, + {0x48435943, 0x02000000, 0x00000002}, + {0x48454E42, 0x02000000, 0x00000001}, + {0x48455142, 0x02000000, 0x00000002}, + {0x48464B59, 0x02000000, 0x00000001}, + {0x48464C42, 0x10000000, 0x00000003}, + {0x48464E42, 0x02000000, 0x00000001}, + {0x48474D41, 0x01000000, 0x00000001}, + {0x48474D43, 0x04000000, 0x00000001}, + {0x48494759, 0x00800000, 0x00000002}, + {0x48495959, 0x01000000, 0x00000001}, + {0x484A3343, 0x10000000, 0x00000003}, + {0x484A4D43, 0x01000000, 0x00000002}, + {0x484B5242, 0x00800000, 0x00000002}, + {0x484C3542, 0x01000000, 0x00000001}, + {0x484C4842, 0x04000000, 0x00000002}, + {0x484C5143, 0x00800000, 0x00000002}, + {0x484C5442, 0x00800000, 0x00000002}, + {0x484C5459, 0x00800000, 0x00000002}, + {0x484D5742, 0x01000000, 0x00000001}, + {0x484E4242, 0x00800000, 0x00000002}, + {0x48504A59, 0x01000000, 0x00000001}, + {0x48505443, 0x00800000, 0x00000002}, + {0x48515443, 0x00800000, 0x00000001}, + {0x48533341, 0x02000000, 0x00000001}, + {0x48544C59, 0x08000000, 0x00000002}, + {0x48565742, 0x02000000, 0x00000001}, + {0x48565841, 0x04000000, 0x00000003}, + {0x48575143, 0x02000000, 0x00000008}, + {0x48594559, 0x01000000, 0x00000001}, + {0x48595759, 0x04000000, 0x00000002}, + {0x485A3243, 0x00800000, 0x00000002}, + {0x485A4841, 0x04000000, 0x00000001}, + {0x485A4942, 0x01000000, 0x00000001}, + {0x49323643, 0x04000000, 0x00000001}, + {0x49334943, 0x04000000, 0x00000001}, + {0x49335141, 0x04000000, 0x00000002}, + {0x49335159, 0x04000000, 0x00000002}, + {0x49335742, 0x08000000, 0x00000002}, + {0x49344259, 0x02000000, 0x00000001}, + {0x49354841, 0x02000000, 0x00000002}, + {0x49364959, 0x04000000, 0x00000002}, + {0x49384C59, 0x01000000, 0x00000001}, + {0x49394341, 0x04000000, 0x00000001}, + {0x49413643, 0x00800000, 0x00000001}, + {0x49414441, 0x04000000, 0x00000006}, + {0x49414C59, 0x00800000, 0x00000002}, + {0x49415041, 0x04000000, 0x00000006}, + {0x49415249, 0x10000000, 0x00000006}, + {0x49424542, 0x10000000, 0x00000003}, + {0x49425249, 0x10000000, 0x00000006}, + {0x49434A42, 0x04000000, 0x00000002}, + {0x49434D43, 0x02000000, 0x00000002}, + {0x49435141, 0x02000000, 0x00000002}, + {0x49435943, 0x02000000, 0x00000002}, + {0x49445249, 0x20000000, 0x00000006}, + {0x49445641, 0x01000000, 0x00000002}, + {0x49454542, 0x10000000, 0x00000003}, + {0x49454559, 0x10000000, 0x00000003}, + {0x49455249, 0x20000000, 0x00000006}, + {0x49464B59, 0x02000000, 0x00000001}, + {0x49464C42, 0x10000000, 0x00000003}, + {0x49465359, 0x04000000, 0x00000001}, + {0x49474354, 0x04000000, 0x00000001}, + {0x49474D41, 0x01000000, 0x00000001}, + {0x49474D43, 0x04000000, 0x00000001}, + {0x49475049, 0x08000000, 0x00000006}, + {0x49483642, 0x02000000, 0x00000001}, + {0x494A3343, 0x10000000, 0x00000003}, + {0x494A4D54, 0x02000000, 0x00000001}, + {0x494A4F41, 0x02000000, 0x00000002}, + {0x494A5641, 0x04000000, 0x00000002}, + {0x494B4356, 0x08000000, 0x00000002}, + {0x494B5049, 0x08000000, 0x00000006}, + {0x494B5356, 0x04000000, 0x00000001}, + {0x494C4C43, 0x00800000, 0x00000002}, + {0x494C5842, 0x01000000, 0x00000002}, + {0x494D4359, 0x02000000, 0x00000001}, + {0x494E5243, 0x01000000, 0x00000001}, + {0x494F4359, 0x04000000, 0x00000001}, + {0x49505A55, 0x08000000, 0xFFFFFFFF}, + {0x49525359, 0x01000000, 0x00000005}, + {0x49525643, 0x00800000, 0x00000001}, + {0x49533341, 0x02000000, 0x00000001}, + {0x49534F41, 0x08000000, 0x00000005}, + {0x49535541, 0x04000000, 0x00000001}, + {0x49544C59, 0x08000000, 0x00000002}, + {0x49554259, 0x08000000, 0x00000003}, + {0x49555043, 0x08000000, 0x00000006}, + {0x49564E43, 0x10000000, 0x00000005}, + {0x49565841, 0x04000000, 0x00000003}, + {0x49574342, 0x01000000, 0x00000001}, + {0x49585059, 0x00800000, 0x00000003}, + {0x49594641, 0x04000000, 0x00000001}, + {0x49594C41, 0x04000000, 0x00000001}, + {0x49595543, 0x02000000, 0x00000001}, + {0x495A3659, 0x08000000, 0x00000008}, + {0x495A4341, 0x01000000, 0x00000001}, + {0x495A4641, 0x04000000, 0x00000001}, + {0x495A4F41, 0x01000000, 0x00000002}, + {0x495A5359, 0x08000000, 0x00000001}, + {0x4A323242, 0x08000000, 0x00000003}, + {0x4A323243, 0x04000000, 0x00000002}, + {0x4A323342, 0x04000000, 0x00000001}, + {0x4A323343, 0x04000000, 0x00000003}, + {0x4A323442, 0x04000000, 0x00000002}, + {0x4A323443, 0x04000000, 0x00000002}, + {0x4A323543, 0x04000000, 0x00000002}, + {0x4A323642, 0x04000000, 0x00000005}, + {0x4A323742, 0x01000000, 0x00000001}, + {0x4A324143, 0x08000000, 0x00000003}, + {0x4A324159, 0x08000000, 0x00000001}, + {0x4A324243, 0x02000000, 0x00000002}, + {0x4A324259, 0x02000000, 0x00000002}, + {0x4A324341, 0x04000000, 0x00000001}, + {0x4A324359, 0x04000000, 0x00000006}, + {0x4A324441, 0x02000000, 0x00000005}, + {0x4A324442, 0x01000000, 0x00000002}, + {0x4A324443, 0x04000000, 0x00000002}, + {0x4A324541, 0x08000000, 0x00000001}, + {0x4A324559, 0x04000000, 0x00000002}, + {0x4A324641, 0x01000000, 0x00000002}, + {0x4A324642, 0x04000000, 0x00000005}, + {0x4A324659, 0x10000000, 0x00000003}, + {0x4A324742, 0x08000000, 0x00000005}, + {0x4A324759, 0x01000000, 0x00000001}, + {0x4A324841, 0x00800000, 0x00000003}, + {0x4A324842, 0x02000000, 0x00000003}, + {0x4A324843, 0x04000000, 0x00000002}, + {0x4A324956, 0x08000000, 0x00000005}, + {0x4A324A43, 0x01000000, 0x00000002}, + {0x4A324B41, 0x02000000, 0x00000001}, + {0x4A324B54, 0x04000000, 0x00000001}, + {0x4A324B59, 0x02000000, 0x00000003}, + {0x4A324C41, 0x04000000, 0x00000002}, + {0x4A324C59, 0x08000000, 0x00000003}, + {0x4A324D41, 0x04000000, 0x00000005}, + {0x4A324D42, 0x02000000, 0x00000003}, + {0x4A324E41, 0x02000000, 0x00000002}, + {0x4A324E43, 0x04000000, 0x00000005}, + {0x4A324F41, 0x08000000, 0x00000005}, + {0x4A324F42, 0x04000000, 0x00000002}, + {0x4A324F43, 0x10000000, 0x00000001}, + {0x4A324F59, 0x02000000, 0x00000002}, + {0x4A325041, 0x02000000, 0x00000001}, + {0x4A325043, 0x04000000, 0x00000003}, + {0x4A325054, 0x08000000, 0x00000002}, + {0x4A325059, 0x04000000, 0x00000005}, + {0x4A325142, 0x10000000, 0x00000003}, + {0x4A325143, 0x01000000, 0x00000003}, + {0x4A325159, 0x04000000, 0x00000002}, + {0x4A325241, 0x02000000, 0x00000005}, + {0x4A325243, 0x04000000, 0x00000002}, + {0x4A325341, 0x01000000, 0x00000001}, + {0x4A325359, 0x04000000, 0x00000005}, + {0x4A325443, 0x04000000, 0x00000002}, + {0x4A325541, 0x04000000, 0x00000001}, + {0x4A325543, 0x01000000, 0x00000002}, + {0x4A325559, 0x01000000, 0x00000005}, + {0x4A325641, 0x02000000, 0x00000001}, + {0x4A325659, 0x02000000, 0x00000002}, + {0x4A325743, 0x01000000, 0x00000001}, + {0x4A325843, 0x04000000, 0x00000003}, + {0x4A325859, 0x00800000, 0x00000002}, + {0x4A325943, 0x04000000, 0x00000001}, + {0x4A325A41, 0x02000000, 0x00000002}, + {0x4A325A42, 0x04000000, 0x00000002}, + {0x4A325A59, 0x00800000, 0x00000002}, + {0x4A333242, 0x04000000, 0x00000005}, + {0x4A333243, 0x02000000, 0x00000002}, + {0x4A333342, 0x04000000, 0x00000002}, + {0x4A333343, 0x04000000, 0x00000001}, + {0x4A333441, 0x00800000, 0x00000000}, + {0x4A333442, 0x04000000, 0x00000003}, + {0x4A333542, 0x02000000, 0x00000003}, + {0x4A333643, 0x02000000, 0x00000002}, + {0x4A334241, 0x04000000, 0x00000003}, + {0x4A334259, 0x04000000, 0x00000005}, + {0x4A334341, 0x02000000, 0x00000005}, + {0x4A334441, 0x02000000, 0x00000005}, + {0x4A334543, 0x10000000, 0x00000003}, + {0x4A334559, 0x02000000, 0x00000002}, + {0x4A334741, 0x02000000, 0x00000005}, + {0x4A334742, 0x04000000, 0x00000002}, + {0x4A334743, 0x02000000, 0x00000002}, + {0x4A334759, 0x02000000, 0x00000003}, + {0x4A334841, 0x02000000, 0x00000003}, + {0x4A334843, 0x04000000, 0x00000002}, + {0x4A334854, 0x20000000, 0x00000002}, + {0x4A334859, 0x10000000, 0x00000002}, + {0x4A334A42, 0x02000000, 0x00000005}, + {0x4A334A59, 0x04000000, 0x00000002}, + {0x4A334B41, 0x02000000, 0x00000002}, + {0x4A334B42, 0x02000000, 0x00000003}, + {0x4A334B59, 0x02000000, 0x00000003}, + {0x4A334C41, 0x02000000, 0x00000001}, + {0x4A334C42, 0x08000000, 0x00000002}, + {0x4A334C56, 0x08000000, 0x00000005}, + {0x4A334C59, 0x04000000, 0x00000002}, + {0x4A334D42, 0x08000000, 0x00000003}, + {0x4A334D43, 0x08000000, 0x00000003}, + {0x4A334D59, 0x02000000, 0x00000002}, + {0x4A334E43, 0x08000000, 0x00000002}, + {0x4A334E54, 0x20000000, 0x00000005}, + {0x4A334F43, 0x10000000, 0x00000001}, + {0x4A334F59, 0x02000000, 0x00000001}, + {0x4A335141, 0x04000000, 0x00000001}, + {0x4A335142, 0x04000000, 0x00000002}, + {0x4A335143, 0x01000000, 0x00000003}, + {0x4A335241, 0x04000000, 0x00000003}, + {0x4A335242, 0x08000000, 0x00000002}, + {0x4A335243, 0x08000000, 0x00000002}, + {0x4A335259, 0x10000000, 0x00000003}, + {0x4A335442, 0x00800000, 0x00000003}, + {0x4A335443, 0x04000000, 0x00000003}, + {0x4A335456, 0x04000000, 0x00000001}, + {0x4A335459, 0x04000000, 0x00000003}, + {0x4A335559, 0x01000000, 0x00000001}, + {0x4A335641, 0x02000000, 0x00000001}, + {0x4A335642, 0x01000000, 0x00000002}, + {0x4A335643, 0x01000000, 0x00000001}, + {0x4A335741, 0x04000000, 0x00000001}, + {0x4A335759, 0x01000000, 0x00000001}, + {0x4A335841, 0x08000000, 0x00000001}, + {0x4A335843, 0x02000000, 0x00000002}, + {0x4A335941, 0x04000000, 0x00000002}, + {0x4A335959, 0x02000000, 0x00000002}, + {0x4A335A41, 0x02000000, 0x00000002}, + {0x4A335A42, 0x08000000, 0x00000003}, + {0x4A335A43, 0x02000000, 0x00000003}, + {0x4A335A59, 0x02000000, 0x00000002}, + {0x4A343243, 0x08000000, 0x00000003}, + {0x4A343342, 0x02000000, 0x00000001}, + {0x4A343343, 0x04000000, 0x00000003}, + {0x4A343442, 0x01000000, 0x00000002}, + {0x4A343443, 0x08000000, 0x00000002}, + {0x4A343541, 0x02000000, 0x00000000}, + {0x4A343542, 0x01000000, 0x00000002}, + {0x4A343559, 0x00400000, 0x00000000}, + {0x4A343643, 0x04000000, 0x00000003}, + {0x4A343742, 0x04000000, 0x00000002}, + {0x4A344142, 0x01000000, 0x00000002}, + {0x4A344241, 0x04000000, 0x00000005}, + {0x4A344242, 0x04000000, 0x00000002}, + {0x4A344254, 0x10000000, 0x00000006}, + {0x4A344341, 0x04000000, 0x00000001}, + {0x4A344342, 0x10000000, 0x00000002}, + {0x4A344343, 0x04000000, 0x00000003}, + {0x4A344354, 0x04000000, 0x00000007}, + {0x4A344359, 0x02000000, 0x00000003}, + {0x4A344454, 0x02000000, 0x00000001}, + {0x4A344541, 0x04000000, 0x00000002}, + {0x4A344543, 0x01000000, 0x00000003}, + {0x4A344642, 0x10000000, 0x00000002}, + {0x4A344654, 0x04000000, 0x00000005}, + {0x4A344659, 0x08000000, 0x00000003}, + {0x4A344742, 0x08000000, 0x00000002}, + {0x4A344743, 0x04000000, 0x00000003}, + {0x4A344754, 0x04000000, 0x00000003}, + {0x4A344759, 0x10000000, 0x00000003}, + {0x4A344841, 0x00800000, 0x00000001}, + {0x4A344859, 0x04000000, 0x00000001}, + {0x4A344941, 0x01000000, 0x00000003}, + {0x4A344A59, 0x01000000, 0x00000002}, + {0x4A344B41, 0x02000000, 0x00000003}, + {0x4A344B42, 0x08000000, 0x00000002}, + {0x4A344B43, 0x04000000, 0x00000003}, + {0x4A344B59, 0x04000000, 0x00000002}, + {0x4A344C41, 0x00800000, 0x00000001}, + {0x4A344C42, 0x04000000, 0x00000002}, + {0x4A344C43, 0x08000000, 0x00000002}, + {0x4A344C59, 0x00800000, 0x00000002}, + {0x4A344D54, 0x04000000, 0x00000002}, + {0x4A344D59, 0x04000000, 0x00000002}, + {0x4A344E41, 0x04000000, 0x00000001}, + {0x4A344F41, 0x02000000, 0x00000002}, + {0x4A344F42, 0x04000000, 0x00000003}, + {0x4A344F43, 0x00800000, 0x00000006}, + {0x4A344F59, 0x08000000, 0x00000002}, + {0x4A345043, 0x08000000, 0x00000002}, + {0x4A345054, 0x04000000, 0x00000002}, + {0x4A345056, 0x08000000, 0x00000006}, + {0x4A345059, 0x04000000, 0x00000002}, + {0x4A345142, 0x04000000, 0x00000002}, + {0x4A345159, 0x00800000, 0x00000002}, + {0x4A345241, 0x01000000, 0x00000002}, + {0x4A345259, 0x01000000, 0x00000003}, + {0x4A345343, 0x08000000, 0x00000003}, + {0x4A345359, 0x04000000, 0x00000002}, + {0x4A345541, 0x01000000, 0x00000001}, + {0x4A345559, 0x02000000, 0x00000003}, + {0x4A345641, 0x02000000, 0x00000001}, + {0x4A345659, 0x08000000, 0x00000003}, + {0x4A345743, 0x10000000, 0x00000003}, + {0x4A345759, 0x04000000, 0x00000003}, + {0x4A345841, 0x08000000, 0x00000001}, + {0x4A345843, 0x04000000, 0x00000005}, + {0x4A345941, 0x08000000, 0x00000001}, + {0x4A345959, 0x04000000, 0x00000003}, + {0x4A345A41, 0x00800000, 0x00000002}, + {0x4A345A59, 0x02000000, 0x00000001}, + {0x4A353342, 0x04000000, 0x00000005}, + {0x4A353443, 0x01000000, 0x00000002}, + {0x4A353543, 0x04000000, 0x00000003}, + {0x4A353742, 0x01000000, 0x00000002}, + {0x4A354143, 0x08000000, 0x00000003}, + {0x4A354241, 0x02000000, 0x00000001}, + {0x4A354341, 0x02000000, 0x00000005}, + {0x4A354354, 0x02000000, 0x00000002}, + {0x4A354459, 0x00800000, 0x00000002}, + {0x4A354541, 0x01000000, 0x00000003}, + {0x4A354542, 0x04000000, 0x00000002}, + {0x4A354742, 0x04000000, 0x00000002}, + {0x4A354843, 0x04000000, 0x00000002}, + {0x4A354859, 0x04000000, 0x00000002}, + {0x4A354941, 0x04000000, 0x00000002}, + {0x4A354A43, 0x02000000, 0x00000002}, + {0x4A354B41, 0x01000000, 0x00000001}, + {0x4A354B43, 0x04000000, 0x00000005}, + {0x4A354B54, 0x00800000, 0x00000003}, + {0x4A354B56, 0x04000000, 0x00000003}, + {0x4A354C59, 0x08000000, 0x00000003}, + {0x4A354D41, 0x04000000, 0x00000005}, + {0x4A354E41, 0x01000000, 0x00000003}, + {0x4A354E43, 0x04000000, 0x00000003}, + {0x4A354F41, 0x02000000, 0x00000005}, + {0x4A354F42, 0x10000000, 0x00000005}, + {0x4A354F59, 0x04000000, 0x00000003}, + {0x4A355154, 0x04000000, 0xFFFFFFFF}, + {0x4A355159, 0x01000000, 0x00000002}, + {0x4A355442, 0x08000000, 0x00000002}, + {0x4A355543, 0x04000000, 0x00000002}, + {0x4A355559, 0x08000000, 0x00000002}, + {0x4A355641, 0x02000000, 0x00000001}, + {0x4A355643, 0x02000000, 0x00000001}, + {0x4A355659, 0x08000000, 0x00000003}, + {0x4A355741, 0x01000000, 0x00000003}, + {0x4A355841, 0x08000000, 0x00000001}, + {0x4A355941, 0x08000000, 0x00000003}, + {0x4A355959, 0x04000000, 0x00000003}, + {0x4A355A43, 0x02000000, 0x00000003}, + {0x4A355A59, 0x02000000, 0x00000002}, + {0x4A363243, 0x00800000, 0x00000002}, + {0x4A363341, 0x02000000, 0x00000000}, + {0x4A363343, 0x04000000, 0x00000001}, + {0x4A363542, 0x04000000, 0x00000005}, + {0x4A363643, 0x04000000, 0x00000002}, + {0x4A364143, 0x04000000, 0x00000002}, + {0x4A364241, 0x02000000, 0x00000001}, + {0x4A364243, 0x01000000, 0x00000002}, + {0x4A364259, 0x01000000, 0x00000002}, + {0x4A364359, 0x01000000, 0x00000003}, + {0x4A364443, 0x08000000, 0x00000003}, + {0x4A364541, 0x04000000, 0x00000003}, + {0x4A364543, 0x01000000, 0x00000002}, + {0x4A364559, 0x04000000, 0x00000003}, + {0x4A364659, 0x04000000, 0x00000003}, + {0x4A364741, 0x02000000, 0x00000002}, + {0x4A364841, 0x01000000, 0x00000001}, + {0x4A364842, 0x04000000, 0x00000002}, + {0x4A364843, 0x04000000, 0x00000001}, + {0x4A364859, 0x04000000, 0x00000001}, + {0x4A364943, 0x02000000, 0x00000003}, + {0x4A364A43, 0x08000000, 0x00000002}, + {0x4A364B42, 0x02000000, 0x00000002}, + {0x4A364B59, 0x00800000, 0x00000003}, + {0x4A364C59, 0x04000000, 0x00000001}, + {0x4A364D43, 0x08000000, 0x00000002}, + {0x4A364E43, 0x04000000, 0x00000002}, + {0x4A364F41, 0x08000000, 0x00000001}, + {0x4A364F42, 0x01000000, 0x00000002}, + {0x4A364F43, 0x04000000, 0x00000002}, + {0x4A364F59, 0x02000000, 0x00000001}, + {0x4A365141, 0x00800000, 0x00000002}, + {0x4A365142, 0x02000000, 0x00000003}, + {0x4A365241, 0x00800000, 0x00000002}, + {0x4A365243, 0x04000000, 0x00000002}, + {0x4A365341, 0x04000000, 0x00000005}, + {0x4A365359, 0x04000000, 0x00000005}, + {0x4A365443, 0x04000000, 0x00000002}, + {0x4A365459, 0x01000000, 0x00000003}, + {0x4A365559, 0x02000000, 0x00000002}, + {0x4A365641, 0x02000000, 0x00000001}, + {0x4A365659, 0x00800000, 0x00000001}, + {0x4A365759, 0x02000000, 0x00000002}, + {0x4A365841, 0x08000000, 0x00000001}, + {0x4A365843, 0x08000000, 0x00000002}, + {0x4A365941, 0x00800000, 0x00000005}, + {0x4A365A41, 0x01000000, 0x00000005}, + {0x4A365A59, 0x02000000, 0x00000002}, + {0x4A373243, 0x08000000, 0x00000003}, + {0x4A374142, 0x02000000, 0x00000002}, + {0x4A374341, 0x00800000, 0x00000002}, + {0x4A374359, 0x02000000, 0x00000002}, + {0x4A374459, 0x04000000, 0x00000002}, + {0x4A374541, 0x08000000, 0x00000002}, + {0x4A374741, 0x02000000, 0x00000002}, + {0x4A374743, 0x04000000, 0x00000002}, + {0x4A374759, 0x04000000, 0x00000002}, + {0x4A374841, 0x04000000, 0x00000002}, + {0x4A374843, 0x10000000, 0x00000003}, + {0x4A374859, 0x08000000, 0x00000001}, + {0x4A374A43, 0x04000000, 0x00000001}, + {0x4A374A54, 0x04000000, 0x00000002}, + {0x4A374A59, 0x01000000, 0x00000002}, + {0x4A374B41, 0x02000000, 0x00000005}, + {0x4A374B59, 0x01000000, 0x00000002}, + {0x4A374C41, 0x02000000, 0x00000001}, + {0x4A374C59, 0x04000000, 0x00000003}, + {0x4A374D41, 0x02000000, 0x00000002}, + {0x4A374D42, 0x04000000, 0x00000003}, + {0x4A374D59, 0x04000000, 0x00000002}, + {0x4A374E54, 0x20000000, 0x00000005}, + {0x4A374F41, 0x04000000, 0x00000002}, + {0x4A374F42, 0x01000000, 0x00000005}, + {0x4A374F59, 0x01000000, 0x00000002}, + {0x4A375141, 0x00800000, 0x00000002}, + {0x4A375241, 0x04000000, 0x00000002}, + {0x4A375259, 0x04000000, 0x00000002}, + {0x4A375341, 0x08000000, 0x00000003}, + {0x4A375342, 0x04000000, 0x00000001}, + {0x4A375343, 0x10000000, 0x00000003}, + {0x4A375541, 0x02000000, 0x00000002}, + {0x4A375641, 0x02000000, 0x00000002}, + {0x4A375659, 0x00800000, 0x00000001}, + {0x4A375741, 0x02000000, 0x00000002}, + {0x4A375841, 0x08000000, 0x00000003}, + {0x4A375859, 0x01000000, 0x00000003}, + {0x4A375941, 0x08000000, 0x00000005}, + {0x4A375A41, 0x01000000, 0x00000002}, + {0x4A375A59, 0x02000000, 0x00000001}, + {0x4A383343, 0x04000000, 0x00000005}, + {0x4A383442, 0x00800000, 0x00000002}, + {0x4A384154, 0x01000000, 0x00000001}, + {0x4A384259, 0x02000000, 0x00000003}, + {0x4A384359, 0x01000000, 0x00000002}, + {0x4A384441, 0x01000000, 0x00000002}, + {0x4A384443, 0x02000000, 0x00000002}, + {0x4A384459, 0x04000000, 0x00000003}, + {0x4A384541, 0x04000000, 0x00000002}, + {0x4A384542, 0x20000000, 0x00000003}, + {0x4A384641, 0x01000000, 0x00000002}, + {0x4A384741, 0x04000000, 0x00000003}, + {0x4A384742, 0x01000000, 0x00000003}, + {0x4A384743, 0x02000000, 0x00000002}, + {0x4A384759, 0x08000000, 0x00000005}, + {0x4A384841, 0x02000000, 0x00000001}, + {0x4A384943, 0x04000000, 0x00000002}, + {0x4A384A43, 0x04000000, 0x00000002}, + {0x4A384A54, 0x04000000, 0x00000002}, + {0x4A384B43, 0x02000000, 0x00000003}, + {0x4A384B59, 0x04000000, 0x00000003}, + {0x4A384D41, 0x01000000, 0x00000001}, + {0x4A384D43, 0x02000000, 0x00000002}, + {0x4A384D59, 0x01000000, 0x00000002}, + {0x4A384E43, 0x10000000, 0x00000003}, + {0x4A385041, 0x02000000, 0x00000005}, + {0x4A385043, 0x02000000, 0x00000002}, + {0x4A385141, 0x00800000, 0x00000002}, + {0x4A385142, 0x04000000, 0x00000002}, + {0x4A385154, 0x04000000, 0x00000003}, + {0x4A385159, 0x04000000, 0x00000003}, + {0x4A385241, 0x04000000, 0x00000002}, + {0x4A385242, 0x01000000, 0x00000001}, + {0x4A385341, 0x00800000, 0x00000002}, + {0x4A385443, 0x04000000, 0x00000003}, + {0x4A385541, 0x04000000, 0x00000002}, + {0x4A385641, 0x01000000, 0x00000001}, + {0x4A385643, 0x04000000, 0x00000002}, + {0x4A385659, 0x00800000, 0x00000001}, + {0x4A385759, 0x08000000, 0x00000005}, + {0x4A385843, 0x02000000, 0x00000002}, + {0x4A385943, 0x10000000, 0x00000003}, + {0x4A385959, 0x04000000, 0x00000002}, + {0x4A385A41, 0x00800000, 0x00000002}, + {0x4A385A59, 0x02000000, 0x00000002}, + {0x4A393243, 0x04000000, 0x00000005}, + {0x4A393256, 0x02000000, 0x00000005}, + {0x4A393341, 0x02000000, 0x00000000}, + {0x4A393342, 0x08000000, 0x00000002}, + {0x4A393441, 0x02000000, 0x00000000}, + {0x4A393443, 0x04000000, 0x00000005}, + {0x4A393542, 0x01000000, 0x00000002}, + {0x4A393543, 0x04000000, 0x00000002}, + {0x4A393741, 0x02000000, 0x00000000}, + {0x4A393842, 0x04000000, 0x00000005}, + {0x4A394142, 0x04000000, 0x00000002}, + {0x4A394154, 0x01000000, 0x00000001}, + {0x4A394241, 0x01000000, 0x00000001}, + {0x4A394243, 0x08000000, 0x00000005}, + {0x4A394441, 0x02000000, 0x00000003}, + {0x4A394443, 0x04000000, 0x00000003}, + {0x4A394541, 0x04000000, 0x00000002}, + {0x4A394559, 0x04000000, 0x00000003}, + {0x4A394741, 0x02000000, 0x00000003}, + {0x4A394742, 0x04000000, 0x00000005}, + {0x4A394743, 0x01000000, 0x00000002}, + {0x4A394842, 0x20000000, 0x00000002}, + {0x4A394843, 0x02000000, 0x00000003}, + {0x4A394859, 0x02000000, 0x00000002}, + {0x4A394941, 0x04000000, 0x00000002}, + {0x4A394A42, 0x01000000, 0x00000002}, + {0x4A394A54, 0x04000000, 0x00000002}, + {0x4A394A59, 0x00800000, 0x00000005}, + {0x4A394B41, 0x01000000, 0x00000002}, + {0x4A394B42, 0x10000000, 0x00000003}, + {0x4A394B43, 0x04000000, 0x00000005}, + {0x4A394B54, 0x08000000, 0x00000002}, + {0x4A394B59, 0x08000000, 0x00000002}, + {0x4A394C59, 0x04000000, 0x00000003}, + {0x4A394D41, 0x01000000, 0x00000002}, + {0x4A394D42, 0x04000000, 0x00000003}, + {0x4A394E41, 0x01000000, 0x00000001}, + {0x4A394E59, 0x02000000, 0x00000002}, + {0x4A394F41, 0x04000000, 0x00000002}, + {0x4A394F42, 0x04000000, 0x00000003}, + {0x4A394F59, 0x02000000, 0x00000003}, + {0x4A395041, 0x01000000, 0x00000002}, + {0x4A395059, 0x04000000, 0x00000003}, + {0x4A395141, 0x04000000, 0x00000001}, + {0x4A395142, 0x00800000, 0x00000002}, + {0x4A395143, 0x00800000, 0x00000002}, + {0x4A395241, 0x02000000, 0x00000002}, + {0x4A395243, 0x01000000, 0x00000002}, + {0x4A395259, 0x04000000, 0x00000002}, + {0x4A395359, 0x04000000, 0x00000003}, + {0x4A395541, 0x01000000, 0x00000002}, + {0x4A395559, 0x04000000, 0x00000002}, + {0x4A395659, 0x00800000, 0x00000001}, + {0x4A395841, 0x04000000, 0x00000002}, + {0x4A395843, 0x08000000, 0x00000003}, + {0x4A395859, 0x01000000, 0x00000003}, + {0x4A395941, 0x08000000, 0x00000003}, + {0x4A395959, 0x02000000, 0x00000002}, + {0x4A395A41, 0x02000000, 0x00000003}, + {0x4A395A42, 0x04000000, 0x00000002}, + {0x4A395A59, 0x02000000, 0x00000002}, + {0x4A413241, 0x04000000, 0x00000002}, + {0x4A413243, 0x08000000, 0x00000002}, + {0x4A413341, 0x04000000, 0x00000006}, + {0x4A413442, 0x01000000, 0x00000002}, + {0x4A413443, 0x04000000, 0x00000001}, + {0x4A413541, 0x04000000, 0x00000001}, + {0x4A413641, 0x02000000, 0x00000005}, + {0x4A413841, 0x00800000, 0x00000001}, + {0x4A414154, 0x02000000, 0x00000004}, + {0x4A414156, 0x02000000, 0x00000008}, + {0x4A414159, 0x04000000, 0x00000002}, + {0x4A414259, 0x02000000, 0x00000002}, + {0x4A414356, 0x04000000, 0x00000001}, + {0x4A414441, 0x04000000, 0x00000006}, + {0x4A414459, 0x02000000, 0x00000003}, + {0x4A414543, 0x02000000, 0x00000003}, + {0x4A414559, 0x02000000, 0x00000003}, + {0x4A414641, 0x04000000, 0x00000003}, + {0x4A414659, 0x02000000, 0x00000003}, + {0x4A414843, 0x04000000, 0x00000003}, + {0x4A414859, 0x01000000, 0x00000003}, + {0x4A414941, 0x04000000, 0x00000001}, + {0x4A414943, 0x08000000, 0x00000003}, + {0x4A414A41, 0x08000000, 0x00000003}, + {0x4A414A59, 0x04000000, 0x00000002}, + {0x4A414B41, 0x08000000, 0x00000005}, + {0x4A414B42, 0x08000000, 0x00000003}, + {0x4A414B59, 0x04000000, 0x00000003}, + {0x4A414C41, 0x04000000, 0x00000005}, + {0x4A414D41, 0x01000000, 0x00000002}, + {0x4A414D43, 0x08000000, 0x00000002}, + {0x4A414D59, 0x02000000, 0x00000002}, + {0x4A414E41, 0x02000000, 0x00000002}, + {0x4A414E59, 0x04000000, 0x00000002}, + {0x4A414F59, 0x02000000, 0x00000002}, + {0x4A415041, 0x04000000, 0x00000006}, + {0x4A415142, 0x01000000, 0x00000005}, + {0x4A415154, 0x08000000, 0x00000004}, + {0x4A415242, 0x04000000, 0x00000002}, + {0x4A415249, 0x10000000, 0x00000006}, + {0x4A415342, 0x04000000, 0x00000003}, + {0x4A415441, 0x01000000, 0x00000001}, + {0x4A415442, 0x08000000, 0x00000003}, + {0x4A415541, 0x04000000, 0x00000005}, + {0x4A415559, 0x04000000, 0x00000001}, + {0x4A415643, 0x04000000, 0x00000002}, + {0x4A415741, 0x04000000, 0x00000002}, + {0x4A415841, 0x08000000, 0x00000002}, + {0x4A415859, 0x04000000, 0x00000003}, + {0x4A415941, 0x00800000, 0x00000002}, + {0x4A415943, 0x04000000, 0x00000006}, + {0x4A415959, 0x02000000, 0x00000003}, + {0x4A415A41, 0x02000000, 0x00000002}, + {0x4A415A59, 0x01000000, 0x00000002}, + {0x4A423241, 0x01000000, 0x00000001}, + {0x4A423242, 0x08000000, 0x00000002}, + {0x4A423341, 0x08000000, 0x00000002}, + {0x4A423442, 0x04000000, 0x00000002}, + {0x4A423443, 0x01000000, 0x00000003}, + {0x4A423541, 0x04000000, 0x00000002}, + {0x4A423641, 0x02000000, 0x00000005}, + {0x4A424241, 0x01000000, 0x00000005}, + {0x4A424341, 0x04000000, 0x00000003}, + {0x4A424359, 0x04000000, 0x00000001}, + {0x4A424441, 0x04000000, 0x00000002}, + {0x4A424442, 0x04000000, 0x00000002}, + {0x4A424454, 0x04000000, 0x00000002}, + {0x4A424542, 0x10000000, 0x00000003}, + {0x4A424543, 0x02000000, 0x00000003}, + {0x4A424556, 0x02000000, 0x00000007}, + {0x4A424559, 0x02000000, 0x00000002}, + {0x4A424754, 0x08000000, 0x00000002}, + {0x4A424759, 0x01000000, 0x00000002}, + {0x4A424843, 0x04000000, 0x00000001}, + {0x4A424859, 0x04000000, 0x00000003}, + {0x4A424941, 0x08000000, 0x00000002}, + {0x4A424943, 0x01000000, 0x00000002}, + {0x4A424A41, 0x04000000, 0x00000005}, + {0x4A424A59, 0x04000000, 0x00000001}, + {0x4A424B41, 0x02000000, 0x00000003}, + {0x4A424B59, 0x04000000, 0x00000003}, + {0x4A424C41, 0x08000000, 0x00000003}, + {0x4A424C43, 0x04000000, 0x00000003}, + {0x4A424D41, 0x04000000, 0x00000002}, + {0x4A424E41, 0x04000000, 0x00000005}, + {0x4A424E42, 0x04000000, 0x00000003}, + {0x4A424E59, 0x04000000, 0x00000002}, + {0x4A424F42, 0x02000000, 0x00000001}, + {0x4A425041, 0x02000000, 0x00000001}, + {0x4A425059, 0x08000000, 0x00000003}, + {0x4A425141, 0x01000000, 0x00000001}, + {0x4A425142, 0x04000000, 0x00000002}, + {0x4A425154, 0x02000000, 0x00000003}, + {0x4A425241, 0x02000000, 0x00000001}, + {0x4A425243, 0x02000000, 0x00000005}, + {0x4A425249, 0x10000000, 0x00000006}, + {0x4A425259, 0x08000000, 0x00000003}, + {0x4A425341, 0x04000000, 0x00000002}, + {0x4A425441, 0x04000000, 0x00000002}, + {0x4A425442, 0x04000000, 0x00000002}, + {0x4A425459, 0x08000000, 0x00000003}, + {0x4A425541, 0x04000000, 0x00000005}, + {0x4A425643, 0x02000000, 0x00000003}, + {0x4A425659, 0x08000000, 0x00000002}, + {0x4A425841, 0x04000000, 0x00000008}, + {0x4A425859, 0x08000000, 0x00000003}, + {0x4A425941, 0x02000000, 0x00000002}, + {0x4A425959, 0x04000000, 0x00000005}, + {0x4A425A41, 0x00800000, 0x00000001}, + {0x4A425A42, 0x02000000, 0x00000003}, + {0x4A425A59, 0x02000000, 0x00000002}, + {0x4A433342, 0x04000000, 0x00000002}, + {0x4A433343, 0x02000000, 0x00000001}, + {0x4A433441, 0x01000000, 0x00000003}, + {0x4A433442, 0x08000000, 0x00000002}, + {0x4A433443, 0x01000000, 0x00000002}, + {0x4A433541, 0x01000000, 0x00000001}, + {0x4A433641, 0x02000000, 0x00000005}, + {0x4A433643, 0x10000000, 0x00000005}, + {0x4A433841, 0x02000000, 0x00000002}, + {0x4A434154, 0x02000000, 0x00000002}, + {0x4A434159, 0x04000000, 0x00000003}, + {0x4A434241, 0x02000000, 0x00000005}, + {0x4A434254, 0x00800000, 0x00000001}, + {0x4A434341, 0x02000000, 0x00000001}, + {0x4A434441, 0x01000000, 0x00000001}, + {0x4A434459, 0x08000000, 0x00000003}, + {0x4A434541, 0x00800000, 0x00000001}, + {0x4A434554, 0x08000000, 0x00000005}, + {0x4A434559, 0x02000000, 0x00000001}, + {0x4A434741, 0x04000000, 0x00000003}, + {0x4A434743, 0x04000000, 0x00000002}, + {0x4A434754, 0x04000000, 0x00000003}, + {0x4A434941, 0x01000000, 0x00000001}, + {0x4A434A41, 0x00800000, 0x00000002}, + {0x4A434B59, 0x02000000, 0x00000002}, + {0x4A434C56, 0x04000000, 0x00000002}, + {0x4A434D41, 0x02000000, 0x00000005}, + {0x4A434E41, 0x04000000, 0x00000002}, + {0x4A434E42, 0x08000000, 0x00000002}, + {0x4A434E43, 0x04000000, 0x00000002}, + {0x4A434F41, 0x01000000, 0x00000003}, + {0x4A434F42, 0x00800000, 0x00000003}, + {0x4A434F59, 0x02000000, 0x00000002}, + {0x4A435041, 0x01000000, 0x00000001}, + {0x4A435054, 0x08000000, 0x00000002}, + {0x4A435141, 0x04000000, 0x00000002}, + {0x4A435154, 0x08000000, 0x00000004}, + {0x4A435259, 0x08000000, 0x00000002}, + {0x4A435341, 0x04000000, 0x00000002}, + {0x4A435459, 0x08000000, 0x00000003}, + {0x4A435541, 0x04000000, 0x00000005}, + {0x4A435542, 0x04000000, 0x00000002}, + {0x4A435641, 0x04000000, 0x00000005}, + {0x4A435643, 0x02000000, 0x00000001}, + {0x4A435741, 0x04000000, 0x00000002}, + {0x4A435742, 0x02000000, 0x00000002}, + {0x4A435743, 0x02000000, 0x00000001}, + {0x4A435841, 0x02000000, 0x00000003}, + {0x4A435859, 0x04000000, 0x00000003}, + {0x4A435941, 0x04000000, 0x00000003}, + {0x4A435A41, 0x00800000, 0x00000001}, + {0x4A435A42, 0x02000000, 0x00000003}, + {0x4A435A43, 0x02000000, 0x00000002}, + {0x4A435A55, 0x08000000, 0xFFFFFFFF}, + {0x4A435A59, 0x01000000, 0x00000002}, + {0x4A443241, 0x02000000, 0x00000002}, + {0x4A443243, 0x04000000, 0x00000002}, + {0x4A443341, 0x08000000, 0x00000003}, + {0x4A443342, 0x04000000, 0x00000002}, + {0x4A443441, 0x04000000, 0x00000003}, + {0x4A443443, 0x04000000, 0x00000002}, + {0x4A443541, 0x00800000, 0x00000002}, + {0x4A443542, 0x04000000, 0x00000002}, + {0x4A443543, 0x02000000, 0x00000001}, + {0x4A443641, 0x04000000, 0x00000002}, + {0x4A443841, 0x04000000, 0x00000002}, + {0x4A444154, 0x08000000, 0x00000005}, + {0x4A444259, 0x08000000, 0x00000002}, + {0x4A444342, 0x04000000, 0x00000002}, + {0x4A444356, 0x04000000, 0x00000002}, + {0x4A444441, 0x01000000, 0x00000001}, + {0x4A444443, 0x04000000, 0x00000002}, + {0x4A444459, 0x01000000, 0x00000001}, + {0x4A444543, 0x04000000, 0x00000002}, + {0x4A444554, 0x02000000, 0x00000003}, + {0x4A444741, 0x02000000, 0x00000003}, + {0x4A444754, 0x10000000, 0x00000002}, + {0x4A444841, 0x04000000, 0x00000002}, + {0x4A444843, 0x08000000, 0x00000002}, + {0x4A444941, 0x02000000, 0x00000002}, + {0x4A444942, 0x08000000, 0x00000003}, + {0x4A444A41, 0x00800000, 0x00000002}, + {0x4A444A43, 0x00800000, 0x00000001}, + {0x4A444B41, 0x01000000, 0x00000002}, + {0x4A444B43, 0x02000000, 0x00000002}, + {0x4A444B54, 0x02000000, 0x00000002}, + {0x4A444B59, 0x08000000, 0x00000005}, + {0x4A444C41, 0x04000000, 0x00000005}, + {0x4A444C59, 0x04000000, 0x00000005}, + {0x4A444D59, 0x02000000, 0x00000003}, + {0x4A444E41, 0x01000000, 0x00000005}, + {0x4A444F41, 0x02000000, 0x00000003}, + {0x4A444F59, 0x04000000, 0x00000002}, + {0x4A445041, 0x01000000, 0x00000002}, + {0x4A445059, 0x02000000, 0x00000005}, + {0x4A445141, 0x02000000, 0x00000003}, + {0x4A445142, 0x04000000, 0x00000002}, + {0x4A445143, 0x01000000, 0x00000002}, + {0x4A445154, 0x02000000, 0x00000003}, + {0x4A445159, 0x02000000, 0x00000002}, + {0x4A445249, 0x20000000, 0x00000006}, + {0x4A445342, 0x04000000, 0x00000002}, + {0x4A445359, 0x04000000, 0x00000005}, + {0x4A445441, 0x01000000, 0x00000002}, + {0x4A445541, 0x04000000, 0x00000005}, + {0x4A445542, 0x01000000, 0x00000001}, + {0x4A445559, 0x01000000, 0x00000005}, + {0x4A445841, 0x01000000, 0x00000002}, + {0x4A445859, 0x02000000, 0x00000003}, + {0x4A445941, 0x04000000, 0x00000002}, + {0x4A445A43, 0x02000000, 0x00000002}, + {0x4A445A59, 0x04000000, 0x00000002}, + {0x4A453243, 0x02000000, 0x00000003}, + {0x4A453343, 0x02000000, 0x00000002}, + {0x4A453541, 0x04000000, 0x00000001}, + {0x4A453542, 0x10000000, 0x00000003}, + {0x4A453543, 0x02000000, 0x00000005}, + {0x4A453641, 0x04000000, 0x00000003}, + {0x4A453841, 0x00800000, 0x00000001}, + {0x4A454159, 0x08000000, 0x00000002}, + {0x4A454243, 0x02000000, 0x00000001}, + {0x4A454341, 0x01000000, 0x00000002}, + {0x4A454441, 0x08000000, 0x00000003}, + {0x4A454442, 0x04000000, 0x00000002}, + {0x4A454456, 0x10000000, 0x00000006}, + {0x4A454541, 0x04000000, 0x00000003}, + {0x4A454542, 0x10000000, 0x00000003}, + {0x4A454559, 0x08000000, 0x00000003}, + {0x4A454641, 0x04000000, 0x00000003}, + {0x4A454643, 0x02000000, 0x00000001}, + {0x4A454659, 0x04000000, 0x00000005}, + {0x4A454741, 0x01000000, 0x00000001}, + {0x4A454759, 0x04000000, 0x00000002}, + {0x4A454841, 0x08000000, 0x00000005}, + {0x4A454859, 0x08000000, 0x00000003}, + {0x4A454A41, 0x08000000, 0x00000003}, + {0x4A454A42, 0x02000000, 0x00000003}, + {0x4A454A43, 0x02000000, 0x00000003}, + {0x4A454B41, 0x04000000, 0x00000002}, + {0x4A454B43, 0x01000000, 0x00000002}, + {0x4A454B59, 0x04000000, 0x00000002}, + {0x4A454C41, 0x08000000, 0x00000002}, + {0x4A454C42, 0x04000000, 0x00000003}, + {0x4A454C59, 0x02000000, 0x00000001}, + {0x4A454D41, 0x02000000, 0x00000002}, + {0x4A454D42, 0x10000000, 0x00000003}, + {0x4A454D43, 0x04000000, 0x00000002}, + {0x4A454D59, 0x00800000, 0x00000002}, + {0x4A454E41, 0x04000000, 0x00000002}, + {0x4A454E43, 0x02000000, 0x00000002}, + {0x4A454F41, 0x04000000, 0x00000003}, + {0x4A454F42, 0x20000000, 0x00000003}, + {0x4A454F43, 0x01000000, 0x00000002}, + {0x4A455041, 0x04000000, 0x00000001}, + {0x4A455043, 0x02000000, 0x00000002}, + {0x4A455059, 0x04000000, 0x00000002}, + {0x4A455241, 0x02000000, 0x00000001}, + {0x4A455249, 0x20000000, 0x00000006}, + {0x4A455259, 0x02000000, 0x00000002}, + {0x4A455341, 0x04000000, 0x00000002}, + {0x4A455343, 0x04000000, 0x00000002}, + {0x4A455441, 0x02000000, 0x00000001}, + {0x4A455541, 0x04000000, 0x00000005}, + {0x4A455643, 0x04000000, 0x00000002}, + {0x4A455741, 0x04000000, 0x00000005}, + {0x4A455759, 0x01000000, 0x00000002}, + {0x4A455841, 0x00800000, 0x00000002}, + {0x4A455859, 0x02000000, 0x00000003}, + {0x4A455941, 0x04000000, 0x00000002}, + {0x4A455A41, 0x04000000, 0x00000006}, + {0x4A455A59, 0x02000000, 0x00000003}, + {0x4A463241, 0x08000000, 0x00000003}, + {0x4A463243, 0x08000000, 0x00000002}, + {0x4A463341, 0x04000000, 0x00000005}, + {0x4A463442, 0x04000000, 0x00000003}, + {0x4A463443, 0x01000000, 0x00000003}, + {0x4A463541, 0x04000000, 0x00000003}, + {0x4A463542, 0x04000000, 0x00000005}, + {0x4A463543, 0x04000000, 0x00000002}, + {0x4A463641, 0x08000000, 0x00000003}, + {0x4A463643, 0x10000000, 0x00000002}, + {0x4A463841, 0x00800000, 0x00000001}, + {0x4A464241, 0x01000000, 0x00000005}, + {0x4A464254, 0x04000000, 0x00000003}, + {0x4A464259, 0x08000000, 0x00000003}, + {0x4A464341, 0x04000000, 0x00000002}, + {0x4A464443, 0x04000000, 0x00000002}, + {0x4A464641, 0x08000000, 0x00000003}, + {0x4A464741, 0x04000000, 0x00000002}, + {0x4A464842, 0x10000000, 0x00000003}, + {0x4A464941, 0x04000000, 0x00000002}, + {0x4A464B41, 0x00800000, 0x00000001}, + {0x4A464B54, 0x04000000, 0x00000005}, + {0x4A464B59, 0x02000000, 0x00000001}, + {0x4A464C42, 0x10000000, 0x00000003}, + {0x4A464D44, 0x02000000, 0xFFFFFFFF}, + {0x4A464F41, 0x02000000, 0x00000003}, + {0x4A464F59, 0x02000000, 0x00000003}, + {0x4A465041, 0x04000000, 0x00000002}, + {0x4A465141, 0x04000000, 0x00000002}, + {0x4A465142, 0x04000000, 0x00000002}, + {0x4A465143, 0x02000000, 0x00000008}, + {0x4A465154, 0x02000000, 0x00000003}, + {0x4A465241, 0x08000000, 0x00000003}, + {0x4A465242, 0x08000000, 0x00000003}, + {0x4A465341, 0x02000000, 0x00000005}, + {0x4A465459, 0x08000000, 0x00000003}, + {0x4A465541, 0x04000000, 0x00000002}, + {0x4A465559, 0x04000000, 0x00000002}, + {0x4A465641, 0x01000000, 0x00000002}, + {0x4A465759, 0x02000000, 0x00000003}, + {0x4A465841, 0x08000000, 0x00000003}, + {0x4A465859, 0x02000000, 0x00000003}, + {0x4A465A59, 0x02000000, 0x00000002}, + {0x4A473241, 0x02000000, 0x00000003}, + {0x4A473243, 0x04000000, 0x00000002}, + {0x4A473256, 0x02000000, 0x00000006}, + {0x4A473341, 0x04000000, 0x00000005}, + {0x4A473342, 0x04000000, 0x00000002}, + {0x4A473441, 0x02000000, 0x00000002}, + {0x4A473442, 0x08000000, 0x00000002}, + {0x4A473443, 0x10000000, 0x00000003}, + {0x4A473542, 0x04000000, 0x00000006}, + {0x4A473543, 0x01000000, 0x00000002}, + {0x4A473641, 0x04000000, 0x00000002}, + {0x4A473643, 0x01000000, 0x00000003}, + {0x4A473841, 0x04000000, 0x00000002}, + {0x4A474342, 0x04000000, 0x00000002}, + {0x4A474343, 0x10000000, 0x00000003}, + {0x4A474356, 0x04000000, 0x00000002}, + {0x4A474441, 0x02000000, 0x00000005}, + {0x4A474442, 0x10000000, 0x00000002}, + {0x4A474443, 0x04000000, 0x00000006}, + {0x4A474543, 0x10000000, 0x00000003}, + {0x4A474559, 0x04000000, 0x00000003}, + {0x4A474643, 0x02000000, 0x00000002}, + {0x4A474741, 0x02000000, 0x00000002}, + {0x4A474743, 0x02000000, 0x00000002}, + {0x4A474841, 0x02000000, 0x00000003}, + {0x4A474843, 0x10000000, 0x00000003}, + {0x4A474854, 0x04000000, 0x00000002}, + {0x4A474859, 0x04000000, 0x00000003}, + {0x4A474941, 0x04000000, 0x00000003}, + {0x4A474943, 0x01000000, 0x00000002}, + {0x4A474A41, 0x00800000, 0x00000005}, + {0x4A474A59, 0x04000000, 0x00000002}, + {0x4A474B41, 0x02000000, 0x00000002}, + {0x4A474B54, 0x04000000, 0x00000002}, + {0x4A474B56, 0x02000000, 0x00000005}, + {0x4A474B59, 0x10000000, 0x00000003}, + {0x4A474C41, 0x04000000, 0x00000001}, + {0x4A474D41, 0x01000000, 0x00000001}, + {0x4A474E41, 0x08000000, 0x00000005}, + {0x4A474E42, 0x04000000, 0x00000005}, + {0x4A474E59, 0x08000000, 0x00000003}, + {0x4A474F59, 0x08000000, 0x00000003}, + {0x4A475041, 0x01000000, 0x00000001}, + {0x4A475043, 0x02000000, 0x00000003}, + {0x4A475049, 0x08000000, 0x00000006}, + {0x4A475054, 0x10000000, 0x00000003}, + {0x4A475056, 0x08000000, 0x00000002}, + {0x4A475141, 0x04000000, 0x00000002}, + {0x4A475143, 0x04000000, 0x00000002}, + {0x4A475154, 0x04000000, 0x00000004}, + {0x4A475241, 0x02000000, 0x00000005}, + {0x4A475242, 0x04000000, 0x00000002}, + {0x4A475254, 0x08000000, 0x00000002}, + {0x4A475259, 0x04000000, 0x00000002}, + {0x4A475341, 0x02000000, 0x00000005}, + {0x4A475343, 0x08000000, 0x00000003}, + {0x4A475441, 0x00800000, 0x00000002}, + {0x4A475442, 0x10000000, 0x00000003}, + {0x4A475443, 0x10000000, 0x00000003}, + {0x4A475459, 0x08000000, 0x00000003}, + {0x4A475559, 0x02000000, 0x00000003}, + {0x4A475641, 0x04000000, 0x00000002}, + {0x4A475659, 0x08000000, 0x00000002}, + {0x4A475741, 0x08000000, 0x00000005}, + {0x4A475743, 0x01000000, 0x00000002}, + {0x4A475859, 0x02000000, 0x00000003}, + {0x4A475941, 0x04000000, 0x00000002}, + {0x4A475942, 0x02000000, 0x00000002}, + {0x4A475943, 0x04000000, 0x00000001}, + {0x4A475959, 0x04000000, 0x00000002}, + {0x4A475A41, 0x01000000, 0x00000003}, + {0x4A475A59, 0x02000000, 0x00000002}, + {0x4A483241, 0x01000000, 0x00000005}, + {0x4A483342, 0x04000000, 0x00000002}, + {0x4A483441, 0x02000000, 0x00000002}, + {0x4A483443, 0x08000000, 0x00000002}, + {0x4A483641, 0x02000000, 0x00000002}, + {0x4A483643, 0x01000000, 0x00000001}, + {0x4A483841, 0x00800000, 0x00000001}, + {0x4A484241, 0x08000000, 0x00000002}, + {0x4A484341, 0x04000000, 0x00000005}, + {0x4A484354, 0x04000000, 0x00000002}, + {0x4A484359, 0x04000000, 0x00000005}, + {0x4A484441, 0x04000000, 0x00000005}, + {0x4A484443, 0x01000000, 0x00000002}, + {0x4A484541, 0x04000000, 0x00000002}, + {0x4A484543, 0x08000000, 0x00000002}, + {0x4A484641, 0x01000000, 0x00000002}, + {0x4A484759, 0x08000000, 0x00000001}, + {0x4A484843, 0x01000000, 0x00000003}, + {0x4A484859, 0x02000000, 0x00000002}, + {0x4A484941, 0x08000000, 0x00000002}, + {0x4A484A41, 0x01000000, 0x00000002}, + {0x4A484A43, 0x04000000, 0x00000003}, + {0x4A484A54, 0x04000000, 0x00000005}, + {0x4A484A59, 0x01000000, 0x00000002}, + {0x4A484B41, 0x04000000, 0x00000002}, + {0x4A484B42, 0x04000000, 0x00000003}, + {0x4A484B59, 0x08000000, 0x00000005}, + {0x4A484C41, 0x02000000, 0x00000001}, + {0x4A484C59, 0x04000000, 0x00000002}, + {0x4A484D41, 0x04000000, 0x00000005}, + {0x4A484D59, 0x04000000, 0x00000003}, + {0x4A484E41, 0x08000000, 0x00000006}, + {0x4A484E42, 0x01000000, 0x00000002}, + {0x4A484E59, 0x02000000, 0x00000003}, + {0x4A484F41, 0x02000000, 0x00000003}, + {0x4A484F42, 0x00800000, 0x00000003}, + {0x4A484F43, 0x10000000, 0x00000002}, + {0x4A484F59, 0x02000000, 0x00000002}, + {0x4A485041, 0x02000000, 0x00000003}, + {0x4A485042, 0x02000000, 0x00000005}, + {0x4A485054, 0x04000000, 0x00000005}, + {0x4A485141, 0x04000000, 0x00000002}, + {0x4A485143, 0x04000000, 0x00000001}, + {0x4A485154, 0x08000000, 0x00000004}, + {0x4A485159, 0x01000000, 0x00000002}, + {0x4A485242, 0x08000000, 0x00000002}, + {0x4A485259, 0x02000000, 0x00000001}, + {0x4A485341, 0x02000000, 0x00000002}, + {0x4A485343, 0x02000000, 0x00000002}, + {0x4A485443, 0x01000000, 0x00000002}, + {0x4A485459, 0x08000000, 0x00000003}, + {0x4A485541, 0x01000000, 0x00000001}, + {0x4A485543, 0x02000000, 0x00000003}, + {0x4A485659, 0x01000000, 0x00000003}, + {0x4A485841, 0x01000000, 0x00000003}, + {0x4A485856, 0x08000000, 0x00000002}, + {0x4A485859, 0x02000000, 0x00000003}, + {0x4A485941, 0x04000000, 0x00000002}, + {0x4A485A41, 0x04000000, 0x00000002}, + {0x4A493241, 0x01000000, 0x00000005}, + {0x4A493341, 0x08000000, 0x00000002}, + {0x4A493342, 0x04000000, 0x00000002}, + {0x4A493442, 0x08000000, 0x00000005}, + {0x4A493443, 0x04000000, 0x00000002}, + {0x4A493543, 0x04000000, 0x00000002}, + {0x4A493641, 0x08000000, 0x00000003}, + {0x4A493841, 0x02000000, 0x00000002}, + {0x4A494143, 0x02000000, 0x00000002}, + {0x4A494241, 0x00800000, 0x00000005}, + {0x4A494259, 0x04000000, 0x00000002}, + {0x4A494341, 0x01000000, 0x00000002}, + {0x4A494441, 0x08000000, 0x00000001}, + {0x4A494459, 0x04000000, 0x00000002}, + {0x4A494555, 0x04000000, 0x00000002}, + {0x4A494559, 0x04000000, 0x00000002}, + {0x4A494643, 0x08000000, 0x00000003}, + {0x4A494841, 0x04000000, 0x00000003}, + {0x4A494843, 0x10000000, 0x00000003}, + {0x4A494859, 0x04000000, 0x00000001}, + {0x4A494941, 0x01000000, 0x00000002}, + {0x4A494959, 0x00800000, 0x00000001}, + {0x4A494B42, 0x08000000, 0x00000007}, + {0x4A494B59, 0x04000000, 0x00000003}, + {0x4A494C42, 0x04000000, 0x00000003}, + {0x4A494C59, 0x04000000, 0x00000002}, + {0x4A494D41, 0x00800000, 0x00000002}, + {0x4A494E41, 0x08000000, 0x00000005}, + {0x4A494F41, 0x02000000, 0x00000006}, + {0x4A494F43, 0x10000000, 0x00000002}, + {0x4A495041, 0x04000000, 0x00000005}, + {0x4A495059, 0x01000000, 0x00000003}, + {0x4A495141, 0x02000000, 0x00000005}, + {0x4A495142, 0x08000000, 0x00000002}, + {0x4A495143, 0x01000000, 0x00000002}, + {0x4A495241, 0x01000000, 0x00000001}, + {0x4A495242, 0x04000000, 0x00000001}, + {0x4A495243, 0x02000000, 0x00000002}, + {0x4A495341, 0x02000000, 0x00000002}, + {0x4A495441, 0x01000000, 0x00000008}, + {0x4A495459, 0x08000000, 0x00000003}, + {0x4A495559, 0x01000000, 0x00000002}, + {0x4A495641, 0x02000000, 0x00000001}, + {0x4A495642, 0x04000000, 0x00000002}, + {0x4A495643, 0x04000000, 0x00000002}, + {0x4A495659, 0x08000000, 0x00000003}, + {0x4A495741, 0x08000000, 0x00000005}, + {0x4A495759, 0x02000000, 0x00000002}, + {0x4A495841, 0x02000000, 0x00000002}, + {0x4A495843, 0x04000000, 0x00000005}, + {0x4A495859, 0x02000000, 0x00000003}, + {0x4A495941, 0x01000000, 0x00000001}, + {0x4A495A41, 0x00800000, 0x00000002}, + {0x4A495A59, 0x01000000, 0x00000002}, + {0x4A4A3241, 0x04000000, 0x00000003}, + {0x4A4A3242, 0x10000000, 0x00000003}, + {0x4A4A3343, 0x10000000, 0x00000003}, + {0x4A4A3441, 0x00800000, 0x00000002}, + {0x4A4A3543, 0x01000000, 0x00000002}, + {0x4A4A3641, 0x04000000, 0x00000002}, + {0x4A4A3842, 0x10000000, 0x00000005}, + {0x4A4A4241, 0x04000000, 0x00000005}, + {0x4A4A4242, 0x04000000, 0x00000003}, + {0x4A4A4441, 0x04000000, 0x00000005}, + {0x4A4A4541, 0x02000000, 0x00000002}, + {0x4A4A4659, 0x04000000, 0x00000003}, + {0x4A4A4843, 0x04000000, 0x00000002}, + {0x4A4A4859, 0x00800000, 0x00000003}, + {0x4A4A4941, 0x02000000, 0x00000003}, + {0x4A4A4A59, 0x04000000, 0x00000002}, + {0x4A4A4B41, 0x01000000, 0x00000003}, + {0x4A4A4B42, 0x01000000, 0x00000002}, + {0x4A4A4B59, 0x08000000, 0x00000002}, + {0x4A4A4C43, 0x08000000, 0x00000002}, + {0x4A4A4D41, 0x02000000, 0x00000005}, + {0x4A4A4D59, 0x04000000, 0x00000001}, + {0x4A4A4F41, 0x02000000, 0x00000002}, + {0x4A4A4F42, 0x04000000, 0x00000002}, + {0x4A4A4F59, 0x01000000, 0x00000002}, + {0x4A4A5041, 0x04000000, 0x00000005}, + {0x4A4A5059, 0x04000000, 0x00000005}, + {0x4A4A5142, 0x02000000, 0x00000003}, + {0x4A4A5154, 0x04000000, 0x00000003}, + {0x4A4A5241, 0x08000000, 0x00000003}, + {0x4A4A5242, 0x08000000, 0x00000003}, + {0x4A4A5341, 0x04000000, 0x00000005}, + {0x4A4A5343, 0x08000000, 0x00000002}, + {0x4A4A5443, 0x08000000, 0x00000002}, + {0x4A4A5559, 0x04000000, 0x00000001}, + {0x4A4A5641, 0x04000000, 0x00000002}, + {0x4A4A5643, 0x04000000, 0x00000002}, + {0x4A4A5841, 0x04000000, 0x00000003}, + {0x4A4A5859, 0x08000000, 0x00000005}, + {0x4A4A5941, 0x02000000, 0x00000005}, + {0x4A4A5943, 0x04000000, 0x00000002}, + {0x4A4A5959, 0x01000000, 0x00000002}, + {0x4A4A5A59, 0x01000000, 0x00000002}, + {0x4A4B3241, 0x04000000, 0x00000005}, + {0x4A4B3242, 0x20000000, 0x00000003}, + {0x4A4B3341, 0x00800000, 0x00000003}, + {0x4A4B3343, 0x00800000, 0x00000003}, + {0x4A4B3441, 0x00800000, 0x00000002}, + {0x4A4B3442, 0x01000000, 0x00000002}, + {0x4A4B3541, 0x01000000, 0x00000003}, + {0x4A4B3542, 0x04000000, 0x00000002}, + {0x4A4B3543, 0x04000000, 0x00000002}, + {0x4A4B3641, 0x08000000, 0x00000003}, + {0x4A4B3643, 0x04000000, 0x00000002}, + {0x4A4B3742, 0x04000000, 0x00000002}, + {0x4A4B3743, 0x04000000, 0x00000002}, + {0x4A4B3841, 0x02000000, 0x00000003}, + {0x4A4B4154, 0x04000000, 0x00000002}, + {0x4A4B4241, 0x01000000, 0x00000001}, + {0x4A4B4243, 0x04000000, 0x00000002}, + {0x4A4B4341, 0x02000000, 0x00000005}, + {0x4A4B4342, 0x04000000, 0x00000002}, + {0x4A4B4354, 0x02000000, 0x00000001}, + {0x4A4B4441, 0x04000000, 0x00000005}, + {0x4A4B4443, 0x01000000, 0x00000002}, + {0x4A4B4459, 0x01000000, 0x00000002}, + {0x4A4B4542, 0x08000000, 0x00000003}, + {0x4A4B4543, 0x04000000, 0x00000002}, + {0x4A4B4559, 0x08000000, 0x00000005}, + {0x4A4B4659, 0x04000000, 0x00000002}, + {0x4A4B4743, 0x02000000, 0x00000001}, + {0x4A4B4754, 0x04000000, 0x00000001}, + {0x4A4B4841, 0x04000000, 0x00000003}, + {0x4A4B4842, 0x01000000, 0x00000002}, + {0x4A4B4859, 0x01000000, 0x00000002}, + {0x4A4B4941, 0x02000000, 0x00000002}, + {0x4A4B4942, 0x04000000, 0x00000005}, + {0x4A4B4943, 0x04000000, 0x00000001}, + {0x4A4B4959, 0x02000000, 0x00000005}, + {0x4A4B4A41, 0x08000000, 0x00000002}, + {0x4A4B4A42, 0x01000000, 0x00000002}, + {0x4A4B4A43, 0x08000000, 0x00000003}, + {0x4A4B4B41, 0x01000000, 0x00000003}, + {0x4A4B4B42, 0x08000000, 0x00000003}, + {0x4A4B4B43, 0x10000000, 0x00000002}, + {0x4A4B4B59, 0x02000000, 0x00000002}, + {0x4A4B4C41, 0x08000000, 0x00000003}, + {0x4A4B4C59, 0x02000000, 0x00000002}, + {0x4A4B4D41, 0x00800000, 0x00000002}, + {0x4A4B4D54, 0x04000000, 0x00000002}, + {0x4A4B4D59, 0x08000000, 0x00000001}, + {0x4A4B4E41, 0x00800000, 0x00000001}, + {0x4A4B4E42, 0x02000000, 0x00000003}, + {0x4A4B4E43, 0x04000000, 0x00000002}, + {0x4A4B4E59, 0x04000000, 0x00000002}, + {0x4A4B4F42, 0x10000000, 0x00000002}, + {0x4A4B4F43, 0x00800000, 0x00000002}, + {0x4A4B4F59, 0x01000000, 0x00000002}, + {0x4A4B5041, 0x02000000, 0x00000005}, + {0x4A4B5049, 0x08000000, 0x00000006}, + {0x4A4B5059, 0x04000000, 0x00000002}, + {0x4A4B5141, 0x02000000, 0x00000002}, + {0x4A4B5154, 0x02000000, 0x00000003}, + {0x4A4B5241, 0x04000000, 0x00000002}, + {0x4A4B5341, 0x04000000, 0x00000002}, + {0x4A4B5342, 0x08000000, 0x00000003}, + {0x4A4B5343, 0x08000000, 0x00000003}, + {0x4A4B5359, 0x08000000, 0x00000003}, + {0x4A4B5441, 0x04000000, 0x00000002}, + {0x4A4B5443, 0x08000000, 0x00000002}, + {0x4A4B5459, 0x04000000, 0x00000003}, + {0x4A4B5541, 0x01000000, 0x00000001}, + {0x4A4B5542, 0x08000000, 0x00000002}, + {0x4A4B5543, 0x08000000, 0x00000002}, + {0x4A4B5641, 0x01000000, 0x00000001}, + {0x4A4B5743, 0x02000000, 0x00000003}, + {0x4A4B5841, 0x01000000, 0x00000002}, + {0x4A4B5859, 0x08000000, 0x00000005}, + {0x4A4B5941, 0x02000000, 0x00000005}, + {0x4A4B5959, 0x04000000, 0x00000002}, + {0x4A4B5A41, 0x00800000, 0x00000002}, + {0x4A4B5A42, 0x02000000, 0x00000003}, + {0x4A4B5A43, 0x04000000, 0x00000002}, + {0x4A4B5A59, 0x10000000, 0x00000003}, + {0x4A4C3243, 0x04000000, 0x00000002}, + {0x4A4C3341, 0x00800000, 0x00000002}, + {0x4A4C3342, 0x20000000, 0x00000003}, + {0x4A4C3441, 0x01000000, 0x00000002}, + {0x4A4C3442, 0x02000000, 0x00000002}, + {0x4A4C3641, 0x00800000, 0x00000002}, + {0x4A4C4142, 0x10000000, 0x00000003}, + {0x4A4C4159, 0x02000000, 0x00000003}, + {0x4A4C4241, 0x08000000, 0x00000002}, + {0x4A4C4341, 0x04000000, 0x00000003}, + {0x4A4C4342, 0x01000000, 0x00000002}, + {0x4A4C4441, 0x04000000, 0x00000003}, + {0x4A4C4541, 0x04000000, 0x00000002}, + {0x4A4C4542, 0x02000000, 0x00000002}, + {0x4A4C4559, 0x02000000, 0x00000001}, + {0x4A4C4654, 0x08000000, 0x00000003}, + {0x4A4C4659, 0x04000000, 0x00000003}, + {0x4A4C4741, 0x02000000, 0x00000001}, + {0x4A4C4841, 0x01000000, 0x00000003}, + {0x4A4C4843, 0x04000000, 0x00000002}, + {0x4A4C4854, 0x20000000, 0x00000002}, + {0x4A4C4859, 0x08000000, 0x00000003}, + {0x4A4C4941, 0x00800000, 0x00000002}, + {0x4A4C4943, 0x02000000, 0x00000001}, + {0x4A4C4959, 0x10000000, 0x00000002}, + {0x4A4C4B41, 0x04000000, 0x00000005}, + {0x4A4C4B42, 0x10000000, 0x00000002}, + {0x4A4C4C41, 0x00800000, 0x00000003}, + {0x4A4C4C59, 0x00800000, 0x00000002}, + {0x4A4C4E43, 0x04000000, 0x00000001}, + {0x4A4C4F42, 0x01000000, 0x00000003}, + {0x4A4C4F43, 0x08000000, 0x00000003}, + {0x4A4C4F59, 0x08000000, 0x00000002}, + {0x4A4C5041, 0x00800000, 0x00000002}, + {0x4A4C5056, 0x08000000, 0x00000006}, + {0x4A4C5154, 0x02000000, 0x00000003}, + {0x4A4C5241, 0x01000000, 0x00000005}, + {0x4A4C5342, 0x02000000, 0x00000003}, + {0x4A4C5359, 0x10000000, 0x00000005}, + {0x4A4C5559, 0x04000000, 0x00000002}, + {0x4A4C5641, 0x02000000, 0x00000002}, + {0x4A4C5642, 0x04000000, 0x00000002}, + {0x4A4C5659, 0x04000000, 0x00000003}, + {0x4A4C5741, 0x08000000, 0x00000003}, + {0x4A4C5759, 0x02000000, 0x00000001}, + {0x4A4C5859, 0x08000000, 0x00000005}, + {0x4A4C5A41, 0x08000000, 0x00000007}, + {0x4A4C5A59, 0x08000000, 0x00000001}, + {0x4A4D3341, 0x08000000, 0x00000002}, + {0x4A4D3541, 0x02000000, 0x00000002}, + {0x4A4D3842, 0x10000000, 0x00000005}, + {0x4A4D4241, 0x00800000, 0x00000001}, + {0x4A4D4259, 0x01000000, 0x00000002}, + {0x4A4D4341, 0x01000000, 0x00000001}, + {0x4A4D4354, 0x04000000, 0x00000002}, + {0x4A4D4441, 0x02000000, 0x00000005}, + {0x4A4D4541, 0x08000000, 0x00000003}, + {0x4A4D4559, 0x02000000, 0x00000003}, + {0x4A4D4641, 0x04000000, 0x00000002}, + {0x4A4D4643, 0x04000000, 0x00000003}, + {0x4A4D4659, 0x04000000, 0x00000003}, + {0x4A4D4743, 0x08000000, 0x00000003}, + {0x4A4D4759, 0x04000000, 0x00000002}, + {0x4A4D4841, 0x02000000, 0x00000002}, + {0x4A4D4854, 0x10000000, 0x00000005}, + {0x4A4D4859, 0x02000000, 0x00000002}, + {0x4A4D4941, 0x01000000, 0x00000005}, + {0x4A4D4942, 0x04000000, 0x00000005}, + {0x4A4D4956, 0x10000000, 0x00000003}, + {0x4A4D4A41, 0x01000000, 0x00000003}, + {0x4A4D4A42, 0x04000000, 0x00000001}, + {0x4A4D4B41, 0x08000000, 0x00000003}, + {0x4A4D4B42, 0x02000000, 0x00000002}, + {0x4A4D4B43, 0x01000000, 0x00000003}, + {0x4A4D4B54, 0x04000000, 0x00000005}, + {0x4A4D4B59, 0x01000000, 0x00000005}, + {0x4A4D4C43, 0x08000000, 0x00000003}, + {0x4A4D4D41, 0x00800000, 0x00000001}, + {0x4A4D4D43, 0x02000000, 0x00000003}, + {0x4A4D4D56, 0x04000000, 0x00000003}, + {0x4A4D4E41, 0x02000000, 0x00000005}, + {0x4A4D4E59, 0x01000000, 0x00000002}, + {0x4A4D4F41, 0x01000000, 0x00000002}, + {0x4A4D4F59, 0x04000000, 0x00000002}, + {0x4A4D5041, 0x01000000, 0x00000001}, + {0x4A4D5043, 0x04000000, 0x00000002}, + {0x4A4D5142, 0x01000000, 0x00000001}, + {0x4A4D5154, 0x08000000, 0x00000004}, + {0x4A4D5159, 0x04000000, 0x00000002}, + {0x4A4D5241, 0x04000000, 0x00000002}, + {0x4A4D5242, 0x01000000, 0x00000002}, + {0x4A4D5243, 0x02000000, 0x00000003}, + {0x4A4D5341, 0x01000000, 0x00000002}, + {0x4A4D5359, 0x08000000, 0x00000003}, + {0x4A4D5441, 0x08000000, 0x00000002}, + {0x4A4D5443, 0x04000000, 0x00000002}, + {0x4A4D5459, 0x04000000, 0x00000002}, + {0x4A4D5541, 0x02000000, 0x00000005}, + {0x4A4D5543, 0x02000000, 0x00000002}, + {0x4A4D5559, 0x00800000, 0x00000002}, + {0x4A4D5641, 0x04000000, 0x00000006}, + {0x4A4D5743, 0x10000000, 0x00000003}, + {0x4A4D5843, 0x04000000, 0x00000003}, + {0x4A4D5859, 0x02000000, 0x00000003}, + {0x4A4D5941, 0x01000000, 0x00000003}, + {0x4A4D5942, 0x04000000, 0x00000002}, + {0x4A4D5943, 0x02000000, 0x00000002}, + {0x4A4D5959, 0x10000000, 0x00000003}, + {0x4A4D5A41, 0x01000000, 0x00000002}, + {0x4A4D5A42, 0x04000000, 0x00000006}, + {0x4A4D5A59, 0x01000000, 0x00000002}, + {0x4A4E3242, 0x02000000, 0x00000001}, + {0x4A4E3343, 0x04000000, 0x00000003}, + {0x4A4E3441, 0x00800000, 0x00000002}, + {0x4A4E3442, 0x00800000, 0x00000002}, + {0x4A4E3443, 0x04000000, 0x00000003}, + {0x4A4E3641, 0x08000000, 0x00000003}, + {0x4A4E3841, 0x02000000, 0x00000005}, + {0x4A4E4156, 0x02000000, 0x00000007}, + {0x4A4E4159, 0x04000000, 0x00000002}, + {0x4A4E4241, 0x04000000, 0x00000002}, + {0x4A4E4259, 0x02000000, 0x00000007}, + {0x4A4E4341, 0x01000000, 0x00000002}, + {0x4A4E4342, 0x08000000, 0x00000005}, + {0x4A4E4359, 0x08000000, 0x00000001}, + {0x4A4E4441, 0x04000000, 0x00000003}, + {0x4A4E4442, 0x04000000, 0x00000003}, + {0x4A4E4459, 0x04000000, 0x00000002}, + {0x4A4E4541, 0x04000000, 0x00000002}, + {0x4A4E4554, 0x20000000, 0x00000002}, + {0x4A4E4641, 0x02000000, 0x00000002}, + {0x4A4E4643, 0x04000000, 0x00000002}, + {0x4A4E4842, 0x10000000, 0x00000002}, + {0x4A4E4859, 0x04000000, 0x00000003}, + {0x4A4E4941, 0x04000000, 0x00000002}, + {0x4A4E4943, 0x08000000, 0x00000002}, + {0x4A4E4959, 0x00800000, 0x00000001}, + {0x4A4E4A41, 0x02000000, 0x00000002}, + {0x4A4E4A59, 0x04000000, 0x00000002}, + {0x4A4E4B41, 0x01000000, 0x00000001}, + {0x4A4E4B43, 0x08000000, 0x00000002}, + {0x4A4E4B54, 0x04000000, 0x00000002}, + {0x4A4E4B56, 0x02000000, 0x00000003}, + {0x4A4E4B59, 0x01000000, 0x00000002}, + {0x4A4E4D41, 0x01000000, 0x00000005}, + {0x4A4E4E41, 0x04000000, 0x00000003}, + {0x4A4E4E42, 0x04000000, 0x00000002}, + {0x4A4E4E59, 0x08000000, 0x00000003}, + {0x4A4E4F41, 0x02000000, 0x00000005}, + {0x4A4E4F42, 0x08000000, 0x00000003}, + {0x4A4E4F43, 0x01000000, 0x00000005}, + {0x4A4E4F59, 0x01000000, 0x00000003}, + {0x4A4E5041, 0x02000000, 0x00000001}, + {0x4A4E5141, 0x01000000, 0x00000002}, + {0x4A4E5143, 0x02000000, 0x00000002}, + {0x4A4E5154, 0x04000000, 0x00000000}, + {0x4A4E5159, 0x04000000, 0x00000002}, + {0x4A4E5241, 0x01000000, 0x00000001}, + {0x4A4E5341, 0x00800000, 0x00000002}, + {0x4A4E5459, 0x08000000, 0x00000003}, + {0x4A4E5541, 0x00800000, 0x00000002}, + {0x4A4E5543, 0x10000000, 0x00000003}, + {0x4A4E5559, 0x04000000, 0x00000003}, + {0x4A4E5641, 0x08000000, 0x00000002}, + {0x4A4E5741, 0x08000000, 0x00000002}, + {0x4A4E5742, 0x02000000, 0x00000002}, + {0x4A4E5743, 0x04000000, 0x00000002}, + {0x4A4E5841, 0x00800000, 0x00000002}, + {0x4A4E5859, 0x02000000, 0x00000003}, + {0x4A4E5941, 0x04000000, 0x00000003}, + {0x4A4E5942, 0x04000000, 0x00000003}, + {0x4A4E5959, 0x02000000, 0x00000001}, + {0x4A4E5A59, 0x04000000, 0x00000002}, + {0x4A4F3241, 0x04000000, 0x00000003}, + {0x4A4F3242, 0x02000000, 0x00000005}, + {0x4A4F3341, 0x00800000, 0x00000001}, + {0x4A4F3343, 0x08000000, 0x00000002}, + {0x4A4F3441, 0x02000000, 0x00000005}, + {0x4A4F3641, 0x02000000, 0x00000002}, + {0x4A4F3643, 0x08000000, 0x00000003}, + {0x4A4F4242, 0x00800000, 0x00000001}, + {0x4A4F4243, 0x02000000, 0x00000005}, + {0x4A4F4341, 0x04000000, 0x00000005}, + {0x4A4F4359, 0x04000000, 0x00000001}, + {0x4A4F4459, 0x02000000, 0x00000002}, + {0x4A4F4541, 0x02000000, 0x00000001}, + {0x4A4F4559, 0x04000000, 0x00000003}, + {0x4A4F4641, 0x04000000, 0x00000003}, + {0x4A4F4741, 0x04000000, 0x00000005}, + {0x4A4F4841, 0x01000000, 0x00000002}, + {0x4A4F4859, 0x01000000, 0x00000002}, + {0x4A4F4941, 0x08000000, 0x00000005}, + {0x4A4F4B41, 0x08000000, 0x00000003}, + {0x4A4F4B59, 0x02000000, 0x00000006}, + {0x4A4F4C43, 0x01000000, 0x00000001}, + {0x4A4F4D41, 0x04000000, 0x00000002}, + {0x4A4F4D42, 0x08000000, 0x00000005}, + {0x4A4F4D43, 0x02000000, 0x00000003}, + {0x4A4F4E41, 0x02000000, 0x00000002}, + {0x4A4F4E43, 0x04000000, 0x00000002}, + {0x4A4F4F41, 0x01000000, 0x00000002}, + {0x4A4F4F42, 0x08000000, 0x00000002}, + {0x4A4F4F59, 0x04000000, 0x00000003}, + {0x4A4F5041, 0x04000000, 0x00000001}, + {0x4A4F5042, 0x04000000, 0x00000003}, + {0x4A4F5059, 0x04000000, 0x00000003}, + {0x4A4F5141, 0x04000000, 0x00000003}, + {0x4A4F5241, 0x08000000, 0x00000003}, + {0x4A4F5242, 0x04000000, 0x00000003}, + {0x4A4F5259, 0x04000000, 0x00000002}, + {0x4A4F5441, 0x04000000, 0x00000002}, + {0x4A4F5442, 0x04000000, 0x00000002}, + {0x4A4F5443, 0x04000000, 0x00000001}, + {0x4A4F5459, 0x04000000, 0x00000002}, + {0x4A4F5559, 0x10000000, 0x00000003}, + {0x4A4F5641, 0x01000000, 0x00000003}, + {0x4A4F5659, 0x02000000, 0x00000002}, + {0x4A4F5842, 0x04000000, 0x00000003}, + {0x4A4F5859, 0x04000000, 0x00000005}, + {0x4A4F5941, 0x04000000, 0x00000003}, + {0x4A4F5942, 0x04000000, 0x00000003}, + {0x4A4F5A59, 0x08000000, 0x00000002}, + {0x4A503242, 0x04000000, 0x00000005}, + {0x4A503243, 0x04000000, 0x00000003}, + {0x4A503341, 0x02000000, 0x00000001}, + {0x4A503443, 0x01000000, 0x00000002}, + {0x4A503541, 0x04000000, 0x00000001}, + {0x4A503542, 0x10000000, 0x00000001}, + {0x4A503543, 0x02000000, 0x00000002}, + {0x4A503641, 0x00800000, 0x00000003}, + {0x4A503643, 0x02000000, 0x00000007}, + {0x4A503742, 0x08000000, 0x00000003}, + {0x4A503841, 0x02000000, 0x00000002}, + {0x4A503842, 0x02000000, 0x00000003}, + {0x4A504142, 0x04000000, 0x00000001}, + {0x4A504341, 0x00800000, 0x00000002}, + {0x4A504356, 0x04000000, 0x00000003}, + {0x4A504359, 0x04000000, 0x00000001}, + {0x4A504441, 0x00800000, 0x00000002}, + {0x4A504459, 0x02000000, 0x00000001}, + {0x4A504541, 0x01000000, 0x00000003}, + {0x4A504641, 0x04000000, 0x00000001}, + {0x4A504642, 0x04000000, 0x00000002}, + {0x4A504654, 0x04000000, 0x00000005}, + {0x4A504741, 0x04000000, 0x00000002}, + {0x4A504759, 0x02000000, 0x00000003}, + {0x4A504841, 0x04000000, 0x00000001}, + {0x4A504843, 0x01000000, 0x00000001}, + {0x4A504859, 0x01000000, 0x00000002}, + {0x4A504942, 0x04000000, 0x00000002}, + {0x4A504943, 0x02000000, 0x00000002}, + {0x4A504959, 0x04000000, 0x00000001}, + {0x4A504A42, 0x02000000, 0x00000002}, + {0x4A504B42, 0x04000000, 0x00000002}, + {0x4A504B56, 0x02000000, 0x00000005}, + {0x4A504C59, 0x00800000, 0x00000002}, + {0x4A504D54, 0x08000000, 0x00000003}, + {0x4A504D59, 0x08000000, 0x00000005}, + {0x4A505042, 0x04000000, 0x00000005}, + {0x4A505054, 0x04000000, 0x00000007}, + {0x4A505059, 0x01000000, 0x00000001}, + {0x4A505142, 0x04000000, 0x00000002}, + {0x4A505159, 0x02000000, 0x00000002}, + {0x4A505242, 0x08000000, 0x00000003}, + {0x4A505341, 0x02000000, 0x00000003}, + {0x4A505343, 0x02000000, 0x00000003}, + {0x4A505359, 0x02000000, 0x00000005}, + {0x4A505441, 0x04000000, 0x00000005}, + {0x4A505541, 0x00800000, 0x00000001}, + {0x4A505559, 0x04000000, 0x00000002}, + {0x4A505641, 0x04000000, 0x00000002}, + {0x4A505643, 0x10000000, 0x00000002}, + {0x4A505659, 0x08000000, 0x00000003}, + {0x4A505759, 0x04000000, 0x00000002}, + {0x4A505841, 0x02000000, 0x00000005}, + {0x4A505842, 0x04000000, 0x00000002}, + {0x4A505859, 0x02000000, 0x00000003}, + {0x4A505A41, 0x01000000, 0x00000002}, + {0x4A505A55, 0x08000000, 0x00000003}, + {0x4A505A59, 0x02000000, 0x00000002}, + {0x4A513242, 0x04000000, 0x00000001}, + {0x4A513341, 0x04000000, 0x00000003}, + {0x4A513441, 0x01000000, 0x00000001}, + {0x4A513442, 0x02000000, 0x00000002}, + {0x4A513541, 0x01000000, 0x00000001}, + {0x4A513641, 0x01000000, 0x00000001}, + {0x4A513742, 0x04000000, 0x00000005}, + {0x4A513841, 0x02000000, 0x00000005}, + {0x4A514154, 0x04000000, 0x00000004}, + {0x4A514159, 0x04000000, 0x00000003}, + {0x4A514254, 0x04000000, 0x00000002}, + {0x4A514341, 0x02000000, 0x00000001}, + {0x4A514359, 0x04000000, 0x00000002}, + {0x4A514441, 0x04000000, 0x00000002}, + {0x4A514443, 0x08000000, 0x00000001}, + {0x4A514459, 0x10000000, 0x00000003}, + {0x4A514541, 0x00800000, 0x00000002}, + {0x4A514542, 0x04000000, 0x00000002}, + {0x4A514641, 0x02000000, 0x00000002}, + {0x4A514654, 0x04000000, 0x00000007}, + {0x4A514659, 0x04000000, 0x00000002}, + {0x4A514842, 0x04000000, 0x00000002}, + {0x4A514859, 0x04000000, 0x00000003}, + {0x4A514941, 0x00800000, 0x00000002}, + {0x4A514959, 0x08000000, 0x00000002}, + {0x4A514A41, 0x02000000, 0x00000002}, + {0x4A514B41, 0x02000000, 0x00000001}, + {0x4A514B59, 0x04000000, 0x00000003}, + {0x4A514D41, 0x04000000, 0x00000005}, + {0x4A514E41, 0x00800000, 0x00000002}, + {0x4A514E43, 0x02000000, 0x00000003}, + {0x4A514E59, 0x00800000, 0x00000002}, + {0x4A514F41, 0x04000000, 0x00000001}, + {0x4A514F42, 0x02000000, 0x00000005}, + {0x4A514F59, 0x08000000, 0x00000002}, + {0x4A515054, 0x04000000, 0x00000002}, + {0x4A515059, 0x01000000, 0x00000001}, + {0x4A515141, 0x02000000, 0x00000002}, + {0x4A515241, 0x04000000, 0x00000003}, + {0x4A515242, 0x04000000, 0x00000005}, + {0x4A515341, 0x00800000, 0x00000002}, + {0x4A515541, 0x01000000, 0x00000002}, + {0x4A515542, 0x08000000, 0x00000001}, + {0x4A515559, 0x01000000, 0x00000002}, + {0x4A515741, 0x01000000, 0x00000001}, + {0x4A515859, 0x02000000, 0x00000003}, + {0x4A515942, 0x02000000, 0x00000002}, + {0x4A515959, 0x01000000, 0x00000002}, + {0x4A515A42, 0x08000000, 0x00000003}, + {0x4A515A59, 0x01000000, 0x00000005}, + {0x4A523241, 0x01000000, 0x00000003}, + {0x4A523342, 0x08000000, 0x00000005}, + {0x4A523343, 0x04000000, 0x00000002}, + {0x4A523356, 0x02000000, 0x00000003}, + {0x4A523441, 0x02000000, 0x00000002}, + {0x4A523541, 0x01000000, 0x00000002}, + {0x4A523543, 0x08000000, 0x00000003}, + {0x4A523641, 0x04000000, 0x00000003}, + {0x4A523643, 0x04000000, 0x00000003}, + {0x4A523841, 0x04000000, 0x00000005}, + {0x4A523842, 0x04000000, 0x00000002}, + {0x4A524142, 0x02000000, 0x00000005}, + {0x4A524255, 0x00800000, 0x00000005}, + {0x4A524259, 0x04000000, 0x00000001}, + {0x4A524441, 0x01000000, 0x00000002}, + {0x4A524541, 0x01000000, 0x00000002}, + {0x4A524559, 0x04000000, 0x00000003}, + {0x4A524643, 0x08000000, 0x00000002}, + {0x4A524741, 0x04000000, 0x00000005}, + {0x4A524742, 0x02000000, 0x00000002}, + {0x4A524743, 0x04000000, 0x00000001}, + {0x4A524759, 0x08000000, 0x00000002}, + {0x4A524841, 0x02000000, 0x00000002}, + {0x4A524854, 0x20000000, 0x00000003}, + {0x4A524856, 0x04000000, 0x00000002}, + {0x4A524941, 0x01000000, 0x00000001}, + {0x4A524A41, 0x08000000, 0x00000005}, + {0x4A524A43, 0x08000000, 0x00000003}, + {0x4A524A59, 0x08000000, 0x00000002}, + {0x4A524B41, 0x04000000, 0x00000002}, + {0x4A524B43, 0x04000000, 0x00000003}, + {0x4A524B59, 0x04000000, 0x00000005}, + {0x4A524C41, 0x00800000, 0x00000002}, + {0x4A524D41, 0x01000000, 0x00000003}, + {0x4A524E41, 0x04000000, 0x00000001}, + {0x4A524E43, 0x04000000, 0x00000002}, + {0x4A524E54, 0x10000000, 0x00000003}, + {0x4A524E59, 0x04000000, 0x00000002}, + {0x4A524F42, 0x01000000, 0x00000003}, + {0x4A524F55, 0x02000000, 0x00000008}, + {0x4A525041, 0x02000000, 0x00000002}, + {0x4A525142, 0x02000000, 0x00000002}, + {0x4A525143, 0x04000000, 0x00000002}, + {0x4A525242, 0x10000000, 0x00000003}, + {0x4A525243, 0x02000000, 0x00000005}, + {0x4A525341, 0x04000000, 0x00000003}, + {0x4A525343, 0x10000000, 0x00000002}, + {0x4A525359, 0x01000000, 0x00000005}, + {0x4A525441, 0x01000000, 0x00000002}, + {0x4A52544E, 0x00180AC8, 0x00000000}, + {0x4A525541, 0x04000000, 0x00000002}, + {0x4A525543, 0x04000000, 0x00000001}, + {0x4A525559, 0x04000000, 0x00000003}, + {0x4A525641, 0x04000000, 0x00000002}, + {0x4A525659, 0x08000000, 0x00000002}, + {0x4A525741, 0x02000000, 0x00000005}, + {0x4A525742, 0x02000000, 0x00000003}, + {0x4A525841, 0x01000000, 0x00000002}, + {0x4A525959, 0x04000000, 0x00000001}, + {0x4A525A41, 0x08000000, 0x00000002}, + {0x4A525A59, 0x01000000, 0x00000002}, + {0x4A533243, 0x08000000, 0x00000004}, + {0x4A533342, 0x20000000, 0x00000003}, + {0x4A534159, 0x10000000, 0x00000005}, + {0x4A534241, 0x01000000, 0x00000005}, + {0x4A534254, 0x02000000, 0x00000002}, + {0x4A534259, 0x08000000, 0x00000003}, + {0x4A534342, 0x04000000, 0x00000002}, + {0x4A534459, 0x04000000, 0x00000002}, + {0x4A534559, 0x04000000, 0x00000003}, + {0x4A534654, 0x02000000, 0x00000003}, + {0x4A534659, 0x04000000, 0x00000002}, + {0x4A534841, 0x02000000, 0x00000002}, + {0x4A534A41, 0x001998C8, 0x00000002}, + {0x4A534A59, 0x02000000, 0x00000002}, + {0x4A534B41, 0x02000000, 0x00000002}, + {0x4A534B42, 0x02000000, 0x00000002}, + {0x4A534C41, 0x04000000, 0x00000002}, + {0x4A534C59, 0x04000000, 0x00000001}, + {0x4A534D41, 0x04000000, 0x00000003}, + {0x4A534D43, 0x02000000, 0x00000003}, + {0x4A534D59, 0x04000000, 0x00000005}, + {0x4A534E41, 0x01000000, 0x00000001}, + {0x4A534E43, 0x04000000, 0x00000002}, + {0x4A534E55, 0x00800000, 0x00000006}, + {0x4A534F41, 0x04000000, 0x00000002}, + {0x4A534F42, 0x01000000, 0x00000003}, + {0x4A534F56, 0x02000000, 0x00000007}, + {0x4A534F59, 0x00800000, 0x00000002}, + {0x4A535041, 0x04000000, 0x00000005}, + {0x4A535054, 0x04000000, 0x00000005}, + {0x4A535059, 0x01000000, 0x00000002}, + {0x4A535141, 0x02000000, 0x00000002}, + {0x4A535142, 0x01000000, 0x00000003}, + {0x4A535241, 0x08000000, 0x00000002}, + {0x4A535359, 0x04000000, 0x00000003}, + {0x4A535443, 0x04000000, 0x00000001}, + {0x4A535641, 0x02000000, 0x00000002}, + {0x4A535659, 0x02000000, 0x00000003}, + {0x4A535841, 0x04000000, 0x00000002}, + {0x4A535842, 0x04000000, 0x00000003}, + {0x4A535859, 0x02000000, 0x00000003}, + {0x4A535941, 0x04000000, 0x00000005}, + {0x4A535942, 0x04000000, 0x00000003}, + {0x4A535959, 0x01000000, 0x00000002}, + {0x4A535A41, 0x01000000, 0x00000003}, + {0x4A535A43, 0x04000000, 0x00000001}, + {0x4A535A59, 0x01000000, 0x00000002}, + {0x4A543243, 0x04000000, 0x00000003}, + {0x4A543342, 0x02000000, 0x00000001}, + {0x4A543442, 0x02000000, 0x00000002}, + {0x4A543443, 0x08000000, 0x00000002}, + {0x4A543541, 0x02000000, 0x00000005}, + {0x4A543841, 0x02000000, 0x00000002}, + {0x4A543842, 0x01000000, 0x00000001}, + {0x4A544143, 0x02000000, 0x00000002}, + {0x4A544259, 0x08000000, 0x00000003}, + {0x4A544341, 0x02000000, 0x00000001}, + {0x4A544343, 0x08000000, 0x00000003}, + {0x4A544354, 0x02000000, 0x00000005}, + {0x4A544356, 0x04000000, 0x00000003}, + {0x4A544359, 0x02000000, 0x00000001}, + {0x4A544459, 0x04000000, 0x00000003}, + {0x4A544541, 0x04000000, 0x00000001}, + {0x4A544542, 0x04000000, 0x00000005}, + {0x4A544543, 0x08000000, 0x00000002}, + {0x4A544654, 0x04000000, 0x00000002}, + {0x4A544659, 0x04000000, 0x00000005}, + {0x4A544741, 0x02000000, 0x00000002}, + {0x4A544742, 0x08000000, 0x00000002}, + {0x4A544843, 0x04000000, 0x00000002}, + {0x4A544854, 0x20000000, 0x00000003}, + {0x4A544859, 0x01000000, 0x00000001}, + {0x4A544942, 0x08000000, 0x00000005}, + {0x4A544A59, 0x08000000, 0x00000002}, + {0x4A544B41, 0x01000000, 0x00000001}, + {0x4A544B42, 0x04000000, 0x00000002}, + {0x4A544B54, 0x04000000, 0x00000002}, + {0x4A544B59, 0x02000000, 0x00000002}, + {0x4A544C54, 0x04000000, 0x00000003}, + {0x4A544C59, 0x08000000, 0x00000002}, + {0x4A544D41, 0x04000000, 0x00000002}, + {0x4A544D42, 0x08000000, 0x00000003}, + {0x4A544D56, 0x10000000, 0x00000002}, + {0x4A544E41, 0x04000000, 0x00000002}, + {0x4A544E43, 0x10000000, 0x00000003}, + {0x4A544E59, 0x10000000, 0x00000001}, + {0x4A544F41, 0x01000000, 0x00000002}, + {0x4A544F42, 0x01000000, 0x00000005}, + {0x4A544F43, 0x01000000, 0x00000005}, + {0x4A544F59, 0x04000000, 0x00000003}, + {0x4A545041, 0x01000000, 0x00000002}, + {0x4A545043, 0x04000000, 0x00000005}, + {0x4A545056, 0x08000000, 0x00000006}, + {0x4A545059, 0x02000000, 0x00000005}, + {0x4A545143, 0x04000000, 0x00000003}, + {0x4A545241, 0x08000000, 0x00000002}, + {0x4A545341, 0x02000000, 0x00000001}, + {0x4A545359, 0x04000000, 0x00000001}, + {0x4A545442, 0x04000000, 0x00000002}, + {0x4A545443, 0x08000000, 0x00000003}, + {0x4A545459, 0x08000000, 0x00000003}, + {0x4A545641, 0x04000000, 0x00000002}, + {0x4A545741, 0x00800000, 0x00000001}, + {0x4A545843, 0x10000000, 0x00000003}, + {0x4A545859, 0x02000000, 0x00000003}, + {0x4A545941, 0x08000000, 0x00000003}, + {0x4A545943, 0x04000000, 0x00000003}, + {0x4A545A41, 0x01000000, 0x00000005}, + {0x4A545A43, 0x02000000, 0x00000002}, + {0x4A545A59, 0x01000000, 0x00000005}, + {0x4A553241, 0x04000000, 0x00000002}, + {0x4A553341, 0x02000000, 0x00000001}, + {0x4A553343, 0x08000000, 0x00000002}, + {0x4A553441, 0x02000000, 0x00000002}, + {0x4A553442, 0x02000000, 0x00000003}, + {0x4A553443, 0x04000000, 0x00000001}, + {0x4A553641, 0x02000000, 0x00000001}, + {0x4A553841, 0x02000000, 0x00000002}, + {0x4A554241, 0x04000000, 0x00000005}, + {0x4A554242, 0x04000000, 0x00000003}, + {0x4A554259, 0x08000000, 0x00000003}, + {0x4A554341, 0x04000000, 0x00000005}, + {0x4A554343, 0x04000000, 0x00000006}, + {0x4A554441, 0x02000000, 0x00000003}, + {0x4A554459, 0x04000000, 0x00000003}, + {0x4A554541, 0x04000000, 0x00000003}, + {0x4A554542, 0x10000000, 0x00000003}, + {0x4A554641, 0x01000000, 0x00000003}, + {0x4A554656, 0x10000000, 0x00000005}, + {0x4A554659, 0x04000000, 0x00000002}, + {0x4A554741, 0x02000000, 0x00000002}, + {0x4A554742, 0x08000000, 0x00000003}, + {0x4A554759, 0x01000000, 0x00000002}, + {0x4A554843, 0x10000000, 0x00000003}, + {0x4A554A41, 0x04000000, 0x00000003}, + {0x4A554A42, 0x02000000, 0x00000003}, + {0x4A554A43, 0x04000000, 0x00000003}, + {0x4A554A59, 0x04000000, 0x00000002}, + {0x4A554B42, 0x08000000, 0x00000005}, + {0x4A554B43, 0x04000000, 0x00000003}, + {0x4A554B59, 0x04000000, 0x00000003}, + {0x4A554C41, 0x02000000, 0x00000002}, + {0x4A554C42, 0x08000000, 0x00000003}, + {0x4A554C59, 0x08000000, 0x00000005}, + {0x4A554E43, 0x02000000, 0x00000002}, + {0x4A554E59, 0x04000000, 0x00000003}, + {0x4A554F41, 0x01000000, 0x00000003}, + {0x4A555041, 0x02000000, 0x00000003}, + {0x4A555042, 0x04000000, 0x00000005}, + {0x4A555043, 0x08000000, 0x00000006}, + {0x4A555141, 0x08000000, 0x00000002}, + {0x4A555142, 0x04000000, 0x00000002}, + {0x4A555143, 0x02000000, 0x00000002}, + {0x4A555159, 0x08000000, 0x00000003}, + {0x4A555241, 0x02000000, 0x00000003}, + {0x4A555259, 0x00800000, 0x00000001}, + {0x4A555341, 0x04000000, 0x00000003}, + {0x4A555359, 0x00800000, 0x00000003}, + {0x4A555441, 0x04000000, 0x00000002}, + {0x4A555442, 0x04000000, 0x00000002}, + {0x4A555443, 0x10000000, 0x00000003}, + {0x4A555459, 0x04000000, 0x00000003}, + {0x4A555541, 0x00800000, 0x00000003}, + {0x4A555543, 0x00800000, 0x00000002}, + {0x4A555559, 0x02000000, 0x00000002}, + {0x4A555641, 0x08000000, 0x00000003}, + {0x4A555643, 0x04000000, 0x00000002}, + {0x4A555659, 0x04000000, 0x00000005}, + {0x4A555759, 0x02000000, 0x00000001}, + {0x4A555859, 0x02000000, 0x00000003}, + {0x4A555941, 0x02000000, 0x00000002}, + {0x4A555A41, 0x01000000, 0x00000002}, + {0x4A555A59, 0x04000000, 0x00000001}, + {0x4A563243, 0x10000000, 0x00000003}, + {0x4A563341, 0x04000000, 0x00000003}, + {0x4A563441, 0x08000000, 0x00000005}, + {0x4A563841, 0x04000000, 0x00000002}, + {0x4A563842, 0x02000000, 0x00000003}, + {0x4A564156, 0x04000000, 0x00000001}, + {0x4A564241, 0x02000000, 0x00000002}, + {0x4A564341, 0x04000000, 0x00000002}, + {0x4A564441, 0x01000000, 0x00000001}, + {0x4A564454, 0x08000000, 0x00000003}, + {0x4A564541, 0x04000000, 0x00000002}, + {0x4A564542, 0x10000000, 0x00000003}, + {0x4A564742, 0x04000000, 0x00000002}, + {0x4A564759, 0x04000000, 0x00000002}, + {0x4A564843, 0x01000000, 0x00000003}, + {0x4A564941, 0x02000000, 0x00000002}, + {0x4A564942, 0x00800000, 0x00000001}, + {0x4A564943, 0x08000000, 0x00000003}, + {0x4A564959, 0x08000000, 0x00000003}, + {0x4A564A41, 0x01000000, 0x00000001}, + {0x4A564B41, 0x04000000, 0x00000001}, + {0x4A564B59, 0x08000000, 0x00000003}, + {0x4A564C41, 0x02000000, 0x00000002}, + {0x4A564C59, 0x04000000, 0x00000002}, + {0x4A564D59, 0x00800000, 0x00000001}, + {0x4A564E43, 0x08000000, 0x00000005}, + {0x4A564E59, 0x02000000, 0x00000002}, + {0x4A564F41, 0x04000000, 0x00000002}, + {0x4A564F43, 0x02000000, 0x00000005}, + {0x4A565041, 0x00800000, 0x00000002}, + {0x4A565142, 0x04000000, 0x00000003}, + {0x4A565259, 0x02000000, 0x00000005}, + {0x4A565359, 0x04000000, 0x00000003}, + {0x4A565541, 0x08000000, 0x00000002}, + {0x4A565559, 0x02000000, 0x00000003}, + {0x4A565641, 0x00800000, 0x00000003}, + {0x4A565643, 0x01000000, 0x00000001}, + {0x4A565659, 0x00800000, 0x00000001}, + {0x4A565741, 0x01000000, 0x00000001}, + {0x4A565743, 0x04000000, 0x00000002}, + {0x4A565759, 0x04000000, 0x00000002}, + {0x4A565841, 0x04000000, 0x00000003}, + {0x4A565843, 0x02000000, 0x00000003}, + {0x4A565942, 0x08000000, 0x00000003}, + {0x4A565943, 0x04000000, 0x00000002}, + {0x4A565A41, 0x00800000, 0x00000001}, + {0x4A565A59, 0x02000000, 0x00000002}, + {0x4A573241, 0x04000000, 0x00000001}, + {0x4A573242, 0x08000000, 0x00000003}, + {0x4A573243, 0x02000000, 0x00000002}, + {0x4A573343, 0x02000000, 0x00000003}, + {0x4A573443, 0x02000000, 0x00000002}, + {0x4A573643, 0x02000000, 0x00000002}, + {0x4A573841, 0x00800000, 0x00000001}, + {0x4A574159, 0x04000000, 0x00000002}, + {0x4A574254, 0x02000000, 0x00000001}, + {0x4A574341, 0x00800000, 0x00000002}, + {0x4A574359, 0x00800000, 0x00000002}, + {0x4A574459, 0x02000000, 0x00000005}, + {0x4A574541, 0x04000000, 0x00000002}, + {0x4A574543, 0x08000000, 0x00000002}, + {0x4A574559, 0x04000000, 0x00000008}, + {0x4A574741, 0x01000000, 0x00000002}, + {0x4A574742, 0x02000000, 0x00000002}, + {0x4A574743, 0x00800000, 0x00000001}, + {0x4A574941, 0x01000000, 0x00000002}, + {0x4A574A41, 0x01000000, 0x00000001}, + {0x4A574B41, 0x04000000, 0x00000002}, + {0x4A574B43, 0x10000000, 0x00000001}, + {0x4A574B59, 0x08000000, 0x00000003}, + {0x4A574C41, 0x02000000, 0x00000001}, + {0x4A574D49, 0x04000000, 0x00000007}, + {0x4A574F43, 0x10000000, 0x00000002}, + {0x4A574F59, 0x02000000, 0x00000002}, + {0x4A575141, 0x02000000, 0x00000002}, + {0x4A575142, 0x08000000, 0x00000003}, + {0x4A575241, 0x01000000, 0x00000002}, + {0x4A575242, 0x08000000, 0x00000005}, + {0x4A575259, 0x02000000, 0x00000005}, + {0x4A575342, 0x08000000, 0x00000006}, + {0x4A575441, 0x02000000, 0x00000002}, + {0x4A575443, 0x01000000, 0x00000003}, + {0x4A575459, 0x08000000, 0x00000003}, + {0x4A575541, 0x04000000, 0x00000003}, + {0x4A575543, 0x04000000, 0x00000003}, + {0x4A575659, 0x10000000, 0x00000003}, + {0x4A575742, 0x08000000, 0x00000003}, + {0x4A575759, 0x02000000, 0x00000002}, + {0x4A575841, 0x00800000, 0x00000002}, + {0x4A575843, 0x02000000, 0x00000003}, + {0x4A575859, 0x01000000, 0x00000003}, + {0x4A575941, 0x02000000, 0x00000002}, + {0x4A575943, 0x01000000, 0x00000001}, + {0x4A575A41, 0x02000000, 0x00000002}, + {0x4A575A43, 0x04000000, 0x00000002}, + {0x4A575A59, 0x02000000, 0x00000002}, + {0x4A583241, 0x01000000, 0x00000002}, + {0x4A583243, 0x02000000, 0x00000003}, + {0x4A583342, 0x01000000, 0x00000001}, + {0x4A583343, 0x08000000, 0x00000002}, + {0x4A583442, 0x04000000, 0x00000002}, + {0x4A583641, 0x02000000, 0x00000002}, + {0x4A583642, 0x01000000, 0x00000003}, + {0x4A583643, 0x00800000, 0x00000002}, + {0x4A583742, 0x08000000, 0x00000003}, + {0x4A583841, 0x04000000, 0x00000002}, + {0x4A584241, 0x02000000, 0x00000002}, + {0x4A584342, 0x04000000, 0x00000005}, + {0x4A584359, 0x02000000, 0x00000002}, + {0x4A584441, 0x02000000, 0x00000002}, + {0x4A584442, 0x01000000, 0x00000001}, + {0x4A584541, 0x08000000, 0x00000002}, + {0x4A584559, 0x02000000, 0x00000002}, + {0x4A584641, 0x08000000, 0x00000003}, + {0x4A584642, 0x04000000, 0x00000002}, + {0x4A584743, 0x10000000, 0x00000001}, + {0x4A584759, 0x08000000, 0x00000002}, + {0x4A584842, 0x04000000, 0x00000002}, + {0x4A584941, 0x04000000, 0x00000002}, + {0x4A584959, 0x08000000, 0x00000003}, + {0x4A584A41, 0x02000000, 0x00000001}, + {0x4A584B41, 0x08000000, 0x00000002}, + {0x4A584B42, 0x04000000, 0x00000003}, + {0x4A584B59, 0x00800000, 0x00000002}, + {0x4A584C54, 0x01000000, 0x00000002}, + {0x4A584D54, 0x04000000, 0x00000003}, + {0x4A584E42, 0x04000000, 0x00000002}, + {0x4A584F42, 0x20000000, 0x00000005}, + {0x4A584F59, 0x04000000, 0x00000003}, + {0x4A585041, 0x04000000, 0x00000005}, + {0x4A585141, 0x08000000, 0x00000003}, + {0x4A585241, 0x04000000, 0x00000001}, + {0x4A585259, 0x04000000, 0x00000002}, + {0x4A585341, 0x01000000, 0x00000002}, + {0x4A585459, 0x04000000, 0x00000002}, + {0x4A585541, 0x01000000, 0x00000001}, + {0x4A585559, 0x04000000, 0x00000003}, + {0x4A585659, 0x04000000, 0x00000002}, + {0x4A585841, 0x04000000, 0x00000002}, + {0x4A585843, 0x02000000, 0x00000003}, + {0x4A585859, 0x04000000, 0x00000002}, + {0x4A585941, 0x08000000, 0x00000005}, + {0x4A585942, 0x10000000, 0x00000003}, + {0x4A585A41, 0x04000000, 0x00000002}, + {0x4A585A59, 0x04000000, 0x00000002}, + {0x4A593241, 0x01000000, 0x00000007}, + {0x4A593243, 0x08000000, 0x00000003}, + {0x4A593341, 0x04000000, 0x00000003}, + {0x4A593343, 0x08000000, 0x00000002}, + {0x4A593441, 0x00800000, 0x00000003}, + {0x4A593442, 0x00800000, 0x00000001}, + {0x4A593543, 0x08000000, 0x00000002}, + {0x4A593643, 0x04000000, 0x00000002}, + {0x4A593841, 0x00800000, 0x00000001}, + {0x4A594159, 0x02000000, 0x00000001}, + {0x4A594341, 0x01000000, 0x00000005}, + {0x4A594541, 0x04000000, 0x00000002}, + {0x4A594659, 0x04000000, 0x00000005}, + {0x4A594741, 0x04000000, 0x00000005}, + {0x4A594743, 0x04000000, 0x00000002}, + {0x4A594759, 0x00800000, 0x00000002}, + {0x4A594942, 0x04000000, 0x00000005}, + {0x4A594A41, 0x04000000, 0x00000006}, + {0x4A594B41, 0x01000000, 0x00000003}, + {0x4A594B43, 0x02000000, 0x00000003}, + {0x4A594B59, 0x02000000, 0x00000002}, + {0x4A594D41, 0x04000000, 0x00000003}, + {0x4A594D43, 0x01000000, 0x00000003}, + {0x4A594E41, 0x04000000, 0x00000003}, + {0x4A594F42, 0x04000000, 0x00000002}, + {0x4A594F59, 0x01000000, 0x00000002}, + {0x4A595041, 0x02000000, 0x00000002}, + {0x4A595056, 0x10000000, 0x00000005}, + {0x4A595141, 0x04000000, 0x00000002}, + {0x4A595159, 0x01000000, 0x00000002}, + {0x4A595242, 0x10000000, 0x00000002}, + {0x4A595259, 0x02000000, 0x00000001}, + {0x4A595341, 0x00800000, 0x00000001}, + {0x4A595541, 0x02000000, 0x00000002}, + {0x4A595542, 0x04000000, 0x00000002}, + {0x4A595543, 0x02000000, 0x00000001}, + {0x4A595641, 0x04000000, 0x00000002}, + {0x4A595659, 0x08000000, 0x00000001}, + {0x4A595741, 0x02000000, 0x00000003}, + {0x4A595742, 0x04000000, 0x00000003}, + {0x4A595841, 0x08000000, 0x00000001}, + {0x4A595843, 0x02000000, 0x00000003}, + {0x4A595942, 0x08000000, 0x00000003}, + {0x4A595959, 0x04000000, 0x00000003}, + {0x4A595A43, 0x02000000, 0x00000002}, + {0x4A5A3241, 0x02000000, 0x00000001}, + {0x4A5A3341, 0x04000000, 0x00000002}, + {0x4A5A3342, 0x02000000, 0x00000001}, + {0x4A5A3641, 0x08000000, 0x00000002}, + {0x4A5A3642, 0x04000000, 0x00000003}, + {0x4A5A3841, 0x02000000, 0x00000002}, + {0x4A5A4143, 0x04000000, 0x00000002}, + {0x4A5A4241, 0x08000000, 0x00000003}, + {0x4A5A4341, 0x01000000, 0x00000001}, + {0x4A5A4441, 0x02000000, 0x00000002}, + {0x4A5A4459, 0x01000000, 0x00000002}, + {0x4A5A4541, 0x04000000, 0x00000002}, + {0x4A5A4542, 0x20000000, 0x00000003}, + {0x4A5A4543, 0x08000000, 0x00000002}, + {0x4A5A4559, 0x04000000, 0x00000002}, + {0x4A5A4741, 0x04000000, 0x00000001}, + {0x4A5A4843, 0x04000000, 0x00000002}, + {0x4A5A4854, 0x20000000, 0x00000002}, + {0x4A5A4941, 0x00800000, 0x00000002}, + {0x4A5A4959, 0x04000000, 0x00000002}, + {0x4A5A4A41, 0x00800000, 0x00000002}, + {0x4A5A4A59, 0x02000000, 0x00000005}, + {0x4A5A4B41, 0x01000000, 0x00000002}, + {0x4A5A4B54, 0x02000000, 0x00000002}, + {0x4A5A4B59, 0x01000000, 0x00000002}, + {0x4A5A4C41, 0x02000000, 0x00000002}, + {0x4A5A4C59, 0x08000000, 0x00000002}, + {0x4A5A4D41, 0x00800000, 0x00000002}, + {0x4A5A4D43, 0x04000000, 0x00000003}, + {0x4A5A4E41, 0x01000000, 0x00000001}, + {0x4A5A4E43, 0x02000000, 0x00000002}, + {0x4A5A4E59, 0x04000000, 0x00000002}, + {0x4A5A4F41, 0x01000000, 0x00000002}, + {0x4A5A4F43, 0x08000000, 0x00000002}, + {0x4A5A5041, 0x01000000, 0x00000002}, + {0x4A5A5141, 0x02000000, 0x00000002}, + {0x4A5A5159, 0x00800000, 0x00000001}, + {0x4A5A5241, 0x04000000, 0x00000002}, + {0x4A5A5242, 0x04000000, 0x00000003}, + {0x4A5A5641, 0x01000000, 0x00000001}, + {0x4A5A5643, 0x10000000, 0x00000003}, + {0x4A5A5659, 0x00800000, 0x00000001}, + {0x4A5A5741, 0x02000000, 0x00000002}, + {0x4A5A5742, 0x04000000, 0x00000003}, + {0x4A5A5759, 0x04000000, 0x00000001}, + {0x4A5A5841, 0x08000000, 0x00000001}, + {0x4A5A5843, 0x02000000, 0x00000003}, + {0x4A5A5941, 0x02000000, 0x00000003}, + {0x4A5A5A41, 0x04000000, 0x00000005}, + {0x4A5A5A59, 0x02000000, 0x00000001}, + {0x4B324359, 0x04000000, 0x00000006}, + {0x4B324441, 0x02000000, 0x00000005}, + {0x4B325043, 0x04000000, 0x00000003}, + {0x4B325359, 0x04000000, 0x00000005}, + {0x4B325859, 0x00800000, 0x00000002}, + {0x4B334341, 0x02000000, 0x00000005}, + {0x4B334359, 0x04000000, 0x00000006}, + {0x4B334441, 0x02000000, 0x00000005}, + {0x4B334741, 0x02000000, 0x00000005}, + {0x4B334C41, 0x02000000, 0x00000001}, + {0x4B334D43, 0x08000000, 0x00000003}, + {0x4B344241, 0x04000000, 0x00000005}, + {0x4B344759, 0x10000000, 0x00000003}, + {0x4B344C43, 0x08000000, 0x00000002}, + {0x4B345043, 0x08000000, 0x00000002}, + {0x4B345759, 0x04000000, 0x00000003}, + {0x4B354459, 0x00800000, 0x00000002}, + {0x4B354759, 0x04000000, 0x00000003}, + {0x4B354B43, 0x04000000, 0x00000005}, + {0x4B355443, 0x08000000, 0x00000002}, + {0x4B363643, 0x04000000, 0x00000002}, + {0x4B364843, 0x04000000, 0x00000001}, + {0x4B364C59, 0x04000000, 0x00000001}, + {0x4B374743, 0x04000000, 0x00000002}, + {0x4B374D41, 0x02000000, 0x00000002}, + {0x4B374D59, 0x04000000, 0x00000002}, + {0x4B375241, 0x04000000, 0x00000002}, + {0x4B383443, 0x04000000, 0x00000006}, + {0x4B384659, 0x02000000, 0x00000003}, + {0x4B384759, 0x08000000, 0x00000005}, + {0x4B385741, 0x04000000, 0x00000001}, + {0x4B385943, 0x10000000, 0x00000003}, + {0x4B394559, 0x04000000, 0x00000003}, + {0x4B394643, 0x02000000, 0x00000003}, + {0x4B395259, 0x04000000, 0x00000002}, + {0x4B395343, 0x02000000, 0x00000001}, + {0x4B395759, 0x08000000, 0x00000001}, + {0x4B395941, 0x08000000, 0x00000003}, + {0x4B413242, 0x04000000, 0x00000003}, + {0x4B414156, 0x02000000, 0x00000008}, + {0x4B414441, 0x04000000, 0x00000006}, + {0x4B414641, 0x04000000, 0x00000003}, + {0x4B414642, 0x02000000, 0x00000003}, + {0x4B415041, 0x04000000, 0x00000006}, + {0x4B415249, 0x10000000, 0x00000006}, + {0x4B415941, 0x00800000, 0x00000002}, + {0x4B424B59, 0x04000000, 0x00000003}, + {0x4B425249, 0x10000000, 0x00000006}, + {0x4B425259, 0x08000000, 0x00000003}, + {0x4B433841, 0x02000000, 0x00000002}, + {0x4B434241, 0x02000000, 0x00000005}, + {0x4B434341, 0x02000000, 0x00000001}, + {0x4B434D41, 0x02000000, 0x00000005}, + {0x4B435041, 0x01000000, 0x00000001}, + {0x4B435141, 0x04000000, 0x00000002}, + {0x4B435259, 0x08000000, 0x00000002}, + {0x4B443241, 0x02000000, 0x00000002}, + {0x4B444154, 0x04000000, 0x00000005}, + {0x4B444342, 0x02000000, 0x00000002}, + {0x4B444E41, 0x01000000, 0x00000005}, + {0x4B444E43, 0x04000000, 0x00000002}, + {0x4B445041, 0x01000000, 0x00000002}, + {0x4B445059, 0x02000000, 0x00000003}, + {0x4B445249, 0x20000000, 0x00000006}, + {0x4B454641, 0x04000000, 0x00000003}, + {0x4B455249, 0x20000000, 0x00000006}, + {0x4B455741, 0x04000000, 0x00000005}, + {0x4B455A41, 0x04000000, 0x00000006}, + {0x4B463341, 0x04000000, 0x00000005}, + {0x4B463541, 0x04000000, 0x00000002}, + {0x4B464B59, 0x02000000, 0x00000001}, + {0x4B465241, 0x08000000, 0x00000003}, + {0x4B473341, 0x04000000, 0x00000005}, + {0x4B473641, 0x04000000, 0x00000002}, + {0x4B474441, 0x02000000, 0x00000005}, + {0x4B474E41, 0x08000000, 0x00000005}, + {0x4B474E59, 0x08000000, 0x00000003}, + {0x4B475049, 0x08000000, 0x00000006}, + {0x4B475059, 0x04000000, 0x00000002}, + {0x4B483643, 0x01000000, 0x00000001}, + {0x4B484759, 0x08000000, 0x00000001}, + {0x4B484D41, 0x04000000, 0x00000005}, + {0x4B484E41, 0x08000000, 0x00000006}, + {0x4B485041, 0x02000000, 0x00000005}, + {0x4B494459, 0x04000000, 0x00000002}, + {0x4B495041, 0x00800000, 0x00000002}, + {0x4B495141, 0x02000000, 0x00000005}, + {0x4B495243, 0x02000000, 0x00000002}, + {0x4B495741, 0x08000000, 0x00000005}, + {0x4B4A4241, 0x04000000, 0x00000005}, + {0x4B4A4342, 0x10000000, 0x00000003}, + {0x4B4A4C43, 0x08000000, 0x00000002}, + {0x4B4A5159, 0x08000000, 0x00000005}, + {0x4B4B4343, 0x02000000, 0x00000001}, + {0x4B4B4841, 0x04000000, 0x00000003}, + {0x4B4B5049, 0x08000000, 0x00000006}, + {0x4B4B5659, 0x08000000, 0x00000002}, + {0x4B4C4143, 0x04000000, 0x00000001}, + {0x4B4C4443, 0x02000000, 0x00000005}, + {0x4B4C4542, 0x02000000, 0x00000002}, + {0x4B4C4F43, 0x08000000, 0x00000003}, + {0x4B4C5759, 0x02000000, 0x00000001}, + {0x4B4C5A41, 0x08000000, 0x00000007}, + {0x4B4D3341, 0x08000000, 0x00000002}, + {0x4B4D4441, 0x02000000, 0x00000005}, + {0x4B4D4641, 0x04000000, 0x00000002}, + {0x4B4D4E41, 0x02000000, 0x00000005}, + {0x4B4D5241, 0x04000000, 0x00000002}, + {0x4B4D5341, 0x01000000, 0x00000001}, + {0x4B4E3442, 0x00800000, 0x00000002}, + {0x4B4E5041, 0x02000000, 0x00000001}, + {0x4B4E5943, 0x01000000, 0x00000002}, + {0x4B4F3242, 0x02000000, 0x00000005}, + {0x4B4F4359, 0x04000000, 0x00000001}, + {0x4B4F4443, 0x04000000, 0x00000005}, + {0x4B4F4559, 0x04000000, 0x00000003}, + {0x4B4F4E59, 0x08000000, 0x00000003}, + {0x4B4F5259, 0x02000000, 0x00000002}, + {0x4B504441, 0x00800000, 0x00000002}, + {0x4B504D59, 0x08000000, 0x00000005}, + {0x4B504E59, 0x04000000, 0x00000002}, + {0x4B505142, 0x04000000, 0x00000002}, + {0x4B505359, 0x02000000, 0x00000005}, + {0x4B505759, 0x04000000, 0x00000002}, + {0x4B505841, 0x02000000, 0x00000005}, + {0x4B514641, 0x04000000, 0x00000003}, + {0x4B514B42, 0x04000000, 0x00000001}, + {0x4B524559, 0x04000000, 0x00000003}, + {0x4B524E41, 0x04000000, 0x00000001}, + {0x4B524E59, 0x04000000, 0x00000002}, + {0x4B525441, 0x01000000, 0x00000002}, + {0x4B534743, 0x08000000, 0x00000001}, + {0x4B534E43, 0x04000000, 0x00000002}, + {0x4B534F41, 0x08000000, 0x00000005}, + {0x4B535043, 0x04000000, 0x00000002}, + {0x4B535143, 0x02000000, 0x00000001}, + {0x4B535659, 0x02000000, 0x00000003}, + {0x4B543841, 0x02000000, 0x00000002}, + {0x4B544659, 0x04000000, 0x00000005}, + {0x4B544C59, 0x08000000, 0x00000002}, + {0x4B545041, 0x01000000, 0x00000002}, + {0x4B545359, 0x04000000, 0x00000001}, + {0x4B545A59, 0x01000000, 0x00000005}, + {0x4B554242, 0x04000000, 0x00000003}, + {0x4B554D42, 0x02000000, 0x00000001}, + {0x4B555043, 0x08000000, 0x00000006}, + {0x4B564143, 0x02000000, 0x00000002}, + {0x4B564C59, 0x04000000, 0x00000002}, + {0x4B573443, 0x02000000, 0x00000002}, + {0x4B574441, 0x04000000, 0x00000002}, + {0x4B574459, 0x02000000, 0x00000005}, + {0x4B574B41, 0x04000000, 0x00000002}, + {0x4B574B59, 0x08000000, 0x00000003}, + {0x4B574F42, 0x04000000, 0x00000002}, + {0x4B575241, 0x01000000, 0x00000002}, + {0x4B575941, 0x02000000, 0x00000002}, + {0x4B575A41, 0x02000000, 0x00000002}, + {0x4B583241, 0x01000000, 0x00000002}, + {0x4B584241, 0x02000000, 0x00000002}, + {0x4B584559, 0x02000000, 0x00000002}, + {0x4B585541, 0x01000000, 0x00000001}, + {0x4B585942, 0x10000000, 0x00000003}, + {0x4B585A43, 0x08000000, 0x00000002}, + {0x4B593242, 0x02000000, 0x00000002}, + {0x4B593341, 0x04000000, 0x00000003}, + {0x4B593441, 0x00800000, 0x00000003}, + {0x4B594541, 0x04000000, 0x00000002}, + {0x4B594659, 0x04000000, 0x00000005}, + {0x4B595543, 0x02000000, 0x00000001}, + {0x4B595942, 0x08000000, 0x00000003}, + {0x4B5A4459, 0x00800000, 0x00000002}, + {0x4B5A4C59, 0x08000000, 0x00000002}, + {0x4B5A5242, 0x04000000, 0x00000003}, + {0x4B5A5A43, 0x10000000, 0x00000005}, + {0x4C464B59, 0x04000000, 0x00000001}, + {0x4C474D43, 0x04000000, 0x00000001}, + {0x4D374C42, 0x04000000, 0x00000001}, + {0x4D375042, 0x02000000, 0x00000001}, + {0x4D385042, 0x04000000, 0x00000001}, + {0x4D435143, 0x02000000, 0x00000001}, + {0x4D474D43, 0x04000000, 0x00000001}, + {0x4D503642, 0x02000000, 0x00000001}, + {0x4E374C42, 0x04000000, 0x00000001}, + {0x4E374E42, 0x02000000, 0x00000001}, + {0x4E375042, 0x02000000, 0x00000001}, + {0x4E385042, 0x04000000, 0x00000001}, + {0x4E435143, 0x02000000, 0x00000001}, + {0x4E454642, 0x04000000, 0x00000001}, + {0x4E503642, 0x02000000, 0x00000001}, + {0x4E573542, 0x02000000, 0x00000001}, + {0x4E584C42, 0x04000000, 0x00000008}, + {0x4E594C42, 0x04000000, 0x00000008}, + {0x4F415249, 0x10000000, 0x00000006}, + {0x4F425249, 0x10000000, 0x00000006}, + {0x4F445249, 0x20000000, 0x00000006}, + {0x4F455249, 0x20000000, 0x00000006}, + {0x50323241, 0x01000000, 0x00000002}, + {0x50323343, 0x04000000, 0x00000003}, + {0x50323542, 0x01000000, 0x00000001}, + {0x50323641, 0x04000000, 0x00000008}, + {0x50323643, 0x04000000, 0x00000001}, + {0x50323743, 0x00800000, 0x00000002}, + {0x50323842, 0x01000000, 0x00000001}, + {0x50324241, 0x02000000, 0x00000002}, + {0x50324242, 0x04000000, 0x00000002}, + {0x50324259, 0x04000000, 0x00000002}, + {0x50324341, 0x04000000, 0x00000001}, + {0x50324343, 0x01000000, 0x00000001}, + {0x50324354, 0x00800000, 0x00000001}, + {0x50324359, 0x00000000, 0x00000006}, + {0x50324441, 0x04000000, 0x00000005}, + {0x50324442, 0x01000000, 0x00000002}, + {0x50324459, 0x01000000, 0x00000003}, + {0x50324643, 0x01000000, 0x00000001}, + {0x50324741, 0x08000000, 0x00000001}, + {0x50324743, 0x02000000, 0x00000002}, + {0x50324759, 0x01000000, 0x00000001}, + {0x50324842, 0x02000000, 0x00000003}, + {0x50324854, 0x01000000, 0x00000001}, + {0x50324859, 0x02000000, 0x00000003}, + {0x50324941, 0x04000000, 0x00000002}, + {0x50324943, 0x00800000, 0x00000001}, + {0x50324959, 0x00800000, 0x00000001}, + {0x50324A41, 0x00800000, 0x00000008}, + {0x50324A42, 0x04000000, 0x00000001}, + {0x50324A43, 0x01000000, 0x00000002}, + {0x50324A56, 0x02000000, 0x00000001}, + {0x50324A59, 0x02000000, 0x00000002}, + {0x50324B43, 0x02000000, 0x00000001}, + {0x50324C41, 0x04000000, 0x00000002}, + {0x50324C59, 0x08000000, 0x00000003}, + {0x50325041, 0x02000000, 0x00000001}, + {0x50325042, 0x02000000, 0x00000001}, + {0x50325059, 0x04000000, 0x00000005}, + {0x50325141, 0x02000000, 0x00000002}, + {0x50325254, 0x02000000, 0x00000002}, + {0x50325259, 0x08000000, 0x00000003}, + {0x50325341, 0x01000000, 0x00000001}, + {0x50325359, 0x04000000, 0x00000005}, + {0x50325442, 0x04000000, 0x00000003}, + {0x50325459, 0x00800000, 0x00000001}, + {0x50325559, 0x01000000, 0x00000003}, + {0x50325642, 0x02000000, 0x00000001}, + {0x50325741, 0x02000000, 0x00000003}, + {0x50325759, 0x04000000, 0x00000005}, + {0x50325841, 0x00800000, 0x00000001}, + {0x50325842, 0x00800000, 0x00000001}, + {0x50325A43, 0x01000000, 0x00000003}, + {0x50333441, 0x01000000, 0x00000008}, + {0x50333543, 0x00800000, 0x00000001}, + {0x50333743, 0x00800000, 0x00000002}, + {0x50333842, 0x08000000, 0x00000001}, + {0x50334142, 0x04000000, 0x00000001}, + {0x50334159, 0x00800000, 0x00000001}, + {0x50334241, 0x04000000, 0x00000003}, + {0x50334242, 0x08000000, 0x00000001}, + {0x50334243, 0x02000000, 0x00000002}, + {0x50334259, 0x04000000, 0x00000005}, + {0x50334341, 0x04000000, 0x00000005}, + {0x50334342, 0x00800000, 0x00000001}, + {0x50334354, 0x04000000, 0x00000002}, + {0x50334441, 0x04000000, 0x00000005}, + {0x50334442, 0x04000000, 0x00000001}, + {0x50334444, 0x02000000, 0x00000001}, + {0x50334542, 0x04000000, 0x00000001}, + {0x50334641, 0x00800000, 0x00000001}, + {0x50334643, 0x01000000, 0x00000001}, + {0x50334659, 0x02000000, 0x00000002}, + {0x50334741, 0x04000000, 0x00000005}, + {0x50334743, 0x02000000, 0x00000002}, + {0x50334759, 0x02000000, 0x00000003}, + {0x50334841, 0x02000000, 0x00000003}, + {0x50334842, 0x02000000, 0x00000002}, + {0x50334941, 0x01000000, 0x00000002}, + {0x50334943, 0x04000000, 0x00000001}, + {0x50334959, 0x04000000, 0x00000002}, + {0x50334A43, 0x00800000, 0x00000001}, + {0x50334A54, 0x01000000, 0x00000001}, + {0x50334A56, 0x02000000, 0x00000001}, + {0x50334B41, 0x02000000, 0x00000002}, + {0x50334B59, 0x02000000, 0x00000003}, + {0x50334C41, 0x02000000, 0x00000001}, + {0x50334C43, 0x01000000, 0x00000001}, + {0x50334C59, 0x04000000, 0x00000002}, + {0x50334D43, 0x08000000, 0x00000003}, + {0x50334D54, 0x04000000, 0x00000001}, + {0x50334F41, 0x02000000, 0x00000001}, + {0x50335043, 0x08000000, 0x00000005}, + {0x50335059, 0x02000000, 0x00000008}, + {0x50335141, 0x04000000, 0x00000002}, + {0x50335154, 0x04000000, 0x00000001}, + {0x50335159, 0x04000000, 0x00000002}, + {0x50335341, 0x02000000, 0x00000001}, + {0x50335343, 0x04000000, 0x00000003}, + {0x50335359, 0x00800000, 0x00000001}, + {0x50335459, 0x04000000, 0x00000003}, + {0x50335543, 0x02000000, 0x00000001}, + {0x50335559, 0x02000000, 0x00000001}, + {0x50335741, 0x04000000, 0x00000001}, + {0x50335742, 0x08000000, 0x00000002}, + {0x50335759, 0x01000000, 0x00000001}, + {0x50335842, 0x00800000, 0x00000001}, + {0x50335941, 0x04000000, 0x00000002}, + {0x50343242, 0x00800000, 0x00000001}, + {0x50343243, 0x08000000, 0x00000003}, + {0x50343543, 0x02000000, 0x00000003}, + {0x50343559, 0x02000000, 0x00000008}, + {0x50343741, 0x04000000, 0x00000008}, + {0x50343743, 0x00800000, 0x00000002}, + {0x50344259, 0x02000000, 0x00000001}, + {0x50344341, 0x04000000, 0x00000001}, + {0x50344441, 0x02000000, 0x00000005}, + {0x50344443, 0x00800000, 0x00000001}, + {0x50344456, 0x04000000, 0x00000001}, + {0x50344643, 0x00800000, 0x00000001}, + {0x50344659, 0x08000000, 0x00000003}, + {0x50344759, 0x10000000, 0x00000003}, + {0x50344843, 0x04000000, 0x00000002}, + {0x50344943, 0x04000000, 0x00000002}, + {0x50344A42, 0x00800000, 0x00000001}, + {0x50344A43, 0x01000000, 0x00000001}, + {0x50344A56, 0x02000000, 0x00000001}, + {0x50344C41, 0x00800000, 0x00000001}, + {0x50344D41, 0x00800000, 0x00000002}, + {0x50344D42, 0x00000000, 0x00000002}, + {0x50344D43, 0x01000000, 0x00000003}, + {0x50344D56, 0x02000000, 0x00000002}, + {0x50344E41, 0x04000000, 0x00000001}, + {0x50345059, 0x04000000, 0x00000002}, + {0x50345141, 0x02000000, 0x00000001}, + {0x50345159, 0x00800000, 0x00000002}, + {0x50345242, 0x08000000, 0x00000003}, + {0x50345243, 0x04000000, 0x00000002}, + {0x50345341, 0x04000000, 0x00000003}, + {0x50345442, 0x01000000, 0x00000008}, + {0x50345443, 0x01000000, 0x00000001}, + {0x50345543, 0x02000000, 0x00000002}, + {0x50345659, 0x08000000, 0x00000003}, + {0x50345742, 0x02000000, 0x00000002}, + {0x50345759, 0x04000000, 0x00000003}, + {0x50345842, 0x00800000, 0x00000001}, + {0x50345A43, 0x04000000, 0x00000001}, + {0x50353441, 0x01000000, 0x00000008}, + {0x50353542, 0x00800000, 0x00000001}, + {0x50353643, 0x02000000, 0x00000001}, + {0x50353743, 0x00800000, 0x00000002}, + {0x50353841, 0x02000000, 0x00000008}, + {0x50353859, 0x00800000, 0x00000000}, + {0x50354142, 0x01000000, 0x00000001}, + {0x50354242, 0x00800000, 0x00000002}, + {0x50354259, 0x02000000, 0x00000002}, + {0x50354342, 0x04000000, 0x00000002}, + {0x50354359, 0x00800000, 0x00000008}, + {0x50354443, 0x02000000, 0x00000001}, + {0x50354642, 0x00800000, 0x00000002}, + {0x50354643, 0x00800000, 0x00000002}, + {0x50354741, 0x01000000, 0x00000001}, + {0x50354743, 0x04000000, 0x00000001}, + {0x50354841, 0x02000000, 0x00000002}, + {0x50354943, 0x01000000, 0x00000001}, + {0x50354A42, 0x02000000, 0x00000001}, + {0x50354A54, 0x01000000, 0x00000002}, + {0x50354A59, 0x08000000, 0x00000002}, + {0x50354B43, 0x04000000, 0x00000005}, + {0x50354C41, 0x04000000, 0x00000001}, + {0x50354D43, 0x04000000, 0x00000001}, + {0x50354F41, 0x02000000, 0x00000005}, + {0x50354F42, 0x10000000, 0x00000005}, + {0x50354F43, 0x04000000, 0x00000001}, + {0x50355043, 0x02000000, 0x00000001}, + {0x50355059, 0x01000000, 0x00000001}, + {0x50355141, 0x04000000, 0x00000001}, + {0x50355241, 0x02000000, 0x00000001}, + {0x50355242, 0x01000000, 0x00000002}, + {0x50355259, 0x02000000, 0x00000002}, + {0x50355341, 0x01000000, 0x00000001}, + {0x50355343, 0x04000000, 0x00000001}, + {0x50355359, 0x02000000, 0x00000001}, + {0x50355459, 0x00800000, 0x00000002}, + {0x50355541, 0x00800000, 0x00000001}, + {0x50355643, 0x02000000, 0x00000001}, + {0x50355659, 0x08000000, 0x00000003}, + {0x50355743, 0x00000000, 0x00000001}, + {0x50355759, 0x01000000, 0x00000001}, + {0x50355842, 0x00800000, 0x00000001}, + {0x50355941, 0x08000000, 0x00000003}, + {0x50363241, 0x01000000, 0x00000008}, + {0x50363242, 0x00800000, 0x00000002}, + {0x50363341, 0x04000000, 0x00000008}, + {0x50363442, 0x01000000, 0x00000001}, + {0x50363642, 0x01000000, 0x00000001}, + {0x50363742, 0x02000000, 0x00000001}, + {0x50363743, 0x02000000, 0x00000002}, + {0x50363842, 0x00800000, 0x00000001}, + {0x50363859, 0x00800000, 0x00000000}, + {0x50364241, 0x02000000, 0x00000001}, + {0x50364243, 0x02000000, 0x00000002}, + {0x50364254, 0x02000000, 0x00000001}, + {0x50364341, 0x01000000, 0x00000002}, + {0x50364542, 0x02000000, 0x00000002}, + {0x50364641, 0x02000000, 0x00000002}, + {0x50364642, 0x00800000, 0x00000001}, + {0x50364743, 0x08000000, 0x00000002}, + {0x50364759, 0x04000000, 0x00000002}, + {0x50364841, 0x02000000, 0x00000001}, + {0x50364843, 0x04000000, 0x00000001}, + {0x50364A56, 0x02000000, 0x00000001}, + {0x50364B41, 0x01000000, 0x00000001}, + {0x50364B59, 0x00800000, 0x00000008}, + {0x50364D41, 0x02000000, 0x00000005}, + {0x50364D43, 0x08000000, 0x00000002}, + {0x50364D54, 0x01000000, 0x00000001}, + {0x50364D59, 0x00800000, 0x00000001}, + {0x50364E41, 0x02000000, 0x00000001}, + {0x50365043, 0x00000000, 0x00000002}, + {0x50365059, 0x01000000, 0x00000001}, + {0x50365241, 0x01000000, 0x00000002}, + {0x50365242, 0x02000000, 0x00000002}, + {0x50365259, 0x02000000, 0x00000002}, + {0x50365342, 0x02000000, 0x00000001}, + {0x50365343, 0x04000000, 0x00000002}, + {0x50365359, 0x04000000, 0x00000005}, + {0x50365541, 0x00800000, 0x00000002}, + {0x50365559, 0x04000000, 0x00000002}, + {0x50365642, 0x01000000, 0x00000001}, + {0x50365643, 0x01000000, 0x00000001}, + {0x50365741, 0x00800000, 0x00000001}, + {0x50365743, 0x04000000, 0x00000002}, + {0x50365842, 0x00800000, 0x00000001}, + {0x50365941, 0x00800000, 0x00000005}, + {0x50365942, 0x01000000, 0x00000001}, + {0x50365A41, 0x01000000, 0x00000005}, + {0x50365A42, 0x04000000, 0x00000002}, + {0x50373241, 0x01000000, 0x00000008}, + {0x50373242, 0x00800000, 0x00000001}, + {0x50373243, 0x08000000, 0x00000003}, + {0x50373442, 0x01000000, 0x00000001}, + {0x50373541, 0x01000000, 0x00000008}, + {0x50373743, 0x02000000, 0x00000003}, + {0x50374143, 0x02000000, 0x00000002}, + {0x50374159, 0x02000000, 0x00000002}, + {0x50374241, 0x00800000, 0x00000001}, + {0x50374242, 0x04000000, 0x00000002}, + {0x50374243, 0x02000000, 0x00000002}, + {0x50374259, 0x04000000, 0x00000002}, + {0x50374341, 0x00800000, 0x00000002}, + {0x50374441, 0x04000000, 0x00000005}, + {0x50374443, 0x01000000, 0x00000001}, + {0x50374542, 0x04000000, 0x00000002}, + {0x50374641, 0x02000000, 0x00000002}, + {0x50374642, 0x00800000, 0x00000001}, + {0x50374659, 0x01000000, 0x00000002}, + {0x50374741, 0x04000000, 0x00000002}, + {0x50374943, 0x04000000, 0x00000002}, + {0x50374A42, 0x00800000, 0x00000001}, + {0x50374C41, 0x02000000, 0x00000001}, + {0x50374C43, 0x01000000, 0x00000002}, + {0x50374D54, 0x04000000, 0x00000002}, + {0x50374D59, 0x04000000, 0x00000002}, + {0x50374E41, 0x02000000, 0x00000002}, + {0x50374E43, 0x01000000, 0x00000002}, + {0x50375141, 0x00800000, 0x00000002}, + {0x50375143, 0x04000000, 0x00000001}, + {0x50375241, 0x08000000, 0x00000002}, + {0x50375259, 0x04000000, 0x00000002}, + {0x50375359, 0x02000000, 0x00000001}, + {0x50375443, 0x00800000, 0x00000002}, + {0x50375459, 0x04000000, 0x00000002}, + {0x50375541, 0x02000000, 0x00000002}, + {0x50375542, 0x08000000, 0x00000001}, + {0x50375643, 0x00800000, 0x00000001}, + {0x50375941, 0x08000000, 0x00000005}, + {0x50375942, 0x00800000, 0x00000001}, + {0x50375943, 0x04000000, 0x00000002}, + {0x50383242, 0x04000000, 0x00000001}, + {0x50383259, 0x02000000, 0x00000008}, + {0x50383342, 0x01000000, 0x00000001}, + {0x50383343, 0x04000000, 0x00000005}, + {0x50383541, 0x02000000, 0x00000008}, + {0x50383542, 0x01000000, 0x00000001}, + {0x50383543, 0x04000000, 0x00000001}, + {0x50383642, 0x00800000, 0x00000001}, + {0x50384149, 0x04000000, 0x00000005}, + {0x50384159, 0x01000000, 0x00000002}, + {0x50384241, 0x02000000, 0x00000001}, + {0x50384243, 0x02000000, 0x00000001}, + {0x50384359, 0x01000000, 0x00000002}, + {0x50384443, 0x02000000, 0x00000002}, + {0x50384642, 0x00800000, 0x00000001}, + {0x50384643, 0x04000000, 0x00000002}, + {0x50384659, 0x02000000, 0x00000003}, + {0x50384741, 0x04000000, 0x00000003}, + {0x50384759, 0x08000000, 0x00000005}, + {0x50384841, 0x02000000, 0x00000001}, + {0x50384843, 0x02000000, 0x00000001}, + {0x50384941, 0x02000000, 0x00000002}, + {0x50384A42, 0x04000000, 0x00000002}, + {0x50384C41, 0x04000000, 0x00000001}, + {0x50384C43, 0x04000000, 0x00000002}, + {0x50384D41, 0x01000000, 0x00000001}, + {0x50384D42, 0x04000000, 0x00000001}, + {0x50384D43, 0x02000000, 0x00000002}, + {0x50384E41, 0x00800000, 0x00000001}, + {0x50384F41, 0x04000000, 0x00000003}, + {0x50384F59, 0x08000000, 0x00000003}, + {0x50385043, 0x02000000, 0x00000002}, + {0x50385059, 0x01000000, 0x00000001}, + {0x50385141, 0x00800000, 0x00000002}, + {0x50385143, 0x01000000, 0x00000001}, + {0x50385243, 0x04000000, 0x00000002}, + {0x50385259, 0x02000000, 0x00000002}, + {0x50385342, 0x04000000, 0x00000002}, + {0x50385343, 0x04000000, 0x00000003}, + {0x50385359, 0x04000000, 0x00000001}, + {0x50385442, 0x08000000, 0x00000001}, + {0x50385459, 0x02000000, 0x00000002}, + {0x50385542, 0x04000000, 0x00000001}, + {0x50385543, 0x00800000, 0x00000001}, + {0x50385642, 0x01000000, 0x00000002}, + {0x50385643, 0x04000000, 0x00000002}, + {0x50385741, 0x04000000, 0x00000001}, + {0x50385742, 0x01000000, 0x00000001}, + {0x50385759, 0x08000000, 0x00000005}, + {0x50385859, 0x08000000, 0x00000001}, + {0x50385942, 0x00800000, 0x00000001}, + {0x50385943, 0x10000000, 0x00000003}, + {0x50385A42, 0x01000000, 0x00000001}, + {0x50393241, 0x00800000, 0x00000008}, + {0x50393343, 0x02000000, 0x00000002}, + {0x50393442, 0x04000000, 0x00000001}, + {0x50393443, 0x04000000, 0x00000005}, + {0x50393459, 0x04000000, 0x00000008}, + {0x50393642, 0x01000000, 0x00000001}, + {0x50393643, 0x04000000, 0x00000002}, + {0x50393741, 0x02000000, 0x00000008}, + {0x50393742, 0x02000000, 0x00000001}, + {0x50394159, 0x00800000, 0x00000001}, + {0x50394241, 0x01000000, 0x00000001}, + {0x50394242, 0x02000000, 0x00000001}, + {0x50394243, 0x08000000, 0x00000005}, + {0x50394259, 0x02000000, 0x00000003}, + {0x50394341, 0x04000000, 0x00000001}, + {0x50394441, 0x04000000, 0x00000003}, + {0x50394442, 0x00800000, 0x00000002}, + {0x50394542, 0x04000000, 0x00000002}, + {0x50394543, 0x01000000, 0x00000003}, + {0x50394641, 0x00800000, 0x00000001}, + {0x50394642, 0x00800000, 0x00000001}, + {0x50394643, 0x02000000, 0x00000003}, + {0x50394659, 0x02000000, 0x00000001}, + {0x50394841, 0x04000000, 0x00000005}, + {0x50394943, 0x01000000, 0x00000002}, + {0x50394A59, 0x00800000, 0x00000005}, + {0x50394B42, 0x10000000, 0x00000003}, + {0x50394C42, 0x08000000, 0x00000001}, + {0x50394D41, 0x01000000, 0x00000002}, + {0x50394D43, 0x01000000, 0x00000001}, + {0x50394D59, 0x01000000, 0x00000001}, + {0x50394E41, 0x01000000, 0x00000001}, + {0x50395042, 0x04000000, 0x00000002}, + {0x50395141, 0x04000000, 0x00000001}, + {0x50395242, 0x01000000, 0x00000001}, + {0x50395259, 0x04000000, 0x00000002}, + {0x50395341, 0x02000000, 0x00000001}, + {0x50395343, 0x00000000, 0x00000001}, + {0x50395442, 0x00800000, 0x00000001}, + {0x50395459, 0x04000000, 0x00000003}, + {0x50395542, 0x04000000, 0x00000001}, + {0x50395642, 0x01000000, 0x00000001}, + {0x50395643, 0x01000000, 0x00000001}, + {0x50395742, 0x08000000, 0x00000002}, + {0x50395759, 0x08000000, 0x00000001}, + {0x50395941, 0x08000000, 0x00000003}, + {0x50395943, 0x04000000, 0x00000001}, + {0x50413342, 0x02000000, 0x00000001}, + {0x50413459, 0x04000000, 0x00000008}, + {0x50413541, 0x04000000, 0x00000001}, + {0x50413542, 0x00800000, 0x00000001}, + {0x50413543, 0x02000000, 0x00000002}, + {0x50413641, 0x02000000, 0x00000005}, + {0x50413741, 0x02000000, 0x00000001}, + {0x50413742, 0x00800000, 0x00000001}, + {0x50413842, 0x02000000, 0x00000001}, + {0x50413859, 0x04000000, 0x00000000}, + {0x50414159, 0x04000000, 0x00000002}, + {0x50414241, 0x02000000, 0x00000001}, + {0x50414254, 0x01000000, 0x00000001}, + {0x50414259, 0x02000000, 0x00000002}, + {0x50414341, 0x00800000, 0x00000001}, + {0x50414342, 0x01000000, 0x00000002}, + {0x50414443, 0x04000000, 0x00000002}, + {0x50414541, 0x08000000, 0x00000001}, + {0x50414642, 0x00000000, 0x00000003}, + {0x50414643, 0x08000000, 0x00000002}, + {0x50414754, 0x01000000, 0x00000001}, + {0x50414759, 0x01000000, 0x00000001}, + {0x50414941, 0x04000000, 0x00000001}, + {0x50414A54, 0x00800000, 0x00000001}, + {0x50414B41, 0x08000000, 0x00000005}, + {0x50414B43, 0x04000000, 0x00000002}, + {0x50414C54, 0x00800000, 0x00000001}, + {0x50414C59, 0x00800000, 0x00000002}, + {0x50414D54, 0x00800000, 0x00000001}, + {0x50414E42, 0x02000000, 0x00000001}, + {0x50414E43, 0x02000000, 0x00000001}, + {0x50414F42, 0x04000000, 0x00000001}, + {0x50415042, 0x02000000, 0x00000002}, + {0x50415043, 0x02000000, 0x00000001}, + {0x50415054, 0x02000000, 0x00000001}, + {0x50415141, 0x02000000, 0x00000001}, + {0x50415241, 0x02000000, 0x00000001}, + {0x50415243, 0x00800000, 0x00000001}, + {0x50415254, 0x00800000, 0x00000001}, + {0x50415343, 0x01000000, 0x00000001}, + {0x50415443, 0x04000000, 0x00000001}, + {0x50415543, 0x04000000, 0x00000001}, + {0x50415641, 0x04000000, 0x00000002}, + {0x50415642, 0x00800000, 0x00000001}, + {0x50415741, 0x04000000, 0x00000002}, + {0x50415742, 0x02000000, 0x00000002}, + {0x50415743, 0x00800000, 0x00000001}, + {0x50415941, 0x02000000, 0x00000002}, + {0x50415A42, 0x08000000, 0x00000001}, + {0x50415A43, 0x02000000, 0x00000002}, + {0x50423342, 0x04000000, 0x00000001}, + {0x50423343, 0x00800000, 0x00000001}, + {0x50423442, 0x04000000, 0x00000002}, + {0x50423443, 0x02000000, 0x00000003}, + {0x50423542, 0x04000000, 0x00000002}, + {0x50423543, 0x01000000, 0x00000003}, + {0x50423641, 0x02000000, 0x00000005}, + {0x50423642, 0x04000000, 0x00000001}, + {0x50423643, 0x02000000, 0x00000002}, + {0x50423741, 0x01000000, 0x00000001}, + {0x50423841, 0x00800000, 0x00000002}, + {0x50423842, 0x01000000, 0x00000002}, + {0x50423959, 0x08000000, 0x00000000}, + {0x50424142, 0x01000000, 0x00000002}, + {0x50424243, 0x01000000, 0x00000002}, + {0x50424259, 0x02000000, 0x00000001}, + {0x50424341, 0x04000000, 0x00000003}, + {0x50424354, 0x08000000, 0x00000001}, + {0x50424441, 0x04000000, 0x00000002}, + {0x50424442, 0x04000000, 0x00000002}, + {0x50424443, 0x04000000, 0x00000001}, + {0x50424542, 0x10000000, 0x00000003}, + {0x50424641, 0x00800000, 0x00000001}, + {0x50424642, 0x01000000, 0x00000002}, + {0x50424654, 0x01000000, 0x00000001}, + {0x50424742, 0x00800000, 0x00000002}, + {0x50424841, 0x02000000, 0x00000002}, + {0x50424842, 0x00800000, 0x00000001}, + {0x50424942, 0x01000000, 0x00000003}, + {0x50424959, 0x02000000, 0x00000001}, + {0x50424A42, 0x04000000, 0x00000001}, + {0x50424A59, 0x04000000, 0x00000001}, + {0x50424B41, 0x04000000, 0x00000003}, + {0x50424C42, 0x04000000, 0x00000002}, + {0x50424C43, 0x08000000, 0x00000003}, + {0x50424E43, 0x04000000, 0x00000003}, + {0x50425054, 0x00800000, 0x00000002}, + {0x50425141, 0x02000000, 0x00000001}, + {0x50425159, 0x00800000, 0x00000001}, + {0x50425241, 0x02000000, 0x00000001}, + {0x50425341, 0x04000000, 0x00000002}, + {0x50425343, 0x01000000, 0x00000002}, + {0x50425359, 0x02000000, 0x00000002}, + {0x50425442, 0x04000000, 0x00000002}, + {0x50425543, 0x04000000, 0x00000003}, + {0x50425559, 0x04000000, 0x00000002}, + {0x50425741, 0x00800000, 0x00000001}, + {0x50425742, 0x04000000, 0x00000002}, + {0x50425743, 0x00800000, 0x00000001}, + {0x50425759, 0x02000000, 0x00000002}, + {0x50425855, 0x08000000, 0x00000008}, + {0x50425942, 0x01000000, 0x00000001}, + {0x50425943, 0x04000000, 0x00000001}, + {0x50425959, 0x08000000, 0x00000005}, + {0x50425A41, 0x00800000, 0x00000001}, + {0x50433342, 0x04000000, 0x00000002}, + {0x50433441, 0x02000000, 0x00000003}, + {0x50433459, 0x08000000, 0x00000008}, + {0x50433543, 0x01000000, 0x00000003}, + {0x50433641, 0x02000000, 0x00000005}, + {0x50433643, 0x10000000, 0x00000005}, + {0x50433741, 0x01000000, 0x00000001}, + {0x50433742, 0x00800000, 0x00000002}, + {0x50433841, 0x02000000, 0x00000002}, + {0x50433859, 0x00800000, 0x00000008}, + {0x50434241, 0x04000000, 0x00000005}, + {0x50434259, 0x02000000, 0x00000002}, + {0x50434341, 0x02000000, 0x00000001}, + {0x50434342, 0x04000000, 0x00000002}, + {0x50434354, 0x00800000, 0x00000001}, + {0x50434441, 0x02000000, 0x00000001}, + {0x50434443, 0x04000000, 0x00000003}, + {0x50434541, 0x04000000, 0x00000001}, + {0x50434543, 0x04000000, 0x00000002}, + {0x50434559, 0x02000000, 0x00000001}, + {0x50434641, 0x00800000, 0x00000001}, + {0x50434659, 0x08000000, 0x00000002}, + {0x50434741, 0x04000000, 0x00000003}, + {0x50434742, 0x00800000, 0x00000001}, + {0x50434759, 0x02000000, 0x00000002}, + {0x50434859, 0x00800000, 0x00000001}, + {0x50434941, 0x01000000, 0x00000001}, + {0x50434943, 0x04000000, 0x00000003}, + {0x50434956, 0x08000000, 0x00000002}, + {0x50434A42, 0x04000000, 0x00000002}, + {0x50434A43, 0x04000000, 0x00000002}, + {0x50434A59, 0x04000000, 0x00000002}, + {0x50434C41, 0x01000000, 0x00000008}, + {0x50434C42, 0x04000000, 0x00000002}, + {0x50434C43, 0x02000000, 0x00000001}, + {0x50434D41, 0x02000000, 0x00000005}, + {0x50434D42, 0x01000000, 0x00000001}, + {0x50434D54, 0x04000000, 0x00000003}, + {0x50435041, 0x01000000, 0x00000001}, + {0x50435043, 0x00800000, 0x00000002}, + {0x50435159, 0x01000000, 0x00000001}, + {0x50435242, 0x04000000, 0x00000003}, + {0x50435243, 0x02000000, 0x00000001}, + {0x50435254, 0x04000000, 0x00000001}, + {0x50435341, 0x04000000, 0x00000002}, + {0x50435343, 0x08000000, 0x00000001}, + {0x50435441, 0x04000000, 0x00000005}, + {0x50435442, 0x01000000, 0x00000001}, + {0x50435641, 0x04000000, 0x00000005}, + {0x50435642, 0x00800000, 0x00000001}, + {0x50435759, 0x02000000, 0x00000002}, + {0x50435842, 0x01000000, 0x00000001}, + {0x50435943, 0x02000000, 0x00000002}, + {0x50435959, 0x04000000, 0x00000001}, + {0x50443241, 0x02000000, 0x00000002}, + {0x50443242, 0x02000000, 0x00000002}, + {0x50443343, 0x01000000, 0x00000001}, + {0x50443442, 0x01000000, 0x00000001}, + {0x50443741, 0x01000000, 0x00000001}, + {0x50443841, 0x04000000, 0x00000002}, + {0x50444154, 0x08000000, 0x00000005}, + {0x50444156, 0x02000000, 0x00000001}, + {0x50444159, 0x01000000, 0x00000001}, + {0x50444343, 0x00000000, 0x00000003}, + {0x50444354, 0x02000000, 0x00000001}, + {0x50444441, 0x01000000, 0x00000001}, + {0x50444442, 0x01000000, 0x00000001}, + {0x50444454, 0x00800000, 0x00000001}, + {0x50444459, 0x01000000, 0x00000001}, + {0x50444541, 0x00800000, 0x00000001}, + {0x50444559, 0x00800000, 0x00000001}, + {0x50444641, 0x04000000, 0x00000002}, + {0x50444643, 0x08000000, 0x00000002}, + {0x50444743, 0x01000000, 0x00000001}, + {0x50444759, 0x00800000, 0x00000002}, + {0x50444841, 0x04000000, 0x00000002}, + {0x50444842, 0x04000000, 0x00000001}, + {0x50444859, 0x04000000, 0x00000001}, + {0x50444943, 0x02000000, 0x00000003}, + {0x50444A54, 0x01000000, 0x00000001}, + {0x50444A59, 0x02000000, 0x00000002}, + {0x50444B41, 0x02000000, 0x00000002}, + {0x50444C41, 0x04000000, 0x00000003}, + {0x50444C42, 0x04000000, 0x00000002}, + {0x50444C54, 0x02000000, 0x00000001}, + {0x50444C59, 0x04000000, 0x00000005}, + {0x50444D42, 0x00000000, 0x00000001}, + {0x50444D43, 0x02000000, 0x00000005}, + {0x50444D54, 0x04000000, 0x00000002}, + {0x50444E41, 0x01000000, 0x00000005}, + {0x50444E42, 0x02000000, 0x00000001}, + {0x50444E43, 0x04000000, 0x00000002}, + {0x50445041, 0x02000000, 0x00000002}, + {0x50445042, 0x04000000, 0x00000002}, + {0x50445043, 0x02000000, 0x00000001}, + {0x50445054, 0x08000000, 0x00000001}, + {0x50445059, 0x04000000, 0x00000003}, + {0x50445241, 0x02000000, 0x00000001}, + {0x50445243, 0x01000000, 0x00000001}, + {0x50445259, 0x02000000, 0x00000001}, + {0x50445341, 0x01000000, 0x00000001}, + {0x50445343, 0x02000000, 0x00000001}, + {0x50445441, 0x01000000, 0x00000002}, + {0x50445442, 0x01000000, 0x00000001}, + {0x50445443, 0x04000000, 0x00000002}, + {0x50445641, 0x01000000, 0x00000002}, + {0x50445643, 0x00800000, 0x00000001}, + {0x50445741, 0x02000000, 0x00000005}, + {0x50445743, 0x02000000, 0x00000003}, + {0x50445759, 0x01000000, 0x00000002}, + {0x50445A42, 0x08000000, 0x00000001}, + {0x50453242, 0x00800000, 0x00000001}, + {0x50453341, 0x00800000, 0x00000002}, + {0x50453442, 0x01000000, 0x00000001}, + {0x50453642, 0x02000000, 0x00000001}, + {0x50453643, 0x00800000, 0x00000002}, + {0x50453741, 0x02000000, 0x00000001}, + {0x50454156, 0x02000000, 0x00000001}, + {0x50454254, 0x04000000, 0x00000001}, + {0x50454342, 0x02000000, 0x00000002}, + {0x50454343, 0x00000000, 0x00000005}, + {0x50454359, 0x02000000, 0x00000002}, + {0x50454442, 0x04000000, 0x00000002}, + {0x50454443, 0x00800000, 0x00000001}, + {0x50454542, 0x10000000, 0x00000003}, + {0x50454559, 0x10000000, 0x00000003}, + {0x50454641, 0x04000000, 0x00000003}, + {0x50454659, 0x04000000, 0x00000005}, + {0x50454741, 0x01000000, 0x00000001}, + {0x50454742, 0x04000000, 0x00000001}, + {0x50454841, 0x08000000, 0x00000005}, + {0x50454843, 0x02000000, 0x00000002}, + {0x50454854, 0x01000000, 0x00000001}, + {0x50454A59, 0x01000000, 0x00000001}, + {0x50454B42, 0x04000000, 0x00000002}, + {0x50454C43, 0x02000000, 0x00000001}, + {0x50454C54, 0x02000000, 0x00000001}, + {0x50454C59, 0x02000000, 0x00000001}, + {0x50454D56, 0x02000000, 0x00000001}, + {0x50454F59, 0x01000000, 0x00000005}, + {0x50455141, 0x00800000, 0x00000002}, + {0x50455143, 0x04000000, 0x00000002}, + {0x50455241, 0x04000000, 0x00000001}, + {0x50455341, 0x08000000, 0x00000002}, + {0x50455443, 0x00800000, 0x00000001}, + {0x50455459, 0x02000000, 0x00000003}, + {0x50455542, 0x02000000, 0x00000001}, + {0x50455543, 0x01000000, 0x00000002}, + {0x50455641, 0x01000000, 0x00000001}, + {0x50455642, 0x00800000, 0x00000002}, + {0x50455741, 0x04000000, 0x00000005}, + {0x50455743, 0x01000000, 0x00000002}, + {0x50455842, 0x04000000, 0x00000001}, + {0x50455942, 0x02000000, 0x00000001}, + {0x50455959, 0x00000000, 0x00000002}, + {0x50455A41, 0x08000000, 0x00000006}, + {0x50463259, 0x04000000, 0x00000008}, + {0x50463342, 0x00800000, 0x00000001}, + {0x50463343, 0x00000000, 0x00000002}, + {0x50463541, 0x08000000, 0x00000002}, + {0x50463641, 0x08000000, 0x00000003}, + {0x50463642, 0x08000000, 0x00000001}, + {0x50463741, 0x02000000, 0x00000001}, + {0x50463743, 0x01000000, 0x00000003}, + {0x50464156, 0x02000000, 0x00000001}, + {0x50464159, 0x02000000, 0x00000002}, + {0x50464243, 0x00000000, 0x00000003}, + {0x50464341, 0x04000000, 0x00000002}, + {0x50464342, 0x01000000, 0x00000002}, + {0x50464343, 0x00800000, 0x00000001}, + {0x50464354, 0x04000000, 0x00000002}, + {0x50464441, 0x01000000, 0x00000001}, + {0x50464443, 0x04000000, 0x00000002}, + {0x50464542, 0x00800000, 0x00000001}, + {0x50464543, 0x01000000, 0x00000001}, + {0x50464641, 0x08000000, 0x00000003}, + {0x50464643, 0x00800000, 0x00000005}, + {0x50464741, 0x04000000, 0x00000002}, + {0x50464743, 0x00800000, 0x00000001}, + {0x50464759, 0x01000000, 0x00000001}, + {0x50464841, 0x02000000, 0x00000001}, + {0x50464843, 0x02000000, 0x00000002}, + {0x50464859, 0x00800000, 0x00000002}, + {0x50464943, 0x02000000, 0x00000001}, + {0x50464959, 0x04000000, 0x00000002}, + {0x50464A59, 0x08000000, 0x00000002}, + {0x50464B43, 0x02000000, 0x00000001}, + {0x50464B59, 0x02000000, 0x00000001}, + {0x50464C42, 0x10000000, 0x00000003}, + {0x50464C43, 0x02000000, 0x00000001}, + {0x50464C54, 0x01000000, 0x00000001}, + {0x50464C59, 0x04000000, 0x00000001}, + {0x50464D41, 0x01000000, 0x00000001}, + {0x50464D42, 0x02000000, 0x00000002}, + {0x50464D59, 0x04000000, 0x00000003}, + {0x50464E41, 0x02000000, 0x00000005}, + {0x50464F41, 0x01000000, 0x00000001}, + {0x50465042, 0x04000000, 0x00000002}, + {0x50465054, 0x02000000, 0x00000001}, + {0x50465159, 0x02000000, 0x00000002}, + {0x50465241, 0x08000000, 0x00000003}, + {0x50465242, 0x08000000, 0x00000003}, + {0x50465243, 0x02000000, 0x00000002}, + {0x50465259, 0x02000000, 0x00000002}, + {0x50465341, 0x04000000, 0x00000005}, + {0x50465342, 0x02000000, 0x00000001}, + {0x50465359, 0x04000000, 0x00000001}, + {0x50465441, 0x01000000, 0x00000001}, + {0x50465443, 0x08000000, 0x00000001}, + {0x50465541, 0x04000000, 0x00000002}, + {0x50465543, 0x01000000, 0x00000001}, + {0x50465643, 0x01000000, 0x00000001}, + {0x50465659, 0x02000000, 0x00000001}, + {0x50465743, 0x02000000, 0x00000002}, + {0x50465841, 0x08000000, 0x00000003}, + {0x50465842, 0x04000000, 0x00000001}, + {0x50465943, 0x08000000, 0x00000003}, + {0x50465956, 0x02000000, 0x00000001}, + {0x50465A42, 0x04000000, 0x00000001}, + {0x50473241, 0x02000000, 0x00000003}, + {0x50473459, 0x01000000, 0x00000008}, + {0x50473559, 0x01000000, 0x00000002}, + {0x50473642, 0x01000000, 0x00000001}, + {0x50473742, 0x00800000, 0x00000001}, + {0x50473743, 0x01000000, 0x00000001}, + {0x50473759, 0x08000000, 0x00000008}, + {0x50474142, 0x01000000, 0x00000001}, + {0x50474143, 0x02000000, 0x00000001}, + {0x50474159, 0x04000000, 0x00000001}, + {0x50474243, 0x02000000, 0x00000005}, + {0x50474254, 0x00800000, 0x00000001}, + {0x50474259, 0x00800000, 0x00000001}, + {0x50474354, 0x04000000, 0x00000001}, + {0x50474441, 0x04000000, 0x00000005}, + {0x50474443, 0x04000000, 0x00000006}, + {0x50474541, 0x04000000, 0x00000001}, + {0x50474542, 0x00800000, 0x00000001}, + {0x50474641, 0x04000000, 0x00000001}, + {0x50474659, 0x01000000, 0x00000001}, + {0x50474742, 0x02000000, 0x00000005}, + {0x50474754, 0x00800000, 0x00000001}, + {0x50474842, 0x02000000, 0x00000001}, + {0x50474942, 0x02000000, 0x00000001}, + {0x50474959, 0x02000000, 0x00000001}, + {0x50474B41, 0x02000000, 0x00000002}, + {0x50474B59, 0x10000000, 0x00000003}, + {0x50474C59, 0x04000000, 0x00000001}, + {0x50474D41, 0x01000000, 0x00000001}, + {0x50474D42, 0x02000000, 0x00000001}, + {0x50474D43, 0x04000000, 0x00000001}, + {0x50474D54, 0x04000000, 0x00000002}, + {0x50474E41, 0x08000000, 0x00000005}, + {0x50474E59, 0x08000000, 0x00000003}, + {0x50474F41, 0x00800000, 0x00000001}, + {0x50474F59, 0x08000000, 0x00000003}, + {0x50475041, 0x01000000, 0x00000001}, + {0x50475059, 0x04000000, 0x00000002}, + {0x50475241, 0x02000000, 0x00000005}, + {0x50475243, 0x01000000, 0x00000001}, + {0x50475541, 0x02000000, 0x00000002}, + {0x50475543, 0x02000000, 0x00000002}, + {0x50475842, 0x04000000, 0x00000002}, + {0x50475843, 0x00800000, 0x00000001}, + {0x50475941, 0x04000000, 0x00000002}, + {0x50475956, 0x04000000, 0x00000001}, + {0x50483241, 0x02000000, 0x00000005}, + {0x50483243, 0x02000000, 0x00000002}, + {0x50483341, 0x02000000, 0x00000001}, + {0x50483343, 0x00800000, 0x00000001}, + {0x50483442, 0x02000000, 0x00000001}, + {0x50483741, 0x02000000, 0x00000001}, + {0x50483742, 0x04000000, 0x00000002}, + {0x50483842, 0x04000000, 0x00000002}, + {0x50484159, 0x04000000, 0x00000002}, + {0x50484241, 0x08000000, 0x00000002}, + {0x50484259, 0x02000000, 0x00000002}, + {0x50484341, 0x04000000, 0x00000005}, + {0x50484342, 0x00800000, 0x00000001}, + {0x50484442, 0x02000000, 0x00000002}, + {0x50484459, 0x02000000, 0x00000005}, + {0x50484541, 0x04000000, 0x00000002}, + {0x50484542, 0x01000000, 0x00000002}, + {0x50484559, 0x04000000, 0x00000001}, + {0x50484643, 0x04000000, 0x00000003}, + {0x50484659, 0x04000000, 0x00000002}, + {0x50484742, 0x10000000, 0x00000001}, + {0x50484743, 0x02000000, 0x00000002}, + {0x50484759, 0x08000000, 0x00000001}, + {0x50484841, 0x04000000, 0x00000001}, + {0x50484842, 0x01000000, 0x00000001}, + {0x50484943, 0x04000000, 0x00000002}, + {0x50484959, 0x02000000, 0x00000002}, + {0x50484A42, 0x01000000, 0x00000001}, + {0x50484B43, 0x02000000, 0x00000002}, + {0x50484B56, 0x02000000, 0x00000002}, + {0x50484C41, 0x02000000, 0x00000001}, + {0x50484C42, 0x08000000, 0x00000001}, + {0x50484C54, 0x01000000, 0x00000001}, + {0x50484D41, 0x04000000, 0x00000005}, + {0x50484D42, 0x04000000, 0x00000001}, + {0x50484D54, 0x00800000, 0x00000001}, + {0x50484E41, 0x08000000, 0x00000006}, + {0x50484E43, 0x04000000, 0x00000002}, + {0x50485041, 0x02000000, 0x00000005}, + {0x50485043, 0x04000000, 0x00000001}, + {0x50485243, 0x02000000, 0x00000002}, + {0x50485254, 0x02000000, 0x00000001}, + {0x50485341, 0x02000000, 0x00000002}, + {0x50485441, 0x04000000, 0x00000001}, + {0x50485641, 0x04000000, 0x00000002}, + {0x50485643, 0x04000000, 0x00000002}, + {0x50485741, 0x01000000, 0x00000001}, + {0x50485759, 0x01000000, 0x00000001}, + {0x50485843, 0x02000000, 0x00000001}, + {0x50485959, 0x04000000, 0x00000001}, + {0x50485A42, 0x01000000, 0x00000001}, + {0x50485A59, 0x04000000, 0x00000001}, + {0x50493241, 0x02000000, 0x00000005}, + {0x50493242, 0x04000000, 0x00000001}, + {0x50493341, 0x08000000, 0x00000002}, + {0x50493441, 0x04000000, 0x00000001}, + {0x50493642, 0x04000000, 0x00000002}, + {0x50493741, 0x02000000, 0x00000001}, + {0x50493742, 0x02000000, 0x00000001}, + {0x50493842, 0x04000000, 0x00000001}, + {0x50494159, 0x04000000, 0x00000001}, + {0x50494341, 0x02000000, 0x00000002}, + {0x50494342, 0x02000000, 0x00000002}, + {0x50494359, 0x01000000, 0x00000001}, + {0x50494442, 0x04000000, 0x00000001}, + {0x50494443, 0x02000000, 0x00000001}, + {0x50494542, 0x01000000, 0x00000001}, + {0x50494641, 0x02000000, 0x00000002}, + {0x50494643, 0x08000000, 0x00000003}, + {0x50494659, 0x04000000, 0x00000001}, + {0x50494742, 0x04000000, 0x00000001}, + {0x50494759, 0x00800000, 0x00000002}, + {0x50494842, 0x04000000, 0x00000002}, + {0x50494959, 0x00800000, 0x00000001}, + {0x50494A43, 0x02000000, 0x00000002}, + {0x50494B42, 0x08000000, 0x00000007}, + {0x50494C43, 0x04000000, 0x00000001}, + {0x50494C56, 0x02000000, 0x00000001}, + {0x50494C59, 0x04000000, 0x00000002}, + {0x50494D43, 0x00800000, 0x00000001}, + {0x50494E41, 0x08000000, 0x00000005}, + {0x50494E42, 0x02000000, 0x00000001}, + {0x50494E43, 0x04000000, 0x00000001}, + {0x50494E59, 0x08000000, 0x00000002}, + {0x50494F42, 0x02000000, 0x00000002}, + {0x50495042, 0x00800000, 0x00000001}, + {0x50495043, 0x01000000, 0x00000002}, + {0x50495056, 0x02000000, 0x00000002}, + {0x50495059, 0x02000000, 0x00000003}, + {0x50495141, 0x02000000, 0x00000005}, + {0x50495241, 0x01000000, 0x00000001}, + {0x50495243, 0x02000000, 0x00000002}, + {0x50495259, 0x04000000, 0x00000002}, + {0x50495341, 0x02000000, 0x00000002}, + {0x50495342, 0x04000000, 0x00000001}, + {0x50495441, 0x01000000, 0x00000008}, + {0x50495442, 0x01000000, 0x00000001}, + {0x50495456, 0x02000000, 0x00000001}, + {0x50495541, 0x02000000, 0x00000001}, + {0x50495543, 0x02000000, 0x00000002}, + {0x50495559, 0x04000000, 0x00000002}, + {0x50495641, 0x04000000, 0x00000001}, + {0x50495659, 0x08000000, 0x00000003}, + {0x50495741, 0x08000000, 0x00000005}, + {0x50495742, 0x01000000, 0x00000002}, + {0x50495941, 0x01000000, 0x00000001}, + {0x50495A41, 0x00800000, 0x00000002}, + {0x504A3259, 0x04000000, 0x00000008}, + {0x504A3343, 0x10000000, 0x00000003}, + {0x504A3356, 0x04000000, 0x00000001}, + {0x504A3442, 0x00800000, 0x00000001}, + {0x504A3542, 0x01000000, 0x00000001}, + {0x504A3642, 0x00800000, 0x00000001}, + {0x504A3742, 0x01000000, 0x00000001}, + {0x504A4241, 0x04000000, 0x00000005}, + {0x504A4243, 0x08000000, 0x00000003}, + {0x504A4259, 0x00800000, 0x00000001}, + {0x504A4341, 0x04000000, 0x00000001}, + {0x504A4343, 0x04000000, 0x00000002}, + {0x504A4359, 0x02000000, 0x00000005}, + {0x504A4559, 0x01000000, 0x00000002}, + {0x504A4643, 0x02000000, 0x00000002}, + {0x504A4743, 0x02000000, 0x00000002}, + {0x504A4759, 0x02000000, 0x00000001}, + {0x504A4841, 0x01000000, 0x00000002}, + {0x504A4943, 0x00800000, 0x00000001}, + {0x504A4959, 0x00000000, 0x00000002}, + {0x504A4A43, 0x00800000, 0x00000002}, + {0x504A4B43, 0x02000000, 0x00000001}, + {0x504A4C41, 0x01000000, 0x00000001}, + {0x504A4C42, 0x04000000, 0x00000001}, + {0x504A4C43, 0x08000000, 0x00000002}, + {0x504A4C54, 0x08000000, 0x00000002}, + {0x504A4C59, 0x04000000, 0x00000001}, + {0x504A4D43, 0x01000000, 0x00000002}, + {0x504A4D59, 0x04000000, 0x00000001}, + {0x504A4E41, 0x02000000, 0x00000001}, + {0x504A4E42, 0x01000000, 0x00000001}, + {0x504A4E43, 0x02000000, 0x00000001}, + {0x504A4E59, 0x02000000, 0x00000001}, + {0x504A4F42, 0x04000000, 0x00000002}, + {0x504A5042, 0x00800000, 0x00000001}, + {0x504A5043, 0x04000000, 0x00000002}, + {0x504A5141, 0x08000000, 0x00000001}, + {0x504A5143, 0x00800000, 0x00000001}, + {0x504A5243, 0x02000000, 0x00000001}, + {0x504A5259, 0x08000000, 0x00000002}, + {0x504A5341, 0x04000000, 0x00000005}, + {0x504A5342, 0x01000000, 0x00000001}, + {0x504A5359, 0x00800000, 0x00000001}, + {0x504A5441, 0x01000000, 0x00000002}, + {0x504A5541, 0x04000000, 0x00000001}, + {0x504A5542, 0x08000000, 0x00000001}, + {0x504A5641, 0x04000000, 0x00000002}, + {0x504A5659, 0x01000000, 0x00000001}, + {0x504A5743, 0x00000000, 0x00000001}, + {0x504A5759, 0x00800000, 0x00000002}, + {0x504A5841, 0x08000000, 0x00000003}, + {0x504A5842, 0x00000000, 0x00000001}, + {0x504A5A43, 0x01000000, 0x00000001}, + {0x504B3342, 0x01000000, 0x00000001}, + {0x504B3443, 0x00800000, 0x00000001}, + {0x504B3641, 0x08000000, 0x00000003}, + {0x504B3642, 0x08000000, 0x00000003}, + {0x504B3842, 0x02000000, 0x00000002}, + {0x504B3859, 0x00800000, 0x00000008}, + {0x504B4159, 0x08000000, 0x00000002}, + {0x504B4241, 0x00800000, 0x00000001}, + {0x504B4242, 0x02000000, 0x00000002}, + {0x504B4243, 0x04000000, 0x00000002}, + {0x504B4343, 0x04000000, 0x00000001}, + {0x504B4541, 0x04000000, 0x00000002}, + {0x504B4641, 0x00800000, 0x00000001}, + {0x504B4742, 0x01000000, 0x00000001}, + {0x504B4841, 0x04000000, 0x00000003}, + {0x504B4843, 0x01000000, 0x00000001}, + {0x504B4A59, 0x08000000, 0x00000002}, + {0x504B4B41, 0x01000000, 0x00000003}, + {0x504B4C41, 0x08000000, 0x00000003}, + {0x504B4C43, 0x04000000, 0x00000001}, + {0x504B4C54, 0x10000000, 0x00000002}, + {0x504B4C59, 0x02000000, 0x00000002}, + {0x504B4E41, 0x01000000, 0x00000001}, + {0x504B4E59, 0x04000000, 0x00000002}, + {0x504B5043, 0x02000000, 0x00000008}, + {0x504B5142, 0x01000000, 0x00000001}, + {0x504B5143, 0x04000000, 0x00000001}, + {0x504B5159, 0x02000000, 0x00000001}, + {0x504B5243, 0x00000000, 0x00000001}, + {0x504B5341, 0x04000000, 0x00000002}, + {0x504B5441, 0x04000000, 0x00000002}, + {0x504B5559, 0x04000000, 0x00000001}, + {0x504B5641, 0x01000000, 0x00000001}, + {0x504B5642, 0x04000000, 0x00000002}, + {0x504B5741, 0x04000000, 0x00000003}, + {0x504B5759, 0x04000000, 0x00000002}, + {0x504B5842, 0x02000000, 0x00000001}, + {0x504B5843, 0x04000000, 0x00000001}, + {0x504B5943, 0x02000000, 0x00000002}, + {0x504B5A41, 0x00800000, 0x00000002}, + {0x504C3241, 0x01000000, 0x00000003}, + {0x504C3242, 0x02000000, 0x00000001}, + {0x504C3541, 0x08000000, 0x00000002}, + {0x504C3543, 0x02000000, 0x00000001}, + {0x504C3742, 0x00800000, 0x00000001}, + {0x504C3743, 0x08000000, 0x00000002}, + {0x504C3859, 0x08000000, 0x00000000}, + {0x504C4143, 0x04000000, 0x00000001}, + {0x504C4241, 0x08000000, 0x00000002}, + {0x504C4242, 0x02000000, 0x00000001}, + {0x504C4259, 0x00800000, 0x00000001}, + {0x504C4341, 0x08000000, 0x00000003}, + {0x504C4354, 0x02000000, 0x00000001}, + {0x504C4441, 0x04000000, 0x00000003}, + {0x504C4443, 0x02000000, 0x00000005}, + {0x504C4642, 0x04000000, 0x00000002}, + {0x504C4741, 0x02000000, 0x00000001}, + {0x504C4742, 0x01000000, 0x00000001}, + {0x504C4759, 0x04000000, 0x00000002}, + {0x504C4859, 0x08000000, 0x00000003}, + {0x504C4A41, 0x04000000, 0x00000001}, + {0x504C4A43, 0x02000000, 0x00000002}, + {0x504C4A54, 0x00800000, 0x00000001}, + {0x504C4A59, 0x01000000, 0x00000002}, + {0x504C4D41, 0x02000000, 0x00000002}, + {0x504C4E41, 0x04000000, 0x00000001}, + {0x504C4E59, 0x04000000, 0x00000001}, + {0x504C4F41, 0x00800000, 0x00000001}, + {0x504C4F43, 0x08000000, 0x00000003}, + {0x504C5041, 0x00800000, 0x00000002}, + {0x504C5042, 0x02000000, 0x00000001}, + {0x504C5043, 0x02000000, 0x00000001}, + {0x504C5054, 0x04000000, 0x00000001}, + {0x504C5059, 0x00800000, 0x00000001}, + {0x504C5141, 0x00800000, 0x00000001}, + {0x504C5159, 0x08000000, 0x00000002}, + {0x504C5243, 0x02000000, 0x00000001}, + {0x504C5259, 0x02000000, 0x00000001}, + {0x504C5342, 0x02000000, 0x00000003}, + {0x504C5441, 0x01000000, 0x00000001}, + {0x504C5443, 0x02000000, 0x00000003}, + {0x504C5459, 0x00800000, 0x00000002}, + {0x504C5643, 0x01000000, 0x00000001}, + {0x504C5741, 0x08000000, 0x00000003}, + {0x504C5742, 0x04000000, 0x00000003}, + {0x504C5759, 0x02000000, 0x00000001}, + {0x504C5841, 0x04000000, 0x00000001}, + {0x504C5843, 0x04000000, 0x00000002}, + {0x504C5941, 0x02000000, 0x00000002}, + {0x504C5943, 0x04000000, 0x00000002}, + {0x504C5956, 0x04000000, 0x00000001}, + {0x504C5A41, 0x10000000, 0x00000007}, + {0x504C5A42, 0x00800000, 0x00000002}, + {0x504C5A43, 0x02000000, 0x00000002}, + {0x504D3241, 0x00800000, 0x00000001}, + {0x504D3242, 0x08000000, 0x00000002}, + {0x504D3243, 0x02000000, 0x00000002}, + {0x504D3341, 0x08000000, 0x00000002}, + {0x504D3443, 0x04000000, 0x00000001}, + {0x504D3643, 0x04000000, 0x00000002}, + {0x504D3743, 0x00000000, 0x00000003}, + {0x504D4142, 0x02000000, 0x00000002}, + {0x504D4154, 0x02000000, 0x00000001}, + {0x504D4156, 0x02000000, 0x00000001}, + {0x504D4159, 0x00800000, 0x00000001}, + {0x504D4241, 0x00800000, 0x00000001}, + {0x504D4242, 0x00800000, 0x00000001}, + {0x504D4243, 0x02000000, 0x00000002}, + {0x504D4254, 0x04000000, 0x00000001}, + {0x504D4341, 0x01000000, 0x00000001}, + {0x504D4342, 0x04000000, 0x00000001}, + {0x504D4343, 0x04000000, 0x00000002}, + {0x504D4354, 0x04000000, 0x00000002}, + {0x504D4356, 0x04000000, 0x00000002}, + {0x504D4359, 0x02000000, 0x00000001}, + {0x504D4441, 0x04000000, 0x00000005}, + {0x504D4442, 0x04000000, 0x00000002}, + {0x504D4459, 0x02000000, 0x00000002}, + {0x504D4556, 0x04000000, 0x00000001}, + {0x504D4559, 0x04000000, 0x00000003}, + {0x504D4642, 0x02000000, 0x00000002}, + {0x504D4742, 0x04000000, 0x00000003}, + {0x504D4843, 0x04000000, 0x00000002}, + {0x504D4943, 0x00000000, 0x00000002}, + {0x504D4959, 0x04000000, 0x00000001}, + {0x504D4A54, 0x00800000, 0x00000001}, + {0x504D4C42, 0x02000000, 0x00000001}, + {0x504D4C54, 0x08000000, 0x00000001}, + {0x504D4D59, 0x02000000, 0x00000001}, + {0x504D4E41, 0x04000000, 0x00000005}, + {0x504D4E43, 0x04000000, 0x00000001}, + {0x504D4E59, 0x01000000, 0x00000002}, + {0x504D5042, 0x02000000, 0x00000001}, + {0x504D5043, 0x04000000, 0x00000002}, + {0x504D5141, 0x00800000, 0x00000001}, + {0x504D5143, 0x00000000, 0x00000001}, + {0x504D5241, 0x04000000, 0x00000002}, + {0x504D5242, 0x01000000, 0x00000002}, + {0x504D5259, 0x02000000, 0x00000003}, + {0x504D5341, 0x01000000, 0x00000002}, + {0x504D5342, 0x01000000, 0x00000002}, + {0x504D5343, 0x01000000, 0x00000003}, + {0x504D5442, 0x00800000, 0x00000002}, + {0x504D5459, 0x04000000, 0x00000002}, + {0x504D5642, 0x02000000, 0x00000001}, + {0x504D5643, 0x02000000, 0x00000002}, + {0x504D5742, 0x01000000, 0x00000001}, + {0x504D5842, 0x04000000, 0x00000002}, + {0x504D5A43, 0x02000000, 0x00000001}, + {0x504E3242, 0x02000000, 0x00000001}, + {0x504E3342, 0x02000000, 0x00000001}, + {0x504E3542, 0x01000000, 0x00000001}, + {0x504E3543, 0x01000000, 0x00000001}, + {0x504E3641, 0x08000000, 0x00000003}, + {0x504E3642, 0x00800000, 0x00000001}, + {0x504E3742, 0x08000000, 0x00000003}, + {0x504E3841, 0x02000000, 0x00000005}, + {0x504E3842, 0x01000000, 0x00000001}, + {0x504E4142, 0x01000000, 0x00000002}, + {0x504E4143, 0x02000000, 0x00000005}, + {0x504E4241, 0x08000000, 0x00000002}, + {0x504E4243, 0x02000000, 0x00000001}, + {0x504E4259, 0x04000000, 0x00000007}, + {0x504E4341, 0x01000000, 0x00000002}, + {0x504E4343, 0x00000000, 0x00000001}, + {0x504E4443, 0x08000000, 0x00000001}, + {0x504E4541, 0x04000000, 0x00000002}, + {0x504E4542, 0x00800000, 0x00000001}, + {0x504E4559, 0x00800000, 0x00000001}, + {0x504E4641, 0x02000000, 0x00000002}, + {0x504E4642, 0x00800000, 0x00000001}, + {0x504E4654, 0x04000000, 0x00000002}, + {0x504E4741, 0x02000000, 0x00000001}, + {0x504E4743, 0x04000000, 0x00000002}, + {0x504E4759, 0x04000000, 0x00000002}, + {0x504E4841, 0x02000000, 0x00000001}, + {0x504E4843, 0x02000000, 0x00000002}, + {0x504E4859, 0x00000000, 0x00000003}, + {0x504E4A41, 0x02000000, 0x00000002}, + {0x504E4A42, 0x02000000, 0x00000001}, + {0x504E4C43, 0x02000000, 0x00000002}, + {0x504E4C59, 0x08000000, 0x00000002}, + {0x504E4D54, 0x01000000, 0x00000002}, + {0x504E4D59, 0x01000000, 0x00000002}, + {0x504E4E42, 0x04000000, 0x00000002}, + {0x504E4E59, 0x08000000, 0x00000003}, + {0x504E4F41, 0x02000000, 0x00000005}, + {0x504E4F43, 0x02000000, 0x00000001}, + {0x504E4F59, 0x04000000, 0x00000003}, + {0x504E5041, 0x02000000, 0x00000001}, + {0x504E5042, 0x02000000, 0x00000002}, + {0x504E5043, 0x02000000, 0x00000008}, + {0x504E5142, 0x04000000, 0x00000001}, + {0x504E5159, 0x04000000, 0x00000002}, + {0x504E5241, 0x02000000, 0x00000001}, + {0x504E5243, 0x01000000, 0x00000001}, + {0x504E5341, 0x00800000, 0x00000002}, + {0x504E5342, 0x02000000, 0x00000001}, + {0x504E5343, 0x08000000, 0x00000003}, + {0x504E5359, 0x04000000, 0x00000002}, + {0x504E5442, 0x04000000, 0x00000002}, + {0x504E5443, 0x01000000, 0x00000002}, + {0x504E5642, 0x04000000, 0x00000001}, + {0x504E5656, 0x02000000, 0x00000002}, + {0x504E5A43, 0x04000000, 0x00000002}, + {0x504F3241, 0x04000000, 0x00000003}, + {0x504F3341, 0x01000000, 0x00000001}, + {0x504F3441, 0x02000000, 0x00000005}, + {0x504F3442, 0x00800000, 0x00000001}, + {0x504F3541, 0x01000000, 0x00000001}, + {0x504F3543, 0x01000000, 0x00000001}, + {0x504F3642, 0x02000000, 0x00000001}, + {0x504F3743, 0x04000000, 0x00000002}, + {0x504F3959, 0x00800000, 0x00000000}, + {0x504F4142, 0x04000000, 0x00000001}, + {0x504F4143, 0x02000000, 0x00000001}, + {0x504F4156, 0x04000000, 0x00000001}, + {0x504F4241, 0x02000000, 0x00000001}, + {0x504F4259, 0x08000000, 0x00000003}, + {0x504F4341, 0x04000000, 0x00000005}, + {0x504F4342, 0x01000000, 0x00000001}, + {0x504F4359, 0x04000000, 0x00000001}, + {0x504F4742, 0x00800000, 0x00000002}, + {0x504F4743, 0x01000000, 0x00000001}, + {0x504F4759, 0x02000000, 0x00000001}, + {0x504F4842, 0x04000000, 0x00000001}, + {0x504F4843, 0x02000000, 0x00000001}, + {0x504F4941, 0x08000000, 0x00000005}, + {0x504F4942, 0x02000000, 0x00000001}, + {0x504F4959, 0x00800000, 0x00000001}, + {0x504F4A42, 0x04000000, 0x00000001}, + {0x504F4A43, 0x04000000, 0x00000002}, + {0x504F4C42, 0x00800000, 0x00000001}, + {0x504F4D41, 0x04000000, 0x00000002}, + {0x504F4D59, 0x04000000, 0x00000001}, + {0x504F4E41, 0x02000000, 0x00000002}, + {0x504F4E42, 0x01000000, 0x00000001}, + {0x504F4F42, 0x00400000, 0x00000002}, + {0x504F4F43, 0x04000000, 0x00000002}, + {0x504F5043, 0x01000000, 0x00000002}, + {0x504F5059, 0x04000000, 0x00000003}, + {0x504F5143, 0x02000000, 0x00000001}, + {0x504F5159, 0x00800000, 0x00000001}, + {0x504F5259, 0x04000000, 0x00000002}, + {0x504F5342, 0x02000000, 0x00000001}, + {0x504F5343, 0x00000000, 0x00000002}, + {0x504F5359, 0x01000000, 0x00000002}, + {0x504F5541, 0x00800000, 0x00000001}, + {0x504F5741, 0x02000000, 0x00000002}, + {0x504F5743, 0x00800000, 0x00000001}, + {0x504F5759, 0x00800000, 0x00000001}, + {0x504F5841, 0x01000000, 0x00000002}, + {0x504F5843, 0x04000000, 0x00000001}, + {0x504F5A42, 0x04000000, 0x00000003}, + {0x504F5A43, 0x02000000, 0x00000001}, + {0x50503342, 0x04000000, 0x00000001}, + {0x50503343, 0x04000000, 0x00000002}, + {0x50503441, 0x02000000, 0x00000002}, + {0x50503541, 0x04000000, 0x00000001}, + {0x50503643, 0x04000000, 0x00000007}, + {0x50503659, 0x04000000, 0x00000008}, + {0x50504143, 0x02000000, 0x00000003}, + {0x50504159, 0x01000000, 0x00000001}, + {0x50504243, 0x01000000, 0x00000002}, + {0x50504259, 0x02000000, 0x00000001}, + {0x50504341, 0x01000000, 0x00000002}, + {0x50504441, 0x00800000, 0x00000002}, + {0x50504442, 0x00800000, 0x00000001}, + {0x50504443, 0x00000000, 0x00000002}, + {0x50504459, 0x02000000, 0x00000001}, + {0x50504542, 0x01000000, 0x00000002}, + {0x50504543, 0x08000000, 0x00000002}, + {0x50504741, 0x04000000, 0x00000002}, + {0x50504742, 0x04000000, 0x00000002}, + {0x50504743, 0x02000000, 0x00000001}, + {0x50504754, 0x02000000, 0x00000001}, + {0x50504841, 0x04000000, 0x00000001}, + {0x50504941, 0x00800000, 0x00000008}, + {0x50504A41, 0x00800000, 0x00000001}, + {0x50504A43, 0x04000000, 0x00000002}, + {0x50504B41, 0x01000000, 0x00000001}, + {0x50504C42, 0x04000000, 0x00000002}, + {0x50504C43, 0x04000000, 0x00000003}, + {0x50504C59, 0x00800000, 0x00000002}, + {0x50504D43, 0x04000000, 0x00000001}, + {0x50504D44, 0x10000000, 0xFFFFFFFF}, + {0x50504E41, 0x01000000, 0x00000001}, + {0x50504E42, 0x04000000, 0x00000001}, + {0x50504E43, 0x01000000, 0x00000002}, + {0x50504E59, 0x04000000, 0x00000002}, + {0x50504F43, 0x01000000, 0x00000003}, + {0x50505041, 0x01000000, 0x00000002}, + {0x50505141, 0x02000000, 0x00000002}, + {0x50505143, 0x01000000, 0x00000001}, + {0x50505241, 0x04000000, 0x00000001}, + {0x50505242, 0x08000000, 0x00000002}, + {0x50505341, 0x02000000, 0x00000003}, + {0x50505343, 0x02000000, 0x00000003}, + {0x50505359, 0x02000000, 0x00000005}, + {0x50505543, 0x00800000, 0x00000001}, + {0x50505642, 0x08000000, 0x00000006}, + {0x50505659, 0x08000000, 0x00000003}, + {0x50505741, 0x01000000, 0x00000001}, + {0x50505742, 0x00800000, 0x00000001}, + {0x50505743, 0x02000000, 0x00000002}, + {0x50505841, 0x02000000, 0x00000005}, + {0x50505843, 0x02000000, 0x00000001}, + {0x50505943, 0x04000000, 0x00000002}, + {0x50505A41, 0x01000000, 0x00000002}, + {0x50505A42, 0x01000000, 0x00000001}, + {0x50505A55, 0x08000000, 0x00000003}, + {0x50513243, 0x00800000, 0x00000001}, + {0x50513342, 0x00800000, 0x00000001}, + {0x50513543, 0x01000000, 0x00000002}, + {0x50513642, 0x00800000, 0x00000001}, + {0x50513643, 0x08000000, 0x00000001}, + {0x50513841, 0x02000000, 0x00000005}, + {0x50513842, 0x00800000, 0x00000001}, + {0x50513859, 0x00800000, 0x00000000}, + {0x50514143, 0x02000000, 0x00000002}, + {0x50514242, 0x00800000, 0x00000001}, + {0x50514243, 0x02000000, 0x00000002}, + {0x50514259, 0x02000000, 0x00000002}, + {0x50514359, 0x04000000, 0x00000002}, + {0x50514459, 0x10000000, 0x00000003}, + {0x50514559, 0x00800000, 0x00000001}, + {0x50514641, 0x04000000, 0x00000002}, + {0x50514642, 0x00800000, 0x00000001}, + {0x50514742, 0x02000000, 0x00000002}, + {0x50514743, 0x04000000, 0x00000003}, + {0x50514759, 0x04000000, 0x00000002}, + {0x50514841, 0x02000000, 0x00000001}, + {0x50514943, 0x02000000, 0x00000002}, + {0x50514A41, 0x04000000, 0x00000002}, + {0x50514A43, 0x00800000, 0x00000002}, + {0x50514A59, 0x01000000, 0x00000001}, + {0x50514B41, 0x02000000, 0x00000001}, + {0x50514B43, 0x02000000, 0x00000001}, + {0x50514C41, 0x00800000, 0x00000001}, + {0x50514C43, 0x04000000, 0x00000001}, + {0x50514D41, 0x04000000, 0x00000005}, + {0x50514D42, 0x04000000, 0x00000001}, + {0x50514D54, 0x02000000, 0x00000002}, + {0x50514E41, 0x00800000, 0x00000002}, + {0x50514E42, 0x02000000, 0x00000001}, + {0x50514F41, 0x01000000, 0x00000001}, + {0x50514F43, 0x04000000, 0x00000002}, + {0x50515043, 0x02000000, 0x00000001}, + {0x50515141, 0x02000000, 0x00000002}, + {0x50515143, 0x04000000, 0x00000001}, + {0x50515243, 0x02000000, 0x00000001}, + {0x50515259, 0x02000000, 0x00000001}, + {0x50515341, 0x01000000, 0x00000002}, + {0x50515343, 0x01000000, 0x00000001}, + {0x50515359, 0x02000000, 0x00000002}, + {0x50515442, 0x01000000, 0x00000001}, + {0x50515641, 0x02000000, 0x00000002}, + {0x50515643, 0x02000000, 0x00000002}, + {0x50515741, 0x01000000, 0x00000001}, + {0x50515743, 0x02000000, 0x00000001}, + {0x50515842, 0x04000000, 0x00000001}, + {0x50515941, 0x01000000, 0x00000002}, + {0x50515943, 0x04000000, 0x00000001}, + {0x50515A41, 0x01000000, 0x00000002}, + {0x50523341, 0x01000000, 0x00000002}, + {0x50523342, 0x08000000, 0x00000005}, + {0x50523443, 0x02000000, 0x00000001}, + {0x50523459, 0x04000000, 0x00000008}, + {0x50523542, 0x10000000, 0x00000001}, + {0x50523559, 0x04000000, 0x00000008}, + {0x50523642, 0x08000000, 0x00000002}, + {0x50523743, 0x00800000, 0x00000001}, + {0x50524241, 0x04000000, 0x00000002}, + {0x50524243, 0x01000000, 0x00000002}, + {0x50524254, 0x04000000, 0x00000001}, + {0x50524255, 0x00800000, 0x00000005}, + {0x50524259, 0x04000000, 0x00000001}, + {0x50524341, 0x02000000, 0x00000001}, + {0x50524343, 0x00800000, 0x00000002}, + {0x50524354, 0x00800000, 0x00000001}, + {0x50524441, 0x01000000, 0x00000002}, + {0x50524442, 0x04000000, 0x00000005}, + {0x50524459, 0x00800000, 0x00000001}, + {0x50524541, 0x01000000, 0x00000002}, + {0x50524543, 0x02000000, 0x00000003}, + {0x50524554, 0x00800000, 0x00000001}, + {0x50524559, 0x04000000, 0x00000003}, + {0x50524641, 0x04000000, 0x00000001}, + {0x50524659, 0x01000000, 0x00000001}, + {0x50524741, 0x02000000, 0x00000005}, + {0x50524754, 0x01000000, 0x00000001}, + {0x50524841, 0x02000000, 0x00000002}, + {0x50524942, 0x01000000, 0x00000001}, + {0x50524943, 0x04000000, 0x00000002}, + {0x50524A41, 0x08000000, 0x00000005}, + {0x50524A42, 0x01000000, 0x00000001}, + {0x50524A43, 0x08000000, 0x00000003}, + {0x50524C42, 0x10000000, 0x00000001}, + {0x50524C43, 0x04000000, 0x00000003}, + {0x50524C54, 0x08000000, 0x00000001}, + {0x50524D43, 0x02000000, 0x00000002}, + {0x50524D59, 0x01000000, 0x00000001}, + {0x50524E41, 0x04000000, 0x00000001}, + {0x50524E42, 0x04000000, 0x00000003}, + {0x50524E43, 0x04000000, 0x00000002}, + {0x50524F55, 0x08000000, 0x00000008}, + {0x50525041, 0x02000000, 0x00000002}, + {0x50525042, 0x00800000, 0x00000001}, + {0x50525054, 0x02000000, 0x00000001}, + {0x50525059, 0x02000000, 0x00000002}, + {0x50525141, 0x01000000, 0x00000002}, + {0x50525143, 0x04000000, 0x00000002}, + {0x50525159, 0x02000000, 0x00000001}, + {0x50525254, 0x01000000, 0x00000001}, + {0x50525259, 0x02000000, 0x00000002}, + {0x50525359, 0x01000000, 0x00000005}, + {0x50525441, 0x01000000, 0x00000002}, + {0x50525442, 0x02000000, 0x00000002}, + {0x50525443, 0x02000000, 0x00000003}, + {0x50525459, 0x00000000, 0x00000001}, + {0x50525741, 0x02000000, 0x00000005}, + {0x50525743, 0x02000000, 0x00000001}, + {0x50525759, 0x04000000, 0x00000001}, + {0x50525843, 0x04000000, 0x00000001}, + {0x50525941, 0x00800000, 0x00000001}, + {0x50525943, 0x02000000, 0x00000001}, + {0x50525959, 0x04000000, 0x00000001}, + {0x50525A43, 0x02000000, 0x00000001}, + {0x50533242, 0x08000000, 0x00000002}, + {0x50533243, 0x08000000, 0x00000004}, + {0x50533341, 0x02000000, 0x00000001}, + {0x50533343, 0x01000000, 0x00000002}, + {0x50533543, 0x08000000, 0x00000001}, + {0x50533641, 0x04000000, 0x00000001}, + {0x50533642, 0x04000000, 0x00000001}, + {0x50533659, 0x04000000, 0x00000008}, + {0x50533759, 0x04000000, 0x00000008}, + {0x50533841, 0x00800000, 0x00000002}, + {0x50534143, 0x02000000, 0x00000001}, + {0x50534156, 0x02000000, 0x00000001}, + {0x50534359, 0x00800000, 0x00000001}, + {0x50534443, 0x08000000, 0x00000001}, + {0x50534556, 0x04000000, 0x00000001}, + {0x50534641, 0x02000000, 0x00000002}, + {0x50534643, 0x02000000, 0x00000001}, + {0x50534743, 0x08000000, 0x00000001}, + {0x50534759, 0x04000000, 0x00000003}, + {0x50534841, 0x02000000, 0x00000002}, + {0x50534843, 0x02000000, 0x00000001}, + {0x50534859, 0x02000000, 0x00000003}, + {0x50534941, 0x01000000, 0x00000001}, + {0x50534943, 0x04000000, 0x00000001}, + {0x50534959, 0x04000000, 0x00000002}, + {0x50534A42, 0x04000000, 0x00000003}, + {0x50534A43, 0x01000000, 0x00000002}, + {0x50534A54, 0x00800000, 0x00000001}, + {0x50534C42, 0x04000000, 0x00000001}, + {0x50534C54, 0x02000000, 0x00000001}, + {0x50534D43, 0x02000000, 0x00000003}, + {0x50534D54, 0x01000000, 0x00000001}, + {0x50534E41, 0x01000000, 0x00000001}, + {0x50534F41, 0x08000000, 0x00000005}, + {0x50534F43, 0x02000000, 0x00000001}, + {0x50535042, 0x04000000, 0x00000002}, + {0x50535043, 0x04000000, 0x00000002}, + {0x50535143, 0x02000000, 0x00000001}, + {0x50535154, 0x00800000, 0x00000001}, + {0x50535159, 0x02000000, 0x00000002}, + {0x50535243, 0x00800000, 0x00000001}, + {0x50535341, 0x04000000, 0x00000002}, + {0x50535343, 0x00800000, 0x00000001}, + {0x50535459, 0x01000000, 0x00000001}, + {0x50535541, 0x04000000, 0x00000001}, + {0x50535542, 0x00800000, 0x00000002}, + {0x50535543, 0x02000000, 0x00000001}, + {0x50535559, 0x00800000, 0x00000001}, + {0x50535641, 0x02000000, 0x00000002}, + {0x50535643, 0x02000000, 0x00000001}, + {0x50535659, 0x02000000, 0x00000003}, + {0x50535741, 0x01000000, 0x00000002}, + {0x50535743, 0x00000000, 0x00000002}, + {0x50535842, 0x04000000, 0x00000003}, + {0x50535843, 0x00000000, 0x00000001}, + {0x50535941, 0x04000000, 0x00000001}, + {0x50543241, 0x02000000, 0x00000001}, + {0x50543341, 0x02000000, 0x00000002}, + {0x50543343, 0x08000000, 0x00000003}, + {0x50543442, 0x01000000, 0x00000002}, + {0x50543541, 0x04000000, 0x00000005}, + {0x50543641, 0x04000000, 0x00000001}, + {0x50543642, 0x04000000, 0x00000001}, + {0x50543643, 0x01000000, 0x00000002}, + {0x50543743, 0x01000000, 0x00000002}, + {0x50543841, 0x02000000, 0x00000002}, + {0x50544142, 0x04000000, 0x00000002}, + {0x50544143, 0x02000000, 0x00000002}, + {0x50544159, 0x01000000, 0x00000002}, + {0x50544241, 0x02000000, 0x00000001}, + {0x50544243, 0x02000000, 0x00000001}, + {0x50544254, 0x01000000, 0x00000001}, + {0x50544256, 0x02000000, 0x00000002}, + {0x50544259, 0x08000000, 0x00000003}, + {0x50544341, 0x02000000, 0x00000001}, + {0x50544459, 0x04000000, 0x00000003}, + {0x50544556, 0x08000000, 0x00000007}, + {0x50544559, 0x01000000, 0x00000001}, + {0x50544641, 0x00800000, 0x00000001}, + {0x50544642, 0x01000000, 0x00000001}, + {0x50544659, 0x08000000, 0x00000005}, + {0x50544742, 0x08000000, 0x00000002}, + {0x50544754, 0x04000000, 0x00000002}, + {0x50544759, 0x02000000, 0x00000001}, + {0x50544841, 0x01000000, 0x00000001}, + {0x50544941, 0x00800000, 0x00000001}, + {0x50544943, 0x01000000, 0x00000001}, + {0x50544A41, 0x02000000, 0x00000001}, + {0x50544A56, 0x04000000, 0x00000001}, + {0x50544B43, 0x04000000, 0x00000002}, + {0x50544C41, 0x00800000, 0x00000001}, + {0x50544C59, 0x08000000, 0x00000002}, + {0x50544D41, 0x04000000, 0x00000002}, + {0x50544D43, 0x02000000, 0x00000001}, + {0x50544D54, 0x04000000, 0x00000003}, + {0x50544D59, 0x02000000, 0x00000002}, + {0x50544F43, 0x02000000, 0x00000001}, + {0x50545041, 0x01000000, 0x00000002}, + {0x50545054, 0x08000000, 0x00000001}, + {0x50545059, 0x02000000, 0x00000005}, + {0x50545154, 0x02000000, 0x00000002}, + {0x50545259, 0x02000000, 0x00000002}, + {0x50545341, 0x02000000, 0x00000001}, + {0x50545359, 0x04000000, 0x00000001}, + {0x50545456, 0x04000000, 0x00000001}, + {0x50545541, 0x02000000, 0x00000001}, + {0x50545542, 0x02000000, 0x00000001}, + {0x50545559, 0x04000000, 0x00000002}, + {0x50545642, 0x01000000, 0x00000001}, + {0x50545643, 0x02000000, 0x00000001}, + {0x50545659, 0x02000000, 0x00000001}, + {0x50545841, 0x00800000, 0x00000001}, + {0x50545942, 0x08000000, 0x00000002}, + {0x50545959, 0x02000000, 0x00000002}, + {0x50545A41, 0x01000000, 0x00000005}, + {0x50545A59, 0x01000000, 0x00000005}, + {0x50553242, 0x02000000, 0x00000001}, + {0x50553342, 0x02000000, 0x00000002}, + {0x50553459, 0x02000000, 0x00000008}, + {0x50553541, 0x02000000, 0x00000005}, + {0x50553659, 0x01000000, 0x00000008}, + {0x50553743, 0x02000000, 0x00000001}, + {0x50553842, 0x01000000, 0x00000001}, + {0x50554159, 0x04000000, 0x00000003}, + {0x50554241, 0x04000000, 0x00000005}, + {0x50554242, 0x08000000, 0x00000003}, + {0x50554259, 0x08000000, 0x00000003}, + {0x50554359, 0x00000000, 0x00000003}, + {0x50554442, 0x02000000, 0x00000001}, + {0x50554443, 0x01000000, 0x00000003}, + {0x50554454, 0x00800000, 0x00000001}, + {0x50554641, 0x01000000, 0x00000003}, + {0x50554643, 0x02000000, 0x00000002}, + {0x50554842, 0x04000000, 0x00000001}, + {0x50554854, 0x02000000, 0x00000001}, + {0x50554859, 0x00800000, 0x00000008}, + {0x50554943, 0x04000000, 0x00000002}, + {0x50554B41, 0x04000000, 0x00000001}, + {0x50554B42, 0x08000000, 0x00000005}, + {0x50554C41, 0x02000000, 0x00000002}, + {0x50554C54, 0x04000000, 0x00000001}, + {0x50554C59, 0x08000000, 0x00000005}, + {0x50554D41, 0x00800000, 0x00000001}, + {0x50554D42, 0x04000000, 0x00000001}, + {0x50554D43, 0x01000000, 0x00000003}, + {0x50554D54, 0x04000000, 0x00000003}, + {0x50554D59, 0x04000000, 0x00000002}, + {0x50554E41, 0x01000000, 0x00000001}, + {0x50554E42, 0x01000000, 0x00000001}, + {0x50554F42, 0x02000000, 0x00000001}, + {0x50555054, 0x01000000, 0x00000001}, + {0x50555059, 0x02000000, 0x00000008}, + {0x50555154, 0x00800000, 0x00000001}, + {0x50555159, 0x08000000, 0x00000003}, + {0x50555341, 0x04000000, 0x00000003}, + {0x50555342, 0x02000000, 0x00000001}, + {0x50555343, 0x02000000, 0x00000001}, + {0x50555442, 0x04000000, 0x00000002}, + {0x50555542, 0x04000000, 0x00000001}, + {0x50555741, 0x02000000, 0x00000001}, + {0x50555743, 0x04000000, 0x00000001}, + {0x50555841, 0x02000000, 0x00000001}, + {0x50555842, 0x04000000, 0x00000001}, + {0x50555843, 0x08000000, 0x00000002}, + {0x50555942, 0x00800000, 0x00000001}, + {0x50555943, 0x01000000, 0x00000002}, + {0x50555959, 0x04000000, 0x00000001}, + {0x50555A42, 0x02000000, 0x00000002}, + {0x50563241, 0x00800000, 0x00000001}, + {0x50563342, 0x02000000, 0x00000001}, + {0x50563343, 0x01000000, 0x00000001}, + {0x50563443, 0x01000000, 0x00000001}, + {0x50563643, 0x02000000, 0x00000001}, + {0x50563743, 0x00800000, 0x00000001}, + {0x50564143, 0x02000000, 0x00000002}, + {0x50564159, 0x04000000, 0x00000002}, + {0x50564242, 0x00800000, 0x00000001}, + {0x50564243, 0x04000000, 0x00000002}, + {0x50564341, 0x04000000, 0x00000002}, + {0x50564359, 0x01000000, 0x00000003}, + {0x50564441, 0x01000000, 0x00000001}, + {0x50564442, 0x00000000, 0x00000001}, + {0x50564443, 0x01000000, 0x00000001}, + {0x50564454, 0x07FFEC70, 0x00000003}, + {0x50564641, 0x04000000, 0x00000001}, + {0x50564642, 0x00800000, 0x00000001}, + {0x50564741, 0x02000000, 0x00000002}, + {0x50564841, 0x01000000, 0x00000001}, + {0x50564842, 0x02000000, 0x00000001}, + {0x50564843, 0x02000000, 0x00000003}, + {0x50564854, 0x04000000, 0x00000001}, + {0x50564942, 0x00800000, 0x00000001}, + {0x50564959, 0x08000000, 0x00000003}, + {0x50564A56, 0x04000000, 0x00000001}, + {0x50564C41, 0x01000000, 0x00000002}, + {0x50564C43, 0x04000000, 0x00000001}, + {0x50564C54, 0x02000000, 0x00000002}, + {0x50564D41, 0x04000000, 0x00000001}, + {0x50564D42, 0x00800000, 0x00000001}, + {0x50564D43, 0x00800000, 0x00000001}, + {0x50564D54, 0x04000000, 0x00000002}, + {0x50564E42, 0x02000000, 0x00000001}, + {0x50564E43, 0x10000000, 0x00000005}, + {0x50565042, 0x00800000, 0x00000002}, + {0x50565043, 0x04000000, 0x00000002}, + {0x50565059, 0x04000000, 0x00000001}, + {0x50565141, 0x01000000, 0x00000002}, + {0x50565143, 0x04000000, 0x00000001}, + {0x50565159, 0x01000000, 0x00000001}, + {0x50565243, 0x02000000, 0x00000001}, + {0x50565259, 0x02000000, 0x00000005}, + {0x50565341, 0x00800000, 0x00000001}, + {0x50565342, 0x02000000, 0x00000001}, + {0x50565343, 0x02000000, 0x00000005}, + {0x50565441, 0x02000000, 0x00000001}, + {0x50565442, 0x02000000, 0x00000002}, + {0x50565443, 0x04000000, 0x00000003}, + {0x50565459, 0x08000000, 0x00000003}, + {0x50565542, 0x02000000, 0x00000002}, + {0x50565642, 0x01000000, 0x00000002}, + {0x50565741, 0x01000000, 0x00000001}, + {0x50565742, 0x02000000, 0x00000001}, + {0x50565756, 0x04000000, 0x00000001}, + {0x50565841, 0x04000000, 0x00000003}, + {0x50565842, 0x02000000, 0x00000001}, + {0x50565859, 0x00800000, 0x00000001}, + {0x50565A41, 0x00800000, 0x00000001}, + {0x50565A43, 0x02000000, 0x00000001}, + {0x50573259, 0x04000000, 0x00000008}, + {0x50573341, 0x04000000, 0x00000002}, + {0x50573641, 0x02000000, 0x00000002}, + {0x50573643, 0x02000000, 0x00000002}, + {0x50573742, 0x01000000, 0x00000002}, + {0x50573759, 0x01000000, 0x00000001}, + {0x50574142, 0x02000000, 0x00000001}, + {0x50574159, 0x04000000, 0x00000002}, + {0x50574259, 0x01000000, 0x00000002}, + {0x50574343, 0x02000000, 0x00000001}, + {0x50574354, 0x02000000, 0x00000001}, + {0x50574442, 0x02000000, 0x00000001}, + {0x50574443, 0x00800000, 0x00000001}, + {0x50574459, 0x02000000, 0x00000005}, + {0x50574542, 0x04000000, 0x00000002}, + {0x50574641, 0x01000000, 0x00000001}, + {0x50574741, 0x01000000, 0x00000002}, + {0x50574759, 0x00800000, 0x00000001}, + {0x50574843, 0x02000000, 0x00000002}, + {0x50574859, 0x02000000, 0x00000001}, + {0x50574942, 0x04000000, 0x00000002}, + {0x50574A43, 0x00800000, 0x00000001}, + {0x50574A59, 0x00800000, 0x00000001}, + {0x50574B41, 0x04000000, 0x00000002}, + {0x50574B42, 0x00800000, 0x00000002}, + {0x50574B59, 0x08000000, 0x00000003}, + {0x50574C41, 0x02000000, 0x00000001}, + {0x50574C43, 0x10000000, 0x00000002}, + {0x50574C54, 0x02000000, 0x00000002}, + {0x50574C59, 0x02000000, 0x00000001}, + {0x50574D41, 0x04000000, 0x00000002}, + {0x50574D43, 0x02000000, 0x00000002}, + {0x50574D49, 0x04000000, 0x00000007}, + {0x50574D54, 0x01000000, 0x00000001}, + {0x50574D59, 0x01000000, 0x00000002}, + {0x50574E41, 0x02000000, 0x00000002}, + {0x50574E42, 0x02000000, 0x00000001}, + {0x50574E59, 0x02000000, 0x00000001}, + {0x50574F41, 0x00800000, 0x00000001}, + {0x50575041, 0x02000000, 0x00000001}, + {0x50575042, 0x01000000, 0x00000001}, + {0x50575043, 0x04000000, 0x00000002}, + {0x50575054, 0x00800000, 0x00000002}, + {0x50575141, 0x01000000, 0x00000001}, + {0x50575159, 0x00800000, 0x00000001}, + {0x50575243, 0x02000000, 0x00000002}, + {0x50575254, 0x04000000, 0x00000002}, + {0x50575259, 0x02000000, 0x00000005}, + {0x50575343, 0x04000000, 0x00000001}, + {0x50575442, 0x02000000, 0x00000001}, + {0x50575443, 0x08000000, 0x00000001}, + {0x50575542, 0x02000000, 0x00000001}, + {0x50575559, 0x02000000, 0x00000002}, + {0x50575641, 0x02000000, 0x00000002}, + {0x50575643, 0x01000000, 0x00000002}, + {0x50575941, 0x02000000, 0x00000002}, + {0x50575942, 0x00800000, 0x00000001}, + {0x50575A41, 0x02000000, 0x00000002}, + {0x50583242, 0x02000000, 0x00000002}, + {0x50583341, 0x04000000, 0x00000001}, + {0x50583542, 0x02000000, 0x00000003}, + {0x50583559, 0x00800000, 0x00000008}, + {0x50583659, 0x00800000, 0x00000008}, + {0x50584142, 0x04000000, 0x00000001}, + {0x50584143, 0x02000000, 0x00000003}, + {0x50584154, 0x00800000, 0x00000001}, + {0x50584159, 0x02000000, 0x00000002}, + {0x50584241, 0x04000000, 0x00000002}, + {0x50584242, 0x00800000, 0x00000001}, + {0x50584259, 0x00800000, 0x00000001}, + {0x50584341, 0x01000000, 0x00000003}, + {0x50584343, 0x01000000, 0x00000003}, + {0x50584354, 0x00800000, 0x00000001}, + {0x50584443, 0x02000000, 0x00000001}, + {0x50584459, 0x04000000, 0x00000001}, + {0x50584559, 0x02000000, 0x00000002}, + {0x50584641, 0x08000000, 0x00000003}, + {0x50584642, 0x04000000, 0x00000002}, + {0x50584741, 0x08000000, 0x00000003}, + {0x50584742, 0x02000000, 0x00000002}, + {0x50584759, 0x08000000, 0x00000002}, + {0x50584841, 0x00800000, 0x00000001}, + {0x50584843, 0x02000000, 0x00000003}, + {0x50584859, 0x01000000, 0x00000001}, + {0x50584943, 0x00800000, 0x00000001}, + {0x50584A43, 0x01000000, 0x00000001}, + {0x50584A59, 0x00800000, 0x00000001}, + {0x50584C41, 0x02000000, 0x00000001}, + {0x50584C43, 0x02000000, 0x00000002}, + {0x50584C59, 0x00800000, 0x00000001}, + {0x50584D41, 0x02000000, 0x00000001}, + {0x50584D42, 0x02000000, 0x00000001}, + {0x50584D59, 0x00800000, 0x00000001}, + {0x50584E41, 0x02000000, 0x00000001}, + {0x50584F41, 0x02000000, 0x00000001}, + {0x50585043, 0x01000000, 0x00000005}, + {0x50585054, 0x00800000, 0x00000002}, + {0x50585059, 0x00800000, 0x00000003}, + {0x50585143, 0x04000000, 0x00000001}, + {0x50585159, 0x01000000, 0x00000001}, + {0x50585342, 0x02000000, 0x00000001}, + {0x50585359, 0x01000000, 0x00000001}, + {0x50585441, 0x01000000, 0x00000002}, + {0x50585543, 0x04000000, 0x00000001}, + {0x50585559, 0x04000000, 0x00000003}, + {0x50585641, 0x01000000, 0x00000001}, + {0x50585741, 0x01000000, 0x00000002}, + {0x50585742, 0x02000000, 0x00000001}, + {0x50585759, 0x01000000, 0x00000002}, + {0x50585859, 0x04000000, 0x00000002}, + {0x50585941, 0x08000000, 0x00000005}, + {0x50585942, 0x10000000, 0x00000003}, + {0x50585A42, 0x02000000, 0x00000001}, + {0x50585A59, 0x04000000, 0x00000002}, + {0x50593259, 0x00800000, 0x00000008}, + {0x50593341, 0x04000000, 0x00000003}, + {0x50593342, 0x02000000, 0x00000001}, + {0x50593443, 0x02000000, 0x00000001}, + {0x50593542, 0x01000000, 0x00000001}, + {0x50593641, 0x01000000, 0x00000002}, + {0x50593842, 0x02000000, 0x00000001}, + {0x50594143, 0x02000000, 0x00000001}, + {0x50594159, 0x02000000, 0x00000001}, + {0x50594242, 0x00800000, 0x00000001}, + {0x50594243, 0x02000000, 0x00000001}, + {0x50594259, 0x02000000, 0x00000001}, + {0x50594343, 0x01000000, 0x00000001}, + {0x50594359, 0x00800000, 0x00000001}, + {0x50594442, 0x04000000, 0x00000002}, + {0x50594443, 0x02000000, 0x00000002}, + {0x50594459, 0x00800000, 0x00000001}, + {0x50594542, 0x00800000, 0x00000001}, + {0x50594641, 0x04000000, 0x00000001}, + {0x50594659, 0x08000000, 0x00000005}, + {0x50594741, 0x04000000, 0x00000005}, + {0x50594742, 0x01000000, 0x00000001}, + {0x50594842, 0x02000000, 0x00000001}, + {0x50594843, 0x00000000, 0x00000001}, + {0x50594859, 0x01000000, 0x00000001}, + {0x50594943, 0x04000000, 0x00000002}, + {0x50594959, 0x01000000, 0x00000001}, + {0x50594A42, 0x04000000, 0x00000001}, + {0x50594A59, 0x00800000, 0x00000001}, + {0x50594B41, 0x02000000, 0x00000003}, + {0x50594B42, 0x02000000, 0x00000002}, + {0x50594C41, 0x04000000, 0x00000001}, + {0x50594C43, 0x02000000, 0x00000002}, + {0x50594C59, 0x02000000, 0x00000002}, + {0x50594D54, 0x00800000, 0x00000001}, + {0x50594D59, 0x08000000, 0x00000005}, + {0x50594E41, 0x04000000, 0x00000003}, + {0x50594E42, 0x04000000, 0x00000001}, + {0x50594E43, 0x08000000, 0x00000002}, + {0x50594E59, 0x00800000, 0x00000001}, + {0x50594F41, 0x02000000, 0x00000002}, + {0x50594F43, 0x00000000, 0x00000002}, + {0x50595041, 0x02000000, 0x00000002}, + {0x50595042, 0x00800000, 0x00000001}, + {0x50595056, 0x10000000, 0x00000005}, + {0x50595241, 0x02000000, 0x00000002}, + {0x50595243, 0x01000000, 0x00000001}, + {0x50595254, 0x02000000, 0x00000001}, + {0x50595342, 0x02000000, 0x00000002}, + {0x50595344, 0x02000000, 0x00000001}, + {0x50595359, 0x01000000, 0x00000001}, + {0x50595442, 0x01000000, 0x00000002}, + {0x50595443, 0x01000000, 0x00000002}, + {0x50595543, 0x02000000, 0x00000001}, + {0x50595642, 0x08000000, 0x00000001}, + {0x50595743, 0x02000000, 0x00000003}, + {0x50595842, 0x04000000, 0x00000002}, + {0x50595941, 0x01000000, 0x00000002}, + {0x50595942, 0x08000000, 0x00000003}, + {0x50595943, 0x00800000, 0x00000001}, + {0x50595A41, 0x04000000, 0x00000002}, + {0x505A3243, 0x00800000, 0x00000002}, + {0x505A3441, 0x00800000, 0x00000001}, + {0x505A3442, 0x08000000, 0x00000002}, + {0x505A3443, 0x04000000, 0x00000002}, + {0x505A3542, 0x01000000, 0x00000001}, + {0x505A3642, 0x04000000, 0x00000003}, + {0x505A3659, 0x08000000, 0x00000000}, + {0x505A3742, 0x04000000, 0x00000001}, + {0x505A3842, 0x01000000, 0x00000001}, + {0x505A4159, 0x01000000, 0x00000001}, + {0x505A4241, 0x08000000, 0x00000003}, + {0x505A4243, 0x01000000, 0x00000003}, + {0x505A4259, 0x01000000, 0x00000001}, + {0x505A4341, 0x01000000, 0x00000001}, + {0x505A4342, 0x01000000, 0x00000002}, + {0x505A4343, 0x00800000, 0x00000001}, + {0x505A4359, 0x00800000, 0x00000001}, + {0x505A4441, 0x02000000, 0x00000002}, + {0x505A4442, 0x04000000, 0x00000003}, + {0x505A4443, 0x04000000, 0x00000002}, + {0x505A4459, 0x01000000, 0x00000002}, + {0x505A4641, 0x04000000, 0x00000001}, + {0x505A4642, 0x00800000, 0x00000001}, + {0x505A4742, 0x01000000, 0x00000002}, + {0x505A4743, 0x00000000, 0x00000001}, + {0x505A4759, 0x04000000, 0x00000001}, + {0x505A4841, 0x04000000, 0x00000001}, + {0x505A4842, 0x02000000, 0x00000003}, + {0x505A4859, 0x04000000, 0x00000002}, + {0x505A4941, 0x02000000, 0x00000002}, + {0x505A4943, 0x02000000, 0x00000001}, + {0x505A4A59, 0x04000000, 0x00000005}, + {0x505A4C42, 0x02000000, 0x00000001}, + {0x505A4C43, 0x04000000, 0x00000001}, + {0x505A4C59, 0x10000000, 0x00000002}, + {0x505A4D42, 0x00800000, 0x00000002}, + {0x505A4D54, 0x01000000, 0x00000002}, + {0x505A4D56, 0x04000000, 0x00000001}, + {0x505A4E41, 0x01000000, 0x00000001}, + {0x505A4E42, 0x01000000, 0x00000001}, + {0x505A4E59, 0x04000000, 0x00000002}, + {0x505A4F41, 0x01000000, 0x00000002}, + {0x505A4F42, 0x02000000, 0x00000001}, + {0x505A4F59, 0x00000000, 0x00000002}, + {0x505A5042, 0x00000000, 0x00000001}, + {0x505A5059, 0x01000000, 0x00000001}, + {0x505A5143, 0x02000000, 0x00000001}, + {0x505A5241, 0x04000000, 0x00000002}, + {0x505A5242, 0x04000000, 0x00000003}, + {0x505A5243, 0x00800000, 0x00000002}, + {0x505A5259, 0x01000000, 0x00000002}, + {0x505A5359, 0x08000000, 0x00000001}, + {0x505A5442, 0x02000000, 0x00000001}, + {0x505A5459, 0x04000000, 0x00000001}, + {0x505A5541, 0x04000000, 0x00000005}, + {0x505A5542, 0x00800000, 0x00000002}, + {0x505A5543, 0x04000000, 0x00000001}, + {0x505A5759, 0x04000000, 0x00000001}, + {0x505A5A42, 0x01000000, 0x00000001}, + {0x51374C42, 0x04000000, 0x00000001}, + {0x51375042, 0x02000000, 0x00000001}, + {0x51375142, 0x02000000, 0x00000001}, + {0x51385042, 0x04000000, 0x00000001}, + {0x51435143, 0x02000000, 0x00000001}, + {0x51454642, 0x04000000, 0x00000001}, + {0x514C5542, 0x02000000, 0x00000001}, + {0x514F5542, 0x01000000, 0x00000001}, + {0x51503642, 0x02000000, 0x00000001}, + {0x51573542, 0x02000000, 0x00000001}, + {0x51584C42, 0x04000000, 0x00000008}, + {0x51585042, 0x04000000, 0x00000003}, + {0x51594C42, 0x04000000, 0x00000008}, + {0x52335741, 0x04000000, 0x00000001}, + {0x52464443, 0x04000000, 0x00000002}, + {0x53323643, 0x04000000, 0x00000001}, + {0x53335141, 0x04000000, 0x00000002}, + {0x53335159, 0x04000000, 0x00000002}, + {0x53344259, 0x02000000, 0x00000001}, + {0x53344C43, 0x04000000, 0x00000002}, + {0x53354841, 0x02000000, 0x00000002}, + {0x53394341, 0x04000000, 0x00000001}, + {0x53414441, 0x04000000, 0x00000006}, + {0x53415041, 0x04000000, 0x00000006}, + {0x53415249, 0x10000000, 0x00000006}, + {0x53424542, 0x10000000, 0x00000003}, + {0x53425249, 0x10000000, 0x00000006}, + {0x53434A42, 0x04000000, 0x00000002}, + {0x53434D43, 0x02000000, 0x00000002}, + {0x53435141, 0x04000000, 0x00000002}, + {0x53435259, 0x08000000, 0x00000002}, + {0x53435943, 0x02000000, 0x00000002}, + {0x53445249, 0x20000000, 0x00000006}, + {0x53445641, 0x01000000, 0x00000002}, + {0x53453231, 0x02000000, 0x00000003}, + {0x53453443, 0x04000000, 0x00000001}, + {0x53454343, 0x01000000, 0x00000005}, + {0x53454542, 0x10000000, 0x00000003}, + {0x53454559, 0x10000000, 0x00000003}, + {0x53454959, 0x02000000, 0x00000002}, + {0x53454C43, 0x04000000, 0x00000001}, + {0x53455249, 0x20000000, 0x00000006}, + {0x53464959, 0x02000000, 0x00000002}, + {0x53464B59, 0x02000000, 0x00000001}, + {0x53464C42, 0x10000000, 0x00000003}, + {0x53465359, 0x04000000, 0x00000001}, + {0x53474D41, 0x01000000, 0x00000001}, + {0x53474D43, 0x04000000, 0x00000001}, + {0x53475049, 0x08000000, 0x00000006}, + {0x534A3343, 0x10000000, 0x00000003}, + {0x534A5641, 0x04000000, 0x00000002}, + {0x534B4356, 0x08000000, 0x00000002}, + {0x534B5049, 0x08000000, 0x00000006}, + {0x534C4443, 0x02000000, 0x00000004}, + {0x534C4C43, 0x01000000, 0x00000002}, + {0x534D4359, 0x02000000, 0x00000001}, + {0x534F4359, 0x04000000, 0x00000001}, + {0x534F5342, 0x02000000, 0x00000001}, + {0x53504A59, 0x01000000, 0x00000001}, + {0x53505A55, 0x08000000, 0xFFFFFFFF}, + {0x53514142, 0x08000000, 0x00000002}, + {0x53525359, 0x01000000, 0x00000005}, + {0x53533341, 0x02000000, 0x00000001}, + {0x53534F41, 0x08000000, 0x00000005}, + {0x53535541, 0x04000000, 0x00000001}, + {0x53544C59, 0x08000000, 0x00000002}, + {0x53554259, 0x08000000, 0x00000003}, + {0x53555043, 0x08000000, 0x00000006}, + {0x53563543, 0x01000000, 0x00000001}, + {0x53564256, 0x02000000, 0x00000001}, + {0x53564E43, 0x10000000, 0x00000005}, + {0x53565841, 0x04000000, 0x00000003}, + {0x53574143, 0x04000000, 0x00000001}, + {0x53594641, 0x04000000, 0x00000001}, + {0x53594C41, 0x04000000, 0x00000001}, + {0x53595543, 0x02000000, 0x00000001}, + {0x53595A41, 0x04000000, 0x00000002}, + {0x535A4641, 0x04000000, 0x00000001}, + {0x535A5359, 0x08000000, 0x00000001}, + {0x54595056, 0x10000000, 0x00000005}, + {0x55414C59, 0x00800000, 0x00000002}, + {0x55425742, 0x04000000, 0x00000002}, + {0x55434956, 0x04000000, 0x00000002}, + {0x55435243, 0x02000000, 0x00000001}, + {0x55444E41, 0x00800000, 0x00000008}, + {0x55454342, 0x02000000, 0x00000002}, + {0x55463343, 0x02000000, 0x00000002}, + {0x554A5243, 0x02000000, 0x00000001}, + {0x55504A59, 0x01000000, 0x00000001}, + {0x55515243, 0x02000000, 0x00000001}, + {0x55524542, 0x02000000, 0x00000001}, + {0x55525342, 0x01000000, 0x00000001}, + {0x55544256, 0x02000000, 0x00000002}, + {0x55545942, 0x04000000, 0x00000002}, + {0x55573341, 0x04000000, 0x00000002}, + {0x55574C41, 0x02000000, 0x00000001}, + {0x56324356, 0x02000000, 0x00000001}, + {0x56324456, 0x04000000, 0x00000001}, + {0x56324D56, 0x04000000, 0x00000002}, + {0x56335356, 0x08000000, 0x00000005}, + {0x56335456, 0x04000000, 0x00000001}, + {0x56345456, 0x04000000, 0x00000003}, + {0x56364356, 0x02000000, 0x00000002}, + {0x56394856, 0x04000000, 0x00000002}, + {0x56395056, 0x04000000, 0x00000001}, + {0x56413956, 0x02000000, 0x00000000}, + {0x56414156, 0x02000000, 0x00000008}, + {0x56414256, 0x02000000, 0x00000001}, + {0x56414356, 0x04000000, 0x00000001}, + {0x56414C56, 0x04000000, 0x00000002}, + {0x56434156, 0x04000000, 0x00000002}, + {0x56434D56, 0x02000000, 0x00000001}, + {0x56444356, 0x04000000, 0x00000002}, + {0x56444956, 0x02000000, 0x00000002}, + {0x56455056, 0x04000000, 0x00000001}, + {0x56455456, 0x04000000, 0x00000002}, + {0x56464956, 0x02000000, 0x00000002}, + {0x56465056, 0x04000000, 0x00000001}, + {0x56473256, 0x02000000, 0x00000006}, + {0x56475256, 0x02000000, 0x00000002}, + {0x56494C56, 0x02000000, 0x00000001}, + {0x56495256, 0x02000000, 0x00000001}, + {0x564A4956, 0x08000000, 0x00000003}, + {0x564B4356, 0x08000000, 0x00000002}, + {0x564B4D56, 0x02000000, 0x00000003}, + {0x564B5355, 0x08000000, 0xFFFFFFFF}, + {0x564B5356, 0x04000000, 0x00000001}, + {0x564C4156, 0x04000000, 0x00000002}, + {0x564C4256, 0x02000000, 0x00000002}, + {0x564C4556, 0x02000000, 0x00000003}, + {0x564D4356, 0x04000000, 0x00000002}, + {0x564E5356, 0x04000000, 0x00000002}, + {0x564F4156, 0x04000000, 0x00000001}, + {0x564F5356, 0x04000000, 0x00000003}, + {0x56505056, 0x02000000, 0x00000001}, + {0x56505256, 0x02000000, 0x00000001}, + {0x56505456, 0x08000000, 0x00000002}, + {0x56524756, 0x04000000, 0x00000001}, + {0x56534256, 0x02000000, 0x00000001}, + {0x56534556, 0x04000000, 0x00000001}, + {0x56534656, 0x08000000, 0x00000003}, + {0x56534844, 0x02000000, 0xFFFFFFFF}, + {0x56544156, 0x02000000, 0x00000001}, + {0x56554B56, 0x04000000, 0x00000001}, + {0x56555A56, 0x02000000, 0x00000002}, + {0x56564156, 0x04000000, 0x00000001}, + {0x56564256, 0x02000000, 0x00000001}, + {0x56564A56, 0x04000000, 0x00000001}, + {0x56565056, 0x04000000, 0x00000002}, + {0x56565756, 0x04000000, 0x00000001}, + {0x56574356, 0x02000000, 0x00000002}, + {0x56574856, 0x04000000, 0x00000002}, + {0x56574A56, 0x02000000, 0x00000003}, + {0x56594D56, 0x04000000, 0x00000001}, + {0x565A4656, 0x02000000, 0x00000001}, + {0x565A4D56, 0x04000000, 0x00000001}, + {0x57325141, 0x02000000, 0x00000002}, + {0x57334941, 0x01000000, 0x00000002}, + {0x57414356, 0x04000000, 0x00000001}, + {0x57414E43, 0x04000000, 0x00000001}, + {0x57445759, 0x01000000, 0x00000002}, + {0x57474C43, 0x04000000, 0x00000001}, + {0x574C5759, 0x02000000, 0x00000001}, + {0x57565141, 0x01000000, 0x00000002}, + {0x575A5242, 0x04000000, 0x00000003}, + {0x58324354, 0x00800000, 0x00000001}, + {0x58324842, 0x02000000, 0x00000003}, + {0x58324859, 0x02000000, 0x00000003}, + {0x58324B41, 0x04000000, 0x00000001}, + {0x58324D56, 0x04000000, 0x00000002}, + {0x58325141, 0x02000000, 0x00000002}, + {0x58325241, 0x02000000, 0x00000003}, + {0x58325341, 0x01000000, 0x00000001}, + {0x58334242, 0x00000000, 0x00000001}, + {0x58334542, 0x04000000, 0x00000001}, + {0x58334759, 0x02000000, 0x00000003}, + {0x58334841, 0x04000000, 0x00000003}, + {0x58334941, 0x01000000, 0x00000002}, + {0x58334943, 0x04000000, 0x00000001}, + {0x58334C41, 0x02000000, 0x00000001}, + {0x58335456, 0x04000000, 0x00000001}, + {0x58343242, 0x00800000, 0x00000001}, + {0x58344A43, 0x01000000, 0x00000001}, + {0x58345442, 0x01000000, 0x00000008}, + {0x58345741, 0x02000000, 0x00000002}, + {0x58354259, 0x02000000, 0x00000002}, + {0x58354A42, 0x02000000, 0x00000001}, + {0x58354D54, 0x04000000, 0x00000003}, + {0x58355059, 0x10000000, 0x00000001}, + {0x58355142, 0x04000000, 0x00000001}, + {0x58355243, 0x10000000, 0x00000001}, + {0x58355259, 0x02000000, 0x00000002}, + {0x58355343, 0x04000000, 0x00000001}, + {0x58363559, 0x04000000, 0x00000008}, + {0x58364254, 0x02000000, 0x00000001}, + {0x58364341, 0x01000000, 0x00000002}, + {0x58365259, 0x00000000, 0x00000002}, + {0x58374943, 0x04000000, 0x00000002}, + {0x58374A42, 0x00800000, 0x00000001}, + {0x58374C42, 0x04000000, 0x00000001}, + {0x58375042, 0x02000000, 0x00000001}, + {0x58384442, 0x04000000, 0x00000001}, + {0x58384843, 0x02000000, 0x00000001}, + {0x58384D41, 0x01000000, 0x00000001}, + {0x58385741, 0x04000000, 0x00000001}, + {0x58385742, 0x01000000, 0x00000001}, + {0x58385859, 0x08000000, 0x00000001}, + {0x58394259, 0x02000000, 0x00000003}, + {0x58394943, 0x01000000, 0x00000002}, + {0x58394D59, 0x01000000, 0x00000001}, + {0x58395056, 0x04000000, 0x00000001}, + {0x58395141, 0x04000000, 0x00000001}, + {0x58395341, 0x02000000, 0x00000001}, + {0x58395759, 0x08000000, 0x00000001}, + {0x58413541, 0x04000000, 0x00000001}, + {0x58414243, 0x02000000, 0x00000001}, + {0x58414356, 0x04000000, 0x00000001}, + {0x58414643, 0x08000000, 0x00000002}, + {0x58414E43, 0x04000000, 0x00000001}, + {0x58415141, 0x02000000, 0x00000001}, + {0x58415243, 0x00800000, 0x00000001}, + {0x58415359, 0x01000000, 0x00000002}, + {0x58415459, 0x04000000, 0x00000001}, + {0x58415A43, 0x02000000, 0x00000002}, + {0x58423242, 0x08000000, 0x00000002}, + {0x58423542, 0x08000000, 0x00000002}, + {0x58424254, 0x02000000, 0x00000001}, + {0x58424654, 0x01000000, 0x00000001}, + {0x58424743, 0x02000000, 0x00000001}, + {0x58424A43, 0x01000000, 0x00000001}, + {0x58424B43, 0x02000000, 0x00000002}, + {0x58425342, 0x04000000, 0x00000003}, + {0x58425442, 0x04000000, 0x00000002}, + {0x58425742, 0x04000000, 0x00000002}, + {0x58433342, 0x04000000, 0x00000002}, + {0x58433441, 0x02000000, 0x00000003}, + {0x58434341, 0x02000000, 0x00000001}, + {0x58434542, 0x01000000, 0x00000003}, + {0x58434642, 0x02000000, 0x00000001}, + {0x58434741, 0x04000000, 0x00000003}, + {0x58434941, 0x01000000, 0x00000001}, + {0x58435043, 0x01000000, 0x00000002}, + {0x58435143, 0x02000000, 0x00000001}, + {0x58435359, 0x02000000, 0x00000001}, + {0x58435842, 0x01000000, 0x00000001}, + {0x58443743, 0x04000000, 0x00000001}, + {0x58444359, 0x01000000, 0x00000001}, + {0x58444642, 0x00000000, 0x00000001}, + {0x58444842, 0x04000000, 0x00000001}, + {0x58444A54, 0x01000000, 0x00000001}, + {0x58444B42, 0x00800000, 0x00000001}, + {0x58445054, 0x08000000, 0x00000001}, + {0x58445759, 0x01000000, 0x00000002}, + {0x58453242, 0x00800000, 0x00000001}, + {0x58453442, 0x01000000, 0x00000001}, + {0x58454543, 0x00800000, 0x00000001}, + {0x58454C43, 0x04000000, 0x00000001}, + {0x58455056, 0x04000000, 0x00000001}, + {0x58455141, 0x00800000, 0x00000002}, + {0x58455143, 0x04000000, 0x00000002}, + {0x58455456, 0x04000000, 0x00000002}, + {0x58455542, 0x02000000, 0x00000001}, + {0x58463642, 0x08000000, 0x00000001}, + {0x58464143, 0x01000000, 0x00000001}, + {0x58464243, 0x08000000, 0x00000003}, + {0x58464541, 0x00800000, 0x00000001}, + {0x58464A42, 0x08000000, 0x00000003}, + {0x58465956, 0x02000000, 0x00000001}, + {0x58465A42, 0x04000000, 0x00000001}, + {0x58473241, 0x02000000, 0x00000003}, + {0x58474142, 0x01000000, 0x00000001}, + {0x58474143, 0x02000000, 0x00000001}, + {0x58474342, 0x04000000, 0x00000002}, + {0x58474354, 0x04000000, 0x00000001}, + {0x58474542, 0x00800000, 0x00000001}, + {0x58475742, 0x04000000, 0x00000001}, + {0x58475956, 0x04000000, 0x00000001}, + {0x58483343, 0x00800000, 0x00000001}, + {0x58483842, 0x04000000, 0x00000002}, + {0x58484759, 0x08000000, 0x00000001}, + {0x58484A42, 0x01000000, 0x00000001}, + {0x58484C41, 0x02000000, 0x00000001}, + {0x58485243, 0x00000000, 0x00000002}, + {0x58485254, 0x02000000, 0x00000001}, + {0x58485641, 0x04000000, 0x00000002}, + {0x58485A59, 0x04000000, 0x00000001}, + {0x58493642, 0x04000000, 0x00000002}, + {0x58494442, 0x04000000, 0x00000001}, + {0x58494641, 0x02000000, 0x00000002}, + {0x58494942, 0x00800000, 0x00000001}, + {0x58494C43, 0x04000000, 0x00000001}, + {0x58495259, 0x04000000, 0x00000002}, + {0x58495442, 0x01000000, 0x00000001}, + {0x584A4841, 0x01000000, 0x00000002}, + {0x584A4D54, 0x02000000, 0x00000001}, + {0x584A5143, 0x00800000, 0x00000001}, + {0x584B3443, 0x00800000, 0x00000001}, + {0x584B3842, 0x02000000, 0x00000002}, + {0x584B4143, 0x04000000, 0x00000002}, + {0x584B4243, 0x04000000, 0x00000002}, + {0x584B4541, 0x04000000, 0x00000002}, + {0x584B4642, 0x04000000, 0x00000001}, + {0x584B4B41, 0x02000000, 0x00000003}, + {0x584B4C42, 0x04000000, 0x00000001}, + {0x584B5356, 0x04000000, 0x00000001}, + {0x584B5559, 0x04000000, 0x00000001}, + {0x584C4643, 0x02000000, 0x00000002}, + {0x584C4A59, 0x01000000, 0x00000002}, + {0x584C4E59, 0x04000000, 0x00000001}, + {0x584C5059, 0x00800000, 0x00000001}, + {0x584C5242, 0x02000000, 0x00000001}, + {0x584C5342, 0x02000000, 0x00000003}, + {0x584C5543, 0x04000000, 0x00000001}, + {0x584C5759, 0x02000000, 0x00000001}, + {0x584C5941, 0x02000000, 0x00000002}, + {0x584C5959, 0x04000000, 0x00000002}, + {0x584D3243, 0x02000000, 0x00000002}, + {0x584D3442, 0x02000000, 0x00000001}, + {0x584D4359, 0x02000000, 0x00000001}, + {0x584D4842, 0x02000000, 0x00000001}, + {0x584D4A54, 0x00800000, 0x00000001}, + {0x584D4C42, 0x01000000, 0x00000001}, + {0x584D4E42, 0x04000000, 0x00000001}, + {0x584D5642, 0x02000000, 0x00000001}, + {0x584D5842, 0x04000000, 0x00000002}, + {0x584E3743, 0x04000000, 0x00000001}, + {0x584E4354, 0x01000000, 0x00000001}, + {0x584E4559, 0x00800000, 0x00000001}, + {0x584E4641, 0x02000000, 0x00000002}, + {0x584E5159, 0x04000000, 0x00000002}, + {0x584F3543, 0x01000000, 0x00000001}, + {0x584F3642, 0x02000000, 0x00000001}, + {0x584F3743, 0x04000000, 0x00000002}, + {0x584F4142, 0x04000000, 0x00000001}, + {0x584F4156, 0x04000000, 0x00000001}, + {0x584F4442, 0x01000000, 0x00000001}, + {0x584F4D59, 0x04000000, 0x00000001}, + {0x584F5542, 0x02000000, 0x00000001}, + {0x584F5741, 0x02000000, 0x00000002}, + {0x584F5841, 0x01000000, 0x00000002}, + {0x584F5843, 0x04000000, 0x00000001}, + {0x58503541, 0x04000000, 0x00000001}, + {0x58504259, 0x02000000, 0x00000001}, + {0x58504342, 0x04000000, 0x00000002}, + {0x58504442, 0x02000000, 0x00000001}, + {0x58504B59, 0x01000000, 0x00000001}, + {0x58504F43, 0x01000000, 0x00000003}, + {0x58505343, 0x02000000, 0x00000003}, + {0x58513543, 0x01000000, 0x00000002}, + {0x58513643, 0x08000000, 0x00000001}, + {0x58514559, 0x01000000, 0x00000001}, + {0x58514A59, 0x01000000, 0x00000001}, + {0x58514C42, 0x02000000, 0x00000001}, + {0x58514D43, 0x02000000, 0x00000001}, + {0x58514D59, 0x02000000, 0x00000001}, + {0x58515459, 0x01000000, 0x00000001}, + {0x58523559, 0x04000000, 0x00000008}, + {0x58523743, 0x00800000, 0x00000001}, + {0x58524354, 0x00800000, 0x00000001}, + {0x58524459, 0x01000000, 0x00000001}, + {0x58524842, 0x02000000, 0x00000001}, + {0x58524943, 0x04000000, 0x00000002}, + {0x58524A42, 0x01000000, 0x00000001}, + {0x58524C54, 0x08000000, 0x00000001}, + {0x58524D42, 0x02000000, 0x00000001}, + {0x58525042, 0x00800000, 0x00000001}, + {0x58525141, 0x01000000, 0x00000002}, + {0x58525642, 0x04000000, 0x00000001}, + {0x58525843, 0x04000000, 0x00000001}, + {0x58533841, 0x00800000, 0x00000002}, + {0x58534342, 0x04000000, 0x00000002}, + {0x58534556, 0x04000000, 0x00000001}, + {0x58534642, 0x04000000, 0x00000001}, + {0x58534643, 0x02000000, 0x00000001}, + {0x58534743, 0x08000000, 0x00000001}, + {0x58534A54, 0x00800000, 0x00000001}, + {0x58534E43, 0x04000000, 0x00000002}, + {0x58535143, 0x02000000, 0x00000001}, + {0x58543341, 0x02000000, 0x00000002}, + {0x58543642, 0x04000000, 0x00000001}, + {0x58543743, 0x01000000, 0x00000002}, + {0x58544256, 0x02000000, 0x00000002}, + {0x58544D59, 0x02000000, 0x00000002}, + {0x58545054, 0x08000000, 0x00000001}, + {0x58545259, 0x02000000, 0x00000002}, + {0x58545A41, 0x01000000, 0x00000005}, + {0x58554159, 0x04000000, 0x00000003}, + {0x58554242, 0x04000000, 0x00000003}, + {0x58554341, 0x08000000, 0x00000005}, + {0x58554454, 0x01000000, 0x00000001}, + {0x58554643, 0x00000000, 0x00000002}, + {0x58554E42, 0x01000000, 0x00000001}, + {0x58555442, 0x04000000, 0x00000002}, + {0x58555841, 0x02000000, 0x00000001}, + {0x58564142, 0x04000000, 0x00000001}, + {0x58564159, 0x04000000, 0x00000002}, + {0x58564343, 0x01000000, 0x00000001}, + {0x58564854, 0x04000000, 0x00000001}, + {0x58564B42, 0x00800000, 0x00000001}, + {0x58564D42, 0x00800000, 0x00000001}, + {0x58565141, 0x01000000, 0x00000002}, + {0x58573241, 0x04000000, 0x00000001}, + {0x58573341, 0x04000000, 0x00000002}, + {0x58573742, 0x01000000, 0x00000002}, + {0x58574443, 0x01000000, 0x00000001}, + {0x58574859, 0x02000000, 0x00000001}, + {0x58574942, 0x04000000, 0x00000002}, + {0x58574C41, 0x02000000, 0x00000001}, + {0x58574D42, 0x04000000, 0x00000002}, + {0x58575141, 0x02000000, 0x00000001}, + {0x58575343, 0x04000000, 0x00000001}, + {0x58575942, 0x00800000, 0x00000001}, + {0x58584254, 0x04000000, 0x00000002}, + {0x58584C41, 0x02000000, 0x00000001}, + {0x58584D59, 0x00800000, 0x00000001}, + {0x58585043, 0x01000000, 0x00000005}, + {0x58594159, 0x02000000, 0x00000001}, + {0x58594259, 0x02000000, 0x00000001}, + {0x58594443, 0x02000000, 0x00000002}, + {0x58594741, 0x04000000, 0x00000003}, + {0x58594842, 0x02000000, 0x00000001}, + {0x58594943, 0x04000000, 0x00000002}, + {0x58594A42, 0x04000000, 0x00000001}, + {0x58594E42, 0x04000000, 0x00000001}, + {0x58595543, 0x02000000, 0x00000001}, + {0x585A3242, 0x00800000, 0x00000001}, + {0x585A3742, 0x04000000, 0x00000001}, + {0x585A4341, 0x01000000, 0x00000001}, + {0x585A4A59, 0x04000000, 0x00000005}, + {0x585A4C59, 0x10000000, 0x00000002}, + {0x585A4D56, 0x04000000, 0x00000001}, + {0x585A5059, 0x01000000, 0x00000001}, + {0x585A5242, 0x04000000, 0x00000003}, + {0x585A5243, 0x00800000, 0x00000002}, + {0x585A5442, 0x04000000, 0x00000001}, + {0x59325141, 0x02000000, 0x00000002}, + {0x59334242, 0x08000000, 0x00000001}, + {0x59334759, 0x02000000, 0x00000003}, + {0x59334941, 0x01000000, 0x00000002}, + {0x59334943, 0x04000000, 0x00000001}, + {0x59334C41, 0x02000000, 0x00000001}, + {0x59345741, 0x02000000, 0x00000002}, + {0x59354A42, 0x02000000, 0x00000001}, + {0x59355142, 0x08000000, 0x00000001}, + {0x59364341, 0x01000000, 0x00000002}, + {0x59374943, 0x00000000, 0x00000002}, + {0x59394259, 0x02000000, 0x00000003}, + {0x59395056, 0x04000000, 0x00000001}, + {0x59414356, 0x04000000, 0x00000001}, + {0x59414643, 0x08000000, 0x00000002}, + {0x59414E43, 0x04000000, 0x00000001}, + {0x59415359, 0x01000000, 0x00000002}, + {0x59415459, 0x04000000, 0x00000001}, + {0x59425442, 0x04000000, 0x00000002}, + {0x59425742, 0x04000000, 0x00000002}, + {0x59434741, 0x04000000, 0x00000003}, + {0x59443442, 0x01000000, 0x00000001}, + {0x59444642, 0x00800000, 0x00000001}, + {0x59445054, 0x08000000, 0x00000001}, + {0x59453442, 0x01000000, 0x00000001}, + {0x59454259, 0x08000000, 0x00000003}, + {0x59454543, 0x00800000, 0x00000001}, + {0x59454C43, 0x04000000, 0x00000001}, + {0x59455056, 0x04000000, 0x00000001}, + {0x59455143, 0x04000000, 0x00000002}, + {0x59455542, 0x02000000, 0x00000001}, + {0x59463642, 0x08000000, 0x00000001}, + {0x59465042, 0x04000000, 0x00000002}, + {0x59474354, 0x04000000, 0x00000001}, + {0x59474C43, 0x04000000, 0x00000001}, + {0x59484A42, 0x01000000, 0x00000001}, + {0x59484C41, 0x02000000, 0x00000001}, + {0x59495443, 0x02000000, 0x00000002}, + {0x594A4841, 0x01000000, 0x00000002}, + {0x594A4D54, 0x02000000, 0x00000001}, + {0x594B5356, 0x04000000, 0x00000001}, + {0x594C4A59, 0x01000000, 0x00000002}, + {0x594C4E59, 0x04000000, 0x00000001}, + {0x594C5759, 0x02000000, 0x00000001}, + {0x594E4641, 0x02000000, 0x00000002}, + {0x594E4654, 0x04000000, 0x00000002}, + {0x594E5159, 0x04000000, 0x00000002}, + {0x594F5841, 0x01000000, 0x00000002}, + {0x59504442, 0x02000000, 0x00000001}, + {0x59513642, 0x00800000, 0x00000001}, + {0x59514559, 0x01000000, 0x00000001}, + {0x59514D59, 0x02000000, 0x00000001}, + {0x59524254, 0x04000000, 0x00000001}, + {0x59524459, 0x01000000, 0x00000001}, + {0x59524842, 0x02000000, 0x00000001}, + {0x59524C54, 0x08000000, 0x00000001}, + {0x59533841, 0x00800000, 0x00000002}, + {0x59545054, 0x08000000, 0x00000001}, + {0x59545259, 0x02000000, 0x00000002}, + {0x59545A41, 0x01000000, 0x00000005}, + {0x59554242, 0x04000000, 0x00000003}, + {0x59554341, 0x08000000, 0x00000005}, + {0x59554B56, 0x04000000, 0x00000001}, + {0x59554D42, 0x04000000, 0x00000001}, + {0x59555154, 0x00800000, 0x00000001}, + {0x59555442, 0x04000000, 0x00000002}, + {0x59564854, 0x04000000, 0x00000001}, + {0x59565141, 0x01000000, 0x00000002}, + {0x59573241, 0x04000000, 0x00000001}, + {0x59574443, 0x01000000, 0x00000001}, + {0x59574C41, 0x02000000, 0x00000001}, + {0x59574D42, 0x04000000, 0x00000002}, + {0x59594159, 0x02000000, 0x00000001}, + {0x59594254, 0x04000000, 0x00000002}, + {0x59594442, 0x08000000, 0x00000002}, + {0x59594E42, 0x04000000, 0x00000001}, + {0x595A4341, 0x01000000, 0x00000001}, + {0x595A4A59, 0x04000000, 0x00000005}, + {0x595A5059, 0x01000000, 0x00000001}, + {0x595A5242, 0x04000000, 0x00000003}, + {0x595A5442, 0x04000000, 0x00000001}, + {0x595A5443, 0x02000000, 0x00000003}, + {0x5A325141, 0x02000000, 0x00000002}, + {0x5A334941, 0x01000000, 0x00000002}, + {0x5A335456, 0x04000000, 0x00000001}, + {0x5A345741, 0x02000000, 0x00000002}, + {0x5A353859, 0x00800000, 0x00000008}, + {0x5A374943, 0x04000000, 0x00000002}, + {0x5A414356, 0x04000000, 0x00000001}, + {0x5A424259, 0x02000000, 0x00000001}, + {0x5A445759, 0x01000000, 0x00000002}, + {0x5A454259, 0x08000000, 0x00000003}, + {0x5A475956, 0x04000000, 0x00000001}, + {0x5A4A3642, 0x00800000, 0x00000001}, + {0x5A4A3959, 0x00800000, 0x00000008}, + {0x5A4C4E59, 0x04000000, 0x00000001}, + {0x5A4C5759, 0x02000000, 0x00000001}, + {0x5A4C5959, 0x04000000, 0x00000002}, + {0x5A4D4842, 0x02000000, 0x00000001}, + {0x5A4F3959, 0x00800000, 0x00000000}, + {0x5A513642, 0x00800000, 0x00000001}, + {0x5A523642, 0x08000000, 0x00000002}, + {0x5A544D59, 0x02000000, 0x00000002}, + {0x5A545054, 0x08000000, 0x00000001}, + {0x5A554242, 0x04000000, 0x00000003}, + {0x5A565141, 0x01000000, 0x00000002}, + {0x5A574C41, 0x02000000, 0x00000001}, + {0x5A595543, 0x02000000, 0x00000001}, + {0x5A5A4254, 0x04000000, 0x00000002}, + {0x5A5A4341, 0x01000000, 0x00000001}, + {0x5A5A5242, 0x04000000, 0x00000003}, +}; + +#endif // ROMLIST_H diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 8df6ec8..a3207c7 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -1900,39 +1900,6 @@ int main(int argc, char** argv) SANITIZE(Config::ScreenSizing, 0, 3); #undef SANITIZE - // TODO: this should be checked before running anything -#if 0 - { - const char* romlist_missing = "Save memory type detection will not work correctly.\n\n" - "You should use the latest version of romlist.bin (provided in melonDS release packages)."; -#if !defined(UNIX_PORTABLE) && !defined(__WIN32__) - std::string missingstr = std::string(romlist_missing) + - "\n\nThe ROM list should be placed in " + g_get_user_data_dir() + "/melonds/, otherwise " - "melonDS will search for it in the current working directory."; - const char* romlist_missing_text = missingstr.c_str(); -#else - const char* romlist_missing_text = romlist_missing; -#endif - - FILE* f = Platform::OpenDataFile("romlist.bin"); - if (f) - { - u32 data; - fread(&data, 4, 1, f); - fclose(f); - - if ((data >> 24) == 0) // old CRC-based list - { - uiMsgBoxError(NULL, "Your version of romlist.bin is outdated.", romlist_missing_text); - } - } - else - { - uiMsgBoxError(NULL, "romlist.bin not found.", romlist_missing_text); - } - } -#endif - QSurfaceFormat format; format.setDepthBufferSize(24); format.setStencilBufferSize(8); -- cgit v1.2.3 From b27ed541bb992d2e296ab3e9884e9cd2e67f45cc Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 30 May 2020 00:38:31 +0200 Subject: blarg --- src/frontend/qt_sdl/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index 37a8ff1..62d6e60 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -110,5 +110,4 @@ install(FILES ../../../icon/melon_48x48.png DESTINATION ${CMAKE_INSTALL_PREFIX}/ install(FILES ../../../icon/melon_64x64.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/64x64/apps RENAME net.kuribo64.melonDS.png) install(FILES ../../../icon/melon_128x128.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/128x128/apps RENAME net.kuribo64.melonDS.png) install(FILES ../../../icon/melon_256x256.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/256x256/apps RENAME net.kuribo64.melonDS.png) -install(FILES ../../../romlist.bin DESTINATION ${CMAKE_INSTALL_PREFIX}/share/melonDS) install(TARGETS melonDS RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) -- cgit v1.2.3 From 82302c9bf48598f889d0942340c224852c1378c5 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 30 May 2020 03:15:05 +0200 Subject: fix shito. --- src/NDSCart.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index 6a25bcb..06c3bde 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -875,10 +875,10 @@ void DecryptSecureArea(u8* out) memcpy(out, &CartROM[arm9base], 0x800); - Key1_InitKeycode(gamecode, 2, 2); + Key1_InitKeycode(false, gamecode, 2, 2); Key1_Decrypt((u32*)&out[0]); - Key1_InitKeycode(gamecode, 3, 2); + Key1_InitKeycode(false, gamecode, 3, 2); for (u32 i = 0; i < 0x800; i += 8) Key1_Decrypt((u32*)&out[i]); @@ -1018,7 +1018,7 @@ bool LoadROM(const char* path, const char* sram, bool direct) ROMCommandHandler = ROMCommand_Retail; // encryption - Key1_InitKeycode(gamecode, 2, 2); + Key1_InitKeycode(false, gamecode, 2, 2); // save printf("Save file: %s\n", sram); -- cgit v1.2.3 From 8a15adb38bf5c141e41b1a5f9984ee363d64786f Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 30 May 2020 03:26:06 +0200 Subject: modern melonDSi HARK HARK HARK --- src/frontend/Util_ROM.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/frontend/Util_ROM.cpp b/src/frontend/Util_ROM.cpp index 3f64b9d..d410550 100644 --- a/src/frontend/Util_ROM.cpp +++ b/src/frontend/Util_ROM.cpp @@ -110,6 +110,7 @@ int VerifyDSFirmware() { // 128KB firmware, not bootable fclose(f); + return Load_OK; // FIXME!!!! return Load_FirmwareNotBootable; } else if (len != 0x40000 && len != 0x80000) -- cgit v1.2.3 From 8f5dff17251b759651d967fe072cf4f56b9edb35 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 30 May 2020 13:52:51 +0200 Subject: make soft-reset work somewhat better --- src/DSi.cpp | 29 +++++++++++++++++++++++++++++ src/DSi_I2C.cpp | 19 +++++++++++-------- 2 files changed, 40 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index 15f06a2..fb4b37a 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -173,12 +173,41 @@ void SoftReset() NDS::ARM9->Reset(); NDS::ARM7->Reset(); + memcpy(NDS::ARM9->ITCM, ITCMInit, 0x8000); + + for (u32 i = 0; i < 0x3C00; i+=4) + ARM7Write32(0x03FFC400+i, *(u32*)&ARM7Init[i]); + DSi_AES::Reset(); LoadNAND(); NDS::ARM9->JumpTo(BootAddr[0]); NDS::ARM7->JumpTo(BootAddr[1]); + + SCFG_BIOS = 0x0101; // TODO: should be zero when booting from BIOS + SCFG_Clock9 = 0x0187; // CHECKME + SCFG_Clock7 = 0x0187; + SCFG_EXT[0] = 0x8307F100; + SCFG_EXT[1] = 0x93FFFB06; + SCFG_MC = 0x0010;//0x0011; + + // LCD init flag + GPU::DispStat[0] |= (1<<6); + GPU::DispStat[1] |= (1<<6); + + NDS::MapSharedWRAM(3); + + u32 eaddr = 0x03FFE6E4; + ARM7Write32(eaddr+0x00, *(u32*)&eMMC_CID[0]); + ARM7Write32(eaddr+0x04, *(u32*)&eMMC_CID[4]); + ARM7Write32(eaddr+0x08, *(u32*)&eMMC_CID[8]); + ARM7Write32(eaddr+0x0C, *(u32*)&eMMC_CID[12]); + ARM7Write16(eaddr+0x2C, 0x0001); + ARM7Write16(eaddr+0x2E, 0x0001); + ARM7Write16(eaddr+0x3C, 0x0100); + ARM7Write16(eaddr+0x3E, 0x40E0); + ARM7Write16(eaddr+0x42, 0x0001); } bool LoadBIOS() diff --git a/src/DSi_I2C.cpp b/src/DSi_I2C.cpp index 0ab7008..b2ca6e4 100644 --- a/src/DSi_I2C.cpp +++ b/src/DSi_I2C.cpp @@ -84,7 +84,7 @@ u8 Read(bool last) return 0; } - //printf("BPTWL: read %02X -> %02X\n", CurPos, Registers[CurPos]); + printf("BPTWL: read %02X -> %02X\n", CurPos, Registers[CurPos]); return Registers[CurPos++]; } @@ -107,7 +107,10 @@ void Write(u8 val, bool last) { printf("BPTWL: soft-reset\n"); val = 0; // checkme + // TODO: soft-reset might need to be scheduled later! DSi::SoftReset(); + CurPos = -1; + return; } if (CurPos == 0x11 || CurPos == 0x12 || @@ -121,7 +124,7 @@ void Write(u8 val, bool last) Registers[CurPos] = val; } - //printf("BPTWL: write %02X -> %02X\n", CurPos, val); + printf("BPTWL: write %02X -> %02X\n", CurPos, val); CurPos++; // CHECKME } @@ -163,7 +166,7 @@ void Reset() void WriteCnt(u8 val) { - //printf("I2C: write CNT %02X, %08X\n", val, NDS::GetPC(1)); + printf("I2C: write CNT %02X, %08X\n", val, NDS::GetPC(1)); // TODO: check ACK flag // TODO: transfer delay @@ -190,7 +193,7 @@ void WriteCnt(u8 val) break; } - //printf("I2C read, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); + printf("I2C read, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); } else { @@ -201,7 +204,7 @@ void WriteCnt(u8 val) if (val & (1<<1)) { Device = Data & 0xFE; - //printf("I2C: %s start, device=%02X\n", (Data&0x01)?"read":"write", Device); + printf("I2C: %s start, device=%02X\n", (Data&0x01)?"read":"write", Device); switch (Device) { @@ -216,7 +219,7 @@ void WriteCnt(u8 val) } else { - //printf("I2C write, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); + printf("I2C write, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); switch (Device) { @@ -240,12 +243,12 @@ void WriteCnt(u8 val) } u8 ReadData() -{ +{printf("I2C: read data: %02X\n", Data); return Data; } void WriteData(u8 val) -{ +{printf("I2C: write data: %02X\n", val); Data = val; } -- cgit v1.2.3 From 77f4663f49caffbfb948ab14e42b6f8ade11d58d Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 1 Jun 2020 16:24:59 +0200 Subject: betterer SD/MMC code. Flipnote can save shit! --- src/DSi_AES.cpp | 12 +- src/DSi_I2C.cpp | 16 +-- src/DSi_NWifi.cpp | 10 +- src/DSi_SD.cpp | 398 +++++++++++++++++++++++++++++------------------------- src/DSi_SD.h | 18 ++- 5 files changed, 253 insertions(+), 201 deletions(-) (limited to 'src') diff --git a/src/DSi_AES.cpp b/src/DSi_AES.cpp index 7aae8f3..4cb1169 100644 --- a/src/DSi_AES.cpp +++ b/src/DSi_AES.cpp @@ -213,12 +213,12 @@ u32 ReadCnt() ret |= InputFIFO->Level(); ret |= (OutputFIFO->Level() << 5); -//printf("READ AES CNT: %08X, LEVELS: IN=%d OUT=%d\n", ret, InputFIFO->Level(), OutputFIFO->Level()); + return ret; } void WriteCnt(u32 val) -{printf("AES CNT = %08X\n", val); +{ u32 oldcnt = Cnt; Cnt = val & 0xFC1FF000; @@ -294,12 +294,12 @@ void WriteCnt(u32 val) } } - printf("AES CNT: %08X / mode=%d key=%d inDMA=%d outDMA=%d blocks=%d\n", - val, AESMode, (val >> 26) & 0x3, InputDMASize, OutputDMASize, RemBlocks); + //printf("AES CNT: %08X / mode=%d key=%d inDMA=%d outDMA=%d blocks=%d\n", + // val, AESMode, (val >> 26) & 0x3, InputDMASize, OutputDMASize, RemBlocks); } void WriteBlkCnt(u32 val) -{printf("AES BLOCK CNT %08X / %d\n", val, val>>16); +{ BlkCnt = val; } @@ -405,7 +405,7 @@ void Update() // CHECKME Cnt &= ~(1<<21); } -printf("AES: FINISHED\n"); + Cnt &= ~(1<<31); if (Cnt & (1<<30)) NDS::SetIRQ2(NDS::IRQ2_DSi_AES); DSi::StopNDMAs(1, 0x2A); diff --git a/src/DSi_I2C.cpp b/src/DSi_I2C.cpp index b2ca6e4..9984f5e 100644 --- a/src/DSi_I2C.cpp +++ b/src/DSi_I2C.cpp @@ -84,7 +84,7 @@ u8 Read(bool last) return 0; } - printf("BPTWL: read %02X -> %02X\n", CurPos, Registers[CurPos]); + //printf("BPTWL: read %02X -> %02X\n", CurPos, Registers[CurPos]); return Registers[CurPos++]; } @@ -124,7 +124,7 @@ void Write(u8 val, bool last) Registers[CurPos] = val; } - printf("BPTWL: write %02X -> %02X\n", CurPos, val); + //printf("BPTWL: write %02X -> %02X\n", CurPos, val); CurPos++; // CHECKME } @@ -166,7 +166,7 @@ void Reset() void WriteCnt(u8 val) { - printf("I2C: write CNT %02X, %08X\n", val, NDS::GetPC(1)); + //printf("I2C: write CNT %02X, %08X\n", val, NDS::GetPC(1)); // TODO: check ACK flag // TODO: transfer delay @@ -193,7 +193,7 @@ void WriteCnt(u8 val) break; } - printf("I2C read, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); + //printf("I2C read, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); } else { @@ -204,7 +204,7 @@ void WriteCnt(u8 val) if (val & (1<<1)) { Device = Data & 0xFE; - printf("I2C: %s start, device=%02X\n", (Data&0x01)?"read":"write", Device); + //printf("I2C: %s start, device=%02X\n", (Data&0x01)?"read":"write", Device); switch (Device) { @@ -219,7 +219,7 @@ void WriteCnt(u8 val) } else { - printf("I2C write, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); + //printf("I2C write, device=%02X, cnt=%02X, data=%02X, last=%d\n", Device, val, Data, islast); switch (Device) { @@ -243,12 +243,12 @@ void WriteCnt(u8 val) } u8 ReadData() -{printf("I2C: read data: %02X\n", Data); +{ return Data; } void WriteData(u8 val) -{printf("I2C: write data: %02X\n", val); +{ Data = val; } diff --git a/src/DSi_NWifi.cpp b/src/DSi_NWifi.cpp index 013173f..79bc632 100644 --- a/src/DSi_NWifi.cpp +++ b/src/DSi_NWifi.cpp @@ -515,6 +515,12 @@ void DSi_NWifi::SendCMD(u8 cmd, u32 param) { switch (cmd) { + case 12: + // stop command + // CHECKME: does the SDIO controller actually send those?? + // DSi firmware sets it to send them + return; + case 52: // IO_RW_DIRECT { u32 func = (param >> 28) & 0x7; @@ -608,7 +614,7 @@ void DSi_NWifi::ReadBlock() TransferAddr &= 0x1FFFF; // checkme } } - len = Host->SendData(data, len); + len = Host->DataRX(data, len); if (RemSize > 0) { @@ -628,7 +634,7 @@ void DSi_NWifi::WriteBlock() len = Host->GetTransferrableLen(len); u8 data[0x200]; - if (len = Host->ReceiveData(data, len)) + if (len = Host->DataTX(data, len)) { for (u32 i = 0; i < len; i++) { diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index a45a8ce..5231b99 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -24,7 +24,27 @@ #include "Platform.h" -#define SD_DESC (Num?"SDIO":"SD/MMC") +// observed IRQ behavior during transfers +// +// during reads: +// * bit23 is cleared during the first block, always set otherwise. weird +// * bit24 (RXRDY) gets set when the FIFO is full +// +// during reads with FIFO32: +// * FIFO16 drains directly into FIFO32 +// * when bit24 is set, FIFO32 is already full (with contents from the other FIFO) +// * reading from an empty FIFO just wraps around (and sets bit21) +// * FIFO32 starts filling when bit24 would be set? +// +// +// TX: +// * when sending command, if current FIFO full +// * upon ContinueTransfer(), if current FIFO full +// * -> upon DataTX() if current FIFO full +// * when filling FIFO + + +#define SD_DESC Num?"SDIO":"SD/MMC" DSi_SDHost::DSi_SDHost(u32 num) @@ -33,6 +53,7 @@ DSi_SDHost::DSi_SDHost(u32 num) DataFIFO[0] = new FIFO(0x100); DataFIFO[1] = new FIFO(0x100); + DataFIFO32 = new FIFO(0x80); Ports[0] = NULL; Ports[1] = NULL; @@ -42,6 +63,7 @@ DSi_SDHost::~DSi_SDHost() { delete DataFIFO[0]; delete DataFIFO[1]; + delete DataFIFO32; if (Ports[0]) delete Ports[0]; if (Ports[1]) delete Ports[1]; @@ -69,6 +91,7 @@ void DSi_SDHost::Reset() DataFIFO[0]->Clear(); DataFIFO[1]->Clear(); CurFIFO = 0; + DataFIFO32->Clear(); IRQStatus = 0; IRQMask = 0x8B7F031D; @@ -84,6 +107,8 @@ void DSi_SDHost::Reset() BlockLen16 = 0; BlockLen32 = 0; StopAction = 0; + TXReq = false; + if (Ports[0]) delete Ports[0]; if (Ports[1]) delete Ports[1]; Ports[0] = NULL; @@ -125,8 +150,8 @@ void DSi_SDHost::UpdateData32IRQ() oldflags &= (Data32IRQ >> 11); Data32IRQ &= ~0x0300; - if (IRQStatus & (1<<24)) Data32IRQ |= (1<<8); - if (!(IRQStatus & (1<<25))) Data32IRQ |= (1<<9); + if (DataFIFO32->Level() >= (BlockLen32>>2)) Data32IRQ |= (1<<8); + if (!DataFIFO32->IsEmpty()) Data32IRQ |= (1<<9); u32 newflags = ((Data32IRQ >> 8) & 0x1) | (((~Data32IRQ) >> 8) & 0x2); newflags &= (Data32IRQ >> 11); @@ -138,8 +163,6 @@ void DSi_SDHost::UpdateData32IRQ() void DSi_SDHost::ClearIRQ(u32 irq) { IRQStatus &= ~(1<CurFIFO ^= 1; + host->CheckSwapFIFO(); - host->ClearIRQ(25); - host->SetIRQ(24); - //if (param & 0x2) host->SetIRQ(2); - - // TODO: this is an assumption and should eventually be confirmed - // Flipnote sets DMA blocklen to 128 words and totallen to 1024 words - // so, presumably, DMA should trigger when the FIFO is full - // 'full' being when it reaches whatever BlockLen16 is set to, or the - // other blocklen register, or when it is actually full (but that makes - // less sense) - DSi::CheckNDMAs(1, host->Num ? 0x29 : 0x28); + if (host->DataMode == 1) + host->UpdateFIFO32(); + else + host->SetIRQ(24); } -u32 DSi_SDHost::SendData(u8* data, u32 len) +u32 DSi_SDHost::DataRX(u8* data, u32 len) { - //printf("%s: data RX, len=%d, blkcnt=%d (%d) blklen=%d, irq=%08X\n", SD_DESC, len, BlockCount16, BlockCountInternal, BlockLen16, IRQMask); if (len != BlockLen16) { printf("!! BAD BLOCKLEN\n"); len = BlockLen16; } bool last = (BlockCountInternal == 0); @@ -232,52 +245,112 @@ u32 DSi_SDHost::SendData(u8* data, u32 len) // send-command function starts polling IRQ status u32 param = Num | (last << 1); NDS::ScheduleEvent(Num ? NDS::Event_DSi_SDIOTransfer : NDS::Event_DSi_SDMMCTransfer, - false, 512, FinishSend, param); + false, 512, FinishRX, param); return len; } -void DSi_SDHost::FinishReceive(u32 param) +void DSi_SDHost::FinishTX(u32 param) { DSi_SDHost* host = (param & 0x1) ? DSi::SDIO : DSi::SDMMC; DSi_SDDevice* dev = host->Ports[host->PortSelect & 0x1]; - host->ClearIRQ(24); - host->SetIRQ(25); + if (host->BlockCountInternal == 0) + { + if (host->StopAction & (1<<8)) + { + if (dev) dev->SendCMD(12, 0); + } - if (dev) dev->ContinueTransfer(); + // CHECKME: presumably IRQ2 should not trigger here, but rather + // when the data transfer is done + //SetIRQ(0); + host->SetIRQ(2); + host->TXReq = false; + } + else + { + if (dev) dev->ContinueTransfer(); + } } -u32 DSi_SDHost::ReceiveData(u8* data, u32 len) +u32 DSi_SDHost::DataTX(u8* data, u32 len) { - printf("%s: data TX, len=%d, blkcnt=%d (%d) blklen=%d, irq=%08X\n", SD_DESC, len, BlockCount16, BlockCountInternal, BlockLen16, IRQMask); - if (len != BlockLen16) { printf("!! BAD BLOCKLEN\n"); len = BlockLen16; } + TXReq = true; u32 f = CurFIFO; - if ((DataFIFO[f]->Level() << 1) < len) + + if (DataMode == 1) { - printf("%s: FIFO not full enough for a transfer (%d / %d)\n", SD_DESC, DataFIFO[f]->Level()<<1, len); - return 0; + if ((DataFIFO32->Level() << 2) < len) + { + if (DataFIFO32->IsEmpty()) + { + SetIRQ(25); + DSi::CheckNDMAs(1, Num ? 0x29 : 0x28); + } + return 0; + } + + // drain FIFO32 into FIFO16 + + if (!DataFIFO[f]->IsEmpty()) printf("VERY BAD!! TRYING TO DRAIN FIFO32 INTO FIFO16 BUT IT CONTAINS SHIT ALREADY\n"); + for (;;) + { + u32 f = CurFIFO; + if ((DataFIFO[f]->Level() << 1) >= BlockLen16) break; + if (DataFIFO32->IsEmpty()) break; + + u32 val = DataFIFO32->Read(); + DataFIFO[f]->Write(val & 0xFFFF); + DataFIFO[f]->Write(val >> 16); + } + + UpdateData32IRQ(); + + if (BlockCount32 > 1) + BlockCount32--; + } + else + { + if ((DataFIFO[f]->Level() << 1) < len) + { + if (DataFIFO[f]->IsEmpty()) SetIRQ(25); + return 0; + } } - DSi_SDDevice* dev = Ports[PortSelect & 0x1]; for (u32 i = 0; i < len; i += 2) *(u16*)&data[i] = DataFIFO[f]->Read(); CurFIFO ^= 1; + BlockCountInternal--; + + NDS::ScheduleEvent(Num ? NDS::Event_DSi_SDIOTransfer : NDS::Event_DSi_SDMMCTransfer, + false, 512, FinishTX, Num); + + return len; +} + +u32 DSi_SDHost::GetTransferrableLen(u32 len) +{ + if (len > BlockLen16) len = BlockLen16; // checkme + return len; +} + +void DSi_SDHost::CheckRX() +{ + DSi_SDDevice* dev = Ports[PortSelect & 0x1]; + + CheckSwapFIFO(); if (BlockCountInternal <= 1) { - printf("%s: data TX complete", SD_DESC); - if (StopAction & (1<<8)) { - printf(", sending CMD12"); if (dev) dev->SendCMD(12, 0); } - printf("\n"); - // CHECKME: presumably IRQ2 should not trigger here, but rather // when the data transfer is done //SetIRQ(0); @@ -286,22 +359,34 @@ u32 DSi_SDHost::ReceiveData(u8* data, u32 len) else { BlockCountInternal--; - } - return len; + if (dev) dev->ContinueTransfer(); + } } -u32 DSi_SDHost::GetTransferrableLen(u32 len) +void DSi_SDHost::CheckTX() { - if (len > BlockLen16) len = BlockLen16; // checkme - return len; + if (!TXReq) return; + + if (DataMode == 1) + { + if ((DataFIFO32->Level() << 2) < BlockLen32) + return; + } + else + { + u32 f = CurFIFO; + if ((DataFIFO[f]->Level() << 1) < BlockLen16) + return; + } + + DSi_SDDevice* dev = Ports[PortSelect & 0x1]; + if (dev) dev->ContinueTransfer(); } u16 DSi_SDHost::Read(u32 addr) { - if(!Num)printf("SDMMC READ %08X %08X\n", addr, NDS::GetPC(1)); - switch (addr & 0x1FF) { case 0x000: return Command; @@ -353,53 +438,7 @@ u16 DSi_SDHost::Read(u32 addr) case 0x036: return CardIRQStatus; case 0x038: return CardIRQMask; - case 0x030: // FIFO16 - { - // TODO: decrement BlockLen???? - - u32 f = CurFIFO; - if (DataFIFO[f]->IsEmpty()) - { - // TODO - return 0; - } - - DSi_SDDevice* dev = Ports[PortSelect & 0x1]; - u16 ret = DataFIFO[f]->Read(); - - if (DataFIFO[f]->IsEmpty()) - { - ClearIRQ(24); - - if (BlockCountInternal <= 1) - { - printf("%s: data RX complete", SD_DESC); - - if (StopAction & (1<<8)) - { - printf(", sending CMD12"); - if (dev) dev->SendCMD(12, 0); - } - - printf("\n"); - - // CHECKME: presumably IRQ2 should not trigger here, but rather - // when the data transfer is done - //SetIRQ(0); - SetIRQ(2); - } - else - { - BlockCountInternal--; - - if (dev) dev->ContinueTransfer(); - } - - SetIRQ(25); - } - - return ret; - } + case 0x030: return ReadFIFO16(); case 0x0D8: return DataCtl; @@ -414,61 +453,52 @@ u16 DSi_SDHost::Read(u32 addr) return 0; } -u32 DSi_SDHost::ReadFIFO32() +u16 DSi_SDHost::ReadFIFO16() { - if (DataMode != 1) return 0; - - // TODO: decrement BlockLen???? - u32 f = CurFIFO; if (DataFIFO[f]->IsEmpty()) { // TODO + // on hardware it seems to wrap around. underflow bit is set upon the first 'empty' read. return 0; } DSi_SDDevice* dev = Ports[PortSelect & 0x1]; - u32 ret = DataFIFO[f]->Read(); - ret |= (DataFIFO[f]->Read() << 16); + u16 ret = DataFIFO[f]->Read(); if (DataFIFO[f]->IsEmpty()) { - ClearIRQ(24); - - if (BlockCountInternal <= 1) - { - printf("%s: data32 RX complete", SD_DESC); + CheckRX(); + } - if (StopAction & (1<<8)) - { - printf(", sending CMD12"); - if (dev) dev->SendCMD(12, 0); - } + return ret; +} - printf("\n"); +u32 DSi_SDHost::ReadFIFO32() +{ + if (DataMode != 1) return 0; - // CHECKME: presumably IRQ2 should not trigger here, but rather - // when the data transfer is done - //SetIRQ(0); - SetIRQ(2); - } - else - { - BlockCountInternal--; + if (DataFIFO32->IsEmpty()) + { + // TODO + return 0; + } - if (dev) dev->ContinueTransfer(); - } + DSi_SDDevice* dev = Ports[PortSelect & 0x1]; + u32 ret = DataFIFO32->Read(); - SetIRQ(25); + if (DataFIFO32->IsEmpty()) + { + CheckRX(); } + UpdateData32IRQ(); + return ret; } void DSi_SDHost::Write(u32 addr, u16 val) { - if(!Num)printf("SDMMC WRITE %08X %04X %08X\n", addr, val, NDS::GetPC(1)); - switch (addr & 0x1FF) { case 0x000: @@ -528,36 +558,10 @@ void DSi_SDHost::Write(u32 addr, u16 val) return; case 0x028: SDOption = val & 0xC1FF; return; - case 0x030: // FIFO16 - { - DSi_SDDevice* dev = Ports[PortSelect & 0x1]; - u32 f = CurFIFO; - if (DataFIFO[f]->IsFull()) - { - // TODO - printf("!!!! %s FIFO (16) FULL\n", SD_DESC); - return; - } - - DataFIFO[f]->Write(val); - - if (DataFIFO[f]->Level() < (BlockLen16>>1)) - { - ClearIRQ(25); - SetIRQ(24); - return; - } - - // we completed one block, send it to the SD card - // TODO measure the actual delay!! - NDS::ScheduleEvent(Num ? NDS::Event_DSi_SDIOTransfer : NDS::Event_DSi_SDMMCTransfer, - false, 2048, FinishReceive, Num); - } - return; + case 0x030: WriteFIFO16(val); return; case 0x034: CardIRQCtl = val & 0x0305; - printf("[%d] CardIRQCtl = %04X\n", Num, val); SetCardIRQ(); return; case 0x036: @@ -565,7 +569,6 @@ void DSi_SDHost::Write(u32 addr, u16 val) return; case 0x038: CardIRQMask = val & 0xC007; - printf("[%d] CardIRQMask = %04X\n", Num, val); SetCardIRQ(); return; @@ -593,12 +596,7 @@ void DSi_SDHost::Write(u32 addr, u16 val) case 0x100: Data32IRQ = (val & 0x1802) | (Data32IRQ & 0x0300); - if (val & (1<<10)) - { - // kind of hacky - u32 f = CurFIFO; - DataFIFO[f]->Clear(); - } + if (val & (1<<10)) DataFIFO32->Clear(); DataMode = ((DataCtl >> 1) & 0x1) & ((Data32IRQ >> 1) & 0x1); printf("%s: data mode %d-bit\n", SD_DESC, DataMode?32:16); return; @@ -609,35 +607,76 @@ void DSi_SDHost::Write(u32 addr, u16 val) printf("unknown %s write %08X %04X\n", SD_DESC, addr, val); } -void DSi_SDHost::WriteFIFO32(u32 val) +void DSi_SDHost::WriteFIFO16(u16 val) { - if (DataMode != 1) return; - - printf("%s: WRITE FIFO32: LEVEL=%d/%d\n", SD_DESC, DataFIFO[CurFIFO]->Level(), (BlockLen16>>1)); - DSi_SDDevice* dev = Ports[PortSelect & 0x1]; u32 f = CurFIFO; if (DataFIFO[f]->IsFull()) { // TODO - printf("!!!! %s FIFO (32) FULL\n", SD_DESC); + printf("!!!! %s FIFO (16) FULL\n", SD_DESC); return; } - DataFIFO[f]->Write(val & 0xFFFF); - DataFIFO[f]->Write(val >> 16); + DataFIFO[f]->Write(val); + + CheckTX(); +} + +void DSi_SDHost::WriteFIFO32(u32 val) +{ + if (DataMode != 1) return; - if (DataFIFO[f]->Level() < (BlockLen16>>1)) + if (DataFIFO32->IsFull()) { - ClearIRQ(25); - SetIRQ(24); + // TODO + printf("!!!! %s FIFO (32) FULL\n", SD_DESC); return; } - // we completed one block, send it to the SD card - // TODO measure the actual delay!! - NDS::ScheduleEvent(Num ? NDS::Event_DSi_SDIOTransfer : NDS::Event_DSi_SDMMCTransfer, - false, 2048, FinishReceive, Num); + DataFIFO32->Write(val); + + CheckTX(); + + UpdateData32IRQ(); +} + +void DSi_SDHost::UpdateFIFO32() +{ + // check whether we can drain FIFO32 into FIFO16, or vice versa + + if (DataMode != 1) return; + + if (!DataFIFO32->IsEmpty()) printf("VERY BAD!! TRYING TO DRAIN FIFO16 INTO FIFO32 BUT IT CONTAINS SHIT ALREADY\n"); + for (;;) + { + u32 f = CurFIFO; + if ((DataFIFO32->Level() << 2) >= BlockLen32) break; + if (DataFIFO[f]->IsEmpty()) break; + + u32 val = DataFIFO[f]->Read(); + val |= (DataFIFO[f]->Read() << 16); + DataFIFO32->Write(val); + } + + UpdateData32IRQ(); + + if ((DataFIFO32->Level() << 2) >= BlockLen32) + { + DSi::CheckNDMAs(1, Num ? 0x29 : 0x28); + } +} + +void DSi_SDHost::CheckSwapFIFO() +{ + // check whether we can swap the FIFOs + + u32 f = CurFIFO; + bool cur_empty = (DataMode == 1) ? DataFIFO32->IsEmpty() : DataFIFO[f]->IsEmpty(); + if (cur_empty && ((DataFIFO[f^1]->Level() << 1) >= BlockLen16)) + { + CurFIFO ^= 1; + } } @@ -813,7 +852,7 @@ void DSi_MMCStorage::SendACMD(u8 cmd, u32 param) case 13: // get SSR Host->SendResponse(CSR, true); - Host->SendData(SSR, 64); + Host->DataRX(SSR, 64); return; case 41: // set operating conditions @@ -834,7 +873,7 @@ void DSi_MMCStorage::SendACMD(u8 cmd, u32 param) case 51: // get SCR Host->SendResponse(CSR, true); - Host->SendData(SCR, 8); + Host->DataRX(SCR, 8); return; } @@ -863,8 +902,6 @@ void DSi_MMCStorage::ContinueTransfer() u32 DSi_MMCStorage::ReadBlock(u64 addr) { - //printf("SD/MMC: reading block @ %08X, len=%08X\n", addr, BlockSize); - u32 len = BlockSize; len = Host->GetTransferrableLen(len); @@ -874,18 +911,17 @@ u32 DSi_MMCStorage::ReadBlock(u64 addr) fseek(File, addr, SEEK_SET); fread(data, 1, len, File); } - return Host->SendData(data, len); + + return Host->DataRX(data, len); } u32 DSi_MMCStorage::WriteBlock(u64 addr) { - printf("SD/MMC: write block @ %08X, len=%08X\n", addr, BlockSize); - u32 len = BlockSize; len = Host->GetTransferrableLen(len); u8 data[0x200]; - if (len = Host->ReceiveData(data, len)) + if (len = Host->DataTX(data, len)) { if (File) { diff --git a/src/DSi_SD.h b/src/DSi_SD.h index f4ca26c..2862173 100644 --- a/src/DSi_SD.h +++ b/src/DSi_SD.h @@ -36,20 +36,29 @@ public: void DoSavestate(Savestate* file); - static void FinishSend(u32 param); - static void FinishReceive(u32 param); + static void FinishRX(u32 param); + static void FinishTX(u32 param); void SendResponse(u32 val, bool last); - u32 SendData(u8* data, u32 len); - u32 ReceiveData(u8* data, u32 len); + u32 DataRX(u8* data, u32 len); + u32 DataTX(u8* data, u32 len); u32 GetTransferrableLen(u32 len); + void CheckRX(); + void CheckTX(); + bool TXReq; + void SetCardIRQ(); u16 Read(u32 addr); void Write(u32 addr, u16 val); + u16 ReadFIFO16(); + void WriteFIFO16(u16 val); u32 ReadFIFO32(); void WriteFIFO32(u32 val); + void UpdateFIFO32(); + void CheckSwapFIFO(); + private: u32 Num; @@ -78,6 +87,7 @@ private: FIFO* DataFIFO[2]; u32 CurFIFO; // FIFO accessible for read/write + FIFO* DataFIFO32; DSi_SDDevice* Ports[2]; -- cgit v1.2.3 From 6326ddd1726773ae21ac2408f9cc3109f112e154 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 1 Jun 2020 16:32:44 +0200 Subject: reset SD controllers during a soft-reset --- src/DSi.cpp | 3 +++ src/DSi_SD.cpp | 12 +++++------- src/NDS.cpp | 4 +--- 3 files changed, 9 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index fb4b37a..58f39c2 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -182,6 +182,9 @@ void SoftReset() LoadNAND(); + SDMMC->Reset(); + SDIO->Reset(); + NDS::ARM9->JumpTo(BootAddr[0]); NDS::ARM7->JumpTo(BootAddr[1]); diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index 5231b99..8584e8b 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -525,12 +525,12 @@ void DSi_SDHost::Write(u32 addr, u16 val) } return; - case 0x002: PortSelect = (val & 0x040F) | (PortSelect & 0x0300); printf("%s: PORT SELECT %04X (%04X)\n", SD_DESC, val, PortSelect); return; + case 0x002: PortSelect = (val & 0x040F) | (PortSelect & 0x0300); return; case 0x004: Param = (Param & 0xFFFF0000) | val; return; case 0x006: Param = (Param & 0x0000FFFF) | (val << 16); return; case 0x008: StopAction = val & 0x0101; return; - case 0x00A: BlockCount16 = val; BlockCountInternal = val; printf("%s: BLOCK COUNT %d\n", SD_DESC, val); return; + case 0x00A: BlockCount16 = val; BlockCountInternal = val; return; case 0x01C: IRQStatus &= (val | 0xFFFF0000); return; case 0x01E: IRQStatus &= ((val << 16) | 0xFFFF); return; @@ -575,7 +575,6 @@ void DSi_SDHost::Write(u32 addr, u16 val) case 0x0D8: DataCtl = (val & 0x0022); DataMode = ((DataCtl >> 1) & 0x1) & ((Data32IRQ >> 1) & 0x1); - printf("%s: data mode %d-bit\n", SD_DESC, DataMode?32:16); return; case 0x0E0: @@ -598,7 +597,6 @@ void DSi_SDHost::Write(u32 addr, u16 val) Data32IRQ = (val & 0x1802) | (Data32IRQ & 0x0300); if (val & (1<<10)) DataFIFO32->Clear(); DataMode = ((DataCtl >> 1) & 0x1) & ((Data32IRQ >> 1) & 0x1); - printf("%s: data mode %d-bit\n", SD_DESC, DataMode?32:16); return; case 0x104: BlockLen32 = val & 0x03FF; return; case 0x108: BlockCount32 = val; return; @@ -803,7 +801,7 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param) return; case 18: // read multiple blocks - printf("READ_MULTIPLE_BLOCKS addr=%08X size=%08X\n", param, BlockSize); + //printf("READ_MULTIPLE_BLOCKS addr=%08X size=%08X\n", param, BlockSize); RWAddress = param; if (OCR & (1<<30)) { @@ -818,7 +816,7 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param) return; case 25: // write multiple blocks - printf("WRITE_MULTIPLE_BLOCKS addr=%08X size=%08X\n", param, BlockSize); + //printf("WRITE_MULTIPLE_BLOCKS addr=%08X size=%08X\n", param, BlockSize); RWAddress = param; if (OCR & (1<<30)) { @@ -846,7 +844,7 @@ void DSi_MMCStorage::SendACMD(u8 cmd, u32 param) switch (cmd) { case 6: // set bus width (TODO?) - printf("SET BUS WIDTH %08X\n", param); + //printf("SET BUS WIDTH %08X\n", param); Host->SendResponse(CSR, true); return; diff --git a/src/NDS.cpp b/src/NDS.cpp index 3936dc8..001dfe6 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -2834,7 +2834,7 @@ u32 ARM9IORead32(u32 addr) case 0x04000130: return (KeyInput & 0xFFFF) | (KeyCnt << 16); - case 0x04000180: /*printf("ARM9 read IPCSYNC: %04X\n", IPCSync9);*/ return IPCSync9; + case 0x04000180: return IPCSync9; case 0x040001A0: return NDSCart::SPICnt | (NDSCart::ReadSPIData() << 16); case 0x040001A4: return NDSCart::ROMCnt; @@ -3043,7 +3043,6 @@ void ARM9IOWrite16(u32 addr, u16 val) return; case 0x04000180: - printf("ARM9 IPCSYNC = %04X\n", val); IPCSync7 &= 0xFFF0; IPCSync7 |= ((val & 0x0F00) >> 8); IPCSync9 &= 0xB0FF; @@ -3633,7 +3632,6 @@ void ARM7IOWrite16(u32 addr, u16 val) case 0x04000138: RTC::Write(val, false); return; case 0x04000180: - printf("ARM7 IPCSYNC = %04X\n", val); IPCSync9 &= 0xFFF0; IPCSync9 |= ((val & 0x0F00) >> 8); IPCSync7 &= 0xB0FF; -- cgit v1.2.3 From b84edfb3219d1610aa59a4f00f9695746bcfd391 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 1 Jun 2020 16:35:09 +0200 Subject: silence pointless and spammy printf --- src/DSi_SD.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index 8584e8b..751c64f 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -444,6 +444,8 @@ u16 DSi_SDHost::Read(u32 addr) case 0x0E0: return SoftReset; + case 0x0F6: return 0; // MMC write protect (always 0) + case 0x100: return Data32IRQ; case 0x104: return BlockLen32; case 0x108: return BlockCount32; -- cgit v1.2.3 From d7b846619b7f1d392b7b5644ddf856290b44e7e1 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 1 Jun 2020 19:11:44 +0200 Subject: add DSi-mode settings --- src/Config.cpp | 18 ++--- src/Config.h | 9 +-- src/frontend/qt_sdl/EmuSettingsDialog.cpp | 66 +++++++++++++++ src/frontend/qt_sdl/EmuSettingsDialog.h | 5 ++ src/frontend/qt_sdl/EmuSettingsDialog.ui | 129 +++++++++++++++++++++++++++++- src/frontend/qt_sdl/PlatformConfig.cpp | 14 ++++ src/frontend/qt_sdl/PlatformConfig.h | 7 ++ src/frontend/qt_sdl/main.cpp | 1 + 8 files changed, 232 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/Config.cpp b/src/Config.cpp index 84c83d8..5745f34 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -32,11 +32,10 @@ char BIOS9Path[1024]; char BIOS7Path[1024]; char FirmwarePath[1024]; -int _3DRenderer; -int Threaded3D; - -int GL_ScaleFactor; -int GL_Antialias; +char DSiBIOS9Path[1024]; +char DSiBIOS7Path[1024]; +char DSiFirmwarePath[1024]; +char DSiNANDPath[1024]; ConfigEntry ConfigFile[] = { @@ -44,11 +43,10 @@ ConfigEntry ConfigFile[] = {"BIOS7Path", 1, BIOS7Path, 0, "", 1023}, {"FirmwarePath", 1, FirmwarePath, 0, "", 1023}, - {"3DRenderer", 0, &_3DRenderer, 1, NULL, 0}, - {"Threaded3D", 0, &Threaded3D, 1, NULL, 0}, - - {"GL_ScaleFactor", 0, &GL_ScaleFactor, 1, NULL, 0}, - {"GL_Antialias", 0, &GL_Antialias, 0, NULL, 0}, + {"DSiBIOS9Path", 1, DSiBIOS9Path, 0, "", 1023}, + {"DSiBIOS7Path", 1, DSiBIOS7Path, 0, "", 1023}, + {"DSiFirmwarePath", 1, DSiFirmwarePath, 0, "", 1023}, + {"DSiNANDPath", 1, DSiNANDPath, 0, "", 1023}, {"", -1, NULL, 0, NULL, 0} }; diff --git a/src/Config.h b/src/Config.h index 05b9b8b..3947598 100644 --- a/src/Config.h +++ b/src/Config.h @@ -46,11 +46,10 @@ extern char BIOS9Path[1024]; extern char BIOS7Path[1024]; extern char FirmwarePath[1024]; -extern int _3DRenderer; -extern int Threaded3D; - -extern int GL_ScaleFactor; -extern int GL_Antialias; +extern char DSiBIOS9Path[1024]; +extern char DSiBIOS7Path[1024]; +extern char DSiFirmwarePath[1024]; +extern char DSiNANDPath[1024]; } diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.cpp b/src/frontend/qt_sdl/EmuSettingsDialog.cpp index 5c2efc0..7760a88 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.cpp +++ b/src/frontend/qt_sdl/EmuSettingsDialog.cpp @@ -42,6 +42,16 @@ EmuSettingsDialog::EmuSettingsDialog(QWidget* parent) : QDialog(parent), ui(new ui->txtBIOS9Path->setText(Config::BIOS9Path); ui->txtBIOS7Path->setText(Config::BIOS7Path); ui->txtFirmwarePath->setText(Config::FirmwarePath); + + ui->txtDSiBIOS9Path->setText(Config::DSiBIOS9Path); + ui->txtDSiBIOS7Path->setText(Config::DSiBIOS7Path); + ui->txtDSiFirmwarePath->setText(Config::DSiFirmwarePath); + ui->txtDSiNANDPath->setText(Config::DSiNANDPath); + + ui->cbxConsoleType->addItem("DS"); + ui->cbxConsoleType->addItem("DSi"); + ui->cbxConsoleType->setCurrentIndex(Config::ConsoleType); + ui->chkDirectBoot->setChecked(Config::DirectBoot != 0); } @@ -99,7 +109,15 @@ void EmuSettingsDialog::on_EmuSettingsDialog_accepted() strncpy(Config::BIOS9Path, ui->txtBIOS9Path->text().toStdString().c_str(), 1023); Config::BIOS9Path[1023] = '\0'; strncpy(Config::BIOS7Path, ui->txtBIOS7Path->text().toStdString().c_str(), 1023); Config::BIOS7Path[1023] = '\0'; strncpy(Config::FirmwarePath, ui->txtFirmwarePath->text().toStdString().c_str(), 1023); Config::FirmwarePath[1023] = '\0'; + + strncpy(Config::DSiBIOS9Path, ui->txtDSiBIOS9Path->text().toStdString().c_str(), 1023); Config::DSiBIOS9Path[1023] = '\0'; + strncpy(Config::DSiBIOS7Path, ui->txtDSiBIOS7Path->text().toStdString().c_str(), 1023); Config::DSiBIOS7Path[1023] = '\0'; + strncpy(Config::DSiFirmwarePath, ui->txtDSiFirmwarePath->text().toStdString().c_str(), 1023); Config::DSiFirmwarePath[1023] = '\0'; + strncpy(Config::DSiNANDPath, ui->txtDSiNANDPath->text().toStdString().c_str(), 1023); Config::DSiNANDPath[1023] = '\0'; + + Config::ConsoleType = ui->cbxConsoleType->currentIndex(); Config::DirectBoot = ui->chkDirectBoot->isChecked() ? 1:0; + Config::Save(); closeDlg(); @@ -145,3 +163,51 @@ void EmuSettingsDialog::on_btnFirmwareBrowse_clicked() ui->txtFirmwarePath->setText(file); } + +void EmuSettingsDialog::on_btnDSiBIOS9Browse_clicked() +{ + QString file = QFileDialog::getOpenFileName(this, + "Select DSi-mode ARM9 BIOS...", + EmuDirectory, + "BIOS files (*.bin *.rom);;Any file (*.*)"); + + if (file.isEmpty()) return; + + ui->txtDSiBIOS9Path->setText(file); +} + +void EmuSettingsDialog::on_btnDSiBIOS7Browse_clicked() +{ + QString file = QFileDialog::getOpenFileName(this, + "Select DSi-mode ARM7 BIOS...", + EmuDirectory, + "BIOS files (*.bin *.rom);;Any file (*.*)"); + + if (file.isEmpty()) return; + + ui->txtDSiBIOS7Path->setText(file); +} + +void EmuSettingsDialog::on_btnDSiFirmwareBrowse_clicked() +{ + QString file = QFileDialog::getOpenFileName(this, + "Select DSi DS-mode firmware...", + EmuDirectory, + "Firmware files (*.bin *.rom);;Any file (*.*)"); + + if (file.isEmpty()) return; + + ui->txtDSiFirmwarePath->setText(file); +} + +void EmuSettingsDialog::on_btnDSiNANDBrowse_clicked() +{ + QString file = QFileDialog::getOpenFileName(this, + "Select DSi NAND...", + EmuDirectory, + "NAND files (*.bin *.rom);;Any file (*.*)"); + + if (file.isEmpty()) return; + + ui->txtDSiNANDPath->setText(file); +} diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.h b/src/frontend/qt_sdl/EmuSettingsDialog.h index 7378641..f604ba5 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.h +++ b/src/frontend/qt_sdl/EmuSettingsDialog.h @@ -58,6 +58,11 @@ private slots: void on_btnBIOS7Browse_clicked(); void on_btnFirmwareBrowse_clicked(); + void on_btnDSiBIOS9Browse_clicked(); + void on_btnDSiBIOS7Browse_clicked(); + void on_btnDSiFirmwareBrowse_clicked(); + void on_btnDSiNANDBrowse_clicked(); + private: void verifyFirmware(); diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.ui b/src/frontend/qt_sdl/EmuSettingsDialog.ui index c70c3a2..4894fa5 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.ui +++ b/src/frontend/qt_sdl/EmuSettingsDialog.ui @@ -7,7 +7,7 @@ 0 0 490 - 217 + 392 @@ -119,13 +119,138 @@ + + + + DSi mode + + + + + + Browse... + + + + + + + DSi ARM9 BIOS: + + + + + + + Browse... + + + + + + + <html><head/><body><p>DSi-mode ARM7 BIOS</p><p><br/></p><p>Size should be 64 KB</p></body></html> + + + + + + + <html><head/><body><p>DSi-mode firmware (used for DS-mode backwards compatibility)</p><p><br/></p><p>Size should be 128 KB</p></body></html> + + + + + + + DSi ARM7 BIOS: + + + + + + + DSi firmware: + + + + + + + Browse... + + + + + + + + 0 + 0 + + + + <html><head/><body><p>DSi-mode ARM9 BIOS</p><p><br/></p><p>Size should be 64 KB</p></body></html> + + + + + + + DSi NAND: + + + + + + + <html><head/><body><p>DSi NAND dump</p><p><br/></p><p>Should have 'nocash footer' at the end</p></body></html> + + + + + + + Browse... + + + + + + - Startup + General + + + + 0 + 0 + + + + Console type: + + + + + + + + 0 + 0 + + + + <html><head/><body><p>The type of console to emulate</p></body></html> + + + + <html><head/><body><p>When loading a ROM, completely skip the regular boot process (&quot;Nintendo DS&quot; screen) to boot the ROM directly.</p><p><br/></p><p>Note: if your firmware dump isn't bootable, the ROM will be booted directly regardless of this setting.</p></body></html> diff --git a/src/frontend/qt_sdl/PlatformConfig.cpp b/src/frontend/qt_sdl/PlatformConfig.cpp index 03fd2ac..06128d7 100644 --- a/src/frontend/qt_sdl/PlatformConfig.cpp +++ b/src/frontend/qt_sdl/PlatformConfig.cpp @@ -47,10 +47,17 @@ int ScreenUseGL; int ScreenVSync; int ScreenVSyncInterval; +int _3DRenderer; +int Threaded3D; + +int GL_ScaleFactor; +int GL_Antialias; + int LimitFPS; int AudioSync; int ShowOSD; +int ConsoleType; int DirectBoot; int SocketBindAnyAddr; @@ -129,10 +136,17 @@ ConfigEntry PlatformConfigFile[] = {"ScreenVSync", 0, &ScreenVSync, 0, NULL, 0}, {"ScreenVSyncInterval", 0, &ScreenVSyncInterval, 1, NULL, 0}, + {"3DRenderer", 0, &_3DRenderer, 1, NULL, 0}, + {"Threaded3D", 0, &Threaded3D, 1, NULL, 0}, + + {"GL_ScaleFactor", 0, &GL_ScaleFactor, 1, NULL, 0}, + {"GL_Antialias", 0, &GL_Antialias, 0, NULL, 0}, + {"LimitFPS", 0, &LimitFPS, 0, NULL, 0}, {"AudioSync", 0, &AudioSync, 1, NULL, 0}, {"ShowOSD", 0, &ShowOSD, 1, NULL, 0}, + {"ConsoleType", 0, &ConsoleType, 0, NULL, 0}, {"DirectBoot", 0, &DirectBoot, 1, NULL, 0}, {"SockBindAnyAddr", 0, &SocketBindAnyAddr, 0, NULL, 0}, diff --git a/src/frontend/qt_sdl/PlatformConfig.h b/src/frontend/qt_sdl/PlatformConfig.h index cc288b6..791bb07 100644 --- a/src/frontend/qt_sdl/PlatformConfig.h +++ b/src/frontend/qt_sdl/PlatformConfig.h @@ -60,10 +60,17 @@ extern int ScreenUseGL; extern int ScreenVSync; extern int ScreenVSyncInterval; +extern int _3DRenderer; +extern int Threaded3D; + +extern int GL_ScaleFactor; +extern int GL_Antialias; + extern int LimitFPS; extern int AudioSync; extern int ShowOSD; +extern int ConsoleType; extern int DirectBoot; extern int SocketBindAnyAddr; diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index a3207c7..ef21bc7 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -1889,6 +1889,7 @@ int main(int argc, char** argv) Config::Load(); #define SANITIZE(var, min, max) { if (var < min) var = min; else if (var > max) var = max; } + SANITIZE(Config::ConsoleType, 0, 1); SANITIZE(Config::_3DRenderer, 0, 1); SANITIZE(Config::ScreenVSyncInterval, 1, 20); SANITIZE(Config::GL_ScaleFactor, 1, 16); -- cgit v1.2.3 From 43e045357f7d74eecff61b0c8af8068b31e963b3 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 1 Jun 2020 20:36:30 +0200 Subject: make it able to switch between DS and DSi modes --- src/ARM.cpp | 46 +++++++++ src/ARM.h | 43 ++++---- src/CP15.cpp | 30 ++---- src/DMA.cpp | 29 ++++-- src/DMA.h | 5 + src/DSi.cpp | 7 +- src/NDS.cpp | 54 +++++++--- src/NDS.h | 5 + src/NDSCart.cpp | 15 ++- src/SPI.cpp | 32 ++++-- src/SPU.cpp | 16 ++- src/SPU.h | 6 ++ src/frontend/FrontendUtil.h | 9 ++ src/frontend/Util_ROM.cpp | 163 +++++++++++++++++++++++++++--- src/frontend/qt_sdl/EmuSettingsDialog.cpp | 2 +- src/frontend/qt_sdl/main.cpp | 45 +++++++-- 16 files changed, 396 insertions(+), 111 deletions(-) (limited to 'src') diff --git a/src/ARM.cpp b/src/ARM.cpp index 2d8c807..68cac59 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -18,6 +18,7 @@ #include #include "NDS.h" +#include "DSi.h" #include "ARM.h" #include "ARMInterpreter.h" #include "AREngine.h" @@ -101,10 +102,55 @@ void ARM::Reset() void ARMv5::Reset() { + if (NDS::ConsoleType == 1) + { + BusRead8 = DSi::ARM9Read8; + BusRead16 = DSi::ARM9Read16; + BusRead32 = DSi::ARM9Read32; + BusWrite8 = DSi::ARM9Write8; + BusWrite16 = DSi::ARM9Write16; + BusWrite32 = DSi::ARM9Write32; + GetMemRegion = DSi::ARM9GetMemRegion; + } + else + { + BusRead8 = NDS::ARM9Read8; + BusRead16 = NDS::ARM9Read16; + BusRead32 = NDS::ARM9Read32; + BusWrite8 = NDS::ARM9Write8; + BusWrite16 = NDS::ARM9Write16; + BusWrite32 = NDS::ARM9Write32; + GetMemRegion = NDS::ARM9GetMemRegion; + } + CP15Reset(); ARM::Reset(); } +void ARMv4::Reset() +{ + if (NDS::ConsoleType) + { + BusRead8 = DSi::ARM7Read8; + BusRead16 = DSi::ARM7Read16; + BusRead32 = DSi::ARM7Read32; + BusWrite8 = DSi::ARM7Write8; + BusWrite16 = DSi::ARM7Write16; + BusWrite32 = DSi::ARM7Write32; + } + else + { + BusRead8 = NDS::ARM7Read8; + BusRead16 = NDS::ARM7Read16; + BusRead32 = NDS::ARM7Read32; + BusWrite8 = NDS::ARM7Write8; + BusWrite16 = NDS::ARM7Write16; + BusWrite32 = NDS::ARM7Write32; + } + + ARM::Reset(); +} + void ARM::DoSavestate(Savestate* file) { diff --git a/src/ARM.h b/src/ARM.h index 95c41d4..e0832e2 100644 --- a/src/ARM.h +++ b/src/ARM.h @@ -23,7 +23,6 @@ #include "types.h" #include "NDS.h" -#include "DSi.h" #define ROR(x, n) (((x) >> (n)) | ((x) << (32-(n)))) @@ -133,6 +132,14 @@ public: NDS::MemRegion CodeMem; static u32 ConditionTable[16]; + +protected: + u8 (*BusRead8)(u32 addr); + u16 (*BusRead16)(u32 addr); + u32 (*BusRead32)(u32 addr); + void (*BusWrite8)(u32 addr, u8 val); + void (*BusWrite16)(u32 addr, u16 val); + void (*BusWrite32)(u32 addr, u32 val); }; class ARMv5 : public ARM @@ -260,6 +267,8 @@ public: s32 RegionCodeCycles; u8* CurICacheLine; + + bool (*GetMemRegion)(u32 addr, bool write, NDS::MemRegion* region); }; class ARMv4 : public ARM @@ -267,26 +276,25 @@ class ARMv4 : public ARM public: ARMv4(); + void Reset(); + void JumpTo(u32 addr, bool restorecpsr = false); void Execute(); u16 CodeRead16(u32 addr) { - //return NDS::ARM7Read16(addr); - return DSi::ARM7Read16(addr); + return BusRead16(addr); } u32 CodeRead32(u32 addr) { - //return NDS::ARM7Read32(addr); - return DSi::ARM7Read32(addr); + return BusRead32(addr); } void DataRead8(u32 addr, u32* val) { - *val = DSi::ARM7Read8(addr); - //*val = NDS::ARM7Read8(addr); + *val = BusRead8(addr); DataRegion = addr >> 24; DataCycles = NDS::ARM7MemTimings[DataRegion][0]; } @@ -295,8 +303,7 @@ public: { addr &= ~1; - *val = DSi::ARM7Read16(addr); - //*val = NDS::ARM7Read16(addr); + *val = BusRead16(addr); DataRegion = addr >> 24; DataCycles = NDS::ARM7MemTimings[DataRegion][0]; } @@ -305,8 +312,7 @@ public: { addr &= ~3; - *val = DSi::ARM7Read32(addr); - //*val = NDS::ARM7Read32(addr); + *val = BusRead32(addr); DataRegion = addr >> 24; DataCycles = NDS::ARM7MemTimings[DataRegion][2]; } @@ -315,15 +321,13 @@ public: { addr &= ~3; - *val = DSi::ARM7Read32(addr); - //*val = NDS::ARM7Read32(addr); + *val = BusRead32(addr); DataCycles += NDS::ARM7MemTimings[DataRegion][3]; } void DataWrite8(u32 addr, u8 val) { - DSi::ARM7Write8(addr, val); - //NDS::ARM7Write8(addr, val); + BusWrite8(addr, val); DataRegion = addr >> 24; DataCycles = NDS::ARM7MemTimings[DataRegion][0]; } @@ -332,8 +336,7 @@ public: { addr &= ~1; - DSi::ARM7Write16(addr, val); - //NDS::ARM7Write16(addr, val); + BusWrite16(addr, val); DataRegion = addr >> 24; DataCycles = NDS::ARM7MemTimings[DataRegion][0]; } @@ -342,8 +345,7 @@ public: { addr &= ~3; - DSi::ARM7Write32(addr, val); - //NDS::ARM7Write32(addr, val); + BusWrite32(addr, val); DataRegion = addr >> 24; DataCycles = NDS::ARM7MemTimings[DataRegion][2]; } @@ -352,8 +354,7 @@ public: { addr &= ~3; - DSi::ARM7Write32(addr, val); - //NDS::ARM7Write32(addr, val); + BusWrite32(addr, val); DataCycles += NDS::ARM7MemTimings[DataRegion][3]; } diff --git a/src/CP15.cpp b/src/CP15.cpp index b61cc45..d340b9e 100644 --- a/src/CP15.cpp +++ b/src/CP15.cpp @@ -720,8 +720,7 @@ u32 ARMv5::CodeRead32(u32 addr, bool branch) if (CodeMem.Mem) return *(u32*)&CodeMem.Mem[addr & CodeMem.Mask]; - //return NDS::ARM9Read32(addr); - return DSi::ARM9Read32(addr); + return BusRead32(addr); } @@ -740,8 +739,7 @@ void ARMv5::DataRead8(u32 addr, u32* val) return; } - *val = DSi::ARM9Read8(addr); - //*val = NDS::ARM9Read8(addr); + *val = BusRead8(addr); DataCycles = MemTimings[addr >> 12][1]; } @@ -762,8 +760,7 @@ void ARMv5::DataRead16(u32 addr, u32* val) return; } - *val = DSi::ARM9Read16(addr); - //*val = NDS::ARM9Read16(addr); + *val = BusRead16(addr); DataCycles = MemTimings[addr >> 12][1]; } @@ -784,8 +781,7 @@ void ARMv5::DataRead32(u32 addr, u32* val) return; } - *val = DSi::ARM9Read32(addr); - //*val = NDS::ARM9Read32(addr); + *val = BusRead32(addr); DataCycles = MemTimings[addr >> 12][2]; } @@ -806,8 +802,7 @@ void ARMv5::DataRead32S(u32 addr, u32* val) return; } - *val = DSi::ARM9Read32(addr); - //*val = NDS::ARM9Read32(addr); + *val = BusRead32(addr); DataCycles += MemTimings[addr >> 12][3]; } @@ -826,8 +821,7 @@ void ARMv5::DataWrite8(u32 addr, u8 val) return; } - DSi::ARM9Write8(addr, val); - //NDS::ARM9Write8(addr, val); + BusWrite8(addr, val); DataCycles = MemTimings[addr >> 12][1]; } @@ -848,8 +842,7 @@ void ARMv5::DataWrite16(u32 addr, u16 val) return; } - DSi::ARM9Write16(addr, val); - //NDS::ARM9Write16(addr, val); + BusWrite16(addr, val); DataCycles = MemTimings[addr >> 12][1]; } @@ -870,8 +863,7 @@ void ARMv5::DataWrite32(u32 addr, u32 val) return; } - DSi::ARM9Write32(addr, val); - //NDS::ARM9Write32(addr, val); + BusWrite32(addr, val); DataCycles = MemTimings[addr >> 12][2]; } @@ -892,8 +884,7 @@ void ARMv5::DataWrite32S(u32 addr, u32 val) return; } - DSi::ARM9Write32(addr, val); - //NDS::ARM9Write32(addr, val); + BusWrite32(addr, val); DataCycles += MemTimings[addr >> 12][3]; } @@ -906,7 +897,6 @@ void ARMv5::GetCodeMemRegion(u32 addr, NDS::MemRegion* region) return; }*/ - DSi::ARM9GetMemRegion(addr, false, &CodeMem); - //NDS::ARM9GetMemRegion(addr, false, &CodeMem); + GetMemRegion(addr, false, &CodeMem); } diff --git a/src/DMA.cpp b/src/DMA.cpp index 8e294fc..cd2df45 100644 --- a/src/DMA.cpp +++ b/src/DMA.cpp @@ -53,8 +53,6 @@ DMA::DMA(u32 cpu, u32 num) CountMask = 0x001FFFFF; else CountMask = (num==3 ? 0x0000FFFF : 0x00003FFF); - - Reset(); } DMA::~DMA() @@ -77,6 +75,21 @@ void DMA::Reset() Running = false; InProgress = false; + + if (NDS::ConsoleType == 1) + { + BusRead16 = (CPU==0) ? DSi::ARM9Read16 : DSi::ARM7Read16; + BusRead32 = (CPU==0) ? DSi::ARM9Read32 : DSi::ARM7Read32; + BusWrite16 = (CPU==0) ? DSi::ARM9Write16 : DSi::ARM7Write16; + BusWrite32 = (CPU==0) ? DSi::ARM9Write32 : DSi::ARM7Write32; + } + else + { + BusRead16 = (CPU==0) ? NDS::ARM9Read16 : NDS::ARM7Read16; + BusRead32 = (CPU==0) ? NDS::ARM9Read32 : NDS::ARM7Read32; + BusWrite16 = (CPU==0) ? NDS::ARM9Write16 : NDS::ARM7Write16; + BusWrite32 = (CPU==0) ? NDS::ARM9Write32 : NDS::ARM7Write32; + } } void DMA::DoSavestate(Savestate* file) @@ -227,8 +240,7 @@ void DMA::Run9() { NDS::ARM9Timestamp += (unitcycles << NDS::ARM9ClockShift); - //NDS::ARM9Write16(CurDstAddr, NDS::ARM9Read16(CurSrcAddr)); - DSi::ARM9Write16(CurDstAddr, DSi::ARM9Read16(CurSrcAddr)); + BusWrite16(CurDstAddr, BusRead16(CurSrcAddr)); CurSrcAddr += SrcAddrInc<<1; CurDstAddr += DstAddrInc<<1; @@ -264,8 +276,7 @@ void DMA::Run9() { NDS::ARM9Timestamp += (unitcycles << NDS::ARM9ClockShift); - //NDS::ARM9Write32(CurDstAddr, NDS::ARM9Read32(CurSrcAddr)); - DSi::ARM9Write32(CurDstAddr, DSi::ARM9Read32(CurSrcAddr)); + BusWrite32(CurDstAddr, BusRead32(CurSrcAddr)); CurSrcAddr += SrcAddrInc<<2; CurDstAddr += DstAddrInc<<2; @@ -341,8 +352,7 @@ void DMA::Run7() { NDS::ARM7Timestamp += unitcycles; - //NDS::ARM7Write16(CurDstAddr, NDS::ARM7Read16(CurSrcAddr)); - DSi::ARM7Write16(CurDstAddr, DSi::ARM7Read16(CurSrcAddr)); + BusWrite16(CurDstAddr, BusRead16(CurSrcAddr)); CurSrcAddr += SrcAddrInc<<1; CurDstAddr += DstAddrInc<<1; @@ -378,8 +388,7 @@ void DMA::Run7() { NDS::ARM7Timestamp += unitcycles; - //NDS::ARM7Write32(CurDstAddr, NDS::ARM7Read32(CurSrcAddr)); - DSi::ARM7Write32(CurDstAddr, DSi::ARM7Read32(CurSrcAddr)); + BusWrite32(CurDstAddr, BusRead32(CurSrcAddr)); CurSrcAddr += SrcAddrInc<<2; CurDstAddr += DstAddrInc<<2; diff --git a/src/DMA.h b/src/DMA.h index 2e7678c..0344fba 100644 --- a/src/DMA.h +++ b/src/DMA.h @@ -86,6 +86,11 @@ private: bool Stall; bool IsGXFIFODMA; + + u16 (*BusRead16)(u32 addr); + u32 (*BusRead32)(u32 addr); + void (*BusWrite16)(u32 addr, u16 val); + void (*BusWrite32)(u32 addr, u32 val); }; #endif diff --git a/src/DSi.cpp b/src/DSi.cpp index 58f39c2..520b269 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -18,6 +18,7 @@ #include #include +#include "Config.h" #include "NDS.h" #include "DSi.h" #include "ARM.h" @@ -221,7 +222,7 @@ bool LoadBIOS() memset(ARM9iBIOS, 0, 0x10000); memset(ARM7iBIOS, 0, 0x10000); - f = Platform::OpenLocalFile("bios9i.bin", "rb"); + f = Platform::OpenLocalFile(Config::DSiBIOS9Path, "rb"); if (!f) { printf("ARM9i BIOS not found\n"); @@ -238,7 +239,7 @@ bool LoadBIOS() fclose(f); } - f = Platform::OpenLocalFile("bios7i.bin", "rb"); + f = Platform::OpenLocalFile(Config::DSiBIOS7Path, "rb"); if (!f) { printf("ARM7i BIOS not found\n"); @@ -283,7 +284,7 @@ bool LoadNAND() memset(NWRAMEnd, 0, sizeof(NWRAMEnd)); memset(NWRAMMask, 0, sizeof(NWRAMMask)); - FILE* f = Platform::OpenLocalFile("nand.bin", "rb"); + FILE* f = Platform::OpenLocalFile(Config::DSiNANDPath, "rb"); if (f) { u32 bootparams[8]; diff --git a/src/NDS.cpp b/src/NDS.cpp index 001dfe6..22368ae 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -62,6 +62,8 @@ namespace NDS // // timings for GBA slot and wifi are set up at runtime +int ConsoleType; + u8 ARM9MemTimings[0x40000][4]; u8 ARM7MemTimings[0x20000][4]; @@ -296,6 +298,8 @@ void InitTimings() // TODO: +3c nonseq waitstate doesn't apply to DMA! // but of course mainRAM always gets 8c nonseq waitstate + // TODO: DSi-specific timings!! + SetARM9RegionTimings(0x00000000, 0xFFFFFFFF, 32, 1 + 3, 1); // void SetARM9RegionTimings(0xFFFF0000, 0xFFFFFFFF, 32, 1 + 3, 1); // BIOS @@ -321,6 +325,12 @@ void InitTimings() void SetupDirectBoot() { + if (ConsoleType == 1) + { + printf("!! DIRECT BOOT NOT SUPPORTED IN DSI MODE\n"); + return; + } + u32 bootparams[8]; memcpy(bootparams, &NDSCart::CartROM[0x20], 8*4); @@ -469,7 +479,7 @@ void Reset() fclose(f); } - if (true) + if (ConsoleType == 1) { DSi::LoadBIOS(); DSi::LoadNAND(); @@ -559,8 +569,11 @@ void Reset() RTC::Reset(); Wifi::Reset(); - DSi::Reset(); - KeyInput &= ~(1 << (16+6)); // TODO + if (ConsoleType == 1) + { + DSi::Reset(); + KeyInput &= ~(1 << (16+6)); + } AREngine::Reset(); } @@ -670,6 +683,11 @@ bool DoSavestate(Savestate* file) { file->Section("NDSG"); + // TODO: + // * do something for bool's (sizeof=1) + // * do something for 'loading DSi-mode savestate in DS mode' and vice-versa + // * add IE2/IF2 there + file->VarArray(MainRAM, 0x400000); file->VarArray(SharedWRAM, 0x8000); file->VarArray(ARM7WRAM, 0x10000); @@ -772,6 +790,11 @@ bool DoSavestate(Savestate* file) return true; } +void SetConsoleType(int type) +{ + ConsoleType = type; +} + bool LoadROM(const char* path, const char* sram, bool direct) { if (NDSCart::LoadROM(path, sram, direct)) @@ -883,7 +906,7 @@ u32 RunFrame() if (!(CPUStop & 0x80000000)) DMAs[1]->Run(); if (!(CPUStop & 0x80000000)) DMAs[2]->Run(); if (!(CPUStop & 0x80000000)) DMAs[3]->Run(); - DSi::RunNDMAs(0); + if (ConsoleType == 1) DSi::RunNDMAs(0); } else { @@ -906,7 +929,7 @@ u32 RunFrame() DMAs[5]->Run(); DMAs[6]->Run(); DMAs[7]->Run(); - DSi::RunNDMAs(1); + if (ConsoleType == 1) DSi::RunNDMAs(1); } else { @@ -990,7 +1013,7 @@ void CancelEvent(u32 id) void TouchScreen(u16 x, u16 y) { - if (true) // TODO!! + if (ConsoleType == 1) { DSi_SPI_TSC::SetTouchCoords(x, y); } @@ -1003,7 +1026,7 @@ void TouchScreen(u16 x, u16 y) void ReleaseScreen() { - if (true) // TODO!! + if (ConsoleType == 1) { DSi_SPI_TSC::SetTouchCoords(0x000, 0xFFF); } @@ -1144,7 +1167,8 @@ void UpdateIRQ(u32 cpu) if (IME[cpu] & 0x1) { arm->IRQ = IE[cpu] & IF[cpu]; - if (cpu) arm->IRQ |= (IE2 & IF2); + if ((ConsoleType == 1) && cpu) + arm->IRQ |= (IE2 & IF2); } else { @@ -1223,7 +1247,7 @@ void GXFIFOStall() DMAs[1]->StallIfRunning(); DMAs[2]->StallIfRunning(); DMAs[3]->StallIfRunning(); - DSi::StallNDMAs(); + if (ConsoleType == 1) DSi::StallNDMAs(); } } @@ -1361,6 +1385,7 @@ void NocashPrint(u32 ncpu, u32 addr) void MonitorARM9Jump(u32 addr) { // checkme: can the entrypoint addr be THUMB? + // also TODO: make it work in DSi mode if ((!RunningGame) && NDSCart::CartROM) { @@ -1468,7 +1493,7 @@ bool DMAsInMode(u32 cpu, u32 mode) if (DMAs[cpu+2]->IsInMode(mode)) return true; if (DMAs[cpu+3]->IsInMode(mode)) return true; - if (true) + if (ConsoleType == 1) { cpu >>= 2; return DSi::NDMAsInMode(cpu, NDMAModes[mode]); @@ -1484,7 +1509,10 @@ bool DMAsRunning(u32 cpu) if (DMAs[cpu+1]->IsRunning()) return true; if (DMAs[cpu+2]->IsRunning()) return true; if (DMAs[cpu+3]->IsRunning()) return true; - if (DSi::NDMAsRunning(cpu>>2)) return true; + if (ConsoleType == 1) + { + if (DSi::NDMAsRunning(cpu>>2)) return true; + } return false; } @@ -1496,7 +1524,7 @@ void CheckDMAs(u32 cpu, u32 mode) DMAs[cpu+2]->StartIfNeeded(mode); DMAs[cpu+3]->StartIfNeeded(mode); - if (true) + if (ConsoleType == 1) { cpu >>= 2; DSi::CheckNDMAs(cpu, NDMAModes[mode]); @@ -1511,7 +1539,7 @@ void StopDMAs(u32 cpu, u32 mode) DMAs[cpu+2]->StopIfNeeded(mode); DMAs[cpu+3]->StopIfNeeded(mode); - if (true) + if (ConsoleType == 1) { cpu >>= 2; DSi::StopNDMAs(cpu, NDMAModes[mode]); diff --git a/src/NDS.h b/src/NDS.h index 26931de..9c5fe3d 100644 --- a/src/NDS.h +++ b/src/NDS.h @@ -133,6 +133,8 @@ typedef struct } MemRegion; +extern int ConsoleType; + extern u8 ARM9MemTimings[0x40000][4]; extern u8 ARM7MemTimings[0x20000][4]; @@ -174,6 +176,9 @@ bool DoSavestate(Savestate* file); void SetARM9RegionTimings(u32 addrstart, u32 addrend, int buswidth, int nonseq, int seq); void SetARM7RegionTimings(u32 addrstart, u32 addrend, int buswidth, int nonseq, int seq); +// 0=DS 1=DSi +void SetConsoleType(int type); + bool LoadROM(const char* path, const char* sram, bool direct); bool LoadGBAROM(const char* path, const char* sram); void LoadBIOS(); diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index 9497d33..b326dd6 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -561,11 +561,18 @@ void Key1_ApplyKeycode(u32* keycode, u32 mod) void Key1_InitKeycode(bool dsi, u32 idcode, u32 level, u32 mod) { - //memcpy(Key1_KeyBuf, &NDS::ARM7BIOS[0x30], 0x1048); // hax - if (dsi) - memcpy(Key1_KeyBuf, &DSi::ARM7Init[0x254], 0x1048); // hax + // TODO: source the key data from different possible places + if (NDS::ConsoleType == 1) + { + if (dsi) + memcpy(Key1_KeyBuf, &DSi::ARM7Init[0x254], 0x1048); // hax + else + memcpy(Key1_KeyBuf, &DSi::ITCMInit[0x4894], 0x1048); // hax + } else - memcpy(Key1_KeyBuf, &DSi::ITCMInit[0x4894], 0x1048); // hax + { + memcpy(Key1_KeyBuf, &NDS::ARM7BIOS[0x30], 0x1048); // hax + } u32 keycode[3] = {idcode, idcode>>1, idcode<<1}; if (level >= 1) Key1_ApplyKeycode(keycode, mod); diff --git a/src/SPI.cpp b/src/SPI.cpp index 29f3321..ac40707 100644 --- a/src/SPI.cpp +++ b/src/SPI.cpp @@ -93,7 +93,10 @@ void Reset() if (Firmware) delete[] Firmware; Firmware = NULL; - strncpy(FirmwarePath, Config::FirmwarePath, 1023); + if (NDS::ConsoleType == 1) + strncpy(FirmwarePath, Config::DSiFirmwarePath, 1023); + else + strncpy(FirmwarePath, Config::FirmwarePath, 1023); FILE* f = Platform::OpenLocalFile(FirmwarePath, "rb"); if (!f) @@ -620,7 +623,7 @@ void Reset() SPI_Firmware::Reset(); SPI_Powerman::Reset(); SPI_TSC::Reset(); - DSi_SPI_TSC::Reset(); + if (NDS::ConsoleType == 1) DSi_SPI_TSC::Reset(); } void DoSavestate(Savestate* file) @@ -633,7 +636,7 @@ void DoSavestate(Savestate* file) SPI_Firmware::DoSavestate(file); SPI_Powerman::DoSavestate(file); SPI_TSC::DoSavestate(file); - DSi_SPI_TSC::DoSavestate(file); + if (NDS::ConsoleType == 1) DSi_SPI_TSC::DoSavestate(file); } @@ -647,8 +650,12 @@ void WriteCnt(u16 val) { case 0x0000: SPI_Powerman::Hold = 0; break; case 0x0100: SPI_Firmware::Hold = 0; break; - //case 0x0200: SPI_TSC::DataPos = 0; break; - case 0x0200: DSi_SPI_TSC::DataPos = 0; break; + case 0x0200: + if (NDS::ConsoleType == 1) + DSi_SPI_TSC::DataPos = 0; + else + SPI_TSC::DataPos = 0; + break; } } @@ -674,8 +681,11 @@ u8 ReadData() { case 0x0000: return SPI_Powerman::Read(); case 0x0100: return SPI_Firmware::Read(); - //case 0x0200: return SPI_TSC::Read(); - case 0x0200: return DSi_SPI_TSC::Read(); + case 0x0200: + if (NDS::ConsoleType == 1) + return DSi_SPI_TSC::Read(); + else + return SPI_TSC::Read(); default: return 0; } } @@ -691,8 +701,12 @@ void WriteData(u8 val) { case 0x0000: SPI_Powerman::Write(val, Cnt&(1<<11)); break; case 0x0100: SPI_Firmware::Write(val, Cnt&(1<<11)); break; - //case 0x0200: SPI_TSC::Write(val, Cnt&(1<<11)); break; - case 0x0200: DSi_SPI_TSC::Write(val, Cnt&(1<<11)); break; + case 0x0200: + if (NDS::ConsoleType == 1) + DSi_SPI_TSC::Write(val, Cnt&(1<<11)); + else + SPI_TSC::Write(val, Cnt&(1<<11)); + break; default: printf("SPI to unknown device %04X %02X\n", Cnt, val); break; } diff --git a/src/SPU.cpp b/src/SPU.cpp index 959de12..9f6b107 100644 --- a/src/SPU.cpp +++ b/src/SPU.cpp @@ -155,6 +155,11 @@ Channel::~Channel() void Channel::Reset() { + if (NDS::ConsoleType == 1) + BusRead32 = DSi::ARM7Read32; + else + BusRead32 = NDS::ARM7Read32; + SetCnt(0); SrcAddr = 0; TimerReload = 0; @@ -217,8 +222,7 @@ void Channel::FIFO_BufferData() for (u32 i = 0; i < burstlen; i += 4) { - //FIFO[FIFOWritePos] = NDS::ARM7Read32(SrcAddr + FIFOReadOffset); - FIFO[FIFOWritePos] = DSi::ARM7Read32(SrcAddr + FIFOReadOffset); + FIFO[FIFOWritePos] = BusRead32(SrcAddr + FIFOReadOffset); FIFOReadOffset += 4; FIFOWritePos++; FIFOWritePos &= 0x7; @@ -466,6 +470,11 @@ CaptureUnit::~CaptureUnit() void CaptureUnit::Reset() { + if (NDS::ConsoleType == 1) + BusWrite32 = DSi::ARM7Write32; + else + BusWrite32 = NDS::ARM7Write32; + SetCnt(0); DstAddr = 0; TimerReload = 0; @@ -501,8 +510,7 @@ void CaptureUnit::FIFO_FlushData() { for (u32 i = 0; i < 4; i++) { - //NDS::ARM7Write32(DstAddr + FIFOWriteOffset, FIFO[FIFOReadPos]); - DSi::ARM7Write32(DstAddr + FIFOWriteOffset, FIFO[FIFOReadPos]); + BusWrite32(DstAddr + FIFOWriteOffset, FIFO[FIFOReadPos]); FIFOReadPos++; FIFOReadPos &= 0x3; diff --git a/src/SPU.h b/src/SPU.h index 74a4471..8ab17a0 100644 --- a/src/SPU.h +++ b/src/SPU.h @@ -142,6 +142,9 @@ public: } void PanOutput(s32* inbuf, u32 samples, s32* leftbuf, s32* rightbuf); + +private: + u32 (*BusRead32)(u32 addr); }; class CaptureUnit @@ -196,6 +199,9 @@ public: } void Run(s32 sample); + +private: + void (*BusWrite32)(u32 addr, u32 val); }; } diff --git a/src/frontend/FrontendUtil.h b/src/frontend/FrontendUtil.h index 6b83cbc..099583f 100644 --- a/src/frontend/FrontendUtil.h +++ b/src/frontend/FrontendUtil.h @@ -46,6 +46,15 @@ enum Load_FirmwareBad, Load_FirmwareNotBootable, + Load_DSiBIOS9Missing, + Load_DSiBIOS9Bad, + + Load_DSiBIOS7Missing, + Load_DSiBIOS7Bad, + + Load_DSiNANDMissing, + Load_DSiNANDBad, + // TODO: more precise errors for ROM loading Load_ROMLoadError, }; diff --git a/src/frontend/Util_ROM.cpp b/src/frontend/Util_ROM.cpp index d410550..8116a93 100644 --- a/src/frontend/Util_ROM.cpp +++ b/src/frontend/Util_ROM.cpp @@ -96,6 +96,42 @@ int VerifyDSBIOS() return Load_OK; } +int VerifyDSiBIOS() +{ + FILE* f; + long len; + + // TODO: check the first 32 bytes + + f = Platform::OpenLocalFile(Config::DSiBIOS9Path, "rb"); + if (!f) return Load_DSiBIOS9Missing; + + fseek(f, 0, SEEK_END); + len = ftell(f); + if (len != 0x10000) + { + fclose(f); + return Load_DSiBIOS9Bad; + } + + fclose(f); + + f = Platform::OpenLocalFile(Config::DSiBIOS7Path, "rb"); + if (!f) return Load_DSiBIOS7Missing; + + fseek(f, 0, SEEK_END); + len = ftell(f); + if (len != 0x10000) + { + fclose(f); + return Load_DSiBIOS7Bad; + } + + fclose(f); + + return Load_OK; +} + int VerifyDSFirmware() { FILE* f; @@ -110,7 +146,6 @@ int VerifyDSFirmware() { // 128KB firmware, not bootable fclose(f); - return Load_OK; // FIXME!!!! return Load_FirmwareNotBootable; } else if (len != 0x40000 && len != 0x80000) @@ -124,6 +159,45 @@ int VerifyDSFirmware() return Load_OK; } +int VerifyDSiFirmware() +{ + FILE* f; + long len; + + f = Platform::OpenLocalFile(Config::DSiFirmwarePath, "rb"); + if (!f) return Load_FirmwareMissing; + + fseek(f, 0, SEEK_END); + len = ftell(f); + if (len != 0x20000) + { + // not 128KB + // TODO: check whether those work + fclose(f); + return Load_FirmwareBad; + } + + fclose(f); + + return Load_OK; +} + +int VerifyDSiNAND() +{ + FILE* f; + long len; + + f = Platform::OpenLocalFile(Config::DSiNANDPath, "rb"); + if (!f) return Load_DSiNANDMissing; + + // TODO: some basic checks + // check that it has the nocash footer, and all + + fclose(f); + + return Load_OK; +} + int LoadBIOS() { int res; @@ -131,8 +205,22 @@ int LoadBIOS() res = VerifyDSBIOS(); if (res != Load_OK) return res; - res = VerifyDSFirmware(); - if (res != Load_OK) return res; + if (Config::ConsoleType == 1) + { + res = VerifyDSiBIOS(); + if (res != Load_OK) return res; + + res = VerifyDSiFirmware(); + if (res != Load_OK) return res; + + res = VerifyDSiNAND(); + if (res != Load_OK) return res; + } + else + { + res = VerifyDSFirmware(); + if (res != Load_OK) return res; + } // TODO: // original code in the libui frontend called NDS::LoadGBAROM() if needed @@ -142,6 +230,7 @@ int LoadBIOS() ROMPath[ROMSlot_NDS][0] = '\0'; SRAMPath[ROMSlot_NDS][0] = '\0'; + NDS::SetConsoleType(Config::ConsoleType); NDS::LoadBIOS(); SavestateLoaded = false; @@ -154,16 +243,39 @@ int LoadROM(const char* file, int slot) int res; bool directboot = Config::DirectBoot != 0; + if (Config::ConsoleType == 1 && slot == 1) + { + // cannot load a GBA ROM into a DSi + return Load_ROMLoadError; + } + res = VerifyDSBIOS(); if (res != Load_OK) return res; - res = VerifyDSFirmware(); - if (res != Load_OK) + if (Config::ConsoleType == 1) { - if (res == Load_FirmwareNotBootable) - directboot = true; - else - return res; + res = VerifyDSiBIOS(); + if (res != Load_OK) return res; + + res = VerifyDSiFirmware(); + if (res != Load_OK) return res; + + res = VerifyDSiNAND(); + if (res != Load_OK) return res; + + GBACart::Eject(); + ROMPath[ROMSlot_GBA][0] = '\0'; + } + else + { + res = VerifyDSFirmware(); + if (res != Load_OK) + { + if (res == Load_FirmwareNotBootable) + directboot = true; + else + return res; + } } char oldpath[1024]; @@ -177,6 +289,8 @@ int LoadROM(const char* file, int slot) SetupSRAMPath(0); SetupSRAMPath(1); + NDS::SetConsoleType(Config::ConsoleType); + if (slot == ROMSlot_NDS && NDS::LoadROM(ROMPath[slot], SRAMPath[slot], directboot)) { SavestateLoaded = false; @@ -225,17 +339,36 @@ int Reset() res = VerifyDSBIOS(); if (res != Load_OK) return res; - res = VerifyDSFirmware(); - if (res != Load_OK) + if (Config::ConsoleType == 1) { - if (res == Load_FirmwareNotBootable) - directboot = true; - else - return res; + res = VerifyDSiBIOS(); + if (res != Load_OK) return res; + + res = VerifyDSiFirmware(); + if (res != Load_OK) return res; + + res = VerifyDSiNAND(); + if (res != Load_OK) return res; + + GBACart::Eject(); + ROMPath[ROMSlot_GBA][0] = '\0'; + } + else + { + res = VerifyDSFirmware(); + if (res != Load_OK) + { + if (res == Load_FirmwareNotBootable) + directboot = true; + else + return res; + } } SavestateLoaded = false; + NDS::SetConsoleType(Config::ConsoleType); + if (ROMPath[ROMSlot_NDS][0] == '\0') { NDS::LoadBIOS(); diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.cpp b/src/frontend/qt_sdl/EmuSettingsDialog.cpp index 7760a88..09faf4e 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.cpp +++ b/src/frontend/qt_sdl/EmuSettingsDialog.cpp @@ -49,7 +49,7 @@ EmuSettingsDialog::EmuSettingsDialog(QWidget* parent) : QDialog(parent), ui(new ui->txtDSiNANDPath->setText(Config::DSiNANDPath); ui->cbxConsoleType->addItem("DS"); - ui->cbxConsoleType->addItem("DSi"); + ui->cbxConsoleType->addItem("DSi (experimental)"); ui->cbxConsoleType->setCurrentIndex(Config::ConsoleType); ui->chkDirectBoot->setChecked(Config::DirectBoot != 0); diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index ef21bc7..7b3d5cd 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -1360,17 +1360,40 @@ QString MainWindow::loadErrorStr(int error) { switch (error) { - case Frontend::Load_BIOS9Missing: return "DS ARM9 BIOS was not found or could not be accessed. Check your emu settings."; - case Frontend::Load_BIOS9Bad: return "DS ARM9 BIOS is not a valid BIOS dump."; - - case Frontend::Load_BIOS7Missing: return "DS ARM7 BIOS was not found or could not be accessed. Check your emu settings."; - case Frontend::Load_BIOS7Bad: return "DS ARM7 BIOS is not a valid BIOS dump."; - - case Frontend::Load_FirmwareMissing: return "DS firmware was not found or could not be accessed. Check your emu settings."; - case Frontend::Load_FirmwareBad: return "DS firmware is not a valid firmware dump."; - case Frontend::Load_FirmwareNotBootable: return "DS firmware is not bootable."; - - case Frontend::Load_ROMLoadError: return "Failed to load the ROM. Make sure the file is accessible and isn't used by another application."; + case Frontend::Load_BIOS9Missing: + return "DS ARM9 BIOS was not found or could not be accessed. Check your emu settings."; + case Frontend::Load_BIOS9Bad: + return "DS ARM9 BIOS is not a valid BIOS dump."; + + case Frontend::Load_BIOS7Missing: + return "DS ARM7 BIOS was not found or could not be accessed. Check your emu settings."; + case Frontend::Load_BIOS7Bad: + return "DS ARM7 BIOS is not a valid BIOS dump."; + + case Frontend::Load_FirmwareMissing: + return "DS firmware was not found or could not be accessed. Check your emu settings."; + case Frontend::Load_FirmwareBad: + return "DS firmware is not a valid firmware dump."; + case Frontend::Load_FirmwareNotBootable: + return "DS firmware is not bootable."; + + case Frontend::Load_DSiBIOS9Missing: + return "DSi ARM9 BIOS was not found or could not be accessed. Check your emu settings."; + case Frontend::Load_DSiBIOS9Bad: + return "DSi ARM9 BIOS is not a valid BIOS dump."; + + case Frontend::Load_DSiBIOS7Missing: + return "DSi ARM7 BIOS was not found or could not be accessed. Check your emu settings."; + case Frontend::Load_DSiBIOS7Bad: + return "DSi ARM7 BIOS is not a valid BIOS dump."; + + case Frontend::Load_DSiNANDMissing: + return "DSi NAND was not found or could not be accessed. Check your emu settings."; + case Frontend::Load_DSiNANDBad: + return "DSi NAND is not a valid NAND dump."; + + case Frontend::Load_ROMLoadError: + return "Failed to load the ROM. Make sure the file is accessible and isn't used by another application."; default: return "Unknown error during launch; smack Arisotura."; } -- cgit v1.2.3 From ee9fe327e2c1c5b9289540a710d4ad2ac04e65c8 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 1 Jun 2020 23:13:38 +0200 Subject: remove requirement for aeskeys.bin and boot2_7/9.bin --- src/DSi.cpp | 87 +++++++++++++++++++++++++++++++++------------------------ src/DSi_AES.cpp | 38 ++++++++++++------------- 2 files changed, 69 insertions(+), 56 deletions(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index 520b269..6a60f80 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -31,6 +31,8 @@ #include "DSi_SD.h" #include "DSi_AES.h" +#include "tiny-AES-c/aes.hpp" + namespace NDS { @@ -341,52 +343,65 @@ bool LoadNAND() MBK[0][8] = mbk[11]; MBK[1][8] = mbk[11]; - // load binaries - // TODO: optionally support loading from actual NAND? - // currently decrypted binaries have to be provided - // they can be decrypted with twltool + // load boot2 binaries - FILE* bin; + AES_ctx ctx; + const u8 boot2key[16] = {0xAD, 0x34, 0xEC, 0xF9, 0x62, 0x6E, 0xC2, 0x3A, 0xF6, 0xB4, 0x6C, 0x00, 0x80, 0x80, 0xEE, 0x98}; + u8 boot2iv[16]; + u8 tmp[16]; + u32 dstaddr; - bin = Platform::OpenLocalFile("boot2_9.bin", "rb"); - if (bin) - { - u32 dstaddr = bootparams[2]; - for (u32 i = 0; i < bootparams[1]; i += 4) - { - u32 _tmp; - fread(&_tmp, 4, 1, bin); - ARM9Write32(dstaddr, _tmp); - dstaddr += 4; - } + *(u32*)&tmp[0] = bootparams[3]; + *(u32*)&tmp[4] = -bootparams[3]; + *(u32*)&tmp[8] = ~bootparams[3]; + *(u32*)&tmp[12] = 0; + for (int i = 0; i < 16; i++) boot2iv[i] = tmp[15-i]; - fclose(bin); - } - else - { - printf("ARM9 boot2 not found\n"); - } + AES_init_ctx_iv(&ctx, boot2key, boot2iv); - bin = Platform::OpenLocalFile("boot2_7.bin", "rb"); - if (bin) + fseek(f, bootparams[0], SEEK_SET); + dstaddr = bootparams[2]; + for (u32 i = 0; i < bootparams[3]; i += 16) { - u32 dstaddr = bootparams[6]; - for (u32 i = 0; i < bootparams[5]; i += 4) - { - u32 _tmp; - fread(&_tmp, 4, 1, bin); - ARM7Write32(dstaddr, _tmp); - dstaddr += 4; - } + u8 data[16]; + fread(data, 16, 1, f); + + for (int j = 0; j < 16; j++) tmp[j] = data[15-j]; + AES_CTR_xcrypt_buffer(&ctx, tmp, 16); + for (int j = 0; j < 16; j++) data[j] = tmp[15-j]; - fclose(bin); + ARM9Write32(dstaddr, *(u32*)&data[0]); dstaddr += 4; + ARM9Write32(dstaddr, *(u32*)&data[4]); dstaddr += 4; + ARM9Write32(dstaddr, *(u32*)&data[8]); dstaddr += 4; + ARM9Write32(dstaddr, *(u32*)&data[12]); dstaddr += 4; } - else + + *(u32*)&tmp[0] = bootparams[7]; + *(u32*)&tmp[4] = -bootparams[7]; + *(u32*)&tmp[8] = ~bootparams[7]; + *(u32*)&tmp[12] = 0; + for (int i = 0; i < 16; i++) boot2iv[i] = tmp[15-i]; + + AES_init_ctx_iv(&ctx, boot2key, boot2iv); + + fseek(f, bootparams[4], SEEK_SET); + dstaddr = bootparams[6]; + for (u32 i = 0; i < bootparams[7]; i += 16) { - printf("ARM7 boot2 not found\n"); + u8 data[16]; + fread(data, 16, 1, f); + + for (int j = 0; j < 16; j++) tmp[j] = data[15-j]; + AES_CTR_xcrypt_buffer(&ctx, tmp, 16); + for (int j = 0; j < 16; j++) data[j] = tmp[15-j]; + + ARM7Write32(dstaddr, *(u32*)&data[0]); dstaddr += 4; + ARM7Write32(dstaddr, *(u32*)&data[4]); dstaddr += 4; + ARM7Write32(dstaddr, *(u32*)&data[8]); dstaddr += 4; + ARM7Write32(dstaddr, *(u32*)&data[12]); dstaddr += 4; } - // repoint CPUs to the boot2 binaries + // repoint the CPUs to the boot2 binaries BootAddr[0] = bootparams[2]; BootAddr[1] = bootparams[6]; diff --git a/src/DSi_AES.cpp b/src/DSi_AES.cpp index 4cb1169..6a8ffad 100644 --- a/src/DSi_AES.cpp +++ b/src/DSi_AES.cpp @@ -131,26 +131,24 @@ void Reset() // initialize keys - FILE* f = Platform::OpenLocalFile("aeskeys.bin", "rb"); - if (f) - { - fread(KeyNormal[0], 16, 1, f); - fread(KeyX[0], 16, 1, f); - fread(KeyY[0], 16, 1, f); - fread(KeyNormal[1], 16, 1, f); - fread(KeyX[1], 16, 1, f); - fread(KeyY[1], 16, 1, f); - fread(KeyNormal[2], 16, 1, f); - fread(KeyX[2], 16, 1, f); - fread(KeyY[2], 16, 1, f); - fread(KeyNormal[3], 16, 1, f); - fread(KeyX[3], 16, 1, f); - fread(KeyY[3], 16, 1, f); - - fclose(f); - } - else - printf("AES: aeskeys.bin not found\n"); + // slot 0: modcrypt + *(u32*)&KeyX[0][0] = 0x746E694E; + *(u32*)&KeyX[0][4] = 0x6F646E65; + + // slot 1: 'Tad'/dev.kp + *(u32*)&KeyX[1][0] = 0x4E00004A; + *(u32*)&KeyX[1][4] = 0x4A00004E; + *(u32*)&KeyX[1][8] = (u32)(DSi::ConsoleID >> 32) ^ 0xC80C4B72; + *(u32*)&KeyX[1][12] = (u32)DSi::ConsoleID; + + // slot 3: console-unique eMMC crypto + *(u32*)&KeyX[3][0] = (u32)DSi::ConsoleID; + *(u32*)&KeyX[3][4] = (u32)DSi::ConsoleID ^ 0x24EE6906; + *(u32*)&KeyX[3][8] = (u32)(DSi::ConsoleID >> 32) ^ 0xE65B601D; + *(u32*)&KeyX[3][12] = (u32)(DSi::ConsoleID >> 32); + *(u32*)&KeyY[3][0] = 0x0AB9DC76; + *(u32*)&KeyY[3][4] = 0xBD4DC4D3; + *(u32*)&KeyY[3][8] = 0x202DDD1D; } -- cgit v1.2.3 From d0af89924edf4e14a092e5352808f6a2ce44d53a Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 2 Jun 2020 00:25:29 +0200 Subject: remove requirement for initmem7/9.bin (but this requires augmented BIOS dumps, we'll get there) --- src/DSi.cpp | 46 +++++++++++++++------------------------------- src/DSi.h | 3 --- src/NDSCart.cpp | 11 ++--------- 3 files changed, 17 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index 6a60f80..701387a 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -129,9 +129,6 @@ void Reset() memcpy(NDS::ARM9->ITCM, ITCMInit, 0x8000); - for (u32 i = 0; i < 0x3C00; i+=4) - ARM7Write32(0x03FFC400+i, *(u32*)&ARM7Init[i]); - DSi_I2C::Reset(); DSi_AES::Reset(); @@ -151,6 +148,9 @@ void Reset() NDS::MapSharedWRAM(3); + for (u32 i = 0; i < 0x3C00; i+=4) + ARM7Write32(0x03FFC400+i, *(u32*)&ARM7Init[i]); + u32 eaddr = 0x03FFE6E4; ARM7Write32(eaddr+0x00, *(u32*)&eMMC_CID[0]); ARM7Write32(eaddr+0x04, *(u32*)&eMMC_CID[4]); @@ -178,9 +178,6 @@ void SoftReset() memcpy(NDS::ARM9->ITCM, ITCMInit, 0x8000); - for (u32 i = 0; i < 0x3C00; i+=4) - ARM7Write32(0x03FFC400+i, *(u32*)&ARM7Init[i]); - DSi_AES::Reset(); LoadNAND(); @@ -204,6 +201,9 @@ void SoftReset() NDS::MapSharedWRAM(3); + for (u32 i = 0; i < 0x3C00; i+=4) + ARM7Write32(0x03FFC400+i, *(u32*)&ARM7Init[i]); + u32 eaddr = 0x03FFE6E4; ARM7Write32(eaddr+0x00, *(u32*)&eMMC_CID[0]); ARM7Write32(eaddr+0x04, *(u32*)&eMMC_CID[4]); @@ -433,32 +433,16 @@ bool LoadNAND() } memset(ITCMInit, 0, 0x8000); - memset(ARM7Init, 0, 0x3C00); - - f = fopen("initmem9.bin", "rb"); - if (f) - { - // first 0x2524 bytes are loaded to 0x01FFC400 - - u32 dstaddr = 0x01FFC400; - fread(&ITCMInit[dstaddr & 0x7FFF], /*0x2524*/0x3C00, 1, f); - fclose(f); - } - else - { - printf("DSi ARM9 meminit not found\n"); - } + memcpy(&ITCMInit[0x4400], &ARM9iBIOS[0x87F4], 0x400); + memcpy(&ITCMInit[0x4800], &ARM9iBIOS[0x9920], 0x80); + memcpy(&ITCMInit[0x4894], &ARM9iBIOS[0x99A0], 0x1048); + memcpy(&ITCMInit[0x58DC], &ARM9iBIOS[0xA9E8], 0x1048); - f = fopen("initmem7.bin", "rb"); - if (f) - { - fread(ARM7Init, 0x3C00, 1, f); - fclose(f); - } - else - { - printf("DSi ARM7 meminit not found\n"); - } + memset(ARM7Init, 0, 0x3C00); + memcpy(&ARM7Init[0x0000], &ARM7iBIOS[0x8188], 0x200); + memcpy(&ARM7Init[0x0200], &ARM7iBIOS[0xB5D8], 0x40); + memcpy(&ARM7Init[0x0254], &ARM7iBIOS[0xC6D0], 0x1048); + memcpy(&ARM7Init[0x129C], &ARM7iBIOS[0xD718], 0x1048); return true; } diff --git a/src/DSi.h b/src/DSi.h index 08712de..8cc8fd5 100644 --- a/src/DSi.h +++ b/src/DSi.h @@ -34,9 +34,6 @@ extern u64 ConsoleID; extern DSi_SDHost* SDMMC; extern DSi_SDHost* SDIO; -extern u8 ITCMInit[0x8000]; -extern u8 ARM7Init[0x3C00]; - bool Init(); void DeInit(); diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index b326dd6..a5e0f41 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -562,17 +562,10 @@ void Key1_ApplyKeycode(u32* keycode, u32 mod) void Key1_InitKeycode(bool dsi, u32 idcode, u32 level, u32 mod) { // TODO: source the key data from different possible places - if (NDS::ConsoleType == 1) - { - if (dsi) - memcpy(Key1_KeyBuf, &DSi::ARM7Init[0x254], 0x1048); // hax - else - memcpy(Key1_KeyBuf, &DSi::ITCMInit[0x4894], 0x1048); // hax - } + if (dsi && NDS::ConsoleType==1) + memcpy(Key1_KeyBuf, &DSi::ARM7iBIOS[0xC6D0], 0x1048); // hax else - { memcpy(Key1_KeyBuf, &NDS::ARM7BIOS[0x30], 0x1048); // hax - } u32 keycode[3] = {idcode, idcode>>1, idcode<<1}; if (level >= 1) Key1_ApplyKeycode(keycode, mod); -- cgit v1.2.3 From d862b5869f492c4747c7dc668312ed03d38244f0 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 2 Jun 2020 00:30:04 +0200 Subject: allow .dsi files --- src/frontend/qt_sdl/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 7b3d5cd..fa542ad 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -1407,7 +1407,7 @@ void MainWindow::onOpenFile() QString filename = QFileDialog::getOpenFileName(this, "Open ROM", Config::LastROMFolder, - "DS ROMs (*.nds *.srl);;GBA ROMs (*.gba);;Any file (*.*)"); + "DS ROMs (*.nds *.dsi *.srl);;GBA ROMs (*.gba);;Any file (*.*)"); if (filename.isEmpty()) { emuThread->emuUnpause(); -- cgit v1.2.3 From ffa29ff4961ded1c1e2a93c2414c5e7061a4f905 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 2 Jun 2020 00:36:07 +0200 Subject: clean it up some --- src/DSi.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/DSi.cpp b/src/DSi.cpp index 701387a..216f724 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -702,8 +702,7 @@ void Set_SCFG_MC(u32 val) u8 ARM9Read8(u32 addr) -{if(addr==0x02FFC1B0) printf("ARM9 READ8 ROM REGION %08X\n", NDS::GetPC(0)); -if(addr==0x02FFFD70) printf("ARM9 READ8 CONSOLE REGION %08X\n", NDS::GetPC(0)); +{ if ((addr >= 0xFFFF0000) && (!(SCFG_BIOS & (1<<1)))) { if ((addr >= 0xFFFF8000) && (SCFG_BIOS & (1<<0))) @@ -740,7 +739,7 @@ if(addr==0x02FFFD70) printf("ARM9 READ8 CONSOLE REGION %08X\n", NDS::GetPC(0)); } u16 ARM9Read16(u32 addr) -{if(addr==0x02FFC1B0) printf("ARM9 READ16 ROM REGION %08X\n", NDS::GetPC(0)); +{ if ((addr >= 0xFFFF0000) && (!(SCFG_BIOS & (1<<1)))) { if ((addr >= 0xFFFF8000) && (SCFG_BIOS & (1<<0))) @@ -777,8 +776,7 @@ u16 ARM9Read16(u32 addr) } u32 ARM9Read32(u32 addr) -{if(addr==0x02FFC1B0) printf("ARM9 READ32 ROM REGION %08X\n", NDS::GetPC(0)); -if(addr==0x2FE71B0) return 0xFFFFFFFF; // hax: bypass region lock +{ if ((addr >= 0xFFFF0000) && (!(SCFG_BIOS & (1<<1)))) { if ((addr >= 0xFFFF8000) && (SCFG_BIOS & (1<<0))) @@ -789,6 +787,12 @@ if(addr==0x2FE71B0) return 0xFFFFFFFF; // hax: bypass region lock switch (addr & 0xFF000000) { + case 0x02000000: + // HACK to bypass region locking + // TODO: make optional + if (addr == 0x02FE71B0) return 0xFFFFFFFF; + break; + case 0x03000000: if (addr >= NWRAMStart[0][0] && addr < NWRAMEnd[0][0]) { @@ -951,8 +955,7 @@ bool ARM9GetMemRegion(u32 addr, bool write, NDS::MemRegion* region) u8 ARM7Read8(u32 addr) -{if(addr==0x02FFC1B0) printf("ARM7 READ8 ROM REGION %08X\n", NDS::GetPC(1)); -if(addr==0x02FFFD70) printf("ARM7 READ8 CONSOLE REGION %08X\n", NDS::GetPC(1)); +{ if ((addr < 0x00010000) && (!(SCFG_BIOS & (1<<9)))) { if ((addr >= 0x00008000) && (SCFG_BIOS & (1<<8))) @@ -993,7 +996,7 @@ if(addr==0x02FFFD70) printf("ARM7 READ8 CONSOLE REGION %08X\n", NDS::GetPC(1)); } u16 ARM7Read16(u32 addr) -{if(addr==0x02FFC1B0) printf("ARM7 READ16 ROM REGION %08X\n", NDS::GetPC(1)); +{ if ((addr < 0x00010000) && (!(SCFG_BIOS & (1<<9)))) { if ((addr >= 0x00008000) && (SCFG_BIOS & (1<<8))) @@ -1034,7 +1037,7 @@ u16 ARM7Read16(u32 addr) } u32 ARM7Read32(u32 addr) -{if(addr==0x02FFC1B0) printf("ARM7 READ32 ROM REGION %08X\n", NDS::GetPC(1)); +{ if ((addr < 0x00010000) && (!(SCFG_BIOS & (1<<9)))) { if ((addr >= 0x00008000) && (SCFG_BIOS & (1<<8))) @@ -1235,7 +1238,7 @@ u8 ARM9IORead8(u32 addr) return NDS::ARM9IORead8(addr); } -//u16 dicks = 0; + u16 ARM9IORead16(u32 addr) { switch (addr) @@ -1253,8 +1256,6 @@ u16 ARM9IORead16(u32 addr) CASE_READ16_32BIT(0x04004058, MBK[0][6]) CASE_READ16_32BIT(0x0400405C, MBK[0][7]) CASE_READ16_32BIT(0x04004060, MBK[0][8]) - - //case 0x04004202: return dicks & 0xEF1F; } return NDS::ARM9IORead16(addr); @@ -1399,8 +1400,6 @@ void ARM9IOWrite16(u32 addr, u16 val) MapNWRAM_C(6, val & 0xFF); MapNWRAM_C(7, val >> 8); return; - - //case 0x04004202: dicks = val & 0xEF3F; return; } return NDS::ARM9IOWrite16(addr, val); -- cgit v1.2.3 From 6c0ec5ebd8f991b6f8778afd98dc7a22f2b77d4d Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 2 Jun 2020 00:37:51 +0200 Subject: heh --- src/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/version.h b/src/version.h index 0045d2a..6250601 100644 --- a/src/version.h +++ b/src/version.h @@ -19,7 +19,7 @@ #ifndef VERSION_H #define VERSION_H -#define MELONDS_VERSION "0.8.3-DSi" +#define MELONDS_VERSION "0.8.3" #define MELONDS_URL "http://melonds.kuribo64.net/" -- cgit v1.2.3 From 1abcb4e6ac65e31a0d76d457524e9aeade8419ee Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 2 Jun 2020 14:36:15 +0200 Subject: I'm a major derp --- src/DSi_SD.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index 751c64f..7fdba0f 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -22,6 +22,7 @@ #include "DSi_SD.h" #include "DSi_NWifi.h" #include "Platform.h" +#include "Config.h" // observed IRQ behavior during transfers @@ -122,7 +123,7 @@ void DSi_SDHost::Reset() sd->SetCID(sd_cid);*/ DSi_MMCStorage* sd = NULL; - DSi_MMCStorage* mmc = new DSi_MMCStorage(this, true, "nand.bin"); + DSi_MMCStorage* mmc = new DSi_MMCStorage(this, true, Config::DSiNANDPath); mmc->SetCID(DSi::eMMC_CID); Ports[0] = sd; -- cgit v1.2.3 From 6e0425d34e9bcdff5f93258e2127c95ebae0ea59 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 3 Jun 2020 14:40:50 +0200 Subject: Add missing threads dependency --- src/frontend/qt_sdl/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index 1559cd4..2ebef96 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -44,6 +44,7 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTORCC ON) +find_package(Threads REQUIRED) find_package(PkgConfig REQUIRED) pkg_check_modules(SDL2 REQUIRED sdl2) @@ -53,6 +54,8 @@ else() add_executable(melonDS ${SOURCES_QT_SDL}) endif() +target_link_libraries(melonDS ${CMAKE_THREAD_LIBS_INIT}) + target_include_directories(melonDS PRIVATE ${SDL2_INCLUDE_DIRS}) target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..") -- cgit v1.2.3 From 7829070b7ff2bb86e2bc47065a57147757510b76 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 3 Jun 2020 14:41:07 +0200 Subject: Handle r+ file mode --- src/frontend/qt_sdl/Platform.cpp | 40 ++++++++-------------------------------- 1 file changed, 8 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index 47befb0..e56e527 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -133,7 +133,14 @@ FILE* OpenFile(const char* path, const char* mode, bool mustexist) return nullptr; } - QIODevice::OpenMode qmode = mode[0] == 'w' ? QIODevice::ReadWrite : QIODevice::ReadOnly; + QIODevice::OpenMode qmode; + if (strlen(mode) > 1 && mode[0] == 'r' && mode[1] == '+') { + qmode = QIODevice::OpenModeFlag::ReadWrite; + } else if (mode[0] == 'w') { + qmode = QIODevice::OpenModeFlag::Truncate; + } else { + qmode = QIODevice::OpenModeFlag::ReadOnly; + } f.open(qmode); FILE* file = fdopen(dup(f.handle()), mode); @@ -167,37 +174,6 @@ FILE* OpenLocalFile(const char* path, const char* mode) return OpenFile(fullpath.toUtf8(), mode, mode[0] != 'w'); } -FILE* OpenDataFile(const char* path) -{ -#ifdef PORTABLE - return OpenLocalFile(path); -#else - QString melondir = "/melonDS/"; - QStringList sys_dirs = QStandardPaths::standardLocations(QStandardPaths::DataLocation); - QString found = nullptr; - - for (int i = 0; i < sys_dirs.size(); i++) - { - QString f = sys_dirs.at(i) + melondir + path; - - if (QFile::exists(f)) - { - found = f; - break; - } - } - - if (found == nullptr) - return nullptr; - - FILE* f = OpenFile(found.toUtf8(), "rb", false); - if (f) - return f; - - return nullptr; -#endif -} - void* Thread_Create(void (* func)()) { QThread* t = QThread::create(func); -- cgit v1.2.3 From 21f1856da2cd218b6b6b10634f11f053ac1adfdf Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 3 Jun 2020 14:54:36 +0200 Subject: Fix indentation --- src/frontend/qt_sdl/CMakeLists.txt | 90 ++++++++--------- src/frontend/qt_sdl/Platform.cpp | 202 ++++++++++++++++++------------------- 2 files changed, 146 insertions(+), 146 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index 2ebef96..ea7849f 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -1,41 +1,41 @@ project(qt_sdl) SET(SOURCES_QT_SDL - main.cpp - main_shaders.h - EmuSettingsDialog.cpp - InputConfigDialog.cpp - VideoSettingsDialog.cpp - AudioSettingsDialog.cpp - WifiSettingsDialog.cpp - Input.cpp - LAN_PCap.cpp - LAN_Socket.cpp - OSD.cpp - OSD_shaders.h - font.h - Platform.cpp - PlatformConfig.cpp - - ../Util_ROM.cpp - ../Util_Video.cpp - ../Util_Audio.cpp - ../FrontendUtil.h - ../mic_blow.h - - ../../../melon.qrc + main.cpp + main_shaders.h + EmuSettingsDialog.cpp + InputConfigDialog.cpp + VideoSettingsDialog.cpp + AudioSettingsDialog.cpp + WifiSettingsDialog.cpp + Input.cpp + LAN_PCap.cpp + LAN_Socket.cpp + OSD.cpp + OSD_shaders.h + font.h + Platform.cpp + PlatformConfig.cpp + + ../Util_ROM.cpp + ../Util_Video.cpp + ../Util_Audio.cpp + ../FrontendUtil.h + ../mic_blow.h + + ../../../melon.qrc ) if (WIN32) - set(CMAKE_RC_COMPILE_OBJECT " -i -o ") + set(CMAKE_RC_COMPILE_OBJECT " -i -o ") endif() if (BUILD_STATIC AND QT5_STATIC_DIR) - set(QT5_STATIC_BASE ${QT5_STATIC_DIR}/lib/cmake/Qt5) - set(Qt5_DIR ${QT5_STATIC_BASE}) - set(Qt5Core_DIR ${QT5_STATIC_BASE}Core) - set(Qt5Gui_DIR ${QT5_STATIC_BASE}Gui) - set(Qt5Widgets_DIR ${QT5_STATIC_BASE}Widgets) + set(QT5_STATIC_BASE ${QT5_STATIC_DIR}/lib/cmake/Qt5) + set(Qt5_DIR ${QT5_STATIC_BASE}) + set(Qt5Core_DIR ${QT5_STATIC_BASE}Core) + set(Qt5Gui_DIR ${QT5_STATIC_BASE}Gui) + set(Qt5Widgets_DIR ${QT5_STATIC_BASE}Widgets) endif() find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED) @@ -49,9 +49,9 @@ find_package(PkgConfig REQUIRED) pkg_check_modules(SDL2 REQUIRED sdl2) if (WIN32 AND (CMAKE_BUILD_TYPE STREQUAL Release)) - add_executable(melonDS WIN32 ${SOURCES_QT_SDL}) + add_executable(melonDS WIN32 ${SOURCES_QT_SDL}) else() - add_executable(melonDS ${SOURCES_QT_SDL}) + add_executable(melonDS ${SOURCES_QT_SDL}) endif() target_link_libraries(melonDS ${CMAKE_THREAD_LIBS_INIT}) @@ -63,28 +63,28 @@ target_include_directories(melonDS PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../..") target_link_libraries(melonDS core) if (BUILD_STATIC) - target_link_libraries(melonDS -static ${SDL2_LIBRARIES}) + target_link_libraries(melonDS -static ${SDL2_LIBRARIES}) else() - target_link_libraries(melonDS ${SDL2_LIBRARIES}) + target_link_libraries(melonDS ${SDL2_LIBRARIES}) endif() if (UNIX) - option(PORTABLE "Make a portable build that looks for its configuration in the current directory" OFF) - target_link_libraries(melonDS dl Qt5::Core Qt5::Gui Qt5::Widgets) + option(PORTABLE "Make a portable build that looks for its configuration in the current directory" OFF) + target_link_libraries(melonDS dl Qt5::Core Qt5::Gui Qt5::Widgets) elseif (WIN32) - option(PORTABLE "Make a portable build that looks for its configuration in the current directory" ON) - target_sources(melonDS PUBLIC "${CMAKE_SOURCE_DIR}/melon.rc") - - target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32) - if (BUILD_STATIC) - target_link_libraries(melonDS imm32 winmm version setupapi -static Qt5::Core Qt5::Gui Qt5::Widgets z zstd) - else() - target_link_libraries(melonDS Qt5::Core Qt5::Gui Qt5::Widgets) - endif() + option(PORTABLE "Make a portable build that looks for its configuration in the current directory" ON) + target_sources(melonDS PUBLIC "${CMAKE_SOURCE_DIR}/melon.rc") + + target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32) + if (BUILD_STATIC) + target_link_libraries(melonDS imm32 winmm version setupapi -static Qt5::Core Qt5::Gui Qt5::Widgets z zstd) + else() + target_link_libraries(melonDS Qt5::Core Qt5::Gui Qt5::Widgets) + endif() endif() if (PORTABLE) - add_definitions(-DPORTABLE) + add_definitions(-DPORTABLE) endif() install(FILES ../../../net.kuribo64.melonDS.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index e56e527..fdb7d6d 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -32,7 +32,7 @@ #include #ifdef __WIN32__ -#define NTDDI_VERSION 0x06000000 // GROSS FUCKING HACK +#define NTDDI_VERSION 0x06000000 // GROSS FUCKING HACK #include //#include // FUCK THAT SHIT #include @@ -104,11 +104,11 @@ void Init(int argc, char** argv) } #else QString confdir; - QDir config(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)); - config.mkdir("melonDS"); - confdir = config.absolutePath() + "/melonDS/"; - EmuDirectory = new char[confdir.length() + 1]; - memcpy(EmuDirectory, confdir.toUtf8().data(), confdir.length()); + QDir config(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)); + config.mkdir("melonDS"); + confdir = config.absolutePath() + "/melonDS/"; + EmuDirectory = new char[confdir.length() + 1]; + memcpy(EmuDirectory, confdir.toUtf8().data(), confdir.length()); #endif } @@ -126,99 +126,99 @@ void StopEmu() FILE* OpenFile(const char* path, const char* mode, bool mustexist) { - QFile f(path); - - if (mustexist && !f.exists()) - { - return nullptr; - } - - QIODevice::OpenMode qmode; - if (strlen(mode) > 1 && mode[0] == 'r' && mode[1] == '+') { - qmode = QIODevice::OpenModeFlag::ReadWrite; - } else if (mode[0] == 'w') { - qmode = QIODevice::OpenModeFlag::Truncate; - } else { - qmode = QIODevice::OpenModeFlag::ReadOnly; - } - - f.open(qmode); - FILE* file = fdopen(dup(f.handle()), mode); - f.close(); - - return file; + QFile f(path); + + if (mustexist && !f.exists()) + { + return nullptr; + } + + QIODevice::OpenMode qmode; + if (strlen(mode) > 1 && mode[0] == 'r' && mode[1] == '+') { + qmode = QIODevice::OpenModeFlag::ReadWrite; + } else if (mode[0] == 'w') { + qmode = QIODevice::OpenModeFlag::Truncate; + } else { + qmode = QIODevice::OpenModeFlag::ReadOnly; + } + + f.open(qmode); + FILE* file = fdopen(dup(f.handle()), mode); + f.close(); + + return file; } FILE* OpenLocalFile(const char* path, const char* mode) { - QString fullpath; - - if (path[0] == '/') - { - // If it's an absolute path, just open that. - fullpath = path; - } - else - { + QString fullpath; + + if (path[0] == '/') + { + // If it's an absolute path, just open that. + fullpath = path; + } + else + { #ifdef PORTABLE - fullpath = QString("./") + path; + fullpath = QString("./") + path; #else - // Check user configuration directory - QDir config(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)); - config.mkdir("melonDS"); - fullpath = config.absolutePath() + "/melonDS/"; - fullpath.append(path); + // Check user configuration directory + QDir config(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)); + config.mkdir("melonDS"); + fullpath = config.absolutePath() + "/melonDS/"; + fullpath.append(path); #endif - } + } - return OpenFile(fullpath.toUtf8(), mode, mode[0] != 'w'); + return OpenFile(fullpath.toUtf8(), mode, mode[0] != 'w'); } void* Thread_Create(void (* func)()) { - QThread* t = QThread::create(func); - t->start(); - return (void*) t; + QThread* t = QThread::create(func); + t->start(); + return (void*) t; } void Thread_Free(void* thread) { - QThread* t = (QThread*) thread; - t->terminate(); - delete t; + QThread* t = (QThread*) thread; + t->terminate(); + delete t; } void Thread_Wait(void* thread) { - ((QThread*) thread)->wait(); + ((QThread*) thread)->wait(); } void* Semaphore_Create() { - return new QSemaphore(); + return new QSemaphore(); } void Semaphore_Free(void* sema) { - delete (QSemaphore*) sema; + delete (QSemaphore*) sema; } void Semaphore_Reset(void* sema) { - QSemaphore* s = (QSemaphore*) sema; + QSemaphore* s = (QSemaphore*) sema; - s->acquire(s->available()); + s->acquire(s->available()); } void Semaphore_Wait(void* sema) { - ((QSemaphore*) sema)->acquire(); + ((QSemaphore*) sema)->acquire(); } void Semaphore_Post(void* sema) { - ((QSemaphore*) sema)->release(); + ((QSemaphore*) sema)->release(); } @@ -242,44 +242,44 @@ bool MP_Init() #endif // __WIN32__ MPSocket = socket(AF_INET, SOCK_DGRAM, 0); - if (MPSocket < 0) - { - return false; - } - - res = setsockopt(MPSocket, SOL_SOCKET, SO_REUSEADDR, (const char*)&opt_true, sizeof(int)); - if (res < 0) - { - closesocket(MPSocket); - MPSocket = INVALID_SOCKET; - return false; - } - - sockaddr_t saddr; - saddr.sa_family = AF_INET; - *(u32*)&saddr.sa_data[2] = htonl(Config::SocketBindAnyAddr ? INADDR_ANY : INADDR_LOOPBACK); - *(u16*)&saddr.sa_data[0] = htons(7064); - res = bind(MPSocket, &saddr, sizeof(sockaddr_t)); - if (res < 0) - { - closesocket(MPSocket); - MPSocket = INVALID_SOCKET; - return false; - } - - res = setsockopt(MPSocket, SOL_SOCKET, SO_BROADCAST, (const char*)&opt_true, sizeof(int)); - if (res < 0) - { - closesocket(MPSocket); - MPSocket = INVALID_SOCKET; - return false; - } - - MPSendAddr.sa_family = AF_INET; - *(u32*)&MPSendAddr.sa_data[2] = htonl(INADDR_BROADCAST); - *(u16*)&MPSendAddr.sa_data[0] = htons(7064); - - return true; + if (MPSocket < 0) + { + return false; + } + + res = setsockopt(MPSocket, SOL_SOCKET, SO_REUSEADDR, (const char*)&opt_true, sizeof(int)); + if (res < 0) + { + closesocket(MPSocket); + MPSocket = INVALID_SOCKET; + return false; + } + + sockaddr_t saddr; + saddr.sa_family = AF_INET; + *(u32*)&saddr.sa_data[2] = htonl(Config::SocketBindAnyAddr ? INADDR_ANY : INADDR_LOOPBACK); + *(u16*)&saddr.sa_data[0] = htons(7064); + res = bind(MPSocket, &saddr, sizeof(sockaddr_t)); + if (res < 0) + { + closesocket(MPSocket); + MPSocket = INVALID_SOCKET; + return false; + } + + res = setsockopt(MPSocket, SOL_SOCKET, SO_BROADCAST, (const char*)&opt_true, sizeof(int)); + if (res < 0) + { + closesocket(MPSocket); + MPSocket = INVALID_SOCKET; + return false; + } + + MPSendAddr.sa_family = AF_INET; + *(u32*)&MPSendAddr.sa_data[2] = htonl(INADDR_BROADCAST); + *(u16*)&MPSendAddr.sa_data[0] = htons(7064); + + return true; } void MP_DeInit() @@ -320,14 +320,14 @@ int MP_RecvPacket(u8* data, bool block) return 0; fd_set fd; - struct timeval tv; + struct timeval tv; - FD_ZERO(&fd); - FD_SET(MPSocket, &fd); - tv.tv_sec = 0; - tv.tv_usec = block ? 5000 : 0; + FD_ZERO(&fd); + FD_SET(MPSocket, &fd); + tv.tv_sec = 0; + tv.tv_usec = block ? 5000 : 0; - if (!select(MPSocket+1, &fd, 0, 0, &tv)) + if (!select(MPSocket+1, &fd, 0, 0, &tv)) { return 0; } -- cgit v1.2.3 From 23aeb5fb72069634ff3c926f778511bf4f6b1578 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 3 Jun 2020 16:38:26 +0200 Subject: Fix _dup on windows --- src/frontend/qt_sdl/Platform.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index fdb7d6d..7621931 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -38,6 +38,8 @@ #include #include #include +#include +#define dup _dup #define socket_t SOCKET #define sockaddr_t SOCKADDR #else -- cgit v1.2.3 From f9644abb67035efefcc31a894ccdd5253fd4311c Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 3 Jun 2020 16:41:34 +0200 Subject: Handle open flags more correctly --- src/frontend/qt_sdl/Platform.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index 7621931..5199254 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -137,9 +137,11 @@ FILE* OpenFile(const char* path, const char* mode, bool mustexist) QIODevice::OpenMode qmode; if (strlen(mode) > 1 && mode[0] == 'r' && mode[1] == '+') { - qmode = QIODevice::OpenModeFlag::ReadWrite; - } else if (mode[0] == 'w') { - qmode = QIODevice::OpenModeFlag::Truncate; + qmode = QIODevice::OpenModeFlag::ReadWrite; + } else if (strlen(mode) > 1 && mode[0] == 'w' && mode[1] == '+') { + qmode = QIODevice::OpenModeFlag::Truncate | QIODevice::OpenModeFlag::ReadWrite; + } else if (mode[0] == 'w') { + qmode = QIODevice::OpenModeFlag::Truncate | QIODevice::OpenModeFlag::WriteOnly; } else { qmode = QIODevice::OpenModeFlag::ReadOnly; } -- cgit v1.2.3 From a4b88f0294c1d051dba55887d70835a518fa16b4 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 3 Jun 2020 16:49:58 +0200 Subject: Fix paths on Windows --- src/frontend/qt_sdl/Platform.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index 5199254..671fdee 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -155,9 +155,10 @@ FILE* OpenFile(const char* path, const char* mode, bool mustexist) FILE* OpenLocalFile(const char* path, const char* mode) { + QDir dir(path); QString fullpath; - if (path[0] == '/') + if (dir.isAbsolute()) { // If it's an absolute path, just open that. fullpath = path; @@ -165,7 +166,7 @@ FILE* OpenLocalFile(const char* path, const char* mode) else { #ifdef PORTABLE - fullpath = QString("./") + path; + fullpath = path; #else // Check user configuration directory QDir config(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)); -- cgit v1.2.3 From 924975f6db7acc419f3ed1758fc5705ea1b13aea Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 3 Jun 2020 17:01:10 +0200 Subject: Use GenericConfigLocation so files will be placed correctly in non-portable Windows builds --- src/frontend/qt_sdl/Platform.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index 671fdee..43f358f 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -169,7 +169,7 @@ FILE* OpenLocalFile(const char* path, const char* mode) fullpath = path; #else // Check user configuration directory - QDir config(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)); + QDir config(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)); config.mkdir("melonDS"); fullpath = config.absolutePath() + "/melonDS/"; fullpath.append(path); -- cgit v1.2.3 From aa6ff499f98dfbb5ca9aa8cac27fed813684eb45 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Fri, 9 Aug 2019 14:19:13 +0200 Subject: prepare JIT beta branch --- src/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/version.h b/src/version.h index 6250601..9084606 100644 --- a/src/version.h +++ b/src/version.h @@ -19,7 +19,7 @@ #ifndef VERSION_H #define VERSION_H -#define MELONDS_VERSION "0.8.3" +#define MELONDS_VERSION "0.8.3-JIT" #define MELONDS_URL "http://melonds.kuribo64.net/" -- cgit v1.2.3 From c692287ebab4dfdec16bb0a8ce338a4b6fe2d439 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sat, 22 Jun 2019 01:28:32 +0200 Subject: JIT: base all instructions are interpreted --- src/ARM.cpp | 13 +- src/ARMJIT.cpp | 177 ++ src/ARMJIT.h | 140 ++ src/ARMJIT_x64/ARMJIT_Compiler.cpp | 332 ++++ src/ARMJIT_x64/ARMJIT_Compiler.h | 54 + src/ARM_InstrInfo.cpp | 376 ++++ src/ARM_InstrInfo.h | 232 +++ src/CMakeLists.txt | 12 + src/CP15.cpp | 7 + src/NDS.cpp | 17 + src/dolphin/Assert.h | 47 + src/dolphin/BitSet.h | 218 +++ src/dolphin/CPUDetect.h | 76 + src/dolphin/CodeBlock.h | 121 ++ src/dolphin/CommonFuncs.cpp | 52 + src/dolphin/CommonFuncs.h | 58 + src/dolphin/Intrinsics.h | 72 + src/dolphin/Log.h | 20 + src/dolphin/MemoryUtil.cpp | 193 ++ src/dolphin/MemoryUtil.h | 22 + src/dolphin/license_dolphin.txt | 339 ++++ src/dolphin/x64ABI.cpp | 119 ++ src/dolphin/x64ABI.h | 57 + src/dolphin/x64CPUDetect.cpp | 274 +++ src/dolphin/x64Emitter.cpp | 3398 ++++++++++++++++++++++++++++++++++++ src/dolphin/x64Emitter.h | 1180 +++++++++++++ src/dolphin/x64Reg.h | 96 + 27 files changed, 7700 insertions(+), 2 deletions(-) create mode 100644 src/ARMJIT.cpp create mode 100644 src/ARMJIT.h create mode 100644 src/ARMJIT_x64/ARMJIT_Compiler.cpp create mode 100644 src/ARMJIT_x64/ARMJIT_Compiler.h create mode 100644 src/ARM_InstrInfo.cpp create mode 100644 src/ARM_InstrInfo.h create mode 100644 src/dolphin/Assert.h create mode 100644 src/dolphin/BitSet.h create mode 100644 src/dolphin/CPUDetect.h create mode 100644 src/dolphin/CodeBlock.h create mode 100644 src/dolphin/CommonFuncs.cpp create mode 100644 src/dolphin/CommonFuncs.h create mode 100644 src/dolphin/Intrinsics.h create mode 100644 src/dolphin/Log.h create mode 100644 src/dolphin/MemoryUtil.cpp create mode 100644 src/dolphin/MemoryUtil.h create mode 100644 src/dolphin/license_dolphin.txt create mode 100644 src/dolphin/x64ABI.cpp create mode 100644 src/dolphin/x64ABI.h create mode 100644 src/dolphin/x64CPUDetect.cpp create mode 100644 src/dolphin/x64Emitter.cpp create mode 100644 src/dolphin/x64Emitter.h create mode 100644 src/dolphin/x64Reg.h (limited to 'src') diff --git a/src/ARM.cpp b/src/ARM.cpp index 68cac59..f2b92b4 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -22,6 +22,7 @@ #include "ARM.h" #include "ARMInterpreter.h" #include "AREngine.h" +#include "ARMJIT.h" // instruction timing notes @@ -524,7 +525,7 @@ void ARMv5::Execute() while (NDS::ARM9Timestamp < NDS::ARM9Target) { - if (CPSR & 0x20) // THUMB + /*if (CPSR & 0x20) // THUMB { // prefetch R[15] += 2; @@ -557,7 +558,15 @@ void ARMv5::Execute() } else AddCycles_C(); - } + }*/ + + if (!ARMJIT::IsMapped(Num, R[15] - ((CPSR&0x20)?2:4))) + printf("aaarg ungempappter raum %x\n", R[15]); + + ARMJIT::CompiledBlock block = ARMJIT::LookUpBlock(Num, R[15] - ((CPSR&0x20)?2:4)); + if (block == NULL) + block = ARMJIT::CompileBlock(this); + Cycles += block(); // TODO optimize this shit!!! if (Halted) diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp new file mode 100644 index 0000000..489cdcf --- /dev/null +++ b/src/ARMJIT.cpp @@ -0,0 +1,177 @@ +#include "ARMJIT.h" + +#include "ARMJIT_x64/ARMJIT_Compiler.h" + +namespace ARMJIT +{ + +Compiler* compiler; +BlockCache cache; + + +#define DUP2(x) x, x + +static ptrdiff_t JIT_MEM[2][32] = { + //arm9 + { + /* 0X*/ DUP2(offsetof(BlockCache, ARM9_ITCM)), + /* 1X*/ DUP2(offsetof(BlockCache, ARM9_ITCM)), // mirror + /* 2X*/ DUP2(offsetof(BlockCache, MainRAM)), + /* 3X*/ DUP2(offsetof(BlockCache, SWRAM)), + /* 4X*/ DUP2(-1), + /* 5X*/ DUP2(-1), + /* 6X*/ -1, + offsetof(BlockCache, ARM9_LCDC), // Plain ARM9-CPU Access (LCDC mode) (max 656KB) + /* 7X*/ DUP2(-1), + /* 8X*/ DUP2(-1), + /* 9X*/ DUP2(-1), + /* AX*/ DUP2(-1), + /* BX*/ DUP2(-1), + /* CX*/ DUP2(-1), + /* DX*/ DUP2(-1), + /* EX*/ DUP2(-1), + /* FX*/ DUP2(offsetof(BlockCache, ARM9_BIOS)) + }, + //arm7 + { + /* 0X*/ DUP2(offsetof(BlockCache, ARM7_BIOS)), + /* 1X*/ DUP2(-1), + /* 2X*/ DUP2(offsetof(BlockCache, MainRAM)), + /* 3X*/ offsetof(BlockCache, SWRAM), + offsetof(BlockCache, ARM7_WRAM), + /* 4X*/ -1, + offsetof(BlockCache, ARM7_WIRAM), + /* 5X*/ DUP2(-1), + /* 6X*/ DUP2(offsetof(BlockCache, ARM7_WVRAM)), /* contrary to Gbatek, melonDS and itself, + DeSmuME doesn't mirror the 64 MB region at 0x6800000 */ + /* 7X*/ DUP2(-1), + /* 8X*/ DUP2(-1), + /* 9X*/ DUP2(-1), + /* AX*/ DUP2(-1), + /* BX*/ DUP2(-1), + /* CX*/ DUP2(-1), + /* DX*/ DUP2(-1), + /* EX*/ DUP2(-1), + /* FX*/ DUP2(-1) + } +}; + +static u32 JIT_MASK[2][32] = { + //arm9 + { + /* 0X*/ DUP2(0x00007FFF), + /* 1X*/ DUP2(0x00007FFF), + /* 2X*/ DUP2(0x003FFFFF), + /* 3X*/ DUP2(0x00007FFF), + /* 4X*/ DUP2(0x00000000), + /* 5X*/ DUP2(0x00000000), + /* 6X*/ 0x00000000, + 0x000FFFFF, + /* 7X*/ DUP2(0x00000000), + /* 8X*/ DUP2(0x00000000), + /* 9X*/ DUP2(0x00000000), + /* AX*/ DUP2(0x00000000), + /* BX*/ DUP2(0x00000000), + /* CX*/ DUP2(0x00000000), + /* DX*/ DUP2(0x00000000), + /* EX*/ DUP2(0x00000000), + /* FX*/ DUP2(0x00007FFF) + }, + //arm7 + { + /* 0X*/ DUP2(0x00003FFF), + /* 1X*/ DUP2(0x00000000), + /* 2X*/ DUP2(0x003FFFFF), + /* 3X*/ 0x00007FFF, + 0x0000FFFF, + /* 4X*/ 0x00000000, + 0x0000FFFF, + /* 5X*/ DUP2(0x00000000), + /* 6X*/ DUP2(0x0003FFFF), + /* 7X*/ DUP2(0x00000000), + /* 8X*/ DUP2(0x00000000), + /* 9X*/ DUP2(0x00000000), + /* AX*/ DUP2(0x00000000), + /* BX*/ DUP2(0x00000000), + /* CX*/ DUP2(0x00000000), + /* DX*/ DUP2(0x00000000), + /* EX*/ DUP2(0x00000000), + /* FX*/ DUP2(0x00000000) + } +}; + +#undef DUP2 + + +void Init() +{ + memset(&cache, 0, sizeof(BlockCache)); + + for (int cpu = 0; cpu < 2; cpu++) + for (int i = 0; i < 0x4000; i++) + cache.AddrMapping[cpu][i] = JIT_MEM[cpu][i >> 9] == -1 ? NULL : + (CompiledBlock*)((u8*)&cache + JIT_MEM[cpu][i >> 9]) + + (((i << 14) & JIT_MASK[cpu][i >> 9]) >> 1); + + compiler = new Compiler(); +} + +void DeInit() +{ + delete compiler; +} + +CompiledBlock CompileBlock(ARM* cpu) +{ + bool thumb = cpu->CPSR & 0x20; + + FetchedInstr instrs[12]; + int i = 0; + u32 r15 = cpu->R[15]; + u32 nextInstr[2] = {cpu->NextInstr[0], cpu->NextInstr[1]}; + //printf("block %x %d\n", r15, thumb); + do + { + r15 += thumb ? 2 : 4; + + instrs[i].Instr = nextInstr[0]; + //printf("%x %x\n", instrs[i].Instr, r15); + instrs[i].NextInstr[0] = nextInstr[0] = nextInstr[1]; + + if (cpu->Num == 0) + { + ARMv5* cpuv5 = (ARMv5*)cpu; + if (thumb && r15 & 0x2) + { + nextInstr[1] >>= 16; + instrs[i].CodeCycles = 0; + } + else + { + nextInstr[1] = cpuv5->CodeRead32(r15, false); + instrs[i].CodeCycles = cpu->CodeCycles; + } + } + else + { + ARMv4* cpuv4 = (ARMv4*)cpu; + if (thumb) + nextInstr[1] = cpuv4->CodeRead16(r15); + else + nextInstr[1] = cpuv4->CodeRead32(r15); + instrs[i].CodeCycles = cpu->CodeCycles; + } + instrs[i].NextInstr[1] = nextInstr[1]; + instrs[i].Info = ARMInstrInfo::Decode(thumb, cpu->Num, instrs[i].Instr); + + i++; + } while(!instrs[i - 1].Info.Branches() && i < 10); + + CompiledBlock block = compiler->CompileBlock(cpu, instrs, i); + + InsertBlock(cpu->Num, cpu->R[15] - (thumb ? 2 : 4), block); + + return block; +} + +} \ No newline at end of file diff --git a/src/ARMJIT.h b/src/ARMJIT.h new file mode 100644 index 0000000..d718295 --- /dev/null +++ b/src/ARMJIT.h @@ -0,0 +1,140 @@ +#ifndef ARMJIT_H +#define ARMJIT_H + +#include "types.h" + +#include + +#include "ARM.h" +#include "ARM_InstrInfo.h" + +namespace ARMJIT +{ + +typedef u32 (*CompiledBlock)(); + +class RegCache +{ + +static const int NativeRegAllocOrder[]; +static const int NativeRegsCount; + +}; + +struct FetchedInstr +{ + u32 A_Reg(int pos) const + { + return (Instr >> pos) & 0xF; + } + + u32 T_Reg(int pos) const + { + return (Instr >> pos) & 0x7; + } + + u32 Cond() const + { + return Instr >> 28; + } + + u32 Instr; + u32 NextInstr[2]; + + u8 CodeCycles; + + ARMInstrInfo::Info Info; +}; + +/* + Copied from DeSmuME + Some names where changed to match the nomenclature of melonDS + + Since it's nowhere explained and atleast I needed some time to get behind it, + here's a summary on how it works: + more or less all memory locations from which code can be executed are + represented by an array of function pointers, which point to null or + a function which executes a block instructions starting from there. + + The most significant 4 bits of each address is ignored. This 28 bit space is + divided into 0x4000 16 KB blocks, each of which a pointer to the relevant + place inside the before mentioned arrays. Only half of the bytes need to be + addressed (ARM address are aligned to 4, Thumb addresses to a 2 byte boundary). + + In case a memory write hits mapped memory, the function block at this + address is set to null, so it's recompiled the next time it's executed. + + This method has disadvantages, namely that only writing to the + first instruction of a block marks it as invalid and that memory remapping + (SWRAM and VRAM) isn't taken into account. +*/ + +struct BlockCache +{ + CompiledBlock* AddrMapping[2][0x4000] = {0}; + + CompiledBlock MainRAM[16*1024*1024/2]; + CompiledBlock SWRAM[0x8000/2]; // Shared working RAM + CompiledBlock ARM9_ITCM[0x8000/2]; + CompiledBlock ARM9_LCDC[0xA4000/2]; + CompiledBlock ARM9_BIOS[0x8000/2]; + CompiledBlock ARM7_BIOS[0x4000/2]; + CompiledBlock ARM7_WRAM[0x10000/2]; // dedicated ARM7 WRAM + CompiledBlock ARM7_WIRAM[0x10000/2]; // Wifi + CompiledBlock ARM7_WVRAM[0x40000/2]; // VRAM allocated as Working RAM +}; + +extern BlockCache cache; + +inline bool IsMapped(u32 num, u32 addr) +{ + return cache.AddrMapping[num][(addr & 0xFFFFFFF) >> 14]; +} + +inline CompiledBlock LookUpBlock(u32 num, u32 addr) +{ + return cache.AddrMapping[num][(addr & 0xFFFFFFF) >> 14][(addr & 0x3FFF) >> 1]; +} + +inline void Invalidate16(u32 num, u32 addr) +{ + if (IsMapped(num, addr)) + cache.AddrMapping[num][(addr & 0xFFFFFFF) >> 14][(addr & 0x3FFF) >> 1] = NULL; +} + +inline void Invalidate32(u32 num, u32 addr) +{ + if (IsMapped(num, addr)) + { + CompiledBlock* page = cache.AddrMapping[num][(addr & 0xFFFFFFF) >> 14]; + page[(addr & 0x3FFF) >> 1] = NULL; + page[((addr + 2) & 0x3FFF) >> 1] = NULL; + } +} + +inline void InsertBlock(u32 num, u32 addr, CompiledBlock func) +{ + cache.AddrMapping[num][(addr & 0xFFFFFFF) >> 14][(addr & 0x3FFF) >> 1] = func; +} + +inline void ResetBlocks() +{ + memset(cache.MainRAM, 0, sizeof(cache.MainRAM)); + memset(cache.SWRAM, 0, sizeof(cache.SWRAM)); + memset(cache.ARM9_BIOS, 0, sizeof(cache.ARM9_BIOS)); + memset(cache.ARM9_ITCM, 0, sizeof(cache.ARM9_ITCM)); + memset(cache.ARM9_LCDC, 0, sizeof(cache.ARM9_LCDC)); + memset(cache.ARM7_BIOS, 0, sizeof(cache.ARM7_BIOS)); + memset(cache.ARM7_WIRAM, 0, sizeof(cache.ARM7_WIRAM)); + memset(cache.ARM7_WRAM, 0, sizeof(cache.ARM7_WRAM)); + memset(cache.ARM7_WVRAM, 0, sizeof(cache.ARM7_WVRAM)); +} + +void Init(); +void DeInit(); + +CompiledBlock CompileBlock(ARM* cpu); + +} + +#endif \ No newline at end of file diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp new file mode 100644 index 0000000..fb2fda8 --- /dev/null +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -0,0 +1,332 @@ +#include "ARMJIT_Compiler.h" + +#include "../ARMInterpreter.h" + +#include + +using namespace Gen; + +namespace ARMJIT +{ + +const int RegCache::NativeRegAllocOrder[] = {(int)RBX, (int)RSI, (int)RDI, (int)R12, (int)R13}; +const int RegCache::NativeRegsCount = 5; + +Compiler::Compiler() +{ + AllocCodeSpace(1024 * 1024 * 4); +} + +typedef void (Compiler::*CompileFunc)(); +typedef void (*InterpretFunc)(ARM*); + +void Compiler::LoadCPSR() +{ + assert(!CPSRDirty); + + MOV(32, R(RCPSR), MDisp(RCPU, offsetof(ARM, CPSR))); +} + +void Compiler::SaveCPSR() +{ + if (CPSRDirty) + { + MOV(32, MDisp(RCPU, offsetof(ARM, CPSR)), R(RCPSR)); + CPSRDirty = false; + } +} + +CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrsCount) +{ + if (IsAlmostFull()) + { + ResetBlocks(); + ResetCodePtr(); + } + + CompiledBlock res = (CompiledBlock)GetWritableCodePtr(); + + ConstantCycles = 0; + Thumb = cpu->CPSR & 0x20; + Num = cpu->Num; + R15 = cpu->R[15]; + + ABI_PushRegistersAndAdjustStack({ABI_ALL_CALLEE_SAVED}, 8, 0); + + MOV(64, R(RCPU), ImmPtr(cpu)); + XOR(32, R(RCycles), R(RCycles)); + + LoadCPSR(); + + for (int i = 0; i < instrsCount; i++) + { + R15 += Thumb ? 2 : 4; + CurrentInstr = instrs[i]; + + CompileFunc comp = NULL; + + if (comp == NULL || i == instrsCount - 1) + { + MOV(32, MDisp(RCPU, offsetof(ARM, R[15])), Imm32(R15)); + MOV(32, MDisp(RCPU, offsetof(ARM, CodeCycles)), Imm32(CurrentInstr.CodeCycles)); + MOV(32, MDisp(RCPU, offsetof(ARM, CurInstr)), Imm32(CurrentInstr.Instr)); + if (i == instrsCount - 1) + { + MOV(32, MDisp(RCPU, offsetof(ARM, NextInstr[0])), Imm32(CurrentInstr.NextInstr[0])); + MOV(32, MDisp(RCPU, offsetof(ARM, NextInstr[1])), Imm32(CurrentInstr.NextInstr[1])); + } + + SaveCPSR(); + } + + if (Thumb) + { + if (comp == NULL) + { + MOV(64, R(ABI_PARAM1), R(RCPU)); + + u32 icode = (CurrentInstr.Instr >> 6) & 0x3FF; + ABI_CallFunction(ARMInterpreter::THUMBInstrTable[icode]); + } + else + { + } + } + else + { + u32 cond = CurrentInstr.Cond(); + if (CurrentInstr.Info.Kind == ARMInstrInfo::ak_BLX_IMM) + { + MOV(64, R(ABI_PARAM1), R(RCPU)); + ABI_CallFunction(ARMInterpreter::A_BLX_IMM); + } + else if (cond == 0xF) + AddCycles_C(); + else + { + FixupBranch skipExecute; + if (cond < 0xE) + { + if (cond >= 0x8) + { + static_assert(RSCRATCH3 == ECX); + MOV(32, R(RSCRATCH3), R(RCPSR)); + SHR(32, R(RSCRATCH3), Imm8(28)); + MOV(32, R(RSCRATCH), Imm32(1)); + SHL(32, R(RSCRATCH), R(RSCRATCH3)); + TEST(32, R(RSCRATCH), Imm32(ARM::ConditionTable[cond])); + + skipExecute = J_CC(CC_Z); + } + else + { + // could have used a LUT, but then where would be the fun? + BT(32, R(RCPSR), Imm8(28 + ((~(cond >> 1) & 1) << 1 | (cond >> 2 & 1) ^ (cond >> 1 & 1)))); + + skipExecute = J_CC(cond & 1 ? CC_C : CC_NC); + } + + } + + if (comp == NULL) + { + MOV(64, R(ABI_PARAM1), R(RCPU)); + + u32 icode = ((CurrentInstr.Instr >> 4) & 0xF) | ((CurrentInstr.Instr >> 16) & 0xFF0); + ABI_CallFunction(ARMInterpreter::ARMInstrTable[icode]); + } + else + { + } + + FixupBranch skipFailed; + if (CurrentInstr.Cond() < 0xE) + { + skipFailed = J(); + SetJumpTarget(skipExecute); + + AddCycles_C(); + + SetJumpTarget(skipFailed); + } + } + } + + /* + we don't need to collect the interpreted cycles, + since all functions only add to it, the dispatcher + can take care of it. + */ + + if (comp == NULL && i != instrsCount - 1) + LoadCPSR(); + } + + SaveCPSR(); + + LEA(32, RAX, MDisp(RCycles, ConstantCycles)); + + ABI_PopRegistersAndAdjustStack({ABI_ALL_CALLEE_SAVED}, 8, 0); + RET(); + + return res; +} + +void Compiler::Compile(RegCache& regs, const FetchedInstr& instr) +{ + const CompileFunc A_Comp[ARMInstrInfo::ak_Count] = + { + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + }; + + const CompileFunc T_Comp[ARMInstrInfo::tk_Count] = { + NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL + }; +} + +void Compiler::AddCycles_C() +{ + s32 cycles = Num ? + NDS::ARM7MemTimings[CurrentInstr.CodeCycles][Thumb ? 1 : 3] + : ((R15 & 0x2) ? 0 : CurrentInstr.CodeCycles); + + if (CurrentInstr.Cond() < 0xE) + ADD(32, R(RCycles), Imm8(cycles)); + else + ConstantCycles += cycles; +} + +// may uses RSCRATCH for op2 and RSCRATCH2 for the carryValue +OpArg Compiler::Comp_ShiftRegImm(int op, int amount, Gen::X64Reg rm, bool S, bool& carryUsed) +{ + carryUsed = true; + + switch (op) + { + case 0: // LSL + if (amount > 0) + { + MOV(32, R(RSCRATCH), R(rm)); + SHL(32, R(RSCRATCH), Imm8(amount)); + if (S) + SETcc(CC_C, R(RSCRATCH2)); + + return R(RSCRATCH); + } + else + { + carryUsed = false; + return R(rm); + } + case 1: // LSR + if (amount > 0) + { + MOV(32, R(RSCRATCH), R(rm)); + SHR(32, R(RSCRATCH), Imm8(amount)); + if (S) + SETcc(CC_C, R(RSCRATCH2)); + return R(RSCRATCH); + } + else + { + if (S) + { + MOV(32, R(RSCRATCH2), R(rm)); + SHR(32, R(RSCRATCH2), Imm8(31)); + } + return Imm32(0); + } + case 2: // ASR + MOV(32, R(RSCRATCH), R(rm)); + SAR(32, R(RSCRATCH), Imm8(amount ? amount : 31)); + if (S) + { + if (amount == 0) + { + MOV(32, R(RSCRATCH2), R(rm)); + SHR(32, R(RSCRATCH2), Imm8(31)); + } + else + SETcc(CC_C, R(RSCRATCH2)); + } + return R(RSCRATCH); + case 3: // ROR + if (amount > 0) + { + MOV(32, R(RSCRATCH), R(rm)); + ROR_(32, R(RSCRATCH), Imm8(amount)); + } + else + { + BT(32, R(RCPSR), Imm8(29)); + MOV(32, R(RSCRATCH), R(rm)); + RCR(32, R(RSCRATCH), Imm8(1)); + } + if (S) + SETcc(CC_C, R(RSCRATCH2)); + return R(RSCRATCH); + } +} + +void Compiler::A_Comp_ALU(const FetchedInstr& instr) +{ +} + +} \ No newline at end of file diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h new file mode 100644 index 0000000..8e1d100 --- /dev/null +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -0,0 +1,54 @@ +#ifndef ARMJIT_COMPILER_H +#define ARMJIT_COMPILER_H + +#include "../dolphin/x64Emitter.h" + +#include "../ARMJIT.h" + + +namespace ARMJIT +{ + +const Gen::X64Reg RCPU = Gen::RBP; +const Gen::X64Reg RCycles = Gen::R14; +const Gen::X64Reg RCPSR = Gen::R15; + +const Gen::X64Reg RSCRATCH = Gen::EAX; +const Gen::X64Reg RSCRATCH2 = Gen::EDX; +const Gen::X64Reg RSCRATCH3 = Gen::ECX; + +class Compiler : public Gen::X64CodeBlock +{ +public: + Compiler(); + + CompiledBlock CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrsCount); + + void StartBlock(ARM* cpu); + CompiledBlock FinaliseBlock(); + + void Compile(RegCache& regs, const FetchedInstr& instr); +private: + void AddCycles_C(); + + Gen::OpArg Comp_ShiftRegImm(int op, int amount, Gen::X64Reg rm, bool S, bool& carryUsed); + + void A_Comp_ALU(const FetchedInstr& instr); + + void LoadCPSR(); + void SaveCPSR(); + + bool CPSRDirty = false; + + FetchedInstr CurrentInstr; + + bool Thumb; + u32 Num; + u32 R15; + + u32 ConstantCycles; +}; + +} + +#endif \ No newline at end of file diff --git a/src/ARM_InstrInfo.cpp b/src/ARM_InstrInfo.cpp new file mode 100644 index 0000000..41c46e1 --- /dev/null +++ b/src/ARM_InstrInfo.cpp @@ -0,0 +1,376 @@ +#include "ARM_InstrInfo.h" + +#include + +namespace ARMInstrInfo +{ + +#define ak(x) ((x) << 13) + +enum { + A_Read0 = 1 << 0, + A_Read16 = 1 << 1, + A_Read8 = 1 << 2, + A_Read12 = 1 << 3, + + A_Write12 = 1 << 4, + A_Write16 = 1 << 5, + A_MemWriteback = 1 << 6, + + A_BranchAlways = 1 << 7, + + // for STRD/LDRD + A_Read12Double = 1 << 8, + A_Write12Double = 1 << 9, + + A_Link = 1 << 10, + + A_LDMSTM = 1 << 11, + + A_ARM9Only = 1 << 12, +}; + +#define A_BIOP A_Read16 +#define A_MONOOP 0 + +#define A_IMPLEMENT_ALU_OP(x,k) \ + const u32 A_##x##_IMM = A_Write12 | A_##k | ak(ak_##x##_IMM); \ + const u32 A_##x##_REG_LSL_IMM = A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_LSL_IMM); \ + const u32 A_##x##_REG_LSR_IMM = A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_LSR_IMM); \ + const u32 A_##x##_REG_ASR_IMM = A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_ASR_IMM); \ + const u32 A_##x##_REG_ROR_IMM = A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_ROR_IMM); \ + const u32 A_##x##_REG_LSL_REG = A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSL_REG); \ + const u32 A_##x##_REG_LSR_REG = A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSR_REG); \ + const u32 A_##x##_REG_ASR_REG = A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_ASR_REG); \ + const u32 A_##x##_REG_ROR_REG = A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_ROR_REG); \ + \ + const u32 A_##x##_IMM_S = A_Write12 | A_##k | ak(ak_##x##_IMM_S); \ + const u32 A_##x##_REG_LSL_IMM_S = A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_LSL_IMM_S); \ + const u32 A_##x##_REG_LSR_IMM_S = A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_LSR_IMM_S); \ + const u32 A_##x##_REG_ASR_IMM_S = A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_ASR_IMM_S); \ + const u32 A_##x##_REG_ROR_IMM_S = A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_ROR_IMM_S); \ + const u32 A_##x##_REG_LSL_REG_S = A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSL_REG_S); \ + const u32 A_##x##_REG_LSR_REG_S = A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSR_REG_S); \ + const u32 A_##x##_REG_ASR_REG_S = A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_ASR_REG_S); \ + const u32 A_##x##_REG_ROR_REG_S = A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_ROR_REG_S); + +A_IMPLEMENT_ALU_OP(AND,BIOP) +A_IMPLEMENT_ALU_OP(EOR,BIOP) +A_IMPLEMENT_ALU_OP(SUB,BIOP) +A_IMPLEMENT_ALU_OP(RSB,BIOP) +A_IMPLEMENT_ALU_OP(ADD,BIOP) +A_IMPLEMENT_ALU_OP(ADC,BIOP) +A_IMPLEMENT_ALU_OP(SBC,BIOP) +A_IMPLEMENT_ALU_OP(RSC,BIOP) +A_IMPLEMENT_ALU_OP(ORR,BIOP) +A_IMPLEMENT_ALU_OP(MOV,MONOOP) +A_IMPLEMENT_ALU_OP(BIC,BIOP) +A_IMPLEMENT_ALU_OP(MVN,MONOOP) + +const u32 A_MOV_REG_LSL_IMM_DBG = A_MOV_REG_LSL_IMM; + +#define A_IMPLEMENT_ALU_TEST(x) \ + const u32 A_##x##_IMM = A_Read16 | A_Read0 | ak(ak_##x##_IMM); \ + const u32 A_##x##_REG_LSL_IMM = A_Read16 | A_Read0 | ak(ak_##x##_REG_LSL_IMM); \ + const u32 A_##x##_REG_LSR_IMM = A_Read16 | A_Read0 | ak(ak_##x##_REG_LSR_IMM); \ + const u32 A_##x##_REG_ASR_IMM = A_Read16 | A_Read0 | ak(ak_##x##_REG_ASR_IMM); \ + const u32 A_##x##_REG_ROR_IMM = A_Read16 | A_Read0 | ak(ak_##x##_REG_ROR_IMM); \ + const u32 A_##x##_REG_LSL_REG = A_Read16 | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSL_REG); \ + const u32 A_##x##_REG_LSR_REG = A_Read16 | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSR_REG); \ + const u32 A_##x##_REG_ASR_REG = A_Read16 | A_Read0 | A_Read8 | ak(ak_##x##_REG_ASR_REG); \ + const u32 A_##x##_REG_ROR_REG = A_Read16 | A_Read0 | A_Read8 | ak(ak_##x##_REG_ROR_REG); + +A_IMPLEMENT_ALU_TEST(TST) +A_IMPLEMENT_ALU_TEST(TEQ) +A_IMPLEMENT_ALU_TEST(CMP) +A_IMPLEMENT_ALU_TEST(CMN) + +const u32 A_MUL = A_Write16 | A_Read0 | A_Read8 | ak(ak_MUL); +const u32 A_MLA = A_Write16 | A_Read0 | A_Read8 | A_Read12 | ak(ak_MLA); +const u32 A_UMULL = A_Write16 | A_Write12 | A_Read0 | A_Read8 | ak(ak_UMULL); +const u32 A_UMLAL = A_Write16 | A_Write12 | A_Read16 | A_Read12 | A_Read0 | A_Read8 | ak(ak_UMLAL); +const u32 A_SMULL = A_Write16 | A_Write12 | A_Read0 | A_Read8 | ak(ak_SMULL); +const u32 A_SMLAL = A_Write16 | A_Write12 | A_Read16 | A_Read12 | A_Read0 | A_Read8 | ak(ak_SMLAL); +const u32 A_SMLAxy = A_Write16 | A_Read0 | A_Read8 | A_Read12 | ak(ak_SMLALxy); +const u32 A_SMLAWy = A_Write16 | A_Read0 | A_Read8 | A_Read12 | ak(ak_SMLAWy); +const u32 A_SMULWy = A_Write16 | A_Read0 | A_Read8 | ak(ak_SMULWy); +const u32 A_SMLALxy = A_Write16 | A_Write12 | A_Read16 | A_Read12 | A_Read0 | A_Read8 | ak(ak_SMLALxy); +const u32 A_SMULxy = A_Write16 | A_Read0 | A_Read8 | ak(ak_SMULxy); + +const u32 A_CLZ = A_Write12 | A_Read0 | A_ARM9Only | ak(ak_CLZ); + +const u32 A_QADD = A_Write12 | A_Read0 | A_Read16 | A_ARM9Only | ak(ak_QADD); +const u32 A_QSUB = A_Write12 | A_Read0 | A_Read16 | A_ARM9Only | ak(ak_QSUB); +const u32 A_QDADD = A_Write12 | A_Read0 | A_Read16 | A_ARM9Only | ak(ak_QDADD); +const u32 A_QDSUB = A_Write12 | A_Read0 | A_Read16 | A_ARM9Only | ak(ak_QDSUB); + +#define A_LDR A_Write12 +#define A_STR A_Read12 + +#define A_IMPLEMENT_WB_LDRSTR(x,k) \ + const u32 A_##x##_IMM = A_##k | A_Read16 | A_MemWriteback | ak(ak_##x##_IMM); \ + const u32 A_##x##_REG_LSL = A_##k | A_Read16 | A_MemWriteback | A_Read0 | ak(ak_##x##_REG_LSL); \ + const u32 A_##x##_REG_LSR = A_##k | A_Read16 | A_MemWriteback | A_Read0 | ak(ak_##x##_REG_LSR); \ + const u32 A_##x##_REG_ASR = A_##k | A_Read16 | A_MemWriteback | A_Read0 | ak(ak_##x##_REG_ASR); \ + const u32 A_##x##_REG_ROR = A_##k | A_Read16 | A_MemWriteback | A_Read0 | ak(ak_##x##_REG_ROR); \ + \ + const u32 A_##x##_POST_IMM = A_##k | A_Read16 | A_Write16 | ak(ak_##x##_POST_IMM); \ + const u32 A_##x##_POST_REG_LSL = A_##k | A_Read16 | A_Write16 | A_Read0 | ak(ak_##x##_POST_REG_LSL); \ + const u32 A_##x##_POST_REG_LSR = A_##k | A_Read16 | A_Write16 | A_Read0 | ak(ak_##x##_POST_REG_LSR); \ + const u32 A_##x##_POST_REG_ASR = A_##k | A_Read16 | A_Write16 | A_Read0 | ak(ak_##x##_POST_REG_ASR); \ + const u32 A_##x##_POST_REG_ROR = A_##k | A_Read16 | A_Write16 | A_Read0 | ak(ak_##x##_POST_REG_ROR); + +A_IMPLEMENT_WB_LDRSTR(STR,STR) +A_IMPLEMENT_WB_LDRSTR(STRB,STR) +A_IMPLEMENT_WB_LDRSTR(LDR,LDR) +A_IMPLEMENT_WB_LDRSTR(LDRB,LDR) + +#define A_LDRD A_Write12Double +#define A_STRD A_Read12Double + +#define A_IMPLEMENT_HD_LDRSTR(x,k) \ + const u32 A_##x##_IMM = A_##k | A_Read16 | A_Write16 | ak(ak_##x##_IMM); \ + const u32 A_##x##_REG = A_##k | A_Read16 | A_Write16 | A_Read0 | ak(ak_##x##_REG); \ + const u32 A_##x##_POST_IMM = A_##k | A_Read16 | A_Write16 | ak(ak_##x##_POST_IMM); \ + const u32 A_##x##_POST_REG = A_##k | A_Read16 | A_Write16 | A_Read0 | ak(ak_##x##_POST_REG); + +A_IMPLEMENT_HD_LDRSTR(STRH,STR) +A_IMPLEMENT_HD_LDRSTR(LDRD,LDRD) +A_IMPLEMENT_HD_LDRSTR(STRD,STRD) +A_IMPLEMENT_HD_LDRSTR(LDRH,LDR) +A_IMPLEMENT_HD_LDRSTR(LDRSB,LDR) +A_IMPLEMENT_HD_LDRSTR(LDRSH,LDR) + +const u32 A_SWP = A_Write12 | A_Read16 | A_Read0 | ak(ak_SWP); +const u32 A_SWPB = A_Write12 | A_Read16 | A_Read0 | ak(ak_SWPB); + +const u32 A_LDM = A_Read16 | A_LDMSTM | ak(ak_LDM); +const u32 A_STM = A_Read16 | A_LDMSTM | ak(ak_STM); + +const u32 A_B = A_BranchAlways | ak(ak_B); +const u32 A_BL = A_BranchAlways | A_Link | ak(ak_BL); +const u32 A_BLX_IMM = A_BranchAlways | A_Link | ak(ak_BLX_IMM); +const u32 A_BX = A_BranchAlways | A_Read0 | ak(ak_BX); +const u32 A_BLX_REG = A_BranchAlways | A_Link | A_Read0 | ak(ak_BLX_REG); + +const u32 A_UNK = A_BranchAlways | A_Link | ak(ak_UNK); +const u32 A_MSR_IMM = A_ARM9Only | ak(ak_MSR_IMM); +const u32 A_MSR_REG = A_Read0 | A_ARM9Only | ak(ak_MSR_REG); +const u32 A_MRS = A_Write12 | A_ARM9Only | ak(ak_MRS); +const u32 A_MCR = A_Read12 | A_ARM9Only | ak(ak_MCR); +const u32 A_MRC = A_Write12 | A_ARM9Only | ak(ak_MRC); +const u32 A_SVC = A_BranchAlways | A_Link | ak(ak_SVC); + +// THUMB + +#define tk(x) ((x) << 16) + +enum { + T_Read0 = 1 << 0, + T_Read3 = 1 << 1, + T_Read6 = 1 << 2, + T_Read8 = 1 << 3, + + T_Write0 = 1 << 4, + T_Write8 = 1 << 5, + + T_ReadHi0 = 1 << 6, + T_ReadHi3 = 1 << 7, + T_WriteHi0 = 1 << 8, + + T_ReadR13 = 1 << 9, + T_WriteR13 = 1 << 10, + T_ReadR15 = 1 << 11, + + T_BranchAlways = 1 << 12, + T_ReadR14 = 1 << 13, + T_WriteR14 = 1 << 14, + + T_PopPC = 1 << 15 +}; + +const u32 T_LSL_IMM = T_Write0 | T_Read3 | tk(tk_LSL_IMM); +const u32 T_LSR_IMM = T_Write0 | T_Read3 | tk(tk_LSR_IMM); +const u32 T_ASR_IMM = T_Write0 | T_Read3 | tk(tk_ASR_IMM); + +const u32 T_ADD_REG_ = T_Write0 | T_Read3 | T_Read6 | tk(tk_ADD_REG_); +const u32 T_SUB_REG_ = T_Write0 | T_Read3 | T_Read6 | tk(tk_SUB_REG_); +const u32 T_ADD_IMM_ = T_Write0 | T_Read3 | tk(tk_ADD_IMM_); +const u32 T_SUB_IMM_ = T_Write0 | T_Read3 | tk(tk_SUB_IMM_); + +const u32 T_MOV_IMM = T_Write8 | tk(tk_MOV_IMM); +const u32 T_CMP_IMM = T_Write8 | tk(tk_CMP_IMM); +const u32 T_ADD_IMM = T_Write8 | T_Read8 | tk(tk_ADD_IMM); +const u32 T_SUB_IMM = T_Write8 | T_Read8 | tk(tk_SUB_IMM); + +const u32 T_AND_REG = T_Write0 | T_Read0 | T_Read3 | tk(tk_AND_REG); +const u32 T_EOR_REG = T_Write0 | T_Read0 | T_Read3 | tk(tk_EOR_REG); +const u32 T_LSL_REG = T_Write0 | T_Read0 | T_Read3 | tk(tk_LSL_REG); +const u32 T_LSR_REG = T_Write0 | T_Read0 | T_Read3 | tk(tk_LSR_REG); +const u32 T_ASR_REG = T_Write0 | T_Read0 | T_Read3 | tk(tk_ASR_REG); +const u32 T_ADC_REG = T_Write0 | T_Read0 | T_Read3 | tk(tk_ADC_REG); +const u32 T_SBC_REG = T_Write0 | T_Read0 | T_Read3 | tk(tk_SBC_REG); +const u32 T_ROR_REG = T_Write0 | T_Read0 | T_Read3 | tk(tk_ROR_REG); +const u32 T_TST_REG = T_Read0 | T_Read3 | tk(tk_TST_REG); +const u32 T_NEG_REG = T_Write0 | T_Read3 | tk(tk_NEG_REG); +const u32 T_CMP_REG = T_Read0 | T_Read3 | tk(tk_CMP_REG); +const u32 T_CMN_REG = T_Read0 | T_Read3 | tk(tk_CMN_REG); +const u32 T_ORR_REG = T_Write0 | T_Read0 | T_Read3 | tk(tk_ORR_REG); +const u32 T_MUL_REG = T_Write0 | T_Read0 | T_Read3 | tk(tk_MUL_REG); +const u32 T_BIC_REG = T_Write0 | T_Read0 | T_Read3 | tk(tk_BIC_REG); +const u32 T_MVN_REG = T_Write0 | T_Read3 | tk(tk_MVN_REG); + +const u32 T_ADD_HIREG = T_WriteHi0 | T_ReadHi0 | T_ReadHi3 | tk(tk_ADD_HIREG); +const u32 T_CMP_HIREG = T_ReadHi0 | T_ReadHi3 | tk(tk_CMP_HIREG); +const u32 T_MOV_HIREG = T_WriteHi0 | T_ReadHi3 | tk(tk_MOV_HIREG); + +const u32 T_ADD_PCREL = T_Write8 | T_ReadR15 | tk(tk_ADD_PCREL); +const u32 T_ADD_SPREL = T_Write8 | T_ReadR13 | tk(tk_ADD_SPREL); +const u32 T_ADD_SP = T_WriteR13 | tk(tk_ADD_SP); + +const u32 T_LDR_PCREL = T_Write8 | tk(tk_LDR_PCREL); + +const u32 T_STR_REG = T_Read0 | T_Read3 | T_Read6 | tk(tk_STR_REG); +const u32 T_STRB_REG = T_Read0 | T_Read3 | T_Read6 | tk(tk_STRB_REG); +const u32 T_LDR_REG = T_Write0 | T_Read3 | T_Read6 | tk(tk_LDR_REG); +const u32 T_LDRB_REG = T_Write0 | T_Read3 | T_Read6 | tk(tk_LDRB_REG); +const u32 T_STRH_REG = T_Read0 | T_Read3 | T_Read6 | tk(tk_STRH_REG); +const u32 T_LDRSB_REG = T_Write0 | T_Read3 | T_Read6 | tk(tk_LDRSB_REG); +const u32 T_LDRH_REG = T_Write0 | T_Read3 | T_Read6 | tk(tk_LDRH_REG); +const u32 T_LDRSH_REG = T_Write0 | T_Read3 | T_Read6 | tk(tk_LDRSH_REG); + +const u32 T_STR_IMM = T_Read0 | T_Read3 | tk(tk_STR_IMM); +const u32 T_LDR_IMM = T_Write0 | T_Read3 | tk(tk_LDR_IMM); +const u32 T_STRB_IMM = T_Read0 | T_Read3 | tk(tk_STRB_IMM); +const u32 T_LDRB_IMM = T_Write0 | T_Read3 | tk(tk_LDRB_IMM); +const u32 T_STRH_IMM = T_Read0 | T_Read3 | tk(tk_STRH_IMM); +const u32 T_LDRH_IMM = T_Write0 | T_Read3 | tk(tk_LDRH_IMM); + +const u32 T_STR_SPREL = T_Read8 | T_ReadR13 | tk(tk_STR_SPREL); +const u32 T_LDR_SPREL = T_Write8 | T_ReadR13 | tk(tk_LDR_SPREL); + +const u32 T_PUSH = T_ReadR15 | T_ReadR13 | T_WriteR13 | tk(tk_PUSH); +const u32 T_POP = T_PopPC | T_ReadR13 | T_WriteR13 | tk(tk_POP); + +const u32 T_LDMIA = T_Read8 | T_Write8 | tk(tk_LDMIA); +const u32 T_STMIA = T_Read8 | T_Write8 | tk(tk_STMIA); + +const u32 T_BCOND = T_BranchAlways | tk(tk_BCOND); +const u32 T_BX = T_BranchAlways | T_ReadHi3 | tk(tk_BX); +const u32 T_BLX_REG = T_BranchAlways | T_ReadR15 | T_WriteR14 | T_ReadHi3 | tk(tk_BLX_REG); +const u32 T_B = T_BranchAlways | tk(tk_B); +const u32 T_BL_LONG_1 = T_WriteR14 | T_ReadR15 | tk(tk_BL_LONG_1); +const u32 T_BL_LONG_2 = T_BranchAlways | T_ReadR14 | T_WriteR14 | T_ReadR15 | tk(tk_BL_LONG_2); + +const u32 T_UNK = T_BranchAlways | T_WriteR14 | tk(tk_UNK); +const u32 T_SVC = T_BranchAlways | T_WriteR14 | T_ReadR15 | tk(tk_SVC); + +#define INSTRFUNC_PROTO(x) u32 x +#include "ARM_InstrTable.h" +#undef INSTRFUNC_PROTO + +Info Decode(bool thumb, u32 num, u32 instr) +{ + Info res = {0}; + if (thumb) + { + u32 data = THUMBInstrTable[(instr >> 6) & 0x3FF]; + + if (data & T_Read0) + res.SrcRegs |= 1 << (instr & 0x7); + if (data & T_Read3) + res.SrcRegs |= 1 << ((instr >> 3) & 0x7); + if (data & T_Read6) + res.SrcRegs |= 1 << ((instr >> 6) & 0x7); + if (data & T_Read8) + res.SrcRegs |= 1 << ((instr >> 8) & 0x7); + + if (data & T_Write0) + res.DstRegs |= 1 << (instr & 0x7); + if (data & T_Write8) + res.DstRegs |= 1 << ((instr >> 8) & 0x7); + + if (data & T_ReadHi0) + res.SrcRegs |= 1 << ((instr & 0x7) | ((instr >> 4) & 0x8)); + if (data & T_ReadHi3) + res.SrcRegs |= 1 << ((instr >> 3) & 0xF); + if (data & T_WriteHi0) + res.DstRegs |= 1 << ((instr & 0x7) | ((instr >> 4) & 0x8)); + + if (data & T_ReadR13) + res.SrcRegs |= (1 << 13); + if (data & T_WriteR13) + res.DstRegs |= (1 << 13); + if (data & T_ReadR15) + res.SrcRegs |= (1 << 15); + + if (data & T_BranchAlways) + res.DstRegs |= (1 << 15); + + if (data & T_PopPC && instr & (1 << 8)) + res.DstRegs |= 1 << 15; + + res.Kind = (data >> 16) & 0x3F; + + return res; + } + else + { + u32 data = ARMInstrTable[((instr >> 4) & 0xF) | ((instr >> 16) & 0xFF0)]; + if ((instr & 0xFE000000) == 0xFA000000) + data = A_BLX_IMM; + + if (data & A_ARM9Only && num != 0) + data |= A_BranchAlways | A_Link; + + if (data & A_Read0) + res.SrcRegs |= 1 << (instr & 0xF); + if (data & A_Read16) + res.SrcRegs |= 1 << ((instr >> 16) & 0xF); + if (data & A_Read8) + res.SrcRegs |= 1 << ((instr >> 8) & 0xF); + if (data & A_Read12) + res.SrcRegs |= 1 << ((instr >> 12) & 0xF); + + if (data & A_Write12) + res.DstRegs |= 1 << ((instr >> 12) & 0xF); + if (data & A_Write16) + res.DstRegs |= 1 << ((instr >> 16) & 0xF); + + if (data & A_MemWriteback && instr & (1 << 21)) + res.DstRegs |= 1 << ((instr >> 16) & 0xF); + + if (data & A_BranchAlways) + res.DstRegs |= 1 << 15; + + if (data & A_Read12Double) + { + res.SrcRegs |= 1 << ((instr >> 12) & 0xF); + res.SrcRegs |= 1 << (((instr >> 12) & 0xF) + 1); + } + if (data & A_Write12Double) + { + res.DstRegs |= 1 << ((instr >> 12) & 0xF); + res.DstRegs |= 1 << (((instr >> 12) & 0xF) + 1); + } + + if (data & A_Link) + { + res.DstRegs |= 1 << 14; + res.SrcRegs |= 1 << 15; + } + + if (data & A_LDMSTM) + { + res.DstRegs |= instr & (!!(instr & (1 << 20)) << 15); + if (instr & (1 << 21)) + res.DstRegs |= 1 << ((instr >> 16) & 0xF); + } + + res.Kind = (data >> 13) & 0x1FF; + + return res; + } +} + +} diff --git a/src/ARM_InstrInfo.h b/src/ARM_InstrInfo.h new file mode 100644 index 0000000..e717664 --- /dev/null +++ b/src/ARM_InstrInfo.h @@ -0,0 +1,232 @@ +#ifndef ARMINSTRINFO_H +#define ARMINSTRINFO_H + +#include "types.h" + +namespace ARMInstrInfo +{ + +// Instruction kinds, for faster dispatch + +#define ak_ALU(n) \ + ak_##n##_REG_LSL_IMM, \ + ak_##n##_REG_LSR_IMM, \ + ak_##n##_REG_ASR_IMM, \ + ak_##n##_REG_ROR_IMM, \ + \ + ak_##n##_REG_LSL_REG, \ + ak_##n##_REG_LSR_REG, \ + ak_##n##_REG_ASR_REG, \ + ak_##n##_REG_ROR_REG, \ + \ + ak_##n##_IMM, \ + \ + ak_##n##_REG_LSL_IMM_S, \ + ak_##n##_REG_LSR_IMM_S, \ + ak_##n##_REG_ASR_IMM_S, \ + ak_##n##_REG_ROR_IMM_S, \ + \ + ak_##n##_REG_LSL_REG_S, \ + ak_##n##_REG_LSR_REG_S, \ + ak_##n##_REG_ASR_REG_S, \ + ak_##n##_REG_ROR_REG_S, \ + \ + ak_##n##_IMM_S \ + +#define ak_Test(n) \ + ak_##n##_REG_LSL_IMM, \ + ak_##n##_REG_LSR_IMM, \ + ak_##n##_REG_ASR_IMM, \ + ak_##n##_REG_ROR_IMM, \ + \ + ak_##n##_REG_LSL_REG, \ + ak_##n##_REG_LSR_REG, \ + ak_##n##_REG_ASR_REG, \ + ak_##n##_REG_ROR_REG, \ + \ + ak_##n##_IMM + +#define ak_WB_LDRSTR(n) \ + ak_##n##_REG_LSL, \ + ak_##n##_REG_LSR, \ + ak_##n##_REG_ASR, \ + ak_##n##_REG_ROR, \ + \ + ak_##n##_IMM, \ + \ + ak_##n##_POST_REG_LSL, \ + ak_##n##_POST_REG_LSR, \ + ak_##n##_POST_REG_ASR, \ + ak_##n##_POST_REG_ROR, \ + \ + ak_##n##_POST_IMM + +#define ak_HD_LDRSTR(n) \ + ak_##n##_REG, \ + ak_##n##_IMM, \ + \ + ak_##n##_POST_REG, \ + ak_##n##_POST_IMM + +enum +{ + ak_ALU(AND), + ak_ALU(EOR), + ak_ALU(SUB), + ak_ALU(RSB), + ak_ALU(ADD), + ak_ALU(ADC), + ak_ALU(SBC), + ak_ALU(RSC), + ak_ALU(ORR), + ak_ALU(MOV), + ak_ALU(BIC), + ak_ALU(MVN), + + ak_ALU(TST), + ak_ALU(TEQ), + ak_ALU(CMP), + ak_ALU(CMN), + + ak_MUL, + ak_MLA, + ak_UMULL, + ak_UMLAL, + ak_SMULL, + ak_SMLAL, + ak_SMLAxy, + ak_SMLAWy, + ak_SMULWy, + ak_SMLALxy, + ak_SMULxy, + + ak_CLZ, + + ak_QADD, + ak_QSUB, + ak_QDADD, + ak_QDSUB, + + ak_WB_LDRSTR(STR), + ak_WB_LDRSTR(STRB), + ak_WB_LDRSTR(LDR), + ak_WB_LDRSTR(LDRB), + + ak_HD_LDRSTR(STRH), + ak_HD_LDRSTR(LDRD), + ak_HD_LDRSTR(STRD), + ak_HD_LDRSTR(LDRH), + ak_HD_LDRSTR(LDRSB), + ak_HD_LDRSTR(LDRSH), + + ak_SWP, + ak_SWPB, + + ak_LDM, + ak_STM, + + ak_B, + ak_BL, + ak_BLX_IMM, + ak_BX, + ak_BLX_REG, + + ak_UNK, + ak_MSR_IMM, + ak_MSR_REG, + ak_MRS, + ak_MCR, + ak_MRC, + ak_SVC, + + ak_Count, + + tk_LSL_IMM = 0, + tk_LSR_IMM, + tk_ASR_IMM, + + tk_ADD_REG_, + tk_SUB_REG_, + tk_ADD_IMM_, + tk_SUB_IMM_, + + tk_MOV_IMM, + tk_CMP_IMM, + tk_ADD_IMM, + tk_SUB_IMM, + + tk_AND_REG, + tk_EOR_REG, + tk_LSL_REG, + tk_LSR_REG, + tk_ASR_REG, + tk_ADC_REG, + tk_SBC_REG, + tk_ROR_REG, + tk_TST_REG, + tk_NEG_REG, + tk_CMP_REG, + tk_CMN_REG, + tk_ORR_REG, + tk_MUL_REG, + tk_BIC_REG, + tk_MVN_REG, + + tk_ADD_HIREG, + tk_CMP_HIREG, + tk_MOV_HIREG, + + tk_ADD_PCREL, + tk_ADD_SPREL, + tk_ADD_SP, + + tk_LDR_PCREL, + tk_STR_REG, + tk_STRB_REG, + tk_LDR_REG, + tk_LDRB_REG, + tk_STRH_REG, + tk_LDRSB_REG, + tk_LDRH_REG, + tk_LDRSH_REG, + tk_STR_IMM, + tk_LDR_IMM, + tk_STRB_IMM, + tk_LDRB_IMM, + tk_STRH_IMM, + tk_LDRH_IMM, + tk_STR_SPREL, + tk_LDR_SPREL, + + tk_PUSH, + tk_POP, + tk_LDMIA, + tk_STMIA, + tk_BCOND, + tk_BX, + tk_BLX_REG, + tk_B, + tk_BL_LONG_1, + tk_BL_LONG_2, + tk_UNK, + tk_SVC, + + tk_Count +}; + +struct Info +{ + u16 DstRegs, SrcRegs; + u16 Kind; + + bool Branches() + { + return DstRegs & (1 << 15); + } +}; + +Info Decode(bool thumb, u32 num, u32 instr); + +} + +#endif \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 32fcac2..a6011e1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,7 @@ project(core) +set (CMAKE_CXX_STANDARD 14) + add_library(core STATIC ARCodeList.cpp AREngine.cpp @@ -9,6 +11,7 @@ add_library(core STATIC ARMInterpreter_ALU.cpp ARMInterpreter_Branch.cpp ARMInterpreter_LoadStore.cpp + ARM_InstrInfo.cpp Config.cpp CP15.cpp CRC32.cpp @@ -46,6 +49,15 @@ add_library(core STATIC WifiAP.cpp tiny-AES-c/aes.c + + ARMJIT.cpp + ARMJIT_x64/ARMJIT_Compiler.cpp + + dolphin/CommonFuncs.cpp + dolphin/x64ABI.cpp + dolphin/x64CPUDetect.cpp + dolphin/x64Emitter.cpp + dolphin/MemoryUtil.cpp ) if (WIN32) diff --git a/src/CP15.cpp b/src/CP15.cpp index d340b9e..3e1c08b 100644 --- a/src/CP15.cpp +++ b/src/CP15.cpp @@ -21,6 +21,7 @@ #include "NDS.h" #include "DSi.h" #include "ARM.h" +#include "ARMJIT.h" // access timing for cached regions @@ -812,6 +813,7 @@ void ARMv5::DataWrite8(u32 addr, u8 val) { DataCycles = 1; *(u8*)&ITCM[addr & 0x7FFF] = val; + ARMJIT::cache.ARM9_ITCM[(addr & 0x7FFF) >> 1] = NULL; return; } if (addr >= DTCMBase && addr < (DTCMBase + DTCMSize)) @@ -833,6 +835,7 @@ void ARMv5::DataWrite16(u32 addr, u16 val) { DataCycles = 1; *(u16*)&ITCM[addr & 0x7FFF] = val; + ARMJIT::cache.ARM9_ITCM[(addr & 0x7FFF) >> 1] = NULL; return; } if (addr >= DTCMBase && addr < (DTCMBase + DTCMSize)) @@ -854,6 +857,8 @@ void ARMv5::DataWrite32(u32 addr, u32 val) { DataCycles = 1; *(u32*)&ITCM[addr & 0x7FFF] = val; + ARMJIT::cache.ARM9_ITCM[(addr & 0x7FFF) >> 1] = NULL; + ARMJIT::cache.ARM9_ITCM[((addr + 2) & 0x7FFF) >> 1] = NULL; return; } if (addr >= DTCMBase && addr < (DTCMBase + DTCMSize)) @@ -875,6 +880,8 @@ void ARMv5::DataWrite32S(u32 addr, u32 val) { DataCycles += 1; *(u32*)&ITCM[addr & 0x7FFF] = val; + ARMJIT::cache.ARM9_ITCM[(addr & 0x7FFF) / 2] = NULL; + ARMJIT::cache.ARM9_ITCM[(addr & 0x7FFF) / 2 + 1] = NULL; return; } if (addr >= DTCMBase && addr < (DTCMBase + DTCMSize)) diff --git a/src/NDS.cpp b/src/NDS.cpp index 22368ae..2a7edfd 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -32,6 +32,7 @@ #include "Wifi.h" #include "AREngine.h" #include "Platform.h" +#include "ARMJIT.h" #include "DSi.h" #include "DSi_SPI_TSC.h" @@ -168,6 +169,8 @@ bool Init() ARM9 = new ARMv5(); ARM7 = new ARMv4(); + ARMJIT::Init(); + DMAs[0] = new DMA(0, 0); DMAs[1] = new DMA(0, 1); DMAs[2] = new DMA(0, 2); @@ -200,6 +203,8 @@ void DeInit() delete ARM9; delete ARM7; + ARMJIT::DeInit(); + for (int i = 0; i < 8; i++) delete DMAs[i]; @@ -1971,6 +1976,8 @@ u32 ARM9Read32(u32 addr) void ARM9Write8(u32 addr, u8 val) { + ARMJIT::Invalidate16(0, addr); + switch (addr & 0xFF000000) { case 0x02000000: @@ -2021,6 +2028,8 @@ void ARM9Write8(u32 addr, u8 val) void ARM9Write16(u32 addr, u16 val) { + ARMJIT::Invalidate16(0, addr); + switch (addr & 0xFF000000) { case 0x02000000: @@ -2087,6 +2096,8 @@ void ARM9Write16(u32 addr, u16 val) void ARM9Write32(u32 addr, u32 val) { + ARMJIT::Invalidate32(0, addr); + switch (addr & 0xFF000000) { case 0x02000000: @@ -2381,6 +2392,8 @@ u32 ARM7Read32(u32 addr) void ARM7Write8(u32 addr, u8 val) { + ARMJIT::Invalidate16(1, addr); + switch (addr & 0xFF800000) { case 0x02000000: @@ -2440,6 +2453,8 @@ void ARM7Write8(u32 addr, u8 val) void ARM7Write16(u32 addr, u16 val) { + ARMJIT::Invalidate16(1, addr); + switch (addr & 0xFF800000) { case 0x02000000: @@ -2509,6 +2524,8 @@ void ARM7Write16(u32 addr, u16 val) void ARM7Write32(u32 addr, u32 val) { + ARMJIT::Invalidate32(1, addr); + switch (addr & 0xFF800000) { case 0x02000000: diff --git a/src/dolphin/Assert.h b/src/dolphin/Assert.h new file mode 100644 index 0000000..4eb16e0 --- /dev/null +++ b/src/dolphin/Assert.h @@ -0,0 +1,47 @@ +// Copyright 2015 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license_dolphin.txt file included. + +#pragma once + +#include + +#define ASSERT_MSG(_t_, _a_, _fmt_, ...) \ + assert(_a_) \ + /*do \ + { \ + if (!(_a_)) \ + { \ + if (!PanicYesNo(_fmt_, ##__VA_ARGS__)) \ + Crash(); \ + } \ + } while (0)*/ + +#define DEBUG_ASSERT_MSG(_t_, _a_, _msg_, ...) \ + assert(_a_); \ + /*do \ + { \ + if (MAX_LOGLEVEL >= LogTypes::LOG_LEVELS::LDEBUG && !(_a_)) \ + { \ + ERROR_LOG(_t_, _msg_, ##__VA_ARGS__); \ + if (!PanicYesNo(_msg_, ##__VA_ARGS__)) \ + Crash(); \ + } \ + } while (0)*/ + +#define ASSERT(_a_) \ + assert(_a_) \ + /*do \ + { \ + ASSERT_MSG(MASTER_LOG, _a_, \ + _trans("An error occurred.\n\n Line: %d\n File: %s\n\nIgnore and continue?"), \ + __LINE__, __FILE__); \ + } while (0)*/ + +#define DEBUG_ASSERT(_a_) \ + assert(_a_) \ + /*do \ + { \ + if (MAX_LOGLEVEL >= LogTypes::LOG_LEVELS::LDEBUG) \ + ASSERT(_a_); \ + } while (0)*/ diff --git a/src/dolphin/BitSet.h b/src/dolphin/BitSet.h new file mode 100644 index 0000000..d32b020 --- /dev/null +++ b/src/dolphin/BitSet.h @@ -0,0 +1,218 @@ +// This file is under the public domain. + +#pragma once + +#include +#include +#include +#include "../types.h" + +#ifdef _WIN32 + +#include + +namespace Common +{ +template +constexpr int CountSetBits(T v) +{ + // from https://graphics.stanford.edu/~seander/bithacks.html + // GCC has this built in, but MSVC's intrinsic will only emit the actual + // POPCNT instruction, which we're not depending on + v = v - ((v >> 1) & (T) ~(T)0 / 3); + v = (v & (T) ~(T)0 / 15 * 3) + ((v >> 2) & (T) ~(T)0 / 15 * 3); + v = (v + (v >> 4)) & (T) ~(T)0 / 255 * 15; + return (T)(v * ((T) ~(T)0 / 255)) >> (sizeof(T) - 1) * 8; +} +inline int LeastSignificantSetBit(u8 val) +{ + unsigned long index; + _BitScanForward(&index, val); + return (int)index; +} +inline int LeastSignificantSetBit(u16 val) +{ + unsigned long index; + _BitScanForward(&index, val); + return (int)index; +} +inline int LeastSignificantSetBit(u32 val) +{ + unsigned long index; + _BitScanForward(&index, val); + return (int)index; +} +inline int LeastSignificantSetBit(u64 val) +{ + unsigned long index; + _BitScanForward64(&index, val); + return (int)index; +} +#else +namespace Common +{ +constexpr int CountSetBits(u8 val) +{ + return __builtin_popcount(val); +} +constexpr int CountSetBits(u16 val) +{ + return __builtin_popcount(val); +} +constexpr int CountSetBits(u32 val) +{ + return __builtin_popcount(val); +} +constexpr int CountSetBits(u64 val) +{ + return __builtin_popcountll(val); +} +inline int LeastSignificantSetBit(u8 val) +{ + return __builtin_ctz(val); +} +inline int LeastSignificantSetBit(u16 val) +{ + return __builtin_ctz(val); +} +inline int LeastSignificantSetBit(u32 val) +{ + return __builtin_ctz(val); +} +inline int LeastSignificantSetBit(u64 val) +{ + return __builtin_ctzll(val); +} +#endif + +// Similar to std::bitset, this is a class which encapsulates a bitset, i.e. +// using the set bits of an integer to represent a set of integers. Like that +// class, it acts like an array of bools: +// BitSet32 bs; +// bs[1] = true; +// but also like the underlying integer ([0] = least significant bit): +// BitSet32 bs2 = ...; +// bs = (bs ^ bs2) & BitSet32(0xffff); +// The following additional functionality is provided: +// - Construction using an initializer list. +// BitSet bs { 1, 2, 4, 8 }; +// - Efficiently iterating through the set bits: +// for (int i : bs) +// [i is the *index* of a set bit] +// (This uses the appropriate CPU instruction to find the next set bit in one +// operation.) +// - Counting set bits using .Count() - see comment on that method. + +// TODO: use constexpr when MSVC gets out of the Dark Ages + +template +class BitSet +{ + static_assert(!std::is_signed::value, "BitSet should not be used with signed types"); + +public: + // A reference to a particular bit, returned from operator[]. + class Ref + { + public: + constexpr Ref(Ref&& other) : m_bs(other.m_bs), m_mask(other.m_mask) {} + constexpr Ref(BitSet* bs, IntTy mask) : m_bs(bs), m_mask(mask) {} + constexpr operator bool() const { return (m_bs->m_val & m_mask) != 0; } + bool operator=(bool set) + { + m_bs->m_val = (m_bs->m_val & ~m_mask) | (set ? m_mask : 0); + return set; + } + + private: + BitSet* m_bs; + IntTy m_mask; + }; + + // A STL-like iterator is required to be able to use range-based for loops. + class Iterator + { + public: + constexpr Iterator(const Iterator& other) : m_val(other.m_val), m_bit(other.m_bit) {} + constexpr Iterator(IntTy val, int bit) : m_val(val), m_bit(bit) {} + Iterator& operator=(Iterator other) + { + new (this) Iterator(other); + return *this; + } + Iterator& operator++() + { + if (m_val == 0) + { + m_bit = -1; + } + else + { + int bit = LeastSignificantSetBit(m_val); + m_val &= ~(1 << bit); + m_bit = bit; + } + return *this; + } + Iterator operator++(int) + { + Iterator other(*this); + ++*this; + return other; + } + constexpr int operator*() const { return m_bit; } + constexpr bool operator==(Iterator other) const { return m_bit == other.m_bit; } + constexpr bool operator!=(Iterator other) const { return m_bit != other.m_bit; } + + private: + IntTy m_val; + int m_bit; + }; + + constexpr BitSet() : m_val(0) {} + constexpr explicit BitSet(IntTy val) : m_val(val) {} + BitSet(std::initializer_list init) + { + m_val = 0; + for (int bit : init) + m_val |= (IntTy)1 << bit; + } + + constexpr static BitSet AllTrue(size_t count) + { + return BitSet(count == sizeof(IntTy) * 8 ? ~(IntTy)0 : (((IntTy)1 << count) - 1)); + } + + Ref operator[](size_t bit) { return Ref(this, (IntTy)1 << bit); } + constexpr const Ref operator[](size_t bit) const { return (*const_cast(this))[bit]; } + constexpr bool operator==(BitSet other) const { return m_val == other.m_val; } + constexpr bool operator!=(BitSet other) const { return m_val != other.m_val; } + constexpr bool operator<(BitSet other) const { return m_val < other.m_val; } + constexpr bool operator>(BitSet other) const { return m_val > other.m_val; } + constexpr BitSet operator|(BitSet other) const { return BitSet(m_val | other.m_val); } + constexpr BitSet operator&(BitSet other) const { return BitSet(m_val & other.m_val); } + constexpr BitSet operator^(BitSet other) const { return BitSet(m_val ^ other.m_val); } + constexpr BitSet operator~() const { return BitSet(~m_val); } + constexpr BitSet operator<<(IntTy shift) const { return BitSet(m_val << shift); } + constexpr BitSet operator>>(IntTy shift) const { return BitSet(m_val >> shift); } + constexpr explicit operator bool() const { return m_val != 0; } + BitSet& operator|=(BitSet other) { return *this = *this | other; } + BitSet& operator&=(BitSet other) { return *this = *this & other; } + BitSet& operator^=(BitSet other) { return *this = *this ^ other; } + BitSet& operator<<=(IntTy shift) { return *this = *this << shift; } + BitSet& operator>>=(IntTy shift) { return *this = *this >> shift; } + // Warning: Even though on modern CPUs this is a single fast instruction, + // Dolphin's official builds do not currently assume POPCNT support on x86, + // so slower explicit bit twiddling is generated. Still should generally + // be faster than a loop. + constexpr unsigned int Count() const { return CountSetBits(m_val); } + constexpr Iterator begin() const { return ++Iterator(m_val, 0); } + constexpr Iterator end() const { return Iterator(m_val, -1); } + IntTy m_val; +}; +} // namespace Common + +using BitSet8 = Common::BitSet; +using BitSet16 = Common::BitSet; +using BitSet32 = Common::BitSet; +using BitSet64 = Common::BitSet; diff --git a/src/dolphin/CPUDetect.h b/src/dolphin/CPUDetect.h new file mode 100644 index 0000000..bd4fd8d --- /dev/null +++ b/src/dolphin/CPUDetect.h @@ -0,0 +1,76 @@ +// Copyright 2008 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license_dolphin.txt file included. + +// Detect the CPU, so we'll know which optimizations to use +#pragma once + +#include + +enum class CPUVendor +{ + Intel, + AMD, + ARM, + Other, +}; + +struct CPUInfo +{ + CPUVendor vendor = CPUVendor::Intel; + + char cpu_string[0x41] = {}; + char brand_string[0x21] = {}; + bool OS64bit = false; + bool CPU64bit = false; + bool Mode64bit = false; + + bool HTT = false; + int num_cores = 0; + int logical_cpu_count = 0; + + bool bSSE = false; + bool bSSE2 = false; + bool bSSE3 = false; + bool bSSSE3 = false; + bool bPOPCNT = false; + bool bSSE4_1 = false; + bool bSSE4_2 = false; + bool bLZCNT = false; + bool bSSE4A = false; + bool bAVX = false; + bool bAVX2 = false; + bool bBMI1 = false; + bool bBMI2 = false; + bool bFMA = false; + bool bFMA4 = false; + bool bAES = false; + // FXSAVE/FXRSTOR + bool bFXSR = false; + bool bMOVBE = false; + // This flag indicates that the hardware supports some mode + // in which denormal inputs _and_ outputs are automatically set to (signed) zero. + bool bFlushToZero = false; + bool bLAHFSAHF64 = false; + bool bLongMode = false; + bool bAtom = false; + + // ARMv8 specific + bool bFP = false; + bool bASIMD = false; + bool bCRC32 = false; + bool bSHA1 = false; + bool bSHA2 = false; + + // Call Detect() + explicit CPUInfo(); + + // Turn the CPU info into a string we can show + std::string Summarize(); + +private: + // Detects the various CPU features + void Detect(); +}; + +extern CPUInfo cpu_info; diff --git a/src/dolphin/CodeBlock.h b/src/dolphin/CodeBlock.h new file mode 100644 index 0000000..1434297 --- /dev/null +++ b/src/dolphin/CodeBlock.h @@ -0,0 +1,121 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license_dolphin.txt file included. + +#pragma once + +#include +#include + +#include "Assert.h" +#include "../types.h" +#include "MemoryUtil.h" + +namespace Common +{ +// Everything that needs to generate code should inherit from this. +// You get memory management for free, plus, you can use all emitter functions without +// having to prefix them with gen-> or something similar. +// Example implementation: +// class JIT : public CodeBlock {} +template +class CodeBlock : public T +{ +private: + // A privately used function to set the executable RAM space to something invalid. + // For debugging usefulness it should be used to set the RAM to a host specific breakpoint + // instruction + virtual void PoisonMemory() = 0; + +protected: + u8* region = nullptr; + // Size of region we can use. + size_t region_size = 0; + // Original size of the region we allocated. + size_t total_region_size = 0; + + bool m_is_child = false; + std::vector m_children; + +public: + CodeBlock() = default; + virtual ~CodeBlock() + { + if (region) + FreeCodeSpace(); + } + CodeBlock(const CodeBlock&) = delete; + CodeBlock& operator=(const CodeBlock&) = delete; + CodeBlock(CodeBlock&&) = delete; + CodeBlock& operator=(CodeBlock&&) = delete; + + // Call this before you generate any code. + void AllocCodeSpace(size_t size) + { + region_size = size; + total_region_size = size; + region = static_cast(Common::AllocateExecutableMemory(total_region_size)); + T::SetCodePtr(region); + } + + // Always clear code space with breakpoints, so that if someone accidentally executes + // uninitialized, it just breaks into the debugger. + void ClearCodeSpace() + { + PoisonMemory(); + ResetCodePtr(); + } + + // Call this when shutting down. Don't rely on the destructor, even though it'll do the job. + void FreeCodeSpace() + { + ASSERT(!m_is_child); + Common::FreeMemoryPages(region, total_region_size); + region = nullptr; + region_size = 0; + total_region_size = 0; + for (CodeBlock* child : m_children) + { + child->region = nullptr; + child->region_size = 0; + child->total_region_size = 0; + } + } + + bool IsInSpace(const u8* ptr) const { return ptr >= region && ptr < (region + region_size); } + // Cannot currently be undone. Will write protect the entire code region. + // Start over if you need to change the code (call FreeCodeSpace(), AllocCodeSpace()). + void WriteProtect() { Common::WriteProtectMemory(region, region_size, true); } + void ResetCodePtr() { T::SetCodePtr(region); } + size_t GetSpaceLeft() const + { + ASSERT(static_cast(T::GetCodePtr() - region) < region_size); + return region_size - (T::GetCodePtr() - region); + } + + bool IsAlmostFull() const + { + // This should be bigger than the biggest block ever. + return GetSpaceLeft() < 0x10000; + } + + bool HasChildren() const { return region_size != total_region_size; } + u8* AllocChildCodeSpace(size_t child_size) + { + ASSERT_MSG(DYNA_REC, child_size < GetSpaceLeft(), "Insufficient space for child allocation."); + u8* child_region = region + region_size - child_size; + region_size -= child_size; + return child_region; + } + void AddChildCodeSpace(CodeBlock* child, size_t child_size) + { + u8* child_region = AllocChildCodeSpace(child_size); + child->m_is_child = true; + child->region = child_region; + child->region_size = child_size; + child->total_region_size = child_size; + child->ResetCodePtr(); + m_children.emplace_back(child); + } +}; +} // namespace Common diff --git a/src/dolphin/CommonFuncs.cpp b/src/dolphin/CommonFuncs.cpp new file mode 100644 index 0000000..f85051d --- /dev/null +++ b/src/dolphin/CommonFuncs.cpp @@ -0,0 +1,52 @@ +// Copyright 2009 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license_dolphin.txt file included. + +#include +#include +#include +#include + +#include "CommonFuncs.h" + +#ifdef _WIN32 +#include +#define strerror_r(err, buf, len) strerror_s(buf, len, err) +#endif + +constexpr size_t BUFFER_SIZE = 256; + +// Wrapper function to get last strerror(errno) string. +// This function might change the error code. +std::string LastStrerrorString() +{ + char error_message[BUFFER_SIZE]; + + // There are two variants of strerror_r. The XSI version stores the message to the passed-in + // buffer and returns an int (0 on success). The GNU version returns a pointer to the message, + // which might have been stored in the passed-in buffer or might be a static string. + + // We check defines in order to figure out variant is in use, and we store the returned value + // to a variable so that we'll get a compile-time check that our assumption was correct. + +#if defined(__GLIBC__) && (_GNU_SOURCE || (_POSIX_C_SOURCE < 200112L && _XOPEN_SOURCE < 600)) + const char* str = strerror_r(errno, error_message, BUFFER_SIZE); + return std::string(str); +#else + int error_code = strerror_r(errno, error_message, BUFFER_SIZE); + return error_code == 0 ? std::string(error_message) : ""; +#endif +} + +#ifdef _WIN32 +// Wrapper function to get GetLastError() string. +// This function might change the error code. +std::string GetLastErrorString() +{ + char error_message[BUFFER_SIZE]; + + FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), error_message, BUFFER_SIZE, nullptr); + return std::string(error_message); +} +#endif diff --git a/src/dolphin/CommonFuncs.h b/src/dolphin/CommonFuncs.h new file mode 100644 index 0000000..708fbc3 --- /dev/null +++ b/src/dolphin/CommonFuncs.h @@ -0,0 +1,58 @@ +// Copyright 2009 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license_dolphin.txt file included. + +#pragma once + +#include +#include +#include "../types.h" + +// Will fail to compile on a non-array: +template +constexpr size_t ArraySize(T (&arr)[N]) +{ + return N; +} + +#ifndef _WIN32 + +// go to debugger mode +#define Crash() \ + { \ + __builtin_trap(); \ + } + +#else // WIN32 +// Function Cross-Compatibility +#define strcasecmp _stricmp +#define strncasecmp _strnicmp +#define unlink _unlink +#define vscprintf _vscprintf + +// 64 bit offsets for Windows +#define fseeko _fseeki64 +#define ftello _ftelli64 +#define atoll _atoi64 +#define stat _stat64 +#define fstat _fstat64 +#define fileno _fileno + +extern "C" { +__declspec(dllimport) void __stdcall DebugBreak(void); +} +#define Crash() \ + { \ + DebugBreak(); \ + } +#endif // WIN32 ndef + +// Wrapper function to get last strerror(errno) string. +// This function might change the error code. +std::string LastStrerrorString(); + +#ifdef _WIN32 +// Wrapper function to get GetLastError() string. +// This function might change the error code. +std::string GetLastErrorString(); +#endif diff --git a/src/dolphin/Intrinsics.h b/src/dolphin/Intrinsics.h new file mode 100644 index 0000000..483f219 --- /dev/null +++ b/src/dolphin/Intrinsics.h @@ -0,0 +1,72 @@ +// Copyright 2015 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license_dolphin.txt file included. + +#pragma once + +#if defined(_M_X86) + +/** + * It is assumed that all compilers used to build Dolphin support intrinsics up to and including + * SSE 4.2 on x86/x64. + */ + +#if defined(__GNUC__) || defined(__clang__) + +/** + * Due to limitations in GCC, SSE intrinsics are only available when compiling with the + * corresponding instruction set enabled. However, using the target attribute, we can compile + * single functions with a different target instruction set, while still creating a generic build. + * + * Since this instruction set is enabled per-function, any callers should verify that the + * instruction set is supported at runtime before calling it, and provide a fallback implementation + * when not supported. + * + * When building with -march=native, or enabling the instruction sets in the compile flags, permit + * usage of the instrinsics without any function attributes. If the command-line architecture does + * not support this instruction set, enable it via function targeting. + */ + +#include +#ifndef __SSE4_2__ +#define FUNCTION_TARGET_SSE42 [[gnu::target("sse4.2")]] +#endif +#ifndef __SSE4_1__ +#define FUNCTION_TARGET_SSR41 [[gnu::target("sse4.1")]] +#endif +#ifndef __SSSE3__ +#define FUNCTION_TARGET_SSSE3 [[gnu::target("ssse3")]] +#endif +#ifndef __SSE3__ +#define FUNCTION_TARGET_SSE3 [[gnu::target("sse3")]] +#endif + +#elif defined(_MSC_VER) || defined(__INTEL_COMPILER) + +/** + * MSVC and ICC support intrinsics for any instruction set without any function attributes. + */ +#include + +#endif // defined(_MSC_VER) || defined(__INTEL_COMPILER) + +#endif // _M_X86 + +/** + * Define the FUNCTION_TARGET macros to nothing if they are not needed, or not on an X86 platform. + * This way when a function is defined with FUNCTION_TARGET you don't need to define a second + * version without the macro around a #ifdef guard. Be careful when using intrinsics, as all use + * should still be placed around a #ifdef _M_X86 if the file is compiled on all architectures. + */ +#ifndef FUNCTION_TARGET_SSE42 +#define FUNCTION_TARGET_SSE42 +#endif +#ifndef FUNCTION_TARGET_SSR41 +#define FUNCTION_TARGET_SSR41 +#endif +#ifndef FUNCTION_TARGET_SSSE3 +#define FUNCTION_TARGET_SSSE3 +#endif +#ifndef FUNCTION_TARGET_SSE3 +#define FUNCTION_TARGET_SSE3 +#endif diff --git a/src/dolphin/Log.h b/src/dolphin/Log.h new file mode 100644 index 0000000..21e69a5 --- /dev/null +++ b/src/dolphin/Log.h @@ -0,0 +1,20 @@ +#pragma once + +#include "CommonFuncs.h" + +#include + +#define PanicAlert(msg) \ + do \ + { \ + printf("%s\n", msg); \ + Crash(); \ + } while (false) + +#define DYNA_REC 0 + +#define ERROR_LOG(which, fmt, ...) \ + do \ + { \ + printf(fmt "\n", ## __VA_ARGS__); \ + } while (false) diff --git a/src/dolphin/MemoryUtil.cpp b/src/dolphin/MemoryUtil.cpp new file mode 100644 index 0000000..01cb897 --- /dev/null +++ b/src/dolphin/MemoryUtil.cpp @@ -0,0 +1,193 @@ +// Copyright 2008 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license_dolphin.txt file included. + +#include +#include +#include + +#define PanicAlert(fmt, ...) \ + do \ + { \ + printf(fmt "\n", ## __VA_ARGS__); \ + abort(); \ + } while (false) + +#include "../types.h" +#include "CommonFuncs.h" + +#ifdef _WIN32 +#include +//#include "Common/StringUtil.h" +#else +#include +#include +#include +#if defined __APPLE__ || defined __FreeBSD__ || defined __OpenBSD__ +#include +#elif defined __HAIKU__ +#include +#else +#include +#endif +#endif + +namespace Common +{ +// This is purposely not a full wrapper for virtualalloc/mmap, but it +// provides exactly the primitive operations that Dolphin needs. + +void* AllocateExecutableMemory(size_t size) +{ + printf("c\n"); + +#if defined(_WIN32) + void* ptr = VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); +#else + void* ptr = + mmap(nullptr, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0); + + if (ptr == MAP_FAILED) + ptr = nullptr; +#endif + printf("a\n"); + + if (ptr == nullptr) + PanicAlert("Failed to allocate executable memory"); + + printf("b\n"); + + return ptr; +} + +void* AllocateMemoryPages(size_t size) +{ +#ifdef _WIN32 + void* ptr = VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_READWRITE); +#else + void* ptr = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); + + if (ptr == MAP_FAILED) + ptr = nullptr; +#endif + + if (ptr == nullptr) + PanicAlert("Failed to allocate raw memory"); + + return ptr; +} + +void* AllocateAlignedMemory(size_t size, size_t alignment) +{ +#ifdef _WIN32 + void* ptr = _aligned_malloc(size, alignment); +#else + void* ptr = nullptr; + if (posix_memalign(&ptr, alignment, size) != 0) + ERROR_LOG(MEMMAP, "Failed to allocate aligned memory"); +#endif + + if (ptr == nullptr) + PanicAlert("Failed to allocate aligned memory"); + + return ptr; +} + +void FreeMemoryPages(void* ptr, size_t size) +{ + if (ptr) + { +#ifdef _WIN32 + if (!VirtualFree(ptr, 0, MEM_RELEASE)) + PanicAlert("FreeMemoryPages failed!\nVirtualFree: %s", GetLastErrorString().c_str()); +#else + if (munmap(ptr, size) != 0) + PanicAlert("FreeMemoryPages failed!\nmunmap: %s", LastStrerrorString().c_str()); +#endif + } +} + +void FreeAlignedMemory(void* ptr) +{ + if (ptr) + { +#ifdef _WIN32 + _aligned_free(ptr); +#else + free(ptr); +#endif + } +} + +void ReadProtectMemory(void* ptr, size_t size) +{ +#ifdef _WIN32 + DWORD oldValue; + if (!VirtualProtect(ptr, size, PAGE_NOACCESS, &oldValue)) + PanicAlert("ReadProtectMemory failed!\nVirtualProtect: %s", GetLastErrorString().c_str()); +#else + if (mprotect(ptr, size, PROT_NONE) != 0) + PanicAlert("ReadProtectMemory failed!\nmprotect: %s", LastStrerrorString().c_str()); +#endif +} + +void WriteProtectMemory(void* ptr, size_t size, bool allowExecute) +{ +#ifdef _WIN32 + DWORD oldValue; + if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READ : PAGE_READONLY, &oldValue)) + PanicAlert("WriteProtectMemory failed!\nVirtualProtect: %s", GetLastErrorString().c_str()); +#else + if (mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_EXEC) : PROT_READ) != 0) + PanicAlert("WriteProtectMemory failed!\nmprotect: %s", LastStrerrorString().c_str()); +#endif +} + +void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute) +{ +#ifdef _WIN32 + DWORD oldValue; + if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE, &oldValue)) + PanicAlert("UnWriteProtectMemory failed!\nVirtualProtect: %s", GetLastErrorString().c_str()); +#else + if (mprotect(ptr, size, + allowExecute ? (PROT_READ | PROT_WRITE | PROT_EXEC) : PROT_WRITE | PROT_READ) != 0) + { + PanicAlert("UnWriteProtectMemory failed!\nmprotect: %s", LastStrerrorString().c_str()); + } +#endif +} + +size_t MemPhysical() +{ +#ifdef _WIN32 + MEMORYSTATUSEX memInfo; + memInfo.dwLength = sizeof(MEMORYSTATUSEX); + GlobalMemoryStatusEx(&memInfo); + return memInfo.ullTotalPhys; +#elif defined __APPLE__ || defined __FreeBSD__ || defined __OpenBSD__ + int mib[2]; + size_t physical_memory; + mib[0] = CTL_HW; +#ifdef __APPLE__ + mib[1] = HW_MEMSIZE; +#elif defined __FreeBSD__ + mib[1] = HW_REALMEM; +#elif defined __OpenBSD__ + mib[1] = HW_PHYSMEM; +#endif + size_t length = sizeof(size_t); + sysctl(mib, 2, &physical_memory, &length, NULL, 0); + return physical_memory; +#elif defined __HAIKU__ + system_info sysinfo; + get_system_info(&sysinfo); + return static_cast(sysinfo.max_pages * B_PAGE_SIZE); +#else + struct sysinfo memInfo; + sysinfo(&memInfo); + return (size_t)memInfo.totalram * memInfo.mem_unit; +#endif +} + +} // namespace Common diff --git a/src/dolphin/MemoryUtil.h b/src/dolphin/MemoryUtil.h new file mode 100644 index 0000000..607b7a8 --- /dev/null +++ b/src/dolphin/MemoryUtil.h @@ -0,0 +1,22 @@ +// Copyright 2008 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license_dolphin.txt file included. + +#pragma once + +#include +#include + +namespace Common +{ +void* AllocateExecutableMemory(size_t size); +void* AllocateMemoryPages(size_t size); +void FreeMemoryPages(void* ptr, size_t size); +void* AllocateAlignedMemory(size_t size, size_t alignment); +void FreeAlignedMemory(void* ptr); +void ReadProtectMemory(void* ptr, size_t size); +void WriteProtectMemory(void* ptr, size_t size, bool executable = false); +void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute = false); +size_t MemPhysical(); + +} // namespace Common diff --git a/src/dolphin/license_dolphin.txt b/src/dolphin/license_dolphin.txt new file mode 100644 index 0000000..d511905 --- /dev/null +++ b/src/dolphin/license_dolphin.txt @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/src/dolphin/x64ABI.cpp b/src/dolphin/x64ABI.cpp new file mode 100644 index 0000000..d86a158 --- /dev/null +++ b/src/dolphin/x64ABI.cpp @@ -0,0 +1,119 @@ +// Copyright 2008 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license_dolphin.txt file included. + +#include "../types.h" +#include "x64ABI.h" +#include "x64Emitter.h" + +using namespace Gen; + +// Shared code between Win64 and Unix64 + +void XEmitter::ABI_CalculateFrameSize(BitSet32 mask, size_t rsp_alignment, size_t needed_frame_size, + size_t* shadowp, size_t* subtractionp, size_t* xmm_offsetp) +{ + size_t shadow = 0; +#if defined(_WIN32) + shadow = 0x20; +#endif + + int count = (mask & ABI_ALL_GPRS).Count(); + rsp_alignment -= count * 8; + size_t subtraction = 0; + int fpr_count = (mask & ABI_ALL_FPRS).Count(); + if (fpr_count) + { + // If we have any XMMs to save, we must align the stack here. + subtraction = rsp_alignment & 0xf; + } + subtraction += 16 * fpr_count; + size_t xmm_base_subtraction = subtraction; + subtraction += needed_frame_size; + subtraction += shadow; + // Final alignment. + rsp_alignment -= subtraction; + subtraction += rsp_alignment & 0xf; + + *shadowp = shadow; + *subtractionp = subtraction; + *xmm_offsetp = subtraction - xmm_base_subtraction; +} + +size_t XEmitter::ABI_PushRegistersAndAdjustStack(BitSet32 mask, size_t rsp_alignment, + size_t needed_frame_size) +{ + size_t shadow, subtraction, xmm_offset; + ABI_CalculateFrameSize(mask, rsp_alignment, needed_frame_size, &shadow, &subtraction, + &xmm_offset); + + for (int r : mask& ABI_ALL_GPRS) + PUSH((X64Reg)r); + + if (subtraction) + SUB(64, R(RSP), subtraction >= 0x80 ? Imm32((u32)subtraction) : Imm8((u8)subtraction)); + + for (int x : mask& ABI_ALL_FPRS) + { + MOVAPD(MDisp(RSP, (int)xmm_offset), (X64Reg)(x - 16)); + xmm_offset += 16; + } + + return shadow; +} + +void XEmitter::ABI_PopRegistersAndAdjustStack(BitSet32 mask, size_t rsp_alignment, + size_t needed_frame_size) +{ + size_t shadow, subtraction, xmm_offset; + ABI_CalculateFrameSize(mask, rsp_alignment, needed_frame_size, &shadow, &subtraction, + &xmm_offset); + + for (int x : mask& ABI_ALL_FPRS) + { + MOVAPD((X64Reg)(x - 16), MDisp(RSP, (int)xmm_offset)); + xmm_offset += 16; + } + + if (subtraction) + ADD(64, R(RSP), subtraction >= 0x80 ? Imm32((u32)subtraction) : Imm8((u8)subtraction)); + + for (int r = 15; r >= 0; r--) + { + if (mask[r]) + POP((X64Reg)r); + } +} + +void XEmitter::MOVTwo(int bits, Gen::X64Reg dst1, Gen::X64Reg src1, s32 offset1, Gen::X64Reg dst2, + Gen::X64Reg src2) +{ + if (dst1 == src2 && dst2 == src1) + { + XCHG(bits, R(src1), R(src2)); + if (offset1) + ADD(bits, R(dst1), Imm32(offset1)); + } + else if (src2 != dst1) + { + if (dst1 != src1 && offset1) + LEA(bits, dst1, MDisp(src1, offset1)); + else if (dst1 != src1) + MOV(bits, R(dst1), R(src1)); + else if (offset1) + ADD(bits, R(dst1), Imm32(offset1)); + if (dst2 != src2) + MOV(bits, R(dst2), R(src2)); + } + else + { + if (dst2 != src2) + MOV(bits, R(dst2), R(src2)); + if (dst1 != src1 && offset1) + LEA(bits, dst1, MDisp(src1, offset1)); + else if (dst1 != src1) + MOV(bits, R(dst1), R(src1)); + else if (offset1) + ADD(bits, R(dst1), Imm32(offset1)); + } +} diff --git a/src/dolphin/x64ABI.h b/src/dolphin/x64ABI.h new file mode 100644 index 0000000..997782e --- /dev/null +++ b/src/dolphin/x64ABI.h @@ -0,0 +1,57 @@ +// Copyright 2008 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license_dolphin.txt file included. + +#pragma once + +#include "BitSet.h" +#include "x64Reg.h" + +// x64 ABI:s, and helpers to help follow them when JIT-ing code. +// All convensions return values in EAX (+ possibly EDX). + +// Windows 64-bit +// * 4-reg "fastcall" variant, very new-skool stack handling +// * Callee moves stack pointer, to make room for shadow regs for the biggest function _it itself +// calls_ +// * Parameters passed in RCX, RDX, ... further parameters are MOVed into the allocated stack space. +// Scratch: RAX RCX RDX R8 R9 R10 R11 +// Callee-save: RBX RSI RDI RBP R12 R13 R14 R15 +// Parameters: RCX RDX R8 R9, further MOV-ed + +// Linux 64-bit +// * 6-reg "fastcall" variant, old skool stack handling (parameters are pushed) +// Scratch: RAX RCX RDX RSI RDI R8 R9 R10 R11 +// Callee-save: RBX RBP R12 R13 R14 R15 +// Parameters: RDI RSI RDX RCX R8 R9 + +#define ABI_ALL_FPRS BitSet32(0xffff0000) +#define ABI_ALL_GPRS BitSet32(0x0000ffff) + +#ifdef _WIN32 // 64-bit Windows - the really exotic calling convention + +#define ABI_PARAM1 RCX +#define ABI_PARAM2 RDX +#define ABI_PARAM3 R8 +#define ABI_PARAM4 R9 + +// xmm0-xmm15 use the upper 16 bits in the functions that push/pop registers. +#define ABI_ALL_CALLER_SAVED \ + (BitSet32{RAX, RCX, RDX, R8, R9, R10, R11}) +#else // 64-bit Unix / OS X + +#define ABI_PARAM1 RDI +#define ABI_PARAM2 RSI +#define ABI_PARAM3 RDX +#define ABI_PARAM4 RCX +#define ABI_PARAM5 R8 +#define ABI_PARAM6 R9 + +// FIXME: avoid pushing all 16 XMM registers when possible? most functions we call probably +// don't actually clobber them. +#define ABI_ALL_CALLER_SAVED (BitSet32{RAX, RCX, RDX, RDI, RSI, R8, R9, R10, R11} | ABI_ALL_FPRS) +#endif // WIN32 + +#define ABI_ALL_CALLEE_SAVED (~ABI_ALL_CALLER_SAVED) + +#define ABI_RETURN RAX diff --git a/src/dolphin/x64CPUDetect.cpp b/src/dolphin/x64CPUDetect.cpp new file mode 100644 index 0000000..05ee11c --- /dev/null +++ b/src/dolphin/x64CPUDetect.cpp @@ -0,0 +1,274 @@ +// Copyright 2008 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license_dolphin.txt file included. + +#include +#include + +#include "CPUDetect.h" +#include "../types.h" +#include "Intrinsics.h" + +#ifndef _MSVC_VER + +#ifdef __FreeBSD__ +#include + +#include +#include +#endif + +static inline void __cpuidex(int info[4], int function_id, int subfunction_id) +{ +#ifdef __FreeBSD__ + // Despite the name, this is just do_cpuid() with ECX as second input. + cpuid_count((u_int)function_id, (u_int)subfunction_id, (u_int*)info); +#else + info[0] = function_id; // eax + info[2] = subfunction_id; // ecx + __asm__("cpuid" + : "=a"(info[0]), "=b"(info[1]), "=c"(info[2]), "=d"(info[3]) + : "a"(function_id), "c"(subfunction_id)); +#endif +} + +static inline void __cpuid(int info[4], int function_id) +{ + return __cpuidex(info, function_id, 0); +} + +#endif // ifndef _WIN32 + +#ifdef _MSVC_VER + +static u64 xgetbv(u32 index) +{ + return _xgetbv(index); +} +constexpr u32 XCR_XFEATURE_ENABLED_MASK = _XCR_XFEATURE_ENABLED_MASK; + +#else + +static u64 xgetbv(u32 index) +{ + u32 eax, edx; + __asm__ __volatile__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(index)); + return ((u64)edx << 32) | eax; +} +constexpr u32 XCR_XFEATURE_ENABLED_MASK = 0; +#endif // ifdef _WIN32 + +CPUInfo cpu_info; + +CPUInfo::CPUInfo() +{ + Detect(); +} + +// Detects the various CPU features +void CPUInfo::Detect() +{ +#ifdef _M_X86_64 + Mode64bit = true; + OS64bit = true; +#endif + num_cores = 1; + + // Set obvious defaults, for extra safety + if (Mode64bit) + { + bSSE = true; + bSSE2 = true; + bLongMode = true; + } + + // Assume CPU supports the CPUID instruction. Those that don't can barely + // boot modern OS:es anyway. + int cpu_id[4]; + + // Detect CPU's CPUID capabilities, and grab CPU string + __cpuid(cpu_id, 0x00000000); + u32 max_std_fn = cpu_id[0]; // EAX + std::memcpy(&brand_string[0], &cpu_id[1], sizeof(int)); + std::memcpy(&brand_string[4], &cpu_id[3], sizeof(int)); + std::memcpy(&brand_string[8], &cpu_id[2], sizeof(int)); + __cpuid(cpu_id, 0x80000000); + u32 max_ex_fn = cpu_id[0]; + if (!strcmp(brand_string, "GenuineIntel")) + vendor = CPUVendor::Intel; + else if (!strcmp(brand_string, "AuthenticAMD")) + vendor = CPUVendor::AMD; + else + vendor = CPUVendor::Other; + + // Set reasonable default brand string even if brand string not available. + strcpy(cpu_string, brand_string); + + // Detect family and other misc stuff. + bool ht = false; + HTT = ht; + logical_cpu_count = 1; + if (max_std_fn >= 1) + { + __cpuid(cpu_id, 0x00000001); + int family = ((cpu_id[0] >> 8) & 0xf) + ((cpu_id[0] >> 20) & 0xff); + int model = ((cpu_id[0] >> 4) & 0xf) + ((cpu_id[0] >> 12) & 0xf0); + // Detect people unfortunate enough to be running Dolphin on an Atom + if (family == 6 && + (model == 0x1C || model == 0x26 || model == 0x27 || model == 0x35 || model == 0x36 || + model == 0x37 || model == 0x4A || model == 0x4D || model == 0x5A || model == 0x5D)) + bAtom = true; + logical_cpu_count = (cpu_id[1] >> 16) & 0xFF; + ht = (cpu_id[3] >> 28) & 1; + + if ((cpu_id[3] >> 25) & 1) + bSSE = true; + if ((cpu_id[3] >> 26) & 1) + bSSE2 = true; + if ((cpu_id[2]) & 1) + bSSE3 = true; + if ((cpu_id[2] >> 9) & 1) + bSSSE3 = true; + if ((cpu_id[2] >> 19) & 1) + bSSE4_1 = true; + if ((cpu_id[2] >> 20) & 1) + bSSE4_2 = true; + if ((cpu_id[2] >> 22) & 1) + bMOVBE = true; + if ((cpu_id[2] >> 25) & 1) + bAES = true; + + if ((cpu_id[3] >> 24) & 1) + { + // We can use FXSAVE. + bFXSR = true; + } + + // AVX support requires 3 separate checks: + // - Is the AVX bit set in CPUID? + // - Is the XSAVE bit set in CPUID? + // - XGETBV result has the XCR bit set. + if (((cpu_id[2] >> 28) & 1) && ((cpu_id[2] >> 27) & 1)) + { + if ((xgetbv(XCR_XFEATURE_ENABLED_MASK) & 0x6) == 0x6) + { + bAVX = true; + if ((cpu_id[2] >> 12) & 1) + bFMA = true; + } + } + + if (max_std_fn >= 7) + { + __cpuidex(cpu_id, 0x00000007, 0x00000000); + // careful; we can't enable AVX2 unless the XSAVE/XGETBV checks above passed + if ((cpu_id[1] >> 5) & 1) + bAVX2 = bAVX; + if ((cpu_id[1] >> 3) & 1) + bBMI1 = true; + if ((cpu_id[1] >> 8) & 1) + bBMI2 = true; + } + } + + bFlushToZero = bSSE; + + if (max_ex_fn >= 0x80000004) + { + // Extract CPU model string + __cpuid(cpu_id, 0x80000002); + memcpy(cpu_string, cpu_id, sizeof(cpu_id)); + __cpuid(cpu_id, 0x80000003); + memcpy(cpu_string + 16, cpu_id, sizeof(cpu_id)); + __cpuid(cpu_id, 0x80000004); + memcpy(cpu_string + 32, cpu_id, sizeof(cpu_id)); + } + if (max_ex_fn >= 0x80000001) + { + // Check for more features. + __cpuid(cpu_id, 0x80000001); + if (cpu_id[2] & 1) + bLAHFSAHF64 = true; + if ((cpu_id[2] >> 5) & 1) + bLZCNT = true; + if ((cpu_id[2] >> 16) & 1) + bFMA4 = true; + if ((cpu_id[3] >> 29) & 1) + bLongMode = true; + } + + num_cores = (logical_cpu_count == 0) ? 1 : logical_cpu_count; + + if (max_ex_fn >= 0x80000008) + { + // Get number of cores. This is a bit complicated. Following AMD manual here. + __cpuid(cpu_id, 0x80000008); + int apic_id_core_id_size = (cpu_id[2] >> 12) & 0xF; + if (apic_id_core_id_size == 0) + { + if (ht) + { + // New mechanism for modern Intel CPUs. + if (vendor == CPUVendor::Intel) + { + __cpuidex(cpu_id, 0x00000004, 0x00000000); + int cores_x_package = ((cpu_id[0] >> 26) & 0x3F) + 1; + HTT = (cores_x_package < logical_cpu_count); + cores_x_package = ((logical_cpu_count % cores_x_package) == 0) ? cores_x_package : 1; + num_cores = (cores_x_package > 1) ? cores_x_package : num_cores; + logical_cpu_count /= cores_x_package; + } + } + } + else + { + // Use AMD's new method. + num_cores = (cpu_id[2] & 0xFF) + 1; + } + } +} + +// Turn the CPU info into a string we can show +std::string CPUInfo::Summarize() +{ + std::string sum(cpu_string); + sum += " ("; + sum += brand_string; + sum += ")"; + + if (bSSE) + sum += ", SSE"; + if (bSSE2) + { + sum += ", SSE2"; + if (!bFlushToZero) + sum += " (but not DAZ!)"; + } + if (bSSE3) + sum += ", SSE3"; + if (bSSSE3) + sum += ", SSSE3"; + if (bSSE4_1) + sum += ", SSE4.1"; + if (bSSE4_2) + sum += ", SSE4.2"; + if (HTT) + sum += ", HTT"; + if (bAVX) + sum += ", AVX"; + if (bAVX2) + sum += ", AVX2"; + if (bBMI1) + sum += ", BMI1"; + if (bBMI2) + sum += ", BMI2"; + if (bFMA) + sum += ", FMA"; + if (bAES) + sum += ", AES"; + if (bMOVBE) + sum += ", MOVBE"; + if (bLongMode) + sum += ", 64-bit support"; + return sum; +} diff --git a/src/dolphin/x64Emitter.cpp b/src/dolphin/x64Emitter.cpp new file mode 100644 index 0000000..7849624 --- /dev/null +++ b/src/dolphin/x64Emitter.cpp @@ -0,0 +1,3398 @@ +// Copyright 2008 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license_dolphin.txt file included. + +#include +#include + +#include "CPUDetect.h" +#include "../types.h" +#include "Log.h" +#include "x64Emitter.h" +#include "x64Reg.h" + +namespace Gen +{ +// TODO(ector): Add EAX special casing, for ever so slightly smaller code. +struct NormalOpDef +{ + u8 toRm8, toRm32, fromRm8, fromRm32, imm8, imm32, simm8, eaximm8, eaximm32, ext; +}; + +// 0xCC is code for invalid combination of immediates +static const NormalOpDef normalops[11] = { + {0x00, 0x01, 0x02, 0x03, 0x80, 0x81, 0x83, 0x04, 0x05, 0}, // ADD + {0x10, 0x11, 0x12, 0x13, 0x80, 0x81, 0x83, 0x14, 0x15, 2}, // ADC + + {0x28, 0x29, 0x2A, 0x2B, 0x80, 0x81, 0x83, 0x2C, 0x2D, 5}, // SUB + {0x18, 0x19, 0x1A, 0x1B, 0x80, 0x81, 0x83, 0x1C, 0x1D, 3}, // SBB + + {0x20, 0x21, 0x22, 0x23, 0x80, 0x81, 0x83, 0x24, 0x25, 4}, // AND + {0x08, 0x09, 0x0A, 0x0B, 0x80, 0x81, 0x83, 0x0C, 0x0D, 1}, // OR + + {0x30, 0x31, 0x32, 0x33, 0x80, 0x81, 0x83, 0x34, 0x35, 6}, // XOR + {0x88, 0x89, 0x8A, 0x8B, 0xC6, 0xC7, 0xCC, 0xCC, 0xCC, 0}, // MOV + + {0x84, 0x85, 0x84, 0x85, 0xF6, 0xF7, 0xCC, 0xA8, 0xA9, 0}, // TEST (to == from) + {0x38, 0x39, 0x3A, 0x3B, 0x80, 0x81, 0x83, 0x3C, 0x3D, 7}, // CMP + + {0x86, 0x87, 0x86, 0x87, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 7}, // XCHG +}; + +enum NormalSSEOps +{ + sseCMP = 0xC2, + sseADD = 0x58, // ADD + sseSUB = 0x5C, // SUB + sseAND = 0x54, // AND + sseANDN = 0x55, // ANDN + sseOR = 0x56, + sseXOR = 0x57, + sseMUL = 0x59, // MUL + sseDIV = 0x5E, // DIV + sseMIN = 0x5D, // MIN + sseMAX = 0x5F, // MAX + sseCOMIS = 0x2F, // COMIS + sseUCOMIS = 0x2E, // UCOMIS + sseSQRT = 0x51, // SQRT + sseRCP = 0x53, // RCP + sseRSQRT = 0x52, // RSQRT (NO DOUBLE PRECISION!!!) + sseMOVAPfromRM = 0x28, // MOVAP from RM + sseMOVAPtoRM = 0x29, // MOVAP to RM + sseMOVUPfromRM = 0x10, // MOVUP from RM + sseMOVUPtoRM = 0x11, // MOVUP to RM + sseMOVLPfromRM = 0x12, + sseMOVLPtoRM = 0x13, + sseMOVHPfromRM = 0x16, + sseMOVHPtoRM = 0x17, + sseMOVHLPS = 0x12, + sseMOVLHPS = 0x16, + sseMOVDQfromRM = 0x6F, + sseMOVDQtoRM = 0x7F, + sseMASKMOVDQU = 0xF7, + sseLDDQU = 0xF0, + sseSHUF = 0xC6, + sseMOVNTDQ = 0xE7, + sseMOVNTP = 0x2B, +}; + +enum class NormalOp +{ + ADD, + ADC, + SUB, + SBB, + AND, + OR, + XOR, + MOV, + TEST, + CMP, + XCHG, +}; + +enum class FloatOp +{ + LD = 0, + ST = 2, + STP = 3, + LD80 = 5, + STP80 = 7, + + Invalid = -1, +}; + +void XEmitter::SetCodePtr(u8* ptr) +{ + code = ptr; +} + +const u8* XEmitter::GetCodePtr() const +{ + return code; +} + +u8* XEmitter::GetWritableCodePtr() +{ + return code; +} + +void XEmitter::Write8(u8 value) +{ + *code++ = value; +} + +void XEmitter::Write16(u16 value) +{ + std::memcpy(code, &value, sizeof(u16)); + code += sizeof(u16); +} + +void XEmitter::Write32(u32 value) +{ + std::memcpy(code, &value, sizeof(u32)); + code += sizeof(u32); +} + +void XEmitter::Write64(u64 value) +{ + std::memcpy(code, &value, sizeof(u64)); + code += sizeof(u64); +} + +void XEmitter::ReserveCodeSpace(int bytes) +{ + for (int i = 0; i < bytes; i++) + *code++ = 0xCC; +} + +u8* XEmitter::AlignCodeTo(size_t alignment) +{ + ASSERT_MSG(DYNA_REC, alignment != 0 && (alignment & (alignment - 1)) == 0, + "Alignment must be power of two"); + u64 c = reinterpret_cast(code) & (alignment - 1); + if (c) + ReserveCodeSpace(static_cast(alignment - c)); + return code; +} + +u8* XEmitter::AlignCode4() +{ + return AlignCodeTo(4); +} + +u8* XEmitter::AlignCode16() +{ + return AlignCodeTo(16); +} + +u8* XEmitter::AlignCodePage() +{ + return AlignCodeTo(4096); +} + +// This operation modifies flags; check to see the flags are locked. +// If the flags are locked, we should immediately and loudly fail before +// causing a subtle JIT bug. +void XEmitter::CheckFlags() +{ + ASSERT_MSG(DYNA_REC, !flags_locked, "Attempt to modify flags while flags locked!"); +} + +void XEmitter::WriteModRM(int mod, int reg, int rm) +{ + Write8((u8)((mod << 6) | ((reg & 7) << 3) | (rm & 7))); +} + +void XEmitter::WriteSIB(int scale, int index, int base) +{ + Write8((u8)((scale << 6) | ((index & 7) << 3) | (base & 7))); +} + +void OpArg::WriteREX(XEmitter* emit, int opBits, int bits, int customOp) const +{ + if (customOp == -1) + customOp = operandReg; + u8 op = 0x40; + // REX.W (whether operation is a 64-bit operation) + if (opBits == 64) + op |= 8; + // REX.R (whether ModR/M reg field refers to R8-R15. + if (customOp & 8) + op |= 4; + // REX.X (whether ModR/M SIB index field refers to R8-R15) + if (indexReg & 8) + op |= 2; + // REX.B (whether ModR/M rm or SIB base or opcode reg field refers to R8-R15) + if (offsetOrBaseReg & 8) + op |= 1; + // Write REX if wr have REX bits to write, or if the operation accesses + // SIL, DIL, BPL, or SPL. + if (op != 0x40 || (scale == SCALE_NONE && bits == 8 && (offsetOrBaseReg & 0x10c) == 4) || + (opBits == 8 && (customOp & 0x10c) == 4)) + { + emit->Write8(op); + // Check the operation doesn't access AH, BH, CH, or DH. + DEBUG_ASSERT((offsetOrBaseReg & 0x100) == 0); + DEBUG_ASSERT((customOp & 0x100) == 0); + } +} + +void OpArg::WriteVEX(XEmitter* emit, X64Reg regOp1, X64Reg regOp2, int L, int pp, int mmmmm, + int W) const +{ + int R = !(regOp1 & 8); + int X = !(indexReg & 8); + int B = !(offsetOrBaseReg & 8); + + int vvvv = (regOp2 == X64Reg::INVALID_REG) ? 0xf : (regOp2 ^ 0xf); + + // do we need any VEX fields that only appear in the three-byte form? + if (X == 1 && B == 1 && W == 0 && mmmmm == 1) + { + u8 RvvvvLpp = (R << 7) | (vvvv << 3) | (L << 2) | pp; + emit->Write8(0xC5); + emit->Write8(RvvvvLpp); + } + else + { + u8 RXBmmmmm = (R << 7) | (X << 6) | (B << 5) | mmmmm; + u8 WvvvvLpp = (W << 7) | (vvvv << 3) | (L << 2) | pp; + emit->Write8(0xC4); + emit->Write8(RXBmmmmm); + emit->Write8(WvvvvLpp); + } +} + +void OpArg::WriteRest(XEmitter* emit, int extraBytes, X64Reg _operandReg, + bool warn_64bit_offset) const +{ + if (_operandReg == INVALID_REG) + _operandReg = (X64Reg)this->operandReg; + int mod = 0; + int ireg = indexReg; + bool SIB = false; + int _offsetOrBaseReg = this->offsetOrBaseReg; + + if (scale == SCALE_RIP) // Also, on 32-bit, just an immediate address + { + // Oh, RIP addressing. + _offsetOrBaseReg = 5; + emit->WriteModRM(0, _operandReg, _offsetOrBaseReg); + // TODO : add some checks + u64 ripAddr = (u64)emit->GetCodePtr() + 4 + extraBytes; + s64 distance = (s64)offset - (s64)ripAddr; + ASSERT_MSG(DYNA_REC, + (distance < 0x80000000LL && distance >= -0x80000000LL) || !warn_64bit_offset, + "WriteRest: op out of range (0x%" PRIx64 " uses 0x%" PRIx64 ")", ripAddr, offset); + s32 offs = (s32)distance; + emit->Write32((u32)offs); + return; + } + + if (scale == 0) + { + // Oh, no memory, Just a reg. + mod = 3; // 11 + } + else + { + // Ah good, no scaling. + if (scale == SCALE_ATREG && !((_offsetOrBaseReg & 7) == 4 || (_offsetOrBaseReg & 7) == 5)) + { + // Okay, we're good. No SIB necessary. + int ioff = (int)offset; + if (ioff == 0) + { + mod = 0; + } + else if (ioff < -128 || ioff > 127) + { + mod = 2; // 32-bit displacement + } + else + { + mod = 1; // 8-bit displacement + } + } + else if (scale >= SCALE_NOBASE_2 && scale <= SCALE_NOBASE_8) + { + SIB = true; + mod = 0; + _offsetOrBaseReg = 5; + } + else + { + if ((_offsetOrBaseReg & 7) == 4) // this would occupy the SIB encoding :( + { + // So we have to fake it with SIB encoding :( + SIB = true; + } + + if (scale >= SCALE_1 && scale < SCALE_ATREG) + { + SIB = true; + } + + if (scale == SCALE_ATREG && ((_offsetOrBaseReg & 7) == 4)) + { + SIB = true; + ireg = _offsetOrBaseReg; + } + + // Okay, we're fine. Just disp encoding. + // We need displacement. Which size? + int ioff = (int)(s64)offset; + if (ioff < -128 || ioff > 127) + { + mod = 2; // 32-bit displacement + } + else + { + mod = 1; // 8-bit displacement + } + } + } + + // Okay. Time to do the actual writing + // ModRM byte: + int oreg = _offsetOrBaseReg; + if (SIB) + oreg = 4; + + emit->WriteModRM(mod, _operandReg & 7, oreg & 7); + + if (SIB) + { + // SIB byte + int ss; + switch (scale) + { + case SCALE_NONE: + _offsetOrBaseReg = 4; + ss = 0; + break; // RSP + case SCALE_1: + ss = 0; + break; + case SCALE_2: + ss = 1; + break; + case SCALE_4: + ss = 2; + break; + case SCALE_8: + ss = 3; + break; + case SCALE_NOBASE_2: + ss = 1; + break; + case SCALE_NOBASE_4: + ss = 2; + break; + case SCALE_NOBASE_8: + ss = 3; + break; + case SCALE_ATREG: + ss = 0; + break; + default: + ASSERT_MSG(DYNA_REC, 0, "Invalid scale for SIB byte"); + ss = 0; + break; + } + emit->Write8((u8)((ss << 6) | ((ireg & 7) << 3) | (_offsetOrBaseReg & 7))); + } + + if (mod == 1) // 8-bit disp + { + emit->Write8((u8)(s8)(s32)offset); + } + else if (mod == 2 || (scale >= SCALE_NOBASE_2 && scale <= SCALE_NOBASE_8)) // 32-bit disp + { + emit->Write32((u32)offset); + } +} + +// W = operand extended width (1 if 64-bit) +// R = register# upper bit +// X = scale amnt upper bit +// B = base register# upper bit +void XEmitter::Rex(int w, int r, int x, int b) +{ + w = w ? 1 : 0; + r = r ? 1 : 0; + x = x ? 1 : 0; + b = b ? 1 : 0; + u8 rx = (u8)(0x40 | (w << 3) | (r << 2) | (x << 1) | (b)); + if (rx != 0x40) + Write8(rx); +} + +void XEmitter::JMP(const u8* addr, bool force5Bytes) +{ + u64 fn = (u64)addr; + if (!force5Bytes) + { + s64 distance = (s64)(fn - ((u64)code + 2)); + ASSERT_MSG(DYNA_REC, distance >= -0x80 && distance < 0x80, + "Jump target too far away, needs force5Bytes = true"); + // 8 bits will do + Write8(0xEB); + Write8((u8)(s8)distance); + } + else + { + s64 distance = (s64)(fn - ((u64)code + 5)); + + ASSERT_MSG(DYNA_REC, distance >= -0x80000000LL && distance < 0x80000000LL, + "Jump target too far away, needs indirect register"); + Write8(0xE9); + Write32((u32)(s32)distance); + } +} + +void XEmitter::JMPptr(const OpArg& arg2) +{ + OpArg arg = arg2; + if (arg.IsImm()) + ASSERT_MSG(DYNA_REC, 0, "JMPptr - Imm argument"); + arg.operandReg = 4; + arg.WriteREX(this, 0, 0); + Write8(0xFF); + arg.WriteRest(this); +} + +// Can be used to trap other processors, before overwriting their code +// not used in Dolphin +void XEmitter::JMPself() +{ + Write8(0xEB); + Write8(0xFE); +} + +void XEmitter::CALLptr(OpArg arg) +{ + if (arg.IsImm()) + ASSERT_MSG(DYNA_REC, 0, "CALLptr - Imm argument"); + arg.operandReg = 2; + arg.WriteREX(this, 0, 0); + Write8(0xFF); + arg.WriteRest(this); +} + +void XEmitter::CALL(const void* fnptr) +{ + u64 distance = u64(fnptr) - (u64(code) + 5); + ASSERT_MSG(DYNA_REC, distance < 0x0000000080000000ULL || distance >= 0xFFFFFFFF80000000ULL, + "CALL out of range (%p calls %p)", code, fnptr); + Write8(0xE8); + Write32(u32(distance)); +} + +FixupBranch XEmitter::CALL() +{ + FixupBranch branch; + branch.type = FixupBranch::Type::Branch32Bit; + branch.ptr = code + 5; + Write8(0xE8); + Write32(0); + return branch; +} + +FixupBranch XEmitter::J(bool force5bytes) +{ + FixupBranch branch; + branch.type = force5bytes ? FixupBranch::Type::Branch32Bit : FixupBranch::Type::Branch8Bit; + branch.ptr = code + (force5bytes ? 5 : 2); + if (!force5bytes) + { + // 8 bits will do + Write8(0xEB); + Write8(0); + } + else + { + Write8(0xE9); + Write32(0); + } + return branch; +} + +FixupBranch XEmitter::J_CC(CCFlags conditionCode, bool force5bytes) +{ + FixupBranch branch; + branch.type = force5bytes ? FixupBranch::Type::Branch32Bit : FixupBranch::Type::Branch8Bit; + branch.ptr = code + (force5bytes ? 6 : 2); + if (!force5bytes) + { + // 8 bits will do + Write8(0x70 + conditionCode); + Write8(0); + } + else + { + Write8(0x0F); + Write8(0x80 + conditionCode); + Write32(0); + } + return branch; +} + +void XEmitter::J_CC(CCFlags conditionCode, const u8* addr) +{ + u64 fn = (u64)addr; + s64 distance = (s64)(fn - ((u64)code + 2)); + if (distance < -0x80 || distance >= 0x80) + { + distance = (s64)(fn - ((u64)code + 6)); + ASSERT_MSG(DYNA_REC, distance >= -0x80000000LL && distance < 0x80000000LL, + "Jump target too far away, needs indirect register"); + Write8(0x0F); + Write8(0x80 + conditionCode); + Write32((u32)(s32)distance); + } + else + { + Write8(0x70 + conditionCode); + Write8((u8)(s8)distance); + } +} + +void XEmitter::SetJumpTarget(const FixupBranch& branch) +{ + if (branch.type == FixupBranch::Type::Branch8Bit) + { + s64 distance = (s64)(code - branch.ptr); + if (!(distance >= -0x80 && distance < 0x80)) + { + printf("miauz\n"); + } + ASSERT_MSG(DYNA_REC, distance >= -0x80 && distance < 0x80, + "Jump target too far away, needs force5Bytes = true"); + branch.ptr[-1] = (u8)(s8)distance; + } + else if (branch.type == FixupBranch::Type::Branch32Bit) + { + s64 distance = (s64)(code - branch.ptr); + ASSERT_MSG(DYNA_REC, distance >= -0x80000000LL && distance < 0x80000000LL, + "Jump target too far away, needs indirect register"); + + s32 valid_distance = static_cast(distance); + std::memcpy(&branch.ptr[-4], &valid_distance, sizeof(s32)); + } +} + +// Single byte opcodes +// There is no PUSHAD/POPAD in 64-bit mode. +void XEmitter::INT3() +{ + Write8(0xCC); +} +void XEmitter::RET() +{ + Write8(0xC3); +} +void XEmitter::RET_FAST() +{ + Write8(0xF3); + Write8(0xC3); +} // two-byte return (rep ret) - recommended by AMD optimization manual for the case of jumping to + // a ret + +// The first sign of decadence: optimized NOPs. +void XEmitter::NOP(size_t size) +{ + DEBUG_ASSERT((int)size > 0); + while (true) + { + switch (size) + { + case 0: + return; + case 1: + Write8(0x90); + return; + case 2: + Write8(0x66); + Write8(0x90); + return; + case 3: + Write8(0x0F); + Write8(0x1F); + Write8(0x00); + return; + case 4: + Write8(0x0F); + Write8(0x1F); + Write8(0x40); + Write8(0x00); + return; + case 5: + Write8(0x0F); + Write8(0x1F); + Write8(0x44); + Write8(0x00); + Write8(0x00); + return; + case 6: + Write8(0x66); + Write8(0x0F); + Write8(0x1F); + Write8(0x44); + Write8(0x00); + Write8(0x00); + return; + case 7: + Write8(0x0F); + Write8(0x1F); + Write8(0x80); + Write8(0x00); + Write8(0x00); + Write8(0x00); + Write8(0x00); + return; + case 8: + Write8(0x0F); + Write8(0x1F); + Write8(0x84); + Write8(0x00); + Write8(0x00); + Write8(0x00); + Write8(0x00); + Write8(0x00); + return; + case 9: + Write8(0x66); + Write8(0x0F); + Write8(0x1F); + Write8(0x84); + Write8(0x00); + Write8(0x00); + Write8(0x00); + Write8(0x00); + Write8(0x00); + return; + case 10: + Write8(0x66); + Write8(0x66); + Write8(0x0F); + Write8(0x1F); + Write8(0x84); + Write8(0x00); + Write8(0x00); + Write8(0x00); + Write8(0x00); + Write8(0x00); + return; + default: + // Even though x86 instructions are allowed to be up to 15 bytes long, + // AMD advises against using NOPs longer than 11 bytes because they + // carry a performance penalty on CPUs older than AMD family 16h. + Write8(0x66); + Write8(0x66); + Write8(0x66); + Write8(0x0F); + Write8(0x1F); + Write8(0x84); + Write8(0x00); + Write8(0x00); + Write8(0x00); + Write8(0x00); + Write8(0x00); + size -= 11; + continue; + } + } +} + +void XEmitter::PAUSE() +{ + Write8(0xF3); + NOP(); +} // use in tight spinloops for energy saving on some CPU +void XEmitter::CLC() +{ + CheckFlags(); + Write8(0xF8); +} // clear carry +void XEmitter::CMC() +{ + CheckFlags(); + Write8(0xF5); +} // flip carry +void XEmitter::STC() +{ + CheckFlags(); + Write8(0xF9); +} // set carry + +// TODO: xchg ah, al ??? +void XEmitter::XCHG_AHAL() +{ + Write8(0x86); + Write8(0xe0); + // alt. 86 c4 +} + +// These two can not be executed on early Intel 64-bit CPU:s, only on AMD! +void XEmitter::LAHF() +{ + Write8(0x9F); +} +void XEmitter::SAHF() +{ + CheckFlags(); + Write8(0x9E); +} + +void XEmitter::PUSHF() +{ + Write8(0x9C); +} +void XEmitter::POPF() +{ + CheckFlags(); + Write8(0x9D); +} + +void XEmitter::LFENCE() +{ + Write8(0x0F); + Write8(0xAE); + Write8(0xE8); +} +void XEmitter::MFENCE() +{ + Write8(0x0F); + Write8(0xAE); + Write8(0xF0); +} +void XEmitter::SFENCE() +{ + Write8(0x0F); + Write8(0xAE); + Write8(0xF8); +} + +void XEmitter::WriteSimple1Byte(int bits, u8 byte, X64Reg reg) +{ + if (bits == 16) + Write8(0x66); + Rex(bits == 64, 0, 0, (int)reg >> 3); + Write8(byte + ((int)reg & 7)); +} + +void XEmitter::WriteSimple2Byte(int bits, u8 byte1, u8 byte2, X64Reg reg) +{ + if (bits == 16) + Write8(0x66); + Rex(bits == 64, 0, 0, (int)reg >> 3); + Write8(byte1); + Write8(byte2 + ((int)reg & 7)); +} + +void XEmitter::CWD(int bits) +{ + if (bits == 16) + Write8(0x66); + Rex(bits == 64, 0, 0, 0); + Write8(0x99); +} + +void XEmitter::CBW(int bits) +{ + if (bits == 8) + Write8(0x66); + Rex(bits == 32, 0, 0, 0); + Write8(0x98); +} + +// Simple opcodes + +// push/pop do not need wide to be 64-bit +void XEmitter::PUSH(X64Reg reg) +{ + WriteSimple1Byte(32, 0x50, reg); +} +void XEmitter::POP(X64Reg reg) +{ + WriteSimple1Byte(32, 0x58, reg); +} + +void XEmitter::PUSH(int bits, const OpArg& reg) +{ + if (reg.IsSimpleReg()) + PUSH(reg.GetSimpleReg()); + else if (reg.IsImm()) + { + switch (reg.GetImmBits()) + { + case 8: + Write8(0x6A); + Write8((u8)(s8)reg.offset); + break; + case 16: + Write8(0x66); + Write8(0x68); + Write16((u16)(s16)(s32)reg.offset); + break; + case 32: + Write8(0x68); + Write32((u32)reg.offset); + break; + default: + ASSERT_MSG(DYNA_REC, 0, "PUSH - Bad imm bits"); + break; + } + } + else + { + if (bits == 16) + Write8(0x66); + reg.WriteREX(this, bits, bits); + Write8(0xFF); + reg.WriteRest(this, 0, (X64Reg)6); + } +} + +void XEmitter::POP(int /*bits*/, const OpArg& reg) +{ + if (reg.IsSimpleReg()) + POP(reg.GetSimpleReg()); + else + ASSERT_MSG(DYNA_REC, 0, "POP - Unsupported encoding"); +} + +void XEmitter::BSWAP(int bits, X64Reg reg) +{ + if (bits >= 32) + { + WriteSimple2Byte(bits, 0x0F, 0xC8, reg); + } + else if (bits == 16) + { + ROL(16, R(reg), Imm8(8)); + } + else if (bits == 8) + { + // Do nothing - can't bswap a single byte... + } + else + { + ASSERT_MSG(DYNA_REC, 0, "BSWAP - Wrong number of bits"); + } +} + +// Undefined opcode - reserved +// If we ever need a way to always cause a non-breakpoint hard exception... +void XEmitter::UD2() +{ + Write8(0x0F); + Write8(0x0B); +} + +void XEmitter::PREFETCH(PrefetchLevel level, OpArg arg) +{ + ASSERT_MSG(DYNA_REC, !arg.IsImm(), "PREFETCH - Imm argument"); + arg.operandReg = (u8)level; + arg.WriteREX(this, 0, 0); + Write8(0x0F); + Write8(0x18); + arg.WriteRest(this); +} + +void XEmitter::SETcc(CCFlags flag, OpArg dest) +{ + ASSERT_MSG(DYNA_REC, !dest.IsImm(), "SETcc - Imm argument"); + dest.operandReg = 0; + dest.WriteREX(this, 0, 8); + Write8(0x0F); + Write8(0x90 + (u8)flag); + dest.WriteRest(this); +} + +void XEmitter::CMOVcc(int bits, X64Reg dest, OpArg src, CCFlags flag) +{ + ASSERT_MSG(DYNA_REC, !src.IsImm(), "CMOVcc - Imm argument"); + ASSERT_MSG(DYNA_REC, bits != 8, "CMOVcc - 8 bits unsupported"); + if (bits == 16) + Write8(0x66); + src.operandReg = dest; + src.WriteREX(this, bits, bits); + Write8(0x0F); + Write8(0x40 + (u8)flag); + src.WriteRest(this); +} + +void XEmitter::WriteMulDivType(int bits, OpArg src, int ext) +{ + ASSERT_MSG(DYNA_REC, !src.IsImm(), "WriteMulDivType - Imm argument"); + CheckFlags(); + src.operandReg = ext; + if (bits == 16) + Write8(0x66); + src.WriteREX(this, bits, bits, 0); + if (bits == 8) + { + Write8(0xF6); + } + else + { + Write8(0xF7); + } + src.WriteRest(this); +} + +void XEmitter::MUL(int bits, const OpArg& src) +{ + WriteMulDivType(bits, src, 4); +} +void XEmitter::DIV(int bits, const OpArg& src) +{ + WriteMulDivType(bits, src, 6); +} +void XEmitter::IMUL(int bits, const OpArg& src) +{ + WriteMulDivType(bits, src, 5); +} +void XEmitter::IDIV(int bits, const OpArg& src) +{ + WriteMulDivType(bits, src, 7); +} +void XEmitter::NEG(int bits, const OpArg& src) +{ + WriteMulDivType(bits, src, 3); +} +void XEmitter::NOT(int bits, const OpArg& src) +{ + WriteMulDivType(bits, src, 2); +} + +void XEmitter::WriteBitSearchType(int bits, X64Reg dest, OpArg src, u8 byte2, bool rep) +{ + ASSERT_MSG(DYNA_REC, !src.IsImm(), "WriteBitSearchType - Imm argument"); + CheckFlags(); + src.operandReg = (u8)dest; + if (bits == 16) + Write8(0x66); + if (rep) + Write8(0xF3); + src.WriteREX(this, bits, bits); + Write8(0x0F); + Write8(byte2); + src.WriteRest(this); +} + +void XEmitter::MOVNTI(int bits, const OpArg& dest, X64Reg src) +{ + if (bits <= 16) + ASSERT_MSG(DYNA_REC, 0, "MOVNTI - bits<=16"); + WriteBitSearchType(bits, src, dest, 0xC3); +} + +void XEmitter::BSF(int bits, X64Reg dest, const OpArg& src) +{ + WriteBitSearchType(bits, dest, src, 0xBC); +} // Bottom bit to top bit +void XEmitter::BSR(int bits, X64Reg dest, const OpArg& src) +{ + WriteBitSearchType(bits, dest, src, 0xBD); +} // Top bit to bottom bit + +void XEmitter::TZCNT(int bits, X64Reg dest, const OpArg& src) +{ + CheckFlags(); + if (!cpu_info.bBMI1) + PanicAlert("Trying to use BMI1 on a system that doesn't support it. Bad programmer."); + WriteBitSearchType(bits, dest, src, 0xBC, true); +} +void XEmitter::LZCNT(int bits, X64Reg dest, const OpArg& src) +{ + CheckFlags(); + if (!cpu_info.bLZCNT) + PanicAlert("Trying to use LZCNT on a system that doesn't support it. Bad programmer."); + WriteBitSearchType(bits, dest, src, 0xBD, true); +} + +void XEmitter::MOVSX(int dbits, int sbits, X64Reg dest, OpArg src) +{ + ASSERT_MSG(DYNA_REC, !src.IsImm(), "MOVSX - Imm argument"); + if (dbits == sbits) + { + MOV(dbits, R(dest), src); + return; + } + src.operandReg = (u8)dest; + if (dbits == 16) + Write8(0x66); + src.WriteREX(this, dbits, sbits); + if (sbits == 8) + { + Write8(0x0F); + Write8(0xBE); + } + else if (sbits == 16) + { + Write8(0x0F); + Write8(0xBF); + } + else if (sbits == 32 && dbits == 64) + { + Write8(0x63); + } + else + { + Crash(); + } + src.WriteRest(this); +} + +void XEmitter::MOVZX(int dbits, int sbits, X64Reg dest, OpArg src) +{ + ASSERT_MSG(DYNA_REC, !src.IsImm(), "MOVZX - Imm argument"); + if (dbits == sbits) + { + MOV(dbits, R(dest), src); + return; + } + src.operandReg = (u8)dest; + if (dbits == 16) + Write8(0x66); + // the 32bit result is automatically zero extended to 64bit + src.WriteREX(this, dbits == 64 ? 32 : dbits, sbits); + if (sbits == 8) + { + Write8(0x0F); + Write8(0xB6); + } + else if (sbits == 16) + { + Write8(0x0F); + Write8(0xB7); + } + else if (sbits == 32 && dbits == 64) + { + Write8(0x8B); + } + else + { + ASSERT_MSG(DYNA_REC, 0, "MOVZX - Invalid size"); + } + src.WriteRest(this); +} + +void XEmitter::WriteMOVBE(int bits, u8 op, X64Reg reg, const OpArg& arg) +{ + ASSERT_MSG(DYNA_REC, cpu_info.bMOVBE, "Generating MOVBE on a system that does not support it."); + if (bits == 8) + { + MOV(8, op & 1 ? arg : R(reg), op & 1 ? R(reg) : arg); + return; + } + if (bits == 16) + Write8(0x66); + ASSERT_MSG(DYNA_REC, !arg.IsSimpleReg() && !arg.IsImm(), "MOVBE: need r<-m or m<-r!"); + arg.WriteREX(this, bits, bits, reg); + Write8(0x0F); + Write8(0x38); + Write8(op); + arg.WriteRest(this, 0, reg); +} +void XEmitter::MOVBE(int bits, X64Reg dest, const OpArg& src) +{ + WriteMOVBE(bits, 0xF0, dest, src); +} +void XEmitter::MOVBE(int bits, const OpArg& dest, X64Reg src) +{ + WriteMOVBE(bits, 0xF1, src, dest); +} + +void XEmitter::LoadAndSwap(int size, X64Reg dst, const OpArg& src, bool sign_extend, MovInfo* info) +{ + if (info) + { + info->address = GetWritableCodePtr(); + info->nonAtomicSwapStore = false; + } + + switch (size) + { + case 8: + if (sign_extend) + MOVSX(32, 8, dst, src); + else + MOVZX(32, 8, dst, src); + break; + case 16: + MOVZX(32, 16, dst, src); + if (sign_extend) + { + BSWAP(32, dst); + SAR(32, R(dst), Imm8(16)); + } + else + { + ROL(16, R(dst), Imm8(8)); + } + break; + case 32: + case 64: + if (cpu_info.bMOVBE) + { + MOVBE(size, dst, src); + } + else + { + MOV(size, R(dst), src); + BSWAP(size, dst); + } + break; + } +} + +void XEmitter::SwapAndStore(int size, const OpArg& dst, X64Reg src, MovInfo* info) +{ + if (cpu_info.bMOVBE) + { + if (info) + { + info->address = GetWritableCodePtr(); + info->nonAtomicSwapStore = false; + } + MOVBE(size, dst, src); + } + else + { + BSWAP(size, src); + if (info) + { + info->address = GetWritableCodePtr(); + info->nonAtomicSwapStore = true; + info->nonAtomicSwapStoreSrc = src; + } + MOV(size, dst, R(src)); + } +} + +void XEmitter::LEA(int bits, X64Reg dest, OpArg src) +{ + ASSERT_MSG(DYNA_REC, !src.IsImm(), "LEA - Imm argument"); + src.operandReg = (u8)dest; + if (bits == 16) + Write8(0x66); // TODO: performance warning + src.WriteREX(this, bits, bits); + Write8(0x8D); + src.WriteRest(this, 0, INVALID_REG, bits == 64); +} + +// shift can be either imm8 or cl +void XEmitter::WriteShift(int bits, OpArg dest, const OpArg& shift, int ext) +{ + CheckFlags(); + bool writeImm = false; + if (dest.IsImm()) + { + ASSERT_MSG(DYNA_REC, 0, "WriteShift - can't shift imms"); + } + if ((shift.IsSimpleReg() && shift.GetSimpleReg() != ECX) || + (shift.IsImm() && shift.GetImmBits() != 8)) + { + ASSERT_MSG(DYNA_REC, 0, "WriteShift - illegal argument"); + } + dest.operandReg = ext; + if (bits == 16) + Write8(0x66); + dest.WriteREX(this, bits, bits, 0); + if (shift.GetImmBits() == 8) + { + // ok an imm + u8 imm = (u8)shift.offset; + if (imm == 1) + { + Write8(bits == 8 ? 0xD0 : 0xD1); + } + else + { + writeImm = true; + Write8(bits == 8 ? 0xC0 : 0xC1); + } + } + else + { + Write8(bits == 8 ? 0xD2 : 0xD3); + } + dest.WriteRest(this, writeImm ? 1 : 0); + if (writeImm) + Write8((u8)shift.offset); +} + +// large rotates and shift are slower on Intel than AMD +// Intel likes to rotate by 1, and the op is smaller too +void XEmitter::ROL(int bits, const OpArg& dest, const OpArg& shift) +{ + WriteShift(bits, dest, shift, 0); +} +void XEmitter::ROR_(int bits, const OpArg& dest, const OpArg& shift) +{ + WriteShift(bits, dest, shift, 1); +} +void XEmitter::RCL(int bits, const OpArg& dest, const OpArg& shift) +{ + WriteShift(bits, dest, shift, 2); +} +void XEmitter::RCR(int bits, const OpArg& dest, const OpArg& shift) +{ + WriteShift(bits, dest, shift, 3); +} +void XEmitter::SHL(int bits, const OpArg& dest, const OpArg& shift) +{ + WriteShift(bits, dest, shift, 4); +} +void XEmitter::SHR(int bits, const OpArg& dest, const OpArg& shift) +{ + WriteShift(bits, dest, shift, 5); +} +void XEmitter::SAR(int bits, const OpArg& dest, const OpArg& shift) +{ + WriteShift(bits, dest, shift, 7); +} + +// index can be either imm8 or register, don't use memory destination because it's slow +void XEmitter::WriteBitTest(int bits, const OpArg& dest, const OpArg& index, int ext) +{ + CheckFlags(); + if (dest.IsImm()) + { + ASSERT_MSG(DYNA_REC, 0, "WriteBitTest - can't test imms"); + } + if ((index.IsImm() && index.GetImmBits() != 8)) + { + ASSERT_MSG(DYNA_REC, 0, "WriteBitTest - illegal argument"); + } + if (bits == 16) + Write8(0x66); + if (index.IsImm()) + { + dest.WriteREX(this, bits, bits); + Write8(0x0F); + Write8(0xBA); + dest.WriteRest(this, 1, (X64Reg)ext); + Write8((u8)index.offset); + } + else + { + X64Reg operand = index.GetSimpleReg(); + dest.WriteREX(this, bits, bits, operand); + Write8(0x0F); + Write8(0x83 + 8 * ext); + dest.WriteRest(this, 1, operand); + } +} + +void XEmitter::BT(int bits, const OpArg& dest, const OpArg& index) +{ + WriteBitTest(bits, dest, index, 4); +} +void XEmitter::BTS(int bits, const OpArg& dest, const OpArg& index) +{ + WriteBitTest(bits, dest, index, 5); +} +void XEmitter::BTR(int bits, const OpArg& dest, const OpArg& index) +{ + WriteBitTest(bits, dest, index, 6); +} +void XEmitter::BTC(int bits, const OpArg& dest, const OpArg& index) +{ + WriteBitTest(bits, dest, index, 7); +} + +// shift can be either imm8 or cl +void XEmitter::SHRD(int bits, const OpArg& dest, const OpArg& src, const OpArg& shift) +{ + CheckFlags(); + if (dest.IsImm()) + { + ASSERT_MSG(DYNA_REC, 0, "SHRD - can't use imms as destination"); + } + if (!src.IsSimpleReg()) + { + ASSERT_MSG(DYNA_REC, 0, "SHRD - must use simple register as source"); + } + if ((shift.IsSimpleReg() && shift.GetSimpleReg() != ECX) || + (shift.IsImm() && shift.GetImmBits() != 8)) + { + ASSERT_MSG(DYNA_REC, 0, "SHRD - illegal shift"); + } + if (bits == 16) + Write8(0x66); + X64Reg operand = src.GetSimpleReg(); + dest.WriteREX(this, bits, bits, operand); + if (shift.GetImmBits() == 8) + { + Write8(0x0F); + Write8(0xAC); + dest.WriteRest(this, 1, operand); + Write8((u8)shift.offset); + } + else + { + Write8(0x0F); + Write8(0xAD); + dest.WriteRest(this, 0, operand); + } +} + +void XEmitter::SHLD(int bits, const OpArg& dest, const OpArg& src, const OpArg& shift) +{ + CheckFlags(); + if (dest.IsImm()) + { + ASSERT_MSG(DYNA_REC, 0, "SHLD - can't use imms as destination"); + } + if (!src.IsSimpleReg()) + { + ASSERT_MSG(DYNA_REC, 0, "SHLD - must use simple register as source"); + } + if ((shift.IsSimpleReg() && shift.GetSimpleReg() != ECX) || + (shift.IsImm() && shift.GetImmBits() != 8)) + { + ASSERT_MSG(DYNA_REC, 0, "SHLD - illegal shift"); + } + if (bits == 16) + Write8(0x66); + X64Reg operand = src.GetSimpleReg(); + dest.WriteREX(this, bits, bits, operand); + if (shift.GetImmBits() == 8) + { + Write8(0x0F); + Write8(0xA4); + dest.WriteRest(this, 1, operand); + Write8((u8)shift.offset); + } + else + { + Write8(0x0F); + Write8(0xA5); + dest.WriteRest(this, 0, operand); + } +} + +void OpArg::WriteSingleByteOp(XEmitter* emit, u8 op, X64Reg _operandReg, int bits) +{ + if (bits == 16) + emit->Write8(0x66); + + this->operandReg = (u8)_operandReg; + WriteREX(emit, bits, bits); + emit->Write8(op); + WriteRest(emit); +} + +// operand can either be immediate or register +void OpArg::WriteNormalOp(XEmitter* emit, bool toRM, NormalOp op, const OpArg& operand, + int bits) const +{ + X64Reg _operandReg; + if (IsImm()) + { + ASSERT_MSG(DYNA_REC, 0, "WriteNormalOp - Imm argument, wrong order"); + } + + if (bits == 16) + emit->Write8(0x66); + + int immToWrite = 0; + const NormalOpDef& op_def = normalops[static_cast(op)]; + + if (operand.IsImm()) + { + WriteREX(emit, bits, bits); + + if (!toRM) + { + ASSERT_MSG(DYNA_REC, 0, "WriteNormalOp - Writing to Imm (!toRM)"); + } + + if (operand.scale == SCALE_IMM8 && bits == 8) + { + // op al, imm8 + if (!scale && offsetOrBaseReg == AL && op_def.eaximm8 != 0xCC) + { + emit->Write8(op_def.eaximm8); + emit->Write8((u8)operand.offset); + return; + } + // mov reg, imm8 + if (!scale && op == NormalOp::MOV) + { + emit->Write8(0xB0 + (offsetOrBaseReg & 7)); + emit->Write8((u8)operand.offset); + return; + } + // op r/m8, imm8 + emit->Write8(op_def.imm8); + immToWrite = 8; + } + else if ((operand.scale == SCALE_IMM16 && bits == 16) || + (operand.scale == SCALE_IMM32 && bits == 32) || + (operand.scale == SCALE_IMM32 && bits == 64)) + { + // Try to save immediate size if we can, but first check to see + // if the instruction supports simm8. + // op r/m, imm8 + if (op_def.simm8 != 0xCC && + ((operand.scale == SCALE_IMM16 && (s16)operand.offset == (s8)operand.offset) || + (operand.scale == SCALE_IMM32 && (s32)operand.offset == (s8)operand.offset))) + { + emit->Write8(op_def.simm8); + immToWrite = 8; + } + else + { + // mov reg, imm + if (!scale && op == NormalOp::MOV && bits != 64) + { + emit->Write8(0xB8 + (offsetOrBaseReg & 7)); + if (bits == 16) + emit->Write16((u16)operand.offset); + else + emit->Write32((u32)operand.offset); + return; + } + // op eax, imm + if (!scale && offsetOrBaseReg == EAX && op_def.eaximm32 != 0xCC) + { + emit->Write8(op_def.eaximm32); + if (bits == 16) + emit->Write16((u16)operand.offset); + else + emit->Write32((u32)operand.offset); + return; + } + // op r/m, imm + emit->Write8(op_def.imm32); + immToWrite = bits == 16 ? 16 : 32; + } + } + else if ((operand.scale == SCALE_IMM8 && bits == 16) || + (operand.scale == SCALE_IMM8 && bits == 32) || + (operand.scale == SCALE_IMM8 && bits == 64)) + { + // op r/m, imm8 + emit->Write8(op_def.simm8); + immToWrite = 8; + } + else if (operand.scale == SCALE_IMM64 && bits == 64) + { + if (scale) + { + ASSERT_MSG(DYNA_REC, 0, + "WriteNormalOp - MOV with 64-bit imm requires register destination"); + } + // mov reg64, imm64 + else if (op == NormalOp::MOV) + { + // movabs reg64, imm64 (10 bytes) + if (static_cast(operand.offset) != static_cast(operand.offset)) + { + emit->Write8(0xB8 + (offsetOrBaseReg & 7)); + emit->Write64(operand.offset); + return; + } + // mov reg64, simm32 (7 bytes) + emit->Write8(op_def.imm32); + immToWrite = 32; + } + else + { + ASSERT_MSG(DYNA_REC, 0, "WriteNormalOp - Only MOV can take 64-bit imm"); + } + } + else + { + ASSERT_MSG(DYNA_REC, 0, "WriteNormalOp - Unhandled case %d %d", operand.scale, bits); + } + + // pass extension in REG of ModRM + _operandReg = static_cast(op_def.ext); + } + else + { + _operandReg = (X64Reg)operand.offsetOrBaseReg; + WriteREX(emit, bits, bits, _operandReg); + // op r/m, reg + if (toRM) + { + emit->Write8(bits == 8 ? op_def.toRm8 : op_def.toRm32); + } + // op reg, r/m + else + { + emit->Write8(bits == 8 ? op_def.fromRm8 : op_def.fromRm32); + } + } + WriteRest(emit, immToWrite >> 3, _operandReg); + switch (immToWrite) + { + case 0: + break; + case 8: + emit->Write8((u8)operand.offset); + break; + case 16: + emit->Write16((u16)operand.offset); + break; + case 32: + emit->Write32((u32)operand.offset); + break; + default: + ASSERT_MSG(DYNA_REC, 0, "WriteNormalOp - Unhandled case"); + } +} + +void XEmitter::WriteNormalOp(int bits, NormalOp op, const OpArg& a1, const OpArg& a2) +{ + if (a1.IsImm()) + { + // Booh! Can't write to an imm + ASSERT_MSG(DYNA_REC, 0, "WriteNormalOp - a1 cannot be imm"); + return; + } + if (a2.IsImm()) + { + a1.WriteNormalOp(this, true, op, a2, bits); + } + else + { + if (a1.IsSimpleReg()) + { + a2.WriteNormalOp(this, false, op, a1, bits); + } + else + { + ASSERT_MSG(DYNA_REC, a2.IsSimpleReg() || a2.IsImm(), + "WriteNormalOp - a1 and a2 cannot both be memory"); + a1.WriteNormalOp(this, true, op, a2, bits); + } + } +} + +void XEmitter::ADD(int bits, const OpArg& a1, const OpArg& a2) +{ + CheckFlags(); + WriteNormalOp(bits, NormalOp::ADD, a1, a2); +} +void XEmitter::ADC(int bits, const OpArg& a1, const OpArg& a2) +{ + CheckFlags(); + WriteNormalOp(bits, NormalOp::ADC, a1, a2); +} +void XEmitter::SUB(int bits, const OpArg& a1, const OpArg& a2) +{ + CheckFlags(); + WriteNormalOp(bits, NormalOp::SUB, a1, a2); +} +void XEmitter::SBB(int bits, const OpArg& a1, const OpArg& a2) +{ + CheckFlags(); + WriteNormalOp(bits, NormalOp::SBB, a1, a2); +} +void XEmitter::AND(int bits, const OpArg& a1, const OpArg& a2) +{ + CheckFlags(); + WriteNormalOp(bits, NormalOp::AND, a1, a2); +} +void XEmitter::OR(int bits, const OpArg& a1, const OpArg& a2) +{ + CheckFlags(); + WriteNormalOp(bits, NormalOp::OR, a1, a2); +} +void XEmitter::XOR(int bits, const OpArg& a1, const OpArg& a2) +{ + CheckFlags(); + WriteNormalOp(bits, NormalOp::XOR, a1, a2); +} +void XEmitter::MOV(int bits, const OpArg& a1, const OpArg& a2) +{ + if (bits == 64 && a1.IsSimpleReg() && a2.scale == SCALE_IMM64 && + a2.offset == static_cast(a2.offset)) + { + WriteNormalOp(32, NormalOp::MOV, a1, a2.AsImm32()); + return; + } + if (a1.IsSimpleReg() && a2.IsSimpleReg() && a1.GetSimpleReg() == a2.GetSimpleReg()) + { + ERROR_LOG(DYNA_REC, "Redundant MOV @ %p - bug in JIT?", code); + } + WriteNormalOp(bits, NormalOp::MOV, a1, a2); +} +void XEmitter::TEST(int bits, const OpArg& a1, const OpArg& a2) +{ + CheckFlags(); + WriteNormalOp(bits, NormalOp::TEST, a1, a2); +} +void XEmitter::CMP(int bits, const OpArg& a1, const OpArg& a2) +{ + CheckFlags(); + WriteNormalOp(bits, NormalOp::CMP, a1, a2); +} +void XEmitter::XCHG(int bits, const OpArg& a1, const OpArg& a2) +{ + WriteNormalOp(bits, NormalOp::XCHG, a1, a2); +} +void XEmitter::CMP_or_TEST(int bits, const OpArg& a1, const OpArg& a2) +{ + CheckFlags(); + if (a1.IsSimpleReg() && a2.IsZero()) // turn 'CMP reg, 0' into shorter 'TEST reg, reg' + { + WriteNormalOp(bits, NormalOp::TEST, a1, a1); + } + else + { + WriteNormalOp(bits, NormalOp::CMP, a1, a2); + } +} + +void XEmitter::MOV_sum(int bits, X64Reg dest, const OpArg& a1, const OpArg& a2) +{ + // This stomps on flags, so ensure they aren't locked + DEBUG_ASSERT(!flags_locked); + + // Zero shortcuts (note that this can generate no code in the case where a1 == dest && a2 == zero + // or a2 == dest && a1 == zero) + if (a1.IsZero()) + { + if (!a2.IsSimpleReg() || a2.GetSimpleReg() != dest) + { + MOV(bits, R(dest), a2); + } + return; + } + if (a2.IsZero()) + { + if (!a1.IsSimpleReg() || a1.GetSimpleReg() != dest) + { + MOV(bits, R(dest), a1); + } + return; + } + + // If dest == a1 or dest == a2 we can simplify this + if (a1.IsSimpleReg() && a1.GetSimpleReg() == dest) + { + ADD(bits, R(dest), a2); + return; + } + + if (a2.IsSimpleReg() && a2.GetSimpleReg() == dest) + { + ADD(bits, R(dest), a1); + return; + } + + // TODO: 32-bit optimizations may apply to other bit sizes (confirm) + if (bits == 32) + { + if (a1.IsImm() && a2.IsImm()) + { + MOV(32, R(dest), Imm32(a1.Imm32() + a2.Imm32())); + return; + } + + if (a1.IsSimpleReg() && a2.IsSimpleReg()) + { + LEA(32, dest, MRegSum(a1.GetSimpleReg(), a2.GetSimpleReg())); + return; + } + + if (a1.IsSimpleReg() && a2.IsImm()) + { + LEA(32, dest, MDisp(a1.GetSimpleReg(), a2.Imm32())); + return; + } + + if (a1.IsImm() && a2.IsSimpleReg()) + { + LEA(32, dest, MDisp(a2.GetSimpleReg(), a1.Imm32())); + return; + } + } + + // Fallback + MOV(bits, R(dest), a1); + ADD(bits, R(dest), a2); +} + +void XEmitter::IMUL(int bits, X64Reg regOp, const OpArg& a1, const OpArg& a2) +{ + CheckFlags(); + if (bits == 8) + { + ASSERT_MSG(DYNA_REC, 0, "IMUL - illegal bit size!"); + return; + } + + if (a1.IsImm()) + { + ASSERT_MSG(DYNA_REC, 0, "IMUL - second arg cannot be imm!"); + return; + } + + if (!a2.IsImm()) + { + ASSERT_MSG(DYNA_REC, 0, "IMUL - third arg must be imm!"); + return; + } + + if (bits == 16) + Write8(0x66); + a1.WriteREX(this, bits, bits, regOp); + + if (a2.GetImmBits() == 8 || (a2.GetImmBits() == 16 && (s8)a2.offset == (s16)a2.offset) || + (a2.GetImmBits() == 32 && (s8)a2.offset == (s32)a2.offset)) + { + Write8(0x6B); + a1.WriteRest(this, 1, regOp); + Write8((u8)a2.offset); + } + else + { + Write8(0x69); + if (a2.GetImmBits() == 16 && bits == 16) + { + a1.WriteRest(this, 2, regOp); + Write16((u16)a2.offset); + } + else if (a2.GetImmBits() == 32 && (bits == 32 || bits == 64)) + { + a1.WriteRest(this, 4, regOp); + Write32((u32)a2.offset); + } + else + { + ASSERT_MSG(DYNA_REC, 0, "IMUL - unhandled case!"); + } + } +} + +void XEmitter::IMUL(int bits, X64Reg regOp, const OpArg& a) +{ + CheckFlags(); + if (bits == 8) + { + ASSERT_MSG(DYNA_REC, 0, "IMUL - illegal bit size!"); + return; + } + + if (a.IsImm()) + { + IMUL(bits, regOp, R(regOp), a); + return; + } + + if (bits == 16) + Write8(0x66); + a.WriteREX(this, bits, bits, regOp); + Write8(0x0F); + Write8(0xAF); + a.WriteRest(this, 0, regOp); +} + +void XEmitter::WriteSSEOp(u8 opPrefix, u16 op, X64Reg regOp, OpArg arg, int extrabytes) +{ + if (opPrefix) + Write8(opPrefix); + arg.operandReg = regOp; + arg.WriteREX(this, 0, 0); + Write8(0x0F); + if (op > 0xFF) + Write8((op >> 8) & 0xFF); + Write8(op & 0xFF); + arg.WriteRest(this, extrabytes); +} + +static int GetVEXmmmmm(u16 op) +{ + // Currently, only 0x38 and 0x3A are used as secondary escape byte. + if ((op >> 8) == 0x3A) + return 3; + else if ((op >> 8) == 0x38) + return 2; + else + return 1; +} + +static int GetVEXpp(u8 opPrefix) +{ + if (opPrefix == 0x66) + return 1; + else if (opPrefix == 0xF3) + return 2; + else if (opPrefix == 0xF2) + return 3; + else + return 0; +} + +void XEmitter::WriteVEXOp(u8 opPrefix, u16 op, X64Reg regOp1, X64Reg regOp2, const OpArg& arg, + int W, int extrabytes) +{ + int mmmmm = GetVEXmmmmm(op); + int pp = GetVEXpp(opPrefix); + // FIXME: we currently don't support 256-bit instructions, and "size" is not the vector size here + arg.WriteVEX(this, regOp1, regOp2, 0, pp, mmmmm, W); + Write8(op & 0xFF); + arg.WriteRest(this, extrabytes, regOp1); +} + +void XEmitter::WriteVEXOp4(u8 opPrefix, u16 op, X64Reg regOp1, X64Reg regOp2, const OpArg& arg, + X64Reg regOp3, int W) +{ + WriteVEXOp(opPrefix, op, regOp1, regOp2, arg, W, 1); + Write8((u8)regOp3 << 4); +} + +void XEmitter::WriteAVXOp(u8 opPrefix, u16 op, X64Reg regOp1, X64Reg regOp2, const OpArg& arg, + int W, int extrabytes) +{ + if (!cpu_info.bAVX) + PanicAlert("Trying to use AVX on a system that doesn't support it. Bad programmer."); + WriteVEXOp(opPrefix, op, regOp1, regOp2, arg, W, extrabytes); +} + +void XEmitter::WriteAVXOp4(u8 opPrefix, u16 op, X64Reg regOp1, X64Reg regOp2, const OpArg& arg, + X64Reg regOp3, int W) +{ + if (!cpu_info.bAVX) + PanicAlert("Trying to use AVX on a system that doesn't support it. Bad programmer."); + WriteVEXOp4(opPrefix, op, regOp1, regOp2, arg, regOp3, W); +} + +void XEmitter::WriteFMA3Op(u8 op, X64Reg regOp1, X64Reg regOp2, const OpArg& arg, int W) +{ + if (!cpu_info.bFMA) + PanicAlert("Trying to use FMA3 on a system that doesn't support it. Computer is v. f'n madd."); + WriteVEXOp(0x66, 0x3800 | op, regOp1, regOp2, arg, W); +} + +void XEmitter::WriteFMA4Op(u8 op, X64Reg dest, X64Reg regOp1, X64Reg regOp2, const OpArg& arg, + int W) +{ + if (!cpu_info.bFMA4) + PanicAlert("Trying to use FMA4 on a system that doesn't support it. Computer is v. f'n madd."); + WriteVEXOp4(0x66, 0x3A00 | op, dest, regOp1, arg, regOp2, W); +} + +void XEmitter::WriteBMIOp(int size, u8 opPrefix, u16 op, X64Reg regOp1, X64Reg regOp2, + const OpArg& arg, int extrabytes) +{ + if (arg.IsImm()) + PanicAlert("BMI1/2 instructions don't support immediate operands."); + if (size != 32 && size != 64) + PanicAlert("BMI1/2 instructions only support 32-bit and 64-bit modes!"); + int W = size == 64; + WriteVEXOp(opPrefix, op, regOp1, regOp2, arg, W, extrabytes); +} + +void XEmitter::WriteBMI1Op(int size, u8 opPrefix, u16 op, X64Reg regOp1, X64Reg regOp2, + const OpArg& arg, int extrabytes) +{ + CheckFlags(); + if (!cpu_info.bBMI1) + PanicAlert("Trying to use BMI1 on a system that doesn't support it. Bad programmer."); + WriteBMIOp(size, opPrefix, op, regOp1, regOp2, arg, extrabytes); +} + +void XEmitter::WriteBMI2Op(int size, u8 opPrefix, u16 op, X64Reg regOp1, X64Reg regOp2, + const OpArg& arg, int extrabytes) +{ + if (!cpu_info.bBMI2) + PanicAlert("Trying to use BMI2 on a system that doesn't support it. Bad programmer."); + WriteBMIOp(size, opPrefix, op, regOp1, regOp2, arg, extrabytes); +} + +void XEmitter::MOVD_xmm(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0x6E, dest, arg, 0); +} +void XEmitter::MOVD_xmm(const OpArg& arg, X64Reg src) +{ + WriteSSEOp(0x66, 0x7E, src, arg, 0); +} + +void XEmitter::MOVQ_xmm(X64Reg dest, OpArg arg) +{ + // Alternate encoding + // This does not display correctly in MSVC's debugger, it thinks it's a MOVD + arg.operandReg = dest; + Write8(0x66); + arg.WriteREX(this, 64, 0); + Write8(0x0f); + Write8(0x6E); + arg.WriteRest(this, 0); +} + +void XEmitter::MOVQ_xmm(OpArg arg, X64Reg src) +{ + if (src > 7 || arg.IsSimpleReg()) + { + // Alternate encoding + // This does not display correctly in MSVC's debugger, it thinks it's a MOVD + arg.operandReg = src; + Write8(0x66); + arg.WriteREX(this, 64, 0); + Write8(0x0f); + Write8(0x7E); + arg.WriteRest(this, 0); + } + else + { + arg.operandReg = src; + arg.WriteREX(this, 0, 0); + Write8(0x66); + Write8(0x0f); + Write8(0xD6); + arg.WriteRest(this, 0); + } +} + +void XEmitter::WriteMXCSR(OpArg arg, int ext) +{ + if (arg.IsImm() || arg.IsSimpleReg()) + ASSERT_MSG(DYNA_REC, 0, "MXCSR - invalid operand"); + + arg.operandReg = ext; + arg.WriteREX(this, 0, 0); + Write8(0x0F); + Write8(0xAE); + arg.WriteRest(this); +} + +void XEmitter::STMXCSR(const OpArg& memloc) +{ + WriteMXCSR(memloc, 3); +} +void XEmitter::LDMXCSR(const OpArg& memloc) +{ + WriteMXCSR(memloc, 2); +} + +void XEmitter::MOVNTDQ(const OpArg& arg, X64Reg regOp) +{ + WriteSSEOp(0x66, sseMOVNTDQ, regOp, arg); +} +void XEmitter::MOVNTPS(const OpArg& arg, X64Reg regOp) +{ + WriteSSEOp(0x00, sseMOVNTP, regOp, arg); +} +void XEmitter::MOVNTPD(const OpArg& arg, X64Reg regOp) +{ + WriteSSEOp(0x66, sseMOVNTP, regOp, arg); +} + +void XEmitter::ADDSS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF3, sseADD, regOp, arg); +} +void XEmitter::ADDSD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF2, sseADD, regOp, arg); +} +void XEmitter::SUBSS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF3, sseSUB, regOp, arg); +} +void XEmitter::SUBSD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF2, sseSUB, regOp, arg); +} +void XEmitter::CMPSS(X64Reg regOp, const OpArg& arg, u8 compare) +{ + WriteSSEOp(0xF3, sseCMP, regOp, arg, 1); + Write8(compare); +} +void XEmitter::CMPSD(X64Reg regOp, const OpArg& arg, u8 compare) +{ + WriteSSEOp(0xF2, sseCMP, regOp, arg, 1); + Write8(compare); +} +void XEmitter::MULSS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF3, sseMUL, regOp, arg); +} +void XEmitter::MULSD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF2, sseMUL, regOp, arg); +} +void XEmitter::DIVSS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF3, sseDIV, regOp, arg); +} +void XEmitter::DIVSD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF2, sseDIV, regOp, arg); +} +void XEmitter::MINSS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF3, sseMIN, regOp, arg); +} +void XEmitter::MINSD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF2, sseMIN, regOp, arg); +} +void XEmitter::MAXSS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF3, sseMAX, regOp, arg); +} +void XEmitter::MAXSD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF2, sseMAX, regOp, arg); +} +void XEmitter::SQRTSS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF3, sseSQRT, regOp, arg); +} +void XEmitter::SQRTSD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF2, sseSQRT, regOp, arg); +} +void XEmitter::RCPSS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF3, sseRCP, regOp, arg); +} +void XEmitter::RSQRTSS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF3, sseRSQRT, regOp, arg); +} + +void XEmitter::ADDPS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x00, sseADD, regOp, arg); +} +void XEmitter::ADDPD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x66, sseADD, regOp, arg); +} +void XEmitter::SUBPS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x00, sseSUB, regOp, arg); +} +void XEmitter::SUBPD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x66, sseSUB, regOp, arg); +} +void XEmitter::CMPPS(X64Reg regOp, const OpArg& arg, u8 compare) +{ + WriteSSEOp(0x00, sseCMP, regOp, arg, 1); + Write8(compare); +} +void XEmitter::CMPPD(X64Reg regOp, const OpArg& arg, u8 compare) +{ + WriteSSEOp(0x66, sseCMP, regOp, arg, 1); + Write8(compare); +} +void XEmitter::ANDPS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x00, sseAND, regOp, arg); +} +void XEmitter::ANDPD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x66, sseAND, regOp, arg); +} +void XEmitter::ANDNPS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x00, sseANDN, regOp, arg); +} +void XEmitter::ANDNPD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x66, sseANDN, regOp, arg); +} +void XEmitter::ORPS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x00, sseOR, regOp, arg); +} +void XEmitter::ORPD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x66, sseOR, regOp, arg); +} +void XEmitter::XORPS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x00, sseXOR, regOp, arg); +} +void XEmitter::XORPD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x66, sseXOR, regOp, arg); +} +void XEmitter::MULPS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x00, sseMUL, regOp, arg); +} +void XEmitter::MULPD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x66, sseMUL, regOp, arg); +} +void XEmitter::DIVPS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x00, sseDIV, regOp, arg); +} +void XEmitter::DIVPD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x66, sseDIV, regOp, arg); +} +void XEmitter::MINPS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x00, sseMIN, regOp, arg); +} +void XEmitter::MINPD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x66, sseMIN, regOp, arg); +} +void XEmitter::MAXPS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x00, sseMAX, regOp, arg); +} +void XEmitter::MAXPD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x66, sseMAX, regOp, arg); +} +void XEmitter::SQRTPS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x00, sseSQRT, regOp, arg); +} +void XEmitter::SQRTPD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x66, sseSQRT, regOp, arg); +} +void XEmitter::RCPPS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x00, sseRCP, regOp, arg); +} +void XEmitter::RSQRTPS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x00, sseRSQRT, regOp, arg); +} +void XEmitter::SHUFPS(X64Reg regOp, const OpArg& arg, u8 shuffle) +{ + WriteSSEOp(0x00, sseSHUF, regOp, arg, 1); + Write8(shuffle); +} +void XEmitter::SHUFPD(X64Reg regOp, const OpArg& arg, u8 shuffle) +{ + WriteSSEOp(0x66, sseSHUF, regOp, arg, 1); + Write8(shuffle); +} + +void XEmitter::COMISS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x00, sseCOMIS, regOp, arg); +} // weird that these should be packed +void XEmitter::COMISD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x66, sseCOMIS, regOp, arg); +} // ordered +void XEmitter::UCOMISS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x00, sseUCOMIS, regOp, arg); +} // unordered +void XEmitter::UCOMISD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x66, sseUCOMIS, regOp, arg); +} + +void XEmitter::MOVAPS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x00, sseMOVAPfromRM, regOp, arg); +} +void XEmitter::MOVAPD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x66, sseMOVAPfromRM, regOp, arg); +} +void XEmitter::MOVAPS(const OpArg& arg, X64Reg regOp) +{ + WriteSSEOp(0x00, sseMOVAPtoRM, regOp, arg); +} +void XEmitter::MOVAPD(const OpArg& arg, X64Reg regOp) +{ + WriteSSEOp(0x66, sseMOVAPtoRM, regOp, arg); +} + +void XEmitter::MOVUPS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x00, sseMOVUPfromRM, regOp, arg); +} +void XEmitter::MOVUPD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x66, sseMOVUPfromRM, regOp, arg); +} +void XEmitter::MOVUPS(const OpArg& arg, X64Reg regOp) +{ + WriteSSEOp(0x00, sseMOVUPtoRM, regOp, arg); +} +void XEmitter::MOVUPD(const OpArg& arg, X64Reg regOp) +{ + WriteSSEOp(0x66, sseMOVUPtoRM, regOp, arg); +} + +void XEmitter::MOVDQA(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x66, sseMOVDQfromRM, regOp, arg); +} +void XEmitter::MOVDQA(const OpArg& arg, X64Reg regOp) +{ + WriteSSEOp(0x66, sseMOVDQtoRM, regOp, arg); +} +void XEmitter::MOVDQU(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF3, sseMOVDQfromRM, regOp, arg); +} +void XEmitter::MOVDQU(const OpArg& arg, X64Reg regOp) +{ + WriteSSEOp(0xF3, sseMOVDQtoRM, regOp, arg); +} + +void XEmitter::MOVSS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF3, sseMOVUPfromRM, regOp, arg); +} +void XEmitter::MOVSD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF2, sseMOVUPfromRM, regOp, arg); +} +void XEmitter::MOVSS(const OpArg& arg, X64Reg regOp) +{ + WriteSSEOp(0xF3, sseMOVUPtoRM, regOp, arg); +} +void XEmitter::MOVSD(const OpArg& arg, X64Reg regOp) +{ + WriteSSEOp(0xF2, sseMOVUPtoRM, regOp, arg); +} + +void XEmitter::MOVLPS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x00, sseMOVLPfromRM, regOp, arg); +} +void XEmitter::MOVLPD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x66, sseMOVLPfromRM, regOp, arg); +} +void XEmitter::MOVLPS(const OpArg& arg, X64Reg regOp) +{ + WriteSSEOp(0x00, sseMOVLPtoRM, regOp, arg); +} +void XEmitter::MOVLPD(const OpArg& arg, X64Reg regOp) +{ + WriteSSEOp(0x66, sseMOVLPtoRM, regOp, arg); +} + +void XEmitter::MOVHPS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x00, sseMOVHPfromRM, regOp, arg); +} +void XEmitter::MOVHPD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x66, sseMOVHPfromRM, regOp, arg); +} +void XEmitter::MOVHPS(const OpArg& arg, X64Reg regOp) +{ + WriteSSEOp(0x00, sseMOVHPtoRM, regOp, arg); +} +void XEmitter::MOVHPD(const OpArg& arg, X64Reg regOp) +{ + WriteSSEOp(0x66, sseMOVHPtoRM, regOp, arg); +} + +void XEmitter::MOVHLPS(X64Reg regOp1, X64Reg regOp2) +{ + WriteSSEOp(0x00, sseMOVHLPS, regOp1, R(regOp2)); +} +void XEmitter::MOVLHPS(X64Reg regOp1, X64Reg regOp2) +{ + WriteSSEOp(0x00, sseMOVLHPS, regOp1, R(regOp2)); +} + +void XEmitter::CVTPS2PD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x00, 0x5A, regOp, arg); +} +void XEmitter::CVTPD2PS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x66, 0x5A, regOp, arg); +} + +void XEmitter::CVTSD2SS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF2, 0x5A, regOp, arg); +} +void XEmitter::CVTSS2SD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF3, 0x5A, regOp, arg); +} +void XEmitter::CVTSD2SI(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF2, 0x2D, regOp, arg); +} +void XEmitter::CVTSS2SI(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF3, 0x2D, regOp, arg); +} +void XEmitter::CVTSI2SD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF2, 0x2A, regOp, arg); +} +void XEmitter::CVTSI2SS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF3, 0x2A, regOp, arg); +} + +void XEmitter::CVTDQ2PD(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF3, 0xE6, regOp, arg); +} +void XEmitter::CVTDQ2PS(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x00, 0x5B, regOp, arg); +} +void XEmitter::CVTPD2DQ(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF2, 0xE6, regOp, arg); +} +void XEmitter::CVTPS2DQ(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x66, 0x5B, regOp, arg); +} + +void XEmitter::CVTTSD2SI(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF2, 0x2C, regOp, arg); +} +void XEmitter::CVTTSS2SI(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF3, 0x2C, regOp, arg); +} +void XEmitter::CVTTPS2DQ(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0xF3, 0x5B, regOp, arg); +} +void XEmitter::CVTTPD2DQ(X64Reg regOp, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xE6, regOp, arg); +} + +void XEmitter::MASKMOVDQU(X64Reg dest, X64Reg src) +{ + WriteSSEOp(0x66, sseMASKMOVDQU, dest, R(src)); +} + +void XEmitter::MOVMSKPS(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x00, 0x50, dest, arg); +} +void XEmitter::MOVMSKPD(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0x50, dest, arg); +} + +void XEmitter::LDDQU(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0xF2, sseLDDQU, dest, arg); +} // For integer data only + +void XEmitter::UNPCKLPS(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x00, 0x14, dest, arg); +} +void XEmitter::UNPCKHPS(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x00, 0x15, dest, arg); +} +void XEmitter::UNPCKLPD(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0x14, dest, arg); +} +void XEmitter::UNPCKHPD(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0x15, dest, arg); +} + +// Pretty much every x86 CPU nowadays supports SSE3, +// but the SSE2 fallbacks are easy. +void XEmitter::MOVSLDUP(X64Reg regOp, const OpArg& arg) +{ + if (cpu_info.bSSE3) + { + WriteSSEOp(0xF3, 0x12, regOp, arg); + } + else + { + if (!arg.IsSimpleReg(regOp)) + MOVAPD(regOp, arg); + UNPCKLPS(regOp, R(regOp)); + } +} +void XEmitter::MOVSHDUP(X64Reg regOp, const OpArg& arg) +{ + if (cpu_info.bSSE3) + { + WriteSSEOp(0xF3, 0x16, regOp, arg); + } + else + { + if (!arg.IsSimpleReg(regOp)) + MOVAPD(regOp, arg); + UNPCKHPS(regOp, R(regOp)); + } +} +void XEmitter::MOVDDUP(X64Reg regOp, const OpArg& arg) +{ + if (cpu_info.bSSE3) + { + WriteSSEOp(0xF2, 0x12, regOp, arg); + } + else + { + if (!arg.IsSimpleReg(regOp)) + MOVSD(regOp, arg); + UNPCKLPD(regOp, R(regOp)); + } +} + +// There are a few more left + +// Also some integer instructions are missing +void XEmitter::PACKSSDW(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0x6B, dest, arg); +} +void XEmitter::PACKSSWB(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0x63, dest, arg); +} +void XEmitter::PACKUSWB(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0x67, dest, arg); +} + +void XEmitter::PUNPCKLBW(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0x60, dest, arg); +} +void XEmitter::PUNPCKLWD(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0x61, dest, arg); +} +void XEmitter::PUNPCKLDQ(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0x62, dest, arg); +} +void XEmitter::PUNPCKLQDQ(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0x6C, dest, arg); +} + +void XEmitter::PSRLW(X64Reg reg, int shift) +{ + WriteSSEOp(0x66, 0x71, (X64Reg)2, R(reg)); + Write8(shift); +} + +void XEmitter::PSRLD(X64Reg reg, int shift) +{ + WriteSSEOp(0x66, 0x72, (X64Reg)2, R(reg)); + Write8(shift); +} + +void XEmitter::PSRLQ(X64Reg reg, int shift) +{ + WriteSSEOp(0x66, 0x73, (X64Reg)2, R(reg)); + Write8(shift); +} + +void XEmitter::PSRLQ(X64Reg reg, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xd3, reg, arg); +} + +void XEmitter::PSRLDQ(X64Reg reg, int shift) +{ + WriteSSEOp(0x66, 0x73, (X64Reg)3, R(reg)); + Write8(shift); +} + +void XEmitter::PSLLW(X64Reg reg, int shift) +{ + WriteSSEOp(0x66, 0x71, (X64Reg)6, R(reg)); + Write8(shift); +} + +void XEmitter::PSLLD(X64Reg reg, int shift) +{ + WriteSSEOp(0x66, 0x72, (X64Reg)6, R(reg)); + Write8(shift); +} + +void XEmitter::PSLLQ(X64Reg reg, int shift) +{ + WriteSSEOp(0x66, 0x73, (X64Reg)6, R(reg)); + Write8(shift); +} + +void XEmitter::PSLLDQ(X64Reg reg, int shift) +{ + WriteSSEOp(0x66, 0x73, (X64Reg)7, R(reg)); + Write8(shift); +} + +// WARNING not REX compatible +void XEmitter::PSRAW(X64Reg reg, int shift) +{ + if (reg > 7) + PanicAlert("The PSRAW-emitter does not support regs above 7"); + Write8(0x66); + Write8(0x0f); + Write8(0x71); + Write8(0xE0 | reg); + Write8(shift); +} + +// WARNING not REX compatible +void XEmitter::PSRAD(X64Reg reg, int shift) +{ + if (reg > 7) + PanicAlert("The PSRAD-emitter does not support regs above 7"); + Write8(0x66); + Write8(0x0f); + Write8(0x72); + Write8(0xE0 | reg); + Write8(shift); +} + +void XEmitter::WriteSSSE3Op(u8 opPrefix, u16 op, X64Reg regOp, const OpArg& arg, int extrabytes) +{ + if (!cpu_info.bSSSE3) + PanicAlert("Trying to use SSSE3 on a system that doesn't support it. Bad programmer."); + WriteSSEOp(opPrefix, op, regOp, arg, extrabytes); +} + +void XEmitter::WriteSSE41Op(u8 opPrefix, u16 op, X64Reg regOp, const OpArg& arg, int extrabytes) +{ + if (!cpu_info.bSSE4_1) + PanicAlert("Trying to use SSE4.1 on a system that doesn't support it. Bad programmer."); + WriteSSEOp(opPrefix, op, regOp, arg, extrabytes); +} + +void XEmitter::PSHUFB(X64Reg dest, const OpArg& arg) +{ + WriteSSSE3Op(0x66, 0x3800, dest, arg); +} +void XEmitter::PTEST(X64Reg dest, const OpArg& arg) +{ + WriteSSE41Op(0x66, 0x3817, dest, arg); +} +void XEmitter::PACKUSDW(X64Reg dest, const OpArg& arg) +{ + WriteSSE41Op(0x66, 0x382b, dest, arg); +} + +void XEmitter::PMOVSXBW(X64Reg dest, const OpArg& arg) +{ + WriteSSE41Op(0x66, 0x3820, dest, arg); +} +void XEmitter::PMOVSXBD(X64Reg dest, const OpArg& arg) +{ + WriteSSE41Op(0x66, 0x3821, dest, arg); +} +void XEmitter::PMOVSXBQ(X64Reg dest, const OpArg& arg) +{ + WriteSSE41Op(0x66, 0x3822, dest, arg); +} +void XEmitter::PMOVSXWD(X64Reg dest, const OpArg& arg) +{ + WriteSSE41Op(0x66, 0x3823, dest, arg); +} +void XEmitter::PMOVSXWQ(X64Reg dest, const OpArg& arg) +{ + WriteSSE41Op(0x66, 0x3824, dest, arg); +} +void XEmitter::PMOVSXDQ(X64Reg dest, const OpArg& arg) +{ + WriteSSE41Op(0x66, 0x3825, dest, arg); +} +void XEmitter::PMOVZXBW(X64Reg dest, const OpArg& arg) +{ + WriteSSE41Op(0x66, 0x3830, dest, arg); +} +void XEmitter::PMOVZXBD(X64Reg dest, const OpArg& arg) +{ + WriteSSE41Op(0x66, 0x3831, dest, arg); +} +void XEmitter::PMOVZXBQ(X64Reg dest, const OpArg& arg) +{ + WriteSSE41Op(0x66, 0x3832, dest, arg); +} +void XEmitter::PMOVZXWD(X64Reg dest, const OpArg& arg) +{ + WriteSSE41Op(0x66, 0x3833, dest, arg); +} +void XEmitter::PMOVZXWQ(X64Reg dest, const OpArg& arg) +{ + WriteSSE41Op(0x66, 0x3834, dest, arg); +} +void XEmitter::PMOVZXDQ(X64Reg dest, const OpArg& arg) +{ + WriteSSE41Op(0x66, 0x3835, dest, arg); +} + +void XEmitter::PBLENDVB(X64Reg dest, const OpArg& arg) +{ + WriteSSE41Op(0x66, 0x3810, dest, arg); +} +void XEmitter::BLENDVPS(X64Reg dest, const OpArg& arg) +{ + WriteSSE41Op(0x66, 0x3814, dest, arg); +} +void XEmitter::BLENDVPD(X64Reg dest, const OpArg& arg) +{ + WriteSSE41Op(0x66, 0x3815, dest, arg); +} +void XEmitter::BLENDPS(X64Reg dest, const OpArg& arg, u8 blend) +{ + WriteSSE41Op(0x66, 0x3A0C, dest, arg, 1); + Write8(blend); +} +void XEmitter::BLENDPD(X64Reg dest, const OpArg& arg, u8 blend) +{ + WriteSSE41Op(0x66, 0x3A0D, dest, arg, 1); + Write8(blend); +} + +void XEmitter::PAND(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xDB, dest, arg); +} +void XEmitter::PANDN(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xDF, dest, arg); +} +void XEmitter::PXOR(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xEF, dest, arg); +} +void XEmitter::POR(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xEB, dest, arg); +} + +void XEmitter::PADDB(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xFC, dest, arg); +} +void XEmitter::PADDW(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xFD, dest, arg); +} +void XEmitter::PADDD(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xFE, dest, arg); +} +void XEmitter::PADDQ(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xD4, dest, arg); +} + +void XEmitter::PADDSB(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xEC, dest, arg); +} +void XEmitter::PADDSW(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xED, dest, arg); +} +void XEmitter::PADDUSB(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xDC, dest, arg); +} +void XEmitter::PADDUSW(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xDD, dest, arg); +} + +void XEmitter::PSUBB(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xF8, dest, arg); +} +void XEmitter::PSUBW(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xF9, dest, arg); +} +void XEmitter::PSUBD(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xFA, dest, arg); +} +void XEmitter::PSUBQ(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xFB, dest, arg); +} + +void XEmitter::PSUBSB(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xE8, dest, arg); +} +void XEmitter::PSUBSW(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xE9, dest, arg); +} +void XEmitter::PSUBUSB(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xD8, dest, arg); +} +void XEmitter::PSUBUSW(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xD9, dest, arg); +} + +void XEmitter::PAVGB(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xE0, dest, arg); +} +void XEmitter::PAVGW(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xE3, dest, arg); +} + +void XEmitter::PCMPEQB(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0x74, dest, arg); +} +void XEmitter::PCMPEQW(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0x75, dest, arg); +} +void XEmitter::PCMPEQD(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0x76, dest, arg); +} + +void XEmitter::PCMPGTB(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0x64, dest, arg); +} +void XEmitter::PCMPGTW(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0x65, dest, arg); +} +void XEmitter::PCMPGTD(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0x66, dest, arg); +} + +void XEmitter::PEXTRW(X64Reg dest, const OpArg& arg, u8 subreg) +{ + WriteSSEOp(0x66, 0xC5, dest, arg); + Write8(subreg); +} +void XEmitter::PINSRW(X64Reg dest, const OpArg& arg, u8 subreg) +{ + WriteSSEOp(0x66, 0xC4, dest, arg); + Write8(subreg); +} +void XEmitter::PINSRD(X64Reg dest, const OpArg& arg, u8 subreg) +{ + WriteSSE41Op(0x66, 0x3A22, dest, arg); + Write8(subreg); +} + +void XEmitter::PMADDWD(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xF5, dest, arg); +} +void XEmitter::PSADBW(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xF6, dest, arg); +} + +void XEmitter::PMAXSW(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xEE, dest, arg); +} +void XEmitter::PMAXUB(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xDE, dest, arg); +} +void XEmitter::PMINSW(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xEA, dest, arg); +} +void XEmitter::PMINUB(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xDA, dest, arg); +} + +void XEmitter::PMOVMSKB(X64Reg dest, const OpArg& arg) +{ + WriteSSEOp(0x66, 0xD7, dest, arg); +} +void XEmitter::PSHUFD(X64Reg regOp, const OpArg& arg, u8 shuffle) +{ + WriteSSEOp(0x66, 0x70, regOp, arg, 1); + Write8(shuffle); +} +void XEmitter::PSHUFLW(X64Reg regOp, const OpArg& arg, u8 shuffle) +{ + WriteSSEOp(0xF2, 0x70, regOp, arg, 1); + Write8(shuffle); +} +void XEmitter::PSHUFHW(X64Reg regOp, const OpArg& arg, u8 shuffle) +{ + WriteSSEOp(0xF3, 0x70, regOp, arg, 1); + Write8(shuffle); +} + +// VEX +void XEmitter::VADDSS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0xF3, sseADD, regOp1, regOp2, arg); +} +void XEmitter::VSUBSS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0xF3, sseSUB, regOp1, regOp2, arg); +} +void XEmitter::VMULSS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0xF3, sseMUL, regOp1, regOp2, arg); +} +void XEmitter::VDIVSS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0xF3, sseDIV, regOp1, regOp2, arg); +} +void XEmitter::VADDPS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x00, sseADD, regOp1, regOp2, arg); +} +void XEmitter::VSUBPS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x00, sseSUB, regOp1, regOp2, arg); +} +void XEmitter::VMULPS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x00, sseMUL, regOp1, regOp2, arg); +} +void XEmitter::VDIVPS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x00, sseDIV, regOp1, regOp2, arg); +} +void XEmitter::VADDSD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0xF2, sseADD, regOp1, regOp2, arg); +} +void XEmitter::VSUBSD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0xF2, sseSUB, regOp1, regOp2, arg); +} +void XEmitter::VMULSD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0xF2, sseMUL, regOp1, regOp2, arg); +} +void XEmitter::VDIVSD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0xF2, sseDIV, regOp1, regOp2, arg); +} +void XEmitter::VADDPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x66, sseADD, regOp1, regOp2, arg); +} +void XEmitter::VSUBPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x66, sseSUB, regOp1, regOp2, arg); +} +void XEmitter::VMULPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x66, sseMUL, regOp1, regOp2, arg); +} +void XEmitter::VDIVPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x66, sseDIV, regOp1, regOp2, arg); +} +void XEmitter::VSQRTSD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0xF2, sseSQRT, regOp1, regOp2, arg); +} +void XEmitter::VCMPPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg, u8 compare) +{ + WriteAVXOp(0x66, sseCMP, regOp1, regOp2, arg, 0, 1); + Write8(compare); +} +void XEmitter::VSHUFPS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg, u8 shuffle) +{ + WriteAVXOp(0x00, sseSHUF, regOp1, regOp2, arg, 0, 1); + Write8(shuffle); +} +void XEmitter::VSHUFPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg, u8 shuffle) +{ + WriteAVXOp(0x66, sseSHUF, regOp1, regOp2, arg, 0, 1); + Write8(shuffle); +} +void XEmitter::VUNPCKLPS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x00, 0x14, regOp1, regOp2, arg); +} +void XEmitter::VUNPCKLPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x66, 0x14, regOp1, regOp2, arg); +} +void XEmitter::VUNPCKHPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x66, 0x15, regOp1, regOp2, arg); +} +void XEmitter::VBLENDVPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg, X64Reg regOp3) +{ + WriteAVXOp4(0x66, 0x3A4B, regOp1, regOp2, arg, regOp3); +} +void XEmitter::VBLENDPS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg, u8 blend) +{ + WriteAVXOp(0x66, 0x3A0C, regOp1, regOp2, arg, 0, 1); + Write8(blend); +} +void XEmitter::VBLENDPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg, u8 blend) +{ + WriteAVXOp(0x66, 0x3A0D, regOp1, regOp2, arg, 0, 1); + Write8(blend); +} + +void XEmitter::VANDPS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x00, sseAND, regOp1, regOp2, arg); +} +void XEmitter::VANDPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x66, sseAND, regOp1, regOp2, arg); +} +void XEmitter::VANDNPS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x00, sseANDN, regOp1, regOp2, arg); +} +void XEmitter::VANDNPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x66, sseANDN, regOp1, regOp2, arg); +} +void XEmitter::VORPS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x00, sseOR, regOp1, regOp2, arg); +} +void XEmitter::VORPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x66, sseOR, regOp1, regOp2, arg); +} +void XEmitter::VXORPS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x00, sseXOR, regOp1, regOp2, arg); +} +void XEmitter::VXORPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x66, sseXOR, regOp1, regOp2, arg); +} + +void XEmitter::VPAND(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x66, 0xDB, regOp1, regOp2, arg); +} +void XEmitter::VPANDN(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x66, 0xDF, regOp1, regOp2, arg); +} +void XEmitter::VPOR(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x66, 0xEB, regOp1, regOp2, arg); +} +void XEmitter::VPXOR(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteAVXOp(0x66, 0xEF, regOp1, regOp2, arg); +} + +void XEmitter::VFMADD132PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0x98, regOp1, regOp2, arg); +} +void XEmitter::VFMADD213PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xA8, regOp1, regOp2, arg); +} +void XEmitter::VFMADD231PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xB8, regOp1, regOp2, arg); +} +void XEmitter::VFMADD132PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0x98, regOp1, regOp2, arg, 1); +} +void XEmitter::VFMADD213PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xA8, regOp1, regOp2, arg, 1); +} +void XEmitter::VFMADD231PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xB8, regOp1, regOp2, arg, 1); +} +void XEmitter::VFMADD132SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0x99, regOp1, regOp2, arg); +} +void XEmitter::VFMADD213SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xA9, regOp1, regOp2, arg); +} +void XEmitter::VFMADD231SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xB9, regOp1, regOp2, arg); +} +void XEmitter::VFMADD132SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0x99, regOp1, regOp2, arg, 1); +} +void XEmitter::VFMADD213SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xA9, regOp1, regOp2, arg, 1); +} +void XEmitter::VFMADD231SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xB9, regOp1, regOp2, arg, 1); +} +void XEmitter::VFMSUB132PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0x9A, regOp1, regOp2, arg); +} +void XEmitter::VFMSUB213PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xAA, regOp1, regOp2, arg); +} +void XEmitter::VFMSUB231PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xBA, regOp1, regOp2, arg); +} +void XEmitter::VFMSUB132PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0x9A, regOp1, regOp2, arg, 1); +} +void XEmitter::VFMSUB213PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xAA, regOp1, regOp2, arg, 1); +} +void XEmitter::VFMSUB231PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xBA, regOp1, regOp2, arg, 1); +} +void XEmitter::VFMSUB132SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0x9B, regOp1, regOp2, arg); +} +void XEmitter::VFMSUB213SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xAB, regOp1, regOp2, arg); +} +void XEmitter::VFMSUB231SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xBB, regOp1, regOp2, arg); +} +void XEmitter::VFMSUB132SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0x9B, regOp1, regOp2, arg, 1); +} +void XEmitter::VFMSUB213SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xAB, regOp1, regOp2, arg, 1); +} +void XEmitter::VFMSUB231SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xBB, regOp1, regOp2, arg, 1); +} +void XEmitter::VFNMADD132PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0x9C, regOp1, regOp2, arg); +} +void XEmitter::VFNMADD213PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xAC, regOp1, regOp2, arg); +} +void XEmitter::VFNMADD231PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xBC, regOp1, regOp2, arg); +} +void XEmitter::VFNMADD132PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0x9C, regOp1, regOp2, arg, 1); +} +void XEmitter::VFNMADD213PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xAC, regOp1, regOp2, arg, 1); +} +void XEmitter::VFNMADD231PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xBC, regOp1, regOp2, arg, 1); +} +void XEmitter::VFNMADD132SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0x9D, regOp1, regOp2, arg); +} +void XEmitter::VFNMADD213SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xAD, regOp1, regOp2, arg); +} +void XEmitter::VFNMADD231SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xBD, regOp1, regOp2, arg); +} +void XEmitter::VFNMADD132SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0x9D, regOp1, regOp2, arg, 1); +} +void XEmitter::VFNMADD213SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xAD, regOp1, regOp2, arg, 1); +} +void XEmitter::VFNMADD231SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xBD, regOp1, regOp2, arg, 1); +} +void XEmitter::VFNMSUB132PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0x9E, regOp1, regOp2, arg); +} +void XEmitter::VFNMSUB213PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xAE, regOp1, regOp2, arg); +} +void XEmitter::VFNMSUB231PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xBE, regOp1, regOp2, arg); +} +void XEmitter::VFNMSUB132PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0x9E, regOp1, regOp2, arg, 1); +} +void XEmitter::VFNMSUB213PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xAE, regOp1, regOp2, arg, 1); +} +void XEmitter::VFNMSUB231PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xBE, regOp1, regOp2, arg, 1); +} +void XEmitter::VFNMSUB132SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0x9F, regOp1, regOp2, arg); +} +void XEmitter::VFNMSUB213SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xAF, regOp1, regOp2, arg); +} +void XEmitter::VFNMSUB231SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xBF, regOp1, regOp2, arg); +} +void XEmitter::VFNMSUB132SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0x9F, regOp1, regOp2, arg, 1); +} +void XEmitter::VFNMSUB213SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xAF, regOp1, regOp2, arg, 1); +} +void XEmitter::VFNMSUB231SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xBF, regOp1, regOp2, arg, 1); +} +void XEmitter::VFMADDSUB132PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0x96, regOp1, regOp2, arg); +} +void XEmitter::VFMADDSUB213PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xA6, regOp1, regOp2, arg); +} +void XEmitter::VFMADDSUB231PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xB6, regOp1, regOp2, arg); +} +void XEmitter::VFMADDSUB132PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0x96, regOp1, regOp2, arg, 1); +} +void XEmitter::VFMADDSUB213PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xA6, regOp1, regOp2, arg, 1); +} +void XEmitter::VFMADDSUB231PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xB6, regOp1, regOp2, arg, 1); +} +void XEmitter::VFMSUBADD132PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0x97, regOp1, regOp2, arg); +} +void XEmitter::VFMSUBADD213PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xA7, regOp1, regOp2, arg); +} +void XEmitter::VFMSUBADD231PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xB7, regOp1, regOp2, arg); +} +void XEmitter::VFMSUBADD132PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0x97, regOp1, regOp2, arg, 1); +} +void XEmitter::VFMSUBADD213PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xA7, regOp1, regOp2, arg, 1); +} +void XEmitter::VFMSUBADD231PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteFMA3Op(0xB7, regOp1, regOp2, arg, 1); +} + +#define FMA4(name, op) \ + void XEmitter::name(X64Reg dest, X64Reg regOp1, X64Reg regOp2, const OpArg& arg) \ + { \ + WriteFMA4Op(op, dest, regOp1, regOp2, arg, 1); \ + } \ + void XEmitter::name(X64Reg dest, X64Reg regOp1, const OpArg& arg, X64Reg regOp2) \ + { \ + WriteFMA4Op(op, dest, regOp1, regOp2, arg, 0); \ + } + +FMA4(VFMADDSUBPS, 0x5C) +FMA4(VFMADDSUBPD, 0x5D) +FMA4(VFMSUBADDPS, 0x5E) +FMA4(VFMSUBADDPD, 0x5F) +FMA4(VFMADDPS, 0x68) +FMA4(VFMADDPD, 0x69) +FMA4(VFMADDSS, 0x6A) +FMA4(VFMADDSD, 0x6B) +FMA4(VFMSUBPS, 0x6C) +FMA4(VFMSUBPD, 0x6D) +FMA4(VFMSUBSS, 0x6E) +FMA4(VFMSUBSD, 0x6F) +FMA4(VFNMADDPS, 0x78) +FMA4(VFNMADDPD, 0x79) +FMA4(VFNMADDSS, 0x7A) +FMA4(VFNMADDSD, 0x7B) +FMA4(VFNMSUBPS, 0x7C) +FMA4(VFNMSUBPD, 0x7D) +FMA4(VFNMSUBSS, 0x7E) +FMA4(VFNMSUBSD, 0x7F) +#undef FMA4 + +void XEmitter::SARX(int bits, X64Reg regOp1, const OpArg& arg, X64Reg regOp2) +{ + WriteBMI2Op(bits, 0xF3, 0x38F7, regOp1, regOp2, arg); +} +void XEmitter::SHLX(int bits, X64Reg regOp1, const OpArg& arg, X64Reg regOp2) +{ + WriteBMI2Op(bits, 0x66, 0x38F7, regOp1, regOp2, arg); +} +void XEmitter::SHRX(int bits, X64Reg regOp1, const OpArg& arg, X64Reg regOp2) +{ + WriteBMI2Op(bits, 0xF2, 0x38F7, regOp1, regOp2, arg); +} +void XEmitter::RORX(int bits, X64Reg regOp, const OpArg& arg, u8 rotate) +{ + WriteBMI2Op(bits, 0xF2, 0x3AF0, regOp, INVALID_REG, arg, 1); + Write8(rotate); +} +void XEmitter::PEXT(int bits, X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteBMI2Op(bits, 0xF3, 0x38F5, regOp1, regOp2, arg); +} +void XEmitter::PDEP(int bits, X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteBMI2Op(bits, 0xF2, 0x38F5, regOp1, regOp2, arg); +} +void XEmitter::MULX(int bits, X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteBMI2Op(bits, 0xF2, 0x38F6, regOp2, regOp1, arg); +} +void XEmitter::BZHI(int bits, X64Reg regOp1, const OpArg& arg, X64Reg regOp2) +{ + CheckFlags(); + WriteBMI2Op(bits, 0x00, 0x38F5, regOp1, regOp2, arg); +} +void XEmitter::BLSR(int bits, X64Reg regOp, const OpArg& arg) +{ + WriteBMI1Op(bits, 0x00, 0x38F3, (X64Reg)0x1, regOp, arg); +} +void XEmitter::BLSMSK(int bits, X64Reg regOp, const OpArg& arg) +{ + WriteBMI1Op(bits, 0x00, 0x38F3, (X64Reg)0x2, regOp, arg); +} +void XEmitter::BLSI(int bits, X64Reg regOp, const OpArg& arg) +{ + WriteBMI1Op(bits, 0x00, 0x38F3, (X64Reg)0x3, regOp, arg); +} +void XEmitter::BEXTR(int bits, X64Reg regOp1, const OpArg& arg, X64Reg regOp2) +{ + WriteBMI1Op(bits, 0x00, 0x38F7, regOp1, regOp2, arg); +} +void XEmitter::ANDN(int bits, X64Reg regOp1, X64Reg regOp2, const OpArg& arg) +{ + WriteBMI1Op(bits, 0x00, 0x38F2, regOp1, regOp2, arg); +} + +// Prefixes + +void XEmitter::LOCK() +{ + Write8(0xF0); +} +void XEmitter::REP() +{ + Write8(0xF3); +} +void XEmitter::REPNE() +{ + Write8(0xF2); +} +void XEmitter::FSOverride() +{ + Write8(0x64); +} +void XEmitter::GSOverride() +{ + Write8(0x65); +} + +void XEmitter::FWAIT() +{ + Write8(0x9B); +} + +// TODO: make this more generic +void XEmitter::WriteFloatLoadStore(int bits, FloatOp op, FloatOp op_80b, const OpArg& arg) +{ + int mf = 0; + ASSERT_MSG(DYNA_REC, !(bits == 80 && op_80b == FloatOp::Invalid), + "WriteFloatLoadStore: 80 bits not supported for this instruction"); + switch (bits) + { + case 32: + mf = 0; + break; + case 64: + mf = 4; + break; + case 80: + mf = 2; + break; + default: + ASSERT_MSG(DYNA_REC, 0, "WriteFloatLoadStore: invalid bits (should be 32/64/80)"); + } + Write8(0xd9 | mf); + // x87 instructions use the reg field of the ModR/M byte as opcode: + if (bits == 80) + op = op_80b; + arg.WriteRest(this, 0, static_cast(op)); +} + +void XEmitter::FLD(int bits, const OpArg& src) +{ + WriteFloatLoadStore(bits, FloatOp::LD, FloatOp::LD80, src); +} +void XEmitter::FST(int bits, const OpArg& dest) +{ + WriteFloatLoadStore(bits, FloatOp::ST, FloatOp::Invalid, dest); +} +void XEmitter::FSTP(int bits, const OpArg& dest) +{ + WriteFloatLoadStore(bits, FloatOp::STP, FloatOp::STP80, dest); +} +void XEmitter::FNSTSW_AX() +{ + Write8(0xDF); + Write8(0xE0); +} + +void XEmitter::RDTSC() +{ + Write8(0x0F); + Write8(0x31); +} +} diff --git a/src/dolphin/x64Emitter.h b/src/dolphin/x64Emitter.h new file mode 100644 index 0000000..122850d --- /dev/null +++ b/src/dolphin/x64Emitter.h @@ -0,0 +1,1180 @@ +// Copyright 2008 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license_dolphin.txt file included. + +// WARNING - THIS LIBRARY IS NOT THREAD SAFE!!! + +#pragma once + +#include +#include +#include +#include +#include + +#include "Assert.h" +#include "BitSet.h" +#include "CodeBlock.h" +#include "../types.h" +#include "x64ABI.h" + +namespace Gen +{ +enum CCFlags +{ + CC_O = 0, + CC_NO = 1, + CC_B = 2, + CC_C = 2, + CC_NAE = 2, + CC_NB = 3, + CC_NC = 3, + CC_AE = 3, + CC_Z = 4, + CC_E = 4, + CC_NZ = 5, + CC_NE = 5, + CC_BE = 6, + CC_NA = 6, + CC_NBE = 7, + CC_A = 7, + CC_S = 8, + CC_NS = 9, + CC_P = 0xA, + CC_PE = 0xA, + CC_NP = 0xB, + CC_PO = 0xB, + CC_L = 0xC, + CC_NGE = 0xC, + CC_NL = 0xD, + CC_GE = 0xD, + CC_LE = 0xE, + CC_NG = 0xE, + CC_NLE = 0xF, + CC_G = 0xF +}; + +enum +{ + NUMGPRs = 16, + NUMXMMs = 16, +}; + +enum +{ + SCALE_NONE = 0, + SCALE_1 = 1, + SCALE_2 = 2, + SCALE_4 = 4, + SCALE_8 = 8, + SCALE_ATREG = 16, + // SCALE_NOBASE_1 is not supported and can be replaced with SCALE_ATREG + SCALE_NOBASE_2 = 34, + SCALE_NOBASE_4 = 36, + SCALE_NOBASE_8 = 40, + SCALE_RIP = 0xFF, + SCALE_IMM8 = 0xF0, + SCALE_IMM16 = 0xF1, + SCALE_IMM32 = 0xF2, + SCALE_IMM64 = 0xF3, +}; + +enum SSECompare +{ + CMP_EQ = 0, + CMP_LT = 1, + CMP_LE = 2, + CMP_UNORD = 3, + CMP_NEQ = 4, + CMP_NLT = 5, + CMP_NLE = 6, + CMP_ORD = 7, +}; + +class XEmitter; +enum class FloatOp; +enum class NormalOp; + +// Information about a generated MOV op +struct MovInfo final +{ + u8* address; + bool nonAtomicSwapStore; + // valid iff nonAtomicSwapStore is true + X64Reg nonAtomicSwapStoreSrc; +}; + +// RIP addressing does not benefit from micro op fusion on Core arch +struct OpArg +{ + // For accessing offset and operandReg. + // This also allows us to keep the op writing functions private. + friend class XEmitter; + + // dummy op arg, used for storage + constexpr OpArg() = default; + constexpr OpArg(u64 offset_, int scale_, X64Reg rm_reg = RAX, X64Reg scaled_reg = RAX) + : scale{static_cast(scale_)}, offsetOrBaseReg{static_cast(rm_reg)}, + indexReg{static_cast(scaled_reg)}, offset{offset_} + { + } + constexpr bool operator==(const OpArg& b) const + { + // TODO: Use std::tie here once Dolphin requires C++17. (We can't do it immediately, + // (because we still support some older versions of GCC where std::tie is not constexpr.) + return operandReg == b.operandReg && scale == b.scale && offsetOrBaseReg == b.offsetOrBaseReg && + indexReg == b.indexReg && offset == b.offset; + } + constexpr bool operator!=(const OpArg& b) const { return !operator==(b); } + u64 Imm64() const + { + DEBUG_ASSERT(scale == SCALE_IMM64); + return (u64)offset; + } + u32 Imm32() const + { + DEBUG_ASSERT(scale == SCALE_IMM32); + return (u32)offset; + } + u16 Imm16() const + { + DEBUG_ASSERT(scale == SCALE_IMM16); + return (u16)offset; + } + u8 Imm8() const + { + DEBUG_ASSERT(scale == SCALE_IMM8); + return (u8)offset; + } + + s64 SImm64() const + { + DEBUG_ASSERT(scale == SCALE_IMM64); + return (s64)offset; + } + s32 SImm32() const + { + DEBUG_ASSERT(scale == SCALE_IMM32); + return (s32)offset; + } + s16 SImm16() const + { + DEBUG_ASSERT(scale == SCALE_IMM16); + return (s16)offset; + } + s8 SImm8() const + { + DEBUG_ASSERT(scale == SCALE_IMM8); + return (s8)offset; + } + + OpArg AsImm64() const + { + DEBUG_ASSERT(IsImm()); + return OpArg((u64)offset, SCALE_IMM64); + } + OpArg AsImm32() const + { + DEBUG_ASSERT(IsImm()); + return OpArg((u32)offset, SCALE_IMM32); + } + OpArg AsImm16() const + { + DEBUG_ASSERT(IsImm()); + return OpArg((u16)offset, SCALE_IMM16); + } + OpArg AsImm8() const + { + DEBUG_ASSERT(IsImm()); + return OpArg((u8)offset, SCALE_IMM8); + } + + constexpr bool IsImm() const + { + return scale == SCALE_IMM8 || scale == SCALE_IMM16 || scale == SCALE_IMM32 || + scale == SCALE_IMM64; + } + constexpr bool IsSimpleReg() const { return scale == SCALE_NONE; } + constexpr bool IsSimpleReg(X64Reg reg) const { return IsSimpleReg() && GetSimpleReg() == reg; } + constexpr bool IsZero() const { return IsImm() && offset == 0; } + constexpr int GetImmBits() const + { + switch (scale) + { + case SCALE_IMM8: + return 8; + case SCALE_IMM16: + return 16; + case SCALE_IMM32: + return 32; + case SCALE_IMM64: + return 64; + default: + return -1; + } + } + + constexpr X64Reg GetSimpleReg() const + { + if (scale == SCALE_NONE) + return static_cast(offsetOrBaseReg); + + return INVALID_REG; + } + + void AddMemOffset(int val) + { + DEBUG_ASSERT_MSG(DYNA_REC, scale == SCALE_RIP || (scale <= SCALE_ATREG && scale > SCALE_NONE), + "Tried to increment an OpArg which doesn't have an offset"); + offset += val; + } + +private: + void WriteREX(XEmitter* emit, int opBits, int bits, int customOp = -1) const; + void WriteVEX(XEmitter* emit, X64Reg regOp1, X64Reg regOp2, int L, int pp, int mmmmm, + int W = 0) const; + void WriteRest(XEmitter* emit, int extraBytes = 0, X64Reg operandReg = INVALID_REG, + bool warn_64bit_offset = true) const; + void WriteSingleByteOp(XEmitter* emit, u8 op, X64Reg operandReg, int bits); + void WriteNormalOp(XEmitter* emit, bool toRM, NormalOp op, const OpArg& operand, int bits) const; + + u8 scale = 0; + u16 offsetOrBaseReg = 0; + u16 indexReg = 0; + u64 offset = 0; // Also used to store immediates. + u16 operandReg = 0; +}; + +template +inline OpArg M(const T* ptr) +{ + return OpArg((u64)(const void*)ptr, (int)SCALE_RIP); +} +constexpr OpArg R(X64Reg value) +{ + return OpArg(0, SCALE_NONE, value); +} +constexpr OpArg MatR(X64Reg value) +{ + return OpArg(0, SCALE_ATREG, value); +} + +constexpr OpArg MDisp(X64Reg value, int offset) +{ + return OpArg(static_cast(offset), SCALE_ATREG, value); +} + +constexpr OpArg MComplex(X64Reg base, X64Reg scaled, int scale, int offset) +{ + return OpArg(offset, scale, base, scaled); +} + +constexpr OpArg MScaled(X64Reg scaled, int scale, int offset) +{ + if (scale == SCALE_1) + return OpArg(offset, SCALE_ATREG, scaled); + + return OpArg(offset, scale | 0x20, RAX, scaled); +} + +constexpr OpArg MRegSum(X64Reg base, X64Reg offset) +{ + return MComplex(base, offset, 1, 0); +} + +constexpr OpArg Imm8(u8 imm) +{ + return OpArg(imm, SCALE_IMM8); +} +constexpr OpArg Imm16(u16 imm) +{ + return OpArg(imm, SCALE_IMM16); +} // rarely used +constexpr OpArg Imm32(u32 imm) +{ + return OpArg(imm, SCALE_IMM32); +} +constexpr OpArg Imm64(u64 imm) +{ + return OpArg(imm, SCALE_IMM64); +} +inline OpArg ImmPtr(const void* imm) +{ + return Imm64(reinterpret_cast(imm)); +} + +inline u32 PtrOffset(const void* ptr, const void* base = nullptr) +{ + s64 distance = (s64)ptr - (s64)base; + if (distance >= 0x80000000LL || distance < -0x80000000LL) + { + ASSERT_MSG(DYNA_REC, 0, "pointer offset out of range"); + return 0; + } + + return (u32)distance; +} + +// usage: int a[]; ARRAY_OFFSET(a,10) +#define ARRAY_OFFSET(array, index) ((u32)((u64) & (array)[index] - (u64) & (array)[0])) +// usage: struct {int e;} s; STRUCT_OFFSET(s,e) +#define STRUCT_OFFSET(str, elem) ((u32)((u64) & (str).elem - (u64) & (str))) + +struct FixupBranch +{ + enum class Type + { + Branch8Bit, + Branch32Bit + }; + + u8* ptr; + Type type; +}; + +class XEmitter +{ + friend struct OpArg; // for Write8 etc +private: + u8* code = nullptr; + bool flags_locked = false; + + void CheckFlags(); + + void Rex(int w, int r, int x, int b); + void WriteModRM(int mod, int reg, int rm); + void WriteSIB(int scale, int index, int base); + void WriteSimple1Byte(int bits, u8 byte, X64Reg reg); + void WriteSimple2Byte(int bits, u8 byte1, u8 byte2, X64Reg reg); + void WriteMulDivType(int bits, OpArg src, int ext); + void WriteBitSearchType(int bits, X64Reg dest, OpArg src, u8 byte2, bool rep = false); + void WriteShift(int bits, OpArg dest, const OpArg& shift, int ext); + void WriteBitTest(int bits, const OpArg& dest, const OpArg& index, int ext); + void WriteMXCSR(OpArg arg, int ext); + void WriteSSEOp(u8 opPrefix, u16 op, X64Reg regOp, OpArg arg, int extrabytes = 0); + void WriteSSSE3Op(u8 opPrefix, u16 op, X64Reg regOp, const OpArg& arg, int extrabytes = 0); + void WriteSSE41Op(u8 opPrefix, u16 op, X64Reg regOp, const OpArg& arg, int extrabytes = 0); + void WriteVEXOp(u8 opPrefix, u16 op, X64Reg regOp1, X64Reg regOp2, const OpArg& arg, int W = 0, + int extrabytes = 0); + void WriteVEXOp4(u8 opPrefix, u16 op, X64Reg regOp1, X64Reg regOp2, const OpArg& arg, + X64Reg regOp3, int W = 0); + void WriteAVXOp(u8 opPrefix, u16 op, X64Reg regOp1, X64Reg regOp2, const OpArg& arg, int W = 0, + int extrabytes = 0); + void WriteAVXOp4(u8 opPrefix, u16 op, X64Reg regOp1, X64Reg regOp2, const OpArg& arg, + X64Reg regOp3, int W = 0); + void WriteFMA3Op(u8 op, X64Reg regOp1, X64Reg regOp2, const OpArg& arg, int W = 0); + void WriteFMA4Op(u8 op, X64Reg dest, X64Reg regOp1, X64Reg regOp2, const OpArg& arg, int W = 0); + void WriteBMIOp(int size, u8 opPrefix, u16 op, X64Reg regOp1, X64Reg regOp2, const OpArg& arg, + int extrabytes = 0); + void WriteBMI1Op(int size, u8 opPrefix, u16 op, X64Reg regOp1, X64Reg regOp2, const OpArg& arg, + int extrabytes = 0); + void WriteBMI2Op(int size, u8 opPrefix, u16 op, X64Reg regOp1, X64Reg regOp2, const OpArg& arg, + int extrabytes = 0); + void WriteMOVBE(int bits, u8 op, X64Reg regOp, const OpArg& arg); + void WriteFloatLoadStore(int bits, FloatOp op, FloatOp op_80b, const OpArg& arg); + void WriteNormalOp(int bits, NormalOp op, const OpArg& a1, const OpArg& a2); + + void ABI_CalculateFrameSize(BitSet32 mask, size_t rsp_alignment, size_t needed_frame_size, + size_t* shadowp, size_t* subtractionp, size_t* xmm_offsetp); + +protected: + void Write8(u8 value); + void Write16(u16 value); + void Write32(u32 value); + void Write64(u64 value); + +public: + XEmitter() = default; + explicit XEmitter(u8* code_ptr) : code{code_ptr} {} + virtual ~XEmitter() = default; + void SetCodePtr(u8* ptr); + void ReserveCodeSpace(int bytes); + u8* AlignCodeTo(size_t alignment); + u8* AlignCode4(); + u8* AlignCode16(); + u8* AlignCodePage(); + const u8* GetCodePtr() const; + u8* GetWritableCodePtr(); + + void LockFlags() { flags_locked = true; } + void UnlockFlags() { flags_locked = false; } + // Looking for one of these? It's BANNED!! Some instructions are slow on modern CPU + // INC, DEC, LOOP, LOOPNE, LOOPE, ENTER, LEAVE, XCHG, XLAT, REP MOVSB/MOVSD, REP SCASD + other + // string instr., + // INC and DEC are slow on Intel Core, but not on AMD. They create a + // false flag dependency because they only update a subset of the flags. + // XCHG is SLOW and should be avoided. + + // Debug breakpoint + void INT3(); + + // Do nothing + void NOP(size_t count = 1); + + // Save energy in wait-loops on P4 only. Probably not too useful. + void PAUSE(); + + // Flag control + void STC(); + void CLC(); + void CMC(); + + // These two can not be executed in 64-bit mode on early Intel 64-bit CPU:s, only on Core2 and + // AMD! + void LAHF(); // 3 cycle vector path + void SAHF(); // direct path fast + + // Stack control + void PUSH(X64Reg reg); + void POP(X64Reg reg); + void PUSH(int bits, const OpArg& reg); + void POP(int bits, const OpArg& reg); + void PUSHF(); + void POPF(); + + // Flow control + void RET(); + void RET_FAST(); + void UD2(); + FixupBranch J(bool force5bytes = false); + + void JMP(const u8* addr, bool force5Bytes = false); + void JMPptr(const OpArg& arg); + void JMPself(); // infinite loop! +#ifdef CALL +#undef CALL +#endif + void CALL(const void* fnptr); + FixupBranch CALL(); + void CALLptr(OpArg arg); + + FixupBranch J_CC(CCFlags conditionCode, bool force5bytes = false); + void J_CC(CCFlags conditionCode, const u8* addr); + + void SetJumpTarget(const FixupBranch& branch); + + void SETcc(CCFlags flag, OpArg dest); + // Note: CMOV brings small if any benefit on current CPUs. + void CMOVcc(int bits, X64Reg dest, OpArg src, CCFlags flag); + + // Fences + void LFENCE(); + void MFENCE(); + void SFENCE(); + + // Bit scan + void BSF(int bits, X64Reg dest, const OpArg& src); // Bottom bit to top bit + void BSR(int bits, X64Reg dest, const OpArg& src); // Top bit to bottom bit + + // Cache control + enum PrefetchLevel + { + PF_NTA, // Non-temporal (data used once and only once) + PF_T0, // All cache levels + PF_T1, // Levels 2+ (aliased to T0 on AMD) + PF_T2, // Levels 3+ (aliased to T0 on AMD) + }; + void PREFETCH(PrefetchLevel level, OpArg arg); + void MOVNTI(int bits, const OpArg& dest, X64Reg src); + void MOVNTDQ(const OpArg& arg, X64Reg regOp); + void MOVNTPS(const OpArg& arg, X64Reg regOp); + void MOVNTPD(const OpArg& arg, X64Reg regOp); + + // Multiplication / division + void MUL(int bits, const OpArg& src); // UNSIGNED + void IMUL(int bits, const OpArg& src); // SIGNED + void IMUL(int bits, X64Reg regOp, const OpArg& src); + void IMUL(int bits, X64Reg regOp, const OpArg& src, const OpArg& imm); + void DIV(int bits, const OpArg& src); + void IDIV(int bits, const OpArg& src); + + // Shift + void ROL(int bits, const OpArg& dest, const OpArg& shift); + void ROR_(int bits, const OpArg& dest, const OpArg& shift); + void RCL(int bits, const OpArg& dest, const OpArg& shift); + void RCR(int bits, const OpArg& dest, const OpArg& shift); + void SHL(int bits, const OpArg& dest, const OpArg& shift); + void SHR(int bits, const OpArg& dest, const OpArg& shift); + void SAR(int bits, const OpArg& dest, const OpArg& shift); + + // Bit Test + void BT(int bits, const OpArg& dest, const OpArg& index); + void BTS(int bits, const OpArg& dest, const OpArg& index); + void BTR(int bits, const OpArg& dest, const OpArg& index); + void BTC(int bits, const OpArg& dest, const OpArg& index); + + // Double-Precision Shift + void SHRD(int bits, const OpArg& dest, const OpArg& src, const OpArg& shift); + void SHLD(int bits, const OpArg& dest, const OpArg& src, const OpArg& shift); + + // Extend EAX into EDX in various ways + void CWD(int bits = 16); + inline void CDQ() { CWD(32); } + inline void CQO() { CWD(64); } + void CBW(int bits = 8); + inline void CWDE() { CBW(16); } + inline void CDQE() { CBW(32); } + // Load effective address + void LEA(int bits, X64Reg dest, OpArg src); + + // Integer arithmetic + void NEG(int bits, const OpArg& src); + void ADD(int bits, const OpArg& a1, const OpArg& a2); + void ADC(int bits, const OpArg& a1, const OpArg& a2); + void SUB(int bits, const OpArg& a1, const OpArg& a2); + void SBB(int bits, const OpArg& a1, const OpArg& a2); + void AND(int bits, const OpArg& a1, const OpArg& a2); + void CMP(int bits, const OpArg& a1, const OpArg& a2); + + // Bit operations + void NOT(int bits, const OpArg& src); + void OR(int bits, const OpArg& a1, const OpArg& a2); + void XOR(int bits, const OpArg& a1, const OpArg& a2); + void MOV(int bits, const OpArg& a1, const OpArg& a2); + void TEST(int bits, const OpArg& a1, const OpArg& a2); + + void CMP_or_TEST(int bits, const OpArg& a1, const OpArg& a2); + void MOV_sum(int bits, X64Reg dest, const OpArg& a1, const OpArg& a2); + + // Are these useful at all? Consider removing. + void XCHG(int bits, const OpArg& a1, const OpArg& a2); + void XCHG_AHAL(); + + // Byte swapping (32 and 64-bit only). + void BSWAP(int bits, X64Reg reg); + + // Sign/zero extension + void MOVSX(int dbits, int sbits, X64Reg dest, + OpArg src); // automatically uses MOVSXD if necessary + void MOVZX(int dbits, int sbits, X64Reg dest, OpArg src); + + // Available only on Atom or >= Haswell so far. Test with cpu_info.bMOVBE. + void MOVBE(int bits, X64Reg dest, const OpArg& src); + void MOVBE(int bits, const OpArg& dest, X64Reg src); + void LoadAndSwap(int size, X64Reg dst, const OpArg& src, bool sign_extend = false, + MovInfo* info = nullptr); + void SwapAndStore(int size, const OpArg& dst, X64Reg src, MovInfo* info = nullptr); + + // Available only on AMD >= Phenom or Intel >= Haswell + void LZCNT(int bits, X64Reg dest, const OpArg& src); + // Note: this one is actually part of BMI1 + void TZCNT(int bits, X64Reg dest, const OpArg& src); + + // WARNING - These two take 11-13 cycles and are VectorPath! (AMD64) + void STMXCSR(const OpArg& memloc); + void LDMXCSR(const OpArg& memloc); + + // Prefixes + void LOCK(); + void REP(); + void REPNE(); + void FSOverride(); + void GSOverride(); + + // x87 + enum x87StatusWordBits + { + x87_InvalidOperation = 0x1, + x87_DenormalizedOperand = 0x2, + x87_DivisionByZero = 0x4, + x87_Overflow = 0x8, + x87_Underflow = 0x10, + x87_Precision = 0x20, + x87_StackFault = 0x40, + x87_ErrorSummary = 0x80, + x87_C0 = 0x100, + x87_C1 = 0x200, + x87_C2 = 0x400, + x87_TopOfStack = 0x2000 | 0x1000 | 0x800, + x87_C3 = 0x4000, + x87_FPUBusy = 0x8000, + }; + + void FLD(int bits, const OpArg& src); + void FST(int bits, const OpArg& dest); + void FSTP(int bits, const OpArg& dest); + void FNSTSW_AX(); + void FWAIT(); + + // SSE/SSE2: Floating point arithmetic + void ADDSS(X64Reg regOp, const OpArg& arg); + void ADDSD(X64Reg regOp, const OpArg& arg); + void SUBSS(X64Reg regOp, const OpArg& arg); + void SUBSD(X64Reg regOp, const OpArg& arg); + void MULSS(X64Reg regOp, const OpArg& arg); + void MULSD(X64Reg regOp, const OpArg& arg); + void DIVSS(X64Reg regOp, const OpArg& arg); + void DIVSD(X64Reg regOp, const OpArg& arg); + void MINSS(X64Reg regOp, const OpArg& arg); + void MINSD(X64Reg regOp, const OpArg& arg); + void MAXSS(X64Reg regOp, const OpArg& arg); + void MAXSD(X64Reg regOp, const OpArg& arg); + void SQRTSS(X64Reg regOp, const OpArg& arg); + void SQRTSD(X64Reg regOp, const OpArg& arg); + void RCPSS(X64Reg regOp, const OpArg& arg); + void RSQRTSS(X64Reg regOp, const OpArg& arg); + + // SSE/SSE2: Floating point bitwise (yes) + void CMPSS(X64Reg regOp, const OpArg& arg, u8 compare); + void CMPSD(X64Reg regOp, const OpArg& arg, u8 compare); + + // SSE/SSE2: Floating point packed arithmetic (x4 for float, x2 for double) + void ADDPS(X64Reg regOp, const OpArg& arg); + void ADDPD(X64Reg regOp, const OpArg& arg); + void SUBPS(X64Reg regOp, const OpArg& arg); + void SUBPD(X64Reg regOp, const OpArg& arg); + void CMPPS(X64Reg regOp, const OpArg& arg, u8 compare); + void CMPPD(X64Reg regOp, const OpArg& arg, u8 compare); + void MULPS(X64Reg regOp, const OpArg& arg); + void MULPD(X64Reg regOp, const OpArg& arg); + void DIVPS(X64Reg regOp, const OpArg& arg); + void DIVPD(X64Reg regOp, const OpArg& arg); + void MINPS(X64Reg regOp, const OpArg& arg); + void MINPD(X64Reg regOp, const OpArg& arg); + void MAXPS(X64Reg regOp, const OpArg& arg); + void MAXPD(X64Reg regOp, const OpArg& arg); + void SQRTPS(X64Reg regOp, const OpArg& arg); + void SQRTPD(X64Reg regOp, const OpArg& arg); + void RCPPS(X64Reg regOp, const OpArg& arg); + void RSQRTPS(X64Reg regOp, const OpArg& arg); + + // SSE/SSE2: Floating point packed bitwise (x4 for float, x2 for double) + void ANDPS(X64Reg regOp, const OpArg& arg); + void ANDPD(X64Reg regOp, const OpArg& arg); + void ANDNPS(X64Reg regOp, const OpArg& arg); + void ANDNPD(X64Reg regOp, const OpArg& arg); + void ORPS(X64Reg regOp, const OpArg& arg); + void ORPD(X64Reg regOp, const OpArg& arg); + void XORPS(X64Reg regOp, const OpArg& arg); + void XORPD(X64Reg regOp, const OpArg& arg); + + // SSE/SSE2: Shuffle components. These are tricky - see Intel documentation. + void SHUFPS(X64Reg regOp, const OpArg& arg, u8 shuffle); + void SHUFPD(X64Reg regOp, const OpArg& arg, u8 shuffle); + + // SSE3 + void MOVSLDUP(X64Reg regOp, const OpArg& arg); + void MOVSHDUP(X64Reg regOp, const OpArg& arg); + void MOVDDUP(X64Reg regOp, const OpArg& arg); + + // SSE/SSE2: Useful alternative to shuffle in some cases. + void UNPCKLPS(X64Reg dest, const OpArg& src); + void UNPCKHPS(X64Reg dest, const OpArg& src); + void UNPCKLPD(X64Reg dest, const OpArg& src); + void UNPCKHPD(X64Reg dest, const OpArg& src); + + // SSE/SSE2: Compares. + void COMISS(X64Reg regOp, const OpArg& arg); + void COMISD(X64Reg regOp, const OpArg& arg); + void UCOMISS(X64Reg regOp, const OpArg& arg); + void UCOMISD(X64Reg regOp, const OpArg& arg); + + // SSE/SSE2: Moves. Use the right data type for your data, in most cases. + void MOVAPS(X64Reg regOp, const OpArg& arg); + void MOVAPD(X64Reg regOp, const OpArg& arg); + void MOVAPS(const OpArg& arg, X64Reg regOp); + void MOVAPD(const OpArg& arg, X64Reg regOp); + + void MOVUPS(X64Reg regOp, const OpArg& arg); + void MOVUPD(X64Reg regOp, const OpArg& arg); + void MOVUPS(const OpArg& arg, X64Reg regOp); + void MOVUPD(const OpArg& arg, X64Reg regOp); + + void MOVDQA(X64Reg regOp, const OpArg& arg); + void MOVDQA(const OpArg& arg, X64Reg regOp); + void MOVDQU(X64Reg regOp, const OpArg& arg); + void MOVDQU(const OpArg& arg, X64Reg regOp); + + void MOVSS(X64Reg regOp, const OpArg& arg); + void MOVSD(X64Reg regOp, const OpArg& arg); + void MOVSS(const OpArg& arg, X64Reg regOp); + void MOVSD(const OpArg& arg, X64Reg regOp); + + void MOVLPS(X64Reg regOp, const OpArg& arg); + void MOVLPD(X64Reg regOp, const OpArg& arg); + void MOVLPS(const OpArg& arg, X64Reg regOp); + void MOVLPD(const OpArg& arg, X64Reg regOp); + + void MOVHPS(X64Reg regOp, const OpArg& arg); + void MOVHPD(X64Reg regOp, const OpArg& arg); + void MOVHPS(const OpArg& arg, X64Reg regOp); + void MOVHPD(const OpArg& arg, X64Reg regOp); + + void MOVHLPS(X64Reg regOp1, X64Reg regOp2); + void MOVLHPS(X64Reg regOp1, X64Reg regOp2); + + // Be careful when using these overloads for reg <--> xmm moves. + // The one you cast to OpArg with R(reg) is the x86 reg, the other + // one is the xmm reg. + // ie: "MOVD_xmm(eax, R(xmm1))" generates incorrect code (movd xmm0, rcx) + // use "MOVD_xmm(R(eax), xmm1)" instead. + void MOVD_xmm(X64Reg dest, const OpArg& arg); + void MOVQ_xmm(X64Reg dest, OpArg arg); + void MOVD_xmm(const OpArg& arg, X64Reg src); + void MOVQ_xmm(OpArg arg, X64Reg src); + + // SSE/SSE2: Generates a mask from the high bits of the components of the packed register in + // question. + void MOVMSKPS(X64Reg dest, const OpArg& arg); + void MOVMSKPD(X64Reg dest, const OpArg& arg); + + // SSE2: Selective byte store, mask in src register. EDI/RDI specifies store address. This is a + // weird one. + void MASKMOVDQU(X64Reg dest, X64Reg src); + void LDDQU(X64Reg dest, const OpArg& src); + + // SSE/SSE2: Data type conversions. + void CVTPS2PD(X64Reg dest, const OpArg& src); + void CVTPD2PS(X64Reg dest, const OpArg& src); + void CVTSS2SD(X64Reg dest, const OpArg& src); + void CVTSI2SS(X64Reg dest, const OpArg& src); + void CVTSD2SS(X64Reg dest, const OpArg& src); + void CVTSI2SD(X64Reg dest, const OpArg& src); + void CVTDQ2PD(X64Reg regOp, const OpArg& arg); + void CVTPD2DQ(X64Reg regOp, const OpArg& arg); + void CVTDQ2PS(X64Reg regOp, const OpArg& arg); + void CVTPS2DQ(X64Reg regOp, const OpArg& arg); + + void CVTTPS2DQ(X64Reg regOp, const OpArg& arg); + void CVTTPD2DQ(X64Reg regOp, const OpArg& arg); + + // Destinations are X64 regs (rax, rbx, ...) for these instructions. + void CVTSS2SI(X64Reg xregdest, const OpArg& src); + void CVTSD2SI(X64Reg xregdest, const OpArg& src); + void CVTTSS2SI(X64Reg xregdest, const OpArg& arg); + void CVTTSD2SI(X64Reg xregdest, const OpArg& arg); + + // SSE2: Packed integer instructions + void PACKSSDW(X64Reg dest, const OpArg& arg); + void PACKSSWB(X64Reg dest, const OpArg& arg); + void PACKUSDW(X64Reg dest, const OpArg& arg); + void PACKUSWB(X64Reg dest, const OpArg& arg); + + void PUNPCKLBW(X64Reg dest, const OpArg& arg); + void PUNPCKLWD(X64Reg dest, const OpArg& arg); + void PUNPCKLDQ(X64Reg dest, const OpArg& arg); + void PUNPCKLQDQ(X64Reg dest, const OpArg& arg); + + void PTEST(X64Reg dest, const OpArg& arg); + void PAND(X64Reg dest, const OpArg& arg); + void PANDN(X64Reg dest, const OpArg& arg); + void PXOR(X64Reg dest, const OpArg& arg); + void POR(X64Reg dest, const OpArg& arg); + + void PADDB(X64Reg dest, const OpArg& arg); + void PADDW(X64Reg dest, const OpArg& arg); + void PADDD(X64Reg dest, const OpArg& arg); + void PADDQ(X64Reg dest, const OpArg& arg); + + void PADDSB(X64Reg dest, const OpArg& arg); + void PADDSW(X64Reg dest, const OpArg& arg); + void PADDUSB(X64Reg dest, const OpArg& arg); + void PADDUSW(X64Reg dest, const OpArg& arg); + + void PSUBB(X64Reg dest, const OpArg& arg); + void PSUBW(X64Reg dest, const OpArg& arg); + void PSUBD(X64Reg dest, const OpArg& arg); + void PSUBQ(X64Reg dest, const OpArg& arg); + + void PSUBSB(X64Reg dest, const OpArg& arg); + void PSUBSW(X64Reg dest, const OpArg& arg); + void PSUBUSB(X64Reg dest, const OpArg& arg); + void PSUBUSW(X64Reg dest, const OpArg& arg); + + void PAVGB(X64Reg dest, const OpArg& arg); + void PAVGW(X64Reg dest, const OpArg& arg); + + void PCMPEQB(X64Reg dest, const OpArg& arg); + void PCMPEQW(X64Reg dest, const OpArg& arg); + void PCMPEQD(X64Reg dest, const OpArg& arg); + + void PCMPGTB(X64Reg dest, const OpArg& arg); + void PCMPGTW(X64Reg dest, const OpArg& arg); + void PCMPGTD(X64Reg dest, const OpArg& arg); + + void PEXTRW(X64Reg dest, const OpArg& arg, u8 subreg); + void PINSRW(X64Reg dest, const OpArg& arg, u8 subreg); + void PINSRD(X64Reg dest, const OpArg& arg, u8 subreg); + + void PMADDWD(X64Reg dest, const OpArg& arg); + void PSADBW(X64Reg dest, const OpArg& arg); + + void PMAXSW(X64Reg dest, const OpArg& arg); + void PMAXUB(X64Reg dest, const OpArg& arg); + void PMINSW(X64Reg dest, const OpArg& arg); + void PMINUB(X64Reg dest, const OpArg& arg); + + void PMOVMSKB(X64Reg dest, const OpArg& arg); + void PSHUFD(X64Reg dest, const OpArg& arg, u8 shuffle); + void PSHUFB(X64Reg dest, const OpArg& arg); + + void PSHUFLW(X64Reg dest, const OpArg& arg, u8 shuffle); + void PSHUFHW(X64Reg dest, const OpArg& arg, u8 shuffle); + + void PSRLW(X64Reg reg, int shift); + void PSRLD(X64Reg reg, int shift); + void PSRLQ(X64Reg reg, int shift); + void PSRLQ(X64Reg reg, const OpArg& arg); + void PSRLDQ(X64Reg reg, int shift); + + void PSLLW(X64Reg reg, int shift); + void PSLLD(X64Reg reg, int shift); + void PSLLQ(X64Reg reg, int shift); + void PSLLDQ(X64Reg reg, int shift); + + void PSRAW(X64Reg reg, int shift); + void PSRAD(X64Reg reg, int shift); + + // SSE4: data type conversions + void PMOVSXBW(X64Reg dest, const OpArg& arg); + void PMOVSXBD(X64Reg dest, const OpArg& arg); + void PMOVSXBQ(X64Reg dest, const OpArg& arg); + void PMOVSXWD(X64Reg dest, const OpArg& arg); + void PMOVSXWQ(X64Reg dest, const OpArg& arg); + void PMOVSXDQ(X64Reg dest, const OpArg& arg); + void PMOVZXBW(X64Reg dest, const OpArg& arg); + void PMOVZXBD(X64Reg dest, const OpArg& arg); + void PMOVZXBQ(X64Reg dest, const OpArg& arg); + void PMOVZXWD(X64Reg dest, const OpArg& arg); + void PMOVZXWQ(X64Reg dest, const OpArg& arg); + void PMOVZXDQ(X64Reg dest, const OpArg& arg); + + // SSE4: blend instructions + void PBLENDVB(X64Reg dest, const OpArg& arg); + void BLENDVPS(X64Reg dest, const OpArg& arg); + void BLENDVPD(X64Reg dest, const OpArg& arg); + void BLENDPS(X64Reg dest, const OpArg& arg, u8 blend); + void BLENDPD(X64Reg dest, const OpArg& arg, u8 blend); + + // AVX + void VADDSS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VSUBSS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VMULSS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VDIVSS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VADDPS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VSUBPS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VMULPS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VDIVPS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VADDSD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VSUBSD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VMULSD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VDIVSD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VADDPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VSUBPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VMULPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VDIVPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VSQRTSD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VCMPPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg, u8 compare); + void VSHUFPS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg, u8 shuffle); + void VSHUFPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg, u8 shuffle); + void VUNPCKLPS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VUNPCKLPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VUNPCKHPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VBLENDVPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg, X64Reg mask); + void VBLENDPS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg, u8 blend); + void VBLENDPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg, u8 blend); + + void VANDPS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VANDPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VANDNPS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VANDNPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VORPS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VORPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VXORPS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VXORPD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + + void VPAND(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VPANDN(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VPOR(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VPXOR(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + + // FMA3 + void VFMADD132PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMADD213PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMADD231PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMADD132PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMADD213PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMADD231PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMADD132SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMADD213SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMADD231SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMADD132SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMADD213SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMADD231SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMSUB132PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMSUB213PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMSUB231PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMSUB132PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMSUB213PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMSUB231PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMSUB132SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMSUB213SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMSUB231SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMSUB132SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMSUB213SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMSUB231SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMADD132PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMADD213PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMADD231PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMADD132PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMADD213PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMADD231PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMADD132SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMADD213SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMADD231SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMADD132SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMADD213SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMADD231SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMSUB132PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMSUB213PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMSUB231PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMSUB132PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMSUB213PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMSUB231PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMSUB132SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMSUB213SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMSUB231SS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMSUB132SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMSUB213SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFNMSUB231SD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMADDSUB132PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMADDSUB213PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMADDSUB231PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMADDSUB132PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMADDSUB213PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMADDSUB231PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMSUBADD132PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMSUBADD213PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMSUBADD231PS(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMSUBADD132PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMSUBADD213PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void VFMSUBADD231PD(X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + +#define FMA4(name) \ + void name(X64Reg dest, X64Reg regOp1, X64Reg regOp2, const OpArg& arg); \ + void name(X64Reg dest, X64Reg regOp1, const OpArg& arg, X64Reg regOp2); + + FMA4(VFMADDSUBPS) + FMA4(VFMADDSUBPD) + FMA4(VFMSUBADDPS) + FMA4(VFMSUBADDPD) + FMA4(VFMADDPS) + FMA4(VFMADDPD) + FMA4(VFMADDSS) + FMA4(VFMADDSD) + FMA4(VFMSUBPS) + FMA4(VFMSUBPD) + FMA4(VFMSUBSS) + FMA4(VFMSUBSD) + FMA4(VFNMADDPS) + FMA4(VFNMADDPD) + FMA4(VFNMADDSS) + FMA4(VFNMADDSD) + FMA4(VFNMSUBPS) + FMA4(VFNMSUBPD) + FMA4(VFNMSUBSS) + FMA4(VFNMSUBSD) +#undef FMA4 + + // VEX GPR instructions + void SARX(int bits, X64Reg regOp1, const OpArg& arg, X64Reg regOp2); + void SHLX(int bits, X64Reg regOp1, const OpArg& arg, X64Reg regOp2); + void SHRX(int bits, X64Reg regOp1, const OpArg& arg, X64Reg regOp2); + void RORX(int bits, X64Reg regOp, const OpArg& arg, u8 rotate); + void PEXT(int bits, X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void PDEP(int bits, X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void MULX(int bits, X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + void BZHI(int bits, X64Reg regOp1, const OpArg& arg, X64Reg regOp2); + void BLSR(int bits, X64Reg regOp, const OpArg& arg); + void BLSMSK(int bits, X64Reg regOp, const OpArg& arg); + void BLSI(int bits, X64Reg regOp, const OpArg& arg); + void BEXTR(int bits, X64Reg regOp1, const OpArg& arg, X64Reg regOp2); + void ANDN(int bits, X64Reg regOp1, X64Reg regOp2, const OpArg& arg); + + void RDTSC(); + + // Utility functions + // The difference between this and CALL is that this aligns the stack + // where appropriate. + template + void ABI_CallFunction(FunctionPointer func) + { + static_assert(std::is_pointer() && + std::is_function>(), + "Supplied type must be a function pointer."); + + const void* ptr = reinterpret_cast(func); + const u64 address = reinterpret_cast(ptr); + const u64 distance = address - (reinterpret_cast(code) + 5); + + if (distance >= 0x0000000080000000ULL && distance < 0xFFFFFFFF80000000ULL) + { + // Far call + MOV(64, R(RAX), Imm64(address)); + CALLptr(R(RAX)); + } + else + { + CALL(ptr); + } + } + + template + void ABI_CallFunctionC16(FunctionPointer func, u16 param1) + { + MOV(32, R(ABI_PARAM1), Imm32(param1)); + ABI_CallFunction(func); + } + + template + void ABI_CallFunctionCC16(FunctionPointer func, u32 param1, u16 param2) + { + MOV(32, R(ABI_PARAM1), Imm32(param1)); + MOV(32, R(ABI_PARAM2), Imm32(param2)); + ABI_CallFunction(func); + } + + template + void ABI_CallFunctionC(FunctionPointer func, u32 param1) + { + MOV(32, R(ABI_PARAM1), Imm32(param1)); + ABI_CallFunction(func); + } + + template + void ABI_CallFunctionCC(FunctionPointer func, u32 param1, u32 param2) + { + MOV(32, R(ABI_PARAM1), Imm32(param1)); + MOV(32, R(ABI_PARAM2), Imm32(param2)); + ABI_CallFunction(func); + } + + template + void ABI_CallFunctionCP(FunctionPointer func, u32 param1, const void* param2) + { + MOV(32, R(ABI_PARAM1), Imm32(param1)); + MOV(64, R(ABI_PARAM2), Imm64(reinterpret_cast(param2))); + ABI_CallFunction(func); + } + + template + void ABI_CallFunctionCCC(FunctionPointer func, u32 param1, u32 param2, u32 param3) + { + MOV(32, R(ABI_PARAM1), Imm32(param1)); + MOV(32, R(ABI_PARAM2), Imm32(param2)); + MOV(32, R(ABI_PARAM3), Imm32(param3)); + ABI_CallFunction(func); + } + + template + void ABI_CallFunctionCCP(FunctionPointer func, u32 param1, u32 param2, const void* param3) + { + MOV(32, R(ABI_PARAM1), Imm32(param1)); + MOV(32, R(ABI_PARAM2), Imm32(param2)); + MOV(64, R(ABI_PARAM3), Imm64(reinterpret_cast(param3))); + ABI_CallFunction(func); + } + + template + void ABI_CallFunctionCCCP(FunctionPointer func, u32 param1, u32 param2, u32 param3, + const void* param4) + { + MOV(32, R(ABI_PARAM1), Imm32(param1)); + MOV(32, R(ABI_PARAM2), Imm32(param2)); + MOV(32, R(ABI_PARAM3), Imm32(param3)); + MOV(64, R(ABI_PARAM4), Imm64(reinterpret_cast(param4))); + ABI_CallFunction(func); + } + + template + void ABI_CallFunctionPC(FunctionPointer func, const void* param1, u32 param2) + { + MOV(64, R(ABI_PARAM1), Imm64(reinterpret_cast(param1))); + MOV(32, R(ABI_PARAM2), Imm32(param2)); + ABI_CallFunction(func); + } + + template + void ABI_CallFunctionPPC(FunctionPointer func, const void* param1, const void* param2, u32 param3) + { + MOV(64, R(ABI_PARAM1), Imm64(reinterpret_cast(param1))); + MOV(64, R(ABI_PARAM2), Imm64(reinterpret_cast(param2))); + MOV(32, R(ABI_PARAM3), Imm32(param3)); + ABI_CallFunction(func); + } + + // Pass a register as a parameter. + template + void ABI_CallFunctionR(FunctionPointer func, X64Reg reg1) + { + if (reg1 != ABI_PARAM1) + MOV(32, R(ABI_PARAM1), R(reg1)); + ABI_CallFunction(func); + } + + // Pass two registers as parameters. + template + void ABI_CallFunctionRR(FunctionPointer func, X64Reg reg1, X64Reg reg2) + { + MOVTwo(64, ABI_PARAM1, reg1, 0, ABI_PARAM2, reg2); + ABI_CallFunction(func); + } + + template + void ABI_CallFunctionAC(int bits, FunctionPointer func, const Gen::OpArg& arg1, u32 param2) + { + if (!arg1.IsSimpleReg(ABI_PARAM1)) + MOV(bits, R(ABI_PARAM1), arg1); + MOV(32, R(ABI_PARAM2), Imm32(param2)); + ABI_CallFunction(func); + } + + template + void ABI_CallFunctionA(int bits, FunctionPointer func, const Gen::OpArg& arg1) + { + if (!arg1.IsSimpleReg(ABI_PARAM1)) + MOV(bits, R(ABI_PARAM1), arg1); + ABI_CallFunction(func); + } + + // Helper method for ABI functions related to calling functions. May be used by itself as well. + void MOVTwo(int bits, X64Reg dst1, X64Reg src1, s32 offset, X64Reg dst2, X64Reg src2); + + // Saves/restores the registers and adjusts the stack to be aligned as + // required by the ABI, where the previous alignment was as specified. + // Push returns the size of the shadow space, i.e. the offset of the frame. + size_t ABI_PushRegistersAndAdjustStack(BitSet32 mask, size_t rsp_alignment, + size_t needed_frame_size = 0); + void ABI_PopRegistersAndAdjustStack(BitSet32 mask, size_t rsp_alignment, + size_t needed_frame_size = 0); + + // Utility to generate a call to a std::function object. + // + // Unfortunately, calling operator() directly is undefined behavior in C++ + // (this method might be a thunk in the case of multi-inheritance) so we + // have to go through a trampoline function. + template + static T CallLambdaTrampoline(const std::function* f, Args... args) + { + return (*f)(args...); + } + + template + void ABI_CallLambdaC(const std::function* f, u32 p1) + { + auto trampoline = &XEmitter::CallLambdaTrampoline; + ABI_CallFunctionPC(trampoline, reinterpret_cast(f), p1); + } +}; // class XEmitter + +class X64CodeBlock : public Common::CodeBlock +{ +private: + void PoisonMemory() override + { + // x86/64: 0xCC = breakpoint + memset(region, 0xCC, region_size); + } +}; + +} // namespace diff --git a/src/dolphin/x64Reg.h b/src/dolphin/x64Reg.h new file mode 100644 index 0000000..a92e024 --- /dev/null +++ b/src/dolphin/x64Reg.h @@ -0,0 +1,96 @@ +// Copyright 2016 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license_dolphin.txt file included. + +#pragma once + +namespace Gen +{ +enum X64Reg +{ + EAX = 0, + EBX = 3, + ECX = 1, + EDX = 2, + ESI = 6, + EDI = 7, + EBP = 5, + ESP = 4, + + RAX = 0, + RBX = 3, + RCX = 1, + RDX = 2, + RSI = 6, + RDI = 7, + RBP = 5, + RSP = 4, + R8 = 8, + R9 = 9, + R10 = 10, + R11 = 11, + R12 = 12, + R13 = 13, + R14 = 14, + R15 = 15, + + AL = 0, + BL = 3, + CL = 1, + DL = 2, + SIL = 6, + DIL = 7, + BPL = 5, + SPL = 4, + AH = 0x104, + BH = 0x107, + CH = 0x105, + DH = 0x106, + + AX = 0, + BX = 3, + CX = 1, + DX = 2, + SI = 6, + DI = 7, + BP = 5, + SP = 4, + + XMM0 = 0, + XMM1, + XMM2, + XMM3, + XMM4, + XMM5, + XMM6, + XMM7, + XMM8, + XMM9, + XMM10, + XMM11, + XMM12, + XMM13, + XMM14, + XMM15, + + YMM0 = 0, + YMM1, + YMM2, + YMM3, + YMM4, + YMM5, + YMM6, + YMM7, + YMM8, + YMM9, + YMM10, + YMM11, + YMM12, + YMM13, + YMM14, + YMM15, + + INVALID_REG = 0xFFFFFFFF +}; + +} // namespace Gen -- cgit v1.2.3 From 2f6b46fd4f4eb593746391131e2523f5252d0ea4 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Tue, 25 Jun 2019 17:09:27 +0200 Subject: JIT: implemented most ALU instructions --- src/ARM.cpp | 18 +- src/ARMJIT.cpp | 16 +- src/ARMJIT.h | 25 +- src/ARMJIT_RegCache.h | 136 +++++++++ src/ARMJIT_x64/ARMJIT_ALU.cpp | 546 +++++++++++++++++++++++++++++++++++++ src/ARMJIT_x64/ARMJIT_Compiler.cpp | 245 ++++++++--------- src/ARMJIT_x64/ARMJIT_Compiler.h | 60 +++- src/CMakeLists.txt | 1 + 8 files changed, 881 insertions(+), 166 deletions(-) create mode 100644 src/ARMJIT_RegCache.h create mode 100644 src/ARMJIT_x64/ARMJIT_ALU.cpp (limited to 'src') diff --git a/src/ARM.cpp b/src/ARM.cpp index f2b92b4..eadedc7 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -560,10 +560,10 @@ void ARMv5::Execute() AddCycles_C(); }*/ - if (!ARMJIT::IsMapped(Num, R[15] - ((CPSR&0x20)?2:4))) - printf("aaarg ungempappter raum %x\n", R[15]); + /*if (!ARMJIT::IsMapped(0, R[15] - ((CPSR&0x20)?2:4))) + printf("aaarg ungempappter raum %x\n", R[15]);*/ - ARMJIT::CompiledBlock block = ARMJIT::LookUpBlock(Num, R[15] - ((CPSR&0x20)?2:4)); + ARMJIT::CompiledBlock block = ARMJIT::LookUpBlock(0, R[15] - ((CPSR&0x20)?2:4)); if (block == NULL) block = ARMJIT::CompileBlock(this); Cycles += block(); @@ -615,7 +615,7 @@ void ARMv4::Execute() while (NDS::ARM7Timestamp < NDS::ARM7Target) { - if (CPSR & 0x20) // THUMB + /*if (CPSR & 0x20) // THUMB { // prefetch R[15] += 2; @@ -643,7 +643,15 @@ void ARMv4::Execute() } else AddCycles_C(); - } + }*/ + + /*if (!ARMJIT::IsMapped(1, R[15] - ((CPSR&0x20)?2:4))) + printf("aaarg ungempappter raum %x\n", R[15]);*/ + + ARMJIT::CompiledBlock block = ARMJIT::LookUpBlock(1, R[15] - ((CPSR&0x20)?2:4)); + if (block == NULL) + block = ARMJIT::CompileBlock(this); + Cycles += block(); // TODO optimize this shit!!! if (Halted) diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 489cdcf..74e154b 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -1,5 +1,7 @@ #include "ARMJIT.h" +#include + #include "ARMJIT_x64/ARMJIT_Compiler.h" namespace ARMJIT @@ -8,7 +10,6 @@ namespace ARMJIT Compiler* compiler; BlockCache cache; - #define DUP2(x) x, x static ptrdiff_t JIT_MEM[2][32] = { @@ -174,4 +175,17 @@ CompiledBlock CompileBlock(ARM* cpu) return block; } +void ResetBlocks() +{ + memset(cache.MainRAM, 0, sizeof(cache.MainRAM)); + memset(cache.SWRAM, 0, sizeof(cache.SWRAM)); + memset(cache.ARM9_BIOS, 0, sizeof(cache.ARM9_BIOS)); + memset(cache.ARM9_ITCM, 0, sizeof(cache.ARM9_ITCM)); + memset(cache.ARM9_LCDC, 0, sizeof(cache.ARM9_LCDC)); + memset(cache.ARM7_BIOS, 0, sizeof(cache.ARM7_BIOS)); + memset(cache.ARM7_WIRAM, 0, sizeof(cache.ARM7_WIRAM)); + memset(cache.ARM7_WRAM, 0, sizeof(cache.ARM7_WRAM)); + memset(cache.ARM7_WVRAM, 0, sizeof(cache.ARM7_WVRAM)); +} + } \ No newline at end of file diff --git a/src/ARMJIT.h b/src/ARMJIT.h index d718295..2ca29e8 100644 --- a/src/ARMJIT.h +++ b/src/ARMJIT.h @@ -3,8 +3,6 @@ #include "types.h" -#include - #include "ARM.h" #include "ARM_InstrInfo.h" @@ -13,14 +11,6 @@ namespace ARMJIT typedef u32 (*CompiledBlock)(); -class RegCache -{ - -static const int NativeRegAllocOrder[]; -static const int NativeRegsCount; - -}; - struct FetchedInstr { u32 A_Reg(int pos) const @@ -117,24 +107,13 @@ inline void InsertBlock(u32 num, u32 addr, CompiledBlock func) cache.AddrMapping[num][(addr & 0xFFFFFFF) >> 14][(addr & 0x3FFF) >> 1] = func; } -inline void ResetBlocks() -{ - memset(cache.MainRAM, 0, sizeof(cache.MainRAM)); - memset(cache.SWRAM, 0, sizeof(cache.SWRAM)); - memset(cache.ARM9_BIOS, 0, sizeof(cache.ARM9_BIOS)); - memset(cache.ARM9_ITCM, 0, sizeof(cache.ARM9_ITCM)); - memset(cache.ARM9_LCDC, 0, sizeof(cache.ARM9_LCDC)); - memset(cache.ARM7_BIOS, 0, sizeof(cache.ARM7_BIOS)); - memset(cache.ARM7_WIRAM, 0, sizeof(cache.ARM7_WIRAM)); - memset(cache.ARM7_WRAM, 0, sizeof(cache.ARM7_WRAM)); - memset(cache.ARM7_WVRAM, 0, sizeof(cache.ARM7_WVRAM)); -} - void Init(); void DeInit(); CompiledBlock CompileBlock(ARM* cpu); +void ResetBlocks(); + } #endif \ No newline at end of file diff --git a/src/ARMJIT_RegCache.h b/src/ARMJIT_RegCache.h new file mode 100644 index 0000000..e18d50f --- /dev/null +++ b/src/ARMJIT_RegCache.h @@ -0,0 +1,136 @@ +#ifndef ARMJIT_REGCACHE_H +#define ARMJIT_REGCACHE_H + +#include "ARMJIT.h" + +// TODO: replace this in the future +#include "dolphin/BitSet.h" + +#include + +namespace ARMJIT +{ + +template +class RegCache +{ +public: + RegCache() + {} + + RegCache(T* compiler, FetchedInstr instrs[], int instrsCount) + : Compiler(compiler), Instrs(instrs), InstrsCount(instrsCount) + { + for (int i = 0; i < 16; i++) + Mapping[i] = (Reg)-1; + } + + void UnloadRegister(int reg) + { + assert(Mapping[reg] != -1); + + if (DirtyRegs & (1 << reg)) + Compiler->UnloadReg(reg, Mapping[reg]); + + DirtyRegs &= ~(1 << reg); + LoadedRegs &= ~(1 << reg); + NativeRegsUsed &= ~(1 << (int)Mapping[reg]); + Mapping[reg] = (Reg)-1; + } + + void LoadRegister(int reg) + { + assert(Mapping[reg] == -1); + for (int i = 0; i < NativeRegsAvailable; i++) + { + Reg nativeReg = NativeRegAllocOrder[i]; + if (!(NativeRegsUsed & (1 << nativeReg))) + { + Mapping[reg] = nativeReg; + NativeRegsUsed |= 1 << (int)nativeReg; + LoadedRegs |= 1 << reg; + + Compiler->LoadReg(reg, nativeReg); + + return; + } + } + + assert("Welp!"); + } + + void Flush() + { + BitSet16 loadedSet(LoadedRegs); + for (int reg : loadedSet) + UnloadRegister(reg); + } + + void Prepare(int i) + { + u16 futureNeeded = 0; + int ranking[16]; + for (int j = 0; j < 16; j++) + ranking[j] = 0; + for (int j = i; j < InstrsCount; j++) + { + BitSet16 regsNeeded((Instrs[j].Info.SrcRegs & ~(1 << 15)) | Instrs[j].Info.DstRegs); + futureNeeded |= regsNeeded.m_val; + for (int reg : regsNeeded) + ranking[reg]++; + } + + // we'll unload all registers which are never used again + BitSet16 neverNeededAgain(LoadedRegs & ~futureNeeded); + for (int reg : neverNeededAgain) + UnloadRegister(reg); + + FetchedInstr Instr = Instrs[i]; + u16 necessaryRegs = (Instr.Info.SrcRegs & ~(1 << 15)) | Instr.Info.DstRegs; + BitSet16 needToBeLoaded(necessaryRegs & ~LoadedRegs); + if (needToBeLoaded != BitSet16(0)) + { + int neededCount = needToBeLoaded.Count(); + BitSet16 loadedSet(LoadedRegs); + while (loadedSet.Count() + neededCount > NativeRegsAvailable) + { + int leastReg = -1; + int rank = 1000; + for (int reg : loadedSet) + { + if (!((1 << reg) & necessaryRegs) && ranking[reg] < rank) + { + leastReg = reg; + rank = ranking[reg]; + } + } + + assert(leastReg != -1); + UnloadRegister(leastReg); + + loadedSet.m_val = LoadedRegs; + } + + for (int reg : needToBeLoaded) + LoadRegister(reg); + } + DirtyRegs |= Instr.Info.DstRegs; + } + + static const Reg NativeRegAllocOrder[]; + static const int NativeRegsAvailable; + + Reg Mapping[16]; + u32 NativeRegsUsed = 0; + u16 LoadedRegs = 0; + u16 DirtyRegs = 0; + + T* Compiler; + + FetchedInstr* Instrs; + int InstrsCount; +}; + +} + +#endif \ No newline at end of file diff --git a/src/ARMJIT_x64/ARMJIT_ALU.cpp b/src/ARMJIT_x64/ARMJIT_ALU.cpp new file mode 100644 index 0000000..d06c99c --- /dev/null +++ b/src/ARMJIT_x64/ARMJIT_ALU.cpp @@ -0,0 +1,546 @@ +#include "ARMJIT_Compiler.h" + +using namespace Gen; + +namespace ARMJIT +{ + +// uses RSCRATCH3 +void Compiler::Comp_ArithTriOp(void (Compiler::*op)(int, const OpArg&, const OpArg&), + OpArg rd, OpArg rn, OpArg op2, bool carryUsed, int opFlags) +{ + if (opFlags & opSyncCarry) + { + BT(32, R(RCPSR), Imm8(29)); + if (opFlags & opInvertCarry) + CMC(); + } + + if (rd == rn && !(opFlags & opInvertOp2)) + (this->*op)(32, rd, op2); + else if (opFlags & opSymmetric && op2 == R(RSCRATCH)) + { + if (opFlags & opInvertOp2) + NOT(32, op2); + (this->*op)(32, op2, rn); + MOV(32, rd, op2); + } + else + { + if (opFlags & opInvertOp2) + { + if (op2 != R(RSCRATCH)) + { + MOV(32, R(RSCRATCH), op2); + op2 = R(RSCRATCH); + } + NOT(32, op2); + } + MOV(32, R(RSCRATCH3), rn); + (this->*op)(32, R(RSCRATCH3), op2); + MOV(32, rd, R(RSCRATCH3)); + } + + if (opFlags & opSetsFlags) + Comp_RetriveFlags(opFlags & opInvertCarry, opFlags & opRetriveCV, carryUsed); +} + +void Compiler::Comp_ArithTriOpReverse(void (Compiler::*op)(int, const Gen::OpArg&, const Gen::OpArg&), + Gen::OpArg rd, Gen::OpArg rn, Gen::OpArg op2, bool carryUsed, int opFlags) +{ + if (opFlags & opSyncCarry) + { + BT(32, R(RCPSR), Imm8(29)); + if (opFlags & opInvertCarry) + CMC(); + } + + if (op2 != R(RSCRATCH)) + { + MOV(32, R(RSCRATCH), op2); + op2 = R(RSCRATCH); + } + (this->*op)(32, op2, rn); + MOV(32, rd, op2); + + if (opFlags & opSetsFlags) + Comp_RetriveFlags(opFlags & opInvertCarry, opFlags & opRetriveCV, carryUsed); +} + +void Compiler::Comp_CmpOp(int op, Gen::OpArg rn, Gen::OpArg op2, bool carryUsed) +{ + switch (op) + { + case 0: // TST + if (rn.IsImm()) + { + MOV(32, R(RSCRATCH3), rn); + rn = R(RSCRATCH3); + } + TEST(32, rn, op2); + break; + case 1: // TEQ + MOV(32, R(RSCRATCH3), rn); + XOR(32, R(RSCRATCH3), op2); + break; + case 2: // CMP + if (rn.IsImm()) + { + MOV(32, R(RSCRATCH3), rn); + rn = R(RSCRATCH3); + } + CMP(32, rn, op2); + break; + case 3: // CMN + MOV(32, R(RSCRATCH3), rn); + ADD(32, R(RSCRATCH3), op2); + break; + } + + Comp_RetriveFlags(op == 2, op >= 2, carryUsed); +} + +// also calculates cycles +OpArg Compiler::A_Comp_GetALUOp2(bool S, bool& carryUsed) +{ + if (CurrentInstr.Instr & (1 << 25)) + { + Comp_AddCycles_C(); + carryUsed = false; + return Imm32(ROR(CurrentInstr.Instr & 0xFF, (CurrentInstr.Instr >> 7) & 0x1E)); + } + else + { + int op = (CurrentInstr.Instr >> 5) & 0x3; + if (CurrentInstr.Instr & (1 << 4)) + { + Comp_AddCycles_CI(1); + OpArg rm = MapReg(CurrentInstr.A_Reg(0)); + if (rm.IsImm() && CurrentInstr.A_Reg(0) == 15) + rm = Imm32(rm.Imm32() + 4); + return Comp_RegShiftReg(op, MapReg(CurrentInstr.A_Reg(8)), rm, S, carryUsed); + } + else + { + Comp_AddCycles_C(); + return Comp_RegShiftImm(op, (CurrentInstr.Instr >> 7) & 0x1F, + MapReg(CurrentInstr.A_Reg(0)), S, carryUsed); + } + } +} + +void Compiler::A_Comp_CmpOp() +{ + u32 op = (CurrentInstr.Instr >> 21) & 0xF; + + bool carryUsed; + OpArg rn = MapReg(CurrentInstr.A_Reg(16)); + OpArg op2 = A_Comp_GetALUOp2((1 << op) & 0xF303, carryUsed); + + Comp_CmpOp(op - 0x8, rn, op2, carryUsed); +} + +void Compiler::A_Comp_Arith() +{ + bool S = CurrentInstr.Instr & (1 << 20); + u32 op = (CurrentInstr.Instr >> 21) & 0xF; + + bool carryUsed; + OpArg rn = MapReg(CurrentInstr.A_Reg(16)); + OpArg rd = MapReg(CurrentInstr.A_Reg(12)); + OpArg op2 = A_Comp_GetALUOp2(S && (1 << op) & 0xF303, carryUsed); + + u32 sFlag = S ? opSetsFlags : 0; + switch (op) + { + case 0x0: // AND + Comp_ArithTriOp(AND, rd, rn, op2, carryUsed, opSymmetric|sFlag); + return; + case 0x1: // EOR + Comp_ArithTriOp(XOR, rd, rn, op2, carryUsed, opSymmetric|sFlag); + return; + case 0x2: // SUB + Comp_ArithTriOp(SUB, rd, rn, op2, carryUsed, sFlag|opRetriveCV|opInvertCarry); + return; + case 0x3: // RSB + if (op2.IsZero()) + { + if (rd != rn) + MOV(32, rd, rn); + NEG(32, rd); + if (S) + Comp_RetriveFlags(true, true, false); + } + else + Comp_ArithTriOpReverse(SUB, rd, rn, op2, carryUsed, sFlag|opRetriveCV|opInvertCarry); + return; + case 0x4: // ADD + Comp_ArithTriOp(ADD, rd, rn, op2, carryUsed, opSymmetric|sFlag|opRetriveCV); + return; + case 0x5: // ADC + Comp_ArithTriOp(ADC, rd, rn, op2, carryUsed, opSymmetric|sFlag|opRetriveCV|opSyncCarry); + return; + case 0x6: // SBC + Comp_ArithTriOp(SBB, rd, rn, op2, carryUsed, opSymmetric|sFlag|opRetriveCV|opSyncCarry|opInvertCarry); + return; + case 0x7: // RSC + Comp_ArithTriOpReverse(SBB, rd, rn, op2, carryUsed, sFlag|opRetriveCV|opInvertCarry|opSyncCarry); + return; + case 0xC: // ORR + Comp_ArithTriOp(OR, rd, rn, op2, carryUsed, opSymmetric|sFlag); + return; + case 0xE: // BIC + Comp_ArithTriOp(AND, rd, rn, op2, carryUsed, sFlag|opSymmetric|opInvertOp2); + return; + default: + assert("unimplemented"); + } +} + +void Compiler::A_Comp_MovOp() +{ + bool carryUsed; + bool S = CurrentInstr.Instr & (1 << 20); + OpArg op2 = A_Comp_GetALUOp2(S, carryUsed); + OpArg rd = MapReg(CurrentInstr.A_Reg(12)); + + if (rd != op2) + MOV(32, rd, op2); + + if (((CurrentInstr.Instr >> 21) & 0xF) == 0xF) + NOT(32, rd); + + if (S) + { + TEST(32, rd, rd); + Comp_RetriveFlags(false, false, carryUsed); + } +} + +void Compiler::Comp_RetriveFlags(bool sign, bool retriveCV, bool carryUsed) +{ + CPSRDirty = true; + + bool carryOnly = !retriveCV && carryUsed; + if (retriveCV) + { + SETcc(CC_O, R(RSCRATCH)); + SETcc(sign ? CC_NC : CC_C, R(RSCRATCH3)); + LEA(32, RSCRATCH2, MComplex(RSCRATCH, RSCRATCH3, SCALE_2, 0)); + } + + if (carryUsed == 983298) + printf("etwas ist faul im lande daenemark %x\n", CurrentInstr.Instr); + + SETcc(CC_S, R(RSCRATCH)); + SETcc(CC_Z, R(RSCRATCH3)); + LEA(32, RSCRATCH, MComplex(RSCRATCH3, RSCRATCH, SCALE_2, 0)); + int shiftAmount = 30; + if (retriveCV || carryUsed) + { + LEA(32, RSCRATCH, MComplex(RSCRATCH2, RSCRATCH, carryOnly ? SCALE_2 : SCALE_4, 0)); + shiftAmount = carryOnly ? 29 : 28; + } + SHL(32, R(RSCRATCH), Imm8(shiftAmount)); + + AND(32, R(RCPSR), Imm32(0x3FFFFFFF & ~(carryUsed << 29) & ~((retriveCV ? 3 : 0) << 28))); + OR(32, R(RCPSR), R(RSCRATCH)); +} + +// always uses RSCRATCH, RSCRATCH2 only if S == true +OpArg Compiler::Comp_RegShiftReg(int op, Gen::OpArg rs, Gen::OpArg rm, bool S, bool& carryUsed) +{ + carryUsed = S; + + if (S) + { + XOR(32, R(RSCRATCH2), R(RSCRATCH2)); + BT(32, R(RCPSR), Imm8(29)); + SETcc(CC_C, R(RSCRATCH2)); + } + + MOV(32, R(RSCRATCH), rm); + static_assert(RSCRATCH3 == ECX); + MOV(32, R(ECX), rs); + AND(32, R(ECX), Imm32(0xFF)); + + FixupBranch zero = J_CC(CC_Z); + if (op < 3) + { + void (Compiler::*shiftOp)(int, const OpArg&, const OpArg&) = NULL; + if (op == 0) + shiftOp = SHL; + else if (op == 1) + shiftOp = SHR; + else if (op == 2) + shiftOp = SAR; + + CMP(32, R(ECX), Imm8(32)); + FixupBranch lt32 = J_CC(CC_L); + FixupBranch done1; + if (op < 2) + { + FixupBranch eq32 = J_CC(CC_E); + XOR(32, R(RSCRATCH), R(RSCRATCH)); + if (S) + XOR(32, R(RSCRATCH2), R(RSCRATCH2)); + done1 = J(); + SetJumpTarget(eq32); + } + (this->*shiftOp)(32, R(RSCRATCH), Imm8(31)); + (this->*shiftOp)(32, R(RSCRATCH), Imm8(1)); + if (S) + SETcc(CC_C, R(RSCRATCH2)); + + FixupBranch done2 = J(); + + SetJumpTarget(lt32); + (this->*shiftOp)(32, R(RSCRATCH), R(ECX)); + if (S) + SETcc(CC_C, R(RSCRATCH2)); + + if (op < 2) + SetJumpTarget(done1); + SetJumpTarget(done2); + + } + else if (op == 3) + { + if (S) + BT(32, R(RSCRATCH), Imm8(31)); + ROR_(32, R(RSCRATCH), R(ECX)); + if (S) + SETcc(CC_C, R(RSCRATCH2)); + } + SetJumpTarget(zero); + + return R(RSCRATCH); +} + +// may uses RSCRATCH for op2 and RSCRATCH2 for the carryValue +OpArg Compiler::Comp_RegShiftImm(int op, int amount, OpArg rm, bool S, bool& carryUsed) +{ + carryUsed = true; + + switch (op) + { + case 0: // LSL + if (amount > 0) + { + MOV(32, R(RSCRATCH), rm); + SHL(32, R(RSCRATCH), Imm8(amount)); + if (S) + SETcc(CC_C, R(RSCRATCH2)); + + return R(RSCRATCH); + } + else + { + carryUsed = false; + return rm; + } + case 1: // LSR + if (amount > 0) + { + MOV(32, R(RSCRATCH), rm); + SHR(32, R(RSCRATCH), Imm8(amount)); + if (S) + SETcc(CC_C, R(RSCRATCH2)); + return R(RSCRATCH); + } + else + { + if (S) + { + MOV(32, R(RSCRATCH2), rm); + SHR(32, R(RSCRATCH2), Imm8(31)); + } + return Imm32(0); + } + case 2: // ASR + MOV(32, R(RSCRATCH), rm); + SAR(32, R(RSCRATCH), Imm8(amount ? amount : 31)); + if (S) + { + if (amount == 0) + BT(32, rm, Imm8(31)); + SETcc(CC_C, R(RSCRATCH2)); + } + return R(RSCRATCH); + case 3: // ROR + MOV(32, R(RSCRATCH), rm); + if (amount > 0) + ROR_(32, R(RSCRATCH), Imm8(amount)); + else + { + BT(32, R(RCPSR), Imm8(29)); + RCR(32, R(RSCRATCH), Imm8(1)); + } + if (S) + SETcc(CC_C, R(RSCRATCH2)); + return R(RSCRATCH); + } + + assert(false); +} + +void Compiler::T_Comp_ShiftImm() +{ + OpArg rd = MapReg(CurrentInstr.T_Reg(0)); + OpArg rs = MapReg(CurrentInstr.T_Reg(3)); + + int op = (CurrentInstr.Instr >> 11) & 0x3; + int amount = (CurrentInstr.Instr >> 6) & 0x1F; + + Comp_AddCycles_C(); + + bool carryUsed; + OpArg shifted = Comp_RegShiftImm(op, amount, rs, true, carryUsed); + + if (shifted != rd) + MOV(32, rd, shifted); + + TEST(32, rd, rd); + Comp_RetriveFlags(false, false, carryUsed); +} + +void Compiler::T_Comp_AddSub_() +{ + OpArg rd = MapReg(CurrentInstr.T_Reg(0)); + OpArg rs = MapReg(CurrentInstr.T_Reg(3)); + + int op = (CurrentInstr.Instr >> 9) & 0x3; + + OpArg rn = op >= 2 ? Imm32((CurrentInstr.Instr >> 6) & 0x7) : MapReg(CurrentInstr.T_Reg(6)); + + Comp_AddCycles_C(); + + if (op & 1) + Comp_ArithTriOp(SUB, rd, rs, rn, false, opSetsFlags|opInvertCarry|opRetriveCV); + else + Comp_ArithTriOp(ADD, rd, rs, rn, false, opSetsFlags|opSymmetric|opRetriveCV); +} + +void Compiler::T_Comp_ALU_Imm8() +{ + OpArg rd = MapReg(CurrentInstr.T_Reg(8)); + + u32 op = (CurrentInstr.Instr >> 11) & 0x3; + OpArg imm = Imm32(CurrentInstr.Instr & 0xFF); + + Comp_AddCycles_C(); + + switch (op) + { + case 0x0: + MOV(32, rd, imm); + TEST(32, rd, rd); + Comp_RetriveFlags(false, false, false); + return; + case 0x1: + Comp_CmpOp(2, rd, imm, false); + return; + case 0x2: + Comp_ArithTriOp(ADD, rd, rd, imm, false, opSetsFlags|opSymmetric|opRetriveCV); + return; + case 0x3: + Comp_ArithTriOp(SUB, rd, rd, imm, false, opSetsFlags|opInvertCarry|opRetriveCV); + return; + } +} + +void Compiler::T_Comp_ALU() +{ + OpArg rd = MapReg(CurrentInstr.T_Reg(0)); + OpArg rs = MapReg(CurrentInstr.T_Reg(3)); + + u32 op = (CurrentInstr.Instr >> 6) & 0xF; + + Comp_AddCycles_C(); + + switch (op) + { + case 0x0: // AND + Comp_ArithTriOp(AND, rd, rd, rs, false, opSetsFlags|opSymmetric); + return; + case 0x1: // EOR + Comp_ArithTriOp(XOR, rd, rd, rs, false, opSetsFlags|opSymmetric); + return; + case 0x2: + case 0x3: + case 0x4: + case 0x7: + { + int shiftOp = op == 7 ? 3 : op - 0x2; + bool carryUsed; + OpArg shifted = Comp_RegShiftReg(shiftOp, rs, rd, true, carryUsed); + TEST(32, shifted, shifted); + MOV(32, rd, shifted); + Comp_RetriveFlags(false, false, true); + } + return; + case 0x5: // ADC + Comp_ArithTriOp(ADC, rd, rd, rs, false, opSetsFlags|opSymmetric|opSyncCarry|opRetriveCV); + return; + case 0x6: // SBC + Comp_ArithTriOp(SBB, rd, rd, rs, false, opSetsFlags|opSyncCarry|opInvertCarry|opRetriveCV); + return; + case 0x8: // TST + Comp_CmpOp(0, rd, rs, false); + return; + case 0x9: // NEG + if (rd != rs) + MOV(32, rd, rs); + NEG(32, rd); + Comp_RetriveFlags(true, true, false); + return; + case 0xA: // CMP + Comp_CmpOp(2, rd, rs, false); + return; + case 0xB: // CMN + Comp_CmpOp(3, rd, rs, false); + return; + case 0xC: // ORR + Comp_ArithTriOp(OR, rd, rd, rs, false, opSetsFlags|opSymmetric); + return; + case 0xE: // BIC + Comp_ArithTriOp(AND, rd, rd, rs, false, opSetsFlags|opSymmetric|opInvertOp2); + return; + case 0xF: // MVN + if (rd != rs) + MOV(32, rd, rs); + NOT(32, rd); + Comp_RetriveFlags(false, false, false); + return; + default: + break; + } +} + +void Compiler::T_Comp_ALU_HiReg() +{ + OpArg rd = MapReg(((CurrentInstr.Instr & 0x7) | ((CurrentInstr.Instr >> 4) & 0x8))); + OpArg rs = MapReg((CurrentInstr.Instr >> 3) & 0xF); + + u32 op = (CurrentInstr.Instr >> 8) & 0x3; + + Comp_AddCycles_C(); + + switch (op) + { + case 0x0: // ADD + Comp_ArithTriOp(ADD, rd, rd, rs, false, opSymmetric|opRetriveCV); + return; + case 0x1: // CMP + Comp_CmpOp(2, rd, rs, false); + return; + case 0x2: // MOV + if (rd != rs) + MOV(32, rd, rs); + TEST(32, rd, rd); + Comp_RetriveFlags(false, false, false); + return; + } +} + +} \ No newline at end of file diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index fb2fda8..f51d4d9 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -8,18 +8,16 @@ using namespace Gen; namespace ARMJIT { - -const int RegCache::NativeRegAllocOrder[] = {(int)RBX, (int)RSI, (int)RDI, (int)R12, (int)R13}; -const int RegCache::NativeRegsCount = 5; +template <> +const X64Reg RegCache::NativeRegAllocOrder[] = {RBX, RSI, RDI, R12, R13}; +template <> +const int RegCache::NativeRegsAvailable = 5; Compiler::Compiler() { AllocCodeSpace(1024 * 1024 * 4); } -typedef void (Compiler::*CompileFunc)(); -typedef void (*InterpretFunc)(ARM*); - void Compiler::LoadCPSR() { assert(!CPSRDirty); @@ -36,6 +34,19 @@ void Compiler::SaveCPSR() } } +void Compiler::LoadReg(int reg, X64Reg nativeReg) +{ + if (reg != 15) + MOV(32, R(nativeReg), MDisp(RCPU, offsetof(ARM, R[reg]))); + else + MOV(32, R(nativeReg), Imm32(R15)); +} + +void Compiler::UnloadReg(int reg, X64Reg nativeReg) +{ + MOV(32, MDisp(RCPU, offsetof(ARM, R[reg])), R(nativeReg)); +} + CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrsCount) { if (IsAlmostFull()) @@ -58,12 +69,18 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs LoadCPSR(); + // TODO: this is ugly as a whole, do better + RegCache = ARMJIT::RegCache(this, instrs, instrsCount); + for (int i = 0; i < instrsCount; i++) { R15 += Thumb ? 2 : 4; CurrentInstr = instrs[i]; - CompileFunc comp = NULL; + CompileFunc comp = GetCompFunc(CurrentInstr.Info.Kind); + + if (CurrentInstr.Info.Branches()) + comp = NULL; if (comp == NULL || i == instrsCount - 1) { @@ -79,6 +96,11 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs SaveCPSR(); } + if (comp != NULL) + RegCache.Prepare(i); + else + RegCache.Flush(); + if (Thumb) { if (comp == NULL) @@ -89,8 +111,7 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs ABI_CallFunction(ARMInterpreter::THUMBInstrTable[icode]); } else - { - } + (this->*comp)(); } else { @@ -101,7 +122,7 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs ABI_CallFunction(ARMInterpreter::A_BLX_IMM); } else if (cond == 0xF) - AddCycles_C(); + Comp_AddCycles_C(); else { FixupBranch skipExecute; @@ -115,17 +136,17 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs MOV(32, R(RSCRATCH), Imm32(1)); SHL(32, R(RSCRATCH), R(RSCRATCH3)); TEST(32, R(RSCRATCH), Imm32(ARM::ConditionTable[cond])); - + skipExecute = J_CC(CC_Z); } else { // could have used a LUT, but then where would be the fun? BT(32, R(RCPSR), Imm8(28 + ((~(cond >> 1) & 1) << 1 | (cond >> 2 & 1) ^ (cond >> 1 & 1)))); - + skipExecute = J_CC(cond & 1 ? CC_C : CC_NC); } - + } if (comp == NULL) @@ -136,8 +157,7 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs ABI_CallFunction(ARMInterpreter::ARMInstrTable[icode]); } else - { - } + (this->*comp)(); FixupBranch skipFailed; if (CurrentInstr.Cond() < 0xE) @@ -145,7 +165,7 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs skipFailed = J(); SetJumpTarget(skipExecute); - AddCycles_C(); + Comp_AddCycles_C(); SetJumpTarget(skipFailed); } @@ -155,13 +175,14 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs /* we don't need to collect the interpreted cycles, since all functions only add to it, the dispatcher - can take care of it. + takes care of it. */ if (comp == NULL && i != instrsCount - 1) LoadCPSR(); } + RegCache.Flush(); SaveCPSR(); LEA(32, RAX, MDisp(RCycles, ConstantCycles)); @@ -172,42 +193,57 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs return res; } -void Compiler::Compile(RegCache& regs, const FetchedInstr& instr) +CompileFunc Compiler::GetCompFunc(int kind) { + // this might look like waste of space, so many repeatitions, but it's invaluable for debugging. + // see ARMInstrInfo.h for the order const CompileFunc A_Comp[ARMInstrInfo::ak_Count] = { - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + // AND + A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, + A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, + // EOR + A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, + A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, + // SUB + A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, + A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, + // RSB + A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, + A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, + // ADD + A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, + A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, + // ADC + A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, + A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, + // SBC + A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, + A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, + // RSC + A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, + A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, + // ORR + A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, + A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, + // MOV + A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, + A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, + // BIC + A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, + A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, + // MVN + A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, + A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, + // TST + A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, + // TEQ + A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, + // CMP + A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, + // CMN + A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, @@ -227,21 +263,34 @@ void Compiler::Compile(RegCache& regs, const FetchedInstr& instr) }; const CompileFunc T_Comp[ARMInstrInfo::tk_Count] = { - NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, + // Shift imm + T_Comp_ShiftImm, T_Comp_ShiftImm, T_Comp_ShiftImm, + // Three operand ADD/SUB + T_Comp_AddSub_, T_Comp_AddSub_, T_Comp_AddSub_, T_Comp_AddSub_, + // 8 bit imm + T_Comp_ALU_Imm8, T_Comp_ALU_Imm8, T_Comp_ALU_Imm8, T_Comp_ALU_Imm8, + // general ALU + T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, + T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, + T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, + T_Comp_ALU, NULL, T_Comp_ALU, T_Comp_ALU, + // hi reg + T_Comp_ALU_HiReg, T_Comp_ALU_HiReg, T_Comp_ALU_HiReg, + // pc/sp relative + NULL, NULL, NULL, + // mem... + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; + + return Thumb ? T_Comp[kind] : A_Comp[kind]; } -void Compiler::AddCycles_C() +void Compiler::Comp_AddCycles_C() { s32 cycles = Num ? NDS::ARM7MemTimings[CurrentInstr.CodeCycles][Thumb ? 1 : 3] @@ -253,80 +302,16 @@ void Compiler::AddCycles_C() ConstantCycles += cycles; } -// may uses RSCRATCH for op2 and RSCRATCH2 for the carryValue -OpArg Compiler::Comp_ShiftRegImm(int op, int amount, Gen::X64Reg rm, bool S, bool& carryUsed) -{ - carryUsed = true; - - switch (op) - { - case 0: // LSL - if (amount > 0) - { - MOV(32, R(RSCRATCH), R(rm)); - SHL(32, R(RSCRATCH), Imm8(amount)); - if (S) - SETcc(CC_C, R(RSCRATCH2)); - - return R(RSCRATCH); - } - else - { - carryUsed = false; - return R(rm); - } - case 1: // LSR - if (amount > 0) - { - MOV(32, R(RSCRATCH), R(rm)); - SHR(32, R(RSCRATCH), Imm8(amount)); - if (S) - SETcc(CC_C, R(RSCRATCH2)); - return R(RSCRATCH); - } - else - { - if (S) - { - MOV(32, R(RSCRATCH2), R(rm)); - SHR(32, R(RSCRATCH2), Imm8(31)); - } - return Imm32(0); - } - case 2: // ASR - MOV(32, R(RSCRATCH), R(rm)); - SAR(32, R(RSCRATCH), Imm8(amount ? amount : 31)); - if (S) - { - if (amount == 0) - { - MOV(32, R(RSCRATCH2), R(rm)); - SHR(32, R(RSCRATCH2), Imm8(31)); - } - else - SETcc(CC_C, R(RSCRATCH2)); - } - return R(RSCRATCH); - case 3: // ROR - if (amount > 0) - { - MOV(32, R(RSCRATCH), R(rm)); - ROR_(32, R(RSCRATCH), Imm8(amount)); - } - else - { - BT(32, R(RCPSR), Imm8(29)); - MOV(32, R(RSCRATCH), R(rm)); - RCR(32, R(RSCRATCH), Imm8(1)); - } - if (S) - SETcc(CC_C, R(RSCRATCH2)); - return R(RSCRATCH); - } -} - -void Compiler::A_Comp_ALU(const FetchedInstr& instr) +void Compiler::Comp_AddCycles_CI(u32 i) { + s32 cycles = (Num ? + NDS::ARM7MemTimings[CurrentInstr.CodeCycles][Thumb ? 0 : 2] + : ((R15 & 0x2) ? 0 : CurrentInstr.CodeCycles)) + i; + + if (CurrentInstr.Cond() < 0xE) + ADD(32, R(RCycles), Imm8(cycles)); + else + ConstantCycles += cycles; } } \ No newline at end of file diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index 8e1d100..9b454f4 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -4,7 +4,7 @@ #include "../dolphin/x64Emitter.h" #include "../ARMJIT.h" - +#include "../ARMJIT_RegCache.h" namespace ARMJIT { @@ -17,6 +17,10 @@ const Gen::X64Reg RSCRATCH = Gen::EAX; const Gen::X64Reg RSCRATCH2 = Gen::EDX; const Gen::X64Reg RSCRATCH3 = Gen::ECX; +class Compiler; + +typedef void (Compiler::*CompileFunc)(); + class Compiler : public Gen::X64CodeBlock { public: @@ -24,24 +28,66 @@ public: CompiledBlock CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrsCount); - void StartBlock(ARM* cpu); - CompiledBlock FinaliseBlock(); + void LoadReg(int reg, Gen::X64Reg nativeReg); + void UnloadReg(int reg, Gen::X64Reg nativeReg); - void Compile(RegCache& regs, const FetchedInstr& instr); private: - void AddCycles_C(); + CompileFunc GetCompFunc(int kind); + + void Comp_AddCycles_C(); + void Comp_AddCycles_CI(u32 i); + + enum + { + opSetsFlags = 1 << 0, + opSymmetric = 1 << 1, + opRetriveCV = 1 << 2, + opInvertCarry = 1 << 3, + opSyncCarry = 1 << 4, + opInvertOp2 = 1 << 5, + }; + + void A_Comp_Arith(); + void A_Comp_MovOp(); + void A_Comp_CmpOp(); - Gen::OpArg Comp_ShiftRegImm(int op, int amount, Gen::X64Reg rm, bool S, bool& carryUsed); + void T_Comp_ShiftImm(); + void T_Comp_AddSub_(); + void T_Comp_ALU_Imm8(); + void T_Comp_ALU(); + void T_Comp_ALU_HiReg(); - void A_Comp_ALU(const FetchedInstr& instr); + void Comp_ArithTriOp(void (Compiler::*op)(int, const Gen::OpArg&, const Gen::OpArg&), + Gen::OpArg rd, Gen::OpArg rn, Gen::OpArg op2, bool carryUsed, int opFlags); + void Comp_ArithTriOpReverse(void (Compiler::*op)(int, const Gen::OpArg&, const Gen::OpArg&), + Gen::OpArg rd, Gen::OpArg rn, Gen::OpArg op2, bool carryUsed, int opFlags); + void Comp_CmpOp(int op, Gen::OpArg rn, Gen::OpArg op2, bool carryUsed); + + void Comp_RetriveFlags(bool sign, bool retriveCV, bool carryUsed); + + Gen::OpArg Comp_RegShiftImm(int op, int amount, Gen::OpArg rm, bool S, bool& carryUsed); + Gen::OpArg Comp_RegShiftReg(int op, Gen::OpArg rs, Gen::OpArg rm, bool S, bool& carryUsed); + + Gen::OpArg A_Comp_GetALUOp2(bool S, bool& carryUsed); void LoadCPSR(); void SaveCPSR(); + Gen::OpArg MapReg(int reg) + { + if (reg == 15 && RegCache.Mapping[reg] == Gen::INVALID_REG) + return Gen::Imm32(R15); + + assert(RegCache.Mapping[reg] != Gen::INVALID_REG); + return Gen::R(RegCache.Mapping[reg]); + } + bool CPSRDirty = false; FetchedInstr CurrentInstr; + RegCache RegCache; + bool Thumb; u32 Num; u32 R15; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a6011e1..0faa57a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,6 +52,7 @@ add_library(core STATIC ARMJIT.cpp ARMJIT_x64/ARMJIT_Compiler.cpp + ARMJIT_x64/ARMJIT_ALU.cpp dolphin/CommonFuncs.cpp dolphin/x64ABI.cpp -- cgit v1.2.3 From ea98a44e1e92b0f7622b28d36a1ba6c8d4679a1f Mon Sep 17 00:00:00 2001 From: RSDuck Date: Tue, 25 Jun 2019 18:28:01 +0200 Subject: jit: correct cycle counting for thumb shift by reg --- src/ARMJIT_x64/ARMJIT_ALU.cpp | 7 +++++-- src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 0 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 src/ARMJIT_x64/ARMJIT_LoadStore.cpp (limited to 'src') diff --git a/src/ARMJIT_x64/ARMJIT_ALU.cpp b/src/ARMJIT_x64/ARMJIT_ALU.cpp index d06c99c..dc82af7 100644 --- a/src/ARMJIT_x64/ARMJIT_ALU.cpp +++ b/src/ARMJIT_x64/ARMJIT_ALU.cpp @@ -456,7 +456,10 @@ void Compiler::T_Comp_ALU() u32 op = (CurrentInstr.Instr >> 6) & 0xF; - Comp_AddCycles_C(); + if ((op >= 0x2 && op < 0x4) || op == 0x7) + Comp_AddCycles_CI(1); + else + Comp_AddCycles_C(); switch (op) { @@ -471,7 +474,7 @@ void Compiler::T_Comp_ALU() case 0x4: case 0x7: { - int shiftOp = op == 7 ? 3 : op - 0x2; + int shiftOp = op == 0x7 ? 3 : op - 0x2; bool carryUsed; OpArg shifted = Comp_RegShiftReg(shiftOp, rs, rd, true, carryUsed); TEST(32, shifted, shifted); diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3 From 550e6b86d2dc09960c5a74270bc49d3f0e895699 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sun, 30 Jun 2019 13:35:03 +0200 Subject: JIT: compilation of word load and store --- src/ARMJIT.cpp | 4 +- src/ARMJIT.h | 3 +- src/ARMJIT_RegCache.h | 2 +- src/ARMJIT_x64/ARMJIT_ALU.cpp | 4 +- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 111 +++++-- src/ARMJIT_x64/ARMJIT_Compiler.h | 19 +- src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 600 ++++++++++++++++++++++++++++++++++++ src/ARM_InstrInfo.h | 8 +- src/CMakeLists.txt | 1 + src/dolphin/x64ABI.h | 3 +- 10 files changed, 712 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 74e154b..4da781c 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -40,8 +40,7 @@ static ptrdiff_t JIT_MEM[2][32] = { /* 2X*/ DUP2(offsetof(BlockCache, MainRAM)), /* 3X*/ offsetof(BlockCache, SWRAM), offsetof(BlockCache, ARM7_WRAM), - /* 4X*/ -1, - offsetof(BlockCache, ARM7_WIRAM), + /* 4X*/ DUP2(-1), /* 5X*/ DUP2(-1), /* 6X*/ DUP2(offsetof(BlockCache, ARM7_WVRAM)), /* contrary to Gbatek, melonDS and itself, DeSmuME doesn't mirror the 64 MB region at 0x6800000 */ @@ -183,7 +182,6 @@ void ResetBlocks() memset(cache.ARM9_ITCM, 0, sizeof(cache.ARM9_ITCM)); memset(cache.ARM9_LCDC, 0, sizeof(cache.ARM9_LCDC)); memset(cache.ARM7_BIOS, 0, sizeof(cache.ARM7_BIOS)); - memset(cache.ARM7_WIRAM, 0, sizeof(cache.ARM7_WIRAM)); memset(cache.ARM7_WRAM, 0, sizeof(cache.ARM7_WRAM)); memset(cache.ARM7_WVRAM, 0, sizeof(cache.ARM7_WVRAM)); } diff --git a/src/ARMJIT.h b/src/ARMJIT.h index 2ca29e8..45bb4ed 100644 --- a/src/ARMJIT.h +++ b/src/ARMJIT.h @@ -63,14 +63,13 @@ struct BlockCache { CompiledBlock* AddrMapping[2][0x4000] = {0}; - CompiledBlock MainRAM[16*1024*1024/2]; + CompiledBlock MainRAM[4*1024*1024/2]; CompiledBlock SWRAM[0x8000/2]; // Shared working RAM CompiledBlock ARM9_ITCM[0x8000/2]; CompiledBlock ARM9_LCDC[0xA4000/2]; CompiledBlock ARM9_BIOS[0x8000/2]; CompiledBlock ARM7_BIOS[0x4000/2]; CompiledBlock ARM7_WRAM[0x10000/2]; // dedicated ARM7 WRAM - CompiledBlock ARM7_WIRAM[0x10000/2]; // Wifi CompiledBlock ARM7_WVRAM[0x40000/2]; // VRAM allocated as Working RAM }; diff --git a/src/ARMJIT_RegCache.h b/src/ARMJIT_RegCache.h index e18d50f..ea9fb30 100644 --- a/src/ARMJIT_RegCache.h +++ b/src/ARMJIT_RegCache.h @@ -30,7 +30,7 @@ public: assert(Mapping[reg] != -1); if (DirtyRegs & (1 << reg)) - Compiler->UnloadReg(reg, Mapping[reg]); + Compiler->SaveReg(reg, Mapping[reg]); DirtyRegs &= ~(1 << reg); LoadedRegs &= ~(1 << reg); diff --git a/src/ARMJIT_x64/ARMJIT_ALU.cpp b/src/ARMJIT_x64/ARMJIT_ALU.cpp index dc82af7..6294e1d 100644 --- a/src/ARMJIT_x64/ARMJIT_ALU.cpp +++ b/src/ARMJIT_x64/ARMJIT_ALU.cpp @@ -255,8 +255,8 @@ OpArg Compiler::Comp_RegShiftReg(int op, Gen::OpArg rs, Gen::OpArg rm, bool S, b if (S) { XOR(32, R(RSCRATCH2), R(RSCRATCH2)); - BT(32, R(RCPSR), Imm8(29)); - SETcc(CC_C, R(RSCRATCH2)); + TEST(32, R(RCPSR), Imm32(1 << 29)); + SETcc(CC_NZ, R(RSCRATCH2)); } MOV(32, R(RSCRATCH), rm); diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index f51d4d9..9096397 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -9,13 +9,43 @@ using namespace Gen; namespace ARMJIT { template <> -const X64Reg RegCache::NativeRegAllocOrder[] = {RBX, RSI, RDI, R12, R13}; +const X64Reg RegCache::NativeRegAllocOrder[] = +{ +#ifdef _WIN32 + RBX, RSI, RDI, R12, R13 +#else + RBX, R12, R13 +#endif +}; template <> -const int RegCache::NativeRegsAvailable = 5; +const int RegCache::NativeRegsAvailable = +#ifdef _WIN32 + 5 +#else + 3 +#endif +; Compiler::Compiler() { - AllocCodeSpace(1024 * 1024 * 4); + AllocCodeSpace(1024 * 1024 * 16); + + for (int i = 0; i < 15; i++) + { + ReadMemFuncs9[i] = Gen_MemoryRoutine9(false, 32, 0x1000000 * i); + WriteMemFuncs9[i] = Gen_MemoryRoutine9(true, 32, 0x1000000 * i); + for (int j = 0; j < 2; j++) + { + ReadMemFuncs7[j][i] = Gen_MemoryRoutine7(false, 32, j, 0x1000000 * i); + WriteMemFuncs7[j][i] = Gen_MemoryRoutine7(true, 32, j, 0x1000000 * i); + } + } + ReadMemFuncs9[15] = Gen_MemoryRoutine9(false, 32, 0xFF000000); + WriteMemFuncs9[15] = Gen_MemoryRoutine9(true, 32, 0xFF000000); + ReadMemFuncs7[15][0] = ReadMemFuncs7[15][1] = Gen_MemoryRoutine7(false, 32, false, 0xFF000000); + WriteMemFuncs7[15][0] = WriteMemFuncs7[15][1] = Gen_MemoryRoutine7(true, 32, false, 0xFF000000); + + ResetStart = GetWritableCodePtr(); } void Compiler::LoadCPSR() @@ -42,7 +72,7 @@ void Compiler::LoadReg(int reg, X64Reg nativeReg) MOV(32, R(nativeReg), Imm32(R15)); } -void Compiler::UnloadReg(int reg, X64Reg nativeReg) +void Compiler::SaveReg(int reg, X64Reg nativeReg) { MOV(32, MDisp(RCPU, offsetof(ARM, R[reg])), R(nativeReg)); } @@ -52,7 +82,7 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs if (IsAlmostFull()) { ResetBlocks(); - ResetCodePtr(); + SetCodePtr((u8*)ResetStart); } CompiledBlock res = (CompiledBlock)GetWritableCodePtr(); @@ -61,8 +91,9 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs Thumb = cpu->CPSR & 0x20; Num = cpu->Num; R15 = cpu->R[15]; + CodeRegion = cpu->CodeRegion; - ABI_PushRegistersAndAdjustStack({ABI_ALL_CALLEE_SAVED}, 8, 0); + ABI_PushRegistersAndAdjustStack({ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS}, 8, 16); MOV(64, R(RCPU), ImmPtr(cpu)); XOR(32, R(RCycles), R(RCycles)); @@ -142,9 +173,9 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs else { // could have used a LUT, but then where would be the fun? - BT(32, R(RCPSR), Imm8(28 + ((~(cond >> 1) & 1) << 1 | (cond >> 2 & 1) ^ (cond >> 1 & 1)))); + TEST(32, R(RCPSR), Imm32(1 << (28 + ((~(cond >> 1) & 1) << 1 | (cond >> 2 & 1) ^ (cond >> 1 & 1))))); - skipExecute = J_CC(cond & 1 ? CC_C : CC_NC); + skipExecute = J_CC(cond & 1 ? CC_NZ : CC_Z); } } @@ -187,7 +218,7 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs LEA(32, RAX, MDisp(RCycles, ConstantCycles)); - ABI_PopRegistersAndAdjustStack({ABI_ALL_CALLEE_SAVED}, 8, 0); + ABI_PopRegistersAndAdjustStack({ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS}, 8, 16); RET(); return res; @@ -243,23 +274,38 @@ CompileFunc Compiler::GetCompFunc(int kind) A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, // CMN A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, + // Mul + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + // ARMv5 stuff + NULL, NULL, NULL, NULL, NULL, + // STR + A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, + // STRB + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + // LDR + A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, + // LDRB + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + // STRH + NULL, NULL, NULL, NULL, + // LDRD + NULL, NULL, NULL, NULL, + // STRD + NULL, NULL, NULL, NULL, + // LDRH + NULL, NULL, NULL, NULL, + // LDRSB NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + // LDRSH + NULL, NULL, NULL, NULL, + // swap + NULL, NULL, + // LDM/STM + NULL, NULL, + // Branch + NULL, NULL, NULL, NULL, NULL, + // system stuff + NULL, NULL, NULL, NULL, NULL, NULL, NULL, }; const CompileFunc T_Comp[ARMInstrInfo::tk_Count] = { @@ -278,10 +324,17 @@ CompileFunc Compiler::GetCompFunc(int kind) T_Comp_ALU_HiReg, T_Comp_ALU_HiReg, T_Comp_ALU_HiReg, // pc/sp relative NULL, NULL, NULL, - // mem... - NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, + // LDR pcrel + NULL, + // LDR/STR reg offset + T_Comp_MemReg, NULL, T_Comp_MemReg, NULL, + // LDR/STR sign extended, half + NULL, NULL, NULL, NULL, + // LDR/STR imm offset + T_Comp_MemImm, T_Comp_MemImm, NULL, NULL, + // LDR/STR half imm offset + NULL, NULL, + // branch, etc. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index 9b454f4..7ab9b25 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -29,7 +29,7 @@ public: CompiledBlock CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrsCount); void LoadReg(int reg, Gen::X64Reg nativeReg); - void UnloadReg(int reg, Gen::X64Reg nativeReg); + void SaveReg(int reg, Gen::X64Reg nativeReg); private: CompileFunc GetCompFunc(int kind); @@ -51,12 +51,17 @@ private: void A_Comp_MovOp(); void A_Comp_CmpOp(); + void A_Comp_MemWB(); + void T_Comp_ShiftImm(); void T_Comp_AddSub_(); void T_Comp_ALU_Imm8(); void T_Comp_ALU(); void T_Comp_ALU_HiReg(); + void T_Comp_MemReg(); + void T_Comp_MemImm(); + void Comp_ArithTriOp(void (Compiler::*op)(int, const Gen::OpArg&, const Gen::OpArg&), Gen::OpArg rd, Gen::OpArg rn, Gen::OpArg op2, bool carryUsed, int opFlags); void Comp_ArithTriOpReverse(void (Compiler::*op)(int, const Gen::OpArg&, const Gen::OpArg&), @@ -65,10 +70,14 @@ private: void Comp_RetriveFlags(bool sign, bool retriveCV, bool carryUsed); + void* Gen_MemoryRoutine9(bool store, int size, u32 region); + void* Gen_MemoryRoutine7(bool store, int size, bool mainRAMCode, u32 region); + Gen::OpArg Comp_RegShiftImm(int op, int amount, Gen::OpArg rm, bool S, bool& carryUsed); Gen::OpArg Comp_RegShiftReg(int op, Gen::OpArg rs, Gen::OpArg rm, bool S, bool& carryUsed); Gen::OpArg A_Comp_GetALUOp2(bool S, bool& carryUsed); + Gen::OpArg A_Comp_GetMemWBOffset(); void LoadCPSR(); void SaveCPSR(); @@ -82,6 +91,8 @@ private: return Gen::R(RegCache.Mapping[reg]); } + void* ResetStart; + bool CPSRDirty = false; FetchedInstr CurrentInstr; @@ -91,10 +102,16 @@ private: bool Thumb; u32 Num; u32 R15; + u32 CodeRegion; u32 ConstantCycles; }; +extern void* ReadMemFuncs9[16]; +extern void* ReadMemFuncs7[2][16]; +extern void* WriteMemFuncs9[16]; +extern void* WriteMemFuncs7[2][16]; + } #endif \ No newline at end of file diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index e69de29..d534269 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -0,0 +1,600 @@ +#include "ARMJIT_Compiler.h" + +#include "../GPU.h" +#include "../Wifi.h" + +namespace NDS +{ +#define MAIN_RAM_SIZE 0x400000 +extern u8* SWRAM_ARM9; +extern u32 SWRAM_ARM9Mask; +extern u8* SWRAM_ARM7; +extern u32 SWRAM_ARM7Mask; +extern u8 ARM7WRAM[]; +extern u16 ARM7BIOSProt; +} + +using namespace Gen; + +namespace ARMJIT +{ + +void* ReadMemFuncs9[16]; +void* ReadMemFuncs7[2][16]; +void* WriteMemFuncs9[16]; +void* WriteMemFuncs7[2][16]; + +template +int squeezePointer(T* ptr) +{ + int truncated = (int)((u64)ptr); + assert((T*)((u64)truncated) == ptr); + return truncated; +} + +u32 ReadVRAM9(u32 addr) +{ + switch (addr & 0x00E00000) + { + case 0x00000000: return GPU::ReadVRAM_ABG(addr); + case 0x00200000: return GPU::ReadVRAM_BBG(addr); + case 0x00400000: return GPU::ReadVRAM_AOBJ(addr); + case 0x00600000: return GPU::ReadVRAM_BOBJ(addr); + default: return GPU::ReadVRAM_LCDC(addr); + } +} + +void WriteVRAM9(u32 addr, u32 val) +{ + switch (addr & 0x00E00000) + { + case 0x00000000: GPU::WriteVRAM_ABG(addr, val); return; + case 0x00200000: GPU::WriteVRAM_BBG(addr, val); return; + case 0x00400000: GPU::WriteVRAM_AOBJ(addr, val); return; + case 0x00600000: GPU::WriteVRAM_BOBJ(addr, val); return; + default: GPU::WriteVRAM_LCDC(addr, val); return; + } +} + +/* + R11 - data to write (store only) + RSCRATCH2 - address + RSCRATCH3 - code cycles +*/ +void* Compiler::Gen_MemoryRoutine9(bool store, int size, u32 region) +{ + AlignCode4(); + void* res = (void*)GetWritableCodePtr(); + + if (!store) + { + MOV(32, R(RSCRATCH), R(RSCRATCH2)); + AND(32, R(RSCRATCH), Imm8(0x3)); + SHL(32, R(RSCRATCH), Imm8(3)); + // enter the shadow realm! + MOV(32, MDisp(RSP, 8), R(RSCRATCH)); + } + + // cycle counting! + // this is AddCycles_CDI + MOV(32, R(R10), R(RSCRATCH2)); + SHR(32, R(R10), Imm8(12)); + MOVZX(32, 8, R10, MComplex(RCPU, R10, SCALE_1, offsetof(ARMv5, MemTimings) + 2)); + LEA(32, RSCRATCH, MComplex(RSCRATCH3, R10, SCALE_1, -6)); + CMP(32, R(R10), R(RSCRATCH3)); + CMOVcc(32, RSCRATCH3, R(R10), CC_G); + CMP(32, R(RSCRATCH), R(RSCRATCH3)); + CMOVcc(32, RSCRATCH3, R(RSCRATCH), CC_G); + ADD(32, R(RCycles), R(RSCRATCH3)); + + if (!store) + XOR(32, R(RSCRATCH), R(RSCRATCH)); + AND(32, R(RSCRATCH2), Imm32(~3)); + + { + MOV(32, R(RSCRATCH3), R(RSCRATCH2)); + SUB(32, R(RSCRATCH2), MDisp(RCPU, offsetof(ARMv5, DTCMBase))); + CMP(32, R(RSCRATCH2), MDisp(RCPU, offsetof(ARMv5, DTCMSize))); + FixupBranch outsideDTCM = J_CC(CC_AE); + AND(32, R(RSCRATCH2), Imm32(0x3FFF)); + if (!store) + { + MOV(32, R(RSCRATCH), MComplex(RCPU, RSCRATCH2, SCALE_1, offsetof(ARMv5, DTCM))); + MOV(32, R(ECX), MDisp(RSP, 8)); + ROR_(32, R(RSCRATCH), R(ECX)); + } + else + MOV(32, MComplex(RCPU, RSCRATCH2, SCALE_1, offsetof(ARMv5, DTCM)), R(R11)); + RET(); + SetJumpTarget(outsideDTCM); + MOV(32, R(RSCRATCH2), R(RSCRATCH3)); + } + + switch (region) + { + case 0x00000000: + case 0x01000000: + { + CMP(32, R(RSCRATCH2), MDisp(RCPU, offsetof(ARMv5, ITCMSize))); + FixupBranch insideITCM = J_CC(CC_B); + RET(); + SetJumpTarget(insideITCM); + AND(32, R(RSCRATCH2), Imm32(0x7FFF)); + if (!store) + MOV(32, R(RSCRATCH), MComplex(RCPU, RSCRATCH2, SCALE_1, offsetof(ARMv5, ITCM))); + else + { + MOV(32, MComplex(RCPU, RSCRATCH2, SCALE_1, offsetof(ARMv5, ITCM)), R(R11)); + MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.ARM9_ITCM)), Imm32(0)); + MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.ARM9_ITCM) + 8), Imm32(0)); + } + } + break; + case 0x02000000: + AND(32, R(RSCRATCH2), Imm32(MAIN_RAM_SIZE - 1)); + if (!store) + MOV(32, R(RSCRATCH), MDisp(RSCRATCH2, squeezePointer(NDS::MainRAM))); + else + { + MOV(32, MDisp(RSCRATCH2, squeezePointer(NDS::MainRAM)), R(R11)); + MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.MainRAM)), Imm32(0)); + MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.MainRAM) + 8), Imm32(0)); + } + break; + case 0x03000000: + { + MOV(64, R(RSCRATCH3), M(&NDS::SWRAM_ARM9)); + TEST(64, R(RSCRATCH3), R(RSCRATCH3)); + FixupBranch notMapped = J_CC(CC_Z); + AND(32, R(RSCRATCH2), M(&NDS::SWRAM_ARM9Mask)); + if (!store) + MOV(32, R(RSCRATCH), MRegSum(RSCRATCH2, RSCRATCH3)); + else + { + MOV(32, MRegSum(RSCRATCH2, RSCRATCH3), R(R11)); + MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.SWRAM)), Imm32(0)); + MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.SWRAM) + 8), Imm32(0)); + } + SetJumpTarget(notMapped); + } + break; + case 0x04000000: + MOV(32, R(ABI_PARAM1), R(RSCRATCH2)); + if (!store) + { + ABI_PushRegistersAndAdjustStack({}, 8, 0); + ABI_CallFunction(NDS::ARM9IORead32); + ABI_PopRegistersAndAdjustStack({}, 8, 0); + } + else + { + MOV(32, R(ABI_PARAM2), R(R11)); + JMP((u8*)NDS::ARM9IOWrite32, true); + } + break; + case 0x05000000: + { + MOV(32, R(RSCRATCH), Imm32(1<<1)); + MOV(32, R(RSCRATCH3), Imm32(1<<9)); + TEST(32, R(RSCRATCH2), Imm32(0x400)); + CMOVcc(32, RSCRATCH, R(RSCRATCH3), CC_NZ); + TEST(16, R(RSCRATCH), M(&NDS::PowerControl9)); + FixupBranch available = J_CC(CC_NZ); + RET(); + SetJumpTarget(available); + AND(32, R(RSCRATCH2), Imm32(0x7FF)); + if (!store) + MOV(32, R(RSCRATCH), MDisp(RSCRATCH2, squeezePointer(GPU::Palette))); + else + MOV(32, MDisp(RSCRATCH2, squeezePointer(GPU::Palette)), R(R11)); + } + break; + case 0x06000000: + MOV(32, R(ABI_PARAM1), R(RSCRATCH2)); + if (!store) + { + ABI_PushRegistersAndAdjustStack({}, 8); + ABI_CallFunction(ReadVRAM9); + ABI_PopRegistersAndAdjustStack({}, 8); + } + else + { + MOV(32, R(ABI_PARAM2), R(R11)); + JMP((u8*)WriteVRAM9, true); + } + break; + case 0x07000000: + { + MOV(32, R(RSCRATCH), Imm32(1<<1)); + MOV(32, R(RSCRATCH3), Imm32(1<<9)); + TEST(32, R(RSCRATCH2), Imm32(0x400)); + CMOVcc(32, RSCRATCH, R(RSCRATCH3), CC_NZ); + TEST(16, R(RSCRATCH), M(&NDS::PowerControl9)); + FixupBranch available = J_CC(CC_NZ); + RET(); + SetJumpTarget(available); + AND(32, R(RSCRATCH2), Imm32(0x7FF)); + if (!store) + MOV(32, R(RSCRATCH), MDisp(RSCRATCH2, squeezePointer(GPU::OAM))); + else + MOV(32, MDisp(RSCRATCH2, squeezePointer(GPU::OAM)), R(R11)); + } + break; + case 0x08000000: + case 0x09000000: + case 0x0A000000: + if (!store) + MOV(32, R(RSCRATCH), Imm32(0xFFFFFFFF)); + break; + case 0xFF000000: + if (!store) + { + AND(32, R(RSCRATCH2), Imm32(0xFFF)); + MOV(32, R(RSCRATCH), MDisp(RSCRATCH2, squeezePointer(NDS::ARM9BIOS))); + } + break; + default: + MOV(32, R(ABI_PARAM1), R(RSCRATCH2)); + if (!store) + { + ABI_PushRegistersAndAdjustStack({}, 8, 0); + ABI_CallFunction(NDS::ARM9Read32); + ABI_PopRegistersAndAdjustStack({}, 8, 0); + } + else + { + MOV(32, R(ABI_PARAM2), R(R11)); + JMP((u8*)NDS::ARM9Write32, true); + } + break; + } + + if (!store) + { + MOV(32, R(ECX), MDisp(RSP, 8)); + ROR_(32, R(RSCRATCH), R(ECX)); + } + + RET(); + + return res; +} + +void* Compiler::Gen_MemoryRoutine7(bool store, int size, bool mainRAMCode, u32 region) +{ + AlignCode4(); + void* res = GetWritableCodePtr(); + + if (!store) + { + MOV(32, R(RSCRATCH), R(RSCRATCH2)); + AND(32, R(RSCRATCH), Imm8(0x3)); + SHL(32, R(RSCRATCH), Imm8(3)); + // enter the shadow realm! + MOV(32, MDisp(RSP, 8), R(RSCRATCH)); + } + + // AddCycles_CDI + MOV(32, R(RSCRATCH), R(RSCRATCH2)); + SHR(32, R(RSCRATCH), Imm8(15)); + MOVZX(32, 8, RSCRATCH, MDisp(RSCRATCH, squeezePointer(NDS::ARM7MemTimings + 2))); + if ((region == 0x02000000 && mainRAMCode) || (region != 0x02000000 && !mainRAMCode)) + { + if (!store && region != 0x02000000) + LEA(32, RSCRATCH3, MComplex(RSCRATCH, RSCRATCH3, SCALE_1, 1)); + ADD(32, R(RCycles), R(RSCRATCH3)); + } + else + { + if (!store) + ADD(32, R(region == 0x02000000 ? RSCRATCH2 : RSCRATCH), Imm8(1)); + LEA(32, R10, MComplex(RSCRATCH, RSCRATCH3, SCALE_1, -3)); + CMP(32, R(RSCRATCH3), R(RSCRATCH)); + CMOVcc(32, RSCRATCH, R(RSCRATCH3), CC_G); + CMP(32, R(R10), R(RSCRATCH)); + CMOVcc(32, RSCRATCH, R(R10), CC_G); + ADD(32, R(RCycles), R(RSCRATCH)); + } + + if (!store) + XOR(32, R(RSCRATCH), R(RSCRATCH)); + AND(32, R(RSCRATCH2), Imm32(~3)); + + switch (region) + { + case 0x00000000: + if (!store) { + CMP(32, R(RSCRATCH2), Imm32(0x4000)); + FixupBranch outsideBIOS1 = J_CC(CC_AE); + + MOV(32, R(RSCRATCH), MDisp(RCPU, offsetof(ARM, R[15]))); + CMP(32, R(RSCRATCH), Imm32(0x4000)); + FixupBranch outsideBIOS2 = J_CC(CC_AE); + MOV(32, R(RSCRATCH3), M(&NDS::ARM7BIOSProt)); + CMP(32, R(RSCRATCH2), R(RSCRATCH3)); + FixupBranch notDenied1 = J_CC(CC_AE); + CMP(32, R(RSCRATCH), R(RSCRATCH3)); + FixupBranch notDenied2 = J_CC(CC_B); + SetJumpTarget(outsideBIOS2); + MOV(32, R(RSCRATCH), Imm32(0xFFFFFFFF)); + RET(); + + SetJumpTarget(notDenied1); + SetJumpTarget(notDenied2); + MOV(32, R(RSCRATCH), MDisp(RSCRATCH2, squeezePointer(NDS::ARM7BIOS))); + MOV(32, R(ECX), MDisp(RSP, 8)); + ROR_(32, R(RSCRATCH), R(ECX)); + RET(); + + SetJumpTarget(outsideBIOS1); + } + break; + case 0x02000000: + AND(32, R(RSCRATCH2), Imm32(MAIN_RAM_SIZE - 1)); + if (!store) + MOV(32, R(RSCRATCH), MDisp(RSCRATCH2, squeezePointer(NDS::MainRAM))); + else + { + MOV(32, MDisp(RSCRATCH2, squeezePointer(NDS::MainRAM)), R(R11)); + MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.MainRAM)), Imm32(0)); + MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.MainRAM) + 8), Imm32(0)); + } + break; + case 0x03000000: + { + TEST(32, R(RSCRATCH2), Imm32(0x800000)); + FixupBranch region = J_CC(CC_NZ); + MOV(64, R(RSCRATCH), M(&NDS::SWRAM_ARM7)); + TEST(64, R(RSCRATCH), R(RSCRATCH)); + FixupBranch notMapped = J_CC(CC_Z); + AND(32, R(RSCRATCH2), M(&NDS::SWRAM_ARM7Mask)); + if (!store) + { + MOV(32, R(RSCRATCH), MRegSum(RSCRATCH, RSCRATCH2)); + MOV(32, R(ECX), MDisp(RSP, 8)); + ROR_(32, R(RSCRATCH), R(ECX)); + } + else + { + MOV(32, MRegSum(RSCRATCH, RSCRATCH2), R(R11)); + MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.SWRAM)), Imm32(0)); + MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.SWRAM) + 8), Imm32(0)); + } + RET(); + SetJumpTarget(region); + SetJumpTarget(notMapped); + AND(32, R(RSCRATCH2), Imm32(0xFFFF)); + if (!store) + MOV(32, R(RSCRATCH), MDisp(RSCRATCH2, squeezePointer(NDS::ARM7WRAM))); + else + { + MOV(32, MDisp(RSCRATCH2, squeezePointer(NDS::ARM7WRAM)), R(R11)); + MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.ARM7_WRAM)), Imm32(0)); + MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.ARM7_WRAM) + 8), Imm32(0)); + } + } + break; + case 0x04000000: + { + TEST(32, R(RSCRATCH2), Imm32(0x800000)); + FixupBranch region = J_CC(CC_NZ); + MOV(32, R(ABI_PARAM1), R(RSCRATCH2)); + if (!store) + { + ABI_PushRegistersAndAdjustStack({}, 8); + ABI_CallFunction(NDS::ARM7IORead32); + ABI_PopRegistersAndAdjustStack({}, 8); + + MOV(32, R(ECX), MDisp(RSP, 8)); + ROR_(32, R(RSCRATCH), R(ECX)); + RET(); + } + else + { + MOV(32, R(ABI_PARAM2), R(R11)); + JMP((u8*)NDS::ARM7IOWrite32, true); + } + SetJumpTarget(region); + + if (!store) + { + ABI_PushRegistersAndAdjustStack({RSCRATCH2}, 8); + MOV(32, R(ABI_PARAM1), R(RSCRATCH2)); + ABI_CallFunction(Wifi::Read); + ABI_PopRegistersAndAdjustStack({RSCRATCH2}, 8); + + ADD(32, R(RSCRATCH2), Imm8(2)); + ABI_PushRegistersAndAdjustStack({EAX}, 8); + MOV(32, R(ABI_PARAM1), R(RSCRATCH2)); + ABI_CallFunction(Wifi::Read); + MOV(32, R(RSCRATCH2), R(EAX)); + SHL(32, R(RSCRATCH2), Imm8(16)); + ABI_PopRegistersAndAdjustStack({EAX}, 8); + OR(32, R(EAX), R(RSCRATCH2)); + } + else + { + ABI_PushRegistersAndAdjustStack({RSCRATCH2, R11}, 8); + MOV(32, R(ABI_PARAM1), R(RSCRATCH2)); + MOVZX(32, 16, ABI_PARAM2, R(R11)); + ABI_CallFunction(Wifi::Write); + ABI_PopRegistersAndAdjustStack({RSCRATCH2, R11}, 8); + SHR(32, R(R11), Imm8(16)); + ADD(32, R(RSCRATCH2), Imm8(2)); + ABI_PushRegistersAndAdjustStack({RSCRATCH2, R11}, 8); + MOV(32, R(ABI_PARAM1), R(RSCRATCH2)); + MOVZX(32, 16, ABI_PARAM2, R(R11)); + ABI_CallFunction(Wifi::Write); + ABI_PopRegistersAndAdjustStack({RSCRATCH2, R11}, 8); + } + } + break; + case 0x06000000: + MOV(32, R(ABI_PARAM1), R(RSCRATCH2)); + if (!store) + { + ABI_PushRegistersAndAdjustStack({}, 8); + ABI_CallFunction(GPU::ReadVRAM_ARM7); + ABI_PopRegistersAndAdjustStack({}, 8); + } + else + { + AND(32, R(ABI_PARAM1), Imm32(0x40000 - 1)); + MOV(64, MScaled(ABI_PARAM1, SCALE_4, squeezePointer(cache.ARM7_WVRAM)), Imm32(0)); + MOV(64, MScaled(ABI_PARAM1, SCALE_4, squeezePointer(cache.ARM7_WVRAM) + 8), Imm32(0)); + MOV(32, R(ABI_PARAM2), R(R11)); + JMP((u8*)GPU::WriteVRAM_ARM7, true); + } + break; + case 0x08000000: + case 0x09000000: + case 0x0A000000: + if (!store) + MOV(32, R(RSCRATCH), Imm32(0xFFFFFFFF)); + break; + /*default: + ABI_PushRegistersAndAdjustStack({}, 8, 0); + MOV(32, R(ABI_PARAM1), R(RSCRATCH2)); + ABI_CallFunction(NDS::ARM7Read32); + ABI_PopRegistersAndAdjustStack({}, 8, 0); + break;*/ + } + + if (!store) + { + MOV(32, R(ECX), MDisp(RSP, 8)); + ROR_(32, R(RSCRATCH), R(ECX)); + } + + RET(); + + return res; +} + +OpArg Compiler::A_Comp_GetMemWBOffset() +{ + if (!(CurrentInstr.Instr & (1 << 25))) + return Imm32(CurrentInstr.Instr & 0xFFF); + else + { + int op = (CurrentInstr.Instr >> 5) & 0x3; + int amount = (CurrentInstr.Instr >> 7) & 0x1F; + OpArg rm = MapReg(CurrentInstr.A_Reg(0)); + bool carryUsed; + return Comp_RegShiftImm(op, amount, rm, false, carryUsed); + } +} + +void Compiler::A_Comp_MemWB() +{ + OpArg rn = MapReg(CurrentInstr.A_Reg(16)); + OpArg rd = MapReg(CurrentInstr.A_Reg(12)); + bool load = CurrentInstr.Instr & (1 << 20); + + MOV(32, R(RSCRATCH2), rn); + if (CurrentInstr.Instr & (1 << 24)) + { + OpArg offset = A_Comp_GetMemWBOffset(); + if (CurrentInstr.Instr & (1 << 23)) + ADD(32, R(RSCRATCH2), offset); + else + SUB(32, R(RSCRATCH2), offset); + + if (CurrentInstr.Instr & (1 << 21)) + MOV(32, rn, R(RSCRATCH2)); + } + + u32 cycles = Num ? NDS::ARM7MemTimings[CurrentInstr.CodeCycles][2] : CurrentInstr.CodeCycles; + MOV(32, R(RSCRATCH3), Imm32(cycles)); + MOV(32, R(RSCRATCH), R(RSCRATCH2)); + SHR(32, R(RSCRATCH), Imm8(24)); + AND(32, R(RSCRATCH), Imm8(0xF)); + void** funcArray; + if (load) + funcArray = Num ? ReadMemFuncs7[CodeRegion == 0x02] : ReadMemFuncs9; + else + { + funcArray = Num ? WriteMemFuncs7[CodeRegion == 0x02] : WriteMemFuncs9; + MOV(32, R(R11), rd); + } + CALLptr(MScaled(RSCRATCH, SCALE_8, squeezePointer(funcArray))); + + if (load) + MOV(32, R(RSCRATCH2), R(RSCRATCH)); + + if (!(CurrentInstr.Instr & (1 << 24))) + { + OpArg offset = A_Comp_GetMemWBOffset(); + + if (CurrentInstr.Instr & (1 << 23)) + ADD(32, rn, offset); + else + SUB(32, rn, offset); + } + + if (load) + MOV(32, rd, R(RSCRATCH2)); +} + +void Compiler::T_Comp_MemReg() +{ + OpArg rd = MapReg(CurrentInstr.T_Reg(0)); + OpArg rb = MapReg(CurrentInstr.T_Reg(3)); + OpArg ro = MapReg(CurrentInstr.T_Reg(6)); + + int op = (CurrentInstr.Instr >> 10) & 0x3; + bool load = op & 0x2; + + MOV(32, R(RSCRATCH2), rb); + ADD(32, R(RSCRATCH2), ro); + + u32 cycles = Num ? NDS::ARM7MemTimings[CurrentInstr.CodeCycles][0] : (R15 & 0x2 ? 0 : CurrentInstr.CodeCycles); + MOV(32, R(RSCRATCH3), Imm32(cycles)); + MOV(32, R(RSCRATCH), R(RSCRATCH2)); + SHR(32, R(RSCRATCH), Imm8(24)); + AND(32, R(RSCRATCH), Imm8(0xF)); + void** funcArray; + if (load) + funcArray = Num ? ReadMemFuncs7[CodeRegion == 0x02] : ReadMemFuncs9; + else + { + funcArray = Num ? WriteMemFuncs7[CodeRegion == 0x02] : WriteMemFuncs9; + MOV(32, R(R11), rd); + } + CALLptr(MScaled(RSCRATCH, SCALE_8, squeezePointer(funcArray))); + + if (load) + MOV(32, rd, R(RSCRATCH)); +} + +void Compiler::T_Comp_MemImm() +{ + // TODO: aufräumen!!! + OpArg rd = MapReg(CurrentInstr.T_Reg(0)); + OpArg rb = MapReg(CurrentInstr.T_Reg(3)); + + int op = (CurrentInstr.Instr >> 11) & 0x3; + u32 offset = ((CurrentInstr.Instr >> 6) & 0x1F) * 4; + bool load = op & 0x1; + + LEA(32, RSCRATCH2, MDisp(rb.GetSimpleReg(), offset)); + u32 cycles = Num ? NDS::ARM7MemTimings[CurrentInstr.CodeCycles][0] : (R15 & 0x2 ? 0 : CurrentInstr.CodeCycles); + MOV(32, R(RSCRATCH3), Imm32(cycles)); + MOV(32, R(RSCRATCH), R(RSCRATCH2)); + SHR(32, R(RSCRATCH), Imm8(24)); + AND(32, R(RSCRATCH), Imm8(0xF)); + void** funcArray; + if (load) + funcArray = Num ? ReadMemFuncs7[CodeRegion == 0x02] : ReadMemFuncs9; + else + { + funcArray = Num ? WriteMemFuncs7[CodeRegion == 0x02] : WriteMemFuncs9; + MOV(32, R(R11), rd); + } + CALLptr(MScaled(RSCRATCH, SCALE_8, squeezePointer(funcArray))); + + if (load) + MOV(32, rd, R(RSCRATCH)); +} + +} \ No newline at end of file diff --git a/src/ARM_InstrInfo.h b/src/ARM_InstrInfo.h index e717664..dcd938b 100644 --- a/src/ARM_InstrInfo.h +++ b/src/ARM_InstrInfo.h @@ -83,10 +83,10 @@ enum ak_ALU(BIC), ak_ALU(MVN), - ak_ALU(TST), - ak_ALU(TEQ), - ak_ALU(CMP), - ak_ALU(CMN), + ak_Test(TST), + ak_Test(TEQ), + ak_Test(CMP), + ak_Test(CMN), ak_MUL, ak_MLA, diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0faa57a..ae04ffb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -53,6 +53,7 @@ add_library(core STATIC ARMJIT.cpp ARMJIT_x64/ARMJIT_Compiler.cpp ARMJIT_x64/ARMJIT_ALU.cpp + ARMJIT_x64/ARMJIT_LoadStore.cpp dolphin/CommonFuncs.cpp dolphin/x64ABI.cpp diff --git a/src/dolphin/x64ABI.h b/src/dolphin/x64ABI.h index 997782e..94336d0 100644 --- a/src/dolphin/x64ABI.h +++ b/src/dolphin/x64ABI.h @@ -37,7 +37,8 @@ // xmm0-xmm15 use the upper 16 bits in the functions that push/pop registers. #define ABI_ALL_CALLER_SAVED \ - (BitSet32{RAX, RCX, RDX, R8, R9, R10, R11}) + (BitSet32{RAX, RCX, RDX, R8, R9, R10, R11, XMM0 + 16, XMM1 + 16, XMM2 + 16, XMM3 + 16, \ + XMM4 + 16, XMM5 + 16}) #else // 64-bit Unix / OS X #define ABI_PARAM1 RDI -- cgit v1.2.3 From 10e386fe50af1a11ada54a380f6802025fca8efd Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sat, 6 Jul 2019 01:48:42 +0200 Subject: JIT: most mem instructions working + branching --- src/ARM.cpp | 10 +- src/ARMJIT.cpp | 7 +- src/ARMJIT.h | 2 +- src/ARMJIT_RegCache.h | 2 +- src/ARMJIT_x64/ARMJIT_ALU.cpp | 322 ++++++++------- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 145 ++++--- src/ARMJIT_x64/ARMJIT_Compiler.h | 42 +- src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 805 +++++++++++++++--------------------- src/ARM_InstrInfo.cpp | 2 +- src/NDS.cpp | 2 + 10 files changed, 653 insertions(+), 686 deletions(-) (limited to 'src') diff --git a/src/ARM.cpp b/src/ARM.cpp index eadedc7..df58ce3 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -565,8 +565,9 @@ void ARMv5::Execute() ARMJIT::CompiledBlock block = ARMJIT::LookUpBlock(0, R[15] - ((CPSR&0x20)?2:4)); if (block == NULL) - block = ARMJIT::CompileBlock(this); - Cycles += block(); + ARMJIT::CompileBlock(this); + else + Cycles += block(); // TODO optimize this shit!!! if (Halted) @@ -650,8 +651,9 @@ void ARMv4::Execute() ARMJIT::CompiledBlock block = ARMJIT::LookUpBlock(1, R[15] - ((CPSR&0x20)?2:4)); if (block == NULL) - block = ARMJIT::CompileBlock(this); - Cycles += block(); + ARMJIT::CompileBlock(this); + else + Cycles += block(); // TODO optimize this shit!!! if (Halted) diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 4da781c..6afa967 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -121,12 +121,13 @@ void DeInit() delete compiler; } -CompiledBlock CompileBlock(ARM* cpu) +void CompileBlock(ARM* cpu) { bool thumb = cpu->CPSR & 0x20; FetchedInstr instrs[12]; int i = 0; + u32 r15Initial = cpu->R[15]; u32 r15 = cpu->R[15]; u32 nextInstr[2] = {cpu->NextInstr[0], cpu->NextInstr[1]}; //printf("block %x %d\n", r15, thumb); @@ -169,9 +170,7 @@ CompiledBlock CompileBlock(ARM* cpu) CompiledBlock block = compiler->CompileBlock(cpu, instrs, i); - InsertBlock(cpu->Num, cpu->R[15] - (thumb ? 2 : 4), block); - - return block; + InsertBlock(cpu->Num, r15Initial - (thumb ? 2 : 4), block); } void ResetBlocks() diff --git a/src/ARMJIT.h b/src/ARMJIT.h index 45bb4ed..71188f9 100644 --- a/src/ARMJIT.h +++ b/src/ARMJIT.h @@ -109,7 +109,7 @@ inline void InsertBlock(u32 num, u32 addr, CompiledBlock func) void Init(); void DeInit(); -CompiledBlock CompileBlock(ARM* cpu); +void CompileBlock(ARM* cpu); void ResetBlocks(); diff --git a/src/ARMJIT_RegCache.h b/src/ARMJIT_RegCache.h index ea9fb30..556d27b 100644 --- a/src/ARMJIT_RegCache.h +++ b/src/ARMJIT_RegCache.h @@ -114,7 +114,7 @@ public: for (int reg : needToBeLoaded) LoadRegister(reg); } - DirtyRegs |= Instr.Info.DstRegs; + DirtyRegs |= Instr.Info.DstRegs & ~(1 << 15); } static const Reg NativeRegAllocOrder[]; diff --git a/src/ARMJIT_x64/ARMJIT_ALU.cpp b/src/ARMJIT_x64/ARMJIT_ALU.cpp index 6294e1d..c22751e 100644 --- a/src/ARMJIT_x64/ARMJIT_ALU.cpp +++ b/src/ARMJIT_x64/ARMJIT_ALU.cpp @@ -71,30 +71,30 @@ void Compiler::Comp_CmpOp(int op, Gen::OpArg rn, Gen::OpArg op2, bool carryUsed) { switch (op) { - case 0: // TST - if (rn.IsImm()) - { - MOV(32, R(RSCRATCH3), rn); - rn = R(RSCRATCH3); - } - TEST(32, rn, op2); - break; - case 1: // TEQ + case 0: // TST + if (rn.IsImm()) + { MOV(32, R(RSCRATCH3), rn); - XOR(32, R(RSCRATCH3), op2); - break; - case 2: // CMP - if (rn.IsImm()) - { - MOV(32, R(RSCRATCH3), rn); - rn = R(RSCRATCH3); - } - CMP(32, rn, op2); - break; - case 3: // CMN + rn = R(RSCRATCH3); + } + TEST(32, rn, op2); + break; + case 1: // TEQ + MOV(32, R(RSCRATCH3), rn); + XOR(32, R(RSCRATCH3), op2); + break; + case 2: // CMP + if (rn.IsImm()) + { MOV(32, R(RSCRATCH3), rn); - ADD(32, R(RSCRATCH3), op2); - break; + rn = R(RSCRATCH3); + } + CMP(32, rn, op2); + break; + case 3: // CMN + MOV(32, R(RSCRATCH3), rn); + ADD(32, R(RSCRATCH3), op2); + break; } Comp_RetriveFlags(op == 2, op >= 2, carryUsed); @@ -103,38 +103,38 @@ void Compiler::Comp_CmpOp(int op, Gen::OpArg rn, Gen::OpArg op2, bool carryUsed) // also calculates cycles OpArg Compiler::A_Comp_GetALUOp2(bool S, bool& carryUsed) { - if (CurrentInstr.Instr & (1 << 25)) + if (CurInstr.Instr & (1 << 25)) { Comp_AddCycles_C(); carryUsed = false; - return Imm32(ROR(CurrentInstr.Instr & 0xFF, (CurrentInstr.Instr >> 7) & 0x1E)); + return Imm32(ROR(CurInstr.Instr & 0xFF, (CurInstr.Instr >> 7) & 0x1E)); } else { - int op = (CurrentInstr.Instr >> 5) & 0x3; - if (CurrentInstr.Instr & (1 << 4)) + int op = (CurInstr.Instr >> 5) & 0x3; + if (CurInstr.Instr & (1 << 4)) { Comp_AddCycles_CI(1); - OpArg rm = MapReg(CurrentInstr.A_Reg(0)); - if (rm.IsImm() && CurrentInstr.A_Reg(0) == 15) + OpArg rm = MapReg(CurInstr.A_Reg(0)); + if (rm.IsImm() && CurInstr.A_Reg(0) == 15) rm = Imm32(rm.Imm32() + 4); - return Comp_RegShiftReg(op, MapReg(CurrentInstr.A_Reg(8)), rm, S, carryUsed); + return Comp_RegShiftReg(op, MapReg(CurInstr.A_Reg(8)), rm, S, carryUsed); } else { Comp_AddCycles_C(); - return Comp_RegShiftImm(op, (CurrentInstr.Instr >> 7) & 0x1F, - MapReg(CurrentInstr.A_Reg(0)), S, carryUsed); + return Comp_RegShiftImm(op, (CurInstr.Instr >> 7) & 0x1F, + MapReg(CurInstr.A_Reg(0)), S, carryUsed); } } } void Compiler::A_Comp_CmpOp() { - u32 op = (CurrentInstr.Instr >> 21) & 0xF; + u32 op = (CurInstr.Instr >> 21) & 0xF; bool carryUsed; - OpArg rn = MapReg(CurrentInstr.A_Reg(16)); + OpArg rn = MapReg(CurInstr.A_Reg(16)); OpArg op2 = A_Comp_GetALUOp2((1 << op) & 0xF303, carryUsed); Comp_CmpOp(op - 0x8, rn, op2, carryUsed); @@ -142,12 +142,12 @@ void Compiler::A_Comp_CmpOp() void Compiler::A_Comp_Arith() { - bool S = CurrentInstr.Instr & (1 << 20); - u32 op = (CurrentInstr.Instr >> 21) & 0xF; + bool S = CurInstr.Instr & (1 << 20); + u32 op = (CurInstr.Instr >> 21) & 0xF; bool carryUsed; - OpArg rn = MapReg(CurrentInstr.A_Reg(16)); - OpArg rd = MapReg(CurrentInstr.A_Reg(12)); + OpArg rn = MapReg(CurInstr.A_Reg(16)); + OpArg rd = MapReg(CurInstr.A_Reg(12)); OpArg op2 = A_Comp_GetALUOp2(S && (1 << op) & 0xF303, carryUsed); u32 sFlag = S ? opSetsFlags : 0; @@ -155,13 +155,13 @@ void Compiler::A_Comp_Arith() { case 0x0: // AND Comp_ArithTriOp(AND, rd, rn, op2, carryUsed, opSymmetric|sFlag); - return; + break; case 0x1: // EOR Comp_ArithTriOp(XOR, rd, rn, op2, carryUsed, opSymmetric|sFlag); - return; + break; case 0x2: // SUB Comp_ArithTriOp(SUB, rd, rn, op2, carryUsed, sFlag|opRetriveCV|opInvertCarry); - return; + break; case 0x3: // RSB if (op2.IsZero()) { @@ -173,41 +173,44 @@ void Compiler::A_Comp_Arith() } else Comp_ArithTriOpReverse(SUB, rd, rn, op2, carryUsed, sFlag|opRetriveCV|opInvertCarry); - return; + break; case 0x4: // ADD Comp_ArithTriOp(ADD, rd, rn, op2, carryUsed, opSymmetric|sFlag|opRetriveCV); - return; + break; case 0x5: // ADC Comp_ArithTriOp(ADC, rd, rn, op2, carryUsed, opSymmetric|sFlag|opRetriveCV|opSyncCarry); - return; + break; case 0x6: // SBC Comp_ArithTriOp(SBB, rd, rn, op2, carryUsed, opSymmetric|sFlag|opRetriveCV|opSyncCarry|opInvertCarry); - return; + break; case 0x7: // RSC Comp_ArithTriOpReverse(SBB, rd, rn, op2, carryUsed, sFlag|opRetriveCV|opInvertCarry|opSyncCarry); - return; + break; case 0xC: // ORR Comp_ArithTriOp(OR, rd, rn, op2, carryUsed, opSymmetric|sFlag); - return; + break; case 0xE: // BIC Comp_ArithTriOp(AND, rd, rn, op2, carryUsed, sFlag|opSymmetric|opInvertOp2); - return; + break; default: assert("unimplemented"); } + + if (CurInstr.A_Reg(12) == 15) + Comp_JumpTo(rd.GetSimpleReg(), S); } void Compiler::A_Comp_MovOp() { bool carryUsed; - bool S = CurrentInstr.Instr & (1 << 20); + bool S = CurInstr.Instr & (1 << 20); OpArg op2 = A_Comp_GetALUOp2(S, carryUsed); - OpArg rd = MapReg(CurrentInstr.A_Reg(12)); + OpArg rd = MapReg(CurInstr.A_Reg(12)); if (rd != op2) MOV(32, rd, op2); - if (((CurrentInstr.Instr >> 21) & 0xF) == 0xF) + if (((CurInstr.Instr >> 21) & 0xF) == 0xF) NOT(32, rd); if (S) @@ -215,6 +218,9 @@ void Compiler::A_Comp_MovOp() TEST(32, rd, rd); Comp_RetriveFlags(false, false, carryUsed); } + + if (CurInstr.A_Reg(12) == 15) + Comp_JumpTo(rd.GetSimpleReg(), S); } void Compiler::Comp_RetriveFlags(bool sign, bool retriveCV, bool carryUsed) @@ -230,7 +236,7 @@ void Compiler::Comp_RetriveFlags(bool sign, bool retriveCV, bool carryUsed) } if (carryUsed == 983298) - printf("etwas ist faul im lande daenemark %x\n", CurrentInstr.Instr); + printf("etwas ist faul im lande daenemark %x\n", CurInstr.Instr); SETcc(CC_S, R(RSCRATCH)); SETcc(CC_Z, R(RSCRATCH3)); @@ -324,61 +330,61 @@ OpArg Compiler::Comp_RegShiftImm(int op, int amount, OpArg rm, bool S, bool& car switch (op) { - case 0: // LSL - if (amount > 0) - { - MOV(32, R(RSCRATCH), rm); - SHL(32, R(RSCRATCH), Imm8(amount)); - if (S) - SETcc(CC_C, R(RSCRATCH2)); - - return R(RSCRATCH); - } - else - { - carryUsed = false; - return rm; - } - case 1: // LSR - if (amount > 0) - { - MOV(32, R(RSCRATCH), rm); - SHR(32, R(RSCRATCH), Imm8(amount)); - if (S) - SETcc(CC_C, R(RSCRATCH2)); - return R(RSCRATCH); - } - else - { - if (S) - { - MOV(32, R(RSCRATCH2), rm); - SHR(32, R(RSCRATCH2), Imm8(31)); - } - return Imm32(0); - } - case 2: // ASR + case 0: // LSL + if (amount > 0) + { MOV(32, R(RSCRATCH), rm); - SAR(32, R(RSCRATCH), Imm8(amount ? amount : 31)); + SHL(32, R(RSCRATCH), Imm8(amount)); if (S) - { - if (amount == 0) - BT(32, rm, Imm8(31)); SETcc(CC_C, R(RSCRATCH2)); - } + return R(RSCRATCH); - case 3: // ROR + } + else + { + carryUsed = false; + return rm; + } + case 1: // LSR + if (amount > 0) + { MOV(32, R(RSCRATCH), rm); - if (amount > 0) - ROR_(32, R(RSCRATCH), Imm8(amount)); - else - { - BT(32, R(RCPSR), Imm8(29)); - RCR(32, R(RSCRATCH), Imm8(1)); - } + SHR(32, R(RSCRATCH), Imm8(amount)); if (S) SETcc(CC_C, R(RSCRATCH2)); return R(RSCRATCH); + } + else + { + if (S) + { + MOV(32, R(RSCRATCH2), rm); + SHR(32, R(RSCRATCH2), Imm8(31)); + } + return Imm32(0); + } + case 2: // ASR + MOV(32, R(RSCRATCH), rm); + SAR(32, R(RSCRATCH), Imm8(amount ? amount : 31)); + if (S) + { + if (amount == 0) + BT(32, rm, Imm8(31)); + SETcc(CC_C, R(RSCRATCH2)); + } + return R(RSCRATCH); + case 3: // ROR + MOV(32, R(RSCRATCH), rm); + if (amount > 0) + ROR_(32, R(RSCRATCH), Imm8(amount)); + else + { + BT(32, R(RCPSR), Imm8(29)); + RCR(32, R(RSCRATCH), Imm8(1)); + } + if (S) + SETcc(CC_C, R(RSCRATCH2)); + return R(RSCRATCH); } assert(false); @@ -386,11 +392,11 @@ OpArg Compiler::Comp_RegShiftImm(int op, int amount, OpArg rm, bool S, bool& car void Compiler::T_Comp_ShiftImm() { - OpArg rd = MapReg(CurrentInstr.T_Reg(0)); - OpArg rs = MapReg(CurrentInstr.T_Reg(3)); + OpArg rd = MapReg(CurInstr.T_Reg(0)); + OpArg rs = MapReg(CurInstr.T_Reg(3)); - int op = (CurrentInstr.Instr >> 11) & 0x3; - int amount = (CurrentInstr.Instr >> 6) & 0x1F; + int op = (CurInstr.Instr >> 11) & 0x3; + int amount = (CurInstr.Instr >> 6) & 0x1F; Comp_AddCycles_C(); @@ -406,12 +412,12 @@ void Compiler::T_Comp_ShiftImm() void Compiler::T_Comp_AddSub_() { - OpArg rd = MapReg(CurrentInstr.T_Reg(0)); - OpArg rs = MapReg(CurrentInstr.T_Reg(3)); + OpArg rd = MapReg(CurInstr.T_Reg(0)); + OpArg rs = MapReg(CurInstr.T_Reg(3)); - int op = (CurrentInstr.Instr >> 9) & 0x3; + int op = (CurInstr.Instr >> 9) & 0x3; - OpArg rn = op >= 2 ? Imm32((CurrentInstr.Instr >> 6) & 0x7) : MapReg(CurrentInstr.T_Reg(6)); + OpArg rn = op >= 2 ? Imm32((CurInstr.Instr >> 6) & 0x7) : MapReg(CurInstr.T_Reg(6)); Comp_AddCycles_C(); @@ -423,38 +429,38 @@ void Compiler::T_Comp_AddSub_() void Compiler::T_Comp_ALU_Imm8() { - OpArg rd = MapReg(CurrentInstr.T_Reg(8)); + OpArg rd = MapReg(CurInstr.T_Reg(8)); - u32 op = (CurrentInstr.Instr >> 11) & 0x3; - OpArg imm = Imm32(CurrentInstr.Instr & 0xFF); + u32 op = (CurInstr.Instr >> 11) & 0x3; + OpArg imm = Imm32(CurInstr.Instr & 0xFF); Comp_AddCycles_C(); switch (op) { - case 0x0: - MOV(32, rd, imm); - TEST(32, rd, rd); - Comp_RetriveFlags(false, false, false); - return; - case 0x1: - Comp_CmpOp(2, rd, imm, false); - return; - case 0x2: - Comp_ArithTriOp(ADD, rd, rd, imm, false, opSetsFlags|opSymmetric|opRetriveCV); - return; - case 0x3: - Comp_ArithTriOp(SUB, rd, rd, imm, false, opSetsFlags|opInvertCarry|opRetriveCV); - return; + case 0x0: + MOV(32, rd, imm); + TEST(32, rd, rd); + Comp_RetriveFlags(false, false, false); + return; + case 0x1: + Comp_CmpOp(2, rd, imm, false); + return; + case 0x2: + Comp_ArithTriOp(ADD, rd, rd, imm, false, opSetsFlags|opSymmetric|opRetriveCV); + return; + case 0x3: + Comp_ArithTriOp(SUB, rd, rd, imm, false, opSetsFlags|opInvertCarry|opRetriveCV); + return; } } void Compiler::T_Comp_ALU() { - OpArg rd = MapReg(CurrentInstr.T_Reg(0)); - OpArg rs = MapReg(CurrentInstr.T_Reg(3)); + OpArg rd = MapReg(CurInstr.T_Reg(0)); + OpArg rs = MapReg(CurInstr.T_Reg(3)); - u32 op = (CurrentInstr.Instr >> 6) & 0xF; + u32 op = (CurInstr.Instr >> 6) & 0xF; if ((op >= 0x2 && op < 0x4) || op == 0x7) Comp_AddCycles_CI(1); @@ -522,28 +528,62 @@ void Compiler::T_Comp_ALU() void Compiler::T_Comp_ALU_HiReg() { - OpArg rd = MapReg(((CurrentInstr.Instr & 0x7) | ((CurrentInstr.Instr >> 4) & 0x8))); - OpArg rs = MapReg((CurrentInstr.Instr >> 3) & 0xF); + u32 rd = ((CurInstr.Instr & 0x7) | ((CurInstr.Instr >> 4) & 0x8)); + OpArg rdMapped = MapReg(rd); + OpArg rs = MapReg((CurInstr.Instr >> 3) & 0xF); - u32 op = (CurrentInstr.Instr >> 8) & 0x3; + u32 op = (CurInstr.Instr >> 8) & 0x3; Comp_AddCycles_C(); switch (op) { - case 0x0: // ADD - Comp_ArithTriOp(ADD, rd, rd, rs, false, opSymmetric|opRetriveCV); - return; - case 0x1: // CMP - Comp_CmpOp(2, rd, rs, false); - return; - case 0x2: // MOV - if (rd != rs) - MOV(32, rd, rs); - TEST(32, rd, rd); - Comp_RetriveFlags(false, false, false); - return; + case 0x0: // ADD + Comp_ArithTriOp(ADD, rdMapped, rdMapped, rs, false, opSymmetric|opRetriveCV); + break; + case 0x1: // CMP + Comp_CmpOp(2, rdMapped, rs, false); + return; // this is on purpose + case 0x2: // MOV + if (rdMapped != rs) + MOV(32, rdMapped, rs); + TEST(32, rdMapped, rdMapped); + Comp_RetriveFlags(false, false, false); + break; + } + + if (rd == 15) + { + OR(32, rdMapped, Imm8(1)); + Comp_JumpTo(rdMapped.GetSimpleReg()); } } +void Compiler::T_Comp_AddSP() +{ + Comp_AddCycles_C(); + + OpArg sp = MapReg(13); + OpArg offset = Imm32((CurInstr.Instr & 0x7F) << 2); + if (CurInstr.Instr & (1 << 7)) + SUB(32, sp, offset); + else + ADD(32, sp, offset); +} + +void Compiler::T_Comp_RelAddr() +{ + Comp_AddCycles_C(); + + OpArg rd = MapReg(CurInstr.T_Reg(8)); + u32 offset = (CurInstr.Instr & 0xFF) << 2; + if (CurInstr.Instr & (1 << 11)) + { + OpArg sp = MapReg(13); + LEA(32, rd.GetSimpleReg(), MDisp(sp.GetSimpleReg(), offset)); + } + else + MOV(32, rd, Imm32((R15 & ~2) + offset)); +} + } \ No newline at end of file diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index 9096397..b7358a2 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -9,7 +9,7 @@ using namespace Gen; namespace ARMJIT { template <> -const X64Reg RegCache::NativeRegAllocOrder[] = +const X64Reg RegCache::NativeRegAllocOrder[] = { #ifdef _WIN32 RBX, RSI, RDI, R12, R13 @@ -18,7 +18,7 @@ const X64Reg RegCache::NativeRegAllocOrder[] = #endif }; template <> -const int RegCache::NativeRegsAvailable = +const int RegCache::NativeRegsAvailable = #ifdef _WIN32 5 #else @@ -30,24 +30,33 @@ Compiler::Compiler() { AllocCodeSpace(1024 * 1024 * 16); - for (int i = 0; i < 15; i++) + for (int i = 0; i < 3; i++) { - ReadMemFuncs9[i] = Gen_MemoryRoutine9(false, 32, 0x1000000 * i); - WriteMemFuncs9[i] = Gen_MemoryRoutine9(true, 32, 0x1000000 * i); for (int j = 0; j < 2; j++) { - ReadMemFuncs7[j][i] = Gen_MemoryRoutine7(false, 32, j, 0x1000000 * i); - WriteMemFuncs7[j][i] = Gen_MemoryRoutine7(true, 32, j, 0x1000000 * i); + MemoryFuncs9[i][j] = Gen_MemoryRoutine9(j, 8 << i); + MemoryFuncs7[i][j][0] = Gen_MemoryRoutine7(j, false, 8 << i); + MemoryFuncs7[i][j][1] = Gen_MemoryRoutine7(j, true, 8 << i); } } - ReadMemFuncs9[15] = Gen_MemoryRoutine9(false, 32, 0xFF000000); - WriteMemFuncs9[15] = Gen_MemoryRoutine9(true, 32, 0xFF000000); - ReadMemFuncs7[15][0] = ReadMemFuncs7[15][1] = Gen_MemoryRoutine7(false, 32, false, 0xFF000000); - WriteMemFuncs7[15][0] = WriteMemFuncs7[15][1] = Gen_MemoryRoutine7(true, 32, false, 0xFF000000); ResetStart = GetWritableCodePtr(); } +DataRegion Compiler::ClassifyAddress(u32 addr) +{ + if (Num == 0 && addr >= ((ARMv5*)CurCPU)->DTCMBase && addr < ((ARMv5*)CurCPU)->DTCMBase) + return dataRegionDTCM; + switch (addr & 0xFF000000) + { + case 0x02000000: return dataRegionMainRAM; + case 0x03000000: return Num == 1 && (addr & 0xF00000) == 0x800000 ? dataRegionWRAM7 : dataRegionSWRAM; + case 0x04000000: return dataRegionIO; + case 0x06000000: return dataRegionVRAM; + } + return dataRegionGeneric; +} + void Compiler::LoadCPSR() { assert(!CPSRDirty); @@ -92,6 +101,7 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs Num = cpu->Num; R15 = cpu->R[15]; CodeRegion = cpu->CodeRegion; + CurCPU = cpu; ABI_PushRegistersAndAdjustStack({ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS}, 8, 16); @@ -106,27 +116,32 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs for (int i = 0; i < instrsCount; i++) { R15 += Thumb ? 2 : 4; - CurrentInstr = instrs[i]; - - CompileFunc comp = GetCompFunc(CurrentInstr.Info.Kind); + CurInstr = instrs[i]; - if (CurrentInstr.Info.Branches()) - comp = NULL; + CompileFunc comp = GetCompFunc(CurInstr.Info.Kind); if (comp == NULL || i == instrsCount - 1) { MOV(32, MDisp(RCPU, offsetof(ARM, R[15])), Imm32(R15)); - MOV(32, MDisp(RCPU, offsetof(ARM, CodeCycles)), Imm32(CurrentInstr.CodeCycles)); - MOV(32, MDisp(RCPU, offsetof(ARM, CurInstr)), Imm32(CurrentInstr.Instr)); + MOV(32, MDisp(RCPU, offsetof(ARM, CodeCycles)), Imm32(CurInstr.CodeCycles)); + MOV(32, MDisp(RCPU, offsetof(ARM, CurInstr)), Imm32(CurInstr.Instr)); if (i == instrsCount - 1) { - MOV(32, MDisp(RCPU, offsetof(ARM, NextInstr[0])), Imm32(CurrentInstr.NextInstr[0])); - MOV(32, MDisp(RCPU, offsetof(ARM, NextInstr[1])), Imm32(CurrentInstr.NextInstr[1])); + MOV(32, MDisp(RCPU, offsetof(ARM, NextInstr[0])), Imm32(CurInstr.NextInstr[0])); + MOV(32, MDisp(RCPU, offsetof(ARM, NextInstr[1])), Imm32(CurInstr.NextInstr[1])); } - SaveCPSR(); + if (comp == NULL || CurInstr.Info.Branches()) + SaveCPSR(); } + // run interpreter + cpu->CodeCycles = CurInstr.CodeCycles; + cpu->R[15] = R15; + cpu->CurInstr = CurInstr.Instr; + cpu->NextInstr[0] = CurInstr.NextInstr[0]; + cpu->NextInstr[1] = CurInstr.NextInstr[1]; + if (comp != NULL) RegCache.Prepare(i); else @@ -134,26 +149,33 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs if (Thumb) { + u32 icode = (CurInstr.Instr >> 6) & 0x3FF; if (comp == NULL) { MOV(64, R(ABI_PARAM1), R(RCPU)); - u32 icode = (CurrentInstr.Instr >> 6) & 0x3FF; ABI_CallFunction(ARMInterpreter::THUMBInstrTable[icode]); } else (this->*comp)(); + + ARMInterpreter::THUMBInstrTable[icode](cpu); } else { - u32 cond = CurrentInstr.Cond(); - if (CurrentInstr.Info.Kind == ARMInstrInfo::ak_BLX_IMM) + u32 cond = CurInstr.Cond(); + if (CurInstr.Info.Kind == ARMInstrInfo::ak_BLX_IMM) { MOV(64, R(ABI_PARAM1), R(RCPU)); ABI_CallFunction(ARMInterpreter::A_BLX_IMM); + + ARMInterpreter::A_BLX_IMM(cpu); } else if (cond == 0xF) + { Comp_AddCycles_C(); + cpu->AddCycles_C(); + } else { FixupBranch skipExecute; @@ -180,18 +202,18 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs } + u32 icode = ((CurInstr.Instr >> 4) & 0xF) | ((CurInstr.Instr >> 16) & 0xFF0); if (comp == NULL) { MOV(64, R(ABI_PARAM1), R(RCPU)); - u32 icode = ((CurrentInstr.Instr >> 4) & 0xF) | ((CurrentInstr.Instr >> 16) & 0xFF0); ABI_CallFunction(ARMInterpreter::ARMInstrTable[icode]); } else (this->*comp)(); FixupBranch skipFailed; - if (CurrentInstr.Cond() < 0xE) + if (CurInstr.Cond() < 0xE) { skipFailed = J(); SetJumpTarget(skipExecute); @@ -200,13 +222,17 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs SetJumpTarget(skipFailed); } + + if (cpu->CheckCondition(cond)) + ARMInterpreter::ARMInstrTable[icode](cpu); + else + cpu->AddCycles_C(); } } /* we don't need to collect the interpreted cycles, - since all functions only add to it, the dispatcher - takes care of it. + since cpu->Cycles is taken into account by the dispatcher. */ if (comp == NULL && i != instrsCount - 1) @@ -277,29 +303,29 @@ CompileFunc Compiler::GetCompFunc(int kind) // Mul NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, // ARMv5 stuff - NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, // STR A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, // STRB - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, // LDR A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, // LDRB - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, // STRH - NULL, NULL, NULL, NULL, + A_Comp_MemHalf, A_Comp_MemHalf, A_Comp_MemHalf, A_Comp_MemHalf, // LDRD NULL, NULL, NULL, NULL, // STRD NULL, NULL, NULL, NULL, // LDRH - NULL, NULL, NULL, NULL, + A_Comp_MemHalf, A_Comp_MemHalf, A_Comp_MemHalf, A_Comp_MemHalf, // LDRSB - NULL, NULL, NULL, NULL, + A_Comp_MemHalf, A_Comp_MemHalf, A_Comp_MemHalf, A_Comp_MemHalf, // LDRSH - NULL, NULL, NULL, NULL, + A_Comp_MemHalf, A_Comp_MemHalf, A_Comp_MemHalf, A_Comp_MemHalf, // swap - NULL, NULL, + NULL, NULL, // LDM/STM NULL, NULL, // Branch @@ -314,26 +340,26 @@ CompileFunc Compiler::GetCompFunc(int kind) // Three operand ADD/SUB T_Comp_AddSub_, T_Comp_AddSub_, T_Comp_AddSub_, T_Comp_AddSub_, // 8 bit imm - T_Comp_ALU_Imm8, T_Comp_ALU_Imm8, T_Comp_ALU_Imm8, T_Comp_ALU_Imm8, + T_Comp_ALU_Imm8, T_Comp_ALU_Imm8, T_Comp_ALU_Imm8, T_Comp_ALU_Imm8, // general ALU - T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, - T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, + T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, + T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, NULL, T_Comp_ALU, T_Comp_ALU, // hi reg T_Comp_ALU_HiReg, T_Comp_ALU_HiReg, T_Comp_ALU_HiReg, // pc/sp relative - NULL, NULL, NULL, + T_Comp_RelAddr, T_Comp_RelAddr, T_Comp_AddSP, // LDR pcrel - NULL, + NULL, // LDR/STR reg offset - T_Comp_MemReg, NULL, T_Comp_MemReg, NULL, - // LDR/STR sign extended, half - NULL, NULL, NULL, NULL, + T_Comp_MemReg, T_Comp_MemReg, T_Comp_MemReg, T_Comp_MemReg, + // LDR/STR sign extended, half + T_Comp_MemRegHalf, T_Comp_MemRegHalf, T_Comp_MemRegHalf, T_Comp_MemRegHalf, // LDR/STR imm offset - T_Comp_MemImm, T_Comp_MemImm, NULL, NULL, + T_Comp_MemImm, T_Comp_MemImm, T_Comp_MemImm, T_Comp_MemImm, // LDR/STR half imm offset - NULL, NULL, + T_Comp_MemImmHalf, T_Comp_MemImmHalf, // branch, etc. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, @@ -346,10 +372,10 @@ CompileFunc Compiler::GetCompFunc(int kind) void Compiler::Comp_AddCycles_C() { s32 cycles = Num ? - NDS::ARM7MemTimings[CurrentInstr.CodeCycles][Thumb ? 1 : 3] - : ((R15 & 0x2) ? 0 : CurrentInstr.CodeCycles); + NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 1 : 3] + : ((R15 & 0x2) ? 0 : CurInstr.CodeCycles); - if (CurrentInstr.Cond() < 0xE) + if (CurInstr.Cond() < 0xE) ADD(32, R(RCycles), Imm8(cycles)); else ConstantCycles += cycles; @@ -358,13 +384,26 @@ void Compiler::Comp_AddCycles_C() void Compiler::Comp_AddCycles_CI(u32 i) { s32 cycles = (Num ? - NDS::ARM7MemTimings[CurrentInstr.CodeCycles][Thumb ? 0 : 2] - : ((R15 & 0x2) ? 0 : CurrentInstr.CodeCycles)) + i; - - if (CurrentInstr.Cond() < 0xE) + NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2] + : ((R15 & 0x2) ? 0 : CurInstr.CodeCycles)) + i; + + if (CurInstr.Cond() < 0xE) ADD(32, R(RCycles), Imm8(cycles)); else ConstantCycles += cycles; } +void Compiler::Comp_JumpTo(Gen::X64Reg addr, bool restoreCPSR) +{ + SaveCPSR(); + + MOV(64, R(ABI_PARAM1), R(RCPU)); + MOV(32, R(ABI_PARAM2), R(addr)); + MOV(32, R(ABI_PARAM3), Imm32(restoreCPSR)); + if (Num == 0) + CALL((void*)&ARMv5::JumpTo); + else + CALL((void*)&ARMv4::JumpTo); +} + } \ No newline at end of file diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index 7ab9b25..9395a29 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -6,6 +6,8 @@ #include "../ARMJIT.h" #include "../ARMJIT_RegCache.h" +#include + namespace ARMJIT { @@ -21,6 +23,19 @@ class Compiler; typedef void (Compiler::*CompileFunc)(); +enum DataRegion +{ + dataRegionGeneric, // hey, that's me! + dataRegionMainRAM, + dataRegionSWRAM, + dataRegionVRAM, + dataRegionIO, + dataRegionExclusive, + dataRegionsCount, + dataRegionDTCM = dataRegionExclusive, + dataRegionWRAM7 = dataRegionExclusive, +}; + class Compiler : public Gen::X64CodeBlock { public: @@ -34,6 +49,8 @@ public: private: CompileFunc GetCompFunc(int kind); + void Comp_JumpTo(Gen::X64Reg addr, bool restoreCPSR = false); + void Comp_AddCycles_C(); void Comp_AddCycles_CI(u32 i); @@ -47,11 +64,14 @@ private: opInvertOp2 = 1 << 5, }; + DataRegion ClassifyAddress(u32 addr); + void A_Comp_Arith(); void A_Comp_MovOp(); void A_Comp_CmpOp(); void A_Comp_MemWB(); + void A_Comp_MemHalf(); void T_Comp_ShiftImm(); void T_Comp_AddSub_(); @@ -59,8 +79,15 @@ private: void T_Comp_ALU(); void T_Comp_ALU_HiReg(); + void T_Comp_RelAddr(); + void T_Comp_AddSP(); + void T_Comp_MemReg(); void T_Comp_MemImm(); + void T_Comp_MemRegHalf(); + void T_Comp_MemImmHalf(); + + void Comp_MemAccess(Gen::OpArg rd, bool signExtend, bool store, int size); void Comp_ArithTriOp(void (Compiler::*op)(int, const Gen::OpArg&, const Gen::OpArg&), Gen::OpArg rd, Gen::OpArg rn, Gen::OpArg op2, bool carryUsed, int opFlags); @@ -70,8 +97,8 @@ private: void Comp_RetriveFlags(bool sign, bool retriveCV, bool carryUsed); - void* Gen_MemoryRoutine9(bool store, int size, u32 region); - void* Gen_MemoryRoutine7(bool store, int size, bool mainRAMCode, u32 region); + void* Gen_MemoryRoutine9(bool store, int size); + void* Gen_MemoryRoutine7(bool store, bool codeMainRAM, int size); Gen::OpArg Comp_RegShiftImm(int op, int amount, Gen::OpArg rm, bool S, bool& carryUsed); Gen::OpArg Comp_RegShiftReg(int op, Gen::OpArg rs, Gen::OpArg rm, bool S, bool& carryUsed); @@ -92,10 +119,12 @@ private: } void* ResetStart; + void* MemoryFuncs9[3][2]; + void* MemoryFuncs7[3][2][2]; bool CPSRDirty = false; - FetchedInstr CurrentInstr; + FetchedInstr CurInstr; RegCache RegCache; @@ -105,12 +134,9 @@ private: u32 CodeRegion; u32 ConstantCycles; -}; -extern void* ReadMemFuncs9[16]; -extern void* ReadMemFuncs7[2][16]; -extern void* WriteMemFuncs9[16]; -extern void* WriteMemFuncs7[2][16]; + ARM* CurCPU; +}; } diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index d534269..69746e2 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -5,7 +5,6 @@ namespace NDS { -#define MAIN_RAM_SIZE 0x400000 extern u8* SWRAM_ARM9; extern u32 SWRAM_ARM9Mask; extern u8* SWRAM_ARM7; @@ -19,11 +18,6 @@ using namespace Gen; namespace ARMJIT { -void* ReadMemFuncs9[16]; -void* ReadMemFuncs7[2][16]; -void* WriteMemFuncs9[16]; -void* WriteMemFuncs7[2][16]; - template int squeezePointer(T* ptr) { @@ -32,569 +26,434 @@ int squeezePointer(T* ptr) return truncated; } -u32 ReadVRAM9(u32 addr) -{ - switch (addr & 0x00E00000) - { - case 0x00000000: return GPU::ReadVRAM_ABG(addr); - case 0x00200000: return GPU::ReadVRAM_BBG(addr); - case 0x00400000: return GPU::ReadVRAM_AOBJ(addr); - case 0x00600000: return GPU::ReadVRAM_BOBJ(addr); - default: return GPU::ReadVRAM_LCDC(addr); - } -} +/* + According to DeSmuME and my own research, approx. 99% (seriously, that's an empirical number) + of all memory load and store instructions always access addresses in the same region as + during the their first execution. -void WriteVRAM9(u32 addr, u32 val) -{ - switch (addr & 0x00E00000) - { - case 0x00000000: GPU::WriteVRAM_ABG(addr, val); return; - case 0x00200000: GPU::WriteVRAM_BBG(addr, val); return; - case 0x00400000: GPU::WriteVRAM_AOBJ(addr, val); return; - case 0x00600000: GPU::WriteVRAM_BOBJ(addr, val); return; - default: GPU::WriteVRAM_LCDC(addr, val); return; - } -} + I tried multiple optimisations, which would benefit from this behaviour + (having fast paths for the first region, …), though none of them yielded a measureable + improvement. +*/ /* - R11 - data to write (store only) - RSCRATCH2 - address - RSCRATCH3 - code cycles + address - ABI_PARAM1 (a.k.a. ECX = RSCRATCH3 on Windows) + store value - ABI_PARAM2 (a.k.a. RDX = RSCRATCH2 on Windows) + code cycles - ABI_PARAM3 */ -void* Compiler::Gen_MemoryRoutine9(bool store, int size, u32 region) +void* Compiler::Gen_MemoryRoutine9(bool store, int size) { + u32 addressMask = ~(size == 32 ? 3 : (size == 16 ? 1 : 0)); AlignCode4(); - void* res = (void*)GetWritableCodePtr(); + void* res = GetWritableCodePtr(); - if (!store) - { - MOV(32, R(RSCRATCH), R(RSCRATCH2)); - AND(32, R(RSCRATCH), Imm8(0x3)); - SHL(32, R(RSCRATCH), Imm8(3)); - // enter the shadow realm! - MOV(32, MDisp(RSP, 8), R(RSCRATCH)); - } + MOV(32, R(RSCRATCH), R(ABI_PARAM1)); + SUB(32, R(RSCRATCH), MDisp(RCPU, offsetof(ARMv5, DTCMBase))); + CMP(32, R(RSCRATCH), MDisp(RCPU, offsetof(ARMv5, DTCMSize))); + FixupBranch insideDTCM = J_CC(CC_B); - // cycle counting! - // this is AddCycles_CDI - MOV(32, R(R10), R(RSCRATCH2)); - SHR(32, R(R10), Imm8(12)); - MOVZX(32, 8, R10, MComplex(RCPU, R10, SCALE_1, offsetof(ARMv5, MemTimings) + 2)); - LEA(32, RSCRATCH, MComplex(RSCRATCH3, R10, SCALE_1, -6)); - CMP(32, R(R10), R(RSCRATCH3)); - CMOVcc(32, RSCRATCH3, R(R10), CC_G); - CMP(32, R(RSCRATCH), R(RSCRATCH3)); - CMOVcc(32, RSCRATCH3, R(RSCRATCH), CC_G); - ADD(32, R(RCycles), R(RSCRATCH3)); - - if (!store) - XOR(32, R(RSCRATCH), R(RSCRATCH)); - AND(32, R(RSCRATCH2), Imm32(~3)); + CMP(32, R(ABI_PARAM1), MDisp(RCPU, offsetof(ARMv5, ITCMSize))); + FixupBranch insideITCM = J_CC(CC_B); + // cycle counting! + MOV(32, R(RSCRATCH), R(ABI_PARAM1)); + SHR(32, R(RSCRATCH), Imm8(12)); + MOVZX(32, 8, RSCRATCH, MComplex(RCPU, RSCRATCH, SCALE_1, offsetof(ARMv5, MemTimings) + (size == 32 ? 2 : 0))); + LEA(32, ABI_PARAM4, MComplex(RSCRATCH, ABI_PARAM3, SCALE_1, -6)); + CMP(32, R(ABI_PARAM3), R(RSCRATCH)); + CMOVcc(32, RSCRATCH, R(ABI_PARAM3), CC_G); + CMP(32, R(ABI_PARAM4), R(RSCRATCH)); + CMOVcc(32, RSCRATCH, R(ABI_PARAM4), CC_G); + ADD(32, R(RCycles), R(RSCRATCH)); + + if (store) { - MOV(32, R(RSCRATCH3), R(RSCRATCH2)); - SUB(32, R(RSCRATCH2), MDisp(RCPU, offsetof(ARMv5, DTCMBase))); - CMP(32, R(RSCRATCH2), MDisp(RCPU, offsetof(ARMv5, DTCMSize))); - FixupBranch outsideDTCM = J_CC(CC_AE); - AND(32, R(RSCRATCH2), Imm32(0x3FFF)); - if (!store) + if (size > 8) + AND(32, R(ABI_PARAM1), Imm32(addressMask)); + switch (size) { - MOV(32, R(RSCRATCH), MComplex(RCPU, RSCRATCH2, SCALE_1, offsetof(ARMv5, DTCM))); - MOV(32, R(ECX), MDisp(RSP, 8)); - ROR_(32, R(RSCRATCH), R(ECX)); + case 32: JMP((u8*)NDS::ARM9Write32, true); break; + case 16: JMP((u8*)NDS::ARM9Write16, true); break; + case 8: JMP((u8*)NDS::ARM9Write8, true); break; } - else - MOV(32, MComplex(RCPU, RSCRATCH2, SCALE_1, offsetof(ARMv5, DTCM)), R(R11)); - RET(); - SetJumpTarget(outsideDTCM); - MOV(32, R(RSCRATCH2), R(RSCRATCH3)); } - - switch (region) + else { - case 0x00000000: - case 0x01000000: - { - CMP(32, R(RSCRATCH2), MDisp(RCPU, offsetof(ARMv5, ITCMSize))); - FixupBranch insideITCM = J_CC(CC_B); - RET(); - SetJumpTarget(insideITCM); - AND(32, R(RSCRATCH2), Imm32(0x7FFF)); - if (!store) - MOV(32, R(RSCRATCH), MComplex(RCPU, RSCRATCH2, SCALE_1, offsetof(ARMv5, ITCM))); - else - { - MOV(32, MComplex(RCPU, RSCRATCH2, SCALE_1, offsetof(ARMv5, ITCM)), R(R11)); - MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.ARM9_ITCM)), Imm32(0)); - MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.ARM9_ITCM) + 8), Imm32(0)); - } - } - break; - case 0x02000000: - AND(32, R(RSCRATCH2), Imm32(MAIN_RAM_SIZE - 1)); - if (!store) - MOV(32, R(RSCRATCH), MDisp(RSCRATCH2, squeezePointer(NDS::MainRAM))); - else - { - MOV(32, MDisp(RSCRATCH2, squeezePointer(NDS::MainRAM)), R(R11)); - MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.MainRAM)), Imm32(0)); - MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.MainRAM) + 8), Imm32(0)); - } - break; - case 0x03000000: - { - MOV(64, R(RSCRATCH3), M(&NDS::SWRAM_ARM9)); - TEST(64, R(RSCRATCH3), R(RSCRATCH3)); - FixupBranch notMapped = J_CC(CC_Z); - AND(32, R(RSCRATCH2), M(&NDS::SWRAM_ARM9Mask)); - if (!store) - MOV(32, R(RSCRATCH), MRegSum(RSCRATCH2, RSCRATCH3)); - else - { - MOV(32, MRegSum(RSCRATCH2, RSCRATCH3), R(R11)); - MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.SWRAM)), Imm32(0)); - MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.SWRAM) + 8), Imm32(0)); - } - SetJumpTarget(notMapped); - } - break; - case 0x04000000: - MOV(32, R(ABI_PARAM1), R(RSCRATCH2)); - if (!store) - { - ABI_PushRegistersAndAdjustStack({}, 8, 0); - ABI_CallFunction(NDS::ARM9IORead32); - ABI_PopRegistersAndAdjustStack({}, 8, 0); - } - else - { - MOV(32, R(ABI_PARAM2), R(R11)); - JMP((u8*)NDS::ARM9IOWrite32, true); - } - break; - case 0x05000000: - { - MOV(32, R(RSCRATCH), Imm32(1<<1)); - MOV(32, R(RSCRATCH3), Imm32(1<<9)); - TEST(32, R(RSCRATCH2), Imm32(0x400)); - CMOVcc(32, RSCRATCH, R(RSCRATCH3), CC_NZ); - TEST(16, R(RSCRATCH), M(&NDS::PowerControl9)); - FixupBranch available = J_CC(CC_NZ); - RET(); - SetJumpTarget(available); - AND(32, R(RSCRATCH2), Imm32(0x7FF)); - if (!store) - MOV(32, R(RSCRATCH), MDisp(RSCRATCH2, squeezePointer(GPU::Palette))); - else - MOV(32, MDisp(RSCRATCH2, squeezePointer(GPU::Palette)), R(R11)); - } - break; - case 0x06000000: - MOV(32, R(ABI_PARAM1), R(RSCRATCH2)); - if (!store) - { - ABI_PushRegistersAndAdjustStack({}, 8); - ABI_CallFunction(ReadVRAM9); - ABI_PopRegistersAndAdjustStack({}, 8); - } - else - { - MOV(32, R(ABI_PARAM2), R(R11)); - JMP((u8*)WriteVRAM9, true); - } - break; - case 0x07000000: + if (size == 32) { - MOV(32, R(RSCRATCH), Imm32(1<<1)); - MOV(32, R(RSCRATCH3), Imm32(1<<9)); - TEST(32, R(RSCRATCH2), Imm32(0x400)); - CMOVcc(32, RSCRATCH, R(RSCRATCH3), CC_NZ); - TEST(16, R(RSCRATCH), M(&NDS::PowerControl9)); - FixupBranch available = J_CC(CC_NZ); + ABI_PushRegistersAndAdjustStack({ABI_PARAM1}, 8); + AND(32, R(ABI_PARAM1), Imm32(addressMask)); + // everything's already in the appropriate register + ABI_CallFunction(NDS::ARM9Read32); + ABI_PopRegistersAndAdjustStack({ECX}, 8); + AND(32, R(ECX), Imm8(3)); + SHL(32, R(ECX), Imm8(3)); + ROR_(32, R(RSCRATCH), R(ECX)); RET(); - SetJumpTarget(available); - AND(32, R(RSCRATCH2), Imm32(0x7FF)); - if (!store) - MOV(32, R(RSCRATCH), MDisp(RSCRATCH2, squeezePointer(GPU::OAM))); - else - MOV(32, MDisp(RSCRATCH2, squeezePointer(GPU::OAM)), R(R11)); } - break; - case 0x08000000: - case 0x09000000: - case 0x0A000000: - if (!store) - MOV(32, R(RSCRATCH), Imm32(0xFFFFFFFF)); - break; - case 0xFF000000: - if (!store) - { - AND(32, R(RSCRATCH2), Imm32(0xFFF)); - MOV(32, R(RSCRATCH), MDisp(RSCRATCH2, squeezePointer(NDS::ARM9BIOS))); - } - break; - default: - MOV(32, R(ABI_PARAM1), R(RSCRATCH2)); - if (!store) + else if (size == 16) { - ABI_PushRegistersAndAdjustStack({}, 8, 0); - ABI_CallFunction(NDS::ARM9Read32); - ABI_PopRegistersAndAdjustStack({}, 8, 0); + AND(32, R(ABI_PARAM1), Imm32(addressMask)); + JMP((u8*)NDS::ARM9Read16, true); } else + JMP((u8*)NDS::ARM9Read8, true); + } + + SetJumpTarget(insideDTCM); + ADD(32, R(RCycles), R(ABI_PARAM3)); + AND(32, R(RSCRATCH), Imm32(0x3FFF & addressMask)); + if (store) + MOV(size, MComplex(RCPU, RSCRATCH, SCALE_1, offsetof(ARMv5, DTCM)), R(ABI_PARAM2)); + else + { + MOVZX(32, size, RSCRATCH, MComplex(RCPU, RSCRATCH, SCALE_1, offsetof(ARMv5, DTCM))); + if (size == 32) { - MOV(32, R(ABI_PARAM2), R(R11)); - JMP((u8*)NDS::ARM9Write32, true); + if (ABI_PARAM1 != ECX) + MOV(32, R(ECX), R(ABI_PARAM1)); + AND(32, R(ECX), Imm8(3)); + SHL(32, R(ECX), Imm8(3)); + ROR_(32, R(RSCRATCH), R(ECX)); } - break; } + RET(); - if (!store) + SetJumpTarget(insideITCM); + ADD(32, R(RCycles), R(ABI_PARAM3)); + MOV(32, R(ABI_PARAM3), R(ABI_PARAM1)); // free up ECX + AND(32, R(ABI_PARAM3), Imm32(0x7FFF & addressMask)); + if (store) { - MOV(32, R(ECX), MDisp(RSP, 8)); - ROR_(32, R(RSCRATCH), R(ECX)); + MOV(size, MComplex(RCPU, ABI_PARAM3, SCALE_1, offsetof(ARMv5, ITCM)), R(ABI_PARAM2)); + XOR(32, R(RSCRATCH), R(RSCRATCH)); + MOV(64, MScaled(ABI_PARAM3, SCALE_4, squeezePointer(cache.ARM9_ITCM)), R(RSCRATCH)); + if (size == 32) + MOV(64, MScaled(ABI_PARAM3, SCALE_4, squeezePointer(cache.ARM9_ITCM) + 8), R(RSCRATCH)); + } + else + { + MOVZX(32, size, RSCRATCH, MComplex(RCPU, ABI_PARAM3, SCALE_1, offsetof(ARMv5, ITCM))); + if (size == 32) + { + if (ABI_PARAM1 != ECX) + MOV(32, R(ECX), R(ABI_PARAM1)); + AND(32, R(ECX), Imm8(3)); + SHL(32, R(ECX), Imm8(3)); + ROR_(32, R(RSCRATCH), R(ECX)); + } } - RET(); + static_assert(RSCRATCH == EAX); + return res; } -void* Compiler::Gen_MemoryRoutine7(bool store, int size, bool mainRAMCode, u32 region) +void* Compiler::Gen_MemoryRoutine7(bool store, bool codeMainRAM, int size) { + u32 addressMask = ~(size == 32 ? 3 : (size == 16 ? 1 : 0)); AlignCode4(); void* res = GetWritableCodePtr(); - if (!store) - { - MOV(32, R(RSCRATCH), R(RSCRATCH2)); - AND(32, R(RSCRATCH), Imm8(0x3)); - SHL(32, R(RSCRATCH), Imm8(3)); - // enter the shadow realm! - MOV(32, MDisp(RSP, 8), R(RSCRATCH)); - } - - // AddCycles_CDI - MOV(32, R(RSCRATCH), R(RSCRATCH2)); + MOV(32, R(RSCRATCH), R(ABI_PARAM1)); SHR(32, R(RSCRATCH), Imm8(15)); - MOVZX(32, 8, RSCRATCH, MDisp(RSCRATCH, squeezePointer(NDS::ARM7MemTimings + 2))); - if ((region == 0x02000000 && mainRAMCode) || (region != 0x02000000 && !mainRAMCode)) + MOVZX(32, 8, ABI_PARAM4, MDisp(RSCRATCH, (size == 32 ? 2 : 0) + squeezePointer(NDS::ARM7MemTimings))); + + MOV(32, R(RSCRATCH), R(ABI_PARAM1)); + AND(32, R(RSCRATCH), Imm32(0xFF000000)); + CMP(32, R(RSCRATCH), Imm32(0x02000000)); + FixupBranch outsideMainRAM = J_CC(CC_NE); + if (codeMainRAM) { - if (!store && region != 0x02000000) - LEA(32, RSCRATCH3, MComplex(RSCRATCH, RSCRATCH3, SCALE_1, 1)); - ADD(32, R(RCycles), R(RSCRATCH3)); + LEA(32, RSCRATCH, MRegSum(ABI_PARAM4, ABI_PARAM3)); + ADD(32, R(RCycles), R(RSCRATCH)); } else { if (!store) - ADD(32, R(region == 0x02000000 ? RSCRATCH2 : RSCRATCH), Imm8(1)); - LEA(32, R10, MComplex(RSCRATCH, RSCRATCH3, SCALE_1, -3)); - CMP(32, R(RSCRATCH3), R(RSCRATCH)); - CMOVcc(32, RSCRATCH, R(RSCRATCH3), CC_G); - CMP(32, R(R10), R(RSCRATCH)); - CMOVcc(32, RSCRATCH, R(R10), CC_G); + ADD(32, R(ABI_PARAM3), Imm8(1)); + LEA(32, RSCRATCH, MComplex(ABI_PARAM4, ABI_PARAM3, SCALE_1, -3)); + CMP(32, R(ABI_PARAM4), R(ABI_PARAM3)); + CMOVcc(32, ABI_PARAM3, R(ABI_PARAM4), CC_G); + CMP(32, R(ABI_PARAM3), R(RSCRATCH)); + CMOVcc(32, RSCRATCH, R(ABI_PARAM3), CC_G); ADD(32, R(RCycles), R(RSCRATCH)); } - - if (!store) + MOV(32, R(ABI_PARAM3), R(ABI_PARAM1)); + AND(32, R(ABI_PARAM3), Imm32((MAIN_RAM_SIZE - 1) & addressMask)); + if (store) + { + MOV(size, MDisp(ABI_PARAM3, squeezePointer(NDS::MainRAM)), R(ABI_PARAM2)); XOR(32, R(RSCRATCH), R(RSCRATCH)); - AND(32, R(RSCRATCH2), Imm32(~3)); + MOV(64, MScaled(ABI_PARAM3, SCALE_4, squeezePointer(cache.MainRAM)), R(RSCRATCH)); + if (size == 32) + MOV(64, MScaled(ABI_PARAM3, SCALE_4, squeezePointer(cache.MainRAM) + 8), R(RSCRATCH)); + } + else + { + MOVZX(32, size, RSCRATCH, MDisp(ABI_PARAM3, squeezePointer(NDS::MainRAM))); + if (size == 32) + { + if (ABI_PARAM1 != ECX) + MOV(32, R(ECX), R(ABI_PARAM1)); + AND(32, R(ECX), Imm8(3)); + SHL(32, R(ECX), Imm8(3)); + ROR_(32, R(RSCRATCH), R(ECX)); + } + } + RET(); - switch (region) + SetJumpTarget(outsideMainRAM); + if (codeMainRAM) + { + if (!store) + ADD(32, R(ABI_PARAM4), Imm8(1)); + LEA(32, RSCRATCH, MComplex(ABI_PARAM4, ABI_PARAM3, SCALE_1, -3)); + CMP(32, R(ABI_PARAM4), R(ABI_PARAM3)); + CMOVcc(32, ABI_PARAM3, R(ABI_PARAM4), CC_G); + CMP(32, R(ABI_PARAM3), R(RSCRATCH)); + CMOVcc(32, RSCRATCH, R(ABI_PARAM3), CC_G); + ADD(32, R(RCycles), R(RSCRATCH)); + } + else + { + LEA(32, RSCRATCH, MComplex(ABI_PARAM4, ABI_PARAM3, SCALE_1, store ? 0 : 1)); + ADD(32, R(RCycles), R(RSCRATCH)); + } + if (store) + { + if (size > 8) + AND(32, R(ABI_PARAM1), Imm32(addressMask)); + switch (size) + { + case 32: JMP((u8*)NDS::ARM7Write32, true); break; + case 16: JMP((u8*)NDS::ARM7Write16, true); break; + case 8: JMP((u8*)NDS::ARM7Write8, true); break; + } + } + else { - case 0x00000000: - if (!store) { - CMP(32, R(RSCRATCH2), Imm32(0x4000)); - FixupBranch outsideBIOS1 = J_CC(CC_AE); - - MOV(32, R(RSCRATCH), MDisp(RCPU, offsetof(ARM, R[15]))); - CMP(32, R(RSCRATCH), Imm32(0x4000)); - FixupBranch outsideBIOS2 = J_CC(CC_AE); - MOV(32, R(RSCRATCH3), M(&NDS::ARM7BIOSProt)); - CMP(32, R(RSCRATCH2), R(RSCRATCH3)); - FixupBranch notDenied1 = J_CC(CC_AE); - CMP(32, R(RSCRATCH), R(RSCRATCH3)); - FixupBranch notDenied2 = J_CC(CC_B); - SetJumpTarget(outsideBIOS2); - MOV(32, R(RSCRATCH), Imm32(0xFFFFFFFF)); - RET(); - - SetJumpTarget(notDenied1); - SetJumpTarget(notDenied2); - MOV(32, R(RSCRATCH), MDisp(RSCRATCH2, squeezePointer(NDS::ARM7BIOS))); - MOV(32, R(ECX), MDisp(RSP, 8)); - ROR_(32, R(RSCRATCH), R(ECX)); - RET(); - - SetJumpTarget(outsideBIOS1); - } - break; - case 0x02000000: - AND(32, R(RSCRATCH2), Imm32(MAIN_RAM_SIZE - 1)); - if (!store) - MOV(32, R(RSCRATCH), MDisp(RSCRATCH2, squeezePointer(NDS::MainRAM))); - else - { - MOV(32, MDisp(RSCRATCH2, squeezePointer(NDS::MainRAM)), R(R11)); - MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.MainRAM)), Imm32(0)); - MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.MainRAM) + 8), Imm32(0)); - } - break; - case 0x03000000: - { - TEST(32, R(RSCRATCH2), Imm32(0x800000)); - FixupBranch region = J_CC(CC_NZ); - MOV(64, R(RSCRATCH), M(&NDS::SWRAM_ARM7)); - TEST(64, R(RSCRATCH), R(RSCRATCH)); - FixupBranch notMapped = J_CC(CC_Z); - AND(32, R(RSCRATCH2), M(&NDS::SWRAM_ARM7Mask)); - if (!store) - { - MOV(32, R(RSCRATCH), MRegSum(RSCRATCH, RSCRATCH2)); - MOV(32, R(ECX), MDisp(RSP, 8)); - ROR_(32, R(RSCRATCH), R(ECX)); - } - else - { - MOV(32, MRegSum(RSCRATCH, RSCRATCH2), R(R11)); - MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.SWRAM)), Imm32(0)); - MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.SWRAM) + 8), Imm32(0)); - } - RET(); - SetJumpTarget(region); - SetJumpTarget(notMapped); - AND(32, R(RSCRATCH2), Imm32(0xFFFF)); - if (!store) - MOV(32, R(RSCRATCH), MDisp(RSCRATCH2, squeezePointer(NDS::ARM7WRAM))); - else - { - MOV(32, MDisp(RSCRATCH2, squeezePointer(NDS::ARM7WRAM)), R(R11)); - MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.ARM7_WRAM)), Imm32(0)); - MOV(64, MScaled(RSCRATCH2, SCALE_4, squeezePointer(cache.ARM7_WRAM) + 8), Imm32(0)); - } - } - break; - case 0x04000000: - { - TEST(32, R(RSCRATCH2), Imm32(0x800000)); - FixupBranch region = J_CC(CC_NZ); - MOV(32, R(ABI_PARAM1), R(RSCRATCH2)); - if (!store) - { - ABI_PushRegistersAndAdjustStack({}, 8); - ABI_CallFunction(NDS::ARM7IORead32); - ABI_PopRegistersAndAdjustStack({}, 8); - - MOV(32, R(ECX), MDisp(RSP, 8)); - ROR_(32, R(RSCRATCH), R(ECX)); - RET(); - } - else - { - MOV(32, R(ABI_PARAM2), R(R11)); - JMP((u8*)NDS::ARM7IOWrite32, true); - } - SetJumpTarget(region); - - if (!store) - { - ABI_PushRegistersAndAdjustStack({RSCRATCH2}, 8); - MOV(32, R(ABI_PARAM1), R(RSCRATCH2)); - ABI_CallFunction(Wifi::Read); - ABI_PopRegistersAndAdjustStack({RSCRATCH2}, 8); - - ADD(32, R(RSCRATCH2), Imm8(2)); - ABI_PushRegistersAndAdjustStack({EAX}, 8); - MOV(32, R(ABI_PARAM1), R(RSCRATCH2)); - ABI_CallFunction(Wifi::Read); - MOV(32, R(RSCRATCH2), R(EAX)); - SHL(32, R(RSCRATCH2), Imm8(16)); - ABI_PopRegistersAndAdjustStack({EAX}, 8); - OR(32, R(EAX), R(RSCRATCH2)); - } - else - { - ABI_PushRegistersAndAdjustStack({RSCRATCH2, R11}, 8); - MOV(32, R(ABI_PARAM1), R(RSCRATCH2)); - MOVZX(32, 16, ABI_PARAM2, R(R11)); - ABI_CallFunction(Wifi::Write); - ABI_PopRegistersAndAdjustStack({RSCRATCH2, R11}, 8); - SHR(32, R(R11), Imm8(16)); - ADD(32, R(RSCRATCH2), Imm8(2)); - ABI_PushRegistersAndAdjustStack({RSCRATCH2, R11}, 8); - MOV(32, R(ABI_PARAM1), R(RSCRATCH2)); - MOVZX(32, 16, ABI_PARAM2, R(R11)); - ABI_CallFunction(Wifi::Write); - ABI_PopRegistersAndAdjustStack({RSCRATCH2, R11}, 8); - } - } - break; - case 0x06000000: - MOV(32, R(ABI_PARAM1), R(RSCRATCH2)); - if (!store) - { - ABI_PushRegistersAndAdjustStack({}, 8); - ABI_CallFunction(GPU::ReadVRAM_ARM7); - ABI_PopRegistersAndAdjustStack({}, 8); - } - else - { - AND(32, R(ABI_PARAM1), Imm32(0x40000 - 1)); - MOV(64, MScaled(ABI_PARAM1, SCALE_4, squeezePointer(cache.ARM7_WVRAM)), Imm32(0)); - MOV(64, MScaled(ABI_PARAM1, SCALE_4, squeezePointer(cache.ARM7_WVRAM) + 8), Imm32(0)); - MOV(32, R(ABI_PARAM2), R(R11)); - JMP((u8*)GPU::WriteVRAM_ARM7, true); - } - break; - case 0x08000000: - case 0x09000000: - case 0x0A000000: - if (!store) - MOV(32, R(RSCRATCH), Imm32(0xFFFFFFFF)); - break; - /*default: - ABI_PushRegistersAndAdjustStack({}, 8, 0); - MOV(32, R(ABI_PARAM1), R(RSCRATCH2)); + if (size == 32) + { + ABI_PushRegistersAndAdjustStack({ABI_PARAM1}, 8); + AND(32, R(ABI_PARAM1), Imm32(addressMask)); ABI_CallFunction(NDS::ARM7Read32); - ABI_PopRegistersAndAdjustStack({}, 8, 0); - break;*/ + ABI_PopRegistersAndAdjustStack({ECX}, 8); + AND(32, R(ECX), Imm8(3)); + SHL(32, R(ECX), Imm8(3)); + ROR_(32, R(RSCRATCH), R(ECX)); + RET(); + } + else if (size == 16) + { + AND(32, R(ABI_PARAM1), Imm32(addressMask)); + JMP((u8*)NDS::ARM7Read16, true); + } + else + JMP((u8*)NDS::ARM7Read8, true); } + return res; +} + +void Compiler::Comp_MemAccess(Gen::OpArg rd, bool signExtend, bool store, int size) +{ + if (store) + MOV(32, R(ABI_PARAM2), rd); + u32 cycles = Num + ? NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2] + : (R15 & 0x2 ? 0 : CurInstr.CodeCycles); + MOV(32, R(ABI_PARAM3), Imm32(cycles)); + CALL(Num == 0 + ? MemoryFuncs9[size >> 4][store] + : MemoryFuncs7[size >> 4][store][CodeRegion == 0x02]); + if (!store) { - MOV(32, R(ECX), MDisp(RSP, 8)); - ROR_(32, R(RSCRATCH), R(ECX)); + if (signExtend) + MOVSX(32, size, rd.GetSimpleReg(), R(RSCRATCH)); + else + MOVZX(32, size, rd.GetSimpleReg(), R(RSCRATCH)); } - - RET(); - - return res; } OpArg Compiler::A_Comp_GetMemWBOffset() { - if (!(CurrentInstr.Instr & (1 << 25))) - return Imm32(CurrentInstr.Instr & 0xFFF); + if (!(CurInstr.Instr & (1 << 25))) + { + u32 imm = CurInstr.Instr & 0xFFF; + return Imm32(imm); + } else { - int op = (CurrentInstr.Instr >> 5) & 0x3; - int amount = (CurrentInstr.Instr >> 7) & 0x1F; - OpArg rm = MapReg(CurrentInstr.A_Reg(0)); + int op = (CurInstr.Instr >> 5) & 0x3; + int amount = (CurInstr.Instr >> 7) & 0x1F; + OpArg rm = MapReg(CurInstr.A_Reg(0)); bool carryUsed; + return Comp_RegShiftImm(op, amount, rm, false, carryUsed); } } void Compiler::A_Comp_MemWB() -{ - OpArg rn = MapReg(CurrentInstr.A_Reg(16)); - OpArg rd = MapReg(CurrentInstr.A_Reg(12)); - bool load = CurrentInstr.Instr & (1 << 20); +{ + OpArg rn = MapReg(CurInstr.A_Reg(16)); + OpArg rd = MapReg(CurInstr.A_Reg(12)); + bool load = CurInstr.Instr & (1 << 20); + bool byte = CurInstr.Instr & (1 << 22); + int size = byte ? 8 : 32; - MOV(32, R(RSCRATCH2), rn); - if (CurrentInstr.Instr & (1 << 24)) + if (CurInstr.Instr & (1 << 24)) { OpArg offset = A_Comp_GetMemWBOffset(); - if (CurrentInstr.Instr & (1 << 23)) - ADD(32, R(RSCRATCH2), offset); + if (CurInstr.Instr & (1 << 23)) + MOV_sum(32, ABI_PARAM1, rn, offset); else - SUB(32, R(RSCRATCH2), offset); + { + MOV(32, R(ABI_PARAM1), rn); + SUB(32, R(ABI_PARAM1), offset); + } - if (CurrentInstr.Instr & (1 << 21)) - MOV(32, rn, R(RSCRATCH2)); + if (CurInstr.Instr & (1 << 21)) + MOV(32, rn, R(ABI_PARAM1)); } - - u32 cycles = Num ? NDS::ARM7MemTimings[CurrentInstr.CodeCycles][2] : CurrentInstr.CodeCycles; - MOV(32, R(RSCRATCH3), Imm32(cycles)); - MOV(32, R(RSCRATCH), R(RSCRATCH2)); - SHR(32, R(RSCRATCH), Imm8(24)); - AND(32, R(RSCRATCH), Imm8(0xF)); - void** funcArray; - if (load) - funcArray = Num ? ReadMemFuncs7[CodeRegion == 0x02] : ReadMemFuncs9; else + MOV(32, R(ABI_PARAM1), rn); + + if (!(CurInstr.Instr & (1 << 24))) + { + OpArg offset = A_Comp_GetMemWBOffset(); + + if (CurInstr.Instr & (1 << 23)) + ADD(32, rn, offset); + else + SUB(32, rn, offset); + } + + Comp_MemAccess(rd, false, !load, byte ? 8 : 32); + if (load && CurInstr.A_Reg(12) == 15) + { + if (byte) + printf("!!! LDRB PC %08X\n", R15); + else + { + if (Num == 1) + AND(32, rd, Imm8(0xFE)); // immediate is sign extended + Comp_JumpTo(rd.GetSimpleReg()); + } + } +} + +void Compiler::A_Comp_MemHalf() +{ + OpArg rn = MapReg(CurInstr.A_Reg(16)); + OpArg rd = MapReg(CurInstr.A_Reg(12)); + + OpArg offset = CurInstr.Instr & (1 << 22) + ? Imm32(CurInstr.Instr & 0xF | ((CurInstr.Instr >> 4) & 0xF0)) + : MapReg(CurInstr.A_Reg(0)); + + if (CurInstr.Instr & (1 << 24)) { - funcArray = Num ? WriteMemFuncs7[CodeRegion == 0x02] : WriteMemFuncs9; - MOV(32, R(R11), rd); + if (CurInstr.Instr & (1 << 23)) + MOV_sum(32, ABI_PARAM1, rn, offset); + else + { + MOV(32, R(ABI_PARAM1), rn); + SUB(32, R(ABI_PARAM1), offset); + } + + if (CurInstr.Instr & (1 << 21)) + MOV(32, rn, R(ABI_PARAM1)); } - CALLptr(MScaled(RSCRATCH, SCALE_8, squeezePointer(funcArray))); + else + MOV(32, R(ABI_PARAM1), rn); - if (load) - MOV(32, R(RSCRATCH2), R(RSCRATCH)); + int op = (CurInstr.Instr >> 5) & 0x3; + bool load = CurInstr.Instr & (1 << 20); - if (!(CurrentInstr.Instr & (1 << 24))) + bool signExtend = false; + int size; + if (!load && op == 1) + size = 16; + else if (load) { - OpArg offset = A_Comp_GetMemWBOffset(); + size = op == 2 ? 8 : 16; + signExtend = op > 1; + } - if (CurrentInstr.Instr & (1 << 23)) + if (!(CurInstr.Instr & (1 << 24))) + { + if (CurInstr.Instr & (1 << 23)) ADD(32, rn, offset); else SUB(32, rn, offset); } - if (load) - MOV(32, rd, R(RSCRATCH2)); + Comp_MemAccess(rd, signExtend, !load, size); + + if (load && CurInstr.A_Reg(12) == 15) + printf("!!! MemHalf op PC %08X\n", R15);; } void Compiler::T_Comp_MemReg() { - OpArg rd = MapReg(CurrentInstr.T_Reg(0)); - OpArg rb = MapReg(CurrentInstr.T_Reg(3)); - OpArg ro = MapReg(CurrentInstr.T_Reg(6)); + OpArg rd = MapReg(CurInstr.T_Reg(0)); + OpArg rb = MapReg(CurInstr.T_Reg(3)); + OpArg ro = MapReg(CurInstr.T_Reg(6)); - int op = (CurrentInstr.Instr >> 10) & 0x3; + int op = (CurInstr.Instr >> 10) & 0x3; bool load = op & 0x2; - - MOV(32, R(RSCRATCH2), rb); - ADD(32, R(RSCRATCH2), ro); - - u32 cycles = Num ? NDS::ARM7MemTimings[CurrentInstr.CodeCycles][0] : (R15 & 0x2 ? 0 : CurrentInstr.CodeCycles); - MOV(32, R(RSCRATCH3), Imm32(cycles)); - MOV(32, R(RSCRATCH), R(RSCRATCH2)); - SHR(32, R(RSCRATCH), Imm8(24)); - AND(32, R(RSCRATCH), Imm8(0xF)); - void** funcArray; - if (load) - funcArray = Num ? ReadMemFuncs7[CodeRegion == 0x02] : ReadMemFuncs9; - else - { - funcArray = Num ? WriteMemFuncs7[CodeRegion == 0x02] : WriteMemFuncs9; - MOV(32, R(R11), rd); - } - CALLptr(MScaled(RSCRATCH, SCALE_8, squeezePointer(funcArray))); + bool byte = op & 0x1; + + MOV_sum(32, ABI_PARAM1, rb, ro); - if (load) - MOV(32, rd, R(RSCRATCH)); + Comp_MemAccess(rd, false, !load, byte ? 8 : 32); } void Compiler::T_Comp_MemImm() { - // TODO: aufräumen!!! - OpArg rd = MapReg(CurrentInstr.T_Reg(0)); - OpArg rb = MapReg(CurrentInstr.T_Reg(3)); - - int op = (CurrentInstr.Instr >> 11) & 0x3; - u32 offset = ((CurrentInstr.Instr >> 6) & 0x1F) * 4; + OpArg rd = MapReg(CurInstr.T_Reg(0)); + OpArg rb = MapReg(CurInstr.T_Reg(3)); + + int op = (CurInstr.Instr >> 11) & 0x3; bool load = op & 0x1; + bool byte = op & 0x2; + u32 offset = ((CurInstr.Instr >> 6) & 0x1F) * (byte ? 1 : 4); - LEA(32, RSCRATCH2, MDisp(rb.GetSimpleReg(), offset)); - u32 cycles = Num ? NDS::ARM7MemTimings[CurrentInstr.CodeCycles][0] : (R15 & 0x2 ? 0 : CurrentInstr.CodeCycles); - MOV(32, R(RSCRATCH3), Imm32(cycles)); - MOV(32, R(RSCRATCH), R(RSCRATCH2)); - SHR(32, R(RSCRATCH), Imm8(24)); - AND(32, R(RSCRATCH), Imm8(0xF)); - void** funcArray; - if (load) - funcArray = Num ? ReadMemFuncs7[CodeRegion == 0x02] : ReadMemFuncs9; - else - { - funcArray = Num ? WriteMemFuncs7[CodeRegion == 0x02] : WriteMemFuncs9; - MOV(32, R(R11), rd); - } - CALLptr(MScaled(RSCRATCH, SCALE_8, squeezePointer(funcArray))); + LEA(32, ABI_PARAM1, MDisp(rb.GetSimpleReg(), offset)); + + Comp_MemAccess(rd, false, !load, byte ? 8 : 32); +} + +void Compiler::T_Comp_MemRegHalf() +{ + OpArg rd = MapReg(CurInstr.T_Reg(0)); + OpArg rb = MapReg(CurInstr.T_Reg(3)); + OpArg ro = MapReg(CurInstr.T_Reg(6)); + + int op = (CurInstr.Instr >> 10) & 0x3; + bool load = op != 0; + int size = op != 1 ? 16 : 8; + bool signExtend = op & 1; + + MOV_sum(32, ABI_PARAM1, rb, ro); + + Comp_MemAccess(rd, signExtend, !load, size); +} + +void Compiler::T_Comp_MemImmHalf() +{ + OpArg rd = MapReg(CurInstr.T_Reg(0)); + OpArg rb = MapReg(CurInstr.T_Reg(3)); + + u32 offset = (CurInstr.Instr >> 5) & 0x3E; + bool load = CurInstr.Instr & (1 << 11); + + LEA(32, ABI_PARAM1, MDisp(rb.GetSimpleReg(), offset)); - if (load) - MOV(32, rd, R(RSCRATCH)); + Comp_MemAccess(rd, false, !load, 16); } } \ No newline at end of file diff --git a/src/ARM_InstrInfo.cpp b/src/ARM_InstrInfo.cpp index 41c46e1..32a9645 100644 --- a/src/ARM_InstrInfo.cpp +++ b/src/ARM_InstrInfo.cpp @@ -317,7 +317,7 @@ Info Decode(bool thumb, u32 num, u32 instr) else { u32 data = ARMInstrTable[((instr >> 4) & 0xF) | ((instr >> 16) & 0xFF0)]; - if ((instr & 0xFE000000) == 0xFA000000) + if (num == 0 && (instr & 0xFE000000) == 0xFA000000) data = A_BLX_IMM; if (data & A_ARM9Only && num != 0) diff --git a/src/NDS.cpp b/src/NDS.cpp index 2a7edfd..4073536 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -566,6 +566,8 @@ void Reset() KeyCnt = 0; RCnt = 0; + ARMJIT::ResetBlocks(); + NDSCart::Reset(); GBACart::Reset(); GPU::Reset(); -- cgit v1.2.3 From 27cbc821b139b74142630c57f7da11478a052282 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Wed, 10 Jul 2019 00:57:59 +0200 Subject: jit: thumb block transfer working also pc and sp relative loads and some refactoring --- src/ARMJIT_RegCache.h | 136 ---------- src/ARMJIT_RegisterCache.h | 136 ++++++++++ src/ARMJIT_x64/ARMJIT_Compiler.cpp | 82 ++++-- src/ARMJIT_x64/ARMJIT_Compiler.h | 19 +- src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 515 +++++++++++++++++++++++++++++++----- src/ARM_InstrInfo.cpp | 46 ++-- 6 files changed, 682 insertions(+), 252 deletions(-) delete mode 100644 src/ARMJIT_RegCache.h create mode 100644 src/ARMJIT_RegisterCache.h (limited to 'src') diff --git a/src/ARMJIT_RegCache.h b/src/ARMJIT_RegCache.h deleted file mode 100644 index 556d27b..0000000 --- a/src/ARMJIT_RegCache.h +++ /dev/null @@ -1,136 +0,0 @@ -#ifndef ARMJIT_REGCACHE_H -#define ARMJIT_REGCACHE_H - -#include "ARMJIT.h" - -// TODO: replace this in the future -#include "dolphin/BitSet.h" - -#include - -namespace ARMJIT -{ - -template -class RegCache -{ -public: - RegCache() - {} - - RegCache(T* compiler, FetchedInstr instrs[], int instrsCount) - : Compiler(compiler), Instrs(instrs), InstrsCount(instrsCount) - { - for (int i = 0; i < 16; i++) - Mapping[i] = (Reg)-1; - } - - void UnloadRegister(int reg) - { - assert(Mapping[reg] != -1); - - if (DirtyRegs & (1 << reg)) - Compiler->SaveReg(reg, Mapping[reg]); - - DirtyRegs &= ~(1 << reg); - LoadedRegs &= ~(1 << reg); - NativeRegsUsed &= ~(1 << (int)Mapping[reg]); - Mapping[reg] = (Reg)-1; - } - - void LoadRegister(int reg) - { - assert(Mapping[reg] == -1); - for (int i = 0; i < NativeRegsAvailable; i++) - { - Reg nativeReg = NativeRegAllocOrder[i]; - if (!(NativeRegsUsed & (1 << nativeReg))) - { - Mapping[reg] = nativeReg; - NativeRegsUsed |= 1 << (int)nativeReg; - LoadedRegs |= 1 << reg; - - Compiler->LoadReg(reg, nativeReg); - - return; - } - } - - assert("Welp!"); - } - - void Flush() - { - BitSet16 loadedSet(LoadedRegs); - for (int reg : loadedSet) - UnloadRegister(reg); - } - - void Prepare(int i) - { - u16 futureNeeded = 0; - int ranking[16]; - for (int j = 0; j < 16; j++) - ranking[j] = 0; - for (int j = i; j < InstrsCount; j++) - { - BitSet16 regsNeeded((Instrs[j].Info.SrcRegs & ~(1 << 15)) | Instrs[j].Info.DstRegs); - futureNeeded |= regsNeeded.m_val; - for (int reg : regsNeeded) - ranking[reg]++; - } - - // we'll unload all registers which are never used again - BitSet16 neverNeededAgain(LoadedRegs & ~futureNeeded); - for (int reg : neverNeededAgain) - UnloadRegister(reg); - - FetchedInstr Instr = Instrs[i]; - u16 necessaryRegs = (Instr.Info.SrcRegs & ~(1 << 15)) | Instr.Info.DstRegs; - BitSet16 needToBeLoaded(necessaryRegs & ~LoadedRegs); - if (needToBeLoaded != BitSet16(0)) - { - int neededCount = needToBeLoaded.Count(); - BitSet16 loadedSet(LoadedRegs); - while (loadedSet.Count() + neededCount > NativeRegsAvailable) - { - int leastReg = -1; - int rank = 1000; - for (int reg : loadedSet) - { - if (!((1 << reg) & necessaryRegs) && ranking[reg] < rank) - { - leastReg = reg; - rank = ranking[reg]; - } - } - - assert(leastReg != -1); - UnloadRegister(leastReg); - - loadedSet.m_val = LoadedRegs; - } - - for (int reg : needToBeLoaded) - LoadRegister(reg); - } - DirtyRegs |= Instr.Info.DstRegs & ~(1 << 15); - } - - static const Reg NativeRegAllocOrder[]; - static const int NativeRegsAvailable; - - Reg Mapping[16]; - u32 NativeRegsUsed = 0; - u16 LoadedRegs = 0; - u16 DirtyRegs = 0; - - T* Compiler; - - FetchedInstr* Instrs; - int InstrsCount; -}; - -} - -#endif \ No newline at end of file diff --git a/src/ARMJIT_RegisterCache.h b/src/ARMJIT_RegisterCache.h new file mode 100644 index 0000000..04c1eda --- /dev/null +++ b/src/ARMJIT_RegisterCache.h @@ -0,0 +1,136 @@ +#ifndef ARMJIT_REGCACHE_H +#define ARMJIT_REGCACHE_H + +#include "ARMJIT.h" + +// TODO: replace this in the future +#include "dolphin/BitSet.h" + +#include + +namespace ARMJIT +{ + +template +class RegisterCache +{ +public: + RegisterCache() + {} + + RegisterCache(T* compiler, FetchedInstr instrs[], int instrsCount) + : Compiler(compiler), Instrs(instrs), InstrsCount(instrsCount) + { + for (int i = 0; i < 16; i++) + Mapping[i] = (Reg)-1; + } + + void UnloadRegister(int reg) + { + assert(Mapping[reg] != -1); + + if (DirtyRegs & (1 << reg)) + Compiler->SaveReg(reg, Mapping[reg]); + + DirtyRegs &= ~(1 << reg); + LoadedRegs &= ~(1 << reg); + NativeRegsUsed &= ~(1 << (int)Mapping[reg]); + Mapping[reg] = (Reg)-1; + } + + void LoadRegister(int reg) + { + assert(Mapping[reg] == -1); + for (int i = 0; i < NativeRegsAvailable; i++) + { + Reg nativeReg = NativeRegAllocOrder[i]; + if (!(NativeRegsUsed & (1 << nativeReg))) + { + Mapping[reg] = nativeReg; + NativeRegsUsed |= 1 << (int)nativeReg; + LoadedRegs |= 1 << reg; + + Compiler->LoadReg(reg, nativeReg); + + return; + } + } + + assert("Welp!"); + } + + void Flush() + { + BitSet16 loadedSet(LoadedRegs); + for (int reg : loadedSet) + UnloadRegister(reg); + } + + void Prepare(int i) + { + u16 futureNeeded = 0; + int ranking[16]; + for (int j = 0; j < 16; j++) + ranking[j] = 0; + for (int j = i; j < InstrsCount; j++) + { + BitSet16 regsNeeded((Instrs[j].Info.SrcRegs & ~(1 << 15)) | Instrs[j].Info.DstRegs); + futureNeeded |= regsNeeded.m_val; + for (int reg : regsNeeded) + ranking[reg]++; + } + + // we'll unload all registers which are never used again + BitSet16 neverNeededAgain(LoadedRegs & ~futureNeeded); + for (int reg : neverNeededAgain) + UnloadRegister(reg); + + FetchedInstr Instr = Instrs[i]; + u16 necessaryRegs = (Instr.Info.SrcRegs & ~(1 << 15)) | Instr.Info.DstRegs; + BitSet16 needToBeLoaded(necessaryRegs & ~LoadedRegs); + if (needToBeLoaded != BitSet16(0)) + { + int neededCount = needToBeLoaded.Count(); + BitSet16 loadedSet(LoadedRegs); + while (loadedSet.Count() + neededCount > NativeRegsAvailable) + { + int leastReg = -1; + int rank = 1000; + for (int reg : loadedSet) + { + if (!((1 << reg) & necessaryRegs) && ranking[reg] < rank) + { + leastReg = reg; + rank = ranking[reg]; + } + } + + assert(leastReg != -1); + UnloadRegister(leastReg); + + loadedSet.m_val = LoadedRegs; + } + + for (int reg : needToBeLoaded) + LoadRegister(reg); + } + DirtyRegs |= Instr.Info.DstRegs & ~(1 << 15); + } + + static const Reg NativeRegAllocOrder[]; + static const int NativeRegsAvailable; + + Reg Mapping[16]; + u32 NativeRegsUsed = 0; + u16 LoadedRegs = 0; + u16 DirtyRegs = 0; + + T* Compiler; + + FetchedInstr* Instrs; + int InstrsCount; +}; + +} + +#endif \ No newline at end of file diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index b7358a2..4fe0c70 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -9,20 +9,20 @@ using namespace Gen; namespace ARMJIT { template <> -const X64Reg RegCache::NativeRegAllocOrder[] = +const X64Reg RegisterCache::NativeRegAllocOrder[] = { #ifdef _WIN32 - RBX, RSI, RDI, R12, R13 + RBX, RSI, RDI, R12, R13, R14 #else - RBX, R12, R13 + RBX, R12, R13, R14 // this is sad #endif }; template <> -const int RegCache::NativeRegsAvailable = +const int RegisterCache::NativeRegsAvailable = #ifdef _WIN32 - 5 + 6 #else - 3 + 4 #endif ; @@ -39,10 +39,47 @@ Compiler::Compiler() MemoryFuncs7[i][j][1] = Gen_MemoryRoutine7(j, true, 8 << i); } } + for (int i = 0; i < 2; i++) + for (int j = 0; j < 2; j++) + { + MemoryFuncsSeq9[i][j] = Gen_MemoryRoutineSeq9(i, j); + MemoryFuncsSeq7[i][j][0] = Gen_MemoryRoutineSeq7(i, j, false); + MemoryFuncsSeq7[i][j][1] = Gen_MemoryRoutineSeq7(i, j, true); + } ResetStart = GetWritableCodePtr(); } +void* Compiler::Gen_ChangeCPSRRoutine() +{ + void* res = (void*)GetWritableCodePtr(); + + MOV(32, R(RSCRATCH), R(RCPSR)); + AND(32, R(RSCRATCH), Imm8(0x1F)); + CMP(32, R(RSCRATCH), Imm8(0x11)); + FixupBranch fiq = J_CC(CC_E); + CMP(32, R(RSCRATCH), Imm8(0x12)); + FixupBranch irq = J_CC(CC_E); + CMP(32, R(RSCRATCH), Imm8(0x13)); + FixupBranch svc = J_CC(CC_E); + CMP(32, R(RSCRATCH), Imm8(0x17)); + FixupBranch abt = J_CC(CC_E); + CMP(32, R(RSCRATCH), Imm8(0x1B)); + FixupBranch und = J_CC(CC_E); + + SetJumpTarget(fiq); + + SetJumpTarget(irq); + + SetJumpTarget(svc); + + SetJumpTarget(abt); + + SetJumpTarget(und); + + return res; +} + DataRegion Compiler::ClassifyAddress(u32 addr) { if (Num == 0 && addr >= ((ARMv5*)CurCPU)->DTCMBase && addr < ((ARMv5*)CurCPU)->DTCMBase) @@ -106,12 +143,11 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs ABI_PushRegistersAndAdjustStack({ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS}, 8, 16); MOV(64, R(RCPU), ImmPtr(cpu)); - XOR(32, R(RCycles), R(RCycles)); LoadCPSR(); // TODO: this is ugly as a whole, do better - RegCache = ARMJIT::RegCache(this, instrs, instrsCount); + RegCache = RegisterCache(this, instrs, instrsCount); for (int i = 0; i < instrsCount; i++) { @@ -242,7 +278,7 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs RegCache.Flush(); SaveCPSR(); - LEA(32, RAX, MDisp(RCycles, ConstantCycles)); + MOV(32, R(RAX), Imm32(ConstantCycles)); ABI_PopRegistersAndAdjustStack({ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS}, 8, 16); RET(); @@ -306,18 +342,20 @@ CompileFunc Compiler::GetCompFunc(int kind) NULL, NULL, NULL, NULL, NULL, // STR A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, + //NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, // STRB + //NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, // LDR + //NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, // LDRB + //NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, // STRH A_Comp_MemHalf, A_Comp_MemHalf, A_Comp_MemHalf, A_Comp_MemHalf, - // LDRD - NULL, NULL, NULL, NULL, - // STRD - NULL, NULL, NULL, NULL, + // LDRD, STRD never used by anything so they stay interpreted (by anything I mean the 5 games I checked) + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, // LDRH A_Comp_MemHalf, A_Comp_MemHalf, A_Comp_MemHalf, A_Comp_MemHalf, // LDRSB @@ -360,10 +398,14 @@ CompileFunc Compiler::GetCompFunc(int kind) T_Comp_MemImm, T_Comp_MemImm, T_Comp_MemImm, T_Comp_MemImm, // LDR/STR half imm offset T_Comp_MemImmHalf, T_Comp_MemImmHalf, - // branch, etc. - NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL + // LDR/STR sp rel + NULL, NULL, + // PUSH/POP + NULL, NULL, + // LDMIA, STMIA + NULL, NULL, + NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL }; return Thumb ? T_Comp[kind] : A_Comp[kind]; @@ -376,7 +418,7 @@ void Compiler::Comp_AddCycles_C() : ((R15 & 0x2) ? 0 : CurInstr.CodeCycles); if (CurInstr.Cond() < 0xE) - ADD(32, R(RCycles), Imm8(cycles)); + ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm8(cycles)); else ConstantCycles += cycles; } @@ -388,13 +430,15 @@ void Compiler::Comp_AddCycles_CI(u32 i) : ((R15 & 0x2) ? 0 : CurInstr.CodeCycles)) + i; if (CurInstr.Cond() < 0xE) - ADD(32, R(RCycles), Imm8(cycles)); + ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm8(cycles)); else ConstantCycles += cycles; } void Compiler::Comp_JumpTo(Gen::X64Reg addr, bool restoreCPSR) { + // potentieller Bug: falls ein Register das noch gecacht ist, beim Modeswitch gespeichert + // wird der alte Wert gespeichert SaveCPSR(); MOV(64, R(ABI_PARAM1), R(RCPU)); diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index 9395a29..a751737 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -4,7 +4,7 @@ #include "../dolphin/x64Emitter.h" #include "../ARMJIT.h" -#include "../ARMJIT_RegCache.h" +#include "../ARMJIT_RegisterCache.h" #include @@ -12,7 +12,6 @@ namespace ARMJIT { const Gen::X64Reg RCPU = Gen::RBP; -const Gen::X64Reg RCycles = Gen::R14; const Gen::X64Reg RCPSR = Gen::R15; const Gen::X64Reg RSCRATCH = Gen::EAX; @@ -72,6 +71,7 @@ private: void A_Comp_MemWB(); void A_Comp_MemHalf(); + void A_Comp_LDM_STM(); void T_Comp_ShiftImm(); void T_Comp_AddSub_(); @@ -86,8 +86,13 @@ private: void T_Comp_MemImm(); void T_Comp_MemRegHalf(); void T_Comp_MemImmHalf(); + void T_Comp_LoadPCRel(); + void T_Comp_MemSPRel(); + void T_Comp_PUSH_POP(); + void T_Comp_LDMIA_STMIA(); void Comp_MemAccess(Gen::OpArg rd, bool signExtend, bool store, int size); + s32 Comp_MemAccessBlock(Gen::OpArg rb, BitSet16 regs, bool store, bool preinc, bool decrement, bool usermode); void Comp_ArithTriOp(void (Compiler::*op)(int, const Gen::OpArg&, const Gen::OpArg&), Gen::OpArg rd, Gen::OpArg rn, Gen::OpArg op2, bool carryUsed, int opFlags); @@ -100,6 +105,11 @@ private: void* Gen_MemoryRoutine9(bool store, int size); void* Gen_MemoryRoutine7(bool store, bool codeMainRAM, int size); + void* Gen_MemoryRoutineSeq9(bool store, bool preinc); + void* Gen_MemoryRoutineSeq7(bool store, bool preinc, bool codeMainRAM); + + void* Gen_ChangeCPSRRoutine(); + Gen::OpArg Comp_RegShiftImm(int op, int amount, Gen::OpArg rm, bool S, bool& carryUsed); Gen::OpArg Comp_RegShiftReg(int op, Gen::OpArg rs, Gen::OpArg rm, bool S, bool& carryUsed); @@ -122,11 +132,14 @@ private: void* MemoryFuncs9[3][2]; void* MemoryFuncs7[3][2][2]; + void* MemoryFuncsSeq9[2][2]; + void* MemoryFuncsSeq7[2][2][2]; + bool CPSRDirty = false; FetchedInstr CurInstr; - RegCache RegCache; + RegisterCache RegCache; bool Thumb; u32 Num; diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index 69746e2..20e1893 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -3,16 +3,6 @@ #include "../GPU.h" #include "../Wifi.h" -namespace NDS -{ -extern u8* SWRAM_ARM9; -extern u32 SWRAM_ARM9Mask; -extern u8* SWRAM_ARM7; -extern u32 SWRAM_ARM7Mask; -extern u8 ARM7WRAM[]; -extern u16 ARM7BIOSProt; -} - using namespace Gen; namespace ARMJIT @@ -41,6 +31,49 @@ int squeezePointer(T* ptr) store value - ABI_PARAM2 (a.k.a. RDX = RSCRATCH2 on Windows) code cycles - ABI_PARAM3 */ + +#define CALC_CYCLES_9(numC, numD, scratch) \ + LEA(32, scratch, MComplex(numD, numC, SCALE_1, -6)); \ + CMP(32, R(numC), R(numD)); \ + CMOVcc(32, numD, R(numC), CC_G); \ + CMP(32, R(numD), R(scratch)); \ + CMOVcc(32, scratch, R(numD), CC_G); \ + ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(scratch)); +#define CALC_CYCLES_7_DATA_MAIN_RAM(numC, numD, scratch) \ + if (codeMainRAM) \ + { \ + LEA(32, scratch, MRegSum(numD, numC)); \ + ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(scratch)); \ + } \ + else \ + { \ + if (!store) \ + ADD(32, R(numC), Imm8(1)); \ + LEA(32, scratch, MComplex(numD, numC, SCALE_1, -3)); \ + CMP(32, R(numD), R(numC)); \ + CMOVcc(32, numC, R(numD), CC_G); \ + CMP(32, R(numC), R(scratch)); \ + CMOVcc(32, scratch, R(numC), CC_G); \ + ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(scratch)); \ + } +#define CALC_CYCLES_7_DATA_NON_MAIN_RAM(numC, numD, scratch) \ + if (codeMainRAM) \ + { \ + if (!store) \ + ADD(32, R(numD), Imm8(1)); \ + LEA(32, scratch, MComplex(numD, numC, SCALE_1, -3)); \ + CMP(32, R(numD), R(numC)); \ + CMOVcc(32, numC, R(numD), CC_G); \ + CMP(32, R(numC), R(scratch)); \ + CMOVcc(32, scratch, R(numC), CC_G); \ + ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(scratch)); \ + } \ + else \ + { \ + LEA(32, scratch, MComplex(numD, numC, SCALE_1, store ? 0 : 1)); \ + ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(scratch)); \ + } + void* Compiler::Gen_MemoryRoutine9(bool store, int size) { u32 addressMask = ~(size == 32 ? 3 : (size == 16 ? 1 : 0)); @@ -56,15 +89,10 @@ void* Compiler::Gen_MemoryRoutine9(bool store, int size) FixupBranch insideITCM = J_CC(CC_B); // cycle counting! - MOV(32, R(RSCRATCH), R(ABI_PARAM1)); - SHR(32, R(RSCRATCH), Imm8(12)); - MOVZX(32, 8, RSCRATCH, MComplex(RCPU, RSCRATCH, SCALE_1, offsetof(ARMv5, MemTimings) + (size == 32 ? 2 : 0))); - LEA(32, ABI_PARAM4, MComplex(RSCRATCH, ABI_PARAM3, SCALE_1, -6)); - CMP(32, R(ABI_PARAM3), R(RSCRATCH)); - CMOVcc(32, RSCRATCH, R(ABI_PARAM3), CC_G); - CMP(32, R(ABI_PARAM4), R(RSCRATCH)); - CMOVcc(32, RSCRATCH, R(ABI_PARAM4), CC_G); - ADD(32, R(RCycles), R(RSCRATCH)); + MOV(32, R(ABI_PARAM4), R(ABI_PARAM1)); + SHR(32, R(ABI_PARAM4), Imm8(12)); + MOVZX(32, 8, ABI_PARAM4, MComplex(RCPU, ABI_PARAM4, SCALE_4, offsetof(ARMv5, MemTimings) + (size == 32 ? 2 : 1))); + CALC_CYCLES_9(ABI_PARAM3, ABI_PARAM4, RSCRATCH) if (store) { @@ -101,7 +129,7 @@ void* Compiler::Gen_MemoryRoutine9(bool store, int size) } SetJumpTarget(insideDTCM); - ADD(32, R(RCycles), R(ABI_PARAM3)); + ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(ABI_PARAM3)); AND(32, R(RSCRATCH), Imm32(0x3FFF & addressMask)); if (store) MOV(size, MComplex(RCPU, RSCRATCH, SCALE_1, offsetof(ARMv5, DTCM)), R(ABI_PARAM2)); @@ -120,7 +148,7 @@ void* Compiler::Gen_MemoryRoutine9(bool store, int size) RET(); SetJumpTarget(insideITCM); - ADD(32, R(RCycles), R(ABI_PARAM3)); + ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(ABI_PARAM3)); MOV(32, R(ABI_PARAM3), R(ABI_PARAM1)); // free up ECX AND(32, R(ABI_PARAM3), Imm32(0x7FFF & addressMask)); if (store) @@ -158,28 +186,13 @@ void* Compiler::Gen_MemoryRoutine7(bool store, bool codeMainRAM, int size) MOV(32, R(RSCRATCH), R(ABI_PARAM1)); SHR(32, R(RSCRATCH), Imm8(15)); - MOVZX(32, 8, ABI_PARAM4, MDisp(RSCRATCH, (size == 32 ? 2 : 0) + squeezePointer(NDS::ARM7MemTimings))); + MOVZX(32, 8, ABI_PARAM4, MScaled(RSCRATCH, SCALE_4, (size == 32 ? 2 : 0) + squeezePointer(NDS::ARM7MemTimings))); MOV(32, R(RSCRATCH), R(ABI_PARAM1)); AND(32, R(RSCRATCH), Imm32(0xFF000000)); CMP(32, R(RSCRATCH), Imm32(0x02000000)); FixupBranch outsideMainRAM = J_CC(CC_NE); - if (codeMainRAM) - { - LEA(32, RSCRATCH, MRegSum(ABI_PARAM4, ABI_PARAM3)); - ADD(32, R(RCycles), R(RSCRATCH)); - } - else - { - if (!store) - ADD(32, R(ABI_PARAM3), Imm8(1)); - LEA(32, RSCRATCH, MComplex(ABI_PARAM4, ABI_PARAM3, SCALE_1, -3)); - CMP(32, R(ABI_PARAM4), R(ABI_PARAM3)); - CMOVcc(32, ABI_PARAM3, R(ABI_PARAM4), CC_G); - CMP(32, R(ABI_PARAM3), R(RSCRATCH)); - CMOVcc(32, RSCRATCH, R(ABI_PARAM3), CC_G); - ADD(32, R(RCycles), R(RSCRATCH)); - } + CALC_CYCLES_7_DATA_MAIN_RAM(ABI_PARAM3, ABI_PARAM4, RSCRATCH) MOV(32, R(ABI_PARAM3), R(ABI_PARAM1)); AND(32, R(ABI_PARAM3), Imm32((MAIN_RAM_SIZE - 1) & addressMask)); if (store) @@ -205,22 +218,7 @@ void* Compiler::Gen_MemoryRoutine7(bool store, bool codeMainRAM, int size) RET(); SetJumpTarget(outsideMainRAM); - if (codeMainRAM) - { - if (!store) - ADD(32, R(ABI_PARAM4), Imm8(1)); - LEA(32, RSCRATCH, MComplex(ABI_PARAM4, ABI_PARAM3, SCALE_1, -3)); - CMP(32, R(ABI_PARAM4), R(ABI_PARAM3)); - CMOVcc(32, ABI_PARAM3, R(ABI_PARAM4), CC_G); - CMP(32, R(ABI_PARAM3), R(RSCRATCH)); - CMOVcc(32, RSCRATCH, R(ABI_PARAM3), CC_G); - ADD(32, R(RCycles), R(RSCRATCH)); - } - else - { - LEA(32, RSCRATCH, MComplex(ABI_PARAM4, ABI_PARAM3, SCALE_1, store ? 0 : 1)); - ADD(32, R(RCycles), R(RSCRATCH)); - } + CALC_CYCLES_7_DATA_NON_MAIN_RAM(ABI_PARAM3, ABI_PARAM4, RSCRATCH) if (store) { if (size > 8) @@ -257,7 +255,189 @@ void* Compiler::Gen_MemoryRoutine7(bool store, bool codeMainRAM, int size) return res; } -void Compiler::Comp_MemAccess(Gen::OpArg rd, bool signExtend, bool store, int size) +#define MEMORY_SEQ_WHILE_COND \ + if (!store) \ + MOV(32, currentElement, R(EAX));\ + if (!preinc) \ + ADD(32, R(ABI_PARAM1), Imm8(4)); \ + \ + SUB(32, R(ABI_PARAM3), Imm8(1)); \ + J_CC(CC_NZ, repeat); + +/* + ABI_PARAM1 address + ABI_PARAM2 address where registers are stored + ABI_PARAM3 how many values to read/write + ABI_PARAM4 code cycles + + Dolphin x64CodeEmitter is my favourite assembler + */ +void* Compiler::Gen_MemoryRoutineSeq9(bool store, bool preinc) +{ + const u8* zero = GetCodePtr(); + ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(ABI_PARAM4)); + RET(); + + void* res = (void*)GetWritableCodePtr(); + + TEST(32, R(ABI_PARAM3), R(ABI_PARAM3)); + J_CC(CC_Z, zero); + + PUSH(ABI_PARAM3); + PUSH(ABI_PARAM4); // we need you later + + const u8* repeat = GetCodePtr(); + + if (preinc) + ADD(32, R(ABI_PARAM1), Imm8(4)); + + MOV(32, R(RSCRATCH), R(ABI_PARAM1)); + SUB(32, R(RSCRATCH), MDisp(RCPU, offsetof(ARMv5, DTCMBase))); + CMP(32, R(RSCRATCH), MDisp(RCPU, offsetof(ARMv5, DTCMSize))); + FixupBranch insideDTCM = J_CC(CC_B); + + CMP(32, R(ABI_PARAM1), MDisp(RCPU, offsetof(ARMv5, ITCMSize))); + FixupBranch insideITCM = J_CC(CC_B); + + OpArg currentElement = MComplex(ABI_PARAM2, ABI_PARAM3, SCALE_8, -8); // wasting stack space like a gangster + + ABI_PushRegistersAndAdjustStack({ABI_PARAM1, ABI_PARAM2, ABI_PARAM3}, 8); + AND(32, R(ABI_PARAM1), Imm8(~3)); + if (store) + { + MOV(32, R(ABI_PARAM2), currentElement); + CALL((void*)NDS::ARM9Write32); + } + else + CALL((void*)NDS::ARM9Read32); + ABI_PopRegistersAndAdjustStack({ABI_PARAM1, ABI_PARAM2, ABI_PARAM3}, 8); + + MEMORY_SEQ_WHILE_COND + MOV(32, R(RSCRATCH), R(ABI_PARAM1)); + SHR(32, R(RSCRATCH), Imm8(12)); + MOVZX(32, 8, ABI_PARAM2, MComplex(RCPU, RSCRATCH, SCALE_4, 2 + offsetof(ARMv5, MemTimings))); + MOVZX(32, 8, RSCRATCH, MComplex(RCPU, RSCRATCH, SCALE_4, 3 + offsetof(ARMv5, MemTimings))); + + FixupBranch finishIt1 = J(); + + SetJumpTarget(insideDTCM); + AND(32, R(RSCRATCH), Imm32(0x3FFF & ~3)); + if (store) + { + MOV(32, R(ABI_PARAM4), currentElement); + MOV(32, MComplex(RCPU, RSCRATCH, SCALE_1, offsetof(ARMv5, DTCM)), R(ABI_PARAM4)); + } + else + MOV(32, R(RSCRATCH), MComplex(RCPU, RSCRATCH, SCALE_1, offsetof(ARMv5, DTCM))); + + MEMORY_SEQ_WHILE_COND + MOV(32, R(RSCRATCH), Imm32(1)); // sequential access time + MOV(32, R(ABI_PARAM2), Imm32(1)); // non sequential + FixupBranch finishIt2 = J(); + + SetJumpTarget(insideITCM); + MOV(32, R(RSCRATCH), R(ABI_PARAM1)); + AND(32, R(RSCRATCH), Imm32(0x7FFF & ~3)); + if (store) + { + MOV(32, R(ABI_PARAM4), currentElement); + MOV(32, MComplex(RCPU, RSCRATCH, SCALE_1, offsetof(ARMv5, ITCM)), R(ABI_PARAM4)); + XOR(32, R(ABI_PARAM4), R(ABI_PARAM4)); + MOV(64, MScaled(RSCRATCH, SCALE_4, squeezePointer(cache.ARM9_ITCM)), R(ABI_PARAM4)); + MOV(64, MScaled(RSCRATCH, SCALE_4, squeezePointer(cache.ARM9_ITCM) + 8), R(ABI_PARAM4)); + } + else + MOV(32, R(RSCRATCH), MComplex(RCPU, RSCRATCH, SCALE_1, offsetof(ARMv5, ITCM))); + + MEMORY_SEQ_WHILE_COND + MOV(32, R(RSCRATCH), Imm32(1)); + MOV(32, R(ABI_PARAM2), Imm32(1)); + + SetJumpTarget(finishIt1); + SetJumpTarget(finishIt2); + + POP(ABI_PARAM4); + POP(ABI_PARAM3); + + CMP(32, R(ABI_PARAM3), Imm8(1)); + FixupBranch skipSequential = J_CC(CC_E); + SUB(32, R(ABI_PARAM3), Imm8(1)); + IMUL(32, R(ABI_PARAM3)); + ADD(32, R(ABI_PARAM2), R(RSCRATCH)); + SetJumpTarget(skipSequential); + + CALC_CYCLES_9(ABI_PARAM4, ABI_PARAM2, RSCRATCH) + RET(); + + return res; +} + +void* Compiler::Gen_MemoryRoutineSeq7(bool store, bool preinc, bool codeMainRAM) +{ + const u8* zero = GetCodePtr(); + ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(ABI_PARAM4)); + RET(); + + void* res = (void*)GetWritableCodePtr(); + + TEST(32, R(ABI_PARAM3), R(ABI_PARAM3)); + J_CC(CC_Z, zero); + + PUSH(ABI_PARAM3); + PUSH(ABI_PARAM4); // we need you later + + const u8* repeat = GetCodePtr(); + + if (preinc) + ADD(32, R(ABI_PARAM1), Imm8(4)); + + OpArg currentElement = MComplex(ABI_PARAM2, ABI_PARAM3, SCALE_8, -8); + + ABI_PushRegistersAndAdjustStack({ABI_PARAM1, ABI_PARAM2, ABI_PARAM3}, 8); + AND(32, R(ABI_PARAM1), Imm8(~3)); + if (store) + { + MOV(32, R(ABI_PARAM2), currentElement); + CALL((void*)NDS::ARM7Write32); + } + else + CALL((void*)NDS::ARM7Read32); + ABI_PopRegistersAndAdjustStack({ABI_PARAM1, ABI_PARAM2, ABI_PARAM3}, 8); + + MEMORY_SEQ_WHILE_COND + MOV(32, R(RSCRATCH), R(ABI_PARAM1)); + SHR(32, R(RSCRATCH), Imm8(15)); + MOVZX(32, 8, ABI_PARAM2, MScaled(RSCRATCH, SCALE_4, 2 + squeezePointer(NDS::ARM7MemTimings))); + MOVZX(32, 8, RSCRATCH, MScaled(RSCRATCH, SCALE_4, 3 + squeezePointer(NDS::ARM7MemTimings))); + + POP(ABI_PARAM4); + POP(ABI_PARAM3); + + CMP(32, R(ABI_PARAM3), Imm8(1)); + FixupBranch skipSequential = J_CC(CC_E); + SUB(32, R(ABI_PARAM3), Imm8(1)); + IMUL(32, R(ABI_PARAM3)); + ADD(32, R(ABI_PARAM2), R(RSCRATCH)); + SetJumpTarget(skipSequential); + + MOV(32, R(RSCRATCH), R(ABI_PARAM1)); + AND(32, R(RSCRATCH), Imm32(0xFF000000)); + CMP(32, R(RSCRATCH), Imm32(0x02000000)); + FixupBranch outsideMainRAM = J_CC(CC_NE); + CALC_CYCLES_7_DATA_MAIN_RAM(ABI_PARAM4, ABI_PARAM2, RSCRATCH) + RET(); + + SetJumpTarget(outsideMainRAM); + CALC_CYCLES_7_DATA_NON_MAIN_RAM(ABI_PARAM4, ABI_PARAM2, RSCRATCH) + RET(); + + return res; +} + +#undef CALC_CYCLES_9 +#undef MEMORY_SEQ_WHILE_COND + +void Compiler::Comp_MemAccess(OpArg rd, bool signExtend, bool store, int size) { if (store) MOV(32, R(ABI_PARAM2), rd); @@ -278,6 +458,129 @@ void Compiler::Comp_MemAccess(Gen::OpArg rd, bool signExtend, bool store, int si } } +s32 Compiler::Comp_MemAccessBlock(OpArg rb, BitSet16 regs, bool store, bool preinc, bool decrement, bool usermode) +{ + int regsCount = regs.Count(); + + const u8 userModeOffsets[] = + { + offsetof(ARM, R[8]), offsetof(ARM, R[9]), offsetof(ARM, R[10]), offsetof(ARM, R[11]), + offsetof(ARM, R[12]), offsetof(ARM, R[13]), offsetof(ARM, R[14]), 0, + + offsetof(ARM, R_FIQ[0]), offsetof(ARM, R_FIQ[1]), offsetof(ARM, R_FIQ[2]), offsetof(ARM, R_FIQ[3]), + offsetof(ARM, R_FIQ[4]), offsetof(ARM, R_FIQ[5]), offsetof(ARM, R_FIQ[6]), 0, + + offsetof(ARM, R[8]), offsetof(ARM, R[9]), offsetof(ARM, R[10]), offsetof(ARM, R[11]), + offsetof(ARM, R[12]), offsetof(ARM, R_IRQ[13]), offsetof(ARM, R_IRQ[14]), 0, + + offsetof(ARM, R[8]), offsetof(ARM, R[9]), offsetof(ARM, R[10]), offsetof(ARM, R[11]), + offsetof(ARM, R[12]), offsetof(ARM, R_SVC[13]), offsetof(ARM, R_SVC[14]), 0, + + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + + offsetof(ARM, R[8]), offsetof(ARM, R[9]), offsetof(ARM, R[10]), offsetof(ARM, R[11]), + offsetof(ARM, R[12]), offsetof(ARM, R_ABT[13]), offsetof(ARM, R_ABT[14]), 0, + + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + + offsetof(ARM, R[8]), offsetof(ARM, R[9]), offsetof(ARM, R[10]), offsetof(ARM, R[11]), + offsetof(ARM, R[12]), offsetof(ARM, R_UND[13]), offsetof(ARM, R_UND[14]), 0, + }; + + if (decrement) + { + MOV_sum(32, ABI_PARAM1, rb, Imm32(-regsCount * 4)); + preinc = !preinc; + } + else + MOV(32, R(ABI_PARAM1), rb); + + MOV(32, R(ABI_PARAM3), Imm32(regsCount)); + u32 cycles = Num + ? NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2] + : (R15 & 0x2 ? 0 : CurInstr.CodeCycles); + MOV(32, R(ABI_PARAM4), Imm32(cycles)); + if (!store) + { + SUB(32, R(RSP), regsCount < 16 ? Imm8(regsCount * 8) : Imm32(regsCount * 8)); + MOV(64, R(ABI_PARAM2), R(RSP)); + + CALL(Num == 0 + ? MemoryFuncsSeq9[0][preinc] + : MemoryFuncsSeq7[0][preinc][CodeRegion == 0x02]); + + for (int reg = 15; reg >= 0; reg--) + { + if (regs[reg]) + { + if (usermode && reg >= 8 && reg < 15) + { + MOV(32, R(RSCRATCH2), R(RCPSR)); + AND(32, R(RSCRATCH2), Imm8(0x1F)); + // (RSCRATCH2 - 0x11) * 8 + squeezePointer(userModeOffsets) + (reg - 8), algebra is great! + MOVZX(32, 8, RSCRATCH2, MScaled(RSCRATCH2, SCALE_8, squeezePointer(userModeOffsets) - 0x11 * 8 + (reg - 8))); + POP(RSCRATCH); + MOV(32, MRegSum(RCPU, RSCRATCH2), R(RSCRATCH)); + } + else if (RegCache.Mapping[reg] == INVALID_REG) + { + assert(reg != 15); + + POP(RSCRATCH); + SaveReg(reg, RSCRATCH); + } + else + { + if (reg != 15) + RegCache.DirtyRegs |= (1 << reg); + POP(MapReg(reg).GetSimpleReg()); + } + } + } + + if (regs[15]) + { + if (Num == 1) + OR(32, MapReg(15), Imm8(1)); + Comp_JumpTo(MapReg(15).GetSimpleReg(), usermode); + } + } + else + { + for (int reg : regs) + { + if (usermode && reg >= 8 && reg < 15) + { + MOV(32, R(RSCRATCH), R(RCPSR)); + AND(32, R(RSCRATCH), Imm8(0x1F)); + // (RSCRATCH2 - 0x11) * 8 + squeezePointer(userModeOffsets) + (reg - 8), algebra is great! + MOVZX(32, 8, RSCRATCH, MScaled(RSCRATCH, SCALE_8, squeezePointer(userModeOffsets) - 0x11 * 8 + (reg - 8))); + MOV(32, R(RSCRATCH), MRegSum(RCPU, RSCRATCH)); + PUSH(RSCRATCH); + } + else if (RegCache.Mapping[reg] == INVALID_REG) + { + LoadReg(reg, RSCRATCH); + PUSH(RSCRATCH); + } + else + PUSH(MapReg(reg).GetSimpleReg()); + } + MOV(64, R(ABI_PARAM2), R(RSP)); + + CALL(Num == 0 + ? MemoryFuncsSeq9[1][preinc] + : MemoryFuncsSeq7[1][preinc][CodeRegion == 0x02]); + + ADD(32, R(RSP), regsCount < 16 ? Imm8(regsCount * 8) : Imm32(regsCount * 8)); + } + + return (regsCount * 4) * (decrement ? -1 : 1); +} + OpArg Compiler::A_Comp_GetMemWBOffset() { if (!(CurInstr.Instr & (1 << 25))) @@ -354,6 +657,25 @@ void Compiler::A_Comp_MemHalf() ? Imm32(CurInstr.Instr & 0xF | ((CurInstr.Instr >> 4) & 0xF0)) : MapReg(CurInstr.A_Reg(0)); + int op = (CurInstr.Instr >> 5) & 0x3; + bool load = CurInstr.Instr & (1 << 20); + + bool signExtend = false; + int size; + if (!load) + { + size = op == 1 ? 16 : 32; + load = op == 2; + } + else if (load) + { + size = op == 2 ? 8 : 16; + signExtend = op > 1; + } + + if (size == 32 && Num == 1) + return; // NOP + if (CurInstr.Instr & (1 << 24)) { if (CurInstr.Instr & (1 << 23)) @@ -370,19 +692,6 @@ void Compiler::A_Comp_MemHalf() else MOV(32, R(ABI_PARAM1), rn); - int op = (CurInstr.Instr >> 5) & 0x3; - bool load = CurInstr.Instr & (1 << 20); - - bool signExtend = false; - int size; - if (!load && op == 1) - size = 16; - else if (load) - { - size = op == 2 ? 8 : 16; - signExtend = op > 1; - } - if (!(CurInstr.Instr & (1 << 24))) { if (CurInstr.Instr & (1 << 23)) @@ -412,6 +721,24 @@ void Compiler::T_Comp_MemReg() Comp_MemAccess(rd, false, !load, byte ? 8 : 32); } +void Compiler::A_Comp_LDM_STM() +{ + BitSet16 regs(CurInstr.Instr & 0xFFFF); + + bool load = (CurInstr.Instr >> 20) & 1; + bool pre = (CurInstr.Instr >> 24) & 1; + bool add = (CurInstr.Instr >> 23) & 1; + bool writeback = (CurInstr.Instr >> 21) & 1; + bool usermode = (CurInstr.Instr >> 22) & 1; + + OpArg rn = MapReg(CurInstr.A_Reg(16)); + + s32 offset = Comp_MemAccessBlock(rn, regs, !load, pre, !add, false); + + if (writeback) + ADD(32, rn, offset >= INT8_MIN && offset < INT8_MAX ? Imm8(offset) : Imm32(offset)); +} + void Compiler::T_Comp_MemImm() { OpArg rd = MapReg(CurInstr.T_Reg(0)); @@ -456,4 +783,56 @@ void Compiler::T_Comp_MemImmHalf() Comp_MemAccess(rd, false, !load, 16); } +void Compiler::T_Comp_LoadPCRel() +{ + OpArg rd = MapReg(CurInstr.T_Reg(8)); + u32 addr = (R15 & ~0x2) + ((CurInstr.Instr & 0xFF) << 2); + + // hopefully this doesn't break + u32 val; CurCPU->DataRead32(addr, &val); + MOV(32, rd, Imm32(val)); +} + +void Compiler::T_Comp_MemSPRel() +{ + u32 offset = (CurInstr.Instr & 0xFF) * 4; + OpArg rd = MapReg(CurInstr.T_Reg(8)); + bool load = CurInstr.Instr & (1 << 11); + + LEA(32, ABI_PARAM1, MDisp(MapReg(13).GetSimpleReg(), offset)); + + Comp_MemAccess(rd, false, !load, 32); +} + +void Compiler::T_Comp_PUSH_POP() +{ + bool load = CurInstr.Instr & (1 << 11); + BitSet16 regs(CurInstr.Instr & 0xFF); + if (CurInstr.Instr & (1 << 8)) + { + if (load) + regs[15] = true; + else + regs[14] = true; + } + + OpArg sp = MapReg(13); + + s32 offset = Comp_MemAccessBlock(sp, regs, !load, !load, !load, false); + + ADD(32, sp, Imm8(offset)); // offset will be always be in range since PUSH accesses 9 regs max +} + +void Compiler::T_Comp_LDMIA_STMIA() +{ + BitSet16 regs(CurInstr.Instr & 0xFF); + OpArg rb = MapReg(CurInstr.T_Reg(8)); + bool load = CurInstr.Instr & (1 << 11); + + s32 offset = Comp_MemAccessBlock(rb, regs, !load, false, false, false); + + if (!load || !regs[CurInstr.T_Reg(8)]) + ADD(32, rb, Imm8(offset)); +} + } \ No newline at end of file diff --git a/src/ARM_InstrInfo.cpp b/src/ARM_InstrInfo.cpp index 32a9645..c519229 100644 --- a/src/ARM_InstrInfo.cpp +++ b/src/ARM_InstrInfo.cpp @@ -25,9 +25,7 @@ enum { A_Link = 1 << 10, - A_LDMSTM = 1 << 11, - - A_ARM9Only = 1 << 12, + A_UnkOnARM7 = 1 << 11, }; #define A_BIOP A_Read16 @@ -97,12 +95,12 @@ const u32 A_SMULWy = A_Write16 | A_Read0 | A_Read8 | ak(ak_SMULWy); const u32 A_SMLALxy = A_Write16 | A_Write12 | A_Read16 | A_Read12 | A_Read0 | A_Read8 | ak(ak_SMLALxy); const u32 A_SMULxy = A_Write16 | A_Read0 | A_Read8 | ak(ak_SMULxy); -const u32 A_CLZ = A_Write12 | A_Read0 | A_ARM9Only | ak(ak_CLZ); +const u32 A_CLZ = A_Write12 | A_Read0 | A_UnkOnARM7 | ak(ak_CLZ); -const u32 A_QADD = A_Write12 | A_Read0 | A_Read16 | A_ARM9Only | ak(ak_QADD); -const u32 A_QSUB = A_Write12 | A_Read0 | A_Read16 | A_ARM9Only | ak(ak_QSUB); -const u32 A_QDADD = A_Write12 | A_Read0 | A_Read16 | A_ARM9Only | ak(ak_QDADD); -const u32 A_QDSUB = A_Write12 | A_Read0 | A_Read16 | A_ARM9Only | ak(ak_QDSUB); +const u32 A_QADD = A_Write12 | A_Read0 | A_Read16 | A_UnkOnARM7 | ak(ak_QADD); +const u32 A_QSUB = A_Write12 | A_Read0 | A_Read16 | A_UnkOnARM7 | ak(ak_QSUB); +const u32 A_QDADD = A_Write12 | A_Read0 | A_Read16 | A_UnkOnARM7 | ak(ak_QDADD); +const u32 A_QDSUB = A_Write12 | A_Read0 | A_Read16 | A_UnkOnARM7 | ak(ak_QDSUB); #define A_LDR A_Write12 #define A_STR A_Read12 @@ -144,8 +142,8 @@ A_IMPLEMENT_HD_LDRSTR(LDRSH,LDR) const u32 A_SWP = A_Write12 | A_Read16 | A_Read0 | ak(ak_SWP); const u32 A_SWPB = A_Write12 | A_Read16 | A_Read0 | ak(ak_SWPB); -const u32 A_LDM = A_Read16 | A_LDMSTM | ak(ak_LDM); -const u32 A_STM = A_Read16 | A_LDMSTM | ak(ak_STM); +const u32 A_LDM = A_Read16 | A_MemWriteback | ak(ak_LDM); +const u32 A_STM = A_Read16 | A_MemWriteback | ak(ak_STM); const u32 A_B = A_BranchAlways | ak(ak_B); const u32 A_BL = A_BranchAlways | A_Link | ak(ak_BL); @@ -154,11 +152,11 @@ const u32 A_BX = A_BranchAlways | A_Read0 | ak(ak_BX); const u32 A_BLX_REG = A_BranchAlways | A_Link | A_Read0 | ak(ak_BLX_REG); const u32 A_UNK = A_BranchAlways | A_Link | ak(ak_UNK); -const u32 A_MSR_IMM = A_ARM9Only | ak(ak_MSR_IMM); -const u32 A_MSR_REG = A_Read0 | A_ARM9Only | ak(ak_MSR_REG); -const u32 A_MRS = A_Write12 | A_ARM9Only | ak(ak_MRS); -const u32 A_MCR = A_Read12 | A_ARM9Only | ak(ak_MCR); -const u32 A_MRC = A_Write12 | A_ARM9Only | ak(ak_MRC); +const u32 A_MSR_IMM = A_UnkOnARM7 | ak(ak_MSR_IMM); +const u32 A_MSR_REG = A_Read0 | A_UnkOnARM7 | ak(ak_MSR_REG); +const u32 A_MRS = A_Write12 | A_UnkOnARM7 | ak(ak_MRS); +const u32 A_MCR = A_Read12 | A_UnkOnARM7 | ak(ak_MCR); +const u32 A_MRC = A_Write12 | A_UnkOnARM7 | ak(ak_MRC); const u32 A_SVC = A_BranchAlways | A_Link | ak(ak_SVC); // THUMB @@ -249,7 +247,7 @@ const u32 T_LDRH_IMM = T_Write0 | T_Read3 | tk(tk_LDRH_IMM); const u32 T_STR_SPREL = T_Read8 | T_ReadR13 | tk(tk_STR_SPREL); const u32 T_LDR_SPREL = T_Write8 | T_ReadR13 | tk(tk_LDR_SPREL); -const u32 T_PUSH = T_ReadR15 | T_ReadR13 | T_WriteR13 | tk(tk_PUSH); +const u32 T_PUSH = T_ReadR13 | T_WriteR13 | tk(tk_PUSH); const u32 T_POP = T_PopPC | T_ReadR13 | T_WriteR13 | tk(tk_POP); const u32 T_LDMIA = T_Read8 | T_Write8 | tk(tk_LDMIA); @@ -320,8 +318,10 @@ Info Decode(bool thumb, u32 num, u32 instr) if (num == 0 && (instr & 0xFE000000) == 0xFA000000) data = A_BLX_IMM; - if (data & A_ARM9Only && num != 0) - data |= A_BranchAlways | A_Link; + if (data & A_UnkOnARM7 && num != 0) + data = A_UNK; + + res.Kind = (data >> 13) & 0x1FF; if (data & A_Read0) res.SrcRegs |= 1 << (instr & 0xF); @@ -360,14 +360,8 @@ Info Decode(bool thumb, u32 num, u32 instr) res.SrcRegs |= 1 << 15; } - if (data & A_LDMSTM) - { - res.DstRegs |= instr & (!!(instr & (1 << 20)) << 15); - if (instr & (1 << 21)) - res.DstRegs |= 1 << ((instr >> 16) & 0xF); - } - - res.Kind = (data >> 13) & 0x1FF; + if (res.Kind == ak_LDM) + res.DstRegs |= instr & (1 << 15); // this is right return res; } -- cgit v1.2.3 From 83bd863361e19bc5456bbaaa3d0ec0df3c1731c0 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Thu, 11 Jul 2019 16:22:47 +0200 Subject: jit: branch instructions --- src/ARM.cpp | 12 +- src/ARMJIT.cpp | 4 +- src/ARMJIT.h | 2 +- src/ARMJIT_x64/ARMJIT_Branch.cpp | 267 ++++++++++++++++++++++++++++++++++++ src/ARMJIT_x64/ARMJIT_Compiler.cpp | 185 ++++++++----------------- src/ARMJIT_x64/ARMJIT_Compiler.h | 30 ++-- src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 42 +----- src/ARM_InstrInfo.cpp | 6 +- src/ARM_InstrInfo.h | 1 + src/CMakeLists.txt | 1 + 10 files changed, 363 insertions(+), 187 deletions(-) create mode 100644 src/ARMJIT_x64/ARMJIT_Branch.cpp (limited to 'src') diff --git a/src/ARM.cpp b/src/ARM.cpp index df58ce3..3c2253c 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -564,11 +564,8 @@ void ARMv5::Execute() printf("aaarg ungempappter raum %x\n", R[15]);*/ ARMJIT::CompiledBlock block = ARMJIT::LookUpBlock(0, R[15] - ((CPSR&0x20)?2:4)); - if (block == NULL) - ARMJIT::CompileBlock(this); - else - Cycles += block(); - + Cycles += (block ? block : ARMJIT::CompileBlock(this))(); + // TODO optimize this shit!!! if (Halted) { @@ -650,10 +647,7 @@ void ARMv4::Execute() printf("aaarg ungempappter raum %x\n", R[15]);*/ ARMJIT::CompiledBlock block = ARMJIT::LookUpBlock(1, R[15] - ((CPSR&0x20)?2:4)); - if (block == NULL) - ARMJIT::CompileBlock(this); - else - Cycles += block(); + Cycles += (block ? block : ARMJIT::CompileBlock(this))(); // TODO optimize this shit!!! if (Halted) diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 6afa967..47b425f 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -121,7 +121,7 @@ void DeInit() delete compiler; } -void CompileBlock(ARM* cpu) +CompiledBlock CompileBlock(ARM* cpu) { bool thumb = cpu->CPSR & 0x20; @@ -171,6 +171,8 @@ void CompileBlock(ARM* cpu) CompiledBlock block = compiler->CompileBlock(cpu, instrs, i); InsertBlock(cpu->Num, r15Initial - (thumb ? 2 : 4), block); + + return block; } void ResetBlocks() diff --git a/src/ARMJIT.h b/src/ARMJIT.h index 71188f9..45bb4ed 100644 --- a/src/ARMJIT.h +++ b/src/ARMJIT.h @@ -109,7 +109,7 @@ inline void InsertBlock(u32 num, u32 addr, CompiledBlock func) void Init(); void DeInit(); -void CompileBlock(ARM* cpu); +CompiledBlock CompileBlock(ARM* cpu); void ResetBlocks(); diff --git a/src/ARMJIT_x64/ARMJIT_Branch.cpp b/src/ARMJIT_x64/ARMJIT_Branch.cpp new file mode 100644 index 0000000..fb2acba --- /dev/null +++ b/src/ARMJIT_x64/ARMJIT_Branch.cpp @@ -0,0 +1,267 @@ +#include "ARMJIT_Compiler.h" + +using namespace Gen; + +namespace ARMJIT +{ + +void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) +{ + // we can simplify constant branches by a lot + // it's not completely safe to assume stuff like, which instructions to preload + // we'll see how it works out + + u32 newPC; + u32 nextInstr[2]; + u32 cycles = 0; + bool setupRegion = false; + + if (addr & 0x1 && !Thumb) + { + CPSRDirty = true; + OR(32, R(RCPSR), Imm8(0x20)); + } + else if (!(addr & 0x1) && Thumb) + { + CPSRDirty = true; + AND(32, R(RCPSR), Imm32(~0x20)); + } + + if (Num == 0) + { + ARMv5* cpu9 = (ARMv5*)CurCPU; + + u32 oldregion = R15 >> 24; + u32 newregion = addr >> 24; + + u32 regionCodeCycles = cpu9->MemTimings[addr >> 12][0]; + cpu9->RegionCodeCycles = regionCodeCycles; + + MOV(32, MDisp(RCPU, offsetof(ARMv5, RegionCodeCycles)), Imm32(regionCodeCycles)); + + setupRegion = newregion != oldregion; + if (setupRegion) + cpu9->SetupCodeMem(addr); + + if (addr & 0x1) + { + addr &= ~0x1; + newPC = addr+2; + + // two-opcodes-at-once fetch + // doesn't matter if we put garbage in the MSbs there + if (addr & 0x2) + { + nextInstr[0] = cpu9->CodeRead32(addr-2, true) >> 16; + cycles += CurCPU->CodeCycles; + nextInstr[1] = cpu9->CodeRead32(addr+2, false); + cycles += CurCPU->CodeCycles; + } + else + { + nextInstr[0] = cpu9->CodeRead32(addr, true); + nextInstr[1] = nextInstr[0] >> 16; + cycles += CurCPU->CodeCycles; + } + } + else + { + addr &= ~0x3; + newPC = addr+4; + + nextInstr[0] = cpu9->CodeRead32(addr, true); + cycles += cpu9->CodeCycles; + nextInstr[1] = cpu9->CodeRead32(addr+4, false); + cycles += cpu9->CodeCycles; + } + } + else + { + ARMv4* cpu7 = (ARMv4*)CurCPU; + + u32 codeRegion = addr >> 24; + u32 codeCycles = addr >> 15; // cheato + + cpu7->CodeRegion = codeRegion; + cpu7->CodeCycles = codeCycles; + + MOV(32, MDisp(RCPU, offsetof(ARM, CodeRegion)), Imm32(codeRegion)); + MOV(32, MDisp(RCPU, offsetof(ARM, CodeRegion)), Imm32(codeCycles)); + + if (addr & 0x1) + { + addr &= ~0x1; + newPC = addr+2; + + nextInstr[0] = ((ARMv4*)CurCPU)->CodeRead16(addr); + nextInstr[1] = ((ARMv4*)CurCPU)->CodeRead16(addr+2); + cycles += NDS::ARM7MemTimings[codeCycles][0] + NDS::ARM7MemTimings[codeCycles][1]; + } + else + { + addr &= ~0x3; + newPC = addr+4; + + nextInstr[0] = cpu7->CodeRead32(addr); + nextInstr[1] = cpu7->CodeRead32(addr+4); + cycles += NDS::ARM7MemTimings[codeCycles][2] + NDS::ARM7MemTimings[codeCycles][3]; + } + } + + MOV(32, MDisp(RCPU, offsetof(ARM, R[15])), Imm32(newPC)); + MOV(32, MDisp(RCPU, offsetof(ARM, NextInstr[0])), Imm32(nextInstr[0])); + MOV(32, MDisp(RCPU, offsetof(ARM, NextInstr[1])), Imm32(nextInstr[1])); + if ((Thumb || CurInstr.Cond() >= 0xE) && !forceNonConstantCycles) + ConstantCycles += cycles; + else + ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm8(cycles)); + + if (setupRegion) + { + MOV(32, R(ABI_PARAM1), R(RCPU)); + MOV(32, R(ABI_PARAM2), Imm32(newPC)); + CALL((void*)&ARMv5::SetupCodeMem); + } +} + +void Compiler::Comp_JumpTo(Gen::X64Reg addr, bool restoreCPSR) +{ + BitSet16 hiRegsLoaded(RegCache.DirtyRegs & 0xFFFF0000); + bool previouslyDirty = CPSRDirty; + SaveCPSR(); + + if (restoreCPSR) + { + if (Thumb || CurInstr.Cond() >= 0xE) + { + for (int reg : hiRegsLoaded) + RegCache.UnloadRegister(reg); + } + else + { + // the ugly way... + // we only save them, to load and save them again + for (int reg : hiRegsLoaded) + SaveReg(reg, RegCache.Mapping[reg]); + } + } + + MOV(64, R(ABI_PARAM1), R(RCPU)); + MOV(32, R(ABI_PARAM2), R(addr)); + if (!restoreCPSR) + XOR(32, R(ABI_PARAM3), R(ABI_PARAM3)); + else + MOV(32, R(ABI_PARAM3), Imm32(restoreCPSR)); + if (Num == 0) + CALL((void*)&ARMv5::JumpTo); + else + CALL((void*)&ARMv4::JumpTo); + + if (!Thumb && restoreCPSR && CurInstr.Cond() < 0xE) + { + for (int reg : hiRegsLoaded) + LoadReg(reg, RegCache.Mapping[reg]); + } + + if (previouslyDirty) + LoadCPSR(); + CPSRDirty = previouslyDirty; +} + +void Compiler::A_Comp_BranchImm() +{ + int op = (CurInstr.Instr >> 24) & 1; + s32 offset = (s32)(CurInstr.Instr << 8) >> 6; + u32 target = R15 + offset; + bool link = op; + + if (CurInstr.Cond() == 0xF) // BLX_imm + { + target += (op << 1) + 1; + link = true; + } + + if (link) + MOV(32, MapReg(14), Imm32(R15 - 4)); + + Comp_JumpTo(target); +} + +void Compiler::A_Comp_BranchXchangeReg() +{ + OpArg rn = MapReg(CurInstr.A_Reg(0)); + if ((CurInstr.Instr & 0xF0) == 0x30) // BLX_reg + MOV(32, MapReg(14), Imm32(R15 - 4)); + Comp_JumpTo(rn.GetSimpleReg()); +} + +void Compiler::T_Comp_BCOND() +{ + u32 cond = (CurInstr.Instr >> 8) & 0xF; + FixupBranch skipExecute = CheckCondition(cond); + + s32 offset = (s32)(CurInstr.Instr << 24) >> 23; + Comp_JumpTo(R15 + offset + 1, true); + + FixupBranch skipFailed = J(); + SetJumpTarget(skipExecute); + Comp_AddCycles_C(true); + SetJumpTarget(skipFailed); +} + +void Compiler::T_Comp_B() +{ + s32 offset = (s32)((CurInstr.Instr & 0x7FF) << 21) >> 20; + Comp_JumpTo(R15 + offset + 1); +} + +void Compiler::T_Comp_BranchXchangeReg() +{ + bool link = CurInstr.Instr & (1 << 7); + if (link && Num == 1) + { + printf("BLX unsupported on ARM7!!!\n"); + return; + } + + OpArg rn = MapReg(CurInstr.A_Reg(3)); + if (link) + MOV(32, MapReg(14), Imm32(R15 - 1)); + Comp_JumpTo(rn.GetSimpleReg()); +} + +void Compiler::T_Comp_BL_LONG_1() +{ + s32 offset = (s32)((CurInstr.Instr & 0x7FF) << 21) >> 9; + MOV(32, MapReg(14), Imm32(R15 + offset)); + Comp_AddCycles_C(); +} + +void Compiler::T_Comp_BL_LONG_2() +{ + OpArg lr = MapReg(14); + s32 offset = (CurInstr.Instr & 0x7FF) << 1; + LEA(32, RSCRATCH, MDisp(lr.GetSimpleReg(), offset)); + MOV(32, lr, Imm32((R15 - 2) | 1)); + if (Num == 1 || CurInstr.Instr & (1 << 12)) + OR(32, R(RSCRATCH), Imm8(1)); + Comp_JumpTo(RSCRATCH); +} + +void Compiler::T_Comp_BL_Merged(FetchedInstr part1) +{ + assert(part1.Info.Kind == ARMInstrInfo::tk_BL_LONG_1); + Comp_AddCycles_C(); + + u32 target = (R15 - 2) + ((s32)((part1.Instr & 0x7FF) << 21) >> 9); + target += (CurInstr.Instr & 0x7FF) << 1; + + if (Num == 1 || CurInstr.Instr & (1 << 12)) + target |= 1; + + MOV(32, MapReg(14), Imm32((R15 - 2) | 1)); + + Comp_JumpTo(target); +} + +} \ No newline at end of file diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index 4fe0c70..6799a90 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -50,50 +50,6 @@ Compiler::Compiler() ResetStart = GetWritableCodePtr(); } -void* Compiler::Gen_ChangeCPSRRoutine() -{ - void* res = (void*)GetWritableCodePtr(); - - MOV(32, R(RSCRATCH), R(RCPSR)); - AND(32, R(RSCRATCH), Imm8(0x1F)); - CMP(32, R(RSCRATCH), Imm8(0x11)); - FixupBranch fiq = J_CC(CC_E); - CMP(32, R(RSCRATCH), Imm8(0x12)); - FixupBranch irq = J_CC(CC_E); - CMP(32, R(RSCRATCH), Imm8(0x13)); - FixupBranch svc = J_CC(CC_E); - CMP(32, R(RSCRATCH), Imm8(0x17)); - FixupBranch abt = J_CC(CC_E); - CMP(32, R(RSCRATCH), Imm8(0x1B)); - FixupBranch und = J_CC(CC_E); - - SetJumpTarget(fiq); - - SetJumpTarget(irq); - - SetJumpTarget(svc); - - SetJumpTarget(abt); - - SetJumpTarget(und); - - return res; -} - -DataRegion Compiler::ClassifyAddress(u32 addr) -{ - if (Num == 0 && addr >= ((ARMv5*)CurCPU)->DTCMBase && addr < ((ARMv5*)CurCPU)->DTCMBase) - return dataRegionDTCM; - switch (addr & 0xFF000000) - { - case 0x02000000: return dataRegionMainRAM; - case 0x03000000: return Num == 1 && (addr & 0xF00000) == 0x800000 ? dataRegionWRAM7 : dataRegionSWRAM; - case 0x04000000: return dataRegionIO; - case 0x06000000: return dataRegionVRAM; - } - return dataRegionGeneric; -} - void Compiler::LoadCPSR() { assert(!CPSRDirty); @@ -123,6 +79,29 @@ void Compiler::SaveReg(int reg, X64Reg nativeReg) MOV(32, MDisp(RCPU, offsetof(ARM, R[reg])), R(nativeReg)); } +// invalidates RSCRATCH and RSCRATCH3 +Gen::FixupBranch Compiler::CheckCondition(u32 cond) +{ + if (cond >= 0x8) + { + static_assert(RSCRATCH3 == ECX); + MOV(32, R(RSCRATCH3), R(RCPSR)); + SHR(32, R(RSCRATCH3), Imm8(28)); + MOV(32, R(RSCRATCH), Imm32(1)); + SHL(32, R(RSCRATCH), R(RSCRATCH3)); + TEST(32, R(RSCRATCH), Imm32(ARM::ConditionTable[cond])); + + return J_CC(CC_Z); + } + else + { + // could have used a LUT, but then where would be the fun? + TEST(32, R(RCPSR), Imm32(1 << (28 + ((~(cond >> 1) & 1) << 1 | (cond >> 2 & 1) ^ (cond >> 1 & 1))))); + + return J_CC(cond & 1 ? CC_NZ : CC_Z); + } +} + CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrsCount) { if (IsAlmostFull()) @@ -140,6 +119,8 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs CodeRegion = cpu->CodeRegion; CurCPU = cpu; + bool mergedThumbBL = false; + ABI_PushRegistersAndAdjustStack({ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS}, 8, 16); MOV(64, R(RCPU), ImmPtr(cpu)); @@ -167,17 +148,10 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs MOV(32, MDisp(RCPU, offsetof(ARM, NextInstr[1])), Imm32(CurInstr.NextInstr[1])); } - if (comp == NULL || CurInstr.Info.Branches()) + if (comp == NULL) SaveCPSR(); } - - // run interpreter - cpu->CodeCycles = CurInstr.CodeCycles; - cpu->R[15] = R15; - cpu->CurInstr = CurInstr.Instr; - cpu->NextInstr[0] = CurInstr.NextInstr[0]; - cpu->NextInstr[1] = CurInstr.NextInstr[1]; - + if (comp != NULL) RegCache.Prepare(i); else @@ -185,58 +159,44 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs if (Thumb) { - u32 icode = (CurInstr.Instr >> 6) & 0x3FF; - if (comp == NULL) + if (i < instrsCount - 1 && CurInstr.Info.Kind == ARMInstrInfo::tk_BL_LONG_1 + && instrs[i + 1].Info.Kind == ARMInstrInfo::tk_BL_LONG_2) + mergedThumbBL = true; + else { - MOV(64, R(ABI_PARAM1), R(RCPU)); + u32 icode = (CurInstr.Instr >> 6) & 0x3FF; + if (comp == NULL) + { + MOV(64, R(ABI_PARAM1), R(RCPU)); - ABI_CallFunction(ARMInterpreter::THUMBInstrTable[icode]); + ABI_CallFunction(ARMInterpreter::THUMBInstrTable[icode]); + } + else if (mergedThumbBL) + T_Comp_BL_Merged(instrs[i - 1]); + else + (this->*comp)(); } - else - (this->*comp)(); - - ARMInterpreter::THUMBInstrTable[icode](cpu); } else { u32 cond = CurInstr.Cond(); if (CurInstr.Info.Kind == ARMInstrInfo::ak_BLX_IMM) { - MOV(64, R(ABI_PARAM1), R(RCPU)); - ABI_CallFunction(ARMInterpreter::A_BLX_IMM); - - ARMInterpreter::A_BLX_IMM(cpu); + if (comp) + (this->*comp)(); + else + { + MOV(64, R(ABI_PARAM1), R(RCPU)); + ABI_CallFunction(ARMInterpreter::A_BLX_IMM); + } } else if (cond == 0xF) - { Comp_AddCycles_C(); - cpu->AddCycles_C(); - } else { FixupBranch skipExecute; if (cond < 0xE) - { - if (cond >= 0x8) - { - static_assert(RSCRATCH3 == ECX); - MOV(32, R(RSCRATCH3), R(RCPSR)); - SHR(32, R(RSCRATCH3), Imm8(28)); - MOV(32, R(RSCRATCH), Imm32(1)); - SHL(32, R(RSCRATCH), R(RSCRATCH3)); - TEST(32, R(RSCRATCH), Imm32(ARM::ConditionTable[cond])); - - skipExecute = J_CC(CC_Z); - } - else - { - // could have used a LUT, but then where would be the fun? - TEST(32, R(RCPSR), Imm32(1 << (28 + ((~(cond >> 1) & 1) << 1 | (cond >> 2 & 1) ^ (cond >> 1 & 1))))); - - skipExecute = J_CC(cond & 1 ? CC_NZ : CC_Z); - } - - } + skipExecute = CheckCondition(cond); u32 icode = ((CurInstr.Instr >> 4) & 0xF) | ((CurInstr.Instr >> 16) & 0xFF0); if (comp == NULL) @@ -258,19 +218,9 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs SetJumpTarget(skipFailed); } - - if (cpu->CheckCondition(cond)) - ARMInterpreter::ARMInstrTable[icode](cpu); - else - cpu->AddCycles_C(); } } - /* - we don't need to collect the interpreted cycles, - since cpu->Cycles is taken into account by the dispatcher. - */ - if (comp == NULL && i != instrsCount - 1) LoadCPSR(); } @@ -367,7 +317,7 @@ CompileFunc Compiler::GetCompFunc(int kind) // LDM/STM NULL, NULL, // Branch - NULL, NULL, NULL, NULL, NULL, + A_Comp_BranchImm, A_Comp_BranchImm, A_Comp_BranchImm, A_Comp_BranchXchangeReg, A_Comp_BranchXchangeReg, // system stuff NULL, NULL, NULL, NULL, NULL, NULL, NULL, }; @@ -389,7 +339,7 @@ CompileFunc Compiler::GetCompFunc(int kind) // pc/sp relative T_Comp_RelAddr, T_Comp_RelAddr, T_Comp_AddSP, // LDR pcrel - NULL, + T_Comp_LoadPCRel, // LDR/STR reg offset T_Comp_MemReg, T_Comp_MemReg, T_Comp_MemReg, T_Comp_MemReg, // LDR/STR sign extended, half @@ -399,25 +349,27 @@ CompileFunc Compiler::GetCompFunc(int kind) // LDR/STR half imm offset T_Comp_MemImmHalf, T_Comp_MemImmHalf, // LDR/STR sp rel - NULL, NULL, + T_Comp_MemSPRel, T_Comp_MemSPRel, // PUSH/POP - NULL, NULL, + T_Comp_PUSH_POP, T_Comp_PUSH_POP, // LDMIA, STMIA - NULL, NULL, - NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL + T_Comp_LDMIA_STMIA, T_Comp_LDMIA_STMIA, + // Branch + T_Comp_BCOND, T_Comp_BranchXchangeReg, T_Comp_BranchXchangeReg, T_Comp_B, T_Comp_BL_LONG_1, T_Comp_BL_LONG_2, + // Unk, SVC + NULL, NULL }; return Thumb ? T_Comp[kind] : A_Comp[kind]; } -void Compiler::Comp_AddCycles_C() +void Compiler::Comp_AddCycles_C(bool forceNonConstant) { s32 cycles = Num ? NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 1 : 3] : ((R15 & 0x2) ? 0 : CurInstr.CodeCycles); - if (CurInstr.Cond() < 0xE) + if ((!Thumb && CurInstr.Cond() < 0xE) || forceNonConstant) ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm8(cycles)); else ConstantCycles += cycles; @@ -429,25 +381,10 @@ void Compiler::Comp_AddCycles_CI(u32 i) NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2] : ((R15 & 0x2) ? 0 : CurInstr.CodeCycles)) + i; - if (CurInstr.Cond() < 0xE) + if (!Thumb && CurInstr.Cond() < 0xE) ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm8(cycles)); else ConstantCycles += cycles; } -void Compiler::Comp_JumpTo(Gen::X64Reg addr, bool restoreCPSR) -{ - // potentieller Bug: falls ein Register das noch gecacht ist, beim Modeswitch gespeichert - // wird der alte Wert gespeichert - SaveCPSR(); - - MOV(64, R(ABI_PARAM1), R(RCPU)); - MOV(32, R(ABI_PARAM2), R(addr)); - MOV(32, R(ABI_PARAM3), Imm32(restoreCPSR)); - if (Num == 0) - CALL((void*)&ARMv5::JumpTo); - else - CALL((void*)&ARMv4::JumpTo); -} - } \ No newline at end of file diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index a751737..45b488a 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -22,19 +22,6 @@ class Compiler; typedef void (Compiler::*CompileFunc)(); -enum DataRegion -{ - dataRegionGeneric, // hey, that's me! - dataRegionMainRAM, - dataRegionSWRAM, - dataRegionVRAM, - dataRegionIO, - dataRegionExclusive, - dataRegionsCount, - dataRegionDTCM = dataRegionExclusive, - dataRegionWRAM7 = dataRegionExclusive, -}; - class Compiler : public Gen::X64CodeBlock { public: @@ -49,8 +36,9 @@ private: CompileFunc GetCompFunc(int kind); void Comp_JumpTo(Gen::X64Reg addr, bool restoreCPSR = false); + void Comp_JumpTo(u32 addr, bool forceNonConstantCycles = false); - void Comp_AddCycles_C(); + void Comp_AddCycles_C(bool forceNonConstant = false); void Comp_AddCycles_CI(u32 i); enum @@ -63,8 +51,6 @@ private: opInvertOp2 = 1 << 5, }; - DataRegion ClassifyAddress(u32 addr); - void A_Comp_Arith(); void A_Comp_MovOp(); void A_Comp_CmpOp(); @@ -73,6 +59,9 @@ private: void A_Comp_MemHalf(); void A_Comp_LDM_STM(); + void A_Comp_BranchImm(); + void A_Comp_BranchXchangeReg(); + void T_Comp_ShiftImm(); void T_Comp_AddSub_(); void T_Comp_ALU_Imm8(); @@ -91,6 +80,13 @@ private: void T_Comp_PUSH_POP(); void T_Comp_LDMIA_STMIA(); + void T_Comp_BCOND(); + void T_Comp_B(); + void T_Comp_BranchXchangeReg(); + void T_Comp_BL_LONG_1(); + void T_Comp_BL_LONG_2(); + void T_Comp_BL_Merged(FetchedInstr prefix); + void Comp_MemAccess(Gen::OpArg rd, bool signExtend, bool store, int size); s32 Comp_MemAccessBlock(Gen::OpArg rb, BitSet16 regs, bool store, bool preinc, bool decrement, bool usermode); @@ -119,6 +115,8 @@ private: void LoadCPSR(); void SaveCPSR(); + Gen::FixupBranch CheckCondition(u32 cond); + Gen::OpArg MapReg(int reg) { if (reg == 15 && RegCache.Mapping[reg] == Gen::INVALID_REG) diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index 20e1893..69b324c 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -462,38 +462,10 @@ s32 Compiler::Comp_MemAccessBlock(OpArg rb, BitSet16 regs, bool store, bool prei { int regsCount = regs.Count(); - const u8 userModeOffsets[] = - { - offsetof(ARM, R[8]), offsetof(ARM, R[9]), offsetof(ARM, R[10]), offsetof(ARM, R[11]), - offsetof(ARM, R[12]), offsetof(ARM, R[13]), offsetof(ARM, R[14]), 0, - - offsetof(ARM, R_FIQ[0]), offsetof(ARM, R_FIQ[1]), offsetof(ARM, R_FIQ[2]), offsetof(ARM, R_FIQ[3]), - offsetof(ARM, R_FIQ[4]), offsetof(ARM, R_FIQ[5]), offsetof(ARM, R_FIQ[6]), 0, - - offsetof(ARM, R[8]), offsetof(ARM, R[9]), offsetof(ARM, R[10]), offsetof(ARM, R[11]), - offsetof(ARM, R[12]), offsetof(ARM, R_IRQ[13]), offsetof(ARM, R_IRQ[14]), 0, - - offsetof(ARM, R[8]), offsetof(ARM, R[9]), offsetof(ARM, R[10]), offsetof(ARM, R[11]), - offsetof(ARM, R[12]), offsetof(ARM, R_SVC[13]), offsetof(ARM, R_SVC[14]), 0, - - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - - offsetof(ARM, R[8]), offsetof(ARM, R[9]), offsetof(ARM, R[10]), offsetof(ARM, R[11]), - offsetof(ARM, R[12]), offsetof(ARM, R_ABT[13]), offsetof(ARM, R_ABT[14]), 0, - - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - - offsetof(ARM, R[8]), offsetof(ARM, R[9]), offsetof(ARM, R[10]), offsetof(ARM, R[11]), - offsetof(ARM, R[12]), offsetof(ARM, R_UND[13]), offsetof(ARM, R_UND[14]), 0, - }; - if (decrement) { MOV_sum(32, ABI_PARAM1, rb, Imm32(-regsCount * 4)); - preinc = !preinc; + preinc ^= true; } else MOV(32, R(ABI_PARAM1), rb); @@ -516,16 +488,16 @@ s32 Compiler::Comp_MemAccessBlock(OpArg rb, BitSet16 regs, bool store, bool prei { if (regs[reg]) { - if (usermode && reg >= 8 && reg < 15) + /*if (usermode && reg >= 8 && reg < 15) { MOV(32, R(RSCRATCH2), R(RCPSR)); AND(32, R(RSCRATCH2), Imm8(0x1F)); // (RSCRATCH2 - 0x11) * 8 + squeezePointer(userModeOffsets) + (reg - 8), algebra is great! - MOVZX(32, 8, RSCRATCH2, MScaled(RSCRATCH2, SCALE_8, squeezePointer(userModeOffsets) - 0x11 * 8 + (reg - 8))); + MOVZX(32, 8, RSCRATCH2, MScaled(RSCRATCH2, SCALE_8, squeezePointer(userModeOffsets) - 0x10 * 8 + (reg - 8))); POP(RSCRATCH); MOV(32, MRegSum(RCPU, RSCRATCH2), R(RSCRATCH)); } - else if (RegCache.Mapping[reg] == INVALID_REG) + else */if (RegCache.Mapping[reg] == INVALID_REG) { assert(reg != 15); @@ -552,16 +524,16 @@ s32 Compiler::Comp_MemAccessBlock(OpArg rb, BitSet16 regs, bool store, bool prei { for (int reg : regs) { - if (usermode && reg >= 8 && reg < 15) + /*if (usermode && reg >= 8 && reg < 15) { MOV(32, R(RSCRATCH), R(RCPSR)); AND(32, R(RSCRATCH), Imm8(0x1F)); // (RSCRATCH2 - 0x11) * 8 + squeezePointer(userModeOffsets) + (reg - 8), algebra is great! - MOVZX(32, 8, RSCRATCH, MScaled(RSCRATCH, SCALE_8, squeezePointer(userModeOffsets) - 0x11 * 8 + (reg - 8))); + MOVZX(32, 8, RSCRATCH, MScaled(RSCRATCH, SCALE_8, squeezePointer(userModeOffsets) - 0x10 * 8 + (reg - 8))); MOV(32, R(RSCRATCH), MRegSum(RCPU, RSCRATCH)); PUSH(RSCRATCH); } - else if (RegCache.Mapping[reg] == INVALID_REG) + else */if (RegCache.Mapping[reg] == INVALID_REG) { LoadReg(reg, RSCRATCH); PUSH(RSCRATCH); diff --git a/src/ARM_InstrInfo.cpp b/src/ARM_InstrInfo.cpp index c519229..b8dff00 100644 --- a/src/ARM_InstrInfo.cpp +++ b/src/ARM_InstrInfo.cpp @@ -255,7 +255,7 @@ const u32 T_STMIA = T_Read8 | T_Write8 | tk(tk_STMIA); const u32 T_BCOND = T_BranchAlways | tk(tk_BCOND); const u32 T_BX = T_BranchAlways | T_ReadHi3 | tk(tk_BX); -const u32 T_BLX_REG = T_BranchAlways | T_ReadR15 | T_WriteR14 | T_ReadHi3 | tk(tk_BLX_REG); +const u32 T_BLX_REG = T_BranchAlways | T_WriteR14 | T_ReadHi3 | tk(tk_BLX_REG); const u32 T_B = T_BranchAlways | tk(tk_B); const u32 T_BL_LONG_1 = T_WriteR14 | T_ReadR15 | tk(tk_BL_LONG_1); const u32 T_BL_LONG_2 = T_BranchAlways | T_ReadR14 | T_WriteR14 | T_ReadR15 | tk(tk_BL_LONG_2); @@ -301,6 +301,10 @@ Info Decode(bool thumb, u32 num, u32 instr) res.DstRegs |= (1 << 13); if (data & T_ReadR15) res.SrcRegs |= (1 << 15); + if (data & T_WriteR14) + res.DstRegs |= (1 << 14); + if (data & T_ReadR14) + res.SrcRegs |= (1 << 14); if (data & T_BranchAlways) res.DstRegs |= (1 << 15); diff --git a/src/ARM_InstrInfo.h b/src/ARM_InstrInfo.h index dcd938b..51dcfa2 100644 --- a/src/ARM_InstrInfo.h +++ b/src/ARM_InstrInfo.h @@ -202,6 +202,7 @@ enum tk_POP, tk_LDMIA, tk_STMIA, + tk_BCOND, tk_BX, tk_BLX_REG, diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ae04ffb..75fa42c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,6 +54,7 @@ add_library(core STATIC ARMJIT_x64/ARMJIT_Compiler.cpp ARMJIT_x64/ARMJIT_ALU.cpp ARMJIT_x64/ARMJIT_LoadStore.cpp + ARMJIT_x64/ARMJIT_Branch.cpp dolphin/CommonFuncs.cpp dolphin/x64ABI.cpp -- cgit v1.2.3 From f22521a43d8e3ea51493119f9f285cf265f21416 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Fri, 12 Jul 2019 03:43:45 +0200 Subject: jit: LDM/STM finally(!) working + MUL, MLA and CLZ --- src/ARM.cpp | 7 +++ src/ARMJIT_x64/ARMJIT_ALU.cpp | 74 +++++++++++++++++++++++ src/ARMJIT_x64/ARMJIT_Branch.cpp | 7 +-- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 108 +++++++++++++++++++++++++++++++-- src/ARMJIT_x64/ARMJIT_Compiler.h | 14 ++++- src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 116 +++++++++++++++++++++++++----------- 6 files changed, 279 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/ARM.cpp b/src/ARM.cpp index 3c2253c..baf8468 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -81,8 +81,15 @@ ARMv4::ARMv4() : ARM(1) // } +namespace ARMJIT {extern int instructionPopularityARM[ARMInstrInfo::ak_Count];} + void ARM::Reset() { + FILE* blabla = fopen("fhhg", "w"); + for (int i = 0; i < ARMInstrInfo::ak_Count; i++) + fprintf(blabla, "%d -> %dx\n", i, ARMJIT::instructionPopularityARM[i]); + fclose(blabla); + Cycles = 0; Halted = 0; diff --git a/src/ARMJIT_x64/ARMJIT_ALU.cpp b/src/ARMJIT_x64/ARMJIT_ALU.cpp index c22751e..cbe67fd 100644 --- a/src/ARMJIT_x64/ARMJIT_ALU.cpp +++ b/src/ARMJIT_x64/ARMJIT_ALU.cpp @@ -223,6 +223,73 @@ void Compiler::A_Comp_MovOp() Comp_JumpTo(rd.GetSimpleReg(), S); } +void Compiler::A_Comp_CLZ() +{ + OpArg rd = MapReg(CurInstr.A_Reg(12)); + OpArg rm = MapReg(CurInstr.A_Reg(0)); + + MOV(32, R(RSCRATCH), Imm32(32)); + TEST(32, rm, rm); + FixupBranch skipZero = J_CC(CC_Z); + BSR(32, RSCRATCH, rm); + XOR(32, R(RSCRATCH), Imm8(0x1F)); // 31 - RSCRATCH + SetJumpTarget(skipZero); + MOV(32, rd, R(RSCRATCH)); +} + +void Compiler::Comp_MulOp(bool S, bool add, Gen::OpArg rd, Gen::OpArg rm, Gen::OpArg rs, Gen::OpArg rn) +{ + if (Num == 0) + Comp_AddCycles_CI(S ? 3 : 1); + else + { + XOR(32, R(RSCRATCH), R(RSCRATCH)); + MOV(32, R(RSCRATCH3), rs); + TEST(32, R(RSCRATCH3), R(RSCRATCH3)); + FixupBranch zeroBSR = J_CC(CC_Z); + BSR(32, RSCRATCH2, R(RSCRATCH3)); + NOT(32, R(RSCRATCH3)); + BSR(32, RSCRATCH, R(RSCRATCH3)); + CMP(32, R(RSCRATCH2), R(RSCRATCH)); + CMOVcc(32, RSCRATCH, R(RSCRATCH2), CC_L); + SHR(32, R(RSCRATCH), Imm8(3)); + SetJumpTarget(zeroBSR); // fortunately that's even right + Comp_AddCycles_CI(RSCRATCH, add ? 2 : 1); + } + + static_assert(EAX == RSCRATCH); + MOV(32, R(RSCRATCH), rm); + if (add) + { + IMUL(32, RSCRATCH, rs); + LEA(32, rd.GetSimpleReg(), MRegSum(RSCRATCH, rn.GetSimpleReg())); + TEST(32, rd, rd); + } + else + { + IMUL(32, RSCRATCH, rs); + MOV(32, rd, R(RSCRATCH)); + TEST(32, R(RSCRATCH), R(RSCRATCH)); + } + + if (S) + Comp_RetriveFlags(false, false, false); +} + +void Compiler::A_Comp_MUL_MLA() +{ + bool S = CurInstr.Instr & (1 << 20); + bool add = CurInstr.Instr & (1 << 21); + OpArg rd = MapReg(CurInstr.A_Reg(16)); + OpArg rm = MapReg(CurInstr.A_Reg(0)); + OpArg rs = MapReg(CurInstr.A_Reg(8)); + OpArg rn; + if (add) + rn = MapReg(CurInstr.A_Reg(12)); + + Comp_MulOp(S, add, rd, rm, rs, rn); +} + void Compiler::Comp_RetriveFlags(bool sign, bool retriveCV, bool carryUsed) { CPSRDirty = true; @@ -455,6 +522,13 @@ void Compiler::T_Comp_ALU_Imm8() } } +void Compiler::T_Comp_MUL() +{ + OpArg rd = MapReg(CurInstr.T_Reg(0)); + OpArg rs = MapReg(CurInstr.T_Reg(3)); + Comp_MulOp(true, false, rd, rd, rs, Imm8(-1)); +} + void Compiler::T_Comp_ALU() { OpArg rd = MapReg(CurInstr.T_Reg(0)); diff --git a/src/ARMJIT_x64/ARMJIT_Branch.cpp b/src/ARMJIT_x64/ARMJIT_Branch.cpp index fb2acba..bd01ffb 100644 --- a/src/ARMJIT_x64/ARMJIT_Branch.cpp +++ b/src/ARMJIT_x64/ARMJIT_Branch.cpp @@ -126,17 +126,14 @@ void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) void Compiler::Comp_JumpTo(Gen::X64Reg addr, bool restoreCPSR) { - BitSet16 hiRegsLoaded(RegCache.DirtyRegs & 0xFFFF0000); + BitSet16 hiRegsLoaded(RegCache.DirtyRegs & 0xFF00); bool previouslyDirty = CPSRDirty; SaveCPSR(); if (restoreCPSR) { if (Thumb || CurInstr.Cond() >= 0xE) - { - for (int reg : hiRegsLoaded) - RegCache.UnloadRegister(reg); - } + RegCache.Flush(); else { // the ugly way... diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index 6799a90..8a895d1 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -26,10 +26,14 @@ const int RegisterCache::NativeRegsAvailable = #endif ; +int instructionPopularityARM[ARMInstrInfo::ak_Count]; + Compiler::Compiler() { AllocCodeSpace(1024 * 1024 * 16); + memset(instructionPopularityARM, 0, sizeof(instructionPopularityARM)); + for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) @@ -47,7 +51,88 @@ Compiler::Compiler() MemoryFuncsSeq7[i][j][1] = Gen_MemoryRoutineSeq7(i, j, true); } - ResetStart = GetWritableCodePtr(); + { + // RSCRATCH mode + // ABI_PARAM2 reg number + // ABI_PARAM3 value in current mode + // ret - ABI_PARAM3 + ReadBanked = (void*)GetWritableCodePtr(); + CMP(32, R(RSCRATCH), Imm8(0x11)); + FixupBranch fiq = J_CC(CC_E); + SUB(32, R(ABI_PARAM2), Imm8(13 - 8)); + FixupBranch notEverything = J_CC(CC_L); + CMP(32, R(RSCRATCH), Imm8(0x12)); + FixupBranch irq = J_CC(CC_E); + CMP(32, R(RSCRATCH), Imm8(0x13)); + FixupBranch svc = J_CC(CC_E); + CMP(32, R(RSCRATCH), Imm8(0x17)); + FixupBranch abt = J_CC(CC_E); + CMP(32, R(RSCRATCH), Imm8(0x1B)); + FixupBranch und = J_CC(CC_E); + SetJumpTarget(notEverything); + RET(); + + SetJumpTarget(fiq); + MOV(32, R(ABI_PARAM3), MComplex(RCPU, ABI_PARAM2, SCALE_4, offsetof(ARM, R_FIQ))); + RET(); + SetJumpTarget(irq); + MOV(32, R(ABI_PARAM3), MComplex(RCPU, ABI_PARAM2, SCALE_4, offsetof(ARM, R_IRQ))); + RET(); + SetJumpTarget(svc); + MOV(32, R(ABI_PARAM3), MComplex(RCPU, ABI_PARAM2, SCALE_4, offsetof(ARM, R_SVC))); + RET(); + SetJumpTarget(abt); + MOV(32, R(ABI_PARAM3), MComplex(RCPU, ABI_PARAM2, SCALE_4, offsetof(ARM, R_ABT))); + RET(); + SetJumpTarget(und); + MOV(32, R(ABI_PARAM3), MComplex(RCPU, ABI_PARAM2, SCALE_4, offsetof(ARM, R_UND))); + RET(); + } + { + // RSCRATCH mode + // ABI_PARAM2 reg n + // ABI_PARAM3 value + // carry flag set if the register isn't banked + WriteBanked = (void*)GetWritableCodePtr(); + CMP(32, R(RSCRATCH), Imm8(0x11)); + FixupBranch fiq = J_CC(CC_E); + SUB(32, R(ABI_PARAM2), Imm8(13 - 8)); + FixupBranch notEverything = J_CC(CC_L); + CMP(32, R(RSCRATCH), Imm8(0x12)); + FixupBranch irq = J_CC(CC_E); + CMP(32, R(RSCRATCH), Imm8(0x13)); + FixupBranch svc = J_CC(CC_E); + CMP(32, R(RSCRATCH), Imm8(0x17)); + FixupBranch abt = J_CC(CC_E); + CMP(32, R(RSCRATCH), Imm8(0x1B)); + FixupBranch und = J_CC(CC_E); + SetJumpTarget(notEverything); + STC(); + RET(); + + SetJumpTarget(fiq); + MOV(32, MComplex(RCPU, ABI_PARAM2, SCALE_4, offsetof(ARM, R_FIQ)), R(ABI_PARAM3)); + CLC(); + RET(); + SetJumpTarget(irq); + MOV(32, MComplex(RCPU, ABI_PARAM2, SCALE_4, offsetof(ARM, R_IRQ)), R(ABI_PARAM3)); + CLC(); + RET(); + SetJumpTarget(svc); + MOV(32, MComplex(RCPU, ABI_PARAM2, SCALE_4, offsetof(ARM, R_SVC)), R(ABI_PARAM3)); + CLC(); + RET(); + SetJumpTarget(abt); + MOV(32, MComplex(RCPU, ABI_PARAM2, SCALE_4, offsetof(ARM, R_ABT)), R(ABI_PARAM3)); + CLC(); + RET(); + SetJumpTarget(und); + MOV(32, MComplex(RCPU, ABI_PARAM2, SCALE_4, offsetof(ARM, R_UND)), R(ABI_PARAM3)); + CLC(); + RET(); + } + + ResetStart = (void*)GetWritableCodePtr(); } void Compiler::LoadCPSR() @@ -136,6 +221,9 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs CurInstr = instrs[i]; CompileFunc comp = GetCompFunc(CurInstr.Info.Kind); + + if (!Thumb) + instructionPopularityARM[CurInstr.Info.Kind] += comp == NULL; if (comp == NULL || i == instrsCount - 1) { @@ -287,9 +375,9 @@ CompileFunc Compiler::GetCompFunc(int kind) // CMN A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, // Mul - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + A_Comp_MUL_MLA, A_Comp_MUL_MLA, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, // ARMv5 stuff - NULL, NULL, NULL, NULL, NULL, + A_Comp_CLZ, NULL, NULL, NULL, NULL, // STR A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, //NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, @@ -315,7 +403,7 @@ CompileFunc Compiler::GetCompFunc(int kind) // swap NULL, NULL, // LDM/STM - NULL, NULL, + A_Comp_LDM_STM, A_Comp_LDM_STM, // Branch A_Comp_BranchImm, A_Comp_BranchImm, A_Comp_BranchImm, A_Comp_BranchXchangeReg, A_Comp_BranchXchangeReg, // system stuff @@ -333,7 +421,7 @@ CompileFunc Compiler::GetCompFunc(int kind) T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, - T_Comp_ALU, NULL, T_Comp_ALU, T_Comp_ALU, + T_Comp_ALU, T_Comp_MUL, T_Comp_ALU, T_Comp_ALU, // hi reg T_Comp_ALU_HiReg, T_Comp_ALU_HiReg, T_Comp_ALU_HiReg, // pc/sp relative @@ -387,4 +475,14 @@ void Compiler::Comp_AddCycles_CI(u32 i) ConstantCycles += cycles; } +void Compiler::Comp_AddCycles_CI(Gen::X64Reg i, int add) +{ + s32 cycles = Num ? + NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2] + : ((R15 & 0x2) ? 0 : CurInstr.CodeCycles); + + LEA(32, RSCRATCH, MDisp(i, add + cycles)); + ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(RSCRATCH)); +} + } \ No newline at end of file diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index 45b488a..89dfe28 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -40,6 +40,7 @@ private: void Comp_AddCycles_C(bool forceNonConstant = false); void Comp_AddCycles_CI(u32 i); + void Comp_AddCycles_CI(Gen::X64Reg i, int add); enum { @@ -55,6 +56,10 @@ private: void A_Comp_MovOp(); void A_Comp_CmpOp(); + void A_Comp_MUL_MLA(); + + void A_Comp_CLZ(); + void A_Comp_MemWB(); void A_Comp_MemHalf(); void A_Comp_LDM_STM(); @@ -62,11 +67,13 @@ private: void A_Comp_BranchImm(); void A_Comp_BranchXchangeReg(); + void T_Comp_ShiftImm(); void T_Comp_AddSub_(); void T_Comp_ALU_Imm8(); void T_Comp_ALU(); void T_Comp_ALU_HiReg(); + void T_Comp_MUL(); void T_Comp_RelAddr(); void T_Comp_AddSP(); @@ -88,7 +95,7 @@ private: void T_Comp_BL_Merged(FetchedInstr prefix); void Comp_MemAccess(Gen::OpArg rd, bool signExtend, bool store, int size); - s32 Comp_MemAccessBlock(Gen::OpArg rb, BitSet16 regs, bool store, bool preinc, bool decrement, bool usermode); + s32 Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc, bool decrement, bool usermode); void Comp_ArithTriOp(void (Compiler::*op)(int, const Gen::OpArg&, const Gen::OpArg&), Gen::OpArg rd, Gen::OpArg rn, Gen::OpArg op2, bool carryUsed, int opFlags); @@ -96,6 +103,8 @@ private: Gen::OpArg rd, Gen::OpArg rn, Gen::OpArg op2, bool carryUsed, int opFlags); void Comp_CmpOp(int op, Gen::OpArg rn, Gen::OpArg op2, bool carryUsed); + void Comp_MulOp(bool S, bool add, Gen::OpArg rd, Gen::OpArg rm, Gen::OpArg rs, Gen::OpArg rn); + void Comp_RetriveFlags(bool sign, bool retriveCV, bool carryUsed); void* Gen_MemoryRoutine9(bool store, int size); @@ -133,6 +142,9 @@ private: void* MemoryFuncsSeq9[2][2]; void* MemoryFuncsSeq7[2][2][2]; + void* ReadBanked; + void* WriteBanked; + bool CPSRDirty = false; FetchedInstr CurInstr; diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index 69b324c..8fbcafd 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -1,7 +1,5 @@ #include "ARMJIT_Compiler.h" -#include "../GPU.h" -#include "../Wifi.h" using namespace Gen; @@ -362,7 +360,7 @@ void* Compiler::Gen_MemoryRoutineSeq9(bool store, bool preinc) CMP(32, R(ABI_PARAM3), Imm8(1)); FixupBranch skipSequential = J_CC(CC_E); SUB(32, R(ABI_PARAM3), Imm8(1)); - IMUL(32, R(ABI_PARAM3)); + IMUL(32, RSCRATCH, R(ABI_PARAM3)); ADD(32, R(ABI_PARAM2), R(RSCRATCH)); SetJumpTarget(skipSequential); @@ -413,10 +411,11 @@ void* Compiler::Gen_MemoryRoutineSeq7(bool store, bool preinc, bool codeMainRAM) POP(ABI_PARAM4); POP(ABI_PARAM3); + // TODO: optimise this CMP(32, R(ABI_PARAM3), Imm8(1)); FixupBranch skipSequential = J_CC(CC_E); SUB(32, R(ABI_PARAM3), Imm8(1)); - IMUL(32, R(ABI_PARAM3)); + IMUL(32, RSCRATCH, R(ABI_PARAM3)); ADD(32, R(ABI_PARAM2), R(RSCRATCH)); SetJumpTarget(skipSequential); @@ -458,25 +457,35 @@ void Compiler::Comp_MemAccess(OpArg rd, bool signExtend, bool store, int size) } } -s32 Compiler::Comp_MemAccessBlock(OpArg rb, BitSet16 regs, bool store, bool preinc, bool decrement, bool usermode) +void printStuff2(u32 a, u32 b) { + printf("b %x %x\n", a, b); +} + +s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc, bool decrement, bool usermode) +{ + FILE* f; + const u8* start = GetCodePtr(); + int regsCount = regs.Count(); if (decrement) { - MOV_sum(32, ABI_PARAM1, rb, Imm32(-regsCount * 4)); + MOV_sum(32, ABI_PARAM1, MapReg(rn), Imm32(-regsCount * 4)); preinc ^= true; } else - MOV(32, R(ABI_PARAM1), rb); + MOV(32, R(ABI_PARAM1), MapReg(rn)); + + s32 offset = (regsCount * 4) * (decrement ? -1 : 1); - MOV(32, R(ABI_PARAM3), Imm32(regsCount)); - u32 cycles = Num + u32 cycles = Num ? NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2] : (R15 & 0x2 ? 0 : CurInstr.CodeCycles); MOV(32, R(ABI_PARAM4), Imm32(cycles)); if (!store) { + MOV(32, R(ABI_PARAM3), Imm32(regsCount)); SUB(32, R(RSP), regsCount < 16 ? Imm8(regsCount * 8) : Imm32(regsCount * 8)); MOV(64, R(ABI_PARAM2), R(RSP)); @@ -484,20 +493,29 @@ s32 Compiler::Comp_MemAccessBlock(OpArg rb, BitSet16 regs, bool store, bool prei ? MemoryFuncsSeq9[0][preinc] : MemoryFuncsSeq7[0][preinc][CodeRegion == 0x02]); + bool firstUserMode = true; for (int reg = 15; reg >= 0; reg--) { if (regs[reg]) { - /*if (usermode && reg >= 8 && reg < 15) + if (usermode && reg >= 8 && reg < 15) { - MOV(32, R(RSCRATCH2), R(RCPSR)); - AND(32, R(RSCRATCH2), Imm8(0x1F)); - // (RSCRATCH2 - 0x11) * 8 + squeezePointer(userModeOffsets) + (reg - 8), algebra is great! - MOVZX(32, 8, RSCRATCH2, MScaled(RSCRATCH2, SCALE_8, squeezePointer(userModeOffsets) - 0x10 * 8 + (reg - 8))); - POP(RSCRATCH); - MOV(32, MRegSum(RCPU, RSCRATCH2), R(RSCRATCH)); + if (firstUserMode) + { + MOV(32, R(RSCRATCH), R(RCPSR)); + AND(32, R(RSCRATCH), Imm8(0x1F)); + firstUserMode = false; + } + MOV(32, R(ABI_PARAM2), Imm32(reg - 8)); + POP(ABI_PARAM3); + CALL(WriteBanked); + FixupBranch sucessfulWritten = J_CC(CC_NC); + if (RegCache.Mapping[reg] != INVALID_REG && RegCache.DirtyRegs & (1 << reg)) + MOV(32, R(RegCache.Mapping[reg]), R(ABI_PARAM3)); + SaveReg(reg, ABI_PARAM3); + SetJumpTarget(sucessfulWritten); } - else */if (RegCache.Mapping[reg] == INVALID_REG) + else if (RegCache.Mapping[reg] == INVALID_REG) { assert(reg != 15); @@ -516,32 +534,48 @@ s32 Compiler::Comp_MemAccessBlock(OpArg rb, BitSet16 regs, bool store, bool prei if (regs[15]) { if (Num == 1) - OR(32, MapReg(15), Imm8(1)); + { + if (Thumb) + OR(32, MapReg(15), Imm8(1)); + else + AND(32, MapReg(15), Imm8(0xFE)); + } Comp_JumpTo(MapReg(15).GetSimpleReg(), usermode); } } else { + bool firstUserMode = true; for (int reg : regs) { - /*if (usermode && reg >= 8 && reg < 15) + if (usermode && reg >= 8 && reg < 15) { - MOV(32, R(RSCRATCH), R(RCPSR)); - AND(32, R(RSCRATCH), Imm8(0x1F)); - // (RSCRATCH2 - 0x11) * 8 + squeezePointer(userModeOffsets) + (reg - 8), algebra is great! - MOVZX(32, 8, RSCRATCH, MScaled(RSCRATCH, SCALE_8, squeezePointer(userModeOffsets) - 0x10 * 8 + (reg - 8))); - MOV(32, R(RSCRATCH), MRegSum(RCPU, RSCRATCH)); - PUSH(RSCRATCH); + if (firstUserMode) + { + MOV(32, R(RSCRATCH), R(RCPSR)); + AND(32, R(RSCRATCH), Imm8(0x1F)); + firstUserMode = false; + } + if (RegCache.Mapping[reg] == INVALID_REG) + LoadReg(reg, ABI_PARAM3); + else + MOV(32, R(ABI_PARAM3), R(RegCache.Mapping[reg])); + MOV(32, R(ABI_PARAM2), Imm32(reg - 8)); + CALL(ReadBanked); + PUSH(ABI_PARAM3); } - else */if (RegCache.Mapping[reg] == INVALID_REG) + else if (RegCache.Mapping[reg] == INVALID_REG) { LoadReg(reg, RSCRATCH); PUSH(RSCRATCH); } else + { PUSH(MapReg(reg).GetSimpleReg()); + } } MOV(64, R(ABI_PARAM2), R(RSP)); + MOV(32, R(ABI_PARAM3), Imm32(regsCount)); CALL(Num == 0 ? MemoryFuncsSeq9[1][preinc] @@ -550,7 +584,14 @@ s32 Compiler::Comp_MemAccessBlock(OpArg rb, BitSet16 regs, bool store, bool prei ADD(32, R(RSP), regsCount < 16 ? Imm8(regsCount * 8) : Imm32(regsCount * 8)); } - return (regsCount * 4) * (decrement ? -1 : 1); + if (usermode && !store) + { + f= fopen("ldm", "a"); + fwrite(start, GetCodePtr() - start, 1, f); + fclose(f); + } + + return offset; } OpArg Compiler::A_Comp_GetMemWBOffset() @@ -697,16 +738,20 @@ void Compiler::A_Comp_LDM_STM() { BitSet16 regs(CurInstr.Instr & 0xFFFF); - bool load = (CurInstr.Instr >> 20) & 1; - bool pre = (CurInstr.Instr >> 24) & 1; - bool add = (CurInstr.Instr >> 23) & 1; - bool writeback = (CurInstr.Instr >> 21) & 1; - bool usermode = (CurInstr.Instr >> 22) & 1; + bool load = CurInstr.Instr & (1 << 20); + bool pre = CurInstr.Instr & (1 << 24); + bool add = CurInstr.Instr & (1 << 23); + bool writeback = CurInstr.Instr & (1 << 21); + bool usermode = CurInstr.Instr & (1 << 22); OpArg rn = MapReg(CurInstr.A_Reg(16)); - s32 offset = Comp_MemAccessBlock(rn, regs, !load, pre, !add, false); + s32 offset = Comp_MemAccessBlock(CurInstr.A_Reg(16), regs, !load, pre, !add, usermode); + if (load && writeback && regs[CurInstr.A_Reg(16)]) + writeback = Num == 0 + ? (!(regs & ~BitSet16(1 << CurInstr.A_Reg(16)))) || (regs & ~BitSet16((2 << CurInstr.A_Reg(16)) - 1)) + : false; if (writeback) ADD(32, rn, offset >= INT8_MIN && offset < INT8_MAX ? Imm8(offset) : Imm32(offset)); } @@ -789,8 +834,7 @@ void Compiler::T_Comp_PUSH_POP() } OpArg sp = MapReg(13); - - s32 offset = Comp_MemAccessBlock(sp, regs, !load, !load, !load, false); + s32 offset = Comp_MemAccessBlock(13, regs, !load, !load, !load, false); ADD(32, sp, Imm8(offset)); // offset will be always be in range since PUSH accesses 9 regs max } @@ -801,7 +845,7 @@ void Compiler::T_Comp_LDMIA_STMIA() OpArg rb = MapReg(CurInstr.T_Reg(8)); bool load = CurInstr.Instr & (1 << 11); - s32 offset = Comp_MemAccessBlock(rb, regs, !load, false, false, false); + s32 offset = Comp_MemAccessBlock(CurInstr.T_Reg(8), regs, !load, false, false, false); if (!load || !regs[CurInstr.T_Reg(8)]) ADD(32, rb, Imm8(offset)); -- cgit v1.2.3 From 9336fcbbe66be0b65f036f26899e413be54c3491 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Fri, 12 Jul 2019 16:42:42 +0200 Subject: jit: SMULL and SMLAL --- src/ARMJIT_x64/ARMJIT_ALU.cpp | 56 ++++++++++++++++++++++++++++++++++++-- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 2 +- src/ARMJIT_x64/ARMJIT_Compiler.h | 1 + 3 files changed, 55 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ARMJIT_x64/ARMJIT_ALU.cpp b/src/ARMJIT_x64/ARMJIT_ALU.cpp index cbe67fd..4afafed 100644 --- a/src/ARMJIT_x64/ARMJIT_ALU.cpp +++ b/src/ARMJIT_x64/ARMJIT_ALU.cpp @@ -290,6 +290,59 @@ void Compiler::A_Comp_MUL_MLA() Comp_MulOp(S, add, rd, rm, rs, rn); } +void Compiler::A_Comp_SMULL_SMLAL() +{ + bool S = CurInstr.Instr & (1 << 20); + bool add = CurInstr.Instr & (1 << 21); + OpArg rd = MapReg(CurInstr.A_Reg(16)); + OpArg rm = MapReg(CurInstr.A_Reg(0)); + OpArg rs = MapReg(CurInstr.A_Reg(8)); + OpArg rn = MapReg(CurInstr.A_Reg(12)); + + if (Num == 0) + Comp_AddCycles_CI(S ? 3 : 1); + else + { + XOR(32, R(RSCRATCH), R(RSCRATCH)); + MOV(32, R(RSCRATCH3), rs); + TEST(32, R(RSCRATCH3), R(RSCRATCH3)); + FixupBranch zeroBSR = J_CC(CC_Z); + BSR(32, RSCRATCH2, R(RSCRATCH3)); + NOT(32, R(RSCRATCH3)); + BSR(32, RSCRATCH, R(RSCRATCH3)); + CMP(32, R(RSCRATCH2), R(RSCRATCH)); + CMOVcc(32, RSCRATCH, R(RSCRATCH2), CC_L); + SHR(32, R(RSCRATCH), Imm8(3)); + SetJumpTarget(zeroBSR); // fortunately that's even right + Comp_AddCycles_CI(RSCRATCH, 2); + } + + MOVSX(64, 32, RSCRATCH2, rm); + MOVSX(64, 32, RSCRATCH3, rs); + if (add) + { + MOV(32, R(RSCRATCH), rd); + SHL(64, R(RSCRATCH), Imm8(32)); + OR(64, R(RSCRATCH), rn); + + IMUL(64, RSCRATCH2, R(RSCRATCH3)); + ADD(64, R(RSCRATCH2), R(RSCRATCH)); + } + else + { + IMUL(64, RSCRATCH2, R(RSCRATCH3)); + if (S) + TEST(64, R(RSCRATCH2), R(RSCRATCH2)); + } + + if (S) + Comp_RetriveFlags(false, false, false); + + MOV(32, rn, R(RSCRATCH2)); + SHR(64, R(RSCRATCH2), Imm8(32)); + MOV(32, rd, R(RSCRATCH2)); +} + void Compiler::Comp_RetriveFlags(bool sign, bool retriveCV, bool carryUsed) { CPSRDirty = true; @@ -302,9 +355,6 @@ void Compiler::Comp_RetriveFlags(bool sign, bool retriveCV, bool carryUsed) LEA(32, RSCRATCH2, MComplex(RSCRATCH, RSCRATCH3, SCALE_2, 0)); } - if (carryUsed == 983298) - printf("etwas ist faul im lande daenemark %x\n", CurInstr.Instr); - SETcc(CC_S, R(RSCRATCH)); SETcc(CC_Z, R(RSCRATCH3)); LEA(32, RSCRATCH, MComplex(RSCRATCH3, RSCRATCH, SCALE_2, 0)); diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index 8a895d1..b6dd529 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -375,7 +375,7 @@ CompileFunc Compiler::GetCompFunc(int kind) // CMN A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, // Mul - A_Comp_MUL_MLA, A_Comp_MUL_MLA, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + A_Comp_MUL_MLA, A_Comp_MUL_MLA, NULL, NULL, NULL, A_Comp_SMULL_SMLAL, NULL, NULL, NULL, NULL, NULL, // ARMv5 stuff A_Comp_CLZ, NULL, NULL, NULL, NULL, // STR diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index 89dfe28..f9bc227 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -57,6 +57,7 @@ private: void A_Comp_CmpOp(); void A_Comp_MUL_MLA(); + void A_Comp_SMULL_SMLAL(); void A_Comp_CLZ(); -- cgit v1.2.3 From 24aff49ae496b2401039b09e120dd0fcbd7b8e9e Mon Sep 17 00:00:00 2001 From: RSDuck Date: Fri, 12 Jul 2019 17:01:10 +0200 Subject: jit: fix wrongly placed const --- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index b6dd529..e043f58 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -328,7 +328,7 @@ CompileFunc Compiler::GetCompFunc(int kind) { // this might look like waste of space, so many repeatitions, but it's invaluable for debugging. // see ARMInstrInfo.h for the order - const CompileFunc A_Comp[ARMInstrInfo::ak_Count] = + CompileFunc const A_Comp[ARMInstrInfo::ak_Count] = { // AND A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, @@ -410,7 +410,7 @@ CompileFunc Compiler::GetCompFunc(int kind) NULL, NULL, NULL, NULL, NULL, NULL, NULL, }; - const CompileFunc T_Comp[ARMInstrInfo::tk_Count] = { + CompileFunc const T_Comp[ARMInstrInfo::tk_Count] = { // Shift imm T_Comp_ShiftImm, T_Comp_ShiftImm, T_Comp_ShiftImm, // Three operand ADD/SUB -- cgit v1.2.3 From 0ff79ea2ad645f85f3a4878be3717ffda44f9cbe Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sun, 14 Jul 2019 02:37:32 +0200 Subject: jit: fix linux --- src/ARMJIT_x64/ARMJIT_ALU.cpp | 48 +++--- src/ARMJIT_x64/ARMJIT_Branch.cpp | 2 +- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 288 +++++++++++++++++++----------------- src/ARMJIT_x64/ARMJIT_Compiler.h | 8 +- src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 15 +- src/dolphin/Log.h | 13 +- src/dolphin/MemoryUtil.cpp | 13 +- 7 files changed, 193 insertions(+), 194 deletions(-) (limited to 'src') diff --git a/src/ARMJIT_x64/ARMJIT_ALU.cpp b/src/ARMJIT_x64/ARMJIT_ALU.cpp index 4afafed..013f54c 100644 --- a/src/ARMJIT_x64/ARMJIT_ALU.cpp +++ b/src/ARMJIT_x64/ARMJIT_ALU.cpp @@ -154,13 +154,13 @@ void Compiler::A_Comp_Arith() switch (op) { case 0x0: // AND - Comp_ArithTriOp(AND, rd, rn, op2, carryUsed, opSymmetric|sFlag); + Comp_ArithTriOp(&Compiler::AND, rd, rn, op2, carryUsed, opSymmetric|sFlag); break; case 0x1: // EOR - Comp_ArithTriOp(XOR, rd, rn, op2, carryUsed, opSymmetric|sFlag); + Comp_ArithTriOp(&Compiler::XOR, rd, rn, op2, carryUsed, opSymmetric|sFlag); break; case 0x2: // SUB - Comp_ArithTriOp(SUB, rd, rn, op2, carryUsed, sFlag|opRetriveCV|opInvertCarry); + Comp_ArithTriOp(&Compiler::SUB, rd, rn, op2, carryUsed, sFlag|opRetriveCV|opInvertCarry); break; case 0x3: // RSB if (op2.IsZero()) @@ -172,25 +172,25 @@ void Compiler::A_Comp_Arith() Comp_RetriveFlags(true, true, false); } else - Comp_ArithTriOpReverse(SUB, rd, rn, op2, carryUsed, sFlag|opRetriveCV|opInvertCarry); + Comp_ArithTriOpReverse(&Compiler::SUB, rd, rn, op2, carryUsed, sFlag|opRetriveCV|opInvertCarry); break; case 0x4: // ADD - Comp_ArithTriOp(ADD, rd, rn, op2, carryUsed, opSymmetric|sFlag|opRetriveCV); + Comp_ArithTriOp(&Compiler::ADD, rd, rn, op2, carryUsed, opSymmetric|sFlag|opRetriveCV); break; case 0x5: // ADC - Comp_ArithTriOp(ADC, rd, rn, op2, carryUsed, opSymmetric|sFlag|opRetriveCV|opSyncCarry); + Comp_ArithTriOp(&Compiler::ADC, rd, rn, op2, carryUsed, opSymmetric|sFlag|opRetriveCV|opSyncCarry); break; case 0x6: // SBC - Comp_ArithTriOp(SBB, rd, rn, op2, carryUsed, opSymmetric|sFlag|opRetriveCV|opSyncCarry|opInvertCarry); + Comp_ArithTriOp(&Compiler::SBB, rd, rn, op2, carryUsed, opSymmetric|sFlag|opRetriveCV|opSyncCarry|opInvertCarry); break; case 0x7: // RSC - Comp_ArithTriOpReverse(SBB, rd, rn, op2, carryUsed, sFlag|opRetriveCV|opInvertCarry|opSyncCarry); + Comp_ArithTriOpReverse(&Compiler::SBB, rd, rn, op2, carryUsed, sFlag|opRetriveCV|opInvertCarry|opSyncCarry); break; case 0xC: // ORR - Comp_ArithTriOp(OR, rd, rn, op2, carryUsed, opSymmetric|sFlag); + Comp_ArithTriOp(&Compiler::OR, rd, rn, op2, carryUsed, opSymmetric|sFlag); break; case 0xE: // BIC - Comp_ArithTriOp(AND, rd, rn, op2, carryUsed, sFlag|opSymmetric|opInvertOp2); + Comp_ArithTriOp(&Compiler::AND, rd, rn, op2, carryUsed, sFlag|opSymmetric|opInvertOp2); break; default: assert("unimplemented"); @@ -392,11 +392,11 @@ OpArg Compiler::Comp_RegShiftReg(int op, Gen::OpArg rs, Gen::OpArg rm, bool S, b { void (Compiler::*shiftOp)(int, const OpArg&, const OpArg&) = NULL; if (op == 0) - shiftOp = SHL; + shiftOp = &Compiler::SHL; else if (op == 1) - shiftOp = SHR; + shiftOp = &Compiler::SHR; else if (op == 2) - shiftOp = SAR; + shiftOp = &Compiler::SAR; CMP(32, R(ECX), Imm8(32)); FixupBranch lt32 = J_CC(CC_L); @@ -539,9 +539,9 @@ void Compiler::T_Comp_AddSub_() Comp_AddCycles_C(); if (op & 1) - Comp_ArithTriOp(SUB, rd, rs, rn, false, opSetsFlags|opInvertCarry|opRetriveCV); + Comp_ArithTriOp(&Compiler::SUB, rd, rs, rn, false, opSetsFlags|opInvertCarry|opRetriveCV); else - Comp_ArithTriOp(ADD, rd, rs, rn, false, opSetsFlags|opSymmetric|opRetriveCV); + Comp_ArithTriOp(&Compiler::ADD, rd, rs, rn, false, opSetsFlags|opSymmetric|opRetriveCV); } void Compiler::T_Comp_ALU_Imm8() @@ -564,10 +564,10 @@ void Compiler::T_Comp_ALU_Imm8() Comp_CmpOp(2, rd, imm, false); return; case 0x2: - Comp_ArithTriOp(ADD, rd, rd, imm, false, opSetsFlags|opSymmetric|opRetriveCV); + Comp_ArithTriOp(&Compiler::ADD, rd, rd, imm, false, opSetsFlags|opSymmetric|opRetriveCV); return; case 0x3: - Comp_ArithTriOp(SUB, rd, rd, imm, false, opSetsFlags|opInvertCarry|opRetriveCV); + Comp_ArithTriOp(&Compiler::SUB, rd, rd, imm, false, opSetsFlags|opInvertCarry|opRetriveCV); return; } } @@ -594,10 +594,10 @@ void Compiler::T_Comp_ALU() switch (op) { case 0x0: // AND - Comp_ArithTriOp(AND, rd, rd, rs, false, opSetsFlags|opSymmetric); + Comp_ArithTriOp(&Compiler::AND, rd, rd, rs, false, opSetsFlags|opSymmetric); return; case 0x1: // EOR - Comp_ArithTriOp(XOR, rd, rd, rs, false, opSetsFlags|opSymmetric); + Comp_ArithTriOp(&Compiler::XOR, rd, rd, rs, false, opSetsFlags|opSymmetric); return; case 0x2: case 0x3: @@ -613,10 +613,10 @@ void Compiler::T_Comp_ALU() } return; case 0x5: // ADC - Comp_ArithTriOp(ADC, rd, rd, rs, false, opSetsFlags|opSymmetric|opSyncCarry|opRetriveCV); + Comp_ArithTriOp(&Compiler::ADC, rd, rd, rs, false, opSetsFlags|opSymmetric|opSyncCarry|opRetriveCV); return; case 0x6: // SBC - Comp_ArithTriOp(SBB, rd, rd, rs, false, opSetsFlags|opSyncCarry|opInvertCarry|opRetriveCV); + Comp_ArithTriOp(&Compiler::SBB, rd, rd, rs, false, opSetsFlags|opSyncCarry|opInvertCarry|opRetriveCV); return; case 0x8: // TST Comp_CmpOp(0, rd, rs, false); @@ -634,10 +634,10 @@ void Compiler::T_Comp_ALU() Comp_CmpOp(3, rd, rs, false); return; case 0xC: // ORR - Comp_ArithTriOp(OR, rd, rd, rs, false, opSetsFlags|opSymmetric); + Comp_ArithTriOp(&Compiler::OR, rd, rd, rs, false, opSetsFlags|opSymmetric); return; case 0xE: // BIC - Comp_ArithTriOp(AND, rd, rd, rs, false, opSetsFlags|opSymmetric|opInvertOp2); + Comp_ArithTriOp(&Compiler::AND, rd, rd, rs, false, opSetsFlags|opSymmetric|opInvertOp2); return; case 0xF: // MVN if (rd != rs) @@ -663,7 +663,7 @@ void Compiler::T_Comp_ALU_HiReg() switch (op) { case 0x0: // ADD - Comp_ArithTriOp(ADD, rdMapped, rdMapped, rs, false, opSymmetric|opRetriveCV); + Comp_ArithTriOp(&Compiler::ADD, rdMapped, rdMapped, rs, false, opSymmetric|opRetriveCV); break; case 0x1: // CMP Comp_CmpOp(2, rdMapped, rs, false); diff --git a/src/ARMJIT_x64/ARMJIT_Branch.cpp b/src/ARMJIT_x64/ARMJIT_Branch.cpp index bd01ffb..05c8ec6 100644 --- a/src/ARMJIT_x64/ARMJIT_Branch.cpp +++ b/src/ARMJIT_x64/ARMJIT_Branch.cpp @@ -118,7 +118,7 @@ void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) if (setupRegion) { - MOV(32, R(ABI_PARAM1), R(RCPU)); + MOV(64, R(ABI_PARAM1), R(RCPU)); MOV(32, R(ABI_PARAM2), Imm32(newPC)); CALL((void*)&ARMv5::SetupCodeMem); } diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index e043f58..2b7ccd2 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -4,6 +4,12 @@ #include +#ifdef _WIN32 +#else +#include +#include +#endif + using namespace Gen; namespace ARMJIT @@ -28,9 +34,34 @@ const int RegisterCache::NativeRegsAvailable = int instructionPopularityARM[ARMInstrInfo::ak_Count]; +/* + We'll repurpose this .bss memory + + */ +u8 CodeMemory[1024 * 1024 * 32]; + Compiler::Compiler() { - AllocCodeSpace(1024 * 1024 * 16); +#ifdef _WIN32 +#else + u64 pagesize = sysconf(_SC_PAGE_SIZE); +#endif + + u8* pageAligned = (u8*)(((u64)CodeMemory & ~(pagesize - 1)) + pagesize); + u64 alignedSize = (((u64)CodeMemory + sizeof(CodeMemory)) & ~(pagesize - 1)) - (u64)pageAligned; + +#ifdef _WIN32 +#else + mprotect(pageAligned, alignedSize, PROT_EXEC | PROT_READ | PROT_WRITE); +#endif + + region = pageAligned; + region_size = alignedSize; + total_region_size = region_size; + + ClearCodeSpace(); + + SetCodePtr(pageAligned); memset(instructionPopularityARM, 0, sizeof(instructionPopularityARM)); @@ -187,6 +218,124 @@ Gen::FixupBranch Compiler::CheckCondition(u32 cond) } } +#define F(x) &Compiler::x +const Compiler::CompileFunc A_Comp[ARMInstrInfo::ak_Count] = +{ + // AND + F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), + F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), + // EOR + F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), + F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), + // SUB + F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), + F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), + // RSB + F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), + F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), + // ADD + F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), + F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), + // ADC + F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), + F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), + // SBC + F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), + F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), + // RSC + F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), + F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), + // ORR + F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), + F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), + // MOV + F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), + F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), + // BIC + F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), + F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), F(A_Comp_Arith), + // MVN + F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), + F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), F(A_Comp_MovOp), + // TST + F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), + // TEQ + F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), + // CMP + F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), + // CMN + F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), + // Mul + F(A_Comp_MUL_MLA), F(A_Comp_MUL_MLA), NULL, NULL, NULL, F(A_Comp_SMULL_SMLAL), NULL, NULL, NULL, NULL, NULL, + // ARMv5 stuff + F(A_Comp_CLZ), NULL, NULL, NULL, NULL, + // STR + F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), + // STRB + F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), + // LDR + F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), + // LDRB + F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), F(A_Comp_MemWB), + // STRH + F(A_Comp_MemHalf), F(A_Comp_MemHalf), F(A_Comp_MemHalf), F(A_Comp_MemHalf), + // LDRD, STRD never used by anything so they stay interpreted (by anything I mean the 5 games I checked) + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + // LDRH + F(A_Comp_MemHalf), F(A_Comp_MemHalf), F(A_Comp_MemHalf), F(A_Comp_MemHalf), + // LDRSB + F(A_Comp_MemHalf), F(A_Comp_MemHalf), F(A_Comp_MemHalf), F(A_Comp_MemHalf), + // LDRSH + F(A_Comp_MemHalf), F(A_Comp_MemHalf), F(A_Comp_MemHalf), F(A_Comp_MemHalf), + // swap + NULL, NULL, + // LDM/STM + F(A_Comp_LDM_STM), F(A_Comp_LDM_STM), + // Branch + F(A_Comp_BranchImm), F(A_Comp_BranchImm), F(A_Comp_BranchImm), F(A_Comp_BranchXchangeReg), F(A_Comp_BranchXchangeReg), + // system stuff + NULL, NULL, NULL, NULL, NULL, NULL, NULL, +}; + +const Compiler::CompileFunc T_Comp[ARMInstrInfo::tk_Count] = { + // Shift imm + F(T_Comp_ShiftImm), F(T_Comp_ShiftImm), F(T_Comp_ShiftImm), + // Three operand ADD/SUB + F(T_Comp_AddSub_), F(T_Comp_AddSub_), F(T_Comp_AddSub_), F(T_Comp_AddSub_), + // 8 bit imm + F(T_Comp_ALU_Imm8), F(T_Comp_ALU_Imm8), F(T_Comp_ALU_Imm8), F(T_Comp_ALU_Imm8), + // general ALU + F(T_Comp_ALU), F(T_Comp_ALU), F(T_Comp_ALU), F(T_Comp_ALU), + F(T_Comp_ALU), F(T_Comp_ALU), F(T_Comp_ALU), F(T_Comp_ALU), + F(T_Comp_ALU), F(T_Comp_ALU), F(T_Comp_ALU), F(T_Comp_ALU), + F(T_Comp_ALU), F(T_Comp_MUL), F(T_Comp_ALU), F(T_Comp_ALU), + // hi reg + F(T_Comp_ALU_HiReg), F(T_Comp_ALU_HiReg), F(T_Comp_ALU_HiReg), + // pc/sp relative + F(T_Comp_RelAddr), F(T_Comp_RelAddr), F(T_Comp_AddSP), + // LDR pcrel + F(T_Comp_LoadPCRel), + // LDR/STR reg offset + F(T_Comp_MemReg), F(T_Comp_MemReg), F(T_Comp_MemReg), F(T_Comp_MemReg), + // LDR/STR sign extended, half + F(T_Comp_MemRegHalf), F(T_Comp_MemRegHalf), F(T_Comp_MemRegHalf), F(T_Comp_MemRegHalf), + // LDR/STR imm offset + F(T_Comp_MemImm), F(T_Comp_MemImm), F(T_Comp_MemImm), F(T_Comp_MemImm), + // LDR/STR half imm offset + F(T_Comp_MemImmHalf), F(T_Comp_MemImmHalf), + // LDR/STR sp rel + F(T_Comp_MemSPRel), F(T_Comp_MemSPRel), + // PUSH/POP + F(T_Comp_PUSH_POP), F(T_Comp_PUSH_POP), + // LDMIA, STMIA + F(T_Comp_LDMIA_STMIA), F(T_Comp_LDMIA_STMIA), + // Branch + F(T_Comp_BCOND), F(T_Comp_BranchXchangeReg), F(T_Comp_BranchXchangeReg), F(T_Comp_B), F(T_Comp_BL_LONG_1), F(T_Comp_BL_LONG_2), + // Unk, SVC + NULL, NULL +}; +#undef F + CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrsCount) { if (IsAlmostFull()) @@ -206,7 +355,7 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs bool mergedThumbBL = false; - ABI_PushRegistersAndAdjustStack({ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS}, 8, 16); + ABI_PushRegistersAndAdjustStack(BitSet32(ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS & ~RSP), 8); MOV(64, R(RCPU), ImmPtr(cpu)); @@ -220,8 +369,10 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs R15 += Thumb ? 2 : 4; CurInstr = instrs[i]; - CompileFunc comp = GetCompFunc(CurInstr.Info.Kind); - + CompileFunc comp = Thumb + ? T_Comp[CurInstr.Info.Kind] + : A_Comp[CurInstr.Info.Kind]; + if (!Thumb) instructionPopularityARM[CurInstr.Info.Kind] += comp == NULL; @@ -318,139 +469,12 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs MOV(32, R(RAX), Imm32(ConstantCycles)); - ABI_PopRegistersAndAdjustStack({ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS}, 8, 16); + ABI_PopRegistersAndAdjustStack(BitSet32(ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS & ~RSP), 8); RET(); return res; } -CompileFunc Compiler::GetCompFunc(int kind) -{ - // this might look like waste of space, so many repeatitions, but it's invaluable for debugging. - // see ARMInstrInfo.h for the order - CompileFunc const A_Comp[ARMInstrInfo::ak_Count] = - { - // AND - A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, - A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, - // EOR - A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, - A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, - // SUB - A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, - A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, - // RSB - A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, - A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, - // ADD - A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, - A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, - // ADC - A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, - A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, - // SBC - A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, - A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, - // RSC - A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, - A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, - // ORR - A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, - A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, - // MOV - A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, - A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, - // BIC - A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, - A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, A_Comp_Arith, - // MVN - A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, - A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, A_Comp_MovOp, - // TST - A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, - // TEQ - A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, - // CMP - A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, - // CMN - A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, A_Comp_CmpOp, - // Mul - A_Comp_MUL_MLA, A_Comp_MUL_MLA, NULL, NULL, NULL, A_Comp_SMULL_SMLAL, NULL, NULL, NULL, NULL, NULL, - // ARMv5 stuff - A_Comp_CLZ, NULL, NULL, NULL, NULL, - // STR - A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, - //NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - // STRB - //NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, - // LDR - //NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, - // LDRB - //NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, A_Comp_MemWB, - // STRH - A_Comp_MemHalf, A_Comp_MemHalf, A_Comp_MemHalf, A_Comp_MemHalf, - // LDRD, STRD never used by anything so they stay interpreted (by anything I mean the 5 games I checked) - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - // LDRH - A_Comp_MemHalf, A_Comp_MemHalf, A_Comp_MemHalf, A_Comp_MemHalf, - // LDRSB - A_Comp_MemHalf, A_Comp_MemHalf, A_Comp_MemHalf, A_Comp_MemHalf, - // LDRSH - A_Comp_MemHalf, A_Comp_MemHalf, A_Comp_MemHalf, A_Comp_MemHalf, - // swap - NULL, NULL, - // LDM/STM - A_Comp_LDM_STM, A_Comp_LDM_STM, - // Branch - A_Comp_BranchImm, A_Comp_BranchImm, A_Comp_BranchImm, A_Comp_BranchXchangeReg, A_Comp_BranchXchangeReg, - // system stuff - NULL, NULL, NULL, NULL, NULL, NULL, NULL, - }; - - CompileFunc const T_Comp[ARMInstrInfo::tk_Count] = { - // Shift imm - T_Comp_ShiftImm, T_Comp_ShiftImm, T_Comp_ShiftImm, - // Three operand ADD/SUB - T_Comp_AddSub_, T_Comp_AddSub_, T_Comp_AddSub_, T_Comp_AddSub_, - // 8 bit imm - T_Comp_ALU_Imm8, T_Comp_ALU_Imm8, T_Comp_ALU_Imm8, T_Comp_ALU_Imm8, - // general ALU - T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, - T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, - T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, T_Comp_ALU, - T_Comp_ALU, T_Comp_MUL, T_Comp_ALU, T_Comp_ALU, - // hi reg - T_Comp_ALU_HiReg, T_Comp_ALU_HiReg, T_Comp_ALU_HiReg, - // pc/sp relative - T_Comp_RelAddr, T_Comp_RelAddr, T_Comp_AddSP, - // LDR pcrel - T_Comp_LoadPCRel, - // LDR/STR reg offset - T_Comp_MemReg, T_Comp_MemReg, T_Comp_MemReg, T_Comp_MemReg, - // LDR/STR sign extended, half - T_Comp_MemRegHalf, T_Comp_MemRegHalf, T_Comp_MemRegHalf, T_Comp_MemRegHalf, - // LDR/STR imm offset - T_Comp_MemImm, T_Comp_MemImm, T_Comp_MemImm, T_Comp_MemImm, - // LDR/STR half imm offset - T_Comp_MemImmHalf, T_Comp_MemImmHalf, - // LDR/STR sp rel - T_Comp_MemSPRel, T_Comp_MemSPRel, - // PUSH/POP - T_Comp_PUSH_POP, T_Comp_PUSH_POP, - // LDMIA, STMIA - T_Comp_LDMIA_STMIA, T_Comp_LDMIA_STMIA, - // Branch - T_Comp_BCOND, T_Comp_BranchXchangeReg, T_Comp_BranchXchangeReg, T_Comp_B, T_Comp_BL_LONG_1, T_Comp_BL_LONG_2, - // Unk, SVC - NULL, NULL - }; - - return Thumb ? T_Comp[kind] : A_Comp[kind]; -} - void Compiler::Comp_AddCycles_C(bool forceNonConstant) { s32 cycles = Num ? diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index f9bc227..e04f96a 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -6,8 +6,6 @@ #include "../ARMJIT.h" #include "../ARMJIT_RegisterCache.h" -#include - namespace ARMJIT { @@ -18,9 +16,6 @@ const Gen::X64Reg RSCRATCH = Gen::EAX; const Gen::X64Reg RSCRATCH2 = Gen::EDX; const Gen::X64Reg RSCRATCH3 = Gen::ECX; -class Compiler; - -typedef void (Compiler::*CompileFunc)(); class Compiler : public Gen::X64CodeBlock { @@ -32,8 +27,7 @@ public: void LoadReg(int reg, Gen::X64Reg nativeReg); void SaveReg(int reg, Gen::X64Reg nativeReg); -private: - CompileFunc GetCompFunc(int kind); + typedef void (Compiler::*CompileFunc)(); void Comp_JumpTo(Gen::X64Reg addr, bool restoreCPSR = false); void Comp_JumpTo(u32 addr, bool forceNonConstantCycles = false); diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index 8fbcafd..15a40f8 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -464,9 +464,6 @@ void printStuff2(u32 a, u32 b) s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc, bool decrement, bool usermode) { - FILE* f; - const u8* start = GetCodePtr(); - int regsCount = regs.Count(); if (decrement) @@ -482,11 +479,12 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc u32 cycles = Num ? NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2] : (R15 & 0x2 ? 0 : CurInstr.CodeCycles); + MOV(32, R(ABI_PARAM4), Imm32(cycles)); if (!store) { MOV(32, R(ABI_PARAM3), Imm32(regsCount)); - SUB(32, R(RSP), regsCount < 16 ? Imm8(regsCount * 8) : Imm32(regsCount * 8)); + SUB(64, R(RSP), regsCount < 16 ? Imm8(regsCount * 8) : Imm32(regsCount * 8)); MOV(64, R(ABI_PARAM2), R(RSP)); CALL(Num == 0 @@ -581,14 +579,7 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc ? MemoryFuncsSeq9[1][preinc] : MemoryFuncsSeq7[1][preinc][CodeRegion == 0x02]); - ADD(32, R(RSP), regsCount < 16 ? Imm8(regsCount * 8) : Imm32(regsCount * 8)); - } - - if (usermode && !store) - { - f= fopen("ldm", "a"); - fwrite(start, GetCodePtr() - start, 1, f); - fclose(f); + ADD(64, R(RSP), regsCount < 16 ? Imm8(regsCount * 8) : Imm32(regsCount * 8)); } return offset; diff --git a/src/dolphin/Log.h b/src/dolphin/Log.h index 21e69a5..a7f4b6a 100644 --- a/src/dolphin/Log.h +++ b/src/dolphin/Log.h @@ -4,12 +4,13 @@ #include -#define PanicAlert(msg) \ - do \ - { \ - printf("%s\n", msg); \ - Crash(); \ - } while (false) +#define PanicAlert(fmt, ...) \ + do \ + { \ + printf(fmt "\n", ## __VA_ARGS__); \ + abort(); \ + } while (false) + #define DYNA_REC 0 diff --git a/src/dolphin/MemoryUtil.cpp b/src/dolphin/MemoryUtil.cpp index 01cb897..7273a8a 100644 --- a/src/dolphin/MemoryUtil.cpp +++ b/src/dolphin/MemoryUtil.cpp @@ -6,15 +6,9 @@ #include #include -#define PanicAlert(fmt, ...) \ - do \ - { \ - printf(fmt "\n", ## __VA_ARGS__); \ - abort(); \ - } while (false) - #include "../types.h" #include "CommonFuncs.h" +#include "Log.h" #ifdef _WIN32 #include @@ -39,8 +33,6 @@ namespace Common void* AllocateExecutableMemory(size_t size) { - printf("c\n"); - #if defined(_WIN32) void* ptr = VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); #else @@ -50,13 +42,10 @@ void* AllocateExecutableMemory(size_t size) if (ptr == MAP_FAILED) ptr = nullptr; #endif - printf("a\n"); if (ptr == nullptr) PanicAlert("Failed to allocate executable memory"); - printf("b\n"); - return ptr; } -- cgit v1.2.3 From d13d625f7363449c3fdc041b0a22005b92c83229 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sun, 14 Jul 2019 04:33:36 +0200 Subject: jit: make everything configurable --- src/ARM.cpp | 127 ++++++++++++++++++++++++++++----- src/ARM.h | 3 + src/ARMJIT.cpp | 21 ++++-- src/ARMJIT.h | 2 +- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 14 ++-- src/ARMJIT_x64/ARMJIT_Compiler.h | 2 + src/Config.cpp | 6 ++ src/Config.h | 3 + src/NDS.cpp | 26 ++++++- src/frontend/qt_sdl/PlatformConfig.cpp | 1 + 10 files changed, 171 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/ARM.cpp b/src/ARM.cpp index baf8468..1cd4bb2 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -532,7 +532,7 @@ void ARMv5::Execute() while (NDS::ARM9Timestamp < NDS::ARM9Target) { - /*if (CPSR & 0x20) // THUMB + if (CPSR & 0x20) // THUMB { // prefetch R[15] += 2; @@ -565,14 +565,8 @@ void ARMv5::Execute() } else AddCycles_C(); - }*/ - - /*if (!ARMJIT::IsMapped(0, R[15] - ((CPSR&0x20)?2:4))) - printf("aaarg ungempappter raum %x\n", R[15]);*/ - - ARMJIT::CompiledBlock block = ARMJIT::LookUpBlock(0, R[15] - ((CPSR&0x20)?2:4)); - Cycles += (block ? block : ARMJIT::CompileBlock(this))(); - + } + // TODO optimize this shit!!! if (Halted) { @@ -597,6 +591,58 @@ void ARMv5::Execute() Halted = 0; } +void ARMv5::ExecuteJIT() +{ + if (Halted) + { + if (Halted == 2) + { + Halted = 0; + } + else if (NDS::HaltInterrupted(0)) + { + Halted = 0; + if (NDS::IME[0] & 0x1) + TriggerIRQ(); + } + else + { + NDS::ARM9Timestamp = NDS::ARM9Target; + return; + } + } + + while (NDS::ARM9Timestamp < NDS::ARM9Target) + { + u32 instrAddr = R[15] - ((CPSR&0x20)?2:4); + if (!ARMJIT::IsMapped(0, instrAddr)) + { + NDS::ARM9Timestamp = NDS::ARM9Target; + printf("ARMv5 PC in non executable region %08X\n", R[15]); + return; + } + + ARMJIT::CompiledBlock block = ARMJIT::LookUpBlock(0, instrAddr); + Cycles += (block ? block : ARMJIT::CompileBlock(this))(); + + if (Halted) + { + if (Halted == 1 && NDS::ARM9Timestamp < NDS::ARM9Target) + { + NDS::ARM9Timestamp = NDS::ARM9Target; + } + break; + } + if (IRQ) TriggerIRQ(); + + NDS::ARM9Timestamp += Cycles; + Cycles = 0; + } + + if (Halted == 2) + Halted = 0; +} + void ARMv4::Execute() { if (Halted) @@ -620,7 +666,7 @@ void ARMv4::Execute() while (NDS::ARM7Timestamp < NDS::ARM7Target) { - /*if (CPSR & 0x20) // THUMB + if (CPSR & 0x20) // THUMB { // prefetch R[15] += 2; @@ -648,13 +694,7 @@ void ARMv4::Execute() } else AddCycles_C(); - }*/ - - /*if (!ARMJIT::IsMapped(1, R[15] - ((CPSR&0x20)?2:4))) - printf("aaarg ungempappter raum %x\n", R[15]);*/ - - ARMJIT::CompiledBlock block = ARMJIT::LookUpBlock(1, R[15] - ((CPSR&0x20)?2:4)); - Cycles += (block ? block : ARMJIT::CompileBlock(this))(); + } // TODO optimize this shit!!! if (Halted) @@ -679,3 +719,56 @@ void ARMv4::Execute() if (Halted == 2) Halted = 0; } + +void ARMv4::ExecuteJIT() +{ + if (Halted) + { + if (Halted == 2) + { + Halted = 0; + } + else if (NDS::HaltInterrupted(1)) + { + Halted = 0; + if (NDS::IME[1] & 0x1) + TriggerIRQ(); + } + else + { + NDS::ARM7Timestamp = NDS::ARM7Target; + return; + } + } + + while (NDS::ARM7Timestamp < NDS::ARM7Target) + { + u32 instrAddr = R[15] - ((CPSR&0x20)?2:4); + if (!ARMJIT::IsMapped(1, instrAddr)) + { + NDS::ARM7Timestamp = NDS::ARM7Target; + printf("ARMv4 PC in non executable region %08X\n", R[15]); + return; + } + ARMJIT::CompiledBlock block = ARMJIT::LookUpBlock(1, instrAddr); + Cycles += (block ? block : ARMJIT::CompileBlock(this))(); + + // TODO optimize this shit!!! + if (Halted) + { + if (Halted == 1 && NDS::ARM7Timestamp < NDS::ARM7Target) + { + NDS::ARM7Timestamp = NDS::ARM7Target; + } + break; + } + + if (IRQ) TriggerIRQ(); + + NDS::ARM7Timestamp += Cycles; + Cycles = 0; + } + + if (Halted == 2) + Halted = 0; +} \ No newline at end of file diff --git a/src/ARM.h b/src/ARM.h index e0832e2..3b01ef3 100644 --- a/src/ARM.h +++ b/src/ARM.h @@ -52,6 +52,7 @@ public: } virtual void Execute() = 0; + virtual void ExecuteJIT() = 0; bool CheckCondition(u32 code) { @@ -159,6 +160,7 @@ public: void DataAbort(); void Execute(); + void ExecuteJIT(); // all code accesses are forced nonseq 32bit u32 CodeRead32(u32 addr, bool branch); @@ -281,6 +283,7 @@ public: void JumpTo(u32 addr, bool restorecpsr = false); void Execute(); + void ExecuteJIT(); u16 CodeRead16(u32 addr) { diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 47b425f..e8e6be0 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -2,6 +2,8 @@ #include +#include "Config.h" + #include "ARMJIT_x64/ARMJIT_Compiler.h" namespace ARMJIT @@ -125,18 +127,21 @@ CompiledBlock CompileBlock(ARM* cpu) { bool thumb = cpu->CPSR & 0x20; - FetchedInstr instrs[12]; + if (Config::JIT_MaxBlockSize < 1) + Config::JIT_MaxBlockSize = 1; + if (Config::JIT_MaxBlockSize > 32) + Config::JIT_MaxBlockSize = 32; + + FetchedInstr instrs[Config::JIT_MaxBlockSize]; int i = 0; - u32 r15Initial = cpu->R[15]; + u32 blockAddr = cpu->R[15] - (thumb ? 2 : 4); u32 r15 = cpu->R[15]; u32 nextInstr[2] = {cpu->NextInstr[0], cpu->NextInstr[1]}; - //printf("block %x %d\n", r15, thumb); do { r15 += thumb ? 2 : 4; instrs[i].Instr = nextInstr[0]; - //printf("%x %x\n", instrs[i].Instr, r15); instrs[i].NextInstr[0] = nextInstr[0] = nextInstr[1]; if (cpu->Num == 0) @@ -166,16 +171,16 @@ CompiledBlock CompileBlock(ARM* cpu) instrs[i].Info = ARMInstrInfo::Decode(thumb, cpu->Num, instrs[i].Instr); i++; - } while(!instrs[i - 1].Info.Branches() && i < 10); + } while(!instrs[i - 1].Info.Branches() && i < Config::JIT_MaxBlockSize); CompiledBlock block = compiler->CompileBlock(cpu, instrs, i); - InsertBlock(cpu->Num, r15Initial - (thumb ? 2 : 4), block); + InsertBlock(cpu->Num, blockAddr, block); return block; } -void ResetBlocks() +void InvalidateBlockCache() { memset(cache.MainRAM, 0, sizeof(cache.MainRAM)); memset(cache.SWRAM, 0, sizeof(cache.SWRAM)); @@ -185,6 +190,8 @@ void ResetBlocks() memset(cache.ARM7_BIOS, 0, sizeof(cache.ARM7_BIOS)); memset(cache.ARM7_WRAM, 0, sizeof(cache.ARM7_WRAM)); memset(cache.ARM7_WVRAM, 0, sizeof(cache.ARM7_WVRAM)); + + compiler->Reset(); } } \ No newline at end of file diff --git a/src/ARMJIT.h b/src/ARMJIT.h index 45bb4ed..004256c 100644 --- a/src/ARMJIT.h +++ b/src/ARMJIT.h @@ -111,7 +111,7 @@ void DeInit(); CompiledBlock CompileBlock(ARM* cpu); -void ResetBlocks(); +void InvalidateBlockCache(); } diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index 2b7ccd2..fe23859 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -336,13 +336,15 @@ const Compiler::CompileFunc T_Comp[ARMInstrInfo::tk_Count] = { }; #undef F +void Compiler::Reset() +{ + SetCodePtr((u8*)ResetStart); +} + CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrsCount) { if (IsAlmostFull()) - { - ResetBlocks(); - SetCodePtr((u8*)ResetStart); - } + InvalidateBlockCache(); CompiledBlock res = (CompiledBlock)GetWritableCodePtr(); @@ -355,7 +357,7 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs bool mergedThumbBL = false; - ABI_PushRegistersAndAdjustStack(BitSet32(ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS & ~RSP), 8); + ABI_PushRegistersAndAdjustStack(BitSet32(ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS & ~BitSet32({RSP})), 8); MOV(64, R(RCPU), ImmPtr(cpu)); @@ -469,7 +471,7 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs MOV(32, R(RAX), Imm32(ConstantCycles)); - ABI_PopRegistersAndAdjustStack(BitSet32(ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS & ~RSP), 8); + ABI_PopRegistersAndAdjustStack(BitSet32(ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS & ~BitSet32({RSP})), 8); RET(); return res; diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index e04f96a..cd58012 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -22,6 +22,8 @@ class Compiler : public Gen::X64CodeBlock public: Compiler(); + void Reset(); + CompiledBlock CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrsCount); void LoadReg(int reg, Gen::X64Reg nativeReg); diff --git a/src/Config.cpp b/src/Config.cpp index 5745f34..5c0892a 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -37,6 +37,9 @@ char DSiBIOS7Path[1024]; char DSiFirmwarePath[1024]; char DSiNANDPath[1024]; +bool JIT_Enable = false; +int JIT_MaxBlockSize = 12; + ConfigEntry ConfigFile[] = { {"BIOS9Path", 1, BIOS9Path, 0, "", 1023}, @@ -48,6 +51,9 @@ ConfigEntry ConfigFile[] = {"DSiFirmwarePath", 1, DSiFirmwarePath, 0, "", 1023}, {"DSiNANDPath", 1, DSiNANDPath, 0, "", 1023}, + {"JIT_Enable", 0, &JIT_Enable, 0, NULL, 0}, + {"JIT_MaxBlockSize", 0, &JIT_MaxBlockSize, 10, NULL, 0}, + {"", -1, NULL, 0, NULL, 0} }; diff --git a/src/Config.h b/src/Config.h index 3947598..9dda157 100644 --- a/src/Config.h +++ b/src/Config.h @@ -51,6 +51,9 @@ extern char DSiBIOS7Path[1024]; extern char DSiFirmwarePath[1024]; extern char DSiNANDPath[1024]; +extern bool JIT_Enable; +extern int JIT_MaxBlockSize; + } #endif // CONFIG_H diff --git a/src/NDS.cpp b/src/NDS.cpp index 4073536..cb85d13 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -566,7 +566,7 @@ void Reset() KeyCnt = 0; RCnt = 0; - ARMJIT::ResetBlocks(); + ARMJIT::InvalidateBlockCache(); NDSCart::Reset(); GBACart::Reset(); @@ -794,6 +794,11 @@ bool DoSavestate(Savestate* file) GPU::SetPowerCnt(PowerControl9); } + if (!file->Saving) + { + ARMJIT::InvalidateBlockCache(); + } + return true; } @@ -884,6 +889,7 @@ void RunSystem(u64 timestamp) } } +template u32 RunFrame() { FrameStartTimestamp = SysTimestamp; @@ -917,7 +923,10 @@ u32 RunFrame() } else { - ARM9->Execute(); + if (EnableJIT) + ARM9->ExecuteJIT(); + else + ARM9->Execute(); } RunTimers(0); @@ -940,7 +949,10 @@ u32 RunFrame() } else { - ARM7->Execute(); + if (EnableJIT) + ARM7->ExecuteJIT(); + else + ARM7->Execute(); } RunTimers(1); @@ -970,6 +982,14 @@ u32 RunFrame() return GPU::TotalScanlines; } +u32 RunFrame() +{ + if (Config::JIT_Enable) + return RunFrame(); + else + return RunFrame(); +} + void Reschedule(u64 target) { if (CurCPU == 0) diff --git a/src/frontend/qt_sdl/PlatformConfig.cpp b/src/frontend/qt_sdl/PlatformConfig.cpp index 06128d7..bfb3f97 100644 --- a/src/frontend/qt_sdl/PlatformConfig.cpp +++ b/src/frontend/qt_sdl/PlatformConfig.cpp @@ -72,6 +72,7 @@ char MicWavPath[1024]; char LastROMFolder[1024]; +bool EnableJIT; ConfigEntry PlatformConfigFile[] = { -- cgit v1.2.3 From fc82ca1a97ce8304bf563ca53187227e505eb54e Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sun, 14 Jul 2019 18:08:42 +0200 Subject: jit: remove unnessary files from dolphin --- src/dolphin/CodeBlock.h | 29 +------- src/dolphin/MemoryUtil.cpp | 182 --------------------------------------------- src/dolphin/MemoryUtil.h | 22 ------ 3 files changed, 1 insertion(+), 232 deletions(-) delete mode 100644 src/dolphin/MemoryUtil.cpp delete mode 100644 src/dolphin/MemoryUtil.h (limited to 'src') diff --git a/src/dolphin/CodeBlock.h b/src/dolphin/CodeBlock.h index 1434297..31a8d93 100644 --- a/src/dolphin/CodeBlock.h +++ b/src/dolphin/CodeBlock.h @@ -49,15 +49,6 @@ public: CodeBlock(CodeBlock&&) = delete; CodeBlock& operator=(CodeBlock&&) = delete; - // Call this before you generate any code. - void AllocCodeSpace(size_t size) - { - region_size = size; - total_region_size = size; - region = static_cast(Common::AllocateExecutableMemory(total_region_size)); - T::SetCodePtr(region); - } - // Always clear code space with breakpoints, so that if someone accidentally executes // uninitialized, it just breaks into the debugger. void ClearCodeSpace() @@ -66,26 +57,8 @@ public: ResetCodePtr(); } - // Call this when shutting down. Don't rely on the destructor, even though it'll do the job. - void FreeCodeSpace() - { - ASSERT(!m_is_child); - Common::FreeMemoryPages(region, total_region_size); - region = nullptr; - region_size = 0; - total_region_size = 0; - for (CodeBlock* child : m_children) - { - child->region = nullptr; - child->region_size = 0; - child->total_region_size = 0; - } - } - bool IsInSpace(const u8* ptr) const { return ptr >= region && ptr < (region + region_size); } - // Cannot currently be undone. Will write protect the entire code region. - // Start over if you need to change the code (call FreeCodeSpace(), AllocCodeSpace()). - void WriteProtect() { Common::WriteProtectMemory(region, region_size, true); } + void ResetCodePtr() { T::SetCodePtr(region); } size_t GetSpaceLeft() const { diff --git a/src/dolphin/MemoryUtil.cpp b/src/dolphin/MemoryUtil.cpp deleted file mode 100644 index 7273a8a..0000000 --- a/src/dolphin/MemoryUtil.cpp +++ /dev/null @@ -1,182 +0,0 @@ -// Copyright 2008 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license_dolphin.txt file included. - -#include -#include -#include - -#include "../types.h" -#include "CommonFuncs.h" -#include "Log.h" - -#ifdef _WIN32 -#include -//#include "Common/StringUtil.h" -#else -#include -#include -#include -#if defined __APPLE__ || defined __FreeBSD__ || defined __OpenBSD__ -#include -#elif defined __HAIKU__ -#include -#else -#include -#endif -#endif - -namespace Common -{ -// This is purposely not a full wrapper for virtualalloc/mmap, but it -// provides exactly the primitive operations that Dolphin needs. - -void* AllocateExecutableMemory(size_t size) -{ -#if defined(_WIN32) - void* ptr = VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); -#else - void* ptr = - mmap(nullptr, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0); - - if (ptr == MAP_FAILED) - ptr = nullptr; -#endif - - if (ptr == nullptr) - PanicAlert("Failed to allocate executable memory"); - - return ptr; -} - -void* AllocateMemoryPages(size_t size) -{ -#ifdef _WIN32 - void* ptr = VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_READWRITE); -#else - void* ptr = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); - - if (ptr == MAP_FAILED) - ptr = nullptr; -#endif - - if (ptr == nullptr) - PanicAlert("Failed to allocate raw memory"); - - return ptr; -} - -void* AllocateAlignedMemory(size_t size, size_t alignment) -{ -#ifdef _WIN32 - void* ptr = _aligned_malloc(size, alignment); -#else - void* ptr = nullptr; - if (posix_memalign(&ptr, alignment, size) != 0) - ERROR_LOG(MEMMAP, "Failed to allocate aligned memory"); -#endif - - if (ptr == nullptr) - PanicAlert("Failed to allocate aligned memory"); - - return ptr; -} - -void FreeMemoryPages(void* ptr, size_t size) -{ - if (ptr) - { -#ifdef _WIN32 - if (!VirtualFree(ptr, 0, MEM_RELEASE)) - PanicAlert("FreeMemoryPages failed!\nVirtualFree: %s", GetLastErrorString().c_str()); -#else - if (munmap(ptr, size) != 0) - PanicAlert("FreeMemoryPages failed!\nmunmap: %s", LastStrerrorString().c_str()); -#endif - } -} - -void FreeAlignedMemory(void* ptr) -{ - if (ptr) - { -#ifdef _WIN32 - _aligned_free(ptr); -#else - free(ptr); -#endif - } -} - -void ReadProtectMemory(void* ptr, size_t size) -{ -#ifdef _WIN32 - DWORD oldValue; - if (!VirtualProtect(ptr, size, PAGE_NOACCESS, &oldValue)) - PanicAlert("ReadProtectMemory failed!\nVirtualProtect: %s", GetLastErrorString().c_str()); -#else - if (mprotect(ptr, size, PROT_NONE) != 0) - PanicAlert("ReadProtectMemory failed!\nmprotect: %s", LastStrerrorString().c_str()); -#endif -} - -void WriteProtectMemory(void* ptr, size_t size, bool allowExecute) -{ -#ifdef _WIN32 - DWORD oldValue; - if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READ : PAGE_READONLY, &oldValue)) - PanicAlert("WriteProtectMemory failed!\nVirtualProtect: %s", GetLastErrorString().c_str()); -#else - if (mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_EXEC) : PROT_READ) != 0) - PanicAlert("WriteProtectMemory failed!\nmprotect: %s", LastStrerrorString().c_str()); -#endif -} - -void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute) -{ -#ifdef _WIN32 - DWORD oldValue; - if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE, &oldValue)) - PanicAlert("UnWriteProtectMemory failed!\nVirtualProtect: %s", GetLastErrorString().c_str()); -#else - if (mprotect(ptr, size, - allowExecute ? (PROT_READ | PROT_WRITE | PROT_EXEC) : PROT_WRITE | PROT_READ) != 0) - { - PanicAlert("UnWriteProtectMemory failed!\nmprotect: %s", LastStrerrorString().c_str()); - } -#endif -} - -size_t MemPhysical() -{ -#ifdef _WIN32 - MEMORYSTATUSEX memInfo; - memInfo.dwLength = sizeof(MEMORYSTATUSEX); - GlobalMemoryStatusEx(&memInfo); - return memInfo.ullTotalPhys; -#elif defined __APPLE__ || defined __FreeBSD__ || defined __OpenBSD__ - int mib[2]; - size_t physical_memory; - mib[0] = CTL_HW; -#ifdef __APPLE__ - mib[1] = HW_MEMSIZE; -#elif defined __FreeBSD__ - mib[1] = HW_REALMEM; -#elif defined __OpenBSD__ - mib[1] = HW_PHYSMEM; -#endif - size_t length = sizeof(size_t); - sysctl(mib, 2, &physical_memory, &length, NULL, 0); - return physical_memory; -#elif defined __HAIKU__ - system_info sysinfo; - get_system_info(&sysinfo); - return static_cast(sysinfo.max_pages * B_PAGE_SIZE); -#else - struct sysinfo memInfo; - sysinfo(&memInfo); - return (size_t)memInfo.totalram * memInfo.mem_unit; -#endif -} - -} // namespace Common diff --git a/src/dolphin/MemoryUtil.h b/src/dolphin/MemoryUtil.h deleted file mode 100644 index 607b7a8..0000000 --- a/src/dolphin/MemoryUtil.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2008 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license_dolphin.txt file included. - -#pragma once - -#include -#include - -namespace Common -{ -void* AllocateExecutableMemory(size_t size); -void* AllocateMemoryPages(size_t size); -void FreeMemoryPages(void* ptr, size_t size); -void* AllocateAlignedMemory(size_t size, size_t alignment); -void FreeAlignedMemory(void* ptr); -void ReadProtectMemory(void* ptr, size_t size); -void WriteProtectMemory(void* ptr, size_t size, bool executable = false); -void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute = false); -size_t MemPhysical(); - -} // namespace Common -- cgit v1.2.3 From 86f2be7260f9a9b51efd7c795c28cdcfda775742 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sun, 14 Jul 2019 19:24:00 +0200 Subject: jit: add compile option --- CMakeLists.txt | 36 ++++++++++++++++++++++ src/ARM.cpp | 13 ++++---- src/ARM.h | 6 ++++ src/ARMJIT_x64/ARMJIT_Compiler.cpp | 61 +++++++++++++++++++++----------------- src/ARMJIT_x64/ARMJIT_Compiler.h | 1 - src/CMakeLists.txt | 25 +++++++++------- src/CP15.cpp | 12 ++++++-- src/Config.cpp | 4 +++ src/Config.h | 2 ++ src/NDS.cpp | 26 ++++++++++++++++ src/dolphin/CodeBlock.h | 3 -- 11 files changed, 136 insertions(+), 53 deletions(-) (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index 885f0dd..1e53c60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,42 @@ if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() +include(CheckSymbolExists) +function(detect_architecture symbol arch) + if (NOT DEFINED ARCHITECTURE) + set(CMAKE_REQUIRED_QUIET 1) + check_symbol_exists("${symbol}" "" ARCHITECTURE_${arch}) + unset(CMAKE_REQUIRED_QUIET) + + # The output variable needs to be unique across invocations otherwise + # CMake's crazy scope rules will keep it defined + if (ARCHITECTURE_${arch}) + set(ARCHITECTURE "${arch}" PARENT_SCOPE) + set(ARCHITECTURE_${arch} 1 PARENT_SCOPE) + add_definitions(-DARCHITECTURE_${arch}=1) + endif() + endif() +endfunction() + +detect_architecture("__x86_64__" x86_64) +detect_architecture("__i386__" x86) +detect_architecture("__arm__" ARM) +detect_architecture("__aarch64__" ARM64) + +if (ARCHITECTURE STREQUAL x86_64) + option(ENABLE_JIT "Enable x64 JIT recompiler" ON) +endif() + +if (ENABLE_JIT) + add_definitions(-DJIT_ENABLED) +endif() + +if (CMAKE_BUILD_TYPE STREQUAL Release) + option(ENABLE_LTO "Enable link-time optimization" ON) +else() + option(ENABLE_LTO "Enable link-time optimization" OFF) +endif() + if (CMAKE_BUILD_TYPE STREQUAL Debug) add_compile_options(-Og) endif() diff --git a/src/ARM.cpp b/src/ARM.cpp index 1cd4bb2..bfe1890 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -81,15 +81,8 @@ ARMv4::ARMv4() : ARM(1) // } -namespace ARMJIT {extern int instructionPopularityARM[ARMInstrInfo::ak_Count];} - void ARM::Reset() { - FILE* blabla = fopen("fhhg", "w"); - for (int i = 0; i < ARMInstrInfo::ak_Count; i++) - fprintf(blabla, "%d -> %dx\n", i, ARMJIT::instructionPopularityARM[i]); - fclose(blabla); - Cycles = 0; Halted = 0; @@ -591,6 +584,7 @@ void ARMv5::Execute() Halted = 0; } +#ifdef JIT_ENABLED void ARMv5::ExecuteJIT() { if (Halted) @@ -642,6 +636,7 @@ void ARMv5::ExecuteJIT() if (Halted == 2) Halted = 0; } +#endif void ARMv4::Execute() { @@ -720,6 +715,7 @@ void ARMv4::Execute() Halted = 0; } +#ifdef JIT_ENABLED void ARMv4::ExecuteJIT() { if (Halted) @@ -771,4 +767,5 @@ void ARMv4::ExecuteJIT() if (Halted == 2) Halted = 0; -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/ARM.h b/src/ARM.h index 3b01ef3..c3e7f44 100644 --- a/src/ARM.h +++ b/src/ARM.h @@ -52,7 +52,9 @@ public: } virtual void Execute() = 0; +#ifdef ENABLE_JIT virtual void ExecuteJIT() = 0; +#endif bool CheckCondition(u32 code) { @@ -160,7 +162,9 @@ public: void DataAbort(); void Execute(); +#ifdef JIT_ENABLED void ExecuteJIT(); +#endif // all code accesses are forced nonseq 32bit u32 CodeRead32(u32 addr, bool branch); @@ -283,7 +287,9 @@ public: void JumpTo(u32 addr, bool restorecpsr = false); void Execute(); +#ifdef JIT_ENABLED void ExecuteJIT(); +#endif u16 CodeRead16(u32 addr) { diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index fe23859..18cb27e 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -4,7 +4,10 @@ #include +#include "../dolphin/CommonFuncs.h" + #ifdef _WIN32 +#include #else #include #include @@ -32,8 +35,6 @@ const int RegisterCache::NativeRegsAvailable = #endif ; -int instructionPopularityARM[ARMInstrInfo::ak_Count]; - /* We'll repurpose this .bss memory @@ -42,29 +43,33 @@ u8 CodeMemory[1024 * 1024 * 32]; Compiler::Compiler() { -#ifdef _WIN32 -#else - u64 pagesize = sysconf(_SC_PAGE_SIZE); -#endif - - u8* pageAligned = (u8*)(((u64)CodeMemory & ~(pagesize - 1)) + pagesize); - u64 alignedSize = (((u64)CodeMemory + sizeof(CodeMemory)) & ~(pagesize - 1)) - (u64)pageAligned; - -#ifdef _WIN32 -#else - mprotect(pageAligned, alignedSize, PROT_EXEC | PROT_READ | PROT_WRITE); -#endif - - region = pageAligned; - region_size = alignedSize; - total_region_size = region_size; + { + #ifdef _WIN32 + SYSTEM_INFO sysInfo; + GetSystemInfo(&sysInfo); + + u64 pageSize = (u64)sysInfo.dwPageSize; + #else + u64 pageSize = sysconf(_SC_PAGE_SIZE); + #endif + + u8* pageAligned = (u8*)(((u64)CodeMemory & ~(pageSize - 1)) + pageSize); + u64 alignedSize = (((u64)CodeMemory + sizeof(CodeMemory)) & ~(pageSize - 1)) - (u64)pageAligned; + + #ifdef _WIN32 + DWORD dummy; + VirtualProtect(pageAligned, alignedSize, PAGE_EXECUTE_READWRITE, &dummy); + #else + mprotect(pageAligned, alignedSize, PROT_EXEC | PROT_READ | PROT_WRITE); + #endif + + region = pageAligned; + region_size = alignedSize; + total_region_size = region_size; + } ClearCodeSpace(); - SetCodePtr(pageAligned); - - memset(instructionPopularityARM, 0, sizeof(instructionPopularityARM)); - for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) @@ -118,7 +123,7 @@ Compiler::Compiler() SetJumpTarget(und); MOV(32, R(ABI_PARAM3), MComplex(RCPU, ABI_PARAM2, SCALE_4, offsetof(ARM, R_UND))); RET(); - } + } { // RSCRATCH mode // ABI_PARAM2 reg n @@ -163,7 +168,10 @@ Compiler::Compiler() RET(); } - ResetStart = (void*)GetWritableCodePtr(); + // move the region forward to prevent overwriting the generated functions + region_size -= GetWritableCodePtr() - region; + total_region_size = region_size; + region = GetWritableCodePtr(); } void Compiler::LoadCPSR() @@ -338,7 +346,7 @@ const Compiler::CompileFunc T_Comp[ARMInstrInfo::tk_Count] = { void Compiler::Reset() { - SetCodePtr((u8*)ResetStart); + ClearCodeSpace(); } CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrsCount) @@ -375,9 +383,6 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs ? T_Comp[CurInstr.Info.Kind] : A_Comp[CurInstr.Info.Kind]; - if (!Thumb) - instructionPopularityARM[CurInstr.Info.Kind] += comp == NULL; - if (comp == NULL || i == instrsCount - 1) { MOV(32, MDisp(RCPU, offsetof(ARM, R[15])), Imm32(R15)); diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index cd58012..0ce7d8d 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -132,7 +132,6 @@ public: return Gen::R(RegCache.Mapping[reg]); } - void* ResetStart; void* MemoryFuncs9[3][2]; void* MemoryFuncs7[3][2][2]; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 75fa42c..bfc0ad9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -49,19 +49,22 @@ add_library(core STATIC WifiAP.cpp tiny-AES-c/aes.c +) - ARMJIT.cpp - ARMJIT_x64/ARMJIT_Compiler.cpp - ARMJIT_x64/ARMJIT_ALU.cpp - ARMJIT_x64/ARMJIT_LoadStore.cpp - ARMJIT_x64/ARMJIT_Branch.cpp +if (ENABLE_JIT) + target_sources(core PRIVATE + ARMJIT.cpp + ARMJIT_x64/ARMJIT_Compiler.cpp + ARMJIT_x64/ARMJIT_ALU.cpp + ARMJIT_x64/ARMJIT_LoadStore.cpp + ARMJIT_x64/ARMJIT_Branch.cpp - dolphin/CommonFuncs.cpp - dolphin/x64ABI.cpp - dolphin/x64CPUDetect.cpp - dolphin/x64Emitter.cpp - dolphin/MemoryUtil.cpp -) + dolphin/CommonFuncs.cpp + dolphin/x64ABI.cpp + dolphin/x64CPUDetect.cpp + dolphin/x64Emitter.cpp + ) +endif() if (WIN32) target_link_libraries(core ole32 comctl32 ws2_32 opengl32) diff --git a/src/CP15.cpp b/src/CP15.cpp index 3e1c08b..5b5f935 100644 --- a/src/CP15.cpp +++ b/src/CP15.cpp @@ -813,7 +813,9 @@ void ARMv5::DataWrite8(u32 addr, u8 val) { DataCycles = 1; *(u8*)&ITCM[addr & 0x7FFF] = val; +#ifdef JIT_ENABLED ARMJIT::cache.ARM9_ITCM[(addr & 0x7FFF) >> 1] = NULL; +#endif return; } if (addr >= DTCMBase && addr < (DTCMBase + DTCMSize)) @@ -835,7 +837,9 @@ void ARMv5::DataWrite16(u32 addr, u16 val) { DataCycles = 1; *(u16*)&ITCM[addr & 0x7FFF] = val; +#ifdef JIT_ENABLED ARMJIT::cache.ARM9_ITCM[(addr & 0x7FFF) >> 1] = NULL; +#endif return; } if (addr >= DTCMBase && addr < (DTCMBase + DTCMSize)) @@ -857,8 +861,10 @@ void ARMv5::DataWrite32(u32 addr, u32 val) { DataCycles = 1; *(u32*)&ITCM[addr & 0x7FFF] = val; +#ifdef JIT_ENABLED ARMJIT::cache.ARM9_ITCM[(addr & 0x7FFF) >> 1] = NULL; ARMJIT::cache.ARM9_ITCM[((addr + 2) & 0x7FFF) >> 1] = NULL; +#endif return; } if (addr >= DTCMBase && addr < (DTCMBase + DTCMSize)) @@ -880,8 +886,10 @@ void ARMv5::DataWrite32S(u32 addr, u32 val) { DataCycles += 1; *(u32*)&ITCM[addr & 0x7FFF] = val; - ARMJIT::cache.ARM9_ITCM[(addr & 0x7FFF) / 2] = NULL; - ARMJIT::cache.ARM9_ITCM[(addr & 0x7FFF) / 2 + 1] = NULL; +#ifdef JIT_ENABLED + ARMJIT::cache.ARM9_ITCM[(addr & 0x7FFF) >> 1] = NULL; + ARMJIT::cache.ARM9_ITCM[((addr & 0x7FFF) >> 1) + 1] = NULL; +#endif return; } if (addr >= DTCMBase && addr < (DTCMBase + DTCMSize)) diff --git a/src/Config.cpp b/src/Config.cpp index 5c0892a..33bab75 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -37,8 +37,10 @@ char DSiBIOS7Path[1024]; char DSiFirmwarePath[1024]; char DSiNANDPath[1024]; +#ifdef JIT_ENABLED bool JIT_Enable = false; int JIT_MaxBlockSize = 12; +#endif ConfigEntry ConfigFile[] = { @@ -51,8 +53,10 @@ ConfigEntry ConfigFile[] = {"DSiFirmwarePath", 1, DSiFirmwarePath, 0, "", 1023}, {"DSiNANDPath", 1, DSiNANDPath, 0, "", 1023}, +#ifdef JIT_ENABLED {"JIT_Enable", 0, &JIT_Enable, 0, NULL, 0}, {"JIT_MaxBlockSize", 0, &JIT_MaxBlockSize, 10, NULL, 0}, +#endif {"", -1, NULL, 0, NULL, 0} }; diff --git a/src/Config.h b/src/Config.h index 9dda157..9296335 100644 --- a/src/Config.h +++ b/src/Config.h @@ -51,8 +51,10 @@ extern char DSiBIOS7Path[1024]; extern char DSiFirmwarePath[1024]; extern char DSiNANDPath[1024]; +#ifdef JIT_ENABLED extern bool JIT_Enable; extern int JIT_MaxBlockSize; +#endif } diff --git a/src/NDS.cpp b/src/NDS.cpp index cb85d13..7636a07 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -169,7 +169,9 @@ bool Init() ARM9 = new ARMv5(); ARM7 = new ARMv4(); +#ifdef JIT_ENABLED ARMJIT::Init(); +#endif DMAs[0] = new DMA(0, 0); DMAs[1] = new DMA(0, 1); @@ -203,7 +205,9 @@ void DeInit() delete ARM9; delete ARM7; +#ifdef JIT_ENABLED ARMJIT::DeInit(); +#endif for (int i = 0; i < 8; i++) delete DMAs[i]; @@ -566,7 +570,9 @@ void Reset() KeyCnt = 0; RCnt = 0; +#ifdef JIT_ENABLED ARMJIT::InvalidateBlockCache(); +#endif NDSCart::Reset(); GBACart::Reset(); @@ -794,10 +800,12 @@ bool DoSavestate(Savestate* file) GPU::SetPowerCnt(PowerControl9); } +#ifdef JIT_ENABLED if (!file->Saving) { ARMJIT::InvalidateBlockCache(); } +#endif return true; } @@ -923,9 +931,11 @@ u32 RunFrame() } else { +#ifdef JIT_ENABLED if (EnableJIT) ARM9->ExecuteJIT(); else +#endif ARM9->Execute(); } @@ -949,9 +959,11 @@ u32 RunFrame() } else { +#ifdef JIT_ENABLED if (EnableJIT) ARM7->ExecuteJIT(); else +#endif ARM7->Execute(); } @@ -984,9 +996,11 @@ u32 RunFrame() u32 RunFrame() { +#ifdef JIT_ENABLED if (Config::JIT_Enable) return RunFrame(); else +#endif return RunFrame(); } @@ -1998,7 +2012,9 @@ u32 ARM9Read32(u32 addr) void ARM9Write8(u32 addr, u8 val) { +#ifdef JIT_ENABLED ARMJIT::Invalidate16(0, addr); +#endif switch (addr & 0xFF000000) { @@ -2050,7 +2066,9 @@ void ARM9Write8(u32 addr, u8 val) void ARM9Write16(u32 addr, u16 val) { +#ifdef JIT_ENABLED ARMJIT::Invalidate16(0, addr); +#endif switch (addr & 0xFF000000) { @@ -2118,7 +2136,9 @@ void ARM9Write16(u32 addr, u16 val) void ARM9Write32(u32 addr, u32 val) { +#ifdef JIT_ENABLED ARMJIT::Invalidate32(0, addr); +#endif switch (addr & 0xFF000000) { @@ -2414,7 +2434,9 @@ u32 ARM7Read32(u32 addr) void ARM7Write8(u32 addr, u8 val) { +#ifdef JIT_ENABLED ARMJIT::Invalidate16(1, addr); +#endif switch (addr & 0xFF800000) { @@ -2475,7 +2497,9 @@ void ARM7Write8(u32 addr, u8 val) void ARM7Write16(u32 addr, u16 val) { +#ifdef JIT_ENABLED ARMJIT::Invalidate16(1, addr); +#endif switch (addr & 0xFF800000) { @@ -2546,7 +2570,9 @@ void ARM7Write16(u32 addr, u16 val) void ARM7Write32(u32 addr, u32 val) { +#ifdef JIT_ENABLED ARMJIT::Invalidate32(1, addr); +#endif switch (addr & 0xFF800000) { diff --git a/src/dolphin/CodeBlock.h b/src/dolphin/CodeBlock.h index 31a8d93..e71cf6d 100644 --- a/src/dolphin/CodeBlock.h +++ b/src/dolphin/CodeBlock.h @@ -9,7 +9,6 @@ #include "Assert.h" #include "../types.h" -#include "MemoryUtil.h" namespace Common { @@ -41,8 +40,6 @@ public: CodeBlock() = default; virtual ~CodeBlock() { - if (region) - FreeCodeSpace(); } CodeBlock(const CodeBlock&) = delete; CodeBlock& operator=(const CodeBlock&) = delete; -- cgit v1.2.3 From dd04cef47ea3e006788e8d10f5e79035e11ca139 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Mon, 15 Jul 2019 19:17:10 +0200 Subject: jit: fix BLX_reg with rn=lr --- src/ARMJIT_x64/ARMJIT_Branch.cpp | 3 ++- src/ARM_InstrInfo.cpp | 3 --- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ARMJIT_x64/ARMJIT_Branch.cpp b/src/ARMJIT_x64/ARMJIT_Branch.cpp index 05c8ec6..1f95a90 100644 --- a/src/ARMJIT_x64/ARMJIT_Branch.cpp +++ b/src/ARMJIT_x64/ARMJIT_Branch.cpp @@ -187,9 +187,10 @@ void Compiler::A_Comp_BranchImm() void Compiler::A_Comp_BranchXchangeReg() { OpArg rn = MapReg(CurInstr.A_Reg(0)); + MOV(32, R(RSCRATCH), rn); if ((CurInstr.Instr & 0xF0) == 0x30) // BLX_reg MOV(32, MapReg(14), Imm32(R15 - 4)); - Comp_JumpTo(rn.GetSimpleReg()); + Comp_JumpTo(RSCRATCH); } void Compiler::T_Comp_BCOND() diff --git a/src/ARM_InstrInfo.cpp b/src/ARM_InstrInfo.cpp index b8dff00..c36d6c1 100644 --- a/src/ARM_InstrInfo.cpp +++ b/src/ARM_InstrInfo.cpp @@ -359,10 +359,7 @@ Info Decode(bool thumb, u32 num, u32 instr) } if (data & A_Link) - { res.DstRegs |= 1 << 14; - res.SrcRegs |= 1 << 15; - } if (res.Kind == ak_LDM) res.DstRegs |= instr & (1 << 15); // this is right -- cgit v1.2.3 From 3167ddcde1b99823e2b2a23f6dd611f3d67f1293 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Mon, 15 Jul 2019 20:34:08 +0200 Subject: jit: LDM/STM keep proper stack alignment --- src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index 15a40f8..ee0a7af 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -480,11 +480,14 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc ? NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2] : (R15 & 0x2 ? 0 : CurInstr.CodeCycles); + // we need to make sure that the stack stays aligned to 16 bytes + u32 stackAlloc = ((regsCount + 1) & ~1) * 8; + MOV(32, R(ABI_PARAM4), Imm32(cycles)); if (!store) { MOV(32, R(ABI_PARAM3), Imm32(regsCount)); - SUB(64, R(RSP), regsCount < 16 ? Imm8(regsCount * 8) : Imm32(regsCount * 8)); + SUB(64, R(RSP), stackAlloc <= INT8_MAX ? Imm8(stackAlloc) : Imm32(stackAlloc)); MOV(64, R(ABI_PARAM2), R(RSP)); CALL(Num == 0 @@ -508,7 +511,7 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc POP(ABI_PARAM3); CALL(WriteBanked); FixupBranch sucessfulWritten = J_CC(CC_NC); - if (RegCache.Mapping[reg] != INVALID_REG && RegCache.DirtyRegs & (1 << reg)) + if (RegCache.Mapping[reg] != INVALID_REG) MOV(32, R(RegCache.Mapping[reg]), R(ABI_PARAM3)); SaveReg(reg, ABI_PARAM3); SetJumpTarget(sucessfulWritten); @@ -529,6 +532,9 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc } } + if (regsCount & 1) + POP(RSCRATCH); + if (regs[15]) { if (Num == 1) @@ -543,6 +549,9 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc } else { + if (regsCount & 1) + PUSH(RSCRATCH); + bool firstUserMode = true; for (int reg : regs) { @@ -572,6 +581,7 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc PUSH(MapReg(reg).GetSimpleReg()); } } + MOV(64, R(ABI_PARAM2), R(RSP)); MOV(32, R(ABI_PARAM3), Imm32(regsCount)); @@ -579,7 +589,7 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc ? MemoryFuncsSeq9[1][preinc] : MemoryFuncsSeq7[1][preinc][CodeRegion == 0x02]); - ADD(64, R(RSP), regsCount < 16 ? Imm8(regsCount * 8) : Imm32(regsCount * 8)); + ADD(64, R(RSP), stackAlloc <= INT8_MAX ? Imm8(stackAlloc) : Imm32(stackAlloc)); } return offset; -- cgit v1.2.3 From 03b321f540f0f546408a85eb0437e66d21befb75 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Wed, 17 Jul 2019 03:18:37 +0200 Subject: jit: fix misc static branch things --- src/ARMJIT_x64/ARMJIT_Branch.cpp | 27 +++++++++++++++++++++++---- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 15 ++++++++++----- src/ARM_InstrInfo.cpp | 11 ++++------- 3 files changed, 37 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/ARMJIT_x64/ARMJIT_Branch.cpp b/src/ARMJIT_x64/ARMJIT_Branch.cpp index 1f95a90..6ae4aad 100644 --- a/src/ARMJIT_x64/ARMJIT_Branch.cpp +++ b/src/ARMJIT_x64/ARMJIT_Branch.cpp @@ -35,6 +35,7 @@ void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) u32 newregion = addr >> 24; u32 regionCodeCycles = cpu9->MemTimings[addr >> 12][0]; + u32 compileTimeCodeCycles = cpu9->RegionCodeCycles; cpu9->RegionCodeCycles = regionCodeCycles; MOV(32, MDisp(RCPU, offsetof(ARMv5, RegionCodeCycles)), Imm32(regionCodeCycles)); @@ -53,7 +54,7 @@ void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) if (addr & 0x2) { nextInstr[0] = cpu9->CodeRead32(addr-2, true) >> 16; - cycles += CurCPU->CodeCycles; + cycles += cpu9->CodeCycles; nextInstr[1] = cpu9->CodeRead32(addr+2, false); cycles += CurCPU->CodeCycles; } @@ -61,7 +62,7 @@ void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) { nextInstr[0] = cpu9->CodeRead32(addr, true); nextInstr[1] = nextInstr[0] >> 16; - cycles += CurCPU->CodeCycles; + cycles += cpu9->CodeCycles; } } else @@ -74,6 +75,10 @@ void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) nextInstr[1] = cpu9->CodeRead32(addr+4, false); cycles += cpu9->CodeCycles; } + + cpu9->RegionCodeCycles = compileTimeCodeCycles; + if (setupRegion) + cpu9->SetupCodeMem(R15); } else { @@ -86,26 +91,40 @@ void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) cpu7->CodeCycles = codeCycles; MOV(32, MDisp(RCPU, offsetof(ARM, CodeRegion)), Imm32(codeRegion)); - MOV(32, MDisp(RCPU, offsetof(ARM, CodeRegion)), Imm32(codeCycles)); + MOV(32, MDisp(RCPU, offsetof(ARM, CodeCycles)), Imm32(codeCycles)); if (addr & 0x1) { addr &= ~0x1; newPC = addr+2; + // this is necessary because ARM7 bios protection + u32 compileTimePC = CurCPU->R[15]; + CurCPU->R[15] = newPC; + nextInstr[0] = ((ARMv4*)CurCPU)->CodeRead16(addr); nextInstr[1] = ((ARMv4*)CurCPU)->CodeRead16(addr+2); cycles += NDS::ARM7MemTimings[codeCycles][0] + NDS::ARM7MemTimings[codeCycles][1]; + + CurCPU->R[15] = compileTimePC; } else { addr &= ~0x3; newPC = addr+4; + u32 compileTimePC = CurCPU->R[15]; + CurCPU->R[15] = newPC; + nextInstr[0] = cpu7->CodeRead32(addr); nextInstr[1] = cpu7->CodeRead32(addr+4); cycles += NDS::ARM7MemTimings[codeCycles][2] + NDS::ARM7MemTimings[codeCycles][3]; + + CurCPU->R[15] = compileTimePC; } + + cpu7->CodeRegion = R15 >> 24; + cpu7->CodeCycles = addr >> 15; } MOV(32, MDisp(RCPU, offsetof(ARM, R[15])), Imm32(newPC)); @@ -204,7 +223,7 @@ void Compiler::T_Comp_BCOND() FixupBranch skipFailed = J(); SetJumpTarget(skipExecute); Comp_AddCycles_C(true); - SetJumpTarget(skipFailed); + SetJumpTarget(skipFailed); } void Compiler::T_Comp_B() diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index 18cb27e..1e871fd 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -354,8 +354,6 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs if (IsAlmostFull()) InvalidateBlockCache(); - CompiledBlock res = (CompiledBlock)GetWritableCodePtr(); - ConstantCycles = 0; Thumb = cpu->CPSR & 0x20; Num = cpu->Num; @@ -363,6 +361,13 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs CodeRegion = cpu->CodeRegion; CurCPU = cpu; + CompiledBlock res = (CompiledBlock)GetWritableCodePtr(); + + if (!IsMapped(Num, R15 - Thumb ? 2 : 4)) + { + printf("Trying to compile a block in unmapped memory\n"); + } + bool mergedThumbBL = false; ABI_PushRegistersAndAdjustStack(BitSet32(ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS & ~BitSet32({RSP})), 8); @@ -383,7 +388,8 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs ? T_Comp[CurInstr.Info.Kind] : A_Comp[CurInstr.Info.Kind]; - if (comp == NULL || i == instrsCount - 1) + bool isConditional = Thumb ? CurInstr.Info.Kind == ARMInstrInfo::tk_BCOND : CurInstr.Cond() < 0xE; + if (comp == NULL || (i == instrsCount - 1 && (!CurInstr.Info.Branches() || isConditional))) { MOV(32, MDisp(RCPU, offsetof(ARM, R[15])), Imm32(R15)); MOV(32, MDisp(RCPU, offsetof(ARM, CodeCycles)), Imm32(CurInstr.CodeCycles)); @@ -454,10 +460,9 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs else (this->*comp)(); - FixupBranch skipFailed; if (CurInstr.Cond() < 0xE) { - skipFailed = J(); + FixupBranch skipFailed = J(); SetJumpTarget(skipExecute); Comp_AddCycles_C(); diff --git a/src/ARM_InstrInfo.cpp b/src/ARM_InstrInfo.cpp index c36d6c1..5db2471 100644 --- a/src/ARM_InstrInfo.cpp +++ b/src/ARM_InstrInfo.cpp @@ -178,7 +178,6 @@ enum { T_ReadR13 = 1 << 9, T_WriteR13 = 1 << 10, - T_ReadR15 = 1 << 11, T_BranchAlways = 1 << 12, T_ReadR14 = 1 << 13, @@ -222,7 +221,7 @@ const u32 T_ADD_HIREG = T_WriteHi0 | T_ReadHi0 | T_ReadHi3 | tk(tk_ADD_HIREG); const u32 T_CMP_HIREG = T_ReadHi0 | T_ReadHi3 | tk(tk_CMP_HIREG); const u32 T_MOV_HIREG = T_WriteHi0 | T_ReadHi3 | tk(tk_MOV_HIREG); -const u32 T_ADD_PCREL = T_Write8 | T_ReadR15 | tk(tk_ADD_PCREL); +const u32 T_ADD_PCREL = T_Write8 | tk(tk_ADD_PCREL); const u32 T_ADD_SPREL = T_Write8 | T_ReadR13 | tk(tk_ADD_SPREL); const u32 T_ADD_SP = T_WriteR13 | tk(tk_ADD_SP); @@ -257,11 +256,11 @@ const u32 T_BCOND = T_BranchAlways | tk(tk_BCOND); const u32 T_BX = T_BranchAlways | T_ReadHi3 | tk(tk_BX); const u32 T_BLX_REG = T_BranchAlways | T_WriteR14 | T_ReadHi3 | tk(tk_BLX_REG); const u32 T_B = T_BranchAlways | tk(tk_B); -const u32 T_BL_LONG_1 = T_WriteR14 | T_ReadR15 | tk(tk_BL_LONG_1); -const u32 T_BL_LONG_2 = T_BranchAlways | T_ReadR14 | T_WriteR14 | T_ReadR15 | tk(tk_BL_LONG_2); +const u32 T_BL_LONG_1 = T_WriteR14 | tk(tk_BL_LONG_1); +const u32 T_BL_LONG_2 = T_BranchAlways | T_ReadR14 | T_WriteR14 | tk(tk_BL_LONG_2); const u32 T_UNK = T_BranchAlways | T_WriteR14 | tk(tk_UNK); -const u32 T_SVC = T_BranchAlways | T_WriteR14 | T_ReadR15 | tk(tk_SVC); +const u32 T_SVC = T_BranchAlways | T_WriteR14 | tk(tk_SVC); #define INSTRFUNC_PROTO(x) u32 x #include "ARM_InstrTable.h" @@ -299,8 +298,6 @@ Info Decode(bool thumb, u32 num, u32 instr) res.SrcRegs |= (1 << 13); if (data & T_WriteR13) res.DstRegs |= (1 << 13); - if (data & T_ReadR15) - res.SrcRegs |= (1 << 15); if (data & T_WriteR14) res.DstRegs |= (1 << 14); if (data & T_ReadR14) -- cgit v1.2.3 From 4deecc7d65e61c13d214b46c105dcfb381aacc54 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sun, 21 Jul 2019 13:36:48 +0200 Subject: jit: decrease blockcache AddrMapping size for ARM9 --- src/ARM.cpp | 8 ++--- src/ARMJIT.cpp | 18 ++++++---- src/ARMJIT.h | 67 ++++++++++++++++++++++++++++---------- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 4 ++- src/NDS.cpp | 12 +++---- 5 files changed, 74 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/ARM.cpp b/src/ARM.cpp index bfe1890..dd0be6a 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -609,14 +609,14 @@ void ARMv5::ExecuteJIT() while (NDS::ARM9Timestamp < NDS::ARM9Target) { u32 instrAddr = R[15] - ((CPSR&0x20)?2:4); - if (!ARMJIT::IsMapped(0, instrAddr)) + if (!ARMJIT::IsMapped<0>(instrAddr)) { NDS::ARM9Timestamp = NDS::ARM9Target; printf("ARMv5 PC in non executable region %08X\n", R[15]); return; } - ARMJIT::CompiledBlock block = ARMJIT::LookUpBlock(0, instrAddr); + ARMJIT::CompiledBlock block = ARMJIT::LookUpBlock<0>(instrAddr); Cycles += (block ? block : ARMJIT::CompileBlock(this))(); if (Halted) @@ -740,13 +740,13 @@ void ARMv4::ExecuteJIT() while (NDS::ARM7Timestamp < NDS::ARM7Target) { u32 instrAddr = R[15] - ((CPSR&0x20)?2:4); - if (!ARMJIT::IsMapped(1, instrAddr)) + if (!ARMJIT::IsMapped<1>(instrAddr)) { NDS::ARM7Timestamp = NDS::ARM7Target; printf("ARMv4 PC in non executable region %08X\n", R[15]); return; } - ARMJIT::CompiledBlock block = ARMJIT::LookUpBlock(1, instrAddr); + ARMJIT::CompiledBlock block = ARMJIT::LookUpBlock<1>(instrAddr); Cycles += (block ? block : ARMJIT::CompileBlock(this))(); // TODO optimize this shit!!! diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index e8e6be0..aad14c0 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -109,11 +109,14 @@ void Init() { memset(&cache, 0, sizeof(BlockCache)); - for (int cpu = 0; cpu < 2; cpu++) - for (int i = 0; i < 0x4000; i++) - cache.AddrMapping[cpu][i] = JIT_MEM[cpu][i >> 9] == -1 ? NULL : - (CompiledBlock*)((u8*)&cache + JIT_MEM[cpu][i >> 9]) - + (((i << 14) & JIT_MASK[cpu][i >> 9]) >> 1); + for (int i = 0; i < 0x2000; i++) + cache.AddrMapping9[i] = JIT_MEM[0][i >> 8] == -1 ? NULL : + (CompiledBlock*)((u8*)&cache + JIT_MEM[0][i >> 8]) + + (((i << 15) & JIT_MASK[0][i >> 8]) >> 1); + for (int i = 0; i < 0x4000; i++) + cache.AddrMapping7[i] = JIT_MEM[1][i >> 9] == -1 ? NULL : + (CompiledBlock*)((u8*)&cache + JIT_MEM[1][i >> 9]) + + (((i << 14) & JIT_MASK[1][i >> 9]) >> 1); compiler = new Compiler(); } @@ -175,7 +178,10 @@ CompiledBlock CompileBlock(ARM* cpu) CompiledBlock block = compiler->CompileBlock(cpu, instrs, i); - InsertBlock(cpu->Num, blockAddr, block); + if (cpu->Num == 0) + InsertBlock<0>(blockAddr, block); + else + InsertBlock<1>(blockAddr, block); return block; } diff --git a/src/ARMJIT.h b/src/ARMJIT.h index 004256c..0fc1c38 100644 --- a/src/ARMJIT.h +++ b/src/ARMJIT.h @@ -47,9 +47,11 @@ struct FetchedInstr a function which executes a block instructions starting from there. The most significant 4 bits of each address is ignored. This 28 bit space is - divided into 0x4000 16 KB blocks, each of which a pointer to the relevant - place inside the before mentioned arrays. Only half of the bytes need to be - addressed (ARM address are aligned to 4, Thumb addresses to a 2 byte boundary). + divided into 0x2000 32 KB for ARM9 and 0x4000 16 KB for ARM7, each of which + a pointer to the relevant place inside the afore mentioned arrays. 32 and 16 KB + are the sizes of the smallest contigous memory region mapped to the respective CPU. + Because ARM addresses are always aligned to 4 bytes and Thumb to a 2 byte boundary, + we only need every second half word to be adressable. In case a memory write hits mapped memory, the function block at this address is set to null, so it's recompiled the next time it's executed. @@ -61,7 +63,8 @@ struct FetchedInstr struct BlockCache { - CompiledBlock* AddrMapping[2][0x4000] = {0}; + CompiledBlock* AddrMapping9[0x2000] = {0}; + CompiledBlock* AddrMapping7[0x4000] = {0}; CompiledBlock MainRAM[4*1024*1024/2]; CompiledBlock SWRAM[0x8000/2]; // Shared working RAM @@ -75,35 +78,63 @@ struct BlockCache extern BlockCache cache; -inline bool IsMapped(u32 num, u32 addr) +template +inline bool IsMapped(u32 addr) { - return cache.AddrMapping[num][(addr & 0xFFFFFFF) >> 14]; + if (num == 0) + return cache.AddrMapping9[(addr & 0xFFFFFFF) >> 15]; + else + return cache.AddrMapping7[(addr & 0xFFFFFFF) >> 14]; } -inline CompiledBlock LookUpBlock(u32 num, u32 addr) +template +inline CompiledBlock LookUpBlock(u32 addr) { - return cache.AddrMapping[num][(addr & 0xFFFFFFF) >> 14][(addr & 0x3FFF) >> 1]; + if (num == 0) + return cache.AddrMapping9[(addr & 0xFFFFFFF) >> 15][(addr & 0x7FFF) >> 1]; + else + return cache.AddrMapping7[(addr & 0xFFFFFFF) >> 14][(addr & 0x3FFF) >> 1]; } -inline void Invalidate16(u32 num, u32 addr) +template +inline void Invalidate16(u32 addr) { - if (IsMapped(num, addr)) - cache.AddrMapping[num][(addr & 0xFFFFFFF) >> 14][(addr & 0x3FFF) >> 1] = NULL; + if (IsMapped(addr)) + { + if (num == 0) + cache.AddrMapping9[(addr & 0xFFFFFFF) >> 15][(addr & 0x7FFF) >> 1] = NULL; + else + cache.AddrMapping7[(addr & 0xFFFFFFF) >> 14][(addr & 0x3FFF) >> 1] = NULL; + } } -inline void Invalidate32(u32 num, u32 addr) +template +inline void Invalidate32(u32 addr) { - if (IsMapped(num, addr)) + if (IsMapped(addr)) { - CompiledBlock* page = cache.AddrMapping[num][(addr & 0xFFFFFFF) >> 14]; - page[(addr & 0x3FFF) >> 1] = NULL; - page[((addr + 2) & 0x3FFF) >> 1] = NULL; + if (num == 0) + { + CompiledBlock* page = cache.AddrMapping9[(addr & 0xFFFFFFF) >> 15]; + page[(addr & 0x7FFF) >> 1] = NULL; + page[((addr + 2) & 0x7FFF) >> 1] = NULL; + } + else + { + CompiledBlock* page = cache.AddrMapping7[(addr & 0xFFFFFFF) >> 14]; + page[(addr & 0x3FFF) >> 1] = NULL; + page[((addr + 2) & 0x3FFF) >> 1] = NULL; + } } } -inline void InsertBlock(u32 num, u32 addr, CompiledBlock func) +template +inline void InsertBlock(u32 addr, CompiledBlock func) { - cache.AddrMapping[num][(addr & 0xFFFFFFF) >> 14][(addr & 0x3FFF) >> 1] = func; + if (num == 0) + cache.AddrMapping9[(addr & 0xFFFFFFF) >> 15][(addr & 0x7FFF) >> 1] = func; + else + cache.AddrMapping7[(addr & 0xFFFFFFF) >> 14][(addr & 0x3FFF) >> 1] = func; } void Init(); diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index 1e871fd..cb11f73 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -363,7 +363,9 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs CompiledBlock res = (CompiledBlock)GetWritableCodePtr(); - if (!IsMapped(Num, R15 - Thumb ? 2 : 4)) + if (!(Num == 0 + ? IsMapped<0>(R15 - (Thumb ? 2 : 4)) + : IsMapped<1>(R15 - (Thumb ? 2 : 4)))) { printf("Trying to compile a block in unmapped memory\n"); } diff --git a/src/NDS.cpp b/src/NDS.cpp index 7636a07..3de9c1f 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -2013,7 +2013,7 @@ u32 ARM9Read32(u32 addr) void ARM9Write8(u32 addr, u8 val) { #ifdef JIT_ENABLED - ARMJIT::Invalidate16(0, addr); + ARMJIT::Invalidate16<0>(addr); #endif switch (addr & 0xFF000000) @@ -2067,7 +2067,7 @@ void ARM9Write8(u32 addr, u8 val) void ARM9Write16(u32 addr, u16 val) { #ifdef JIT_ENABLED - ARMJIT::Invalidate16(0, addr); + ARMJIT::Invalidate16<0>(addr); #endif switch (addr & 0xFF000000) @@ -2137,7 +2137,7 @@ void ARM9Write16(u32 addr, u16 val) void ARM9Write32(u32 addr, u32 val) { #ifdef JIT_ENABLED - ARMJIT::Invalidate32(0, addr); + ARMJIT::Invalidate32<0>(addr); #endif switch (addr & 0xFF000000) @@ -2435,7 +2435,7 @@ u32 ARM7Read32(u32 addr) void ARM7Write8(u32 addr, u8 val) { #ifdef JIT_ENABLED - ARMJIT::Invalidate16(1, addr); + ARMJIT::Invalidate16<1>(addr); #endif switch (addr & 0xFF800000) @@ -2498,7 +2498,7 @@ void ARM7Write8(u32 addr, u8 val) void ARM7Write16(u32 addr, u16 val) { #ifdef JIT_ENABLED - ARMJIT::Invalidate16(1, addr); + ARMJIT::Invalidate16<1>(addr); #endif switch (addr & 0xFF800000) @@ -2571,7 +2571,7 @@ void ARM7Write16(u32 addr, u16 val) void ARM7Write32(u32 addr, u32 val) { #ifdef JIT_ENABLED - ARMJIT::Invalidate32(1, addr); + ARMJIT::Invalidate32<1>(addr); #endif switch (addr & 0xFF800000) -- cgit v1.2.3 From d74b15eecc4c5d82703535e0d5c687c3cf225eae Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sun, 21 Jul 2019 17:28:16 +0200 Subject: jit: fix thumb hi reg alu and mcr halt + mcr/mrc aren't always, msr_imm is never unk on ARM7 --- src/ARMJIT.cpp | 2 +- src/ARMJIT_x64/ARMJIT_ALU.cpp | 4 +--- src/ARMJIT_x64/ARMJIT_Branch.cpp | 21 ++++++++++++++------- src/ARM_InstrInfo.cpp | 33 ++++++++++++++++++++++++++++----- src/ARM_InstrInfo.h | 1 + 5 files changed, 45 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index aad14c0..6948eee 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -174,7 +174,7 @@ CompiledBlock CompileBlock(ARM* cpu) instrs[i].Info = ARMInstrInfo::Decode(thumb, cpu->Num, instrs[i].Instr); i++; - } while(!instrs[i - 1].Info.Branches() && i < Config::JIT_MaxBlockSize); + } while(!instrs[i - 1].Info.EndBlock && i < Config::JIT_MaxBlockSize); CompiledBlock block = compiler->CompileBlock(cpu, instrs, i); diff --git a/src/ARMJIT_x64/ARMJIT_ALU.cpp b/src/ARMJIT_x64/ARMJIT_ALU.cpp index 013f54c..bdf06f7 100644 --- a/src/ARMJIT_x64/ARMJIT_ALU.cpp +++ b/src/ARMJIT_x64/ARMJIT_ALU.cpp @@ -663,7 +663,7 @@ void Compiler::T_Comp_ALU_HiReg() switch (op) { case 0x0: // ADD - Comp_ArithTriOp(&Compiler::ADD, rdMapped, rdMapped, rs, false, opSymmetric|opRetriveCV); + Comp_ArithTriOp(&Compiler::ADD, rdMapped, rdMapped, rs, false, opSymmetric); break; case 0x1: // CMP Comp_CmpOp(2, rdMapped, rs, false); @@ -671,8 +671,6 @@ void Compiler::T_Comp_ALU_HiReg() case 0x2: // MOV if (rdMapped != rs) MOV(32, rdMapped, rs); - TEST(32, rdMapped, rdMapped); - Comp_RetriveFlags(false, false, false); break; } diff --git a/src/ARMJIT_x64/ARMJIT_Branch.cpp b/src/ARMJIT_x64/ARMJIT_Branch.cpp index 6ae4aad..9d4c1e2 100644 --- a/src/ARMJIT_x64/ARMJIT_Branch.cpp +++ b/src/ARMJIT_x64/ARMJIT_Branch.cpp @@ -235,16 +235,23 @@ void Compiler::T_Comp_B() void Compiler::T_Comp_BranchXchangeReg() { bool link = CurInstr.Instr & (1 << 7); - if (link && Num == 1) - { - printf("BLX unsupported on ARM7!!!\n"); - return; - } - OpArg rn = MapReg(CurInstr.A_Reg(3)); if (link) + { + if (Num == 1) + { + printf("BLX unsupported on ARM7!!!\n"); + return; + } + MOV(32, R(RSCRATCH), MapReg(CurInstr.A_Reg(3))); MOV(32, MapReg(14), Imm32(R15 - 1)); - Comp_JumpTo(rn.GetSimpleReg()); + Comp_JumpTo(RSCRATCH); + } + else + { + OpArg rn = MapReg(CurInstr.A_Reg(3)); + Comp_JumpTo(rn.GetSimpleReg()); + } } void Compiler::T_Comp_BL_LONG_1() diff --git a/src/ARM_InstrInfo.cpp b/src/ARM_InstrInfo.cpp index 5db2471..b70c8dc 100644 --- a/src/ARM_InstrInfo.cpp +++ b/src/ARM_InstrInfo.cpp @@ -152,11 +152,11 @@ const u32 A_BX = A_BranchAlways | A_Read0 | ak(ak_BX); const u32 A_BLX_REG = A_BranchAlways | A_Link | A_Read0 | ak(ak_BLX_REG); const u32 A_UNK = A_BranchAlways | A_Link | ak(ak_UNK); -const u32 A_MSR_IMM = A_UnkOnARM7 | ak(ak_MSR_IMM); -const u32 A_MSR_REG = A_Read0 | A_UnkOnARM7 | ak(ak_MSR_REG); -const u32 A_MRS = A_Write12 | A_UnkOnARM7 | ak(ak_MRS); -const u32 A_MCR = A_Read12 | A_UnkOnARM7 | ak(ak_MCR); -const u32 A_MRC = A_Write12 | A_UnkOnARM7 | ak(ak_MRC); +const u32 A_MSR_IMM = ak(ak_MSR_IMM); +const u32 A_MSR_REG = A_Read0 | ak(ak_MSR_REG); +const u32 A_MRS = A_Write12 | ak(ak_MRS); +const u32 A_MCR = A_Read12 | ak(ak_MCR); +const u32 A_MRC = A_Write12 | ak(ak_MRC); const u32 A_SVC = A_BranchAlways | A_Link | ak(ak_SVC); // THUMB @@ -310,6 +310,7 @@ Info Decode(bool thumb, u32 num, u32 instr) res.DstRegs |= 1 << 15; res.Kind = (data >> 16) & 0x3F; + res.EndBlock = res.Branches(); return res; } @@ -324,6 +325,26 @@ Info Decode(bool thumb, u32 num, u32 instr) res.Kind = (data >> 13) & 0x1FF; + if (res.Kind == ak_MCR) + { + u32 cn = (instr >> 16) & 0xF; + u32 cm = instr & 0xF; + u32 cpinfo = (instr >> 5) & 0x7; + u32 id = (cn<<8)|(cm<<4)|cpinfo; + if (id == 0x704 || id == 0x782) + res.EndBlock |= true; + } + if (res.Kind == ak_MCR || res.Kind == ak_MRC) + { + u32 cp = ((instr >> 8) & 0xF); + if ((num == 0 && cp != 15) || (num == 1 && cp != 14)) + { + printf("happens\n"); + data = A_UNK; + res.Kind = ak_UNK; + } + } + if (data & A_Read0) res.SrcRegs |= 1 << (instr & 0xF); if (data & A_Read16) @@ -361,6 +382,8 @@ Info Decode(bool thumb, u32 num, u32 instr) if (res.Kind == ak_LDM) res.DstRegs |= instr & (1 << 15); // this is right + res.EndBlock |= res.Branches(); + return res; } } diff --git a/src/ARM_InstrInfo.h b/src/ARM_InstrInfo.h index 51dcfa2..4fe9b10 100644 --- a/src/ARM_InstrInfo.h +++ b/src/ARM_InstrInfo.h @@ -220,6 +220,7 @@ struct Info u16 DstRegs, SrcRegs; u16 Kind; + bool EndBlock; bool Branches() { return DstRegs & (1 << 15); -- cgit v1.2.3 From 00cd9af033cfaffce262dc972170dbec177af3e1 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sun, 21 Jul 2019 23:56:24 +0200 Subject: fix uninitialised memory mapping --- src/ARM.cpp | 1 - src/CP15.cpp | 2 ++ src/NDS.cpp | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ARM.cpp b/src/ARM.cpp index dd0be6a..50ef8fd 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -124,7 +124,6 @@ void ARMv5::Reset() GetMemRegion = NDS::ARM9GetMemRegion; } - CP15Reset(); ARM::Reset(); } diff --git a/src/CP15.cpp b/src/CP15.cpp index 5b5f935..77244f2 100644 --- a/src/CP15.cpp +++ b/src/CP15.cpp @@ -258,9 +258,11 @@ void ARMv5::UpdatePURegions(bool update_all) void ARMv5::UpdateRegionTimings(u32 addrstart, u32 addrend) { + printf("initialising region timings %x %x\n", addrstart, addrend); addrstart >>= 12; addrend >>= 12; + if (addrend == 0xFFFFF) addrend++; for (u32 i = addrstart; i < addrend; i++) diff --git a/src/NDS.cpp b/src/NDS.cpp index 3de9c1f..0bde139 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -501,6 +501,10 @@ void Reset() ARM9ClockShift = 1; MainRAMMask = 0x3FFFFF; } + // has to be called before InitTimings + // otherwise some PU settings are completely + // unitialised on the first run + ARM9->CP15Reset(); ARM9Timestamp = 0; ARM9Target = 0; ARM7Timestamp = 0; ARM7Target = 0; -- cgit v1.2.3 From 0d786573aba04573bb5909b98c4af7a38a750224 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sun, 21 Jul 2019 23:59:02 +0200 Subject: remove debug printf --- src/CP15.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/CP15.cpp b/src/CP15.cpp index 77244f2..5b5f935 100644 --- a/src/CP15.cpp +++ b/src/CP15.cpp @@ -258,11 +258,9 @@ void ARMv5::UpdatePURegions(bool update_all) void ARMv5::UpdateRegionTimings(u32 addrstart, u32 addrend) { - printf("initialising region timings %x %x\n", addrstart, addrend); addrstart >>= 12; addrend >>= 12; - if (addrend == 0xFFFFF) addrend++; for (u32 i = addrstart; i < addrend; i++) -- cgit v1.2.3 From 851930f5e0605f8e6fce1c6b1ce110dfe5d3decd Mon Sep 17 00:00:00 2001 From: RSDuck Date: Mon, 22 Jul 2019 01:04:42 +0200 Subject: jit: fix RSC --- src/ARMJIT_x64/ARMJIT_ALU.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/ARMJIT_x64/ARMJIT_ALU.cpp b/src/ARMJIT_x64/ARMJIT_ALU.cpp index bdf06f7..368fd8b 100644 --- a/src/ARMJIT_x64/ARMJIT_ALU.cpp +++ b/src/ARMJIT_x64/ARMJIT_ALU.cpp @@ -181,7 +181,7 @@ void Compiler::A_Comp_Arith() Comp_ArithTriOp(&Compiler::ADC, rd, rn, op2, carryUsed, opSymmetric|sFlag|opRetriveCV|opSyncCarry); break; case 0x6: // SBC - Comp_ArithTriOp(&Compiler::SBB, rd, rn, op2, carryUsed, opSymmetric|sFlag|opRetriveCV|opSyncCarry|opInvertCarry); + Comp_ArithTriOp(&Compiler::SBB, rd, rn, op2, carryUsed, sFlag|opRetriveCV|opSyncCarry|opInvertCarry); break; case 0x7: // RSC Comp_ArithTriOpReverse(&Compiler::SBB, rd, rn, op2, carryUsed, sFlag|opRetriveCV|opInvertCarry|opSyncCarry); -- cgit v1.2.3 From 86b96ca47a3b08a16ed5ed865b2d1bdb46a6c8cb Mon Sep 17 00:00:00 2001 From: RSDuck Date: Fri, 16 Aug 2019 23:17:08 +0200 Subject: remove unneeded dolphin code, C++11 static_assert --- src/ARMJIT.cpp | 2 + src/ARMJIT_x64/ARMJIT_ALU.cpp | 4 +- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 19 ++++---- src/ARMJIT_x64/ARMJIT_Compiler.h | 5 +- src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 2 +- src/dolphin/Assert.h | 47 ------------------- src/dolphin/CodeBlock.h | 91 ------------------------------------- src/dolphin/Compat.h | 63 +++++++++++++++++++++++++ src/dolphin/Intrinsics.h | 72 ----------------------------- src/dolphin/Log.h | 21 --------- src/dolphin/x64CPUDetect.cpp | 1 - src/dolphin/x64Emitter.cpp | 3 +- src/dolphin/x64Emitter.h | 13 +----- 13 files changed, 84 insertions(+), 259 deletions(-) delete mode 100644 src/dolphin/Assert.h delete mode 100644 src/dolphin/CodeBlock.h create mode 100644 src/dolphin/Compat.h delete mode 100644 src/dolphin/Intrinsics.h delete mode 100644 src/dolphin/Log.h (limited to 'src') diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 6948eee..74554d7 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -188,6 +188,8 @@ CompiledBlock CompileBlock(ARM* cpu) void InvalidateBlockCache() { + printf("Resetting JIT block cache...\n"); + memset(cache.MainRAM, 0, sizeof(cache.MainRAM)); memset(cache.SWRAM, 0, sizeof(cache.SWRAM)); memset(cache.ARM9_BIOS, 0, sizeof(cache.ARM9_BIOS)); diff --git a/src/ARMJIT_x64/ARMJIT_ALU.cpp b/src/ARMJIT_x64/ARMJIT_ALU.cpp index 368fd8b..f0bcf8e 100644 --- a/src/ARMJIT_x64/ARMJIT_ALU.cpp +++ b/src/ARMJIT_x64/ARMJIT_ALU.cpp @@ -257,7 +257,7 @@ void Compiler::Comp_MulOp(bool S, bool add, Gen::OpArg rd, Gen::OpArg rm, Gen::O Comp_AddCycles_CI(RSCRATCH, add ? 2 : 1); } - static_assert(EAX == RSCRATCH); + static_assert(EAX == RSCRATCH, "Someone changed RSCRATCH!"); MOV(32, R(RSCRATCH), rm); if (add) { @@ -383,7 +383,7 @@ OpArg Compiler::Comp_RegShiftReg(int op, Gen::OpArg rs, Gen::OpArg rm, bool S, b } MOV(32, R(RSCRATCH), rm); - static_assert(RSCRATCH3 == ECX); + static_assert(RSCRATCH3 == ECX, "Someone changed RSCRATCH3"); MOV(32, R(ECX), rs); AND(32, R(ECX), Imm32(0xFF)); diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index cb11f73..0fbcfda 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -63,12 +63,11 @@ Compiler::Compiler() mprotect(pageAligned, alignedSize, PROT_EXEC | PROT_READ | PROT_WRITE); #endif - region = pageAligned; - region_size = alignedSize; - total_region_size = region_size; + ResetStart = pageAligned; + CodeMemSize = alignedSize; } - ClearCodeSpace(); + Reset(); for (int i = 0; i < 3; i++) { @@ -169,9 +168,8 @@ Compiler::Compiler() } // move the region forward to prevent overwriting the generated functions - region_size -= GetWritableCodePtr() - region; - total_region_size = region_size; - region = GetWritableCodePtr(); + CodeMemSize -= GetWritableCodePtr() - ResetStart; + ResetStart = GetWritableCodePtr(); } void Compiler::LoadCPSR() @@ -208,7 +206,7 @@ Gen::FixupBranch Compiler::CheckCondition(u32 cond) { if (cond >= 0x8) { - static_assert(RSCRATCH3 == ECX); + static_assert(RSCRATCH3 == ECX, "RSCRATCH has to be equal to ECX!"); MOV(32, R(RSCRATCH3), R(RCPSR)); SHR(32, R(RSCRATCH3), Imm8(28)); MOV(32, R(RSCRATCH), Imm32(1)); @@ -346,12 +344,13 @@ const Compiler::CompileFunc T_Comp[ARMInstrInfo::tk_Count] = { void Compiler::Reset() { - ClearCodeSpace(); + memset(ResetStart, 0xcc, CodeMemSize); + SetCodePtr(ResetStart); } CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrsCount) { - if (IsAlmostFull()) + if (CodeMemSize - (GetWritableCodePtr() - ResetStart) < 1024 * 32) // guess... InvalidateBlockCache(); ConstantCycles = 0; diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index 0ce7d8d..3151cbc 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -17,7 +17,7 @@ const Gen::X64Reg RSCRATCH2 = Gen::EDX; const Gen::X64Reg RSCRATCH3 = Gen::ECX; -class Compiler : public Gen::X64CodeBlock +class Compiler : public Gen::XEmitter { public: Compiler(); @@ -132,6 +132,9 @@ public: return Gen::R(RegCache.Mapping[reg]); } + u8* ResetStart; + u32 CodeMemSize; + void* MemoryFuncs9[3][2]; void* MemoryFuncs7[3][2][2]; diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index ee0a7af..6386f8b 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -171,7 +171,7 @@ void* Compiler::Gen_MemoryRoutine9(bool store, int size) } RET(); - static_assert(RSCRATCH == EAX); + static_assert(RSCRATCH == EAX, "Someone changed RSCRATCH!"); return res; } diff --git a/src/dolphin/Assert.h b/src/dolphin/Assert.h deleted file mode 100644 index 4eb16e0..0000000 --- a/src/dolphin/Assert.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2015 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license_dolphin.txt file included. - -#pragma once - -#include - -#define ASSERT_MSG(_t_, _a_, _fmt_, ...) \ - assert(_a_) \ - /*do \ - { \ - if (!(_a_)) \ - { \ - if (!PanicYesNo(_fmt_, ##__VA_ARGS__)) \ - Crash(); \ - } \ - } while (0)*/ - -#define DEBUG_ASSERT_MSG(_t_, _a_, _msg_, ...) \ - assert(_a_); \ - /*do \ - { \ - if (MAX_LOGLEVEL >= LogTypes::LOG_LEVELS::LDEBUG && !(_a_)) \ - { \ - ERROR_LOG(_t_, _msg_, ##__VA_ARGS__); \ - if (!PanicYesNo(_msg_, ##__VA_ARGS__)) \ - Crash(); \ - } \ - } while (0)*/ - -#define ASSERT(_a_) \ - assert(_a_) \ - /*do \ - { \ - ASSERT_MSG(MASTER_LOG, _a_, \ - _trans("An error occurred.\n\n Line: %d\n File: %s\n\nIgnore and continue?"), \ - __LINE__, __FILE__); \ - } while (0)*/ - -#define DEBUG_ASSERT(_a_) \ - assert(_a_) \ - /*do \ - { \ - if (MAX_LOGLEVEL >= LogTypes::LOG_LEVELS::LDEBUG) \ - ASSERT(_a_); \ - } while (0)*/ diff --git a/src/dolphin/CodeBlock.h b/src/dolphin/CodeBlock.h deleted file mode 100644 index e71cf6d..0000000 --- a/src/dolphin/CodeBlock.h +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2014 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license_dolphin.txt file included. - -#pragma once - -#include -#include - -#include "Assert.h" -#include "../types.h" - -namespace Common -{ -// Everything that needs to generate code should inherit from this. -// You get memory management for free, plus, you can use all emitter functions without -// having to prefix them with gen-> or something similar. -// Example implementation: -// class JIT : public CodeBlock {} -template -class CodeBlock : public T -{ -private: - // A privately used function to set the executable RAM space to something invalid. - // For debugging usefulness it should be used to set the RAM to a host specific breakpoint - // instruction - virtual void PoisonMemory() = 0; - -protected: - u8* region = nullptr; - // Size of region we can use. - size_t region_size = 0; - // Original size of the region we allocated. - size_t total_region_size = 0; - - bool m_is_child = false; - std::vector m_children; - -public: - CodeBlock() = default; - virtual ~CodeBlock() - { - } - CodeBlock(const CodeBlock&) = delete; - CodeBlock& operator=(const CodeBlock&) = delete; - CodeBlock(CodeBlock&&) = delete; - CodeBlock& operator=(CodeBlock&&) = delete; - - // Always clear code space with breakpoints, so that if someone accidentally executes - // uninitialized, it just breaks into the debugger. - void ClearCodeSpace() - { - PoisonMemory(); - ResetCodePtr(); - } - - bool IsInSpace(const u8* ptr) const { return ptr >= region && ptr < (region + region_size); } - - void ResetCodePtr() { T::SetCodePtr(region); } - size_t GetSpaceLeft() const - { - ASSERT(static_cast(T::GetCodePtr() - region) < region_size); - return region_size - (T::GetCodePtr() - region); - } - - bool IsAlmostFull() const - { - // This should be bigger than the biggest block ever. - return GetSpaceLeft() < 0x10000; - } - - bool HasChildren() const { return region_size != total_region_size; } - u8* AllocChildCodeSpace(size_t child_size) - { - ASSERT_MSG(DYNA_REC, child_size < GetSpaceLeft(), "Insufficient space for child allocation."); - u8* child_region = region + region_size - child_size; - region_size -= child_size; - return child_region; - } - void AddChildCodeSpace(CodeBlock* child, size_t child_size) - { - u8* child_region = AllocChildCodeSpace(child_size); - child->m_is_child = true; - child->region = child_region; - child->region_size = child_size; - child->total_region_size = child_size; - child->ResetCodePtr(); - m_children.emplace_back(child); - } -}; -} // namespace Common diff --git a/src/dolphin/Compat.h b/src/dolphin/Compat.h new file mode 100644 index 0000000..f2f52a5 --- /dev/null +++ b/src/dolphin/Compat.h @@ -0,0 +1,63 @@ +// Stubs for Assert.h and Log.h +#pragma once + +#include + +// Assert stub +#define ASSERT_MSG(_t_, _a_, _fmt_, ...) \ + assert(_a_) \ + /*do \ + { \ + if (!(_a_)) \ + { \ + if (!PanicYesNo(_fmt_, ##__VA_ARGS__)) \ + Crash(); \ + } \ + } while (0)*/ + +#define DEBUG_ASSERT_MSG(_t_, _a_, _msg_, ...) \ + assert(_a_); \ + /*do \ + { \ + if (MAX_LOGLEVEL >= LogTypes::LOG_LEVELS::LDEBUG && !(_a_)) \ + { \ + ERROR_LOG(_t_, _msg_, ##__VA_ARGS__); \ + if (!PanicYesNo(_msg_, ##__VA_ARGS__)) \ + Crash(); \ + } \ + } while (0)*/ + +#define ASSERT(_a_) \ + assert(_a_) \ + /*do \ + { \ + ASSERT_MSG(MASTER_LOG, _a_, \ + _trans("An error occurred.\n\n Line: %d\n File: %s\n\nIgnore and continue?"), \ + __LINE__, __FILE__); \ + } while (0)*/ + +#define DEBUG_ASSERT(_a_) \ + assert(_a_) \ + /*do \ + { \ + if (MAX_LOGLEVEL >= LogTypes::LOG_LEVELS::LDEBUG) \ + ASSERT(_a_); \ + } while (0)*/ + +// Log Stub +#include + +#define PanicAlert(fmt, ...) \ + do \ + { \ + printf(fmt "\n", ## __VA_ARGS__); \ + abort(); \ + } while (false) + +#define DYNA_REC 0 + +#define ERROR_LOG(which, fmt, ...) \ + do \ + { \ + printf(fmt "\n", ## __VA_ARGS__); \ + } while (false) diff --git a/src/dolphin/Intrinsics.h b/src/dolphin/Intrinsics.h deleted file mode 100644 index 483f219..0000000 --- a/src/dolphin/Intrinsics.h +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2015 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license_dolphin.txt file included. - -#pragma once - -#if defined(_M_X86) - -/** - * It is assumed that all compilers used to build Dolphin support intrinsics up to and including - * SSE 4.2 on x86/x64. - */ - -#if defined(__GNUC__) || defined(__clang__) - -/** - * Due to limitations in GCC, SSE intrinsics are only available when compiling with the - * corresponding instruction set enabled. However, using the target attribute, we can compile - * single functions with a different target instruction set, while still creating a generic build. - * - * Since this instruction set is enabled per-function, any callers should verify that the - * instruction set is supported at runtime before calling it, and provide a fallback implementation - * when not supported. - * - * When building with -march=native, or enabling the instruction sets in the compile flags, permit - * usage of the instrinsics without any function attributes. If the command-line architecture does - * not support this instruction set, enable it via function targeting. - */ - -#include -#ifndef __SSE4_2__ -#define FUNCTION_TARGET_SSE42 [[gnu::target("sse4.2")]] -#endif -#ifndef __SSE4_1__ -#define FUNCTION_TARGET_SSR41 [[gnu::target("sse4.1")]] -#endif -#ifndef __SSSE3__ -#define FUNCTION_TARGET_SSSE3 [[gnu::target("ssse3")]] -#endif -#ifndef __SSE3__ -#define FUNCTION_TARGET_SSE3 [[gnu::target("sse3")]] -#endif - -#elif defined(_MSC_VER) || defined(__INTEL_COMPILER) - -/** - * MSVC and ICC support intrinsics for any instruction set without any function attributes. - */ -#include - -#endif // defined(_MSC_VER) || defined(__INTEL_COMPILER) - -#endif // _M_X86 - -/** - * Define the FUNCTION_TARGET macros to nothing if they are not needed, or not on an X86 platform. - * This way when a function is defined with FUNCTION_TARGET you don't need to define a second - * version without the macro around a #ifdef guard. Be careful when using intrinsics, as all use - * should still be placed around a #ifdef _M_X86 if the file is compiled on all architectures. - */ -#ifndef FUNCTION_TARGET_SSE42 -#define FUNCTION_TARGET_SSE42 -#endif -#ifndef FUNCTION_TARGET_SSR41 -#define FUNCTION_TARGET_SSR41 -#endif -#ifndef FUNCTION_TARGET_SSSE3 -#define FUNCTION_TARGET_SSSE3 -#endif -#ifndef FUNCTION_TARGET_SSE3 -#define FUNCTION_TARGET_SSE3 -#endif diff --git a/src/dolphin/Log.h b/src/dolphin/Log.h deleted file mode 100644 index a7f4b6a..0000000 --- a/src/dolphin/Log.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "CommonFuncs.h" - -#include - -#define PanicAlert(fmt, ...) \ - do \ - { \ - printf(fmt "\n", ## __VA_ARGS__); \ - abort(); \ - } while (false) - - -#define DYNA_REC 0 - -#define ERROR_LOG(which, fmt, ...) \ - do \ - { \ - printf(fmt "\n", ## __VA_ARGS__); \ - } while (false) diff --git a/src/dolphin/x64CPUDetect.cpp b/src/dolphin/x64CPUDetect.cpp index 05ee11c..49b51c9 100644 --- a/src/dolphin/x64CPUDetect.cpp +++ b/src/dolphin/x64CPUDetect.cpp @@ -7,7 +7,6 @@ #include "CPUDetect.h" #include "../types.h" -#include "Intrinsics.h" #ifndef _MSVC_VER diff --git a/src/dolphin/x64Emitter.cpp b/src/dolphin/x64Emitter.cpp index 7849624..343f314 100644 --- a/src/dolphin/x64Emitter.cpp +++ b/src/dolphin/x64Emitter.cpp @@ -7,9 +7,10 @@ #include "CPUDetect.h" #include "../types.h" -#include "Log.h" #include "x64Emitter.h" #include "x64Reg.h" +#include "Compat.h" +#include "CommonFuncs.h" namespace Gen { diff --git a/src/dolphin/x64Emitter.h b/src/dolphin/x64Emitter.h index 122850d..869acb6 100644 --- a/src/dolphin/x64Emitter.h +++ b/src/dolphin/x64Emitter.h @@ -12,9 +12,8 @@ #include #include -#include "Assert.h" +#include "Compat.h" #include "BitSet.h" -#include "CodeBlock.h" #include "../types.h" #include "x64ABI.h" @@ -1167,14 +1166,4 @@ public: } }; // class XEmitter -class X64CodeBlock : public Common::CodeBlock -{ -private: - void PoisonMemory() override - { - // x86/64: 0xCC = breakpoint - memset(region, 0xCC, region_size); - } -}; - } // namespace -- cgit v1.2.3 From 26ecf6bb3c0fe6dec76433662e69903cc453242b Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sat, 17 Aug 2019 14:58:37 +0200 Subject: fix register alloc for half word loads fixes Mega Man Star Force 2 with cheat applied it probably used a pc relative load which were interpreted as branches --- src/ARM_InstrInfo.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ARM_InstrInfo.cpp b/src/ARM_InstrInfo.cpp index b70c8dc..4813799 100644 --- a/src/ARM_InstrInfo.cpp +++ b/src/ARM_InstrInfo.cpp @@ -127,8 +127,8 @@ A_IMPLEMENT_WB_LDRSTR(LDRB,LDR) #define A_STRD A_Read12Double #define A_IMPLEMENT_HD_LDRSTR(x,k) \ - const u32 A_##x##_IMM = A_##k | A_Read16 | A_Write16 | ak(ak_##x##_IMM); \ - const u32 A_##x##_REG = A_##k | A_Read16 | A_Write16 | A_Read0 | ak(ak_##x##_REG); \ + const u32 A_##x##_IMM = A_##k | A_Read16 | A_MemWriteback | ak(ak_##x##_IMM); \ + const u32 A_##x##_REG = A_##k | A_Read16 | A_MemWriteback | A_Read0 | ak(ak_##x##_REG); \ const u32 A_##x##_POST_IMM = A_##k | A_Read16 | A_Write16 | ak(ak_##x##_POST_IMM); \ const u32 A_##x##_POST_REG = A_##k | A_Read16 | A_Write16 | A_Read0 | ak(ak_##x##_POST_REG); -- cgit v1.2.3 From 316378092ac1791f4ada3b6b81b2681eab14d58d Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sat, 17 Aug 2019 16:50:48 +0200 Subject: abandon pipelining on jit fixes Golden Sun Dawn this makes the cpu state incompatible between interpreter and JIT. That's why switching cpu mode requires a restart(not requiring is stupid anyway) and the pipeline is manually filled when making a save state. --- src/ARM.cpp | 46 ++++++++++++++++++++++++++++++++++++- src/ARM.h | 6 +++++ src/ARMJIT.cpp | 1 + src/ARMJIT_x64/ARMJIT_Branch.cpp | 39 ++++++++++++++----------------- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 5 ---- src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 5 ---- 6 files changed, 69 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/ARM.cpp b/src/ARM.cpp index 50ef8fd..7caef75 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -23,6 +23,7 @@ #include "ARMInterpreter.h" #include "AREngine.h" #include "ARMJIT.h" +#include "Config.h" // instruction timing notes @@ -168,6 +169,13 @@ void ARM::DoSavestate(Savestate* file) file->VarArray(R_IRQ, 3*sizeof(u32)); file->VarArray(R_UND, 3*sizeof(u32)); file->Var32(&CurInstr); + if (!file->Saving && Config::JIT_Enable) + { + // hack, the JIT doesn't really pipeline + // but we still want JIT save states to be + // loaded while running the interpreter + FillPipeline(); + } file->VarArray(NextInstr, 2*sizeof(u32)); file->Var32(&ExceptionBase); @@ -767,4 +775,40 @@ void ARMv4::ExecuteJIT() if (Halted == 2) Halted = 0; } -#endif \ No newline at end of file +#endif + +void ARMv5::FillPipeline() +{ + if (CPSR & 0x20) + { + if ((R[15] - 2) & 0x2) + { + NextInstr[0] = CodeRead32(R[15] - 4, false) >> 16; + NextInstr[1] = CodeRead32(R[15], false); + } + else + { + NextInstr[0] = CodeRead32(R[15] - 2, false); + NextInstr[1] = NextInstr[0] >> 16; + } + } + else + { + NextInstr[0] = CodeRead32(R[15] - 4, false); + NextInstr[1] = CodeRead32(R[15], false); + } +} + +void ARMv4::FillPipeline() +{ + if (CPSR & 0x20) + { + NextInstr[0] = CodeRead16(R[15] - 2); + NextInstr[1] = CodeRead16(R[15]); + } + else + { + NextInstr[0] = CodeRead32(R[15] - 4); + NextInstr[1] = CodeRead32(R[15]); + } +} \ No newline at end of file diff --git a/src/ARM.h b/src/ARM.h index c3e7f44..811b2e0 100644 --- a/src/ARM.h +++ b/src/ARM.h @@ -42,6 +42,8 @@ public: virtual void DoSavestate(Savestate* file); + virtual void FillPipeline() = 0; + virtual void JumpTo(u32 addr, bool restorecpsr = false) = 0; void RestoreCPSR(); @@ -156,6 +158,8 @@ public: void UpdateRegionTimings(u32 addrstart, u32 addrend); + void FillPipeline(); + void JumpTo(u32 addr, bool restorecpsr = false); void PrefetchAbort(); @@ -284,6 +288,8 @@ public: void Reset(); + void FillPipeline(); + void JumpTo(u32 addr, bool restorecpsr = false); void Execute(); diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 74554d7..949bc1c 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -139,6 +139,7 @@ CompiledBlock CompileBlock(ARM* cpu) int i = 0; u32 blockAddr = cpu->R[15] - (thumb ? 2 : 4); u32 r15 = cpu->R[15]; + cpu->FillPipeline(); u32 nextInstr[2] = {cpu->NextInstr[0], cpu->NextInstr[1]}; do { diff --git a/src/ARMJIT_x64/ARMJIT_Branch.cpp b/src/ARMJIT_x64/ARMJIT_Branch.cpp index 9d4c1e2..30b18d7 100644 --- a/src/ARMJIT_x64/ARMJIT_Branch.cpp +++ b/src/ARMJIT_x64/ARMJIT_Branch.cpp @@ -4,6 +4,14 @@ using namespace Gen; namespace ARMJIT { + +template +int squeezePointer(T* ptr) +{ + int truncated = (int)((u64)ptr); + assert((T*)((u64)truncated) == ptr); + return truncated; +} void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) { @@ -12,9 +20,7 @@ void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) // we'll see how it works out u32 newPC; - u32 nextInstr[2]; u32 cycles = 0; - bool setupRegion = false; if (addr & 0x1 && !Thumb) { @@ -40,7 +46,7 @@ void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) MOV(32, MDisp(RCPU, offsetof(ARMv5, RegionCodeCycles)), Imm32(regionCodeCycles)); - setupRegion = newregion != oldregion; + bool setupRegion = newregion != oldregion; if (setupRegion) cpu9->SetupCodeMem(addr); @@ -53,15 +59,14 @@ void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) // doesn't matter if we put garbage in the MSbs there if (addr & 0x2) { - nextInstr[0] = cpu9->CodeRead32(addr-2, true) >> 16; + cpu9->CodeRead32(addr-2, true); cycles += cpu9->CodeCycles; - nextInstr[1] = cpu9->CodeRead32(addr+2, false); + cpu9->CodeRead32(addr+2, false); cycles += CurCPU->CodeCycles; } else { - nextInstr[0] = cpu9->CodeRead32(addr, true); - nextInstr[1] = nextInstr[0] >> 16; + cpu9->CodeRead32(addr, true); cycles += cpu9->CodeCycles; } } @@ -70,12 +75,15 @@ void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) addr &= ~0x3; newPC = addr+4; - nextInstr[0] = cpu9->CodeRead32(addr, true); + cpu9->CodeRead32(addr, true); cycles += cpu9->CodeCycles; - nextInstr[1] = cpu9->CodeRead32(addr+4, false); + cpu9->CodeRead32(addr+4, false); cycles += cpu9->CodeCycles; } + MOV(64, MDisp(RCPU, offsetof(ARM, CodeMem.Mem)), Imm32(squeezePointer(cpu9->CodeMem.Mem))); + MOV(32, MDisp(RCPU, offsetof(ARM, CodeMem.Mask)), Imm32(cpu9->CodeMem.Mask)); + cpu9->RegionCodeCycles = compileTimeCodeCycles; if (setupRegion) cpu9->SetupCodeMem(R15); @@ -102,8 +110,6 @@ void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) u32 compileTimePC = CurCPU->R[15]; CurCPU->R[15] = newPC; - nextInstr[0] = ((ARMv4*)CurCPU)->CodeRead16(addr); - nextInstr[1] = ((ARMv4*)CurCPU)->CodeRead16(addr+2); cycles += NDS::ARM7MemTimings[codeCycles][0] + NDS::ARM7MemTimings[codeCycles][1]; CurCPU->R[15] = compileTimePC; @@ -116,8 +122,6 @@ void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) u32 compileTimePC = CurCPU->R[15]; CurCPU->R[15] = newPC; - nextInstr[0] = cpu7->CodeRead32(addr); - nextInstr[1] = cpu7->CodeRead32(addr+4); cycles += NDS::ARM7MemTimings[codeCycles][2] + NDS::ARM7MemTimings[codeCycles][3]; CurCPU->R[15] = compileTimePC; @@ -128,19 +132,10 @@ void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) } MOV(32, MDisp(RCPU, offsetof(ARM, R[15])), Imm32(newPC)); - MOV(32, MDisp(RCPU, offsetof(ARM, NextInstr[0])), Imm32(nextInstr[0])); - MOV(32, MDisp(RCPU, offsetof(ARM, NextInstr[1])), Imm32(nextInstr[1])); if ((Thumb || CurInstr.Cond() >= 0xE) && !forceNonConstantCycles) ConstantCycles += cycles; else ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm8(cycles)); - - if (setupRegion) - { - MOV(64, R(ABI_PARAM1), R(RCPU)); - MOV(32, R(ABI_PARAM2), Imm32(newPC)); - CALL((void*)&ARMv5::SetupCodeMem); - } } void Compiler::Comp_JumpTo(Gen::X64Reg addr, bool restoreCPSR) diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index 0fbcfda..ab13cb6 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -395,11 +395,6 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs MOV(32, MDisp(RCPU, offsetof(ARM, R[15])), Imm32(R15)); MOV(32, MDisp(RCPU, offsetof(ARM, CodeCycles)), Imm32(CurInstr.CodeCycles)); MOV(32, MDisp(RCPU, offsetof(ARM, CurInstr)), Imm32(CurInstr.Instr)); - if (i == instrsCount - 1) - { - MOV(32, MDisp(RCPU, offsetof(ARM, NextInstr[0])), Imm32(CurInstr.NextInstr[0])); - MOV(32, MDisp(RCPU, offsetof(ARM, NextInstr[1])), Imm32(CurInstr.NextInstr[1])); - } if (comp == NULL) SaveCPSR(); diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index 6386f8b..3b4cb7d 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -457,11 +457,6 @@ void Compiler::Comp_MemAccess(OpArg rd, bool signExtend, bool store, int size) } } -void printStuff2(u32 a, u32 b) -{ - printf("b %x %x\n", a, b); -} - s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc, bool decrement, bool usermode) { int regsCount = regs.Count(); -- cgit v1.2.3 From f378458c104f1879f30610dfe4010e4772218787 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sun, 25 Aug 2019 12:28:48 +0200 Subject: optimise away unneeded flag sets - especially useful for thumb code and larger max block sizes - can still be improved upon --- src/ARMJIT.cpp | 24 ++++ src/ARMJIT.h | 1 + src/ARMJIT_x64/ARMJIT_ALU.cpp | 64 +++++++--- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 9 ++ src/ARMJIT_x64/ARMJIT_Compiler.h | 6 +- src/ARM_InstrInfo.cpp | 238 +++++++++++++++++++++++-------------- src/ARM_InstrInfo.h | 13 ++ 7 files changed, 246 insertions(+), 109 deletions(-) (limited to 'src') diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 949bc1c..3b6bc2e 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -126,6 +126,24 @@ void DeInit() delete compiler; } +void floodFillSetFlags(FetchedInstr instrs[], int start, u8 flags) +{ + for (int j = start; j >= 0; j--) + { + u8 match = instrs[j].Info.WriteFlags & flags; + u8 matchMaybe = (instrs[j].Info.WriteFlags >> 4) & flags; + if (matchMaybe) // writes flags maybe + instrs[j].SetFlags |= matchMaybe; + if (match) + { + instrs[j].SetFlags |= match; + flags &= ~match; + if (!flags) + return; + } + } +} + CompiledBlock CompileBlock(ARM* cpu) { bool thumb = cpu->CPSR & 0x20; @@ -175,8 +193,14 @@ CompiledBlock CompileBlock(ARM* cpu) instrs[i].Info = ARMInstrInfo::Decode(thumb, cpu->Num, instrs[i].Instr); i++; + + bool canCompile = compiler->CanCompile(thumb, instrs[i - 1].Info.Kind); + if (instrs[i - 1].Info.ReadFlags != 0 || !canCompile) + floodFillSetFlags(instrs, i - 2, canCompile ? instrs[i - 1].Info.ReadFlags : 0xF); } while(!instrs[i - 1].Info.EndBlock && i < Config::JIT_MaxBlockSize); + floodFillSetFlags(instrs, i - 1, 0xF); + CompiledBlock block = compiler->CompileBlock(cpu, instrs, i); if (cpu->Num == 0) diff --git a/src/ARMJIT.h b/src/ARMJIT.h index 0fc1c38..6197695 100644 --- a/src/ARMJIT.h +++ b/src/ARMJIT.h @@ -28,6 +28,7 @@ struct FetchedInstr return Instr >> 28; } + u8 SetFlags; u32 Instr; u32 NextInstr[2]; diff --git a/src/ARMJIT_x64/ARMJIT_ALU.cpp b/src/ARMJIT_x64/ARMJIT_ALU.cpp index f0bcf8e..6a7d711 100644 --- a/src/ARMJIT_x64/ARMJIT_ALU.cpp +++ b/src/ARMJIT_x64/ARMJIT_ALU.cpp @@ -111,6 +111,8 @@ OpArg Compiler::A_Comp_GetALUOp2(bool S, bool& carryUsed) } else { + S = S && (CurInstr.SetFlags & 0x2); + int op = (CurInstr.Instr >> 5) & 0x3; if (CurInstr.Instr & (1 << 4)) { @@ -215,7 +217,8 @@ void Compiler::A_Comp_MovOp() if (S) { - TEST(32, rd, rd); + if (FlagsNZRequired()) + TEST(32, rd, rd); Comp_RetriveFlags(false, false, carryUsed); } @@ -263,12 +266,14 @@ void Compiler::Comp_MulOp(bool S, bool add, Gen::OpArg rd, Gen::OpArg rm, Gen::O { IMUL(32, RSCRATCH, rs); LEA(32, rd.GetSimpleReg(), MRegSum(RSCRATCH, rn.GetSimpleReg())); - TEST(32, rd, rd); + if (S && FlagsNZRequired()) + TEST(32, rd, rd); } else { IMUL(32, RSCRATCH, rs); MOV(32, rd, R(RSCRATCH)); + if (S && FlagsNZRequired()) TEST(32, R(RSCRATCH), R(RSCRATCH)); } @@ -331,7 +336,7 @@ void Compiler::A_Comp_SMULL_SMLAL() else { IMUL(64, RSCRATCH2, R(RSCRATCH3)); - if (S) + if (S && FlagsNZRequired()) TEST(64, R(RSCRATCH2), R(RSCRATCH2)); } @@ -345,9 +350,20 @@ void Compiler::A_Comp_SMULL_SMLAL() void Compiler::Comp_RetriveFlags(bool sign, bool retriveCV, bool carryUsed) { - CPSRDirty = true; + if (CurInstr.SetFlags == 0) + return; + if (retriveCV && !(CurInstr.SetFlags & 0x3)) + retriveCV = false; bool carryOnly = !retriveCV && carryUsed; + if (carryOnly && !(CurInstr.SetFlags & 0x2)) + { + carryUsed = false; + carryOnly = false; + } + + CPSRDirty = true; + if (retriveCV) { SETcc(CC_O, R(RSCRATCH)); @@ -355,19 +371,28 @@ void Compiler::Comp_RetriveFlags(bool sign, bool retriveCV, bool carryUsed) LEA(32, RSCRATCH2, MComplex(RSCRATCH, RSCRATCH3, SCALE_2, 0)); } - SETcc(CC_S, R(RSCRATCH)); - SETcc(CC_Z, R(RSCRATCH3)); - LEA(32, RSCRATCH, MComplex(RSCRATCH3, RSCRATCH, SCALE_2, 0)); - int shiftAmount = 30; - if (retriveCV || carryUsed) + if (FlagsNZRequired()) { - LEA(32, RSCRATCH, MComplex(RSCRATCH2, RSCRATCH, carryOnly ? SCALE_2 : SCALE_4, 0)); - shiftAmount = carryOnly ? 29 : 28; - } - SHL(32, R(RSCRATCH), Imm8(shiftAmount)); + SETcc(CC_S, R(RSCRATCH)); + SETcc(CC_Z, R(RSCRATCH3)); + LEA(32, RSCRATCH, MComplex(RSCRATCH3, RSCRATCH, SCALE_2, 0)); + int shiftAmount = 30; + if (retriveCV || carryUsed) + { + LEA(32, RSCRATCH, MComplex(RSCRATCH2, RSCRATCH, carryOnly ? SCALE_2 : SCALE_4, 0)); + shiftAmount = carryOnly ? 29 : 28; + } + SHL(32, R(RSCRATCH), Imm8(shiftAmount)); - AND(32, R(RCPSR), Imm32(0x3FFFFFFF & ~(carryUsed << 29) & ~((retriveCV ? 3 : 0) << 28))); - OR(32, R(RCPSR), R(RSCRATCH)); + AND(32, R(RCPSR), Imm32(0x3FFFFFFF & ~(carryUsed << 29) & ~((retriveCV ? 3 : 0) << 28))); + OR(32, R(RCPSR), R(RSCRATCH)); + } + else + { + SHL(32, R(RSCRATCH2), Imm8(carryOnly ? 29 : 28)); + AND(32, R(RCPSR), Imm32(0xFFFFFFFF & ~(carryUsed << 29) & ~((retriveCV ? 3 : 0) << 28))); + OR(32, R(RCPSR), R(RSCRATCH2)); + } } // always uses RSCRATCH, RSCRATCH2 only if S == true @@ -523,7 +548,8 @@ void Compiler::T_Comp_ShiftImm() if (shifted != rd) MOV(32, rd, shifted); - TEST(32, rd, rd); + if (FlagsNZRequired()) + TEST(32, rd, rd); Comp_RetriveFlags(false, false, carryUsed); } @@ -557,7 +583,8 @@ void Compiler::T_Comp_ALU_Imm8() { case 0x0: MOV(32, rd, imm); - TEST(32, rd, rd); + if (FlagsNZRequired()) + TEST(32, rd, rd); Comp_RetriveFlags(false, false, false); return; case 0x1: @@ -607,7 +634,8 @@ void Compiler::T_Comp_ALU() int shiftOp = op == 0x7 ? 3 : op - 0x2; bool carryUsed; OpArg shifted = Comp_RegShiftReg(shiftOp, rs, rd, true, carryUsed); - TEST(32, shifted, shifted); + if (FlagsNZRequired()) + TEST(32, shifted, shifted); MOV(32, rd, shifted); Comp_RetriveFlags(false, false, true); } diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index ab13cb6..6abb2bb 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -342,6 +342,11 @@ const Compiler::CompileFunc T_Comp[ARMInstrInfo::tk_Count] = { }; #undef F +bool Compiler::CanCompile(bool thumb, u16 kind) +{ + return (thumb ? T_Comp[kind] : A_Comp[kind]) != NULL; +} + void Compiler::Reset() { memset(ResetStart, 0xcc, CodeMemSize); @@ -380,11 +385,15 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs // TODO: this is ugly as a whole, do better RegCache = RegisterCache(this, instrs, instrsCount); + printf("block start %d\n", Thumb); + for (int i = 0; i < instrsCount; i++) { R15 += Thumb ? 2 : 4; CurInstr = instrs[i]; + printf("%x %d %d %d\n", CurInstr.Instr, CurInstr.SetFlags, CurInstr.Info.WriteFlags, CurInstr.Info.ReadFlags); + CompileFunc comp = Thumb ? T_Comp[CurInstr.Info.Kind] : A_Comp[CurInstr.Info.Kind]; diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index 3151cbc..8861884 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -29,6 +29,8 @@ public: void LoadReg(int reg, Gen::X64Reg nativeReg); void SaveReg(int reg, Gen::X64Reg nativeReg); + bool CanCompile(bool thumb, u16 kind); + typedef void (Compiler::*CompileFunc)(); void Comp_JumpTo(Gen::X64Reg addr, bool restoreCPSR = false); @@ -64,7 +66,6 @@ public: void A_Comp_BranchImm(); void A_Comp_BranchXchangeReg(); - void T_Comp_ShiftImm(); void T_Comp_AddSub_(); void T_Comp_ALU_Imm8(); @@ -121,6 +122,9 @@ public: void LoadCPSR(); void SaveCPSR(); + bool FlagsNZRequired() + { return CurInstr.SetFlags & 0xC; } + Gen::FixupBranch CheckCondition(u32 cond); Gen::OpArg MapReg(int reg) diff --git a/src/ARM_InstrInfo.cpp b/src/ARM_InstrInfo.cpp index 4813799..ea6d827 100644 --- a/src/ARM_InstrInfo.cpp +++ b/src/ARM_InstrInfo.cpp @@ -5,7 +5,7 @@ namespace ARMInstrInfo { -#define ak(x) ((x) << 13) +#define ak(x) ((x) << 18) enum { A_Read0 = 1 << 0, @@ -26,69 +26,81 @@ enum { A_Link = 1 << 10, A_UnkOnARM7 = 1 << 11, + + A_SetNZ = 1 << 12, + A_SetCV = 1 << 13, + A_SetMaybeC = 1 << 14, + A_MulFlags = 1 << 15, + A_ReadC = 1 << 16, + A_RRXReadC = 1 << 17, }; #define A_BIOP A_Read16 #define A_MONOOP 0 -#define A_IMPLEMENT_ALU_OP(x,k) \ - const u32 A_##x##_IMM = A_Write12 | A_##k | ak(ak_##x##_IMM); \ - const u32 A_##x##_REG_LSL_IMM = A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_LSL_IMM); \ - const u32 A_##x##_REG_LSR_IMM = A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_LSR_IMM); \ - const u32 A_##x##_REG_ASR_IMM = A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_ASR_IMM); \ - const u32 A_##x##_REG_ROR_IMM = A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_ROR_IMM); \ - const u32 A_##x##_REG_LSL_REG = A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSL_REG); \ - const u32 A_##x##_REG_LSR_REG = A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSR_REG); \ - const u32 A_##x##_REG_ASR_REG = A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_ASR_REG); \ - const u32 A_##x##_REG_ROR_REG = A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_ROR_REG); \ +#define A_ARITH A_SetCV +#define A_LOGIC A_SetMaybeC +#define A_ARITH_IMM A_SetCV +#define A_LOGIC_IMM 0 + +#define A_IMPLEMENT_ALU_OP(x,k,a,c) \ + const u32 A_##x##_IMM = A_Write12 | c | A_##k | ak(ak_##x##_IMM); \ + const u32 A_##x##_REG_LSL_IMM = A_Write12 | c | A_##k | A_Read0 | ak(ak_##x##_REG_LSL_IMM); \ + const u32 A_##x##_REG_LSR_IMM = A_Write12 | c | A_##k | A_Read0 | ak(ak_##x##_REG_LSR_IMM); \ + const u32 A_##x##_REG_ASR_IMM = A_Write12 | c | A_##k | A_Read0 | ak(ak_##x##_REG_ASR_IMM); \ + const u32 A_##x##_REG_ROR_IMM = A_RRXReadC | A_Write12 | c | A_##k | A_Read0 | ak(ak_##x##_REG_ROR_IMM); \ + const u32 A_##x##_REG_LSL_REG = A_Write12 | c | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSL_REG); \ + const u32 A_##x##_REG_LSR_REG = A_Write12 | c | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSR_REG); \ + const u32 A_##x##_REG_ASR_REG = A_Write12 | c | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_ASR_REG); \ + const u32 A_##x##_REG_ROR_REG = A_Write12 | c | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_ROR_REG); \ \ - const u32 A_##x##_IMM_S = A_Write12 | A_##k | ak(ak_##x##_IMM_S); \ - const u32 A_##x##_REG_LSL_IMM_S = A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_LSL_IMM_S); \ - const u32 A_##x##_REG_LSR_IMM_S = A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_LSR_IMM_S); \ - const u32 A_##x##_REG_ASR_IMM_S = A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_ASR_IMM_S); \ - const u32 A_##x##_REG_ROR_IMM_S = A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_ROR_IMM_S); \ - const u32 A_##x##_REG_LSL_REG_S = A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSL_REG_S); \ - const u32 A_##x##_REG_LSR_REG_S = A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSR_REG_S); \ - const u32 A_##x##_REG_ASR_REG_S = A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_ASR_REG_S); \ - const u32 A_##x##_REG_ROR_REG_S = A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_ROR_REG_S); - -A_IMPLEMENT_ALU_OP(AND,BIOP) -A_IMPLEMENT_ALU_OP(EOR,BIOP) -A_IMPLEMENT_ALU_OP(SUB,BIOP) -A_IMPLEMENT_ALU_OP(RSB,BIOP) -A_IMPLEMENT_ALU_OP(ADD,BIOP) -A_IMPLEMENT_ALU_OP(ADC,BIOP) -A_IMPLEMENT_ALU_OP(SBC,BIOP) -A_IMPLEMENT_ALU_OP(RSC,BIOP) -A_IMPLEMENT_ALU_OP(ORR,BIOP) -A_IMPLEMENT_ALU_OP(MOV,MONOOP) -A_IMPLEMENT_ALU_OP(BIC,BIOP) -A_IMPLEMENT_ALU_OP(MVN,MONOOP) + const u32 A_##x##_IMM_S = A_SetNZ | c | A_##a##_IMM | A_Write12 | A_##k | ak(ak_##x##_IMM_S); \ + const u32 A_##x##_REG_LSL_IMM_S = A_SetNZ | c | A_##a | A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_LSL_IMM_S); \ + const u32 A_##x##_REG_LSR_IMM_S = A_SetNZ | c | A_##a | A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_LSR_IMM_S); \ + const u32 A_##x##_REG_ASR_IMM_S = A_SetNZ | c | A_##a | A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_ASR_IMM_S); \ + const u32 A_##x##_REG_ROR_IMM_S = A_RRXReadC | A_SetNZ | c | A_##a | A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_ROR_IMM_S); \ + const u32 A_##x##_REG_LSL_REG_S = A_SetNZ | c | A_##a | A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSL_REG_S); \ + const u32 A_##x##_REG_LSR_REG_S = A_SetNZ | c | A_##a | A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSR_REG_S); \ + const u32 A_##x##_REG_ASR_REG_S = A_SetNZ | c | A_##a | A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_ASR_REG_S); \ + const u32 A_##x##_REG_ROR_REG_S = A_SetNZ | c | A_##a | A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_ROR_REG_S); + +A_IMPLEMENT_ALU_OP(AND,BIOP,LOGIC,0) +A_IMPLEMENT_ALU_OP(EOR,BIOP,LOGIC,0) +A_IMPLEMENT_ALU_OP(SUB,BIOP,ARITH,0) +A_IMPLEMENT_ALU_OP(RSB,BIOP,ARITH,0) +A_IMPLEMENT_ALU_OP(ADD,BIOP,ARITH,0) +A_IMPLEMENT_ALU_OP(ADC,BIOP,ARITH,A_ReadC) +A_IMPLEMENT_ALU_OP(SBC,BIOP,ARITH,A_ReadC) +A_IMPLEMENT_ALU_OP(RSC,BIOP,ARITH,A_ReadC) +A_IMPLEMENT_ALU_OP(ORR,BIOP,LOGIC,0) +A_IMPLEMENT_ALU_OP(MOV,MONOOP,LOGIC,0) +A_IMPLEMENT_ALU_OP(BIC,BIOP,LOGIC,0) +A_IMPLEMENT_ALU_OP(MVN,MONOOP,LOGIC,0) const u32 A_MOV_REG_LSL_IMM_DBG = A_MOV_REG_LSL_IMM; -#define A_IMPLEMENT_ALU_TEST(x) \ - const u32 A_##x##_IMM = A_Read16 | A_Read0 | ak(ak_##x##_IMM); \ - const u32 A_##x##_REG_LSL_IMM = A_Read16 | A_Read0 | ak(ak_##x##_REG_LSL_IMM); \ - const u32 A_##x##_REG_LSR_IMM = A_Read16 | A_Read0 | ak(ak_##x##_REG_LSR_IMM); \ - const u32 A_##x##_REG_ASR_IMM = A_Read16 | A_Read0 | ak(ak_##x##_REG_ASR_IMM); \ - const u32 A_##x##_REG_ROR_IMM = A_Read16 | A_Read0 | ak(ak_##x##_REG_ROR_IMM); \ - const u32 A_##x##_REG_LSL_REG = A_Read16 | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSL_REG); \ - const u32 A_##x##_REG_LSR_REG = A_Read16 | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSR_REG); \ - const u32 A_##x##_REG_ASR_REG = A_Read16 | A_Read0 | A_Read8 | ak(ak_##x##_REG_ASR_REG); \ - const u32 A_##x##_REG_ROR_REG = A_Read16 | A_Read0 | A_Read8 | ak(ak_##x##_REG_ROR_REG); - -A_IMPLEMENT_ALU_TEST(TST) -A_IMPLEMENT_ALU_TEST(TEQ) -A_IMPLEMENT_ALU_TEST(CMP) -A_IMPLEMENT_ALU_TEST(CMN) - -const u32 A_MUL = A_Write16 | A_Read0 | A_Read8 | ak(ak_MUL); -const u32 A_MLA = A_Write16 | A_Read0 | A_Read8 | A_Read12 | ak(ak_MLA); -const u32 A_UMULL = A_Write16 | A_Write12 | A_Read0 | A_Read8 | ak(ak_UMULL); -const u32 A_UMLAL = A_Write16 | A_Write12 | A_Read16 | A_Read12 | A_Read0 | A_Read8 | ak(ak_UMLAL); -const u32 A_SMULL = A_Write16 | A_Write12 | A_Read0 | A_Read8 | ak(ak_SMULL); -const u32 A_SMLAL = A_Write16 | A_Write12 | A_Read16 | A_Read12 | A_Read0 | A_Read8 | ak(ak_SMLAL); +#define A_IMPLEMENT_ALU_TEST(x,a) \ + const u32 A_##x##_IMM = A_SetNZ | A_Read16 | A_##a | A_Read0 | ak(ak_##x##_IMM); \ + const u32 A_##x##_REG_LSL_IMM = A_SetNZ | A_Read16 | A_##a | A_Read0 | ak(ak_##x##_REG_LSL_IMM); \ + const u32 A_##x##_REG_LSR_IMM = A_SetNZ | A_Read16 | A_##a | A_Read0 | ak(ak_##x##_REG_LSR_IMM); \ + const u32 A_##x##_REG_ASR_IMM = A_SetNZ | A_Read16 | A_##a | A_Read0 | ak(ak_##x##_REG_ASR_IMM); \ + const u32 A_##x##_REG_ROR_IMM = A_RRXReadC | A_SetNZ | A_Read16 | A_##a | A_Read0 | ak(ak_##x##_REG_ROR_IMM); \ + const u32 A_##x##_REG_LSL_REG = A_SetNZ | A_Read16 | A_##a | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSL_REG); \ + const u32 A_##x##_REG_LSR_REG = A_SetNZ | A_Read16 | A_##a | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSR_REG); \ + const u32 A_##x##_REG_ASR_REG = A_SetNZ | A_Read16 | A_##a | A_Read0 | A_Read8 | ak(ak_##x##_REG_ASR_REG); \ + const u32 A_##x##_REG_ROR_REG = A_SetNZ | A_Read16 | A_##a | A_Read0 | A_Read8 | ak(ak_##x##_REG_ROR_REG); + +A_IMPLEMENT_ALU_TEST(TST,LOGIC) +A_IMPLEMENT_ALU_TEST(TEQ,LOGIC) +A_IMPLEMENT_ALU_TEST(CMP,ARITH) +A_IMPLEMENT_ALU_TEST(CMN,ARITH) + +const u32 A_MUL = A_MulFlags | A_Write16 | A_Read0 | A_Read8 | ak(ak_MUL); +const u32 A_MLA = A_MulFlags | A_Write16 | A_Read0 | A_Read8 | A_Read12 | ak(ak_MLA); +const u32 A_UMULL = A_MulFlags | A_Write16 | A_Write12 | A_Read0 | A_Read8 | ak(ak_UMULL); +const u32 A_UMLAL = A_MulFlags | A_Write16 | A_Write12 | A_Read16 | A_Read12 | A_Read0 | A_Read8 | ak(ak_UMLAL); +const u32 A_SMULL = A_MulFlags | A_Write16 | A_Write12 | A_Read0 | A_Read8 | ak(ak_SMULL); +const u32 A_SMLAL = A_MulFlags | A_Write16 | A_Write12 | A_Read16 | A_Read12 | A_Read0 | A_Read8 | ak(ak_SMLAL); const u32 A_SMLAxy = A_Write16 | A_Read0 | A_Read8 | A_Read12 | ak(ak_SMLALxy); const u32 A_SMLAWy = A_Write16 | A_Read0 | A_Read8 | A_Read12 | ak(ak_SMLAWy); const u32 A_SMULWy = A_Write16 | A_Read0 | A_Read8 | ak(ak_SMULWy); @@ -161,7 +173,7 @@ const u32 A_SVC = A_BranchAlways | A_Link | ak(ak_SVC); // THUMB -#define tk(x) ((x) << 16) +#define tk(x) ((x) << 20) enum { T_Read0 = 1 << 0, @@ -183,42 +195,47 @@ enum { T_ReadR14 = 1 << 13, T_WriteR14 = 1 << 14, - T_PopPC = 1 << 15 + T_PopPC = 1 << 15, + + T_SetNZ = 1 << 16, + T_SetCV = 1 << 17, + T_SetMaybeC = 1 << 18, + T_ReadC = 1 << 19 }; -const u32 T_LSL_IMM = T_Write0 | T_Read3 | tk(tk_LSL_IMM); -const u32 T_LSR_IMM = T_Write0 | T_Read3 | tk(tk_LSR_IMM); -const u32 T_ASR_IMM = T_Write0 | T_Read3 | tk(tk_ASR_IMM); - -const u32 T_ADD_REG_ = T_Write0 | T_Read3 | T_Read6 | tk(tk_ADD_REG_); -const u32 T_SUB_REG_ = T_Write0 | T_Read3 | T_Read6 | tk(tk_SUB_REG_); -const u32 T_ADD_IMM_ = T_Write0 | T_Read3 | tk(tk_ADD_IMM_); -const u32 T_SUB_IMM_ = T_Write0 | T_Read3 | tk(tk_SUB_IMM_); - -const u32 T_MOV_IMM = T_Write8 | tk(tk_MOV_IMM); -const u32 T_CMP_IMM = T_Write8 | tk(tk_CMP_IMM); -const u32 T_ADD_IMM = T_Write8 | T_Read8 | tk(tk_ADD_IMM); -const u32 T_SUB_IMM = T_Write8 | T_Read8 | tk(tk_SUB_IMM); - -const u32 T_AND_REG = T_Write0 | T_Read0 | T_Read3 | tk(tk_AND_REG); -const u32 T_EOR_REG = T_Write0 | T_Read0 | T_Read3 | tk(tk_EOR_REG); -const u32 T_LSL_REG = T_Write0 | T_Read0 | T_Read3 | tk(tk_LSL_REG); -const u32 T_LSR_REG = T_Write0 | T_Read0 | T_Read3 | tk(tk_LSR_REG); -const u32 T_ASR_REG = T_Write0 | T_Read0 | T_Read3 | tk(tk_ASR_REG); -const u32 T_ADC_REG = T_Write0 | T_Read0 | T_Read3 | tk(tk_ADC_REG); -const u32 T_SBC_REG = T_Write0 | T_Read0 | T_Read3 | tk(tk_SBC_REG); -const u32 T_ROR_REG = T_Write0 | T_Read0 | T_Read3 | tk(tk_ROR_REG); -const u32 T_TST_REG = T_Read0 | T_Read3 | tk(tk_TST_REG); -const u32 T_NEG_REG = T_Write0 | T_Read3 | tk(tk_NEG_REG); -const u32 T_CMP_REG = T_Read0 | T_Read3 | tk(tk_CMP_REG); -const u32 T_CMN_REG = T_Read0 | T_Read3 | tk(tk_CMN_REG); -const u32 T_ORR_REG = T_Write0 | T_Read0 | T_Read3 | tk(tk_ORR_REG); -const u32 T_MUL_REG = T_Write0 | T_Read0 | T_Read3 | tk(tk_MUL_REG); -const u32 T_BIC_REG = T_Write0 | T_Read0 | T_Read3 | tk(tk_BIC_REG); -const u32 T_MVN_REG = T_Write0 | T_Read3 | tk(tk_MVN_REG); +const u32 T_LSL_IMM = T_SetNZ | T_SetMaybeC | T_Write0 | T_Read3 | tk(tk_LSL_IMM); +const u32 T_LSR_IMM = T_SetNZ | T_SetMaybeC | T_Write0 | T_Read3 | tk(tk_LSR_IMM); +const u32 T_ASR_IMM = T_SetNZ | T_SetMaybeC | T_Write0 | T_Read3 | tk(tk_ASR_IMM); + +const u32 T_ADD_REG_ = T_SetNZ | T_SetCV | T_Write0 | T_Read3 | T_Read6 | tk(tk_ADD_REG_); +const u32 T_SUB_REG_ = T_SetNZ | T_SetCV | T_Write0 | T_Read3 | T_Read6 | tk(tk_SUB_REG_); +const u32 T_ADD_IMM_ = T_SetNZ | T_SetCV | T_Write0 | T_Read3 | tk(tk_ADD_IMM_); +const u32 T_SUB_IMM_ = T_SetNZ | T_SetCV | T_Write0 | T_Read3 | tk(tk_SUB_IMM_); + +const u32 T_MOV_IMM = T_SetNZ | T_Write8 | tk(tk_MOV_IMM); +const u32 T_CMP_IMM = T_SetNZ | T_SetCV | T_Write8 | tk(tk_CMP_IMM); +const u32 T_ADD_IMM = T_SetNZ | T_SetCV | T_Write8 | T_Read8 | tk(tk_ADD_IMM); +const u32 T_SUB_IMM = T_SetNZ | T_SetCV | T_Write8 | T_Read8 | tk(tk_SUB_IMM); + +const u32 T_AND_REG = T_SetNZ | T_Write0 | T_Read0 | T_Read3 | tk(tk_AND_REG); +const u32 T_EOR_REG = T_SetNZ | T_Write0 | T_Read0 | T_Read3 | tk(tk_EOR_REG); +const u32 T_LSL_REG = T_SetNZ | T_SetMaybeC | T_Write0 | T_Read0 | T_Read3 | tk(tk_LSL_REG); +const u32 T_LSR_REG = T_SetNZ | T_SetMaybeC | T_Write0 | T_Read0 | T_Read3 | tk(tk_LSR_REG); +const u32 T_ASR_REG = T_SetNZ | T_SetMaybeC | T_Write0 | T_Read0 | T_Read3 | tk(tk_ASR_REG); +const u32 T_ADC_REG = T_ReadC | T_SetNZ | T_SetCV | T_Write0 | T_Read0 | T_Read3 | tk(tk_ADC_REG); +const u32 T_SBC_REG = T_ReadC | T_SetNZ | T_SetCV | T_Write0 | T_Read0 | T_Read3 | tk(tk_SBC_REG); +const u32 T_ROR_REG = T_SetNZ | T_SetMaybeC | T_Write0 | T_Read0 | T_Read3 | tk(tk_ROR_REG); +const u32 T_TST_REG = T_SetNZ | T_Read0 | T_Read3 | tk(tk_TST_REG); +const u32 T_NEG_REG = T_SetNZ | T_SetCV | T_Write0 | T_Read3 | tk(tk_NEG_REG); +const u32 T_CMP_REG = T_SetNZ | T_SetCV | T_Read0 | T_Read3 | tk(tk_CMP_REG); +const u32 T_CMN_REG = T_SetNZ | T_SetCV | T_Read0 | T_Read3 | tk(tk_CMN_REG); +const u32 T_ORR_REG = T_SetNZ | T_Write0 | T_Read0 | T_Read3 | tk(tk_ORR_REG); +const u32 T_MUL_REG = T_SetNZ | T_Write0 | T_Read0 | T_Read3 | tk(tk_MUL_REG); +const u32 T_BIC_REG = T_SetNZ | T_Write0 | T_Read0 | T_Read3 | tk(tk_BIC_REG); +const u32 T_MVN_REG = T_SetNZ | T_Write0 | T_Read3 | tk(tk_MVN_REG); const u32 T_ADD_HIREG = T_WriteHi0 | T_ReadHi0 | T_ReadHi3 | tk(tk_ADD_HIREG); -const u32 T_CMP_HIREG = T_ReadHi0 | T_ReadHi3 | tk(tk_CMP_HIREG); +const u32 T_CMP_HIREG = T_SetNZ | T_SetCV | T_ReadHi0 | T_ReadHi3 | tk(tk_CMP_HIREG); const u32 T_MOV_HIREG = T_WriteHi0 | T_ReadHi3 | tk(tk_MOV_HIREG); const u32 T_ADD_PCREL = T_Write8 | tk(tk_ADD_PCREL); @@ -268,10 +285,20 @@ const u32 T_SVC = T_BranchAlways | T_WriteR14 | tk(tk_SVC); Info Decode(bool thumb, u32 num, u32 instr) { + const u8 FlagsReadPerCond[7] = { + flag_Z, + flag_C, + flag_N, + flag_V, + flag_C | flag_Z, + flag_N | flag_V, + flag_Z | flag_N | flag_V}; + Info res = {0}; if (thumb) { u32 data = THUMBInstrTable[(instr >> 6) & 0x3FF]; + res.Kind = (data >> 20) & 0x3F; if (data & T_Read0) res.SrcRegs |= 1 << (instr & 0x7); @@ -309,7 +336,18 @@ Info Decode(bool thumb, u32 num, u32 instr) if (data & T_PopPC && instr & (1 << 8)) res.DstRegs |= 1 << 15; - res.Kind = (data >> 16) & 0x3F; + if (data & T_SetNZ) + res.WriteFlags |= flag_N | flag_Z; + if (data & T_SetCV) + res.WriteFlags |= flag_C | flag_V; + if (data & T_SetMaybeC) + res.WriteFlags |= flag_C << 4; + if (data & T_ReadC) + res.ReadFlags |= flag_C; + + if (res.Kind == tk_BCOND) + res.ReadFlags |= FlagsReadPerCond[(instr >> 9) & 0x7]; + res.EndBlock = res.Branches(); return res; @@ -323,7 +361,7 @@ Info Decode(bool thumb, u32 num, u32 instr) if (data & A_UnkOnARM7 && num != 0) data = A_UNK; - res.Kind = (data >> 13) & 0x1FF; + res.Kind = (data >> 18) & 0x1FF; if (res.Kind == ak_MCR) { @@ -382,6 +420,26 @@ Info Decode(bool thumb, u32 num, u32 instr) if (res.Kind == ak_LDM) res.DstRegs |= instr & (1 << 15); // this is right + if (data & A_SetNZ) + res.WriteFlags |= flag_N | flag_Z; + if (data & A_SetCV) + res.WriteFlags |= flag_C | flag_V; + if (data & A_SetMaybeC) + res.WriteFlags |= flag_C << 4; + if ((data & A_MulFlags) && (instr & (1 << 20))) + res.WriteFlags |= flag_N | flag_Z; + if (data & A_ReadC) + res.ReadFlags |= flag_C; + if ((data & A_RRXReadC) && !((instr >> 7) & 0x1F)) + res.ReadFlags |= flag_C; + + if ((instr >> 28) < 0xE) + { + // make non conditional flag sets conditional + res.WriteFlags = res.WriteFlags | (res.WriteFlags << 4); + res.ReadFlags |= FlagsReadPerCond[instr >> 29]; + } + res.EndBlock |= res.Branches(); return res; diff --git a/src/ARM_InstrInfo.h b/src/ARM_InstrInfo.h index 4fe9b10..5336837 100644 --- a/src/ARM_InstrInfo.h +++ b/src/ARM_InstrInfo.h @@ -215,11 +215,24 @@ enum tk_Count }; +enum +{ + flag_N = 1 << 3, + flag_Z = 1 << 2, + flag_C = 1 << 1, + flag_V = 1 << 0, +}; + struct Info { u16 DstRegs, SrcRegs; u16 Kind; + u8 ReadFlags; + // lower 4 bits - set always + // upper 4 bits - might set flag + u8 WriteFlags; + bool EndBlock; bool Branches() { -- cgit v1.2.3 From d208f5909c97c3caeaa4c1c95a37e618824ec199 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sun, 25 Aug 2019 13:06:27 +0200 Subject: fixes for flag optimisation --- src/ARMJIT.cpp | 1 + src/ARMJIT_x64/ARMJIT_ALU.cpp | 2 +- src/ARM_InstrInfo.cpp | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 3b6bc2e..5d92e47 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -163,6 +163,7 @@ CompiledBlock CompileBlock(ARM* cpu) { r15 += thumb ? 2 : 4; + instrs[i].SetFlags = 0; instrs[i].Instr = nextInstr[0]; instrs[i].NextInstr[0] = nextInstr[0] = nextInstr[1]; diff --git a/src/ARMJIT_x64/ARMJIT_ALU.cpp b/src/ARMJIT_x64/ARMJIT_ALU.cpp index 6a7d711..f868ddf 100644 --- a/src/ARMJIT_x64/ARMJIT_ALU.cpp +++ b/src/ARMJIT_x64/ARMJIT_ALU.cpp @@ -387,7 +387,7 @@ void Compiler::Comp_RetriveFlags(bool sign, bool retriveCV, bool carryUsed) AND(32, R(RCPSR), Imm32(0x3FFFFFFF & ~(carryUsed << 29) & ~((retriveCV ? 3 : 0) << 28))); OR(32, R(RCPSR), R(RSCRATCH)); } - else + else if (carryUsed || retriveCV) { SHL(32, R(RSCRATCH2), Imm8(carryOnly ? 29 : 28)); AND(32, R(RCPSR), Imm32(0xFFFFFFFF & ~(carryUsed << 29) & ~((retriveCV ? 3 : 0) << 28))); diff --git a/src/ARM_InstrInfo.cpp b/src/ARM_InstrInfo.cpp index ea6d827..3634c35 100644 --- a/src/ARM_InstrInfo.cpp +++ b/src/ARM_InstrInfo.cpp @@ -436,7 +436,7 @@ Info Decode(bool thumb, u32 num, u32 instr) if ((instr >> 28) < 0xE) { // make non conditional flag sets conditional - res.WriteFlags = res.WriteFlags | (res.WriteFlags << 4); + res.WriteFlags = (res.WriteFlags | (res.WriteFlags << 4)) & 0xF0; res.ReadFlags |= FlagsReadPerCond[instr >> 29]; } -- cgit v1.2.3 From d57ee718ba056f7b5ec1bcebc6c6c79f1fe26993 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sun, 25 Aug 2019 13:09:03 +0200 Subject: remove debug printing --- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src') diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index 6abb2bb..5e05446 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -385,15 +385,11 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs // TODO: this is ugly as a whole, do better RegCache = RegisterCache(this, instrs, instrsCount); - printf("block start %d\n", Thumb); - for (int i = 0; i < instrsCount; i++) { R15 += Thumb ? 2 : 4; CurInstr = instrs[i]; - printf("%x %d %d %d\n", CurInstr.Instr, CurInstr.SetFlags, CurInstr.Info.WriteFlags, CurInstr.Info.ReadFlags); - CompileFunc comp = Thumb ? T_Comp[CurInstr.Info.Kind] : A_Comp[CurInstr.Info.Kind]; -- cgit v1.2.3 From 85680d6fe56a701d85f7312766764615fab2f012 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sun, 8 Sep 2019 14:09:00 +0200 Subject: more fixes for flag optimisation + small cycle counting optimisation --- src/ARMJIT_x64/ARMJIT_Branch.cpp | 4 ++ src/ARMJIT_x64/ARMJIT_Compiler.cpp | 28 ++++++++--- src/ARMJIT_x64/ARMJIT_Compiler.h | 2 + src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 4 ++ src/ARM_InstrInfo.cpp | 92 ++++++++++++++++++++++--------------- 5 files changed, 86 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/ARMJIT_x64/ARMJIT_Branch.cpp b/src/ARMJIT_x64/ARMJIT_Branch.cpp index 30b18d7..c0a8f1f 100644 --- a/src/ARMJIT_x64/ARMJIT_Branch.cpp +++ b/src/ARMJIT_x64/ARMJIT_Branch.cpp @@ -19,6 +19,8 @@ void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) // it's not completely safe to assume stuff like, which instructions to preload // we'll see how it works out + IrregularCycles = true; + u32 newPC; u32 cycles = 0; @@ -140,6 +142,8 @@ void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) void Compiler::Comp_JumpTo(Gen::X64Reg addr, bool restoreCPSR) { + IrregularCycles = true; + BitSet16 hiRegsLoaded(RegCache.DirtyRegs & 0xFF00); bool previouslyDirty = CPSRDirty; SaveCPSR(); diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index 5e05446..d585f39 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -447,6 +447,8 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs Comp_AddCycles_C(); else { + IrregularCycles = false; + FixupBranch skipExecute; if (cond < 0xE) skipExecute = CheckCondition(cond); @@ -463,13 +465,19 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs if (CurInstr.Cond() < 0xE) { - FixupBranch skipFailed = J(); - SetJumpTarget(skipExecute); + if (IrregularCycles) + { + FixupBranch skipFailed = J(); + SetJumpTarget(skipExecute); - Comp_AddCycles_C(); + Comp_AddCycles_C(true); - SetJumpTarget(skipFailed); + SetJumpTarget(skipFailed); + } + else + SetJumpTarget(skipExecute); } + } } @@ -518,8 +526,16 @@ void Compiler::Comp_AddCycles_CI(Gen::X64Reg i, int add) NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2] : ((R15 & 0x2) ? 0 : CurInstr.CodeCycles); - LEA(32, RSCRATCH, MDisp(i, add + cycles)); - ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(RSCRATCH)); + if (!Thumb && CurInstr.Cond() < 0xE) + { + LEA(32, RSCRATCH, MDisp(i, add + cycles)); + ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(RSCRATCH)); + } + else + { + ConstantCycles += i + cycles; + ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(i)); + } } } \ No newline at end of file diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index 8861884..a62f043 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -139,6 +139,8 @@ public: u8* ResetStart; u32 CodeMemSize; + bool IrregularCycles; + void* MemoryFuncs9[3][2]; void* MemoryFuncs7[3][2][2]; diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index 3b4cb7d..bf8280d 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -438,6 +438,8 @@ void* Compiler::Gen_MemoryRoutineSeq7(bool store, bool preinc, bool codeMainRAM) void Compiler::Comp_MemAccess(OpArg rd, bool signExtend, bool store, int size) { + IrregularCycles = true; + if (store) MOV(32, R(ABI_PARAM2), rd); u32 cycles = Num @@ -459,6 +461,8 @@ void Compiler::Comp_MemAccess(OpArg rd, bool signExtend, bool store, int size) s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc, bool decrement, bool usermode) { + IrregularCycles = true; + int regsCount = regs.Count(); if (decrement) diff --git a/src/ARM_InstrInfo.cpp b/src/ARM_InstrInfo.cpp index 3634c35..9239e29 100644 --- a/src/ARM_InstrInfo.cpp +++ b/src/ARM_InstrInfo.cpp @@ -5,7 +5,7 @@ namespace ARMInstrInfo { -#define ak(x) ((x) << 18) +#define ak(x) ((x) << 21) enum { A_Read0 = 1 << 0, @@ -33,13 +33,21 @@ enum { A_MulFlags = 1 << 15, A_ReadC = 1 << 16, A_RRXReadC = 1 << 17, + A_StaticShiftSetC = 1 << 18, + A_SetC = 1 << 19, + + A_WriteMemory = 1 << 20, }; #define A_BIOP A_Read16 #define A_MONOOP 0 -#define A_ARITH A_SetCV -#define A_LOGIC A_SetMaybeC +#define A_ARITH_LSL_IMM A_SetCV +#define A_LOGIC_LSL_IMM A_StaticShiftSetC +#define A_ARITH_SHIFT_IMM A_SetCV +#define A_LOGIC_SHIFT_IMM A_SetC +#define A_ARITH_SHIFT_REG A_SetCV +#define A_LOGIC_SHIFT_REG A_SetMaybeC #define A_ARITH_IMM A_SetCV #define A_LOGIC_IMM 0 @@ -55,14 +63,14 @@ enum { const u32 A_##x##_REG_ROR_REG = A_Write12 | c | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_ROR_REG); \ \ const u32 A_##x##_IMM_S = A_SetNZ | c | A_##a##_IMM | A_Write12 | A_##k | ak(ak_##x##_IMM_S); \ - const u32 A_##x##_REG_LSL_IMM_S = A_SetNZ | c | A_##a | A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_LSL_IMM_S); \ - const u32 A_##x##_REG_LSR_IMM_S = A_SetNZ | c | A_##a | A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_LSR_IMM_S); \ - const u32 A_##x##_REG_ASR_IMM_S = A_SetNZ | c | A_##a | A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_ASR_IMM_S); \ - const u32 A_##x##_REG_ROR_IMM_S = A_RRXReadC | A_SetNZ | c | A_##a | A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_ROR_IMM_S); \ - const u32 A_##x##_REG_LSL_REG_S = A_SetNZ | c | A_##a | A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSL_REG_S); \ - const u32 A_##x##_REG_LSR_REG_S = A_SetNZ | c | A_##a | A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSR_REG_S); \ - const u32 A_##x##_REG_ASR_REG_S = A_SetNZ | c | A_##a | A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_ASR_REG_S); \ - const u32 A_##x##_REG_ROR_REG_S = A_SetNZ | c | A_##a | A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_ROR_REG_S); + const u32 A_##x##_REG_LSL_IMM_S = A_SetNZ | c | A_##a##_LSL_IMM | A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_LSL_IMM_S); \ + const u32 A_##x##_REG_LSR_IMM_S = A_SetNZ | c | A_##a##_SHIFT_IMM | A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_LSR_IMM_S); \ + const u32 A_##x##_REG_ASR_IMM_S = A_SetNZ | c | A_##a##_SHIFT_IMM | A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_ASR_IMM_S); \ + const u32 A_##x##_REG_ROR_IMM_S = A_RRXReadC | A_SetNZ | c | A_##a##_SHIFT_IMM | A_Write12 | A_##k | A_Read0 | ak(ak_##x##_REG_ROR_IMM_S); \ + const u32 A_##x##_REG_LSL_REG_S = A_SetNZ | c | A_##a##_SHIFT_REG | A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSL_REG_S); \ + const u32 A_##x##_REG_LSR_REG_S = A_SetNZ | c | A_##a##_SHIFT_REG | A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSR_REG_S); \ + const u32 A_##x##_REG_ASR_REG_S = A_SetNZ | c | A_##a##_SHIFT_REG | A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_ASR_REG_S); \ + const u32 A_##x##_REG_ROR_REG_S = A_SetNZ | c | A_##a##_SHIFT_REG | A_Write12 | A_##k | A_Read0 | A_Read8 | ak(ak_##x##_REG_ROR_REG_S); A_IMPLEMENT_ALU_OP(AND,BIOP,LOGIC,0) A_IMPLEMENT_ALU_OP(EOR,BIOP,LOGIC,0) @@ -80,15 +88,15 @@ A_IMPLEMENT_ALU_OP(MVN,MONOOP,LOGIC,0) const u32 A_MOV_REG_LSL_IMM_DBG = A_MOV_REG_LSL_IMM; #define A_IMPLEMENT_ALU_TEST(x,a) \ - const u32 A_##x##_IMM = A_SetNZ | A_Read16 | A_##a | A_Read0 | ak(ak_##x##_IMM); \ - const u32 A_##x##_REG_LSL_IMM = A_SetNZ | A_Read16 | A_##a | A_Read0 | ak(ak_##x##_REG_LSL_IMM); \ - const u32 A_##x##_REG_LSR_IMM = A_SetNZ | A_Read16 | A_##a | A_Read0 | ak(ak_##x##_REG_LSR_IMM); \ - const u32 A_##x##_REG_ASR_IMM = A_SetNZ | A_Read16 | A_##a | A_Read0 | ak(ak_##x##_REG_ASR_IMM); \ - const u32 A_##x##_REG_ROR_IMM = A_RRXReadC | A_SetNZ | A_Read16 | A_##a | A_Read0 | ak(ak_##x##_REG_ROR_IMM); \ - const u32 A_##x##_REG_LSL_REG = A_SetNZ | A_Read16 | A_##a | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSL_REG); \ - const u32 A_##x##_REG_LSR_REG = A_SetNZ | A_Read16 | A_##a | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSR_REG); \ - const u32 A_##x##_REG_ASR_REG = A_SetNZ | A_Read16 | A_##a | A_Read0 | A_Read8 | ak(ak_##x##_REG_ASR_REG); \ - const u32 A_##x##_REG_ROR_REG = A_SetNZ | A_Read16 | A_##a | A_Read0 | A_Read8 | ak(ak_##x##_REG_ROR_REG); + const u32 A_##x##_IMM = A_SetNZ | A_Read16 | A_##a##_IMM | ak(ak_##x##_IMM); \ + const u32 A_##x##_REG_LSL_IMM = A_SetNZ | A_Read16 | A_##a##_LSL_IMM | A_Read0 | ak(ak_##x##_REG_LSL_IMM); \ + const u32 A_##x##_REG_LSR_IMM = A_SetNZ | A_Read16 | A_##a##_SHIFT_IMM | A_Read0 | ak(ak_##x##_REG_LSR_IMM); \ + const u32 A_##x##_REG_ASR_IMM = A_SetNZ | A_Read16 | A_##a##_SHIFT_IMM | A_Read0 | ak(ak_##x##_REG_ASR_IMM); \ + const u32 A_##x##_REG_ROR_IMM = A_RRXReadC | A_SetNZ | A_Read16 | A_##a##_SHIFT_IMM | A_Read0 | ak(ak_##x##_REG_ROR_IMM); \ + const u32 A_##x##_REG_LSL_REG = A_SetNZ | A_Read16 | A_##a##_SHIFT_REG | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSL_REG); \ + const u32 A_##x##_REG_LSR_REG = A_SetNZ | A_Read16 | A_##a##_SHIFT_REG | A_Read0 | A_Read8 | ak(ak_##x##_REG_LSR_REG); \ + const u32 A_##x##_REG_ASR_REG = A_SetNZ | A_Read16 | A_##a##_SHIFT_REG | A_Read0 | A_Read8 | ak(ak_##x##_REG_ASR_REG); \ + const u32 A_##x##_REG_ROR_REG = A_SetNZ | A_Read16 | A_##a##_SHIFT_REG | A_Read0 | A_Read8 | ak(ak_##x##_REG_ROR_REG); A_IMPLEMENT_ALU_TEST(TST,LOGIC) A_IMPLEMENT_ALU_TEST(TEQ,LOGIC) @@ -115,20 +123,20 @@ const u32 A_QDADD = A_Write12 | A_Read0 | A_Read16 | A_UnkOnARM7 | ak(ak_QDADD); const u32 A_QDSUB = A_Write12 | A_Read0 | A_Read16 | A_UnkOnARM7 | ak(ak_QDSUB); #define A_LDR A_Write12 -#define A_STR A_Read12 +#define A_STR A_Read12 | A_WriteMemory #define A_IMPLEMENT_WB_LDRSTR(x,k) \ const u32 A_##x##_IMM = A_##k | A_Read16 | A_MemWriteback | ak(ak_##x##_IMM); \ const u32 A_##x##_REG_LSL = A_##k | A_Read16 | A_MemWriteback | A_Read0 | ak(ak_##x##_REG_LSL); \ const u32 A_##x##_REG_LSR = A_##k | A_Read16 | A_MemWriteback | A_Read0 | ak(ak_##x##_REG_LSR); \ const u32 A_##x##_REG_ASR = A_##k | A_Read16 | A_MemWriteback | A_Read0 | ak(ak_##x##_REG_ASR); \ - const u32 A_##x##_REG_ROR = A_##k | A_Read16 | A_MemWriteback | A_Read0 | ak(ak_##x##_REG_ROR); \ + const u32 A_##x##_REG_ROR = A_##k | A_RRXReadC | A_Read16 | A_MemWriteback | A_Read0 | ak(ak_##x##_REG_ROR); \ \ const u32 A_##x##_POST_IMM = A_##k | A_Read16 | A_Write16 | ak(ak_##x##_POST_IMM); \ const u32 A_##x##_POST_REG_LSL = A_##k | A_Read16 | A_Write16 | A_Read0 | ak(ak_##x##_POST_REG_LSL); \ const u32 A_##x##_POST_REG_LSR = A_##k | A_Read16 | A_Write16 | A_Read0 | ak(ak_##x##_POST_REG_LSR); \ const u32 A_##x##_POST_REG_ASR = A_##k | A_Read16 | A_Write16 | A_Read0 | ak(ak_##x##_POST_REG_ASR); \ - const u32 A_##x##_POST_REG_ROR = A_##k | A_Read16 | A_Write16 | A_Read0 | ak(ak_##x##_POST_REG_ROR); + const u32 A_##x##_POST_REG_ROR = A_##k | A_RRXReadC | A_Read16 | A_Write16 | A_Read0 | ak(ak_##x##_POST_REG_ROR); A_IMPLEMENT_WB_LDRSTR(STR,STR) A_IMPLEMENT_WB_LDRSTR(STRB,STR) @@ -136,7 +144,7 @@ A_IMPLEMENT_WB_LDRSTR(LDR,LDR) A_IMPLEMENT_WB_LDRSTR(LDRB,LDR) #define A_LDRD A_Write12Double -#define A_STRD A_Read12Double +#define A_STRD A_Read12Double | A_WriteMemory #define A_IMPLEMENT_HD_LDRSTR(x,k) \ const u32 A_##x##_IMM = A_##k | A_Read16 | A_MemWriteback | ak(ak_##x##_IMM); \ @@ -151,11 +159,11 @@ A_IMPLEMENT_HD_LDRSTR(LDRH,LDR) A_IMPLEMENT_HD_LDRSTR(LDRSB,LDR) A_IMPLEMENT_HD_LDRSTR(LDRSH,LDR) -const u32 A_SWP = A_Write12 | A_Read16 | A_Read0 | ak(ak_SWP); -const u32 A_SWPB = A_Write12 | A_Read16 | A_Read0 | ak(ak_SWPB); +const u32 A_SWP = A_Write12 | A_Read16 | A_Read0 | A_WriteMemory | ak(ak_SWP); +const u32 A_SWPB = A_Write12 | A_Read16 | A_Read0 | A_WriteMemory | ak(ak_SWPB); const u32 A_LDM = A_Read16 | A_MemWriteback | ak(ak_LDM); -const u32 A_STM = A_Read16 | A_MemWriteback | ak(ak_STM); +const u32 A_STM = A_Read16 | A_MemWriteback | A_WriteMemory | ak(ak_STM); const u32 A_B = A_BranchAlways | ak(ak_B); const u32 A_BL = A_BranchAlways | A_Link | ak(ak_BL); @@ -173,7 +181,7 @@ const u32 A_SVC = A_BranchAlways | A_Link | ak(ak_SVC); // THUMB -#define tk(x) ((x) << 20) +#define tk(x) ((x) << 21) enum { T_Read0 = 1 << 0, @@ -200,12 +208,13 @@ enum { T_SetNZ = 1 << 16, T_SetCV = 1 << 17, T_SetMaybeC = 1 << 18, - T_ReadC = 1 << 19 + T_ReadC = 1 << 19, + T_SetC = 1 << 20, }; const u32 T_LSL_IMM = T_SetNZ | T_SetMaybeC | T_Write0 | T_Read3 | tk(tk_LSL_IMM); -const u32 T_LSR_IMM = T_SetNZ | T_SetMaybeC | T_Write0 | T_Read3 | tk(tk_LSR_IMM); -const u32 T_ASR_IMM = T_SetNZ | T_SetMaybeC | T_Write0 | T_Read3 | tk(tk_ASR_IMM); +const u32 T_LSR_IMM = T_SetNZ | T_SetC | T_Write0 | T_Read3 | tk(tk_LSR_IMM); +const u32 T_ASR_IMM = T_SetNZ | T_SetC | T_Write0 | T_Read3 | tk(tk_ASR_IMM); const u32 T_ADD_REG_ = T_SetNZ | T_SetCV | T_Write0 | T_Read3 | T_Read6 | tk(tk_ADD_REG_); const u32 T_SUB_REG_ = T_SetNZ | T_SetCV | T_Write0 | T_Read3 | T_Read6 | tk(tk_SUB_REG_); @@ -213,7 +222,7 @@ const u32 T_ADD_IMM_ = T_SetNZ | T_SetCV | T_Write0 | T_Read3 | tk(tk_ADD_IMM_); const u32 T_SUB_IMM_ = T_SetNZ | T_SetCV | T_Write0 | T_Read3 | tk(tk_SUB_IMM_); const u32 T_MOV_IMM = T_SetNZ | T_Write8 | tk(tk_MOV_IMM); -const u32 T_CMP_IMM = T_SetNZ | T_SetCV | T_Write8 | tk(tk_CMP_IMM); +const u32 T_CMP_IMM = T_SetNZ | T_SetCV | T_Read8 | tk(tk_CMP_IMM); const u32 T_ADD_IMM = T_SetNZ | T_SetCV | T_Write8 | T_Read8 | tk(tk_ADD_IMM); const u32 T_SUB_IMM = T_SetNZ | T_SetCV | T_Write8 | T_Read8 | tk(tk_SUB_IMM); @@ -240,7 +249,7 @@ const u32 T_MOV_HIREG = T_WriteHi0 | T_ReadHi3 | tk(tk_MOV_HIREG); const u32 T_ADD_PCREL = T_Write8 | tk(tk_ADD_PCREL); const u32 T_ADD_SPREL = T_Write8 | T_ReadR13 | tk(tk_ADD_SPREL); -const u32 T_ADD_SP = T_WriteR13 | tk(tk_ADD_SP); +const u32 T_ADD_SP = T_WriteR13 | T_ReadR13 | tk(tk_ADD_SP); const u32 T_LDR_PCREL = T_Write8 | tk(tk_LDR_PCREL); @@ -298,7 +307,7 @@ Info Decode(bool thumb, u32 num, u32 instr) if (thumb) { u32 data = THUMBInstrTable[(instr >> 6) & 0x3FF]; - res.Kind = (data >> 20) & 0x3F; + res.Kind = (data >> 21) & 0x3F; if (data & T_Read0) res.SrcRegs |= 1 << (instr & 0x7); @@ -344,12 +353,14 @@ Info Decode(bool thumb, u32 num, u32 instr) res.WriteFlags |= flag_C << 4; if (data & T_ReadC) res.ReadFlags |= flag_C; + if (data & T_SetC) + res.WriteFlags |= flag_C; + + res.EndBlock |= res.Branches(); if (res.Kind == tk_BCOND) res.ReadFlags |= FlagsReadPerCond[(instr >> 9) & 0x7]; - res.EndBlock = res.Branches(); - return res; } else @@ -361,7 +372,7 @@ Info Decode(bool thumb, u32 num, u32 instr) if (data & A_UnkOnARM7 && num != 0) data = A_UNK; - res.Kind = (data >> 18) & 0x1FF; + res.Kind = (data >> 21) & 0x1FF; if (res.Kind == ak_MCR) { @@ -369,7 +380,7 @@ Info Decode(bool thumb, u32 num, u32 instr) u32 cm = instr & 0xF; u32 cpinfo = (instr >> 5) & 0x7; u32 id = (cn<<8)|(cm<<4)|cpinfo; - if (id == 0x704 || id == 0x782) + if (id == 0x704 || id == 0x782 || id == 0x750 || id == 0x751 || id == 0x752) res.EndBlock |= true; } if (res.Kind == ak_MCR || res.Kind == ak_MRC) @@ -420,6 +431,9 @@ Info Decode(bool thumb, u32 num, u32 instr) if (res.Kind == ak_LDM) res.DstRegs |= instr & (1 << 15); // this is right + if (res.Kind == ak_STM) + res.SrcRegs |= instr & (1 << 15); + if (data & A_SetNZ) res.WriteFlags |= flag_N | flag_Z; if (data & A_SetCV) @@ -432,6 +446,8 @@ Info Decode(bool thumb, u32 num, u32 instr) res.ReadFlags |= flag_C; if ((data & A_RRXReadC) && !((instr >> 7) & 0x1F)) res.ReadFlags |= flag_C; + if ((data & A_SetC) || (data & A_StaticShiftSetC) && ((instr >> 7) & 0x1F)) + res.WriteFlags |= flag_C; if ((instr >> 28) < 0xE) { -- cgit v1.2.3 From 0e26aa4edeafa0dab57d6e5a1b77e1a80c6ae3c4 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sun, 8 Sep 2019 14:48:20 +0200 Subject: load register only if needed - do thumb bl long merge in the first step - preparations for better branch jitting --- src/ARMJIT.cpp | 16 ++++++++++++++++ src/ARMJIT.h | 1 + src/ARMJIT_RegisterCache.h | 12 ++++++++---- src/ARMJIT_x64/ARMJIT_Branch.cpp | 12 +++++++----- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 34 ++++++++++++---------------------- src/ARMJIT_x64/ARMJIT_Compiler.h | 2 +- src/ARM_InstrInfo.h | 3 +++ 7 files changed, 48 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 5d92e47..85cadf3 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -159,6 +159,7 @@ CompiledBlock CompileBlock(ARM* cpu) u32 r15 = cpu->R[15]; cpu->FillPipeline(); u32 nextInstr[2] = {cpu->NextInstr[0], cpu->NextInstr[1]}; + u32 nextInstrAddr[2] = {blockAddr, r15}; do { r15 += thumb ? 2 : 4; @@ -166,6 +167,10 @@ CompiledBlock CompileBlock(ARM* cpu) instrs[i].SetFlags = 0; instrs[i].Instr = nextInstr[0]; instrs[i].NextInstr[0] = nextInstr[0] = nextInstr[1]; + + instrs[i].Addr = nextInstrAddr[0]; + nextInstrAddr[0] = nextInstrAddr[1]; + nextInstrAddr[1] = r15; if (cpu->Num == 0) { @@ -193,8 +198,19 @@ CompiledBlock CompileBlock(ARM* cpu) instrs[i].NextInstr[1] = nextInstr[1]; instrs[i].Info = ARMInstrInfo::Decode(thumb, cpu->Num, instrs[i].Instr); + if (thumb && instrs[i].Info.Kind == ARMInstrInfo::tk_BL_LONG_2 && i > 0 + && instrs[i - 1].Info.Kind == ARMInstrInfo::tk_BL_LONG_1) + { + instrs[i - 1].Info.Kind = ARMInstrInfo::tk_BL_LONG; + instrs[i - 1].Instr = (instrs[i - 1].Instr & 0xFFFF) | (instrs[i].Instr << 16); + instrs[i - 1].Info.DstRegs = 0xC000; + instrs[i - 1].Info.SrcRegs = 0; + instrs[i - 1].Info.EndBlock = true; + i--; + } i++; + bool canCompile = compiler->CanCompile(thumb, instrs[i - 1].Info.Kind); if (instrs[i - 1].Info.ReadFlags != 0 || !canCompile) floodFillSetFlags(instrs, i - 2, canCompile ? instrs[i - 1].Info.ReadFlags : 0xF); diff --git a/src/ARMJIT.h b/src/ARMJIT.h index 6197695..7e448ef 100644 --- a/src/ARMJIT.h +++ b/src/ARMJIT.h @@ -31,6 +31,7 @@ struct FetchedInstr u8 SetFlags; u32 Instr; u32 NextInstr[2]; + u32 Addr; u8 CodeCycles; diff --git a/src/ARMJIT_RegisterCache.h b/src/ARMJIT_RegisterCache.h index 04c1eda..fe2f203 100644 --- a/src/ARMJIT_RegisterCache.h +++ b/src/ARMJIT_RegisterCache.h @@ -38,7 +38,7 @@ public: Mapping[reg] = (Reg)-1; } - void LoadRegister(int reg) + void LoadRegister(int reg, bool loadValue) { assert(Mapping[reg] == -1); for (int i = 0; i < NativeRegsAvailable; i++) @@ -50,7 +50,8 @@ public: NativeRegsUsed |= 1 << (int)nativeReg; LoadedRegs |= 1 << reg; - Compiler->LoadReg(reg, nativeReg); + if (loadValue) + Compiler->LoadReg(reg, nativeReg); return; } @@ -66,7 +67,7 @@ public: UnloadRegister(reg); } - void Prepare(int i) + void Prepare(bool thumb, int i) { u16 futureNeeded = 0; int ranking[16]; @@ -111,8 +112,11 @@ public: loadedSet.m_val = LoadedRegs; } + BitSet16 needValueLoaded(needToBeLoaded); + if (thumb || Instr.Cond() >= 0xE) + needValueLoaded = BitSet16(Instr.Info.SrcRegs); for (int reg : needToBeLoaded) - LoadRegister(reg); + LoadRegister(reg, needValueLoaded[reg]); } DirtyRegs |= Instr.Info.DstRegs & ~(1 << 15); } diff --git a/src/ARMJIT_x64/ARMJIT_Branch.cpp b/src/ARMJIT_x64/ARMJIT_Branch.cpp index c0a8f1f..cc7a3c4 100644 --- a/src/ARMJIT_x64/ARMJIT_Branch.cpp +++ b/src/ARMJIT_x64/ARMJIT_Branch.cpp @@ -271,15 +271,17 @@ void Compiler::T_Comp_BL_LONG_2() Comp_JumpTo(RSCRATCH); } -void Compiler::T_Comp_BL_Merged(FetchedInstr part1) +void Compiler::T_Comp_BL_Merged() { - assert(part1.Info.Kind == ARMInstrInfo::tk_BL_LONG_1); Comp_AddCycles_C(); - u32 target = (R15 - 2) + ((s32)((part1.Instr & 0x7FF) << 21) >> 9); - target += (CurInstr.Instr & 0x7FF) << 1; + R15 += 2; - if (Num == 1 || CurInstr.Instr & (1 << 12)) + u32 upperPart = CurInstr.Instr >> 16; + u32 target = (R15 - 2) + ((s32)((CurInstr.Instr & 0x7FF) << 21) >> 9); + target += (upperPart & 0x7FF) << 1; + + if (Num == 1 || upperPart & (1 << 12)) target |= 1; MOV(32, MapReg(14), Imm32((R15 - 2) | 1)); diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index d585f39..d8ce1aa 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -338,7 +338,8 @@ const Compiler::CompileFunc T_Comp[ARMInstrInfo::tk_Count] = { // Branch F(T_Comp_BCOND), F(T_Comp_BranchXchangeReg), F(T_Comp_BranchXchangeReg), F(T_Comp_B), F(T_Comp_BL_LONG_1), F(T_Comp_BL_LONG_2), // Unk, SVC - NULL, NULL + NULL, NULL, + F(T_Comp_BL_Merged) }; #undef F @@ -361,21 +362,18 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs ConstantCycles = 0; Thumb = cpu->CPSR & 0x20; Num = cpu->Num; - R15 = cpu->R[15]; CodeRegion = cpu->CodeRegion; CurCPU = cpu; CompiledBlock res = (CompiledBlock)GetWritableCodePtr(); if (!(Num == 0 - ? IsMapped<0>(R15 - (Thumb ? 2 : 4)) - : IsMapped<1>(R15 - (Thumb ? 2 : 4)))) + ? IsMapped<0>(instrs[0].Addr - (Thumb ? 2 : 4)) + : IsMapped<1>(instrs[0].Addr - (Thumb ? 2 : 4)))) { printf("Trying to compile a block in unmapped memory\n"); } - bool mergedThumbBL = false; - ABI_PushRegistersAndAdjustStack(BitSet32(ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS & ~BitSet32({RSP})), 8); MOV(64, R(RCPU), ImmPtr(cpu)); @@ -387,8 +385,8 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs for (int i = 0; i < instrsCount; i++) { - R15 += Thumb ? 2 : 4; CurInstr = instrs[i]; + R15 = CurInstr.Addr + (Thumb ? 4 : 8); CompileFunc comp = Thumb ? T_Comp[CurInstr.Info.Kind] @@ -406,29 +404,21 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs } if (comp != NULL) - RegCache.Prepare(i); + RegCache.Prepare(Thumb, i); else RegCache.Flush(); if (Thumb) { - if (i < instrsCount - 1 && CurInstr.Info.Kind == ARMInstrInfo::tk_BL_LONG_1 - && instrs[i + 1].Info.Kind == ARMInstrInfo::tk_BL_LONG_2) - mergedThumbBL = true; - else + u32 icode = (CurInstr.Instr >> 6) & 0x3FF; + if (comp == NULL) { - u32 icode = (CurInstr.Instr >> 6) & 0x3FF; - if (comp == NULL) - { - MOV(64, R(ABI_PARAM1), R(RCPU)); + MOV(64, R(ABI_PARAM1), R(RCPU)); - ABI_CallFunction(ARMInterpreter::THUMBInstrTable[icode]); - } - else if (mergedThumbBL) - T_Comp_BL_Merged(instrs[i - 1]); - else - (this->*comp)(); + ABI_CallFunction(ARMInterpreter::THUMBInstrTable[icode]); } + else + (this->*comp)(); } else { diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index a62f043..fcb2380 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -90,7 +90,7 @@ public: void T_Comp_BranchXchangeReg(); void T_Comp_BL_LONG_1(); void T_Comp_BL_LONG_2(); - void T_Comp_BL_Merged(FetchedInstr prefix); + void T_Comp_BL_Merged(); void Comp_MemAccess(Gen::OpArg rd, bool signExtend, bool store, int size); s32 Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc, bool decrement, bool usermode); diff --git a/src/ARM_InstrInfo.h b/src/ARM_InstrInfo.h index 5336837..d01c600 100644 --- a/src/ARM_InstrInfo.h +++ b/src/ARM_InstrInfo.h @@ -212,6 +212,9 @@ enum tk_UNK, tk_SVC, + // not a real instruction + tk_BL_LONG, + tk_Count }; -- cgit v1.2.3 From 40b88ab05aeb7e5c5216f29f4004fb5797db04b5 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Thu, 3 Oct 2019 01:10:59 +0200 Subject: new block cache and much more... - more reliable code invalidation detection - blocks aren't stopped at any branch, but are being followed if possible to get larger blocks - idle loop recognition - optimised literal loads, load/store cycle counting and loads/stores from constant addresses --- src/ARM.cpp | 44 ++- src/ARM.h | 16 +- src/ARMInterpreter.h | 9 + src/ARMJIT.cpp | 755 ++++++++++++++++++++++++++++++------ src/ARMJIT.h | 141 ++----- src/ARMJIT_Internal.h | 198 ++++++++++ src/ARMJIT_RegisterCache.h | 36 +- src/ARMJIT_x64/ARMJIT_ALU.cpp | 16 +- src/ARMJIT_x64/ARMJIT_Branch.cpp | 43 +- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 184 +++++++-- src/ARMJIT_x64/ARMJIT_Compiler.h | 51 ++- src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 629 ++++++++++++++---------------- src/ARM_InstrInfo.cpp | 47 ++- src/ARM_InstrInfo.h | 11 +- src/CP15.cpp | 12 +- src/Config.cpp | 2 + src/Config.h | 1 + src/NDS.cpp | 22 +- 18 files changed, 1529 insertions(+), 688 deletions(-) create mode 100644 src/ARMJIT_Internal.h (limited to 'src') diff --git a/src/ARM.cpp b/src/ARM.cpp index 7caef75..1e75301 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -623,21 +623,26 @@ void ARMv5::ExecuteJIT() return; } - ARMJIT::CompiledBlock block = ARMJIT::LookUpBlock<0>(instrAddr); - Cycles += (block ? block : ARMJIT::CompileBlock(this))(); + ARMJIT::JitBlockEntry block = ARMJIT::LookUpBlock<0>(instrAddr); + if (block) + Cycles += block(); + else + ARMJIT::CompileBlock(this); + + NDS::ARM9Timestamp += Cycles; + Cycles = 0; + if (IRQ) TriggerIRQ(); if (Halted) { - if (Halted == 1 && NDS::ARM9Timestamp < NDS::ARM9Target) + bool idleLoop = Halted & 0x20; + Halted &= ~0x20; + if ((Halted == 1 || idleLoop) && NDS::ARM9Timestamp < NDS::ARM9Target) { NDS::ARM9Timestamp = NDS::ARM9Target; } break; } - if (IRQ) TriggerIRQ(); - - NDS::ARM9Timestamp += Cycles; - Cycles = 0; } if (Halted == 2) @@ -753,23 +758,28 @@ void ARMv4::ExecuteJIT() printf("ARMv4 PC in non executable region %08X\n", R[15]); return; } - ARMJIT::CompiledBlock block = ARMJIT::LookUpBlock<1>(instrAddr); - Cycles += (block ? block : ARMJIT::CompileBlock(this))(); + + ARMJIT::JitBlockEntry block = ARMJIT::LookUpBlock<1>(instrAddr); + if (block) + Cycles += block(); + else + ARMJIT::CompileBlock(this); + + NDS::ARM7Timestamp += Cycles; + Cycles = 0; // TODO optimize this shit!!! + if (IRQ) TriggerIRQ(); if (Halted) { - if (Halted == 1 && NDS::ARM7Timestamp < NDS::ARM7Target) + bool idleLoop = Halted & 0x20; + Halted &= ~0x20; + if ((Halted == 1 || idleLoop) && NDS::ARM7Timestamp < NDS::ARM7Target) { NDS::ARM7Timestamp = NDS::ARM7Target; } break; } - - if (IRQ) TriggerIRQ(); - - NDS::ARM7Timestamp += Cycles; - Cycles = 0; } if (Halted == 2) @@ -779,6 +789,8 @@ void ARMv4::ExecuteJIT() void ARMv5::FillPipeline() { + SetupCodeMem(R[15]); + if (CPSR & 0x20) { if ((R[15] - 2) & 0x2) @@ -801,6 +813,8 @@ void ARMv5::FillPipeline() void ARMv4::FillPipeline() { + SetupCodeMem(R[15]); + if (CPSR & 0x20) { NextInstr[0] = CodeRead16(R[15] - 2); diff --git a/src/ARM.h b/src/ARM.h index 811b2e0..b36120a 100644 --- a/src/ARM.h +++ b/src/ARM.h @@ -311,7 +311,7 @@ public: { *val = BusRead8(addr); DataRegion = addr >> 24; - DataCycles = NDS::ARM7MemTimings[DataRegion][0]; + DataCycles = NDS::ARM7MemTimings[addr >> 15][0]; } void DataRead16(u32 addr, u32* val) @@ -320,7 +320,7 @@ public: *val = BusRead16(addr); DataRegion = addr >> 24; - DataCycles = NDS::ARM7MemTimings[DataRegion][0]; + DataCycles = NDS::ARM7MemTimings[addr >> 15][0]; } void DataRead32(u32 addr, u32* val) @@ -329,7 +329,7 @@ public: *val = BusRead32(addr); DataRegion = addr >> 24; - DataCycles = NDS::ARM7MemTimings[DataRegion][2]; + DataCycles = NDS::ARM7MemTimings[addr >> 15][2]; } void DataRead32S(u32 addr, u32* val) @@ -337,14 +337,14 @@ public: addr &= ~3; *val = BusRead32(addr); - DataCycles += NDS::ARM7MemTimings[DataRegion][3]; + DataCycles += NDS::ARM7MemTimings[addr >> 15][3]; } void DataWrite8(u32 addr, u8 val) { BusWrite8(addr, val); DataRegion = addr >> 24; - DataCycles = NDS::ARM7MemTimings[DataRegion][0]; + DataCycles = NDS::ARM7MemTimings[addr >> 15][0]; } void DataWrite16(u32 addr, u16 val) @@ -353,7 +353,7 @@ public: BusWrite16(addr, val); DataRegion = addr >> 24; - DataCycles = NDS::ARM7MemTimings[DataRegion][0]; + DataCycles = NDS::ARM7MemTimings[addr >> 15][0]; } void DataWrite32(u32 addr, u32 val) @@ -362,7 +362,7 @@ public: BusWrite32(addr, val); DataRegion = addr >> 24; - DataCycles = NDS::ARM7MemTimings[DataRegion][2]; + DataCycles = NDS::ARM7MemTimings[addr >> 15][2]; } void DataWrite32S(u32 addr, u32 val) @@ -370,7 +370,7 @@ public: addr &= ~3; BusWrite32(addr, val); - DataCycles += NDS::ARM7MemTimings[DataRegion][3]; + DataCycles += NDS::ARM7MemTimings[addr >> 15][3]; } diff --git a/src/ARMInterpreter.h b/src/ARMInterpreter.h index 7244238..2bf8167 100644 --- a/src/ARMInterpreter.h +++ b/src/ARMInterpreter.h @@ -28,6 +28,15 @@ namespace ARMInterpreter extern void (*ARMInstrTable[4096])(ARM* cpu); extern void (*THUMBInstrTable[1024])(ARM* cpu); +void A_MSR_IMM(ARM* cpu); +void A_MSR_REG(ARM* cpu); +void A_MRS(ARM* cpu); +void A_MCR(ARM* cpu); +void A_MRC(ARM* cpu); +void A_SVC(ARM* cpu); + +void T_SVC(ARM* cpu); + void A_BLX_IMM(ARM* cpu); // I'm a special one look at me } diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 85cadf3..686bdd6 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -1,122 +1,137 @@ #include "ARMJIT.h" #include +#include #include "Config.h" +#include "ARMJIT_Internal.h" #include "ARMJIT_x64/ARMJIT_Compiler.h" +#include "ARMInterpreter_ALU.h" +#include "ARMInterpreter_LoadStore.h" +#include "ARMInterpreter_Branch.h" +#include "ARMInterpreter.h" + +#include "GPU3D.h" +#include "SPU.h" +#include "Wifi.h" + namespace ARMJIT { +#define JIT_DEBUGPRINT(msg, ...) + Compiler* compiler; -BlockCache cache; -#define DUP2(x) x, x +const u32 ExeMemRegionSizes[] = { + 0x8000, // Unmapped Region (dummy) + 0x8000, // ITCM + 4*1024*1024, // Main RAM + 0x8000, // SWRAM + 0xA4000, // LCDC + 0x8000, // ARM9 BIOS + 0x4000, // ARM7 BIOS + 0x10000, // ARM7 WRAM + 0x40000 // ARM7 WVRAM +}; -static ptrdiff_t JIT_MEM[2][32] = { - //arm9 - { - /* 0X*/ DUP2(offsetof(BlockCache, ARM9_ITCM)), - /* 1X*/ DUP2(offsetof(BlockCache, ARM9_ITCM)), // mirror - /* 2X*/ DUP2(offsetof(BlockCache, MainRAM)), - /* 3X*/ DUP2(offsetof(BlockCache, SWRAM)), - /* 4X*/ DUP2(-1), - /* 5X*/ DUP2(-1), - /* 6X*/ -1, - offsetof(BlockCache, ARM9_LCDC), // Plain ARM9-CPU Access (LCDC mode) (max 656KB) - /* 7X*/ DUP2(-1), - /* 8X*/ DUP2(-1), - /* 9X*/ DUP2(-1), - /* AX*/ DUP2(-1), - /* BX*/ DUP2(-1), - /* CX*/ DUP2(-1), - /* DX*/ DUP2(-1), - /* EX*/ DUP2(-1), - /* FX*/ DUP2(offsetof(BlockCache, ARM9_BIOS)) - }, - //arm7 - { - /* 0X*/ DUP2(offsetof(BlockCache, ARM7_BIOS)), - /* 1X*/ DUP2(-1), - /* 2X*/ DUP2(offsetof(BlockCache, MainRAM)), - /* 3X*/ offsetof(BlockCache, SWRAM), - offsetof(BlockCache, ARM7_WRAM), - /* 4X*/ DUP2(-1), - /* 5X*/ DUP2(-1), - /* 6X*/ DUP2(offsetof(BlockCache, ARM7_WVRAM)), /* contrary to Gbatek, melonDS and itself, - DeSmuME doesn't mirror the 64 MB region at 0x6800000 */ - /* 7X*/ DUP2(-1), - /* 8X*/ DUP2(-1), - /* 9X*/ DUP2(-1), - /* AX*/ DUP2(-1), - /* BX*/ DUP2(-1), - /* CX*/ DUP2(-1), - /* DX*/ DUP2(-1), - /* EX*/ DUP2(-1), - /* FX*/ DUP2(-1) - } +const u32 ExeMemRegionOffsets[] = { + 0, + 0x8000, + 0x10000, + 0x410000, + 0x418000, + 0x4BC000, + 0x4C4000, + 0x4C8000, + 0x4D8000, + 0x518000, }; -static u32 JIT_MASK[2][32] = { +#define DUP2(x) x, x + +const static ExeMemKind JIT_MEM[2][32] = { //arm9 { - /* 0X*/ DUP2(0x00007FFF), - /* 1X*/ DUP2(0x00007FFF), - /* 2X*/ DUP2(0x003FFFFF), - /* 3X*/ DUP2(0x00007FFF), - /* 4X*/ DUP2(0x00000000), - /* 5X*/ DUP2(0x00000000), - /* 6X*/ 0x00000000, - 0x000FFFFF, - /* 7X*/ DUP2(0x00000000), - /* 8X*/ DUP2(0x00000000), - /* 9X*/ DUP2(0x00000000), - /* AX*/ DUP2(0x00000000), - /* BX*/ DUP2(0x00000000), - /* CX*/ DUP2(0x00000000), - /* DX*/ DUP2(0x00000000), - /* EX*/ DUP2(0x00000000), - /* FX*/ DUP2(0x00007FFF) + /* 0X*/ DUP2(exeMem_ITCM), + /* 1X*/ DUP2(exeMem_ITCM), // mirror + /* 2X*/ DUP2(exeMem_MainRAM), + /* 3X*/ DUP2(exeMem_SWRAM), + /* 4X*/ DUP2(exeMem_Unmapped), + /* 5X*/ DUP2(exeMem_Unmapped), + /* 6X*/ exeMem_Unmapped, + exeMem_LCDC, // Plain ARM9-CPU Access (LCDC mode) (max 656KB) + /* 7X*/ DUP2(exeMem_Unmapped), + /* 8X*/ DUP2(exeMem_Unmapped), + /* 9X*/ DUP2(exeMem_Unmapped), + /* AX*/ DUP2(exeMem_Unmapped), + /* BX*/ DUP2(exeMem_Unmapped), + /* CX*/ DUP2(exeMem_Unmapped), + /* DX*/ DUP2(exeMem_Unmapped), + /* EX*/ DUP2(exeMem_Unmapped), + /* FX*/ DUP2(exeMem_ARM9_BIOS) }, //arm7 { - /* 0X*/ DUP2(0x00003FFF), - /* 1X*/ DUP2(0x00000000), - /* 2X*/ DUP2(0x003FFFFF), - /* 3X*/ 0x00007FFF, - 0x0000FFFF, - /* 4X*/ 0x00000000, - 0x0000FFFF, - /* 5X*/ DUP2(0x00000000), - /* 6X*/ DUP2(0x0003FFFF), - /* 7X*/ DUP2(0x00000000), - /* 8X*/ DUP2(0x00000000), - /* 9X*/ DUP2(0x00000000), - /* AX*/ DUP2(0x00000000), - /* BX*/ DUP2(0x00000000), - /* CX*/ DUP2(0x00000000), - /* DX*/ DUP2(0x00000000), - /* EX*/ DUP2(0x00000000), - /* FX*/ DUP2(0x00000000) + /* 0X*/ DUP2(exeMem_ARM7_BIOS), + /* 1X*/ DUP2(exeMem_Unmapped), + /* 2X*/ DUP2(exeMem_MainRAM), + /* 3X*/ exeMem_SWRAM, + exeMem_ARM7_WRAM, + /* 4X*/ DUP2(exeMem_Unmapped), + /* 5X*/ DUP2(exeMem_Unmapped), + /* 6X*/ DUP2(exeMem_ARM7_WVRAM), /* contrary to Gbatek, melonDS and itself, + DeSmuME doesn't mirror the 64 MB region at 0x6800000 */ + /* 7X*/ DUP2(exeMem_Unmapped), + /* 8X*/ DUP2(exeMem_Unmapped), + /* 9X*/ DUP2(exeMem_Unmapped), + /* AX*/ DUP2(exeMem_Unmapped), + /* BX*/ DUP2(exeMem_Unmapped), + /* CX*/ DUP2(exeMem_Unmapped), + /* DX*/ DUP2(exeMem_Unmapped), + /* EX*/ DUP2(exeMem_Unmapped), + /* FX*/ DUP2(exeMem_Unmapped) } }; #undef DUP2 +/* + translates address to pseudo physical address + - more compact, eliminates mirroring, everything comes in a row + - we only need one translation table +*/ +u32 AddrTranslate9[0x2000]; +u32 AddrTranslate7[0x4000]; -void Init() +JitBlockEntry FastBlockAccess[ExeMemSpaceSize / 2]; +AddressRange CodeRanges[ExeMemSpaceSize / 256]; + +TinyVector JitBlocks; +JitBlock* RestoreCandidates[0x1000] = {NULL}; + +u32 HashRestoreCandidate(u32 pseudoPhysicalAddr) { - memset(&cache, 0, sizeof(BlockCache)); + return (u32)(((u64)pseudoPhysicalAddr * 11400714819323198485llu) >> 53); +} +void Init() +{ for (int i = 0; i < 0x2000; i++) - cache.AddrMapping9[i] = JIT_MEM[0][i >> 8] == -1 ? NULL : - (CompiledBlock*)((u8*)&cache + JIT_MEM[0][i >> 8]) - + (((i << 15) & JIT_MASK[0][i >> 8]) >> 1); + { + ExeMemKind kind = JIT_MEM[0][i >> 8]; + u32 size = ExeMemRegionSizes[kind]; + + AddrTranslate9[i] = ExeMemRegionOffsets[kind] + ((i << 15) & (size - 1)); + } for (int i = 0; i < 0x4000; i++) - cache.AddrMapping7[i] = JIT_MEM[1][i >> 9] == -1 ? NULL : - (CompiledBlock*)((u8*)&cache + JIT_MEM[1][i >> 9]) - + (((i << 14) & JIT_MASK[1][i >> 9]) >> 1); + { + ExeMemKind kind = JIT_MEM[1][i >> 9]; + u32 size = ExeMemRegionSizes[kind]; + + AddrTranslate7[i] = ExeMemRegionOffsets[kind] + ((i << 14) & (size - 1)); + } compiler = new Compiler(); } @@ -126,7 +141,7 @@ void DeInit() delete compiler; } -void floodFillSetFlags(FetchedInstr instrs[], int start, u8 flags) +void FloodFillSetFlags(FetchedInstr instrs[], int start, u8 flags) { for (int j = start; j >= 0; j--) { @@ -144,7 +159,154 @@ void floodFillSetFlags(FetchedInstr instrs[], int start, u8 flags) } } -CompiledBlock CompileBlock(ARM* cpu) +bool DecodeBranch(bool thumb, const FetchedInstr& instr, u32& cond, u32& targetAddr) +{ + if (thumb) + { + u32 r15 = instr.Addr + 4; + cond = 0xE; + + if (instr.Info.Kind == ARMInstrInfo::tk_BL_LONG && !(instr.Instr & (1 << 12))) + { + targetAddr = r15 + ((s32)((instr.Instr & 0x7FF) << 21) >> 9); + targetAddr += ((instr.Instr >> 16) & 0x7FF) << 1; + return true; + } + else if (instr.Info.Kind == ARMInstrInfo::tk_B) + { + s32 offset = (s32)((instr.Instr & 0x7FF) << 21) >> 20; + targetAddr = r15 + offset; + return true; + } + else if (instr.Info.Kind == ARMInstrInfo::tk_BCOND) + { + cond = (instr.Instr >> 8) & 0xF; + s32 offset = (s32)(instr.Instr << 24) >> 23; + targetAddr = r15 + offset; + return true; + } + } + else + { + cond = instr.Cond(); + if (instr.Info.Kind == ARMInstrInfo::ak_BL + || instr.Info.Kind == ARMInstrInfo::ak_B) + { + s32 offset = (s32)(instr.Instr << 8) >> 6; + u32 r15 = instr.Addr + 8; + targetAddr = r15 + offset; + return true; + } + } + return false; +} + +bool IsIdleLoop(FetchedInstr* instrs, int instrsCount) +{ + // see https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/Core/PowerPC/PPCAnalyst.cpp#L678 + // it basically checks if one iteration of a loop depends on another + // the rules are quite simple + + u16 regsWrittenTo = 0; + u16 regsDisallowedToWrite = 0; + for (int i = 0; i < instrsCount; i++) + { + //printf("instr %d %x regs(%x %x) %x %x\n", i, instrs[i].Instr, instrs[i].Info.DstRegs, instrs[i].Info.SrcRegs, regsWrittenTo, regsDisallowedToWrite); + if (instrs[i].Info.SpecialKind == ARMInstrInfo::special_WriteMem) + return false; + if (i < instrsCount - 1 && instrs[i].Info.Branches()) + return false; + + u16 srcRegs = instrs[i].Info.SrcRegs & ~(1 << 15); + u16 dstRegs = instrs[i].Info.DstRegs & ~(1 << 15); + + regsDisallowedToWrite |= srcRegs & ~regsWrittenTo; + + if (dstRegs & regsDisallowedToWrite) + return false; + regsWrittenTo |= dstRegs; + } + return true; +} + +typedef void (*InterpreterFunc)(ARM* cpu); + +#define F(x) &ARMInterpreter::A_##x +#define F_ALU(name, s) \ + F(name##_REG_LSL_IMM##s), F(name##_REG_LSR_IMM##s), F(name##_REG_ASR_IMM##s), F(name##_REG_ROR_IMM##s), \ + F(name##_REG_LSL_REG##s), F(name##_REG_LSR_REG##s), F(name##_REG_ASR_REG##s), F(name##_REG_ROR_REG##s), F(name##_IMM##s) +#define F_MEM_WB(name) \ + F(name##_REG_LSL), F(name##_REG_LSR), F(name##_REG_ASR), F(name##_REG_ROR), F(name##_IMM), \ + F(name##_POST_REG_LSL), F(name##_POST_REG_LSR), F(name##_POST_REG_ASR), F(name##_POST_REG_ROR), F(name##_POST_IMM) +#define F_MEM_HD(name) \ + F(name##_REG), F(name##_IMM), F(name##_POST_REG), F(name##_POST_IMM) +InterpreterFunc InterpretARM[ARMInstrInfo::ak_Count] = +{ + F_ALU(AND,), F_ALU(AND,_S), + F_ALU(EOR,), F_ALU(EOR,_S), + F_ALU(SUB,), F_ALU(SUB,_S), + F_ALU(RSB,), F_ALU(RSB,_S), + F_ALU(ADD,), F_ALU(ADD,_S), + F_ALU(ADC,), F_ALU(ADC,_S), + F_ALU(SBC,), F_ALU(SBC,_S), + F_ALU(RSC,), F_ALU(RSC,_S), + F_ALU(ORR,), F_ALU(ORR,_S), + F_ALU(MOV,), F_ALU(MOV,_S), + F_ALU(BIC,), F_ALU(BIC,_S), + F_ALU(MVN,), F_ALU(MVN,_S), + F_ALU(TST,), + F_ALU(TEQ,), + F_ALU(CMP,), + F_ALU(CMN,), + + F(MUL), F(MLA), F(UMULL), F(UMLAL), F(SMULL), F(SMLAL), F(SMLAxy), F(SMLAWy), F(SMULWy), F(SMLALxy), F(SMULxy), + F(CLZ), F(QADD), F(QDADD), F(QSUB), F(QDSUB), + + F_MEM_WB(STR), + F_MEM_WB(STRB), + F_MEM_WB(LDR), + F_MEM_WB(LDRB), + + F_MEM_HD(STRH), + F_MEM_HD(LDRD), + F_MEM_HD(STRD), + F_MEM_HD(LDRH), + F_MEM_HD(LDRSB), + F_MEM_HD(LDRSH), + + F(SWP), F(SWPB), + F(LDM), F(STM), + + F(B), F(BL), F(BLX_IMM), F(BX), F(BLX_REG), + F(UNK), F(MSR_IMM), F(MSR_REG), F(MRS), F(MCR), F(MRC), F(SVC) +}; +#undef F_ALU +#undef F_MEM_WB +#undef F_MEM_HD +#undef F + +#define F(x) ARMInterpreter::T_##x +InterpreterFunc InterpretTHUMB[ARMInstrInfo::tk_Count] = +{ + F(LSL_IMM), F(LSR_IMM), F(ASR_IMM), + F(ADD_REG_), F(SUB_REG_), F(ADD_IMM_), F(SUB_IMM_), + F(MOV_IMM), F(CMP_IMM), F(ADD_IMM), F(SUB_IMM), + F(AND_REG), F(EOR_REG), F(LSL_REG), F(LSR_REG), F(ASR_REG), + F(ADC_REG), F(SBC_REG), F(ROR_REG), F(TST_REG), F(NEG_REG), + F(CMP_REG), F(CMN_REG), F(ORR_REG), F(MUL_REG), F(BIC_REG), F(MVN_REG), + F(ADD_HIREG), F(CMP_HIREG), F(MOV_HIREG), + F(ADD_PCREL), F(ADD_SPREL), F(ADD_SP), + F(LDR_PCREL), F(STR_REG), F(STRB_REG), F(LDR_REG), F(LDRB_REG), F(STRH_REG), + F(LDRSB_REG), F(LDRH_REG), F(LDRSH_REG), F(STR_IMM), F(LDR_IMM), F(STRB_IMM), + F(LDRB_IMM), F(STRH_IMM), F(LDRH_IMM), F(STR_SPREL), F(LDR_SPREL), + F(PUSH), F(POP), F(LDMIA), F(STMIA), + F(BCOND), F(BX), F(BLX_REG), F(B), F(BL_LONG_1), F(BL_LONG_2), + F(UNK), F(SVC), + NULL // BL_LONG psudo opcode +}; +#undef F + +void CompileBlock(ARM* cpu) { bool thumb = cpu->CPSR & 0x20; @@ -153,17 +315,41 @@ CompiledBlock CompileBlock(ARM* cpu) if (Config::JIT_MaxBlockSize > 32) Config::JIT_MaxBlockSize = 32; + u32 blockAddr = cpu->R[15] - (thumb ? 2 : 4); + if (!(cpu->Num == 0 + ? IsMapped<0>(blockAddr) + : IsMapped<1>(blockAddr))) + { + printf("Trying to compile a block in unmapped memory: %x\n", blockAddr); + } + + u32 pseudoPhysicalAddr = cpu->Num == 0 + ? TranslateAddr<0>(blockAddr) + : TranslateAddr<1>(blockAddr); + FetchedInstr instrs[Config::JIT_MaxBlockSize]; int i = 0; - u32 blockAddr = cpu->R[15] - (thumb ? 2 : 4); u32 r15 = cpu->R[15]; + + u32 addresseRanges[32] = {}; + u32 numAddressRanges = 0; + cpu->FillPipeline(); u32 nextInstr[2] = {cpu->NextInstr[0], cpu->NextInstr[1]}; u32 nextInstrAddr[2] = {blockAddr, r15}; + + JIT_DEBUGPRINT("start block %x (%x) %p %p (region invalidates %dx)\n", + blockAddr, pseudoPhysicalAddr, FastBlockAccess[pseudoPhysicalAddr / 2], + cpu->Num == 0 ? LookUpBlock<0>(blockAddr) : LookUpBlock<1>(blockAddr), + CodeRanges[pseudoPhysicalAddr / 256].TimesInvalidated); + + u32 lastSegmentStart = blockAddr; + do { r15 += thumb ? 2 : 4; + instrs[i].BranchFlags = 0; instrs[i].SetFlags = 0; instrs[i].Instr = nextInstr[0]; instrs[i].NextInstr[0] = nextInstr[0] = nextInstr[1]; @@ -171,6 +357,25 @@ CompiledBlock CompileBlock(ARM* cpu) instrs[i].Addr = nextInstrAddr[0]; nextInstrAddr[0] = nextInstrAddr[1]; nextInstrAddr[1] = r15; + JIT_DEBUGPRINT("instr %08x %x\n", instrs[i].Instr & (thumb ? 0xFFFF : ~0), instrs[i].Addr); + + u32 translatedAddr = (cpu->Num == 0 + ? TranslateAddr<0>(instrs[i].Addr) + : TranslateAddr<1>(instrs[i].Addr)) & ~0xFF; + if (i == 0 || translatedAddr != addresseRanges[numAddressRanges - 1]) + { + bool returning = false; + for (int j = 0; j < numAddressRanges; j++) + { + if (addresseRanges[j] == translatedAddr) + { + returning = true; + break; + } + } + if (!returning) + addresseRanges[numAddressRanges++] = translatedAddr; + } if (cpu->Num == 0) { @@ -198,6 +403,34 @@ CompiledBlock CompileBlock(ARM* cpu) instrs[i].NextInstr[1] = nextInstr[1]; instrs[i].Info = ARMInstrInfo::Decode(thumb, cpu->Num, instrs[i].Instr); + cpu->R[15] = r15; + cpu->CurInstr = instrs[i].Instr; + cpu->CodeCycles = instrs[i].CodeCycles; + + if (thumb) + { + InterpretTHUMB[instrs[i].Info.Kind](cpu); + } + else + { + if (cpu->Num == 0 && instrs[i].Info.Kind == ARMInstrInfo::ak_BLX_IMM) + { + ARMInterpreter::A_BLX_IMM(cpu); + } + else + { + u32 icode = ((instrs[i].Instr >> 4) & 0xF) | ((instrs[i].Instr >> 16) & 0xFF0); + assert(InterpretARM[instrs[i].Info.Kind] == ARMInterpreter::ARMInstrTable[icode] || instrs[i].Info.Kind == ARMInstrInfo::ak_MOV_REG_LSL_IMM); + if (cpu->CheckCondition(instrs[i].Cond())) + InterpretARM[instrs[i].Info.Kind](cpu); + else + cpu->AddCycles_C(); + } + } + + instrs[i].DataCycles = cpu->DataCycles; + instrs[i].DataRegion = cpu->DataRegion; + if (thumb && instrs[i].Info.Kind == ARMInstrInfo::tk_BL_LONG_2 && i > 0 && instrs[i - 1].Info.Kind == ARMInstrInfo::tk_BL_LONG_1) { @@ -208,40 +441,340 @@ CompiledBlock CompileBlock(ARM* cpu) instrs[i - 1].Info.EndBlock = true; i--; } - i++; + if (instrs[i].Info.Branches() && Config::JIT_BrancheOptimisations) + { + bool hasBranched = cpu->R[15] != r15; + + u32 cond, target; + bool staticBranch = DecodeBranch(thumb, instrs[i], cond, target); + JIT_DEBUGPRINT("branch cond %x target %x (%d)\n", cond, target, hasBranched); + + if (staticBranch) + { + bool isBackJump = false; + if (hasBranched) + { + for (int j = 0; j < i; j++) + { + if (instrs[i].Addr == target) + { + isBackJump = true; + break; + } + } + } + + if (cond < 0xE && target < instrs[i].Addr && target >= lastSegmentStart) + { + // we might have an idle loop + u32 offset = (target - blockAddr) / (thumb ? 2 : 4); + if (IsIdleLoop(instrs + offset, i - offset + 1)) + { + instrs[i].BranchFlags |= branch_IdleBranch; + JIT_DEBUGPRINT("found %s idle loop %d in block %x\n", thumb ? "thumb" : "arm", cpu->Num, blockAddr); + } + } + else if (hasBranched && (!thumb || cond == 0xE) && !isBackJump && i + 1 < Config::JIT_MaxBlockSize) + { + u32 targetPseudoPhysical = cpu->Num == 0 + ? TranslateAddr<0>(target) + : TranslateAddr<1>(target); + + r15 = target + (thumb ? 2 : 4); + assert(r15 == cpu->R[15]); + + JIT_DEBUGPRINT("block lengthened by static branch (target %x)\n", target); + + nextInstr[0] = cpu->NextInstr[0]; + nextInstr[1] = cpu->NextInstr[1]; + + nextInstrAddr[0] = target; + nextInstrAddr[1] = r15; + + lastSegmentStart = target; + + instrs[i].Info.EndBlock = false; + + if (cond < 0xE) + instrs[i].BranchFlags |= branch_FollowCondTaken; + } + } + + if (!hasBranched && cond < 0xE && i + 1 < Config::JIT_MaxBlockSize) + { + instrs[i].Info.EndBlock = false; + instrs[i].BranchFlags |= branch_FollowCondNotTaken; + } + } + + i++; bool canCompile = compiler->CanCompile(thumb, instrs[i - 1].Info.Kind); - if (instrs[i - 1].Info.ReadFlags != 0 || !canCompile) - floodFillSetFlags(instrs, i - 2, canCompile ? instrs[i - 1].Info.ReadFlags : 0xF); - } while(!instrs[i - 1].Info.EndBlock && i < Config::JIT_MaxBlockSize); + bool secondaryFlagReadCond = !canCompile || (instrs[i - 1].BranchFlags & (branch_FollowCondTaken | branch_FollowCondNotTaken)); + if (instrs[i - 1].Info.ReadFlags != 0 || secondaryFlagReadCond) + FloodFillSetFlags(instrs, i - 2, !secondaryFlagReadCond ? instrs[i - 1].Info.ReadFlags : 0xF); + } while(!instrs[i - 1].Info.EndBlock && i < Config::JIT_MaxBlockSize && !cpu->Halted); - floodFillSetFlags(instrs, i - 1, 0xF); + u32 restoreSlot = HashRestoreCandidate(pseudoPhysicalAddr); + JitBlock* prevBlock = RestoreCandidates[restoreSlot]; + bool mayRestore = true; + if (prevBlock && prevBlock->PseudoPhysicalAddr == pseudoPhysicalAddr) + { + RestoreCandidates[restoreSlot] = NULL; + if (prevBlock->NumInstrs == i) + { + for (int j = 0; j < i; j++) + { + if (prevBlock->Instrs()[j] != instrs[j].Instr) + { + mayRestore = false; + break; + } + } + } + else + mayRestore = false; - CompiledBlock block = compiler->CompileBlock(cpu, instrs, i); + if (prevBlock->NumAddresses == numAddressRanges) + { + for (int j = 0; j < numAddressRanges; j++) + { + if (prevBlock->AddressRanges()[j] != addresseRanges[j]) + { + mayRestore = false; + break; + } + } + } + else + mayRestore = false; + } + else + { + mayRestore = false; + prevBlock = NULL; + } - if (cpu->Num == 0) - InsertBlock<0>(blockAddr, block); + JitBlock* block; + if (!mayRestore) + { + if (prevBlock) + delete prevBlock; + + block = new JitBlock(i, numAddressRanges); + for (int j = 0; j < i; j++) + block->Instrs()[j] = instrs[j].Instr; + for (int j = 0; j < numAddressRanges; j++) + block->AddressRanges()[j] = addresseRanges[j]; + + block->StartAddr = blockAddr; + block->PseudoPhysicalAddr = pseudoPhysicalAddr; + + FloodFillSetFlags(instrs, i - 1, 0xF); + + block->EntryPoint = compiler->CompileBlock(cpu, thumb, instrs, i); + } else - InsertBlock<1>(blockAddr, block); + { + JIT_DEBUGPRINT("restored! %p\n", prevBlock); + block = prevBlock; + } + + for (int j = 0; j < numAddressRanges; j++) + { + assert(addresseRanges[j] == block->AddressRanges()[j]); + CodeRanges[addresseRanges[j] / 256].Blocks.Add(block); + } + + FastBlockAccess[block->PseudoPhysicalAddr / 2] = block->EntryPoint; - return block; + JitBlocks.Add(block); } -void InvalidateBlockCache() +void InvalidateByAddr(u32 pseudoPhysical) { - printf("Resetting JIT block cache...\n"); + JIT_DEBUGPRINT("invalidating by addr %x\n", pseudoPhysical); + AddressRange* range = &CodeRanges[pseudoPhysical / 256]; + int startLength = range->Blocks.Length; + for (int i = 0; i < range->Blocks.Length; i++) + { + assert(range->Blocks.Length == startLength); + JitBlock* block = range->Blocks[i]; + for (int j = 0; j < block->NumAddresses; j++) + { + u32 addr = block->AddressRanges()[j]; + if ((addr / 256) != (pseudoPhysical / 256)) + { + AddressRange* otherRange = &CodeRanges[addr / 256]; + assert(otherRange != range); + assert(otherRange->Blocks.RemoveByValue(block)); + } + } + + assert(JitBlocks.RemoveByValue(block)); + + FastBlockAccess[block->PseudoPhysicalAddr / 2] = NULL; - memset(cache.MainRAM, 0, sizeof(cache.MainRAM)); - memset(cache.SWRAM, 0, sizeof(cache.SWRAM)); - memset(cache.ARM9_BIOS, 0, sizeof(cache.ARM9_BIOS)); - memset(cache.ARM9_ITCM, 0, sizeof(cache.ARM9_ITCM)); - memset(cache.ARM9_LCDC, 0, sizeof(cache.ARM9_LCDC)); - memset(cache.ARM7_BIOS, 0, sizeof(cache.ARM7_BIOS)); - memset(cache.ARM7_WRAM, 0, sizeof(cache.ARM7_WRAM)); - memset(cache.ARM7_WVRAM, 0, sizeof(cache.ARM7_WVRAM)); + u32 slot = HashRestoreCandidate(block->PseudoPhysicalAddr); + if (RestoreCandidates[slot] && RestoreCandidates[slot] != block) + delete RestoreCandidates[slot]; + + RestoreCandidates[slot] = block; + } + if ((range->TimesInvalidated + 1) > range->TimesInvalidated) + range->TimesInvalidated++; + + range->Blocks.Clear(); +} + +void InvalidateByAddr7(u32 addr) +{ + u32 pseudoPhysical = TranslateAddr<1>(addr); + if (__builtin_expect(CodeRanges[pseudoPhysical / 256].Blocks.Length > 0, false)) + InvalidateByAddr(pseudoPhysical); +} + +void InvalidateITCM(u32 addr) +{ + u32 pseudoPhysical = addr + ExeMemRegionOffsets[exeMem_ITCM]; + if (CodeRanges[pseudoPhysical / 256].Blocks.Length > 0) + InvalidateByAddr(pseudoPhysical); +} + +void InvalidateAll() +{ + JIT_DEBUGPRINT("invalidating all %x\n", JitBlocks.Length); + for (int i = 0; i < JitBlocks.Length; i++) + { + JitBlock* block = JitBlocks[i]; + + FastBlockAccess[block->PseudoPhysicalAddr / 2] = NULL; + + for (int j = 0; j < block->NumAddresses; j++) + { + u32 addr = block->AddressRanges()[j]; + AddressRange* range = &CodeRanges[addr / 256]; + range->Blocks.Clear(); + if (range->TimesInvalidated + 1 > range->TimesInvalidated) + range->TimesInvalidated++; + } + + u32 slot = HashRestoreCandidate(block->PseudoPhysicalAddr); + if (RestoreCandidates[slot] && RestoreCandidates[slot] != block) + delete RestoreCandidates[slot]; + + RestoreCandidates[slot] = block; + } + + JitBlocks.Clear(); +} + +void ResetBlockCache() +{ + printf("Resetting JIT block cache...\n"); + + memset(FastBlockAccess, 0, sizeof(FastBlockAccess)); + for (int i = 0; i < sizeof(RestoreCandidates)/sizeof(RestoreCandidates[0]); i++) + { + if (RestoreCandidates[i]) + { + delete RestoreCandidates[i]; + RestoreCandidates[i] = NULL; + } + } + for (int i = 0; i < JitBlocks.Length; i++) + { + JitBlock* block = JitBlocks[i]; + for (int j = 0; j < block->NumAddresses; j++) + { + u32 addr = block->AddressRanges()[j]; + CodeRanges[addr / 256].Blocks.Clear(); + CodeRanges[addr / 256].TimesInvalidated = 0; + } + delete block; + } + JitBlocks.Clear(); compiler->Reset(); } +void* GetFuncForAddr(ARM* cpu, u32 addr, bool store, int size) +{ + if (cpu->Num == 0) + { + if ((addr & 0xFF000000) == 0x04000000) + { + /* + unfortunately we can't map GPU2D this way + since it's hidden inside an object + + though GPU3D registers are accessed much more intensive + */ + if (addr >= 0x04000320 && addr < 0x040006A4) + { + switch (size | store) + { + case 8: return (void*)GPU3D::Read8; + case 9: return (void*)GPU3D::Write8; + case 16: return (void*)GPU3D::Read16; + case 17: return (void*)GPU3D::Write16; + case 32: return (void*)GPU3D::Read32; + case 33: return (void*)GPU3D::Write32; + } + } + + switch (size | store) + { + case 8: return (void*)NDS::ARM9IORead8; + case 9: return (void*)NDS::ARM9IOWrite8; + case 16: return (void*)NDS::ARM9IORead16; + case 17: return (void*)NDS::ARM9IOWrite16; + case 32: return (void*)NDS::ARM9IORead32; + case 33: return (void*)NDS::ARM9IOWrite32; + } + } + } + else + { + switch (addr & 0xFF800000) + { + case 0x04000000: + if (addr >= 0x04000400 && addr < 0x04000520) + { + switch (size | store) + { + case 8: return (void*)SPU::Read8; + case 9: return (void*)SPU::Write8; + case 16: return (void*)SPU::Read16; + case 17: return (void*)SPU::Write16; + case 32: return (void*)SPU::Read32; + case 33: return (void*)SPU::Write32; + } + } + + switch (size | store) + { + case 8: return (void*)NDS::ARM7IORead8; + case 9: return (void*)NDS::ARM7IOWrite8; + case 16: return (void*)NDS::ARM7IORead16; + case 17: return (void*)NDS::ARM7IOWrite16; + case 32: return (void*)NDS::ARM7IORead32; + case 33: return (void*)NDS::ARM7IOWrite32; + } + break; + case 0x04800000: + if (addr < 0x04810000 && size == 16) + { + if (store) + return (void*)Wifi::Write; + else + return (void*)Wifi::Read; + } + break; + } + } + return NULL; +} + } \ No newline at end of file diff --git a/src/ARMJIT.h b/src/ARMJIT.h index 7e448ef..1db4d66 100644 --- a/src/ARMJIT.h +++ b/src/ARMJIT.h @@ -9,142 +9,67 @@ namespace ARMJIT { -typedef u32 (*CompiledBlock)(); - -struct FetchedInstr +enum ExeMemKind { - u32 A_Reg(int pos) const - { - return (Instr >> pos) & 0xF; - } - - u32 T_Reg(int pos) const - { - return (Instr >> pos) & 0x7; - } - - u32 Cond() const - { - return Instr >> 28; - } - - u8 SetFlags; - u32 Instr; - u32 NextInstr[2]; - u32 Addr; - - u8 CodeCycles; - - ARMInstrInfo::Info Info; + exeMem_Unmapped = 0, + exeMem_ITCM, + exeMem_MainRAM, + exeMem_SWRAM, + exeMem_LCDC, + exeMem_ARM9_BIOS, + exeMem_ARM7_BIOS, + exeMem_ARM7_WRAM, + exeMem_ARM7_WVRAM, + exeMem_Count }; -/* - Copied from DeSmuME - Some names where changed to match the nomenclature of melonDS +extern const u32 ExeMemRegionOffsets[]; +extern const u32 ExeMemRegionSizes[]; - Since it's nowhere explained and atleast I needed some time to get behind it, - here's a summary on how it works: - more or less all memory locations from which code can be executed are - represented by an array of function pointers, which point to null or - a function which executes a block instructions starting from there. +typedef u32 (*JitBlockEntry)(); - The most significant 4 bits of each address is ignored. This 28 bit space is - divided into 0x2000 32 KB for ARM9 and 0x4000 16 KB for ARM7, each of which - a pointer to the relevant place inside the afore mentioned arrays. 32 and 16 KB - are the sizes of the smallest contigous memory region mapped to the respective CPU. - Because ARM addresses are always aligned to 4 bytes and Thumb to a 2 byte boundary, - we only need every second half word to be adressable. +extern u32 AddrTranslate9[0x2000]; +extern u32 AddrTranslate7[0x4000]; - In case a memory write hits mapped memory, the function block at this - address is set to null, so it's recompiled the next time it's executed. - - This method has disadvantages, namely that only writing to the - first instruction of a block marks it as invalid and that memory remapping - (SWRAM and VRAM) isn't taken into account. -*/ - -struct BlockCache -{ - CompiledBlock* AddrMapping9[0x2000] = {0}; - CompiledBlock* AddrMapping7[0x4000] = {0}; - - CompiledBlock MainRAM[4*1024*1024/2]; - CompiledBlock SWRAM[0x8000/2]; // Shared working RAM - CompiledBlock ARM9_ITCM[0x8000/2]; - CompiledBlock ARM9_LCDC[0xA4000/2]; - CompiledBlock ARM9_BIOS[0x8000/2]; - CompiledBlock ARM7_BIOS[0x4000/2]; - CompiledBlock ARM7_WRAM[0x10000/2]; // dedicated ARM7 WRAM - CompiledBlock ARM7_WVRAM[0x40000/2]; // VRAM allocated as Working RAM -}; - -extern BlockCache cache; +const u32 ExeMemSpaceSize = 0x518000; // I hate you C++, sometimes I really hate you... +extern JitBlockEntry FastBlockAccess[ExeMemSpaceSize / 2]; template inline bool IsMapped(u32 addr) { if (num == 0) - return cache.AddrMapping9[(addr & 0xFFFFFFF) >> 15]; + return AddrTranslate9[(addr & 0xFFFFFFF) >> 15] >= ExeMemRegionSizes[exeMem_Unmapped]; else - return cache.AddrMapping7[(addr & 0xFFFFFFF) >> 14]; + return AddrTranslate7[(addr & 0xFFFFFFF) >> 14] >= ExeMemRegionSizes[exeMem_Unmapped]; } template -inline CompiledBlock LookUpBlock(u32 addr) +inline u32 TranslateAddr(u32 addr) { if (num == 0) - return cache.AddrMapping9[(addr & 0xFFFFFFF) >> 15][(addr & 0x7FFF) >> 1]; + return AddrTranslate9[(addr & 0xFFFFFFF) >> 15] + (addr & 0x7FFF); else - return cache.AddrMapping7[(addr & 0xFFFFFFF) >> 14][(addr & 0x3FFF) >> 1]; + return AddrTranslate7[(addr & 0xFFFFFFF) >> 14] + (addr & 0x3FFF); } template -inline void Invalidate16(u32 addr) +inline JitBlockEntry LookUpBlock(u32 addr) { - if (IsMapped(addr)) - { - if (num == 0) - cache.AddrMapping9[(addr & 0xFFFFFFF) >> 15][(addr & 0x7FFF) >> 1] = NULL; - else - cache.AddrMapping7[(addr & 0xFFFFFFF) >> 14][(addr & 0x3FFF) >> 1] = NULL; - } -} - -template -inline void Invalidate32(u32 addr) -{ - if (IsMapped(addr)) - { - if (num == 0) - { - CompiledBlock* page = cache.AddrMapping9[(addr & 0xFFFFFFF) >> 15]; - page[(addr & 0x7FFF) >> 1] = NULL; - page[((addr + 2) & 0x7FFF) >> 1] = NULL; - } - else - { - CompiledBlock* page = cache.AddrMapping7[(addr & 0xFFFFFFF) >> 14]; - page[(addr & 0x3FFF) >> 1] = NULL; - page[((addr + 2) & 0x3FFF) >> 1] = NULL; - } - } -} - -template -inline void InsertBlock(u32 addr, CompiledBlock func) -{ - if (num == 0) - cache.AddrMapping9[(addr & 0xFFFFFFF) >> 15][(addr & 0x7FFF) >> 1] = func; - else - cache.AddrMapping7[(addr & 0xFFFFFFF) >> 14][(addr & 0x3FFF) >> 1] = func; + return FastBlockAccess[TranslateAddr(addr) / 2]; } void Init(); void DeInit(); -CompiledBlock CompileBlock(ARM* cpu); +void InvalidateByAddr(u32 pseudoPhysical); +void InvalidateAll(); + +void InvalidateITCM(u32 addr); +void InvalidateByAddr7(u32 addr); + +void CompileBlock(ARM* cpu); -void InvalidateBlockCache(); +void ResetBlockCache(); } diff --git a/src/ARMJIT_Internal.h b/src/ARMJIT_Internal.h new file mode 100644 index 0000000..4acb488 --- /dev/null +++ b/src/ARMJIT_Internal.h @@ -0,0 +1,198 @@ +#ifndef ARMJIT_INTERNAL_H +#define ARMJIT_INTERNAL_H + +#include "types.h" +#include + +#include "ARMJIT.h" + +// here lands everything which doesn't fit into ARMJIT.h +// where it would be included by pretty much everything +namespace ARMJIT +{ + +enum +{ + branch_IdleBranch = 1 << 0, + branch_FollowCondTaken = 1 << 1, + branch_FollowCondNotTaken = 1 << 2 +}; + +struct FetchedInstr +{ + u32 A_Reg(int pos) const + { + return (Instr >> pos) & 0xF; + } + + u32 T_Reg(int pos) const + { + return (Instr >> pos) & 0x7; + } + + u32 Cond() const + { + return Instr >> 28; + } + + u8 BranchFlags; + u8 SetFlags; + u32 Instr; + u32 NextInstr[2]; + u32 Addr; + + u8 CodeCycles; + u8 DataCycles; + u8 DataRegion; + + ARMInstrInfo::Info Info; +}; + +/* + TinyVector + - because reinventing the wheel is the best! + + - meant to be used very often, with not so many elements + max 1 << 16 elements + - doesn't allocate while no elements are inserted + - not stl confirmant of course + - probably only works with POD types + - remove operations don't preserve order, but O(1)! +*/ +template +struct __attribute__((packed)) TinyVector +{ + T* Data = NULL; + u16 Capacity = 0; + u32 Length = 0; // make it 32 bit so we don't need movzx + + ~TinyVector() + { + delete[] Data; + } + + void MakeCapacity(u32 capacity) + { + assert(capacity <= UINT16_MAX); + assert(capacity > Capacity); + T* newMem = new T[capacity]; + if (Data != NULL) + memcpy(newMem, Data, sizeof(Data) * Length); + + T* oldData = Data; + Data = newMem; + if (oldData != NULL) + delete[] oldData; + + Capacity = capacity; + } + + void Clear() + { + Length = 0; + } + + void Add(T element) + { + assert(Length + 1 <= UINT16_MAX); + if (Length + 1 > Capacity) + MakeCapacity(((Capacity + 4) * 3) / 2); + + Data[Length++] = element; + } + + void Remove(int index) + { + assert(index >= 0 && index < Length); + + Length--; + Data[index] = Data[Length]; + /*for (int i = index; i < Length; i++) + Data[i] = Data[i + 1];*/ + } + + int Find(T needle) + { + for (int i = 0; i < Length; i++) + { + if (Data[i] == needle) + return i; + } + return -1; + } + + bool RemoveByValue(T needle) + { + for (int i = 0; i < Length; i++) + { + if (Data[i] == needle) + { + Remove(i); + return true; + } + } + return false; + } + + T& operator[](int index) + { + assert(index >= 0 && index < Length); + return Data[index]; + } +}; + +class JitBlock +{ +public: + JitBlock(u32 numInstrs, u32 numAddresses) + { + NumInstrs = numInstrs; + NumAddresses = numAddresses; + Data = new u32[numInstrs + numAddresses]; + } + + ~JitBlock() + { + delete[] Data; + } + + u32 StartAddr; + u32 PseudoPhysicalAddr; + + u32 NumInstrs; + u32 NumAddresses; + + JitBlockEntry EntryPoint; + + u32* Instrs() + { return Data; } + u32* AddressRanges() + { return Data + NumInstrs; } + +private: + /* + 0.. Blocks; + u16 TimesInvalidated; +}; + +extern AddressRange CodeRanges[ExeMemSpaceSize / 256]; + +typedef void (*InterpreterFunc)(ARM* cpu); +extern InterpreterFunc InterpretARM[]; +extern InterpreterFunc InterpretTHUMB[]; + +void* GetFuncForAddr(ARM* cpu, u32 addr, bool store, int size); + +} + +#endif \ No newline at end of file diff --git a/src/ARMJIT_RegisterCache.h b/src/ARMJIT_RegisterCache.h index fe2f203..ed6a2b7 100644 --- a/src/ARMJIT_RegisterCache.h +++ b/src/ARMJIT_RegisterCache.h @@ -60,15 +60,46 @@ public: assert("Welp!"); } + void PutLiteral(int reg, u32 val) + { + LiteralsLoaded |= (1 << reg); + LiteralValues[reg] = val; + } + + void UnloadLiteral(int reg) + { + LiteralsLoaded &= ~(1 << reg); + } + + bool IsLiteral(int reg) + { + return LiteralsLoaded & (1 << reg); + } + + void PrepareExit() + { + BitSet16 dirtyRegs(DirtyRegs); + for (int reg : dirtyRegs) + Compiler->SaveReg(reg, Mapping[reg]); + } + void Flush() { BitSet16 loadedSet(LoadedRegs); for (int reg : loadedSet) UnloadRegister(reg); + LiteralsLoaded = 0; } void Prepare(bool thumb, int i) { + if (LoadedRegs & (1 << 15)) + UnloadRegister(15); + + BitSet16 invalidedLiterals(LiteralsLoaded & Instrs[i].Info.DstRegs); + for (int reg : invalidedLiterals) + UnloadLiteral(reg); + u16 futureNeeded = 0; int ranking[16]; for (int j = 0; j < 16; j++) @@ -86,7 +117,7 @@ public: for (int reg : neverNeededAgain) UnloadRegister(reg); - FetchedInstr Instr = Instrs[i]; + FetchedInstr Instr = Instrs[i]; u16 necessaryRegs = (Instr.Info.SrcRegs & ~(1 << 15)) | Instr.Info.DstRegs; BitSet16 needToBeLoaded(necessaryRegs & ~LoadedRegs); if (needToBeLoaded != BitSet16(0)) @@ -125,6 +156,9 @@ public: static const int NativeRegsAvailable; Reg Mapping[16]; + u32 LiteralValues[16]; + + u16 LiteralsLoaded = 0; u32 NativeRegsUsed = 0; u16 LoadedRegs = 0; u16 DirtyRegs = 0; diff --git a/src/ARMJIT_x64/ARMJIT_ALU.cpp b/src/ARMJIT_x64/ARMJIT_ALU.cpp index f868ddf..14c223b 100644 --- a/src/ARMJIT_x64/ARMJIT_ALU.cpp +++ b/src/ARMJIT_x64/ARMJIT_ALU.cpp @@ -213,7 +213,13 @@ void Compiler::A_Comp_MovOp() MOV(32, rd, op2); if (((CurInstr.Instr >> 21) & 0xF) == 0xF) + { NOT(32, rd); + if (op2.IsImm() && CurInstr.Cond() == 0xE) + RegCache.PutLiteral(CurInstr.A_Reg(12), ~op2.Imm32()); + } + else if (op2.IsImm() && CurInstr.Cond() == 0xE) + RegCache.PutLiteral(CurInstr.A_Reg(12), op2.Imm32()); if (S) { @@ -564,7 +570,13 @@ void Compiler::T_Comp_AddSub_() Comp_AddCycles_C(); - if (op & 1) + // special case for thumb mov being alias to add rd, rn, #0 + if (CurInstr.SetFlags == 0 && rn.IsImm() && rn.Imm32() == 0) + { + if (rd != rs) + MOV(32, rd, rs); + } + else if (op & 1) Comp_ArithTriOp(&Compiler::SUB, rd, rs, rn, false, opSetsFlags|opInvertCarry|opRetriveCV); else Comp_ArithTriOp(&Compiler::ADD, rd, rs, rn, false, opSetsFlags|opSymmetric|opRetriveCV); @@ -614,7 +626,7 @@ void Compiler::T_Comp_ALU() u32 op = (CurInstr.Instr >> 6) & 0xF; if ((op >= 0x2 && op < 0x4) || op == 0x7) - Comp_AddCycles_CI(1); + Comp_AddCycles_CI(1); // shift by reg else Comp_AddCycles_C(); diff --git a/src/ARMJIT_x64/ARMJIT_Branch.cpp b/src/ARMJIT_x64/ARMJIT_Branch.cpp index cc7a3c4..0dedb3f 100644 --- a/src/ARMJIT_x64/ARMJIT_Branch.cpp +++ b/src/ARMJIT_x64/ARMJIT_Branch.cpp @@ -16,9 +16,6 @@ int squeezePointer(T* ptr) void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) { // we can simplify constant branches by a lot - // it's not completely safe to assume stuff like, which instructions to preload - // we'll see how it works out - IrregularCycles = true; u32 newPC; @@ -39,18 +36,12 @@ void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) { ARMv5* cpu9 = (ARMv5*)CurCPU; - u32 oldregion = R15 >> 24; - u32 newregion = addr >> 24; - u32 regionCodeCycles = cpu9->MemTimings[addr >> 12][0]; u32 compileTimeCodeCycles = cpu9->RegionCodeCycles; cpu9->RegionCodeCycles = regionCodeCycles; - MOV(32, MDisp(RCPU, offsetof(ARMv5, RegionCodeCycles)), Imm32(regionCodeCycles)); - - bool setupRegion = newregion != oldregion; - if (setupRegion) - cpu9->SetupCodeMem(addr); + if (Exit) + MOV(32, MDisp(RCPU, offsetof(ARMv5, RegionCodeCycles)), Imm32(regionCodeCycles)); if (addr & 0x1) { @@ -83,12 +74,7 @@ void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) cycles += cpu9->CodeCycles; } - MOV(64, MDisp(RCPU, offsetof(ARM, CodeMem.Mem)), Imm32(squeezePointer(cpu9->CodeMem.Mem))); - MOV(32, MDisp(RCPU, offsetof(ARM, CodeMem.Mask)), Imm32(cpu9->CodeMem.Mask)); - cpu9->RegionCodeCycles = compileTimeCodeCycles; - if (setupRegion) - cpu9->SetupCodeMem(R15); } else { @@ -100,8 +86,11 @@ void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) cpu7->CodeRegion = codeRegion; cpu7->CodeCycles = codeCycles; - MOV(32, MDisp(RCPU, offsetof(ARM, CodeRegion)), Imm32(codeRegion)); - MOV(32, MDisp(RCPU, offsetof(ARM, CodeCycles)), Imm32(codeCycles)); + if (Exit) + { + MOV(32, MDisp(RCPU, offsetof(ARM, CodeRegion)), Imm32(codeRegion)); + MOV(32, MDisp(RCPU, offsetof(ARM, CodeCycles)), Imm32(codeCycles)); + } if (addr & 0x1) { @@ -133,7 +122,8 @@ void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) cpu7->CodeCycles = addr >> 15; } - MOV(32, MDisp(RCPU, offsetof(ARM, R[15])), Imm32(newPC)); + if (Exit) + MOV(32, MDisp(RCPU, offsetof(ARM, R[15])), Imm32(newPC)); if ((Thumb || CurInstr.Cond() >= 0xE) && !forceNonConstantCycles) ConstantCycles += cycles; else @@ -219,10 +209,23 @@ void Compiler::T_Comp_BCOND() s32 offset = (s32)(CurInstr.Instr << 24) >> 23; Comp_JumpTo(R15 + offset + 1, true); + Comp_SpecialBranchBehaviour(); + FixupBranch skipFailed = J(); SetJumpTarget(skipExecute); + + if (CurInstr.BranchFlags & branch_FollowCondTaken) + { + RegCache.PrepareExit(); + SaveCPSR(false); + + MOV(32, R(RAX), Imm32(ConstantCycles)); + ABI_PopRegistersAndAdjustStack(BitSet32(ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS & ~BitSet32({RSP})), 8); + RET(); + } + Comp_AddCycles_C(true); - SetJumpTarget(skipFailed); + SetJumpTarget(skipFailed); } void Compiler::T_Comp_B() diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index d8ce1aa..25c55a3 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -72,12 +72,15 @@ Compiler::Compiler() for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) - { MemoryFuncs9[i][j] = Gen_MemoryRoutine9(j, 8 << i); - MemoryFuncs7[i][j][0] = Gen_MemoryRoutine7(j, false, 8 << i); - MemoryFuncs7[i][j][1] = Gen_MemoryRoutine7(j, true, 8 << i); - } } + MemoryFuncs7[0][0] = (void*)NDS::ARM7Read8; + MemoryFuncs7[0][1] = (void*)NDS::ARM7Write8; + MemoryFuncs7[1][0] = (void*)NDS::ARM7Read16; + MemoryFuncs7[1][1] = (void*)NDS::ARM7Write16; + MemoryFuncs7[2][0] = (void*)NDS::ARM7Read32; + MemoryFuncs7[2][1] = (void*)NDS::ARM7Write32; + for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) { @@ -179,12 +182,13 @@ void Compiler::LoadCPSR() MOV(32, R(RCPSR), MDisp(RCPU, offsetof(ARM, CPSR))); } -void Compiler::SaveCPSR() +void Compiler::SaveCPSR(bool flagClean) { if (CPSRDirty) { MOV(32, MDisp(RCPU, offsetof(ARM, CPSR)), R(RCPSR)); - CPSRDirty = false; + if (flagClean) + CPSRDirty = false; } } @@ -204,6 +208,9 @@ void Compiler::SaveReg(int reg, X64Reg nativeReg) // invalidates RSCRATCH and RSCRATCH3 Gen::FixupBranch Compiler::CheckCondition(u32 cond) { + // hack, ldm/stm can get really big TODO: make this better + bool ldmStm = !Thumb && + (CurInstr.Info.Kind == ARMInstrInfo::ak_LDM || CurInstr.Info.Kind == ARMInstrInfo::ak_STM); if (cond >= 0x8) { static_assert(RSCRATCH3 == ECX, "RSCRATCH has to be equal to ECX!"); @@ -213,14 +220,14 @@ Gen::FixupBranch Compiler::CheckCondition(u32 cond) SHL(32, R(RSCRATCH), R(RSCRATCH3)); TEST(32, R(RSCRATCH), Imm32(ARM::ConditionTable[cond])); - return J_CC(CC_Z); + return J_CC(CC_Z, ldmStm); } else { // could have used a LUT, but then where would be the fun? TEST(32, R(RCPSR), Imm32(1 << (28 + ((~(cond >> 1) & 1) << 1 | (cond >> 2 & 1) ^ (cond >> 1 & 1))))); - return J_CC(cond & 1 ? CC_NZ : CC_Z); + return J_CC(cond & 1 ? CC_NZ : CC_Z, ldmStm); } } @@ -354,25 +361,34 @@ void Compiler::Reset() SetCodePtr(ResetStart); } -CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrsCount) +void Compiler::Comp_SpecialBranchBehaviour() +{ + if (CurInstr.BranchFlags & branch_IdleBranch) + OR(32, MDisp(RCPU, offsetof(ARM, Halted)), Imm8(0x20)); + + if (CurInstr.BranchFlags & branch_FollowCondNotTaken) + { + RegCache.PrepareExit(); + SaveCPSR(false); + + MOV(32, R(RAX), Imm32(ConstantCycles)); + ABI_PopRegistersAndAdjustStack(BitSet32(ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS & ~BitSet32({RSP})), 8); + RET(); + } +} + +JitBlockEntry Compiler::CompileBlock(ARM* cpu, bool thumb, FetchedInstr instrs[], int instrsCount) { if (CodeMemSize - (GetWritableCodePtr() - ResetStart) < 1024 * 32) // guess... - InvalidateBlockCache(); + ResetBlockCache(); ConstantCycles = 0; - Thumb = cpu->CPSR & 0x20; + Thumb = thumb; Num = cpu->Num; - CodeRegion = cpu->CodeRegion; + CodeRegion = instrs[0].Addr >> 24; CurCPU = cpu; - CompiledBlock res = (CompiledBlock)GetWritableCodePtr(); - - if (!(Num == 0 - ? IsMapped<0>(instrs[0].Addr - (Thumb ? 2 : 4)) - : IsMapped<1>(instrs[0].Addr - (Thumb ? 2 : 4)))) - { - printf("Trying to compile a block in unmapped memory\n"); - } + JitBlockEntry res = (JitBlockEntry)GetWritableCodePtr(); ABI_PushRegistersAndAdjustStack(BitSet32(ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS & ~BitSet32({RSP})), 8); @@ -380,7 +396,6 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs LoadCPSR(); - // TODO: this is ugly as a whole, do better RegCache = RegisterCache(this, instrs, instrsCount); for (int i = 0; i < instrsCount; i++) @@ -388,21 +403,25 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs CurInstr = instrs[i]; R15 = CurInstr.Addr + (Thumb ? 4 : 8); + Exit = i == instrsCount - 1 || (CurInstr.BranchFlags & branch_FollowCondNotTaken); + CompileFunc comp = Thumb ? T_Comp[CurInstr.Info.Kind] : A_Comp[CurInstr.Info.Kind]; bool isConditional = Thumb ? CurInstr.Info.Kind == ARMInstrInfo::tk_BCOND : CurInstr.Cond() < 0xE; - if (comp == NULL || (i == instrsCount - 1 && (!CurInstr.Info.Branches() || isConditional))) + if (comp == NULL || (CurInstr.BranchFlags & branch_FollowCondTaken) || (i == instrsCount - 1 && (!CurInstr.Info.Branches() || isConditional))) { MOV(32, MDisp(RCPU, offsetof(ARM, R[15])), Imm32(R15)); - MOV(32, MDisp(RCPU, offsetof(ARM, CodeCycles)), Imm32(CurInstr.CodeCycles)); - MOV(32, MDisp(RCPU, offsetof(ARM, CurInstr)), Imm32(CurInstr.Instr)); - if (comp == NULL) + { + MOV(32, MDisp(RCPU, offsetof(ARM, CodeCycles)), Imm32(CurInstr.CodeCycles)); + MOV(32, MDisp(RCPU, offsetof(ARM, CurInstr)), Imm32(CurInstr.Instr)); + SaveCPSR(); + } } - + if (comp != NULL) RegCache.Prepare(Thumb, i); else @@ -410,12 +429,11 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs if (Thumb) { - u32 icode = (CurInstr.Instr >> 6) & 0x3FF; if (comp == NULL) { MOV(64, R(ABI_PARAM1), R(RCPU)); - ABI_CallFunction(ARMInterpreter::THUMBInstrTable[icode]); + ABI_CallFunction(InterpretTHUMB[CurInstr.Info.Kind]); } else (this->*comp)(); @@ -434,7 +452,9 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs } } else if (cond == 0xF) + { Comp_AddCycles_C(); + } else { IrregularCycles = false; @@ -443,25 +463,36 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs if (cond < 0xE) skipExecute = CheckCondition(cond); - u32 icode = ((CurInstr.Instr >> 4) & 0xF) | ((CurInstr.Instr >> 16) & 0xFF0); if (comp == NULL) { MOV(64, R(ABI_PARAM1), R(RCPU)); - ABI_CallFunction(ARMInterpreter::ARMInstrTable[icode]); + ABI_CallFunction(InterpretARM[CurInstr.Info.Kind]); } else (this->*comp)(); + Comp_SpecialBranchBehaviour(); + if (CurInstr.Cond() < 0xE) { - if (IrregularCycles) + if (IrregularCycles || (CurInstr.BranchFlags & branch_FollowCondTaken)) { FixupBranch skipFailed = J(); SetJumpTarget(skipExecute); Comp_AddCycles_C(true); + if (CurInstr.BranchFlags & branch_FollowCondTaken) + { + RegCache.PrepareExit(); + SaveCPSR(false); + + MOV(32, R(RAX), Imm32(ConstantCycles)); + ABI_PopRegistersAndAdjustStack(BitSet32(ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS & ~BitSet32({RSP})), 8); + RET(); + } + SetJumpTarget(skipFailed); } else @@ -483,6 +514,12 @@ CompiledBlock Compiler::CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrs ABI_PopRegistersAndAdjustStack(BitSet32(ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS & ~BitSet32({RSP})), 8); RET(); + /*FILE* codeout = fopen("codeout", "a"); + fprintf(codeout, "beginning block argargarg__ %x!!!", instrs[0].Addr); + fwrite((u8*)res, GetWritableCodePtr() - (u8*)res, 1, codeout); + + fclose(codeout);*/ + return res; } @@ -528,4 +565,89 @@ void Compiler::Comp_AddCycles_CI(Gen::X64Reg i, int add) } } +void Compiler::Comp_AddCycles_CDI() +{ + if (Num == 0) + Comp_AddCycles_CD(); + else + { + IrregularCycles = true; + + s32 cycles; + + s32 numC = NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2]; + s32 numD = CurInstr.DataCycles; + + if (CurInstr.DataRegion == 0x02) // mainRAM + { + if (CodeRegion == 0x02) + cycles = numC + numD; + else + { + numC++; + cycles = std::max(numC + numD - 3, std::max(numC, numD)); + } + } + else if (CodeRegion == 0x02) + { + numD++; + cycles = std::max(numC + numD - 3, std::max(numC, numD)); + } + else + { + cycles = numC + numD + 1; + } + + printf("%x: %d %d cycles cdi (%d)\n", CurInstr.Instr, Num, CurInstr.DataCycles, cycles); + + if (!Thumb && CurInstr.Cond() < 0xE) + ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm8(cycles)); + else + ConstantCycles += cycles; + } +} + +void Compiler::Comp_AddCycles_CD() +{ + u32 cycles = 0; + if (Num == 0) + { + s32 numC = (R15 & 0x2) ? 0 : CurInstr.CodeCycles; + s32 numD = CurInstr.DataCycles; + + //if (DataRegion != CodeRegion) + cycles = std::max(numC + numD - 6, std::max(numC, numD)); + + IrregularCycles = cycles != numC; + } + else + { + s32 numC = NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2]; + s32 numD = CurInstr.DataCycles; + + if (CurInstr.DataRegion == 0x02) + { + if (CodeRegion == 0x02) + cycles += numC + numD; + else + cycles += std::max(numC + numD - 3, std::max(numC, numD)); + } + else if (CodeRegion == 0x02) + { + cycles += std::max(numC + numD - 3, std::max(numC, numD)); + } + else + { + cycles += numC + numD; + } + + IrregularCycles = true; + } + + if (!Thumb && CurInstr.Cond() < 0xE) + ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm8(cycles)); + else + ConstantCycles += cycles; +} + } \ No newline at end of file diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index fcb2380..792ff66 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -4,6 +4,7 @@ #include "../dolphin/x64Emitter.h" #include "../ARMJIT.h" +#include "../ARMJIT_Internal.h" #include "../ARMJIT_RegisterCache.h" namespace ARMJIT @@ -16,6 +17,32 @@ const Gen::X64Reg RSCRATCH = Gen::EAX; const Gen::X64Reg RSCRATCH2 = Gen::EDX; const Gen::X64Reg RSCRATCH3 = Gen::ECX; +struct ComplexOperand +{ + ComplexOperand() + {} + + ComplexOperand(u32 imm) + : IsImm(true), Imm(imm) + {} + ComplexOperand(int reg, int op, int amount) + : IsImm(false) + { + Reg.Reg = reg; + Reg.Op = op; + Reg.Amount = amount; + } + + bool IsImm; + union + { + struct + { + int Reg, Op, Amount; + } Reg; + u32 Imm; + }; +}; class Compiler : public Gen::XEmitter { @@ -24,7 +51,7 @@ public: void Reset(); - CompiledBlock CompileBlock(ARM* cpu, FetchedInstr instrs[], int instrsCount); + JitBlockEntry CompileBlock(ARM* cpu, bool thumb, FetchedInstr instrs[], int instrsCount); void LoadReg(int reg, Gen::X64Reg nativeReg); void SaveReg(int reg, Gen::X64Reg nativeReg); @@ -39,6 +66,8 @@ public: void Comp_AddCycles_C(bool forceNonConstant = false); void Comp_AddCycles_CI(u32 i); void Comp_AddCycles_CI(Gen::X64Reg i, int add); + void Comp_AddCycles_CDI(); + void Comp_AddCycles_CD(); enum { @@ -92,8 +121,17 @@ public: void T_Comp_BL_LONG_2(); void T_Comp_BL_Merged(); - void Comp_MemAccess(Gen::OpArg rd, bool signExtend, bool store, int size); + enum + { + memop_Writeback = 1 << 0, + memop_Post = 1 << 1, + memop_SignExtend = 1 << 2, + memop_Store = 1 << 3, + memop_SubtractOffset = 1 << 4 + }; + void Comp_MemAccess(int rd, int rn, const ComplexOperand& op2, int size, int flags); s32 Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc, bool decrement, bool usermode); + void Comp_MemLoadLiteral(int size, int rd, u32 addr); void Comp_ArithTriOp(void (Compiler::*op)(int, const Gen::OpArg&, const Gen::OpArg&), Gen::OpArg rd, Gen::OpArg rn, Gen::OpArg op2, bool carryUsed, int opFlags); @@ -105,8 +143,9 @@ public: void Comp_RetriveFlags(bool sign, bool retriveCV, bool carryUsed); + void Comp_SpecialBranchBehaviour(); + void* Gen_MemoryRoutine9(bool store, int size); - void* Gen_MemoryRoutine7(bool store, bool codeMainRAM, int size); void* Gen_MemoryRoutineSeq9(bool store, bool preinc); void* Gen_MemoryRoutineSeq7(bool store, bool preinc, bool codeMainRAM); @@ -117,10 +156,9 @@ public: Gen::OpArg Comp_RegShiftReg(int op, Gen::OpArg rs, Gen::OpArg rm, bool S, bool& carryUsed); Gen::OpArg A_Comp_GetALUOp2(bool S, bool& carryUsed); - Gen::OpArg A_Comp_GetMemWBOffset(); void LoadCPSR(); - void SaveCPSR(); + void SaveCPSR(bool flagClean = true); bool FlagsNZRequired() { return CurInstr.SetFlags & 0xC; } @@ -139,10 +177,11 @@ public: u8* ResetStart; u32 CodeMemSize; + bool Exit; bool IrregularCycles; void* MemoryFuncs9[3][2]; - void* MemoryFuncs7[3][2][2]; + void* MemoryFuncs7[3][2]; void* MemoryFuncsSeq9[2][2]; void* MemoryFuncsSeq7[2][2][2]; diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index bf8280d..13ca415 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -27,51 +27,7 @@ int squeezePointer(T* ptr) /* address - ABI_PARAM1 (a.k.a. ECX = RSCRATCH3 on Windows) store value - ABI_PARAM2 (a.k.a. RDX = RSCRATCH2 on Windows) - code cycles - ABI_PARAM3 */ - -#define CALC_CYCLES_9(numC, numD, scratch) \ - LEA(32, scratch, MComplex(numD, numC, SCALE_1, -6)); \ - CMP(32, R(numC), R(numD)); \ - CMOVcc(32, numD, R(numC), CC_G); \ - CMP(32, R(numD), R(scratch)); \ - CMOVcc(32, scratch, R(numD), CC_G); \ - ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(scratch)); -#define CALC_CYCLES_7_DATA_MAIN_RAM(numC, numD, scratch) \ - if (codeMainRAM) \ - { \ - LEA(32, scratch, MRegSum(numD, numC)); \ - ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(scratch)); \ - } \ - else \ - { \ - if (!store) \ - ADD(32, R(numC), Imm8(1)); \ - LEA(32, scratch, MComplex(numD, numC, SCALE_1, -3)); \ - CMP(32, R(numD), R(numC)); \ - CMOVcc(32, numC, R(numD), CC_G); \ - CMP(32, R(numC), R(scratch)); \ - CMOVcc(32, scratch, R(numC), CC_G); \ - ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(scratch)); \ - } -#define CALC_CYCLES_7_DATA_NON_MAIN_RAM(numC, numD, scratch) \ - if (codeMainRAM) \ - { \ - if (!store) \ - ADD(32, R(numD), Imm8(1)); \ - LEA(32, scratch, MComplex(numD, numC, SCALE_1, -3)); \ - CMP(32, R(numD), R(numC)); \ - CMOVcc(32, numC, R(numD), CC_G); \ - CMP(32, R(numC), R(scratch)); \ - CMOVcc(32, scratch, R(numC), CC_G); \ - ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(scratch)); \ - } \ - else \ - { \ - LEA(32, scratch, MComplex(numD, numC, SCALE_1, store ? 0 : 1)); \ - ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(scratch)); \ - } - void* Compiler::Gen_MemoryRoutine9(bool store, int size) { u32 addressMask = ~(size == 32 ? 3 : (size == 16 ? 1 : 0)); @@ -86,12 +42,6 @@ void* Compiler::Gen_MemoryRoutine9(bool store, int size) CMP(32, R(ABI_PARAM1), MDisp(RCPU, offsetof(ARMv5, ITCMSize))); FixupBranch insideITCM = J_CC(CC_B); - // cycle counting! - MOV(32, R(ABI_PARAM4), R(ABI_PARAM1)); - SHR(32, R(ABI_PARAM4), Imm8(12)); - MOVZX(32, 8, ABI_PARAM4, MComplex(RCPU, ABI_PARAM4, SCALE_4, offsetof(ARMv5, MemTimings) + (size == 32 ? 2 : 1))); - CALC_CYCLES_9(ABI_PARAM3, ABI_PARAM4, RSCRATCH) - if (store) { if (size > 8) @@ -127,7 +77,6 @@ void* Compiler::Gen_MemoryRoutine9(bool store, int size) } SetJumpTarget(insideDTCM); - ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(ABI_PARAM3)); AND(32, R(RSCRATCH), Imm32(0x3FFF & addressMask)); if (store) MOV(size, MComplex(RCPU, RSCRATCH, SCALE_1, offsetof(ARMv5, DTCM)), R(ABI_PARAM2)); @@ -146,16 +95,22 @@ void* Compiler::Gen_MemoryRoutine9(bool store, int size) RET(); SetJumpTarget(insideITCM); - ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(ABI_PARAM3)); MOV(32, R(ABI_PARAM3), R(ABI_PARAM1)); // free up ECX AND(32, R(ABI_PARAM3), Imm32(0x7FFF & addressMask)); if (store) { MOV(size, MComplex(RCPU, ABI_PARAM3, SCALE_1, offsetof(ARMv5, ITCM)), R(ABI_PARAM2)); - XOR(32, R(RSCRATCH), R(RSCRATCH)); - MOV(64, MScaled(ABI_PARAM3, SCALE_4, squeezePointer(cache.ARM9_ITCM)), R(RSCRATCH)); - if (size == 32) - MOV(64, MScaled(ABI_PARAM3, SCALE_4, squeezePointer(cache.ARM9_ITCM) + 8), R(RSCRATCH)); + + // if CodeRanges[pseudoPhysical/256].Blocks.Length > 0 we're writing into code! + static_assert(sizeof(AddressRange) == 16); + LEA(32, ABI_PARAM1, MDisp(ABI_PARAM3, ExeMemRegionOffsets[exeMem_ITCM])); + MOV(32, R(RSCRATCH), R(ABI_PARAM1)); + SHR(32, R(RSCRATCH), Imm8(8)); + SHL(32, R(RSCRATCH), Imm8(4)); + CMP(32, MDisp(RSCRATCH, squeezePointer(CodeRanges) + offsetof(AddressRange, Blocks.Length)), Imm8(0)); + FixupBranch noCode = J_CC(CC_Z); + JMP((u8*)InvalidateByAddr, true); + SetJumpTarget(noCode); } else { @@ -176,83 +131,6 @@ void* Compiler::Gen_MemoryRoutine9(bool store, int size) return res; } -void* Compiler::Gen_MemoryRoutine7(bool store, bool codeMainRAM, int size) -{ - u32 addressMask = ~(size == 32 ? 3 : (size == 16 ? 1 : 0)); - AlignCode4(); - void* res = GetWritableCodePtr(); - - MOV(32, R(RSCRATCH), R(ABI_PARAM1)); - SHR(32, R(RSCRATCH), Imm8(15)); - MOVZX(32, 8, ABI_PARAM4, MScaled(RSCRATCH, SCALE_4, (size == 32 ? 2 : 0) + squeezePointer(NDS::ARM7MemTimings))); - - MOV(32, R(RSCRATCH), R(ABI_PARAM1)); - AND(32, R(RSCRATCH), Imm32(0xFF000000)); - CMP(32, R(RSCRATCH), Imm32(0x02000000)); - FixupBranch outsideMainRAM = J_CC(CC_NE); - CALC_CYCLES_7_DATA_MAIN_RAM(ABI_PARAM3, ABI_PARAM4, RSCRATCH) - MOV(32, R(ABI_PARAM3), R(ABI_PARAM1)); - AND(32, R(ABI_PARAM3), Imm32((MAIN_RAM_SIZE - 1) & addressMask)); - if (store) - { - MOV(size, MDisp(ABI_PARAM3, squeezePointer(NDS::MainRAM)), R(ABI_PARAM2)); - XOR(32, R(RSCRATCH), R(RSCRATCH)); - MOV(64, MScaled(ABI_PARAM3, SCALE_4, squeezePointer(cache.MainRAM)), R(RSCRATCH)); - if (size == 32) - MOV(64, MScaled(ABI_PARAM3, SCALE_4, squeezePointer(cache.MainRAM) + 8), R(RSCRATCH)); - } - else - { - MOVZX(32, size, RSCRATCH, MDisp(ABI_PARAM3, squeezePointer(NDS::MainRAM))); - if (size == 32) - { - if (ABI_PARAM1 != ECX) - MOV(32, R(ECX), R(ABI_PARAM1)); - AND(32, R(ECX), Imm8(3)); - SHL(32, R(ECX), Imm8(3)); - ROR_(32, R(RSCRATCH), R(ECX)); - } - } - RET(); - - SetJumpTarget(outsideMainRAM); - CALC_CYCLES_7_DATA_NON_MAIN_RAM(ABI_PARAM3, ABI_PARAM4, RSCRATCH) - if (store) - { - if (size > 8) - AND(32, R(ABI_PARAM1), Imm32(addressMask)); - switch (size) - { - case 32: JMP((u8*)NDS::ARM7Write32, true); break; - case 16: JMP((u8*)NDS::ARM7Write16, true); break; - case 8: JMP((u8*)NDS::ARM7Write8, true); break; - } - } - else - { - if (size == 32) - { - ABI_PushRegistersAndAdjustStack({ABI_PARAM1}, 8); - AND(32, R(ABI_PARAM1), Imm32(addressMask)); - ABI_CallFunction(NDS::ARM7Read32); - ABI_PopRegistersAndAdjustStack({ECX}, 8); - AND(32, R(ECX), Imm8(3)); - SHL(32, R(ECX), Imm8(3)); - ROR_(32, R(RSCRATCH), R(ECX)); - RET(); - } - else if (size == 16) - { - AND(32, R(ABI_PARAM1), Imm32(addressMask)); - JMP((u8*)NDS::ARM7Read16, true); - } - else - JMP((u8*)NDS::ARM7Read8, true); - } - - return res; -} - #define MEMORY_SEQ_WHILE_COND \ if (!store) \ MOV(32, currentElement, R(EAX));\ @@ -266,24 +144,13 @@ void* Compiler::Gen_MemoryRoutine7(bool store, bool codeMainRAM, int size) ABI_PARAM1 address ABI_PARAM2 address where registers are stored ABI_PARAM3 how many values to read/write - ABI_PARAM4 code cycles Dolphin x64CodeEmitter is my favourite assembler */ void* Compiler::Gen_MemoryRoutineSeq9(bool store, bool preinc) { - const u8* zero = GetCodePtr(); - ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(ABI_PARAM4)); - RET(); - void* res = (void*)GetWritableCodePtr(); - TEST(32, R(ABI_PARAM3), R(ABI_PARAM3)); - J_CC(CC_Z, zero); - - PUSH(ABI_PARAM3); - PUSH(ABI_PARAM4); // we need you later - const u8* repeat = GetCodePtr(); if (preinc) @@ -311,12 +178,7 @@ void* Compiler::Gen_MemoryRoutineSeq9(bool store, bool preinc) ABI_PopRegistersAndAdjustStack({ABI_PARAM1, ABI_PARAM2, ABI_PARAM3}, 8); MEMORY_SEQ_WHILE_COND - MOV(32, R(RSCRATCH), R(ABI_PARAM1)); - SHR(32, R(RSCRATCH), Imm8(12)); - MOVZX(32, 8, ABI_PARAM2, MComplex(RCPU, RSCRATCH, SCALE_4, 2 + offsetof(ARMv5, MemTimings))); - MOVZX(32, 8, RSCRATCH, MComplex(RCPU, RSCRATCH, SCALE_4, 3 + offsetof(ARMv5, MemTimings))); - - FixupBranch finishIt1 = J(); + RET(); SetJumpTarget(insideDTCM); AND(32, R(RSCRATCH), Imm32(0x3FFF & ~3)); @@ -329,9 +191,7 @@ void* Compiler::Gen_MemoryRoutineSeq9(bool store, bool preinc) MOV(32, R(RSCRATCH), MComplex(RCPU, RSCRATCH, SCALE_1, offsetof(ARMv5, DTCM))); MEMORY_SEQ_WHILE_COND - MOV(32, R(RSCRATCH), Imm32(1)); // sequential access time - MOV(32, R(ABI_PARAM2), Imm32(1)); // non sequential - FixupBranch finishIt2 = J(); + RET(); SetJumpTarget(insideITCM); MOV(32, R(RSCRATCH), R(ABI_PARAM1)); @@ -340,31 +200,23 @@ void* Compiler::Gen_MemoryRoutineSeq9(bool store, bool preinc) { MOV(32, R(ABI_PARAM4), currentElement); MOV(32, MComplex(RCPU, RSCRATCH, SCALE_1, offsetof(ARMv5, ITCM)), R(ABI_PARAM4)); - XOR(32, R(ABI_PARAM4), R(ABI_PARAM4)); - MOV(64, MScaled(RSCRATCH, SCALE_4, squeezePointer(cache.ARM9_ITCM)), R(ABI_PARAM4)); - MOV(64, MScaled(RSCRATCH, SCALE_4, squeezePointer(cache.ARM9_ITCM) + 8), R(ABI_PARAM4)); + + ADD(32, R(RSCRATCH), Imm32(ExeMemRegionOffsets[exeMem_ITCM])); + MOV(32, R(ABI_PARAM4), R(RSCRATCH)); + SHR(32, R(RSCRATCH), Imm8(8)); + SHL(32, R(RSCRATCH), Imm8(4)); + CMP(32, MDisp(RSCRATCH, squeezePointer(CodeRanges) + offsetof(AddressRange, Blocks.Length)), Imm8(0)); + FixupBranch noCode = J_CC(CC_Z); + ABI_PushRegistersAndAdjustStack({ABI_PARAM1, ABI_PARAM2, ABI_PARAM3}, 8); + MOV(32, R(ABI_PARAM1), R(ABI_PARAM4)); + CALL((u8*)InvalidateByAddr); + ABI_PopRegistersAndAdjustStack({ABI_PARAM1, ABI_PARAM2, ABI_PARAM3}, 8); + SetJumpTarget(noCode); } else MOV(32, R(RSCRATCH), MComplex(RCPU, RSCRATCH, SCALE_1, offsetof(ARMv5, ITCM))); MEMORY_SEQ_WHILE_COND - MOV(32, R(RSCRATCH), Imm32(1)); - MOV(32, R(ABI_PARAM2), Imm32(1)); - - SetJumpTarget(finishIt1); - SetJumpTarget(finishIt2); - - POP(ABI_PARAM4); - POP(ABI_PARAM3); - - CMP(32, R(ABI_PARAM3), Imm8(1)); - FixupBranch skipSequential = J_CC(CC_E); - SUB(32, R(ABI_PARAM3), Imm8(1)); - IMUL(32, RSCRATCH, R(ABI_PARAM3)); - ADD(32, R(ABI_PARAM2), R(RSCRATCH)); - SetJumpTarget(skipSequential); - - CALC_CYCLES_9(ABI_PARAM4, ABI_PARAM2, RSCRATCH) RET(); return res; @@ -372,18 +224,8 @@ void* Compiler::Gen_MemoryRoutineSeq9(bool store, bool preinc) void* Compiler::Gen_MemoryRoutineSeq7(bool store, bool preinc, bool codeMainRAM) { - const u8* zero = GetCodePtr(); - ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(ABI_PARAM4)); - RET(); - void* res = (void*)GetWritableCodePtr(); - TEST(32, R(ABI_PARAM3), R(ABI_PARAM3)); - J_CC(CC_Z, zero); - - PUSH(ABI_PARAM3); - PUSH(ABI_PARAM4); // we need you later - const u8* repeat = GetCodePtr(); if (preinc) @@ -403,59 +245,227 @@ void* Compiler::Gen_MemoryRoutineSeq7(bool store, bool preinc, bool codeMainRAM) ABI_PopRegistersAndAdjustStack({ABI_PARAM1, ABI_PARAM2, ABI_PARAM3}, 8); MEMORY_SEQ_WHILE_COND - MOV(32, R(RSCRATCH), R(ABI_PARAM1)); - SHR(32, R(RSCRATCH), Imm8(15)); - MOVZX(32, 8, ABI_PARAM2, MScaled(RSCRATCH, SCALE_4, 2 + squeezePointer(NDS::ARM7MemTimings))); - MOVZX(32, 8, RSCRATCH, MScaled(RSCRATCH, SCALE_4, 3 + squeezePointer(NDS::ARM7MemTimings))); + RET(); - POP(ABI_PARAM4); - POP(ABI_PARAM3); + return res; +} - // TODO: optimise this - CMP(32, R(ABI_PARAM3), Imm8(1)); - FixupBranch skipSequential = J_CC(CC_E); - SUB(32, R(ABI_PARAM3), Imm8(1)); - IMUL(32, RSCRATCH, R(ABI_PARAM3)); - ADD(32, R(ABI_PARAM2), R(RSCRATCH)); - SetJumpTarget(skipSequential); +#undef MEMORY_SEQ_WHILE_COND - MOV(32, R(RSCRATCH), R(ABI_PARAM1)); - AND(32, R(RSCRATCH), Imm32(0xFF000000)); - CMP(32, R(RSCRATCH), Imm32(0x02000000)); - FixupBranch outsideMainRAM = J_CC(CC_NE); - CALC_CYCLES_7_DATA_MAIN_RAM(ABI_PARAM4, ABI_PARAM2, RSCRATCH) - RET(); +void Compiler::Comp_MemLoadLiteral(int size, int rd, u32 addr) +{ + u32 val; + // make sure arm7 bios is accessible + u32 tmpR15 = CurCPU->R[15]; + CurCPU->R[15] = R15; + if (size == 32) + { + CurCPU->DataRead32(addr & ~0x3, &val); + val = ROR(val, (addr & 0x3) << 3); + } + else if (size == 16) + CurCPU->DataRead16(addr & ~0x1, &val); + else + CurCPU->DataRead8(addr, &val); + CurCPU->R[15] = tmpR15; - SetJumpTarget(outsideMainRAM); - CALC_CYCLES_7_DATA_NON_MAIN_RAM(ABI_PARAM4, ABI_PARAM2, RSCRATCH) - RET(); + MOV(32, MapReg(rd), Imm32(val)); - return res; + if (Thumb || CurInstr.Cond() == 0xE) + RegCache.PutLiteral(rd, val); + + Comp_AddCycles_CDI(); } -#undef CALC_CYCLES_9 -#undef MEMORY_SEQ_WHILE_COND +void fault(u32 a, u32 b) +{ + printf("actually not static! %x %x\n", a, b); +} -void Compiler::Comp_MemAccess(OpArg rd, bool signExtend, bool store, int size) +void Compiler::Comp_MemAccess(int rd, int rn, const ComplexOperand& op2, int size, int flags) { - IrregularCycles = true; + if (flags & memop_Store) + { + Comp_AddCycles_CD(); + } + else + { + Comp_AddCycles_CDI(); + } - if (store) - MOV(32, R(ABI_PARAM2), rd); - u32 cycles = Num - ? NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2] - : (R15 & 0x2 ? 0 : CurInstr.CodeCycles); - MOV(32, R(ABI_PARAM3), Imm32(cycles)); - CALL(Num == 0 - ? MemoryFuncs9[size >> 4][store] - : MemoryFuncs7[size >> 4][store][CodeRegion == 0x02]); + u32 addressMask = ~0; + if (size == 32) + addressMask = ~3; + if (size == 16) + addressMask = ~1; - if (!store) + if (rn == 15 && rd != 15 && op2.IsImm && !(flags & (memop_Post|memop_Store|memop_Writeback))) { - if (signExtend) - MOVSX(32, size, rd.GetSimpleReg(), R(RSCRATCH)); + Comp_MemLoadLiteral(size, rd, + R15 + op2.Imm * ((flags & memop_SubtractOffset) ? -1 : 1)); + } + else + { + OpArg rdMapped = MapReg(rd); + OpArg rnMapped = MapReg(rn); + + bool inlinePreparation = Num == 1; + u32 constLocalROR32 = 4; + + void* memoryFunc = Num == 0 + ? MemoryFuncs9[size >> 4][!!(flags & memop_Store)] + : MemoryFuncs7[size >> 4][!!((flags & memop_Store))]; + + if ((rd != 15 || (flags & memop_Store)) && op2.IsImm && RegCache.IsLiteral(rn)) + { + u32 addr = RegCache.LiteralValues[rn] + op2.Imm * ((flags & memop_SubtractOffset) ? -1 : 1); + + /*MOV(32, R(ABI_PARAM1), Imm32(CurInstr.Instr)); + MOV(32, R(ABI_PARAM1), Imm32(R15)); + MOV_sum(32, RSCRATCH, rnMapped, Imm32(op2.Imm * ((flags & memop_SubtractOffset) ? -1 : 1))); + CMP(32, R(RSCRATCH), Imm32(addr)); + FixupBranch eq = J_CC(CC_E); + CALL((void*)fault); + SetJumpTarget(eq);*/ + + NDS::MemRegion region; + region.Mem = NULL; + if (Num == 0) + { + ARMv5* cpu5 = (ARMv5*)CurCPU; + + // stupid dtcm... + if (addr >= cpu5->DTCMBase && addr < (cpu5->DTCMBase + cpu5->DTCMSize)) + { + region.Mem = cpu5->DTCM; + region.Mask = 0x3FFF; + } + else + { + NDS::ARM9GetMemRegion(addr, flags & memop_Store, ®ion); + } + } + else + NDS::ARM7GetMemRegion(addr, flags & memop_Store, ®ion); + + if (region.Mem != NULL) + { + void* ptr = ®ion.Mem[addr & addressMask & region.Mask]; + + if (flags & memop_Store) + { + MOV(size, M(ptr), MapReg(rd)); + } + else + { + if (flags & memop_SignExtend) + MOVSX(32, size, rdMapped.GetSimpleReg(), M(ptr)); + else + MOVZX(32, size, rdMapped.GetSimpleReg(), M(ptr)); + + if (size == 32 && addr & ~0x3) + { + ROR_(32, rdMapped, Imm8((addr & 0x3) << 3)); + } + } + + return; + } + + void* specialFunc = GetFuncForAddr(CurCPU, addr, flags & memop_Store, size); + if (specialFunc) + { + memoryFunc = specialFunc; + inlinePreparation = true; + constLocalROR32 = addr & 0x3; + } + } + + X64Reg finalAddr = ABI_PARAM1; + if (flags & memop_Post) + { + MOV(32, R(ABI_PARAM1), rnMapped); + + finalAddr = rnMapped.GetSimpleReg(); + } + + if (op2.IsImm) + { + MOV_sum(32, finalAddr, rnMapped, Imm32(op2.Imm * ((flags & memop_SubtractOffset) ? -1 : 1))); + } else - MOVZX(32, size, rd.GetSimpleReg(), R(RSCRATCH)); + { + OpArg rm = MapReg(op2.Reg.Reg); + + if (!(flags & memop_SubtractOffset) && rm.IsSimpleReg() && rnMapped.IsSimpleReg() + && op2.Reg.Op == 0 && op2.Reg.Amount > 0 && op2.Reg.Amount <= 3) + { + LEA(32, finalAddr, + MComplex(rnMapped.GetSimpleReg(), rm.GetSimpleReg(), 1 << op2.Reg.Amount, 0)); + } + else + { + bool throwAway; + OpArg offset = + Comp_RegShiftImm(op2.Reg.Op, op2.Reg.Amount, rm, false, throwAway); + + if (flags & memop_SubtractOffset) + { + MOV(32, R(finalAddr), rnMapped); + if (!offset.IsZero()) + SUB(32, R(finalAddr), offset); + } + else + MOV_sum(32, finalAddr, rnMapped, offset); + } + } + + if ((flags & memop_Writeback) && !(flags & memop_Post)) + MOV(32, rnMapped, R(finalAddr)); + + if (flags & memop_Store) + MOV(32, R(ABI_PARAM2), rdMapped); + + if (!(flags & memop_Store) && inlinePreparation && constLocalROR32 == 4 && size == 32) + MOV(32, rdMapped, R(ABI_PARAM1)); + + if (inlinePreparation && size > 8) + AND(32, R(ABI_PARAM1), Imm8(addressMask)); + + CALL(memoryFunc); + + if (!(flags & memop_Store)) + { + if (inlinePreparation && size == 32) + { + if (constLocalROR32 == 4) + { + static_assert(RSCRATCH3 == ECX); + MOV(32, R(ECX), rdMapped); + AND(32, R(ECX), Imm8(3)); + SHL(32, R(ECX), Imm8(3)); + ROR_(32, R(RSCRATCH), R(ECX)); + } + else if (constLocalROR32 != 0) + ROR_(32, R(RSCRATCH), Imm8(constLocalROR32 << 3)); + } + + if (flags & memop_SignExtend) + MOVSX(32, size, rdMapped.GetSimpleReg(), R(RSCRATCH)); + else + MOVZX(32, size, rdMapped.GetSimpleReg(), R(RSCRATCH)); + } + + if (!(flags & memop_Store) && rd == 15) + { + if (size < 32) + printf("!!! LDR <32 bit PC %08X %x\n", R15, CurInstr.Instr); + { + if (Num == 1) + AND(32, rdMapped, Imm8(0xFE)); // immediate is sign extended + Comp_JumpTo(rdMapped.GetSimpleReg()); + } + } } } @@ -475,16 +485,13 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc s32 offset = (regsCount * 4) * (decrement ? -1 : 1); - u32 cycles = Num - ? NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2] - : (R15 & 0x2 ? 0 : CurInstr.CodeCycles); - // we need to make sure that the stack stays aligned to 16 bytes u32 stackAlloc = ((regsCount + 1) & ~1) * 8; - MOV(32, R(ABI_PARAM4), Imm32(cycles)); if (!store) { + Comp_AddCycles_CDI(); + MOV(32, R(ABI_PARAM3), Imm32(regsCount)); SUB(64, R(RSP), stackAlloc <= INT8_MAX ? Imm8(stackAlloc) : Imm32(stackAlloc)); MOV(64, R(ABI_PARAM2), R(RSP)); @@ -548,6 +555,8 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc } else { + Comp_AddCycles_CD(); + if (regsCount & 1) PUSH(RSCRATCH); @@ -594,81 +603,45 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc return offset; } -OpArg Compiler::A_Comp_GetMemWBOffset() -{ - if (!(CurInstr.Instr & (1 << 25))) - { - u32 imm = CurInstr.Instr & 0xFFF; - return Imm32(imm); - } - else - { - int op = (CurInstr.Instr >> 5) & 0x3; - int amount = (CurInstr.Instr >> 7) & 0x1F; - OpArg rm = MapReg(CurInstr.A_Reg(0)); - bool carryUsed; - - return Comp_RegShiftImm(op, amount, rm, false, carryUsed); - } -} void Compiler::A_Comp_MemWB() { - OpArg rn = MapReg(CurInstr.A_Reg(16)); - OpArg rd = MapReg(CurInstr.A_Reg(12)); bool load = CurInstr.Instr & (1 << 20); bool byte = CurInstr.Instr & (1 << 22); int size = byte ? 8 : 32; + + int flags = 0; + if (!load) + flags |= memop_Store; + if (!(CurInstr.Instr & (1 << 24))) + flags |= memop_Post; + if (CurInstr.Instr & (1 << 21)) + flags |= memop_Writeback; + if (!(CurInstr.Instr & (1 << 23))) + flags |= memop_SubtractOffset; - if (CurInstr.Instr & (1 << 24)) + ComplexOperand offset; + if (!(CurInstr.Instr & (1 << 25))) { - OpArg offset = A_Comp_GetMemWBOffset(); - if (CurInstr.Instr & (1 << 23)) - MOV_sum(32, ABI_PARAM1, rn, offset); - else - { - MOV(32, R(ABI_PARAM1), rn); - SUB(32, R(ABI_PARAM1), offset); - } - - if (CurInstr.Instr & (1 << 21)) - MOV(32, rn, R(ABI_PARAM1)); + offset = ComplexOperand(CurInstr.Instr & 0xFFF); } else - MOV(32, R(ABI_PARAM1), rn); - - if (!(CurInstr.Instr & (1 << 24))) { - OpArg offset = A_Comp_GetMemWBOffset(); + int op = (CurInstr.Instr >> 5) & 0x3; + int amount = (CurInstr.Instr >> 7) & 0x1F; + int rm = CurInstr.A_Reg(0); - if (CurInstr.Instr & (1 << 23)) - ADD(32, rn, offset); - else - SUB(32, rn, offset); + offset = ComplexOperand(rm, op, amount); } - Comp_MemAccess(rd, false, !load, byte ? 8 : 32); - if (load && CurInstr.A_Reg(12) == 15) - { - if (byte) - printf("!!! LDRB PC %08X\n", R15); - else - { - if (Num == 1) - AND(32, rd, Imm8(0xFE)); // immediate is sign extended - Comp_JumpTo(rd.GetSimpleReg()); - } - } + Comp_MemAccess(CurInstr.A_Reg(12), CurInstr.A_Reg(16), offset, size, flags); } void Compiler::A_Comp_MemHalf() { - OpArg rn = MapReg(CurInstr.A_Reg(16)); - OpArg rd = MapReg(CurInstr.A_Reg(12)); - - OpArg offset = CurInstr.Instr & (1 << 22) - ? Imm32(CurInstr.Instr & 0xF | ((CurInstr.Instr >> 4) & 0xF0)) - : MapReg(CurInstr.A_Reg(0)); + ComplexOperand offset = CurInstr.Instr & (1 << 22) + ? ComplexOperand(CurInstr.Instr & 0xF | ((CurInstr.Instr >> 4) & 0xF0)) + : ComplexOperand(CurInstr.A_Reg(0), 0, 0); int op = (CurInstr.Instr >> 5) & 0x3; bool load = CurInstr.Instr & (1 << 20); @@ -689,49 +662,29 @@ void Compiler::A_Comp_MemHalf() if (size == 32 && Num == 1) return; // NOP - if (CurInstr.Instr & (1 << 24)) - { - if (CurInstr.Instr & (1 << 23)) - MOV_sum(32, ABI_PARAM1, rn, offset); - else - { - MOV(32, R(ABI_PARAM1), rn); - SUB(32, R(ABI_PARAM1), offset); - } - - if (CurInstr.Instr & (1 << 21)) - MOV(32, rn, R(ABI_PARAM1)); - } - else - MOV(32, R(ABI_PARAM1), rn); - + int flags = 0; + if (signExtend) + flags |= memop_SignExtend; + if (!load) + flags |= memop_Store; if (!(CurInstr.Instr & (1 << 24))) - { - if (CurInstr.Instr & (1 << 23)) - ADD(32, rn, offset); - else - SUB(32, rn, offset); - } + flags |= memop_Post; + if (!(CurInstr.Instr & (1 << 23))) + flags |= memop_SubtractOffset; + if (CurInstr.Instr & (1 << 21)) + flags |= memop_Writeback; - Comp_MemAccess(rd, signExtend, !load, size); - - if (load && CurInstr.A_Reg(12) == 15) - printf("!!! MemHalf op PC %08X\n", R15);; + Comp_MemAccess(CurInstr.A_Reg(12), CurInstr.A_Reg(16), offset, size, flags); } void Compiler::T_Comp_MemReg() { - OpArg rd = MapReg(CurInstr.T_Reg(0)); - OpArg rb = MapReg(CurInstr.T_Reg(3)); - OpArg ro = MapReg(CurInstr.T_Reg(6)); - int op = (CurInstr.Instr >> 10) & 0x3; bool load = op & 0x2; bool byte = op & 0x1; - MOV_sum(32, ABI_PARAM1, rb, ro); - - Comp_MemAccess(rd, false, !load, byte ? 8 : 32); + Comp_MemAccess(CurInstr.T_Reg(0), CurInstr.T_Reg(3), ComplexOperand(CurInstr.T_Reg(6), 0, 0), + byte ? 8 : 32, load ? 0 : memop_Store); } void Compiler::A_Comp_LDM_STM() @@ -758,67 +711,55 @@ void Compiler::A_Comp_LDM_STM() void Compiler::T_Comp_MemImm() { - OpArg rd = MapReg(CurInstr.T_Reg(0)); - OpArg rb = MapReg(CurInstr.T_Reg(3)); - int op = (CurInstr.Instr >> 11) & 0x3; bool load = op & 0x1; bool byte = op & 0x2; u32 offset = ((CurInstr.Instr >> 6) & 0x1F) * (byte ? 1 : 4); - LEA(32, ABI_PARAM1, MDisp(rb.GetSimpleReg(), offset)); - - Comp_MemAccess(rd, false, !load, byte ? 8 : 32); + Comp_MemAccess(CurInstr.T_Reg(0), CurInstr.T_Reg(3), ComplexOperand(offset), + byte ? 8 : 32, load ? 0 : memop_Store); } void Compiler::T_Comp_MemRegHalf() { - OpArg rd = MapReg(CurInstr.T_Reg(0)); - OpArg rb = MapReg(CurInstr.T_Reg(3)); - OpArg ro = MapReg(CurInstr.T_Reg(6)); - int op = (CurInstr.Instr >> 10) & 0x3; bool load = op != 0; int size = op != 1 ? 16 : 8; bool signExtend = op & 1; - MOV_sum(32, ABI_PARAM1, rb, ro); + int flags = 0; + if (signExtend) + flags |= memop_SignExtend; + if (!load) + flags |= memop_Store; - Comp_MemAccess(rd, signExtend, !load, size); + Comp_MemAccess(CurInstr.T_Reg(0), CurInstr.T_Reg(3), ComplexOperand(CurInstr.T_Reg(6), 0, 0), + size, flags); } void Compiler::T_Comp_MemImmHalf() { - OpArg rd = MapReg(CurInstr.T_Reg(0)); - OpArg rb = MapReg(CurInstr.T_Reg(3)); - u32 offset = (CurInstr.Instr >> 5) & 0x3E; bool load = CurInstr.Instr & (1 << 11); - LEA(32, ABI_PARAM1, MDisp(rb.GetSimpleReg(), offset)); - - Comp_MemAccess(rd, false, !load, 16); + Comp_MemAccess(CurInstr.T_Reg(0), CurInstr.T_Reg(3), ComplexOperand(offset), 16, + load ? 0 : memop_Store); } void Compiler::T_Comp_LoadPCRel() { - OpArg rd = MapReg(CurInstr.T_Reg(8)); u32 addr = (R15 & ~0x2) + ((CurInstr.Instr & 0xFF) << 2); - // hopefully this doesn't break - u32 val; CurCPU->DataRead32(addr, &val); - MOV(32, rd, Imm32(val)); + Comp_MemLoadLiteral(32, CurInstr.T_Reg(8), addr); } void Compiler::T_Comp_MemSPRel() { u32 offset = (CurInstr.Instr & 0xFF) * 4; - OpArg rd = MapReg(CurInstr.T_Reg(8)); bool load = CurInstr.Instr & (1 << 11); - LEA(32, ABI_PARAM1, MDisp(MapReg(13).GetSimpleReg(), offset)); - - Comp_MemAccess(rd, false, !load, 32); + Comp_MemAccess(CurInstr.T_Reg(8), 13, ComplexOperand(offset), 32, + load ? 0 : memop_Store); } void Compiler::T_Comp_PUSH_POP() diff --git a/src/ARM_InstrInfo.cpp b/src/ARM_InstrInfo.cpp index 9239e29..0fbde26 100644 --- a/src/ARM_InstrInfo.cpp +++ b/src/ARM_InstrInfo.cpp @@ -36,7 +36,7 @@ enum { A_StaticShiftSetC = 1 << 18, A_SetC = 1 << 19, - A_WriteMemory = 1 << 20, + A_WriteMem = 1 << 20 }; #define A_BIOP A_Read16 @@ -109,7 +109,7 @@ const u32 A_UMULL = A_MulFlags | A_Write16 | A_Write12 | A_Read0 | A_Read8 | ak( const u32 A_UMLAL = A_MulFlags | A_Write16 | A_Write12 | A_Read16 | A_Read12 | A_Read0 | A_Read8 | ak(ak_UMLAL); const u32 A_SMULL = A_MulFlags | A_Write16 | A_Write12 | A_Read0 | A_Read8 | ak(ak_SMULL); const u32 A_SMLAL = A_MulFlags | A_Write16 | A_Write12 | A_Read16 | A_Read12 | A_Read0 | A_Read8 | ak(ak_SMLAL); -const u32 A_SMLAxy = A_Write16 | A_Read0 | A_Read8 | A_Read12 | ak(ak_SMLALxy); +const u32 A_SMLAxy = A_Write16 | A_Read0 | A_Read8 | A_Read12 | ak(ak_SMLAxy); const u32 A_SMLAWy = A_Write16 | A_Read0 | A_Read8 | A_Read12 | ak(ak_SMLAWy); const u32 A_SMULWy = A_Write16 | A_Read0 | A_Read8 | ak(ak_SMULWy); const u32 A_SMLALxy = A_Write16 | A_Write12 | A_Read16 | A_Read12 | A_Read0 | A_Read8 | ak(ak_SMLALxy); @@ -123,7 +123,7 @@ const u32 A_QDADD = A_Write12 | A_Read0 | A_Read16 | A_UnkOnARM7 | ak(ak_QDADD); const u32 A_QDSUB = A_Write12 | A_Read0 | A_Read16 | A_UnkOnARM7 | ak(ak_QDSUB); #define A_LDR A_Write12 -#define A_STR A_Read12 | A_WriteMemory +#define A_STR A_Read12 | A_WriteMem #define A_IMPLEMENT_WB_LDRSTR(x,k) \ const u32 A_##x##_IMM = A_##k | A_Read16 | A_MemWriteback | ak(ak_##x##_IMM); \ @@ -144,7 +144,7 @@ A_IMPLEMENT_WB_LDRSTR(LDR,LDR) A_IMPLEMENT_WB_LDRSTR(LDRB,LDR) #define A_LDRD A_Write12Double -#define A_STRD A_Read12Double | A_WriteMemory +#define A_STRD A_Read12Double | A_WriteMem #define A_IMPLEMENT_HD_LDRSTR(x,k) \ const u32 A_##x##_IMM = A_##k | A_Read16 | A_MemWriteback | ak(ak_##x##_IMM); \ @@ -159,11 +159,11 @@ A_IMPLEMENT_HD_LDRSTR(LDRH,LDR) A_IMPLEMENT_HD_LDRSTR(LDRSB,LDR) A_IMPLEMENT_HD_LDRSTR(LDRSH,LDR) -const u32 A_SWP = A_Write12 | A_Read16 | A_Read0 | A_WriteMemory | ak(ak_SWP); -const u32 A_SWPB = A_Write12 | A_Read16 | A_Read0 | A_WriteMemory | ak(ak_SWPB); +const u32 A_SWP = A_Write12 | A_Read16 | A_Read0 | A_WriteMem | ak(ak_SWP); +const u32 A_SWPB = A_Write12 | A_Read16 | A_Read0 | A_WriteMem | ak(ak_SWPB); const u32 A_LDM = A_Read16 | A_MemWriteback | ak(ak_LDM); -const u32 A_STM = A_Read16 | A_MemWriteback | A_WriteMemory | ak(ak_STM); +const u32 A_STM = A_Read16 | A_MemWriteback | A_WriteMem | ak(ak_STM); const u32 A_B = A_BranchAlways | ak(ak_B); const u32 A_BL = A_BranchAlways | A_Link | ak(ak_BL); @@ -181,7 +181,7 @@ const u32 A_SVC = A_BranchAlways | A_Link | ak(ak_SVC); // THUMB -#define tk(x) ((x) << 21) +#define tk(x) ((x) << 22) enum { T_Read0 = 1 << 0, @@ -210,6 +210,8 @@ enum { T_SetMaybeC = 1 << 18, T_ReadC = 1 << 19, T_SetC = 1 << 20, + + T_WriteMem = 1 << 21, }; const u32 T_LSL_IMM = T_SetNZ | T_SetMaybeC | T_Write0 | T_Read3 | tk(tk_LSL_IMM); @@ -253,30 +255,30 @@ const u32 T_ADD_SP = T_WriteR13 | T_ReadR13 | tk(tk_ADD_SP); const u32 T_LDR_PCREL = T_Write8 | tk(tk_LDR_PCREL); -const u32 T_STR_REG = T_Read0 | T_Read3 | T_Read6 | tk(tk_STR_REG); -const u32 T_STRB_REG = T_Read0 | T_Read3 | T_Read6 | tk(tk_STRB_REG); +const u32 T_STR_REG = T_Read0 | T_Read3 | T_Read6 | T_WriteMem | tk(tk_STR_REG); +const u32 T_STRB_REG = T_Read0 | T_Read3 | T_Read6 | T_WriteMem | tk(tk_STRB_REG); const u32 T_LDR_REG = T_Write0 | T_Read3 | T_Read6 | tk(tk_LDR_REG); const u32 T_LDRB_REG = T_Write0 | T_Read3 | T_Read6 | tk(tk_LDRB_REG); -const u32 T_STRH_REG = T_Read0 | T_Read3 | T_Read6 | tk(tk_STRH_REG); +const u32 T_STRH_REG = T_Read0 | T_Read3 | T_Read6 | T_WriteMem | tk(tk_STRH_REG); const u32 T_LDRSB_REG = T_Write0 | T_Read3 | T_Read6 | tk(tk_LDRSB_REG); const u32 T_LDRH_REG = T_Write0 | T_Read3 | T_Read6 | tk(tk_LDRH_REG); const u32 T_LDRSH_REG = T_Write0 | T_Read3 | T_Read6 | tk(tk_LDRSH_REG); -const u32 T_STR_IMM = T_Read0 | T_Read3 | tk(tk_STR_IMM); +const u32 T_STR_IMM = T_Read0 | T_Read3 | T_WriteMem | tk(tk_STR_IMM); const u32 T_LDR_IMM = T_Write0 | T_Read3 | tk(tk_LDR_IMM); -const u32 T_STRB_IMM = T_Read0 | T_Read3 | tk(tk_STRB_IMM); +const u32 T_STRB_IMM = T_Read0 | T_Read3 | T_WriteMem | tk(tk_STRB_IMM); const u32 T_LDRB_IMM = T_Write0 | T_Read3 | tk(tk_LDRB_IMM); -const u32 T_STRH_IMM = T_Read0 | T_Read3 | tk(tk_STRH_IMM); +const u32 T_STRH_IMM = T_Read0 | T_Read3 | T_WriteMem | tk(tk_STRH_IMM); const u32 T_LDRH_IMM = T_Write0 | T_Read3 | tk(tk_LDRH_IMM); -const u32 T_STR_SPREL = T_Read8 | T_ReadR13 | tk(tk_STR_SPREL); +const u32 T_STR_SPREL = T_Read8 | T_ReadR13 | T_WriteMem | tk(tk_STR_SPREL); const u32 T_LDR_SPREL = T_Write8 | T_ReadR13 | tk(tk_LDR_SPREL); -const u32 T_PUSH = T_ReadR13 | T_WriteR13 | tk(tk_PUSH); +const u32 T_PUSH = T_ReadR13 | T_WriteR13 | T_WriteMem | tk(tk_PUSH); const u32 T_POP = T_PopPC | T_ReadR13 | T_WriteR13 | tk(tk_POP); const u32 T_LDMIA = T_Read8 | T_Write8 | tk(tk_LDMIA); -const u32 T_STMIA = T_Read8 | T_Write8 | tk(tk_STMIA); +const u32 T_STMIA = T_Read8 | T_Write8 | T_WriteMem | tk(tk_STMIA); const u32 T_BCOND = T_BranchAlways | tk(tk_BCOND); const u32 T_BX = T_BranchAlways | T_ReadHi3 | tk(tk_BX); @@ -307,7 +309,7 @@ Info Decode(bool thumb, u32 num, u32 instr) if (thumb) { u32 data = THUMBInstrTable[(instr >> 6) & 0x3FF]; - res.Kind = (data >> 21) & 0x3F; + res.Kind = (data >> 22) & 0x3F; if (data & T_Read0) res.SrcRegs |= 1 << (instr & 0x7); @@ -356,6 +358,9 @@ Info Decode(bool thumb, u32 num, u32 instr) if (data & T_SetC) res.WriteFlags |= flag_C; + if (data & T_WriteMem) + res.SpecialKind = special_WriteMem; + res.EndBlock |= res.Branches(); if (res.Kind == tk_BCOND) @@ -382,6 +387,9 @@ Info Decode(bool thumb, u32 num, u32 instr) u32 id = (cn<<8)|(cm<<4)|cpinfo; if (id == 0x704 || id == 0x782 || id == 0x750 || id == 0x751 || id == 0x752) res.EndBlock |= true; + + if (id == 0x704 || id == 0x782) + res.SpecialKind = special_WaitForInterrupt; } if (res.Kind == ak_MCR || res.Kind == ak_MRC) { @@ -449,6 +457,9 @@ Info Decode(bool thumb, u32 num, u32 instr) if ((data & A_SetC) || (data & A_StaticShiftSetC) && ((instr >> 7) & 0x1F)) res.WriteFlags |= flag_C; + if (data & A_WriteMem) + res.SpecialKind = special_WriteMem; + if ((instr >> 28) < 0xE) { // make non conditional flag sets conditional diff --git a/src/ARM_InstrInfo.h b/src/ARM_InstrInfo.h index d01c600..d02f168 100644 --- a/src/ARM_InstrInfo.h +++ b/src/ARM_InstrInfo.h @@ -226,18 +226,27 @@ enum flag_V = 1 << 0, }; +enum +{ + special_NotSpecialAtAll = 0, + special_WriteMem, + special_WaitForInterrupt +}; + struct Info { u16 DstRegs, SrcRegs; u16 Kind; + u8 SpecialKind; + u8 ReadFlags; // lower 4 bits - set always // upper 4 bits - might set flag u8 WriteFlags; bool EndBlock; - bool Branches() + bool Branches() const { return DstRegs & (1 << 15); } diff --git a/src/CP15.cpp b/src/CP15.cpp index 5b5f935..8a9b31d 100644 --- a/src/CP15.cpp +++ b/src/CP15.cpp @@ -562,9 +562,11 @@ void ARMv5::CP15Write(u32 id, u32 val) case 0x750: + ARMJIT::InvalidateAll(); ICacheInvalidateAll(); return; case 0x751: + ARMJIT::InvalidateByAddr(ARMJIT::TranslateAddr<0>(val)); ICacheInvalidateByAddr(val); return; case 0x752: @@ -814,7 +816,7 @@ void ARMv5::DataWrite8(u32 addr, u8 val) DataCycles = 1; *(u8*)&ITCM[addr & 0x7FFF] = val; #ifdef JIT_ENABLED - ARMJIT::cache.ARM9_ITCM[(addr & 0x7FFF) >> 1] = NULL; + ARMJIT::InvalidateITCM(addr & 0x7FFF); #endif return; } @@ -838,7 +840,7 @@ void ARMv5::DataWrite16(u32 addr, u16 val) DataCycles = 1; *(u16*)&ITCM[addr & 0x7FFF] = val; #ifdef JIT_ENABLED - ARMJIT::cache.ARM9_ITCM[(addr & 0x7FFF) >> 1] = NULL; + ARMJIT::InvalidateITCM(addr & 0x7FFF); #endif return; } @@ -862,8 +864,7 @@ void ARMv5::DataWrite32(u32 addr, u32 val) DataCycles = 1; *(u32*)&ITCM[addr & 0x7FFF] = val; #ifdef JIT_ENABLED - ARMJIT::cache.ARM9_ITCM[(addr & 0x7FFF) >> 1] = NULL; - ARMJIT::cache.ARM9_ITCM[((addr + 2) & 0x7FFF) >> 1] = NULL; + ARMJIT::InvalidateITCM(addr & 0x7FFF); #endif return; } @@ -887,8 +888,7 @@ void ARMv5::DataWrite32S(u32 addr, u32 val) DataCycles += 1; *(u32*)&ITCM[addr & 0x7FFF] = val; #ifdef JIT_ENABLED - ARMJIT::cache.ARM9_ITCM[(addr & 0x7FFF) >> 1] = NULL; - ARMJIT::cache.ARM9_ITCM[((addr & 0x7FFF) >> 1) + 1] = NULL; + ARMJIT::InvalidateITCM(addr & 0x7FFF); #endif return; } diff --git a/src/Config.cpp b/src/Config.cpp index 33bab75..c117a41 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -40,6 +40,7 @@ char DSiNANDPath[1024]; #ifdef JIT_ENABLED bool JIT_Enable = false; int JIT_MaxBlockSize = 12; +bool JIT_BrancheOptimisations = true; #endif ConfigEntry ConfigFile[] = @@ -56,6 +57,7 @@ ConfigEntry ConfigFile[] = #ifdef JIT_ENABLED {"JIT_Enable", 0, &JIT_Enable, 0, NULL, 0}, {"JIT_MaxBlockSize", 0, &JIT_MaxBlockSize, 10, NULL, 0}, + {"JIT_BrancheOptimisations", 0, &JIT_BrancheOptimisations, 1, NULL, 0}, #endif {"", -1, NULL, 0, NULL, 0} diff --git a/src/Config.h b/src/Config.h index 9296335..c9013aa 100644 --- a/src/Config.h +++ b/src/Config.h @@ -54,6 +54,7 @@ extern char DSiNANDPath[1024]; #ifdef JIT_ENABLED extern bool JIT_Enable; extern int JIT_MaxBlockSize; +extern bool JIT_BrancheOptimisations; #endif } diff --git a/src/NDS.cpp b/src/NDS.cpp index 0bde139..0cfbd1a 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -575,7 +575,7 @@ void Reset() RCnt = 0; #ifdef JIT_ENABLED - ARMJIT::InvalidateBlockCache(); + ARMJIT::ResetBlockCache(); #endif NDSCart::Reset(); @@ -807,7 +807,7 @@ bool DoSavestate(Savestate* file) #ifdef JIT_ENABLED if (!file->Saving) { - ARMJIT::InvalidateBlockCache(); + ARMJIT::ResetBlockCache(); } #endif @@ -2016,10 +2016,6 @@ u32 ARM9Read32(u32 addr) void ARM9Write8(u32 addr, u8 val) { -#ifdef JIT_ENABLED - ARMJIT::Invalidate16<0>(addr); -#endif - switch (addr & 0xFF000000) { case 0x02000000: @@ -2070,10 +2066,6 @@ void ARM9Write8(u32 addr, u8 val) void ARM9Write16(u32 addr, u16 val) { -#ifdef JIT_ENABLED - ARMJIT::Invalidate16<0>(addr); -#endif - switch (addr & 0xFF000000) { case 0x02000000: @@ -2140,10 +2132,6 @@ void ARM9Write16(u32 addr, u16 val) void ARM9Write32(u32 addr, u32 val) { -#ifdef JIT_ENABLED - ARMJIT::Invalidate32<0>(addr); -#endif - switch (addr & 0xFF000000) { case 0x02000000: @@ -2439,7 +2427,7 @@ u32 ARM7Read32(u32 addr) void ARM7Write8(u32 addr, u8 val) { #ifdef JIT_ENABLED - ARMJIT::Invalidate16<1>(addr); + ARMJIT::InvalidateByAddr7(addr); #endif switch (addr & 0xFF800000) @@ -2502,7 +2490,7 @@ void ARM7Write8(u32 addr, u8 val) void ARM7Write16(u32 addr, u16 val) { #ifdef JIT_ENABLED - ARMJIT::Invalidate16<1>(addr); + ARMJIT::InvalidateByAddr7(addr); #endif switch (addr & 0xFF800000) @@ -2575,7 +2563,7 @@ void ARM7Write16(u32 addr, u16 val) void ARM7Write32(u32 addr, u32 val) { #ifdef JIT_ENABLED - ARMJIT::Invalidate32<1>(addr); + ARMJIT::InvalidateByAddr7(addr); #endif switch (addr & 0xFF800000) -- cgit v1.2.3 From 52dd0ee75a3dd78bc0ef8638c8ff16c1e9abdd36 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Thu, 3 Oct 2019 01:14:33 +0200 Subject: remove leftover debug code --- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index 25c55a3..a994d34 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -598,8 +598,6 @@ void Compiler::Comp_AddCycles_CDI() cycles = numC + numD + 1; } - printf("%x: %d %d cycles cdi (%d)\n", CurInstr.Instr, Num, CurInstr.DataCycles, cycles); - if (!Thumb && CurInstr.Cond() < 0xE) ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm8(cycles)); else -- cgit v1.2.3 From 9cf7780e4641abaf07b6c453dfa182a80516c190 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Wed, 16 Oct 2019 23:39:12 +0200 Subject: decrease jit block cache address granularity fixes Dragon Quest IX move code with side effects out of assert, fixes release build (thanks to m4wx for this one) also remove some leftovers of jit pipelining --- src/ARMJIT.cpp | 42 ++++++++++++++++++++++--------------- src/ARMJIT_Internal.h | 3 +-- src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 31 ++++++++++++++------------- src/ARM_InstrInfo.cpp | 25 ++++++++++++++-------- src/ARM_InstrInfo.h | 3 ++- 5 files changed, 60 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 686bdd6..19a5e70 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -106,7 +106,7 @@ u32 AddrTranslate9[0x2000]; u32 AddrTranslate7[0x4000]; JitBlockEntry FastBlockAccess[ExeMemSpaceSize / 2]; -AddressRange CodeRanges[ExeMemSpaceSize / 256]; +AddressRange CodeRanges[ExeMemSpaceSize / 512]; TinyVector JitBlocks; JitBlock* RestoreCandidates[0x1000] = {NULL}; @@ -285,6 +285,13 @@ InterpreterFunc InterpretARM[ARMInstrInfo::ak_Count] = #undef F_MEM_HD #undef F +void T_BL_LONG(ARM* cpu) +{ + ARMInterpreter::T_BL_LONG_1(cpu); + cpu->R[15] += 2; + ARMInterpreter::T_BL_LONG_2(cpu); +} + #define F(x) ARMInterpreter::T_##x InterpreterFunc InterpretTHUMB[ARMInstrInfo::tk_Count] = { @@ -302,7 +309,7 @@ InterpreterFunc InterpretTHUMB[ARMInstrInfo::tk_Count] = F(PUSH), F(POP), F(LDMIA), F(STMIA), F(BCOND), F(BX), F(BLX_REG), F(B), F(BL_LONG_1), F(BL_LONG_2), F(UNK), F(SVC), - NULL // BL_LONG psudo opcode + T_BL_LONG // BL_LONG psudo opcode }; #undef F @@ -341,7 +348,7 @@ void CompileBlock(ARM* cpu) JIT_DEBUGPRINT("start block %x (%x) %p %p (region invalidates %dx)\n", blockAddr, pseudoPhysicalAddr, FastBlockAccess[pseudoPhysicalAddr / 2], cpu->Num == 0 ? LookUpBlock<0>(blockAddr) : LookUpBlock<1>(blockAddr), - CodeRanges[pseudoPhysicalAddr / 256].TimesInvalidated); + CodeRanges[pseudoPhysicalAddr / 512].TimesInvalidated); u32 lastSegmentStart = blockAddr; @@ -352,7 +359,7 @@ void CompileBlock(ARM* cpu) instrs[i].BranchFlags = 0; instrs[i].SetFlags = 0; instrs[i].Instr = nextInstr[0]; - instrs[i].NextInstr[0] = nextInstr[0] = nextInstr[1]; + nextInstr[0] = nextInstr[1]; instrs[i].Addr = nextInstrAddr[0]; nextInstrAddr[0] = nextInstrAddr[1]; @@ -361,7 +368,7 @@ void CompileBlock(ARM* cpu) u32 translatedAddr = (cpu->Num == 0 ? TranslateAddr<0>(instrs[i].Addr) - : TranslateAddr<1>(instrs[i].Addr)) & ~0xFF; + : TranslateAddr<1>(instrs[i].Addr)) & ~0x1FF; if (i == 0 || translatedAddr != addresseRanges[numAddressRanges - 1]) { bool returning = false; @@ -400,7 +407,6 @@ void CompileBlock(ARM* cpu) nextInstr[1] = cpuv4->CodeRead32(r15); instrs[i].CodeCycles = cpu->CodeCycles; } - instrs[i].NextInstr[1] = nextInstr[1]; instrs[i].Info = ARMInstrInfo::Decode(thumb, cpu->Num, instrs[i].Instr); cpu->R[15] = r15; @@ -584,7 +590,7 @@ void CompileBlock(ARM* cpu) for (int j = 0; j < numAddressRanges; j++) { assert(addresseRanges[j] == block->AddressRanges()[j]); - CodeRanges[addresseRanges[j] / 256].Blocks.Add(block); + CodeRanges[addresseRanges[j] / 512].Blocks.Add(block); } FastBlockAccess[block->PseudoPhysicalAddr / 2] = block->EntryPoint; @@ -595,7 +601,7 @@ void CompileBlock(ARM* cpu) void InvalidateByAddr(u32 pseudoPhysical) { JIT_DEBUGPRINT("invalidating by addr %x\n", pseudoPhysical); - AddressRange* range = &CodeRanges[pseudoPhysical / 256]; + AddressRange* range = &CodeRanges[pseudoPhysical / 512]; int startLength = range->Blocks.Length; for (int i = 0; i < range->Blocks.Length; i++) { @@ -604,15 +610,17 @@ void InvalidateByAddr(u32 pseudoPhysical) for (int j = 0; j < block->NumAddresses; j++) { u32 addr = block->AddressRanges()[j]; - if ((addr / 256) != (pseudoPhysical / 256)) + if ((addr / 512) != (pseudoPhysical / 512)) { - AddressRange* otherRange = &CodeRanges[addr / 256]; + AddressRange* otherRange = &CodeRanges[addr / 512]; assert(otherRange != range); - assert(otherRange->Blocks.RemoveByValue(block)); + bool removed = otherRange->Blocks.RemoveByValue(block); + assert(removed); } } - assert(JitBlocks.RemoveByValue(block)); + bool removed = JitBlocks.RemoveByValue(block); + assert(removed); FastBlockAccess[block->PseudoPhysicalAddr / 2] = NULL; @@ -631,14 +639,14 @@ void InvalidateByAddr(u32 pseudoPhysical) void InvalidateByAddr7(u32 addr) { u32 pseudoPhysical = TranslateAddr<1>(addr); - if (__builtin_expect(CodeRanges[pseudoPhysical / 256].Blocks.Length > 0, false)) + if (__builtin_expect(CodeRanges[pseudoPhysical / 512].Blocks.Length > 0, false)) InvalidateByAddr(pseudoPhysical); } void InvalidateITCM(u32 addr) { u32 pseudoPhysical = addr + ExeMemRegionOffsets[exeMem_ITCM]; - if (CodeRanges[pseudoPhysical / 256].Blocks.Length > 0) + if (CodeRanges[pseudoPhysical / 512].Blocks.Length > 0) InvalidateByAddr(pseudoPhysical); } @@ -654,7 +662,7 @@ void InvalidateAll() for (int j = 0; j < block->NumAddresses; j++) { u32 addr = block->AddressRanges()[j]; - AddressRange* range = &CodeRanges[addr / 256]; + AddressRange* range = &CodeRanges[addr / 512]; range->Blocks.Clear(); if (range->TimesInvalidated + 1 > range->TimesInvalidated) range->TimesInvalidated++; @@ -689,8 +697,8 @@ void ResetBlockCache() for (int j = 0; j < block->NumAddresses; j++) { u32 addr = block->AddressRanges()[j]; - CodeRanges[addr / 256].Blocks.Clear(); - CodeRanges[addr / 256].TimesInvalidated = 0; + CodeRanges[addr / 512].Blocks.Clear(); + CodeRanges[addr / 512].TimesInvalidated = 0; } delete block; } diff --git a/src/ARMJIT_Internal.h b/src/ARMJIT_Internal.h index 4acb488..9e6713d 100644 --- a/src/ARMJIT_Internal.h +++ b/src/ARMJIT_Internal.h @@ -38,7 +38,6 @@ struct FetchedInstr u8 BranchFlags; u8 SetFlags; u32 Instr; - u32 NextInstr[2]; u32 Addr; u8 CodeCycles; @@ -185,7 +184,7 @@ struct __attribute__((packed)) AddressRange u16 TimesInvalidated; }; -extern AddressRange CodeRanges[ExeMemSpaceSize / 256]; +extern AddressRange CodeRanges[ExeMemSpaceSize / 512]; typedef void (*InterpreterFunc)(ARM* cpu); extern InterpreterFunc InterpretARM[]; diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index 13ca415..eb01c87 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -105,7 +105,7 @@ void* Compiler::Gen_MemoryRoutine9(bool store, int size) static_assert(sizeof(AddressRange) == 16); LEA(32, ABI_PARAM1, MDisp(ABI_PARAM3, ExeMemRegionOffsets[exeMem_ITCM])); MOV(32, R(RSCRATCH), R(ABI_PARAM1)); - SHR(32, R(RSCRATCH), Imm8(8)); + SHR(32, R(RSCRATCH), Imm8(9)); SHL(32, R(RSCRATCH), Imm8(4)); CMP(32, MDisp(RSCRATCH, squeezePointer(CodeRanges) + offsetof(AddressRange, Blocks.Length)), Imm8(0)); FixupBranch noCode = J_CC(CC_Z); @@ -203,7 +203,7 @@ void* Compiler::Gen_MemoryRoutineSeq9(bool store, bool preinc) ADD(32, R(RSCRATCH), Imm32(ExeMemRegionOffsets[exeMem_ITCM])); MOV(32, R(ABI_PARAM4), R(RSCRATCH)); - SHR(32, R(RSCRATCH), Imm8(8)); + SHR(32, R(RSCRATCH), Imm8(9)); SHL(32, R(RSCRATCH), Imm8(4)); CMP(32, MDisp(RSCRATCH, squeezePointer(CodeRanges) + offsetof(AddressRange, Blocks.Length)), Imm8(0)); FixupBranch noCode = J_CC(CC_Z); @@ -284,28 +284,29 @@ void fault(u32 a, u32 b) void Compiler::Comp_MemAccess(int rd, int rn, const ComplexOperand& op2, int size, int flags) { - if (flags & memop_Store) - { - Comp_AddCycles_CD(); - } - else - { - Comp_AddCycles_CDI(); - } - u32 addressMask = ~0; if (size == 32) addressMask = ~3; if (size == 16) addressMask = ~1; - if (rn == 15 && rd != 15 && op2.IsImm && !(flags & (memop_Post|memop_Store|memop_Writeback))) + if (rn == 15 && rd != 15 && op2.IsImm && !(flags & (memop_SignExtend|memop_Post|memop_Store|memop_Writeback))) { - Comp_MemLoadLiteral(size, rd, - R15 + op2.Imm * ((flags & memop_SubtractOffset) ? -1 : 1)); + u32 addr = R15 + op2.Imm * ((flags & memop_SubtractOffset) ? -1 : 1); + Comp_MemLoadLiteral(size, rd, addr); + return; } - else + { + if (flags & memop_Store) + { + Comp_AddCycles_CD(); + } + else + { + Comp_AddCycles_CDI(); + } + OpArg rdMapped = MapReg(rd); OpArg rnMapped = MapReg(rn); diff --git a/src/ARM_InstrInfo.cpp b/src/ARM_InstrInfo.cpp index 0fbde26..1261bbe 100644 --- a/src/ARM_InstrInfo.cpp +++ b/src/ARM_InstrInfo.cpp @@ -5,7 +5,7 @@ namespace ARMInstrInfo { -#define ak(x) ((x) << 21) +#define ak(x) ((x) << 22) enum { A_Read0 = 1 << 0, @@ -36,7 +36,8 @@ enum { A_StaticShiftSetC = 1 << 18, A_SetC = 1 << 19, - A_WriteMem = 1 << 20 + A_WriteMem = 1 << 20, + A_LoadMem = 1 << 21 }; #define A_BIOP A_Read16 @@ -122,7 +123,7 @@ const u32 A_QSUB = A_Write12 | A_Read0 | A_Read16 | A_UnkOnARM7 | ak(ak_QSUB); const u32 A_QDADD = A_Write12 | A_Read0 | A_Read16 | A_UnkOnARM7 | ak(ak_QDADD); const u32 A_QDSUB = A_Write12 | A_Read0 | A_Read16 | A_UnkOnARM7 | ak(ak_QDSUB); -#define A_LDR A_Write12 +#define A_LDR A_Write12 | A_LoadMem #define A_STR A_Read12 | A_WriteMem #define A_IMPLEMENT_WB_LDRSTR(x,k) \ @@ -143,7 +144,7 @@ A_IMPLEMENT_WB_LDRSTR(STRB,STR) A_IMPLEMENT_WB_LDRSTR(LDR,LDR) A_IMPLEMENT_WB_LDRSTR(LDRB,LDR) -#define A_LDRD A_Write12Double +#define A_LDRD A_Write12Double | A_LoadMem #define A_STRD A_Read12Double | A_WriteMem #define A_IMPLEMENT_HD_LDRSTR(x,k) \ @@ -159,10 +160,10 @@ A_IMPLEMENT_HD_LDRSTR(LDRH,LDR) A_IMPLEMENT_HD_LDRSTR(LDRSB,LDR) A_IMPLEMENT_HD_LDRSTR(LDRSH,LDR) -const u32 A_SWP = A_Write12 | A_Read16 | A_Read0 | A_WriteMem | ak(ak_SWP); -const u32 A_SWPB = A_Write12 | A_Read16 | A_Read0 | A_WriteMem | ak(ak_SWPB); +const u32 A_SWP = A_Write12 | A_Read16 | A_Read0 | A_LoadMem | A_WriteMem | ak(ak_SWP); +const u32 A_SWPB = A_Write12 | A_Read16 | A_Read0 | A_LoadMem | A_WriteMem | ak(ak_SWPB); -const u32 A_LDM = A_Read16 | A_MemWriteback | ak(ak_LDM); +const u32 A_LDM = A_Read16 | A_MemWriteback | A_LoadMem | ak(ak_LDM); const u32 A_STM = A_Read16 | A_MemWriteback | A_WriteMem | ak(ak_STM); const u32 A_B = A_BranchAlways | ak(ak_B); @@ -360,6 +361,9 @@ Info Decode(bool thumb, u32 num, u32 instr) if (data & T_WriteMem) res.SpecialKind = special_WriteMem; + + if (res.Kind == ARMInstrInfo::tk_LDR_PCREL) + res.SpecialKind = special_LoadLiteral; res.EndBlock |= res.Branches(); @@ -377,7 +381,7 @@ Info Decode(bool thumb, u32 num, u32 instr) if (data & A_UnkOnARM7 && num != 0) data = A_UNK; - res.Kind = (data >> 21) & 0x1FF; + res.Kind = (data >> 22) & 0x1FF; if (res.Kind == ak_MCR) { @@ -454,12 +458,15 @@ Info Decode(bool thumb, u32 num, u32 instr) res.ReadFlags |= flag_C; if ((data & A_RRXReadC) && !((instr >> 7) & 0x1F)) res.ReadFlags |= flag_C; - if ((data & A_SetC) || (data & A_StaticShiftSetC) && ((instr >> 7) & 0x1F)) + if ((data & A_SetC) || ((data & A_StaticShiftSetC) && ((instr >> 7) & 0x1F))) res.WriteFlags |= flag_C; if (data & A_WriteMem) res.SpecialKind = special_WriteMem; + if ((data & A_LoadMem) && res.SrcRegs == (1 << 15)) + res.SpecialKind = special_LoadLiteral; + if ((instr >> 28) < 0xE) { // make non conditional flag sets conditional diff --git a/src/ARM_InstrInfo.h b/src/ARM_InstrInfo.h index d02f168..c032a4f 100644 --- a/src/ARM_InstrInfo.h +++ b/src/ARM_InstrInfo.h @@ -230,7 +230,8 @@ enum { special_NotSpecialAtAll = 0, special_WriteMem, - special_WaitForInterrupt + special_WaitForInterrupt, + special_LoadLiteral }; struct Info -- cgit v1.2.3 From 441869a10567c2da3de210052cbe93d783a9ce83 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Fri, 18 Oct 2019 13:29:17 +0200 Subject: integrate changes from ARM64 backend and more - better handle LDM/STM in reg alloc - unify Halted and IRQ in anticipation for branch inlining - literal optimisations can be disabled in gui - jit blocks follow simple returns - fix idle loop detection - break jit blocks on IRQ (fixes saving in Pokemon White) --- src/ARM.cpp | 40 ++++++++++++++++++----------- src/ARM.h | 13 +++++++--- src/ARMJIT.cpp | 50 +++++++++++++++++++++++++++++++------ src/ARMJIT_RegisterCache.h | 33 +++++++++++++++++++----- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 7 +++--- src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 16 ++++++++---- src/ARM_InstrInfo.cpp | 28 +++++++++++++++++++++ src/ARM_InstrInfo.h | 2 +- src/Config.cpp | 2 ++ src/Config.h | 1 + src/NDS.cpp | 4 +-- 11 files changed, 153 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/ARM.cpp b/src/ARM.cpp index 1e75301..2f4aa90 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -159,7 +159,7 @@ void ARM::DoSavestate(Savestate* file) file->Var32((u32*)&Cycles); //file->Var32((u32*)&CyclesToRun); - file->Var32(&Halted); + file->Var32(&StopExecution); file->VarArray(R, 16*sizeof(u32)); file->Var32(&CPSR); @@ -632,16 +632,21 @@ void ARMv5::ExecuteJIT() NDS::ARM9Timestamp += Cycles; Cycles = 0; - if (IRQ) TriggerIRQ(); - if (Halted) + if (StopExecution) { - bool idleLoop = Halted & 0x20; - Halted &= ~0x20; - if ((Halted == 1 || idleLoop) && NDS::ARM9Timestamp < NDS::ARM9Target) + if (IRQ) + TriggerIRQ(); + + if (Halted || IdleLoop) { - NDS::ARM9Timestamp = NDS::ARM9Target; + bool idleLoop = IdleLoop; + IdleLoop = 0; + if ((Halted == 1 || idleLoop) && NDS::ARM9Timestamp < NDS::ARM9Target) + { + NDS::ARM9Timestamp = NDS::ARM9Target; + } + break; } - break; } } @@ -769,16 +774,21 @@ void ARMv4::ExecuteJIT() Cycles = 0; // TODO optimize this shit!!! - if (IRQ) TriggerIRQ(); - if (Halted) + if (StopExecution) { - bool idleLoop = Halted & 0x20; - Halted &= ~0x20; - if ((Halted == 1 || idleLoop) && NDS::ARM7Timestamp < NDS::ARM7Target) + if (IRQ) + TriggerIRQ(); + + if (Halted || IdleLoop) { - NDS::ARM7Timestamp = NDS::ARM7Target; + bool idleLoop = IdleLoop; + IdleLoop = 0; + if ((Halted == 1 || idleLoop) && NDS::ARM7Timestamp < NDS::ARM7Target) + { + NDS::ARM7Timestamp = NDS::ARM7Target; + } + break; } - break; } } diff --git a/src/ARM.h b/src/ARM.h index b36120a..96dd857 100644 --- a/src/ARM.h +++ b/src/ARM.h @@ -112,9 +112,16 @@ public: u32 Num; s32 Cycles; - u32 Halted; - - u32 IRQ; // nonzero to trigger IRQ + union + { + struct + { + u8 Halted; + u8 IRQ; // nonzero to trigger IRQ + u8 IdleLoop; + }; + u32 StopExecution; + }; u32 CodeRegion; s32 CodeCycles; diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 19a5e70..0695b85 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -16,11 +16,13 @@ #include "GPU3D.h" #include "SPU.h" #include "Wifi.h" +#include "NDSCart.h" namespace ARMJIT { #define JIT_DEBUGPRINT(msg, ...) +//#define JIT_DEBUGPRINT(msg, ...) printf(msg, ## __VA_ARGS__) Compiler* compiler; @@ -159,13 +161,17 @@ void FloodFillSetFlags(FetchedInstr instrs[], int start, u8 flags) } } -bool DecodeBranch(bool thumb, const FetchedInstr& instr, u32& cond, u32& targetAddr) +bool DecodeBranch(bool thumb, const FetchedInstr& instr, u32& cond, bool hasLink, u32 lr, bool& link, + u32& linkAddr, u32& targetAddr) { if (thumb) { u32 r15 = instr.Addr + 4; cond = 0xE; + link = instr.Info.Kind == ARMInstrInfo::tk_BL_LONG; + linkAddr = instr.Addr + 4; + if (instr.Info.Kind == ARMInstrInfo::tk_BL_LONG && !(instr.Instr & (1 << 12))) { targetAddr = r15 + ((s32)((instr.Instr & 0x7FF) << 21) >> 9); @@ -185,9 +191,18 @@ bool DecodeBranch(bool thumb, const FetchedInstr& instr, u32& cond, u32& targetA targetAddr = r15 + offset; return true; } + else if (hasLink && instr.Info.Kind == ARMInstrInfo::tk_BX && instr.A_Reg(3) == 14) + { + JIT_DEBUGPRINT("returning!\n"); + targetAddr = lr; + return true; + } } else { + link = instr.Info.Kind == ARMInstrInfo::ak_BL; + linkAddr = instr.Addr + 4; + cond = instr.Cond(); if (instr.Info.Kind == ARMInstrInfo::ak_BL || instr.Info.Kind == ARMInstrInfo::ak_B) @@ -197,6 +212,12 @@ bool DecodeBranch(bool thumb, const FetchedInstr& instr, u32& cond, u32& targetA targetAddr = r15 + offset; return true; } + else if (hasLink && instr.Info.Kind == ARMInstrInfo::ak_BX && instr.A_Reg(0) == 14) + { + JIT_DEBUGPRINT("returning!\n"); + targetAddr = lr; + return true; + } } return false; } @@ -351,6 +372,8 @@ void CompileBlock(ARM* cpu) CodeRanges[pseudoPhysicalAddr / 512].TimesInvalidated); u32 lastSegmentStart = blockAddr; + u32 lr; + bool hasLink = false; do { @@ -413,6 +436,9 @@ void CompileBlock(ARM* cpu) cpu->CurInstr = instrs[i].Instr; cpu->CodeCycles = instrs[i].CodeCycles; + if (instrs[i].Info.DstRegs & (1 << 14)) + hasLink = false; + if (thumb) { InterpretTHUMB[instrs[i].Info.Kind](cpu); @@ -452,8 +478,9 @@ void CompileBlock(ARM* cpu) { bool hasBranched = cpu->R[15] != r15; - u32 cond, target; - bool staticBranch = DecodeBranch(thumb, instrs[i], cond, target); + bool link; + u32 cond, target, linkAddr; + bool staticBranch = DecodeBranch(thumb, instrs[i], cond, hasLink, lr, link, linkAddr, target); JIT_DEBUGPRINT("branch cond %x target %x (%d)\n", cond, target, hasBranched); if (staticBranch) @@ -474,18 +501,24 @@ void CompileBlock(ARM* cpu) if (cond < 0xE && target < instrs[i].Addr && target >= lastSegmentStart) { // we might have an idle loop - u32 offset = (target - blockAddr) / (thumb ? 2 : 4); - if (IsIdleLoop(instrs + offset, i - offset + 1)) + u32 backwardsOffset = (instrs[i].Addr - target) / (thumb ? 2 : 4); + if (IsIdleLoop(&instrs[i - backwardsOffset], backwardsOffset + 1)) { instrs[i].BranchFlags |= branch_IdleBranch; JIT_DEBUGPRINT("found %s idle loop %d in block %x\n", thumb ? "thumb" : "arm", cpu->Num, blockAddr); } } - else if (hasBranched && (!thumb || cond == 0xE) && !isBackJump && i + 1 < Config::JIT_MaxBlockSize) + else if (hasBranched && !isBackJump && i + 1 < Config::JIT_MaxBlockSize) { u32 targetPseudoPhysical = cpu->Num == 0 ? TranslateAddr<0>(target) : TranslateAddr<1>(target); + + if (link) + { + lr = linkAddr; + hasLink = true; + } r15 = target + (thumb ? 2 : 4); assert(r15 == cpu->R[15]); @@ -520,7 +553,7 @@ void CompileBlock(ARM* cpu) bool secondaryFlagReadCond = !canCompile || (instrs[i - 1].BranchFlags & (branch_FollowCondTaken | branch_FollowCondNotTaken)); if (instrs[i - 1].Info.ReadFlags != 0 || secondaryFlagReadCond) FloodFillSetFlags(instrs, i - 2, !secondaryFlagReadCond ? instrs[i - 1].Info.ReadFlags : 0xF); - } while(!instrs[i - 1].Info.EndBlock && i < Config::JIT_MaxBlockSize && !cpu->Halted); + } while(!instrs[i - 1].Info.EndBlock && i < Config::JIT_MaxBlockSize && !cpu->Halted && (!cpu->IRQ || (cpu->CPSR & 0x80))); u32 restoreSlot = HashRestoreCandidate(pseudoPhysicalAddr); JitBlock* prevBlock = RestoreCandidates[restoreSlot]; @@ -713,6 +746,9 @@ void* GetFuncForAddr(ARM* cpu, u32 addr, bool store, int size) { if ((addr & 0xFF000000) == 0x04000000) { + if (!store && size == 32 && addr == 0x04100010 && NDS::ExMemCnt[0] & (1<<11)) + return (void*)NDSCart::ReadROMData; + /* unfortunately we can't map GPU2D this way since it's hidden inside an object diff --git a/src/ARMJIT_RegisterCache.h b/src/ARMJIT_RegisterCache.h index ed6a2b7..2222bc2 100644 --- a/src/ARMJIT_RegisterCache.h +++ b/src/ARMJIT_RegisterCache.h @@ -93,10 +93,12 @@ public: void Prepare(bool thumb, int i) { + FetchedInstr instr = Instrs[i]; + if (LoadedRegs & (1 << 15)) UnloadRegister(15); - BitSet16 invalidedLiterals(LiteralsLoaded & Instrs[i].Info.DstRegs); + BitSet16 invalidedLiterals(LiteralsLoaded & instr.Info.DstRegs); for (int reg : invalidedLiterals) UnloadLiteral(reg); @@ -108,6 +110,7 @@ public: { BitSet16 regsNeeded((Instrs[j].Info.SrcRegs & ~(1 << 15)) | Instrs[j].Info.DstRegs); futureNeeded |= regsNeeded.m_val; + regsNeeded &= BitSet16(~Instrs[j].Info.NotStrictlyNeeded); for (int reg : regsNeeded) ranking[reg]++; } @@ -117,8 +120,8 @@ public: for (int reg : neverNeededAgain) UnloadRegister(reg); - FetchedInstr Instr = Instrs[i]; - u16 necessaryRegs = (Instr.Info.SrcRegs & ~(1 << 15)) | Instr.Info.DstRegs; + u16 necessaryRegs = ((instr.Info.SrcRegs & ~(1 << 15)) | instr.Info.DstRegs) & ~instr.Info.NotStrictlyNeeded; + u16 writeRegs = instr.Info.DstRegs & ~instr.Info.NotStrictlyNeeded; BitSet16 needToBeLoaded(necessaryRegs & ~LoadedRegs); if (needToBeLoaded != BitSet16(0)) { @@ -143,13 +146,31 @@ public: loadedSet.m_val = LoadedRegs; } + // we don't need to load a value which is always going to be overwritten BitSet16 needValueLoaded(needToBeLoaded); - if (thumb || Instr.Cond() >= 0xE) - needValueLoaded = BitSet16(Instr.Info.SrcRegs); + if (thumb || instr.Cond() >= 0xE) + needValueLoaded = BitSet16(instr.Info.SrcRegs); for (int reg : needToBeLoaded) LoadRegister(reg, needValueLoaded[reg]); + } + { + BitSet16 loadedSet(LoadedRegs); + BitSet16 loadRegs(instr.Info.NotStrictlyNeeded & futureNeeded & ~LoadedRegs); + if (loadRegs && loadedSet.Count() < NativeRegsAvailable) + { + int left = NativeRegsAvailable - loadedSet.Count(); + for (int reg : loadRegs) + { + if (left-- == 0) + break; + + writeRegs |= (1 << reg) & instr.Info.DstRegs; + LoadRegister(reg, !(thumb || instr.Cond() >= 0xE) || (1 << reg) & instr.Info.SrcRegs); + } + } } - DirtyRegs |= Instr.Info.DstRegs & ~(1 << 15); + + DirtyRegs |= writeRegs & ~(1 << 15); } static const Reg NativeRegAllocOrder[]; diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index a994d34..fd38724 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -364,7 +364,7 @@ void Compiler::Reset() void Compiler::Comp_SpecialBranchBehaviour() { if (CurInstr.BranchFlags & branch_IdleBranch) - OR(32, MDisp(RCPU, offsetof(ARM, Halted)), Imm8(0x20)); + OR(32, MDisp(RCPU, offsetof(ARM, IdleLoop)), Imm8(0x1)); if (CurInstr.BranchFlags & branch_FollowCondNotTaken) { @@ -402,6 +402,7 @@ JitBlockEntry Compiler::CompileBlock(ARM* cpu, bool thumb, FetchedInstr instrs[] { CurInstr = instrs[i]; R15 = CurInstr.Addr + (Thumb ? 4 : 8); + CodeRegion = R15 >> 24; Exit = i == instrsCount - 1 || (CurInstr.BranchFlags & branch_FollowCondNotTaken); @@ -571,8 +572,6 @@ void Compiler::Comp_AddCycles_CDI() Comp_AddCycles_CD(); else { - IrregularCycles = true; - s32 cycles; s32 numC = NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2]; @@ -642,7 +641,7 @@ void Compiler::Comp_AddCycles_CD() IrregularCycles = true; } - if (!Thumb && CurInstr.Cond() < 0xE) + if (IrregularCycles && !Thumb && CurInstr.Cond() < 0xE) ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm8(cycles)); else ConstantCycles += cycles; diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index eb01c87..3799774 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -1,5 +1,6 @@ #include "ARMJIT_Compiler.h" +#include "../Config.h" using namespace Gen; @@ -290,7 +291,7 @@ void Compiler::Comp_MemAccess(int rd, int rn, const ComplexOperand& op2, int siz if (size == 16) addressMask = ~1; - if (rn == 15 && rd != 15 && op2.IsImm && !(flags & (memop_SignExtend|memop_Post|memop_Store|memop_Writeback))) + if (Config::JIT_LiteralOptimisations && rn == 15 && rd != 15 && op2.IsImm && !(flags & (memop_SignExtend|memop_Post|memop_Store|memop_Writeback))) { u32 addr = R15 + op2.Imm * ((flags & memop_SubtractOffset) ? -1 : 1); Comp_MemLoadLiteral(size, rd, addr); @@ -309,6 +310,8 @@ void Compiler::Comp_MemAccess(int rd, int rn, const ComplexOperand& op2, int siz OpArg rdMapped = MapReg(rd); OpArg rnMapped = MapReg(rn); + if (Thumb && rn == 15) + rnMapped = Imm32(R15 & ~0x2); bool inlinePreparation = Num == 1; u32 constLocalROR32 = 4; @@ -317,7 +320,7 @@ void Compiler::Comp_MemAccess(int rd, int rn, const ComplexOperand& op2, int siz ? MemoryFuncs9[size >> 4][!!(flags & memop_Store)] : MemoryFuncs7[size >> 4][!!((flags & memop_Store))]; - if ((rd != 15 || (flags & memop_Store)) && op2.IsImm && RegCache.IsLiteral(rn)) + if (Config::JIT_LiteralOptimisations && (rd != 15 || (flags & memop_Store)) && op2.IsImm && RegCache.IsLiteral(rn)) { u32 addr = RegCache.LiteralValues[rn] + op2.Imm * ((flags & memop_SubtractOffset) ? -1 : 1); @@ -749,9 +752,12 @@ void Compiler::T_Comp_MemImmHalf() void Compiler::T_Comp_LoadPCRel() { - u32 addr = (R15 & ~0x2) + ((CurInstr.Instr & 0xFF) << 2); - - Comp_MemLoadLiteral(32, CurInstr.T_Reg(8), addr); + u32 offset = (CurInstr.Instr & 0xFF) << 2; + u32 addr = (R15 & ~0x2) + offset; + if (Config::JIT_LiteralOptimisations) + Comp_MemLoadLiteral(32, CurInstr.T_Reg(8), addr); + else + Comp_MemAccess(CurInstr.T_Reg(8), 15, ComplexOperand(offset), 32, 0); } void Compiler::T_Comp_MemSPRel() diff --git a/src/ARM_InstrInfo.cpp b/src/ARM_InstrInfo.cpp index 1261bbe..8f8bd35 100644 --- a/src/ARM_InstrInfo.cpp +++ b/src/ARM_InstrInfo.cpp @@ -365,6 +365,21 @@ Info Decode(bool thumb, u32 num, u32 instr) if (res.Kind == ARMInstrInfo::tk_LDR_PCREL) res.SpecialKind = special_LoadLiteral; + if (res.Kind == tk_LDMIA || res.Kind == tk_POP) + { + u32 set = (instr & 0xFF) & ~(res.DstRegs|res.SrcRegs); + res.NotStrictlyNeeded |= set; + res.DstRegs |= set; + } + if (res.Kind == tk_STMIA || res.Kind == tk_PUSH) + { + u32 set = (instr & 0xFF) & ~(res.DstRegs|res.SrcRegs); + if (res.Kind == tk_PUSH && instr & (1 << 8)) + set |= (1 << 14); + res.NotStrictlyNeeded |= set; + res.SrcRegs |= set; + } + res.EndBlock |= res.Branches(); if (res.Kind == tk_BCOND) @@ -466,6 +481,19 @@ Info Decode(bool thumb, u32 num, u32 instr) if ((data & A_LoadMem) && res.SrcRegs == (1 << 15)) res.SpecialKind = special_LoadLiteral; + + if (res.Kind == ak_LDM) + { + u16 set = (instr & 0xFFFF) & ~(res.SrcRegs|res.DstRegs|(1<<15)); + res.DstRegs |= set; + res.NotStrictlyNeeded |= set; + } + if (res.Kind == ak_STM) + { + u16 set = (instr & 0xFFFF) & ~(res.SrcRegs|res.DstRegs|(1<<15)); + res.SrcRegs |= set; + res.NotStrictlyNeeded |= set; + } if ((instr >> 28) < 0xE) { diff --git a/src/ARM_InstrInfo.h b/src/ARM_InstrInfo.h index c032a4f..2732181 100644 --- a/src/ARM_InstrInfo.h +++ b/src/ARM_InstrInfo.h @@ -236,7 +236,7 @@ enum struct Info { - u16 DstRegs, SrcRegs; + u16 DstRegs, SrcRegs, NotStrictlyNeeded; u16 Kind; u8 SpecialKind; diff --git a/src/Config.cpp b/src/Config.cpp index c117a41..a7d78cd 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -41,6 +41,7 @@ char DSiNANDPath[1024]; bool JIT_Enable = false; int JIT_MaxBlockSize = 12; bool JIT_BrancheOptimisations = true; +bool JIT_LiteralOptimisations = true; #endif ConfigEntry ConfigFile[] = @@ -58,6 +59,7 @@ ConfigEntry ConfigFile[] = {"JIT_Enable", 0, &JIT_Enable, 0, NULL, 0}, {"JIT_MaxBlockSize", 0, &JIT_MaxBlockSize, 10, NULL, 0}, {"JIT_BrancheOptimisations", 0, &JIT_BrancheOptimisations, 1, NULL, 0}, + {"JIT_BrancheOptimisations", 0, &JIT_LiteralOptimisations, 1, NULL, 0}, #endif {"", -1, NULL, 0, NULL, 0} diff --git a/src/Config.h b/src/Config.h index c9013aa..1fcd9bb 100644 --- a/src/Config.h +++ b/src/Config.h @@ -55,6 +55,7 @@ extern char DSiNANDPath[1024]; extern bool JIT_Enable; extern int JIT_MaxBlockSize; extern bool JIT_BrancheOptimisations; +extern bool JIT_LiteralOptimisations; #endif } diff --git a/src/NDS.cpp b/src/NDS.cpp index 0cfbd1a..7b6a450 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -1211,9 +1211,9 @@ void UpdateIRQ(u32 cpu) if (IME[cpu] & 0x1) { - arm->IRQ = IE[cpu] & IF[cpu]; + arm->IRQ = !!(IE[cpu] & IF[cpu]); if ((ConsoleType == 1) && cpu) - arm->IRQ |= (IE2 & IF2); + arm->IRQ |= !!(IE2 & IF2); } else { -- cgit v1.2.3 From d1d96d2236b705a6c7c0b68d56bc4c8c1e72ec42 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Fri, 18 Oct 2019 18:03:31 +0200 Subject: fix config key for jit literal optimisations --- src/Config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Config.cpp b/src/Config.cpp index a7d78cd..07b1e3e 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -59,7 +59,7 @@ ConfigEntry ConfigFile[] = {"JIT_Enable", 0, &JIT_Enable, 0, NULL, 0}, {"JIT_MaxBlockSize", 0, &JIT_MaxBlockSize, 10, NULL, 0}, {"JIT_BrancheOptimisations", 0, &JIT_BrancheOptimisations, 1, NULL, 0}, - {"JIT_BrancheOptimisations", 0, &JIT_LiteralOptimisations, 1, NULL, 0}, + {"JIT_LiteralOptimisations", 0, &JIT_LiteralOptimisations, 1, NULL, 0}, #endif {"", -1, NULL, 0, NULL, 0} -- cgit v1.2.3 From 3e7483636f69f18da0efabc10686ed4ab04c6b86 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sun, 3 Nov 2019 15:33:20 +0100 Subject: make literal optimisation more reliable fixes spanish Pokemon HeartGold --- src/ARMJIT.cpp | 52 +++++++++++++++++++++++++++++++++---- src/ARMJIT.h | 2 +- src/ARMJIT_Internal.h | 3 ++- src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 34 +++++++++++++++++++----- 4 files changed, 77 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 0695b85..c7387c9 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -161,6 +161,27 @@ void FloodFillSetFlags(FetchedInstr instrs[], int start, u8 flags) } } +bool DecodeLiteral(const FetchedInstr& instr, u32& addr) +{ + switch (instr.Info.Kind) + { + case ARMInstrInfo::ak_STR_IMM: + case ARMInstrInfo::ak_STRB_IMM: + addr = (instr.Addr + 8) + ((instr.Instr & 0xFFF) * (instr.Instr & (1 << 23) ? 1 : -1)); + return true; + case ARMInstrInfo::ak_STRD_IMM: + case ARMInstrInfo::ak_STRH_IMM: + addr = (instr.Addr + 8) + (((instr.Instr & 0xF00) >> 4 | (instr.Instr & 0xF)) * (instr.Instr & (1 << 23) ? 1 : -1)); + return true; + case ARMInstrInfo::ak_STM: // I honestly hope noone was ever crazy enough to do stm pc, {whatever} + addr = instr.Addr + 8; + return true; + default: + JIT_DEBUGPRINT("Literal %08x %x not recognised\n", instr.Instr, instr.Addr); + return false; + } +} + bool DecodeBranch(bool thumb, const FetchedInstr& instr, u32& cond, bool hasLink, u32 lr, bool& link, u32& linkAddr, u32& targetAddr) { @@ -463,6 +484,23 @@ void CompileBlock(ARM* cpu) instrs[i].DataCycles = cpu->DataCycles; instrs[i].DataRegion = cpu->DataRegion; + if (instrs[i].Info.SpecialKind == ARMInstrInfo::special_WriteMem + && instrs[i].Info.SrcRegs == (1 << 15) + && instrs[i].Info.DstRegs == 0) + { + assert (!thumb); + + u32 addr; + if (DecodeLiteral(instrs[i], addr)) + { + JIT_DEBUGPRINT("pc relative write detected\n"); + u32 translatedAddr = cpu->Num == 0 ? TranslateAddr<0>(addr) : TranslateAddr<1>(addr); + + ARMJIT::InvalidateByAddr(translatedAddr, false); + CodeRanges[translatedAddr / 512].InvalidLiterals |= (1 << ((translatedAddr & 0x1FF) / 16)); + } + } + if (thumb && instrs[i].Info.Kind == ARMInstrInfo::tk_BL_LONG_2 && i > 0 && instrs[i - 1].Info.Kind == ARMInstrInfo::tk_BL_LONG_1) { @@ -631,7 +669,7 @@ void CompileBlock(ARM* cpu) JitBlocks.Add(block); } -void InvalidateByAddr(u32 pseudoPhysical) +void InvalidateByAddr(u32 pseudoPhysical, bool mayRestore) { JIT_DEBUGPRINT("invalidating by addr %x\n", pseudoPhysical); AddressRange* range = &CodeRanges[pseudoPhysical / 512]; @@ -657,11 +695,14 @@ void InvalidateByAddr(u32 pseudoPhysical) FastBlockAccess[block->PseudoPhysicalAddr / 2] = NULL; - u32 slot = HashRestoreCandidate(block->PseudoPhysicalAddr); - if (RestoreCandidates[slot] && RestoreCandidates[slot] != block) - delete RestoreCandidates[slot]; + if (mayRestore) + { + u32 slot = HashRestoreCandidate(block->PseudoPhysicalAddr); + if (RestoreCandidates[slot] && RestoreCandidates[slot] != block) + delete RestoreCandidates[slot]; - RestoreCandidates[slot] = block; + RestoreCandidates[slot] = block; + } } if ((range->TimesInvalidated + 1) > range->TimesInvalidated) range->TimesInvalidated++; @@ -732,6 +773,7 @@ void ResetBlockCache() u32 addr = block->AddressRanges()[j]; CodeRanges[addr / 512].Blocks.Clear(); CodeRanges[addr / 512].TimesInvalidated = 0; + CodeRanges[addr / 512].InvalidLiterals = 0; } delete block; } diff --git a/src/ARMJIT.h b/src/ARMJIT.h index 1db4d66..09cc463 100644 --- a/src/ARMJIT.h +++ b/src/ARMJIT.h @@ -61,7 +61,7 @@ inline JitBlockEntry LookUpBlock(u32 addr) void Init(); void DeInit(); -void InvalidateByAddr(u32 pseudoPhysical); +void InvalidateByAddr(u32 pseudoPhysical, bool mayRestore = true); void InvalidateAll(); void InvalidateITCM(u32 addr); diff --git a/src/ARMJIT_Internal.h b/src/ARMJIT_Internal.h index 9e6713d..fb05f75 100644 --- a/src/ARMJIT_Internal.h +++ b/src/ARMJIT_Internal.h @@ -63,7 +63,7 @@ struct __attribute__((packed)) TinyVector { T* Data = NULL; u16 Capacity = 0; - u32 Length = 0; // make it 32 bit so we don't need movzx + u16 Length = 0; ~TinyVector() { @@ -181,6 +181,7 @@ private: struct __attribute__((packed)) AddressRange { TinyVector Blocks; + u16 InvalidLiterals; u16 TimesInvalidated; }; diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index 3799774..82f80a7 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -108,7 +108,7 @@ void* Compiler::Gen_MemoryRoutine9(bool store, int size) MOV(32, R(RSCRATCH), R(ABI_PARAM1)); SHR(32, R(RSCRATCH), Imm8(9)); SHL(32, R(RSCRATCH), Imm8(4)); - CMP(32, MDisp(RSCRATCH, squeezePointer(CodeRanges) + offsetof(AddressRange, Blocks.Length)), Imm8(0)); + CMP(16, MDisp(RSCRATCH, squeezePointer(CodeRanges) + offsetof(AddressRange, Blocks.Length)), Imm8(0)); FixupBranch noCode = J_CC(CC_Z); JMP((u8*)InvalidateByAddr, true); SetJumpTarget(noCode); @@ -206,7 +206,7 @@ void* Compiler::Gen_MemoryRoutineSeq9(bool store, bool preinc) MOV(32, R(ABI_PARAM4), R(RSCRATCH)); SHR(32, R(RSCRATCH), Imm8(9)); SHL(32, R(RSCRATCH), Imm8(4)); - CMP(32, MDisp(RSCRATCH, squeezePointer(CodeRanges) + offsetof(AddressRange, Blocks.Length)), Imm8(0)); + CMP(16, MDisp(RSCRATCH, squeezePointer(CodeRanges) + offsetof(AddressRange, Blocks.Length)), Imm8(0)); FixupBranch noCode = J_CC(CC_Z); ABI_PushRegistersAndAdjustStack({ABI_PARAM1, ABI_PARAM2, ABI_PARAM3}, 8); MOV(32, R(ABI_PARAM1), R(ABI_PARAM4)); @@ -278,10 +278,10 @@ void Compiler::Comp_MemLoadLiteral(int size, int rd, u32 addr) Comp_AddCycles_CDI(); } -void fault(u32 a, u32 b) +/*void fault(u32 a, u32 b, u32 c, u32 d) { - printf("actually not static! %x %x\n", a, b); -} + printf("actually not static! %x %x %x %x\n", a, b, c, d); +}*/ void Compiler::Comp_MemAccess(int rd, int rn, const ComplexOperand& op2, int size, int flags) { @@ -291,11 +291,17 @@ void Compiler::Comp_MemAccess(int rd, int rn, const ComplexOperand& op2, int siz if (size == 16) addressMask = ~1; + //bool check = false; if (Config::JIT_LiteralOptimisations && rn == 15 && rd != 15 && op2.IsImm && !(flags & (memop_SignExtend|memop_Post|memop_Store|memop_Writeback))) { u32 addr = R15 + op2.Imm * ((flags & memop_SubtractOffset) ? -1 : 1); - Comp_MemLoadLiteral(size, rd, addr); - return; + u32 translatedAddr = Num == 0 ? TranslateAddr<0>(addr) : TranslateAddr<1>(addr); + + if (!(CodeRanges[translatedAddr / 512].InvalidLiterals & (1 << ((translatedAddr & 0x1FF) / 16)))) + { + Comp_MemLoadLiteral(size, rd, addr); + return; + } } { @@ -438,6 +444,20 @@ void Compiler::Comp_MemAccess(int rd, int rn, const ComplexOperand& op2, int siz CALL(memoryFunc); + /*if (Num == 0 && check) + { + CMP(32, R(EAX), rdMapped); + FixupBranch notEqual = J_CC(CC_E); + ABI_PushRegistersAndAdjustStack({RSCRATCH}, 0); + MOV(32, R(ABI_PARAM1), Imm32(R15 - (Thumb ? 4 : 8))); + MOV(32, R(ABI_PARAM2), R(EAX)); + MOV(32, R(ABI_PARAM3), rdMapped); + MOV(32, R(ABI_PARAM4), Imm32(CurInstr.Instr)); + CALL((u8*)fault); + ABI_PopRegistersAndAdjustStack({RSCRATCH}, 0); + SetJumpTarget(notEqual); + }*/ + if (!(flags & memop_Store)) { if (inlinePreparation && size == 32) -- cgit v1.2.3 From 1cfbbcbb2af09c7f56ca3f6303b0ce8a36cd7146 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Tue, 5 Nov 2019 18:50:17 +0100 Subject: make savestates 100% compatible again --- src/ARM.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ARM.cpp b/src/ARM.cpp index 2f4aa90..896bb5c 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -159,7 +159,11 @@ void ARM::DoSavestate(Savestate* file) file->Var32((u32*)&Cycles); //file->Var32((u32*)&CyclesToRun); - file->Var32(&StopExecution); + + // hack to make save states compatible + u32 halted = Halted; + file->Var32(&halted); + Halted = halted; file->VarArray(R, 16*sizeof(u32)); file->Var32(&CPSR); -- cgit v1.2.3 From 000c03c9d6307faa7b52988da1510cc4d0dcd8a3 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Fri, 6 Dec 2019 22:16:23 +0100 Subject: disable literal optimations in DTCM --- src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index 82f80a7..b66f304 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -347,8 +347,10 @@ void Compiler::Comp_MemAccess(int rd, int rn, const ComplexOperand& op2, int siz // stupid dtcm... if (addr >= cpu5->DTCMBase && addr < (cpu5->DTCMBase + cpu5->DTCMSize)) { - region.Mem = cpu5->DTCM; - region.Mask = 0x3FFF; + // disable this for now as DTCM is located in heap + // which might excced the RIP-addressable range + //region.Mem = cpu5->DTCM; + //region.Mask = 0x3FFF; } else { -- cgit v1.2.3 From ec965c6014df2eb252d9da498684e94fe41fece4 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Tue, 4 Feb 2020 17:28:51 +0100 Subject: improve nop handling and proper behaviour for LDM^ fixes dslinux --- src/ARM.cpp | 2 ++ src/ARMJIT.cpp | 13 +++++++++---- src/ARMJIT_RegisterCache.h | 2 +- src/ARMJIT_x64/ARMJIT_Branch.cpp | 6 +++--- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 1 + src/ARMJIT_x64/ARMJIT_Compiler.h | 2 ++ src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 5 +++-- src/ARM_InstrInfo.cpp | 2 ++ src/ARM_InstrInfo.h | 2 ++ 9 files changed, 25 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/ARM.cpp b/src/ARM.cpp index 896bb5c..fc0b898 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -768,6 +768,8 @@ void ARMv4::ExecuteJIT() return; } + //printf("executing armv4 at %08x\n", instrAddr); + ARMJIT::JitBlockEntry block = ARMJIT::LookUpBlock<1>(instrAddr); if (block) Cycles += block(); diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index c7387c9..8fd7708 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -273,6 +273,8 @@ bool IsIdleLoop(FetchedInstr* instrs, int instrsCount) typedef void (*InterpreterFunc)(ARM* cpu); +void NOP(ARM* cpu) {} + #define F(x) &ARMInterpreter::A_##x #define F_ALU(name, s) \ F(name##_REG_LSL_IMM##s), F(name##_REG_LSR_IMM##s), F(name##_REG_ASR_IMM##s), F(name##_REG_ROR_IMM##s), \ @@ -320,7 +322,8 @@ InterpreterFunc InterpretARM[ARMInstrInfo::ak_Count] = F(LDM), F(STM), F(B), F(BL), F(BLX_IMM), F(BX), F(BLX_REG), - F(UNK), F(MSR_IMM), F(MSR_REG), F(MRS), F(MCR), F(MRC), F(SVC) + F(UNK), F(MSR_IMM), F(MSR_REG), F(MRS), F(MCR), F(MRC), F(SVC), + NOP }; #undef F_ALU #undef F_MEM_WB @@ -387,8 +390,8 @@ void CompileBlock(ARM* cpu) u32 nextInstr[2] = {cpu->NextInstr[0], cpu->NextInstr[1]}; u32 nextInstrAddr[2] = {blockAddr, r15}; - JIT_DEBUGPRINT("start block %x (%x) %p %p (region invalidates %dx)\n", - blockAddr, pseudoPhysicalAddr, FastBlockAccess[pseudoPhysicalAddr / 2], + JIT_DEBUGPRINT("start block %x %08x (%x) %p %p (region invalidates %dx)\n", + blockAddr, cpu->CPSR, pseudoPhysicalAddr, FastBlockAccess[pseudoPhysicalAddr / 2], cpu->Num == 0 ? LookUpBlock<0>(blockAddr) : LookUpBlock<1>(blockAddr), CodeRanges[pseudoPhysicalAddr / 512].TimesInvalidated); @@ -473,7 +476,9 @@ void CompileBlock(ARM* cpu) else { u32 icode = ((instrs[i].Instr >> 4) & 0xF) | ((instrs[i].Instr >> 16) & 0xFF0); - assert(InterpretARM[instrs[i].Info.Kind] == ARMInterpreter::ARMInstrTable[icode] || instrs[i].Info.Kind == ARMInstrInfo::ak_MOV_REG_LSL_IMM); + assert(InterpretARM[instrs[i].Info.Kind] == ARMInterpreter::ARMInstrTable[icode] + || instrs[i].Info.Kind == ARMInstrInfo::ak_MOV_REG_LSL_IMM + || instrs[i].Info.Kind == ARMInstrInfo::ak_Nop); if (cpu->CheckCondition(instrs[i].Cond())) InterpretARM[instrs[i].Info.Kind](cpu); else diff --git a/src/ARMJIT_RegisterCache.h b/src/ARMJIT_RegisterCache.h index 2222bc2..b894657 100644 --- a/src/ARMJIT_RegisterCache.h +++ b/src/ARMJIT_RegisterCache.h @@ -152,7 +152,7 @@ public: needValueLoaded = BitSet16(instr.Info.SrcRegs); for (int reg : needToBeLoaded) LoadRegister(reg, needValueLoaded[reg]); - } + } { BitSet16 loadedSet(LoadedRegs); BitSet16 loadRegs(instr.Info.NotStrictlyNeeded & futureNeeded & ~LoadedRegs); diff --git a/src/ARMJIT_x64/ARMJIT_Branch.cpp b/src/ARMJIT_x64/ARMJIT_Branch.cpp index 0dedb3f..e02865d 100644 --- a/src/ARMJIT_x64/ARMJIT_Branch.cpp +++ b/src/ARMJIT_x64/ARMJIT_Branch.cpp @@ -134,7 +134,7 @@ void Compiler::Comp_JumpTo(Gen::X64Reg addr, bool restoreCPSR) { IrregularCycles = true; - BitSet16 hiRegsLoaded(RegCache.DirtyRegs & 0xFF00); + BitSet16 hiRegsLoaded(RegCache.LoadedRegs & 0x7F00); bool previouslyDirty = CPSRDirty; SaveCPSR(); @@ -156,12 +156,12 @@ void Compiler::Comp_JumpTo(Gen::X64Reg addr, bool restoreCPSR) if (!restoreCPSR) XOR(32, R(ABI_PARAM3), R(ABI_PARAM3)); else - MOV(32, R(ABI_PARAM3), Imm32(restoreCPSR)); + MOV(32, R(ABI_PARAM3), Imm32(true)); // what a waste if (Num == 0) CALL((void*)&ARMv5::JumpTo); else CALL((void*)&ARMv4::JumpTo); - + if (!Thumb && restoreCPSR && CurInstr.Cond() < 0xE) { for (int reg : hiRegsLoaded) diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index fd38724..5afe842 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -308,6 +308,7 @@ const Compiler::CompileFunc A_Comp[ARMInstrInfo::ak_Count] = F(A_Comp_BranchImm), F(A_Comp_BranchImm), F(A_Comp_BranchImm), F(A_Comp_BranchXchangeReg), F(A_Comp_BranchXchangeReg), // system stuff NULL, NULL, NULL, NULL, NULL, NULL, NULL, + F(Nop) }; const Compiler::CompileFunc T_Comp[ARMInstrInfo::tk_Count] = { diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index 792ff66..2cb57dc 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -79,6 +79,8 @@ public: opInvertOp2 = 1 << 5, }; + void Nop() {} + void A_Comp_Arith(); void A_Comp_MovOp(); void A_Comp_CmpOp(); diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index b66f304..4cafc1c 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -531,7 +531,7 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc { if (regs[reg]) { - if (usermode && reg >= 8 && reg < 15) + if (usermode && !regs[15] && reg >= 8 && reg < 15) { if (firstUserMode) { @@ -545,7 +545,8 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc FixupBranch sucessfulWritten = J_CC(CC_NC); if (RegCache.Mapping[reg] != INVALID_REG) MOV(32, R(RegCache.Mapping[reg]), R(ABI_PARAM3)); - SaveReg(reg, ABI_PARAM3); + else + SaveReg(reg, ABI_PARAM3); SetJumpTarget(sucessfulWritten); } else if (RegCache.Mapping[reg] == INVALID_REG) diff --git a/src/ARM_InstrInfo.cpp b/src/ARM_InstrInfo.cpp index 8f8bd35..08e2f0a 100644 --- a/src/ARM_InstrInfo.cpp +++ b/src/ARM_InstrInfo.cpp @@ -392,6 +392,8 @@ Info Decode(bool thumb, u32 num, u32 instr) u32 data = ARMInstrTable[((instr >> 4) & 0xF) | ((instr >> 16) & 0xFF0)]; if (num == 0 && (instr & 0xFE000000) == 0xFA000000) data = A_BLX_IMM; + else if ((instr >> 28) == 0xF) + data = ak(ak_Nop); if (data & A_UnkOnARM7 && num != 0) data = A_UNK; diff --git a/src/ARM_InstrInfo.h b/src/ARM_InstrInfo.h index 2732181..6ab4929 100644 --- a/src/ARM_InstrInfo.h +++ b/src/ARM_InstrInfo.h @@ -139,6 +139,8 @@ enum ak_MRC, ak_SVC, + ak_Nop, + ak_Count, tk_LSL_IMM = 0, -- cgit v1.2.3 From baed0ac0d59d3cbbce01389a84da9774f5613b3b Mon Sep 17 00:00:00 2001 From: RSDuck Date: Tue, 4 Feb 2020 17:38:04 +0100 Subject: remove debug leftovers --- src/ARM.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/ARM.cpp b/src/ARM.cpp index fc0b898..896bb5c 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -768,8 +768,6 @@ void ARMv4::ExecuteJIT() return; } - //printf("executing armv4 at %08x\n", instrAddr); - ARMJIT::JitBlockEntry block = ARMJIT::LookUpBlock<1>(instrAddr); if (block) Cycles += block(); -- cgit v1.2.3 From 99b34efe2d923c4fd6fbfdb051833d2af6ea2136 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Tue, 4 Feb 2020 18:29:52 +0100 Subject: move ARM64 JIT backend here --- CMakeLists.txt | 2 +- src/ARM.h | 9 +- src/ARMJIT.cpp | 4 + src/ARMJIT_A64/ARMJIT_ALU.cpp | 837 +++++++ src/ARMJIT_A64/ARMJIT_Branch.cpp | 452 ++++ src/ARMJIT_A64/ARMJIT_Compiler.cpp | 707 ++++++ src/ARMJIT_A64/ARMJIT_Compiler.h | 234 ++ src/ARMJIT_A64/ARMJIT_LoadStore.cpp | 848 +++++++ src/ARM_InstrInfo.cpp | 7 +- src/CMakeLists.txt | 27 +- src/dolphin/Align.h | 24 + src/dolphin/Arm64Emitter.cpp | 4466 +++++++++++++++++++++++++++++++++++ src/dolphin/Arm64Emitter.h | 1152 +++++++++ src/dolphin/ArmCommon.h | 27 + src/dolphin/BitUtils.h | 254 ++ src/dolphin/Compat.h | 12 + src/dolphin/MathUtil.cpp | 13 + src/dolphin/MathUtil.h | 121 + 18 files changed, 9188 insertions(+), 8 deletions(-) create mode 100644 src/ARMJIT_A64/ARMJIT_ALU.cpp create mode 100644 src/ARMJIT_A64/ARMJIT_Branch.cpp create mode 100644 src/ARMJIT_A64/ARMJIT_Compiler.cpp create mode 100644 src/ARMJIT_A64/ARMJIT_Compiler.h create mode 100644 src/ARMJIT_A64/ARMJIT_LoadStore.cpp create mode 100644 src/dolphin/Align.h create mode 100644 src/dolphin/Arm64Emitter.cpp create mode 100644 src/dolphin/Arm64Emitter.h create mode 100644 src/dolphin/ArmCommon.h create mode 100644 src/dolphin/BitUtils.h create mode 100644 src/dolphin/MathUtil.cpp create mode 100644 src/dolphin/MathUtil.h (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e53c60..6729e73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,7 @@ detect_architecture("__i386__" x86) detect_architecture("__arm__" ARM) detect_architecture("__aarch64__" ARM64) -if (ARCHITECTURE STREQUAL x86_64) +if (ARCHITECTURE STREQUAL x86_64 OR ARCHITECTURE STREQUAL ARM64) option(ENABLE_JIT "Enable x64 JIT recompiler" ON) endif() diff --git a/src/ARM.h b/src/ARM.h index 96dd857..7ef1938 100644 --- a/src/ARM.h +++ b/src/ARM.h @@ -254,10 +254,14 @@ public: u32 DTCMSetting, ITCMSetting; - u8 ITCM[0x8000]; + // for aarch64 JIT they need to go up here + // to be addressable by a 12-bit immediate u32 ITCMSize; - u8 DTCM[0x4000]; u32 DTCMBase, DTCMSize; + s32 RegionCodeCycles; + + u8 ITCM[0x8000]; + u8 DTCM[0x4000]; u8 ICache[0x2000]; u32 ICacheTags[64*4]; @@ -282,7 +286,6 @@ public: // code/16N/32N/32S u8 MemTimings[0x100000][4]; - s32 RegionCodeCycles; u8* CurICacheLine; bool (*GetMemRegion)(u32 addr, bool write, NDS::MemRegion* region); diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 8fd7708..561fabb 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -6,7 +6,11 @@ #include "Config.h" #include "ARMJIT_Internal.h" +#if defined(__x86_64__) #include "ARMJIT_x64/ARMJIT_Compiler.h" +#else +#include "ARMJIT_A64/ARMJIT_Compiler.h" +#endif #include "ARMInterpreter_ALU.h" #include "ARMInterpreter_LoadStore.h" diff --git a/src/ARMJIT_A64/ARMJIT_ALU.cpp b/src/ARMJIT_A64/ARMJIT_ALU.cpp new file mode 100644 index 0000000..0fe6a97 --- /dev/null +++ b/src/ARMJIT_A64/ARMJIT_ALU.cpp @@ -0,0 +1,837 @@ +#include "ARMJIT_Compiler.h" + +using namespace Arm64Gen; + +namespace ARMJIT +{ + +void Compiler::Comp_RegShiftReg(int op, bool S, Op2& op2, ARM64Reg rs) +{ + if (!(CurInstr.SetFlags & 0x2)) + S = false; + + CPSRDirty |= S; + + UBFX(W1, rs, 0, 8); + + if (!S) + { + if (op == 3) + RORV(W0, op2.Reg.Rm, W1); + else + { + CMP(W1, 32); + if (op == 2) + { + MOVI2R(W2, 31); + CSEL(W1, W2, W1, CC_GE); + ASRV(W0, op2.Reg.Rm, W1); + } + else + { + if (op == 0) + LSLV(W0, op2.Reg.Rm, W1); + else if (op == 1) + LSRV(W0, op2.Reg.Rm, W1); + CSEL(W0, WZR, W0, CC_GE); + } + } + } + else + { + MOV(W0, op2.Reg.Rm); + FixupBranch zero = CBZ(W1); + + SUB(W1, W1, 1); + if (op == 3) + { + RORV(W0, op2.Reg.Rm, W1); + BFI(RCPSR, W0, 29, 1); + } + else + { + CMP(W1, 31); + if (op == 2) + { + MOVI2R(W2, 31); + CSEL(W1, W2, W1, CC_GT); + ASRV(W0, op2.Reg.Rm, W1); + BFI(RCPSR, W0, 29, 1); + } + else + { + if (op == 0) + { + LSLV(W0, op2.Reg.Rm, W1); + UBFX(W1, W0, 31, 1); + } + else if (op == 1) + LSRV(W0, op2.Reg.Rm, W1); + CSEL(W1, WZR, op ? W0 : W1, CC_GT); + BFI(RCPSR, W1, 29, 1); + CSEL(W0, WZR, W0, CC_GE); + } + } + + MOV(W0, W0, ArithOption(W0, (ShiftType)op, 1)); + SetJumpTarget(zero); + } + op2 = Op2(W0, ST_LSL, 0); +} + +void Compiler::Comp_RegShiftImm(int op, int amount, bool S, Op2& op2, ARM64Reg tmp) +{ + if (!(CurInstr.SetFlags & 0x2)) + S = false; + + CPSRDirty |= S; + + switch (op) + { + case 0: // LSL + if (S && amount) + { + UBFX(tmp, op2.Reg.Rm, 32 - amount, 1); + BFI(RCPSR, tmp, 29, 1); + } + op2 = Op2(op2.Reg.Rm, ST_LSL, amount); + return; + case 1: // LSR + if (S) + { + UBFX(tmp, op2.Reg.Rm, (amount ? amount : 32) - 1, 1); + BFI(RCPSR, tmp, 29, 1); + } + if (amount == 0) + { + op2 = Op2(0); + return; + } + op2 = Op2(op2.Reg.Rm, ST_LSR, amount); + return; + case 2: // ASR + if (S) + { + UBFX(tmp, op2.Reg.Rm, (amount ? amount : 32) - 1, 1); + BFI(RCPSR, tmp, 29, 1); + } + op2 = Op2(op2.Reg.Rm, ST_ASR, amount ? amount : 31); + return; + case 3: // ROR + if (amount == 0) + { + UBFX(tmp, RCPSR, 29, 1); + LSL(tmp, tmp, 31); + if (S) + BFI(RCPSR, op2.Reg.Rm, 29, 1); + ORR(tmp, tmp, op2.Reg.Rm, ArithOption(tmp, ST_LSR, 1)); + + op2 = Op2(tmp, ST_LSL, 0); + } + else + { + if (S) + { + UBFX(tmp, op2.Reg.Rm, amount - 1, 1); + BFI(RCPSR, tmp, 29, 1); + } + op2 = Op2(op2.Reg.Rm, ST_ROR, amount); + } + return; + } +} + +void Compiler::Comp_RetriveFlags(bool retriveCV) +{ + if (CurInstr.SetFlags) + CPSRDirty = true; + + if (CurInstr.SetFlags & 0x4) + { + CSET(W0, CC_EQ); + BFI(RCPSR, W0, 30, 1); + } + if (CurInstr.SetFlags & 0x8) + { + CSET(W0, CC_MI); + BFI(RCPSR, W0, 31, 1); + } + if (retriveCV) + { + if (CurInstr.SetFlags & 0x2) + { + CSET(W0, CC_CS); + BFI(RCPSR, W0, 29, 1); + } + if (CurInstr.SetFlags & 0x1) + { + CSET(W0, CC_VS); + BFI(RCPSR, W0, 28, 1); + } + } +} + +void Compiler::Comp_Logical(int op, bool S, ARM64Reg rd, ARM64Reg rn, Op2 op2) +{ + if (S && !CurInstr.SetFlags) + S = false; + + switch (op) + { + case 0x0: // AND + if (S) + { + if (op2.IsImm) + ANDSI2R(rd, rn, op2.Imm, W0); + else + ANDS(rd, rn, op2.Reg.Rm, op2.ToArithOption()); + } + else + { + if (op2.IsImm) + ANDI2R(rd, rn, op2.Imm, W0); + else + AND(rd, rn, op2.Reg.Rm, op2.ToArithOption()); + } + break; + case 0x1: // EOR + if (op2.IsImm) + EORI2R(rd, rn, op2.Imm, W0); + else + EOR(rd, rn, op2.Reg.Rm, op2.ToArithOption()); + if (S && FlagsNZNeeded()) + TST(rd, rd); + break; + case 0xC: // ORR + if (op2.IsImm) + ORRI2R(rd, rn, op2.Imm, W0); + else + ORR(rd, rn, op2.Reg.Rm, op2.ToArithOption()); + if (S && FlagsNZNeeded()) + TST(rd, rd); + break; + case 0xE: // BIC + if (S) + { + if (op2.IsImm) + ANDSI2R(rd, rn, ~op2.Imm, W0); + else + BICS(rd, rn, op2.Reg.Rm, op2.ToArithOption()); + } + else + { + if (op2.IsImm) + ANDI2R(rd, rn, ~op2.Imm, W0); + else + BIC(rd, rn, op2.Reg.Rm, op2.ToArithOption()); + } + break; + } + + if (S) + Comp_RetriveFlags(false); +} + +void Compiler::Comp_Arithmetic(int op, bool S, ARM64Reg rd, ARM64Reg rn, Op2 op2) +{ + if (!op2.IsImm && op2.Reg.ShiftType == ST_ROR) + { + MOV(W0, op2.Reg.Rm, op2.ToArithOption()); + op2 = Op2(W0, ST_LSL, 0); + } + + if (S && !CurInstr.SetFlags) + S = false; + + bool CVInGP = false; + switch (op) + { + case 0x2: // SUB + if (S) + { + if (op2.IsImm) + SUBSI2R(rd, rn, op2.Imm, W0); + else + SUBS(rd, rn, op2.Reg.Rm, op2.ToArithOption()); + } + else + { + if (op2.IsImm) + { + MOVI2R(W2, op2.Imm); + SUBI2R(rd, rn, op2.Imm, W0); + } + else + SUB(rd, rn, op2.Reg.Rm, op2.ToArithOption()); + } + break; + case 0x3: // RSB + if (op2.IsZero()) + { + op2 = Op2(WZR); + } + else if (op2.IsImm) + { + MOVI2R(W1, op2.Imm); + op2 = Op2(W1); + } + else if (op2.Reg.ShiftAmount != 0) + { + MOV(W1, op2.Reg.Rm, op2.ToArithOption()); + op2 = Op2(W1); + } + + if (S) + SUBS(rd, op2.Reg.Rm, rn); + else + SUB(rd, op2.Reg.Rm, rn); + break; + case 0x4: // ADD + if (S) + { + if (op2.IsImm) + ADDSI2R(rd, rn, op2.Imm, W0); + else + ADDS(rd, rn, op2.Reg.Rm, op2.ToArithOption()); + } + else + { + if (op2.IsImm) + ADDI2R(rd, rn, op2.Imm, W0); + else + ADD(rd, rn, op2.Reg.Rm, op2.ToArithOption()); + } + break; + case 0x5: // ADC + UBFX(W2, RCPSR, 29, 1); + if (S) + { + CVInGP = true; + ADDS(W1, rn, W2); + CSET(W2, CC_CS); + CSET(W3, CC_VS); + if (op2.IsImm) + ADDSI2R(rd, W1, op2.Imm, W0); + else + ADDS(rd, W1, op2.Reg.Rm, op2.ToArithOption()); + CSINC(W2, W2, WZR, CC_CC); + CSINC(W3, W3, WZR, CC_VC); + } + else + { + ADD(W1, rn, W2); + if (op2.IsImm) + ADDI2R(rd, W1, op2.Imm, W0); + else + ADD(rd, W1, op2.Reg.Rm, op2.ToArithOption()); + } + break; + case 0x6: // SBC + UBFX(W2, RCPSR, 29, 1); + // W1 = -op2 - 1 + if (op2.IsImm) + MOVI2R(W1, ~op2.Imm); + else + ORN(W1, WZR, op2.Reg.Rm, op2.ToArithOption()); + if (S) + { + CVInGP = true; + ADDS(W1, W2, W1); + CSET(W2, CC_CS); + CSET(W3, CC_VS); + ADDS(rd, rn, W1); + CSINC(W2, W2, WZR, CC_CC); + CSINC(W3, W3, WZR, CC_VC); + } + else + { + ADD(W1, W2, W1); + ADD(rd, rn, W1); + } + break; + case 0x7: // RSC + UBFX(W2, RCPSR, 29, 1); + // W1 = -rn - 1 + MVN(W1, rn); + if (S) + { + CVInGP = true; + ADDS(W1, W2, W1); + CSET(W2, CC_CS); + CSET(W3, CC_VS); + if (op2.IsImm) + ADDSI2R(rd, W1, op2.Imm); + else + ADDS(rd, W1, op2.Reg.Rm, op2.ToArithOption()); + CSINC(W2, W2, WZR, CC_CC); + CSINC(W3, W3, WZR, CC_VC); + } + else + { + ADD(W1, W2, W1); + if (op2.IsImm) + ADDI2R(rd, W1, op2.Imm); + else + ADD(rd, W1, op2.Reg.Rm, op2.ToArithOption()); + } + break; + } + + if (S) + { + if (CVInGP) + { + BFI(RCPSR, W2, 29, 1); + BFI(RCPSR, W3, 28, 1); + } + Comp_RetriveFlags(!CVInGP); + } +} + +void Compiler::Comp_Compare(int op, ARM64Reg rn, Op2 op2) +{ + if (!op2.IsImm && op2.Reg.ShiftType == ST_ROR) + { + MOV(W0, op2.Reg.Rm, op2.ToArithOption()); + op2 = Op2(W0, ST_LSL, 0); + } + + switch (op) + { + case 0x8: // TST + if (op2.IsImm) + TSTI2R(rn, op2.Imm, W0); + else + ANDS(WZR, rn, op2.Reg.Rm, op2.ToArithOption()); + break; + case 0x9: // TEQ + if (op2.IsImm) + EORI2R(W0, rn, op2.Imm, W0); + else + EOR(W0, rn, op2.Reg.Rm, op2.ToArithOption()); + TST(W0, W0); + break; + case 0xA: // CMP + if (op2.IsImm) + CMPI2R(rn, op2.Imm, W0); + else + CMP(rn, op2.Reg.Rm, op2.ToArithOption()); + break; + case 0xB: // CMN + if (op2.IsImm) + ADDSI2R(WZR, rn, op2.Imm, W0); + else + CMN(rn, op2.Reg.Rm, op2.ToArithOption()); + break; + } + + Comp_RetriveFlags(op >= 0xA); +} + +// also counts cycles! +void Compiler::A_Comp_GetOp2(bool S, Op2& op2) +{ + if (CurInstr.Instr & (1 << 25)) + { + Comp_AddCycles_C(); + op2 = Op2(ROR(CurInstr.Instr & 0xFF, (CurInstr.Instr >> 7) & 0x1E)); + } + else + { + int op = (CurInstr.Instr >> 5) & 0x3; + op2.Reg.Rm = MapReg(CurInstr.A_Reg(0)); + if (CurInstr.Instr & (1 << 4)) + { + Comp_AddCycles_CI(1); + + ARM64Reg rs = MapReg(CurInstr.A_Reg(8)); + if (CurInstr.A_Reg(0) == 15) + { + ADD(W0, op2.Reg.Rm, 4); + op2.Reg.Rm = W0; + } + Comp_RegShiftReg(op, S, op2, rs); + } + else + { + Comp_AddCycles_C(); + + int amount = (CurInstr.Instr >> 7) & 0x1F; + Comp_RegShiftImm(op, amount, S, op2); + } + } +} + +void Compiler::A_Comp_ALUCmpOp() +{ + u32 op = (CurInstr.Instr >> 21) & 0xF; + ARM64Reg rn = MapReg(CurInstr.A_Reg(16)); + Op2 op2; + A_Comp_GetOp2(op <= 0x9, op2); + + Comp_Compare(op, rn, op2); +} + +void Compiler::A_Comp_ALUMovOp() +{ + bool S = CurInstr.Instr & (1 << 20); + u32 op = (CurInstr.Instr >> 21) & 0xF; + + ARM64Reg rd = MapReg(CurInstr.A_Reg(12)); + Op2 op2; + A_Comp_GetOp2(S, op2); + + if (op == 0xF) // MVN + { + if (op2.IsImm) + { + if (CurInstr.Cond() == 0xE) + RegCache.PutLiteral(CurInstr.A_Reg(12), ~op2.Imm); + MOVI2R(rd, ~op2.Imm); + } + else + ORN(rd, WZR, op2.Reg.Rm, op2.ToArithOption()); + } + else // MOV + { + if (op2.IsImm) + { + if (CurInstr.Cond() == 0xE) + RegCache.PutLiteral(CurInstr.A_Reg(12), op2.Imm); + MOVI2R(rd, op2.Imm); + } + else + MOV(rd, op2.Reg.Rm, op2.ToArithOption()); + } + + if (S) + { + if (FlagsNZNeeded()) + TST(rd, rd); + Comp_RetriveFlags(false); + } + + if (CurInstr.Info.Branches()) + Comp_JumpTo(rd, true, S); +} + +void Compiler::A_Comp_ALUTriOp() +{ + bool S = CurInstr.Instr & (1 << 20); + u32 op = (CurInstr.Instr >> 21) & 0xF; + bool logical = (1 << op) & 0xF303; + + ARM64Reg rd = MapReg(CurInstr.A_Reg(12)); + ARM64Reg rn = MapReg(CurInstr.A_Reg(16)); + Op2 op2; + A_Comp_GetOp2(S && logical, op2); + + if (op2.IsImm && op2.Imm == 0) + op2 = Op2(WZR, ST_LSL, 0); + + if (logical) + Comp_Logical(op, S, rd, rn, op2); + else + Comp_Arithmetic(op, S, rd, rn, op2); + + if (CurInstr.Info.Branches()) + Comp_JumpTo(rd, true, S); +} + +void Compiler::A_Comp_Clz() +{ + Comp_AddCycles_C(); + + ARM64Reg rd = MapReg(CurInstr.A_Reg(12)); + ARM64Reg rm = MapReg(CurInstr.A_Reg(0)); + + CLZ(rd, rm); + + assert(Num == 0); +} + +void Compiler::Comp_Mul_Mla(bool S, bool mla, ARM64Reg rd, ARM64Reg rm, ARM64Reg rs, ARM64Reg rn) +{ + if (Num == 0) + { + Comp_AddCycles_CI(S ? 3 : 1); + } + else + { + CLZ(W0, rs); + CLS(W1, rs); + CMP(W0, W1); + CSEL(W0, W0, W1, CC_GT); + Comp_AddCycles_CI(mla ? 1 : 0, W0, ArithOption(W0, ST_LSR, 3)); + } + + if (mla) + MADD(rd, rm, rs, rn); + else + MUL(rd, rm, rs); + + if (S && FlagsNZNeeded()) + { + TST(rd, rd); + Comp_RetriveFlags(false); + } +} + +void Compiler::A_Comp_Mul_Long() +{ + ARM64Reg rd = MapReg(CurInstr.A_Reg(16)); + ARM64Reg rm = MapReg(CurInstr.A_Reg(0)); + ARM64Reg rs = MapReg(CurInstr.A_Reg(8)); + ARM64Reg rn = MapReg(CurInstr.A_Reg(12)); + + bool S = CurInstr.Instr & (1 << 20); + bool add = CurInstr.Instr & (1 << 21); + bool sign = CurInstr.Instr & (1 << 22); + + if (Num == 0) + { + Comp_AddCycles_CI(S ? 3 : 1); + } + else + { + CLZ(W0, rs); + CLS(W1, rs); + CMP(W0, W1); + CSEL(W0, W0, W1, CC_GT); + Comp_AddCycles_CI(0, W0, ArithOption(W0, ST_LSR, 3)); + } + + if (add) + { + MOV(W0, rn); + BFI(X0, EncodeRegTo64(rd), 32, 32); + if (sign) + SMADDL(EncodeRegTo64(rn), rm, rs, X0); + else + UMADDL(EncodeRegTo64(rn), rm, rs, X0); + if (S && FlagsNZNeeded()) + TST(EncodeRegTo64(rn), EncodeRegTo64(rn)); + UBFX(EncodeRegTo64(rd), EncodeRegTo64(rn), 32, 32); + } + else + { + if (sign) + SMULL(EncodeRegTo64(rn), rm, rs); + else + UMULL(EncodeRegTo64(rn), rm, rs); + if (S && FlagsNZNeeded()) + TST(EncodeRegTo64(rn), EncodeRegTo64(rn)); + UBFX(EncodeRegTo64(rd), EncodeRegTo64(rn), 32, 32); + } + + if (S) + Comp_RetriveFlags(false); +} + +void Compiler::A_Comp_Mul() +{ + ARM64Reg rd = MapReg(CurInstr.A_Reg(16)); + ARM64Reg rm = MapReg(CurInstr.A_Reg(0)); + ARM64Reg rs = MapReg(CurInstr.A_Reg(8)); + + bool S = CurInstr.Instr & (1 << 20); + bool mla = CurInstr.Instr & (1 << 21); + ARM64Reg rn = INVALID_REG; + if (mla) + rn = MapReg(CurInstr.A_Reg(12)); + + Comp_Mul_Mla(S, mla, rd, rm, rs, rn); +} + +void Compiler::T_Comp_ShiftImm() +{ + Comp_AddCycles_C(); + + u32 op = (CurInstr.Instr >> 11) & 0x3; + int amount = (CurInstr.Instr >> 6) & 0x1F; + + ARM64Reg rd = MapReg(CurInstr.T_Reg(0)); + Op2 op2; + op2.Reg.Rm = MapReg(CurInstr.T_Reg(3)); + Comp_RegShiftImm(op, amount, true, op2); + if (op2.IsImm) + MOVI2R(rd, op2.Imm); + else + MOV(rd, op2.Reg.Rm, op2.ToArithOption()); + if (FlagsNZNeeded()) + TST(rd, rd); + + Comp_RetriveFlags(false); +} + +void Compiler::T_Comp_AddSub_() +{ + Comp_AddCycles_C(); + + Op2 op2; + if (CurInstr.Instr & (1 << 10)) + op2 = Op2((CurInstr.Instr >> 6) & 0x7); + else + op2 = Op2(MapReg(CurInstr.T_Reg(6))); + + Comp_Arithmetic( + CurInstr.Instr & (1 << 9) ? 0x2 : 0x4, + true, + MapReg(CurInstr.T_Reg(0)), + MapReg(CurInstr.T_Reg(3)), + op2); +} + +void Compiler::T_Comp_ALUImm8() +{ + Comp_AddCycles_C(); + + u32 imm = CurInstr.Instr & 0xFF; + int op = (CurInstr.Instr >> 11) & 0x3; + + ARM64Reg rd = MapReg(CurInstr.T_Reg(8)); + + switch (op) + { + case 0: + MOVI2R(rd, imm); + if (FlagsNZNeeded()) + TST(rd, rd); + Comp_RetriveFlags(false); + break; + case 1: + Comp_Compare(0xA, rd, Op2(imm)); + break; + case 2: + case 3: + Comp_Arithmetic(op == 2 ? 0x4 : 0x2, true, rd, rd, Op2(imm)); + break; + } +} + +void Compiler::T_Comp_ALU() +{ + int op = (CurInstr.Instr >> 6) & 0xF; + ARM64Reg rd = MapReg(CurInstr.T_Reg(0)); + ARM64Reg rs = MapReg(CurInstr.T_Reg(3)); + + if ((op >= 0x2 && op <= 0x4) || op == 0x7) + Comp_AddCycles_CI(1); + else + Comp_AddCycles_C(); + + switch (op) + { + case 0x0: + Comp_Logical(0x0, true, rd, rd, Op2(rs)); + break; + case 0x1: + Comp_Logical(0x1, true, rd, rd, Op2(rs)); + break; + case 0x2: + case 0x3: + case 0x4: + case 0x7: + { + Op2 op2; + op2.Reg.Rm = rd; + Comp_RegShiftReg(op == 0x7 ? 3 : (op - 0x2), true, op2, rs); + MOV(rd, op2.Reg.Rm, op2.ToArithOption()); + if (FlagsNZNeeded()) + TST(rd, rd); + Comp_RetriveFlags(false); + } + break; + case 0x5: + Comp_Arithmetic(0x5, true, rd, rd, Op2(rs)); + break; + case 0x6: + Comp_Arithmetic(0x6, true, rd, rd, Op2(rs)); + break; + case 0x8: + Comp_Compare(0x8, rd, Op2(rs)); + break; + case 0x9: + Comp_Arithmetic(0x3, true, rd, rs, Op2(0)); + break; + case 0xA: + Comp_Compare(0xA, rd, Op2(rs)); + break; + case 0xB: + Comp_Compare(0xB, rd, Op2(rs)); + break; + case 0xC: + Comp_Logical(0xC, true, rd, rd, Op2(rs)); + break; + case 0xD: + Comp_Mul_Mla(true, false, rd, rd, rs, INVALID_REG); + break; + case 0xE: + Comp_Logical(0xE, true, rd, rd, Op2(rs)); + break; + case 0xF: + MVN(rd, rs); + if (FlagsNZNeeded()) + TST(rd, rd); + Comp_RetriveFlags(false); + break; + } +} + +void Compiler::T_Comp_ALU_HiReg() +{ + u32 rd = ((CurInstr.Instr & 0x7) | ((CurInstr.Instr >> 4) & 0x8)); + ARM64Reg rdMapped = MapReg(rd); + ARM64Reg rs = MapReg((CurInstr.Instr >> 3) & 0xF); + + u32 op = (CurInstr.Instr >> 8) & 0x3; + + Comp_AddCycles_C(); + + switch (op) + { + case 0: + Comp_Arithmetic(0x4, false, rdMapped, rdMapped, Op2(rs)); + break; + case 1: + Comp_Compare(0xA, rdMapped, rs); + return; + case 2: + MOV(rdMapped, rs); + break; + } + + if (rd == 15) + { + Comp_JumpTo(rdMapped, false, false); + } +} + +void Compiler::T_Comp_AddSP() +{ + Comp_AddCycles_C(); + + ARM64Reg sp = MapReg(13); + u32 offset = (CurInstr.Instr & 0x7F) << 2; + if (CurInstr.Instr & (1 << 7)) + SUB(sp, sp, offset); + else + ADD(sp, sp, offset); +} + +void Compiler::T_Comp_RelAddr() +{ + Comp_AddCycles_C(); + + ARM64Reg rd = MapReg(CurInstr.T_Reg(8)); + u32 offset = (CurInstr.Instr & 0xFF) << 2; + if (CurInstr.Instr & (1 << 11)) + { + ARM64Reg sp = MapReg(13); + ADD(rd, sp, offset); + } + else + MOVI2R(rd, (R15 & ~2) + offset); +} + +} \ No newline at end of file diff --git a/src/ARMJIT_A64/ARMJIT_Branch.cpp b/src/ARMJIT_A64/ARMJIT_Branch.cpp new file mode 100644 index 0000000..542f0b7 --- /dev/null +++ b/src/ARMJIT_A64/ARMJIT_Branch.cpp @@ -0,0 +1,452 @@ +#include "ARMJIT_Compiler.h" + +using namespace Arm64Gen; + +// hack +const int kCodeCacheTiming = 3; + +namespace ARMJIT +{ + +template +void jumpToTrampoline(T* cpu, u32 addr, bool changeCPSR) +{ + cpu->JumpTo(addr, changeCPSR); +} + +void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) +{ + // we can simplify constant branches by a lot + // it's not completely safe to assume stuff like, which instructions to preload + // we'll see how it works out + + IrregularCycles = true; + + u32 newPC; + u32 cycles = 0; + bool setupRegion = false; + + if (addr & 0x1 && !Thumb) + { + CPSRDirty = true; + ORRI2R(RCPSR, RCPSR, 0x20); + } + else if (!(addr & 0x1) && Thumb) + { + CPSRDirty = true; + ANDI2R(RCPSR, RCPSR, ~0x20); + } + + if (Num == 0) + { + ARMv5* cpu9 = (ARMv5*)CurCPU; + + u32 oldregion = R15 >> 24; + u32 newregion = addr >> 24; + + u32 regionCodeCycles = cpu9->MemTimings[addr >> 12][0]; + u32 compileTimeCodeCycles = cpu9->RegionCodeCycles; + cpu9->RegionCodeCycles = regionCodeCycles; + + MOVI2R(W0, regionCodeCycles); + STR(INDEX_UNSIGNED, W0, RCPU, offsetof(ARMv5, RegionCodeCycles)); + + setupRegion = newregion != oldregion; + if (setupRegion) + cpu9->SetupCodeMem(addr); + + if (addr & 0x1) + { + addr &= ~0x1; + newPC = addr+2; + + // two-opcodes-at-once fetch + // doesn't matter if we put garbage in the MSbs there + if (addr & 0x2) + { + cpu9->CodeRead32(addr-2, true) >> 16; + cycles += cpu9->CodeCycles; + cpu9->CodeRead32(addr+2, false); + cycles += CurCPU->CodeCycles; + } + else + { + cpu9->CodeRead32(addr, true); + cycles += cpu9->CodeCycles; + } + } + else + { + addr &= ~0x3; + newPC = addr+4; + + cpu9->CodeRead32(addr, true); + cycles += cpu9->CodeCycles; + cpu9->CodeRead32(addr+4, false); + cycles += cpu9->CodeCycles; + } + + cpu9->RegionCodeCycles = compileTimeCodeCycles; + if (setupRegion) + cpu9->SetupCodeMem(R15); + } + else + { + ARMv4* cpu7 = (ARMv4*)CurCPU; + + u32 codeRegion = addr >> 24; + u32 codeCycles = addr >> 15; // cheato + + cpu7->CodeRegion = codeRegion; + cpu7->CodeCycles = codeCycles; + + MOVI2R(W0, codeRegion); + STR(INDEX_UNSIGNED, W0, RCPU, offsetof(ARM, CodeRegion)); + MOVI2R(W0, codeCycles); + STR(INDEX_UNSIGNED, W0, RCPU, offsetof(ARM, CodeCycles)); + + if (addr & 0x1) + { + addr &= ~0x1; + newPC = addr+2; + + // this is necessary because ARM7 bios protection + u32 compileTimePC = CurCPU->R[15]; + CurCPU->R[15] = newPC; + + cycles += NDS::ARM7MemTimings[codeCycles][0] + NDS::ARM7MemTimings[codeCycles][1]; + + CurCPU->R[15] = compileTimePC; + } + else + { + addr &= ~0x3; + newPC = addr+4; + + u32 compileTimePC = CurCPU->R[15]; + CurCPU->R[15] = newPC; + + cycles += NDS::ARM7MemTimings[codeCycles][2] + NDS::ARM7MemTimings[codeCycles][3]; + + CurCPU->R[15] = compileTimePC; + } + + cpu7->CodeRegion = R15 >> 24; + cpu7->CodeCycles = addr >> 15; + } + + if (Exit) + { + MOVI2R(W0, newPC); + STR(INDEX_UNSIGNED, W0, RCPU, offsetof(ARM, R[15])); + } + if ((Thumb || CurInstr.Cond() >= 0xE) && !forceNonConstantCycles) + ConstantCycles += cycles; + else + ADD(RCycles, RCycles, cycles); +} + + +void* Compiler::Gen_JumpTo9(int kind) +{ + AlignCode16(); + void* res = GetRXPtr(); + + MOVI2R(W2, kCodeCacheTiming); + // W1 - code cycles non branch + // W2 - branch code cycles + LSR(W1, W0, 12); + LSL(W1, W1, 2); + ADDI2R(W1, W1, offsetof(ARMv5, MemTimings), W2); + LDRB(W1, RCPU, W1); + + LDR(INDEX_UNSIGNED, W3, RCPU, offsetof(ARMv5, ITCMSize)); + + STR(INDEX_UNSIGNED, W1, RCPU, offsetof(ARMv5, RegionCodeCycles)); + + CMP(W0, W3); + FixupBranch outsideITCM = B(CC_LO); + MOVI2R(W1, 1); + MOVI2R(W2, 1); + SetJumpTarget(outsideITCM); + + FixupBranch switchToThumb; + if (kind == 0) + switchToThumb = TBNZ(W0, 0); + + if (kind == 0 || kind == 1) + { + ANDI2R(W0, W0, ~3); + + if (kind == 0) + ANDI2R(RCPSR, RCPSR, ~0x20); + + ADD(W3, W0, 4); + STR(INDEX_UNSIGNED, W3, RCPU, offsetof(ARM, R[15])); + + ADD(W1, W1, W2); + ADD(RCycles, RCycles, W1); + + RET(); + } + if (kind == 0 || kind == 2) + { + if (kind == 0) + { + SetJumpTarget(switchToThumb); + + ORRI2R(RCPSR, RCPSR, 0x20); + } + + ANDI2R(W0, W0, ~1); + + ADD(W3, W0, 2); + STR(INDEX_UNSIGNED, W3, RCPU, offsetof(ARM, R[15])); + + FixupBranch halfwordLoc = TBZ(W0, 1); + ADD(W1, W1, W2); + ADD(RCycles, RCycles, W1); + RET(); + + SetJumpTarget(halfwordLoc); + ADD(RCycles, RCycles, W2); + RET(); + } + + return res; +} + +void* Compiler::Gen_JumpTo7(int kind) +{ + void* res = GetRXPtr(); + + LSR(W1, W0, 24); + STR(INDEX_UNSIGNED, W1, RCPU, offsetof(ARM, CodeRegion)); + LSR(W1, W0, 15); + STR(INDEX_UNSIGNED, W1, RCPU, offsetof(ARM, CodeCycles)); + + MOVP2R(X2, NDS::ARM7MemTimings); + LDR(W3, X2, ArithOption(W1, true)); + + FixupBranch switchToThumb; + if (kind == 0) + switchToThumb = TBNZ(W0, 0); + + if (kind == 0 || kind == 1) + { + UBFX(W2, W3, 0, 8); + UBFX(W3, W3, 8, 8); + ADD(W2, W3, W2); + ADD(RCycles, RCycles, W2); + + ANDI2R(W0, W0, ~3); + + if (kind == 0) + ANDI2R(RCPSR, RCPSR, ~0x20); + + ADD(W3, W0, 4); + STR(INDEX_UNSIGNED, W3, RCPU, offsetof(ARM, R[15])); + + RET(); + } + if (kind == 0 || kind == 2) + { + if (kind == 0) + { + SetJumpTarget(switchToThumb); + + ORRI2R(RCPSR, RCPSR, 0x20); + } + + UBFX(W2, W3, 16, 8); + UBFX(W3, W3, 24, 8); + ADD(W2, W3, W2); + ADD(RCycles, RCycles, W2); + + ANDI2R(W0, W0, ~1); + + ADD(W3, W0, 2); + STR(INDEX_UNSIGNED, W3, RCPU, offsetof(ARM, R[15])); + + RET(); + } + + return res; +} + +void Compiler::Comp_JumpTo(Arm64Gen::ARM64Reg addr, bool switchThumb, bool restoreCPSR) +{ + IrregularCycles = true; + + if (!restoreCPSR) + { + if (switchThumb) + CPSRDirty = true; + MOV(W0, addr); + BL((Num ? JumpToFuncs7 : JumpToFuncs9)[switchThumb ? 0 : (Thumb + 1)]); + } + else + { + BitSet16 hiRegsLoaded(RegCache.DirtyRegs & 0xFF00); + bool previouslyDirty = CPSRDirty; + SaveCPSR(); + + if (restoreCPSR) + { + if (Thumb || CurInstr.Cond() >= 0xE) + RegCache.Flush(); + else + { + // the ugly way... + // we only save them, to load and save them again + for (int reg : hiRegsLoaded) + SaveReg(reg, RegCache.Mapping[reg]); + } + } + + if (switchThumb) + MOV(W1, addr); + else + { + if (Thumb) + ORRI2R(W1, addr, 1); + else + ANDI2R(W1, addr, ~1); + } + MOV(X0, RCPU); + MOVI2R(W2, restoreCPSR); + if (Num == 0) + QuickCallFunction(X3, jumpToTrampoline); + else + QuickCallFunction(X3, jumpToTrampoline); + + if (!Thumb && restoreCPSR && CurInstr.Cond() < 0xE) + { + for (int reg : hiRegsLoaded) + LoadReg(reg, RegCache.Mapping[reg]); + } + + if (previouslyDirty) + LoadCPSR(); + CPSRDirty = previouslyDirty; + } +} + +void Compiler::A_Comp_BranchImm() +{ + int op = (CurInstr.Instr >> 24) & 1; + s32 offset = (s32)(CurInstr.Instr << 8) >> 6; + u32 target = R15 + offset; + bool link = op; + + if (CurInstr.Cond() == 0xF) // BLX_imm + { + target += (op << 1) + 1; + link = true; + } + + if (link) + MOVI2R(MapReg(14), R15 - 4); + + Comp_JumpTo(target); +} + +void Compiler::A_Comp_BranchXchangeReg() +{ + ARM64Reg rn = MapReg(CurInstr.A_Reg(0)); + MOV(W0, rn); + if ((CurInstr.Instr & 0xF0) == 0x30) // BLX_reg + MOVI2R(MapReg(14), R15 - 4); + Comp_JumpTo(W0, true); +} + +void Compiler::T_Comp_BCOND() +{ + u32 cond = (CurInstr.Instr >> 8) & 0xF; + FixupBranch skipExecute = CheckCondition(cond); + + s32 offset = (s32)(CurInstr.Instr << 24) >> 23; + Comp_JumpTo(R15 + offset + 1, true); + + Comp_BranchSpecialBehaviour(); + + FixupBranch skipFailed = B(); + SetJumpTarget(skipExecute); + Comp_AddCycles_C(true); + + if (CurInstr.BranchFlags & branch_FollowCondTaken) + { + SaveCPSR(false); + RegCache.PrepareExit(); + + ADD(W0, RCycles, ConstantCycles); + ABI_PopRegisters(SavedRegs); + RET(); + } + + SetJumpTarget(skipFailed); +} + +void Compiler::T_Comp_B() +{ + s32 offset = (s32)((CurInstr.Instr & 0x7FF) << 21) >> 20; + Comp_JumpTo(R15 + offset + 1); +} + +void Compiler::T_Comp_BranchXchangeReg() +{ + bool link = CurInstr.Instr & (1 << 7); + + if (link) + { + if (Num == 1) + { + printf("BLX unsupported on ARM7!!!\n"); + return; + } + MOV(W0, MapReg(CurInstr.A_Reg(3))); + MOVI2R(MapReg(14), R15 - 1); + Comp_JumpTo(W0, true); + } + else + { + ARM64Reg rn = MapReg(CurInstr.A_Reg(3)); + Comp_JumpTo(rn, true); + } +} + +void Compiler::T_Comp_BL_LONG_1() +{ + s32 offset = (s32)((CurInstr.Instr & 0x7FF) << 21) >> 9; + MOVI2R(MapReg(14), R15 + offset); + Comp_AddCycles_C(); +} + +void Compiler::T_Comp_BL_LONG_2() +{ + ARM64Reg lr = MapReg(14); + s32 offset = (CurInstr.Instr & 0x7FF) << 1; + ADD(W0, lr, offset); + MOVI2R(lr, (R15 - 2) | 1); + Comp_JumpTo(W0, Num == 0 && !(CurInstr.Instr & (1 << 12))); +} + +void Compiler::T_Comp_BL_Merged() +{ + Comp_AddCycles_C(); + + R15 += 2; + + u32 upperPart = CurInstr.Instr >> 16; + u32 target = (R15 - 2) + ((s32)((CurInstr.Instr & 0x7FF) << 21) >> 9); + target += (upperPart & 0x7FF) << 1; + + if (Num == 1 || upperPart & (1 << 12)) + target |= 1; + + MOVI2R(MapReg(14), (R15 - 2) | 1); + + Comp_JumpTo(target); +} + +} \ No newline at end of file diff --git a/src/ARMJIT_A64/ARMJIT_Compiler.cpp b/src/ARMJIT_A64/ARMJIT_Compiler.cpp new file mode 100644 index 0000000..89d0029 --- /dev/null +++ b/src/ARMJIT_A64/ARMJIT_Compiler.cpp @@ -0,0 +1,707 @@ +#include "ARMJIT_Compiler.h" + +#include "../ARMInterpreter.h" + +#include "../ARMJIT_Internal.h" + +#ifdef __SWITCH__ +#include "../switch/compat_switch.h" + +extern char __start__; +#endif + +#include + +using namespace Arm64Gen; + + +namespace ARMJIT +{ + +/* + + Recompiling classic ARM to ARMv8 code is at the same time + easier and trickier than compiling to a less related architecture + like x64. At one hand you can translate a lot of instructions directly. + But at the same time, there are a ton of exceptions, like for + example ADD and SUB can't have a RORed second operand on ARMv8. + */ + +template <> +const ARM64Reg RegisterCache::NativeRegAllocOrder[] = + {W19, W20, W21, W22, W23, W24, W25, W26}; +template <> +const int RegisterCache::NativeRegsAvailable = 8; + +const int JitMemSize = 16 * 1024 * 1024; + +void Compiler::MovePC() +{ + ADD(MapReg(15), MapReg(15), Thumb ? 2 : 4); +} + +Compiler::Compiler() +{ +#ifdef __SWITCH__ + JitRWBase = memalign(0x1000, JitMemSize); + + JitRXStart = (u8*)&__start__ - JitMemSize - 0x1000; + JitRWStart = virtmemReserve(JitMemSize); + MemoryInfo info = {0}; + u32 pageInfo = {0}; + int i = 0; + while (JitRXStart != NULL) + { + svcQueryMemory(&info, &pageInfo, (u64)JitRXStart); + if (info.type != MemType_Unmapped) + JitRXStart = (void*)((u8*)info.addr - JitMemSize - 0x1000); + else + break; + if (i++ > 8) + { + printf("couldn't find unmapped place for jit memory\n"); + JitRXStart = NULL; + } + } + + assert(JitRXStart != NULL); + + bool succeded = R_SUCCEEDED(svcMapProcessCodeMemory(envGetOwnProcessHandle(), (u64)JitRXStart, (u64)JitRWBase, JitMemSize)); + assert(succeded); + succeded = R_SUCCEEDED(svcSetProcessMemoryPermission(envGetOwnProcessHandle(), (u64)JitRXStart, JitMemSize, Perm_Rx)); + assert(succeded); + succeded = R_SUCCEEDED(svcMapProcessMemory(JitRWStart, envGetOwnProcessHandle(), (u64)JitRXStart, JitMemSize)); + assert(succeded); + + SetCodeBase((u8*)JitRWStart, (u8*)JitRXStart); + JitMemUseableSize = JitMemSize; + Reset(); +#endif + + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 2; j++) + { + MemFunc9[i][j] = Gen_MemoryRoutine9(8 << i, j); + } + } + MemFunc7[0][0] = (void*)NDS::ARM7Read8; + MemFunc7[1][0] = (void*)NDS::ARM7Read16; + MemFunc7[2][0] = (void*)NDS::ARM7Read32; + MemFunc7[0][1] = (void*)NDS::ARM7Write8; + MemFunc7[1][1] = (void*)NDS::ARM7Write16; + MemFunc7[2][1] = (void*)NDS::ARM7Write32; + + for (int i = 0; i < 2; i++) + { + for (int j = 0; j < 2; j++) + { + MemFuncsSeq9[i][j] = Gen_MemoryRoutine9Seq(i, j); + MemFuncsSeq7[i][j] = Gen_MemoryRoutine7Seq(i, j); + } + } + + for (int i = 0; i < 3; i++) + { + JumpToFuncs9[i] = Gen_JumpTo9(i); + JumpToFuncs7[i] = Gen_JumpTo7(i); + } + + /* + W0 - mode + W1 - reg num + W3 - in/out value of reg + */ + { + ReadBanked = GetRXPtr(); + + ADD(X2, RCPU, X1, ArithOption(X1, ST_LSL, 2)); + CMP(W0, 0x11); + FixupBranch fiq = B(CC_EQ); + SUBS(W1, W1, 13 - 8); + ADD(X2, RCPU, X1, ArithOption(X1, ST_LSL, 2)); + FixupBranch notEverything = B(CC_LT); + CMP(W0, 0x12); + FixupBranch irq = B(CC_EQ); + CMP(W0, 0x13); + FixupBranch svc = B(CC_EQ); + CMP(W0, 0x17); + FixupBranch abt = B(CC_EQ); + CMP(W0, 0x1B); + FixupBranch und = B(CC_EQ); + SetJumpTarget(notEverything); + RET(); + + SetJumpTarget(fiq); + LDR(INDEX_UNSIGNED, W3, X2, offsetof(ARM, R_FIQ)); + RET(); + SetJumpTarget(irq); + LDR(INDEX_UNSIGNED, W3, X2, offsetof(ARM, R_IRQ)); + RET(); + SetJumpTarget(svc); + LDR(INDEX_UNSIGNED, W3, X2, offsetof(ARM, R_SVC)); + RET(); + SetJumpTarget(abt); + LDR(INDEX_UNSIGNED, W3, X2, offsetof(ARM, R_ABT)); + RET(); + SetJumpTarget(und); + LDR(INDEX_UNSIGNED, W3, X2, offsetof(ARM, R_UND)); + RET(); + } + { + WriteBanked = GetRXPtr(); + + ADD(X2, RCPU, X1, ArithOption(X1, ST_LSL, 2)); + CMP(W0, 0x11); + FixupBranch fiq = B(CC_EQ); + SUBS(W1, W1, 13 - 8); + ADD(X2, RCPU, X1, ArithOption(X1, ST_LSL, 2)); + FixupBranch notEverything = B(CC_LT); + CMP(W0, 0x12); + FixupBranch irq = B(CC_EQ); + CMP(W0, 0x13); + FixupBranch svc = B(CC_EQ); + CMP(W0, 0x17); + FixupBranch abt = B(CC_EQ); + CMP(W0, 0x1B); + FixupBranch und = B(CC_EQ); + SetJumpTarget(notEverything); + MOVI2R(W4, 0); + RET(); + + SetJumpTarget(fiq); + STR(INDEX_UNSIGNED, W3, X2, offsetof(ARM, R_FIQ)); + MOVI2R(W4, 1); + RET(); + SetJumpTarget(irq); + STR(INDEX_UNSIGNED, W3, X2, offsetof(ARM, R_IRQ)); + MOVI2R(W4, 1); + RET(); + SetJumpTarget(svc); + STR(INDEX_UNSIGNED, W3, X2, offsetof(ARM, R_SVC)); + MOVI2R(W4, 1); + RET(); + SetJumpTarget(abt); + STR(INDEX_UNSIGNED, W3, X2, offsetof(ARM, R_ABT)); + MOVI2R(W4, 1); + RET(); + SetJumpTarget(und); + STR(INDEX_UNSIGNED, W3, X2, offsetof(ARM, R_UND)); + MOVI2R(W4, 1); + RET(); + } + + //FlushIcache(); + + JitMemUseableSize -= GetCodeOffset(); + SetCodeBase((u8*)GetRWPtr(), (u8*)GetRXPtr()); +} + +Compiler::~Compiler() +{ +#ifdef __SWITCH__ + if (JitRWStart != NULL) + { + bool succeded = R_SUCCEEDED(svcUnmapProcessMemory(JitRWStart, envGetOwnProcessHandle(), (u64)JitRXStart, JitMemSize)); + assert(succeded); + virtmemFree(JitRWStart, JitMemSize); + succeded = R_SUCCEEDED(svcUnmapProcessCodeMemory(envGetOwnProcessHandle(), (u64)JitRXStart, (u64)JitRWBase, JitMemSize)); + assert(succeded); + free(JitRWBase); + } +#endif +} + +void Compiler::LoadReg(int reg, ARM64Reg nativeReg) +{ + if (reg == 15) + MOVI2R(nativeReg, R15); + else + LDR(INDEX_UNSIGNED, nativeReg, RCPU, offsetof(ARM, R[reg])); +} + +void Compiler::SaveReg(int reg, ARM64Reg nativeReg) +{ + STR(INDEX_UNSIGNED, nativeReg, RCPU, offsetof(ARM, R[reg])); +} + +void Compiler::LoadCPSR() +{ + assert(!CPSRDirty); + LDR(INDEX_UNSIGNED, RCPSR, RCPU, offsetof(ARM, CPSR)); +} + +void Compiler::SaveCPSR(bool markClean) +{ + if (CPSRDirty) + { + STR(INDEX_UNSIGNED, RCPSR, RCPU, offsetof(ARM, CPSR)); + CPSRDirty = CPSRDirty && !markClean; + } +} + +FixupBranch Compiler::CheckCondition(u32 cond) +{ + if (cond >= 0x8) + { + LSR(W1, RCPSR, 28); + MOVI2R(W2, 1); + LSLV(W2, W2, W1); + ANDI2R(W2, W2, ARM::ConditionTable[cond], W3); + + return CBZ(W2); + } + else + { + u8 bit = (28 + ((~(cond >> 1) & 1) << 1 | (cond >> 2 & 1) ^ (cond >> 1 & 1))); + + if (cond & 1) + return TBNZ(RCPSR, bit); + else + return TBZ(RCPSR, bit); + } +} + +#define F(x) &Compiler::A_Comp_##x +const Compiler::CompileFunc A_Comp[ARMInstrInfo::ak_Count] = +{ + // AND + F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), + F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), + // EOR + F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), + F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), + // SUB + F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), + F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), + // RSB + F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), + F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), + // ADD + F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), + F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), + // ADC + F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), + F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), + // SBC + F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), + F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), + // RSC + F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), + F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), + // ORR + F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), + F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), + // MOV + F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), + F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), + // BIC + F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), + F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), F(ALUTriOp), + // MVN + F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), + F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), F(ALUMovOp), + // TST + F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), + // TEQ + F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), + // CMP + F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), + // CMN + F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), F(ALUCmpOp), + // Mul + F(Mul), F(Mul), F(Mul_Long), F(Mul_Long), F(Mul_Long), F(Mul_Long), NULL, NULL, NULL, NULL, NULL, + // ARMv5 exclusives + F(Clz), NULL, NULL, NULL, NULL, + + // STR + F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), + // STRB + F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), + // LDR + F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), + // LDRB + F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), F(MemWB), + // STRH + F(MemHD), F(MemHD), F(MemHD), F(MemHD), + // LDRD + NULL, NULL, NULL, NULL, + // STRD + NULL, NULL, NULL, NULL, + // LDRH + F(MemHD), F(MemHD), F(MemHD), F(MemHD), + // LDRSB + F(MemHD), F(MemHD), F(MemHD), F(MemHD), + // LDRSH + F(MemHD), F(MemHD), F(MemHD), F(MemHD), + // Swap + NULL, NULL, + // LDM, STM + F(LDM_STM), F(LDM_STM), + // Branch + F(BranchImm), F(BranchImm), F(BranchImm), F(BranchXchangeReg), F(BranchXchangeReg), + // Special + NULL, NULL, NULL, NULL, NULL, NULL, NULL +}; +#undef F +#define F(x) &Compiler::T_Comp_##x +const Compiler::CompileFunc T_Comp[ARMInstrInfo::tk_Count] = +{ + // Shift imm + F(ShiftImm), F(ShiftImm), F(ShiftImm), + // Add/sub tri operand + F(AddSub_), F(AddSub_), F(AddSub_), F(AddSub_), + // 8 bit imm + F(ALUImm8), F(ALUImm8), F(ALUImm8), F(ALUImm8), + // ALU + F(ALU), F(ALU), F(ALU), F(ALU), F(ALU), F(ALU), F(ALU), F(ALU), + F(ALU), F(ALU), F(ALU), F(ALU), F(ALU), F(ALU), F(ALU), F(ALU), + // ALU hi reg + F(ALU_HiReg), F(ALU_HiReg), F(ALU_HiReg), + // PC/SP relative ops + F(RelAddr), F(RelAddr), F(AddSP), + // LDR PC rel + F(LoadPCRel), + // LDR/STR reg offset + F(MemReg), F(MemReg), F(MemReg), F(MemReg), + // LDR/STR sign extended, half + F(MemRegHalf), F(MemRegHalf), F(MemRegHalf), F(MemRegHalf), + // LDR/STR imm offset + F(MemImm), F(MemImm), F(MemImm), F(MemImm), + // LDR/STR half imm offset + F(MemImmHalf), F(MemImmHalf), + // LDR/STR sp rel + F(MemSPRel), F(MemSPRel), + // PUSH/POP + F(PUSH_POP), F(PUSH_POP), + // LDMIA, STMIA + F(LDMIA_STMIA), F(LDMIA_STMIA), + // Branch + F(BCOND), F(BranchXchangeReg), F(BranchXchangeReg), F(B), F(BL_LONG_1), F(BL_LONG_2), + // Unk, SVC + NULL, NULL, + F(BL_Merged) +}; + +bool Compiler::CanCompile(bool thumb, u16 kind) +{ + return (thumb ? T_Comp[kind] : A_Comp[kind]) != NULL; +} + +void Compiler::Comp_BranchSpecialBehaviour() +{ + if (CurInstr.BranchFlags & branch_IdleBranch) + { + MOVI2R(W0, 1); + STRB(INDEX_UNSIGNED, W0, RCPU, offsetof(ARM, IdleLoop)); + } + + if (CurInstr.BranchFlags & branch_FollowCondNotTaken) + { + SaveCPSR(false); + RegCache.PrepareExit(); + ADD(W0, RCycles, ConstantCycles); + ABI_PopRegisters(SavedRegs); + RET(); + } +} + +JitBlockEntry Compiler::CompileBlock(ARM* cpu, bool thumb, FetchedInstr instrs[], int instrsCount) +{ + if (JitMemUseableSize - GetCodeOffset() < 1024 * 16) + { + printf("JIT memory full, resetting...\n"); + ResetBlockCache(); + } + + JitBlockEntry res = (JitBlockEntry)GetRXPtr(); + + Thumb = thumb; + Num = cpu->Num; + CurCPU = cpu; + ConstantCycles = 0; + RegCache = RegisterCache(this, instrs, instrsCount, true); + + //printf("compiling block at %x\n", R15 - (Thumb ? 2 : 4)); + const u32 ALL_CALLEE_SAVED = 0x7FF80000; + + SavedRegs = BitSet32((RegCache.GetPushRegs() | BitSet32(0x78000000)) & BitSet32(ALL_CALLEE_SAVED)); + + //if (Num == 1) + { + ABI_PushRegisters(SavedRegs); + + MOVP2R(RCPU, CurCPU); + MOVI2R(RCycles, 0); + + LoadCPSR(); + } + + for (int i = 0; i < instrsCount; i++) + { + CurInstr = instrs[i]; + R15 = CurInstr.Addr + (Thumb ? 4 : 8); + CodeRegion = R15 >> 24; + + CompileFunc comp = Thumb + ? T_Comp[CurInstr.Info.Kind] + : A_Comp[CurInstr.Info.Kind]; + + Exit = i == (instrsCount - 1) || (CurInstr.BranchFlags & branch_FollowCondNotTaken); + + //printf("%x instr %x regs: r%x w%x n%x flags: %x %x %x\n", R15, CurInstr.Instr, CurInstr.Info.SrcRegs, CurInstr.Info.DstRegs, CurInstr.Info.ReadFlags, CurInstr.Info.NotStrictlyNeeded, CurInstr.Info.WriteFlags, CurInstr.SetFlags); + + bool isConditional = Thumb ? CurInstr.Info.Kind == ARMInstrInfo::tk_BCOND : CurInstr.Cond() < 0xE; + if (comp == NULL || (CurInstr.BranchFlags & branch_FollowCondTaken) || (i == instrsCount - 1 && (!CurInstr.Info.Branches() || isConditional))) + { + MOVI2R(W0, R15); + STR(INDEX_UNSIGNED, W0, RCPU, offsetof(ARM, R[15])); + if (comp == NULL) + { + MOVI2R(W0, CurInstr.Instr); + STR(INDEX_UNSIGNED, W0, RCPU, offsetof(ARM, CurInstr)); + } + if (Num == 0) + { + MOVI2R(W0, (s32)CurInstr.CodeCycles); + STR(INDEX_UNSIGNED, W0, RCPU, offsetof(ARM, CodeCycles)); + } + } + + if (comp == NULL) + { + SaveCPSR(); + RegCache.Flush(); + } + else + RegCache.Prepare(Thumb, i); + + if (Thumb) + { + if (comp == NULL) + { + MOV(X0, RCPU); + QuickCallFunction(X1, InterpretTHUMB[CurInstr.Info.Kind]); + } + else + (this->*comp)(); + } + else + { + u32 cond = CurInstr.Cond(); + if (CurInstr.Info.Kind == ARMInstrInfo::ak_BLX_IMM) + { + if (comp) + (this->*comp)(); + else + { + MOV(X0, RCPU); + QuickCallFunction(X1, ARMInterpreter::A_BLX_IMM); + } + } + else if (cond == 0xF) + Comp_AddCycles_C(); + else + { + IrregularCycles = false; + + FixupBranch skipExecute; + if (cond < 0xE) + skipExecute = CheckCondition(cond); + + if (comp == NULL) + { + MOV(X0, RCPU); + QuickCallFunction(X1, InterpretARM[CurInstr.Info.Kind]); + } + else + { + (this->*comp)(); + } + + Comp_BranchSpecialBehaviour(); + + if (cond < 0xE) + { + if (IrregularCycles) + { + FixupBranch skipNop = B(); + SetJumpTarget(skipExecute); + + Comp_AddCycles_C(); + + if (CurInstr.BranchFlags & branch_FollowCondTaken) + { + SaveCPSR(false); + RegCache.PrepareExit(); + ADD(W0, RCycles, ConstantCycles); + ABI_PopRegisters(SavedRegs); + RET(); + } + + SetJumpTarget(skipNop); + } + else + SetJumpTarget(skipExecute); + } + + } + } + + if (comp == NULL) + LoadCPSR(); + } + + RegCache.Flush(); + + //if (Num == 1) + { + SaveCPSR(); + + ADD(W0, RCycles, ConstantCycles); + + ABI_PopRegisters(SavedRegs); + } + //else + // ADD(RCycles, RCycles, ConstantCycles); + + RET(); + + FlushIcache(); + + //printf("finished\n"); + + return res; +} + +void Compiler::Reset() +{ + SetCodePtr(0); + + const u32 brk_0 = 0xD4200000; + + for (int i = 0; i < JitMemUseableSize / 4; i++) + *(((u32*)GetRWPtr()) + i) = brk_0; +} + +void Compiler::Comp_AddCycles_C(bool nonConst) +{ + s32 cycles = Num ? + NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 1 : 3] + : ((R15 & 0x2) ? 0 : CurInstr.CodeCycles); + + if (!nonConst && !CurInstr.Info.Branches()) + ConstantCycles += cycles; + else + ADD(RCycles, RCycles, cycles); +} + +void Compiler::Comp_AddCycles_CI(u32 numI) +{ + s32 cycles = (Num ? + NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2] + : ((R15 & 0x2) ? 0 : CurInstr.CodeCycles)) + numI; + + if (Thumb || CurInstr.Cond() >= 0xE) + ConstantCycles += cycles; + else + ADD(RCycles, RCycles, cycles); +} + +void Compiler::Comp_AddCycles_CI(u32 c, ARM64Reg numI, ArithOption shift) +{ + s32 cycles = (Num ? + NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2] + : ((R15 & 0x2) ? 0 : CurInstr.CodeCycles)) + c; + + ADD(RCycles, RCycles, numI, shift); + if (Thumb || CurInstr.Cond() >= 0xE) + ConstantCycles += c; + else + ADD(RCycles, RCycles, cycles); +} + +void Compiler::Comp_AddCycles_CDI() +{ + if (Num == 0) + Comp_AddCycles_CD(); + else + { + IrregularCycles = true; + + s32 cycles; + + s32 numC = NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2]; + s32 numD = CurInstr.DataCycles; + + if (CurInstr.DataRegion == 0x02) // mainRAM + { + if (CodeRegion == 0x02) + cycles = numC + numD; + else + { + numC++; + cycles = std::max(numC + numD - 3, std::max(numC, numD)); + } + } + else if (CodeRegion == 0x02) + { + numD++; + cycles = std::max(numC + numD - 3, std::max(numC, numD)); + } + else + { + cycles = numC + numD + 1; + } + + if (!Thumb && CurInstr.Cond() < 0xE) + ADD(RCycles, RCycles, cycles); + else + ConstantCycles += cycles; + } +} + +void Compiler::Comp_AddCycles_CD() +{ + u32 cycles = 0; + if (Num == 0) + { + s32 numC = (R15 & 0x2) ? 0 : CurInstr.CodeCycles; + s32 numD = CurInstr.DataCycles; + + //if (DataRegion != CodeRegion) + cycles = std::max(numC + numD - 6, std::max(numC, numD)); + + IrregularCycles = cycles != numC; + } + else + { + s32 numC = NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2]; + s32 numD = CurInstr.DataCycles; + + if (CurInstr.DataRegion == 0x02) + { + if (CodeRegion == 0x02) + cycles += numC + numD; + else + cycles += std::max(numC + numD - 3, std::max(numC, numD)); + } + else if (CodeRegion == 0x02) + { + cycles += std::max(numC + numD - 3, std::max(numC, numD)); + } + else + { + cycles += numC + numD; + } + + IrregularCycles = true; + } + + if ((!Thumb && CurInstr.Cond() < 0xE) && IrregularCycles) + ADD(RCycles, RCycles, cycles); + else + ConstantCycles += cycles; +} + +} \ No newline at end of file diff --git a/src/ARMJIT_A64/ARMJIT_Compiler.h b/src/ARMJIT_A64/ARMJIT_Compiler.h new file mode 100644 index 0000000..7e13507 --- /dev/null +++ b/src/ARMJIT_A64/ARMJIT_Compiler.h @@ -0,0 +1,234 @@ +#ifndef ARMJIT_COMPILER_H +#define ARMJIT_COMPILER_H + +#include "../ARM.h" +#include "../ARMJIT.h" + +#include "../dolphin/Arm64Emitter.h" + +#include "../ARMJIT_Internal.h" +#include "../ARMJIT_RegisterCache.h" + +namespace ARMJIT +{ + +const Arm64Gen::ARM64Reg RCPSR = Arm64Gen::W27; +const Arm64Gen::ARM64Reg RCycles = Arm64Gen::W28; +const Arm64Gen::ARM64Reg RCPU = Arm64Gen::X29; + +struct Op2 +{ + Op2() + {} + + Op2(Arm64Gen::ARM64Reg rm) : IsImm(false) + { + Reg.Rm = rm; + Reg.ShiftType = Arm64Gen::ST_LSL; + Reg.ShiftAmount = 0; + } + + Op2(u32 imm) : IsImm(true), Imm(imm) + {} + + Op2(Arm64Gen::ARM64Reg rm, Arm64Gen::ShiftType st, int amount) : IsImm(false) + { + Reg.Rm = rm; + Reg.ShiftType = st; + Reg.ShiftAmount = amount; + } + + Arm64Gen::ArithOption ToArithOption() + { + assert(!IsImm); + return Arm64Gen::ArithOption(Reg.Rm, Reg.ShiftType, Reg.ShiftAmount); + } + + bool IsSimpleReg() + { return !IsImm && !Reg.ShiftAmount && Reg.ShiftType == Arm64Gen::ST_LSL; } + bool ImmFits12Bit() + { return IsImm && (Imm & 0xFFF == Imm); } + bool IsZero() + { return IsImm && !Imm; } + + bool IsImm; + union + { + struct + { + Arm64Gen::ARM64Reg Rm; + Arm64Gen::ShiftType ShiftType; + int ShiftAmount; + } Reg; + u32 Imm; + }; +}; + +class Compiler : Arm64Gen::ARM64XEmitter +{ +public: + typedef void (Compiler::*CompileFunc)(); + + Compiler(); + ~Compiler(); + + Arm64Gen::ARM64Reg MapReg(int reg) + { + assert(RegCache.Mapping[reg] != Arm64Gen::INVALID_REG); + return RegCache.Mapping[reg]; + } + + JitBlockEntry CompileBlock(ARM* cpu, bool thumb, FetchedInstr instrs[], int instrsCount); + + bool CanCompile(bool thumb, u16 kind); + + bool FlagsNZNeeded() + { + return CurInstr.SetFlags & 0xC; + } + + void Reset(); + + void Comp_AddCycles_C(bool forceNonConst = false); + void Comp_AddCycles_CI(u32 numI); + void Comp_AddCycles_CI(u32 c, Arm64Gen::ARM64Reg numI, Arm64Gen::ArithOption shift); + void Comp_AddCycles_CD(); + void Comp_AddCycles_CDI(); + + void MovePC(); + + void LoadReg(int reg, Arm64Gen::ARM64Reg nativeReg); + void SaveReg(int reg, Arm64Gen::ARM64Reg nativeReg); + + void LoadCPSR(); + void SaveCPSR(bool markClean = true); + + void A_Comp_ALUTriOp(); + void A_Comp_ALUMovOp(); + void A_Comp_ALUCmpOp(); + + void A_Comp_Mul(); + void A_Comp_Mul_Long(); + + void A_Comp_Clz(); + + void A_Comp_MemWB(); + void A_Comp_MemHD(); + + void A_Comp_LDM_STM(); + + void A_Comp_BranchImm(); + void A_Comp_BranchXchangeReg(); + + + void T_Comp_ShiftImm(); + void T_Comp_AddSub_(); + void T_Comp_ALUImm8(); + void T_Comp_ALU(); + void T_Comp_ALU_HiReg(); + void T_Comp_AddSP(); + void T_Comp_RelAddr(); + + void T_Comp_MemReg(); + void T_Comp_MemImm(); + void T_Comp_MemRegHalf(); + void T_Comp_MemImmHalf(); + void T_Comp_LoadPCRel(); + void T_Comp_MemSPRel(); + + void T_Comp_LDMIA_STMIA(); + void T_Comp_PUSH_POP(); + + void T_Comp_BCOND(); + void T_Comp_B(); + void T_Comp_BranchXchangeReg(); + void T_Comp_BL_LONG_1(); + void T_Comp_BL_LONG_2(); + void T_Comp_BL_Merged(); + + s32 Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc, bool decrement, bool usermode); + + void Comp_Mul_Mla(bool S, bool mla, Arm64Gen::ARM64Reg rd, Arm64Gen::ARM64Reg rm, Arm64Gen::ARM64Reg rs, Arm64Gen::ARM64Reg rn); + + void Comp_Compare(int op, Arm64Gen::ARM64Reg rn, Op2 op2); + void Comp_Logical(int op, bool S, Arm64Gen::ARM64Reg rd, Arm64Gen::ARM64Reg rn, Op2 op2); + void Comp_Arithmetic(int op, bool S, Arm64Gen::ARM64Reg rd, Arm64Gen::ARM64Reg rn, Op2 op2); + + void Comp_RetriveFlags(bool retriveCV); + + Arm64Gen::FixupBranch CheckCondition(u32 cond); + + void Comp_JumpTo(Arm64Gen::ARM64Reg addr, bool switchThumb, bool restoreCPSR = false); + void Comp_JumpTo(u32 addr, bool forceNonConstantCycles = false); + + void A_Comp_GetOp2(bool S, Op2& op2); + + void Comp_RegShiftImm(int op, int amount, bool S, Op2& op2, Arm64Gen::ARM64Reg tmp = Arm64Gen::W0); + void Comp_RegShiftReg(int op, bool S, Op2& op2, Arm64Gen::ARM64Reg rs); + + void Comp_MemLoadLiteral(int size, bool signExtend, int rd, u32 addr); + enum + { + memop_Writeback = 1 << 0, + memop_Post = 1 << 1, + memop_SignExtend = 1 << 2, + memop_Store = 1 << 3, + memop_SubtractOffset = 1 << 4 + }; + void Comp_MemAccess(int rd, int rn, Op2 offset, int size, int flags); + + void* Gen_MemoryRoutine9(int size, bool store); + + void* Gen_MemoryRoutine9Seq(bool store, bool preinc); + void* Gen_MemoryRoutine7Seq(bool store, bool preinc); + + // 0 = switch mode, 1 = stay arm, 2 = stay thumb + void* Gen_JumpTo9(int kind); + void* Gen_JumpTo7(int kind); + + void Comp_BranchSpecialBehaviour(); + + bool Exit; + + FetchedInstr CurInstr; + bool Thumb; + u32 R15; + u32 Num; + ARM* CurCPU; + u32 ConstantCycles; + u32 CodeRegion; + + BitSet32 SavedRegs; + + u32 JitMemUseableSize; + + void* ReadBanked, *WriteBanked; + + // [size][store] + void* MemFunc9[3][2]; + void* MemFunc7[3][2]; + + // [store][pre increment] + void* MemFuncsSeq9[2][2]; + // "[code in main ram] + void* MemFuncsSeq7[2][2]; + + void* JumpToFuncs9[3]; + void* JumpToFuncs7[3]; + + RegisterCache RegCache; + + bool CPSRDirty = false; + + bool IrregularCycles = false; + +#ifdef __SWITCH__ + void* JitRWBase; + void* JitRWStart; + void* JitRXStart; +#endif +}; + +} + +#endif \ No newline at end of file diff --git a/src/ARMJIT_A64/ARMJIT_LoadStore.cpp b/src/ARMJIT_A64/ARMJIT_LoadStore.cpp new file mode 100644 index 0000000..a5d0e3f --- /dev/null +++ b/src/ARMJIT_A64/ARMJIT_LoadStore.cpp @@ -0,0 +1,848 @@ +#include "ARMJIT_Compiler.h" + +#include "../Config.h" + +using namespace Arm64Gen; + +namespace ARMJIT +{ + +// W0 - address +// (if store) W1 - value to store +// W2 - code cycles +void* Compiler::Gen_MemoryRoutine9(int size, bool store) +{ + AlignCode16(); + void* res = GetRXPtr(); + + u32 addressMask; + switch (size) + { + case 32: addressMask = ~3; break; + case 16: addressMask = ~1; break; + case 8: addressMask = ~0; break; + } + + LDR(INDEX_UNSIGNED, W3, RCPU, offsetof(ARMv5, DTCMBase)); + LDR(INDEX_UNSIGNED, W4, RCPU, offsetof(ARMv5, DTCMSize)); + SUB(W3, W0, W3); + CMP(W3, W4); + FixupBranch insideDTCM = B(CC_LO); + + UBFX(W4, W0, 24, 8); + CMP(W4, 0x02); + FixupBranch outsideMainRAM = B(CC_NEQ); + ANDI2R(W3, W0, addressMask & (MAIN_RAM_SIZE - 1)); + MOVP2R(X4, NDS::MainRAM); + if (!store && size == 32) + { + LDR(W3, X3, X4); + ANDI2R(W0, W0, 3); + LSL(W0, W0, 3); + RORV(W0, W3, W0); + } + else if (store) + STRGeneric(size, W1, X3, X4); + else + LDRGeneric(size, false, W0, X3, X4); + RET(); + + SetJumpTarget(outsideMainRAM); + + LDR(INDEX_UNSIGNED, W3, RCPU, offsetof(ARMv5, ITCMSize)); + CMP(W0, W3); + FixupBranch insideITCM = B(CC_LO); + + if (store) + { + if (size > 8) + ANDI2R(W0, W0, addressMask); + + switch (size) + { + case 32: QuickTailCall(X4, NDS::ARM9Write32); break; + case 16: QuickTailCall(X4, NDS::ARM9Write16); break; + case 8: QuickTailCall(X4, NDS::ARM9Write8); break; + } + } + else + { + if (size == 32) + ABI_PushRegisters({0, 30}); + if (size > 8) + ANDI2R(W0, W0, addressMask); + + switch (size) + { + case 32: QuickCallFunction(X4, NDS::ARM9Read32); break; + case 16: QuickTailCall (X4, NDS::ARM9Read16); break; + case 8: QuickTailCall (X4, NDS::ARM9Read8 ); break; + } + if (size == 32) + { + ABI_PopRegisters({1, 30}); + ANDI2R(W1, W1, 3); + LSL(W1, W1, 3); + RORV(W0, W0, W1); + RET(); + } + } + + SetJumpTarget(insideDTCM); + ANDI2R(W3, W3, 0x3FFF & addressMask); + ADDI2R(W3, W3, offsetof(ARMv5, DTCM), W4); + if (!store && size == 32) + { + ANDI2R(W4, W0, 3); + LDR(W0, RCPU, W3); + LSL(W4, W4, 3); + RORV(W0, W0, W4); + } + else if (store) + STRGeneric(size, W1, RCPU, W3); + else + LDRGeneric(size, false, W0, RCPU, W3); + + RET(); + + SetJumpTarget(insideITCM); + ANDI2R(W3, W0, 0x7FFF & addressMask); + if (store) + { + LSR(W0, W3, 8); + ADDI2R(W0, W0, ExeMemRegionOffsets[exeMem_ITCM], W4); + MOVP2R(X4, CodeRanges); + ADD(X4, X4, X0, ArithOption(X0, ST_LSL, 4)); + static_assert(sizeof(AddressRange) == 16); + LDR(INDEX_UNSIGNED, W4, X4, offsetof(AddressRange, Blocks.Length)); + FixupBranch null = CBZ(W4); + ABI_PushRegisters({1, 3, 30}); + QuickCallFunction(X4, InvalidateByAddr); + ABI_PopRegisters({1, 3, 30}); + SetJumpTarget(null); + } + ADDI2R(W3, W3, offsetof(ARMv5, ITCM), W4); + if (!store && size == 32) + { + ANDI2R(W4, W0, 3); + LDR(W0, RCPU, W3); + LSL(W4, W4, 3); + RORV(W0, W0, W4); + } + else if (store) + STRGeneric(size, W1, RCPU, W3); + else + LDRGeneric(size, false, W0, RCPU, W3); + RET(); + + return res; +} + +/* + W0 - base address + X1 - stack space + W2 - values count +*/ +void* Compiler::Gen_MemoryRoutine9Seq(bool store, bool preinc) +{ + AlignCode16(); + void* res = GetRXPtr(); + + void* loopStart = GetRXPtr(); + SUB(W2, W2, 1); + + if (preinc) + ADD(W0, W0, 4); + + LDR(INDEX_UNSIGNED, W4, RCPU, offsetof(ARMv5, DTCMBase)); + LDR(INDEX_UNSIGNED, W5, RCPU, offsetof(ARMv5, DTCMSize)); + SUB(W4, W0, W4); + CMP(W4, W5); + FixupBranch insideDTCM = B(CC_LO); + + LDR(INDEX_UNSIGNED, W4, RCPU, offsetof(ARMv5, ITCMSize)); + CMP(W0, W4); + FixupBranch insideITCM = B(CC_LO); + + ABI_PushRegisters({0, 1, 2, 30}); // TODO: move SP only once + if (store) + { + LDR(X1, X1, ArithOption(X2, true)); + QuickCallFunction(X4, NDS::ARM9Write32); + + ABI_PopRegisters({0, 1, 2, 30}); + } + else + { + QuickCallFunction(X4, NDS::ARM9Read32); + MOV(W4, W0); + + ABI_PopRegisters({0, 1, 2, 30}); + + STR(X4, X1, ArithOption(X2, true)); + } + + if (!preinc) + ADD(W0, W0, 4); + CBNZ(W2, loopStart); + RET(); + + SetJumpTarget(insideDTCM); + + ANDI2R(W4, W4, ~3 & 0x3FFF); + ADDI2R(X4, X4, offsetof(ARMv5, DTCM)); + if (store) + { + LDR(X5, X1, ArithOption(X2, true)); + STR(W5, RCPU, X4); + } + else + { + LDR(W5, RCPU, X4); + STR(X5, X1, ArithOption(X2, true)); + } + + if (!preinc) + ADD(W0, W0, 4); + CBNZ(W2, loopStart); + RET(); + + SetJumpTarget(insideITCM); + + ANDI2R(W4, W0, ~3 & 0x7FFF); + + if (store) + { + LSR(W6, W4, 8); + ADDI2R(W6, W6, ExeMemRegionOffsets[exeMem_ITCM], W5); + MOVP2R(X5, CodeRanges); + ADD(X5, X5, X6, ArithOption(X6, ST_LSL, 4)); + static_assert(sizeof(AddressRange) == 16); + LDR(INDEX_UNSIGNED, W5, X5, offsetof(AddressRange, Blocks.Length)); + FixupBranch null = CBZ(W5); + ABI_PushRegisters({0, 1, 2, 4, 30}); + MOV(W0, W6); + QuickCallFunction(X5, InvalidateByAddr); + ABI_PopRegisters({0, 1, 2, 4, 30}); + SetJumpTarget(null); + } + + ADDI2R(W4, W4, offsetof(ARMv5, ITCM), W5); + if (store) + { + LDR(X5, X1, ArithOption(X2, true)); + STR(W5, RCPU, X4); + } + else + { + LDR(W5, RCPU, X4); + STR(X5, X1, ArithOption(X2, true)); + } + + if (!preinc) + ADD(W0, W0, 4); + CBNZ(W2, loopStart); + RET(); + return res; +} + +void* Compiler::Gen_MemoryRoutine7Seq(bool store, bool preinc) +{ + AlignCode16(); + void* res = GetRXPtr(); + + void* loopStart = GetRXPtr(); + SUB(W2, W2, 1); + + if (preinc) + ADD(W0, W0, 4); + + ABI_PushRegisters({0, 1, 2, 30}); + if (store) + { + LDR(X1, X1, ArithOption(X2, true)); + QuickCallFunction(X4, NDS::ARM7Write32); + ABI_PopRegisters({0, 1, 2, 30}); + } + else + { + QuickCallFunction(X4, NDS::ARM7Read32); + MOV(W4, W0); + ABI_PopRegisters({0, 1, 2, 30}); + STR(X4, X1, ArithOption(X2, true)); + } + + if (!preinc) + ADD(W0, W0, 4); + CBNZ(W2, loopStart); + RET(); + + return res; +} + +void Compiler::Comp_MemLoadLiteral(int size, bool signExtend, int rd, u32 addr) +{ + u32 val; + // make sure arm7 bios is accessible + u32 tmpR15 = CurCPU->R[15]; + CurCPU->R[15] = R15; + if (size == 32) + { + CurCPU->DataRead32(addr & ~0x3, &val); + val = ROR(val, (addr & 0x3) << 3); + } + else if (size == 16) + { + CurCPU->DataRead16(addr & ~0x1, &val); + if (signExtend) + val = ((s32)val << 16) >> 16; + } + else + { + CurCPU->DataRead8(addr, &val); + if (signExtend) + val = ((s32)val << 24) >> 24; + } + CurCPU->R[15] = tmpR15; + + MOVI2R(MapReg(rd), val); + + if (Thumb || CurInstr.Cond() == 0xE) + RegCache.PutLiteral(rd, val); +} + +void Compiler::Comp_MemAccess(int rd, int rn, Op2 offset, int size, int flags) +{ + u32 addressMask = ~0; + if (size == 32) + addressMask = ~3; + if (size == 16) + addressMask = ~1; + + if (flags & memop_Store) + Comp_AddCycles_CD(); + else + Comp_AddCycles_CDI(); + + if (Config::JIT_LiteralOptimisations && rn == 15 && rd != 15 && offset.IsImm && !(flags & (memop_Post|memop_Store|memop_Writeback))) + { + u32 addr = R15 + offset.Imm * ((flags & memop_SubtractOffset) ? -1 : 1); + u32 translatedAddr = Num == 0 ? TranslateAddr<0>(addr) : TranslateAddr<1>(addr); + + if (!(CodeRanges[translatedAddr / 512].InvalidLiterals & (1 << ((translatedAddr & 0x1FF) / 16)))) + { + Comp_MemLoadLiteral(size, flags & memop_SignExtend, rd, addr); + return; + } + } + + { + ARM64Reg rdMapped = MapReg(rd); + ARM64Reg rnMapped = MapReg(rn); + + bool inlinePreparation = Num == 1; + u32 constLocalROR32 = 4; + + void* memFunc = Num == 0 + ? MemFunc9[size >> 4][!!(flags & memop_Store)] + : MemFunc7[size >> 4][!!((flags & memop_Store))]; + + if (Config::JIT_LiteralOptimisations && (rd != 15 || (flags & memop_Store)) && offset.IsImm && RegCache.IsLiteral(rn)) + { + u32 addr = RegCache.LiteralValues[rn] + offset.Imm * ((flags & memop_SubtractOffset) ? -1 : 1); + + NDS::MemRegion region; + region.Mem = NULL; + if (Num == 0) + { + ARMv5* cpu5 = (ARMv5*)CurCPU; + + // stupid dtcm... + if (addr >= cpu5->DTCMBase && addr < (cpu5->DTCMBase + cpu5->DTCMSize)) + { + region.Mem = cpu5->DTCM; + region.Mask = 0x3FFF; + } + else + { + NDS::ARM9GetMemRegion(addr, flags & memop_Store, ®ion); + } + } + else + NDS::ARM7GetMemRegion(addr, flags & memop_Store, ®ion); + + if (region.Mem != NULL) + { + void* ptr = ®ion.Mem[addr & addressMask & region.Mask]; + + MOVP2R(X0, ptr); + if (flags & memop_Store) + STRGeneric(size, INDEX_UNSIGNED, rdMapped, X0, 0); + else + { + LDRGeneric(size, flags & memop_SignExtend, INDEX_UNSIGNED, rdMapped, X0, 0); + if (size == 32 && addr & ~0x3) + ROR_(rdMapped, rdMapped, (addr & 0x3) << 3); + } + return; + } + + void* specialFunc = GetFuncForAddr(CurCPU, addr, flags & memop_Store, size); + if (specialFunc) + { + memFunc = specialFunc; + inlinePreparation = true; + constLocalROR32 = addr & 0x3; + } + } + + ARM64Reg finalAddr = W0; + if (flags & memop_Post) + { + finalAddr = rnMapped; + MOV(W0, rnMapped); + } + + if (flags & memop_Store) + MOV(W1, rdMapped); + + if (!offset.IsImm) + Comp_RegShiftImm(offset.Reg.ShiftType, offset.Reg.ShiftAmount, false, offset, W2); + // offset might become an immediate + if (offset.IsImm) + { + if (flags & memop_SubtractOffset) + SUB(finalAddr, rnMapped, offset.Imm); + else + ADD(finalAddr, rnMapped, offset.Imm); + } + else + { + if (offset.Reg.ShiftType == ST_ROR) + { + ROR_(W0, offset.Reg.Rm, offset.Reg.ShiftAmount); + offset = Op2(W0); + } + + if (flags & memop_SubtractOffset) + SUB(finalAddr, rnMapped, offset.Reg.Rm, offset.ToArithOption()); + else + ADD(finalAddr, rnMapped, offset.Reg.Rm, offset.ToArithOption()); + } + + if (!(flags & memop_Post) && (flags & memop_Writeback)) + MOV(rnMapped, W0); + + if (inlinePreparation) + { + if (size == 32 && !(flags & memop_Store) && constLocalROR32 == 4) + ANDI2R(rdMapped, W0, 3); + if (size > 8) + ANDI2R(W0, W0, addressMask); + } + QuickCallFunction(X2, memFunc); + if (!(flags & memop_Store)) + { + if (inlinePreparation && !(flags & memop_Store) && size == 32) + { + if (constLocalROR32 == 4) + { + LSL(rdMapped, rdMapped, 3); + RORV(rdMapped, W0, rdMapped); + } + else if (constLocalROR32 > 0) + ROR_(rdMapped, W0, constLocalROR32 << 3); + else + MOV(rdMapped, W0); + } + else if (flags & memop_SignExtend) + { + if (size == 16) + SXTH(rdMapped, W0); + else if (size == 8) + SXTB(rdMapped, W0); + else + assert("What's wrong with you?"); + } + else + MOV(rdMapped, W0); + + if (CurInstr.Info.Branches()) + { + if (size < 32) + printf("LDR size < 32 branching?\n"); + Comp_JumpTo(rdMapped, Num == 0, false); + } + } + } +} + +void Compiler::A_Comp_MemWB() +{ + Op2 offset; + if (CurInstr.Instr & (1 << 25)) + offset = Op2(MapReg(CurInstr.A_Reg(0)), (ShiftType)((CurInstr.Instr >> 5) & 0x3), (CurInstr.Instr >> 7) & 0x1F); + else + offset = Op2(CurInstr.Instr & 0xFFF); + + bool load = CurInstr.Instr & (1 << 20); + bool byte = CurInstr.Instr & (1 << 22); + + int flags = 0; + if (!load) + flags |= memop_Store; + if (!(CurInstr.Instr & (1 << 24))) + flags |= memop_Post; + if (CurInstr.Instr & (1 << 21)) + flags |= memop_Writeback; + if (!(CurInstr.Instr & (1 << 23))) + flags |= memop_SubtractOffset; + + Comp_MemAccess(CurInstr.A_Reg(12), CurInstr.A_Reg(16), offset, byte ? 8 : 32, flags); +} + +void Compiler::A_Comp_MemHD() +{ + bool load = CurInstr.Instr & (1 << 20); + bool signExtend; + int op = (CurInstr.Instr >> 5) & 0x3; + int size; + + if (load) + { + signExtend = op >= 2; + size = op == 2 ? 8 : 16; + } + else + { + size = 16; + signExtend = false; + } + + Op2 offset; + if (CurInstr.Instr & (1 << 22)) + offset = Op2((CurInstr.Instr & 0xF) | ((CurInstr.Instr >> 4) & 0xF0)); + else + offset = Op2(MapReg(CurInstr.A_Reg(0))); + + int flags = 0; + if (signExtend) + flags |= memop_SignExtend; + if (!load) + flags |= memop_Store; + if (!(CurInstr.Instr & (1 << 24))) + flags |= memop_Post; + if (!(CurInstr.Instr & (1 << 23))) + flags |= memop_SubtractOffset; + if (CurInstr.Instr & (1 << 21)) + flags |= memop_Writeback; + + Comp_MemAccess(CurInstr.A_Reg(12), CurInstr.A_Reg(16), offset, size, flags); +} + +void Compiler::T_Comp_MemReg() +{ + int op = (CurInstr.Instr >> 10) & 0x3; + bool load = op & 0x2; + bool byte = op & 0x1; + + Comp_MemAccess(CurInstr.T_Reg(0), CurInstr.T_Reg(3), + Op2(MapReg(CurInstr.T_Reg(6))), byte ? 8 : 32, load ? 0 : memop_Store); +} + +void Compiler::T_Comp_MemImm() +{ + int op = (CurInstr.Instr >> 11) & 0x3; + bool load = op & 0x1; + bool byte = op & 0x2; + u32 offset = ((CurInstr.Instr >> 6) & 0x1F) * (byte ? 1 : 4); + + Comp_MemAccess(CurInstr.T_Reg(0), CurInstr.T_Reg(3), Op2(offset), + byte ? 8 : 32, load ? 0 : memop_Store); +} + +void Compiler::T_Comp_MemRegHalf() +{ + int op = (CurInstr.Instr >> 10) & 0x3; + bool load = op != 0; + int size = op != 1 ? 16 : 8; + bool signExtend = op & 1; + + int flags = 0; + if (signExtend) + flags |= memop_SignExtend; + if (!load) + flags |= memop_Store; + + Comp_MemAccess(CurInstr.T_Reg(0), CurInstr.T_Reg(3), Op2(MapReg(CurInstr.T_Reg(6))), + size, flags); +} + +void Compiler::T_Comp_MemImmHalf() +{ + u32 offset = (CurInstr.Instr >> 5) & 0x3E; + bool load = CurInstr.Instr & (1 << 11); + + Comp_MemAccess(CurInstr.T_Reg(0), CurInstr.T_Reg(3), Op2(offset), 16, + load ? 0 : memop_Store); +} + +void Compiler::T_Comp_LoadPCRel() +{ + u32 addr = (R15 & ~0x2) + ((CurInstr.Instr & 0xFF) << 2); + + if (Config::JIT_LiteralOptimisations) + { + Comp_MemLoadLiteral(32, false, CurInstr.T_Reg(8), addr); + Comp_AddCycles_CDI(); + } + else + { + bool negative = addr < R15; + u32 abs = negative ? R15 - addr : addr - R15; + Comp_MemAccess(CurInstr.T_Reg(8), 15, Op2(abs), 32, negative ? memop_SubtractOffset : 0); + } +} + +void Compiler::T_Comp_MemSPRel() +{ + u32 offset = (CurInstr.Instr & 0xFF) * 4; + bool load = CurInstr.Instr & (1 << 11); + + Comp_MemAccess(CurInstr.T_Reg(8), 13, Op2(offset), 32, load ? 0 : memop_Store); +} + +s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc, bool decrement, bool usermode) +{ + IrregularCycles = true; + + int regsCount = regs.Count(); + + if (regsCount == 0) + return 0; // actually not the right behaviour TODO: fix me + + SUB(SP, SP, ((regsCount + 1) & ~1) * 8); + if (store) + { + Comp_AddCycles_CD(); + + if (usermode && (regs & BitSet16(0x7f00))) + UBFX(W0, RCPSR, 0, 5); + + int i = regsCount - 1; + + BitSet16::Iterator it = regs.begin(); + while (it != regs.end()) + { + BitSet16::Iterator nextReg = it; + nextReg++; + + int reg = *it; + + if (usermode && reg >= 8 && reg < 15) + { + if (RegCache.Mapping[reg] != INVALID_REG) + MOV(W3, MapReg(reg)); + else + LoadReg(reg, W3); + MOVI2R(W1, reg - 8); + BL(ReadBanked); + STR(INDEX_UNSIGNED, W3, SP, i * 8); + } + else if (!usermode && nextReg != regs.end()) + { + ARM64Reg first = W3; + ARM64Reg second = W4; + + if (RegCache.Mapping[reg] != INVALID_REG) + first = MapReg(reg); + else + LoadReg(reg, W3); + + if (RegCache.Mapping[*nextReg] != INVALID_REG) + second = MapReg(*nextReg); + else + LoadReg(*nextReg, W4); + + STP(INDEX_SIGNED, EncodeRegTo64(second), EncodeRegTo64(first), SP, i * 8 - 8); + + i--; + it++; + } + else if (RegCache.Mapping[reg] != INVALID_REG) + STR(INDEX_UNSIGNED, MapReg(reg), SP, i * 8); + else + { + LoadReg(reg, W3); + STR(INDEX_UNSIGNED, W3, SP, i * 8); + } + i--; + it++; + } + } + if (decrement) + { + SUB(W0, MapReg(rn), regsCount * 4); + preinc ^= true; + } + else + MOV(W0, MapReg(rn)); + ADD(X1, SP, 0); + MOVI2R(W2, regsCount); + + BL(Num ? MemFuncsSeq7[store][preinc] : MemFuncsSeq9[store][preinc]); + + if (!store) + { + Comp_AddCycles_CDI(); + + if (usermode && (regs & BitSet16(0x7f00))) + UBFX(W0, RCPSR, 0, 5); + + int i = regsCount - 1; + BitSet16::Iterator it = regs.begin(); + while (it != regs.end()) + { + BitSet16::Iterator nextReg = it; + nextReg++; + + int reg = *it; + + if (usermode && reg >= 8 && reg < 15) + { + LDR(INDEX_UNSIGNED, W3, SP, i * 8); + MOVI2R(W1, reg - 8); + BL(WriteBanked); + FixupBranch alreadyWritten = CBNZ(W4); + if (RegCache.Mapping[reg] != INVALID_REG) + { + MOV(MapReg(reg), W3); + RegCache.DirtyRegs |= 1 << reg; + } + else + SaveReg(reg, W3); + SetJumpTarget(alreadyWritten); + } + else if (!usermode && nextReg != regs.end()) + { + ARM64Reg first = W3, second = W4; + + if (RegCache.Mapping[reg] != INVALID_REG) + { + first = MapReg(reg); + if (reg != 15) + RegCache.DirtyRegs |= 1 << reg; + } + if (RegCache.Mapping[*nextReg] != INVALID_REG) + { + second = MapReg(*nextReg); + if (*nextReg != 15) + RegCache.DirtyRegs |= 1 << *nextReg; + } + + LDP(INDEX_SIGNED, EncodeRegTo64(second), EncodeRegTo64(first), SP, i * 8 - 8); + + if (first == W3) + SaveReg(reg, W3); + if (second == W4) + SaveReg(*nextReg, W4); + + it++; + i--; + } + else if (RegCache.Mapping[reg] != INVALID_REG) + { + ARM64Reg mapped = MapReg(reg); + LDR(INDEX_UNSIGNED, mapped, SP, i * 8); + + if (reg != 15) + RegCache.DirtyRegs |= 1 << reg; + } + else + { + LDR(INDEX_UNSIGNED, W3, SP, i * 8); + SaveReg(reg, W3); + } + + it++; + i--; + } + } + ADD(SP, SP, ((regsCount + 1) & ~1) * 8); + + if (!store && regs[15]) + { + ARM64Reg mapped = MapReg(15); + Comp_JumpTo(mapped, Num == 0, usermode); + } + + return regsCount * 4 * (decrement ? -1 : 1); +} + +void Compiler::A_Comp_LDM_STM() +{ + BitSet16 regs(CurInstr.Instr & 0xFFFF); + + bool load = CurInstr.Instr & (1 << 20); + bool pre = CurInstr.Instr & (1 << 24); + bool add = CurInstr.Instr & (1 << 23); + bool writeback = CurInstr.Instr & (1 << 21); + bool usermode = CurInstr.Instr & (1 << 22); + + ARM64Reg rn = MapReg(CurInstr.A_Reg(16)); + + s32 offset = Comp_MemAccessBlock(CurInstr.A_Reg(16), regs, !load, pre, !add, usermode); + + if (load && writeback && regs[CurInstr.A_Reg(16)]) + writeback = Num == 0 + ? (!(regs & ~BitSet16(1 << CurInstr.A_Reg(16)))) || (regs & ~BitSet16((2 << CurInstr.A_Reg(16)) - 1)) + : false; + if (writeback) + { + if (offset > 0) + ADD(rn, rn, offset); + else + SUB(rn, rn, -offset); + } +} + +void Compiler::T_Comp_PUSH_POP() +{ + bool load = CurInstr.Instr & (1 << 11); + BitSet16 regs(CurInstr.Instr & 0xFF); + if (CurInstr.Instr & (1 << 8)) + { + if (load) + regs[15] = true; + else + regs[14] = true; + } + + ARM64Reg sp = MapReg(13); + s32 offset = Comp_MemAccessBlock(13, regs, !load, !load, !load, false); + + if (offset > 0) + ADD(sp, sp, offset); + else + SUB(sp, sp, -offset); +} + +void Compiler::T_Comp_LDMIA_STMIA() +{ + BitSet16 regs(CurInstr.Instr & 0xFF); + ARM64Reg rb = MapReg(CurInstr.T_Reg(8)); + bool load = CurInstr.Instr & (1 << 11); + u32 regsCount = regs.Count(); + + s32 offset = Comp_MemAccessBlock(CurInstr.T_Reg(8), regs, !load, false, false, false); + + if (!load || !regs[CurInstr.T_Reg(8)]) + { + if (offset > 0) + ADD(rb, rb, offset); + else + SUB(rb, rb, -offset); + } +} + +} \ No newline at end of file diff --git a/src/ARM_InstrInfo.cpp b/src/ARM_InstrInfo.cpp index 08e2f0a..b884773 100644 --- a/src/ARM_InstrInfo.cpp +++ b/src/ARM_InstrInfo.cpp @@ -2,6 +2,8 @@ #include +#include "Config.h" + namespace ARMInstrInfo { @@ -363,7 +365,11 @@ Info Decode(bool thumb, u32 num, u32 instr) res.SpecialKind = special_WriteMem; if (res.Kind == ARMInstrInfo::tk_LDR_PCREL) + { + if (!Config::JIT_LiteralOptimisations) + res.SrcRegs |= 1 << 15; res.SpecialKind = special_LoadLiteral; + } if (res.Kind == tk_LDMIA || res.Kind == tk_POP) { @@ -417,7 +423,6 @@ Info Decode(bool thumb, u32 num, u32 instr) u32 cp = ((instr >> 8) & 0xF); if ((num == 0 && cp != 15) || (num == 1 && cp != 14)) { - printf("happens\n"); data = A_UNK; res.Kind = ak_UNK; } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bfc0ad9..fce9e49 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -60,10 +60,31 @@ if (ENABLE_JIT) ARMJIT_x64/ARMJIT_Branch.cpp dolphin/CommonFuncs.cpp - dolphin/x64ABI.cpp - dolphin/x64CPUDetect.cpp - dolphin/x64Emitter.cpp ) + + if (ARCHITECTURE STREQUAL x86_64) + target_sources(core PRIVATE + dolphin/x64ABI.cpp + dolphin/x64CPUDetect.cpp + dolphin/x64Emitter.cpp + + ARMJIT_x64/ARMJIT_Compiler.cpp + ARMJIT_x64/ARMJIT_ALU.cpp + ARMJIT_x64/ARMJIT_LoadStore.cpp + ARMJIT_x64/ARMJIT_Branch.cpp + ) + endif() + if (ARCHITECTURE STREQUAL ARM64) + target_sources(core PRIVATE + dolphin/Arm64Emitter.cpp + dolphin/MathUtil.cpp + + ARMJIT_A64/ARMJIT_Compiler.cpp + ARMJIT_A64/ARMJIT_ALU.cpp + ARMJIT_A64/ARMJIT_LoadStore.cpp + ARMJIT_A64/ARMJIT_Branch.cpp + ) + endif() endif() if (WIN32) diff --git a/src/dolphin/Align.h b/src/dolphin/Align.h new file mode 100644 index 0000000..40c4576 --- /dev/null +++ b/src/dolphin/Align.h @@ -0,0 +1,24 @@ +// This file is under the public domain. + +#pragma once + +#include +#include + +namespace Common +{ +template +constexpr T AlignUp(T value, size_t size) +{ + static_assert(std::is_unsigned(), "T must be an unsigned value."); + return static_cast(value + (size - value % size) % size); +} + +template +constexpr T AlignDown(T value, size_t size) +{ + static_assert(std::is_unsigned(), "T must be an unsigned value."); + return static_cast(value - value % size); +} + +} // namespace Common diff --git a/src/dolphin/Arm64Emitter.cpp b/src/dolphin/Arm64Emitter.cpp new file mode 100644 index 0000000..dbcf425 --- /dev/null +++ b/src/dolphin/Arm64Emitter.cpp @@ -0,0 +1,4466 @@ +// Copyright 2015 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include +#include +#include +#include +#include + +#include "Align.h" +#include "Arm64Emitter.h" +#include "Assert.h" +#include "BitUtils.h" +#include "../types.h" +#include "MathUtil.h" + +namespace Arm64Gen +{ +namespace +{ +const int kWRegSizeInBits = 32; +const int kXRegSizeInBits = 64; + +// The below few functions are taken from V8. +int CountLeadingZeros(uint64_t value, int width) +{ + // TODO(jbramley): Optimize this for ARM64 hosts. + int count = 0; + uint64_t bit_test = 1ULL << (width - 1); + while ((count < width) && ((bit_test & value) == 0)) + { + count++; + bit_test >>= 1; + } + return count; +} + +uint64_t LargestPowerOf2Divisor(uint64_t value) +{ + return value & -(int64_t)value; +} + +// For ADD/SUB +bool IsImmArithmetic(uint64_t input, u32* val, bool* shift) +{ + if (input < 4096) + { + *val = input; + *shift = false; + return true; + } + else if ((input & 0xFFF000) == input) + { + *val = input >> 12; + *shift = true; + return true; + } + return false; +} + +// For AND/TST/ORR/EOR etc +bool IsImmLogical(uint64_t value, unsigned int width, unsigned int* n, unsigned int* imm_s, + unsigned int* imm_r) +{ + // DCHECK((n != NULL) && (imm_s != NULL) && (imm_r != NULL)); + // DCHECK((width == kWRegSizeInBits) || (width == kXRegSizeInBits)); + + bool negate = false; + + // Logical immediates are encoded using parameters n, imm_s and imm_r using + // the following table: + // + // N imms immr size S R + // 1 ssssss rrrrrr 64 UInt(ssssss) UInt(rrrrrr) + // 0 0sssss xrrrrr 32 UInt(sssss) UInt(rrrrr) + // 0 10ssss xxrrrr 16 UInt(ssss) UInt(rrrr) + // 0 110sss xxxrrr 8 UInt(sss) UInt(rrr) + // 0 1110ss xxxxrr 4 UInt(ss) UInt(rr) + // 0 11110s xxxxxr 2 UInt(s) UInt(r) + // (s bits must not be all set) + // + // A pattern is constructed of size bits, where the least significant S+1 bits + // are set. The pattern is rotated right by R, and repeated across a 32 or + // 64-bit value, depending on destination register width. + // + // Put another way: the basic format of a logical immediate is a single + // contiguous stretch of 1 bits, repeated across the whole word at intervals + // given by a power of 2. To identify them quickly, we first locate the + // lowest stretch of 1 bits, then the next 1 bit above that; that combination + // is different for every logical immediate, so it gives us all the + // information we need to identify the only logical immediate that our input + // could be, and then we simply check if that's the value we actually have. + // + // (The rotation parameter does give the possibility of the stretch of 1 bits + // going 'round the end' of the word. To deal with that, we observe that in + // any situation where that happens the bitwise NOT of the value is also a + // valid logical immediate. So we simply invert the input whenever its low bit + // is set, and then we know that the rotated case can't arise.) + + if (value & 1) + { + // If the low bit is 1, negate the value, and set a flag to remember that we + // did (so that we can adjust the return values appropriately). + negate = true; + value = ~value; + } + + if (width == kWRegSizeInBits) + { + // To handle 32-bit logical immediates, the very easiest thing is to repeat + // the input value twice to make a 64-bit word. The correct encoding of that + // as a logical immediate will also be the correct encoding of the 32-bit + // value. + + // The most-significant 32 bits may not be zero (ie. negate is true) so + // shift the value left before duplicating it. + value <<= kWRegSizeInBits; + value |= value >> kWRegSizeInBits; + } + + // The basic analysis idea: imagine our input word looks like this. + // + // 0011111000111110001111100011111000111110001111100011111000111110 + // c b a + // |<--d-->| + // + // We find the lowest set bit (as an actual power-of-2 value, not its index) + // and call it a. Then we add a to our original number, which wipes out the + // bottommost stretch of set bits and replaces it with a 1 carried into the + // next zero bit. Then we look for the new lowest set bit, which is in + // position b, and subtract it, so now our number is just like the original + // but with the lowest stretch of set bits completely gone. Now we find the + // lowest set bit again, which is position c in the diagram above. Then we'll + // measure the distance d between bit positions a and c (using CLZ), and that + // tells us that the only valid logical immediate that could possibly be equal + // to this number is the one in which a stretch of bits running from a to just + // below b is replicated every d bits. + uint64_t a = LargestPowerOf2Divisor(value); + uint64_t value_plus_a = value + a; + uint64_t b = LargestPowerOf2Divisor(value_plus_a); + uint64_t value_plus_a_minus_b = value_plus_a - b; + uint64_t c = LargestPowerOf2Divisor(value_plus_a_minus_b); + + int d, clz_a, out_n; + uint64_t mask; + + if (c != 0) + { + // The general case, in which there is more than one stretch of set bits. + // Compute the repeat distance d, and set up a bitmask covering the basic + // unit of repetition (i.e. a word with the bottom d bits set). Also, in all + // of these cases the N bit of the output will be zero. + clz_a = CountLeadingZeros(a, kXRegSizeInBits); + int clz_c = CountLeadingZeros(c, kXRegSizeInBits); + d = clz_a - clz_c; + mask = ((UINT64_C(1) << d) - 1); + out_n = 0; + } + else + { + // Handle degenerate cases. + // + // If any of those 'find lowest set bit' operations didn't find a set bit at + // all, then the word will have been zero thereafter, so in particular the + // last lowest_set_bit operation will have returned zero. So we can test for + // all the special case conditions in one go by seeing if c is zero. + if (a == 0) + { + // The input was zero (or all 1 bits, which will come to here too after we + // inverted it at the start of the function), for which we just return + // false. + return false; + } + else + { + // Otherwise, if c was zero but a was not, then there's just one stretch + // of set bits in our word, meaning that we have the trivial case of + // d == 64 and only one 'repetition'. Set up all the same variables as in + // the general case above, and set the N bit in the output. + clz_a = CountLeadingZeros(a, kXRegSizeInBits); + d = 64; + mask = ~UINT64_C(0); + out_n = 1; + } + } + + // If the repeat period d is not a power of two, it can't be encoded. + if (!MathUtil::IsPow2(d)) + return false; + + // If the bit stretch (b - a) does not fit within the mask derived from the + // repeat period, then fail. + if (((b - a) & ~mask) != 0) + return false; + + // The only possible option is b - a repeated every d bits. Now we're going to + // actually construct the valid logical immediate derived from that + // specification, and see if it equals our original input. + // + // To repeat a value every d bits, we multiply it by a number of the form + // (1 + 2^d + 2^(2d) + ...), i.e. 0x0001000100010001 or similar. These can + // be derived using a table lookup on CLZ(d). + static const std::array multipliers = {{ + 0x0000000000000001UL, + 0x0000000100000001UL, + 0x0001000100010001UL, + 0x0101010101010101UL, + 0x1111111111111111UL, + 0x5555555555555555UL, + }}; + + int multiplier_idx = CountLeadingZeros(d, kXRegSizeInBits) - 57; + + // Ensure that the index to the multipliers array is within bounds. + DEBUG_ASSERT((multiplier_idx >= 0) && (static_cast(multiplier_idx) < multipliers.size())); + + uint64_t multiplier = multipliers[multiplier_idx]; + uint64_t candidate = (b - a) * multiplier; + + // The candidate pattern doesn't match our input value, so fail. + if (value != candidate) + return false; + + // We have a match! This is a valid logical immediate, so now we have to + // construct the bits and pieces of the instruction encoding that generates + // it. + + // Count the set bits in our basic stretch. The special case of clz(0) == -1 + // makes the answer come out right for stretches that reach the very top of + // the word (e.g. numbers like 0xffffc00000000000). + int clz_b = (b == 0) ? -1 : CountLeadingZeros(b, kXRegSizeInBits); + int s = clz_a - clz_b; + + // Decide how many bits to rotate right by, to put the low bit of that basic + // stretch in position a. + int r; + if (negate) + { + // If we inverted the input right at the start of this function, here's + // where we compensate: the number of set bits becomes the number of clear + // bits, and the rotation count is based on position b rather than position + // a (since b is the location of the 'lowest' 1 bit after inversion). + s = d - s; + r = (clz_b + 1) & (d - 1); + } + else + { + r = (clz_a + 1) & (d - 1); + } + + // Now we're done, except for having to encode the S output in such a way that + // it gives both the number of set bits and the length of the repeated + // segment. The s field is encoded like this: + // + // imms size S + // ssssss 64 UInt(ssssss) + // 0sssss 32 UInt(sssss) + // 10ssss 16 UInt(ssss) + // 110sss 8 UInt(sss) + // 1110ss 4 UInt(ss) + // 11110s 2 UInt(s) + // + // So we 'or' (-d << 1) with our computed s to form imms. + *n = out_n; + *imm_s = ((-d << 1) | (s - 1)) & 0x3f; + *imm_r = r; + + return true; +} + +float FPImm8ToFloat(u8 bits) +{ + const u32 sign = bits >> 7; + const u32 bit6 = (bits >> 6) & 1; + const u32 exp = ((!bit6) << 7) | (0x7C * bit6) | ((bits >> 4) & 3); + const u32 mantissa = (bits & 0xF) << 19; + const u32 f = (sign << 31) | (exp << 23) | mantissa; + + return Common::BitCast(f); +} + +bool FPImm8FromFloat(float value, u8* imm_out) +{ + const u32 f = Common::BitCast(value); + const u32 mantissa4 = (f & 0x7FFFFF) >> 19; + const u32 exponent = (f >> 23) & 0xFF; + const u32 sign = f >> 31; + + if ((exponent >> 7) == ((exponent >> 6) & 1)) + return false; + + const u8 imm8 = (sign << 7) | ((!(exponent >> 7)) << 6) | ((exponent & 3) << 4) | mantissa4; + const float new_float = FPImm8ToFloat(imm8); + if (new_float == value) + *imm_out = imm8; + else + return false; + + return true; +} +} // Anonymous namespace + +void ARM64XEmitter::SetCodePtrUnsafe(ptrdiff_t ptr) +{ + m_code = ptr; +} + +void ARM64XEmitter::SetCodePtr(ptrdiff_t ptr) +{ + SetCodePtrUnsafe(ptr); + m_lastCacheFlushEnd = ptr; +} + +void ARM64XEmitter::SetCodeBase(u8* rwbase, u8* rxbase) +{ + m_code = 0; + m_lastCacheFlushEnd = 0; + m_rwbase = rwbase; + m_rxbase = rxbase; +} + +ptrdiff_t ARM64XEmitter::GetCodeOffset() +{ + return m_code; +} + +const u8* ARM64XEmitter::GetRWPtr() +{ + return m_rwbase + m_code; +} + +u8* ARM64XEmitter::GetWriteableRWPtr() +{ + return m_rwbase + m_code; +} + +void* ARM64XEmitter::GetRXPtr() +{ + return m_rxbase + m_code; +} + +void ARM64XEmitter::ReserveCodeSpace(u32 bytes) +{ + for (u32 i = 0; i < bytes / 4; i++) + BRK(0); +} + +ptrdiff_t ARM64XEmitter::AlignCode16() +{ + int c = int((u64)m_code & 15); + if (c) + ReserveCodeSpace(16 - c); + return m_code; +} + +ptrdiff_t ARM64XEmitter::AlignCodePage() +{ + int c = int((u64)m_code & 4095); + if (c) + ReserveCodeSpace(4096 - c); + return m_code; +} + +void ARM64XEmitter::Write32(u32 value) +{ + std::memcpy(m_rwbase + m_code, &value, sizeof(u32)); + m_code += sizeof(u32); +} + +void ARM64XEmitter::FlushIcache() +{ + FlushIcacheSection(m_rxbase + m_lastCacheFlushEnd, m_rxbase + m_code); + m_lastCacheFlushEnd = m_code; +} + +void ARM64XEmitter::FlushIcacheSection(u8* start, u8* end) +{ + if (start == end) + return; + +#if defined(IOS) + // Header file says this is equivalent to: sys_icache_invalidate(start, end - start); + sys_cache_control(kCacheFunctionPrepareForExecution, start, end - start); +#else + // Don't rely on GCC's __clear_cache implementation, as it caches + // icache/dcache cache line sizes, that can vary between cores on + // big.LITTLE architectures. + u64 addr, ctr_el0; + static size_t icache_line_size = 0xffff, dcache_line_size = 0xffff; + size_t isize, dsize; + + __asm__ volatile("mrs %0, ctr_el0" : "=r"(ctr_el0)); + isize = 4 << ((ctr_el0 >> 0) & 0xf); + dsize = 4 << ((ctr_el0 >> 16) & 0xf); + + // use the global minimum cache line size + icache_line_size = isize = icache_line_size < isize ? icache_line_size : isize; + dcache_line_size = dsize = dcache_line_size < dsize ? dcache_line_size : dsize; + + addr = (u64)start & ~(u64)(dsize - 1); + for (; addr < (u64)end; addr += dsize) + // use "civac" instead of "cvau", as this is the suggested workaround for + // Cortex-A53 errata 819472, 826319, 827319 and 824069. + __asm__ volatile("dc civac, %0" : : "r"(addr) : "memory"); + __asm__ volatile("dsb ish" : : : "memory"); + + addr = (u64)start & ~(u64)(isize - 1); + for (; addr < (u64)end; addr += isize) + __asm__ volatile("ic ivau, %0" : : "r"(addr) : "memory"); + + __asm__ volatile("dsb ish" : : : "memory"); + __asm__ volatile("isb" : : : "memory"); +#endif +} + +// Exception generation +static const u32 ExcEnc[][3] = { + {0, 0, 1}, // SVC + {0, 0, 2}, // HVC + {0, 0, 3}, // SMC + {1, 0, 0}, // BRK + {2, 0, 0}, // HLT + {5, 0, 1}, // DCPS1 + {5, 0, 2}, // DCPS2 + {5, 0, 3}, // DCPS3 +}; + +// Arithmetic generation +static const u32 ArithEnc[] = { + 0x058, // ADD + 0x258, // SUB +}; + +// Conditional Select +static const u32 CondSelectEnc[][2] = { + {0, 0}, // CSEL + {0, 1}, // CSINC + {1, 0}, // CSINV + {1, 1}, // CSNEG +}; + +// Data-Processing (1 source) +static const u32 Data1SrcEnc[][2] = { + {0, 0}, // RBIT + {0, 1}, // REV16 + {0, 2}, // REV32 + {0, 3}, // REV64 + {0, 4}, // CLZ + {0, 5}, // CLS +}; + +// Data-Processing (2 source) +static const u32 Data2SrcEnc[] = { + 0x02, // UDIV + 0x03, // SDIV + 0x08, // LSLV + 0x09, // LSRV + 0x0A, // ASRV + 0x0B, // RORV + 0x10, // CRC32B + 0x11, // CRC32H + 0x12, // CRC32W + 0x14, // CRC32CB + 0x15, // CRC32CH + 0x16, // CRC32CW + 0x13, // CRC32X (64bit Only) + 0x17, // XRC32CX (64bit Only) +}; + +// Data-Processing (3 source) +static const u32 Data3SrcEnc[][2] = { + {0, 0}, // MADD + {0, 1}, // MSUB + {1, 0}, // SMADDL (64Bit Only) + {1, 1}, // SMSUBL (64Bit Only) + {2, 0}, // SMULH (64Bit Only) + {5, 0}, // UMADDL (64Bit Only) + {5, 1}, // UMSUBL (64Bit Only) + {6, 0}, // UMULH (64Bit Only) +}; + +// Logical (shifted register) +static const u32 LogicalEnc[][2] = { + {0, 0}, // AND + {0, 1}, // BIC + {1, 0}, // OOR + {1, 1}, // ORN + {2, 0}, // EOR + {2, 1}, // EON + {3, 0}, // ANDS + {3, 1}, // BICS +}; + +// Load/Store Exclusive +static const u32 LoadStoreExcEnc[][5] = { + {0, 0, 0, 0, 0}, // STXRB + {0, 0, 0, 0, 1}, // STLXRB + {0, 0, 1, 0, 0}, // LDXRB + {0, 0, 1, 0, 1}, // LDAXRB + {0, 1, 0, 0, 1}, // STLRB + {0, 1, 1, 0, 1}, // LDARB + {1, 0, 0, 0, 0}, // STXRH + {1, 0, 0, 0, 1}, // STLXRH + {1, 0, 1, 0, 0}, // LDXRH + {1, 0, 1, 0, 1}, // LDAXRH + {1, 1, 0, 0, 1}, // STLRH + {1, 1, 1, 0, 1}, // LDARH + {2, 0, 0, 0, 0}, // STXR + {3, 0, 0, 0, 0}, // (64bit) STXR + {2, 0, 0, 0, 1}, // STLXR + {3, 0, 0, 0, 1}, // (64bit) STLXR + {2, 0, 0, 1, 0}, // STXP + {3, 0, 0, 1, 0}, // (64bit) STXP + {2, 0, 0, 1, 1}, // STLXP + {3, 0, 0, 1, 1}, // (64bit) STLXP + {2, 0, 1, 0, 0}, // LDXR + {3, 0, 1, 0, 0}, // (64bit) LDXR + {2, 0, 1, 0, 1}, // LDAXR + {3, 0, 1, 0, 1}, // (64bit) LDAXR + {2, 0, 1, 1, 0}, // LDXP + {3, 0, 1, 1, 0}, // (64bit) LDXP + {2, 0, 1, 1, 1}, // LDAXP + {3, 0, 1, 1, 1}, // (64bit) LDAXP + {2, 1, 0, 0, 1}, // STLR + {3, 1, 0, 0, 1}, // (64bit) STLR + {2, 1, 1, 0, 1}, // LDAR + {3, 1, 1, 0, 1}, // (64bit) LDAR +}; + +void ARM64XEmitter::EncodeCompareBranchInst(u32 op, ARM64Reg Rt, const void* ptr) +{ + bool b64Bit = Is64Bit(Rt); + s64 distance = (s64)ptr - (s64)(m_rxbase + m_code); + + ASSERT_MSG(DYNA_REC, !(distance & 0x3), "%s: distance must be a multiple of 4: %" PRIx64, + __func__, distance); + + distance >>= 2; + + ASSERT_MSG(DYNA_REC, distance >= -0x40000 && distance <= 0x3FFFF, + "%s: Received too large distance: %" PRIx64, __func__, distance); + + Rt = DecodeReg(Rt); + Write32((b64Bit << 31) | (0x34 << 24) | (op << 24) | (((u32)distance << 5) & 0xFFFFE0) | Rt); +} + +void ARM64XEmitter::EncodeTestBranchInst(u32 op, ARM64Reg Rt, u8 bits, const void* ptr) +{ + bool b64Bit = Is64Bit(Rt); + s64 distance = (s64)ptr - (s64)(m_rxbase + m_code); + + ASSERT_MSG(DYNA_REC, !(distance & 0x3), "%s: distance must be a multiple of 4: %" PRIx64, + __func__, distance); + + distance >>= 2; + + ASSERT_MSG(DYNA_REC, distance >= -0x3FFF && distance < 0x3FFF, + "%s: Received too large distance: %" PRIx64, __func__, distance); + + Rt = DecodeReg(Rt); + Write32((b64Bit << 31) | (0x36 << 24) | (op << 24) | (bits << 19) | + (((u32)distance << 5) & 0x7FFE0) | Rt); +} + +void ARM64XEmitter::EncodeUnconditionalBranchInst(u32 op, const void* ptr) +{ + s64 distance = (s64)ptr - s64(m_rxbase + m_code); + + ASSERT_MSG(DYNA_REC, !(distance & 0x3), "%s: distance must be a multiple of 4: %" PRIx64, + __func__, distance); + + distance >>= 2; + + ASSERT_MSG(DYNA_REC, distance >= -0x2000000LL && distance <= 0x1FFFFFFLL, + "%s: Received too large distance: %" PRIx64, __func__, distance); + + Write32((op << 31) | (0x5 << 26) | (distance & 0x3FFFFFF)); +} + +void ARM64XEmitter::EncodeUnconditionalBranchInst(u32 opc, u32 op2, u32 op3, u32 op4, ARM64Reg Rn) +{ + Rn = DecodeReg(Rn); + Write32((0x6B << 25) | (opc << 21) | (op2 << 16) | (op3 << 10) | (Rn << 5) | op4); +} + +void ARM64XEmitter::EncodeExceptionInst(u32 instenc, u32 imm) +{ + ASSERT_MSG(DYNA_REC, !(imm & ~0xFFFF), "%s: Exception instruction too large immediate: %d", + __func__, imm); + + Write32((0xD4 << 24) | (ExcEnc[instenc][0] << 21) | (imm << 5) | (ExcEnc[instenc][1] << 2) | + ExcEnc[instenc][2]); +} + +void ARM64XEmitter::EncodeSystemInst(u32 op0, u32 op1, u32 CRn, u32 CRm, u32 op2, ARM64Reg Rt) +{ + Write32((0x354 << 22) | (op0 << 19) | (op1 << 16) | (CRn << 12) | (CRm << 8) | (op2 << 5) | Rt); +} + +void ARM64XEmitter::EncodeArithmeticInst(u32 instenc, bool flags, ARM64Reg Rd, ARM64Reg Rn, + ARM64Reg Rm, ArithOption Option) +{ + bool b64Bit = Is64Bit(Rd); + + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + Rm = DecodeReg(Rm); + Write32((b64Bit << 31) | (flags << 29) | (ArithEnc[instenc] << 21) | + (Option.GetType() == ArithOption::TYPE_EXTENDEDREG ? (1 << 21) : 0) | (Rm << 16) | + Option.GetData() | (Rn << 5) | Rd); +} + +void ARM64XEmitter::EncodeArithmeticCarryInst(u32 op, bool flags, ARM64Reg Rd, ARM64Reg Rn, + ARM64Reg Rm) +{ + bool b64Bit = Is64Bit(Rd); + + Rd = DecodeReg(Rd); + Rm = DecodeReg(Rm); + Rn = DecodeReg(Rn); + Write32((b64Bit << 31) | (op << 30) | (flags << 29) | (0xD0 << 21) | (Rm << 16) | (Rn << 5) | Rd); +} + +void ARM64XEmitter::EncodeCondCompareImmInst(u32 op, ARM64Reg Rn, u32 imm, u32 nzcv, CCFlags cond) +{ + bool b64Bit = Is64Bit(Rn); + + ASSERT_MSG(DYNA_REC, !(imm & ~0x1F), "%s: too large immediate: %d", __func__, imm); + ASSERT_MSG(DYNA_REC, !(nzcv & ~0xF), "%s: Flags out of range: %d", __func__, nzcv); + + Rn = DecodeReg(Rn); + Write32((b64Bit << 31) | (op << 30) | (1 << 29) | (0xD2 << 21) | (imm << 16) | (cond << 12) | + (1 << 11) | (Rn << 5) | nzcv); +} + +void ARM64XEmitter::EncodeCondCompareRegInst(u32 op, ARM64Reg Rn, ARM64Reg Rm, u32 nzcv, + CCFlags cond) +{ + bool b64Bit = Is64Bit(Rm); + + ASSERT_MSG(DYNA_REC, !(nzcv & ~0xF), "%s: Flags out of range: %d", __func__, nzcv); + + Rm = DecodeReg(Rm); + Rn = DecodeReg(Rn); + Write32((b64Bit << 31) | (op << 30) | (1 << 29) | (0xD2 << 21) | (Rm << 16) | (cond << 12) | + (Rn << 5) | nzcv); +} + +void ARM64XEmitter::EncodeCondSelectInst(u32 instenc, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, + CCFlags cond) +{ + bool b64Bit = Is64Bit(Rd); + + Rd = DecodeReg(Rd); + Rm = DecodeReg(Rm); + Rn = DecodeReg(Rn); + Write32((b64Bit << 31) | (CondSelectEnc[instenc][0] << 30) | (0xD4 << 21) | (Rm << 16) | + (cond << 12) | (CondSelectEnc[instenc][1] << 10) | (Rn << 5) | Rd); +} + +void ARM64XEmitter::EncodeData1SrcInst(u32 instenc, ARM64Reg Rd, ARM64Reg Rn) +{ + bool b64Bit = Is64Bit(Rd); + + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + Write32((b64Bit << 31) | (0x2D6 << 21) | (Data1SrcEnc[instenc][0] << 16) | + (Data1SrcEnc[instenc][1] << 10) | (Rn << 5) | Rd); +} + +void ARM64XEmitter::EncodeData2SrcInst(u32 instenc, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + bool b64Bit = Is64Bit(Rd); + + Rd = DecodeReg(Rd); + Rm = DecodeReg(Rm); + Rn = DecodeReg(Rn); + Write32((b64Bit << 31) | (0x0D6 << 21) | (Rm << 16) | (Data2SrcEnc[instenc] << 10) | (Rn << 5) | + Rd); +} + +void ARM64XEmitter::EncodeData3SrcInst(u32 instenc, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, + ARM64Reg Ra) +{ + bool b64Bit = Is64Bit(Rd); + + Rd = DecodeReg(Rd); + Rm = DecodeReg(Rm); + Rn = DecodeReg(Rn); + Ra = DecodeReg(Ra); + Write32((b64Bit << 31) | (0xD8 << 21) | (Data3SrcEnc[instenc][0] << 21) | (Rm << 16) | + (Data3SrcEnc[instenc][1] << 15) | (Ra << 10) | (Rn << 5) | Rd); +} + +void ARM64XEmitter::EncodeLogicalInst(u32 instenc, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, + ArithOption Shift) +{ + bool b64Bit = Is64Bit(Rd); + + Rd = DecodeReg(Rd); + Rm = DecodeReg(Rm); + Rn = DecodeReg(Rn); + Write32((b64Bit << 31) | (LogicalEnc[instenc][0] << 29) | (0x5 << 25) | + (LogicalEnc[instenc][1] << 21) | Shift.GetData() | (Rm << 16) | (Rn << 5) | Rd); +} + +void ARM64XEmitter::EncodeLoadRegisterInst(u32 bitop, ARM64Reg Rt, u32 imm) +{ + bool b64Bit = Is64Bit(Rt); + bool bVec = IsVector(Rt); + + ASSERT_MSG(DYNA_REC, !(imm & 0xFFFFF), "%s: offset too large %d", __func__, imm); + + Rt = DecodeReg(Rt); + if (b64Bit && bitop != 0x2) // LDRSW(0x2) uses 64bit reg, doesn't have 64bit bit set + bitop |= 0x1; + Write32((bitop << 30) | (bVec << 26) | (0x18 << 24) | (imm << 5) | Rt); +} + +void ARM64XEmitter::EncodeLoadStoreExcInst(u32 instenc, ARM64Reg Rs, ARM64Reg Rt2, ARM64Reg Rn, + ARM64Reg Rt) +{ + Rs = DecodeReg(Rs); + Rt2 = DecodeReg(Rt2); + Rn = DecodeReg(Rn); + Rt = DecodeReg(Rt); + Write32((LoadStoreExcEnc[instenc][0] << 30) | (0x8 << 24) | (LoadStoreExcEnc[instenc][1] << 23) | + (LoadStoreExcEnc[instenc][2] << 22) | (LoadStoreExcEnc[instenc][3] << 21) | (Rs << 16) | + (LoadStoreExcEnc[instenc][4] << 15) | (Rt2 << 10) | (Rn << 5) | Rt); +} + +void ARM64XEmitter::EncodeLoadStorePairedInst(u32 op, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn, + u32 imm) +{ + bool b64Bit = Is64Bit(Rt); + bool b128Bit = IsQuad(Rt); + bool bVec = IsVector(Rt); + + if (b128Bit) + imm >>= 4; + else if (b64Bit) + imm >>= 3; + else + imm >>= 2; + + ASSERT_MSG(DYNA_REC, !(imm & ~0xF), "%s: offset too large %d", __func__, imm); + + u32 opc = 0; + if (b128Bit) + opc = 2; + else if (b64Bit && bVec) + opc = 1; + else if (b64Bit && !bVec) + opc = 2; + + Rt = DecodeReg(Rt); + Rt2 = DecodeReg(Rt2); + Rn = DecodeReg(Rn); + Write32((opc << 30) | (bVec << 26) | (op << 22) | (imm << 15) | (Rt2 << 10) | (Rn << 5) | Rt); +} + +void ARM64XEmitter::EncodeLoadStoreIndexedInst(u32 op, u32 op2, ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + bool b64Bit = Is64Bit(Rt); + bool bVec = IsVector(Rt); + + u32 offset = imm & 0x1FF; + + ASSERT_MSG(DYNA_REC, !(imm < -256 || imm > 255), "%s: offset too large %d", __func__, imm); + + Rt = DecodeReg(Rt); + Rn = DecodeReg(Rn); + Write32((b64Bit << 30) | (op << 22) | (bVec << 26) | (offset << 12) | (op2 << 10) | (Rn << 5) | + Rt); +} + +void ARM64XEmitter::EncodeLoadStoreIndexedInst(u32 op, ARM64Reg Rt, ARM64Reg Rn, s32 imm, u8 size) +{ + bool b64Bit = Is64Bit(Rt); + bool bVec = IsVector(Rt); + + if (size == 64) + imm >>= 3; + else if (size == 32) + imm >>= 2; + else if (size == 16) + imm >>= 1; + + ASSERT_MSG(DYNA_REC, imm >= 0, "%s(INDEX_UNSIGNED): offset must be positive %d", __func__, imm); + ASSERT_MSG(DYNA_REC, !(imm & ~0xFFF), "%s(INDEX_UNSIGNED): offset too large %d", __func__, imm); + + Rt = DecodeReg(Rt); + Rn = DecodeReg(Rn); + Write32((b64Bit << 30) | (op << 22) | (bVec << 26) | (imm << 10) | (Rn << 5) | Rt); +} + +void ARM64XEmitter::EncodeMOVWideInst(u32 op, ARM64Reg Rd, u32 imm, ShiftAmount pos) +{ + bool b64Bit = Is64Bit(Rd); + + ASSERT_MSG(DYNA_REC, !(imm & ~0xFFFF), "%s: immediate out of range: %d", __func__, imm); + + Rd = DecodeReg(Rd); + Write32((b64Bit << 31) | (op << 29) | (0x25 << 23) | (pos << 21) | (imm << 5) | Rd); +} + +void ARM64XEmitter::EncodeBitfieldMOVInst(u32 op, ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms) +{ + bool b64Bit = Is64Bit(Rd); + + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + Write32((b64Bit << 31) | (op << 29) | (0x26 << 23) | (b64Bit << 22) | (immr << 16) | + (imms << 10) | (Rn << 5) | Rd); +} + +void ARM64XEmitter::EncodeLoadStoreRegisterOffset(u32 size, u32 opc, ARM64Reg Rt, ARM64Reg Rn, + ArithOption Rm) +{ + Rt = DecodeReg(Rt); + Rn = DecodeReg(Rn); + ARM64Reg decoded_Rm = DecodeReg(Rm.GetReg()); + + Write32((size << 30) | (opc << 22) | (0x1C1 << 21) | (decoded_Rm << 16) | Rm.GetData() | + (1 << 11) | (Rn << 5) | Rt); +} + +void ARM64XEmitter::EncodeAddSubImmInst(u32 op, bool flags, u32 shift, u32 imm, ARM64Reg Rn, + ARM64Reg Rd) +{ + bool b64Bit = Is64Bit(Rd); + + ASSERT_MSG(DYNA_REC, !(imm & ~0xFFF), "%s: immediate too large: %x", __func__, imm); + + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + Write32((b64Bit << 31) | (op << 30) | (flags << 29) | (0x11 << 24) | (shift << 22) | (imm << 10) | + (Rn << 5) | Rd); +} + +void ARM64XEmitter::EncodeLogicalImmInst(u32 op, ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms, + int n) +{ + // Sometimes Rd is fixed to SP, but can still be 32bit or 64bit. + // Use Rn to determine bitness here. + bool b64Bit = Is64Bit(Rn); + + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + + Write32((b64Bit << 31) | (op << 29) | (0x24 << 23) | (n << 22) | (immr << 16) | (imms << 10) | + (Rn << 5) | Rd); +} + +void ARM64XEmitter::EncodeLoadStorePair(u32 op, u32 load, IndexType type, ARM64Reg Rt, ARM64Reg Rt2, + ARM64Reg Rn, s32 imm) +{ + bool b64Bit = Is64Bit(Rt); + u32 type_encode = 0; + + switch (type) + { + case INDEX_SIGNED: + type_encode = 0b010; + break; + case INDEX_POST: + type_encode = 0b001; + break; + case INDEX_PRE: + type_encode = 0b011; + break; + case INDEX_UNSIGNED: + ASSERT_MSG(DYNA_REC, false, "%s doesn't support INDEX_UNSIGNED!", __func__); + break; + } + + if (b64Bit) + { + op |= 0b10; + imm >>= 3; + } + else + { + imm >>= 2; + } + + Rt = DecodeReg(Rt); + Rt2 = DecodeReg(Rt2); + Rn = DecodeReg(Rn); + + Write32((op << 30) | (0b101 << 27) | (type_encode << 23) | (load << 22) | ((imm & 0x7F) << 15) | + (Rt2 << 10) | (Rn << 5) | Rt); +} +void ARM64XEmitter::EncodeAddressInst(u32 op, ARM64Reg Rd, s32 imm) +{ + Rd = DecodeReg(Rd); + + Write32((op << 31) | ((imm & 0x3) << 29) | (0x10 << 24) | ((imm & 0x1FFFFC) << 3) | Rd); +} + +void ARM64XEmitter::EncodeLoadStoreUnscaled(u32 size, u32 op, ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + ASSERT_MSG(DYNA_REC, !(imm < -256 || imm > 255), "%s received too large offset: %d", __func__, + imm); + Rt = DecodeReg(Rt); + Rn = DecodeReg(Rn); + + Write32((size << 30) | (0b111 << 27) | (op << 22) | ((imm & 0x1FF) << 12) | (Rn << 5) | Rt); +} + +static constexpr bool IsInRangeImm19(s64 distance) +{ + return (distance >= -0x40000 && distance <= 0x3FFFF); +} + +static constexpr bool IsInRangeImm14(s64 distance) +{ + return (distance >= -0x2000 && distance <= 0x1FFF); +} + +static constexpr bool IsInRangeImm26(s64 distance) +{ + return (distance >= -0x2000000 && distance <= 0x1FFFFFF); +} + +static constexpr u32 MaskImm19(s64 distance) +{ + return distance & 0x7FFFF; +} + +static constexpr u32 MaskImm14(s64 distance) +{ + return distance & 0x3FFF; +} + +static constexpr u32 MaskImm26(s64 distance) +{ + return distance & 0x3FFFFFF; +} + +// FixupBranch branching +void ARM64XEmitter::SetJumpTarget(FixupBranch const& branch) +{ + bool Not = false; + u32 inst = 0; + s64 distance = (s64)(m_code - branch.ptr); + distance >>= 2; + + switch (branch.type) + { + case 1: // CBNZ + Not = true; + case 0: // CBZ + { + ASSERT_MSG(DYNA_REC, IsInRangeImm19(distance), "%s(%d): Received too large distance: %" PRIx64, + __func__, branch.type, distance); + bool b64Bit = Is64Bit(branch.reg); + ARM64Reg reg = DecodeReg(branch.reg); + inst = (b64Bit << 31) | (0x1A << 25) | (Not << 24) | (MaskImm19(distance) << 5) | reg; + } + break; + case 2: // B (conditional) + ASSERT_MSG(DYNA_REC, IsInRangeImm19(distance), "%s(%d): Received too large distance: %" PRIx64, + __func__, branch.type, distance); + inst = (0x2A << 25) | (MaskImm19(distance) << 5) | branch.cond; + break; + case 4: // TBNZ + Not = true; + case 3: // TBZ + { + ASSERT_MSG(DYNA_REC, IsInRangeImm14(distance), "%s(%d): Received too large distance: %" PRIx64, + __func__, branch.type, distance); + ARM64Reg reg = DecodeReg(branch.reg); + inst = ((branch.bit & 0x20) << 26) | (0x1B << 25) | (Not << 24) | ((branch.bit & 0x1F) << 19) | + (MaskImm14(distance) << 5) | reg; + } + break; + case 5: // B (uncoditional) + ASSERT_MSG(DYNA_REC, IsInRangeImm26(distance), "%s(%d): Received too large distance: %" PRIx64, + __func__, branch.type, distance); + inst = (0x5 << 26) | MaskImm26(distance); + break; + case 6: // BL (unconditional) + ASSERT_MSG(DYNA_REC, IsInRangeImm26(distance), "%s(%d): Received too large distance: %" PRIx64, + __func__, branch.type, distance); + inst = (0x25 << 26) | MaskImm26(distance); + break; + } + + std::memcpy(m_rwbase + branch.ptr, &inst, sizeof(inst)); +} + +FixupBranch ARM64XEmitter::CBZ(ARM64Reg Rt) +{ + FixupBranch branch; + branch.ptr = m_code; + branch.type = 0; + branch.reg = Rt; + HINT(HINT_NOP); + return branch; +} +FixupBranch ARM64XEmitter::CBNZ(ARM64Reg Rt) +{ + FixupBranch branch; + branch.ptr = m_code; + branch.type = 1; + branch.reg = Rt; + HINT(HINT_NOP); + return branch; +} +FixupBranch ARM64XEmitter::B(CCFlags cond) +{ + FixupBranch branch; + branch.ptr = m_code; + branch.type = 2; + branch.cond = cond; + HINT(HINT_NOP); + return branch; +} +FixupBranch ARM64XEmitter::TBZ(ARM64Reg Rt, u8 bit) +{ + FixupBranch branch; + branch.ptr = m_code; + branch.type = 3; + branch.reg = Rt; + branch.bit = bit; + HINT(HINT_NOP); + return branch; +} +FixupBranch ARM64XEmitter::TBNZ(ARM64Reg Rt, u8 bit) +{ + FixupBranch branch; + branch.ptr = m_code; + branch.type = 4; + branch.reg = Rt; + branch.bit = bit; + HINT(HINT_NOP); + return branch; +} +FixupBranch ARM64XEmitter::B() +{ + FixupBranch branch; + branch.ptr = m_code; + branch.type = 5; + HINT(HINT_NOP); + return branch; +} +FixupBranch ARM64XEmitter::BL() +{ + FixupBranch branch; + branch.ptr = m_code; + branch.type = 6; + HINT(HINT_NOP); + return branch; +} + +// Compare and Branch +void ARM64XEmitter::CBZ(ARM64Reg Rt, const void* ptr) +{ + EncodeCompareBranchInst(0, Rt, ptr); +} +void ARM64XEmitter::CBNZ(ARM64Reg Rt, const void* ptr) +{ + EncodeCompareBranchInst(1, Rt, ptr); +} + +// Conditional Branch +void ARM64XEmitter::B(CCFlags cond, const void* ptr) +{ + s64 distance = (s64)ptr - (s64)(m_rxbase + m_code); + + distance >>= 2; + + ASSERT_MSG(DYNA_REC, IsInRangeImm19(distance), + "%s: Received too large distance: %p->%p %" PRIi64 " %" PRIx64, __func__, m_execcode, ptr, + distance, distance); + Write32((0x54 << 24) | (MaskImm19(distance) << 5) | cond); +} + +// Test and Branch +void ARM64XEmitter::TBZ(ARM64Reg Rt, u8 bits, const void* ptr) +{ + EncodeTestBranchInst(0, Rt, bits, ptr); +} +void ARM64XEmitter::TBNZ(ARM64Reg Rt, u8 bits, const void* ptr) +{ + EncodeTestBranchInst(1, Rt, bits, ptr); +} + +// Unconditional Branch +void ARM64XEmitter::B(const void* ptr) +{ + EncodeUnconditionalBranchInst(0, ptr); +} +void ARM64XEmitter::BL(const void* ptr) +{ + EncodeUnconditionalBranchInst(1, ptr); +} + +void ARM64XEmitter::QuickCallFunction(ARM64Reg scratchreg, const void* func) +{ + s64 distance = (s64)func - (s64)(m_rxbase + m_code); + distance >>= 2; // Can only branch to opcode-aligned (4) addresses + if (!IsInRangeImm26(distance)) + { + // WARN_LOG(DYNA_REC, "Distance too far in function call (%p to %p)! Using scratch.", m_code, + // func); + MOVI2R(scratchreg, (uintptr_t)func); + BLR(scratchreg); + } + else + { + BL(func); + } +} + +void ARM64XEmitter::QuickTailCall(ARM64Reg scratchreg, const void* func) +{ + s64 distance = (s64)func - (s64)(m_rxbase + m_code); + distance >>= 2; // Can only branch to opcode-aligned (4) addresses + if (!IsInRangeImm26(distance)) + { + // WARN_LOG(DYNA_REC, "Distance too far in function call (%p to %p)! Using scratch.", m_code, + // func); + MOVI2R(scratchreg, (uintptr_t)func); + BR(scratchreg); + } + else + { + B(func); + } +} + +// Unconditional Branch (register) +void ARM64XEmitter::BR(ARM64Reg Rn) +{ + EncodeUnconditionalBranchInst(0, 0x1F, 0, 0, Rn); +} +void ARM64XEmitter::BLR(ARM64Reg Rn) +{ + EncodeUnconditionalBranchInst(1, 0x1F, 0, 0, Rn); +} +void ARM64XEmitter::RET(ARM64Reg Rn) +{ + EncodeUnconditionalBranchInst(2, 0x1F, 0, 0, Rn); +} +void ARM64XEmitter::ERET() +{ + EncodeUnconditionalBranchInst(4, 0x1F, 0, 0, SP); +} +void ARM64XEmitter::DRPS() +{ + EncodeUnconditionalBranchInst(5, 0x1F, 0, 0, SP); +} + +// Exception generation +void ARM64XEmitter::SVC(u32 imm) +{ + EncodeExceptionInst(0, imm); +} + +void ARM64XEmitter::HVC(u32 imm) +{ + EncodeExceptionInst(1, imm); +} + +void ARM64XEmitter::SMC(u32 imm) +{ + EncodeExceptionInst(2, imm); +} + +void ARM64XEmitter::BRK(u32 imm) +{ + EncodeExceptionInst(3, imm); +} + +void ARM64XEmitter::HLT(u32 imm) +{ + EncodeExceptionInst(4, imm); +} + +void ARM64XEmitter::DCPS1(u32 imm) +{ + EncodeExceptionInst(5, imm); +} + +void ARM64XEmitter::DCPS2(u32 imm) +{ + EncodeExceptionInst(6, imm); +} + +void ARM64XEmitter::DCPS3(u32 imm) +{ + EncodeExceptionInst(7, imm); +} + +// System +void ARM64XEmitter::_MSR(PStateField field, u8 imm) +{ + u32 op1 = 0, op2 = 0; + switch (field) + { + case FIELD_SPSel: + op1 = 0; + op2 = 5; + break; + case FIELD_DAIFSet: + op1 = 3; + op2 = 6; + break; + case FIELD_DAIFClr: + op1 = 3; + op2 = 7; + break; + default: + ASSERT_MSG(DYNA_REC, false, "Invalid PStateField to do a imm move to"); + break; + } + EncodeSystemInst(0, op1, 4, imm, op2, WSP); +} + +static void GetSystemReg(PStateField field, int& o0, int& op1, int& CRn, int& CRm, int& op2) +{ + switch (field) + { + case FIELD_NZCV: + o0 = 3; + op1 = 3; + CRn = 4; + CRm = 2; + op2 = 0; + break; + case FIELD_FPCR: + o0 = 3; + op1 = 3; + CRn = 4; + CRm = 4; + op2 = 0; + break; + case FIELD_FPSR: + o0 = 3; + op1 = 3; + CRn = 4; + CRm = 4; + op2 = 1; + break; + case FIELD_PMCR_EL0: + o0 = 3; + op1 = 3; + CRn = 9; + CRm = 6; + op2 = 0; + break; + case FIELD_PMCCNTR_EL0: + o0 = 3; + op1 = 3; + CRn = 9; + CRm = 7; + op2 = 0; + break; + default: + ASSERT_MSG(DYNA_REC, false, "Invalid PStateField to do a register move from/to"); + break; + } +} + +void ARM64XEmitter::_MSR(PStateField field, ARM64Reg Rt) +{ + int o0 = 0, op1 = 0, CRn = 0, CRm = 0, op2 = 0; + ASSERT_MSG(DYNA_REC, Is64Bit(Rt), "MSR: Rt must be 64-bit"); + GetSystemReg(field, o0, op1, CRn, CRm, op2); + EncodeSystemInst(o0, op1, CRn, CRm, op2, DecodeReg(Rt)); +} + +void ARM64XEmitter::MRS(ARM64Reg Rt, PStateField field) +{ + int o0 = 0, op1 = 0, CRn = 0, CRm = 0, op2 = 0; + ASSERT_MSG(DYNA_REC, Is64Bit(Rt), "MRS: Rt must be 64-bit"); + GetSystemReg(field, o0, op1, CRn, CRm, op2); + EncodeSystemInst(o0 | 4, op1, CRn, CRm, op2, DecodeReg(Rt)); +} + +void ARM64XEmitter::CNTVCT(Arm64Gen::ARM64Reg Rt) +{ + ASSERT_MSG(DYNA_REC, Is64Bit(Rt), "CNTVCT: Rt must be 64-bit"); + + // MRS , CNTVCT_EL0 ; Read CNTVCT_EL0 into Xt + EncodeSystemInst(3 | 4, 3, 0xe, 0, 2, DecodeReg(Rt)); +} + +void ARM64XEmitter::HINT(SystemHint op) +{ + EncodeSystemInst(0, 3, 2, 0, op, WSP); +} +void ARM64XEmitter::CLREX() +{ + EncodeSystemInst(0, 3, 3, 0, 2, WSP); +} +void ARM64XEmitter::DSB(BarrierType type) +{ + EncodeSystemInst(0, 3, 3, type, 4, WSP); +} +void ARM64XEmitter::DMB(BarrierType type) +{ + EncodeSystemInst(0, 3, 3, type, 5, WSP); +} +void ARM64XEmitter::ISB(BarrierType type) +{ + EncodeSystemInst(0, 3, 3, type, 6, WSP); +} + +// Add/Subtract (extended register) +void ARM64XEmitter::ADD(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + ADD(Rd, Rn, Rm, ArithOption(Rd, ST_LSL, 0)); +} + +void ARM64XEmitter::ADD(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Option) +{ + EncodeArithmeticInst(0, false, Rd, Rn, Rm, Option); +} + +void ARM64XEmitter::ADDS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeArithmeticInst(0, true, Rd, Rn, Rm, ArithOption(Rd, ST_LSL, 0)); +} + +void ARM64XEmitter::ADDS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Option) +{ + EncodeArithmeticInst(0, true, Rd, Rn, Rm, Option); +} + +void ARM64XEmitter::SUB(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + SUB(Rd, Rn, Rm, ArithOption(Rd, ST_LSL, 0)); +} + +void ARM64XEmitter::SUB(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Option) +{ + EncodeArithmeticInst(1, false, Rd, Rn, Rm, Option); +} + +void ARM64XEmitter::SUBS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeArithmeticInst(1, true, Rd, Rn, Rm, ArithOption(Rd, ST_LSL, 0)); +} + +void ARM64XEmitter::SUBS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Option) +{ + EncodeArithmeticInst(1, true, Rd, Rn, Rm, Option); +} + +void ARM64XEmitter::CMN(ARM64Reg Rn, ARM64Reg Rm) +{ + CMN(Rn, Rm, ArithOption(Rn, ST_LSL, 0)); +} + +void ARM64XEmitter::CMN(ARM64Reg Rn, ARM64Reg Rm, ArithOption Option) +{ + EncodeArithmeticInst(0, true, Is64Bit(Rn) ? ZR : WZR, Rn, Rm, Option); +} + +void ARM64XEmitter::CMP(ARM64Reg Rn, ARM64Reg Rm) +{ + CMP(Rn, Rm, ArithOption(Rn, ST_LSL, 0)); +} + +void ARM64XEmitter::CMP(ARM64Reg Rn, ARM64Reg Rm, ArithOption Option) +{ + EncodeArithmeticInst(1, true, Is64Bit(Rn) ? ZR : WZR, Rn, Rm, Option); +} + +// Add/Subtract (with carry) +void ARM64XEmitter::ADC(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeArithmeticCarryInst(0, false, Rd, Rn, Rm); +} +void ARM64XEmitter::ADCS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeArithmeticCarryInst(0, true, Rd, Rn, Rm); +} +void ARM64XEmitter::SBC(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeArithmeticCarryInst(1, false, Rd, Rn, Rm); +} +void ARM64XEmitter::SBCS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeArithmeticCarryInst(1, true, Rd, Rn, Rm); +} + +// Conditional Compare (immediate) +void ARM64XEmitter::CCMN(ARM64Reg Rn, u32 imm, u32 nzcv, CCFlags cond) +{ + EncodeCondCompareImmInst(0, Rn, imm, nzcv, cond); +} +void ARM64XEmitter::CCMP(ARM64Reg Rn, u32 imm, u32 nzcv, CCFlags cond) +{ + EncodeCondCompareImmInst(1, Rn, imm, nzcv, cond); +} + +// Conditiona Compare (register) +void ARM64XEmitter::CCMN(ARM64Reg Rn, ARM64Reg Rm, u32 nzcv, CCFlags cond) +{ + EncodeCondCompareRegInst(0, Rn, Rm, nzcv, cond); +} +void ARM64XEmitter::CCMP(ARM64Reg Rn, ARM64Reg Rm, u32 nzcv, CCFlags cond) +{ + EncodeCondCompareRegInst(1, Rn, Rm, nzcv, cond); +} + +// Conditional Select +void ARM64XEmitter::CSEL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, CCFlags cond) +{ + EncodeCondSelectInst(0, Rd, Rn, Rm, cond); +} +void ARM64XEmitter::CSINC(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, CCFlags cond) +{ + EncodeCondSelectInst(1, Rd, Rn, Rm, cond); +} +void ARM64XEmitter::CSINV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, CCFlags cond) +{ + EncodeCondSelectInst(2, Rd, Rn, Rm, cond); +} +void ARM64XEmitter::CSNEG(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, CCFlags cond) +{ + EncodeCondSelectInst(3, Rd, Rn, Rm, cond); +} + +// Data-Processing 1 source +void ARM64XEmitter::RBIT(ARM64Reg Rd, ARM64Reg Rn) +{ + EncodeData1SrcInst(0, Rd, Rn); +} +void ARM64XEmitter::REV16(ARM64Reg Rd, ARM64Reg Rn) +{ + EncodeData1SrcInst(1, Rd, Rn); +} +void ARM64XEmitter::REV32(ARM64Reg Rd, ARM64Reg Rn) +{ + EncodeData1SrcInst(2, Rd, Rn); +} +void ARM64XEmitter::REV64(ARM64Reg Rd, ARM64Reg Rn) +{ + EncodeData1SrcInst(3, Rd, Rn); +} +void ARM64XEmitter::CLZ(ARM64Reg Rd, ARM64Reg Rn) +{ + EncodeData1SrcInst(4, Rd, Rn); +} +void ARM64XEmitter::CLS(ARM64Reg Rd, ARM64Reg Rn) +{ + EncodeData1SrcInst(5, Rd, Rn); +} + +// Data-Processing 2 source +void ARM64XEmitter::UDIV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeData2SrcInst(0, Rd, Rn, Rm); +} +void ARM64XEmitter::SDIV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeData2SrcInst(1, Rd, Rn, Rm); +} +void ARM64XEmitter::LSLV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeData2SrcInst(2, Rd, Rn, Rm); +} +void ARM64XEmitter::LSRV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeData2SrcInst(3, Rd, Rn, Rm); +} +void ARM64XEmitter::ASRV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeData2SrcInst(4, Rd, Rn, Rm); +} +void ARM64XEmitter::RORV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeData2SrcInst(5, Rd, Rn, Rm); +} +void ARM64XEmitter::CRC32B(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeData2SrcInst(6, Rd, Rn, Rm); +} +void ARM64XEmitter::CRC32H(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeData2SrcInst(7, Rd, Rn, Rm); +} +void ARM64XEmitter::CRC32W(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeData2SrcInst(8, Rd, Rn, Rm); +} +void ARM64XEmitter::CRC32CB(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeData2SrcInst(9, Rd, Rn, Rm); +} +void ARM64XEmitter::CRC32CH(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeData2SrcInst(10, Rd, Rn, Rm); +} +void ARM64XEmitter::CRC32CW(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeData2SrcInst(11, Rd, Rn, Rm); +} +void ARM64XEmitter::CRC32X(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeData2SrcInst(12, Rd, Rn, Rm); +} +void ARM64XEmitter::CRC32CX(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeData2SrcInst(13, Rd, Rn, Rm); +} + +// Data-Processing 3 source +void ARM64XEmitter::MADD(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra) +{ + EncodeData3SrcInst(0, Rd, Rn, Rm, Ra); +} +void ARM64XEmitter::MSUB(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra) +{ + EncodeData3SrcInst(1, Rd, Rn, Rm, Ra); +} +void ARM64XEmitter::SMADDL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra) +{ + EncodeData3SrcInst(2, Rd, Rn, Rm, Ra); +} +void ARM64XEmitter::SMULL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + SMADDL(Rd, Rn, Rm, SP); +} +void ARM64XEmitter::SMSUBL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra) +{ + EncodeData3SrcInst(3, Rd, Rn, Rm, Ra); +} +void ARM64XEmitter::SMULH(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeData3SrcInst(4, Rd, Rn, Rm, SP); +} +void ARM64XEmitter::UMADDL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra) +{ + EncodeData3SrcInst(5, Rd, Rn, Rm, Ra); +} +void ARM64XEmitter::UMULL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + UMADDL(Rd, Rn, Rm, SP); +} +void ARM64XEmitter::UMSUBL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra) +{ + EncodeData3SrcInst(6, Rd, Rn, Rm, Ra); +} +void ARM64XEmitter::UMULH(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeData3SrcInst(7, Rd, Rn, Rm, SP); +} +void ARM64XEmitter::MUL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeData3SrcInst(0, Rd, Rn, Rm, SP); +} +void ARM64XEmitter::MNEG(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EncodeData3SrcInst(1, Rd, Rn, Rm, SP); +} + +// Logical (shifted register) +void ARM64XEmitter::AND(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift) +{ + EncodeLogicalInst(0, Rd, Rn, Rm, Shift); +} +void ARM64XEmitter::BIC(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift) +{ + EncodeLogicalInst(1, Rd, Rn, Rm, Shift); +} +void ARM64XEmitter::ORR(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift) +{ + EncodeLogicalInst(2, Rd, Rn, Rm, Shift); +} +void ARM64XEmitter::ORN(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift) +{ + EncodeLogicalInst(3, Rd, Rn, Rm, Shift); +} +void ARM64XEmitter::EOR(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift) +{ + EncodeLogicalInst(4, Rd, Rn, Rm, Shift); +} +void ARM64XEmitter::EON(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift) +{ + EncodeLogicalInst(5, Rd, Rn, Rm, Shift); +} +void ARM64XEmitter::ANDS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift) +{ + EncodeLogicalInst(6, Rd, Rn, Rm, Shift); +} +void ARM64XEmitter::BICS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift) +{ + EncodeLogicalInst(7, Rd, Rn, Rm, Shift); +} + +void ARM64XEmitter::MOV(ARM64Reg Rd, ARM64Reg Rm, ArithOption Shift) +{ + ORR(Rd, Is64Bit(Rd) ? ZR : WZR, Rm, Shift); +} + +void ARM64XEmitter::MOV(ARM64Reg Rd, ARM64Reg Rm) +{ + if (IsGPR(Rd) && IsGPR(Rm)) + ORR(Rd, Is64Bit(Rd) ? ZR : WZR, Rm, ArithOption(Rm, ST_LSL, 0)); + else + ASSERT_MSG(DYNA_REC, false, "Non-GPRs not supported in MOV"); +} +void ARM64XEmitter::MVN(ARM64Reg Rd, ARM64Reg Rm) +{ + ORN(Rd, Is64Bit(Rd) ? ZR : WZR, Rm, ArithOption(Rm, ST_LSL, 0)); +} +void ARM64XEmitter::LSL(ARM64Reg Rd, ARM64Reg Rm, int shift) +{ + int bits = Is64Bit(Rd) ? 64 : 32; + UBFM(Rd, Rm, (bits - shift) & (bits - 1), bits - shift - 1); +} +void ARM64XEmitter::LSR(ARM64Reg Rd, ARM64Reg Rm, int shift) +{ + int bits = Is64Bit(Rd) ? 64 : 32; + UBFM(Rd, Rm, shift, bits - 1); +} +void ARM64XEmitter::ASR(ARM64Reg Rd, ARM64Reg Rm, int shift) +{ + int bits = Is64Bit(Rd) ? 64 : 32; + SBFM(Rd, Rm, shift, bits - 1); +} +void ARM64XEmitter::ROR_(ARM64Reg Rd, ARM64Reg Rm, int shift) +{ + EXTR(Rd, Rm, Rm, shift); +} + +// Logical (immediate) +void ARM64XEmitter::AND(ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms, bool invert) +{ + EncodeLogicalImmInst(0, Rd, Rn, immr, imms, invert); +} +void ARM64XEmitter::ANDS(ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms, bool invert) +{ + EncodeLogicalImmInst(3, Rd, Rn, immr, imms, invert); +} +void ARM64XEmitter::EOR(ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms, bool invert) +{ + EncodeLogicalImmInst(2, Rd, Rn, immr, imms, invert); +} +void ARM64XEmitter::ORR(ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms, bool invert) +{ + EncodeLogicalImmInst(1, Rd, Rn, immr, imms, invert); +} +void ARM64XEmitter::TST(ARM64Reg Rn, u32 immr, u32 imms, bool invert) +{ + EncodeLogicalImmInst(3, Is64Bit(Rn) ? ZR : WZR, Rn, immr, imms, invert); +} + +// Add/subtract (immediate) +void ARM64XEmitter::ADD(ARM64Reg Rd, ARM64Reg Rn, u32 imm, bool shift) +{ + EncodeAddSubImmInst(0, false, shift, imm, Rn, Rd); +} +void ARM64XEmitter::ADDS(ARM64Reg Rd, ARM64Reg Rn, u32 imm, bool shift) +{ + EncodeAddSubImmInst(0, true, shift, imm, Rn, Rd); +} +void ARM64XEmitter::SUB(ARM64Reg Rd, ARM64Reg Rn, u32 imm, bool shift) +{ + EncodeAddSubImmInst(1, false, shift, imm, Rn, Rd); +} +void ARM64XEmitter::SUBS(ARM64Reg Rd, ARM64Reg Rn, u32 imm, bool shift) +{ + EncodeAddSubImmInst(1, true, shift, imm, Rn, Rd); +} +void ARM64XEmitter::CMP(ARM64Reg Rn, u32 imm, bool shift) +{ + EncodeAddSubImmInst(1, true, shift, imm, Rn, Is64Bit(Rn) ? SP : WSP); +} + +// Data Processing (Immediate) +void ARM64XEmitter::MOVZ(ARM64Reg Rd, u32 imm, ShiftAmount pos) +{ + EncodeMOVWideInst(2, Rd, imm, pos); +} +void ARM64XEmitter::MOVN(ARM64Reg Rd, u32 imm, ShiftAmount pos) +{ + EncodeMOVWideInst(0, Rd, imm, pos); +} +void ARM64XEmitter::MOVK(ARM64Reg Rd, u32 imm, ShiftAmount pos) +{ + EncodeMOVWideInst(3, Rd, imm, pos); +} + +// Bitfield move +void ARM64XEmitter::BFM(ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms) +{ + EncodeBitfieldMOVInst(1, Rd, Rn, immr, imms); +} +void ARM64XEmitter::SBFM(ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms) +{ + EncodeBitfieldMOVInst(0, Rd, Rn, immr, imms); +} +void ARM64XEmitter::UBFM(ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms) +{ + EncodeBitfieldMOVInst(2, Rd, Rn, immr, imms); +} + +void ARM64XEmitter::BFI(ARM64Reg Rd, ARM64Reg Rn, u32 lsb, u32 width) +{ + u32 size = Is64Bit(Rn) ? 64 : 32; + ASSERT_MSG(DYNA_REC, (lsb + width) <= size, + "%s passed lsb %d and width %d which is greater than the register size!", __func__, + lsb, width); + EncodeBitfieldMOVInst(1, Rd, Rn, (size - lsb) % size, width - 1); +} +void ARM64XEmitter::UBFIZ(ARM64Reg Rd, ARM64Reg Rn, u32 lsb, u32 width) +{ + u32 size = Is64Bit(Rn) ? 64 : 32; + ASSERT_MSG(DYNA_REC, (lsb + width) <= size, + "%s passed lsb %d and width %d which is greater than the register size!", __func__, + lsb, width); + EncodeBitfieldMOVInst(2, Rd, Rn, (size - lsb) % size, width - 1); +} +void ARM64XEmitter::EXTR(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, u32 shift) +{ + bool sf = Is64Bit(Rd); + bool N = sf; + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + Rm = DecodeReg(Rm); + Write32((sf << 31) | (0x27 << 23) | (N << 22) | (Rm << 16) | (shift << 10) | (Rm << 5) | Rd); +} +void ARM64XEmitter::SXTB(ARM64Reg Rd, ARM64Reg Rn) +{ + SBFM(Rd, Rn, 0, 7); +} +void ARM64XEmitter::SXTH(ARM64Reg Rd, ARM64Reg Rn) +{ + SBFM(Rd, Rn, 0, 15); +} +void ARM64XEmitter::SXTW(ARM64Reg Rd, ARM64Reg Rn) +{ + ASSERT_MSG(DYNA_REC, Is64Bit(Rd), "%s requires 64bit register as destination", __func__); + SBFM(Rd, Rn, 0, 31); +} +void ARM64XEmitter::UXTB(ARM64Reg Rd, ARM64Reg Rn) +{ + UBFM(Rd, Rn, 0, 7); +} +void ARM64XEmitter::UXTH(ARM64Reg Rd, ARM64Reg Rn) +{ + UBFM(Rd, Rn, 0, 15); +} + +// Load Register (Literal) +void ARM64XEmitter::LDR(ARM64Reg Rt, u32 imm) +{ + EncodeLoadRegisterInst(0, Rt, imm); +} +void ARM64XEmitter::LDRSW(ARM64Reg Rt, u32 imm) +{ + EncodeLoadRegisterInst(2, Rt, imm); +} +void ARM64XEmitter::PRFM(ARM64Reg Rt, u32 imm) +{ + EncodeLoadRegisterInst(3, Rt, imm); +} + +// Load/Store pair +void ARM64XEmitter::LDP(IndexType type, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn, s32 imm) +{ + EncodeLoadStorePair(0, 1, type, Rt, Rt2, Rn, imm); +} +void ARM64XEmitter::LDPSW(IndexType type, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn, s32 imm) +{ + EncodeLoadStorePair(1, 1, type, Rt, Rt2, Rn, imm); +} +void ARM64XEmitter::STP(IndexType type, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn, s32 imm) +{ + EncodeLoadStorePair(0, 0, type, Rt, Rt2, Rn, imm); +} + +// Load/Store Exclusive +void ARM64XEmitter::STXRB(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rn) +{ + EncodeLoadStoreExcInst(0, Rs, SP, Rt, Rn); +} +void ARM64XEmitter::STLXRB(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rn) +{ + EncodeLoadStoreExcInst(1, Rs, SP, Rt, Rn); +} +void ARM64XEmitter::LDXRB(ARM64Reg Rt, ARM64Reg Rn) +{ + EncodeLoadStoreExcInst(2, SP, SP, Rt, Rn); +} +void ARM64XEmitter::LDAXRB(ARM64Reg Rt, ARM64Reg Rn) +{ + EncodeLoadStoreExcInst(3, SP, SP, Rt, Rn); +} +void ARM64XEmitter::STLRB(ARM64Reg Rt, ARM64Reg Rn) +{ + EncodeLoadStoreExcInst(4, SP, SP, Rt, Rn); +} +void ARM64XEmitter::LDARB(ARM64Reg Rt, ARM64Reg Rn) +{ + EncodeLoadStoreExcInst(5, SP, SP, Rt, Rn); +} +void ARM64XEmitter::STXRH(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rn) +{ + EncodeLoadStoreExcInst(6, Rs, SP, Rt, Rn); +} +void ARM64XEmitter::STLXRH(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rn) +{ + EncodeLoadStoreExcInst(7, Rs, SP, Rt, Rn); +} +void ARM64XEmitter::LDXRH(ARM64Reg Rt, ARM64Reg Rn) +{ + EncodeLoadStoreExcInst(8, SP, SP, Rt, Rn); +} +void ARM64XEmitter::LDAXRH(ARM64Reg Rt, ARM64Reg Rn) +{ + EncodeLoadStoreExcInst(9, SP, SP, Rt, Rn); +} +void ARM64XEmitter::STLRH(ARM64Reg Rt, ARM64Reg Rn) +{ + EncodeLoadStoreExcInst(10, SP, SP, Rt, Rn); +} +void ARM64XEmitter::LDARH(ARM64Reg Rt, ARM64Reg Rn) +{ + EncodeLoadStoreExcInst(11, SP, SP, Rt, Rn); +} +void ARM64XEmitter::STXR(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rn) +{ + EncodeLoadStoreExcInst(12 + Is64Bit(Rt), Rs, SP, Rt, Rn); +} +void ARM64XEmitter::STLXR(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rn) +{ + EncodeLoadStoreExcInst(14 + Is64Bit(Rt), Rs, SP, Rt, Rn); +} +void ARM64XEmitter::STXP(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn) +{ + EncodeLoadStoreExcInst(16 + Is64Bit(Rt), Rs, Rt2, Rt, Rn); +} +void ARM64XEmitter::STLXP(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn) +{ + EncodeLoadStoreExcInst(18 + Is64Bit(Rt), Rs, Rt2, Rt, Rn); +} +void ARM64XEmitter::LDXR(ARM64Reg Rt, ARM64Reg Rn) +{ + EncodeLoadStoreExcInst(20 + Is64Bit(Rt), SP, SP, Rt, Rn); +} +void ARM64XEmitter::LDAXR(ARM64Reg Rt, ARM64Reg Rn) +{ + EncodeLoadStoreExcInst(22 + Is64Bit(Rt), SP, SP, Rt, Rn); +} +void ARM64XEmitter::LDXP(ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn) +{ + EncodeLoadStoreExcInst(24 + Is64Bit(Rt), SP, Rt2, Rt, Rn); +} +void ARM64XEmitter::LDAXP(ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn) +{ + EncodeLoadStoreExcInst(26 + Is64Bit(Rt), SP, Rt2, Rt, Rn); +} +void ARM64XEmitter::STLR(ARM64Reg Rt, ARM64Reg Rn) +{ + EncodeLoadStoreExcInst(28 + Is64Bit(Rt), SP, SP, Rt, Rn); +} +void ARM64XEmitter::LDAR(ARM64Reg Rt, ARM64Reg Rn) +{ + EncodeLoadStoreExcInst(30 + Is64Bit(Rt), SP, SP, Rt, Rn); +} + +// Load/Store no-allocate pair (offset) +void ARM64XEmitter::STNP(ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn, u32 imm) +{ + EncodeLoadStorePairedInst(0xA0, Rt, Rt2, Rn, imm); +} +void ARM64XEmitter::LDNP(ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn, u32 imm) +{ + EncodeLoadStorePairedInst(0xA1, Rt, Rt2, Rn, imm); +} + +// Load/Store register (immediate post-indexed) +// XXX: Most of these support vectors +void ARM64XEmitter::STRB(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + if (type == INDEX_UNSIGNED) + EncodeLoadStoreIndexedInst(0x0E4, Rt, Rn, imm, 8); + else + EncodeLoadStoreIndexedInst(0x0E0, type == INDEX_POST ? 1 : 3, Rt, Rn, imm); +} +void ARM64XEmitter::LDRB(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + if (type == INDEX_UNSIGNED) + EncodeLoadStoreIndexedInst(0x0E5, Rt, Rn, imm, 8); + else + EncodeLoadStoreIndexedInst(0x0E1, type == INDEX_POST ? 1 : 3, Rt, Rn, imm); +} +void ARM64XEmitter::LDRSB(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + if (type == INDEX_UNSIGNED) + EncodeLoadStoreIndexedInst(Is64Bit(Rt) ? 0x0E6 : 0x0E7, Rt, Rn, imm, 8); + else + EncodeLoadStoreIndexedInst(Is64Bit(Rt) ? 0x0E2 : 0x0E3, type == INDEX_POST ? 1 : 3, Rt, Rn, + imm); +} +void ARM64XEmitter::STRH(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + if (type == INDEX_UNSIGNED) + EncodeLoadStoreIndexedInst(0x1E4, Rt, Rn, imm, 16); + else + EncodeLoadStoreIndexedInst(0x1E0, type == INDEX_POST ? 1 : 3, Rt, Rn, imm); +} +void ARM64XEmitter::LDRH(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + if (type == INDEX_UNSIGNED) + EncodeLoadStoreIndexedInst(0x1E5, Rt, Rn, imm, 16); + else + EncodeLoadStoreIndexedInst(0x1E1, type == INDEX_POST ? 1 : 3, Rt, Rn, imm); +} +void ARM64XEmitter::LDRSH(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + if (type == INDEX_UNSIGNED) + EncodeLoadStoreIndexedInst(Is64Bit(Rt) ? 0x1E6 : 0x1E7, Rt, Rn, imm, 16); + else + EncodeLoadStoreIndexedInst(Is64Bit(Rt) ? 0x1E2 : 0x1E3, type == INDEX_POST ? 1 : 3, Rt, Rn, + imm); +} +void ARM64XEmitter::STR(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + if (type == INDEX_UNSIGNED) + EncodeLoadStoreIndexedInst(Is64Bit(Rt) ? 0x3E4 : 0x2E4, Rt, Rn, imm, Is64Bit(Rt) ? 64 : 32); + else + EncodeLoadStoreIndexedInst(Is64Bit(Rt) ? 0x3E0 : 0x2E0, type == INDEX_POST ? 1 : 3, Rt, Rn, + imm); +} +void ARM64XEmitter::LDR(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + if (type == INDEX_UNSIGNED) + EncodeLoadStoreIndexedInst(Is64Bit(Rt) ? 0x3E5 : 0x2E5, Rt, Rn, imm, Is64Bit(Rt) ? 64 : 32); + else + EncodeLoadStoreIndexedInst(Is64Bit(Rt) ? 0x3E1 : 0x2E1, type == INDEX_POST ? 1 : 3, Rt, Rn, + imm); +} +void ARM64XEmitter::LDRSW(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + if (type == INDEX_UNSIGNED) + EncodeLoadStoreIndexedInst(0x2E6, Rt, Rn, imm, 32); + else + EncodeLoadStoreIndexedInst(0x2E2, type == INDEX_POST ? 1 : 3, Rt, Rn, imm); +} + +// Load/Store register (register offset) +void ARM64XEmitter::STRB(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm) +{ + EncodeLoadStoreRegisterOffset(0, 0, Rt, Rn, Rm); +} +void ARM64XEmitter::LDRB(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm) +{ + EncodeLoadStoreRegisterOffset(0, 1, Rt, Rn, Rm); +} +void ARM64XEmitter::LDRSB(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm) +{ + bool b64Bit = Is64Bit(Rt); + EncodeLoadStoreRegisterOffset(0, 3 - b64Bit, Rt, Rn, Rm); +} +void ARM64XEmitter::STRH(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm) +{ + EncodeLoadStoreRegisterOffset(1, 0, Rt, Rn, Rm); +} +void ARM64XEmitter::LDRH(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm) +{ + EncodeLoadStoreRegisterOffset(1, 1, Rt, Rn, Rm); +} +void ARM64XEmitter::LDRSH(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm) +{ + bool b64Bit = Is64Bit(Rt); + EncodeLoadStoreRegisterOffset(1, 3 - b64Bit, Rt, Rn, Rm); +} +void ARM64XEmitter::STR(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm) +{ + bool b64Bit = Is64Bit(Rt); + EncodeLoadStoreRegisterOffset(2 + b64Bit, 0, Rt, Rn, Rm); +} +void ARM64XEmitter::LDR(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm) +{ + bool b64Bit = Is64Bit(Rt); + EncodeLoadStoreRegisterOffset(2 + b64Bit, 1, Rt, Rn, Rm); +} +void ARM64XEmitter::LDRSW(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm) +{ + EncodeLoadStoreRegisterOffset(2, 2, Rt, Rn, Rm); +} +void ARM64XEmitter::PRFM(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm) +{ + EncodeLoadStoreRegisterOffset(3, 2, Rt, Rn, Rm); +} + +// Load/Store register (unscaled offset) +void ARM64XEmitter::STURB(ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + EncodeLoadStoreUnscaled(0, 0, Rt, Rn, imm); +} +void ARM64XEmitter::LDURB(ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + EncodeLoadStoreUnscaled(0, 1, Rt, Rn, imm); +} +void ARM64XEmitter::LDURSB(ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + EncodeLoadStoreUnscaled(0, Is64Bit(Rt) ? 2 : 3, Rt, Rn, imm); +} +void ARM64XEmitter::STURH(ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + EncodeLoadStoreUnscaled(1, 0, Rt, Rn, imm); +} +void ARM64XEmitter::LDURH(ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + EncodeLoadStoreUnscaled(1, 1, Rt, Rn, imm); +} +void ARM64XEmitter::LDURSH(ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + EncodeLoadStoreUnscaled(1, Is64Bit(Rt) ? 2 : 3, Rt, Rn, imm); +} +void ARM64XEmitter::STUR(ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + EncodeLoadStoreUnscaled(Is64Bit(Rt) ? 3 : 2, 0, Rt, Rn, imm); +} +void ARM64XEmitter::LDUR(ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + EncodeLoadStoreUnscaled(Is64Bit(Rt) ? 3 : 2, 1, Rt, Rn, imm); +} +void ARM64XEmitter::LDURSW(ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + ASSERT_MSG(DYNA_REC, !Is64Bit(Rt), "%s must have a 64bit destination register!", __func__); + EncodeLoadStoreUnscaled(2, 2, Rt, Rn, imm); +} + +void ARM64XEmitter::LDRGeneric(int size, bool signExtend, ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm) +{ + switch (size | signExtend) + { + case 32: LDR (Rt, Rn, Rm); break; + case 33: LDRSW(Rt, Rn, Rm); break; + case 16: LDRH (Rt, Rn, Rm); break; + case 17: LDRSH(Rt, Rn, Rm); break; + case 8: LDRB (Rt, Rn, Rm); break; + case 9: LDRSB(Rt, Rn, Rm); break; + default: PanicAlert("LDRGeneric(reg): invalid size %d", size); break; + } +} +void ARM64XEmitter::STRGeneric(int size, ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm) +{ + switch (size) + { + case 32: STR (Rt, Rn, Rm); break; + case 16: STRH (Rt, Rn, Rm); break; + case 8: STRB (Rt, Rn, Rm); break; + default: PanicAlert("STRGeneric(reg): invalid size %d", size); break; + } +} + +void ARM64XEmitter::LDRGeneric(int size, bool signExtend, IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + switch (size | signExtend) + { + case 32: LDR (type, Rt, Rn, imm); break; + case 33: LDRSW(type, Rt, Rn, imm); break; + case 16: LDRH (type, Rt, Rn, imm); break; + case 17: LDRSH(type, Rt, Rn, imm); break; + case 8: LDRB (type, Rt, Rn, imm); break; + case 9: LDRSB(type, Rt, Rn, imm); break; + default: PanicAlert("LDRGeneric(imm): invalid size %d", size); break; + } +} +void ARM64XEmitter::STRGeneric(int size, IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + switch (size) + { + case 32: STR (type, Rt, Rn, imm); break; + case 16: STRH (type, Rt, Rn, imm); break; + case 8: STRB (type, Rt, Rn, imm); break; + default: PanicAlert("STRGeneric(imm): invalid size %d", size); break; + } +} + +// Address of label/page PC-relative +void ARM64XEmitter::ADR(ARM64Reg Rd, s32 imm) +{ + EncodeAddressInst(0, Rd, imm); +} +void ARM64XEmitter::ADRP(ARM64Reg Rd, s32 imm) +{ + EncodeAddressInst(1, Rd, imm >> 12); +} + +// Wrapper around MOVZ+MOVK (and later MOVN) +void ARM64XEmitter::MOVI2R(ARM64Reg Rd, u64 imm, bool optimize) +{ + unsigned int parts = Is64Bit(Rd) ? 4 : 2; + BitSet32 upload_part(0); + + // Always start with a movz! Kills the dependency on the register. + bool use_movz = true; + + if (!imm) + { + // Zero immediate, just clear the register. EOR is pointless when we have MOVZ, which looks + // clearer in disasm too. + MOVZ(Rd, 0, SHIFT_0); + return; + } + + if ((Is64Bit(Rd) && imm == std::numeric_limits::max()) || + (!Is64Bit(Rd) && imm == std::numeric_limits::max())) + { + // Max unsigned value (or if signed, -1) + // Set to ~ZR + ARM64Reg ZR = Is64Bit(Rd) ? SP : WSP; + ORN(Rd, ZR, ZR, ArithOption(ZR, ST_LSL, 0)); + return; + } + + // TODO: Make some more systemic use of MOVN, but this will take care of most cases. + // Small negative integer. Use MOVN + if (!Is64Bit(Rd) && (imm | 0xFFFF0000) == imm) + { + MOVN(Rd, ~imm, SHIFT_0); + return; + } + + // XXX: Use MOVN when possible. + // XXX: Optimize more + // XXX: Support rotating immediates to save instructions + if (optimize) + { + for (unsigned int i = 0; i < parts; ++i) + { + if ((imm >> (i * 16)) & 0xFFFF) + upload_part[i] = 1; + } + } + + u64 aligned_pc = (u64)(m_rxbase + m_code) & ~0xFFF; +s64 aligned_offset = (s64)imm - (s64)aligned_pc; + // The offset for ADR/ADRP is an s32, so make sure it can be represented in that + if (upload_part.Count() > 1 && std::abs(aligned_offset) < 0x7FFFFFFFLL) + { + // Immediate we are loading is within 4GB of our aligned range + // Most likely a address that we can load in one or two instructions + if (!(std::abs(aligned_offset) & 0xFFF)) + { + // Aligned ADR + ADRP(Rd, (s32)aligned_offset); + return; + } + else + { + // If the address is within 1MB of PC we can load it in a single instruction still + s64 offset = (s64)imm - (s64)(m_rxbase + m_code); + if (offset >= -0xFFFFF && offset <= 0xFFFFF) + { + ADR(Rd, (s32)offset); + return; + } + else + { + ADRP(Rd, (s32)(aligned_offset & ~0xFFF)); + ADD(Rd, Rd, imm & 0xFFF); + return; + } + } + } + + for (unsigned i = 0; i < parts; ++i) + { + if (use_movz && upload_part[i]) + { + MOVZ(Rd, (imm >> (i * 16)) & 0xFFFF, (ShiftAmount)i); + use_movz = false; + } + else + { + if (upload_part[i] || !optimize) + MOVK(Rd, (imm >> (i * 16)) & 0xFFFF, (ShiftAmount)i); + } + } +} + +bool ARM64XEmitter::MOVI2R2(ARM64Reg Rd, u64 imm1, u64 imm2) +{ + // TODO: Also optimize for performance, not just for code size. + ptrdiff_t start_offset = GetCodeOffset(); + + MOVI2R(Rd, imm1); + int size1 = GetCodeOffset() - start_offset; + + SetCodePtrUnsafe(start_offset); + + MOVI2R(Rd, imm2); + int size2 = GetCodeOffset() - start_offset; + + SetCodePtrUnsafe(start_offset); + + bool element = size1 > size2; + + MOVI2R(Rd, element ? imm2 : imm1); + + return element; +} + +void ARM64XEmitter::ABI_PushRegisters(BitSet32 registers) +{ + int num_regs = registers.Count(); + int stack_size = (num_regs + (num_regs & 1)) * 8; + auto it = registers.begin(); + + if (!num_regs) + return; + + // 8 byte per register, but 16 byte alignment, so we may have to padd one register. + // Only update the SP on the last write to avoid the dependency between those stores. + + // The first push must adjust the SP, else a context switch may invalidate everything below SP. + if (num_regs & 1) + { + STR(INDEX_PRE, (ARM64Reg)(X0 + *it++), SP, -stack_size); + } + else + { + ARM64Reg first_reg = (ARM64Reg)(X0 + *it++); + ARM64Reg second_reg = (ARM64Reg)(X0 + *it++); + STP(INDEX_PRE, first_reg, second_reg, SP, -stack_size); + } + + // Fast store for all other registers, this is always an even number. + for (int i = 0; i < (num_regs - 1) / 2; i++) + { + ARM64Reg odd_reg = (ARM64Reg)(X0 + *it++); + ARM64Reg even_reg = (ARM64Reg)(X0 + *it++); + STP(INDEX_SIGNED, odd_reg, even_reg, SP, 16 * (i + 1)); + } + + ASSERT_MSG(DYNA_REC, it == registers.end(), "%s registers don't match.", __func__); +} + +void ARM64XEmitter::ABI_PopRegisters(BitSet32 registers, BitSet32 ignore_mask) +{ + int num_regs = registers.Count(); + int stack_size = (num_regs + (num_regs & 1)) * 8; + auto it = registers.begin(); + + if (!num_regs) + return; + + // We must adjust the SP in the end, so load the first (two) registers at least. + ARM64Reg first = (ARM64Reg)(X0 + *it++); + ARM64Reg second; + if (!(num_regs & 1)) + second = (ARM64Reg)(X0 + *it++); + + // 8 byte per register, but 16 byte alignment, so we may have to padd one register. + // Only update the SP on the last load to avoid the dependency between those loads. + + // Fast load for all but the first (two) registers, this is always an even number. + for (int i = 0; i < (num_regs - 1) / 2; i++) + { + ARM64Reg odd_reg = (ARM64Reg)(X0 + *it++); + ARM64Reg even_reg = (ARM64Reg)(X0 + *it++); + LDP(INDEX_SIGNED, odd_reg, even_reg, SP, 16 * (i + 1)); + } + + // Post loading the first (two) registers. + if (num_regs & 1) + LDR(INDEX_POST, first, SP, stack_size); + else + LDP(INDEX_POST, first, second, SP, stack_size); + + ASSERT_MSG(DYNA_REC, it == registers.end(), "%s registers don't match.", __func__); +} + +// Float Emitter +void ARM64FloatEmitter::EmitLoadStoreImmediate(u8 size, u32 opc, IndexType type, ARM64Reg Rt, + ARM64Reg Rn, s32 imm) +{ + Rt = DecodeReg(Rt); + Rn = DecodeReg(Rn); + u32 encoded_size = 0; + u32 encoded_imm = 0; + + if (size == 8) + encoded_size = 0; + else if (size == 16) + encoded_size = 1; + else if (size == 32) + encoded_size = 2; + else if (size == 64) + encoded_size = 3; + else if (size == 128) + encoded_size = 0; + + if (type == INDEX_UNSIGNED) + { + ASSERT_MSG(DYNA_REC, !(imm & ((size - 1) >> 3)), + "%s(INDEX_UNSIGNED) immediate offset must be aligned to size! (%d) (%p)", __func__, + imm, m_emit->GetCodePtr()); + ASSERT_MSG(DYNA_REC, imm >= 0, "%s(INDEX_UNSIGNED) immediate offset must be positive!", + __func__); + if (size == 16) + imm >>= 1; + else if (size == 32) + imm >>= 2; + else if (size == 64) + imm >>= 3; + else if (size == 128) + imm >>= 4; + encoded_imm = (imm & 0xFFF); + } + else + { + ASSERT_MSG(DYNA_REC, !(imm < -256 || imm > 255), + "%s immediate offset must be within range of -256 to 256!", __func__); + encoded_imm = (imm & 0x1FF) << 2; + if (type == INDEX_POST) + encoded_imm |= 1; + else + encoded_imm |= 3; + } + + Write32((encoded_size << 30) | (0xF << 26) | (type == INDEX_UNSIGNED ? (1 << 24) : 0) | + (size == 128 ? (1 << 23) : 0) | (opc << 22) | (encoded_imm << 10) | (Rn << 5) | Rt); +} + +void ARM64FloatEmitter::EmitScalar2Source(bool M, bool S, u32 type, u32 opcode, ARM64Reg Rd, + ARM64Reg Rn, ARM64Reg Rm) +{ + ASSERT_MSG(DYNA_REC, !IsQuad(Rd), "%s only supports double and single registers!", __func__); + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + Rm = DecodeReg(Rm); + + Write32((M << 31) | (S << 29) | (0b11110001 << 21) | (type << 22) | (Rm << 16) | (opcode << 12) | + (1 << 11) | (Rn << 5) | Rd); +} + +void ARM64FloatEmitter::EmitThreeSame(bool U, u32 size, u32 opcode, ARM64Reg Rd, ARM64Reg Rn, + ARM64Reg Rm) +{ + ASSERT_MSG(DYNA_REC, !IsSingle(Rd), "%s doesn't support singles!", __func__); + bool quad = IsQuad(Rd); + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + Rm = DecodeReg(Rm); + + Write32((quad << 30) | (U << 29) | (0b1110001 << 21) | (size << 22) | (Rm << 16) | + (opcode << 11) | (1 << 10) | (Rn << 5) | Rd); +} + +void ARM64FloatEmitter::EmitCopy(bool Q, u32 op, u32 imm5, u32 imm4, ARM64Reg Rd, ARM64Reg Rn) +{ + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + + Write32((Q << 30) | (op << 29) | (0b111 << 25) | (imm5 << 16) | (imm4 << 11) | (1 << 10) | + (Rn << 5) | Rd); +} + +void ARM64FloatEmitter::Emit2RegMisc(bool Q, bool U, u32 size, u32 opcode, ARM64Reg Rd, ARM64Reg Rn) +{ + ASSERT_MSG(DYNA_REC, !IsSingle(Rd), "%s doesn't support singles!", __func__); + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + + Write32((Q << 30) | (U << 29) | (0b1110001 << 21) | (size << 22) | (opcode << 12) | (1 << 11) | + (Rn << 5) | Rd); +} + +void ARM64FloatEmitter::EmitLoadStoreSingleStructure(bool L, bool R, u32 opcode, bool S, u32 size, + ARM64Reg Rt, ARM64Reg Rn) +{ + ASSERT_MSG(DYNA_REC, !IsSingle(Rt), "%s doesn't support singles!", __func__); + bool quad = IsQuad(Rt); + Rt = DecodeReg(Rt); + Rn = DecodeReg(Rn); + + Write32((quad << 30) | (0b1101 << 24) | (L << 22) | (R << 21) | (opcode << 13) | (S << 12) | + (size << 10) | (Rn << 5) | Rt); +} + +void ARM64FloatEmitter::EmitLoadStoreSingleStructure(bool L, bool R, u32 opcode, bool S, u32 size, + ARM64Reg Rt, ARM64Reg Rn, ARM64Reg Rm) +{ + ASSERT_MSG(DYNA_REC, !IsSingle(Rt), "%s doesn't support singles!", __func__); + bool quad = IsQuad(Rt); + Rt = DecodeReg(Rt); + Rn = DecodeReg(Rn); + Rm = DecodeReg(Rm); + + Write32((quad << 30) | (0x1B << 23) | (L << 22) | (R << 21) | (Rm << 16) | (opcode << 13) | + (S << 12) | (size << 10) | (Rn << 5) | Rt); +} + +void ARM64FloatEmitter::Emit1Source(bool M, bool S, u32 type, u32 opcode, ARM64Reg Rd, ARM64Reg Rn) +{ + ASSERT_MSG(DYNA_REC, !IsQuad(Rd), "%s doesn't support vector!", __func__); + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + + Write32((M << 31) | (S << 29) | (0xF1 << 21) | (type << 22) | (opcode << 15) | (1 << 14) | + (Rn << 5) | Rd); +} + +void ARM64FloatEmitter::EmitConversion(bool sf, bool S, u32 type, u32 rmode, u32 opcode, + ARM64Reg Rd, ARM64Reg Rn) +{ + ASSERT_MSG(DYNA_REC, Rn <= SP, "%s only supports GPR as source!", __func__); + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + + Write32((sf << 31) | (S << 29) | (0xF1 << 21) | (type << 22) | (rmode << 19) | (opcode << 16) | + (Rn << 5) | Rd); +} + +void ARM64FloatEmitter::EmitConvertScalarToInt(ARM64Reg Rd, ARM64Reg Rn, RoundingMode round, + bool sign) +{ + DEBUG_ASSERT_MSG(DYNA_REC, IsScalar(Rn), "fcvts: Rn must be floating point"); + if (IsGPR(Rd)) + { + // Use the encoding that transfers the result to a GPR. + bool sf = Is64Bit(Rd); + int type = IsDouble(Rn) ? 1 : 0; + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + int opcode = (sign ? 1 : 0); + int rmode = 0; + switch (round) + { + case ROUND_A: + rmode = 0; + opcode |= 4; + break; + case ROUND_P: + rmode = 1; + break; + case ROUND_M: + rmode = 2; + break; + case ROUND_Z: + rmode = 3; + break; + case ROUND_N: + rmode = 0; + break; + } + EmitConversion2(sf, 0, true, type, rmode, opcode, 0, Rd, Rn); + } + else + { + // Use the encoding (vector, single) that keeps the result in the fp register. + int sz = IsDouble(Rn); + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + int opcode = 0; + switch (round) + { + case ROUND_A: + opcode = 0x1C; + break; + case ROUND_N: + opcode = 0x1A; + break; + case ROUND_M: + opcode = 0x1B; + break; + case ROUND_P: + opcode = 0x1A; + sz |= 2; + break; + case ROUND_Z: + opcode = 0x1B; + sz |= 2; + break; + } + Write32((0x5E << 24) | (sign << 29) | (sz << 22) | (1 << 21) | (opcode << 12) | (2 << 10) | + (Rn << 5) | Rd); + } +} + +void ARM64FloatEmitter::FCVTS(ARM64Reg Rd, ARM64Reg Rn, RoundingMode round) +{ + EmitConvertScalarToInt(Rd, Rn, round, false); +} + +void ARM64FloatEmitter::FCVTU(ARM64Reg Rd, ARM64Reg Rn, RoundingMode round) +{ + EmitConvertScalarToInt(Rd, Rn, round, true); +} + +void ARM64FloatEmitter::EmitConversion2(bool sf, bool S, bool direction, u32 type, u32 rmode, + u32 opcode, int scale, ARM64Reg Rd, ARM64Reg Rn) +{ + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + + Write32((sf << 31) | (S << 29) | (0xF0 << 21) | (direction << 21) | (type << 22) | (rmode << 19) | + (opcode << 16) | (scale << 10) | (Rn << 5) | Rd); +} + +void ARM64FloatEmitter::EmitCompare(bool M, bool S, u32 op, u32 opcode2, ARM64Reg Rn, ARM64Reg Rm) +{ + ASSERT_MSG(DYNA_REC, !IsQuad(Rn), "%s doesn't support vector!", __func__); + bool is_double = IsDouble(Rn); + + Rn = DecodeReg(Rn); + Rm = DecodeReg(Rm); + + Write32((M << 31) | (S << 29) | (0xF1 << 21) | (is_double << 22) | (Rm << 16) | (op << 14) | + (1 << 13) | (Rn << 5) | opcode2); +} + +void ARM64FloatEmitter::EmitCondSelect(bool M, bool S, CCFlags cond, ARM64Reg Rd, ARM64Reg Rn, + ARM64Reg Rm) +{ + ASSERT_MSG(DYNA_REC, !IsQuad(Rd), "%s doesn't support vector!", __func__); + bool is_double = IsDouble(Rd); + + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + Rm = DecodeReg(Rm); + + Write32((M << 31) | (S << 29) | (0xF1 << 21) | (is_double << 22) | (Rm << 16) | (cond << 12) | + (3 << 10) | (Rn << 5) | Rd); +} + +void ARM64FloatEmitter::EmitPermute(u32 size, u32 op, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + ASSERT_MSG(DYNA_REC, !IsSingle(Rd), "%s doesn't support singles!", __func__); + + bool quad = IsQuad(Rd); + + u32 encoded_size = 0; + if (size == 16) + encoded_size = 1; + else if (size == 32) + encoded_size = 2; + else if (size == 64) + encoded_size = 3; + + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + Rm = DecodeReg(Rm); + + Write32((quad << 30) | (7 << 25) | (encoded_size << 22) | (Rm << 16) | (op << 12) | (1 << 11) | + (Rn << 5) | Rd); +} + +void ARM64FloatEmitter::EmitScalarImm(bool M, bool S, u32 type, u32 imm5, ARM64Reg Rd, u32 imm8) +{ + ASSERT_MSG(DYNA_REC, !IsQuad(Rd), "%s doesn't support vector!", __func__); + + bool is_double = !IsSingle(Rd); + + Rd = DecodeReg(Rd); + + Write32((M << 31) | (S << 29) | (0xF1 << 21) | (is_double << 22) | (type << 22) | (imm8 << 13) | + (1 << 12) | (imm5 << 5) | Rd); +} + +void ARM64FloatEmitter::EmitShiftImm(bool Q, bool U, u32 immh, u32 immb, u32 opcode, ARM64Reg Rd, + ARM64Reg Rn) +{ + ASSERT_MSG(DYNA_REC, immh, "%s bad encoding! Can't have zero immh", __func__); + + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + + Write32((Q << 30) | (U << 29) | (0xF << 24) | (immh << 19) | (immb << 16) | (opcode << 11) | + (1 << 10) | (Rn << 5) | Rd); +} + +void ARM64FloatEmitter::EmitScalarShiftImm(bool U, u32 immh, u32 immb, u32 opcode, ARM64Reg Rd, + ARM64Reg Rn) +{ + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + + Write32((2 << 30) | (U << 29) | (0x3E << 23) | (immh << 19) | (immb << 16) | (opcode << 11) | + (1 << 10) | (Rn << 5) | Rd); +} + +void ARM64FloatEmitter::EmitLoadStoreMultipleStructure(u32 size, bool L, u32 opcode, ARM64Reg Rt, + ARM64Reg Rn) +{ + bool quad = IsQuad(Rt); + u32 encoded_size = 0; + + if (size == 16) + encoded_size = 1; + else if (size == 32) + encoded_size = 2; + else if (size == 64) + encoded_size = 3; + + Rt = DecodeReg(Rt); + Rn = DecodeReg(Rn); + + Write32((quad << 30) | (3 << 26) | (L << 22) | (opcode << 12) | (encoded_size << 10) | (Rn << 5) | + Rt); +} + +void ARM64FloatEmitter::EmitLoadStoreMultipleStructurePost(u32 size, bool L, u32 opcode, + ARM64Reg Rt, ARM64Reg Rn, ARM64Reg Rm) +{ + bool quad = IsQuad(Rt); + u32 encoded_size = 0; + + if (size == 16) + encoded_size = 1; + else if (size == 32) + encoded_size = 2; + else if (size == 64) + encoded_size = 3; + + Rt = DecodeReg(Rt); + Rn = DecodeReg(Rn); + Rm = DecodeReg(Rm); + + Write32((quad << 30) | (0b11001 << 23) | (L << 22) | (Rm << 16) | (opcode << 12) | + (encoded_size << 10) | (Rn << 5) | Rt); +} + +void ARM64FloatEmitter::EmitScalar1Source(bool M, bool S, u32 type, u32 opcode, ARM64Reg Rd, + ARM64Reg Rn) +{ + ASSERT_MSG(DYNA_REC, !IsQuad(Rd), "%s doesn't support vector!", __func__); + + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + + Write32((M << 31) | (S << 29) | (0xF1 << 21) | (type << 22) | (opcode << 15) | (1 << 14) | + (Rn << 5) | Rd); +} + +void ARM64FloatEmitter::EmitVectorxElement(bool U, u32 size, bool L, u32 opcode, bool H, + ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + bool quad = IsQuad(Rd); + + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + Rm = DecodeReg(Rm); + + Write32((quad << 30) | (U << 29) | (0xF << 24) | (size << 22) | (L << 21) | (Rm << 16) | + (opcode << 12) | (H << 11) | (Rn << 5) | Rd); +} + +void ARM64FloatEmitter::EmitLoadStoreUnscaled(u32 size, u32 op, ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + ASSERT_MSG(DYNA_REC, !(imm < -256 || imm > 255), "%s received too large offset: %d", __func__, + imm); + Rt = DecodeReg(Rt); + Rn = DecodeReg(Rn); + + Write32((size << 30) | (0xF << 26) | (op << 22) | ((imm & 0x1FF) << 12) | (Rn << 5) | Rt); +} + +void ARM64FloatEmitter::EncodeLoadStorePair(u32 size, bool load, IndexType type, ARM64Reg Rt, + ARM64Reg Rt2, ARM64Reg Rn, s32 imm) +{ + u32 type_encode = 0; + u32 opc = 0; + + switch (type) + { + case INDEX_SIGNED: + type_encode = 0b010; + break; + case INDEX_POST: + type_encode = 0b001; + break; + case INDEX_PRE: + type_encode = 0b011; + break; + case INDEX_UNSIGNED: + ASSERT_MSG(DYNA_REC, false, "%s doesn't support INDEX_UNSIGNED!", __func__); + break; + } + + if (size == 128) + { + ASSERT_MSG(DYNA_REC, !(imm & 0xF), "%s received invalid offset 0x%x!", __func__, imm); + opc = 2; + imm >>= 4; + } + else if (size == 64) + { + ASSERT_MSG(DYNA_REC, !(imm & 0x7), "%s received invalid offset 0x%x!", __func__, imm); + opc = 1; + imm >>= 3; + } + else if (size == 32) + { + ASSERT_MSG(DYNA_REC, !(imm & 0x3), "%s received invalid offset 0x%x!", __func__, imm); + opc = 0; + imm >>= 2; + } + + Rt = DecodeReg(Rt); + Rt2 = DecodeReg(Rt2); + Rn = DecodeReg(Rn); + + Write32((opc << 30) | (0b1011 << 26) | (type_encode << 23) | (load << 22) | ((imm & 0x7F) << 15) | + (Rt2 << 10) | (Rn << 5) | Rt); +} + +void ARM64FloatEmitter::EncodeLoadStoreRegisterOffset(u32 size, bool load, ARM64Reg Rt, ARM64Reg Rn, + ArithOption Rm) +{ + ASSERT_MSG(DYNA_REC, Rm.GetType() == ArithOption::TYPE_EXTENDEDREG, + "%s must contain an extended reg as Rm!", __func__); + + u32 encoded_size = 0; + u32 encoded_op = 0; + + if (size == 8) + { + encoded_size = 0; + encoded_op = 0; + } + else if (size == 16) + { + encoded_size = 1; + encoded_op = 0; + } + else if (size == 32) + { + encoded_size = 2; + encoded_op = 0; + } + else if (size == 64) + { + encoded_size = 3; + encoded_op = 0; + } + else if (size == 128) + { + encoded_size = 0; + encoded_op = 2; + } + + if (load) + encoded_op |= 1; + + Rt = DecodeReg(Rt); + Rn = DecodeReg(Rn); + ARM64Reg decoded_Rm = DecodeReg(Rm.GetReg()); + + Write32((encoded_size << 30) | (encoded_op << 22) | (0b111100001 << 21) | (decoded_Rm << 16) | + Rm.GetData() | (1 << 11) | (Rn << 5) | Rt); +} + +void ARM64FloatEmitter::EncodeModImm(bool Q, u8 op, u8 cmode, u8 o2, ARM64Reg Rd, u8 abcdefgh) +{ + union + { + u8 hex; + struct + { + unsigned defgh : 5; + unsigned abc : 3; + }; + } v; + v.hex = abcdefgh; + Rd = DecodeReg(Rd); + Write32((Q << 30) | (op << 29) | (0xF << 24) | (v.abc << 16) | (cmode << 12) | (o2 << 11) | + (1 << 10) | (v.defgh << 5) | Rd); +} + +void ARM64FloatEmitter::LDR(u8 size, IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + EmitLoadStoreImmediate(size, 1, type, Rt, Rn, imm); +} +void ARM64FloatEmitter::STR(u8 size, IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + EmitLoadStoreImmediate(size, 0, type, Rt, Rn, imm); +} + +// Loadstore unscaled +void ARM64FloatEmitter::LDUR(u8 size, ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + u32 encoded_size = 0; + u32 encoded_op = 0; + + if (size == 8) + { + encoded_size = 0; + encoded_op = 1; + } + else if (size == 16) + { + encoded_size = 1; + encoded_op = 1; + } + else if (size == 32) + { + encoded_size = 2; + encoded_op = 1; + } + else if (size == 64) + { + encoded_size = 3; + encoded_op = 1; + } + else if (size == 128) + { + encoded_size = 0; + encoded_op = 3; + } + + EmitLoadStoreUnscaled(encoded_size, encoded_op, Rt, Rn, imm); +} +void ARM64FloatEmitter::STUR(u8 size, ARM64Reg Rt, ARM64Reg Rn, s32 imm) +{ + u32 encoded_size = 0; + u32 encoded_op = 0; + + if (size == 8) + { + encoded_size = 0; + encoded_op = 0; + } + else if (size == 16) + { + encoded_size = 1; + encoded_op = 0; + } + else if (size == 32) + { + encoded_size = 2; + encoded_op = 0; + } + else if (size == 64) + { + encoded_size = 3; + encoded_op = 0; + } + else if (size == 128) + { + encoded_size = 0; + encoded_op = 2; + } + + EmitLoadStoreUnscaled(encoded_size, encoded_op, Rt, Rn, imm); +} + +// Loadstore single structure +void ARM64FloatEmitter::LD1(u8 size, ARM64Reg Rt, u8 index, ARM64Reg Rn) +{ + bool S = 0; + u32 opcode = 0; + u32 encoded_size = 0; + ARM64Reg encoded_reg = INVALID_REG; + + if (size == 8) + { + S = (index & 4) != 0; + opcode = 0; + encoded_size = index & 3; + if (index & 8) + encoded_reg = EncodeRegToQuad(Rt); + else + encoded_reg = EncodeRegToDouble(Rt); + } + else if (size == 16) + { + S = (index & 2) != 0; + opcode = 2; + encoded_size = (index & 1) << 1; + if (index & 4) + encoded_reg = EncodeRegToQuad(Rt); + else + encoded_reg = EncodeRegToDouble(Rt); + } + else if (size == 32) + { + S = (index & 1) != 0; + opcode = 4; + encoded_size = 0; + if (index & 2) + encoded_reg = EncodeRegToQuad(Rt); + else + encoded_reg = EncodeRegToDouble(Rt); + } + else if (size == 64) + { + S = 0; + opcode = 4; + encoded_size = 1; + if (index == 1) + encoded_reg = EncodeRegToQuad(Rt); + else + encoded_reg = EncodeRegToDouble(Rt); + } + + EmitLoadStoreSingleStructure(1, 0, opcode, S, encoded_size, encoded_reg, Rn); +} + +void ARM64FloatEmitter::LD1(u8 size, ARM64Reg Rt, u8 index, ARM64Reg Rn, ARM64Reg Rm) +{ + bool S = 0; + u32 opcode = 0; + u32 encoded_size = 0; + ARM64Reg encoded_reg = INVALID_REG; + + if (size == 8) + { + S = (index & 4) != 0; + opcode = 0; + encoded_size = index & 3; + if (index & 8) + encoded_reg = EncodeRegToQuad(Rt); + else + encoded_reg = EncodeRegToDouble(Rt); + } + else if (size == 16) + { + S = (index & 2) != 0; + opcode = 2; + encoded_size = (index & 1) << 1; + if (index & 4) + encoded_reg = EncodeRegToQuad(Rt); + else + encoded_reg = EncodeRegToDouble(Rt); + } + else if (size == 32) + { + S = (index & 1) != 0; + opcode = 4; + encoded_size = 0; + if (index & 2) + encoded_reg = EncodeRegToQuad(Rt); + else + encoded_reg = EncodeRegToDouble(Rt); + } + else if (size == 64) + { + S = 0; + opcode = 4; + encoded_size = 1; + if (index == 1) + encoded_reg = EncodeRegToQuad(Rt); + else + encoded_reg = EncodeRegToDouble(Rt); + } + + EmitLoadStoreSingleStructure(1, 0, opcode, S, encoded_size, encoded_reg, Rn, Rm); +} + +void ARM64FloatEmitter::LD1R(u8 size, ARM64Reg Rt, ARM64Reg Rn) +{ + EmitLoadStoreSingleStructure(1, 0, 6, 0, size >> 4, Rt, Rn); +} +void ARM64FloatEmitter::LD2R(u8 size, ARM64Reg Rt, ARM64Reg Rn) +{ + EmitLoadStoreSingleStructure(1, 1, 6, 0, size >> 4, Rt, Rn); +} +void ARM64FloatEmitter::LD1R(u8 size, ARM64Reg Rt, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitLoadStoreSingleStructure(1, 0, 6, 0, size >> 4, Rt, Rn, Rm); +} +void ARM64FloatEmitter::LD2R(u8 size, ARM64Reg Rt, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitLoadStoreSingleStructure(1, 1, 6, 0, size >> 4, Rt, Rn, Rm); +} + +void ARM64FloatEmitter::ST1(u8 size, ARM64Reg Rt, u8 index, ARM64Reg Rn) +{ + bool S = 0; + u32 opcode = 0; + u32 encoded_size = 0; + ARM64Reg encoded_reg = INVALID_REG; + + if (size == 8) + { + S = (index & 4) != 0; + opcode = 0; + encoded_size = index & 3; + if (index & 8) + encoded_reg = EncodeRegToQuad(Rt); + else + encoded_reg = EncodeRegToDouble(Rt); + } + else if (size == 16) + { + S = (index & 2) != 0; + opcode = 2; + encoded_size = (index & 1) << 1; + if (index & 4) + encoded_reg = EncodeRegToQuad(Rt); + else + encoded_reg = EncodeRegToDouble(Rt); + } + else if (size == 32) + { + S = (index & 1) != 0; + opcode = 4; + encoded_size = 0; + if (index & 2) + encoded_reg = EncodeRegToQuad(Rt); + else + encoded_reg = EncodeRegToDouble(Rt); + } + else if (size == 64) + { + S = 0; + opcode = 4; + encoded_size = 1; + if (index == 1) + encoded_reg = EncodeRegToQuad(Rt); + else + encoded_reg = EncodeRegToDouble(Rt); + } + + EmitLoadStoreSingleStructure(0, 0, opcode, S, encoded_size, encoded_reg, Rn); +} + +void ARM64FloatEmitter::ST1(u8 size, ARM64Reg Rt, u8 index, ARM64Reg Rn, ARM64Reg Rm) +{ + bool S = 0; + u32 opcode = 0; + u32 encoded_size = 0; + ARM64Reg encoded_reg = INVALID_REG; + + if (size == 8) + { + S = (index & 4) != 0; + opcode = 0; + encoded_size = index & 3; + if (index & 8) + encoded_reg = EncodeRegToQuad(Rt); + else + encoded_reg = EncodeRegToDouble(Rt); + } + else if (size == 16) + { + S = (index & 2) != 0; + opcode = 2; + encoded_size = (index & 1) << 1; + if (index & 4) + encoded_reg = EncodeRegToQuad(Rt); + else + encoded_reg = EncodeRegToDouble(Rt); + } + else if (size == 32) + { + S = (index & 1) != 0; + opcode = 4; + encoded_size = 0; + if (index & 2) + encoded_reg = EncodeRegToQuad(Rt); + else + encoded_reg = EncodeRegToDouble(Rt); + } + else if (size == 64) + { + S = 0; + opcode = 4; + encoded_size = 1; + if (index == 1) + encoded_reg = EncodeRegToQuad(Rt); + else + encoded_reg = EncodeRegToDouble(Rt); + } + + EmitLoadStoreSingleStructure(0, 0, opcode, S, encoded_size, encoded_reg, Rn, Rm); +} + +// Loadstore multiple structure +void ARM64FloatEmitter::LD1(u8 size, u8 count, ARM64Reg Rt, ARM64Reg Rn) +{ + ASSERT_MSG(DYNA_REC, !(count == 0 || count > 4), "%s must have a count of 1 to 4 registers!", + __func__); + u32 opcode = 0; + if (count == 1) + opcode = 0b111; + else if (count == 2) + opcode = 0b1010; + else if (count == 3) + opcode = 0b0110; + else if (count == 4) + opcode = 0b0010; + EmitLoadStoreMultipleStructure(size, 1, opcode, Rt, Rn); +} +void ARM64FloatEmitter::LD1(u8 size, u8 count, IndexType type, ARM64Reg Rt, ARM64Reg Rn, + ARM64Reg Rm) +{ + ASSERT_MSG(DYNA_REC, !(count == 0 || count > 4), "%s must have a count of 1 to 4 registers!", + __func__); + ASSERT_MSG(DYNA_REC, type == INDEX_POST, "%s only supports post indexing!", __func__); + + u32 opcode = 0; + if (count == 1) + opcode = 0b111; + else if (count == 2) + opcode = 0b1010; + else if (count == 3) + opcode = 0b0110; + else if (count == 4) + opcode = 0b0010; + EmitLoadStoreMultipleStructurePost(size, 1, opcode, Rt, Rn, Rm); +} +void ARM64FloatEmitter::ST1(u8 size, u8 count, ARM64Reg Rt, ARM64Reg Rn) +{ + ASSERT_MSG(DYNA_REC, !(count == 0 || count > 4), "%s must have a count of 1 to 4 registers!", + __func__); + u32 opcode = 0; + if (count == 1) + opcode = 0b111; + else if (count == 2) + opcode = 0b1010; + else if (count == 3) + opcode = 0b0110; + else if (count == 4) + opcode = 0b0010; + EmitLoadStoreMultipleStructure(size, 0, opcode, Rt, Rn); +} +void ARM64FloatEmitter::ST1(u8 size, u8 count, IndexType type, ARM64Reg Rt, ARM64Reg Rn, + ARM64Reg Rm) +{ + ASSERT_MSG(DYNA_REC, !(count == 0 || count > 4), "%s must have a count of 1 to 4 registers!", + __func__); + ASSERT_MSG(DYNA_REC, type == INDEX_POST, "%s only supports post indexing!", __func__); + + u32 opcode = 0; + if (count == 1) + opcode = 0b111; + else if (count == 2) + opcode = 0b1010; + else if (count == 3) + opcode = 0b0110; + else if (count == 4) + opcode = 0b0010; + EmitLoadStoreMultipleStructurePost(size, 0, opcode, Rt, Rn, Rm); +} + +// Scalar - 1 Source +void ARM64FloatEmitter::FMOV(ARM64Reg Rd, ARM64Reg Rn, bool top) +{ + if (IsScalar(Rd) && IsScalar(Rn)) + { + EmitScalar1Source(0, 0, IsDouble(Rd), 0, Rd, Rn); + } + else + { + ASSERT_MSG(DYNA_REC, !IsQuad(Rd) && !IsQuad(Rn), "FMOV can't move to/from quads"); + int rmode = 0; + int opcode = 6; + int sf = 0; + if (IsSingle(Rd) && !Is64Bit(Rn) && !top) + { + // GPR to scalar single + opcode |= 1; + } + else if (!Is64Bit(Rd) && IsSingle(Rn) && !top) + { + // Scalar single to GPR - defaults are correct + } + else + { + // TODO + ASSERT_MSG(DYNA_REC, 0, "FMOV: Unhandled case"); + } + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + Write32((sf << 31) | (0x1e2 << 20) | (rmode << 19) | (opcode << 16) | (Rn << 5) | Rd); + } +} + +// Loadstore paired +void ARM64FloatEmitter::LDP(u8 size, IndexType type, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn, + s32 imm) +{ + EncodeLoadStorePair(size, true, type, Rt, Rt2, Rn, imm); +} +void ARM64FloatEmitter::STP(u8 size, IndexType type, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn, + s32 imm) +{ + EncodeLoadStorePair(size, false, type, Rt, Rt2, Rn, imm); +} + +// Loadstore register offset +void ARM64FloatEmitter::STR(u8 size, ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm) +{ + EncodeLoadStoreRegisterOffset(size, false, Rt, Rn, Rm); +} +void ARM64FloatEmitter::LDR(u8 size, ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm) +{ + EncodeLoadStoreRegisterOffset(size, true, Rt, Rn, Rm); +} + +void ARM64FloatEmitter::FABS(ARM64Reg Rd, ARM64Reg Rn) +{ + EmitScalar1Source(0, 0, IsDouble(Rd), 1, Rd, Rn); +} +void ARM64FloatEmitter::FNEG(ARM64Reg Rd, ARM64Reg Rn) +{ + EmitScalar1Source(0, 0, IsDouble(Rd), 2, Rd, Rn); +} +void ARM64FloatEmitter::FSQRT(ARM64Reg Rd, ARM64Reg Rn) +{ + EmitScalar1Source(0, 0, IsDouble(Rd), 3, Rd, Rn); +} + +// Scalar - 2 Source +void ARM64FloatEmitter::FADD(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitScalar2Source(0, 0, IsDouble(Rd), 2, Rd, Rn, Rm); +} +void ARM64FloatEmitter::FMUL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitScalar2Source(0, 0, IsDouble(Rd), 0, Rd, Rn, Rm); +} +void ARM64FloatEmitter::FSUB(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitScalar2Source(0, 0, IsDouble(Rd), 3, Rd, Rn, Rm); +} +void ARM64FloatEmitter::FDIV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitScalar2Source(0, 0, IsDouble(Rd), 1, Rd, Rn, Rm); +} +void ARM64FloatEmitter::FMAX(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitScalar2Source(0, 0, IsDouble(Rd), 4, Rd, Rn, Rm); +} +void ARM64FloatEmitter::FMIN(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitScalar2Source(0, 0, IsDouble(Rd), 5, Rd, Rn, Rm); +} +void ARM64FloatEmitter::FMAXNM(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitScalar2Source(0, 0, IsDouble(Rd), 6, Rd, Rn, Rm); +} +void ARM64FloatEmitter::FMINNM(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitScalar2Source(0, 0, IsDouble(Rd), 7, Rd, Rn, Rm); +} +void ARM64FloatEmitter::FNMUL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitScalar2Source(0, 0, IsDouble(Rd), 8, Rd, Rn, Rm); +} + +void ARM64FloatEmitter::FMADD(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra) +{ + EmitScalar3Source(IsDouble(Rd), Rd, Rn, Rm, Ra, 0); +} +void ARM64FloatEmitter::FMSUB(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra) +{ + EmitScalar3Source(IsDouble(Rd), Rd, Rn, Rm, Ra, 1); +} +void ARM64FloatEmitter::FNMADD(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra) +{ + EmitScalar3Source(IsDouble(Rd), Rd, Rn, Rm, Ra, 2); +} +void ARM64FloatEmitter::FNMSUB(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra) +{ + EmitScalar3Source(IsDouble(Rd), Rd, Rn, Rm, Ra, 3); +} + +void ARM64FloatEmitter::EmitScalar3Source(bool isDouble, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, + ARM64Reg Ra, int opcode) +{ + int type = isDouble ? 1 : 0; + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + Rm = DecodeReg(Rm); + Ra = DecodeReg(Ra); + int o1 = opcode >> 1; + int o0 = opcode & 1; + m_emit->Write32((0x1F << 24) | (type << 22) | (o1 << 21) | (Rm << 16) | (o0 << 15) | (Ra << 10) | + (Rn << 5) | Rd); +} + +// Scalar floating point immediate +void ARM64FloatEmitter::FMOV(ARM64Reg Rd, uint8_t imm8) +{ + EmitScalarImm(0, 0, 0, 0, Rd, imm8); +} + +// Vector +void ARM64FloatEmitter::AND(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitThreeSame(0, 0, 3, Rd, Rn, Rm); +} +void ARM64FloatEmitter::BSL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitThreeSame(1, 1, 3, Rd, Rn, Rm); +} +void ARM64FloatEmitter::DUP(u8 size, ARM64Reg Rd, ARM64Reg Rn, u8 index) +{ + u32 imm5 = 0; + + if (size == 8) + { + imm5 = 1; + imm5 |= index << 1; + } + else if (size == 16) + { + imm5 = 2; + imm5 |= index << 2; + } + else if (size == 32) + { + imm5 = 4; + imm5 |= index << 3; + } + else if (size == 64) + { + imm5 = 8; + imm5 |= index << 4; + } + + EmitCopy(IsQuad(Rd), 0, imm5, 0, Rd, Rn); +} +void ARM64FloatEmitter::FABS(u8 size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(IsQuad(Rd), 0, 2 | (size >> 6), 0xF, Rd, Rn); +} +void ARM64FloatEmitter::FADD(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitThreeSame(0, size >> 6, 0x1A, Rd, Rn, Rm); +} +void ARM64FloatEmitter::FMAX(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitThreeSame(0, size >> 6, 0b11110, Rd, Rn, Rm); +} +void ARM64FloatEmitter::FMLA(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitThreeSame(0, size >> 6, 0x19, Rd, Rn, Rm); +} +void ARM64FloatEmitter::FMIN(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitThreeSame(0, 2 | size >> 6, 0b11110, Rd, Rn, Rm); +} +void ARM64FloatEmitter::FCVTL(u8 size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(false, 0, size >> 6, 0x17, Rd, Rn); +} +void ARM64FloatEmitter::FCVTL2(u8 size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(true, 0, size >> 6, 0x17, Rd, Rn); +} +void ARM64FloatEmitter::FCVTN(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(IsQuad(Rd), 0, dest_size >> 5, 0x16, Rd, Rn); +} +void ARM64FloatEmitter::FCVTZS(u8 size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(IsQuad(Rd), 0, 2 | (size >> 6), 0x1B, Rd, Rn); +} +void ARM64FloatEmitter::FCVTZU(u8 size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(IsQuad(Rd), 1, 2 | (size >> 6), 0x1B, Rd, Rn); +} +void ARM64FloatEmitter::FDIV(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitThreeSame(1, size >> 6, 0x1F, Rd, Rn, Rm); +} +void ARM64FloatEmitter::FMUL(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitThreeSame(1, size >> 6, 0x1B, Rd, Rn, Rm); +} +void ARM64FloatEmitter::FNEG(u8 size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(IsQuad(Rd), 1, 2 | (size >> 6), 0xF, Rd, Rn); +} +void ARM64FloatEmitter::FRECPE(u8 size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(IsQuad(Rd), 0, 2 | (size >> 6), 0x1D, Rd, Rn); +} +void ARM64FloatEmitter::FRSQRTE(u8 size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(IsQuad(Rd), 1, 2 | (size >> 6), 0x1D, Rd, Rn); +} +void ARM64FloatEmitter::FSUB(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitThreeSame(0, 2 | (size >> 6), 0x1A, Rd, Rn, Rm); +} +void ARM64FloatEmitter::FMLS(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitThreeSame(0, 2 | (size >> 6), 0x19, Rd, Rn, Rm); +} +void ARM64FloatEmitter::NOT(ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(IsQuad(Rd), 1, 0, 5, Rd, Rn); +} +void ARM64FloatEmitter::ORR(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitThreeSame(0, 2, 3, Rd, Rn, Rm); +} +void ARM64FloatEmitter::REV16(u8 size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(IsQuad(Rd), 0, size >> 4, 1, Rd, Rn); +} +void ARM64FloatEmitter::REV32(u8 size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(IsQuad(Rd), 1, size >> 4, 0, Rd, Rn); +} +void ARM64FloatEmitter::REV64(u8 size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(IsQuad(Rd), 0, size >> 4, 0, Rd, Rn); +} +void ARM64FloatEmitter::SCVTF(u8 size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(IsQuad(Rd), 0, size >> 6, 0x1D, Rd, Rn); +} +void ARM64FloatEmitter::UCVTF(u8 size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(IsQuad(Rd), 1, size >> 6, 0x1D, Rd, Rn); +} +void ARM64FloatEmitter::SCVTF(u8 size, ARM64Reg Rd, ARM64Reg Rn, int scale) +{ + int imm = size * 2 - scale; + EmitShiftImm(IsQuad(Rd), 0, imm >> 3, imm & 7, 0x1C, Rd, Rn); +} +void ARM64FloatEmitter::UCVTF(u8 size, ARM64Reg Rd, ARM64Reg Rn, int scale) +{ + int imm = size * 2 - scale; + EmitShiftImm(IsQuad(Rd), 1, imm >> 3, imm & 7, 0x1C, Rd, Rn); +} +void ARM64FloatEmitter::SQXTN(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(false, 0, dest_size >> 4, 0b10100, Rd, Rn); +} +void ARM64FloatEmitter::SQXTN2(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(true, 0, dest_size >> 4, 0b10100, Rd, Rn); +} +void ARM64FloatEmitter::UQXTN(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(false, 1, dest_size >> 4, 0b10100, Rd, Rn); +} +void ARM64FloatEmitter::UQXTN2(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(true, 1, dest_size >> 4, 0b10100, Rd, Rn); +} +void ARM64FloatEmitter::XTN(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(false, 0, dest_size >> 4, 0b10010, Rd, Rn); +} +void ARM64FloatEmitter::XTN2(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(true, 0, dest_size >> 4, 0b10010, Rd, Rn); +} + +// Move +void ARM64FloatEmitter::DUP(u8 size, ARM64Reg Rd, ARM64Reg Rn) +{ + u32 imm5 = 0; + + if (size == 8) + imm5 = 1; + else if (size == 16) + imm5 = 2; + else if (size == 32) + imm5 = 4; + else if (size == 64) + imm5 = 8; + + EmitCopy(IsQuad(Rd), 0, imm5, 1, Rd, Rn); +} +void ARM64FloatEmitter::INS(u8 size, ARM64Reg Rd, u8 index, ARM64Reg Rn) +{ + u32 imm5 = 0; + + if (size == 8) + { + imm5 = 1; + imm5 |= index << 1; + } + else if (size == 16) + { + imm5 = 2; + imm5 |= index << 2; + } + else if (size == 32) + { + imm5 = 4; + imm5 |= index << 3; + } + else if (size == 64) + { + imm5 = 8; + imm5 |= index << 4; + } + + EmitCopy(1, 0, imm5, 3, Rd, Rn); +} +void ARM64FloatEmitter::INS(u8 size, ARM64Reg Rd, u8 index1, ARM64Reg Rn, u8 index2) +{ + u32 imm5 = 0, imm4 = 0; + + if (size == 8) + { + imm5 = 1; + imm5 |= index1 << 1; + imm4 = index2; + } + else if (size == 16) + { + imm5 = 2; + imm5 |= index1 << 2; + imm4 = index2 << 1; + } + else if (size == 32) + { + imm5 = 4; + imm5 |= index1 << 3; + imm4 = index2 << 2; + } + else if (size == 64) + { + imm5 = 8; + imm5 |= index1 << 4; + imm4 = index2 << 3; + } + + EmitCopy(1, 1, imm5, imm4, Rd, Rn); +} + +void ARM64FloatEmitter::UMOV(u8 size, ARM64Reg Rd, ARM64Reg Rn, u8 index) +{ + bool b64Bit = Is64Bit(Rd); + ASSERT_MSG(DYNA_REC, Rd < SP, "%s destination must be a GPR!", __func__); + ASSERT_MSG(DYNA_REC, !(b64Bit && size != 64), + "%s must have a size of 64 when destination is 64bit!", __func__); + u32 imm5 = 0; + + if (size == 8) + { + imm5 = 1; + imm5 |= index << 1; + } + else if (size == 16) + { + imm5 = 2; + imm5 |= index << 2; + } + else if (size == 32) + { + imm5 = 4; + imm5 |= index << 3; + } + else if (size == 64) + { + imm5 = 8; + imm5 |= index << 4; + } + + EmitCopy(b64Bit, 0, imm5, 7, Rd, Rn); +} +void ARM64FloatEmitter::SMOV(u8 size, ARM64Reg Rd, ARM64Reg Rn, u8 index) +{ + bool b64Bit = Is64Bit(Rd); + ASSERT_MSG(DYNA_REC, Rd < SP, "%s destination must be a GPR!", __func__); + ASSERT_MSG(DYNA_REC, size != 64, "%s doesn't support 64bit destination. Use UMOV!", __func__); + u32 imm5 = 0; + + if (size == 8) + { + imm5 = 1; + imm5 |= index << 1; + } + else if (size == 16) + { + imm5 = 2; + imm5 |= index << 2; + } + else if (size == 32) + { + imm5 = 4; + imm5 |= index << 3; + } + + EmitCopy(b64Bit, 0, imm5, 5, Rd, Rn); +} + +// One source +void ARM64FloatEmitter::FCVT(u8 size_to, u8 size_from, ARM64Reg Rd, ARM64Reg Rn) +{ + u32 dst_encoding = 0; + u32 src_encoding = 0; + + if (size_to == 16) + dst_encoding = 3; + else if (size_to == 32) + dst_encoding = 0; + else if (size_to == 64) + dst_encoding = 1; + + if (size_from == 16) + src_encoding = 3; + else if (size_from == 32) + src_encoding = 0; + else if (size_from == 64) + src_encoding = 1; + + Emit1Source(0, 0, src_encoding, 4 | dst_encoding, Rd, Rn); +} + +void ARM64FloatEmitter::SCVTF(ARM64Reg Rd, ARM64Reg Rn) +{ + if (IsScalar(Rn)) + { + // Source is in FP register (like destination!). We must use a vector encoding. + bool sign = false; + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + int sz = IsDouble(Rn); + Write32((0x5e << 24) | (sign << 29) | (sz << 22) | (0x876 << 10) | (Rn << 5) | Rd); + } + else + { + bool sf = Is64Bit(Rn); + u32 type = 0; + if (IsDouble(Rd)) + type = 1; + EmitConversion(sf, 0, type, 0, 2, Rd, Rn); + } +} + +void ARM64FloatEmitter::UCVTF(ARM64Reg Rd, ARM64Reg Rn) +{ + if (IsScalar(Rn)) + { + // Source is in FP register (like destination!). We must use a vector encoding. + bool sign = true; + Rd = DecodeReg(Rd); + Rn = DecodeReg(Rn); + int sz = IsDouble(Rn); + Write32((0x5e << 24) | (sign << 29) | (sz << 22) | (0x876 << 10) | (Rn << 5) | Rd); + } + else + { + bool sf = Is64Bit(Rn); + u32 type = 0; + if (IsDouble(Rd)) + type = 1; + + EmitConversion(sf, 0, type, 0, 3, Rd, Rn); + } +} + +void ARM64FloatEmitter::SCVTF(ARM64Reg Rd, ARM64Reg Rn, int scale) +{ + bool sf = Is64Bit(Rn); + u32 type = 0; + if (IsDouble(Rd)) + type = 1; + + EmitConversion2(sf, 0, false, type, 0, 2, 64 - scale, Rd, Rn); +} + +void ARM64FloatEmitter::UCVTF(ARM64Reg Rd, ARM64Reg Rn, int scale) +{ + bool sf = Is64Bit(Rn); + u32 type = 0; + if (IsDouble(Rd)) + type = 1; + + EmitConversion2(sf, 0, false, type, 0, 3, 64 - scale, Rd, Rn); +} + +void ARM64FloatEmitter::FCMP(ARM64Reg Rn, ARM64Reg Rm) +{ + EmitCompare(0, 0, 0, 0, Rn, Rm); +} +void ARM64FloatEmitter::FCMP(ARM64Reg Rn) +{ + EmitCompare(0, 0, 0, 8, Rn, (ARM64Reg)0); +} +void ARM64FloatEmitter::FCMPE(ARM64Reg Rn, ARM64Reg Rm) +{ + EmitCompare(0, 0, 0, 0x10, Rn, Rm); +} +void ARM64FloatEmitter::FCMPE(ARM64Reg Rn) +{ + EmitCompare(0, 0, 0, 0x18, Rn, (ARM64Reg)0); +} +void ARM64FloatEmitter::FCMEQ(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitThreeSame(0, size >> 6, 0x1C, Rd, Rn, Rm); +} +void ARM64FloatEmitter::FCMEQ(u8 size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(IsQuad(Rd), 0, 2 | (size >> 6), 0xD, Rd, Rn); +} +void ARM64FloatEmitter::FCMGE(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitThreeSame(1, size >> 6, 0x1C, Rd, Rn, Rm); +} +void ARM64FloatEmitter::FCMGE(u8 size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(IsQuad(Rd), 1, 2 | (size >> 6), 0x0C, Rd, Rn); +} +void ARM64FloatEmitter::FCMGT(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitThreeSame(1, 2 | (size >> 6), 0x1C, Rd, Rn, Rm); +} +void ARM64FloatEmitter::FCMGT(u8 size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(IsQuad(Rd), 0, 2 | (size >> 6), 0x0C, Rd, Rn); +} +void ARM64FloatEmitter::FCMLE(u8 size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(IsQuad(Rd), 1, 2 | (size >> 6), 0xD, Rd, Rn); +} +void ARM64FloatEmitter::FCMLT(u8 size, ARM64Reg Rd, ARM64Reg Rn) +{ + Emit2RegMisc(IsQuad(Rd), 0, 2 | (size >> 6), 0xE, Rd, Rn); +} + +void ARM64FloatEmitter::FCSEL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, CCFlags cond) +{ + EmitCondSelect(0, 0, cond, Rd, Rn, Rm); +} + +// Permute +void ARM64FloatEmitter::UZP1(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitPermute(size, 0b001, Rd, Rn, Rm); +} +void ARM64FloatEmitter::TRN1(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitPermute(size, 0b010, Rd, Rn, Rm); +} +void ARM64FloatEmitter::ZIP1(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitPermute(size, 0b011, Rd, Rn, Rm); +} +void ARM64FloatEmitter::UZP2(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitPermute(size, 0b101, Rd, Rn, Rm); +} +void ARM64FloatEmitter::TRN2(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitPermute(size, 0b110, Rd, Rn, Rm); +} +void ARM64FloatEmitter::ZIP2(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) +{ + EmitPermute(size, 0b111, Rd, Rn, Rm); +} + +// Shift by immediate +void ARM64FloatEmitter::SSHLL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift) +{ + SSHLL(src_size, Rd, Rn, shift, false); +} +void ARM64FloatEmitter::SSHLL2(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift) +{ + SSHLL(src_size, Rd, Rn, shift, true); +} +void ARM64FloatEmitter::SHRN(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift) +{ + SHRN(dest_size, Rd, Rn, shift, false); +} +void ARM64FloatEmitter::SHRN2(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift) +{ + SHRN(dest_size, Rd, Rn, shift, true); +} +void ARM64FloatEmitter::USHLL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift) +{ + USHLL(src_size, Rd, Rn, shift, false); +} +void ARM64FloatEmitter::USHLL2(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift) +{ + USHLL(src_size, Rd, Rn, shift, true); +} +void ARM64FloatEmitter::SXTL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn) +{ + SXTL(src_size, Rd, Rn, false); +} +void ARM64FloatEmitter::SXTL2(u8 src_size, ARM64Reg Rd, ARM64Reg Rn) +{ + SXTL(src_size, Rd, Rn, true); +} +void ARM64FloatEmitter::UXTL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn) +{ + UXTL(src_size, Rd, Rn, false); +} +void ARM64FloatEmitter::UXTL2(u8 src_size, ARM64Reg Rd, ARM64Reg Rn) +{ + UXTL(src_size, Rd, Rn, true); +} + +void ARM64FloatEmitter::SSHLL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift, bool upper) +{ + ASSERT_MSG(DYNA_REC, shift < src_size, "%s shift amount must less than the element size!", + __func__); + u32 immh = 0; + u32 immb = shift & 0xFFF; + + if (src_size == 8) + { + immh = 1; + } + else if (src_size == 16) + { + immh = 2 | ((shift >> 3) & 1); + } + else if (src_size == 32) + { + immh = 4 | ((shift >> 3) & 3); + ; + } + EmitShiftImm(upper, 0, immh, immb, 0b10100, Rd, Rn); +} + +void ARM64FloatEmitter::USHLL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift, bool upper) +{ + ASSERT_MSG(DYNA_REC, shift < src_size, "%s shift amount must less than the element size!", + __func__); + u32 immh = 0; + u32 immb = shift & 0xFFF; + + if (src_size == 8) + { + immh = 1; + } + else if (src_size == 16) + { + immh = 2 | ((shift >> 3) & 1); + } + else if (src_size == 32) + { + immh = 4 | ((shift >> 3) & 3); + ; + } + EmitShiftImm(upper, 1, immh, immb, 0b10100, Rd, Rn); +} + +void ARM64FloatEmitter::SHRN(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift, bool upper) +{ + ASSERT_MSG(DYNA_REC, shift < dest_size, "%s shift amount must less than the element size!", + __func__); + u32 immh = 0; + u32 immb = shift & 0xFFF; + + if (dest_size == 8) + { + immh = 1; + } + else if (dest_size == 16) + { + immh = 2 | ((shift >> 3) & 1); + } + else if (dest_size == 32) + { + immh = 4 | ((shift >> 3) & 3); + ; + } + EmitShiftImm(upper, 1, immh, immb, 0b10000, Rd, Rn); +} + +void ARM64FloatEmitter::SXTL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, bool upper) +{ + SSHLL(src_size, Rd, Rn, 0, upper); +} + +void ARM64FloatEmitter::UXTL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, bool upper) +{ + USHLL(src_size, Rd, Rn, 0, upper); +} + +// vector x indexed element +void ARM64FloatEmitter::FMUL(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, u8 index) +{ + ASSERT_MSG(DYNA_REC, size == 32 || size == 64, "%s only supports 32bit or 64bit size!", __func__); + + bool L = false; + bool H = false; + if (size == 32) + { + L = index & 1; + H = (index >> 1) & 1; + } + else if (size == 64) + { + H = index == 1; + } + + EmitVectorxElement(0, 2 | (size >> 6), L, 0x9, H, Rd, Rn, Rm); +} + +void ARM64FloatEmitter::FMLA(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, u8 index) +{ + ASSERT_MSG(DYNA_REC, size == 32 || size == 64, "%s only supports 32bit or 64bit size!", __func__); + + bool L = false; + bool H = false; + if (size == 32) + { + L = index & 1; + H = (index >> 1) & 1; + } + else if (size == 64) + { + H = index == 1; + } + + EmitVectorxElement(0, 2 | (size >> 6), L, 1, H, Rd, Rn, Rm); +} + +// Modified Immediate +void ARM64FloatEmitter::MOVI(u8 size, ARM64Reg Rd, u64 imm, u8 shift) +{ + bool Q = IsQuad(Rd); + u8 cmode = 0; + u8 op = 0; + u8 abcdefgh = imm & 0xFF; + if (size == 8) + { + ASSERT_MSG(DYNA_REC, shift == 0, "%s(size8) doesn't support shift!", __func__); + ASSERT_MSG(DYNA_REC, !(imm & ~0xFFULL), "%s(size8) only supports 8bit values!", __func__); + } + else if (size == 16) + { + ASSERT_MSG(DYNA_REC, shift == 0 || shift == 8, "%s(size16) only supports shift of {0, 8}!", + __func__); + ASSERT_MSG(DYNA_REC, !(imm & ~0xFFULL), "%s(size16) only supports 8bit values!", __func__); + + if (shift == 8) + cmode |= 2; + } + else if (size == 32) + { + ASSERT_MSG(DYNA_REC, shift == 0 || shift == 8 || shift == 16 || shift == 24, + "%s(size32) only supports shift of {0, 8, 16, 24}!", __func__); + // XXX: Implement support for MOVI - shifting ones variant + ASSERT_MSG(DYNA_REC, !(imm & ~0xFFULL), "%s(size32) only supports 8bit values!", __func__); + switch (shift) + { + case 8: + cmode |= 2; + break; + case 16: + cmode |= 4; + break; + case 24: + cmode |= 6; + break; + default: + break; + } + } + else // 64 + { + ASSERT_MSG(DYNA_REC, shift == 0, "%s(size64) doesn't support shift!", __func__); + + op = 1; + cmode = 0xE; + abcdefgh = 0; + for (int i = 0; i < 8; ++i) + { + u8 tmp = (imm >> (i << 3)) & 0xFF; + ASSERT_MSG(DYNA_REC, tmp == 0xFF || tmp == 0, "%s(size64) Invalid immediate!", __func__); + if (tmp == 0xFF) + abcdefgh |= (1 << i); + } + } + EncodeModImm(Q, op, cmode, 0, Rd, abcdefgh); +} + +void ARM64FloatEmitter::BIC(u8 size, ARM64Reg Rd, u8 imm, u8 shift) +{ + bool Q = IsQuad(Rd); + u8 cmode = 1; + u8 op = 1; + if (size == 16) + { + ASSERT_MSG(DYNA_REC, shift == 0 || shift == 8, "%s(size16) only supports shift of {0, 8}!", + __func__); + + if (shift == 8) + cmode |= 2; + } + else if (size == 32) + { + ASSERT_MSG(DYNA_REC, shift == 0 || shift == 8 || shift == 16 || shift == 24, + "%s(size32) only supports shift of {0, 8, 16, 24}!", __func__); + // XXX: Implement support for MOVI - shifting ones variant + switch (shift) + { + case 8: + cmode |= 2; + break; + case 16: + cmode |= 4; + break; + case 24: + cmode |= 6; + break; + default: + break; + } + } + else + { + ASSERT_MSG(DYNA_REC, false, "%s only supports size of {16, 32}!", __func__); + } + EncodeModImm(Q, op, cmode, 0, Rd, imm); +} + +void ARM64FloatEmitter::ABI_PushRegisters(BitSet32 registers, ARM64Reg tmp) +{ + bool bundled_loadstore = false; + + for (int i = 0; i < 32; ++i) + { + if (!registers[i]) + continue; + + int count = 0; + while (++count < 4 && (i + count) < 32 && registers[i + count]) + { + } + if (count > 1) + { + bundled_loadstore = true; + break; + } + } + + if (bundled_loadstore && tmp != INVALID_REG) + { + int num_regs = registers.Count(); + m_emit->SUB(SP, SP, num_regs * 16); + m_emit->ADD(tmp, SP, 0); + std::vector island_regs; + for (int i = 0; i < 32; ++i) + { + if (!registers[i]) + continue; + + int count = 0; + + // 0 = true + // 1 < 4 && registers[i + 1] true! + // 2 < 4 && registers[i + 2] true! + // 3 < 4 && registers[i + 3] true! + // 4 < 4 && registers[i + 4] false! + while (++count < 4 && (i + count) < 32 && registers[i + count]) + { + } + + if (count == 1) + island_regs.push_back((ARM64Reg)(Q0 + i)); + else + ST1(64, count, INDEX_POST, (ARM64Reg)(Q0 + i), tmp); + + i += count - 1; + } + + // Handle island registers + std::vector pair_regs; + for (auto& it : island_regs) + { + pair_regs.push_back(it); + if (pair_regs.size() == 2) + { + STP(128, INDEX_POST, pair_regs[0], pair_regs[1], tmp, 32); + pair_regs.clear(); + } + } + if (pair_regs.size()) + STR(128, INDEX_POST, pair_regs[0], tmp, 16); + } + else + { + std::vector pair_regs; + for (auto it : registers) + { + pair_regs.push_back((ARM64Reg)(Q0 + it)); + if (pair_regs.size() == 2) + { + STP(128, INDEX_PRE, pair_regs[0], pair_regs[1], SP, -32); + pair_regs.clear(); + } + } + if (pair_regs.size()) + STR(128, INDEX_PRE, pair_regs[0], SP, -16); + } +} +void ARM64FloatEmitter::ABI_PopRegisters(BitSet32 registers, ARM64Reg tmp) +{ + bool bundled_loadstore = false; + int num_regs = registers.Count(); + + for (int i = 0; i < 32; ++i) + { + if (!registers[i]) + continue; + + int count = 0; + while (++count < 4 && (i + count) < 32 && registers[i + count]) + { + } + if (count > 1) + { + bundled_loadstore = true; + break; + } + } + + if (bundled_loadstore && tmp != INVALID_REG) + { + // The temporary register is only used to indicate that we can use this code path + std::vector island_regs; + for (int i = 0; i < 32; ++i) + { + if (!registers[i]) + continue; + + int count = 0; + while (++count < 4 && (i + count) < 32 && registers[i + count]) + { + } + + if (count == 1) + island_regs.push_back((ARM64Reg)(Q0 + i)); + else + LD1(64, count, INDEX_POST, (ARM64Reg)(Q0 + i), SP); + + i += count - 1; + } + + // Handle island registers + std::vector pair_regs; + for (auto& it : island_regs) + { + pair_regs.push_back(it); + if (pair_regs.size() == 2) + { + LDP(128, INDEX_POST, pair_regs[0], pair_regs[1], SP, 32); + pair_regs.clear(); + } + } + if (pair_regs.size()) + LDR(128, INDEX_POST, pair_regs[0], SP, 16); + } + else + { + bool odd = num_regs % 2; + std::vector pair_regs; + for (int i = 31; i >= 0; --i) + { + if (!registers[i]) + continue; + + if (odd) + { + // First load must be a regular LDR if odd + odd = false; + LDR(128, INDEX_POST, (ARM64Reg)(Q0 + i), SP, 16); + } + else + { + pair_regs.push_back((ARM64Reg)(Q0 + i)); + if (pair_regs.size() == 2) + { + LDP(128, INDEX_POST, pair_regs[1], pair_regs[0], SP, 32); + pair_regs.clear(); + } + } + } + } +} + +void ARM64XEmitter::ANDI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch) +{ + unsigned int n, imm_s, imm_r; + if (!Is64Bit(Rn)) + imm &= 0xFFFFFFFF; + if (IsImmLogical(imm, Is64Bit(Rn) ? 64 : 32, &n, &imm_s, &imm_r)) + { + AND(Rd, Rn, imm_r, imm_s, n != 0); + } + else + { + ASSERT_MSG(DYNA_REC, scratch != INVALID_REG, + "ANDI2R - failed to construct logical immediate value from %08x, need scratch", + (u32)imm); + MOVI2R(scratch, imm); + AND(Rd, Rn, scratch); + } +} + +void ARM64XEmitter::ORRI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch) +{ + unsigned int n, imm_s, imm_r; + if (IsImmLogical(imm, Is64Bit(Rn) ? 64 : 32, &n, &imm_s, &imm_r)) + { + ORR(Rd, Rn, imm_r, imm_s, n != 0); + } + else + { + ASSERT_MSG(DYNA_REC, scratch != INVALID_REG, + "ORRI2R - failed to construct logical immediate value from %08x, need scratch", + (u32)imm); + MOVI2R(scratch, imm); + ORR(Rd, Rn, scratch); + } +} + +void ARM64XEmitter::EORI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch) +{ + unsigned int n, imm_s, imm_r; + if (IsImmLogical(imm, Is64Bit(Rn) ? 64 : 32, &n, &imm_s, &imm_r)) + { + EOR(Rd, Rn, imm_r, imm_s, n != 0); + } + else + { + ASSERT_MSG(DYNA_REC, scratch != INVALID_REG, + "EORI2R - failed to construct logical immediate value from %08x, need scratch", + (u32)imm); + MOVI2R(scratch, imm); + EOR(Rd, Rn, scratch); + } +} + +void ARM64XEmitter::ANDSI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch) +{ + unsigned int n, imm_s, imm_r; + if (IsImmLogical(imm, Is64Bit(Rn) ? 64 : 32, &n, &imm_s, &imm_r)) + { + ANDS(Rd, Rn, imm_r, imm_s, n != 0); + } + else + { + ASSERT_MSG(DYNA_REC, scratch != INVALID_REG, + "ANDSI2R - failed to construct logical immediate value from %08x, need scratch", + (u32)imm); + MOVI2R(scratch, imm); + ANDS(Rd, Rn, scratch); + } +} + +void ARM64XEmitter::AddImmediate(ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool shift, bool negative, + bool flags) +{ + switch ((negative << 1) | flags) + { + case 0: + ADD(Rd, Rn, imm, shift); + break; + case 1: + ADDS(Rd, Rn, imm, shift); + break; + case 2: + SUB(Rd, Rn, imm, shift); + break; + case 3: + SUBS(Rd, Rn, imm, shift); + break; + } +} + +void ARM64XEmitter::ADDI2R_internal(ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool negative, bool flags, + ARM64Reg scratch) +{ + bool has_scratch = scratch != INVALID_REG; + u64 imm_neg = Is64Bit(Rd) ? -imm : -imm & 0xFFFFFFFFuLL; + bool neg_neg = negative ? false : true; + + // Fast paths, aarch64 immediate instructions + // Try them all first + if (imm <= 0xFFF) + { + AddImmediate(Rd, Rn, imm, false, negative, flags); + return; + } + if (imm <= 0xFFFFFF && (imm & 0xFFF) == 0) + { + AddImmediate(Rd, Rn, imm >> 12, true, negative, flags); + return; + } + if (imm_neg <= 0xFFF) + { + AddImmediate(Rd, Rn, imm_neg, false, neg_neg, flags); + return; + } + if (imm_neg <= 0xFFFFFF && (imm_neg & 0xFFF) == 0) + { + AddImmediate(Rd, Rn, imm_neg >> 12, true, neg_neg, flags); + return; + } + + // ADD+ADD is slower than MOVK+ADD, but inplace. + // But it supports a few more bits, so use it to avoid MOVK+MOVK+ADD. + // As this splits the addition in two parts, this must not be done on setting flags. + if (!flags && (imm >= 0x10000u || !has_scratch) && imm < 0x1000000u) + { + AddImmediate(Rd, Rn, imm & 0xFFF, false, negative, false); + AddImmediate(Rd, Rd, imm >> 12, true, negative, false); + return; + } + if (!flags && (imm_neg >= 0x10000u || !has_scratch) && imm_neg < 0x1000000u) + { + AddImmediate(Rd, Rn, imm_neg & 0xFFF, false, neg_neg, false); + AddImmediate(Rd, Rd, imm_neg >> 12, true, neg_neg, false); + return; + } + + ASSERT_MSG(DYNA_REC, has_scratch, + "ADDI2R - failed to construct arithmetic immediate value from %08x, need scratch", + (u32)imm); + + negative ^= MOVI2R2(scratch, imm, imm_neg); + switch ((negative << 1) | flags) + { + case 0: + ADD(Rd, Rn, scratch); + break; + case 1: + ADDS(Rd, Rn, scratch); + break; + case 2: + SUB(Rd, Rn, scratch); + break; + case 3: + SUBS(Rd, Rn, scratch); + break; + } +} + +void ARM64XEmitter::ADDI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch) +{ + ADDI2R_internal(Rd, Rn, imm, false, false, scratch); +} + +void ARM64XEmitter::ADDSI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch) +{ + ADDI2R_internal(Rd, Rn, imm, false, true, scratch); +} + +void ARM64XEmitter::SUBI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch) +{ + ADDI2R_internal(Rd, Rn, imm, true, false, scratch); +} + +void ARM64XEmitter::SUBSI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch) +{ + ADDI2R_internal(Rd, Rn, imm, true, true, scratch); +} + +void ARM64XEmitter::CMPI2R(ARM64Reg Rn, u64 imm, ARM64Reg scratch) +{ + ADDI2R_internal(Is64Bit(Rn) ? ZR : WZR, Rn, imm, true, true, scratch); +} + +bool ARM64XEmitter::TryADDI2R(ARM64Reg Rd, ARM64Reg Rn, u32 imm) +{ + u32 val; + bool shift; + if (IsImmArithmetic(imm, &val, &shift)) + ADD(Rd, Rn, val, shift); + else + return false; + + return true; +} + +bool ARM64XEmitter::TrySUBI2R(ARM64Reg Rd, ARM64Reg Rn, u32 imm) +{ + u32 val; + bool shift; + if (IsImmArithmetic(imm, &val, &shift)) + SUB(Rd, Rn, val, shift); + else + return false; + + return true; +} + +bool ARM64XEmitter::TryCMPI2R(ARM64Reg Rn, u32 imm) +{ + u32 val; + bool shift; + if (IsImmArithmetic(imm, &val, &shift)) + CMP(Rn, val, shift); + else + return false; + + return true; +} + +bool ARM64XEmitter::TryANDI2R(ARM64Reg Rd, ARM64Reg Rn, u32 imm) +{ + u32 n, imm_r, imm_s; + if (IsImmLogical(imm, 32, &n, &imm_s, &imm_r)) + AND(Rd, Rn, imm_r, imm_s, n != 0); + else + return false; + + return true; +} +bool ARM64XEmitter::TryORRI2R(ARM64Reg Rd, ARM64Reg Rn, u32 imm) +{ + u32 n, imm_r, imm_s; + if (IsImmLogical(imm, 32, &n, &imm_s, &imm_r)) + ORR(Rd, Rn, imm_r, imm_s, n != 0); + else + return false; + + return true; +} +bool ARM64XEmitter::TryEORI2R(ARM64Reg Rd, ARM64Reg Rn, u32 imm) +{ + u32 n, imm_r, imm_s; + if (IsImmLogical(imm, 32, &n, &imm_s, &imm_r)) + EOR(Rd, Rn, imm_r, imm_s, n != 0); + else + return false; + + return true; +} + +void ARM64FloatEmitter::MOVI2F(ARM64Reg Rd, float value, ARM64Reg scratch, bool negate) +{ + ASSERT_MSG(DYNA_REC, !IsDouble(Rd), "MOVI2F does not yet support double precision"); + uint8_t imm8; + if (value == 0.0) + { + FMOV(Rd, IsDouble(Rd) ? ZR : WZR); + if (negate) + FNEG(Rd, Rd); + // TODO: There are some other values we could generate with the float-imm instruction, like + // 1.0... + } + else if (FPImm8FromFloat(value, &imm8)) + { + FMOV(Rd, imm8); + } + else + { + ASSERT_MSG(DYNA_REC, scratch != INVALID_REG, + "Failed to find a way to generate FP immediate %f without scratch", value); + if (negate) + value = -value; + + const u32 ival = Common::BitCast(value); + m_emit->MOVI2R(scratch, ival); + FMOV(Rd, scratch); + } +} + +// TODO: Quite a few values could be generated easily using the MOVI instruction and friends. +void ARM64FloatEmitter::MOVI2FDUP(ARM64Reg Rd, float value, ARM64Reg scratch) +{ + // TODO: Make it work with more element sizes + // TODO: Optimize - there are shorter solution for many values + ARM64Reg s = (ARM64Reg)(S0 + DecodeReg(Rd)); + MOVI2F(s, value, scratch); + DUP(32, Rd, Rd, 0); +} + +} // namespace Arm64Gen diff --git a/src/dolphin/Arm64Emitter.h b/src/dolphin/Arm64Emitter.h new file mode 100644 index 0000000..4cb9ff7 --- /dev/null +++ b/src/dolphin/Arm64Emitter.h @@ -0,0 +1,1152 @@ +// Copyright 2015 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include +#include + +#include "ArmCommon.h" +#include "Assert.h" +#include "BitSet.h" +#include "Compat.h" + +namespace Arm64Gen +{ +// X30 serves a dual purpose as a link register +// Encoded as +// Types: +// 000 - 32bit GPR +// 001 - 64bit GPR +// 010 - VFP single precision +// 100 - VFP double precision +// 110 - VFP quad precision +enum ARM64Reg +{ + // 32bit registers + W0 = 0, + W1, + W2, + W3, + W4, + W5, + W6, + W7, + W8, + W9, + W10, + W11, + W12, + W13, + W14, + W15, + W16, + W17, + W18, + W19, + W20, + W21, + W22, + W23, + W24, + W25, + W26, + W27, + W28, + W29, + W30, + + WSP, // 32bit stack pointer + + // 64bit registers + X0 = 0x20, + X1, + X2, + X3, + X4, + X5, + X6, + X7, + X8, + X9, + X10, + X11, + X12, + X13, + X14, + X15, + X16, + X17, + X18, + X19, + X20, + X21, + X22, + X23, + X24, + X25, + X26, + X27, + X28, + X29, + X30, + + SP, // 64bit stack pointer + + // VFP single precision registers + S0 = 0x40, + S1, + S2, + S3, + S4, + S5, + S6, + S7, + S8, + S9, + S10, + S11, + S12, + S13, + S14, + S15, + S16, + S17, + S18, + S19, + S20, + S21, + S22, + S23, + S24, + S25, + S26, + S27, + S28, + S29, + S30, + S31, + + // VFP Double Precision registers + D0 = 0x80, + D1, + D2, + D3, + D4, + D5, + D6, + D7, + D8, + D9, + D10, + D11, + D12, + D13, + D14, + D15, + D16, + D17, + D18, + D19, + D20, + D21, + D22, + D23, + D24, + D25, + D26, + D27, + D28, + D29, + D30, + D31, + + // ASIMD Quad-Word registers + Q0 = 0xC0, + Q1, + Q2, + Q3, + Q4, + Q5, + Q6, + Q7, + Q8, + Q9, + Q10, + Q11, + Q12, + Q13, + Q14, + Q15, + Q16, + Q17, + Q18, + Q19, + Q20, + Q21, + Q22, + Q23, + Q24, + Q25, + Q26, + Q27, + Q28, + Q29, + Q30, + Q31, + + // For PRFM(prefetch memory) encoding + // This is encoded in the Rt register + // Data preload + PLDL1KEEP = 0, + PLDL1STRM, + PLDL2KEEP, + PLDL2STRM, + PLDL3KEEP, + PLDL3STRM, + // Instruction preload + PLIL1KEEP = 8, + PLIL1STRM, + PLIL2KEEP, + PLIL2STRM, + PLIL3KEEP, + PLIL3STRM, + // Prepare for store + PLTL1KEEP = 16, + PLTL1STRM, + PLTL2KEEP, + PLTL2STRM, + PLTL3KEEP, + PLTL3STRM, + + WZR = WSP, + ZR = SP, + + INVALID_REG = 0xFFFFFFFF +}; + +constexpr bool Is64Bit(ARM64Reg reg) +{ + return (reg & 0x20) != 0; +} +constexpr bool IsSingle(ARM64Reg reg) +{ + return (reg & 0xC0) == 0x40; +} +constexpr bool IsDouble(ARM64Reg reg) +{ + return (reg & 0xC0) == 0x80; +} +constexpr bool IsScalar(ARM64Reg reg) +{ + return IsSingle(reg) || IsDouble(reg); +} +constexpr bool IsQuad(ARM64Reg reg) +{ + return (reg & 0xC0) == 0xC0; +} +constexpr bool IsVector(ARM64Reg reg) +{ + return (reg & 0xC0) != 0; +} +constexpr bool IsGPR(ARM64Reg reg) +{ + return static_cast(reg) < 0x40; +} + +constexpr ARM64Reg DecodeReg(ARM64Reg reg) +{ + return static_cast(reg & 0x1F); +} +constexpr ARM64Reg EncodeRegTo64(ARM64Reg reg) +{ + return static_cast(reg | 0x20); +} +constexpr ARM64Reg EncodeRegToSingle(ARM64Reg reg) +{ + return static_cast(DecodeReg(reg) + S0); +} +constexpr ARM64Reg EncodeRegToDouble(ARM64Reg reg) +{ + return static_cast((reg & ~0xC0) | 0x80); +} +constexpr ARM64Reg EncodeRegToQuad(ARM64Reg reg) +{ + return static_cast(reg | 0xC0); +} + +enum OpType +{ + TYPE_IMM = 0, + TYPE_REG, + TYPE_IMMSREG, + TYPE_RSR, + TYPE_MEM +}; + +enum ShiftType +{ + ST_LSL = 0, + ST_LSR = 1, + ST_ASR = 2, + ST_ROR = 3, +}; + +enum IndexType +{ + INDEX_UNSIGNED, + INDEX_POST, + INDEX_PRE, + INDEX_SIGNED, // used in LDP/STP +}; + +enum ShiftAmount +{ + SHIFT_0 = 0, + SHIFT_16 = 1, + SHIFT_32 = 2, + SHIFT_48 = 3, +}; + +enum RoundingMode +{ + ROUND_A, // round to nearest, ties to away + ROUND_M, // round towards -inf + ROUND_N, // round to nearest, ties to even + ROUND_P, // round towards +inf + ROUND_Z, // round towards zero +}; + +struct FixupBranch +{ + ptrdiff_t ptr; + // Type defines + // 0 = CBZ (32bit) + // 1 = CBNZ (32bit) + // 2 = B (conditional) + // 3 = TBZ + // 4 = TBNZ + // 5 = B (unconditional) + // 6 = BL (unconditional) + u32 type; + + // Used with B.cond + CCFlags cond; + + // Used with TBZ/TBNZ + u8 bit; + + // Used with Test/Compare and Branch + ARM64Reg reg; +}; + +enum PStateField +{ + FIELD_SPSel = 0, + FIELD_DAIFSet, + FIELD_DAIFClr, + FIELD_NZCV, // The only system registers accessible from EL0 (user space) + FIELD_PMCR_EL0, + FIELD_PMCCNTR_EL0, + FIELD_FPCR = 0x340, + FIELD_FPSR = 0x341, +}; + +enum SystemHint +{ + HINT_NOP = 0, + HINT_YIELD, + HINT_WFE, + HINT_WFI, + HINT_SEV, + HINT_SEVL, +}; + +enum BarrierType +{ + OSHLD = 1, + OSHST = 2, + OSH = 3, + NSHLD = 5, + NSHST = 6, + NSH = 7, + ISHLD = 9, + ISHST = 10, + ISH = 11, + LD = 13, + ST = 14, + SY = 15, +}; + +class ArithOption +{ +public: + enum WidthSpecifier + { + WIDTH_DEFAULT, + WIDTH_32BIT, + WIDTH_64BIT, + }; + + enum ExtendSpecifier + { + EXTEND_UXTB = 0x0, + EXTEND_UXTH = 0x1, + EXTEND_UXTW = 0x2, /* Also LSL on 32bit width */ + EXTEND_UXTX = 0x3, /* Also LSL on 64bit width */ + EXTEND_SXTB = 0x4, + EXTEND_SXTH = 0x5, + EXTEND_SXTW = 0x6, + EXTEND_SXTX = 0x7, + }; + + enum TypeSpecifier + { + TYPE_EXTENDEDREG, + TYPE_IMM, + TYPE_SHIFTEDREG, + }; + +private: + ARM64Reg m_destReg; + WidthSpecifier m_width; + ExtendSpecifier m_extend; + TypeSpecifier m_type; + ShiftType m_shifttype; + u32 m_shift; + +public: + ArithOption(ARM64Reg Rd, bool index = false) + { + // Indexed registers are a certain feature of AARch64 + // On Loadstore instructions that use a register offset + // We can have the register as an index + // If we are indexing then the offset register will + // be shifted to the left so we are indexing at intervals + // of the size of what we are loading + // 8-bit: Index does nothing + // 16-bit: Index LSL 1 + // 32-bit: Index LSL 2 + // 64-bit: Index LSL 3 + if (index) + m_shift = 4; + else + m_shift = 0; + + m_destReg = Rd; + m_type = TYPE_EXTENDEDREG; + if (Is64Bit(Rd)) + { + m_width = WIDTH_64BIT; + m_extend = EXTEND_UXTX; + } + else + { + m_width = WIDTH_32BIT; + m_extend = EXTEND_UXTW; + } + m_shifttype = ST_LSL; + } + ArithOption(ARM64Reg Rd, ShiftType shift_type, u32 shift) + { + m_destReg = Rd; + m_shift = shift; + m_shifttype = shift_type; + m_type = TYPE_SHIFTEDREG; + if (Is64Bit(Rd)) + { + m_width = WIDTH_64BIT; + if (shift == 64) + m_shift = 0; + } + else + { + m_width = WIDTH_32BIT; + if (shift == 32) + m_shift = 0; + } + } + TypeSpecifier GetType() const { return m_type; } + ARM64Reg GetReg() const { return m_destReg; } + u32 GetData() const + { + switch (m_type) + { + case TYPE_EXTENDEDREG: + return (m_extend << 13) | (m_shift << 10); + break; + case TYPE_SHIFTEDREG: + return (m_shifttype << 22) | (m_shift << 10); + break; + default: + DEBUG_ASSERT_MSG(DYNA_REC, false, "Invalid type in GetData"); + break; + } + return 0; + } +}; + +class ARM64XEmitter +{ + friend class ARM64FloatEmitter; + +private: + ptrdiff_t m_code; + ptrdiff_t m_lastCacheFlushEnd; + u8* m_rwbase; + u8* m_rxbase; + + void AddImmediate(ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool shift, bool negative, bool flags); + void EncodeCompareBranchInst(u32 op, ARM64Reg Rt, const void* ptr); + void EncodeTestBranchInst(u32 op, ARM64Reg Rt, u8 bits, const void* ptr); + void EncodeUnconditionalBranchInst(u32 op, const void* ptr); + void EncodeUnconditionalBranchInst(u32 opc, u32 op2, u32 op3, u32 op4, ARM64Reg Rn); + void EncodeExceptionInst(u32 instenc, u32 imm); + void EncodeSystemInst(u32 op0, u32 op1, u32 CRn, u32 CRm, u32 op2, ARM64Reg Rt); + void EncodeArithmeticInst(u32 instenc, bool flags, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, + ArithOption Option); + void EncodeArithmeticCarryInst(u32 op, bool flags, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void EncodeCondCompareImmInst(u32 op, ARM64Reg Rn, u32 imm, u32 nzcv, CCFlags cond); + void EncodeCondCompareRegInst(u32 op, ARM64Reg Rn, ARM64Reg Rm, u32 nzcv, CCFlags cond); + void EncodeCondSelectInst(u32 instenc, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, CCFlags cond); + void EncodeData1SrcInst(u32 instenc, ARM64Reg Rd, ARM64Reg Rn); + void EncodeData2SrcInst(u32 instenc, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void EncodeData3SrcInst(u32 instenc, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra); + void EncodeLogicalInst(u32 instenc, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift); + void EncodeLoadRegisterInst(u32 bitop, ARM64Reg Rt, u32 imm); + void EncodeLoadStoreExcInst(u32 instenc, ARM64Reg Rs, ARM64Reg Rt2, ARM64Reg Rn, ARM64Reg Rt); + void EncodeLoadStorePairedInst(u32 op, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn, u32 imm); + void EncodeLoadStoreIndexedInst(u32 op, u32 op2, ARM64Reg Rt, ARM64Reg Rn, s32 imm); + void EncodeLoadStoreIndexedInst(u32 op, ARM64Reg Rt, ARM64Reg Rn, s32 imm, u8 size); + void EncodeMOVWideInst(u32 op, ARM64Reg Rd, u32 imm, ShiftAmount pos); + void EncodeBitfieldMOVInst(u32 op, ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms); + void EncodeLoadStoreRegisterOffset(u32 size, u32 opc, ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm); + void EncodeAddSubImmInst(u32 op, bool flags, u32 shift, u32 imm, ARM64Reg Rn, ARM64Reg Rd); + void EncodeLogicalImmInst(u32 op, ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms, int n); + void EncodeLoadStorePair(u32 op, u32 load, IndexType type, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn, + s32 imm); + void EncodeAddressInst(u32 op, ARM64Reg Rd, s32 imm); + void EncodeLoadStoreUnscaled(u32 size, u32 op, ARM64Reg Rt, ARM64Reg Rn, s32 imm); + +protected: + // TODO: make this less ugly + // used for Switch where memory is executable and writeable and different addresses + // we need to take this for relative addressing in account + + void Write32(u32 value); + +public: + ARM64XEmitter() : m_code(0), m_lastCacheFlushEnd(0), m_rwbase(nullptr), m_rxbase(nullptr) {} + ARM64XEmitter(u8* rwbase, u8* rxbase, ptrdiff_t offset) + { + m_rwbase = rwbase; + m_rxbase = rxbase; + m_code = offset; + m_lastCacheFlushEnd = offset; + } + + virtual ~ARM64XEmitter() {} + void SetCodePtr(ptrdiff_t ptr); + void SetCodePtrUnsafe(ptrdiff_t ptr); + void SetCodeBase(u8* rwbase, u8* rxbase); + void ReserveCodeSpace(u32 bytes); + ptrdiff_t AlignCode16(); + ptrdiff_t AlignCodePage(); + ptrdiff_t GetCodeOffset(); + const u8* GetRWPtr(); + u8* GetWriteableRWPtr(); + void* GetRXPtr(); + void FlushIcache(); + void FlushIcacheSection(u8* start, u8* end); + + // FixupBranch branching + void SetJumpTarget(FixupBranch const& branch); + FixupBranch CBZ(ARM64Reg Rt); + FixupBranch CBNZ(ARM64Reg Rt); + FixupBranch B(CCFlags cond); + FixupBranch TBZ(ARM64Reg Rt, u8 bit); + FixupBranch TBNZ(ARM64Reg Rt, u8 bit); + FixupBranch B(); + FixupBranch BL(); + + // Compare and Branch + void CBZ(ARM64Reg Rt, const void* ptr); + void CBNZ(ARM64Reg Rt, const void* ptr); + + // Conditional Branch + void B(CCFlags cond, const void* ptr); + + // Test and Branch + void TBZ(ARM64Reg Rt, u8 bits, const void* ptr); + void TBNZ(ARM64Reg Rt, u8 bits, const void* ptr); + + // Unconditional Branch + void B(const void* ptr); + void BL(const void* ptr); + + // Unconditional Branch (register) + void BR(ARM64Reg Rn); + void BLR(ARM64Reg Rn); + void RET(ARM64Reg Rn = X30); + void ERET(); + void DRPS(); + + // Exception generation + void SVC(u32 imm); + void HVC(u32 imm); + void SMC(u32 imm); + void BRK(u32 imm); + void HLT(u32 imm); + void DCPS1(u32 imm); + void DCPS2(u32 imm); + void DCPS3(u32 imm); + + // System + void _MSR(PStateField field, u8 imm); + void _MSR(PStateField field, ARM64Reg Rt); + void MRS(ARM64Reg Rt, PStateField field); + void CNTVCT(ARM64Reg Rt); + + void HINT(SystemHint op); + void CLREX(); + void DSB(BarrierType type); + void DMB(BarrierType type); + void ISB(BarrierType type); + + // Add/Subtract (Extended/Shifted register) + void ADD(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void ADD(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Option); + void ADDS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void ADDS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Option); + void SUB(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void SUB(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Option); + void SUBS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void SUBS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Option); + void CMN(ARM64Reg Rn, ARM64Reg Rm); + void CMN(ARM64Reg Rn, ARM64Reg Rm, ArithOption Option); + void CMP(ARM64Reg Rn, ARM64Reg Rm); + void CMP(ARM64Reg Rn, ARM64Reg Rm, ArithOption Option); + + // Add/Subtract (with carry) + void ADC(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void ADCS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void SBC(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void SBCS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + + // Conditional Compare (immediate) + void CCMN(ARM64Reg Rn, u32 imm, u32 nzcv, CCFlags cond); + void CCMP(ARM64Reg Rn, u32 imm, u32 nzcv, CCFlags cond); + + // Conditional Compare (register) + void CCMN(ARM64Reg Rn, ARM64Reg Rm, u32 nzcv, CCFlags cond); + void CCMP(ARM64Reg Rn, ARM64Reg Rm, u32 nzcv, CCFlags cond); + + // Conditional Select + void CSEL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, CCFlags cond); + void CSINC(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, CCFlags cond); + void CSINV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, CCFlags cond); + void CSNEG(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, CCFlags cond); + + // Aliases + void CSET(ARM64Reg Rd, CCFlags cond) + { + ARM64Reg zr = Is64Bit(Rd) ? ZR : WZR; + CSINC(Rd, zr, zr, (CCFlags)((u32)cond ^ 1)); + } + void CSETM(ARM64Reg Rd, CCFlags cond) + { + ARM64Reg zr = Is64Bit(Rd) ? ZR : WZR; + CSINV(Rd, zr, zr, (CCFlags)((u32)cond ^ 1)); + } + void NEG(ARM64Reg Rd, ARM64Reg Rs) { SUB(Rd, Is64Bit(Rd) ? ZR : WZR, Rs); } + // Data-Processing 1 source + void RBIT(ARM64Reg Rd, ARM64Reg Rn); + void REV16(ARM64Reg Rd, ARM64Reg Rn); + void REV32(ARM64Reg Rd, ARM64Reg Rn); + void REV64(ARM64Reg Rd, ARM64Reg Rn); + void CLZ(ARM64Reg Rd, ARM64Reg Rn); + void CLS(ARM64Reg Rd, ARM64Reg Rn); + + // Data-Processing 2 source + void UDIV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void SDIV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void LSLV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void LSRV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void ASRV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void RORV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void CRC32B(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void CRC32H(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void CRC32W(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void CRC32CB(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void CRC32CH(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void CRC32CW(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void CRC32X(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void CRC32CX(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + + // Data-Processing 3 source + void MADD(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra); + void MSUB(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra); + void SMADDL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra); + void SMULL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void SMSUBL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra); + void SMULH(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void UMADDL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra); + void UMULL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void UMSUBL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra); + void UMULH(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void MUL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void MNEG(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + + // Logical (shifted register) + void AND(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift); + void BIC(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift); + void ORR(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift); + void ORN(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift); + void EOR(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift); + void EON(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift); + void ANDS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift); + void BICS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift); + + // Wrap the above for saner syntax + void AND(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) { AND(Rd, Rn, Rm, ArithOption(Rd, ST_LSL, 0)); } + void BIC(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) { BIC(Rd, Rn, Rm, ArithOption(Rd, ST_LSL, 0)); } + void ORR(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) { ORR(Rd, Rn, Rm, ArithOption(Rd, ST_LSL, 0)); } + void ORN(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) { ORN(Rd, Rn, Rm, ArithOption(Rd, ST_LSL, 0)); } + void EOR(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) { EOR(Rd, Rn, Rm, ArithOption(Rd, ST_LSL, 0)); } + void EON(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) { EON(Rd, Rn, Rm, ArithOption(Rd, ST_LSL, 0)); } + void ANDS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) { ANDS(Rd, Rn, Rm, ArithOption(Rd, ST_LSL, 0)); } + void BICS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm) { BICS(Rd, Rn, Rm, ArithOption(Rd, ST_LSL, 0)); } + // Convenience wrappers around ORR. These match the official convenience syntax. + void MOV(ARM64Reg Rd, ARM64Reg Rm, ArithOption Shift); + void MOV(ARM64Reg Rd, ARM64Reg Rm); + void MVN(ARM64Reg Rd, ARM64Reg Rm); + + // Convenience wrappers around UBFM/EXTR. + void LSR(ARM64Reg Rd, ARM64Reg Rm, int shift); + void LSL(ARM64Reg Rd, ARM64Reg Rm, int shift); + void ASR(ARM64Reg Rd, ARM64Reg Rm, int shift); + void ROR_(ARM64Reg Rd, ARM64Reg Rm, int shift); + + // Logical (immediate) + void AND(ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms, bool invert = false); + void ANDS(ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms, bool invert = false); + void EOR(ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms, bool invert = false); + void ORR(ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms, bool invert = false); + void TST(ARM64Reg Rn, u32 immr, u32 imms, bool invert = false); + void TST(ARM64Reg Rn, ARM64Reg Rm) { ANDS(Is64Bit(Rn) ? ZR : WZR, Rn, Rm); } + // Add/subtract (immediate) + void ADD(ARM64Reg Rd, ARM64Reg Rn, u32 imm, bool shift = false); + void ADDS(ARM64Reg Rd, ARM64Reg Rn, u32 imm, bool shift = false); + void SUB(ARM64Reg Rd, ARM64Reg Rn, u32 imm, bool shift = false); + void SUBS(ARM64Reg Rd, ARM64Reg Rn, u32 imm, bool shift = false); + void CMP(ARM64Reg Rn, u32 imm, bool shift = false); + + // Data Processing (Immediate) + void MOVZ(ARM64Reg Rd, u32 imm, ShiftAmount pos = SHIFT_0); + void MOVN(ARM64Reg Rd, u32 imm, ShiftAmount pos = SHIFT_0); + void MOVK(ARM64Reg Rd, u32 imm, ShiftAmount pos = SHIFT_0); + + // Bitfield move + void BFM(ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms); + void SBFM(ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms); + void UBFM(ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms); + void BFI(ARM64Reg Rd, ARM64Reg Rn, u32 lsb, u32 width); + void UBFIZ(ARM64Reg Rd, ARM64Reg Rn, u32 lsb, u32 width); + + // Extract register (ROR with two inputs, if same then faster on A67) + void EXTR(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, u32 shift); + + // Aliases + void SXTB(ARM64Reg Rd, ARM64Reg Rn); + void SXTH(ARM64Reg Rd, ARM64Reg Rn); + void SXTW(ARM64Reg Rd, ARM64Reg Rn); + void UXTB(ARM64Reg Rd, ARM64Reg Rn); + void UXTH(ARM64Reg Rd, ARM64Reg Rn); + + void UBFX(ARM64Reg Rd, ARM64Reg Rn, int lsb, int width) { UBFM(Rd, Rn, lsb, lsb + width - 1); } + // Load Register (Literal) + void LDR(ARM64Reg Rt, u32 imm); + void LDRSW(ARM64Reg Rt, u32 imm); + void PRFM(ARM64Reg Rt, u32 imm); + + // Load/Store Exclusive + void STXRB(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rn); + void STLXRB(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rn); + void LDXRB(ARM64Reg Rt, ARM64Reg Rn); + void LDAXRB(ARM64Reg Rt, ARM64Reg Rn); + void STLRB(ARM64Reg Rt, ARM64Reg Rn); + void LDARB(ARM64Reg Rt, ARM64Reg Rn); + void STXRH(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rn); + void STLXRH(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rn); + void LDXRH(ARM64Reg Rt, ARM64Reg Rn); + void LDAXRH(ARM64Reg Rt, ARM64Reg Rn); + void STLRH(ARM64Reg Rt, ARM64Reg Rn); + void LDARH(ARM64Reg Rt, ARM64Reg Rn); + void STXR(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rn); + void STLXR(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rn); + void STXP(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn); + void STLXP(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn); + void LDXR(ARM64Reg Rt, ARM64Reg Rn); + void LDAXR(ARM64Reg Rt, ARM64Reg Rn); + void LDXP(ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn); + void LDAXP(ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn); + void STLR(ARM64Reg Rt, ARM64Reg Rn); + void LDAR(ARM64Reg Rt, ARM64Reg Rn); + + // Load/Store no-allocate pair (offset) + void STNP(ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn, u32 imm); + void LDNP(ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn, u32 imm); + + // Load/Store register (immediate indexed) + void STRB(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm); + void LDRB(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm); + void LDRSB(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm); + void STRH(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm); + void LDRH(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm); + void LDRSH(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm); + void STR(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm); + void LDR(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm); + void LDRSW(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm); + + // Load/Store register (register offset) + void STRB(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm); + void LDRB(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm); + void LDRSB(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm); + void STRH(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm); + void LDRH(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm); + void LDRSH(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm); + void STR(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm); + void LDR(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm); + void LDRSW(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm); + void PRFM(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm); + + // Load/Store register (unscaled offset) + void STURB(ARM64Reg Rt, ARM64Reg Rn, s32 imm); + void LDURB(ARM64Reg Rt, ARM64Reg Rn, s32 imm); + void LDURSB(ARM64Reg Rt, ARM64Reg Rn, s32 imm); + void STURH(ARM64Reg Rt, ARM64Reg Rn, s32 imm); + void LDURH(ARM64Reg Rt, ARM64Reg Rn, s32 imm); + void LDURSH(ARM64Reg Rt, ARM64Reg Rn, s32 imm); + void STUR(ARM64Reg Rt, ARM64Reg Rn, s32 imm); + void LDUR(ARM64Reg Rt, ARM64Reg Rn, s32 imm); + void LDURSW(ARM64Reg Rt, ARM64Reg Rn, s32 imm); + + // Load/Store pair + void LDP(IndexType type, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn, s32 imm); + void LDPSW(IndexType type, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn, s32 imm); + void STP(IndexType type, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn, s32 imm); + + void LDRGeneric(int size, bool signExtend, ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm); + void STRGeneric(int size, ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm); + + void LDRGeneric(int size, bool signExtend, IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm); + void STRGeneric(int size, IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm); + + // Address of label/page PC-relative + void ADR(ARM64Reg Rd, s32 imm); + void ADRP(ARM64Reg Rd, s32 imm); + + // Wrapper around MOVZ+MOVK + void MOVI2R(ARM64Reg Rd, u64 imm, bool optimize = true); + bool MOVI2R2(ARM64Reg Rd, u64 imm1, u64 imm2); + template + void MOVP2R(ARM64Reg Rd, P* ptr) + { + ASSERT_MSG(DYNA_REC, Is64Bit(Rd), "Can't store pointers in 32-bit registers"); + MOVI2R(Rd, (uintptr_t)ptr); + } + + // Wrapper around AND x, y, imm etc. If you are sure the imm will work, no need to pass a scratch + // register. + void ANDI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch = INVALID_REG); + void ANDSI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch = INVALID_REG); + void TSTI2R(ARM64Reg Rn, u64 imm, ARM64Reg scratch = INVALID_REG) + { + ANDSI2R(Is64Bit(Rn) ? ZR : WZR, Rn, imm, scratch); + } + void ORRI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch = INVALID_REG); + void EORI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch = INVALID_REG); + void CMPI2R(ARM64Reg Rn, u64 imm, ARM64Reg scratch = INVALID_REG); + + void ADDI2R_internal(ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool negative, bool flags, + ARM64Reg scratch); + void ADDI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch = INVALID_REG); + void ADDSI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch = INVALID_REG); + void SUBI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch = INVALID_REG); + void SUBSI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch = INVALID_REG); + + bool TryADDI2R(ARM64Reg Rd, ARM64Reg Rn, u32 imm); + bool TrySUBI2R(ARM64Reg Rd, ARM64Reg Rn, u32 imm); + bool TryCMPI2R(ARM64Reg Rn, u32 imm); + + bool TryANDI2R(ARM64Reg Rd, ARM64Reg Rn, u32 imm); + bool TryORRI2R(ARM64Reg Rd, ARM64Reg Rn, u32 imm); + bool TryEORI2R(ARM64Reg Rd, ARM64Reg Rn, u32 imm); + + // ABI related + void ABI_PushRegisters(BitSet32 registers); + void ABI_PopRegisters(BitSet32 registers, BitSet32 ignore_mask = BitSet32(0)); + + // Utility to generate a call to a std::function object. + // + // Unfortunately, calling operator() directly is undefined behavior in C++ + // (this method might be a thunk in the case of multi-inheritance) so we + // have to go through a trampoline function. + template + static T CallLambdaTrampoline(const std::function* f, Args... args) + { + return (*f)(args...); + } + + // This function expects you to have set up the state. + // Overwrites X0 and X30 + template + ARM64Reg ABI_SetupLambda(const std::function* f) + { + auto trampoline = &ARM64XEmitter::CallLambdaTrampoline; + MOVI2R(X30, (uintptr_t)trampoline); + MOVI2R(X0, (uintptr_t) const_cast((const void*)f)); + return X30; + } + + void QuickTailCall(ARM64Reg scratchreg, const void* func); + template + void QuickTailCall(ARM64Reg scratchreg, T func) + { + QuickTailCall(scratchreg, (const void*)func); + } + + // Plain function call + void QuickCallFunction(ARM64Reg scratchreg, const void* func); + template + void QuickCallFunction(ARM64Reg scratchreg, T func) + { + QuickCallFunction(scratchreg, (const void*)func); + } +}; + +class ARM64FloatEmitter +{ +public: + ARM64FloatEmitter(ARM64XEmitter* emit) : m_emit(emit) {} + void LDR(u8 size, IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm); + void STR(u8 size, IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm); + + // Loadstore unscaled + void LDUR(u8 size, ARM64Reg Rt, ARM64Reg Rn, s32 imm); + void STUR(u8 size, ARM64Reg Rt, ARM64Reg Rn, s32 imm); + + // Loadstore single structure + void LD1(u8 size, ARM64Reg Rt, u8 index, ARM64Reg Rn); + void LD1(u8 size, ARM64Reg Rt, u8 index, ARM64Reg Rn, ARM64Reg Rm); + void LD1R(u8 size, ARM64Reg Rt, ARM64Reg Rn); + void LD2R(u8 size, ARM64Reg Rt, ARM64Reg Rn); + void LD1R(u8 size, ARM64Reg Rt, ARM64Reg Rn, ARM64Reg Rm); + void LD2R(u8 size, ARM64Reg Rt, ARM64Reg Rn, ARM64Reg Rm); + void ST1(u8 size, ARM64Reg Rt, u8 index, ARM64Reg Rn); + void ST1(u8 size, ARM64Reg Rt, u8 index, ARM64Reg Rn, ARM64Reg Rm); + + // Loadstore multiple structure + void LD1(u8 size, u8 count, ARM64Reg Rt, ARM64Reg Rn); + void LD1(u8 size, u8 count, IndexType type, ARM64Reg Rt, ARM64Reg Rn, ARM64Reg Rm = SP); + void ST1(u8 size, u8 count, ARM64Reg Rt, ARM64Reg Rn); + void ST1(u8 size, u8 count, IndexType type, ARM64Reg Rt, ARM64Reg Rn, ARM64Reg Rm = SP); + + // Loadstore paired + void LDP(u8 size, IndexType type, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn, s32 imm); + void STP(u8 size, IndexType type, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn, s32 imm); + + // Loadstore register offset + void STR(u8 size, ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm); + void LDR(u8 size, ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm); + + // Scalar - 1 Source + void FABS(ARM64Reg Rd, ARM64Reg Rn); + void FNEG(ARM64Reg Rd, ARM64Reg Rn); + void FSQRT(ARM64Reg Rd, ARM64Reg Rn); + void FMOV(ARM64Reg Rd, ARM64Reg Rn, bool top = false); // Also generalized move between GPR/FP + + // Scalar - 2 Source + void FADD(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void FMUL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void FSUB(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void FDIV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void FMAX(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void FMIN(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void FMAXNM(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void FMINNM(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void FNMUL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + + // Scalar - 3 Source. Note - the accumulator is last on ARM! + void FMADD(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra); + void FMSUB(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra); + void FNMADD(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra); + void FNMSUB(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra); + + // Scalar floating point immediate + void FMOV(ARM64Reg Rd, uint8_t imm8); + + // Vector + void AND(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void BSL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void DUP(u8 size, ARM64Reg Rd, ARM64Reg Rn, u8 index); + void FABS(u8 size, ARM64Reg Rd, ARM64Reg Rn); + void FADD(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void FMAX(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void FMLA(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void FMLS(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void FMIN(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void FCVTL(u8 size, ARM64Reg Rd, ARM64Reg Rn); + void FCVTL2(u8 size, ARM64Reg Rd, ARM64Reg Rn); + void FCVTN(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn); + void FCVTN2(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn); + void FCVTZS(u8 size, ARM64Reg Rd, ARM64Reg Rn); + void FCVTZU(u8 size, ARM64Reg Rd, ARM64Reg Rn); + void FDIV(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void FMUL(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void FNEG(u8 size, ARM64Reg Rd, ARM64Reg Rn); + void FRECPE(u8 size, ARM64Reg Rd, ARM64Reg Rn); + void FRSQRTE(u8 size, ARM64Reg Rd, ARM64Reg Rn); + void FSUB(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void NOT(ARM64Reg Rd, ARM64Reg Rn); + void ORR(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void MOV(ARM64Reg Rd, ARM64Reg Rn) { ORR(Rd, Rn, Rn); } + void REV16(u8 size, ARM64Reg Rd, ARM64Reg Rn); + void REV32(u8 size, ARM64Reg Rd, ARM64Reg Rn); + void REV64(u8 size, ARM64Reg Rd, ARM64Reg Rn); + void SCVTF(u8 size, ARM64Reg Rd, ARM64Reg Rn); + void UCVTF(u8 size, ARM64Reg Rd, ARM64Reg Rn); + void SCVTF(u8 size, ARM64Reg Rd, ARM64Reg Rn, int scale); + void UCVTF(u8 size, ARM64Reg Rd, ARM64Reg Rn, int scale); + void SQXTN(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn); + void SQXTN2(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn); + void UQXTN(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn); + void UQXTN2(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn); + void XTN(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn); + void XTN2(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn); + + // Move + void DUP(u8 size, ARM64Reg Rd, ARM64Reg Rn); + void INS(u8 size, ARM64Reg Rd, u8 index, ARM64Reg Rn); + void INS(u8 size, ARM64Reg Rd, u8 index1, ARM64Reg Rn, u8 index2); + void UMOV(u8 size, ARM64Reg Rd, ARM64Reg Rn, u8 index); + void SMOV(u8 size, ARM64Reg Rd, ARM64Reg Rn, u8 index); + + // One source + void FCVT(u8 size_to, u8 size_from, ARM64Reg Rd, ARM64Reg Rn); + + // Scalar convert float to int, in a lot of variants. + // Note that the scalar version of this operation has two encodings, one that goes to an integer + // register + // and one that outputs to a scalar fp register. + void FCVTS(ARM64Reg Rd, ARM64Reg Rn, RoundingMode round); + void FCVTU(ARM64Reg Rd, ARM64Reg Rn, RoundingMode round); + + // Scalar convert int to float. No rounding mode specifier necessary. + void SCVTF(ARM64Reg Rd, ARM64Reg Rn); + void UCVTF(ARM64Reg Rd, ARM64Reg Rn); + + // Scalar fixed point to float. scale is the number of fractional bits. + void SCVTF(ARM64Reg Rd, ARM64Reg Rn, int scale); + void UCVTF(ARM64Reg Rd, ARM64Reg Rn, int scale); + + // Float comparison + void FCMP(ARM64Reg Rn, ARM64Reg Rm); + void FCMP(ARM64Reg Rn); + void FCMPE(ARM64Reg Rn, ARM64Reg Rm); + void FCMPE(ARM64Reg Rn); + void FCMEQ(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void FCMEQ(u8 size, ARM64Reg Rd, ARM64Reg Rn); + void FCMGE(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void FCMGE(u8 size, ARM64Reg Rd, ARM64Reg Rn); + void FCMGT(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void FCMGT(u8 size, ARM64Reg Rd, ARM64Reg Rn); + void FCMLE(u8 size, ARM64Reg Rd, ARM64Reg Rn); + void FCMLT(u8 size, ARM64Reg Rd, ARM64Reg Rn); + + // Conditional select + void FCSEL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, CCFlags cond); + + // Permute + void UZP1(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void TRN1(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void ZIP1(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void UZP2(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void TRN2(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void ZIP2(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + + // Shift by immediate + void SSHLL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift); + void SSHLL2(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift); + void USHLL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift); + void USHLL2(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift); + void SHRN(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift); + void SHRN2(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift); + void SXTL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn); + void SXTL2(u8 src_size, ARM64Reg Rd, ARM64Reg Rn); + void UXTL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn); + void UXTL2(u8 src_size, ARM64Reg Rd, ARM64Reg Rn); + + // vector x indexed element + void FMUL(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, u8 index); + void FMLA(u8 esize, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, u8 index); + + // Modified Immediate + void MOVI(u8 size, ARM64Reg Rd, u64 imm, u8 shift = 0); + void BIC(u8 size, ARM64Reg Rd, u8 imm, u8 shift = 0); + + void MOVI2F(ARM64Reg Rd, float value, ARM64Reg scratch = INVALID_REG, bool negate = false); + void MOVI2FDUP(ARM64Reg Rd, float value, ARM64Reg scratch = INVALID_REG); + + // ABI related + void ABI_PushRegisters(BitSet32 registers, ARM64Reg tmp = INVALID_REG); + void ABI_PopRegisters(BitSet32 registers, ARM64Reg tmp = INVALID_REG); + +private: + ARM64XEmitter* m_emit; + inline void Write32(u32 value) { m_emit->Write32(value); } + // Emitting functions + void EmitLoadStoreImmediate(u8 size, u32 opc, IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm); + void EmitScalar2Source(bool M, bool S, u32 type, u32 opcode, ARM64Reg Rd, ARM64Reg Rn, + ARM64Reg Rm); + void EmitThreeSame(bool U, u32 size, u32 opcode, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void EmitCopy(bool Q, u32 op, u32 imm5, u32 imm4, ARM64Reg Rd, ARM64Reg Rn); + void Emit2RegMisc(bool Q, bool U, u32 size, u32 opcode, ARM64Reg Rd, ARM64Reg Rn); + void EmitLoadStoreSingleStructure(bool L, bool R, u32 opcode, bool S, u32 size, ARM64Reg Rt, + ARM64Reg Rn); + void EmitLoadStoreSingleStructure(bool L, bool R, u32 opcode, bool S, u32 size, ARM64Reg Rt, + ARM64Reg Rn, ARM64Reg Rm); + void Emit1Source(bool M, bool S, u32 type, u32 opcode, ARM64Reg Rd, ARM64Reg Rn); + void EmitConversion(bool sf, bool S, u32 type, u32 rmode, u32 opcode, ARM64Reg Rd, ARM64Reg Rn); + void EmitConversion2(bool sf, bool S, bool direction, u32 type, u32 rmode, u32 opcode, int scale, + ARM64Reg Rd, ARM64Reg Rn); + void EmitCompare(bool M, bool S, u32 op, u32 opcode2, ARM64Reg Rn, ARM64Reg Rm); + void EmitCondSelect(bool M, bool S, CCFlags cond, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void EmitPermute(u32 size, u32 op, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm); + void EmitScalarImm(bool M, bool S, u32 type, u32 imm5, ARM64Reg Rd, u32 imm8); + void EmitShiftImm(bool Q, bool U, u32 immh, u32 immb, u32 opcode, ARM64Reg Rd, ARM64Reg Rn); + void EmitScalarShiftImm(bool U, u32 immh, u32 immb, u32 opcode, ARM64Reg Rd, ARM64Reg Rn); + void EmitLoadStoreMultipleStructure(u32 size, bool L, u32 opcode, ARM64Reg Rt, ARM64Reg Rn); + void EmitLoadStoreMultipleStructurePost(u32 size, bool L, u32 opcode, ARM64Reg Rt, ARM64Reg Rn, + ARM64Reg Rm); + void EmitScalar1Source(bool M, bool S, u32 type, u32 opcode, ARM64Reg Rd, ARM64Reg Rn); + void EmitVectorxElement(bool U, u32 size, bool L, u32 opcode, bool H, ARM64Reg Rd, ARM64Reg Rn, + ARM64Reg Rm); + void EmitLoadStoreUnscaled(u32 size, u32 op, ARM64Reg Rt, ARM64Reg Rn, s32 imm); + void EmitConvertScalarToInt(ARM64Reg Rd, ARM64Reg Rn, RoundingMode round, bool sign); + void EmitScalar3Source(bool isDouble, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra, + int opcode); + void EncodeLoadStorePair(u32 size, bool load, IndexType type, ARM64Reg Rt, ARM64Reg Rt2, + ARM64Reg Rn, s32 imm); + void EncodeLoadStoreRegisterOffset(u32 size, bool load, ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm); + void EncodeModImm(bool Q, u8 op, u8 cmode, u8 o2, ARM64Reg Rd, u8 abcdefgh); + + void SSHLL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift, bool upper); + void USHLL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift, bool upper); + void SHRN(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift, bool upper); + void SXTL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, bool upper); + void UXTL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, bool upper); +}; + +} \ No newline at end of file diff --git a/src/dolphin/ArmCommon.h b/src/dolphin/ArmCommon.h new file mode 100644 index 0000000..6d82e9d --- /dev/null +++ b/src/dolphin/ArmCommon.h @@ -0,0 +1,27 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "../types.h" + +enum CCFlags +{ + CC_EQ = 0, // Equal + CC_NEQ, // Not equal + CC_CS, // Carry Set + CC_CC, // Carry Clear + CC_MI, // Minus (Negative) + CC_PL, // Plus + CC_VS, // Overflow + CC_VC, // No Overflow + CC_HI, // Unsigned higher + CC_LS, // Unsigned lower or same + CC_GE, // Signed greater than or equal + CC_LT, // Signed less than + CC_GT, // Signed greater than + CC_LE, // Signed less than or equal + CC_AL, // Always (unconditional) 14 + CC_HS = CC_CS, // Alias of CC_CS Unsigned higher or same + CC_LO = CC_CC, // Alias of CC_CC Unsigned lower +}; +const u32 NO_COND = 0xE0000000; diff --git a/src/dolphin/BitUtils.h b/src/dolphin/BitUtils.h new file mode 100644 index 0000000..8b64a92 --- /dev/null +++ b/src/dolphin/BitUtils.h @@ -0,0 +1,254 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include +#include + +namespace Common +{ +/// +/// Retrieves the size of a type in bits. +/// +/// @tparam T Type to get the size of. +/// +/// @return the size of the type in bits. +/// +template +constexpr size_t BitSize() noexcept +{ + return sizeof(T) * CHAR_BIT; +} + +/// +/// Extracts a bit from a value. +/// +/// @param src The value to extract a bit from. +/// @param bit The bit to extract. +/// +/// @tparam T The type of the value. +/// +/// @return The extracted bit. +/// +template +constexpr T ExtractBit(const T src, const size_t bit) noexcept +{ + return (src >> bit) & static_cast(1); +} + +/// +/// Extracts a bit from a value. +/// +/// @param src The value to extract a bit from. +/// +/// @tparam bit The bit to extract. +/// @tparam T The type of the value. +/// +/// @return The extracted bit. +/// +template +constexpr T ExtractBit(const T src) noexcept +{ + static_assert(bit < BitSize(), "Specified bit must be within T's bit width."); + + return ExtractBit(src, bit); +} + +/// +/// Extracts a range of bits from a value. +/// +/// @param src The value to extract the bits from. +/// @param begin The beginning of the bit range. This is inclusive. +/// @param end The ending of the bit range. This is inclusive. +/// +/// @tparam T The type of the value. +/// @tparam Result The returned result type. This is the unsigned analog +/// of a signed type if a signed type is passed as T. +/// +/// @return The extracted bits. +/// +template > +constexpr Result ExtractBits(const T src, const size_t begin, const size_t end) noexcept +{ + return static_cast(((static_cast(src) << ((BitSize() - 1) - end)) >> + (BitSize() - end + begin - 1))); +} + +/// +/// Extracts a range of bits from a value. +/// +/// @param src The value to extract the bits from. +/// +/// @tparam begin The beginning of the bit range. This is inclusive. +/// @tparam end The ending of the bit range. This is inclusive. +/// @tparam T The type of the value. +/// @tparam Result The returned result type. This is the unsigned analog +/// of a signed type if a signed type is passed as T. +/// +/// @return The extracted bits. +/// +template > +constexpr Result ExtractBits(const T src) noexcept +{ + static_assert(begin < end, "Beginning bit must be less than the ending bit."); + static_assert(begin < BitSize(), "Beginning bit is larger than T's bit width."); + static_assert(end < BitSize(), "Ending bit is larger than T's bit width."); + + return ExtractBits(src, begin, end); +} + +/// +/// Rotates a value left (ROL). +/// +/// @param value The value to rotate. +/// @param amount The number of bits to rotate the value. +/// @tparam T An unsigned type. +/// +/// @return The rotated value. +/// +template +constexpr T RotateLeft(const T value, size_t amount) noexcept +{ + static_assert(std::is_unsigned(), "Can only rotate unsigned types left."); + + amount %= BitSize(); + + if (amount == 0) + return value; + + return static_cast((value << amount) | (value >> (BitSize() - amount))); +} + +/// +/// Rotates a value right (ROR). +/// +/// @param value The value to rotate. +/// @param amount The number of bits to rotate the value. +/// @tparam T An unsigned type. +/// +/// @return The rotated value. +/// +template +constexpr T RotateRight(const T value, size_t amount) noexcept +{ + static_assert(std::is_unsigned(), "Can only rotate unsigned types right."); + + amount %= BitSize(); + + if (amount == 0) + return value; + + return static_cast((value >> amount) | (value << (BitSize() - amount))); +} + +/// +/// Verifies whether the supplied value is a valid bit mask of the form 0b00...0011...11. +/// Both edge cases of all zeros and all ones are considered valid masks, too. +/// +/// @param mask The mask value to test for validity. +/// +/// @tparam T The type of the value. +/// +/// @return A bool indicating whether the mask is valid. +/// +template +constexpr bool IsValidLowMask(const T mask) noexcept +{ + static_assert(std::is_integral::value, "Mask must be an integral type."); + static_assert(std::is_unsigned::value, "Signed masks can introduce hard to find bugs."); + + // Can be efficiently determined without looping or bit counting. It's the counterpart + // to https://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2 + // and doesn't require special casing either edge case. + return (mask & (mask + 1)) == 0; +} + +/// +/// Reinterpret objects of one type as another by bit-casting between object representations. +/// +/// @remark This is the example implementation of std::bit_cast which is to be included +/// in C++2a. See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0476r2.html +/// for more details. The only difference is this variant is not constexpr, +/// as the mechanism for bit_cast requires a compiler built-in to have that quality. +/// +/// @param source The source object to convert to another representation. +/// +/// @tparam To The type to reinterpret source as. +/// @tparam From The initial type representation of source. +/// +/// @return The representation of type From as type To. +/// +/// @pre Both To and From types must be the same size +/// @pre Both To and From types must satisfy the TriviallyCopyable concept. +/// +template +inline To BitCast(const From& source) noexcept +{ + static_assert(sizeof(From) == sizeof(To), + "BitCast source and destination types must be equal in size."); + static_assert(std::is_trivially_copyable(), + "BitCast source type must be trivially copyable."); + static_assert(std::is_trivially_copyable(), + "BitCast destination type must be trivially copyable."); + + std::aligned_storage_t storage; + std::memcpy(&storage, &source, sizeof(storage)); + return reinterpret_cast(storage); +} + +template +class BitCastPtrType +{ +public: + static_assert(std::is_trivially_copyable(), + "BitCastPtr source type must be trivially copyable."); + static_assert(std::is_trivially_copyable(), + "BitCastPtr destination type must be trivially copyable."); + + explicit BitCastPtrType(PtrType* ptr) : m_ptr(ptr) {} + + // Enable operator= only for pointers to non-const data + template + inline typename std::enable_if() && !std::is_const()>::type + operator=(const S& source) + { + std::memcpy(m_ptr, &source, sizeof(source)); + } + + inline operator T() const + { + T result; + std::memcpy(&result, m_ptr, sizeof(result)); + return result; + } + +private: + PtrType* m_ptr; +}; + +// Provides an aliasing-safe alternative to reinterpret_cast'ing pointers to structs +// Conversion constructor and operator= provided for a convenient syntax. +// Usage: MyStruct s = BitCastPtr(some_ptr); +// BitCastPtr(some_ptr) = s; +template +inline auto BitCastPtr(PtrType* ptr) noexcept -> BitCastPtrType +{ + return BitCastPtrType{ptr}; +} + +template +void SetBit(T& value, size_t bit_number, bool bit_value) +{ + static_assert(std::is_unsigned(), "SetBit is only sane on unsigned types."); + + if (bit_value) + value |= (T{1} << bit_number); + else + value &= ~(T{1} << bit_number); +} + +} // namespace Common diff --git a/src/dolphin/Compat.h b/src/dolphin/Compat.h index f2f52a5..787d505 100644 --- a/src/dolphin/Compat.h +++ b/src/dolphin/Compat.h @@ -61,3 +61,15 @@ { \ printf(fmt "\n", ## __VA_ARGS__); \ } while (false) + +#if __cplusplus < 201703L +// cheat +namespace std +{ +template +T clamp(const T& v, const T& lo, const T& hi) +{ + return v < lo ? lo : (v > hi ? hi : v); +} +} +#endif \ No newline at end of file diff --git a/src/dolphin/MathUtil.cpp b/src/dolphin/MathUtil.cpp new file mode 100644 index 0000000..70f2ede --- /dev/null +++ b/src/dolphin/MathUtil.cpp @@ -0,0 +1,13 @@ +// Copyright 2008 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "MathUtil.h" + +#include + +// Calculate sum of a float list +float MathFloatVectorSum(const std::vector& Vec) +{ + return std::accumulate(Vec.begin(), Vec.end(), 0.0f); +} diff --git a/src/dolphin/MathUtil.h b/src/dolphin/MathUtil.h new file mode 100644 index 0000000..b1dbbae --- /dev/null +++ b/src/dolphin/MathUtil.h @@ -0,0 +1,121 @@ +// Copyright 2008 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include +#include + +#include "Compat.h" + +#include "../types.h" + +#ifdef _MSC_VER +#include +#endif + +namespace MathUtil +{ +constexpr double TAU = 6.2831853071795865; +constexpr double PI = TAU / 2; + +template +constexpr auto Sign(const T& val) -> decltype((T{} < val) - (val < T{})) +{ + return (T{} < val) - (val < T{}); +} + +template +constexpr auto Lerp(const T& x, const T& y, const F& a) -> decltype(x + (y - x) * a) +{ + return x + (y - x) * a; +} + +template +constexpr bool IsPow2(T imm) +{ + return imm > 0 && (imm & (imm - 1)) == 0; +} + +constexpr u32 NextPowerOf2(u32 value) +{ + --value; + value |= value >> 1; + value |= value >> 2; + value |= value >> 4; + value |= value >> 8; + value |= value >> 16; + ++value; + + return value; +} + +template +struct Rectangle +{ + T left{}; + T top{}; + T right{}; + T bottom{}; + + constexpr Rectangle() = default; + + constexpr Rectangle(T theLeft, T theTop, T theRight, T theBottom) + : left(theLeft), top(theTop), right(theRight), bottom(theBottom) + { + } + + constexpr bool operator==(const Rectangle& r) const + { + return left == r.left && top == r.top && right == r.right && bottom == r.bottom; + } + + T GetWidth() const { return abs(right - left); } + T GetHeight() const { return abs(bottom - top); } + // If the rectangle is in a coordinate system with a lower-left origin, use + // this Clamp. + void ClampLL(T x1, T y1, T x2, T y2) + { + left = std::clamp(left, x1, x2); + right = std::clamp(right, x1, x2); + top = std::clamp(top, y2, y1); + bottom = std::clamp(bottom, y2, y1); + } + + // If the rectangle is in a coordinate system with an upper-left origin, + // use this Clamp. + void ClampUL(T x1, T y1, T x2, T y2) + { + left = std::clamp(left, x1, x2); + right = std::clamp(right, x1, x2); + top = std::clamp(top, y1, y2); + bottom = std::clamp(bottom, y1, y2); + } +}; + +} // namespace MathUtil + +float MathFloatVectorSum(const std::vector&); + +// Rounds down. 0 -> undefined +inline int IntLog2(u64 val) +{ +#if defined(__GNUC__) + return 63 - __builtin_clzll(val); + +#elif defined(_MSC_VER) + unsigned long result = ULONG_MAX; + _BitScanReverse64(&result, val); + return result; + +#else + int result = -1; + while (val != 0) + { + val >>= 1; + ++result; + } + return result; +#endif +} -- cgit v1.2.3 From 0d83e98e04548eb7b860df53be0a76e9ecb0809b Mon Sep 17 00:00:00 2001 From: RSDuck Date: Tue, 4 Feb 2020 18:33:05 +0100 Subject: apply fixes for aarch64 linux by @nadiaholmquist --- src/ARMJIT_A64/ARMJIT_Compiler.cpp | 16 ++++++++++++++++ src/dolphin/Arm64Emitter.cpp | 2 +- src/dolphin/Arm64Emitter.h | 1 - 3 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ARMJIT_A64/ARMJIT_Compiler.cpp b/src/ARMJIT_A64/ARMJIT_Compiler.cpp index 89d0029..b598ac8 100644 --- a/src/ARMJIT_A64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_A64/ARMJIT_Compiler.cpp @@ -8,6 +8,9 @@ #include "../switch/compat_switch.h" extern char __start__; +#else +#include +#include #endif #include @@ -34,6 +37,9 @@ template <> const int RegisterCache::NativeRegsAvailable = 8; const int JitMemSize = 16 * 1024 * 1024; +#ifndef __SWITCH__ +u8 JitMem[JitMemSize]; +#endif void Compiler::MovePC() { @@ -76,6 +82,16 @@ Compiler::Compiler() SetCodeBase((u8*)JitRWStart, (u8*)JitRXStart); JitMemUseableSize = JitMemSize; Reset(); +#else + #else + u64 pageSize = sysconf(_SC_PAGE_SIZE); + u8* pageAligned = (u8*)(((u64)JitMem & ~(pageSize - 1)) + pageSize); + u64 alignedSize = (((u64)JitMem + sizeof(JitMem)) & ~(pageSize - 1)) - (u64)pageAligned; + mprotect(pageAligned, alignedSize, PROT_EXEC | PROT_READ | PROT_WRITE); + + SetCodeBase(pageAligned, pageAligned); + JitMemUseableSize = alignedSize; + Reset(); #endif for (int i = 0; i < 3; i++) diff --git a/src/dolphin/Arm64Emitter.cpp b/src/dolphin/Arm64Emitter.cpp index dbcf425..dd2416b 100644 --- a/src/dolphin/Arm64Emitter.cpp +++ b/src/dolphin/Arm64Emitter.cpp @@ -8,9 +8,9 @@ #include #include +#include "Compat.h" #include "Align.h" #include "Arm64Emitter.h" -#include "Assert.h" #include "BitUtils.h" #include "../types.h" #include "MathUtil.h" diff --git a/src/dolphin/Arm64Emitter.h b/src/dolphin/Arm64Emitter.h index 4cb9ff7..3d9d4ba 100644 --- a/src/dolphin/Arm64Emitter.h +++ b/src/dolphin/Arm64Emitter.h @@ -8,7 +8,6 @@ #include #include "ArmCommon.h" -#include "Assert.h" #include "BitSet.h" #include "Compat.h" -- cgit v1.2.3 From 3173e6e25d4456ec3ba26bed18d212bdf6cdfe81 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Tue, 4 Feb 2020 18:50:16 +0100 Subject: re add error for unsupported JIT platforms --- src/ARMJIT.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 561fabb..208801e 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -8,8 +8,10 @@ #include "ARMJIT_Internal.h" #if defined(__x86_64__) #include "ARMJIT_x64/ARMJIT_Compiler.h" -#else +#elif defined(__aarch64__) #include "ARMJIT_A64/ARMJIT_Compiler.h" +#else +#error "The current target platform doesn't have a JIT backend" #endif #include "ARMInterpreter_ALU.h" -- cgit v1.2.3 From 272542972775368cec990561e419e84e34e09fe8 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Tue, 4 Feb 2020 19:07:30 +0100 Subject: fix LDM usermode for aarch64 as well --- src/ARMJIT_A64/ARMJIT_Compiler.cpp | 3 ++- src/ARMJIT_A64/ARMJIT_Compiler.h | 2 ++ src/ARMJIT_A64/ARMJIT_LoadStore.cpp | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ARMJIT_A64/ARMJIT_Compiler.cpp b/src/ARMJIT_A64/ARMJIT_Compiler.cpp index b598ac8..d61cc9c 100644 --- a/src/ARMJIT_A64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_A64/ARMJIT_Compiler.cpp @@ -357,7 +357,8 @@ const Compiler::CompileFunc A_Comp[ARMInstrInfo::ak_Count] = // Branch F(BranchImm), F(BranchImm), F(BranchImm), F(BranchXchangeReg), F(BranchXchangeReg), // Special - NULL, NULL, NULL, NULL, NULL, NULL, NULL + NULL, NULL, NULL, NULL, NULL, NULL, NULL, + F(Nop) }; #undef F #define F(x) &Compiler::T_Comp_##x diff --git a/src/ARMJIT_A64/ARMJIT_Compiler.h b/src/ARMJIT_A64/ARMJIT_Compiler.h index 7e13507..5c9ef41 100644 --- a/src/ARMJIT_A64/ARMJIT_Compiler.h +++ b/src/ARMJIT_A64/ARMJIT_Compiler.h @@ -103,6 +103,8 @@ public: void LoadCPSR(); void SaveCPSR(bool markClean = true); + void Nop() {} + void A_Comp_ALUTriOp(); void A_Comp_ALUMovOp(); void A_Comp_ALUCmpOp(); diff --git a/src/ARMJIT_A64/ARMJIT_LoadStore.cpp b/src/ARMJIT_A64/ARMJIT_LoadStore.cpp index a5d0e3f..4fd8559 100644 --- a/src/ARMJIT_A64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_A64/ARMJIT_LoadStore.cpp @@ -639,7 +639,7 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc int reg = *it; - if (usermode && reg >= 8 && reg < 15) + if (usermode && !regs[15] && reg >= 8 && reg < 15) { if (RegCache.Mapping[reg] != INVALID_REG) MOV(W3, MapReg(reg)); -- cgit v1.2.3 From d2acceb36754df349cf5d483155f71332a50000c Mon Sep 17 00:00:00 2001 From: RSDuck Date: Fri, 7 Feb 2020 00:08:29 +0100 Subject: fixup for aarch64 JIT --- src/ARMJIT_A64/ARMJIT_Compiler.cpp | 1 - src/ARMJIT_RegisterCache.h | 10 ++++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ARMJIT_A64/ARMJIT_Compiler.cpp b/src/ARMJIT_A64/ARMJIT_Compiler.cpp index d61cc9c..2033307 100644 --- a/src/ARMJIT_A64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_A64/ARMJIT_Compiler.cpp @@ -83,7 +83,6 @@ Compiler::Compiler() JitMemUseableSize = JitMemSize; Reset(); #else - #else u64 pageSize = sysconf(_SC_PAGE_SIZE); u8* pageAligned = (u8*)(((u64)JitMem & ~(pageSize - 1)) + pageSize); u64 alignedSize = (((u64)JitMem + sizeof(JitMem)) & ~(pageSize - 1)) - (u64)pageAligned; diff --git a/src/ARMJIT_RegisterCache.h b/src/ARMJIT_RegisterCache.h index b894657..8460825 100644 --- a/src/ARMJIT_RegisterCache.h +++ b/src/ARMJIT_RegisterCache.h @@ -18,11 +18,15 @@ public: RegisterCache() {} - RegisterCache(T* compiler, FetchedInstr instrs[], int instrsCount) + RegisterCache(T* compiler, FetchedInstr instrs[], int instrsCount, bool pcAllocatableAsSrc = false) : Compiler(compiler), Instrs(instrs), InstrsCount(instrsCount) { for (int i = 0; i < 16; i++) Mapping[i] = (Reg)-1; + + PCAllocatableAsSrc = ~(pcAllocatableAsSrc + ? 0 + : (1 << 15)); } void UnloadRegister(int reg) @@ -120,7 +124,7 @@ public: for (int reg : neverNeededAgain) UnloadRegister(reg); - u16 necessaryRegs = ((instr.Info.SrcRegs & ~(1 << 15)) | instr.Info.DstRegs) & ~instr.Info.NotStrictlyNeeded; + u16 necessaryRegs = ((instr.Info.SrcRegs & PCAllocatableAsSrc) | instr.Info.DstRegs) & ~instr.Info.NotStrictlyNeeded; u16 writeRegs = instr.Info.DstRegs & ~instr.Info.NotStrictlyNeeded; BitSet16 needToBeLoaded(necessaryRegs & ~LoadedRegs); if (needToBeLoaded != BitSet16(0)) @@ -184,6 +188,8 @@ public: u16 LoadedRegs = 0; u16 DirtyRegs = 0; + u16 PCAllocatableAsSrc = 0; + T* Compiler; FetchedInstr* Instrs; -- cgit v1.2.3 From 262dc7ad0003e31078c219ba3f295e018cf14a1e Mon Sep 17 00:00:00 2001 From: RSDuck Date: Fri, 7 Feb 2020 00:12:09 +0100 Subject: this it should work --- src/ARMJIT_RegisterCache.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ARMJIT_RegisterCache.h b/src/ARMJIT_RegisterCache.h index 8460825..d4e5539 100644 --- a/src/ARMJIT_RegisterCache.h +++ b/src/ARMJIT_RegisterCache.h @@ -95,6 +95,20 @@ public: LiteralsLoaded = 0; } + BitSet32 GetPushRegs() + { + BitSet16 used; + for (int i = 0; i < InstrsCount; i++) + used |= BitSet16(Instrs[i].Info.SrcRegs | Instrs[i].Info.DstRegs); + + BitSet32 res; + u32 registersMax = std::min((int)used.Count(), NativeRegsAvailable); + for (int i = 0; i < registersMax; i++) + res |= BitSet32(1 << (int)NativeRegAllocOrder[i]); + + return res; + } + void Prepare(bool thumb, int i) { FetchedInstr instr = Instrs[i]; @@ -111,7 +125,7 @@ public: for (int j = 0; j < 16; j++) ranking[j] = 0; for (int j = i; j < InstrsCount; j++) - { + {s BitSet16 regsNeeded((Instrs[j].Info.SrcRegs & ~(1 << 15)) | Instrs[j].Info.DstRegs); futureNeeded |= regsNeeded.m_val; regsNeeded &= BitSet16(~Instrs[j].Info.NotStrictlyNeeded); -- cgit v1.2.3 From c8b7a34383c2800845892fd3c1a06c09dab89349 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Fri, 7 Feb 2020 00:21:08 +0100 Subject: git played a prank on me haha very funny --- src/ARMJIT_RegisterCache.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ARMJIT_RegisterCache.h b/src/ARMJIT_RegisterCache.h index d4e5539..5e18e84 100644 --- a/src/ARMJIT_RegisterCache.h +++ b/src/ARMJIT_RegisterCache.h @@ -125,7 +125,7 @@ public: for (int j = 0; j < 16; j++) ranking[j] = 0; for (int j = i; j < InstrsCount; j++) - {s + { BitSet16 regsNeeded((Instrs[j].Info.SrcRegs & ~(1 << 15)) | Instrs[j].Info.DstRegs); futureNeeded |= regsNeeded.m_val; regsNeeded &= BitSet16(~Instrs[j].Info.NotStrictlyNeeded); @@ -212,4 +212,4 @@ public: } -#endif \ No newline at end of file +#endif -- cgit v1.2.3 From 225f90cced63c3e282ade81b0c4807f96fc96d59 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Fri, 7 Feb 2020 00:34:26 +0100 Subject: the time of good commit names is long gone --- src/ARMJIT_A64/ARMJIT_Compiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/ARMJIT_A64/ARMJIT_Compiler.cpp b/src/ARMJIT_A64/ARMJIT_Compiler.cpp index 2033307..513c117 100644 --- a/src/ARMJIT_A64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_A64/ARMJIT_Compiler.cpp @@ -357,7 +357,7 @@ const Compiler::CompileFunc A_Comp[ARMInstrInfo::ak_Count] = F(BranchImm), F(BranchImm), F(BranchImm), F(BranchXchangeReg), F(BranchXchangeReg), // Special NULL, NULL, NULL, NULL, NULL, NULL, NULL, - F(Nop) + &Compiler::Nop }; #undef F #define F(x) &Compiler::T_Comp_##x -- cgit v1.2.3 From 5ab56cef5fdc9f49cdf19ab719c8d63dd831081f Mon Sep 17 00:00:00 2001 From: RSDuck Date: Fri, 7 Feb 2020 00:43:05 +0100 Subject: this mistake was phenomally stupid --- src/CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fce9e49..c34ba3b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,10 +54,6 @@ add_library(core STATIC if (ENABLE_JIT) target_sources(core PRIVATE ARMJIT.cpp - ARMJIT_x64/ARMJIT_Compiler.cpp - ARMJIT_x64/ARMJIT_ALU.cpp - ARMJIT_x64/ARMJIT_LoadStore.cpp - ARMJIT_x64/ARMJIT_Branch.cpp dolphin/CommonFuncs.cpp ) -- cgit v1.2.3 From 3098c6a9a03dc284b780b19962d35bebde62ea35 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Mon, 6 Apr 2020 12:25:35 +0200 Subject: preparations for block linking --- src/ARMJIT_Internal.h | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/ARMJIT_Internal.h b/src/ARMJIT_Internal.h index fb05f75..b968dcb 100644 --- a/src/ARMJIT_Internal.h +++ b/src/ARMJIT_Internal.h @@ -86,6 +86,14 @@ struct __attribute__((packed)) TinyVector Capacity = capacity; } + void SetLength(u16 length) + { + if (Capacity < length) + MakeCapacity(length); + + Length = length; + } + void Clear() { Length = 0; @@ -147,12 +155,7 @@ public: { NumInstrs = numInstrs; NumAddresses = numAddresses; - Data = new u32[numInstrs + numAddresses]; - } - - ~JitBlock() - { - delete[] Data; + Data.SetLength(numInstrs + numAddresses); } u32 StartAddr; @@ -160,13 +163,14 @@ public: u32 NumInstrs; u32 NumAddresses; + u32 NumLinks; JitBlockEntry EntryPoint; u32* Instrs() - { return Data; } + { return &Data[0]; } u32* AddressRanges() - { return Data + NumInstrs; } + { return &Data[NumInstrs]; } private: /* @@ -174,7 +178,7 @@ private: NumInstrs..<(NumLinks + NumInstrs) - pseudo physical addresses where the block is located (atleast one, the pseudo physical address of the block) */ - u32* Data; + TinyVector Data; }; // size should be 16 bytes because I'm to lazy to use mul and whatnot -- cgit v1.2.3 From 3ab9e4a4c91d482917782a7ac8f88beeab97a5b2 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Mon, 6 Apr 2020 12:31:20 +0200 Subject: arm64 fix itcm invalidation and ldm^/stm^ --- src/ARMJIT_A64/ARMJIT_LoadStore.cpp | 50 ++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/ARMJIT_A64/ARMJIT_LoadStore.cpp b/src/ARMJIT_A64/ARMJIT_LoadStore.cpp index 4fd8559..6cf710b 100644 --- a/src/ARMJIT_A64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_A64/ARMJIT_LoadStore.cpp @@ -109,12 +109,12 @@ void* Compiler::Gen_MemoryRoutine9(int size, bool store) ANDI2R(W3, W0, 0x7FFF & addressMask); if (store) { - LSR(W0, W3, 8); - ADDI2R(W0, W0, ExeMemRegionOffsets[exeMem_ITCM], W4); + ADDI2R(W0, W3, ExeMemRegionOffsets[exeMem_ITCM], W4); + LSR(W5, W0, 9); MOVP2R(X4, CodeRanges); - ADD(X4, X4, X0, ArithOption(X0, ST_LSL, 4)); + ADD(X4, X4, X5, ArithOption(X5, ST_LSL, 4)); static_assert(sizeof(AddressRange) == 16); - LDR(INDEX_UNSIGNED, W4, X4, offsetof(AddressRange, Blocks.Length)); + LDRH(INDEX_UNSIGNED, W4, X4, offsetof(AddressRange, Blocks.Length)); FixupBranch null = CBZ(W4); ABI_PushRegisters({1, 3, 30}); QuickCallFunction(X4, InvalidateByAddr); @@ -211,34 +211,34 @@ void* Compiler::Gen_MemoryRoutine9Seq(bool store, bool preinc) ANDI2R(W4, W0, ~3 & 0x7FFF); + ADDI2R(W6, W4, offsetof(ARMv5, ITCM), W5); if (store) { - LSR(W6, W4, 8); - ADDI2R(W6, W6, ExeMemRegionOffsets[exeMem_ITCM], W5); + LDR(X5, X1, ArithOption(X2, true)); + STR(W5, RCPU, X6); + } + else + { + LDR(W5, RCPU, X6); + STR(X5, X1, ArithOption(X2, true)); + } + + if (store) + { + ADDI2R(W4, W4, ExeMemRegionOffsets[exeMem_ITCM], W5); + LSR(W6, W4, 9); MOVP2R(X5, CodeRanges); ADD(X5, X5, X6, ArithOption(X6, ST_LSL, 4)); static_assert(sizeof(AddressRange) == 16); - LDR(INDEX_UNSIGNED, W5, X5, offsetof(AddressRange, Blocks.Length)); + LDRH(INDEX_UNSIGNED, W5, X5, offsetof(AddressRange, Blocks.Length)); FixupBranch null = CBZ(W5); ABI_PushRegisters({0, 1, 2, 4, 30}); - MOV(W0, W6); + MOV(W0, W4); QuickCallFunction(X5, InvalidateByAddr); ABI_PopRegisters({0, 1, 2, 4, 30}); SetJumpTarget(null); } - ADDI2R(W4, W4, offsetof(ARMv5, ITCM), W5); - if (store) - { - LDR(X5, X1, ArithOption(X2, true)); - STR(W5, RCPU, X4); - } - else - { - LDR(W5, RCPU, X4); - STR(X5, X1, ArithOption(X2, true)); - } - if (!preinc) ADD(W0, W0, 4); CBNZ(W2, loopStart); @@ -639,7 +639,7 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc int reg = *it; - if (usermode && !regs[15] && reg >= 8 && reg < 15) + if (usermode && reg >= 8 && reg < 15) { if (RegCache.Mapping[reg] != INVALID_REG) MOV(W3, MapReg(reg)); @@ -663,7 +663,7 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc second = MapReg(*nextReg); else LoadReg(*nextReg, W4); - + STP(INDEX_SIGNED, EncodeRegTo64(second), EncodeRegTo64(first), SP, i * 8 - 8); i--; @@ -696,7 +696,7 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc { Comp_AddCycles_CDI(); - if (usermode && (regs & BitSet16(0x7f00))) + if (usermode && !regs[15] && (regs & BitSet16(0x7f00))) UBFX(W0, RCPSR, 0, 5); int i = regsCount - 1; @@ -708,7 +708,7 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc int reg = *it; - if (usermode && reg >= 8 && reg < 15) + if (usermode && !regs[15] && reg >= 8 && reg < 15) { LDR(INDEX_UNSIGNED, W3, SP, i * 8); MOVI2R(W1, reg - 8); @@ -739,7 +739,7 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc if (*nextReg != 15) RegCache.DirtyRegs |= 1 << *nextReg; } - + LDP(INDEX_SIGNED, EncodeRegTo64(second), EncodeRegTo64(first), SP, i * 8 - 8); if (first == W3) -- cgit v1.2.3 From 1ad90cb334125090a0317efe522c36c6f285e556 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Thu, 16 Apr 2020 16:40:29 +0200 Subject: include more information in DataRegion --- src/ARM.h | 16 ++++++++-------- src/ARMJIT_A64/ARMJIT_Compiler.cpp | 4 ++-- src/ARMJIT_Internal.h | 7 +++++-- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 4 ++-- src/CP15.cpp | 12 ++++++++++++ 5 files changed, 29 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/ARM.h b/src/ARM.h index 7ef1938..ccef265 100644 --- a/src/ARM.h +++ b/src/ARM.h @@ -320,7 +320,7 @@ public: void DataRead8(u32 addr, u32* val) { *val = BusRead8(addr); - DataRegion = addr >> 24; + DataRegion = addr >> 20; DataCycles = NDS::ARM7MemTimings[addr >> 15][0]; } @@ -329,7 +329,7 @@ public: addr &= ~1; *val = BusRead16(addr); - DataRegion = addr >> 24; + DataRegion = addr >> 20; DataCycles = NDS::ARM7MemTimings[addr >> 15][0]; } @@ -338,7 +338,7 @@ public: addr &= ~3; *val = BusRead32(addr); - DataRegion = addr >> 24; + DataRegion = addr >> 20; DataCycles = NDS::ARM7MemTimings[addr >> 15][2]; } @@ -353,7 +353,7 @@ public: void DataWrite8(u32 addr, u8 val) { BusWrite8(addr, val); - DataRegion = addr >> 24; + DataRegion = addr >> 20; DataCycles = NDS::ARM7MemTimings[addr >> 15][0]; } @@ -362,7 +362,7 @@ public: addr &= ~1; BusWrite16(addr, val); - DataRegion = addr >> 24; + DataRegion = addr >> 20; DataCycles = NDS::ARM7MemTimings[addr >> 15][0]; } @@ -371,7 +371,7 @@ public: addr &= ~3; BusWrite32(addr, val); - DataRegion = addr >> 24; + DataRegion = addr >> 20; DataCycles = NDS::ARM7MemTimings[addr >> 15][2]; } @@ -402,7 +402,7 @@ public: s32 numC = NDS::ARM7MemTimings[CodeCycles][(CPSR&0x20)?0:2]; s32 numD = DataCycles; - if (DataRegion == 0x02) // mainRAM + if ((DataRegion >> 4) == 0x02) // mainRAM { if (CodeRegion == 0x02) Cycles += numC + numD; @@ -429,7 +429,7 @@ public: s32 numC = NDS::ARM7MemTimings[CodeCycles][(CPSR&0x20)?0:2]; s32 numD = DataCycles; - if (DataRegion == 0x02) + if ((DataRegion >> 4) == 0x02) { if (CodeRegion == 0x02) Cycles += numC + numD; diff --git a/src/ARMJIT_A64/ARMJIT_Compiler.cpp b/src/ARMJIT_A64/ARMJIT_Compiler.cpp index 513c117..00fa436 100644 --- a/src/ARMJIT_A64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_A64/ARMJIT_Compiler.cpp @@ -650,7 +650,7 @@ void Compiler::Comp_AddCycles_CDI() s32 numC = NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2]; s32 numD = CurInstr.DataCycles; - if (CurInstr.DataRegion == 0x02) // mainRAM + if ((CurInstr.DataRegion >> 4) == 0x02) // mainRAM { if (CodeRegion == 0x02) cycles = numC + numD; @@ -695,7 +695,7 @@ void Compiler::Comp_AddCycles_CD() s32 numC = NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2]; s32 numD = CurInstr.DataCycles; - if (CurInstr.DataRegion == 0x02) + if ((CurInstr.DataRegion >> 4) == 0x02) { if (CodeRegion == 0x02) cycles += numC + numD; diff --git a/src/ARMJIT_Internal.h b/src/ARMJIT_Internal.h index b968dcb..0d6add9 100644 --- a/src/ARMJIT_Internal.h +++ b/src/ARMJIT_Internal.h @@ -40,9 +40,9 @@ struct FetchedInstr u32 Instr; u32 Addr; - u8 CodeCycles; u8 DataCycles; - u8 DataRegion; + u16 CodeCycles; + u32 DataRegion; ARMInstrInfo::Info Info; }; @@ -195,6 +195,9 @@ typedef void (*InterpreterFunc)(ARM* cpu); extern InterpreterFunc InterpretARM[]; extern InterpreterFunc InterpretTHUMB[]; +extern u8 MemRegion9[0x80000]; +extern u8 MemRegion7[0x80000]; + void* GetFuncForAddr(ARM* cpu, u32 addr, bool store, int size); } diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index 5afe842..d69bdff 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -578,7 +578,7 @@ void Compiler::Comp_AddCycles_CDI() s32 numC = NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2]; s32 numD = CurInstr.DataCycles; - if (CurInstr.DataRegion == 0x02) // mainRAM + if ((CurInstr.DataRegion >> 4) == 0x02) // mainRAM { if (CodeRegion == 0x02) cycles = numC + numD; @@ -623,7 +623,7 @@ void Compiler::Comp_AddCycles_CD() s32 numC = NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2]; s32 numD = CurInstr.DataCycles; - if (CurInstr.DataRegion == 0x02) + if ((CurInstr.DataRegion >> 4) == 0x02) { if (CodeRegion == 0x02) cycles += numC + numD; diff --git a/src/CP15.cpp b/src/CP15.cpp index 8a9b31d..e168d7f 100644 --- a/src/CP15.cpp +++ b/src/CP15.cpp @@ -729,6 +729,8 @@ u32 ARMv5::CodeRead32(u32 addr, bool branch) void ARMv5::DataRead8(u32 addr, u32* val) { + DataRegion = addr >> 12; + if (addr < ITCMSize) { DataCycles = 1; @@ -748,6 +750,8 @@ void ARMv5::DataRead8(u32 addr, u32* val) void ARMv5::DataRead16(u32 addr, u32* val) { + DataRegion = addr >> 12; + addr &= ~1; if (addr < ITCMSize) @@ -769,6 +773,8 @@ void ARMv5::DataRead16(u32 addr, u32* val) void ARMv5::DataRead32(u32 addr, u32* val) { + DataRegion = addr >> 12; + addr &= ~3; if (addr < ITCMSize) @@ -811,6 +817,8 @@ void ARMv5::DataRead32S(u32 addr, u32* val) void ARMv5::DataWrite8(u32 addr, u8 val) { + DataRegion = addr >> 12; + if (addr < ITCMSize) { DataCycles = 1; @@ -833,6 +841,8 @@ void ARMv5::DataWrite8(u32 addr, u8 val) void ARMv5::DataWrite16(u32 addr, u16 val) { + DataRegion = addr >> 12; + addr &= ~1; if (addr < ITCMSize) @@ -857,6 +867,8 @@ void ARMv5::DataWrite16(u32 addr, u16 val) void ARMv5::DataWrite32(u32 addr, u32 val) { + DataRegion = addr >> 12; + addr &= ~3; if (addr < ITCMSize) -- cgit v1.2.3 From 1c07932b40e6e072c6ea66c49889860252e45186 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sat, 25 Apr 2020 13:40:51 +0200 Subject: implement block linking + some refactoring currently only supported for x64 --- .gitignore | 2 + src/ARM.cpp | 37 +- src/ARM.h | 32 +- src/ARMJIT.cpp | 223 +++- src/ARMJIT.h | 10 +- src/ARMJIT_Internal.h | 24 +- src/ARMJIT_x64/ARMJIT_Branch.cpp | 23 +- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 140 +- src/ARMJIT_x64/ARMJIT_Compiler.h | 19 +- src/ARMJIT_x64/ARMJIT_GenOffsets.cpp | 15 + src/ARMJIT_x64/ARMJIT_Linkage.s | 74 ++ src/ARMJIT_x64/ARMJIT_Offsets.h | 3 + src/CMakeLists.txt | 6 + src/Config.cpp | 8 +- src/Config.h | 6 +- src/xxhash/xxh3.h | 2390 ++++++++++++++++++++++++++++++++++ src/xxhash/xxhash.c | 43 + src/xxhash/xxhash.h | 1965 ++++++++++++++++++++++++++++ 18 files changed, 4870 insertions(+), 150 deletions(-) create mode 100644 src/ARMJIT_x64/ARMJIT_GenOffsets.cpp create mode 100644 src/ARMJIT_x64/ARMJIT_Linkage.s create mode 100644 src/ARMJIT_x64/ARMJIT_Offsets.h create mode 100644 src/xxhash/xxh3.h create mode 100644 src/xxhash/xxhash.c create mode 100644 src/xxhash/xxhash.h (limited to 'src') diff --git a/.gitignore b/.gitignore index dd81614..3c87740 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ melon_grc.h cmake-build cmake-build-debug .idea + +*.exe diff --git a/src/ARM.cpp b/src/ARM.cpp index 896bb5c..3eac74d 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -252,15 +252,15 @@ void ARMv5::JumpTo(u32 addr, bool restorecpsr) if (addr & 0x2) { NextInstr[0] = CodeRead32(addr-2, true) >> 16; - Cycles += CodeCycles; + Cycles -= CodeCycles; NextInstr[1] = CodeRead32(addr+2, false); - Cycles += CodeCycles; + Cycles -= CodeCycles; } else { NextInstr[0] = CodeRead32(addr, true); NextInstr[1] = NextInstr[0] >> 16; - Cycles += CodeCycles; + Cycles -= CodeCycles; } CPSR |= 0x20; @@ -273,9 +273,9 @@ void ARMv5::JumpTo(u32 addr, bool restorecpsr) if (newregion != oldregion) SetupCodeMem(addr); NextInstr[0] = CodeRead32(addr, true); - Cycles += CodeCycles; + Cycles -= CodeCycles; NextInstr[1] = CodeRead32(addr+4, false); - Cycles += CodeCycles; + Cycles -= CodeCycles; CPSR &= ~0x20; } @@ -315,7 +315,7 @@ void ARMv4::JumpTo(u32 addr, bool restorecpsr) NextInstr[0] = CodeRead16(addr); NextInstr[1] = CodeRead16(addr+2); - Cycles += NDS::ARM7MemTimings[CodeCycles][0] + NDS::ARM7MemTimings[CodeCycles][1]; + Cycles -= NDS::ARM7MemTimings[CodeCycles][0] + NDS::ARM7MemTimings[CodeCycles][1]; CPSR |= 0x20; } @@ -328,7 +328,7 @@ void ARMv4::JumpTo(u32 addr, bool restorecpsr) NextInstr[0] = CodeRead32(addr); NextInstr[1] = CodeRead32(addr+4); - Cycles += NDS::ARM7MemTimings[CodeCycles][2] + NDS::ARM7MemTimings[CodeCycles][3]; + Cycles -= NDS::ARM7MemTimings[CodeCycles][2] + NDS::ARM7MemTimings[CodeCycles][3]; CPSR &= ~0x20; } @@ -587,7 +587,7 @@ void ARMv5::Execute() }*/ if (IRQ) TriggerIRQ(); - NDS::ARM9Timestamp += Cycles; + NDS::ARM9Timestamp -= Cycles; Cycles = 0; } @@ -627,14 +627,16 @@ void ARMv5::ExecuteJIT() return; } - ARMJIT::JitBlockEntry block = ARMJIT::LookUpBlock<0>(instrAddr); + // hack so Cycles <= 0 becomes Cycles < 0 + Cycles = NDS::ARM9Target - NDS::ARM9Timestamp - 1; + + ARMJIT::JitBlockEntry block = ARMJIT::LookUpBlockEntry(ARMJIT::TranslateAddr<0>(instrAddr)); if (block) - Cycles += block(); + ARM_Dispatch(this, block); else ARMJIT::CompileBlock(this); - NDS::ARM9Timestamp += Cycles; - Cycles = 0; + NDS::ARM9Timestamp = NDS::ARM9Target - (Cycles + 1); if (StopExecution) { @@ -728,7 +730,7 @@ void ARMv4::Execute() }*/ if (IRQ) TriggerIRQ(); - NDS::ARM7Timestamp += Cycles; + NDS::ARM7Timestamp -= Cycles; Cycles = 0; } @@ -768,14 +770,15 @@ void ARMv4::ExecuteJIT() return; } - ARMJIT::JitBlockEntry block = ARMJIT::LookUpBlock<1>(instrAddr); + Cycles = NDS::ARM7Target - NDS::ARM7Timestamp - 1; + + ARMJIT::JitBlockEntry block = ARMJIT::LookUpBlockEntry(ARMJIT::TranslateAddr<1>(instrAddr)); if (block) - Cycles += block(); + ARM_Dispatch(this, block); else ARMJIT::CompileBlock(this); - NDS::ARM7Timestamp += Cycles; - Cycles = 0; + NDS::ARM7Timestamp = NDS::ARM7Target - (Cycles + 1); // TODO optimize this shit!!! if (StopExecution) diff --git a/src/ARM.h b/src/ARM.h index ccef265..b71102a 100644 --- a/src/ARM.h +++ b/src/ARM.h @@ -193,14 +193,14 @@ public: { // code only. always nonseq 32-bit for ARM9. s32 numC = (R[15] & 0x2) ? 0 : CodeCycles; - Cycles += numC; + Cycles -= numC; } void AddCycles_CI(s32 numI) { // code+internal s32 numC = (R[15] & 0x2) ? 0 : CodeCycles; - Cycles += numC + numI; + Cycles -= numC + numI; } void AddCycles_CDI() @@ -211,9 +211,9 @@ public: s32 numD = DataCycles; //if (DataRegion != CodeRegion) - Cycles += std::max(numC + numD - 6, std::max(numC, numD)); + Cycles -= std::max(numC + numD - 6, std::max(numC, numD)); //else - // Cycles += numC + numD; + // Cycles -= numC + numD; } void AddCycles_CD() @@ -223,9 +223,9 @@ public: s32 numD = DataCycles; //if (DataRegion != CodeRegion) - Cycles += std::max(numC + numD - 6, std::max(numC, numD)); + Cycles -= std::max(numC + numD - 6, std::max(numC, numD)); //else - // Cycles += numC + numD; + // Cycles -= numC + numD; } void GetCodeMemRegion(u32 addr, NDS::MemRegion* region); @@ -387,13 +387,13 @@ public: void AddCycles_C() { // code only. this code fetch is sequential. - Cycles += NDS::ARM7MemTimings[CodeCycles][(CPSR&0x20)?1:3]; + Cycles -= NDS::ARM7MemTimings[CodeCycles][(CPSR&0x20)?1:3]; } void AddCycles_CI(s32 num) { // code+internal. results in a nonseq code fetch. - Cycles += NDS::ARM7MemTimings[CodeCycles][(CPSR&0x20)?0:2] + num; + Cycles -= NDS::ARM7MemTimings[CodeCycles][(CPSR&0x20)?0:2] + num; } void AddCycles_CDI() @@ -405,21 +405,21 @@ public: if ((DataRegion >> 4) == 0x02) // mainRAM { if (CodeRegion == 0x02) - Cycles += numC + numD; + Cycles -= numC + numD; else { numC++; - Cycles += std::max(numC + numD - 3, std::max(numC, numD)); + Cycles -= std::max(numC + numD - 3, std::max(numC, numD)); } } else if (CodeRegion == 0x02) { numD++; - Cycles += std::max(numC + numD - 3, std::max(numC, numD)); + Cycles -= std::max(numC + numD - 3, std::max(numC, numD)); } else { - Cycles += numC + numD + 1; + Cycles -= numC + numD + 1; } } @@ -432,17 +432,17 @@ public: if ((DataRegion >> 4) == 0x02) { if (CodeRegion == 0x02) - Cycles += numC + numD; + Cycles -= numC + numD; else - Cycles += std::max(numC + numD - 3, std::max(numC, numD)); + Cycles -= std::max(numC + numD - 3, std::max(numC, numD)); } else if (CodeRegion == 0x02) { - Cycles += std::max(numC + numD - 3, std::max(numC, numD)); + Cycles -= std::max(numC + numD - 3, std::max(numC, numD)); } else { - Cycles += numC + numD; + Cycles -= numC + numD; } } }; diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 208801e..cc8d4ce 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -2,6 +2,10 @@ #include #include +#include + +#define XXH_STATIC_LINKING_ONLY +#include "xxhash/xxhash.h" #include "Config.h" @@ -113,16 +117,101 @@ const static ExeMemKind JIT_MEM[2][32] = { u32 AddrTranslate9[0x2000]; u32 AddrTranslate7[0x4000]; -JitBlockEntry FastBlockAccess[ExeMemSpaceSize / 2]; AddressRange CodeRanges[ExeMemSpaceSize / 512]; -TinyVector JitBlocks; -JitBlock* RestoreCandidates[0x1000] = {NULL}; +std::unordered_map JitBlocks; -u32 HashRestoreCandidate(u32 pseudoPhysicalAddr) +template +struct UnreliableHashTable { - return (u32)(((u64)pseudoPhysicalAddr * 11400714819323198485llu) >> 53); -} + struct Bucket + { + K KeyA, KeyB; + V ValA, ValB; + }; + + Bucket Table[Size]; + + void Reset() + { + for (int i = 0; i < Size; i++) + { + Table[i].ValA = Table[i].ValB = InvalidValue; + } + } + + UnreliableHashTable() + { + Reset(); + } + + V Insert(K key, V value) + { + u32 slot = XXH3_64bits(&key, sizeof(K)) & (Size - 1); + Bucket* bucket = &Table[slot]; + + if (bucket->ValA == value || bucket->ValB == value) + { + return InvalidValue; + } + else if (bucket->ValA == InvalidValue) + { + bucket->KeyA = key; + bucket->ValA = value; + } + else if (bucket->ValB == InvalidValue) + { + bucket->KeyB = key; + bucket->ValB = value; + } + else + { + V prevVal = bucket->ValB; + bucket->KeyB = bucket->KeyA; + bucket->ValB = bucket->ValA; + bucket->KeyA = key; + bucket->ValA = value; + return prevVal; + } + + return InvalidValue; + } + + void Remove(K key) + { + u32 slot = XXH3_64bits(&key, sizeof(K)) & (Size - 1); + Bucket* bucket = &Table[slot]; + + if (bucket->KeyA == key && bucket->ValA != InvalidValue) + { + bucket->ValA = InvalidValue; + if (bucket->ValB != InvalidValue) + { + bucket->KeyA = bucket->KeyB; + bucket->ValA = bucket->ValB; + bucket->ValB = InvalidValue; + } + } + if (bucket->KeyB == key && bucket->ValB != InvalidValue) + bucket->ValB = InvalidValue; + } + + V LookUp(K addr) + { + u32 slot = XXH3_64bits(&addr, 4) & (Size - 1); + Bucket* bucket = &Table[slot]; + + if (bucket->ValA != InvalidValue && bucket->KeyA == addr) + return bucket->ValA; + if (bucket->ValB != InvalidValue && bucket->KeyB == addr) + return bucket->ValB; + + return InvalidValue; + } +}; + +UnreliableHashTable RestoreCandidates; +UnreliableHashTable FastBlockLookUp; void Init() { @@ -396,9 +485,8 @@ void CompileBlock(ARM* cpu) u32 nextInstr[2] = {cpu->NextInstr[0], cpu->NextInstr[1]}; u32 nextInstrAddr[2] = {blockAddr, r15}; - JIT_DEBUGPRINT("start block %x %08x (%x) %p %p (region invalidates %dx)\n", - blockAddr, cpu->CPSR, pseudoPhysicalAddr, FastBlockAccess[pseudoPhysicalAddr / 2], - cpu->Num == 0 ? LookUpBlock<0>(blockAddr) : LookUpBlock<1>(blockAddr), + JIT_DEBUGPRINT("start block %x %08x (%x) (region invalidates %dx)\n", + blockAddr, cpu->CPSR, pseudoPhysicalAddr, CodeRanges[pseudoPhysicalAddr / 512].TimesInvalidated); u32 lastSegmentStart = blockAddr; @@ -534,6 +622,8 @@ void CompileBlock(ARM* cpu) if (staticBranch) { + instrs[i].BranchFlags |= branch_StaticTarget; + bool isBackJump = false; if (hasBranched) { @@ -604,12 +694,11 @@ void CompileBlock(ARM* cpu) FloodFillSetFlags(instrs, i - 2, !secondaryFlagReadCond ? instrs[i - 1].Info.ReadFlags : 0xF); } while(!instrs[i - 1].Info.EndBlock && i < Config::JIT_MaxBlockSize && !cpu->Halted && (!cpu->IRQ || (cpu->CPSR & 0x80))); - u32 restoreSlot = HashRestoreCandidate(pseudoPhysicalAddr); - JitBlock* prevBlock = RestoreCandidates[restoreSlot]; + JitBlock* prevBlock = RestoreCandidates.LookUp(pseudoPhysicalAddr); bool mayRestore = true; - if (prevBlock && prevBlock->PseudoPhysicalAddr == pseudoPhysicalAddr) + if (prevBlock) { - RestoreCandidates[restoreSlot] = NULL; + RestoreCandidates.Remove(pseudoPhysicalAddr); if (prevBlock->NumInstrs == i) { for (int j = 0; j < i; j++) @@ -661,7 +750,7 @@ void CompileBlock(ARM* cpu) FloodFillSetFlags(instrs, i - 1, 0xF); - block->EntryPoint = compiler->CompileBlock(cpu, thumb, instrs, i); + block->EntryPoint = compiler->CompileBlock(pseudoPhysicalAddr, cpu, thumb, instrs, i); } else { @@ -675,9 +764,8 @@ void CompileBlock(ARM* cpu) CodeRanges[addresseRanges[j] / 512].Blocks.Add(block); } - FastBlockAccess[block->PseudoPhysicalAddr / 2] = block->EntryPoint; - - JitBlocks.Add(block); + JitBlocks[pseudoPhysicalAddr] = block; + FastBlockLookUp.Insert(pseudoPhysicalAddr, compiler->SubEntryOffset(block->EntryPoint)); } void InvalidateByAddr(u32 pseudoPhysical, bool mayRestore) @@ -701,18 +789,17 @@ void InvalidateByAddr(u32 pseudoPhysical, bool mayRestore) } } - bool removed = JitBlocks.RemoveByValue(block); - assert(removed); + for (int j = 0; j < block->NumLinks(); j++) + compiler->UnlinkBlock(block->Links()[j]); - FastBlockAccess[block->PseudoPhysicalAddr / 2] = NULL; + JitBlocks.erase(block->PseudoPhysicalAddr); + FastBlockLookUp.Remove(block->PseudoPhysicalAddr); if (mayRestore) { - u32 slot = HashRestoreCandidate(block->PseudoPhysicalAddr); - if (RestoreCandidates[slot] && RestoreCandidates[slot] != block) - delete RestoreCandidates[slot]; - - RestoreCandidates[slot] = block; + JitBlock* prevBlock = RestoreCandidates.Insert(block->PseudoPhysicalAddr, block); + if (prevBlock) + delete prevBlock; } } if ((range->TimesInvalidated + 1) > range->TimesInvalidated) @@ -738,47 +825,54 @@ void InvalidateITCM(u32 addr) void InvalidateAll() { JIT_DEBUGPRINT("invalidating all %x\n", JitBlocks.Length); - for (int i = 0; i < JitBlocks.Length; i++) + for (auto it : JitBlocks) { - JitBlock* block = JitBlocks[i]; + JitBlock* block = it.second; - FastBlockAccess[block->PseudoPhysicalAddr / 2] = NULL; - - for (int j = 0; j < block->NumAddresses; j++) + FastBlockLookUp.Remove(block->PseudoPhysicalAddr); + + for (int i = 0; i < block->NumAddresses; i++) { - u32 addr = block->AddressRanges()[j]; + u32 addr = block->AddressRanges()[i]; AddressRange* range = &CodeRanges[addr / 512]; range->Blocks.Clear(); if (range->TimesInvalidated + 1 > range->TimesInvalidated) range->TimesInvalidated++; } + for (int i = 0; i < block->NumLinks(); i++) + compiler->UnlinkBlock(block->Links()[i]); + block->ResetLinks(); - u32 slot = HashRestoreCandidate(block->PseudoPhysicalAddr); - if (RestoreCandidates[slot] && RestoreCandidates[slot] != block) - delete RestoreCandidates[slot]; - - RestoreCandidates[slot] = block; + JitBlock* prevBlock = RestoreCandidates.Insert(block->PseudoPhysicalAddr, block); + if (prevBlock) + delete prevBlock; } - JitBlocks.Clear(); + JitBlocks.clear(); } void ResetBlockCache() { printf("Resetting JIT block cache...\n"); - - memset(FastBlockAccess, 0, sizeof(FastBlockAccess)); - for (int i = 0; i < sizeof(RestoreCandidates)/sizeof(RestoreCandidates[0]); i++) + + FastBlockLookUp.Reset(); + RestoreCandidates.Reset(); + for (int i = 0; i < sizeof(RestoreCandidates.Table)/sizeof(RestoreCandidates.Table[0]); i++) { - if (RestoreCandidates[i]) + if (RestoreCandidates.Table[i].ValA) { - delete RestoreCandidates[i]; - RestoreCandidates[i] = NULL; + delete RestoreCandidates.Table[i].ValA; + RestoreCandidates.Table[i].ValA = NULL; + } + if (RestoreCandidates.Table[i].ValA) + { + delete RestoreCandidates.Table[i].ValB; + RestoreCandidates.Table[i].ValB = NULL; } } - for (int i = 0; i < JitBlocks.Length; i++) + for (auto it : JitBlocks) { - JitBlock* block = JitBlocks[i]; + JitBlock* block = it.second; for (int j = 0; j < block->NumAddresses; j++) { u32 addr = block->AddressRanges()[j]; @@ -788,11 +882,43 @@ void ResetBlockCache() } delete block; } - JitBlocks.Clear(); + JitBlocks.clear(); compiler->Reset(); } +JitBlockEntry LookUpBlockEntry(u32 addr) +{ + u32 entryOffset = FastBlockLookUp.LookUp(addr); + if (entryOffset != UINT32_MAX) + return compiler->AddEntryOffset(entryOffset); + + auto block = JitBlocks.find(addr); + if (block != JitBlocks.end()) + { + FastBlockLookUp.Insert(addr, compiler->SubEntryOffset(block->second->EntryPoint)); + return block->second->EntryPoint; + } + return NULL; +} + +template +void LinkBlock(ARM* cpu, u32 codeOffset) +{ + u32 targetPseudoPhys = TranslateAddr(cpu->R[15] - ((cpu->CPSR&0x20)?2:4)); + auto block = JitBlocks.find(targetPseudoPhys); + if (block == JitBlocks.end()) + { + CompileBlock(cpu); + block = JitBlocks.find(targetPseudoPhys); + } + + JIT_DEBUGPRINT("linking to block %08x\n", targetPseudoPhys); + + block->second->AddLink(codeOffset); + compiler->LinkBlock(codeOffset, block->second->EntryPoint); +} + void* GetFuncForAddr(ARM* cpu, u32 addr, bool store, int size) { if (cpu->Num == 0) @@ -874,4 +1000,7 @@ void* GetFuncForAddr(ARM* cpu, u32 addr, bool store, int size) return NULL; } -} \ No newline at end of file +} + +template void ARMJIT::LinkBlock<0>(ARM*, u32); +template void ARMJIT::LinkBlock<1>(ARM*, u32); diff --git a/src/ARMJIT.h b/src/ARMJIT.h index 09cc463..cab385f 100644 --- a/src/ARMJIT.h +++ b/src/ARMJIT.h @@ -32,7 +32,6 @@ extern u32 AddrTranslate9[0x2000]; extern u32 AddrTranslate7[0x4000]; const u32 ExeMemSpaceSize = 0x518000; // I hate you C++, sometimes I really hate you... -extern JitBlockEntry FastBlockAccess[ExeMemSpaceSize / 2]; template inline bool IsMapped(u32 addr) @@ -52,11 +51,8 @@ inline u32 TranslateAddr(u32 addr) return AddrTranslate7[(addr & 0xFFFFFFF) >> 14] + (addr & 0x3FFF); } -template -inline JitBlockEntry LookUpBlock(u32 addr) -{ - return FastBlockAccess[TranslateAddr(addr) / 2]; -} +JitBlockEntry LookUpBlockEntry(u32 addr); + void Init(); void DeInit(); @@ -73,4 +69,6 @@ void ResetBlockCache(); } +extern "C" void ARM_Dispatch(ARM* cpu, ARMJIT::JitBlockEntry entry); + #endif \ No newline at end of file diff --git a/src/ARMJIT_Internal.h b/src/ARMJIT_Internal.h index 0d6add9..66d1808 100644 --- a/src/ARMJIT_Internal.h +++ b/src/ARMJIT_Internal.h @@ -15,7 +15,8 @@ enum { branch_IdleBranch = 1 << 0, branch_FollowCondTaken = 1 << 1, - branch_FollowCondNotTaken = 1 << 2 + branch_FollowCondNotTaken = 1 << 2, + branch_StaticTarget = 1 << 3, }; struct FetchedInstr @@ -76,7 +77,7 @@ struct __attribute__((packed)) TinyVector assert(capacity > Capacity); T* newMem = new T[capacity]; if (Data != NULL) - memcpy(newMem, Data, sizeof(Data) * Length); + memcpy(newMem, Data, sizeof(T) * Length); T* oldData = Data; Data = newMem; @@ -163,7 +164,6 @@ public: u32 NumInstrs; u32 NumAddresses; - u32 NumLinks; JitBlockEntry EntryPoint; @@ -171,6 +171,21 @@ public: { return &Data[0]; } u32* AddressRanges() { return &Data[NumInstrs]; } + u32* Links() + { return &Data[NumInstrs + NumAddresses]; } + + u32 NumLinks() + { return Data.Length - NumInstrs - NumAddresses; } + + void AddLink(u32 link) + { + Data.Add(link); + } + + void ResetLinks() + { + Data.SetLength(NumInstrs + NumAddresses); + } private: /* @@ -200,6 +215,9 @@ extern u8 MemRegion7[0x80000]; void* GetFuncForAddr(ARM* cpu, u32 addr, bool store, int size); +template +void LinkBlock(ARM* cpu, u32 codeOffset); + } #endif \ No newline at end of file diff --git a/src/ARMJIT_x64/ARMJIT_Branch.cpp b/src/ARMJIT_x64/ARMJIT_Branch.cpp index e02865d..cac590a 100644 --- a/src/ARMJIT_x64/ARMJIT_Branch.cpp +++ b/src/ARMJIT_x64/ARMJIT_Branch.cpp @@ -127,7 +127,7 @@ void Compiler::Comp_JumpTo(u32 addr, bool forceNonConstantCycles) if ((Thumb || CurInstr.Cond() >= 0xE) && !forceNonConstantCycles) ConstantCycles += cycles; else - ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm8(cycles)); + SUB(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm8(cycles)); } void Compiler::Comp_JumpTo(Gen::X64Reg addr, bool restoreCPSR) @@ -135,7 +135,7 @@ void Compiler::Comp_JumpTo(Gen::X64Reg addr, bool restoreCPSR) IrregularCycles = true; BitSet16 hiRegsLoaded(RegCache.LoadedRegs & 0x7F00); - bool previouslyDirty = CPSRDirty; + bool cpsrDirty = CPSRDirty; SaveCPSR(); if (restoreCPSR) @@ -168,9 +168,10 @@ void Compiler::Comp_JumpTo(Gen::X64Reg addr, bool restoreCPSR) LoadReg(reg, RegCache.Mapping[reg]); } - if (previouslyDirty) - LoadCPSR(); - CPSRDirty = previouslyDirty; + LoadCPSR(); + // in case this instruction is skipped + if (CurInstr.Cond() < 0xE) + CPSRDirty = cpsrDirty; } void Compiler::A_Comp_BranchImm() @@ -209,20 +210,12 @@ void Compiler::T_Comp_BCOND() s32 offset = (s32)(CurInstr.Instr << 24) >> 23; Comp_JumpTo(R15 + offset + 1, true); - Comp_SpecialBranchBehaviour(); + Comp_SpecialBranchBehaviour(true); FixupBranch skipFailed = J(); SetJumpTarget(skipExecute); - if (CurInstr.BranchFlags & branch_FollowCondTaken) - { - RegCache.PrepareExit(); - SaveCPSR(false); - - MOV(32, R(RAX), Imm32(ConstantCycles)); - ABI_PopRegistersAndAdjustStack(BitSet32(ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS & ~BitSet32({RSP})), 8); - RET(); - } + Comp_SpecialBranchBehaviour(false); Comp_AddCycles_C(true); SetJumpTarget(skipFailed); diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index d69bdff..be3709e 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -1,6 +1,7 @@ #include "ARMJIT_Compiler.h" #include "../ARMInterpreter.h" +#include "../Config.h" #include @@ -15,6 +16,8 @@ using namespace Gen; +extern "C" void ARM_Ret(); + namespace ARMJIT { template <> @@ -170,6 +173,24 @@ Compiler::Compiler() RET(); } + { + CPSRDirty = true; + BranchStub[0] = GetWritableCodePtr(); + SaveCPSR(); + MOV(64, R(ABI_PARAM1), R(RCPU)); + CALL((u8*)ARMJIT::LinkBlock<0>); + LoadCPSR(); + JMP((u8*)ARM_Ret, true); + + CPSRDirty = true; + BranchStub[1] = GetWritableCodePtr(); + SaveCPSR(); + MOV(64, R(ABI_PARAM1), R(RCPU)); + CALL((u8*)ARMJIT::LinkBlock<1>); + LoadCPSR(); + JMP((u8*)ARM_Ret, true); + } + // move the region forward to prevent overwriting the generated functions CodeMemSize -= GetWritableCodePtr() - ResetStart; ResetStart = GetWritableCodePtr(); @@ -362,23 +383,43 @@ void Compiler::Reset() SetCodePtr(ResetStart); } -void Compiler::Comp_SpecialBranchBehaviour() +void Compiler::Comp_SpecialBranchBehaviour(bool taken) { - if (CurInstr.BranchFlags & branch_IdleBranch) - OR(32, MDisp(RCPU, offsetof(ARM, IdleLoop)), Imm8(0x1)); + if (taken && CurInstr.BranchFlags & branch_IdleBranch) + OR(8, MDisp(RCPU, offsetof(ARM, IdleLoop)), Imm8(0x1)); - if (CurInstr.BranchFlags & branch_FollowCondNotTaken) + if ((CurInstr.BranchFlags & branch_FollowCondNotTaken && taken) + || (CurInstr.BranchFlags & branch_FollowCondTaken && !taken)) { RegCache.PrepareExit(); - SaveCPSR(false); - - MOV(32, R(RAX), Imm32(ConstantCycles)); - ABI_PopRegistersAndAdjustStack(BitSet32(ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS & ~BitSet32({RSP})), 8); - RET(); + + SUB(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm32(ConstantCycles)); + + if (Config::JIT_BrancheOptimisations == 2 && !(CurInstr.BranchFlags & branch_IdleBranch) + && (!taken || (CurInstr.BranchFlags & branch_StaticTarget))) + { + FixupBranch ret = J_CC(CC_S); + CMP(32, MDisp(RCPU, offsetof(ARM, StopExecution)), Imm8(0)); + FixupBranch ret2 = J_CC(CC_NZ); + + u8* rewritePart = GetWritableCodePtr(); + NOP(5); + + MOV(32, R(ABI_PARAM2), Imm32(rewritePart - ResetStart)); + JMP((u8*)BranchStub[Num], true); + + SetJumpTarget(ret); + SetJumpTarget(ret2); + JMP((u8*)ARM_Ret, true); + } + else + { + JMP((u8*)&ARM_Ret, true); + } } } -JitBlockEntry Compiler::CompileBlock(ARM* cpu, bool thumb, FetchedInstr instrs[], int instrsCount) +JitBlockEntry Compiler::CompileBlock(u32 translatedAddr, ARM* cpu, bool thumb, FetchedInstr instrs[], int instrsCount) { if (CodeMemSize - (GetWritableCodePtr() - ResetStart) < 1024 * 32) // guess... ResetBlockCache(); @@ -388,15 +429,11 @@ JitBlockEntry Compiler::CompileBlock(ARM* cpu, bool thumb, FetchedInstr instrs[] Num = cpu->Num; CodeRegion = instrs[0].Addr >> 24; CurCPU = cpu; + // CPSR might have been modified in a previous block + CPSRDirty = Config::JIT_BrancheOptimisations == 2; JitBlockEntry res = (JitBlockEntry)GetWritableCodePtr(); - ABI_PushRegistersAndAdjustStack(BitSet32(ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS & ~BitSet32({RSP})), 8); - - MOV(64, R(RCPU), ImmPtr(cpu)); - - LoadCPSR(); - RegCache = RegisterCache(this, instrs, instrsCount); for (int i = 0; i < instrsCount; i++) @@ -474,7 +511,7 @@ JitBlockEntry Compiler::CompileBlock(ARM* cpu, bool thumb, FetchedInstr instrs[] else (this->*comp)(); - Comp_SpecialBranchBehaviour(); + Comp_SpecialBranchBehaviour(true); if (CurInstr.Cond() < 0xE) { @@ -485,15 +522,7 @@ JitBlockEntry Compiler::CompileBlock(ARM* cpu, bool thumb, FetchedInstr instrs[] Comp_AddCycles_C(true); - if (CurInstr.BranchFlags & branch_FollowCondTaken) - { - RegCache.PrepareExit(); - SaveCPSR(false); - - MOV(32, R(RAX), Imm32(ConstantCycles)); - ABI_PopRegistersAndAdjustStack(BitSet32(ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS & ~BitSet32({RSP})), 8); - RET(); - } + Comp_SpecialBranchBehaviour(false); SetJumpTarget(skipFailed); } @@ -504,17 +533,38 @@ JitBlockEntry Compiler::CompileBlock(ARM* cpu, bool thumb, FetchedInstr instrs[] } } - if (comp == NULL && i != instrsCount - 1) + if (comp == NULL) LoadCPSR(); } RegCache.Flush(); - SaveCPSR(); - MOV(32, R(RAX), Imm32(ConstantCycles)); + SUB(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm32(ConstantCycles)); + + if (Config::JIT_BrancheOptimisations == 2 + && !(instrs[instrsCount - 1].BranchFlags & branch_IdleBranch) + && (!instrs[instrsCount - 1].Info.Branches() + || instrs[instrsCount - 1].BranchFlags & branch_FollowCondNotTaken + || (instrs[instrsCount - 1].BranchFlags & branch_FollowCondTaken && instrs[instrsCount - 1].BranchFlags & branch_StaticTarget))) + { + FixupBranch ret = J_CC(CC_S); + CMP(32, MDisp(RCPU, offsetof(ARM, StopExecution)), Imm8(0)); + FixupBranch ret2 = J_CC(CC_NZ); + + u8* rewritePart = GetWritableCodePtr(); + NOP(5); + + MOV(32, R(ABI_PARAM2), Imm32(rewritePart - ResetStart)); + JMP((u8*)BranchStub[Num], true); - ABI_PopRegistersAndAdjustStack(BitSet32(ABI_ALL_CALLEE_SAVED & ABI_ALL_GPRS & ~BitSet32({RSP})), 8); - RET(); + SetJumpTarget(ret); + SetJumpTarget(ret2); + JMP((u8*)ARM_Ret, true); + } + else + { + JMP((u8*)ARM_Ret, true); + } /*FILE* codeout = fopen("codeout", "a"); fprintf(codeout, "beginning block argargarg__ %x!!!", instrs[0].Addr); @@ -525,6 +575,22 @@ JitBlockEntry Compiler::CompileBlock(ARM* cpu, bool thumb, FetchedInstr instrs[] return res; } +void Compiler::LinkBlock(u32 offset, JitBlockEntry entry) +{ + u8* curPtr = GetWritableCodePtr(); + SetCodePtr(ResetStart + offset); + JMP((u8*)entry, true); + SetCodePtr(curPtr); +} + +void Compiler::UnlinkBlock(u32 offset) +{ + u8* curPtr = GetWritableCodePtr(); + SetCodePtr(ResetStart + offset); + NOP(5); + SetCodePtr(curPtr); +} + void Compiler::Comp_AddCycles_C(bool forceNonConstant) { s32 cycles = Num ? @@ -532,7 +598,7 @@ void Compiler::Comp_AddCycles_C(bool forceNonConstant) : ((R15 & 0x2) ? 0 : CurInstr.CodeCycles); if ((!Thumb && CurInstr.Cond() < 0xE) || forceNonConstant) - ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm8(cycles)); + SUB(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm8(cycles)); else ConstantCycles += cycles; } @@ -544,7 +610,7 @@ void Compiler::Comp_AddCycles_CI(u32 i) : ((R15 & 0x2) ? 0 : CurInstr.CodeCycles)) + i; if (!Thumb && CurInstr.Cond() < 0xE) - ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm8(cycles)); + SUB(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm8(cycles)); else ConstantCycles += cycles; } @@ -558,12 +624,12 @@ void Compiler::Comp_AddCycles_CI(Gen::X64Reg i, int add) if (!Thumb && CurInstr.Cond() < 0xE) { LEA(32, RSCRATCH, MDisp(i, add + cycles)); - ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(RSCRATCH)); + SUB(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(RSCRATCH)); } else { ConstantCycles += i + cycles; - ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(i)); + SUB(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(i)); } } @@ -599,7 +665,7 @@ void Compiler::Comp_AddCycles_CDI() } if (!Thumb && CurInstr.Cond() < 0xE) - ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm8(cycles)); + SUB(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm8(cycles)); else ConstantCycles += cycles; } @@ -643,7 +709,7 @@ void Compiler::Comp_AddCycles_CD() } if (IrregularCycles && !Thumb && CurInstr.Cond() < 0xE) - ADD(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm8(cycles)); + SUB(32, MDisp(RCPU, offsetof(ARM, Cycles)), Imm8(cycles)); else ConstantCycles += cycles; } diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index 2cb57dc..b428c33 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -51,7 +51,10 @@ public: void Reset(); - JitBlockEntry CompileBlock(ARM* cpu, bool thumb, FetchedInstr instrs[], int instrsCount); + void LinkBlock(u32 offset, JitBlockEntry entry); + void UnlinkBlock(u32 offset); + + JitBlockEntry CompileBlock(u32 translatedAddr, ARM* cpu, bool thumb, FetchedInstr instrs[], int instrsCount); void LoadReg(int reg, Gen::X64Reg nativeReg); void SaveReg(int reg, Gen::X64Reg nativeReg); @@ -145,7 +148,7 @@ public: void Comp_RetriveFlags(bool sign, bool retriveCV, bool carryUsed); - void Comp_SpecialBranchBehaviour(); + void Comp_SpecialBranchBehaviour(bool taken); void* Gen_MemoryRoutine9(bool store, int size); @@ -176,12 +179,24 @@ public: return Gen::R(RegCache.Mapping[reg]); } + JitBlockEntry AddEntryOffset(u32 offset) + { + return (JitBlockEntry)(ResetStart + offset); + } + + u32 SubEntryOffset(JitBlockEntry entry) + { + return (u8*)entry - ResetStart; + } + u8* ResetStart; u32 CodeMemSize; bool Exit; bool IrregularCycles; + void* BranchStub[2]; + void* MemoryFuncs9[3][2]; void* MemoryFuncs7[3][2]; diff --git a/src/ARMJIT_x64/ARMJIT_GenOffsets.cpp b/src/ARMJIT_x64/ARMJIT_GenOffsets.cpp new file mode 100644 index 0000000..9696d22 --- /dev/null +++ b/src/ARMJIT_x64/ARMJIT_GenOffsets.cpp @@ -0,0 +1,15 @@ +#include "../ARM.h" + +int main(int argc, char* argv[]) +{ + FILE* f = fopen("ARMJIT_Offsets.h", "w"); +#define writeOffset(field) \ + fprintf(f, "#define ARM_" #field "_offset 0x%x\n", offsetof(ARM, field)) + + writeOffset(CPSR); + writeOffset(Cycles); + writeOffset(StopExecution); + + fclose(f); + return 0; +} \ No newline at end of file diff --git a/src/ARMJIT_x64/ARMJIT_Linkage.s b/src/ARMJIT_x64/ARMJIT_Linkage.s new file mode 100644 index 0000000..dbbb024 --- /dev/null +++ b/src/ARMJIT_x64/ARMJIT_Linkage.s @@ -0,0 +1,74 @@ +.intel_syntax noprefix + +#include "ARMJIT_Offsets.h" + +.text + +#define RCPU rbp +#define RCPSR r15d + +#ifdef WIN64 +#define ARG1_REG ecx +#define ARG2_REG edx +#define ARG3_REG r8d +#define ARG4_REG r9d +#define ARG1_REG64 rcx +#define ARG2_REG64 rdx +#define ARG3_REG64 r8 +#define ARG4_REG64 r9 +#else +#define ARG1_REG edi +#define ARG2_REG esi +#define ARG3_REG edx +#define ARG4_REG ecx +#define ARG1_REG64 rdi +#define ARG2_REG64 rsi +#define ARG3_REG64 rdx +#define ARG4_REG64 rcx +#endif + +.p2align 4,,15 + +.global ARM_Dispatch +ARM_Dispatch: +#ifdef WIN64 + push rdi + push rsi +#endif + push rbx + push r12 + push r13 + push r14 + push r15 + push rbp + +#ifdef WIN64 + sub rsp, 0x28 +#endif + mov RCPU, ARG1_REG64 + mov RCPSR, [RCPU + ARM_CPSR_offset] + + jmp ARG2_REG64 + +.p2align 4,,15 + +.global ARM_Ret +ARM_Ret: + mov [RCPU + ARM_CPSR_offset], RCPSR + +#ifdef WIN64 + add rsp, 0x28 +#endif + + pop rbp + pop r15 + pop r14 + pop r13 + pop r12 + pop rbx +#ifdef WIN64 + pop rsi + pop rdi +#endif + + ret diff --git a/src/ARMJIT_x64/ARMJIT_Offsets.h b/src/ARMJIT_x64/ARMJIT_Offsets.h new file mode 100644 index 0000000..a73dd59 --- /dev/null +++ b/src/ARMJIT_x64/ARMJIT_Offsets.h @@ -0,0 +1,3 @@ +#define ARM_CPSR_offset 0x64 +#define ARM_Cycles_offset 0xc +#define ARM_StopExecution_offset 0x10 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c34ba3b..a0c3a36 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -49,9 +49,12 @@ add_library(core STATIC WifiAP.cpp tiny-AES-c/aes.c + xxhash/xxhash.c ) if (ENABLE_JIT) + enable_language(ASM) + target_sources(core PRIVATE ARMJIT.cpp @@ -68,7 +71,10 @@ if (ENABLE_JIT) ARMJIT_x64/ARMJIT_ALU.cpp ARMJIT_x64/ARMJIT_LoadStore.cpp ARMJIT_x64/ARMJIT_Branch.cpp + + ARMJIT_x64/ARMJIT_Linkage.s ) + set_source_files_properties(ARMJIT_x64/ARMJIT_Linkage.s PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp") endif() if (ARCHITECTURE STREQUAL ARM64) target_sources(core PRIVATE diff --git a/src/Config.cpp b/src/Config.cpp index 07b1e3e..e69319b 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -38,10 +38,10 @@ char DSiFirmwarePath[1024]; char DSiNANDPath[1024]; #ifdef JIT_ENABLED -bool JIT_Enable = false; +int JIT_Enable = false; int JIT_MaxBlockSize = 12; -bool JIT_BrancheOptimisations = true; -bool JIT_LiteralOptimisations = true; +int JIT_BrancheOptimisations = 2; +int JIT_LiteralOptimisations = true; #endif ConfigEntry ConfigFile[] = @@ -58,7 +58,7 @@ ConfigEntry ConfigFile[] = #ifdef JIT_ENABLED {"JIT_Enable", 0, &JIT_Enable, 0, NULL, 0}, {"JIT_MaxBlockSize", 0, &JIT_MaxBlockSize, 10, NULL, 0}, - {"JIT_BrancheOptimisations", 0, &JIT_BrancheOptimisations, 1, NULL, 0}, + {"JIT_BranchOptimisations", 0, &JIT_BrancheOptimisations, 2, NULL, 0}, {"JIT_LiteralOptimisations", 0, &JIT_LiteralOptimisations, 1, NULL, 0}, #endif diff --git a/src/Config.h b/src/Config.h index 1fcd9bb..d546524 100644 --- a/src/Config.h +++ b/src/Config.h @@ -52,10 +52,10 @@ extern char DSiFirmwarePath[1024]; extern char DSiNANDPath[1024]; #ifdef JIT_ENABLED -extern bool JIT_Enable; +extern int JIT_Enable; extern int JIT_MaxBlockSize; -extern bool JIT_BrancheOptimisations; -extern bool JIT_LiteralOptimisations; +extern int JIT_BrancheOptimisations; +extern int JIT_LiteralOptimisations; #endif } diff --git a/src/xxhash/xxh3.h b/src/xxhash/xxh3.h new file mode 100644 index 0000000..5d5faf8 --- /dev/null +++ b/src/xxhash/xxh3.h @@ -0,0 +1,2390 @@ +/* + * xxHash - Extremely Fast Hash algorithm + * Development source file for `xxh3` + * Copyright (C) 2019-2020 Yann Collet + * + * BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * You can contact the author at: + * - xxHash homepage: https://www.xxhash.com + * - xxHash source repository: https://github.com/Cyan4973/xxHash + */ + +/* + * Note: This file is separated for development purposes. + * It will be integrated into `xxhash.h` when development stage is completed. + * + * Credit: most of the work on vectorial and asm variants comes from @easyaspi314 + */ + +#ifndef XXH3_H_1397135465 +#define XXH3_H_1397135465 + +/* === Dependencies === */ +#ifndef XXHASH_H_5627135585666179 +/* special: when including `xxh3.h` directly, turn on XXH_INLINE_ALL */ +# undef XXH_INLINE_ALL /* avoid redefinition */ +# define XXH_INLINE_ALL +#endif +#include "xxhash.h" + + +/* === Compiler specifics === */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* >= C99 */ +# define XXH_RESTRICT restrict +#else +/* Note: it might be useful to define __restrict or __restrict__ for some C++ compilers */ +# define XXH_RESTRICT /* disable */ +#endif + +#if (defined(__GNUC__) && (__GNUC__ >= 3)) \ + || (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 800)) \ + || defined(__clang__) +# define XXH_likely(x) __builtin_expect(x, 1) +# define XXH_unlikely(x) __builtin_expect(x, 0) +#else +# define XXH_likely(x) (x) +# define XXH_unlikely(x) (x) +#endif + +#if defined(__GNUC__) +# if defined(__AVX2__) +# include +# elif defined(__SSE2__) +# include +# elif defined(__ARM_NEON__) || defined(__ARM_NEON) +# define inline __inline__ /* clang bug */ +# include +# undef inline +# endif +#elif defined(_MSC_VER) +# include +#endif + +/* + * One goal of XXH3 is to make it fast on both 32-bit and 64-bit, while + * remaining a true 64-bit/128-bit hash function. + * + * This is done by prioritizing a subset of 64-bit operations that can be + * emulated without too many steps on the average 32-bit machine. + * + * For example, these two lines seem similar, and run equally fast on 64-bit: + * + * xxh_u64 x; + * x ^= (x >> 47); // good + * x ^= (x >> 13); // bad + * + * However, to a 32-bit machine, there is a major difference. + * + * x ^= (x >> 47) looks like this: + * + * x.lo ^= (x.hi >> (47 - 32)); + * + * while x ^= (x >> 13) looks like this: + * + * // note: funnel shifts are not usually cheap. + * x.lo ^= (x.lo >> 13) | (x.hi << (32 - 13)); + * x.hi ^= (x.hi >> 13); + * + * The first one is significantly faster than the second, simply because the + * shift is larger than 32. This means: + * - All the bits we need are in the upper 32 bits, so we can ignore the lower + * 32 bits in the shift. + * - The shift result will always fit in the lower 32 bits, and therefore, + * we can ignore the upper 32 bits in the xor. + * + * Thanks to this optimization, XXH3 only requires these features to be efficient: + * + * - Usable unaligned access + * - A 32-bit or 64-bit ALU + * - If 32-bit, a decent ADC instruction + * - A 32 or 64-bit multiply with a 64-bit result + * - For the 128-bit variant, a decent byteswap helps short inputs. + * + * The first two are already required by XXH32, and almost all 32-bit and 64-bit + * platforms which can run XXH32 can run XXH3 efficiently. + * + * Thumb-1, the classic 16-bit only subset of ARM's instruction set, is one + * notable exception. + * + * First of all, Thumb-1 lacks support for the UMULL instruction which + * performs the important long multiply. This means numerous __aeabi_lmul + * calls. + * + * Second of all, the 8 functional registers are just not enough. + * Setup for __aeabi_lmul, byteshift loads, pointers, and all arithmetic need + * Lo registers, and this shuffling results in thousands more MOVs than A32. + * + * A32 and T32 don't have this limitation. They can access all 14 registers, + * do a 32->64 multiply with UMULL, and the flexible operand allowing free + * shifts is helpful, too. + * + * Therefore, we do a quick sanity check. + * + * If compiling Thumb-1 for a target which supports ARM instructions, we will + * emit a warning, as it is not a "sane" platform to compile for. + * + * Usually, if this happens, it is because of an accident and you probably need + * to specify -march, as you likely meant to compile for a newer architecture. + */ +#if defined(__thumb__) && !defined(__thumb2__) && defined(__ARM_ARCH_ISA_ARM) +# warning "XXH3 is highly inefficient without ARM or Thumb-2." +#endif + +/* ========================================== + * Vectorization detection + * ========================================== */ +#define XXH_SCALAR 0 /* Portable scalar version */ +#define XXH_SSE2 1 /* SSE2 for Pentium 4 and all x86_64 */ +#define XXH_AVX2 2 /* AVX2 for Haswell and Bulldozer */ +#define XXH_NEON 3 /* NEON for most ARMv7-A and all AArch64 */ +#define XXH_VSX 4 /* VSX and ZVector for POWER8/z13 */ +#define XXH_AVX512 5 /* AVX512 for Skylake and Icelake */ + +#ifndef XXH_VECTOR /* can be defined on command line */ +# if defined(__AVX512F__) +# define XXH_VECTOR XXH_AVX512 +# elif defined(__AVX2__) +# define XXH_VECTOR XXH_AVX2 +# elif defined(__SSE2__) || defined(_M_AMD64) || defined(_M_X64) || (defined(_M_IX86_FP) && (_M_IX86_FP == 2)) +# define XXH_VECTOR XXH_SSE2 +# elif defined(__GNUC__) /* msvc support maybe later */ \ + && (defined(__ARM_NEON__) || defined(__ARM_NEON)) \ + && (defined(__LITTLE_ENDIAN__) /* We only support little endian NEON */ \ + || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) +# define XXH_VECTOR XXH_NEON +# elif (defined(__PPC64__) && defined(__POWER8_VECTOR__)) \ + || (defined(__s390x__) && defined(__VEC__)) \ + && defined(__GNUC__) /* TODO: IBM XL */ +# define XXH_VECTOR XXH_VSX +# else +# define XXH_VECTOR XXH_SCALAR +# endif +#endif + +/* + * Controls the alignment of the accumulator. + * This is for compatibility with aligned vector loads, which are usually faster. + */ +#ifndef XXH_ACC_ALIGN +# if XXH_VECTOR == XXH_SCALAR /* scalar */ +# define XXH_ACC_ALIGN 8 +# elif XXH_VECTOR == XXH_SSE2 /* sse2 */ +# define XXH_ACC_ALIGN 16 +# elif XXH_VECTOR == XXH_AVX2 /* avx2 */ +# define XXH_ACC_ALIGN 32 +# elif XXH_VECTOR == XXH_NEON /* neon */ +# define XXH_ACC_ALIGN 16 +# elif XXH_VECTOR == XXH_VSX /* vsx */ +# define XXH_ACC_ALIGN 16 +# elif XXH_VECTOR == XXH_AVX512 /* avx512 */ +# define XXH_ACC_ALIGN 64 +# endif +#endif + +/* + * UGLY HACK: + * GCC usually generates the best code with -O3 for xxHash. + * + * However, when targeting AVX2, it is overzealous in its unrolling resulting + * in code roughly 3/4 the speed of Clang. + * + * There are other issues, such as GCC splitting _mm256_loadu_si256 into + * _mm_loadu_si128 + _mm256_inserti128_si256. This is an optimization which + * only applies to Sandy and Ivy Bridge... which don't even support AVX2. + * + * That is why when compiling the AVX2 version, it is recommended to use either + * -O2 -mavx2 -march=haswell + * or + * -O2 -mavx2 -mno-avx256-split-unaligned-load + * for decent performance, or to use Clang instead. + * + * Fortunately, we can control the first one with a pragma that forces GCC into + * -O2, but the other one we can't control without "failed to inline always + * inline function due to target mismatch" warnings. + */ +#if XXH_VECTOR == XXH_AVX2 /* AVX2 */ \ + && defined(__GNUC__) && !defined(__clang__) /* GCC, not Clang */ \ + && defined(__OPTIMIZE__) && !defined(__OPTIMIZE_SIZE__) /* respect -O0 and -Os */ +# pragma GCC push_options +# pragma GCC optimize("-O2") +#endif + + +#if XXH_VECTOR == XXH_NEON +/* + * NEON's setup for vmlal_u32 is a little more complicated than it is on + * SSE2, AVX2, and VSX. + * + * While PMULUDQ and VMULEUW both perform a mask, VMLAL.U32 performs an upcast. + * + * To do the same operation, the 128-bit 'Q' register needs to be split into + * two 64-bit 'D' registers, performing this operation:: + * + * [ a | b ] + * | '---------. .--------' | + * | x | + * | .---------' '--------. | + * [ a & 0xFFFFFFFF | b & 0xFFFFFFFF ],[ a >> 32 | b >> 32 ] + * + * Due to significant changes in aarch64, the fastest method for aarch64 is + * completely different than the fastest method for ARMv7-A. + * + * ARMv7-A treats D registers as unions overlaying Q registers, so modifying + * D11 will modify the high half of Q5. This is similar to how modifying AH + * will only affect bits 8-15 of AX on x86. + * + * VZIP takes two registers, and puts even lanes in one register and odd lanes + * in the other. + * + * On ARMv7-A, this strangely modifies both parameters in place instead of + * taking the usual 3-operand form. + * + * Therefore, if we want to do this, we can simply use a D-form VZIP.32 on the + * lower and upper halves of the Q register to end up with the high and low + * halves where we want - all in one instruction. + * + * vzip.32 d10, d11 @ d10 = { d10[0], d11[0] }; d11 = { d10[1], d11[1] } + * + * Unfortunately we need inline assembly for this: Instructions modifying two + * registers at once is not possible in GCC or Clang's IR, and they have to + * create a copy. + * + * aarch64 requires a different approach. + * + * In order to make it easier to write a decent compiler for aarch64, many + * quirks were removed, such as conditional execution. + * + * NEON was also affected by this. + * + * aarch64 cannot access the high bits of a Q-form register, and writes to a + * D-form register zero the high bits, similar to how writes to W-form scalar + * registers (or DWORD registers on x86_64) work. + * + * The formerly free vget_high intrinsics now require a vext (with a few + * exceptions) + * + * Additionally, VZIP was replaced by ZIP1 and ZIP2, which are the equivalent + * of PUNPCKL* and PUNPCKH* in SSE, respectively, in order to only modify one + * operand. + * + * The equivalent of the VZIP.32 on the lower and upper halves would be this + * mess: + * + * ext v2.4s, v0.4s, v0.4s, #2 // v2 = { v0[2], v0[3], v0[0], v0[1] } + * zip1 v1.2s, v0.2s, v2.2s // v1 = { v0[0], v2[0] } + * zip2 v0.2s, v0.2s, v1.2s // v0 = { v0[1], v2[1] } + * + * Instead, we use a literal downcast, vmovn_u64 (XTN), and vshrn_n_u64 (SHRN): + * + * shrn v1.2s, v0.2d, #32 // v1 = (uint32x2_t)(v0 >> 32); + * xtn v0.2s, v0.2d // v0 = (uint32x2_t)(v0 & 0xFFFFFFFF); + * + * This is available on ARMv7-A, but is less efficient than a single VZIP.32. + */ + +/* + * Function-like macro: + * void XXH_SPLIT_IN_PLACE(uint64x2_t &in, uint32x2_t &outLo, uint32x2_t &outHi) + * { + * outLo = (uint32x2_t)(in & 0xFFFFFFFF); + * outHi = (uint32x2_t)(in >> 32); + * in = UNDEFINED; + * } + */ +# if !defined(XXH_NO_VZIP_HACK) /* define to disable */ \ + && defined(__GNUC__) \ + && !defined(__aarch64__) && !defined(__arm64__) +# define XXH_SPLIT_IN_PLACE(in, outLo, outHi) \ + do { \ + /* Undocumented GCC/Clang operand modifier: %e0 = lower D half, %f0 = upper D half */ \ + /* https://github.com/gcc-mirror/gcc/blob/38cf91e5/gcc/config/arm/arm.c#L22486 */ \ + /* https://github.com/llvm-mirror/llvm/blob/2c4ca683/lib/Target/ARM/ARMAsmPrinter.cpp#L399 */ \ + __asm__("vzip.32 %e0, %f0" : "+w" (in)); \ + (outLo) = vget_low_u32 (vreinterpretq_u32_u64(in)); \ + (outHi) = vget_high_u32(vreinterpretq_u32_u64(in)); \ + } while (0) +# else +# define XXH_SPLIT_IN_PLACE(in, outLo, outHi) \ + do { \ + (outLo) = vmovn_u64 (in); \ + (outHi) = vshrn_n_u64 ((in), 32); \ + } while (0) +# endif +#endif /* XXH_VECTOR == XXH_NEON */ + +/* + * VSX and Z Vector helpers. + * + * This is very messy, and any pull requests to clean this up are welcome. + * + * There are a lot of problems with supporting VSX and s390x, due to + * inconsistent intrinsics, spotty coverage, and multiple endiannesses. + */ +#if XXH_VECTOR == XXH_VSX +# if defined(__s390x__) +# include +# else +# include +# endif + +# undef vector /* Undo the pollution */ + +typedef __vector unsigned long long xxh_u64x2; +typedef __vector unsigned char xxh_u8x16; +typedef __vector unsigned xxh_u32x4; + +# ifndef XXH_VSX_BE +# if defined(__BIG_ENDIAN__) \ + || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +# define XXH_VSX_BE 1 +# elif defined(__VEC_ELEMENT_REG_ORDER__) && __VEC_ELEMENT_REG_ORDER__ == __ORDER_BIG_ENDIAN__ +# warning "-maltivec=be is not recommended. Please use native endianness." +# define XXH_VSX_BE 1 +# else +# define XXH_VSX_BE 0 +# endif +# endif /* !defined(XXH_VSX_BE) */ + +# if XXH_VSX_BE +/* A wrapper for POWER9's vec_revb. */ +# if defined(__POWER9_VECTOR__) || (defined(__clang__) && defined(__s390x__)) +# define XXH_vec_revb vec_revb +# else +XXH_FORCE_INLINE xxh_u64x2 XXH_vec_revb(xxh_u64x2 val) +{ + xxh_u8x16 const vByteSwap = { 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, + 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08 }; + return vec_perm(val, val, vByteSwap); +} +# endif +# endif /* XXH_VSX_BE */ + +/* + * Performs an unaligned load and byte swaps it on big endian. + */ +XXH_FORCE_INLINE xxh_u64x2 XXH_vec_loadu(const void *ptr) +{ + xxh_u64x2 ret; + memcpy(&ret, ptr, sizeof(xxh_u64x2)); +# if XXH_VSX_BE + ret = XXH_vec_revb(ret); +# endif + return ret; +} + +/* + * vec_mulo and vec_mule are very problematic intrinsics on PowerPC + * + * These intrinsics weren't added until GCC 8, despite existing for a while, + * and they are endian dependent. Also, their meaning swap depending on version. + * */ +# if defined(__s390x__) + /* s390x is always big endian, no issue on this platform */ +# define XXH_vec_mulo vec_mulo +# define XXH_vec_mule vec_mule +# elif defined(__clang__) && __has_builtin(__builtin_altivec_vmuleuw) +/* Clang has a better way to control this, we can just use the builtin which doesn't swap. */ +# define XXH_vec_mulo __builtin_altivec_vmulouw +# define XXH_vec_mule __builtin_altivec_vmuleuw +# else +/* gcc needs inline assembly */ +/* Adapted from https://github.com/google/highwayhash/blob/master/highwayhash/hh_vsx.h. */ +XXH_FORCE_INLINE xxh_u64x2 XXH_vec_mulo(xxh_u32x4 a, xxh_u32x4 b) +{ + xxh_u64x2 result; + __asm__("vmulouw %0, %1, %2" : "=v" (result) : "v" (a), "v" (b)); + return result; +} +XXH_FORCE_INLINE xxh_u64x2 XXH_vec_mule(xxh_u32x4 a, xxh_u32x4 b) +{ + xxh_u64x2 result; + __asm__("vmuleuw %0, %1, %2" : "=v" (result) : "v" (a), "v" (b)); + return result; +} +# endif /* XXH_vec_mulo, XXH_vec_mule */ +#endif /* XXH_VECTOR == XXH_VSX */ + + +/* prefetch + * can be disabled, by declaring XXH_NO_PREFETCH build macro */ +#if defined(XXH_NO_PREFETCH) +# define XXH_PREFETCH(ptr) (void)(ptr) /* disabled */ +#else +# if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) /* _mm_prefetch() is not defined outside of x86/x64 */ +# include /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */ +# define XXH_PREFETCH(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T0) +# elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) ) +# define XXH_PREFETCH(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 3 /* locality */) +# else +# define XXH_PREFETCH(ptr) (void)(ptr) /* disabled */ +# endif +#endif /* XXH_NO_PREFETCH */ + + +/* ========================================== + * XXH3 default settings + * ========================================== */ + +#define XXH_SECRET_DEFAULT_SIZE 192 /* minimum XXH3_SECRET_SIZE_MIN */ + +#if (XXH_SECRET_DEFAULT_SIZE < XXH3_SECRET_SIZE_MIN) +# error "default keyset is not large enough" +#endif + +/* Pseudorandom secret taken directly from FARSH */ +XXH_ALIGN(64) static const xxh_u8 kSecret[XXH_SECRET_DEFAULT_SIZE] = { + 0xb8, 0xfe, 0x6c, 0x39, 0x23, 0xa4, 0x4b, 0xbe, 0x7c, 0x01, 0x81, 0x2c, 0xf7, 0x21, 0xad, 0x1c, + 0xde, 0xd4, 0x6d, 0xe9, 0x83, 0x90, 0x97, 0xdb, 0x72, 0x40, 0xa4, 0xa4, 0xb7, 0xb3, 0x67, 0x1f, + 0xcb, 0x79, 0xe6, 0x4e, 0xcc, 0xc0, 0xe5, 0x78, 0x82, 0x5a, 0xd0, 0x7d, 0xcc, 0xff, 0x72, 0x21, + 0xb8, 0x08, 0x46, 0x74, 0xf7, 0x43, 0x24, 0x8e, 0xe0, 0x35, 0x90, 0xe6, 0x81, 0x3a, 0x26, 0x4c, + 0x3c, 0x28, 0x52, 0xbb, 0x91, 0xc3, 0x00, 0xcb, 0x88, 0xd0, 0x65, 0x8b, 0x1b, 0x53, 0x2e, 0xa3, + 0x71, 0x64, 0x48, 0x97, 0xa2, 0x0d, 0xf9, 0x4e, 0x38, 0x19, 0xef, 0x46, 0xa9, 0xde, 0xac, 0xd8, + 0xa8, 0xfa, 0x76, 0x3f, 0xe3, 0x9c, 0x34, 0x3f, 0xf9, 0xdc, 0xbb, 0xc7, 0xc7, 0x0b, 0x4f, 0x1d, + 0x8a, 0x51, 0xe0, 0x4b, 0xcd, 0xb4, 0x59, 0x31, 0xc8, 0x9f, 0x7e, 0xc9, 0xd9, 0x78, 0x73, 0x64, + + 0xea, 0xc5, 0xac, 0x83, 0x34, 0xd3, 0xeb, 0xc3, 0xc5, 0x81, 0xa0, 0xff, 0xfa, 0x13, 0x63, 0xeb, + 0x17, 0x0d, 0xdd, 0x51, 0xb7, 0xf0, 0xda, 0x49, 0xd3, 0x16, 0x55, 0x26, 0x29, 0xd4, 0x68, 0x9e, + 0x2b, 0x16, 0xbe, 0x58, 0x7d, 0x47, 0xa1, 0xfc, 0x8f, 0xf8, 0xb8, 0xd1, 0x7a, 0xd0, 0x31, 0xce, + 0x45, 0xcb, 0x3a, 0x8f, 0x95, 0x16, 0x04, 0x28, 0xaf, 0xd7, 0xfb, 0xca, 0xbb, 0x4b, 0x40, 0x7e, +}; + +/* + * Calculates a 32-bit to 64-bit long multiply. + * + * Wraps __emulu on MSVC x86 because it tends to call __allmul when it doesn't + * need to (but it shouldn't need to anyways, it is about 7 instructions to do + * a 64x64 multiply...). Since we know that this will _always_ emit MULL, we + * use that instead of the normal method. + * + * If you are compiling for platforms like Thumb-1 and don't have a better option, + * you may also want to write your own long multiply routine here. + * + * XXH_FORCE_INLINE xxh_u64 XXH_mult32to64(xxh_u64 x, xxh_u64 y) + * { + * return (x & 0xFFFFFFFF) * (y & 0xFFFFFFFF); + * } + */ +#if defined(_MSC_VER) && defined(_M_IX86) +# include +# define XXH_mult32to64(x, y) __emulu((unsigned)(x), (unsigned)(y)) +#else +/* + * Downcast + upcast is usually better than masking on older compilers like + * GCC 4.2 (especially 32-bit ones), all without affecting newer compilers. + * + * The other method, (x & 0xFFFFFFFF) * (y & 0xFFFFFFFF), will AND both operands + * and perform a full 64x64 multiply -- entirely redundant on 32-bit. + */ +# define XXH_mult32to64(x, y) ((xxh_u64)(xxh_u32)(x) * (xxh_u64)(xxh_u32)(y)) +#endif + +/* + * Calculates a 64->128-bit long multiply. + * + * Uses __uint128_t and _umul128 if available, otherwise uses a scalar version. + */ +static XXH128_hash_t +XXH_mult64to128(xxh_u64 lhs, xxh_u64 rhs) +{ + /* + * GCC/Clang __uint128_t method. + * + * On most 64-bit targets, GCC and Clang define a __uint128_t type. + * This is usually the best way as it usually uses a native long 64-bit + * multiply, such as MULQ on x86_64 or MUL + UMULH on aarch64. + * + * Usually. + * + * Despite being a 32-bit platform, Clang (and emscripten) define this type + * despite not having the arithmetic for it. This results in a laggy + * compiler builtin call which calculates a full 128-bit multiply. + * In that case it is best to use the portable one. + * https://github.com/Cyan4973/xxHash/issues/211#issuecomment-515575677 + */ +#if defined(__GNUC__) && !defined(__wasm__) \ + && defined(__SIZEOF_INT128__) \ + || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128) + + __uint128_t const product = (__uint128_t)lhs * (__uint128_t)rhs; + XXH128_hash_t r128; + r128.low64 = (xxh_u64)(product); + r128.high64 = (xxh_u64)(product >> 64); + return r128; + + /* + * MSVC for x64's _umul128 method. + * + * xxh_u64 _umul128(xxh_u64 Multiplier, xxh_u64 Multiplicand, xxh_u64 *HighProduct); + * + * This compiles to single operand MUL on x64. + */ +#elif defined(_M_X64) || defined(_M_IA64) + +#ifndef _MSC_VER +# pragma intrinsic(_umul128) +#endif + xxh_u64 product_high; + xxh_u64 const product_low = _umul128(lhs, rhs, &product_high); + XXH128_hash_t r128; + r128.low64 = product_low; + r128.high64 = product_high; + return r128; + +#else + /* + * Portable scalar method. Optimized for 32-bit and 64-bit ALUs. + * + * This is a fast and simple grade school multiply, which is shown below + * with base 10 arithmetic instead of base 0x100000000. + * + * 9 3 // D2 lhs = 93 + * x 7 5 // D2 rhs = 75 + * ---------- + * 1 5 // D2 lo_lo = (93 % 10) * (75 % 10) = 15 + * 4 5 | // D2 hi_lo = (93 / 10) * (75 % 10) = 45 + * 2 1 | // D2 lo_hi = (93 % 10) * (75 / 10) = 21 + * + 6 3 | | // D2 hi_hi = (93 / 10) * (75 / 10) = 63 + * --------- + * 2 7 | // D2 cross = (15 / 10) + (45 % 10) + 21 = 27 + * + 6 7 | | // D2 upper = (27 / 10) + (45 / 10) + 63 = 67 + * --------- + * 6 9 7 5 // D4 res = (27 * 10) + (15 % 10) + (67 * 100) = 6975 + * + * The reasons for adding the products like this are: + * 1. It avoids manual carry tracking. Just like how + * (9 * 9) + 9 + 9 = 99, the same applies with this for UINT64_MAX. + * This avoids a lot of complexity. + * + * 2. It hints for, and on Clang, compiles to, the powerful UMAAL + * instruction available in ARM's Digital Signal Processing extension + * in 32-bit ARMv6 and later, which is shown below: + * + * void UMAAL(xxh_u32 *RdLo, xxh_u32 *RdHi, xxh_u32 Rn, xxh_u32 Rm) + * { + * xxh_u64 product = (xxh_u64)*RdLo * (xxh_u64)*RdHi + Rn + Rm; + * *RdLo = (xxh_u32)(product & 0xFFFFFFFF); + * *RdHi = (xxh_u32)(product >> 32); + * } + * + * This instruction was designed for efficient long multiplication, and + * allows this to be calculated in only 4 instructions at speeds + * comparable to some 64-bit ALUs. + * + * 3. It isn't terrible on other platforms. Usually this will be a couple + * of 32-bit ADD/ADCs. + */ + + /* First calculate all of the cross products. */ + xxh_u64 const lo_lo = XXH_mult32to64(lhs & 0xFFFFFFFF, rhs & 0xFFFFFFFF); + xxh_u64 const hi_lo = XXH_mult32to64(lhs >> 32, rhs & 0xFFFFFFFF); + xxh_u64 const lo_hi = XXH_mult32to64(lhs & 0xFFFFFFFF, rhs >> 32); + xxh_u64 const hi_hi = XXH_mult32to64(lhs >> 32, rhs >> 32); + + /* Now add the products together. These will never overflow. */ + xxh_u64 const cross = (lo_lo >> 32) + (hi_lo & 0xFFFFFFFF) + lo_hi; + xxh_u64 const upper = (hi_lo >> 32) + (cross >> 32) + hi_hi; + xxh_u64 const lower = (cross << 32) | (lo_lo & 0xFFFFFFFF); + + XXH128_hash_t r128; + r128.low64 = lower; + r128.high64 = upper; + return r128; +#endif +} + +/* + * Does a 64-bit to 128-bit multiply, then XOR folds it. + * + * The reason for the separate function is to prevent passing too many structs + * around by value. This will hopefully inline the multiply, but we don't force it. + */ +static xxh_u64 +XXH3_mul128_fold64(xxh_u64 lhs, xxh_u64 rhs) +{ + XXH128_hash_t product = XXH_mult64to128(lhs, rhs); + return product.low64 ^ product.high64; +} + +/* Seems to produce slightly better code on GCC for some reason. */ +XXH_FORCE_INLINE xxh_u64 XXH_xorshift64(xxh_u64 v64, int shift) +{ + XXH_ASSERT(0 <= shift && shift < 64); + return v64 ^ (v64 >> shift); +} + +/* + * We don't need to (or want to) mix as much as XXH64. + * + * Short hashes are more evenly distributed, so it isn't necessary. + */ +static XXH64_hash_t XXH3_avalanche(xxh_u64 h64) +{ + h64 = XXH_xorshift64(h64, 37); + h64 *= 0x165667919E3779F9ULL; + h64 = XXH_xorshift64(h64, 32); + return h64; +} + + +/* ========================================== + * Short keys + * ========================================== + * One of the shortcomings of XXH32 and XXH64 was that their performance was + * sub-optimal on short lengths. It used an iterative algorithm which strongly + * favored lengths that were a multiple of 4 or 8. + * + * Instead of iterating over individual inputs, we use a set of single shot + * functions which piece together a range of lengths and operate in constant time. + * + * Additionally, the number of multiplies has been significantly reduced. This + * reduces latency, especially when emulating 64-bit multiplies on 32-bit. + * + * Depending on the platform, this may or may not be faster than XXH32, but it + * is almost guaranteed to be faster than XXH64. + */ + +/* + * At very short lengths, there isn't enough input to fully hide secrets, or use + * the entire secret. + * + * There is also only a limited amount of mixing we can do before significantly + * impacting performance. + * + * Therefore, we use different sections of the secret and always mix two secret + * samples with an XOR. This should have no effect on performance on the + * seedless or withSeed variants because everything _should_ be constant folded + * by modern compilers. + * + * The XOR mixing hides individual parts of the secret and increases entropy. + * + * This adds an extra layer of strength for custom secrets. + */ +XXH_FORCE_INLINE XXH64_hash_t +XXH3_len_1to3_64b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed) +{ + XXH_ASSERT(input != NULL); + XXH_ASSERT(1 <= len && len <= 3); + XXH_ASSERT(secret != NULL); + /* + * len = 1: combined = { input[0], 0x01, input[0], input[0] } + * len = 2: combined = { input[1], 0x02, input[0], input[1] } + * len = 3: combined = { input[2], 0x03, input[0], input[1] } + */ + { xxh_u8 const c1 = input[0]; + xxh_u8 const c2 = input[len >> 1]; + xxh_u8 const c3 = input[len - 1]; + xxh_u32 const combined = ((xxh_u32)c1 << 16) | ((xxh_u32)c2 << 24) + | ((xxh_u32)c3 << 0) | ((xxh_u32)len << 8); + xxh_u64 const bitflip = (XXH_readLE32(secret) ^ XXH_readLE32(secret+4)) + seed; + xxh_u64 const keyed = (xxh_u64)combined ^ bitflip; + xxh_u64 const mixed = keyed * PRIME64_1; + return XXH3_avalanche(mixed); + } +} + +XXH_FORCE_INLINE XXH64_hash_t +XXH3_len_4to8_64b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed) +{ + XXH_ASSERT(input != NULL); + XXH_ASSERT(secret != NULL); + XXH_ASSERT(4 <= len && len < 8); + seed ^= (xxh_u64)XXH_swap32((xxh_u32)seed) << 32; + { xxh_u32 const input1 = XXH_readLE32(input); + xxh_u32 const input2 = XXH_readLE32(input + len - 4); + xxh_u64 const bitflip = (XXH_readLE64(secret+8) ^ XXH_readLE64(secret+16)) - seed; + xxh_u64 const input64 = input2 + (((xxh_u64)input1) << 32); + xxh_u64 x = input64 ^ bitflip; + /* this mix is inspired by Pelle Evensen's rrmxmx */ + x ^= XXH_rotl64(x, 49) ^ XXH_rotl64(x, 24); + x *= 0x9FB21C651E98DF25ULL; + x ^= (x >> 35) + len ; + x *= 0x9FB21C651E98DF25ULL; + return XXH_xorshift64(x, 28); + } +} + +XXH_FORCE_INLINE XXH64_hash_t +XXH3_len_9to16_64b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed) +{ + XXH_ASSERT(input != NULL); + XXH_ASSERT(secret != NULL); + XXH_ASSERT(8 <= len && len <= 16); + { xxh_u64 const bitflip1 = (XXH_readLE64(secret+24) ^ XXH_readLE64(secret+32)) + seed; + xxh_u64 const bitflip2 = (XXH_readLE64(secret+40) ^ XXH_readLE64(secret+48)) - seed; + xxh_u64 const input_lo = XXH_readLE64(input) ^ bitflip1; + xxh_u64 const input_hi = XXH_readLE64(input + len - 8) ^ bitflip2; + xxh_u64 const acc = len + + XXH_swap64(input_lo) + input_hi + + XXH3_mul128_fold64(input_lo, input_hi); + return XXH3_avalanche(acc); + } +} + +XXH_FORCE_INLINE XXH64_hash_t +XXH3_len_0to16_64b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed) +{ + XXH_ASSERT(len <= 16); + { if (XXH_likely(len > 8)) return XXH3_len_9to16_64b(input, len, secret, seed); + if (XXH_likely(len >= 4)) return XXH3_len_4to8_64b(input, len, secret, seed); + if (len) return XXH3_len_1to3_64b(input, len, secret, seed); + return XXH3_avalanche((PRIME64_1 + seed) ^ (XXH_readLE64(secret+56) ^ XXH_readLE64(secret+64))); + } +} + +/* + * DISCLAIMER: There are known *seed-dependent* multicollisions here due to + * multiplication by zero, affecting hashes of lengths 17 to 240. + * + * However, they are very unlikely. + * + * Keep this in mind when using the unseeded XXH3_64bits() variant: As with all + * unseeded non-cryptographic hashes, it does not attempt to defend itself + * against specially crafted inputs, only random inputs. + * + * Compared to classic UMAC where a 1 in 2^31 chance of 4 consecutive bytes + * cancelling out the secret is taken an arbitrary number of times (addressed + * in XXH3_accumulate_512), this collision is very unlikely with random inputs + * and/or proper seeding: + * + * This only has a 1 in 2^63 chance of 8 consecutive bytes cancelling out, in a + * function that is only called up to 16 times per hash with up to 240 bytes of + * input. + * + * This is not too bad for a non-cryptographic hash function, especially with + * only 64 bit outputs. + * + * The 128-bit variant (which trades some speed for strength) is NOT affected + * by this, although it is always a good idea to use a proper seed if you care + * about strength. + */ +XXH_FORCE_INLINE xxh_u64 XXH3_mix16B(const xxh_u8* XXH_RESTRICT input, + const xxh_u8* XXH_RESTRICT secret, xxh_u64 seed64) +{ +#if defined(__GNUC__) && !defined(__clang__) /* GCC, not Clang */ \ + && defined(__i386__) && defined(__SSE2__) /* x86 + SSE2 */ \ + && !defined(XXH_ENABLE_AUTOVECTORIZE) /* Define to disable like XXH32 hack */ + /* + * UGLY HACK: + * GCC for x86 tends to autovectorize the 128-bit multiply, resulting in + * slower code. + * + * By forcing seed64 into a register, we disrupt the cost model and + * cause it to scalarize. See `XXH32_round()` + * + * FIXME: Clang's output is still _much_ faster -- On an AMD Ryzen 3600, + * XXH3_64bits @ len=240 runs at 4.6 GB/s with Clang 9, but 3.3 GB/s on + * GCC 9.2, despite both emitting scalar code. + * + * GCC generates much better scalar code than Clang for the rest of XXH3, + * which is why finding a more optimal codepath is an interest. + */ + __asm__ ("" : "+r" (seed64)); +#endif + { xxh_u64 const input_lo = XXH_readLE64(input); + xxh_u64 const input_hi = XXH_readLE64(input+8); + return XXH3_mul128_fold64( + input_lo ^ (XXH_readLE64(secret) + seed64), + input_hi ^ (XXH_readLE64(secret+8) - seed64) + ); + } +} + +/* For mid range keys, XXH3 uses a Mum-hash variant. */ +XXH_FORCE_INLINE XXH64_hash_t +XXH3_len_17to128_64b(const xxh_u8* XXH_RESTRICT input, size_t len, + const xxh_u8* XXH_RESTRICT secret, size_t secretSize, + XXH64_hash_t seed) +{ + XXH_ASSERT(secretSize >= XXH3_SECRET_SIZE_MIN); (void)secretSize; + XXH_ASSERT(16 < len && len <= 128); + + { xxh_u64 acc = len * PRIME64_1; + if (len > 32) { + if (len > 64) { + if (len > 96) { + acc += XXH3_mix16B(input+48, secret+96, seed); + acc += XXH3_mix16B(input+len-64, secret+112, seed); + } + acc += XXH3_mix16B(input+32, secret+64, seed); + acc += XXH3_mix16B(input+len-48, secret+80, seed); + } + acc += XXH3_mix16B(input+16, secret+32, seed); + acc += XXH3_mix16B(input+len-32, secret+48, seed); + } + acc += XXH3_mix16B(input+0, secret+0, seed); + acc += XXH3_mix16B(input+len-16, secret+16, seed); + + return XXH3_avalanche(acc); + } +} + +#define XXH3_MIDSIZE_MAX 240 + +XXH_NO_INLINE XXH64_hash_t +XXH3_len_129to240_64b(const xxh_u8* XXH_RESTRICT input, size_t len, + const xxh_u8* XXH_RESTRICT secret, size_t secretSize, + XXH64_hash_t seed) +{ + XXH_ASSERT(secretSize >= XXH3_SECRET_SIZE_MIN); (void)secretSize; + XXH_ASSERT(128 < len && len <= XXH3_MIDSIZE_MAX); + + #define XXH3_MIDSIZE_STARTOFFSET 3 + #define XXH3_MIDSIZE_LASTOFFSET 17 + + { xxh_u64 acc = len * PRIME64_1; + int const nbRounds = (int)len / 16; + int i; + for (i=0; i<8; i++) { + acc += XXH3_mix16B(input+(16*i), secret+(16*i), seed); + } + acc = XXH3_avalanche(acc); + XXH_ASSERT(nbRounds >= 8); +#if defined(__clang__) /* Clang */ \ + && (defined(__ARM_NEON) || defined(__ARM_NEON__)) /* NEON */ \ + && !defined(XXH_ENABLE_AUTOVECTORIZE) /* Define to disable */ + /* + * UGLY HACK: + * Clang for ARMv7-A tries to vectorize this loop, similar to GCC x86. + * In everywhere else, it uses scalar code. + * + * For 64->128-bit multiplies, even if the NEON was 100% optimal, it + * would still be slower than UMAAL (see XXH_mult64to128). + * + * Unfortunately, Clang doesn't handle the long multiplies properly and + * converts them to the nonexistent "vmulq_u64" intrinsic, which is then + * scalarized into an ugly mess of VMOV.32 instructions. + * + * This mess is difficult to avoid without turning autovectorization + * off completely, but they are usually relatively minor and/or not + * worth it to fix. + * + * This loop is the easiest to fix, as unlike XXH32, this pragma + * _actually works_ because it is a loop vectorization instead of an + * SLP vectorization. + */ + #pragma clang loop vectorize(disable) +#endif + for (i=8 ; i < nbRounds; i++) { + acc += XXH3_mix16B(input+(16*i), secret+(16*(i-8)) + XXH3_MIDSIZE_STARTOFFSET, seed); + } + /* last bytes */ + acc += XXH3_mix16B(input + len - 16, secret + XXH3_SECRET_SIZE_MIN - XXH3_MIDSIZE_LASTOFFSET, seed); + return XXH3_avalanche(acc); + } +} + + +/* === Long Keys === */ + +#define STRIPE_LEN 64 +#define XXH_SECRET_CONSUME_RATE 8 /* nb of secret bytes consumed at each accumulation */ +#define ACC_NB (STRIPE_LEN / sizeof(xxh_u64)) + +typedef enum { XXH3_acc_64bits, XXH3_acc_128bits } XXH3_accWidth_e; + +/* + * XXH3_accumulate_512 is the tightest loop for long inputs, and it is the most optimized. + * + * It is a hardened version of UMAC, based off of FARSH's implementation. + * + * This was chosen because it adapts quite well to 32-bit, 64-bit, and SIMD + * implementations, and it is ridiculously fast. + * + * We harden it by mixing the original input to the accumulators as well as the product. + * + * This means that in the (relatively likely) case of a multiply by zero, the + * original input is preserved. + * + * On 128-bit inputs, we swap 64-bit pairs when we add the input to improve + * cross-pollination, as otherwise the upper and lower halves would be + * essentially independent. + * + * This doesn't matter on 64-bit hashes since they all get merged together in + * the end, so we skip the extra step. + * + * Both XXH3_64bits and XXH3_128bits use this subroutine. + */ +XXH_FORCE_INLINE void +XXH3_accumulate_512( void* XXH_RESTRICT acc, + const void* XXH_RESTRICT input, + const void* XXH_RESTRICT secret, + XXH3_accWidth_e accWidth) +{ +#if (XXH_VECTOR == XXH_AVX512) + + XXH_ASSERT((((size_t)acc) & 63) == 0); + XXH_STATIC_ASSERT(STRIPE_LEN == sizeof(__m512i)); + { XXH_ALIGN(64) __m512i* const xacc = (__m512i *) acc; + + /* data_vec = input[0]; */ + __m512i const data_vec = _mm512_loadu_si512 (input); + /* key_vec = secret[0]; */ + __m512i const key_vec = _mm512_loadu_si512 (secret); + /* data_key = data_vec ^ key_vec; */ + __m512i const data_key = _mm512_xor_si512 (data_vec, key_vec); + /* data_key_lo = data_key >> 32; */ + __m512i const data_key_lo = _mm512_shuffle_epi32 (data_key, _MM_SHUFFLE(0, 3, 0, 1)); + /* product = (data_key & 0xffffffff) * (data_key_lo & 0xffffffff); */ + __m512i const product = _mm512_mul_epu32 (data_key, data_key_lo); + if (accWidth == XXH3_acc_128bits) { + /* xacc[0] += swap(data_vec); */ + __m512i const data_swap = _mm512_shuffle_epi32(data_vec, _MM_SHUFFLE(1, 0, 3, 2)); + __m512i const sum = _mm512_add_epi64(*xacc, data_swap); + /* xacc[0] += product; */ + *xacc = _mm512_add_epi64(product, sum); + } else { /* XXH3_acc_64bits */ + /* xacc[0] += data_vec; */ + __m512i const sum = _mm512_add_epi64(*xacc, data_vec); + /* xacc[0] += product; */ + *xacc = _mm512_add_epi64(product, sum); + } + } + +#elif (XXH_VECTOR == XXH_AVX2) + + XXH_ASSERT((((size_t)acc) & 31) == 0); + { XXH_ALIGN(32) __m256i* const xacc = (__m256i *) acc; + /* Unaligned. This is mainly for pointer arithmetic, and because + * _mm256_loadu_si256 requires a const __m256i * pointer for some reason. */ + const __m256i* const xinput = (const __m256i *) input; + /* Unaligned. This is mainly for pointer arithmetic, and because + * _mm256_loadu_si256 requires a const __m256i * pointer for some reason. */ + const __m256i* const xsecret = (const __m256i *) secret; + + size_t i; + for (i=0; i < STRIPE_LEN/sizeof(__m256i); i++) { + /* data_vec = xinput[i]; */ + __m256i const data_vec = _mm256_loadu_si256 (xinput+i); + /* key_vec = xsecret[i]; */ + __m256i const key_vec = _mm256_loadu_si256 (xsecret+i); + /* data_key = data_vec ^ key_vec; */ + __m256i const data_key = _mm256_xor_si256 (data_vec, key_vec); + /* data_key_lo = data_key >> 32; */ + __m256i const data_key_lo = _mm256_shuffle_epi32 (data_key, _MM_SHUFFLE(0, 3, 0, 1)); + /* product = (data_key & 0xffffffff) * (data_key_lo & 0xffffffff); */ + __m256i const product = _mm256_mul_epu32 (data_key, data_key_lo); + if (accWidth == XXH3_acc_128bits) { + /* xacc[i] += swap(data_vec); */ + __m256i const data_swap = _mm256_shuffle_epi32(data_vec, _MM_SHUFFLE(1, 0, 3, 2)); + __m256i const sum = _mm256_add_epi64(xacc[i], data_swap); + /* xacc[i] += product; */ + xacc[i] = _mm256_add_epi64(product, sum); + } else { /* XXH3_acc_64bits */ + /* xacc[i] += data_vec; */ + __m256i const sum = _mm256_add_epi64(xacc[i], data_vec); + /* xacc[i] += product; */ + xacc[i] = _mm256_add_epi64(product, sum); + } + } } + +#elif (XXH_VECTOR == XXH_SSE2) + + /* SSE2 is just a half-scale version of the AVX2 version. */ + XXH_ASSERT((((size_t)acc) & 15) == 0); + { XXH_ALIGN(16) __m128i* const xacc = (__m128i *) acc; + /* Unaligned. This is mainly for pointer arithmetic, and because + * _mm_loadu_si128 requires a const __m128i * pointer for some reason. */ + const __m128i* const xinput = (const __m128i *) input; + /* Unaligned. This is mainly for pointer arithmetic, and because + * _mm_loadu_si128 requires a const __m128i * pointer for some reason. */ + const __m128i* const xsecret = (const __m128i *) secret; + + size_t i; + for (i=0; i < STRIPE_LEN/sizeof(__m128i); i++) { + /* data_vec = xinput[i]; */ + __m128i const data_vec = _mm_loadu_si128 (xinput+i); + /* key_vec = xsecret[i]; */ + __m128i const key_vec = _mm_loadu_si128 (xsecret+i); + /* data_key = data_vec ^ key_vec; */ + __m128i const data_key = _mm_xor_si128 (data_vec, key_vec); + /* data_key_lo = data_key >> 32; */ + __m128i const data_key_lo = _mm_shuffle_epi32 (data_key, _MM_SHUFFLE(0, 3, 0, 1)); + /* product = (data_key & 0xffffffff) * (data_key_lo & 0xffffffff); */ + __m128i const product = _mm_mul_epu32 (data_key, data_key_lo); + if (accWidth == XXH3_acc_128bits) { + /* xacc[i] += swap(data_vec); */ + __m128i const data_swap = _mm_shuffle_epi32(data_vec, _MM_SHUFFLE(1,0,3,2)); + __m128i const sum = _mm_add_epi64(xacc[i], data_swap); + /* xacc[i] += product; */ + xacc[i] = _mm_add_epi64(product, sum); + } else { /* XXH3_acc_64bits */ + /* xacc[i] += data_vec; */ + __m128i const sum = _mm_add_epi64(xacc[i], data_vec); + /* xacc[i] += product; */ + xacc[i] = _mm_add_epi64(product, sum); + } + } } + +#elif (XXH_VECTOR == XXH_NEON) + + XXH_ASSERT((((size_t)acc) & 15) == 0); + { + XXH_ALIGN(16) uint64x2_t* const xacc = (uint64x2_t *) acc; + /* We don't use a uint32x4_t pointer because it causes bus errors on ARMv7. */ + uint8_t const* const xinput = (const uint8_t *) input; + uint8_t const* const xsecret = (const uint8_t *) secret; + + size_t i; + for (i=0; i < STRIPE_LEN / sizeof(uint64x2_t); i++) { + /* data_vec = xinput[i]; */ + uint8x16_t data_vec = vld1q_u8(xinput + (i * 16)); + /* key_vec = xsecret[i]; */ + uint8x16_t key_vec = vld1q_u8(xsecret + (i * 16)); + uint64x2_t data_key; + uint32x2_t data_key_lo, data_key_hi; + if (accWidth == XXH3_acc_64bits) { + /* xacc[i] += data_vec; */ + xacc[i] = vaddq_u64 (xacc[i], vreinterpretq_u64_u8(data_vec)); + } else { /* XXH3_acc_128bits */ + /* xacc[i] += swap(data_vec); */ + uint64x2_t const data64 = vreinterpretq_u64_u8(data_vec); + uint64x2_t const swapped = vextq_u64(data64, data64, 1); + xacc[i] = vaddq_u64 (xacc[i], swapped); + } + /* data_key = data_vec ^ key_vec; */ + data_key = vreinterpretq_u64_u8(veorq_u8(data_vec, key_vec)); + /* data_key_lo = (uint32x2_t) (data_key & 0xFFFFFFFF); + * data_key_hi = (uint32x2_t) (data_key >> 32); + * data_key = UNDEFINED; */ + XXH_SPLIT_IN_PLACE(data_key, data_key_lo, data_key_hi); + /* xacc[i] += (uint64x2_t) data_key_lo * (uint64x2_t) data_key_hi; */ + xacc[i] = vmlal_u32 (xacc[i], data_key_lo, data_key_hi); + + } + } + +#elif (XXH_VECTOR == XXH_VSX) + xxh_u64x2* const xacc = (xxh_u64x2*) acc; /* presumed aligned */ + xxh_u64x2 const* const xinput = (xxh_u64x2 const*) input; /* no alignment restriction */ + xxh_u64x2 const* const xsecret = (xxh_u64x2 const*) secret; /* no alignment restriction */ + xxh_u64x2 const v32 = { 32, 32 }; + size_t i; + for (i = 0; i < STRIPE_LEN / sizeof(xxh_u64x2); i++) { + /* data_vec = xinput[i]; */ + xxh_u64x2 const data_vec = XXH_vec_loadu(xinput + i); + /* key_vec = xsecret[i]; */ + xxh_u64x2 const key_vec = XXH_vec_loadu(xsecret + i); + xxh_u64x2 const data_key = data_vec ^ key_vec; + /* shuffled = (data_key << 32) | (data_key >> 32); */ + xxh_u32x4 const shuffled = (xxh_u32x4)vec_rl(data_key, v32); + /* product = ((xxh_u64x2)data_key & 0xFFFFFFFF) * ((xxh_u64x2)shuffled & 0xFFFFFFFF); */ + xxh_u64x2 const product = XXH_vec_mulo((xxh_u32x4)data_key, shuffled); + xacc[i] += product; + + if (accWidth == XXH3_acc_64bits) { + xacc[i] += data_vec; + } else { /* XXH3_acc_128bits */ + /* swap high and low halves */ +#ifdef __s390x__ + xxh_u64x2 const data_swapped = vec_permi(data_vec, data_vec, 2); +#else + xxh_u64x2 const data_swapped = vec_xxpermdi(data_vec, data_vec, 2); +#endif + xacc[i] += data_swapped; + } + } + +#else /* scalar variant of Accumulator - universal */ + + XXH_ALIGN(XXH_ACC_ALIGN) xxh_u64* const xacc = (xxh_u64*) acc; /* presumed aligned */ + const xxh_u8* const xinput = (const xxh_u8*) input; /* no alignment restriction */ + const xxh_u8* const xsecret = (const xxh_u8*) secret; /* no alignment restriction */ + size_t i; + XXH_ASSERT(((size_t)acc & (XXH_ACC_ALIGN-1)) == 0); + for (i=0; i < ACC_NB; i++) { + xxh_u64 const data_val = XXH_readLE64(xinput + 8*i); + xxh_u64 const data_key = data_val ^ XXH_readLE64(xsecret + i*8); + + if (accWidth == XXH3_acc_64bits) { + xacc[i] += data_val; + } else { + xacc[i ^ 1] += data_val; /* swap adjacent lanes */ + } + xacc[i] += XXH_mult32to64(data_key & 0xFFFFFFFF, data_key >> 32); + } +#endif +} + +/* + * XXH3_scrambleAcc: Scrambles the accumulators to improve mixing. + * + * Multiplication isn't perfect, as explained by Google in HighwayHash: + * + * // Multiplication mixes/scrambles bytes 0-7 of the 64-bit result to + * // varying degrees. In descending order of goodness, bytes + * // 3 4 2 5 1 6 0 7 have quality 228 224 164 160 100 96 36 32. + * // As expected, the upper and lower bytes are much worse. + * + * Source: https://github.com/google/highwayhash/blob/0aaf66b/highwayhash/hh_avx2.h#L291 + * + * Since our algorithm uses a pseudorandom secret to add some variance into the + * mix, we don't need to (or want to) mix as often or as much as HighwayHash does. + * + * This isn't as tight as XXH3_accumulate, but still written in SIMD to avoid + * extraction. + * + * Both XXH3_64bits and XXH3_128bits use this subroutine. + */ +XXH_FORCE_INLINE void +XXH3_scrambleAcc(void* XXH_RESTRICT acc, const void* XXH_RESTRICT secret) +{ +#if (XXH_VECTOR == XXH_AVX512) + + XXH_ASSERT((((size_t)acc) & 63) == 0); + XXH_STATIC_ASSERT(STRIPE_LEN == sizeof(__m512i)); + { XXH_ALIGN(64) __m512i* const xacc = (__m512i*) acc; + const __m512i prime32 = _mm512_set1_epi32((int)PRIME32_1); + + /* xacc[0] ^= (xacc[0] >> 47) */ + __m512i const acc_vec = *xacc; + __m512i const shifted = _mm512_srli_epi64 (acc_vec, 47); + __m512i const data_vec = _mm512_xor_si512 (acc_vec, shifted); + /* xacc[0] ^= secret; */ + __m512i const key_vec = _mm512_loadu_si512 (secret); + __m512i const data_key = _mm512_xor_si512 (data_vec, key_vec); + + /* xacc[0] *= PRIME32_1; */ + __m512i const data_key_hi = _mm512_shuffle_epi32 (data_key, _MM_SHUFFLE(0, 3, 0, 1)); + __m512i const prod_lo = _mm512_mul_epu32 (data_key, prime32); + __m512i const prod_hi = _mm512_mul_epu32 (data_key_hi, prime32); + *xacc = _mm512_add_epi64(prod_lo, _mm512_slli_epi64(prod_hi, 32)); + } + +#elif (XXH_VECTOR == XXH_AVX2) + + XXH_ASSERT((((size_t)acc) & 31) == 0); + { XXH_ALIGN(32) __m256i* const xacc = (__m256i*) acc; + /* Unaligned. This is mainly for pointer arithmetic, and because + * _mm256_loadu_si256 requires a const __m256i * pointer for some reason. */ + const __m256i* const xsecret = (const __m256i *) secret; + const __m256i prime32 = _mm256_set1_epi32((int)PRIME32_1); + + size_t i; + for (i=0; i < STRIPE_LEN/sizeof(__m256i); i++) { + /* xacc[i] ^= (xacc[i] >> 47) */ + __m256i const acc_vec = xacc[i]; + __m256i const shifted = _mm256_srli_epi64 (acc_vec, 47); + __m256i const data_vec = _mm256_xor_si256 (acc_vec, shifted); + /* xacc[i] ^= xsecret; */ + __m256i const key_vec = _mm256_loadu_si256 (xsecret+i); + __m256i const data_key = _mm256_xor_si256 (data_vec, key_vec); + + /* xacc[i] *= PRIME32_1; */ + __m256i const data_key_hi = _mm256_shuffle_epi32 (data_key, _MM_SHUFFLE(0, 3, 0, 1)); + __m256i const prod_lo = _mm256_mul_epu32 (data_key, prime32); + __m256i const prod_hi = _mm256_mul_epu32 (data_key_hi, prime32); + xacc[i] = _mm256_add_epi64(prod_lo, _mm256_slli_epi64(prod_hi, 32)); + } + } + +#elif (XXH_VECTOR == XXH_SSE2) + + XXH_ASSERT((((size_t)acc) & 15) == 0); + { XXH_ALIGN(16) __m128i* const xacc = (__m128i*) acc; + /* Unaligned. This is mainly for pointer arithmetic, and because + * _mm_loadu_si128 requires a const __m128i * pointer for some reason. */ + const __m128i* const xsecret = (const __m128i *) secret; + const __m128i prime32 = _mm_set1_epi32((int)PRIME32_1); + + size_t i; + for (i=0; i < STRIPE_LEN/sizeof(__m128i); i++) { + /* xacc[i] ^= (xacc[i] >> 47) */ + __m128i const acc_vec = xacc[i]; + __m128i const shifted = _mm_srli_epi64 (acc_vec, 47); + __m128i const data_vec = _mm_xor_si128 (acc_vec, shifted); + /* xacc[i] ^= xsecret[i]; */ + __m128i const key_vec = _mm_loadu_si128 (xsecret+i); + __m128i const data_key = _mm_xor_si128 (data_vec, key_vec); + + /* xacc[i] *= PRIME32_1; */ + __m128i const data_key_hi = _mm_shuffle_epi32 (data_key, _MM_SHUFFLE(0, 3, 0, 1)); + __m128i const prod_lo = _mm_mul_epu32 (data_key, prime32); + __m128i const prod_hi = _mm_mul_epu32 (data_key_hi, prime32); + xacc[i] = _mm_add_epi64(prod_lo, _mm_slli_epi64(prod_hi, 32)); + } + } + +#elif (XXH_VECTOR == XXH_NEON) + + XXH_ASSERT((((size_t)acc) & 15) == 0); + + { uint64x2_t* xacc = (uint64x2_t*) acc; + uint8_t const* xsecret = (uint8_t const*) secret; + uint32x2_t prime = vdup_n_u32 (PRIME32_1); + + size_t i; + for (i=0; i < STRIPE_LEN/sizeof(uint64x2_t); i++) { + /* xacc[i] ^= (xacc[i] >> 47); */ + uint64x2_t acc_vec = xacc[i]; + uint64x2_t shifted = vshrq_n_u64 (acc_vec, 47); + uint64x2_t data_vec = veorq_u64 (acc_vec, shifted); + + /* xacc[i] ^= xsecret[i]; */ + uint8x16_t key_vec = vld1q_u8(xsecret + (i * 16)); + uint64x2_t data_key = veorq_u64(data_vec, vreinterpretq_u64_u8(key_vec)); + + /* xacc[i] *= PRIME32_1 */ + uint32x2_t data_key_lo, data_key_hi; + /* data_key_lo = (uint32x2_t) (xacc[i] & 0xFFFFFFFF); + * data_key_hi = (uint32x2_t) (xacc[i] >> 32); + * xacc[i] = UNDEFINED; */ + XXH_SPLIT_IN_PLACE(data_key, data_key_lo, data_key_hi); + { /* + * prod_hi = (data_key >> 32) * PRIME32_1; + * + * Avoid vmul_u32 + vshll_n_u32 since Clang 6 and 7 will + * incorrectly "optimize" this: + * tmp = vmul_u32(vmovn_u64(a), vmovn_u64(b)); + * shifted = vshll_n_u32(tmp, 32); + * to this: + * tmp = "vmulq_u64"(a, b); // no such thing! + * shifted = vshlq_n_u64(tmp, 32); + * + * However, unlike SSE, Clang lacks a 64-bit multiply routine + * for NEON, and it scalarizes two 64-bit multiplies instead. + * + * vmull_u32 has the same timing as vmul_u32, and it avoids + * this bug completely. + * See https://bugs.llvm.org/show_bug.cgi?id=39967 + */ + uint64x2_t prod_hi = vmull_u32 (data_key_hi, prime); + /* xacc[i] = prod_hi << 32; */ + xacc[i] = vshlq_n_u64(prod_hi, 32); + /* xacc[i] += (prod_hi & 0xFFFFFFFF) * PRIME32_1; */ + xacc[i] = vmlal_u32(xacc[i], data_key_lo, prime); + } + } } + +#elif (XXH_VECTOR == XXH_VSX) + + XXH_ASSERT((((size_t)acc) & 15) == 0); + + { xxh_u64x2* const xacc = (xxh_u64x2*) acc; + const xxh_u64x2* const xsecret = (const xxh_u64x2*) secret; + /* constants */ + xxh_u64x2 const v32 = { 32, 32 }; + xxh_u64x2 const v47 = { 47, 47 }; + xxh_u32x4 const prime = { PRIME32_1, PRIME32_1, PRIME32_1, PRIME32_1 }; + size_t i; + for (i = 0; i < STRIPE_LEN / sizeof(xxh_u64x2); i++) { + /* xacc[i] ^= (xacc[i] >> 47); */ + xxh_u64x2 const acc_vec = xacc[i]; + xxh_u64x2 const data_vec = acc_vec ^ (acc_vec >> v47); + + /* xacc[i] ^= xsecret[i]; */ + xxh_u64x2 const key_vec = XXH_vec_loadu(xsecret + i); + xxh_u64x2 const data_key = data_vec ^ key_vec; + + /* xacc[i] *= PRIME32_1 */ + /* prod_lo = ((xxh_u64x2)data_key & 0xFFFFFFFF) * ((xxh_u64x2)prime & 0xFFFFFFFF); */ + xxh_u64x2 const prod_even = XXH_vec_mule((xxh_u32x4)data_key, prime); + /* prod_hi = ((xxh_u64x2)data_key >> 32) * ((xxh_u64x2)prime >> 32); */ + xxh_u64x2 const prod_odd = XXH_vec_mulo((xxh_u32x4)data_key, prime); + xacc[i] = prod_odd + (prod_even << v32); + } } + +#else /* scalar variant of Scrambler - universal */ + + XXH_ALIGN(XXH_ACC_ALIGN) xxh_u64* const xacc = (xxh_u64*) acc; /* presumed aligned */ + const xxh_u8* const xsecret = (const xxh_u8*) secret; /* no alignment restriction */ + size_t i; + XXH_ASSERT((((size_t)acc) & (XXH_ACC_ALIGN-1)) == 0); + for (i=0; i < ACC_NB; i++) { + xxh_u64 const key64 = XXH_readLE64(xsecret + 8*i); + xxh_u64 acc64 = xacc[i]; + acc64 = XXH_xorshift64(acc64, 47); + acc64 ^= key64; + acc64 *= PRIME32_1; + xacc[i] = acc64; + } + +#endif +} + +#define XXH_PREFETCH_DIST 384 + +#ifdef __clang__ // for clang +# define XXH_PREFETCH_DIST_AVX512_64 320 +# define XXH_PREFETCH_DIST_AVX512_128 320 +#else // for gcc +# define XXH_PREFETCH_DIST_AVX512_64 640 +# define XXH_PREFETCH_DIST_AVX512_128 512 +#endif + +/* + * XXH3_accumulate() + * Loops over XXH3_accumulate_512(). + * Assumption: nbStripes will not overflow the secret size + */ +XXH_FORCE_INLINE void +XXH3_accumulate( xxh_u64* XXH_RESTRICT acc, + const xxh_u8* XXH_RESTRICT input, + const xxh_u8* XXH_RESTRICT secret, + size_t nbStripes, + XXH3_accWidth_e accWidth) +{ + size_t n; + for (n = 0; n < nbStripes; n++ ) { + const xxh_u8* const in = input + n*STRIPE_LEN; +#if (XXH_VECTOR == XXH_AVX512) + if (accWidth == XXH3_acc_64bits) XXH_PREFETCH(in + XXH_PREFETCH_DIST_AVX512_64); + else XXH_PREFETCH(in + XXH_PREFETCH_DIST_AVX512_128); +#else + XXH_PREFETCH(in + XXH_PREFETCH_DIST); +#endif + XXH3_accumulate_512(acc, + in, + secret + n*XXH_SECRET_CONSUME_RATE, + accWidth); + } +} + +XXH_FORCE_INLINE void +XXH3_hashLong_internal_loop( xxh_u64* XXH_RESTRICT acc, + const xxh_u8* XXH_RESTRICT input, size_t len, + const xxh_u8* XXH_RESTRICT secret, size_t secretSize, + XXH3_accWidth_e accWidth) +{ + size_t const nb_rounds = (secretSize - STRIPE_LEN) / XXH_SECRET_CONSUME_RATE; + size_t const block_len = STRIPE_LEN * nb_rounds; + size_t const nb_blocks = len / block_len; + + size_t n; + + XXH_ASSERT(secretSize >= XXH3_SECRET_SIZE_MIN); + + for (n = 0; n < nb_blocks; n++) { + XXH3_accumulate(acc, input + n*block_len, secret, nb_rounds, accWidth); + XXH3_scrambleAcc(acc, secret + secretSize - STRIPE_LEN); + } + + /* last partial block */ + XXH_ASSERT(len > STRIPE_LEN); + { size_t const nbStripes = (len - (block_len * nb_blocks)) / STRIPE_LEN; + XXH_ASSERT(nbStripes <= (secretSize / XXH_SECRET_CONSUME_RATE)); + XXH3_accumulate(acc, input + nb_blocks*block_len, secret, nbStripes, accWidth); + + /* last stripe */ + if (len & (STRIPE_LEN - 1)) { + const xxh_u8* const p = input + len - STRIPE_LEN; + /* Do not align on 8, so that the secret is different from the scrambler */ +#define XXH_SECRET_LASTACC_START 7 + XXH3_accumulate_512(acc, p, secret + secretSize - STRIPE_LEN - XXH_SECRET_LASTACC_START, accWidth); + } } +} + +XXH_FORCE_INLINE xxh_u64 +XXH3_mix2Accs(const xxh_u64* XXH_RESTRICT acc, const xxh_u8* XXH_RESTRICT secret) +{ + return XXH3_mul128_fold64( + acc[0] ^ XXH_readLE64(secret), + acc[1] ^ XXH_readLE64(secret+8) ); +} + +static XXH64_hash_t +XXH3_mergeAccs(const xxh_u64* XXH_RESTRICT acc, const xxh_u8* XXH_RESTRICT secret, xxh_u64 start) +{ + xxh_u64 result64 = start; + size_t i = 0; + + for (i = 0; i < 4; i++) { + result64 += XXH3_mix2Accs(acc+2*i, secret + 16*i); +#if defined(__clang__) /* Clang */ \ + && (defined(__arm__) || defined(__thumb__)) /* ARMv7 */ \ + && (defined(__ARM_NEON) || defined(__ARM_NEON__)) /* NEON */ \ + && !defined(XXH_ENABLE_AUTOVECTORIZE) /* Define to disable */ + /* + * UGLY HACK: + * Prevent autovectorization on Clang ARMv7-a. Exact same problem as + * the one in XXH3_len_129to240_64b. Speeds up shorter keys > 240b. + * XXH3_64bits, len == 256, Snapdragon 835: + * without hack: 2063.7 MB/s + * with hack: 2560.7 MB/s + */ + __asm__("" : "+r" (result64)); +#endif + } + + return XXH3_avalanche(result64); +} + +#define XXH3_INIT_ACC { PRIME32_3, PRIME64_1, PRIME64_2, PRIME64_3, \ + PRIME64_4, PRIME32_2, PRIME64_5, PRIME32_1 } + +XXH_FORCE_INLINE XXH64_hash_t +XXH3_hashLong_64b_internal(const xxh_u8* XXH_RESTRICT input, size_t len, + const xxh_u8* XXH_RESTRICT secret, size_t secretSize) +{ + XXH_ALIGN(XXH_ACC_ALIGN) xxh_u64 acc[ACC_NB] = XXH3_INIT_ACC; + + XXH3_hashLong_internal_loop(acc, input, len, secret, secretSize, XXH3_acc_64bits); + + /* converge into final hash */ + XXH_STATIC_ASSERT(sizeof(acc) == 64); + /* do not align on 8, so that the secret is different from the accumulator */ +#define XXH_SECRET_MERGEACCS_START 11 + XXH_ASSERT(secretSize >= sizeof(acc) + XXH_SECRET_MERGEACCS_START); + return XXH3_mergeAccs(acc, secret + XXH_SECRET_MERGEACCS_START, (xxh_u64)len * PRIME64_1); +} + +XXH_FORCE_INLINE void XXH_writeLE64(void* dst, xxh_u64 v64) +{ + if (!XXH_CPU_LITTLE_ENDIAN) v64 = XXH_swap64(v64); + memcpy(dst, &v64, sizeof(v64)); +} + +/* XXH3_initCustomSecret() : + * destination `customSecret` is presumed allocated and same size as `kSecret`. + */ +XXH_FORCE_INLINE void XXH3_initCustomSecret(xxh_u8* XXH_RESTRICT customSecret, xxh_u64 seed64) +{ + int const nbRounds = XXH_SECRET_DEFAULT_SIZE / 16; + int i; + /* + * We need a separate pointer for the hack below. + * Any decent compiler will optimize this out otherwise. + */ + const xxh_u8 *kSecretPtr = kSecret; + + XXH_STATIC_ASSERT((XXH_SECRET_DEFAULT_SIZE & 15) == 0); + +#if defined(__clang__) && defined(__aarch64__) + /* + * UGLY HACK: + * Clang generates a bunch of MOV/MOVK pairs for aarch64, and they are + * placed sequentially, in order, at the top of the unrolled loop. + * + * While MOVK is great for generating constants (2 cycles for a 64-bit + * constant compared to 4 cycles for LDR), long MOVK chains stall the + * integer pipelines: + * I L S + * MOVK + * MOVK + * MOVK + * MOVK + * ADD + * SUB STR + * STR + * By forcing loads from memory (as the asm line causes Clang to assume + * that kSecretPtr has been changed), the pipelines are used more efficiently: + * I L S + * LDR + * ADD LDR + * SUB STR + * STR + * XXH3_64bits_withSeed, len == 256, Snapdragon 835 + * without hack: 2654.4 MB/s + * with hack: 3202.9 MB/s + */ + __asm__("" : "+r" (kSecretPtr)); +#endif + /* + * Note: in debug mode, this overrides the asm optimization + * and Clang will emit MOVK chains again. + */ + XXH_ASSERT(kSecretPtr == kSecret); + + for (i=0; i < nbRounds; i++) { + /* + * The asm hack causes Clang to assume that kSecretPtr aliases with + * customSecret, and on aarch64, this prevented LDP from merging two + * loads together for free. Putting the loads together before the stores + * properly generates LDP. + */ + xxh_u64 lo = XXH_readLE64(kSecretPtr + 16*i) + seed64; + xxh_u64 hi = XXH_readLE64(kSecretPtr + 16*i + 8) - seed64; + XXH_writeLE64(customSecret + 16*i, lo); + XXH_writeLE64(customSecret + 16*i + 8, hi); + } +} + + +/* + * It's important for performance that XXH3_hashLong is not inlined. Not sure + * why (uop cache maybe?), but the difference is large and easily measurable. + */ +XXH_NO_INLINE XXH64_hash_t +XXH3_hashLong_64b_defaultSecret(const xxh_u8* XXH_RESTRICT input, size_t len) +{ + return XXH3_hashLong_64b_internal(input, len, kSecret, sizeof(kSecret)); +} + +/* + * It's important for performance that XXH3_hashLong is not inlined. Not sure + * why (uop cache maybe?), but the difference is large and easily measurable. + */ +XXH_NO_INLINE XXH64_hash_t +XXH3_hashLong_64b_withSecret(const xxh_u8* XXH_RESTRICT input, size_t len, + const xxh_u8* XXH_RESTRICT secret, size_t secretSize) +{ + return XXH3_hashLong_64b_internal(input, len, secret, secretSize); +} + +/* + * XXH3_hashLong_64b_withSeed(): + * Generate a custom key based on alteration of default kSecret with the seed, + * and then use this key for long mode hashing. + * + * This operation is decently fast but nonetheless costs a little bit of time. + * Try to avoid it whenever possible (typically when seed==0). + * + * It's important for performance that XXH3_hashLong is not inlined. Not sure + * why (uop cache maybe?), but the difference is large and easily measurable. + */ +XXH_NO_INLINE XXH64_hash_t +XXH3_hashLong_64b_withSeed(const xxh_u8* input, size_t len, XXH64_hash_t seed) +{ + XXH_ALIGN(8) xxh_u8 secret[XXH_SECRET_DEFAULT_SIZE]; + if (seed==0) return XXH3_hashLong_64b_defaultSecret(input, len); + XXH3_initCustomSecret(secret, seed); + return XXH3_hashLong_64b_internal(input, len, secret, sizeof(secret)); +} + +/* === Public entry point === */ + +XXH_PUBLIC_API XXH64_hash_t XXH3_64bits(const void* input, size_t len) +{ + if (len <= 16) + return XXH3_len_0to16_64b((const xxh_u8*)input, len, kSecret, 0); + if (len <= 128) + return XXH3_len_17to128_64b((const xxh_u8*)input, len, kSecret, sizeof(kSecret), 0); + if (len <= XXH3_MIDSIZE_MAX) + return XXH3_len_129to240_64b((const xxh_u8*)input, len, kSecret, sizeof(kSecret), 0); + return XXH3_hashLong_64b_defaultSecret((const xxh_u8*)input, len); +} + +XXH_PUBLIC_API XXH64_hash_t +XXH3_64bits_withSecret(const void* input, size_t len, const void* secret, size_t secretSize) +{ + XXH_ASSERT(secretSize >= XXH3_SECRET_SIZE_MIN); + /* + * If an action is to be taken if `secret` conditions are not respected, + * it should be done here. + * For now, it's a contract pre-condition. + * Adding a check and a branch here would cost performance at every hash. + */ + if (len <= 16) + return XXH3_len_0to16_64b((const xxh_u8*)input, len, (const xxh_u8*)secret, 0); + if (len <= 128) + return XXH3_len_17to128_64b((const xxh_u8*)input, len, (const xxh_u8*)secret, secretSize, 0); + if (len <= XXH3_MIDSIZE_MAX) + return XXH3_len_129to240_64b((const xxh_u8*)input, len, (const xxh_u8*)secret, secretSize, 0); + return XXH3_hashLong_64b_withSecret((const xxh_u8*)input, len, (const xxh_u8*)secret, secretSize); +} + +XXH_PUBLIC_API XXH64_hash_t +XXH3_64bits_withSeed(const void* input, size_t len, XXH64_hash_t seed) +{ + if (len <= 16) + return XXH3_len_0to16_64b((const xxh_u8*)input, len, kSecret, seed); + if (len <= 128) + return XXH3_len_17to128_64b((const xxh_u8*)input, len, kSecret, sizeof(kSecret), seed); + if (len <= XXH3_MIDSIZE_MAX) + return XXH3_len_129to240_64b((const xxh_u8*)input, len, kSecret, sizeof(kSecret), seed); + return XXH3_hashLong_64b_withSeed((const xxh_u8*)input, len, seed); +} + +/* === XXH3 streaming === */ + + +/* + * Malloc's a pointer that is always aligned to align. + * + * This must be freed with `XXH_alignedFree()`. + * + * malloc typically guarantees 16 byte alignment on 64-bit systems and 8 byte + * alignment on 32-bit. This isn't enough for the 32 byte aligned loads in AVX2 + * or on 32-bit, the 16 byte aligned loads in SSE2 and NEON. + * + * This underalignment previously caused a rather obvious crash which went + * completely unnoticed due to XXH3_createState() not actually being tested. + * Credit to RedSpah for noticing this bug. + * + * The alignment is done manually: Functions like posix_memalign or _mm_malloc + * are avoided: To maintain portability, we would have to write a fallback + * like this anyways, and besides, testing for the existence of library + * functions without relying on external build tools is impossible. + * + * The method is simple: Overallocate, manually align, and store the offset + * to the original behind the returned pointer. + * + * Align must be a power of 2 and 8 <= align <= 128. + */ +static void* XXH_alignedMalloc(size_t s, size_t align) +{ + XXH_ASSERT(align <= 128 && align >= 8); /* range check */ + XXH_ASSERT((align & (align-1)) == 0); /* power of 2 */ + XXH_ASSERT(s != 0 && s < (s + align)); /* empty/overflow */ + { /* Overallocate to make room for manual realignment and an offset byte */ + xxh_u8* base = (xxh_u8*)XXH_malloc(s + align); + if (base != NULL) { + /* + * Get the offset needed to align this pointer. + * + * Even if the returned pointer is aligned, there will always be + * at least one byte to store the offset to the original pointer. + */ + size_t offset = align - ((size_t)base & (align - 1)); /* base % align */ + /* Add the offset for the now-aligned pointer */ + xxh_u8* ptr = base + offset; + + XXH_ASSERT((size_t)ptr % align == 0); + + /* Store the offset immediately before the returned pointer. */ + ptr[-1] = (xxh_u8)offset; + return ptr; + } + return NULL; + } +} +/* + * Frees an aligned pointer allocated by XXH_alignedMalloc(). Don't pass + * normal malloc'd pointers, XXH_alignedMalloc has a specific data layout. + */ +static void XXH_alignedFree(void* p) +{ + if (p != NULL) { + xxh_u8* ptr = (xxh_u8*)p; + /* Get the offset byte we added in XXH_malloc. */ + xxh_u8 offset = ptr[-1]; + /* Free the original malloc'd pointer */ + xxh_u8* base = ptr - offset; + XXH_free(base); + } +} +XXH_PUBLIC_API XXH3_state_t* XXH3_createState(void) +{ + return (XXH3_state_t*)XXH_alignedMalloc(sizeof(XXH3_state_t), 64); +} + +XXH_PUBLIC_API XXH_errorcode XXH3_freeState(XXH3_state_t* statePtr) +{ + XXH_alignedFree(statePtr); + return XXH_OK; +} + +XXH_PUBLIC_API void +XXH3_copyState(XXH3_state_t* dst_state, const XXH3_state_t* src_state) +{ + memcpy(dst_state, src_state, sizeof(*dst_state)); +} + +static void +XXH3_64bits_reset_internal(XXH3_state_t* statePtr, + XXH64_hash_t seed, + const xxh_u8* secret, size_t secretSize) +{ + XXH_ASSERT(statePtr != NULL); + memset(statePtr, 0, sizeof(*statePtr)); + statePtr->acc[0] = PRIME32_3; + statePtr->acc[1] = PRIME64_1; + statePtr->acc[2] = PRIME64_2; + statePtr->acc[3] = PRIME64_3; + statePtr->acc[4] = PRIME64_4; + statePtr->acc[5] = PRIME32_2; + statePtr->acc[6] = PRIME64_5; + statePtr->acc[7] = PRIME32_1; + statePtr->seed = seed; + XXH_ASSERT(secret != NULL); + statePtr->secret = secret; + XXH_ASSERT(secretSize >= XXH3_SECRET_SIZE_MIN); + statePtr->secretLimit = (XXH32_hash_t)(secretSize - STRIPE_LEN); + statePtr->nbStripesPerBlock = statePtr->secretLimit / XXH_SECRET_CONSUME_RATE; +} + +XXH_PUBLIC_API XXH_errorcode +XXH3_64bits_reset(XXH3_state_t* statePtr) +{ + if (statePtr == NULL) return XXH_ERROR; + XXH3_64bits_reset_internal(statePtr, 0, kSecret, XXH_SECRET_DEFAULT_SIZE); + return XXH_OK; +} + +XXH_PUBLIC_API XXH_errorcode +XXH3_64bits_reset_withSecret(XXH3_state_t* statePtr, const void* secret, size_t secretSize) +{ + if (statePtr == NULL) return XXH_ERROR; + XXH3_64bits_reset_internal(statePtr, 0, (const xxh_u8*)secret, secretSize); + if (secret == NULL) return XXH_ERROR; + if (secretSize < XXH3_SECRET_SIZE_MIN) return XXH_ERROR; + return XXH_OK; +} + +XXH_PUBLIC_API XXH_errorcode +XXH3_64bits_reset_withSeed(XXH3_state_t* statePtr, XXH64_hash_t seed) +{ + if (statePtr == NULL) return XXH_ERROR; + XXH3_64bits_reset_internal(statePtr, seed, kSecret, XXH_SECRET_DEFAULT_SIZE); + XXH3_initCustomSecret(statePtr->customSecret, seed); + statePtr->secret = statePtr->customSecret; + return XXH_OK; +} + +XXH_FORCE_INLINE void +XXH3_consumeStripes( xxh_u64* acc, + XXH32_hash_t* nbStripesSoFarPtr, XXH32_hash_t nbStripesPerBlock, + const xxh_u8* input, size_t totalStripes, + const xxh_u8* secret, size_t secretLimit, + XXH3_accWidth_e accWidth) +{ + XXH_ASSERT(*nbStripesSoFarPtr < nbStripesPerBlock); + if (nbStripesPerBlock - *nbStripesSoFarPtr <= totalStripes) { + /* need a scrambling operation */ + size_t const nbStripes = nbStripesPerBlock - *nbStripesSoFarPtr; + XXH3_accumulate(acc, input, secret + nbStripesSoFarPtr[0] * XXH_SECRET_CONSUME_RATE, nbStripes, accWidth); + XXH3_scrambleAcc(acc, secret + secretLimit); + XXH3_accumulate(acc, input + nbStripes * STRIPE_LEN, secret, totalStripes - nbStripes, accWidth); + *nbStripesSoFarPtr = (XXH32_hash_t)(totalStripes - nbStripes); + } else { + XXH3_accumulate(acc, input, secret + nbStripesSoFarPtr[0] * XXH_SECRET_CONSUME_RATE, totalStripes, accWidth); + *nbStripesSoFarPtr += (XXH32_hash_t)totalStripes; + } +} + +/* + * Both XXH3_64bits_update and XXH3_128bits_update use this routine. + */ +XXH_FORCE_INLINE XXH_errorcode +XXH3_update(XXH3_state_t* state, const xxh_u8* input, size_t len, XXH3_accWidth_e accWidth) +{ + if (input==NULL) +#if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1) + return XXH_OK; +#else + return XXH_ERROR; +#endif + + { const xxh_u8* const bEnd = input + len; + + state->totalLen += len; + + if (state->bufferedSize + len <= XXH3_INTERNALBUFFER_SIZE) { /* fill in tmp buffer */ + XXH_memcpy(state->buffer + state->bufferedSize, input, len); + state->bufferedSize += (XXH32_hash_t)len; + return XXH_OK; + } + /* input is now > XXH3_INTERNALBUFFER_SIZE */ + + #define XXH3_INTERNALBUFFER_STRIPES (XXH3_INTERNALBUFFER_SIZE / STRIPE_LEN) + XXH_STATIC_ASSERT(XXH3_INTERNALBUFFER_SIZE % STRIPE_LEN == 0); /* clean multiple */ + + /* + * There is some input left inside the internal buffer. + * Fill it, then consume it. + */ + if (state->bufferedSize) { + size_t const loadSize = XXH3_INTERNALBUFFER_SIZE - state->bufferedSize; + XXH_memcpy(state->buffer + state->bufferedSize, input, loadSize); + input += loadSize; + XXH3_consumeStripes(state->acc, + &state->nbStripesSoFar, state->nbStripesPerBlock, + state->buffer, XXH3_INTERNALBUFFER_STRIPES, + state->secret, state->secretLimit, + accWidth); + state->bufferedSize = 0; + } + + /* Consume input by full buffer quantities */ + if (input+XXH3_INTERNALBUFFER_SIZE <= bEnd) { + const xxh_u8* const limit = bEnd - XXH3_INTERNALBUFFER_SIZE; + do { + XXH3_consumeStripes(state->acc, + &state->nbStripesSoFar, state->nbStripesPerBlock, + input, XXH3_INTERNALBUFFER_STRIPES, + state->secret, state->secretLimit, + accWidth); + input += XXH3_INTERNALBUFFER_SIZE; + } while (input<=limit); + } + + if (input < bEnd) { /* Some remaining input: buffer it */ + XXH_memcpy(state->buffer, input, (size_t)(bEnd-input)); + state->bufferedSize = (XXH32_hash_t)(bEnd-input); + } + } + + return XXH_OK; +} + +XXH_PUBLIC_API XXH_errorcode +XXH3_64bits_update(XXH3_state_t* state, const void* input, size_t len) +{ + return XXH3_update(state, (const xxh_u8*)input, len, XXH3_acc_64bits); +} + + +XXH_FORCE_INLINE void +XXH3_digest_long (XXH64_hash_t* acc, const XXH3_state_t* state, XXH3_accWidth_e accWidth) +{ + /* + * Digest on a local copy. This way, the state remains unaltered, and it can + * continue ingesting more input afterwards. + */ + memcpy(acc, state->acc, sizeof(state->acc)); + if (state->bufferedSize >= STRIPE_LEN) { + size_t const totalNbStripes = state->bufferedSize / STRIPE_LEN; + XXH32_hash_t nbStripesSoFar = state->nbStripesSoFar; + XXH3_consumeStripes(acc, + &nbStripesSoFar, state->nbStripesPerBlock, + state->buffer, totalNbStripes, + state->secret, state->secretLimit, + accWidth); + if (state->bufferedSize % STRIPE_LEN) { /* one last partial stripe */ + XXH3_accumulate_512(acc, + state->buffer + state->bufferedSize - STRIPE_LEN, + state->secret + state->secretLimit - XXH_SECRET_LASTACC_START, + accWidth); + } + } else { /* bufferedSize < STRIPE_LEN */ + if (state->bufferedSize) { /* one last stripe */ + xxh_u8 lastStripe[STRIPE_LEN]; + size_t const catchupSize = STRIPE_LEN - state->bufferedSize; + memcpy(lastStripe, state->buffer + sizeof(state->buffer) - catchupSize, catchupSize); + memcpy(lastStripe + catchupSize, state->buffer, state->bufferedSize); + XXH3_accumulate_512(acc, + lastStripe, + state->secret + state->secretLimit - XXH_SECRET_LASTACC_START, + accWidth); + } } +} + +XXH_PUBLIC_API XXH64_hash_t XXH3_64bits_digest (const XXH3_state_t* state) +{ + if (state->totalLen > XXH3_MIDSIZE_MAX) { + XXH_ALIGN(XXH_ACC_ALIGN) XXH64_hash_t acc[ACC_NB]; + XXH3_digest_long(acc, state, XXH3_acc_64bits); + return XXH3_mergeAccs(acc, + state->secret + XXH_SECRET_MERGEACCS_START, + (xxh_u64)state->totalLen * PRIME64_1); + } + /* len <= XXH3_MIDSIZE_MAX: short code */ + if (state->seed) + return XXH3_64bits_withSeed(state->buffer, (size_t)state->totalLen, state->seed); + return XXH3_64bits_withSecret(state->buffer, (size_t)(state->totalLen), + state->secret, state->secretLimit + STRIPE_LEN); +} + +/* ========================================== + * XXH3 128 bits (a.k.a XXH128) + * ========================================== + * XXH3's 128-bit variant has better mixing and strength than the 64-bit variant, + * even without counting the significantly larger output size. + * + * For example, extra steps are taken to avoid the seed-dependent collisions + * in 17-240 byte inputs (See XXH3_mix16B and XXH128_mix32B). + * + * This strength naturally comes at the cost of some speed, especially on short + * lengths. Note that longer hashes are about as fast as the 64-bit version + * due to it using only a slight modification of the 64-bit loop. + * + * XXH128 is also more oriented towards 64-bit machines. It is still extremely + * fast for a _128-bit_ hash on 32-bit (it usually clears XXH64). + */ + +XXH_FORCE_INLINE XXH128_hash_t +XXH3_len_1to3_128b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed) +{ + /* A doubled version of 1to3_64b with different constants. */ + XXH_ASSERT(input != NULL); + XXH_ASSERT(1 <= len && len <= 3); + XXH_ASSERT(secret != NULL); + /* + * len = 1: combinedl = { input[0], 0x01, input[0], input[0] } + * len = 2: combinedl = { input[1], 0x02, input[0], input[1] } + * len = 3: combinedl = { input[2], 0x03, input[0], input[1] } + */ + { xxh_u8 const c1 = input[0]; + xxh_u8 const c2 = input[len >> 1]; + xxh_u8 const c3 = input[len - 1]; + xxh_u32 const combinedl = ((xxh_u32)c1 <<16) | ((xxh_u32)c2 << 24) + | ((xxh_u32)c3 << 0) | ((xxh_u32)len << 8); + xxh_u32 const combinedh = XXH_rotl32(XXH_swap32(combinedl), 13); + xxh_u64 const bitflipl = (XXH_readLE32(secret) ^ XXH_readLE32(secret+4)) + seed; + xxh_u64 const bitfliph = (XXH_readLE32(secret+8) ^ XXH_readLE32(secret+12)) - seed; + xxh_u64 const keyed_lo = (xxh_u64)combinedl ^ bitflipl; + xxh_u64 const keyed_hi = (xxh_u64)combinedh ^ bitfliph; + xxh_u64 const mixedl = keyed_lo * PRIME64_1; + xxh_u64 const mixedh = keyed_hi * PRIME64_5; + XXH128_hash_t h128; + h128.low64 = XXH3_avalanche(mixedl); + h128.high64 = XXH3_avalanche(mixedh); + return h128; + } +} + +XXH_FORCE_INLINE XXH128_hash_t +XXH3_len_4to8_128b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed) +{ + XXH_ASSERT(input != NULL); + XXH_ASSERT(secret != NULL); + XXH_ASSERT(4 <= len && len <= 8); + seed ^= (xxh_u64)XXH_swap32((xxh_u32)seed) << 32; + { xxh_u32 const input_lo = XXH_readLE32(input); + xxh_u32 const input_hi = XXH_readLE32(input + len - 4); + xxh_u64 const input_64 = input_lo + ((xxh_u64)input_hi << 32); + xxh_u64 const bitflip = (XXH_readLE64(secret+16) ^ XXH_readLE64(secret+24)) + seed; + xxh_u64 const keyed = input_64 ^ bitflip; + + /* Shift len to the left to ensure it is even, this avoids even multiplies. */ + XXH128_hash_t m128 = XXH_mult64to128(keyed, PRIME64_1 + (len << 2)); + + m128.high64 += (m128.low64 << 1); + m128.low64 ^= (m128.high64 >> 3); + + m128.low64 = XXH_xorshift64(m128.low64, 35); + m128.low64 *= 0x9FB21C651E98DF25ULL; + m128.low64 = XXH_xorshift64(m128.low64, 28); + m128.high64 = XXH3_avalanche(m128.high64); + return m128; + } +} + +XXH_FORCE_INLINE XXH128_hash_t +XXH3_len_9to16_128b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed) +{ + XXH_ASSERT(input != NULL); + XXH_ASSERT(secret != NULL); + XXH_ASSERT(9 <= len && len <= 16); + { xxh_u64 const bitflipl = (XXH_readLE64(secret+32) ^ XXH_readLE64(secret+40)) - seed; + xxh_u64 const bitfliph = (XXH_readLE64(secret+48) ^ XXH_readLE64(secret+56)) + seed; + xxh_u64 const input_lo = XXH_readLE64(input); + xxh_u64 input_hi = XXH_readLE64(input + len - 8); + XXH128_hash_t m128 = XXH_mult64to128(input_lo ^ input_hi ^ bitflipl, PRIME64_1); + /* + * Put len in the middle of m128 to ensure that the length gets mixed to + * both the low and high bits in the 128x64 multiply below. + */ + m128.low64 += (xxh_u64)(len - 1) << 54; + input_hi ^= bitfliph; + /* + * Add the high 32 bits of input_hi to the high 32 bits of m128, then + * add the long product of the low 32 bits of input_hi and PRIME32_2 to + * the high 64 bits of m128. + * + * The best approach to this operation is different on 32-bit and 64-bit. + */ + if (sizeof(void *) < sizeof(xxh_u64)) { /* 32-bit */ + /* + * 32-bit optimized version, which is more readable. + * + * On 32-bit, it removes an ADC and delays a dependency between the two + * halves of m128.high64, but it generates an extra mask on 64-bit. + */ + m128.high64 += (input_hi & 0xFFFFFFFF00000000) + XXH_mult32to64((xxh_u32)input_hi, PRIME32_2); + } else { + /* + * 64-bit optimized (albeit more confusing) version. + * + * Uses some properties of addition and multiplication to remove the mask: + * + * Let: + * a = input_hi.lo = (input_hi & 0x00000000FFFFFFFF) + * b = input_hi.hi = (input_hi & 0xFFFFFFFF00000000) + * c = PRIME32_2 + * + * a + (b * c) + * Inverse Property: x + y - x == y + * a + (b * (1 + c - 1)) + * Distributive Property: x * (y + z) == (x * y) + (x * z) + * a + (b * 1) + (b * (c - 1)) + * Identity Property: x * 1 == x + * a + b + (b * (c - 1)) + * + * Substitute a, b, and c: + * input_hi.hi + input_hi.lo + ((xxh_u64)input_hi.lo * (PRIME32_2 - 1)) + * + * Since input_hi.hi + input_hi.lo == input_hi, we get this: + * input_hi + ((xxh_u64)input_hi.lo * (PRIME32_2 - 1)) + */ + m128.high64 += input_hi + XXH_mult32to64((xxh_u32)input_hi, PRIME32_2 - 1); + } + /* m128 ^= XXH_swap64(m128 >> 64); */ + m128.low64 ^= XXH_swap64(m128.high64); + + { /* 128x64 multiply: h128 = m128 * PRIME64_2; */ + XXH128_hash_t h128 = XXH_mult64to128(m128.low64, PRIME64_2); + h128.high64 += m128.high64 * PRIME64_2; + + h128.low64 = XXH3_avalanche(h128.low64); + h128.high64 = XXH3_avalanche(h128.high64); + return h128; + } } +} + +/* + * Assumption: `secret` size is >= XXH3_SECRET_SIZE_MIN + */ +XXH_FORCE_INLINE XXH128_hash_t +XXH3_len_0to16_128b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed) +{ + XXH_ASSERT(len <= 16); + { if (len > 8) return XXH3_len_9to16_128b(input, len, secret, seed); + if (len >= 4) return XXH3_len_4to8_128b(input, len, secret, seed); + if (len) return XXH3_len_1to3_128b(input, len, secret, seed); + { XXH128_hash_t h128; + xxh_u64 const bitflipl = XXH_readLE64(secret+64) ^ XXH_readLE64(secret+72); + xxh_u64 const bitfliph = XXH_readLE64(secret+80) ^ XXH_readLE64(secret+88); + h128.low64 = XXH3_avalanche((PRIME64_1 + seed) ^ bitflipl); + h128.high64 = XXH3_avalanche((PRIME64_2 - seed) ^ bitfliph); + return h128; + } } +} + +/* + * A bit slower than XXH3_mix16B, but handles multiply by zero better. + */ +XXH_FORCE_INLINE XXH128_hash_t +XXH128_mix32B(XXH128_hash_t acc, const xxh_u8* input_1, const xxh_u8* input_2, + const xxh_u8* secret, XXH64_hash_t seed) +{ + acc.low64 += XXH3_mix16B (input_1, secret+0, seed); + acc.low64 ^= XXH_readLE64(input_2) + XXH_readLE64(input_2 + 8); + acc.high64 += XXH3_mix16B (input_2, secret+16, seed); + acc.high64 ^= XXH_readLE64(input_1) + XXH_readLE64(input_1 + 8); + return acc; +} + + +XXH_FORCE_INLINE XXH128_hash_t +XXH3_len_17to128_128b(const xxh_u8* XXH_RESTRICT input, size_t len, + const xxh_u8* XXH_RESTRICT secret, size_t secretSize, + XXH64_hash_t seed) +{ + XXH_ASSERT(secretSize >= XXH3_SECRET_SIZE_MIN); (void)secretSize; + XXH_ASSERT(16 < len && len <= 128); + + { XXH128_hash_t acc; + acc.low64 = len * PRIME64_1; + acc.high64 = 0; + if (len > 32) { + if (len > 64) { + if (len > 96) { + acc = XXH128_mix32B(acc, input+48, input+len-64, secret+96, seed); + } + acc = XXH128_mix32B(acc, input+32, input+len-48, secret+64, seed); + } + acc = XXH128_mix32B(acc, input+16, input+len-32, secret+32, seed); + } + acc = XXH128_mix32B(acc, input, input+len-16, secret, seed); + { XXH128_hash_t h128; + h128.low64 = acc.low64 + acc.high64; + h128.high64 = (acc.low64 * PRIME64_1) + + (acc.high64 * PRIME64_4) + + ((len - seed) * PRIME64_2); + h128.low64 = XXH3_avalanche(h128.low64); + h128.high64 = (XXH64_hash_t)0 - XXH3_avalanche(h128.high64); + return h128; + } + } +} + +XXH_NO_INLINE XXH128_hash_t +XXH3_len_129to240_128b(const xxh_u8* XXH_RESTRICT input, size_t len, + const xxh_u8* XXH_RESTRICT secret, size_t secretSize, + XXH64_hash_t seed) +{ + XXH_ASSERT(secretSize >= XXH3_SECRET_SIZE_MIN); (void)secretSize; + XXH_ASSERT(128 < len && len <= XXH3_MIDSIZE_MAX); + + { XXH128_hash_t acc; + int const nbRounds = (int)len / 32; + int i; + acc.low64 = len * PRIME64_1; + acc.high64 = 0; + for (i=0; i<4; i++) { + acc = XXH128_mix32B(acc, + input + (32 * i), + input + (32 * i) + 16, + secret + (32 * i), + seed); + } + acc.low64 = XXH3_avalanche(acc.low64); + acc.high64 = XXH3_avalanche(acc.high64); + XXH_ASSERT(nbRounds >= 4); + for (i=4 ; i < nbRounds; i++) { + acc = XXH128_mix32B(acc, + input + (32 * i), + input + (32 * i) + 16, + secret + XXH3_MIDSIZE_STARTOFFSET + (32 * (i - 4)), + seed); + } + /* last bytes */ + acc = XXH128_mix32B(acc, + input + len - 16, + input + len - 32, + secret + XXH3_SECRET_SIZE_MIN - XXH3_MIDSIZE_LASTOFFSET - 16, + 0ULL - seed); + + { XXH128_hash_t h128; + h128.low64 = acc.low64 + acc.high64; + h128.high64 = (acc.low64 * PRIME64_1) + + (acc.high64 * PRIME64_4) + + ((len - seed) * PRIME64_2); + h128.low64 = XXH3_avalanche(h128.low64); + h128.high64 = (XXH64_hash_t)0 - XXH3_avalanche(h128.high64); + return h128; + } + } +} + +XXH_FORCE_INLINE XXH128_hash_t +XXH3_hashLong_128b_internal(const xxh_u8* XXH_RESTRICT input, size_t len, + const xxh_u8* XXH_RESTRICT secret, size_t secretSize) +{ + XXH_ALIGN(XXH_ACC_ALIGN) xxh_u64 acc[ACC_NB] = XXH3_INIT_ACC; + + XXH3_hashLong_internal_loop(acc, input, len, secret, secretSize, XXH3_acc_128bits); + + /* converge into final hash */ + XXH_STATIC_ASSERT(sizeof(acc) == 64); + XXH_ASSERT(secretSize >= sizeof(acc) + XXH_SECRET_MERGEACCS_START); + { XXH128_hash_t h128; + h128.low64 = XXH3_mergeAccs(acc, + secret + XXH_SECRET_MERGEACCS_START, + (xxh_u64)len * PRIME64_1); + h128.high64 = XXH3_mergeAccs(acc, + secret + secretSize + - sizeof(acc) - XXH_SECRET_MERGEACCS_START, + ~((xxh_u64)len * PRIME64_2)); + return h128; + } +} + +/* + * It's important for performance that XXH3_hashLong is not inlined. Not sure + * why (uop cache maybe?), but the difference is large and easily measurable. + */ +XXH_NO_INLINE XXH128_hash_t +XXH3_hashLong_128b_defaultSecret(const xxh_u8* input, size_t len) +{ + return XXH3_hashLong_128b_internal(input, len, kSecret, sizeof(kSecret)); +} + +/* + * It's important for performance that XXH3_hashLong is not inlined. Not sure + * why (uop cache maybe?), but the difference is large and easily measurable. + */ +XXH_NO_INLINE XXH128_hash_t +XXH3_hashLong_128b_withSecret(const xxh_u8* input, size_t len, + const xxh_u8* secret, size_t secretSize) +{ + return XXH3_hashLong_128b_internal(input, len, secret, secretSize); +} + +/* + * It's important for performance that XXH3_hashLong is not inlined. Not sure + * why (uop cache maybe?), but the difference is large and easily measurable. + */ +XXH_NO_INLINE XXH128_hash_t +XXH3_hashLong_128b_withSeed(const xxh_u8* input, size_t len, XXH64_hash_t seed) +{ + XXH_ALIGN(8) xxh_u8 secret[XXH_SECRET_DEFAULT_SIZE]; + if (seed == 0) return XXH3_hashLong_128b_defaultSecret(input, len); + XXH3_initCustomSecret(secret, seed); + return XXH3_hashLong_128b_internal(input, len, secret, sizeof(secret)); +} + + +XXH_PUBLIC_API XXH128_hash_t XXH3_128bits(const void* input, size_t len) +{ + if (len <= 16) + return XXH3_len_0to16_128b((const xxh_u8*)input, len, kSecret, 0); + if (len <= 128) + return XXH3_len_17to128_128b((const xxh_u8*)input, len, kSecret, sizeof(kSecret), 0); + if (len <= XXH3_MIDSIZE_MAX) + return XXH3_len_129to240_128b((const xxh_u8*)input, len, kSecret, sizeof(kSecret), 0); + return XXH3_hashLong_128b_defaultSecret((const xxh_u8*)input, len); +} + +XXH_PUBLIC_API XXH128_hash_t +XXH3_128bits_withSecret(const void* input, size_t len, const void* secret, size_t secretSize) +{ + XXH_ASSERT(secretSize >= XXH3_SECRET_SIZE_MIN); + /* + * If an action is to be taken if `secret` conditions are not respected, + * it should be done here. + * For now, it's a contract pre-condition. + * Adding a check and a branch here would cost performance at every hash. + */ + if (len <= 16) + return XXH3_len_0to16_128b((const xxh_u8*)input, len, (const xxh_u8*)secret, 0); + if (len <= 128) + return XXH3_len_17to128_128b((const xxh_u8*)input, len, (const xxh_u8*)secret, secretSize, 0); + if (len <= XXH3_MIDSIZE_MAX) + return XXH3_len_129to240_128b((const xxh_u8*)input, len, (const xxh_u8*)secret, secretSize, 0); + return XXH3_hashLong_128b_withSecret((const xxh_u8*)input, len, (const xxh_u8*)secret, secretSize); +} + +XXH_PUBLIC_API XXH128_hash_t +XXH3_128bits_withSeed(const void* input, size_t len, XXH64_hash_t seed) +{ + if (len <= 16) + return XXH3_len_0to16_128b((const xxh_u8*)input, len, kSecret, seed); + if (len <= 128) + return XXH3_len_17to128_128b((const xxh_u8*)input, len, kSecret, sizeof(kSecret), seed); + if (len <= XXH3_MIDSIZE_MAX) + return XXH3_len_129to240_128b((const xxh_u8*)input, len, kSecret, sizeof(kSecret), seed); + return XXH3_hashLong_128b_withSeed((const xxh_u8*)input, len, seed); +} + +XXH_PUBLIC_API XXH128_hash_t +XXH128(const void* input, size_t len, XXH64_hash_t seed) +{ + return XXH3_128bits_withSeed(input, len, seed); +} + + +/* === XXH3 128-bit streaming === */ + +/* + * All the functions are actually the same as for 64-bit streaming variant. + * The only difference is the finalizatiom routine. + */ + +static void +XXH3_128bits_reset_internal(XXH3_state_t* statePtr, + XXH64_hash_t seed, + const xxh_u8* secret, size_t secretSize) +{ + XXH3_64bits_reset_internal(statePtr, seed, secret, secretSize); +} + +XXH_PUBLIC_API XXH_errorcode +XXH3_128bits_reset(XXH3_state_t* statePtr) +{ + if (statePtr == NULL) return XXH_ERROR; + XXH3_128bits_reset_internal(statePtr, 0, kSecret, XXH_SECRET_DEFAULT_SIZE); + return XXH_OK; +} + +XXH_PUBLIC_API XXH_errorcode +XXH3_128bits_reset_withSecret(XXH3_state_t* statePtr, const void* secret, size_t secretSize) +{ + if (statePtr == NULL) return XXH_ERROR; + XXH3_128bits_reset_internal(statePtr, 0, (const xxh_u8*)secret, secretSize); + if (secret == NULL) return XXH_ERROR; + if (secretSize < XXH3_SECRET_SIZE_MIN) return XXH_ERROR; + return XXH_OK; +} + +XXH_PUBLIC_API XXH_errorcode +XXH3_128bits_reset_withSeed(XXH3_state_t* statePtr, XXH64_hash_t seed) +{ + if (statePtr == NULL) return XXH_ERROR; + XXH3_128bits_reset_internal(statePtr, seed, kSecret, XXH_SECRET_DEFAULT_SIZE); + XXH3_initCustomSecret(statePtr->customSecret, seed); + statePtr->secret = statePtr->customSecret; + return XXH_OK; +} + +XXH_PUBLIC_API XXH_errorcode +XXH3_128bits_update(XXH3_state_t* state, const void* input, size_t len) +{ + return XXH3_update(state, (const xxh_u8*)input, len, XXH3_acc_128bits); +} + +XXH_PUBLIC_API XXH128_hash_t XXH3_128bits_digest (const XXH3_state_t* state) +{ + if (state->totalLen > XXH3_MIDSIZE_MAX) { + XXH_ALIGN(XXH_ACC_ALIGN) XXH64_hash_t acc[ACC_NB]; + XXH3_digest_long(acc, state, XXH3_acc_128bits); + XXH_ASSERT(state->secretLimit + STRIPE_LEN >= sizeof(acc) + XXH_SECRET_MERGEACCS_START); + { XXH128_hash_t h128; + h128.low64 = XXH3_mergeAccs(acc, + state->secret + XXH_SECRET_MERGEACCS_START, + (xxh_u64)state->totalLen * PRIME64_1); + h128.high64 = XXH3_mergeAccs(acc, + state->secret + state->secretLimit + STRIPE_LEN + - sizeof(acc) - XXH_SECRET_MERGEACCS_START, + ~((xxh_u64)state->totalLen * PRIME64_2)); + return h128; + } + } + /* len <= XXH3_MIDSIZE_MAX : short code */ + if (state->seed) + return XXH3_128bits_withSeed(state->buffer, (size_t)state->totalLen, state->seed); + return XXH3_128bits_withSecret(state->buffer, (size_t)(state->totalLen), + state->secret, state->secretLimit + STRIPE_LEN); +} + +/* 128-bit utility functions */ + +#include /* memcmp, memcpy */ + +/* return : 1 is equal, 0 if different */ +XXH_PUBLIC_API int XXH128_isEqual(XXH128_hash_t h1, XXH128_hash_t h2) +{ + /* note : XXH128_hash_t is compact, it has no padding byte */ + return !(memcmp(&h1, &h2, sizeof(h1))); +} + +/* This prototype is compatible with stdlib's qsort(). + * return : >0 if *h128_1 > *h128_2 + * <0 if *h128_1 < *h128_2 + * =0 if *h128_1 == *h128_2 */ +XXH_PUBLIC_API int XXH128_cmp(const void* h128_1, const void* h128_2) +{ + XXH128_hash_t const h1 = *(const XXH128_hash_t*)h128_1; + XXH128_hash_t const h2 = *(const XXH128_hash_t*)h128_2; + int const hcmp = (h1.high64 > h2.high64) - (h2.high64 > h1.high64); + /* note : bets that, in most cases, hash values are different */ + if (hcmp) return hcmp; + return (h1.low64 > h2.low64) - (h2.low64 > h1.low64); +} + + +/*====== Canonical representation ======*/ +XXH_PUBLIC_API void +XXH128_canonicalFromHash(XXH128_canonical_t* dst, XXH128_hash_t hash) +{ + XXH_STATIC_ASSERT(sizeof(XXH128_canonical_t) == sizeof(XXH128_hash_t)); + if (XXH_CPU_LITTLE_ENDIAN) { + hash.high64 = XXH_swap64(hash.high64); + hash.low64 = XXH_swap64(hash.low64); + } + memcpy(dst, &hash.high64, sizeof(hash.high64)); + memcpy((char*)dst + sizeof(hash.high64), &hash.low64, sizeof(hash.low64)); +} + +XXH_PUBLIC_API XXH128_hash_t +XXH128_hashFromCanonical(const XXH128_canonical_t* src) +{ + XXH128_hash_t h; + h.high64 = XXH_readBE64(src); + h.low64 = XXH_readBE64(src->digest + 8); + return h; +} + +/* Pop our optimization override from above */ +#if XXH_VECTOR == XXH_AVX2 /* AVX2 */ \ + && defined(__GNUC__) && !defined(__clang__) /* GCC, not Clang */ \ + && defined(__OPTIMIZE__) && !defined(__OPTIMIZE_SIZE__) /* respect -O0 and -Os */ +# pragma GCC pop_options +#endif + +#endif /* XXH3_H_1397135465 */ diff --git a/src/xxhash/xxhash.c b/src/xxhash/xxhash.c new file mode 100644 index 0000000..0fae88c --- /dev/null +++ b/src/xxhash/xxhash.c @@ -0,0 +1,43 @@ +/* + * xxHash - Extremely Fast Hash algorithm + * Copyright (C) 2012-2020 Yann Collet + * + * BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * You can contact the author at: + * - xxHash homepage: https://www.xxhash.com + * - xxHash source repository: https://github.com/Cyan4973/xxHash + */ + + +/* + * xxhash.c instantiates functions defined in xxhash.h + */ + +#define XXH_STATIC_LINKING_ONLY /* access advanced declarations */ +#define XXH_IMPLEMENTATION /* access definitions */ + +#include "xxhash.h" diff --git a/src/xxhash/xxhash.h b/src/xxhash/xxhash.h new file mode 100644 index 0000000..67a5887 --- /dev/null +++ b/src/xxhash/xxhash.h @@ -0,0 +1,1965 @@ +/* + * xxHash - Extremely Fast Hash algorithm + * Header File + * Copyright (C) 2012-2020 Yann Collet + * + * BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * You can contact the author at: + * - xxHash homepage: https://www.xxhash.com + * - xxHash source repository: https://github.com/Cyan4973/xxHash + */ + +/* TODO: update */ +/* Notice extracted from xxHash homepage: + +xxHash is an extremely fast hash algorithm, running at RAM speed limits. +It also successfully passes all tests from the SMHasher suite. + +Comparison (single thread, Windows Seven 32 bits, using SMHasher on a Core 2 Duo @3GHz) + +Name Speed Q.Score Author +xxHash 5.4 GB/s 10 +CrapWow 3.2 GB/s 2 Andrew +MumurHash 3a 2.7 GB/s 10 Austin Appleby +SpookyHash 2.0 GB/s 10 Bob Jenkins +SBox 1.4 GB/s 9 Bret Mulvey +Lookup3 1.2 GB/s 9 Bob Jenkins +SuperFastHash 1.2 GB/s 1 Paul Hsieh +CityHash64 1.05 GB/s 10 Pike & Alakuijala +FNV 0.55 GB/s 5 Fowler, Noll, Vo +CRC32 0.43 GB/s 9 +MD5-32 0.33 GB/s 10 Ronald L. Rivest +SHA1-32 0.28 GB/s 10 + +Q.Score is a measure of quality of the hash function. +It depends on successfully passing SMHasher test set. +10 is a perfect score. + +Note: SMHasher's CRC32 implementation is not the fastest one. +Other speed-oriented implementations can be faster, +especially in combination with PCLMUL instruction: +https://fastcompression.blogspot.com/2019/03/presenting-xxh3.html?showComment=1552696407071#c3490092340461170735 + +A 64-bit version, named XXH64, is available since r35. +It offers much better speed, but for 64-bit applications only. +Name Speed on 64 bits Speed on 32 bits +XXH64 13.8 GB/s 1.9 GB/s +XXH32 6.8 GB/s 6.0 GB/s +*/ + +#if defined (__cplusplus) +extern "C" { +#endif + +/* **************************** + * INLINE mode + ******************************/ +/*! + * XXH_INLINE_ALL (and XXH_PRIVATE_API) + * Use these build macros to inline xxhash into the target unit. + * Inlining improves performance on small inputs, especially when the length is + * expressed as a compile-time constant: + * + * https://fastcompression.blogspot.com/2018/03/xxhash-for-small-keys-impressive-power.html + * + * It also keeps xxHash symbols private to the unit, so they are not exported. + * + * Usage: + * #define XXH_INLINE_ALL + * #include "xxhash.h" + * + * Do not compile and link xxhash.o as a separate object, as it is not useful. + */ +#if (defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API)) \ + && !defined(XXH_INLINE_ALL_31684351384) + /* this section should be traversed only once */ +# define XXH_INLINE_ALL_31684351384 + /* give access to the advanced API, required to compile implementations */ +# undef XXH_STATIC_LINKING_ONLY /* avoid macro redef */ +# define XXH_STATIC_LINKING_ONLY + /* make all functions private */ +# undef XXH_PUBLIC_API +# if defined(__GNUC__) +# define XXH_PUBLIC_API static __inline __attribute__((unused)) +# elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) +# define XXH_PUBLIC_API static inline +# elif defined(_MSC_VER) +# define XXH_PUBLIC_API static __inline +# else + /* note: this version may generate warnings for unused static functions */ +# define XXH_PUBLIC_API static +# endif + + /* + * This part deals with the special case where a unit wants to inline xxHash, + * but "xxhash.h" has previously been included without XXH_INLINE_ALL, such + * as part of some previously included *.h header file. + * Without further action, the new include would just be ignored, + * and functions would effectively _not_ be inlined (silent failure). + * The following macros solve this situation by prefixing all inlined names, + * avoiding naming collision with previous inclusions. + */ +# ifdef XXH_NAMESPACE +# error "XXH_INLINE_ALL with XXH_NAMESPACE is not supported" + /* + * Note: Alternative: #undef all symbols (it's a pretty large list). + * Without #error: it compiles, but functions are actually not inlined. + */ +# endif +# define XXH_NAMESPACE XXH_INLINE_ + /* + * Some identifiers (enums, type names) are not symbols, but they must + * still be renamed to avoid redeclaration. + * Alternative solution: do not redeclare them. + * However, this requires some #ifdefs, and is a more dispersed action. + * Meanwhile, renaming can be achieved in a single block + */ +# define XXH_IPREF(Id) XXH_INLINE_ ## Id +# define XXH_OK XXH_IPREF(XXH_OK) +# define XXH_ERROR XXH_IPREF(XXH_ERROR) +# define XXH_errorcode XXH_IPREF(XXH_errorcode) +# define XXH32_canonical_t XXH_IPREF(XXH32_canonical_t) +# define XXH64_canonical_t XXH_IPREF(XXH64_canonical_t) +# define XXH128_canonical_t XXH_IPREF(XXH128_canonical_t) +# define XXH32_state_s XXH_IPREF(XXH32_state_s) +# define XXH32_state_t XXH_IPREF(XXH32_state_t) +# define XXH64_state_s XXH_IPREF(XXH64_state_s) +# define XXH64_state_t XXH_IPREF(XXH64_state_t) +# define XXH3_state_s XXH_IPREF(XXH3_state_s) +# define XXH3_state_t XXH_IPREF(XXH3_state_t) +# define XXH128_hash_t XXH_IPREF(XXH128_hash_t) + /* Ensure the header is parsed again, even if it was previously included */ +# undef XXHASH_H_5627135585666179 +# undef XXHASH_H_STATIC_13879238742 +#endif /* XXH_INLINE_ALL || XXH_PRIVATE_API */ + + + +/* **************************************************************** + * Stable API + *****************************************************************/ +#ifndef XXHASH_H_5627135585666179 +#define XXHASH_H_5627135585666179 1 + +/* specific declaration modes for Windows */ +#if !defined(XXH_INLINE_ALL) && !defined(XXH_PRIVATE_API) +# if defined(WIN32) && defined(_MSC_VER) && (defined(XXH_IMPORT) || defined(XXH_EXPORT)) +# ifdef XXH_EXPORT +# define XXH_PUBLIC_API __declspec(dllexport) +# elif XXH_IMPORT +# define XXH_PUBLIC_API __declspec(dllimport) +# endif +# else +# define XXH_PUBLIC_API /* do nothing */ +# endif +#endif + +/*! + * XXH_NAMESPACE, aka Namespace Emulation: + * + * If you want to include _and expose_ xxHash functions from within your own + * library, but also want to avoid symbol collisions with other libraries which + * may also include xxHash, you can use XXH_NAMESPACE to automatically prefix + * any public symbol from xxhash library with the value of XXH_NAMESPACE + * (therefore, avoid empty or numeric values). + * + * Note that no change is required within the calling program as long as it + * includes `xxhash.h`: Regular symbol names will be automatically translated + * by this header. + */ +#ifdef XXH_NAMESPACE +# define XXH_CAT(A,B) A##B +# define XXH_NAME2(A,B) XXH_CAT(A,B) +# define XXH_versionNumber XXH_NAME2(XXH_NAMESPACE, XXH_versionNumber) +# define XXH32 XXH_NAME2(XXH_NAMESPACE, XXH32) +# define XXH32_createState XXH_NAME2(XXH_NAMESPACE, XXH32_createState) +# define XXH32_freeState XXH_NAME2(XXH_NAMESPACE, XXH32_freeState) +# define XXH32_reset XXH_NAME2(XXH_NAMESPACE, XXH32_reset) +# define XXH32_update XXH_NAME2(XXH_NAMESPACE, XXH32_update) +# define XXH32_digest XXH_NAME2(XXH_NAMESPACE, XXH32_digest) +# define XXH32_copyState XXH_NAME2(XXH_NAMESPACE, XXH32_copyState) +# define XXH32_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH32_canonicalFromHash) +# define XXH32_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH32_hashFromCanonical) +# define XXH64 XXH_NAME2(XXH_NAMESPACE, XXH64) +# define XXH64_createState XXH_NAME2(XXH_NAMESPACE, XXH64_createState) +# define XXH64_freeState XXH_NAME2(XXH_NAMESPACE, XXH64_freeState) +# define XXH64_reset XXH_NAME2(XXH_NAMESPACE, XXH64_reset) +# define XXH64_update XXH_NAME2(XXH_NAMESPACE, XXH64_update) +# define XXH64_digest XXH_NAME2(XXH_NAMESPACE, XXH64_digest) +# define XXH64_copyState XXH_NAME2(XXH_NAMESPACE, XXH64_copyState) +# define XXH64_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH64_canonicalFromHash) +# define XXH64_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH64_hashFromCanonical) +#endif + + +/* ************************************* +* Version +***************************************/ +#define XXH_VERSION_MAJOR 0 +#define XXH_VERSION_MINOR 7 +#define XXH_VERSION_RELEASE 4 +#define XXH_VERSION_NUMBER (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE) +XXH_PUBLIC_API unsigned XXH_versionNumber (void); + + +/* **************************** +* Definitions +******************************/ +#include /* size_t */ +typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode; + + +/*-********************************************************************** +* 32-bit hash +************************************************************************/ +#if !defined (__VMS) \ + && (defined (__cplusplus) \ + || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) ) +# include + typedef uint32_t XXH32_hash_t; +#else +# include +# if UINT_MAX == 0xFFFFFFFFUL + typedef unsigned int XXH32_hash_t; +# else +# if ULONG_MAX == 0xFFFFFFFFUL + typedef unsigned long XXH32_hash_t; +# else +# error "unsupported platform: need a 32-bit type" +# endif +# endif +#endif + +/*! + * XXH32(): + * Calculate the 32-bit hash of sequence "length" bytes stored at memory address "input". + * The memory between input & input+length must be valid (allocated and read-accessible). + * "seed" can be used to alter the result predictably. + * Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark): 5.4 GB/s + * + * Note: XXH3 provides competitive speed for both 32-bit and 64-bit systems, + * and offers true 64/128 bit hash results. It provides a superior level of + * dispersion, and greatly reduces the risks of collisions. + */ +XXH_PUBLIC_API XXH32_hash_t XXH32 (const void* input, size_t length, XXH32_hash_t seed); + +/******* Streaming *******/ + +/* + * Streaming functions generate the xxHash value from an incrememtal input. + * This method is slower than single-call functions, due to state management. + * For small inputs, prefer `XXH32()` and `XXH64()`, which are better optimized. + * + * An XXH state must first be allocated using `XXH*_createState()`. + * + * Start a new hash by initializing the state with a seed using `XXH*_reset()`. + * + * Then, feed the hash state by calling `XXH*_update()` as many times as necessary. + * + * The function returns an error code, with 0 meaning OK, and any other value + * meaning there is an error. + * + * Finally, a hash value can be produced anytime, by using `XXH*_digest()`. + * This function returns the nn-bits hash as an int or long long. + * + * It's still possible to continue inserting input into the hash state after a + * digest, and generate new hash values later on by invoking `XXH*_digest()`. + * + * When done, release the state using `XXH*_freeState()`. + */ + +typedef struct XXH32_state_s XXH32_state_t; /* incomplete type */ +XXH_PUBLIC_API XXH32_state_t* XXH32_createState(void); +XXH_PUBLIC_API XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr); +XXH_PUBLIC_API void XXH32_copyState(XXH32_state_t* dst_state, const XXH32_state_t* src_state); + +XXH_PUBLIC_API XXH_errorcode XXH32_reset (XXH32_state_t* statePtr, XXH32_hash_t seed); +XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t* statePtr, const void* input, size_t length); +XXH_PUBLIC_API XXH32_hash_t XXH32_digest (const XXH32_state_t* statePtr); + +/******* Canonical representation *******/ + +/* + * The default return values from XXH functions are unsigned 32 and 64 bit + * integers. + * This the simplest and fastest format for further post-processing. + * + * However, this leaves open the question of what is the order on the byte level, + * since little and big endian conventions will store the same number differently. + * + * The canonical representation settles this issue by mandating big-endian + * convention, the same convention as human-readable numbers (large digits first). + * + * When writing hash values to storage, sending them over a network, or printing + * them, it's highly recommended to use the canonical representation to ensure + * portability across a wider range of systems, present and future. + * + * The following functions allow transformation of hash values to and from + * canonical format. + */ + +typedef struct { unsigned char digest[4]; } XXH32_canonical_t; +XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t hash); +XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src); + + +#ifndef XXH_NO_LONG_LONG +/*-********************************************************************** +* 64-bit hash +************************************************************************/ +#if !defined (__VMS) \ + && (defined (__cplusplus) \ + || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) ) +# include + typedef uint64_t XXH64_hash_t; +#else + /* the following type must have a width of 64-bit */ + typedef unsigned long long XXH64_hash_t; +#endif + +/*! + * XXH64(): + * Returns the 64-bit hash of sequence of length @length stored at memory + * address @input. + * @seed can be used to alter the result predictably. + * + * This function usually runs faster on 64-bit systems, but slower on 32-bit + * systems (see benchmark). + * + * Note: XXH3 provides competitive speed for both 32-bit and 64-bit systems, + * and offers true 64/128 bit hash results. It provides a superior level of + * dispersion, and greatly reduces the risks of collisions. + */ +XXH_PUBLIC_API XXH64_hash_t XXH64 (const void* input, size_t length, XXH64_hash_t seed); + +/******* Streaming *******/ +typedef struct XXH64_state_s XXH64_state_t; /* incomplete type */ +XXH_PUBLIC_API XXH64_state_t* XXH64_createState(void); +XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr); +XXH_PUBLIC_API void XXH64_copyState(XXH64_state_t* dst_state, const XXH64_state_t* src_state); + +XXH_PUBLIC_API XXH_errorcode XXH64_reset (XXH64_state_t* statePtr, XXH64_hash_t seed); +XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t* statePtr, const void* input, size_t length); +XXH_PUBLIC_API XXH64_hash_t XXH64_digest (const XXH64_state_t* statePtr); + +/******* Canonical representation *******/ +typedef struct { unsigned char digest[8]; } XXH64_canonical_t; +XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t hash); +XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src); + + +#endif /* XXH_NO_LONG_LONG */ + +#endif /* XXHASH_H_5627135585666179 */ + + + +#if defined(XXH_STATIC_LINKING_ONLY) && !defined(XXHASH_H_STATIC_13879238742) +#define XXHASH_H_STATIC_13879238742 +/* **************************************************************************** + * This section contains declarations which are not guaranteed to remain stable. + * They may change in future versions, becoming incompatible with a different + * version of the library. + * These declarations should only be used with static linking. + * Never use them in association with dynamic linking! + ***************************************************************************** */ + +/* + * These definitions are only present to allow static allocation of an XXH + * state, for example, on the stack or in a struct. + * Never **ever** access members directly. + */ + +struct XXH32_state_s { + XXH32_hash_t total_len_32; + XXH32_hash_t large_len; + XXH32_hash_t v1; + XXH32_hash_t v2; + XXH32_hash_t v3; + XXH32_hash_t v4; + XXH32_hash_t mem32[4]; + XXH32_hash_t memsize; + XXH32_hash_t reserved; /* never read nor write, might be removed in a future version */ +}; /* typedef'd to XXH32_state_t */ + + +#ifndef XXH_NO_LONG_LONG /* defined when there is no 64-bit support */ + +struct XXH64_state_s { + XXH64_hash_t total_len; + XXH64_hash_t v1; + XXH64_hash_t v2; + XXH64_hash_t v3; + XXH64_hash_t v4; + XXH64_hash_t mem64[4]; + XXH32_hash_t memsize; + XXH32_hash_t reserved32; /* required for padding anyway */ + XXH64_hash_t reserved64; /* never read nor write, might be removed in a future version */ +}; /* typedef'd to XXH64_state_t */ + + +/*-********************************************************************** +* XXH3 +* New experimental hash +************************************************************************/ + +/* ************************************************************************ + * XXH3 is a new hash algorithm featuring: + * - Improved speed for both small and large inputs + * - True 64-bit and 128-bit outputs + * - SIMD acceleration + * - Improved 32-bit viability + * + * Speed analysis methodology is explained here: + * + * https://fastcompression.blogspot.com/2019/03/presenting-xxh3.html + * + * In general, expect XXH3 to run about ~2x faster on large inputs and >3x + * faster on small ones compared to XXH64, though exact differences depend on + * the platform. + * + * The algorithm is portable: Like XXH32 and XXH64, it generates the same hash + * on all platforms. + * + * It benefits greatly from SIMD and 64-bit arithmetic, but does not require it. + * + * Almost all 32-bit and 64-bit targets that can run XXH32 smoothly can run + * XXH3 at competitive speeds, even if XXH64 runs slowly. Further details are + * explained in the implementation. + * + * Optimized implementations are provided for AVX512, AVX2, SSE2, NEON, POWER8, + * ZVector and scalar targets. This can be controlled with the XXH_VECTOR macro. + * + * XXH3 offers 2 variants, _64bits and _128bits. + * When only 64 bits are needed, prefer calling the _64bits variant, as it + * reduces the amount of mixing, resulting in faster speed on small inputs. + * + * It's also generally simpler to manipulate a scalar return type than a struct. + * + * The 128-bit version adds additional strength, but it is slightly slower. + * + * The XXH3 algorithm is still in development. + * The results it produces may still change in future versions. + * + * Results produced by v0.7.x are not comparable with results from v0.7.y. + * However, the API is completely stable, and it can safely be used for + * ephemeral data (local sessions). + * + * Avoid storing values in long-term storage until the algorithm is finalized. + * + * Since v0.7.3, XXH3 has reached "release candidate" status, meaning that, if + * everything remains fine, its current format will be "frozen" and become the + * final one. + * + * After which, return values of XXH3 and XXH128 will no longer change in + * future versions. + * + * XXH3's return values will be officially finalized upon reaching v0.8.0. + * + * The API supports one-shot hashing, streaming mode, and custom secrets. + */ + +#ifdef XXH_NAMESPACE +# define XXH3_64bits XXH_NAME2(XXH_NAMESPACE, XXH3_64bits) +# define XXH3_64bits_withSecret XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_withSecret) +# define XXH3_64bits_withSeed XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_withSeed) + +# define XXH3_createState XXH_NAME2(XXH_NAMESPACE, XXH3_createState) +# define XXH3_freeState XXH_NAME2(XXH_NAMESPACE, XXH3_freeState) +# define XXH3_copyState XXH_NAME2(XXH_NAMESPACE, XXH3_copyState) + +# define XXH3_64bits_reset XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_reset) +# define XXH3_64bits_reset_withSeed XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_reset_withSeed) +# define XXH3_64bits_reset_withSecret XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_reset_withSecret) +# define XXH3_64bits_update XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_update) +# define XXH3_64bits_digest XXH_NAME2(XXH_NAMESPACE, XXH3_64bits_digest) +#endif + +/* XXH3_64bits(): + * default 64-bit variant, using default secret and default seed of 0. + * It's the fastest variant. */ +XXH_PUBLIC_API XXH64_hash_t XXH3_64bits(const void* data, size_t len); + +/* + * XXH3_64bits_withSecret(): + * It's possible to provide any blob of bytes as a "secret" to generate the hash. + * This makes it more difficult for an external actor to prepare an intentional + * collision. + * The secret *must* be large enough (>= XXH3_SECRET_SIZE_MIN). + * It should consist of random bytes. + * Avoid trivial sequences, such as repeating sequences and especially '\0', + * as this can cancel out itself. + * Failure to respect these conditions will result in a poor quality hash. + */ +#define XXH3_SECRET_SIZE_MIN 136 +XXH_PUBLIC_API XXH64_hash_t XXH3_64bits_withSecret(const void* data, size_t len, const void* secret, size_t secretSize); + +/* + * XXH3_64bits_withSeed(): + * This variant generates a custom secret on the fly based on the default + * secret, altered using the `seed` value. + * While this operation is decently fast, note that it's not completely free. + * Note: seed==0 produces the same results as XXH3_64bits(). + */ +XXH_PUBLIC_API XXH64_hash_t XXH3_64bits_withSeed(const void* data, size_t len, XXH64_hash_t seed); + + +/* streaming 64-bit */ + +#if defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11+ */ +# include +# define XXH_ALIGN(n) alignas(n) +#elif defined(__GNUC__) +# define XXH_ALIGN(n) __attribute__ ((aligned(n))) +#elif defined(_MSC_VER) +# define XXH_ALIGN(n) __declspec(align(n)) +#else +# define XXH_ALIGN(n) /* disabled */ +#endif + +/* Old GCC versions only accept the attribute after the type in structures. */ +#if !(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) /* C11+ */ \ + && defined(__GNUC__) +# define XXH_ALIGN_MEMBER(align, type) type XXH_ALIGN(align) +#else +# define XXH_ALIGN_MEMBER(align, type) XXH_ALIGN(align) type +#endif + +typedef struct XXH3_state_s XXH3_state_t; + +#define XXH3_SECRET_DEFAULT_SIZE 192 /* minimum XXH3_SECRET_SIZE_MIN */ +#define XXH3_INTERNALBUFFER_SIZE 256 +struct XXH3_state_s { + XXH_ALIGN_MEMBER(64, XXH64_hash_t acc[8]); + /* used to store a custom secret generated from the seed. Makes state larger. + * Design might change */ + XXH_ALIGN_MEMBER(64, unsigned char customSecret[XXH3_SECRET_DEFAULT_SIZE]); + XXH_ALIGN_MEMBER(64, unsigned char buffer[XXH3_INTERNALBUFFER_SIZE]); + XXH32_hash_t bufferedSize; + XXH32_hash_t nbStripesPerBlock; + XXH32_hash_t nbStripesSoFar; + XXH32_hash_t secretLimit; + XXH32_hash_t reserved32; + XXH32_hash_t reserved32_2; + XXH64_hash_t totalLen; + XXH64_hash_t seed; + XXH64_hash_t reserved64; + /* note: there is some padding after due to alignment on 64 bytes */ + const unsigned char* secret; +}; /* typedef'd to XXH3_state_t */ + +#undef XXH_ALIGN_MEMBER + +/* + * Streaming requires state maintenance. + * This operation costs memory and CPU. + * As a consequence, streaming is slower than one-shot hashing. + * For better performance, prefer one-shot functions whenever possible. + */ +XXH_PUBLIC_API XXH3_state_t* XXH3_createState(void); +XXH_PUBLIC_API XXH_errorcode XXH3_freeState(XXH3_state_t* statePtr); +XXH_PUBLIC_API void XXH3_copyState(XXH3_state_t* dst_state, const XXH3_state_t* src_state); + + +/* + * XXH3_64bits_reset(): + * Initialize with the default parameters. + * The result will be equivalent to `XXH3_64bits()`. + */ +XXH_PUBLIC_API XXH_errorcode XXH3_64bits_reset(XXH3_state_t* statePtr); +/* + * XXH3_64bits_reset_withSeed(): + * Generate a custom secret from `seed`, and store it into `statePtr`. + * digest will be equivalent to `XXH3_64bits_withSeed()`. + */ +XXH_PUBLIC_API XXH_errorcode XXH3_64bits_reset_withSeed(XXH3_state_t* statePtr, XXH64_hash_t seed); +/* + * XXH3_64bits_reset_withSecret(): + * `secret` is referenced, and must outlive the hash streaming session, so + * be careful when using stack arrays. + * `secretSize` must be >= `XXH3_SECRET_SIZE_MIN`. + */ +XXH_PUBLIC_API XXH_errorcode XXH3_64bits_reset_withSecret(XXH3_state_t* statePtr, const void* secret, size_t secretSize); + +XXH_PUBLIC_API XXH_errorcode XXH3_64bits_update (XXH3_state_t* statePtr, const void* input, size_t length); +XXH_PUBLIC_API XXH64_hash_t XXH3_64bits_digest (const XXH3_state_t* statePtr); + + +/* 128-bit */ + +#ifdef XXH_NAMESPACE +# define XXH128 XXH_NAME2(XXH_NAMESPACE, XXH128) +# define XXH3_128bits XXH_NAME2(XXH_NAMESPACE, XXH3_128bits) +# define XXH3_128bits_withSeed XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_withSeed) +# define XXH3_128bits_withSecret XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_withSecret) + +# define XXH3_128bits_reset XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_reset) +# define XXH3_128bits_reset_withSeed XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_reset_withSeed) +# define XXH3_128bits_reset_withSecret XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_reset_withSecret) +# define XXH3_128bits_update XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_update) +# define XXH3_128bits_digest XXH_NAME2(XXH_NAMESPACE, XXH3_128bits_digest) + +# define XXH128_isEqual XXH_NAME2(XXH_NAMESPACE, XXH128_isEqual) +# define XXH128_cmp XXH_NAME2(XXH_NAMESPACE, XXH128_cmp) +# define XXH128_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH128_canonicalFromHash) +# define XXH128_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH128_hashFromCanonical) +#endif + +typedef struct { + XXH64_hash_t low64; + XXH64_hash_t high64; +} XXH128_hash_t; + +XXH_PUBLIC_API XXH128_hash_t XXH128(const void* data, size_t len, XXH64_hash_t seed); +XXH_PUBLIC_API XXH128_hash_t XXH3_128bits(const void* data, size_t len); +XXH_PUBLIC_API XXH128_hash_t XXH3_128bits_withSeed(const void* data, size_t len, XXH64_hash_t seed); /* == XXH128() */ +XXH_PUBLIC_API XXH128_hash_t XXH3_128bits_withSecret(const void* data, size_t len, const void* secret, size_t secretSize); + +XXH_PUBLIC_API XXH_errorcode XXH3_128bits_reset(XXH3_state_t* statePtr); +XXH_PUBLIC_API XXH_errorcode XXH3_128bits_reset_withSeed(XXH3_state_t* statePtr, XXH64_hash_t seed); +XXH_PUBLIC_API XXH_errorcode XXH3_128bits_reset_withSecret(XXH3_state_t* statePtr, const void* secret, size_t secretSize); + +XXH_PUBLIC_API XXH_errorcode XXH3_128bits_update (XXH3_state_t* statePtr, const void* input, size_t length); +XXH_PUBLIC_API XXH128_hash_t XXH3_128bits_digest (const XXH3_state_t* statePtr); + + +/* Note: For better performance, these functions can be inlined using XXH_INLINE_ALL */ + +/*! + * XXH128_isEqual(): + * Return: 1 if `h1` and `h2` are equal, 0 if they are not. + */ +XXH_PUBLIC_API int XXH128_isEqual(XXH128_hash_t h1, XXH128_hash_t h2); + +/*! + * XXH128_cmp(): + * + * This comparator is compatible with stdlib's `qsort()`/`bsearch()`. + * + * return: >0 if *h128_1 > *h128_2 + * <0 if *h128_1 < *h128_2 + * =0 if *h128_1 == *h128_2 + */ +XXH_PUBLIC_API int XXH128_cmp(const void* h128_1, const void* h128_2); + + +/******* Canonical representation *******/ +typedef struct { unsigned char digest[16]; } XXH128_canonical_t; +XXH_PUBLIC_API void XXH128_canonicalFromHash(XXH128_canonical_t* dst, XXH128_hash_t hash); +XXH_PUBLIC_API XXH128_hash_t XXH128_hashFromCanonical(const XXH128_canonical_t* src); + + +#endif /* XXH_NO_LONG_LONG */ + +#if defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API) +# define XXH_IMPLEMENTATION +#endif + +#endif /* defined(XXH_STATIC_LINKING_ONLY) && !defined(XXHASH_H_STATIC_13879238742) */ + + +/* ======================================================================== */ +/* ======================================================================== */ +/* ======================================================================== */ + + +/*-********************************************************************** + * xxHash implementation + *-********************************************************************** + * xxHash's implementation used to be found in xxhash.c. + * + * However, code inlining requires the implementation to be visible to the + * compiler, usually within the header. + * + * As a workaround, xxhash.c used to be included within xxhash.h. This caused + * some issues with some build systems, especially ones which treat .c files + * as source files. + * + * Therefore, the implementation is now directly integrated within xxhash.h. + * Another small advantage is that xxhash.c is no longer needed in /include. + ************************************************************************/ + +#if ( defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API) \ + || defined(XXH_IMPLEMENTATION) ) && !defined(XXH_IMPLEM_13a8737387) +# define XXH_IMPLEM_13a8737387 + +/* ************************************* +* Tuning parameters +***************************************/ +/*! + * XXH_FORCE_MEMORY_ACCESS: + * By default, access to unaligned memory is controlled by `memcpy()`, which is + * safe and portable. + * + * Unfortunately, on some target/compiler combinations, the generated assembly + * is sub-optimal. + * + * The below switch allow to select a different access method for improved + * performance. + * Method 0 (default): + * Use `memcpy()`. Safe and portable. + * Method 1: + * `__attribute__((packed))` statement. It depends on compiler extensions + * and is therefore not portable. + * This method is safe if your compiler supports it, and *generally* as + * fast or faster than `memcpy`. + * Method 2: + * Direct access via cast. This method doesn't depend on the compiler but + * violates the C standard. + * It can generate buggy code on targets which do not support unaligned + * memory accesses. + * But in some circumstances, it's the only known way to get the most + * performance (ie GCC + ARMv6) + * Method 3: + * Byteshift. This can generate the best code on old compilers which don't + * inline small `memcpy()` calls, and it might also be faster on big-endian + * systems which lack a native byteswap instruction. + * See https://stackoverflow.com/a/32095106/646947 for details. + * Prefer these methods in priority order (0 > 1 > 2 > 3) + */ +#ifndef XXH_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */ +# if !defined(__clang__) && defined(__GNUC__) && defined(__ARM_FEATURE_UNALIGNED) && defined(__ARM_ARCH) && (__ARM_ARCH == 6) +# define XXH_FORCE_MEMORY_ACCESS 2 +# elif !defined(__clang__) && ((defined(__INTEL_COMPILER) && !defined(_WIN32)) || \ + (defined(__GNUC__) && (defined(__ARM_ARCH) && __ARM_ARCH >= 7))) +# define XXH_FORCE_MEMORY_ACCESS 1 +# endif +#endif + +/*! + *XXH_ACCEPT_NULL_INPUT_POINTER: + * If the input pointer is NULL, xxHash's default behavior is to dereference it, + * triggering a segfault. + * When this macro is enabled, xxHash actively checks the input for a null pointer. + * If it is, the result for null input pointers is the same as a zero-length input. + */ +#ifndef XXH_ACCEPT_NULL_INPUT_POINTER /* can be defined externally */ +# define XXH_ACCEPT_NULL_INPUT_POINTER 0 +#endif + +/*! + * XXH_FORCE_ALIGN_CHECK: + * This is a minor performance trick, only useful with lots of very small keys. + * It means: check for aligned/unaligned input. + * The check costs one initial branch per hash; + * Set it to 0 when the input is guaranteed to be aligned or when alignment + * doesn't matter for performance. + * + * This option does not affect XXH3. + */ +#ifndef XXH_FORCE_ALIGN_CHECK /* can be defined externally */ +# if defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64) +# define XXH_FORCE_ALIGN_CHECK 0 +# else +# define XXH_FORCE_ALIGN_CHECK 1 +# endif +#endif + +/*! + * XXH_NO_INLINE_HINTS: + * + * By default, xxHash tries to force the compiler to inline almost all internal + * functions. + * + * This can usually improve performance due to reduced jumping and improved + * constant folding, but significantly increases the size of the binary which + * might not be favorable. + * + * Additionally, sometimes the forced inlining can be detrimental to performance, + * depending on the architecture. + * + * XXH_NO_INLINE_HINTS marks all internal functions as static, giving the + * compiler full control on whether to inline or not. + * + * When not optimizing (-O0), optimizing for size (-Os, -Oz), or using + * -fno-inline with GCC or Clang, this will automatically be defined. + */ +#ifndef XXH_NO_INLINE_HINTS +# if defined(__OPTIMIZE_SIZE__) /* -Os, -Oz */ \ + || defined(__NO_INLINE__) /* -O0, -fno-inline */ +# define XXH_NO_INLINE_HINTS 1 +# else +# define XXH_NO_INLINE_HINTS 0 +# endif +#endif + +/*! + * XXH_REROLL: + * Whether to reroll XXH32_finalize, and XXH64_finalize, + * instead of using an unrolled jump table/if statement loop. + * + * This is automatically defined on -Os/-Oz on GCC and Clang. + */ +#ifndef XXH_REROLL +# if defined(__OPTIMIZE_SIZE__) +# define XXH_REROLL 1 +# else +# define XXH_REROLL 0 +# endif +#endif + + +/* ************************************* +* Includes & Memory related functions +***************************************/ +/*! + * Modify the local functions below should you wish to use some other memory + * routines for malloc() and free() + */ +#include + +static void* XXH_malloc(size_t s) { return malloc(s); } +static void XXH_free(void* p) { free(p); } + +/*! and for memcpy() */ +#include +static void* XXH_memcpy(void* dest, const void* src, size_t size) +{ + return memcpy(dest,src,size); +} + +#include /* ULLONG_MAX */ + + +/* ************************************* +* Compiler Specific Options +***************************************/ +#ifdef _MSC_VER /* Visual Studio warning fix */ +# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */ +#endif + +#if XXH_NO_INLINE_HINTS /* disable inlining hints */ +# define XXH_FORCE_INLINE static +# define XXH_NO_INLINE static +#elif defined(_MSC_VER) /* Visual Studio */ +# define XXH_FORCE_INLINE static __forceinline +# define XXH_NO_INLINE static __declspec(noinline) +#else +# if defined (__cplusplus) \ + || defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */ +# ifdef __GNUC__ +# define XXH_FORCE_INLINE static inline __attribute__((always_inline)) +# define XXH_NO_INLINE static __attribute__((noinline)) +# else +# define XXH_FORCE_INLINE static inline +# define XXH_NO_INLINE static +# endif +# else +# define XXH_FORCE_INLINE static +# define XXH_NO_INLINE static +# endif /* __STDC_VERSION__ */ +#endif + + + +/* ************************************* +* Debug +***************************************/ +/* + * DEBUGLEVEL is expected to be defined externally, typically via the compiler's + * command line options. The value must be a number. + */ +#ifndef DEBUGLEVEL +# define DEBUGLEVEL 0 +#endif + +#if (DEBUGLEVEL>=1) +# include /* note: can still be disabled with NDEBUG */ +# define XXH_ASSERT(c) assert(c) +#else +# define XXH_ASSERT(c) ((void)0) +#endif + +/* note: use after variable declarations */ +#define XXH_STATIC_ASSERT(c) do { enum { XXH_sa = 1/(int)(!!(c)) }; } while (0) + + +/* ************************************* +* Basic Types +***************************************/ +#if !defined (__VMS) \ + && (defined (__cplusplus) \ + || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) ) +# include + typedef uint8_t xxh_u8; +#else + typedef unsigned char xxh_u8; +#endif +typedef XXH32_hash_t xxh_u32; + + +/* *** Memory access *** */ + +#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3)) +/* + * Manual byteshift. Best for old compilers which don't inline memcpy. + * We actually directly use XXH_readLE32 and XXH_readBE32. + */ +#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==2)) + +/* + * Force direct memory access. Only works on CPU which support unaligned memory + * access in hardware. + */ +static xxh_u32 XXH_read32(const void* memPtr) { return *(const xxh_u32*) memPtr; } + +#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==1)) + +/* + * __pack instructions are safer but compiler specific, hence potentially + * problematic for some compilers. + * + * Currently only defined for GCC and ICC. + */ +typedef union { xxh_u32 u32; } __attribute__((packed)) unalign; +static xxh_u32 XXH_read32(const void* ptr) { return ((const unalign*)ptr)->u32; } + +#else + +/* + * Portable and safe solution. Generally efficient. + * see: https://stackoverflow.com/a/32095106/646947 + */ +static xxh_u32 XXH_read32(const void* memPtr) +{ + xxh_u32 val; + memcpy(&val, memPtr, sizeof(val)); + return val; +} + +#endif /* XXH_FORCE_DIRECT_MEMORY_ACCESS */ + + +/* *** Endianess *** */ +typedef enum { XXH_bigEndian=0, XXH_littleEndian=1 } XXH_endianess; + +/*! + * XXH_CPU_LITTLE_ENDIAN: + * Defined to 1 if the target is little endian, or 0 if it is big endian. + * It can be defined externally, for example on the compiler command line. + * + * If it is not defined, a runtime check (which is usually constant folded) + * is used instead. + */ +#ifndef XXH_CPU_LITTLE_ENDIAN +/* + * Try to detect endianness automatically, to avoid the nonstandard behavior + * in `XXH_isLittleEndian()` + */ +# if defined(_WIN32) /* Windows is always little endian */ \ + || defined(__LITTLE_ENDIAN__) \ + || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +# define XXH_CPU_LITTLE_ENDIAN 1 +# elif defined(__BIG_ENDIAN__) \ + || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +# define XXH_CPU_LITTLE_ENDIAN 0 +# else +static int XXH_isLittleEndian(void) +{ + /* + * Nonstandard, but well-defined behavior in practice. + * Don't use static: it is detrimental to performance. + */ + const union { xxh_u32 u; xxh_u8 c[4]; } one = { 1 }; + return one.c[0]; +} +# define XXH_CPU_LITTLE_ENDIAN XXH_isLittleEndian() +# endif +#endif + + + + +/* **************************************** +* Compiler-specific Functions and Macros +******************************************/ +#define XXH_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) + +#ifndef __has_builtin +# define __has_builtin(x) 0 +#endif + +#if !defined(NO_CLANG_BUILTIN) && __has_builtin(__builtin_rotateleft32) \ + && __has_builtin(__builtin_rotateleft64) +# define XXH_rotl32 __builtin_rotateleft32 +# define XXH_rotl64 __builtin_rotateleft64 +/* Note: although _rotl exists for minGW (GCC under windows), performance seems poor */ +#elif defined(_MSC_VER) +# define XXH_rotl32(x,r) _rotl(x,r) +# define XXH_rotl64(x,r) _rotl64(x,r) +#else +# define XXH_rotl32(x,r) (((x) << (r)) | ((x) >> (32 - (r)))) +# define XXH_rotl64(x,r) (((x) << (r)) | ((x) >> (64 - (r)))) +#endif + +#if defined(_MSC_VER) /* Visual Studio */ +# define XXH_swap32 _byteswap_ulong +#elif XXH_GCC_VERSION >= 403 +# define XXH_swap32 __builtin_bswap32 +#else +static xxh_u32 XXH_swap32 (xxh_u32 x) +{ + return ((x << 24) & 0xff000000 ) | + ((x << 8) & 0x00ff0000 ) | + ((x >> 8) & 0x0000ff00 ) | + ((x >> 24) & 0x000000ff ); +} +#endif + + +/* *************************** +* Memory reads +*****************************/ +typedef enum { XXH_aligned, XXH_unaligned } XXH_alignment; + +/* + * XXH_FORCE_MEMORY_ACCESS==3 is an endian-independent byteshift load. + * + * This is ideal for older compilers which don't inline memcpy. + */ +#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3)) + +XXH_FORCE_INLINE xxh_u32 XXH_readLE32(const void* memPtr) +{ + const xxh_u8* bytePtr = (const xxh_u8 *)memPtr; + return bytePtr[0] + | ((xxh_u32)bytePtr[1] << 8) + | ((xxh_u32)bytePtr[2] << 16) + | ((xxh_u32)bytePtr[3] << 24); +} + +XXH_FORCE_INLINE xxh_u32 XXH_readBE32(const void* memPtr) +{ + const xxh_u8* bytePtr = (const xxh_u8 *)memPtr; + return bytePtr[3] + | ((xxh_u32)bytePtr[2] << 8) + | ((xxh_u32)bytePtr[1] << 16) + | ((xxh_u32)bytePtr[0] << 24); +} + +#else +XXH_FORCE_INLINE xxh_u32 XXH_readLE32(const void* ptr) +{ + return XXH_CPU_LITTLE_ENDIAN ? XXH_read32(ptr) : XXH_swap32(XXH_read32(ptr)); +} + +static xxh_u32 XXH_readBE32(const void* ptr) +{ + return XXH_CPU_LITTLE_ENDIAN ? XXH_swap32(XXH_read32(ptr)) : XXH_read32(ptr); +} +#endif + +XXH_FORCE_INLINE xxh_u32 +XXH_readLE32_align(const void* ptr, XXH_alignment align) +{ + if (align==XXH_unaligned) { + return XXH_readLE32(ptr); + } else { + return XXH_CPU_LITTLE_ENDIAN ? *(const xxh_u32*)ptr : XXH_swap32(*(const xxh_u32*)ptr); + } +} + + +/* ************************************* +* Misc +***************************************/ +XXH_PUBLIC_API unsigned XXH_versionNumber (void) { return XXH_VERSION_NUMBER; } + + +/* ******************************************************************* +* 32-bit hash functions +*********************************************************************/ +static const xxh_u32 PRIME32_1 = 0x9E3779B1U; /* 0b10011110001101110111100110110001 */ +static const xxh_u32 PRIME32_2 = 0x85EBCA77U; /* 0b10000101111010111100101001110111 */ +static const xxh_u32 PRIME32_3 = 0xC2B2AE3DU; /* 0b11000010101100101010111000111101 */ +static const xxh_u32 PRIME32_4 = 0x27D4EB2FU; /* 0b00100111110101001110101100101111 */ +static const xxh_u32 PRIME32_5 = 0x165667B1U; /* 0b00010110010101100110011110110001 */ + +static xxh_u32 XXH32_round(xxh_u32 acc, xxh_u32 input) +{ + acc += input * PRIME32_2; + acc = XXH_rotl32(acc, 13); + acc *= PRIME32_1; +#if defined(__GNUC__) && defined(__SSE4_1__) && !defined(XXH_ENABLE_AUTOVECTORIZE) + /* + * UGLY HACK: + * This inline assembly hack forces acc into a normal register. This is the + * only thing that prevents GCC and Clang from autovectorizing the XXH32 + * loop (pragmas and attributes don't work for some resason) without globally + * disabling SSE4.1. + * + * The reason we want to avoid vectorization is because despite working on + * 4 integers at a time, there are multiple factors slowing XXH32 down on + * SSE4: + * - There's a ridiculous amount of lag from pmulld (10 cycles of latency on + * newer chips!) making it slightly slower to multiply four integers at + * once compared to four integers independently. Even when pmulld was + * fastest, Sandy/Ivy Bridge, it is still not worth it to go into SSE + * just to multiply unless doing a long operation. + * + * - Four instructions are required to rotate, + * movqda tmp, v // not required with VEX encoding + * pslld tmp, 13 // tmp <<= 13 + * psrld v, 19 // x >>= 19 + * por v, tmp // x |= tmp + * compared to one for scalar: + * roll v, 13 // reliably fast across the board + * shldl v, v, 13 // Sandy Bridge and later prefer this for some reason + * + * - Instruction level parallelism is actually more beneficial here because + * the SIMD actually serializes this operation: While v1 is rotating, v2 + * can load data, while v3 can multiply. SSE forces them to operate + * together. + * + * How this hack works: + * __asm__("" // Declare an assembly block but don't declare any instructions + * : // However, as an Input/Output Operand, + * "+r" // constrain a read/write operand (+) as a general purpose register (r). + * (acc) // and set acc as the operand + * ); + * + * Because of the 'r', the compiler has promised that seed will be in a + * general purpose register and the '+' says that it will be 'read/write', + * so it has to assume it has changed. It is like volatile without all the + * loads and stores. + * + * Since the argument has to be in a normal register (not an SSE register), + * each time XXH32_round is called, it is impossible to vectorize. + */ + __asm__("" : "+r" (acc)); +#endif + return acc; +} + +/* mix all bits */ +static xxh_u32 XXH32_avalanche(xxh_u32 h32) +{ + h32 ^= h32 >> 15; + h32 *= PRIME32_2; + h32 ^= h32 >> 13; + h32 *= PRIME32_3; + h32 ^= h32 >> 16; + return(h32); +} + +#define XXH_get32bits(p) XXH_readLE32_align(p, align) + +static xxh_u32 +XXH32_finalize(xxh_u32 h32, const xxh_u8* ptr, size_t len, XXH_alignment align) +{ +#define PROCESS1 do { \ + h32 += (*ptr++) * PRIME32_5; \ + h32 = XXH_rotl32(h32, 11) * PRIME32_1; \ +} while (0) + +#define PROCESS4 do { \ + h32 += XXH_get32bits(ptr) * PRIME32_3; \ + ptr += 4; \ + h32 = XXH_rotl32(h32, 17) * PRIME32_4; \ +} while (0) + + /* Compact rerolled version */ + if (XXH_REROLL) { + len &= 15; + while (len >= 4) { + PROCESS4; + len -= 4; + } + while (len > 0) { + PROCESS1; + --len; + } + return XXH32_avalanche(h32); + } else { + switch(len&15) /* or switch(bEnd - p) */ { + case 12: PROCESS4; + /* fallthrough */ + case 8: PROCESS4; + /* fallthrough */ + case 4: PROCESS4; + return XXH32_avalanche(h32); + + case 13: PROCESS4; + /* fallthrough */ + case 9: PROCESS4; + /* fallthrough */ + case 5: PROCESS4; + PROCESS1; + return XXH32_avalanche(h32); + + case 14: PROCESS4; + /* fallthrough */ + case 10: PROCESS4; + /* fallthrough */ + case 6: PROCESS4; + PROCESS1; + PROCESS1; + return XXH32_avalanche(h32); + + case 15: PROCESS4; + /* fallthrough */ + case 11: PROCESS4; + /* fallthrough */ + case 7: PROCESS4; + /* fallthrough */ + case 3: PROCESS1; + /* fallthrough */ + case 2: PROCESS1; + /* fallthrough */ + case 1: PROCESS1; + /* fallthrough */ + case 0: return XXH32_avalanche(h32); + } + XXH_ASSERT(0); + return h32; /* reaching this point is deemed impossible */ + } +} + +XXH_FORCE_INLINE xxh_u32 +XXH32_endian_align(const xxh_u8* input, size_t len, xxh_u32 seed, XXH_alignment align) +{ + const xxh_u8* bEnd = input + len; + xxh_u32 h32; + +#if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1) + if (input==NULL) { + len=0; + bEnd=input=(const xxh_u8*)(size_t)16; + } +#endif + + if (len>=16) { + const xxh_u8* const limit = bEnd - 15; + xxh_u32 v1 = seed + PRIME32_1 + PRIME32_2; + xxh_u32 v2 = seed + PRIME32_2; + xxh_u32 v3 = seed + 0; + xxh_u32 v4 = seed - PRIME32_1; + + do { + v1 = XXH32_round(v1, XXH_get32bits(input)); input += 4; + v2 = XXH32_round(v2, XXH_get32bits(input)); input += 4; + v3 = XXH32_round(v3, XXH_get32bits(input)); input += 4; + v4 = XXH32_round(v4, XXH_get32bits(input)); input += 4; + } while (input < limit); + + h32 = XXH_rotl32(v1, 1) + XXH_rotl32(v2, 7) + + XXH_rotl32(v3, 12) + XXH_rotl32(v4, 18); + } else { + h32 = seed + PRIME32_5; + } + + h32 += (xxh_u32)len; + + return XXH32_finalize(h32, input, len&15, align); +} + + +XXH_PUBLIC_API XXH32_hash_t XXH32 (const void* input, size_t len, XXH32_hash_t seed) +{ +#if 0 + /* Simple version, good for code maintenance, but unfortunately slow for small inputs */ + XXH32_state_t state; + XXH32_reset(&state, seed); + XXH32_update(&state, (const xxh_u8*)input, len); + return XXH32_digest(&state); + +#else + + if (XXH_FORCE_ALIGN_CHECK) { + if ((((size_t)input) & 3) == 0) { /* Input is 4-bytes aligned, leverage the speed benefit */ + return XXH32_endian_align((const xxh_u8*)input, len, seed, XXH_aligned); + } } + + return XXH32_endian_align((const xxh_u8*)input, len, seed, XXH_unaligned); +#endif +} + + + +/******* Hash streaming *******/ + +XXH_PUBLIC_API XXH32_state_t* XXH32_createState(void) +{ + return (XXH32_state_t*)XXH_malloc(sizeof(XXH32_state_t)); +} +XXH_PUBLIC_API XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr) +{ + XXH_free(statePtr); + return XXH_OK; +} + +XXH_PUBLIC_API void XXH32_copyState(XXH32_state_t* dstState, const XXH32_state_t* srcState) +{ + memcpy(dstState, srcState, sizeof(*dstState)); +} + +XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t* statePtr, XXH32_hash_t seed) +{ + XXH32_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */ + memset(&state, 0, sizeof(state)); + state.v1 = seed + PRIME32_1 + PRIME32_2; + state.v2 = seed + PRIME32_2; + state.v3 = seed + 0; + state.v4 = seed - PRIME32_1; + /* do not write into reserved, planned to be removed in a future version */ + memcpy(statePtr, &state, sizeof(state) - sizeof(state.reserved)); + return XXH_OK; +} + + +XXH_PUBLIC_API XXH_errorcode +XXH32_update(XXH32_state_t* state, const void* input, size_t len) +{ + if (input==NULL) +#if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1) + return XXH_OK; +#else + return XXH_ERROR; +#endif + + { const xxh_u8* p = (const xxh_u8*)input; + const xxh_u8* const bEnd = p + len; + + state->total_len_32 += (XXH32_hash_t)len; + state->large_len |= (XXH32_hash_t)((len>=16) | (state->total_len_32>=16)); + + if (state->memsize + len < 16) { /* fill in tmp buffer */ + XXH_memcpy((xxh_u8*)(state->mem32) + state->memsize, input, len); + state->memsize += (XXH32_hash_t)len; + return XXH_OK; + } + + if (state->memsize) { /* some data left from previous update */ + XXH_memcpy((xxh_u8*)(state->mem32) + state->memsize, input, 16-state->memsize); + { const xxh_u32* p32 = state->mem32; + state->v1 = XXH32_round(state->v1, XXH_readLE32(p32)); p32++; + state->v2 = XXH32_round(state->v2, XXH_readLE32(p32)); p32++; + state->v3 = XXH32_round(state->v3, XXH_readLE32(p32)); p32++; + state->v4 = XXH32_round(state->v4, XXH_readLE32(p32)); + } + p += 16-state->memsize; + state->memsize = 0; + } + + if (p <= bEnd-16) { + const xxh_u8* const limit = bEnd - 16; + xxh_u32 v1 = state->v1; + xxh_u32 v2 = state->v2; + xxh_u32 v3 = state->v3; + xxh_u32 v4 = state->v4; + + do { + v1 = XXH32_round(v1, XXH_readLE32(p)); p+=4; + v2 = XXH32_round(v2, XXH_readLE32(p)); p+=4; + v3 = XXH32_round(v3, XXH_readLE32(p)); p+=4; + v4 = XXH32_round(v4, XXH_readLE32(p)); p+=4; + } while (p<=limit); + + state->v1 = v1; + state->v2 = v2; + state->v3 = v3; + state->v4 = v4; + } + + if (p < bEnd) { + XXH_memcpy(state->mem32, p, (size_t)(bEnd-p)); + state->memsize = (unsigned)(bEnd-p); + } + } + + return XXH_OK; +} + + +XXH_PUBLIC_API XXH32_hash_t XXH32_digest (const XXH32_state_t* state) +{ + xxh_u32 h32; + + if (state->large_len) { + h32 = XXH_rotl32(state->v1, 1) + + XXH_rotl32(state->v2, 7) + + XXH_rotl32(state->v3, 12) + + XXH_rotl32(state->v4, 18); + } else { + h32 = state->v3 /* == seed */ + PRIME32_5; + } + + h32 += state->total_len_32; + + return XXH32_finalize(h32, (const xxh_u8*)state->mem32, state->memsize, XXH_aligned); +} + + +/******* Canonical representation *******/ + +/* + * The default return values from XXH functions are unsigned 32 and 64 bit + * integers. + * + * The canonical representation uses big endian convention, the same convention + * as human-readable numbers (large digits first). + * + * This way, hash values can be written into a file or buffer, remaining + * comparable across different systems. + * + * The following functions allow transformation of hash values to and from their + * canonical format. + */ +XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t hash) +{ + XXH_STATIC_ASSERT(sizeof(XXH32_canonical_t) == sizeof(XXH32_hash_t)); + if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap32(hash); + memcpy(dst, &hash, sizeof(*dst)); +} + +XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src) +{ + return XXH_readBE32(src); +} + + +#ifndef XXH_NO_LONG_LONG + +/* ******************************************************************* +* 64-bit hash functions +*********************************************************************/ + +/******* Memory access *******/ + +typedef XXH64_hash_t xxh_u64; + + +/*! + * XXH_REROLL_XXH64: + * Whether to reroll the XXH64_finalize() loop. + * + * Just like XXH32, we can unroll the XXH64_finalize() loop. This can be a + * performance gain on 64-bit hosts, as only one jump is required. + * + * However, on 32-bit hosts, because arithmetic needs to be done with two 32-bit + * registers, and 64-bit arithmetic needs to be simulated, it isn't beneficial + * to unroll. The code becomes ridiculously large (the largest function in the + * binary on i386!), and rerolling it saves anywhere from 3kB to 20kB. It is + * also slightly faster because it fits into cache better and is more likely + * to be inlined by the compiler. + * + * If XXH_REROLL is defined, this is ignored and the loop is always rerolled. + */ +#ifndef XXH_REROLL_XXH64 +# if (defined(__ILP32__) || defined(_ILP32)) /* ILP32 is often defined on 32-bit GCC family */ \ + || !(defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64) /* x86-64 */ \ + || defined(_M_ARM64) || defined(__aarch64__) || defined(__arm64__) /* aarch64 */ \ + || defined(__PPC64__) || defined(__PPC64LE__) || defined(__ppc64__) || defined(__powerpc64__) /* ppc64 */ \ + || defined(__mips64__) || defined(__mips64)) /* mips64 */ \ + || (!defined(SIZE_MAX) || SIZE_MAX < ULLONG_MAX) /* check limits */ +# define XXH_REROLL_XXH64 1 +# else +# define XXH_REROLL_XXH64 0 +# endif +#endif /* !defined(XXH_REROLL_XXH64) */ + +#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3)) +/* + * Manual byteshift. Best for old compilers which don't inline memcpy. + * We actually directly use XXH_readLE64 and XXH_readBE64. + */ +#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==2)) + +/* Force direct memory access. Only works on CPU which support unaligned memory access in hardware */ +static xxh_u64 XXH_read64(const void* memPtr) { return *(const xxh_u64*) memPtr; } + +#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==1)) + +/* + * __pack instructions are safer, but compiler specific, hence potentially + * problematic for some compilers. + * + * Currently only defined for GCC and ICC. + */ +typedef union { xxh_u32 u32; xxh_u64 u64; } __attribute__((packed)) unalign64; +static xxh_u64 XXH_read64(const void* ptr) { return ((const unalign64*)ptr)->u64; } + +#else + +/* + * Portable and safe solution. Generally efficient. + * see: https://stackoverflow.com/a/32095106/646947 + */ +static xxh_u64 XXH_read64(const void* memPtr) +{ + xxh_u64 val; + memcpy(&val, memPtr, sizeof(val)); + return val; +} + +#endif /* XXH_FORCE_DIRECT_MEMORY_ACCESS */ + +#if defined(_MSC_VER) /* Visual Studio */ +# define XXH_swap64 _byteswap_uint64 +#elif XXH_GCC_VERSION >= 403 +# define XXH_swap64 __builtin_bswap64 +#else +static xxh_u64 XXH_swap64 (xxh_u64 x) +{ + return ((x << 56) & 0xff00000000000000ULL) | + ((x << 40) & 0x00ff000000000000ULL) | + ((x << 24) & 0x0000ff0000000000ULL) | + ((x << 8) & 0x000000ff00000000ULL) | + ((x >> 8) & 0x00000000ff000000ULL) | + ((x >> 24) & 0x0000000000ff0000ULL) | + ((x >> 40) & 0x000000000000ff00ULL) | + ((x >> 56) & 0x00000000000000ffULL); +} +#endif + + +/* XXH_FORCE_MEMORY_ACCESS==3 is an endian-independent byteshift load. */ +#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==3)) + +XXH_FORCE_INLINE xxh_u64 XXH_readLE64(const void* memPtr) +{ + const xxh_u8* bytePtr = (const xxh_u8 *)memPtr; + return bytePtr[0] + | ((xxh_u64)bytePtr[1] << 8) + | ((xxh_u64)bytePtr[2] << 16) + | ((xxh_u64)bytePtr[3] << 24) + | ((xxh_u64)bytePtr[4] << 32) + | ((xxh_u64)bytePtr[5] << 40) + | ((xxh_u64)bytePtr[6] << 48) + | ((xxh_u64)bytePtr[7] << 56); +} + +XXH_FORCE_INLINE xxh_u64 XXH_readBE64(const void* memPtr) +{ + const xxh_u8* bytePtr = (const xxh_u8 *)memPtr; + return bytePtr[7] + | ((xxh_u64)bytePtr[6] << 8) + | ((xxh_u64)bytePtr[5] << 16) + | ((xxh_u64)bytePtr[4] << 24) + | ((xxh_u64)bytePtr[3] << 32) + | ((xxh_u64)bytePtr[2] << 40) + | ((xxh_u64)bytePtr[1] << 48) + | ((xxh_u64)bytePtr[0] << 56); +} + +#else +XXH_FORCE_INLINE xxh_u64 XXH_readLE64(const void* ptr) +{ + return XXH_CPU_LITTLE_ENDIAN ? XXH_read64(ptr) : XXH_swap64(XXH_read64(ptr)); +} + +static xxh_u64 XXH_readBE64(const void* ptr) +{ + return XXH_CPU_LITTLE_ENDIAN ? XXH_swap64(XXH_read64(ptr)) : XXH_read64(ptr); +} +#endif + +XXH_FORCE_INLINE xxh_u64 +XXH_readLE64_align(const void* ptr, XXH_alignment align) +{ + if (align==XXH_unaligned) + return XXH_readLE64(ptr); + else + return XXH_CPU_LITTLE_ENDIAN ? *(const xxh_u64*)ptr : XXH_swap64(*(const xxh_u64*)ptr); +} + + +/******* xxh64 *******/ + +static const xxh_u64 PRIME64_1 = 0x9E3779B185EBCA87ULL; /* 0b1001111000110111011110011011000110000101111010111100101010000111 */ +static const xxh_u64 PRIME64_2 = 0xC2B2AE3D27D4EB4FULL; /* 0b1100001010110010101011100011110100100111110101001110101101001111 */ +static const xxh_u64 PRIME64_3 = 0x165667B19E3779F9ULL; /* 0b0001011001010110011001111011000110011110001101110111100111111001 */ +static const xxh_u64 PRIME64_4 = 0x85EBCA77C2B2AE63ULL; /* 0b1000010111101011110010100111011111000010101100101010111001100011 */ +static const xxh_u64 PRIME64_5 = 0x27D4EB2F165667C5ULL; /* 0b0010011111010100111010110010111100010110010101100110011111000101 */ + +static xxh_u64 XXH64_round(xxh_u64 acc, xxh_u64 input) +{ + acc += input * PRIME64_2; + acc = XXH_rotl64(acc, 31); + acc *= PRIME64_1; + return acc; +} + +static xxh_u64 XXH64_mergeRound(xxh_u64 acc, xxh_u64 val) +{ + val = XXH64_round(0, val); + acc ^= val; + acc = acc * PRIME64_1 + PRIME64_4; + return acc; +} + +static xxh_u64 XXH64_avalanche(xxh_u64 h64) +{ + h64 ^= h64 >> 33; + h64 *= PRIME64_2; + h64 ^= h64 >> 29; + h64 *= PRIME64_3; + h64 ^= h64 >> 32; + return h64; +} + + +#define XXH_get64bits(p) XXH_readLE64_align(p, align) + +static xxh_u64 +XXH64_finalize(xxh_u64 h64, const xxh_u8* ptr, size_t len, XXH_alignment align) +{ +#define PROCESS1_64 do { \ + h64 ^= (*ptr++) * PRIME64_5; \ + h64 = XXH_rotl64(h64, 11) * PRIME64_1; \ +} while (0) + +#define PROCESS4_64 do { \ + h64 ^= (xxh_u64)(XXH_get32bits(ptr)) * PRIME64_1; \ + ptr += 4; \ + h64 = XXH_rotl64(h64, 23) * PRIME64_2 + PRIME64_3; \ +} while (0) + +#define PROCESS8_64 do { \ + xxh_u64 const k1 = XXH64_round(0, XXH_get64bits(ptr)); \ + ptr += 8; \ + h64 ^= k1; \ + h64 = XXH_rotl64(h64,27) * PRIME64_1 + PRIME64_4; \ +} while (0) + + /* Rerolled version for 32-bit targets is faster and much smaller. */ + if (XXH_REROLL || XXH_REROLL_XXH64) { + len &= 31; + while (len >= 8) { + PROCESS8_64; + len -= 8; + } + if (len >= 4) { + PROCESS4_64; + len -= 4; + } + while (len > 0) { + PROCESS1_64; + --len; + } + return XXH64_avalanche(h64); + } else { + switch(len & 31) { + case 24: PROCESS8_64; + /* fallthrough */ + case 16: PROCESS8_64; + /* fallthrough */ + case 8: PROCESS8_64; + return XXH64_avalanche(h64); + + case 28: PROCESS8_64; + /* fallthrough */ + case 20: PROCESS8_64; + /* fallthrough */ + case 12: PROCESS8_64; + /* fallthrough */ + case 4: PROCESS4_64; + return XXH64_avalanche(h64); + + case 25: PROCESS8_64; + /* fallthrough */ + case 17: PROCESS8_64; + /* fallthrough */ + case 9: PROCESS8_64; + PROCESS1_64; + return XXH64_avalanche(h64); + + case 29: PROCESS8_64; + /* fallthrough */ + case 21: PROCESS8_64; + /* fallthrough */ + case 13: PROCESS8_64; + /* fallthrough */ + case 5: PROCESS4_64; + PROCESS1_64; + return XXH64_avalanche(h64); + + case 26: PROCESS8_64; + /* fallthrough */ + case 18: PROCESS8_64; + /* fallthrough */ + case 10: PROCESS8_64; + PROCESS1_64; + PROCESS1_64; + return XXH64_avalanche(h64); + + case 30: PROCESS8_64; + /* fallthrough */ + case 22: PROCESS8_64; + /* fallthrough */ + case 14: PROCESS8_64; + /* fallthrough */ + case 6: PROCESS4_64; + PROCESS1_64; + PROCESS1_64; + return XXH64_avalanche(h64); + + case 27: PROCESS8_64; + /* fallthrough */ + case 19: PROCESS8_64; + /* fallthrough */ + case 11: PROCESS8_64; + PROCESS1_64; + PROCESS1_64; + PROCESS1_64; + return XXH64_avalanche(h64); + + case 31: PROCESS8_64; + /* fallthrough */ + case 23: PROCESS8_64; + /* fallthrough */ + case 15: PROCESS8_64; + /* fallthrough */ + case 7: PROCESS4_64; + /* fallthrough */ + case 3: PROCESS1_64; + /* fallthrough */ + case 2: PROCESS1_64; + /* fallthrough */ + case 1: PROCESS1_64; + /* fallthrough */ + case 0: return XXH64_avalanche(h64); + } + } + /* impossible to reach */ + XXH_ASSERT(0); + return 0; /* unreachable, but some compilers complain without it */ +} + +XXH_FORCE_INLINE xxh_u64 +XXH64_endian_align(const xxh_u8* input, size_t len, xxh_u64 seed, XXH_alignment align) +{ + const xxh_u8* bEnd = input + len; + xxh_u64 h64; + +#if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1) + if (input==NULL) { + len=0; + bEnd=input=(const xxh_u8*)(size_t)32; + } +#endif + + if (len>=32) { + const xxh_u8* const limit = bEnd - 32; + xxh_u64 v1 = seed + PRIME64_1 + PRIME64_2; + xxh_u64 v2 = seed + PRIME64_2; + xxh_u64 v3 = seed + 0; + xxh_u64 v4 = seed - PRIME64_1; + + do { + v1 = XXH64_round(v1, XXH_get64bits(input)); input+=8; + v2 = XXH64_round(v2, XXH_get64bits(input)); input+=8; + v3 = XXH64_round(v3, XXH_get64bits(input)); input+=8; + v4 = XXH64_round(v4, XXH_get64bits(input)); input+=8; + } while (input<=limit); + + h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18); + h64 = XXH64_mergeRound(h64, v1); + h64 = XXH64_mergeRound(h64, v2); + h64 = XXH64_mergeRound(h64, v3); + h64 = XXH64_mergeRound(h64, v4); + + } else { + h64 = seed + PRIME64_5; + } + + h64 += (xxh_u64) len; + + return XXH64_finalize(h64, input, len, align); +} + + +XXH_PUBLIC_API XXH64_hash_t XXH64 (const void* input, size_t len, XXH64_hash_t seed) +{ +#if 0 + /* Simple version, good for code maintenance, but unfortunately slow for small inputs */ + XXH64_state_t state; + XXH64_reset(&state, seed); + XXH64_update(&state, (const xxh_u8*)input, len); + return XXH64_digest(&state); + +#else + + if (XXH_FORCE_ALIGN_CHECK) { + if ((((size_t)input) & 7)==0) { /* Input is aligned, let's leverage the speed advantage */ + return XXH64_endian_align((const xxh_u8*)input, len, seed, XXH_aligned); + } } + + return XXH64_endian_align((const xxh_u8*)input, len, seed, XXH_unaligned); + +#endif +} + +/******* Hash Streaming *******/ + +XXH_PUBLIC_API XXH64_state_t* XXH64_createState(void) +{ + return (XXH64_state_t*)XXH_malloc(sizeof(XXH64_state_t)); +} +XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr) +{ + XXH_free(statePtr); + return XXH_OK; +} + +XXH_PUBLIC_API void XXH64_copyState(XXH64_state_t* dstState, const XXH64_state_t* srcState) +{ + memcpy(dstState, srcState, sizeof(*dstState)); +} + +XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH64_state_t* statePtr, XXH64_hash_t seed) +{ + XXH64_state_t state; /* use a local state to memcpy() in order to avoid strict-aliasing warnings */ + memset(&state, 0, sizeof(state)); + state.v1 = seed + PRIME64_1 + PRIME64_2; + state.v2 = seed + PRIME64_2; + state.v3 = seed + 0; + state.v4 = seed - PRIME64_1; + /* do not write into reserved64, might be removed in a future version */ + memcpy(statePtr, &state, sizeof(state) - sizeof(state.reserved64)); + return XXH_OK; +} + +XXH_PUBLIC_API XXH_errorcode +XXH64_update (XXH64_state_t* state, const void* input, size_t len) +{ + if (input==NULL) +#if defined(XXH_ACCEPT_NULL_INPUT_POINTER) && (XXH_ACCEPT_NULL_INPUT_POINTER>=1) + return XXH_OK; +#else + return XXH_ERROR; +#endif + + { const xxh_u8* p = (const xxh_u8*)input; + const xxh_u8* const bEnd = p + len; + + state->total_len += len; + + if (state->memsize + len < 32) { /* fill in tmp buffer */ + XXH_memcpy(((xxh_u8*)state->mem64) + state->memsize, input, len); + state->memsize += (xxh_u32)len; + return XXH_OK; + } + + if (state->memsize) { /* tmp buffer is full */ + XXH_memcpy(((xxh_u8*)state->mem64) + state->memsize, input, 32-state->memsize); + state->v1 = XXH64_round(state->v1, XXH_readLE64(state->mem64+0)); + state->v2 = XXH64_round(state->v2, XXH_readLE64(state->mem64+1)); + state->v3 = XXH64_round(state->v3, XXH_readLE64(state->mem64+2)); + state->v4 = XXH64_round(state->v4, XXH_readLE64(state->mem64+3)); + p += 32-state->memsize; + state->memsize = 0; + } + + if (p+32 <= bEnd) { + const xxh_u8* const limit = bEnd - 32; + xxh_u64 v1 = state->v1; + xxh_u64 v2 = state->v2; + xxh_u64 v3 = state->v3; + xxh_u64 v4 = state->v4; + + do { + v1 = XXH64_round(v1, XXH_readLE64(p)); p+=8; + v2 = XXH64_round(v2, XXH_readLE64(p)); p+=8; + v3 = XXH64_round(v3, XXH_readLE64(p)); p+=8; + v4 = XXH64_round(v4, XXH_readLE64(p)); p+=8; + } while (p<=limit); + + state->v1 = v1; + state->v2 = v2; + state->v3 = v3; + state->v4 = v4; + } + + if (p < bEnd) { + XXH_memcpy(state->mem64, p, (size_t)(bEnd-p)); + state->memsize = (unsigned)(bEnd-p); + } + } + + return XXH_OK; +} + + +XXH_PUBLIC_API XXH64_hash_t XXH64_digest (const XXH64_state_t* state) +{ + xxh_u64 h64; + + if (state->total_len >= 32) { + xxh_u64 const v1 = state->v1; + xxh_u64 const v2 = state->v2; + xxh_u64 const v3 = state->v3; + xxh_u64 const v4 = state->v4; + + h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18); + h64 = XXH64_mergeRound(h64, v1); + h64 = XXH64_mergeRound(h64, v2); + h64 = XXH64_mergeRound(h64, v3); + h64 = XXH64_mergeRound(h64, v4); + } else { + h64 = state->v3 /*seed*/ + PRIME64_5; + } + + h64 += (xxh_u64) state->total_len; + + return XXH64_finalize(h64, (const xxh_u8*)state->mem64, (size_t)state->total_len, XXH_aligned); +} + + +/******* Canonical representation *******/ + +XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t hash) +{ + XXH_STATIC_ASSERT(sizeof(XXH64_canonical_t) == sizeof(XXH64_hash_t)); + if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap64(hash); + memcpy(dst, &hash, sizeof(*dst)); +} + +XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src) +{ + return XXH_readBE64(src); +} + + + +/* ********************************************************************* +* XXH3 +* New generation hash designed for speed on small keys and vectorization +************************************************************************ */ + +#include "xxh3.h" + + +#endif /* XXH_NO_LONG_LONG */ + + +#endif /* XXH_IMPLEMENTATION */ + + +#if defined (__cplusplus) +} +#endif -- cgit v1.2.3 From 1c98cefcee727a2ff621bfe9924cf6cd91770379 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sat, 25 Apr 2020 14:42:37 +0200 Subject: compile UMULLs and some fixes --- src/ARMJIT_x64/ARMJIT_ALU.cpp | 33 +++++++++++++++++++++++++-------- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 4 ++-- src/ARMJIT_x64/ARMJIT_Compiler.h | 2 +- src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 3 ++- 4 files changed, 30 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/ARMJIT_x64/ARMJIT_ALU.cpp b/src/ARMJIT_x64/ARMJIT_ALU.cpp index 14c223b..43b94b6 100644 --- a/src/ARMJIT_x64/ARMJIT_ALU.cpp +++ b/src/ARMJIT_x64/ARMJIT_ALU.cpp @@ -301,10 +301,11 @@ void Compiler::A_Comp_MUL_MLA() Comp_MulOp(S, add, rd, rm, rs, rn); } -void Compiler::A_Comp_SMULL_SMLAL() +void Compiler::A_Comp_Mul_Long() { bool S = CurInstr.Instr & (1 << 20); bool add = CurInstr.Instr & (1 << 21); + bool sign = CurInstr.Instr & (1 << 22); OpArg rd = MapReg(CurInstr.A_Reg(16)); OpArg rm = MapReg(CurInstr.A_Reg(0)); OpArg rs = MapReg(CurInstr.A_Reg(8)); @@ -318,18 +319,34 @@ void Compiler::A_Comp_SMULL_SMLAL() MOV(32, R(RSCRATCH3), rs); TEST(32, R(RSCRATCH3), R(RSCRATCH3)); FixupBranch zeroBSR = J_CC(CC_Z); - BSR(32, RSCRATCH2, R(RSCRATCH3)); - NOT(32, R(RSCRATCH3)); - BSR(32, RSCRATCH, R(RSCRATCH3)); - CMP(32, R(RSCRATCH2), R(RSCRATCH)); - CMOVcc(32, RSCRATCH, R(RSCRATCH2), CC_L); + if (sign) + { + BSR(32, RSCRATCH2, R(RSCRATCH3)); + NOT(32, R(RSCRATCH3)); + BSR(32, RSCRATCH, R(RSCRATCH3)); + CMP(32, R(RSCRATCH2), R(RSCRATCH)); + CMOVcc(32, RSCRATCH, R(RSCRATCH2), CC_L); + } + else + { + BSR(32, RSCRATCH, R(RSCRATCH3)); + } + SHR(32, R(RSCRATCH), Imm8(3)); SetJumpTarget(zeroBSR); // fortunately that's even right Comp_AddCycles_CI(RSCRATCH, 2); } - MOVSX(64, 32, RSCRATCH2, rm); - MOVSX(64, 32, RSCRATCH3, rs); + if (sign) + { + MOVSX(64, 32, RSCRATCH2, rm); + MOVSX(64, 32, RSCRATCH3, rs); + } + else + { + MOV(32, R(RSCRATCH2), rm); + MOV(32, R(RSCRATCH3), rs); + } if (add) { MOV(32, R(RSCRATCH), rd); diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index be3709e..1b2d312 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -300,7 +300,7 @@ const Compiler::CompileFunc A_Comp[ARMInstrInfo::ak_Count] = // CMN F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), F(A_Comp_CmpOp), // Mul - F(A_Comp_MUL_MLA), F(A_Comp_MUL_MLA), NULL, NULL, NULL, F(A_Comp_SMULL_SMLAL), NULL, NULL, NULL, NULL, NULL, + F(A_Comp_MUL_MLA), F(A_Comp_MUL_MLA), F(A_Comp_Mul_Long), F(A_Comp_Mul_Long), F(A_Comp_Mul_Long), F(A_Comp_Mul_Long), NULL, NULL, NULL, NULL, NULL, // ARMv5 stuff F(A_Comp_CLZ), NULL, NULL, NULL, NULL, // STR @@ -628,7 +628,7 @@ void Compiler::Comp_AddCycles_CI(Gen::X64Reg i, int add) } else { - ConstantCycles += i + cycles; + ConstantCycles += cycles; SUB(32, MDisp(RCPU, offsetof(ARM, Cycles)), R(i)); } } diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index b428c33..a448b6d 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -89,7 +89,7 @@ public: void A_Comp_CmpOp(); void A_Comp_MUL_MLA(); - void A_Comp_SMULL_SMLAL(); + void A_Comp_Mul_Long(); void A_Comp_CLZ(); diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index 4cafc1c..7f6fa53 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -423,7 +423,8 @@ void Compiler::Comp_MemAccess(int rd, int rn, const ComplexOperand& op2, int siz if (flags & memop_SubtractOffset) { - MOV(32, R(finalAddr), rnMapped); + if (R(finalAddr) != rnMapped) + MOV(32, R(finalAddr), rnMapped); if (!offset.IsZero()) SUB(32, R(finalAddr), offset); } -- cgit v1.2.3 From c2dd6a186da3e7e705b970c1fcc6768d00dba08e Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sat, 25 Apr 2020 19:35:40 +0200 Subject: implement msr and mrs for the x64 JIT --- src/ARMJIT.cpp | 2 +- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 127 ++++++++++++++++++++++++++++++++++++- src/ARMJIT_x64/ARMJIT_Compiler.h | 3 + src/ARM_InstrInfo.cpp | 4 ++ 4 files changed, 134 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index cc8d4ce..46f71f1 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -824,7 +824,7 @@ void InvalidateITCM(u32 addr) void InvalidateAll() { - JIT_DEBUGPRINT("invalidating all %x\n", JitBlocks.Length); + JIT_DEBUGPRINT("invalidating all %x\n", JitBlocks.size()); for (auto it : JitBlocks) { JitBlock* block = it.second; diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index 1b2d312..52a16dc 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -38,6 +38,131 @@ const int RegisterCache::NativeRegsAvailable = #endif ; +void Compiler::A_Comp_MRS() +{ + Comp_AddCycles_C(); + + OpArg rd = MapReg(CurInstr.A_Reg(12)); + + if (CurInstr.Instr & (1 << 22)) + { + MOV(32, R(RSCRATCH), R(RCPSR)); + AND(32, R(RSCRATCH), Imm8(0x1F)); + XOR(32, R(ABI_PARAM3), R(ABI_PARAM3)); + MOV(32, R(ABI_PARAM2), Imm32(15 - 8)); + CALL(ReadBanked); + MOV(32, rd, R(ABI_PARAM3)); + } + else + MOV(32, rd, R(RCPSR)); +} + +void Compiler::A_Comp_MSR() +{ + Comp_AddCycles_C(); + + OpArg val = CurInstr.Instr & (1 << 25) + ? Imm32(ROR((CurInstr.Instr & 0xFF), ((CurInstr.Instr >> 7) & 0x1E))) + : MapReg(CurInstr.A_Reg(0)); + + u32 mask = 0; + if (CurInstr.Instr & (1<<16)) mask |= 0x000000FF; + if (CurInstr.Instr & (1<<17)) mask |= 0x0000FF00; + if (CurInstr.Instr & (1<<18)) mask |= 0x00FF0000; + if (CurInstr.Instr & (1<<19)) mask |= 0xFF000000; + + if (CurInstr.Instr & (1 << 22)) + { + MOV(32, R(RSCRATCH), R(RCPSR)); + AND(32, R(RSCRATCH), Imm8(0x1F)); + XOR(32, R(ABI_PARAM3), R(ABI_PARAM3)); + MOV(32, R(ABI_PARAM2), Imm32(15 - 8)); + CALL(ReadBanked); + + MOV(32, R(RSCRATCH2), Imm32(0xFFFFFF00)); + MOV(32, R(RSCRATCH3), Imm32(0xFFFFFFFF)); + MOV(32, R(RSCRATCH), R(RCPSR)); + AND(32, R(RSCRATCH), Imm8(0x1F)); + CMP(32, R(RSCRATCH), Imm8(0x10)); + CMOVcc(32, RSCRATCH2, R(RSCRATCH3), CC_NE); + AND(32, R(RSCRATCH2), Imm32(mask)); + + MOV(32, R(RSCRATCH), R(RSCRATCH2)); + NOT(32, R(RSCRATCH)); + AND(32, R(ABI_PARAM3), R(RSCRATCH)); + + AND(32, R(RSCRATCH2), val); + OR(32, R(ABI_PARAM3), R(RSCRATCH2)); + + MOV(32, R(RSCRATCH), R(RCPSR)); + AND(32, R(RSCRATCH), Imm8(0x1F)); + MOV(32, R(ABI_PARAM2), Imm32(15 - 8)); + CALL(WriteBanked); + } + else + { + mask &= 0xFFFFFFDF; + CPSRDirty = true; + + if ((mask & 0xFF) == 0) + { + AND(32, R(RCPSR), Imm32(~mask)); + if (val.IsImm()) + { + MOV(32, R(RSCRATCH), val); + AND(32, R(RSCRATCH), Imm32(mask)); + OR(32, R(RCPSR), R(RSCRATCH)); + } + else + { + OR(32, R(RCPSR), Imm32(val.Imm32() & mask)); + } + } + else + { + MOV(32, R(RSCRATCH2), Imm32(mask)); + MOV(32, R(RSCRATCH3), R(RSCRATCH2)); + AND(32, R(RSCRATCH3), Imm32(0xFFFFFF00)); + MOV(32, R(RSCRATCH), R(RCPSR)); + AND(32, R(RSCRATCH), Imm8(0x1F)); + CMP(32, R(RSCRATCH), Imm8(0x10)); + CMOVcc(32, RSCRATCH2, R(RSCRATCH3), CC_E); + + MOV(32, R(RSCRATCH3), R(RCPSR)); + + // I need you ANDN + MOV(32, R(RSCRATCH), R(RSCRATCH2)); + NOT(32, R(RSCRATCH)); + AND(32, R(RCPSR), R(RSCRATCH)); + + AND(32, R(RSCRATCH2), val); + OR(32, R(RCPSR), R(RSCRATCH2)); + + BitSet16 hiRegsLoaded(RegCache.LoadedRegs & 0x7F00); + if (Thumb || CurInstr.Cond() >= 0xE) + RegCache.Flush(); + else + { + // the ugly way... + // we only save them, to load and save them again + for (int reg : hiRegsLoaded) + SaveReg(reg, RegCache.Mapping[reg]); + } + + MOV(32, R(ABI_PARAM3), R(RCPSR)); + MOV(32, R(ABI_PARAM2), R(RSCRATCH3)); + MOV(64, R(ABI_PARAM1), R(RCPU)); + CALL((void*)&ARM::UpdateMode); + + if (!Thumb && CurInstr.Cond() < 0xE) + { + for (int reg : hiRegsLoaded) + LoadReg(reg, RegCache.Mapping[reg]); + } + } + } +} + /* We'll repurpose this .bss memory @@ -328,7 +453,7 @@ const Compiler::CompileFunc A_Comp[ARMInstrInfo::ak_Count] = // Branch F(A_Comp_BranchImm), F(A_Comp_BranchImm), F(A_Comp_BranchImm), F(A_Comp_BranchXchangeReg), F(A_Comp_BranchXchangeReg), // system stuff - NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, F(A_Comp_MSR), F(A_Comp_MSR), F(A_Comp_MRS), NULL, NULL, NULL, F(Nop) }; diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index a448b6d..2230eb8 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -100,6 +100,9 @@ public: void A_Comp_BranchImm(); void A_Comp_BranchXchangeReg(); + void A_Comp_MRS(); + void A_Comp_MSR(); + void T_Comp_ShiftImm(); void T_Comp_AddSub_(); void T_Comp_ALU_Imm8(); diff --git a/src/ARM_InstrInfo.cpp b/src/ARM_InstrInfo.cpp index b884773..28362d9 100644 --- a/src/ARM_InstrInfo.cpp +++ b/src/ARM_InstrInfo.cpp @@ -427,6 +427,10 @@ Info Decode(bool thumb, u32 num, u32 instr) res.Kind = ak_UNK; } } + if (res.Kind == ak_MRS && !(instr & (1 << 22))) + res.ReadFlags |= flag_N | flag_Z | flag_C | flag_V; + if ((res.Kind == ak_MSR_IMM || res.Kind == ak_MSR_REG) && instr & (1 << 19)) + res.WriteFlags |= flag_N | flag_Z | flag_C | flag_V; if (data & A_Read0) res.SrcRegs |= 1 << (instr & 0xF); -- cgit v1.2.3 From dc86bac83d865ebc1b9a520791b831f6799fe87c Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sun, 26 Apr 2020 16:17:16 +0200 Subject: hopefully fix stack handling for linux --- src/ARMJIT_x64/ARMJIT_Linkage.s | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/ARMJIT_x64/ARMJIT_Linkage.s b/src/ARMJIT_x64/ARMJIT_Linkage.s index dbbb024..0a84df0 100644 --- a/src/ARMJIT_x64/ARMJIT_Linkage.s +++ b/src/ARMJIT_x64/ARMJIT_Linkage.s @@ -44,6 +44,8 @@ ARM_Dispatch: #ifdef WIN64 sub rsp, 0x28 +#else + sub rsp, 0x8 #endif mov RCPU, ARG1_REG64 mov RCPSR, [RCPU + ARM_CPSR_offset] @@ -58,6 +60,8 @@ ARM_Ret: #ifdef WIN64 add rsp, 0x28 +#else + add rsp, 0x8 #endif pop rbp -- cgit v1.2.3 From 6d217e1010f3aed73a86d5dff2f3f46a3ca60cb5 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sun, 26 Apr 2020 16:27:26 +0200 Subject: fix build with JIT disabled and set default JIT maxblock size to 32 --- src/ARM.cpp | 2 ++ src/CMakeLists.txt | 2 +- src/CP15.cpp | 4 ++++ src/Config.cpp | 4 ++-- 4 files changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ARM.cpp b/src/ARM.cpp index 3eac74d..6b8df30 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -173,6 +173,7 @@ void ARM::DoSavestate(Savestate* file) file->VarArray(R_IRQ, 3*sizeof(u32)); file->VarArray(R_UND, 3*sizeof(u32)); file->Var32(&CurInstr); +#ifdef JIT_ENABLED if (!file->Saving && Config::JIT_Enable) { // hack, the JIT doesn't really pipeline @@ -180,6 +181,7 @@ void ARM::DoSavestate(Savestate* file) // loaded while running the interpreter FillPipeline(); } +#endif file->VarArray(NextInstr, 2*sizeof(u32)); file->Var32(&ExceptionBase); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a0c3a36..0029e96 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,7 +11,6 @@ add_library(core STATIC ARMInterpreter_ALU.cpp ARMInterpreter_Branch.cpp ARMInterpreter_LoadStore.cpp - ARM_InstrInfo.cpp Config.cpp CP15.cpp CRC32.cpp @@ -57,6 +56,7 @@ if (ENABLE_JIT) target_sources(core PRIVATE ARMJIT.cpp + ARM_InstrInfo.cpp dolphin/CommonFuncs.cpp ) diff --git a/src/CP15.cpp b/src/CP15.cpp index e168d7f..ff8531c 100644 --- a/src/CP15.cpp +++ b/src/CP15.cpp @@ -562,11 +562,15 @@ void ARMv5::CP15Write(u32 id, u32 val) case 0x750: +#ifdef JIT_ENABLED ARMJIT::InvalidateAll(); +#endif ICacheInvalidateAll(); return; case 0x751: +#ifdef JIT_ENABLED ARMJIT::InvalidateByAddr(ARMJIT::TranslateAddr<0>(val)); +#endif ICacheInvalidateByAddr(val); return; case 0x752: diff --git a/src/Config.cpp b/src/Config.cpp index e69319b..c0ec4ec 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -39,7 +39,7 @@ char DSiNANDPath[1024]; #ifdef JIT_ENABLED int JIT_Enable = false; -int JIT_MaxBlockSize = 12; +int JIT_MaxBlockSize = 32; int JIT_BrancheOptimisations = 2; int JIT_LiteralOptimisations = true; #endif @@ -57,7 +57,7 @@ ConfigEntry ConfigFile[] = #ifdef JIT_ENABLED {"JIT_Enable", 0, &JIT_Enable, 0, NULL, 0}, - {"JIT_MaxBlockSize", 0, &JIT_MaxBlockSize, 10, NULL, 0}, + {"JIT_MaxBlockSize", 0, &JIT_MaxBlockSize, 32, NULL, 0}, {"JIT_BranchOptimisations", 0, &JIT_BrancheOptimisations, 2, NULL, 0}, {"JIT_LiteralOptimisations", 0, &JIT_LiteralOptimisations, 1, NULL, 0}, #endif -- cgit v1.2.3 From 5a3607bc688b42cc1da886bd2afc58d7aa4733be Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sun, 26 Apr 2020 20:47:36 +0200 Subject: don't use param registers for ReadBanked/WriteBanked should fix linux build --- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 64 ++++++++++++++++++------------------- src/ARMJIT_x64/ARMJIT_Compiler.h | 1 + src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 16 +++++----- 3 files changed, 40 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index 52a16dc..8d20425 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -48,10 +48,10 @@ void Compiler::A_Comp_MRS() { MOV(32, R(RSCRATCH), R(RCPSR)); AND(32, R(RSCRATCH), Imm8(0x1F)); - XOR(32, R(ABI_PARAM3), R(ABI_PARAM3)); - MOV(32, R(ABI_PARAM2), Imm32(15 - 8)); + XOR(32, R(RSCRATCH3), R(RSCRATCH3)); + MOV(32, R(RSCRATCH2), Imm32(15 - 8)); CALL(ReadBanked); - MOV(32, rd, R(ABI_PARAM3)); + MOV(32, rd, R(RSCRATCH3)); } else MOV(32, rd, R(RCPSR)); @@ -75,28 +75,26 @@ void Compiler::A_Comp_MSR() { MOV(32, R(RSCRATCH), R(RCPSR)); AND(32, R(RSCRATCH), Imm8(0x1F)); - XOR(32, R(ABI_PARAM3), R(ABI_PARAM3)); - MOV(32, R(ABI_PARAM2), Imm32(15 - 8)); + XOR(32, R(RSCRATCH3), R(RSCRATCH3)); + MOV(32, R(RSCRATCH2), Imm32(15 - 8)); CALL(ReadBanked); - MOV(32, R(RSCRATCH2), Imm32(0xFFFFFF00)); - MOV(32, R(RSCRATCH3), Imm32(0xFFFFFFFF)); + MOV(32, R(RSCRATCH2), Imm32(mask)); + MOV(32, R(RSCRATCH4), R(RSCRATCH2)); + AND(32, R(RSCRATCH4), Imm32(0xFFFFFF00)); MOV(32, R(RSCRATCH), R(RCPSR)); AND(32, R(RSCRATCH), Imm8(0x1F)); CMP(32, R(RSCRATCH), Imm8(0x10)); - CMOVcc(32, RSCRATCH2, R(RSCRATCH3), CC_NE); - AND(32, R(RSCRATCH2), Imm32(mask)); + CMOVcc(32, RSCRATCH2, R(RSCRATCH4), CC_E); - MOV(32, R(RSCRATCH), R(RSCRATCH2)); - NOT(32, R(RSCRATCH)); - AND(32, R(ABI_PARAM3), R(RSCRATCH)); + MOV(32, R(RSCRATCH4), R(RSCRATCH2)); + NOT(32, R(RSCRATCH4)); + AND(32, R(RSCRATCH3), R(RSCRATCH4)); AND(32, R(RSCRATCH2), val); - OR(32, R(ABI_PARAM3), R(RSCRATCH2)); + OR(32, R(RSCRATCH3), R(RSCRATCH2)); - MOV(32, R(RSCRATCH), R(RCPSR)); - AND(32, R(RSCRATCH), Imm8(0x1F)); - MOV(32, R(ABI_PARAM2), Imm32(15 - 8)); + MOV(32, R(RSCRATCH2), Imm32(15 - 8)); CALL(WriteBanked); } else @@ -219,13 +217,13 @@ Compiler::Compiler() { // RSCRATCH mode - // ABI_PARAM2 reg number - // ABI_PARAM3 value in current mode - // ret - ABI_PARAM3 + // RSCRATCH2 reg number + // RSCRATCH3 value in current mode + // ret - RSCRATCH3 ReadBanked = (void*)GetWritableCodePtr(); CMP(32, R(RSCRATCH), Imm8(0x11)); FixupBranch fiq = J_CC(CC_E); - SUB(32, R(ABI_PARAM2), Imm8(13 - 8)); + SUB(32, R(RSCRATCH2), Imm8(13 - 8)); FixupBranch notEverything = J_CC(CC_L); CMP(32, R(RSCRATCH), Imm8(0x12)); FixupBranch irq = J_CC(CC_E); @@ -239,30 +237,30 @@ Compiler::Compiler() RET(); SetJumpTarget(fiq); - MOV(32, R(ABI_PARAM3), MComplex(RCPU, ABI_PARAM2, SCALE_4, offsetof(ARM, R_FIQ))); + MOV(32, R(RSCRATCH3), MComplex(RCPU, RSCRATCH2, SCALE_4, offsetof(ARM, R_FIQ))); RET(); SetJumpTarget(irq); - MOV(32, R(ABI_PARAM3), MComplex(RCPU, ABI_PARAM2, SCALE_4, offsetof(ARM, R_IRQ))); + MOV(32, R(RSCRATCH3), MComplex(RCPU, RSCRATCH2, SCALE_4, offsetof(ARM, R_IRQ))); RET(); SetJumpTarget(svc); - MOV(32, R(ABI_PARAM3), MComplex(RCPU, ABI_PARAM2, SCALE_4, offsetof(ARM, R_SVC))); + MOV(32, R(RSCRATCH3), MComplex(RCPU, RSCRATCH2, SCALE_4, offsetof(ARM, R_SVC))); RET(); SetJumpTarget(abt); - MOV(32, R(ABI_PARAM3), MComplex(RCPU, ABI_PARAM2, SCALE_4, offsetof(ARM, R_ABT))); + MOV(32, R(RSCRATCH3), MComplex(RCPU, RSCRATCH2, SCALE_4, offsetof(ARM, R_ABT))); RET(); SetJumpTarget(und); - MOV(32, R(ABI_PARAM3), MComplex(RCPU, ABI_PARAM2, SCALE_4, offsetof(ARM, R_UND))); + MOV(32, R(RSCRATCH3), MComplex(RCPU, RSCRATCH2, SCALE_4, offsetof(ARM, R_UND))); RET(); } { // RSCRATCH mode - // ABI_PARAM2 reg n - // ABI_PARAM3 value + // RSCRATCH2 reg n + // RSCRATCH3 value // carry flag set if the register isn't banked WriteBanked = (void*)GetWritableCodePtr(); CMP(32, R(RSCRATCH), Imm8(0x11)); FixupBranch fiq = J_CC(CC_E); - SUB(32, R(ABI_PARAM2), Imm8(13 - 8)); + SUB(32, R(RSCRATCH2), Imm8(13 - 8)); FixupBranch notEverything = J_CC(CC_L); CMP(32, R(RSCRATCH), Imm8(0x12)); FixupBranch irq = J_CC(CC_E); @@ -277,23 +275,23 @@ Compiler::Compiler() RET(); SetJumpTarget(fiq); - MOV(32, MComplex(RCPU, ABI_PARAM2, SCALE_4, offsetof(ARM, R_FIQ)), R(ABI_PARAM3)); + MOV(32, MComplex(RCPU, RSCRATCH2, SCALE_4, offsetof(ARM, R_FIQ)), R(RSCRATCH3)); CLC(); RET(); SetJumpTarget(irq); - MOV(32, MComplex(RCPU, ABI_PARAM2, SCALE_4, offsetof(ARM, R_IRQ)), R(ABI_PARAM3)); + MOV(32, MComplex(RCPU, RSCRATCH2, SCALE_4, offsetof(ARM, R_IRQ)), R(RSCRATCH3)); CLC(); RET(); SetJumpTarget(svc); - MOV(32, MComplex(RCPU, ABI_PARAM2, SCALE_4, offsetof(ARM, R_SVC)), R(ABI_PARAM3)); + MOV(32, MComplex(RCPU, RSCRATCH2, SCALE_4, offsetof(ARM, R_SVC)), R(RSCRATCH3)); CLC(); RET(); SetJumpTarget(abt); - MOV(32, MComplex(RCPU, ABI_PARAM2, SCALE_4, offsetof(ARM, R_ABT)), R(ABI_PARAM3)); + MOV(32, MComplex(RCPU, RSCRATCH2, SCALE_4, offsetof(ARM, R_ABT)), R(RSCRATCH3)); CLC(); RET(); SetJumpTarget(und); - MOV(32, MComplex(RCPU, ABI_PARAM2, SCALE_4, offsetof(ARM, R_UND)), R(ABI_PARAM3)); + MOV(32, MComplex(RCPU, RSCRATCH2, SCALE_4, offsetof(ARM, R_UND)), R(RSCRATCH3)); CLC(); RET(); } diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index 2230eb8..e0a4978 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -16,6 +16,7 @@ const Gen::X64Reg RCPSR = Gen::R15; const Gen::X64Reg RSCRATCH = Gen::EAX; const Gen::X64Reg RSCRATCH2 = Gen::EDX; const Gen::X64Reg RSCRATCH3 = Gen::ECX; +const Gen::X64Reg RSCRATCH4 = Gen::R8; struct ComplexOperand { diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index 7f6fa53..85a3737 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -540,14 +540,14 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc AND(32, R(RSCRATCH), Imm8(0x1F)); firstUserMode = false; } - MOV(32, R(ABI_PARAM2), Imm32(reg - 8)); - POP(ABI_PARAM3); + MOV(32, R(RSCRATCH2), Imm32(reg - 8)); + POP(RSCRATCH3); CALL(WriteBanked); FixupBranch sucessfulWritten = J_CC(CC_NC); if (RegCache.Mapping[reg] != INVALID_REG) - MOV(32, R(RegCache.Mapping[reg]), R(ABI_PARAM3)); + MOV(32, R(RegCache.Mapping[reg]), R(RSCRATCH3)); else - SaveReg(reg, ABI_PARAM3); + SaveReg(reg, RSCRATCH3); SetJumpTarget(sucessfulWritten); } else if (RegCache.Mapping[reg] == INVALID_REG) @@ -600,12 +600,12 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc firstUserMode = false; } if (RegCache.Mapping[reg] == INVALID_REG) - LoadReg(reg, ABI_PARAM3); + LoadReg(reg, RSCRATCH3); else - MOV(32, R(ABI_PARAM3), R(RegCache.Mapping[reg])); - MOV(32, R(ABI_PARAM2), Imm32(reg - 8)); + MOV(32, R(RSCRATCH3), R(RegCache.Mapping[reg])); + MOV(32, R(RSCRATCH2), Imm32(reg - 8)); CALL(ReadBanked); - PUSH(ABI_PARAM3); + PUSH(RSCRATCH3); } else if (RegCache.Mapping[reg] == INVALID_REG) { -- cgit v1.2.3 From b902cd1b8e0b5509f108e2b60ded3ec38b1c53fc Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sun, 26 Apr 2020 23:25:32 +0200 Subject: fix regression from last commit also a small mistake with msr --- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 2 +- src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index 8d20425..dd20e3c 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -105,7 +105,7 @@ void Compiler::A_Comp_MSR() if ((mask & 0xFF) == 0) { AND(32, R(RCPSR), Imm32(~mask)); - if (val.IsImm()) + if (!val.IsImm()) { MOV(32, R(RSCRATCH), val); AND(32, R(RSCRATCH), Imm32(mask)); diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index 85a3737..b595e32 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -502,14 +502,6 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc int regsCount = regs.Count(); - if (decrement) - { - MOV_sum(32, ABI_PARAM1, MapReg(rn), Imm32(-regsCount * 4)); - preinc ^= true; - } - else - MOV(32, R(ABI_PARAM1), MapReg(rn)); - s32 offset = (regsCount * 4) * (decrement ? -1 : 1); // we need to make sure that the stack stays aligned to 16 bytes @@ -519,6 +511,14 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc { Comp_AddCycles_CDI(); + if (decrement) + { + MOV_sum(32, ABI_PARAM1, MapReg(rn), Imm32(-regsCount * 4)); + preinc ^= true; + } + else + MOV(32, R(ABI_PARAM1), MapReg(rn)); + MOV(32, R(ABI_PARAM3), Imm32(regsCount)); SUB(64, R(RSP), stackAlloc <= INT8_MAX ? Imm8(stackAlloc) : Imm32(stackAlloc)); MOV(64, R(ABI_PARAM2), R(RSP)); @@ -618,6 +618,14 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc } } + if (decrement) + { + MOV_sum(32, ABI_PARAM1, MapReg(rn), Imm32(-regsCount * 4)); + preinc ^= true; + } + else + MOV(32, R(ABI_PARAM1), MapReg(rn)); + MOV(64, R(ABI_PARAM2), R(RSP)); MOV(32, R(ABI_PARAM3), Imm32(regsCount)); -- cgit v1.2.3 From 052ff7367211728209d6eb5f8f0f6d02cfab321e Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sat, 9 May 2020 00:45:05 +0200 Subject: rewrite JIT memory emulation --- src/ARM.cpp | 10 +- src/ARM.h | 24 +- src/ARMJIT.cpp | 905 +++++++++++++++++++++++++--------- src/ARMJIT.h | 65 ++- src/ARMJIT_A64/ARMJIT_Compiler.cpp | 4 +- src/ARMJIT_Internal.h | 68 ++- src/ARMJIT_RegisterCache.h | 18 +- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 43 +- src/ARMJIT_x64/ARMJIT_Compiler.h | 34 +- src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 935 +++++++++++++++++++----------------- src/ARM_InstrInfo.cpp | 16 +- src/CP15.cpp | 44 +- src/NDS.cpp | 105 +++- src/NDS.h | 9 +- 14 files changed, 1465 insertions(+), 815 deletions(-) (limited to 'src') diff --git a/src/ARM.cpp b/src/ARM.cpp index 6b8df30..92a3a9e 100644 --- a/src/ARM.cpp +++ b/src/ARM.cpp @@ -622,7 +622,8 @@ void ARMv5::ExecuteJIT() while (NDS::ARM9Timestamp < NDS::ARM9Target) { u32 instrAddr = R[15] - ((CPSR&0x20)?2:4); - if (!ARMJIT::IsMapped<0>(instrAddr)) + u32 translatedAddr = ARMJIT::TranslateAddr9(instrAddr); + if (!translatedAddr) { NDS::ARM9Timestamp = NDS::ARM9Target; printf("ARMv5 PC in non executable region %08X\n", R[15]); @@ -632,7 +633,7 @@ void ARMv5::ExecuteJIT() // hack so Cycles <= 0 becomes Cycles < 0 Cycles = NDS::ARM9Target - NDS::ARM9Timestamp - 1; - ARMJIT::JitBlockEntry block = ARMJIT::LookUpBlockEntry(ARMJIT::TranslateAddr<0>(instrAddr)); + ARMJIT::JitBlockEntry block = ARMJIT::LookUpBlockEntry<0>(translatedAddr); if (block) ARM_Dispatch(this, block); else @@ -765,7 +766,8 @@ void ARMv4::ExecuteJIT() while (NDS::ARM7Timestamp < NDS::ARM7Target) { u32 instrAddr = R[15] - ((CPSR&0x20)?2:4); - if (!ARMJIT::IsMapped<1>(instrAddr)) + u32 translatedAddr = ARMJIT::TranslateAddr7(instrAddr); + if (!translatedAddr) { NDS::ARM7Timestamp = NDS::ARM7Target; printf("ARMv4 PC in non executable region %08X\n", R[15]); @@ -774,7 +776,7 @@ void ARMv4::ExecuteJIT() Cycles = NDS::ARM7Target - NDS::ARM7Timestamp - 1; - ARMJIT::JitBlockEntry block = ARMJIT::LookUpBlockEntry(ARMJIT::TranslateAddr<1>(instrAddr)); + ARMJIT::JitBlockEntry block = ARMJIT::LookUpBlockEntry<1>(translatedAddr); if (block) ARM_Dispatch(this, block); else diff --git a/src/ARM.h b/src/ARM.h index b71102a..b1e8053 100644 --- a/src/ARM.h +++ b/src/ARM.h @@ -320,7 +320,7 @@ public: void DataRead8(u32 addr, u32* val) { *val = BusRead8(addr); - DataRegion = addr >> 20; + DataRegion = addr; DataCycles = NDS::ARM7MemTimings[addr >> 15][0]; } @@ -329,7 +329,7 @@ public: addr &= ~1; *val = BusRead16(addr); - DataRegion = addr >> 20; + DataRegion = addr; DataCycles = NDS::ARM7MemTimings[addr >> 15][0]; } @@ -338,7 +338,7 @@ public: addr &= ~3; *val = BusRead32(addr); - DataRegion = addr >> 20; + DataRegion = addr; DataCycles = NDS::ARM7MemTimings[addr >> 15][2]; } @@ -353,7 +353,7 @@ public: void DataWrite8(u32 addr, u8 val) { BusWrite8(addr, val); - DataRegion = addr >> 20; + DataRegion = addr; DataCycles = NDS::ARM7MemTimings[addr >> 15][0]; } @@ -362,7 +362,7 @@ public: addr &= ~1; BusWrite16(addr, val); - DataRegion = addr >> 20; + DataRegion = addr; DataCycles = NDS::ARM7MemTimings[addr >> 15][0]; } @@ -371,7 +371,7 @@ public: addr &= ~3; BusWrite32(addr, val); - DataRegion = addr >> 20; + DataRegion = addr; DataCycles = NDS::ARM7MemTimings[addr >> 15][2]; } @@ -402,7 +402,7 @@ public: s32 numC = NDS::ARM7MemTimings[CodeCycles][(CPSR&0x20)?0:2]; s32 numD = DataCycles; - if ((DataRegion >> 4) == 0x02) // mainRAM + if ((DataRegion >> 24) == 0x02) // mainRAM { if (CodeRegion == 0x02) Cycles -= numC + numD; @@ -429,7 +429,7 @@ public: s32 numC = NDS::ARM7MemTimings[CodeCycles][(CPSR&0x20)?0:2]; s32 numD = DataCycles; - if ((DataRegion >> 4) == 0x02) + if ((DataRegion >> 24) == 0x02) { if (CodeRegion == 0x02) Cycles -= numC + numD; @@ -455,4 +455,12 @@ void T_UNK(ARM* cpu); } +namespace NDS +{ + +extern ARMv5* ARM9; +extern ARMv4* ARM7; + +} + #endif // ARM_H diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 46f71f1..9602aed 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -23,6 +23,7 @@ #include "ARMInterpreter_Branch.h" #include "ARMInterpreter.h" +#include "GPU.h" #include "GPU3D.h" #include "SPU.h" #include "Wifi.h" @@ -34,9 +35,10 @@ namespace ARMJIT #define JIT_DEBUGPRINT(msg, ...) //#define JIT_DEBUGPRINT(msg, ...) printf(msg, ## __VA_ARGS__) -Compiler* compiler; +Compiler* JITCompiler; -const u32 ExeMemRegionSizes[] = { +const u32 ExeMemRegionSizes[] = +{ 0x8000, // Unmapped Region (dummy) 0x8000, // ITCM 4*1024*1024, // Main RAM @@ -48,7 +50,8 @@ const u32 ExeMemRegionSizes[] = { 0x40000 // ARM7 WVRAM }; -const u32 ExeMemRegionOffsets[] = { +const u32 ExeMemRegionOffsets[] = +{ 0, 0x8000, 0x10000, @@ -61,65 +64,391 @@ const u32 ExeMemRegionOffsets[] = { 0x518000, }; -#define DUP2(x) x, x - -const static ExeMemKind JIT_MEM[2][32] = { - //arm9 - { - /* 0X*/ DUP2(exeMem_ITCM), - /* 1X*/ DUP2(exeMem_ITCM), // mirror - /* 2X*/ DUP2(exeMem_MainRAM), - /* 3X*/ DUP2(exeMem_SWRAM), - /* 4X*/ DUP2(exeMem_Unmapped), - /* 5X*/ DUP2(exeMem_Unmapped), - /* 6X*/ exeMem_Unmapped, - exeMem_LCDC, // Plain ARM9-CPU Access (LCDC mode) (max 656KB) - /* 7X*/ DUP2(exeMem_Unmapped), - /* 8X*/ DUP2(exeMem_Unmapped), - /* 9X*/ DUP2(exeMem_Unmapped), - /* AX*/ DUP2(exeMem_Unmapped), - /* BX*/ DUP2(exeMem_Unmapped), - /* CX*/ DUP2(exeMem_Unmapped), - /* DX*/ DUP2(exeMem_Unmapped), - /* EX*/ DUP2(exeMem_Unmapped), - /* FX*/ DUP2(exeMem_ARM9_BIOS) - }, - //arm7 - { - /* 0X*/ DUP2(exeMem_ARM7_BIOS), - /* 1X*/ DUP2(exeMem_Unmapped), - /* 2X*/ DUP2(exeMem_MainRAM), - /* 3X*/ exeMem_SWRAM, - exeMem_ARM7_WRAM, - /* 4X*/ DUP2(exeMem_Unmapped), - /* 5X*/ DUP2(exeMem_Unmapped), - /* 6X*/ DUP2(exeMem_ARM7_WVRAM), /* contrary to Gbatek, melonDS and itself, - DeSmuME doesn't mirror the 64 MB region at 0x6800000 */ - /* 7X*/ DUP2(exeMem_Unmapped), - /* 8X*/ DUP2(exeMem_Unmapped), - /* 9X*/ DUP2(exeMem_Unmapped), - /* AX*/ DUP2(exeMem_Unmapped), - /* BX*/ DUP2(exeMem_Unmapped), - /* CX*/ DUP2(exeMem_Unmapped), - /* DX*/ DUP2(exeMem_Unmapped), - /* EX*/ DUP2(exeMem_Unmapped), - /* FX*/ DUP2(exeMem_Unmapped) - } -}; - -#undef DUP2 - /* translates address to pseudo physical address - more compact, eliminates mirroring, everything comes in a row - we only need one translation table */ -u32 AddrTranslate9[0x2000]; -u32 AddrTranslate7[0x4000]; + +u32 TranslateAddr9(u32 addr) +{ + switch (ClassifyAddress9(addr)) + { + case memregion_MainRAM: return ExeMemRegionOffsets[exeMem_MainRAM] + (addr & (MAIN_RAM_SIZE - 1)); + case memregion_SWRAM9: + if (NDS::SWRAM_ARM9) + return ExeMemRegionOffsets[exeMem_SWRAM] + (NDS::SWRAM_ARM9 - NDS::SharedWRAM) + (addr & NDS::SWRAM_ARM9Mask); + else + return 0; + case memregion_ITCM: return ExeMemRegionOffsets[exeMem_ITCM] + (addr & 0x7FFF); + case memregion_VRAM: return (addr >= 0x6800000 && addr < 0x68A4000) ? ExeMemRegionOffsets[exeMem_LCDC] + (addr - 0x6800000) : 0; + case memregion_BIOS9: return ExeMemRegionOffsets[exeMem_ARM9_BIOS] + (addr & 0xFFF); + default: return 0; + } +} + +u32 TranslateAddr7(u32 addr) +{ + switch (ClassifyAddress7(addr)) + { + case memregion_MainRAM: return ExeMemRegionOffsets[exeMem_MainRAM] + (addr & (MAIN_RAM_SIZE - 1)); + case memregion_SWRAM7: + if (NDS::SWRAM_ARM7) + return ExeMemRegionOffsets[exeMem_SWRAM] + (NDS::SWRAM_ARM7 - NDS::SharedWRAM) + (addr & NDS::SWRAM_ARM7Mask); + else + return 0; + case memregion_BIOS7: return ExeMemRegionOffsets[exeMem_ARM7_BIOS] + addr; + case memregion_WRAM7: return ExeMemRegionOffsets[exeMem_ARM7_WRAM] + (addr & 0xFFFF); + case memregion_VWRAM: return ExeMemRegionOffsets[exeMem_ARM7_WVRAM] + (addr & 0x1FFFF); + default: return 0; + } +} AddressRange CodeRanges[ExeMemSpaceSize / 512]; -std::unordered_map JitBlocks; +TinyVector InvalidLiterals; + +std::unordered_map JitBlocks9; +std::unordered_map JitBlocks7; + +u8 MemoryStatus9[0x800000]; +u8 MemoryStatus7[0x800000]; + +int ClassifyAddress9(u32 addr) +{ + if (addr < NDS::ARM9->ITCMSize) + return memregion_ITCM; + else if (addr >= NDS::ARM9->DTCMBase && addr < (NDS::ARM9->DTCMBase + NDS::ARM9->DTCMSize)) + return memregion_DTCM; + else if ((addr & 0xFFFFF000) == 0xFFFF0000) + return memregion_BIOS9; + else + { + switch (addr & 0xFF000000) + { + case 0x02000000: + return memregion_MainRAM; + case 0x03000000: + return memregion_SWRAM9; + case 0x04000000: + return memregion_IO9; + case 0x06000000: + return memregion_VRAM; + } + } + return memregion_Other; +} + +int ClassifyAddress7(u32 addr) +{ + if (addr < 0x00004000) + return memregion_BIOS7; + else + { + switch (addr & 0xFF800000) + { + case 0x02000000: + case 0x02800000: + return memregion_MainRAM; + case 0x03000000: + if (NDS::SWRAM_ARM7) + return memregion_SWRAM7; + else + return memregion_WRAM7; + case 0x03800000: + return memregion_WRAM7; + case 0x04000000: + return memregion_IO7; + case 0x04800000: + return memregion_Wifi; + case 0x06000000: + case 0x06800000: + return memregion_VWRAM; + } + } + return memregion_Other; +} + +void UpdateMemoryStatus9(u32 start, u32 end) +{ + start >>= 12; + end >>= 12; + + if (end == 0xFFFFF) + end++; + + for (u32 i = start; i < end; i++) + { + u32 addr = i << 12; + + int region = ClassifyAddress9(addr); + u32 pseudoPhyisical = TranslateAddr9(addr); + + for (u32 j = 0; j < 8; j++) + { + u8 val = region; + if (CodeRanges[(pseudoPhyisical + (j << 12)) / 512].Blocks.Length) + val |= 0x80; + MemoryStatus9[i * 8 + j] = val; + } + } +} + +void UpdateMemoryStatus7(u32 start, u32 end) +{ + start >>= 12; + end >>= 12; + + if (end == 0xFFFFF) + end++; + + for (u32 i = start; i < end; i++) + { + u32 addr = i << 12; + + int region = ClassifyAddress7(addr); + u32 pseudoPhyisical = TranslateAddr7(addr); + + for (u32 j = 0; j < 8; j++) + { + u8 val = region; + if (CodeRanges[(pseudoPhyisical + (j << 12)) / 512].Blocks.Length) + val |= 0x80; + MemoryStatus7[i * 8 + j] = val; + } + } +} + +void UpdateRegionByPseudoPhyiscal(u32 addr, bool invalidate) +{ + for (u32 i = 1; i < exeMem_Count; i++) + { + if (addr >= ExeMemRegionOffsets[i] && addr < ExeMemRegionOffsets[i] + ExeMemRegionSizes[i]) + { + for (u32 num = 0; num < 2; num++) + { + u32 physSize = ExeMemRegionSizes[i]; + u32 mapSize = 0; + u32 mapStart = 0; + switch (i) + { + case exeMem_ITCM: + if (num == 0) + mapStart = 0; mapSize = NDS::ARM9->ITCMSize; + break; + case exeMem_MainRAM: mapStart = 0x2000000; mapSize = 0x1000000; break; + case exeMem_SWRAM: + if (num == 0) + { + if (NDS::SWRAM_ARM9) + mapStart = 0x3000000, mapSize = 0x1000000; + else + mapStart = mapSize = 0; + } + else + { + if (NDS::SWRAM_ARM7) + mapStart = 0x3000000, mapSize = 0x800000; + else + mapStart = mapSize = 0; + } + break; + case exeMem_LCDC: + if (num == 0) + mapStart = 0x6800000, mapSize = 0xA4000; + break; + case exeMem_ARM9_BIOS: + if (num == 0) + mapStart = 0xFFFF0000, mapSize = 0x10000; + break; + case exeMem_ARM7_BIOS: + if (num == 1) + mapStart = 0; mapSize = 0x4000; + break; + case exeMem_ARM7_WRAM: + if (num == 1) + { + if (NDS::SWRAM_ARM7) + mapStart = 0x3800000, mapSize = 0x800000; + else + mapStart = 0x3000000, mapSize = 0x1000000; + } + break; + case exeMem_ARM7_WVRAM: + if (num == 1) + mapStart = 0x6000000, mapSize = 0x1000000; + break; + } + + for (u32 j = 0; j < mapSize / physSize; j++) + { + u32 virtAddr = mapStart + physSize * j + (addr - ExeMemRegionOffsets[i]); + if (num == 0 + && virtAddr >= NDS::ARM9->DTCMBase && virtAddr < (NDS::ARM9->DTCMBase + NDS::ARM9->DTCMSize)) + continue; + if (invalidate) + { + if (num == 0) + MemoryStatus9[virtAddr / 512] |= 0x80; + else + MemoryStatus7[virtAddr / 512] |= 0x80; + } + else + { + if (num == 0) + MemoryStatus9[virtAddr / 512] &= ~0x80; + else + MemoryStatus7[virtAddr / 512] &= ~0x80; + } + } + + } + return; + } + } + + assert(false); +} + +template +T SlowRead9(ARMv5* cpu, u32 addr) +{ + u32 offset = addr & 0x3; + addr &= ~(sizeof(T) - 1); + + T val; + if (addr < cpu->ITCMSize) + val = *(T*)&cpu->ITCM[addr & 0x7FFF]; + else if (addr >= cpu->DTCMBase && addr < (cpu->DTCMBase + cpu->DTCMSize)) + val = *(T*)&cpu->DTCM[(addr - cpu->DTCMBase) & 0x3FFF]; + else if (std::is_same::value) + val = NDS::ARM9Read32(addr); + else if (std::is_same::value) + val = NDS::ARM9Read16(addr); + else + val = NDS::ARM9Read8(addr); + + if (std::is_same::value) + return ROR(val, offset << 3); + else + return val; +} + +template +void SlowWrite9(ARMv5* cpu, u32 addr, T val) +{ + addr &= ~(sizeof(T) - 1); + + if (addr < cpu->ITCMSize) + { + InvalidateITCMIfNecessary(addr); + *(T*)&cpu->ITCM[addr & 0x7FFF] = val; + } + else if (addr >= cpu->DTCMBase && addr < (cpu->DTCMBase + cpu->DTCMSize)) + { + *(T*)&cpu->DTCM[(addr - cpu->DTCMBase) & 0x3FFF] = val; + } + else if (std::is_same::value) + { + NDS::ARM9Write32(addr, val); + } + else if (std::is_same::value) + { + NDS::ARM9Write16(addr, val); + } + else + { + NDS::ARM9Write8(addr, val); + } +} + +template void SlowWrite9(ARMv5*, u32, u32); +template void SlowWrite9(ARMv5*, u32, u16); +template void SlowWrite9(ARMv5*, u32, u8); + +template u32 SlowRead9(ARMv5*, u32); +template u16 SlowRead9(ARMv5*, u32); +template u8 SlowRead9(ARMv5*, u32); + +template +T SlowRead7(u32 addr) +{ + u32 offset = addr & 0x3; + addr &= ~(sizeof(T) - 1); + + T val; + if (std::is_same::value) + val = NDS::ARM7Read32(addr); + else if (std::is_same::value) + val = NDS::ARM7Read16(addr); + else + val = NDS::ARM7Read8(addr); + + if (std::is_same::value) + return ROR(val, offset << 3); + else + return val; +} + +template +void SlowWrite7(u32 addr, T val) +{ + addr &= ~(sizeof(T) - 1); + + if (std::is_same::value) + NDS::ARM7Write32(addr, val); + else if (std::is_same::value) + NDS::ARM7Write16(addr, val); + else + NDS::ARM7Write8(addr, val); +} + +template +void SlowBlockTransfer9(u32 addr, u64* data, u32 num, ARMv5* cpu) +{ + addr &= ~0x3; + for (int i = 0; i < num; i++) + { + addr += PreInc * 4; + if (Write) + SlowWrite9(cpu, addr, data[i]); + else + data[i] = SlowRead9(cpu, addr); + addr += !PreInc * 4; + } +} + +template +void SlowBlockTransfer7(u32 addr, u64* data, u32 num) +{ + addr &= ~0x3; + for (int i = 0; i < num; i++) + { + addr += PreInc * 4; + if (Write) + SlowWrite7(addr, data[i]); + else + data[i] = SlowRead7(addr); + addr += !PreInc * 4; + } +} + +template void SlowWrite7(u32, u32); +template void SlowWrite7(u32, u16); +template void SlowWrite7(u32, u8); + +template u32 SlowRead7(u32); +template u16 SlowRead7(u32); +template u8 SlowRead7(u32); + +template void SlowBlockTransfer9(u32, u64*, u32, ARMv5*); +template void SlowBlockTransfer9(u32, u64*, u32, ARMv5*); +template void SlowBlockTransfer9(u32, u64*, u32, ARMv5*); +template void SlowBlockTransfer9(u32, u64*, u32, ARMv5*); +template void SlowBlockTransfer7(u32 addr, u64* data, u32 num); +template void SlowBlockTransfer7(u32 addr, u64* data, u32 num); +template void SlowBlockTransfer7(u32 addr, u64* data, u32 num); +template void SlowBlockTransfer7(u32 addr, u64* data, u32 num); template struct UnreliableHashTable @@ -211,31 +540,25 @@ struct UnreliableHashTable }; UnreliableHashTable RestoreCandidates; -UnreliableHashTable FastBlockLookUp; +UnreliableHashTable FastBlockLookUp9; +UnreliableHashTable FastBlockLookUp7; void Init() { - for (int i = 0; i < 0x2000; i++) - { - ExeMemKind kind = JIT_MEM[0][i >> 8]; - u32 size = ExeMemRegionSizes[kind]; - - AddrTranslate9[i] = ExeMemRegionOffsets[kind] + ((i << 15) & (size - 1)); - } - for (int i = 0; i < 0x4000; i++) - { - ExeMemKind kind = JIT_MEM[1][i >> 9]; - u32 size = ExeMemRegionSizes[kind]; - - AddrTranslate7[i] = ExeMemRegionOffsets[kind] + ((i << 14) & (size - 1)); - } - - compiler = new Compiler(); + JITCompiler = new Compiler(); } void DeInit() { - delete compiler; + delete JITCompiler; +} + +void Reset() +{ + ResetBlockCache(); + + UpdateMemoryStatus9(0, 0xFFFFFFFF); + UpdateMemoryStatus7(0, 0xFFFFFFFF); } void FloodFillSetFlags(FetchedInstr instrs[], int start, u8 flags) @@ -256,25 +579,31 @@ void FloodFillSetFlags(FetchedInstr instrs[], int start, u8 flags) } } -bool DecodeLiteral(const FetchedInstr& instr, u32& addr) +bool DecodeLiteral(bool thumb, const FetchedInstr& instr, u32& addr) { - switch (instr.Info.Kind) + if (!thumb) { - case ARMInstrInfo::ak_STR_IMM: - case ARMInstrInfo::ak_STRB_IMM: - addr = (instr.Addr + 8) + ((instr.Instr & 0xFFF) * (instr.Instr & (1 << 23) ? 1 : -1)); - return true; - case ARMInstrInfo::ak_STRD_IMM: - case ARMInstrInfo::ak_STRH_IMM: - addr = (instr.Addr + 8) + (((instr.Instr & 0xF00) >> 4 | (instr.Instr & 0xF)) * (instr.Instr & (1 << 23) ? 1 : -1)); - return true; - case ARMInstrInfo::ak_STM: // I honestly hope noone was ever crazy enough to do stm pc, {whatever} - addr = instr.Addr + 8; + switch (instr.Info.Kind) + { + case ARMInstrInfo::ak_LDR_IMM: + case ARMInstrInfo::ak_LDRB_IMM: + addr = (instr.Addr + 8) + ((instr.Instr & 0xFFF) * (instr.Instr & (1 << 23) ? 1 : -1)); + return true; + case ARMInstrInfo::ak_LDRH_IMM: + addr = (instr.Addr + 8) + (((instr.Instr & 0xF00) >> 4 | (instr.Instr & 0xF)) * (instr.Instr & (1 << 23) ? 1 : -1)); + return true; + default: + break; + } + } + else if (instr.Info.Kind == ARMInstrInfo::tk_LDR_PCREL) + { + addr = ((instr.Addr + 4) & ~0x2) + ((instr.Instr & 0xFF) << 2); return true; - default: - JIT_DEBUGPRINT("Literal %08x %x not recognised\n", instr.Instr, instr.Addr); - return false; } + + JIT_DEBUGPRINT("Literal %08x %x not recognised %d\n", instr.Instr, instr.Addr, instr.Info.Kind); + return false; } bool DecodeBranch(bool thumb, const FetchedInstr& instr, u32& cond, bool hasLink, u32 lr, bool& link, @@ -453,6 +782,8 @@ InterpreterFunc InterpretTHUMB[ARMInstrInfo::tk_Count] = }; #undef F + +extern u32 literalsPerBlock; void CompileBlock(ARM* cpu) { bool thumb = cpu->CPSR & 0x20; @@ -463,31 +794,33 @@ void CompileBlock(ARM* cpu) Config::JIT_MaxBlockSize = 32; u32 blockAddr = cpu->R[15] - (thumb ? 2 : 4); - if (!(cpu->Num == 0 - ? IsMapped<0>(blockAddr) - : IsMapped<1>(blockAddr))) + u32 pseudoPhysicalAddr = cpu->Num == 0 + ? TranslateAddr9(blockAddr) + : TranslateAddr7(blockAddr); + if (pseudoPhysicalAddr < ExeMemRegionSizes[exeMem_Unmapped]) { printf("Trying to compile a block in unmapped memory: %x\n", blockAddr); } - u32 pseudoPhysicalAddr = cpu->Num == 0 - ? TranslateAddr<0>(blockAddr) - : TranslateAddr<1>(blockAddr); - FetchedInstr instrs[Config::JIT_MaxBlockSize]; int i = 0; u32 r15 = cpu->R[15]; - u32 addresseRanges[32] = {}; + u32 addressRanges[Config::JIT_MaxBlockSize]; + u32 addressMasks[Config::JIT_MaxBlockSize] = {0}; u32 numAddressRanges = 0; + u32 numLiterals = 0; + u32 literalLoadAddrs[Config::JIT_MaxBlockSize]; + // they are going to be hashed + u32 literalValues[Config::JIT_MaxBlockSize]; + u32 instrValues[Config::JIT_MaxBlockSize]; + cpu->FillPipeline(); u32 nextInstr[2] = {cpu->NextInstr[0], cpu->NextInstr[1]}; u32 nextInstrAddr[2] = {blockAddr, r15}; - JIT_DEBUGPRINT("start block %x %08x (%x) (region invalidates %dx)\n", - blockAddr, cpu->CPSR, pseudoPhysicalAddr, - CodeRanges[pseudoPhysicalAddr / 512].TimesInvalidated); + JIT_DEBUGPRINT("start block %x %08x (%x)\n", blockAddr, cpu->CPSR, pseudoPhysicalAddr); u32 lastSegmentStart = blockAddr; u32 lr; @@ -507,23 +840,29 @@ void CompileBlock(ARM* cpu) nextInstrAddr[1] = r15; JIT_DEBUGPRINT("instr %08x %x\n", instrs[i].Instr & (thumb ? 0xFFFF : ~0), instrs[i].Addr); - u32 translatedAddr = (cpu->Num == 0 - ? TranslateAddr<0>(instrs[i].Addr) - : TranslateAddr<1>(instrs[i].Addr)) & ~0x1FF; - if (i == 0 || translatedAddr != addresseRanges[numAddressRanges - 1]) + instrValues[i] = instrs[i].Instr; + + u32 translatedAddr = cpu->Num == 0 + ? TranslateAddr9(instrs[i].Addr) + : TranslateAddr7(instrs[i].Addr); + u32 translatedAddrRounded = translatedAddr & ~0x1FF; + if (i == 0 || translatedAddrRounded != addressRanges[numAddressRanges - 1]) { bool returning = false; for (int j = 0; j < numAddressRanges; j++) { - if (addresseRanges[j] == translatedAddr) + if (addressRanges[j] == translatedAddrRounded) { + std::swap(addressRanges[j], addressRanges[numAddressRanges - 1]); + std::swap(addressMasks[j], addressMasks[numAddressRanges - 1]); returning = true; break; } } if (!returning) - addresseRanges[numAddressRanges++] = translatedAddr; + addressRanges[numAddressRanges++] = translatedAddrRounded; } + addressMasks[numAddressRanges - 1] |= 1 << ((translatedAddr & 0x1FF) / 16); if (cpu->Num == 0) { @@ -572,7 +911,8 @@ void CompileBlock(ARM* cpu) u32 icode = ((instrs[i].Instr >> 4) & 0xF) | ((instrs[i].Instr >> 16) & 0xFF0); assert(InterpretARM[instrs[i].Info.Kind] == ARMInterpreter::ARMInstrTable[icode] || instrs[i].Info.Kind == ARMInstrInfo::ak_MOV_REG_LSL_IMM - || instrs[i].Info.Kind == ARMInstrInfo::ak_Nop); + || instrs[i].Info.Kind == ARMInstrInfo::ak_Nop + || instrs[i].Info.Kind == ARMInstrInfo::ak_UNK); if (cpu->CheckCondition(instrs[i].Cond())) InterpretARM[instrs[i].Info.Kind](cpu); else @@ -583,21 +923,26 @@ void CompileBlock(ARM* cpu) instrs[i].DataCycles = cpu->DataCycles; instrs[i].DataRegion = cpu->DataRegion; - if (instrs[i].Info.SpecialKind == ARMInstrInfo::special_WriteMem - && instrs[i].Info.SrcRegs == (1 << 15) - && instrs[i].Info.DstRegs == 0) + u32 literalAddr; + if (Config::JIT_LiteralOptimisations + && instrs[i].Info.SpecialKind == ARMInstrInfo::special_LoadLiteral + && DecodeLiteral(thumb, instrs[i], literalAddr)) { - assert (!thumb); - - u32 addr; - if (DecodeLiteral(instrs[i], addr)) - { - JIT_DEBUGPRINT("pc relative write detected\n"); - u32 translatedAddr = cpu->Num == 0 ? TranslateAddr<0>(addr) : TranslateAddr<1>(addr); - - ARMJIT::InvalidateByAddr(translatedAddr, false); - CodeRanges[translatedAddr / 512].InvalidLiterals |= (1 << ((translatedAddr & 0x1FF) / 16)); - } + u32 translatedAddr = cpu->Num == 0 + ? TranslateAddr9(literalAddr) + : TranslateAddr7(literalAddr); + u32 translatedAddrRounded = translatedAddr & ~0x1FF; + + u32 j = 0; + for (; j < numAddressRanges; j++) + if (addressRanges[j] == translatedAddrRounded) + break; + if (j == numAddressRanges) + addressRanges[numAddressRanges++] = translatedAddrRounded; + addressMasks[j] |= 1 << ((translatedAddr & 0x1FF) / 16); + JIT_DEBUGPRINT("literal loading %08x %08x %08x %08x\n", literalAddr, translatedAddr, addressMasks[j], addressRanges[j]); + cpu->DataRead32(literalAddr, &literalValues[numLiterals]); + literalLoadAddrs[numLiterals++] = translatedAddr; } if (thumb && instrs[i].Info.Kind == ARMInstrInfo::tk_BL_LONG_2 && i > 0 @@ -650,8 +995,8 @@ void CompileBlock(ARM* cpu) else if (hasBranched && !isBackJump && i + 1 < Config::JIT_MaxBlockSize) { u32 targetPseudoPhysical = cpu->Num == 0 - ? TranslateAddr<0>(target) - : TranslateAddr<1>(target); + ? TranslateAddr9(target) + : TranslateAddr7(target); if (link) { @@ -688,36 +1033,29 @@ void CompileBlock(ARM* cpu) i++; - bool canCompile = compiler->CanCompile(thumb, instrs[i - 1].Info.Kind); + bool canCompile = JITCompiler->CanCompile(thumb, instrs[i - 1].Info.Kind); bool secondaryFlagReadCond = !canCompile || (instrs[i - 1].BranchFlags & (branch_FollowCondTaken | branch_FollowCondNotTaken)); if (instrs[i - 1].Info.ReadFlags != 0 || secondaryFlagReadCond) FloodFillSetFlags(instrs, i - 2, !secondaryFlagReadCond ? instrs[i - 1].Info.ReadFlags : 0xF); } while(!instrs[i - 1].Info.EndBlock && i < Config::JIT_MaxBlockSize && !cpu->Halted && (!cpu->IRQ || (cpu->CPSR & 0x80))); + u32 literalHash = (u32)XXH3_64bits(literalValues, numLiterals * 4); + u32 instrHash = (u32)XXH3_64bits(instrValues, i * 4); + JitBlock* prevBlock = RestoreCandidates.LookUp(pseudoPhysicalAddr); bool mayRestore = true; if (prevBlock) { RestoreCandidates.Remove(pseudoPhysicalAddr); - if (prevBlock->NumInstrs == i) - { - for (int j = 0; j < i; j++) - { - if (prevBlock->Instrs()[j] != instrs[j].Instr) - { - mayRestore = false; - break; - } - } - } - else - mayRestore = false; - if (prevBlock->NumAddresses == numAddressRanges) + mayRestore = prevBlock->LiteralHash == literalHash && prevBlock->InstrHash == instrHash; + + if (mayRestore && prevBlock->NumAddresses == numAddressRanges) { for (int j = 0; j < numAddressRanges; j++) { - if (prevBlock->AddressRanges()[j] != addresseRanges[j]) + if (prevBlock->AddressRanges()[j] != addressRanges[j] + || prevBlock->AddressMasks()[j] != addressMasks[j]) { mayRestore = false; break; @@ -739,18 +1077,21 @@ void CompileBlock(ARM* cpu) if (prevBlock) delete prevBlock; - block = new JitBlock(i, numAddressRanges); - for (int j = 0; j < i; j++) - block->Instrs()[j] = instrs[j].Instr; + block = new JitBlock(cpu->Num, i, numAddressRanges, numLiterals); + block->LiteralHash = literalHash; + block->InstrHash = instrHash; + for (int j = 0; j < numAddressRanges; j++) + block->AddressRanges()[j] = addressRanges[j]; for (int j = 0; j < numAddressRanges; j++) - block->AddressRanges()[j] = addresseRanges[j]; + block->AddressMasks()[j] = addressMasks[j]; + for (int j = 0; j < numLiterals; j++) + block->Literals()[j] = literalLoadAddrs[j]; - block->StartAddr = blockAddr; block->PseudoPhysicalAddr = pseudoPhysicalAddr; FloodFillSetFlags(instrs, i - 1, 0xF); - block->EntryPoint = compiler->CompileBlock(pseudoPhysicalAddr, cpu, thumb, instrs, i); + block->EntryPoint = JITCompiler->CompileBlock(pseudoPhysicalAddr, cpu, thumb, instrs, i); } else { @@ -760,23 +1101,73 @@ void CompileBlock(ARM* cpu) for (int j = 0; j < numAddressRanges; j++) { - assert(addresseRanges[j] == block->AddressRanges()[j]); - CodeRanges[addresseRanges[j] / 512].Blocks.Add(block); + assert(addressRanges[j] == block->AddressRanges()[j]); + assert(addressMasks[j] == block->AddressMasks()[j]); + assert(addressMasks[j] != 0); + CodeRanges[addressRanges[j] / 512].Code |= addressMasks[j]; + CodeRanges[addressRanges[j] / 512].Blocks.Add(block); + + UpdateRegionByPseudoPhyiscal(addressRanges[j], true); } - JitBlocks[pseudoPhysicalAddr] = block; - FastBlockLookUp.Insert(pseudoPhysicalAddr, compiler->SubEntryOffset(block->EntryPoint)); + if (cpu->Num == 0) + { + JitBlocks9[pseudoPhysicalAddr] = block; + FastBlockLookUp9.Insert(pseudoPhysicalAddr, JITCompiler->SubEntryOffset(block->EntryPoint)); + } + else + { + JitBlocks7[pseudoPhysicalAddr] = block; + FastBlockLookUp7.Insert(pseudoPhysicalAddr, JITCompiler->SubEntryOffset(block->EntryPoint)); + } } -void InvalidateByAddr(u32 pseudoPhysical, bool mayRestore) +void InvalidateByAddr(u32 pseudoPhysical) { JIT_DEBUGPRINT("invalidating by addr %x\n", pseudoPhysical); AddressRange* range = &CodeRanges[pseudoPhysical / 512]; - int startLength = range->Blocks.Length; - for (int i = 0; i < range->Blocks.Length; i++) + u32 mask = 1 << ((pseudoPhysical & 0x1FF) / 16); + + range->Code = 0; + for (int i = 0; i < range->Blocks.Length;) { - assert(range->Blocks.Length == startLength); JitBlock* block = range->Blocks[i]; + + bool invalidated = false; + u32 mask = 0; + for (int j = 0; j < block->NumAddresses; j++) + { + if (block->AddressRanges()[j] == (pseudoPhysical & ~0x1FF)) + { + mask = block->AddressMasks()[j]; + invalidated = block->AddressMasks()[j] & mask; + break; + } + } + assert(mask); + if (!invalidated) + { + range->Code |= mask; + i++; + continue; + } + range->Blocks.Remove(i); + + bool literalInvalidation = false; + for (int j = 0; j < block->NumLiterals; j++) + { + u32 addr = block->Literals()[j]; + if (addr == pseudoPhysical) + { + if (InvalidLiterals.Find(pseudoPhysical) != -1) + { + InvalidLiterals.Add(pseudoPhysical); + JIT_DEBUGPRINT("found invalid literal %d\n", InvalidLiterals.Length); + } + literalInvalidation = true; + break; + } + } for (int j = 0; j < block->NumAddresses; j++) { u32 addr = block->AddressRanges()[j]; @@ -786,76 +1177,59 @@ void InvalidateByAddr(u32 pseudoPhysical, bool mayRestore) assert(otherRange != range); bool removed = otherRange->Blocks.RemoveByValue(block); assert(removed); + + if (otherRange->Blocks.Length == 0) + { + otherRange->Code = 0; + UpdateRegionByPseudoPhyiscal(addr, false); + } } } for (int j = 0; j < block->NumLinks(); j++) - compiler->UnlinkBlock(block->Links()[j]); + JITCompiler->UnlinkBlock(block->Links()[j]); + block->ResetLinks(); - JitBlocks.erase(block->PseudoPhysicalAddr); - FastBlockLookUp.Remove(block->PseudoPhysicalAddr); + if (block->Num == 0) + { + JitBlocks9.erase(block->PseudoPhysicalAddr); + FastBlockLookUp9.Remove(block->PseudoPhysicalAddr); + } + else + { + JitBlocks7.erase(block->PseudoPhysicalAddr); + FastBlockLookUp7.Remove(block->PseudoPhysicalAddr); + } - if (mayRestore) + if (!literalInvalidation) { JitBlock* prevBlock = RestoreCandidates.Insert(block->PseudoPhysicalAddr, block); if (prevBlock) delete prevBlock; } + else + { + delete block; + } } - if ((range->TimesInvalidated + 1) > range->TimesInvalidated) - range->TimesInvalidated++; - - range->Blocks.Clear(); -} -void InvalidateByAddr7(u32 addr) -{ - u32 pseudoPhysical = TranslateAddr<1>(addr); - if (__builtin_expect(CodeRanges[pseudoPhysical / 512].Blocks.Length > 0, false)) - InvalidateByAddr(pseudoPhysical); + if (range->Blocks.Length == 0) + UpdateRegionByPseudoPhyiscal(pseudoPhysical, false); } -void InvalidateITCM(u32 addr) +void InvalidateRegionIfNecessary(u32 pseudoPhyisical) { - u32 pseudoPhysical = addr + ExeMemRegionOffsets[exeMem_ITCM]; - if (CodeRanges[pseudoPhysical / 512].Blocks.Length > 0) - InvalidateByAddr(pseudoPhysical); -} - -void InvalidateAll() -{ - JIT_DEBUGPRINT("invalidating all %x\n", JitBlocks.size()); - for (auto it : JitBlocks) - { - JitBlock* block = it.second; - - FastBlockLookUp.Remove(block->PseudoPhysicalAddr); - - for (int i = 0; i < block->NumAddresses; i++) - { - u32 addr = block->AddressRanges()[i]; - AddressRange* range = &CodeRanges[addr / 512]; - range->Blocks.Clear(); - if (range->TimesInvalidated + 1 > range->TimesInvalidated) - range->TimesInvalidated++; - } - for (int i = 0; i < block->NumLinks(); i++) - compiler->UnlinkBlock(block->Links()[i]); - block->ResetLinks(); - - JitBlock* prevBlock = RestoreCandidates.Insert(block->PseudoPhysicalAddr, block); - if (prevBlock) - delete prevBlock; - } - - JitBlocks.clear(); + if (CodeRanges[pseudoPhyisical / 512].Code & (1 << ((pseudoPhyisical & 0x1FF) / 16))) + InvalidateByAddr(pseudoPhyisical); } void ResetBlockCache() { printf("Resetting JIT block cache...\n"); - FastBlockLookUp.Reset(); + InvalidLiterals.Clear(); + FastBlockLookUp9.Reset(); + FastBlockLookUp7.Reset(); RestoreCandidates.Reset(); for (int i = 0; i < sizeof(RestoreCandidates.Table)/sizeof(RestoreCandidates.Table[0]); i++) { @@ -870,61 +1244,119 @@ void ResetBlockCache() RestoreCandidates.Table[i].ValB = NULL; } } - for (auto it : JitBlocks) + for (auto it : JitBlocks9) { JitBlock* block = it.second; for (int j = 0; j < block->NumAddresses; j++) { u32 addr = block->AddressRanges()[j]; CodeRanges[addr / 512].Blocks.Clear(); - CodeRanges[addr / 512].TimesInvalidated = 0; - CodeRanges[addr / 512].InvalidLiterals = 0; + CodeRanges[addr / 512].Code = 0; } delete block; } - JitBlocks.clear(); + for (auto it : JitBlocks7) + { + JitBlock* block = it.second; + for (int j = 0; j < block->NumAddresses; j++) + { + u32 addr = block->AddressRanges()[j]; + CodeRanges[addr / 512].Blocks.Clear(); + CodeRanges[addr / 512].Code = 0; + } + } + JitBlocks9.clear(); + JitBlocks7.clear(); - compiler->Reset(); + JITCompiler->Reset(); } +template JitBlockEntry LookUpBlockEntry(u32 addr) { - u32 entryOffset = FastBlockLookUp.LookUp(addr); + auto& fastMap = Num == 0 ? FastBlockLookUp9 : FastBlockLookUp7; + u32 entryOffset = fastMap.LookUp(addr); if (entryOffset != UINT32_MAX) - return compiler->AddEntryOffset(entryOffset); + return JITCompiler->AddEntryOffset(entryOffset); - auto block = JitBlocks.find(addr); - if (block != JitBlocks.end()) + auto& slowMap = Num == 0 ? JitBlocks9 : JitBlocks7; + auto block = slowMap.find(addr); + if (block != slowMap.end()) { - FastBlockLookUp.Insert(addr, compiler->SubEntryOffset(block->second->EntryPoint)); + fastMap.Insert(addr, JITCompiler->SubEntryOffset(block->second->EntryPoint)); return block->second->EntryPoint; } return NULL; } +template JitBlockEntry LookUpBlockEntry<0>(u32); +template JitBlockEntry LookUpBlockEntry<1>(u32); + template void LinkBlock(ARM* cpu, u32 codeOffset) { - u32 targetPseudoPhys = TranslateAddr(cpu->R[15] - ((cpu->CPSR&0x20)?2:4)); - auto block = JitBlocks.find(targetPseudoPhys); - if (block == JitBlocks.end()) + auto& blockMap = Num == 0 ? JitBlocks9 : JitBlocks7; + u32 instrAddr = cpu->R[15] - ((cpu->CPSR&0x20)?2:4); + u32 targetPseudoPhys = Num == 0 ? TranslateAddr9(instrAddr) : TranslateAddr7(instrAddr); + auto block = blockMap.find(targetPseudoPhys); + if (block == blockMap.end()) { CompileBlock(cpu); - block = JitBlocks.find(targetPseudoPhys); + block = blockMap.find(targetPseudoPhys); } JIT_DEBUGPRINT("linking to block %08x\n", targetPseudoPhys); block->second->AddLink(codeOffset); - compiler->LinkBlock(codeOffset, block->second->EntryPoint); + JITCompiler->LinkBlock(codeOffset, block->second->EntryPoint); +} + +template void LinkBlock<0>(ARM*, u32); +template void LinkBlock<1>(ARM*, u32); + +void WifiWrite32(u32 addr, u32 val) +{ + Wifi::Write(addr, val & 0xFFFF); + Wifi::Write(addr + 2, val >> 16); +} + +u32 WifiRead32(u32 addr) +{ + return Wifi::Read(addr) | (Wifi::Read(addr + 2) << 16); +} + +template +void VRAMWrite(u32 addr, T val) +{ + switch (addr & 0x00E00000) + { + case 0x00000000: GPU::WriteVRAM_ABG(addr, val); return; + case 0x00200000: GPU::WriteVRAM_BBG(addr, val); return; + case 0x00400000: GPU::WriteVRAM_AOBJ(addr, val); return; + case 0x00600000: GPU::WriteVRAM_BOBJ(addr, val); return; + default: GPU::WriteVRAM_LCDC(addr, val); return; + } +} +template +T VRAMRead(u32 addr) +{ + switch (addr & 0x00E00000) + { + case 0x00000000: return GPU::ReadVRAM_ABG(addr); + case 0x00200000: return GPU::ReadVRAM_BBG(addr); + case 0x00400000: return GPU::ReadVRAM_AOBJ(addr); + case 0x00600000: return GPU::ReadVRAM_BOBJ(addr); + default: return GPU::ReadVRAM_LCDC(addr); + } } void* GetFuncForAddr(ARM* cpu, u32 addr, bool store, int size) { if (cpu->Num == 0) { - if ((addr & 0xFF000000) == 0x04000000) + switch (addr & 0xFF000000) { + case 0x04000000: if (!store && size == 32 && addr == 0x04100010 && NDS::ExMemCnt[0] & (1<<11)) return (void*)NDSCart::ReadROMData; @@ -949,13 +1381,25 @@ void* GetFuncForAddr(ARM* cpu, u32 addr, bool store, int size) switch (size | store) { - case 8: return (void*)NDS::ARM9IORead8; - case 9: return (void*)NDS::ARM9IOWrite8; + case 8: return (void*)NDS::ARM9IORead8; + case 9: return (void*)NDS::ARM9IOWrite8; case 16: return (void*)NDS::ARM9IORead16; case 17: return (void*)NDS::ARM9IOWrite16; case 32: return (void*)NDS::ARM9IORead32; case 33: return (void*)NDS::ARM9IOWrite32; } + break; + case 0x06000000: + switch (size | store) + { + case 8: return (void*)VRAMRead; + case 9: return NULL; + case 16: return (void*)VRAMRead; + case 17: return (void*)VRAMWrite; + case 32: return (void*)VRAMRead; + case 33: return (void*)VRAMWrite; + } + break; } } else @@ -987,20 +1431,31 @@ void* GetFuncForAddr(ARM* cpu, u32 addr, bool store, int size) } break; case 0x04800000: - if (addr < 0x04810000 && size == 16) + if (addr < 0x04810000 && size >= 16) { - if (store) - return (void*)Wifi::Write; - else - return (void*)Wifi::Read; + switch (size | store) + { + case 16: return (void*)Wifi::Read; + case 17: return (void*)Wifi::Write; + case 32: return (void*)WifiRead32; + case 33: return (void*)WifiWrite32; + } } break; + case 0x06000000: + case 0x06800000: + switch (size | store) + { + case 8: return (void*)GPU::ReadVRAM_ARM7; + case 9: return (void*)GPU::WriteVRAM_ARM7; + case 16: return (void*)GPU::ReadVRAM_ARM7; + case 17: return (void*)GPU::WriteVRAM_ARM7; + case 32: return (void*)GPU::ReadVRAM_ARM7; + case 33: return (void*)GPU::WriteVRAM_ARM7; + } } } return NULL; } } - -template void ARMJIT::LinkBlock<0>(ARM*, u32); -template void ARMJIT::LinkBlock<1>(ARM*, u32); diff --git a/src/ARMJIT.h b/src/ARMJIT.h index cab385f..44a6140 100644 --- a/src/ARMJIT.h +++ b/src/ARMJIT.h @@ -28,45 +28,60 @@ extern const u32 ExeMemRegionSizes[]; typedef u32 (*JitBlockEntry)(); -extern u32 AddrTranslate9[0x2000]; -extern u32 AddrTranslate7[0x4000]; - const u32 ExeMemSpaceSize = 0x518000; // I hate you C++, sometimes I really hate you... -template -inline bool IsMapped(u32 addr) -{ - if (num == 0) - return AddrTranslate9[(addr & 0xFFFFFFF) >> 15] >= ExeMemRegionSizes[exeMem_Unmapped]; - else - return AddrTranslate7[(addr & 0xFFFFFFF) >> 14] >= ExeMemRegionSizes[exeMem_Unmapped]; -} - -template -inline u32 TranslateAddr(u32 addr) -{ - if (num == 0) - return AddrTranslate9[(addr & 0xFFFFFFF) >> 15] + (addr & 0x7FFF); - else - return AddrTranslate7[(addr & 0xFFFFFFF) >> 14] + (addr & 0x3FFF); -} +u32 TranslateAddr9(u32 addr); +u32 TranslateAddr7(u32 addr); +template JitBlockEntry LookUpBlockEntry(u32 addr); - void Init(); void DeInit(); -void InvalidateByAddr(u32 pseudoPhysical, bool mayRestore = true); -void InvalidateAll(); +void Reset(); + +void InvalidateByAddr(u32 pseudoPhysical); + +void InvalidateRegionIfNecessary(u32 addr); -void InvalidateITCM(u32 addr); -void InvalidateByAddr7(u32 addr); +inline void InvalidateMainRAMIfNecessary(u32 addr) +{ + InvalidateRegionIfNecessary(ExeMemRegionOffsets[exeMem_MainRAM] + (addr & (MAIN_RAM_SIZE - 1))); +} +inline void InvalidateITCMIfNecessary(u32 addr) +{ + InvalidateRegionIfNecessary(ExeMemRegionOffsets[exeMem_ITCM] + (addr & 0x7FFF)); +} +inline void InvalidateLCDCIfNecessary(u32 addr) +{ + if (addr < 0x68A3FFF) + InvalidateRegionIfNecessary(ExeMemRegionOffsets[exeMem_LCDC] + (addr - 0x6800000)); +} +inline void InvalidateSWRAM7IfNecessary(u32 addr) +{ + InvalidateRegionIfNecessary(ExeMemRegionOffsets[exeMem_SWRAM] + (NDS::SWRAM_ARM7 - NDS::SharedWRAM) + (addr & NDS::SWRAM_ARM7Mask)); +} +inline void InvalidateSWRAM9IfNecessary(u32 addr) +{ + InvalidateRegionIfNecessary(ExeMemRegionOffsets[exeMem_SWRAM] + (NDS::SWRAM_ARM9 - NDS::SharedWRAM) + (addr & NDS::SWRAM_ARM9Mask)); +} +inline void InvalidateARM7WRAMIfNecessary(u32 addr) +{ + InvalidateRegionIfNecessary(ExeMemRegionOffsets[exeMem_ARM7_WRAM] + (addr & 0xFFFF)); +} +inline void InvalidateARM7WVRAMIfNecessary(u32 addr) +{ + InvalidateRegionIfNecessary(ExeMemRegionOffsets[exeMem_ARM7_WVRAM] + (addr & 0x1FFFF)); +} void CompileBlock(ARM* cpu); void ResetBlockCache(); +void UpdateMemoryStatus9(u32 start, u32 end); +void UpdateMemoryStatus7(u32 start, u32 end); + } extern "C" void ARM_Dispatch(ARM* cpu, ARMJIT::JitBlockEntry entry); diff --git a/src/ARMJIT_A64/ARMJIT_Compiler.cpp b/src/ARMJIT_A64/ARMJIT_Compiler.cpp index 00fa436..a67f357 100644 --- a/src/ARMJIT_A64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_A64/ARMJIT_Compiler.cpp @@ -650,7 +650,7 @@ void Compiler::Comp_AddCycles_CDI() s32 numC = NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2]; s32 numD = CurInstr.DataCycles; - if ((CurInstr.DataRegion >> 4) == 0x02) // mainRAM + if ((CurInstr.DataRegion >> 24) == 0x02) // mainRAM { if (CodeRegion == 0x02) cycles = numC + numD; @@ -695,7 +695,7 @@ void Compiler::Comp_AddCycles_CD() s32 numC = NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2]; s32 numD = CurInstr.DataCycles; - if ((CurInstr.DataRegion >> 4) == 0x02) + if ((CurInstr.DataRegion >> 24) == 0x02) { if (CodeRegion == 0x02) cycles += numC + numD; diff --git a/src/ARMJIT_Internal.h b/src/ARMJIT_Internal.h index 66d1808..4e45760 100644 --- a/src/ARMJIT_Internal.h +++ b/src/ARMJIT_Internal.h @@ -152,30 +152,34 @@ struct __attribute__((packed)) TinyVector class JitBlock { public: - JitBlock(u32 numInstrs, u32 numAddresses) + JitBlock(u32 num, u32 literalHash, u32 numAddresses, u32 numLiterals) { - NumInstrs = numInstrs; + Num = num; NumAddresses = numAddresses; - Data.SetLength(numInstrs + numAddresses); + NumLiterals = numLiterals; + Data.SetLength(numAddresses * 2 + numLiterals); } - u32 StartAddr; u32 PseudoPhysicalAddr; - - u32 NumInstrs; - u32 NumAddresses; + + u32 InstrHash, LiteralHash; + u8 Num; + u16 NumAddresses; + u16 NumLiterals; JitBlockEntry EntryPoint; - u32* Instrs() - { return &Data[0]; } u32* AddressRanges() - { return &Data[NumInstrs]; } + { return &Data[0]; } + u32* AddressMasks() + { return &Data[NumAddresses]; } + u32* Literals() + { return &Data[NumAddresses * 2]; } u32* Links() - { return &Data[NumInstrs + NumAddresses]; } + { return &Data[NumAddresses * 2 + NumLiterals]; } u32 NumLinks() - { return Data.Length - NumInstrs - NumAddresses; } + { return Data.Length - NumAddresses * 2 - NumLiterals; } void AddLink(u32 link) { @@ -184,7 +188,7 @@ public: void ResetLinks() { - Data.SetLength(NumInstrs + NumAddresses); + Data.SetLength(NumAddresses * 2 + NumLiterals); } private: @@ -200,8 +204,7 @@ private: struct __attribute__((packed)) AddressRange { TinyVector Blocks; - u16 InvalidLiterals; - u16 TimesInvalidated; + u32 Code; }; extern AddressRange CodeRanges[ExeMemSpaceSize / 512]; @@ -210,14 +213,45 @@ typedef void (*InterpreterFunc)(ARM* cpu); extern InterpreterFunc InterpretARM[]; extern InterpreterFunc InterpretTHUMB[]; -extern u8 MemRegion9[0x80000]; -extern u8 MemRegion7[0x80000]; +extern u8 MemoryStatus9[0x800000]; +extern u8 MemoryStatus7[0x800000]; + +extern TinyVector InvalidLiterals; void* GetFuncForAddr(ARM* cpu, u32 addr, bool store, int size); template void LinkBlock(ARM* cpu, u32 codeOffset); +enum +{ + memregion_Other = 0, + memregion_ITCM, + memregion_DTCM, + memregion_BIOS9, + memregion_MainRAM, + memregion_SWRAM9, + memregion_SWRAM7, + memregion_IO9, + memregion_VRAM, + memregion_BIOS7, + memregion_WRAM7, + memregion_IO7, + memregion_Wifi, + memregion_VWRAM, +}; + +int ClassifyAddress9(u32 addr); +int ClassifyAddress7(u32 addr); + +template T SlowRead9(ARMv5* cpu, u32 addr); +template void SlowWrite9(ARMv5* cpu, u32 addr, T val); +template T SlowRead7(u32 addr); +template void SlowWrite7(u32 addr, T val); + +template void SlowBlockTransfer9(u32 addr, u64* data, u32 num, ARMv5* cpu); +template void SlowBlockTransfer7(u32 addr, u64* data, u32 num); + } #endif \ No newline at end of file diff --git a/src/ARMJIT_RegisterCache.h b/src/ARMJIT_RegisterCache.h index 5e18e84..0547c84 100644 --- a/src/ARMJIT_RegisterCache.h +++ b/src/ARMJIT_RegisterCache.h @@ -95,20 +95,6 @@ public: LiteralsLoaded = 0; } - BitSet32 GetPushRegs() - { - BitSet16 used; - for (int i = 0; i < InstrsCount; i++) - used |= BitSet16(Instrs[i].Info.SrcRegs | Instrs[i].Info.DstRegs); - - BitSet32 res; - u32 registersMax = std::min((int)used.Count(), NativeRegsAvailable); - for (int i = 0; i < registersMax; i++) - res |= BitSet32(1 << (int)NativeRegAllocOrder[i]); - - return res; - } - void Prepare(bool thumb, int i) { FetchedInstr instr = Instrs[i]; @@ -139,7 +125,6 @@ public: UnloadRegister(reg); u16 necessaryRegs = ((instr.Info.SrcRegs & PCAllocatableAsSrc) | instr.Info.DstRegs) & ~instr.Info.NotStrictlyNeeded; - u16 writeRegs = instr.Info.DstRegs & ~instr.Info.NotStrictlyNeeded; BitSet16 needToBeLoaded(necessaryRegs & ~LoadedRegs); if (needToBeLoaded != BitSet16(0)) { @@ -182,13 +167,12 @@ public: if (left-- == 0) break; - writeRegs |= (1 << reg) & instr.Info.DstRegs; LoadRegister(reg, !(thumb || instr.Cond() >= 0xE) || (1 << reg) & instr.Info.SrcRegs); } } } - DirtyRegs |= writeRegs & ~(1 << 15); + DirtyRegs |= (LoadedRegs & instr.Info.DstRegs) & ~(1 << 15); } static const Reg NativeRegAllocOrder[]; diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index dd20e3c..eee2e0f 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -195,26 +195,6 @@ Compiler::Compiler() Reset(); - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 2; j++) - MemoryFuncs9[i][j] = Gen_MemoryRoutine9(j, 8 << i); - } - MemoryFuncs7[0][0] = (void*)NDS::ARM7Read8; - MemoryFuncs7[0][1] = (void*)NDS::ARM7Write8; - MemoryFuncs7[1][0] = (void*)NDS::ARM7Read16; - MemoryFuncs7[1][1] = (void*)NDS::ARM7Write16; - MemoryFuncs7[2][0] = (void*)NDS::ARM7Read32; - MemoryFuncs7[2][1] = (void*)NDS::ARM7Write32; - - for (int i = 0; i < 2; i++) - for (int j = 0; j < 2; j++) - { - MemoryFuncsSeq9[i][j] = Gen_MemoryRoutineSeq9(i, j); - MemoryFuncsSeq7[i][j][0] = Gen_MemoryRoutineSeq7(i, j, false); - MemoryFuncsSeq7[i][j][1] = Gen_MemoryRoutineSeq7(i, j, true); - } - { // RSCRATCH mode // RSCRATCH2 reg number @@ -317,6 +297,12 @@ Compiler::Compiler() // move the region forward to prevent overwriting the generated functions CodeMemSize -= GetWritableCodePtr() - ResetStart; ResetStart = GetWritableCodePtr(); + + NearStart = ResetStart; + FarStart = ResetStart + 1024*1024*24; + + NearSize = FarStart - ResetStart; + FarSize = (ResetStart + CodeMemSize) - FarStart; } void Compiler::LoadCPSR() @@ -504,6 +490,9 @@ void Compiler::Reset() { memset(ResetStart, 0xcc, CodeMemSize); SetCodePtr(ResetStart); + + NearCode = NearStart; + FarCode = FarStart; } void Compiler::Comp_SpecialBranchBehaviour(bool taken) @@ -544,8 +533,16 @@ void Compiler::Comp_SpecialBranchBehaviour(bool taken) JitBlockEntry Compiler::CompileBlock(u32 translatedAddr, ARM* cpu, bool thumb, FetchedInstr instrs[], int instrsCount) { - if (CodeMemSize - (GetWritableCodePtr() - ResetStart) < 1024 * 32) // guess... + if (NearSize - (NearCode - NearStart) < 1024 * 32) // guess... + { + printf("near reset\n"); + ResetBlockCache(); + } + if (FarSize - (FarCode - FarStart) < 1024 * 32) // guess... + { + printf("far reset\n"); ResetBlockCache(); + } ConstantCycles = 0; Thumb = thumb; @@ -762,12 +759,14 @@ void Compiler::Comp_AddCycles_CDI() Comp_AddCycles_CD(); else { + IrregularCycles = true; + s32 cycles; s32 numC = NDS::ARM7MemTimings[CurInstr.CodeCycles][Thumb ? 0 : 2]; s32 numD = CurInstr.DataCycles; - if ((CurInstr.DataRegion >> 4) == 0x02) // mainRAM + if ((CurInstr.DataRegion >> 24) == 0x02) // mainRAM { if (CodeRegion == 0x02) cycles = numC + numD; diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index e0a4978..9df218b 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -140,7 +140,7 @@ public: }; void Comp_MemAccess(int rd, int rn, const ComplexOperand& op2, int size, int flags); s32 Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc, bool decrement, bool usermode); - void Comp_MemLoadLiteral(int size, int rd, u32 addr); + bool Comp_MemLoadLiteral(int size, int rd, u32 addr); void Comp_ArithTriOp(void (Compiler::*op)(int, const Gen::OpArg&, const Gen::OpArg&), Gen::OpArg rd, Gen::OpArg rn, Gen::OpArg op2, bool carryUsed, int opFlags); @@ -154,12 +154,6 @@ public: void Comp_SpecialBranchBehaviour(bool taken); - void* Gen_MemoryRoutine9(bool store, int size); - - void* Gen_MemoryRoutineSeq9(bool store, bool preinc); - void* Gen_MemoryRoutineSeq7(bool store, bool preinc, bool codeMainRAM); - - void* Gen_ChangeCPSRRoutine(); Gen::OpArg Comp_RegShiftImm(int op, int amount, Gen::OpArg rm, bool S, bool& carryUsed); Gen::OpArg Comp_RegShiftReg(int op, Gen::OpArg rs, Gen::OpArg rm, bool S, bool& carryUsed); @@ -193,6 +187,26 @@ public: return (u8*)entry - ResetStart; } + void SwitchToNearCode() + { + FarCode = GetWritableCodePtr(); + SetCodePtr(NearCode); + } + + void SwitchToFarCode() + { + NearCode = GetWritableCodePtr(); + SetCodePtr(FarCode); + } + + u8* FarCode; + u8* NearCode; + u32 FarSize; + u32 NearSize; + + u8* NearStart; + u8* FarStart; + u8* ResetStart; u32 CodeMemSize; @@ -201,12 +215,6 @@ public: void* BranchStub[2]; - void* MemoryFuncs9[3][2]; - void* MemoryFuncs7[3][2]; - - void* MemoryFuncsSeq9[2][2]; - void* MemoryFuncsSeq7[2][2][2]; - void* ReadBanked; void* WriteBanked; diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index b595e32..c13b779 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -25,236 +25,17 @@ int squeezePointer(T* ptr) improvement. */ -/* - address - ABI_PARAM1 (a.k.a. ECX = RSCRATCH3 on Windows) - store value - ABI_PARAM2 (a.k.a. RDX = RSCRATCH2 on Windows) -*/ -void* Compiler::Gen_MemoryRoutine9(bool store, int size) +bool Compiler::Comp_MemLoadLiteral(int size, int rd, u32 addr) { - u32 addressMask = ~(size == 32 ? 3 : (size == 16 ? 1 : 0)); - AlignCode4(); - void* res = GetWritableCodePtr(); - - MOV(32, R(RSCRATCH), R(ABI_PARAM1)); - SUB(32, R(RSCRATCH), MDisp(RCPU, offsetof(ARMv5, DTCMBase))); - CMP(32, R(RSCRATCH), MDisp(RCPU, offsetof(ARMv5, DTCMSize))); - FixupBranch insideDTCM = J_CC(CC_B); - - CMP(32, R(ABI_PARAM1), MDisp(RCPU, offsetof(ARMv5, ITCMSize))); - FixupBranch insideITCM = J_CC(CC_B); - - if (store) - { - if (size > 8) - AND(32, R(ABI_PARAM1), Imm32(addressMask)); - switch (size) - { - case 32: JMP((u8*)NDS::ARM9Write32, true); break; - case 16: JMP((u8*)NDS::ARM9Write16, true); break; - case 8: JMP((u8*)NDS::ARM9Write8, true); break; - } - } - else - { - if (size == 32) - { - ABI_PushRegistersAndAdjustStack({ABI_PARAM1}, 8); - AND(32, R(ABI_PARAM1), Imm32(addressMask)); - // everything's already in the appropriate register - ABI_CallFunction(NDS::ARM9Read32); - ABI_PopRegistersAndAdjustStack({ECX}, 8); - AND(32, R(ECX), Imm8(3)); - SHL(32, R(ECX), Imm8(3)); - ROR_(32, R(RSCRATCH), R(ECX)); - RET(); - } - else if (size == 16) - { - AND(32, R(ABI_PARAM1), Imm32(addressMask)); - JMP((u8*)NDS::ARM9Read16, true); - } - else - JMP((u8*)NDS::ARM9Read8, true); - } - - SetJumpTarget(insideDTCM); - AND(32, R(RSCRATCH), Imm32(0x3FFF & addressMask)); - if (store) - MOV(size, MComplex(RCPU, RSCRATCH, SCALE_1, offsetof(ARMv5, DTCM)), R(ABI_PARAM2)); - else - { - MOVZX(32, size, RSCRATCH, MComplex(RCPU, RSCRATCH, SCALE_1, offsetof(ARMv5, DTCM))); - if (size == 32) - { - if (ABI_PARAM1 != ECX) - MOV(32, R(ECX), R(ABI_PARAM1)); - AND(32, R(ECX), Imm8(3)); - SHL(32, R(ECX), Imm8(3)); - ROR_(32, R(RSCRATCH), R(ECX)); - } - } - RET(); + u32 translatedAddr = Num == 0 ? TranslateAddr9(addr) : TranslateAddr7(addr); - SetJumpTarget(insideITCM); - MOV(32, R(ABI_PARAM3), R(ABI_PARAM1)); // free up ECX - AND(32, R(ABI_PARAM3), Imm32(0x7FFF & addressMask)); - if (store) - { - MOV(size, MComplex(RCPU, ABI_PARAM3, SCALE_1, offsetof(ARMv5, ITCM)), R(ABI_PARAM2)); - - // if CodeRanges[pseudoPhysical/256].Blocks.Length > 0 we're writing into code! - static_assert(sizeof(AddressRange) == 16); - LEA(32, ABI_PARAM1, MDisp(ABI_PARAM3, ExeMemRegionOffsets[exeMem_ITCM])); - MOV(32, R(RSCRATCH), R(ABI_PARAM1)); - SHR(32, R(RSCRATCH), Imm8(9)); - SHL(32, R(RSCRATCH), Imm8(4)); - CMP(16, MDisp(RSCRATCH, squeezePointer(CodeRanges) + offsetof(AddressRange, Blocks.Length)), Imm8(0)); - FixupBranch noCode = J_CC(CC_Z); - JMP((u8*)InvalidateByAddr, true); - SetJumpTarget(noCode); - } - else + int invalidLiteralIdx = InvalidLiterals.Find(translatedAddr); + if (invalidLiteralIdx != -1) { - MOVZX(32, size, RSCRATCH, MComplex(RCPU, ABI_PARAM3, SCALE_1, offsetof(ARMv5, ITCM))); - if (size == 32) - { - if (ABI_PARAM1 != ECX) - MOV(32, R(ECX), R(ABI_PARAM1)); - AND(32, R(ECX), Imm8(3)); - SHL(32, R(ECX), Imm8(3)); - ROR_(32, R(RSCRATCH), R(ECX)); - } + InvalidLiterals.Remove(invalidLiteralIdx); + return false; } - RET(); - - static_assert(RSCRATCH == EAX, "Someone changed RSCRATCH!"); - - return res; -} - -#define MEMORY_SEQ_WHILE_COND \ - if (!store) \ - MOV(32, currentElement, R(EAX));\ - if (!preinc) \ - ADD(32, R(ABI_PARAM1), Imm8(4)); \ - \ - SUB(32, R(ABI_PARAM3), Imm8(1)); \ - J_CC(CC_NZ, repeat); - -/* - ABI_PARAM1 address - ABI_PARAM2 address where registers are stored - ABI_PARAM3 how many values to read/write - - Dolphin x64CodeEmitter is my favourite assembler - */ -void* Compiler::Gen_MemoryRoutineSeq9(bool store, bool preinc) -{ - void* res = (void*)GetWritableCodePtr(); - - const u8* repeat = GetCodePtr(); - - if (preinc) - ADD(32, R(ABI_PARAM1), Imm8(4)); - MOV(32, R(RSCRATCH), R(ABI_PARAM1)); - SUB(32, R(RSCRATCH), MDisp(RCPU, offsetof(ARMv5, DTCMBase))); - CMP(32, R(RSCRATCH), MDisp(RCPU, offsetof(ARMv5, DTCMSize))); - FixupBranch insideDTCM = J_CC(CC_B); - - CMP(32, R(ABI_PARAM1), MDisp(RCPU, offsetof(ARMv5, ITCMSize))); - FixupBranch insideITCM = J_CC(CC_B); - - OpArg currentElement = MComplex(ABI_PARAM2, ABI_PARAM3, SCALE_8, -8); // wasting stack space like a gangster - - ABI_PushRegistersAndAdjustStack({ABI_PARAM1, ABI_PARAM2, ABI_PARAM3}, 8); - AND(32, R(ABI_PARAM1), Imm8(~3)); - if (store) - { - MOV(32, R(ABI_PARAM2), currentElement); - CALL((void*)NDS::ARM9Write32); - } - else - CALL((void*)NDS::ARM9Read32); - ABI_PopRegistersAndAdjustStack({ABI_PARAM1, ABI_PARAM2, ABI_PARAM3}, 8); - - MEMORY_SEQ_WHILE_COND - RET(); - - SetJumpTarget(insideDTCM); - AND(32, R(RSCRATCH), Imm32(0x3FFF & ~3)); - if (store) - { - MOV(32, R(ABI_PARAM4), currentElement); - MOV(32, MComplex(RCPU, RSCRATCH, SCALE_1, offsetof(ARMv5, DTCM)), R(ABI_PARAM4)); - } - else - MOV(32, R(RSCRATCH), MComplex(RCPU, RSCRATCH, SCALE_1, offsetof(ARMv5, DTCM))); - - MEMORY_SEQ_WHILE_COND - RET(); - - SetJumpTarget(insideITCM); - MOV(32, R(RSCRATCH), R(ABI_PARAM1)); - AND(32, R(RSCRATCH), Imm32(0x7FFF & ~3)); - if (store) - { - MOV(32, R(ABI_PARAM4), currentElement); - MOV(32, MComplex(RCPU, RSCRATCH, SCALE_1, offsetof(ARMv5, ITCM)), R(ABI_PARAM4)); - - ADD(32, R(RSCRATCH), Imm32(ExeMemRegionOffsets[exeMem_ITCM])); - MOV(32, R(ABI_PARAM4), R(RSCRATCH)); - SHR(32, R(RSCRATCH), Imm8(9)); - SHL(32, R(RSCRATCH), Imm8(4)); - CMP(16, MDisp(RSCRATCH, squeezePointer(CodeRanges) + offsetof(AddressRange, Blocks.Length)), Imm8(0)); - FixupBranch noCode = J_CC(CC_Z); - ABI_PushRegistersAndAdjustStack({ABI_PARAM1, ABI_PARAM2, ABI_PARAM3}, 8); - MOV(32, R(ABI_PARAM1), R(ABI_PARAM4)); - CALL((u8*)InvalidateByAddr); - ABI_PopRegistersAndAdjustStack({ABI_PARAM1, ABI_PARAM2, ABI_PARAM3}, 8); - SetJumpTarget(noCode); - } - else - MOV(32, R(RSCRATCH), MComplex(RCPU, RSCRATCH, SCALE_1, offsetof(ARMv5, ITCM))); - - MEMORY_SEQ_WHILE_COND - RET(); - - return res; -} - -void* Compiler::Gen_MemoryRoutineSeq7(bool store, bool preinc, bool codeMainRAM) -{ - void* res = (void*)GetWritableCodePtr(); - - const u8* repeat = GetCodePtr(); - - if (preinc) - ADD(32, R(ABI_PARAM1), Imm8(4)); - - OpArg currentElement = MComplex(ABI_PARAM2, ABI_PARAM3, SCALE_8, -8); - - ABI_PushRegistersAndAdjustStack({ABI_PARAM1, ABI_PARAM2, ABI_PARAM3}, 8); - AND(32, R(ABI_PARAM1), Imm8(~3)); - if (store) - { - MOV(32, R(ABI_PARAM2), currentElement); - CALL((void*)NDS::ARM7Write32); - } - else - CALL((void*)NDS::ARM7Read32); - ABI_PopRegistersAndAdjustStack({ABI_PARAM1, ABI_PARAM2, ABI_PARAM3}, 8); - - MEMORY_SEQ_WHILE_COND - RET(); - - return res; -} - -#undef MEMORY_SEQ_WHILE_COND - -void Compiler::Comp_MemLoadLiteral(int size, int rd, u32 addr) -{ u32 val; // make sure arm7 bios is accessible u32 tmpR15 = CurCPU->R[15]; @@ -276,12 +57,10 @@ void Compiler::Comp_MemLoadLiteral(int size, int rd, u32 addr) RegCache.PutLiteral(rd, val); Comp_AddCycles_CDI(); + + return true; } -/*void fault(u32 a, u32 b, u32 c, u32 d) -{ - printf("actually not static! %x %x %x %x\n", a, b, c, d); -}*/ void Compiler::Comp_MemAccess(int rd, int rn, const ComplexOperand& op2, int size, int flags) { @@ -291,17 +70,12 @@ void Compiler::Comp_MemAccess(int rd, int rn, const ComplexOperand& op2, int siz if (size == 16) addressMask = ~1; - //bool check = false; if (Config::JIT_LiteralOptimisations && rn == 15 && rd != 15 && op2.IsImm && !(flags & (memop_SignExtend|memop_Post|memop_Store|memop_Writeback))) { u32 addr = R15 + op2.Imm * ((flags & memop_SubtractOffset) ? -1 : 1); - u32 translatedAddr = Num == 0 ? TranslateAddr<0>(addr) : TranslateAddr<1>(addr); - - if (!(CodeRanges[translatedAddr / 512].InvalidLiterals & (1 << ((translatedAddr & 0x1FF) / 16)))) - { - Comp_MemLoadLiteral(size, rd, addr); + + if (Comp_MemLoadLiteral(size, rd, addr)) return; - } } { @@ -314,173 +88,334 @@ void Compiler::Comp_MemAccess(int rd, int rn, const ComplexOperand& op2, int siz Comp_AddCycles_CDI(); } + bool addrIsStatic = Config::JIT_LiteralOptimisations + && RegCache.IsLiteral(rn) && op2.IsImm && !(flags & (memop_Writeback|memop_Post)); + u32 staticAddress; + if (addrIsStatic) + staticAddress = RegCache.LiteralValues[rn] + op2.Imm * ((flags & memop_SubtractOffset) ? -1 : 1); OpArg rdMapped = MapReg(rd); - OpArg rnMapped = MapReg(rn); - if (Thumb && rn == 15) - rnMapped = Imm32(R15 & ~0x2); - - bool inlinePreparation = Num == 1; - u32 constLocalROR32 = 4; - - void* memoryFunc = Num == 0 - ? MemoryFuncs9[size >> 4][!!(flags & memop_Store)] - : MemoryFuncs7[size >> 4][!!((flags & memop_Store))]; - if (Config::JIT_LiteralOptimisations && (rd != 15 || (flags & memop_Store)) && op2.IsImm && RegCache.IsLiteral(rn)) + if (!addrIsStatic) { - u32 addr = RegCache.LiteralValues[rn] + op2.Imm * ((flags & memop_SubtractOffset) ? -1 : 1); - - /*MOV(32, R(ABI_PARAM1), Imm32(CurInstr.Instr)); - MOV(32, R(ABI_PARAM1), Imm32(R15)); - MOV_sum(32, RSCRATCH, rnMapped, Imm32(op2.Imm * ((flags & memop_SubtractOffset) ? -1 : 1))); - CMP(32, R(RSCRATCH), Imm32(addr)); - FixupBranch eq = J_CC(CC_E); - CALL((void*)fault); - SetJumpTarget(eq);*/ - - NDS::MemRegion region; - region.Mem = NULL; - if (Num == 0) + OpArg rnMapped = MapReg(rn); + if (Thumb && rn == 15) + rnMapped = Imm32(R15 & ~0x2); + + X64Reg finalAddr = RSCRATCH3; + if (flags & memop_Post) { - ARMv5* cpu5 = (ARMv5*)CurCPU; + MOV(32, R(RSCRATCH3), rnMapped); - // stupid dtcm... - if (addr >= cpu5->DTCMBase && addr < (cpu5->DTCMBase + cpu5->DTCMSize)) - { - // disable this for now as DTCM is located in heap - // which might excced the RIP-addressable range - //region.Mem = cpu5->DTCM; - //region.Mask = 0x3FFF; - } - else - { - NDS::ARM9GetMemRegion(addr, flags & memop_Store, ®ion); - } + finalAddr = rnMapped.GetSimpleReg(); } - else - NDS::ARM7GetMemRegion(addr, flags & memop_Store, ®ion); - if (region.Mem != NULL) + if (op2.IsImm) + { + MOV_sum(32, finalAddr, rnMapped, Imm32(op2.Imm * ((flags & memop_SubtractOffset) ? -1 : 1))); + } + else { - void* ptr = ®ion.Mem[addr & addressMask & region.Mask]; + OpArg rm = MapReg(op2.Reg.Reg); - if (flags & memop_Store) + if (!(flags & memop_SubtractOffset) && rm.IsSimpleReg() && rnMapped.IsSimpleReg() + && op2.Reg.Op == 0 && op2.Reg.Amount > 0 && op2.Reg.Amount <= 3) { - MOV(size, M(ptr), MapReg(rd)); + LEA(32, finalAddr, + MComplex(rnMapped.GetSimpleReg(), rm.GetSimpleReg(), 1 << op2.Reg.Amount, 0)); } else { - if (flags & memop_SignExtend) - MOVSX(32, size, rdMapped.GetSimpleReg(), M(ptr)); - else - MOVZX(32, size, rdMapped.GetSimpleReg(), M(ptr)); + bool throwAway; + OpArg offset = + Comp_RegShiftImm(op2.Reg.Op, op2.Reg.Amount, rm, false, throwAway); - if (size == 32 && addr & ~0x3) + if (flags & memop_SubtractOffset) { - ROR_(32, rdMapped, Imm8((addr & 0x3) << 3)); + if (R(finalAddr) != rnMapped) + MOV(32, R(finalAddr), rnMapped); + if (!offset.IsZero()) + SUB(32, R(finalAddr), offset); } + else + MOV_sum(32, finalAddr, rnMapped, offset); } - - return; } - void* specialFunc = GetFuncForAddr(CurCPU, addr, flags & memop_Store, size); - if (specialFunc) - { - memoryFunc = specialFunc; - inlinePreparation = true; - constLocalROR32 = addr & 0x3; - } + if ((flags & memop_Writeback) && !(flags & memop_Post)) + MOV(32, rnMapped, R(finalAddr)); } - X64Reg finalAddr = ABI_PARAM1; - if (flags & memop_Post) - { - MOV(32, R(ABI_PARAM1), rnMapped); + int expectedTarget = Num == 0 + ? ClassifyAddress9(addrIsStatic ? staticAddress : CurInstr.DataRegion) + : ClassifyAddress7(addrIsStatic ? staticAddress : CurInstr.DataRegion); + if (CurInstr.Cond() < 0xE) + expectedTarget = memregion_Other; + + bool compileFastPath = false, compileSlowPath = !addrIsStatic || (flags & memop_Store); - finalAddr = rnMapped.GetSimpleReg(); + switch (expectedTarget) + { + case memregion_MainRAM: + case memregion_DTCM: + case memregion_WRAM7: + case memregion_SWRAM9: + case memregion_SWRAM7: + case memregion_IO9: + case memregion_IO7: + case memregion_VWRAM: + compileFastPath = true; + break; + case memregion_Wifi: + compileFastPath = size >= 16; + break; + case memregion_VRAM: + compileFastPath = !(flags & memop_Store) || size >= 16; + case memregion_BIOS9: + compileFastPath = !(flags & memop_Store); + break; + default: break; } - if (op2.IsImm) + if (addrIsStatic && !compileFastPath) { - MOV_sum(32, finalAddr, rnMapped, Imm32(op2.Imm * ((flags & memop_SubtractOffset) ? -1 : 1))); + compileFastPath = false; + compileSlowPath = true; } - else + + if (addrIsStatic && compileSlowPath) + MOV(32, R(RSCRATCH3), Imm32(staticAddress)); + + if (compileFastPath) { - OpArg rm = MapReg(op2.Reg.Reg); + FixupBranch slowPath; + if (compileSlowPath) + { + MOV(32, R(RSCRATCH), R(RSCRATCH3)); + SHR(32, R(RSCRATCH), Imm8(9)); + if (flags & memop_Store) + { + CMP(8, MDisp(RSCRATCH, squeezePointer(Num == 0 ? MemoryStatus9 : MemoryStatus7)), Imm8(expectedTarget)); + } + else + { + MOVZX(32, 8, RSCRATCH, MDisp(RSCRATCH, squeezePointer(Num == 0 ? MemoryStatus9 : MemoryStatus7))); + AND(32, R(RSCRATCH), Imm8(~0x80)); + CMP(32, R(RSCRATCH), Imm8(expectedTarget)); + } + + slowPath = J_CC(CC_NE, true); + } - if (!(flags & memop_SubtractOffset) && rm.IsSimpleReg() && rnMapped.IsSimpleReg() - && op2.Reg.Op == 0 && op2.Reg.Amount > 0 && op2.Reg.Amount <= 3) + if (expectedTarget == memregion_MainRAM || expectedTarget == memregion_WRAM7 + || expectedTarget == memregion_BIOS9) { - LEA(32, finalAddr, - MComplex(rnMapped.GetSimpleReg(), rm.GetSimpleReg(), 1 << op2.Reg.Amount, 0)); + u8* data; + u32 mask; + if (expectedTarget == memregion_MainRAM) + { + data = NDS::MainRAM; + mask = MAIN_RAM_SIZE - 1; + } + else if (expectedTarget == memregion_BIOS9) + { + data = NDS::ARM9BIOS; + mask = 0xFFF; + } + else + { + data = NDS::ARM7WRAM; + mask = 0xFFFF; + } + OpArg memLoc; + if (addrIsStatic) + { + memLoc = M(data + ((staticAddress & mask & addressMask))); + } + else + { + MOV(32, R(RSCRATCH), R(RSCRATCH3)); + AND(32, R(RSCRATCH), Imm32(mask & addressMask)); + memLoc = MDisp(RSCRATCH, squeezePointer(data)); + } + if (flags & memop_Store) + MOV(size, memLoc, rdMapped); + else if (flags & memop_SignExtend) + MOVSX(32, size, rdMapped.GetSimpleReg(), memLoc); + else + MOVZX(32, size, rdMapped.GetSimpleReg(), memLoc); } - else + else if (expectedTarget == memregion_DTCM) + { + if (addrIsStatic) + MOV(32, R(RSCRATCH), Imm32(staticAddress)); + else + MOV(32, R(RSCRATCH), R(RSCRATCH3)); + SUB(32, R(RSCRATCH), MDisp(RCPU, offsetof(ARMv5, DTCMBase))); + AND(32, R(RSCRATCH), Imm32(0x3FFF & addressMask)); + OpArg memLoc = MComplex(RCPU, RSCRATCH, SCALE_1, offsetof(ARMv5, DTCM)); + if (flags & memop_Store) + MOV(size, memLoc, rdMapped); + else if (flags & memop_SignExtend) + MOVSX(32, size, rdMapped.GetSimpleReg(), memLoc); + else + MOVZX(32, size, rdMapped.GetSimpleReg(), memLoc); + } + else if (expectedTarget == memregion_SWRAM9 || expectedTarget == memregion_SWRAM7) { - bool throwAway; - OpArg offset = - Comp_RegShiftImm(op2.Reg.Op, op2.Reg.Amount, rm, false, throwAway); - - if (flags & memop_SubtractOffset) + MOV(64, R(RSCRATCH2), M(expectedTarget == memregion_SWRAM9 ? &NDS::SWRAM_ARM9 : &NDS::SWRAM_ARM7)); + if (addrIsStatic) { - if (R(finalAddr) != rnMapped) - MOV(32, R(finalAddr), rnMapped); - if (!offset.IsZero()) - SUB(32, R(finalAddr), offset); + MOV(32, R(RSCRATCH), Imm32(staticAddress & addressMask)); } else - MOV_sum(32, finalAddr, rnMapped, offset); + { + MOV(32, R(RSCRATCH), R(RSCRATCH3)); + AND(32, R(RSCRATCH), Imm8(addressMask)); + } + AND(32, R(RSCRATCH), M(expectedTarget == memregion_SWRAM9 ? &NDS::SWRAM_ARM9Mask : &NDS::SWRAM_ARM7Mask)); + OpArg memLoc = MRegSum(RSCRATCH, RSCRATCH2); + if (flags & memop_Store) + MOV(size, memLoc, rdMapped); + else if (flags & memop_SignExtend) + MOVSX(32, size, rdMapped.GetSimpleReg(), memLoc); + else + MOVZX(32, size, rdMapped.GetSimpleReg(), memLoc); } - } + else + { + u32 maskedDataRegion; - if ((flags & memop_Writeback) && !(flags & memop_Post)) - MOV(32, rnMapped, R(finalAddr)); + if (addrIsStatic) + { + maskedDataRegion = staticAddress; + MOV(32, R(ABI_PARAM1), Imm32(staticAddress)); + } + else + { + if (ABI_PARAM1 != RSCRATCH3) + MOV(32, R(ABI_PARAM1), R(RSCRATCH3)); + AND(32, R(ABI_PARAM1), Imm8(addressMask)); - if (flags & memop_Store) - MOV(32, R(ABI_PARAM2), rdMapped); + maskedDataRegion = CurInstr.DataRegion; + if (Num == 0) + maskedDataRegion &= ~0xFFFFFF; + else + maskedDataRegion &= ~0x7FFFFF; + } - if (!(flags & memop_Store) && inlinePreparation && constLocalROR32 == 4 && size == 32) - MOV(32, rdMapped, R(ABI_PARAM1)); + void* func = GetFuncForAddr(CurCPU, maskedDataRegion, flags & memop_Store, size); - if (inlinePreparation && size > 8) - AND(32, R(ABI_PARAM1), Imm8(addressMask)); + if (flags & memop_Store) + { + MOV(32, R(ABI_PARAM2), rdMapped); - CALL(memoryFunc); + ABI_CallFunction((void(*)())func); + } + else + { + if (!addrIsStatic) + MOV(32, rdMapped, R(RSCRATCH3)); - /*if (Num == 0 && check) - { - CMP(32, R(EAX), rdMapped); - FixupBranch notEqual = J_CC(CC_E); - ABI_PushRegistersAndAdjustStack({RSCRATCH}, 0); - MOV(32, R(ABI_PARAM1), Imm32(R15 - (Thumb ? 4 : 8))); - MOV(32, R(ABI_PARAM2), R(EAX)); - MOV(32, R(ABI_PARAM3), rdMapped); - MOV(32, R(ABI_PARAM4), Imm32(CurInstr.Instr)); - CALL((u8*)fault); - ABI_PopRegistersAndAdjustStack({RSCRATCH}, 0); - SetJumpTarget(notEqual); - }*/ - - if (!(flags & memop_Store)) - { - if (inlinePreparation && size == 32) + ABI_CallFunction((void(*)())func); + + if (!addrIsStatic) + MOV(32, R(RSCRATCH3), rdMapped); + + if (flags & memop_SignExtend) + MOVSX(32, size, rdMapped.GetSimpleReg(), R(RSCRATCH)); + else + MOVZX(32, size, rdMapped.GetSimpleReg(), R(RSCRATCH)); + } + } + + if ((size == 32 && !(flags & memop_Store))) { - if (constLocalROR32 == 4) + if (addrIsStatic) + { + if (staticAddress & 0x3) + ROR_(32, rdMapped, Imm8((staticAddress & 0x3) * 8)); + } + else { - static_assert(RSCRATCH3 == ECX); - MOV(32, R(ECX), rdMapped); - AND(32, R(ECX), Imm8(3)); - SHL(32, R(ECX), Imm8(3)); - ROR_(32, R(RSCRATCH), R(ECX)); + AND(32, R(RSCRATCH3), Imm8(0x3)); + SHL(32, R(RSCRATCH3), Imm8(3)); + ROR_(32, rdMapped, R(RSCRATCH3)); } - else if (constLocalROR32 != 0) - ROR_(32, R(RSCRATCH), Imm8(constLocalROR32 << 3)); } - if (flags & memop_SignExtend) - MOVSX(32, size, rdMapped.GetSimpleReg(), R(RSCRATCH)); + if (compileSlowPath) + { + SwitchToFarCode(); + SetJumpTarget(slowPath); + } + } + + if (compileSlowPath) + { + if (Num == 0) + { + MOV(32, R(ABI_PARAM2), R(RSCRATCH3)); + MOV(64, R(ABI_PARAM1), R(RCPU)); + if (flags & memop_Store) + { + MOV(32, R(ABI_PARAM3), rdMapped); + + switch (size) + { + case 32: CALL((void*)&SlowWrite9); break; + case 16: CALL((void*)&SlowWrite9); break; + case 8: CALL((void*)&SlowWrite9); break; + } + } + else + { + switch (size) + { + case 32: CALL((void*)&SlowRead9); break; + case 16: CALL((void*)&SlowRead9); break; + case 8: CALL((void*)&SlowRead9); break; + } + } + } else - MOVZX(32, size, rdMapped.GetSimpleReg(), R(RSCRATCH)); + { + if (ABI_PARAM1 != RSCRATCH3) + MOV(32, R(ABI_PARAM1), R(RSCRATCH3)); + if (flags & memop_Store) + { + MOV(32, R(ABI_PARAM2), rdMapped); + + switch (size) + { + case 32: CALL((void*)&SlowWrite7); break; + case 16: CALL((void*)&SlowWrite7); break; + case 8: CALL((void*)&SlowWrite7); break; + } + } + else + { + switch (size) + { + case 32: CALL((void*)&SlowRead7); break; + case 16: CALL((void*)&SlowRead7); break; + case 8: CALL((void*)&SlowRead7); break; + } + } + } + if (!(flags & memop_Store)) + { + if (flags & memop_SignExtend) + MOVSX(32, size, rdMapped.GetSimpleReg(), R(RSCRATCH)); + else + MOVZX(32, size, rdMapped.GetSimpleReg(), R(RSCRATCH)); + } + } + + if (compileFastPath && compileSlowPath) + { + FixupBranch ret = J(true); + SwitchToNearCode(); + SetJumpTarget(ret); } if (!(flags & memop_Store) && rd == 15) @@ -498,100 +433,160 @@ void Compiler::Comp_MemAccess(int rd, int rn, const ComplexOperand& op2, int siz s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc, bool decrement, bool usermode) { - IrregularCycles = true; - int regsCount = regs.Count(); s32 offset = (regsCount * 4) * (decrement ? -1 : 1); // we need to make sure that the stack stays aligned to 16 bytes +#ifdef _WIN32 + // include shadow + u32 stackAlloc = ((regsCount + 4 + 1) & ~1) * 8; +#else u32 stackAlloc = ((regsCount + 1) & ~1) * 8; +#endif + u32 allocOffset = stackAlloc - regsCount * 8; - if (!store) + int expectedTarget = Num == 0 + ? ClassifyAddress9(CurInstr.DataRegion) + : ClassifyAddress7(CurInstr.DataRegion); + if (usermode || CurInstr.Cond() < 0xE) + expectedTarget = memregion_Other; + + bool compileFastPath = false; + + switch (expectedTarget) { + case memregion_DTCM: + case memregion_MainRAM: + case memregion_SWRAM9: + case memregion_SWRAM7: + case memregion_WRAM7: + compileFastPath = true; + break; + default: + break; + } + + if (!store) Comp_AddCycles_CDI(); + else + Comp_AddCycles_CD(); - if (decrement) + if (decrement) + { + MOV_sum(32, RSCRATCH4, MapReg(rn), Imm32(-regsCount * 4)); + preinc ^= true; + } + else + MOV(32, R(RSCRATCH4), MapReg(rn)); + + if (compileFastPath) + { + assert(!usermode); + + MOV(32, R(RSCRATCH), R(RSCRATCH4)); + SHR(32, R(RSCRATCH), Imm8(9)); + + if (store) { - MOV_sum(32, ABI_PARAM1, MapReg(rn), Imm32(-regsCount * 4)); - preinc ^= true; + CMP(8, MDisp(RSCRATCH, squeezePointer(Num == 0 ? MemoryStatus9 : MemoryStatus7)), Imm8(expectedTarget)); } else - MOV(32, R(ABI_PARAM1), MapReg(rn)); - - MOV(32, R(ABI_PARAM3), Imm32(regsCount)); - SUB(64, R(RSP), stackAlloc <= INT8_MAX ? Imm8(stackAlloc) : Imm32(stackAlloc)); - MOV(64, R(ABI_PARAM2), R(RSP)); - - CALL(Num == 0 - ? MemoryFuncsSeq9[0][preinc] - : MemoryFuncsSeq7[0][preinc][CodeRegion == 0x02]); + { + MOVZX(32, 8, RSCRATCH, MDisp(RSCRATCH, squeezePointer(Num == 0 ? MemoryStatus9 : MemoryStatus7))); + AND(32, R(RSCRATCH), Imm8(~0x80)); + CMP(32, R(RSCRATCH), Imm8(expectedTarget)); + } + FixupBranch slowPath = J_CC(CC_NE, true); - bool firstUserMode = true; - for (int reg = 15; reg >= 0; reg--) + if (expectedTarget == memregion_DTCM) { - if (regs[reg]) + SUB(32, R(RSCRATCH4), MDisp(RCPU, offsetof(ARMv5, DTCMBase))); + AND(32, R(RSCRATCH4), Imm32(0x3FFF & ~3)); + LEA(64, RSCRATCH4, MComplex(RCPU, RSCRATCH4, 1, offsetof(ARMv5, DTCM))); + } + else if (expectedTarget == memregion_MainRAM) + { + AND(32, R(RSCRATCH4), Imm32((MAIN_RAM_SIZE - 1) & ~3)); + ADD(64, R(RSCRATCH4), Imm32(squeezePointer(NDS::MainRAM))); + } + else if (expectedTarget == memregion_WRAM7) + { + AND(32, R(RSCRATCH4), Imm32(0xFFFF & ~3)); + ADD(64, R(RSCRATCH4), Imm32(squeezePointer(NDS::ARM7WRAM))); + } + else // SWRAM + { + AND(32, R(RSCRATCH4), Imm8(~3)); + AND(32, R(RSCRATCH4), M(expectedTarget == memregion_SWRAM9 ? &NDS::SWRAM_ARM9Mask : &NDS::SWRAM_ARM7Mask)); + ADD(64, R(RSCRATCH4), M(expectedTarget == memregion_SWRAM9 ? &NDS::SWRAM_ARM9 : &NDS::SWRAM_ARM7)); + } + u32 offset = 0; + for (int reg : regs) + { + if (preinc) + offset += 4; + OpArg mem = MDisp(RSCRATCH4, offset); + if (store) { - if (usermode && !regs[15] && reg >= 8 && reg < 15) + if (RegCache.LoadedRegs & (1 << reg)) { - if (firstUserMode) - { - MOV(32, R(RSCRATCH), R(RCPSR)); - AND(32, R(RSCRATCH), Imm8(0x1F)); - firstUserMode = false; - } - MOV(32, R(RSCRATCH2), Imm32(reg - 8)); - POP(RSCRATCH3); - CALL(WriteBanked); - FixupBranch sucessfulWritten = J_CC(CC_NC); - if (RegCache.Mapping[reg] != INVALID_REG) - MOV(32, R(RegCache.Mapping[reg]), R(RSCRATCH3)); - else - SaveReg(reg, RSCRATCH3); - SetJumpTarget(sucessfulWritten); + MOV(32, mem, MapReg(reg)); } - else if (RegCache.Mapping[reg] == INVALID_REG) + else { - assert(reg != 15); - - POP(RSCRATCH); - SaveReg(reg, RSCRATCH); + LoadReg(reg, RSCRATCH); + MOV(32, mem, R(RSCRATCH)); + } + } + else + { + if (RegCache.LoadedRegs & (1 << reg)) + { + MOV(32, MapReg(reg), mem); } else { - if (reg != 15) - RegCache.DirtyRegs |= (1 << reg); - POP(MapReg(reg).GetSimpleReg()); + MOV(32, R(RSCRATCH), mem); + SaveReg(reg, RSCRATCH); } } + if (!preinc) + offset += 4; } - if (regsCount & 1) - POP(RSCRATCH); + SwitchToFarCode(); + SetJumpTarget(slowPath); + } + + if (!store) + { + MOV(32, R(ABI_PARAM1), R(RSCRATCH4)); + MOV(32, R(ABI_PARAM3), Imm32(regsCount)); + SUB(64, R(RSP), stackAlloc <= INT8_MAX ? Imm8(stackAlloc) : Imm32(stackAlloc)); + if (allocOffset == 0) + MOV(64, R(ABI_PARAM2), R(RSP)); + else + LEA(64, ABI_PARAM2, MDisp(RSP, allocOffset)); + + if (Num == 0) + MOV(64, R(ABI_PARAM4), R(RCPU)); - if (regs[15]) + switch (Num * 2 | preinc) { - if (Num == 1) - { - if (Thumb) - OR(32, MapReg(15), Imm8(1)); - else - AND(32, MapReg(15), Imm8(0xFE)); - } - Comp_JumpTo(MapReg(15).GetSimpleReg(), usermode); + case 0: CALL((void*)&SlowBlockTransfer9); break; + case 1: CALL((void*)&SlowBlockTransfer9); break; + case 2: CALL((void*)&SlowBlockTransfer7); break; + case 3: CALL((void*)&SlowBlockTransfer7); break; } - } - else - { - Comp_AddCycles_CD(); - if (regsCount & 1) - PUSH(RSCRATCH); + if (allocOffset) + ADD(64, R(RSP), Imm8(allocOffset)); bool firstUserMode = true; for (int reg : regs) { - if (usermode && reg >= 8 && reg < 15) + if (usermode && !regs[15] && reg >= 8 && reg < 15) { if (firstUserMode) { @@ -599,43 +594,107 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc AND(32, R(RSCRATCH), Imm8(0x1F)); firstUserMode = false; } - if (RegCache.Mapping[reg] == INVALID_REG) - LoadReg(reg, RSCRATCH3); - else - MOV(32, R(RSCRATCH3), R(RegCache.Mapping[reg])); MOV(32, R(RSCRATCH2), Imm32(reg - 8)); - CALL(ReadBanked); - PUSH(RSCRATCH3); + POP(RSCRATCH3); + CALL(WriteBanked); + FixupBranch sucessfulWritten = J_CC(CC_NC); + if (RegCache.LoadedRegs & (1 << reg)) + MOV(32, R(RegCache.Mapping[reg]), R(RSCRATCH3)); + else + SaveReg(reg, RSCRATCH3); + SetJumpTarget(sucessfulWritten); } - else if (RegCache.Mapping[reg] == INVALID_REG) + else if (!(RegCache.LoadedRegs & (1 << reg))) { - LoadReg(reg, RSCRATCH); - PUSH(RSCRATCH); + assert(reg != 15); + + POP(RSCRATCH); + SaveReg(reg, RSCRATCH); } else { - PUSH(MapReg(reg).GetSimpleReg()); + POP(MapReg(reg).GetSimpleReg()); } } - - if (decrement) + } + else + { + bool firstUserMode = true; + for (int reg = 15; reg >= 0; reg--) { - MOV_sum(32, ABI_PARAM1, MapReg(rn), Imm32(-regsCount * 4)); - preinc ^= true; + if (regs[reg]) + { + if (usermode && reg >= 8 && reg < 15) + { + if (firstUserMode) + { + MOV(32, R(RSCRATCH), R(RCPSR)); + AND(32, R(RSCRATCH), Imm8(0x1F)); + firstUserMode = false; + } + if (RegCache.Mapping[reg] == INVALID_REG) + LoadReg(reg, RSCRATCH3); + else + MOV(32, R(RSCRATCH3), R(RegCache.Mapping[reg])); + MOV(32, R(RSCRATCH2), Imm32(reg - 8)); + CALL(ReadBanked); + PUSH(RSCRATCH3); + } + else if (!(RegCache.LoadedRegs & (1 << reg))) + { + LoadReg(reg, RSCRATCH); + PUSH(RSCRATCH); + } + else + { + PUSH(MapReg(reg).GetSimpleReg()); + } + } } - else - MOV(32, R(ABI_PARAM1), MapReg(rn)); - MOV(64, R(ABI_PARAM2), R(RSP)); + if (allocOffset) + SUB(64, R(RSP), Imm8(allocOffset)); + + MOV(32, R(ABI_PARAM1), R(RSCRATCH4)); + if (allocOffset) + LEA(64, ABI_PARAM2, MDisp(RSP, allocOffset)); + else + MOV(64, R(ABI_PARAM2), R(RSP)); + MOV(32, R(ABI_PARAM3), Imm32(regsCount)); + if (Num == 0) + MOV(64, R(ABI_PARAM4), R(RCPU)); - CALL(Num == 0 - ? MemoryFuncsSeq9[1][preinc] - : MemoryFuncsSeq7[1][preinc][CodeRegion == 0x02]); + switch (Num * 2 | preinc) + { + case 0: CALL((void*)&SlowBlockTransfer9); break; + case 1: CALL((void*)&SlowBlockTransfer9); break; + case 2: CALL((void*)&SlowBlockTransfer7); break; + case 3: CALL((void*)&SlowBlockTransfer7); break; + } ADD(64, R(RSP), stackAlloc <= INT8_MAX ? Imm8(stackAlloc) : Imm32(stackAlloc)); } + if (compileFastPath) + { + FixupBranch ret = J(true); + SwitchToNearCode(); + SetJumpTarget(ret); + } + + if (!store && regs[15]) + { + if (Num == 1) + { + if (Thumb) + OR(32, MapReg(15), Imm8(1)); + else + AND(32, MapReg(15), Imm8(0xFE)); + } + Comp_JumpTo(MapReg(15).GetSimpleReg(), usermode); + } + return offset; } @@ -786,9 +845,7 @@ void Compiler::T_Comp_LoadPCRel() { u32 offset = (CurInstr.Instr & 0xFF) << 2; u32 addr = (R15 & ~0x2) + offset; - if (Config::JIT_LiteralOptimisations) - Comp_MemLoadLiteral(32, CurInstr.T_Reg(8), addr); - else + if (!Config::JIT_LiteralOptimisations || !Comp_MemLoadLiteral(32, CurInstr.T_Reg(8), addr)) Comp_MemAccess(CurInstr.T_Reg(8), 15, ComplexOperand(offset), 32, 0); } diff --git a/src/ARM_InstrInfo.cpp b/src/ARM_InstrInfo.cpp index 28362d9..b50e821 100644 --- a/src/ARM_InstrInfo.cpp +++ b/src/ARM_InstrInfo.cpp @@ -373,16 +373,16 @@ Info Decode(bool thumb, u32 num, u32 instr) if (res.Kind == tk_LDMIA || res.Kind == tk_POP) { - u32 set = (instr & 0xFF) & ~(res.DstRegs|res.SrcRegs); - res.NotStrictlyNeeded |= set; + u32 set = (instr & 0xFF); + res.NotStrictlyNeeded |= set & ~(res.DstRegs|res.SrcRegs); res.DstRegs |= set; } if (res.Kind == tk_STMIA || res.Kind == tk_PUSH) { - u32 set = (instr & 0xFF) & ~(res.DstRegs|res.SrcRegs); + u32 set = (instr & 0xFF); if (res.Kind == tk_PUSH && instr & (1 << 8)) set |= (1 << 14); - res.NotStrictlyNeeded |= set; + res.NotStrictlyNeeded |= set & ~(res.DstRegs|res.SrcRegs); res.SrcRegs |= set; } @@ -495,15 +495,15 @@ Info Decode(bool thumb, u32 num, u32 instr) if (res.Kind == ak_LDM) { - u16 set = (instr & 0xFFFF) & ~(res.SrcRegs|res.DstRegs|(1<<15)); + u16 set = (instr & 0xFFFF); + res.NotStrictlyNeeded |= set & ~(res.SrcRegs|res.DstRegs|(1<<15)); res.DstRegs |= set; - res.NotStrictlyNeeded |= set; } if (res.Kind == ak_STM) { - u16 set = (instr & 0xFFFF) & ~(res.SrcRegs|res.DstRegs|(1<<15)); + u16 set = (instr & 0xFFFF); + res.NotStrictlyNeeded |= set & ~(res.SrcRegs|res.DstRegs|(1<<15)); res.SrcRegs |= set; - res.NotStrictlyNeeded |= set; } if ((instr >> 28) < 0xE) diff --git a/src/CP15.cpp b/src/CP15.cpp index ff8531c..225847e 100644 --- a/src/CP15.cpp +++ b/src/CP15.cpp @@ -98,6 +98,10 @@ void ARMv5::CP15DoSavestate(Savestate* file) void ARMv5::UpdateDTCMSetting() { +#ifdef JIT_ENABLED + u32 oldDTCMBase = DTCMBase; + u32 oldDTCMSize = DTCMSize; +#endif if (CP15Control & (1<<16)) { DTCMBase = DTCMSetting & 0xFFFFF000; @@ -110,10 +114,20 @@ void ARMv5::UpdateDTCMSetting() DTCMSize = 0; //printf("DTCM disabled\n"); } +#ifdef JIT_ENABLED + if (oldDTCMBase != DTCMBase || oldDTCMSize != DTCMSize) + { + ARMJIT::UpdateMemoryStatus9(oldDTCMBase, oldDTCMBase + oldDTCMSize); + ARMJIT::UpdateMemoryStatus9(DTCMBase, DTCMBase + DTCMSize); + } +#endif } void ARMv5::UpdateITCMSetting() { +#ifdef JIT_ENABLED + u32 oldITCMSize = ITCMSize; +#endif if (CP15Control & (1<<18)) { ITCMSize = 0x200 << ((ITCMSetting >> 1) & 0x1F); @@ -124,6 +138,10 @@ void ARMv5::UpdateITCMSetting() ITCMSize = 0; //printf("ITCM disabled\n"); } +#ifdef JIT_ENABLED + if (oldITCMSize != ITCMSize) + ARMJIT::UpdateMemoryStatus9(0, std::max(oldITCMSize, ITCMSize)); +#endif } @@ -562,15 +580,9 @@ void ARMv5::CP15Write(u32 id, u32 val) case 0x750: -#ifdef JIT_ENABLED - ARMJIT::InvalidateAll(); -#endif ICacheInvalidateAll(); return; case 0x751: -#ifdef JIT_ENABLED - ARMJIT::InvalidateByAddr(ARMJIT::TranslateAddr<0>(val)); -#endif ICacheInvalidateByAddr(val); return; case 0x752: @@ -733,7 +745,7 @@ u32 ARMv5::CodeRead32(u32 addr, bool branch) void ARMv5::DataRead8(u32 addr, u32* val) { - DataRegion = addr >> 12; + DataRegion = addr; if (addr < ITCMSize) { @@ -754,7 +766,7 @@ void ARMv5::DataRead8(u32 addr, u32* val) void ARMv5::DataRead16(u32 addr, u32* val) { - DataRegion = addr >> 12; + DataRegion = addr; addr &= ~1; @@ -777,7 +789,7 @@ void ARMv5::DataRead16(u32 addr, u32* val) void ARMv5::DataRead32(u32 addr, u32* val) { - DataRegion = addr >> 12; + DataRegion = addr; addr &= ~3; @@ -821,14 +833,14 @@ void ARMv5::DataRead32S(u32 addr, u32* val) void ARMv5::DataWrite8(u32 addr, u8 val) { - DataRegion = addr >> 12; + DataRegion = addr; if (addr < ITCMSize) { DataCycles = 1; *(u8*)&ITCM[addr & 0x7FFF] = val; #ifdef JIT_ENABLED - ARMJIT::InvalidateITCM(addr & 0x7FFF); + ARMJIT::InvalidateITCMIfNecessary(addr); #endif return; } @@ -845,7 +857,7 @@ void ARMv5::DataWrite8(u32 addr, u8 val) void ARMv5::DataWrite16(u32 addr, u16 val) { - DataRegion = addr >> 12; + DataRegion = addr; addr &= ~1; @@ -854,7 +866,7 @@ void ARMv5::DataWrite16(u32 addr, u16 val) DataCycles = 1; *(u16*)&ITCM[addr & 0x7FFF] = val; #ifdef JIT_ENABLED - ARMJIT::InvalidateITCM(addr & 0x7FFF); + ARMJIT::InvalidateITCMIfNecessary(addr); #endif return; } @@ -871,7 +883,7 @@ void ARMv5::DataWrite16(u32 addr, u16 val) void ARMv5::DataWrite32(u32 addr, u32 val) { - DataRegion = addr >> 12; + DataRegion = addr; addr &= ~3; @@ -880,7 +892,7 @@ void ARMv5::DataWrite32(u32 addr, u32 val) DataCycles = 1; *(u32*)&ITCM[addr & 0x7FFF] = val; #ifdef JIT_ENABLED - ARMJIT::InvalidateITCM(addr & 0x7FFF); + ARMJIT::InvalidateITCMIfNecessary(addr); #endif return; } @@ -904,7 +916,7 @@ void ARMv5::DataWrite32S(u32 addr, u32 val) DataCycles += 1; *(u32*)&ITCM[addr & 0x7FFF] = val; #ifdef JIT_ENABLED - ARMJIT::InvalidateITCM(addr & 0x7FFF); + ARMJIT::InvalidateITCMIfNecessary(addr); #endif return; } diff --git a/src/NDS.cpp b/src/NDS.cpp index 7b6a450..56e7566 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -574,10 +574,6 @@ void Reset() KeyCnt = 0; RCnt = 0; -#ifdef JIT_ENABLED - ARMJIT::ResetBlockCache(); -#endif - NDSCart::Reset(); GBACart::Reset(); GPU::Reset(); @@ -593,6 +589,10 @@ void Reset() } AREngine::Reset(); + +#ifdef JIT_ENABLED + ARMJIT::Reset(); +#endif } void Stop() @@ -1127,6 +1127,9 @@ void Halt() void MapSharedWRAM(u8 val) { + if (val == WRAMCnt) + return; + WRAMCnt = val; switch (WRAMCnt & 0x3) @@ -1159,6 +1162,11 @@ void MapSharedWRAM(u8 val) SWRAM_ARM7Mask = 0x7FFF; break; } + +#ifdef JIT_ENABLED + ARMJIT::UpdateMemoryStatus9(0x3000000, 0x3000000 + 0x1000000); + ARMJIT::UpdateMemoryStatus7(0x3000000, 0x3000000 + 0x1000000); +#endif } @@ -2020,11 +2028,17 @@ void ARM9Write8(u32 addr, u8 val) { case 0x02000000: *(u8*)&MainRAM[addr & MainRAMMask] = val; +#ifdef JIT_ENABLED + ARMJIT::InvalidateMainRAMIfNecessary(addr); +#endif return; case 0x03000000: if (SWRAM_ARM9) { +#ifdef JIT_ENABLED + ARMJIT::InvalidateSWRAM9IfNecessary(addr); +#endif *(u8*)&SWRAM_ARM9[addr & SWRAM_ARM9Mask] = val; } return; @@ -2070,11 +2084,17 @@ void ARM9Write16(u32 addr, u16 val) { case 0x02000000: *(u16*)&MainRAM[addr & MainRAMMask] = val; +#ifdef JIT_ENABLED + ARMJIT::InvalidateMainRAMIfNecessary(addr); +#endif return; case 0x03000000: if (SWRAM_ARM9) { +#ifdef JIT_ENABLED + ARMJIT::InvalidateSWRAM9IfNecessary(addr); +#endif *(u16*)&SWRAM_ARM9[addr & SWRAM_ARM9Mask] = val; } return; @@ -2095,7 +2115,12 @@ void ARM9Write16(u32 addr, u16 val) case 0x00200000: GPU::WriteVRAM_BBG(addr, val); return; case 0x00400000: GPU::WriteVRAM_AOBJ(addr, val); return; case 0x00600000: GPU::WriteVRAM_BOBJ(addr, val); return; - default: GPU::WriteVRAM_LCDC(addr, val); return; + default: +#ifdef JIT_ENABLED + ARMJIT::InvalidateLCDCIfNecessary(addr); +#endif + GPU::WriteVRAM_LCDC(addr, val); + return; } case 0x07000000: @@ -2136,11 +2161,17 @@ void ARM9Write32(u32 addr, u32 val) { case 0x02000000: *(u32*)&MainRAM[addr & MainRAMMask] = val; +#ifdef JIT_ENABLED + ARMJIT::InvalidateMainRAMIfNecessary(addr); +#endif return ; case 0x03000000: if (SWRAM_ARM9) { +#ifdef JIT_ENABLED + ARMJIT::InvalidateSWRAM9IfNecessary(addr); +#endif *(u32*)&SWRAM_ARM9[addr & SWRAM_ARM9Mask] = val; } return; @@ -2161,7 +2192,12 @@ void ARM9Write32(u32 addr, u32 val) case 0x00200000: GPU::WriteVRAM_BBG(addr, val); return; case 0x00400000: GPU::WriteVRAM_AOBJ(addr, val); return; case 0x00600000: GPU::WriteVRAM_BOBJ(addr, val); return; - default: GPU::WriteVRAM_LCDC(addr, val); return; + default: +#ifdef JIT_ENABLED + ARMJIT::InvalidateLCDCIfNecessary(addr); +#endif + GPU::WriteVRAM_LCDC(addr, val); + return; } case 0x07000000: @@ -2426,30 +2462,38 @@ u32 ARM7Read32(u32 addr) void ARM7Write8(u32 addr, u8 val) { -#ifdef JIT_ENABLED - ARMJIT::InvalidateByAddr7(addr); -#endif - switch (addr & 0xFF800000) { case 0x02000000: case 0x02800000: *(u8*)&MainRAM[addr & MainRAMMask] = val; +#ifdef JIT_ENABLED + ARMJIT::InvalidateMainRAMIfNecessary(addr); +#endif return; case 0x03000000: if (SWRAM_ARM7) { +#ifdef JIT_ENABLED + ARMJIT::InvalidateSWRAM7IfNecessary(addr); +#endif *(u8*)&SWRAM_ARM7[addr & SWRAM_ARM7Mask] = val; return; } else { +#ifdef JIT_ENABLED + ARMJIT::InvalidateARM7WRAMIfNecessary(addr); +#endif *(u8*)&ARM7WRAM[addr & 0xFFFF] = val; return; } case 0x03800000: +#ifdef JIT_ENABLED + ARMJIT::InvalidateARM7WRAMIfNecessary(addr); +#endif *(u8*)&ARM7WRAM[addr & 0xFFFF] = val; return; @@ -2459,6 +2503,9 @@ void ARM7Write8(u32 addr, u8 val) case 0x06000000: case 0x06800000: +#ifdef JIT_ENABLED + ARMJIT::InvalidateARM7WVRAMIfNecessary(addr); +#endif GPU::WriteVRAM_ARM7(addr, val); return; @@ -2489,30 +2536,38 @@ void ARM7Write8(u32 addr, u8 val) void ARM7Write16(u32 addr, u16 val) { -#ifdef JIT_ENABLED - ARMJIT::InvalidateByAddr7(addr); -#endif - switch (addr & 0xFF800000) { case 0x02000000: case 0x02800000: *(u16*)&MainRAM[addr & MainRAMMask] = val; +#ifdef JIT_ENABLED + ARMJIT::InvalidateMainRAMIfNecessary(addr); +#endif return; case 0x03000000: if (SWRAM_ARM7) { +#ifdef JIT_ENABLED + ARMJIT::InvalidateSWRAM7IfNecessary(addr); +#endif *(u16*)&SWRAM_ARM7[addr & SWRAM_ARM7Mask] = val; return; } else { +#ifdef JIT_ENABLED + ARMJIT::InvalidateARM7WRAMIfNecessary(addr); +#endif *(u16*)&ARM7WRAM[addr & 0xFFFF] = val; return; } case 0x03800000: +#ifdef JIT_ENABLED + ARMJIT::InvalidateARM7WRAMIfNecessary(addr); +#endif *(u16*)&ARM7WRAM[addr & 0xFFFF] = val; return; @@ -2530,6 +2585,9 @@ void ARM7Write16(u32 addr, u16 val) case 0x06000000: case 0x06800000: +#ifdef JIT_ENABLED + ARMJIT::InvalidateARM7WVRAMIfNecessary(addr); +#endif GPU::WriteVRAM_ARM7(addr, val); return; @@ -2562,30 +2620,38 @@ void ARM7Write16(u32 addr, u16 val) void ARM7Write32(u32 addr, u32 val) { -#ifdef JIT_ENABLED - ARMJIT::InvalidateByAddr7(addr); -#endif - switch (addr & 0xFF800000) { case 0x02000000: case 0x02800000: *(u32*)&MainRAM[addr & MainRAMMask] = val; +#ifdef JIT_ENABLED + ARMJIT::InvalidateMainRAMIfNecessary(addr); +#endif return; case 0x03000000: if (SWRAM_ARM7) { +#ifdef JIT_ENABLED + ARMJIT::InvalidateSWRAM7IfNecessary(addr); +#endif *(u32*)&SWRAM_ARM7[addr & SWRAM_ARM7Mask] = val; return; } else { +#ifdef JIT_ENABLED + ARMJIT::InvalidateARM7WRAMIfNecessary(addr); +#endif *(u32*)&ARM7WRAM[addr & 0xFFFF] = val; return; } case 0x03800000: +#ifdef JIT_ENABLED + ARMJIT::InvalidateARM7WRAMIfNecessary(addr); +#endif *(u32*)&ARM7WRAM[addr & 0xFFFF] = val; return; @@ -2604,6 +2670,9 @@ void ARM7Write32(u32 addr, u32 val) case 0x06000000: case 0x06800000: +#ifdef JIT_ENABLED + ARMJIT::InvalidateARM7WVRAMIfNecessary(addr); +#endif GPU::WriteVRAM_ARM7(addr, val); return; diff --git a/src/NDS.h b/src/NDS.h index 9c5fe3d..6eda658 100644 --- a/src/NDS.h +++ b/src/NDS.h @@ -80,7 +80,7 @@ enum IRQ_IPCSendDone, IRQ_IPCRecv, IRQ_CartSendDone, // TODO: less misleading name - IRQ_CartIREQMC, // IRQ triggered by game cart (example: Pokémon Typing Adventure, BT controller) + IRQ_CartIREQMC, // IRQ triggered by game cart (example: Pokďż˝mon Typing Adventure, BT controller) IRQ_GXFIFO, IRQ_LidOpen, IRQ_SPI, @@ -163,6 +163,13 @@ extern u16 ARM7BIOSProt; extern u8 MainRAM[0x1000000]; extern u32 MainRAMMask; +extern u8 SharedWRAM[0x8000]; +extern u8* SWRAM_ARM9; +extern u8* SWRAM_ARM7; +extern u32 SWRAM_ARM9Mask; +extern u32 SWRAM_ARM7Mask; + +extern u8 ARM7WRAM[0x10000]; extern u32 KeyInput; -- cgit v1.2.3 From 80b88dbd05a66ad50108778d5f36e17f5b1cd661 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sat, 9 May 2020 14:34:52 +0200 Subject: allow allocating caller saved registers currently system-v only --- src/ARMJIT_x64/ARMJIT_Branch.cpp | 19 ++---------- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 58 ++++++++++++++++++++++++++----------- src/ARMJIT_x64/ARMJIT_Compiler.h | 3 ++ src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 19 ++++++++++++ 4 files changed, 65 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/ARMJIT_x64/ARMJIT_Branch.cpp b/src/ARMJIT_x64/ARMJIT_Branch.cpp index cac590a..27c24c7 100644 --- a/src/ARMJIT_x64/ARMJIT_Branch.cpp +++ b/src/ARMJIT_x64/ARMJIT_Branch.cpp @@ -138,18 +138,7 @@ void Compiler::Comp_JumpTo(Gen::X64Reg addr, bool restoreCPSR) bool cpsrDirty = CPSRDirty; SaveCPSR(); - if (restoreCPSR) - { - if (Thumb || CurInstr.Cond() >= 0xE) - RegCache.Flush(); - else - { - // the ugly way... - // we only save them, to load and save them again - for (int reg : hiRegsLoaded) - SaveReg(reg, RegCache.Mapping[reg]); - } - } + PushRegs(restoreCPSR); MOV(64, R(ABI_PARAM1), R(RCPU)); MOV(32, R(ABI_PARAM2), R(addr)); @@ -162,11 +151,7 @@ void Compiler::Comp_JumpTo(Gen::X64Reg addr, bool restoreCPSR) else CALL((void*)&ARMv4::JumpTo); - if (!Thumb && restoreCPSR && CurInstr.Cond() < 0xE) - { - for (int reg : hiRegsLoaded) - LoadReg(reg, RegCache.Mapping[reg]); - } + PopRegs(restoreCPSR); LoadCPSR(); // in case this instruction is skipped diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index eee2e0f..ef04601 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -26,7 +26,8 @@ const X64Reg RegisterCache::NativeRegAllocOrder[] = #ifdef _WIN32 RBX, RSI, RDI, R12, R13, R14 #else - RBX, R12, R13, R14 // this is sad + RBX, R12, R13, R14, // callee saved, this is sad + R9, R10, R11, // caller saved #endif }; template <> @@ -34,10 +35,46 @@ const int RegisterCache::NativeRegsAvailable = #ifdef _WIN32 6 #else - 4 + 7 #endif ; +void Compiler::PushRegs(bool saveHiRegs) +{ + BitSet32 loadedRegs(RegCache.LoadedRegs); + + if (saveHiRegs) + { + BitSet32 hiRegsLoaded(RegCache.LoadedRegs & 0x7F00); + for (int reg : hiRegsLoaded) + { + if (Thumb || CurInstr.Cond() == 0xE) + RegCache.UnloadRegister(reg); + else + SaveReg(reg, RegCache.Mapping[reg]); + // prevent saving the register twice + loadedRegs[reg] = false; + } + } + + for (int reg : loadedRegs) + if (BitSet32(1 << RegCache.Mapping[reg]) & ABI_ALL_CALLER_SAVED) + SaveReg(reg, RegCache.Mapping[reg]); +} + +void Compiler::PopRegs(bool saveHiRegs) +{ + BitSet32 loadedRegs(RegCache.LoadedRegs); + for (int reg : loadedRegs) + { + if ((saveHiRegs && reg >= 8 && reg < 15) + || BitSet32(1 << RegCache.Mapping[reg]) & ABI_ALL_CALLER_SAVED) + { + LoadReg(reg, RegCache.Mapping[reg]); + } + } +} + void Compiler::A_Comp_MRS() { Comp_AddCycles_C(); @@ -136,27 +173,14 @@ void Compiler::A_Comp_MSR() AND(32, R(RSCRATCH2), val); OR(32, R(RCPSR), R(RSCRATCH2)); - BitSet16 hiRegsLoaded(RegCache.LoadedRegs & 0x7F00); - if (Thumb || CurInstr.Cond() >= 0xE) - RegCache.Flush(); - else - { - // the ugly way... - // we only save them, to load and save them again - for (int reg : hiRegsLoaded) - SaveReg(reg, RegCache.Mapping[reg]); - } + PushRegs(true); MOV(32, R(ABI_PARAM3), R(RCPSR)); MOV(32, R(ABI_PARAM2), R(RSCRATCH3)); MOV(64, R(ABI_PARAM1), R(RCPU)); CALL((void*)&ARM::UpdateMode); - if (!Thumb && CurInstr.Cond() < 0xE) - { - for (int reg : hiRegsLoaded) - LoadReg(reg, RegCache.Mapping[reg]); - } + PopRegs(true); } } } diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index 9df218b..f2fc301 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -168,6 +168,9 @@ public: Gen::FixupBranch CheckCondition(u32 cond); + void PushRegs(bool saveHiRegs); + void PopRegs(bool saveHiRegs); + Gen::OpArg MapReg(int reg) { if (reg == 15 && RegCache.Mapping[reg] == Gen::INVALID_REG) diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index c13b779..b27efdd 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -283,6 +283,8 @@ void Compiler::Comp_MemAccess(int rd, int rn, const ComplexOperand& op2, int siz } else { + PushRegs(false); + u32 maskedDataRegion; if (addrIsStatic) @@ -310,6 +312,8 @@ void Compiler::Comp_MemAccess(int rd, int rn, const ComplexOperand& op2, int siz MOV(32, R(ABI_PARAM2), rdMapped); ABI_CallFunction((void(*)())func); + + PopRegs(false); } else { @@ -318,6 +322,8 @@ void Compiler::Comp_MemAccess(int rd, int rn, const ComplexOperand& op2, int siz ABI_CallFunction((void(*)())func); + PopRegs(false); + if (!addrIsStatic) MOV(32, R(RSCRATCH3), rdMapped); @@ -352,6 +358,8 @@ void Compiler::Comp_MemAccess(int rd, int rn, const ComplexOperand& op2, int siz if (compileSlowPath) { + PushRegs(false); + if (Num == 0) { MOV(32, R(ABI_PARAM2), R(RSCRATCH3)); @@ -402,6 +410,9 @@ void Compiler::Comp_MemAccess(int rd, int rn, const ComplexOperand& op2, int siz } } } + + PopRegs(false); + if (!(flags & memop_Store)) { if (flags & memop_SignExtend) @@ -561,6 +572,8 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc if (!store) { + PushRegs(false); + MOV(32, R(ABI_PARAM1), R(RSCRATCH4)); MOV(32, R(ABI_PARAM3), Imm32(regsCount)); SUB(64, R(RSP), stackAlloc <= INT8_MAX ? Imm8(stackAlloc) : Imm32(stackAlloc)); @@ -580,6 +593,8 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc case 3: CALL((void*)&SlowBlockTransfer7); break; } + PopRegs(false); + if (allocOffset) ADD(64, R(RSP), Imm8(allocOffset)); @@ -655,6 +670,8 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc if (allocOffset) SUB(64, R(RSP), Imm8(allocOffset)); + PushRegs(false); + MOV(32, R(ABI_PARAM1), R(RSCRATCH4)); if (allocOffset) LEA(64, ABI_PARAM2, MDisp(RSP, allocOffset)); @@ -674,6 +691,8 @@ s32 Compiler::Comp_MemAccessBlock(int rn, BitSet16 regs, bool store, bool preinc } ADD(64, R(RSP), stackAlloc <= INT8_MAX ? Imm8(stackAlloc) : Imm32(stackAlloc)); + + PopRegs(false); } if (compileFastPath) -- cgit v1.2.3 From efb796640b6b4c140dd8e2924e740702d66e7823 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sat, 9 May 2020 14:36:18 +0200 Subject: use instr hash as key for restore candidates makes Golden Sun burn a little slower through the JIT memory --- src/ARMJIT.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 9602aed..8d87c76 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -1042,13 +1042,13 @@ void CompileBlock(ARM* cpu) u32 literalHash = (u32)XXH3_64bits(literalValues, numLiterals * 4); u32 instrHash = (u32)XXH3_64bits(instrValues, i * 4); - JitBlock* prevBlock = RestoreCandidates.LookUp(pseudoPhysicalAddr); + JitBlock* prevBlock = RestoreCandidates.LookUp(instrHash); bool mayRestore = true; if (prevBlock) { - RestoreCandidates.Remove(pseudoPhysicalAddr); + RestoreCandidates.Remove(instrHash); - mayRestore = prevBlock->LiteralHash == literalHash && prevBlock->InstrHash == instrHash; + mayRestore = prevBlock->PseudoPhysicalAddr == pseudoPhysicalAddr && prevBlock->LiteralHash == literalHash; if (mayRestore && prevBlock->NumAddresses == numAddressRanges) { @@ -1125,6 +1125,7 @@ void CompileBlock(ARM* cpu) void InvalidateByAddr(u32 pseudoPhysical) { JIT_DEBUGPRINT("invalidating by addr %x\n", pseudoPhysical); + AddressRange* range = &CodeRanges[pseudoPhysical / 512]; u32 mask = 1 << ((pseudoPhysical & 0x1FF) / 16); @@ -1203,7 +1204,7 @@ void InvalidateByAddr(u32 pseudoPhysical) if (!literalInvalidation) { - JitBlock* prevBlock = RestoreCandidates.Insert(block->PseudoPhysicalAddr, block); + JitBlock* prevBlock = RestoreCandidates.Insert(block->InstrHash, block); if (prevBlock) delete prevBlock; } -- cgit v1.2.3 From c17f7b100e36edb1c728dbf21c77f9484d1820c6 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sat, 9 May 2020 15:39:39 +0200 Subject: allow allocating caller saved regs on windows --- src/ARMJIT_x64/ARMJIT_Compiler.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.cpp b/src/ARMJIT_x64/ARMJIT_Compiler.cpp index ef04601..fd3fb70 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_x64/ARMJIT_Compiler.cpp @@ -24,7 +24,8 @@ template <> const X64Reg RegisterCache::NativeRegAllocOrder[] = { #ifdef _WIN32 - RBX, RSI, RDI, R12, R13, R14 + RBX, RSI, RDI, R12, R13, R14, // callee saved + R10, R11, // caller saved #else RBX, R12, R13, R14, // callee saved, this is sad R9, R10, R11, // caller saved @@ -33,7 +34,7 @@ const X64Reg RegisterCache::NativeRegAllocOrder[] = template <> const int RegisterCache::NativeRegsAvailable = #ifdef _WIN32 - 6 + 8 #else 7 #endif -- cgit v1.2.3