main(int argc,char *argv[]) { char huge *sptemp; int huge *ip; unsigned int u; char huge *cp; int a,b,c,d,e,f,g,x,y,z; #ifdef DEBUG fr=fopen("tmp","wt"); #endif indemo=1; dis_partstart(); sprintf(tmpname,"%s.00M",scene); if(!indemo) printf("Loading materials %s...\n",tmpname); scene0=scenem=readfile(tmpname); memcpy(scene0+16+192*3,bg+16,64*3); bg2=halloc(16384,4); for(u=z=0;z<4;z++) { for(y=0;y<200;y++) { for(x=z;x<320;x+=4) { a=bg[16+768+x+y*320]; bg2[u++]=a; } } } memcpy(bg,bg2,64000); hfree(bg2); if(scene0[15]=='C') city=1; if(scene0[15]=='R') city=2; ip=(int huge *)(scene0+LONGAT(scene0+4)); conum=d=*ip++; for(f=-1,c=1;c<d;c++) { e=*ip++; if(e>f) { f=e; sprintf(tmpname,"%s.%03i",scene,e); if(!indemo) printf("Loading %s... ",tmpname); co[c].o=vis_loadobject(tmpname); memset(co[c].o->r,0,sizeof(rmatrix)); memset(co[c].o->r0,0,sizeof(rmatrix)); co[c].index=e; co[c].on=0; if(!indemo) printf("(co[%i]:%s)\n",c,co[c].o->name); } else { if(!indemo) printf("Copying %s.%03i... ",scene,e); for(g=0;g<c;g++) if(co[g].index==e) break; memcpy(co+c,co+g,sizeof(struct s_co)); co[c].o=getmem(sizeof(object)); memcpy(co[c].o,co[g].o,sizeof(object)); co[c].o->r=getmem(sizeof(rmatrix)); co[c].o->r0=getmem(sizeof(rmatrix)); memset(co[c].o->r,0,sizeof(rmatrix)); memset(co[c].o->r0,0,sizeof(rmatrix)); co[c].on=0; if(!indemo) printf("(co[%i]:%s)\n",c,co[c].o->name); } } co[0].o=&camobject; camobject.r=&cam; camobject.r0=&cam; sprintf(tmpname,"%s.0AA",scene); if(!indemo) printf("Loading animations...\n",tmpname); ip=readfile(tmpname); while(*ip) { a=*ip; if(a==-1) break; sprintf(tmpname,"%s.0%c%c",scene,a/10+'A',a%10+'A'); if(!indemo) printf("Scene: %s ",tmpname); scenelist[scl].data=readfile(tmpname); printf("(%i:@%Fp)\n",scl,scenelist[scl].data); scl++; ip+=2; } if(!indemo) { printf("Press any key to continue..."); getch(); } resetscene(); for(;;) { _asm { mov bx,6 int 0fch mov a,cx mov b,bx } if(a>10 && b>46) break; if(dis_exit()) return; } vid_init(3); ////// oversample x 4 cp=(char *)(scenem+16); //vid_setpal(cp); outp(0x3c8,0); for(a=0;a<768;a++) outp(0x3c9,cp[a]); vid_window(0L,319L,25L,174L,512L,9999999L); dis_setcopper(2,copper2); dis_partstart(); xit=0; coppercnt=0; syncframe=0; avgrepeat=1; cl[0].ready=0; cl[1].ready=0; cl[2].ready=0; cl[3].ready=1; while(!dis_exit() && !xit) { int fov; int onum; long pflag; long dis; long l; object *o; rmatrix *r; _asm { mov bx,6 int 0fch mov a,cx mov b,bx } if(a>11 && b>54) break; deadlock=0; while(cl[clw].ready) { if(deadlock>16) break; } // Draw to free frame vid_setswitch(clw,-1); vid_clearbg(bg); // Field of vision vid_cameraangle(fov); // Calc matrices and add to order list (only enabled objects) ordernum=0; /* start at 1 to skip camera */ for(a=1;a<conum;a++) if(co[a].on) { order[ordernum++]=a; o=co[a].o; memcpy(o->r,o->r0,sizeof(rmatrix)); calc_applyrmatrix(o->r,&cam); b=o->pl[0][1]; // center vertex co[a].dist=calc_singlez(b,o->v0,o->r); } // Zsort if(city==1) { co[2].dist=1000000000L; // for CITY scene, test co[7].dist=1000000000L; // for CITY scene, test co[13].dist=1000000000L; // for CITY scene, test } if(city==2) { co[14].dist=1000000000L; // for CITY scene, test } for(a=0;a<ordernum;a++) { dis=co[c=order[a]].dist; for(b=a-1;b>=0 && dis>co[order[b]].dist;b--) order[b+1]=order[b]; order[b+1]=c; } // Draw for(a=0;a<ordernum;a++) { int x,y; o=co[order[a]].o; vis_drawobject(o); } // **** Drawing completed **** // // calculate how many frames late of schedule avgrepeat=(avgrepeat+(syncframe-currframe)+1)/2; repeat=avgrepeat; if(repeat<1) repeat=1; cl[clw].frames=repeat; cl[clw].ready=1; clw++; clw&=3; // advance that many frames repeat=repeat; currframe+=repeat; while(repeat-- && !xit) { // parse animation stream for 1 frame onum=0; while(!xit) { a=*sp++; if(a==0xff) { a=*sp++; if(a<=0x7f) { fov=a<<8; break; } else if(a==0xff) { resetscene(); xit=1; continue; } } if((a&0xc0)==0xc0) { onum=((a&0x3f)<<4); a=*sp++; } onum=(onum&0xff0)|(a&0xf); b=0; switch(a&0xc0) { case 0x80 : b=1; co[onum].on=1; break; case 0x40 : b=1; co[onum].on=0; break; } #ifdef DEBUG if(b) fprintf(fr,"[%i (%s) ",onum,co[onum].on?"on":"off"); else fprintf(fr,"[%i (--) ",onum,co[onum].on?"on":"off"); #endif if(onum>=conum) { return(3); } r=co[onum].o->r0; pflag=0; switch(a&0x30) { case 0x00 : break; case 0x10 : pflag|=*sp++; break; case 0x20 : pflag|=sp[0]; pflag|=(long)sp[1]<<8; sp+=2; break; case 0x30 : pflag|=sp[0]; pflag|=(long)sp[1]<<8; pflag|=(long)sp[2]<<16; sp+=3; break; } #ifdef DEBUG fprintf(fr,"pfl:%06lX",pflag); #endif l=lsget(pflag); r->x+=l; l=lsget(pflag>>2); r->y+=l; l=lsget(pflag>>4); r->z+=l; #ifdef DEBUG fprintf(fr," XYZ:(%li,%li,%li)",r->x,r->y,r->z); #endif if(pflag&0x40) { // word matrix for(b=0;b<9;b++) if(pflag&(0x80<<b)) { r->m[b]+=lsget(2); } } else { // byte matrix for(b=0;b<9;b++) if(pflag&(0x80<<b)) { r->m[b]+=lsget(1); } } #ifdef DEBUG fprintf(fr,"]\n"); #endif } } } dis_setcopper(2,NULL); vid_setswitch(0,-1); vid_clearbg(bg); vid_setswitch(1,-1); vid_clearbg(bg); vid_setswitch(2,-1); vid_clearbg(bg); vid_setswitch(3,-1); vid_clearbg(bg); if(!dis_indemo()) { vid_deinit(); } #ifdef DEBUG fclose(fr); #endif return(0); }
void Decompress_frame (void) { unsigned short x,y,z,w; unsigned short changes, nfo_word, packets, offset, row; int frame_pos=0; unsigned int scr_pos; char c1, c2, c3, a; char hi, lo; for (z=1; z<=h_frame.actions; z++) { memmove ( &h_action, (flc_buffer+frame_pos), sizeof(actionheader) ); switch (h_action.code) { case 4: a=1;//fcl_buffer[frame_pos]; // b=0;//flc_buffer[frame_pos]; // c=256; //0=256 frame_pos+=10; outp (0x3c8, 0); for (x=0; x<=768; x++) outp (0x3c9, (flc_buffer[(x+frame_pos)]/=4) ); frame_pos+=768; break; case 7: frame_pos+=6; lo=flc_buffer[frame_pos]; frame_pos++; hi=flc_buffer[frame_pos]; frame_pos++; changes=hi*256+lo; row=0; for (y=0; y<=(changes-1); y++) // pocet menenych radek { lo=flc_buffer[frame_pos]; frame_pos++; hi=flc_buffer[frame_pos]; frame_pos++; nfo_word=hi*256+lo; scr_pos=row*h_flc.width; if (nfo_word>=0xC000) // preskakovane radky { nfo_word=0xFFFF-nfo_word+1; row+=nfo_word; } else { for (z=1; z<=nfo_word; z++) // pocet menenych bloku { x=1; a=0; offset = flc_buffer[frame_pos]; // rel. offset bloku frame_pos++; scr_pos+=offset; // while (!a) // zmena bloku // { c1 = flc_buffer[frame_pos]; frame_pos++; if (c1>128) { c1=0xFF-c1+1; c2=flc_buffer[frame_pos]; frame_pos++; c3=flc_buffer[frame_pos]; frame_pos++; for (w=1; w<=c1; w++) { frame_buffer[scr_pos]=c2; scr_pos++; frame_buffer[scr_pos]=c3; scr_pos++; } } else { // c3=0xFF-c3+1; for (w=1; w<=c1; w++) { frame_buffer[scr_pos]=flc_buffer[frame_pos]; frame_pos++; scr_pos++; frame_buffer[scr_pos]=flc_buffer[frame_pos]; frame_pos++; scr_pos++; } } // if (x>=640) a=1; // } } row++; } } // frame_pos+=h_action.size; break; case 15: frame_pos+=6; for (y=0; y<=(h_flc.height-1); y++) { frame_pos++; x=1; //a=0; scr_pos=y*h_flc.width; while (x<=h_flc.width) { c1 = flc_buffer[frame_pos]; frame_pos++; if (c1<128) { c2=flc_buffer[frame_pos]; frame_pos++; for (w=1; w<=c1; w++) { frame_buffer[scr_pos]=c2; scr_pos++; x++; } } else { c1=0xFF-c1+1; for (w=1; w<=c1; w++) { frame_buffer[scr_pos]=flc_buffer[frame_pos]; scr_pos++; frame_pos++; x++; } } } } break; default: frame_pos+=h_action.size; break; }; } }
void SelfAwareness::iam(const Address &reporter,const InetAddress &reporterPhysicalAddress,const InetAddress &myPhysicalAddress,bool trusted,uint64_t now) { const InetAddress::IpScope scope = myPhysicalAddress.ipScope(); // This would be weird, e.g. a public IP talking to 10.0.0.1, so just ignore it. // If your network is this weird it's probably not reliable information. if (scope != reporterPhysicalAddress.ipScope()) return; // Some scopes we ignore, and global scope IPs are only used for this // mechanism if they come from someone we trust (e.g. a root). switch(scope) { case InetAddress::IP_SCOPE_NONE: case InetAddress::IP_SCOPE_LOOPBACK: case InetAddress::IP_SCOPE_MULTICAST: return; case InetAddress::IP_SCOPE_GLOBAL: if (!trusted) return; break; default: break; } Mutex::Lock _l(_phy_m); PhySurfaceEntry &entry = _phy[PhySurfaceKey(reporter,reporterPhysicalAddress,scope)]; if ( ((now - entry.ts) < ZT_SELFAWARENESS_ENTRY_TIMEOUT) && (!entry.mySurface.ipsEqual(myPhysicalAddress)) ) { entry.mySurface = myPhysicalAddress; entry.ts = now; TRACE("physical address %s for scope %u as seen from %s(%s) differs from %s, resetting paths in scope",myPhysicalAddress.toString().c_str(),(unsigned int)scope,reporter.toString().c_str(),reporterPhysicalAddress.toString().c_str(),entry.mySurface.toString().c_str()); // Erase all entries in this scope that were not reported from this remote address to prevent 'thrashing' // due to multiple reports of endpoint change. // Don't use 'entry' after this since hash table gets modified. { Hashtable< PhySurfaceKey,PhySurfaceEntry >::Iterator i(_phy); PhySurfaceKey *k = (PhySurfaceKey *)0; PhySurfaceEntry *e = (PhySurfaceEntry *)0; while (i.next(k,e)) { if ((k->reporterPhysicalAddress != reporterPhysicalAddress)&&(k->scope == scope)) _phy.erase(*k); } } // Reset all paths within this scope _ResetWithinScope rset(RR,now,(InetAddress::IpScope)scope); RR->topology->eachPeer<_ResetWithinScope &>(rset); // Send a NOP to all peers for whom we forgot a path. This will cause direct // links to be re-established if possible, possibly using a root server or some // other relay. for(std::vector< SharedPtr<Peer> >::const_iterator p(rset.peersReset.begin());p!=rset.peersReset.end();++p) { if ((*p)->activelyTransferringFrames(now)) { Packet outp((*p)->address(),RR->identity.address(),Packet::VERB_NOP); RR->sw->send(outp,true,0); } } } else { entry.mySurface = myPhysicalAddress; entry.ts = now; } }
void __interrupt __far timer_handler( union INTPACK r ) { if( --TimerMod == 0 ) { TimerMod = TimerMult; _CHAIN_TO( old_timer_handler ); } else { /* end of interrupt (expected by 8259 before you do RETI) */ outp( INT_CTRL, EOI ); } if( ! SamplerOff ) { if( InsiderTime == 0 ) { ++InsiderTime; if( SampleIndex == 0 ) { Samples->pref.tick = CurrTick; if( CallGraphMode ) { CallGraph->pref.tick = CurrTick; } } ++CurrTick; #ifdef __NETWARE__ /* avoid pointer truncation warning */ RecordSample( (union INTPACK *)FP_OFF(&r) ); #else RecordSample( &r ); #endif if( SampleIndex >= Margin ) { if( InDOS() ) { Save_Request = TRUE; } else { /* We are not in DOS so we can suspend things for a while and save our block of samples */ if( Save_Request ) { Save_Request = 0; } StopAndSave(); } if( SampleIndex >= Ceiling ) { if( CallGraphMode ) { --SampleCount; SampleIndex = LastSampleIndex; } else { --SampleIndex; } LostData = TRUE; } } --InsiderTime; } } }
static void set_timer_reload(int reload_val) { outp(PORT_CMD, CMD_CHAN0 | CMD_ACCESS_BOTH | CMD_OP_SQWAVE); outp(PORT_DATA0, reload_val & 0xff); outp(PORT_DATA0, (reload_val >> 8) & 0xff); }
main() { int a,b,c,y; dis_partstart(); outp(0x3c4,2); outp(0x3c5,15); memset(vram,15,32768); memset(vram+32768,15,32768); //_asm mov ax,80h+13h //_asm int 10h for(a=0;a<32;a++) dis_waitb(); outp(0x3c8,0); for(a=0;a<255;a++) { outp(0x3c9,63); outp(0x3c9,63); outp(0x3c9,63); } outp(0x3c9,0); outp(0x3c9,0); outp(0x3c9,0); inp(0x3da); outp(0x3c0,0x11); outp(0x3c0,255); outp(0x3c0,0x20); //inittwk(); _asm { mov dx,3d4h mov ax,000ch out dx,ax mov ax,000dh out dx,ax mov al,9 out dx,al inc dx in al,dx and al,not 80h and al,not 31 out dx,al mov dx,3c0h mov al,11h out dx,al mov al,0 out dx,al mov al,32 out dx,al } _asm { mov dx,3c0h mov al,11h out dx,al mov al,255 out dx,al mov al,20h out dx,al } readp(palette,-1,pic); for(y=0;y<400;y++) { readp(rowbuf,y,pic); lineblit(vram+(unsigned)y*80U,rowbuf); } for(c=0;c<=128;c++) { for(a=0;a<768-3;a++) pal2[a]=((128-c)*63+palette[a]*c)/128; dis_waitb(); setpalarea(pal2,0,254); } setpalarea(palette,0,254); }
void main ( void ) { uchar *video=( uchar * )0xA0000000L; uint pos,x; _asm mov ax,13h _asm int 10h outp( 0x3c8,0 ); for( x=0; x<256; x++ ) { outp( 0x3c9,x >> 2 ); outp( 0x3c9,x >> 2 ); outp( 0x3c9,63 ); } /* sprot. CRT */ outp( 0x3d4, 0x11 ); outp( 0x3d5, inp( 0x3d5 ) & 0x7f ); /* 256 */ /* ampiezza logica */ _outcrt( 0x13, 32 ); /* tot hor */ _outcrt( 0, 64 + 16 ); /* fine vis. hor */ _outcrt( 1, 63 ); /* iniz blank hor */ _outcrt( 2, 69 ); /* fin blank hor */ _outcrt( 3, 113 ); /* iniz. ritr. oriz */ _outcrt( 4, 72 ); /* fine ritr. oriz */ _outcrt( 5, 112 ); /* 240 */ /* _outcrt( 6, 13 ); _outcrt( 7, 62 ); _outcrt( 9, 65 ); _outcrt( 0x10, 234 ); _outcrt( 0x11, 172 ); _outcrt( 0x12, 223 ); _outcrt( 0x14, 0 ); _outcrt( 0x15, 231 ); _outcrt( 0x16, 6 ); _outcrt( 0x17, 227 ); outpw( 0x3c4, 0x0100 ); outp( 0x3c2, 0xe3 ); outpw( 0x3c4, 0x0300 ); */ /* prot. CRT */ outp( 0x3d4, 0x11 ); outp( 0x3d5, inp( 0x3d5 ) | 256 ); for( pos=0; pos<256; pos++ ) for( x=0; x<256; x++ ) video[ ( pos << 8 ) | x ]= ( unsigned char ) ( pos + x ); getch(); _asm mov ax,3h _asm int 10h }
// #define LM78_WRITE(addr,data) outp(LM78_ADDRESS,addr);outp(LM78_DATA,data) void LM78_WRITE(int addr, int data) { outp(LM78_ADDRESS, addr); outp(LM78_DATA, data); }
/* Set up uart stuff; expects DDR register to already be set up */ void serial_init_rx(void) { outp(BPS(115200, CPUFREQ), UBRR); outp(inp(UCR) | (1 << RXCIE) | (1 << RXEN), UCR); }
int LM78_EXIST(void) { outp(LM78_ADDRESS,LM78_IN0); inp(LM78_DATA); return(inp(LM78_ADDRESS) == LM78_IN0); }
// #define LM78_READ(addr) ({outp(LM78_ADDRESS,addr);inp(LM78_DATA);}) int LM78_READ(int addr) { outp(LM78_ADDRESS,addr); return(inp(LM78_DATA)); }
/* Output a word to an I/O port. */ static void out_word(unsigned int p,unsigned int d) { outp(p, d & 0xff); outp(p + 1, (d >> 8) & 0xff); }
int up_addrenv_restore(hw_addrenv_t oldenv) { outp(Z180_MMU_CBR, (uint8_t)oldenv); return OK; }
void __interrupt __far key_handler() { unsigned char scancode, breakbit, temp; unsigned short keycode; #ifndef WATCOM_10 #ifndef NDEBUG ubyte * MONO = (ubyte *)(0x0b0000+24*80*2); if ( ((MONO[0]=='D') && (MONO[2]=='B') && (MONO[4]=='G') && (MONO[6]=='>')) || ((MONO[14]=='<') && (MONO[16]=='i') && (MONO[18]=='>') && (MONO[20]==' ') && (MONO[22]=='-')) || ((MONO[0]==200 ) && (MONO[2]==27) && (MONO[4]==17) ) ) _chain_intr( key_data.prev_int_9 ); #endif #endif // Read in scancode scancode = inp( 0x60 ); switch( scancode ) { case 0xE0: key_data.E0Flag = 0x80; break; default: // Parse scancode and break bit if (key_data.E1Flag > 0 ) { // Special code for Pause, which is E1 1D 45 E1 9D C5 key_data.E1Flag--; if ( scancode == 0x1D ) { scancode = KEY_PAUSE; breakbit = 0; } else if ( scancode == 0x9d ) { scancode = KEY_PAUSE; breakbit = 1; } else { break; // skip this keycode } } else if ( scancode==0xE1 ) { key_data.E1Flag = 2; break; } else { breakbit = scancode & 0x80; // Get make/break bit scancode &= 0x7f; // Strip make/break bit off of scancode scancode |= key_data.E0Flag; // Add in extended key code } key_data.E0Flag = 0; // Clear extended key code if (breakbit) { // Key going up keyd_last_released = scancode; keyd_pressed[scancode] = 0; key_data.NumUps[scancode]++; temp = 0; temp |= keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT]; temp |= keyd_pressed[KEY_LALT] || keyd_pressed[KEY_RALT]; temp |= keyd_pressed[KEY_LCTRL] || keyd_pressed[KEY_RCTRL]; #ifndef NDEBUG temp |= keyd_pressed[KEY_DELETE]; if ( !(keyd_editor_mode && temp) ) #endif // NOTICE LINK TO ABOVE IF!!!! key_data.TimeKeyHeldDown[scancode] += timer_get_fixed_secondsX() - key_data.TimeKeyWentDown[scancode]; } else { // Key going down keyd_last_pressed = scancode; keyd_time_when_last_pressed = timer_get_fixed_secondsX(); if (!keyd_pressed[scancode]) { // First time down key_data.TimeKeyWentDown[scancode] = timer_get_fixed_secondsX(); keyd_pressed[scancode] = 1; key_data.NumDowns[scancode]++; #ifndef NDEBUG if ( (keyd_pressed[KEY_LSHIFT]) && (scancode == KEY_BACKSP) ) { keyd_pressed[KEY_LSHIFT] = 0; Int5(); } #endif } else if (!keyd_repeat) { // Don't buffer repeating key if repeat mode is off scancode = 0xAA; } if ( scancode!=0xAA ) { keycode = scancode; if ( keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT] ) keycode |= KEY_SHIFTED; if ( keyd_pressed[KEY_LALT] || keyd_pressed[KEY_RALT] ) keycode |= KEY_ALTED; if ( keyd_pressed[KEY_LCTRL] || keyd_pressed[KEY_RCTRL] ) keycode |= KEY_CTRLED; #ifndef NDEBUG if ( keyd_pressed[KEY_DELETE] ) keycode |= KEY_DEBUGGED; #endif temp = key_data.keytail+1; if ( temp >= KEY_BUFFER_SIZE ) temp=0; if (temp!=key_data.keyhead) { key_data.keybuffer[key_data.keytail] = keycode; key_data.time_pressed[key_data.keytail] = keyd_time_when_last_pressed; key_data.keytail = temp; } } } } #ifndef NDEBUG #ifdef PASS_KEYS_TO_BIOS _chain_intr( key_data.prev_int_9 ); #endif #endif temp = inp(0x61); // Get current port 61h state temp |= 0x80; // Turn on bit 7 to signal clear keybrd outp( 0x61, temp ); // Send to port temp &= 0x7f; // Turn off bit 7 to signal break outp( 0x61, temp ); // Send to port outp( 0x20, 0x20 ); // Reset interrupt controller }
static void outwGUS(unsigned int baseport,unsigned int reg,unsigned int val) { outp(baseport+0x103, reg); outpw(baseport+0x104, val); }
// Initialize_timer_frequency to ~2.8ms. void initialize_timer_frequency( void ) { outp( 0x42, 0x3c ); outp( 0x40, 0x00 ); outp( 0x40, 0x10 ); }
static unsigned int inGUS(unsigned int baseport,unsigned int reg) { outp(baseport+0x103, reg); return inp(baseport+0x105); }
int _RTL_FUNC _outp(unsigned short port, int val) { return outp(port, val); }
void pulse_width_test() { int fd; unsigned char cc; unsigned int play; unsigned char plan_b=0; unsigned int patience = 10000; _cli(); write_8254_system_timer(0xFFFF); /* BUGFIX: Personal experience tells me BIOSes would fail reading the floppy if the IRQ 0 timer isn't ticking along at 18Hz */ _sti(); fd = open("..\\test1_22.wav",O_RDONLY|O_BINARY); if (fd < 0) fd = open("test1_22.wav",O_RDONLY|O_BINARY); if (fd < 0) { fprintf(stderr,"Cannot open test WAV\n"); return; } lseek(fd,44,SEEK_SET); read(fd,tmp,sizeof(tmp)); for (play=0;play < sizeof(tmp);play++) tmp[play] = (((tmp[play]) * 53) / 255) + 1; /* add "noise" to dither */ close(fd); /* set timer 0 to 54 ticks (1.191MHz / 54 ~ 22050Hz) */ _cli(); t8254_pc_speaker_set_gate(0); write_8254_pc_speaker(1); write_8254_system_timer(54); _sti(); _cli(); { outp(T8254_CONTROL_PORT,(0 << 6) | (0 << 4) | 0); /* latch counter N, counter latch read */ do { if (--patience == 1) break; cc = inp(T8254_TIMER_PORT(0)); inp(T8254_TIMER_PORT(0)); } while (cc < (54/2)); do { if (--patience == 0) break; cc = inp(T8254_TIMER_PORT(0)); inp(T8254_TIMER_PORT(0)); } while (cc >= (54/2)); if (patience <= 2) { write_8254_system_timer(0xFFFF); /* BUGFIX: on very old slow machines, the 54-count tick can easily cause the printf() below to absolutely CRAWL... */ _sti(); fprintf(stderr,"Oops! Either your CPU is too fast or the timer countdown trick doesn't work.\n"); _cli(); write_8254_system_timer(54); plan_b = 1; } } _sti(); while (1) { if (kbhit()) { int c = getch(); if (c == 27) break; } if (plan_b) { /* run with interrupts enabled, use IRQ0 to know when to tick */ _cli(); counter = 0; t8254_pc_speaker_set_gate(3); for (play=0;play < sizeof(tmp);) { outp(T8254_CONTROL_PORT,(2 << 6) | (1 << 4) | (T8254_MODE_0_INT_ON_TERMINAL_COUNT << 1)); /* MODE 0, low byte only, counter 2 */ outp(T8254_TIMER_PORT(2),tmp[play]); _sti(); while (counter == 0); _cli(); play += counter; counter = 0; } _sti(); } else { _cli(); t8254_pc_speaker_set_gate(3); outp(T8254_CONTROL_PORT,(0 << 6) | (0 << 4) | 0); /* latch counter N, counter latch read */ for (play=0;play < sizeof(tmp);play++) { outp(T8254_CONTROL_PORT,(2 << 6) | (1 << 4) | (T8254_MODE_0_INT_ON_TERMINAL_COUNT << 1)); /* MODE 0, low byte only, counter 2 */ outp(T8254_TIMER_PORT(2),tmp[play]); do { cc = inp(T8254_TIMER_PORT(0)); inp(T8254_TIMER_PORT(0)); } while (cc < (54/2)); do { cc = inp(T8254_TIMER_PORT(0)); inp(T8254_TIMER_PORT(0)); } while (cc >= (54/2)); } _sti(); } } t8254_pc_speaker_set_gate(0); }
beg_main() { char far *vram=MK_FP(0x0a000,0); int a,b,c,y; unsigned char al; dis_partstart(); outp(0x3c4,2); outp(0x3c5,15); memset(vram,15,32768); memset(vram+32768,15,32768); //_asm mov ax,80h+13h //_asm int 10h for(a=0;a<32;a++) dis_waitb(); outp(0x3c8,0); for(a=0;a<255;a++) { outp(0x3c9,63); outp(0x3c9,63); outp(0x3c9,63); } outp(0x3c9,0); outp(0x3c9,0); outp(0x3c9,0); inp(0x3da); outp(0x3c0,0x11); outp(0x3c0,255); outp(0x3c0,0x20); //inittwk(); outport(0x3D4, 0x000C); outport(0x3D4, 0x000D); outp(0x3D4, 9); al = inp(0x3D5); al &= ~0x80; al &= ~31; outp(0x3D5, al); outp(0x3C0, 0x11); outp(0x3C0, 0); outp(0x3C0, 32); outp(0x3C0, 0x11); outp(0x3C0, 255); outp(0x3C0, 0x20); readp(palette,-1,pic); for(y=0;y<400;y++) { readp(rowbuf,y,pic); lineblit(vram+(unsigned)y*80U,rowbuf); } for(c=0;c<=128;c++) { for(a=0;a<768-3;a++) pal2[a]=((128-c)*63+palette[a]*c)/128; dis_waitb(); setpalarea(pal2,0,254); } setpalarea(palette,0,254); }
void KoskoStudy::makePath(QString path, QVector<int> &nowImg) { int lenOfNum; QVector<int> intPath; int leftBorder = 10000, upperBorder = -1000, rightBorder = -1000, bottomBorder = 10000, tmp; QVector<bool> isInc; while (path != "") { if (path[1] == '|') { isInc << 0; path = path.right(path.size() - 3); if (path == "") break; } else isInc << 1; lenOfNum = path.indexOf(",", 0); tmp = path.left(lenOfNum).toInt(); intPath << tmp; if (tmp < leftBorder) { leftBorder = tmp; } if (tmp > rightBorder) { rightBorder = tmp; } path = path.right(path.size() - lenOfNum - 2); lenOfNum = path.indexOf(" ", 0); tmp = path.left(lenOfNum).toInt(); intPath << tmp; if (tmp < bottomBorder) { bottomBorder = tmp; } if (tmp > upperBorder) { upperBorder = tmp; } path = path.right(path.size() - lenOfNum - 3); } int i; for (i = 0; i < intPath.size(); i += 2) { intPath[i] -= leftBorder; intPath[i + 1] -= bottomBorder; } nowImg.fill(0); int width = rightBorder - leftBorder + 1; int height = upperBorder - bottomBorder + 1; QVector<int> img (width * height, 0); for (i = 0; i < intPath.size() - 2; i += 2) { if (isInc[1 + i / 2]) { makeLine(intPath.at(i) , intPath.at(i + 1) , intPath.at(i + 2) , intPath.at(i + 3) , width , height , img ); } } int leftCM, rightCM, upperCM, bottomCM; makeMassCentres(img, width, height, leftCM, rightCM, upperCM, bottomCM); fitToSize(intPath, isInc, nowImg, leftCM, rightCM, upperCM, bottomCM); outp(nowImg); }
void VL_modexPalUpdate(bitmap_t *bmp, word *i, word qp, word aqpp) { byte *p = bmp->palette; word w=0; word q=0; word qq=0; word ii; static word a[256] = { 0 }; word z=0,aq=0,aa=0; word pp=0,spee=0,ppee=0; sword aqpw; // if(qp>0) printf("(*i)=%02d\n", (*i)); modexWaitBorder(); if((*i)==0) outp(PAL_WRITE_REG, 0); /* start at the beginning of palette */ else if(qp==0) { q=(*i); } else { q=(*i); qq=(*i)/3; // printf("q: %02d\n", (q)); // printf("qq: %02d\n", (qq)); //printf(" (*i)-q=%02d\n", (*i)-q); // printf("================\n"); outp(PAL_WRITE_REG, qq); /* start at the beginning of palette */ } if((*i)<PAL_SIZE && w==0) { for(; (*i)<PAL_SIZE; (*i)++) { //if(i%3==0 && (p[i+5]==p[i+4] && p[i+4]==p[i+3] && p[i+3]==p[i+2] && p[i+2]==p[i+1] && p[i+1]==p[i] && p[i+5]==p[i])) //____ if((qp>0)&&((*i)-q)%3==0 && (p[((*i)-q)]==p[((*i)-q)+3] && p[((*i)-q)+1]==p[((*i)-q)+4] && p[((*i)-q)+2]==p[((*i)-q)+5])) outp(PAL_DATA_REG, p[(*i)-q]); else if(((((*i)-q)%3==0) || ((qp>0)&&((*i)-(bmp->offset*3))%3==0)) && (p[((*i)-q)]==p[((*i)-q)+3] && p[((*i)-q)+1]==p[((*i)-q)+4] && p[((*i)-q)+2]==p[((*i)-q)+5])) { if(qp>0) { (*i)-=(aqpp*3); aqpw=aqpp-1; outp(PAL_WRITE_REG, qq+(((*i)+(aqpw*3)-(bmp->offset*3))/3)); for(ii=aqpp; ii>0; ii--) { outp(PAL_DATA_REG, p[((((*i)+((aqpp-ii)*3))+((aqpp+ii)*3))-(bmp->offset*3))]); outp(PAL_DATA_REG, p[((((*i)+((aqpp-ii)*3))+((aqpp+ii)*3)+1)-(bmp->offset*3))]); outp(PAL_DATA_REG, p[((((*i)+((aqpp-ii)*3))+((aqpp+ii)*3)+2)-(bmp->offset*3))]); // printf("position = %d\n", qq+(((*i)+(aqpw*3)-(bmp->offset*3))/3)); /*if(qp>0){ //printf("[%d]", p[((*i)-q)]); printf("[%d]", p[((*i)-q)+1]); printf("[%d]", p[((*i)-q)+2]); printf("[%d]", p[((*i)-q)+3]); printf("[%d]", p[((*i)-q)+4]); printf("[%d]", p[((*i)-q)+5]); printf(" %d [%d]\n", (*i), p[((*i)-q)]); } printf("[%d]", p[((((*i)+((aqpp-ii)*3)))-(bmp->offset*3))]); printf("[%d]", p[((((*i)+((aqpp-ii)*3))+1)-(bmp->offset*3))]); printf("[%d] | ", p[((((*i)+((aqpp-ii)*3))+2)-(bmp->offset*3))]); printf("[%d]", p[((((*i)+((aqpp-ii)*3))+3)-(bmp->offset*3))]); printf("[%d]", p[((((*i)+((aqpp-ii)*3))+4)-(bmp->offset*3))]); printf("[%d]", p[((((*i)+((aqpp-ii)*3))+5)-(bmp->offset*3))]); printf(" %d [%d]\n",((((*i)+((aqpp-ii)*3))+((aqpp+ii)*3))-(bmp->offset*3))/3, p[((((*i)+((aqpp-ii)*3))+((aqpp+ii)*3))-(bmp->offset*3))]); }*/ //printf("%d\n", ((*i)+((ii)*3))/3); //printf("ii=%d\n", ii); //printf("aqpp=%d\n", aqpp); //printf(" %d\n", ((*i)+((aqpp-ii)*3))/3); } //printf(" %d\n",((((*i)+((aqpp-ii)*3)))-(bmp->offset*3))); //printf(" %d\n",((((*i)+((aqpp-ii)*3))+1)-(bmp->offset*3))); //printf(" %d\n",((((*i)+((aqpp-ii)*3))+2)-(bmp->offset*3))); //printf("(*i)=%d\n", (*i)); } //printf("[%d]", p[((*i)-q)]); printf("[%d]", p[((*i)-q)+1]); printf("[%d]", p[((*i)-q)+2]); printf("[%d]", p[((*i)-q)+3]); printf("[%d]", p[((*i)-q)+4]); printf("[%d]", p[((*i)-q)+5]); printf(" %d [%d]\n", (*i), p[((*i)-q)]); w++; break; } else { if(bmp->offset==0 && (*i)<3 && q==0) outp(PAL_DATA_REG, 0); else if(qp==0) outp(PAL_DATA_REG, p[(*i)-q]); else outp(PAL_DATA_REG, p[((*i)-(bmp->offset*3))]); } } } //palette checker~ if(q>0 && qp==0) { long lq; long bufSize = (bmp->width * bmp->height); chkcolor(bmp, &q, &a, &aa, &z); /*printf("z=%d\n", z/3); printf("q+z=%d\n", (q+z)/3); printf("z-ppee=%d\n", (z-ppee)/3); printf("q=%d\n", q/3); printf("aa=%d\n", aa);*/ aq=0; pp = q; ppee=q; aqpee: while(aq<=aa) { //printf("a[%02d]=(%d)", aq, a[aq]); if(a[aq]==0) aq++; else{ aqpp++; break; } } /* printf("aq=%02d\n", aq); printf("z=%02d\n", z/3); printf("(z/3)-aqpp=%02d\n", (z/3)-aqpp); printf("aqpp=%02d\n", aqpp);*/ for(lq=0; lq<bufSize; lq++) { if(bmp->data[lq]+bmp->offset==aq) { //printf("\n%02d\n", bmp->data[lq]); //printf("\n%02d\n", bmp->offset); //printf("\naq= %02d\n", aq); //printf("a[aq]= %02d\n", a[aq]); //bmp->data[lq]=((bmp->data[lq]+bmp->offset)-a[aq]); bmp->data[lq]=a[aq]; //printf("_%d \n", bmp->data[lq]); } else if(bmp->data[lq]+bmp->offset < (z/3)-aqpp) { if(bmp->data[lq]+bmp->offset >= aq) bmp->data[lq]=(bmp->data[lq]+bmp->offset)-aqpp; else bmp->data[lq]+=(bmp->offset); } //printf("%02d ", bmp->data[lq]); //if(lq > 0 && lq%bmp->width==0) printf("\n"); } while(pp<=(aq*3)) { if(((pp/3)==aq || spee>0)) { /*printf("spee=%d\n", spee); printf(" pp=%02d ", pp/3); printf("old bmp: [%d]", bmp->palette[(pp-ppee)]); printf("[%d]", bmp->palette[(pp-ppee)+1]); printf("[%d]\n", bmp->palette[(pp-ppee)+2]);*/ //if(spee==0) printf("\npp=%02d\n\n", pp/3); bmp->palette[(pp-ppee)]= bmp->palette[(pp-ppee)+3]; bmp->palette[(pp-ppee)+1]= bmp->palette[(pp-ppee)+4]; bmp->palette[(pp-ppee)+2]= bmp->palette[(pp-ppee)+5]; if(spee==0) spee++; } /*printf(" pp=%02d ", pp/3); printf(" bmp: [%d]", bmp->palette[(pp-ppee)]); printf("[%d]", bmp->palette[(pp-ppee)+1]); printf("[%d]\n", bmp->palette[(pp-ppee)+2]);*/ pp+=3; } //update the palette~ //printf(" aqpp= %d\n", aqpp); VL_modexPalUpdate(bmp, &ppee, 1, aqpp); (*i)=ppee; //printf(" aqpp= %d\n", aqpp); //printf(" ppee= %d\n", ppee); /*printf(".\n"); printf("aqpp= %02d\n", aqpp/3); printf("aq= %02d\n", aq); printf("aa= %02d\n", aa); printf(" ppee= %02d\n", ppee);*/ if(aq<aa){ /*printf("~~~~\n"); */ppee=q; aq++; goto aqpee; } /*printf("ppee=%d\n", ppee); printf("pp=%d\n", pp); printf("q=%d\n", q); printf("(*i)=%d\n", (*i));*/ } }
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 dos_video_init(void) { /* Change video settings if screen expansion is enabled */ if(option.expand) { option.video_driver = GFX_AUTODETECT; option.video_width = (IS_GG) ? 400 : 512; option.video_height = (IS_GG) ? 300 : 384; } /* Double requested height if scanlines are being used and screen expansion is disabled */ if((option.scanlines == 1) && (option.expand == 0)) { option.video_height *= 2; } /* Change video settings if tweaked display is enabled */ if(option.tweak) { option.video_driver = GFX_VGA; option.video_depth = 8; option.video_width = 320; option.video_height = 200; } /* Attempt to set graphics mode */ set_color_depth(option.video_depth); if(set_gfx_mode(option.video_driver, option.video_width, option.video_height, 0, 0) != 0) { printf("Error: %s\n", allegro_error); exit(1); } /* Clear palette and display */ memcpy(sms_pal, black_palette, sizeof(PALETTE)); sms_pal[0xFE].r = sms_pal[0xFE].g = sms_pal[0xFE].b = 0xFF; set_palette(sms_pal); clear(screen); /* Use vertical stretching if screen expansion is enabled, VGA expansion is disabled, and scanlines are disabled */ if((option.expand == 1) && (option.no_vga == 0) && (option.scanlines == 0)) { outp(0x3D4, 0x09); outp(0x3D5, (inp(0x3D5) & 0xE0) | 0x03); } /* Force overscan color to be black */ if(option.video_depth == 8) { inp(0x3DA); outp(0x3C0, 0x31); outp(0x3C0, 0xFF); clear_to_color(screen, 0xFF); } /* Tweak display accordingly */ if(option.tweak) { int i, j = IS_GG ? 1 : 0; /* Disable CRTC write protect */ outp(0x3D4, 0x11); outp(0x3D5, inp(0x3D5) & 0x7F); /* Load CRTC parameters */ for(i = 0; i <= 0x0D; i++) outpw(0x3D4, twktbl[j][i]); /* Enable CRTC write protect */ outp(0x3D4, 0x11); outp(0x3D5, inp(0x3D5) | 0x80); /* Set clocking mode register */ outp(0x3C2, twktbl[j][0x0E]); /* Set miscellaneous output register */ outpw(0x3C4, twktbl[j][0x0F]); } }
GetCRTCReg(int r) { outp(*ADDR_6845,r); return inp(*ADDR_6845+1); }
void Peer::received( const RuntimeEnvironment *RR, const SharedPtr<Socket> &fromSock, const InetAddress &remoteAddr, unsigned int hops, uint64_t packetId, Packet::Verb verb, uint64_t inRePacketId, Packet::Verb inReVerb, uint64_t now) { // Update system-wide last packet receive time *((const_cast<uint64_t *>(&(RR->timeOfLastPacketReceived)))) = now; // Global last receive time regardless of path _lastReceive = now; if (!hops) { // Learn paths from direct packets (hops == 0) { bool havePath = false; for(unsigned int p=0,np=_numPaths;p<np;++p) { if ((_paths[p].address() == remoteAddr)&&(_paths[p].tcp() == fromSock->tcp())) { _paths[p].received(now); havePath = true; break; } } if (!havePath) { unsigned int np = _numPaths; if (np >= ZT_PEER_MAX_PATHS) clean(now); np = _numPaths; if (np < ZT_PEER_MAX_PATHS) { Path::Type pt = Path::PATH_TYPE_UDP; switch(fromSock->type()) { case Socket::ZT_SOCKET_TYPE_TCP_IN: pt = Path::PATH_TYPE_TCP_IN; break; case Socket::ZT_SOCKET_TYPE_TCP_OUT: pt = Path::PATH_TYPE_TCP_OUT; break; default: break; } _paths[np].init(remoteAddr,pt,false); _paths[np].received(now); _numPaths = ++np; } } } /* Announce multicast groups of interest to direct peers if they are * considered authorized members of a given network. Also announce to * supernodes and network controllers. The other place this is done * is in rescanMulticastGroups() in Network, but that only sends something * if a network's multicast groups change. */ if ((now - _lastAnnouncedTo) >= ((ZT_MULTICAST_LIKE_EXPIRE / 2) - 1000)) { _lastAnnouncedTo = now; bool isSupernode = RR->topology->isSupernode(_id.address()); Packet outp(_id.address(),RR->identity.address(),Packet::VERB_MULTICAST_LIKE); std::vector< SharedPtr<Network> > networks(RR->nc->networks()); for(std::vector< SharedPtr<Network> >::iterator n(networks.begin());n!=networks.end();++n) { if ( ((*n)->isAllowed(_id.address())) || (isSupernode) ) { std::set<MulticastGroup> mgs((*n)->multicastGroups()); for(std::set<MulticastGroup>::iterator mg(mgs.begin());mg!=mgs.end();++mg) { if ((outp.size() + 18) > ZT_UDP_DEFAULT_PAYLOAD_MTU) { outp.armor(_key,true); fromSock->send(remoteAddr,outp.data(),outp.size()); outp.reset(_id.address(),RR->identity.address(),Packet::VERB_MULTICAST_LIKE); } // network ID, MAC, ADI outp.append((uint64_t)(*n)->id()); mg->mac().appendTo(outp); outp.append((uint32_t)mg->adi()); } } } if (outp.size() > ZT_PROTO_MIN_PACKET_LENGTH) { outp.armor(_key,true); fromSock->send(remoteAddr,outp.data(),outp.size()); } } } if ((verb == Packet::VERB_FRAME)||(verb == Packet::VERB_EXT_FRAME)) _lastUnicastFrame = now; else if ((verb == Packet::VERB_P5_MULTICAST_FRAME)||(verb == Packet::VERB_MULTICAST_FRAME)) _lastMulticastFrame = now; }
main(int argc,char *argv[]) { int timer=30000; int dropper,repeat; int frame=0; int rota=-1*64; int fb=0; int rot=0,rots=0; int a,b,c,d,i,j,mode; int grav,gravd; int f=0; dis_partstart(); dotnum=512; for(a=0;a<dotnum;a++) dottaul[a]=a; for(a=0;a<500;a++) { b=rand()%dotnum; c=rand()%dotnum; d=dottaul[b]; dottaul[b]=dottaul[c]; dottaul[c]=d; } { dropper=22000; for(a=0;a<dotnum;a++) { dot[a].x=0; dot[a].y=2560-dropper; dot[a].z=0; dot[a].yadd=0; } mode=7; grav=3; gravd=13; gravitybottom=8105; i=-1; } for(a=0;a<500;a++) { // scramble b=rand()%dotnum; c=rand()%dotnum; d=dot[b].x; dot[b].x=dot[c].x; dot[c].x=d; d=dot[b].y; dot[b].y=dot[c].y; dot[c].y=d; d=dot[b].z; dot[b].z=dot[c].z; dot[c].z=d; } for(a=0;a<200;a++) rows[a]=a*320; _asm mov ax,13h _asm int 10h outp(0x3c8,0); for(a=0;a<16;a++) for(b=0;b<4;b++) { c=100+a*9; outp(0x3c9,cols[b*3+0]); outp(0x3c9,cols[b*3+1]*c/256); outp(0x3c9,cols[b*3+2]*c/256); } outp(0x3c8,255); outp(0x3c9,31); outp(0x3c9,0); outp(0x3c9,15); outp(0x3c8,64); for(a=0;a<100;a++) { c=64-256/(a+4); c=c*c/64; outp(0x3c9,c/4); outp(0x3c9,c/4); outp(0x3c9,c/4); } outp(0x3c7,0); for(a=0;a<768;a++) pal[a]=inp(0x3c9); outp(0x3c8,0); for(a=0;a<768;a++) outp(0x3c9,0); for(a=0;a<100;a++) { memset(vram+(100+a)*320,a+64,320); } for(a=0;a<128;a++) { c=a-(43+20)/2; c=c*3/4; c+=8; if(c<0) c=0; else if(c>15) c=15; c=15-c; depthtable1[a]=0x202+0x04040404*c; depthtable2[a]=0x02030302+0x04040404*c; depthtable3[a]=0x202+0x04040404*c; //depthtable4[a]=0x02020302+0x04040404*c; } bgpic=halloc(64000L,1L); memcpy(bgpic,vram,64000); a=0; for(b=64;b>=0;b--) { for(c=0;c<768;c++) { a=pal[c]-b; if(a<0) a=0; pal2[c]=a; } dis_waitb(); dis_waitb(); outp(0x3c8,0); for(c=0;c<768;c++) outp(0x3c9,pal2[c]); } while(!dis_exit() && frame<2450) { //setborder(0); repeat=dis_waitb(); if(frame>2300) setpalette(pal2); //setborder(1); if(dis_indemo()) { a=dis_musplus(); if(a>-4 && a<0) break; } while(repeat--) { frame++; if(frame==500) f=0; i=dottaul[j]; j++; j%=dotnum; if(frame<500) { dot[i].x=isin(f*11)*40; dot[i].y=icos(f*13)*10-dropper; dot[i].z=isin(f*17)*40; dot[i].yadd=0; } else if(frame<900) { dot[i].x=icos(f*15)*55; dot[i].y=dropper; dot[i].z=isin(f*15)*55; dot[i].yadd=-260; } else if(frame<1700) { a=sin1024[frame&1023]/8; dot[i].x=icos(f*66)*a; dot[i].y=8000; dot[i].z=isin(f*66)*a; dot[i].yadd=-300; } else if(frame<2360) { /* a=rand()/128+32; dot[i].y=8000-a*80; b=rand()&1023; a+=rand()&31; dot[i].x=sin1024[b]*a/3+(a-50)*7; dot[i].z=sin1024[(b+256)&1023]*a/3+(a-40)*7; dot[i].yadd=300; if(frame>1640 && !(frame&31) && grav>-2) grav--; */ dot[i].x=rand()-16384; dot[i].y=8000-rand()/2; dot[i].z=rand()-16384; dot[i].yadd=0; if(frame>1900 && !(frame&31) && grav>0) grav--; } else if(frame<2400) { a=frame-2360; for(b=0;b<768;b+=3) { c=pal[b+0]+a*3; if(c>63) c=63; pal2[b+0]=c; c=pal[b+1]+a*3; if(c>63) c=63; pal2[b+1]=c; c=pal[b+2]+a*4; if(c>63) c=63; pal2[b+2]=c; } } else if(frame<2440) { a=frame-2400; for(b=0;b<768;b+=3) { c=63-a*2; if(c<0) c=0; pal2[b+0]=c; pal2[b+1]=c; pal2[b+2]=c; } } if(dropper>4000) dropper-=100; rotcos=icos(rot)*64; rotsin=isin(rot)*64; rots+=2; if(frame>1900) { rot+=rota/64; rota--; } else rot=isin(rots); f++; gravity=grav; gravityd=gravd; } drawdots(); } if(!dis_indemo()) { _asm mov ax,3h _asm int 10h }
/* this is used to probe for ports in standard locations, when we really don't know if it's there */ int probe_8250(uint16_t port) { unsigned char ier,dlab1,dlab2,c,fcr; struct info_8250 *inf; if (already_got_8250_port(port)) return 0; if (base_8250_full()) return 0; inf = &info_8250_port[base_8250_ports]; inf->type = TYPE_8250_IS_8250; inf->port = port; inf->irq = -1; if (windows_mode == WINDOWS_NONE || windows_mode == WINDOWS_REAL) { /* in real-mode DOS we can play with the UART to our heart's content. so we play with the * DLAB select and interrupt enable registers to detect the UART in a manner non-destructive * to the hardware state. */ /* there's no way to autodetect the COM port's IRQ, we have to guess */ if (port == 0x3F8 || port == 0x3E8) inf->irq = 4; else if (port == 0x2F8 || port == 0x2E8) inf->irq = 3; /* switch registers 0+1 back to RX/TX and interrupt enable, and then test the Interrupt Enable register */ _cli(); outp(port+3,inp(port+3) & 0x7F); if (inp(port+3) == 0xFF) { _sti(); return 0; } ier = inp(port+1); outp(port+1,0); if (inp(port+1) == 0xFF) { _sti(); return 0; } outp(port+1,ier); if ((inp(port+1) & 0xF) != (ier & 0xF)) { _sti(); return 0; } /* then switch 0+1 to DLAB (divisor registers) and see if values differ from what we read the first time */ outp(port+3,inp(port+3) | 0x80); dlab1 = inp(port+0); dlab2 = inp(port+1); outp(port+0,ier ^ 0xAA); outp(port+1,ier ^ 0x55); if (inp(port+1) == ier || inp(port+0) != (ier ^ 0xAA) || inp(port+1) != (ier ^ 0x55)) { outp(port+0,dlab1); outp(port+1,dlab2); outp(port+3,inp(port+3) & 0x7F); _sti(); return 0; } outp(port+0,dlab1); outp(port+1,dlab2); outp(port+3,inp(port+3) & 0x7F); /* now figure out what type */ fcr = inp(port+2); outp(port+2,0xE7); /* write FCR */ c = inp(port+2); /* read IIR */ if (c & 0x40) { /* if FIFO */ if (c & 0x80) { if (c & 0x20) inf->type = TYPE_8250_IS_16750; else inf->type = TYPE_8250_IS_16550A; } else { inf->type = TYPE_8250_IS_16550; } } else { unsigned char oscratch = inp(port+7); /* no FIFO. try the scratch register */ outp(port+7,0x55); if (inp(port+7) == 0x55) { outp(port+7,0xAA); if (inp(port+7) == 0xAA) { outp(port+7,0x00); if (inp(port+7) == 0x00) { inf->type = TYPE_8250_IS_16450; } } } outp(port+7,oscratch); } outp(port+2,fcr); _sti(); } else { unsigned int i; /* if we were to actually do our self-test in a VM, Windows would mistakingly assume we * were trying to use it and would allocate the port. we're just enumerating at this point. * play it safe and assume it works if the port is listed as one of the BIOS ports. * we also don't use interrupts. */ for (i=0;i < bios_8250_ports && port != get_8250_bios_port(i);) i++; if (i >= bios_8250_ports) return 0; } base_8250_port[base_8250_ports++] = port; return 1; }
/* Draws a circle of radius Radius in color Color centered at * screen coordinate (X,Y) */ void DrawCircle(int X, int Y, int Radius, int Color) { int MajorAxis, MinorAxis; unsigned long RadiusSqMinusMajorAxisSq, MinorAxisSquaredThreshold; unsigned char *PixListPtr, OriginalGCMode; /* Set drawing color via set/reset */ outpw(GC_INDEX, (0x0F << 8) | SET_RESET_ENABLE_INDEX); /* enable set/reset for all planes */ outpw(GC_INDEX, (Color << 8) | SET_RESET_INDEX); /* set set/reset (drawing) color */ #if ISVGA /* Remember original read/write mode & select read mode 1/write mode 3, with Color Don't Care set to ignore all planes and therefore always return 0xFF */ outp(GC_INDEX, GC_MODE_INDEX); OriginalGCMode = inp(GC_INDEX + 1); outp(GC_INDEX+1, OriginalGCMode | 0x0B); outpw(GC_INDEX, (0x00 << 8) | COLOR_DONT_CARE); outpw(GC_INDEX, (0xFF << 8) | BIT_MASK_INDEX); #else outp(GC_INDEX, BIT_MASK_INDEX); /* leave the GC Index reg pointing to the Bit Mask reg */ #endif /* Set up to draw the circle by setting the initial point to one end of the 1/8th of a circle arc we'll draw */ MajorAxis = 0; MinorAxis = Radius; /* Set initial Radius**2 - MajorAxis**2 (MajorAxis is initially 0) */ RadiusSqMinusMajorAxisSq = (unsigned long) Radius * Radius; /* Set threshold for minor axis movement at (MinorAxis - 0.5)**2 */ MinorAxisSquaredThreshold = (unsigned long) MinorAxis * MinorAxis - MinorAxis; /* Calculate all points along an arc of 1/8th of the circle. Results are placed in PixList */ MajorAxis = GenerateOctant(PixList, MajorAxis, MinorAxis, RadiusSqMinusMajorAxisSq, MinorAxisSquaredThreshold); /* Now draw each of the 8 symmetries of the octant in turn */ /* Draw the octants for which Y is the major axis */ DrawVOctant(X-Radius,Y,MajorAxis,-SCREEN_WIDTH_IN_BYTES,1,PixList); DrawVOctant(X-Radius,Y,MajorAxis,SCREEN_WIDTH_IN_BYTES,1,PixList); DrawVOctant(X+Radius,Y,MajorAxis,-SCREEN_WIDTH_IN_BYTES,0,PixList); DrawVOctant(X+Radius,Y,MajorAxis,SCREEN_WIDTH_IN_BYTES,0,PixList); /* Draw the octants for which X is the major axis */ DrawHOctant(X,Y-Radius,MajorAxis,SCREEN_WIDTH_IN_BYTES,0,PixList); DrawHOctant(X,Y-Radius,MajorAxis,SCREEN_WIDTH_IN_BYTES,1,PixList); DrawHOctant(X,Y+Radius,MajorAxis,-SCREEN_WIDTH_IN_BYTES,0, PixList); DrawHOctant(X,Y+Radius,MajorAxis,-SCREEN_WIDTH_IN_BYTES,1, PixList); #if ISVGA /* Restore original write mode */ outpw(GC_INDEX, (OriginalGCMode << 8) | GC_MODE_INDEX); /* Restore normal Color Don't Care setting */ outpw(GC_INDEX, (0x0F << 8) | COLOR_DONT_CARE); #else /* Reset the Bit Mask register to normal */ outp(GC_INDEX + 1, 0xFF); #endif /* Turn off set/reset enable */ outpw(GC_INDEX, (0x00 << 8) | SET_RESET_ENABLE_INDEX); }
void SDR1000::Latch(uint8 addr, uint8 data) { outp(lpt_addr, data); outp(lpt_addr+2, addr); outp(lpt_addr+2, 0xB); // 0xB selects none of the boards }