;	WinSTon

;	BSR <label>

;	XNZVC
;	-----

PUBLIC _bsr_s
PUBLIC _bsr_w

;-----------------------------------------------------------------------
;BSR.S <label> (8-bit offset)
_bsr_s PROC NEAR
	sub		DWORD PTR _Regs[REG_A7*4],SIZE_LONG		;SP-=4
	mov		ebp,_Regs[REG_A7*4]						;SP
	MASK_24BIT_ADDR(ebp)							;as 24-bit address in PC memory
	mov		edx,esi									;Program counter into 'ecx'
	sub		edx,STRAM_OFFSET						;As ST address space
	and		[_PC],0ff000000h						;Combine with stored Program Counter to retain top byte
	or		edx,[_PC]
	SWAP_ENDIAN_LONG_EDX							;into wrong endian
	mov		DWORD PTR _STRam[ebp],edx				;Save PC

	add		esi,DECODE_1[ecx]						;PC += (char)OpCode
	FRET
_bsr_s ENDP

;-----------------------------------------------------------------------
;BSR.W <label>
_bsr_w PROC NEAR
	mov		bx,WORD PTR [esi]						;16-bit offset(wrong endian)
	SWAP_ENDIAN_WORD_BX

	sub		DWORD PTR _Regs[REG_A7*4],SIZE_LONG		;SP-=4
	mov		ebp,_Regs[REG_A7*4]						;SP
	MASK_24BIT_ADDR(ebp)							;as 24-bit address in PC memory
	mov		edx,esi									;Program counter into 'ecx'
	add		edx,SIZE_WORD							;Skip immediate after opcode
	sub		edx,STRAM_OFFSET						;As ST address space
	and		[_PC],0ff000000h						;Combine with stored Program Counter to retain top byte
	or		edx,[_PC]
	SWAP_ENDIAN_LONG_EDX							;into wrong endian
	mov		DWORD PTR _STRam[ebp],edx				;Save PC

	movsx	ebx,bx									;sign extended
	add		esi,ebx									;PC += (short int)Offset
	FRET	
_bsr_w ENDP
