Hey what's up guys, Code Monkey King's here.
I'd like to present a new project I've just completed -
it's a chess program written in 6502 assembly that takes only 909 bytes of KIM-1 RAM when loaded:
DATA SEGMENT: 192 bytes (board, move offsets, etc.)
CODE SEGMENT: 717 bytes (search, make move & display)
Project repo and readme: https://github.com/maksimKorzh/6502-chess
Source in 6502 assembly: https://github.com/maksimKorzh/6502-che ... /chess.asm
Source in KIM-1 Paper Tape format: https://github.com/maksimKorzh/6502-che ... /chess.ptp
Prototype in C: https://github.com/maksimKorzh/6502-che ... rc/chess.c
As a development environment I've been using a KIM-1 emulator I've made eariler:
https://maksimkorzh.github.io/KIM-1/
(6502 CPU emulator and assembler are 3rd party projects, I just bundled them together to emulate and develop for KIM-1)
There's also a mobile version with pre-loaded chess on it:
https://maksimkorzh.github.io/KIM-1/mob ... chess.html
Finally you can have a look how I play the whole game of chess vs this engine:
Looking forward to your feedback)
I made a chess program in under 1K of 6502 assembly that runs on an unexpended KIM-1
Moderator: Ras
-
maksimKorzh
- Posts: 775
- Joined: Sat Sep 08, 2018 5:37 pm
- Location: Ukraine
- Full name: Maksim Korzh
I made a chess program in under 1K of 6502 assembly that runs on an unexpended KIM-1
Didactic chess engines:
https://www.chessprogramming.org/Maksim_Korzh
Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ
https://www.chessprogramming.org/Maksim_Korzh
Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ
-
algerbrex
- Posts: 608
- Joined: Sun May 30, 2021 5:03 am
- Location: United States
- Full name: Christian Dean
Re: I made a chess program in under 1K of 6502 assembly that runs on an unexpended KIM-1
Cool project Maksim! One of the next projects I'm planning on doing is actually an emulator, for chip-8 though.maksimKorzh wrote: ↑Sun Jun 12, 2022 3:39 pm Hey what's up guys, Code Monkey King's here.
I'd like to present a new project I've just completed -
it's a chess program written in 6502 assembly that takes only 909 bytes of KIM-1 RAM when loaded:
DATA SEGMENT: 192 bytes (board, move offsets, etc.)
CODE SEGMENT: 717 bytes (search, make move & display)
Project repo and readme: https://github.com/maksimKorzh/6502-chess
Source in 6502 assembly: https://github.com/maksimKorzh/6502-che ... /chess.asm
Source in KIM-1 Paper Tape format: https://github.com/maksimKorzh/6502-che ... /chess.ptp
Prototype in C: https://github.com/maksimKorzh/6502-che ... rc/chess.c
As a development environment I've been using a KIM-1 emulator I've made eariler:
https://maksimkorzh.github.io/KIM-1/
(6502 CPU emulator and assembler are 3rd party projects, I just bundled them together to emulate and develop for KIM-1)
There's also a mobile version with pre-loaded chess on it:
https://maksimkorzh.github.io/KIM-1/mob ... chess.html
Finally you can have a look how I play the whole game of chess vs this engine:
Looking forward to your feedback)
I poked around a little bit in the asm source code as I've never really tried to write a serious program in only assembly before, so I was curious what that would even look like.
I may try playing against it a little later today. What would you say the biggest challenge was in trying to convert chess programming ideas to a much lower level language like assembly?
-
maksimKorzh
- Posts: 775
- Joined: Sat Sep 08, 2018 5:37 pm
- Location: Ukraine
- Full name: Maksim Korzh
Re: I made a chess program in under 1K of 6502 assembly that runs on an unexpended KIM-1
Thank you, it's a very good question.algerbrex wrote: ↑Sun Jun 12, 2022 4:15 pmCool project Maksim! One of the next projects I'm planning on doing is actually an emulator, for chip-8 though.maksimKorzh wrote: ↑Sun Jun 12, 2022 3:39 pm Hey what's up guys, Code Monkey King's here.
I'd like to present a new project I've just completed -
it's a chess program written in 6502 assembly that takes only 909 bytes of KIM-1 RAM when loaded:
DATA SEGMENT: 192 bytes (board, move offsets, etc.)
CODE SEGMENT: 717 bytes (search, make move & display)
Project repo and readme: https://github.com/maksimKorzh/6502-chess
Source in 6502 assembly: https://github.com/maksimKorzh/6502-che ... /chess.asm
Source in KIM-1 Paper Tape format: https://github.com/maksimKorzh/6502-che ... /chess.ptp
Prototype in C: https://github.com/maksimKorzh/6502-che ... rc/chess.c
As a development environment I've been using a KIM-1 emulator I've made eariler:
https://maksimkorzh.github.io/KIM-1/
(6502 CPU emulator and assembler are 3rd party projects, I just bundled them together to emulate and develop for KIM-1)
There's also a mobile version with pre-loaded chess on it:
https://maksimkorzh.github.io/KIM-1/mob ... chess.html
Finally you can have a look how I play the whole game of chess vs this engine:
Looking forward to your feedback)
I poked around a little bit in the asm source code as I've never really tried to write a serious program in only assembly before, so I was curious what that would even look like.
I may try playing against it a little later today. What would you say the biggest challenge was in trying to convert chess programming ideas to a much lower level language like assembly?
The biggest issue for me was to implement 12 local variables on a stack and fetch the return value from the previous stack frame - since I didn't know for sure how that should be done it was intriguing whether it works or not. Apart from this fitting evaluation values into 8 bits was a real pain but even harder thing was to make a signed comparison between a current and the best scores.
CHIP-8 is a good idea, good luck with that!
Didactic chess engines:
https://www.chessprogramming.org/Maksim_Korzh
Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ
https://www.chessprogramming.org/Maksim_Korzh
Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ
-
algerbrex
- Posts: 608
- Joined: Sun May 30, 2021 5:03 am
- Location: United States
- Full name: Christian Dean
Re: I made a chess program in under 1K of 6502 assembly that runs on an unexpended KIM-1
Thanks, it should be a fun project. I remember I started one a couple of years ago but never finished it. I'll probably use it as an excuse to learn a new language. I'm thinking either Rust, or a functional programming language like Ocaml, since I don't know either of those very well.
Either way though, congrats!
-
maksimKorzh
- Posts: 775
- Joined: Sat Sep 08, 2018 5:37 pm
- Location: Ukraine
- Full name: Maksim Korzh
Re: I made a chess program in under 1K of 6502 assembly that runs on an unexpended KIM-1
Thank you)algerbrex wrote: ↑Sun Jun 12, 2022 6:37 pmThanks, it should be a fun project. I remember I started one a couple of years ago but never finished it. I'll probably use it as an excuse to learn a new language. I'm thinking either Rust, or a functional programming language like Ocaml, since I don't know either of those very well.
Either way though, congrats!
Didactic chess engines:
https://www.chessprogramming.org/Maksim_Korzh
Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ
https://www.chessprogramming.org/Maksim_Korzh
Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ
-
mvanthoor
- Posts: 1784
- Joined: Wed Jul 03, 2019 4:42 pm
- Location: Netherlands
- Full name: Marcel Vanthoor
Re: I made a chess program in under 1K of 6502 assembly that runs on an unexpended KIM-1
This is both a completely useless but also completely epic project. I'd personally never write something like this, but as an embedded software engineer, I can appreciate it
I'll certainly go and take a look at this series.
-
hgm
- Posts: 28426
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: I made a chess program in under 1K of 6502 assembly that runs on an unexpended KIM-1
As if writing a new program for orthodox chess for PC or Mac is anything less than useless... This is why they call it a 'hobby'. 
-
maksimKorzh
- Posts: 775
- Joined: Sat Sep 08, 2018 5:37 pm
- Location: Ukraine
- Full name: Maksim Korzh
Re: I made a chess program in under 1K of 6502 assembly that runs on an unexpended KIM-1
Mr. Muller don't you like how your MicroMax 3 nested loop idea for generating moves fits into KIM-1?
And also exactly thankfully to you I've considered signed comparison of score and best score!
Didactic chess engines:
https://www.chessprogramming.org/Maksim_Korzh
Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ
https://www.chessprogramming.org/Maksim_Korzh
Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ
-
maksimKorzh
- Posts: 775
- Joined: Sat Sep 08, 2018 5:37 pm
- Location: Ukraine
- Full name: Maksim Korzh
Re: I made a chess program in under 1K of 6502 assembly that runs on an unexpended KIM-1
Hi Marcel, thank you for your feedback.mvanthoor wrote: ↑Mon Jun 13, 2022 2:13 pmThis is both a completely useless but also completely epic project. I'd personally never write something like this, but as an embedded software engineer, I can appreciate it(Did you also write the emulator yourself? In that case it would be very hard to find out of something that goes wrong is actually wrong in the chess program, or if the problem is in the emulator...)
I'll certainly go and take a look at this series.
Yes I made the emulator, but I've bundled existing 6502 CPU emulator. As for emulator's accuracy - it runs most of the original KIM-1 software including KIM venture by Bob Leedom which no other existing emulator I know can handle. I'm in touch with a friend owning a couple of original KIMs and a few modern replicas like Corsham KIM and PAL-1. He has tested my program on all the hardware he has and it works exactly the same as on the emulator.
Didactic chess engines:
https://www.chessprogramming.org/Maksim_Korzh
Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ
https://www.chessprogramming.org/Maksim_Korzh
Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ
-
Rebel
- Posts: 7435
- Joined: Thu Aug 18, 2011 12:04 pm
- Full name: Ed Schröder
Re: I made a chess program in under 1K of 6502 assembly that runs on an unexpended KIM-1
Nice to see the good old 6502 code.
One thing
One nice thing of the 6502 is after a load into memory the Zero Flag and Negative Flag are automatically set, meaning you can skip the CMP #$00 instruction.
One thing
Code: Select all
LDA BOARD,Y ; occupied by pieces
CMP #$00 ;
BNE SCR ;90% of coding is debugging, the other 10% is writing bugs.