-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCOLOR.ASM
More file actions
1577 lines (1440 loc) · 31.1 KB
/
COLOR.ASM
File metadata and controls
1577 lines (1440 loc) · 31.1 KB
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
;colorForth, 2001 Jul 22, Chuck Moore, Public Domain
.MODEL tiny
.486p
only SEGMENT USE32
ASSUME DS:only
next MACRO adr
dec ECX
jnz adr
ENDM
DUP_ MACRO
lea ESI, [ESI-4]
mov [ESI], EAX
ENDM
DROP MACRO
lodsd
ENDM
;hp equ 800
;vp equ 600
;vesa equ 114h
hp equ 1024 ; "horizontal pixels"
vp equ 768 ; "vertical pixels"
vesa equ 117h ; VESA mode #
buffer equ 604*256
include boot.asm ; boot boot0 hard
; 100000 dictionary
; a0000 top of return stack
; 9f800 top of data stack
; 9d800 free
; 97000 floppy buffer
; 4800 source
icons equ 12*256*4 ; 3000
; 7c00 BIOS boot sector
; 0 Forth
warm: DUP_
start1: call ATI0
; mov screen, offset nul
; xor EAX, EAX
call show0
mov forths, (forth1-forth0)/4
mov macros, (macro1-macro0)/4
mov EAX, 18
call LOAD
jmp ACCEPT
Gods equ 28000h*4 ; 0A0000h
Godd equ Gods-750*4
mains equ Godd-1500*4
maind equ mains-750*4
ALIGN 4
me dd offset God
screen dd 0 ; logo
ROUND: call unPAUSE
God dd 0 ; Gods-2*4
call unPAUSE
main dd 0 ; mains-2*4
jmp ROUND
PAUSE: DUP_
push ESI
mov EAX, me
mov [EAX], ESP
add EAX, 4
jmp EAX
unPAUSE: pop EAX
mov ESP, [EAX]
mov me, EAX
pop ESI
DROP
ret
ACT: mov EDX, maind-4
mov [EDX], EAX
mov EAX, mains-4
pop [EAX]
sub EAX, 4
mov [EAX], EDX
mov main, EAX
DROP
ret
show0: call show
ret
show: pop screen
DUP_
xor EAX, EAX
call ACT
@@: call graphic
call [screen]
call SWITCH
inc EAX
jmp @b
c_: mov ESI, Godd+4
ret
mark: mov ECX, macros
mov mk, ECX
mov ECX, forths
mov mk+4, ECX
mov ECX, H
mov mk+2*4, ECX
ret
empty: mov ECX, mk+2*4
mov H, ECX
mov ECX, mk+4
mov forths, ECX
mov ECX, mk
mov macros, ECX
mov class, 0
ret
mFIND: mov ECX, macros
push EDI
lea EDI, [macro0-4+ECX*4]
jmp @f
FIND: mov ECX, forths
push EDI
lea EDI, [forth0-4+ECX*4]
@@: std
repne scasd
cld
pop EDI
ret
EX1: dec words ; from keyboard
jz @f
DROP
jmp EX1
@@: call FIND
jnz ABORT1
DROP
jmp [forth2+ECX*4]
execute: mov lit, offset alit
DUP_
mov EAX, [-4+EDI*4]
ex2: and EAX, -20o
call FIND
jnz ABORT
DROP
jmp [forth2+ECX*4]
ABORT: mov curs, EDI
shr EDI, 10-2
mov blk, EDI
ABORT1: mov ESP, Gods
; reset the behavor of the (some of the?) spaces
mov spaces+3*4, offset forthd
mov spaces+4*4, offset qcompile
mov spaces+5*4, offset cnum
mov spaces+6*4, offset cshort
mov EAX, 57o ; ?
call ECHO_
jmp ACCEPT
; set whether defining (red) should call macrod or forthd
; note that the words MACRO_ and FORTH are placed immediately before macrod
; and forthd, respectively
sDEFINE: pop aDEFINE ; previous RIP
ret
MACRO_: call sDEFINE
macrod: mov ECX, macros
inc macros
lea ECX, [macro0+ECX*4]
jmp @f
FORTH: call sDEFINE
forthd: mov ECX, forths
inc forths
lea ECX, [forth0+ECX*4]
@@: mov EDX, [-4+EDI*4]
and EDX, -20o
mov [ECX], EDX
mov EDX, h
mov [forth2-forth0+ECX], EDX
lea EDX, [forth2-forth0+ECX]
shr EDX, 2
mov last, EDX
mov list, ESP
mov lit, offset adup
test class, -1
jz @f
jmp [class]
@@: ret
cdrop: mov EDX, h
mov list, EDX
mov byte ptr [EDX], 0adh ; lodsd
inc h
ret
qdup: mov EDX, h
dec EDX
cmp list, EDX
jnz cdup
cmp byte ptr [EDX], 0adh
jnz cdup
mov h, EDX
ret
cdup: mov EDX, h
mov dword ptr [EDX], 89fc768dh
mov byte ptr [4+EDX], 06
add h, 5
ret
adup: DUP_
ret
var1: DUP_
mov EAX, [4+forth0+ECX*4]
ret
variable: call forthd
mov [forth2-forth0+ECX], offset var1
inc forths ; dummy entry for source address
mov [4+ECX], EDI
call macrod
mov [forth2-forth0+ECX], offset @f
inc macros
mov [4+ECX], EDI
inc EDI
ret
@@: call [lit]
mov EAX, [4+macro0+ECX*4]
jmp @f
cNUM: call [lit]
mov EAX, [EDI*4]
inc EDI
jmp @f
cSHORT: call [lit]
mov EAX, [-4+EDI*4]
sar EAX, 5
@@: call literal
DROP
ret
alit: mov lit, offset adup
literal: call qDUP
mov EDX, list
mov list+4, EDX
mov EDX, h
mov list, EDX
mov byte ptr [EDX], 0b8h
mov [1+EDX], EAX
add h, 5
ret
qCOMPILE: call [lit]
mov EAX, [-4+EDI*4]
and EAX, -20o
call mFIND
jnz @f
DROP
jmp [macro2+ECX*4]
@@: call FIND
mov EAX, [forth2+ECX*4]
@@: jnz ABORT
call_: mov EDX, h
mov list, EDX
mov byte ptr [EDX], 0e8h
add EDX, 5
sub EAX, EDX
mov [-4+EDX], EAX
mov h, EDX
DROP
ret
COMPILE: call [lit]
mov EAX, [-4+EDI*4]
and EAX, -20o
call mFIND
mov EAX, [macro2+ECX*4]
jmp @b
SHORT_: mov lit, offset alit
DUP_
mov EAX, [-4+EDI*4]
sar EAX, 5
ret
NUM: mov lit, offset alit
DUP_
mov EAX, [EDI*4]
inc EDI
ret
comma: mov ECX, 4
@@: mov EDX, h
mov [EDX], EAX
mov EAX, [ESI] ; drop
lea EDX, [EDX+ECX]
lea ESI, [ESI+4]
mov h, EDX
; DROP
ret
comma1: mov ECX, 1
jmp @b
comma2: mov ECX, 2
jmp @b
comma3: mov ECX, 3
jmp @b
semi: mov EDX, h
sub EDX, 5
cmp list, EDX
jnz @f
cmp byte ptr [EDX], 0e8h
jnz @f
inc byte ptr [EDX] ; jmp
ret
@@: mov byte ptr [5+EDX], 0c3h ; ret
inc h
ret
then: mov list, ESP
mov EDX, h
sub EDX, EAX
mov [-1+EAX], DL
DROP
ret
begin: mov list, ESP
here: DUP_
mov EAX, h
ret
qlit: mov EDX, h
lea EDX, [EDX-5]
cmp list, EDX
jnz @f
cmp byte ptr [EDX], 0b8h
jnz @f
DUP_
mov EAX, list+4
mov list, EAX
mov EAX, [1+EDX]
cmp dword ptr [EDX-5], 89fc768dh ; dup
jz q1
mov h, EDX
jmp cdrop
q1: add h, -10 ; flag nz
ret
@@: xor EDX, EDX ; flag z
ret
less: cmp [ESI], EAX
js @f ; flag nz
xor ECX, ECX ; flag z
@@: ret
qIGNORE: test dword ptr [-4+EDI*4], -20o
jnz nul
pop EDI
pop EDI
nul: ret
; holy shit this is wickedly powerful
jump: pop EDX
add EDX, EAX
lea EDX, [5+EAX*4+EDX]
add EDX, [-4+EDX]
DROP
jmp EDX
LOAD: shl EAX, 10-2
push EDI
mov EDI, EAX
DROP
INTER: mov EDX, [EDI*4]
inc EDI
and EDX, 17o
call spaces[EDX*4]
jmp INTER
; this is the main control of what each space should do
ALIGN 4
spaces dd offset qIGNORE, offset execute, offset NUM
aDEFINE dd 5+offset MACRO_ ; offset macrod, sDEFINE sets this
dd offset qCOMPILE, offset cNUM, offset cSHORT, offset COMPILE
dd offset SHORT_, offset nul, offset nul, offset nul
dd offset variable, offset nul, offset nul, offset nul
lit dd offset adup
mk dd 0, 0, 0
H dd 40000h*4
last dd 0
class dd 0
list dd 0, 0
macros dd 0
forths dd 0
;macro0 dd (3 shl 4+1)shl 24 ; or
; dd ((5 shl 4+6)shl 7+140o)shl 17 ; and
; dd 173o shl 25 ; +
macro0 dd 170o shl 25 ; ;
dd ((140o shl 7+146o)shl 7+142o)shl 11 ; dup
dd (((177o shl 7+140o)shl 7+146o)shl 7+142o)shl 4 ; ?dup
dd (((140o shl 4+1)shl 4+3)shl 7+142o)shl 10 ; drop
; dd ((6 shl 4+7)shl 7+142o)shl 17 ; nip
dd (((2 shl 7+144o)shl 4+4)shl 4+6)shl 13 ; then
dd ((((143o shl 4+4)shl 5+25o)shl 4+7)shl 4+6)shl 8 ; begin
macro1 dd 128 dup (0)
forth0 dd (((143o shl 4+3)shl 4+3)shl 4+2)shl 13 ; boot
dd (((27o shl 4+5)shl 4+1)shl 5+21o)shl 14 ; warm
dd ((((142o shl 4+5)shl 7+146o)shl 5+20o)shl 4+4)shl 5 ; pause
dd ((((21o shl 4+5)shl 5+22o)shl 4+1)shl 4+3)shl 10 ; MACRO
dd ((((26o shl 4+3)shl 4+1)shl 4+2)shl 7+144o)shl 8 ; FORTH
dd 22o shl 27 ; c
dd (((20o shl 4+2)shl 4+3)shl 7+142o)shl 12 ; stop
dd (((1 shl 4+4)shl 4+5)shl 7+140o)shl 13 ; read
dd ((((27o shl 4+1)shl 4+7)shl 4+2)shl 4+4)shl 11 ; write
dd (6 shl 5+22o)shl 23 ; nc
dd (((((22o shl 4+3)shl 5+21o)shl 5+21o)shl 4+5)shl 4+6)shl 5; comman d
dd (((20o shl 4+4)shl 4+4)shl 7+164o)shl 12 ; seek
dd ((((1 shl 4+4)shl 4+5)shl 7+140o)shl 5+23o)shl 8 ; ready
; dd (((22o shl 5+24o)shl 4+1)shl 4+7)shl 14 ; clri
dd ((5 shl 5+22o)shl 4+2)shl 19 ; ACT
dd (((20o shl 7+144o)shl 4+3) shl 5+27o)shl 11 ; SHOW
dd (((24o shl 4+3)shl 4+5)shl 7+140o)shl 12 ; LOAD
dd (((144o shl 4+4)shl 4+1)shl 4+4)shl 13 ; here
dd (((177o shl 5+24o)shl 4+7)shl 4+2)shl 12 ; ?lit
dd (153o shl 7+176o) shl 18 ; 3,
dd (152o shl 7+176o) shl 18 ; 2,
dd (151o shl 7+176o) shl 18 ; 1,
dd 176o shl 25 ; ,
dd (((24o shl 4+4)shl 5+20o)shl 5+20o)shl 13 ; less
dd (((162o shl 7+146o)shl 5+21o)shl 7+142o)shl 6 ; jump
dd (((((5 shl 5+22o)shl 5+22o)shl 4+4)shl 7+142o)shl 4+2)shl 3 ; accept
dd ((142o shl 4+5)shl 7+140o)shl 14 ; pad
dd ((((4 shl 4+1)shl 4+5)shl 5+20o)shl 4+4)shl 11 ; erase
dd (((22o shl 4+3)shl 7+142o)shl 5+23o)shl 11 ; copy
dd (((21o shl 4+5)shl 4+1)shl 7+164o)shl 12 ; mark
dd (((4 shl 5+21o)shl 7+142o)shl 4+2)shl 12 ; empt
dd (((4 shl 5+21o)shl 4+7)shl 4+2)shl 15 ; emit
dd ((((140o shl 4+7)shl 5+25o)shl 4+7)shl 4+2)shl 8 ; digit
dd ((((152o shl 4+4)shl 5+21o)shl 4+7)shl 4+2)shl 8 ; 2emit
dd 165o shl 25 ; .
dd (144o shl 7+165o)shl 18 ; h.
dd ((144o shl 7+165o)shl 4+6)shl 14 ; h.n
dd (22o shl 4+1)shl 23 ; CR
dd ((((20o shl 7+142o)shl 4+5)shl 5+22o)shl 4+4)shl 7 ; space
dd (((140o shl 4+3)shl 5+27o)shl 4+6)shl 12 ; DOWN
dd (((4 shl 7+140o)shl 4+7)shl 4+2)shl 13 ; edit
dd 4 shl 28 ; E
; dd (((26o shl 4+3)shl 4+6)shl 4+2)shl 15 ; font
dd (24o shl 5+21o)shl 22 ; lm
dd (1 shl 5+21o)shl 23 ; rm
dd ((((25o shl 4+1)shl 4+5)shl 7+142o)shl 7+144o)shl 5 ; graph ic
dd (((2 shl 4+4)shl 7+145o)shl 4+2)shl 13 ; text
; dd (153o shl 7+140o)shl 18 ; 3d
; dd (((((1 shl 4+4)shl 4+6)shl 7+140o)shl 4+4)shl 4+1)shl 5 ; render
; dd ((((141o shl 4+4)shl 4+1)shl 4+2)shl 4+4)shl 9 ; verte x
; dd ((((26o shl 4+1)shl 4+3)shl 4+6)shl 4+2)shl 11 ; front
; dd ((2 shl 4+3)shl 7+142o)shl 17 ; top
; dd (((20o shl 4+7)shl 7+140o)shl 4+4)shl 12 ; side
dd ((((164o shl 4+4)shl 5+23o)shl 7+143o)shl 4+3)shl 5 ; keybo ard
dd (((140o shl 4+4)shl 7+143o)shl 7+146o)shl 7 ; debu g
dd (5 shl 4+2)shl 24 ; at
dd ((173o shl 4+5)shl 4+2)shl 17 ; +at
dd (145o shl 5+23o)shl 20 ; xy
dd ((26o shl 4+3)shl 7+141o)shl 16 ; fov
dd (((26o shl 4+7)shl 5+26o)shl 4+3)shl 14 ; fifo
dd ((143o shl 4+3)shl 7+145o)shl 14 ; box
dd (((24o shl 4+7)shl 4+6)shl 4+4)shl 15 ; line
dd ((((22o shl 4+3)shl 5+24o)shl 4+3)shl 4+1)shl 10 ; color
; dd (((22o shl 5+24o)shl 4+7)shl 7+142o)shl 11 ; clip
dd (((((3 shl 5+22o)shl 4+2)shl 4+5)shl 4+6)shl 4+2)shl 7 ; octant
dd (20o shl 7+142o)shl 20 ; sp
dd (((24o shl 4+5)shl 5+20o)shl 4+2)shl 14 ; last
dd (((((146o shl 4+6)shl 7+142o)shl 4+5)shl 5+22o))shl 5 ; unpac k
; dd (((142o shl 4+5)shl 5+22o)shl 7+164o)shl 9 ; pack
forth1 dd 512 dup (0)
;macro2 dd offset cOR
; dd offset cAND
; dd offset PLUS
macro2 dd offset semi
dd offset cdup
dd offset qdup
dd offset cdrop
; dd offset nip
dd offset then
dd offset begin
dd 128 dup (0)
forth2 dd offset boot
dd offset warm
dd offset PAUSE
dd offset MACRO_
dd offset FORTH
dd offset c_
dd offset stop
dd offset readf
dd offset writef
dd offset nc_
dd offset cmdf
dd offset seekf
dd offset readyf
dd offset ACT
dd offset SHOW
dd offset LOAD
dd offset here
dd offset qlit
dd offset COMMA3
dd offset COMMA2
dd offset COMMA1
dd offset COMMA
dd offset less
dd offset jump
dd offset ACCEPT
dd offset pad
dd offset erase
dd offset copy
dd offset mark
dd offset empty
dd offset emit
dd offset eDIG
dd offset emit2
dd offset dot10
dd offset hdot
dd offset hdotn
dd offset CR
dd offset space
dd offset DOWN
dd offset edit
dd offset E
; dd offset font
dd offset LMs
dd offset RMs
dd offset graphic
dd offset text1
; dd offset set3d
; dd offset render
; dd offset vertex
; dd offset front
; dd offset top_
; dd offset side
dd offset keyboard
dd offset debug
dd offset at
dd offset pat
dd offset xy_
dd offset fov_
dd offset fifof
dd offset box
dd offset line
dd offset color
; dd offset clip
dd offset octant
dd offset sps
dd offset last_
dd offset unpack
; dd offset pack
dd 512 dup (0)
boot: mov AL, 0FEh ; Reset
out 64h, AL
jmp $
erase: mov ECX, EAX
shl ECX, 8
DROP
push EDI
mov EDI, EAX
shl EDI, 2+8
xor EAX, EAX
rep stosd
pop EDI
DROP
ret
;move: mov ECX, EAX
; DROP
; mov EDI, EAX
; shl EDI, 2
; DROP
; push ESI
; mov ESI, EAX
; shl ESI, 2
; rep movsd
; pop ESI
; DROP
; ret
copy: cmp EAX, 12
jc ABORT1
mov EDI, EAX
shl EDI, 2+8
push ESI
mov ESI, blk
shl ESI, 2+8
mov ECX, 256
rep movsd
pop ESI
mov blk, EAX
DROP
ret
debug: mov xy, 3*10000h+(vc-2)*ih+3
DUP_
mov EAX, God
push [EAX]
call dot
DUP_
pop EAX
call dot
DUP_
mov EAX, main
call dot
DUP_
mov EAX, ESI
jmp dot
iw equ 16+6 ; something width
ih equ 24+6 ; same thing height
hc equ hp/iw ; 46
vc equ vp/ih ; 25
ALIGN 4
xy dd 3*10000h+3
lm dd 3
rm dd hc*iw ; 1012
xycr dd 0
fov dd 10*(2*vp+vp/2)
; These have funky "addresses" that get moved into EAX because colorForth
; uses dword addresses, and `start' is a symbol at the beginning of the
; memory image of colorForth (in BOOT.ASM).
nc_: DUP_
mov EAX, (offset nc-offset start)/4
ret
xy_: DUP_
mov EAX, (offset xy-offset start)/4
ret
fov_: DUP_
mov EAX, (offset fov-offset start)/4
ret
sps: DUP_
mov EAX, (offset spaces-offset start)/4
ret
last_: DUP_
mov EAX, (offset last-offset start)/4
ret
include gen.asm ; cce.asm pio.asm ATI128.asm ATI64.asm gen.asm
yellow equ 0ffff00h
CYAN: DUP_
mov EAX, 0ffffh
jmp color
MAGENTA: DUP_
mov EAX, 0ff00ffh
jmp color
SILVER: DUP_
mov EAX, 0c0c0c0h
jmp color
BLUE: DUP_
mov EAX, 4040ffh
jmp color
RED: DUP_
mov EAX, 0ff0000h
jmp color
GREEN: DUP_
mov EAX, 8000ff00h
jmp color
history db 11 dup (0)
ECHO_: push ESI
mov ECX, 11-1
lea EDI, history
lea ESI, [1+EDI]
rep movsb
pop ESI
mov history+11-1, AL
DROP
ret
RIGHT: DUP_
mov ECX, 11
lea EDI, history
xor EAX, EAX
rep stosb
DROP
ret
DOWN: DUP_
xor EDX, EDX
mov ECX, ih
div ECX
mov EAX, EDX
add EDX, 3*10000h+8000h-ih+3
mov xy, EDX
ZERO: test EAX, EAX
mov EAX, 0
jnz @f
inc EAX
@@: ret
blank: DUP_
xor EAX, EAX
mov xy, EAX
call color
DUP_
mov EAX, hp
DUP_
mov EAX, vp
jmp box
TOP: mov ECX, lm
shl ECX, 16
add ECX, 3
mov xy, ECX
mov xycr, ECX
ret
qcr: mov CX, word ptr xy+2
cmp CX, word ptr rm
js @f
cr: mov ECX, lm
shl ECX, 16
mov CX, word ptr xy
add ECX, ih
mov xy, ECX
@@: ret
LMs: mov lm, EAX
DROP
ret
RMs: mov rm, EAX
DROP
ret
at: mov word ptr xy, AX
DROP
mov word ptr xy+2, AX
DROP
ret
pAT: add word ptr xy, AX
DROP
add word ptr xy+2, AX
DROP
ret
;cl1: xor EAX, EAX
; mov [ESI], EAX
; ret
;clip: movsx EDX, word ptr xy
; cmp EDX, vp
; jns cl1
; add EAX, EDX
; js cl1
; test EDX, EDX
; jns @f
; xor EDX, EDX
;@@: cmp EAX, vp
; js @f
; mov EAX, vp
;@@: sub EAX, EDX
; mov word ptr xy, DX
; movsx EDX, word ptr xy+2
; cmp EDX, hp
; jns cl1
; add [ESI], EDX
; js cl1
; test EDX, EDX
; jns @f
; xor EDX, EDX
;@@: cmp dword ptr [ESI], hp
; js @f
; mov dword ptr [ESI], hp
;@@: sub [ESI], EDX
; mov word ptr xy+2, DX
; ret
octant: DUP_
mov EAX, 43h ; poly -last y+ x+ ;23h ; last y+ x+
mov EDX, [4+ESI]
test EDX, EDX
jns @f
neg EDX
mov [4+ESI], EDX
xor AL, 1
@@: cmp EDX, [ESI]
jns @f
xor AL, 4
@@: ret
; Keyboard
EIGHT: add EDI, 12
call FOUR
call SPACE
sub EDI, 16
FOUR: mov ECX, 4
FOUR1: push ECX
DUP_
xor EAX, EAX
mov AL, [4+EDI]
inc EDI
call EMIT
pop ECX
next FOUR1
ret
stack: mov EDI, Godd-4
@@: mov EDX, God
cmp [EDX], EDI
jnc @f
DUP_
mov EAX, [EDI]
sub EDI, 4
call qDOT
jmp @b
@@: ret
KEYBOARD: call text1
mov EDI, board
DUP_
mov EAX, keyc
call color
mov rm, hc*iw
mov lm, hp-9*iw+3
mov xy, (hp-9*iw+3)*10000h+vp-4*ih+3
call EIGHT
call EIGHT
call EIGHT
call CR
add xy, 4*iw*10000h
mov EDI, shift
add EDI, 4*4-4
mov ECX, 3
call FOUR1
mov lm, 3
mov word ptr xy+2, 3
call stack
mov word ptr xy+2, hp-(11+9)*iw+3
lea EDI, history-4
mov ECX, 11
jmp FOUR1
alpha db 15o, 12o, 1 , 14o
db 24o, 2 , 6 , 10o
db 23o, 11o, 17o, 21o
db 22o, 13o, 16o, 7
db 5 , 3 , 4 , 26o
db 27o, 44o, 25o, 20o
graphics db 31o, 32o, 33o, 0
db 34o, 35o, 36o, 30o
db 37o, 40o, 41o, 57o
db 51o, 50o, 52o, 54o ; : ; ! @
db 46o, 42o, 45o, 56o ; Z J . ,
db 55o, 47o, 53o, 43o ; * / + -
numbers db 31o, 32o, 33o, 0
db 34o, 35o, 36o, 30o
db 37o, 40o, 41o, 0
db 0, 0 , 0 , 0
db 0, 0 , 0 , 0
db 0, 0 , 0 , 0
octals db 31o, 32o, 33o, 0
db 34o, 35o, 36o, 30o
db 37o, 40o, 41o, 0
db 0 , 5 , 23o, 12o
db 0 , 20o, 4 , 16o
db 0 , 0 , 0 , 0
LETTER: cmp AL, 4
js @f
mov EDX, board
mov AL, [EDX][EAX]
@@: ret
keys db 16, 17, 18, 19, 0, 0, 4, 5 ; 20
db 6, 7, 0, 0, 0, 0, 20, 21
db 22, 23, 0, 0, 8, 9, 10, 11 ; 40
db 0, 0, 0, 0, 24, 25, 26, 27
db 0, 1, 12, 13, 14, 15, 0, 0 ; 60 N
db 3, 2 ; alt space
KEY: DUP_
xor EAX, EAX
@@: call PAUSE
in AL, 144o
test AL, 1
jz @b
in AL, 140o
test AL, 360o
jz @b
cmp AL, 72o
jnc @b
mov AL, [keys-20o+EAX]
ret
ALIGN 4
graph0 dd offset nul0, offset nul0, offset nul0, offset ALPH0
db 0 , 0 , 5 , 0 ; a
graph1 dd offset WORD0, offset X, offset LJ, offset ALPH
db 25o, 45o, 5 , 0 ; x . a
alpha0 dd offset nul0, offset nul0, offset NUMBER, offset STAR0
db 0 , 41o, 55o, 0 ; 9 *
alpha1 dd offset WORD0, offset X, offset LJ, offset GRAPH
db 25o, 45o, 55o, 0 ; x . *
numb0 dd offset nul0, offset MINUS, offset ALPHn, offset OCTAL
db 43o, 5 , 16o, 0 ; - a f
numb1 dd offset NUMBER0, offset Xn, offset ENDN, offset NUMBER0
db 25o, 45o, 0 , 0 ; x .
board dd offset alpha-4
shift dd offset alpha0
base dd 10
current dd offset decimal
keyc dd yellow
chars dd 1
aword dd offset EX1
anumber dd offset nul
words dd 1
nul0: DROP
jmp @f
ACCEPT:
acceptn: mov shift, offset alpha0
lea EDI, alpha-4
ACCEPT1: mov board, EDI
@@: call KEY
cmp AL, 4
jns first
mov EDX, shift
jmp dword ptr [EDX+EAX*4]
bits db 28
@@: add EAX, 120o
mov CL, 7
jmp @f
PACK: cmp AL, 20o
jnc @b
mov CL, 4
test AL, 10o
jz @f
inc ECX
xor AL, 30o
@@: mov EDX, EAX
mov CH, CL
@@: cmp bits, CL
jnc @f
shr AL, 1
jc FULL
dec CL
jmp @b
@@: shl dword ptr [ESI], CL
xor [ESI], EAX
sub bits, CL
ret
LJ0: mov CL, bits
add CL, 4
shl dword ptr [ESI], CL
ret
LJ: call LJ0
DROP
ret
FULL: call LJ0
inc words
mov bits, 28
sub bits, CH
mov EAX, EDX
DUP_
ret
X: call RIGHT
mov EAX, words
lea ESI, [EAX*4+ESI]
DROP
jmp ACCEPT
WORD_: call RIGHT
mov words, 1
mov chars, 1
DUP_
mov dword ptr [ESI], 0
mov bits, 28
WORD1: call LETTER
jns @f
mov EDX, shift
jmp dword ptr [EDX+EAX*4]