Thursday 29 August 2013

Tips for writing writting an good program in programming language

1.Know your objective

2.Draw an outline of your problem

3.Divide the problem into different small modules

4.Implement each module at once and individually and check if its working according to the specifications

5.If your program has to meet high specifications like(your logic should work for 1billion numbers,your app should run on any type of system........) first neglect it and and try to implement it sucessfully for small logic

6.Integrate all the modules int the order

7.Try  to compile the full program......

8.Then extend your program to high level or universal level that should meet its full specifications

Wednesday 28 August 2013

allegro game programming circle animations

#include<allegro.h>
BITMAP *buffer;
double radius=0;
int r=0,b=0,g=0;
int i=0;
int cx=0,cy=0;
int main()
{
    allegro_init();
    install_keyboard();
    set_color_depth(32);
    set_gfx_mode(GFX_AUTODETECT_WINDOWED,1200,700,0,0);
    srand(time(NULL));
    buffer=create_bitmap(SCREEN_W,SCREEN_H);
    srand(time(NULL));

                                         while((!key[KEY_ESC]))
                                         {
                                                             clear_bitmap(buffer);
                                                             cx=rand()%(SCREEN_W-100);
                                                             cy=rand()%(SCREEN_H-100);
                                                             radius=0;
                                                                 for(i=0;i<50;i++)
                                                                 {
                                                                 radius+=rand()%2;
                                                                  r=rand()%255;
                                                                  g=rand()%200+25;
                                                                  b=rand()%100+150;
                                                                  circle(buffer,cx,cy,radius,makecol(r,g,b));
                                                                  blit(buffer,screen,0,0,0,0,buffer->w,buffer->h);
                                                                  rest(4);
                                                                  }
                                                                      
                                                                       }
                                                                       //readkey();
                                                                       destroy_bitmap(buffer);
                                                                       }END_OF_MAIN();             

allegro programming corner animation

#include<allegro.h>
#include<stdlib.h>
int rect_x=0,rect_y=0;
BITMAP *buffer;
int r=0,b=0,g=0;
int radius=0;
int i=0;
int k=0;
int main()

{
    allegro_init();
    install_keyboard();
    set_color_depth(32);
    if(set_gfx_mode(GFX_AUTODETECT_WINDOWED,1200,700,0,0)!=0)
    {
                                                            set_gfx_mode(GFX_TEXT,0,0,0,0);
                                                            allegro_message("error in initiallization of screen");
                                                            allegro_exit();
                                                            exit(1);
                                                            }
                                                            srand(time(NULL));
                                                            buffer=create_bitmap(SCREEN_W,SCREEN_H);                                                           clear_bitmap(buffer);
                                                            srand(time(NULL));
                                                            rect_x=SCREEN_W/2;
                                                            rect_y=SCREEN_H/2;
                                                           
                                                            while((!key[KEY_ESC]))
                                                            {
                                                                                                 
                                                                                                  r=rand()%200+20;
                                                                                                  g=rand()%255;
                                                                                                  b=rand()%220;
                                                                                                  if(i==350) radius=0,i=0,k=0,clear_bitmap(buffer); 
                                                                                                  arc(buffer,0,SCREEN_H,64,0,radius,makecol(r,g,b));//right to bottom
                                                                                                  arc(buffer,0,0,64,0,radius,makecol(g,b,r));//left to bottom
                                                                                                  arc(buffer,SCREEN_W,0,-64,-128,radius,makecol(b,r,g));//top to left
                                                                                                  arc(buffer,SCREEN_W,SCREEN_H,64,0,radius,makecol(g,g,b));
                                                                                                  //circle(buffer,SCREEN_W/2,SCREEN_H/2,radius,makecol(0,0,0));
                                                                                                  //rect(buffer,rect_x-k,rect_y-k,rect_x+k,rect_y+k,makecol(0,0,0));
                                                                                                  blit(buffer,screen,0,0,0,0,buffer->w,buffer->h);
                                                                                                  radius+=4;
                                                                                                  i++;
                                                                                                  k+=2;
                                                                                                  rest(20);
                                                                                                  }
                                                                                                 
                                                                                                  destroy_bitmap(buffer);
                                                                                               
                                                                                                     }END_OF_MAIN();
                                                                                  


                          


                                                                                                 

memory organization in mips



HEAP:===>Dynamic memoey allocation
STACK==>local variables,fuction call addr,return add,local and formal arguments
 

Tuesday 27 August 2013

vhdl program for 2 input nor gate



library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity or_2 is
     port(
         a : in STD_LOGIC;
         b : in STD_LOGIC;
         c_or : out STD_LOGIC
         );
end or_2;

--}} End of automatically maintained section

architecture or_df of or_2 is
begin
   
    c_or <= a or b;

     -- enter your statements here --

end or_df;

vhdl program for 2 input nand gate

---------------------------------------------------------------------------------------------------
--
-- Title       : nand_2
-- Design      : and1
-- Author      : rajashekar
-- Company     : kits
--
---------------------------------------------------------------------------------------------------
--
-- File        : nand_2.vhd
-- Generated   : Sat Jun 29 14:17:43 2013
-- From        : interface description file
-- By          : Itf2Vhdl ver. 1.20
--
---------------------------------------------------------------------------------------------------
--
-- Description :
--
---------------------------------------------------------------------------------------------------

--{{ Section below this comment is automatically maintained
--   and may be overwritten
--{entity {nand_2} architecture {nand_df}}

library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity nand_2 is
     port(
         a : in STD_LOGIC;
         b : in STD_LOGIC;
         c_nand : out STD_LOGIC
         );
end nand_2;

--}} End of automatically maintained section

architecture nand_df of nand_2 is
begin
   
    c_nand <= a nand b;

     -- enter your statements here --

end nand_df;

vhdl program to evaluate an function using mux

---------------------------------------------------------------------------------------------------
--
-- Title       : mux_fun1
-- Design      : and1
-- Author      : rajashekar
-- Company     : kits
--
---------------------------------------------------------------------------------------------------
--
-- File        : mux_fun1.vhd
-- Generated   : Wed Jul 17 18:31:30 2013
-- From        : interface description file
-- By          : Itf2Vhdl ver. 1.20
--
---------------------------------------------------------------------------------------------------
--
-- Description :
--
---------------------------------------------------------------------------------------------------

--{{ Section below this comment is automatically maintained
--   and may be overwritten
--{entity {mux_fun1} architecture {muxfun1}}

library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity mux_fun1 is
    port (--a:in STD_LOGIC_VECTOR (0 to 7);
    sel:in STD_LOGIC_VECTOR (0 to 2);
    c:out STD_LOGIC
    );
end mux_fun1;

--}} End of automatically maintained section

architecture muxfun1 of mux_fun1 is

component mux_81 is
        port (i:in STD_LOGIC_VECTOR (0 to 7);
    s:in STD_LOGIC_VECTOR (0 to 2);
    y:out STD_LOGIC
    );
end component ;


begin
   
    i0:mux_81 port map ("10010011",sel,c);
    --i1:mux_81 port map (a,'0',c);
    --i2:mux_81 port map (a,'0',c);
    --i3:mux_81 port map (a,'1',c);
    --i4:mux_81 port map (a,'0',c);
    --i5:mux_81 port map (a,'0',c);
    --i6:mux_81 port map (a,'1',c);
    --i7:mux_81 port map (a,'1',c);
   
   

     -- enter your statements here --

end muxfun1;