#include<dos.h> #include<stat.h> #include<conio.h> #include<stdio.h> #include<fcntl.h> #include<io.h> void main() { int in,bytes,i,n; char buf[512]; clrscr(); in=open("sect.dat",O_CREAT|O_BINARY|O_WRONLY); gotoxy(25,2); printf("Sector reader\n"); for(i=1;i<=2847-1;i++) { absread(0,1,i,&buf); write(in,buf,512); gotoxy(15,5); printf("%d sectors readed",i); } close(in); gotoxy(15,7); printf("\nEnter target disk"); wait; in=open("sect.dat",O_BINARY|O_RDONLY); for(i=1;i<=1439;i++) { read(in,buf,512); n=abswrite(0,1,i,&buf); if(n!=0) { gotoxy(15,10); printf("%3d th sector skipped"); } gotoxy(15,12); printf("sectors written = %3d",i); } close(in); } |
In C graphics mode when you initialize the mouse you will can see a mouse pointer which is the default one like in windows. I thought of changing it and searched the books. i found a description in yeshavant kanetkar’s book c graphics. The explanation was very nice. I created a program name mice which with i generate various mouse pointers and i save it as a header file which has codes like the following.
Mice will allow you to save mouse pointers as .h file with any valid ms-dos file name.(you can find the mice program and its partial code in future from my home page links title probably “C Snippets”.
The following code used very long variable names just for the matter of understanding… so dont worry the actual code for this seems very tiny…
The shape structure has two type of data of the mouse bitmap. one for the the foreground and other for the transparency… that is cursor mask and screen mask…
When you’re designing the cursor mask, each bit is 1 if it is displayed,
and 0 if it is not. On the screen mask, bits that are 1 are transparent.
you can assume the concept of GIF file here…
int shape [32] = { 0xffff,0xffff,0xffff,0xffff, 0xffff,0xffff,0xffff,0xffff, 0xff3f,0xff3f,0xffff,0xffff, 0xffff,0xffff,0xffff,0xffff, 0xf00f,0x8001,0x8001,0x8001, 0x0,0x0,0x0,0x180, 0x180,0x0,0x0,0x0, 0x8001,0x8001,0x8001,0xf00f }; //Call the function from main as change_mouse_pointer(shape); void change_mouse_pointer(int *shape) { union REGS inputregister,outputregister; struct SREGS segmentregister; inputregister.x.ax=0; int86(0x33,&inputregister,&outputregister); inputregister.x.ax=1; int86(0x33,&inputregister,&outputregister); inputregister.x.ax=9; inputregister.x.bx=0; inputregister.x.cx=0; inputregister.x.dx= (unsigned) shape; segread(&segmentregister); segmentregister.es=segmentregister.ds; int86x(0x33,&inputregister,&outputregister,&segmentregister); } |
and when i searched the net at the time of posting this code i found one good article titled Programming the Microsoft Mouse. but at this date the page was removed. The reason is to see how many such tutorials still exists these days because people almost forgot MS-DOS… but some still had like the universities and other c programmers reference links…
and a news about geocities is that yahoo is going to stop its free web hosting service… so better save a copy of the information whatever you see in geocities… 🙁
It has been a very long time since my programming with the MS-DOS mouse… anyway if good then enjoy…
1.
On line 371 of the wp-includes/rewrite.php file, you’ll see the code:
$this->category_structure = $this->front . ‘category/’;
Now just remove the “category” from the string, and the code should look like:
$this->category_structure = $this->front . ‘/’;
2.
another way of doing that is by the following which worked for me so here we go…
Just enter /. as the value for Category base.
…..
I wrote a program to draw on the screen using putpixel which will plot a pixel at x,y,colorvalue where x,y is the location which you can get from the mouse interrupts… so my idea is to draw but this approach was not much effective because if you move the mouse fast you will not get the desired shape…
so i read a technique which is actually the original way of drawing using the mouse using the lineto function which will not break the path where as using putpixel will break…
#include<graphics.h> #include<bios.h> #include<dos.h> void getxy(); int prevx,prevy,mousex,mousey,butt=1; void main() { int x=DETECT,y; initgraph(&x,&y,""); // path to EGAVGA.BGI if this is not in your current directory _AX=0; asm int 33h setcolor(15); while(inportb(0x60)!=1) { getxy(); if(butt==1) { _AX=2; asm int 33h line(mousex-1,mousey-1,prevx-1,prevy-1); } else { _AX=1; asm int 33h } } closegraph(); } void getxy() { _AX=3; asm int 33h; prevx=mousex; prevy=mousey; mousex=_CX; mousey=_DX; butt=_BX; gotoxy(2,2); printf("%3d %3d %2d",mousex,mousey,butt); } |
_AX=0 – Initialize mouse
_AX=1 – show mouse pointer
_AX=2 – hide mouse pointer
_AX=3 – get coordinates and the return values will be in cs and dx.
The while loop executes till the esc key is pressed
I use inportb macro for keyboard port 60h to get keystrokes from the keyboard buffer directly using a loop.
for example in a loop executes and in that block i will use this function to get the scan codes of keystrokes and use it… like the following
unsigned char key; while(1) { if((key = inportb(0x60))==1)break; // if esc is pressed printf("\n%d",key); } |
i hope people know why %d is used for a char datatype. But behind this there is a contradiction among many young programmers…
here, your screen will be flooded with scan codes whether or not press any key… that’s the use of inportb…
you press a key and you can see the scan code. if you want the ascii code then you have to issue an interrupt to get both scan codes and ascii code as integer in which the first 8bits and other 8bits will give you the ascii and scan codes…
and the problem is when you press a key and before you release you are sending more than the limit of keystrokes to the the keyboard buffer and to notify this the beep sound beeps… and these extra keystrokes will appear for your next input which is not needed… it is like if you press ‘k’ and then you do some process and then your code again waits for the key strokes now you will get the remaining k’s from the keyboard buffer if it is not flushed…
so here comes the following code which will clear the keyboard buffer for every time it executes…
#include<stdio.h> #include<dos.h> void main() { int i; while(1) { if(inportb(0x60)==2)break; printf("\n%d",inportb(0x60)); _AH=0xc; _AL=0x2; asm int 21h } } |
whether or not a key is pressed the buffer is cleared… so from the next stroke i could assume that only one entry will be present in the keyboard buffer before it is read…
and hope people are good in registers of the processor and interrupts to understand the above code which has an inline assembly language code.
21h is for keyboard and other two are sub functions to clear buffer. maybe i should sit a little more to elaborate. déjame ver if i could… .
This program displays the click event of the mouse in ms dos environment using Turbo C. If you double click on the screen then you will get the message that you have double clicked else none. I wrote this function to use it in the 640×480 16 color graphics mode for a simple my computer program to which detects single click and double click on a file.
If people know about interrupts, ports, scan codes and button states then it might be useful for them if they are trying to under stand the concept of low level input and output. Using this may help them understand the windows env better…
and one more important point is i have used inline asm codes so … be ware…
here i would like to say one thing and that is about the inportb macro… using this i mimicked a multiprocessing program… which displays the time and at the same time it can detect the mouse and keyboard like in windows… i can never forget this word because i have used it very extensively.
anyway here is the code…
Interrupt 33 deals with the mouse and sub function 0 and 1 are for initialize mouse and show mouse pointer respectively… one interesting function i have made among the others… yeeeehaaawww…
#include<time.h> #include<stdio.h> #include<dos.h> char butt; clock_t start; void main() { void mouse(); void click(); start=clock(); _AX=0;asm int 33h; _AX=1;asm int 33h; while(inportb(0x60)!=1) { mouse(); if(butt) { click(); while(butt)mouse(); } } } void click() { float as; as=(float) start-clock(); gotoxy(50,2); if(as>-6.&&as<0.) printf("double click"); else printf(" "); start=clock(); } void mouse() { _AX=3;asm int 33h; butt=_BX; } |
This program is no longer used cause no body uses a floppy… i have to update it to a 32bit program from 16bit… and manipulating a USB will be nice instead of a floppy.
This program displays the boot sector of a floppy drive. The biosdisk function can be used to manipulate a FAT32 hard drive even now. Manipulating a FAT16 and FAT12 are straight forward using absolute disk read and absolute disk write functions provided in Borland’s Turbo C IDE.
I am trying to write a program which will help me play with FAT32 in windows… using WIN32 API…
anyway here is one silly program for the strong hearts…
#include<stdio.h> #include<conio.h> #include<bios.h> struct { char jump[3]; char si[8];//system id int bps;// no of bytes per sector char spc;// no of sectors per cluster int res;// no of reserved area char cof;// no of copies of fat int rde;//no of root directory entries int tos;// total no of sectors char md;// media discriptor int spf;// no of sectors per fat int spt;// no of sectors per track int sides;// no of sides int hs;// no of hidden sectors char rest[482]; }zero; void display_bootsector(); void main() { biosdisk(2,0x81,0,0,1,1,&zero); display_bootsector(); } void display_bootsector() { zero.jump[3]=0; printf("\nJump Instruction\t\t%s",zero.jump); zero.si[8]=0; printf("\nSystem Id\t\t%s",zero.si); printf("\nBytes per sector\t%d",zero.bps); printf("\nSectors per cluster\t%d",zero.spc); printf("\nReserved\t\t%d",zero.res); printf("\nCopies of fat\t\t%d",zero.cof); printf("\nRoot directory entries\t%d",zero.rde); printf("\nTotal no of sectors\t%d",zero.tos); printf("\nMedia discriptor\t%0x",zero.md); printf("\nSectors per fat\t\t%d",zero.spf); printf("\nSectors per track\t%d",zero.spt); printf("\nNo of sides\t\t%d",zero.sides); printf("\nNo of hidden sectors\t%d",zero.hs); printf("\n"); } |
I was thinking of writing a resume download program using win32 to know how it works since i know how socket is working. While i was reading about different headers of HTTP i came to know about Range request with which you can request a part of a file by specifying the start and end position.
$out ="GET /a.txt HTTP/1.1\r\n"; $out.="Host: localhost\r\n"; $out.="Range: bytes=3-5\r\n"; |
Firstly, we should determine the total size of a file using the HEAD request.
$out ="HEAD /a.txt HTTP/1.1\r\n"; $out.="Host: localhost\r\n\r\n"; |
You can use your own parser to fetch the size of the file and have it in the memory.
Here is the code to fetch a part of a file using php
$f = fsockopen("localhost",80); if(!$f)die("cannnot connect"); $out ="GET /this/one.txt HTTP/1.1\r\n"; $out.="Host: localhost\r\n"; $out.="Range: bytes=3-5\r\n"; $out.="Keev-alive: timeout=15, max=100\r\n"; $out.="connection: keep-alive\r\n\r\n"; fwrite($f,$out); $str =''; while(!feof($f)) $str.=fgets($f,128); echo $str; |
now you can see the part of the text in the file. change the byte ranges in the Range header and try more to see what happens. You can use a parser to fetch the content. You can find a http parser in php.net site.
I have given the very least of information. I will explore on this more and this post will get updated as i update myself.
If there is any objection then yes… proceed… that could help me and all who read this post… anyway… gozar…
I used xmlhttp request to send multiple data from javascript to php. I created objects and properties (virtually it is referred as Associative Array in javascript). And finally all the objects are encapsulated into a main object and this was stringified by using JSON method… finally i got a json string which i sent using xmlhttp.
When i received the string in php and debugged it and is said all as StdObjects and when i tried to use in foreach it didnt work. So i searched for the following and i converted the StdObject to array using the following. Hope people might use it.
If anybody willing to comment on its performance or any other idea then please do so…
function object_to_array($data) { if(is_array($data) || is_object($data)) { $result = array(); foreach($data as $key => $value) { $result[$key] = object_to_array($value); } return $result; } return $data; } |
Recent Comments