Advertisement
Mysoft

Untitled

Jan 8th, 2016
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "windows.bi"
  2. #include "fbgfx.bi"
  3. #include "crt.bi"
  4.  
  5. #include "win\ddraw.bi"
  6. dim shared as LPDIRECTDRAW DD7
  7.  
  8. extern fbCTX alias "__fb_ctx" as ulong
  9.  
  10. dim shared as handle hOldScreen,pMiniBuff
  11. dim shared as string sMyTitle
  12. sMyTitle = "Mysoft Console"
  13.  
  14. #define CharColor(_CH, _CF, _CB) clng(((_CF and 15) shl 16) or ((_CB and 15) shl 20)) or (cshort(_CH))
  15.  
  16. sub MsgBox( sMsg as string , iMode as integer = MB_ICONERROR)
  17.   MessageBox( null , sMsg , sMyTitle , iMode or MB_TASKMODAL )
  18. end sub
  19. function Console_Create(iWidth as integer = 80, iHeight as integer = 25) as handle
  20.  
  21.   if iWidth <= 8 or iHeight <= 4 then
  22.     MsgBox("ConsoleCreate: Bad console size selected")
  23.     return null
  24.   end if
  25.    
  26.   width iWidth,iHeight
  27.    
  28.   hOldScreen = GetStdHandle( STD_OUTPUT_HANDLE )
  29.   var hCon = hOldScreen
  30.  
  31.   if SetConsoleActiveScreenBuffer( hCon ) = false then
  32.     MsgBox("ConsoleCreate: Failed to SetActiveScreenBuffer")
  33.     CloseHandle(hCon): return null
  34.   end if
  35.  
  36.   var pTemp = cast(any ptr,@fbCTX)
  37.   var pOldCtx = allocate(4096)
  38.   memcpy( pOldCtx , pTemp , 4096 )
  39.   screenres iWidth,iHeight,32,,fb.gfx_null
  40.   memcpy( pTemp , pOldCtx , 4096 )
  41.   deallocate(pOldCtx)  
  42.  
  43.   return hCon
  44.  
  45. end function
  46. function Console_ImageCreate( iWidth as integer , iHeight as integer ) as fb.image ptr
  47.  
  48.   if iWidth <= 1 or iHeight <= 1 then
  49.     MsgBox("Console_ImageCreate: Bad console size selected")
  50.     return null
  51.   end if
  52.    
  53.   dim as fb.image ptr pImg = callocate( iWidth*iHeight*4 + sizeof(fb.image) )
  54.   if pImg = null then
  55.     MsgBox("Console_ImageCreate: Failed to create image (no memory?)")
  56.     return null
  57.   end if
  58.  
  59.   pImg->Type = 7
  60.   pImg->Width = iWidth: pImg->Height = iHeight
  61.   pImg->Bpp = 4: pImg->Pitch = iWidth*pImg->Bpp
  62.  
  63.   return pImg
  64. end function
  65. sub Console_ImageDestroy( pImage as fb.image ptr )
  66.   if pImage = 0 orelse IsBadWritePtr( pImage , sizeof(fb.image) ) orelse pImage->Type<>7 then
  67.     MsgBox("Console_ImageDestroy: Bad Image handle.")
  68.     exit sub
  69.   end if
  70. end sub
  71. sub Console_Update()
  72.   var iXY = width(), ConWid = LoWord(iXY), ConHei = HiWord(iXY)
  73.   WriteConsoleOutput( hOldScreen, cptr( CHAR_INFO ptr , screenptr ) , _
  74.   type(ConWid,ConHei) , type(0,0) , @type<SMALL_RECT>(0,0,ConWid-1,ConHei-1) )
  75. end sub
  76. sub Console_SyncedUpdate()  
  77.    
  78.   do
  79.     if DD7 = INVALID_HANDLE_VALUE then
  80.       static as double TMR
  81.       var dwOldPri = GetThreadPriority( GetCurrentThread() )
  82.       SetThreadPriority(GetCurrentThread() , THREAD_PRIORITY_TIME_CRITICAL )
  83.       SwitchToThread()      
  84.       Console_Update()
  85.       if abs(timer-TMR) > 1/2 then TMR = timer
  86.       while (timer-TMR) < 1/60
  87.         SleepEx 1,1
  88.       wend
  89.       TMR += 1/60      
  90.       SetThreadPriority(GetCurrentThread() , dwOldPri )
  91.       SwitchToThread()
  92.       exit sub
  93.     end if      
  94.     if DD7 = null then
  95.       if DirectDrawCreate(cast(any ptr,DDCREATE_HARDWAREONLY),@DD7,null) <> DD_OK then
  96.         DD7 = cast(any ptr,INVALID_HANDLE_VALUE)
  97.         continue do
  98.       end if
  99.     end if
  100.     exit do
  101.   loop
  102.  
  103.  
  104.   var dwOldPri = GetThreadPriority( GetCurrentThread() )
  105.   SetThreadPriority(GetCurrentThread() , THREAD_PRIORITY_TIME_CRITICAL )
  106.   SwitchToThread()
  107.  
  108.   var iXY = width(), ConWid = LoWord(iXY), ConHei = HiWord(iXY)
  109.   var hConWnd = GetConsoleWindow(), iCellHei = 0
  110.   dim RcDesk as rect, RcScr as rect, tPt as point, iScan as integer
  111.   GetWindowRect( GetDesktopWindow(), @RcDesk )
  112.   GetClientRect( hConWnd, @RcScr )
  113.  
  114.   do
  115.     DD7->lpVtbl->GetScanLine(DD7,@iScan)    
  116.     if iScan > (RcDesk.bottom shr 1) then exit do
  117.     SleepEx(1,1)
  118.   loop
  119.  
  120.   var hStart = cptr( CHAR_INFO ptr , screenptr ), iStart = 0
  121.   tPt = type(0,(RcDesk.bottom shr 1)): iCellHei = RcScr.Bottom\ConHei
  122.   if ScreenToClient( hConWnd , @tPt ) = 0 then exit sub
  123.   if cshort(tPt.y) >= 0 and cshort(tPt.y) < RcDesk.Bottom then
  124.     iStart = (cshort(tPt.y)\iCellHei)+1
  125.     WriteConsoleOutput( hOldScreen, hStart , type(ConWid,iStart) , _
  126.     type(0,0) , @type<SMALL_RECT>(0,0,ConWid-1,iStart-1) )    
  127.     hStart += iStart*ConWid
  128.   end if
  129.  
  130.   do
  131.     DD7->lpVtbl->GetScanLine(DD7,@iScan)    
  132.     if iScan <= (RcDesk.bottom shr 1) then exit do
  133.     SleepEx(1,1)
  134.   loop
  135.  
  136.   if iStart < RcDesk.Bottom then
  137.     var iHeight = ConHei-iStart
  138.     WriteConsoleOutput( hOldScreen, hStart , type(ConWid,iHeight) , _
  139.     type(0,0) , @type<SMALL_RECT>(0,iStart,ConWid-1,iStart+iHeight-1) )
  140.   end if
  141.    
  142.   SetThreadPriority(GetCurrentThread() , dwOldPri )
  143.   SwitchToThread()
  144.    
  145. end sub
  146.  
  147. const ConWid = 80, ConHei = 50
  148. const CenX = ConWid\2, CenY = ConHei\2
  149. const PI = atn(1)/(ConWid/4)
  150.  
  151. var hConsole = Console_Create(ConWid,ConHei)
  152. 'var fbBuff = Console_ImageCreate(ConWid,ConHei)
  153.  
  154. do
  155.  
  156.   static as integer iBase : iBase += 1
  157.  
  158.   select case ((iBase shr 8) and 3)
  159.   case 0
  160.     for CNT as integer = ConWid to 0 step -1
  161.       circle(CenX,CenY),CNT,CharColor(177,CNT+iBase,((CNT+iBase) shr 4)),,,.66,f  
  162.     next CNT
  163.   case 1
  164.     for CNT as integer = ConWid to 0 step -1      
  165.       var pYM = CenY-CNT, pYP = CenY+CNT,pXM = CenX-CNT, pXP = CenX+CNT
  166.       line(pXM,CenY)-(CenX,pYM),CharColor(177,CNT+iBase,((CNT+iBase) shr 4))
  167.       line -(pXP,CenY),CharColor(177,CNT+iBase,((CNT+iBase) shr 4))
  168.       line -(CenX,pYP),CharColor(177,CNT+iBase,((CNT+iBase) shr 4))
  169.       line -(pXM,CenY),CharColor(177,CNT+iBase,((CNT+iBase) shr 4))      
  170.     next CNT
  171.   case 2
  172.     for CNT as integer = ConHei to 0 step -1
  173.       line(CenX-CNT,CenY-CNT*.66)-(CenX+CNT,CenY+CNT*.66),CharColor(177,CNT+iBase,((CNT+iBase) shr 4)),b      
  174.     next CNT  
  175.   case 3
  176.     for CNT as integer = ConWid to 0 step -1
  177.       line(CNT,0)-(ConWid-CNT,ConHei),CharColor(177,CNT+iBase,((CNT+iBase) shr 4))
  178.       line(ConWid,CNT)-(0,ConHei-CNT),CharColor(177,CNT+iBase,((CNT+iBase) shr 4))      
  179.     next CNT
  180.   end select
  181.  
  182.   var iOX = int(sin(iBase*PI)*(CenX-14))
  183.   var iOY = cint(sin(iBase*PI+timer)*(CenY-3))
  184.   for iY as integer = -1 to 1
  185.     for iX as integer = -1 to 1
  186.       draw string (CenX-14+iOX+iX,CenY-3+iOY+iY),"Hi!!",CharColor( asc(" ") , 0 , 0 )
  187.     next iX
  188.   next iY
  189.   draw string (CenX-14+iOX,CenY-3+iOY),"Hi!!",CharColor( iBase , 15 , 0 )  
  190.  
  191.   Console_SyncedUpdate()
  192.  
  193. loop until len(inkey$)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement