Título: FILLRAM Publicado por: SapphiRe en 21 de Marzo de 2006, 05:44:19 pm A fast way to fill (bc+1) bytes of RAM with a given value:
Input: hl = initial address a = value bc = length - 1 (so, don't use this routine to fill just 1 byte ;D) Code: Código: ld [hl],a ld d,h ld e,l inc de ldir ret Título: Re: FILLRAM Publicado por: SapphiRe en 16 de Abril de 2006, 10:46:21 am A faster way, don't use just for a few bytes:
hl = initial address a = value bc = length / 2 (so, don't use this routine to fill an odd number of bytes ;D) Code: Código: di ; NO INTERRUPTS ALLOWED INSIDE THIS CODE ld [STACK],SP ; Saves Stack Pointer value add hl,bc ; Go to the last address add hl,bc ; Useless if you set initially the correct value on hl ld SP,hl ; Stack Pointer -> Next byte to the desired fill area ld d,a ; d = a ld e,a ; de = aa @@loop: push de ; two bytes filled, SP decremented cpi ; A-(hl) , inc hl (useless), dec bc (Parity flag set until BC=0) jp PE,@@loop ; close loop ld SP,[STACK] ; restore Stack (don't forget it!) ei ; Enable interrupts (also, don't forget it!) ret ; return PUSH = 11 cycles CPI = 16 cycles JP PE = 10 cycles Total = 37 cycles each 2 bytes Using ldir = 21 cycles each byte -> 42 cycles each 2 bytes Not many, but, of course, you can unroll the loop to avoid executing CPI and JP PE each PUSH... so you can gain more extra cycles Título: Re: FILLRAM Publicado por: WYZ en 28 de Mayo de 2006, 10:25:54 am The old "fast clear screen" spectrum rutine.... :D
Simply brilliant. |