So, I got this strange piece of code.

Just from trying a few examples, it looks like it is effectively doing an 8-bit by 8-bit multiplication.

I'm guessing should just go ahead with that assumption?

$40/41 the multipliers, $42/43 the little-endian result.

(looking at the formula for determining enemy damage to the player.

$40 = (enemy attack - player defense)>>4

$41 = random value 0-6

since 42 is going to be overwritten by 8 bits anyways, it would seem it's initial value is undefined and unimportant

` txa`

pha

lda #$00

sta $43

ldx #$08

MainLoop:

lsr $40

bcc NoCarry

clc

adc $41

NoCarry:

ror a

ror $42

dex

bne MainLoop

sta $43

pla

tax

rts