mirror of
https://github.com/Pixinn/gameoflife-appleii.git
synced 2024-06-13 17:29:26 +00:00
Editor in gfx mode. Some bugs left.
This commit is contained in:
parent
0e47d54b8b
commit
75eb6acada
14
gfx.asm
14
gfx.asm
|
@ -157,7 +157,7 @@ fill_line:
|
||||||
CPY #40 ;nb pixels per line
|
CPY #40 ;nb pixels per line
|
||||||
BNE fill_line
|
BNE fill_line
|
||||||
INX
|
INX
|
||||||
CPX #24 ;nb lines
|
CPX #20 ;nb lines
|
||||||
BNE for_lines
|
BNE for_lines
|
||||||
fill_end:
|
fill_end:
|
||||||
;displaying the page we filled
|
;displaying the page we filled
|
||||||
|
@ -182,6 +182,8 @@ _gfx_pixel:
|
||||||
jsr pusha
|
jsr pusha
|
||||||
LDA tmp2
|
LDA tmp2
|
||||||
jsr pusha
|
jsr pusha
|
||||||
|
;LDA tmp1
|
||||||
|
;jsr pusha
|
||||||
LDA ptr1
|
LDA ptr1
|
||||||
jsr pusha
|
jsr pusha
|
||||||
LDA ptr2
|
LDA ptr2
|
||||||
|
@ -193,6 +195,8 @@ _gfx_pixel:
|
||||||
AND #1
|
AND #1
|
||||||
BEQ even
|
BEQ even
|
||||||
odd: ; pixel is on an odd line
|
odd: ; pixel is on an odd line
|
||||||
|
LDA #$0F ;To or with the other nybble when writting the pixel
|
||||||
|
STA tmp1
|
||||||
LDY #(1+4) ;there were 4 pushes to save registers
|
LDY #(1+4) ;there were 4 pushes to save registers
|
||||||
LDA (sp),Y ;color
|
LDA (sp),Y ;color
|
||||||
ASL ;shift the color to put it on high nybble
|
ASL ;shift the color to put it on high nybble
|
||||||
|
@ -202,6 +206,8 @@ odd: ; pixel is on an odd line
|
||||||
CLC
|
CLC
|
||||||
BCC oddeven
|
BCC oddeven
|
||||||
even: ; pixel is on an even line
|
even: ; pixel is on an even line
|
||||||
|
LDA #$F0 ;To or with the other nybble when writting the pixel
|
||||||
|
STA tmp1
|
||||||
LDY #(1+4) ;there were 4 pushes to save registers
|
LDY #(1+4) ;there were 4 pushes to save registers
|
||||||
LDA (sp),Y ;color
|
LDA (sp),Y ;color
|
||||||
oddeven:
|
oddeven:
|
||||||
|
@ -231,7 +237,9 @@ oddeven:
|
||||||
LDA (sp),Y
|
LDA (sp),Y
|
||||||
; draw
|
; draw
|
||||||
TAY
|
TAY
|
||||||
LDA tmp2 ;color
|
LDA (ptr2),Y ;a color may have been present on the other nybble
|
||||||
|
AND tmp1 ;clearing the pixel's nybble
|
||||||
|
ORA tmp2 ;adding the color to the pixel's nyyble
|
||||||
STA (ptr2),Y
|
STA (ptr2),Y
|
||||||
|
|
||||||
;restoring the context
|
;restoring the context
|
||||||
|
@ -239,6 +247,8 @@ oddeven:
|
||||||
STA ptr2
|
STA ptr2
|
||||||
JSR popa
|
JSR popa
|
||||||
STA ptr1
|
STA ptr1
|
||||||
|
;JSR popa
|
||||||
|
;STA tmp1
|
||||||
JSR popa
|
JSR popa
|
||||||
STA tmp2
|
STA tmp2
|
||||||
JSR popa
|
JSR popa
|
||||||
|
|
84
gol_apple2.c
84
gol_apple2.c
|
@ -16,7 +16,7 @@ void __fastcall__ init_asm( uint8_t* p_cell, uint8_t* p_cells_future ); /* Init
|
||||||
void init_display( void ); /* Inits displayed playfield */
|
void init_display( void ); /* Inits displayed playfield */
|
||||||
void draw_cells( void ); /* Draws the actual cells */
|
void draw_cells( void ); /* Draws the actual cells */
|
||||||
void editor( void ); /* lets the user draw some starting cells */
|
void editor( void ); /* lets the user draw some starting cells */
|
||||||
uint8_t toggle_cell( const uint8_t x, const uint8_t y ); /* toggles the cell at the given coordinates. \
|
void toggle_cell( const uint8_t x, const uint8_t y ); /* toggles the cell at the given coordinates. \
|
||||||
Returns the cursor X position */
|
Returns the cursor X position */
|
||||||
|
|
||||||
void run( void ); /* runs the simulation */
|
void run( void ); /* runs the simulation */
|
||||||
|
@ -29,7 +29,7 @@ void quit( void );
|
||||||
|
|
||||||
/******************* CUSTOM TYPES AND VALUES DEFINITIONS ****************/
|
/******************* CUSTOM TYPES AND VALUES DEFINITIONS ****************/
|
||||||
|
|
||||||
#define NB_LINES 23u
|
#define NB_LINES 40u
|
||||||
#define NB_COLUMNS 40u
|
#define NB_COLUMNS 40u
|
||||||
|
|
||||||
#define ALIVE 1u
|
#define ALIVE 1u
|
||||||
|
@ -61,12 +61,6 @@ int main( int argc, char** argv )
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
|
|
||||||
//+ DEBUG
|
|
||||||
//gotoxy(0,0);
|
|
||||||
//printf("Cells:0x%x - Cells_future:0x%x",(uint16_t)(&Cells[0][0]),(uint16_t)(&Cells_Future[0][0]));
|
|
||||||
//cgetc();
|
|
||||||
//- DEBUG
|
|
||||||
|
|
||||||
init_asm( (uint8_t*)Cells, (uint8_t*)Cells_Future );
|
init_asm( (uint8_t*)Cells, (uint8_t*)Cells_Future );
|
||||||
|
|
||||||
/* Running the state machine */
|
/* Running the state machine */
|
||||||
|
@ -79,7 +73,6 @@ int main( int argc, char** argv )
|
||||||
State = STATE_EDITOR;
|
State = STATE_EDITOR;
|
||||||
break;
|
break;
|
||||||
case STATE_EDITOR:
|
case STATE_EDITOR:
|
||||||
mode_text();
|
|
||||||
editor();
|
editor();
|
||||||
State = STATE_RUN;
|
State = STATE_RUN;
|
||||||
break;
|
break;
|
||||||
|
@ -120,15 +113,22 @@ void quit( void )
|
||||||
|
|
||||||
void init_display( void )
|
void init_display( void )
|
||||||
{
|
{
|
||||||
clrscr();
|
register uint8_t i;
|
||||||
chlinexy (1u, 0u, NB_COLUMNS-2u );
|
gfx_init( LOWRES, SPLIT );
|
||||||
chlinexy (1u, NB_LINES-1u, NB_COLUMNS-2u );
|
gfx_fill( BLACK );
|
||||||
cvlinexy (0u, 1u, NB_LINES-1u );
|
for( i = 0u; i < NB_COLUMNS; ++i ) {
|
||||||
cvlinexy (NB_COLUMNS-1u, 1u, NB_LINES-1u );
|
gfx_pixel( WHITE, i, 0u );
|
||||||
cputcxy ( 0u, 0u, '+' );
|
}
|
||||||
cputcxy ( 0u , NB_LINES-1u,'+');
|
for( i = 0u; i < NB_COLUMNS; ++i ) {
|
||||||
cputcxy ( NB_COLUMNS-1u, 0u,'+');
|
gfx_pixel( WHITE, i, NB_LINES-1u );
|
||||||
cputcxy ( NB_COLUMNS-1u, NB_LINES-1u,'+');
|
}
|
||||||
|
for( i = 0u; i < NB_LINES; ++i ) {
|
||||||
|
gfx_pixel( WHITE, 0u, i );
|
||||||
|
}
|
||||||
|
for( i = 0u; i < NB_LINES; ++i ) {
|
||||||
|
gfx_pixel( WHITE, NB_LINES-1u, i );
|
||||||
|
}
|
||||||
|
cgetc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -147,6 +147,12 @@ void draw_cells( void ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clear_cursor( const uint8_t x, const uint8_t y )
|
||||||
|
{
|
||||||
|
if( Cells[x][y] == DEAD ) {
|
||||||
|
gfx_pixel( BLACK, x, y );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void editor( void )
|
void editor( void )
|
||||||
{
|
{
|
||||||
|
@ -157,39 +163,43 @@ void editor( void )
|
||||||
|
|
||||||
uint8_t quit, x, y;
|
uint8_t quit, x, y;
|
||||||
|
|
||||||
gotoxy( 0u, NB_LINES );
|
|
||||||
printf("EDITOR (D)one");
|
|
||||||
|
|
||||||
x = NB_COLUMNS >> 1u;
|
x = NB_COLUMNS >> 1u;
|
||||||
y = NB_LINES >> 1u;
|
y = NB_LINES >> 1u;
|
||||||
gotoxy(x,y);
|
|
||||||
|
|
||||||
quit = 0;
|
quit = 0;
|
||||||
while ( quit == 0)
|
while ( quit == 0)
|
||||||
{
|
{
|
||||||
cursor(1);
|
|
||||||
KeyPressed = cgetc();
|
KeyPressed = cgetc();
|
||||||
switch (KeyPressed) {
|
switch (KeyPressed) {
|
||||||
case KEY_LEFT:
|
case KEY_LEFT:
|
||||||
if( x > 1u ) { gotoxy( --x, y ); }
|
clear_cursor(x,y);
|
||||||
|
if( x > 1u ) { --x; }
|
||||||
break;
|
break;
|
||||||
case KEY_DOWN:
|
case KEY_DOWN:
|
||||||
if( y < NB_LINES-2u ) { gotoxy( x, ++y ); }
|
clear_cursor(x,y);
|
||||||
|
if( y < NB_LINES-2u ) { ++y; }
|
||||||
break;
|
break;
|
||||||
case KEY_UP:
|
case KEY_UP:
|
||||||
if( y > 1u ) { gotoxy( x, --y ); }
|
clear_cursor(x,y);
|
||||||
|
if( y > 1u ) { --y; }
|
||||||
break;
|
break;
|
||||||
case KEY_RIGHT:
|
case KEY_RIGHT:
|
||||||
if( x < NB_COLUMNS-2u ) { gotoxy( ++x, y ); }
|
clear_cursor(x,y);
|
||||||
|
if( x < NB_COLUMNS-2u ) { ++x; }
|
||||||
break;
|
break;
|
||||||
case ' ':
|
case ' ':
|
||||||
x = toggle_cell( x, y );
|
if( x > 1u && x < NB_COLUMNS-2u
|
||||||
|
&& y > 1u && y < NB_LINES-2u )
|
||||||
|
{
|
||||||
|
toggle_cell( x++, y );
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
quit = 1;
|
quit = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
gfx_pixel( WHITE, x, y ); //cursor
|
||||||
|
}
|
||||||
|
|
||||||
/* Cells was updated by the calls to toggle() */
|
/* Cells was updated by the calls to toggle() */
|
||||||
memcpy( Cells_Future, Cells, sizeof(Cells_Future) );
|
memcpy( Cells_Future, Cells, sizeof(Cells_Future) );
|
||||||
|
@ -197,31 +207,27 @@ void editor( void )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint8_t toggle_cell( const uint8_t x, const uint8_t y )
|
void toggle_cell( const uint8_t x, const uint8_t y )
|
||||||
{
|
{
|
||||||
char* cell;
|
char* cell;
|
||||||
if( x == 0u || x >= NB_COLUMNS-1u || y == 0u || y >= NB_LINES-1u ) { return x; }
|
if( x == 0u || x >= NB_COLUMNS-1u || y == 0u || y >= NB_LINES-1u ) { return; }
|
||||||
cell = &Cells[x][y];
|
cell = &Cells[x][y];
|
||||||
if( *cell == DEAD ) {
|
if( *cell == DEAD ) {
|
||||||
*cell = ALIVE;
|
*cell = ALIVE;
|
||||||
cputc( SPRITE_ALIVE );
|
gfx_pixel( ORANGE, x, y );
|
||||||
} else {
|
} else {
|
||||||
*cell = DEAD;
|
*cell = DEAD;
|
||||||
cputc( SPRITE_DEAD );
|
gfx_pixel( BLACK, x, y );
|
||||||
}
|
}
|
||||||
return wherex ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void run( void )
|
void run( void )
|
||||||
{
|
{
|
||||||
uint8_t i;
|
|
||||||
char str_nb_iteration [5];
|
char str_nb_iteration [5];
|
||||||
uint16_t nb_iterations = 2u;
|
uint16_t nb_iterations = 2u;
|
||||||
KeyPressed = NO_KEY;
|
KeyPressed = NO_KEY;
|
||||||
|
|
||||||
gfx_init( LOWRES, SPLIT );
|
|
||||||
gfx_fill( BLACK );
|
|
||||||
cursor(0);
|
cursor(0);
|
||||||
gotoxy( 0u, NB_LINES );
|
gotoxy( 0u, NB_LINES );
|
||||||
printf("Iteration:1 (R)eset (E)ditor (Q)uit");
|
printf("Iteration:1 (R)eset (E)ditor (Q)uit");
|
||||||
|
@ -261,11 +267,11 @@ void __fastcall__ update( void )
|
||||||
) {
|
) {
|
||||||
*cell_future_line = DEAD;
|
*cell_future_line = DEAD;
|
||||||
//cputcxy( x, y, SPRITE_DEAD );
|
//cputcxy( x, y, SPRITE_DEAD );
|
||||||
gfx_pixel( BLACK, x, 2*y );
|
gfx_pixel( BLACK, x, y );
|
||||||
}
|
}
|
||||||
else if( *cell_curr == DEAD && nb_neighbours == 3u ) {
|
else if( *cell_curr == DEAD && nb_neighbours == 3u ) {
|
||||||
*cell_future_line = ALIVE;
|
*cell_future_line = ALIVE;
|
||||||
gfx_pixel( WHITE, x, 2*y );
|
gfx_pixel( WHITE, x, y );
|
||||||
//cputcxy( x, y, SPRITE_ALIVE );
|
//cputcxy( x, y, SPRITE_ALIVE );
|
||||||
}
|
}
|
||||||
cell_curr += NB_LINES;
|
cell_curr += NB_LINES;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user