table.xyw

table.xyw
calendarsave
; Find entry b in table st and return string address s.
; or $0000 if there is no entry for b.
; st b -> s
.label table_find
  POPy  ; y = code
  POPxw ; xw = first entry of st
  .label table_find.next
    LDBxw INCxw
    ; check if code is $FF then at end of table                  
    DUP $FF EQU table_find.missing JCNw 
    ; if code equal to y, then return entry
    EQUy table_find.found JCNw
    ; otherwise no match, skip string 
    .label table_find.skip
      LDBxw INCxw         
      ; loop until string null byte       
      table_find.skip JCNw 
      table_find.next JMPw
    ; code found, return s
    .label table_find.found
      PSHxw RTS      
    ; code not found          
    .label table_find.missing
      POP                         
      $0000 RTS