147.VGA256色模式编程

/*
     VGA256.c -- VGA 256 色编程
*/
#include "dos.h"
#include "conio.h"
#include "stdio.h"

void InitScr();
void RstScr();
void PutPoint(int x, int y, int Color);
void Rect(int x1, int y1, int x2, int y2, int Color);
void LineV(int x1, int y1, int x2, int y2, int Color);

int main()
{
    int x1, y1, x2, y2, i, j;
    x1 = y1 = 0;
    x2 = 319;
    y2 = 199;
    InitScr();
    for (i = 0; i < 256; i++)
       LineV(i, 0, i, 199, i);
    for( i = 18; i < 100; i++)
       Rect(x1++, y1++, x2--, y2--, i);
    for( i = 18; i < 50; i++)
       Rect(x1--, y1--, x2++, y2++, i);
    getch();
    RstScr();
}

void InitScr()
{
    union REGS In;
    In.x.ax = 0x13;                 /*进入13H模式  */
    int86(0x10, &In, &In);
}

void RstScr()
{
    union REGS In;
    In.x.ax = 0x03;             /* 退出13H模式 */
    int86(0x10, &In, &In);
}

/* 直接写视频缓冲区 */
void PutPoint(int x, int y, int Color)   /* 画点函数 */
{
   char far *p;
   p = (char far *) (0x0a0000000L);
   * (x+y*320+p) = Color;
}

/* 利用VGA BIOS中断在屏幕上画点, 速度慢
void PutPoint(int x, int y, int Color)
{
   union REGS  In;
   In.h.ah = 0x0C;
   In.h.al = Color;
   In.x.cx = x;
   In.x.dx = y;
   In.h.bh = 0;
   int86(0x10, &In, &In);
}
*/

void LineV(int x1, int y1, int x2, int y2, int Color)  /* 画一垂直线 */
{
   int i;
   for (i = 0; i < 199; i++)
      PutPoint(x1, i, Color);
}

void Rect(int x1, int y1, int x2, int y2, int Color)  /* 画一矩形*/
{
   int i;
   for(i = x1; i <= x2; i++)
   {
      PutPoint(i, y1, Color);
      PutPoint(i, y2, Color);
   }
   for(i = y1; i <= y2; i++)
   {
      PutPoint(x1, i, Color);
      PutPoint(x2, i, Color);
   }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程与实战

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值