exec.inc
chalharu_nerust/roms/ppu/ppu_read_buffer/source/filler/exec.inc
Pop:	inc byte [R_S]
	mov al, [R_S]
	mov ah, 1
	jmp RB

Push:	mov dl, al ; V becomes the second parameter to WB
	mov al, 0
R_S	equ $-1
	mov ah, 1
	dec byte [R_S]
	jmp WB

Misfire:
	; ax = reference page; dx = intended destination
        mov al, dl ; ax=wrapped address: al = new address, ah = old page
	cmp ax, dx
	jne RB ; If the wrapped address is not same, do extra read
	ret

ExecuteOpcode:
	mov al, [C_NMI]
	push ax
	 mov di, 0xC000
R_PC	 equ $-2

	 mov ax, di
	 inc di
	 call RB
	 mov ah, 0
	 mov [C_OPCODE], ax
	pop ax

	;;;;;;;;;;;
	;; TODO: insert NMI/IRQ
	;;;;;;;;;;;
	
	mov byte [C_PBITS], 0x30
	cmp byte [C_RESET], 0
	jne .GotReset
	cmp al, 0
	je .NotNMI
	cmp byte [C_NMI_EDGE], 0
	je .GotNMI
.NotNMI:cmp byte [C_IRQ], 0
	je .NotIRQ
	test byte [R_P], 4
	jz .GotIRQ
.NotIRQ:cmp al, 0
	jne short  .DoOpcode
	mov byte [C_NMI_EDGE], 0
	jmp short  .DoOpcode
.GotReset:
	mov al,1
	jmp short .GotSpecial
.GotNMI:
	mov byte [C_NMI_EDGE], 1
	mov al,0
	jmp short .GotSpecial
.GotIRQ:
	mov al,2
.GotSpecial:
	mov ah,1
	mov word [C_OPCODE], ax
	mov byte [C_PBITS], 0x20
	;jmp .DoOpcode
.DoOpcode:

	call DEBUG

	mov bx, word 0x0000
C_OPCODE	equ $-2
	mov cl, bl
	shr bx, 3 ; BX = C_OPCODE / 8
	and cl, 7 ; CL = C_OPCODE % 8
	mov al, 1
	shl al, cl
	mov [C_OPCODEBIT], al
	mov byte [C_SB], 0
	mov [mop_bx], bx

	xor si, si	; C_ADDR = 0
	xor bp, bp	; C_D    = 0
	mov cx, 0x00FF	; C_T and C_C

	mov bx, mop_engine

	; REGISTER ALLOCATION:
	;  AX, DX = function parameters and temporaries
	;  AL     = RB&WB return value
	;  AX     = wrap&Misfire return values
	
	;  DI = R_PC
	;  SI = C_ADDR (address operand, initialized to $0000)
	;  BP = C_D    (address index,   initialized to $0000)
	;  CL = C_T    (operand,        initialized to $FF)
	;  CH = C_C    (second operand, initialized to 0)
	;
	;  BX = mop_engine
	;
	; No function must trample these. In addition, Pop must not trample DX.

%macro opcode_test 2
	call bx
	dw %2
	db %1 - $ - 1
	;mov al, [C_OPCODEBIT]	;3 bytes
	;test al, [%2 + bx]	;4 bytes
	;jz short %1		;2 bytes
	; skip if the opcode did not match
%endm

;/* Decode address operand */
mop00:	opcode_test mop01, mop00data
	mov si, 0xFFFA ;// NMI vector location

mop01:	opcode_test mop02, mop01data
        mov si, 0xFFFC ;// Reset vector location

mop02:	opcode_test mop03, mop02data
	mov si, 0xFFFE ;// Interrupt vector location

mop03:	opcode_test mop04, mop03data
        mov ax, di
        inc di
        call RB
        movzx si, al

mop04:	opcode_test mop05, mop04data
	movzx bp, byte[R_X] ;// register index

mop05:	opcode_test mop06, mop05data
	movzx bp, byte[R_Y] ;// register index

mop06:	opcode_test mop07, mop06data
        lea si, [bp+si]   ;// add zeropage-index
        and si, 0xFF
        xor bp, bp
        call tick

mop07:	opcode_test mop08, mop07data
        mov ax, di      ;// absolute address
        inc di
        call RB
        mov dx, si
        mov dh, al
        mov si, dx

mop08:	opcode_test mop09, mop08data
        xchg si, ax
        push ax
         call RB
         movzx si, al
        pop ax
        mov dx, ax
        inc dx
        mov al, dl ; wrapped address: al = new address, ah = old page
        call RB
        mov dx, si
        mov dh, al
        mov si, dx ;// indirect w/ page wrap

