Author Topic: a few questions about ascii demos  (Read 12642 times)

0 Members and 1 Guest are viewing this topic.

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
a few questions about ascii demos
« on: February 01, 2008 »
hey folks,

ive never done ascii before and i cant get it right at all.

i tried to make a simple 80*50 bufferd window like so.

Code: [Select]
Dim shared As String BackBuffer( 80 * 50 )

WIDTH 80, 50

Declare Sub FlipAsciiBuffers()
Declare Sub ClearAsciiBuffers()

While Not Inkey$ = chr(27)
   
    For Y = 1 To 80 * 50
        BackBuffer( Y ) = "~"
    Next
   
    FlipAsciiBuffers()
    ClearAsciiBuffers()

Wend

Sub ClearAsciiBuffers()
   
    For Y = 1 To 80 * 50
        BackBuffer( Y ) = Chr( 219 )
    Next
   
End Sub

Sub FlipAsciiBuffers()
   
    Dim As String FrontBuffer
    Locate 1,1
   
    For Y = 1 to 80 * 50
        FrontBuffer += BackBuffer( Y )
    Next
   
    color 1,3
    Print FrontBuffer

End Sub

but there is a huge amount of tearing and the colors cant be set for individual cells so im wondering how other folks make ascii stuff.

i know in the windows api there is stuff like this CreateConsoleScreenBuffer but would this give a smooth animation and i still have no idea how to color individual cells any info would be much appreciated as im really curious how this stuff is done.
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: a few questions about ascii demos
« Reply #1 on: February 02, 2008 »
Yeah, under Windows you need to use the Console API otherwise you don't stand a chance.

Attached is the source for my ascii demo which sets that up.  It does some other cool things too - it can play a video using the multimedia APIs and colour match it to the limited set of ascii letters/colours I chose.

Jim
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: a few questions about ascii demos
« Reply #2 on: February 02, 2008 »
cool thanks very much jim k+,

ill have a play around and see what i come up with.
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: a few questions about ascii demos
« Reply #3 on: February 02, 2008 »
thanks very much again jim it all works great now im using your setup and blitting code   :)

Code: [Select]
#include "windows.bi"

Const ScreenWidth = 80
Const ScreenHeight = 50

Declare Sub FlipAsciiBuffers()
Declare Sub ClearAsciiBuffers()

Dim Shared As COORD origin = ( 0 , 0 )
Dim Shared As SMALL_RECT di = ( 0 , 0 , SCREENWIDTH - 1 , SCREENHEIGHT - 1 )
Dim Shared As HANDLE outp
Dim Shared As COORD Size = ( SCREENWIDTH , SCREENHEIGHT )
Dim Shared As CONSOLE_FONT_INFO fonti
Dim Shared As CHAR_INFO scr( SCREENWIDTH * SCREENHEIGHT)

outp = CreateConsoleScreenBuffer( GENERIC_WRITE Or GENERIC_READ , 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL)
SetConsoleActiveScreenBuffer( outp )
SetConsoleScreenBufferSize( outp, Size )

While Not Inkey$ = chr(27)
   
    For Y = 1 to 80 * 50
         scr(Y).Char.AsciiChar = 219
         scr(Y).Attributes = 1+(Rnd(1)*14)
    Next
   
    FlipAsciiBuffers()
    ClearAsciiBuffers()

Wend

Sub ClearAsciiBuffers()
   
    For Y = 1 To 80 * 50
         scr(Y).Char.AsciiChar = 219
         scr(Y).Attributes = 0
    Next
   
End Sub

Sub FlipAsciiBuffers()
    WriteConsoleOutput(outp, @scr(0), size, origin, @di)
End Sub
Challenge Trophies Won:

Offline p01

  • Atari ST
  • ***
  • Posts: 158
  • Karma: 51
    • View Profile
    • www.p01.org
Re: a few questions about ascii demos
« Reply #4 on: February 02, 2008 »
Check out libcaca.

For URYA, which I wrote in Turbo Pascal (yuk), I simply drew directly in the segment $b800 . Each character is stored in a WORD. The first BYTE for the color ( in the 4 LSB ) and background color ( in the 4 MSB) , the second BYTE contains the ASCII code of the character.

HTH

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: a few questions about ascii demos
« Reply #5 on: February 02, 2008 »
Check out libcaca.

For URYA, which I wrote in Turbo Pascal (yuk), I simply drew directly in the segment $b800 . Each character is stored in a WORD. The first BYTE for the color ( in the 4 LSB ) and background color ( in the 4 MSB) , the second BYTE contains the ASCII code of the character.

HTH

I never knew you'd made an ascii demo pO1, and 1996, hehe, 12 years ago doesn't time fly?

hey folks,

ive never done ascii before and i cant get it right at all.

but there is a huge amount of tearing and the colors cant be set for individual cells so im wondering how other folks make ascii stuff.

i know in the windows api there is stuff like this CreateConsoleScreenBuffer but would this give a smooth animation and i still have no idea how to color individual cells any info would be much appreciated as im really curious how this stuff is done.

