\ 1861paint

decimal
variable (vscreen)

128 128 bitmap draw-vscreen
here (vscreen) !
128 128 *  8 /  allot
: vscreen  ( -- addr )    (vscreen) @ ;

 \ word offset into vscreen
variable woffset

hex

align
create bittable 0200 allot

: (stretch-bits)  ( byte -- word )
    >r    0000
    r@ 01 and    if  0003 or  then
    r@ 02 and    if  000C or  then
    r@ 04 and    if  0030 or  then
    r@ 08 and    if  00C0 or  then
    r@ 10 and    if  0300 or  then
    r@ 20 and    if  0C00 or  then
    r@ 40 and    if  3000 or  then
    r> 80 and    if  C000 or  then ;

: fill-bittable  ( -- )
    0100 0 do
        i (stretch-bits)
       FFFF xor                  \ light on dark
        i 2* bittable +  !
    loop ;

fill-bittable

: stretch-bits  ( byte -- word )
    2* bittable +  @ ;
inline

variable difference
: 1861-dma  ( byte -- )
    stretch-bits  dup              ( w )
    woffset @  vscreen +     ( w w adr )
    dup  @                        ( w w adr oldw )
    rot = if                        ( w adr )
        2drop
    else
        !
        true difference !
    then 
    2 woffset +!  ;  

decimal

: paint-frame  ( -- )
        4 4 draw-vscreen ;   inline

: paint-if-changed  ( -- )
    difference @ if
        paint-frame
        false difference !
    then ;   inline