mop09:	opcode_test mop10, mop09data
        mov ax, si
        lea dx, [bp+si]
	call Misfire	;// abs. load: extra misread when cross-page

mop10:	opcode_test mop11, mop10data
        mov ax, si ;// abs. store: always issue a misread
        lea dx, [bp+si]
        mov al, dl ; wrapped address: al = new address, ah = old page
	call RB

;/* Load source operand */
mop11:	opcode_test mop12, mop11data
        and cl, byte 0x00 ;// Many operations take A or X as operand. Some try in
R_A	equ $-1

mop12:	opcode_test mop13, mop12data
        and cl, byte 0x00  ;// error to take both; the outcome is an AND operation.
R_X	equ $-1

mop13:	opcode_test mop14, mop13data
        and cl, byte 0x00  ;// sty,dey,iny,tya,cpy
R_Y	equ $-1

mop14:	opcode_test mop15, mop14data
        and cl, [R_S] ;// tsx, las

mop15:	opcode_test mop16, mop15data
        mov al, byte 0x00
R_P	equ $-1
        or  al, byte 0x30
C_PBITS equ $-1
	and cl, al
        mov ch, cl ;// php, flag test/set/clear, interrupts

mop16:	opcode_test mop17, mop16data
        mov ch, cl
        mov cl, 0xFF         ;// save as second operand

mop17:	opcode_test mop18, mop17data
        lea ax, [bp+si]
	call RB
	and cl, al ;// memory operand

mop18:	opcode_test mop19, mop18data
        mov ax, di
        inc di
        call RB
        and cl, al  ;// immediate operand

;/* Operations that mogrify memory operands directly */
mop19:	opcode_test mop1A, mop19data
	mov al, cl
	and al, 0xC0
	mov ah, [R_P]
	and ah, 0x3F
	or al, ah
	mov [R_P], al ;// bit

mop1A:	opcode_test mop20, mop1Adata
	mov al, [R_P]
	and al, 1
	mov [C_SB], al	;// rol,rla, ror,rra,arr

mop20:	opcode_test mop21, mop20data
        mov al, cl
        shr al, 7 ;// rol,rla, asl,slo,[arr,anc]
        push word mop21
        mop_set_c:
          mov ah, [R_P]
          and ah, 0xFE
          or al, ah
          mov [R_P], al
          ret

mop21:	opcode_test mop22, mop21data
        mov al, cl
        and al, 1 ;// lsr,sre, ror,rra,asr
        call mop_set_c

mop22:	opcode_test mop23, mop22data
        shl cl, 1
        or cl, [C_SB]

mop23:	opcode_test mop24, mop23data
        shr cl, 1
        mov ah, 0
C_SB	equ $-1
        shl ah, 7
        or cl, ah

mop24:	opcode_test mop25, mop24data
        dec cl ;// dec,dex,dey,dcp
        ; ^ No cx. Must not wrap into ch.

mop25:	opcode_test mop26, mop25data
        inc cl  ;// inc,inx,iny,isb
        ; ^ No cx. Must not wrap into ch.

;/* Store modified value (memory) */
mop26:	opcode_test mop27, mop26data
        lea ax, [bp+si]
	mov dl, cl
	call WB

mop27:	opcode_test mop28, mop27data
        mov ax, si
        lea dx, [bp+si]
        mov al, dl   ; wrapped address: al = new address, ah = old page

        shr dx, 8
        and dl, cl
        mov cl, dl
        call WB		;// [shx,shy,shs,sha?]

;/* Some operations used up one clock cycle that we did not account for yet */
mop28:	opcode_test mop29, mop28data
        call tick ;// nop,flag ops,inc,dec,shifts,stack,transregister,interrupts

;/* Stack operations and unconditional jumps */
mop29:	opcode_test mop30, mop29data
        call tick
        call Pop
        mov cl, al                      ;// pla,plp,rti

mop30:	opcode_test mop31, mop30data
        mov ax, di
        inc di
        call RB
        call Pop
        mov dl, al
        call Pop
        mov dh, al
        mov di, dx ;// rti,rts

mop31:	opcode_test mop32, mop31data
        mov ax, di
        inc di
        call RB ;// rts

mop32:	opcode_test mop33, mop32data
        lea ax, [di-1] ; normal
        cmp word [C_OPCODE], 0
        jne .normal
        lea ax, [di+1] ; BRK
       .normal:
        push ax
         mov al, ah
         call Push
        pop ax
        call Push ;// jsr, interrupts

