Advertisement
Guest User

CP/M-86 Aztec C 3.2d VGA TEST pixel.c

a guest
Sep 29th, 2021
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.98 KB | None | 0 0
  1. /**************************************************************************
  2.  * pixel.c                                                                *
  3.  * written by David Brackeen                                              *
  4.  * http://www.brackeen.com/home/vga/                                      *
  5.  *                                                                        *
  6.  * This is a 16-bit program.                                              *
  7.  * Tab stops are set to 2.                                                *
  8.  * Remember to compile in the SMALL memory model!                         *
  9.  * To compile in CP/M-86 Aztec C 3.2d                                     *
  10.  *      cc pixel.c                                                        *
  11.  *      ln pixel.o m.lib c.lib                                            *
  12.  *                                                                        *
  13.  * This program will only work on CP/M86 systems with a                   *
  14.  * VGA, SuperVGA or compatible video adapter.                             *
  15.  *                                                                        *
  16.  * Please feel free to copy this source code.                             *
  17.  *                                                                        *
  18.  * DESCRIPTION: This program demostrates how much faster writing directly *
  19.  * to video memory is.                                                    *
  20.  **************************************************************************/
  21.  
  22. #include <stdio.h>
  23. /*
  24. #include <stdlib.h>
  25. #include <dos.h>
  26. */
  27. #include <regs.h>
  28. #include <math.h>
  29.  
  30. #define VIDEO_INT           0x10      /* the BIOS video interrupt. */
  31. #define WRITE_DOT           0x0C      /* BIOS func to plot a pixel. */
  32. #define SET_MODE            0x00      /* BIOS func to set the video mode. */
  33. #define VGA_256_COLOR_MODE  0x13      /* use to set 256-color mode. */
  34. #define TEXT_MODE           0x03      /* use to set 80x25 text mode. */
  35.  
  36. #define SCREEN_WIDTH        320       /* width in pixels of mode 0x13 */
  37. #define SCREEN_HEIGHT       200       /* height in pixels of mode 0x13 */
  38. #define NUM_COLORS          256       /* number of colors in mode 0x13 */
  39.  
  40. typedef unsigned char  byte;
  41. typedef unsigned short word;
  42.  
  43. /* byte *VGA=(byte *)0xA0000000L; */       /* this points to video memory. */
  44. word VGA_SEG = 0xa000;
  45.  
  46. /* word *my_clock=(word *)0x0000046C;  */    /* this points to the 18.2hz system
  47.                                          clock. */
  48. word my_clk_seg = 0x0000;
  49. word my_clk_ofst = 0x046c;
  50.  
  51. int rand(){
  52.     return (int)(ran() * 32767.0);
  53. }
  54.  
  55. /**************************************************************************
  56.  *  set_mode                                                              *
  57.  *     Sets the video mode.                                               *
  58.  **************************************************************************/
  59.  
  60. void set_mode(mode)
  61. byte mode;
  62. {
  63.   union REGS regs;
  64.  
  65.   regs.h.ah = SET_MODE;
  66.   regs.h.al = mode;
  67.   int86(VIDEO_INT, &regs, &regs);
  68. }
  69.  
  70. /**************************************************************************
  71.  *  plot_pixel_slow                                                       *
  72.  *    Plot a pixel by using BIOS function 0x0C (Write Dot).               *
  73.  **************************************************************************/
  74.  
  75. void plot_pixel_slow(x, y, color)
  76. int x;
  77. int y;
  78. byte color;
  79. {
  80.   union REGS regs;
  81.  
  82.   regs.h.ah = WRITE_DOT;
  83.   regs.h.al = color;
  84.   regs.x.cx = x;
  85.   regs.x.dx = y;
  86.   int86(VIDEO_INT, &regs, &regs);
  87. }
  88.  
  89. /**************************************************************************
  90.  *  plot_pixel_fast                                                       *
  91.  *    Plot a pixel by directly writing to video memory.                   *
  92.  **************************************************************************/
  93.  
  94. void plot_pixel_fast(x, y, color)
  95. int x;
  96. int y;
  97. byte color;
  98. {
  99. /*  VGA[y*SCREEN_WIDTH+x]=color; */
  100.   pokeb(y * SCREEN_WIDTH + x, VGA_SEG, color);
  101.  
  102. }
  103.  
  104. /**************************************************************************
  105.  *  Main                                                                  *
  106.  *    Plots 50000 pixels two different ways: using the BIOS and by        *
  107.  *    directly writing to video memory.                                   *
  108.  **************************************************************************/
  109.  
  110. main()
  111. {
  112.   int x,y,color;
  113.   float t1,t2;
  114.   word i,start;
  115.  
  116. /*  srand(*my_clock); */                  /* seed the number generator. */
  117.   set_mode(VGA_256_COLOR_MODE);       /* set the video mode. */
  118.  
  119. /*  start=*my_clock; */                   /* record the starting time. */
  120.   start = peedw(my_clk_ofst, my_clk_seg);
  121.  
  122.   for(i=0;i<50000L;i++)               /* randomly plot 50000 pixels. */
  123.   {
  124.     x=rand()%SCREEN_WIDTH;
  125.     y=rand()%SCREEN_HEIGHT;
  126.     color=rand()%NUM_COLORS;
  127.     plot_pixel_slow(x,y,color);
  128.   }
  129.  
  130. /*  t1=(*my_clock-start)/18.2; */         /* calculate how long it took. */
  131.   t1 = peekw(my_clk_ofst, my_clk_seg)/18.2;
  132.  
  133.   set_mode(VGA_256_COLOR_MODE);       /* set the video mode again in order
  134.                                          to clear the screen. */
  135.  
  136. /*  start=*my_clock; */                   /* record the starting time. */
  137.   start = peedw(my_clk_ofst, my_clk_seg);
  138.  
  139.   for(i=0;i<50000L;i++)               /* randomly plot 50000 pixels. */
  140.   {
  141.     x=rand()%SCREEN_WIDTH;
  142.     y=rand()%SCREEN_HEIGHT;
  143.     color=rand()%NUM_COLORS;
  144.     plot_pixel_fast(x,y,color);
  145.   }
  146.  
  147. /*  t2=(*my_clock-start)/18.2; */          /* calculate how long it took. */
  148.   t2 = peekw(my_clk_ofst, my_clk_seg)/18.2;
  149.  
  150.   set_mode(TEXT_MODE);                /* set the video mode back to
  151.                                          text mode. */
  152.   /* output the results... */
  153.  
  154.   printf("\n");
  155.   printf("Slow pixel plotting took %f seconds.\n",t1);
  156.   printf("Fast pixel plotting took %f seconds.\n",t2);
  157.   if (t2 != 0) printf("Fast pixel plotting was %f times faster.\n",t1/t2);
  158.  
  159.   return 0;
  160.  
  161. }
  162.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement