Current area: HOME ->

Zip File view

Adam's Assembler Tutorial 1.0


This page allows you to view the contents of a file contained inside a ZIP archive available at Programmer's Heaven. This means you can view the code and find what you need from it without having to download the ZIP file first. If the file contains source code for a language we recognize, we have syntax highlighted it.

Filename displayed: STARS.PAS
Found in file: ALLTUTS.ZIP

Download: MOD4WIN V2.30 MOD4WIN is a player for digital music modules on IBM-PC  compatible machines running Microsoft Windows.
Program StarfieldDemo;

(*
       ??????????????????????????????????????????????????????????????
       ?                  Starfield Demonstration 2.0               ???
       ?????????????????????????????????????????????????????????????? ?
       ? This program is a very simple example of how starfields    ? ?
       ? can be produced on the PC.  It is easy to understand, and  ? ?
       ? uses techniques that are important to learn.               ? ?
       ?                                                            ? ?
       ? You are free to modify and use this code in your programs, ? ?
       ? just don't put your name on it and redistribute it - okay? ? ?
       ? The program can also be improved upon greatly, so if you   ? ?
       ? make something good from this - send it to me.  I like to  ? ?
       ? see what people have done with my work.                    ? ?
       ?                                                            ? ?
       ?                        28th June 1996                      ? ?
       ?                                                            ? ?
       ? Contact Adam Hyde at:                                      ? ?
       ?    ? http://www.faroc.com.au/~blackcat                     ? ?
       ?    ? [[Email Removed]]                                 ? ?
       ?                                                            ? ?
       ?                      (C) 1996 Adam Hyde                    ? ?
       ?????????????????????????????????????????????????????????????? ?
        ???????????????????????????????????????????????????????????????
*)


{============================================================================}

Uses Crt;   { Needed for the KeyPressed and ReadKey functions }

{============================================================================}

Const
   NumStars      = 100;
   PlaneSpeed1   : Byte = 1; { The speed for the stars in plane 1           }
   PlaneSpeed2   : Byte = 2; { The speed for the stars in plane 2           }
   PlaneSpeed3   : Byte = 3; { The speed for the stars in plane 3           }

