equation: xor a ld (methode), a equation2: ld h, $2b;'+' ld l, $1c;'->' ld (bfchar), hl ld hl, buffer ld a, (bfLength) ld b, 0 ld c, a add hl, bc ld (bfpos), hl;(bfpos) point nu wel naar char NA de buffer, maar bfFindNext decrement hem toch weer eerst ld c, 0 columnRepeat:;b = counter how much + / -> , c = aantal '+' ervoor when -> found call bfFindNext jr z, columnRepeat_ inc b cp $1c jr nz, columnRepeat xor a cp c jp nz, err2muchis ld c, b jr columnRepeat columnRepeat_: xor a cp c jp z, errnois ld a, b ld (matDim), a sub c inc a ld (matSignChange), a errISback: ;(cl004) ld h, $28 ld l, $29 ld (bfchar), hl ld hl, buffer ld a, (bfLength) ld b, 0 ld c, a add hl, bc ld (bfpos), hl;(bfpos) point nu wel naar char NA de buffer, maar bfFindNext decrement hem toch weer eerst ;ld c, 0;c moet even zijn wanneer die haakje open ziet, oneven bij haakje dicht ;dit is niet helemaal juist, (CO(OH)2)3 moet ook kunnen ld d, 0;aantal open haakjes ld e, 0;aantal gesloten haakjes vindvolgendhaakje: call bfFindNext jr z, vindvolgendhaakje_ cp $29 jr z, haakjedicht haakjeopen: ld a, d cp e;moetn altijd meer ) dan ( zijn jr nc, verkeerdevolgorde inc d jr vindvolgendhaakje haakjedicht: inc e jr vindvolgendhaakje verkeerdevolgorde:;dit kan ook betekenen dat t aantal haakjes niet klopt ld hl, errbracketsmsg call dspmsg jp menu2 verkeerdeaantal: ld hl, errbracketsmsg2;nu weten we cker dat aantal niet klopt call dspmsg jp menu2 vindvolgendhaakje_: ld a, d cp e;check evenveel ) als ( jr nz, verkeerdevolgorde rlca ;a*=2(nr haakjes totaal) inc a;zodat als er geen haakjes zijn er ook ruimte is inc a; ld b, 0 ld c, a;bc is aantal haakjes ld hl, stackTimes ld a, 1 call stackCreate jp c, menu2 ld h, $28 ld l, $29 ld (bfchar), hl ld hl, buffer ld a, (bfLength) ld b, 0 ld c, a add hl, bc ld (bfpos), hl;(bfpos) point nu wel naar char NA de buffer, maar bfFindNext decrement hem toch weer eerst ld a, 1;tbegint met gwon 1x alle atomen ld hl, stackTimes call stackpush call stackget abcd: call bfFindNext jr z, abcd_ cp $29 jr z, closebracket pop hl ld d, l ld hl, stackTimes call stackget ld h, 0 ld l, a call hldivd ld a, l ld hl, stackTimes call stackpush jr abcd closebracket: call bfint2bf2 ;ld hl, buffer2;kan toch weg? call bf22c ld a, c or a jr nz, welgetalnahaakje ld c, 1 welgetalnahaakje: push bc ld hl, stackTimes;del HL niet tot call stackget ld b, a call aisbxc call stackpush;hier jr abcd abcd_: ld hl, stackTimes;(cl004) - bug dat ie bij meerdere haakjes de laatste keer een nul ziet inplaats van 1 ;waarom is deze regel nodig? ;jr $ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; equationRead: ld hl, buffer ld a, (bfLength) ld b, 0 ld c, a ;jr $ call arSetup ;setup 2 stacks ld hl, stAtomNr ld bc, maxAtoms ld a, 1 call stackCreate jp c, menu2 ; ld hl, stAtomQt ld bc, maxAtoms ld a, 2 call stackCreate jp c, menu2 ;01 kijkt hoeveel ruimte er nog is en geeft 1/3 aan sttblatom en 2/3 aan sttblatomqt ld hl, (stackNewPos) ld de, (stackEndPos) or a sbc hl, de ld d, 3 call hldivd push hl ld b, h ld c, l ld a, 1 ld hl, stTblAtom call stackCreate jp c, menu2 pop bc ld hl, stTblAtomQt ld a, 2 call stackCreate jp c, menu2 ;make first entry of the stacks 0 so we can identify the beginning(or better, the end of the pops) ld hl, stAtomNr xor a call stackPush ld hl, stAtomQt call stackPushDE;whats inside de doesn't matter ; ld hl, stTblAtom call stackPush ld hl, stTblAtomQt ;ld de, 2222;kan later weg call stackPushDE inf: call argetnext ;call debuga jp z, inf_ call isBig jr z, big call isSmall jr z, small call isBracket jr z, bracket call isOperator jr z, operator call isSuper jr z, super jr inf big: ld h, a ld l, 1 ld a, bb ; call nz, flushAtomStack call argetnext call isSmall call nz, arback jr nz, notsmall ld l, a notsmall: ;h=first atom, l=last atom call atomnr;a = atomNr cp -1 jp z, atomNotFound call getNrOnArPos;hl = quantity atom call pushAtom jr inf small: ;nu weten we al dat atom niet bestaat, normaal zou die al weg zijn gehaald in big: cp 101 ;voor e een uitzondering ( elektron) jr z, inf ld h, a ld l, 1 jp atomNotFound jr inf bracket: ld hl, stackTimes call stackPop;naar volgende haakjes gegevens jr inf operator: call atoms2TblBuffer jp inf super: call getSuperNrOnArPos ld h, 0 ld l, a ld a, 150;die voor plus en min lading, 150 bestaat toch niet als atom call pushAtom jp inf isBig: cp $41 jr c, zoff cp $5b jr nc, zoff jr zon isSmall: cp $61 jr c, zoff cp $7b jr nc, zoff jr zon isBracket: cp $28 jr z, zon cp $29 jr z, zon jr zoff isOperator: cp $1c jr z, zon cp $2b jr z, zon jr zoff isSuper cp $8c jr c, zoff cp $8c + 12 jr c, zon jr zoff zoff:;kon natuurlijk ook met carry flag, wist ik toen nog niet push hl ld h, a ld a, 1 jr zon_ zon: push hl ld h, a xor a zon_: or a ld a, h pop hl ret pushAtom: ;in hl = quantity ; a = atomNr push hl ld hl, stAtomNr ld b, a;backup call stackFind jr c, notYetInStack ;alreadyInStack ld hl, stAtomQt call stackGetAtDE pop hl add hl, de ld d, h ld e, l ld hl, stAtomQt call stackEditDE jr notYetInStack_ notYetInStack: ld a, b;restore ld hl, stAtomNr call stackPush pop de;de is quantity ld hl, stAtomQt call stackPushDE notYetInStack_: ret atoms2TblBuffer: atoms2TblBuffer_loop: ld hl, stAtomNr call stackPop or a jr z, atoms2TblBuffer_endloop ld hl, stTblAtom call stackpush ld hl, stAtomQt call stackPopDE ld hl, stTblAtomQt call stackPushDE jr atoms2TblBuffer_loop atoms2TblBuffer_endloop: call stackUnget ld hl, stTblAtom;laten zien dat dit einde/begin kolom is ld a, 250;gwon een getal waar geen atomnr voor is, zodat we dit getal gebruiken voor de Delimiter call stackPush ld hl, stTblAtomQt;nodig zodat index tzelfde blijft ;ld de, 3333;kan later weg call stackPushDE;maakt niet uit wat de is ret inf_: call atoms2TblBuffer ld hl, stackStartPos;we kunnen nu een nieuwe stack maken in t begin van de stack, omdat we 3 stacks niet meer nodig hebben:haakjesstack(we cant rely on this one, it can have a length of only one or something), stackAtomNr & stackAtomQt(total length 3x maxatoms, has to be enough, right?) ld (stackNewPos), hl ld hl, stTblAtomIx ld bc, maxAtoms*3 ld a, 1 call stackCreate jp c, menu2 ;01 ld hl, sttblatomix ld a, 212;zodat hij t einde weet call stackpush ; ;alle atoms in stTblAtom afgaan, en alle verschillende in deze tabel zetten ld ix, stTblAtom ld h, (ix+1) ld l, (ix+0) push hl;backup hl(index of sttblatom) so we can restore it after atom2ixloop: ld hl, stTblAtom call stackPop cp 250 jr z, atom2ixloop or a jr z, atom2ixloop_ ld hl, stTblAtomIx ld b, a;backup call stackFind jr nc, atom2ixloop ld a, b;restore ;call debuga call stackPush jr atom2ixloop atom2ixloop_: pop hl;restore ld ix, stTblAtom ld (ix+1), h ld (ix+0), l ld a, (methode) cp 1 jp z, molmassaback cp 2 jp z, zoekenintblback cp 3 jp z, atomDetailsBack