;LAST UPDATE: 08.12.2009 savelij
KEYS EI
HALT
DI
BIT 5,(IY+1)
JR Z,KEYS
LD A,(IY-0X32)
RES 5,(IY+1)
RET
VCURS PUSH AF
LD A,(CURSOR)
LD B,A
ADD A,A
ADD A,B
ADD A,A
LD B,A
LD A,(BUFFE+2)
ADD A,B
PUSH AF
LD DE,BUFTSC
LD HL,(BUFFE+1)
LD H,0
ADD HL,HL
ADD HL,DE
LD E,(HL)
INC HL
LD D,(HL)
RRCA
RRCA
RRCA
AND 0X1F
ADD A,E
LD L,A
LD H,D
POP AF
AND 7
LD B,A
LD A,0X80
JR Z,$+5
RRCA
DJNZ $-1
LD B,8
LD C,A
LD A,C
XOR (HL)
LD (HL),A
INC H
DJNZ $-4
POP AF
RET
ZADER LD A,15
DEC A
LD (ZADER+1),A
RET NZ
LD A,15
LD (ZADER+1),A
JP VCURS
INPUTT LD (BUFFE+1),HL
LD (LENGHT),A
LD L,A
INC A
LD (PRIBUF+1),A
PUSH HL
XOR A
LD HL,BUFFER
LD E,L
LD D,H
INC DE
LD BC,39
LD (HL),A
LDIR
SET 3,(IY+48)
POP HL
LD (CURSOR),A
LD H,A
LD DE,BUFFER
ADD HL,DE
LD (BUFEND),HL
LD A,(LENGHT)
LD B,A
LD HL,BUFFER
CLEAR LD (HL),0X20
INC HL
DJNZ CLEAR
ACCEPT LD HL,BUFFE
CALL PRIBUF
GETKEY CALL VCURS
CALL KEYS
CALL VCURS
CP 7
RET Z
; CP 6
; JR C,GETKEY
CP 0X0D
JP Z,ENTER
CP 8
JR Z,CRLEFT
CP 9
JR Z,CRRIGT
CP 0X0C
JR Z,DELETE
; CP 0X0F
; JP Z,INSOVR
CP 0X06
JP Z,CAPSLK
CP 0X21
JR C,GETKEY
CP 0X80
JR NC,GETKEY
LD E,A
LD A,(CURSOR)
LD B,A
LD A,(LENGHT)
SUB B
JR Z,GETKEY
LD C,A
LD A,B
INC A
LD (CURSOR),A
LD A,E
LD HL,(BUFEND)
LD D,H
LD E,L
BIT 6,(IY+48)
JR NZ,$+3
DEC HL
LD B,0
LDDR
LD (DE),A
JR ACCEPT
CRLEFT LD A,(CURSOR)
AND A
JR Z,GETKEY
DEC A
LD (CURSOR),A
JP ACCEPT
CRRIGT LD A,(LENGHT)
LD C,A
LD A,(CURSOR)
CP C
JP Z,GETKEY
INC A
LD (CURSOR),A
JP ACCEPT
DELETE LD A,(CURSOR)
AND A
JP Z,GETKEY
LD E,A
LD A,(LENGHT)
SUB E
INC A
LD C,A
LD A,E
DEC A
LD (CURSOR),A
LD HL,BUFFER
LD D,0
ADD HL,DE
LD D,H
LD E,L
DEC DE
LD B,0
LDIR
LD A,0X20
LD (DE),A
JP ACCEPT
INSOVR LD A,0X40
XOR (IY+48)
LD (IY+48),A
JP ACCEPT
CAPSLK LD A,8
XOR (IY+48)
LD (IY+48),A
JP ACCEPT
ENTER LD DE,BUFFER
LD HL,BUFEND-1
CLEAN LD A,(HL)
CP 0X21
JR NC,ENDEDIT
LD (HL),0
DEC HL
JR CLEAN
ENDEDIT XOR A
LD HL,BUFFER
RET
BUFFE DB 0X16,0,0
BUFFER DS 40
BUFEND DW 0
CURSOR DB 0
LETTER DB 0
LENGHT DB 0
MOVI LD DE,BUFFER
EX DE,HL
LD B,0
LDIR
EX DE,HL
RET
PRIBUF LD B,0
LD A,(HL)
INC HL
PUSH BC
CALL PRINT
POP BC
DJNZ PRIBUF+2
RET
ADRTSC LD B,0X18
LD DE,0X4000
LD HL,BUFTSC
LD C,8
LD (HL),E
INC HL
LD (HL),D
INC HL
INC D
DEC C
JR NZ,$-6
LD A,0X20
ADD A,E
LD E,A
JR C,$+6
LD A,D
SUB 8
LD D,A
DJNZ $-20
RET
WTABL LD L,(IX+6)
LD H,(IX+7)
ADD A,A
LD D,0
LD E,A
ADD HL,DE
LD E,(HL)
INC HL
LD D,(HL)
EX DE,HL
LD A,L
OR H
RET Z
JP (HL)
CLS LD HL,0X4000
LD E,L
LD D,H
LD (HL),L
INC E
LD BC,0X1800
LDIR
CLSCLR LD (0X5C8D),A
LD (0X5C48),A
LD HL,0X5800
LD D,H
LD E,L
LD (HL),A
LD BC,0X02FF
INC E
LDIR
RRCA
RRCA
RRCA
AND 7
OUT (0XFE),A
RET
INWERT LD A,(IX)
INC IX
ADD A,C
LD L,A
LD H,(IX)
INC IX
LD D,H
LD E,L
INC E
LD (HL),0XFF
PUSH BC
CALL LDIST
POP BC
DJNZ INWERT
RET
;X-L,Y-H,H-B,V-C
WINOUT PUSH HL
PUSH BC
PUSH IX
PUSH AF
LD A,0X22
SUB B
ADD A,A
LD (LDIST+1),A
PUSH BC
LD A,C
RLCA
RLCA
RLCA
DEC A
DEC A
LD B,A
LD IX,BUFTSC
EX DE,HL
LD L,D
LD H,0
ADD HL,HL
ADD HL,HL
ADD HL,HL
ADD HL,HL
EX DE,HL
ADD IX,DE
PUSH IX
LD C,L
POWT1 INC IX
INC IX
LD E,(IX)
LD D,(IX+1)
LD A,C
ADD A,E
LD E,A
EX DE,HL
LD (HL),0X80
RAMK0 EQU $-1
INC HL
LD (HL),0
LD D,H
LD E,L
INC E
PUSH BC
CALL LDIST
POP BC
LD (HL),1
RAMK1 EQU $-1
DJNZ POWT1
LD E,(IX)
LD D,(IX+1)
INC D
LD A,C
ADD A,E
LD E,A
EX DE,HL
LD (HL),0XFF
RAMK2 EQU $-1
LD D,H
LD E,L
INC E
PUSH BC
CALL LDIST
LDI
POP BC
POP IX
LD E,(IX)
LD D,(IX+1)
LD A,C
ADD A,E
LD E,A
EX DE,HL
LD (HL),0XFF
RAMK3 EQU $-1
LD D,H
LD E,L
INC E
PUSH BC
CALL LDIST
LDI
POP BC
LD A,(IX)
ADD A,C
LD E,A
LD A,(IX+1)
RRA
RRA
RRA
AND 0X0F
OR 0X50
LD D,A
EX DE,HL
POP DE
LD B,E
POP AF
POWT2 PUSH HL
LD D,H
LD E,L
INC E
LD (HL),A
PUSH BC
CALL LDIST
LDI
POP BC
POP HL
LD DE,0X20
ADD HL,DE
DJNZ POWT2
POP IX
POP BC
POP HL
RET
WINW BIT 6,(IX+8)
LD HL,0X8001
LD B,0XFF
JR Z,WINW1
LD HL,0
LD B,L
WINW1 LD A,H
LD (RAMK0),A
LD A,L
LD (RAMK1),A
LD A,B
LD (RAMK3),A
LD (RAMK2),A
LD L,(IX+0)
LD H,(IX+1)
LD C,(IX+2)
LD B,(IX+3)
LD A,(IX+4)
CALL WINOUT
BIT 5,(IX+8)
JR Z,W_NIZ
LD HL,LDIST+1
DEC (HL)
DEC (HL)
PUSH IX
LD C,(IX)
LD B,8
LD L,(IX+1)
LD H,0
LD IX,BUFTSC
ADD HL,HL
ADD HL,HL
ADD HL,HL
ADD HL,HL
EX DE,HL
ADD IX,DE
CALL INWERT
POP IX
W_NIZ BIT 7,(IX+8)
JR Z,RASCH
PUSH IX
LD C,(IX)
LD B,8
LD A,(IX+1)
ADD A,(IX+2)
DEC A
LD L,A
LD H,0
ADD HL,HL
ADD HL,HL
ADD HL,HL
ADD HL,HL
LD IX,BUFTSC
EX DE,HL
ADD IX,DE
CALL INWERT
POP IX
RASCH LD A,(IX)
ADD A,A
ADD A,A
ADD A,A
INC A
LD D,A
LD (XNEW+1),A
LD (EX2+1),A
LD A,(IX+1)
ADD A,A
ADD A,A
ADD A,A
LD E,A
LD (ADRSTR+1),DE
LD A,(IX+3)
ADD A,A
ADD A,A
ADD A,A
LD (EX1+1),A
BIT 4,(IX+8)
RET NZ
LD L,(IX+13)
LD H,(IX+14)
JP NEXT
SCRUP PUSH BC
PUSH IX
LD L,(IX+1)
INC L
CALL USTAN
LD A,(IX+0X10)
ADD A,C
LD L,A
LD H,(IX+0X11)
LD A,(IX)
ADD A,C
LD E,A
LD D,(IX+1)
CALL SHIFT
LD DE,0X10
ADD IX,DE
DJNZ $-24
POP IX
POP BC
RET
SCRDN PUSH BC
PUSH IX
LD A,(IX+2)
ADD A,(IX+1)
SUB 3
LD L,A
CALL USTAN
LD A,(IX)
ADD A,C
LD L,A
LD H,(IX+1)
LD A,(IX+0X10)
ADD A,C
LD E,A
LD D,(IX+0X11)
CALL SHIFT
LD DE,0XFFF0
ADD IX,DE
DJNZ $-24
POP IX
POP BC
RET
SHIFT PUSH BC
REPT 8
PUSH HL
PUSH DE
CALL LDIST
POP DE
POP HL
INC H
INC D
ENDM
POP BC
RET
LDIST JR $
REPT 32
LDI
ENDM
RET
USTAN LD A,0X20
SUB (IX+3)
ADD A,A
LD (LDIST+1),A
LD C,(IX) ;СМЕЩЕНИЕ ПО X
LD B,(IX+2) ;ВЫСОТА В ЗНАКОМЕСТАХ
DEC B
DEC B
DEC B
LD H,0
ADD HL,HL
ADD HL,HL
ADD HL,HL
LD IX,BUFTSC
EX DE,HL
ADD IX,DE
ADD IX,DE
RET
ADRDIS LD (ASD+1),A
LD A,L
AND 0X18
OR 0X40
EX AF,AF'
LD A,L
AND 7
RRCA
RRCA
RRCA
ADD A,H
LD L,A
EX AF,AF'
LD H,A
LD E,L
ADRATR LD A,H
RRCA
RRCA
RRCA
AND 3
OR 0X58
LD D,A
ASD LD A,0
RET
INCHL INC H
LD A,H
AND 7
RET NZ
LD A,L
ADD A,0X20
LD L,A
RET C
UMEHL1 LD A,H
SUB 8
LD H,A
RET
DECHL DEC H
LD A,H
AND 7
CP 7
RET NZ
LD A,L
SUB 0X20
LD L,A
RET C
UVEHL1 LD A,H
ADD A,8
LD H,A
RET
UVEHL LD A,0X20
ADD A,L
LD L,A
RET NC
JR UVEHL1
UMEHL LD A,L
SUB 0X20
LD L,A
RET NC
JR UMEHL1
NEXT LD A,(HL)
INC HL
AND A
RET Z
CALL PRINT
JR NEXT
PRINT CP 0X20
JR NC,PRINTA
CP 3
JR NZ,COD9
CENTR LD B,0 ;ЦЕНТРОВКА СТРОКИ В ОКНЕ
PUSH HL
CEN2 LD A,(HL)
CP 0X20
JR C,EX1
LD A,6
ADD A,B
LD B,A
INC HL
JR CEN2
EX1 LD A,0
SUB B
SRL A
DEC A
EX2 ADD A,0
LD (ADRSTR+2),A
POP HL
RET
COD9 CP 9
JR NZ,COD13
LD A,(HL) ;ТАБУЛЯЦИЯ НА N ПОЗИЦИЙ
INC HL
LD B,A
ADD A,A
ADD A,B
ADD A,A
LD B,A
LD A,(ADRSTR+2)
ADD A,B
LD (ADRSTR+2),A
RET
COD13 CP 0X0D
JR NZ,COD14
XNEW LD A,0 ;ПЕРЕВОД СТРОКИ
LD (ADRSTR+2),A
LD A,(ADRSTR+1)
ADD A,8
LD (ADRSTR+1),A
RET
COD14 CP 0X14
JR NZ,COD16
LD A,(HL) ;ВКЛ/ВЫКЛ ИНВЕРСИИ ПЕЧАТИ
INC HL
AND A
JR Z,$+4
LD A,0XFC
LD (NO_INW+1),A
RET
COD16 CP 0X16
RET NZ
LD E,(HL) ;ПЕЧАТЬ В УКАЗАННОЙ ПОЗИЦИИ
INC HL
LD D,(HL)
INC HL
LD (ADRSTR+1),DE
RET
;ПЕЧАТЬ СИМВОЛА В "A"
PRINTA PUSH HL
PUSH DE
LD DE,CHARS
LD L,A
XOR A
LD H,A
ADD HL,HL
ADD HL,HL
ADD HL,HL
ADD HL,DE
EXX
ADRSTR LD HL,0 ;H=X L=Y
LD D,A
LD A,H
AND 0XF8
LD B,A
LD A,H
AND 7
LD C,A
LD A,6
ADD A,H
LD H,A
LD (ADRSTR+1),HL
LD E,L
LD A,B
LD HL,BUFTSC
LD B,D
ADD HL,DE
ADD HL,DE
RRCA
RRCA
RRCA
ADD A,(HL)
INC HL
LD E,A
LD D,(HL)
LD A,21
SUB C
SUB C
SUB C
LD (SKOLKO+1),A
LD HL,BUFMSK
ADD HL,BC
ADD HL,BC
LD A,(HL)
INC HL
LD H,(HL)
LD L,A
EX DE,HL
LD A,8
SLEDU EX AF,AF'
EXX
LD A,(HL)
INC HL
EXX
NO_INW XOR 0
LD C,A
XOR A
SKOLKO JR $+21
REPT 7
SRL C ;8
RRA ;4
ENDM
LD B,A
LD A,(HL)
AND E
OR C
LD (HL),A
INC L
LD A,(HL)
AND D
OR B
LD (HL),A
DEC L
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XCC,0XCD,0XCE,0XCF,0XD0,0XD1,0XD2
;DB 0XD3,0XD4,0XD5,0XD6,0XD7,0XD8,0XD9
;DB 0XDA,0XDB,0XDC,0XDD,0XDE,0XDF,0X9B
;DB 0X9C,0X9D,0XA5,0XA7,0X83,0X84,0X85
;DB 0X86,0X97,0X95,0X91,0X92,0X8B,0X8C
;DB 0XA1,0XA3,0XA8,0XA6,0XA9,0XA4,0XAA
;DB 0X8D,0X8E,0X93,0X90,0X98,0X96,0X99
;DB 0X94,0X9A,0X80,0X81,0X82,0X87,0X88
;DB 0X89,0X8A,0X8F,0X9E,0X9F,0XA2,0XA0
;DB 0XAB,0XAC,0XAD,0XAE,0XAF
;DB 0XE0,0XE1,0XE2,0XE3,0XE4,0XE5,0XE6
;DB 0XE7,0XE8,0XE9,0XEA,0XEB,0XEC,0XED
;DB 0XEE,0XEF,0XF0,0XF1,0XF2,0XF3,0XF4
;DB 0XF5,0XF6,0XF7,0XF8,0XF9,0XFA,0XFB
;DB 0XFC,0XFD,0XFE,0XFF
HEX2TXT LD HL,TXT_HEX
PUSH HL
LD A,B
CALL HEX_CON
LD A,C
CALL HEX_CON
LD A,D
CALL HEX_CON
LD A,E
CALL HEX_CON
LD (HL),0
POP HL
RET
HEX_CON LD B,A
RRCA
RRCA
RRCA
RRCA
CALL ML_BYT
LD A,B
ML_BYT AND 0X0F
ADD A,0X30
CP 0X3A
JR C,$+4
ADD A,7
LD (HL),A
INC HL
RET
HEX4DEC EXX
LD HL,TXT_DEC
PUSH HL
PUSH HL
LD B,9
EXX
LD HL,CHISLA4
REPT 9
CALL BCDEMHL
ENDM
H2D1 LD A,0X30
ADD A,E
EXX
LD (HL),A
INC HL
LD (HL),0
LD A,B
EXX
POP HL
LD B,A
LD A,(HL)
CP 0X30
JR NZ,$+7
LD (HL),0X20
INC HL
DJNZ $-8
POP HL
RET
HEX2DEC EXX
LD HL,TXT_DEC
PUSH HL
PUSH HL
LD B,4
EXX
LD HL,CHISLA2
LD BC,0
JR H2D1-(4*3)
HEX1DEC EXX
LD HL,TXT_DEC
PUSH HL
PUSH HL
LD B,2
EXX
LD HL,CHISLA1
LD BC,0
LD D,0
JR H2D1-(2*3)
CHISLA4 DB 0X00,0XCA,0X9A,0X3B;1000000000
DB 0X00,0XE1,0XF5,0X05;100000000
DB 0X80,0X96,0X98,0X00;10000000
DB 0X40,0X42,0X0F,0X00;1000000
DB 0XA0,0X86,0X01,0X00;100000
CHISLA2 DB 0X10,0X27,0X00,0X00;10000
DB 0XE8,0X03,0X00,0X00;1000
CHISLA1 DB 0X64,0X00,0X00,0X00;100
DB 0X0A,0X00,0X00,0X00;10
;BCDE-(ADR)=BCDE
BCDEMHL XOR A
EX AF,AF'
LD A,E
SUB (HL)
INC HL
LD E,A
LD A,D
SBC A,(HL)
INC HL
LD D,A
LD A,C
SBC A,(HL)
INC HL
LD C,A
LD A,B
SBC A,(HL)
LD B,A
DEC HL
DEC HL
DEC HL
EX AF,AF'
INC A
EX AF,AF'
LD A,B
CP 0XC4
JR C,BCDEMHL+2
LD A,(HL)
ADD A,E
LD E,A
INC HL
LD A,(HL)
ADC A,D
LD D,A
INC HL
LD A,(HL)
ADC A,C
LD C,A
INC HL
LD A,(HL)
ADC A,B
LD B,A
DEC HL
DEC HL
DEC HL
EX AF,AF'
DEC A
ADD A,0X30
INC HL
INC HL
INC HL
INC HL
EXX
LD (HL),A
INC HL
EXX
RET
CP_KEYS POP HL
LD B,A
CPKEYS1 LD A,(HL)
INC HL
AND A
JR NZ,$+3
JP (HL)
LD E,(HL)
INC HL
LD D,(HL)
INC HL
CP B
JR NZ,CPKEYS1
PUSH DE
CPKEYS2 LD A,(HL)
INC HL
AND A
JR NZ,$+4
EX (SP),HL
JP (HL)
INC HL
INC HL
JR CPKEYS2
PAG_128 PUSH BC
LD BC,0X7FFD
OR 0X10
OUT (C),A
; LD (PAGE128),A
POP BC
RET