Browse Source

+ inline assembler implementation of FillChar

git-svn-id: branches/z80@44910 -
nickysn 5 years ago
parent
commit
2b4ed4e90d
1 changed files with 26 additions and 12 deletions
  1. 26 12
      rtl/z80/z80.inc

+ 26 - 12
rtl/z80/z80.inc

@@ -57,19 +57,33 @@ end;
 
 {$define FPC_SYSTEM_HAS_FILLCHAR}
 Procedure FillChar(var x;count:SizeInt;value:byte);
-var
-  pdest,pend : pbyte;
-  v : ptruint;
+label
+  skip, loop;
 begin
-  if count <= 0 then
-    exit;
-  pdest:=@x;
-  pend:=pdest+count;
-  while pdest<pend do
-    begin
-      pdest^:=value;
-      inc(pdest);
-    end;
+  asm
+    ld c, (count)
+    ld b, (count+1)
+    bit 7, b
+    jp NZ, skip
+
+    ld a, b
+    or a, c
+    jp Z, skip
+
+    ld e, (value)
+    ld a, 0
+    ld l, (x)
+    ld h, (x+1)
+loop:
+    ld (hl), e
+    inc hl
+    dec bc
+    cp a, c
+    jp NZ, loop
+    cp a, b
+    jp NZ, loop
+skip:
+  end;
 end;