org &8000
nolist
scr_set_mode equ &bc0e
txt_output equ &bb5a
mc_wait_flyback equ &bd19
km_test_key equ &bb1e
scr_set_ink equ &bc32
sprite_height equ 16
sprite_width_pixels equ 14
sprite_width_bytes equ sprite_width_pixels/2
start:
ld a,0
call scr_set_mode
ld d,'A'
ld b,24
l2:
ld c,20
l1:
ld a,d
call txt_output
dec c
jr nz,l1
inc d
dec b
jr nz,l2
call make_scr_table
call draw_sprite_cur_coords
main_loop:
call mc_wait_flyback
ld hl,(sprite_coords)
ld (prev_coords),hl
call do_keys
halt
call redraw_sprite
jp main_loop
redraw_sprite:
ld hl,(prev_coords)
ld bc,(sprite_coords)
or a
sbc hl,bc
ld a,h
or l
jr nz,rs1
ret
rs1:
ld hl,(prev_coords)
ld de,sprite_background
ld b,sprite_height
ld c,sprite_width_bytes
call sprite_background_restore
draw_sprite_cur_coords:
ld hl,(sprite_coords)
ld de,sprite_background
ld b,sprite_height
ld c,sprite_width_bytes
call sprite_background_store
ld hl,(sprite_coords)
call get_scr_addr
call sprite_0
ret
make_scr_table:
ld hl,&c000
ld b,200
ld ix,scr_table
mst1:
ld (ix+0),l
ld (ix+1),h
call scr_next_line
inc ix
inc ix
djnz mst1
ret
scr_table:
defs 200*2
get_scr_addr:
push bc
push de
ld d,0
ld e,h
ld h,0
add hl,hl
ld bc,scr_table
add hl,bc
ld a,(hl)
inc hl
ld h,(hl)
ld l,a
add hl,de
pop de
pop bc
ret
scr_next_line:
ld a,h
add a,8
ld h,a
ret nc
ld a,l
add a,&50
ld l,a
ld a,h
adc a,&c0
ld h,a
ret
do_keys:
ld a,0*8+0
call km_test_key
jr nz,move_up
ld a,0*8+1
call km_test_key
jr nz,move_right
ld a,0*8+2
call km_test_key
jr nz,move_down
ld a,1*8+0
call km_test_key
jr nz,move_left
ret
move_up:
ld a,(y_coord)
or a
ret z
dec a
ld (y_coord),a
ret
move_down:
ld a,(y_coord)
sub 200-sprite_height
ret nc
ld a,(y_coord)
inc a
ld (y_coord),a
ret
move_left:
ld a,(x_coord)
or a
ret z
dec a
ld (x_coord),a
ret
right_side equ (40*2)-sprite_width_bytes
move_right:
ld a,(x_coord)
sub right_side
ret nc
ld a,(x_coord)
inc a
ld (x_coord),a
ret
sprite_background_store:
call get_scr_addr
sprite_back_height:
push bc
push hl
sprite_back_width:
ld a,(hl)
ld (de),a
inc hl
inc de
dec c
jr nz,sprite_back_width
pop hl
call scr_next_line
pop bc
djnz sprite_back_height
ret
sprite_background_restore:
call get_scr_addr
sprite_reback_height:
push bc
push hl
sprite_reback_width:
ld a,(de)
ld (hl),a
inc hl
inc de
dec c
jr nz,sprite_reback_width
pop hl
call scr_next_line
pop bc
djnz sprite_reback_height
ret
sprite_0:
push hl
inc hl
ld a,(hl)
and &aa
ld (hl),a
inc hl
ld (hl),&cc
inc hl
ld (hl),&cc
inc hl
ld (hl),&cc
pop hl
call scr_next_line
push hl
inc hl
ld (hl),&cc
inc hl
ld (hl),&cc
inc hl
ld (hl),&cc
inc hl
ld (hl),&cc
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &44
ld (hl),a
inc hl
ld (hl),&cc
inc hl
ld a,(hl)
and &55
or &88
ld (hl),a
inc hl
inc hl
inc hl
ld a,(hl)
and &aa
ld (hl),a
inc hl
ld (hl),&cc
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &44
ld (hl),a
inc hl
ld (hl),&cc
inc hl
ld a,(hl)
and &55
or &88
ld (hl),a
inc hl
inc hl
inc hl
ld a,(hl)
and &aa
ld (hl),a
inc hl
ld (hl),&cc
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &44
ld (hl),a
inc hl
ld (hl),&cc
inc hl
ld a,(hl)
and &55
or &88
ld (hl),a
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &44
ld (hl),a
inc hl
ld (hl),&cc
inc hl
ld a,(hl)
and &55
or &88
ld (hl),a
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &44
ld (hl),a
inc hl
ld (hl),&cc
inc hl
ld a,(hl)
and &55
or &88
ld (hl),a
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &44
ld (hl),a
inc hl
ld (hl),&cc
inc hl
ld a,(hl)
and &55
or &88
ld (hl),a
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &44
ld (hl),a
inc hl
ld (hl),&cc
inc hl
ld a,(hl)
and &55
or &88
ld (hl),a
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &44
ld (hl),a
inc hl
ld (hl),&cc
inc hl
ld a,(hl)
and &55
or &88
ld (hl),a
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &44
ld (hl),a
inc hl
ld (hl),&cc
inc hl
ld a,(hl)
and &55
or &88
ld (hl),a
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &44
ld (hl),a
inc hl
ld (hl),&cc
inc hl
ld a,(hl)
and &55
or &88
ld (hl),a
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &44
ld (hl),a
inc hl
ld (hl),&cc
inc hl
ld a,(hl)
and &55
or &88
ld (hl),a
inc hl
inc hl
inc hl
ld a,(hl)
and &aa
ld (hl),a
inc hl
ld (hl),&cc
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &44
ld (hl),a
inc hl
ld (hl),&cc
inc hl
ld a,(hl)
and &55
or &88
ld (hl),a
inc hl
inc hl
inc hl
ld a,(hl)
and &aa
ld (hl),a
inc hl
ld (hl),&cc
pop hl
call scr_next_line
push hl
inc hl
ld (hl),&cc
inc hl
ld (hl),&cc
inc hl
ld (hl),&cc
inc hl
ld (hl),&cc
inc hl
ld a,(hl)
and &55
or &88
ld (hl),a
pop hl
call scr_next_line
inc hl
ld (hl),&cc
inc hl
ld (hl),&cc
inc hl
ld (hl),&cc
inc hl
ld a,(hl)
and &55
or &88
ld (hl),a
ret
sprite_1:
push hl
inc hl
ld a,(hl)
and &aa
ld (hl),a
inc hl
ld (hl),&c0
inc hl
ld (hl),&c0
inc hl
ld (hl),&c0
inc hl
ld a,(hl)
and &55
or &80
ld (hl),a
pop hl
call scr_next_line
push hl
inc hl
ld (hl),&c0
inc hl
ld (hl),&c0
inc hl
ld (hl),&c0
inc hl
ld (hl),&c0
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &40
ld (hl),a
inc hl
ld (hl),&c0
inc hl
ld a,(hl)
and &55
or &80
ld (hl),a
inc hl
inc hl
inc hl
ld a,(hl)
and &aa
ld (hl),a
inc hl
ld (hl),&c0
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &40
ld (hl),a
inc hl
ld (hl),&c0
inc hl
ld a,(hl)
and &55
or &80
ld (hl),a
inc hl
inc hl
inc hl
ld a,(hl)
and &aa
ld (hl),a
inc hl
ld (hl),&c0
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &40
ld (hl),a
inc hl
ld (hl),&c0
inc hl
ld a,(hl)
and &55
or &80
ld (hl),a
inc hl
inc hl
inc hl
ld a,(hl)
and &aa
ld (hl),a
inc hl
ld (hl),&c0
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &40
ld (hl),a
inc hl
ld (hl),&c0
inc hl
ld a,(hl)
and &55
or &80
ld (hl),a
inc hl
inc hl
inc hl
ld a,(hl)
and &aa
ld (hl),a
inc hl
ld (hl),&c0
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &40
ld (hl),a
inc hl
ld (hl),&c0
inc hl
ld a,(hl)
and &55
or &80
ld (hl),a
inc hl
inc hl
inc hl
ld a,(hl)
and &aa
ld (hl),a
inc hl
ld (hl),&c0
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &40
ld (hl),a
inc hl
ld (hl),&c0
inc hl
ld a,(hl)
and &55
or &80
ld (hl),a
inc hl
inc hl
inc hl
ld a,(hl)
and &aa
ld (hl),a
inc hl
ld (hl),&c0
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &40
ld (hl),a
inc hl
ld (hl),&c0
inc hl
ld (hl),&c0
inc hl
ld (hl),&c0
inc hl
ld (hl),&c0
inc hl
ld (hl),&c0
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &40
ld (hl),a
inc hl
ld (hl),&c0
inc hl
ld (hl),&c0
inc hl
ld (hl),&c0
inc hl
ld (hl),&c0
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &40
ld (hl),a
inc hl
ld (hl),&c0
inc hl
ld a,(hl)
and &55
or &80
ld (hl),a
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &40
ld (hl),a
inc hl
ld (hl),&c0
inc hl
ld a,(hl)
and &55
or &80
ld (hl),a
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &40
ld (hl),a
inc hl
ld (hl),&c0
inc hl
ld a,(hl)
and &55
or &80
ld (hl),a
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &40
ld (hl),a
inc hl
ld (hl),&c0
inc hl
ld a,(hl)
and &55
or &80
ld (hl),a
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &40
ld (hl),a
inc hl
ld (hl),&c0
inc hl
ld a,(hl)
and &55
or &80
ld (hl),a
pop hl
call scr_next_line
ld a,(hl)
and &aa
or &40
ld (hl),a
inc hl
ld (hl),&c0
inc hl
ld a,(hl)
and &55
or &80
ld (hl),a
ret
sprite_2:
push hl
inc hl
ld a,(hl)
and &aa
ld (hl),a
inc hl
ld (hl),&0c
inc hl
ld (hl),&0c
inc hl
ld (hl),&0c
pop hl
call scr_next_line
push hl
inc hl
ld (hl),&0c
inc hl
ld (hl),&0c
inc hl
ld (hl),&0c
inc hl
ld (hl),&0c
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &04
ld (hl),a
inc hl
ld (hl),&0c
inc hl
ld a,(hl)
and &55
or &08
ld (hl),a
inc hl
inc hl
inc hl
ld a,(hl)
and &aa
ld (hl),a
inc hl
ld (hl),&0c
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &04
ld (hl),a
inc hl
ld (hl),&0c
inc hl
ld a,(hl)
and &55
or &08
ld (hl),a
inc hl
inc hl
inc hl
ld a,(hl)
and &aa
ld (hl),a
inc hl
ld (hl),&0c
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &04
ld (hl),a
inc hl
ld (hl),&0c
inc hl
ld a,(hl)
and &55
or &08
ld (hl),a
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &04
ld (hl),a
inc hl
ld (hl),&0c
inc hl
ld a,(hl)
and &55
or &08
ld (hl),a
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &04
ld (hl),a
inc hl
ld (hl),&0c
inc hl
ld a,(hl)
and &55
or &08
ld (hl),a
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &04
ld (hl),a
inc hl
ld (hl),&0c
inc hl
ld a,(hl)
and &55
or &08
ld (hl),a
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &04
ld (hl),a
inc hl
ld (hl),&0c
inc hl
ld a,(hl)
and &55
or &08
ld (hl),a
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &04
ld (hl),a
inc hl
ld (hl),&0c
inc hl
ld a,(hl)
and &55
or &08
ld (hl),a
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &04
ld (hl),a
inc hl
ld (hl),&0c
inc hl
ld a,(hl)
and &55
or &08
ld (hl),a
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &04
ld (hl),a
inc hl
ld (hl),&0c
inc hl
ld a,(hl)
and &55
or &08
ld (hl),a
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &04
ld (hl),a
inc hl
ld (hl),&0c
inc hl
ld a,(hl)
and &55
or &08
ld (hl),a
inc hl
inc hl
inc hl
ld a,(hl)
and &aa
ld (hl),a
inc hl
ld (hl),&0c
pop hl
call scr_next_line
push hl
ld a,(hl)
and &aa
or &04
ld (hl),a
inc hl
ld (hl),&0c
inc hl
ld a,(hl)
and &55
or &08
ld (hl),a
inc hl
inc hl
inc hl
ld a,(hl)
and &aa
ld (hl),a
inc hl
ld (hl),&0c
pop hl
call scr_next_line
push hl
inc hl
ld (hl),&0c
inc hl
ld (hl),&0c
inc hl
ld (hl),&0c
inc hl
ld (hl),&0c
inc hl
ld a,(hl)
and &55
or &08
ld (hl),a
pop hl
call scr_next_line
inc hl
ld (hl),&0c
inc hl
ld (hl),&0c
inc hl
ld (hl),&0c
inc hl
ld a,(hl)
and &55
or &08
ld (hl),a
ret
sprite_background:
defs sprite_height*sprite_width_bytes
prev_coords:
prev_y_coord:
defb 0
prev_x_coord:
defb 0
sprite_coords:
y_coord:
defb 0
x_coord:
defb 0
end