| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #if ! defined(ARDUINO) && ! defined(__HARDWAREH__) |
| | #define __HARDWAREH__ |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #define POSIXTERMINAL |
| | #define POSIXVT52TOANSI |
| | #define POSIXSIGNALS |
| | #undef POSIXNONBLOCKING |
| | #undef POSIXFRAMEBUFFER |
| | #undef POSIXWIRE |
| | #undef POSIXMQTT |
| | #undef POSIXWIRING |
| | #undef POSIXPIGPIO |
| |
|
| | |
| | #undef SPIRAMSIMULATOR |
| |
|
| | |
| | #define ARDUINOPRT |
| |
|
| | |
| |
|
| | |
| | |
| | #undef BREAKPIN |
| |
|
| | |
| | #define BREAKSIGNAL SIGINT |
| |
|
| | |
| | #ifdef POSIXNONBLOCKING |
| | #define BASICBGTASK |
| | #endif |
| |
|
| | |
| | #ifndef RASPPI |
| | #undef POSIXFRAMEBUFFER |
| | #endif |
| |
|
| | |
| | #define POSIXI2CBUS 1 |
| |
|
| | |
| | #ifdef POSIXWIRING |
| | #include <wiringPi.h> |
| | #endif |
| |
|
| | #ifdef POSIXPIGPIO |
| | #include <pigpiod_if2.h> |
| | #undef POSIXWIRING |
| | static int pigpio_pi = 0; |
| | #endif |
| |
|
| | |
| | |
| | |
| |
|
| | #if defined(MSDOS) |
| | const char bsystype = SYSTYPE_MSDOS |
| | #elif defined(RASPPI) |
| | const char bsystype = SYSTYPE_PASPPI |
| | #elif defined(MINGW) |
| | const char bsystype = SYSTYPE_MINGW |
| | #else |
| | const char bsystype = SYSTYPE_POSIX; |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | const int serial_baudrate = 0; |
| | const int serial1_baudrate = 0; |
| | char sendcr = 0; |
| | short blockmode = 0; |
| |
|
| | |
| | struct timeb start_time; |
| | void timeinit() { ftime(&start_time); } |
| |
|
| | |
| | void wiringbegin() { |
| | #ifdef POSIXWIRING |
| | wiringPiSetup(); |
| | #endif |
| | #ifdef POSIXPIGPIO |
| | pigpio_pi=pigpio_start("localhost","8888"); |
| | printf("** GPIO started with result %d\n", pigpio_pi); |
| | printf("** pigpio version %d.\n", get_pigpio_version(pigpio_pi)); |
| | printf("** Hardware revision %d.\n", get_hardware_revision(pigpio_pi)); |
| | #endif |
| | } |
| |
|
| | |
| | |
| | |
| | #ifdef POSIXSIGNALS |
| | #include <signal.h> |
| | mem_t breaksignal = 0; |
| |
|
| | |
| | void signalhandler(int sig){ |
| | breaksignal=1; |
| | signal(BREAKSIGNAL, signalhandler); |
| | } |
| |
|
| | |
| | void signalon() { |
| | signal(BREAKSIGNAL, signalhandler); |
| | } |
| |
|
| | |
| | void signaloff() {} |
| |
|
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | long freememorysize() { |
| | #ifdef MSDOS |
| | return 48000; |
| | #else |
| | return 65536; |
| | #endif |
| | } |
| |
|
| | long freeRam() { |
| | return freememorysize(); |
| | } |
| |
|
| | |
| | |
| | |
| | void restartsystem() { exit(0);} |
| | void activatesleep(long t) {} |
| |
|
| | |
| | |
| | |
| | void spibegin() {} |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | const int dsp_rows=0; |
| | const int dsp_columns=0; |
| | void dspsetupdatemode(char c) {} |
| | void dspwrite(char c){} |
| | void dspbegin() {} |
| | int dspstat(char c) {return 0; } |
| | char dspwaitonscroll() { return 0; } |
| | char dspactive() {return 0; } |
| | void dspsetscrollmode(char c, short l) {} |
| | void dspsetcursor(short c, short r) {} |
| |
|
| | #ifndef POSIXFRAMEBUFFER |
| | |
| | void rgbcolor(int r, int g, int b) {} |
| | void vgacolor(short c) {} |
| | void plot(int x, int y) {} |
| | void line(int x0, int y0, int x1, int y1) {} |
| | void rect(int x0, int y0, int x1, int y1) {} |
| | void frect(int x0, int y0, int x1, int y1) {} |
| | void circle(int x0, int y0, int r) {} |
| | void fcircle(int x0, int y0, int r) {} |
| |
|
| | |
| | void vgabegin(){} |
| | void vgawrite(char c){} |
| | #else |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | #include <sys/fcntl.h> |
| | #include <sys/ioctl.h> |
| | #include <linux/fb.h> |
| | #include <sys/mman.h> |
| | #include <string.h> |
| |
|
| | |
| | char *framemem = 0; |
| | int framedesc = 0; |
| |
|
| | |
| | struct fb_var_screeninfo vinfo; |
| | struct fb_fix_screeninfo finfo; |
| | struct fb_var_screeninfo orig_vinfo; |
| |
|
| | |
| | long framecolor = 0xffffff; |
| | int framevgacolor = 0x0f; |
| | long framescreensize = 0; |
| | int framecolordepth = 0; |
| |
|
| | |
| | void vgabegin() { |
| |
|
| | |
| | framedesc = open("/dev/fb0", O_RDWR); |
| | if (!framedesc) { |
| | printf("** error opening frame buffer \n"); |
| | return; |
| | } |
| |
|
| | |
| | if (ioctl(framedesc, FBIOGET_VSCREENINFO, &vinfo)) { |
| | printf("** error reading screen information \n"); |
| | return; |
| | } |
| | printf("** detected screen %dx%d, %dbpp \n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel); |
| |
|
| | |
| | memcpy(&orig_vinfo, &vinfo, sizeof(struct fb_var_screeninfo)); |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | framecolordepth = vinfo.bits_per_pixel; |
| |
|
| | |
| | if (ioctl(framedesc, FBIOGET_FSCREENINFO, &finfo)) { |
| | printf("Error reading fixed information.\n"); |
| | return; |
| | } |
| |
|
| | |
| |
|
| | framescreensize = (framecolordepth/8) * vinfo.xres * vinfo.yres; |
| | framemem = (char*)mmap(0, framescreensize, PROT_READ | PROT_WRITE, MAP_SHARED, framedesc, 0); |
| | if ((int)framemem == -1) { |
| | printf("** error failed to mmap.\n"); |
| | framemem=0; |
| | return; |
| | } |
| |
|
| | |
| | } |
| |
|
| | |
| | void vgaend() { |
| | if ((int)framemem) munmap(framemem, framescreensize); |
| | if (ioctl(framedesc, FBIOPUT_VSCREENINFO, &orig_vinfo)) { |
| | printf("** error re-setting variable information \n"); |
| | } |
| | close(framedesc); |
| | } |
| |
|
| | |
| | void rgbcolor(int r, int g, int b) { |
| | switch (framecolordepth/8) { |
| | case 4: |
| | framecolor = (((long)r << 16) & 0x00ff0000) | (((long)g << 8) & 0x0000ff00) | ((long)b & 0x000000ff); |
| | break; |
| | case 3: |
| | framecolor = (((long)r << 16) & 0x00ff0000) | (((long)g << 8) & 0x0000ff00) | ((long)b & 0x000000ff); |
| | break; |
| | case 2: |
| | framecolor = ((long) (r & 0xff) >> 3) << 10 | ((long) (g & 0xff) >> 2) << 6 | ((long) (b & 0xff) >> 3); |
| | break; |
| | case 1: |
| | framecolor = ((long) (r & 0xff) >> 5) << 5 | ((long) (g & 0xff) >> 5) << 2 | ((long) (b & 0xff) >> 6); |
| | break; |
| | } |
| | } |
| |
|
| | |
| | void vgacolor(short c) { |
| | short base=128; |
| | framevgacolor=c; |
| | if (c==8) { rgbcolor(64, 64, 64); return; } |
| | if (c>8) base=255; |
| | rgbcolor(base*(c&1), base*((c&2)/2), base*((c&4)/4)); |
| | } |
| |
|
| | |
| | void plot(int x, int y) { |
| | unsigned long pix_offset; |
| |
|
| | |
| | if (x < 0 || y < 0 || x >= vinfo.xres || y >= vinfo.yres) return; |
| |
|
| | |
| | pix_offset = (framecolordepth/8) * x + y * finfo.line_length; |
| |
|
| | if (pix_offset < 0 || pix_offset+ (framecolordepth/8-1) > framescreensize) return; |
| |
|
| | |
| | switch (framecolordepth/8) { |
| | case 4: |
| | *((char*)(framemem + pix_offset )) = (unsigned char)(framecolor & 0x000000ff); |
| | *((char*)(framemem + pix_offset+1)) = (unsigned char)((framecolor >> 8) & 0x000000ff); |
| | *((char*)(framemem + pix_offset+3)) = (unsigned char)((framecolor >> 16) & 0x000000ff); |
| | break; |
| | case 3: |
| | *((char*)(framemem + pix_offset )) = (unsigned char)(framecolor & 0x000000ff); |
| | *((char*)(framemem + pix_offset+1)) = (unsigned char)((framecolor >> 8) & 0x000000ff); |
| | *((char*)(framemem + pix_offset+2)) = (unsigned char)((framecolor >> 16) & 0x000000ff); |
| | break; |
| | case 2: |
| | *((char*)(framemem + pix_offset )) = (unsigned char)((framecolor & 0x1f) + (((framecolor >> 5) & 0x03) << 6)); |
| | *((char*)(framemem + pix_offset+1)) = (unsigned char)((framecolor >> 7) & 0xff); |
| | break; |
| | case 1: |
| | *((char*)(framemem + pix_offset )) = (unsigned char)(framecolor & 0x000000ff); |
| | break; |
| | } |
| |
|
| | } |
| |
|
| | |
| | void line(int x0, int y0, int x1, int y1) { |
| | int dx, dy, sx, sy; |
| | int error, e2; |
| | |
| | dx=abs(x0-x1); |
| | sx=x0 < x1 ? 1 : -1; |
| | dy=-abs(y1-y0); |
| | sy=y0 < y1 ? 1 : -1; |
| | error=dx+dy; |
| |
|
| | while(1) { |
| | plot(x0, y0); |
| | if (x0 == x1 && y0 == y1) break; |
| | e2=2*error; |
| | if (e2 > dy) { |
| | if (x0 == x1) break; |
| | error=error+dy; |
| | x0=x0+sx; |
| | } |
| | if (e2 <= dx) { |
| | if (y0 == y1) break; |
| | error=error+dx; |
| | y0=y0+sy; |
| | } |
| | } |
| | } |
| |
|
| | |
| | void rect(int x0, int y0, int x1, int y1) { |
| | line(x0, y0, x1, y0); |
| | line(x1, y0, x1, y1); |
| | line(x1, y1, x0, y1); |
| | line(x0, y1, x0, y0); |
| | } |
| |
|
| | |
| | void frect(int x0, int y0, int x1, int y1) { |
| | int dx, sx; |
| | int x; |
| | sx=x0 < x1 ? 1 : -1; |
| | for(x=x0; x != x1; x=x+sx) line(x, y0, x, y1); |
| | } |
| |
|
| | |
| | void circle(int x0, int y0, int r) { |
| | int x, y, err; |
| | x=-r; |
| | y=0; |
| | err=2-2*r; |
| | do { |
| | plot(x0-x, y0+y); |
| | plot(x0-y, y0-x); |
| | plot(x0+x, y0-y); |
| | plot(x0+y, y0+x); |
| | r=err; |
| | if (r <= y) err+=++y*2+1; |
| | if (r > x || err > y) err+=++x*2+1; |
| | } while (x < 0); |
| | } |
| |
|
| | |
| | void fcircle(int x0, int y0, int r) { |
| | int x, y, err; |
| | x=-r; |
| | y=0; |
| | err=2-2*r; |
| | do { |
| | line(x0-x, y0+y, x0+x, y0+y); |
| | line(x0+x, y0-y, x0-x, y0-y); |
| | r=err; |
| | if (r <= y) err+=++y*2+1; |
| | if (r > x || err > y) err+=++x*2+1; |
| | } while (x < 0); |
| | } |
| |
|
| | |
| | void vgawrite(char c) {} |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | void kbdbegin() {} |
| | int kbdstat(char c) {return 0; } |
| | char kbdavailable(){ return 0;} |
| | char kbdread() { return 0;} |
| | char kbdcheckch() { return 0;} |
| |
|
| | |
| | mem_t vt52avail() {return 0;} |
| | char vt52read() { return 0; } |
| |
|
| | |
| |
|
| | |
| | |
| | |
| | #define HASCLOCK |
| |
|
| | void rtcbegin() {} |
| |
|
| | short rtcget(short i) { |
| | struct timeb thetime; |
| | struct tm *ltime; |
| | ftime(&thetime); |
| | ltime=localtime(&thetime.time); |
| | switch (i) { |
| | case 0: |
| | return ltime->tm_sec; |
| | case 1: |
| | return ltime->tm_min; |
| | case 2: |
| | return ltime->tm_hour; |
| | case 3: |
| | return ltime->tm_wday; |
| | case 4: |
| | return ltime->tm_mday; |
| | case 5: |
| | return ltime->tm_mon+1; |
| | case 6: |
| | return ltime->tm_year-100; |
| | default: |
| | return 0; |
| | } |
| | } |
| |
|
| | void rtcset(uint8_t i, short v) {} |
| |
|
| |
|
| | |
| | |
| | |
| | #ifndef POSIXMQTT |
| | void netbegin() {} |
| | char netconnected() { return 0; } |
| | void mqttbegin() {} |
| | int mqttstat(char c) {return 0; } |
| | int mqttstate() {return -1;} |
| | void mqttsubscribe(char *t) {} |
| | void mqttsettopic(char *t) {} |
| | void mqttouts(char *m, short l) {} |
| | void mqttins(char *b, short nb) { z.a=0; }; |
| | char mqttinch() {return 0;}; |
| | #else |
| | |
| | #include <mosquitto.h> |
| | |
| | void netbegin() {} |
| | char netconnected() { return 1; } |
| | |
| | void mqttbegin() {} |
| | int mqttstat(char c) {return 0; } |
| | int mqttstate() {return -1;} |
| | void mqttsubscribe(char *t) {} |
| | void mqttsettopic(char *t) {} |
| | void mqttouts(char *m, short l) {} |
| | void mqttins(char *b, short nb) { z.a=0; }; |
| | char mqttinch() {return 0;}; |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | |
| | signed char eeprom[EEPROMSIZE]; |
| | void ebegin(){ |
| | int i; |
| | FILE* efile; |
| | for (i=0; i<EEPROMSIZE; i++) eeprom[i]=-1; |
| | efile=fopen("eeprom.dat", "r"); |
| | if (efile) fread(eeprom, EEPROMSIZE, 1, efile); |
| | } |
| |
|
| | void eflush(){ |
| | FILE* efile; |
| | efile=fopen("eeprom.dat", "w"); |
| | if (efile) fwrite(eeprom, EEPROMSIZE, 1, efile); |
| | fclose(efile); |
| | } |
| |
|
| | address_t elength() { return EEPROMSIZE; } |
| | void eupdate(address_t a, mem_t c) { if (a>=0 && a<EEPROMSIZE) eeprom[a]=c; } |
| | mem_t eread(address_t a) { if (a>=0 && a<EEPROMSIZE) return eeprom[a]; else return -1; } |
| |
|
| | |
| | |
| | |
| | #if !defined(POSIXWIRING) && !defined(POSIXPIGPIO) |
| | void aread(){ pop(); push(0); } |
| | void dread(){ pop(); push(0); } |
| | void awrite(address_t p, address_t v){} |
| | void dwrite(address_t p, address_t v){} |
| | void pinm(address_t p, address_t m){} |
| | #endif |
| |
|
| | #ifdef POSIXWIRING |
| | void aread(){ push(analogRead(pop())); } |
| | void dread(){ push(digitalRead(pop())); } |
| |
|
| |
|
| | void awrite(address_t p, address_t v){ |
| | if (v >= 0 && v<256) analogWrite(p, v); |
| | else error(EORANGE); |
| | } |
| |
|
| | void dwrite(address_t p, address_t v){ |
| | if (v == 0) digitalWrite(p, LOW); |
| | else if (v == 1) digitalWrite(p, HIGH); |
| | else error(EORANGE); |
| | } |
| |
|
| | |
| | void pinm(address_t p, address_t m){ |
| | if (m>=0) pinMode(p, m); |
| | else error(EORANGE); |
| | } |
| | #endif |
| |
|
| | |
| | #ifdef POSIXPIGPIO |
| |
|
| |
|
| | void aread(){ pop(); push(0); } |
| |
|
| |
|
| | void dread(){ |
| | push(gpio_read(pigpio_pi, pop())); |
| | } |
| |
|
| | void awrite(address_t p, address_t v){ |
| | set_PWM_dutycycle(pigpio_pi, p, v); |
| | } |
| |
|
| |
|
| | void dwrite(address_t p, address_t v){ |
| | gpio_write(pigpio_pi, p, v); |
| | } |
| |
|
| | void pinm(address_t p, address_t m){ |
| | set_mode(pigpio_pi, p, m); |
| | } |
| | #endif |
| |
|
| | |
| | #if !defined(POSIXWIRING) |
| | unsigned long millis() { |
| | struct timeb thetime; |
| | ftime(&thetime); |
| | return (thetime.time-start_time.time)*1000+(thetime.millitm-start_time.millitm); |
| | } |
| | #endif |
| |
|
| | void bpulsein() { pop(); pop(); pop(); push(0); } |
| | void bpulseout(short a) { while (a--) pop(); } |
| | void btone(short a) { pop(); pop(); if (a == 3) pop(); } |
| |
|
| | |
| | void yieldfunction() {} |
| |
|
| | void longyieldfunction() { |
| | #ifdef BASICBGTASK |
| | |
| | #ifdef POSIXNONBLOCKING |
| | if (checkch() == BREAKCHAR) breakcondition=1; |
| | #endif |
| | #endif |
| | } |
| |
|
| | void yieldschedule() {} |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | void fsbegin(char v) {} |
| | #define FILESYSTEMDRIVER |
| | FILE* ifile; |
| | FILE* ofile; |
| | #ifndef MSDOS |
| | DIR* root; |
| | struct dirent* file; |
| | #else |
| | void* root; |
| | void* file; |
| | #endif |
| |
|
| | |
| | int fsstat(char c) {return 1; } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | void filewrite(char c) { |
| | if (ofile) |
| | fputc(c, ofile); |
| | else |
| | ert=1; |
| | } |
| |
|
| | char fileread(){ |
| | char c; |
| | if (ifile) c=fgetc(ifile); else { ert=1; return 0; } |
| | if (cheof(c)) ert=-1; |
| | return c; |
| | } |
| |
|
| | char ifileopen(const char* filename){ |
| | ifile=fopen(filename, "r"); |
| | |
| | return ifile!=0; |
| | } |
| |
|
| | void ifileclose(){ |
| | if (ifile) fclose(ifile); |
| | ifile=0; |
| | } |
| |
|
| | char ofileopen(char* filename, const char* m){ |
| | ofile=fopen(filename, m); |
| | |
| | return ofile!=0; |
| | } |
| |
|
| | void ofileclose(){ |
| | if (ofile) fclose(ofile); |
| | ofile=0; |
| | } |
| |
|
| | int fileavailable(){ return !feof(ifile); } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | #ifdef MSDOS |
| | #include <dos.h> |
| | #include <dir.h> |
| | struct ffblk *bffblk; |
| | #endif |
| |
|
| | void rootopen() { |
| | #ifndef MSDOS |
| | root=opendir ("./"); |
| | #else |
| | (void) findfirst("*.*", bffblk, 0); |
| | #endif |
| | } |
| |
|
| | int rootnextfile() { |
| | #ifndef MSDOS |
| | file = readdir(root); |
| | return (file != 0); |
| | #else |
| | return (findnext(bffblk) == 0); |
| | #endif |
| | } |
| |
|
| | int rootisfile() { |
| | #if !defined(MSDOS) && !defined(MINGW) |
| | return (file->d_type == DT_REG); |
| | #else |
| | return 1; |
| | #endif |
| | } |
| |
|
| | const char* rootfilename() { |
| | #ifndef MSDOS |
| | return (file->d_name); |
| | #else |
| | return (bffblk->ff_name); |
| | #endif |
| | } |
| |
|
| | long rootfilesize() { |
| | #ifndef MSDOS |
| | return 0; |
| | #else |
| | return (bffblk->ff_fsize); |
| | #endif |
| | } |
| |
|
| | void rootfileclose() {} |
| | void rootclose(){ |
| | #ifndef MSDOS |
| | (void) closedir(root); |
| | #endif |
| | } |
| |
|
| | |
| | |
| | |
| | void removefile(char *filename) { |
| | remove(filename); |
| | } |
| |
|
| | |
| | |
| | |
| | void formatdisk(short i) { |
| | outsc("Format not implemented on this platform\n"); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | #ifdef POSIXNONBLOCKING |
| | #if !defined(MSDOS) && !defined(MINGW) |
| | #include <fcntl.h> |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | void serialbegin() { |
| | |
| | |
| | |
| | |
| | } |
| |
|
| | |
| | short serialcheckch(){ |
| | fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK); |
| | int ch=getchar(); |
| | ungetc(ch, stdin); |
| | fcntl(0, F_SETFL, fcntl(0, F_GETFL) & ~O_NONBLOCK); |
| | return ch; |
| | } |
| |
|
| | |
| | short serialavailable() { |
| | if (cheof(serialcheckch())) return 0; else return 1; |
| | } |
| |
|
| | |
| | char serialread() { |
| | char ch; |
| | |
| | ch=getchar(); |
| | return ch; |
| | |
| | |
| | |
| | |
| | |
| | } |
| |
|
| | |
| | void serialflush() { |
| | fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK); |
| | while (!cheof(getchar())); |
| | fcntl(0, F_SETFL, fcntl(0, F_GETFL) & ~O_NONBLOCK); |
| | } |
| | #else |
| | |
| | #include <conio.h> |
| | |
| | void serialbegin(){} |
| |
|
| | |
| | char serialread() { |
| | return getchar(); |
| | } |
| |
|
| | |
| | short serialcheckch(){ |
| | if (kbhit()) return getch(); |
| | } |
| |
|
| | |
| | short serialavailable() { |
| | return 1; |
| | } |
| |
|
| | |
| | void serialflush() { } |
| | #endif |
| | #else |
| | |
| | void serialbegin(){} |
| | char serialread() { return getchar(); } |
| | short serialcheckch(){ return 1; } |
| | short serialavailable() { return 1; } |
| | void serialflush() {} |
| | #endif |
| |
|
| | int serialstat(char c) { |
| | if (c == 0) return 1; |
| | if (c == 1) return serial_baudrate; |
| | return 0; |
| | } |
| |
|
| | |
| | void sendcsi() { |
| | putchar(27); putchar('['); |
| | } |
| |
|
| | |
| | #ifdef POSIXVT52TOANSI |
| | #include <stdlib.h> |
| | mem_t dspesc = 0; |
| | mem_t vt52s = 0; |
| | int cursory = 0; |
| | mem_t vt52active = 1; |
| |
|
| | |
| | uint8_t vt52number(char c) { |
| | uint8_t b=c; |
| | if (b>31) return b-32; else return 0; |
| | } |
| |
|
| | |
| | void dspsetcursory(int i) { |
| | cursory=i; |
| | } |
| |
|
| | |
| | void dspsetcursorx(int i) { |
| | sendcsi(); |
| | printf("%d;%dH", abs(cursory)+1, abs(i)+1); |
| | } |
| |
|
| | |
| | void dspsetfgcolor(int co) { |
| | sendcsi(); |
| | if (co < 8) { |
| | putchar('3'); |
| | } else { |
| | putchar('9'); |
| | co=co-8; |
| | } |
| | putchar('0'+co); |
| | putchar('m'); |
| | } |
| |
|
| | void dspsetbgcolor(int co) { |
| | sendcsi(); |
| | if (co < 8) { |
| | putchar('4'); |
| | } else { |
| | putchar('1'); putchar('0'); |
| | co=co-8; |
| | } |
| | putchar('0'+co); |
| | putchar('m'); |
| | } |
| |
|
| | |
| | void dspvt52(char* c){ |
| | |
| | |
| | switch (vt52s) { |
| | case 'Y': |
| | if (dspesc == 2) { |
| | dspsetcursory(vt52number(*c)); |
| | dspesc=1; |
| | *c=0; |
| | return; |
| | } |
| | if (dspesc == 1) { |
| | dspsetcursorx(vt52number(*c)); |
| | *c=0; |
| | } |
| | vt52s=0; |
| | break; |
| | case 'b': |
| | dspsetfgcolor(vt52number(*c)); |
| | *c=0; |
| | vt52s=0; |
| | break; |
| | case 'c': |
| | dspsetbgcolor(vt52number(*c)); |
| | *c=0; |
| | vt52s=0; |
| | break; |
| | } |
| | |
| | |
| | switch (*c) { |
| | case 'v': |
| | break; |
| | case 'w': |
| | break; |
| | case '^': |
| | break; |
| | case '_': |
| | break; |
| | case 'W': |
| | break; |
| | case 'X': |
| | break; |
| | case 'V': |
| | break; |
| | case ']': |
| | break; |
| | case 'F': |
| | break; |
| | case 'G': |
| | break; |
| | case 'Z': |
| | break; |
| | case '=': |
| | case '>': |
| | break; |
| | case 'b': |
| | case 'c': |
| | vt52s=*c; |
| | dspesc=1; |
| | *c=0; |
| | return; |
| | case 'e': |
| | break; |
| | case 'f': |
| | break; |
| | case 'p': |
| | break; |
| | case 'q': |
| | break; |
| | case 'A': |
| | sendcsi(); |
| | putchar('A'); |
| | break; |
| | case 'B': |
| | sendcsi(); |
| | putchar('B'); |
| | break; |
| | case 'C': |
| | sendcsi(); |
| | putchar('C'); |
| | break; |
| | case 'D': |
| | sendcsi(); |
| | putchar('D'); |
| | break; |
| | case 'E': |
| | *c=12; |
| | dspesc=0; |
| | return; |
| | case 'H': |
| | *c=2; |
| | dspesc=0; |
| | return; |
| | case 'Y': |
| | vt52s='Y'; |
| | dspesc=2; |
| | *c=0; |
| | return; |
| | case 'J': |
| | sendcsi(); |
| | putchar('J'); |
| | break; |
| | case 'd': |
| | sendcsi(); |
| | putchar('1'); putchar('J'); |
| | break; |
| | case 'K': |
| | sendcsi(); |
| | putchar('K'); |
| | break; |
| | case 'l': |
| | sendcsi(); |
| | putchar('2'); putchar('K'); |
| | break; |
| | case 'o': |
| | sendcsi(); |
| | putchar('1'); putchar('K'); |
| | break; |
| | case 'k': |
| | break; |
| | case 'j': |
| | break; |
| | case 'I': |
| | putchar(27); |
| | putchar('M'); |
| | break; |
| | case 'L': |
| | break; |
| | case 'M': |
| | sendcsi(); |
| | putchar('2'); putchar('K'); |
| | break; |
| | } |
| | dspesc=0; |
| | *c=0; |
| | } |
| | #endif |
| |
|
| | void serialwrite(char c) { |
| |
|
| | |
| | #ifdef POSIXVT52TOANSI |
| | if (dspesc) { |
| | dspvt52(&c); |
| | if (c == 0) return; |
| | } |
| |
|
| | |
| | if (c == 27 && vt52active) { |
| | dspesc=1; |
| | return; |
| | } |
| | #endif |
| |
|
| | |
| | |
| | |
| | #ifdef POSIXTERMINAL |
| | switch (c) { |
| | |
| | case 12: |
| | sendcsi(); |
| | putchar('2'); putchar('J'); |
| | |
| | case 2: |
| | sendcsi(); |
| | putchar('H'); |
| | return; |
| | } |
| | #endif |
| |
|
| | |
| | putchar(c); |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | void consins(char *b, short nb) { |
| | char c; |
| | |
| | z.a=1; |
| | while(z.a < nb) { |
| | c=inch(); |
| | if (c == '\r') c=inch(); |
| | if (c == '\n' || cheof(c)) { |
| | break; |
| | } else { |
| | b[z.a++]=c; |
| | } |
| | } |
| | b[z.a]=0x00; |
| | z.a--; |
| | b[0]=(unsigned char)z.a; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | #ifdef ARDUINOPRT |
| | #include <fcntl.h> |
| | #if !defined(MSDOS) && !defined(MINGW) |
| | #include <termios.h> |
| | #endif |
| |
|
| | |
| | int prtfile; |
| |
|
| | |
| | char prtbuf = 0; |
| |
|
| |
|
| | void prtbegin() {} |
| |
|
| | char prtopen(char* filename, int mode) { |
| | #if !defined(MSDOS) && !defined(MINGW) |
| |
|
| | |
| | prtfile=open(filename, O_RDWR | O_NOCTTY); |
| | if (prtfile == -1) { |
| | perror(filename); |
| | return 0; |
| | } |
| |
|
| | |
| | tcflush(prtfile, TCIOFLUSH); |
| |
|
| | |
| | struct termios opt; |
| | (void) tcgetattr(prtfile, &opt); |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | opt.c_cc[VTIME] = 1; |
| | opt.c_cc[VMIN] = 0; |
| |
|
| | |
| | switch (mode) { |
| | case 9600: |
| | cfsetospeed(&opt, B9600); |
| | break; |
| | default: |
| | cfsetospeed(&opt, B9600); |
| | break; |
| | } |
| | cfsetispeed(&opt, cfgetospeed(&opt)); |
| |
|
| | |
| | tcsetattr(prtfile, TCSANOW, &opt); |
| | #endif |
| |
|
| | return 1; |
| | } |
| |
|
| | void prtclose() { |
| | if (prtfile) close(prtfile); |
| | } |
| |
|
| | int prtstat(char c) {return 1; } |
| | void prtset(int s) {} |
| |
|
| | |
| | void prtwrite(char c) { |
| | int i=write(prtfile, &c, 1); |
| | if (i != 1) ert=1; |
| | } |
| |
|
| | |
| | char prtread() { |
| | char c; |
| |
|
| | |
| | if (prtbuf) { |
| | c=prtbuf; |
| | prtbuf=0; |
| | } else { |
| | |
| | int i=read(prtfile, &c, 1); |
| | if (i < 0) { |
| | ert=1; |
| | return 0; |
| | } |
| | if (i == 0) return -1; |
| | } |
| | return c; |
| | } |
| |
|
| | |
| | short prtcheckch(){ |
| | if (!prtbuf) { |
| | int i=read(prtfile, &prtbuf, 1); |
| | if (i <= 0) prtbuf=0; |
| | } |
| | return prtbuf; |
| | } |
| |
|
| | short prtavailable(){ |
| | return prtcheckch()!=0; |
| | } |
| |
|
| | #else |
| | void prtbegin() {} |
| | int prtstat(char c) {return 0; } |
| | void prtset(int s) {} |
| | void prtwrite(char c) {} |
| | char prtread() {return 0;} |
| | short prtcheckch(){ return 0; } |
| | short prtavailable(){ return 0; } |
| | #endif |
| |
|
| |
|
| | |
| | |
| | |
| | #if defined(POSIXWIRE) && defined(POSIXPIGPIO) |
| | #define HASWIRE |
| | uint8_t wire_slaveid = 0; |
| |
|
| | |
| | void wirebegin() { |
| | } |
| |
|
| | |
| | int wirestat(char c) { |
| | return 1; |
| | } |
| |
|
| | void wireopen(char s, char m) { |
| | if (m == 0) { |
| | wire_slaveid=s; |
| | } else if ( m == 1 ) { |
| | outsc("** wire slave mode not implemented"); outcr(); |
| | } else |
| | error(EORANGE); |
| | } |
| |
|
| |
|
| | |
| | void wireins(char *b, uint8_t l) { |
| | int handle; |
| |
|
| | handle=i2c_open(pigpio_pi, POSIXI2CBUS, wire_slaveid, 0); |
| | if (handle < 0) { |
| | printf("** wire handle %d returned \n", handle); |
| | ert=1; |
| | } |
| |
|
| | z.a=i2c_read_device(pigpio_pi, handle, b+1, l); |
| |
|
| | if (z.a < 0) { |
| | ert=-1; |
| | z.a=0; |
| | } |
| | b[0]=z.a; |
| |
|
| | i2c_close(pigpio_pi, handle); |
| | } |
| |
|
| |
|
| |
|
| | void wireouts(char *b, uint8_t l) { |
| | int handle; |
| |
|
| | handle=i2c_open(pigpio_pi, POSIXI2CBUS, wire_slaveid, 0); |
| | if (handle < 0) { |
| | printf("** wire handle %d returned \n", handle); |
| | ert=1; |
| | } |
| |
|
| | if (i2c_write_device(pigpio_pi, handle, b, l) < 0) ert=-1; |
| |
|
| | i2c_close(pigpio_pi, handle); |
| | } |
| |
|
| | short wireavailable() { return 1; } |
| |
|
| | |
| | short wirereadbyte(short port) { |
| | int res, handle; |
| | handle=i2c_open(pigpio_pi, POSIXI2CBUS, port, 0); |
| | if (handle < 0) { |
| | printf("** wire handle %d returned \n", handle); |
| | ert=1; |
| | return -1; |
| | } |
| | |
| | res=i2c_read_byte(pigpio_pi, handle); |
| | i2c_close(pigpio_pi, handle); |
| | return res; |
| | } |
| |
|
| | |
| | void wirewritebyte(short port, short data) { |
| | int res, handle; |
| | handle=i2c_open(pigpio_pi, POSIXI2CBUS, port, 0); |
| | if (handle < 0) { ert=1; return; } |
| | |
| | ert=i2c_write_byte(pigpio_pi, handle, data); |
| |
|
| | i2c_close(pigpio_pi, handle); |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | void wirewriteword(short port, short data1, short data2) { |
| | int res, handle; |
| | mem_t buf[2]; |
| |
|
| | handle=i2c_open(pigpio_pi, POSIXI2CBUS, port, 0); |
| | if (handle < 0) { ert=1; return; } |
| |
|
| | buf[0]=data1; |
| | buf[1]=data2; |
| |
|
| | if (i2c_write_device(pigpio_pi, handle, buf, 2) <0 ) ert=-1; |
| |
|
| | i2c_close(pigpio_pi, handle); |
| | } |
| |
|
| | #else |
| | void wirebegin() {} |
| | int wirestat(char c) {return 0; } |
| | void wireopen(char s, char m) {} |
| | void wireins(char *b, uint8_t l) { b[0]=0; z.a=0; } |
| | void wireouts(char *b, uint8_t l) {} |
| | short wireavailable() { return 1; } |
| | short wirereadbyte(short port) { return 0; } |
| | void wirewritebyte(short port, short data) { return; } |
| | void wirewriteword(short port, short data1, short data2) { return; } |
| | #endif |
| |
|
| | |
| | |
| | |
| | |
| | int radiostat(char c) {return 0; } |
| | void radioset(int s) {} |
| | void radioins(char *b, short nb) { b[0]=0; b[1]=0; z.a=0; } |
| | void radioouts(char *b, short l) {} |
| | void iradioopen(char *filename) {} |
| | void oradioopen(char *filename) {} |
| | short radioavailable() { return 0; } |
| |
|
| | |
| | void sensorbegin() {} |
| | number_t sensorread(short s, short v) {return 0;}; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #ifdef SPIRAMSIMULATOR |
| | #define USEMEMINTERFACE |
| |
|
| | static mem_t* spiram; |
| |
|
| | |
| | address_t spirambegin() { |
| | spiram=(mem_t*)malloc(65536); |
| | if (maxnum>32767) return 65534; else return 32766; |
| | } |
| |
|
| | |
| | void spiramrawwrite(address_t a, mem_t c) {spiram[a]=c;} |
| |
|
| | |
| | mem_t spiramrawread(address_t a) {return spiram[a];} |
| |
|
| | |
| |
|
| | void spiram_rwbufferwrite(address_t a, mem_t c) {spiram[a]=c;} |
| |
|
| | mem_t spiram_rwbufferread(address_t a) {return spiram[a];} |
| |
|
| | mem_t spiram_robufferread(address_t a) {return spiram[a];} |
| |
|
| | |
| | |
| | |
| | |
| | #define SPIRAMSBSIZE 128 |
| | char spistrbuf1[SPIRAMSBSIZE]; |
| | char spistrbuf2[SPIRAMSBSIZE]; |
| | #endif |
| |
|
| | |
| | #ifdef HASEVENTS |
| | mem_t enableevent(mem_t pin) { |
| | int i; |
| | if ((i=eventindex(pin))<0) return 0; |
| | else { |
| | eventlist[i].enabled=1; |
| | return 1; |
| | } |
| | } |
| | void disableevent(mem_t pin) {} |
| | #endif |
| |
|
| |
|
| | #endif |
| |
|
| |
|