Retrocomputing with the 6502

Discussion of chess software programming and technical issues.

Moderators: bob, hgm, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 6:43 pm

Retrocomputing with the 6502

Post by sje » Fri Jun 22, 2007 1:39 am

The 1970s eight bit 6502 CPU was used for quite a few enthusiast computers and also a number of dedicated chess computers. One of the popular 6502 platforms from the Old Days was the KIM-1 single board computer, introduced in 1975 by MOS Technologies. In its default configuration, it had only 1 KB of RAM along with 2 KB of ROM.

Not surprisingly, there was a chess program written for it. Called "Microchess", it fit into the limited memory and could play legal moves. I seem to recall that it also played in one of the early ACM annual events.

Other chess programs were written for the KIM, some requiring more than the 1 KB default RAM.

Anyway, there is a revival kit called the Micro-KIM:

http://www.brielcomputers.com/micro-KIM.html

For US$100, it comes with a huge 5 KB RAM standard along with an RS-232 interface and an expansion header. I'm going to get one of these and try some experiments as time permits.

Carey
Posts: 313
Joined: Wed Mar 08, 2006 7:18 pm
Contact:

Re: Retrocomputing with the 6502

Post by Carey » Fri Jun 22, 2007 2:29 am

sje wrote:Not surprisingly, there was a chess program written for it. Called "Microchess", it fit into the limited memory and could play legal moves. I seem to recall that it also played in one of the early ACM annual events.
I don't think it did.

Later, more advanced versions may have played in a few tournaments at some point, but not the ACM tournaments.

8080 chess played in 1977.

Mike & Sargon 2 played in 1978.

Sargon 3 & MyChess in 1979.

Of course, even Sargon 1 or an early Mike or one of the other very early ones would have easily beaten the first version of Microchess.

I don't know what the strength of the later versions were.

User avatar
hgm
Posts: 23630
Joined: Fri Mar 10, 2006 9:06 am
Location: Amsterdam
Full name: H G Muller
Contact:

Re: Retrocomputing with the 6502

Post by hgm » Fri Jun 22, 2007 10:20 am

Incredible they still sell the required components.

I used to have an AIM-65 machine, which was a KIM-1 derivative manufactured by Rockwell, with 4KB on-board RAM, and a full ASCII keyboard and (LED) display. My Chess program Usurpator II was developed on that.

In my matchbox Chess computer I put 8KB of RAM, because next to the Cess program it also needed to hold system I/O routines (which on the AIM-65 came in ROM).

In stead of the 6502, I used the 65C802 there, which was fully pin (and binary code) compatible with 6502, but allowed higher clock speed. The 6502 had a rather sparse opcode map, most opcodes were reserved for future expansion. The 65802 made good use of that, by expanding the 6502 to a 16-bit machine with 24-bit addressing capability, assigning most of the unused opcodes to new addressing modes (using 16-bit index registers, or 24 bit addresses) and new instructions (operatng on 16-bit wide data).

User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 6:43 pm

Re: Retrocomputing with the 6502

Post by sje » Fri Jun 22, 2007 11:21 am

Actually, the old 6530 RIOT chip (a little RAM plus 1 K ROM) is no longer available, so the Micro-KIM uses a 6530 RIOT and an external ROM. The old custom keypad is replaced by a discrete switch array, and the original two expansion edge connectors are replaced with a two row pin header. The main I/O port is now RS-232 instead of 20 mA current loop and the tape interface is now a future option. Other than the above, it's very close to the original and nearly identical with respect to software and firmware. Oh, and it has 5 KB RAM instead of 1 KB RAM.

There's no provision for a direct connection of a keyboard although it wouldn't be too hard to do if one had a old style ASCII TTL keyboard as was used in the Old Days in machines like the Apple I. Probably the fastest way to do I/O is through the serial port via an external terminal emulator.

If I were running a CS undergraduate program, I'd have every incoming student get one of these boards in the summer prior to admittance. Any student who didn't have fun with it and come up with something creative would be encouraged to change majors.

--------

