cube_init
        ld hl,wastexture
        ld de,texture
        ld c,64;chmhgt
clearchm0
        push de
        ld b,64;chmwid
clearchm1
        ld a,(de);(hl)
        and #1f
        add a,a
        add a,#c0
        ld (de),a
        inc hl
        inc e
        djnz clearchm1
        pop de
        inc d
        dec c
        jr nz,clearchm0

        ;call GENLOG2
        ;ret

;GEN TABLE Y.W=LOG2(-L) ,L=(-1,-255)
GENLOG2
        LD HL,TBLOG2
        XOR A
        LD E,A
	ld D,A
        LD (HL),A
        INC H
        LD (HL),#F0
        DEC H
        dec l;INC L
GNLG1   LD (HL),D
        INC H
        LD (HL),A
        DEC H
        EXA 
        PUSH HL,DE
        LD DE,#7440
        xor a:sub l:ld c,a;LD C,L
        SRL C
        RR D
        XOR A
        LD HL,#B8AA
        EXX 
        LD H,A
	ld L,A
        LD B,#10
GNLG2   EXX 
        ADD HL,HL
        ADC A,A
        SBC HL,DE
        SBC A,C
        JR NC,GNLG3
        ADD HL,DE
        ADC A,C
GNLG3   EXX 
        CCF 
        adc hl,hl
        ;rl l
        ;rl h
        DJNZ GNLG2
        POP DE
        EXA 
        ADD HL,DE
        ADC A,B
        EX DE,HL
        POP HL
        dec l;INC L
        JR NZ,GNLG1
        ;RET 

;GEN TABLE Y.B=2^(X/256)-1 ,X=(0;1)
GEN2X
        LD IX,TB2X
        LD HL,0
GN2X    LD A,H;ROUNDING
        BIT 7,L
        JR Z,$+3
        INC A
        LD (IX),A
        XOR A
        EXX 
        LD L,A
	ld H,A
	ld E,A
        LD BC,#00B2;(2^1/256)*#10000
        EXX 
        LD BC,#1801
GN2X1   RR C
	rr H
	rr L
        EXX 
        JR NC,GN2X2
        ADD HL,BC
        ADC A,1
GN2X2   RRA 
        RR H
	rr L
        EXX 
        DJNZ GN2X1
        LD A,C
        RRA 
        EXX 
        LD H,L
	ld L,A
        INC LX
        JR NZ,GN2X
        RET 
