home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / cpm68k / com2.lbr / COM1.SQ / COM1.S
Encoding:
Text File  |  1986-09-07  |  23.5 KB  |  961 lines

  1. *************************************************************************
  2. *                                    *
  3. *                                    *
  4. *    8080 Simulator for MC68000                    *
  5. *                                    *
  6. *    With CP/M 2.2 call support, optional tracing and        *
  7. *    Morrow HDDMA DMA buffer translating.                *
  8. *                                    *
  9. *                                    *
  10. *    Version 1.2 1/21/85 JEC                        *
  11. *        Fixed Extent bug in OPEN logic.                *
  12. *        Sped up code, sample MAC from 2:13 to 1:40.        *
  13. *        Now runs at a 1.4 MHz equivalent based on MAC sample.    *
  14. *                                    *
  15. *    Version 1.1 8/29/84 JEC                        *
  16. *        Fixed BDOS call #6 bug.                    *
  17. *                                    *
  18. *    Version 1.0 05/25/84 by Jim Cathey                *
  19. *                                    *
  20. *    This program has been written for speed wherever possible,    *
  21. *    as such tends to be large because of the separate subroutine    *
  22. *    for each and every opcode of the target processor.        *
  23. *                                    *
  24. *    On an 8MHz 68000 (Compupro) system the simulation speed is    *
  25. *    a little better than a 1MHz Z-80 when running MAC.  The time    *
  26. *    for a sample assembly was 2:13 for the simulation vs 0:35    *
  27. *    on a 4MHz Z-80, both systems used identical hard disk systems.    *
  28. *                                    *
  29. *    It is not a complete simulation, as some flag handling        *
  30. *    isn't quite right, but it is enough to run the programs        *
  31. *    I wrote it for (DDT, LU, MAC, and Morrow's FORMATMW).        *
  32. *                                    *
  33. *************************************************************************
  34.     text
  35.     page
  36. *************************************************************************
  37. *                                    *
  38. *    This file contains the startup routines, the simulator core,    *
  39. *    tracing code, and the CP/M 2.2 simulation.            *
  40. *                                    *
  41. *************************************************************************
  42.  
  43.     xdef optabl,flags,mnops
  44.     globl mloop,illegl,service
  45.  
  46. *
  47. *    Conditional assembly flags.
  48. *
  49. trace    equ 0        ; Non-zero for trace routine inclusion.
  50. trcdsk    equ 0        ; Non-zero for FCB trace routine inclusion.
  51. dmpdsk    equ 0        ; Non-zero for register dump in FCB trace.
  52. *  !! diskio is in file COM2.S !!
  53. *diskio    equ 0        ; Non-zero for special HDDMA support.
  54.  
  55.  
  56. *
  57. *    Register definitions for the simulation.
  58. *
  59. return     equ @16,r    ; JMP (return) is fast return to MLOOP.
  60. pseudopc equ @15,r    ; 8080's PC is register A5.
  61. opptr    equ @14,r    ; Pointer to opcode dispatch table.
  62. pseudosp equ @13,r    ; 8080's SP is register A3.
  63. flagptr  equ @12,r    ; Pointer to 8080's flag lookup table is A2.
  64. targbase equ @11,r    ; Pointer to 8080's address space is A1.
  65. regs     equ @11,r    ; Base pointer to 8080's registers is A1.
  66. regcon0e equ 7,r    ; Register based constant #$E (for speed).
  67. regcon01 equ 6,r    ; Register based constant #$1.
  68. regcon0f equ 5,r    ; Register based constant #$F.
  69. regconff equ 4,r    ; Register based constant #$FF.
  70. regf     equ 3,r    ; 8080's Flags
  71. rega     equ 2,r    ; 8080's Accumulator
  72.  
  73. *
  74. *    Note, only leaves D0-D1/A0 for free use by entire
  75. *    program without saving registers for temporary use.
  76. *
  77.  
  78. bdos    .opd 0,$4e42    ; BDOS 'macro'.
  79. bios    .opd 0,$4e43    ; BIOS 'macro'.
  80.  
  81.     page
  82. *************************************************************************
  83. *                                    *
  84. *    Initialization and Main Opcode dispatcher.            *
  85. *                                    *
  86. *************************************************************************
  87.  
  88. start    lea.l target,targbase    ; Start of target memory.
  89.     ifne trace        ; Optional trace code.
  90.     bsr entrads        ; Enter trace delimiting addresses
  91. *                ; if the code is desired.
  92.     endc
  93.     bsr lodfdos        ; Load up the fake FDOS in target mem.
  94.     bsr lodregs        ; Load the remaining simulation registers.
  95.     bsr loadcom        ; Load the .COM program,
  96.     tst d0            ; quit if unsuccessful.
  97.     bne optprnt
  98.     rts
  99.  
  100. optprnt    equ *
  101.     ifne trcdsk        ; If FCB tracing, print header.
  102.     lea.l fcbmsg,a0
  103.     bsr lpstr
  104.     endc
  105.  
  106.  
  107. mloop:    *            ; Execute simulation
  108. ~~mloop:
  109.     ifne trace        ; Optional trace.
  110.     tst traceflg
  111.     bne dotrace
  112.     cmpa.l tracesad,pseudopc
  113.     bne notrace
  114.     move.b #1,traceflg
  115. dotrace    bsr dump
  116.     cmpa.l traceead,pseudopc
  117.     bne notrace
  118.     move.b #0,traceflg
  119. notrace    equ *
  120.     endc
  121.  
  122.     moveq #0,d0        ; Execute appropriate simulation subroutine.
  123.     move.b (pseudopc)+,d0    ; Grab next opcode.
  124.     asl #2,d0        ; (D0 high word is still 0!)
  125.     move.l 0(opptr,d0.w),a0
  126.     jmp (a0)        ; To the subroutine.
  127.  
  128.     page
  129. *************************************************************************
  130. *                                    *
  131. *    Illegal instructions and Dumping.                *
  132. *                                    *
  133. *************************************************************************
  134.  
  135. illegl    move.l #illgmsg,d1    ; Illegal opcode, say what & where,
  136.     move.w #9,d0
  137.     bdos
  138.     lea.l -1(pseudopc),a0
  139.     move.b (a0),d1
  140.     suba.l targbase,a0
  141.     bsr pbyte
  142.     move.l #ilgmsg2,d1
  143.     move.w #9,d0
  144.     bdos
  145.     move.l a0,d1
  146.     bsr pword
  147.     move.l #ilgmsg3,d1
  148.     move.w #9,d0
  149.     bdos
  150.     move.l #dumpmsg,d1
  151.     move.w #9,d0
  152.     bdos
  153.     bsr dump        ; and spill guts.
  154.     rts            ; Quit simulation.
  155.  
  156.     page
  157. dump    movem.l d0-d1/a0,-(sp)
  158.     move.l #dmpmsg2,d1    ; Dump all registers,
  159.     move.w #9,d0        ; used for illegals and tracing.
  160.     bdos
  161.     move.b rega,d1
  162.     bsr pbyte
  163.     move.b regf,d1
  164.     bsr pbyte
  165.     bsr pspace
  166.     move.w regb(regs),d1
  167.     bsr pword
  168.     bsr pspace
  169.     move.w regd(regs),d1
  170.     bsr pword
  171.     bsr pspace
  172.     move.w regh(regs),d1
  173.     bsr pword
  174.     bsr pspace
  175.     move.l pseudosp,d1
  176.     sub.l targbase,d1
  177.     bsr pword
  178.     bsr pspace
  179.     move.l pseudosp,a0
  180.     swap d2            ; Save REGA
  181.     move.w #3,d2
  182. tosloop    move.b 1(a0),d1
  183.     ror.w #8,d1
  184.     move.b 0(a0),d1
  185.     bsr pword
  186.     bsr pspace
  187.     addq.l #2,a0
  188.     dbra d2,tosloop
  189.     swap d2
  190.     move.l pseudopc,d1
  191.     sub.l targbase,d1
  192.     bsr pword
  193.     bsr pspace
  194.     bsr pspace
  195.     move.b (pseudopc),d1
  196.     bsr pbyte
  197.     bsr pspace        ; Now show mnemonic
  198.     bsr pspace
  199.     moveq #0,d0
  200.     move.b (pseudopc),d0
  201.     asl.w #2,d0
  202.     lea.l mnops,a0
  203.     move.l (a0,d0.l),d1
  204.     move.l d1,-(sp)
  205.     inc.l d1
  206.     move #9,d0
  207.     bdos
  208.     move.l (sp)+,a0
  209.     cmp.b #" ",(a0)
  210.     beq nooprnd
  211.     cmp.b #"C",(a0)
  212.     bne notcons
  213.     move.b 1(pseudopc),d1
  214.     bsr pbyte
  215.     bra nooprnd
  216. notcons    cmp.b #"A",(a0)
  217.     bne nooprnd
  218.     move.b 2(pseudopc),d1
  219.     bsr pbyte
  220.     move.b 1(pseudopc),d1
  221.     bsr pbyte
  222. nooprnd    bsr pspace        ; In case of conout calls during trace,
  223.     bsr pspace        ; they will be visible at end of line.
  224.     bsr pspace
  225.     movem.l (sp)+,d0-d1/a0
  226.     rts
  227.  
  228.     page
  229. *************************************************************************
  230. *                                    *
  231. *    Initialization subroutines.                    *
  232. *                                    *
  233. *************************************************************************
  234.  
  235. lodfdos    lea.l fdos,a6        ; Load up the fake FDOS.
  236.     move.l targbase,pseudosp
  237.     adda.l #$10000,pseudosp
  238.     lea.l -256(pseudosp),a0
  239.     move.w #fdoslen,d0
  240. lodloop    move.b (a6)+,(a0)+
  241.     dbra d0,lodloop
  242.     lea.l -256(pseudosp),a0
  243.     move.l a0,d0
  244.     sub.l targbase,d0
  245.     move.b #$c3,0(targbase)    ; Build BIOS & BDOS jumps.
  246.     move.b #$c3,5(targbase)
  247.     move.b d0,6(targbase)
  248.     rol.w #8,d0
  249.     move.b d0,7(targbase)
  250.     rol.w #8,d0
  251.     add.w #3,d0
  252.     move.b d0,1(targbase)
  253.     rol.w #8,d0
  254.     move.b d0,2(targbase)
  255.     move.w #0,-(pseudosp)    ; Set up a return stack to exit simulation.
  256.     rts
  257.  
  258.  
  259. lodregs    lea.l optabl,opptr    ; Point base register to opcode dispatch table.
  260.     lea.l mloop,return
  261.     lea.l flags,flagptr
  262.     move.l targbase,pseudopc
  263.     adda.l #$100,pseudopc    ; Start execution at 0100H in target space.
  264.     moveq #$e,regcon0e    ; Set up quick constants.
  265.     moveq #$1,regcon01
  266.     moveq #$f,regcon0f
  267.     move.l #$ff,regconff
  268.     moveq #0,rega
  269.     moveq #0,regf
  270.     rts
  271.  
  272.     page
  273. entrads    move.l #tracemsg,d1    ; Enter trace address if necessary.
  274.     move.w #9,d0
  275.     bdos
  276.     bsr atol        ; Get trace start address.
  277.     and.l #$ffff,d1
  278.     move.l d1,a0
  279.     adda.l targbase,a0
  280.     move.l a0,tracesad
  281.     move.l #tracemg2,d1
  282.     move.w #9,d0
  283.     bdos
  284.     bsr atol        ; Get trace end address.
  285.     and.l #$ffff,d1
  286.     move.l d1,a0
  287.     adda.l targbase,a0
  288.     move.l a0,traceead
  289.     move.w #10,d1        ; CRLF to end line.
  290.     move.w #2,d0
  291.     bdos
  292.     move.w #13,d1
  293.     move.w #2,d0
  294.     bdos
  295.     rts
  296.  
  297. *
  298. *    OPEN file to be loaded, and load it into target
  299. *    space if successful.
  300. *
  301.     .globl    loadcom
  302. loadcom    link a6,#0        ; Mark stack frame.
  303.     movem.l    d2-d4/a2-a5,-(sp)
  304.     move.l 12(a6),a0    ; Get the address of the base page.
  305.     lea.l $5c(a0),a2    ; Get FCB address.
  306.     move.b #'C',9(a2)    ; mash filename to .COM
  307.     move.b #'O',10(a2)
  308.     move.b #'M',11(a2)
  309.     move.l a2,d1
  310.     move.w #15,d0
  311.     bdos            ; OPEN file.
  312.     cmpi.w #255,d0        ; ERROR?
  313.     beq openerr
  314.  
  315.     move.l pseudopc,d2    ; Start loading at $0100 in target.
  316. filelod    move.l d2,d1        ; Set DMA address.
  317.     move.w #26,d0
  318.     bdos
  319.     move.l a2,d1
  320.     move.w #20,d0        ; Read file until EOF.
  321.     bdos
  322.     tst d0
  323.     bne basepg
  324.     add.l #128,d2
  325.     bra filelod
  326.  
  327. basepg    lea.l $80(targbase),a2    ; Set up the target's base page.
  328.     move.l a2,d1        ; Start with default DMA address.
  329.     move.l a2,dmaaddr
  330.     move.w #26,d0
  331.     bdos
  332.     lea.l $38(a0),a2
  333.     lea.l $5c(targbase),a3    ; Copy host's 2nd FCB to target's 1st FCB.
  334.     move.w #15,d0
  335. fcbloop move.b (a2)+,(a3)+
  336.     dbra d0,fcbloop
  337.     clr.b    (A3)+        ; zero out fcb #2 drive
  338.     move.w    #10,D4        ; fill filename & type with blanks
  339. fcbxlp    move.b    #' ',(A3)+
  340.     dbra    D4,fcbxlp
  341.     clr.b    (A3)+        ; rest of "fcb2"
  342.     clr.b    (A3)+
  343.     clr.b    (A3)+
  344.     clr.b    (A3)+
  345.     clr.b    (A3)+        ; rec# field
  346.     clr.b    (A3)+
  347.     clr.b    (A3)+
  348.     clr.b    (A3)+
  349.     lea.l $80(a0),a2
  350.     lea.l $80(targbase),a4
  351.     lea.l $81(targbase),a3
  352.     clr d0
  353.     move.b d0,(a4)
  354.     move.b (a2)+,d0        ; Grab command tail from host's buffer.
  355. tail1    cmp.b #$20,(a2)+    ; Hack off ?.COM filename.
  356.     dbeq d0,tail1
  357.     bne loaded        ; If there's any tail left, then
  358. tail2    cmp.b #$20,(a2)+    ; remove leading whitespace.
  359.     dbne d0,tail2
  360.     beq loaded
  361.     dec.l a2
  362.     subq #2,d0
  363.     move.w    D0,D4
  364.     move.l    A2,A5        ; save ptr to head of command tail
  365. tail3    move.b (a2)+,(a3)+    ; Move the rest of the tail.
  366.     inc.b (a4)
  367.     dbra d0,tail3
  368.     move.b #0,(a3)
  369.     move.l    A5,A2        ; restore ptr to head of command tail
  370.     move.w    D4,D0        ; character count
  371.     addq    #1,D0        ; fixed
  372.     lea    $6c(targbase),A3 ; fcb2 base    
  373. tail4    cmp.b #$20,(a2)+    ; Hack off first filename
  374.     dbeq d0,tail4
  375.     bne loaded        ; If there's any tail left, then
  376. tail5    cmp.b #$20,(a2)+    ; remove leading whitespace.
  377.     dbne d0,tail5
  378.     beq loaded
  379.     dec.l a2
  380.     subq #1,d0
  381. * now parse second file name
  382.     clr.b    0(A3)        ; assume default drive
  383.     cmpi.b    #':',1(A2)    ; is there a colon?
  384.     bne    fcb2drv        ; skip if no colon
  385.     move.b    (a2)+,D4    ; get drive letter
  386.     tst.b    (a2)+        ; skip colon
  387.     subq    #2,D0        ; and count 'em
  388.     subi.b    #'@',D4        ; convert to drive letter
  389.     cmpi.b    #0,D4        ; lower bound
  390.     ble    loaded        ; skip if bogus drive
  391.     cmpi.b    #16,D4        ; upper bound
  392.     bgt    loaded        ; skip if bogus drive
  393.     move.b    D4,0(A3)    ; stash drive #
  394. fcb2drv    lea    1(A3),A5    ; file name base
  395.     moveq    #7,D2        ; #bytes in file name
  396. fcb2fn    cmpi.b    #'.',(A2)    ; is dot?
  397.     beq    fcb2t1        ; br if so
  398.     cmpi.b    #'*',(A2)    ; wild card?
  399.     beq    fcb2fq        ; yes, fill with '?'
  400.     cmpi.b    #' ',(A2)    ; is blank?
  401.     beq    loaded
  402.     move.b    (A2)+,(A5)+    ; else move byte
  403.     subq    #1,D0        ; count in byte
  404.     dbeq    D2,fcb2fn    ; count and loop
  405.     bne    loaded        ; no more characters
  406. fcb2sl    cmpi.b    #'.',(A2)    ; is dot?    
  407.     beq    fcb2t1        ; br if so
  408.     cmpi.b    #' ',(A2)    ; is space?
  409.     beq    loaded        ; if so, we are done
  410.     tst.b    (A2)+        ; skip over char
  411.     subq    #1,D0        ; and count it
  412.     bne    fcb2sl        ; loop
  413.     bra    loaded
  414. fcb2fq    move.b    #'?',(A5)+    ; stash ?
  415.     dbra    D2,fcb2fq    ; loop
  416.     tst.b    (A2)+        ; skip *
  417.     subq    #1,D0        ; and count it
  418.     bra    fcb2sl        ; and go look for end or dot    
  419. fcb2t1    tst.b    (A2)+        ; skip dot
  420.     subq    #1,D0        ; and count it
  421.     lea    09(A3),A5    ; type base
  422.     moveq    #2,D2        ; count
  423. fcb2ty    cmpi.b    #'*',(A2)    ; wild card?
  424.     beq    fcb2tq        ; go handle
  425.     cmpi.b    #' ',(A2)    ; blank?
  426.     beq    loaded
  427.     move.b    (A2)+,(A5)+    ; else move byte
  428.     subq    #1,D0
  429.     dbeq    D2,fcb2ty    ; count and loop
  430.     bra    loaded        ; done.
  431. fcb2tq    move.b    #'?',(A5)+    ; fill with '?'
  432.     dbra    D2,fcb2tq    ; loop
  433.     bra loaded
  434.  
  435. openerr    move.l #opnmsg,d1    ; Can't open file.
  436.     move.w #9,d0
  437.     bdos
  438.     clr d0
  439.  
  440. loaded    movem.l (sp)+,d2-d4/a2-a5
  441.     unlk    a6        ; Trantor.
  442.     rts
  443.  
  444.  
  445.     page
  446. *************************************************************************
  447. *                                    *
  448. *    BIOS and BDOS service request handler.                *
  449. *                                    *
  450. *************************************************************************
  451.  
  452. service    moveq #0,d0        ; Handle BIOS/BDOS service request
  453.     move.b (pseudopc)+,d0    ; of form HLT DB opcode.
  454.     bne biosfn        ; BDOS or BIOS?
  455. bdosfn    moveq #0,d1
  456.     move.b regc(regs),d0    ; Get BDOS function number.
  457.     move.w regd(regs),d1    ; Get argument.
  458.     cmp #31,d0        ; Can't do Disk Parm Hdr function
  459.     beq badbdos
  460.     cmp #27,d0        ; or ALLOC vector fn.
  461.     bne okbdos
  462. badbdos    move.l #ilgbdos,d1
  463.     move.w #9,d0
  464.     bdos
  465.     bsr dump
  466.     bra quitprg
  467.  
  468. okbdos    cmp #9,d0        ; Translate target address to real address.
  469.     blt noconv
  470.     cmp #14,d0
  471.     beq noconv
  472.     cmp #32,d0
  473.     beq noconv
  474.     cmp #37,d0
  475.     beq noconv
  476.     add.l targbase,d1
  477. noconv    cmp #26,d0        ; Save last known DMA address
  478.     bne notdma        ; (in case of OPEN processing).
  479.     move.l d1,dmaaddr
  480. notdma    move.b #0,fcbflag    ; Separate FCB type requests
  481.     cmp #15,d0        ; from the rest of the swine.
  482.     blt notfcb        ; (Assume not, at first).
  483.     cmp #24,d0
  484.     blt fcb
  485.     cmp #30,d0
  486.     beq fcb
  487.     cmp #33,d0
  488.     blt notfcb
  489.     cmp #37,d0
  490.     blt fcb
  491.     cmp #40,d0
  492.     beq fcb
  493.     bra notfcb
  494.  
  495.     page
  496. fcb    swap d2
  497.     move.w #35,d2        ; Move the FCB to host working buf,
  498.     move.l d1,a0
  499.     move.l a1,-(sp)
  500.     lea.l fcbstor,a1
  501. fcb1    move.b (a0)+,(a1)+
  502.     dbra d2,fcb1
  503.     move.l (sp)+,a1
  504.     lea.l fcbstor,a0    ; and swap the random record bytes
  505.     move.b 33(a0),d2    ; to make them match the 68000's.
  506.     move.b 35(a0),33(a0)
  507.     move.b d2,35(a0)
  508.     swap d2
  509.     move.b #1,fcbflag    ; Set flag for proper recovery.
  510.     move.l d1,-(sp)        ; (Gotta put the pig back in pen!)
  511.     move.l a0,d1
  512.     ifne trcdsk
  513.     ifne dmpdsk        ; Optional^2 Register dump.
  514.     bsr dump
  515.     endc
  516.     endc
  517.     cmp.w #15,d0        ; OPEN has a problem in that CP/M-68K
  518.     bne notopen        ; can only open the base extent, unlike
  519.     tst.b 12(a0)        ; CP/M-80.  So we have to check and do
  520.     beq notopen        ; an OPEN then SEEK (RREAD) if required.
  521.     bsr openproc
  522.     bra results
  523.  
  524. notopen:
  525. ~~notopen:
  526.     ifne trcdsk        ; Optional FCB trace.
  527.     move.l d2,-(sp)
  528.     move.b #' ',d2
  529.     bsr fcbtrc1
  530.     move.l (sp)+,d2
  531.     endc
  532.  
  533.  
  534. notfcb    cmp #6,d0        ; Not an FCB request.  Is it
  535.     bne notdcon        ; a direct console I/O function?
  536.     cmp.b #$ff,d1        ; Yes, make host's look like target's.
  537.     bne notdcon
  538.     move.w #$fe,d1
  539.     bdos
  540.     tst d0
  541.     beq results
  542.     move.w #6,d0
  543.     move.w #$FF,d1
  544.  
  545. notdcon    bdos            ; FINALLY!  Do the translated function.
  546. results    move.w d0,regh(regs)
  547.     move.b d0,rega
  548.     move.b regh(regs),regb(regs)
  549.     tst.b fcbflag        ; Do we need to restore a FCB?
  550.     beq done
  551.     ifne trcdsk
  552.     bsr fcbtrc2
  553.     endc
  554.     lea.l fcbstor,a0    ; Restore the FCB to target, in proper order.
  555.     swap d2
  556.     move.b 33(a0),d2
  557.     move.b 35(a0),33(a0)
  558.     move.b d2,35(a0)
  559.     move.l (sp)+,a0
  560.     move.l a1,-(sp)
  561.     lea.l fcbstor,a1
  562.     move.w #35,d2
  563. fcb2    move.b (a1)+,(a0)+
  564.     dbra d2,fcb2
  565.     swap d2
  566.     move.l (sp)+,a1
  567. done    move.b rega,d0
  568.     and.w regconff,d0
  569.     move.b 0(flagptr,d0.w),regf
  570.     rts
  571.  
  572.  
  573. openproc:
  574. ~~openproc:
  575.     ifne trcdsk        ; Optional FCB trace.
  576.     swap d2
  577.     move.b #' ',d2
  578.     bsr fcbtrc1
  579.     swap d2
  580.     bsr fcbtrc2a
  581.     endc
  582.  
  583.     move.b 33(a0),-(sp)    ; Save away RR fields!
  584.     move.b 34(a0),-(sp)
  585.     move.b 35(a0),-(sp)
  586.     movem.l d0-d2,-(sp)
  587.     moveq #0,d2
  588.     move.b 12(a0),d2    ; Save desired extent.
  589.     clr.b 12(a0)
  590.     bsr fcbbdos        ; Do BDOS (with opt. tracing).
  591.     tst.b d0
  592.     bmi badopen        ; No seek if not good OPEN.
  593.     asl.l #7,d2        ; Make EXTENT # into record offset.
  594.     moveq #0,d0
  595.     move.b 32(a0),d0
  596.     bclr #7,d0
  597.     add.l d2,d0        ; Add onto CR to make abs record #.
  598.     move.w d0,34(a0)    ; Put into FCB.
  599.     swap d0
  600.     move.b d0,33(a0)
  601.     move.l #junkbuf,d1    ; Set DMA addr elsewhere for Rand Seek.
  602.     move.w #26,d0
  603.     bdos
  604.     movem.l (sp)+,d0-d2
  605.     move.w #33,d0        ; Random READ (SEEK) desired extent.
  606.     bsr fcbbdos        ; Do BDOS (with opt. tracing).
  607.     clr d0            ; (OPEN) must always be successful because
  608. *                ; of the way CP/M-80 & CP/M-68K differ
  609. *                ; on OPENing non-zero extents.
  610.     movem.l d0-d1,-(sp)    ; Restore the proper DMA address.
  611.     move.w #26,d0
  612.     move.l dmaaddr,d1
  613.     bdos
  614.     movem.l (sp)+,d0-d1
  615. restore    move.b (sp)+,35(a0)    ; Restore RR fields.
  616.     move.b (sp)+,34(a0)
  617.     move.b (sp)+,33(a0)
  618.     rts
  619.  
  620. badopen movem.l (sp)+,d0-d2
  621.     bra restore
  622.  
  623.  
  624. fcbbdos:
  625. ~~fcbbdos:
  626.     ifne trcdsk        ; BDOS call with optional FCB trace.
  627.     move.l d2,-(sp)
  628.     move.b #'+',d2
  629.     bsr fcbtrc1
  630.     move.l (sp)+,d2
  631.     endc
  632.     bdos
  633.     ifne trcdsk
  634.     bsr fcbtrc2
  635.     endc
  636.     rts
  637.  
  638.  
  639. biosfn    cmp #1,d0        ; Handle Bios calls.
  640.     beq quitprg
  641.     cmp #$f,d0        ; List Status is ok.
  642.     beq gudbios
  643.     cmp #7,d0
  644.     bge badbios        ; Don't allow disk functions!
  645. gudbios    clr.w d1
  646.     move.b regc(regs),d1
  647.     movem.l d2-d7/a0-a6,-(sp)
  648.     bios
  649.     movem.l (sp)+,d2-d7/a0-a6
  650.     move.b d0,rega
  651.     rts
  652.  
  653. badbios    move.b d0,-(sp)        ; Flag illegal BIOS call
  654.     move.l #biosmsg,d1    ; and spill guts.
  655.     move.w #9,d0
  656.     bdos
  657.     move.b (sp)+,d1
  658.     bsr pbyte
  659.     move.l #biosmg2,d1
  660.     move.w #9,d0
  661.     bdos
  662.     bsr dump
  663.  
  664. quitprg    move.l (sp)+,d0        ; Trash return address and
  665.     rts            ; quit simulation.
  666.  
  667.     page
  668. *************************************************************************
  669. *                                    *
  670. *    FCB Tracing support routines.                    *
  671. *                                    *
  672. *************************************************************************
  673.  
  674.     ifne trcdsk
  675. fcbtrc1    movem.l d0-d2/a0,-(sp)    ; Dump to printer each FCB usage
  676.     move.b #9,d1        ; in format FN #, Disk, Name (ASCII)
  677.     bsr lpchar        ; and the rest, all in hex but the
  678.     move.w d0,d1        ; name field.  Print the returned
  679.     bsr lpbyte        ; value after the FCB.
  680.     move.b d2,d1        ; Char in D2 is printed after FN #.
  681.     bsr lpchar
  682.     bsr lpspace
  683.     bsr lpspace
  684.     move.b (a0)+,d1
  685.     bsr lpbyte
  686.     bsr lpspace
  687.     move.w #10,d2
  688. fcbtr1    move.b (a0)+,d1        ; Print Name field...
  689.     bsr lpchar
  690.     dbra d2,fcbtr1
  691.     bsr lpspace
  692.     move.w #3,d2
  693. fcbtr2    move.b (a0)+,d1        ; Ex .. Rc
  694.     bsr lpbyte
  695.     bsr lpspace
  696.     dbra d2,fcbtr2
  697.     bsr lpspace
  698.     bsr lpspace
  699.     lea.l 16(a0),a0        ; Skip d0..dn field.
  700.     move.w #3,d2
  701. fcbtr3    move.b (a0)+,d1        ; CR .. R2
  702.     bsr lpbyte
  703.     bsr lpspace
  704.     dbra d2,fcbtr3
  705.     bsr lpspace
  706.     bsr lpspace
  707.     move.l dmaaddr,d1
  708.     sub.l targbase,d1
  709.     bsr lpword
  710.     bsr lpspace
  711.     movem.l (sp)+,d0-d2/a0
  712.     rts
  713.  
  714.     page
  715. fcbtrc2 movem.l d0-d1,-(sp)    ; Line termination of FCB trace.
  716.     bsr lpspace
  717.     bsr lpspace
  718.     move.b d0,d1
  719.     bsr lpbyte
  720. fcbtr21    move.b #10,d1
  721.     bsr lpchar
  722.     move.b #13,d1
  723.     bsr lpchar
  724.     movem.l (sp)+,d0-d1
  725.     rts
  726.  
  727. fcbtrc2a:
  728.     movem.l d0-d1,-(sp)    ; Line termination if no result
  729.     bra fcbtr21        ; is to be presented.
  730.     endc
  731.  
  732.     page
  733. *************************************************************************
  734. *                                    *
  735. *    Misc. service routines.                        *
  736. *    (Inelegant, but rarely used so they stand as is).        *
  737. *                                    *
  738. *************************************************************************
  739.  
  740.  
  741. pbyte    move.l #$20018,d0    ; 2 nybbles, 24 bit shift first.
  742.     bra pdigits
  743. pword    move.l #$40010,d0    ; 4 nybbles, 16 bit shift first.
  744.     bra pdigits
  745. paddr    move.l #$60008,d0    ; 6 nybbles, 8 bit shift first.
  746.     bra pdigits
  747. plong    move.l #$80000,d0    ; 8 nybbles, no shift first.
  748. pdigits    rol.l d0,d1        ; Do shift.
  749.     bra pdigent
  750. pdiglop    swap d0            ; Save nybble count.
  751.     rol.l #4,d1        ; Print variable in d1.
  752.     bsr ntoa
  753. pdigent    swap d0            ; Get nybble count.
  754.     dbra d0,pdiglop
  755.     rts
  756.  
  757. ntoa    movem.l d0-d1,-(sp)    ; Nybble in d1 to ASCII, then output.
  758.     and #$f,d1
  759.     cmp #$a,d1
  760.     blt ntoa2
  761.     add.b #'A'-'9'-1,d1
  762. ntoa2    add.b #'0',d1
  763.     move.w #2,d0
  764.     bdos 
  765.     movem.l (sp)+,d0-d1
  766.     rts
  767.  
  768. pspace    move.w #32,d1        ; Print a space.
  769.     move.w #2,d0
  770.     bdos
  771.     rts
  772.  
  773.     page
  774. *
  775. *    Line Printer versions of above
  776. *
  777.  
  778. lpbyte    move.l #$20018,d0    ; 2 nybbles, 24 bit shift first.
  779.     bra lpdigts
  780. lpword    move.l #$40010,d0    ; 4 nybbles, 16 bit shift first.
  781.     bra lpdigts
  782. lpaddr    move.l #$60008,d0    ; 6 nybbles, 8 bit shift first.
  783.     bra lpdigts
  784. lplong    move.l #$80000,d0    ; 8 nybbles, no shift first.
  785. lpdigts    rol.l d0,d1        ; Do shift.
  786.     bra lpdgent
  787. lpdiglp    swap d0            ; Save nybble count.
  788.     rol.l #4,d1        ; Print variable in d1.
  789.     bsr lntoa
  790. lpdgent    swap d0            ; Get nybble count.
  791.     dbra d0,lpdiglp
  792.     rts
  793.  
  794. lntoa    movem.l d0-d1,-(sp)    ; Nybble in d1 to ASCII, then output.
  795.     and #$f,d1
  796.     cmp #$a,d1
  797.     blt lntoa2
  798.     add.b #'A'-'9'-1,d1
  799. lntoa2    add.b #'0',d1
  800. lntoa3    move.w #5,d0
  801.     bdos 
  802.     movem.l (sp)+,d0-d1
  803.     rts
  804.  
  805. lpchar    movem.l d0-d1,-(sp)    ; Print a character.
  806.     bra lntoa3
  807.  
  808. lpspace    movem.l d0-d1,-(sp)    ; Print space.
  809.     move.w #32,d1
  810.     bra lntoa3
  811.  
  812.     page
  813. *
  814. *    Remaining misc. service routines.
  815. *
  816.  
  817. lpstr    movem.l d0-d1,-(sp)    ; Print a null-terminated string.
  818. lpstr1    move.b (a0)+,d1
  819.     beq lpstr2
  820.     bsr lpchar
  821.     bra lpstr1
  822. lpstr2    movem.l (sp)+,d0-d1
  823.     rts
  824.  
  825.  
  826. konin    move.w #1,d0    ; Console input for 'atol'.
  827.     bdos
  828.     rts
  829.  
  830.  
  831. atol    moveq #0,d1    ; ASCII to long, stops on invalid hex char.
  832.     clr d2        ; Returns long in d1, terminator char in d0,
  833. atol1    bsr konin    ; d2=1 if any chars entered before terminator.
  834.     cmp.b #$40,d0
  835.     blo atol2
  836.     and #$5F,d0    ; Mask to upper case.
  837. atol2    cmpi.b #'0',d0    ; Check range (0..9,A..F).
  838.     blo atolend
  839.     cmpi.b #'F',d0
  840.     bhi atolend
  841.     cmpi.b #'9',d0
  842.     bls atol3
  843.     cmpi.b #'A',d0
  844.     bhs atol3
  845.     bra atolend
  846. atol3    moveq #1,d2    ; Valid characters entered, flag it.
  847.     sub.b #'0',d0
  848.     cmp.b #$9,d0
  849.     bls atol4
  850.     sub.b #'A'-'9'-1,d0
  851. atol4    ext d0        ; To long.
  852.     ext.l d0
  853.     asl.l #4,d1    ; Tack it onto D1.
  854.     add.l d0,d1
  855.     bra atol1
  856. atolend    rts
  857.  
  858.     page
  859.     data
  860. *************************************************************************
  861. *                                    *
  862. *    Target processor's data registers.                *
  863. *    Fake FDOS.                            *
  864. *                                    *
  865. *************************************************************************
  866.  
  867.     even
  868. regop3    equ -9        ; Operand 1 for DAA storage.
  869. regb    equ -8        ; Offsets from register base pointer for
  870. regc    equ -7        ; 8080's pseudo-registers.
  871. regd    equ -6        ; A & F are in Data Registers.
  872. rege    equ -5        ; Pseudo-PC is kept in an Address Register.
  873. regh    equ -4
  874. regl    equ -3
  875. regop1    equ -2        ; Operand 1 for DAA storage.
  876. regop2    equ -1        ;    "    2  "   "     "
  877.  
  878. fcbstor ds.b 36        ; Host works FCB's out of here.
  879. fcbflag    ds.b 1        ; Flag says we used the FCB buffer.
  880.  
  881.     even
  882. tracesad ds.l 1        ; Trace start address.
  883. traceead ds.l 1        ; Trace end address.
  884. traceflg ds.w 1        ; Tracing enabled flag.
  885.  
  886. dmaaddr    ds.l 1        ; DMA address storage.
  887.  
  888.     page
  889. fdos    dc.b $76,0,$C9    ; Fake BDOS for target system.
  890. *            ; BIOS Jump Table
  891.     dc.b $C3,$33,$FF    ; Wboot
  892.     dc.b $C3,$36,$FF    ; Const
  893.     dc.b $C3,$39,$FF    ; Conin
  894.     dc.b $C3,$3C,$FF    ; Conout
  895.     dc.b $C3,$3F,$FF    ; List
  896.     dc.b $C3,$42,$FF    ; Punch
  897.     dc.b $C3,$45,$FF    ; Reader
  898.     dc.b $C3,$48,$FF    ; Home
  899.     dc.b $C3,$4B,$FF    ; Seldsk
  900.     dc.b $C3,$4E,$FF    ; Settrk
  901.     dc.b $C3,$51,$FF    ; Setsec
  902.     dc.b $C3,$54,$FF    ; Setdma
  903.     dc.b $C3,$57,$FF    ; Read
  904.     dc.b $C3,$5A,$FF    ; Write
  905.     dc.b $C3,$5D,$FF    ; Listst
  906.     dc.b $C3,$60,$FF    ; Sectran
  907.  
  908.     dc.b $76,1,$C9    ; Fake BIOS for target system
  909.     dc.b $76,2,$C9        ; Const
  910.     dc.b $76,3,$C9        ; Conin
  911.     dc.b $76,4,$C9        ; Conout
  912.     dc.b $76,5,$C9        ; List
  913.     dc.b $76,6,$C9        ; Punch
  914.     dc.b $76,7,$C9        ; Reader
  915.     dc.b $76,8,$C9        ; Home *
  916.     dc.b $76,9,$C9        ; Seldsk *
  917.     dc.b $76,10,$C9        ; Settrk *
  918.     dc.b $76,11,$C9        ; Setsec *
  919.     dc.b $76,12,$C9        ; Setdma *
  920.     dc.b $76,13,$C9        ; Read *
  921.     dc.b $76,14,$C9        ; Write *
  922.     dc.b $76,15,$C9        ; Listst
  923.     dc.b $76,16,$C9        ; Sectran *
  924.  
  925. fdoslen    equ *-fdos
  926.  
  927.     page
  928. *************************************************************************
  929. *                                    *
  930. *    Messages.                            *
  931. *                                    *
  932. *************************************************************************
  933.  
  934. illgmsg    dc.b $d,$a,'Illegal instruction $'
  935. ilgmsg2 dc.b ' at $'
  936. ilgmsg3 dc.b '.$'
  937. dumpmsg    dc.b $d,$a,'Register contents:$'
  938. dmpmsg2    dc.b $d,$a
  939.     dc.b '-AF- -BC- -DE- -HL- -SP- -S0- -S1- -S2- -S3- -PC- -op-',$d,$a,'$'
  940. biosmsg dc.b $d,$a,'Illegal BIOS call $'
  941. biosmg2 dc.b '.$'
  942. tracemsg dc.b 13,10,'Start trace at >$'
  943. tracemg2 dc.b 13,10,'End trace at >$'
  944. opnmsg    dc.b 'Cannot open .COM file.$'
  945. ilgbdos dc.b 'Unsupported BDOS call.$'
  946. fcbmsg    dc.b 9,'Fn#  Dr    NAME     EX S1 S2 RC   CR R0 R1 R2   Addr  Rslt',10,13
  947.     dc.b 9,'----------------------------------------------------------',10,13,0
  948.     page
  949.     bss
  950. *************************************************************************
  951. *                                    *
  952. *    Target processor's address space.                *
  953. *                                    *
  954. *************************************************************************
  955.  
  956.     even
  957. registers ds.b 10        ; Actual storage for 8080's other registers.
  958. target    ds.b $10000        ; 8080's universe.
  959. junkbuf    ds.b $80        ; For BDOS' OPEN faking (RREAD buffer).
  960.     .end
  961.