Uhrzeit anzeigen



  • Hallo,

    hat jemand ein Codebeispiel, wie man die Zeit anzeigen kann, ich meine eine bios-funktion, die ich in mein os einbinden könnte.also die zeit,die im bios eingestellt ist.Danke



  • Hi,

    hier was zum cmos auslesen:

    /*--------------------------------------------------------------------------------------------------
    File Name : cmos.h      Purpose : Declarations for accessing CMOS
    --------------------------------------------------------------------------------------------------*/
    
    #ifndef __cmos_h__
    #define __cmos_h__
    
    typedef struct time_str_tag
    {
    	int hour;
    	int minute;
    	int second;
    }time_stamp;
    
    typedef struct date_str_tag
    {
    	int year;
    	int month;
    	int date;
    	int day;
    }date_stamp;
    
    class Cmos
    {
    	public:
    		int read(unsigned char);
    		int read_bcd(unsigned char address);
    		void time(time_stamp &);
    		void date(date_stamp &);
    
    	private:
    		bool busy();
    		int bcd2bin(unsigned char);
    };
    
    #define CMOS_OUT_PORT 0x70
    #define CMOS_IN_PORT 0x71
    
    #define SECOND 0x00
    #define MINUTE 0x02
    #define HOUR 0x04
    #define DAY 0x06
    #define DATE 0x07
    #define MONTH 0x08
    #define YEAR 0x09
    #define STATUS_A 0x0A
    #define STATUS_B 0x0B
    #define STATUS_C 0x0C
    #define STATUS_D 0x0D
    
    #endif
    

    und nun die Cpp:

    #include "cmos.h"
    
    int Cmos::read(unsigned char address)		//reads a byte out of the cmos
    {
    	while(busy());
    	outportb(CMOS_OUT_PORT, 0x80|address);	//Use 0x80 coz we need to disable NMI
    	return inportb(CMOS_IN_PORT);
    }
    
    int Cmos::read_bcd(unsigned char address)
    {
    	return bcd2bin(read(address));
    }
    
    bool Cmos::busy()							//checks if the cmos is ready
    {
    	outportb(CMOS_OUT_PORT, 0x80|STATUS_A);
    	if(inportb(CMOS_IN_PORT) & 0x80)		//Bit 7 is set in Status Register A if Clock is busy
    		return true;
    	else
    		return false;
    }
    
    int Cmos::bcd2bin(unsigned char bcd)		//binary coded decimal to binary converter
    {
    	return((bcd & 0xF) + ((bcd >> 4) * 10));
    }
    
    void Cmos::time(time_stamp &time)			//gets the time from the cmos
    {
    	time.second = read_bcd(SECOND);
    	time.minute = read_bcd(MINUTE);
    	time.hour   = read_bcd(HOUR);
    }
    
    void Cmos::date(date_stamp &date)			//gets the date from the cmos
    {
    	date.year  = (read_bcd(0x32) * 100) + read_bcd(YEAR);	//0x32 is the century number in the cmos
    	date.month = read_bcd(MONTH);
    	date.date  = read_bcd(DATE);
    	date.day   = read_bcd(DAY);
    }
    

    Ich hoffe das reicht 😉



  • danke, aber ich wollts in assembler-code (x86)



  • Hi,

    okay nur noch die paar Funktionen dann solltest du echt keine Probleme haben das auf x86 umzuschreiben 😉

    inline static unsigned char inportb(int port)
    {
    	register unsigned char r;
    
       	asm volatile
    	( 
    		"inb %%dx, %%al\n\t" 
    		: "=a" (r) 
    		: "d" (port)
    	);
    
       	return (r);
    }
    
    inline static void outportb(int port, unsigned char data)
    {
    	asm volatile
    	(
    		"outb %%al, %%dx\n\t" 
    		:
    		: "a" (data), "d" (port)
    	);
    }
    
    inline static unsigned short inportw(int port)
    {
    	register unsigned short r;
    
       	asm volatile
    	(
    		"inw %%dx, %%ax\n\t" 
    		: "=a" (r) 
    		: "d" (port)
    	);
    
       	return (r);
    }
    
    inline static void outportw(int port, unsigned short data)
    {
    	asm volatile
    	(
    		"outw %%ax, %%dx\n\t" 
    		:
    		: "a" (data), "d" (port)
    	);
    }
    

    Alles Assembler 😉 funzt super unter GCC



  • hi,

    du kannst das ganze auch über
    BIOS-Interrupt 1Ah (Funktion 0x02) machen, solange dein OS im Real-Mode arbeitet (oder im Virtual86-Mode).


Anmelden zum Antworten