Exemplo n.º 1
0
void umul32x64(uint32_t factor1, FAR const struct uint64_s *factor2,
              FAR struct uint64_s *product)
{
  struct uint64_s part1;
  struct uint64_s part2;

  /* factor2 = factor2->ms << 32 + factor2->ls
   *
   * Full 128-bit product:
   *   factor1 * factor2 = factor1 * (factor2->ms << 32) +
   *                       factor1 * factor2->ls
   */

  /* Get part1 = factor1 * factor2->ms, shifting left by 32-bits
   * (truncating to 64-bits)
   */

  part1.ms = factor1 * factor2->ms;
  part1.ls = 0;

  /* Get the full 64-bit part2 = factor1 * factor2->ls */

  umul32(factor1, factor2->ls, &part2);

  /* The product is then the sum */

  uadd64(&part1, &part2, product);
}
Exemplo n.º 2
0
void umul64(FAR const struct uint64_s *factor1,
            FAR const struct uint64_s *factor2,
            FAR struct uint64_s *product)
{
  struct uint64_s part1;
  struct uint64_s part2;

  /* factor1 = factor1->ms << 32 + factor1->ls
   * factor2 = factor2->ms << 32 + factor2->ls
   *
   * Full 128-bit product:
   *   factor1 * factor2 = (factor1->ms * factor2->ms << 64) +
   *                       factor1->ls * (factor2->ms << 32) +
   *                       factor2->ls * (factor1->ms << 32) +
   *                       factor1->ls * factor2->ls
   *
   * Truncated, 64-bit product:
   *   factor1 * factor2 = (factor1->ls * factor2->ms +
   *                        factor2->ls * factor1->ms) << 32) +
   *                       factor1->ls * factor2->ls
   *
   *   part1             = (factor1->ls * factor2->ms +
   *                       factor2->ls * factor1->ms) << 32)
   *   part2             = factor1->ls * factor2->ls
   *   factor1 * factor2 = part1 + part2
   */

  /* Get part1 = factor1->ls * factor2->ms + factor2->ls * factor1->ms,
   * shifting left by 32-bits (truncating to 64-bits)
   */

  part1.ms = factor1->ls * factor2->ms +
             factor2->ls * factor2->ms;
  part1.ls = 0;

  /* Get the full 64-bit part2 = factor1->ls * factor2->ls */

  umul32(factor1->ls, factor2->ls, &part2);

  /* The product is then the sum */

  uadd64(&part1, &part2, product);
}
Exemplo n.º 3
0
long atol(char *string) {
    long result = 0;
    unsigned long digit;
    int sign;

    /*
     * Skip any leading blanks.
     */

    //while (*string = ' ') {
	//string += 1;
    //}

    /*
     * Check for a sign.
     */

    if (*string == '-') {
	sign = 1;
	string += 1;
    } else {
	sign = 0;
	if (*string == '+') {
	    string += 1;
	}
    }

    for ( ; ; string += 1) {
	digit = *string - '0';
	if (digit > 9) {
	    break;
	}
	result = umul32(10, result) + digit;
    }

    if (sign) {
	return ~result + 1;
    }
    return result;
}
Exemplo n.º 4
0
void _GrScanEllipse(int xc,int yc,int xa,int ya,GrFiller *f,GrFillArg c,int filled)
{
    int x1,x2,y1,y2;
    if(xa < 0) xa = (-xa);
    if(ya < 0) ya = (-ya);
    x1 = xc - xa;
    y1 = yc - ya;
    x2 = xc + xa;
    y2 = yc + ya;
    clip_ordbox(CURC,x1,y1,x2,y2);
    mouse_block(CURC,x1,y1,x2,y2);
    setup_ALLOC();
    if((xa == 0) || (ya == 0)) (*f->line)(
            (x1 + CURC->gc_xoffset),
            (y1 + CURC->gc_yoffset),
            (x2 - x1),
            (y2 - y1),
            c
        );
    else if((xa > MAXR) || (ya > MAXR)) {   /* Bresenham would overflow !! */
        int (*points)[2] = ALLOC(sizeof(int) * 2 * GR_MAX_ELLIPSE_POINTS);
        if(points != NULL) {
            int count = GrGenerateEllipse(xc,yc,xa,ya,points);
            if(filled) _GrScanConvexPoly(count,points,f,c);
            else       _GrDrawPolygon(count,points,f,c,TRUE);
            FREE(points);
        }
    }
    else {
        int *scans = ALLOC(sizeof(int) * (ya + 1));
        int  row   = ya;
        int  col   = 0;
        if(scans != NULL) {
            long yasq  = umul32(ya,ya);
            long xasq  = umul32(xa,xa);
            long xasq2 = xasq + xasq;
            long yasq2 = yasq + yasq;
            long xasq4 = xasq2 + xasq2;
            long yasq4 = yasq2 + yasq2;
            long error = (xasq2 * (row - 1) * row) +
                         (yasq2 * (1 - xasq))      +
                         xasq;
            while((xasq * row) > (yasq * col)) {
                if(error >= 0) {
                    scans[row] = col;
                    row--;
                    error -= xasq4 * row;
                }
                error += yasq2 * (3 + (col << 1));
                col++;
            }
            error = (yasq2 * (col + 1) * col)         +
                    (xasq2 * ((row * (row - 2)) + 1)) +
                    (yasq  * (1 - xasq2));
            while(row >= 0) {
                scans[row] = col;
                if(error <= 0) {
                    col++;
                    error += yasq4 * col;
                }
                row--;
                error += xasq2 * (2 - (row << 1));
            }
            for(row = y1; row <= y2; row++) {
                col = iabs(yc - row);
                if(!filled && (col < ya)) {
                    x1 = xc - scans[col];
                    x2 = xc - scans[col + 1];
                    if(x1 < x2) x2--;
                    do {
                        clip_ordxrange_(CURC,x1,x2,break,CLIP_EMPTY_MACRO_ARG);
                        (*f->scan)(
                            (x1  + CURC->gc_xoffset),
                            (row + CURC->gc_yoffset),
                            (x2  - x1 + 1),
                            c
                        );
                    } while (0);
                    x1 = xc + scans[col + 1];
                    x2 = xc + scans[col];
                    if(x1 < x2) x1++;
                }
                else {
                    x1 = xc - scans[col];
                    x2 = xc + scans[col];
                }
                clip_ordxrange_(CURC,x1,x2,continue,CLIP_EMPTY_MACRO_ARG);
                (*f->scan)(
                    (x1  + CURC->gc_xoffset),
                    (row + CURC->gc_yoffset),
                    (x2  - x1 + 1),
                    c
                );
            }
Exemplo n.º 5
0
int GrSetMode(GrGraphicsMode which,...)
{
    int  w,h,pl,vw,vh;
    int  t,noclear,res;
    GrColor c;
    va_list ap;
    GRX_ENTER();
    pl = 0;
    vw = 0;
    vh = 0;
    t = FALSE;
    noclear = FALSE;
    c = 0;
    res = FALSE;
    DBGPRINTF(DBG_SETMD,("Mode: %d\n",(int)which));
    if(DRVINFO->vdriver == NULL) {
        GrSetDriver(NULL);
        if(DRVINFO->vdriver == NULL) {
            res = errhdlr("could not find suitable video driver");
            goto done;
        }
    }
    va_start(ap,which);
    switch(which) {
    case GR_NC_default_text:
        noclear = TRUE;
    case GR_default_text:
        w = DRVINFO->deftw;
        h = DRVINFO->defth;
        c = DRVINFO->deftc;
        t = TRUE;
        break;
    case GR_NC_320_200_graphics:
        noclear = TRUE;
    case GR_320_200_graphics:
        w = 320;
        h = 200;
        c = DRVINFO->defgc;
        break;
    case GR_NC_default_graphics:
        noclear = TRUE;
    case GR_default_graphics:
        w = DRVINFO->defgw;
        h = DRVINFO->defgh;
        c = DRVINFO->defgc;
        break;
    case GR_NC_width_height_graphics:
        noclear = TRUE;
    case GR_width_height_graphics:
        w = va_arg(ap,int);
        h = va_arg(ap,int);
        c = DRVINFO->defgc;
        break;
    case GR_NC_biggest_graphics:
        noclear = TRUE;
    case GR_biggest_graphics:
        w = DRVINFO->biggw;
        h = DRVINFO->biggh;
        pl = 32;
        break;
    case GR_NC_width_height_color_graphics:
        noclear = TRUE;
    case GR_width_height_color_graphics:
        w = va_arg(ap,int);
        h = va_arg(ap,int);
        c = va_arg(ap,GrColor);
        break;
    case GR_NC_width_height_bpp_graphics:
        noclear = TRUE;
    case GR_width_height_bpp_graphics:
        w  = va_arg(ap,int);
        h  = va_arg(ap,int);
        pl = va_arg(ap,int);
        break;
    case GR_NC_custom_graphics:
        noclear = TRUE;
    case GR_custom_graphics:
        w  = va_arg(ap,int);
        h  = va_arg(ap,int);
        c  = va_arg(ap,GrColor);
        vw = va_arg(ap,int);
        vh = va_arg(ap,int);
        break;
    case GR_NC_custom_bpp_graphics:
        noclear = TRUE;
    case GR_custom_bpp_graphics:
        w  = va_arg(ap,int);
        h  = va_arg(ap,int);
        pl = va_arg(ap,int);
        vw = va_arg(ap,int);
        vh = va_arg(ap,int);
        break;
    default:
        va_end(ap);
        res = errhdlr("unknown video mode");
        goto done;
    }
    va_end(ap);
    if (c)
        for(pl = 1; (pl < 32) && ((1UL << pl) < (GrColor)c); pl++) ;
    for( ; ; ) {
        GrContext     cxt;
        GrFrameDriver fdr;
        GrVideoMode  *mdp,vmd;
        mdp = (DRVINFO->vdriver->selectmode)(DRVINFO->vdriver,w,h,pl,t,NULL);
        if(!mdp) {
            res = errhdlr("could not find suitable video mode");
            goto done;
        }
        sttcopy(&vmd,mdp);
        if((t || buildframedriver(&vmd,&fdr)) &&
                (*vmd.extinfo->setup)(&vmd,noclear) &&
                (t || buildcontext(&vmd,&fdr,&cxt))) {
            if((!t) &&
                    ((vw > vmd.width) || (vh > vmd.height)) &&
                    (vmd.extinfo->setvsize != NULL) &&
                    (vmd.extinfo->scroll   != NULL)) {
                int ww = vmd.width  = imax(vw,vmd.width);
                int hh = vmd.height = imax(vh,vmd.height);
                if(!(*vmd.extinfo->setvsize)(&vmd,ww,hh,&vmd) ||
                        !buildcontext(&vmd,&fdr,&cxt)) {
                    sttcopy(&vmd,mdp);
                    buildcontext(&vmd,&fdr,&cxt);
                    (*vmd.extinfo->setup)(&vmd,noclear);
                }
            }
//		DBGPRINTF(DBG_SETMD,("GrMouseUnInit ...\n"));
//		GrMouseUnInit();
//		DBGPRINTF(DBG_SETMD,("GrMouseUnInit done\n"));
            DRVINFO->setbank    = (void (*)(int    ))_GrDummyFunction;
            DRVINFO->setrwbanks = (void (*)(int,int))_GrDummyFunction;
            DRVINFO->curbank    = (-1);
            DRVINFO->splitbanks = FALSE;
            if(!t) {
                if(vmd.extinfo->setbank) {
                    DRVINFO->setbank = vmd.extinfo->setbank;
                }
                if(vmd.extinfo->setrwbanks) {
                    DRVINFO->setrwbanks = vmd.extinfo->setrwbanks;
                    DRVINFO->splitbanks = TRUE;
                }
                if(umul32(vmd.lineoffset,vmd.height) <= 0x10000L) {
                    DRVINFO->splitbanks = TRUE;
                }
            }
            else {
                sttzero(&cxt);
                sttcopy(&fdr,&DRVINFO->tdriver);
                cxt.gc_driver = &DRVINFO->tdriver;
            }
            sttcopy(&CXTINFO->current,&cxt);
            sttcopy(&CXTINFO->screen, &cxt);
            sttcopy(&DRVINFO->fdriver,&fdr);
            sttcopy(&DRVINFO->sdriver,&fdr);
            sttcopy(&DRVINFO->actmode,&vmd);
            DRVINFO->curmode = mdp;
            DRVINFO->mcode   = which;
            DRVINFO->vposx   = 0;
            DRVINFO->vposy   = 0;
            DBGPRINTF(DBG_SETMD,("GrResetColors ...\n"));
            if ( !_GrResetColors() ) {
                res = errhdlr("could not set color mode");
                goto done;
            }
            DBGPRINTF(DBG_SETMD,("GrResetColors done\n"));
            if(fdr.init) {
                DBGPRINTF(DBG_SETMD,("fdr.init ...\n"));
                (*fdr.init)(&DRVINFO->actmode);
                DBGPRINTF(DBG_SETMD,("fdr.init done\n"));
            }
            if(DRVINFO->mdsethook) {
                DBGPRINTF(DBG_SETMD,("mdsethook ...\n"));
                (*DRVINFO->mdsethook)();
                DBGPRINTF(DBG_SETMD,("mdsethook done\n"));
            }
            DBGPRINTF(DBG_SETMD,("GrSetMode complete\n"));
            res = TRUE;
            goto done;
        }
        mdp->present = FALSE;
    }
done:
    GRX_RETURN(res);
}
Exemplo n.º 6
0
static int buildcontext(GrVideoMode *mp,GrFrameDriver *fdp,GrContext *cxt)
{
    long plsize;
    int res;
    GRX_ENTER();
    res = FALSE;
    plsize = umul32(mp->lineoffset,mp->height);
    DBGPRINTF(DBG_SETMD,("buildcontext - Mode Frame buffer = 0x%x\n",mp->extinfo->frame));
    DBGPRINTF(DBG_SETMD,("buildcontext - Mode Frame selector = 0x%x\n",mp->extinfo->LFB_Selector));
    sttzero(cxt);
#if !(defined(__XWIN__) && !defined(XF86DGA_FRAMEBUFFER))
    if(mp->extinfo->flags&GR_VMODEF_LINEAR)
    {
        DBGPRINTF(DBG_SETMD,("buildcontext - Linear Mode\n"));
        cxt->gc_baseaddr[0] =
            cxt->gc_baseaddr[1] =
                cxt->gc_baseaddr[2] =
                    cxt->gc_baseaddr[3] = LINP_PTR(mp->extinfo->frame);
        cxt->gc_selector    = mp->extinfo->LFB_Selector;
    } else
#endif
        if (mp->extinfo->flags&GR_VMODEF_MEMORY)
        {
            DBGPRINTF(DBG_SETMD,("buildcontext - Memory Mode\n"));
            if(plsize > fdp->max_plane_size) goto done; /* FALSE */
            if(mp->lineoffset % fdp->row_align) goto done; /* FALSE */
            DBGPRINTF(DBG_SETMD,("buildcontext - mp->present    = %d\n",mp->present));
            DBGPRINTF(DBG_SETMD,("buildcontext - mp->bpp        = %d\n",mp->bpp));
            DBGPRINTF(DBG_SETMD,("buildcontext - mp->width      = %d\n",mp->width));
            DBGPRINTF(DBG_SETMD,("buildcontext - mp->height     = %d\n",mp->height));
            DBGPRINTF(DBG_SETMD,("buildcontext - mp->mode       = %d\n",mp->mode));
            DBGPRINTF(DBG_SETMD,("buildcontext - mp->lineoffset = %d\n",mp->lineoffset));
            DBGPRINTF(DBG_SETMD,("buildcontext - mp->ext->mode  = %d\n",mp->extinfo->mode));
            DBGPRINTF(DBG_SETMD,("buildcontext - mp->ext->flags = %x\n",mp->extinfo->flags));
#ifdef GRX_USE_RAM3x8
            if (mp->bpp==24)
            {
                int m_incr = mp->lineoffset*mp->height;
                cxt->gc_baseaddr[0] = mp->extinfo->frame;
                cxt->gc_baseaddr[1] = cxt->gc_baseaddr[0] + m_incr;
                cxt->gc_baseaddr[2] = cxt->gc_baseaddr[1] + m_incr;
                cxt->gc_baseaddr[3] = NULL;
            }
            else
#endif
                if (mp->bpp==4)
                {
                    int m_incr = mp->lineoffset*mp->height;
                    cxt->gc_baseaddr[0] = mp->extinfo->frame;
                    cxt->gc_baseaddr[1] = cxt->gc_baseaddr[0] + m_incr;
                    cxt->gc_baseaddr[2] = cxt->gc_baseaddr[1] + m_incr;
                    cxt->gc_baseaddr[3] = cxt->gc_baseaddr[2] + m_incr;
                }
                else
                {
                    cxt->gc_baseaddr[0] =
                        cxt->gc_baseaddr[1] =
                            cxt->gc_baseaddr[2] =
                                cxt->gc_baseaddr[3] = mp->extinfo->frame;
                }
        }
        else
        {
            if(plsize > fdp->max_plane_size) goto done; /* FALSE */
            if(!mp->extinfo->setbank && (plsize > 0x10000L)) goto done; /* FALSE */
            if(mp->lineoffset % fdp->row_align) goto done; /* FALSE */
            cxt->gc_baseaddr[0] =
                cxt->gc_baseaddr[1] =
                    cxt->gc_baseaddr[2] =
                        cxt->gc_baseaddr[3] = LINP_PTR(mp->extinfo->frame);
            cxt->gc_selector    = LINP_SEL(mp->extinfo->frame);
        }
    cxt->gc_onscreen    = !(mp->extinfo->flags&GR_VMODEF_MEMORY);
    /* Why do we default to screen driver ?? */
    cxt->gc_onscreen    = TRUE;
    cxt->gc_lineoffset  = mp->lineoffset;
    cxt->gc_xcliphi     = cxt->gc_xmax = mp->width  - 1;
    cxt->gc_ycliphi     = cxt->gc_ymax = mp->height - 1;
    cxt->gc_driver      = &DRVINFO->sdriver;

    res = TRUE;

    DBGPRINTF(DBG_SETMD,("buildcontext - context buffer 0 = 0x%x\n",cxt->gc_baseaddr[0]));
    DBGPRINTF(DBG_SETMD,("buildcontext - context buffer 1 = 0x%x\n",cxt->gc_baseaddr[1]));
    DBGPRINTF(DBG_SETMD,("buildcontext - context buffer 2 = 0x%x\n",cxt->gc_baseaddr[2]));
    DBGPRINTF(DBG_SETMD,("buildcontext - context buffer 3 = 0x%x\n",cxt->gc_baseaddr[3]));
done:
    GRX_RETURN(res);
}