From 55157640c577a0cb22bf85d37295be53bf7f7cac Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Sun, 27 May 2018 15:14:04 +0200 Subject: [PATCH] New ML support - czech version is working!!! postbuild.sh, make_lang.sh - fixed (id and offset calculation) language.c, language.h - fixed (==||==) config.h - reserved space for _SEC_LANG changed Marlin_main.cpp - debug output + hardcoded lang_select(1) //means cz --- Firmware/Marlin_main.cpp | 14 +++++++++++++- Firmware/config.h | 3 ++- Firmware/language.c | 18 +++++++++++++++--- Firmware/language.h | 1 + lang/make_lang.sh | 28 ++++++++++++++++------------ lang/postbuild.sh | 2 +- 6 files changed, 48 insertions(+), 18 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 8e479799..13d5b82b 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1263,13 +1263,25 @@ void setup() /// if (lang_selected >= LANG_NUM){ /// lcd_mylang(); /// } - lang_select(0); + lang_select(1); puts_P(_n("\nNew ML support")); printf_P(_n(" lang_selected = %d\n"), lang_selected); printf_P(_n(" &_SEC_LANG = 0x%04x\n"), &_SEC_LANG); printf_P(_n(" sizeof(_SEC_LANG) = 0x%04x\n"), sizeof(_SEC_LANG)); uint16_t ptr_lang_table0 = ((uint16_t)(&_SEC_LANG) + 0xff) & 0xff00; printf_P(_n(" &_lang_table0 = 0x%04x\n"), ptr_lang_table0); + uint32_t _lt_magic = pgm_read_dword(((uint32_t*)(ptr_lang_table0 + 0))); + uint16_t _lt_size = pgm_read_word(((uint16_t*)(ptr_lang_table0 + 4))); + uint16_t _lt_count = pgm_read_word(((uint16_t*)(ptr_lang_table0 + 6))); + uint16_t _lt_chsum = pgm_read_word(((uint16_t*)(ptr_lang_table0 + 8))); + uint16_t _lt_resv0 = pgm_read_word(((uint16_t*)(ptr_lang_table0 + 10))); + uint32_t _lt_resv1 = pgm_read_dword(((uint32_t*)(ptr_lang_table0 + 12))); + printf_P(_n(" _lt_magic = 0x%08lx %S\n"), _lt_magic, (_lt_magic==0x4bb45aa5)?_n("OK"):_n("NA")); + printf_P(_n(" _lt_size = 0x%04x (%d)\n"), _lt_size, _lt_size); + printf_P(_n(" _lt_count = 0x%04x (%d)\n"), _lt_count, _lt_count); + printf_P(_n(" _lt_chsum = 0x%04x\n"), _lt_chsum); + printf_P(_n(" _lt_resv0 = 0x%04x\n"), _lt_resv0); + printf_P(_n(" _lt_resv1 = 0x%08lx\n"), _lt_resv1); puts_P(_n("\n")); diff --git a/Firmware/config.h b/Firmware/config.h index a90cad5a..6839dd17 100644 --- a/Firmware/config.h +++ b/Firmware/config.h @@ -21,7 +21,8 @@ //LANG - Multi-language support //#define LANG_MODE 0 // primary language only #define LANG_MODE 1 // sec. language support -#define LANG_SIZE_RESERVED 0x2800 // reserved space for secondary language (10kb) +#define LANG_SIZE_RESERVED 0x2700 // reserved space for secondary language (~10kb) +//#define LANG_SIZE_RESERVED 0x1ef8 // reserved space for secondary language (~10kb) #endif //_CONFIG_H diff --git a/Firmware/language.c b/Firmware/language.c index a7f38fd1..78512f18 100644 --- a/Firmware/language.c +++ b/Firmware/language.c @@ -39,7 +39,19 @@ const char* lang_get_translation(const char* s) uint16_t ui = pgm_read_word(((uint16_t*)s)); //read string id if (ui == 0xffff) return s + 2; //translation not found ui = pgm_read_word(((uint16_t*)(((char*)lang_table + 16 + ui*2)))); //read relative offset - return (const char*)((char*)lang_table + ui + 16); //return calculated pointer + return (const char*)((char*)lang_table + ui); //return calculated pointer +} + +const char* lang_get_sec_lang_str(const char* s) +{ + uint16_t ui = (uint16_t)&_SEC_LANG; //pointer to _SEC_LANG reserved space + ui += 0x00ff; //add 1 page + ui &= 0xff00; //align to page + lang_table_t* _lang_table = ui; //table pointer + ui = pgm_read_word(((uint16_t*)s)); //read string id + if (ui == 0xffff) return s + 2; //translation not found + ui = pgm_read_word(((uint16_t*)(((char*)_lang_table + 16 + ui*2)))); //read relative offset + return (const char*)((char*)_lang_table + ui); //return calculated pointer } const char* lang_select(unsigned char lang) @@ -54,10 +66,10 @@ const char* lang_select(unsigned char lang) return; } uint16_t ui = (uint16_t)&_SEC_LANG; //pointer to _SEC_LANG reserved space - ui += 0x0100; //add 1 page + ui += 0x00ff; //add 1 page ui &= 0xff00; //align to page lang_table = ui; //set table pointer ui = pgm_read_word(((uint16_t*)(((char*)lang_table + 16)))); //read relative offset of first string (language name) - return (const char*)((char*)lang_table + ui + 16); //return calculated pointer + return (const char*)((char*)lang_table + ui); //return calculated pointer #endif //(LANG_MODE == 0) } \ No newline at end of file diff --git a/Firmware/language.h b/Firmware/language.h index fbd3ecde..193fcda2 100644 --- a/Firmware/language.h +++ b/Firmware/language.h @@ -70,6 +70,7 @@ extern const char _SEC_LANG[LANG_SIZE_RESERVED]; #endif //(LANG_MODE == 0) extern const char* lang_get_translation(const char* s); +extern const char* lang_get_sec_lang_str(const char* s); extern const char* lang_select(unsigned char lang); #if defined(__cplusplus) diff --git a/lang/make_lang.sh b/lang/make_lang.sh index 976269c9..11a3dd51 100644 --- a/lang/make_lang.sh +++ b/lang/make_lang.sh @@ -78,21 +78,22 @@ cat lang_$LANG.txt | sed "s/\\\\/\\\\\\\\/g" | while read s; do done >lang_$LANG.dat echo "OK" >&2 -#generate lang_xx.ofs (secondary language text data offset table) -echo -n " generating lang_$LANG.ofs..." >&2 -cat lang_$LANG.txt | sed "s/\\\\x[0-9a-f][0-9a-f]/\./g;s/\\\\[0-7][0-7][0-7]/\./g" |\ - awk 'BEGIN { o=0;} { printf("%d\n",o); o+=(length($0)-1); }' > lang_$LANG.ofs -echo "OK" >&2 - -lt_data_size=$(wc -c lang_$LANG.dat | cut -f1 -d' ') - +#calculate variables lt_magic='\xa5\x5a\xb4\x4b' lt_count=$(grep -c '^' lang_$LANG.txt) -lt_size=$((16 + 2 * $lt_count + $lt_data_size)) +lt_data_size=$(wc -c lang_$LANG.dat | cut -f1 -d' ') +lt_offs_size=$((2 * $lt_count)) +lt_size=$((16 + $lt_offs_size + $lt_data_size)) lt_chsum=1 lt_resv0='\xff\xff' lt_resv1='\xff\xff\xff\xff' +#generate lang_xx.ofs (secondary language text data offset table) +echo -n " generating lang_$LANG.ofs..." >&2 +cat lang_$LANG.txt | sed "s/\\\\x[0-9a-f][0-9a-f]/\./g;s/\\\\[0-7][0-7][0-7]/\./g" |\ + awk 'BEGIN { o='$((16 + $lt_offs_size))';} { printf("%d\n",o); o+=(length($0)-1); }' > lang_$LANG.ofs +echo "OK" >&2 + #generate lang_xx.bin (secondary language result binary file) echo " generating lang_$LANG.bin:" >&2 #create empty file @@ -117,13 +118,13 @@ echo -n -e "$lt_resv1" |\ dd of=lang_$LANG.bin bs=1 count=4 seek=12 conv=notrunc 2>/dev/null echo "OK" >&2 -echo -n " writing offset table ($((2 * $lt_count)) bytes)..." >&2 +echo -n " writing offset table ($lt_offs_size bytes)..." >&2 echo -n -e $(cat lang_$LANG.ofs | awk "$awk_ui16" | tr -d '\n'; echo) |\ - dd of=./lang_$LANG.bin bs=1 count=$((2 * $lt_count)) seek=16 conv=notrunc 2>/dev/null + dd of=./lang_$LANG.bin bs=1 count=$lt_offs_size seek=16 conv=notrunc 2>/dev/null echo "OK" >&2 echo -n " writing text data ($lt_data_size bytes)..." >&2 -dd if=./lang_$LANG.dat of=./lang_$LANG.bin bs=1 count=$lt_data_size seek=$((16 + 2 * $lt_count)) conv=notrunc 2>/dev/null +dd if=./lang_$LANG.dat of=./lang_$LANG.bin bs=1 count=$lt_data_size seek=$((16 + $lt_offs_size)) conv=notrunc 2>/dev/null echo "OK" >&2 echo " lang_table details:" >&2 @@ -132,3 +133,6 @@ echo " lt_size = $lt_size" >&2 echo " lt_chsum = $lt_chsum" >&2 finish 0 + + + diff --git a/lang/postbuild.sh b/lang/postbuild.sh index 0bdab8ad..b24bc67d 100644 --- a/lang/postbuild.sh +++ b/lang/postbuild.sh @@ -81,7 +81,7 @@ echo " updating binary:" >&2 #update progmem1 id entries in binary file echo -n " primary language ids..." >&2 cat textaddr.txt | grep "^ADDR OK" | cut -f3- -d' ' | sed "s/^0000/0x/" |\ - awk '{ hi = int($2 / 256); lo = int($2 - 256 * hi); printf("%d \\\\x%02x\\\\x%02x\n", strtonum($1), lo, hi); }' |\ + awk '{ id = $2 - 1; hi = int(id / 256); lo = int(id - 256 * hi); printf("%d \\\\x%02x\\\\x%02x\n", strtonum($1), lo, hi); }' |\ while read addr data; do echo -n -e $data | dd of=./firmware.bin bs=1 count=2 seek=$addr conv=notrunc oflag=nonblock 2>/dev/null done