; Code to implement the two undocumented op-codess
; $12 and $13 used on the Namco 60A1 and 63A1 micro-controllers 
; on the HD6301/6303/63701 micro-controllers
;
; These instructions perform
; "addx 1,sp"
; add the byte value last pushed onto the stack to X-reg
;
 
; The code is for the freeware motorola 6801 assembler ( AS01.EXE )

; 
; -- jrok 2005


org $E000
; invalid opcode trap is redirected down here...


; set X to the top of the stack

tsx ; x = sp + 1

; at this point the stack poined to by X contains

; offset register
; ------ --------
; 0 CPU flags
; 1 A
; 2 B
; 3 Xhi
; 4 Xlo
; 5 return address hi
; 6 return address lo

; 7 byte to be added 


; increment the PC by 1 opcode
; skip over the invalid instruction
; on RTI


ldd 5,x
addd #1
std 5,x 


; byte on the top of the stack before the
; invalid opcode trap is the value
; to be added to X

ldab $7, x ; top byte of stack for add !!
ldx $3, x ; load X from the stack
abx

; 6301 opcode "xgdx ; swap D and X"
; not supported on AS01 6801 assembler 


fcb $18

; get X pointing back at the stack
tsx

; save the new value of X
std 3,x

rti



; original code
; superceded by the correct method ;)

; tab ; transfer A to B
; abx ; add A & B
; xgdx ; 
; tsx
;
; staa 3,x ; save X register to its 
; stab 4,x ; restore location
;
; ldd 5,x ; increment the PC by 1
; addd #1
; std 5,x
;
; rti