         .OUTPI ALFRES
         .ENTRY LOOKUP
         .VIRT8 BX,HPTR,AX
;Lookup_Code locates the slot with the current char
;On Entry, bx is the code to lookup, ax is the data byte
;
LOOKUP   JSR INDEX   ;Set hptr
         LDA #0
         STA FIRSTU ;Default is first time
         LDY #HFIRST+1
         LDA (HPTR),Y ;Has this code been used ?
         CMP #$FF    ;Is hptr.first=-1 ?
         BCC LOOK1
         DEY
         CMP (HPTR),Y
         BNE LOOK1
         SEC
         RTS
LOOK1    INC FIRSTU ;Say not first use
         LDY #HFIRST
         LDA (HPTR),Y
         STA BX      ;Get first entry
         INY
         LDA (HPTR),Y
         STA BX+1
LOOK2    JSR INDEX   ;Lookup code
         LDY #HCHAR
         LDA (HPTR),Y
         CMP AX      ;Is it the same character ?
         BNE LOOK3
         LDA BX                 ;THIS IS THE NEW SLOT
         STA AX
         LDA BX+1
         STA AX+1
         CLC
         RTS
LOOK3    LDY #HNEXT
         LDA (HPTR),Y
         CMP #$FF
         BCC LOOK4
         INY
         LDA (HPTR),Y
         CMP #$FF
         BNE LOOK4
         SEC
         RTS
LOOK4    LDY #HNEXT
         LDA (HPTR),Y
         STA BX
         INY
         LDA (HPTR),Y
         STA BX+1
         JMP LOOK2
