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,421 @@
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
+; TX buffer usage counter
13
+var txLength
14
+; TX buffer
15
+var txBuffer[39]
16
+
17
+; RX buffer usage counter
18
+var rxLength
19
+; RX buffer
20
+var rxBuffer[39]
21
+
22
+; Displayed lines counter
23
+var lineQuantity
24
+
25
+; First label is the entry point
26
+.entry:
27
+	call .main
28
+	ret
29
+
30
+; No arguments
31
+; No return
32
+.main:
33
+	push A
34
+	; Reset counters and buffers
35
+	str 0, *txLength
36
+	str 0, *txBuffer
37
+	str 0, *rxLength
38
+	str 0, *rxBuffer
39
+	str 0, *lineQuantity
40
+	; Clear screen
41
+	call .xLcdClear
42
+	; Show input
43
+	call .showInput
44
+	; Refresh screen
45
+	call .xLcdRefresh
46
+	; Keyboard and rs232 event loop
47
+.main_loop:
48
+	; Check if key was clicked
49
+	call .xKeyboardIsDataReady
50
+	cmp 0, A
51
+	jne .main_processKey
52
+	; Check if RX data is ready to read
53
+	call .xRS232IsRxDataReady
54
+	cmp 0, A
55
+	jne .main_processReceive
56
+	; Jump back to the beginning of event loop
57
+	jmp .main_loop
58
+	; Start processing key press event
59
+.main_processKey:
60
+	call .xKeyboardGetChar
61
+	; Exit if clicked key is ESC
62
+	cmp 0x1b, A
63
+	je .main_end
64
+	call .processKey
65
+	; Jump back to the beginning of event loop
66
+	jmp .main_loop
67
+	; Start processing RX data event
68
+.main_processReceive:
69
+	call .xRS232Receive
70
+	call .processReceive
71
+	; Jump back to the beginning of event loop
72
+	jmp .main_loop
73
+.main_end:
74
+	pop A
75
+	ret
76
+
77
+; Arguments:
78
+;	A - keycode
79
+; No return
80
+.processKey:
81
+	push A
82
+	; Check for backspace
83
+	cmp 0x08, A
84
+	je .processKey_backspace
85
+	; Check for enter
86
+	cmp 0x0d, A
87
+	je .processKey_enter
88
+	; Check for not printable char
89
+	; 0x20 > A
90
+	cmp 0x20, A
91
+	jg .processKey_notPrint
92
+	; 0x80 <= A
93
+	cmp 0x80, A
94
+	jle .processKey_notPrint
95
+	push B
96
+	; Check current length of buffer
97
+	ldr *txLength, B
98
+	; 38 =< B
99
+	cmp 38, B
100
+	jle .processKey_bufferFull
101
+	push X
102
+	push Y
103
+	; Set address to TX buffer
104
+	mov low(*txBuffer), X
105
+	mov high(*txBuffer), Y
106
+	; Move to working position
107
+	add B, X
108
+	incc Y
109
+	; Store keycode
110
+	str A
111
+	; Clear register
112
+	clr A
113
+	; Move to next position
114
+	inc X
115
+	incc Y
116
+	; Store termination code
117
+	str A
118
+	; Increment TX buffer position
119
+	inc B
120
+	; Store current TX buffer position
121
+	str B, *txLength
122
+	; Show input
123
+	call .showInput
124
+	; Refresh screen
125
+	call .xLcdRefresh
126
+.processKey_end:
127
+	pop Y
128
+	pop X
129
+.processKey_bufferFull:
130
+	pop B
131
+.processKey_notPrint:
132
+	pop A
133
+	ret
134
+	; Remove last char from TX buffer
135
+.processKey_backspace:
136
+	; Load TX buffer position
137
+	ldr *txLength, A
138
+	; 0 == A
139
+	cmp 0, A
140
+	; Do nothing if buffer is empty
141
+	je .processKey_notPrint
142
+	push X
143
+	push Y
144
+	; Decrement buffer position
145
+	dec A
146
+	; Store current TX buffer position
147
+	str A, *txLength
148
+	; Set address to TX buffer
149
+	mov low(*txBuffer), X
150
+	mov high(*txBuffer), Y
151
+	; Move to working position
152
+	add A, X
153
+	incc Y
154
+	; Clear register
155
+	clr A
156
+	; Store termination code
157
+	str A
158
+	; Show input
159
+	call .showInput
160
+	; Refresh screen
161
+	call .xLcdRefresh
162
+	pop Y
163
+	pop X
164
+	pop A
165
+	ret
166
+	; Enter key was pressed
167
+.processKey_enter:
168
+	; Load TX buffer position
169
+	ldr *txLength, A
170
+	; 0 == A
171
+	cmp 0, A
172
+	; Do nothing if buffer is empty
173
+	je .processKey_notPrint
174
+	; Send buffer content
175
+	call .sendString
176
+	; Print buffer content
177
+	call .printSentString
178
+	; Reset TX counter and TX buffer
179
+	str 0, *txLength
180
+	str 0, *txBuffer
181
+	; Show input
182
+	call .showInput
183
+	; Refresh screen
184
+	call .xLcdRefresh
185
+	pop A
186
+	ret
187
+
188
+; Arguments
189
+;	A - RX data
190
+; No return
191
+.processReceive:
192
+	; Check for end of string
193
+	cmp 0, A
194
+	je .processReceive_endString
195
+	; Check for LF code
196
+	cmp 0x0a, A
197
+	je .processReceive_endString
198
+	; Check for not printable char
199
+	; 0x20 > A
200
+	cmp 0x20, A
201
+	jg .processReceive_end
202
+	; 0x80 <= A
203
+	cmp 0x80, A
204
+	jle .processReceive_end
205
+	push B
206
+	push X
207
+	push Y
208
+	; Load RX buffer position
209
+	ldr *rxLength, B
210
+	; Set address to RX buffer
211
+	mov low(*rxBuffer), X
212
+	mov high(*rxBuffer), Y
213
+	; Move to working position
214
+	add B, X
215
+	incc Y
216
+	; Store RX data
217
+	str A
218
+	; Move to next position
219
+	inc X
220
+	incc Y
221
+	; Store termination code
222
+	str 0
223
+	; Increment RX buffer position
224
+	inc B
225
+	; Store current RX buffer position
226
+	str B, *rxLength
227
+	pop Y
228
+	pop X
229
+	; Check current length of buffer
230
+	; 38 > B
231
+	cmp 38, B
232
+	pop B
233
+	; Go to end if is is free space in RX buffer
234
+	jg .processReceive_end
235
+	push A
236
+	; Prepare termination code
237
+	clr A
238
+	; Call itself for process full buffer
239
+	call .processReceive
240
+	pop A
241
+	ret
242
+.processReceive_endString:
243
+	; Load RX buffer position 
244
+	ldr *rxLength, A
245
+	; 0 == A
246
+	cmp 0, A
247
+	; Do not print empty string
248
+	je .processReceive_end
249
+	; Print buffer content
250
+	call .printReceivedString
251
+	; Reset RX counter and RX buffer
252
+	str 0, *rxLength
253
+	str 0, *rxBuffer
254
+	; Show input
255
+	call .showInput
256
+	; Refresh screen
257
+	call .xLcdRefresh
258
+.processReceive_end:
259
+	ret
260
+
261
+; No arguments
262
+; No return
263
+.showInput:
264
+	push A
265
+	push B
266
+	push X
267
+	push Y
268
+	; Set draw start position
269
+	mov 0, X
270
+	mov 28, Y
271
+	call .xStringSetCursor
272
+	; Set clear char
273
+	mov ' ', A
274
+	; Reset counter
275
+	clr B
276
+.showInput_blankLoop:
277
+	; Print clear char
278
+	call .xStringPrintChar
279
+	; Draw 39+1 times
280
+	loope 39, B, .showInput_blankLoop
281
+	; Change colors for input
282
+	mov 0xf, A
283
+	call .xLcdSetBackground
284
+	mov 0x0, A
285
+	call .xLcdSetForeground
286
+	; Set clear char
287
+	mov ' ', A
288
+	; Reset counter
289
+	clr B
290
+.showInput_inputLoop:
291
+	call .xStringPrintChar
292
+	; Draw 39+1 times
293
+	loope 39, B, .showInput_inputLoop
294
+	; Go back at beginning of row
295
+	mov 0, A
296
+	call .xStringSetCursorX
297
+	; Print prompt
298
+	mov '>', A
299
+	call .xStringPrintChar
300
+	; Set address to TX buffer
301
+	mov low(*txBuffer), X
302
+	mov high(*txBuffer), Y
303
+	; Print buffer content
304
+	call .xStringPrint
305
+	; Print cursor
306
+	mov 0xDB, A
307
+	call .xStringPrintChar
308
+	; Turn back default colors
309
+	mov 0x0, A
310
+	call .xLcdSetBackground
311
+	mov 0xf, A
312
+	call .xLcdSetForeground
313
+	pop Y
314
+	pop X
315
+	pop B
316
+	pop A
317
+	ret
318
+
319
+; No arguments
320
+; No return
321
+.sendString:
322
+	push A
323
+	push B
324
+	push X
325
+	push Y
326
+	; Set address to TX buffer
327
+	mov low(*txBuffer), X
328
+	mov high(*txBuffer), Y
329
+	; Load TX buffer position 
330
+	ldr *txLength, B
331
+.sendString_loop:
332
+	; Load char to send
333
+	ldr A
334
+	; Check for end of string
335
+	cmp 0, A
336
+	jne .sendString_send
337
+	; Set LF code
338
+	mov 0x0a, A
339
+.sendString_send:
340
+	; Send char
341
+	call .xRS232Send
342
+	; Move to next position
343
+	inc X
344
+	incc Y
345
+	; Repeat B+1 times
346
+	loopz B, .sendString_loop
347
+	pop Y
348
+	pop X
349
+	pop B
350
+	pop A
351
+	ret
352
+
353
+; Arguments:
354
+;	X - low address
355
+;	Y - high address
356
+; No return
357
+.printString:
358
+	push A
359
+	; Load drawn line quantity
360
+	ldr *lineQuantity, A
361
+	; 27 <= A
362
+	cmp 27, A
363
+	; Count only 27+1 first lines else scroll screen
364
+	jle .printString_scroll
365
+	; Increment counter
366
+	inc A
367
+	; Store counter to line quantity
368
+	str A, *lineQuantity
369
+	jmp .printString_print
370
+.printString_scroll:
371
+	; Scroll screen to make a space to draw a new line of text
372
+	call .xLcdScroll
373
+.printString_print:
374
+	push X
375
+	push Y
376
+	; Move cursor to right place to print
377
+	mov 0, X
378
+	mov A, Y
379
+	call .xStringSetCursor
380
+	pop Y
381
+	pop X
382
+	; Print string from buffer
383
+	call .xStringPrint
384
+	pop A
385
+	ret
386
+
387
+; No arguments
388
+; No return
389
+.printSentString:
390
+	push X
391
+	push Y
392
+	; Set address to TX buffer
393
+	mov low(*txBuffer), X
394
+	mov high(*txBuffer), Y
395
+	; Print buffer on screen
396
+	call .printString
397
+	pop Y
398
+	pop Y
399
+	ret
400
+
401
+; No arguments
402
+; No return
403
+.printReceivedString:
404
+	push A
405
+	; Set foregound color to green
406
+	mov 0x0a, A
407
+	call .xLcdSetForeground
408
+	push X
409
+	push Y
410
+	; Set address to RX buffer
411
+	mov low(*rxBuffer), X
412
+	mov high(*rxBuffer), Y
413
+	; Print buffer on screen
414
+	call .printString
415
+	pop Y
416
+	pop X
417
+	; Set foregound color to default
418
+	mov 0x0f, A
419
+	call .xLcdSetForeground
420
+	pop A
421
+	ret