        ;ld hl,65535
        ;ld de,0x4010
        ;call prnum
        
calcscraddr
;de=#4000 + (y&#18)+((y*32)&#ff+x)
        ld a,b ;y
        and 0x18
        add a,0x40
        ld d,a
        ld a,b ;y
        rrca
        rrca
        rrca
        and 0xe0
        add a,c ;x
        ld e,a
        ret 
        
getkey
        halt
        bit 5,(iy+1)
        jr z,getkey
        res 5,(iy+1)
        ld a,(23560)
        ret

copyscrline
;hl -> de
        ld bc,#04ff
copyscrline0
        dup 31
        ldi
        edup
        ld a,(hl)
        ld (de),a
        inc h
        inc d
        dup 31
        ldd
        edup
        ld a,(hl)
        ld (de),a
        inc h
        inc d
        dec b
        jp nz,copyscrline0
        ret

scrollup
        ld de,#4000
        ld b,scrhgt-1
scrollup0
        push bc
        ld h,d
        ld l,e
        call nextlinede
        ex de,hl ;hl=next line
        push hl
        call copyscrline
        pop de
        pop bc
        djnz scrollup0
        ret
        
scrolldown
        ld de,#50e0
        ld b,scrhgt-1
scrolldown0
        push bc
        ld h,d
        ld l,e
        call prevlinede
        ex de,hl ;hl=next line
        push hl
        call copyscrline
        pop de
        pop bc
        djnz scrolldown0
        ret
        
cls
	ld hl,#4000
	ld de,#4001
        ld bc,#17ff
        ld (hl),0;#ff
        ldir
	ld hl,#5800
	ld de,#5801
	ld (hl),emptyattr
	ld bc,767
	ldir
        ret

nextlinede
        ld a,e
        add a,32
        ld e,a
        ret nc
        ld a,d
        add a,8
        ld d,a
        ret
        
prevlinede
        ld a,e
        sub 32
        ld e,a
        ret nc
        ld a,d
        sub 8
        ld d,a
        ret

prnum
        ld bc,-10000
        call prdig
        ld bc,-1000
        call prdig
        ld bc,-100
        call prdig
        ld c,-10
        call prdig
        ld c,-1
prdig
        ld a,'0'-1
prdig0
        inc a
        add hl,bc
        jr c,prdig0
        sbc hl,bc
        ;jp prchar
prchar
;a=code
;de=screen
        push de
        push hl
        ld l,a
        ld h,font/256
        dup 7
        ld a,(hl) ;font
        ld (de),a ;scr
        inc h
        inc d ;+256
        edup
        ld a,(hl) ;font
        ld (de),a ;scr
        pop hl
        pop de
        inc e
        ret
