home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / lzwsch / search.asm < prev   
Encoding:
Assembly Source File  |  1992-05-10  |  1.8 KB  |  73 lines

  1. SEARCH    LD    IX,PREFIX
  2.     LD    BC,(NO2SRCH)
  3.     LD    HL,(BGNSRCH)
  4.     LD    DE,4096
  5. SCH010    LD    A,B
  6.     OR    C
  7.     JR    Z,SCH030    ;go if more to search
  8.     LD    A,(IX)        ;p/u lsb of PREFIX
  9.     CPIR            ;in PRELSB table?
  10.     JR    NZ,SCH030    ;go if not
  11.     LD    (SCH020+1),HL    ;store addr of char + 1
  12.     DEC    HL        ;-> actual char
  13.     ADD    HL,DE        ;-> PREMSB value
  14.     LD    A,(IX+1)    ;p/u msb of PREFIX
  15.     CP    (HL)        ;msbs match?
  16.     JR    NZ,SCH020    ;go if not
  17.     ADD    HL,DE        ;-> SUFLSB value
  18.     LD    A,(IX+2)    ;p/u suffix
  19.     CP    (HL)        ;suffix lsbs match?
  20. SCH020    LD    HL,$-$        ;addr of char + 1
  21.     JR    NZ,SCH010    ;CPIR again if no match
  22. ;
  23.     LD    (BGNSRCH),HL    ;update these for next
  24.     LD    (NO2SRCH),BC    ;   invocation
  25.     DEC    HL        ;HL = addr of char
  26.     LD    DE,PRELSB    ;DE = table base
  27.     SBC    HL,DE        ;calc offset
  28.     LD    (PREFIX),HL    ;this is slot #
  29.     CP    A        ;Z means "string found"
  30.     RET
  31. ;
  32. SCH030    LD    B,H        ;here if string not found
  33.     LD    C,L        ;store addr of char + 1
  34.     LD    DE,PREMSB    ;are we past table end?
  35.     OR    A
  36.     SBC    HL,DE
  37.     JR    NC,SCH040    ;go if so
  38. ;
  39.     LD    H,B        ;here to record string
  40.     LD    L,C        ;addr of char + 1
  41.     LD    DE,PRELSB+6    ;table base + # root values + 2
  42.     LD    (BGNSRCH),DE    ;   (would be 258 for 256-color image)
  43.     OR    A
  44.     SBC    HL,DE        ;calc # of slots filled
  45.     INC    HL
  46.     LD    (NO2SRCH),HL
  47. ;
  48.     LD    H,B
  49.     LD    L,C        ;-> next PRELSB posn
  50.     LD    A,(IX)
  51.     LD    (HL),A        ;store new prefix lsb
  52.     LD    DE,4096
  53.     ADD    HL,DE        ;-> next PREMSB posn
  54.     LD    A,(IX+1)
  55.     LD    (HL),A        ;store new prefix msb
  56.     ADD    HL,DE        ;-> next SUFLSB posn
  57.     LD    A,(IX+2)
  58.     LD    (HL),A
  59.     RET            ;w/NZ means string not found
  60. ;
  61. ; here if table full
  62. ;
  63. SCH040    CALL    OUTCODE        ;send prefix to file
  64.     LD    HL,CLRCODE
  65.     LD    (PREFIX),HL
  66.     CALL    OUTCODE        ;clear table (OUTCODE resets search params
  67.                 ;   (BGNSRCH, NO2SRCH, CODESIZ, MAXCODE, etc.)
  68.     LD    HL,(SUFFIX)
  69.     LD    (PREFIX),HL    ;new root value string in PREFIX-SUFFIX
  70.     CP    A        ;set Z to trick calling routine into thinking
  71.     RET            ;   root in PREFIX was found via search
  72. ;
  73.