home *** CD-ROM | disk | FTP | other *** search
/ 500 Game Surplus / XSurplus.iso / 217 / STAMPPK.EXE / SAMPLE.AS_ / SAMPLE.AS
Text File  |  1993-12-06  |  10KB  |  257 lines

  1. ; Copyright 1993 DATAWARE
  2. ; P.O. Box 64211, Lubbock, TX 79464-4211
  3. ;
  4. ; This program displays a graphic image (star) on the screen.
  5. ;
  6. ; The image was produced within STAMP PAD by using the diskette function
  7. ; (located on the cut and paste menu). The diskette function saves a
  8. ; marked area to a text file in the STAMPPAD directory called ASCII.TXT.
  9. ; The file is in the proper format to include it in an assembly language
  10. ; program. Each pixel is represented with its equivalent hexadecimal number
  11. ; preceded by "db". The procedures included in this sample program will
  12. ; display images saved with the diskette function in STAMP PAD.
  13. ;
  14. ; If you want to display other images using this program, save a file
  15. ; using the diskette function in STAMP PAD. Then insert the text from the
  16. ; file, ASCII.TXT in the data segment after the label, "stamp_pad".
  17. ; The "equ" values also need to be adjusted to specify the size of the image
  18. ; and the starting position.
  19. ;
  20. ; This program was written using MASM 6.0. The compiled version, SAMPLE.EXE
  21. ; is also included in the STAMPPAD directory.
  22. ;
  23. ; *****************************************
  24. ; PROGRAM BEGINS HERE
  25. ; *****************************************
  26. ;
  27. TITLE sample.asm
  28. ;
  29. ;
  30. .DOSSEG
  31. .MODEL LARGE
  32.  
  33. ; MACROS are located here
  34.  
  35.  
  36. ; Macro used when displaying text on the screen.
  37. ; To use this macro, type "print" and then the label of the text to be
  38. ; displayed (located in the data segment). For an example,
  39. ; see the label, "message" in the data segment.
  40.  
  41.     print   MACRO   text        ; macro to print a line of text at cursor location
  42.         mov     ah,2        ; DOS function to set cursor position
  43.         mov     bh,0        ; page zero when in graphics mode
  44.         mov     dh,24        ; row (Y coordinate)
  45.         mov     dl,10        ; column (X coordinate)
  46.         int     10h         ; call BIOS
  47.         lea     dx,text        ; gets address of text
  48.         mov     ah,9        ; and uses DOS function 9 to print it
  49.         int     21h
  50.         call    wait_key        ;procedure to wait for a key stroke
  51.         ENDM
  52.  
  53. ; Macro to test for a VGA board
  54.     is_vga  MACRO
  55.         mov     ax,1a00H        ; function to determine if VGA ah=1aH al=00
  56.         int     10h         ; call bios
  57.         cmp     al,1aH        ; only VGA cards return 1ah in al
  58.         je        @F            ; if VGA continue
  59.         print   not_vga        ; if not VGA quit
  60.         jmp     exit
  61.         @@:
  62.         ENDM
  63.  
  64. ; EQU statements are located here except for the EQU statements
  65. ; associated with the graphic image.
  66.  
  67.     VIDEO_SEG        EQU 0A000H        ; VGA video segment
  68.     GMODE        EQU    13H        ; VGA 320x200, 256 color mode
  69.     DEFAULT_VIDEO   EQU     3        ; default video mode 80x25 text
  70.     BACK_GROUND     EQU  0000H        ; color used to clear screen (COLOR-4)
  71.  
  72. ; -----------------------------------------------
  73. .STACK
  74.  
  75. ; -----------------------------------------------
  76. .DATA
  77. ; -------------------------------------------------------------------------
  78. ; The EQU statements (stamp_pad_x, etc.) determine the location and size of
  79. ; the graphic image saved as ASCII.TXT. "stamp_pad_x" and "stamp_pad_y"
  80. ; define the upper left hand corner of the graphic image (in pixels) and
  81. ; "stamp_pad_x_1" and "stamp_pad_y_1" define the length and height in the
  82. ; x-direction in the y-direction respectively.
  83.  
  84. ; -------------------------------------------------------------------------
  85. ; location and size of the graphic image
  86.     stamp_pad_x    equ 151    ; starting column in pixels
  87.     stamp_pad_y    equ  93    ; starting row in pixels
  88.     stamp_pad_x_l    equ  14    ; length in pixels
  89.     stamp_pad_y_l    equ  14    ; height in pixels
  90.  
  91. ; -------------------------------------------------------------------------
  92. ; This is the file, ASCII.TXT with a label called "stamp_pad". If you want to
  93. ; display other images using this program, save a file using the
  94. ; diskette function in STAMP PAD. Then delete the text following
  95. ; the label, "stamp_pad" and replace it with the text from ASCII.TXT.
  96. ; The "equ" values (above) also need to be adjusted to specify the size of
  97. ; the image and the starting position.
  98.  
  99. stamp_pad  db 00h,00h,00h,00h,00h,00h,2Ch,2Ch,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h
  100. db 2Ch,2Ch,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,2Ch,2Ch,2Ch,2Ch,00h,00h,00h
  101. db 00h,00h,00h,00h,00h,00h,00h,2Ch,2Ch,2Ch,2Ch,00h,00h,00h,00h,00h,2Ch,2Ch,2Ch,2Ch
  102. db 2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,00h,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch
  103. db 2Ch,2Ch,2Ch,00h,00h,00h,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,00h,00h,00h,00h
  104. db 00h,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,00h,00h,00h,00h,00h,00h,2Ch,2Ch,2Ch,2Ch,2Ch
  105. db 2Ch,2Ch,2Ch,00h,00h,00h,00h,00h,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,00h,00h
  106. db 00h,00h,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,2Ch,00h,00h,00h,2Ch,2Ch,2Ch,2Ch,2Ch
  107. db 00h,00h,2Ch,2Ch,2Ch,2Ch,2Ch,00h,00h,2Ch,2Ch,2Ch,00h,00h,00h,00h,00h,00h,2Ch,2Ch
  108. db 2Ch,00h,2Ch,2Ch,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,2Ch,2Ch
  109.  
  110.  
  111. ; Additional data used by the display procedures
  112.  
  113. not_vga         db "Requires a VGA card.  Press any key.$"    ; error message
  114. message            db "PRESS ANY KEY TO EXIT$"            ; message
  115. color_back_ground   dw 0    ; back ground color for clear_screen
  116. number_of_rows        dw 0    ; number of rows in graphic image being drawn
  117. number_of_cols        dw 0    ; number of columns in graphic image being drawn
  118. count_rows        dw 0    ; counter in draw_screen
  119. start_pos        dw 0    ; starting position moved to DI, sum row, col math
  120.  
  121. ; -----------------------------------------------
  122. .CODE
  123. .STARTUP
  124.     start:
  125.     mov    ax,@data
  126.     mov    ds,ax        ; initialize data segment
  127.  
  128. ; test for VGA card
  129.     is_vga            ; macro for testing for VGA card
  130.  
  131. ; set to VGA graphics mode 320 x 200 -- 256 colors
  132.     mov    ah,0        ; set video mode function
  133.     mov    al,GMODE    ; mode to be set
  134.     int    10h        ; call DOS to set video mode
  135.  
  136. ; clear the screen first
  137.     mov    color_back_ground,BACK_GROUND  ; color for clear_screen to use
  138.     call    clear_screen               ; clear screen to back ground color
  139.  
  140. ; draw the graphic image on the screen
  141.     call    d_stamp_pad ; function to display the graphic image
  142.  
  143. ; message to continue
  144.     print message        ; macro for displaying text
  145.  
  146. ; reset video
  147.     mov    ah,0          ; set video mode function
  148.     mov    al,DEFAULT_VIDEO  ; default text mode
  149.     int    10h          ; call DOS to reset video mode
  150.  
  151. exit:
  152.  
  153. .EXIT
  154. ; *****************************************
  155. ; PROCEDURES
  156. ; *****************************************
  157.  
  158. ; -----------------------------------------
  159. ; "draw_screen" draws the graphic image that is stored in data segment.
  160. ; It assumes DS points to the data segment that contains
  161. ; the graphic image.    BX will contain the address of graphic image.
  162. ; This procedure will set ES to the video segment for the destination.
  163.  
  164. draw_screen proc
  165.     mov     di,start_pos     ; offset in video segment
  166.     mov     ax,VIDEO_SEG     ; ES gets video segment
  167.     mov     es,ax
  168.     mov     count_rows,0     ; row counter initialize
  169. next_row:
  170.     mov     cx,number_of_cols     ; counter for loop-number of columns to be printed
  171. next_char:
  172.     mov     al,ds:[bx]         ; the byte pointed to by BX is moved to AL
  173.     mov     es:[di],al         ; AL to video segment
  174.     inc     di             ; move screen pointer 1 byte to right
  175.     inc     bx             ; data pointer moved 1 byte
  176.     loop    next_char         ; loop until CX is zero
  177.     inc     count_rows         ; advances to next row
  178.     mov     cx,count_rows
  179.     cmp     cx,number_of_rows     ; see if done enough rows
  180.     je        exit_set_up      ; if equal done
  181.     mov     dx,320         ; width of screen
  182.     sub     dx,number_of_cols     ; minus width of the graphic image
  183.     add     di,dx         ; added to DI is the next row
  184.     jmp     next_row         ; print another row
  185. exit_set_up:             ; when complete exit here
  186.     ret
  187.  
  188. draw_screen endp
  189.  
  190. ; -------------------------------------------------------------------
  191. ; "d_stamp_pad" passes the graphic image information to draw_screen to
  192. ; actually draw the graphic image. First the offset in the video segment
  193. ; is calculated using the X and Y coordinates and passed to draw_screen
  194. ; with a variable (start_pos).    Then the length and height are passed
  195. ; to draw_screen through variables also.  The address of the actual
  196. ; data is passed via the BX register.
  197.  
  198. d_stamp_pad proc
  199.     mov     cx,stamp_pad_x     ; column value for the graphic image
  200.     mov     dx,stamp_pad_y     ; row value for the graphic image
  201.     call    calc_start         ; calculate starting position
  202.     lea     bx,stamp_pad     ; address of the graphic image is loaded in BX
  203.     mov     ax,stamp_pad_y_l     ; length of the graphic image
  204.     mov     number_of_rows,ax     ; goes into variable
  205.     mov     ax,stamp_pad_x_l     ; same for height value
  206.     mov     number_of_cols,ax
  207.     call    draw_screen      ; draw it on the screen
  208.     ret
  209.  
  210. d_stamp_pad endp
  211.  
  212. ; -----------------------------------------
  213. ; "clear_screen " clears the screen by writing a word (double byte) to
  214. ; the video segment which is set in ES
  215.  
  216. clear_screen proc USES ax cx di es
  217.     mov     ax,VIDEO_SEG     ; put video segment in ES via AX
  218.     mov     es,ax         ; destination segment
  219.     mov     cx,32000         ; number of words in video segment
  220.     mov     ax,color_back_ground ; color to fill background
  221.     mov     di,0         ; offset in video segment advanced by STOSW
  222.     rep stosw             ; write the value in AX the number of times in CX
  223.     ret
  224.  
  225. clear_screen endp
  226.  
  227. ; -------------------------------------------------------------------
  228. ; "calc_start" calculates the upper left hand corner
  229. ; of the graphic image using row and column values of the graphic image.
  230. ; The row and column should be stored:    CX=column position, DX=row position.
  231. ; The offset is returned in the "start_pos" variable.
  232.  
  233. calc_start proc  USES AX BX CX DX
  234.     mov     ax,dx         ; row (dx) times 320 gives pixel position of row
  235.     mov     bx,320         ; load bx with pixels per row value
  236.     mul     bx             ; multiply (bx * ax) result in ax
  237.     add        ax,cx         ; add column to result to finish pixel positioning
  238.     mov     start_pos,ax     ; put pixel position in start_pos
  239.                  ; for use with draw_screen
  240.     ret
  241.  
  242. calc_start endp
  243.  
  244. ; -----------------------------------------
  245. ; "wait_key" uses DOS int 21h to wait for a key press.
  246.  
  247. wait_key proc
  248.     mov     ah,7         ; function number
  249.     int     21h          ; call DOS
  250.     ret
  251.  
  252. wait_key endp
  253. ; -----------------------------------------
  254.  
  255. ; *****************************************
  256. END
  257.