ts-7000
[Top] [All Lists]

[ts-7000] Re: Frame Buffer Programming ? Solved - example circle drawing

To:
Subject: [ts-7000] Re: Frame Buffer Programming ? Solved - example circle drawing program
From: "mattsaintdev" <>
Date: Mon, 07 Aug 2006 09:19:24 -0000
//
// Circle - modified from bitblt source code
// Compiled with Cygwin & cross compiler
// Target tested on Ts-7200 with TS-7KV video card
//
#include<unistd.h>
#include<sys/types.h>
#include<sys/mman.h>
#include<sys/time.h>
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<math.h>

volatile unsigned short *regs;

unsigned short *fb;
unsigned int yoffsets[639]; 

void setpixel(const int x, const int y, const unsigned short clr)
{
  register unsigned int p;
  p=x+yoffsets[y];
  if ((p>=0) && (p<=307199)) {// 307199 = 640*480-1
        fb[ p ]=clr;
  }

}

void clearvideo(unsigned short clr)
{
  register int idx;
  for(idx=0; idx<307200; idx++) { // 307200 = 640*480
       fb[idx]=clr;
  }
}


int imax(const int a, const int b)
{
    if (a>b) {
        return a;
    }
    else
    {
        return b;
    }
}

void linedda(const int xa, const int ya, const int xb, const int yb, 
const unsigned short clr)
{
  double dx=(double)(xb-xa);
  double dy=(double)(yb-ya);
  double x=(double) xa;
  double y=(double) ya;
  int adx,ady,k,steps;
  adx=abs(dx);
  ady=abs(dy);
  steps=imax(adx,ady);
  setpixel( (int)(x+0.5), (int)(y+0.5), clr);
  if (steps>0) {
    dx /=steps;
    dy /=steps;
    for(k=0; k<steps; k++) {
      x += dx;
      y += dy;
      setpixel( (int)(x+0.5), (int)(y+0.5), clr);    
    }
  } 
}


int main(int argc, char **argv) {
        float rx,ry,px,py, pi;
        unsigned short c;
        unsigned int idx, ix,iy,cx,cy;

        // slight speed up for setpixel calls 
        for(idx=0; idx<640; idx++) yoffsets[idx]=idx*640;

        int fd = open("/dev/mem", O_RDWR|O_SYNC);
        regs = (unsigned short *)mmap(0, 4096, PROT_READ|PROT_WRITE, 
MAP_SHARED, fd, 0x21800000 );
        fb = (unsigned short *)mmap(0, 640 * 480 * 2, 
PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x21800000 );
        regs += (0x30 / sizeof(unsigned short));
        regs[4] = 0x301;
        pi=0.0;        
        rx=319;
        ry=239;
        
        ix=px;
        iy=py;
        clearvideo(0);

        c=0x0001;

        px=sin(pi)*rx;
        py=cos(pi)*ry;
        cx=(int)px;
        cy=(int)py;


        while ((rx>1) && (ry>1)) {
           px=sin(pi)*rx;
           py=cos(pi)*ry;
           ix=320+(int)px;
           iy=240+(int)py;
           linedda(cx,cy,  ix,iy,c);
           cx=ix;
           cy=iy;
           c=c+0x8;
           pi=pi+0.2;
           rx=rx-0.025;
           ry=ry-0.015;
        }
 
        regs[4] = 0x300;
        close(fd);
        return 0;
}

 
Compile with;

$ /opt/crosstool/arm-unknown-linux-gnu/gcc-3.3.2-glibc-2.3.2/arm-
unknown-linux-gnu/bin/gcc -Wall -lm circle.c -o circle












 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/ts-7000/

<*> To unsubscribe from this group, send an email to:
    

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU