-
Notifications
You must be signed in to change notification settings - Fork 1
/
title.asm
151 lines (137 loc) · 3.31 KB
/
title.asm
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
;---------------------------------------------------------------------------
; Copyright (C) 2017 Lance Kindle
; Original from <github.com/lancekindle/minesweepGB>
; Licensed under GNU GPL v3 <http://www.gnu.org/licenses/>
;---------------------------------------------------------------------------
include "syntax.inc"
include "matrix.asm"
include "crosshairs.asm"
include "dma.inc"
include "math.asm"
include "debug.asm"
; holds methods for displaying the title-screen
IF !DEF(title_asm)
title_asm set 1
; generate text on fly
screen_write: MACRO
jr .past_letters\@
.letters\@
DB \3
.past_letters\@
mat_GetYX _SCRN0, \1, \2
ldpair de, hl ; destination is screen
ld hl, .letters\@ ; source is screen letters
ld bc, .past_letters\@ - .letters\@; # of bytes to write
call mem_CopyVRAM
ENDM
EASY_Y SET 8
MEDIUM_Y SET 10
HARD_Y SET 12
EASY_DIFFICULTY SET 30
EASY_RAMP SET 5
EASY_DENSITY SET 100
MEDIUM_DIFFICULTY SET 42
MEDIUM_RAMP SET 10
MEDIUM_DENSITY SET 200
HARD_DIFFICULTY SET 55
HARD_RAMP SET 15
HARD_DENSITY SET 230
; displays startscreen and waits for user input before returning
; runs a tight loop so that when the user presses a button,
; it initializes the random-value generator (not tied to vblank)
title_LevelSelect:
screen_write 5, 5, "Level Select"
screen_write EASY_Y, 5, "Easy"
screen_write MEDIUM_Y, 5, "Medium"
screen_write HARD_Y, 5, "Hard"
lda 8 + 3 + 2*8 ; offset + X*grid
ld [rPlayerX], a
ld [rCrosshairX], a
lda EASY_Y * 8
ld [rPlayerY], a
ld [rCrosshairY], a
call crosshairs_update
call DMACODELOC
irq_CallFromVBLANK title_vblank
irq_EnableVBLANK
.loop_for_input
if_not jpad_EdgeA, jr .loop_for_input
; we get here if the user pressed A
call set_difficulty_chosen
call jpad_GetKeys ; read keys again so that A is not "just"
; pressed. Prevents actions from happening
ld a, 8*8 ; place player coordinates directly in middle
ld [rPlayerY], a
ld a, 9*8
ld [rPlayerX], a
ret ; return to main execution
; handle moving cursor up or down
title_vblank:
call jpad_GetKeys
if_ jpad_EdgeDown, call MoveDownLevels
if_ jpad_EdgeUp, call MoveUpLevels
call crosshairs_update
call DMACODELOC
ret
MoveDownLevels:
if_ Player@Hard, ret ; don't move down past Hard
ld hl, rPlayerY
lda [hl]
add 16
ld [hl], a
ret
MoveUpLevels:
if_ Player@Easy, ret ; don't move above Easy
ld hl, rPlayerY
lda [hl]
sub 16
ld [hl], a
ret
Player@Easy:
lda [rPlayerY]
math_Div a, 8
ifa ==, EASY_Y, ret_true
ret_false
Player@Medium:
lda [rPlayerY]
math_Div a, 8
ifa ==, MEDIUM_Y, ret_true
ret_false
Player@Hard:
lda [rPlayerY]
math_Div a, 8
ifa ==, HARD_Y, ret_true
ret_false
; set difficulty based on player Y's position (which corresponds to difficulty)
; default of easy is chosen if it couldn't match any
set_difficulty_chosen:
if_ Player@Easy, jr .easy
if_ Player@Medium, jr .medium
if_ Player@Hard, jr .hard
.default
bug_message "didn't match any difficulty"
.easy
lda EASY_DIFFICULTY
ld [rDifficulty], a
lda EASY_RAMP
ld [rDifficultyRamp], a
lda EASY_DENSITY
ld [rDenseDifficulty], a
ret
.medium
lda MEDIUM_DIFFICULTY
ld [rDifficulty], a
lda MEDIUM_RAMP
ld [rDifficultyRamp], a
lda MEDIUM_DENSITY
ld [rDenseDifficulty], a
ret
.hard
lda HARD_DIFFICULTY
ld [rDifficulty], a
lda HARD_RAMP
ld [rDifficultyRamp], a
lda HARD_DENSITY
ld [rDenseDifficulty], a
ret
ENDC ; end title define