; PCE definitions. By Groepaz/Hitmem.
 ;
 
-; FIXME: optimize zeropage usage
-CURS_X          = $30
-CURS_Y          = $31
-SCREEN_PTR      = $32           ;2
-CHARCOLOR       = $34
-RVS             = $35
-BGCOLOR         = $36
-tickcount       = $37           ;4
-
 ; FIXME: screen dimensions my change according to selected video mode
 screenrows      = (224/8)
 charsperline    = 61
 
 
 MEMORY {
         # FIXME: is this correct? the first 3? bytes cant be used?
-        ZP:  start = $03, size = $1A, type = rw, define = yes;
+        ZP: start = $03, size = $fd, type = rw, define = yes;
 
         # reset-bank and hardware vectors
         ROM0: start = $e000, size = $1ff6, file = %O ,fill = yes, define = yes;
         BSS:     load = RAM, type = bss, define = yes;
         VECTORS: load = ROMV, type = rw, define = yes;
         ZEROPAGE: load = ZP, type = zp, define = yes;
+        EXTZP: load = ZP, type = zp, define = yes, optional = yes;
+        APPZP: load = ZP, type = zp, define = yes, optional = yes;
 }
 
 FEATURES {
 
 
         .include        "pce.inc"
+        .include        "extzp.inc"
 
+        .import PLOT
         .export _clrscr
 _clrscr:
 
         dey
         bne     rowloop
 
-        rts
+; Go to the home position.
+
+        stz     CURS_X
+        stz     CURS_Y
+        jmp     PLOT
 
 ;-------------------------------------------------------------------------------
 ; force the init constructor to be imported
 
 
         .export     _textcolor, _bgcolor, _bordercolor
 
-        .include    "pce.inc"
+        .include        "pce.inc"
+        .include        "extzp.inc"
 
 _textcolor:
         ldx     CHARCOLOR       ; get old value
 
 _bordercolor:
         lda     #0
-        txa
+        tax
         rts
 
+        .rodata
         .export colors
 
 colors:
 
         .import         __BSS_SIZE__
 
         .include        "pce.inc"
+        .include        "extzp.inc"
 
         .importzp       sp
         .importzp       ptr1,ptr2
         tii     $2000, $2001, $1FFF
 
         ; Initialize hardware
-        stz     TIMER_COUNT     ; Timer off
+        stz     TIMER_CTRL      ; Timer off
         lda     #$07
         sta     IRQ_MASK        ; Interrupts off
         stz     IRQ_STATUS      ; Acknowledge timer
 
--- /dev/null
+;
+; extzp.inc for the PC-Engine
+;
+; Groepaz/Hitmen, 2015-11-19
+;
+; Assembler include file that imports the runtime zero page locations used
+; by the PC-Engine runtime, ready for usage in asm code.
+;
+
+
+        .global         CURS_X: zp
+        .global         CURS_Y: zp
+        .global         SCREEN_PTR: zp
+        .global         CHARCOLOR: zp
+        .global         RVS: zp
+        .global         BGCOLOR: zp
+        .global         tickcount: zp
 
--- /dev/null
+;
+; Groepaz/Hitmen, 2015-11-19
+;
+; zeropage locations for exclusive use by the library
+;
+
+        .include "extzp.inc"
+
+        .segment "EXTZP" : zeropage
+
+CURS_X:         .res 1
+CURS_Y:         .res 1
+SCREEN_PTR:     .res 2
+CHARCOLOR:      .res 1
+RVS:            .res 1
+BGCOLOR:        .res 1
+tickcount:      .res 4