gonzui


Format: Advanced Search

tkernel_2/driver/tef_em1d/screen/src/main.cbare sourcepermlink (0.02 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    T-Kernel 2.0 Software Package
    4:  *
    5:  *    Copyright 2011 by Ken Sakamura.
    6:  *    This software is distributed under the latest version of T-License 2.x.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by T-Engine Forum(http://www.t-engine.org/) at 2011/05/17.
   10:  *    Modified by T-Engine Forum at 2013/03/11.
   11:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/01.
   12:  *
   13:  *----------------------------------------------------------------------
   14:  */
   15: 
   16: /*
   17:         main.C          screen driver : main part
   18:  *
   19:  */
   20: #include "screen.h"
   21: 
   22: LOCAL   BOOL      suspended;           /* suspended state     */
   23: LOCAL   SDI       ScrSdi;                       /* device driver I/F handle */
   24: 
   25: #define Read    0x01
   26: #define Write   0x02
   27: #define R_OK    Read
   28: #define W_OK    Write
   29: #define RW_OK   (R_OK | W_OK)
   30: 
   31: /*
   32:         check parameter & set up address space
   33:                 = E_OK : OK (size == 0)
   34:                 > E_OK : OK (size > 0)
   35:                 < E_OK : error
   36: */
   37: LOCAL   ER        checkParam(INT mode, INT size, W dsz, W okpat)
   38: {
   39:         if (dsz <= 0) return E_OBJ;
   40: 
   41:         if ((mode & okpat) == 0) return E_PAR;
   42: 
   43:         if (size < 0 || (size > 0 && size < dsz)) return E_PAR;
   44: 
   45:         return (size == 0) ? E_OK : (E_OK + 1);
   46: }
   47: /*
   48:         perform I/O requests
   49: */
   50: LOCAL   INT       rwfn(INT mode, INT start, INT size, void *buf)
   51: {
   52:         INT    er;
   53:         W      dsz;
   54:         BOOL   set = (mode == Write);
   55: 
   56:         switch (start) {
   57:         case DN_SCRSPEC:
   58:                 dsz = sizeof(DEV_SPEC);
   59:                 if ((er = checkParam(mode, size, dsz, R_OK)) > E_OK)
   60:                         er = getSCRSPEC((DEV_SPEC*)buf);
   61:                 break;
   62:         case DN_SCRLIST:
   63:                 dsz = getSCRLIST(NULL);
   64:                 if ((er = checkParam(mode, size, dsz, R_OK)) > E_OK)
   65:                         er = getSCRLIST((TC*)buf);
   66:                 break;
   67:         case DN_SCRNO:
   68:                 dsz = sizeof(W);
   69:                 if ((er = checkParam(mode, size, dsz, RW_OK)) > E_OK)
   70:                         er = getsetSCRNO((W*)buf, suspended, set);
   71:                 break;
   72:         case DN_SCRCOLOR:
   73:                 dsz = getsetSCRCOLOR(NULL, FALSE);
   74:                 if ((er = checkParam(mode, size, dsz, RW_OK)) > E_OK)
   75:                         er = getsetSCRCOLOR((COLOR*)buf, set);
   76:                 break;
   77:         case DN_SCRBMP:
   78:                 dsz = sizeof(BMP);
   79:                 if ((er = checkParam(mode, size, dsz, R_OK)) > E_OK)
   80:                         er = getSCRBMP((BMP*)buf);
   81:                 break;
   82:         case DN_SCRBRIGHT:
   83:                 dsz = sizeof(W);
   84:                 if ((er = checkParam(mode, size, dsz, RW_OK)) > E_OK)
   85:                         er = getsetSCRBRIGHT((W*)buf, set);
   86:                 break;
   87:         case DN_SCRUPDFN:
   88:                 dsz = sizeof(FP);
   89:                 if ((er = checkParam(mode, size, dsz, R_OK)) > E_OK)
   90:                         er = getSCRUPDFN((FP*)buf);
   91:                 break;
   92:         case DN_SCRVFREQ:
   93:                 dsz = sizeof(W);
   94:                 if ((er = checkParam(mode, size, dsz, RW_OK)) > E_OK)
   95:                         er = getsetSCRVFREQ((W*)buf, set);
   96:                 break;
   97:         case DN_SCRADJUST:
   98:                 dsz = sizeof(ScrAdjust);
   99:                 if ((er = checkParam(mode, size, dsz, RW_OK)) > E_OK)
  100:                         er = getsetSCRADJUST((ScrAdjust*)buf, set);
  101:                 break;
  102:         case DN_SCRDEVINFO:
  103:                 dsz = sizeof(ScrDevInfo);
  104:                 if ((er = checkParam(mode, size, dsz, R_OK)) > E_OK)
  105:                         er = getSCRDEVINFO((ScrDevInfo*)buf);
  106:                 break;
  107:         case DN_SCRMEMCLK:
  108:                 dsz = 0;
  109:                 er = E_NOSPT;
  110:                 break;
  111:         case DN_SCRUPDRECT:
  112:                 dsz = sizeof(RECT);
  113:                 if ((er = checkParam(mode, size, dsz, W_OK)) > E_OK)
  114:                         er = setSCRUPDRECT((RECT*)buf);
  115:                 break;
  116:         case DN_SCRWRITE:
  117:                 dsz = size;
  118:                 if ((er = checkParam(mode, size, dsz, W_OK)) > E_OK)
  119:                         er = setSCRWRITE(0, buf, dsz);
  120:                 break;
  121:         default:
  122:                 if (start <= DN_SCRXSPEC(1) && start >= DN_SCRXSPEC(255)) {
  123:                         dsz = sizeof(DEV_SPEC);
  124:                         if ((er = checkParam(mode, size, dsz, R_OK)) > E_OK)
  125:                                 er = getSCRXSPEC((DEV_SPEC*)buf,
  126:                                                  DN_SCRXSPEC(1) - start);
  127:                 } else {
  128:                         dsz = 0;
  129:                         er = E_PAR;
  130:                 }
  131:                 break;
  132:         }
  133:         return (er < E_OK) ? er : dsz;
  134: }
  135: /*
  136:         input processing
  137: */
  138: LOCAL   INT       readfn(ID devid, INT start, INT size, void *buf, SDI sdi)
  139: {
  140:         return rwfn(Read, start, size, buf);
  141: }
  142: /*
  143:         output processing
  144: */
  145: LOCAL   INT       writefn(ID devid, INT start, INT size, void *buf, SDI sdi)
  146: {
  147:         return rwfn(Write, start, size, buf);
  148: }
  149: /*
  150:         event processing (suspend / resume)
  151: */
  152: LOCAL   INT       eventfn(INT evttyp, void *evtinf, SDI sdi)
  153: {
  154:         INT    er;
  155: 
  156:         switch (evttyp) {
  157:         case   TDV_SUSPEND:
  158:                 if (suspended == FALSE) {
  159:                         suspendSCREEN();
  160:                         suspended = TRUE;
  161:                 }
  162:                 er = E_OK;
  163:                 break;
  164: 
  165:         case   TDV_RESUME:
  166:                 if (suspended == TRUE) {
  167:                         suspended = FALSE;
  168:                         resumeSCREEN();
  169:                 }
  170:                 er = E_OK;
  171:                 break;
  172: 
  173:         default:
  174:                 er = E_ILUSE;
  175:         }
  176: 
  177:         return er;
  178: }
  179: /*
  180:         startup
  181: */
  182: EXPORT  ER       ScreenDrv(INT ac, UB *av[])
  183: {
  184:         ER     er;
  185:         T_IDEV idev;
  186:         static const SDefDev   ddev = {
  187:                 NULL,         /* exinf */
  188:                 "SCREEN",     /* devnm */
  189:                 0,            /* drvatr */
  190:                 0,            /* devatr */
  191:                 0,            /* nsub */
  192:                 1,            /* blksz */
  193:                 NULL,         /* open */
  194:                 NULL,         /* close */
  195:                 readfn,               /* read */
  196:                 writefn,      /* write */
  197:                 eventfn,      /* event */
  198:         };
  199:         W      v[L_DEVCONF_VAL];
  200: 
  201:         /* effective? */
  202:         if (GetDevConf("ScreenDrvEnable", v) > 0 && !v[0]) return E_NOSPT;
  203: 
  204:         /* epilog processing */
  205:         if (ac < 0) {
  206:                 if (Vinf.attr & NEED_FINPROC) (*(Vinf.fn_setmode))(-1);
  207:                 return E_OK;
  208:         }
  209: 
  210:         /* initialization */
  211:         suspended = FALSE;
  212: 
  213:         /* device initialization processing */
  214:         if ((er = initSCREEN()) < E_OK) goto EEXIT;
  215: 
  216:         /* register device */
  217:         er = SDefDevice(&ddev, &idev, &ScrSdi);
  218:         if (er < E_OK) finishSCREEN();
  219: 
  220:  EEXIT:
  221:         return er;
  222: }