zoekenintbl: ;jp notfinished xor a ld l, 2 call menuCreate ld hl, item10 ld de, tblSelect1 call menuItemCreate ld hl, item11 ld de, tblSelect2 call menuItemCreate ld hl, item6 ld de, menu2 call menuItemCreate ;kan later weg ;ld a, 2 ;ld (menuIndex), a jp menuBegin tblSelect1: setf (whichtbl) jr tblSelect_ tblSelect2: resf (whichtbl) tblSelect3: tblSelect_: xor a ld l, 2 call menuCreate ;uitleg ld hl, $2600 ld (pencol), hl ld hl, menutxt4 call dspStringSmall ld hl, item13 ld de, methodSelect1 call menuItemCreate ld hl, item14 ld de, methodSelect2 call menuItemCreate ;ld hl, item15 ;ld de, tblSelect3 ;call menuItemCreate ;kan later weg ;ld a, 2 ;ld (menuIndex), a jp menuBegin methodSelect1: ld a, 2 jr methodSelect_ methodSelect2: ld a, 1 methodSelect_: ld (searchmethod), a ld a, 2 ld (methode), a jp equation2 zoekenintblback: ;we kunnen heel appBackUpScreen(eerste 256bytes lijkt me toch niet) gebruiken, ;gebruik makend van 2 stacks: stTblAtom, stTblAtomQt res textinverse, (iy + textflags) xor a ld (pencolstart), a ; jr debug33_ ; call draaiom ; ld hl, sttblatom ; ld a, 0 ; call stackArSetIx ; ld hl, sttblatomqt ; call stackArSetIxDE ;debug33: ; ld hl, sttblatom ; call stackargetix ; ;call debuga1 ; call stackarpop ; call debuga ; ld hl, sttblatomqt ; call stackarpopde ; call debugde ; ;call stackargetixde ; ;call debuga ; jr debug33 ;debug33_: call draaiom ld hl, 0 ld (penCol), hl b_call (_clrlcdfull) jr nxtMolecuul nxtmolecuulWithPop: ld hl, sttblatom call stackarpop nxtMolecuul: ;tblRowPos ld hl, sttblatom call stackarpop cp 250 jr z, nxtMolecuul call stackarunget ;call stackarpop ;call debuga ;call stackarunget call stackargetix ld hl, sttblatomqt call stackarsetixde ld (AtomMolecuulIx), a ;call debuga1 ;call stackarpop ;call debuga ;ld a, (AtomMolecuulIx) ;call debuga1 ;call stackarsetix ;call stackarpop ;call debuga ;;call debuga1 ld hl, tbl49 ld bc, tbl49_ - tbl49 bitf (whichtbl) jr nz, tbl49Set ld hl, tbl48 ld bc, tbl48_ - tbl48 tbl49Set: call arsetup ;debug1111: ; call argetnext ; call debuga ; jr debug1111 ld a, 1 ld (tblrow), a xor a ld (tblrowlastfound), a ld (molecuulnietgevonden), a ld (molecuulalgevonden), a ld hl, (arPos) ld (tblrowpos), hl ;ld (tblRowLastFound), a ;ld (tblRowLastFound+1), a call showmolecule jr nxtAtom searchNextRowForThisMolecule: ;jr $ ld a, (AtomMolecuulIx);reset naar index van eerste atoom van t molecuul ld hl, sttblatom call stackarsetix ld hl, sttblatomqt call stackarsetixde call findnextrow jp nxtAtom nxtAtomWithPop: ld hl, sttblatomqt call stackarpopde nxtAtom: ld hl, sttblatom call stackarpop ; call debuga1 or a jp z, allatomstried cp 250 jr z, amatch bitf (whichtbl) jr z, redoxTbl cp 150 jr z, nxtAtomWithPop redoxTbl: ;call debuga1 ld e, a ld a, (molecuulnietgevonden) or a jr nz, nxtAtomWithPop;er is al een atoom uit het molecuul niet gevonden, dus hoeven ook niet verder te zoeke ;call debuge call findfirste ld a, (tblRow) ld e, a ld a, (tblRowLastFound) ;call debuga ;call debuge or a jr z, firstsofine cp e jr z, stayedsamesofine ;ld hl, 123 ;call debughl ;we zoeken een atoom, maar vinden hem pas een in latere row, nu moeten we beginnen bij t begin van deze row, met t eerste atoom van t molecuul ld a, (AtomMolecuulIx);reset naar index van eerste atoom van t molecuul ld hl, sttblatom call stackarsetix ld hl, sttblatomqt call stackarsetixde firstsofine: stayedsamesofine: ld a, e ld (tblRowLastFound), a ld hl, (tblrowpos);reset ar index naar begin row ld (arPos), hl jr nxtAtom ;ld a, (tblrow) ;call debuga ;call debughl ;jr nxtatom amatch: ld hl, sttblatomqt call stackarpopde;junk - keep index same ld a, (molecuulnietgevonden) ;call debuga1 or a jp nz, notfound2 call checkendscreen ;call isexactlysamemolecule ;jp nz, notfound2 ;cp 2 ;jp z, bijvolgenderowaangekomen ld a, (tblrow) ;call debuga dec a bit 0, a jr z, aleven dec a alEven: rrca ;a /= 2 ld h, 0 ld l, a ld d, h ld e, l add hl, hl;hl *= 5; add hl, hl add hl, de ld c, 0 notfound3: ld de, tbl49pKz bitf (whichtbl) jr nz, tbl49pkzset ld de, tbl48pKz tbl49pkzset: add hl, de ld b, 5 disploop: ld a, (hl) inc hl b_call (_vputmap);print pKz djnz disploop disploop_: ld a, c or a jr nz, dontprintzuur ld a, (searchmethod) cp 2 jr nz, dontprintzuur;alleen bij exacte search dit printen ld a, (tblRow) ld hl, zuur bitf (whichtbl) jr nz, tbl49set2 ld hl, ox tbl49set2: bit 0, a jr nz, leftColumn ld hl, base bitf (whichtbl) jr nz, tbl49set3 ld hl, red tbl49set3: leftColumn: call vputc;print (zuur) / (base) dontprintzuur: ld a, (penRow) add a, 8 ld (penRow), a xor a ld (penCol), a ld a, 1 ld (molecuulalgevonden), a jp searchNextRowForThisMolecule ;jp nxtMolecuul allatomstried: b_call (_getkey) cp kTrace jp z, _end jp menu2 notfound2: ld a, (molecuulalgevonden) or a ld hl, -5 ld c, 1;we moeten nu niet (zuur) printen jr z, notfound4 call drawBorder ;cp 64-8 ;jr c, goed2 ;call debug2 ;goed2: xor a ld (penCol), a jp nxtmolecuul;is al misntens 1 row gevonden met dit molecuul, hoeven geen "??" te printen notfound4: call checkendscreen jp notfound3 findfirst: ld e, a findfirste: ;call debuge jr findfirst_loop findfirst_loopWithPop: call argetnext;junk - quantity atom findfirst_loop: call argetnext ;;call debuga1 jr z, molecuulnietgevonden2 ;call debuga cp e jr nz, nietzelfdeatom ;atom match ld a, (searchmethod) or a jr z, retwithcall call argetnext;a = quantity in binastbl ;call debuga ld hl, sttblatomqt ld b, e;backup call stackarpopde ld h, 0 ld l, a ;call debuga cphlde jr c, verkeerdeqt;quantity in binas is minder dan de gesubmitte jr nz, binasGrotereQt binasGrotereQtBack: ;match(quantity komt precies overeen(of minstens, bij method 1)) ld a, (searchMethod) cp 1 ret z;method 1 hoeft niet precies gelijke molecuul te vinden call isExactlySameMolecule ret z verkeerdeqt: ;ret nc;quantity in binas is meer of gelijk ;atom match maar met andere quantity ;;call debughl ;;call debugde ;call debug1 ld hl, sttblatomqt call stackArUngetDE ld e, b;restore jr findfirst_loop ;ld hl, sttblatom ;call stackarpop ;call stackarpop ;call debuga ;or a ;jp z, allatomstried ;call stackarunget ;call stackarunget molecuulnietgevonden3: molecuulnietgevonden2: ;call debug2 ld a, 1 ld (molecuulnietgevonden), a jp nxtatomwithpop binasGrotereQt: ld a, (searchmethod) cp 2 jr z, verkeerdeqt jr binasGrotereQtBack retwithcall: call argetnext;junk ret nietzelfdeatom: cp 240 jr z, tblrowplusoneNot cp 250 ;jr z, findfirst_loop;toch niet want hier moet ie ook restten jr z, tblrowplusone or a jr nz, findfirst_loopWithPop tblrowplusone: ;call debuga1 ld hl, tblrow inc (hl) tblrowplusoneNot: ld hl, (arPos) ld (tblRowPos), hl jr findfirst_loop findnextrow: jr findfirst_loop1 findfirst_loopWithPop1: call argetnext;junk - quantity atom findfirst_loop1: call argetnext ;call debuga1 jr z, molecuulnietgevonden3 ;call debuga cp 240 jr z, findfirst_loop1 cp 250 ;jr z, findfirst_loop;toch niet want hier moet ie ook restten jr z, tblrowplusone1 or a jr nz, findfirst_loopWithPop1 tblrowplusone1: ;call debuga1 ld a, (tblrow) inc a ld (tblrowlastfound), a ld (tblrow), a ld hl, (arPos) ld (tblRowPos), hl bit 0, a ret nz ;hij moet nu nog een rij verder, want zit nu in 2e column(tis namelijk 1,2 3,4 5,6) call findnextrow ret isExactlySameMolecule: ;kijken of atoom molecuul precies tzelfde is(gelijke aantal verschillende atomen) ;flags z, set als moleculen tzelfde zijn ;del all but bc push bc ;out b ;sttblatom index blijft gelijk(voor als dat nodig is, denkt wel) ld hl, sttblatom call stackargetix push af ld a, (AtomMolecuulIx) call stackarsetix ld b, 0;counter loop34: call stackarpop ;call debuga bitf (whichtbl) jr z, redoxTbl2 cp 150 jr z, loop34 redoxTbl2: cp 250 jr z, bIsNrSt inc b jr loop34 bIsNrSt:;b is number atoms in stack pop af call stackarsetix ;call debugb ;out c ;arpos wordt niet gewijzigd(weenie of dit wel nodig is) ld hl, (arpos) push hl ld hl, (tblRowPos) ld (arpos), hl ld c, 0 loop44: call argetnext ;call debuga or a jr z, cIsNrTbl49 cp 250 jr z, cIsNrTbl49 cp 240 jr z, cIsNrTbl49 ;cp 150 ;jr z, ladingisgeenatom inc c ladingisgeenatom: call argetnext jr loop44 cIsNrTbl49:;c is number atoms in tbl 49 for this row entry pop hl ld (arpos), hl ;call debugc ld a, b ;call debuga ;call debugc cp c pop bc ret showmolecule: ;if(molecule == 0) return; ld hl, sttblatom call stackarpop call stackarunget or a ret z ;we zitten met klein probleempje, doordat we stackArray gebruiken staat alles omgedraaid, dit moeten we fixen(we willen wel dat de user t ziet zoals die um heeft ingevoerd) ;get end of molecule(the place to start) ld hl, sttblatom getEnd: call stackarpop or a jr z, getEnd_ cp 250 jr z, getEnd_ jr getEnd getEnd_: call stackarunget call stackargetix ld hl, sttblatomqt call stackarsetixde call checkendscreen jr getNxtAtom getNxtAtomWithPop: ld hl, sttblatomqt call stackpopDE getNxtAtom: ld hl, sttblatom call stackpop or a jr z, endofmolecule cp 250 jr z, endofmolecule cp 150 jr z, dsplading;lading displayen we niet;toch wel voor redox ;a = atomNr die we gaan displayen ld c, a call dspAtomAbb ld hl, sttblatomqt call stackpopde ld a, e cp 1 jr z, getNxtAtom call dspNumber199 jr getNxtAtom dsplading: bitf (whichtbl) jr nz, getNxtAtomWithPop;bij zuurbase tabel niet lading weergeven ld a, (searchmethod) cp 2 jr nz, getNxtAtomWithPop;bij zoekmethode 'deel molecuul' ook niet ld a, $20;' ' b_call (_vputmap) ld hl, sttblatomqt call stackpopde ld a, e cp 128 jr c, nietmin xor 255;a *= -1 inc a ; cp 1 ; jr z, dont1 call dspNumber199 dont1: ld a, $d2;- jr nietmin_ nietmin: ; cp 1 ;jr z, dont2 call dspNumber199 dont2: ld a, $2b;+ nietmin_: b_call (_vputmap) jr getNxtAtom ; call debuga;compiler bug........... ; call debuga ; call debuga ; call debuga ; call debuga ; call debuga ; call debuga ; call debuga ; call debuga ; call debuga endofmolecule: ;
ld a, (penRow) add a, 8 ld (penRow), a ;restore ld a, (AtomMolecuulIx) ld hl, sttblatom call stackarsetix ld hl, sttblatomqt call stackarsetixde ;b_call (_getkey) ret checkendscreen: ld a, (penRow) cp 64-7+1 jr c, checkendscreen_ xor a ld (penRow), a ld a, (pencolstart) add a, 32 ld (pencolstart), a cp 96 jr nz, checkendscreen_ b_call (_getkey) b_call (_clrlcdfull) xor a ld (pencolstart), a checkendscreen_: ld a, (pencolstart) ld (pencol), a ret drawBorder: ld hl, sttblatom call stackarpop call stackarunget or a ret z;bij laatste dit overslaan ;cp 250 ;jp z, nxtmolecuulWithPop;tegen bug ld a, (penRow) or a ret z;bij eerste row overslaan cp 8*7 jr z, skipborder;bij laatste row alleen naar volgende col gaan(staat beetje knullig, Fe: helemaal onderaan cp 8*6 jr z, skipborder2times ;drawborder skipborder: ld a, (penRow) add a, 8 ld (penRow), a ret skipborder2times: ld hl, skipborder push hl jr skipborder