You know, once you have your console window working properly, there are a few things you can do to make your ascii demo look really cool. Bearing in mind that most ascii demos released today are straight framebuffer - textscreen conversions (this is the easy route but maybe not the best looking), you could analysie the default font to establish a good range of character densities, ie. how many dots make up each letter, this will pay dividends later as in your frame buffer - text screen conversion you'll want to be able to give each cell "weight" according to what you converted there.

If you are going to release it into the demo scene you might want to use the default palette because some purists (not many these days) frown upon ascii demos that use thier own palettes.

here are some really cool textmode demos from tdmc

linky
Shockwave ^ Codigos
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: a few questions about ascii demos
« Reply #6 on: February 02, 2008 »
@pO1 thats very handy cheers mate!
i will take some time and look at all my possible options but that lib looks rather good.

@shockwave again some handy advice cheers mate!
i was on tmdc till about 4am last night going through all the demos and trying to get a feel for the art.

if i do ascii stuff it will be always in a console window only no double bufferd gfx mode.and when you say standerd pallette mode is that the 0 - 15 colors 0 = black 15 = white?

from what ive seen the code behind the demos isnt that complicated its getting the demos to look good that is the hard part, i think ill start of right at the begining and try to find out what i like the look of best.
Challenge Trophies Won:

Offline p01

  • Atari ST
  • ***
  • Posts: 158
  • Karma: 51
    • View Profile
    • www.p01.org
Re: a few questions about ascii demos
« Reply #7 on: February 02, 2008 »
You can have as many buffers as you want, in memory. It's not like you'll notice a chunk of 80x50x2 byte more or less.

Libcaca is usually provided in the TMDC. And AFAIK it works in 32 bits, then convert that to some ANSI characters with the standard EGA palette and blit to the standard output ( segment b800 )

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: a few questions about ascii demos
« Reply #8 on: February 02, 2008 »
yeah i noticed you can have more than one buffer set up and then its just a case of setting the one you wish to be visable. which could prove handy for a couple of things.

im going to try and steer clear of using any libs although some of the code in the libs looks very usfull so i might use bits out of them. ill need to experiment a bit but what ever i come up with ill post.
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: a few questions about ascii demos
« Reply #9 on: February 02, 2008 »
right ive had a spare half hour so here is my framework for the console window cleaned up a bit.

the reason im posting this is for anyone else to look at/use before i go and add some demo specific stuff.

Code: [Select]
#include "windows.bi"

Type AsciiWindow
   
    ScreenWidth As Integer
    ScreenHeight As Integer
   
    Origin As COORD
    Dimensions As SMALL_RECT
    CHwnd As HANDLE
    Size As COORD
    WndPtr As CHAR_INFO Ptr

End Type

Declare Sub FlipAsciiBuffers( Buffer As AsciiWindow Ptr )
Declare Sub ClearAsciiBuffers( Buffer As AsciiWindow Ptr )
Declare Sub KillAsciiWindow( AscWindow As AsciiWindow Ptr )
Declare Function SetUpAsciiWindow( ByVal X As Integer = 0 , ByVal Y As Integer = 0 , Byval Wdth As Integer = 80 , ByVal Hght As Integer = 50 ) As AsciiWindow Ptr
Declare Function AsRgb( ByVal FCol As Integer , ByVal BCol As Integer )

Dim Shared MyTextWnd As AsciiWindow Ptr

MyTextWnd = SetUpAsciiWindow( 0, 0, 80, 50 )

While Not Inkey$ = chr(27)

    For Y = 0 to 80 * 50
         If Y And 1 Then
            MyTextWnd->WndPtr[Y].Char.AsciiChar = cast( CHAR , 40 )
            MyTextWnd->WndPtr[Y].Attributes = AsRgb( 1 + ( rnd( 1 ) * 14 ) , 4  )
         Else
            MyTextWnd->WndPtr[Y].Char.AsciiChar = cast( CHAR , 219 )
            MyTextWnd->WndPtr[Y].Attributes = AsRgb( 1 + ( rnd( 1 ) * 14 ) , 1  )
         End If
    Next
   
    FlipAsciiBuffers( MyTextWnd )
    ClearAsciiBuffers( MyTextWnd )

Wend
KillAsciiWindow( MyTextWnd )


Sub ClearAsciiBuffers( Buffer As AsciiWindow Ptr )
   
    For Y = 1 To 80 * 50
         Buffer->WndPtr[Y].Char.AsciiChar = cast( CHAR , 219 )
         Buffer->WndPtr[Y].Attributes = 0
    Next
   
End Sub



Sub FlipAsciiBuffers( Buffer As AsciiWindow Ptr )
   
    WriteConsoleOutput( Buffer->CHwnd , Buffer->WndPtr , Buffer->Size , Buffer->Origin , @Buffer->Dimensions )

End Sub



Function AsRgb( ByVal FCol As Integer , ByVal BCol As Integer )

    Return FCol + ( BCol Shl 4 )

