MSXDISK 0.9 BETA: Virtual Floppy Disk Driver over JOYSTICK2 of MSX

Страница 9/11
2 | 3 | 4 | 5 | 6 | 7 | 8 | | 10 | 11

By NYYRIKKI

Enlighted (5776)

Аватар пользователя NYYRIKKI

30-03-2021, 23:48

NYYRIKKI wrote:

BTW this fixed timing seems pretty tight: (off by 0.45 cycles / byte)

TXSTARTBIT:

    PUSH BC             ;(12)     |
    LD C,(HL)           ;(8)      |
    LD B,8              ;(8)      |
                        ;         | (18+45=63)
    LD A,E              ;(5)      |
    OUT (094H),A        ;(12)* 0  |       |
                        ;                 |
    BIT 0,(HL)          ;(14)             |
                        ;                 |
TXBITLOOP:              ;                 |
                        ;                 | (62)
    CP (HL)             ;(8) ALIGNMENT  | |
                        ;               | |
    RRC C               ;(10)           | |
                        ;               | |
    LD A,E              ;(5) SET 0      | |
    JR NC,TXBIT         ;(13/8)         | |
    LD A,D              ;(5) SET 1      | |
                        ;               | 
TXBIT:                  ;               | (62)
                        ;               |
    OUT (094H),A        ;(12)           |
    DJNZ TXBITLOOP      ;(14/9)       | |
                        ;             |
TXENDBITLOOP:           ;             |
                        ;             |
    POP BC		;(11)         | (62)
    CP (HL)		;(8)          |
    DEC BC              ;(7)          |
                        ;             |
TXSTOPBIT:              ;             |
                        ;             |
    LD A,B              ;(5)          |
    OR C                ;(5)          |
    LD A,D              ;(5)          |
    OUT (094H),A        ;(12)* 0      |

TXNEXTBYTE:

    INC HL              ;(7)   |
    JP NZ,TXSTARTBIT    ;(11)  | (18+)

Ok, maybe I'll post this RX-part as well...

RXSTARTBIT:             ;WAIT FOR STARTBIT

    IN A,(090H)         ;(12)* | |
    AND E               ;(5)   | | (28)
    JP NZ,RXSTARTBIT    ;(11)  | |
    CP (HL)             ;(8)   |
    CP (HL)             ;(8)   |
    CP (HL)             ;(8)   |
    LD D,80H            ;(8)   | (79)
    NOP                 ;(5)   |
                        ;      |
RXBITLOOP:              ;      |
    INC HL		;(7)   | |
    DEC HL		;(7)   | | (62)
    IN A,(090H)         ;(12)   ||
    AND E               ;(5)    ||
    ADD A,255		;(8)    ||
    RR D                ;(10)   ||
    JR NC,RXBITLOOP     ;(13/8) || 
    LD (HL),D		;(8)    | 
    CPI                 ;(18)   | (80)
    JP PE,RXSTARTBIT    ;(11)   |

By NYYRIKKI

Enlighted (5776)

Аватар пользователя NYYRIKKI

31-03-2021, 01:56

Aargh... I started to think again about cycle decimals... The more I think about this the more my head just hurts... To feel a bit more safe side, I reduced one cycle from the begin wait... I hope in "worst case scenario" this makes reads to rotate towards front edge of the signal between byte reads. (Inside 27 cycle error margin, while still keeping safe distance to both edges: 28+78+80 = 3*62) Still... None of this is tested.

RXSTARTBIT:             ;WAIT FOR STARTBIT

    IN A,(090H)         ;(12)* | |
    AND E               ;(5)   | | (28)
    JP NZ,RXSTARTBIT    ;(11)  | |
    INC HL              ;(7)   |
    DEC HL              ;(7)   |
    INC HL              ;(7)   | (78)
    DEC HL              ;(7)   |
    LD D,80H            ;(8)   |
                        ;      |
RXBITLOOP:              ;      |
    INC HL		;(7)   | |
    DEC HL		;(7)   | | (62)
    IN A,(090H)         ;(12)   ||
    AND E               ;(5)    ||
    ADD A,255		;(8)    ||
    RR D                ;(10)   ||
    JR NC,RXBITLOOP     ;(13/8) || 
    LD (HL),D		;(8)    | 
    CPI                 ;(18)   | (80)
    JP PE,RXSTARTBIT    ;(11)   |

By ocitygate

Expert (67)

Аватар пользователя ocitygate

31-03-2021, 05:21

@NYYRIKKI
Thanks for your observations.
Drop me an email for the latest source code.
You can easily compile and test it.
I decided to make it closed source for now.
But will share it with other contributors.

By RvS

Resident (49)

Аватар пользователя RvS

31-03-2021, 09:25