mop33:	opcode_test mop34, mop33data
        mov di, si ;// jmp, jsr, interrupts

mop34:	opcode_test mop35, mop34data
        mov al, cl
        call Push   ;// pha, php, interrupts

;/* Bitmasks */
mop35:	opcode_test mop36, mop35data
        mov cl, 1

mop36:	opcode_test mop37, mop36data
        shl cl, 1

mop37:	opcode_test mop38, mop37data
        shl cl, 2

mop38:	opcode_test mop39, mop38data
        shl cl, 4

mop39:	opcode_test mop40, mop39data
	not cl ;// sbc, isb,      clear flag

mop40:	opcode_test mop41, mop40data
        or cl, ch  ;// ora, slo,      set flag

mop41:	opcode_test mop42, mop41data
        and cl, ch ;// and, bit, rla, clear/test flag

mop42:	opcode_test mop43, mop42data
        xor cl, ch  ;// eor, sre

;/* Conditional branches */
mop43:	opcode_test mop44, mop43data
        mov al, cl
        or al, al
        jz .NoBranch1
    	call tick
    	mov dx, di
    	mov ax, si ;discard hi part.
    	;movsx ax, al
    	cbw
    	add ax, dx
    	mov di, ax
    	xchg dx, ax
    	call Misfire
   .NoBranch1:

mop44:	opcode_test mop45, mop44data
        mov al, cl
        or al, al
        jnz .NoBranch2
    	call tick
    	mov dx, di
    	mov ax, si ;discard hi part.
    	cbw
    	add ax, dx
    	mov di, ax
    	xchg dx, ax
    	call Misfire
   .NoBranch2:

;/* Addition and subtraction */
mop45:	opcode_test mop46, mop45data
        mov ch, cl
        mov ah, [R_P]
        and ah, 1
        add ah, 0xFF ; now host Cf is set if P.C was
        adc cl, [R_A]
        mov dh, 0
        rcl dh, 1 ; new carry flag is in DH
        mov dl, ch
        xor dl, cl   ; dl = c^t
        xor al, [R_A]; al = A^t
        and al, dl   ; al = (c^t) & (A^t)
        and al, 80h
        shr al, 1     
        or al, dh
         mov ah, [R_P]
         and ah, 0xFF-0x41
        or al, ah
        mov [R_P], al

mop46:	opcode_test mop47, mop46data
        mov al, ch
        sub al, cl
        mov cl, al
        ; FIXME: check if a CMC is necessary here
        cmc
        ;;;
        mov al, 0
        rcl al, 1 ;// cmp,cpx,cpy, dcp, sbx
        call mop_set_c

;/* Store modified value (register) */
mop47:	opcode_test mop48, mop47data
	mov [R_A], cl

mop48:	opcode_test mop49, mop48data
        mov [R_X], cl

mop49:	opcode_test mop50, mop49data
        mov [R_Y], cl

mop50:	opcode_test mop51, mop50data
        mov [R_S], cl

mop51:	opcode_test mop52, mop51data
        mov al, cl
        and al, 0xFF-0x30
        mov [R_P], al ;// plp, rti, flag set/clear

;/* Generic status flag updates */
mop52:	opcode_test mop53, mop52data
        mov al, cl
        and al, 0x80
        mov ah, [R_P]
        and ah, 0x7F
        or al, ah
        mov [R_P], al

mop53:	opcode_test mop54, mop53data
        mov al, [R_P]
        and al, 0xFD
        mov ah, cl
        or ah, ah
        jnz @@nz
        or al, 2
@@nz:   mov [R_P], al

mop54:	opcode_test mop_done, mop54data
        mov al, cl
        add al, 0x20
        and al, 0x40
        mov ah, [R_P]
        and ah, 0xBF
        or al, ah
        mov [R_P], al  ;// [arr]

mop_done:
	mov [R_PC], di
	mov byte [C_RESET], 0
	ret

section .const

