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,196 @@
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 fileListHeader "File list:"
14
+
15
+; Error messages
16
+const fileListIsEmpty "Warning: File list is empty"
17
+const fileListOpenError "Error: Cannot open the file dir"
18
+
19
+; Read buffer to store one sector
20
+var readBuffer[256]
21
+
22
+; App quantity in app dir
23
+var fileQuantity
24
+
25
+; App counter
26
+var fileCount
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 file
41
+	call .xFSListFile
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 file 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, *fileQuantity
62
+	pop B
63
+	pop A
64
+	str 0, *fileCount
65
+	; Calc how many block are needed to read
66
+	dec A
67
+	decc B
68
+	; Set starting block
69
+	clr A
70
+	; Print header
71
+	mov low(*fileListHeader), X
72
+	mov high(*fileListHeader), Y
73
+	call .xStringPrint
74
+	call .xStringNewLine
75
+	; Run copy loop B+1 times
76
+.main_loop:
77
+	; Set buffer address
78
+	mov low(*readBuffer), X
79
+	mov high(*readBuffer), Y
80
+	; Read block
81
+	call .xFSReadBlock
82
+	inc A
83
+	; Print files from block
84
+	call .printBlock
85
+	; Exit loop if all files was printed
86
+	push A
87
+	push B
88
+	ldr *fileCount, A
89
+	ldr *fileQuantity, B
90
+	cmp A, B
91
+	pop B
92
+	pop A
93
+	jge .main_loop_exit
94
+	loopz B, .main_loop
95
+.main_loop_exit:
96
+	; Refresh the screen
97
+	call .xLcdRefresh
98
+	pop Y
99
+	pop X
100
+	pop B
101
+	pop A
102
+	ret
103
+.main_error:
104
+	; Print open error
105
+	mov low(*fileListOpenError), X
106
+	mov high(*fileListOpenError), Y
107
+	call .xStringPrint
108
+	; Refresh the screen
109
+	call .xLcdRefresh
110
+	pop Y
111
+	pop X
112
+	pop B
113
+	pop A
114
+	ret
115
+.main_empty:
116
+	; Print empty list message
117
+	mov low(*fileListIsEmpty), X
118
+	mov high(*fileListIsEmpty), Y
119
+	call .xStringPrint
120
+	; Refresh the screen
121
+	call .xLcdRefresh
122
+	pop Y
123
+	pop X
124
+	pop B
125
+	pop A
126
+	ret
127
+
128
+; No arguments
129
+; No return
130
+.printBlock:
131
+	push A
132
+	push B
133
+	push X
134
+	push Y
135
+	; Set buffer address
136
+	mov low(*readBuffer), X
137
+	mov high(*readBuffer), Y
138
+	mov 15, B
139
+	; Run print loop B+1 times
140
+.printBlock_loop:
141
+	; Print file name
142
+	call .printName
143
+	; Exit loop if all files was printed
144
+	push B
145
+	xchg *fileCount, A
146
+	ldr *fileQuantity, B
147
+	inc A
148
+	cmp A, B
149
+	pop B
150
+	xchg *fileCount, A
151
+	jge .main_loop_exit
152
+	; Go to next entry
153
+	add 16, X
154
+	incc Y
155
+	loopz B, .printBlock_loop
156
+.printBlock_loop_exit:
157
+	pop Y
158
+	pop X
159
+	pop B
160
+	pop A
161
+	ret
162
+
163
+; No arguments
164
+; No return
165
+.printName:
166
+	push A
167
+	push B
168
+	push X
169
+	push Y
170
+	ldr *fileCount, A
171
+	and 0x1, A
172
+	cmp 0, A
173
+	jne .printName_noNewLine
174
+	; Print name in new line
175
+	call .xStringNewLine
176
+	jmp .printName_noOffset
177
+.printName_noNewLine:
178
+	mov 20, A
179
+	call .xStringSetCursorX
180
+.printName_noOffset:
181
+	; Print name
182
+	call .xStringPrint
183
+	mov ' ', A
184
+	call .xStringPrintChar
185
+	add 14, X
186
+	incc Y
187
+	ldr A
188
+	inc X
189
+	incc Y
190
+	ldr B
191
+	call .xStringPrintU16
192
+	pop Y
193
+	pop X
194
+	pop B
195
+	pop A
196
+	ret