1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-12-23 08:29:35 +00:00

Port "life" example to C264 and A8

This commit is contained in:
Karol Stasiak 2019-07-12 13:30:50 +02:00
parent 98f35937e3
commit 156c1c0413
2 changed files with 70 additions and 5 deletions

View File

@ -18,7 +18,7 @@
* [Bell](crossplatform/bell.mfk) (Apple II/ZX Spectrum) a program that goes \*ding!\*
* [Life](crossplatform/life.mfk) (C64/ZX Spectrum) Conway's game of life
* [Life](crossplatform/life.mfk) (C64/C16/Atari/ZX Spectrum) Conway's game of life
## Commodore 64 examples

View File

@ -1,4 +1,4 @@
#if CBM_64
#if CBM_64 || CBM_264
const byte width = 40
const byte height = 25
#endif
@ -6,17 +6,22 @@ const byte height = 25
const byte width = 32
const byte height = 24
#endif
#if ATARI_8
const byte width = 40
const byte height = 24
#endif
const word area = word(width) * word(height)
// representation: $1 live now $80 live soon
const byte ALIVE = $81
const byte DEAD = 0
array buffer [width * height] align(256)
void init_buffer() {
pointer p
for p,buffer.addr,paralleluntil,buffer.addr+area {
p[0] = 0
p[0] = DEAD
}
// glider:
buffer[1*width + 2] = ALIVE
@ -59,8 +64,8 @@ void do_round() align(fast) {
p = buffer.addr
for j,0,paralleluntil,height {
for x,0,paralleluntil,width {
if p[x] & $80 != 0 { p[x] = $81 }
else { p[x] = 0 }
if p[x] & $80 != 0 { p[x] = ALIVE }
else { p[x] = DEAD }
}
p += width
}
@ -103,6 +108,66 @@ void wait_frame() align(fast) {
}
#endif
#if CBM_264
void init_gfx() {
}
void redraw() align(fast) {
pointer src, dest
byte x, y
src = buffer.addr
dest = $c00
for y,0,until,height {
for x,0,until,width {
if src[x] != 0 {
dest[x] = 128 + ' '
} else {
dest[x] = ' '
}
}
src += width
dest += width
}
}
void wait_frame() align(fast) {
while ted_raster_y != $ff {}
while ted_raster_y == $ff {}
}
#endif
#if ATARI_8
pointer screen_start @$58
byte clock @$14
void init_gfx() {
}
void redraw() align(fast) {
pointer src, dest
byte x, y
src = buffer.addr
dest = screen_start
for y,0,until,height {
for x,0,until,width {
if src[x] != 0 {
dest[x] = 128 + ' 'scr
} else {
dest[x] = ' 'scr
}
}
src += width
dest += width
}
}
void wait_frame() align(fast) {
while clock != clock {}
}
#endif
#if ZX_SPECTRUM
void init_gfx() {