tty.c
ubixos/tty.h
ubixos/kpanic.h
ubixos/spinlock.h
lib/kprintf.h
lib/kmalloc.h
sys/io.h
string.h
ubixos/kpanic.h
ubixos/spinlock.h
src/sys/kernel/tty.c
ubixos/types.h
sys/_types.h
string.h
lib/kmalloc.h
lib/kprintf.h
ubixos/tty.h
sys/io.h
int int tty_change (uInt16 tty) tty_change uInt16 tty kpanic memcpy outportByte terms tty_termNode::tty_buffer tty_foreground TTY_MAX_TERMS tty_termNode::tty_pointer tty_termNode::tty_x tty_termNode::tty_y keyboardHandler
tty_term * tty_term* tty_find (uInt16 tty) tty_find uInt16 tty terms execFile kprint systemTask
int int tty_init () tty_init inportByte kmalloc kpanic kprintf outportByte terms tty_termNode::tty_buffer tty_termNode::tty_colour tty_foreground TTY_MAX_TERMS tty_termNode::tty_pointer tty_termNode::tty_x tty_termNode::tty_y
int int tty_print (char *string, tty_term *term) tty_print char * string tty_term * term outportByte spinLock spinUnlock tty_termNode::tty_colour tty_foreground tty_termNode::tty_pointer tty_spinLock tty_termNode::tty_x tty_termNode::tty_y x20 kprint sysFwrite
tty_term * tty_term* terms terms 0x0 tty_change tty_find tty_init
tty_term * tty_term* tty_foreground tty_foreground 0x0 backSpace getch keyboardHandler kpanic kprint sysFgetc tty_change tty_init tty_print
spinLock_t spinLock_t tty_spinLock tty_spinLock SPIN_LOCK_INITIALIZER tty_print

    /*****************************************************************************************
    Copyright(c)2002-2004TheUbixOSProject
    Allrightsreserved.

    Redistributionanduseinsourceandbinaryforms,withorwithoutmodification,are
    permittedprovidedthatthefollowingconditionsaremet:

    Redistributionsofsourcecodemustretaintheabovecopyrightnotice,thislistof
    conditions,thefollowingdisclaimerandthelistofauthors.Redistributionsinbinary
    formmustreproducetheabovecopyrightnotice,thislistofconditions,thefollowing
    disclaimerandthelistofauthorsinthedocumentationand/orothermaterialsprovided
    withthedistribution.NeitherthenameoftheUbixOSProjectnorthenamesofits
    contributorsmaybeusedtoendorseorpromoteproductsderivedfromthissoftware
    withoutspecificpriorwrittenpermission.

    THISSOFTWAREISPROVIDEDBYTHECOPYRIGHTHOLDERSANDCONTRIBUTORS"ASIS"ANDANY
    EXPRESSORIMPLIEDWARRANTIES,INCLUDING,BUTNOTLIMITEDTO,THEIMPLIEDWARRANTIESOF
    MERCHANTABILITYANDFITNESSFORAPARTICULARPURPOSEAREDISCLAIMED.INNOEVENTSHALL
    THECOPYRIGHTOWNERORCONTRIBUTORSBELIABLEFORANYDIRECT,INDIRECT,INCIDENTAL,
    SPECIAL,EXEMPLARY,ORCONSEQUENTIALDAMAGES(INCLUDING,BUTNOTLIMITEDTO,PROCUREMENT
    OFSUBSTITUTEGOODSORSERVICES;LOSSOFUSE,DATA,ORPROFITS;ORBUSINESSINTERRUPTION)
    HOWEVERCAUSEDANDONANYTHEORYOFLIABILITY,WHETHERINCONTRACT,STRICTLIABILITY,OR
    TORT(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAYOUTOFTHEUSEOFTHIS
    SOFTWARE,EVENIFADVISEDOFTHEPOSSIBILITYOFSUCHDAMAGE.

    $Id: tty_8c.xml 88 2016-01-12 00:11:29Z reddawg $

    *****************************************************************************************/

    #include<ubixos/tty.h>
    #include<ubixos/kpanic.h>
    #include<ubixos/spinlock.h>
    #include<lib/kprintf.h>
    #include<lib/kmalloc.h>
    #include<sys/io.h>
    #include<string.h>

    statictty_term*terms=0x0;
    tty_term*tty_foreground=0x0;
    staticspinLock_ttty_spinLock=SPIN_LOCK_INITIALIZER;

    inttty_init(){
    inti=0x0;

    /*Allocatememoryforterminals*/
    terms=(tty_term*)kmalloc(sizeof(tty_term)*TTY_MAX_TERMS);
    if(terms==0x0)
    kpanic("tty_init:Failedtoallocatememory.File:%s,Line:%i\n",__FILE__,__LINE__);

    /*Setupalldefaultterminalinformation*/
    for(i=0;i<TTY_MAX_TERMS;i++){
    terms[i].tty_buffer=(char*)kmalloc(80*60*2);
    if(terms[i].tty_buffer==0x0)
    kpanic("tty_init:Failedtoallocatebuffermemory.File:%s,Line:%i\n",__FILE__,__LINE__);

    terms[i].tty_pointer=terms[i].tty_buffer;/*Setupttypointertointernalbuffer*/
    terms[i].tty_x=0x0;/*SetupdefaultXposition*/
    terms[i].tty_y=0x0;/*SetupdefaultYposition*/
    terms[i].tty_colour=0x0A+i;/*Setupdefaultttytextcolour*/
    }

    /*Readtty0currentposition(tomigratefromkprintf).*/
    outportByte(0x3D4,0x0e);
    terms[0].tty_y=inportByte(0x3D5);
    outportByte(0x3D4,0x0f);
    terms[0].tty_x=inportByte(0x3D5);

    /*Setuppointerfortheforegroundtty*/
    tty_foreground=&terms[0];

    /*Setuptheforegroundttysinformation*/
    tty_foreground->tty_pointer=(char*)0xB8000;

    /*Returntoletkernelknowinitializationiscomplete*/
    kprintf("tty0-Initialized\n");

    return(0x0);
    }

    /*
    Thiswillchangethespecifiedtty.Itultimatelycopiesthescreen
    totheforegroundbuffercopiesthenewttysbuffertothescreenand
    adjustsacouplepointersandwearegoodtogo.
    */
    inttty_change(uInt16tty){

    if(tty>TTY_MAX_TERMS)
    kpanic("Error:Changingtoaninvalidtty.File:%s,Line:%i\n",__FILE__,__LINE__);

    /*Copydisplaybuffertottybuffer*/
    memcpy(tty_foreground->tty_buffer,(char*)0xB8000,(80*60*2));

    /*Copynewttybuffertodisplaybuffer*/
    memcpy((char*)0xB8000,terms[tty].tty_buffer,(80*60*2));

    /*
    Setthetty_pointertotheinternalbuffersoIcancontinue
    writingtowhatitbelievesisthescreen
    */
    tty_foreground->tty_pointer=tty_foreground->tty_buffer;

    terms[tty].tty_pointer=(char*)0xB8000;

    /*setnewforegroundtty*/
    tty_foreground=&terms[tty];

    /*Adjustcursorwhenwechangeconsoles*/
    outportByte(0x3D4,0x0F);
    outportByte(0x3D5,tty_foreground->tty_x);
    outportByte(0x3D4,0x0E);
    outportByte(0x3D5,tty_foreground->tty_y);

    return(0x0);
    }

    inttty_print(char*string,tty_term*term){
    unsignedintbufferOffset=0x0,character=0x0,i=0x0;
    spinLock(&tty_spinLock);

    /*WeNeedToGetTheYPosition*/
    bufferOffset=term->tty_y;
    bufferOffset<<=8;

    /*ThenWeNeedToAddTheXPosition*/
    bufferOffset+=term->tty_x;
    bufferOffset<<=1;

    while((character=*string++)){
    switch(character){
    case'\n':
    bufferOffset=(bufferOffset/160)*160+160;
    break;
    default:
    term->tty_pointer[bufferOffset++]=character;
    term->tty_pointer[bufferOffset++]=term->tty_colour;
    break;
    }/*switch*/

    /*CheckToSeeIfWeAreOutOfBounds*/
    if(bufferOffset>=160*25){
    for(i=0;i<160*24;i++){
    term->tty_pointer[i]=term->tty_pointer[i+160];
    }
    for(i=0;i<80;i++){
    term->tty_pointer[(160*24)+(i*2)]=0x20;
    term->tty_pointer[(160*24)+(i*2)+1]=term->tty_colour;
    }
    bufferOffset-=160;
    }
    }

    bufferOffset>>=1;/*Setthenewcursorposition*/
    term->tty_x=(bufferOffset&0xFF);
    term->tty_y=(bufferOffset>>0x8);

    if(term==tty_foreground){
    outportByte(0x3D4,0x0f);
    outportByte(0x3D5,term->tty_x);
    outportByte(0x3D4,0x0e);
    outportByte(0x3D5,term->tty_y);
    }

    spinUnlock(&tty_spinLock);

    return(0x0);
    }

    tty_term*tty_find(uInt16tty){
    return(&terms[tty]);
    }

    /***
    END
    ***/