Announcement

Collapse
No announcement yet.

DMA Transfer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • DMA Transfer

    Hi All,

    I am quite new with the PB/DOS. I would need some comments and
    pointers for information how to do DMA Transfers.

    I have an IO-Card which is capable of doing D/A and A/D translations.
    I would like to use DMA for the transfers.

    Any example anyone ? Or where could I get some code and/or
    documents for the further study.

    Best Regards
    Kari Laine
    [email protected]
    Kari Laine

  • #2
    DMA handling needs to be done in assembly language. I don't know of
    any examples for PB/DOS. It's a bit of an arcane topic. Try a web
    search with keywords DMA, ports, interrupts.

    ------------------
    Tom Hanlin
    PowerBASIC Staff

    Comment


    • #3
      Check the manual and see if there are port(s) you can access. If
      so, you may be able to try the INP and OUT instructions.


      ------------------
      There are no atheists in a fox hole or the morning of a math test.
      If my flag offends you, I'll help you pack.

      Comment


      • #4
        Kari,
        it's unusual to use DMA on an I/O card unless that card is specifically designed to handle DMA transfers.
        If it is designed for it that it will probably come with drivers and instructions on how to do it.

        DMA tends to transfer blocks of data with no regard to the timing of individual samples, it simply goes as fast as possible when the memory is free.
        Most A/D or D/A cards require constant sampling which DMA won't give you unless the card has built in buffers to buffer the whole block of data that is DMA'd.

        It's far more common to use interrupts to work such cards. It's also easier, less likely to cause problems in protected mode programs, less likely to cause confilcts with other programs (DMA channelsa re a scarce, non-sharable resource) and, on a modern computer, is probably just as fast as the DMA that DOS can handle.

        Having said all that, if you really want to try DMA out then you need to familiarise yourself with the 8237A DMA controller chip.
        Try http://www.nondot.org/sabre/os/files...rDatasheet.pdf
        Any code you write will need to be in ASM, but PB/DOS can handle that ok.

        Paul.

        Comment


        • #5
          Originally posted by Paul Dixon:
          Kari,

          Having said all that, if you really want to try DMA out then you need to familiarise yourself with the 8237A DMA controller chip.
          Try http://www.nondot.org/sabre/os/files...rDatasheet.pdf
          Any code you write will need to be in ASM, but PB/DOS can handle that ok.

          Paul.
          Thanks for the comments ! The link seems to be dead but I will
          try to search net for the DMA.

          I think I first try to make via an interrupt handler. I think
          I am able to do that. The manual just says DMA is possible but
          doesn't have any example how to do it. It is an old ISA-card
          which I bought used. I will try to locate the manufacturer also.

          Best Regards
          Kari

          Kari Laine

          Comment


          • #6
            Kari,
            the link is fine, I've used it twice now, it points to a 250kbyte PDF document describing the DMA controller chip.

            For interrupt routines in PB/DOS, search the source code forum here, I know there are some examples, I posted them.

            Paul.

            Comment


            • #7
              Originally posted by Paul Dixon:
              Kari,
              the link is fine, I've used it twice now, it points to a 250kbyte PDF document describing the DMA controller chip.

              For interrupt routines in PB/DOS, search the source code forum here, I know there are some examples, I posted them.

              Paul.
              Thanks Paul,

              Yep I tried again and I got it! Now then ... Am I supposed
              to understand something of it

              I will have a look at the source forum. I found the manufacturer
              it is Advantec and downloaded driver for it.

              Thanks

              Best Regards
              Kari


              Kari Laine

              Comment


              • #8
                Kari,
                <<Am I supposed to understand something of it >>

                Of course, it's very straight forward...
                Just ignore the bits that look like they don't relate to programming and remember that everything to do with DMA is done by this chip so it is the thing you need to program to carry out DMA.

                Start with pages 4 -7 which explain what types of DMA there are and what they do.
                Then pages 7-9 tell you where the registers are and what the bits in them do.

                Use IN and OUT instructions to write the registers..
                .. and start off by looking into Interrupts driven stuff, cos it's a whole lot easier!

                But, if you really want to get the hang of DMA then, really, this data sheet is the way to go. There's nothing like understanding how the hardware works to make software easier and better.

                Paul.



                ------------------

                Comment


                • #9

                  On 07 Apr 03, in article "DMA Transfer", Kari Laine wrote:

                  Hello Kari,

                  > I am quite new with the PB/DOS. I would need some comments and
                  > pointers for information how to do DMA Transfers.

                  Here's a little demo for SB/Pro compatible Sound Blaster cards.

                  Code:
                  ' SB 8bit DMA example, (c) 1995 Th.Gohel
                  $COMPILE EXE
                  
                  SampleRate? = 165        '256-(1000000/Frequenz)
                  SBPort%     = &h0220
                  SBIRQ%      = 5
                  DMAKanal%   = 1
                  
                  SHARED SBPort%, SBIRQ%, SampleRate?, DMAKanal%
                  SHARED DMASetMaske%, DMADelMaske%, DMAAdresseReg%
                  SHARED PICSetMaske%, PICDelMaske%
                  SHARED DMAPort%, DMAStart%
                  SHARED DataHigh??, DataLow??, DataLen??
                  SHARED InterruptVektor?, OldInt1CSeg??, OldInt1COff??
                  SHARED NewIntVektorSeg??, NewIntVektorOff??
                  
                  SHARED J%, VocHandle%
                  
                  J% = -1
                  CLS
                  InitSB
                  DMAPlay("demo1.voc")
                  
                      SCREEN 12
                      FOR i% = 1 TO 400
                          CIRCLE (1,1),i%,i%
                          CIRCLE (100,1),i%,i%
                          CIRCLE (1,300),i%,i%
                      NEXT i%
                  
                  DO WHILE J% <> 0 OR LEN(A$) <> 0
                      A$=INKEY$
                  LOOP
                  PRINT "Fertig", J%
                  END
                  
                  FUNCTION InitSB public
                          ! mov ax, SBPort%
                          ! add ax, 6
                          ! mov dx, ax
                          ! mov al, 1
                          ! out dx, al
                          DELAY 0.05
                          ! mov al, 0
                          ! out dx, al
                          ! mov ax, SBPort%
                          ! add ax, &hE
                          ! mov dx, ax
                          ! in  al, dx
                          ! test al, &b10000000
                          ! jz DSPOk
                          PRINT "DSP nicht bereit oder gefunden"
                          EXIT FUNCTION
                          DSPOk:
                          DELAY 0.05
                          ! mov cx, 100
                          DSPReady:
                          ! mov ax, SBPort%
                          ! add ax, &hA
                          ! mov dx, ax
                          ! in  al, dx
                          ! cmp al, &hAA
                          ! jz DSPSpeakerEin
                          ! loop DSPReady
                          DSPSpeakerEin:
                          ! mov ax, SBPort%
                          ! add ax, &hC
                          ! mov dx, ax
                          ! in  al, dx
                          ! test al, &b10000000
                          ! jnz DSPSpeakerEin
                          ! mov ax, SBPort%
                          ! add ax, &hC
                          ! mov dx, ax
                          ! mov al, &hD1
                          ! out dx, al
                          PRINT "Sound Blaster Karte gefunden"
                  END FUNCTION
                  
                  FUNCTION DMAPlay(VocFile$) public
                  
                          VocHandle% = FREEFILE
                          OPEN "B", #1, VocFile$
                              GET$ VocHandle%, 16, Copy$
                              GET$ VocHandle%, 32000, Copy$
                          PRINT "VOC: ";VocHandle%
                          CLOSE VocHandle%
                          DataSeg?? = STRSEG(Copy$)
                          DataOff?? = STRPTR(Copy$)
                          DataLen?? = LEN(Copy$)
                  
                          ' *** Berechnen der linearen 20bit Adresse ***
                  
                          ! mov  dx, DataSeg??
                          ! mov  ax, DataOff??
                          ! mov  bl, dh
                          ! mov  cl, 4
                          ! shr  bl, cl            ;isolate upper 4 bits of segment
                          ! shl  dx, cl            ;make segment into ABS address
                          ! add  ax, dx            ;add the offset and put it in AX
                          ! adc  bl, 0             ;complete the addition
                          ! mov  dh, bl            ;put the PAGE where it goes
                          ! mov  DataHigh??, dh
                          ! mov  DataLow??, ax
                  
                          PRINT HEX$(DataSeg??) ; ":"; HEX$(DataOff??)
                          PRINT HEX$(DataHigh??); ":"; HEX$(DataLow??)
                          PRINT "Länge der Daten: "; DataLen??
                          IF (DataLen??-1) + Datalow?? > 65535 THEN
                              PRINT (DataLen??-1) + DataLow??
                              PRINT "Segment-Überlauf"
                          ELSE
                              PRINT (DataLen??-1) + DataLow??
                              PRINT "Segment ist korrekt"
                          END IF
                  
                          ' InterruptVektor verbiegen
                          InterruptVektor? = &h0d
                          ! call GetInterruptVektor
                          NewIntVektorSeg?? = CODESEG(Aufruf)
                          NewIntVektorOff?? = CODEPTR(Aufruf)
                          ! call SetInterruptVektor
                  
                          ' *** Zum Zugriff auf interne PowerBASIC-Variablen muss unbedingt ***
                          ' *** das Datensegment restauriert werden! ***
                  
                          ! mov ax, ds
                          ! mov DataSeg%, ax
                          PRINT "DS: "; HEX$(DataSeg%)
                          DEF SEG = CODESEG(DatenSegment)
                              POKEI CODEPTR(DatenSegment)+1, DataSeg%
                          DEF SEG
                  
                          ' SHELL "DEBUG"
                          ' EXIT FUNCTION
                  
                          ' DMA - Maskierungsbit für Kanal
                          SELECT CASE DMAKanal%
                              CASE 0: DMASetMaske%   = &b00000100
                                      DMADelMaske%   = &b00000000
                                      DMAAdresseReg% = &h87
                                      DMAPort%       = &h00
                              CASE 1: DMASetMaske%   = &b00000101
                                      DMADelMaske%   = &b00000001
                                      DMAAdresseReg% = &h83
                                      DMAPort%       = &h02
                              CASE 2: DMASetMaske%   = &b00000110
                                      DMADelMaske%   = &b00000010
                                      DMAAdresseReg% = &h81
                                      DMAPort%       = &h04
                              CASE 3: DMASetMaske%   = &b00000111
                                      DMADelMaske%   = &b00000011
                                      DMAAdresseReg% = &h82
                                      DMAPort%       = &h06
                          END SELECT
                          SELECT CASE SBIRQ%
                              CASE 5: PICSetMaske%   = &b00100000
                                      PICDelMaske%   = &b11011111
                              CASE 7: PICSetMaske%   = &b10000000
                                      PICDelMaske%   = &b01111111
                          END SELECT
                  
                          ! mov  al, 0             ; DMA - Master Clear (kompletter Reset)
                          ! out &hD, al
                  
                          ! mov al, DMASetMaske%   ; DMA - Kanal sperren
                          ! out &hA, al
                  
                          ! mov  al, 0             ; DMA - First/Last-FlipFlop löschen
                          ! out &hc, al
                  
                          ! mov al, &b01001001     ; SingleMode, aufsteigend, Read from Memory
                          ! out &hb, al
                  
                          ! mov dx, DMAAdresseReg% ; HighByte der linearen 20bit Adresse
                          ! mov ax, DataHigh??
                          ! out dx, al
                  
                          ! mov dx, DMAPort%       ; DMA - LowByte der 20bit Adresse
                          ! mov ax, DataLow??
                          ! out dx, al
                          ! mov al, ah
                          ! out dx, al
                  
                          ! mov dx, DMAPort%       ; DMA - Länge an DMA-Controller übergeben
                          ! inc dx
                          ! mov ax, DataLen??
                          ! dec ax
                          ! out dx, al
                          ! mov al, ah
                          ! out dx, al
                  
                          ! mov ax, SBPort%        ; DSP - Frequenz setzen
                          ! add ax, &hC
                          ! mov dx, ax
                          ! mov al, &h40
                          ! out dx, al
                          ! call DSPWait
                  
                          ! mov ax, SBPort%        ; DSP - SamplingRate einstellen
                          ! add ax, &hC
                          ! mov dx, ax
                          ! mov al, SampleRate?
                          ! out dx, al
                  
                          ! call DSPWait
                          ! mov ax, SBPort%
                          ! add ax, &hC
                          ! mov dx, ax
                          ! mov al, &h14
                          ! out dx, al
                          ! call dspwait
                  
                          ! mov ax, SBPort%
                          ! add ax, &hC
                          ! mov dx, ax
                          ! mov ax, DataLen??
                          ! dec ax
                          ! out dx, al
                          ! call dspwait
                  
                          ! mov ax, DataLen??
                          ! dec ax
                          ! mov al, ah
                          ! out dx, al
                          ! call dspwait
                  
                          ! mov dx, &hA            ; DMA - Maskierungsbit löschen
                          ! mov al, DMADelMaske%
                          ! out dx, al             ; DMA - Maskregister = Maske freigeben
                  
                          ! in  al, &h21           ; PIC - programmieren
                          ! mov ah, PICDelMaske%   ; BIT des IRQ auf Null setzen um einen IRQ
                          ! and al, ah             ; auslösen zu lassen
                          ! out &h21, al
                          ! mov a?, al
                          print bin$(a?)
                  
                          ! in  al, &h21           ; PIC - programmieren
                          ! mov ah, PICSetMaske%   ; BIT des IRQ wieder setzen um IRQ zu
                          ! or  al, ah             ; sperren
                  '        ! out &h21, al
                  '        ! mov a?, al
                  '        print bin$(a?)
                  
                          EXIT FUNCTION
                  
                          DSPWait:
                          ! mov ax, SBPort%
                          ! add ax, &hC
                          ! mov dx, ax
                          ! in  al, dx
                          ! test al, &b10000000
                          ! jnz DSPWait
                          ! retn
                  
                          SetInterruptVektor:
                          ! push ds
                          ! mov  ah, &h25
                          ! mov  al, InterruptVektor?
                          ! mov  dx, NewIntVektorOff??
                          ! mov  ds, NewIntVektorSeg??
                          ! int  &h21
                          ! pop  ds
                          ! retn
                  
                          GetInterruptVektor:
                          ! push ds
                          ! mov ah, &h35
                          ! mov al, InterruptVektor?
                          ! int &h21
                          ! pop ds
                          ! mov OldInt1CSeg??, es
                          ! mov OldInt1COff??, bx
                          ! retn
                  
                          Aufruf:
                          ! push  ax
                          ! push  bx
                          ! push  cx
                          ! push  dx
                          ! push  si
                          ! push  di
                          ! push  bp
                          ! push  ds
                          ! push  es
                  
                          DatenSegment:
                          ! db &hB8                        ; Restore DataSegment   
                          ! dw &h0000
                          ! mov ds, ax
                  
                  '        SCREEN 12
                          PRINT "VOC: ";VocHandle%
                          J% = 0
                  '        DEF SEG = &hb800
                  '            POKEI 200, &haaaa
                  '        DEF SEG
                  
                          ! mov ax, &hb800                 ; Musiknote auf Screen schreiben
                          ! mov es, ax                     ; damit man sieht ob der IRQ aus-
                          ! mov al, 14                     ; gelöst wurde
                          ! mov bx, 0
                          ! mov es:[bx], al
                          ! inc bx
                          ! mov al, 31
                          ! mov es:[bx], al
                  
                          ! mov   al, &h20                 ; End Of Interrupt (EOI) an
                          ! out &h20, al                   ; PIC senden
                  
                          ! pop   es
                          ! pop   ds
                          ! pop   bp
                          ! pop   di
                          ! pop   si
                          ! pop   dx
                          ! pop   cx
                          ! pop   bx
                          ! pop   ax
                          ! iret
                  
                  END FUNCTION
                  > I have an IO-Card which is capable of doing D/A and A/D translations.
                  > I would like to use DMA for the transfers.

                  Hope it helps.

                  Regards,

                  --------------
                  / h o m a s
                  ------------------
                  email : [email protected] / mailto:[email protected][email protected]</A> (PGP-Key available)
                  www : www.gohel.de / http://pbsound.basicguru.com (PowerBASIC)
                  fax/bbs: +49-30-47300910 (VFC, V34+, X75, ISDN, CCB, 9600-128000bps)
                  ## CrossPoint [XP2] v3.31.003 Beta DOS/16 R/C2478, via PBNEWS v0.18g
                  http://www.gohel.de - http://www.gohel.net - http://www.pbhq.com

                  Comment


                  • #10
                    Originally posted by Thomas Gohel:

                    On 07 Apr 03, in article "DMA Transfer", Kari Laine wrote:

                    Hello Kari,

                    > I am quite new with the PB/DOS. I would need some comments and
                    > pointers for information how to do DMA Transfers.

                    Here's a little demo for SB/Pro compatible Sound Blaster cards.


                    Hope it helps.

                    Regards,

                    --------------
                    / h o m a s
                    Hi Thomas,

                    You call that a little I happen to have SB 16-bit on an
                    machine so I can test this out. Thanks a lot for the code.
                    Now I have the specs Paul pointed out (thanks Paul) and
                    this example code and an assembler book - so it seems I
                    am all set. I also found SB programming info in some German
                    web site, now I just have to find it again...

                    I even found a PC hardware book where is a
                    chapter about DMA, even though a short one. I will dig to it
                    full time at latest on weekend. If I get anything to work
                    I will report back and give code back to be used by others.

                    Do you guys have names for good hardware books and assembler
                    books? I mean books where programming the DMA, UART, USB-controller,
                    TIMER, PCMCIA and such stuff would be expained in many words.
                    As someone uses to say in these forums - "I am not the
                    sharpest tool in the shed".

                    Thanks a lot !

                    Best Regards
                    Kari
                    Kari Laine

                    Comment


                    • #11
                      Originally posted by Kari Laine:
                      Hi Thomas,

                      I also found SB programming info in some German
                      web site, now I just have to find it again...
                      Hi Thomas,

                      it was easy to find It is YOUR site I clicked
                      and now music is playing...

                      Best Regards
                      Kari


                      ------------------
                      Kari Laine
                      Kari Laine

                      Comment


                      • #12
                        Kari,
                        Assembler books, you need the Intel manuals available free from Intel. These are mainly for the CPU in protected mode but most of the instructions are also usable in DOS. Find the 3 volume set here http://www.intel.com/design/pentium4/manuals/245471.htm , volume 2 is the software guide.
                        For DOS programming try "The 8086 8088 primer" by Stephen P Morse (he designed the CPU for Intel), ISBN 0-8104-6255-9 published by Hayden Book Company Inc.

                        For general hardware you should get "The indispensable PC hardware book" ISBN 0-201-87697-3 by Hans-Peter Messmer, published by Addison-Wesley. This book isn't 100% comprehensive, but it covers most of the stuff you need for most of the basic components of the PC including CPUs, Interrupts, DMA, Hard disk, Floppy disk, UART.. but not USB (at least not in the second edition of the book because USB wasn't invented then)
                        You mentioned visiting a German website, if you speak German then this book is the English translation from the original German book "PC-Hardwarebuch".

                        Paul.

                        Comment


                        • #13
                          Originally posted by Paul Dixon:
                          Kari,
                          Assembler books, you need the Intel manuals available free from Intel. These are mainly for the CPU in protected mode but most of the instructions are also usable in DOS. Find the 3 volume set here http://www.intel.com/design/pentium4/manuals/245471.htm , volume 2 is the software guide.
                          For DOS programming try "The 8086 8088 primer" by Stephen P Morse (he designed the CPU for Intel), ISBN 0-8104-6255-9 published by Hayden Book Company Inc.

                          For general hardware you should get "The indispensable PC hardware book" ISBN 0-201-87697-3 by Hans-Peter Messmer, published by Addison-Wesley. This book isn't 100% comprehensive, but it covers most of the stuff you need for most of the basic components of the PC including CPUs, Interrupts, DMA, Hard disk, Floppy disk, UART.. but not USB (at least not in the second edition of the book because USB wasn't invented then)
                          You mentioned visiting a German website, if you speak German then this book is the English translation from the original German book "PC-Hardwarebuch".

                          Paul.
                          Hi Paul,

                          Thanks, downloaded (big) files from Intel. I have one 8086 book
                          already but the The Indispensable PC Hardware book seems interesting.
                          I will order that. Yep it was Thomas website I remembered having
                          a lot of SoundBlaster stuff. But I didn't find any SB programming
                          info there. I also visited Creatives web-site and there were
                          no programming info there either. So if Thomas reads this, could
                          you tell me where to obtain that information - please. I am not
                          going to compete with your SB-libraries - that should be obvious
                          from the level of the messages I post

                          No it's pity my Deutch is quite bad. Read two years it in school
                          long time ago. Newer used it much. I can understand if I read
                          easy text.

                          It is 01:30 at night here in Finland - I goto to sleep now.

                          Thanks again for the good information.

                          Best Regards
                          Kari

                          Kari Laine

                          Comment


                          • #14

                            On 08 Apr 03, in article "Re: DMA Transfer", Kari Laine wrote:

                            Hello Kari,

                            > Thanks, downloaded (big) files from Intel. I have one 8086 book
                            > already but the The Indispensable PC Hardware book seems interesting.
                            > I will order that. Yep it was Thomas website I remembered having
                            > a lot of SoundBlaster stuff. But I didn't find any SB programming
                            > info there. I also visited Creatives web-site and there were
                            > no programming info there either. So if Thomas reads this, could
                            > you tell me where to obtain that information - please. I am not
                            > going to compete with your SB-libraries - that should be obvious
                            > from the level of the messages I post :-)
                            >
                            > No it's pity my Deutch is quite bad. Read two years it in school
                            > long time ago. Newer used it much. I can understand if I read
                            > easy text.

                            Na dann ... :-)

                            Das meiste zum Thema "DMA" bzw. "Sound Blaster" habe ich aus
                            deutscher Literatur: PC-Intern, PC-Underground, SoundBlaster
                            Profi Buch, etc. oder aus dem SDK von Creative Labs.

                            Allerdings gibt es zwei englische FAQs zur DMA-Programmierung,
                            die ich noch auf Hardisk habe, vielleicht interessierts Dich?

                            Regards,

                            --------------
                            / h o m a s
                            ------------------
                            email : [email protected] / mailto:[email protected][email protected]</A> (PGP-Key available)
                            www : www.gohel.de / http://pbsound.basicguru.com (PowerBASIC)
                            fax/bbs: +49-30-47300910 (VFC, V34+, X75, ISDN, CCB, 9600-128000bps)
                            ## CrossPoint [XP2] v3.31.003 Beta DOS/16 R/C2478, via PBNEWS v0.18g
                            http://www.gohel.de - http://www.gohel.net - http://www.pbhq.com

                            Comment


                            • #15
                              Originally posted by Thomas Gohel:

                              On 08 Apr 03, in article "Re: DMA Transfer", Kari Laine wrote:

                              Hello Kari,


                              Na dann ... :-)

                              Das meiste zum Thema "DMA" bzw. "Sound Blaster" habe ich aus
                              deutscher Literatur: PC-Intern, PC-Underground, SoundBlaster
                              Profi Buch, etc. oder aus dem SDK von Creative Labs.

                              Allerdings gibt es zwei englische FAQs zur DMA-Programmierung,
                              die ich noch auf Hardisk habe, vielleicht interessierts Dich?

                              Regards,

                              --------------
                              / h o m a s
                              Now you are testing me
                              Sorry I answer in English.
                              That SoundBlaster Profi Buch sounds interesting. Is it still
                              available from somewhere? Is that SDK available for download
                              or must I order for it? Could you also send those FAQs to me
                              to [email protected] And please send whatever
                              electronishes material you have concerning DMA and ASM.

                              Thanks A LOT for your time !

                              Best Regards
                              Kari Laine
                              [email protected]
                              Kari Laine

                              Comment

                              Working...
                              X