org &2000
nolist
scr_set_mode equ &bc0e
txt_output equ &bb5a
scr_next_line equ &bc26
start:
ld a,2
call scr_set_mode
ld bc,24*80
ld d,' '
l2:
inc d
ld a,d
cp &7f
jr nz,no_char_reset
ld d,' '
no_char_reset:
ld a,d
call txt_output
dec bc
ld a,b
or c
jr nz,l2
ld hl,&c000
ld b,200
shiftedl:
push bc
push hl
ld e,l
ld d,h
ld a,d
and &3f
or &40
ld d,a
inc hl
ld bc,&80-1
ldir
pop hl
call scr_next_line
pop bc
djnz shiftedl
di
im 1
ld a,&c3
ld hl,int_handler1
ld (&0038),a
ld (&0039),hl
ld bc,&bc07
out (c),c
ld bc,&bd00+7
out (c),c
call vsync_sync
ld bc,&bc04
out (c),c
ld bc,&bd00+14-1-1
out (c),c
ei
loop1:
ld b,&f5
l1:
in a,(c)
rra
jr nc,l1
ld c,1
call scroll_up
call scroll_right
ld hl,(scrl2)
ld a,(scroll_adjustment)
or a
ld c,&30
jr z,loop2a
ld c,&18
loop2a:
ld a,h
and &3
or c
ld h,a
ld (scrl2),hl
ld a,1
ld (fetch_values),a
loop5:
loop2:
halt
halt
halt
jp loop1
scroll_adjustment:
defb 0
scroll_right:
ld a,(scroll_adjustment)
xor 1
ld (scroll_adjustment),a
cp 1
ret z
ld hl,(scrl2)
inc hl
ld a,h
and &3
ld h,a
ld (scrl2),hl
ret
scroll_left:
ld a,(scroll_adjustment)
xor 1
ld (scroll_adjustment),a
or a
ret z
ld hl,(scrl2)
dec hl
ld a,h
and &3
ld h,a
ld (scrl2),hl
ret
scroll_up:
ld a,(vscrl_line2)
add a,c
cp 8
jr c,scroll_up2
and &7
ld (vscrl_line2),a
ld hl,(scrl2)
ld bc,40
add hl,bc
ld a,h
and &3
ld h,a
ld (scrl2),hl
ret
scroll_up2:
and &7
ld (vscrl_line2),a
ret
scroll_down:
ld a,(vscrl_line2)
dec a
and &7
ld (vscrl_line2),a
or a
jr nz,loop2
ld hl,(scrl2)
or a
ld bc,40
sbc hl,bc
ld a,h
and &3
ld h,a
ld (scrl2),hl
ret
vsync_sync:
ld b,&f5
vs1:
in a,(c)
rra
jr nc,vs1
vs2:
in a,(c)
rra
jr c,vs2
ret
int_handler1:
push bc
push hl
push af
ld bc,&bc07
out (c),c
ld bc,&bdff
out (c),c
ld bc,&bc05
out (c),c
inc b
ld a,(vscrl_line)
neg
add a,8
out (c),a
ld hl,int_handler2
ld (&0039),hl
pop af
pop hl
pop bc
ei
ret
int_handler2:
push hl
ld bc,&bc0c
out (c),c
ld hl,(scrl)
inc b
out (c),h
ld bc,&bc0d
out (c),c
inc b
out (c),l
ld bc,&bc01
out (c),c
ld bc,&bd00+40
out (c),c
ld hl,int_handler3
ld (&0039),hl
pop hl
ei
ret
int_handler3:
push bc
push hl
push af
ld bc,&bc04
out (c),c
ld bc,&bd00+25-1
out (c),c
ld bc,&bc05
out (c),c
inc b
ld a,(vscrl_line)
out (c),a
ld hl,int_handler4
ld (&0039),hl
pop af
pop hl
pop bc
ei
ret
int_handler4:
push hl
ld hl,int_handler5
ld (&0039),hl
pop hl
ei
ret
int_handler5:
push hl
ld hl,int_handler6
ld (&0039),hl
pop hl
ei
ret
int_handler6:
push bc
push hl
push af
ld bc,&bc01
out (c),c
ld bc,&bd00
out (c),c
ld bc,&bc04
out (c),c
ld bc,&bd00+14-1-1
out (c),c
ld bc,&bc07
out (c),c
ld bc,&bd00+7
out (c),c
ld hl,int_handler1
ld (&0039),hl
ld a,(fetch_values)
or a
jr z,int_handler1a
ld a,(vscrl_line2)
ld (vscrl_line),a
ld hl,(scrl2)
ld (scrl),hl
xor a
ld (fetch_values),a
int_handler1a:
pop af
pop hl
pop bc
ei
ret
fetch_values:
defb 0
hsync:
defb 0
hsync2:
defb &85
scrl2:
defw 0
vscrl_line2:
defb 0
vscrl_line:
defb 0
scrl:
defw 0
end