So I am drawing stuff to the screen and decide to check how fast my redraws are my fps sit around 90 with no lighting on the screen to something like 30 with ONE source on the screen.... This is my redraw routine:

using allegro/msvc++.net/win xp

I am looking for ways to trim it down to a nicer looking function. Any ideas are appreciated. Any questions just reply and I will post the relevant code or info. At this point switching to SDL GL DX etc can not happen this project is nearly done just tweaking what I can.

I have heard of using dirty rectangles, just not sure about how to implement them in this case.
Code:
void RedrawScreen()
{
	if(FPSCNT == 0)FPSCNT = GetTickCount();
	FPS++;
	int mm,nm;
	mm = player->GetY() - 10;
	nm = player->GetX() - 14;
	blit(LAYOUT,BUFFER,0,0,0,0,scrx,scry);
	for(int m = 0;m < 21;m++)
	{
		for(int n = 0;n < 29;n++)
		{
			
			if(mm+m < 0 || nm+n < 0 || mm+m >= mymap->GetY() || nm+n >= mymap->GetX())
			{
					
			}else
			{
				blit(mymap->GetTile(nm+n,mm+m),BUFFER,0,0,48+(n<<5),48+(m<<5),32,32);
				
			}
			if(m == 11 && n == 14)
			{
				try
				{
				if(!player->SwingingSword())masked_blit(player->GetImage(),BUFFER,(direction*3+step)*charx,0,(scrx/2)-(charx/2),(scry/2)-(chary/2)-16,charx,chary);
				else masked_blit(player->GetImage(),BUFFER,(direction*3+step)*charx,chary,(scrx/2)-(charx/2),(scry/2)-(chary/2)-16,charx,chary);
				}
				catch(...)
				{
					
				}
			}
			int p;//added by DarkAlloy(fixes scoping issue)
			for(	p = 0;p < mymap->GetNumNPC();p++)
			{
				tmpNPC = mymap->GetNPC(p);
				if(tmpNPC != NULL && tmpNPC->GetX() == nm+n && tmpNPC->GetY() == mm+m)
				{
					masked_blit(tmpNPC->GetIGPic(),BUFFER,(DOWN*3+tmpNPC->GetStep())*charx,0,48+n*32-(charx>>1)+16,48+m*32-(chary>>1),charx,chary);			
				}
			}
			for(    p = 0;p < mymap->GetNumMonster();p++)
			{
				tmpMonster = mymap->GetMonster(p);
				if(tmpMonster != NULL && tmpMonster->GetX() == nm+n && tmpMonster->GetY() == mm+m)
				{
					if(tmpMonster->IsDead())
					{
						masked_blit(tmpMonster->GetPic(),BUFFER,((GetTickCount()-tmpMonster->GetTick())/150)*charx,chary,48+n*32-(charx/2)+16,48+m*32-(chary/2),charx,chary);
						if(GetTickCount()-tmpMonster->GetTick() > 450 )
						{
							mymap->DestroyMonster(p);
						}
					}else
					masked_blit(tmpMonster->GetPic(),BUFFER,(DOWN*3+step)*charx,0,48+n*32-(charx>>1)+16,48+m*32-(chary>>1),charx,chary);			
				}
			}
		}
	}
	int zmz;//added by DarkAlloy(fixes scoping issue)
	for(	zmz=0;zmz<10;zmz++)
	{
		if(DamageFloats[zmz].damage != -1 && DamageFloats[zmz].x >= 0 && DamageFloats[zmz].y >= 0)
		{
			int mam;
			mam = text_mode(-1);
			int timedifferance = GetTickCount() - DamageFloats[zmz].time;
			char damagestr[3];
			damagestr[2] = '\0';
			if(DamageFloats[zmz].damage / 10 > 0)
			{
				damagestr[0] = '0' + DamageFloats[zmz].damage / 10;
			}
			else damagestr[0] = ' ';
			damagestr[1] = '0' + DamageFloats[zmz].damage%10;
			textout(BUFFER,big_font,damagestr,DamageFloats[zmz].x,DamageFloats[zmz].y-((timedifferance/50)*1),makecol(255-(timedifferance/50)*2,255-(timedifferance/50)*2,255-(timedifferance/50)*2));
			if(timedifferance >= 1500)DamageFloats[zmz].damage = -1;
			text_mode(mam);
		}
	}
	for(   zmz=0;zmz<15;zmz++)
	{
		if(Spells[zmz].Draw)
		{
			if(Spells[zmz].centered)
			{
				masked_blit(Spells[zmz].myspell->GetAnimation(),BUFFER,((GetTickCount()-Spells[zmz].StartTime)/Spells[zmz].myspell->GetFrameLength())*Spells[zmz].myspell->GetX(),0,(scrx/2)-Spells[zmz].myspell->GetX()/2,(scry/2)-Spells[zmz].myspell->GetY()/2,Spells[zmz].myspell->GetX(),Spells[zmz].myspell->GetY());
				if(GetTickCount()-Spells[zmz].StartTime >= Spells[zmz].myspell->GetFrameLength()*Spells[zmz].myspell->GetNumFrames())
					Spells[zmz].Draw = false;	//no delete b/c it is not ours to delete.
			}else
			if(Spells[zmz].x-nm > 0 && Spells[zmz].x-nm < 20 && Spells[zmz].y-mm > 0 && Spells[zmz].y-mm < 28)
			{
				masked_blit(Spells[zmz].myspell->GetAnimation(),BUFFER,((GetTickCount()-Spells[zmz].StartTime)/Spells[zmz].myspell->GetFrameLength())*Spells[zmz].myspell->GetX(),0,(48+(Spells[zmz].x-nm)*32)-Spells[zmz].myspell->GetX()/2,(48+(Spells[zmz].y-mm)*32)-Spells[zmz].myspell->GetY()/2,Spells[zmz].myspell->GetX(),Spells[zmz].myspell->GetY());
				if(GetTickCount()-Spells[zmz].StartTime >= Spells[zmz].myspell->GetFrameLength()*Spells[zmz].myspell->GetNumFrames())
					Spells[zmz].Draw = false;	//no delete b/c it is not ours to delete.
			}
		}
	}
	if(SHOWFPS == true)
	{
		char countstr[20];
		strcpy(countstr,"FPS: ");
		countstr[5] = '0' + (OLDFPS%1000)/100;
		countstr[6] = '0' + (OLDFPS%100)/10;
		countstr[7] = '0' +  OLDFPS%10;
		countstr[8] = '\0';
		textout(BUFFER,big_font,countstr,0,0,makecol(255,255,255));
	}
	masked_blit(HEALTHBAR,BUFFER,19,0,10,100+(player->GetHpLostAsPercent()*2)+scry/2,19,200-(player->GetHpLostAsPercent()*2));
	masked_blit(HEALTHBAR,BUFFER,0,0,10,100+scry/2,19,200);
	
	masked_blit(HEALTHBAR,BUFFER,38,0,990,100+(player->GetManaLostAsPercent()*2)+scry/2,19,200-(player->GetManaLostAsPercent()*2));
	masked_blit(HEALTHBAR,BUFFER,0,0,990,100+scry/2,19,200);
	for(int m = 0;m < 21;m++)
	{
		for(int n = 0;n < 29;n++)
		{
			for(int p = 0;p < mymap->GetNumObj();p++)
			{
				tmpObject = mymap->GetObj(p);	
				if(tmpObject->GetMapX() == nm+n && tmpObject->GetMapY() == mm+m)
				{

					masked_blit(tmpObject->GetImage(),BUFFER,tmpObject->GetX()*tmpObject->GetFrame(),0,48+(n*32)-(tmpObject->GetX()/2)+16,48+(m*32)-(tmpObject->GetY()/2),tmpObject->GetX(),tmpObject->GetY());	
					if(DRAW_LIGHTS && tmpObject->IsLightSource())
					{
						int ax,ay;
						ax = (n-tmpObject->GetMapX())*32;
						ay = (m-tmpObject->GetMapY())*32;
						OnTheFlyLighting(tmpObject,ax,ay);
					}
					
				}
			}
			for(int procnt = 0;procnt < 25;procnt++)
			{
				if(Projectiles[procnt].X == nm+n && Projectiles[procnt].Y == mm+m && Projectiles[procnt].Image && Projectiles[procnt].draw)
				{
					masked_blit(Projectiles[procnt].Image,BUFFER,16*Projectiles[procnt].Direction,0,56+(n*32),40+(m*32),16,16);
				}
			}
		}
	}
	if(DRAW_LIGHTS)
	{
		for(int aq = 0 ;aq < NUM_MAX_PARTICALS;aq++)
		{
			if(Particals[aq].draw)
			{
				if(Particals[aq].BlendLevel == 0)
				{
					fast_putpixel(BUFFER,Particals[aq].X,Particals[aq].Y,makecol((int)Particals[aq].Red,(int)Particals[aq].Green,(int)Particals[aq].Blue));
					
				}else
				{
					int tr,tb,tg;
					int c = fast_getpixel(BUFFER,Particals[aq].X,Particals[aq].Y);
						
					tr=MyLightMap[(getr32(c))][Particals[aq].Red][Particals[aq].BlendLevel];
					tg=MyLightMap[(getg32(c))][Particals[aq].Green][Particals[aq].BlendLevel];
					tb=MyLightMap[(getb32(c))][Particals[aq].Blue][Particals[aq].BlendLevel];
					fast_putpixel(BUFFER,Particals[aq].X,Particals[aq].Y,makecol32(tr,tg,tb));
					
				}
			}
		}
	}
	masked_blit(EXPBAR,BUFFER,0,7,(scrx/2)-75,scry-48,player->GetXPper()*1.5,7);
	masked_blit(EXPBAR,BUFFER,0,0,(scrx/2)-75,scry-48,150,7);
	
	blit(BUFFER,screen,0,0,0,0,scrx,scry);
	
	if(GetTickCount()-FPSCNT >= 1000)
	{
		OLDFPS = FPS;
		FPS = 0;
		FPSCNT = 0;
	}
}
Code:
void OnTheFlyLighting(Object* temp,int ax,int ay)
{
	int cx,cy;
	int tr,tg,tb;
	cx = ax + 48 + (temp->GetX()>>1) + (temp->GetMapX()<<5);
	cy = ay + 48 + (temp->GetY()>>1) + (temp->GetMapY()<<5);
	for(int LCVY = cy-temp->GetBrightness(); LCVY < cy+temp->GetBrightness();LCVY++)
	{
		if( LCVY > 0 && LCVY < scry)
		for(int LCVX = cx-temp->GetBrightness(); LCVX < cx+temp->GetBrightness();LCVX++)
		{
			if(LCVX < 0 || LCVX > scrx)
			{

			}
			else
			{
				int grade = temp->GetLightInfo(LCVX-cx+temp->GetBrightness(),LCVY-cy+temp->GetBrightness());
				int c = fast_getpixel(BUFFER,LCVX,LCVY);
				if(grade != 0)
				{
					if(temp->GetR() == 0)
					{
						tr = (getr32(c));
					}else
					tr=MyLightMap[temp->GetR()][(getr32(c))][grade<<3];

					if(temp->GetG() == 0)
					{
						tg = (getg32(c));
					}else
					tg=MyLightMap[temp->GetG()][(getg32(c))][grade<<3];

					if(temp->GetB() == 0)
					{
						tb = (getb32(c));
					}else
					tb=MyLightMap[temp->GetB()][(getb32(c))][grade<<3];

					fast_putpixel(BUFFER,LCVX,LCVY,makecol(tr,tg,tb));
				}
			}
		}
	}
}
Get and put pixel functions:
Code:
void fast_putpixel(BITMAP *bmp, int x, int y, int color)
  {
        ((long *)bmp->line[y])[x] = color;
  }
Code:
int fast_getpixel(BITMAP *bmp, int x, int y)
  {
        return ((long *)bmp->line[y])[x];
  }