Sharp PC-G850VS
|
02-22-2021, 09:28 PM
(This post was last modified: 07-08-2022 02:52 PM by robve.)
Post: #141
|
|||
|
|||
RE: Sharp PC-G850VS
(02-22-2021 12:26 AM)Eddie W. Shore Wrote: Does anyone know how to find the integer or fractional part in the C programming module? Perhaps this is useful I spent some time today to map the math BASIC functions to C for the G850(V)(S). To use this code, enter the macros and functions (or only the ones you need) with line numbers (use A to auto number) in a new file basic.h on the G850(V)(S). Then add #include "basic.h" in your C program: /* C equivalents of BASIC math functions - Dr. Robert van Engelen */ /* Written in compact form to save space, using fp (double) and li (long) */ /* WARNING: <,<=,>,>= on floats have a bug on some G850's, instead of x<y use x-y<0 */ /* Functions do not perform any range validity checking on argument values */ /* INT() and FIX() arguments should be in range -2147483648 to 2147483647 */ /* Note that ABS(x) takes a double, whereas abs(n) takes an int */ /* Note that li (long) values must be displayed with printf("%ld",n); */ /* License: BSD-3 open source */ #define fp double #define li long #define ACS acos #define AHC acosh #define AHS asinh #define AHT atanh #define ASN asin #define ATN atan #define COS cos #define EXP exp #define LN log #define LOG log10 #define PI 3.141592654 #define RCP 1./ #define SIN sin #define SQR sqrt #define TAN tan fp ABS(fp x){return x<0?-x:x;} fp CUB(fp x){return x*x*x;} fp CUR(fp x){return pow(x,1./3);} fp FACT(li n){fp x=1;while(n>1)x*=n--;return x;} li FIX(fp x){return x;} li INT(fp x){return x<0?x-.9999999999:x;} li NCR(li n,li k){li i=1,j=0;if(k>n-k)k=n-k;while(++j<=k)i*=n-k+j,i/=j;return i;} li NPR(li n,li k){li i=1;k=n-k;while(++k<=n)i*=k;return i;} fp POL(fp x,fp y,fp*z){*z=x>0?atan(y/x):y?asin(y<0?-1:1)-atan(x/y):acos(-(x<0));return sqrt(x*x+y*y);} fp REC(fp x,fp y,fp*z){*z=x*sin(y);return x*cos(y);} li SGN(fp x){return x<0?-1:!!x;} fp SQU(fp x){return x*x;} fp TEN(x){return pow(10,x);} /* 0<RND(0)<1 gives double float result */ /* 0<RND(n)<=ceil(n) for n>=1 gives integer result */ /* RND(-n)==n new PRNG seed n */ fp RND(fp x) { static unsigned li s=5323; if (x<0) return s=-x; s=8253729*s+2396403; return x<1 ? (s%32767+1)/32768. : (li)(s%32767*x)/32767+1; } Most of the math functions available in BASIC are already defined in C, but the ones that are missing are defined in this code. Note that the code is very terse to keep it as small as possible. Every punctuation character is significant! Best is to load the code with bas2img and bin2wav over the CE-126P cassette interface (see my earlier post) or directly via RS232. I also found that the PC-G850(V)(S) user guide has some omissions, such as beep(x,y,z) which is the same BEEP command as in BASIC which works if you have a piezo buzzer installed. Also the ternary operators (?:) and the comma operator (,) are not mentioned, and there are a couple of minor mistakes. Disclaimer: I tested this code extensively and found no bugs. But I cannot offer any warranty. I may post a set of C math functions that are missing on the G850(V)(S). Suggestions and contributions are welcome! - Rob "I count on old friends to remain rational" |
|||
02-22-2021, 10:29 PM
Post: #142
|
|||
|
|||
RE: Sharp PC-G850VS
(02-22-2021 02:53 AM)robve Wrote: That is not true IMHO. The C compiler/interpreter has the same math functions as BASIC offers, but no more than that, because there is no <math.h> you can #include. However, you can define your own .h file (e.g. math.h) with extra functions that you often use and save it to the file system. Then simply #include "math.h". This is quite surprising, but thanks for insights on the additional C function support for the built-in BASIC functions. I recall he told me there was a certain entire class of functions that were not provided, which I took to mean something like 'all the trig Fns', 'all the Stats Fns', etc. but perhaps he merely meant that basic functions such as you've provided in your 2nd post, which can be easily assembled from available core functions, were not provided? Also, ROM space limits was a factor (it always is!) so best to spend ROM space on the much more difficult transcendental functions. In fact, maybe another reason these were not provided for students learning C on this machine was to leave these exact Functions as a challenge to be built in C, as you've done here. It appears you pass!! Also, thanks for providing the templates. Useful themselves but also good illustrative examples. --Bob Prosperi |
|||
02-23-2021, 04:03 AM
(This post was last modified: 07-08-2022 02:52 PM by robve.)
Post: #143
|
|||
|
|||
RE: Sharp PC-G850VS
(02-22-2021 10:29 PM)rprosperi Wrote: This is quite surprising, but thanks for insights on the additional C function support for the built-in BASIC functions. I recall he told me there was a certain entire class of functions that were not provided, which I took to mean something like 'all the trig Fns', 'all the Stats Fns', etc. but perhaps he merely meant that basic functions such as you've provided in your 2nd post, which can be easily assembled from available core functions, were not provided? Also, ROM space limits was a factor (it always is!) so best to spend ROM space on the much more difficult transcendental functions. Very good points! I should add that most students learning C typically do not need any of the advanced math functions. They spend a lot of time on other things, like getting to grips with the concept of C pointers to build data structures (or depending what PL you like best). It might be useful to reproduce most of the math.h functions for the PC-G850(V)(S), even if it is just an exercise. This is a professional calculator forum after all The C math functions are carefully crafted to prevent catastrophic cancellation, roundoff, and overflow issues. These issues are not for beginners. Entire books have been written on this subject. Here is my attempt at reproducing the math.h functions and constants for the PC-G850(V)(S). EDIT: added new functions atan2, fmod, erf, erfc, tgamma, and lgamma with everything tested and verified: /* math.h for the PC-G850(V)(S) - Dr. Robert van Engelen */ /* Written in compact form to save space */ /* WARNING: <,<=,>,>= on floats have a bug on some G850's, instead of x<y use x-y<0 */ /* Note: erf and erfc precision is at least 1.2e-7 (erfcc) */ /* Note: lgamma and tgamma precision is at least 2e-10 (Lanczos) */ /* License: BSD-3 open source */ #define M_E 2.718281828 #define M_LOG2E 1.366512921 #define M_LOG10E .4342944819 #define M_LN2 .693147181 #define M_LN10 2.302585093 #define M_PI 3.141592654 #define M_PI_2 1.570796327 #define M_PI_4 .7853981634 #define M_1_PI .3183098862 #define M_2_PI .6366197724 #define M_2_SQRTPI 1.128379167 #define M_SQRT2 1.414213562 #define M_SQRT1_2 .7071067812 double fabs(double x){return x<0?-x:x;} double copysign(double x,double y){return y<0?-fabs(x):fabs(x);} double log2(double x){return log(x)/M_LN2;} double exp2(double x){return exp(M_LN2*x);} double cbrt(double x){return pow(x,1./3);} double floor(double x){return fabs(x)-1e9<0?x<0?(long)(x-.9999999999):(long)x:x;} double ceil(double x){return -floor(-x);} double trunc(double x){return fabs(x)-1e9<0?(long)x:x;} double round(double x){return floor(x+.5);} double modf(double x,double*y){return x-(*y=fabs(x)-1e9<0?x-(long)x:0);} double fdim(double x,double y){return x-y>0?x-y:0;} double fmax(double x,double y){return x-y>0?x:y;} double fmin(double x,double y){return x-y<0?x:y;} double hypot(double x,double y){double a=fabs(x),b=fabs(y);return a?b?a-b<0?b*sqrt(1+x/y*x/y):a*sqrt(1+y/x*y/x):a:b;} double atan2(double y,double x){return x>0?atan(y/x):y?asin(y<0?-1:1)-atan(x/y):acos(-(x<0));} double fmod(double x,double y){return x-y*trunc(x/y);} double erfc(double x){double p=1/(1+fabs(x)/2),q=-.18628806+p*(.27886807+p*(-1.13520398+p*(1.4885187+p*(-.82215223+p*.17087277))));p*=exp(-x*x-1.26551223+p*(1.00002368+p*(.37409196+p*(.09678418+p*q))));return x<0?2-p: p;} double erf(double x){return 1-erfc(x);} double lgamma(double x){return log((1+76.18009173/(x+1)-86.50532033/(x+2)+24.01409824/(x+3)-1.231739572/(x+4)+1.208650974e-3/(x+5)-5.395239385e-6/(x+6))*2.506628275/x)+(x+.5)*log(x+5.5)-x-5.5;} double tgamma(double x){return exp(lgamma(x));} Note that hypot avoids catastrophic overflow by rearranging terms. Macros are used only if the argument(s) is/are guaranteed to be evaluated just once in the macro body. This avoids the common problem with calls like fmax(x++,y++) that fail as a macro. Otherwise, I tried to be as efficient as possible. Unlike the BASIC INT() function posted earlier, the floor(), ceil(), trunc(), round(), and modf() all work on unlimited doubles by using the fact that a long integer can hold up to 9 digits and G850(V)(S) doubles have 10 digit mantissas. This means that values >=1e9 have no fractional part. I used this observation to trick the code to check for |x|<1e9 which means the value has a fraction and can use a long cast in that case to obtain the integer part, otherwise just return the value unchanged. If you spot an issue or an opportunity for further optimization then let us know! - Rob EDIT: replaced #defines with functions and added warning. "I count on old friends to remain rational" |
|||
06-03-2021, 05:30 PM
Post: #144
|
|||
|
|||
RE: Sharp PC-G850VS
I just picked up a G850V, and am loving it for C programming. Thank you Rob for the wonderful condensed basic.h and math.h.
I'm not finding many limitations with the device at all, but it is a system where you have to do pretty much everything yourself. Not a lot of built-ins, but I'm finding myself very pleased with the C implementation. Next up, assembly/machine code! The only thing that I have found as a bit of a limitation is that if you are using a function that's defined in an #include'd file, if you use the trace mode, you can't step line by line through the code. So debug whatever you want to use as an #include first. Also in the debug mode, sometimes it's difficult to get at the data you want to see, I sometimes jump over to the MON mode to examine memory, but then, unfortunately you lose your runtime state. Anyways it's tons of fun. Happy hacking everyone! |
|||
06-06-2021, 07:45 PM
(This post was last modified: 06-18-2021 05:47 PM by robve.)
Post: #145
|
|||
|
|||
RE: Sharp PC-G850VS
(06-03-2021 05:30 PM)silven Wrote: Happy hacking everyone! Happy to help with "hacking" on the PC-G850V A dragon curve C code "hack" that is pleasing to the eye on the small screen and to show how fast this machine can be to draw graphics: Code: const char SIN[4]={0,2,0,-2}, COS[4]={2,0,-2,0}; Enter a positive integer between 1 and 10, such as 8. Note: larger values are OK, but will produce off-screen graphics. Edit: change 2 and -2 to 1 and -1 in the SIN[4] and COS[4] tables to produce smaller graphics that fit larger dragon curves on the screen. One tiny issue that the PC-G850 manual does not mention is that local variables can only be declared in a function block, not in other {...} blocks. There is also no typedef, but #define works just as well. Other than these two minor limitations, this little machine is fun to "hack" some C and Z80 assembly code together. - Rob "I count on old friends to remain rational" |
|||
06-07-2021, 05:00 PM
Post: #146
|
|||
|
|||
RE: Sharp PC-G850VS
(06-06-2021 07:45 PM)robve Wrote: A dragon curve C code "hack" that is pleasing to the eye on the small screen and to show how fast this machine can be to draw graphics: What a beautiful little piece of code! I'm just working on a command interpreter and simple csv based database for information collection on the go, and generally just having fun with having such a versatile environment that's so handy. Do you have a solution for getting data in and out? I'm considering either hacking something together with a breadboard and an ftdi module or springing for one of those premade cables or a printer. zmc |
|||
06-07-2021, 09:30 PM
Post: #147
|
|||
|
|||
RE: Sharp PC-G850VS
(06-07-2021 05:00 PM)silven Wrote: Do you have a solution for getting data in and out? I'm considering either hacking something together with a breadboard and an ftdi module or springing for one of those premade cables or a printer. SIO with FTDI. I assume you've read section "USB PC Adapter Cable with Hardware Handshake" with DIY instructions. Watch the UART-TTL signal levels of the PC-G850V. DIY SIO/PIO is best. To store data on an SD card, see the excellent video by A Menadue: https://www.youtube.com/watch?v=HhB2_JjCkgk By contrast, I've not had much luck with USB RS232 adapters and SHARP level converters (e.g. CE-T800 and CE-T801 for the PC-G850V or CE-130T for other SHARP). The adapters don't reach the required voltage levels for the SHARP level converters. A DIY works, but there is a small risk of ruining the device if something goes wrong. Adding some diodes and resistors to avoid shorts is a good idea. Then in C just open the SIO with fopen("stdaux", "rw") for half duplex or fopen("stdaux1", "rw") for full duplex mode with "rw" for reading and/or writing. Note that "a+" in the manual should mention "append to a file", not "input and output". - Rob "I count on old friends to remain rational" |
|||
06-08-2021, 12:37 PM
Post: #148
|
|||
|
|||
RE: Sharp PC-G850VS
The Sharp cables CE-132T and 133T tend to work with more devices than the very early 130T.
The 132T uses an external ac adapter, so less flexible, but it is less dependent on power from the connected device. The 133T is standalone, but in some cases cannot self-power from the connection. Here's a cheap 133T for anyone looking for an Sharp 15-pin serial adapter: https://www.ebay.com/itm/133672149943 --Bob Prosperi |
|||
06-08-2021, 05:18 PM
(This post was last modified: 06-12-2021 01:21 AM by robve.)
Post: #149
|
|||
|
|||
RE: Sharp PC-G850VS
(06-08-2021 12:37 PM)rprosperi Wrote: The Sharp cables CE-132T and 133T tend to work with more devices than the very early 130T. Caveat lector+emptor: I also tried a CE-133T with no luck. The CE-132T could work since it's externally powered, but I don't know for sure. Note that the CE-133T requires +/-7V input signal at minimum and +/-15V max (see the operating manual). Unfortunately, most USB RS-232C adapters offered online won't spec out the level or mention boosting. I got two USB adapters. One boosts the level to 6V, which is still insufficient. A DIY adapter is out of the question for me, because I don't want to take the risk of ruining these 80s computers. If anyone is interested, a DIY 15-pin adapter is described here https://www.qsl.net/yt2fsg/pocket/pocket.html and here https://www.simon-lehmayr.de/e_pc.htm (click on PC-1350 then "Connections" at the top of the screen). EDIT: please note that these adapters will NOT work with the PC-G850V but with older SHARP PC with a 15pin port! For details see https://sharppocketcomputers.com/#level - Rob "I count on old friends to remain rational" |
|||
06-09-2021, 02:18 AM
Post: #150
|
|||
|
|||
RE: Sharp PC-G850VS
(06-08-2021 05:18 PM)robve Wrote: The CE-132T could work since it's externally powered, but I don't know for sure. I believe I still have a CE-132T - if you'd like, I'll loan it to you to see if it works, which would then at least identify something that folks could safely use, even if they are a bit hard to find these days. Contact me by email if you're interested - I'm only an hour from the city, it may even be possible to meet somewhere in the middle. --Bob Prosperi |
|||
06-11-2021, 07:35 AM
Post: #151
|
|||
|
|||
RE: Sharp PC-G850VS
(12-18-2020 07:48 PM)robve Wrote: The PC-G850 can be nicely used as a calculator, albeit in BASIC, which is cumbersome. Thanks so much !!! I have just discovered this calc and I love it. It is even better now. |
|||
06-16-2021, 11:26 PM
Post: #152
|
|||
|
|||
RE: Sharp PC-G850VS
(06-07-2021 09:30 PM)robve Wrote:(06-07-2021 05:00 PM)silven Wrote: Do you have a solution for getting data in and out? So I got an FTDI cable and was able to reflash it to use the inverted signals that the 850 uses. I can send information to the 850 just fine, but when I want to send from the 850 to my PC it blocks and sends nothing. I'm guessing that it has something to do with flow control. My ftdi cables doesn't break out lines for CTS/RTS, so I just disabled flow control, but it looks like its waiting for something. I'm betting it's something as simple as applying 5v to CD or something like that, but I don't want to start tossing 5V randomly at those pins for fear of breaking something. Any input would be much appreciated. zmc |
|||
06-19-2021, 03:40 PM
Post: #153
|
|||
|
|||
RE: Sharp PC-G850VS
(06-16-2021 11:26 PM)silven Wrote: So I got an FTDI cable and was able to reflash it to use the inverted signals that the 850 uses. I can send information to the 850 just fine, but when I want to send from the 850 to my PC it blocks and sends nothing. Some years ago there was a discussion about a DIY adapter on the French forum silicium.org. A summary of this discussion was made available as a pdf file. See the attachment. I don't own this adapter, and I have not tried to make it, so I can't help on this subject, but maybe you will find some useful information in this document. Jean-Charles |
|||
07-12-2021, 07:11 PM
Post: #154
|
|||
|
|||
RE: Sharp PC-G850VS
(06-19-2021 03:40 PM)Helix Wrote: Some years ago there was a discussion about a DIY adapter on the French forum silicium.org. A summary of this discussion was made available as a pdf file. See the attachment. If it helps, I just found another DIY adapter on a Japanese web site (Google translate to the rescue). This one is based on the ADM232A and uses a standard RS232 male 9 pin connector, not USB: http://park19.wakwak.com/~gadget_factory...s232c.html Here is some interesting info on the G850V UART registers (in Japanese): http://ver0.sakura.ne.jp/doc/pcg850vuart.html Disclaimer: I have not tried this DIY RS232 level converter/adapter. - Rob "I count on old friends to remain rational" |
|||
02-01-2022, 01:37 PM
Post: #155
|
|||
|
|||
RE: Sharp PC-G850VS
RE: serial adapter:
RTS&CTS on the G850 must be shortened and pulled to 5V with 1K resistor to circumvent handshake. Disabling flow control in text editor SIO/Format does not suffice. I built a WiFi adapter to conenct to PC via netcat on linux or putty on Windows, in case this is of interest, feel free to ping me. details here Cheers |
|||
02-02-2022, 02:00 AM
Post: #156
|
|||
|
|||
RE: Sharp PC-G850VS
(02-01-2022 01:37 PM)chrisherman Wrote: RE: serial adapter: I really like this concept! A couple of weeks ago I saw a bluetooth dongle for the PC-G850, PC-E500, PC-1360, PC-1600 based on the RN42 chip: http://www.silicium.org/forum/viewtopic....24&t=47098 I hope a future version of the WiFi adapter will have the ability to sleep when inactive, or turn off, to reduce power draw. - Rob "I count on old friends to remain rational" |
|||
02-02-2022, 03:01 AM
Post: #157
|
|||
|
|||
RE: Sharp PC-G850VS
(02-01-2022 01:37 PM)chrisherman Wrote: RE: serial adapter: I wonder if that's the same problem I'm having with the PC-1360 and PC-E500... I attempt to transmit data using the CE-133T, and the machine just hangs like it's waiting for something until I kill it with the break key. I'll dig out a couple 1K resistors and play around with my RS-232 tester/breakout adapter. (Granted, I can only easily poke around on the 12V side.) |
|||
02-02-2022, 01:22 PM
Post: #158
|
|||
|
|||
RE: Sharp PC-G850VS
@Dave - Though I don't know for sure, it's likely that this is indeed the same issue, as the E500 and the G850V are really the same family internally, and these things tended to be implemented the same way. And when these were initially developed, hardware handshake lines were commonly used with RTS/CTS, etc. and you need either cables with all the lines, or fake them with pull-ups, etc.
--Bob Prosperi |
|||
02-02-2022, 10:59 PM
(This post was last modified: 02-15-2022 09:20 PM by chrisherman.)
Post: #159
|
|||
|
|||
RE: Sharp PC-G850VS
(02-02-2022 03:01 AM)Dave Britten Wrote:(02-01-2022 01:37 PM)chrisherman Wrote: RE: serial adapter: For the WiFI dongle: Sleep function, status LED, basic "AT" commands and slightly smaller form-factor are WIP. <<apologies if I say something that is already well established - I'm new to this community>> You can build a simple "G850 to USB" adapter with just an Arduino Nano and a Breadboard. The nano is great becaus it does 5V TTL logic. (You can use pretty much any Arduino, even 3.3V devices when you build a voltage divider for the TX signal that comes from the G850. I connect a 3.3V pin to the G850's RX pin and it works reliably for quite a while now. ). Use "softserial" - it does the inverted logic and in my github repository is a very simple sketch that send everything from the softserial rx pin to the serial port (i.e. to the USB port) and vice versa. BTW further up someone posted a concern about ordering G850s from japan: I've bought 3 by now (all G850V or G850VS, because the display is better than the G850's). My experience has been excellent (via ebay). All extremely well packaged and arrived within 2 weeks in (very) good condition (UK). missing lines on the display are fixable (watch Hey Birt's video). So can only recommend. ++++++++++ update: sleep, AT-commands and a smaller form-factor version are now published at https://simplestuffmatters.com/sharp-pc-...al-module/ and https://github.com/chrisherman/G850_RawT...al_Adapter |
|||
04-11-2022, 08:32 PM
Post: #160
|
|||
|
|||
RE: Sharp PC-G850VS
I just found this thread and what a joy it’s been to read through. I just dusted off my G850V in order to explore it’s C. Like others on this thread I’m impressed, it’s a much more capable machine than the Casio VX-4. And quite fast as well.
The only thing I miss in C as a random number call, but I’ll try the one posted on this thread. The other thing I can’t get working is the “void angle(void)” call. It just says Syntax Error. Does anyone know how to put a C program in to Radians when it runs? |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 13 Guest(s)