-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.htm
248 lines (244 loc) · 16.7 KB
/
index.htm
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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>index</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
</style>
<link rel="stylesheet" href="/G-Pascal/G-Pascal.css" />
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
</head>
<body>
<header id="title-block-header">
<h1 class="title">G-Pascal for Ben Eater’s 6502 board</h1>
</header>
<p><strong>Author</strong>: Nick Gammon</p>
<p><strong>Date written</strong>: February 2022</p>
<div class="quick_link">
<a href="pascal_compiler.htm">G-Pascal info</a>
</div>
<div class="quick_link">
<a href="assembler.htm">Assembler info</a>
</div>
<div class="quick_link">
<a href="hardware_mods.htm">Suggested hardware mods</a>
</div>
<div class="quick_link">
<a href="installation.htm">How to install</a>
</div>
<div class="quick_link">
<a href="editor.htm">Text editor</a>
</div>
<div class="quick_link">
<a href="file_menu.htm">File menu</a>
</div>
<div class="quick_link">
<a href="adventure.htm">Adventure game</a>
</div>
<div class="quick_link">
<a href="i2c.htm">I2C support</a>
</div>
<div class="quick_link">
<a href="spi.htm">SPI support</a>
</div>
<div class="quick_link">
<a href="https://gammon.com.au/electronics">More electronics</a>
</div>
<h2 id="on-board-assembler-tiny-pascal-and-text-editor-for-ben-eaters-board">On-board assembler, tiny Pascal, and text editor for <a href="https://eater.net/6502">Ben Eater’s board</a></h2>
<p>Demonstration video <a href="https://vimeo.com/682663375">here on Vimeo</a>.</p>
<h3 id="includes">Includes:</h3>
<ul>
<li>A <strong>6502 assembler</strong> which lets you try out your assembler programming without having to keep removing the EEPROM chip and programming it externally. The assembler supports:
<ul>
<li><p>The documented WD65C02 instruction set, with all operand modes</p></li>
<li><p>Full expression evaluation of operands, with operator precedence, parentheses, bitwise operations and so on.</p></li>
<li><p>Relocation of the output to any memory address (ORG directive)</p></li>
<li><p>Support for debugging using breakpoints (BRK instruction)</p></li>
<li><p>Here is “hello world” in assembler:</p>
<pre><code> jmp begin ; skip the message
hello asciiz "Hello, world!"
begin:
lda #<hello
ldx #>hello
jsr print
rts</code></pre></li>
<li><p>Detailed notes about the assembler <a href="assembler.htm">here</a>.</p></li>
</ul></li>
<li>A <strong>“tiny” Pascal compiler</strong> (G-Pascal) which allows you to program the board in a high-level language. Whilst there are limitations in what can be done in a few KB of memory, the compiler supports:
<ul>
<li><p>CONST, VAR, FUNCTION and PROCEDURE declarations</p></li>
<li><p>Local declarations (functions and variables within functions, etc.)</p></li>
<li><p>Recursive function and procedure calls</p></li>
<li><p>Arithmetic: multiply, divide, add, subtract, modulus</p></li>
<li><p>Logical operations: and, or, shift left, shift right, exclusive or</p></li>
<li><p>INTEGER and CHAR data types. (Integer are 3 bytes and thus range from 8388607 to -8388608)</p></li>
<li><p>Arrays</p></li>
<li><p>Interface with any memory address by using the MEM and MEMC constructs (to peek and poke memory locations)</p></li>
<li><p>Built-in functions to write to the LCD display.</p></li>
<li><p>Built-in functions to do pinMode, digitalRead and digitalWrite, similar to the Arduino. These interface with any available ports on the VIA chip.</p></li>
<li><p>Here is “hello world” for the LCD display:</p>
<pre class="pas"><code>begin
lcdclear;
lcdwrite ("Hello, world!")
end.</code></pre>
<p>And for the serial monitor:</p>
<pre class="pas"><code>begin
writeln ("Hello, world!")
end.</code></pre></li>
<li><p>Detailed notes about the compiler <a href="pascal_compiler.htm">here</a>.</p></li>
</ul></li>
<li>A <strong>text editor</strong> for keying in programs. It supports:
<ul>
<li>Loading and saving (via the RS232 interface)</li>
<li>Inserting and deleting lines</li>
<li>Find and replace</li>
<li>Detailed notes about the <a href="editor.htm">editor</a> and <a href="file_menu.htm">how to load and save source</a>.</li>
</ul>
<pre><code>Available actions:
List/SAve line_number_range
Delete line_number_range
Insert/LOad after_line
Find line_number_range /target/flags
Replace line_number_range /target/replacement/flags
Help
INfo
Memory first_address last_address
Compile/Syntax/Assemble
RUn/DEBug/Trace/RESume
Poke/Jsr/JMp
RECover
(Actions may be abbreviated)
(Flags: 'I'gnore case, 'G'lobal, 'Q'uiet)</code></pre></li>
<li><strong>Support functions</strong>, such as:
<ul>
<li>RS232 interface for connecting a “dumb” terminal, or a PC/Mac</li>
<li>Support for the LCD interface described in Ben’s videos</li>
<li>Other support functions for use by your assembler code, such as multiplication and division, CRC calculations, binary-to-decimal conversion</li>
<li>Support for NMI (non-maskable interrupts) so that you can recover from runaway code</li>
<li>Support for I<sup>2</sup>C communication for connecting to real-time clocks, port expanders, etc.</li>
<li>Support for SPI communication for connecting to port expanders, display boards and other devices.</li>
<li>There is over 9k of space available on the EEPROM to add your own functions (over 11k if you omit the CP437 character set from it)</li>
</ul></li>
</ul>
<p>Both the Pascal compiler and assembler are quite fast. Any program that will fit into memory will compile in a few seconds. For example, using a 1 MHz clock:</p>
<ul>
<li>A 335-line assembler program testing all opcodes assembles in 5 seconds</li>
<li>A 651-line G-Pascal program (the Adventure game) compiles in 6 seconds</li>
</ul>
<hr />
<h2 id="how-much-does-it-cost">How much does it cost?</h2>
<ul>
<li>The software is open source</li>
<li>There is no fee</li>
<li>You do not need to register</li>
<li>You do not need to provide any personal details such as email address</li>
<li>The software can be <a href="https://github.com/nickgammon/G-Pascal">downloaded from GitHub</a></li>
<li>The license (MIT License) is <a href="doc/license.txt">here</a></li>
</ul>
<hr />
<h2 id="hardware-modifications-suggestedrequired">Hardware modifications suggested/required</h2>
<p><img src="images/Board%20photo.png" /></p>
<ul>
<li><p>RS232 interface (required)</p>
<p>To interface with the compiler, text editor and assembler you clearly need some way to “talk” to Ben’s 6502 board. The on-board code supports interfacing with a serial interface running at 4800 baud. To do this you will need to use an FTDI cable, available on eBay for around $US 10. The wiring for it is <a href="hardware_mods.htm#rs232_interface">here</a>.</p></li>
<li><p>An NMI interrupt push-button (suggested)</p>
<p>It helps to recover from runaway or rogue code by pressing a switch button connected to the NMI pin of the 65C02. This does a “warm restart” which basically starts the code again, however it retains your existing source code. The wiring for it is <a href="hardware_mods.htm#nmi_interrupt">here</a>.</p></li>
<li><p>An enhancement that stops you attempting to write to EEPROM (suggested)</p>
<p>The way Ben described the address decoding for the EEPROM, it is possible for both the CPU and the EEPROM to be attempting to write to the bus at the same time (eg. STA $8000). The suggested wiring uses a spare NAND gate on the existing board to prevent that. This would prevent possible damage to the CPU and/or the EEPROM if such code was attempted. The wiring for it is <a href="hardware_mods.htm#protect_EEPROM">here</a>.</p></li>
<li><p>An enhancement to give yourself access to more of the on-board RAM (suggested)</p>
<p>The way Ben did his address decoding for the RAM meant that only 16k of the chip’s 32k was available. You can make a simple change using a 74LS08 “AND” gate that extends the RAM address space to 0x6000 rather than 0x4000, thus giving you 24k of RAM (an extra 8k) for the cost of a one dollar chip and a few jumper cables. This change is required to compile the “Adventure” game because of its size. The wiring for it is <a href="hardware_mods.htm#increased_ram">here</a>.</p></li>
<li><p>Put in a faster oscillator</p>
<p>To get a nice speed boost, simply replace the 1 MHz oscillator with 2 MHz or 4 MHz. You will get a corresponding increase in speed. Since the serial communications assume a 1 MHz oscillator, simply increase the baud rate that you use to communicate with the board to match. In other words, with a 2 MHz oscillator use 9600 baud, and with a 4 MHz oscillator use 19200 baud. I haven’t tried faster clock speeds yet.</p></li>
<li><p>You can disconnect, if you wish, the four low-order data bits from the HD44780U LCD screen to the VIA. (That is, VIA pins 10, 11, 12 and 13). This is because the LCD code has been rewritten to use 4-bit mode, thus freeing up those pins.</p></li>
</ul>
<hr />
<h2 id="more-via-pins-are-available">More VIA pins are available</h2>
<p>I rewrote the LCD code to use 4-bit mode on the HD44780U LCD display. This frees up 4 fairly valuable pins on the VIA (versatile interface adapter) chip for other uses, such as developing an SPI interface.</p>
<p>Pins PA0 and PA1 on the VIA are used for the serial interface, as well as CB2 to detect the start bit for incoming serial data.</p>
<p>That leaves 7 pins for your own use (PA2, PA3, PA4, PB0, PB1, PB2, PB3).</p>
<hr />
<h2 id="example-programs">Example programs</h2>
<p>As an example of what can be done, there is a (roughly) 700-line “Adventure” program available <a href="examples/pas/adventure.pas">here</a> for compiling. That demonstrates a lot of the features of the compiler and is a fun game to try out. Note that running this requires a small hardware modification to Ben’s board to make more of the RAM available, as described <a href="hardware_mods.htm#increased_ram">here</a>. This program was originally written in 1982 for the Apple II version of G-Pascal, and has been modified slightly to conform to the syntax of this compiler.</p>
<p>Other example programs are <a href="examples/pas/prime_numbers.pas">prime number generation</a>, <a href="examples/pas/sqrt.pas">square roots calculation</a>, and a <a href="examples/pas/guessing_game.pas">guessing game</a>.</p>
<p>Or, you can play with assembler coding and make LEDs blink. :)</p>
<p>Example code <a href="examples/">here</a>.</p>
<p>The code is released under an extremely liberal license (MIT License), which basically means you can do anything at all you like with it, except claiming you wrote it yourself. ;)</p>
<hr />
<h2 id="ben-eaters-6502-board">Ben Eater’s 6502 board</h2>
<p>Ben does a fabulous series of YouTube videos about wiring together this 6502 breadboard computer. The first in the series is <a href="https://www.youtube.com/watch?v=LnzuMJLZRdU">here</a>.</p>
<p>It really is extremely interesting and educational. I strongly recommend you watch the video series and consider supporting <a href="https://www.patreon.com/beneater">Ben’s Patreon</a>.</p>
<p>You can buy a <a href="https://eater.net/6502">kit from Ben</a>. Ben has put a lot of work into making these educational videos — I suggest you support him and his future endeavours by buying his kits from him.</p>
<hr />
<h2 id="support-for-other-6502-boards">Support for other 6502 boards</h2>
<p>There is no particular reason this code wouldn’t run on other 6502 set-ups. You would need to be aware of the hardware addresses of things like your RAM (which presumably starts at 0x0000 because you need access to the 6502 hardware stack at 0x0100) and your ROM (which presumably covers 0xF000 to 0xFFFF because of the need to have NMI/Reset/IRQ vectors).</p>
<p>You may need to modify the way the code interfaces with the hardware, depending on your personal setup.</p>
<hr />
<h2 id="construction-notes">Construction notes</h2>
<p>My board was made from a genuine kit from <a href="https://eater.net/6502">Ben Eater’s website</a>, however I largely connected the pins using wire-wrapping rather than breadboard wires.</p>
<p><img src="images/wire-wrap.jpg" /></p>
<p>There were several reasons for this:</p>
<ul>
<li>I found running lots of breadboard wires in a confined space tedious, especially when there were a lot in close proximity to each other</li>
<li>If you weren’t careful, touching the wires would tend to pop one out of the breadboard, due to the force from nearby wires in a cluster</li>
<li>It was difficult or impossible to see whether you had run the right wire to the right pin</li>
<li>Changing a wrong wire was difficult if it happened to be under a cluster of wires</li>
<li>The wire-wrap posts made a convenient test point for attaching oscilloscope or logic analyser probes</li>
</ul>
<p>Wire wrapping is not much slower than putting in breadboard wires. You still have to cut the wires to length and strip them, so that part is much the same, except when the supplied breadboard wires happen to be exactly the right length. The only extra step is to insert the wire into the tool and twirl it around to bind it to the post.</p>
<p>The extra things you need to do wire-wrapping are:</p>
<ul>
<li>A wire-wrap tool (see photo below) - around $US 20 from eBay</li>
<li>A spool or two of AWG30 wire-wrapping wire - around $US 10 from eBay each</li>
<li>Some header pins of the longer variety. You need them to be long enough to firmly go into the breadboard, and have enough room on top for two or three wire-wraps. The ones I used were 17.5 mm long (see bottom-right corner of photo below).</li>
</ul>
<p><img src="images/wire-wrapping%20tool.jpg" /></p>
<p>There are various tutorials around for how to wire-wrap including <a href="https://learn.sparkfun.com/tutorials/working-with-wire/how-to-use-a-wire-wrap-tool">this one from Sparkfun</a>.</p>
<hr />
<h2 id="hardware-theory-and-notes">Hardware theory and notes</h2>
<p>A <em>considerable</em> amount of detail about the 6502 and suggested schematics are at <a href="http://wilsonminesco.com/6502primer/">Garth Wilson’s 6502 primer: Building your own 6502 computer</a>. There is a <a href="http://wilsonminesco.com/6502primer/potpourri.html">schematic</a> on his site which looks similar to the one Ben used. There is also a lot of background detail there and suggestions for alternatives.</p>
<hr />
<h2 id="questions-or-comments">Questions or comments</h2>
<p>Questions or comments may be posted by joining <a href="http://www.gammon.com.au/forum/index.php?bbtopic_id=125">my forum</a>.</p>
<hr />
<h2 id="other-links">Other links</h2>
<h3 id="this-site">This site</h3>
<ul>
<li><a href="hardware_mods.htm">Suggested hardware modifications</a> to Ben’s 6502 board including accessing more of the on-board RAM, and connecting up the board to your PC/Mac</li>
<li><a href="pascal_compiler.htm">G-Pascal compiler features</a> and limitations</li>
<li><a href="assembler.htm">Assembler features</a> and limitations</li>
<li><a href="examples/">Example code</a></li>
<li><a href="editor.htm">Text editor</a></li>
<li><a href="file_menu.htm">File menu</a></li>
<li><a href="installation.htm">How to install</a></li>
<li><a href="i2c.htm">I2C support</a></li>
<li><a href="spi.htm">SPI support</a></li>
<li><a href="history.htm">History of G-Pascal</a> and the assembler</li>
<li><a href="https://www.gammon.com.au/forum/index.php?bbsection_id=14">My forum with posts about electronics</a></li>
<li><a href="http://www.gammon.com.au/forum/index.php?bbtopic_id=125">G-Pascal part of my forum</a></li>
</ul>
<h3 id="source-code-and-documentation-on-github">Source code and documentation on GitHub</h3>
<ul>
<li><a href="https://github.com/nickgammon/G-Pascal">https://github.com/nickgammon/G-Pascal</a></li>
</ul>
<h3 id="other-sites">Other sites</h3>
<ul>
<li><a href="https://eater.net/6502">Ben Eater’s 6502 board</a></li>
<li><a href="https://www.youtube.com/watch?v=LnzuMJLZRdU">Ben Eater’s first 6502 board tutorial on YouTube</a></li>
<li><a href="http://wilsonminesco.com/6502primer/">Garth Wilson’s 6502 primer: Building your own 6502 computer</a></li>
<li><a href="http://forum.6502.org/">6502 forum</a></li>
<li><a href="https://www.reddit.com/r/beneater/">Reddit: Ben Eater</a></li>
</ul>
<hr />
<h2 id="license">License</h2>
<p>Information and images on this site are licensed under the <a href="https://creativecommons.org/licenses/by/3.0/au/">Creative Commons Attribution 3.0 Australia License</a> unless stated otherwise.</p>
<p>Source code licensed under the <a href="doc/license.txt">MIT License</a>.</p>
</body>
</html>