
OPERANDS = 0
.include "shell.inc"
; .include "instr_test.inc"
; .include "macros.inc"

values:
	.byte 0,1,2,$40,$7F,$80,$81,$FF
values_size = * - values

zp_res in_a,2
zp_res in_x,2
zp_res in_y,2
zp_res in_p,2
zp_res in_s,2
zp_res out_a
zp_res out_x
zp_res out_y
zp_res out_p
zp_res out_s

.macro store_ptr zp_ptr, value
	lda #.lobyte(value)
	sta zp_ptr
	lda #.hibyte(value)
	sta zp_ptr+1
.endmacro

testcase_init:
	store_ptr in_a, values
	store_ptr in_x, values
	store_ptr in_y, values
	store_ptr in_p, values
	store_ptr in_s, values
	rts

; Calling convention: Will trash stack - anything that needs to be saved must be elsewhere
; Will call `test_code` with the requisite
zp_res return_addr
run_tc:
	lda (in_s,x)
	tax
	txs ; As long as the following code has the same number of pushes & pulls, stack ptr will be correct
	ldx #0
	lda (in_p,x)
	pha
	lda (in_a,x)
	pha
	lda (in_x,x)
	pha
	lda (in_y,x)
	pha
	; Stack <y, x, a, p>
	pla
	tay
	; Stack <x, a, p>, y correct
	pla
	tax
	; Stack <a, p>, C: x, y
	pla
	; Stack <p>, C: x, y
	plp
	; Stack <>, C: x, y, p, (also S)
	jsr test_code
	php
	sta out_a
	pla
	sta out_p
	stx out_x
	sty out_y
	tsx
	stx out_s
	
	jmp (return_addr)

test_code:
	rts

main:
	jsr testcase_init
	; $A2,$67,$77,$F8
	; entry $2A,"ROL A",$CB,$4B,$9A,$4C ; A = op A
	; entry $0A,"ASL A",$00,$00,$00,$00
	; entry $0A,"ROR A",$00,$00,$00,$00
	; entry $4A,"LSR A",$00,$00,$00,$00

	; entry $8A,"TXA",$00,$00,$00,$00 ; AXY = AXY
	; entry $98,"TYA",$00,$00,$00,$00
	; entry $AA,"TAX",$00,$00,$00,$00
	; entry $A8,"TAY",$00,$00,$00,$00
	
	; entry $E8,"INX",$00,$00,$00,$00 ; XY = op XY
	; entry $C8,"INY",$00,$00,$00,$00
	; entry $CA,"DEX",$00,$00,$00,$00
	; entry $88,"DEY",$00,$00,$00,$00
	
	; entry $38,"SEC",$00,$00,$00,$00 ; flags = op flags
	; entry $18,"CLC",$00,$00,$00,$00
	; entry $F8,"SED",$00,$00,$00,$00
	; entry $D8,"CLD",$00,$00,$00,$00
	; entry $78,"SEI",$00,$00,$00,$00
	; entry $58,"CLI",$00,$00,$00,$00
	; entry $B8,"CLV",$00,$00,$00,$00
	
	; entry $EA,"NOP",$00,$00,$00,$00
	
	lda #$00
	jmp exit


; .ifndef OFFICIAL_ONLY
; 	entry $1A,"NOP"
; 	entry $3A,"NOP"
; 	entry $5A,"NOP"
; 	entry $7A,"NOP"
; 	entry $DA,"NOP"
; 	entry $FA,"NOP"
; .endif
; instrs_size = * - instrs

; instr_template:
; 	nop
; 	jmp instr_done
; instr_template_size = * - instr_template

; .include "instr_test_end.s"

; test_values:
; 	test_normal
; 	rts
