Minimal functional AppleII code

This commit is contained in:
Christophe Meneboeuf 2016-09-15 00:01:04 +02:00
parent 96d8a2d868
commit 85d9f44888
4 changed files with 89 additions and 35 deletions

2
.gitignore vendored
View File

@ -1,4 +1,6 @@
*.out
*.a2
*.o
*.map
*.dsk
gol

View File

@ -1,28 +1,25 @@
# LINUX
LINUX_CC := cc
LINUX_CFLAGS := -Wall -Wextra -pedantic-errors -ansi -std=gnu99 -lncurses -lm
LINUX_DFLAGS := -g -pg -O0
LINUX_OUT := gol
LINUX_SRC := gol_linux.c
LINUX_CC := cc
LINUX_SRC := gol_linux.c
LINUX_CFLAGS := -Wall -Wextra -pedantic-errors -ansi -std=gnu99 -lncurses -lm -O3
LINUX_OUT := gol.out
# APPLE II
APPLE_CC := $(CC65_HOME)/bin/cl65
APPLE_CFLAGS := -t apple2 -Oirs -v
APPLE_OUT := gol.a2
APPLE_SRC := gol_apple.c
APPLE2_CL := $(CC65_HOME)/bin/cl65
APPLE2_CC := $(CC65_HOME)/bin/cc65
APPLE2_SRC := gol_apple2.c
APPLE2_MAP := gol_apple2.map
APPLE2_CFLAGS := -Oirs -v -t apple2
APPLE2_OUT := gol.a2
all: linux apple
all: linux apple2
linux: $(LINUX_SRC)
$(LINUX_CC) -O3 -o $(LINUX_OUT) $? $(LINUX_CFLAGS)
$(LINUX_CC) -o $(LINUX_OUT) $? $(LINUX_CFLAGS)
apple2: $(APPLE2_SRC)
$(APPLE2_CL) -m $(APPLE2_MAP) -o $(APPLE2_OUT) $? $(APPLE2_CFLAGS)
apple2-asm: $(APPLE2_SRC)
$(APPLE2_CC) $(APPLE2_CFLAGS) -r -T $?
apple: $(APPLE_SRC)
$(APPLE_CC) $(APPLE_CFLAGS) $? -o $(APPLE_OUT)
clean: $(SRC)
rm -f $(LINUX_OUT) $(APPLE_OUT) gmon.out
rm -f $(LINUX_OUT) $(APPLE2_OUT) $(APPLE2_MAP) *.o *.s gmon.out

View File

@ -1,10 +1,15 @@
/* Standard headers */
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
/* Specific headers */
#include <conio.h>
/******************* FUNCTION DEFINITIONS **************/
void init_display( void ); /* Inits displayed playfield */
void draw_cells( void ); /* lets the user draw some starting cells */
void toggle_cell( const uint8_t x, const uint8_t y ); /* toggles the cell at the given coordinates */
@ -12,10 +17,11 @@ void run( void ); /* runs the simulation */
void update( void ); /* updates the simulation */
uint8_t count_neighbours( const uint8_t x, const uint8_t y); /* counts nb neighbours of a cell */
void quit( void );
/******************* CUSTOM TYPES AND VALUES DEFINITIONS ****************/
#define NB_LINES 24
#define NB_LINES 20
#define NB_COLUMNS 40
#define ALIVE '0'
@ -32,13 +38,58 @@ char Cells_Future[ NB_COLUMNS ][ NB_LINES ];
/******************** CODE ************************/
int main( void )
int main( int argc, char** argv )
{
/* TBD */
(void)argc;
(void)argv;
printf("HELLO");
/* Initial state */
memset( Cells, DEAD, sizeof(Cells) );
init_display();
quit();
return 0;
}
void quit( void )
{
uint8_t x, y;
screensize (&x, &y);
gotoxy( 1u, y-1u );
printf("BYE BYE!");
exit(0);
}
void init_display( void )
{
clrscr();
chlinexy (1u, 0u, NB_COLUMNS-2u );
chlinexy (1u, NB_LINES-1u, NB_COLUMNS-2u );
cvlinexy (0u, 1u, NB_LINES-1u );
cvlinexy (NB_COLUMNS-1u, 1u, NB_LINES-1u );
cputcxy ( 0u, 0u, '+' );
cputcxy ( 0u , NB_LINES-1u,'+');
cputcxy ( NB_COLUMNS-1u, 0u,'+');
cputcxy ( NB_COLUMNS-1u, NB_LINES-1u,'+');
/*for( i = 0u; i < NB_COLUMNS; ++i ) {
cputcxy (i,0u,'+');
}
for( i = 0u; i < NB_COLUMNS; ++i ) {
cputcxy (i,NB_LINES-1u,'+');
}
for( i = 0u; i < NB_LINES; ++i ) {
cputcxy (0u,i,'+');
}
for( i = 0u; i < NB_LINES; ++i ) {
cputcxy (NB_COLUMNS-1u,i,'+');
}*/
}
void draw_cells( void )

View File

@ -10,6 +10,7 @@
static void finish(int sig);
void init_display( void );
void draw_cells( void ); /* lets the user draw some starting cells */
void toggle_cell( uint8_t x, uint8_t y ); /* toggles the cell at the given coordinates */
@ -39,13 +40,23 @@ char Cells_Future[ NB_COLUMNS ][ NB_LINES ];
int main( void )
{
uint8_t i;
signal(SIGINT, finish); /* arrange interrupts to terminate */
/* Initial state */
memset( Cells, DEAD, sizeof(Cells) );
init_display();
/* go */
draw_cells();
run();
endwin();
return 0;
}
void init_display( void )
{
/* Init ncurses */
setlocale(LC_ALL, "");
initscr();
@ -57,6 +68,7 @@ int main( void )
nodelay(stdscr, TRUE);
/* Init displayed playfield */
uint8_t i;
for( i = 0u; i < NB_COLUMNS; ++i ) {
mvaddch(0u,i,'+');
}
@ -70,17 +82,9 @@ int main( void )
mvaddch(i,NB_COLUMNS-1u,'+');
}
refresh();
/* go */
draw_cells();
run();
endwin();
return 0;
}
void draw_cells( void )
{
int quit = 0;