Welcome to Emulationworld

Forum Index | FAQ | New User | Login | Search

Make a New PostPrevious ThreadView All ThreadsNext Thread*Show in Threaded Mode


SubjectDrawing graphics new Reply to this message
Posted byGeSUB
Posted on03/29/04 00:15 AM



I'm about to start programming a Commodore 64 emulator but before I begin, I'd like to ask a few questions regarding the graphics part of it. But before I ask my questions, let me give you some background info on what I know.

- Assembly for the 6502/6510 cpu.
- VIC II, 6526 CIA architecture (internal registers)
- Still working on reviewing the SID chip

As for my programming knowledge, I've done quite a bit of work with VB 6 but my language of choice is C/C++. I've also done quite a bit of programming for the Directx API (version 7-9) especially Direct3D.

Now to my questions:

1) Which is preferred for displaying the graphics when using the DirectX API? DirectDraw or Direct3D? I'm asking because Direct3D doesn't really seem suited for direct pixel manipulation which I believe is whats needed for drawing the screen.

2) Is the screen drawn all at once or one scanline at a time? I would think it needs to be drawn one scanline at a time for it to be accurate. I say this because the C64 uses raster interrupts that can modify the screen in real time.

3) If drawing the screen using scanlines is the preferred method, what's the fastest way to achieve this. I'd hate to lock and unlock the back buffer many times as the scanline is drawn. This would be way to slow in Direct3D or DirectDraw. Am I better off drawing the scanlines in a temporary array (virtual screen) and then paint it to the screen at once? What's the best approach to this.

4) And what about the 8 sprites the C64 supports. Is this a matter of just making PC sprites that mimic the C64's sprites.

I'd appreciate any info you guys could give me.

Thanks




SubjectRe: Drawing graphics new Reply to this message
Posted byBart T.
Posted on03/29/04 00:30 AM



> 1) Which is preferred for displaying the graphics when using the DirectX API?
> DirectDraw or Direct3D? I'm asking because Direct3D doesn't really seem suited
> for direct pixel manipulation which I believe is whats needed for drawing the
> screen.

If you're more comfortable with DDraw, use that. It should perform quite well. To use Direct3D, you'll have to render to textures and display those with an orthogonal projection.

> 3) If drawing the screen using scanlines is the preferred method, what's the
> fastest way to achieve this. I'd hate to lock and unlock the back buffer many
> times as the scanline is drawn. This would be way to slow in Direct3D or
> DirectDraw. Am I better off drawing the scanlines in a temporary array (virtual
> screen) and then paint it to the screen at once? What's the best approach to
> this.

Drawing at least a scanline at a time is the way to go.

As for where to draw to, use a backbuffer and then flip buffers each frame. DDraw has direct support for this IIRC. It's probably the fastest way of doing it.

> 4) And what about the 8 sprites the C64 supports. Is this a matter of just
> making PC sprites that mimic the C64's sprites.

The PC doesn't have sprites. Your rendering code will have to render them properly into the current scanline. You'll have to determine which sprites are visible on a given scanline and then figure out which line of each sprite to draw. I'll guess the C64 also has priorities and various attributes you'll have to account for.




----
Bart


SubjectRe: Drawing graphics new Reply to this message
Posted bygalibert
Posted on03/29/04 06:07 AM



> 2) Is the screen drawn all at once or one scanline at a time? I would think it
> needs to be drawn one scanline at a time for it to be accurate. I say this
> because the C64 uses raster interrupts that can modify the screen in real time.

I think the most accurate (while still reasonably efficient) way is to detect all write accesses to video registers and memory and render everything up to the current pixel when one happens. You can even change the trapping range every scanline to make things slightly faster. Modern PCs can handle it anyway.

OG.





SubjectRe: Drawing graphics Reply to this message
Posted byfinaldave
Posted on03/29/04 08:06 AM



