1k zx chess sources question

Discussion of chess software programming and technical issues.

Moderators: hgm, Dann Corbit, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
User avatar
hgm
Posts: 26576
Joined: Fri Mar 10, 2006 9:06 am
Location: Amsterdam
Full name: H G Muller
Contact:

Re: 1k zx chess sources question

Post by hgm » Wed Jul 21, 2021 5:08 pm

maksimKorzh wrote:
Wed Jul 21, 2021 3:42 pm
So say for 1k zx chess both source code and chess data structures (like board array) were fitting only 1k of RAM!
You are making improper use of the term 'source code'. The executable read-only part of 1k zx chess that is in RAM was most likely Z80 machine code. That is called 'object code', similar to what is in a Windows .exe file, not source code. If 1k zx chess was written in assembler, the assembly source code would be human-readable text, encoded as 1 character per byte ascii codes. A single instruction like " MOVB AL,BH", which would fit into a single byte in x86 machine code, would thus be 12 bytes of source code (counting the obligatory newline as 1).

If 1k zx chess would have been a BASIC program, the program code would have been some intermediate 'basic code' (e.g. where the BASIC keywords and the variable names were each represented by a single byte), which would be executed by the interpreter in ROM. It would still not be 'source code'.

After writing the 6800 program, (which was done on the computer of a friend), I obtained a 6502-based computer (the AIM-65) with 4KB, which I expanded to 12KB. There the ROM really contained a text editor, which could edit assembly source code in RAM, and an assembler to translate the text in the edit buffer to machine code. I used that to develop a chess program that used the lowest 5K of memory when executing (code from 0x200 to 0x1400, data from 0 to 0x200), and used the remainder of the memory as edit buffer for the source code. Later I put the machine code for that program into a home-built computer that fitted in a small matchbox. (This used an 8KB CMOS RAM with a watch battery for data retention, and no ROM.)

Gerd Isenberg
Posts: 2246
Joined: Wed Mar 08, 2006 7:47 pm
Location: Hattingen, Germany

Re: 1k zx chess sources question

Post by Gerd Isenberg » Wed Jul 21, 2021 6:46 pm

maksimKorzh wrote:
Wed Jul 21, 2021 7:32 am
Hi guys, I have a few questions on 1k zx chess by David Horne:
1. 1K means 1K of RAM?
2. Were there any limitations on source code size?
3. Is it written in assembly because BASIC interpreter takes some RAM on it's own?
4. Are there any ports of 1k zx chess from assembly to whatever languages?
I'm just really interested how one of the pioneer programs look liked in terms of design patterns
and it would be great to figure that out without learning zx assembly)
But if there's no other choice than any references on zx assembly docs?
1K ZX Chess with code size of 672 bytes in Ram is "open source", see Your Computer article. Source code is Z80 assembly.
One Z80 assembly instruction translates to one to three bytes of machine code. The ZX81 had an 8 KB ROM with the operating system, the Sinclair BASIC interpreter, and one KB of RAM, which could be expanded externally to 16 KiB. Z80 machine code could be encoded in Basic comment lines (rem).

For Z80 assembly see Z-80 and 8080 assembly language programming by Sargon co-author Kathe Spracklen. Also Rodnay Zaks' Programming the Z80 is available online.

User avatar
maksimKorzh
Posts: 724
Joined: Sat Sep 08, 2018 3:37 pm
Location: Ukraine
Full name: Maksim Korzh
Contact:

Re: 1k zx chess sources question

Post by maksimKorzh » Fri Jul 23, 2021 1:44 pm

hgm wrote:
Wed Jul 21, 2021 5:08 pm
maksimKorzh wrote:
Wed Jul 21, 2021 3:42 pm
So say for 1k zx chess both source code and chess data structures (like board array) were fitting only 1k of RAM!
You are making improper use of the term 'source code'. The executable read-only part of 1k zx chess that is in RAM was most likely Z80 machine code. That is called 'object code', similar to what is in a Windows .exe file, not source code. If 1k zx chess was written in assembler, the assembly source code would be human-readable text, encoded as 1 character per byte ascii codes. A single instruction like " MOVB AL,BH", which would fit into a single byte in x86 machine code, would thus be 12 bytes of source code (counting the obligatory newline as 1).

If 1k zx chess would have been a BASIC program, the program code would have been some intermediate 'basic code' (e.g. where the BASIC keywords and the variable names were each represented by a single byte), which would be executed by the interpreter in ROM. It would still not be 'source code'.

After writing the 6800 program, (which was done on the computer of a friend), I obtained a 6502-based computer (the AIM-65) with 4KB, which I expanded to 12KB. There the ROM really contained a text editor, which could edit assembly source code in RAM, and an assembler to translate the text in the edit buffer to machine code. I used that to develop a chess program that used the lowest 5K of memory when executing (code from 0x200 to 0x1400, data from 0 to 0x200), and used the remainder of the memory as edit buffer for the source code. Later I put the machine code for that program into a home-built computer that fitted in a small matchbox. (This used an 8KB CMOS RAM with a watch battery for data retention, and no ROM.)
Thank you for clarification!
Mr. Muller, do you think it's possible to port micro max to zx spectrum the following way:
1. rewrite source code in zx basic
2. type it into emulator line by line
I'm actually going to try it...

User avatar
maksimKorzh
Posts: 724
Joined: Sat Sep 08, 2018 3:37 pm
Location: Ukraine
Full name: Maksim Korzh
Contact:

Re: 1k zx chess sources question

Post by maksimKorzh » Fri Jul 23, 2021 1:48 pm

Gerd Isenberg wrote:
Wed Jul 21, 2021 6:46 pm
maksimKorzh wrote:
Wed Jul 21, 2021 7:32 am
Hi guys, I have a few questions on 1k zx chess by David Horne:
1. 1K means 1K of RAM?
2. Were there any limitations on source code size?
3. Is it written in assembly because BASIC interpreter takes some RAM on it's own?
4. Are there any ports of 1k zx chess from assembly to whatever languages?
I'm just really interested how one of the pioneer programs look liked in terms of design patterns
and it would be great to figure that out without learning zx assembly)
But if there's no other choice than any references on zx assembly docs?
1K ZX Chess with code size of 672 bytes in Ram is "open source", see Your Computer article. Source code is Z80 assembly.
One Z80 assembly instruction translates to one to three bytes of machine code. The ZX81 had an 8 KB ROM with the operating system, the Sinclair BASIC interpreter, and one KB of RAM, which could be expanded externally to 16 KiB. Z80 machine code could be encoded in Basic comment lines (rem).

For Z80 assembly see Z-80 and 8080 assembly language programming by Sargon co-author Kathe Spracklen. Also Rodnay Zaks' Programming the Z80 is available online.
Thanks for sharing Gerd!
I'm already aware of articles but couldn't find books on zx80 assembly yet.
Those you've provided links for seem to be very promising!

Post Reply