; ; COMPARE.MAC - Comparison Functions ; ; 97/12/28 ; ; 0= = 0< 0> < U< > MIN MAX WITHIN D0= D= D0< D< DU< ; DMIN DMAX ; ; 0= ( x -- flag ) hdr 2,'0=' zequ: pop hl ld a,l or h jp z,true jp false ; = ( x1 x2 -- flag ) - 0= hdr 1,'=' equal: pop de pop hl equal1: call cmpu jp z,true jp false ; 0< ( n -- flag ) hdr 2,'0<' zless: pop hl zless1: add hl,hl jp c,true jp false ; 0> ( n -- flag ) hdr 2,'0>' zgreat: pop hl ld a,h or a jp m,false or l jp nz,true jp false ; < ( n1 n2 -- flag ) hdr 1,'<' less: pop de pop hl less1: call cmps jp c,true jp false ; U< ( u1 u2 -- flag ) hdr 2,'U<' uless: pop de pop hl uless1: call cmpu jp c,true jp false ; > ( n1 n2 -- flag ) hdr 1,'>' great: pop hl pop de call cmps jp c,true jp false ; MIN ( n1 n2 -- n1 | n2 ) 2dup > if swap then drop hdr 3,'MIN' min: pop de pop hl call cmps jp max1 ; MAX ( n1 n2 -- n1 | n2 ) 2dup < if swap then drop hdr 3,'MAX' max: pop de pop hl call cmps ex de,hl max1: jp c,hpush ex de,hl jp hpush ; WITHIN ( n1 n2 n3 -- flag ) over - >r - r> u< hdr 6,'WITHIN' ; ANS within: pop hl pop de call ssub ex (sp),hl call ssub pop de jp uless1 ; D0= ( d -- flag ) or 0= hdr 3,'D0=' dzequ: call docol dw orr,zequ dw exit ; D= ( d1 d2 -- flag ) hdr 2,'D=' dequ: pop de pop hl ex (sp),hl call cmpu pop de pop hl jp nz,false jp equal1 ; D0< ( d -- flag ) swap drop 0< hdr 3,'D0<' ; ANS dzle: pop hl pop de jp zless1 ; D< ( d1 d2 -- flag ) rot 2dup = if 2drop u< exit then 2swap 2drop > hdr 2,'D<' dless: pop de pop hl ex (sp),hl call cmpu jp z,uless inc sp inc sp inc sp inc sp jp less1 ; DU< ( ud1 ud2 -- flag ) rot swap 2dup u< if 2drop 2drop -1 exit ; then - if 2drop 0 exit then u< hdr 3,'DU<' dules: pop de pop hl ex (sp),hl call cmpu pop de pop hl jp c,true jp nz,false jp uless1 ; DMIN ( d1 d2 -- d1 | d2 ) 2over 2over d< 0= if 2swap then 2drop hdr 4,'DMIN' dmin: call docol dw tover,tover dw dless,zequ dmin1: dw zbran,dmin2 dw tswap dmin2: dw tdrop dw exit ; DMAX ( d1 d2 -- d1 | d2 ) 2over 2over d< if 2swap then 2drop hdr 4,'DMAX' dmax: call docol dw tover,tover dw dless dw bran,dmin1 ; end