Lesson 2: Graphics mode 13h By Blazing Scorpion HTTP://www.fortunecity.com/roswell/chupacabras/11/ To start programming graphics, you first have to set up the screen. I will use Mode 13h throughout the early tutors, because it is the best mode available for plain vga (except for possibly mode x, but that is beyond the horizon for this tutorial). To use Mode 13h we need to tell the computer that we are going to. What we need to do is move the screen value into AX. After that we run interrupt 10h (a video interrupt) and it will change to the mode in AX. (Note: 13h means 13 hexadecimal. Hexadecimal is a base 6 number system. It isn't too important.) Here is some code to change to mode 13h. ASM MOV AX,13h {moves 13h into AX} INT 10h {Interrupt 10h} END; To go back to text mode we need to do the same, but with a different value: ASM MOV AX,3h {3h is the standard dos text mode} INT 10h {Interrupt 10h} END; Now that we have that down, we need to know how to write pixels to the screen. Pascal's built in pixel plotting is MUCH too slow. This means we need to use a different method. We need to write our information directly to the internal memory of the computer, which will print our pixel on the screen. We can do this through the following code: ASM MOV AX,[VGA] {sets AX to vga memory} MOV ES,AX MOV DI,[nx] {sets DI to x value of pixel} MOV DX,[ny] {sets DX to y value of pixel} MOV BX,DX SHL DX,8 SHL BX,6 ADD DX,BX {past 3 statements are essentially DX=(320*y value of pixel)} ADD DI,DX {add x + y} MOV AL,[color] {set al to color} STOSB {send the byte} END; What does this mean? First of all, when a variable appears like this [variable] that is a regular Pascal variable inside of the ASM code. So if you had a variable VGA then it would be [VGA] in an ASM segment. The [VGA] in the program is a constant defined as "VGA = $A000;". This sets VGA to the beginning of the VGA's memory. (confusing?) ES cannot be directly assigned a value. It has to be assigned through a register. The y value is multiplied by 320 and then added to x to find the number of bytes to skip until you get to the spot in memory that you want to change. AL is the value that STOSB places at memory location DI. STOSB finishes the process. Whew, that was tough. (trouble? Send E-mail to ted@totcon.com) Obviously you could clear the screen by repeating this 64000 times until the screen was full, but this isn't exactly efficient. We can use the Fillchar pascal statement to speed up the process. This statement fills a certain number of bytes of memory with a set value. In the next chapter I will finish explaining this and show you a few more graphics things. Au revoir!