Page 1 of 1

Questions about Device IDs and more

Posted: Fri Aug 12, 2005 12:21 pm
by OSMAN
Hi!

I am developing an Operating System in C and little bit in asm.
Now I can acces the video memory, print to the screen, read the keyboard scancode (from 0x60 DevID). But, the question is: What are the other (so called) DeviceID values (in hex) of -for instance- Speaker (soundcard), mouse, hard drive components and floppy drive components?
Are there any more important hardware needed memory areas plus the videomemory?
(Don't have to answer but how do I set all the 16 colors avaible for Voodoo3 in text mode? [I'd like to see the answer as _inline_assembly in C])

Thanks for any help!

Re:Questions about Device IDs and more

Posted: Fri Aug 12, 2005 1:14 pm
by NotTheCHEAT
You mean the ports? Well, it depends. It's very complicated, because each PC is setup differently, and may have different ports. Some things have fixed ports, but you never know.

A PS/2 mouse uses the same ports as the keyboard - you have to send a special code before each command, so it knows the command is for the mouse, not the keyboard. See this: http://www.computer-engineering.org/ps2mouse/ for more details.
A serial mouse uses the serial ports, and usually the same protocol (except you don't have to send the special code first). The serial UART ports bases (COM1, COM2, COM3, COM4): 3F8h, 2F8h, 3E8h, 2E8h. The last two are subject to differences in systems (OS/2 have up to 8 serial ports, and only the first two are the same as DOS/Windows). They also have an IRQ, #3 is shared between COM2 and COM4, and #4 between COM1 and COM3.

The floppy uses several ports. The primary floppy controller uses port 3F0h, while the secondary controller (if there is one) uses 370h. Usually. If you have a SCSI or USB floppy then it gets a lot more complicated, and in that case I can't help you. You can have up to two floppies.

The hard disk depends on a lot. If it's an IDE hard disk, the primary controller usually uses registers starting at 170h (like the floppy, it uses several ports; the first port is called the base address) and the secondary controller starts at 1F0h. Each controller supports up to two disks, so you have up to 4.
There are also other things, like ATAPI and SCSI, which I know very little about. I don't think they use fixed addresses, I think you should scan the PCI config space for those.

The speaker/soundcard depends. If you just mean the PC speaker, which virtually every PC has built in, the one that old DOS games used for their sound, which consisted of little beeps, that uses two ports, a keyboard port and the PIT channel 2. The lower two bits of port 61h must both be set for PIT channel 2 to connect to the speaker. You program the PIT, telling it the frequency to emit, and with bits 0 and 1 of port 61h set, you'll have sound. PCGPE (PC Game Programmers Encyclopedia) has a speaker.txt which explains how this works.
This is a very primitive sound system, not suitable for a modern OS. Programming modern sound cards is complex, and you probably shouldn't do it until you have done a lot of other thing first (soundcards are less important than most other things). Some documents on sound cards are here: http://www.osdever.net/cottontail/#Sound

You need to learn about DMA (Direct Memory Access), the PIT (Programmable Interval Timer), the PIC (Programmable Interrupt Controller), and others to make many of these things work. You can learn about these things, or download documents about them, at:

http://www.osdever.net/documents.php?cat=0&sort=1
http://www.osdever.net/cottontail/
http://www.geocities.com/SiliconValley/2151/pcgpe.html

and of course, our very own

http://www.Mega-Tokyo.com/osfaq2/index.php

;-) good luck!

Re:Questions about Device IDs and more

Posted: Fri Aug 12, 2005 2:55 pm
by Dex4u

Code: Select all

__declspec(naked) int test()
        {
            int x, y, z; 

            _asm
            {   push BP 
                mov BP,SP
                sub SP,__LOCAL_SIZE 
                mov BX,__LOCAL_SIZE[BP]
                mov BX,__LOCAL_SIZE+2[BP] 
                mov AX,__LOCAL_SIZE
                mov AX,__LOCAL_SIZE+2 
;Here is my answer to your ?? _inline _assmbly in C
;try this link   

http://homepage.swissonline.ch/tinyasm/v3.htm

Code: Select all

            }
            _AX = x + y + z; 
            _asm
            { 
                mov SP,BP
                pop BP 
                ret
            } 
        } 

Re:Questions about Device IDs and more

Posted: Fri Aug 12, 2005 2:58 pm
by DennisCGc
Hi,

You do realize that ATAPI uses the IDE controller? So it still has the same ports as an IDE harddisk. To be more specific, the fixed ports of the IDE controllers are called legacy mode, IIRC. (To keep it just one standard, unlike SCSI)

Oh, one thing, 1F0h is for the primary controller, and 170h for the secondary controller. Please note that the above I/O ports are base ports, as mentioned before. For information you should read that ATA specs @ www.t13.org

_That asm code (declspec(naked) etc...)

Posted: Sat Aug 13, 2005 2:42 am
by OSMAN
What does that asm code actually do to Voodoo3?
And how can I paste it into my C-code, where every asm-functions' formula's like:
///////////////////////////////
inline datatype function(args)
{
asm volatile("asm code");
};
///////////////////////////////

Will I have to specify those long VARIABLE_NAMES not seen in anywhere else in the code?

(My broblem is that red, green and some other colors are replaced with black in text mode.)

Re:Questions about Device IDs and more

Posted: Sat Aug 13, 2005 7:21 am
by Dex4u
It was a joke, you asked for the answer in inline assembly C, so i give you the link that may help you in the middle of inline_assembly C.
The code is random inline C code, do not try to use it.

Re:Questions about Device IDs and more

Posted: Sat Aug 13, 2005 12:56 pm
by Cjmovie
As for sound, I beleive BOCHS can emulate a 16-bit SoundBlaster Interface - Information on programming it can be found at http://www.gamedev.net/reference/list.a ... yid=80#142

Check "Programming the 16 bit Sound Blaster".

There's also a graphics section if you look for the link right above the stuff for sound :).

Re:Questions about Device IDs and more

Posted: Sat Aug 13, 2005 3:59 pm
by OSMAN
I was looking for the ports in form 0xXX (/hex). At the beginning I need the keyboard port which tells is a key pressed or not. [Not 0x60]. What's the hex number of that port?

Re:Questions about Device IDs and more

Posted: Sat Aug 13, 2005 4:56 pm
by QuiTeVexat
I'm not sure if there's a port that does this, but even if there is, one doesn't typically poll the keyboard. Usually, you'll wait for the keyboard IRQ, and in the IRQ handler you'll read the scancode.

Re:Questions about Device IDs and more

Posted: Sun Aug 14, 2005 12:04 am
by Cjmovie
YOU have to write code that will take scancodes from (yes) 0x60, then YOUR code will keep track of what is pressed. There is no easy way in systems programming :).

Re:Questions about Device IDs and more

Posted: Sun Aug 14, 2005 5:57 am
by Dex4u
Heres a quick and dirty way.

Code: Select all

xor   eax,eax  ;0 eax
in    al,60h   ;get the scan code
cmp   al,0x50  ;Test ArrowDown key
jne   NoKey50h ;if not jump to lable

; If yes, Do something here

NoKey50h:
cmp   al,0x48 ;Test ArrowUp key
 jne   NoKey48h  ;if not jump to lable

; If yes, Do something here

NoKey48h: