ExecBase=4
Allocmem=-198
Open=-30
Close=-36
Read=-42
Write=-48
OpenLib=-408
CloseLib=-414
GetMsg=-372
OpenWindow=-204
CloseWindow=-72
WaitPort=-384
FindTask=-294

CLI_WB:                   ;We must determine where we started from
 move.l ExecBase,a6
 move.l #0,a1
 jsr    FindTask(a6)
 move.l d0,a2
 tst.l  $ac(a2)
 bne    FromCLI
 lea    $5c(a2),a0    ;we started from workbench
 jsr    WaitPort(a6)  ;get the wb message but we do not use it
 lea    $5c(a2),a0
 jsr    GetMsg(a6)

FromCLI:
 move.l #20,DOSResult   ;DOSResult will give a return value to DOS
 move.l ExecBase,a6
Open_DOS:             ;we'll open dos.library
 lea    DOS_Name,a1
 moveq  #0,d0          ;any version
 jsr    OpenLib(a6)
 move.l d0,DOS_Base
 beq    No_DOS        ;if coud not open DOS. we should exit!
Window_Opening:
 move.l  #Consolename,d1   ;opening awindow
 move.l  #1005,d2        ;mode_old
 move.l  DOS_Base,a6
 jsr     open(a6)
 move.l d0,Window_Handler
 beq    NoMem               ;if could noy open CON, then exit
 move.l DOS_Base,a6
 move.l Window_Handler,d1
 move.l #texte,d2
 move.l #textend-texte,d3
 jsr    write(a6)          ;write introduction text
 move.l #inbuff,d2
 move.l DOS_Base,a6
 move.l Window_Handler,d1
 jsr    read(a6)           ;read the user's choice to install the code
 moveq  #0,d1
 move.b inbuff,d1
 cmpi.b #'i',d1       ;is it 'i' ?
 beq    install
 cmpi.b #'I',d1       ;or 'I' ?
 bne    NoMem         ;if not equal exit
Install:
 move.l  #ende-begin,d0  ; length  of actual code in d0
 moveq   #0,d1
 move.l  ExecBase,a6
 jsr     Allocmem(a6)   ;allocate mem
 move.l  d0,NewExcept
 beq     NoMem
 move.l  #1024,d0      ;there are 255 longword vector addresses
 moveq   #0,d1
 move.l  ExecBase,a6
 jsr     Allocmem(a6)
 move.l  d0,NewVec     ;address of the copied original vectors
 beq     NoMem
 move.l  $10,OldExcept  ;save the original 'illegal instruction' address
 movea.l #begin,a0
 movea.l NewExcept,a1
 move.l  #ende-begin,d0
 sub.l   #1,d0
copy:
 move.b  (a0)+,(a1)+    ;copy our exception code to the allocated mem
 dbf     d0,copy
 move.l  #1023,d0
 movea.l #0,a0
 movea.l NewVec,a1
copy2:
 move.b  (a0)+,(a1)+   ;get a copy of all the vector area contents
 dbf     d0,copy2
 move.l  NewExcept,$10   ;install code
 move.l DOS_Base,a6
 move.l Window_Handler,d1
 move.l #text2,d2
 move.l #textend2-text2,d3
 jsr    write(a6)            ;write 'Now you can run 68010...'
 move.l #inbuff,d2
 move.l DOS_Base,a6
 move.l Window_Handler,d1
 jsr    read(a6)           ;wait for user to press return
 move.l  #0,DOSResult

NoMem:
  move.l  Window_Handler,d1 
  move.l  DOS_Base,a6
  jsr     Close(a6)       ;close CON

close_DOS:
 move.l DOS_base,a1
 move.l ExecBase,a6
 jsr    CloseLIB(a6)    ;close DOS
No_DOS:
 move.l DOSResult,d0
 rts

Consolename:  dc.b 'CON:80/50/480/120/Run 68010 programs!',0
 align
DOS_Name:       dc.b 'dos.library',0
 align
texte:
 dc.b 'This program allows you to run 68010 software on a 68000',13,10,13,10
 dc.b 'It uses self-modifying code so do not run it if you have',13,10
 dc.b 'a cache.It would not have any effect on 680x0 (x>0).',13,10
 dc.b 'Written By Kamran Karimi',13,10,13,10
 dc.b 'enter  ->i<-  to install the code, or Return key to quit',13,10
 dc.b 'without installing',13,10,13,10
 dc.b 'Enter i to install:'
