comparison doc/sbc09.creole @ 57:2088fd998865

sbc09 directry clean up
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 23 Jul 2018 16:07:12 +0900
parents
children
comparison
equal deleted inserted replaced
56:4fa2bdb0c457 57:2088fd998865
1
2 = SBC09, an Emulator for a 6809-Based Single Board Compuer. =
3
4 author: **L.C. Benschop**
5
6 This file is the content of **sbc09.tex** converted 2013 by Jens Diemer into
7 this creole markup.
8
9 Revisions:
10 2014-06-26 Jens Diemer
11 Merge some text parts from the origin README textfile
12
13
14 == Introduction ==
15
16
17 The {{{sbc09}}} package contains an emulator of a 6809-based single board
18 computer that runs under UNIX. It contains all the programs needed to work
19 with the emulator, such as the emulator itself, an assembler, a monitor
20 program, a BASIC interpreter, a Forth interpreter, several example programs
21 and several tools needed to build the programs. The program should work
22 under most more-or-less POSIX-compliant versions of UNIX and they were
23 developed under Linux. Of course I believe that the programs that currently
24 run on the emulator would also run on a real 6809 machine.
25
26
27 === A Bit of Background on SBCs. ===
28
29
30 In the seventies you could buy single board microcomputers that had a
31 hexadecimal keypad and 7-segment displays. These computers typically had
32 less than 1 kilobyte of RAM and a simple monitor program in ROM. An
33 interface to a cassette recorder (or paper tape reader/writer) and a
34 terminal was possible, but not standard. The typical way to program the
35 machine was entering hexadecimal machine codes on the keypad. Machine code
36 was the only language in which you could program them, especially if you
37 only had a hexadecimal keypad and 7-segment led displays. You typically used
38 these machines to experiment with hardware interfacing, as games and
39 calculations were a bit limited with only six 7-segment digits.
40
41 Next came simple home computers, like the TRS80, the Apple ][ and the
42 Commodore PET. These machines had BASIC in ROM and they used a simple
43 cassette recorder to store data. These computers had a TV or a low quality
44 monitor as display and a QWERTY keyboard. These machines could be upgraded
45 with a floppy disk drive and a printer and then they could be used for
46 professional work. These machines had 4 to 64 kilobytes of memory.
47 Apart from assembly language you could use BASIC, Forth
48 and sometimes Pascal to program these machines. Most useful programs (and
49 the best games) were programmed in assembly language. Many of these machines
50 had BASIC in ROM and no machine code monitor. You had to load that
51 separately.
52
53 Today we have personal computers that run DOS, Windows, UNIX or something
54 else. New computers have 4 to 16 megabytes of RAM and hard disks of more
55 than 500 Megabytes. Apart from having in the order of 1000 times more
56 storage, they are also 1000 times faster than the old 8-bit home computers.
57 Programming? You can use Visual BASIC, C++ and about
58 every other programming language on the planet. But programs have become
59 bigger and bigger. Programming is not the same as it was before.
60
61 I guess there is some demand for small 8-bit computer systems that are simple
62 to build, easy to interface to all kinds of hobby projects, fun to program
63 and small enough to integrate into a home-built project.
64 Do we want to use hexadecimal keyboards and 7-segment displays? I guess not
65 many people want to use them. Do we want to use a cassette recorder for data
66 storage and a TV as a display? Not me. And if you build your own 8-bit
67 microprocessor, do you want to waste your time and money on a hexadecimal
68 keypad or a cassette interface that you do not like to use and that you do
69 not need anyway? PCs of five years ago are more than adequate to run an
70 editor, a terminal program and a cross assembler for your favourite 8-bit
71 processor. The terminal program can then be used to send the programs to the
72 8-bit micro.
73 If you equip an 8-bit system with some static CMOS RAM, a serial
74 interface and a monitor in ROM, you can use the keyboard, hard disk and
75 monitor of your PC for program development and the 8-bit micro can be
76 disconnected from the PC and do its task, once it is programmed.
77
78 Cross development is nothing special. How do you think the microprocessor in
79 you microwave was programmed? But it is not practical for a hobbyist to
80 program an EPROM for each program change. Professional developers of
81 embedded processors have expensive tools, like ROM emulators, processor
82 emulators etc. to see what the processor is doing on its way to the next
83 crash. For a hobbyist it is much more practical to have a slightly more
84 expensive embedded computer that you can run an interactive debugger on.
85 And you are not even limited to assembly language. If you have 32k ROM you
86 can have both the monitor program and a BASIC interpreter and some
87 application code in ROM. Nothing prevents you from having Forth as well.
88
89
90 === The Emulated System. ===
91
92 {{{
93 RESET
94 | /---- 32K ROM
95 | |
96 v |
97 6809 CPU --|---- 32K RAM
98 ^ |
99 | FIRQ |
100 | \---- 6850 ACIA <--- RS232
101 TIMER
102 }}}
103 Block Diagram of SBC.
104
105 The program {{{sbc09}}} emulates the above mentioned single board computer
106 {{{plus}}} the terminal program that communicates with it.
107
108
109 == Building the Programs. ==
110
111
112
113 == The 6809 Assembler a09. ==
114
115
116 The assembler is a09. Run it with
117 {{{
118 a09 [-l listing] [-o object|-s object] source
119 }}}
120
121 Source is a mandatory argument. The -l listing and {{{-o}}} or {{{-s}}}
122 object arguments are
123 optional. By default there is no listing and the object file is the
124 sourcefile name without an extension and if the source file name has no
125 extension it is the source file name with {{{.b}}} extension.
126
127 A09 recognises standard 6809 mnemonics. Labels should start in the first
128 column and may or may not be terminated by a colon. Every line starting with
129 a non-alphanumeric is taken to be a comment line. Everything after the
130 operand field is taken to be comment. There is a full expression evaluator
131 with C-style operators (and Motorola style number bases).
132
133 There are the usual pseudo-ops such as ORG EQU SET SETDP RMB FCB FDB FCC etc.
134 Strings within double quotes may be mixed with numbers on FCB lines. There
135 is conditional assembly with IF/ELSE/ENDIF and there is INCLUDE. The
136 assembler is case-insensitive.
137
138 The object file is either a binary image file (-o) or Motorola S-records (-s).
139 In the former case it contains a binary image of the assembled data starting
140 at the first address where something is assembled. In the following case
141 {{{
142 ORG 0
143 VAR1 RMB 2
144 VAR2 RMB 2
145
146 ORG $100
147 START LDS #$400
148 ...
149 }}}
150
151 the RMB statements generate no data so the object file contains the memory
152 image from address $100.
153
154 The list file contains no pretty lay-out and no pagination. It is assumed
155 that utilities (Unix pr or enscript) are available for that.
156
157 There are no macros and no linkable modules yet. Some provisions are taken
158 for it in the code.
159
160 After the assembler has finished, it prints the number of pass 2 errors.
161 This should be zero. So if you see
162 {{{
163 0 Pass 2 Errors.
164 }}}
165 then you are lucky.
166
167
168 == The Virtual SBC v09. ==
169
170
171 The simulator is v09. Run it with
172 {{{
173 v09 [-t tracefile [-tl tracelo] [-th tracehi]] [-e escchar]
174 }}}
175
176 {{{tracelo}}} and {{{tracehi}}} are addresses. They can be entered in
177 decimal, octal or hex using the C conventions for number input.
178
179 If a tracefile is specified, all instructions at addresses between
180 {{{tracelo}}} and {{{tracehi}}} are traced. Tracing information such as program
181 location, register contents and opcodes are written to the trace file.
182
183 {{{escchar}}} is the escape character. It must be entered as a number. This is
184 the character that you must type to get the v09 prompt. This is control-]
185 by default. (0x1d)
186
187 The program loads its ROM image from the file {{{v09.rom}}}, which is a 32
188 kilobyte binary file. This file should have been generated by the {{{Makefile}}}.
189 The program starts executing at the address found at $FFFE in
190 the ROM, just like a real 6809 would do on reset.
191
192 The address map is as follows:
193 | **$0000--$7FFF** | RAM.
194 | **$8000--$FFFF** | ROM (except the I/O addresses). These addresses are write-protected.
195 | **$E000--$E0FF** | I/O addresses. Currently only one ACIA is mapped.
196
197 At addresses $E000 and $E001 there is an emulated serial port (ACIA). All
198 bytes sent to it (or read from it) are send to (read from) the terminal and
199 sometimes to/from a file.
200 Terminal I/O is in raw mode.
201
202 If you press the escape char, you get the v09 prompt. At the prompt you
203 can enter the following things:
204
205 **X**
206 to exit the simulator.
207
208 **R**
209 to reset the emulated 6809 (very useful).
210
211 **L**//filename//
212 (no space in between) to log terminal output to a file.
213 Control chars and cr are filtered to make the output a normal
214 text file. L without a file name stops logging.
215
216 **S**//filename//
217 to send a specified file to the simulator through its terminal
218 input. LF is converted to CR to mimic raw terminal input.
219
220 **U**//filename//
221 (terminal upload command) to send a file to the 6809 using the
222 X-modem protocol. The 6809 must already run an X-modem receiving
223 program.
224
225 **D**//filename//
226 (terminal download command) to receive a file from the 6809 using
227 the X-modem protocol. The 6809 must already run an X-modem
228 sending program.
229
230 All of these commands, except the R command, can be seen as commands of the
231 communication program that is used to access the single board computer.
232 The R command is a subsitute for pushing the RESET button on the emulated
233 computer.
234
235
236 == Machine Language Monitor. ==
237
238
239 The program {{{monitor.asm}}} is a program that is intended to be included
240 in the ROM of a 6809 based single board computer. The program allows a user
241 to communicate with the single board computer through a serial port. It
242 allows a user to enter machine code, examine memory and registers, to set
243 breakpoints, to trace a program and more. Furthermore, data can be sent to
244 and be received from the single board computer through the X-MODEM protocol.
245
246
247 ==== Getting Started. ====
248
249
250 If you start v09 with the standard ROM, then you will run the monitor
251 program.
252 If all goes well you see something like
253 {{{
254 Welcome to BUGGY 1.0
255 }}}
256 and you can type text. Excellent, you are now running 6809 code.
257
258 The following example programs you can run from the 6809 monitor.
259 All of them start at address $400. For example to run the program bin2dec
260 you type.
261
262 {{{
263 XL400
264 }}}
265
266 Then press your escape character (default is control-] ).
267
268 Then at the v09 prompt type
269
270 {{{
271 ubin2dec
272 }}}
273
274 Now you see some lines displaying the progress of the X-modem session.
275 If that is finished, you type
276
277 {{{
278 G400
279 }}}
280
281 Now it runs and exits to the monitor with SWI, so that the registers are
282 displayed.
283
284 ** cond09.asm **
285
286 ** cond09.inc **
287 Nonsense program to show conditional assembly and the like.
288
289 ** bench09.asm **
290 Benchmark program. Executes tight loop. Takes 83 secs on
291 25 MHz 386. Should take about 8 sec. on 1MHz real 6809. :-(
292
293 ** test09.asm **
294 Tests some nasty features of the 6809. Prints a few lines
295 of PASSED nn and should never print ERROR nn.
296
297 ** bin2dec.asm **
298 Unusual way to convert numbers to decimal using DAA instruction.
299 Prints some test numbers.
300
301 ** basic.asm **
302 Tiny BASIC by John Byrns. Docs are in basic.doc.
303 To test it start the monitor and run basic.
304
305 Then press your escape char.
306 At the v09 prompt type: sexampl.bas
307
308 Now a BASIC program is input.
309 Type RUN to run it.
310
311 Leave BASIC by pressing the escape char and entering x at the
312 prompt.
313
314
315
316 === Use of the monitor commands ===
317
318
319
320
321 ==== Single Letter Commands ====
322
323
324 ===== D - Dump memory =====
325
326 Syntax:
327
328 ** Daddr,len ** Hex/ascii dump of memory region.
329 ** Daddr ** length=64 bytes by default.
330 ** D ** address is address after previous dump by default.
331
332 Examples:
333 {{{
334 DE400,100
335 }}}
336 Dump 256 bytes starting at $E400
337 {{{
338 D
339 }}}
340 Dump the next 64 bytes.
341
342
343 ===== E - Enter data into memory =====
344
345 ** Eaddr bytes **
346 Enter hexadecimal bytes at address.
347 ** Eaddr"ascii" **
348 Enter ascii at address.
349 ** Eaddr **
350 Enter interactively at address (until empty line).
351
352 Examples:
353 {{{
354 E0400 86449D033F
355 }}}
356 Enter the bytes 86 44 9D 03 3F at address $400.
357 {{{
358 E5000"Welcome"
359 }}}
360 Enter the ASCII codes of "Welcome" at address $400.
361
362
363 ===== F - Find string in memory =====
364
365 Syntax:
366 ** Faddr bytes **
367 Find byte string string from address.
368 ** Faddr"ascii" **
369 Find ASCII string.
370
371 Find the specified string in memory, starting at the specified address. The
372 I/O addresses $E000-$E0FF are skipped. The addresses of the first 16
373 occurrences are shown.
374
375 Example:
376 {{{
377 FE400"SEX"
378 }}}
379 Search for the word "SEX" starting in the monitor.
380
381
382 ===== M - Move memory region =====
383
384 ** Maddr1,addr2,len **
385 Move region of memory from addr1 to addr2. If addr2 is
386 1 higher than addr1, a region is filled.
387
388 Example:
389 {{{
390 M400,500,80
391 }}}
392 Move 128 bytes from address $400 to $500.
393
394
395 ===== A - Assemble instructions =====
396
397 Syntax:
398 ** Aaddr **
399 Enter line-by-line assembler.
400
401 You are in the assembler until you make an error or until you enter an empty
402 line.
403
404 Example:
405 {{{
406 A400
407 LDB #$4B
408 JSR $03
409 SWI
410 <empty line>
411 }}}
412
413
414 ===== U - Disassemble instructions =====
415
416 Syntax:
417 ** Uaddr,len **
418 Disassemble memory region.
419 ** Uaddr **
420 (disassemble 21 bytes)
421 ** U **
422
423
424 Examples:
425 {{{
426 UE400,20
427 }}}
428 Diassemble first 32 bytes of monitor program.
429 {{{
430 U
431 }}}
432 Disassemble next 21 bytes.
433
434
435 ===== B - Set, clear and show breakpoints =====
436
437 Syntax:
438 ** Baddr **
439 Set/reset breakpoint at address.
440 ** B **
441 Display active breakpoints.
442 Four breakpoints can be active simultaneously.
443
444 Examples:
445 {{{
446 B403
447 B408
448 }}}
449 Set the breakpoints at the addresses $403 and $408.
450 {{{
451 B
452 }}}
453 Show the breakpoints.
454 {{{
455 B403
456 }}}
457 Remove the breakpoint at $403.
458
459 ===== J - Call a subroutine / G - Go to specified address =====
460
461 Syntax:
462 ** Jaddr **
463 JSR to specified address.
464 ** Gaddr **
465 Go to specified address.
466 ** G **
467 Go to address in PC register.
468 The registers are loaded from where they are saved (on the stack) and at the
469 breakpoints SWI instructions are entered. Next the code is executed at the
470 indicated address. The SWI instruction (or RTS for the J command) returns to
471 the monitor, saving the registers.
472
473
474 ===== H - Calculate HEX expression =====
475
476 Syntax:
477
478 ** Hhexnum{(+|-)hexnum} **
479 Calculate simple expression in hex with + and -
480
481 Examples:
482 {{{
483 H4444+A5
484 H4444-44F3
485 }}}
486
487 ===== P - Put a temporary breakpoint after current instruction and execute it,
488
489 P is similar to T, because it usually executes one instruction and returns
490 to the monitor after it. That does not work for jumps though. Normally you
491 use P only with JSR instructions if you want to execute the whole subroutine
492 without single-stepping through it.
493
494
495 ===== R - Display or modify registers =====
496
497 Syntax:
498 ** R **
499 Register display.
500 ** Rregvalue **
501 Enter new value into register Supported registers:
502 X,Y,U,S,A,B,D (direct page),P (program counter),C (condition code).
503 The R command uses the saved register values (on the stack). There are some
504 restrictions on changing the S register.
505
506 Examples:
507 {{{
508 R
509 }}}
510 Display all registers.
511 {{{
512 RB03
513 RP4444
514 }}}
515 Load the B register with $03 and the program counter with $4444.
516
517
518 ===== T - Single step trace =====
519
520 ===== I - Show the contents of one address =====
521
522 Syntax:
523 ** Iaddr **
524 Display the contents of the given address. (used to read input
525 port)
526
527 Example:
528 {{{
529 IE001
530 }}}
531 Show the ACIA status.
532
533
534 ==== S-Records Related Commands. ====
535
536
537 ** S1bytes **
538 Enter Motorola S records.
539 ** S9bytes **
540 Last S record in series.
541
542 S records are usually entered from a file, either ASCII transfer (S command
543 from the v09 prompt) or X-MODEM transfer (XX command in monitor, U command
544 from v09 prompt). Most Motorola cross assemblers generate S records.
545
546 ** SSaddr,len **
547 Dump memory region as Motorola S records.
548
549 These S records can be loaded later by the monitor program.
550
551 Usually you capture the S records into a file (use L command at v09 prompt)
552 or use XSS instead.
553 The XSS command is the same as SS, except that it outputs the S records
554 through the X-modem protocol (use D command at v09 prompt).
555
556 ** SOaddr **
557 Set origin address for S-record transfer.
558
559 Before entering S records, it sets the first memory address where S records
560 will be loaded, regardless of the address contained in the S records.
561
562 Before the SS command, it sets the first address that will go into the S
563 records.
564
565 Examples.
566 {{{
567 SO800
568 S1130400etc...
569 }}}
570 Load the S records at address $800 even though the address in the S records
571 is $400
572 {{{
573 SO8000
574 SS400,100
575 }}}
576 Save the memory region of 256 bytes starting at $400 as S records. The S
577 records contain addresses starting at $8000.
578
579
580 ==== X-Modem Related Commands. ====
581
582
583 ** XLaddr **
584 Load binary data using X-modem protocol
585
586 Example:
587 {{{
588 XL400
589 }}}
590 Type your escape character and at the v09 prompt type
591 {{{
592 ubasic
593 }}}
594 to load the binary file "basic" at address $400.
595
596 ** XSaddr,len **
597 Save binary data using X-modem protocol.
598
599 Example:
600 {{{
601 XS400,100
602 }}}
603 to save the memory region of 128 bytes starting at $400
604 Type your escape character and at the v09 prompt type:
605 {{{
606 dfoo
607 }}}
608 Now the bytes are saved into the file "foo".
609
610 ** XSSaddr,len **
611 Save memory region as S records through X-modem protocol.
612
613 See SS command for more details.
614
615 ** XX **
616 Execute commands received through X-modem protocol
617 This is usually used to receive S-records.
618
619 Example:
620 {{{
621 XX
622 }}}
623 Now press the escape character and at the v09 prompt type
624 {{{
625 usfile
626 }}}
627 where {{{sfile}}} is a file with S-records.
628
629 ** XOnl,eof **
630 Set X-modem text output options, first number type of newline.
631 1=LF, 2=CR, 3=CRLF, second number filler byte at end of file
632 (sensible options include 0,4,1A) These options are used by
633 the XSS command.
634
635 Example: Under a UNIX system you want X-modem's text output with just LF
636 and a filler byte of 0. Type:
637 {{{
638 XO1,0
639 }}}
640
641
642 === Memory Map ===
643
644 Apart from the monitor commands, the monitor program contains I/O routines
645 that can be used by applications started from it.
646
647 === Operating System Facilities ===
648
649
650 | **getchar** | address **$00** Input one character into B register.
651 | **putchar** | address **$03** Output one character in B register.
652 | **getline** | address **$06** Input line at address in X, length in B.
653 | **putline** | address **$09** Output string at address in X, length in B.
654 | **putcr** | address **$0C** Output a newline.
655 | **getpoll** | address **$0F**
656 | **xopenin** | address **$12**
657 | **xopenout** | address **$15**
658 | **xabortin** | address **$18**
659 | **xclosein** | address **$1B**
660 | **xcloseout** | address **$1E**
661 | **delay** | address **$21** On input the D register contains the number of timer ticks to wait. Each timer tick is 20ms
662
663 There are other routines that redirect these I/O operations through the
664 X-modem protocol.
665
666
667
668
669 === Extending the built-in Assembler ===
670
671 EXAMPLE PROGRAMS
672
673 The following example programs you can run from the 6809 monitor.
674 All of them start at address $400. For example to run the program bin2dec
675 you type.
676
677 XL400
678
679 Then press your escape character (default is control-] ).
680
681 Then at the v09 prompt type
682
683 ubin2dec
684
685 Now you see some lines displaying the progress of the X-modem session.
686 If that is finished, you type
687
688 G400
689
690 Now it runs and exits to the monitor with SWI, so that the registers are
691 displayed.
692
693
694 cond09.asm
695 cond09.inc Nonsense program to show conditional assembly and the like.
696
697 bench09.asm Benchmark program. Executes tight loop. Takes 83 secs on
698 25 MHz 386. Should take about 8 sec. on 1MHz real 6809. :-(
699
700 test09.asm Tests some nasty features of the 6809. Prints a few lines
701 of PASSED nn and should never print ERROR nn.
702
703 bin2dec.asm Unusual way to convert numbers to decimal using DAA instruction.
704 Prints some test numbers.
705
706 mon2.asm is an alternative version of the monitor program.
707
708 alt09.rom is a version of the ROM that contains the alternative monitor and
709 Forth. Forth is transferrred to RAM by a small loader.
710 To start Forth type G8000. To start it again, type G400.
711
712
713
714 == The Forth Language. ==
715
716
717 kernel09 and the *.4 files. FORTH for the 6809. To run it, type
718 **XX**
719
720 Then press the escape char (default is control-] ) and at the v09 prompt type:
721
722 **ukernel09**
723
724 Then type
725
726 **G400**
727
728 From FORTH type
729
730 **XLOAD**
731
732 Then press your escape char and at the v09 prompt type
733
734 **uextend09.4**
735
736 From FORTH type
737
738 **XLOAD**
739
740 Then press your escape char and at the v09 prompt type
741
742 **utetris.4**
743
744 From FORTH type
745
746 **TT**
747
748 And play tetris under FORTH on the 6809!
749
750
751 == The BASIC Interpreter. ==
752
753 basic.asm Tiny BASIC by John Byrns. Docs are in basic.doc.
754 To test it start the monitor and run basic.
755
756 Then press your escape char.
757 At the v09 prompt type: sexampl.bas
758
759 Now a BASIC program is input.
760 Type RUN to run it.
761
762 Leave BASIC by pressing the escape char and entering x at the
763 prompt.
764
765
766 == History of the Project. ==
767
768
769
770 === Introduction. ===
771
772
773 Of all the 8-bit home computers only a few had the Motorola 6809 CPU, the
774 most famous of which was the Tandy Color Computer. Then there was its clone
775 (from Wales) the Dragon and there was an old obscure SuperPet that I have
776 never seen. The 6809 was the 8-bit processor finally done right, but it came
777 a bit too late to have a real influence on the market.
778
779 The book that raised my enthousiasm for the Motorola 6809 processor was:
780 Lance A. Leventhal, //6809 Assembly Language Programming//, 1981
781 Osborne/McGrawhill. ISBN 0-07-931035-4. I borrowed it several times from the
782 university library and finally I bought my own copy.
783
784 The first sentence on the back of that book reads:
785 While everyone's been talking about new 16-bit microprocessors, the 6809 has
786 emerged as {{{the}}} important new device.
787
788 Though it was not the processor that changed the world, it certainly was the
789 processor that changed my idea of what a good instruction set should look
790 like. Before that I thought that the Z80 was superior to everything else on
791 the planet, at least superior to every other 8-bit processor.
792
793 It was in April 1987. I borrowed the book for the first time and I had just
794 written a Forth interpreter for my Z80 machine. It struck me that the
795 following 7-instruction sequence on a Z80
796 {{{
797 EX DE,HL
798 LD E,(HL)
799 INC HL
800 LD D,(HL)
801 INC HL
802 EX DE,HL
803 JMP (HL)
804 }}}
805
806 could be replaced by just {{{one}}} instruction on the 6809.
807 {{{
808 JMP [,Y++]
809 }}}
810
811 BTW the above instructions are the heart of a Forth interpreter and making
812 them more efficient has a tremendous effect on efficiency.
813
814
815 === The 6809 Emulator in Forth. ===
816
817
818 The years went by and I had bought an XT compatible computer in 1988. I
819 didn't buy a 6809 system though I could have done so. But it would either be
820 too expensive or I would have to build it myself (I wasn't too handy with
821 soldering) or it would be a primitive machine like the Tandy Color Computer
822 without expansions and I didn't like to use cassettes and a 32-column
823 display.
824
825 In 1989 I saw a 6502 simulator at a meeting of our Forth club. One could
826 interactively enter hex codes, page through memory, modify registers, trace
827 intructions etc. I just got to have this, but for a 6809 instead.
828
829 Around Christmas of that year I wrote a 6809 Forth assembler and an
830 interactive simulator, like the one I had seen on the club meeting.
831 Everything was written in F-PC, a very comprehensive Forth system for the
832 PC.
833
834 {{{
835 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
836 0000 10 8E 00 40 E6 A0 D7 80 8E 00 81 3A 5D 27 07 A6 ...@f W ...:]'.&
837 0010 A0 A7 82 5A 26 F9 7E FF FF 00 00 00 00 00 00 00 '.Z&y~ .......
838 0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
839 0030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
840 0040 05 46 4F 52 54 48 00 00 00 00 00 00 00 00 00 00 .FORTH..........
841 0050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
842 0060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
843 0070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
844 0080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
845 0090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
846 00A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
847 00B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
848 00C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
849 00D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
850 00E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
851 00F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
852 CC=00000000 A=$00 B=$00 DP=$00 X=$0000 Y=$0000 U=$0000 S=$0000
853 EFHINZVC PC=$0000 LDY # $0040
854 }}}
855 Screen snapshot of the Forth-based 6809 simulator
856
857 I even made a start with writing an implementation of Forth for it, but the
858 obvious lack of speed (among other things) witheld me from finishing it.
859 I had a fairly complete set of assembly routines though.
860 The estimated speed was around one thousand instructions per second, good
861 for an equivalent processor speed of around 4kHz.
862
863 In May 1992 I changed my trusted 8MHz Turbo XT for a blistering fast 25MHz
864 80386 and it could run the simulator more than 5 times as fast. But then I
865 wasn't really working on it. In the summer of 1992 I changed to Linux, which
866 I have been using ever since.
867
868 Around the summer of 1993 I was working with pfe, a brand new Forth system
869 for Unix written by Dirk Zoller. It had reached such state of completeness
870 and usability that porting the 6809 simulator to it would be feasible.
871 I ported it and by doing so I regained interest in the 6809 processor.
872 PFE is written in C instead of assembler and at least on the 80386 it is
873 considerably slower than a Forth written in Assembler, like FPC. My
874 simulated processor speed was around 5kHz, nothing to write home
875 about. It was faster than on the XT, but not much.
876
877
878 === The Assembler and Simulator in C. ===
879
880
881 The switch from Forth to C was caused by the fact that I wanted a
882 traditional 6809 assembler, instead of the 'Forth' assembler, in which the
883 syntax is slightly tweaked to make the thing easy to implement in Forth and
884 easy to use within Forth. In the fall of 1993 I wrote a traditional two pass
885 assembler in a few days. It worked more or less, but only recently it has
886 become bug-free in that it assembles all the instructions and all the
887 addressing modes (even PC relative) without error.
888
889 Now that I had a real assembler, I could write real 6809 assembly programs,
890 such as a BASIC interpreter (maybe kidding) or a monitor program or god
891 knows what. If I would ever run real code on that 6809 simulator, I had to
892 increase its speed considerably. So I wrote a very straightforward
893 6809 simulator in C using tables of function pointers. It did really well in
894 terms of speed, I could reach an equivalent processor clock speed of around
895 200kHz. The C simulator didn't have any fancy display, memory edit or single
896 step functions. Its only I/O was through the SWI2 instruction for character
897 output and SWI3 for character input, something I had added to the
898 Forth-based simulator quite some time ago.
899
900 One afternoon in optimized hack mode brought me a crude port of E-Forth, a
901 tiny and very slow (most was interpreted, very few assembler words)
902 implementation of Forth. The original was written in MASM for the 8086 and
903 other ports (like the 8051) wre already around. That was the first time I
904 had Forth on an emulated 6809. BTW this Forth would also run, or should I
905 say crawl, on the Forth-based simulator.
906
907 I released the assembler, simulator and EForth on {{{alt.sources}}} in November
908 1993.
909
910 Of course I also wrote some test and toy programs (what about a program to
911 convert binary numbers to decimal using that oddball DAA instruction?).
912
913 In the spring of 1994 I picked up that old TINY BASIC interpreter written by
914 John Byrns. And tiny it was. Not even arrays were supported. I ported it to
915 my simulator and found some bugs, both in my simulator and in TINY BASIC
916 itself.
917
918 I made some improvements to the 6809 simulator. Now I could send ASCII files
919 to it and log the output to another ASCII file. That way I could 'load' and
920 'save' BASIC programs for one thing. Further I had a trace facility to write
921 a trace of all the instructions in a certain address range to a file. Last I
922 cleaned up the I/O and signal handling somewhat, making it portable across
923 several Unix versions.
924
925 That version of the software, along with some example programs, was also
926 released on {{{alt.sources}}}. The assembler implemented includes and conditional
927 assembly in that version.
928
929
930 === The Virtual SBC. ===
931
932
933 That blistering fast 80386 that I bought back in 1992 has become slow as
934 molasses. It has actually become slower since the memory upgrade with
935 slow memory (it was cheap) that necessitated an extra wait state.
936 Fortunately I recently pruchased a Pentium.
937
938 At the moment I actually have plans to build (or have somebody build for me)
939 a single board computer containing a 6809. I would like to have 32k RAM plus
940 32k EPROM. I definitely like to have a monitor program with the features I
941 want. Hence another project was born, the virtual SBC that I could prototype
942 my monitor ROM and some other software on.
943
944 The virtual SBC emulates a single board computer that communicates with a PC
945 through an ACIA. On that PC there runs a simple terminal program that
946 supports XMODEM file transfer. Things I recently did.
947
948
949 * I rewrote the 6809 emulator engine with giant switch statements to hammerout all unnecessary procedure calls and to gain some speed by enabling thecompiler to use register variables where appropriate. On my 386 thespeed increase was disappointing. The equivalent processor speed is now250kHz, up from about 170kHz (remember that extra wait state?). On a HPUXworkstation, I got a factor of 2 speed increase. That sucker runs at anemulated processor speed of about 3.5MHz. A Pentium-90 is even faster,more than any real 6809 can (officially) run.
950 * I added XMODEM upload/download features to the 'terminal front end' of thesimulator. On the other end of the 'serial link' a 6809 machine codeprogram runs the other end of the XMODEM file transfer protocol.
951 * I changed the SWI2/SWI3 hack to real ACIA emulation at a port address.
952 * I write-protected the ROM area.
953 * I added a 20ms timer interrupt.
954 * I wrote a monitor program for the virtual SBC that has to followinfeatures.
955 ** Simple (vectorized) operating system functions, like character I/Oline I/O, XMODEM transfer. Usable by application programs.
956 ** a hex/ascii dump command.
957 ** a hex/ascii enter command.
958 ** a hex/ascii memory search command.
959 ** memory move command.
960 ** S-record send and receive capabilities (directly in ASCII orthrough XMODEM).
961 ** Binary load and save of memory region through XMODEM
962 ** register display and modify.
963 ** go to address (or current program counter) and call subroutine commands.
964 ** breakpoints.
965 ** program step tracing (breakpoint after next instruction), DEBUG Pcommand
966 ** single step tracing (based on timer interrupt). I had to cheat with theemulator to implement this.
967 ** one-pass (no labels) disassembler (DEBUG U command).
968 ** line-by-line assembler (DEBUG A command) I wrotethis one such that an additional real assembler can use most of the guts ofit.
969
970 Finally I wrote a real 6809 Forth, based on some other Forth I wrote for an
971 imaginary stack machine. Those old dusty primitives that I had written back in
972 1990 proved very useful now. This Forth can load programs through XMODEM
973 too. It can recompile (metacompile) itself and, very importantly, it runs
974 tetris! (crawls on the 386) This is the tetris implementation written in
975 ANSI Forth by Dirk Zoller and it is used as a test program.
976 Next I have to make this Forth ROM-able.
977
978 What else will go into that 32k ROM area? The monitor will be around 7k, 1k
979 is reserved for the I/O space. Forth (with its own Forth assembler) will
980 take about 12k, 8k without. A few additional k could be used for a 'real'
981 assemler, but I doubt I will ever use that. A cross assembler is much more
982 convenient. BASIC no doubt. But I'm afraid I'll have to write it myself,
983 more so as I want to have {{{source code}}} of all my 6809 stuff. I already have
984 the floating point routines for it.
985