> I'm about to start programming a Commodore 64 emulator but before I begin, I'd
> like to ask a few questions regarding the graphics part of it. But before I ask
> my questions, let me give you some background info on what I know.
>
> - Assembly for the 6502/6510 cpu.
> - VIC II, 6526 CIA architecture (internal registers)
> - Still working on reviewing the SID chip
>
> As for my programming knowledge, I've done quite a bit of work with VB 6 but my
> language of choice is C/C . I've also done quite a bit of programming for the
> Directx API (version 7-9) especially Direct3D.
>
> Now to my questions:
>
> 1) Which is preferred for displaying the graphics when using the DirectX API?
> DirectDraw or Direct3D? I'm asking because Direct3D doesn't really seem suited
> for direct pixel manipulation which I believe is whats needed for drawing the
> screen.

In Direct3D you could make a texture the size of the screen, lock the texture write the screen into it, and then draw a Quad the size of the screen. This is how I'm doing stuff on the XBox as well, albeit with swizzled textures, and it seems to work nice. It's also how other XBox emulators work.
Or I think you can lock Surface's in the same way as DirectDraw though I haven't tried this yet.

On PC, DirectDraw might be preferable, because of the compatiblity (95, 98, NT, 2000, XP all have DirectX 3.0)

> 2) Is the screen drawn all at once or one scanline at a time? I would think it
> needs to be drawn one scanline at a time for it to be accurate. I say this
> because the C64 uses raster interrupts that can modify the screen in real time.

See OG's reply - he has it right
>
> 3) If drawing the screen using scanlines is the preferred method, what's the
> fastest way to achieve this. I'd hate to lock and unlock the back buffer many
> times as the scanline is drawn. This would be way to slow in Direct3D or
> DirectDraw. Am I better off drawing the scanlines in a temporary array (virtual
> screen) and then paint it to the screen at once? What's the best approach to
> this.

Yes, that's what I do, I use a temporary buffer and then copy it to a DirectDraw Surface when it's done. I prefer this method rather than Locking before the start of a frame and Unlocking after the frame, or locking each scanline, because if the emulator crashes during a Lock/Unlock pair it tends to lock up some systems (especially on older versions of Windows)

Also you sometimes have to alpha blend a video image, so it can be faster than reading out of video memory


>
> 4) And what about the 8 sprites the C64 supports. Is this a matter of just
> making PC sprites that mimic the C64's sprites.

You'd typically do the sprites in software to be honest
>
> I'd appreciate any info you guys could give me.
>
> Thanks
>


You learn something old everyday...



SubjectRe: Drawing graphics new Reply to this message
Posted byGeSUB
Posted on03/29/04 04:33 PM



Thanks for all the reply's. You guy's have been a great help.

Thanks




SubjectRe: Drawing graphics new Reply to this message
Posted byR. Belmont
Posted on03/31/04 10:44 PM



> I think the most accurate (while still reasonably efficient) way is to detect
> all write accesses to video registers and memory and render everything up to the
> current pixel when one happens. You can even change the trapping range every
> scanline to make things slightly faster. Modern PCs can handle it anyway.

I've also seen emulators that simply store the current scanline each time a write occurs and then play it back like a display list at the end of the frame. It's faster than conventional scanline rendering since you don't need to stop the CPU and context switch, but it can be memory intensive :-)





SubjectRe: Drawing graphics new Reply to this message
Posted byJan_Klaassen
Posted on04/02/04 11:51 AM



> I'm about to start programming a Commodore 64 emulator but before I begin, I'd
> like to ask a few questions regarding the graphics part of it. But before I ask
> my questions, let me give you some background info on what I know.
>
> - Assembly for the 6502/6510 cpu.
> - VIC II, 6526 CIA architecture (internal registers)
> - Still working on reviewing the SID chip
>
> As for my programming knowledge, I've done quite a bit of work with VB 6 but my
> language of choice is C/C++. I've also done quite a bit of programming for the
> Directx API (version 7-9) especially Direct3D.
>
> Now to my questions:
>
> 1) Which is preferred for displaying the graphics when using the DirectX API?
> DirectDraw or Direct3D? I'm asking because Direct3D doesn't really seem suited
> for direct pixel manipulation which I believe is whats needed for drawing the
> screen.