textend:
 align
text2:
 dc.b 13,10,'Now you can run 68010 software!',13,10
 dc.b '   Press return...'
textend2:
 align
DOS_Base:       dc.l 0
Window_handler: dc.l 0
DOSResult:      dc.l 0
inbuff:         dc.b 0,0

begin:                      ;determining which command caused exception
 movem.l d0-d7/a0-a6,-(a7)
 movea.l 62(a7),a0
 move.w  (a0),d3
 move.w  d3,d4
 cmpi.w  #$4e74,d3   ;was is RTD?
 beq     R_T_D
 lsr.w   #1,d3
 cmpi.w  #$273d,d3     ;or MOVEC?
 bne     what1
 move.w  60(a7),d0  ;get status register
 btst    #13,d0  ;check if we were in supervisor mode when exception occured
 bne     M_O_V_E_C
 movem.l (a7)+,d0-d7/a0-a6
 move.l  $20,-(a7)           ;making a fake return address and SR on stack
 suba.l  #2,a7
 move.w  $6(a7),(a7)
 bset    #13,(a7)    ;supervisor mode
 bclr    #15,(a7)    ;no trace
 rte
what1:
 move.w  d4,d3
 lsr.w   #8,d3
 cmpi.w  #$0e,d3    ;was the illegal command MOVES?
 bne     what2
 move.w  60(a7),d0
 btst    #13,d0      ;in supervisor mode
 bne     M_O_V_E_S
 movem.l (a7)+,d0-d7/a0-a6
 move.l  $20,-(a7)    ;making a fake return address and SR on stack
 suba.l  #2,a7
 move.w  $6(a7),(a7)
 bset    #13,(a7)    ;supervisor mode
 bclr    #15,(a7)    ;no trace
 rte
what2:
 move.w  d4,d3
 lsr.w   #6,d3
 cmpi.w  #$010b,d3         ;was the instruction move ccr,<ea> ?
 beq     M_O_V_E_F_C_C_R

illegale:      ;it was non of them so do the usual exception processing
 movem.l (a7)+,d0-d7/a0-a6
 move.l   OldExcept(pc),-(a7) ;place address of original except handler
 suba.l   #2,a7                  ;as return address on the stack
 move.w   $6(a7),(a7)
 bset     #13,(a7)
 bclr     #15,(a7)
 rte


R_T_D:      ;Syntax: rtd  #<data>
 adda.l  #2,a0
 moveq   #0,d0
 move.w  (a0),d0    ;d0 = #<data>
 move.w  60(a7),d1
 btst    #13,d1         ;which stack we were using befor the exception?
 bne     SuperStack
 move.l  usp,a6
 move.l  (a6)+,62(a7)  ;place return address on the usp as the except return
 adda.l  d0,a6        ;address on top of the ssp so we'll return there
               ;then add  the number of bytes appropriate to the usp
 move.l  a6,usp
 bra     EndIt
SuperStack:
 move.l  a7,a6
 adda.l  #70,a6 ;60=15 regs*4,2 for SR,4 for illegal inst,addr,4for ret addr
 adda.l  d0,a6
 move.l  66(a7),-(a6)  ;retun address for rtd
 move.w  60(a7),-(a6)  ;SR
 move.l  #14,d4       ;15 regs
 adda.l  #60,a7
cop:
 move.l  -(a7),-(a6)
 dbra    d4,cop
 move.l  a6,a7
EndIt:
 movem.l (a7)+,d0-d7/a0-a6
 rte


M_O_V_E_C:   ;Syntax:movec CR,Rn or movec Rn,CR (CR=a control register)
 moveq   #0,d2  ;in d2 we'll place the emulated code
 moveq   #0,d5  ;all other regisres are used as flags or variable holders
 moveq   #0,d6 ;this speeds up operations because no mem access is involved
 moveq   #0,d7
 move.w  (a0),d3  ;this is the illegal instruction
 btst    #0,d3
 seq     d5      ;d5=1 if movec CR,Rn,d5=0 if movec Rn,CR
 adda.l  #2,a0
 move.w  (a0),d3  ;get the next word
 move.w  d3,d4    ;get a copy of it
 btst    #15,d3
 seq     d6     ;d6=1 if Rn is a data register,0 if Rn is address refister
 tst.b   d5
 beq     ToCR
 tst.b   d6
 beq     addressreg
 move.w  #$2009,d2   ;move.l a1,Dn
 bra     GoOn1