Type
   Starfield    = Record     { Structure to hold the various star locations }
      X         : Integer;   { Star X coordinate                            }
      Y         : Integer;   { Star Y coordinate                            }
      Plane     : Byte;      { Plane we'll be drawing in                    }
      Color     : Byte;      { The color to draw with                       }
   End;    { Record }

Var
   Star         : Array[0..NumStars] Of Starfield;

{============================================================================}

{ This procedure plots a pixel at location X, Y }
Procedure PutPixel(X, Y : Integer; Color : Byte);   Assembler;

Asm     { PutPixel }
   mov   ax, 0A000h          { Move the segment of the VGA into AX,         }
   mov   es, ax              { and now into ES                              }
   mov   bx, [X]             { Move the X value into BX                     }
   mov   dx, [Y]             { Move the Y value into DX                     }
   mov   di, bx              { Move X into DI                               }
   mov   bx, dx              { Move Y into BX                               }
   shl   dx, 8               { In this part we use shifts to multiply       }
   shl   bx, 6               { Y by 320                                     }
   add   dx, bx              { Now here we add X onto the above,            }
   add   di, dx              { giving us DI = Y x 320 + X                   }
   mov   al, [Color]         { Put the color to plot into AL                }
   mov   es:[di], al         { Put the byte, AL, at ES:DI                   }
End;    { PutPixel }

{============================================================================}

{ This procedure puts gets some random star locations for the starfield }
Procedure SetUpStarfield;

Var
   PlaneNum      : Byte;     { The plane we'll be working in                }
   StarToUse     : Integer{ The star we're currently working on          }

Begin   { SetUpStarfield }
   Randomize;
   For StarToUse := 0 To NumStars Do
    Begin    { For...Do }
       Star[StarToUse].X := Random(319);   { Get some random X and Y        }
       Star[StarToUse].Y := Random(199);   { locations                      }

       PlaneNum          := Random(3);     { Pick a plane to draw in at     }
       Inc(PlaneNum);                      { random                         }

       Case PlaneNum Of                    { Set the drawing colors for the }
        1 : Begin   { Case...Of }          { frame we're working in         }
               Star[StarToUse].Plane := 1;
               Star[StarToUse].Color := 8;
            End;    { Case...Of }
        2 : Begin   { Case...Of }
               Star[StarToUse].Plane := 2;
               Star[StarToUse].Color := 7;
            End;    { Case...Of }
        3 : Begin   { Case...Of }
               Star[StarToUse].Plane := 3;
               Star[StarToUse].Color := 15;
            End;    { Case...Of }
       End;    { Case }
    End;    { For...Do }
End;    { SetUpStarField }

{============================================================================}

Var
   CanGo         : Boolean;
   Count         : Byte;
   StarToUse     : Byte;
   DelayRate     : Byte;
   Ch            : Char;

Begin    { Main }
   CanGo         := False;
   DelayRate     := 50;
   Asm
      mov   ah, 00h                        { Put us in mode 13h             }
      mov   al, 13h
      int   10h
   End;    { Asm }

   SetUpStarfield;                         { Create some random locations   }
   Count := 1;

   Repeat                                  { Here's the main loop           }
    If KeyPressed Then
     Begin   { If...Then }
        Ch := ReadKey;

        Case Ch Of
         '-' : If DelayRate <> 250 Then Inc(DelayRate, 10);
         '+' : If DelayRate <> 10 Then Dec(DelayRate, 10);
         #27 : CanGo := True;              { User hit Escape, so lets go    }

        End;    { Case }
     End;    { If...Then }

    For StarToUse := 0 To NumStars Do
     Begin    { For...Do }

        PutPixel(Star[StarToUse].X, Star[StarToUse].Y, 0);
        { ^^^ Erase the old stars, by plotting them again in black ^^^      }

        Case Star[StarToUse].Plane Of
         1 : If Count = 1 Then Inc(Star[StarToUse].X);
         2 : If (Count = 1) Or (Count = 2) Then Inc(Star[StarToUse].X);
         3 : Inc(Star[StarToUse].X);
        End;

        If Star[StarToUse].X > 319 Then
         Dec(Star[StarToUse].X, 320);   { Check to see if star is off the   }
                                        { RIGHT of the screen               }
        If Star[StarToUse].X < 0 Then
         Inc(Star[StarToUse].X, 320);   { Check to see if star is off the   }
                                        { LEFT of the screen                }
        PutPixel(Star[StarToUse].X, Star[StarToUse].Y, Star[StarToUse].Color);
        Inc(Count);
        If Count = 4 Then Count := 1;
     End;    { For...Do }

     Delay(DelayRate);

    { ^^^ May need to be raised up or down depending on the speed of your   }
    { machine                                                               }

   Until CanGo;         { The user pressed Escape, so let's get out of here }

   Asm                  { Dump us back in 80x25 text mode                   }
      mov   ah, 00h
      mov   al, 03h
      int   10h
   End;    { Asm }

{============================================================================}

End.    { Main }


Groovy Hex Editor 1.6
Groovy Hex Editor is a tool for editing binary formats. I've paid particular attention to making it colorful and easy to use and tried to give it a cool looking color scheme (hence the name "gro...
HS NMEA GPS C Source Library 1.0
HS GPS is a software library (with full C source code) which provides access to a NMEA-183 compliant GPS receiver via a serial communications port, decoding NMEA sentences: $GPGGA, $GPGSA, $GPGSV, $G...
MOD4WIN V2.30
MOD4WIN is a player for digital music modules on IBM-PC compatible machines running Microsoft Windows.
Download Groovy Hex Editor 1.6 Groovy Hex Editor is a tool for editing binary formats. I've paid particular attention to making it colorful and easy to use and tried to give it a cool looking color scheme (hence the name "gro... Download HS NMEA GPS C Source Library 1.0 HS GPS is a software library (with full C source code) which provides access to a NMEA-183 compliant GPS receiver via a serial communications port, decoding NMEA sentences: $GPGGA, $GPGSA, $GPGSV, $G... Download MOD4WIN V2.30 MOD4WIN is a player for digital music modules on IBM-PC  compatible machines running Microsoft Windows.







Sponsored links

Build IT Knowledge with Current & Trusted Content
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.
Check Out IT Certification Preparation Materials
Sign Up With SkillSoft & Get Access to Training Materials for Over 50 Professional Certifications.
Localize software in three simple steps
Localize .Net, C/C++ & Delphi apps visually. HTML, HTML Help, XML & databases. Try Sisulizer now!
Localize Delphi software in three simple steps
Localize Delphi VCL & .Net apps visually. Plus HTML, HTML Help, XML & databases. Try Sisulizer now!
Web based bug tracking - AdminiTrack.com
AdminiTrack offers an effective web-based bug tracking system designed for professional software development teams.


Newsletter | Submit Content | About | Advertising | Awards | Contact Us | Link to us |
© 1996-2008 Community Networks Ltd All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Synchron Data - .NET development.