        MAIN "*.*",134

;String Editor v2.0

EDIT    RES 0,(IX+5)
        LD A,16
        LD (23658),A
        XOR A
        LD (POS_),A
        LD A,B
        LD (MAXPOS_),A
        LD (STR_ADR),HL
        LD A,(IX+0)
        ADD A,D
        LD D,A
        LD A,(IX+1)
        ADD A,E
        LD E,A
        LD (KURS_XY),DE
REFR
        PUSH DE
        CALL WIN
        POP DE
;       SET 0,(IX+5)
        CALL KURSOR
EDIT1
        XOR A
        LD (23560),A
        EI 
        HALT 
        LD A,(23560)
        AND A
        JR Z,EDIT1
        CP " "
        JP NC,EDIT_SYM
;       CP 7
;       JP Z,SWITCH
        CP 9
        JP Z,RIGHT
        CP 8
        JP Z,LEFT
        CP 13
        JR Z,EXIT
        CP 12
        JR Z,BACK_SP
        CP 15
        JR Z,DELETE
        CP 7;               14
        JR Z,EXIT
        CP 6
        JR Z,LOCK
        JR EDIT1

LOCK
        LD A,(23658)
        AND A
        JR NZ,LOCK1
        LD A,8
        JR LOCK2
LOCK1
        XOR A
LOCK2
        LD (23658),A
        JP EDIT1

EXIT
        LD DE,(KURS_XY)
        CALL KURSOR
        SET 0,(IX+5)
        RET 

DELETE
        LD A,(POS_)
        LD E,A
        LD D,0
        LD HL,(STR_ADR)
        ADD HL,DE
        LD A,(MAXPOS_)
        CP 1
        JR Z,DELETE1
        SUB E
        AND A
        JP Z,EDIT1
        LD C,A
        LD B,0
        PUSH HL
        POP DE
        INC HL
        LDIR 
        DEC HL
DELETE1
        LD (HL)," "
        LD DE,(KURS_XY)
        JP REFR

BACK_SP
        LD A,(POS_)
        AND A
        JP Z,EDIT1
        DEC A
        LD (POS_),A
        LD E,A
        LD D,0
        LD HL,(STR_ADR)
        ADD HL,DE
        LD A," "
        LD (HL),A
        LD DE,(KURS_XY)
        DEC D
        LD (KURS_XY),DE
        JP REFR

EDIT_SYM
        CALL PEREKOD
        PUSH AF
        LD A,(POS_)
        LD C,A
        LD B,0
        LD HL,(STR_ADR)
        ADD HL,BC
        LD DE,(KURS_XY)
        LD C,A
        LD A,(MAXPOS_)
        DEC A
        JR Z,EDIT_SYM1
        CP C
        JR C,EDIT_SYM1
        LD A,C
        INC A
        LD (POS_),A
        INC D
EDIT_SYM1
        LD (KURS_XY),DE
        POP AF
        LD (HL),A
;       SET 0,(IX+5)
        JP REFR
LEFT
        LD A,(POS_)
        AND A
        JP Z,EDIT1
        DEC A
        LD (POS_),A
        LD DE,(KURS_XY)
        CALL KURSOR
        DEC D
        LD (KURS_XY),DE
        CALL KURSOR
        JP EDIT1

RIGHT
        LD A,(MAXPOS_)
        CP 1
        JP Z,EDIT1
        LD C,A
        LD A,(POS_)
        CP C
        JP NC,EDIT1
        INC A
        LD (POS_),A
        LD DE,(KURS_XY)
        CALL KURSOR
        INC D
        LD (KURS_XY),DE
        CALL KURSOR
        JP EDIT1

KURS_XY DEFW #0000
STR_ADR DW 0
POS_     DB 0
MAXPOS_  DB 0

;DE=XY
KURSOR  CALL RASCH
        LD A,6
        ADD A,H
        LD H,A
        LD A,(HL)
        CPL 
        LD (HL),A
        INC H
        LD A,(HL)
        CPL 
        LD (HL),A
        RET 

PEREKOD
        LD L,A
        LD H,0
        LD DE,LAT_TAB
PER_TAB EQU $-2
        ADD HL,DE
        LD A,(HL)
        RET 

;             0123456789ABCDEF
LAT_TAB
        DEFB "................";0
        DEFB "................";1
        DEFB " !"
        DEFB #22;Š€‚›—Šˆ
        DEFB    "#$%&'()*+,-./";2
        DEFB "0123456789:;<=>?";3
        DEFB "@ABCDEFGHIJKLMNO";4
        DEFB "PQRSTUVWXYZ[\]^_";5
        DEFB "`abcdefghijklmno";6
        DEFB "pqrstuvwxyz{|}~.";7
        DEFB "................";8
        DEFB "................";9
        DEFB "................";A
        DEFB "................";B
        DEFB "...|.][....}{\..";C
        DEFB "................";D
        DEFB "..~.............";E
        DEFB "................";F