addressreg:
 move.w  #$2049,d2   ;move.l a1,An
GoOn1:
 andi.l  #$00007000,d3   ;get the register
 move.l  d3,d7
 lsr.w   #8,d7
 lsr.w   #4,d7        ;get it to right for comarison
 lsr.w   #3,d3        ;place it in the destination register place
 or.w    d3,d2        ;put it in d2  (n in An or Dn determined)
 andi.w  #$0fff,d4     ;get the control register
 cmpi.w  #$0,d4        ;is it SFC?
 bne     nextt1
 movea.l SFC(pc),a1     ;put its contents in a1
 bra     here1
nextt1:
 cmpi.w  #$0001,d4     ;is it DFC?
 bne     nextt2
 movea.l DFC(pc),a1    ;put it in a1
 bra     here1
nextt2:
 cmpi.w  #$0800,d4     ;is it USP?
 bne     nextt3
 move    USP,a1        ;put it in a1
 bra     here1
nextt3:
 cmpi.w  #$0801,d4      ;is it VBR?
 bne     illegale
 movea.l VBR(pc),a1    ; put it in a1
Here1:
 cmpi.l  #1,d7          ;is the destination register also a1 or d1?
 bne     Nota1
 lea     savea1(pc),a3  ;yes so instead of move.l a1,a1:move.l d0,a1
 move.l  a1,(a3)        ;save a1
 andi.w  #$fff6,d2      ;prepare the code for it
 lea     code11(pc),a3  ;code11 is the place of the constructed instruction
 move.w  d2,(a3)
 lea     saveA7(pc),a3
 move.l  a7,(a3)     ;save a7,we need it to write position-independent code
 movem.l (a7)+,d0-d7/a0-a6   ;we must work with actual register contents
 lea     savereg(pc),a7
 move.l  d0,(a7)         ;save original contents of d0
 move.l  savea1(pc),d0   ;move a1 to d0
code11:  dc.w 0          ;execute our move.l instructtion
 move.l  savereg(pc),d0  ;restore contents of d0
 bra     done1
Nota1:                     ;the destination is not a1
 lea     savea1(pc),a3
 move.l  a1,(a3)       ;save a1,because after restoring regs it will be lost
 lea     code12(pc),a3
 move.w  d2,(a3)       ;put the move.l in its place
 lea     saveA7(pc),a3
 move.l  a7,(a3)            ;save a7
 movem.l (a7)+,d0-d7/a0-a6
 lea     savereg(pc),a7
 move.l  a1,(a7)           ;save original a1
 movea.l savea1(pc),a1     ;move CR content to a1
code12:  dc.w 0            ;execute code
 move.l  savereg(pc),a1    ;restore a1
done1:
 move.l  saveA7(pc),a7     ;restore a7
 adda.l  #60,a7            ;add 60 because we pull 60 byte from stack
 movem.l d0-d7/a0-a6,-(a7)
 move.l  62(a7),d4         ;get the address of the movec instruction
 add.l   #4,d4       ;add 4 so that execution begins with the next opcode
 move.l  d4,62(a7)
 movem.l (a7)+,d0-d7/a0-a6
 rte

ToCR:
 tst.b   d6
 beq     address2
 move.w  #$2200,d2
 bra     GoOn2
address2:
 move.w  #$2208,d2
GoOn2:
 andi.l  #$00007000,d3
 move.l  #12,d7
 lsr.w   d7,d3
 move.w  d3,d7
 or.w    d3,d2
 lea     critical(pc),a3
 move.w  d4,(a3)
 cmpi.l  #1,d7
 bne     Notd1
 andi.w  #$fdff,d2
 lea     code21(pc),a3
 move.w  d2,(a3)
 lea     saveA7(pc),a3
 move.l  a7,(a3)
 movem.l (a7)+,d0-d7/a0-a6
 lea     savereg(pc),a7
 move.l  d0,(a7)
