-
Notifications
You must be signed in to change notification settings - Fork 1
/
project.s
137 lines (116 loc) · 5.58 KB
/
project.s
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
;------------------------------------------------------------------------------
; Project
; Ted John
; Version 1.0
; 16 April 2013
;
; This programme is an audio player.
;
;------------------------------------------------------------------------------
INCLUDE ./os.s
;------------------------------------------------------------------------------
ORG OFFSET_USER
;------------------------------------------------------------------------------
;
;------------------------------------------------------------------------------
STATE_ABOUT EQU 0
STATE_STOPPED EQU 1
STATE_PLAYING EQU 2
STATE_FINISHED EQU 3
STATE_END EQU 4
;------------------------------------------------------------------------------
; Program variables
;------------------------------------------------------------------------------
module_project DEFS MODULE_PROJECT_SIZE
module_ui DEFS MODULE_UI_SIZE
module_player DEFS MODULE_PLAYER_SIZE
ALIGN
;------------------------------------------------------------------------------
; main() - user program entry point
;
; R7 - port i/o
;------------------------------------------------------------------------------
main
MOV SP, #OFFSET_ENDRAM ; initialise user stack pointer
MOV R3, #OFFSET_USER
ADD R0, R3, #(module_project-OFFSET_USER)
ADD R1, R3, #(module_ui-OFFSET_USER)
ADD R2, R3, #(module_player-OFFSET_USER)
BL project_init ; initialise the project module
BL project_run ; run the project program
SVC SVC_EXIT ; close the operating system
;------------------------------------------------------------------------------
; MODULE_PROJECT - structure for storing the project variables
;------------------------------------------------------------------------------
RECORD
MODULE_PROJECT_UI WORD
MODULE_PROJECT_PLAYER WORD
MODULE_PROJECT_MUSIC WORD
MODULE_PROJECT_STATE WORD
MODULE_PROJECT_SIZE ALIAS
;------------------------------------------------------------------------------
; project_init() - display information on the LCD
;
; I R0 - project module address
; I R1 - ui module address
; I R2 - player module address
;------------------------------------------------------------------------------
project_init_music_offset
DEFW music_data
project_init
PUSH {R0, R1, R3, LR}
STR R1, [R0, #MODULE_PROJECT_UI] ; store ui module address
STR R2, [R0, #MODULE_PROJECT_PLAYER] ; store player module address
LDR R3, project_init_music_offset ; store music data address
STR R3, [R0, #MODULE_PROJECT_MUSIC]
MOV R1, R0 ; project module address
MOV R0, R2 ; player module address
BL player_init ; initialise player module
LDR R0, [R1, #MODULE_PROJECT_UI]
BL ui_init
POP {R0, R1, R3, PC}
;------------------------------------------------------------------------------
; project_run() - run the project program
;
; I R0 - project module address
;
; R2 - project module address
;------------------------------------------------------------------------------
project_run
PUSH {R0, R1, R2, LR}
MOV R2, R0
; initialisation
MOV R0, #STATE_ABOUT ; set about state
STR R0, [R2, #MODULE_PROJECT_STATE]
LDR R0, [R2, #MODULE_PROJECT_UI]
BL ui_show_about
project_run_loop
LDR R1, [R2, #MODULE_PROJECT_STATE]
CMP R1, #STATE_PLAYING
BNE project_run_post_playing_check
LDR R0, [R2, #MODULE_PROJECT_PLAYER] ; update the player
BL player_update
CMP R1, #FALSE ; check if track has finished
MOVEQ R1, #STATE_FINISHED ; set state to stopped
STREQ R1, [R2, #MODULE_PROJECT_STATE]
project_run_post_playing_check
LDR R0, [R2, #MODULE_PROJECT_UI] ; update the ui (time)
CMP R1, #STATE_ABOUT
BEQ project_run_post_about_check
BL ui_track_updated
project_run_post_about_check
BL ui_handle_input ; handle input
LDR R0, [R2, #MODULE_PROJECT_STATE]
CMP R0, #STATE_END
BNE project_run_loop
POP {R0, R1, R2, PC}
;------------------------------------------------------------------------------
; Include other modules
;------------------------------------------------------------------------------
INCLUDE ./player.s
INCLUDE ./ui.s
;------------------------------------------------------------------------------
; Include the music data
;------------------------------------------------------------------------------
music_data
INCLUDE ./music_data.s