Using 16 bits

Hi there…

Paul Lowe wrote:

I’m porting some graphics stuff I’ve written in 8 bits to 16 bits. One
of the problems I’m encountering is replacing memset as a filling
function. For example, to set an entire surface to a certain color.
Because 16 bits uses more than one byte for the color description, I am
unable to do this. How can I go about doing this on a 16 bit surface?

Ok, so what you want is something which does a 16-bit memset? Ok…

edi=destination pointer
ecx=number of 16 bit pixels to set.
lower half of eax is the colour you want.

mov dx,ax
shl eax,16
mov ax,dx
cld
mov ebx,ecx
shr ecx,1
rep stosd
mov ecx,ebx
and ecx,01b
rep stosw
ret

I haven’t actually tried the above, but it probably works :slight_smile:

I’ve considered ideas…but they don’t sound too practical:

(1) Use memcpy to copy a color template (line) to the destination
surface one line at a time

(2) Manually set the pixels one by one? (yuck) …

One example of this was a Fill_Box function I wrote that used memset to
set a number of bytes (line) in a surface from a mapped pointer, and go
about doing this line by line.

What’s the best means of going about doing this?

Use a 16 bit assembler memset like above. Or, alternatively use a C 16-bit
memset.

:slight_smile:
Peter>

Thanks,

Paul Lowe
xpaull at ultraviolet.org

Euwww, why use asm pointlessly?!

short *p;
int i = width;
while(–i >= 0)
*p++ = value;

Any compiler worth it’s memory footprint will optimise that!

njh

Hi there…

Nathan Hurst wrote:

Euwww, why use asm pointlessly?!

short *p;
int i = width;
while(–i >= 0)
*p++ = value;

Any compiler worth it’s memory footprint will optimise that!

Because asm is fun. Evidently you haven’t experienced the joy of getting
your program’s memory footprint down to 512 bytes while still having it
do something constructive… :slight_smile:

:slight_smile:
Peter

Any compiler worth it’s memory footprint will optimise that!

Because asm is fun. Evidently you haven’t experienced the joy of getting
your program’s memory footprint down to 512 bytes while still having it
do something constructive… :slight_smile:

No, quite the opposite, I’ve realised how much time I’ve wasted writing
asm which was no faster than my compiler(remembering here that I’ve been
using RISC arch for many years). I know writing asm is fun, but more fun
is writing high level algos that make such optimisations unnecessary.

njhOn Tue, 3 Nov 1998, Peter Hawkins wrote:

Nathan Hurst skrev:

No, quite the opposite, I’ve realised how much time I’ve wasted writing
asm which was no faster than my compiler(remembering here that I’ve been
using RISC arch for many years). I know writing asm is fun, but more fun
is writing high level algos that make such optimisations unnecessary.

Asm is fun but this is hardly a subject concerning SDL!

/ Christian

Christian Granstr?m, Bryggerigatan 4A, 733 34 Sala, Sweden
home:0224-77312, cellular:070-4961587, work:018-184470
@christian.granstrom, christian.granstrom at home.se