Computer Engineering II
||Kalbarczyk, Fall 2000
Machine Problem 4: High Quality Graphics
This MP is under construction
||Thursday, October 26, 2000
||Protected Mode, Great Graphics, Mouse
||Tuesday Nov 14 5:00pm
Ever looked at something like Adobe Photoshop and wondered how they
did it? Or even Windows Paint? In MP4 we are going to create a program
somewhere inbetween the previous two. You now have the amazing tool of
Protected Mode Programming available to you. It's time to start really
We're going to implement some features that you might expect in a paint
- Controlling the program with the Mouse
- Ability to enter text strings via DrawChar
- Stamping images onto the canvas with AlphaBlit
- Line Drawing via AALine
Only it won't be the plain vanilla way of doing things. We're doing
a full alpha-blit for stamping images. This way we can stamp images
that have a drop shadow, and have it look good. We're writing in an
anti-aliased font, which again makes the text look rather good. We're
drawing anti-aliased lines--none of the stairstep jagginess of plain
lines for us!
Take a look at the pages we've linked above for full information on
how to implement them. You probably need to learn it before you start
We're also using the brand new High Resolution
Graphics library written by our very own Pete Johnson, to let you do
these amazing tasks. Read up on it--as it alone tells you of some known
problems when trying to use it, especially in conjunction with cv32.
Check back if you start running into issues you really don't understand,
and let us know so we can add it to the page.
You are required to code 9 functions. These functions are described
in C notation whenever you see the parenthesis, or assembly notation if
you see register names. Don't forget the leading underscore that goes
unwritten in the C notation!
Note: I've tried to list these in something approaching order of
difficulty. You can certainly approach them in any order you feel
appropriate, but we strongly suggest understanding and/or implementing
AlphaBlit() before AALine().
- Clear the "paint" area (_ImageBlock) to a solid color
- The area you want to clear is 640 by 450 pixels
- Use a string operation to make this short and easy and worth full
- Writes to variables: MouseSeg, MouseOff
- Returns 1 on error, 0 otherwise
- Install the mouse callback
- Don't forget to lock areas the callback will access
- You need to use a library function to
obtain a real-mode callback address (segment and offset) that you can
pass to Int 33h.
- Do not try to pass cs and the offset of MouseCallback
directly to Int 33h: selectors are not the same as segments!
- You want the callback to be called on left mouse button press and
release as well as on mouse movement.
- To get the length of the handler, subtract the start of the
handler from the label at the end of the handler (remember, labels
are just addresses)
- Reads from variables: MouseSeg, MouseOff
- Remove the mouse callback
- Uninstall the mouse callback using Int 33h before
you free the real-mode callback.
- DPMIRegsPtr, pointer to a DPMI registers structure
- Adds event to event queue
- Index into the DPMI registers structure using the library-defined
DPMI_*_off, where *=EAX,EBX, etc.
- Look at the mouse interrupt documentation to find what registers
map to what variables
- See the Mouse section for further information.
- DestSel, destination selector to write character into
- Dest, offset into DestSel
- Char, ASCII character to write
- CharPos, position to write character at: specified in character units, not pixels
- Color, color to make text
- Correct character written to correct location in DestSel
- Writes a single character. Used in both dialogs (typing in filenames) and
with the Text tool to write strings to the screen.
- Each character is 16x16.
- Overwrite the color value of each pixel written with the Color argument,
but leave the alpha value intact: as the characters are antialiased, when they
are copied to the screen using AlphaBlit, they will be correctly blended onto
- MMX highly recommended, but not required. Use this function to
familiarize yourself with the MMX instructions and how to use them to modify
32-bit pixels before diving into AlphaBlit.
- The width of the destination bitmap is always 640 (pixels). You need to
adjust the destination pointer after every row so that the character is
aligned properly on the destination.
- See Drawing Strings of Text for further information.
- DestSel, selector containing destination image to blit onto
- Dest, offset of start of image within DestSel
- DestWidth, width of destination image in pixels
- DestX, X coordinate of the upper-left corner of where the source image should be placed on the destination
- DestY, Y coordinate of the upper-left corner of where the source image should be placed on the destination
- SrcSel, selector containing source image to blit from
- Src, offset of start of image within SrcSel
- SrcWidth, width of source image in pixels
- SrcHeight, height of source image in pixels
- Source alpha-blended onto destination
- Copy a source image over a destination image taking into account the
alpha value of each pixel in the source (the destination alpha values are
- DestWidth and SrcWidth will always be multiples of 2.
- Provides the setup and loop for AlphaCompose()
- You must correctly handle the source image going off the right of
the destination (don't worry about it going off the bottom).
- You should load RoundingFactor into an MMX register in the setup here.
It will be used by AlphaCompose, but AlphaCompose doesn't know what the real
data segment (where RoundingFactor is stored) is, so it can't load it. If you
use the library AlphaCompose, load RoundingFactor into mm4 and zero mm5 (pxor
mm5, mm5) in AlphaBlit, before starting the loop that calls AlphaCompose().
- See Alpha Blitting for further information.
- ds:esi points to the source image double-pixel
- es:edi points to the destination image double-pixel
- Alpha Composed Source over Destination in Destination double-pixel
- Perform the Over operation as a helper function to AlphaBlit()
- Use MMX for full points and speed
- The Over operator is Dest = (alpha * Source) + ((1-alpha) * Dest)
- See Alpha Blitting for further
information and optimizations.
- (x0,y0), starting coordinate of anti-aliased line
- (x1,y1), ending coordinate of anti-aliased line
- Color, color to draw line with
- Anti-aliased line drawn in the current color
- Draws an anti-aliased line in the current color by calling
- This function calls DrawPixelD in an irregular way!
- Make sure to leave ES as passed, when you call DrawPixelD
- See Anti-aliased Lines for further
information and optimizations
- addr holds the pixel address
- Color holds the base color to draw the pixel with
- st0 holds the calculated distance
- Composited pixel for Anti-aliased line
- Perform the one pixel Alpha Compositing with Alpha as a function
- Don't use MMX in this function!
- ES holds the selector to which you should draw. ([ES:addr])
- This function is called irregularly! Nowhere else will you see a
value passed on the FPU stack.
- Use the Over operator, as above.
Monitor the newsgroup and this on-line section for revisions to the
MP or to the write-up
Copy the given MP4 files from the network drive to your home directory
with the following command:
xcopy /s V:\ece291\mp4 W:\mp4
Alternatively, from home you can download the same files as mp4.zip.
Note that this MP will
not work unless you have Windows 2000 (or possibly NT).
Unlike most previous MP's, you need to run V:\djgpp\djgpp.bat
before building your program (only once per DOS session!).
nmake to build an executable program using the given ECE291
As with previous MP's, use a text editor to modify the program. As given,
the program uses LIBMP4 routines to implement all functionality. To receive
full credit for the assignment, you will need to implement each of the
subroutines described above with your own code. At Handin, the program
must be fully functional, with library functions used as necessary to
replace any broken or unwritten functions. You will not receive points
for library functions.
By modifying a few comments, you can mix and match usage of your own code
and Library routines. You may notice that the LIBMP4 routines contain extraneous
and difficult-to-read code. They are not meant to be easily unassembled!
Verify that your program meets all requirements for handin.
Print a copy of the
Demonstrate MP4.EXE to a TA or to the instructor.
Be prepared to answer questions about any aspect of the operation of your
program. The TAs will not accept an MP if you cannot fully explain all
operations of your code.
Handin in your program with the TA on the Web Page
Print your MP4.ASM 4 pages per page and double sided.
If you don't know how to do this ask a TA for assistance.
Staple the MP4 grading sheet to the front of your MP4.ASM file and give
both to the same TA that approved your demonstration.