-
Notifications
You must be signed in to change notification settings - Fork 0
/
DRAFT-COREWARS.4TH
116 lines (93 loc) · 1.81 KB
/
DRAFT-COREWARS.4TH
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
( WORK IN PROGRESS )
( ATARI 800XL, APX EXTENDED FIG FORTH )
( TODO: change arena to a char array? )
( Day 1: ca. 5h )
( Day 2: ca. 1h )
( * Micro Core Wars * )
FORTH DEFINITIONS DECIMAL
( ** INCLUDES ** )
( 39 LOAD ( assembler ) CR
( 50 LOAD ( graphics ) CR
( ** CONSTANTS ** )
1 CONSTANT #DEBUG
160 80 * CONSTANT #SIZE
0 CONSTANT #_
24 CONSTANT #MAXPROG
88 CONSTANT #SAVMSC
( ** VARIABLES ** )
0 VARIABLE arena #SIZE 2 - ALLOT
1 VARIABLE progCnt
( ** WORDS ** )
( "coroutine" )
: <CO> R> R> SWAP >R >R ; ( -- )
: ColCycle ( -- )
BEGIN
712 @ 255 = IF 0 712 ! THEN
712 @ 1+ 712 !
1000 0 DO LOOP <CO>
AGAIN ;
: TEST.ColCycle ( -- )
ColCycle
BEGIN ." Y" <CO> AGAIN ;
( dummy commands, see "Moje Atari 6": )
( https://archive.org/details/moje-atari-6/ )
( page/n3/mode/2up )
: JMP DROP ; : MOV DROP DROP ;
: DAT DROP ; : ADD DROP DROP ;
( Random number using POKEY )
: Rnd ( rng -- rnd )
-11766 C@ -11766 C@ 256 * +
SWAP MOD ABS ;
( Start in an empty cell )
: SetCell ( c -- )
BEGIN
#SIZE Rnd arena + ( c n )
DUP C@ #_ = IF ( c n )
#DEBUG IF
CR ." setcell: " 2DUP . .
CR
THEN
C! ;S ELSE DROP DROP
THEN
AGAIN ;
: Worm ( pl -- )
<BUILDS
8 0 DO #_ C, LOOP
1 progCnt +! progCnt C@ ,
SetCell ( -- )
DOES>
0 1 MOV ;
: Dwrf ( pl -- name )
<BUILDS
8 0 DO #_ C, LOOP
1 progCnt +! progCnt C@ ,
SetCell ( -- )
DOES>
2 JMP
0 DAT
5 -1 ADD
0 -2 MOV
2 JMP ;
: Init ( -- )
arena #SIZE #_ FILL ;
: Show ( -- )
CR #SIZE 0 DO
arena I + C@ .
LOOP CR ;
: (Run)
arena #SAVMSC @ #SIZE CMOVE
BEGIN
KEY 27 = IF ;S THEN
AGAIN
;
: Run ( -- )
5 GR.
(Run)
XGR ;
( Init
( 1 Worm WORM1
( 1 Worm WORM2
( 2 Worm WORM3
( 2 Dwrf DWRF1
( 3 Worm WORM4
( Run