Rev Author Line No. Line
4985 kaklik 1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5 <title> amforth.asm </title>
6 <meta name="keywords" content="amforth programming language Forth ATmega ATMEL">
7 <meta name="description" content="amforth - laguage Forth for ATMEL ATmega">
8 <!-- AUTOINCLUDE START "Page/Head.en.ihtml" DO NOT REMOVE -->
9 <link rel="StyleSheet" href="../../../../Web/CSS/MLAB.css" type="text/css" title="MLAB Basic Style">
10 <link rel="StyleSheet" href="../../../../Web/CSS/MLAB_Print.css" type="text/css" media="print">
11 <link rel="shortcut icon" type="image/x-icon" href="../../../../Web/PIC/MLAB.ico">
12 <script type="text/javascript" src="../../../../Web/JS/MLAB_Menu.js"></script>
13 <!-- AUTOINCLUDE END -->
14 </head>
15  
16 <body lang="en">
17  
18 <!-- AUTOINCLUDE START "Page/Header.en.ihtml" DO NOT REMOVE -->
19 <!-- ============== HEADER ============== -->
20 <div class="Header">
21 <script type="text/javascript">
22 <!--
23 SetRelativePath("../../../../");
24 DrawHeader();
25 // -->
26 </script>
27 <noscript>
28 <p><b> JavaScript is required for including of the header </b></p>
29 </noscript>
30 </div>
31 <!-- AUTOINCLUDE END -->
32  
33 <!-- AUTOINCLUDE START "Page/Menu.en.ihtml" DO NOT REMOVE -->
34 <!-- ============== MENU ============== -->
35 <div class="Menu">
36 <script type="text/javascript">
37 <!--
38 SetRelativePath("../../../../");
39 DrawMenu();
40 // -->
41 </script>
42 <noscript>
43 <p><b> JavaScript is required for including of the menu </b><p>
44 </noscript>
45 </div>
46 <!-- AUTOINCLUDE END -->
47  
48 <!-- ============== TEXT ============== -->
49 <div class="Text">
50  
51 <h1> amforth.asm </h1>
52  
53 <p>
54 <input type=button onClick="history.back()" value="Back">
55 <input type=button onClick="history.forward()" value="Forward">
56 <a href="../WordList.en.html">Jump to Vocabulary</a>
57 </p>
58  
59 <pre>
60 ;;;; avr forth
61 ;;;;
62 ;;;; GPL V2 (only)
63  
64 .set pc_ = pc
65  
66 .org $0000
67 rjmp reset
68  
69 .org pc_
70 ; main entry point
71 reset:
72 clr zerol
73 clr zeroh
74 ; init first user data area
75 ldi zl, low(heap)
76 ldi zh, high(heap)
77 movw upl, zl
78 ; init return stack pointer
79 ldi temp0,low(ramend)
80 out SPL,temp0
81 std Z+2, temp0
82 ldi temp1,high(ramend)
83 out SPH,temp1
84 std Z+3, temp1
85  
86 ; init parameter stack pointer
87 ldi yl,low(stackstart)
88 std Z+6, yl
89 ldi yh,high(stackstart)
90 std Z+7, yh
91  
92 ; allocate space for User Area
93 .set heap = heap + USERSIZE
94  
95 ; load Forth IP with starting word
96 ldi xl, low(PFA_COLD)
97 ldi xh, high(PFA_COLD)
98 ; the following should be turnkey-action, but adds a few more words to the the dictionary
99 call_ device_init
100 ; its a far jump...
101 jmp_ DO_NEXT
102  
103 ; ISR routines
104 .include &quot;words/intx.asm&quot;
105 .include &quot;words/usart.asm&quot;
106  
107 ; lower part of the dictionary
108 .include &quot;dict_minimum.asm&quot;
109 .if dict_optional==1
110 .include &quot;dict_optional.asm&quot;
111 .endif
112  
113 .set lowflashlast = pc
114  
115 ; high part of the dictionary (primitives and words for self programming)
116 .org nrww
117 ; the inner interpreter.
118 DO_DODOES:
119 adiw wl, 1
120 savetos
121 movw tosl, wl
122  
123 pop wh
124 pop wl
125  
126 push xh
127 push xl
128 movw xl, wl
129 rjmp DO_NEXT
130  
131 DO_COLON: ; 31 CPU cycles to ijmp
132 push xh
133 push xl ; PUSH IP
134 adiw wl, 1 ; set W to PFA
135 movw xl, wl
136  
137 DO_NEXT: ; 24 CPU cycles to ijmp
138 brts DO_INTERRUPT
139 movw zl,xl ; READ IP
140 lsl zl
141 rol zh
142 lpm wl, Z+
143 lpm wh, Z ; done read IP
144 adiw xl, 1 ; INC IP
145  
146 DO_EXECUTE: ; 12 cpu cycles to ijmp
147 movw zl, wl
148 lsl zl
149 rol zh
150 lpm temp0, Z+
151 lpm temp1, Z
152 movw zl, temp0
153 ijmp
154  
155 DO_INTERRUPT: ; 12 cpu cycles to rjmp (+12=24 to ijmp)
156 ; here we deal with interrupts the forth way
157 lds temp0, intcur
158 ldi zl, LOW(intvec)
159 ldi zh, HIGH(intvec)
160 add zl, temp0
161 adc zh, zeroh
162 ldd wl, Z+0
163 ldd wh, Z+1
164  
165 clt ; clear the t flag to indicate that the interrupt is handled
166 rjmp DO_EXECUTE
167  
168 .include &quot;dict_high.asm&quot;
169  
170 .if dict_optional==2
171 .include &quot;dict_optional.asm&quot;
172 .endif
173 .set flashlast = pc
174  
175 .eseg
176 .dw lowflashlast ; DP
177 .dw VE_HEAD ; HEAD
178 .dw heap ; HEAP
179 .dw edp ; EDP
180 .dw XT_VER ; TURNKEY
181 .dw baud_rate ; BAUDRATE
182 ; 1st free address in EEPROM, see above
183 edp:
184 .cseg
185 </pre>
186  
187 <p>
188 <input type=button onClick="history.back()" value="Back">
189 <input type=button onClick="history.forward()" value="Forward">
190 <a href="../WordList.en.html">Jump to Vocabulary</a>
191 </p>
192  
193 </div>
194  
195 <!-- AUTOINCLUDE START "Page/Footer.en.ihtml" DO NOT REMOVE -->
196 <!-- ============== FOOTER ============== -->
197 <div class="Footer">
198 <script type="text/javascript">
199 <!--
200 SetRelativePath("../../../../");
201 DrawFooter();
202 // -->
203 </script>
204 <noscript>
205 <p><b> JavaScript is required for including of the footer </b></p>
206 </noscript>
207 </div>
208 <!-- AUTOINCLUDE END -->
209  
210 </body>
211 </html>