[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Writing emulator...



Dosius wrote:
> Not sure, because the manual did say this - but if I omit them, I get
> different results - yes, I get CP/M, but the output is garbled.

The manual is correct, but it's handled in software.  If you disassemble the 
code that 60k CP/M 2.23 puts in $3C0-$3DB and $E3F-$E4A, you get this:

03C0    AD 83 C0        LDA C083        ; activate LC
03C3    AD 83 C0        LDA C083
03C6    8D 00 C4        STA Cx00        ; activate Z80
03C9    AD C0 81        LDA C081        ; deactivate LC
03CC    20 3F 0E        JSR 0E3F        ; get registers
03CF    20 YY XX        JSR XXYY        ; jsr to user 6502 code
03D2    8D 81 C0        STA C081        ; deactivate LC for monitor call
03D5    78              SEI             ; disable interrupts
03D6    20 4A FF        JSR FF4A        ; save registers [SAVE]
03D9    4C C0 03        JMP 03C0        ; reactivate softcard

0E3F    A5 48           LDA 48          ; get P reg
0E41    48              PHA             ; push it
0E42    A5 45           LDA 45          ; get A register
0E44    A6 46           LDX 46          ; get X register
0E46    A4 47           LDY 47          ; get Y register
0E48    28              PLP             ; pull P from stack
0E49    58              CLI             ; enable interrupts
0E4A    60              RTS             ; return to caller

You'll notice that the 6502 calling code uses the standard monitor save 
areas for registers.  The CP/M software does not maintain the S register at 
all.

Incidentally, the NMI and RESET vectors both point to the code at $3C0, 
which is the standard place that CP/M jumps to to reactivate the SoftCard 
from 6502 mode.

So the way this works is, the 6502 stops with $3C9 as the next instruction 
to fetch.  When Z80 code deactivates the card (as described in the calling 
6502 code section in the manual), that's where it goes.  It deactivates the 
language card, restores the registers from the locations given in the 
manual, and calls to the user code.  It then reactivates the SoftCard.

> but if I omit them, I get
> different results - yes, I get CP/M, but the output is garbled.

How is it garbled?  I read on your site that there is a problem with a 
"phantom" 80-column card.  That could well be your garbled display problem, 
since CP/M attempts to enable any card in slot 3 for console I/O.  If it 
does not find a display card, it uses Apple monitor routines to do keyboard 
and display.  When CP/M is doing I/O, it is always using 6502 code for it.

Another thing to note: Microsoft CP/M versions prior to 2.23 do not follow 
the Pascal slot protocol.

Mike