Page 1 of 1

commodore 64 loading screen

Posted: Sat Nov 23, 2013 7:28 pm
by rootuid
I have a function written in a different language (BlitzMax) which emulates the Commodore 64 load screen. See video here
http://www.youtube.com/watch?v=9GqXXLSfT7g

This is the legacy code:

Code: Select all

Function C64Loading()
	Local y=0,h
	Repeat
		h=Rand(5,60)
		SetColor Rand(255),Rand(255),Rand(255)
		DrawRect 0,y,GraphicsWidth(),h
		y:+h
	Until y>=GraphicsHeight()
End Function
I'm trying to do this in purebasic but am stuck. This is what I have.

Code: Select all

  y=0
  height=0
  	Repeat
  		height=Random(5,60)
              Color=RGB(Random(255),Random(255),Random(255))  
             Box(0,y,640,Height,Color)
  		y:+height
  	Until y>=GraphicsHeight()Random


How do I emulate the drawRect() in purepasic? Anyone done this already by chance?

Thanks.

Re: commodore 64 loading screen

Posted: Sat Nov 23, 2013 10:16 pm
by Bisonte
can you tell us the original syntax of this drawrect ? It's look like the Box(x, y, Width, Height, Color) function...

Re: commodore 64 loading screen

Posted: Sat Nov 23, 2013 10:25 pm
by rootuid
That's it petty much.

Re: commodore 64 loading screen

Posted: Sat Nov 23, 2013 10:27 pm
by Demivec
Just because I was little curious, here's one I worked up for you:

Code: Select all

InitSprite()
InitKeyboard()

If ExamineScreenModes() = 0
  MessageRequester("Error", "Screen is unavailable")
  End
EndIf

sw = 5000 ;arbitrary high number

;looks for the smallest screen that meets our needs (could be improved to look for the best apsect ratio)
While NextScreenMode()
  If ScreenModeDepth() = 32 And ScreenModeWidth() >=320 And ScreenModeWidth() <= sw
    sw = ScreenModeWidth()
    sh = ScreenModeHeight()
  EndIf
Wend

If sw = 5000 Or sh = 0
  MessageRequester("Error", "A suitable screen size is not available")
  End
EndIf

sf = sw / 320 ;scale factor

OpenScreen(sw, sh, 32, "C64 load screen", #PB_Screen_WaitSynchronization)
SetFrameRate(30)

quit = 0
Repeat
   ;Comment out this StartDrawing()/StopDrawing area and uncomment the following one for a messier version
   StartDrawing(ScreenOutput())
     y = 0
     h = 0
     Repeat
       h=Random(60, 5) * sf ;this gives a number between 5 and 60 that is then scaled
       Box(0, y, OutputWidth(), h, RGB(Random(255),Random(255),Random(255)))
       y + h
     Until y >= OutputHeight()
   StopDrawing()
  
;;This alternate method is a little messier and more realistic
;  StartDrawing(ScreenOutput())
;    y = 0
;    h = 0
;    c = RGB(Random(255),Random(255),Random(255))
;    Repeat
;      h = Random(25, 5) * sf ;this gives a number between 5 and 60 that is then scaled
;      Box(0, y, OutputWidth(), h, c)
;      y + h
;      x = Random(40) * 8 * sf
;      LineXY(0, y - 1, x - 1, y - 1, c)
;      c = RGB(Random(255),Random(255),Random(255))
;      LineXY(x, y - 1, OutputWidth(), y - 1, c)
;    Until y >= OutputHeight()
;  StopDrawing()
    
  
  FlipBuffers()

  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_Escape)
    quit = 1
  EndIf
Until quit = 1
Oh yea, hit Escape to exit the demo. :)


Here's a version of the code using the color palette that oreopa provided with his code sample later in this thread.

Code: Select all

DataSection
  ColorTable: ;pepto palette (attributed to oreopa)
  Data.i $000000, $FFFFFF, $2B3768, $B2A470, $863D6F, $438D58, $792835, $6FC7B8
  Data.i $254F6F, $003943, $59679A, $444444, $6C6C6C, $84D29A, $B55E6C, $959595
EndDataSection

Structure integer_array
  i.i[0]
EndStructure


Global *a_PAL.integer_array = ?ColorTable


InitSprite()
InitKeyboard()

If ExamineScreenModes() = 0
  MessageRequester("Error", "Screen is unavailable")
  End
EndIf

sw = 5000 ;arbitrary high number

;looks for the smallest screen that meets our needs (could be improved to look for the best apsect ratio)
While NextScreenMode()
  If ScreenModeDepth() = 32 And ScreenModeWidth() >=320 And ScreenModeWidth() <= sw
    sw = ScreenModeWidth()
    sh = ScreenModeHeight()
  EndIf
Wend

If sw = 5000 Or sh = 0
  MessageRequester("Error", "A suitable screen size is not available")
  End
EndIf

sf = sw / 320 ;scale factor

OpenScreen(sw, sh, 32, "C64 load screen", #PB_Screen_WaitSynchronization)
SetFrameRate(30)

quit = 0
Repeat
 ;This alternate method is a little messier and more realistic
 StartDrawing(ScreenOutput())
   y = 0
   h = 0
   c = *a_PAL\i[Random(15)] 
   Repeat
     h = Random(25, 5) * sf ;this gives a number between 5 and 60 that is then scaled
     Box(0, y, OutputWidth(), h, c)
     y + h
     x = Random(40) * 8 * sf
     LineXY(0, y - 1, x - 1, y - 1, c)
     c = *a_PAL\i[Random(15)] 
     LineXY(x, y - 1, OutputWidth(), y - 1, c)
   Until y >= OutputHeight()
 StopDrawing()
    
  
  FlipBuffers()

  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_Escape)
    quit = 1
  EndIf
Until quit = 1
@Edit: added second code sample using a select palette of colors instead of a completely random shade.

Re: commodore 64 loading screen

Posted: Sat Nov 23, 2013 10:30 pm
by rootuid
Thanks exactly it Demivec, many thanks.

Re: commodore 64 loading screen

Posted: Sat Nov 23, 2013 10:35 pm
by Demivec
rootuid wrote:Thanks exactly it Demivec, many thanks.
Your welcome.

Welcome also to the PureBasic Forums.

Re: commodore 64 loading screen

Posted: Sat Nov 23, 2013 11:47 pm
by em_uk
Hi,

You may want to take a look a Jase's work :

Taken from the wonderful DBFInteractive forum.

http://www.dbfinteractive.com/forum/ind ... 8#msg70908

Code: Select all

;***************************************************************
;*                                                             *
;*                 Amiga Depacking Effect                      *
;*                                                             *
;*                  by Jace / ST Knights                       *
;*                                                             *
;*                     29 / 07 / 2011                          *
;*                                                             *
;*   use  : depackRemake(<effect>,<duration in second>)        *
;*                                                             *
;*          Effect 1 is using direct buffer writing, so use 2  *
;*          for boxes (and slowest) effect                     *
;***************************************************************

