Code layout
This commit is contained in:
parent
3e796dfe38
commit
a542878e7a
|
@ -4,3 +4,4 @@ Time to 50 iterations
|
|||
555db95 : 38:51
|
||||
d0f9aef : 15:43
|
||||
9687b85 : 27:27
|
||||
3e796df : 10:42
|
||||
|
|
39
gol_apple2.c
39
gol_apple2.c
|
@ -22,7 +22,6 @@ void toggle_cell( const uint8_t x, const uint8_t y ); /* toggles the cell at the
|
|||
|
||||
void run( void ); /* runs the simulation */
|
||||
void __fastcall__ update( void ); /* updates the simulation */
|
||||
void __fastcall__ update_wip( void ); /* updates the simulation */
|
||||
uint8_t __fastcall__ count_neighbours( uint8_t* cell ); /* counts nb neighbours of the cell */
|
||||
|
||||
|
||||
|
@ -240,7 +239,7 @@ void run( void )
|
|||
while( KeyPressed == NO_KEY)
|
||||
{
|
||||
/* Evolving the cells */
|
||||
update_wip( );
|
||||
update( );
|
||||
gotoxy(10u, PRINTF_LINE);
|
||||
printf( itoa(nb_iterations++, str_nb_iteration, 10) );
|
||||
/* Testing key pressed */
|
||||
|
@ -250,39 +249,3 @@ void run( void )
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void __fastcall__ update( void )
|
||||
{
|
||||
uint8_t x, y;
|
||||
uint8_t* cell_neighbourhoud = (uint8_t*)Cells; // cell_neighbourhoud = &Cells[0][0];
|
||||
uint8_t* cell_line = cell_neighbourhoud + NB_LINES + 1u; // cell_line = &Cells[1][1];
|
||||
uint8_t* cell_future = (uint8_t*)Cells_Future + NB_LINES + 1u; // cell_future = &Cells_Future[1][1];
|
||||
for( y = 1u; y < NB_LINES - 1u; ++y )
|
||||
{
|
||||
uint8_t* cell_curr = cell_line;
|
||||
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_curr == ALIVE && \
|
||||
(nb_neighbours < 2u || nb_neighbours > 3u )
|
||||
) {
|
||||
*cell_future_line = DEAD;
|
||||
gfx_pixel( BLACK, x, y );
|
||||
}
|
||||
else if( *cell_curr == DEAD && nb_neighbours == 3u ) {
|
||||
*cell_future_line = ALIVE;
|
||||
gfx_pixel( get_color(), x, y );
|
||||
}
|
||||
cell_curr += NB_LINES;
|
||||
cell_neighbourhoud_line += NB_LINES;
|
||||
cell_future_line += NB_LINES;
|
||||
}
|
||||
++cell_line;
|
||||
++cell_neighbourhoud;
|
||||
++cell_future;
|
||||
}
|
||||
memcpy( Cells, Cells_Future, sizeof(Cells) );
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
.export _init_asm
|
||||
.export _count_neighbours
|
||||
.export _update_wip
|
||||
.export _update
|
||||
|
||||
|
||||
.define NB_LINES 40
|
||||
|
@ -23,67 +23,6 @@
|
|||
.define BLACK 0
|
||||
.define CELLS_SIZE 1600
|
||||
|
||||
|
||||
; ******************
|
||||
;uint8_t __fastcall__ count_neighbours( uint8_t* cell )
|
||||
;param: cell is in AX
|
||||
; ! A, X, Y & PTR4 ARE OVERWRITTEN !
|
||||
_count_neighbours:
|
||||
|
||||
;ASSUMPTIONS:
|
||||
; -> A and Y (offset to starting ptr) won't overflow!
|
||||
|
||||
;alias
|
||||
cell := ptr4
|
||||
;init
|
||||
STA cell
|
||||
STX cell+1
|
||||
LDA #0
|
||||
LDY #0
|
||||
CLC
|
||||
|
||||
;acc 1st row
|
||||
ADC (cell),Y
|
||||
INY
|
||||
ADC (cell),Y
|
||||
INY
|
||||
ADC (cell),Y
|
||||
|
||||
;next row
|
||||
STA tmp4
|
||||
TYA
|
||||
ADC #JUMP_BEGINNING_NEXT_LINE
|
||||
TAY
|
||||
LDA tmp4
|
||||
ADC (cell),Y
|
||||
INY
|
||||
INY
|
||||
ADC (cell),Y
|
||||
|
||||
;next row
|
||||
STA tmp4
|
||||
TYA
|
||||
ADC #JUMP_BEGINNING_NEXT_LINE
|
||||
TAY
|
||||
LDA tmp4
|
||||
ADC (cell),Y
|
||||
INY
|
||||
ADC (cell),Y
|
||||
INY
|
||||
ADC (cell),Y
|
||||
|
||||
;return
|
||||
LDX #0
|
||||
RTS
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
;************************* WORK IN PROGRESS **************************
|
||||
|
||||
|
||||
|
||||
.BSS
|
||||
|
||||
Cells: .word $0
|
||||
|
@ -96,6 +35,8 @@ cell_future: .word $0
|
|||
|
||||
.CODE
|
||||
|
||||
|
||||
|
||||
;16 bit addition of the content of an adress with a 16bit value
|
||||
.macro add_16 addr_dst, addr_src, value_low, value_hi
|
||||
CLC
|
||||
|
@ -141,7 +82,7 @@ _init_asm:
|
|||
; ******************
|
||||
;void __fastcall__ update( void )
|
||||
; ! A, X, Y & ALL PTRx ARE OVERWRITTEN !
|
||||
_update_wip:
|
||||
_update:
|
||||
|
||||
;aliases
|
||||
cell_curr := ptr1
|
||||
|
@ -284,3 +225,56 @@ end_update:
|
|||
RTS
|
||||
|
||||
;*************** END OF UPDATE **************
|
||||
|
||||
|
||||
; ******************
|
||||
;uint8_t __fastcall__ count_neighbours( uint8_t* cell )
|
||||
;param: cell is in AX
|
||||
; ! A, X, Y & PTR4 ARE OVERWRITTEN !
|
||||
_count_neighbours:
|
||||
|
||||
;ASSUMPTIONS:
|
||||
; -> A and Y (offset to starting ptr) won't overflow!
|
||||
|
||||
;alias
|
||||
cell := ptr4
|
||||
;init
|
||||
STA cell
|
||||
STX cell+1
|
||||
LDA #0
|
||||
LDY #0
|
||||
CLC
|
||||
|
||||
;acc 1st row
|
||||
ADC (cell),Y
|
||||
INY
|
||||
ADC (cell),Y
|
||||
INY
|
||||
ADC (cell),Y
|
||||
|
||||
;next row
|
||||
STA tmp4
|
||||
TYA
|
||||
ADC #JUMP_BEGINNING_NEXT_LINE
|
||||
TAY
|
||||
LDA tmp4
|
||||
ADC (cell),Y
|
||||
INY
|
||||
INY
|
||||
ADC (cell),Y
|
||||
|
||||
;next row
|
||||
STA tmp4
|
||||
TYA
|
||||
ADC #JUMP_BEGINNING_NEXT_LINE
|
||||
TAY
|
||||
LDA tmp4
|
||||
ADC (cell),Y
|
||||
INY
|
||||
ADC (cell),Y
|
||||
INY
|
||||
ADC (cell),Y
|
||||
|
||||
;return
|
||||
LDX #0
|
||||
RTS
|
||||
|
|
Loading…
Reference in New Issue