home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / fakesrc / scrl.asm < prev    next >
Assembly Source File  |  1993-11-20  |  15KB  |  442 lines

  1. ;=============================================================================
  2. ; scrl.asm - Simple Horizontal Scroller.
  3. ;                                                   File created: 11/21/93
  4. ; Copyright (c) 1993, Carlos Hasan                 Last modified: 11/21/93
  5. ;
  6. ; Description:
  7. ;  Just a simple scroller in VGA ModeX and an external proportional
  8. ; font file in VLA chars format. Mainly based on VLA scrollers.
  9. ;
  10. ; Dependency:
  11. ;  Requires Turbo Assembler 3.2 or later to be assembled.
  12. ;  Dependant on the IBM PC 286 or better processor.
  13. ;=============================================================================
  14.  
  15.         ideal
  16.         model   small,pascal
  17.         jumps
  18.         p286
  19.  
  20.         dosseg
  21.         stack   1024
  22.     ends
  23.  
  24. IFDEF LinkFont
  25.         global  FontFAR:byte            ; SCRL.FNT linked file.
  26. ENDIF
  27.  
  28. ;=========================== VLA Font Header =================================
  29.  
  30. struc   FontHeader
  31.   Magic   db   "VGACH"                  ; Font Signature
  32.   First   db   ?                        ; First Char
  33.   Width   db   ?                        ; Font Width
  34.   Height  db   ?                        ; Font Height
  35.   Total   db   ?                        ; Number of Chars
  36. ends    FontHeader
  37.  
  38. ;=========================== Data Segment ====================================
  39.  
  40.         dataseg
  41.  
  42. SCREENWIDTH     equ  (2*320+8)          ; Logical Screen Width
  43.                                         ; Enough Space for Double-Window
  44.                                         ; and the working hidden area
  45. SCROLLROW       equ  180                ; Scroller Window Start Row.
  46.  
  47. WinOffs         dw   ?                  ; Window Offset
  48. CharOffs        dw   ?                  ; Char BitMap Offset
  49. MesgOffs        dw   ?                  ; Ascii-Message Offset
  50. FontHead        FontHeader ?            ; Font Header
  51. CharColumn      db   ?                  ; Cur Char Column
  52. FontFirst       db   ?                  ; Font First Char
  53. FontWidth       db   ?                  ; Font Max Width
  54. FontHeight      db   ?                  ; Font Height
  55. FontDataOfs     dw   ?                  ; Font Data Offset
  56. FontDataSeg     dw   ?                  ; Font Data Segment
  57. FontWidths      db   256 dup(?)         ; Font Width Table
  58. FontSize        dw   ?                  ; Font Char Size (Width*Height)
  59.  
  60. IFNDEF LinkFont
  61. FontFileName    db   "SCRL.FNT",0       ; Font File Name
  62. ENDIF
  63.  
  64. TheMessage      db   " ... Hello out there ... "
  65.         db   "                        "
  66.         db   " ... I am PELUSA from Chile ... "
  67.         db   "                        "
  68.         db   " ... Just a simple scroller... "
  69.         db   "                        "
  70.         db   " ... only useful to say that it's the FAKE demo ... "
  71.         db   "                        "
  72.         db   " ... you probably could have guessed that ... "
  73.         db   "                        "
  74.         db   " ... I hate scrollers because i have nothing to say..."
  75.         db   "                        "
  76.         db   " ... now enjoy the rest of this LAME thing ... "
  77.         db   "                                    ",0
  78.  
  79.         codeseg
  80.  
  81. ;-----------------------------------------------------------------------------
  82. ; SetModeX - Sets the VGA in Tweaked ModeX 320x400x256.
  83. ;-----------------------------------------------------------------------------
  84.  
  85. proc    SetModeX
  86.         mov     ax,0013h                ; Sets VGA linear 320x200x256
  87.         int     10h
  88.         mov     dx,3C4h                 ; Disable Chain-Four
  89.         mov     ax,0604h
  90.         out     dx,ax
  91.         mov     dx,3C4h                 ; Enable Write to All Four Planes
  92.         mov     ax,0F02h
  93.         out     dx,ax
  94.         mov     ax,0A000h               ; Clear Display Memory
  95.         mov     es,ax
  96.         xor     di,di
  97.         xor     ax,ax
  98.         mov     cx,8000h
  99.         cld
  100.         rep     stosw
  101.         mov     dx,3D4h                 ; Reprogram CRT Controller:
  102.         mov     ax,00014h               ; turn off dword mode
  103.         out     dx,ax
  104.         mov     ax,0e317h               ; turn on byte mode
  105.         out     dx,ax
  106.         mov     ax,00009h               ; cell height
  107.         out     dx,ax
  108.         mov     dx,3D4h                 ; Sets Logical Screen Width
  109.         mov     al,13h
  110.         mov     ah,SCREENWIDTH/8
  111.         out     dx,ax
  112.         ret
  113. endp    SetModeX
  114.  
  115. ;-----------------------------------------------------------------------------
  116. ; WaitVR - Waits the Next VGA Vertical Retrace Ending.
  117. ;-----------------------------------------------------------------------------
  118.  
  119. proc    WaitVR
  120.         mov     dx,3DAh
  121. WaitStartVR:
  122.         in      al,dx
  123.         test    al,8
  124.         je      WaitStartVR
  125. WaitEndVR:
  126.         in      al,dx
  127.         test    al,8
  128.         jne     WaitEndVR
  129.         ret
  130. endp    WaitVR
  131.  
  132. ;-----------------------------------------------------------------------------
  133. ; InitScroll - Initializes the Scroller Variables.
  134. ; Out:
  135. ;  CF=1 if function was not successful.
  136. ;  CF=0 if function was successful.
  137. ;-----------------------------------------------------------------------------
  138.  
  139. proc    InitScroll
  140.         mov     [WinOffs],0             ; Start Window Column
  141.         mov     [CharColumn],0          ; Start with a ZeroWidth Char
  142.         mov     [CharOffs],0            ; ZeroWidth Char BitMap Address
  143.         lea     ax,[TheMessage]         ; Sets Message Address
  144.         mov     [MesgOffs],ax
  145.         call    LoadFont                ; Load Font Data
  146.         ret
  147. endp    InitScroll
  148.  
  149. ;-----------------------------------------------------------------------------
  150. ; DoneScroll - Done Scroller Variables.
  151. ;-----------------------------------------------------------------------------
  152.  
  153. proc    DoneScroll
  154. IFNDEF LinkFont
  155.         mov     es,[FontDataSeg]        ; Free Font Data Segment
  156.         mov     ah,49h
  157.         int     21h
  158. ENDIF
  159.         ret
  160. endp    DoneScroll
  161.  
  162. ;-----------------------------------------------------------------------------
  163. ; LoadFont - Loads a New VGA Font.
  164. ; Out:
  165. ;  CF=1 if function was not successful.
  166. ;  CF=0 if function was successful.
  167. ;-----------------------------------------------------------------------------
  168.  
  169. proc    LoadFont
  170.  
  171. IFDEF LinkFont
  172.         mov     ax,SEG FontFAR          ; Load Font File Address
  173.         mov     es,ax
  174.         mov     [FontDataSeg],ax
  175.         mov     [FontDataOfs],Size FontHeader
  176.         mov     al,[es:FontHeader.First] ; Get Font First Char
  177.         mov     [FontFirst],al
  178.         mov     al,[es:FontHeader.Width] ; Get Font Data Size
  179.         mov     ah,[es:FontHeader.Height]
  180.         mov     [FontWidth],al
  181.         mov     [FontHeight],ah
  182.         mul     ah
  183.         mov     [FontSize],ax
  184.         mov     dl,[es:FontHeader.Total]
  185.         xor     dh,dh
  186.         mul     dx
  187.         add     ax,Size FontHeader      ; Copy Font Widths.
  188.         mov     si,ax
  189.         xor     di,di
  190.         mov     cl,[es:FontHeader.Total]
  191.         xor     ch,ch
  192. CopyWidths:
  193.         mov     al,[es:si]
  194.         mov     [FontWidths+di],al
  195.         inc     si
  196.         inc     di
  197.         loop    CopyWidths
  198. ELSE
  199.         mov     [FontDataSeg],0
  200.         mov     ax,3D00h                ; Open Font File
  201.         lea     dx,[FontFileName]
  202.         int     21h
  203.         jc      LoadFontExit
  204.         mov     bx,ax
  205.         mov     ah,3Fh                  ; Read Font Header
  206.         lea     dx,[FontHead]
  207.         mov     cx,Size FontHeader
  208.         int     21h
  209.         jc      LoadFontExit
  210.         mov     al,[FontHead.First]     ; Get Font First Char
  211.         mov     [FontFirst],al
  212.         mov     al,[FontHead.Width]     ; Get Font Data Size
  213.         mov     ah,[FontHead.Height]
  214.         mov     [FontWidth],al
  215.         mov     [FontHeight],ah
  216.         mul     ah
  217.         mov     [FontSize],ax
  218.         mov     dl,[FontHead.Total]
  219.         xor     dh,dh
  220.         mul     dx
  221.         push    ax
  222.         push    bx                      ; Alloc Space for Font Data
  223.         mov     bx,ax
  224.         shr     bx,4
  225.         inc     bx
  226.         mov     ah,48h
  227.         int     21h
  228.         pop     bx
  229.         pop     cx
  230.         jc      LoadFontExit
  231.         push    ds                      ; Read Font Data
  232.         mov     [FontDataSeg],ax
  233.         mov     [FontDataOfs],0
  234.         mov     ds,ax
  235.         xor     dx,dx
  236.         mov     ah,3Fh
  237.         int     21h
  238.         pop     ds
  239.         jc      LoadFontExit
  240.         lea     dx,[FontWidths]         ; Read Font Widths
  241.         mov     cl,[FontHead.Total]
  242.         xor     ch,ch
  243.         mov     ah,3Fh
  244.         int     21h
  245.         jc      LoadFontExit
  246.         mov     ah,3Eh                  ; Close Font File
  247.         int     21h
  248. ENDIF
  249. LoadFontExit:
  250.         ret
  251. endp    LoadFont
  252.  
  253. ;-----------------------------------------------------------------------------
  254. ; DrawScroll - Polls the Horizontal Scroller.
  255. ; Out:
  256. ;  CF=1 If no more scroll message.
  257. ;  CF=0 If more scroll message.
  258. ;-----------------------------------------------------------------------------
  259.  
  260. proc    DrawScroll
  261.         mov     bx,[WinOffs]            ; Loads Window Offset
  262.         add     bx,2
  263.         mov     dx,3D4h                 ; Sets VGA Start Address
  264.         mov     al,0Dh
  265.         mov     ah,bl
  266.         out     dx,ax
  267.         dec     al
  268.         mov     ah,bh
  269.         out     dx,ax
  270.         sub     [CharColumn],4          ; Advance 4 pixels
  271.         jg      NoNewChar               ; Need a New Char?
  272.         call    GetsNewChar             ; Yes, Draw a New Char
  273.         jc      DrawScrollExit
  274. NoNewChar:
  275.         mov     ax,0A000h               ; Loads Display Memory Segment
  276.         mov     es,ax
  277.         mov     bl,[FontWidth]          ; Loads Font Width and Height
  278.         mov     cl,[FontHeight]
  279.         xor     bh,bh
  280.         xor     ch,ch
  281.         mov     bp,SCREENWIDTH/4        ; Loads Logical Screen Width
  282.  
  283.         mov     dx,3C4h                 ; Enable Write to Plane 1
  284.         mov     ax,0102h
  285.         out     dx,ax
  286.         mov     si,[CharOffs]           ; Loads Char BitMap Address
  287.         mov     di,[WinOffs]            ; Loads VGA Window Dest Address
  288.         add     di,SCROLLROW*SCREENWIDTH/4
  289.         push    cx
  290.         push    ds
  291.         mov     ds,[FontDataSeg]
  292. DrawCharColumn1:
  293.         mov     al,[ds:si]
  294.         mov     [es:di],al
  295.         mov     [es:di+SCREENWIDTH/8],al
  296.         add     si,bx
  297.         add     di,bp
  298.         loop    DrawCharColumn1
  299.         pop     ds
  300.         pop     cx
  301.  
  302.         mov     dx,3C4h                 ; Enable Write to Plane 2
  303.         mov     ax,0202h
  304.         out     dx,ax
  305.         mov     si,[CharOffs]           ; Loads Char BitMap Address
  306.         mov     di,[WinOffs]            ; Loads VGA Window Dest Address
  307.         inc     si
  308.         add     di,SCROLLROW*SCREENWIDTH/4
  309.         push    cx
  310.         push    ds
  311.         mov     ds,[FontDataSeg]
  312. DrawCharColumn2:
  313.         mov     al,[ds:si]
  314.         mov     [es:di],al
  315.         mov     [es:di+SCREENWIDTH/8],al
  316.         add     si,bx
  317.         add     di,bp
  318.         loop    DrawCharColumn2
  319.         pop     ds
  320.         pop     cx
  321.  
  322.         mov     dx,3C4h                 ; Enable Write to Plane 3
  323.         mov     ax,0402h
  324.         out     dx,ax
  325.         mov     si,[CharOffs]           ; Loads Char BitMap Address
  326.         mov     di,[WinOffs]            ; Loads VGA Window Dest Address
  327.         add     si,2
  328.         add     di,SCROLLROW*SCREENWIDTH/4
  329.         push    cx
  330.         push    ds
  331.         mov     ds,[FontDataSeg]
  332. DrawCharColumn3:
  333.         mov     al,[ds:si]
  334.         mov     [es:di],al
  335.         mov     [es:di+SCREENWIDTH/8],al
  336.         add     si,bx
  337.         add     di,bp
  338.         loop    DrawCharColumn3
  339.         pop     ds
  340.         pop     cx
  341.  
  342.         mov     dx,3C4h                 ; Enable Write to Plane 4
  343.         mov     ax,0802h
  344.         out     dx,ax
  345.         mov     si,[CharOffs]           ; Loads Char BitMap Address
  346.         mov     di,[WinOffs]            ; Loads VGA Window Dest Address
  347.         add     si,3
  348.         add     di,SCROLLROW*SCREENWIDTH/4
  349.         push    cx
  350.         push    ds
  351.         mov     ds,[FontDataSeg]
  352. DrawCharColumn4:
  353.         mov     al,[ds:si]
  354.         mov     [es:di],al
  355.         mov     [es:di+SCREENWIDTH/8],al
  356.         add     si,bx
  357.         add     di,bp
  358.         loop    DrawCharColumn4
  359.         pop     ds
  360.         pop     cx
  361.  
  362.         inc     [WinOffs]               ; Advance Window by 4 pixels
  363.         cmp     [WinOffs],SCREENWIDTH/8
  364.         jb      DontWrapWindow
  365.         mov     [WinOffs],0
  366. DontWrapWindow:
  367.         add     [CharOffs],4            ; Advance Char Column by 4
  368.         clc
  369. DrawScrollExit:
  370.         ret
  371. endp    DrawScroll
  372.  
  373. ;-----------------------------------------------------------------------------
  374. ; GetsNewChar - Gets the next message Character.
  375. ; Out:
  376. ;  CF=1 If no more characters
  377. ;  CF=0 If more characters
  378. ;-----------------------------------------------------------------------------
  379.  
  380. proc    GetsNewChar
  381.         mov     si,[MesgOffs]           ; Loads the Message Offset
  382. GetCharLoop:
  383.         lodsb                           ; Gets the Character
  384.         test    al,al                   ; if End of Message ReStart
  385.         jne     DrawCharNow
  386.         stc
  387.         jmp     GetsNewCharExit
  388. DrawCharNow:
  389.         mov     [MesgOffs],si           ; Save Message Offset
  390.         sub     al,[FontFirst]          ; Compute the Char BitMap Address
  391.         xor     ah,ah
  392.         mov     bx,ax
  393.         mov     dx,[FontSize]
  394.         mul     dx
  395.         add     ax,[FontDataOfs]
  396.         mov     [CharOffs],ax
  397.         mov     al,[FontWidths+bx]      ; Set the Char Width
  398.         mov     [CharColumn],al
  399.         clc
  400. GetsNewCharExit:
  401.         ret
  402. endp    GetsNewChar
  403.  
  404.  
  405. ;-----------------------------------------------------------------------------
  406. ; Start - Start the Demostration. Called from DOS.
  407. ;-----------------------------------------------------------------------------
  408.  
  409. proc    Start
  410.         mov     ax,@Data                ; Sets Data Segment.
  411.         mov     ds,ax
  412.         mov     bx,sp                   ; Shrink Program Memory Block.
  413.         shr     bx,4
  414.         inc     bx
  415.         mov     ax,ss
  416.         mov     dx,es
  417.         sub     ax,dx
  418.         add     bx,ax
  419.         mov     ah,4Ah
  420.         int     21h
  421.         call    SetModeX                ; Sets VGA ModeX.
  422.         call    InitScroll              ; Init Scroller.
  423.         jc      DemoExit
  424.         cld
  425. DemoLoop:
  426.         call    WaitVR                  ; Waits Vertical Retrace.
  427.         call    DrawScroll              ; Draw the Scroller.
  428.         jc      DemoBreak
  429.         mov     ah,1                    ; Any Key Pressed?
  430.         int     16h                     ; No, Loop.
  431.         je      DemoLoop
  432. DemoBreak:
  433.         call    DoneScroll              ; Done Scroller.
  434. DemoExit:
  435.         mov     ax,0003h                ; Set Text Mode.
  436.         int     10h
  437.         mov     ax,4C00h                ; Exit to DOS.
  438.         int     21h
  439. endp    Start
  440.  
  441.         end     Start
  442.