;; This example shows how to scroll the screen vertically using 
;; the CPC+.
;; This example is designed for CPC+ only and will
;; not work on CPC or KC Compact.
;;;; This example will compile with the MAXAM assembler
;; or the built-in assembler of WinAPE32.

;; NOTE - For this example to work, the code must not
;; be in the range &4000-&7fff inclusive. The ASIC registers
;; are paged into this range, and the code would not be
;; visible to the CPU if it was also in this range.
org &8000

ld hl,&4000
ld b,200
ld c,8
xor a
push af
push bc
push hl
ld e,l
ld d,h
inc de
ld (hl),a
ld bc,79
pop hl
pop bc
ld a,h
add a,8
ld h,a
dec c
jr nz,lp2
ld c,8
ld a,l
add a,80
ld l,a
ld a,h
adc a,&c0
ld h,a
pop af
inc a
djnz lp

;; STEP 1 - Unlock CPC+ additional features
;; unlock asic to gain access to asic registers

ld b,&bc
ld hl,sequence
ld e,17
ld a,(hl)
out (c),a
inc hl
dec e
jr nz,seq

ld bc,&bc0c
out (c),c
ld bc,&bd30
out (c),c
ld bc,&bc0d
out (c),c
ld bc,&bd00
out (c),c

ld bc,&7fb8
out (c),c
ld hl,&1000
ld a,h
ld (&6802),a
ld a,l
ld (&6803),a

ld b,&f5
in a,(c)
jr nc,ml1

;; no scroll
ld a,0
ld (&6804),a

ld a,100
ld (&6800),a
ld (&6801),a

ld a,(scrl_val)
inc a
and 7
ld (scrl_val),a
add a,a
add a,a
add a,a
add a,a
ld (scrl+1),a
.scrl ld a,0
ld (&6804),a
xor a
ld (&6800),a
ld (&6801),a
jp ml

.scrl_val defb 0

;; this is the sequence to unlock the ASIC extra features
defb &ff,&00,&ff,&77,&b3,&51,&a8,&d4,&62,&39,&9c,&46,&2b,&15,&8a,&cd,&ee