"Connect 4" conversion from BASIC to Machine Code

Post Reply
User avatar
mz-80a
Posts: 93
Joined: Thu Jan 25, 2018 10:46 am
Location: Devon, UK
Contact:

"Connect 4" conversion from BASIC to Machine Code

Post by mz-80a » Sun Sep 16, 2018 6:46 pm

I recently made it a challenge for myself to convert the game "Connect 4" from the BASIC listing found on Page 24 of "Peeking and Pokeing the MZ-80A" by G. P. Ridley to machine code. It's probably taken me around a week to do with lots of debugging and wondering why certain routines that seemed logical to me weren't behaving as expected (the routine which finds a winning line of 4, for instance, had a few re-writes before I got a working behaviour out of it!). As a bit of an amateur assembly language programmer this feels like a big deal to me :) I didn't realise, at first glance, how complicated some of the BASIC listing was. I thought it would be an easy game to convert to machine code but lots of bits tripped me up. I had to also take an already-written multiplication maths routine from the web (no point in re-inventing the wheel).

I am going to put a code comparison between the BASIC and assembly language versions on my website soon and am also part way through fully writing all this up for an SUC newsletter.

As for now, I have attached the finished game to this post. The ZIP file contains the original BASIC version (as typed in by my friend Joachim - it was because of him that I decided to set myself this challenge and to hopefully show him a few assembly language instructions too), the machine code version and the object code (compatible with the ZEN assembler).

Joachim also has an article on his website here about his experience typing in Connect 4:

https://spillhistorie.no/2018/09/04/spi ... rp-mz-80a/

As far as my assembly code goes : I could have written the code in a much more efficient manner but have decided to leave it so that it more closely matches the BASIC algorithms. Anyway, files are attached here.
CONNECT4.zip
(5.16 KiB) Downloaded 15 times
MZ-80A Secrets
https://mz-80a.com/

Sharpworks (Sharp MZ homebrew)
http://mz-sharpworks.co.uk/

User avatar
mz-80a
Posts: 93
Joined: Thu Jan 25, 2018 10:46 am
Location: Devon, UK
Contact:

Re: "Connect 4" conversion from BASIC to Machine Code

Post by mz-80a » Mon Sep 17, 2018 12:36 am

And forgot to put a link to Peeking and Pokeing. The Connect 4 listing is on Page 24 here:

https://mz80a.files.wordpress.com/2015/ ... gmz80a.pdf
MZ-80A Secrets
https://mz-80a.com/

Sharpworks (Sharp MZ homebrew)
http://mz-sharpworks.co.uk/

User avatar
mz-80a
Posts: 93
Joined: Thu Jan 25, 2018 10:46 am
Location: Devon, UK
Contact:

Re: "Connect 4" conversion from BASIC to Machine Code

Post by mz-80a » Tue Oct 30, 2018 3:04 pm

Whoops... in the ZIP file I named something incorrectly.
"CONNECT4-OBJ.MZF" should actually be named "CONNECT4-SRC.MZF" as it is the source code, not the object code.
Also, I am still writing up the notes comparing the BASIC code with the assembly code, still to come in this post.
MZ-80A Secrets
https://mz-80a.com/

Sharpworks (Sharp MZ homebrew)
http://mz-sharpworks.co.uk/

Post Reply