Menu

#305 win32 - Attaching cart prevents user port RS-232 emulation

v2.3
closed-invalid
nobody
None
Windows
RS232
2021-10-25
2012-06-20
AgentFriday
No

Any time I attach an easy flash .CRT, RS-232 emulation on the user port will not work.

Discussion

  • gpz

    gpz - 2012-06-20

    could you provide a testcase for this?

     
  • AgentFriday

    AgentFriday - 2012-06-21

    .crt, .ini, and test program

     
  • AgentFriday

    AgentFriday - 2012-06-21

    Test case attached.

    Control:
    1. Load the attached .ini settings.
    2. Load and run testcase.prg. You should see a directory come through at 300 baud.

    To reproduce bug:
    1. Load the attached .ini settings.
    2. Attach the included testcase.crt image
    3. Use F2 to go straight to basic w/o loading anything.
    3. Load and run testcase.prg

    With the .crt attached, nothing comes back. Note that on real hardware, we use easyflash all the time with RS-232 and there is no conflict.

    I suspect that attaching ANY cart would trigger the same problem, but since all the .crt images I have are games, and there's no reason why EF should prevent RS-232 from working, I didn't bother hunting down a regular non-game cart.

     
  • gpz

    gpz - 2012-06-21

    err? there surely has to be something connected on the other end of the rs232 ?

     
  • AgentFriday

    AgentFriday - 2012-06-21

    unfortunately the service that the url in the .ini is connecting to is down right now. I've notified the sysop. Try again in a bit, or substitute any other telnet ip:port to see SOMETHING come back.

     
  • AgentFriday

    AgentFriday - 2012-06-21

    All you need is an internet connection. The service should always be up and running. Let me know if you have any trouble getting results with the control.

     
  • gpz

    gpz - 2012-06-21

    ok, managed to reproduce (its a bit tricky with wine on linux hehe). i noticed that simply detaching the cartridge makes rs232 emulation work again, so there probably is indeed some kind of correlation.
    assigning to blacky, since this is a windows specific problem (or atleast, rs232 can not be used that way in linux)

     
  • gpz

    gpz - 2018-08-31

    can someone test if this works with GTK3 please?

     
  • gpz

    gpz - 2020-05-02

    please?

     
  • gpz

    gpz - 2021-10-05

    relaying from IRC:

    <durandal> Found out what fails in bug#305, but not why: CIA2 PRB gets stuck unless you write a value different from DDRB (assuming you have some bits set to output)
    <durandal> Kernal does LDA#$06 STA $DD03 STA $DD01, it works normally, but fails with the crt attached
    <durandal> using a terminal with custom routines that sets $DD01 to $02 for example or poking from BASIC gets PRB unstuck and it starts behaving normally
    
     
  • gpz

    gpz - 2021-10-06

    again relaying from IRC :)

    <durandal> I think I got a fix for bug#305, need to do some more tests just in case it breaks something else
    <durandal> seems ok, tested with a few terminals for the userport, and then ran the ciaports.prg and ghosting.prg testprogs
    
    Index: vice/src/core/ciacore.c
    ===================================================================
    --- vice/src/core/ciacore.c (revisión: 40848)
    +++ vice/src/core/ciacore.c (copia de trabajo)
    @@ -324,22 +324,26 @@
    
             case CIA_PRB:           /* port B */
             case CIA_DDRB:
    -            cia_context->c_cia[addr] = byte;
    +            if (addr == CIA_PRB) {
    +                cia_context->c_cia[CIA_PRB] = byte & cia_context->c_cia[CIA_DDRB]; /* Write only bits set to output into PRB */
    +            } else {
    +                cia_context->c_cia[addr] = byte;
    +            }
                 byte = cia_context->c_cia[CIA_PRB] | ~(cia_context->c_cia[CIA_DDRB]);
                 if ((cia_context->c_cia[CIA_CRA]
    -                 | cia_context->c_cia[CIA_CRB]) & 0x02) {
    -                if (cia_context->c_cia[CIA_CRA] & 0x02) {
    +                 | cia_context->c_cia[CIA_CRB]) & 0x02) {   /* timer B PB7 out */
    +                if (cia_context->c_cia[CIA_CRA] & 0x02) {   /* timer A PB6 out */
                         cia_update_ta(cia_context, rclk);
                         byte &= 0xbf;
    -                    if (((cia_context->c_cia[CIA_CRA] & 0x04) ? cia_context->tat
    +                    if (((cia_context->c_cia[CIA_CRA] & 0x04) ? cia_context->tat    /* timer A PB6 toggle */
                              : ciat_is_underflow_clk(cia_context->ta, rclk))) {
                             byte |= 0x40;
                         }
                     }
    -                if (cia_context->c_cia[CIA_CRB] & 0x02) {
    +                if (cia_context->c_cia[CIA_CRB] & 0x02) {   /* timer B PB7 out */
                         cia_update_tb(cia_context, rclk);
                         byte &= 0x7f;
    -                    if (((cia_context->c_cia[CIA_CRB] & 0x04) ? cia_context->tbt
    +                    if (((cia_context->c_cia[CIA_CRB] & 0x04) ? cia_context->tbt    /* timer B PB7 toggle */
                              : ciat_is_underflow_clk(cia_context->tb, rclk))) {
                             byte |= 0x80;
                         }
    
     
  • gpz

    gpz - 2021-10-06

    that fix is almost certainly wrong, there is no reason you should ignore ddr when writing to port b, the proper way to solve it is: first check the behaviour on a real c64. and if that actually works, the problem is more likely in the logic that handles the userport rs232. And then we should come up with a simple test program that reproduces the problem, ie works on c64 and not in VICE. Dont assume running random programs, or even the testbench, can actually prove you didnt break something - it can only prove you DID break something, when a program that worked before stops working, not the other way around.

     
  • gpz

    gpz - 2021-10-06

    that fix is almost certainly wrong, there is no reason you should ignore ddr when writing to port b

    oops disregard, i misread the patch - it actually adds that!. The rest still stands though - we need a program to reproduce the problem before we can apply the patch - the CIA core is just too important for experiments.

     
  • gpz

    gpz - 2021-10-06

    To add on this, i think the cia_context->c_cia values should always contain what was actually written to them, ie what is missing is some masking with DDR elsewhere in the code

     
  • Durandal

    Durandal - 2021-10-07

    Thinking further about this, I figured this patch I wrote is just fixing the symptoms and not the real problem. It's wrong.
    In VICE the userport RS232 emulation doesnt stablish a connection thru the RS232 driver until the DTR pin goes from high to low. This normally happens in the kernal when the pin goes from input (its pulled up to high) to output (goes to low because the default hard reset value in the PRB register is 0). The kernal then writes 6 to PRB setting DTR to high again.
    Easyflash sets PRB to $FF by default, then when the DTR pin changes from input to output in never goes down and thus the userport RS232 never initiates a connection.

    I have no idea about the modems used back in the day, but nowadays wifi modems and rs232 userport interfaces ignore DTR altogether (is not connected).

    A solution might be to simply initiate the connection with the RS232 driver the moment the userport RS232 emulation is enabled.

     
  • gpz

    gpz - 2021-10-07

    This normally happens in the kernal when the pin goes from input (its pulled up to high) to output (goes to low because the default hard reset value in the PRB register is 0). The kernal then writes 6 to PRB setting DTR to high again.
    Easyflash sets PRB to $FF by default, then when the DTR pin changes from input to output in never goes down and thus the userport RS232 never initiates a connection.

    That sounds like it would not work on a real C64 either - the emulation should be able to deal with this correctly (changing the port status by changing DDR) - which is indeed why your patch is wrong :)

    It'd really help if someone could confirm this on the real thing. My rs232 interface is broken unfortunately, so i cant help here :/

     
  • gpz

    gpz - 2021-10-07

    just for the records: kernal initializes the CIA2 ports like this - interestingly the portb output value is NOT initialized - so the kernel itself relies on the power up value in the CIA!

    .C:fdc1  8E 03 DD    STX $DD03      - A:08 X:00 Y:0A SP:fd ..-..IZC         94
    .C:fdcd  8D 00 DD    STA $DD00      - A:07 X:FF Y:0A SP:fd ..-..I.C        110
    .C:fdd2  8D 02 DD    STA $DD02      - A:3F X:FF Y:0A SP:fd ..-..I.C        116
    
     
    • Greg King

      Greg King - 2021-10-14

      just for the records: kernal initializes the CIA2 ports like this - interestingly, the portb output value is NOT initialized - so the kernel itself relies on the power-up value in the CIA!

      KERNAL doesn't set the output value because it's irrelevant -- all pins are set to input.

       
  • gpz

    gpz - 2021-10-14

    yes and no - it only works if you rely on those registers being untouched by other programs.

     
  • gpz

    gpz - 2021-10-25
    • status: open-need-info --> closed-invalid
     
  • gpz

    gpz - 2021-10-25

    closing this - i am convinced enough that this is not an emulation problem, but simply a software issue

     

Log in to post a comment.