C64 VIC-II chip

Started by Baggey, November 19, 2021, 11:50:04

Previous topic - Next topic

Baggey

Quote from: Midimaster on November 20, 2021, 10:48:56
Ok... I found out, that TPixMaps are not converted in a virtual resolution. But TImages will . So a workaround could be to convert the TPixmap into a TImage before drawing it:

Code (BlitzMax) Select
    Graphics 800,600
    SetVirtualResolution 320,200
Global image:TPixmap=LoadPixmap("test320200.png")
    Repeat
            Cls
            DrawRect 5,5,10,10
            DrawRect 5,185,10,10
            DrawRect 305,185,10,10
            DrawRect 305,5,10,10
            DrawImage LoadImage(image),0,0
            Flip 1
     
    Until AppTerminate()

Test320200.png is in the attachment

Can you draw pixels using a ptr with Timages?

Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 24GB ram 1TB SSD and NVIDIA Quadro K620 . DID Technology stop! Or have we been assimulated!

ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!

Baggey

#16
Quote from: Midimaster on November 20, 2021, 10:48:56
Ok... I found out, that TPixMaps are not converted in a virtual resolution. But TImages will . So a workaround could be to convert the TPixmap into a TImage before drawing it:

Code (BlitzMax) Select
    Graphics 800,600
    SetVirtualResolution 320,200
Global image:TPixmap=LoadPixmap("test320200.png")
    Repeat
            Cls
            DrawRect 5,5,10,10
            DrawRect 5,185,10,10
            DrawRect 305,185,10,10
            DrawRect 305,5,10,10
            DrawImage LoadImage(image),0,0
            Flip 1
     
    Until AppTerminate()

Test320200.png is in the attachment

Very Interesting. Ive changed to see what your saying :)

Code (blitzmax) Select


        Graphics 800,600
        SetVirtualResolution 320,200

            Global image:TImage=LoadImage("test320200.png")
       

        Repeat
                Cls
                DrawRect 5,5,10,10
                DrawRect 5,185,10,10
                DrawRect 305,185,10,10
                DrawRect 305,5,10,10

                DrawImage image,0,0
                Flip 1

         
        Until AppTerminate()


Add this line to get rid of TaskBar  :)

Code (Blitzcode) Select

Graphics 1920,1080,32,0


Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 24GB ram 1TB SSD and NVIDIA Quadro K620 . DID Technology stop! Or have we been assimulated!

ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!

Midimaster

To manipulate PixMaps you should use the given TPixmaps methods like Copy(), Paste, ReadPixel() and WritePixel()... as a first step. On a modern computer they are fast enough for a lot of cases.

See my example of how to cut a hole into a TPixmap here:
Last version of code:
https://www.syntaxbomb.com/blitzmax-blitzmax-ng/try-to-make-a-hole-on-an-image-using-setrenderimage-but-is-not-working/msg347053189/#msg347053189

Image-files:
https://www.syntaxbomb.com/blitzmax-blitzmax-ng/try-to-make-a-hole-on-an-image-using-setrenderimage-but-is-not-working/?action=dlattach;attach=4985

https://www.syntaxbomb.com/blitzmax-blitzmax-ng/try-to-make-a-hole-on-an-image-using-setrenderimage-but-is-not-working/?action=dlattach;attach=4983

https://www.syntaxbomb.com/blitzmax-blitzmax-ng/try-to-make-a-hole-on-an-image-using-setrenderimage-but-is-not-working/?action=dlattach;attach=4987

Of course you can also use Int Ptr to manipulate directly the pixels of allocated RAM of TPixmap. In this case I would work with always the same TPixMap-format to keep things easy. f.e. PF_RGBA8888.

In this format a INTEGER represents a single Pixel with its components (4 bytes) A-R-G-B. This Pointer approach maybe faster, because there are no "out-of-bound"-checks.

What do you plan to do? Would you like to "insert" 8x8pixel-rectangles into a TPixelmap?
...back from Egypt

Baggey

Trying to Resize a Tpixmap to an arbitary size using GL!

This Dosent work as expected!  :-[  Any ideas why?

Code (blitzmax) Select


SuperStrict

SetGraphicsDriver(GLMax2DDriver())

Graphics 800 , 600

Global pix:TPixmap=LoadPixmap(blitzmaxpath()+"\samples\hitoro\gfx\boing.png")
Global pixptr: Int Ptr
pixptr = Int Ptr(pix.pixels)

If pix = Null Then
RuntimeError ("Error Loading Image")
End If

Global screen: TPixmap
Global screenptr: Int Ptr

screen = CreatePixmap(500, 500, PF_RGBA8888)
screen.ClearPixels(255)
screenptr = Int Ptr(screen.pixels)

gluScaleImage(GL_RGBA, 50, 50, GL_UNSIGNED_byte, pixptr, 500, 500, GL_UNSIGNED_byte, screenptr)

Repeat
Cls
DrawPixmap pix, 50, 50
DrawPixmap screen, MouseX() , MouseY()
Flip
Until KeyHit(key_escape) Or AppTerminate()


Kind Regards Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 24GB ram 1TB SSD and NVIDIA Quadro K620 . DID Technology stop! Or have we been assimulated!

ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!

Midimaster

I dont know anything about OpenGL, but scaling a TPixMap into a new one can also be done with the function

NewPixMap:TPixMap = ResizePixmap( OldPixMap, NewWidth,NewHeight )
...back from Egypt

Baggey

#20
Quote from: Midimaster on November 20, 2021, 14:56:26
I dont know anything about OpenGL, but scaling a TPixMap into a new one can also be done with the function

NewPixMap:TPixMap = ResizePixmap( OldPixMap, NewWidth,NewHeight )

I have taken on your suggestions and im having sucess with full Screen and IDE enviroment Window using your "test320200.png"  8)

However when i make my own 320x200.png and try to use it i get Nothing Working!?

this line gives nothing as well? Global Screen:TPixmap=CreatePixmap(C64_Width, C64_Height, PF_RGBA8888,4)

I seem to remember many years ago something to do with masked pixels and Alpha blending! Whitch i have no fricken idea about! :-X

Could this be my problem?

UPDATE!

Ive used Gimp2 to save my own .png and its working? if I use a black Background thou it dosent? Is this Alpha or Masking problem  ::)

