Autoboot + minor refinements

This commit is contained in:
Christophe Meneboeuf 2016-10-17 00:11:23 +02:00
parent 73566b7a42
commit 18f22dec78
4 changed files with 54 additions and 8 deletions

16
README.md Normal file → Executable file
View File

@ -2,17 +2,27 @@ This is an Apple II port of **Conway's Game of Life**.
It should build with no modification on Linux, macOs and Windows 10 (using the bash).
---
Two binaries will be produced.
1. *gol.out* is a Linux executable.
2. *gol.a2* is an Apple II executable
**Prerequisite in order to build:**
* The [cc65 compiler suite](https://github.com/cc65/cc65), with the environment variable *CC65_HOME* set to its folder
**How to make a disc image**
In order to embed the Apple II executable into a disc image, you can use [*AppleCommander*](http://applecommander.sourceforge.net/).
**Prerequisite in order to produce the disk image**
>java -jar [APPLECOMMANDER_PATH] -cc65 disc.dsk GOL BIN < gol.a2
* Java Runtime
* [*AppleCommander*](http://applecommander.sourceforge.net/)
**Embedding the Apple 2 binary into the disk image**
Run the *add-to-disk.sh* script.
---
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)

19
add-to-disk.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
# Adds the gol.a2 Apple2 binary exceutable to the provided disk.dsk
# usage: add_to_disk PATH_TO_APPLECOMMANDER.jar
set -e
if (( $# != 1 )); then
echo "Bad number of arguments"
echo "usage: add_to_disk.sh PATH_TO_APPLECOMMANDER.jar"
exit
fi
echo " . revoving previous instance of GOL form the disk"
java -jar ${1} -d disk.dsk GOL
echo " .. adding GOL to the disk"
java -jar ${1} -cc65 disk.dsk GOL BIN < gol.a2
echo "DONE."

BIN
disk.dsk Executable file

Binary file not shown.

27
gol_apple2.c Normal file → Executable file
View File

@ -32,6 +32,7 @@
void __fastcall__ init_asm( uint8_t* p_cell, uint8_t* p_cells_future ); /* Inits the variables used in the ASM scope */
void init_display( void ); /* Inits displayed playfield */
void clear_text( void ); /* Clears the 4 line text field in splitted mode */
void draw_cells( void ); /* Draws the actual cells */
void editor( 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. \
@ -68,6 +69,9 @@ char KeyPressed = NO_KEY;
#define CELL_COLOR ORANGE
#define PRINTF_LINE 20u
/******************* STATIC GLOBAL VARIABLES ******************/
static uint8_t Cells[ NB_COLUMNS ][ NB_LINES ];
@ -95,10 +99,12 @@ int main( int argc, char** argv )
State = STATE_EDITOR;
break;
case STATE_EDITOR:
clear_text();
editor();
State = STATE_RUN;
break;
case STATE_RUN:
clear_text();
run();
if( KeyPressed == 'e' ) { /* Go back to editor */
State = STATE_EDITOR;
@ -133,6 +139,16 @@ void quit( void )
}
void clear_text( void )
{
register uint8_t i;
gotoxy( 0u, PRINTF_LINE );
for( i = 0; i < 4u; ++i ) {
printf(" "); /* clears a line */
}
}
void init_display( void )
{
register uint8_t i;
@ -151,7 +167,6 @@ void init_display( void )
for( i = 0u; i < NB_LINES; ++i ) {
gfx_pixel( BORDER_COLOR, NB_LINES-1u, i );
}
cgetc();
}
@ -180,6 +195,9 @@ void editor( void )
uint8_t quit, x_cursor, y_cursor;
uint8_t color_pixel;
gotoxy( 0u, PRINTF_LINE );
printf("J L I K:Move the cursor\nSPACE: Toggle a cell\n\n(D)one");
//Place the cursor middle screen
x_cursor = NB_COLUMNS >> 1u;
@ -246,18 +264,17 @@ void toggle_cell( const uint8_t x, const uint8_t y )
void run( void )
{
#define PRINTF_LINE 21u
{
char str_nb_iteration [5];
uint16_t nb_iterations = 2u;
KeyPressed = NO_KEY;
gotoxy( 0u, PRINTF_LINE );
gotoxy( 0u, PRINTF_LINE+1 );
printf("Iteration:1\n\n(R)eset (E)ditor (Q)uit");
while( KeyPressed == NO_KEY)
{
/* Evolving the cells */
update( );
gotoxy(10u, PRINTF_LINE);
gotoxy(10u, PRINTF_LINE+1);
printf( itoa(nb_iterations++, str_nb_iteration, 10) );
/* Testing key pressed */
if( kbhit() ) {