As I promised , here is a working solution for connecting MSX and PC !

Try this Turbo Pascal code . 4 bits in 4 bits out via Joystick port and Pc
printer port . (Tested and works)

Sincerely Kari Lammassaari/Finland/ACDEMY 

Oh shi.. The cable pinout lacks. Post it tomorrow !(I have to measure the
cable)

MSX-side :

-- cut here --
{MSX_PC.INC}

{Connecting MSX via joystick to PC parallel port }
{by Kari Lammassaari (ACADEMY) 1996-98 }
{The routines for PC are in file  PC_MSX.PAS }

{REM IMPORTANT !!! In the block send/receive routines the two first
 sent/received bytes contain the total lenght of the block including
 the two first bytes (low byte first)}
{ This file contain following procedures and functions :

  - Procedure JoyByteSend(value:Byte);
  - Procedure JoyBlockSend(BuffAddr:Integer);

  - Function  JoyByteReceive:Byte;
  - Procedure JoyBlockReceive(BufAddr:Integer);

  and following type definition, which is used also in PC_MSX.PAS
}

Type DataBlockType = Record
                       Len    :Integer;
                       ChkSum :Integer;
                       DataId :Byte;
                       Data   :Array[0..255] Of Byte;
                     End;

Procedure JoyByteSend(value:Byte);
 Begin
   Inline($f3/
          $3a/Value /
          $67/$cb/$3c/$cb/$3c/$cb/$3c/$cb/$3c/ {High nibble to H }
          $e6/$0f/ $6f/                        {Low nibble to L  }

          $3e/0/$d3/$99/$d9/$d9/$3e/$40/$d3/$99/$d9/$d9/$3a/Value /$d3/$98/
          {The code above just writes current byte value on vram addr 0 }

          $3e/$0e/$d3/$a0/$db/$a2/$cb/$47/$20/<-6/ { Wait until ready ? }
          $3e/$0f/$d3/$a0/ $7d /$f6/$50/ $d3/$a1/  { Send high nibble }

          $3e/$0e/$d3/$a0/$db/$a2/$cb/$47/$28/<-6/ {Wait until PC has
received }
          $3e/$0f/$d3/$a0/$3e/$40 /$d3/$a1/        {Reset data ready signal }

          $3e/$0e/$d3/$a0/$db/$a2/$cb/$47/$20/<-6/  {Wait until pc ready }
          $3e/$0f/$d3/$a0/ $7c/ $f6/$50/ $d3/$a1/   {Send low nibble }

          $3e/$0e/$d3/$a0/$db/$a2/$cb/$47/$28/<-6/  {... }
          $3e/$0f/$d3/$a0/$3e/$40 /$d3/$a1/
          $fb);

 End;

Procedure JoyBlockSend(BuffAddr:Integer);
  Var BlockAddress :Integer;
  Begin
    BlockAddress := BuffAddr;
    Inline
     (
     $F3/$DD/$2a/BlockAddress/$DD/$4E/$0/$DD/$46/$1/$DD/$7E/$0/$67/$CB/
     $3C/$CB/$3C/$CB/$3C/$CB/$3C/$E6/$F/$6F/

     $3E/$0/$D3/$99/$D9/$D9/$3E/$40/$D3/$99/$DD/$7E/$0/$D9/$D9/$D3/$98/

     {The code above just writes current byte value on vram addr 0 }

     $3E/$E/$D3/$A0/$DB/
     $A2/$CB/$47/$20/$FA/$3E/$F/$D3/$A0/$7D/$F6/$50/$D3/$A1/$3E/$E/
     $D3/$A0/$DB/$A2/$CB/$47/$28/$FA/$3E/$F/$D3/$A0/$3E/$40/$D3/$A1/
     $3E/$E/$D3/$A0/$DB/$A2/$CB/$47/$20/$FA/$3E/$F/$D3/$A0/$7C/$F6/
     $50/$D3/$A1/$3E/$E/$D3/$A0/$DB/$A2/$CB/$47/$28/$FA/$3E/$F/$D3/
     $A0/$3E/$40/$D3/$A1/$DD/$23/$B/$78/$B1/$20/$8F/$FB
     );
   End;


Function JoyByteReceive:Byte;
 Var Value :Byte;
 Begin
   Inline($f3/

          $3e/$0f/$d3/$a0/ $3e /$5f/ $d3/$a1/
          $3e/$0e/$d3/$a0/$db/$a2/$cb/$47/$20/<-6/ {Pc data ready ? }
          $3e/$0f/$d3/$a0/ $3e /$1f/ $d3/$a1/      {Set joy port 1 fo
reading }
          $3e/$0e/$d3/$a0/$db/$a2/$e6/$0f/$6f /    {Read and store data in L}
          $3e/$0f/$d3/$a0/$3e/$4f /$d3/$a1/        {Msx has read data }
          $3e/$0e/$d3/$a0/$db/$a2/$cb/$47/$28/<-6/

          $3e/$0f/$d3/$a0/ $3e /$5f/ $d3/$a1/
          $3e/$0e/$d3/$a0/$db/$a2/$cb/$47/$20/<-6/ {Pc data ready ? }
          $3e/$0f/$d3/$a0/ $3e /$1f/ $d3/$a1/      {Set joy port 1 fo
reading }
          $3e/$0e/$d3/$a0/$db/$a2/
          $cb/$27/$cb/$27/$cb/$27/$cb/$27/$67 /    {Read and store data in H }
          $3e/$0f/$d3/$a0/$3e/$4f /$d3/$a1/        {Msx has read data }
          $3e/$0e/$d3/$a0/$db/$a2/$cb/$47/$28/<-6/
          $7c/$85/$32/Value /
          $3e/0/$d3/$99/$d9/$d9/$3e/$40/$d3/$99/$d9/$d9/$3a/Value /$d3/$98/
          {The code above just writes current byte value on vram addr 0 }
          $fb);
       JoyByteReceive := Value;
 End;

Procedure JoyBlockReceive(BufAddr:Integer);

  Var Len,i :Integer;
  Begin
   Len := JoyByteReceive + 256*JoyByteReceive;

   Mem[BufAddr] := Lo(Len);
   Mem[BufAddr+1] := Hi(Len);
   For i := 1 To Len+3 Do Mem[BufAddr+1+i] :=JoyByteReceive;
  End;

----- cut here ---

Pc-code 

---- cut here ---

{PC_MSX:PAS by Kari Lammassaari 1996-98}
{The routines are to be used with the msx equivalent routines in
 msx_pc.inc }
{REM IMPORTANT ! The block send/receive-routines expect the two first
received/sent byte contain the total lenght of the block including
those two first bytes !}

{This file contains following procedures and functions:

  - Function ParallelByteReceive:Byte;
  - Procedure ParallelBlockReceive(DataBlock:DataBlockType);

  - Procedure ParallelByteSend(Value:Byte);
  - Procedure ParallelBlockSend(Var DataBlock:DataBlockType);
  and following type definition:
}
Type DataBlockType = Record
                        Len    :Word;
                        ChkSum :Word;
                        DataId :Char;
                        Data   :Array[0..255] Of Byte;
                      End;

   {
     Function GetNibble:Byte;
      Begin
       Port[$37a] :=205;
       Repeat Until  ((Port[$379] And 128) = 0) Or KeyPressed;
        GetNibble := (Port[$379] shr 3) And 15;
        Port[$37a] :=204;
       Repeat Until ((Port[$379] And 128) = 128) Or KeyPressed;
     End;
   }

Function GetNibble:Byte; Assembler;
 Asm
       Mov dx,$37a   ;{Ctrl-port of parallel port  }
       Mov al,205    ;{Normal value after reset is 204}
       Out dx,al     ;{Pc is ready to receive      }

       Mov dx,$379   ;{Status port in dx           }

 @Loop1:             ;

       In al,dx      ;{Is data ready               }
       and al,128
       Jnz @Loop1    ;

       push ax       ;{ Let signals be settled     }
       pop ax        ;

       In al,dx      ;{Reread data                 }
       Shr al,3      ;{Shift bits to the right edge}

       And al,15     ;{Mask off the upper nibble   }

       Push ax       ;

       Mov dx,$37a   ;{Ctrl-port                   }
       Mov al,204    ;{Normal after-reset value    }
       Out dx,al     ;{Data received               }

       Mov dx,$379   ;{Status port                 }

@Loop2:
       In al,dx      ;{Has Msx received message ?  }
       and al,128    ;
       Jz @Loop2     ;
       Pop Ax        ;
 End;

Function ParallelByteReceive:Byte;
 Begin
   ParallelByteReceive := 16 * GetNibble + GetNibble;
 End;

Procedure ParallelBlockReceive(Var DataBlock:DataBlockType);
  Var i :Word;
  Begin
   DataBlock.Len :=    ParallelByteReceive*256 + ParallelByteReceive -5;
{Do not include the header bytes }
   DataBlock.ChkSum := ParallelByteReceive*256 + ParallelByteReceive;
   DataBlock.DataId := Chr(ParallelByteReceive);
   i:=0;
   While i < DataBlock.Len Do
    Begin
      DataBlock.Data[i]:= ParallelByteReceive;
      Inc(i);
    End;
  End;

   {
    Procedure PutNibble(Value:Byte);
     Begin
      Repeat Until ((Port[$379] And 128) = 0) Or KeyPressed;
      Port[$378] := Value And 15;
      Port[$37a] := 205 ;
      Repeat Until ((Port[$379] And 128) = 128) Or KeyPressed;
      Port[$37a] := 204 ;
     End;
    }

Procedure PutNibble(Value:Byte);Assembler;
 Asm
    mov dx,$379 ;
@loop1:
    in  al,dx   ;
    and al,128  ;
    jnz @loop1   ;
    mov dx,$378 ;
    mov al,Byte Ptr [Value]      ;
    out dx,al
    mov dx,$37a ;
    mov al,205  ;
    out dx,al   ;
    mov dx,$379
@loop2:
      in al,dx  ;
      and al,128   ;
      jz  @loop2  ;

      mov dx,$37a
      mov al,204
      out dx,al
  end;

Procedure ParallelByteSend(Value:Byte);
Begin
  PutNibble(Value And 15);
  PutNibble(Value shr 4 );
End;

Procedure ParallelBlockSend(Var DataBlock:DataBlockType);
  Var Counter :Word;
      Ptr     :^Byte;
  Begin
     Ptr := Addr(DataBlock);
     For Counter := 1 to DataBlock.Len + 5 Do
      Begin
         ParallelByteSend(Ptr^);
         Inc(Ptr);
      End;
  End;



****
MSX Mailinglist. To unsubscribe, send an email to [EMAIL PROTECTED] and put
in the body (not subject) "unsubscribe msx [EMAIL PROTECTED]" (without the
quotes :-) Problems? contact [EMAIL PROTECTED] (www.stack.nl/~wiebe/mailinglist/)
****

Reply via email to