Direct3D can be a bit of a pain, but not for that reason (dynamic textures require special care). You'll want to draw to a buffer and then transfer that to a DirectX surface later anyway, so it won't make any difference for your drawing code if you use DirectDraw or Direct3D. If you want something that's simple and works on pretty much any hardware, go for DirectDraw3. Unless you need something that requires using Direct3D, it's not worth the hassle.

> 2) Is the screen drawn all at once or one scanline at a time? I would think it
> needs to be drawn one scanline at a time for it to be accurate. I say this
> because the C64 uses raster interrupts that can modify the screen in real time.

It's worse, you'll need to have cycle-accurate synchronisation, and you'll need to have it for all emulated chips, not just video. Even some games rely on bugs in the VIC-II chip, so enjoy. :)

> 3) If drawing the screen using scanlines is the preferred method, what's the
> fastest way to achieve this. I'd hate to lock and unlock the back buffer many
> times as the scanline is drawn. This would be way to slow in Direct3D or
> DirectDraw. Am I better off drawing the scanlines in a temporary array (virtual
> screen) and then paint it to the screen at once? What's the best approach to
> this.

A temporary buffer of some kind, as you've surmised.

> 4) And what about the 8 sprites the C64 supports. Is this a matter of just
> making PC sprites that mimic the C64's sprites.

No, aside from PC's not using sprites, there's details like the hardware collision detection the VIC-II chip has. Also there are countless games that re-use the sprites to get more than 8 on the screen (on C64, sprites eat memory cycles from the 6510 as well, you'll need to take that into account).




SubjectCan't believe nobody's said SDL *nt* SDL pwns u new Reply to this message
Posted byMooglyGuy
Posted on04/06/04 09:26 AM



> I'm about to start programming a Commodore 64 emulator but before I begin, I'd
> like to ask a few questions regarding the graphics part of it. But before I ask
> my questions, let me give you some background info on what I know.
>
> - Assembly for the 6502/6510 cpu.
> - VIC II, 6526 CIA architecture (internal registers)
> - Still working on reviewing the SID chip
>
> As for my programming knowledge, I've done quite a bit of work with VB 6 but my
> language of choice is C/C++. I've also done quite a bit of programming for the
> Directx API (version 7-9) especially Direct3D.
>
> Now to my questions:
>
> 1) Which is preferred for displaying the graphics when using the DirectX API?
> DirectDraw or Direct3D? I'm asking because Direct3D doesn't really seem suited
> for direct pixel manipulation which I believe is whats needed for drawing the
> screen.
>
> 2) Is the screen drawn all at once or one scanline at a time? I would think it
> needs to be drawn one scanline at a time for it to be accurate. I say this
> because the C64 uses raster interrupts that can modify the screen in real time.
>
> 3) If drawing the screen using scanlines is the preferred method, what's the
> fastest way to achieve this. I'd hate to lock and unlock the back buffer many
> times as the scanline is drawn. This would be way to slow in Direct3D or
> DirectDraw. Am I better off drawing the scanlines in a temporary array (virtual
> screen) and then paint it to the screen at once? What's the best approach to
> this.
>
> 4) And what about the 8 sprites the C64 supports. Is this a matter of just
> making PC sprites that mimic the C64's sprites.
>
> I'd appreciate any info you guys could give me.
>
> Thanks
>



SubjectRe: Drawing graphics new Reply to this message
Posted bysmf
Posted on04/07/04 07:12 AM



Yes, you would also need to store buffered contents of video ram for certain systems. You could use this for sending the display across a network.

smf





Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode