Título: changecolors.asm Publicado por: SapphiRe en 24 de Abril de 2006, 02:42:44 pm Hi again!
Imagine you have a ram buffer filled with 4bit color data (screen 1,2 or 3) and you want to replace white color for grey, light green for dark green... (for instance to simulate a darkening of the image). Código: xor a ; a =0 @@LOOP: rrd ; Rotate nibbles a -> [hl] -> a ld e,a ; Lower byte of the color change table ld a,[de] ; Paper color substitution rrd ; Rotate nibbles a -> [hl] -> a ld e,a ; Lower byte of the color change table ld a,[de] ; Ink color substitution rrd ; Rotate nibbles a -> [hl] -> a cpi ; Inc HL, Dec BC jp pe,@@LOOP ; If BC <> 0 then goto @@LOOP ret ; Return RRD rotates a 12 bits number (4 lower bits of A and 8 bits of [HL]) 4 bits to the right. RRL do the same to the left. Both are standard and documented Z80 instructions. Usage of the routine: HL -> Buffer address DE -> Change color table address (lower byte MUST be zero! This speeds up a lot the routine) BC -> Buffer length The change color table is a 16 bytes area containing the destination color for each source color. For instance, the table: Código: .db 0,1,2,3,4,5,6,7,8,9,10,11,12,13,15,14 just exchange white and grey colors. Surely you can find more interesting uses for this little piece of code. Regards -- SapphiRe |