byte huge *getdump (long *size,void (* func)(double)) /*********** * Describe : принять дамп памяти прибора в память ЭВМ * Params : word *size - размер принятых данных (в байтах), меньше чем * : размер выделенной памяти, так как он выровнен * : на границу 1024 байта * : PFV func - функция для отображения считывания, ей * : передаем процент считанной информации * Return : byte huge* - указатель на буфер, куда записаны данные * Call : input,waitstart,setaddr,getKbyte,bioscom ***********/ { /* i-текущий адрес */ unsigned long volume,i_long; uint i=0,Imax=1024; /* Imax-макс. адрес */ byte empty,bufer[1024]; /* */ int err=0,rpt=0; /* */ byte huge *ppm=NULL,huge *cur=NULL; /* указатель на буфер */ // считываем базовый адрес порта base_addr = *((unsigned far *)((unsigned far *)0x00400000L+connect_port)); if (base_addr==0) // СОМ1 в 40:00 СОМ2 в 42:00 {printf("\nCOM-%d is absent!",connect_port); return 0; } // bioscom (0,SETTINGS,connect_port); /* инициализируем COM */ outportb (base_addr+3,0x83); // 8byt 1stop N outportb (base_addr,12); // скорость обмена 115200/12=9600 outportb (base_addr+1,0); outportb (base_addr+3,0x03); // конец установки скорости empty = inportb (base_addr+4); outportb (base_addr+4,0); // Запрет прерывания от порта for (i_long=0L;i_long<Imax;i_long+=512L,cur=(byte huge *)cur+1024,i=(uint)i_long) { if (func!=NULL) /* */ func ((double)((double)i_long/(double)Imax)); /* рисуем прогресс */ sleep (1); do /* */ { /* */ setaddr(i); /* посылаем адрес начала */ err=waitstart(); /* ждем строки "STRT" */ if (err==0) /* если не ошибка то */ err=input(&empty); /* принимаем пустой байт */ if (err==0) /* если не ошибка и если */ if (i==0) /* первый Кбайт то */ err=getKbyte(bufer); /* принимаем в буфер */ else /* иначе */ { err=getKbyte(cur); /* принимаем в назначение */ if (*bufer!=*ppm) { printf ("\n There is problem, count = %u",(uint)i); abort (); } } if (err != 0) /* если ошибка */ { /* */ rpt++; /* число повторов */ if (rpt>REPEATS) /* */ { /* */ if (ppm!=NULL) /* освобождаем память */ farfree ((byte far *)ppm); /* если выделена */ printf("\nCommunication ERROR %X",(unsigned)err); return (NULL); /* возвращаем ошибка */ } /* */ } /* */ } /* */ while (err!=0); /* */ /* */ if (i==0) /* если первый Кбайт */ { /* то */ Imax = (uint)bufer[8]+bufer[9]*256; /* вычисляем Imax */ *size = (long)Imax*2L; /* размер в байтах */ volume = (unsigned long)(*size)+1024; /* выделяем 128 Кбайт */ ppm=(byte huge*) farcalloc(volume,sizeof(byte));/* выделяем память */ cur = ppm; if (ppm==NULL) { printf ("\n Imax = %u, size = %ld",Imax,(*size)); printf ("\n No enough memory! Function GETDUMP. "); printf ("\n %ul bytes free. ",farcoreleft()); abort (); } reportmemory(getmaxx(),getmaxy()-textheight("X")-5); memcpy ((byte *)ppm,bufer,1024); /* копируем из буфера */ } /* */ } /* */ if (func!=NULL) /* */ func ((double)1.0); /* рисуем прогресс */ return ((byte huge*) ppm); /* */ } /* */
void nosound() { unsigned short tmp = (inportb(0x61) & 0xFC); outportb(0x61, tmp); }
irqreturn_t nic_8019_rx(int irq, void *dev_id, struct pt_regs *regs) { u8 RxPageBeg, RxPageEnd; u8 RxNextPage; u8 RxStatus; u16 *data,temp; u16 i, RxLength,RxLen; struct sk_buff *skb; struct net_device *dev = (struct net_device *) dev_id; struct nic_8019_priv *priv = (struct nic_8019_priv *) dev->priv; TRACE("TX/RX Interupt!\n"); spin_lock(&priv->lock); SetRegPage(0); outportb(BNRY, rBNRY); //??? RxStatus = inportb(ISR); if (RxStatus & 2) { outportb(ISR, 0x2); //clr TX interupt priv->stats.tx_packets++; TRACE("transmit one packet complete!\n"); } if (RxStatus & 1) { TRACE("Receivex packet....\n"); outportb(ISR, 0x1); //clr Rx interupt SetRegPage(1); RxPageEnd = inportb(CURR); SetRegPage(0); RxPageBeg = rBNRY+1; if(RxPageBeg>=RPSTOP) RxPageBeg = RPSTART; outportb(BaseAddr, 0x22); // stop remote dma //outport(RSAR0, RxPageBeg<<8); //outport(RBCR0, 256); outportb(RSAR0, 0); outportb(RSAR1, RxPageBeg); outportb(RBCR0, 4); outportb(RBCR1, 0); outportb(BaseAddr, 0xa); #ifdef RTL8019_OP_16 temp = inportw(RWPORT); RxNextPage = temp>>8; RxStatus = temp&0xff; RxLength = inportw(RWPORT); #else RxStatus = inportb(RWPORT); RxNextPage = inportb(RWPORT); RxLength = inportb(RWPORT); RxLength |= inportb(RWPORT)<<8; #endif TRACE("\nRxBeg = %x, RxEnd = %x, nextpage = %x, size = %i\n", RxPageBeg, RxPageEnd, RxNextPage, RxLength); RxLength -= 4; if (RxLength>ETH_FRAME_LEN) { if (RxPageEnd==RPSTART) rBNRY = RPSTOP-1; else rBNRY = RxPageEnd-1; outportb(BNRY, rBNRY); TRACE("RxLength more long than %x\n", ETH_FRAME_LEN); return IRQ_HANDLED; } skb = dev_alloc_skb(RxLength+2); if (!skb) { TRACE("Rtl8019as eth: low on mem - packet dropped\n"); priv->stats.rx_dropped++; return IRQ_HANDLED; } skb->dev = dev; skb_reserve(skb, 2); skb_put(skb, RxLength); data = ( u16 *)skb->data; // eth_copy_and_sum(skb, data, len, 0); outportb(RSAR0, 4); outportb(RSAR1, RxPageBeg); outportb(RBCR0, RxLength); outportb(RBCR1, RxLength>>8); outportb(BaseAddr, 0xa); #ifdef RTL8019_OP_16 i = 2; data -= 2; RxLen=(RxLength+1)/2; #else i = 4; data -= 4; RxLen=RxLength; #endif for(; RxLen--;) { #ifdef RTL8019_OP_16 static const int cmp_val = 0x7f; #else static const int cmp_val = 0xff; #endif if (!(i & cmp_val)) { outportb(BNRY, RxPageBeg); RxPageBeg++; if(RxPageBeg>=RPSTOP) RxPageBeg = RPSTART; } #ifdef RTL8019_OP_16 data[i++] = inportw(RWPORT); TRACE("%2X,%2X,", data[i-1]&0xff,data[i-1]>>8); #else data[i++] = inportb(RWPORT); TRACE("%2X,", data[i-1]); #endif } TRACE("\n"); outportb(BNRY, RxPageBeg); rBNRY = RxPageBeg; skb->protocol = eth_type_trans(skb, dev); TRACE("\nprotocol=%x\n", skb->protocol); priv->stats.rx_packets++; priv->stats.rx_bytes +=RxLength; netif_rx(skb); } else {
void speaker_on() { char val= inportb(SPEAKER_CTRL); outportb(SPEAKER_CTRL, val | SPEAKER_ENABLE | TIMER2_ENABLE); }
void IRQ7ISR() { SemPostISR(print_sid); // perform SemPostISR directly from here outportb(0x20, 0x67); // 0x20 is PIC control, 0x67 dismisses IRQ 7 }
void floppy_command(uint8_t command) { floppy_wait(); outportb(FLOPPY_FIRST + DATA_FIFO, command); }
int main(int argc, char **argv) { std::fprintf(stdout, "==========================================\n" #ifdef HARDWARE_OPL3 " libADLMIDI demo utility (HW OPL)\n" #else " libADLMIDI demo utility\n" #endif "==========================================\n\n"); flushout(stdout); if(argc < 2 || std::string(argv[1]) == "--help" || std::string(argv[1]) == "-h") { std::printf( "Usage: adlmidi <midifilename> [ <options> ] [ <bank> [ <numchips> [ <numfourops>] ] ]\n" " -p Enables adlib percussion instrument mode\n" " -t Enables tremolo amplification mode\n" " -v Enables vibrato amplification mode\n" " -s Enables scaling of modulator volumes\n" " -frb Enables full-ranged CC74 XG Brightness controller\n" " -nl Quit without looping\n" " -w Write WAV file rather than playing\n" " -mb Run the test of multibank over embedded. 62, 14, 68, and 74'th banks will be combined into one\n" " --solo <track> Selects a solo track to play\n" " --only <track1,...,trackN> Selects a subset of tracks to play\n" #ifndef HARDWARE_OPL3 " -fp Enables full-panning stereo support\n" " --emu-nuked Uses Nuked OPL3 v 1.8 emulator\n" " --emu-nuked7 Uses Nuked OPL3 v 1.7.4 emulator\n" " --emu-dosbox Uses DosBox 0.74 OPL3 emulator\n" #endif "\n" "Where <bank> - number of embeeded bank or filepath to custom WOPL bank file\n" "\n" "Note: To create WOPL bank files use OPL Bank Editor you can get here: \n" "https://github.com/Wohlstand/OPL3BankEditor\n" "\n" ); // Get count of embedded banks (no initialization needed) int banksCount = adl_getBanksCount(); //Get pointer to list of embedded bank names const char *const *banknames = adl_getBankNames(); if(banksCount > 0) { std::printf(" Available embedded banks by number:\n\n"); for(int a = 0; a < banksCount; ++a) std::printf("%10s%2u = %s\n", a ? "" : "Banks:", a, banknames[a]); std::printf( "\n" " Use banks 2-5 to play Descent \"q\" soundtracks.\n" " Look up the relevant bank number from descent.sng.\n" "\n" " The fourth parameter can be used to specify the number\n" " of four-op channels to use. Each four-op channel eats\n" " the room of two regular channels. Use as many as required.\n" " The Doom & Hexen sets require one or two, while\n" " Miles four-op set requires the maximum of numcards*6.\n" "\n" ); } else { std::printf(" This build of libADLMIDI has no embedded banks!\n\n"); } flushout(stdout); return 0; } long sampleRate = 44100; #ifndef HARDWARE_OPL3 //const unsigned MaxSamplesAtTime = 512; // 512=dbopl limitation // How long is SDL buffer, in seconds? // The smaller the value, the more often SDL_AudioCallBack() // is called. const double AudioBufferLength = 0.08; // How much do WE buffer, in seconds? The smaller the value, // the more prone to sound chopping we are. const double OurHeadRoomLength = 0.1; // The lag between visual content and audio content equals // the sum of these two buffers. #ifndef OUTPUT_WAVE_ONLY SDL_AudioSpec spec; SDL_AudioSpec obtained; spec.freq = (int)sampleRate; spec.format = AUDIO_S16SYS; spec.channels = 2; spec.samples = Uint16((double)spec.freq * AudioBufferLength); spec.callback = SDL_AudioCallbackX; #endif //OUTPUT_WAVE_ONLY #endif //HARDWARE_OPL3 ADL_MIDIPlayer *myDevice; //Initialize libADLMIDI and create the instance (you can initialize multiple of them!) myDevice = adl_init(sampleRate); if(myDevice == NULL) { printError("Failed to init MIDI device!\n"); return 1; } //Set internal debug messages hook to print all libADLMIDI's internal debug messages adl_setDebugMessageHook(myDevice, debugPrint, NULL); /* * Set library options by parsing of command line arguments */ bool multibankFromEnbededTest = false; #ifndef OUTPUT_WAVE_ONLY bool recordWave = false; int loopEnabled = 1; #endif #ifndef HARDWARE_OPL3 int emulator = ADLMIDI_EMU_NUKED; #endif size_t soloTrack = ~(size_t)0; std::vector<size_t> onlyTracks; #if !defined(HARDWARE_OPL3) && !defined(OUTPUT_WAVE_ONLY) g_audioFormat.type = ADLMIDI_SampleType_S16; g_audioFormat.containerSize = sizeof(Sint16); g_audioFormat.sampleOffset = sizeof(Sint16) * 2; #endif while(argc > 2) { bool had_option = false; if(!std::strcmp("-p", argv[2])) adl_setPercMode(myDevice, 1);//Turn on AdLib percussion mode else if(!std::strcmp("-v", argv[2])) adl_setHVibrato(myDevice, 1);//Force turn on deep vibrato #if !defined(OUTPUT_WAVE_ONLY) && !defined(HARDWARE_OPL3) else if(!std::strcmp("-w", argv[2])) { //Current Wave output implementation allows only SINT16 output g_audioFormat.type = ADLMIDI_SampleType_S16; g_audioFormat.containerSize = sizeof(Sint16); g_audioFormat.sampleOffset = sizeof(Sint16) * 2; recordWave = true;//Record library output into WAV file } else if(!std::strcmp("-s8", argv[2]) && !recordWave) spec.format = AUDIO_S8; else if(!std::strcmp("-u8", argv[2]) && !recordWave) spec.format = AUDIO_U8; else if(!std::strcmp("-s16", argv[2]) && !recordWave) spec.format = AUDIO_S16; else if(!std::strcmp("-u16", argv[2]) && !recordWave) spec.format = AUDIO_U16; else if(!std::strcmp("-s32", argv[2]) && !recordWave) spec.format = AUDIO_S32; else if(!std::strcmp("-f32", argv[2]) && !recordWave) spec.format = AUDIO_F32; #endif else if(!std::strcmp("-t", argv[2])) adl_setHTremolo(myDevice, 1);//Force turn on deep tremolo else if(!std::strcmp("-frb", argv[2])) adl_setFullRangeBrightness(myDevice, 1);//Turn on a full-ranged XG CC74 Brightness #ifndef OUTPUT_WAVE_ONLY else if(!std::strcmp("-nl", argv[2])) loopEnabled = 0; //Enable loop #endif #ifndef HARDWARE_OPL3 else if(!std::strcmp("--emu-nuked", argv[2])) emulator = ADLMIDI_EMU_NUKED; else if(!std::strcmp("--emu-nuked7", argv[2])) emulator = ADLMIDI_EMU_NUKED_174; else if(!std::strcmp("--emu-dosbox", argv[2])) emulator = ADLMIDI_EMU_DOSBOX; #endif else if(!std::strcmp("-fp", argv[2])) adl_setSoftPanEnabled(myDevice, 1); else if(!std::strcmp("-mb", argv[2])) multibankFromEnbededTest = true; else if(!std::strcmp("-s", argv[2])) adl_setScaleModulators(myDevice, 1);//Turn on modulators scaling by volume else if(!std::strcmp("--solo", argv[2])) { if(argc <= 3) { printError("The option --solo requires an argument!\n"); return 1; } soloTrack = std::strtoul(argv[3], NULL, 0); had_option = true; } else if(!std::strcmp("--only", argv[2])) { if(argc <= 3) { printError("The option --only requires an argument!\n"); return 1; } const char *strp = argv[3]; unsigned long value; unsigned size; bool err = std::sscanf(strp, "%lu%n", &value, &size) != 1; while(!err && *(strp += size)) { onlyTracks.push_back(value); err = std::sscanf(strp, ",%lu%n", &value, &size) != 1; } if(err) { printError("Invalid argument to --only!\n"); return 1; } onlyTracks.push_back(value); had_option = true; } else break; std::copy(argv + (had_option ? 4 : 3), argv + argc, argv + 2); argc -= (had_option ? 2 : 1); } #ifndef OUTPUT_WAVE_ONLY //Turn loop on/off (for WAV recording loop must be disabled!) adl_setLoopEnabled(myDevice, recordWave ? 0 : loopEnabled); #endif #ifdef DEBUG_TRACE_ALL_EVENTS //Hook all MIDI events are ticking while generating an output buffer if(!recordWave) adl_setRawEventHook(myDevice, debugPrintEvent, NULL); #endif #ifndef HARDWARE_OPL3 adl_switchEmulator(myDevice, emulator); #endif std::fprintf(stdout, " - Library version %s\n", adl_linkedLibraryVersion()); #ifdef HARDWARE_OPL3 std::fprintf(stdout, " - Hardware OPL3 chip in use\n"); #else std::fprintf(stdout, " - %s Emulator in use\n", adl_chipEmulatorName(myDevice)); #endif #if !defined(HARDWARE_OPL3) && !defined(OUTPUT_WAVE_ONLY) if(!recordWave) { // Set up SDL if(SDL_OpenAudio(&spec, &obtained) < 0) { std::fprintf(stderr, "\nERROR: Couldn't open audio: %s\n\n", SDL_GetError()); //return 1; } if(spec.samples != obtained.samples) { std::fprintf(stderr, " - Audio wanted (format=%s,samples=%u,rate=%u,channels=%u);\n" " - Audio obtained (format=%s,samples=%u,rate=%u,channels=%u)\n", SDLAudioToStr(spec.format), spec.samples, spec.freq, spec.channels, SDLAudioToStr(obtained.format), obtained.samples, obtained.freq, obtained.channels); } switch(obtained.format) { case AUDIO_S8: g_audioFormat.type = ADLMIDI_SampleType_S8; g_audioFormat.containerSize = sizeof(Sint8); g_audioFormat.sampleOffset = sizeof(Sint8) * 2; break; case AUDIO_U8: g_audioFormat.type = ADLMIDI_SampleType_U8; g_audioFormat.containerSize = sizeof(Uint8); g_audioFormat.sampleOffset = sizeof(Uint8) * 2; break; case AUDIO_S16: g_audioFormat.type = ADLMIDI_SampleType_S16; g_audioFormat.containerSize = sizeof(Sint16); g_audioFormat.sampleOffset = sizeof(Sint16) * 2; break; case AUDIO_U16: g_audioFormat.type = ADLMIDI_SampleType_U16; g_audioFormat.containerSize = sizeof(Uint16); g_audioFormat.sampleOffset = sizeof(Uint16) * 2; break; case AUDIO_S32: g_audioFormat.type = ADLMIDI_SampleType_S32; g_audioFormat.containerSize = sizeof(Sint32); g_audioFormat.sampleOffset = sizeof(Sint32) * 2; break; case AUDIO_F32: g_audioFormat.type = ADLMIDI_SampleType_F32; g_audioFormat.containerSize = sizeof(float); g_audioFormat.sampleOffset = sizeof(float) * 2; break; } } #endif if(argc >= 3) { if(is_number(argv[2])) { int bankno = std::atoi(argv[2]); //Choose one of embedded banks if(adl_setBank(myDevice, bankno) != 0) { printError(adl_errorInfo(myDevice)); return 1; } std::fprintf(stdout, " - Use embedded bank #%d [%s]\n", bankno, adl_getBankNames()[bankno]); } else { std::string bankPath = argv[2]; std::fprintf(stdout, " - Use custom bank [%s]...", bankPath.c_str()); flushout(stdout); //Open external bank file (WOPL format is supported) //to create or edit them, use OPL3 Bank Editor you can take here https://github.com/Wohlstand/OPL3BankEditor if(adl_openBankFile(myDevice, bankPath.c_str()) != 0) { std::fprintf(stdout, "FAILED!\n"); flushout(stdout); printError(adl_errorInfo(myDevice)); return 1; } std::fprintf(stdout, "OK!\n"); } } if(multibankFromEnbededTest) { ADL_BankId id[] = { {0, 0, 0}, /*62*/ // isPercussion, MIDI bank MSB, LSB {0, 8, 0}, /*14*/ // Use as MSB-8 {1, 0, 0}, /*68*/ {1, 0, 25} /*74*/ }; int banks[] = { 62, 14, 68, 74 }; for(size_t i = 0; i < 4; i++) { ADL_Bank bank; if(adl_getBank(myDevice, &id[i], ADLMIDI_Bank_Create, &bank) < 0) { printError(adl_errorInfo(myDevice)); return 1; } if(adl_loadEmbeddedBank(myDevice, &bank, banks[i]) < 0) { printError(adl_errorInfo(myDevice)); return 1; } } std::fprintf(stdout, " - Ran a test of multibank over embedded\n"); } #ifndef HARDWARE_OPL3 int numOfChips = 4; if(argc >= 4) numOfChips = std::atoi(argv[3]); //Set count of concurrent emulated chips count to excite channels limit of one chip if(adl_setNumChips(myDevice, numOfChips) != 0) { printError(adl_errorInfo(myDevice)); return 1; } std::fprintf(stdout, " - Number of chips %d\n", adl_getNumChips(myDevice)); #else int numOfChips = 1; adl_setNumChips(myDevice, numOfChips); #endif if(argc >= 5) { //Set total count of 4-operator channels between all emulated chips if(adl_setNumFourOpsChn(myDevice, std::atoi(argv[4])) != 0) { printError(adl_errorInfo(myDevice)); return 1; } } std::fprintf(stdout, " - Number of four-ops %d\n", adl_getNumFourOpsChn(myDevice)); std::string musPath = argv[1]; //Open MIDI file to play if(adl_openFile(myDevice, musPath.c_str()) != 0) { printError(adl_errorInfo(myDevice)); return 2; } std::fprintf(stdout, " - Track count: %lu\n", (unsigned long)adl_trackCount(myDevice)); if(soloTrack != ~(size_t)0) { std::fprintf(stdout, " - Solo track: %lu\n", (unsigned long)soloTrack); adl_setTrackOptions(myDevice, soloTrack, ADLMIDI_TrackOption_Solo); } if(!onlyTracks.empty()) { size_t count = adl_trackCount(myDevice); for(size_t track = 0; track < count; ++track) adl_setTrackOptions(myDevice, track, ADLMIDI_TrackOption_Off); std::fprintf(stdout, " - Only tracks:"); for(size_t i = 0, n = onlyTracks.size(); i < n; ++i) { size_t track = onlyTracks[i]; adl_setTrackOptions(myDevice, track, ADLMIDI_TrackOption_On); std::fprintf(stdout, " %lu", (unsigned long)track); } std::fprintf(stdout, "\n"); } std::fprintf(stdout, " - File [%s] opened!\n", musPath.c_str()); flushout(stdout); #ifndef HARDWARE_OPL3 signal(SIGINT, sighandler); signal(SIGTERM, sighandler); # if !defined(_WIN32) && !defined(__WATCOMC__) signal(SIGHUP, sighandler); # endif #else//HARDWARE_OPL3 static const unsigned NewTimerFreq = 209; unsigned TimerPeriod = 0x1234DDul / NewTimerFreq; #ifdef __DJGPP__ //disable(); outportb(0x43, 0x34); outportb(0x40, TimerPeriod & 0xFF); outportb(0x40, TimerPeriod >> 8); //enable(); #endif//__DJGPP__ #ifdef __WATCOMC__ std::fprintf(stdout, " - Initializing BIOS timer...\n"); flushout(stdout); //disable(); outp(0x43, 0x34); outp(0x40, TimerPeriod & 0xFF); outp(0x40, TimerPeriod >> 8); //enable(); std::fprintf(stdout, " - Ok!\n"); flushout(stdout); #endif//__WATCOMC__ unsigned long BIOStimer_begin = BIOStimer; double tick_delay = 0.0; #endif//HARDWARE_OPL3 double total = adl_totalTimeLength(myDevice); #ifndef OUTPUT_WAVE_ONLY double loopStart = adl_loopStartTime(myDevice); double loopEnd = adl_loopEndTime(myDevice); char totalHMS[25]; char loopStartHMS[25]; char loopEndHMS[25]; secondsToHMSM(total, totalHMS, 25); if(loopStart >= 0.0 && loopEnd >= 0.0) { secondsToHMSM(loopStart, loopStartHMS, 25); secondsToHMSM(loopEnd, loopEndHMS, 25); } # ifndef HARDWARE_OPL3 if(!recordWave) # endif { std::fprintf(stdout, " - Loop is turned %s\n", loopEnabled ? "ON" : "OFF"); if(loopStart >= 0.0 && loopEnd >= 0.0) std::fprintf(stdout, " - Has loop points: %s ... %s\n", loopStartHMS, loopEndHMS); std::fprintf(stdout, "\n==========================================\n"); flushout(stdout); # ifndef HARDWARE_OPL3 SDL_PauseAudio(0); # endif # ifdef DEBUG_SEEKING_TEST int delayBeforeSeek = 50; std::fprintf(stdout, "DEBUG: === Random position set test is active! ===\n"); flushout(stdout); # endif # ifndef HARDWARE_OPL3 Uint8 buff[16384]; # endif char posHMS[25]; uint64_t milliseconds_prev = -1; while(!stop) { # ifndef HARDWARE_OPL3 size_t got = (size_t)adl_playFormat(myDevice, 4096, buff, buff + g_audioFormat.containerSize, &g_audioFormat) * g_audioFormat.containerSize; if(got <= 0) break; # endif # ifdef DEBUG_TRACE_ALL_CHANNELS enum { TerminalColumns = 80 }; char channelText[TerminalColumns + 1]; char channelAttr[TerminalColumns + 1]; adl_describeChannels(myDevice, channelText, channelAttr, sizeof(channelText)); std::fprintf(stdout, "%*s\r", TerminalColumns, ""); // erase the line std::fprintf(stdout, "%s\n", channelText); # endif # ifndef DEBUG_TRACE_ALL_EVENTS double time_pos = adl_positionTell(myDevice); std::fprintf(stdout, " \r"); uint64_t milliseconds = static_cast<uint64_t>(time_pos * 1000.0); if(milliseconds != milliseconds_prev) { secondsToHMSM(time_pos, posHMS, 25); std::fprintf(stdout, " \r"); std::fprintf(stdout, "Time position: %s / %s\r", posHMS, totalHMS); flushout(stdout); milliseconds_prev = milliseconds; } # endif # ifndef HARDWARE_OPL3 g_audioBuffer_lock.Lock(); size_t pos = g_audioBuffer.size(); g_audioBuffer.resize(pos + got); for(size_t p = 0; p < got; ++p) g_audioBuffer[pos + p] = buff[p]; g_audioBuffer_lock.Unlock(); const SDL_AudioSpec &spec = obtained; while(g_audioBuffer.size() > static_cast<size_t>(spec.samples + (spec.freq * g_audioFormat.sampleOffset) * OurHeadRoomLength)) { SDL_Delay(1); } # ifdef DEBUG_SEEKING_TEST if(delayBeforeSeek-- <= 0) { delayBeforeSeek = rand() % 50; double seekTo = double((rand() % int(adl_totalTimeLength(myDevice)) - delayBeforeSeek - 1 )); adl_positionSeek(myDevice, seekTo); } # endif # else//HARDWARE_OPL3 const double mindelay = 1.0 / NewTimerFreq; //__asm__ volatile("sti\nhlt"); //usleep(10000); #ifdef __DJGPP__ __dpmi_yield(); #endif #ifdef __WATCOMC__ //dpmi_dos_yield(); mch_delay((unsigned int)(tick_delay * 1000.0)); #endif static unsigned long PrevTimer = BIOStimer; const unsigned long CurTimer = BIOStimer; const double eat_delay = (CurTimer - PrevTimer) / (double)NewTimerFreq; PrevTimer = CurTimer; tick_delay = adl_tickEvents(myDevice, eat_delay, mindelay); if(adl_atEnd(myDevice) && tick_delay <= 0) stop = true; if(kbhit()) { // Quit on ESC key! int c = getch(); if(c == 27) stop = true; } # endif//HARDWARE_OPL3 } std::fprintf(stdout, " \n\n"); # ifndef HARDWARE_OPL3 SDL_CloseAudio(); # endif } #endif //OUTPUT_WAVE_ONLY #ifndef HARDWARE_OPL3 # ifndef OUTPUT_WAVE_ONLY else # endif //OUTPUT_WAVE_ONLY { std::string wave_out = musPath + ".wav"; std::fprintf(stdout, " - Recording WAV file %s...\n", wave_out.c_str()); std::fprintf(stdout, "\n==========================================\n"); flushout(stdout); if(wave_open(sampleRate, wave_out.c_str()) == 0) { wave_enable_stereo(); short buff[4096]; int complete_prev = -1; while(!stop) { size_t got = (size_t)adl_play(myDevice, 4096, buff); if(got <= 0) break; wave_write(buff, (long)got); int complete = static_cast<int>(std::floor(100.0 * adl_positionTell(myDevice) / total)); flushout(stdout); if(complete_prev != complete) { std::fprintf(stdout, " \r"); std::fprintf(stdout, "Recording WAV... [%d%% completed]\r", complete); std::fflush(stdout); complete_prev = complete; } } wave_close(); std::fprintf(stdout, " \n\n"); if(stop) std::fprintf(stdout, "Interrupted! Recorded WAV is incomplete, but playable!\n"); else std::fprintf(stdout, "Completed!\n"); flushout(stdout); } else { adl_close(myDevice); return 1; } } #endif //HARDWARE_OPL3 #ifdef HARDWARE_OPL3 #ifdef __DJGPP__ // Fix the skewed clock and reset BIOS tick rate _farpokel(_dos_ds, 0x46C, BIOStimer_begin + (BIOStimer - BIOStimer_begin) * (0x1234DD / 65536.0) / NewTimerFreq); //disable(); outportb(0x43, 0x34); outportb(0x40, 0); outportb(0x40, 0); //enable(); #endif #ifdef __WATCOMC__ outp(0x43, 0x34); outp(0x40, 0); outp(0x40, 0); #endif adl_panic(myDevice); //Shut up all sustaining notes #endif adl_close(myDevice); return 0; }
void Speaker::on(unsigned int pitch) //Enables the speaker and sets frequency { pit.init(pitch, 2); outportb(0x61, (inportb(0x61) | 3)); }
void Speaker::off() //Disables the speaker { outportb(0x61, (inportb(0x61) & 0xfc)); }
//reset void kbdReset() { outportb(ATKBD_DATA,0xF6); inportb(ATKBD_DATA); // should be ACK }
static boolean __wss_detect() { /* First find the port number */ if (!wss.port) { static unsigned int wss_ports[] = { 0x32c, 0x530, 0x604, 0xE80, 0xF40 }; int i; for (i = 0; i < 5; i++) { wss.port = wss_ports[i]; if (__wss_ping()) break; } if (i < 0) { wss.port = 0; return FALSE; } } /* Now disable output */ wss_output(FALSE); /* Detect the DMA channel */ if (!wss.dma) { static int __dma[] = { 0, 1, 3 }; int i; /* Enable playback IRQ */ __wss_regbit_set(WSSR_PIN_CTRL, WSSM_IRQ_ENABLE); __wss_outreg(WSSR_IRQ_STATUS, WSSM_PLAYBACK_IRQ); /* Start a short DMA transfer and check if DMA count is zero */ for (i = 0; i < 3; i++) { unsigned int timer, status, freq = 44100; wss.dma = __dma[i]; dma_disable(wss.dma); dma_set_mode(wss.dma, DMA_MODE_WRITE); dma_clear_ff(wss.dma); dma_set_count(wss.dma, 10); dma_enable(wss.dma); /* Clear IRQ status */ outportb(WSS_STATUS, 0); __wss_setformat(__wss_getrate(&freq)); __wss_outreg(WSSR_COUNT_LOW, 1); __wss_outreg(WSSR_COUNT_HIGH, 0); /* Tell codec to start transfer */ __wss_regbit_set(WSSR_IFACE_CTRL, WSSM_PLAYBACK_ENABLE); _farsetsel(_dos_ds); timer = _farnspeekl(0x46c); while (_farnspeekl(0x46c) - timer <= 2) if (dma_get_count(wss.dma) == 0) break; __wss_regbit_reset(WSSR_IFACE_CTRL, WSSM_PLAYBACK_ENABLE); dma_disable(wss.dma); /* Now check if DMA transfer count is zero and an IRQ is pending */ status = inportb(WSS_STATUS); outportb(WSS_STATUS, 0); if ((dma_get_count(wss.dma) == 0) && (status & WSSM_INT)) break; wss.dma = 0; } if (!wss.dma) return FALSE; } /* Now detect the IRQ number */ if (!wss.irq) { unsigned int i, irqmask, freq = 5510; unsigned long timer, delta = 0x7fffffff; /* IRQ can be one of 2,3,5,7,10 */ irq_detect_start(0x04ac, __wss_irq_irqdetect); dma_disable(wss.dma); dma_set_mode(wss.dma, DMA_MODE_WRITE | DMA_MODE_AUTOINIT); dma_clear_ff(wss.dma); dma_set_count(wss.dma, 1); dma_enable(wss.dma); __wss_setformat(__wss_getrate(&freq)); /* Clear IRQ status */ outportb(WSS_STATUS, 0); __wss_outreg(WSSR_COUNT_LOW, 0); __wss_outreg(WSSR_COUNT_HIGH, 0); /* Prepare timeout counter */ _farsetsel(_dos_ds); timer = _farnspeekl(0x46c); while (timer == _farnspeekl(0x46c)); timer = _farnspeekl(0x46c); /* Reset all IRQ counters */ irq_detect_clear(); /* Tell codec to start transfer */ __wss_regbit_set(WSSR_IFACE_CTRL, WSSM_PLAYBACK_ENABLE); /* Now wait 1/18 seconds */ while (timer == _farnspeekl(0x46c)); __wss_regbit_reset(WSSR_IFACE_CTRL, WSSM_PLAYBACK_ENABLE); dma_disable(wss.dma); /* Given frequency 5510Hz, a buffer size of 1 byte and a time interval of 1/18.2 second, we should have received about 302 interrupts */ for (i = 2; i <= 10; i++) { int count = abs(302 - irq_detect_get(i, &irqmask)); if (count < delta) wss.irq = i, delta = count; } if (delta > 150) wss.irq = 0; irq_detect_end(); if (!wss.irq) return FALSE; } return TRUE; }
void irq_ack(size_t irq_no) { if (irq_no >= 8) { outportb(0xA0, 0x20); } outportb(0x20, 0x20); }
int init_rtl(void) { if (rtl_device_pci) { debug_print(NOTICE, "Located an RTL 8139: 0x%x\n", rtl_device_pci); uint16_t command_reg = pci_read_field(rtl_device_pci, PCI_COMMAND, 4); debug_print(NOTICE, "COMMAND register before: 0x%4x\n", command_reg); if (command_reg & (1 << 2)) { debug_print(NOTICE, "Bus mastering already enabled.\n"); } else { command_reg |= (1 << 2); /* bit 2 */ debug_print(NOTICE, "COMMAND register after: 0x%4x\n", command_reg); pci_write_field(rtl_device_pci, PCI_COMMAND, 4, command_reg); command_reg = pci_read_field(rtl_device_pci, PCI_COMMAND, 4); debug_print(NOTICE, "COMMAND register after: 0x%4x\n", command_reg); } rtl_irq = pci_get_interrupt(rtl_device_pci); debug_print(NOTICE, "Interrupt Line: %x\n", rtl_irq); irq_install_handler(rtl_irq, rtl_irq_handler, "rtl8139"); uint32_t rtl_bar0 = pci_read_field(rtl_device_pci, PCI_BAR0, 4); uint32_t rtl_bar1 = pci_read_field(rtl_device_pci, PCI_BAR1, 4); debug_print(NOTICE, "BAR0: 0x%8x\n", rtl_bar0); debug_print(NOTICE, "BAR1: 0x%8x\n", rtl_bar1); rtl_iobase = 0x00000000; if (rtl_bar0 & 0x00000001) { rtl_iobase = rtl_bar0 & 0xFFFFFFFC; } else { debug_print(NOTICE, "This doesn't seem right! RTL8139 should be using an I/O BAR; this looks like a memory bar."); } debug_print(NOTICE, "RTL iobase: 0x%x\n", rtl_iobase); rx_wait = list_create(); debug_print(NOTICE, "Determining mac address...\n"); for (int i = 0; i < 6; ++i) { mac[i] = inports(rtl_iobase + RTL_PORT_MAC + i); } debug_print(NOTICE, "%2x:%2x:%2x:%2x:%2x:%2x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); debug_print(NOTICE, "Enabling RTL8139.\n"); outportb(rtl_iobase + RTL_PORT_CONFIG, 0x0); debug_print(NOTICE, "Resetting RTL8139.\n"); outportb(rtl_iobase + RTL_PORT_CMD, 0x10); while ((inportb(rtl_iobase + 0x37) & 0x10) != 0) { } debug_print(NOTICE, "Done resetting RTL8139.\n"); for (int i = 0; i < 5; ++i) { rtl_tx_buffer[i] = (void*)kvmalloc_p(0x1000, &rtl_tx_phys[i]); for (int j = 0; j < 60; ++j) { rtl_tx_buffer[i][j] = 0xF0; } } rtl_rx_buffer = (uint8_t *)kvmalloc_p(0x3000, &rtl_rx_phys); memset(rtl_rx_buffer, 0x00, 0x3000); debug_print(NOTICE, "Buffers:\n"); debug_print(NOTICE, " rx 0x%x [phys 0x%x and 0x%x and 0x%x]\n", rtl_rx_buffer, rtl_rx_phys, map_to_physical((uintptr_t)rtl_rx_buffer + 0x1000), map_to_physical((uintptr_t)rtl_rx_buffer + 0x2000)); for (int i = 0; i < 5; ++i) { debug_print(NOTICE, " tx 0x%x [phys 0x%x]\n", rtl_tx_buffer[i], rtl_tx_phys[i]); } debug_print(NOTICE, "Initializing receive buffer.\n"); outportl(rtl_iobase + RTL_PORT_RBSTART, rtl_rx_phys); debug_print(NOTICE, "Enabling IRQs.\n"); outports(rtl_iobase + RTL_PORT_IMR, 0x8000 | /* PCI error */ 0x4000 | /* PCS timeout */ 0x40 | /* Rx FIFO over */ 0x20 | /* Rx underrun */ 0x10 | /* Rx overflow */ 0x08 | /* Tx error */ 0x04 | /* Tx okay */ 0x02 | /* Rx error */ 0x01 /* Rx okay */ ); /* TOK, ROK */ debug_print(NOTICE, "Configuring transmit\n"); outportl(rtl_iobase + RTL_PORT_TCR, 0 ); debug_print(NOTICE, "Configuring receive buffer.\n"); outportl(rtl_iobase + RTL_PORT_RCR, (0) | /* 8K receive */ 0x08 | /* broadcast */ 0x01 /* all physical */ ); debug_print(NOTICE, "Enabling receive and transmit.\n"); outportb(rtl_iobase + RTL_PORT_CMD, 0x08 | 0x04); debug_print(NOTICE, "Resetting rx stats\n"); outportl(rtl_iobase + RTL_PORT_RXMISS, 0); net_queue = list_create(); debug_print(NOTICE, "Initializing netif functions\n"); init_netif_funcs(rtl_get_mac, rtl_get_packet, rtl_send_packet, "RTL8139"); debug_print(NOTICE, "Back from starting the worker thread.\n"); } else { return -1; } return 0; }
void write_rtc(Byte add, Byte value) { disable(); outportb(RTC_ADDR_REG, add); outportb(RTC_DATA_REG, value); enable(); }
void kbSendCommand(unsigned char c) /*Sends a command to the keyboard*/ { kbWaitForReady(); outportb(0x64,c); }
void writeChar2Bochs( uint8 char2Write ) { outportb( 0xE9, char2Write ); }
void kbSendData(unsigned char data) /*Sends a command or data to keyboard*/ { kbWaitForReady(); /*MicroDelay((unsigned long) 10);*/ outportb(0x60, data); }
// gets the time from the RTC(in 24 hour format) and puts it into strings // BUG: "9" for some reason is displayed as an "s" void get_time_str(u_char no_leading_zero, char *hr, char *min, char *sec) { char num_to_char[9] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; // for converting numbers into charactors u_char tmp1, tmp2; // getting the hour outportb(0x70, 0x04); tmp1 = inportb(0x71); tmp2 = tmp1 >> 4; tmp1 = tmp1 & 0xF; if(no_leading_zero == 0) { hr[0] = num_to_char[tmp2]; hr[1] = num_to_char[tmp1]; hr[2] = '\0'; } else // cut off the leading zero(instead of "05", just have "5") { if(tmp2 != 0) { hr[0] = num_to_char[tmp2]; hr[1] = num_to_char[tmp1]; hr[2] = '\0'; } else { hr[0] = num_to_char[tmp1]; hr[1] = '\0'; }; }; // get the minutes outportb(0x70, 0x02); tmp1 = inportb(0x71); tmp2 = tmp1 >> 4; tmp1 = tmp1 & 0xF; if(no_leading_zero == 0) { min[0] = num_to_char[tmp2]; min[1] = num_to_char[tmp1]; min[2] = '\0'; } else // cut off the leading zero(instead of "05", just have "5") { if(tmp2 != 0) { min[0] = num_to_char[tmp2]; min[1] = num_to_char[tmp1]; min[2] = '\0'; } else { min[0] = num_to_char[tmp1]; min[1] = '\0'; }; }; // get the seconds outportb(0x70, 0x00); tmp1 = inportb(0x71); tmp2 = tmp1 >> 4; tmp1 = tmp1 & 0xF; if(no_leading_zero == 0) { sec[0] = num_to_char[tmp2]; sec[1] = num_to_char[tmp1]; sec[2] = '\0'; } else // cut off the leading zero(instead of "05", just have "5") { if(tmp2 != 0) { sec[0] = num_to_char[tmp2]; sec[1] = num_to_char[tmp1]; sec[2] = '\0'; } else { sec[0] = num_to_char[tmp1]; sec[1] = '\0'; }; }; };
void floppy_reset_flipflop_dma(void) { outportb(0xC, 0); }
main() { int i,ar,in,inp; /*modo grafico*/ int gdriver=DETECT,gmode,errorcode; initgraph(&gdriver,&gmode,"..\\bgi"); errorcode=graphresult(); if (errorcode!= grOk) { printf("Error grafico: %s/n",grapherrormsg(errorcode)); printf("Presione cualquier tecla:"); getch(); exit(1); } getch(); /* >>>>>>>>>>>>> INTRODUCCION <<<<<<<<<<<<<<<<*/ /* Background */ setcolor(1); for (i=240; i>=0; i--) { /*delay(50);*/ rectangle(i,i,getmaxx()-i,getmaxy()-i); } setcolor(14); rectangle(0,0,getmaxx(),getmaxy()); rectangle(1,1,getmaxx()-1,getmaxy()-1); rectangle(2,2,getmaxx()-2,getmaxy()-2); rectangle(3,3,getmaxx()-3,getmaxy()-3); rectangle(4,4,getmaxx()-4,getmaxy()-4); rectangle(5,5,getmaxx()-5,getmaxy()-5); settextstyle(SMALL_FONT,VERT_DIR,4); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(20,420,"UNIVERSIDAD"); outtextxy(20,270,"SANTA"); outtextxy(20,115,"VINA"); outtextxy(614,420,"UNIVERSIDAD"); outtextxy(614,270,"SANTA"); outtextxy(614,115,"VINA"); setcolor(9); rectangle(6,6,getmaxx()-6,getmaxy()-6); rectangle(7,7,getmaxx()-7,getmaxy()-7); rectangle(8,8,getmaxx()-8,getmaxy()-8); rectangle(9,9,getmaxx()-9,getmaxy()-9); rectangle(10,10,getmaxx()-10,getmaxy()-10); rectangle(11,11,getmaxx()-11,getmaxy()-11); settextstyle(SMALL_FONT,VERT_DIR,4); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(20,365,"TECNICA"); outtextxy(20,237,"MARIA"); outtextxy(20,91,"DEL"); outtextxy(614,365,"TECNICA"); outtextxy(614,237,"MARIA"); outtextxy(614,91,"DEL"); setcolor(4); rectangle(12,12,getmaxx()-12,getmaxy()-12); rectangle(13,13,getmaxx()-13,getmaxy()-13); rectangle(14,14,getmaxx()-14,getmaxy()-14); rectangle(15,15,getmaxx()-15,getmaxy()-15); rectangle(16,16,getmaxx()-16,getmaxy()-16); rectangle(17,17,getmaxx()-17,getmaxy()-17); settextstyle(SMALL_FONT,VERT_DIR,4); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(20,315,"FEDERICO"); outtextxy(20,140,"SEDE"); outtextxy(20,71,"MAR"); outtextxy(614,315,"FEDERICO"); outtextxy(614,140,"SEDE"); outtextxy(614,71,"MAR"); /*fin background */ setcolor(4); for(i=0; i<=133; i++)rectangle(50+i,50+i,580-i,190-i); /*line (col1,fila1,col2,fila2) */ setcolor(14); line(50,50,50,190); line(51,50,51,190); line(52,50,52,190); line(580,50,580,190); line(581,50,581,190); line(582,50,582,190); line(50,50,580,50); line(50,51,580,51); line(50,52,580,52); line(50,190,582,190); line(50,191,582,191); line(50,192,582,192); setcolor(14); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,4); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(312,100,"PROGRAMACION DE SISTEMAS"); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,3); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(312,160,"Proyecto Final"); setcolor(14); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,4); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(320,230,"Control de un Motor Paso a Paso"); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(320,370,"ALUMNOS:"); outtextxy(320,390,"Rodrigo Augosto Cancino"); outtextxy(320,410,"Ivan Moyano Varas"); /* >>>>>>>>>>>>>> FIN INTRODUCCION <<<<<<<<<<<<<<<<<*/ /*delay(9999); delay(9999); delay(9999); delay(9999);*/ /*delay(9999); delay(9999); delay(9999); delay(9999);*/ /*delay(9999); delay(9999);*/ delay(9000); /* >>>>>> FUNCIONAMIENTO <<<<<<<<<< */ /* Background*/ setcolor(1); for (i=0; i<=240; i++)rectangle(i,i,getmaxx()-i,getmaxy()-i); setcolor(14); rectangle(0,0,getmaxx(),getmaxy()); rectangle(1,1,getmaxx()-1,getmaxy()-1); rectangle(2,2,getmaxx()-2,getmaxy()-2); rectangle(3,3,getmaxx()-3,getmaxy()-3); rectangle(4,4,getmaxx()-4,getmaxy()-4); rectangle(5,5,getmaxx()-5,getmaxy()-5); settextstyle(SMALL_FONT,VERT_DIR,4); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(20,420,"UNIVERSIDAD"); outtextxy(20,270,"SANTA"); outtextxy(20,115,"VINA"); outtextxy(614,420,"UNIVERSIDAD"); outtextxy(614,270,"SANTA"); outtextxy(614,115,"VINA"); setcolor(9); rectangle(6,6,getmaxx()-6,getmaxy()-6); rectangle(7,7,getmaxx()-7,getmaxy()-7); rectangle(8,8,getmaxx()-8,getmaxy()-8); rectangle(9,9,getmaxx()-9,getmaxy()-9); rectangle(10,10,getmaxx()-10,getmaxy()-10); rectangle(11,11,getmaxx()-11,getmaxy()-11); settextstyle(SMALL_FONT,VERT_DIR,4); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(20,365,"TECNICA"); outtextxy(20,237,"MARIA"); outtextxy(20,91,"DEL"); outtextxy(614,365,"TECNICA"); outtextxy(614,237,"MARIA"); outtextxy(614,91,"DEL"); setcolor(4); rectangle(12,12,getmaxx()-12,getmaxy()-12); rectangle(13,13,getmaxx()-13,getmaxy()-13); rectangle(14,14,getmaxx()-14,getmaxy()-14); rectangle(15,15,getmaxx()-15,getmaxy()-15); rectangle(16,16,getmaxx()-16,getmaxy()-16); rectangle(17,17,getmaxx()-17,getmaxy()-17); settextstyle(SMALL_FONT,VERT_DIR,4); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(20,315,"FEDERICO"); outtextxy(20,140,"SEDE"); outtextxy(20,71,"MAR"); outtextxy(614,315,"FEDERICO"); outtextxy(614,140,"SEDE"); outtextxy(614,71,"MAR"); /*fin background */ setcolor(14); for(i=0; i<=100; i++)rectangle(50+i,80+i,580-i,182-i); setcolor(1); /*line (col1,fila1,col2,fila2) */ line(55,85,55,175); line(56,85,56,175); line(57,85,57,175); line(573,85,573,175); line(574,85,574,175); line(575,85,575,175); line(55,85,575,85); line(55,86,575,86); line(55,87,575,87); line(55,175,575,175); line(55,176,575,176); line(55,177,575,177); setcolor(1); settextjustify(CENTER_TEXT,CENTER_TEXT); settextstyle(SANS_SERIF_FONT, HORIZ_DIR,2); outtextxy(300, 122, "DESCRIPCION DE FUNCIONAMIENTO"); outtextxy(300, 142, "DEL PROGRAMA"); setcolor(14); settextjustify(CENTER_TEXT, CENTER_TEXT); settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 2); outtextxy(300, 220, "Programa disenado para controlar"); outtextxy(300, 245, "el movimiento de un motor paso a paso"); outtextxy(300, 270, "por intermedio de un Dip - Switch"); outtextxy(300, 295, "A continuacion se daran a conocer"); outtextxy(300, 320, "las posiciones del switch para"); outtextxy(300, 345, "distintos movimientos del motor."); /* >>>>>>>>>> FIN FUNCIONAMIENTO <<<<<<<<<<<<<<<<<*/ /*delay(9999); delay(9999); delay(9999); delay(9999);*/ /*delay(9999); delay(9999); delay(9999); delay(9999);*/ /*delay(9999); delay(9999); delay(9999);*/ delay(9000); /* >>>>>>>>>>>> PROGRAMA <<<<<<<<<<<<<<<<<<<<<<*/ while(1) { /* Background*/ setcolor(1); for (i=0; i<=240; i++)rectangle(i,i,getmaxx()-i,getmaxy()-i); setcolor(14); rectangle(0,0,getmaxx(),getmaxy()); rectangle(1,1,getmaxx()-1,getmaxy()-1); rectangle(2,2,getmaxx()-2,getmaxy()-2); rectangle(3,3,getmaxx()-3,getmaxy()-3); rectangle(4,4,getmaxx()-4,getmaxy()-4); rectangle(5,5,getmaxx()-5,getmaxy()-5); settextstyle(SMALL_FONT,VERT_DIR,4); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(20,420,"UNIVERSIDAD"); outtextxy(20,270,"SANTA"); outtextxy(20,115,"VINA"); outtextxy(614,420,"UNIVERSIDAD"); outtextxy(614,270,"SANTA"); outtextxy(614,115,"VINA"); setcolor(9); rectangle(6,6,getmaxx()-6,getmaxy()-6); rectangle(7,7,getmaxx()-7,getmaxy()-7); rectangle(8,8,getmaxx()-8,getmaxy()-8); rectangle(9,9,getmaxx()-9,getmaxy()-9); rectangle(10,10,getmaxx()-10,getmaxy()-10); rectangle(11,11,getmaxx()-11,getmaxy()-11); settextstyle(SMALL_FONT,VERT_DIR,4); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(20,365,"TECNICA"); outtextxy(20,237,"MARIA"); outtextxy(20,91,"DEL"); outtextxy(614,365,"TECNICA"); outtextxy(614,237,"MARIA"); outtextxy(614,91,"DEL"); setcolor(4); rectangle(12,12,getmaxx()-12,getmaxy()-12); rectangle(13,13,getmaxx()-13,getmaxy()-13); rectangle(14,14,getmaxx()-14,getmaxy()-14); rectangle(15,15,getmaxx()-15,getmaxy()-15); rectangle(16,16,getmaxx()-16,getmaxy()-16); rectangle(17,17,getmaxx()-17,getmaxy()-17); settextstyle(SMALL_FONT,VERT_DIR,4); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(20,315,"FEDERICO"); outtextxy(20,140,"SEDE"); outtextxy(20,71,"MAR"); outtextxy(614,315,"FEDERICO"); outtextxy(614,140,"SEDE"); outtextxy(614,71,"MAR"); /*fin background */ setcolor(4); for(i=0; i<=100; i++)rectangle(50+i,80+i,580-i,182-i); setcolor(15); /*line (col1,fila1,col2,fila2) */ line(55,85,55,175); line(56,85,56,175); line(57,85,57,175); line(573,85,573,175); line(574,85,574,175); line(575,85,575,175); line(55,85,575,85); line(55,86,575,86); line(55,87,575,87); line(55,175,575,175); line(55,176,575,176); line(55,177,575,177); setcolor(14); settextstyle(SANS_SERIF_FONT, HORIZ_DIR,2); settextjustify(CENTER_TEXT, CENTER_TEXT); outtextxy(315,130,"POSICIONES DEL DIP SWITCH"); settextjustify(LEFT_TEXT, CENTER_TEXT); settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 1); outtextxy(110, 240, " 0 0 El Motor esta detenido"); outtextxy(110, 260, " 0 1 El Motor avanza 36 grados y se detiene"); outtextxy(110, 280, " 1 0 El Motor avanza 18 grados y se detiene"); outtextxy(110, 300, " 1 1 El Motor retrocede 36 grados y se detiene"); in=inport(0x379); inp=in&0xff; printf("\n puerto de entrada: %x ",inp); switch(inp){ case 0x7f : outportb(0x378,0x88); outportb(0x378,0x44); outportb(0x378,0x22); outportb(0x378,0x11); break; case 0x6f : outportb(0x378,0x11); outportb(0x378,0x22); outportb(0x378,0x44); outportb(0x378,0x88); break; case 0x77 : outportb(0x378,0x88); outportb(0x378,0xcc); outportb(0x378,0x44); outportb(0x378,0x66); outportb(0x378,0x22); outportb(0x378,0x33); outportb(0x378,0x11); outportb(0x378,0x99); break; case 0x67 : outportb(0x378,0x11); outportb(0x378,0x33); outportb(0x378,0x22); outportb(0x378,0x66); outportb(0x378,0x44); outportb(0x378,0xcc); outportb(0x378,0x88); outportb(0x378,0x99); break; default : break; } /* >>>>>>>>>>>> FIN PROGRAMA <<<<<<<<<<<<<<*/ setcolor(15); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,1); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(500,450,"Otro giro (s/n)"); /*if (inp==0xff|inp==0xe7|inp==0xef|inp==0xf7)*/ ar=getch(); if (ar==110|ar==27) { clrscr(); outportb(0x378,0x00); /* Background*/ setcolor(1); for (i=0; i<=240; i++)rectangle(i,i,getmaxx()-i,getmaxy()-i); setcolor(14); rectangle(0,0,getmaxx(),getmaxy()); rectangle(1,1,getmaxx()-1,getmaxy()-1); rectangle(2,2,getmaxx()-2,getmaxy()-2); rectangle(3,3,getmaxx()-3,getmaxy()-3); rectangle(4,4,getmaxx()-4,getmaxy()-4); rectangle(5,5,getmaxx()-5,getmaxy()-5); settextstyle(SMALL_FONT,VERT_DIR,4); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(20,420,"UNIVERSIDAD"); outtextxy(20,270,"SANTA"); outtextxy(20,115,"VINA"); outtextxy(614,420,"UNIVERSIDAD"); outtextxy(614,270,"SANTA"); outtextxy(614,115,"VINA"); setcolor(9); rectangle(6,6,getmaxx()-6,getmaxy()-6); rectangle(7,7,getmaxx()-7,getmaxy()-7); rectangle(8,8,getmaxx()-8,getmaxy()-8); rectangle(9,9,getmaxx()-9,getmaxy()-9); rectangle(10,10,getmaxx()-10,getmaxy()-10); rectangle(11,11,getmaxx()-11,getmaxy()-11); settextstyle(SMALL_FONT,VERT_DIR,4); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(20,365,"TECNICA"); outtextxy(20,237,"MARIA"); outtextxy(20,91,"DEL"); outtextxy(614,365,"TECNICA"); outtextxy(614,237,"MARIA"); outtextxy(614,91,"DEL"); setcolor(4); rectangle(12,12,getmaxx()-12,getmaxy()-12); rectangle(13,13,getmaxx()-13,getmaxy()-13); rectangle(14,14,getmaxx()-14,getmaxy()-14); rectangle(15,15,getmaxx()-15,getmaxy()-15); rectangle(16,16,getmaxx()-16,getmaxy()-16); rectangle(17,17,getmaxx()-17,getmaxy()-17); settextstyle(SMALL_FONT,VERT_DIR,4); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(20,315,"FEDERICO"); outtextxy(20,140,"SEDE"); outtextxy(20,71,"MAR"); outtextxy(614,315,"FEDERICO"); outtextxy(614,140,"SEDE"); outtextxy(614,71,"MAR"); /*fin background */ setcolor(15); settextstyle(GOTHIC_FONT,HORIZ_DIR,2); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(300,40,"UNIVERSIDAD TECNICA FEDERICO SANTA MARIA"); outtextxy(340,60,"Sede Vina del Mar - CHILE"); settextstyle(TRIPLEX_FONT,HORIZ_DIR,3); settextjustify(LEFT_TEXT,CENTER_TEXT); outtextxy(180,200,"ALUMNOS:"); outtextxy(200,220,"* Rodrigo Augosto Cancino"); outtextxy(200,240,"* Ivan Moyano Varas"); settextstyle(TRIPLEX_FONT,HORIZ_DIR,3); settextjustify(LEFT_TEXT,CENTER_TEXT); outtextxy(180,280,"PROFESOR:"); outtextxy(200,300,"* Jose Estay"); settextstyle(SMALL_FONT,HORIZ_DIR,4); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(310,430,"www.ivaninternet.com"); outtextxy(310,440,"www.alumnos.utfsm.cl/~raugostc"); outtextxy(310,450,">>>>TODOS LOS DERECHOS RESERVADOS<<<<"); settextstyle(SANS_SERIF_FONT,VERT_DIR,2); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(60,270,"CARRERA DE ELECTRONICA"); outtextxy(40,270,"PROGRAMACION DE SISTEMAS"); settextstyle(SANS_SERIF_FONT,VERT_DIR,2); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(580,270,"CARRERA DE ELECTRONICA"); outtextxy(600,270,"PROGRAMACION DE SISTEMAS"); /*delay(9999); delay(9999); delay(60999); delay(9999);*/ /*delay(9999); delay(9999); delay(9999); delay(9999);*/ /*delay(9999); delay(9999); delay(9999); delay(9999);*/ /*delay(9999); delay(9999);*/ delay(9000); break; } } closegraph(); return(0); }
void speaker_off() { char val= inportb(SPEAKER_CTRL); outportb(SPEAKER_CTRL, val & ~SPEAKER_ENABLE & ~TIMER2_ENABLE); }
uint32 IDEDriver::doDeviceDetection() { uint32 jiffies = 0; uint16 base_port = 0x1F0; uint16 base_regport = 0x3F6; uint8 cs = 0; uint8 sc; uint8 sn; uint8 devCtrl; uint8 ata_irqs[4] = { 14, 15, 11, 9 }; // setup register values devCtrl = 0x00; // please use interrupts // assume there are no devices debug(IDE_DRIVER, "doDetection:%d\n", cs); for( cs = 0; cs < 4; cs ++) { char name[5]; name[0] = 'i'; name[1] = 'd'; name[2] = 'e'; name[3] = cs + 'a'; name[4] = '\0'; debug(IDE_DRIVER, "doDetection:Detecting IDE DEV: %s\n", name); if( cs > 1 ) { base_port = 0x170; base_regport = 0x376; } outbp( base_regport, devCtrl ); // init the device with interupts uint8 value = (cs % 2 == 0 ? 0xA0 : 0xB0 ); uint16 bpp6 = base_port + 6; uint16 bpp2 = base_port + 2; uint16 bpp3 = base_port + 3; outportb( bpp6, value ); outportb( 0x80, 0x00 ); outportb( bpp2, 0x55 ); outportb( 0x80, 0x00 ); outportb( bpp3, 0xAA ); outportb( 0x80, 0x00 ); outportb( bpp2, 0xAA ); outportb( 0x80, 0x00 ); outportb( bpp3, 0x55 ); outportb( 0x80, 0x00 ); outportb( bpp2, 0x55 ); outportb( 0x80, 0x00 ); outportb( bpp3, 0xAA ); outportb( 0x80, 0x00 ); sc = inportb( bpp2 ); outportb( 0x80, 0x00 ); sn = inportb( bpp3 ); outportb( 0x80, 0x00 ); if ( ( sc == 0x55 ) && ( sn == 0xAA ) ) { outbp( base_regport , devCtrl | 0x04 ); // RESET outbp( base_regport , devCtrl ); jiffies = 0; while (!(inbp( base_port + 7 ) & 0x58) && jiffies++ < IO_TIMEOUT) ArchInterrupts::yieldIfIFSet(); if( jiffies >= IO_TIMEOUT ) debug(IDE_DRIVER, "doDetection: Still busy after reset!\n "); else { outbp( base_port + 6, (cs % 2 == 0 ? 0xA0 : 0xB0 ) ); uint8 c1 = inbp( base_port + 2 ); uint8 c2 = inbp( base_port + 3 ); if( c1 != 0x01 && c2 != 0x01 ) debug(IDE_DRIVER, "doDetection: Not found after reset ! \n"); else { uint8 c3 = inbp( base_port + 7 ); uint8 c4 = inbp( base_port + 4 ); uint8 c5 = inbp( base_port + 5 ); if(((c4 == 0x14) && (c5 == 0xEB)) || ((c4 == 0x69) && (c5 == 0x96))) { debug(IDE_DRIVER, "doDetection: Found ATAPI ! \n"); debug(IDE_DRIVER, "doDetection: port: %4X, drive: %d \n", base_port, cs%2); debug(IDE_DRIVER, "doDetection: CDROM not supported \n"); // CDROM hook goes here // // char *name = "ATAX0"; // name[3] = cs + '0'; // drv = new CROMDriver ( base_port, cs % 2 ); // BDVirtualDevice *bdv = new // BDVirtualDevice( drv, 0, drv->getNumSectors(), // drv->getSectorSize(), name, true); // BDManager::getInstance()->addDevice( bdv ); } else { if( c3 != 0 ) { if( ( c4 == 0x00 ) && ( c5 == 0x00 ) ) { debug(IDE_DRIVER, "doDetection: Found PATA ! \n"); debug(IDE_DRIVER, "doDetection: port: %4X, drive: %d \n", base_port, cs%2); ATADriver *drv = new ATADriver( base_port, cs % 2, ata_irqs[cs] ); BDVirtualDevice *bdv = new BDVirtualDevice( drv, 0, drv->getNumSectors(), drv->getSectorSize(), name, true); BDManager::getInstance()->addVirtualDevice( bdv ); processMBR( drv, 0, drv->SPT, name ); } else if( ( c4 == 0x3C ) && ( c5 == 0xC3 ) ) { debug(IDE_DRIVER, "doDetection: Found SATA device! \n"); debug(IDE_DRIVER, "doDetection: port: %4X, drive: %d \n", base_port, cs%2); // SATA hook // drv = new SATADriver ( base_port, cs % 2 ); debug(IDE_DRIVER, "doDetection: Running SATA device as PATA in compatibility mode! \n"); ATADriver *drv = new ATADriver( base_port, cs % 2, ata_irqs[cs] ); BDVirtualDevice *bdv = new BDVirtualDevice( drv, 0, drv->getNumSectors(), drv->getSectorSize(), name, true); BDManager::getInstance()->addVirtualDevice( bdv ); processMBR( drv, 0, drv->SPT, name ); } } else { debug(IDE_DRIVER, "doDetection: Unknown harddisk!\n"); } } } } } else { debug(IDE_DRIVER, "doDetection: Not found!\n "); } } // TODO : verify if the device is ATA and not ATAPI or SATA return 0; }
void pci_write8(uint32_t id, uint32_t reg, uint8_t data) { uint32_t address = 0x80000000 | id | (reg & 0xfc); outportl(PCI_CONFIG_ADDR, address); outportb(PCI_CONFIG_DATA + (reg & 0x03), data); }
void write_serial(char a) { while (!is_transmit_empty()); outportb(PORT,a); }
int init_rtl(void) { if (rtl_device_pci) { debug_print(NOTICE, "Located an RTL 8139: 0x%x\n", rtl_device_pci); uint16_t command_reg = pci_read_field(rtl_device_pci, PCI_COMMAND, 4); debug_print(NOTICE, "COMMAND register before: 0x%4x\n", command_reg); if (command_reg & (1 << 2)) { debug_print(NOTICE, "Bus mastering already enabled.\n"); } else { command_reg |= (1 << 2); /* bit 2 */ debug_print(NOTICE, "COMMAND register after: 0x%4x\n", command_reg); pci_write_field(rtl_device_pci, PCI_COMMAND, 4, command_reg); command_reg = pci_read_field(rtl_device_pci, PCI_COMMAND, 4); debug_print(NOTICE, "COMMAND register after: 0x%4x\n", command_reg); } rtl_irq = pci_read_field(rtl_device_pci, PCI_INTERRUPT_LINE, 1); debug_print(NOTICE, "Interrupt Line: %x\n", rtl_irq); irq_install_handler(rtl_irq, rtl_irq_handler); uint32_t rtl_bar0 = pci_read_field(rtl_device_pci, PCI_BAR0, 4); uint32_t rtl_bar1 = pci_read_field(rtl_device_pci, PCI_BAR1, 4); debug_print(NOTICE, "BAR0: 0x%8x\n", rtl_bar0); debug_print(NOTICE, "BAR1: 0x%8x\n", rtl_bar1); rtl_iobase = 0x00000000; if (rtl_bar0 & 0x00000001) { rtl_iobase = rtl_bar0 & 0xFFFFFFFC; } else { debug_print(NOTICE, "This doesn't seem right! RTL8139 should be using an I/O BAR; this looks like a memory bar."); } debug_print(NOTICE, "RTL iobase: 0x%x\n", rtl_iobase); rx_wait = list_create(); debug_print(NOTICE, "Determining mac address...\n"); for (int i = 0; i < 6; ++i) { mac[i] = inports(rtl_iobase + RTL_PORT_MAC + i); } debug_print(NOTICE, "%2x:%2x:%2x:%2x:%2x:%2x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); debug_print(NOTICE, "Enabling RTL8139.\n"); outportb(rtl_iobase + RTL_PORT_CONFIG, 0x0); debug_print(NOTICE, "Resetting RTL8139.\n"); outportb(rtl_iobase + RTL_PORT_CMD, 0x10); while ((inportb(rtl_iobase + 0x37) & 0x10) != 0) { } debug_print(NOTICE, "Done resetting RTL8139.\n"); for (int i = 0; i < 5; ++i) { rtl_tx_buffer[i] = (void*)kvmalloc_p(0x1000, &rtl_tx_phys[i]); for (int j = 0; j < 60; ++j) { rtl_tx_buffer[i][j] = 0xF0; } } rtl_rx_buffer = (uint8_t *)kvmalloc_p(0x3000, &rtl_rx_phys); memset(rtl_rx_buffer, 0x00, 0x3000); debug_print(NOTICE, "Buffers:\n"); debug_print(NOTICE, " rx 0x%x [phys 0x%x and 0x%x and 0x%x]\n", rtl_rx_buffer, rtl_rx_phys, map_to_physical((uintptr_t)rtl_rx_buffer + 0x1000), map_to_physical((uintptr_t)rtl_rx_buffer + 0x2000)); for (int i = 0; i < 5; ++i) { debug_print(NOTICE, " tx 0x%x [phys 0x%x]\n", rtl_tx_buffer[i], rtl_tx_phys[i]); } debug_print(NOTICE, "Initializing receive buffer.\n"); outportl(rtl_iobase + RTL_PORT_RBSTART, rtl_rx_phys); debug_print(NOTICE, "Enabling IRQs.\n"); outports(rtl_iobase + RTL_PORT_IMR, 0x8000 | /* PCI error */ 0x4000 | /* PCS timeout */ 0x40 | /* Rx FIFO over */ 0x20 | /* Rx underrun */ 0x10 | /* Rx overflow */ 0x08 | /* Tx error */ 0x04 | /* Tx okay */ 0x02 | /* Rx error */ 0x01 /* Rx okay */ ); /* TOK, ROK */ debug_print(NOTICE, "Configuring transmit\n"); outportl(rtl_iobase + RTL_PORT_TCR, 0 ); debug_print(NOTICE, "Configuring receive buffer.\n"); outportl(rtl_iobase + RTL_PORT_RCR, (0) | /* 8K receive */ 0x08 | /* broadcast */ 0x01 /* all physical */ ); debug_print(NOTICE, "Enabling receive and transmit.\n"); outportb(rtl_iobase + RTL_PORT_CMD, 0x08 | 0x04); debug_print(NOTICE, "Resetting rx stats\n"); outportl(rtl_iobase + RTL_PORT_RXMISS, 0); net_queue = list_create(); #if 1 { debug_print(NOTICE, "Sending DHCP discover\n"); size_t packet_size = write_dhcp_packet(rtl_tx_buffer[next_tx]); outportl(rtl_iobase + RTL_PORT_TXBUF + 4 * next_tx, rtl_tx_phys[next_tx]); outportl(rtl_iobase + RTL_PORT_TXSTAT + 4 * next_tx, packet_size); next_tx++; if (next_tx == 4) { next_tx = 0; } } { struct ethernet_packet * eth = (struct ethernet_packet *)rtl_dequeue(); uint16_t eth_type = ntohs(eth->type); debug_print(NOTICE, "Ethernet II, Src: (%2x:%2x:%2x:%2x:%2x:%2x), Dst: (%2x:%2x:%2x:%2x:%2x:%2x) [type=%4x)\n", eth->source[0], eth->source[1], eth->source[2], eth->source[3], eth->source[4], eth->source[5], eth->destination[0], eth->destination[1], eth->destination[2], eth->destination[3], eth->destination[4], eth->destination[5], eth_type); struct ipv4_packet * ipv4 = (struct ipv4_packet *)eth->payload; uint32_t src_addr = ntohl(ipv4->source); uint32_t dst_addr = ntohl(ipv4->destination); uint16_t length = ntohs(ipv4->length); char src_ip[16]; char dst_ip[16]; ip_ntoa(src_addr, src_ip); ip_ntoa(dst_addr, dst_ip); debug_print(NOTICE, "IP packet [%s → %s] length=%d bytes\n", src_ip, dst_ip, length); struct udp_packet * udp = (struct udp_packet *)ipv4->payload;; uint16_t src_port = ntohs(udp->source_port); uint16_t dst_port = ntohs(udp->destination_port); uint16_t udp_len = ntohs(udp->length); debug_print(NOTICE, "UDP [%d → %d] length=%d bytes\n", src_port, dst_port, udp_len); struct dhcp_packet * dhcp = (struct dhcp_packet *)udp->payload; uint32_t yiaddr = ntohl(dhcp->yiaddr); char yiaddr_ip[16]; ip_ntoa(yiaddr, yiaddr_ip); debug_print(NOTICE, "DHCP Offer: %s\n", yiaddr_ip); free(eth); } #endif debug_print(NOTICE, "Card is configured, going to start worker thread now.\n"); debug_print(NOTICE, "Initializing netif functions\n"); init_netif_funcs(rtl_get_mac, rtl_get_packet, rtl_send_packet); create_kernel_tasklet(net_handler, "[eth]", NULL); debug_print(NOTICE, "Back from starting the worker thread.\n"); } else { return -1; } return 0; }
// Set rate in Hz for PIT ticks void pit_set_timer_phase(int16_t hz) { int16_t divisor = 1193180 / hz; /* Calculate our divisor */ outportb(0x43, 0x36); /* Set our command byte 0x36 */ outportb(0x40, divisor & 0xFF); /* Set low byte of divisor */ outportb(0x40, divisor >> 8); /* Set high byte of divisor */ }
void writeChar2Bochs( char char2Write ) { outportb( 0xE9, char2Write ); }
void shell() { char cmd[256]; char string[256]; char *user = kmalloc(24); memset(user, 0, strlen(user)); printf(LNG_USER); scanf ("%23s",user); while (!strlen(user)) { printf(LNG_USER); scanf ("%s",user); printf(LNG_USER_R); } _kclear(); aalogo(); printf("\n\n\n\n"); shell_mess = strlen (user) + 3; argc=1; for (;;) { printf("%s~# ",user); scanf("%254s",cmd); options (cmd); if (strcmp(argv[0], "help") == 0) { printf("Available commands:\n"); help(); } else if (strcmp(argv[0], "echo") == 0) { int c; for (c=1; c<argc; c++) printf ("%s ", argv[c]); printf ("\n"); } else if (strcmp(argv[0], "poweroff") == 0) { printf("Poweroff..\n"); poweroff(); } else if (strcmp(argv[0], "clear") == 0) { _kclear(); } else if (strcmp (argv[0], "uname") == 0) { /*if (argv[2] != " ") { memmove(argv[2], argv[2]+6, strlen(argv[2])); }*/ if (!(_kstrncmp(argv[1], "-a", 2)) || !(_kstrncmp(argv[1], "--all", 5))) { printf("%s %s.%s%s #1 CEST 2009 %s\n",NAME,VERSION,PATCHLEVEL,EXTRAVERSION,cpu_vendor); } else if (!(_kstrncmp(argv[1], "-r", 2)) || !(_kstrncmp(argv[1], "--rev", 5))) { printf("%s.%s%s\n",VERSION,PATCHLEVEL,EXTRAVERSION); } else if (!(_kstrncmp(argv[1], "-h", 2) ) || !(_kstrncmp(argv[1], "--help", 6))) { uname_help(); } else if (!(_kstrncmp(argv[1], "-i", 2)) || !(_kstrncmp(argv[1], "--info", 6))) { info(); } if (!(_kstrncmp(argv[1], '\0', 1))) { printf("%s\n" "For more info about this tool, please do 'uname --help'\n",NAME); } } else if (strcmp(argv[0], "cpuid") == 0) { struct cpuinfo_generic *sinfo = get_cpuid(); printf ("----- CPUID Information -----\n"); printf ("Vendor: %s\n", sinfo->cpu_vendor); printf ("Type: %s\n", sinfo->cpu_type); free (sinfo); } else if (strcmp(argv[0], "answer") == 0) { printf("42\n"); outportb('4',0xe9); } else if (strcmp(argv[0], "sleep") == 0) { int s; if (argv[1]) { s = atoi(argv[1]); if (s != -1) sleep (s); } else printf ("Missing operand\n"); } else if (strcmp(argv[0], "kmalloc") == 0) { printf("kmalloc try: ...\n"); int *b; b = (int*) kmalloc(10*sizeof(int)); printf("Address obtained: %d\n", b); int i = 0; while(i<10){ b[i] = i*2; i++; } i=0; while(i<10) { printf("b[%d] = %d\n",i, b[i]); i++; } printf("Address of a: %d\n", b); printf("Navigating used list...\n"); print_heap_list (kheap->used_list); free (b); } else if (strcmp(argv[0], "do_fault") == 0) { printf ("Genero un pagefault scrivendo 10 nella locazione 0xa0000000...\n"); int *prova; prova = (int*)0xa0000000; *prova = 10; printf ("Contenuto della locazione 0xa0000000 dopo l'intervento dell'handler: %d\n", *prova); } /*else if (!(_kstrncmp(cmd,"try_heap",8))){ try_alloc(); } else if (!(_kstrncmp(cmd,"free",4))) { unsigned int ptr = 425548; free((unsigned int*)ptr); ptr = 437836; free((unsigned int*)ptr); ptr=446028; free((unsigned int*)ptr); printf("Navigating used list...\n"); print_heap_list (kheap->used_list); printf("Navigating free list...\n"); print_heap_list (kheap->free_list); printf("Navigating free nodes...\n"); print_heap_list (kheap->free_nodes); }*/ else if (strcmp(argv[0], "printmem") == 0) print_heap_list(kheap->used_list); else if (strcmp(argv[0], "date") == 0) date(); else if (strcmp(argv[0], "aalogo") == 0) aalogo(); else if (strcmp(argv[0], "credits") == 0) { _kcolor('\011'); _kputs("DreamOS Credits\n\n"); _kputs("Main Developers:\n"); _kcolor('\012'); printf("Shainer - Lisa\n" "Finarfin - Ivan\n\n\n" ); _kcolor('\011'); _kputs("Contributors:\n"); _kcolor('\012'); _kputs("Osiris\n" "Celeron\n" "Hamcha\n" "m0nt0\n" "and many others (3 or 4 :P)\n\n"); _kcolor('\007'); } else if (strlen(cmd)>0) { printf(LNG_UNKNOWN_CMD " %s\n", argv[0]); } memset(string+5, 0, strlen(string)); memset(cmd, 0, strlen(cmd)); for (--argc; argc>=0; argc--) { free (argv[argc]); } } }
static void ISR_16550 (ComPort *p) { int count; byte source; byte b; disable(); while((source = inportb (p->uart + INTERRUPT_ID_REGISTER) & 0x07) != 1) { switch (source) { case IIR_RX_DATA_READY_INTERRUPT: do { b = inportb (p->uart + RECEIVE_BUFFER_REGISTER); if (!FULL(p->inputQueue)) { ENQUEUE (p->inputQueue, b); } else { p->lineStatus |= LSR_OVERRUN_ERROR; p->statusUpdated = true; } } while (inportb (p->uart + LINE_STATUS_REGISTER) & LSR_DATA_READY); break; case IIR_TX_HOLDING_REGISTER_INTERRUPT: count = 16; while ((! EMPTY(p->outputQueue)) && count--) { DEQUEUE (p->outputQueue, b); outportb (p->uart + TRANSMIT_HOLDING_REGISTER, b); } break; case IIR_MODEM_STATUS_INTERRUPT: p->modemStatus = (inportb (p->uart + MODEM_STATUS_REGISTER) & MODEM_STATUS_MASK) | p->modemStatusIgnore; p->statusUpdated = true; break; case IIR_LINE_STATUS_INTERRUPT: p->lineStatus = inportb (p->uart + LINE_STATUS_REGISTER); p->statusUpdated = true; break; } source = inportb (p->uart + INTERRUPT_ID_REGISTER) & 0x07; } // check for lost IIR_TX_HOLDING_REGISTER_INTERRUPT on 16550a! if (inportb (p->uart + LINE_STATUS_REGISTER ) & LSR_TRANSMITTER_EMPTY) { count = 16; while ((! EMPTY(p->outputQueue)) && count--) { DEQUEUE (p->outputQueue, b); outportb (p->uart + TRANSMIT_HOLDING_REGISTER, b); } } outportb (0x20, 0x20); }
void inti_floppy() { int i; unsigned char c, a, b; // these are the internal names... they can change, since it really doesn't matter what the floppy drives are called :) floppy_drives[0].name = "fda"; floppy_drives[1].name = "fdb"; outportb(0x70, 0x10); // select floppy drive type byte in CMOS c = inportb(0x71); if(c == 0x00) { k_printf("No floppy drive(s) detected.\n"); return; }; a = c >> 4; b = c & 0x0F; floppy_drives[0].type = a; floppy_drives[1].type = b; switch(floppy_drives[0].type) { case 0x04: k_printf("Floppy drive A found(1.44 MB 3.5 Drive).\n"); break; case 0x00: k_printf("No A floppy drive found.\n"); break; case 0x05: k_printf("Floppy drive A found(2.88 MB 3.5 drive).\n"); break; case 0x01: k_printf("Floppy drive A found(360 KB 5.25 Drive).\n"); break; case 0x02: k_printf("Floppy drive A found(1.2 MB 5.25 Drive).\n"); break; case 0x03: k_printf("Floppy drive A found(720 KB 3.5 Drive).\n"); break; default: k_printf("Unknown A floppy drive type.\n"); break; }; switch(floppy_drives[1].type) { case 0x04: k_printf("Floppy drive B found(1.44 MB 3.5 Drive).\n"); break; case 0x00: k_printf("No B floppy drive found.\n"); break; case 0x01: k_printf("Floppy drive B found(360 KB 5.25 Drive).\n"); break; case 0x02: k_printf("Floppy drive B found(1.2 MB 5.25 Drive).\n"); break; case 0x03: k_printf("Floppy drive B found(720 KB 3.5 Drive).\n"); break; case 0x05: k_printf("Floppy drive B found(2.88 MB 3.5 drive).\n"); break; default: k_printf("Unknown B floppy drive type.\n"); break; }; if(floppy_drives[0].type != 1 && floppy_drives[0].type != 2) // most common { floppy_drives[0].GAP3 = 27; } else { floppy_drives[0].GAP3 = 42; }; if(floppy_drives[1].type != 1 && floppy_drives[1].type != 2) // most common { floppy_drives[1].GAP3 = 27; } else { floppy_drives[1].GAP3 = 42; }; };