End Function



Function SetUpAsciiWindow( ByVal X As Integer = 0 ,ByVal Y As Integer = 0 , Byval Wdth As Integer = 80 , ByVal Hght As Integer = 50 ) As AsciiWindow Ptr
   
    Dim As AsciiWindow Ptr TmpWindow
   
    TmpWindow = CAllocate( SizeOf( AsciiWindow ) )
     
    TmpWindow->ScreenWidth = Wdth
    TmpWindow->ScreenHeight = Hght
   
    TmpWindow->WndPtr = CAllocate( TmpWindow->ScreenWidth * TmpWindow->ScreenHeight *  Sizeof( AsciiWindow ) )
   
    TmpWindow->Size.X = TmpWindow->ScreenWidth
    TmpWindow->Size.Y = TmpWindow->ScreenHeight
   
    TmpWindow->Origin.X = X
    TmpWindow->Origin.Y = Y
   
    TmpWindow->Dimensions.Left = 0
    TmpWindow->Dimensions.Top = 0
    TmpWindow->Dimensions.Right = TmpWindow->ScreenWidth - 1
    TmpWindow->Dimensions.Bottom = TmpWindow->ScreenHeight - 1
   
    TmpWindow->CHwnd = CreateConsoleScreenBuffer( GENERIC_WRITE Or GENERIC_READ , 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL)
    SetConsoleActiveScreenBuffer( TmpWindow->CHwnd )
    SetConsoleScreenBufferSize( TmpWindow->CHwnd, TmpWindow->Size )
    SetConsoleWindowInfo( TmpWindow->CHwnd, TRUE, @TmpWindow->Dimensions )
   
    Return TmpWindow
   
End Function



Sub KillAsciiWindow( AscWindow As AsciiWindow Ptr )
   
    If ( AscWindow ) Then
        If ( AscWindow->WndPtr ) Then
            Deallocate( AscWindow->WndPtr )
        End If
        Deallocate( AscWindow )
    End If
   
End Sub
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: a few questions about ascii demos
« Reply #10 on: February 02, 2008 »
First ascii framework we've had here in Freebasic I think Nino :)

That has to be worth some good karma! It will be great to see what you do with it now.

I tried making some ascii effects myself but they didn't open a proper console window like you, they were just drawn on a regular graphics screen.

Shockwave ^ Codigos
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: a few questions about ascii demos
« Reply #11 on: February 03, 2008 »
cheers shockwave.

yeah i saw some of your ascii stuff in the comp that was run, i thought it was really cool and if i manage anything like that ill be well happy.

im really enjoing tinkering so far though and if i come up with anything worth while ill post it up.
« Last Edit: February 03, 2008 by ninogenio »
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: a few questions about ascii demos
« Reply #12 on: February 12, 2008 »
here is a little update on my progress its just a hedra sphere and my font engine im struggling with the limited colors so any tips you guys could give me would be handy.

i need to know also how it runs on your comp as i had a lot of tearing at first but ive got it running smooth on my system by using system timers and clamping the frame rate at 59.1 but im curious if it will be similarily smooth on other comps.

Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1432
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: a few questions about ascii demos
« Reply #13 on: February 12, 2008 »
@ninogenio:
wow, very nice and amazing for a first ascii demo! *thumbs up*
i am still looking forward to see more of your ascii demos in the future!

PS:
Just one question... does the scene is something like an included animation or is it/there something realtime (3D cube) ? However, very very nice work! I really like it! *respect*
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: a few questions about ascii demos
« Reply #14 on: February 12, 2008 »
cheers vain!

its all realtime with 3d projection in a double buffered console window.

im glad you like it mate but tbh my colors are really crappy and thats what im working on now trying to make stuff look good with 16 colors.

ill post the source soon its all a bit of a mess atm and im working on alpha blending my hedra sphere.
Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: a few questions about ascii demos
« Reply #15 on: February 12, 2008 »
It works well and Im also impressed by the fact you got nice stuff displayed first time.
One thing to work on is that on my computer the ascii window opened with a scrollbar at the side, and I guess thats not what it should do. It means half the demo appeared to be missing from the bottom of the screen. I had to reszie the window by hand.

Taj
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: a few questions about ascii demos
« Reply #16 on: February 12, 2008 »
cheers taj,

that's strange that's one thing that should'nt happen i codded it to open the full 80*50 res. is it vista your on as i may be doing something that it doesn't like.
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: a few questions about ascii demos
« Reply #17 on: February 12, 2008 »
@nino:
Congratz, works very well. Opens here correctly on
Vista!
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: a few questions about ascii demos
« Reply #18 on: February 12, 2008 »
wonder why it opens windowed on taj's system?,

anywho cheers for trying it benny and im glad you like it too. this is just really a test to see if im on the right track with the refresh rate and my colors.

once i get my alpha blending going ill make something worth looking at.
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: a few questions about ascii demos
« Reply #19 on: February 12, 2008 »
Fabulous looking first ascii mate, welldone indeed.

Cheers and all the best,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won: