Video mode in Borland Pascal

Task: Draw a circle of the specified radius in the 320x200 point mode for the VGA video adapter. I work in Dosbox Implemented like this(Via bios interrupt):

Uses DOS;
var R:registers;
i,rad,...:integer;

Procedure SetVM; //Устанавливаем видеорежим через 10-е прерывание.
begin
  R.ah:=0;
  R.al:=$13;
  Intr($10,R);
end;

Procedure PutPixel();//процедура для отображения пикселя
begin
  R.ah:=$0C;
  R.al:=14;
  R.bh:=0;
  R.cx:=x;
  R.dx:=y;
  Intr($10,R);
end;

Then I just draw a circle in the loop, etc.

Question: you need to implement the same thing, but without interrupts, referring directly to the video memory, the assembler practically does not understand how to implement it?

Author: AndrrK, 2018-10-08

1 answers

Simplified video memory access option for 13h video mode 320x200 256 colors.

Procedure PutPixel(x:integere, y:integer, c:byte);
//процедура для отображения    пикселя
begin
      Mem[$a000:y*200 + x] := c;
end;

For optimization. You can store the offset in the ES register (for example), and access the memory through it. But... any use of a "long" pointer erases the ES. Example... something like that:

my_ofs := y*200 +x;
asm
   mov ax,0A000h; это 
   mov es,ax; и это можно вынести из цикла
   mov bx, my_ofs;
   mov al,c;
   mov es:[bx],al;
end

In borland c++, this is done better

 char _ES* v=0;
 _ES= 0xA000; // Задали ES
 v[y*200+x] = c;

You also need to remember that the multiplication operation is expensive. If you copy a rectangular area, or draw a flat line parallel to the axes the multiplication by 200 can be taken "out of brackets".

The rest of the ways I can't quickly show. I'll just list it:

  1. Optimization of the algorithm (here you can write a lot, depending on the task)
  2. CPU-level optimization. Using assembler, you can use 32,64,128 bit commands like 386 and MMX and SSE set. The chain commands movsb stosb, etc., load all the processor registers as much as possible to draw the desired shape, even if it is just copy the area.
  3. There are palette registers. You can throw them all to zero, and smoothly restore. You can do the lightning effect without redrawing the entire video memory. You can give the same color to two palette colors and play with the palette. Playing with the palette will give the effect of speed. But I think such special effects are outdated.
  4. (not suitable for this question) There is a 3-D accelerator card, there is a description of the 10h interrupt commands. There is OpegGL DirectX, reading articles on this topic-you can achieve the maximum speed of operation.

Very old games were made under this video mode. More links

1) http://pascal.sources.ru/articles/100.htm (here + working with the palette)

 0
Author: nick_n_a, 2018-10-10 13:51:33