code21:  dc.w 0
 lea     saved1(pc),a7
 move.l  d0,(a7)
 move.l  savereg(pc),d0
 move.l  saveA7(pc),a7
 adda.l  #60,a7
 movem.l d0-d7/a0-a6,-(a7)
 move.l  saved1(pc),d1
 bra     done2
Notd1:
 lea     code22(pc),a3
 move.w  d2,(a3)
 lea     saveA7(pc),a3
 move.l  a7,(a3)
 movem.l (a7)+,d0-d7/a0-a6
 lea     savereg(pc),a7
 move.l  d1,(a7)
code22:  dc.w 0
 lea     saved1(pc),a7
 move.l  d1,(a7)
 move.l  savereg(pc),d1
 move.l  saveA7(pc),a7
 adda.l  #60,a7
 movem.l d0-d7/a0-a6,-(a7)
 move.l  saved1(pc),d1
done2:
 move.w  critical(pc),d4
 andi.w  #$0fff,d4
 cmpi.w  #$0,d4
 bne     nextr1
 lea     SFC(pc),a3
 move.l  d1,(a3)
 bra     here2
nextr1:
 cmpi.w  #$0001,d4
 bne     nextr2
 lea     DFC(pc),a3
 move.l  d1,(a3)
 bra     here2
nextr2:
 cmpi.w  #$0800,d4
 bne     nextr3
 movea.l d1,a2
 move    a2,USP
nextr3:
 cmpi.w  #$0801,d4
 bne     illegale
 lea     VBR(pc),a3
 move.l  d1,(a3)
 bne     NotZero   ;if new address not zero then copy the 1024 bytes at the
 movea.l #0,a5         ;VBR address to the locations 0-1024
 movea.l NewVec(pc),a4
 move.l  #1023,d4
copy3:
 move.b  (a4)+,(a5)+
 dbf     d4,copy3
 move.l  NewExcept(pc),$10 ;install this program again otherwise we'll have
 bra     here2      ;troubles the second time you call a 68010 instruction
NotZero:
 movea.l VBR(pc),a4 ;if the VBR holds 0,then copy the original vectors in
 movea.l #0,a5      ;in its place
 move.l  #1023,d4
copy4:
 move.b  (a4)+,(a5)+
 dbf     d4,copy4
 move.l  NewExcept(pc),$10   ;install this program again

here2:
 move.l  62(a7),d4
 add.l   #4,d4
 move.l  d4,62(a7)
 movem.l (a7)+,d0-d7/a0-a6
 rte

M_O_V_E_S:       ;Syntax:moves Rn,<ea> or moves <ea>,Rn
 adda.l  #2,a0    ;address of the second word of operand
 move.w  (a0),d3
 btst    #11,d3
 beq     ea2Rn
           ;this is moves.x  Rn,<ea>.first move.x Rn,d0 then move.x d0,<ea>
 moveq   #0,d2      ;we will produce the opcode in d2
 movea.l 62(a7),a0
 move.w  (a0),d3    ;first word in d3
 andi.w  #$00c0,d3     ;determine operation size (.B, .W or .L)
 lsr.w   #6,d3
 cmpi.w  #0,d3
 bne     wl
 move.w  #$1000,d2
 bra     size1
wl:               ;Word or Long
 cmpi.w  #1,d3
 bne     l
 move.w  #$3000,d2
 bra     size1
l:                 ;Long
 move.w  #$2000,d2
size1:
 adda.l  #2,a0
 move.w  (a0),d3    ;second word in d3
 andi.w  #$f000,d3
 lsr.w   #8,d3
 lsr.w   #4,d3
 cmpi.w  #0,d3
 seq     d6      ;was the Rn, d0? if yes, then set d6 to 1
 or.w    d3,d2
 tst.b   d6
 beq     Notd01
 movem.l (a7)+,d0-d7/a0-a6
 movem.l d0-d7/a0-a6,-(a7)
 lea     saved0(pc),a3
 move.l  d0,(a3)
 bra     here3
Notd01:
 lea     CRn2d2,a3
 move.w  d2,(a3)
 lea     saveA7(pc),a3
 move.l  a7,(a3)
 movem.l (a7)+,d0-d7/a0-a6
 lea     savereg(pc),a7
 move.l  d0,(a7)
