计算机移屏广告画面设计

Author: Date: 1996-05-31

        源程序scroll.c如下:
        /* scroll.c */
        #include <stdio.h>
        #include <stdlib.h>
        #include <graphics.h>
        #include <dos.h>
        unsigned long count=0;
        unsigned saveptr;
        int putspt(char *sptf,int x1,int y1,int color);
        void scroll(int,int);
        /*--------*/
        main()
        {
        char far *ptr;
        int gd=9,gm=2;
        initgraph(&gd,&gm," ");
        setfillstyle(1,1);
        bar(0,135,639,230);
        putspt("exam.spt",10,10,14);
        /*保存起始地址*/
        ptr=MK-FP(0x40,0x4e);
        saveptr=*ptr;
        while(1)
        { if(kbhit()) break;
        ptr=MK-FP(0x40,0x4e);
        scroll(1,400);
        }
        /*恢复起始地址*/
        ptr=MK-FP(0x40,0x4e);
        *ptr=saveptr;
        closegraph();
        }
        /**********/
        void scroll(int direction,int delay-time)
        { char far *ptr;
        unsigned ccw;
        char cch,ccl;
        ptr=MK-FP(0x40,0x4e);
        switch(direction){
        case 1: /* move right */
        /*修改显示指针*/
        *ptr-=1;count-=1;
        if(count<0){ *ptr+=1;count+=1; }
        delay(delay-time);
        break;
        case -1: /* move left  */
        *ptr+=1;count+=1;
        delay(delay-time);
        break;       }
        ccw=*ptr;
        ccl=(char)ccw;
        cch=(char)(ccw>>8);
        /*选择显存起始地址(高)*/
        outportb(0x3d4,12);
        outportb(0x3d5,cch);
        /*选择显存起始地址(低)*/
        outportb(0x3d4,13);
        outportb(0x3d5,ccl);
        }
        /**********/
        int putspt(char *sptf,int x1,int y1,int color)
        {
        /* 略 */
        unsigned char dot;
        FILE *fp;
        int h,w,i,j,k,p,x,y;
        fp=fopen(sptf,"rb");
        fseek(fp,34L,SEEK-SET);
        fread(&w,2,1,fp);
        fseek(fp,36L,SEEK-SET);
        fread(&h,2,1,fp);
        if(fseek(fp,64L,SEEK-SET)) return(1);
        for(i=0;i<h;i++)
        { y=y1+i;
        for(j=0;j<w/8;j++)
        {
        x=x1+8*j;dot=fgetc(fp);p=0x80;
        for(k=0;k<8;k++)
        {
        if(!(dot&p))  putpixel(x+k,y,color);
        p>>=1;
        }
        }
        }
        fclose(fp);return(0);
        }