[A89] Re: clipping pixels


[Prev][Next][Index][Thread]

[A89] Re: clipping pixels




I think that you need to be careful when checking the lower bounds of the
LCD memory block. You have a <= comparison where it really should be a <.
Why?

Say you have a block of 5 bytes ... LCD_SIZE=5

Addresses (made up):

11,12,13,14,15
^-----------------LCD_MEM

Now the LCD_MEM pointer points to address 11.

What is LCD_MEM+LCDSIZE?
Address 11 + 5 = Address 16.

Clearly that is beyond the bounds of the 5 byte block (which ends at address
15). So that's why you want to say either
( <=  LCD_MEM+LCD_SIZE -1)
or more simply
( < LCD_MEM+LCD_SIZE)

Hope that helps!

WiseOwl





----- Original Message -----
> Date: Sat, 5 Jan 2002 19:09:10 -0600
> Subject: [A89] clipping pixels
> From: the_juggernaut@juno.com
>
> Will this function do what it's supposed to (draw pixels only to video
> memory)?  It works alright, but how can I be sure that it's not secretly
> screwing everything up?  I ask because I'm not to familiar with pointers
> and pointer arithmetic.
>
> Jon K.
>
>
> file://from the extgraph library
> #define EXT_PIXOFFSET(x,y)  ((y<<5)-(y<<1)+(x>>3))
> #define EXT_PIXADDR(p,x,y)  (((unsigned char*)(p))+EXT_PIXOFFSET(x,y))
> #define EXT_PIXMASK(x)      ((unsigned char)(0x80 >> ((x)&7)))
>
> #define EXT_SETPIX_AM(a,m)   (*(a) |= (m))
> #define EXT_CLRPIX_AM(a,m)   (*(a) &= ~(m))
> #define EXT_XORPIX_AM(a,m)   (*(a) ^= (m))
> #define EXT_GETPIX_AM(a,m)   (*(a) & (m))
>
> void SET_CLIP_PIX(int x, int y)
> {
> unsigned char *addr = EXT_PIXADDR(LCD_MEM,x,y);
> if(((void*)addr >= LCD_MEM)&&((void*)addr <= LCD_MEM + LCD_SIZE))
>  EXT_SETPIX_AM(addr, EXT_PIXMASK(x));
> }
>
>
> ------------------------------
>
> End of assembly-89 Digest V1 #156
> *********************************
>