-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample2.asm
More file actions
137 lines (116 loc) · 2.89 KB
/
example2.asm
File metadata and controls
137 lines (116 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
; BIOS functions / MSX constants----------------
WRTVDP: equ #0047
LDIRVM: equ #005c
CHGMOD: equ #005f
BEEP: equ #00c0
SPRTBL2: equ #3800 ; sprite pattern address
SPRATR2: equ #1b00 ; sprite attribute address
CHSNS: equ #009c
CHGET: equ #009f
GTSTCK: equ #00d5
; ROM header -----------------------------------
org #4000
db "AB" ; ROM signature
dw Start ; start address
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Start:
ld a, 2 ; Change screen mode (Screen 2)
call CHGMOD
ld bc, 0e201h ; write e2h in VDP register 01h (activate sprites, generate interrupts, set 16x16 sprites)
call WRTVDP
; Define sprite:
ld de, SPRTBL2
ld hl, shipsprite
ld bc, 32
call LDIRVM
; transfer sprite attributes to RAM:
ld ix, spriteattributesRAM
ld (ix), 64 ; y
ld (ix+1), 64 ; x
ld (ix+2), 0 ; sprite pattern
ld (ix+3), 15 ; color
call BEEP
loop:
halt ; make the program run at 50/60 frames per second
; scan joystick (or cursor keys)
ld a, #0
call GTSTCK
; a should 1 - up, 2 - up/right, 3 - right, 4 - right/down,
; 5 - down, 6 - down/left, 7 - left, 8 - left/up
cp #1
jr z, move_up
cp #2
jr z, move_upright
cp #3
jr z, move_right
cp #4
jr z, move_rightdown
cp #5
jr z, move_down
cp #6
jr z, move_downleft
cp #7
jr z, move_left
cp #8
jr z, move_leftup
jp setsprite
move_up:
ld hl, spriteattributesRAM
dec (hl) ; decrease y
jp setsprite
move_upright:
ld hl, spriteattributesRAM
dec (hl) ; decrease y
ld hl, spriteattributesRAM + 1
inc (hl) ; increase x
jp setsprite
move_right:
ld hl, spriteattributesRAM + 1
inc (hl) ; increase x
jp setsprite
move_rightdown:
ld hl, spriteattributesRAM
inc (hl) ; increase y
ld hl, spriteattributesRAM + 1
inc (hl) ; increase x
jp setsprite
move_down:
ld hl, spriteattributesRAM
inc (hl) ; increase y
jp setsprite
move_downleft:
ld hl, spriteattributesRAM
inc (hl) ; increase y
ld hl, spriteattributesRAM + 1
dec (hl) ; decrease x
jp setsprite
move_left:
ld hl, spriteattributesRAM + 1
dec (hl) ; decrease x
jp setsprite
move_leftup:
ld hl, spriteattributesRAM
dec (hl) ; decrease y
ld hl, spriteattributesRAM + 1
dec (hl) ; decrease x
setsprite:
;; Update the sprite attributes in VRAM:
ld hl, spriteattributesRAM
ld de, SPRATR2
ld bc, 4
call LDIRVM
jp loop
getch:
call CHSNS ; call CHSNS
ld l, #0
ret z
call CHGET ; call CHGET
ld l, a
ret
shipsprite:
db 00h, 00h, 01h, 01h, 01h, 03h, 03h, 07h, 07h, 0fh, 1fh, 3fh, 3ch, 18h, 00h, 00h
db 00h, 00h, 80h, 80h, 80h,0c0h,0c0h,0e0h,0e0h,0f0h,0f8h,0fch, 3ch, 18h, 00h, 00h
ds 8000h - $ ; fill the rest of the ROM (up to 16KB with 0s)
org 0c000h ; RAM
spriteattributesRAM:
ds virtual 4