; VDEngine Macros
; Slayer - a desktop anti-virus for RISC OS
; Copyright (C) 1996 - 2000 Kiwi Software (UK)
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
;
; info@kiwisoft.co.uk
; -------------------------------------------------------------------------


; created by Rob (30/9/98)

; strings to compare should be in r1 and r2.  This is only suitible for
; use in certain parts of the VDEngine, and if r2 is word aligned.

MACRO strcmpw bytes:i
{
#rept (bytes / 4)
 ldr	r4, [r1], #4
 ldr	r5, [r2], #4
 teq	r4, r5
 movnes	pc, r14
#endr
#set done = (bytes / 4)
#set done = done * 4
#if done < bytes
 #set left = bytes - done
 #rept left
  ldrb	r4, [r1], #1
  ldrb	r5, [r2], #1
  teq	r4, r5
  movnes	pc, r14
 #endr
#endif
}

; strings to compare should be in r1 and r2.  This is only suitible for
; use in certain parts of the VDEngine, and if r2 isn't word aligned; must provide
; how many bytes need to be processed before it is.


MACRO strcmpb bytes:i, off:i
{
#set done = 0
#set todo = 0
#rept off
  ldrb	 r4, [r1], #1
  ldrb	 r5, [r2], #1
  teq	 r4, r5
  movnes pc, r14
  #set done = done + 1
#endr
#set todo = (bytes - done) / 4
#rept (todo)
  ldr	 r4, [r1], #4
  ldr	 r5, [r2], #4
  teq	 r4, r5
  movnes pc, r14
  #set done = done + 4
#endr
#rept bytes - done
  ldrb	 r4, [r1], #1
  ldrb	 r5, [r2], #1
  teq	 r4, r5
  movnes pc, r14
#endr
}

; byte at a time...
MACRO strcmp bytes:i
{
#rept bytes
 ldrb	r4, [r1], #1
 ldrb	r5, [r2], #1
 teq	r4, r5
 movnes	pc, r14
#endr
}