mop35data: db 0x01,0x00,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x00,0x01,0x01,0x07
mop37data: db 0x01,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x07
mop40data: db 0xAB,0xA2,0xAA,0xAA,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x07
mop33data: db 0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07
mop28data: db 0xD9,0xD5,0xDC,0xDD,0xC9,0xC5,0xDC,0xDD,0xD8,0xC5,0xDC,0xDD,0xD9,0xC5,0xDC,0xDD,0x00,0x05,0x00,0x05,0x00,0x05,0x00,0x05,0xC8,0xC5,0xDC,0xDD,0xC8,0xC5,0xDC,0xDD,0x07
mop51data: db 0x01,0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x07
mop52data: db 0xEE,0xEE,0xEE,0xEA,0xEE,0xEE,0xEE,0xEA,0xEE,0xEE,0xEE,0xEA,0xEE,0xEF,0xEE,0xEA,0x00,0x0D,0x00,0x01,0xFF,0xFF,0xFE,0xFE,0xFB,0xFF,0xEE,0xEA,0xFB,0xFB,0xEE,0xEA
mop09data: db 0x00,0x00,0x02,0x32,0x00,0x00,0x02,0x32,0x00,0x00,0x02,0x32,0x00,0x00,0x02,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0xFA,0x00,0x00,0x02,0x32,0x00,0x00,0x02,0x32
mop10data: db 0x00,0x00,0x0C,0xC8,0x00,0x00,0x0C,0xC8,0x00,0x00,0x0C,0xC8,0x00,0x00,0x0C,0xC8,0x00,0x00,0x0E,0xFA,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0xC8,0x00,0x00,0x0C,0xC8
mop07data: db 0x00,0xF0,0x00,0xFA,0x01,0xF0,0x00,0xFA,0x00,0xF0,0x00,0xFA,0x00,0xF0,0x00,0xFA,0x00,0xF0,0x00,0xFA,0x00,0xF0,0x00,0xFA,0x00,0xF0,0x00,0xFA,0x00,0xF0,0x00,0xFA
mop05data: db 0x00,0x00,0x0E,0x0A,0x00,0x00,0x0E,0x0A,0x00,0x00,0x0E,0x0A,0x00,0x00,0x0E,0x0A,0x00,0x00,0xCE,0xCA,0x00,0x00,0xCE,0xCA,0x00,0x00,0x0E,0x0A,0x00,0x00,0x0E
mop06data: db 0x0A,0x00,0xF0,0x00,0x0A,0x00,0xF0,0x00,0x0A,0x00,0xF0,0x00,0x0A,0x00,0xF0,0x00,0x0A,0x00,0xF0,0x00,0x0A,0x00,0xF0,0x00,0x0A,0x00,0xF0,0x00,0x0A,0x00,0xF0
mop41data: db 0x00,0x00,0x01,0x01,0xBA,0xB2,0xAB,0xAA,0x00,0x00,0x01,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x01,0x01
mop38data: db 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
mop31data: db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
mop02data: db 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
mop48data: db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xCC,0xCC,0xCC,0xCC,0x00,0x0C,0x00
mop36data: db 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00
mop34data: db 0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07
mop53data: db 0xEE,0xEE,0xEE,0xEA,0xFE,0xFE,0xEE,0xEA,0xEE,0xEE,0xEE,0xEA,0xEE,0xEF,0xEE,0xEA,0x00,0x0D,0x00,0x01,0xFF,0xFF,0xFE,0xFE,0xFB,0xFF,0xEE,0xEA,0xFB,0xFB,0xEE,0xEA,0x00
mop47data: db 0xAE,0xAE,0xAA,0xAA,0xAE,0xAE,0xAA,0xAA,0xAE,0xAE,0xAA,0xAA,0xAE,0xAF,0xAA,0xAA,0x00,0x0C,0x00,0x01,0xAA,0xAA,0xAA,0xAA,0x00,0x00,0x00,0x00,0xAA,0xAA,0xAA,0xAA,0x00
mop26data: db 0xC8,0xC0,0xCC,0xC8,0xC8,0xC0,0xCC,0xC8,0xC8,0xC0,0xCC,0xC8,0xC8,0xC0,0xCC,0xC8,0xFA,0xF0,0xFE,0x22,0x00,0x00,0x00,0x00,0xC8,0xC0,0xCC,0xC8,0xC8,0xC0,0xCC,0xC8,0x00
mop08data: db 0x0B,0x00,0x0E,0x00,0x0A,0x00,0x0E,0x00,0x0A,0x00,0x0E,0x00,0x0A,0x10,0x0E,0x00,0x0A,0x00,0x0E,0x00,0x0A,0x00,0x0E,0x00,0x0A,0x00,0x0E,0x00,0x0A,0x00,0x0E,0x00,0x07
mop11data: db 0xAE,0xAE,0xAA,0xAA,0xBE,0xBE,0xAA,0xAA,0xAE,0xAF,0xAA,0xAA,0x04,0x0C,0x00,0x00,0xAA,0xAA,0xAA,0xAA,0x00,0x05,0x00,0x00,0xAA,0xAA,0xAA,0xAA
mop29data: db 0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x01
mop50data: db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x08
mop54data: db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08
mop27data: db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xD8
mop13data: db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x11,0x10,0x11,0x00,0x00,0x00,0x00,0x11,0x11
mop30data: db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
mop32data: db 0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07
mop03data: db 0xFA,0xF0,0xFF,0xFA,0xFB,0xF0,0xFF,0xFA,0xFA,0xF0,0xFF,0xFA,0xFA,0xF0,0xFF,0xFA,0xFA,0xF0,0xFF,0xFA,0xFA,0xF0,0xFF,0xFA,0xFA,0xF0,0xFF,0xFA,0xFA,0xF0,0xFF,0xFA,0x00
mop04data: db 0x0A,0x00,0xF0,0xF0,0x0A,0x00,0xF0,0xF0,0x0A,0x00,0xF0,0xF0,0x0A,0x00,0xF0,0xF0,0x0A,0x00,0x30,0x30,0x0A,0x00,0x30,0x30,0x0A,0x00,0xF0,0xF0,0x0A,0x00,0xF0,0xF0,0x00
mop22data: db 0xCC,0xC4,0xCC,0xC8,0xCC,0xC4,0xCC,0xC8
mop00data: db 0x00,0x00,0x00,0x00,0x00,0x00,0x00
mop25data: db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0xC8,0xC1,0xCC,0xC8,0x00
mop20data: db 0xCC,0xCC,0xCC,0xC8,0xCC,0xCC,0xCC,0xC8,0x00,0x00,0x00,0x00,0x00,0x08
mop14data: db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C
mop45data: db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xAA,0xA2,0xAA,0xAA,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xAA,0xAA,0xAA,0xAA,0x00
mop16data: db 0xAA,0xA2,0xAA,0xAA,0xBA,0xB2,0xAA,0xAA,0xAA,0xA2,0xAA,0xAA,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xBB,0xBA,0xAA,0xAA,0x11,0x10
mop1Adata: db 0x00,0x00,0x00,0x00,0xCC,0xC4,0xCC,0xC8,0x00,0x00,0x00,0x00,0xCC,0xCC,0xCC,0xC8,0x00
mop12data: db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC8,0xCC,0xCC,0xCC,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x11,0x11
mop21data: db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xCC,0xCC,0xCC,0xC8,0xCC,0xC4,0xCC,0xC8
mop49data: db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x11,0x11,0x10,0x10,0x00,0x01
mop42data: db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xAA,0xA2,0xAA,0xAA
mop46data: db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xBB,0xBA,0xAA,0xAA,0x11,0x10
mop23data: db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xCC,0xCC,0xCC,0xC8,0xCC,0xCC,0xCC,0xC8
mop24data: db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0xC8,0xC4,0xCC,0xC8
mop43data: db 0x00,0x00,0x00,0x00
mop44data: db 0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00
mop39data: db 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0xAA,0xAA,0xAA,0xAA,0x00
mop15data: db 0x01,0x01,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x00,0x01,0x01,0x07
mop18data: db 0x04,0x0A,0x00,0x00,0x04,0x0A,0x00,0x00,0x04,0x0A,0x00,0x00,0x04,0x0A,0x00,0x00,0x05,0x0A,0x00,0x00,0x05,0x0A,0x00,0x00,0x05,0x0A,0x00,0x00,0x05,0x0A
mop19data: db 0x00,0x00,0x00,0x00,0x10,0x10
mop01data: db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
mop17data: db 0xEA,0xE0,0xEE,0xEA,0xFA,0xF0,0xEE,0xEA,0xEA,0xE0,0xEE,0xEA,0xEA,0xE0,0xEE,0xEA,0x00,0x00,0x00,0x00,0xFA,0xF0,0xFE,0xFA,0xFA,0xF0,0xEE,0xEA,0xFA,0xF0,0xEE,0xEA,0x00

section .text

mop_engine:
	; This only purpose of this function is
	; to make the opcode_test macro take 5 bytes
	; rather than 9 bytes per call site.
	pop bx
	push di
	mov di, .return-2
	
	mov ax, [bx]

	 mov dl, [bx+2]
	 sub bx, di
	 inc bx
	 mov [di], bx

	xchg bx, ax
	mov al, 0
    C_OPCODEBIT EQU $-1
	test al, [bx + 0xC3C3]
    mop_bx equ $-2
	jnz .no_skip

	mov dh, 0
	add [di], dx
    .no_skip:
	pop di
	mov bx, mop_engine
	jmp .return + 0xC3C3
    .return:

;1B9
;A3E7

	

%include "disasm.inc"

%include "cpu.asm"