CRn2d2:  dc.w 0
 lea     saved0(pc),a7
 move.l  d0,(a7)
 move.l  savereg(pc),d0
 move.l  saveA7(pc),a7
 adda.l  #60,a7
 movem.l d0-d7/a0-a6,-(a7)
here3:
 moveq   #0,d2
 movea.l 62(a7),a0
 move.w  (a0),d3
 move.w  d3,d4
 andi.w  #$0007,d3     ;register number of <ea>
 cmpi.w  #0,d3
 seq     d5 ;set if register number=0, if mode=7 then it means Absolut short
 cmpi.w  #1,d3
 seq     d7 ;if reg num=1 and mode =7 then addressing=absolute long
 lsl.w   #8,d3
 lsl.w   #1,d3
 or.w    d3,d2
 move.w  d4,d3
 andi.w  #$0038,d3      ;get the mode in d3 lsr.w   #3,d3
 cmpi.w  #7,d3
 seq     d1     ;if mode=1 then set d1 to 1
 cmpi.w  #5,d3
 bne     gg1
 seq     d6   ;if mode=5 then address reg indirect with displacement
 bra     gg2
gg1:
 cmpi.w  #6,d3
 seq     d6 ;if mode=6 then address reg indirect with index and displacement
gg2:
 lsl.w   #6,d3
 or.w    d3,d2
 move.w  d4,d3
 andi.w  #$00c0,d3       ;get size
 lsr.w   #6,d3
 cmpi.w  #0,d3
 bne     wl2
 ori.w   #$1000,d2
 bra     size2
wl2:
 cmpi.w  #1,d3
 bne     l2
 ori.w   #$3000,d2
 bra     size2
l2:
 ori.w   #$2000,d2
size2:
 tst.b   d6
 beq     NoAdind
 adda.l  #4,a0
 lea     code32(pc),a3
 move.w  (a0),(a3)
 lea     code33(pc),a3
 move.w  #$4e71,(a3)
 lea     NumAdd(pc),a3
 move.l  #6,(a3)
 bra     GoOn5
NoAdind:  ;it is no form of address reg indirect with displacement or index
 tst.b   d1
 beq     NoExt  ;<ea> has no extention words at all (like (An) or (An)+)
 tst.b   d5
 beq     testlong
 adda.l  #4,a0       ;get the extention word
 lea     code32(pc),a3
 move.w  (a0),(a3)       ;move extention word
 lea     code33(pc),a3
 move.w  #$4e71,(a3)  ;move NOP
 lea     NumAdd(pc),a3 ;we must add 6 to the pc to get the next instruction
 move.l  #6,(a3)
 bra     GoOn5
testlong:       ;is it absolute long addressing
 tst.b   d7
 beq     illegale  ;could not fined a legal addressing
 adda.l  #4,a0
 lea     code32(pc),a3
 move.l  (a0),(a3)
 lea     NumAdd(pc),a3
 move.l  #8,(a3)
 bra     GoOn5
NoExt:
 lea     code32(pc),a3
 move.l  #$4e714e71,(a3)  ;move two NOPs
 lea     NumAdd(pc),a3
 move.l  #4,(a3)
GoOn5:
 lea     code31(pc),a3
 move.w  d2,(a3)
 lea     saveA7(pc),a3
 move.l  a7,(a3)
 movem.l (a7)+,d0-d7/a0-a6
 lea     savereg(pc),a7
 move.l  d0,(a7)
 move.l  saved0(pc),d0
code31:  dc.w 0
code32:  dc.w 0
code33:  dc.w 0
 move.l  savereg(pc),d0
 move.l  saveA7(pc),a7
 adda.l  #60,a7
 movem.l d0-d7/a0-a6,-(a7)
 move.l  62(a7),d4
 add.l   NumAdd(pc),d4
 move.l  d4,62(a7)
 movem.l (a7)+,d0-d7/a0-a6
 rte

ea2Rn:    ;moves.x <ea>,Rn=move.x <ea>,d0 + move.x d0,Rn
 moveq   #0,d2
 movea.l 62(a7),a0
 move.w  (a0),d3
 move.w  d3,d4
 andi.w  #$003f,d3
 move.w  d3,d2
 move.w  d4,d3
 andi.w  #$0007,d3
 cmpi.w  #0,d3
 seq     d5
 cmpi.w  #1,d3
 seq     d7
 move.w  d4,d3
 andi.w  #$0038,d3
 lsr.w   #3,d3
 cmpi.w  #7,d3
 seq     d1
 cmpi.w  #5,d3
 bne     ff1
 seq     d6
 bra     ff2
ff1:
 cmpi.w  #6,d3
 seq     d6
ff2:
 move.w  d4,d3
 andi.w  #$00c0,d3
 lsr.w   #6,d3
 cmpi.w  #0,d3
 bne     wl3
 ori.w   #$1000,d2
 bra     size3
wl3:
 cmpi.w  #1,d3
 bne     l3
 ori.w   #$3000,d2
 bra     size3
l3:
 ori.w   #$2000,d2
size3:
 tst.b   d6
 beq     NoAdind2
 adda.l  #4,a0
 lea     code42(pc),a3
 move.w  (a0),(a3)
 lea     code43(pc),a3
 move.w  #$4e71,(a3)
 lea     NumAdd(pc),a3
 move.l  #6,(a3)
 bra     GoOn6
NoAdind2:
 tst.b   d1
 beq     NoExt2
 tst.b   d5
 beq     testlong2
 adda.l  #4,a0
 lea     code42(pc),a3
 move.w  (a0),(a3)
 lea     code43(pc),a3
 move.w  #$4e71,(a3)
 lea     NumAdd(pc),a3
 move.l  #6,(a3)
 bra     GoOn6
testlong2:
 tst.b   d7
 beq     illegale
 adda.l  #4,a0
 lea     code42(pc),a3
 move.l  (a0),(a3)
 lea     NumAdd(pc),a3
 move.l  #8,(a3)
 bra     GoOn6
NoExt2:
 lea     code42(pc),a3
 move.l  #$4e714e71,(a3)
 lea     NumAdd(pc),a3
 move.l  #4,(a3)
GoOn6:
 lea     code41(pc),a3
 move.w  d2,(a3)
 lea     saveA7(pc),a3
 move.l  a7,(a3)
 movem.l (a7)+,d0-d7/a0-a6
 lea     savereg(pc),a7
 move.l  d0,(a7)
code41: dc.w 0
code42: dc.w 0
code43: dc.w 0
 lea     saved0(pc),a7
 move.l  d0,(a7)
 move.l  savereg(pc),d0
 move.l  saveA7(pc),a7
 adda.l  #60,a7
 movem.l d0-d7/a0-a6,-(a7)
here6:
 moveq   #0,d2
 movea.l 62(a7),a0
 move.w  (a0),d3
 andi.w  #$00c0,d3
 lsr.w   #6,d3
 cmpi.w  #0,d3
 bne     wl4
 move.w  #$1000,d2
 bra     size4
wl4:
 cmpi.w  #1,d3
 bne     l4
 move.w  #$3000,d2
 bra     size4
l4:
 move.w  #$2000,d2
size4:
 adda.l  #2,a0
 move.w  (a0),d3
 btst    #15,d3
 seq     d5
 andi.w  #$7000,d3
 move.w  d3,d7
 lsr.w   #8,d7
 lsr.w   #4,d7
 lsr.w   #3,d3
 cmpi.w  #0,d7
 seq     d6
 tst.b   d5
 bne     GoOn4
 ori.w   #$0040,d3
GoOn4:
 or.w    d3,d2
 tst.b   d6
 beq     Notd02
 ori.w   #$0001,d2
 lea     Cd2Rn1(pc),a3
 move.w  d2,(a3)
 lea     saveA7(pc),a3
 move.l  a7,(a3)
 movem.l (a7)+,d0-d7/a0-a6
 lea     savereg(pc),a7
 move.l  d1,(a7)
 move.l  saved0(pc),d1
Cd2Rn1:  dc.w 0
 move.l  savereg(pc),d1
 bra     here4
Notd02:
 lea     Cd2Rn2(pc),a3
 move.w  d2,(a3)
 lea     saveA7(pc),a3
 move.l  a7,(a3)
 movem.l (a7)+,d0-d7/a0-a6
 lea     savereg(pc),a7
 move.l  d0,(a7)
 move.l  saved0(pc),d0
