home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / ddjmag / ddj8601.zip / CTAHEY.JAN < prev    next >
Text File  |  1986-01-31  |  22KB  |  884 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. loadcom    link a6,#0        ; Mark stack frame.
  302.     movem.l    d2-d3/a2-a4,-(sp)
  303.     move.l 12(a6),a0    ; Get the address of the base page.
  304.     lea.l $5c(a0),a2    ; Get FCB address.
  305.     move.b #'C',9(a2)    ; mash filename to .COM
  306.     move.b #'O',10(a2)
  307.     move.b #'M',11(a2)
  308.     move.l a2,d1
  309.     move.w #15,d0
  310.     bdos            ; OPEN file.
  311.     cmpi.w #255,d0        ; ERROR?
  312.     beq openerr
  313.  
  314.     move.l pseudopc,d2    ; Start loading at $0100 in target.
  315. filelod    move.l d2,d1        ; Set DMA address.
  316.     move.w #26,d0
  317.     bdos
  318.     move.l a2,d1
  319.     move.w #20,d0        ; Read file until EOF.
  320.     bdos
  321.     tst d0
  322.     bne basepg
  323.     add.l #128,d2
  324.     bra filelod
  325.  
  326. basepg    lea.l $80(targbase),a2    ; Set up the target's base page.
  327.     move.l a2,d1        ; Start with default DMA address.
  328.     move.l a2,dmaaddr
  329.     move.w #26,d0
  330.     bdos
  331.     lea.l $38(a0),a2
  332.     lea.l $5c(targbase),a3    ; Copy host's 2nd FCB to target's 1st FCB.
  333.     move.w #36,d0
  334. fcbloop move.b (a2)+,(a3)+
  335.     dbra d0,fcbloop
  336.     lea.l $80(a0),a2
  337.     lea.l $80(targbase),a4
  338.     lea.l $81(targbase),a3
  339.     clr d0
  340.     move.b d0,(a4)
  341.     move.b (a2)+,d0        ; Grab command tail from host's buffer.
  342. tail1    cmp.b #$20,(a2)+    ; Hack off ?.COM filename.
  343.     dbeq d0,tail1
  344.     bne loaded        ; If there's any tail left, then
  345. tail2    cmp.b #$20,(a2)+    ; remove leading whitespace.
  346.     dbne d0,tail2
  347.     beq loaded
  348.     dec.l a2
  349.     subq #2,d0
  350. tail3    move.b (a2)+,(a3)+    ; Move the rest of the tail.
  351.     inc.b (a4)
  352.     dbra d0,tail3
  353.     move.b #0,(a3)
  354.     bra loaded
  355.  
  356. openerr    move.l #opnmsg,d1    ; Can't open file.
  357.     move.w #9,d0
  358.     bdos
  359.     clr d0
  360.  
  361. loaded    movem.l (sp)+,d2-d3/a2-a4
  362.     unlk    a6        ; Trantor.
  363.     rts
  364.  
  365.  
  366.     page
  367. *************************************************************************
  368. *                                    *
  369. *    BIOS and BDOS service request handler.                *
  370. *                                    *
  371. *************************************************************************
  372.  
  373. service    moveq #0,d0        ; Handle BIOS/BDOS service request
  374.     move.b (pseudopc)+,d0    ; of form HLT DB opcode.
  375.     bne biosfn        ; BDOS or BIOS?
  376. bdosfn    moveq #0,d1
  377.     move.b regc(regs),d0    ; Get BDOS function number.
  378.     move.w regd(regs),d1    ; Get argument.
  379.     cmp #31,d0        ; Can't do Disk Parm Hdr function
  380.     beq badbdos
  381.     cmp #27,d0        ; or ALLOC vector fn.
  382.     bne okbdos
  383. badbdos    move.l #ilgbdos,d1
  384.     move.w #9,d0
  385.     bdos
  386.     bsr dump
  387.     bra quitprg
  388.  
  389. okbdos    cmp #9,d0        ; Translate target address to real address.
  390.     blt noconv
  391.     cmp #14,d0
  392.     beq noconv
  393.     cmp #32,d0
  394.     beq noconv
  395.     cmp #37,d0
  396.     beq noconv
  397.     add.l targbase,d1
  398. noconv    cmp #26,d0        ; Save last known DMA address
  399.     bne notdma        ; (in case of OPEN processing).
  400.     move.l d1,dmaaddr
  401. notdma    move.b #0,fcbflag    ; Separate FCB type requests
  402.     cmp #15,d0        ; from the rest of the swine.
  403.     blt notfcb        ; (Assume not, at first).
  404.     cmp #24,d0
  405.     blt fcb
  406.     cmp #30,d0
  407.     beq fcb
  408.     cmp #33,d0
  409.     blt notfcb
  410.     cmp #37,d0
  411.     blt fcb
  412.     cmp #40,d0
  413.     beq fcb
  414.     bra notfcb
  415.  
  416.     page
  417. fcb    swap d2
  418.     move.w #35,d2        ; Move the FCB to host working buf,
  419.     move.l d1,a0
  420.     move.l a1,-(sp)
  421.     lea.l fcbstor,a1
  422. fcb1    move.b (a0)+,(a1)+
  423.     dbra d2,fcb1
  424.     move.l (sp)+,a1
  425.     lea.l fcbstor,a0    ; and swap the random record bytes
  426.     move.b 33(a0),d2    ; to make them match the 68000's.
  427.     move.b 35(a0),33(a0)
  428.     move.b d2,35(a0)
  429.     swap d2
  430.     move.b #1,fcbflag    ; Set flag for proper recovery.
  431.     move.l d1,-(sp)        ; (Gotta put the pig back in pen!)
  432.     move.l a0,d1
  433.     ifne trcdsk
  434.     ifne dmpdsk        ; Optional^2 Register dump.
  435.     bsr dump
  436.     endc
  437.     endc
  438.     cmp.w #15,d0        ; OPEN has a problem in that CP/M-68K
  439.     bne notopen        ; can only open the base extent, unlike
  440.     tst.b 12(a0)        ; CP/M-80.  So we have to check and do
  441.     beq notopen        ; an OPEN then SEEK (RREAD) if required.
  442.     bsr openproc
  443.     bra results
  444.  
  445. notopen:
  446. ~~notopen:
  447.     ifne trcdsk        ; Optional FCB trace.
  448.     move.l d2,-(sp)
  449.     move.b #' ',d2
  450.     bsr fcbtrc1
  451.     move.l (sp)+,d2
  452.     endc
  453.  
  454.  
  455. notfcb    cmp #6,d0        ; Not an FCB request.  Is it
  456.     bne notdcon        ; a direct console I/O function?
  457.     cmp.b #$ff,d1        ; Yes, make host's look like target's.
  458.     bne notdcon
  459.     move.w #$fe,d1
  460.     bdos
  461.     tst d0
  462.     beq results
  463.     move.w #6,d0
  464.     move.w #$FF,d1
  465.  
  466. notdcon    bdos            ; FINALLY!  Do the translated function.
  467. results    move.w d0,regh(regs)
  468.     move.b d0,rega
  469.     move.b regh(regs),regb(regs)
  470.     tst.b fcbflag        ; Do we need to restore a FCB?
  471.     beq done
  472.     ifne trcdsk
  473.     bsr fcbtrc2
  474.     endc
  475.     lea.l fcbstor,a0    ; Restore the FCB to target, in proper order.
  476.     swap d2
  477.     move.b 33(a0),d2
  478.     move.b 35(a0),33(a0)
  479.     move.b d2,35(a0)
  480.     move.l (sp)+,a0
  481.     move.l a1,-(sp)
  482.     lea.l fcbstor,a1
  483.     move.w #35,d2
  484. fcb2    move.b (a1)+,(a0)+
  485.     dbra d2,fcb2
  486.     swap d2
  487.     move.l (sp)+,a1
  488. done    move.b rega,d0
  489.     and.w regconff,d0
  490.     move.b 0(flagptr,d0.w),regf
  491.     rts
  492.  
  493.  
  494. openproc:
  495. ~~openproc:
  496.     ifne trcdsk        ; Optional FCB trace.
  497.     swap d2
  498.     move.b #' ',d2
  499.     bsr fcbtrc1
  500.     swap d2
  501.     bsr fcbtrc2a
  502.     endc
  503.  
  504.     move.b 33(a0),-(sp)    ; Save away RR fields!
  505.     move.b 34(a0),-(sp)
  506.     move.b 35(a0),-(sp)
  507.     movem.l d0-d2,-(sp)
  508.     moveq #0,d2
  509.     move.b 12(a0),d2    ; Save desired extent.
  510.     clr.b 12(a0)
  511.     bsr fcbbdos        ; Do BDOS (with opt. tracing).
  512.     tst.b d0
  513.     bmi badopen        ; No seek if not good OPEN.
  514.     asl.l #7,d2        ; Make EXTENT # into record offset.
  515.     moveq #0,d0
  516.     move.b 32(a0),d0
  517.     bclr #7,d0
  518.     add.l d2,d0        ; Add onto CR to make abs record #.
  519.     move.w d0,34(a0)    ; Put into FCB.
  520.     swap d0
  521.     move.b d0,33(a0)
  522.     move.l #junkbuf,d1    ; Set DMA addr elsewhere for Rand Seek.
  523.     move.w #26,d0
  524.     bdos
  525.     movem.l (sp)+,d0-d2
  526.     move.w #33,d0        ; Random READ (SEEK) desired extent.
  527.     bsr fcbbdos        ; Do BDOS (with opt. tracing).
  528.     clr d0            ; (OPEN) must always be successful because
  529. *                ; of the way CP/M-80 & CP/M-68K differ
  530. *                ; on OPENing non-zero extents.
  531.     movem.l d0-d1,-(sp)    ; Restore the proper DMA address.
  532.     move.w #26,d0
  533.     move.l dmaaddr,d1
  534.     bdos
  535.     movem.l (sp)+,d0-d1
  536. restore    move.b (sp)+,35(a0)    ; Restore RR fields.
  537.     move.b (sp)+,34(a0)
  538.     move.b (sp)+,33(a0)
  539.     rts
  540.  
  541. badopen movem.l (sp)+,d0-d2
  542.     bra restore
  543.  
  544.  
  545. fcbbdos:
  546. ~~fcbbdos:
  547.     ifne trcdsk        ; BDOS call with optional FCB trace.
  548.     move.l d2,-(sp)
  549.     move.b #'+',d2
  550.     bsr fcbtrc1
  551.     move.l (sp)+,d2
  552.     endc
  553.     bdos
  554.     ifne trcdsk
  555.     bsr fcbtrc2
  556.     endc
  557.     rts
  558.  
  559.  
  560. biosfn    cmp #1,d0        ; Handle Bios calls.
  561.     beq quitprg
  562.     cmp #$f,d0        ; List Status is ok.
  563.     beq gudbios
  564.     cmp #7,d0
  565.     bge badbios        ; Don't allow disk functions!
  566. gudbios    clr.w d1
  567.     move.b regc(regs),d1
  568.     movem.l d2-d7/a0-a6,-(sp)
  569.     bios
  570.     movem.l (sp)+,d2-d7/a0-a6
  571.     move.b d0,rega
  572.     rts
  573.  
  574. badbios    move.b d0,-(sp)        ; Flag illegal BIOS call
  575.     move.l #biosmsg,d1    ; and spill guts.
  576.     move.w #9,d0
  577.     bdos
  578.     move.b (sp)+,d1
  579.     bsr pbyte
  580.     move.l #biosmg2,d1
  581.     move.w #9,d0
  582.     bdos
  583.     bsr dump
  584.  
  585. quitprg    move.l (sp)+,d0        ; Trash return address and
  586.     rts            ; quit simulation.
  587.  
  588.     page
  589. *************************************************************************
  590. *                                    *
  591. *    FCB Tracing support routines.                    *
  592. *                                    *
  593. *************************************************************************
  594.  
  595.     ifne trcdsk
  596. fcbtrc1    movem.l d0-d2/a0,-(sp)    ; Dump to printer each FCB usage
  597.     move.b #9,d1        ; in format FN #, Disk, Name (ASCII)
  598.     bsr lpchar        ; and the rest, all in hex but the
  599.     move.w d0,d1        ; name field.  Print the returned
  600.     bsr lpbyte        ; value after the FCB.
  601.     move.b d2,d1        ; Char in D2 is printed after FN #.
  602.     bsr lpchar
  603.     bsr lpspace
  604.     bsr lpspace
  605.     move.b (a0)+,d1
  606.     bsr lpbyte
  607.     bsr lpspace
  608.     move.w #10,d2
  609. fcbtr1    move.b (a0)+,d1        ; Print Name field...
  610.     bsr lpchar
  611.     dbra d2,fcbtr1
  612.     bsr lpspace
  613.     move.w #3,d2
  614. fcbtr2    move.b (a0)+,d1        ; Ex .. Rc
  615.     bsr lpbyte
  616.     bsr lpspace
  617.     dbra d2,fcbtr2
  618.     bsr lpspace
  619.     bsr lpspace
  620.     lea.l 16(a0),a0        ; Skip d0..dn field.
  621.     move.w #3,d2
  622. fcbtr3    move.b (a0)+,d1        ; CR .. R2
  623.     bsr lpbyte
  624.     bsr lpspace
  625.     dbra d2,fcbtr3
  626.     bsr lpspace
  627.     bsr lpspace
  628.     move.l dmaaddr,d1
  629.     sub.l targbase,d1
  630.     bsr lpword
  631.     bsr lpspace
  632.     movem.l (sp)+,d0-d2/a0
  633.     rts
  634.  
  635.     page
  636. fcbtrc2 movem.l d0-d1,-(sp)    ; Line termination of FCB trace.
  637.     bsr lpspace
  638.     bsr lpspace
  639.     move.b d0,d1
  640.     bsr lpbyte
  641. fcbtr21    move.b #10,d1
  642.     bsr lpchar
  643.     move.b #13,d1
  644.     bsr lpchar
  645.     movem.l (sp)+,d0-d1
  646.     rts
  647.  
  648. fcbtrc2a:
  649.     movem.l d0-d1,-(sp)    ; Line termination if no result
  650.     bra fcbtr21        ; is to be presented.
  651.     endc
  652.  
  653.     page
  654. *************************************************************************
  655. *                                    *
  656. *    Misc. service routines.                        *
  657. *    (Inelegant, but rarely used so they stand as is).        *
  658. *                                    *
  659. *************************************************************************
  660.  
  661.  
  662. pbyte    move.l #$20018,d0    ; 2 nybbles, 24 bit shift first.
  663.     bra pdigits
  664. pword    move.l #$40010,d0    ; 4 nybbles, 16 bit shift first.
  665.     bra pdigits
  666. paddr    move.l #$60008,d0    ; 6 nybbles, 8 bit shift first.
  667.     bra pdigits
  668. plong    move.l #$80000,d0    ; 8 nybbles, no shift first.
  669. pdigits    rol.l d0,d1        ; Do shift.
  670.     bra pdigent
  671. pdiglop    swap d0            ; Save nybble count.
  672.     rol.l #4,d1        ; Print variable in d1.
  673.     bsr ntoa
  674. pdigent    swap d0            ; Get nybble count.
  675.     dbra d0,pdiglop
  676.     rts
  677.  
  678. ntoa    movem.l d0-d1,-(sp)    ; Nybble in d1 to ASCII, then output.
  679.     and #$f,d1
  680.     cmp #$a,d1
  681.     blt ntoa2
  682.     add.b #'A'-'9'-1,d1
  683. ntoa2    add.b #'0',d1
  684.     move.w #2,d0
  685.     bdos 
  686.     movem.l (sp)+,d0-d1
  687.     rts
  688.  
  689. pspace    move.w #32,d1        ; Print a space.
  690.     move.w #2,d0
  691.     bdos
  692.     rts
  693.  
  694.     page
  695. *
  696. *    Line Printer versions of above
  697. *
  698.  
  699. lpbyte    move.l #$20018,d0    ; 2 nybbles, 24 bit shift first.
  700.     bra lpdigts
  701. lpword    move.l #$40010,d0    ; 4 nybbles, 16 bit shift first.
  702.     bra lpdigts
  703. lpaddr    move.l #$60008,d0    ; 6 nybbles, 8 bit shift first.
  704.     bra lpdigts
  705. lplong    move.l #$80000,d0    ; 8 nybbles, no shift first.
  706. lpdigts    rol.l d0,d1        ; Do shift.
  707.     bra lpdgent
  708. lpdiglp    swap d0            ; Save nybble count.
  709.     rol.l #4,d1        ; Print variable in d1.
  710.     bsr lntoa
  711. lpdgent    swap d0            ; Get nybble count.
  712.     dbra d0,lpdiglp
  713.     rts
  714.  
  715. lntoa    movem.l d0-d1,-(sp)    ; Nybble in d1 to ASCII, then output.
  716.     and #$f,d1
  717.     cmp #$a,d1
  718.     blt lntoa2
  719.     add.b #'A'-'9'-1,d1
  720. lntoa2    add.b #'0',d1
  721. lntoa3    move.w #5,d0
  722.     bdos 
  723.     movem.l (sp)+,d0-d1
  724.     rts
  725.  
  726. lpchar    movem.l d0-d1,-(sp)    ; Print a character.
  727.     bra lntoa3
  728.  
  729. lpspace    movem.l d0-d1,-(sp)    ; Print space.
  730.     move.w #32,d1
  731.     bra lntoa3
  732.  
  733.     page
  734. *
  735. *    Remaining misc. service routines.
  736. *
  737.  
  738. lpstr    movem.l d0-d1,-(sp)    ; Print a null-terminated string.
  739. lpstr1    move.b (a0)+,d1
  740.     beq lpstr2
  741.     bsr lpchar
  742.     bra lpstr1
  743. lpstr2    movem.l (sp)+,d0-d1
  744.     rts
  745.  
  746.  
  747. konin    move.w #1,d0    ; Console input for 'atol'.
  748.     bdos
  749.     rts
  750.  
  751.  
  752. atol    moveq #0,d1    ; ASCII to long, stops on invalid hex char.
  753.     clr d2        ; Returns long in d1, terminator char in d0,
  754. atol1    bsr konin    ; d2=1 if any chars entered before terminator.
  755.     cmp.b #$40,d0
  756.     blo atol2
  757.     and #$5F,d0    ; Mask to upper case.
  758. atol2    cmpi.b #'0',d0    ; Check range (0..9,A..F).
  759.     blo atolend
  760.     cmpi.b #'F',d0
  761.     bhi atolend
  762.     cmpi.b #'9',d0
  763.     bls atol3
  764.     cmpi.b #'A',d0
  765.     bhs atol3
  766.     bra atolend
  767. atol3    moveq #1,d2    ; Valid characters entered, flag it.
  768.     sub.b #'0',d0
  769.     cmp.b #$9,d0
  770.     bls atol4
  771.     sub.b #'A'-'9'-1,d0
  772. atol4    ext d0        ; To long.
  773.     ext.l d0
  774.     asl.l #4,d1    ; Tack it onto D1.
  775.     add.l d0,d1
  776.     bra atol1
  777. atolend    rts
  778.  
  779.     page
  780.     data
  781. *************************************************************************
  782. *                                    *
  783. *    Target processor's data registers.                *
  784. *    Fake FDOS.                            *
  785. *                                    *
  786. *************************************************************************
  787.  
  788.     even
  789. regop3    equ -9        ; Operand 1 for DAA storage.
  790. regb    equ -8        ; Offsets from register base pointer for
  791. regc    equ -7        ; 8080's pseudo-registers.
  792. regd    equ -6        ; A & F are in Data Registers.
  793. rege    equ -5        ; Pseudo-PC is kept in an Address Register.
  794. regh    equ -4
  795. regl    equ -3
  796. regop1    equ -2        ; Operand 1 for DAA storage.
  797. regop2    equ -1        ;    "    2  "   "     "
  798.  
  799. fcbstor ds.b 36        ; Host works FCB's out of here.
  800. fcbflag    ds.b 1        ; Flag says we used the FCB buffer.
  801.  
  802.     even
  803. tracesad ds.l 1        ; Trace start address.
  804. traceead ds.l 1        ; Trace end address.
  805. traceflg ds.w 1        ; Tracing enabled flag.
  806.  
  807. dmaaddr    ds.l 1        ; DMA address storage.
  808.  
  809.     page
  810. fdos    dc.b $76,0,$C9    ; Fake BDOS for target system.
  811. *            ; BIOS Jump Table
  812.     dc.b $C3,$33,$FF    ; Wboot
  813.     dc.b $C3,$36,$FF    ; Const
  814.     dc.b $C3,$39,$FF    ; Conin
  815.     dc.b $C3,$3C,$FF    ; Conout
  816.     dc.b $C3,$3F,$FF    ; List
  817.     dc.b $C3,$42,$FF    ; Punch
  818.     dc.b $C3,$45,$FF    ; Reader
  819.     dc.b $C3,$48,$FF    ; Home
  820.     dc.b $C3,$4B,$FF    ; Seldsk
  821.     dc.b $C3,$4E,$FF    ; Settrk
  822.     dc.b $C3,$51,$FF    ; Setsec
  823.     dc.b $C3,$54,$FF    ; Setdma
  824.     dc.b $C3,$57,$FF    ; Read
  825.     dc.b $C3,$5A,$FF    ; Write
  826.     dc.b $C3,$5D,$FF    ; Listst
  827.     dc.b $C3,$60,$FF    ; Sectran
  828.  
  829.     dc.b $76,1,$C9    ; Fake BIOS for target system
  830.     dc.b $76,2,$C9        ; Const
  831.     dc.b $76,3,$C9        ; Conin
  832.     dc.b $76,4,$C9        ; Conout
  833.     dc.b $76,5,$C9        ; List
  834.     dc.b $76,6,$C9        ; Punch
  835.     dc.b $76,7,$C9        ; Reader
  836.     dc.b $76,8,$C9        ; Home *
  837.     dc.b $76,9,$C9        ; Seldsk *
  838.     dc.b $76,10,$C9        ; Settrk *
  839.     dc.b $76,11,$C9        ; Setsec *
  840.     dc.b $76,12,$C9        ; Setdma *
  841.     dc.b $76,13,$C9        ; Read *
  842.     dc.b $76,14,$C9        ; Write *
  843.     dc.b $76,15,$C9        ; Listst
  844.     dc.b $76,16,$C9        ; Sectran *
  845.  
  846. fdoslen    equ *-fdos
  847.  
  848.     page
  849. *************************************************************************
  850. *                                    *
  851. *    Messages.                            *
  852. *                                    *
  853. *************************************************************************
  854.  
  855. illgmsg    dc.b $d,$a,'Illegal instruction $'
  856. ilgmsg2 dc.b ' at $'
  857. ilgmsg3 dc.b '.$'
  858. dumpmsg    dc.b $d,$a,'Register contents:$'
  859. dmpmsg2    dc.b $d,$a
  860.     dc.b '-AF- -BC- -DE- -HL- -SP- -S0- -S1- -S2- -S3- -PC- -op-',$d,$a,'$'
  861. biosmsg dc.b $d,$a,'Illegal BIOS call $'
  862. biosmg2 dc.b '.$'
  863. tracemsg dc.b 13,10,'Start trace at >$'
  864. tracemg2 dc.b 13,10,'End trace at >$'
  865. opnmsg    dc.b 'Cannot open .COM file.$'
  866. ilgbdos dc.b 'Unsupported BDOS call.$'
  867. fcbmsg    dc.b 9,'Fn#  Dr    NAME     EX S1 S2 RC   CR R0 R1 R2   Addr  Rslt',10,13
  868.     dc.b 9,'----------------------------------------------------------',10,13,0
  869.     page
  870.     bss
  871. *************************************************************************
  872. *                                    *
  873. *    Target processor's address space.                *
  874. *                                    *
  875. *************************************************************************
  876.  
  877.     even
  878. registers ds.b 10        ; Actual storage for 8080's other registers.
  879. target    ds.b $10000        ; 8080's universe.
  880. junkbuf    ds.b $80        ; For BDOS' OPEN faking (RREAD buffer).
  881.     .end
  882. 's other registers.
  883. target    ds.b $10000        ; 8080's universe.
  884. junkbuf    ds.b $80        ; For BDO