⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 video.cpp

📁 Jazmyn is a 32-bit, protected mode, multitasking OS which runs on i386 & above CPU`s. Its complete
💻 CPP
字号:
#define uchar  unsigned char
#define uint   unsigned int
#define ushort unsigned short
#define ulong  unsigned long

#include "video.h"

void* memset(void* _b,ushort _v,int _n)
{
        __asm__ __volatile__("cld;rep stosw"::"a" (_v),"D" (_b),"c" (_n));
        return _b;
}

void* memmove(void* _d,void* _s,int _n)
{
        if(_d<_s) __asm__ __volatile__("cld;rep movsb"::"c" (_n),"S" (_s), "D" (_d));
        else __asm__ __volatile__("std;rep movsb"::"c" (_n),"S" ((int)_s+_n-1),"D" ((int)_d+_n-1));
        return _d;
}

VideoMemory::VideoMemory()
{
        m_Row = 0;
        m_Col = 0;
        m_VideoMemory = (unsigned short *) 0xB8000;     //0xB8000 is videomemory
        Write("video\n");
}

void VideoMemory::init_video()
{
        Write("Video driver installed    :Video memory base -> 0xB8000\n",2);
}
void VideoMemory::Write(char *cp,short attr)
{
        char *str = cp,*ch;
        for(ch=str;*ch;ch++)
        {
                char newline = 0;       //flag to indicate a newline i,e '\n'
                if( m_Col >= 80 )       //if exceeds width (80 chars), 
                {                       //goto next line
                        m_Row += 80;
                        m_Col = 0;
                }
                if( *ch == '\n' )       //if '\n' ,goto next line
                {
                        m_Row += 80;
                        m_Col = 0;
                        newline = 1;
                }
                if( m_Row >= 80*25 )    //if exceeds the screen limit, scroll
                {
                        Scroll();
                }
                /* 
			 for writing to videomemory, each char requires two bytes:

                   1. actual char
                   2. attribute byte

                   for eg: 0xB8000 = 'A' --> actual char
                           0xB8001 = 0x7 --> attribute byte

                   0x7 indicate white color
                */
                if(!newline)           
                {
                        m_VideoMemory[m_Row + m_Col] = (unsigned char)*ch | (attr<<8);
                        m_Col++;
                }
                appendcursor();         //update the cursor
        }
}

void VideoMemory::putch(char ch,short attr)
{
        char newline = 0;
        char bkspace = 0;
        if( m_Col >= 80 )
        {
                m_Row += 80;
                m_Col = 0;      
        }
        if( ch == '\n' )
        {
                m_Row += 80;
                m_Col = 0;
                newline = 1;
        }
        if( ch == '\b' )        //if backspace, move back one position
        {
                m_Col--;
                ch = ' ';
                bkspace = 1;
        }
        if( m_Row >= 80*25 )
        {
                Scroll();
        }
        if(!newline)
        {
                m_VideoMemory[m_Row + m_Col] = (unsigned char)ch | (attr<<8);
                if(!bkspace)
                        m_Col++;
        }
        appendcursor();
}
                

void VideoMemory::Scroll()                                                 
{
        int r,c;
        for(r=0;r<24;r++ )      //move all the lines up one row
        {
                for(c=0;c<80;c++)
                {
                        m_VideoMemory[r*80+c] = m_VideoMemory[(r+1)*80+c];
                }
        }
        for(c=0;c<80;c++)       //make last line blank
        {
                m_VideoMemory[r*80+c] = (unsigned char)' ' | 0x0700;
        }

        m_Row = 80*24;
        m_Col = 0;
}
                
                        
void VideoMemory::clrscr()
{
        memset(m_VideoMemory,(' '|0x0700),80*25);
        m_Row = 0;
        m_Col = 0;
        appendcursor();
}

void VideoMemory::gotoxy(int x,int y)
{
        m_Row = y * 80;
        m_Col = x;
}

int VideoMemory::getrow()
{
        return (int) m_Row / 80;
}

int VideoMemory::getcol()
{
        return m_Col;
}

void VideoMemory::appendcursor()
{
}                               

void VideoMemory::displaynum(uint num,int base)
{
        char arr[20];
        int i = 0;
        if(num == 0)            //if num=0, display 0 & return
        {
                putch('0');
                return;
        }
        while(num > 0)          //store individual nums in array
        {
                arr[i++] = num % base;
                num = num / base;
        }
        i--;
        while(i >= 0)           //display nums stored in array
        {
                if(arr[i] > 9)
                        arr[i] = arr[i] + 7; //for hex nums exceeding 9
                putch(arr[i--] + '0');
        }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -