;; This example shows a suggested startup for a cartridge

;; cartridge page 0 exists at &0000-&3fff
;; execution starts at &0000
;;
org &0000

start:

di					;; disable interrupts
im 1					;; set interrupt mode 1
ld bc,&f782			;; setup initial PPI port directions
out (c),c
ld bc,&f400			;; set initial PPI port A (AY)
out (c),c
ld bc,&f600			;; set initial PPI port C (AY direction)
out (c),c

ld bc,&7fc0			;; set initial RAM configuration
out (c),c

;; unlock ASIC so we can access ASIC registers
ld b,&bc
ld hl,sequence
ld e,17
seq:
ld a,(hl)
out (c),a
inc hl
dec e
jr nz,seq

;; set initial CRTC settings (screen dimensions etc)
ld hl,end_crtc_data
ld bc,&bc0f
crtc_loop:
out (c),c
dec hl
ld a,(hl)
inc b
out (c),a
dec b
dec c
jp p,crtc_loop

ld hl,&c9fb
ld (&0038),hl
ei

;; enable asic ram (will be visible in range &4000-&7fff)
ld bc,&7fb8
out (c),c

;; your code here
loop:
jr loop

;; your crtc setup values here; these are examples
crtc_data:
defb &3f, &28, &2e, &8e, &26, &00, &19, &1e, &00, &07, &00,&00,&30,&00,&c0,&00
end_crtc_data:

;; sequence to unlock asic
sequence:
defb &ff,&00,&ff,&77,&b3,&51,&a8,&d4,&62,&39,&9c,&46,&2b,&15,&8a,&cd,&ee

end start