Procedure depackRemake(version,duree)
  Protected x_res,y_res,depth,base,y,x,i,j,xold,timeDepack,coul.q,oldcoul.q
  #vsize = 10
  StartDrawing (ScreenOutput())
  *ecran = DrawingBuffer()
  ligne = DrawingBufferPitch() 
  x_res = OutputWidth()
  y_res = OutputHeight()
  depth = OutputDepth()
  StopDrawing()
  If depth <>32 
    ProcedureReturn
  EndIf
  endTime = ElapsedMilliseconds() + duree * 1000
  Repeat
    base = 0
    y = 0
    xold = 0
    Select version
      Case 1
        Repeat
          h = 1+Random(#vsize) : x = Random(x_res/2) : coul = ((Random(32)*8) & $ff) + (((Random(32)*8) & $ff)<<8 ) + (((Random(32)*8) & $ff)<<16 ) : coul =  coul <<32 + coul
          For j = 0 To h-1
            For i=0 To ligne/8-1
              PokeQ(*ecran+base+i*4*2,coul) : PokeQ(*ecran+base+ligne+i*4*2,coul) 
            Next
            If xold<>0 And j = 0
              For i = 0 To xold-1
                PokeQ(*ecran+base+i*4*2,oldcoul) : PokeQ(*ecran+base+ligne+i*4*2,oldcoul)
              Next
            EndIf
            base = base + ligne*2 : y = y +1
          Next
          xold = x : oldcoul = coul
        Until y > (y_res / 2)-(#vsize+1)
        coul = ((Random(255)& $ff)<<8 ) + ((Random(255)& $ff)<<16 ) + ((Random(255)& $ff)<<24 ) : coul = coul <<32 + coul
        For j = 0 To ((y_res/2)-y)-1
          For i=0 To ligne/8-1
            PokeQ(*ecran+base+i*4*2,coul) : PokeQ(*ecran+base+ligne+i*4*2,coul)
          Next
          If xold<>0 And j = 0
            For i = 0 To xold-1
              PokeQ(*ecran+base+i*4*2,oldcoul) : PokeQ(*ecran+base+ligne+i*4*2,oldcoul)
            Next
          EndIf
          base = base + ligne*2
        Next
        
      Case 2 ;box display of the 1rst model, for "academical" coders!
        Repeat
          h = 1+Random(#vsize) : x = Random(x_res-1) : coul = RGB(Random(32)*8,Random(32)*8,Random(32)*8) ; use of 32 levels for Amiga and Atari like palette
          StartDrawing(ScreenOutput()) : Box(0,y,x_res,h,coul) :  : StopDrawing()
          If xold<>0 
            StartDrawing(ScreenOutput()) : Box(0,y,xold,2,oldcoul) : StopDrawing()
          EndIf
          xold = x : oldcoul = coul : y = y + h
        Until y > y_res
        
      Case 3 ; other version of depack..
        ClearScreen(RGB(255,255,255))
        Repeat
          h = 1+Random(5) : x = Random(x_res-10)
          StartDrawing(ScreenOutput()) : Line(x,y+h,10,1,0) : Line(x,y+h+1,10,1,0) : StopDrawing()
          y = y + h
        Until y > y_res-10
    EndSelect
    FlipBuffers()
    ExamineKeyboard()
  Until KeyboardPushed (#PB_Key_Escape) Or ElapsedMilliseconds() > endTime              
 
EndProcedure

InitSprite() : InitKeyboard() 

If OpenWindow(0,0,0,800,600, "Depacking Effect",#PB_Window_BorderLess | #PB_Window_ScreenCentered   ) 
  If OpenWindowedScreen(WindowID(0), 0, 0,  800 , 600,false,0,0,#PB_Screen_SmartSynchronization) =0    
    MessageRequester("Error", " I can't open the window", 0)       
    End                                                    
  EndIf
Else
  MessageRequester("Error", " I can't create the window", 0)       
EndIf

depackRemake(1,5) ; <effect>,<duration>

CloseScreen()

End

Re: commodore 64 loading screen

Posted: Sat Nov 23, 2013 11:51 pm
by rootuid
Thanks for that. I tried that but all I get is a blank window.

Re: commodore 64 loading screen

Posted: Tue May 13, 2014 3:01 pm
by Teddy Rogers
I know this topic is a bit old but I thought I'd share this code that I posted in another forum, for a similar effect...

Code: Select all

If InitSprite()
  If OpenWindow(0, 0, 0, 820, 620, "Old School Decrunch Effect...", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
    If OpenWindowedScreen(WindowID(0), 10, 10, 800, 600, #True, 10, 10, #PB_Screen_NoSynchronization) ; x, y position, width, height, autostretch
      If CreateSprite(0, 800, 600) ; sprite, width, height
        
        Repeat
          MyEvent = WindowEvent()
            
          If StartDrawing(SpriteOutput(0))
            Box(0, Random(600), 800, 10, RGB((Random(255)), (Random(255)), (Random(255)))) ; Entire field x, y radius, width, height, colour
            StopDrawing()
          EndIf
          
          FlipBuffers() 
          DisplaySprite(0, 0, Random(600))
        
        Until MyEvent = #PB_Event_CloseWindow
        
      EndIf
    EndIf
  EndIf
EndIf
Ted.

Re: commodore 64 loading screen

Posted: Tue May 13, 2014 4:58 pm
by majikeyric
C64 rulez! :mrgreen:

Re: commodore 64 loading screen

Posted: Tue May 13, 2014 7:22 pm
by Danilo
Teddy Rogers wrote:I know this topic is a bit old but I thought I'd share this code that I posted in another forum, for a similar effect...
Slightly modified, just for fun (original here):

Code: Select all

If InitSprite()
    If OpenWindow(0, 0, 0, 820, 620, "Old School Decrunch Effect...", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
        If OpenWindowedScreen(WindowID(0), 10, 10, 800, 600, #True, 10, 10, #PB_Screen_NoSynchronization) ; x, y position, width, height, autostretch
            If CreateSprite(1,ScreenWidth(),256*2)
                If StartDrawing(SpriteOutput(1))
                    For y = 0 To OutputHeight()-2 Step 2
                        Box(0,y,OutputWidth(),2,RGB(Random($FF),Random($FF),Random($FF)))
                    Next y
                    StopDrawing()
                EndIf
                
                Repeat
                    Repeat
                        MyEvent = WindowEvent()
                        If MyEvent = #PB_Event_CloseWindow
                            Quit = #True
                            Break
                        EndIf
                    Until MyEvent = 0
                    
                    FlipBuffers()
                    If IsScreenActive()
                        ClearScreen(0)
                        
                        For a = 0 To ScreenHeight()-1 Step 4
                            x=0
                            While x<ScreenWidth()
                                length = Random(ScreenWidth()/8)
                                ClipSprite(1,0,Random(256)*2,length,2)
                                DisplaySprite(1,x,a)
                                x+length
                            Wend
                        Next a
                        StopDrawing()
                        Delay(Random(100))
                        
                    EndIf
                Until Quit = #True
            EndIf
        EndIf
    EndIf
EndIf
:)

Re: commodore 64 loading screen

Posted: Wed May 14, 2014 12:36 pm
by coco2
I Googled but didn't find the answer to my question... did the C64 and Amiga decompress using video RAM because it was faster than the regular RAM? Why did they do it this way?

Re: commodore 64 loading screen

Posted: Wed May 14, 2014 7:14 pm
by Danilo
coco2 wrote:I Googled but didn't find the answer to my question... did the C64 and Amiga decompress using video RAM because it was faster than the regular RAM? Why did they do it this way?
You should find some answers in this thread:
- Why raster bars for a loading screen?
Fröhn wrote:It's just the most simple way to show that the loader is still working. One extra asm opcode.
adric22 wrote:Nobody seemed to mention the fact that by disabling the video output, extra CPU cycles became available since they weren't needed for bad lines.
And since the screen was off anyway, the easiest way to give the user some feedback was with raster lines.
Some loaders/decompressors also used video and color ram, just because there was not much memory available (C64).
But this resulted usually in random strange characters and colors displayed on screen. Video and color RAM were just
parts of the whole $FFFF memory map.

- RAM under ROM - A Brief Look Into C64 Memory
- Commodore 64 memory map
- C64 Wiki - Memory Map

- C64 Programmer's Reference Guide - 03 - Programming Graphics.pdf (Commodore Manuals)

- An Introduction to Programming C-64 Demos
- C=Hacking
- C64 technical details

Re: commodore 64 loading screen

Posted: Wed May 14, 2014 11:09 pm
by coco2
Thanks for that information, I always wondered about that.

Re: commodore 64 loading screen

Posted: Sat May 17, 2014 4:35 pm
by oreopa

Code: Select all

Global Dim a_PAL(15) ; pepto palette
a_PAL(0) = $000000
a_PAL(1) = $FFFFFF
a_PAL(2) = $2B3768
a_PAL(3) = $B2A470
a_PAL(4) = $863D6F
a_PAL(5) = $438D58
a_PAL(6) = $792835
a_PAL(7) = $6FC7B8
a_PAL(8) = $254F6F
a_PAL(9) = $003943
a_PAL(10) = $59679A
a_PAL(11) = $444444
a_PAL(12) = $6C6C6C
a_PAL(13) = $84D29A
a_PAL(14) = $B55E6C
a_PAL(15) = $959595

If InitSprite()
	If OpenWindow(0, 0, 0, 820, 620, "Old School Decrunch Effect...", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
		If OpenWindowedScreen(WindowID(0), 10, 10, 800, 600, #True, 10, 10, #PB_Screen_NoSynchronization) ; x, y position, width, height, autostretch
			If CreateSprite(1,ScreenWidth(),256*2)
				If StartDrawing(SpriteOutput(1))
						For y = 0 To OutputHeight()-2 Step 2
							Box(0,y,OutputWidth(),2,a_pal(Random(15)))
						Next y
					StopDrawing()
				EndIf
				
				Repeat
					Repeat
						MyEvent = WindowEvent()
						If MyEvent = #PB_Event_CloseWindow
							Quit = #True
							Break
						EndIf
					Until MyEvent = 0
					
					FlipBuffers()
					If IsScreenActive()
						ClearScreen(0)
						
						For a = 0 To ScreenHeight()-1 Step 4
							x=0
							While x<ScreenWidth()
								length = Random(ScreenWidth()/8)
								ClipSprite(1,0,Random(256)*2,length,2)
								DisplaySprite(1,x,a)
								x+length
							Wend
						Next a
					StopDrawing()
					Delay(Random(100))
					
				EndIf
			Until Quit = #True
		EndIf
	EndIf
EndIf
EndIf
Added a proper palette ;) Tho its still not really like a c64 loading screen imo... :D