I started with a serial 'mini-driver' a year ago and tested it with a function generator (a square wave is valid serial data).
For RX, the trick is indeed to detect the startbit as fast as possible (now 28 cycles), then jump to the middle of bit0.
This is 1.5*62 minus the uncertainty of detection (28/2=14) 79 cycles. from that point consistent steps of 62 cycles till bit7.
There the byte can be stored (skip the detection of the stopbit).
The detection of the next startbit must start within the time region of the stopbit, ideally in the middle of that region.
TX is more forgiving, the normal serial interfaces allow for almost 3% of variation.

An improvement could be to change the startbit detection to (all bits are assumed to be '1' at idle):

RXSTARTBIT:
    IN A,(C)
    JP PE,RXSTARTBIT   ;25 CYCLES

A complicating factor is that not all MSX machines run at 3.58 MHz (at least the NMS8220 and NMS8245 run at 3.55MHz) and not all serial interfaces run at the selected frequency, but can deviate around 0.5%

By NYYRIKKI

Enlighted (5776)

Аватар пользователя NYYRIKKI

31-03-2021, 09:37

ocitygate wrote:

I decided to make it closed source for now.

Personally I don't think this is best way to go... Many people here might have something to say or to learn... If you mean pushing untested code out, then yes... Definitely no reason to do that before these ideas have been tested in real life.

Finally I dig out all the needed spare parts to my table... (case, USB-cable etc.) Now I only need to pick up that soldering iron to finish that last 1 minute task. Wink

Anyway, I'll send you a mail...

By NYYRIKKI

Enlighted (5776)

Аватар пользователя NYYRIKKI

31-03-2021, 10:05

RvS wrote:

This is 1.5*62 minus the uncertainty of detection (28/2=14) 79 cycles. from that point consistent steps of 62 cycles till bit7.

Yes, but I think the uncertainty is 27 cycles as in case of 28 the edge should be detected... My idea was that since I found no way to reduce "stop bit time" from 80 cycles, I "loaned" the needed cycle from start bit in order to avoid need for second stop bit. (On MSX you actually can, but I was thinking porting the routine to SVI)

By NYYRIKKI

Enlighted (5776)

Аватар пользователя NYYRIKKI

31-03-2021, 10:24

RvS wrote:

A complicating factor is that not all MSX machines run at 3.58 MHz (at least the NMS8220 and NMS8245 run at 3.55MHz) and not all serial interfaces run at the selected frequency, but can deviate around 0.5%

This would make it 61.63 cycles... In absolutely perfect, temperature controlled world it should be 3579545/57600 = 62.15

By RvS

Resident (49)

Аватар пользователя RvS

31-03-2021, 10:41

Smile
I think I solved the 80 cycles part with the help of the 'fast loops' code that I picked up from Grauw.
The resulting code is more complex and less elegant (because I added a 'time-out'), but maybe you can have a look at it:
57600bps routine

By NYYRIKKI

Enlighted (5776)

Аватар пользователя NYYRIKKI

31-03-2021, 14:47

I just realized that if we just offset HL by one, we can easily get rid of the final stop bit payload problem, TADAA!


RXSTARTBIT:             ;WAIT FOR STARTBIT

    IN A,(090H)         ;(12)* | |
    AND E               ;(5)   | | (28)
    JP NZ,RXSTARTBIT    ;(11)  | |
    INC HL              ;(7)   |
    DEC BC              ;(7)   |
    BIT 0,(HL)          ;(14)  | (78)
    LD D,80H            ;(8)   |
                        ;      |
RXBITLOOP:              ;      |
    INC HL		;(7)   | |
    DEC HL		;(7)   | | (62)
    IN A,(090H)         ;(12)   ||
    AND E               ;(5)    ||
    ADD A,255		;(8)    ||
    RR D                ;(10)   ||
    JR NC,RXBITLOOP     ;(13/8) || 
    LD (HL),D		;(8)    | 
    LD A,B              ;(5)    | (72)
    OR C                ;(5)    |
    JP NZ,RXSTARTBIT    ;(11)   |

By NYYRIKKI

Enlighted (5776)

Аватар пользователя NYYRIKKI

02-04-2021, 22:56

So one last time... 5 cycles away we send:

RXSTARTBIT:             ;WAIT FOR STARTBIT

    IN A,(090H)         ;(12)* | |
    AND E               ;(5)   | | (28)
    JP NZ,RXSTARTBIT    ;(11)  | |
    NOP                 ;(5)   |
    CPI	                ;(18)  |
    EX AF,AF'           ;(5)   | (78)
    LD D,80H            ;(8)   |
                        ;      |
RXBITLOOP:              ;      |
    INC HL              ;(7)   | |
    DEC HL              ;(7)   | | (62)
    IN A,(090H)         ;(12)   ||
    AND E               ;(5)    ||
    ADD A,255           ;(8)    ||
    RR D                ;(10)   ||
    JR NC,RXBITLOOP     ;(13/8) || 
    LD (HL),D           ;(8)    | 
    EX AF,AF'           ;(5)    | (67)
    JP PE,RXSTARTBIT    ;(11)   |
Страница 9/11
2 | 3 | 4 | 5 | 6 | 7 | 8 | | 10 | 11