home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / Z80 emulator / 68K version / cmd_ED.c < prev    next >
Encoding:
Text File  |  1995-11-01  |  12.7 KB  |  669 lines  |  [TEXT/CWIE]

  1.  
  2. /* ----------------------- 0xED Command Dispatcher ------------------------------
  3.     not implemented:  INI, INIR, IND, INDR, OUTI, OTIR, OUTD, OTDR
  4.     illegals marked with *) are taken from G.Lunter's Z80 v3.0 documentation
  5.  
  6.     Z80 Emulator
  7.     Copyright (C) 1994 G.Woigk
  8.     
  9.     This file is part of Mac Spectacle and it is free software
  10.     See application.c for details
  11.             
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
  15. */
  16.  
  17.     
  18. cmd_ED:    
  19.  
  20. // -----    read next byte of instruction ----------------------------
  21.     move.b    (ip)+,db
  22.  
  23.  
  24. // -----    increment r register -----------------------------------
  25. #if EXACT_R
  26.     addq.b    #1,r
  27. #endif
  28.  
  29.  
  30. // -----    debugger related testings -------------------------------
  31. #if CMD_PROFILE || cmd_firstuse
  32.     movea.l    cnt_ed,a0
  33. //    addq.l    #1,(a0,db.l*4)
  34.     lsl    #2,db
  35.     addq.l    #1,(a0,db.l)
  36.     lsr    #2,db
  37. #if cmd_firstuse
  38.     bne.s    cmded2
  39.     }; Do_1st_Instr ( ip-2 ); asm {
  40. cmded2:
  41. #endif
  42. #endif
  43.  
  44.  
  45. // -----    Execute instruction -------------------------------------
  46.     dc.w    0x41FB, 0x4A06        // lea    *+$08(D4.l*2),A0
  47.     adda.w    (a0),a0
  48.     jmp    (a0)
  49.     
  50. ed_tab:    dc.w    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  51.     dc.w    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  52.     dc.w    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  53.     dc.w    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  54.     dc.w    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  55.     dc.w    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  56.     dc.w    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  57.     dc.w    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  58.     
  59.     dc.w    ed_40,    ed_41,    ed_42,    ed_43,    ed_44,    ed_45,    ed_46,    ed_47
  60.     dc.w    ed_48,    ed_49,    ed_4a,    ed_4b,    ed_4c,    ed_4d,    ed_4e,    ed_4f
  61.     dc.w    ed_50,    ed_51,    ed_52,    ed_53,    ed_54,    ed_55,    ed_56,    ed_57
  62.     dc.w    ed_58,    ed_59,    ed_5a,    ed_5b,    ed_5c,    ed_5d,    ed_5e,    ed_5f
  63.     dc.w    ed_60,    ed_61,    ed_62,    ed_63,    ed_64,    ed_65,    ed_66,    ed_67
  64.     dc.w    ed_68,    ed_69,    ed_6a,    ed_6b,    ed_6c,    ed_6d,    ed_6e,    ed_6f
  65.     dc.w    ed_70,    ed_71,    ed_72,    ed_73,    ed_74,    ed_75,    ed_76,    ed_77
  66.     dc.w    ed_78,    ed_79,    ed_7a,    ed_7b,    ed_7c,    ed_7d,    ed_7e,    ed_7f
  67.  
  68.     dc.w    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  69.     dc.w    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  70.     dc.w    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  71.     dc.w    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  72.     dc.w    ed_a0,    ed_a1,    ed_a2,    ed_a3,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  73.     dc.w    ed_a8,    ed_a9,    ed_aa,    ed_ab,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  74.     dc.w    ldir,    ed_b1,    ed_b2,    ed_b3,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  75.     dc.w    lddr,    ed_b9,    ed_ba,    ed_bb,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  76.  
  77.     dc.w    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  78.     dc.w    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  79.     dc.w    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  80.     dc.w    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  81.     dc.w    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  82.     dc.w    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  83.     dc.w    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  84.     dc.w    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP,    EDNOP
  85.  
  86.  
  87. // handle not implemented block commands
  88. ed_a2:    // ini
  89. ed_a3:    // outi
  90. ed_aa:    // ind
  91. ed_ab:    // outd
  92. ed_b2:    // inir
  93. ed_b3:    // otir
  94. ed_ba:    // indr
  95. ed_bb:    // otdr
  96.     bra    exit_illinstr2
  97.  
  98. // handle 0xED00 ... 0xED3F
  99. // handle 0xED80 ... 0xEDBF (except legal instructions (block move/compare/io))
  100. // handle 0xEDC0 ... 0xEDFF
  101. EDNOP:    more4            // 8 T cycles: 4+4
  102.     do_info_illegals2
  103.     m_next
  104.  
  105. // ####################################################################
  106.  
  107. ed_77:    // nop            *)
  108. ed_7f:    // nop            *)
  109.     more4            // 8 T cycles
  110.     do_info_illegals2
  111.     m_next
  112.  
  113.  
  114. ed_4c:    // neg            *)    
  115. ed_54:    // neg            *)
  116. ed_5c:    // neg            *)    
  117. ed_64:    // neg            *)
  118. ed_6c:    // neg            *)
  119. ed_74:    // neg            *)
  120. ed_7c:    // neg            *)
  121.     do_info_illegals2
  122. ed_44:    more4            // neg
  123.     neg.b    a        
  124.     move    ccr,f
  125.     m_next
  126.  
  127.  
  128. ed_55:    // retn        G.Lunter: ret, retn, or reti
  129. ed_65:    // retn        G.Lunter: ret, retn, or reti
  130. ed_75:    // retn        G.Lunter: ret, retn, or reti
  131.     do_info_illegals2
  132. ed_45:    more8        // retn    
  133.     more2        // 14 T cycles: 4+2+8
  134.     do_info_retn        
  135.     move.w    (rp)+,core
  136.     rol.w    #8,core
  137.     movea.l    core,ip
  138.     move.b    IFF2,IFF1
  139.     m_next
  140.  
  141.  
  142. ed_5d:    // reti            G.Lunter: ret, reti, or retn    
  143. ed_6d:    // reti            G.Lunter: ret, reti, or retn    
  144. ed_7d:    // reti            G.Lunter: ret, reti, or retn    
  145.     do_info_illegals2
  146. ed_4d:    more8        // reti    
  147.     more2        // 14 T cycles: 4+8+2
  148.     do_info_reti
  149. ed4d1:    move.w    (rp)+,core
  150.     rol.w    #8,core
  151.     movea.l    core,ip
  152.     m_next
  153.     
  154.  
  155. ed_4e:                // im 0 *)
  156. ed_66:                // im 0 *)
  157. ed_6e:    do_info_illegals2        // im 0 *)
  158. ed_46:    more4            // im 0
  159.     do_info_im
  160.     move.b    #0,IM
  161.     m_next
  162.     
  163. ed_76:    do_info_illegals2        // im 1 *)
  164. ed_56:    more4            // im 1
  165.     do_info_im
  166.     move.b    #1,IM
  167.     m_next
  168.     
  169. ed_7e:    do_info_illegals2        // im 2 *)
  170. ed_5e:    more4            // im 2
  171.     do_info_im
  172.     move.b    #2,IM
  173.     m_next
  174.     
  175.  
  176. ed_47:    more5            // ld i,a
  177.     do_info_i
  178.     move.b    a,RI
  179.     m_next
  180.     
  181. ed_4f:    more5            // ld r,a
  182.     do_info_r
  183.     ld_r_a
  184.     m_next
  185.     
  186. ed_57:    more5            // ld a,i
  187.     do_info_i
  188.     and.b    #1,f
  189.     move.b    RI,a
  190.     move    ccr,d0
  191.     or.b    d0,f
  192.     tst.b    IFF2
  193.     beq    nxtirpt
  194.     bset    #1,f        // copy iff2 to P/V
  195.     m_next
  196.     
  197. ed_5f:    more5            // ld a,r
  198.     do_info_r
  199.     ld_a_r            // returns with flags Z and S set
  200.     move    ccr,d0
  201.     and.b    #1,f        // preserve C flag
  202.     or.b    d0,f
  203.     tst.b    IFF2
  204.     beq    nxtirpt
  205.     bset    #1,f        // copy iff2 to P/V
  206.     m_next
  207.     
  208.  
  209. // -----    Input commands ---------------------------------------
  210. #define    do_input_bc(DEST)        \
  211.         more8            ;\
  212.         sto_cc            ;\
  213.         move.w    BC,-(a7)        ;\
  214.         jsr    Do_Input        ;\
  215.         addq.l    #2,a7        ;\
  216.         move.b    d0,DEST        ;\
  217.         move.b    d0,db        ;\
  218.         and.b    #1,f        ;\
  219.         or.b    (logflags,db.l),f    ;\
  220.         load_rom_end        ;\
  221.         m_next
  222.  
  223. ed_40:    do_input_bc(RB)
  224. ed_48:    do_input_bc(RC)
  225. ed_50:    do_input_bc(RD)
  226. ed_58:    do_input_bc(RE)
  227. ed_60:    do_input_bc(RH)
  228. ed_68:    do_input_bc(RL)
  229. ed_70:    do_input_bc(db)
  230. ed_78:    do_input_bc(a)
  231.  
  232.  
  233. // -----    Output commands ------------------------------------------------
  234. #define    do_output_bc(DATA)        \
  235.         more8            ;\
  236.         sto_cc            ;\
  237.         move.b    DATA,-(a7)    ;\
  238.         move.w    BC,-(a7)        ;\
  239.         jsr    Do_Output        ;\
  240.         addq.l    #4,a7        ;\
  241.         load_rom_end        ;\
  242.         m_next
  243.  
  244. ed_41:    do_output_bc(RB)
  245. ed_49:    do_output_bc(RC)
  246. ed_51:    do_output_bc(RD)
  247. ed_59:    do_output_bc(RE)
  248. ed_61:    do_output_bc(RH)
  249. ed_69:    do_output_bc(RL)
  250. ed_71:    do_info_illegals2        // out (c),0
  251.     do_output_bc(#0)
  252. ed_79:    do_output_bc(a)
  253.  
  254.  
  255. // -----    sbc hl,ss ------------------------------------------------
  256.  
  257. ed_42:    more8            // sbc hl,bc
  258.     more3            // 15 T states: 4+8+3
  259.     move.w    BC,d0
  260.     move.w    HL,d1
  261.     lsr.b    #1,f
  262.     cmp    d0,d0        // set Z flag
  263.     subx.w    d0,d1
  264.     move    ccr,f
  265.     move.w    d1,HL
  266.     m_next
  267.  
  268. ed_52:    more8            // sbc hl,de
  269.     more3
  270.     move.w    DE,d0
  271.     move.w    HL,d1
  272.     lsr.b    #1,f
  273.     cmp    d0,d0        // Z-Flag setzen!
  274.     subx.w    d0,d1        
  275.     move    ccr,f
  276.     move.w    d1,HL
  277.     m_next
  278.     
  279. ed_62:    more8            // sbc hl,hl
  280.     more3
  281.     lsr.b    #1,f
  282.     cmp    d0,d0        // Z-Flag setzen!
  283.     subx.w    d0,d0
  284.     move    ccr,f
  285.     move.w    d0,HL
  286.     m_next
  287.     
  288. ed_72:    more8            // sbc hl,sp
  289.     more3
  290.     move.w    rp,d0
  291.     move.w    HL,d1
  292.     lsr.b    #1,f
  293.     cmp    d0,d0        // Z-Flag setzen!
  294.     subx.w    d0,d1
  295.     move    ccr,f
  296.     move.w    d1,HL
  297.     m_next
  298.     
  299.  
  300. // -----    ld (nn),ss --------------------------------------------------
  301.  
  302. #if rom_protection
  303. sto_bc:    move.w    BC,d0
  304.     bra    store_word
  305. sto_de:    move.w    DE,d0
  306.     bra    store_word
  307. #endif
  308.  
  309. ed_43:    more8        // ld (nn),bc
  310.     more8            
  311.     move.w    (ip)+,core
  312.     rol.w    #8,core
  313.     movea.l    core,a0
  314.     if_rom(sto_bc)
  315.     move.b    RC,(a0)+
  316.     move.b    RB,(a0)
  317.     m_next
  318.  
  319. ed_53:    more8        // ld (nn),de
  320.     more8            
  321.     move.w    (ip)+,core
  322.     rol.w    #8,core
  323.     movea.l    core,a0
  324.     if_rom(sto_de)
  325.     move.b    RE,(a0)+
  326.     move.b    RD,(a0)
  327.     m_next
  328.  
  329. ed_73:    more8        // ld (nn),sp
  330.     more8            
  331.     move.w    (ip)+,core
  332.     rol.w    #8,core
  333.     movea.l    core,a0
  334.     move.w    rp,d0
  335.     if_rom(store_word)
  336.     rol.w    #8,d0
  337.     move.w    d0,(a0)
  338.     m_next
  339.  
  340.  
  341. // -----    ld ss,(nn) --------------------------------------------------------
  342.  
  343. ed_4b:    more8            // ld bc,(nn)
  344.     more8            // 20 T cycles: 4+8+8
  345.     move.w    (ip)+,core
  346.     rol.w    #8,core
  347.     movea.l    core,a0
  348.     move.b    (a0)+,RC
  349.     move.b    (a0),RB
  350.     m_next
  351.  
  352. ed_5b:    more8            // ld de,(nn)
  353.     more8            
  354.     move.w    (ip)+,core
  355.     rol.w    #8,core
  356.     movea.l    core,a0
  357.     move.b    (a0)+,RE
  358.     move.b    (a0),RD
  359.     m_next
  360.  
  361. ed_6b:    more8            // ld hl,(nn)
  362.     more8            
  363.     move.w    (ip)+,core
  364.     rol.w    #8,core
  365.     movea.l    core,a0
  366.     move.b    (a0)+,RL
  367.     move.b    (a0),RH
  368.     m_next
  369.     
  370. ed_7b:    more8            // ld sp,(nn)
  371.     more8            
  372.     move.w    (ip)+,core
  373.     rol.w    #8,core
  374.     movea.l    core,a0
  375.     move.w    (a0),core
  376.     rol.w    #8,core
  377.     movea.l    core,rp
  378.     bne    nxtirpt
  379.     adda.l    #0x00010000,rp    // falls sp := ramend
  380.     m_next
  381.     
  382.  
  383. // -----    adc hl,ss ---------------------------------------------
  384.  
  385. ed_4a:    more8            // adc hl,bc
  386.     more3            // 15 T cycles: 4+8+3
  387.     move.w    BC,d0
  388.     move.w    HL,d1
  389.     lsr.b    #1,f
  390.     cmp    d0,d0        // Z-Flag setzen!
  391.     addx.w    d0,d1
  392.     move    ccr,f
  393.     move.w    d1,HL
  394.     m_next
  395.  
  396. ed_5a:    more8            // adc hl,de
  397.     more3
  398.     move.w    DE,d0
  399.     move.w    HL,d1
  400.     lsr.b    #1,f
  401.     cmp    d0,d0        // Z-Flag setzen!
  402.     addx.w    d0,d1
  403.     move    ccr,f
  404.     move.w    d1,HL
  405.     m_next
  406.     
  407. ed_6a:    more8            // adc hl,hl
  408.     more3
  409.     move.w    HL,d0
  410.     lsr.b    #1,f
  411.     cmp    d0,d0        // Z-Flag setzen!
  412.     addx.w    d0,d0
  413.     move    ccr,f
  414.     move.w    d0,HL
  415.     m_next
  416.  
  417. ed_7a:    more8            // adc hl,sp
  418.     more3
  419.     move.w    rp,d0
  420.     move.w    HL,d1
  421.     lsr.b    #1,f
  422.     cmp    d0,d0        // Z-Flag setzen!
  423.     addx.w    d0,d1
  424.     move    ccr,f
  425.     move.w    d1,HL
  426.     m_next
  427.     
  428.  
  429. // -----    BCD arithmetics ----------------------------------------------
  430.  
  431. ed_67:    more8            // rrd            new: 10.4.95
  432.     more6
  433.     movea.l    AHL,a0
  434.  
  435.     move.b    (a0),db        // db = old (hl) 
  436.     lsr.b    #4,db
  437.     lsl.w    #4,a
  438.     or.b    a,db        // db = new (hl)
  439.  
  440.     move.b    (a0),a
  441.     lsl.b    #4,a
  442.     lsr.w    #4,a
  443.  
  444.     and.b    #1,f
  445.     or.b    (logflags,a.w),f
  446.     store_db
  447.     
  448.  
  449. ed_6f:    more8            // rld            new: 10.4.95
  450.     more6
  451.     movea.l    AHL,a0
  452.  
  453.     move.b    (a0),db        // db = old (hl) 
  454.     lsl.b    #4,db
  455.     moveq    #0x0F,d0
  456.     and.b    a,d0
  457.     or.b    d0,db        // db = new (hl)
  458.  
  459.     sub.b    d0,a
  460.     move.b    (a0),d0
  461.     lsr.b    #4,d0
  462.     or.b    d0,a
  463.  
  464.     and.b    #1,f
  465.     or.b    (logflags,a.w),f
  466.     store_db
  467.     
  468.  
  469. // -----    block instructions ---------------------------------------------
  470.  
  471. ed_a9:    movea.l    AHL,a0        // cpd
  472.     subq.w    #1,HL
  473.     bra.s    cpi1
  474.  
  475. ed_a1:    movea.l    AHL,a0        // cpi            modified 11.apr.95 KIO !
  476.     addq.w    #1,HL
  477. cpi1:    more8
  478.     more4        
  479.     and.b    #0x01,f
  480.     subq.w    #1,BC
  481.     beq.s    cpi2
  482.     addq.b    #2,f    // P/V = 1  if  BC<>0
  483. cpi2:    cmp.b    (a0),a
  484.     move    ccr,d0
  485.     and.b    #0x0c,d0
  486.     or.b    d0,f
  487.     m_next
  488.  
  489.  
  490. ed_b9:    moveq    #-1,d1        // cpdr
  491.     bra.s    cpir0
  492.  
  493. ed_b1:    moveq    #1,d1        // cpir            modified 11.apr.95 KIO !
  494. cpir0:    and.b    #1,f    // preserve c flag
  495.     move.w    HL,core
  496.     move.w    BC,d0
  497. #if EXACT_R
  498.     add.b    d0,r
  499.     add.b    d0,r
  500.     subq.b    #2,r
  501. #endif
  502. #if exact_timing
  503.     more8
  504.     more4        // 'last' byte takes 16 T cycles
  505.     subq.w    #1,d0
  506.     mulu    #21,d0
  507.     sub.l    d0,cc
  508.     move.w    BC,d0    // load again
  509. #endif
  510. cpir1:    move.l    core,a0
  511.     add.w    d1,core    // hl+1 or hl-1, depending on cpir or cpdr
  512.     subq.w    #1,d0    // bc-1
  513.     beq.s    cpir2    // end of buffer
  514.     cmp.b    (a0),a
  515.     bne.s    cpir1
  516.     addq.b    #2,f    // p=1
  517. #if EXACT_R
  518.     sub.b    d0,r    // RC
  519.     sub.b    d0,r    // RC
  520. #endif
  521. #if exact_timing
  522.     moveq    #21,d1
  523.     mulu    d0,d1    // bc (rest)
  524.     add.l    d1,cc
  525. #endif
  526. cpir2:    move.w    core,HL
  527.     move.w    d0,BC
  528.     cmp.b    (a0),a
  529.     move    ccr,d0
  530.     and.b    #0x0C,d0    // z and s flag
  531.     or.b    d0,f
  532.     bra    nxtirpt
  533.     
  534.  
  535. #if rom_protection
  536. lddx:    move.b    (a1),db
  537.     bra    store_byte
  538. #endif
  539.  
  540. ed_a8:    moveq    #-1,d0        // ldd    (hl) -> (de)    modified 11.apr.95 KIO !
  541.     bra.s    ldd1
  542.     
  543. ed_a0:    moveq    #1,d0        // ldi    (hl) -> (de)
  544. ldd1:    more8
  545.     more4
  546.     bset    #1,f    // P/V = 1  if  BC<>0
  547.     subq.w    #1,BC
  548.     bne.s    ldd2
  549.     subq.b    #2,f    // P/V = 0  if  BC==0
  550. ldd2:    movea.l    AHL,a1
  551.     movea.l    ADE,a0
  552.     add.w    d0,HL
  553.     add.w    d0,DE
  554.     if_rom(lddx)
  555.     move.b    (a1),(a0)
  556.     m_next
  557.  
  558.  
  559. // =====    BLOCK MOVE =======================================
  560.  
  561. ldir:    bclr    #1,f    // P/V=0
  562. #if EXACT_R
  563.     add.b    BC,r
  564.     add.b    BC,r
  565.     subq.b    #2,r
  566. #endif
  567. #if exact_timing
  568.     more8
  569.     more4        // 'last' byte takes 16 T cycles
  570.     move.w    BC,d0
  571.     subq.w    #1,d0
  572.     mulu    #21,d0
  573.     sub.l    d0,cc
  574. #endif
  575.     movea.l    AHL,a1
  576.     movea.l    ADE,a0
  577.     move.w    BC,d0
  578.     beq.s    sldir    // slow ldir: complete core shifts (don't worry, be happy!)
  579.     clr.w    BC
  580.     add.w    d0,HL
  581.     bcs.s    sldir1    // slow ldir: source pointer wraps
  582.     add.w    d0,DE
  583.     bcs.s    sldir2    // slow ldir: destination pointer wraps
  584.     if_rom(sldir2)    // slow ldir: first target byte is in rom
  585. // quick ldir: move d0.w bytes (a1)+ -> (a0)+
  586.     subq.w    #1,d0
  587. ldir1:    move.b    (a1)+,(a0)+
  588.     dbf    d0,ldir1
  589.     bra    nxtirpt
  590.  
  591.  
  592. #if rom_protection
  593. ldirx:    movem.l    d0-d2,-(a7)
  594.     move.b    (a1),-(a7)
  595.     move.w    a0,-(a7)
  596.     jsr    write_to_rom
  597.     addq.l    #4,a7
  598.     movem.l    (a7)+,d0-d2
  599.     bra.s    sldir5
  600. #endif
  601.  
  602.  
  603. sldir:    add.w    d0,HL
  604. sldir1:    add.w    d0,DE
  605. sldir2:    moveq    #1,db
  606.     bra.s    sldir3
  607.  
  608. slddr:    sub.w    d0,HL
  609. slddr1:    sub.w    d0,DE
  610. slddr2:    moveq    #-1,db
  611.     
  612. sldir3:    move.w    d0,core        // counter
  613.     subq.w    #1,core
  614.     move.l    a0,d0
  615.     move.l    a1,d1
  616.  
  617. sldir4:    movea.l    d0,a0
  618.     movea.l    d1,a1
  619.     if_rom(ldirx)
  620.     move.b    (a1),(a0)
  621. sldir5:    add.w    db,d0
  622.     add.w    db,d1
  623.     dbf    core,sldir4
  624.  
  625.     moveq    #0,db
  626.     bra    nxtirpt
  627.  
  628.  
  629.  
  630.  
  631. lddr:    bclr    #1,f    // P/V=0
  632. #if EXACT_R
  633.     add.b    BC,r
  634.     add.b    BC,r
  635.     subq.b    #2,r
  636. #endif
  637. #if exact_timing
  638.     more8
  639.     more4        // 'last' byte takes 16 T cycles
  640.     move.w    BC,d0
  641.     subq.w    #1,d0
  642.     mulu    #21,d0
  643.     sub.l    d0,cc
  644. #endif
  645.     movea.l    AHL,a1
  646.     movea.l    ADE,a0
  647.     move.w    BC,d0
  648.     beq.s    slddr    // slow ldir: complete core shifts (don't worry, be happy!)
  649.     clr.w    BC
  650.     sub.w    d0,HL
  651.     bcs.s    slddr1    // slow ldir: source pointer wraps
  652.     sub.w    d0,DE
  653.     bcs.s    slddr2    // slow ldir: destination pointer wraps
  654. #if rom_protection
  655.     cmp.w    DE,rom_end
  656.     bhi.s    slddr2
  657. #endif
  658. // quick lddr: move d0.w bytes (a1)- -> (a0)-
  659.     addq.l    #1,a0
  660.     addq.l    #1,a1
  661.     subq.w    #1,d0
  662. lddr1:    move.b    -(a1),-(a0)
  663.     dbf    d0,lddr1
  664.     bra    nxtirpt
  665.  
  666.  
  667.  
  668.  
  669.