I still cant Create a sucessfull createTpixmap Directly  :(  Ive cycled through all the Formats.  ???

I Think i need some sleep now!

Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 24GB ram 1TB SSD and NVIDIA Quadro K620 . DID Technology stop! Or have we been assimulated!

ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!

Baggey

So,
     This is all Runnable code in BlitzmaxNG!

So without further ado! With Midimaster's suggestions i have come up with this whitch closely suits my IDE Enviroment to get the VIC-II Full screen going. Im going to have to re-write the ZX Emulator it was a Fluke i got full screen  :'(

Ive used GIMP2.0 to get a working Formatted image

Anyway if i use this code the VirtualResolution dosent work  with the image???

Version1

Code (blitzmax) Select


SetGraphicsDriver(GLMax2DDriver())

'Graphics 800,600

'SetMaskColor( 255,0,0 ) ' If Loaded image is red it dosent get seen its masked?

Global DeskWidth:Int=DesktopWidth()-16 , DeskHeight:Int=558

Global BigORsmall:Byte=0

Global C64_Width:Int=320 , C64_Height:Int=200
Global C64_TV_Width:Int=352 , C64_TV_Height:Int=232

' BUG! ... Creating a Pixmap in Blitzmax Dosent give an image that can be used in Virtual Screen!
Global Screen:TPixmap=CreatePixmap(C64_Width, C64_Height, PF_RGBA8888)

' Loading one from else where Dose!?
'Global Screen:TPixmap=LoadPixmap("out_run_64.png")

ClearPixels(screen, $FF0000) ' Turn Color RED ... (R),(G),(B) Components

Global Border:TPixmap = ResizePixmap( Screen, C64_TV_Width, C64_TV_Height )




ChangeScreen()

    Repeat
            Cls

            Local color:Int = Rnd($ffffff)
            ClearPixels(Border, color)


            If BigORSmall=0 Then ' Big screen Emulator FULL MODE!
                   HideMouse()
                   DrawImage LoadImage (Border),0,0 ' VirtualMouseX(),VirtualMouseY()
                   DrawImage LoadImage (Screen),16,16 ' VirtualMouseX()+16,VirtualMouseY()+16
     

              Else ' Small screen IDE Enviroment
                   ShowMouse()
                   DrawPixmap (Border),316,14 ' MouseX(),MouseY()
                   DrawPixmap (screen),332,30 ' MouseX()+16,MouseY()+16
                   SetColor(255,0,0)
                   DrawText(" PRESS S for FULLSCREEN! ... Remember ESC for QUIT or S For Screen Change!",10,540)
            End If


            Flip(0)
           
            If KeyHit(KEY_ESCAPE) End
            If KeyHit(key_S) Then ChangeScreen()

    Until AppTerminate()
     
    Function ChangeScreen()
            BigORsmall = Not BigORsmall
            Select BigORsmall
                    Case 0 ' Big
                        'End Graphics DeskWidth,DeskHeight
                        Graphics 1920,1080,32,0
                        SetVirtualResolution C64_TV_Width,C64_TV_Height
               
                    Case 1 ' Small
                        Graphics DeskWidth,DeskHeight
                        SetVirtualResolution DeskWidth,DeskHeight
                       
            End Select

    End Function
   



Now in the next version ive captured a screen shot and saved it with GIMP2.0 see attached image to get going!

Version2.0

Code (blitzmax) Select


SetGraphicsDriver(GLMax2DDriver())

'Graphics 800,600

'SetMaskColor( 255,0,0 ) ' If Loaded image is red it dosent get seen its masked?

Global DeskWidth:Int=DesktopWidth()-16 , DeskHeight:Int=558

Global BigORsmall:Byte=0

Global C64_Width:Int=320 , C64_Height:Int=200
Global C64_TV_Width:Int=352 , C64_TV_Height:Int=232

' BUG! ... Creating a Pixmap in Blitzmax Dosent give an image that can be used in Virtual Screen!
'Global Screen:TPixmap=CreatePixmap(C64_Width, C64_Height, PF_RGBA8888)

' Loading one from else where Dose!?
Global Screen:TPixmap=LoadPixmap("out_run_64.png")

'ClearPixels(screen, $FF0000) ' Turn Color RED ... (R),(G),(B) Components

Global Border:TPixmap = ResizePixmap( Screen, C64_TV_Width, C64_TV_Height )




ChangeScreen()

    Repeat
            Cls

            Local color:Int = Rnd($ffffff)
            ClearPixels(Border, color)


            If BigORSmall=0 Then ' Big screen Emulator FULL MODE!
                   HideMouse()
                   DrawImage LoadImage (Border),0,0 ' VirtualMouseX(),VirtualMouseY()
                   DrawImage LoadImage (Screen),16,16 ' VirtualMouseX()+16,VirtualMouseY()+16
     

              Else ' Small screen IDE Enviroment
                   ShowMouse()
                   DrawPixmap (Border),316,14 ' MouseX(),MouseY()
                   DrawPixmap (screen),332,30 ' MouseX()+16,MouseY()+16
                   SetColor(255,0,0)
                   DrawText(" PRESS S for FULLSCREEN! ... Remember ESC for QUIT or S For Screen Change!",10,540)
            End If


            Flip(0)
           
            If KeyHit(KEY_ESCAPE) End
            If KeyHit(key_S) Then ChangeScreen()

    Until AppTerminate()
     
    Function ChangeScreen()
            BigORsmall = Not BigORsmall
            Select BigORsmall
                    Case 0 ' Big
                        'End Graphics DeskWidth,DeskHeight
                        Graphics 1920,1080,32,0
                        SetVirtualResolution C64_TV_Width,C64_TV_Height
               
                    Case 1 ' Small
                        Graphics DeskWidth,DeskHeight
                        SetVirtualResolution DeskWidth,DeskHeight
                       
            End Select

    End Function
   


Now why does this work i ask myself :-X

It must be to do with the FORMAT the pixel's are in. Any idea's I need to use the Tpixmap with Gl and pointers to get real Speed! But this is the basic setup  8)

Kind Regards Baggey


Running a PC that just Aint fast enough!? i7 4Ghz Quad core 24GB ram 1TB SSD and NVIDIA Quadro K620 . DID Technology stop! Or have we been assimulated!

ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!

Baggey

I have Text Mode Working!  8)

