conway's game of life
This commit is contained in:
parent
9ff541a0d3
commit
82a2c992d9
3
Makefile
3
Makefile
|
@ -1,8 +1,7 @@
|
|||
MACHINE=mac99
|
||||
PPC=powerpc-linux-gnu
|
||||
QEMU=qemu-system-ppc
|
||||
RES=1280x768x32
|
||||
|
||||
RES=1360x720x32
|
||||
DISK.APM: kernel.elf bootinfo.txt scripts/kpartx.sh
|
||||
dd bs=512K count=2 if=/dev/zero of=DISK.APM
|
||||
parted DISK.APM --script mklabel mac mkpart primary hfs+ 32.8KB 100%
|
||||
|
|
132
entry/boot.c
132
entry/boot.c
|
@ -1,22 +1,35 @@
|
|||
#include "boot.h"
|
||||
void __stack_chk_fail_local(void){}
|
||||
|
||||
void get_io_type(void)
|
||||
{
|
||||
if (*(unsigned char*)__VRAM__BEIGE == beige) IO_TYPE = beige;
|
||||
else if (*(unsigned char*)__VRAM__MAC99 == mac99) IO_TYPE = mac99;
|
||||
if (IO_TYPE == beige)
|
||||
{
|
||||
screen_width = (*(unsigned int*)(__VRAM__BEIGE+4));
|
||||
screen_height = (*(unsigned int*)(__VRAM__BEIGE+8));
|
||||
|
||||
}
|
||||
else if (IO_TYPE == mac99)
|
||||
{
|
||||
screen_width = (*(unsigned int*)(__VRAM__MAC99+4));
|
||||
screen_height = (*(unsigned int*)(__VRAM__MAC99+8));
|
||||
}
|
||||
}
|
||||
void init(void)
|
||||
{
|
||||
if (IO_TYPE == beige)
|
||||
{
|
||||
for(;;); // unsupported yet.
|
||||
p_vram = __VRAM__BEIGE;
|
||||
p_bios = __BIOS__BEIGE;
|
||||
p_timer= __TIMR__BEIGE;
|
||||
}
|
||||
else if (IO_TYPE == mac99)
|
||||
{
|
||||
p_vram = __VRAM__MAC99;
|
||||
p_bios = __BIOS__MAC99;
|
||||
p_mouse=__MOUSE__MAC99;
|
||||
p_keyboard=__KEYBOARD__MAC99;
|
||||
p_timer= __TIMR__MAC99;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,29 +37,96 @@ void main(void)
|
|||
{
|
||||
get_io_type();
|
||||
init();
|
||||
int N = screen_width;
|
||||
int i,j,ip1,jp1,nei;
|
||||
unsigned int random;
|
||||
unsigned char universe[N][N];
|
||||
unsigned char universe2[N][N];
|
||||
for (i = 0; i < N; i++) for (j = 0; j < N; j++)
|
||||
{
|
||||
random = (*p_timer );
|
||||
if (!(random%3)) universe[i][j] = 1;
|
||||
else universe[i][j] = 0;
|
||||
p_bios++;
|
||||
}
|
||||
for(;;)
|
||||
{
|
||||
memcpy_24bit(0x81000000, p_mouse, 1, 0x100000);
|
||||
init();
|
||||
for (i = 0; i < N; i++) for (j = 0; j < N; j++)
|
||||
{
|
||||
if (universe[i][j]) fillscreen(p_vram, 255,255,255,1);
|
||||
else fillscreen(p_vram,200 ,110,50,1);
|
||||
p_vram+=4;
|
||||
}
|
||||
for (i = 0; i < N; i++) for (j = 0; j < N; j++) universe2[i][j] = universe[i][j];
|
||||
for (i = 0; i < N; i++) for (j = 0; j < N; j++)
|
||||
{
|
||||
nei = 0;
|
||||
ip1 = i + 1;
|
||||
jp1 = j + 1;
|
||||
if (i == N) ip1=0;
|
||||
if (j == N) jp1=0;
|
||||
if (!i) ip1=N;
|
||||
if (!j) jp1=N;
|
||||
if (universe[i][jp1]) nei++;
|
||||
if (universe[ip1][j]) nei++;
|
||||
if (universe[i][j-1]) nei++;
|
||||
if (universe[i-1][j]) nei++;
|
||||
if (universe[ip1][jp1]) nei++;
|
||||
if (universe[ip1][j-1]) nei++;
|
||||
if (universe[i-1][jp1]) nei++;
|
||||
if (universe[i-1][j-1]) nei++;
|
||||
|
||||
if (universe[i][j])
|
||||
{
|
||||
if (nei == 2 || nei == 3) universe2[i][j] = universe[i][j];
|
||||
else universe2[i][j] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (nei == 3) universe2[i][j] = 1;
|
||||
else universe2[i][j] = universe[i][j];
|
||||
}
|
||||
|
||||
}
|
||||
for (i = 0; i < N; i++) for (j = 0; j < N; j++) universe[i][j] = universe2[i][j];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void fillscreen(unsigned char a, unsigned char b, unsigned char c, int n)
|
||||
void fillscreen(unsigned int* addr, unsigned char a, unsigned char b, unsigned char c, int n)
|
||||
{
|
||||
init();
|
||||
unsigned char* ptr = addr;
|
||||
for (unsigned int i = 0; i<n; i++)
|
||||
{
|
||||
//24-bit VGA
|
||||
*p_vram = 0;
|
||||
p_vram++;
|
||||
*p_vram = a;
|
||||
p_vram++;
|
||||
*p_vram = b;
|
||||
p_vram++;
|
||||
*p_vram = c;
|
||||
p_vram++;
|
||||
*ptr = a;
|
||||
ptr++;
|
||||
*ptr = b;
|
||||
ptr++;
|
||||
*ptr = c;
|
||||
ptr++;
|
||||
*ptr = 0;
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
void colorscreen(unsigned int* addr, unsigned char a, unsigned char b, unsigned char c, int n)
|
||||
{
|
||||
unsigned char* ptr = addr;
|
||||
for (unsigned int i = 0; i<n; i++)
|
||||
{
|
||||
//24-bit VGA
|
||||
*ptr = a;
|
||||
ptr++;
|
||||
*ptr = b;
|
||||
ptr++;
|
||||
ptr++;
|
||||
*ptr = 0;
|
||||
ptr++;
|
||||
}
|
||||
|
||||
}
|
||||
void memcpy(unsigned char* dest, unsigned char* src, int n)
|
||||
{
|
||||
unsigned char* destination = dest;
|
||||
|
@ -57,31 +137,11 @@ void memcpy(unsigned char* dest, unsigned char* src, int n)
|
|||
destination++; source++;
|
||||
}
|
||||
}
|
||||
void memcpy_24bit(unsigned char* dest, unsigned char* src, int n, int size)
|
||||
{
|
||||
unsigned char* destination = dest;
|
||||
unsigned char* source = src;
|
||||
for (int i = 0; i<n; i++)
|
||||
{
|
||||
for (int k = 0; k < size; k++)
|
||||
{
|
||||
*destination = 0;
|
||||
destination++;
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
*destination = *source;
|
||||
destination++;
|
||||
}
|
||||
}
|
||||
source++;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char u8_extract_bit(unsigned char n, unsigned char bit)
|
||||
{
|
||||
return (n & (0b10000000 >> bit)) >> (7 - bit);
|
||||
return (n & (0b10000000 >> bit)) >> (7 - bit);
|
||||
}
|
||||
|
||||
unsigned char u32_extract_bit(unsigned int n, unsigned char bit)
|
||||
{
|
||||
return (n & (0x80000000 >> bit)) >> (31 - bit);
|
||||
|
|
21
entry/boot.h
21
entry/boot.h
|
@ -3,22 +3,25 @@
|
|||
|
||||
#define __VRAM__BEIGE 0x80000000
|
||||
#define __BIOS__BEIGE 0xFFC00000
|
||||
|
||||
#define __TIMR__BEIGE 0x1badc0de //later
|
||||
#define __VRAM__MAC99 0x81000000
|
||||
#define __BIOS__MAC99 0XFFF00000
|
||||
#define __MOUSE__MAC99 0x8008003C
|
||||
#define __KEYBOARD__MAC99 0x80080038
|
||||
#define __BIOS__MAC99 0xFFF00000
|
||||
#define __TIMR__MAC99 0x80080038
|
||||
void __stack_chk_fail_local();
|
||||
|
||||
unsigned char IO_TYPE;
|
||||
unsigned int screen_width;
|
||||
unsigned int screen_height;
|
||||
|
||||
unsigned char* p_vram;
|
||||
unsigned char* p_bios;
|
||||
unsigned char* p_keyboard;
|
||||
unsigned char* p_mouse;
|
||||
|
||||
unsigned char* p_timer;
|
||||
unsigned char u8_extract_bit(unsigned char n, unsigned char bit);
|
||||
void get_io_type(void);
|
||||
void init(void);
|
||||
void fillscreen(unsigned char a, unsigned char b, unsigned char c, int n);
|
||||
void fillscreen(unsigned int* addr, unsigned char a, unsigned char b, unsigned char c, int n);
|
||||
void memcpy(unsigned char* dest, unsigned char* src, int n);
|
||||
void memcpy_24bit(unsigned char* dest, unsigned char* src, int n, int size);
|
||||
unsigned char u8_extract_bit(unsigned char n, unsigned char bit);
|
||||
unsigned char u32_extract_bit(unsigned int n, unsigned char bit);
|
||||
void colorscreen(unsigned int* addr, unsigned char a, unsigned char b, unsigned char c, int n);
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
.globl _start
|
||||
_start:
|
||||
_start:
|
||||
b main
|
||||
|
|
|
@ -4,21 +4,23 @@
|
|||
: sup - dup abs = ;
|
||||
: inf dup sup 1 + ;
|
||||
: diff = if 0 else -1 then ;
|
||||
|
||||
: fba frame-buffer-adr ;
|
||||
: beige-vram 80000000 ; : mac99-vram 81000000 ;
|
||||
|
||||
: beige-error ." G3 Beige machine is not supported yet. Please run it with a post-1999 PowerPC Mac." ;
|
||||
: hardware-error ." Hardware not supported." ;
|
||||
variable run
|
||||
|
||||
fba beige-vram = if ." Beige hardware detected" cr 0BE beige-vram c! then
|
||||
fba mac99-vram = if ." mac99 hardware detected" cr 05A mac99-vram c! then
|
||||
|
||||
fba beige-vram = if screen-width 4 beige-vram + l! then
|
||||
fba beige-vram = if screen-height 8 beige-vram + l! then
|
||||
|
||||
fba mac99-vram = if screen-width 4 mac99-vram + l! then
|
||||
fba mac99-vram = if screen-height 8 mac99-vram + l! then
|
||||
|
||||
variable run
|
||||
-1 run !
|
||||
|
||||
fba beige-vram = if beige-error cr 100 0 do 0BE i beige-vram + c! loop then
|
||||
fba mac99-vram = if ." mac99" cr 100 0 do 05A i mac99-vram + c! loop then
|
||||
fba beige-vram diff fba mac99-vram diff and if hardware-error cr 0 run ! then
|
||||
|
||||
run @ 0 = if 1 0 do 0 +loop then
|
||||
80080000 100 dump
|
||||
80080000 100 dump
|
||||
80080000 100 dump
|
||||
boot hd:,\boot\kernel.elf
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue