-
Notifications
You must be signed in to change notification settings - Fork 1
/
FISH_STM32F4_IARg.s
5657 lines (4860 loc) · 122 KB
/
FISH_STM32F4_IARg.s
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
// FISH_STM32F4_IAR.s - FULL WORD
// FISH FOR THE STM IS CURRENTLY SUPPORTING F2 TO F4
// Code is common, seperate linker files used for memory map differences.
$FISH_STM32F4_MAIN_INCLUDES.h
//------------------------------------------------------------------------------
// 2DO: Add VIO_UARTX, VIO_KEY, VIO_?KEY and VIO_EMIT
// (EMIT), (KEY?), and (KEY).
// v1.7:
// 2DO: Signon updated. (FOR TEST - FIX B4 SHIP)
// 2DO: Updated .hex .out and sym.bat
// 2DO:
// #define EOL_DLE // DLE in QUIT after last line interpreted
// #define EOL_NAK // NAK in error messages for STDLED editor highlight
// Split out files to FISH_RM_COMMON and FISH_RM_COMMON_CODE_CORTEX_M
// ADDED EHON and EHOFF to FISH RM
// Changes iar.s COLD, ERROR and ABORT
// Changes FISH_STM32F4_SLIB.s SV_INIT_VALUES: & FWARM:
// Adds 1 word to FISH_STM32F4_MEMMAP.s - ERROR_HALT: SV
// ADDED P(PROMPT), PON(PROMPTON) and POFF(PROMPTOFF) to FISH RM
// Changes FISH_STM32F4_SLIB.s SV_INIT_VALUES: & FWARM: & QUIT:
// Adds 1 word to FISH_STM32F4_MEMMAP.s - PROMPT: SV
// Added #define TRUE_EQU_NEG_ONE
// Changed all user visible true flags to -1
// Added SXTB Rd, Rm and SXTH Rd, Rm
// Number Stuff Wordcat reorganized (search NOEXEC or WC_NUMBERS_NFA)
// EXPECT does counted null strings:
// NUMBER to look for null terminatiion instead of BLANK.
// WORD changed to expect null string and elimated BLANKS fill of HERE.
// SPEEDS UP TOKENIZATION OF TIB INPUT!
// ALL IN AND IN_SV INIT SET TO 1 in QUERY SV_INIT_VALUES CLRTIB
// NUMBERSUFFIX changed to replace suffix with null
// PAREN ( changed to use TIB+1
// DPL restored to dictionairy.
//------------------------------------------------------------------------------
SECTION .text : CONST (2)
msg_FISH:
// DC8 "?" IS A NULL TERMINATED STRING
// DC8 '?' IS NOT
//#if FISH_PubRel_WORDSET | FISH_DebugSrc_WORDSET
DC8 'FISH ARM '
//#endif
#if FISH_PubRel_WORDSET & FISH_Debug_WORDSET
DC8 ' VTOR FIXED - EHON/EHOFF '
// DC8 '-1 True Flag '
#endif
#if VTOR_PATCH & STM32F205RC
DC8 'VTOR_PATCH FOR MS '
#endif
#ifdef FISH_Debug_WORDSET
DC8 'DebugSrc '
#endif
#ifdef STM32F4_XRC08_168MHZ
DC8 'STM32F407VG DISCO '
#endif
#ifdef STM32F205RC_XRC10_118MHZ
DC8 'STM32F205RC STP RPM Board '
#endif
#ifdef FISH_PRO_WORDCAT
DC8 'Pro '
#endif
DC8 'RM V1.7 (C)2014-2015 A-TEAM FORTH : '
DC8 __DATE__ // Null string
msg_FISH_TIMESTAMP:
DC8 ' at '
DC8 __TIME__ // Null string
msg_MY_OK:
DC8 " ok, go fish in BASE "
//-----------------START OF DICTIONARY = Last word in search--------------------
// NOOP NOOP: ( -- )
SECTION .text : CONST (2)
NOOP_NFA:
DC8 0x84
DC8 'NOO'
DC8 'P'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 0 // 0 START OF DICTIONARY = Last word in search
NOOP:
DC32 .+5
SECTION .text : CODE (2)
NEXT
// EXECUTE EXEC: ( cfa -- ) RENAMED: EXECUTE to EXEC
// Execute a single word whose cfa is on the stack
SECTION .text : CONST (2)
EXEC_NFA:
DC8 0x87
DC8 'EXECUT'
DC8 'E'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 NOOP_NFA
EXEC:
DC32 .+5
SECTION .text : CODE (2)
#ifndef IO2TP
#ifdef XON_XOFF
BL TXRDY_SUBR
BL XOFF_SUBR
#endif
#endif
EXEC_ACTION:
POPp2w // as in xeq token at ToS setup for exec LDM p!, {w}
NEXT1
#ifndef IO2TP
// TXRDY_SUBR:
SECTION .text : CODE (2)
TXRDY_SUBR:
MOV w, lr // Allow for interrupts to use LR
LDR y, = USART3_SR // Line Status Register
txRDY?:
LDR n, [y] // Get Line Status
// THIS IS TXE TEST AND FAILS IN TEXT DOWNLOAD
// LSRS n, n, #7 // 80h Bit 7 TXE: Transmit data register empty
// THIS IS ___ AND WORKS IN TEXT DOWNLOAD
LSRS n, n, #8 // 100h Bit 8 ORIG
BCC txRDY? // Ready
BX w // lr - SUBR RETURN
// XOFF_SUBR:
#ifdef XON_XOFF
SECTION .text : CODE (2)
XOFF_SUBR:
MOV w, lr // Allow for interrupts to use LR
LDR n,= USART3_DR
LDR y, = XOFF_CHAR
STRB y, [n]
BX w // lr - SUBR RETURN
#endif // XON_XOFF
// XON_SUBR:
#ifdef XON_XOFF
SECTION .text : CODE (2)
XON_SUBR:
MOV w, lr // Allow for interrupts to use LR
LDR n,= USART3_DR
LDR y, = XON_CHAR // preserve TOS 11 24 01 49
STRB y, [n]
BX w //lr // SUBR RETURN
#endif // XON_XOFF
#endif // IO2TP
LTORG
// BL BLANK: ( -- n )
// Push ascii space character as n to TOS.
SECTION .text : CONST (2)
BLANK_NFA:
DC8 0x82
DC8 'B'
DC8 'L'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 EXEC_NFA
BLANK:
DC32 DOCON, 0x20
//========================= START SYSTEM VARIABLES ===========================//
// _SV IS cfa label of WORD's that return their address.
// MODIFIED ALL to be label based vs. offset based.
// UP UP_SV: ( -- addr of UP ) Value stored here is ALIGNED
// A system variable, the RAM VAR pointer, which contains
// the address of the next free memory above in the USERRAMSPACE.
// The value may be read by .UV and altered by VAR.
SECTION .text : CONST (2)
UP_NFA:
DC8 0x82
DC8 'U'
DC8 'P'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 BLANK_NFA
UP_SV:
DC32 DOCON, UP
// FENCE FENCE_SV: ( -- addr of FENCE )
// A system variable containing an address below which FORGET ting is
// trapped. To forget below this point the system must alter the contents
// of FENCE.
SECTION .text : CONST (2)
FENCE_NFA:
DC8 0x85
DC8 'FENC'
DC8 'E'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 UP_NFA
FENCE_SV:
DC32 DOCON, FENCE
// DP DP_SV: ( -- addr of DP ) Value stored here is ALIGNED
// A system variable, the dictionary pointer, which contains the address
// of the next free memory above the dictionary. The value may be read
// by HERE and altered by COMMA (ALIGNED) , ALLOT and CALLOT (UNALIGNED) .
SECTION .text : CONST (2)
DP_NFA:
DC8 0x82
DC8 'D'
DC8 'P'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 FENCE_NFA
DP_SV:
DC32 DOCON, DP
// BASE BASE_SV: ( -- addr of NBASE )
// A system variable containing the current number base used for input
// and output conversion.
SECTION .text : CONST (2)
BASE_NFA:
DC8 0x84
DC8 'BAS'
DC8 'E'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 DP_NFA
BASE_SV:
DC32 DOCON, NBASE
// CURRENT CURRENT_SV: ( -- addr of CURRENT )
// CURRENT searched everytime. CONTEXT is not used
// Used by Create, Definitions, etc and by Latest
// to leave the nfa of the topmost word in the CURRENT
// vocabulary. See LATEST NOTE:(FIG) CURR @ @ this CURR @
SECTION .text : CONST (2)
CURRENT_NFA:
DC8 0x87
DC8 'CURREN'
DC8 'T'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 BASE_NFA
CURRENT_SV:
DC32 DOCON, CURRENT // LATEST = CURRENT_SV -> MOST RECENT DEF NFA
// STATE STATE_SV: ( -- addr of CSTATE )
// A system variable containing the compilation state. A non-zero value
// indicates compilation. The value itself may be implementation
// dependent. 0xC0 must be used for INTERPRET to execute IMMEDIATE words.
SECTION .text : CONST (2)
STATE_NFA:
DC8 0x85
DC8 'STAT'
DC8 'E'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 CURRENT_NFA
STATE_SV:
DC32 DOCON, CSTATE //Compile STATE
// OUT OUT_SV: ( -- addr of OUT )
// A system variable that contains a value incremented by EMIT. The system
// may alter and examine OUT to control display formating.
SECTION .text : CONST (2)
OUT_NFA:
DC8 0x83
DC8 'OU'
DC8 'T'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 STATE_NFA
OUT_SV:
DC32 DOCON, OUT
// IN IN_SV: ( -- addr of IN )
// A system variable containing the byte offset within (TIB),
// from which the tokens are parsed by WORD and moved to HERE,
// as a counted null terminated string (created by EXPECT).
// Initialized to 1 to skip count byte produced by EXPECT.
SECTION .text : CONST (2)
IN_NFA:
DC8 0x82
DC8 'I'
DC8 'N'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 OUT_NFA
IN_SV:
DC32 DOCON, IN
// PAD PAD_SV: ( -- addr of PAD )
// Leave the address of the text output buffer PAD on the stack.
// Typically at least 82 bytes long.
SECTION .text : CONST (2)
PAD_NFA:
DC8 0x83
DC8 'PA'
DC8 'D'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 IN_NFA
PAD_SV:
DC32 DOCON, PAD
// TIB TIB_SV: ( -- addr of INITTIB )
// Leave the address of the text input buffer TIB on the stack.
// Typically at least 82 bytes long.
SECTION .text : CONST (2)
TIB_NFA:
DC8 0x83
DC8 'TI'
DC8 'B'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 PAD_NFA
TIB_SV:
DC32 DOCON, TIB
//======================== END SYSTEM VARIABLES ==============================//
// HERE HERE: ( -- addr ) Value stored here is ALIGNED
// Leave the address of the next available dictionary location.
SECTION .text : CONST (2)
HERE_NFA:
DC8 0x84
DC8 'HER'
DC8 'E'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 TIB_NFA
HERE:
DC32 DOCOL
DC32 DP_SV
DC32 AT
DC32 SEMIS
// ALLOT ALLOT: ( sn -- ) Warning: UNALIGNED:
// IF DICTIONAIRY FULL PRINT error MESSAGE AND abort.
// Add the signed number to the dictionary pointer DP. May be used to
// reserve dictionary space or re-origin memory.
// CAUTION!
// ALLOT and C, (CCOMMA:) ARE THE ONLY WORDS THAT CAN ALLOT UNEVEN AMOUNTS
// NOTE: USE ALIGN32_DP_FF_PAD after ALLOT or C, (CCOMMA) .
SECTION .text : CONST (2)
ALLOT_NFA:
DC8 0x85
DC8 'ALLO'
DC8 'T'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 HERE_NFA
ALLOT:
DC32 DOCOL
DC32 DICTSPACE // \ -- n
DC32 OVER, SUBB
DC32 ZLESS
DC32 ZBRAN
DC32 ALLOTOK-.
DC32 DICTFULL_ABORT
ALLOTOK:
DC32 DP_SV
DC32 PSTORE
DC32 SEMIS
// ALIGNED ALIGNED: ( addr -- a-addr ) DPANS94
SECTION .text : CONST (2)
ALIGNED_NFA:
DC8 0x87
DC8 'ALIGNE'
DC8 'D'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 ALLOT_NFA
ALIGNED:
DC32 .+5
SECTION .text : CODE (2)
POP2t
ADDS t, t, #3
LDR n, =-4
ANDS t, t, n
TPUSH
LTORG
// ALIGN32_DP_FF_PAD ALIGN: ( -- ) DPANS94
// Align DP_SV primitive. Pads current DP with 0xFF until aligned.
// USED IN , (COMMA:) . Reflected by HERE .
// CAUTION! USE AFTER ALLOT or C, (CCOMMA:) .
// See , (COMMA:) which is ALIGNED.
SECTION .text : CONST (2)
ALIGN_NFA:
DC8 0x85
DC8 'ALIG'
DC8 'N'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 ALIGNED_NFA
ALIGN:
ALIGN32_DP_FF_PAD:
DC32 DOCOL
DC32 HERE
// COULD ADD CODE TO SEE IF ALIGNED ALREADY
DC32 THREE, PLUS // 3PLUS
DC32 DUP, TOR
DC32 HERE
DC32 XDO
ALIGN_PAD_DO:
DC32 LIT, 0xFF, I, CSTORE
DC32 XLOOP
DC32 ALIGN_PAD_DO-.
DC32 RFROM
DC32 LIT, 0xFFFFFFFC // -4
DC32 ANDD
DC32 DP_SV, STORE
DC32 SEMIS
// , COMMA: ( n -- ) ALIGNED
// IF DICTIONAIRY FULL PRINT Error MESSAGE AND Abort.
// Write n into next ALIGNED dictionary memory cell, DP reflected by HERE
SECTION .text : CONST (2)
COMMA_NFA:
DC8 0x81
DC8 ','+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 ALIGN_NFA
COMMA:
DC32 DOCOL
DC32 DICTSPACE // \ -- n
DC32 ZLESS
DC32 ZBRAN
DC32 COMMA_OK-.
DC32 DICTFULL_ABORT
COMMA_OK:
DC32 COMMA_PRIM
DC32 SEMIS
// C, CCOMMA: ( n -- ) Warning: UNALIGNED:
// IF DICTIONAIRY FULL PRINT Error MESSAGE AND Abort.
// Store LS 8 bits of n into the next available dictionary byte, advancing
// the dictionary pointer.
// CAUTION!
// ALLOT and C, (CCOMMA:) ARE THE ONLY WORDS THAT CAN ALLOT UNEVEN AMOUNTS
// NOTE: USE ALIGN32_DP_FF_PAD after ALLOT or C, (CCOMMA) .
// See , (COMMA:) which is ALIGNED.
SECTION .text : CONST (2)
CCOMMA_NFA:
DC8 0x82
DC8 'C'
DC8 ','+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 COMMA_NFA
CCOMMA:
DC32 DOCOL
DC32 DICTSPACE // \ -- n
DC32 ZLESS
DC32 ZBRAN
DC32 CCOMMA_OK-.
DC32 DICTFULL_ABORT
CCOMMA_OK:
DC32 HERE
DC32 CSTORE
DC32 ONE
DC32 ALLOT_PRIM
DC32 SEMIS
// VARALLOT VARALLOT: ( n -- addr ) Value stored here is ALIGNED
// IF USERVAR SPACE FULL PRINT Error MESSAGE AND Abort.
// Add n * 32 bits to the RAMVARSPACE pointer UP.
// Used to allocate space in Ram for VAR's and other system data structures
SECTION .text : CONST (2)
VARALLOT_NFA:
DC8 0x88
DC8 'VARALLO'
DC8 'T'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 CCOMMA_NFA
VARALLOT:
DC32 DOCOL
DC32 VARSPACE // \ -- n
DC32 FOUR, SLASH, OVER, SUBB
DC32 ZLESS
DC32 ZBRAN
DC32 VALLOT_OK-.
DC32 LIT, msg_uvfull
DC32 NULLSTRLEN, TYPE
#ifdef IO2TP
//VARALLOT_BP1:
// DC32 NOOP
DC32 CLRPAD // Resets OUT
#endif
DC32 ABORT
VALLOT_OK:
DC32 UP_SV, AT // Address of this allotment
DC32 SWAP // n
DC32 FOUR, STAR // n = 4 bytes
DC32 UP_SV
DC32 PSTORE // Address of next var available
DC32 SEMIS
// LATEST LATEST: ( -- nfa )
// Initially ADDR OF LAST WORD IN THE DICTIONARY
// Leave the nfa of the topmost word in the dictionary.
SECTION .text : CONST (2)
LATEST_NFA:
DC8 0x86
DC8 'LATES'
DC8 'T'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 VARALLOT_NFA
LATEST:
DC32 DOCOL
DC32 CURRENT_SV // LATEST = CURRENT_SV
DC32 AT
DC32 SEMIS
// LFA LFA: ( pfa -- lfa )
// Convert the parameter field address of a dictionary definition to
// its link field address.
SECTION .text : CONST (2)
LFA_NFA:
DC8 0x83
DC8 'LF'
DC8 'A'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 LATEST_NFA
LFA:
DC32 .+5
SECTION .text : CODE (2)
POP2t
SUBS t, t, #8
TPUSH
// CFA CFA: ( pfa -- cfa )
// Convert the parameter field address of a dictionary definition to
// its code field address. <if thumb2 execution addr smudged>
SECTION .text : CONST (2)
CFA_NFA:
DC8 0x83
DC8 'CF'
DC8 'A'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 LFA_NFA
CFA:
DC32 .+5
SECTION .text : CODE (2)
POP2t
SUBS t, t, #4
TPUSH
// NFA NFA: ( pfa -- nfa )
// Convert the parameter field address of a definition to its name
// field. Modified for nfa alighnment padding
SECTION .text : CONST (2)
NFA_NFA:
DC8 0x83
DC8 'NF'
DC8 'A'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 CFA_NFA
NFA:
DC32 DOCOL
DC32 EIGHT, SUBB // Addr OF lfa, DUPED TO TRAVERSE Padding
NFA_ALIGN_BEGIN:
DC32 ONE, SUBB // ADDR 1 BEFORE lfa, eliminate padding
DC32 DUP, CAT // ALIGNROM FF padded?
DC32 LIT, 0xFF, SUBB
DC32 ZBRAN // UNTIL
DC32 NFA_ALIGN_BEGIN-.
DC32 LIT,-1 // DIRECTION FOR TRAVERSE = Toward nfa
DC32 TRAVERSE // \ -- addr2
DC32 SEMIS
// PFA PFA: ( nfa -- pfa )
// Convert the name field address of a compiled definition to its
// parameter field address.
SECTION .text : CONST (2)
PFA_NFA:
DC8 0x83
DC8 'PF'
DC8 'A'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 NFA_NFA
PFA:
DC32 DOCOL // \ NFA --
DC32 ONE // DIRECTION FOR TRAVERSE = Toward CFA
DC32 TRAVERSE // \ NFA 1 -- addr2
PFA_ALIGN_BEGIN:
DC32 ONEP // ADDR 1 BEFORE lfa, eliminate padding
DC32 DUP, CAT // ALIGNROM FF padded?
DC32 LIT, 0xFF, SUBB
DC32 ZBRAN // UNTIL
DC32 PFA_ALIGN_BEGIN-.
DC32 EIGHT
DC32 PLUS
DC32 SEMIS
// ?ALIGNED QALIGNED: ( value -- )
// If value not aligned by 4 issue message and ABORT.
SECTION .text : CONST (2)
QALIGNED_NFA:
DC8 0x88
DC8 '?ALIGNE'
DC8 'D'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 PFA_NFA
QALIGNED:
DC32 DOCOL
DC32 LIT, 3, ANDD
DC32 ZBRAN //IF no err leave
DC32 QALIGN_OK-.
DC32 PDOTQ
DC8 46
DC8 'VALUE MUST BE EVEN NOT ODD AND MULTIPLE OF 4! '
ALIGNROM 2,0xFFFFFFFF
DC32 ABORT
QALIGN_OK:
DC32 SEMIS
// ?ERROR QERROR: ( f nullstr -- )
// If f NON ZERO type error message (nullstr) and ABORT.
SECTION .text : CONST (2)
QERROR_NFA:
DC8 0x86
DC8 '?ERRO'
DC8 'R'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 QALIGNED_NFA
QERROR:
DC32 DOCOL
DC32 SWAP
DC32 ZBRAN //IF no err leave
DC32 QERROR_FINISH-.
DC32 ERROR // \ nullstr-addr --- ABORT's
DC32 BRAN //ELSE
DC32 QERROR_DONE-.
QERROR_FINISH:
DC32 DROP //endif
QERROR_DONE:
DC32 SEMIS
// DIGIT DIGIT: ( c base -- digit 1 ) (ok)
// ( c base -- 0 (bad)
// Converts the ascii character c using base to its binary
// equivalent digit, accompanied by a true flag. If the conversion is
// invalid, leaves only a false flag.
SECTION .text : CONST (2)
DIGIT_NFA:
DC8 0x85
DC8 'DIGI'
DC8 'T'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 QERROR_NFA
DIGIT:
DC32 .+5
SECTION .text : CODE (2)
POP2w // Number base
POP2t // ASCII DIGIT
SUBS t, t, #'0'
BMI DIGI2 // Number error
CMP t, #9
BLE DIGI1 // Number = 0 THRU 9
// Combine?
SUBS t, t, #7
CMP t, #10 // Number 'A' THRU 'Z'?
BLT DIGI2 // NO
DIGI1:
CMP t, w // COMPARE Number TO base
BGE DIGI2
MOV w, t // NEW BINARY Number
MOVS t, #1 // TRUE FLAG
DPUSH
// Number error
DIGI2:
MOVS t, #0 // FALSE FLAG
TPUSH
// ENCLOSE ENCL: ( addr1 c -- addr1 n1 n2 n3 )
// A text scanning iterative primitive used only in WORD.
// IN is used before and after callS for the iteration
// Typically TIB + IN = addr1
// noop EX: \ TIB 32 -- TIB 0 4 5
// NULL EX: \ TIB 32 -- ADDR-B4-NULL 0 1 1 So DFIND CAN FIND IT!
// NULL EX: \ WORD/ENCL -> TIB 1, 0, 20'S
// From the text address addr1 and an ascii delimiting character c,
// is determined the byte offset to the first non-delimiter character n1,
// the offset to the first delimiter after the text n2,
// and the offset to the first character not included.
// This procedure will not process past an ASCII 'null', treating it
// as an unconditional delimiter. NULL termination by EXPECT in QUERY.
SECTION .text : CONST (2)
ENCL_NFA:
DC8 0x87
DC8 'ENCLOS'
DC8 'E'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 DIGIT_NFA
ENCL:
DC32 .+5
SECTION .text : CODE (2)
POP2t // TERMINATOR CHAR
LDR n, [p] // get text address but leave on stack
MOVS w, #0
SUBS w, w, #1 // CHAR COUNTER
SUBS n, n, #1 // ADDR -1
// SCAN TO FIRST NON-TERMINATOR CHARACTER
// and PUSH count to stack leaving last 2 params to compute
ENCL1:
ADDS n, n, #1 // ADDR+1
ADDS w, w, #1 // COUNT+1
LDRB x, [n]
CMP t, x //CMP AL,[BX]
BEQ ENCL1 //JZ ENCL1 // WAIT FOR NON-TERMINATOR
PUSHw //offset to the first non-delimiter character
//EXiT is now only DPUSH
CMP x, #0 //CMP AH,[BX] // null CHAR?
BNE ENCL2 //JNZ ENCL2 // NO
// FOUND null BEFORE 1ST NON-TERM CHAR
// RETURN ok args = NULL EX//
// \ TIB 32 -- ADDR-B4-NULL 0 1 1 So DFIND CAN FIND IT!
//
MOV t, x
ADDS w, w, #1 // w = offset to the delimiter after the text
DPUSH
// FOUND FIRST TEXT CHAR - COUNT THE CHARS
ENCL2:
ADDS n, n, #1 // ADDR+1
ADDS w, w, #1 //COUNT+1
LDRB x, [n]
CMP t, x //TERMINATOR CHAR?
BEQ ENCL4 //YES
CMP x, #0 //null CHAR?
BNE ENCL2 //NO, LOOP AGAIN
ENCL3: // FOUND null AT END OF TEXT
ENCL4: // FOUND TERMINATOR CHARACTER
MOV t, w // COUNT+1 =
ADDS t, t, #1 // offset to the first character not included
DPUSH
// 0 NULL: ( -- ) IMMEDIATE
// Don't return to Interpret, return to Quit at end of a line of input.
// Executed at end of TIB when QUERY lenght or CR entered.
SECTION .text : CONST (2)
NULL_NFA:
DC8 0x0C1 // A BINARY ZER
DC8 0x80
ALIGNROM 2,0xFFFFFFFF
DC32 ENCL_NFA
NULL:
// DC32 SEMIS // Actual Semis code below
DC32 .+5
SECTION .text : CODE (2)
POPr2i // pop docol saved IP from Rstack
NEXT
// WORD WORD: ( c -- )
// Parse the text in TIB , until a delimiter c is found, tokenizing input.
// Move the token to HERE, with a count byte and 2 nulls at the end.
// Leading occurrences of c are ignored. IN is incremented.
// See IN. Usually used inside a definition.
SECTION .text : CONST (2)
WORD_NFA:
DC8 0x84
DC8 'WOR'
DC8 'D'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 NULL_NFA
WORD:
DC32 DOCOL
WORD1:
// This is required for number suffix's at least ???
// NOT WITH NEW COUNTED NULL STRING EXPECT
// DC32 HERE, LIT, MAXWORDLEN+2, BLANKS
DC32 TIB_SV
WORD2:
DC32 IN_SV
DC32 AT
DC32 PLUS
DC32 SWAP // ( TIB+IN CH-DELIM -- )
DC32 ENCL // ( TIB+IN 32 -- TIB+IN 0 4 5 )
WENCL:
DC32 IN_SV // encl TOS = end of word offset to be added to IN
DC32 PSTORE // TIB+IN 0 4
DC32 OVER //
DC32 SUBB // Char cnt going to R and HERE
DC32 TOR
DC32 R
DC32 HERE
DC32 CSTORE // CHAR CNT OF word
DC32 PLUS
DC32 HERE
DC32 ONEP
// DC32 RFROM
// MOVE word TO DICT FOR finding ENDING WITH NULLS
DC32 R
DC32 CMOVE // ( from to count -- )
// add null to end of token - NUMBER adjusted
DC32 ZERO, HERE, ONEP, RFROM, PLUS, CSTORE
#ifdef IOBUFS_DEBUG
DC32 HERE, ONE, DUMP
#endif
DC32 SEMIS
// NUMBER NUMBER: ( addr -- sd )
// If error print message and ABORT.
// Convert a character string left at addr with a preceeding count,
// and a terminating null, to a signed number, in the current numeric base.
// If a decimal point is encountered in the text, its position will be
// given in DPL, but no other effect occurs. If numeric conversion is
// not possible, an error message will be given.
SECTION .text : CONST (2)
NUMBER_NFA:
DC8 0x86
DC8 'NUMBE'
DC8 'R'+0x80
ALIGNROM 2,0xFFFFFFFF
DC32 WORD_NFA
NUMBER:
DC32 DOCOL
DC32 BASE_TO_R12 // Save current BASE
DC32 NUMBERSUFFIX
DC32 ZERO, ZERO
DC32 ROT // ( 0 0 addr -- )
DC32 DUP, ONEP // ( 0 0 addr addr+1 -- )
DC32 CAT // ( 0 0 addr 1rstchar -- )
DC32 LIT, '-' // Minus sign = 0x2D
// ( 0 0 addr 1rstchar 0x2D --- )
DC32 EQUAL // ( 0 0 addr f -- )
#ifdef TRUE_EQU_NEG_ONE // FIX ASSUMPTION THIS FLAG WILL BE ONE!
DC32 ONE, ANDD // ( 0 0 addr f -- ) FLAG IS ONE OR ZERO
#endif
DC32 DUP, TOR // ( 0 0 addr f -- ) copy of f >R
DC32 PLUS // ASSUMPTION FLAG WILL BE 1 or 0
DC32 LIT, -1
NUMB1: // Begin
DC32 DPL_SV, STORE
DC32 PNUMBER // ( 0 0 addr -- ud=(LSW MSW) ADDR=PAST#)
// END OF NUMBER CHARACTER CHECK HERE
DC32 DUP
DC32 CAT
// Convert from space to NULL terminated string fix here
// DC32 BLANK //20h
DC32 ZERO
DC32 SUBB
// while
DC32 ZBRAN // IF NULL (WAS BLANK)
DC32 NUMB2-. // DONE UNLESS IT NEEDS TO BE NEGATED
DC32 DUP
DC32 CAT
DC32 LIT, '.' // 2EH period
DC32 SUBB
NUMERRTEST:
// IF zero (NOT GOING TO ERROR) LEAVE BASE ALONE FOR LOOP!
// consumed flag here so provide true flag if you don't
// DC32 DUP
DC32 ZBRAN
DC32 NOBRESTOR-.
// GOING TO ERROR SO RESTORE BASE!
DC32 BASE_FROM_R12 // Restore BASE
//NOBRESTOR:
DC32 ONE // provide non zero flag for error
DC32 LIT, msg_number_error
DC32 QERROR // ( f nullstr-addr -- ) IF f TRUE EXECUTE ERROR!
NOBRESTOR: // Reset DPL to zero
DC32 ZERO
DC32 BRAN
DC32 NUMB1-.
NUMB2:
DC32 DROP
DC32 RFROM // FLAG OF "-" TEST
// IF
DC32 ZBRAN
DC32 NUMB3-.
DC32 DNEGATE
NUMB3: // endif
DC32 BASE_FROM_R12 // Restore BASE
DC32 SEMIS
// ERROR ERROR: ( nullstr --- )
// Execute error notification and restart of system.
// IN_SV is saved to assist in determining the location of the error.
SECTION .text : CONST (2)
ERROR_NFA:
DC8 0x85
DC8 'ERRO'
DC8 'R'+0x80
ALIGNROM 2,0xFFFFFFFF
// DC32 DFIND_NFA
DC32 NUMBER_NFA
ERROR:
DC32 DOCOL
DC32 HERE, COUNT, TYPE // Offending item
DC32 NULLSTRLEN, TYPE // Passed in null string
#ifdef IO2TP
ERROR_BP1:
DC32 NOOP // View error message
DC32 CLRPAD // Resets OUT
#endif
#ifdef XON_XOFF
DC32 XOFF // TEMP TEST THRE
#endif
// DO THIS WHERE STATE IS SET BACK TO ZERO
DC32 STATE_SV, AT
DC32 ZBRAN
DC32 CREATED_OK-.
// NON-ZERO CSDP = RESTORE DP TO forget DAMAGED WORDS
DC32 CSDP_SV, AT // Create saves dp here for if word exists err
DC32 ZBRAN
DC32 CREATED_OK-.
// assume ITS A CREATE'd WORD!!!!
ERROR_FIXUP: // CSDP_SV contains NFA of definition that has error.
DC32 CSDP_SV, AT // SHOULD BE AT NFA!!