;*************************************************************************
;
;:Program.       EdAssemSup.asm
;:Contents.      Assembler-Routines for AmokEd
;:Author.        Tobias Ruland, Hartmut Goebel
;:Language.      MC68000-Assembler
;:History.       V1.0,  3/90, Tobias Ruland, Hartmut Goebel
;:History.       V1.0c, 04 Aug 1991 [hG]: Angepasst: lst.Node ist STRUCT
;
;*************************************************************************

        XDEF FindNext
        XDEF FindPrev

l.next     = 0
l.prev     = 4
l.string   = 8   ; ab hier + 4, wenn RECORD!! (wg. Typeguard)
l.len      = 12

fs.find    = 0
fs.line    = 4
fs.flen    = 8
fs.pos     = 10


        SECTION FindNext

FindNext:
        move.l  fs.find(a0),a1        ; Find-String-Pointer
        move.l  fs.line(a0),a4        ; Startline-Struktur --> a4
        move.l  l.string(a4),a2       ; Pointer auf LineBuffer --> a2
        move    fs.pos(a0),d6
        move    d6,d5                 ; Sicherheitskopie pos --> d5
        move.l  a1,a3                 ; Sicherheitskopie FindStr --> a1
        move.l  #0,d7                 ; anzahl zeilenwechsel
CompIt:
        tst.b   (a3)
        beq     foundIt
        tst.b   0(a2,d6)
        beq     getNextLine
        move.b  0(a2,d6),d4
        cmp.b   (a3)+,d4
        beq     nochGleich
        move.l  a1,a3                 ; von vorne
        addq    #1,d5
        move    d5,d6
        bra     CompIt
nochGleich:
        addq    #1,d6
        bra     CompIt
getNextLine:
        move.l  l.next(a4),a4
        cmpa.l  #0,a4
        beq     notFound
        move.l  l.string(a4),a2
        moveq   #0,d6
        moveq   #0,d5
        move.l  a1,a3
        add.l   #1,d7
        bra     CompIt
foundIt:
        sub     fs.flen(a0),d6       ; an Wortanfang
        move    d6,fs.pos(a0)
        move.l  a4,fs.line(a0)
        move.l  d7,d0
        rts
notFound:
        move.l  d7,d1
        move.l  #-1,d0
        rts

;-------------------------------------------------------------------------

        SECTION FindPrev

FindPrev:
        move.l  fs.find(a0),a1        ; Find-String-Pointer
        move.l  fs.line(a0),a4        ; Startline-Struktur --> a4
        move.l  l.string(a4),a2       ; Pointer auf LineBuffer --> a2
        move    fs.pos(a0),d6         ; Cursorposition
        move    fs.flen(a0),d3        ; Länge des FindStrings
        move.l  a1,a3                 ; Sicherheitskopie FindStr --> a1
        move.l  #0,d7                 ; anzahl zeilenwechsel
        subq    #2,d6
        move    d6,d5
        tst     d6
        bmi     getPrevLine
P.CompIt:
        tst.b   (a3)
        beq     foundIt
        move.b  0(a2,d6),d4
        cmp.b   (a3)+,d4
        beq     p.nochGleich
        move.l  a1,a3                 ; von vorne
        subq    #1,d5
        bmi     getPrevLine
        move    d5,d6
        bra     P.CompIt
p.nochGleich:
        addq    #1,d6
        bra     P.CompIt
getPrevLine:
        move.l  l.prev(a4),a4
        cmpa.l  #0,a4
        beq     notFound
        add.l   #1,d7
        move.l  l.string(a4),a2
        move    l.len(a4),d6
        subq    #8,d6
eol.search:
        tst.b   0(a2,d6)
        beq     eol.found
        addq    #1,d6
        bra     eol.search
eol.found:
        sub     d3,d6
        bmi     getPrevLine
        move    d6,d5
        move.l  a1,a3
        bra     P.CompIt
;
        END

