TinyLife-6502

Programming the 6502 microprocessor and its relatives in assembly and other languages.
Post Reply
orac81
Posts: 53
Joined: 20 Apr 2024
Location: uk

TinyLife-6502

Post by orac81 »

TINYLIFE-6502
lifet06b.zip
(9.83 KiB) Downloaded 35 times
https://github.com/orac81/miniapples/ra ... fet06b.zip
screen-lifet-c64.png
screen-lifet-c64.png (1.34 KiB) Viewed 925 times

This is a "size-code" version of the classic LIFE game, for the Commodore C64, C16, VIC20, PET. The smallest version is 126 bytes (see smallbin folder), but I recommend using the slightly bigger version with built in edit and help.

To use, just edit using the PET editor to create the patterns using the letter "O" for the cells.
Note that the program is very simple, ie. it doesnt handle screen
wrap properly. But it is quite fast.

The "small" version needs the user to edit before running. Put the "run" command on the 2nd line. This version needs VIC20 users to type:
POKE 36879,8:print chr$(5)chr$(147) before editing.

To avoid all that, use the "big" version!

Released as FREE/GPL3 software, source included.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: TinyLife-6502

Post by BigEd »

126 bytes is an extraordinary achievement! Well done... there was a 256 byte program mentioned previously - follow the breadcrumbs here (or go direct).
User avatar
Broti
Posts: 28
Joined: 07 Sep 2023
Location: Moers, Germany

Re: TinyLife-6502

Post by Broti »

Cool. It would even fit in RAM on the Atari 2600. ^.^
ROR A? Where we're coding, we don't need A.
orac81
Posts: 53
Joined: 20 Apr 2024
Location: uk

Re: TinyLife-6502

Post by orac81 »

Thanks! This version will go down by 12 bytes (to 114 bytes) if you loose the basic stub and start with a sys. But it does rely on the PET editor to setup the start pattern, some machines dont have that. As a simple hack you could just fill the screen with random data to start.
The code depends on having a pet style mem mapped char screen. So it might transfer to uk101 or BBC text mode or Apple2 text (with address translation) but other bitmap screen 6502 systems (oric?) would need additional code. I don't think the Atari 2600 has enough screen ram for a useful life demo, unless you use a cart with extra ram. Most sizecode stuff is very system dependant.

The code makes a complete copy of the screen with just bit 0 kept, so each byte is 0 or 1. Letter O or petscii "ball" (81) have bit 0 set. It then uses this code to count the surrounding cells:

Code: Select all

CLC ; Add 8 surrounding cell values together
LDA (ZWORK),Y
INY
ADC (ZWORK),Y
INY
ADC (ZWORK),Y
LDY #VDUX
ADC (ZWORK),Y
INY
INY
ADC (ZWORK),Y
LDY #VDUX+VDUX
ADC (ZWORK),Y
INY
ADC (ZWORK),Y
INY
ADC (ZWORK),Y
; A=Surrounding cell count
Now if you kept a 3 line rolling wrap around 256 byte buffer instead you can just use 8 ADC abs,Y instructions, which will be faster.
You could implement proper wrap around at the same time. That would make the code bigger that 126 bytes though.

A version using Petscii quarter pixel gfx would give 80x50, with the right code using that method should be quite fast. It would need a special editor for it.
Last edited by orac81 on Tue Nov 18, 2025 1:00 pm, edited 1 time in total.
teamtempest
Posts: 443
Joined: 08 Nov 2009
Location: Minnesota
Contact:

Re: TinyLife-6502

Post by teamtempest »

Quote:
t would need a special editor for it.

You could also use the regular screen editor and treat that as being a 1/4 size (40x25) starting point for the "whole" (80x50) screen. Basically the same program, just with more room to "evolve". Might cost a few more bytes to do the translation, though.
orac81
Posts: 53
Joined: 20 Apr 2024
Location: uk

Re: TinyLife-6502

Post by orac81 »

Yes, but with the current code you hit a key to stop, edit, then restart with ENTER, which is a nice feature for such a small program. Really if you make a quarter char pixel version, you break the "small code" because of look ups to handle that at speed, so you might as add code for edit, proper wrapping etc..
I forgot to say this runs on C128, and 8032 too.
Post Reply