//-------------------------------------------------------
//
//                     KOALALIB
//
//           Library that shows koala pictures
//
// Author: Mattias Hansson
// License: GPL2
// Compiler version: c65cm, v.04+
// ZP usage: $9e-$9f, $fb-$ff
//
//-------------------------------------------------------

#IFNDEF __LIB_KOALA
#DEFINE __LIB_KOALA = 1

#INCLUDE <c64scr.c65>
#INCLUDE <c64defs.c65>

GOTO lib_koala_skip

WORD lib_koala_skpicptr @ $fc

//-------------------------------------------------------
//
//-------------------------------------------------------
FUNC lib_koala_show ( io:lib_koala_skpicptr )

  // Koala format description (excluding CBM loading address)
  // Bitmap:   $0000-$1f3f (0-7999)
  // Videoram: $1f40-$2327 (8000-8999)
  // Colorram: $2328-$270f (9000-9999)
  // Background: $2710     (10000)

  WORD lib_koala_skpoke @ $9e
  BYTE lib_koala_sktemp @ $fb

  GOSUB lib_c64scr_blank

  //-----------------------------------------
  // Copy picture data to the right locations
  //-----------------------------------------

  LET lib_koala_skpoke = $e000
  WHILE lib_koala_skpoke < $e000+8000
    PEEK lib_koala_skpicptr -> lib_koala_sktemp
    POKE lib_koala_skpoke , lib_koala_sktemp
    INC lib_koala_skpicptr
    INC lib_koala_skpoke
  WEND

  LET lib_koala_skpoke = $c000
  WHILE lib_koala_skpoke < $c000+1000
    PEEK lib_koala_skpicptr -> lib_koala_sktemp
    POKE lib_koala_skpoke , lib_koala_sktemp
    INC lib_koala_skpicptr
    INC lib_koala_skpoke
  WEND

  LET lib_koala_skpoke = colorram
  WHILE lib_koala_skpoke < colorram+1000
    PEEK lib_koala_skpicptr -> lib_koala_sktemp
    POKE lib_koala_skpoke , lib_koala_sktemp
    INC lib_koala_skpicptr
    INC lib_koala_skpoke
  WEND

  //background color (one of the colors in MCB mode)
  PEEK lib_koala_skpicptr -> lib_koala_sktemp
  POKE vic2+$21 , lib_koala_sktemp

  //----------------------------
  // Setup VIC2 to show picture
  //----------------------------

  //Setup bank 4 ($c000-$ffff) for VIC-II (bits 0 and 1 negated)
  PEEK cia2 -> lib_koala_sktemp
  AND lib_koala_sktemp WITH $fc -> lib_koala_sktemp
  POKE cia2 , lib_koala_sktemp

  //Setup bitmap @ $e000 and videoram @ $c000
  PEEK vic2+$18 -> lib_koala_sktemp
  AND lib_koala_sktemp WITH 7 -> lib_koala_sktemp
  OR lib_koala_sktemp WITH 8 -> lib_koala_sktemp
  POKE vic2+$18 , lib_koala_sktemp

  //Setup multicolor graphics
  PEEK vic2+$11 -> lib_koala_sktemp
  OR lib_koala_sktemp WITH 32 -> lib_koala_sktemp
  POKE vic2+$11 , lib_koala_sktemp
  PEEK vic2+$16 -> lib_koala_sktemp
  OR lib_koala_sktemp WITH 16 -> lib_koala_sktemp
  POKE vic2+$16 , lib_koala_sktemp

  GOSUB lib_c64scr_show

FEND

LABEL lib_koala_skip

#IFEND
