(*---------------------------------------------------------------------------
  :Program.       Characters.asm
  :Author.        Thomas Clever
  :Address.       Bürhausen 9, D-5883 Kierspe 3
  :Phone.         02269/7084
  :ShortCut.      [tcl]
  :Version.       1.4
  :Date.          26.09.90
  :Copyright.     PD
  :Language.      ASSEMBLER
  :Translator.    Devpac 2.0 + ObjektKonverter (m2oc)
  :Contents.      Bearbeitung von einzelnen Zeichen und einzelnen Zeichen
  :Contents.      innerhalb von Zeichenketten.
  :History.       V1.0 [tcl] Juli 1989
  :History.       V1.1, V1.2 [tcl] Prozeduren hinzugefügt
  :History.       V1.3 [tcl] an ObjektKonverter angepaßt
  :History.       V1.4 [tcl] Prozeduren hinzugefügt
---------------------------------------------------------------------------*)

  INCLUDE Characters.i

; *************** Allgemeine Registerbelegung ******************

retAdr    EQUR  a0     ;Rücksprung-Adresse
str       EQUR  a1     ;Parameter
high      EQUR  d7     ;Parameter
pos       EQUR  d5     ;Parameter
ch        EQUR  d0     ;Parameter

*****************************************************************
**   PROCEDURE Letter( ch{0}: CHAR ): BOOLEAN;

Letter:
    cmp.b     #"A",d0
    blt.s     .returnFALSE
    cmp.b     #"Z",d0
    ble.s     .returnTRUE
    cmp.b     #"a",d0
    blt.s     .returnFALSE
    cmp.b     #"z",d0
    bgt.s     .returnFALSE
.returnTRUE
    moveq     #-1,d0
    bra.s     .end
.returnFALSE
    moveq     #0,d0
.end
    rts


*****************************************************************
**  PROCEDURE NatLetter( ch{0}: CHAR ): BOOLEAN;

NatLetter:
    cmp.b     #"A",d0
    blt.s     .returnFALSE
    cmp.b     #"Z",d0
    ble.s     .returnTRUE
    cmp.b     #"a",d0
    blt.s     .returnFALSE
    cmp.b     #"z",d0
    ble.s     .returnTRUE
    cmp.b     #192,d0
    bge.s     .returnTRUE
.returnFALSE
    moveq     #0,d0
    bra.s     .end
.returnTRUE
    moveq     #-1,d0
.end
    rts


*****************************************************************
**  PROCEDURE Digit( ch{0}: CHAR ): BOOLEAN;

Digit:
    cmp.b     #"0",d0
    blt.s     .returnFALSE
    cmp.b     #"9",d0
    bgt.s     .returnFALSE
.returnTRUE
    moveq     #-1,d0
    bra.s     .end
.returnFALSE
    moveq     #0,d0
.end
    rts


*****************************************************************
**  PROCEDURE NatCAP( ch{0}: CHAR ): CHAR;

NatCAP:
    cmp.b     #'a',d0
    blt.s     .end
    cmp.b     #'z',d0
    ble.s     .sub32
    cmp.b     #224,d0
    blt.s     .end
    cmp.b     #254,d0
    bgt.s     .end
.sub32
    sub.b     #32,d0
.end
    rts


*****************************************************************
**  PROCEDURE LOW( ch{0}: CHAR ): CHAR;

LOW:
    cmp.b     #"Z",d0
    bgt.s     .end
    cmp.b     #"A",d0
    blt.s     .end
    add.b     #32,d0
.end
    rts


*****************************************************************
**  PROCEDURE NatLOW( ch{0}: CHAR ): CHAR;

NatLOW:
    cmp.b     #'A',d0
    blt.s     .end
    cmp.b     #'Z',d0
    ble.s     .add32
    cmp.b     #192,d0
    blt.s     .end
    cmp.b     #222,d0
    bgt.s     .end
.add32
    add.b   #32,d0
.end
    rts


*****************************************************************
**  PROCEDURE LastChar( str: ARRAY OF CHAR ): CHAR;

LastChar:
    move.l    (sp)+,retAdr
    move.l    (sp)+,str
    move.l    (sp)+,high
    chk       #$7FFE,high

    move.l    str,a2              Anfangsadresse von 'str' retten
    moveq     #0,d0               Ergebnis-Register löschen

.loop
    tst.b     (str)+
    dbeq      high,.loop
    bne.s     .Ende_durch_HIGH

