00001
00002
00003
00004
00005
00006
00007 #include <stdio.h>
00008 #include <string.h>
00009 #include <avr/io.h>
00010 #include <cio.h>
00011 #include "CursesDev.h"
00012
00018 static int WOpen(IOCB *pIOCB) __attribute__((section(".lowtext")));
00019 static int WClose(IOCB *pIOCB) __attribute__((section(".lowtext")));
00020 static int WGetC(IOCB *pIOCB) __attribute__((section(".lowtext")));
00021 static int WRead(IOCB *pIOCB,char *b, int n) __attribute__((section(".lowtext")));
00022 static int WPutC(IOCB *pIOCB,int c) __attribute__((section(".lowtext")));
00023 static int WWrite(IOCB *pIOCB,char *b, int n) __attribute__((section(".lowtext")));
00024 static int WStatus(IOCB *pIOCB,int m) __attribute__((section(".lowtext")));
00025 static int WXio(IOCB *pIOCB,int cmd,void *pP) __attribute__((section(".lowtext")));
00026 static int WInit(void) __attribute__((section(".lowtext")));
00027
00028 static H_JVEC WJump = {
00029 WOpen,
00030 WClose,
00031 WGetC,
00032 WRead,
00033 WPutC,
00034 WWrite,
00035 WStatus,
00036 WXio,
00037 WInit
00038 };
00039
00057 static int WOpen(IOCB *pIOCB)
00058 {
00059 char *pC,*pN;
00060
00061 pIOCB->p = NULL;
00062 pC = strchr(pIOCB->dev_name,':');
00063 if(pC)
00064 {
00065 ++pC;
00066 pN = malloc(strlen(pC)+1);
00067 strcpy(pN,pC);
00068 pIOCB->dev_name = pN;
00069 }
00070 else
00071 pIOCB->dev_name = NULL;
00072 return 0;
00073 }
00074
00082 static int WClose(IOCB *pIOCB)
00083 {
00084 if(pIOCB->dev_name) free(pIOCB->dev_name);
00085 return 0;
00086 }
00087
00094 static int WGetC(IOCB *pIOCB)
00095 {
00096 return 0;
00097 }
00098
00108 static int WRead(IOCB *pIOCB,char *b, int n)
00109 {
00110 return 0;
00111 }
00112
00120 static int WPutC(IOCB *pIOCB,int c)
00121 {
00122 WINDOW *pW = (WINDOW *)pIOCB->p;
00123 waddch(pW,c);
00124 return 0;
00125 }
00126
00136 static int WWrite(IOCB *pIOCB,char *b, int n)
00137 {
00138 int i;
00139 WINDOW *pW = (WINDOW *)pIOCB->p;
00140 for(i=0;i<n;++i)
00141 waddch(pW,b[i]);
00142 return 0;
00143 }
00144
00153 static int WStatus(IOCB *pIOCB,int m)
00154 {
00155 return 0;
00156 }
00157
00167 static int WXio(IOCB *pIOCB,int cmd,void *pP)
00168 {
00169 struct _Wparams *pWP;
00170 WINDOW *pW;
00171 int retval = 0;
00172 switch(cmd)
00173 {
00174 case CURSESDEV_XIO_CREATEWINDOW:
00175 pWP = (struct _Wparams *)pP;
00176
00177 pW = newwin(pWP->ysize,pWP->xsize,pWP->ypos,pWP->xpos,NULL,FG(pWP->fg) | BG(pWP->bg),1);
00178 scrollok(pW,pWP->mode);
00179 if(pIOCB->dev_name)
00180 WinSetTitle(pW,pIOCB->dev_name);
00181 pIOCB->p= (void *)pW;
00182 break;
00183 }
00184 return retval;
00185 }
00186
00187 static int WInit(void)
00188 {
00189 CioAddHandler("W",&WJump);
00190 return 0;
00191 }
00192
00198 void CursesDevInit(void)
00199 {
00200 WInit();
00201 }
00202
00216 void InitWParams(struct _Wparams *pWP,int xpos,int ypos, int xsize,int ysize,int fg, int bg, int mode)
00217 {
00218 pWP->xpos = xpos;
00219 pWP->ypos = ypos;
00220 pWP->xsize = xsize;
00221 pWP->ysize = ysize;
00222 pWP->fg = fg;
00223 pWP->bg = bg;
00224 pWP->mode = mode;
00225 }