Results 1 to 17 of 17

Thread: Hardware interaction in C

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2002
    Posts
    16

    Hardware interaction in C

    Hi guys,

    I have recently completed my fair knowledge with C.
    I also have alittle idea about BIOS-interrupt,how they can be used [ex:int86()] for manipulation or accessing various hardware information.Hence I want to learn more about this.
    Can anyone recommend good books or links that can explain me or give me an indepth knowlegde of this fascinating thing?
    I will be greatful to you.
    Thanks.
    Bye.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    They're very unhelpful to you because they're now forbidden in most OS's.

    I'd suggest learning some of the services a good OS gives you, direct hardware access in any decent system requires kernel privileges.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2002
    Posts
    16
    Wow parksie that was a quick reply
    But can you please be a more detail about the thing you want to say?I didn't get you properly.
    Sorry.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    What sort of hardware interaction were you thinking of?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Some things:

    Programming those DOS interrupts requires ASM sometimes.

    You cannot get to those interrupts in NT, Win2K, XP. You have to use the OS intervening calls or use libraries, like WMI.

    Code that uses them will be pretty much unusable in about four years when support for the last consumer Windows version (Win ME) goes away.

    Then it'll be like having written code for a prime computer or for DOS 6.0 - there are still people who use these boxes/OS'es, but they don't buy software, except maybe at a flea market.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jul 2002
    Posts
    16
    Originally posted by parksie
    What sort of hardware interaction were you thinking of?
    Like getting the printer status,setting time/date in CMOS chip etc..etc. (BTW, I don't know much more )

    Also if these things are not possible in C (or may get outdated)..then is there any other language that can help me to achieve these sort of things.What do I need to learn?

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    It's not the language you need to worry about.

    For setting the time and date, you use the API of the OS you're running under; that's what it's there for. For printing, that's pretty much OS-dependent as well.

    A lot of this is to shield the programmer from variations in hardware - the OS gives a single coherent interface, and handles the nasty details itself (you're not allowed to do it yourself most of the time).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    It's called protection.

    Do you remember the DOS and Win16 days, when every faulty app would make your PC crash completly so that you would have to reboot?
    Programmers had hard times back then, especially game programmers. I admit I didn't program, I was about 10 years old. But I remember the long setup sessions setting the sound IRQ, testing, failing, setting another IRQ, testing, crashing...

    All of it because programmers had to access hardware directly to work with it.

    Today's operating systems have device dirvers to handle that nasty part. They expose the functionality through their API. No other means of accessing hardware are allowed. Why? Because it makes the system more stable. If an app changes hardware settings and then crashes the OS won't be able to recover from it. If the app only uses the API then the OS can monitor and intercept, or use collected info to better recover from errors.

    The nearest you get to hardware these days is using DirectX, but this too is already 3 layers above hardware.

    All in all you can trust me, it's a good thing. As parksie said you are better off learning the API of windows, MacOS, POSIX and/or some XWin variant. You can then program for windows or for POSIX systems (GNU/Linux, FreeBSD, NetBSD...).
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Jul 2002
    Posts
    16

    So what actually is API?

  10. #10
    Addicted Member HairyDave's Avatar
    Join Date
    Aug 2002
    Location
    Er...I can't remember.
    Posts
    196
    The API is the Application Programming Interface.

    It defines the functions, their parameters and return values etc. For example, the Windows API functions include those to manipulate the registry etc.

    HD

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    An API is more generic than that though, for example Windows has an API, Unix has an API, Photoshop has one, etc.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  12. #12
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You can compare an API to cpu instructions. cpu instructions are the things you can tell the cpu to do. The API functions are the things you can tell some higher level (an operating system or even some application) to do.

    Every OS has it's API, as does every application that can be extended with plug-ins (Photoshop, 3DSMAX, IE, Mozilla, Winamp, just to name VERY few). It's the means by which the application or OS communicates with your code.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Jul 2002
    Posts
    16
    Great
    But from where do I learn it ?

  14. #14
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Which one are you interested in learning?

    What OS, compiler?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Jul 2002
    Posts
    16
    Anyone thats the best, and can help in future.

  16. #16
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Get a Unix system then. Either GNU/Linux or one of the free BSDs (www.openbsd.org, www.freebsd.org, www.netbsd.org).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  17. #17
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Anyone thats the best, and can help in future.
    parksie:
    Get a Unix system then.


    True, but funny anyway.

    But, as anyone can tell you, there's not really a "best" OS. At least not for a programmer. Programming for UNIX gives you a stable system with a good-looking future, portable code and a great open source base for code reviewers or example code. Programming for Windows gives you a LAAAAAAAAAARGE user base.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width