// calc.c #define GBUFFER_SIZE 1024 #include "comdefs_app.h" #define NOTMEMCPY_ENABLE #define NOTSTRCMP_ENABLE #define NOTSTRCPY_ENABLE #define NOTATOD_ENABLE #define FPTOA_ENABLE #define NOTSTRLEN_ENABLE #define NOTSTRAPPEND_ENABLE #define NOTMEMSET_ENABLE #define NOTFWRITE_ENABLE #define NOTITOA10_ENABLE #define NOTATOI10_ENABLE #define NOTSTRREV_ENABLE #define NOTFGETS_ENABLE #define _START_ENABLE #define _SYSCALL_ENABLE #include "notlibc.h" #define BKGNDGREY RGB(192,192,192) static char mem_slab[GBUFFER_SIZE]={0}; static char gbuffer[GBUFFER_SIZE]={0}; unsigned char gdisplaystr[MAX_DISPLAYSTR_LEN], gfisnumberentering, gbinop; unsigned int gdisplaystrlen, gfnotexit; double gax, gbx; signed short gFRectx1, gFRecty1, gFRectx2, gFRecty2, gRectx1, gRecty1, gRectx2, gRecty2; signed short gCentertextx, gCentertexty, gLefttextx, gLefttexty, gRighttextx, gRighttexty; unsigned int kbdcolor[KBDROWS*KBDCOLS] = { ADMINCLR, ADMINCLR, ADMINCLR, OPCLR, NUMCLR, NUMCLR, NUMCLR, OPCLR, NUMCLR, NUMCLR, NUMCLR, OPCLR, NUMCLR, NUMCLR, NUMCLR, OPCLR, NUMCLR, NUMCLR, NUMCLR, OPCLR }; unsigned char *kbdstr[KBDROWS*KBDCOLS] = { "Off", "C", " 0 ) { if ( gdisplaystrlen == 1 ) { displaystr( 0, "0", RGB(92,92,127) ); } gdisplaystr[--gdisplaystrlen] = '\0'; if ( gdisplaystrlen > 0 ) { displaystr( 0, gdisplaystr, RGB(92,92,127) ); } } break; case RC(4,2): if ( gdisplaystrlen > 0 ) { if ( gdisplaystr[0] == '-' ) { notmemcpy( gdisplaystr, gdisplaystr+1, gdisplaystrlen-- ); gdisplaystr[gdisplaystrlen] = '\0'; } else if ( gdisplaystrlen < ( MAX_DISPLAYSTR_LEN - 1 ) ) { notmemcpy( gdisplaystr+1, gdisplaystr, ++gdisplaystrlen ); gdisplaystr[0] = '-'; } displaystr( 0, gdisplaystr, RGB(92,92,127) ); } break; case RC(0,3): case RC(1,3): case RC(2,3): case RC(3,3): gbinop = kbdstr[rowcol][0]; notatod( gdisplaystr, &gax ); gfisnumberentering = 0; break; case RC(4,3): if ( gfisnumberentering ) { notatod( gdisplaystr, &gbx ); gfisnumberentering = 0; } switch ( gbinop ) { case '*': gax *= gbx; break; case '/': gax /= gbx; break; case '+': gax += gbx; break; case '-': gax -= gbx; break; } drawapp(); fptoa( gdisplaystr, gax ); gdisplaystrlen = notstrlen( gdisplaystr ); displaystr( 0, gdisplaystr, RGB(92,92,127) ); break; } } int _NOTMAIN( int argc, char **argv ) { int button, x, y, row, col; char *ptr; gfnotexit = 1; button = 0; x = 0; y = 0; while ( gfnotexit && notfgets( gbuffer, GBUFFER_SIZE, 0 ) ) { if ( notstrcmp( gbuffer, "drawapp\n" ) == 0 ) { drawapp(); } else { ptr = notatoi10( gbuffer, &button ); if ( *ptr == ' ' ) { ptr++; } ptr = notatoi10( ptr, &x ); if ( *ptr == ' ' ) { ptr++; } ptr = notatoi10( ptr, &y ); switch ( (x<0)? x : button ) { case 1: row = Y_TO_ROW(y); col = X_TO_COL(x); if ( ( row >= 0 ) && ( row < KBDROWS ) && ( col >= 0 ) && ( col < KBDCOLS ) ) { key_to_exe( row*KBDCOLS+col ); } break; case -4: ptr=notstrcpy(gbuffer, "Rz "); ptr=notitoa10( ptr, button ); ptr=notstrappend( ptr, " " ); ptr=notitoa10( ptr, y ); ptr=notstrcpy(ptr, "\n"); notfwrite( 1, gbuffer ); break; case -5: ptr=notstrcpy(gbuffer, "Mv "); ptr=notitoa10( ptr, button ); ptr=notstrappend( ptr, " " ); ptr=notitoa10( ptr, y ); ptr=notstrcpy(ptr, "\n"); notfwrite( 1, gbuffer ); drawapp(); break; case -2: switch ( button ) { case 'o': case 'O': key_to_exe( 0 ); break; case 'c': case 'C': key_to_exe( 1 ); break; case 8: key_to_exe( 2 ); break; case '*': key_to_exe( 3 ); break; case '7': key_to_exe( 4 ); break; case '8': key_to_exe( 5 ); break; case '9': key_to_exe( 6 ); break; case '/': key_to_exe( 7 ); break; case '4': key_to_exe( 8 ); break; case '5': key_to_exe( 9 ); break; case '6': key_to_exe( 10 ); break; case '+': key_to_exe( 11 ); break; case '1': key_to_exe( 12 ); break; case '2': key_to_exe( 13 ); break; case '3': key_to_exe( 14 ); break; case '-': key_to_exe( 15 ); break; case '0': key_to_exe( 16 ); break; case '.': key_to_exe( 17 ); break; case 'I': case 'i': key_to_exe( 18 ); break; case '=': key_to_exe( 19 ); break; } break; //case -98: usleep(100*y); break; } } } _EXIT(0); }