-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeacherMors.asm
2172 lines (2023 loc) · 36.9 KB
/
TeacherMors.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
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;
; TeacherMorsVFinal.asm
;
; Created: 1.01.2024 22:47:14
; Author : Digdem Yildiz & Zeynep Gencer
;
; define constants
.equ BAUD_RATE =9600
.equ CPU_CLOCK =4000000
.equ BAUD_DIV =(CPU_CLOCK/(16*BAUD_RATE))-1
.equ FIFOSIZE = 50 ; establish a buffer of size 50
.equ TEACHER = 0
.equ EXAM = 1
;;;;;;;;;;;;;;;
;TEACHING STATE
;.equ WAITING = 0
;.equ HASCHAR = 1
.equ MORSCHAR = 2
.equ SINGING = 3
.equ SILENT = 4
;;;;;;;;;;;;;;
;EXAM STATE
.equ FALSE = 5
.equ TRUE = 6
.equ A03 = 220
.equ maskT_dur = $03
;**************************************************************************
;**************************************************************************
.equ Xtal = 1048576 ; system clock frequency
.equ prescaler_t1 = 64 ; timer1 prescaler
.equ N_samples = 5 ; Number of samples in lookup table
.equ Fck = Xtal/prescaler_t1 ; timer1 working frequency
; define register aliases
.def SENTCHAR =r0 ; sent character
.def RECCHAR =r2 ; received character
.def TEMP1 =r17 ; another temporary register
.def FIFOHEAD =r22 ; index of beginning of FIFO
.def FIFOTAIL =r23 ; index of end of FIFO
.def tmp = r16 ; temp register
.def T_cnt = r18 ; Tone duration counter
.def T_dur = r19 ; Tone duration
.def state = R24
.def playState = R25
.def char = R3
.def morsCode = R21
.def chcheck =r20 ; temporary register
;.def flag =r26 ; flag for no match GIVES AN ERROR
; data segment
.dseg
fifo: .byte FIFOSIZE ; this is the FIFO area of size FIFOSIZE
; code segment
.cseg
.org $000
jmp reset ; $000 HW reset or watchdog
.org 0x012
rjmp tim1_ovf ; Timer1 overflow Handler
.org $016
rjmp tim0_ovf ; Timer/Counter0 Overflow Handler
.org $01A
jmp REC_INT ; $01A UART Rx complete
;;;; Timer 0 Overflow Handler
tim0_ovf:
push tmp ; Store temporary register
in tmp,SREG
push tmp ; Store status register
push ZL
push ZH ; Store Z-Pointer
push R0 ; Store R0 Register
cpi state, EXAM
breq T_exit
cpi playState, MORSCHAR
breq readT_dur
;cpi playState, SINGING
;brne if_notsilent
;rjmp continue
;if_notsilent:
;cpi playState, SILENT
;brne T_exit
; continue:
T0:
cp T_cnt, T_dur
breq switchMode
ldi tmp, 1
add T_cnt, tmp
cpi playState, SILENT
breq silentSinging
sbi DDRD,PD4 ; Set pin PD5 as output
ldi playState, SINGING
rjmp T_exit
switchMode:
cpi playState, SINGING
brne toSinging
ldi playState, SILENT
;ldi T_dur, $05
clr T_cnt
rjmp silentSinging
toSinging:
ldi playState, SINGING
cpi morsCode, $00
breq T1
readT_dur:
ldi playState, SINGING
mov T_dur, morsCode
andi T_dur, maskT_dur
lsl T_dur
lsl T_dur
clr T_cnt
lsr morsCode
lsr morsCode
rjmp T0
silentSinging:
cbi DDRD,PD4 ; Clear pin PD5 to disable output
rjmp T_exit
T1:
cbi DDRD,PD4 ; Clear pin PD5 to disable output
clr T_cnt
clr T_dur
T_exit:
pop R0 ; Restore R0 Register
pop ZH
pop ZL ; Restore Z-Pointer
pop tmp
out SREG,tmp ; Restore SREG
pop tmp ; Restore temporary register;
reti
;;; Timer 1 Overflow Handler
tim1_ovf:
push tmp ; Store temporary register
in tmp,SREG
push tmp ; Store status register
push ZL
push ZH ; Store Z-Pointer
push R0 ; Store R0 Register
cpi state, EXAM
brne T1_exit
generate:
ldi tmp, Fck/A03 ; load the note A03
mov R0, tmp
ldi tmp, 255
sub tmp, R0
out TCNT1L, tmp ; Load initial count value to T1
lsr R0 ; Divide R0 by 2
add tmp, R0 ; OCR threshold for 50% duty cycle
out OCR1BL,tmp ; send the OCR value to PWM
T1_exit:
pop R0 ; Restore R0 Register
pop ZH
pop ZL ; Restore Z-Pointer
pop tmp
out SREG,tmp ; Restore SREG
pop tmp ; Restore temporary register;
reti
; Interrupt Handler
REC_INT:
push tmp ; registers
in tmp, SREG
push tmp
push RECCHAR
in RECCHAR, UDR ; read UART receive data
mov tmp, RECCHAR
out PORTB, tmp ; display data on LEDs
put_char:
rcall FIFOput ; place data in the FIFO
rec_int_exit:
pop RECCHAR ; restore registers
pop tmp
out SREG, tmp
pop tmp
reti ; return from interrupt
; begin main code
reset:
ldi tmp, low(RAMEND) ; initialize stack pointer
out SPL, tmp
ldi tmp, high(RAMEND)
out SPH, tmp
rcall clrFIFO ; initialize FIFO
ldi state, TEACHER ; initialize state
;ldi playState, WAITING
ldi morsCode, 0
ldi T_dur, 0
ldi T_cnt, 0
ldi tmp, $FF ; port D all outputs
out DDRC, tmp
ldi tmp, $FF ; port B all outputs
out DDRB, tmp
ldi tmp, $00
out PORTB, tmp ; initially all LEDs off
ldi tmp, low(BAUD_DIV) ; set UART baud rate
out UBRRL, tmp
ldi tmp, high(BAUD_DIV) ; set UART baud rate
out UBRRH, tmp
sbi UCSRB, TXEN ; enable serial transmitter
sbi UCSRB, RXEN ; enable serial receiver
sbi UCSRB, RXCIE ; enable receiver interrupts
;enable timer0 ovf interrupt
ldi tmp, (1<<CS02)|(1<<CS00) ; Prepare prescaler
out TCCR0, tmp ; Timer clock = system clock / 1024
; timer0 ovf frequency 4 Hz
;enable timer1 / timer0 interrupt
ldi tmp,(1<<TOIE1)+(1<<TOIE0)
out TIMSK,tmp ; Enable Timer0/Timer1 ovf interrupt
; set timer1 PWM mode
ldi tmp,(1<<WGM10)+(1<<COM1B1)
out TCCR1A,tmp ; 8 bit Fast PWM non-inverting (Fck/256)
ldi tmp,(1<<WGM12)+(1<<CS10)+(1<<CS11) ; 8 bit Fast PWM non-inverting (Fck/256)
out TCCR1B,tmp
sei ; enable interrupts
rcall printTeacherMors
rcall printNewLine
rcall printNewLine
rcall printWelcome
rcall printNewLine
rcall printStartMessage
rcall printNewLine
rcall printTeacherMode
rcall printNewLine
mloop:
out PORTC, state
cpi state, TEACHER
brne mloop2
;cpi playState, WAITING
;brne mloop
rcall fillChar
;cpi playState, HASCHAR
;brne mloop
rcall tolowerTeacher
rcall parseCharA_Z
cpi state, EXAM
breq mloop2
//ldi playState, MORSCHAR
rcall printNewLine
rcall printTeacherMode
rcall printNewLine
rjmp mloop
mloop2:
out PORTC, state
rcall FIFOget ; get the next character from the FIFO
brcc no_inp ;
mov chcheck, RECCHAR; we will receive the testing char
mov SENTCHAR, chcheck
rcall putchar ; transmit character
cpi chcheck, $21 ;if char is ! change back to teaching state
breq toTeacherMode
cpi chcheck, $3F ;if char is ? change back to exam state
breq toExamMode
rcall tolowerExam
rcall readCharA_Z
rcall printExamMode
rcall printNewLine
no_inp:
rjmp mloop2
toTeacherMode:
ldi state, Teacher
;ldi playState, WAITING
rcall printNewLine
rcall printTeacherMode
rcall printNewLine
jmp mloop
toExamMode:
ldi state, EXAM
rcall printNewLine
rcall printExamMode
rcall printNewLine
jmp mloop2
; subroutines
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;TEACHER STATE
tolowerTeacher:
ldi tmp, $61
cp char,tmp ;61 is hex for A, 41 is for a; to avoid confusion I will turn every uppercase letter to lowercase
brge makeLowerTeacher
ret
makeLowerTeacher:
ldi tmp, $20
sub char, tmp
ret
parseCharA_Z:
;ldi playState, WAITING
mov tmp, char ; Get dash character (?)
cpi tmp, $3F
breq toExam
;ldi tmp, $21 ; Get exclamation point character (!)
cpi tmp, $21
breq toTeacher
ldi playState, MORSCHAR
checkA:
cpi tmp, $41 ; Get A
;cp char, tmp
breq toA
cpi tmp, $42 ; Get B
;cp char, tmp
breq toB
cpi tmp, $43 ; Get C
;cp char, tmp
breq toC
cpi tmp, $44 ; Get D
;cp char, tmp
breq toD
cpi tmp, $45 ; Get E
;cp char, tmp
breq toE
cpi tmp, $46 ; Get F
;cp char, tmp
breq toF
cpi tmp, $47 ; Get G
;cp char, tmp
breq toG
cpi tmp, $48 ; Get H
;cp char, tmp
breq toH
cpi tmp, $49 ; Get I
;cp char, tmp
breq toI
cpi tmp, $4A ; Get J
;cp char, tmp
breq toJ
cpi tmp, $4B ; Get K
;cp char, tmp
breq toK
cpi tmp, $4C ; Get L
;cp char, tmp
breq toL
cpi tmp, $4D ; Get M
; cp char, tmp
breq toM
cpi tmp, $4E ; Get N
;cp char, tmp
breq toN
cpi tmp, $4F ; Get O
;cp char, tmp
breq toO
cpi tmp, $50 ; Get P
;cp char, tmp
breq toP
cpi tmp, $51 ; Get Q
;cp char, tmp
breq toQ
rcall parseCharR_Z
ret
toExam:
ldi state, EXAM
rcall printNewLine
rcall printExamMode
rcall printNewLine
ret
toTeacher:
ldi state, TEACHER
ret
toA:
ldi morsCode, 0b00001101
ret
toB:
ldi morsCode, 0b01010111
ret
toC:
ldi morsCode, 0b01110111
ret
toD:
ldi morsCode, 0b00010111
ret
toE:
ldi morsCode, 0b00000001
ret
toF:
ldi morsCode, 0b01110101
ret
toG:
ldi morsCode, 0b00011111
ret
toH:
ldi morsCode, 0b00010101
ret
toI:
ldi morsCode, 0b00000101
ret
toJ:
ldi morsCode, 0b11111101
ret
toK:
ldi morsCode, 0b00110111
ret
toL:
ldi morsCode, 0b01011101
ret
toM:
ldi morsCode, 0b00001111
ret
toN:
ldi morsCode, 0b00000111
ret
toO:
ldi morsCode, 0b00111111
ret
toP:
ldi morsCode, 0b01111101
ret
toQ:
ldi morsCode, 0b11011111
ret
parseCharR_Z:
cpi tmp, $52 ; Get R
;cp char, tmp
breq toR
cpi tmp, $53 ; Get S
;cp char, tmp
breq toS
cpi tmp, $54 ; Get T
;cp char, tmp
breq toT
cpi tmp, $55 ; Get U
;cp char, tmp
breq toU
cpi tmp, $56 ; Get V
;cp char, tmp
breq toV
cpi tmp, $57 ; Get W
;cp char, tmp
breq toW
cpi tmp, $58 ; Get X
;cp char, tmp
breq toX
cpi tmp, $59 ; Get Y
;cp char, tmp
breq toY
cpi tmp, $5A ; Get Z
;cp char, tmp
breq toZ
;ldi playState, WAITING
rcall printNewLine
rcall printInvalidChar
rcall printNewLine
rcall printTeacherMode
rcall printNewLine
ret
toR:
ldi morsCode, 0b00011101
ret
toS:
ldi morsCode, 0b00010101
ret
toT:
ldi morsCode, 0b00000011
ret
toU:
ldi morsCode, 0b00110101
ret
toV:
ldi morsCode, 0b11010101
ret
toW:
ldi morsCode, 0b00111101
ret
toX:
ldi morsCode, 0b11010111
ret
toY:
ldi morsCode, 0b11110111
ret
toZ:
ldi morsCode, 0b01011111
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;EXAM STATE
tolowerExam:
cpi chcheck, $61 ;61 is hex for A, 41 is for a; to avoid confusion I will turn every uppercase letter to lowercase
brge makeLowerExam
ret
;rcall readChar
makeLowerExam:
subi chcheck, $20
ret
readCharA_Z:
cpi chcheck, $41
breq morsA
cpi chcheck, $42
breq morsB
cpi chcheck, $43
breq morsC
cpi chcheck, $44
breq morsD
cpi chcheck, $45
breq morsE
cpi chcheck, $46
breq morsF
rcall readCharG_L
ret
morsA: ; .- ascii 46 and 45 => hex 2E and 2D
rcall readDot
cpi playState, FALSE
breq morsA_Exit
rcall readDash
rcall checkCodeTrue
ret
morsA_Exit:
ret
morsB: ; -...
rcall readDash
cpi playState, FALSE
breq morsB_Exit
rcall readDot
cpi playState, FALSE
breq morsB_Exit
rcall readDot
cpi playState, FALSE
breq morsB_Exit
rcall readDot
rcall checkCodeTrue
morsB_Exit:
ret
morsC: ; -.-.
rcall readDash
cpi playState, FALSE
breq morsC_Exit
rcall readDot
cpi playState, FALSE
breq morsC_Exit
rcall readDash
cpi playState, FALSE
breq morsC_Exit
rcall readDot
rcall checkCodeTrue
morsC_Exit:
ret
morsD: ; -..
rcall readDash
cpi playState, FALSE
breq morsD_Exit
rcall readDot
cpi playState, FALSE
breq morsD_Exit
rcall readDot
rcall checkCodeTrue
morsD_Exit:
ret
morsE: ; .
rcall readDot
rcall checkCodeTrue
ret
morsF: ; ..-.
rcall readDot
cpi playState, FALSE
breq morsF_Exit
rcall readDot
cpi playState, FALSE
breq morsF_Exit
rcall readDash
cpi playState, FALSE
breq morsF_Exit
rcall readDot
rcall checkCodeTrue
morsF_Exit:
ret
readCharG_L:
cpi chcheck, $47
breq morsG
cpi chcheck, $48
breq morsH
cpi chcheck, $49
breq morsI
cpi chcheck, $4A
breq morsJ
cpi chcheck, $4B
breq morsK
cpi chcheck, $4C
breq morsL
rcall readCharM_O
ret
morsG: ; --.
rcall readDash
cpi playState, FALSE
breq morsG_Exit
rcall readDash
cpi playState, FALSE
breq morsG_Exit
rcall readDot
rcall checkCodeTrue
morsG_Exit:
ret
morsH: ; ....
rcall readDot
cpi playState, FALSE
breq morsH_Exit
rcall readDot
cpi playState, FALSE
breq morsH_Exit
rcall readDot
cpi playState, FALSE
breq morsH_Exit
rcall readDot
rcall checkCodeTrue
morsH_Exit:
ret
morsI: ; ..
rcall readDot
cpi playState, FALSE
breq morsI_Exit
rcall readDot
rcall checkCodeTrue
morsI_Exit:
ret
morsJ: ; .---
rcall readDot
cpi playState, FALSE
breq morsJ_Exit
rcall readDash
cpi playState, FALSE
breq morsJ_Exit
rcall readDash
cpi playState, FALSE
breq morsJ_Exit
rcall readDash
rcall checkCodeTrue
morsJ_Exit:
ret
morsK: ; -.-
rcall readDash
cpi playState, FALSE
breq morsK_Exit
rcall readDot
cpi playState, FALSE
breq morsK_Exit
rcall readDash
rcall checkCodeTrue
morsK_Exit:
ret
morsL: ; .-..
rcall readDot
cpi playState, FALSE
breq morsL_Exit
rcall readDash
cpi playState, FALSE
breq morsL_Exit
rcall readDot
cpi playState, FALSE
breq morsL_Exit
rcall readDot
rcall checkCodeTrue
morsL_Exit:
ret
readCharM_O:
cpi chcheck, $4D
breq morsM
cpi chcheck, $4E
breq morsN
cpi chcheck, $4F
breq morsO
rcall readCharP_U
ret
morsM: ; --
rcall readDash
cpi playState, FALSE
breq morsM_Exit
rcall readDash
rcall checkCodeTrue
morsM_Exit:
ret
morsN: ; -.
rcall readDash
cpi playState, FALSE
breq morsN_Exit
rcall readDot
rcall checkCodeTrue
morsN_Exit:
ret
morsO: ; ---
rcall readDash
cpi playState, FALSE
breq morsO_Exit
rcall readDash
cpi playState, FALSE
breq morsO_Exit
rcall readDash
rcall checkCodeTrue
morsO_Exit:
ret
readCharP_U:
cpi chcheck, $50
breq morsP
cpi chcheck, $51
breq morsQ
cpi chcheck, $52
breq morsR
cpi chcheck, $53
breq morsS
cpi chcheck, $54
breq morsT
cpi chcheck, $55
breq morsU
rcall readCharV_Z
ret
morsP: ; .--.
rcall readDot
cpi playState, FALSE
breq morsP_Exit
rcall readDash
cpi playState, FALSE
breq morsP_Exit
rcall readDash
cpi playState, FALSE
breq morsP_Exit
rcall readDot
rcall checkCodeTrue
morsP_Exit:
ret
morsQ: ; --.-
rcall readDash
cpi playState, FALSE
breq morsQ_Exit
rcall readDash
cpi playState, FALSE
breq morsQ_Exit
rcall readDot
cpi playState, FALSE
breq morsQ_Exit
rcall readDash
rcall checkCodeTrue
morsQ_Exit:
ret
morsR: ; .-.
rcall readDot
cpi playState, FALSE
breq morsR_Exit
rcall readDash
cpi playState, FALSE
breq morsR_Exit
rcall readDot
rcall checkCodeTrue
morsR_Exit:
ret
morsS: ; ...
rcall readDot
cpi playState, FALSE
breq morsS_Exit
rcall readDot
cpi playState, FALSE
breq morsS_Exit
rcall readDot
rcall checkCodeTrue
morsS_Exit:
ret
morsT: ; -
rcall readDash
rcall checkCodeTrue
ret
morsU: ; ..-
rcall readDot
cpi playState, FALSE
breq morsU_Exit
rcall readDot
cpi playState, FALSE
breq morsU_Exit
rcall readDash
rcall checkCodeTrue
morsU_Exit:
ret
readCharV_Z:
cpi chcheck, $56
breq morsV
cpi chcheck, $57
breq morsW
cpi chcheck, $58
breq morsX
cpi chcheck, $59
breq morsY
cpi chcheck, $5A
breq morsZ
rcall printNewLine
rcall printInvalidChar
rcall printNewLine
ret
morsV: ; ...-
rcall readDot
cpi playState, FALSE
breq morsV_Exit
rcall readDot
cpi playState, FALSE
breq morsV_Exit
rcall readDot
cpi playState, FALSE
breq morsV_Exit
rcall readDash
rcall checkCodeTrue
morsV_Exit:
ret
morsW: ; .--
rcall readDot
cpi playState, FALSE
breq morsW_Exit
rcall readDash
cpi playState, FALSE
breq morsW_Exit
rcall readDash
rcall checkCodeTrue
morsW_Exit:
ret
morsX: ; -..-
rcall readDash
cpi playState, FALSE
breq morsX_Exit
rcall readDot
cpi playState, FALSE
breq morsX_Exit
rcall readDot
cpi playState, FALSE
breq morsX_Exit
rcall readDash
rcall checkCodeTrue
morsX_Exit:
ret
morsY: ; -.--
rcall readDash
cpi playState, FALSE
breq morsY_Exit
rcall readDot
cpi playState, FALSE
breq morsY_Exit
rcall readDash
cpi playState, FALSE
breq morsY_Exit
rcall readDash
rcall checkCodeTrue
morsY_Exit:
ret
morsZ: ; --..
rcall readDash
cpi playState, FALSE
breq morsZ_Exit
rcall readDash
cpi playState, FALSE
breq morsZ_Exit
rcall readDot
cpi playState, FALSE
breq morsZ_Exit
rcall readDot
rcall checkCodeTrue
morsZ_Exit:
ret
;;;;;;;;;;;;;;;
readDot:
rcall FIFOget ; get the next character from the FIFO
brcc readDot
mov chcheck, RECCHAR
mov SENTCHAR, chcheck
rcall putChar
cpi chcheck, $2E ; ascii for dot
brne dotFalse
ldi playState, TRUE
ret
dotFalse:
ldi playState, FALSE
cpi chcheck, $2D ; ascii for dash
breq prntF
//if its not dot or dash its invalid
rcall printNewLine
rcall printNotDotNotDash
prntF:
rcall printNewLine
rcall printFalse
ret
;;;;;;;;;;;;;;;
readDash:
rcall FIFOget ; get the next character from the FIFO
brcc readDash
mov chcheck, RECCHAR
mov SENTCHAR, chcheck
rcall putChar
cpi chcheck, $2D ; ascii for dash
brne dashFalse
ldi playState, TRUE
ret
dashFalse:
ldi playState, FALSE
cpi chcheck, $2E ; ascii for dash
breq prntF
//if its not dot or dash its invalid
rcall printNewLine
rcall printNotDotNotDash
rcall printNewLine
rcall printFalse
ret
;;;;;;;;;;;;;;
checkCodeTrue:
cpi playState, TRUE
breq codeTrue
ret
codeTrue:
rcall printNewLine
rcall printTrue
ret
printNewline:
ldi tmp, $0A
mov SENTCHAR, tmp
rcall putchar
ldi tmp, $0D
mov SENTCHAR, tmp
rcall putchar
ret
printFalse:
ldi tmp, $46