;LAST UPDATE: 25.01.19 savelij
include ../../macros.a80
ORG 0X6000
;CMOS SetUp & HELP для Gluk
secHDD EQU 0XA000 ;GLUcat
secOLD EQU secHDD+512
symm EQU 0 ;символьный режим в докторе
SYSREG_EFF7 EQU 0XEFF7
SET_ADR EQU 0XDFF7
RD_WR_DATA EQU 0XBFF7
CMOS_ON EQU 0X80
CMOS_OFF EQU 0
LD BC,0X7FFD
LD A,0X10
OUT (C),A ;выключаем ROM 128 бейсика
LD HL,0X010F
LD (0X5C09),HL
EI
CALL HELPCLS
JP C,TSTKEY
LD A,0XFE
IN A,(0XFE)
AND 8 ;"C"
JP Z,COLTEST
LD A,0XFD
IN A,(0XFE)
AND 2
JP NZ,PRHELP ;anykey, не "S"
CDE0 LD A,(CDECURadr)
AND 0XFE
CP 0X13*2
LD HL,TZERO
JR NC,CDEnomsg
LD HL,TCMOSMSGS
ADD A,L
LD L,A
JR NC,$+3
INC H
LD A,(HL)
INC HL
LD H,(HL)
LD L,A
CDEnomsg
CALL PRHELPP
LD HL,TNORM
CALL PRHELP0
RES 5,(IY+1)
CDENKEY HALT
LD HL,0X5903
LD (HL),7
DEC L
LD (HL),7
DEC L
LD (HL),5
DEC L
LD (HL),5
LD DE,0X5904
LD BC,0X80-4
LDIR
LD A,0X38
CALL CDECUR
LD DE,0X4800
LD H,0
GOPR0 PUSH HL
CALL READ_CMOS
CALL PRHEX
POP HL
INC H
BIT 6,H
JR Z,GOPR0
LD E,0XA0
LD H,0
GOPR1 PUSH HL
CALL READ_CMOS
CALL PR88
POP HL
INC H
BIT 6,H
JR Z,GOPR1
BIT 5,(IY+1)
JR Z,CDENKEY
LD HL,CDE0
PUSH HL
LD L,0
CDECURadr EQU $-1
LD A,(0X5C08)
DEC L
CP 8
JR Z,CDE0OK
INC L
CP 9
JR Z,CDEyR
CP 10
JR NZ,CDEnD
LD A,L
ADD A,0X20
LD L,A
JR CDE0OK
CDEnD CP 0X0B
JR NZ,CDEnU
LD A,L
SUB 0X20
LD L,A
JR CDE0OK
CDEnU CALL CDEin0F ;0..9A..F
RET C
LD E,A
LD H,L
SRL H
CALL READ_CMOS
BIT 0,L
JR NZ,CDE0Frgt
AND 0X0F
REPT 4
SLA E
ENDM
JR CDE0FrQ
CDE0Frgt
AND 0XF0
CDE0FrQ OR E
PUSH HL
LD H,L
SRL H
LD L,A
CALL WRITE_CMOS
POP HL
CDEyR INC L
CDE0OK RES 7,L
LD A,L
LD (CDECURadr),A
RET
CDEnR
CDEin0F OR 0X20
SUB "0"
RET C
CP 0X0A
CCF
RET NC ;0..9
CP 0X61-0X30 ;"a"-"0"
RET C
SUB 0X61-0X3A ;"a"-":"
CP 0X10
CCF
RET
CDECUR LD HL,(CDECURadr)
LD H,0X59
LD (HL),A
RET
PRHEX PUSH AF
REPT 4
RRCA
ENDM
CALL $+4
POP AF
AND 0X0F
CP 0X0A
CCF
ADC A,"0"
DAA
PR88 PUSH BC
PUSH DE
PUSH HL
ADD A,A
CP 0X40
JR NC,$+4
LD A,0X2E*2 ;"."*2
LD L,A
LD H,0X0F
ADD HL,HL
ADD HL,HL
LD B,8
LD A,(HL)
LD (DE),A
INC L
INC D
DJNZ $-4
POP HL
POP DE
POP BC
INC E
RET
COLTEST LD IXL,0
COLTESU LD A,IXL
OUT (0X0FE),A
LD DE,0X4001
LD BC,0X600
LD H,D
LD L,C
LD (HL),0X7E
LDIR
LD B,2
LD (HL),L
LDIR
LD B,8
DEC (HL)
LDIR
LD C,0XAA
COLTST0 LD (HL),C
INC L
JR NZ,$-2
LD A,C
CPL
LD C,A
INC H
BIT 3,H
JR Z,COLTST0
COLTST1 LD A,B
XOR 0XC0
LD (HL),A
INC HL
LD (HL),A
INC HL
INC B
BIT 1,H
JR Z,COLTST1
COLTST2 LD A,L
XOR 0X80
RRA
LD (HL),A
INC HL
LD (HL),A
INC L
JR NZ,COLTST2
COLTSYK EI
HALT
XOR A
IN A,(0XFE)
CPL
AND 0X1F
JR NZ,COLTSYK
COLTSTK DI
PULS SBC A,A ;если не будет,то only для компов с FE:765=111
PULSI INC A
OUT (0XFB),A
DJNZ PULSI
PULSD OUT (0XFB),A
INC B
DEC A
JR NZ,PULSD
XOR A
IN A,(0XFE)
RRA
JR C,PULS
INC IXL
JR COLTESU
WRITE_CMOS
CALL onCMOS
LD A,H
LD BC,SET_ADR
OUT (C),A
LD A,L
LD BC,RD_WR_DATA
OUT (C),A
offCMOS LD BC,SYSREG_EFF7
LD A,CMOS_OFF
OUT (C),A
EI
RET
onCMOS DI
LD BC,SYSREG_EFF7
LD A,CMOS_ON
OUT (C),A
RET
READ_CMOS
CALL onCMOS
LD A,H
LD BC,SET_ADR
OUT (C),A
LD BC,RD_WR_DATA
IN A,(C)
LD H,A
CALL offCMOS
LD A,H
AND A
RET
TSTKEY LD HL,TTSTKEY
CALL PRHELPP
TSTKEY0 HALT
LD BC,0XFEFE
LD HL,0X5860
CALL TSTKEYP
LD L,9
CALL TSTKEYP
JR TSTKEY0
TSTKEYP LD E,4
TSTKEY1 LD D,5
IN A,(C)
TSTKEY2 RRA
LD (HL),7
JR C,$+4
LD (HL),0X30
TSTKEYi INC L
DEC D
JR NZ,TSTKEY2
LD A,L
TSTKEYs SUB 0X25
LD L,A
RLC B
DEC E
JR NZ,TSTKEY1
LD DE,TSTKEYi
LD A,(DE)
XOR 1 ;inc/dec
LD (DE),A
LD DE,TSTKEYs
LD A,(DE)
XOR 0X10 ;add/sub
LD (DE),A
RET
PRHELPP LD DE,0X4000
PRHELP0 LD A,(HL)
INC HL
OR A
RET Z
CALL PR88
JR NZ,$+6
LD A,D
ADD A,8
LD D,A
JR PRHELP0
PRHELP LD HL,THELP
CALL PRHELPP
;инициализировать TR-DOS (15649 не помогает)
LD HL,SYSVAR
LD DE,0X5C00
LD BC,SYS1LN
LDIR
LD E,LOW (0X5C36)
LD C,SYS2L1
LDIR
LD E,LOW (0X5CC8)
LD C,SYS2L2
LDIR
LD E,LOW (0X5CD6)
LD C,SYS2L3
LDIR
LD E,LOW (0X5C0C)
LD C,SYS2L4
LDIR
LD E,LOW (0X5C26)
LD C,SYS2L5
LDIR
LD A,0XC9
LD (0X5CC2),A
DDDKN RES 5,(IY+1)
DDDK0 BIT 5,(IY+1)
JR Z,DDDK0
LD A,(0X5C08)
SUB "1"
CP 4
JR NC,DDDKN
LD C,1
CALL 0X3D13
LD C,0X18
CALL 0X3D13
DISKDOC LD (IY+48),0 ;A
CALL HELPCLS
HDELOAD LD HL,HDEDUMP
PUSH HL
LD DE,0X4000
CALL INH
RET C
REPT 4 ;HDEDUMP
ADD A,A
ENDM
LD H,A
CALL INH
RET C ;HDEDUMP
ADD A,H
LD H,A
CALL INH
RET C ;HDEDUMP
LD L,A
LD (HDEts),HL
EX DE,HL
POP HL
LD BC,0X105
HDE3D13 LD DE,0XFFFF
HDEts EQU $-2
LD HL,secHDD
CALL 0X3D13
HDE2COPY
LD HL,secHDD
LD DE,secOLD
LD B,1 ;BC,512
LDIR
HDEDUMP CALL PRDUMP ;печатаем дамп
HDE0 RES 5,(IY+1)
HDENKEY CALL HDECUR
HALT
BIT 5,(IY+1)
JR Z,HDENKEY
CALL HDECUROFF
LD HL,HDE0
PUSH HL
LD HL,(CURadr)
LD A,(0X5C08)
CP 4
JR Z,HDEPGOK
CP 5
JR Z,HDEPGOK
CP 8
JR NZ,HDEnL
DEC L
JR HDE0OK
HDEnL CP 9
JR NZ,HDEnR
HDEyR INC L
JR HDE0OK
HDEnR CP 0X0A
JR NZ,HDEnDN
LD A,L
ADD A,8
LD L,A
JR HDE0OK
HDEnDN CP 0X0B
JR NZ,HDEnUP
LD A,L
SUB 8
LD L,A
JR HDE0OK
HDEPGOK LD A,L
XOR 0X80
LD L,A
HDE0OK LD A,(CURadr)
XOR L
RLA
LD (CURadr),HL
RET NC ;HDE0
JR PRDUMP ;,HDE0
HDEnUP CP 0X0C
JR NZ,HDEnBS
DEC L
INC H
INC H
LD A,(HL)
DEC H
DEC H
LD (HL),A
PUSH HL
CALL PRHEXLIN
POP HL
JR HDE0OK
HDEnBS CP 0XC7
JR NZ,HDEnsQ
PUSH HL
HDEsQ0 INC HL
LD A,(HL)
DEC HL
LD (HL),A
INC HL
LD A,H
SUB HIGH (secHDD)+1 ;2
JR NZ,HDEsQ0
DEC HL
LD (HL),A
POP HL
JR PRDUMP
HDEnsQ CP 0XC9
JR NZ,HDEnsW
PUSH HL
LD C,(HL)
HDEsW0 INC HL
LD A,(HL)
LD (HL),C
LD C,A
INC HL
LD A,H
DEC HL
SUB HIGH (secHDD)+1 ;2
JR NZ,HDEsW0
POP HL
PRDUMP LD HL,secHDD ;печаталка дампа
CURadr EQU $-2
LD A,L
AND 0X80
LD L,A
PRHXPG0 CALL PRHEXLIN
LD A,L
ADD A,A
JR NZ,PRHXPG0
RET
HDEnsW CP "l" ;load
POP DE ;сняли адрес HDE0
JP Z,HDELOAD
CP 0X0D
JR NZ,HDEnSAV
CALL 0X1F5A
LD BC,0X106
JP NC,HDE3D13
HDEnSAV PUSH DE ;0..9A..F
CALL HDEin0F
RET C
HDE09OK LD C,(HL)
REPT 4
RLA
ENDM
XOR (HL)
AND 0XF0
XOR (HL)
LD (HL),A
PUSH BC
PUSH HL
CALL PRHEXLIN
HD0F0 XOR A
LD (inv2chr),A
RES 5,(IY+1)
HD0FKEY CALL HDECUR
HALT
BIT 5,(IY+1)
JR Z,HD0FKEY
CALL HDECUROFF
LD A,0XFF
LD (inv2chr),A
CALL 0X1F54
JR NC,HD0FBACK
LD A,(0X5C08)
CALL HDEin0F
JR C,HD0F0
POP HL
POP BC
XOR (HL)
AND 0X0F
XOR (HL)
HDEprA LD (HL),A
PUSH HL
CALL PRHEXLIN
POP HL
JP HDEyR
HD0FBACK
POP HL
POP BC
LD (HL),C
PUSH HL
CALL PRHEXLIN
POP HL
RET
HDEin0F OR 0X20
SUB "0"
RET C
CP 0X0A
CCF
RET NC ;0..9
CP 0X61-0X30 ;"a"-"0"
RET C
SUB 0X61-0X3A ;"a"-":"
CP 0X10
CCF
RET
;печаталка одной строки дампа
PRHEXLIN
LD A,L
AND 0XF8
LD L,A
AND 0X7F
RRCA
RRCA
RRCA
LD B,A
LD C,3 ;4
CALL AT
LD A,L
CALL PRHEX
INC E
PUSH HL
LD B,8
PRH0 LD A,(HL)
CALL PRHEX
INC H
INC H
LD A,(HL)
DEC H
DEC H
CP (HL)
JR Z,PRH0OK
DEC E
DEC E
CALL INV2SYM
PRH0OK INC HL
DJNZ PRH0
POP HL
INC E
LD B,8
PRH1 LD A,(HL)
CALL PR88 ;PRSYM
INC H
INC H
LD A,(HL)
DEC H
DEC H
CP (HL)
JR Z,PRH1OK
DEC E
CALL INVSYM
PRH1OK INC HL
DJNZ PRH1
RET
AT EX DE,HL ;BC->DE
LD A,C
ADD A,A
ADD A,A
ADD A,A
LD C,A
LD A,B
ADD A,A
ADD A,A
ADD A,A
CALL 0X22B0
EX DE,HL
RET
HDECUROFF
LD A,1
LD (hdecurtim),A
LD A,(hdecuron)
OR A
RET Z
JR HDECURU
HDECUR PUSH HL
LD HL,(CURadr)
LD A,(HL)
INC H
INC H
CP (HL)
LD A,0X20
JR Z,$+3
ADD A,A
LD (hdetimadd),A
POP HL
LD A,1
hdecurtim EQU $-1
SUB 0X20
hdetimadd EQU $-1
LD (hdecurtim),A
RET NC
LD A,0 ;0XFF=printed
hdecuron EQU $-1
HDECURU CPL
LD (hdecuron),A
LD A,(CURadr) ;low byte of addr
LD C,A
RRA
RRA
RRA
AND 0X0F ;31
LD B,A
LD A,C
AND 7
ADD A,A
ADD A,6 ;8
LD C,A
CALL AT
LD A,0XFF ;0XFF=2chr
inv2chr EQU $-1
OR A
JR NZ,INV2SYM
INC E
JR INVSYM
INV2SYM CALL INVSYM
INVSYM
INV86 PUSH BC
PUSH DE
LD B,4 ;3
IN860 LD A,(DE)
CPL
LD (DE),A
INC D
LD A,(DE)
CPL
LD (DE),A
INC D
DJNZ IN860
POP DE
POP BC
INC E
RET
;для доктора
INH PUSH BC
PUSH DE
LD D,0X58
LD A,0XB0
LD (DE),A
RES 5,(IY+1)
INH0 BIT 5,(IY+1)
JR Z,INH0
LD A,7
LD (DE),A
POP DE
POP BC
LD A,(0X5C08)
CALL HDEin0F
RET C
PUSH AF
LD A,(0X5C08)
CALL PR88 ;PRSYM
POP AF
RET
HELPCLS LD DE,0X4001
LD BC,0X1800
LD H,D
LD L,C
LD (HL),L
LDIR
LD (HL),7
LD BC,0X02FF
LDIR
RET
TTSTKEY DB "1234567890"
DUPL 22," "
DB "QWERTYUIOP"
DUPL 22," "
DB "ASDFGHJKLe"
DUPL 22," "
DB "cZXCVBNMs",0
TNORM DB " ",0
TZERO EQU $-1
TSEC DB "sec",0
TSECAL DB "sec alarm",0
TMIN DB "min",0
TMINAL DB "min alarm",0
THR DB "hour",0
THRAL DB "hour alarm",0
TDAYOFW DB "[day of week]",0
TDAY DB "day",0
TMONTH DB "month",0
TYEAR DB "year",0
T20 DB "#20",0
TBIN DB "b2=noBCD,b1=24hour,b0=season",0
TINT DB "[int bits]",0
TBATT DB "[b7=battery low]",0
TMEM DB "mem mode (b7=slow)",0
TDRV DB "drv (b7=off)",0
TAA DB "#AA",0
T_G DB "#47=msg in following mem",0
TCMOSMSGS
DW TSEC
DW TSECAL
DW TMIN
DW TMINAL
DW THR
DW THRAL
DW TDAYOFW
DW TDAY
DW TMONTH
DW TYEAR
DW T20
DW TBIN
DW TINT
DW TBATT
DW TMEM
DW TZERO
DW TDRV
DW TAA
DW T_G
THELP ;12345678901234567890123456789012
DB "Key+RESET: Space=TRDOS "
DB " CS=Basic128 SS=Basic48 "
; DB " CS+SS=Basic128 Space=TRDOS "
DB "D=Grass!512b(PSB^Halloween CC04)"
DB " C=ColorTable+border keys+COVOX "
DB " S=CMOS SetUp "
DB " "
DB " In Gluk main menu: 1-4=drive, "
DB " M=memory mode, W=on/off turbo "
DB "Y=Virtual drive, V=TR-DOS drive "
DB " 8=on/off mouse, 9=on/off time "
DB " & uppercased option keys. "
DB 0
include "sysvar.a80"