Browse code

Add source code of the applications

Pawel Jablonski authored on 18/03/2023 16:35:34
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,193 @@
1
+; Author: Pawel Jablonski
2
+; E-mail: pj@xirx.net
3
+; WWW: xirx.net
4
+; GIT: git.xirx.net
5
+;
6
+; License: You can use this code however you like
7
+; but leave information about the original author.
8
+; Code is free for non-commercial and commercial use.
9
+
10
+map ../../../bin/rom/rom.map
11
+
12
+; Start message
13
+const appListHeader "App list:"
14
+
15
+; Error messages
16
+const appListIsEmpty "Warning: App list is empty"
17
+const appListOpenError "Error: Cannot open the app dir"
18
+
19
+; Read buffer to store one sector
20
+var readBuffer[256]
21
+
22
+; App quantity in app dir
23
+var appQuantity
24
+
25
+; App counter
26
+var appCount
27
+
28
+; First label is the entry point
29
+.entry:
30
+	call .main
31
+	ret
32
+
33
+; No arguments
34
+; No return
35
+.main:
36
+	push A
37
+	push B
38
+	push X
39
+	push Y
40
+	; List app
41
+	call .xFSListApp
42
+	cmp 0, A
43
+	je .main_error
44
+	; Get list size
45
+	call .xFSSize
46
+	; Do not process empty list
47
+	push B
48
+	or A, B
49
+	; 0 == B
50
+	cmp 0, B
51
+	pop B
52
+	je .main_empty
53
+	; Save app quantity
54
+	push A
55
+	push B
56
+	swap A
57
+	and 0x0f, A
58
+	swap B
59
+	and 0xf0, B
60
+	or B, A
61
+	str A, *appQuantity
62
+	pop B
63
+	pop A
64
+	str 0, *appCount
65
+	; Calc how many block are needed to read
66
+	dec A
67
+	decc B
68
+	; Set starting block
69
+	mov 0, A
70
+	; Print header
71
+	mov low(*appListHeader), X
72
+	mov high(*appListHeader), Y
73
+	call .xStringPrint
74
+	call .xStringNewLine
75
+	call .xStringNewLine
76
+	; Run copy loop B+1 times
77
+.main_loop:
78
+	; Set buffer address
79
+	mov low(*readBuffer), X
80
+	mov high(*readBuffer), Y
81
+	; Read block
82
+	call .xFSReadBlock
83
+	inc A
84
+	; Print apps from block
85
+	call .printBlock
86
+	; Exit loop if all apps was printed
87
+	push A
88
+	push B
89
+	ldr *appCount, A
90
+	ldr *appQuantity, B
91
+	cmp A, B
92
+	pop B
93
+	pop A
94
+	jge .main_loop_exit
95
+	loopz B, .main_loop
96
+.main_loop_exit:
97
+	; Refresh the screen
98
+	call .xLcdRefresh
99
+	pop Y
100
+	pop X
101
+	pop B
102
+	pop A
103
+	ret
104
+.main_error:
105
+	; Print open error
106
+	mov low(*appListOpenError), X
107
+	mov high(*appListOpenError), Y
108
+	call .xStringPrint
109
+	; Refresh the screen
110
+	call .xLcdRefresh
111
+	pop Y
112
+	pop X
113
+	pop B
114
+	pop A
115
+	ret
116
+.main_empty:
117
+	; Print empty list message
118
+	mov low(*appListIsEmpty), X
119
+	mov high(*appListIsEmpty), Y
120
+	call .xStringPrint
121
+	; Refresh the screen
122
+	call .xLcdRefresh
123
+	pop Y
124
+	pop X
125
+	pop B
126
+	pop A
127
+	ret
128
+
129
+; No arguments
130
+; No return
131
+.printBlock:
132
+	push A
133
+	push B
134
+	push X
135
+	push Y
136
+	; Set buffer address
137
+	mov low(*readBuffer), X
138
+	mov high(*readBuffer), Y
139
+	mov 15, B
140
+	; Run print loop B+1 times
141
+.printBlock_loop:
142
+	; Print app name
143
+	call .printName
144
+	; Exit loop if all apps was printed
145
+	push B
146
+	xchg *appCount, A
147
+	ldr *appQuantity, B
148
+	inc A
149
+	cmp A, B
150
+	pop B
151
+	xchg *appCount, A
152
+	jge .main_loop_exit
153
+	; Go to next entry
154
+	add 16, X
155
+	incc Y
156
+	loopz B, .printBlock_loop
157
+.printBlock_loop_exit:
158
+	pop Y
159
+	pop X
160
+	pop B
161
+	pop A
162
+	ret
163
+
164
+; No arguments
165
+; No return
166
+.printName:
167
+	push A
168
+	push B
169
+	; Print a comma if it is not a first name
170
+	ldr *appCount, A
171
+	cmp 0, A
172
+	je .printName_noComma
173
+	mov '\,', A
174
+	call .xStringPrintChar
175
+	mov ' ', A
176
+	call .xStringPrintChar
177
+.printName_noComma:
178
+	; Check if it is enough space for next name in line
179
+	call .xStringLength
180
+	mov A, B
181
+	call .xStringGetCursorX
182
+	add B, A
183
+	; 40 > A
184
+	cmp 39, A
185
+	jg .printName_noNewLine
186
+	; Print name in new line
187
+	call .xStringNewLine
188
+.printName_noNewLine:
189
+	; Print name
190
+	call .xStringPrint
191
+	pop B
192
+	pop A
193
+	ret