Dark Bit Factory & Gravity

PROGRAMMING => Freebasic => Topic started by: DrewPee on September 13, 2006

Title: Another C64 loading/depacking screen . . .
Post by: DrewPee on September 13, 2006
I noticed that somebody (a while ago now) had written something in Blitz that looked like a C64 loading/depacking screen . . .

so i decided to try and write one using FreeBasic and tinyptc, and i think ive done it - see what you think.

I guess it aint much use to anybody but at least i have the hang of tinyptc now!!! Thanks to all you other coders on here!

DrewPee
Title: Re: Another C64 loading/depacking screen . . .
Post by: Clyde on September 13, 2006
Nice work mate :)
Title: Re: Another C64 loading/depacking screen . . .
Post by: MrP on September 14, 2006
Not looked at this yet as im in work, but its good to see your getting the hang of tinyptc, keep up the good work
Title: Re: Another C64 loading/depacking screen . . .
Post by: DrewPee on September 14, 2006
Thanks guys - it took a while to stick in but I think I have it now!

DrewPee
Title: Re: Another C64 loading/depacking screen . . .
Post by: ninogenio on September 14, 2006
big thumbs up mate for taking the dive into tiny ptc as i know it can be a bit daunting at first good stuff  :)
Title: Re: Another C64 loading/depacking screen . . .
Post by: Shockwave on September 14, 2006
The trick with tinyptc is to remember that it soesn't matter how the colours get into the screen array. Actually I was a bit confused about the way you'd coded it, it seemed to run slowly, I remember the loading bars being a little bit faster so I took the liberty of optimising the code a little, though your cool technique stays intact :)

Code: [Select]
'
' C64 DEPACK SCREEN BY DREWPEE, SOME OPTIMISATIONS BY SHOCKWAVE.
'

option explicit
#define PTC_WIN
#Include Once "tinyptc.bi"
Const XRES=640
Const YRES=480
Dim Shared ScreenBuffer(XRES*YRES)
If(ptc_open("C64 unpacking by DrewPee",xres,yres)=0) Then
End -1
End If

dim as uinteger y,blk,rgbb,XW
dim as ubyte ranr,rang,ranb
DIM SHARED PP AS INTEGER PTR
do
    ranr=(INT(RND(1)*255)+1)
    rang=(INT(RND(1)*255)+1)
    ranb=(INT(RND(1)*255)+1)
    rgbb=rgb(ranr,rang,ranb)
    XW=xres   
    for y=0 to yres-1
        blk=rnd*(100)
        if blk>90 then
                ranr=(INT(RND(1)*255)+1)
                rang=(INT(RND(1)*255)+1)
                ranb=(INT(RND(1)*255)+1)
                rgbb=rgb(ranr,rang,ranb)
        end if
    if y<yres then
    PP = @ScreenBuffer(Y*XRES)
    asm
        mov eax,dword ptr[rgbb]
        mov ecx, [XW]
        mov edi, [PP]
        cld
        rep stosd
    end asm   
    end if
    next y
    ptc_update @screenbuffer(0)
LOOP UNTIL INKEY$<>""
ptc_close
end

Please note that it is not the asm that has made a huge difference here, it's the way your code was structured. I've broken it down for you;

GENERATE BLOCK SIZE AND COLOUR
NOTE THAT THIS IS WHERE YOUR OUTER LOOP STARTS!
do
    blk=(INT(RND(1)*20)+1)
    ranr=(INT(RND(1)*255)+1)
    rang=(INT(RND(1)*255)+1)
    ranb=(INT(RND(1)*255)+1)

DRAW **ONLY** THE BLOCK YOU CALCULATED ABOVE   

    for y=top to top+blk
         for x=0 to xres-1
            feedpixels(x,y,rgb(ranr,rang,ranb))
         next x
    next y

MOVE THE BLOCK OFFSET AND BOUNDS CHECK;       
    top=top+blk
    if top-blk>=564 then top=0
UPDATE THE SCREEN AFTER ONLY DRAWING ONE BLOCK!!!!!!!       
    ptc_update @screenbuffer(0)
LOOP UNTIL INKEY$<>""


In fact if you'd put the command Erase ScreenBuffer after the ptc update your problem would become clearer as you'd see that you only drew one raster block per update.
If that was the effect that you intended to do though I sincerely apologise for my meddling and I'll stfu :)
Title: Re: Another C64 loading/depacking screen . . .
Post by: DrewPee on September 14, 2006
Thanks for the optimisations Shockwave - the effect did need to be faster I guess.
I just need to do something with it now!!!!

Drew
Title: Re: Another C64 loading/depacking screen . . .
Post by: Shockwave on September 14, 2006
Yes indeed :) A demo would be nice mate.