flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
xoxo 20 May 2025, 12:14
EDIT: phrasing, added PS;
Thanks a bunch for writing this! Found all info useful, including the keyboard shortcuts You mentioned at the end. Eager to learn more about your workflow with helpPC and volkov! xoxo PS. Keys for starting the mapper on my system were a little different in a default installation: [F11/F12]+M. As per official docs: https://dosbox-x.com/wiki/Home |
|||
![]() |
|
Hans-Joachim Rudolph 04 Oct 2025, 23:43
Here is some more for beginners. This is just preliminary for the next part where we'll write a graphical animation that replicates an effect seen in a well-known DOS era game.
Code: Part 2: Graphical template Playing with graphics (VGA in this case) is a nice way to get started. On the one hand it’s quite nice to look at, on the other hand it’s rather easy. You just write into some memory lo‐ cation and pixels start to appear on your screen. But you need to switch DOS into a graphical mode first. The most popular by far is typically referred to as mode 13 (13h, $13 or 0x13 depend‐ ing on your preference). Here is an example how you can draw a single pixel. Save it in Dosbox, open it with fasmd and run it straight away with F9 like you saw in the last part. You should see a black screen and a tiny white dot in the upper left. org $100 mov ax,$13 int $10 ; set up video mode push $A000 pop fs ; set up video segment address mov byte[fs:0],$F ; paint a single white pixel mov ah,7 int $21 ; wait for keypress mov ax,3 int $10 ; return to 80x25 chars text mode int $20 ; exit program The first line is practically all the boilerplate that’s needed to write a COM file. COM files are way easier than EXE files. They are loaded into memory and then code starts executing at $100. That’s what this first line is for. It tells FASM to start generating addresses at this origin. The next two lines you’ll see an interrupt request, which is the common way to talk to the OS, BIOS, CPU and so on. In higher languages you use API functions calls that would look something like VideoBios(0, 0x13). In assembly the MOV instruction can be thought of as setting the arguments to the call. There are two arguments because AX is a 16‐bit register which consists of 8‐bit AH (high) and AL (low). So this one line sets AH to 0 and AL to $13. The next line actually hands other the control. You can consult HelpPC for this particular one by looking for INT 10,0. There you’ll see that INT 10 handles video requests, AH (0) is for the function that you request (set video mode) and finally AL ($13) is the actual first "argument". The mode is then switched to $13. This is a multi‐color video mode with 320x200 pixel. Now we can simply write into video memory, but there is one prob‐ lem. In DOS we typically have 16 bit wide registers. The highest num‐ ber they can handle is $FFFF = 65535. The video that we want to address, however, is at $A’0000. See how this is one hexadecimal digit (four bit) more? We need a second register to keep this information. This is where the segment register (fs in this case) comes in. We set this up with $A000 (three zeroes). When we use it in [fs:0] a line later the CPU interprets it: It shifts $A000 left which makes it $A’0000 and adds the value behind the colon (which is 0 in this case). That’s roughly how you address 20‐bit addresses on 16‐bit DOS and a very basic introduction to Memory Segmentation on x86. The next line actually draws the pixel. MOV moves (rather copies) data. In this case it moves a color value ($0F) to the first address of the video RAM. The very first address of the video RAM is shown in the upper left corner of the screen. You could replace the zero in [fs:0] with another number and hit F9 again to run the code. Start small value and make your way up. You should notice the white dot starts moving right. Eventually you’d hit the right end of the screen and the dot just skips the beginning of the next line. It’s the same way we read text. With HelpPC or searching the internet you’ll likely decipher the next interrupt requests easily. The first is meant as a conve‐ nience. It just keeps your program running until you have found your pixel on screen. The next switches back to the original text mode. The last int exits the program. You need to return control to the DOS command interpreter otherwise your program will just hang in the end and you need to restart the computer or Dosbox. xoxo, thanks for your feedback. :) Is there something you'd like to see in a future part? |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.