/* initialize interrupt table so the handler can match addresses with interrupt numbers */ void interrupt_table_init( ){ long keyboard_address; long interrupt_address; long interrupt_table_ptr[2]; keyboard_address = (long)keyboard_handler; IDT[0x21].offset_lower_bits = keyboard_address & 0xffff; IDT[0x21].selector = 0x08; IDT[0x21].zero = 0; IDT[0x21].flag_type = 0x8e; IDT[0x21].offset_higher_bits = (keyboard_address & 0xffff0000) >> 16; /* remaps PCI interrupts to avoid double faults in protected mode*/ out_port(0x20 , 0x11); out_port(0xA0 , 0x11); out_port(0x21 , 0x20); out_port(0xA1 , 0x28); out_port(0x21 , 0x00); out_port(0xA1 , 0x00); out_port(0x21 , 0x01); out_port(0xA1 , 0x01); out_port(0x21 , 0xff); out_port(0xA1 , 0xff); interrupt_address = (long)IDT ; interrupt_table_ptr[0] = (sizeof (struct Interrupt_Table_Entry) * 256) + ((interrupt_address & 0xffff) << 16); interrupt_table_ptr[1] = interrupt_address >> 16 ; load_interupt_loc(interrupt_table_ptr); }
/* not implemented correctly function to move flashing cursor */ void move_cursor( int curr_loc ){ int temp; //temp = 10 * 80 + 2; temp = curr_loc; out_port(0x3D4, 14); out_port(0x3D5, temp >> 8); out_port(0x3D4, 15); out_port(0x3D5, temp); }
int main(void) { USHORT in_stuff; in_stuff = in_port (INPUT_PORT); out_port (OUTPUT_PORT,TEST_DATA); }
void int_timer1(void){ TCCR1B=0x00; out_port(); TCNT1H=time_h_1; TCNT1L=time_l_1; TCCR1B=0x05; return; }
void out_addr(int addr) { int temp; out_port(addr&0xff,0); temp=port[1]; temp&=~0xf; temp|=(addr>>8)&0xf; out_port(temp, 1); temp=port[3]; temp&=~0x41; if (addr&0x1000) temp|=0x40; if (addr&0x2000) temp|=1; out_port(temp,3); }
int main(void) { int value, i; unsigned char data[0x4000]; FILE *file; ioperm(PORT_BASE,8,1); out_port(0,0); out_port(0,1); // CS on out_port(0,2); // out_port(0,6); // vpp off out_port(4,3); // VCC on, VCC=5V, Socket=24pin, /OE=0, read wait_ticks (100000); // for (i=0; i<0x40; i++) { for (i=0; i<0x4000; i++) { out_addr(i); wait_ticks(100); value=inb(PORT_BASE+4); data[i]=value; if ((i&0xf)==0) printf("%.4x:",i); printf(" %.2x", value); if ((i&0xf)==0xf) printf("\n"); } out_port(0xf8,2); // led off out_port(0,3); //VCC off out_port(0,6); //VPP off out_port(0,0); file=fopen("dil24.bin","wb"); fwrite(data,1,sizeof(data),file); fclose(file); return 0; }
void keyboard_main( ){ char status; char key_code; out_port(0x20, 0x20); status = in_port(0x64); // io pressed key port for keyboards if (status & 0x01) { key_code = in_port(0x60); // io status key port for keyboard if(key_code < 0) return; if(key_code == 0x1C) { // check if it's the enter key that was pressed print_newline(); return; } VGA[curr_loc++] = keyboard_map[(unsigned char) key_code]; VGA[curr_loc++] = 0x07; } }
/* initialize keyboard interrupt requests */ void keyboard_init( ){ out_port(0x21 , 0xFD); }
uint8_t GoLine(void) { register uint8_t li; register uint8_t *lp; register unsigned int bi; //printf("\n#%d:%s\n",CLine,CmdInp); //printf("\n*lnum=%d A=%d\n",CLine,Vars[0]); Gp = CmdInp + 1; switch(CmdInp[0]){ case STOP: STOPPROG(ESTOP); case BEEP: lp = findchar(CmdInp, ','); if(lp) { *lp = 0; bi = ExpPars1(); Gp=lp+1; Beep(bi,ExpPars1()); } return(0); case DIM: Gp+=2;//( li = ExpPars1(); if(CmdInp[1] != SIGNEDBYTE && CmdInp[1] != UNSIGNEDBYTE)//type of array li = li << 1;//two byte on item if(li <= (MAXBMEMSIZE-1)){ /* lp = Vars[TOVAR(CmdInp[1])]; if(lp > FirstPrgLine) lfree(lp);*/ lp = lmalloc(li+1,LlP); if(!lp) STOPPROG(EALLOC); *lp = CmdInp[1];//type of array lp++; //printf("\n*%p %c %d %d %s\n",lp,*(lp-1),*(lp-2),li,CmdInp); li = CmdInp[2];//name of array // if(SYMISVAR(li)) Vars[TOVAR(li)] = (unsigned int)lp; return(0); } STOPPROG(EERROR); return(0); case LET: lp = findchar(CmdInp, '='); Gp = lp+1; bi = ExpPars1(); // if(!SYMISVAR(li)) if(*(lp-1) == ')'){ *lp = 0; Gp = CmdInp+2;// '(' li = ExpPars1();//array index lp = (uint8_t *)Vars[TOVAR(CmdInp[1])]; //printf("\n+%p %c %d %d %d\n",lp,*(lp-1),*(lp-2),li,bi); if(*(lp-2) > (li+2)){// switch(*(lp-1)){//type of array case SIGNEDBYTE: *(((char *)lp + li)) = bi; break; case UNSIGNEDBYTE: *(((uint8_t *)lp + li)) = bi; break; default: // case SIGNEDWORD: *(((int *)lp + li)) = bi; break; /* case UNSIGNEDWORD: *(((unsigned int *)lp + li)) = bi; break; */ } } else STOPPROG(EERROR);//TODO } else Vars[TOVAR(CmdInp[1])] = bi; return(0); case AT: lp = findchar(CmdInp, ','); if(lp) { *lp = 0; li = ExpPars1();//x if(li< LCDTWIDTH) #ifdef AVR xt=li*LCDSYMWIDTH; else xt=(LCDTWIDTH-1)*LCDSYMWIDTH; #else xt=li; else xt=(LCDTWIDTH-1); #endif Gp=lp+1; li = ExpPars1();//y if(li< LCDTHEIGHT) yt=li; else yt=LCDTHEIGHT-1; #ifdef AVR st7565_command(CMD_SET_DISP_START_LINE | ((LCDTHEIGHT-1)*8)+8); #else printf( "%c[%d;%dH", 27, yt+1, xt+1 ); // установили курсор в позицию fflush( stdout ); #endif } return(0); case OUT: lp = findchar(CmdInp, ','); if(lp) { *lp = 0; li = ExpPars1();//port Gp=lp+1; out_port(li,ExpPars1()); } return(0); case REM: return(0); case LOAD: FreePrg(); ReplaceChar(CmdInp+2, '"', 0); loadprg((const char *)(CmdInp+2)); PrgLineP = FirstPrgLine; return(1); case INPUT: lp = (uint8_t *)(Vars + TOVAR(CmdInp[1]));//pointer to var Gp++;//to '(' or 0 if(*Gp == '(') li = ExpPars1();//index else li = 255; lgets(CmdInp); if(CmdInp[0]==BREAK_KEY) STOPPROG(EINTERUPT); Gp=CmdInp; bi = ExpPars1(); if(li < MAXBMEMSIZE){ lp = (uint8_t *)(*((unsigned int *)lp)); if(*(lp-2) > (li+2)){// switch(*(lp-1)){//type of array case SIGNEDBYTE: *(((char *)lp + li)) = bi; break; case UNSIGNEDBYTE: *(((uint8_t *)lp + li)) = bi; break; default: *(((int *)lp + li)) = bi; break; } } else STOPPROG(EERROR);//TODO } else *lp = (int)bi; return(0); case IF: lp = findchar(CmdInp, THEN); if(lp){ *lp = 0; if(ExpPars1()){ strcpy((char *)CmdInp,(const char *)(lp+1)); return(2);; } }else STOPPROG(EERROR); return(0); case PRINT: li = strlen((const char *)CmdInp); while(Gp && *Gp){ if(*Gp == '"'){ Gp++; lp =findchar(Gp ,'"'); *lp = 0; lputs((char *)(Gp)); Gp = lp+1; } else{ if(*Gp == '$'){ Gp++; lputchar(ExpPars1()); } else lputint(ExpPars1()); } //printf("\n++ %s\n",Gp); Gp =findchar(Gp ,','); if(Gp) Gp++; } if(CmdInp[li-1]!=';') lputchar('\n'); return(0); case PAUSE: bi = ExpPars1(); delay_ms(bi); return(0); case GOTO: PrgLineP = GetPrgLine(ExpPars1(),0); if(!PrgLineP){ STOPPROG(EGOTONOWHERE); } return(1) ; case GOSUB: SubStack[SubStackP] = PrgLineP->next; SubStackP++; if(SubStackP >= SMAX){ STOPPROG(EGSOVF); } PrgLineP = GetPrgLine(ExpPars1(),0); if(!PrgLineP){ STOPPROG(EGOTONOWHERE); } return(1); case RETURN: if(SubStackP < 1){ STOPPROG(ERETWOG); } --SubStackP; PrgLineP = SubStack[SubStackP]; return(1); case FOR : lp = findchar(CmdInp, TO); if(lp){ *lp = 0; Gp = CmdInp+ 3; li = TOVAR(CmdInp[1]); if(li>LMAX) STOPPROG(ELOPSOVF); Vars[li] = ExpPars1(); Gp = lp + 1; LoopVar[li].var_to = ExpPars1(); LoopVar[li].line_begin = PrgLineP->next; }else STOPPROG(EERROR); return(0); case NEXT: li = TOVAR(CmdInp[1]); if(++Vars[li] <= LoopVar[li].var_to){ PrgLineP = LoopVar[li].line_begin; return(1); } break; }