Hi guys, I'm a new NES developer. Still trying to figure out things, especially the asm 6502. Currently I'm using the cc65 and tried to change a simple data copying method from C into asm. I'm using Shiru's example as the base. So anyway, here's my code.

**Code:**

.segment "CODE"

.importzp _temp_x, _p_x

.importzp _temp_y, _temp_pos, _temp_moving, _temp_type, _temp_health, _temp_sprite_type

.importzp _temp_dx, _temp_dy

.importzp _p_y, _p_pos, _p_moving, _p_type, _p_health, _p_active, _p_sprite_type

.importzp _p_dx, _p_dy

.importzp _temp_team

.export _CopyToTemp, _CopyFromTemp

;void __fastcall__ CopyToTemp(u8 id);

_CopyToTemp:

; temp_team = id < 6 ? 0:1;

ldx #$00

lda sp

cmp #$06

bcc @lessThanSix

ldx #$01

@lessThanSix:

stx _temp_team

tay

; temp_y = p_y[id]; unsigned 8 bit

lda (_p_y), y

sta _temp_y

; temp_dx = p_dx[id]; signed 8 bit

lda (_p_dx),y

sta _temp_dx

; temp_dy = p_dy[id]; signed 8 bit

lda (_p_dy),y

sta _temp_dy

; temp_moving = p_moving[id]; unsigned 8 bit

lda (_p_moving),y

sta _temp_moving

; temp_type = p_type[id]; unsigned 8 bit

lda (_p_type),y

sta _temp_type

; temp_pos = p_pos[id]; unsigned 8 bit

lda (_p_pos),y

sta _temp_pos

; temp_x = p_x[id]; unsigned 16 bit. should we shift the index value to the left by one?]

lda sp

asl a

tay

lda (_p_x), y

sta _temp_x

iny

lda (_p_x), y

sta _temp_x+1

;if ( id < 3)

; temp_health = p_health[id];

;else if (id >5 && id < 9)

; temp_health = p_health[id-3];

lda sp

cmp #$03

bcc @copyP1Health

cmp #$05

bcc @doneCopyToTemp

cmp #$09

bcc @copyP2Health

jmp @doneCopyToTemp

@copyP1Health:

tay

lda (_p_health), y

jmp @storeCopyHealth

@copyP2Health:

clc

sbc #$03

tay

lda (_p_health), y

@storeCopyHealth:

sta _temp_health

@doneCopyToTemp:

rts

;void __fastcall__ CopyToTemp(u8 id);

_CopyFromTemp:

;p_y[id] = temp_y;unsigned 8 bit

ldy sp

lda _temp_y

sta (_p_y), y

;p_dx[id] = temp_dx;signed 8 bit

lda _temp_dx

sta (_p_dx), y

;p_dy[id] = temp_dy; signed 8 bit

lda _temp_dy

sta (_p_dy), y

;p_moving[id] = temp_moving; unsigned 8 bit

lda _temp_moving

sta (_p_moving), y

;p_sprite_type[id] = temp_sprite_type; unsigned 8 bit

lda _temp_sprite_type

sta (_p_sprite_type), y

;p_x[id] = temp_x; unsigned 16 bit. should we shift the index value to the left by one?

lda sp

asl a

tay

lda _temp_x

sta (_p_x), y

iny

lda _temp_x + 1

sta (_p_x), y

;TODO: Add health?

rts

I've added this file in the crt0.s like so:

**Code:**

.include "main.sinc"

Can you please check if this code works as intended and give comment about it please? I don't know that much about asm and when I use the pure C codes, it has some flickering. So I though I'll try getting some of my codes changed to asm. Thanks in advance.