So that was a lot of Math! You need to build the address for the Screen Mem from the bits stored in C64 Memory. Then find out what Byte is actually stored in their. Then from this the bits stored in C64 Memory. Calculate the Character ROM address, which we can relate to the code for the character which we then, find the row offset related to the address of the character ROM. Then calculate Pixel Coordinates related to this bearing in mind Screen Ram is Movable and Character Rom is movable or can be Userdefind as well.  :o

So, it needs polishing up a bit. But for now it seems to be reasonably fast enough. I may look into creating another Screen Buffer where all of the above is referenced to one screen byte using Pointers. Maybe use a Flag check so that if a particular Raster Line hasn't altered skip it! Looping 24000 times before a screen update needs to happen. Needs to be as fast as possible.

Single stepping instructions and creating them as the Emulator CRASHES! Wont be so boring now, that there's something Visual to look at  :-X

Kind Regards Baggey



Running a PC that just Aint fast enough!? i7 4Ghz Quad core 24GB ram 1TB SSD and NVIDIA Quadro K620 . DID Technology stop! Or have we been assimulated!

ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!

Baggey

So, In what seems to be a never ending quest?

I have got my BlitzmaxC64 working. And now i find different software used different graphics modes. Okay the programmer used what they where comfortable with.

So i realize i need to emulate these ???

I didnt know the C64 had 8 graphics modes and 3 of them where complete garbage/gobledegook  :-X  giving only Black colour's. Totally unuseable for the HUMAN.

Try Pokeing on the real machine 

POKE(53265,(PEEK(53265)OR64)) : POKE(53270,(PEEK(53270)OR16))

You will get a black screen so what was the FUKG point of that!?

I find this old 8 bit C64 Computer both interesting and anoying at the same time WTF?

Why do you need these types of Mode's for, when its completely useless at the same time? Maybe this was the way forward for the C128?

So i need to emulate these to get an actual working version of the real thing, and not just a Simulation!

Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 24GB ram 1TB SSD and NVIDIA Quadro K620 . DID Technology stop! Or have we been assimulated!

ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!

Dan

I can imagine that these modes could accelerate some basic programs.
For example if you need a lot of data statements to poke, you would switch to these modes, use the pokes, then turn back to normal.
The C64 CPU does not need to worry about what is on the screen and concentrate on the program.

65536 GOTO Back2Basic

Baggey

Im Implementing the so called SMOOTH SCROLLING of the VICII

From the programmers reference manual you type on the real C64, POKE 53270,PEEK(53270)AND247

We get larger borders :D

Im using a TV monitor :( and am getting blur! I can see part of the cursor flashing on the Left so Bit0 is left as normal.

So, ive implemented that. But i would expect the same to happen with Bit7 on the right side of the screen so you can see whats scrolling in :-\

I cant make any detail with a blurred TV screen/picture. And im not entirely sure if the E is one pixel from the border or dead tight to it ???

Anyone remember or could shed some light on it?

Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 24GB ram 1TB SSD and NVIDIA Quadro K620 . DID Technology stop! Or have we been assimulated!

ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!

Baggey

So, Ive implemented the 38 Column mode and the 24 Row Mode

Im, glad i have The "Real Mini C64" at hand, as the 24 Row mode isn't quite what you'd expect unless you have the real thing to work in conjunction with :D

The 24 Row mode is in fact A Nibble of rows on Row 0 Bits 4..7, and a Nibble of rows on Row 23 Bits 0..3

Ive just realized i may need to do a re-write of the VICII for actual scrolling. I can offset Vertically but Horizontally is something a bit different Hmm? :-\

I may need to use some sort of viewport command?

I may leave this for now as im unsure how many games actually used this? It may of been more for Basic Programming as the C64 Basic is Badly Slow!

So Lets get some sprites going.

Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 24GB ram 1TB SSD and NVIDIA Quadro K620 . DID Technology stop! Or have we been assimulated!

ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!

Baggey

#27
Im at the point where Loading in games is given rubbish :-X

It seems that the VICII did a complete share of the Master Clock so in a nut shell they took in turns with each other.

But the VICII was a bit greedy on every 0 line reading memory twice. So it stole 40 Cycles. Apparently this is the famous bad line.

It also appears that the VICII did this on the fly! Hence Raster demo effects that are quite popular these days utilizing the Raster Timing and pushing the Boundaries of the VICII by changing the registers on the fly with interrupts. Making it do what it wasn't supposed todo :o . I need to emulate this as well.

It seems that back in the day People weren't really aware of these tricks or just didn't have the time or the budget to fully explore what this chip could really do. I suppose tight time schedules to pump out the next game! Was the governing factor. In the 80's the Spectrum always looked more aesthetically pleasing with its smaller pixels. You'd have to be completely blind if you think differently about that ::)

