Rewriting count_neighbourgs in assembly
This commit is contained in:
parent
50ef808124
commit
555db9524d
2
Makefile
2
Makefile
|
@ -5,7 +5,7 @@ LINUX_OUT := gol.out
|
|||
|
||||
APPLE2_CL := $(CC65_HOME)/bin/cl65
|
||||
APPLE2_CC := $(CC65_HOME)/bin/cc65
|
||||
APPLE2_SRC := gol_apple2.c
|
||||
APPLE2_SRC := gol_apple2.c gol_apple2_optimized.asm
|
||||
APPLE2_MAP := gol_apple2.map
|
||||
APPLE2_CFLAGS := -Oirs -v -t apple2
|
||||
APPLE2_OUT := gol.a2
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
Time to 50 iterations
|
||||
|
||||
50ef808 : 61:25
|
||||
: 38:51
|
||||
|
14
gol_apple2.c
14
gol_apple2.c
|
@ -17,7 +17,7 @@ uint8_t toggle_cell( const uint8_t x, const uint8_t y ); /* toggles the cell at
|
|||
|
||||
void run( void ); /* runs the simulation */
|
||||
void update( void ); /* updates the simulation */
|
||||
void count_neighbours( uint8_t* cell, uint8_t* count ); /* counts nb neighbours of the cell */
|
||||
uint8_t __fastcall__ count_neighbours( uint8_t* cell ); /* counts nb neighbours of the cell */
|
||||
|
||||
void quit( void );
|
||||
|
||||
|
@ -224,7 +224,6 @@ void run( void )
|
|||
|
||||
void update( void )
|
||||
{
|
||||
uint8_t nb_neighbours;
|
||||
uint8_t x, y;
|
||||
for( y = 1u; y < NB_LINES-1; ++y )
|
||||
{
|
||||
|
@ -232,7 +231,7 @@ void update( void )
|
|||
{
|
||||
register uint8_t nb_neighbours;
|
||||
uint8_t* cell = &Cells[x-1u][y-1u];
|
||||
count_neighbours( cell, &nb_neighbours );
|
||||
nb_neighbours = count_neighbours( cell );
|
||||
if( Cells[x][y] == ALIVE && \
|
||||
(nb_neighbours < 2u || nb_neighbours > 3u )
|
||||
) {
|
||||
|
@ -248,12 +247,3 @@ void update( void )
|
|||
memcpy( Cells, Cells_Future, sizeof(Cells) );
|
||||
}
|
||||
|
||||
|
||||
void count_neighbours( uint8_t* cell, uint8_t* count )
|
||||
{
|
||||
*count = *cell++; *count += *cell++; *count += *cell;
|
||||
cell += JUMP_BEGINNING_NEXT_LINE;
|
||||
*count += *cell; cell+=2 ; *count += *cell;
|
||||
cell += JUMP_BEGINNING_NEXT_LINE;
|
||||
*count += *cell++; *count += *cell++; *count += *cell;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
|
||||
.include "apple2.inc"
|
||||
.include "zeropage.inc"
|
||||
|
||||
.export _count_neighbours
|
||||
|
||||
; ******************
|
||||
;uint8_t __fastcall__ count_neighbours( uint8_t* cell )
|
||||
;param: cell is in AX
|
||||
_count_neighbours:
|
||||
|
||||
;ASSUMPTIONS:
|
||||
; -> A and Y (offset to starting ptr) won't overflow!
|
||||
|
||||
;init
|
||||
STA ptr1
|
||||
STX ptr1+1
|
||||
LDA #0
|
||||
LDY #0
|
||||
CLC
|
||||
|
||||
;acc 1st row
|
||||
ADC (ptr1),Y
|
||||
INY
|
||||
ADC (ptr1),Y
|
||||
INY
|
||||
ADC (ptr1),Y
|
||||
|
||||
;next row
|
||||
STA tmp1
|
||||
TYA
|
||||
ADC #$15
|
||||
TAY
|
||||
LDA tmp1
|
||||
ADC (ptr1),Y
|
||||
INY
|
||||
INY
|
||||
ADC (ptr1),Y
|
||||
|
||||
;next row
|
||||
STA tmp1
|
||||
TYA
|
||||
ADC #$15
|
||||
TAY
|
||||
LDA tmp1
|
||||
ADC (ptr1),Y
|
||||
INY
|
||||
ADC (ptr1),Y
|
||||
INY
|
||||
ADC (ptr1),Y
|
||||
|
||||
;return
|
||||
TAX
|
||||
LDX #0
|
||||
RTS
|
||||
|
Loading…
Reference in New Issue