;LINE - LINE B - LINE BF - COPY

;LINE
func_line:

jp func_line_b_7

;LINE B

func_line_b:

PUSH AF
LD A,($FCAF)
CP 5
JP C,func_line_b_6 ;$7359
POP AF
PUSH HL
PUSH IX
POP HL
AND A
PUSH HL
SBC HL,DE
POP HL
JR NC,func_line_b_1
EX DE,HL
AND A

func_line_b_1:
EX (SP),HL
PUSH DE
PUSH IY
POP DE
PUSH HL
SBC HL,DE
POP HL
JR C,func_line_b_2
EX DE,HL

func_line_b_2:
PUSH DE
POP IY
POP DE
POP IX
PUSH IY
PUSH HL
POP IY
DEC IX
CALL func_line_b_7 ;$6D6D
INC IX
POP HL
DEC HL
PUSH IY
PUSH DE
PUSH IX
POP DE
CALL func_line_b_7 ;$6D6D
INC HL
POP IX
INC IX
PUSH HL
POP IY
CALL func_line_b_7 ;$6D6D
DEC IX
POP HL
INC HL
PUSH IX
POP DE

func_line_b_7:
PUSH AF
LD A,($FCAF)
CP 5
JP C,func_line_b_8 ;$7354
CALL func_line_b_11 ;$7320
CALL func_line_b_10 ;$7307
POP AF
PUSH DE
PUSH HL
PUSH IX
PUSH IY
PUSH AF
PUSH AF
PUSH HL
LD A,(6)
LD C,A
INC C
CALL func_line_b_16 ;$6FC3
INC C
INC C
PUSH IX
POP HL
OUT (C),L
OUT (C),H
PUSH IY
POP HL
OUT (C),L
LD A,($FAF6)
OR H
OUT (C),A
LD A,$C
PUSH IX
POP HL
SBC HL,DE
JR NC,func_line_b_3
EX DE,HL
LD HL,1
SBC HL,DE
AND $FB

func_line_b_3:
PUSH HL
POP IX
POP DE
PUSH IY
POP HL
SBC HL,DE
JR NC,func_line_b_4
EX DE,HL
LD HL,1
SBC HL,DE
AND $F7

func_line_b_4:
PUSH IX
POP DE
PUSH HL
SBC HL,DE
POP HL
JR C,func_line_b_5
EX DE,HL
OR 1

func_line_b_5:
OUT (C),E
OUT (C),D
OUT (C),L
OUT (C),H
LD E,A
POP AF
OUT (C),A
OUT (C),E
LD A,B
OR $70
OUT (C),A
POP AF
POP IY
POP IX
POP HL
POP DE
RET

func_line_bf_10:
LD BC,$58C1
jr func_line_b_9


func_line_b_8:
LD BC,$58FC
JR func_line_b_9

func_line_b_6:
LD BC,$5912

func_line_b_9:
POP AF
LD ($F3F2),A
PUSH BC
LD ($FCB3),DE
LD ($FCB5),HL
PUSH IX
POP BC
PUSH IY
POP DE
POP IX
CALL $159
EI
RET

func_line_b_10:
LD A,($F7C0)
AND A
RET Z
PUSH HL
PUSH DE
PUSH IX
POP DE
PUSH IY
POP HL
CALL func_line_b_11 ;$7320
PUSH HL
POP IY
PUSH DE
POP IX
POP DE
POP HL
RET

func_line_b_11:
LD A,($F7C0)
AND A
RET Z
LD A,D
ADD A,A
JR NC,func_line_b_12
LD DE,0
JR func_line_b_13

func_line_b_12:
LD A,($FCAF)
RRCA
AND 1
CP D
JR NC,func_line_b_13:
LD E,$FF
LD D,A

func_line_b_13:
LD A,H
ADD A,A
JR NC,func_line_b_14
LD HL,0
RET

func_line_b_14:
JR NZ,func_line_b_15
LD A,L
CP $D4
RET C

func_line_b_15:
LD HL,$D3
RET

func_line_b_16:
LD A,$24

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

func_line_b_18:
LD A,2
DI
CALL func_line_b_17 ;$6FE0
IN A,(C)
PUSH AF
XOR A
CALL func_line_b_17 ;$6FE0
EI
POP AF
RRA
JR C,func_line_b_18 ;06FCDH
RET

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



;LINE BF

