home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / BKISSSRC.ZIP / STRETCH / STRETCH.ASM < prev   
Encoding:
Assembly Source File  |  1994-02-13  |  14.3 KB  |  404 lines

  1. ideal
  2. locals
  3. jumps
  4. model huge
  5. stack 100h
  6. p386
  7.  
  8.  
  9. TextMode = 0
  10. LoopDemo = 0            ;loop infinitely?
  11. AngleStep = 5           ;amount to rotate image
  12. DebugKeys = 0           ;active debugging keys?
  13.  
  14. segment     MyCode
  15.             assume cs:MyCode, ds:MyData, es:VideoSeg, fs:CompiledTextSeg
  16. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  17. include     "drawstr.inc"
  18. include     "sincos.inc"
  19. FadeHandler = RefreshScreen
  20. include     "palette.inc"
  21. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  22. macro       WaitForRetrace
  23.             local @@ras1, @@ras2
  24.             mov dx,3dah
  25. @@ras1:     in al,dx
  26.             test al,8
  27.             jnz @@ras1
  28. @@ras2:     in al,dx
  29.             test al,8
  30.             jz @@ras2
  31. endm        WaitForRetrace
  32. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  33. proc        Start
  34.             ;set up all of the segments
  35.             cld
  36.             mov ax,MyData
  37.             mov ds,ax
  38.             mov ax,VideoSeg
  39.             mov es,ax
  40.             mov ax,CompiledTextSeg
  41.             mov fs,ax
  42.  
  43.             ;switch over to graphics mode
  44.             mov ax,0013h
  45.             int 10h
  46.  
  47.             ;load in the palette
  48.             mov si,offset CurrentPal
  49.             mov di,offset HeartPalette
  50.             call fade_to
  51.  
  52. @@MainLoop: call RefreshScreen
  53.             jc @@AllDone
  54.  
  55.             ;get stdio.  If something's been pressed, quit
  56.             mov ah,6
  57.             mov dl,0FFh
  58.             int 21h
  59.             jz @@MainLoop
  60.             if DebugKeys ne 0
  61.                 cmp al,'1'
  62.                 jb @@AllDone
  63.                 cmp al,'3'
  64.                 ja @@AllDone
  65.                 sub al,'0'
  66.                 xor ah,ah
  67.                 mov [Method],ax
  68.                 jmp @@MainLoop
  69.             endif
  70.  
  71. @@AllDone:  call fade_out
  72.  
  73.             ;change back to text mode and quit
  74.             if TextMode ne 0
  75.                 mov ax,0003h
  76.                 int 10h
  77.             endif
  78.             mov ax,4C00h
  79.             int 21h
  80. endp        Start
  81. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  82. proc        RefreshScreen
  83.             ;get some text on screen
  84.             cmp [TextDelay],0
  85.             jnz @@NoText
  86.             call MoreText
  87.             if LoopDemo eq 0
  88.                 jc @@AllDone
  89.             endif
  90. @@NoText:   dec [TextDelay]
  91.  
  92.             ;draw a frame
  93.             mov si,[ScalePtr]           ;\
  94.             shl si,1                    ; \
  95.             movsx ebx,[Sine+si]         ;  \
  96.             sal ebx,9                   ;   > SI = angle
  97.             mov si,[Angle]              ;  /  EBX = scaler (16.16 fixed point)
  98.             mov ax,[Method]             ; /
  99.             call DrawFrame              ;/
  100.             add [Angle],AngleStep       ;\ increment the angle
  101.             and [Angle],1023            ;/
  102.             inc [ScalePtr]              ;\ increment the scaler
  103.             and [ScalePtr],1023         ;/
  104.  
  105.             ;wait for a retrace to complete (for timing)
  106.             WaitForRetrace
  107.             clc
  108.  
  109. @@AllDone:  ret
  110. endp        RefreshScreen
  111. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  112. proc        MoreText
  113.             ;set default time before we return again
  114.             mov [TextDelay],120
  115.  
  116.             ;clear our text buffer
  117.             cmp [@@DontClear],0
  118.             jnz @@TextLoop
  119.             xor eax,eax
  120.             mov cx,(320*200)/4
  121.             xor di,di
  122. @@Wipe:     mov [dword fs:di],eax
  123.             add di,4
  124.             dec cx
  125.             jnz @@Wipe
  126.  
  127.             ;render the text
  128. @@TextLoop: mov si,[TextPtr]
  129.             cmp [word si],-1            ;\ have we reached end of text?
  130.             jz @@Restart                ;/    yes -- loop it again
  131.             cmp [word si],-2            ;\ have we reached end of this page?
  132.             jz @@PageDone               ;/    yes -- return
  133.             cmp [word si],-3            ;\ is it a 'wait until angle' command?
  134.             jz @@WaitAngle              ;/    yes -- handle it
  135.             cmp [word si],-4            ;\ is it a 'change method' command?
  136.             jz @@ChangeMethod           ;/    yes -- handle it
  137.             cmp [word si],-5            ;\ is it a 'set delay' command?
  138.             jz @@SetDelay               ;/    yes -- handle it
  139.             push (seg CompiledText) (offset CompiledText)
  140.             push [word si+2] [word si]  ;push the row and column
  141.             add si,4
  142.             push (seg ScrollText) si    ;push the pointer to the text
  143.             push (seg FontData) (offset FontData)
  144.             call _Draw_String
  145.             add sp,16
  146.             mov si,[TextPtr]
  147.             add si,5
  148. @@FindEnd:  lodsb                       ;\
  149.             or al,al                    ; > seek to the end of this row
  150.             jnz @@FindEnd               ;/
  151.             mov [TextPtr],si
  152.             jmp @@TextLoop              ;else do the next line
  153.  
  154. @@WaitAngle:mov [TextDelay],1
  155.             mov [@@DontClear],1
  156.             mov ax,[word si+2]
  157.             sub ax,[Angle]
  158.             cmp ax,0
  159.             jg @@WaitRet
  160.             cmp ax,-AngleStep
  161.             jle @@WaitRet
  162.             add [TextPtr],4
  163.             mov [@@DontClear],0
  164.             mov [TextDelay],120
  165.             jmp @@TextLoop
  166. @@WaitRet:  clc
  167.             ret
  168. @@DontClear db 0
  169.  
  170. @@ChangeMethod:
  171.             mov ax,[word si+2]
  172.             mov [Method],ax
  173.             add [TextPtr],4
  174.             jmp @@TextLoop
  175.  
  176. @@SetDelay: mov ax,[word si+2]
  177.             mov [TextDelay],ax
  178.             add [TextPtr],4
  179.             jmp @@TextLoop
  180.  
  181. @@PageDone: add [TextPtr],2
  182.             clc
  183.             ret
  184.  
  185. @@Restart:  if LoopDemo ne 0
  186.                 mov [TextPtr],offset ScrollText
  187.                 clc
  188.             else
  189.                 stc
  190.             endif
  191.             ret
  192. endp        MoreText
  193. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  194. ;           AX = stretch method (1 = none, 2 = full stretch, 3 = 45° stretch)
  195. ;           SI = angle (0 to 1023)
  196. ;           EBX = scale factor (16.16 fixed point)
  197. ;
  198. proc        DrawFrame
  199.             cmp ax,1
  200.             jz @@Normal
  201.             cmp ax,2
  202.             jz @@Full
  203.             cmp ax,3
  204.             jz @@45
  205.             ret
  206.  
  207. @@Normal:   shl si,1                    ;SI = current angle offset
  208.             mov ecx,10000h              ;
  209.             movsx eax,[Cosine+si]       ;\
  210.             sal eax,8                   ; \ calculate cos(SI) and convert to
  211.             imul ebx                    ;  >
  212.             idiv ecx                    ; / 16.16 fixed point format
  213.             mov [@@X_add],eax           ;/
  214.             movsx eax,[Sine+si]         ;\
  215.             sal eax,8                   ; \ calculate sin(SI) and convert to
  216.             imul ebx                    ;  >
  217.             idiv ecx                    ; / 16.16 fixed point format
  218.             mov [@@Y_add],eax           ;/
  219.             shr si,1                    ;\
  220.             add si,256                  ; \ rotate 90°
  221.             and si,1023                 ; /
  222.             shl si,1                    ;/
  223.             movsx eax,[Cosine+si]       ;\
  224.             sal eax,8                   ; \ calculate cos(SI) and convert to
  225.             imul ebx                    ;  >
  226.             idiv ecx                    ; / 16.16 fixed point format
  227.             mov [@@X_lineadd],eax       ;/
  228.             movsx eax,[Sine+si]         ;\
  229.             sal eax,8                   ; \ calculate sin(SI) and convert to
  230.             imul ebx                    ;  >
  231.             idiv ecx                    ; /  16.16 fixed point format
  232.             mov [@@Y_lineadd],eax       ;/
  233.             jmp @@Go                    ;start rendering!
  234. @@Full:     shl si,1                    ;SI = current angle offset
  235.             mov ecx,10000h              ;
  236.             movsx eax,[Cosine+si]       ;\
  237.             sal eax,8                   ; \
  238.             imul ebx                    ;  \ calculate cos(SI) and convert to
  239.             idiv ecx                    ;  / 16.16 fixed point format
  240.             mov [@@X_add],eax           ; /
  241.             mov [@@Y_lineadd],eax       ;/
  242.             movsx eax,[Sine+si]         ;\
  243.             sal eax,8                   ; \
  244.             imul ebx                    ;  \ calculate sin(SI) and convert to
  245.             idiv ecx                    ;  / 16.16 fixed point format
  246.             mov [@@Y_add],eax           ; /
  247.             mov [@@X_lineadd],eax       ;/
  248.             jmp @@Go                    ;start rendering!
  249. @@45:       shl si,1                    ;SI = current angle offset
  250.             mov ecx,10000h              ;
  251.             movsx eax,[Cosine+si]       ;\
  252.             sal eax,8                   ; \ calculate cos(SI) and convert to
  253.             imul ebx                    ;  >
  254.             idiv ecx                    ; / 16.16 fixed point format
  255.             mov [@@X_add],eax           ;/
  256.             movsx eax,[Sine+si]         ;\
  257.             sal eax,8                   ; \ calculate sin(SI) and convert to
  258.             imul ebx                    ;  >
  259.             idiv ecx                    ; / 16.16 fixed point format
  260.             mov [@@Y_add],eax           ;/
  261.             shr si,1                    ;\
  262.             add si,256                  ; \ rotate 90°
  263.             and si,1023                 ; /
  264.             shl si,1                    ;/
  265.             movsx eax,[Cosine+si]       ;\
  266.             sal eax,8                   ; \ calculate cos(SI) and convert to
  267.             imul ebx                    ;  >
  268.             idiv ecx                    ; / 16.16 fixed point format
  269.             mov [@@Y_lineadd],eax       ;/
  270.             movsx eax,[Sine+si]         ;\
  271.             sal eax,8                   ; \ calculate sin(SI) and convert to
  272.             imul ebx                    ;  >
  273.             idiv ecx                    ; /  16.16 fixed point format
  274.             mov [@@X_lineadd],eax       ;/
  275.  
  276. @@Go:       mov di,offset VideoBuffer   ;ES:DI ==> refresh buffer
  277.             mov [@@Col],0               ;\ set initial position in bitmap
  278.             mov [@@Row],0               ;/
  279.             mov cx,200                  ;CX = number of rows
  280. @@RowLoop:      push cx                     ;save CX
  281.                 mov cx,160                  ;CX = number of columns
  282.                 mov eax,[@@Col]             ;\ load position into registers
  283.                 mov ebx,[@@Row]             ;/
  284. @@ColLoop:          mov dx,[word fs:di]
  285.                     mov esi,ebx
  286.                     mov ebp,eax
  287.                     shr esi,16
  288.                     shr ebp,16
  289.                     and si,63
  290.                     and bp,63
  291.                     shl si,6
  292.                     add ebx,[@@Y_add]
  293.                     add eax,[@@X_add]
  294.                     add dl,[byte ds:si+bp+offset HeartImage]
  295.                     mov esi,ebx
  296.                     mov ebp,eax
  297.                     shr esi,16
  298.                     shr ebp,16
  299.                     and si,63
  300.                     and bp,63
  301.                     shl si,6
  302.                     add ebx,[@@Y_add]
  303.                     add dh,[byte ds:si+bp+offset HeartImage]
  304.                     add eax,[@@X_add]
  305.                     mov [word es:di],dx
  306.                     add di,2
  307.                 dec cx
  308.                 jnz @@ColLoop
  309.                 mov eax,[@@X_lineadd]       ;\
  310.                 add [@@Col],eax             ; \ update our variables
  311.                 mov eax,[@@Y_lineadd]       ; /
  312.                 add [@@Row],eax             ;/
  313.                 pop cx                      ;restore CX
  314.             dec cx                      ;\ loop until all rows done
  315.             jnz @@RowLoop               ;/
  316.             ret                         ;return
  317. @@X_add     dd 0        ;amount to add to Col after each pixel
  318. @@Y_add     dd 0        ;amount to add to Row after each pixel
  319. @@X_lineadd dd 0        ;amount to add to Col after each row
  320. @@Y_lineadd dd 0        ;amount to add to Row after each row
  321. @@Col       dd 0        ;current Column in bitmap (modulo 64)
  322. @@Row       dd 0        ;current Row in bitmap (modulo 64)
  323. endp        DrawFrame
  324. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  325. ends        MyCode
  326.  
  327. macro       DefineText X,Y,text
  328.             dw X,Y
  329.             db text,0
  330. endm        DefineText
  331.  
  332. macro       Delay time
  333.             dw -5,time
  334. endm        Delay
  335.  
  336. macro       ChangeMethod method
  337.             dw -4,method
  338. endm        ChangeMethod
  339.  
  340. macro       WaitUntilAngle theta
  341.             dw -3,(theta-1024/4) AND 1023
  342. endm        WaitUntilAngle
  343.  
  344. macro       EndOfPage
  345.             dw -2
  346. endm        EndOfPage
  347.  
  348. macro       EndOfText
  349.             dw -1
  350. endm        EndOfText
  351.  
  352. segment     MyData
  353. Angle       dw 0                    ;0 to 1023 (0 = 1024 = 360°)
  354. Scale       dd 0                    ;scale factor (16.16 fixed point)
  355. Method      dw 1                    ;rendering method
  356. ScalePtr    dw 0
  357. label       ScrollText byte
  358.             ;DefineText 10,50,"jeff rules!"     ;too objectionable :)
  359.             DefineText 61,100,"isn't this"
  360.             DefineText 41,150,"really cool?"
  361.             WaitUntilAngle 128
  362.             ChangeMethod 2
  363.             Delay 30
  364.             EndOfPage
  365.  
  366.             DefineText 36,40,"there's even"
  367.             DefineText 46,90,"transparent"
  368.             DefineText 96,140,"text!"
  369.             WaitUntilAngle 640
  370.             ChangeMethod 3
  371.             Delay 45
  372.             EndOfPage
  373.  
  374.             WaitUntilAngle 128
  375.             ChangeMethod 2
  376.             Delay 30
  377.             EndOfPage
  378.  
  379.             DefineText 30,53,"having fun?"
  380.             WaitUntilAngle 640
  381.             ChangeMethod 1
  382.             DefineText 45,90,"well you"
  383.             DefineText 30,135,"shouldn't be!"
  384.             Delay 80
  385.             EndOfPage
  386.             EndOfText
  387. TextDelay   dw 0
  388. TextPtr     dw offset ScrollText
  389. CurrentPal  db 256 dup(0,0,0)
  390. extrn       HeartImage:byte     ;this should be a 64x64x256 raw image
  391. extrn       HeartPalette:byte   ;this should be a 256 color triplet map
  392. extrn       FontData:byte       ;this should be a valid JLF font
  393. ends        MyData
  394.  
  395. segment     CompiledTextSeg
  396. label       CompiledText byte
  397. ends        CompiledTextSeg
  398.  
  399. segment     VideoSeg at 0A000h
  400. VideoBuffer db 320*200 dup (?)
  401. ends        VideoSeg
  402.  
  403.             end     Start
  404.