-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_H.asm
147 lines (141 loc) · 3.51 KB
/
command_H.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
; This file is part of Programator.
;
; Programator is free software: you can redistribute it and/or
; modify it under the terms of the GNU General Public License as
; published by the Free Software Foundation, either version 3 of the
; License, or (at your option) any later version.
;
; Programator is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
; General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with Programator. If not, see <https://www.gnu.org/licenses/>.
;
; Copyright (c) 2022, 2024 Aleksander Mazur
;
; Procedura obsługi polecenia H (Help)
; Podaje listę wszystkich dostępnych komend
;-----------------------------------------------------------
; H
if USE_HELP_DESC
dw s_help_H
endif
command_help:
bcall ensure_no_args
clr A
dec A
push ACC ; push -1
mov R0, #input
clr A
; A=0 - zaczynamy od początku listy
command_help_next_reset_dptr:
mov DPTR, #s_commands
command_help_next:
; A = bieżący offset
cjne A, #-1, command_help_next_ok
; offset = -1 -> koniec
ret
command_help_next_ok:
mov R2, A
acall get_next_from_dptr_a
; R2 = offset za znakiem
; A = kod znaku na liście przejść stanu
; A=0 -> koniec komendy
jz command_help_print_cmd
; A=-1 -> powrót
cjne A, #-1, command_help_collect_char
sjmp command_help_pop
command_help_collect_char:
mov @R0, A
inc R0
; A = offset podlisty
acall get_next_from_dptr_r2
push AR2 ; zapisujemy offset następnego znaku w tej podliście
sjmp command_help_next_ok
command_help_print_cmd:
; wypisujemy, co mamy w input
mov @R0, #0
mov R1, #input
command_help_print_cmd_loop:
mov A, @R1
jz command_help_print_cmd2
bcall uart_send_char
inc R1
sjmp command_help_print_cmd_loop
command_help_print_cmd2:
if USE_HELP_DESC
; sprawdzamy kod realizujący komendę
acall get_next_from_dptr_r2
cjne A, #2, command_help_not_ljmp
; LJMP hh ll - adres bezwzględny jest w dwóch kolejnych bajtach
acall get_next_from_dptr_r2
mov R6, A
acall get_next_from_dptr_r2
mov R7, A
sjmp command_help_print_desc
command_help_not_ljmp:
; czy to AJMP? kody 01h, 21h, 41h, 61h, 81h, A1h, C1h, E1h
mov R6, A
anl A, #00011111b
cjne A, #01h, command_help_not_ajmp
; 8 najmłodszych bitów adresu jest w drugim bajcie rozkazu
; 3 kolejne są w najstarszych bitach pierwszego bajtu (które właśnie zamaskowaliśmy)
; najstarsze bity są takie, jak w punkcie skoku, czyli w DPTR po przejściu za rozkaz
mov A, R6
rl A
rl A
rl A
anl A, #00000111b
mov R6, A
acall get_next_from_dptr_r2
mov R7, A
mov A, DPH
anl A, #11111000b
orl A, R6
mov R6, A
command_help_print_desc:
mov A, #9 ; tab
bcall uart_send_char
; w R6:R7 mamy adres docelowy skoku realizującego komendę
; 2 bajty wcześniej powinien być adres tekstu z krótkim opisem komendy
clr C
mov A, R7
subb A, #2
mov R7, A
mov A, R6
subb A, #0
mov DPH, A
mov DPL, R7
; DPTR := code[DPTR]
clr A
movc A, @A + DPTR
mov R6, A
mov A, #1
movc A, @A + DPTR
mov DPH, R6
mov DPL, A
bcall uart_send_rom
command_help_not_ajmp:
endif
; i enter
bcall uart_send_crlf
command_help_pop:
; wracamy poziom wyżej
dec R0
pop ACC
if USE_HELP_DESC
sjmp command_help_next_reset_dptr
else
sjmp command_help_next
endif
;-----------------------------------------------------------
; Pobiera bajt spod DPTR+R2 do A i zwiększa R2
; A := code[DPTR + R2++]
get_next_from_dptr_r2:
mov A, R2
get_next_from_dptr_a:
movc A, @A + DPTR
inc R2
ret