commodore 64 loading screen

Just starting out? Need help? Post your questions and find answers here.
rootuid
User
User
Posts: 48
Joined: Sat Nov 23, 2013 11:46 am

commodore 64 loading screen

Post 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.
User avatar
Bisonte
Addict
Addict
Posts: 1313
Joined: Tue Oct 09, 2007 2:15 am

Re: commodore 64 loading screen

Post by Bisonte »

can you tell us the original syntax of this drawrect ? It's look like the Box(x, y, Width, Height, Color) function...
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
rootuid
User
User
Posts: 48
Joined: Sat Nov 23, 2013 11:46 am

Re: commodore 64 loading screen

Post by rootuid »

That's it petty much.
Last edited by rootuid on Sat Nov 23, 2013 10:30 pm, edited 1 time in total.
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: commodore 64 loading screen

Post 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.
Last edited by Demivec on Sun May 18, 2014 4:02 pm, edited 1 time in total.
rootuid
User
User
Posts: 48
Joined: Sat Nov 23, 2013 11:46 am

Re: commodore 64 loading screen

Post by rootuid »

Thanks exactly it Demivec, many thanks.
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: commodore 64 loading screen

Post by Demivec »

rootuid wrote:Thanks exactly it Demivec, many thanks.
Your welcome.

Welcome also to the PureBasic Forums.
User avatar
em_uk
Enthusiast
Enthusiast
Posts: 366
Joined: Sun Aug 08, 2010 3:32 pm
Location: Manchester UK

Re: commodore 64 loading screen

Post 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
----

R Tape loading error, 0:1
rootuid
User
User
Posts: 48
Joined: Sat Nov 23, 2013 11:46 am

Re: commodore 64 loading screen

Post by rootuid »

Thanks for that. I tried that but all I get is a blank window.
User avatar
Teddy Rogers
User
User
Posts: 98
Joined: Sun Feb 23, 2014 2:05 am
Location: Australia
Contact:

Re: commodore 64 loading screen

Post 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.
User avatar
majikeyric
Enthusiast
Enthusiast
Posts: 187
Joined: Mon Oct 21, 2013 5:21 pm
Location: France
Contact:

Re: commodore 64 loading screen

Post by majikeyric »

C64 rulez! :mrgreen:
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: commodore 64 loading screen

Post 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
:)
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: commodore 64 loading screen

Post 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?
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: commodore 64 loading screen

Post 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
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: commodore 64 loading screen

Post by coco2 »

Thanks for that information, I always wondered about that.
User avatar
oreopa
Enthusiast
Enthusiast
Posts: 283
Joined: Sat Jun 24, 2006 3:29 am
Location: Edinburgh, Scotland.

Re: commodore 64 loading screen

Post 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
Proud supporter of PB! * Musician * C64/6502 Freak
Post Reply