home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programming
/
powerprogramming1994.iso
/
progtool
/
microcrn
/
issue_32.arc
/
C.FIG
< prev
next >
Wrap
Text File
|
1979-12-31
|
4KB
|
129 lines
((this is C Fig. 1))
main()
{
system("copy c:\budget\taxes.wk c:\lotus");
system("cd \lotus");
exec("123.exe","");
system("copy c:\lotus\taxes.wk c:\budget");
system("del c:\lotus\taxes.wk");
}
((this is C Fig. 2))
filesend(source,target)
char *source.*target;
{
int fout,fin;
char buffer[BUFSIZE]; /* set BUFSIZE as big as you'd like, for speed */
if( (fout=open(source,0)) == -1) error(); /*or however you wish to */
if( (fin=creat(target,0) == -1) error(); /* handle errors */
while( write(fin,buffer,read(fout,buffer,BUFSIZE)) == BUFSIZE);
}
((C Figure 3 - An On Screen Clock))
; Module for masm. DeSmet fans could go in-line with this.
CODE SEGMENT PUBLIC BYTE
ASSUME CS:CODE ,DS:DATA
PUBLIC _ourint,_putds
savds DW ? ;storage for DS
_puts: MOV CS:savds,DS ;storing DS in code segment
RET
_ourint: PUSH AX ;heck--save everything in sight
PUSH BX ;but let's use the subprogram's stack
PUSH CX
PUSH DX
PUSH DI
PUSH SI
PUSH ES
PUSH DS
PUSH BP
MOV DS,CS:savds
MOV ES,CS:savds
CALL _procss ; calling C-code
POP BP
POP DS ;restore everything again
POP ES
POP SI
POP DI
POP DX
POP CX
POP BX
POP AX
IRET ;and back to subprogram
/*************************/
/* the C module */
#include <regs.h > /* header for interrupt structures */
#define clkint 0x1c /* clock interrupt */
#define timeaddr 0x46C /* ticks past midnight */
#define scrseg 0xb800 /* video ram segment--you could test for this */
#define offset 3840 /* position on screen = lower left corner */
extern unsigned _code,_data; /* obvious segment addresses */
unsigned us[2],them[2],hand,index,tick,hour,minute,second;
char time[]=
" \160 \160 \160:\160 \160 \160:\160 \160 \160 \160"; /*reverse video */
long midtick;
/**************************/
procss() /* interrupt handler itself: called by assembly code*/
{
if(tick++%9) return; else tick=0; /* look every half second */
peek(0,timeaddr,&midtick,4); /* get tick count from low memory */
hour=midtick/65543; /* 65543 ticks/hour */
midtick %= 65543;
minute = midtick/1092;
midtick %= 1092;
second = midtick/18;
time[2]=0x30+hour/10; /* stuffing array for poking into video ram */
time[4]=0x30+hour%10;
time[8]=0x30+minute/10;
time[10]=0x30+minute%10;
time[14]=0x30+second/10;
time[16]=0x30+second%10;
poke(scrseg,offset,time,18); /* Who needs an operating system, anyway? */
}
/******************/
main(argc,argv) /* put compound command line in quotes as argument */
int argc;
char **argv;
{
int ourint(); /* declaring assembly language routine */
if(argc != 2){
puts("USE: clock \"command_line\"\n");
exit(0);
}
putds(); /*assembly language routine for storing DS in CODE segment */
peek(0,clkint*4,them,4); /* preserve old interrupt */
us[0]=ourint;
us[1]=_code;
poke(0,clkint*4,us,4); /* insert our own handler */
system(argv[1]); /* run applications program */
poke(0,clkint*4,them,4); /*nice children clean up after playing */
}
((C Figure 4 - Going All the Way))
main(argc,argv)
int argc;
char **argv;
{
int ourint();
char *malloc();
unsigned topseg /* bottom of freeable memory */
struct regs rr;
putds();
us[0]=ourint;
us[1]=_code;
poke(0,clkint*4,us,4);
topseg = 1 + (unsigned)malloc(0)/0x10 ; /*get paragraph boundary*/
rr.ax=0x3100; /* terminate but stay resident */
rr.dx=topseg + _data - _code; /*program size, in paragraphs */
interrupt(0x21,&rr); /* bye bye */
}