Cd2Rn2:  dc.w 0
 move.l  savereg(pc),d0
here4:
 move.l  saveA7(pc),a7
 adda.l  #60,a7
 movem.l d0-d7/a0-a6,-(a7)
 move.l  62(a7),d4
 add.l   NumAdd(pc),d4
 move.l  d4,62(a7)
 movem.l (a7)+,d0-d7/a0-a6
 rte

M_O_V_E_F_C_C_R:     ;Syntax: move CCR,<ea> = move CCR,d0 + move d0,<ea>
 moveq   #0,d0         ;move SR to d0 then and with #$00ff
 move.w  60(a7),d0
 andi.w  #$00ff,d0
 lea     saved0(pc),a3
 move.w  d0,(a3)
 moveq   #0,d2
 movea.l 62(a7),a0
 move.w  (a0),d3
 move.w  d3,d4
 andi.w  #$003f,d3
 cmpi.w  #$0,d3        ;is <ea> the same as d0?
 bne     Notd04
 movem.l (a7)+,d0-d7/a0-a6
 move.w  saved0(pc),d0
 movem.l d0-d7/a0-a6,-(a7)
 lea     NumAdd(pc),a3
 move.l  #2,(a3)
 bra     here7
Notd04:
 move.w  d4,d3
 andi.w  #$0007,d3
 cmpi.w  #0,d3
 seq     d5
 cmpi.w  #1,d3
 seq     d7
 lsl.w   #8,d3
 lsl.w   #1,d3
 or.w    d3,d2
 move.w  d4,d3
 andi.w  #$0038,d3
 lsr.w   #3,d3
 cmpi.w  #7,d3
 seq     d1
 cmpi.w  #5,d3
 bne     hh1
 seq     d6
 bra     hh2
hh1:
 cmpi.w  #6,d3
 seq     d6
hh2:
 lsl.w   #6,d3
 or.w    d3,d2
 move.w  d4,d3
 ori.w   #$3000,d2
 tst.b   d6
 beq     NoAdind3
 adda.l  #2,a0
 lea     code52(pc),a3
 move.w  (a0),(a3)
 lea     code53(pc),a3
 move.w  #$4e71,(a3)
 lea     NumAdd(pc),a3
 move.l  #4,(a3)
 bra     GoOn7
NoAdind3:
 tst.b   d1
 beq     NoExt3
 tst.b   d5
 beq     testlong3
 adda.l  #2,a0
 lea     code52(pc),a3
 move.w  (a0),(a3)
 lea     code53(pc),a3
 move.w  #$4e71,(a3)
 lea     NumAdd(pc),a3
 move.l  #4,(a3)
 bra     GoOn7
testlong3:
 tst.b   d7
 beq     illegale
 adda.l  #2,a0
 lea     code52(pc),a3
 move.l  (a0),(a3)
 lea     NumAdd(pc),a3
 move.l  #6,(a3)
 bra     GoOn7
NoExt3:
 lea     code52(pc),a3
 move.l  #$4e714e71,(a3)
 lea     NumAdd(pc),a3
 move.l  #2,(a3)
GoOn7:
 lea     code51(pc),a3
 move.w  d2,(a3)
 lea     saveA7(pc),a3
 move.l  a7,(a3)
 movem.l (a7)+,d0-d7/a0-a6
 lea     savereg(pc),a7
 move.l  d0,(a7)
 move.w  saved0(pc),d0
code51:  dc.w 0
code52:  dc.w 0
code53:  dc.w 0
 move.l  savereg(pc),d0
 move.l  saveA7(pc),a7
 adda.l  #60,a7
 movem.l d0-d7/a0-a6,-(a7)
here7:
 move.l  62(a7),d4
 add.l   NumAdd(pc),d4
 move.l  d4,62(a7)
 movem.l (a7)+,d0-d7/a0-a6
 rte


OldExcept:  dc.l 0
NewExcept:  dc.l 0
NewVec:     dc.l 0
VBR:        dc.l 0
SFC:        dc.l 0
DFC:        dc.l 0
savea1:     dc.l 0
saved1:     dc.l 0
saved0      dc.l 0
critical:   dc.w 0
savereg:    dc.l 0
saveA7:     dc.l 0
NumAdd:     dc.l 0

ende:
 end