Writing a chess program in 1 KB of assembler is not very hard if one doesn't care too much about the quality of play. There may be some difficulty implementing repetition detection, but all the other rules should be okay. At least the Micro-KIM monitor ROM has built in routines for keypad and display, so that will help. (The display consists of six 7 segment digits and it's controlled at the segment level. It's also not latched, so it has to be dynamically refreshed.)

With 5 KB RAM, a chess program could show some interesting play, even when limited by the 1 MHz clock and a paltry 200 KIPS.
--------

One of the ideas I have is to use the unit along with some wire wrap and breadboard skills to disassemble ROM contents from a few older dedicated chess computers. With a little patience, it should be possible to decipher the I/O routines and recode these for making an image of the entire chess program that's suitable for emulation.

User avatar
hgm
Posts: 23630
Joined: Fri Mar 10, 2006 9:06 am
Location: Amsterdam
Full name: H G Muller
Contact:

Re: Retrocomputing with the 6502

Post by hgm » Fri Jun 22, 2007 11:42 am

Well, ROMs were custom chips anyway, so this is not really surprising.

My guess is that writing even a 6502 Chess program in 1KB of RAM is actually quite hard. Don't forget that the data should also be put in this RAM, and that the 256 bytes 01xxH are reserved for the hardware stack (of which you cannot be sure how much the system ROM routines will need).

6502 code, with its single accumulator, is actually quite cumbersome, as virtually every operation needs 3 instructions getting the operands from memory (e.g. LDA op1, AND op2, STA res). Even if the operands / results all reside in the direct page, these are all 2-byte instructions. 16-bit operations have to be composed, a 16-bit add takes 7 instructions / 13 bytes (CLC, LDA lo1, ADC lo2, STA reslo, LDA hi1, ADC hi2, STA reshi). This burns bytes fast...

User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 6:43 pm

Re: Retrocomputing with the 6502

Post by sje » Fri Jun 22, 2007 6:16 pm

The lack of 16 bit operations on the 6502 can be alleviated with a good set of library routines. Wozniak did this with his Sweet 16 emulator where the first 32 bytes of page zero was treated as sixteen 16 bit registers. With his code, all "instructions" for 16 bit compare, move, etc., were a single byte with emulated register R0 being the 16 bit accumulator.

Yes, it was slow. But it really shrank the overall code size.

It would be possible to expand on Sweet 16 and have several 64 bit registers and then use these with writing bitboard code. But my suspicion here is that th a 1 MHz clock would limit the resulting chess program to only a few evaluations per second.

Another idea is to go a step further and have the entire application program be interpreted as was done in the UCSD Pascal P-System. This would be rather easier to code, but the slowdown would surely be even worse.

Dan Andersson
Posts: 442
Joined: Wed Mar 08, 2006 7:54 pm

Re: Retrocomputing with the 6502

Post by Dan Andersson » Fri Jun 22, 2007 8:32 pm

For an on board runtime for such small systems a Forth was a common choice. Or a Forth cross compiler.

MvH Dan Andersson

User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 6:43 pm

Re: Retrocomputing with the 6502

Post by sje » Fri Jun 22, 2007 10:11 pm

Yes; I recall when Forth first came out when it was originally developed as a tool for automating amateur telescope control. One could argue that programming the early HP RPN calculators (I had an HP-41C) was rather Forth-like.

I have seen Lisp implementations that would fit into 8 KB, albeit with little space left over for a user program.

User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 6:43 pm

A link to the 6502 Microchess program

Post by sje » Sat Jun 23, 2007 1:17 am

Here's a link to the 6502 Microchess program source:

http://www.6502.org/source/games/uchess/uchess.htm

The code was modified slightly to include serial I/O. A screen shot is included that shows a board display.

User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 6:43 pm

And if you have a Palm handheld

Post by sje » Wed Jun 27, 2007 1:52 pm

And if you have a Palm handheld, there is a nifty KIM-1 emulator:

http://www.genedorr.com/software/vkim.zip

It includes both keypad and TTY I/O. The emulation supports 4 KB RAM and also has all of the ROM contents. Programs may be loaded and saved using memo text files.

Post Reply