
                        ķ
                         PROZERO's TUTORIAL III 
                        Ľ
                              for beginners

         Topics of the day: - the mouse
                            - read/write files
                            - .SCI-files



 I. How to use the mouse
 

  1. Introduction
  

    Using the mouse is really  something  easy.   There are a lot of
    useful fonctions executed  with  the  interrupt  33h.   In  this
    tutorial,  we will not use all the fonctions because I just want
    to show how  to  use  the  mouse  and  some functions are really
    useless.

  2. Explanations
  
  
    The first function of the interrupt 33h is 00h.   This  function
    modifies AX: if AX=0000h after calling this function, then there
    is  no  mouse  driver  and  if AX=0FFFFh (-1), there is one.  BX
    contains the number of  buttons  (2  or  3).  Here is an example
    code:

               mov ax,00h         ;function number
               int 33h            ;interrupt of the mouse
               cmp ax,0ffffh	  ;if no driver,
               jne error          ;display an error message
               mov nb_buttons,bx  ;(it's not often useful :)
               
    The function 01h displays the mouse cursor.  You simply have  to
    call  the  int  33h  with  AX=1h.   The  function  02h hides the
    cursor...

    The function 03h is quite  interesting: it reads the position of
    the mouse and the state of the buttons.  Call it with AX=3h  and
    then  you get CX with X-position and DX with Y-position.  Notice
    that the number in CX is between  0  and 638 and DX is between 0
    and 199.  BX contains the buttons state: if  the  bit  0  of  BX
    contains  1,  the  left  button is pressed and if it is 0, it is
    not.  The bit 1 is for  the  right button and on 3-button mouse,
    the bit 2 is for the middle button. Here is an example:
    
              loopmouse:
              mov ax,3      ; function 3
              int 33h       ; interrupt 33h
              or bl,bl      ; the same as cmp bl,0
              jne loopmouse ; if no buttons pressed, we loop.

    This small part of code pauses until a button is pressed.


    The function 04h  allow  to  change  the  position of the mouse.
    Call the function 04h with the new X-position in CX and the  new
    Y-position in DX.

    There are a  few  other  functions  but  i  think they are quite
    useless.  If you want to know  them,  read  the  file  MOUSE.INT
    taken  from  the  interrupt  list ((c) Ralf Brown).

    
  3. Source code
  

    The example program is really simple: it allows you to 'draw' in
    graphic mode.  It draws in green  when you move and if you press
    any button, it draws in white.  But before drawing, it shows how
    to use the show & hide cursor functions in textmode.
    
    In  the  source code, there is a putpixel routine.  If you don't
    know how it works,  read  the  chapter  tat is about loading and
    displaying .SCI files.
    

 II. How to read&write files
 

  1. Introduction
  

    In this second part, we will see how to read and write files but
    it'll be quite short because it's very easy.  It's important for
    the next chapter because we will load image files.

  2. Explanations
  

    We have functions of the int 21h that are the functions 3C 3D 3E
    3F  40  & 42.  As these functions are very easy to understand, i
    won't take time to explain it,  just read the file FILE.INT that
    i took from the interrupt list ((c) Ralf Brown).
    
    Main functions: 3ch : create a file
                    3dh : open a file
                    3eh : close a file
                    3fh : read a file (previously opened)
                    40h : write in a file (previously opened)
                    42h : move file pointer (=seek)

    It's not explained but  look  at  the  source code, ALL of these
    functions are used.

  3. Source code
  

    In this exemple (file.asm), i create  a file, open a file, close
    a file, read a file, write a file and move the file pointer.  So
    it's easy for you to see how these functions works.  If you want
    the program to run good, first delete the file  tmp.tmp  because
    it's the file that will be created.  But there is no error check
    so  if  it  hangs,  it  may  stop  the  program or make anything
    unwanted, sorry.  (NB: this  program does nothing visible except
    displaying a '' but look at the source code: it creates a file,
    then it read one byte in it).


 III. Displaying .SCI-files
 

    1. Introduction
    
    
    .SCI format (ColorRix) is  really  easy  to  understand  because
    there is no compression.  It's a sort of RAW file with a header.
    So we will load SCI file and display the picture on screen.

    2. Explanation
    
    
    I assume that you know a little about mode 13h.  If not, say  it
    to  me,  it MAY be a new topic for my tutorial.  But i'll make a
    small explanation:
    To write on the screen, you have to write in the segment  0a000h
    (in  real mode).  So set a segment register with 0a000h (we will
    use ES).  Then, the offset (e.g.  DI) represents the destination
    of the point on the screen.   As  the screen is 320x200, to have
    the position you just make ofs=x+y*320.  Look at  the  following
    piece of code that plots a point(X;Y) with color(col):
                 
                 mov ax,0a000h
                 mov es,ax       ;set video segment
                 mov ax,320
                 mul y       ;y*320...
                 add ax,x    ;...+x
                 mov di,ax   ;ofs:=y*320+x
                 mov al,col  ;al=color
                 mov es:[di],al ; put the pixel.

    Now,  a few words about setting the palette: You have to use the
    ports 3c7h, 3c8h and 3c9h.  Use  3c8h to select the color number
    to modify and use 3c9h to put the color components.  Look at the
    source for betting understanding.  3c7h  is  used  to  read  the
    color components.

    Back to our SCI loader, now. To format is very simple:
              Signature  'RIX3'      4 bytes
              Width of the picture   2 bytes
              Height of the picture  2 bytes
              unused? (skip it)      2 bytes
              Palette                768 bytes (r1, g1, b1, r2, g2 ...)
              Pixels                 X*Y bytes

    So we will skip the first  4  bytes,  then we will read x and y,
    set the palette and finally, put the pixels.  Very easy.

    3. Source code
    

    The  procedure  i create can easily be used in any program.  You
    have to call it with options:
         ds:dx : name of the file to load
         es:di : segment:offset of the pixels destination
     
    You can modify the source  to  make  an option that allow you to
    set the palette in a buffer instead of  directly  in  the  video
    card.

    The first version of this loader was in pmode.  If you want  it,
    just  ask  it  (but  i  think  you  should  be  able to make the
    transformation yourself,  no?   ;).   My  pmode version's better
    that this one in few points: as it  is  in  pmode,  i  can  load
    images  bigger  than  65536  bytes  (one  segment)  ; i load the
    palette in a buffer ; etc...
    


 IV. That's all folks
 

    I hope this helped someone!

  Remarks, ideas for new tuts, questions, or just contacts are welcome:
          Prozero / Cyclone
          Franois GUIBERT
          8 rue d'Anjou
          44450 La Chapelle Basse Mer
          FRANCE
          prozero@remcomp.komicom.fr (this email may change and i
          can't use it for now so try to check our web site to see
          the changements: http://www.mygale.org/07/Usul)

      Others tutorials: #1 : Displaying binary hexadecimal & decimal
                             number in assembler.
                        #2 : How  to  code  a  keyboard  handler  in
                             assembler
                        #3 : How  to  use  the  mouse, to read&write
                             files and to read .SCI-files.
                        #4 : !!I'M WAITING FOR YOUR SUGGESTIONS & WISHES!!
                        #5 : ...

                                           Ŀ
  Greetings going to the following groups: zen     nitrophusion
                                           ribbon    revelation
                                           olympus    freestyle
                                           skytech      cyclone
                                           
  and to all my contacts (...)

the endͻ
(c) prozero^cycloneͼ
