News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

Life - Back to basics (and z80 asm)

Started by goksteroo, 09:05, 01 March 20

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

goksteroo

My CPC journey - 2019

An experiment in relearning Locomotive Basic and Z80 Machine Code

I had a 464 then a 6128 back when they were first released in Australia. I played games, programmed many basic games and utilities (even had some published in various magazines of the day) and taught myself Z80 code to write some utilities, RSXs and games. unfortunately I sold my machines along with all my discs/tapes when I upgraded to a 16bit machine.

Zip along to 2018 and I'm now retired and getting into retro gaming to relive my youth! Among my finds was WinApe - great for replaying some of my favourite CPC games like Sorcery, Knight Lore, Elite, Spindizzy, Boulder Dash, etc etc etc. Eventually (or very quickly) I noticed the built in Assembly and this brought back memories of my attempts at Z80 coding.

I decided to try my hand at locomotive basic again and chose and old friend of mine, Conway's Game of LIFE, to tackle. This not really a game, more a mathematical model of population growth within a set of rules - see below. A simple programme that involves a lot of simple maths. This didn't take long to do once I mastered the conversion of PC keys to CPC keys. I planned an 80x25 board for the game so it wasn't real fast in displaying each generation - 43.5 Secs per generation

I then remembered integer maths was a faster way of doing Basic calculations so added a DEFINT command at the beginning of the program. Much better speed now - 29.1 sec per generation.

I found a copy of Fast basic compiler and compiled the program to see the speed difference. Much, much better now - 6.4 secs per generation.

Then I grabbed life by the goonies and tackled a Z80 assembly version. Wow, what a learning/remembering curve that was. About all I could recall was LD hl,a but that was a start. Much reading and experimenting later I had a routine to draw the screen done. Whoohoo!

Then much more reading, a lot of coffee, head scratching, swearing, sweating and stubbornness I had a programme that actually assembled and worked. The speed difference was incredible - 1.2 Secs per Generation. Now I remember why I started to learn M/Code all those years ago.... speed.

Well, that's my journey back into the CPC world over the last few weeks. It will continue.

Geoff

Attached file - LIFE.RAR
            - LIFE.TXT - This file!
            - LIFE.ASM - machine code listing for Life
            - LIFE.DSK - CPC Disc Image
                - LIFE.BAS - Basic listing of Life
                - LIFE-INT.BAS - Basic listing using Integers - 1 line addition!
                - LIFE-COM.BIN - Compiled basic using Fast Basic Compiler
                - LIFE.BIN - Assembled M/Code version

Timings - Timer started when file name pressed so included loading time and stopped when 10 generations displayed.

Programme    10 Gen Time in Min.Sec        Seconds per Generation
LIFE .BAS                              7.15                43.5
LIFE-INT.BAS                         4.51                29.1
LIFE.COMP.BIN                      1.04                 6.4
LIFE.BIN                                 .12                 1.2

Powered by SMFPacks Menu Editor Mod