diff --git a/Makefile b/Makefile index 167f115..16a7958 100755 --- a/Makefile +++ b/Makefile @@ -1,23 +1,15 @@ -LINUX_CC := cc -LINUX_SRC := src/gol_linux.c -LINUX_CFLAGS := -Wall -Wextra -pedantic-errors -ansi -std=gnu99 -lncurses -lm -O3 -LINUX_OUT := bin/gol.out - APPLE2_CL := $(CC65_HOME)/bin/cl65 APPLE2_CC := $(CC65_HOME)/bin/cc65 -APPLE2_SRC := src/gol_apple2.c src/gol_apple2_optimized.asm src/gfx.asm src/rnd_colors.asm src/file_io.c src/mli.asm src/music.asm -APPLE2_MAP := gol_apple2.map +APPLE2_SRC := src/gol_main.c src/gol_optimized.asm src/gfx.asm src/rnd_colors.asm src/file_io.c src/mli.asm src/music.asm +APPLE2_MAP := gol.map APPLE2_CFLAGS := -Oirs -v -t apple2 APPLE2_OUT := bin/gol.a2 -all: directories linux apple2 +all: directories apple2 directories: mkdir -p bin -linux: $(LINUX_SRC) - $(LINUX_CC) -o $(LINUX_OUT) $? $(LINUX_CFLAGS) - apple2: $(APPLE2_SRC) $(APPLE2_CL) -m $(APPLE2_MAP) -o $(APPLE2_OUT) $? $(APPLE2_CFLAGS) -C src/game-of-life.cfg diff --git a/README.md b/README.md index 75cc547..e00bf19 100755 --- a/README.md +++ b/README.md @@ -4,10 +4,7 @@ It should build with no modification on Linux, macOs and Windows 10 (using the b --- -Two binaries will be produced. - -1. *gol.out* is a Linux executable. -2. *gol.a2* is an Apple II executable +It will produce the file *gol.a2*, which is an Apple II executable **Prerequisite in order to build:** @@ -22,10 +19,10 @@ Two binaries will be produced. Run the *add-to-disk.sh* script. -**Title screen** +**Splash screen** -The title screen art is located in the *assets* folder. It has to be -manually loaded on the disk image using the *AppleCommander's GUI*, for the +The splash screen art is located in the *assets* folder. **It has to be +manually loaded** on the disk image using the *AppleCommander's GUI*, for the command line loads a corrupted file! This screen was converted from a PNG using [*Rgb2Hires*](https://github.com/Pixinn/Rgb2Hires). @@ -34,3 +31,7 @@ This screen was converted from a PNG using [*Rgb2Hires*](https://github.com/Pixi For more information, you can refer to these posts on [my blog](https://www.xtof/info/blog/). * [Coding in C for a 8 bit 6502 CPU](https://www.xtof.info/blog/?p=714) * [Coding in Assembly for an Apple II](https://www.xtof.info/blog/?p=745) +* [HIRES Graphics on the Apple II](https://www.xtof.info/blog/?p=768) +* [Making the Apple II sing](https://www.xtof.info/blog/?p=807) +* [A Game of Life](https://www.xtof.info/blog/?p=837) + diff --git a/scripts/Sound_Precalculus.ods b/scripts/Sound_Precalculus.ods index 40cde99..9cd91fe 100755 Binary files a/scripts/Sound_Precalculus.ods and b/scripts/Sound_Precalculus.ods differ diff --git a/src/gol_linux.c b/src/gol_linux.c deleted file mode 100755 index de41eb2..0000000 --- a/src/gol_linux.c +++ /dev/null @@ -1,238 +0,0 @@ -/* A Conway's Game of Life -* Copyright (C) 2016 Christophe Meneboeuf -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -#include -#include -#include -#include -#include -#include -#include - -/******************* FUNCTION DEFINITIONS **************/ - -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 */ - -void run( void ); /* runs the simulation */ -void update( void ); /* updates the simulation */ -uint8_t count_neighbours( uint8_t* cell ); /* counts nb neighbours of the cell */ - - -/******************* CUSTOM TYPES AND VALUES DEFINITIONS ****************/ - -#define NB_LINES 23u -#define NB_COLUMNS 40u - -#define ALIVE 1u -#define DEAD 0u -#define SPRITE_ALIVE '0' -#define SPRITE_DEAD ' ' - - - -/******************* STATIC GLOBAL VARIABLES ******************/ - -uint8_t Cells[ NB_COLUMNS ][ NB_LINES ]; -uint8_t Cells_Future[ NB_COLUMNS ][ NB_LINES ]; - - -/******************** CODE ************************/ - - -int main( void ) -{ - 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(); - cbreak(); - noecho(); - nonl(); - intrflush(stdscr, FALSE); - keypad(stdscr, TRUE); - nodelay(stdscr, TRUE); - - /* Init displayed playfield */ - uint8_t i; - for( i = 0u; i < NB_COLUMNS; ++i ) { - mvaddch(0u,i,'+'); - } - for( i = 0u; i < NB_COLUMNS; ++i ) { - mvaddch(NB_LINES-1u,i,'+'); - } - for( i = 0u; i < NB_LINES; ++i ) { - mvaddch(i,0u,'+'); - } - for( i = 0u; i < NB_LINES; ++i ) { - mvaddch(i,NB_COLUMNS-1u,'+'); - } - refresh(); -} - - -void draw_cells( void ) -{ - uint8_t quit = 0u; - - uint8_t ch; - uint8_t y = NB_LINES >> 1; - uint8_t x = NB_COLUMNS >> 1; - - move(y,x); - refresh(); - - while ( quit == 0) - { - getyx(stdscr, y, x); - ch = getch(); - switch (ch) { - case 'j': - if( x > 1u ) { move(y, --x); } - break; - case 'k': - if( y < NB_LINES - 2u ) { move(++y, x); } - break; - case 'i': - if( y > 1u ) { move(--y, x); } - break; - case 'l': - if( x < NB_COLUMNS - 2u ) { move(y, ++x); } - break; - case ' ': - toggle_cell(x,y); - break; - case 'q': - quit = 1; - break; - } - - refresh(); - } - - /* Cells was updated by the calls to toggle() */ - memcpy( Cells_Future, Cells, sizeof(Cells_Future) ); - -} - - -void toggle_cell( const uint8_t x, const uint8_t y ) -{ - if( x == 0u || x >= NB_COLUMNS-1 || y == 0u || y >= NB_LINES-1 ) { return; } - uint8_t* cell = &Cells[x][y]; - if( *cell == DEAD ) { - *cell = ALIVE; - mvaddch(y,x,SPRITE_ALIVE); - } else { - *cell = DEAD; - mvaddch(y,x,SPRITE_DEAD); - } - refresh(); -} - - -void run( void ) -{ - #define PERIOD_MS 200000u - curs_set(0); - char ch = '\0'; - while( ch != 'q') - { - ch = getch(); - update(); - usleep( PERIOD_MS ); - } -} - - -void update( void ) -{ - uint8_t x, y; - uint8_t* cell_neighbourhoud = &Cells[0][0]; // cell_neighbourhoud = &Cells[0][0]; - uint8_t* cell = cell_neighbourhoud + NB_LINES + 1u; // cell = &Cells[1][1]; - uint8_t* cell_future = &Cells_Future[0][0] + NB_LINES + 1u; // cell_future = &Cells_Future[1][1]; - for( y = 1u; y < NB_LINES - 1u; ++y ) - { - - uint8_t* cell_line = cell; - uint8_t* cell_neighbourhoud_line = cell_neighbourhoud; - uint8_t* cell_future_line = cell_future; - for( x = 1u; x < NB_COLUMNS - 1u; ++x) - { - uint8_t nb_neighbours = count_neighbours( cell_neighbourhoud_line ); - if( *cell_line == ALIVE && \ - (nb_neighbours < 2u || nb_neighbours > 3u ) - ) { - *cell_future_line = DEAD; - mvaddch(y,x,SPRITE_DEAD); - } - else if( *cell_line == DEAD && nb_neighbours == 3u ) { - *cell_future_line = ALIVE; - mvaddch(y,x,SPRITE_ALIVE); - } - cell_line += NB_LINES; - cell_neighbourhoud_line += NB_LINES; - cell_future_line += NB_LINES; - } - ++cell; - ++cell_neighbourhoud; - ++cell_future; - } - memcpy( Cells, Cells_Future, sizeof(Cells) ); - refresh(); -} - - -uint8_t count_neighbours( uint8_t* cell ) -{ - uint8_t count; - count = *cell++; count += *cell++; count += *cell; - cell += NB_LINES - 2u; - count += *cell; cell+=2 ; count += *cell; - cell += NB_LINES - 2u; - count += *cell++; count += *cell++; count += *cell; - return count; -} - -static void finish(int sig) -{ - (void) sig; - endwin(); - - /* do your non-curses wrapup here */ - - exit(0); -} diff --git a/src/gol_apple2.c b/src/gol_main.c similarity index 100% rename from src/gol_apple2.c rename to src/gol_main.c diff --git a/src/gol_apple2_optimized.asm b/src/gol_optimized.asm similarity index 100% rename from src/gol_apple2_optimized.asm rename to src/gol_optimized.asm diff --git a/src/music.asm b/src/music.asm index ea94c75..79c341c 100755 --- a/src/music.asm +++ b/src/music.asm @@ -8,8 +8,6 @@ .export _pause .DATA -Loops: .byte 149, 141, 133, 125, 118, 111, 105, 99, 94, 88, 83, 78 ;Note loops -Test: .word 31100 ;NB nop loops of each note, lasting hal a period Half_Periods: .byte 251, 237, 224, 211, 199, 188, 177, 167, 158