;; Test scrolling mid-line up, down, left and right

org &8000
nolist
;;write direct "plusscrl.bin"
;;run start

scr_set_mode equ &bc0e
txt_output equ &bb5a

start:



;; initialise a display window of 48x35 characters
;; each character is 8 scanlines tall

;; set character height to 8 scanlines
ld bc,&bc09
out (c),c
ld bc,&bd00+7
out (c),c

;; set default horizontal total (set horizontal total to 64 CRTC characters
;; = 64 microseconds)
ld bc,&bc00
out (c),c
ld bc,&bd00+&3f
out (c),c

;; set default vertical total (set vertical total to 39 CRTC character-lines)
ld bc,&bc04
out (c),c
ld bc,&bd00+38
out (c),c

;; setup default horizontal and vertical sync widths
;; this is compatible with CRTC type 2 based on the width
;; and hsync position defined in this example
ld bc,&bc03
out (c),c
ld bc,&bd00+&89
out (c),c

;; setup default vertical adjust
ld bc,&bc05
out (c),c
ld bc,&bd00
out (c),c

;; setup default interlace & skew
ld bc,&bc08
out (c),c
ld bc,&bd00
out (c),c

;; set width of display window
;; this value is compatible with crtc type 2
ld bc,&bc01
out (c),c
ld bc,&bd00+48
out (c),c

;; set horizontal sync position; and therefore the
;; horizontal position of the display window
;; within the monitor display
;;
;; this value is compatible with crtc type 2
ld bc,&bc02
out (c),c
ld bc,&bd00+48
out (c),c

;; set height of display window
ld bc,&bc06
out (c),c
ld bc,&bd00+35
out (c),c

;; set vertical sync position; and therefore the
;; vertical position of the display window
;; within the monitor display
ld bc,&bc07
out (c),c
ld bc,&bd00+35
out (c),c

;; set display start
;; force MA11=MA10=1, so that the internal MA
;; counter will increment enough to change MA12.

;; the displayed data is &0000-&7fff
ld bc,&bc0c
out (c),c
ld bc,&bd00+&0c
out (c),c
ld bc,&bc0d
out (c),c
ld bc,&bd00+0
out (c),c

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

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

ld bc,&7fb8
out (c),c

ld a,8
ld (&6800),a

mainloop:

;; scroll down
ld a,(vscroll1)
add a,16
and %01110000
ld (vscroll1),a

;; scroll up
ld a,(vscroll2)
sub 16
and %01110000
ld (vscroll2),a

;; scroll right
ld a,(hscroll1)
inc a
and %1111
ld (hscroll1),a

;; scroll left
ld a,(hscroll2)
dec a
and %1111
ld (hscroll2),a

;; scroll down
ld a,(vscroll3)
add a,16
and %01110000
or %10000000
ld (vscroll3),a

;; scroll up
ld a,(vscroll4)
sub 16
and %01110000
or %10000000
ld (vscroll4),a

;; scroll right
ld a,(hscroll3)
inc a
and %1111
or %10000000
ld (hscroll3),a

;; scroll left
ld a,(hscroll4)
dec a
and %1111
or %10000000
ld (hscroll4),a

halt

ld hl,&6804			;; [3]
ld de,(vscroll)		;; [6]

call set_scroll

ld a,58
ld (&6800),a

halt

ld hl,&6804			;; [3]
ld de,(vscrollb)		;; [6]

call set_scroll

ld a,106
ld (&6800),a

halt

ld hl,&6804
ld de,(hscroll)

call set_scroll

ld a,154
ld (&6800),a

halt

ld hl,&6804
ld de,(hscrollb)

call set_scroll

ld a,8
ld (&6800),a

jp mainloop

set_scroll:
;; 5 here
xor a				;; [1]
defs 54

;; no scroll initially
ld (hl),a			;; [2]

ld c,32				;; [2]
set_scroll2:
defs 4
ld (hl),D			;; [2]
defs 8
;; middle non-scrolling section
ld (hl),a			;; [2]
defs 6
ld (hl),e			;; [2]
defs 8
ld (hl),a			;; [2]
defs 26	
dec c				;; [1]
jp nz,set_scroll2	;; [3]	

;; and end with no scroll
ld (hl),a
ret


vscroll:
vscroll1:
defb 0
vscroll2:
defb 0

vscrollb:
vscroll3:
defb 0
vscroll4:
defb 0

hscroll:
hscroll1:
defb 0
hscroll2:
defb 0

hscrollb:
hscroll3:
defb 0
hscroll4:
defb 0

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

;;end start