;CLS

func_cls:

LD A,($FCAF)
CP 5
JP C,func_cls_3
LD A,(6)
LD C,A
INC C
CALL func_cls_5 ;$6FC3
INC C
INC C
XOR A
OUT (C),A
OUT (C),A
OUT (C),A
LD A,($FAF6)
OUT (C),A
XOR A
OUT (C),A
LD A,($FCAF)
RRCA
AND 1
INC A
OUT (C),A
LD A,($F7C0)
AND A
JR NZ,func_cls_1
OUT (C),A
INC A
JR func_cls_2

func_cls_1:
LD A,$D4
OUT (C),A
XOR A
func_cls_2:
OUT (C),A
LD A,($F3EA)
CALL func_cls_8 ;$6CFF
OUT (C),H
XOR A
OUT (C),A
LD A,$C0
OUT (C),A
RET

func_cls_3:
XOR A
LD IX,$C3
JP func_cls_4

func_cls_4:
CALL $159
EI
RET

func_cls_5:
LD A,$24
DI
OUT (C),A
LD A,$91
EI
OUT (C),A

func_cls_6:
LD A,2
DI
CALL func_cls_7
IN A,(C)
PUSH AF
XOR A
CALL func_cls_7
EI
POP AF
RRA
JR C,func_cls_6
RET

func_cls_7:
OUT (C),A
LD A,$8F
OUT (C),A
RET

func_cls_8:
LD H,A
LD A,($FCAF)
CP 8
RET Z
CP 7
JR Z,func_cls_9
CP 5
JR Z,func_cls_9
LD A,H
ADD A,A
ADD A,A
OR H
LD H,A

func_cls_9:
LD A,H
ADD A,A
ADD A,A
ADD A,A
ADD A,A
OR H
LD H,A
RET