func_line_bf:
PUSH AF
LD A,($FCAF)
CP 5
JP C,func_line_bf_10 ;$735E
CALL func_line_b_11 ;$7320
CALL func_line_b_10 ;$7307
POP AF
PUSH AF
PUSH HL
PUSH IX
POP HL
AND A
PUSH HL
SBC HL,DE
POP HL
JR NC,func_line_bf_1 ;06E0BH
EX DE,HL
AND A

func_line_bf_1:
EX (SP),HL
PUSH DE
PUSH IY
POP DE
PUSH HL
SBC HL,DE
POP HL
JR C,func_line_bf_2 ;06E17H
EX DE,HL

func_line_bf_2:
PUSH DE
POP IY
POP DE
POP IX
LD A,(6)
LD C,A
INC C
CALL func_line_b_16 ;$6FC3
INC C
INC C
OUT (C),E
OUT (C),D
OUT (C),L
LD A,($FAF6)
OR H
OUT (C),A
PUSH HL
PUSH IX
POP HL
AND A
SBC HL,DE
INC HL
OUT (C),L
OUT (C),H
LD A,L
OR E
PUSH IY
POP HL
POP DE
SBC HL,DE
INC HL
OUT (C),L
OUT (C),H
LD E,A
POP HL
INC B
DJNZ func_line_bf_3 ;06E6BH
LD A,($FCAF)
CP 8
JR Z,func_line_bf_4; 06E82H
CP 7
JR Z,func_line_bf_5 ;06E60H
CP 6
JR Z,func_line_bf_6 ;06E66H

func_line_bf_5:
LD A,E
RRCA
JR NC,func_line_bf_7 ;06E7BH
JR func_line_bf_3 ;06E6BH

func_line_bf_6:
LD A,E
AND 3
JR Z,func_line_bf_3b ;06E76H

func_line_bf_3:
OUT (C),H
XOR A
OUT (C),A
LD A,B
OR $80
OUT (C),A
RET

func_line_bf_3b:
LD A,H
ADD A,A
ADD A,A
OR H
LD H,A

func_line_bf_7:
LD A,H
ADD A,A
ADD A,A
ADD A,A
ADD A,A
OR H
LD H,A

func_line_bf_4:
OUT (C),H
XOR A
OUT (C),A
LD A,$C0
OUT (C),A
RET


;COPY VRAM

func_copyvram:
CALL func_line_b_11 ;$7320
CALL func_line_b_10 ;$7307
PUSH HL
PUSH DE
LD DE,($FCB7)
LD HL,($FCB9)
CALL func_line_b_11 ;$7320
LD ($FCB7),DE
LD ($FCB9),HL
POP DE
POP HL
PUSH DE
PUSH BC
LD A,(6)
LD C,A
INC C
LD A,$20
CALL func_copyvram_2 ;$6FC5
INC C
INC C
OUT (C),E
OUT (C),D
OUT (C),L
LD A,($FC18)
OR H
OUT (C),A
PUSH HL
LD HL,($FCB7)
OUT (C),L
OUT (C),H
LD HL,($FCB9)
OUT (C),L
LD A,($FC19)
OR H
OUT (C),A
LD B,0
LD A,($FCB7)
OR E
PUSH IX
POP HL
SBC HL,DE
JR NC,func_copyvram_3 ;06EF1H
LD A,($FCB7)
CPL
LD D,A
LD A,E
CPL
OR D
EX DE,HL
LD HL,0
SBC HL,DE
SET 2,B

func_copyvram_3:
INC HL
OUT (C),L
OUT (C),H
OR L
POP DE
PUSH IY
POP HL
SBC HL,DE
JR NC,func_copyvram_4 ;06F07H
EX DE,HL
LD HL,1
SBC HL,DE
SET 3,B

func_copyvram_4:
INC HL
OUT (C),L
OUT (C),H
OUT (C),A
OUT (C),B
LD B,A
POP HL
POP DE
LD A,H
AND A
JR NZ,func_copyvram_5 ;06F31H
LD A,($FCAF)
CP 8
JR Z,func_copyvram_6 ;06F37H
CP 7
JR Z,func_copyvram_7 ;06F26H
CP 6
JR Z,func_copyvram_8 ;06F2CH

func_copyvram_7:
LD A,B
RRCA
JR NC,func_copyvram_6 ;06F37H
JR func_copyvram_5 ;06F31H

func_copyvram_8:
LD A,B
AND 3
JR Z,func_copyvram_6 ;06F37H

func_copyvram_5:
LD A,H
OR $90
OUT (C),A
RET

func_copyvram_6:
LD A,$D0
OUT (C),A
RET