But it seems that if you knew about the above and could be bothered todo the math to time the tricks. Let alone the time and budget. Games could of been so much more and very different graphically.

We could of had more than 8 sprites on the same line or used bit mapped graphics more, rather than fat ugly double wide pixels, which seemed to be the accepted norm for the day. Even more colors. The VICII could of done so much more! or still can with out any modifications to the bog standard C64.

There is also a Raster counter with a ninth bit! This all keeps track of what position the VICII is Writing to the Screen and selecting the data from memory as well!? In conjunction with CIA2 $DD00 and $D012, $D018, Current 3 bits of the Raster counter and the Current Screen Code. To find and fetch data.

So, a re-write is on the cards :-\ .

It seems that some of the known tricks were used so games where programmed to mix Graphic modes with text Bitmaps. Hence why im not getting games to Run!?

Apart from The C64 Programmers Reference Guide, Christian Bauer's texts. This is all ive got to learn from.

I have just come across the C64OS write up which is another good reference, off the above. But in what i would call Laymen Speak! Its more readable and more detailed. There is also some very good write ups here on the C64!

https://c64os.com/post/flitiming1

So, Lets see where i get.

Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 24GB ram 1TB SSD and NVIDIA Quadro K620 . DID Technology stop! Or have we been assimulated!

ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!

Baggey

Quote from: Baggey on November 02, 2023, 11:21:08Im at the point where Loading in games is given rubbish :-X

It seems that the VICII did a complete share of the Master Clock so in a nut shell they took in turns with each other.
Did some work towards the taking in turns of the VICII and the CPU yesterday. But im sort off left wondering about the CPU emulation to do this.

Currently i run an instruction. This could of taken between ( 2 and 8 ) Tcycles. If the there is indeed a real Cycle share that would mean the VICII would have run 3 times during a 3 Tcycle instruction and upto 8 during an 8 Tcycle instruction.

From an emulation point of few, it maybe i just run the instruction then make sure the VICII runs 3 to 8 times after!?

Ben Eater has done some work on how the instructions work in depth. https://eater.net/ Im now wondering wether i need to go this deep to achieve true Raster Emulation.

Note, I seem to remember there are steps within an instruction. ie, M1,M2,M3...etc This means that the instruction may assert a Ram read 1 Cycle. Get data 1 Cycle and do the operation in another Cycle. So this would mean that data on the bus would of changed so i think errors would occur if this happens when data is being written or read to the screen?

As in the first Tcycle we may of had lets say 255 on the data bus and half way through the instruction it may of changed to 127. So the VICII Emulation would need to see this todo a proper raster line with the change and that time stamp. Maybe i need to add in a check if this happens with certain instructions? Only experimentation i feel is going to prove this by visually looking for glitches running some games or raster demos. :-X

On a so called Badline i think the VICII steals 40 Cycles to get the Screen code and color data to produce the next 7 rows.

In order to get Raster bars and Split screen Modes it seems i need to come up with away of achieving the above.

If anyone has any experience with this, i sure would appreciate some pointers.

Baggey 
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 24GB ram 1TB SSD and NVIDIA Quadro K620 . DID Technology stop! Or have we been assimulated!

ZX Spectrum 48k, C64, ORIC Atmos 48K, Enterprise 128K, The SID chip. Im Misunderstood!