TRSE icon indicating copy to clipboard operation
TRSE copied to clipboard

Target 65816 STY with improper bit-width

Open noyen1973 opened this issue 2 years ago • 2 comments

I have this line of code which is part of a case.. of block:

			100: if (Players[0].direction=23) then Players[0].direction:=0
					else inc(Players[0].direction); // "d" turn right

Which produces this assembly code:

	lda #$64
	cmp tb ;keep
	bne TestCar_casenext309
	; LineNumber: 945
	; Binary clause INTEGER: EQUALS
	; Load Integer array
	sep #$10        ; disable X/Y 16-bit
	ldx #0 ; watch for bug, Integer array has max index of 128
	lda Players_Player_Type_Player_Type_direction,x
	ldy Players_Player_Type_Player_Type_direction+1,x
	rep #$10        ; enable X/Y 16-bit
	sta TestCar_rightvarInteger_var318
	sty TestCar_rightvarInteger_var318+1 ;**** LOOK HERE ****
	; Compare INTEGER with pure num / var optimization. GREATER. 
	lda TestCar_rightvarInteger_var318+1   ; compare high bytes
	cmp #$00 ;keep
	bne TestCar_elseblock313
	lda TestCar_rightvarInteger_var318
	cmp #$17 ;keep
	bne TestCar_elseblock313
	jmp TestCar_ConditionalTrueBlock312

On the line that says **** LOOK HERE **** the STY will write a 16-bit value into TestCar_rightvarInteger_var318+1. It needs a SEP #$10 to change the index register to 8-bit and then followup with a REP #$10 to change it back to 16-bit. Otherwise the address after TestCar_rightvarInteger_var318+1 will be corrupted.

noyen1973 avatar Mar 23 '22 08:03 noyen1973

could you provide some more info here? When I'm testing this, the temp value is a zero page address and you get the correct "sep #$10", so I am unable to reproduce this..

leuat avatar Mar 24 '22 12:03 leuat

ok should be fixed, but having some trouble with building a new release. If you see a new release, please download and verify!

leuat avatar Mar 24 '22 13:03 leuat