File: morse.i

package info (click to toggle)
picasm 1.14-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 528 kB
  • ctags: 378
  • sloc: ansic: 4,481; asm: 150; makefile: 72
file content (233 lines) | stat: -rw-r--r-- 3,808 bytes parent folder | download | duplicates (4)
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
;
; morse.i
;

;
; Macro to convert ascii strings and numbers to encoded morse code data.
; Uses macro recursion.
;
morsedata macro ; opcode,arg1,arg2,...
	if isstr(\2)
	  morse_string \1,\2,0
	else
	  if streq("\2","")
	    exitm
	  endif
	  morsechar \1,\2
	endif
	morsedata \1,\3,\4,\5,\6,\7,\8,\9
	endm

;
; This macro converts strings to morse code.
; Called from the morsedata macro.
; Also recursive.
;
morse_string macro ;string, startpos
	if chrval(\2,\3) >= 0
	  morsechar \1,chrval(\2,\3)
	  morse_string \1,\2,\3+1
	endif
	endm

;
; a big macro to convert one character of
; ASCII to morse code at assembly time
;
; zero bit represents a dot, and one bit represents a dash.
; the code is right-justified inside a byte, and is preceeded
; by a start bit of one (and padded with zero bits).
;
morsechar macro  ; opcode,asciicode
	if	(\2 == 32)
	  \1	0xff		;special code for space
	  exitm
	endif
	if	(\2 == '"')
	  \1	1010010b	; .-..-.
	  exitm
	endif
	if	(\2 == '(')
	  \1	1101101b	; -.--.-
	  exitm
	endif
	if	(\2 == ')')
	  \1	1101101b	; -.--.-
	  exitm
	endif
	if	(\2 == ',')
	  \1	1110011b	; --..--
	  exitm
	endif
	if	(\2 == '-')
	  \1	1100001b	; -....-
	  exitm
	endif
	if	(\2 == '.')
	  \1	1101010b	; -.-.-.
	  exitm
	endif
	if	(\2 == '/')
	  \1	110010b		; -..-.
	  exitm
	endif
	if	(\2 == '0')
	  \1	111111b		; -----
	  exitm
	endif
	if	(\2 == '1')
	  \1	101111b		; .----
	  exitm
	endif
	if	(\2 == '2')
	  \1	100111b		; ..---
	  exitm
	endif
	if	(\2 == '3')
	  \1	100011b		; ...--
	  exitm
	endif
	if	(\2 == '4')
	  \1	100001b		; ....-
	  exitm
	endif
	if	(\2 == '5')
	  \1	100000b		; .....
	  exitm
	endif
	if	(\2 == '6')
	  \1	110000b		; -....
	  exitm
	endif
	if	(\2 == '7')
	  \1	111000b		; --...
	  exitm
	endif
	if	(\2 == '8')
	  \1	111100b		; ---..
	  exitm
	endif
	if	(\2 == '9')
	  \1	111110b		; ----.
	  exitm
	endif
	if	(\2 == ':')
	  \1	1111000b	; ---...
	  exitm
	endif
	if	(\2 == '=')
	  \1	110001b		; -...-
	  exitm
	endif
	if	(\2 == '?')
	  \1	1001100b	; ..--..
	  exitm
	endif
	if	(\2 == 'A') | (\2 == 'a')
	  \1	101b		; .-
	  exitm
	endif
	if	(\2 == 'B') | (\2 == 'b')
	  \1	11000b		; -...
	  exitm
	endif
	if	(\2 == 'C') | (\2 == 'c')
	  \1	11010b		; -.-.
	  exitm
	endif
	if	(\2 == 'D') | (\2 == 'd')
	  \1	1100b		; -..
	  exitm
	endif
	if	(\2 == 'E') | (\2 == 'e')
	  \1	10b		; .
	  exitm
	endif
	if	(\2 == 'F') | (\2 == 'f')
	  \1	10010b		; ..-.
	  exitm
	endif
	if	(\2 == 'G') | (\2 == 'g')
	  \1	1110b		; --.
	  exitm
	endif
	if	(\2 == 'H') | (\2 == 'h')
	  \1	10000b		; ....
	  exitm
	endif
	if	(\2 == 'I') | (\2 == 'i')
	  \1	100b		; ..
	  exitm
	endif
	if	(\2 == 'J') | (\2 == 'j')
	  \1	10111b		; .---
	  exitm
	endif
	if	(\2 == 'K') | (\2 == 'k')
	  \1	1101b		; -.-
	  exitm
	endif
	if	(\2 == 'L') | (\2 == 'l')
	  \1	10100b		; .-..
	  exitm
	endif
	if	(\2 == 'M') | (\2 == 'm')
	  \1	111b		; --
	  exitm
	endif
	if	(\2 == 'N') | (\2 == 'n')
	  \1	110b		; -.
	  exitm
	endif
	if	(\2 == 'O') | (\2 == 'o')
	  \1	1111b		; ---
	  exitm
	endif
	if	(\2 == 'P') | (\2 == 'p')
	  \1	10110b		; .--.
	  exitm
	endif
	if	(\2 == 'Q') | (\2 == 'q')
	  \1	11101b		; --.-
	  exitm
	endif
	if	(\2 == 'R') | (\2 == 'r')
	  \1	1010b		; .-.
	  exitm
	endif
	if	(\2 == 'S') | (\2 == 's')
	  \1	1000b		; ...
	  exitm
	endif
	if	(\2 == 'T') | (\2 == 't')
	  \1	11b		; -
	  exitm
	endif
	if	(\2 == 'U') | (\2 == 'u')
	  \1	1001b		; ..-
	  exitm
	endif
	if	(\2 == 'V') | (\2 == 'v')
	  \1	10001b		; ...-
	  exitm
	endif
	if	(\2 == 'W') | (\2 == 'w')
	  \1	1011b		; .--
	  exitm
	endif
	if	(\2 == 'X') | (\2 == 'x')
	  \1	11001b		; -..-
	  exitm
	endif
	if	(\2 == 'Y') | (\2 == 'y')
	  \1	11011b		; -.--
	  exitm
	endif
	if	(\2 == 'Z') | (\2 == 'z')
	  \1	11100b		; --..
	  exitm
	endif

        ~ ;Error: Character not in morse code table!
        endm    ; end of morsechar macro