; CODE file to find the 'ZENV' sequence searching up from top of tpa ; .Z80 aseg org 100h dw last-first ; length of code segment first: ld hl,(6) ; hl = top of tpa ld de,0feffh ; de = limit of search - 1 scf sbc hl,de push hl pop bc ; bc = length of search ld hl,(6) searchz: ld a,'Z' cpir ; look for a 'Z' push af pop de bit 2,e ; test ov flag jr z,not$found push hl pop ix ; we have a z now check to see if next 4 char are '3ENV' ld a,'3' ; look for a '3' cp (ix) jr nz,searchz ; if no match, look for another 'Z' ld a,'E' ; look for an 'E' cp (ix+1) jr nz,searchz ; if no match, look for another 'Z' ld a,'N' ; look for an 'N' cp (ix+2) jr nz,searchz ; if no match, look for another 'Z' ld a,'V' ; look for a 'V' cp (ix+3) jr nz,searchz ; if no match, look for another 'Z' ; we have the full 'Z3ENV' - confirm the correctness by looking for ; a jump instruction 3 cells below the 'Z' ld a,0c3h cp (ix-4) jr nz,searchz ; if not found, resume 'Z' search ; got it - last check - see if internal address agrees with result dec hl ; adjust hl dec hl dec hl dec hl ld a,(ix+23) ; test lo address byte cp l jr nz,adr$fail ld a,(ix+24) ; test hi address byte cp h jr z,exit ; verified! return result adr$fail: push ix ; failed, pop hl ; restore hl and continue search jr searchz exit: ex (sp),hl ; swap env address onto stack jp (hl) ; make an exit ; come here if completed search without finding env address not$found: ld hl,0 jr exit last: end