Sharp PCG850VS

02222021, 09:28 PM
Post: #141




RE: Sharp PCG850VS
(02222021 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) */ /* 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: BSD3 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(x) (1./(x)) #define SIN sin #define SQR sqrt #define TAN tan #define TEN(x) pow(10,(x)) 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>nk)k=nk;while(++j<=k)i*=nk+j,i/=j;return i;} li NPR(li n,li k){li i=1;k=nk;while(++k<=n)i*=k;return i;} fp POL(fp x,fp y,fp*z){*z=!y?acos(x<0?1:!!x):x>0?atan(y/x):asin(y<0?1:1)atan(x/y);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;} /* 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 CE126P cassette interface (see my earlier post) or directly via RS232. I also found that the PCG850(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 HP 71B,Prime G2;Ti VOY200,Nspire CXII CAS;Casio fxCG50;Sharp PCG850VS,E500S,1475,1450,1403,1360,1350,2500,1262,1500A 

02222021, 10:29 PM
Post: #142




RE: Sharp PCG850VS
(02222021 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 builtin 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 

02232021, 04:03 AM
(This post was last modified: 02242021 12:16 AM by robve.)
Post: #143




RE: Sharp PCG850VS
(02222021 10:29 PM)rprosperi Wrote: This is quite surprising, but thanks for insights on the additional C function support for the builtin 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 PCG850(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 PCG850(V)(S). EDIT: added new functions atan2, fmod, erf, erfc, tgamma, and lgamma with everything tested and verified: /* math.h  PCG850(V)(S)  Dr. Robert van Engelen */ /* Written in compact form to save space */ /* Note: erf and erfc precision is at least 1.2e7 (erfcc) */ /* Note: lgamma and tgamma precision is at least 2e10 (Lanczos) */ /* License: BSD3 open source */ #define M_E 2.718281828 #define M_LOG2E 1.366512921 #define M_LOG10E .434294481 #define M_LN2 .69314718 #define M_LN10 2.302585093 #define M_PI 3.141592654 #define M_PI_2 1.570796327 #define M_PI_4 .785398163 #define M_1_PI .318309886 #define M_2_PI .636619772 #define M_2_SQRTPI 1.128379167 #define M_SQRT2 1.414213562 #define M_SQRT1_2 .707106781 #define copysign(x,y) ((y)<0?fabs((x)):fabs((x))) #define log2(x) (log((x))/M_LN2) #define exp2(x) (exp(M_LN2*(x))) #define cbrt(x) (pow((x),1/.3)) double fabs(double x){return x<0?x:x;} double floor(double x){return fabs(x)<1e9?x<0?(long)(x.9999999999):(long)x:x;} double ceil(double x){return fabs(x)<1e9?x>0?(long)(x.9999999999):(long)x:x;} double trunc(double x){return fabs(x)<1e9?(long)x:x;} double round(double x){return fabs(x)<1e9?x<0?(long)(x.4999999999):(long)(x+.5):x;} double modf(double x,double*y){return x(*y=fabs(x)<1e9?x(long)x:0);} double fdim(double x,double y){return x>y?xy:0;} double fmax(double x,double y){return x>y?x:y;} double fmin(double x,double y){return x<y?x:y;} double hypot(double x,double y){double a=fabs(x),b=fabs(y);return a?b?a<b?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 xy*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*x1.26551223+p*(1.00002368+p*(.37409196+p*(.09678418+p*q))));return x<0?2p: p;} double erf(double x){return 1erfc(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.208650974e3/(x+5)5.395239385e6/(x+6))*2.506628275/x)+(x+.5)*log(x+5.5)x5.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 HP 71B,Prime G2;Ti VOY200,Nspire CXII CAS;Casio fxCG50;Sharp PCG850VS,E500S,1475,1450,1403,1360,1350,2500,1262,1500A 

06032021, 05:30 PM
Post: #144




RE: Sharp PCG850VS
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 builtins, 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! 

06062021, 07:45 PM
(This post was last modified: 06182021 05:47 PM by robve.)
Post: #145




RE: Sharp PCG850VS
(06032021 05:30 PM)silven Wrote: Happy hacking everyone! Happy to help with "hacking" on the PCG850V 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 offscreen 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 PCG850 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 HP 71B,Prime G2;Ti VOY200,Nspire CXII CAS;Casio fxCG50;Sharp PCG850VS,E500S,1475,1450,1403,1360,1350,2500,1262,1500A 

06072021, 05:00 PM
Post: #146




RE: Sharp PCG850VS
(06062021 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 

06072021, 09:30 PM
Post: #147




RE: Sharp PCG850VS
(06072021 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 UARTTTL signal levels of the PCG850V. 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. CET800 and CET801 for the PCG850V or CE130T 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 HP 71B,Prime G2;Ti VOY200,Nspire CXII CAS;Casio fxCG50;Sharp PCG850VS,E500S,1475,1450,1403,1360,1350,2500,1262,1500A 

06082021, 12:37 PM
Post: #148




RE: Sharp PCG850VS
The Sharp cables CE132T 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 selfpower from the connection. Here's a cheap 133T for anyone looking for an Sharp 15pin serial adapter: https://www.ebay.com/itm/133672149943 Bob Prosperi 

06082021, 05:18 PM
(This post was last modified: 06122021 01:21 AM by robve.)
Post: #149




RE: Sharp PCG850VS
(06082021 12:37 PM)rprosperi Wrote: The Sharp cables CE132T and 133T tend to work with more devices than the very early 130T. Caveat lector+emptor: I also tried a CE133T with no luck. The CE132T could work since it's externally powered, but I don't know for sure. Note that the CE133T requires +/7V input signal at minimum and +/15V max (see the operating manual). Unfortunately, most USB RS232C 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 15pin adapter is described here https://www.qsl.net/yt2fsg/pocket/pocket.html and here https://www.simonlehmayr.de/e_pc.htm (click on PC1350 then "Connections" at the top of the screen). EDIT: please note that these adapters will NOT work with the PCG850V but with older SHARP PC with a 15pin port! For details see https://sharppocketcomputers.com/#level  Rob HP 71B,Prime G2;Ti VOY200,Nspire CXII CAS;Casio fxCG50;Sharp PCG850VS,E500S,1475,1450,1403,1360,1350,2500,1262,1500A 

06092021, 02:18 AM
Post: #150




RE: Sharp PCG850VS
(06082021 05:18 PM)robve Wrote: The CE132T could work since it's externally powered, but I don't know for sure. I believe I still have a CE132T  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 

06112021, 07:35 AM
Post: #151




RE: Sharp PCG850VS
(12182020 07:48 PM)robve Wrote: The PCG850 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. 

06162021, 11:26 PM
Post: #152




RE: Sharp PCG850VS
(06072021 09:30 PM)robve Wrote:(06072021 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 

06172021, 04:43 AM
Post: #153




RE: Sharp PCG850VS
If you look in my PCG850 gadget github repository at the Arduino sketch for the gadget there is a function called:
void button_set_sio() This function sets the 11 pin interface signals up for transmit and receive on the SIO interface. The code that handles the GPIO lines is here: // Set the data directions for the SIO mode set_if_sio(); // Set up control lines to allow 850 to send and receive // SIO data pinMode(SIOCTSPin, OUTPUT); pinMode(SIORXDPin, OUTPUT); pinMode(SIOCDPin, OUTPUT); pinMode(SIODSRPin, OUTPUT); pinMode(SIOCIPin, OUTPUT); // Drive signals to allow sending by 850 digitalWrite(SIOCTSPin, HIGH); // HIGH to allow 850 to send digitalWrite(SIODSRPin, LOW); digitalWrite(SIOCDPin, LOW); digitalWrite(SIOCIPin, LOW); // Put RXD into inactive line state digitalWrite(SIORXDPin, LOW); You can see that the CTS line needs to be taken high to allow the 850 to send. The sketch file is here: https://github.com/blackjetrock/pcg850vs...dget_1.ino Regards Andrew 

06192021, 03:40 PM
Post: #154




RE: Sharp PCG850VS
(06162021 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. JeanCharles 

07122021, 07:11 PM
Post: #155




RE: Sharp PCG850VS
(06192021 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 HP 71B,Prime G2;Ti VOY200,Nspire CXII CAS;Casio fxCG50;Sharp PCG850VS,E500S,1475,1450,1403,1360,1350,2500,1262,1500A 

« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)