.Ende_durch_NULL
    subq.l    #1,str
    cmp.l     a2,str
    bgt.s     .String_nicht_leer
    bra.s     .end                String leer, Rückgabe 0C

.String_nicht_leer
.Ende_durch_HIGH
    move.b    -1(str),d0

.end
    jmp       (retAdr)


****************************************************************************
**  PROCEDURE InsertChar( VAR str: ARRAY OF CHAR; pos: INTEGER; ch: CHAR );

source  EQUR  a2
x       EQUR  d2

InsertChar:
    move.l    (sp)+,retAdr
    move.b    (sp)+,ch
    move.w    (sp)+,pos
    move.l    (sp)+,str
    move.l    (sp)+,high
    chk       #$7FFE,high
    tst.w     pos               ;pos < 0 ?
    blt.s     .end
.kopieren
    add.l     high,str
    move.l    str,source      source = Quelle
    addq.l    #1,str          str = Ziel
    move.w    high,x
    sub.w     pos,x
    blt.s     .end
    beq.s     .insert
    subq.w    #1,x            x = Anzahl der Schleifendurchläufe
.loop
    move.b    -(source),-(str)
    dbra      x,.loop
.insert
    move.b    ch,-(str)
.end
    jmp       (retAdr)


*****************************************************************
**  PROCEDURE AppendChar( VAR str: ARRAY OF CHAR; ch: CHAR );

AppendChar:
    move.l    (sp)+,retAdr
    move.b    (sp)+,ch
    move.l    (sp)+,str
    move.l    (sp)+,high
    chk       #$7FFE,high
    move.l    str,a2
    move.l    high,d2
.loop
    tst.b     (a2)+
    dbeq      d2,.loop
    bne.s     .append
    subq.l    #1,a2
.append
    adda.l    high,str
    cmp.l     str,a2
    bgt.s     .end
    beq.s     2$
    clr.b     1(a2)
2$: move.b    ch,(a2)
.end
    jmp       (retAdr)


*****************************************************************
** PROCEDURE DeleteChar( VAR str: ARRAY OF CHAR; pos: INTEGER );

DeleteChar:
    move.l  (sp)+,retAdr
    move.w  (sp)+,pos
    move.l  (sp)+,str
    move.l  (sp)+,high      ;wird im Programmverlauf verändert!
    chk     #$7FFE,high

    tst.w   pos             ;pos < 0 ?
    blt.s   .end

    add.w   pos,str
    move.l  str,a2          ;a2 = source, str = dest
    addq.l  #1,a2
    sub.w   pos,high
    blt.s   .end            ;pos > HIGH(str)
    subq.w  #1,high
    blt.s   .nul
.loop
    move.b  (a2)+,(str)+
    dbeq    high,.loop

.nul
    clr.b   (str)

.end
    jmp     (retAdr)


*****************************************************************
**  PROCEDURE DeleteLastChar( VAR str: ARRAY OF CHAR );

DeleteLastChar:
    move.l    (sp)+,retAdr
    move.l    (sp)+,str
    move.l    (sp)+,high
    chk       #$7FFE,high

    move.l    str,a2              Anfangsadresse von 'str' merken
.loop
    tst.b     (str)+
    dbeq      high,.loop
    bne.s     .Ende_durch_HIGH

.Ende_durch_NULL
    subq.l    #1,str
    cmp.l     a2,str
    bgt.s     .String_nicht_leer
    bra.s     .end                 String ist leer --> nichts tun

.String_nicht_leer
.Ende_durch_HIGH
    clr.b     -1(str)

.end
    jmp       (retAdr)


****************************************************************************
** PROCEDURE ReplaceChar( VAR str: ARRAY OF CHAR; char, repl: CHAR );

;retAdr     EQUR  a0     ;Rücksprung-Adresse
;str        EQUR  a1     ;Parameter
;high       EQUR  d7     ;Parameter
char        EQUR  d0     ;Parameter
repl        EQUR  d1     ;Parameter

ReplaceChar:
    move.l  (sp)+,retAdr
    move.b  (sp)+,repl
    move.b  (sp)+,char
    move.l  (sp)+,str
    move.l  (sp)+,high

.loop
    move.b  (str)+,d2
    beq.s   .end
    cmp.b   d2,char
    bne.s   1$
    move.b  repl,-1(str)
1$  subq.l  #1,high
    bge.s   .loop

.end
    jmp     (retAdr)


****************************************************************************
CharactersInit
    rts

    END
