ZX BASIC:HMirror.bas

From BorielWiki
Jump to: navigation, search

hMirror.bas

This Function takes a byte in, and returns the byte that has reflected the bits around the x axis, such that bits 7,6,5,4,3,2,1,0 become bits 0,1,2,3,4,5,6,7.

This can be useful if you elect to make all your graphics face in one direction - you can mirror the bytes (perhaps to a buffer or a UDG) before you print them. It's faster to store them facing both ways, but you can make quite a memory saving if you just choose one way.

 
FUNCTION FASTCALL hMirror (number AS UBYTE) AS UBYTE
ASM
  ld c,a
; unrolled LOOP FOR speed. Still quite small - costs 10 bytes OVER the LOOP version, AND saves OVER half the time.
   RR C
   RLA
   RR C
   RLA
   RR C
   RLA
   RR C
   RLA
   RR C
   RLA
   RR C
   RLA
   RR C
   RLA
   RR C
   RLA
END ASM
END FUNCTION
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox
Translate
Google AdSense