forked from Howerd/colorForth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cf2023Ref.img_2023Jan31_172433.f
3345 lines (2929 loc) · 117 KB
/
cf2023Ref.img_2023Jan31_172433.f
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
\ C:\Users\User\Dropbox\colorForth\cf2023\cf2023Ref.img converted by colorForthScan V1.0 2023 Jan 29
\ File MD5 = E00E8D2DFC237E4F041110AD9B55851C pecans-cuffs
\ MagentaV is the colorForth Magenta Variable
: MagentaV ( initial -- ) create , ; \ Runtime: ( -- a )
\ Block 64
( colorforth cf2022 2023 Jan 31 )
( processor clock ) #4 MagentaV mhz
( dump ) #74732 MagentaV x #1088 MagentaV y ( ld ) #80 MagentaV lblk
#2 #12 +thru
: dump #78 load ;
: words #112 ld ;
: icons #80 ld ;
: serve #506 ld ;
: north #92 ld ;
: rtc #96 ld ;
: lan #98 ld ;
: colors #102 ld ;
: wood #106 ld ;
: mand #108 ld ;
: sound #114 ld ;
: gr #118 ld ;
: eth #176 ld ;
: life #272 ld ;
: ed #252 ld ;
: slime #246 ld ;
: int #288 ld ;
: xx #278 load ;
: info ver dump ;
: staks #504 ld ;
( hardware ) #0 MagentaV rng
: chm ( -- ) #0 mhz ! $1740 x ! #0 y ! #64 lblk ! $00010000
: ch ( n-- ) #64 block swap md5 dump ;
: hlp randq rng ! logo pause calkhz
onesec @ #1000 / mhz ! e ;
mark empty hlp
( Press the * key to see the comment block )
( Press F1 )
\ Block 65
\ ( Based on colorforth 2001 Jul 31 by Chuck Moore )
\ ( released into the Public Domain. )
\ ( This block is loaded at power up. Press F1 for help )
\ : dump ( instant compile version of DUMP )
\ : icons ( edit the character font icons )
\ : north ( North Bridge PCI chip display )
\ : rtc ( Real Time Clock display )
\ : colors ( 3-axis rgb colour display )
\ : wood ( imitation pine blockboard )
\ : mand ( display the Mandeldrot set )
\ : sound ( control the PC speaker )
\ : gr ( graphics - type ok to run the demo )
\ : life ( Conways game of life )
\ : ed ( the editor partly converted to colorforth )
\ : slime ( watch out for the slugs! )
\ : int ( 1000 Hz timer interrupt )
\ : xx ( colorforth explorer )
\ : ch ( show MD5 of n bytes starting at block 64 )
\ : chm ( show MD5 of system blocks )
\ : help ( press the space bar to leave the editor, then type the keys indicated in the keypad in the bottom right of the
\ screen, then the space bar to execute the word. Type ) e ( or ) #64 edit ( to run the editor. )
\ info ( to view the boot system version )
\ seeb ( to toggle display of blue words )
\ hlp ( shows help and clock speed )
\ Block 66
macro
: ?f $C021 2, ;
: 0if $75 2, here ;
: +if $78 2, here ;
: 1+ ( n-n ) $40 1, ;
: 1- ( n-n ) $48 1, ;
: 2/ ( n-n ) $F8D1 2, ;
: time ( -u ) qdup $310F 2, ;
: shl ( uc-u ) ?lit $E0C1 2, 1, ;
: shr ( uc-u ) ?lit $E8C1 2, 1, ;
: r@ qdup $8B 1, $C7 1, ;
: sti $FB 1, ; ( enable interrupts )
: cli $FA 1, ; ( disable interrupts ) forth
: cli cli ;
: sti sti ;
: nul ;
: time time ;
\ Block 67
\ ( Pentium macros: )
\ : ?f ( set flags to reflect tos )
\ : 0if ( if zero ... then jnz aids in clarity )
\ : +if ( js, this complements the set )
\ : 1- ( subtract 1 )
\ : 2/ ( divide by 2 )
\ : qdup ( is the new name for ?dup )
\ : time ( return Pentium instruction counter )
\ : lshift ( shift u left c places )
\ : rshift ( shift u right c places )
\ : r@ ( copies the top of the return stack to TOS )
\ : sti ( enable device interrupts )
\ : cli ( disable them )
\ : a,
\ Block 68
( more macros ) macro
: swap $168B 2, $C28B0689 , ;
: 0 qdup $C031 2, ;
: if $74 2, here ;
: -if $79 2, here ;
: a qdup $C28B 2, ;
: a! ?lit if $BA 1, , ; then $D08B 2, drop ;
: 1@ $8A 2, ;
: 1! a! $0288 2, drop ;
: p@ ( a-n ) qdup a! $EC 1, ;
: p! ( na- ) a! $EE 1, drop ;
: 2* $E0D1 2, ;
: a, , ;
: @ ?lit if qdup $058B 2, , ; then $8B 2, 0 , ;
: ! ?lit if ?lit if $05C7 2, swap , , ; then $0589 2, , drop ; then a! $0289 2, 0 , drop ;
: nip $0004768D 3, ;
: + ?lit if $05 1, , ; then $0603 2, nip ;
: xor $0633
: binary ?lit if swap #2 + 1, , ; then 2, nip ;
: and $0623 binary ;
: or $060B binary ;
: u+ ?lit if $0681 2, , ; then $00044601 3, drop ;
: ? ?lit $A9 1, , ;
\ Block 69
\ ( Pentium macros: 1, 2, 3, , compile 1-4 bytes )
\ : drop ( lodsd, flags unchanged, why sp is in ESI )
\ : over ( sp 4 + @ )
\ : swap ( sp xchg )
\ : 0 ( 0 0 xor, macro 0 identical to number 0 )
\ : a ( 2 0 mov, never used? )
\ : a! ( 0 2 mov, unoptimized )
\ : 1@ ( fetch byte from byte address )
\ : 1! ( store byte to byte address )
\ : p@ p-n ( fetch byte from port )
\ : p! np ( store byte to port )
\ : @ ( EAX 4 *, unoptimized )
\ : ! ( EDX 4 * )
\ : nop ( used to thwart look-back optimization )
\ : - ( ones-complement )
\ : 2*
\ : 2/
\ : if ( jz, flags set, max 127 bytes, leave address )
\ : -if ( jns, same )
\ : then ( fix address - in kernel )
\ : push ( EAX push )
\ : pop ( EAX pop )
\ : u+ ( add to 2nd number, literal or value )
\ : ? ( test bits, set flags, literal only! )
\ Block 70
( even more macros )
: over qdup $0004468B 3, ;
: push $50 1, drop ;
: pop qdup $58 1, ;
: invert ( n-n ) $D0F7 2, ;
: for push begin ;
: *next swap
: next $75240CFF
: 0next , here invert + 1, $0004C483 3, ;
: -next $79240CFF 0next ;
: i qdup $0024048B 3, ;
: *end swap
: end $EB 1, here invert + 1, ;
: +! ?lit if ?lit if $0581 2, swap , , ; then $0501 2, , drop ; then a! $0201 2, drop ;
: nop $90 1, ;
: align here invert #3 and drop if nop align ; then ;
: or! a! $00950409 3, 0 , drop ;
: * $0006AF0F 3, nip ;
: */ $C88B 2, drop $F9F72EF7 , nip ;
: /mod swap $99 1, $16893EF7 , ;
: / /mod nip ;
: mod /mod drop ;
\ Block 71
\
\ : - n-n ( ones complement negate , xor )
\ : for n ( push count onto return stack, falls into ) begin
\ : begin -a ( current code address - byte )
\ : *next aa-aa ( swap ) for ( and ) if ( addresses )
\ : next a ( decrement count, jnz to ) for, ( pop return stack when done )
\ : -next a ( same, jns - loop includes 0 )
\ : i -n ( copy loop index to data stack )
\ : end a ( jmp to ) begin
\ : +! na ( add to memory, 2 literals optimized )
\ : align ( next call to end on word boundary )
\ : or! na ( inclusive-or to memory, unoptimized )
\ : * mm-p ( 32-bit product )
\ : */ mnd-q ( 64-bit product, then quotient )
\ : /mod nd-rq ( remainder and quotient )
\ : / nd-q ( quotient )
\ : mod nd-r ( remainder )
\ : time -n ( Pentium cycle counter, calibrate to get actual clock rate )
\ Block 72
( Compiled macros ) forth
: r@ ( -n ) r@ ;
: @ ( a-n ) @ ;
: ! ( an- ) ! ;
: + ( nn-n ) + ;
: 1+ ( u--u ) 1+ ;
: 1- ( u--u ) 1- ;
: invert ( n-n ) invert ;
: */ ( nnn-n ) */ ;
: * ( nn-n ) * ;
: / ( nn-n ) / ;
: 2* ( n-n ) 2* ;
: 2/ ( n-n ) 2/ ;
: dup ( n-nn ) dup ;
: swap ( nn-nn ) swap ;
: over over ;
( Arithmetic )
: negate ( n-n ) invert #1 + ;
: - ( nn-n ) negate + ;
: min ( nn-n ) less if drop ; then swap drop ;
: abs ( n-u ) dup negate
: max ( nn-n ) less if swap then drop ;
: v+ ( vv-v ) push u+ pop + ;
: save sss ;
: sa sss e ;
\ Block 73
\ ( These macros may be ) yellow, ( others may not )
\ : block n-a ( block number to word address )
\ : r@ ( copies the top of the return stack to stack )
\ : @ etc ( Arithmetic )
\ : negate n-n ( when you just cant use ) -
\ : min nn-n ( minimum )
\ : abs n-u ( absolute value )
\ : max nn-n ( maximum )
\ : v+ vv-v ( add 2-vectors )
\ : save ( write colorforth to a bootable USB drive )
\ : sa ( save, then show edit screen )
\ Block 74
( Relative load blocks )
: ll ( -- ) blk @ load ;
: sect ( --asn ) blk @ block blk @ 2* #2 ;
: ss ( -- ) sect writes drop drop ;
: uu ( -- ) sect reads drop drop ;
: ld ( n- ) dup lblk ! load ;
: vv ( -- ) lblk @ edit ;
: help ( -- ) lblk @ #1 + edit ;
( Real Time Clock )
: rtc@ ( t-c ) $70 p! $71 p@ ;
: rtc! ( ct- ) $70 p! $71 p! ;
: hi ( -- ) #10 rtc@ $80 and drop 0if hi ; then ;
: lo ( -- ) #10 rtc@ $80 and drop if lo ; then ;
: calkhz ( -- ) hi lo counter hi lo counter swap -
dup onesec ! #1 rshift #250 + #500 / dup khz ! ;
: ms ( n- ) khz @ * counter + begin pause dup counter
invert + drop -if drop ; then end drop ;
: secs ( n- ) for pause lo hi next ; macro
: swapb ( w-w ) $E086 2, ; forth
: split ( w--cc ) dup swapb $FF and swap $FF and ;
\ Block 75
\
\ : nload ( loads the next source block : b+2 )
\ : +load ( loads the source block : b+n )
\ : blk ( where the current blk happens to be kept )
\ : ll ( load the current edit blk )
\ : ss ( save the sector containing the current edit block to the floppy disc )
\ : lblk ( holds the last block loaded by )
\ : ld
\ : vv ( edits the last block loaded by ld )
\ : rtc@ reg-n ( fetch reg from rtc )
\ : rtc! n reg- ( store in rtc register )
\ : hi ( wait till Update In Progress bit is high )
\ : lo ( wait till UIP bit is low )
\ : calkhz ( calibrate the processor clock using the RTC )
\ : ms ( wait for n milliseconds )
\ : secs ( wait for n seconds )
\ : swapb ( swap the two low bytes )
\ : split ( split the low two bytes )
\ : vframe ( byte address of the video frame buffer )
\ Block 76
( Colors etc )
: white $00FFFFFF rgb color ; : red $00FF0000 rgb color ;
: green $FF00 rgb color ; : blue $FF rgb color ;
: silver $00BFBFBF rgb color ; : yellow $FFE0 color ;
: orange $00E04000 rgb color ; : black $00 rgb color ;
: 5* #5 for 2emit next ;
: cf #25 dup at red $72 $6F $6C $6F $63 5* green $68 $74 $72 $6F $46 5* ;
: logo show black screen #800 #710 blue box #600 #50 at #1024 #620 red box #200 #100 at #700 #500 green box text cf keypa d ;
: noshow show keypad ;
: lshift ( uc-u ) $1F and ?f 0if drop ; then for #1 shl next ;
: rshift ( uc-u ) $1F and ?f 0if drop ; then for #1 shr next ;
: rand32 ( -n ) time dup #16 lshift xor ;
: string pop ;
: 1@ ( a-c ) 1@ $0F and ;
: 1! ( ac- ) 1! ;
\ Block 77
\
\ : colors ( specified as rgb: 888 )
\ : screen ( fills screen with current color )
\ : at xy ( set current screen position )
\ : box xy ( lower-right of colored rectangle )
\ : 5* ( displays 5 large characters )
\ : cf ( displays ) colorforth
\ : logo ( displays colorforth logo )
\ : empty ( also displays the logo )
\ : lshift ( shift u left c places )
\ : rshift ( shift u right c places )
\ : show ( background task executes following code repeatedly )
\ : keyboard ( displays keypad and stack )
\ : string ( returns the address of the string following )
\ : rand32 ( returns a 3 bit random number )
\ Block 78
( Dump names )
: .cell ( a-a ) orange dup @ #4 for dup $FF and emit $0100 / next drop white ;
: one dup dup @ dup push h. space dup h. pop space swap .cell drop space space space space dup dotsf drop white cr ;
: lines for one #4 + next drop ;
: dump ( a- ) $0FFFFFFC and x !
: r show black screen x @ #16 text lines cr x @ #16 for .cell #4 + next drop keypad ;
: it @ + @ dup h. space ;
: lines for white i x it i y it xor drop if red then i . cr -next ;
: cmp show blue screen text #19 lines red x @ h. space y @ h. keypad ;
: u $40
: +xy dup x +! y +! ;
: d $FFFFFFC0 +xy ;
: ati $F4100000 ( ff7fc000 ) xor
: byte #4 / dump ;
: fix for #0 over ! #1 + next ; dump
\ Block 79
\ ( Does not say empty, compiles on top of application )
\ : x -a ( current address )
\ : one a-a ( line of display )
\ : lines an
\ : dump a ( background task continually displays memory : decodes the value as a name and ASCII )
\ : u ( increment address )
\ : d ( decrement )
\ : ati ( address of AGP graphic registers )
\ : byte a ( byte address dump )
\ : fix an-a ( test word )
\ : ver ( show the kernel version information )
\ : cmp ( shows data at both ) x ( and ) y ( addresses )
\ Block 80
( App: Icons font editor ) empty
( icon number ) #28 MagentaV ic ( cursor ) #367 MagentaV cu
macro : @w $8B66 3, ; : !w a! $00028966 3, drop ;
: *byte $C486 2, ; forth
: sq xy @ $00010000 /mod #16 + swap #16 + box #17 #0 +at ;
: loc ic @ $FF and
: tofont ( n--a ) #16 #24 #8 */ * font @ + ;
: 0/1 $8000 ? if green sq ; then blue sq ;
: row dup @w *byte #16 for 0/1 2* next drop #-17 #16 * #17 +at ;
: cpl #32 ;
: showall ( -- ) #2 lm iconw cpl * rm ic @ cpl /mod iconh * #448 #2 - + swap iconw * swap over over at red #16 #4 + u+ #24
+ #4 + box white
#0 #2 #448 at #256 for dup emit #1 + next drop ;
: ikon loc #24 for row #2 + next drop ;
: adj #17 * swap ;
: cursor cu @ #16 /mod adj adj over over at red #52 u+ #52 + box ;
: ok show page cursor #18 dup at ikon text blue #400 #400 at ef #416 #424 box #400 #400 at white ef ic @ dup emit space
dup green . $30 emit $78 emit #2 h.n showall keypad ;
: fcopy tofont swap tofont swap #16 #24 #8 */ cmove ;
nload ok h
\ Block 81
\ ( Draw big-bits icon )
\ : @w a-n ( fetch 16-bit word from byte address )
\ : !w na ( store same )
\ : *byte n-n ( swap bytes )
\ : ic -a ( current icon )
\ : cu -a ( cursor )
\ : sq ( draw small square )
\ : xy -a ( current screen position, set by ) at
\ : loc -a ( location of current icons bit-map )
\ : 0/1 n-n ( color square depending on bit 15 )
\ : row a-a ( draw row of icon )
\ : +at nn ( relative change to screen position )
\ : ikon ( draw big-bits icon )
\ : adj nn-nn ( magnify cursor position )
\ : cursor ( draw red box for cursor )
\ : ok ( background task to continually draw icon, icon number at bottom )
\ Block 82
( Edit icon )
: icmv ( n-- ) ic @ + $FF and ic ! ;
: +ic #1 icmv ;
: -ic #-1 icmv ;
: ++ic cpl icmv ;
: --ic cpl negate icmv ;
: bit cu @ 2/ 2/ 2/ 2/ 2* loc + $00010000 cu @ $0F and #1 + for 2/ next *byte ;
: toggle bit over @w xor swap !w ;
: td toggle
: d #16
: wrap cu @ + #16 #24 * dup u+ /mod drop cu ! ;
: tu toggle
: u #-16 wrap ;
: tr toggle
: r #1 wrap ;
: tl toggle
: l #-1 wrap ;
: nul ;
: h keypd
nul nul quit nul tl tu td tr
l u d r -ic --ic ++ic +ic
nul nul nul nul nul nul nul toggle
nul nul nul nul
$2500 , $13121110 dup , , $2B16152D , #0 , $80000000 , #0 ,
\ Block 83
\ ( Edit icon )
\ : t ( toggles the current pixel )
\ : ludr ( left up down right )
\ : . ( top row toggles and moves )
\ : -+ ( select icon to edit )
\ Block 84
( Print PNG to disk ) #1024 MagentaV w #768 MagentaV h #1 MagentaV d
#6 +load #4 +load #2 +load
: -crc ( a ) here over negate + crc . ;
: crc -crc ;
: wd ( -a ) here #3 and drop if #0 1, wd ; then here #2 2/s ;
: bys ( n-a ) . here swap , ;
: plte $45544C50 #48 bys $00 3, $00FF0000 3, $FF00 3, $00FFFF00 3, $FF 3, $00FF00FF 3, $FFFF 3, $00FFFFFF 3, $00 3, $00C00000
3, $C000 3, $00C0C000 3, $C0 3, $00C000C0 3, $C0C0 3, $00C0C0C0 3, crc ;
: png ( awh ) d @ / h ! d @ / w ! wd swap $474E5089 , $0A1A0A0D , ( ihdr ) $52444849 #13 bys w @ . h @ . $0304 , $00 1, crc
plte ( idat ) $54414449 #0 bys swap deflate crc ( iend ) $444E4549 #0 bys crc wd over negate + ;
: at #1024 * + 2* vframe + ;
: full #4 d ! #0 dup at #1024 #768 png ;
: pad #1 d ! #46 #-9 + #22 * nop #25 #-4 + #30 * at #9 #22 * nop #4 #30 * png ;
: go #1 d ! #1024 w ! #768 h ! #0 #0 at #1024 #768 png raw ; go e
\ Block 85
\ ( Print PNG to disk )
\ : frame ( the video frame buffer )
\ : -crc ( a )
\ : crc
\ : wd ( -a )
\ : bys ( n-a )
\ : plte
\ : png ( awh )
\ : at
\ : full
\ : pad
\ : go ( copy the screen image as a PNG file to the floppy disk block 270 and up. )
\ Block 86
( lz77 ) macro
: @w $8B66 3, ;
: *byte $C486 2, ;
: !b a! $0289 2, drop ; forth
: *bys dup #16 2/s *byte swap $FFFF and *byte $00010000 * + ;
: . *bys , ;
: +or over invert and or ;
: 0/1 $10 ? if $1E and $1E or drop if #7 ; then $0F ; then #0 and ;
: 4b dup 0/1 #9 and over #6 2/s 0/1 $0A and +or swap #11 2/s 0/1 $0C and +or $08 or ;
: pix dup @w d @ 2* u+ 4b ;
: row 1, dup w @ 2/ dup #1 + dup 2, invert 2, #0 dup 1, +adl for pix #16 * push pix pop or dup 1, +adl next drop +mod d @
#1024 #2 * * + ;
: deflate $0178 2, #1 #0 adl! h @ #-1 + for #0 row next #1 row drop ad2 @ *byte 2, ad1 @ *byte 2, here over #4 + negate +
*bys over #-4 + !b ;
\ Block 88
( Crc ) macro
: 2/s ?lit $E8C1 2, 1, ;
: 1@ $8A 2, ; forth #36054 MagentaV ad1 #54347 MagentaV ad2
: array ( -a ) pop #2 2/s ;
: bit ( n-n ) #1 ? if #1 2/s $EDB88320 or ; then #1 2/s ;
: fill ( nn ) for dup #8 for bit next , #1 + next drop ;
: table ( -a ) align array #0 #256 fill
: crc ( an-n ) #-1 swap for over 1@ over or $FF and table + @ swap #8 2/s or #1 u+ next invert nip ;
: +adl ( n ) $FF and ad1 @ + dup ad2 @ +
: adl! ad2 ! ad1 ! ;
: +mod ad1 @ #65521 mod ad2 @ #65521 mod adl! ;
\ Block 90
( DOS file )
: blks #256 * ;
: w/c #18 blks ;
: buffer block ;
: size ( -a ) buffer #0 #1 reads buffer $098F + ;
: set ( n ) ! buffer s #1 writes ;
: cyls ( n-nn ) #1 swap w/c #-1 + + w/c / ;
: put ( an ) dup 2* 2* size set cyls writes /flop ;
: raw ( an- ) #15 swap 2* 2* w/c #-1 + + w/c / writes /flop ;
: get ( a ) size @ #3 + 2/ 2/ cyls reads /flop ;
: .com #0 #63 blocks put ;
\ Block 91
\
\ : blks n-n ( size in blocks to words )
\ : w/c -n ( words per cylinder )
\ : buffer -a ( 1 cylinder required for floppy dma )
\ : size -a ( locate size of 2nd file. Floppy has first FILLER then FILE allocated. FILLER is 2048 bytes, to fill out cylind
\er 0. Names at most 8 letters, all caps. Directory starts at ) buffer $0980 +
\ : set n ( size. FILE must be larger than your file. )
\ : cyls n-nn ( starting cylinder 1 and number of cylinders )
\ : raw an ( write raw data to cyl 15 , block 270 )
\ : put an ( write file from address )
\ : get a ( read file to address )
\ Block 92
( App: North Bridge ) empty macro
: 4@ dup $ED 1, ;
: 4! $EF 1, drop ; forth #2048 MagentaV dev
: nb $00 dev ! ;
: sb $3800 dev ! ;
: agp $0800 dev ! ;
: ess $6800 dev ! ;
: ric $7800 dev ! ;
: win $8000 dev ! ;
: ati $00010000 dev ! ;
: add $0CF8 a! 4! $0CFC a! ;
: q $80000000 + add 4@ ;
: en $8004 q #-4 and xor 4! ;
: dv dup $0800 * q swap #1 + ;
: regs dev @ #19 #4 * + #20 for dup q h. space dup h. cr #-4 + next drop ;
: devs #0 #33 for dup q dup #1 + drop if dup h. space drop dup #8 + q dup h. space over h. cr then drop $0800 + next drop
;
: ok show black screen text regs keypad ;
: ko show black screen text devs keypad ;
: u $40 dev +! ;
: d #-64 dev +! ;
: test $FF00 + a! 4@ ; ok
\ Block 93
\ ( Display the PCI interface chip registers )
\ Block 94
( ASCII )
: cf-ii string ( 0*00 ) $6F747200 , $696E6165 , $79636D73 , $7766676C , ( 0*10 ) $62707664 , $71757868 , $33323130 , $37363534
, ( 0*20 ) $2D6A3938 , $2F7A2E6B , $2B213A3B , $3F2C2A40 , ( 0*30 ) $4F545200 ,
: ch $FFFFFFF0 and unpack cf-ii + 1@ $FF and ;
: ii-cf string ( 0x20 ) $64632A00 , $7271706F , $2B2D6E6D , $2725232E , ( 0x30 3210 ) $1B1A1918 , ( 7654 ) $1F1E1D1C , ( ..98
) $28292120 , $2F6C6B6A , ( 0x40 CBA@ ) $3A43352C , ( GFED ) $3D3E3440 , ( KJIH ) $54523744 , ( ONML ) $3336393C , ( 0x50
SRQP ) $38314742 , ( WVUT ) $3F414632 , ( .ZYX ) $58563B45 , $75745973 , ( 0x60 cba. ) $0A130576 , ( gfed ) $0D0E0410 , ( kjih
) $24220714 , ( onml ) $0306090C , ( 0x70 srqp ) $08011712 , ( wvut ) $0F111602 , ( .zyx ) $77260B15 , $62617879 ,
: chc $FFFFFFE0 + ii-cf + 1@ $FF and ;
: tst #2000 block dup #4 * #-1 + $60 for $01 + $80 i negate + over 1! next drop dump ; #51 MagentaV qch
: rr ( c-c ) qch ! $20 $60 for $01 + dup chc qch @ negate + drop 0if pop drop ; then next $7F and ;
\ Block 95
\ ( Convert colorforth chars to and from ASCII )
\ : cf-ii ( conversion table )
\ : ch ( convert colorforth character to ASCII )
\ : ii-cf ( conversion table )
\ : chc ( convert ASCII to colorforth )
\ : tst ( create a table of ASCII characters )
\ : r ( scan the ii-cf table to perform cf-ii . Used to cross-reference the two tables )
\ : info ( display the ASCII version information in the last 64 bytes of block 11 . Type u to see more . )
\ ( dump takes a byte address )
\ Block 96
( App: RTC Real Time Clock ) empty
: bcd ( -c ) rtc@ #16 /mod #10 * + ;
: hms ( -n ) lo #4 bcd #100 * #2 bcd + #100 * #0 bcd + ; s
: ymd ( -n ) lo #9 bcd #2000 + #100 * #8 bcd + #100 * #7 bcd + ;
: day ( -c ) lo #6 bcd ;
: crlf ( Port Dump )
: one ( n-n ) space yellow dup rtc@ h.2 blue space dup . cr ;
: lines ( sn- ) for one #-1 + next drop ;
: ok show page text cr #15 #16 lines white cr ymd .
hms . day . keypad ;
: h
keypd nul nul quit nul nul nul nul
nul nul nul nul nul nul nul nul
nul nul nul nul nul nul nul nul
nul nul nul nul nul
$00250000 , #0 , #0 , #0 , #0 , #0 , #0 ,
ok
\ Block 97
\ ( RTC Real Time Clock )
\ : . ( displays the PC clock registers )
\ : bcd bcd-n ( bcd to binary )
\ : hms -n ( hours+mins+secs )
\ : ymd -n ( year+month+day )
\ : day -n ( day of the week )
\ : rtc ( display the Real Time Clock registers )
\ : one ( display one line )
\ : lines ( display n lines starting at s )
\ : ok ( display task )
\ Block 98
( LAN ) empty $03F8 nload init
: no block #4 * #1024 ;
: send no for dup 1@ xmit #1 + next drop ;
: receive no for rcv over 1! #1 + next drop ;
: no #18 #7 #18 * ;
: backup no for dup send #1 + next drop ;
: accept no for dup receive #1 + next drop ;
\ Block 99
\
\ Block 100
( Serial 3f8 2e8 1050 ) macro
: 1@ $8A 2, ;
: 1! a! $0288 2, drop ; forth
: r #0 + + ;
: 9600 #12 ;
: 38400 #3 ;
: 115200 #1 ;
: b/s $83 #3 r p! 38400 #0 r p! #0 #1 r p! #3 #3 r p! ;
: init b/s ( 16550 ) #1 #2 r p! #0 #4 r p! ;
: xmit ( n ) #5 r p@ $20 and drop if #0 r p! ; then pause xmit ;
: cts #6 r p@ $30 and $30 xor drop if cts ; then xmit ;
: st #6 r p@
: xbits $30 and $10 / dup #1 and 2* 2* + 2/ ;
: st! #4 r p! ;
: ?rcv #5 r p@ #1 and drop if #0 r p@ then ;
: rcv ?rcv if ; then pause rcv ; lblk @ edit
\ Block 101
\
\ : 1@ a-n ( fetch byte from byte address )
\ : 1! na ( store byte to byte address )
\ : r n-p ( convert relative to absolute port address. Base port on stack at compile time. Compiled as literal at yellow
\-green transition )
\ : 9600
\ : 115200 ( baud-rate divisors. These are names, not numbers )
\ : b/s ( set baud rate. Edit to change )
\ : init ( initialize uart )
\ : xmit n ( wait for ready and transmit byte )
\ : cts n ( wait for clear-to-send then xmit )
\ : st -n ( fetch status byte )
\ : xbits n-n ( exchange status bits )
\ : st! n ( store control byte )
\ : ?rcv ( fetch byte if ready. Set flag to be tested by ) if
\ : rcv -n ( wait for ready and fetch byte )
\ Block 102
( App: Colors ) empty
#4210752 MagentaV col #4210752 MagentaV del
: lin dup 2/ 2/ dup 2* line ;
: hex xy @ #7 and over 2/ for lin #7 + next over for lin next swap 2/ for #-7 + lin next drop ;
: +del del @ nop
: petal and col @ + $00F8F8F8 and rgb color #100 hex ;
: -del del @ $00F8F8F8 xor $00080808 + ;
: rose #0 +del #-176 #-200 +at $00F80000 -del petal #352 #-200 +at $00F80000 +del #-264 #-349 +at $F800 -del petal #176 #-200
+at $F8 +del #-176 #98 +at $F8 -del petal #176 #-200 +at $F800 +del ;
: ok show page #512 #282 at rose text col @ h. space del @ $FF and h. keypad ; nload ok h e
\ Block 103
\ ( Draws 7 hexagons. Colors differ along red, green and blue axes. )
\ : col ( color of center hexagon )
\ : del ( color difference )
\ : lin n ( draws 1 horizontal line of a hexagon )
\ : hex n ( draws top, center and bottom. Slope 7 x to 4 y is 1.750 compared to 1.732 )
\ : +del n ( increment color )
\ : -del n
\ : petal n ( draw colored hexagon )
\ : rose ( draw 7 hexagons )
\ : ok ( describe screen. Center color at top )
\ Block 104
( Colors keypad )
: in del @ 2* $00404040 min del ! ;
: out del @ 2/ $00080808 max del ! ;
: r $00F80000
: +del del @
: +col and col @ + $00F8F8F8 and col ! ;
: g $F800 +del ;
: b $F8 +del ;
: -r $00F80000 -del +col ;
: -g $F800 -del +col ;
: -b $F8 -del +col ;
: nul ;
: h keypd nul nul quit nul -r -g -b nul r g b nul out nul nul in nul nul nul nul nul nul nul nul nul nul nul nul $00250000
, $00626772 dup , , $2B00002D , #0 , #0 , #0 ,
\ Block 105
\
\ : in ( increment color difference )
\ : out ( decrement it )
\ : r
\ : g
\ : b ( increment center color )
\ : -r
\ : -g
\ : -b ( decrement it )
\ : +del ( redefine with ; )
\ : +col ( change center color )
\ : nul ( ignore )
\ : h ( describe keypad )
\ Block 106
( App: Wood ) empty #125810090 MagentaV x #-1123891786 MagentaV y
#8286477 MagentaV inc #33554432 MagentaV frame #39 MagentaV dep #65056 MagentaV hole
: h0 #400000 inc ! #15 dep !
: home inc @ scrnw #2 / * negate x s ! inc @ scrnh #2 / * y ! ; macro
: f* $2EF7 2, #26 shr $E2C1 2, #6 1, $C20B 2, nip ;
: w! a! $00028966 3, drop ; forth
: wf+ frame @ w! #2 frame +! ;
: om negate $FF + ;
: o5 om $03 shr $07E0 xor ;
: o4 $FC and #3 shl $1F xor ;
: o3 om $F8 and #8 shl $1F xor ;
: o2 #3 shr $F800 xor ;
: o1 om $FC and #3 shl $F800 xor ;
: o0 $F8 and #8 shl $07E0 xor ;
: order jump o0 o1 o2 o3 o4 o5 o0
: hue #8 shl #26 / dup $FF and swap #8 shr order ;
: vlen dup f* swap dup f* + ;
: vdup over over ;
: vndp push push vdup pop pop ;
: itr over dup f* over dup f* negate + push f* 2* pop swap v+ over 2* + 2/ vndp + + ;
: data ; #4 +load ok draw h
\ Block 107
\ ( Display an imitation pine blockboard screen )
\
\ ( This is based on a skewed Mandelbrot set with )
\ ( modified colors )
\ Block 108
( App: Mandelbrot Set ) empty
#-204800000 MagentaV x #153600000 MagentaV y #400000 MagentaV inc
#34 MagentaV dep #33554432 MagentaV frame #0 MagentaV hole
: h0 #400000 inc ! #34 dep !
: home inc @ scrnw #2 / * negate x s ! inc @ scrnh #2 / * y ! ; macro
: f* $2EF7 2, #26 shr $E2C1 2, #6 1, $C20B 2, nip ;
: w! a! $00028966 3, drop ; forth
: wf+ frame @ w! #2 frame +! ;
: hue ( n-n ) #8191 * ; dup dup + dup dup + + + dup dup + dup dup ef + + ; #3142 * ; @ ; ef
: vlen dup f* swap dup f* + ;
: vdup over over ;
: vndp push push vdup pop pop ;
: itr over dup f* over dup f* negate + push f* 2* pop swap v+ ;
: x: ( c- ) emit $3D emit ;
: data text #0 #0 at $78 x: x @ . $79 x: y @ . $69 x: inc @ . $64 x: dep @ . ; nload ok draw h
\ Block 109
\
\ Block 110
( Mandelbrot Set )
: o 0 0 dep @ #1 max for vndp itr vdup vlen $F0000000 + drop -if *next drop drop hole @ ; then drop drop pop hue ;
: mh x @ swap scrnw for o wf+ inc @ u+ next nip ;
: mv y @ scrnh for mh inc @ negate + next drop ;
: +d #2 dep +! : -d #-1 dep +! dep @ #1 max dep !
: draw vframe frame ! mv data ;
: ok c show keypad ;
: l inc @ scrnw #1 - #8 */ negate x +! draw ;
: u inc @ scrnh #1 - #8 */ y +! draw ;
: d inc @ scrnh #1 - #8 */ negate y +! draw ;
: r inc @ scrnw #1 - #8 */ x +! draw ;
: +z inc @ #3 max dup scrnw #1 - #8 */ x +! dup scrnh #1 - #8 */ negate y +! #3 #4 */ #3 max inc ! draw ;
: -z inc @ #10000000 min dup scrnw #1 - #8 */ negate x +! dup scrnh #1 - #8 */ y +! #4 #3 */ inc ! draw ;
: hh home draw ; : hh2 h0 draw ;
: h keypd nul nul quit nul -d nul nul +d l u d r -z hh hh2 +z nul nul nul nul nul nul nul nul nul nul nul nul $2500 , $2B00002D
, $13121110 , $2B30482D , #0 , #0 , #0 ,
\ Block 111
\ ( More Mandelbrot )
\ ( ludr move the cursor left right up down )
\ ( - + top row change depth detail )
\ ( - + bottom row change zoom )
\ ( h centres the image to the home location )
\ ( 0 resets depth and zoom )
\ Block 112
( App: words )
#74796 MagentaV from
#10315920 MagentaV tobl
#16 MagentaV num
#10010 MagentaV blkn
: tost ( u-- ) tobl @ ! #4 tobl +! ;
: tb $25C7C00E tost ; ( blue tab token )
: docr $9080000E tost ; ( blue cr token )
: setbl ( u-- ) blkn ! blkn @ block dup #1024 erase tobl ! #0 num ! ;
: newblk blkn @ #2 + setbl ;
: one ( -- ) from @ @ $FFFFFFF0 and $09 or tost tb #4 from +! #1 num +! ;
: chk1 num @ #6 mod #0 + 0if docr then drop ;
: chk2 num @ #96 mod #0 + 0if newblk then drop ;
: ww ( -- ) #10000 setbl
( FORTH ) $B189640B tost docr
ftha from ! fthn @ for one chk1 chk2 next
( MACRO ) newblk $8AC84C0B tost docr
maca from ! macn @ for one chk1 chk2 next
( BLUE ) newblk $C74CC80B tost docr
blua from ! blun @ for one chk1 chk2 next
#10000 edit ; ww
\ Block 113
\
\ Block 114
( App: Sounds make a noise ) empty
#25 MagentaV tempo #0 MagentaV mute #2259 MagentaV period
: tn ( ft- ) tempo @ * swap #660 #50 */
: hz ( tf- ) push #1000 #1193 pop */
: osc ( tp- ) dup period ! split $42 p! $42 p!
: tone ( t- ) mute @ #0 + drop if drop ; then $4F $61 p! ms $4D $61 p! #20 ms ;
: click #1 #90 osc ;
: t #3 tn ;
: q #8 tn ;
: c #16 tn ;
: 2tone #75 q #50 q ;
: h1 #50 c #54 q #50 q #45 c #60 c ;
: h2 #40 c #45 q #50 q #50 c #45 c ;
: h3 #54 c #60 q #54 q #50 c #45 q #40 q #50 t #45 t #50 t #45 t #45 #12 tn #40 q #40 #32 tn ;
: hh
: handel h1 h2 h3 ;
: piano #55 #7 for dup q #3 #2 */ next drop ;
: cetk #6 c #10 c #8 c #4 c #6 #32 tn ;
: bomb mute @ #0 + drop if ; then $4F $61 p! #500 for #1000 i invert + split $42 p! $42 p! #1 ms next $4D $61 p! #1 #32 tn
; handel
\ Block 115
\ ( Sounds : using the PC internal speaker )
\ : tempo ( in ms per 1/8 quaver )
\ : mute ( equals -1 to disable sound )
\ : period ( test only - value sent to hardware )
\ : tn ( ft- play f Hz for t * 11 ms )
\ : hz ( tf- play t ms at f Hz )
\ : osc ( tp- play t ms of period p )
\ : tone ( t- play the current tone for t ms )
\ : click ( makes a click )
\ : t ( triplet )
\ : q ( quaver )
\ : c ( crotchet )
\ : 2tone ( 2 tones )
\ : h1
\ : h2
\ : h3
\ : hh
\ : handel ( part of Handels Gavotte )
\ : piano
\ : cetk ( Close Encounters of the Third Kind )
\ : bomb ( - well sort of .... )
\ Block 116
( Colourblind Editor Display )
#1 MagentaV state $01 MagentaV state*
: +txt white $6D emit space ;
: -txt white $6E emit space ;
: +imm yellow $58 emit space ;
: -imm yellow $59 emit space ;
: +mvar yellow $09 emit $11 emit $05 emit $01 emit space ;
: txts string $03010100 , $07060504 , $09090901 , $0F0E0D0C , ( ; )
: tx ( c-c ) $0F and txts + 1@ $0F and ;
: .new state @ $0F and jump nul +imm nul nul nul nul nul nul nul +txt nul nul +mvar nul nul nul ;
: .old state* @ $0F and jump nul -imm nul nul nul nul nul nul nul -txt nul nul nul nul nul nul ;
here
: cb ( n-n ) #0 + 0if ; then tx
state @ swap dup state ! - drop if .old .new
state @ #0 + if dup state* ! then then ;
: cbs ( -- here ) #0 + $00 + cblind ! ;
\ Block 117
\
\ : state
\ : cb ( acts on a change of token type. It ignores extension tokens )
\ Block 118
( Graphics demo Todo: fix this! ) empty
#2 #22 +thru
: htm #116 load ( html ) ;
log1
\ Block 119
\ ( A graphics extension package )
\ : . ( Type ) ok ( after loading this block )
\ Block 120
( added macros ) forth
: mfill #24 for cr space #5 for rand32 h. space next next ;
: matrix show black screen green mfill keypad ;
\ Block 121
\ ( added macros )
\ : 1+ ( increment tos )
\ : 1- ( decrement tos )
\ : @b ( fetch byte from absolute addr. )
\ : @w ( fetch word from absolute addr. )
\ : @l ( fetch long from absolute addr. )
\ : !b ( store byte in absolute addr. )
\ : !w ( store word in absolute addr. )
\ : !l ( store long in absolute addr. )
\ : matrix ( What is the Matrix? )
\ : ver ( returns the address of the CFDOS version - use as ) ver dump
\ Block 122
( Stack juggling + misc. )
: v- ( v-v ) push invert 1+ u+ pop invert 1+ + ;
: vn push rot less if rot pop -rot ; then -rot pop ; #2222 MagentaV pen #236986408 MagentaV bs
: vloc ( xy-a ) scrnw 2* * over + + vframe + ;
macro
: @w $8B66 3, ;
: !w a! $00028966 3, drop ;
forth
: point ( xy- ) pen @ swap w! ;
: at? ( -xy ) xy @ $00010000 /mod swap ;
: @r ( a-a ) 1+ dup #4 u+ @ + ;
: !r ( aa- ) 1+ dup push negate #-4 + + pop ! ;
: select ( an- ) #5 * over + @r swap @r !r ;
\ Block 123
\ ( Stack juggling words. small and fast. )
\ : addr -a ( absolute address )
\ : rot abc-bca ( stack pictures are best .. )
\ : -rot abc-cab ( ..described with letters, in )
\ : tuck ab-bab ( ..this case. )
\ : 2swap abxy-xyab
\ : 2over abxy-abxyab
\ : 2dup ab-abab
\ : v- v1v2 - v1-v2 ( vector subtract. )
\ : vn vv-vv ( sort vectors so x1 is less x2 )
\ : vframe -addr ( address of screen. )
\ : pen -addr ( current color. )
\ : bs -addr ( base for elements )
\ : vloc xy-a ( convert xy into addr. )
\ : point xy- ( set point at xy to current pen. )
\ : at? -xy ( return current screen location. )
\ : @r a-a ( get absolute addr from jump/call )
\ : !r aa- ( set jump/call to absolute addr. )
\ : select an- ( select call n from table a. Store it in table call 0 )
\ Block 124
( new logo )
: .co $72 $6F $6C $6F $63 5* ;
: .fo $68 $74 $72 $6F $46 5* ;
: cf #27 dup at silver .co .fo #25 dup at red .co green .fo ;
: log1 show black screen text cf keypad ;
: ckb black #0 #740 at #1023 #767 box #800 #650 at #1023 #740 box ;
: grads #0 #128 for i 2* 1- rgb color dup #10 at #5 + dup #120 box next
iconw #21 * - #128 for #257 i 2* negate + dup #256 * + rgb color dup #10 at #5 + dup #100 box next drop ;
\ Block 125
\ ( New logo )
\ : log1 ( a simple text demo )
\ : ok ( the graphics demo )
\ Block 126
( Circles ) #-16977 MagentaV c-cd #0 MagentaV c-ff
: point4 #4096 * swap #4 * 2dup + 2/ negate bs @ + pen @ over w! over push + pen @ over w! + pen @ over w! pop negate + pen
@ swap w! ;
: opnts 2dup point4 2dup swap point4 ;
: d? c-cd @ ?f drop -if ; then dup invert c-cd +! 1- #1 c-ff ! ;
: cfl 1+ 1+ push pen @ swap pop 2/ for over over w! 1+ 1+ next drop drop ;