diff options
-rw-r--r-- | backends/platform/dc/dc.h | 2 | ||||
-rw-r--r-- | backends/platform/dc/dcmain.cpp | 87 |
2 files changed, 89 insertions, 0 deletions
diff --git a/backends/platform/dc/dc.h b/backends/platform/dc/dc.h index c31328f3f6..adb1af7ba7 100644 --- a/backends/platform/dc/dc.h +++ b/backends/platform/dc/dc.h @@ -242,6 +242,8 @@ class OSystem_Dreamcast : private DCHardware, public BaseBackend, public Filesys Common::SeekableReadStream *createConfigReadStream(); Common::WriteStream *createConfigWriteStream(); + + Common::String getSystemLanguage() const; }; diff --git a/backends/platform/dc/dcmain.cpp b/backends/platform/dc/dcmain.cpp index 22a5f6b767..8c9cf56a56 100644 --- a/backends/platform/dc/dcmain.cpp +++ b/backends/platform/dc/dcmain.cpp @@ -219,6 +219,93 @@ Common::WriteStream *OSystem_Dreamcast::createConfigWriteStream() { return 0; } +namespace DC_Flash { + static int syscall_info_flash(int sect, int *info) + { + return (*(int (**)(int, void*, int, int))0x8c0000b8)(sect,info,0,0); + } + + static int syscall_read_flash(int offs, void *buf, int cnt) + { + return (*(int (**)(int, void*, int, int))0x8c0000b8)(offs,buf,cnt,1); + } + + static int flash_crc(const char *buf, int size) + { + int i, c, n = -1; + for(i=0; i<size; i++) { + n ^= (buf[i]<<8); + for(c=0; c<8; c++) + if(n & 0x8000) + n = (n << 1) ^ 4129; + else + n <<= 1; + } + return (unsigned short)~n; + } + + static int flash_read_sector(int partition, int sec, unsigned char *dst) + { + int s, r, n, b, bmb, got=0; + int info[2]; + char buf[64]; + char bm[64]; + + if((r = syscall_info_flash(partition, info))<0) + return r; + + if((r = syscall_read_flash(info[0], buf, 64))<0) + return r; + + if(memcmp(buf, "KATANA_FLASH", 12) || + buf[16] != partition || buf[17] != 0) + return -2; + + n = (info[1]>>6)-1-((info[1] + 0x7fff)>>15); + bmb = n+1; + for(b = 0; b < n; b++) { + if(!(b&511)) { + if((r = syscall_read_flash(info[0] + (bmb++ << 6), bm, 64))<0) + return r; + } + if(!(bm[(b>>3)&63] & (0x80>>(b&7)))) + if((r = syscall_read_flash(info[0] + ((b+1) << 6), buf, 64))<0) + return r; + else if((s=*(unsigned short *)(buf+0)) == sec && + flash_crc(buf, 62) == *(unsigned short *)(buf+62)) { + memcpy(dst+(s-sec)*60, buf+2, 60); + got=1; + } + } + return got; + } + + static int get_locale_setting() + { + unsigned char data[60]; + if (flash_read_sector(2,5,data) == 1) + return data[5]; + else + return -1; + } +}; + +Common::String OSystem_Dreamcast::getSystemLanguage() const { + static const char *languages[] = { + "ja_JP", + "en_US", + "de_DE", + "fr_FR", + "es_ES", + "it_IT" + }; + int l = DC_Flash::get_locale_setting(); + if (l<0 || l>=sizeof(languages)/sizeof(languages[0])) + l = 1; + return Common::String(languages[l]); +} + + void DCHardware::dc_init_hardware() { #ifndef NOSERIAL |