How do I make a port of MicroPython for Casio calculators?

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Zezombye
Posts: 33
Joined: Mon Jul 30, 2018 8:29 pm

Re: How do I make a port of MicroPython for Casio calculators?

Post by Zezombye » Sat Dec 01, 2018 5:30 am

No, it's the string "from xxx import *":

Code: Select all

			char str[30];
			char filename[13];
			strcpy(filename, _sFile);
			filename[strlen(filename)-3] = '\0';
			
			sprintf(str, "from %s import *\r", filename);
			
			for (int k = 0; str[k]; k++) {
				str[k] = tolower2(str[k]);
			}
			
			_iAppMode = SHELL;
			
			mpy_main(str);
The actual text of the script is then retrieved by MPy with the import statement.

Now, the REPL calls the function mp_hal_stdout_tx_strn(const char *str, mp_uint_t len), which is just a wrapper for shell_print(str, len). The problem is simply that it sends char by char, and I have to update the display char by char (because I don't know when the string actually ends).

If I ignore the "len" argument and stop printing when I hit a \0, I can see that it actually sends strings, but with len=1. For example, printing "abcd" gives "abcdbcdcdd".

jickster
Posts: 546
Joined: Thu Sep 07, 2017 8:57 pm

Re: How do I make a port of MicroPython for Casio calculators?

Post by jickster » Sun Dec 02, 2018 3:45 am

Why and how have you refactored the py code?

You’re sending the first line into pyexec_friendly_repl() though that function is normally void.

If this is part of a script why are you using REPL functions?



Sent from my iPhone using Tapatalk Pro

Zezombye
Posts: 33
Joined: Mon Jul 30, 2018 8:29 pm

Re: How do I make a port of MicroPython for Casio calculators?

Post by Zezombye » Sun Dec 02, 2018 6:32 am

I refactored that because it was a simple way to automatically send the string "from xxx import *" to the shell.

So pyexec_friendly_repl(char *text), through a bunch of ifs, ultimately calls int readline(vstr_t *line, const char *prompt, char *text), which is the following function:

Code: Select all

int readline_index = 0;

int readline(vstr_t *line, const char *prompt, char *text) {
    readline_init(line, prompt);
	
	if (text != NULL) {
		for (;text[readline_index] != 0;) {
			int r;
			if (text[readline_index] != 0x0C) {
				if (text[readline_index] == '\n') {
					r = readline_process_char('\r');
				} else {
					r = readline_process_char(text[readline_index]);
				}
				readline_index++;
			} else {
				r = readline_process_char('\r');
				readline_index++;
			}
			if (r >= 0) {
				return r;
			}
		}
	}
	
    for (;;) {
		char str[45] = {0};
		
		if (waitForKey(str) == KEY_CTRL_EXIT) {
			return -KEY_CTRL_EXIT;
		}
		
		int charsAfterCursorCounter = 0;
		char countCharsAfterCursor = 0;
		
		for (int i = 0; str[i]; i++) {
			int c = str[i];
			
			if (c == '\a') {
				countCharsAfterCursor = 1;
			} else {
				
				if (countCharsAfterCursor) {
					charsAfterCursorCounter++;
				}
				
				int r = readline_process_char(c);
				if (r >= 0) {
					return r;
				}
			}
		}
		for (int i = 0; i < charsAfterCursorCounter; i++) {
			readline_process_char(CHAR_LEFT);
		}
    }
}
Basically: readline_index is the position in the sent text.
If readline_index is less than the length of the text, print the character of the text; else, listen for keys and print the string they send.

Though it's not a problem with readline; the REPL behaved that way since the very beginning, when I only overrode the mp_hal_stdout_tx_strn function to display to the screen. So my refactoring isn't the cause of this behavior, it's by default in MPy.

User avatar
boochow
Posts: 22
Joined: Sat Dec 16, 2017 9:36 am

Re: How do I make a port of MicroPython for Casio calculators?

Post by boochow » Tue Dec 04, 2018 7:55 am

FYI
CASIO releases MicroPython for fx-CG50 (Japanese version)

https://web.casio.jp/dentaku/fxcg50/python.html

Zezombye
Posts: 33
Joined: Mon Jul 30, 2018 8:29 pm

Re: How do I make a port of MicroPython for Casio calculators?

Post by Zezombye » Tue Dec 04, 2018 4:48 pm

Yeah, I knew about this port - in fact Casio not releasing MPy for monochrome calcs is why I'm doing this port myself :p

Shame they used the big font though, you could fit much more letters in the screen.

Post Reply