?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1.     OPT push reset --syntax=abfw
  2.  
  3.     MACRO negR16toR16 fromR16?, toR16?
  4.         ; 6B 24T, uses A
  5.         xor     a
  6.         sub     low fromR16?
  7.         ld      low toR16?,a    ; low = 0 - low
  8.         sbc     a,a
  9.         sub     high fromR16?
  10.         ld      high toR16?,a   ; high = 0 - high - borrow
  11.     ENDM
  12.  
  13.     MACRO negR16 r16?
  14.         ; 6B 24T, uses A
  15.         negR16toR16 r16?, r16?
  16.     ENDM
  17.  
  18.     MACRO negHLuseDE            ; 6B 38T
  19.         ; HL = -HL, DE = HL (preserves A)
  20.         ex  de,hl
  21.         or  a
  22.         sbc hl,hl               ; HL = 0
  23.         sbc hl,de               ; HL = 0 - HL
  24.     ENDM
  25.  
  26.     MACRO negDEuseHL            ; 6B 38T
  27.         ; DE = -DE, HL = DE (preserves A)
  28.         or  a
  29.         sbc hl,hl
  30.         sbc hl,de
  31.         ex  de,hl
  32.     ENDM
  33.  
  34.     MACRO alignHl alignValue?
  35.         ASSERT 2 <= (alignValue?)
  36.         ASSERT 0 == ((alignValue?) & ((alignValue?)-1)) ; make sure it's power of two
  37.         push    af
  38.         IF (alignValue?) == 256
  39.             xor     a
  40.             cp      l           ; Fc=1 when 0 < L
  41.             ld      l,a         ; L = 0
  42.             adc     a,h
  43.             ld      h,a
  44.                 ; 20T 5B
  45.         ELSE : IF (alignValue?) == 2
  46.             inc     hl
  47.             res     0,l
  48.                 ; 14T 3B
  49.         ELSE : IF (alignValue?) < 256
  50.             ld      a,(alignValue?)-1
  51.             IFNDEF SJ_LIBRARY_USE_Z80N
  52.                 add     a,l
  53.                 rra             ; preserve carry flag for increment of H
  54.                 and     -((alignValue?)>>1)     ; clear bottom bits, Fc=0
  55.                 rla             ; restore add-carry and fix position of L bits
  56.                 ld      l,a
  57.                 adc     a,h     ; A = L + H + add-carry
  58.                 sub     l       ; A = H + add-carry (new H)
  59.                 ld      h,a
  60.                     ; 42T 11B
  61.             ELSE
  62.                 add     hl,a    ; add align-1 to HL
  63.                 cpl             ; bits to keep in L (and clear bottom bits)
  64.                 and     l
  65.                 ld      l,a
  66.                     ; 27T 7B
  67.             ENDIF
  68.         ELSE : ASSERT 256 < (alignValue?)
  69.             xor     a
  70.             cp      l
  71.             ld      l,a
  72.             adc     a,h     ; if 0 < L, then ++H here in every case
  73.             add     a,((alignValue?)-1)>>8
  74.             and     -((alignValue?)>>8)
  75.             ld      h,a
  76.                 ; 34T 9B
  77.         ENDIF : ENDIF : ENDIF
  78.         pop     af
  79.     ENDM
  80.  
  81.     OPT pop
  82.