Advertisement
Zeda

SearchVarBC

Jan 4th, 2012
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;**All outputs are exactly the same as rFindSym**
  2. ;FindVar:
  3. ;Inputs:
  4. ;     OP1+1 contains the name of a symbol var. No type byte.
  5. ;
  6. ;FindVarSym(DE)
  7. ;Inputs:
  8. ;     DE points to the name of a symbol var
  9. ;
  10. ;FindVarSym(HL)
  11. ;Inputs:
  12. ;     HL points to the name of a symbol var
  13. ;
  14. ;SearchVarBC
  15. ;Inputs:
  16. ;     BC contains the name of the var to search. For example, if BC was 00AAh, it would search for Str1. In hex it makes more sense to do it this way (in hex ld bc,00AAh is 01AA00), but you can modify the code a little to make it so that you can do ld bc,$AA00 instead
  17.  
  18. FindSym:
  19.  ld de,OP1+1
  20. FindVarSym(DE):
  21.  ex de,hl
  22. FindVarSym(HL):
  23.  ld c,(hl)
  24.  inc hl
  25.  ld b,(hl)
  26. SearchVarBC:
  27.  ld hl,symtable-6
  28. SearchLoop:
  29.   ld a,c
  30.   cp (hl)
  31.   dec hl
  32.   jr nz,$+6             ;2004 is the hex code. I believe this is correct... It skips the next 4 bytes
  33.    ld a,b
  34.    cp (hl)
  35.    jr z,$+16            ;280E This skips the next 14 bytes if z is set.
  36.   ld de,-8
  37.   add hl,de
  38.   ex de,hl
  39.   ld hl,(progPtr)
  40.   sbc hl,de
  41.   ex de,hl
  42.   ld a,d
  43.   or a
  44.   ccf
  45.   jr nz,SearchLoop      ;20E7
  46.  inc hl
  47.  inc hl
  48.  ld b,(hl)
  49.  inc hl
  50.  ld d,(hl)
  51.  inc hl
  52.  ld e,(hl)
  53.  inc hl
  54.  inc hl
  55.  inc hl
  56.  ld a,(hl)
  57.  ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement