Serial Communication with the 2600 @115.200 baud

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Al_Nafuur

just because we can 8) , or maybe we can use this to flash a Arduino based board like the KeyPortari?


; NTSC 1.190.476 Hz ≈ 0,840 µs per CPU cycle
; PAL 1.179.000 Hz ≈ 0,849 µs per CPU cycle
; 115.200 baud is ~8,68056μs per bit (=10,225 PAL CPU cycles or 10,334 NTSC CPU cycles )

    lda #%00000001 ; Set our TX to output
    sta SWACNT
    lda #$ff
    sta SWCHA

    sta WSYNC

    ldx #0
    ldy #1

byte_loop
    lda #0          ; 2
    sta SWCHA       ; 4 @00 : Start-bit (low))
;    ldy #7          ; 2
    lda data_uart,x ; 4

;bit_loop
;    sta SWCHA       ; 4 @10 : Bit 0-7
;    ror             ; 2
;    dey             ; 2
;    bpl bit_loop    ; 2/3

;bit_loop enrolled!
    SLEEP 2         ; 2
    sta SWCHA       ; 4 @10 : Bit 0 (@ 10,225)

    SLEEP 4         ; 4
    ror             ; 2
    sta SWCHA       ; 4 @20 : Bit 1 (@ 20,45)

    SLEEP 5         ; 5
    ror             ; 2
    sta SWCHA       ; 4 @31 : Bit 2 (@ 30,675)

    SLEEP 4         ; 4
    ror             ; 2
    sta SWCHA       ; 4 @41 : Bit 3 (@ 40,9)

    SLEEP 4         ; 4
    ror             ; 2
    sta SWCHA       ; 4 @51 : Bit 4 (@ 51,125)

    SLEEP 4         ; 4
    ror             ; 2
    sta SWCHA       ; 4 @61 : Bit 5 (@ 61,35)

    SLEEP 5         ; 5
    ror             ; 2
    sta SWCHA       ; 4 @72 : Bit 6 (@ 71,575)

    SLEEP 4         ; 4
    ror             ; 2
    sta SWCHA       ; 4 @82 : Bit 7 (@ 81,8)

    SLEEP 6         ; 6
; end of enrolled bit_loop!

    sty SWCHA       ; 4 @92 : Stop-bit high (@ 92,025) (y=0xff)

    ; idle (TX high) time can be longer than 10 cycles
    SLEEP 2

    inx
    bne byte_loop

    ALIGN 256
data_uart
    .byte "Hello UART World"
    .byte 13, "Hello World 002"
    .byte 13, "Hello World 003"
    .byte 13, "Hello World 004"
    .byte 13, "Hello World 005"
    .byte 13, "Hello World 006"
    .byte 13, "Hello World 007"
    .byte 13, "Hello World 008"
    .byte 13, "Hello World 009"
    .byte 13, "Hello World 00A"
    .byte 13, "Hello World 00B"
    .byte 13, "Hello World 00C"
    .byte 13, "Hello World 00D"
    .byte 13, "Hello World 00E"
    .byte 13, "Hello World 00F"
    .byte 13, "Hello World 010"

result on the PC Serial-Monitor


 

Al_Nafuur

#1
here is a small schematics how to connect.



I have only tested with a PAL system. I can post the binary, if someone is interested to test with a NTSC system.

Caution: the schematics is "from" the 2600, so pin 1 and 2 are PA0 and PA1. Pin 7 is +5V and is used as pull-up via the 10K resistor for PA0

alex_79

I used serial connection to dump cartridges in the past, and also in some test roms as an easier way to get the results without the need to design a kernel to display them on the TV...

I think the fastest speed I used was 57600 baud, and at that speed my 7800 needed the loop to be shorter (or longer, I don't remember) by 1 cycle, else it didn't work.

Probably not relevant in 2025, but if anyone is using a legacy (non TTL) RS232 port (or an usb to RS232 adapter), I successfully used this simple level converter built with just a few discrete parts with my consoles:
https://web.archive.org/web/20080218095911/http://www.uchobby.com/index.php/2007/06/11/ttl-to-rs232-adaptor-explained/

The leds and related resistors are optional, and also the entire "TTL RX" part if you only need to transmit.

Al_Nafuur


Al_Nafuur

#4
Successful reading at 9600 baud via INPT5 in vcsELF:


  char c = 0;
  while(c != '*' && i<256){
    while(vcsRead4(INPT5) & 0x80 ){
      vcsJmp3();
    }; // wait for start bit (RX low)
    vcsSleep(140); // 6
    vcsWrite5(COLUBK, bk);
    bk += 0x10;
    c = vcsRead4(INPT5);
    vcsSleep(119);
    c = (c >> 1) | (vcsRead4(INPT5) & 0b10000000);
    vcsSleep(118);
    c = (c >> 1) | (vcsRead4(INPT5) & 0b10000000);
    vcsSleep(119);
    c = (c >> 1) | (vcsRead4(INPT5) & 0b10000000);
    vcsSleep(119);
    c = (c >> 1) | (vcsRead4(INPT5) & 0b10000000);
    vcsSleep(119);
    c = (c >> 1) | (vcsRead4(INPT5) & 0b10000000);
    vcsSleep(118);
    c = (c >> 1) | (vcsRead4(INPT5) & 0b10000000);
    vcsSleep(119);
    c = (c >> 1) | (vcsRead4(INPT5) & 0b10000000);
    vcsSleep(100);
    buffer[i++] = c;
  }
  buffer[i] = 0;




Al_Nafuur

I can't get the vcsELF TX code to work:

  char buffer[256] = "RDIR\n";
  uint8_t i = 0;
  uint8_t bk = 0x04;
  uint8_t  c = 0;
  char *pbuffer = &buffer[0];
  vcsEndOverblank();
  vcsWrite5(COLUBK, 0xa0);
  vcsWrite5(VBLANK, 0); // disable blanking
  while(! (vcsRead4(INPT5) & 0x80) ){
    vcsJmp3();
  } // waiting for start bit geting high again
  vcsWrite5(COLUBK, bk);
  vcsWrite6(SWACNT, 0b00000001);
  vcsWrite6(SWCHA, 0xff);
  vcsWrite5(WSYNC, 0b00000001);
  while (*pbuffer != 0){
    vcsWrite6(SWCHA, 0); // RX start-bit low
    vcsSleep(117);
    c = (uint8_t)*pbuffer++;
    vcsWrite6(SWCHA, c);
    vcsSleep(117);
    c = (c >> 1);
    vcsWrite6(SWCHA, c);
    vcsSleep(116);
    c = (c >> 1);
    vcsWrite6(SWCHA, c);
    vcsSleep(117);
    c = (c >> 1);
    vcsWrite6(SWCHA, c);
    vcsSleep(117);
    c = (c >> 1);
    vcsWrite6(SWCHA, c);
    vcsSleep(117);
    c = (c >> 1);
    vcsWrite6(SWCHA, c);
    vcsSleep(116);
    c = (c >> 1);
    vcsWrite6(SWCHA, c);
    vcsSleep(117);
    c = (c >> 1);
    vcsWrite6(SWCHA, c);
    vcsSleep(117);
    vcsWrite6(SWCHA, 1); //RX stop-bit high
    vcsSleep(117);
  }
  vcsWrite6(SWACNT, 0b00000000);

Al_Nafuur

Ok I finally found the issue. Since I am still using 8-bit ASCII in the KeyPortari protocol I have to wait until the keyboard key is released and the KeyPortari releases the port. So for now I added a:

  while( (vcsRead4(SWCHA) != 0xff) ){
    vcsJmp3();
  } // waiting for release of KeyPortari


Later we might use a 7-bit ASCII protocol where one bit is always "free" for communication