home *** CD-ROM | disk | FTP | other *** search
/ The Don Maslin Archive / maslin_archive.zip / AARDVARK_Tape_Backups / maslin_c_d_3oct95 / ddrive / hold / cpm22.lbr / cpm3.s < prev    next >
Text File  |  1992-05-18  |  7KB  |  271 lines

  1. *************************************************************************
  2. *                                    *
  3. *    This file contains the special Z-80 simulation routines and    *
  4. *    the Morrow HDC/DMA support routines.                *
  5. *                                    *
  6. *************************************************************************
  7.  
  8.     globl preED,outspec
  9.     xdef mloop,illegl
  10.  
  11. return     equ @16,r    ; JMP (return) is fast return to MLOOP.
  12. pseudopc equ @15,r    ; 8080's PC is register A5.
  13. opptr    equ @14,r    ; Pointer to opcode dispatch table.
  14. pseudosp equ @13,r    ; 8080's SP is register A3.
  15. flagptr  equ @12,r    ; Pointer to 8080's flag lookup table is A2.
  16. targbase equ @11,r    ; Pointer to 8080's address space is A1.
  17. regs     equ @11,r    ; Base pointer to 8080's registers is A1.
  18.  
  19. regcon0e equ 7,r    ; Register based constant #$E (for speed).
  20. regcon01 equ 6,r    ; Register based constant #$1.
  21. regcon0f equ 5,r    ; Register based constant #$F.
  22. regcondd equ 4,r    ; Register based constant #$FF.
  23. regf     equ 3,r    ; 8080's Flags
  24. rega     equ 2,r    ; 8080's Accumulator
  25.  
  26. regb    equ -8        ; Offsets from register base pointer for
  27. regc    equ -7        ; 8080's pseudo-registers.
  28. regd    equ -6        ; A & F are in Data Registers.
  29. rege    equ -5        ; Pseudo-PC is kept in an Address Register.
  30. regh    equ -4
  31. regl    equ -3
  32. regop1    equ -2        ; Operand 1 for DAA storage
  33. regop2    equ -1        ;    "    2  "   "     "
  34.  
  35.  
  36.     data
  37.     page
  38. *************************************************************************
  39. *                                    *
  40. *    Opcode dispatch table.  One longword entry per opcode of the     *
  41. *    target (Z-80) processor, including illegals.            *
  42. *                                    *
  43. *************************************************************************
  44. *                                    *
  45. *    Only a few of the most popular instructions are simulated.    *
  46. *    Support for the Z-80 Block move instructions is provided    *
  47. *    as the flags for this simulation resemble those of the Z-80    *
  48. *    rather than the 8080.  Certain packages (notably BDS-C) check    *
  49. *    the flags and mistakenly assume a Z-80, then use LDIR/LDDR.    *
  50. *    Therefore, minimal Z-80 support is provided for these        *
  51. *    instructions.  By no means is this a complete simulation    *
  52. *    of the Z-80.                            *
  53. *                                    *
  54. *************************************************************************
  55.  
  56.     even
  57. EDoptab    dc.l 0,0,0,0,0,0,0,0        ; ED00
  58.     dc.l 0,0,0,0,0,0,0,0
  59.     dc.l 0,0,0,0,0,0,0,0        ; ED10
  60.     dc.l 0,0,0,0,0,0,0,0
  61.     dc.l 0,0,0,0,0,0,0,0        ; ED20
  62.     dc.l 0,0,0,0,0,0,0,0
  63.     dc.l 0,0,0,0,0,0,0,0        ; ED30
  64.     dc.l 0,0,0,0,0,0,0,0
  65.     dc.l 0,0,0,0,0,0,0,0        ; ED40
  66.     dc.l 0,0,0,0,0,0,0,0
  67.     dc.l 0,0,0,0,0,0,0,0        ; ED50
  68.     dc.l 0,0,0,0,0,0,0,0
  69.     dc.l 0,0,0,0,0,0,0,0        ; ED60
  70.     dc.l 0,0,0,0,0,0,0,0
  71.     dc.l 0,0,0,0,0,0,0,0        ; ED70
  72.     dc.l 0,0,0,0,0,0,0,0
  73.     dc.l 0,0,0,0,0,0,0,0        ; ED80
  74.     dc.l 0,0,0,0,0,0,0,0
  75.     dc.l 0,0,0,0,0,0,0,0        ; ED90
  76.     dc.l 0,0,0,0,0,0,0,0
  77.     dc.l 0,0,0,0,0,0,0,0        ; EDA0
  78.     dc.l 0,0,0,0,0,0,0,0
  79.     dc.l ldir,cpir,0,0,0,0,0,0    ; EDB0
  80.     dc.l lddr,0,0,0,0,0,0,0
  81.     dc.l 0,0,0,0,0,0,0,0        ; EDC0
  82.     dc.l 0,0,0,0,0,0,0,0
  83.     dc.l 0,0,0,0,0,0,0,0        ; EDD0
  84.     dc.l 0,0,0,0,0,0,0,0
  85.     dc.l 0,0,0,0,0,0,0,0        ; EDE0
  86.     dc.l 0,0,0,0,0,0,0,0
  87.     dc.l 0,0,0,0,0,0,0,0        ; EDF0
  88.     dc.l 0,0,0,0,0,0,0,0
  89.  
  90.     page
  91.     text
  92. preED    moveq #0,d1            ; Zero-fill high bits.
  93.     move.b (pseudopc)+,d1        ; Grab next opcode.
  94.     asl #2,d1
  95.     lea.l EDoptab,a0
  96.     move.l 0(a0,d1.w),-(sp)        ; Do the operation.
  97.     beq illgED
  98.     rts
  99.  
  100. illgED    move.l (sp)+,d1            ; Trash the address,
  101.     dec.l pseudopc            ; fix PPC for ILLEGAL.
  102.     bra illegl
  103.  
  104.     page
  105. *************************************************************************
  106. *                                    *
  107. *    Z-80 opcode simulation routines.                *
  108. *                                    *
  109. *************************************************************************
  110.  
  111.  
  112. ldir    move.l d2,-(sp)
  113.     move.w regb(regs),d0        ; Grab count,
  114.     dec.w d0            ; adjust for DBRA later.
  115.     moveq #0,d1
  116.     moveq #0,d2
  117.     move.w regh(regs),d1        ; Grab source.
  118.     move.w regd(regs),d2        ; Grab dest.
  119.     move.l a5,-(sp)            ; Need an address reg.
  120.     lea.l 0(targbase,d2.l),a5
  121.     lea.l 0(targbase,d1.l),a0
  122. ldirlop    move.b (a0)+,(a5)+
  123.     inc.w d1
  124.     inc.w d2
  125.     dbra d0,ldirlop
  126.     move.l (sp)+,a5
  127.     move.w d1,regh(regs)        ; Restore result registers.
  128.     move.w d2,regd(regs)
  129.     move.w #0,regb(regs)
  130.     moveq #0,regf
  131.     move.l (sp)+,d2
  132.     jmp (return)
  133.  
  134. lddr    move.l d2,-(sp)
  135.     move.w regb(regs),d0        ; Grab count,
  136.     dec.w d0            ; adjust for DBRA later.
  137.     moveq #0,d1
  138.     moveq #0,d2
  139.     move.w regh(regs),d1        ; Grab source.
  140.     move.w regd(regs),d2        ; Grab dest.
  141.     move.l a5,-(sp)            ; Need an address reg.
  142.     lea.l 1(targbase,d2.l),a5
  143.     lea.l 1(targbase,d1.l),a0
  144. lddrlop    move.b -(a0),-(a5)
  145.     dec.w d1
  146.     dec.w d2
  147.     dbra d0,lddrlop
  148.     move.l (sp)+,a5
  149.     move.w d1,regh(regs)        ; Restore result registers.
  150.     move.w d2,regd(regs)
  151.     move.w #0,regb(regs)
  152.     moveq #0,regf
  153.     move.l (sp)+,d2
  154.     jmp (return)
  155.  
  156.     page
  157. cpir    move.w regb(regs),d0        ; Grab count,
  158.     dec.w d0            ; adjust for DBRA later.
  159.     moveq #0,d1
  160.     move.w regh(regs),d1        ; Grab source.
  161.     lea.l 0(targbase,d1.l),a0
  162. cpirlop    inc.w d1
  163.     cmp.b (a0)+,rega
  164.     dbeq d0,cpirlop
  165.     seq regf
  166.     move.w d1,regh(regs)        ; Restore result registers.
  167.     inc.w d0
  168.     move.w d0,regb(regs)
  169.     tst.b regf
  170.     bne cpir1
  171.     moveq #0,regf            ; Not found.
  172.     jmp (return)
  173. cpir1    tst d0
  174.     beq cpir2
  175.     moveq #$44,regf            ; Found, in the string.
  176.     jmp (return)
  177. cpir2    moveq #$40,regf            ; Found, but at last place.
  178.     jmp (return)
  179.  
  180.     page
  181. *************************************************************************
  182. *                                    *
  183. *    Output instruction simulator for Morrow HDDMA            *
  184. *                                    *
  185. *************************************************************************
  186.  
  187.  
  188. outspec    move.l d3,-(sp)
  189.     cmp.b #$55,d0
  190.     beq hdstart            ; Start command?  Do it,
  191.     move.l #hdbuf,d1        ; else build first link to host buffer
  192.     move.l #$50,a0            ; if it's a HDRESET command.
  193.     move.b d1,(a0)+
  194.     ror.l #8,d1
  195.     move.b d1,(a0)+
  196.     ror.l #8,d1
  197.     move.b d1,(a0)+
  198.  
  199.     move.l #$ff0000,a0        ; Do the output to HDDMA.
  200.     adda.l d0,a0
  201.     move.b rega,(a0)
  202.     move.l (sp)+,d3
  203.     jmp (return)
  204.  
  205. hdstart    move.l dmalink,a0        ; Move target buffer to host buffer, do
  206.     adda.l targbase,a0        ; all appropriate patching of addresses.
  207.     moveq #0,d1
  208.     move.b (a0)+,d1            ; Get link address.
  209.     ror.l #8,d1
  210.     move.b (a0)+,d1
  211.     ror.l #8,d1
  212.     move.b (a0)+,d1
  213.     rol.l #8,d1
  214.     rol.l #8,d1
  215.     move.l d1,a0
  216.     adda.l targbase,a0
  217.     move.l a6,-(sp)
  218.     lea.l hdbuf,a6
  219.     move.w #3,d1
  220. hdloop    move.b (a0)+,(a6)+
  221.     dbra d1,hdloop
  222.     moveq #0,d3            ; Fix DMA address to -> target area.
  223.     move.b (a0)+,d3
  224.     ror.l #8,d3
  225.     move.b (a0)+,d3
  226.     ror.l #8,d3
  227.     move.b (a0)+,d3
  228.     rol.l #8,d3
  229.     rol.l #8,d3
  230.     add.l targbase,d3
  231.     move.b d3,(a6)+
  232.     ror.l #8,d3
  233.     move.b d3,(a6)+
  234.     ror.l #8,d3
  235.     move.b d3,(a6)+
  236.     move.w #5,d1            ; Move rest of command buffer.
  237. hdloop2    move.b (a0)+,(a6)+
  238.     dbra d1,hdloop2
  239.  
  240.     move.l #hdbuf,d1
  241.     move.b d1,(a6)+            ; Point host buffer to self.
  242.     ror.l #8,d1
  243.     move.b d1,(a6)+
  244.     ror.l #8,d1
  245.     move.b d1,(a6)+
  246.     move.l (sp)+,a6
  247.     move.l a0,-(sp)            ; Save STATUS address for return val.
  248.     suba.l targbase,a0
  249.     move.l a0,dmalink        ; Stash new target link address.
  250.     
  251.     move.l #$ff0000,a0        ; Do the output to HDDMA.
  252.     adda.l d0,a0
  253.     move.b rega,(a0)
  254.  
  255.     move.l #hdbuf+12,a0        ; Wait for completion
  256. hdloop3    tst.b (a0)
  257.     beq hdloop3            ; Fragile, but what do you want for $1.00?
  258.     move.b (a0),d1
  259.     move.l (sp)+,a0            ; Grab the STATUS address in target space.
  260.     move.b d1,-(a0)            ; And stash status for it.
  261.     move.l (sp)+,d3
  262.     jmp (return)            ; Return to simulation.
  263.  
  264.     data
  265.     even
  266.  
  267. dmalink    dc.l $50        ; Storage for current HDDMA command buffer.
  268. hdbuf    ds.b 16
  269.  
  270.     end
  271.