Is VIA emulation cycle-exact in VICE xvic?

You need an actual VIC.

Moderator: Moderators

Zagon
Vic 20 Newbie
Posts: 19
Joined: Sun May 10, 2009 9:37 am

Is VIA emulation cycle-exact in VICE xvic?

Post by Zagon »

Hi Denial people,

A short introduction: I'm new here and new to the vic 20 but I've been doing some 6502 programming in the past for the Commodore family of 8-bit computers so I wouldn't call myself completely green. However this is my first project on the vic 20.

I've been toying with a library for the vic 20 that emulates raster interrupts by reprogramming the one-shot
timer of the 'NMI'-VIA-chip.

The library allows for multiple "raster"-interrupts in one screen.
The interrupt triggers the same amunt of cycles from the beginning of the default centered screen
for both PAL and NTSC sytems. This makes it easy to write rasters that works on both systems.
Since a via timer is used it is also possible to do cycle-stable routines. the provided test-program
des this.

I've got it working in VICE but I'm not sure how much I can trust the xvic-emulation.

I would be very grateful if someone could test the provided prg file on the real thing, both PAL and
NTSC and see if it behaves the same as it does in vice.

The program displays three black lines as wide as the text-screen and cycle-exact centered
at the text screen and returns the prompt. The lines should be stable and not jitter.

The linked zip-file contains the test prg, called rnmi.prg, and the complete sourcecode for it, including
the library.

http://hem.bredband.net/magli143/vic20/rnmi.zip
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

Welcome, Swedish (?) friend.

It is my belief that VIA is very well emulated in xvic. Up to now the trailing behind has been the VIC-I chip which still is explored.

I can try your effects on both PAL and NTSC later tonight. In the mean time, perhaps you know since 1996 there already are routines to link a VIA timer to the raster beam? Possibly your routines work differently though. See for example the source code to Veni Vidi VIC!
Anders Carlsson

Image Image Image Image Image
User avatar
Jeff-20
Denial Founder
Posts: 5759
Joined: Wed Dec 31, 1969 6:00 pm

Post by Jeff-20 »

carlsson wrote:Welcome, Swedish (?) friend.
How did you guess?
High Scores, Links, and Jeff's Basic Games page.
User avatar
Mike
Herr VC
Posts: 4843
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

Jeff-20 wrote:How did you guess?
hem.bredband.net/[...] ? ;)

The VIA timers seem to be emulated reasonably well, witness Vicual MMIX, and all the earlier demos featuring stable in-raster splits.

I'm not that sure about the accuracy of the serial bus emulation (at least I wouldn't try to actually develop a floppy speeder on VICE without testing it on real hardware), and the keyboard interface, especially when more than 2 keys are pressed simultaneously.
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

Anyway, your raster lines are nice and stable both on PAL and NTSC. Once in a while there is a very slight flicker in the border area, but it is not possible to recreate on regular basis.
Anders Carlsson

Image Image Image Image Image
Zagon
Vic 20 Newbie
Posts: 19
Joined: Sun May 10, 2009 9:37 am

Post by Zagon »

Thanks for testing, carlsson.

So xvic is accurate enough for my routine. This is nice to hear.
However, that very slight flicker in the border area annoys me.
Does it occur on both PAL and NTSC?

I believe that it would me much easier for me to get hold of a PAL-system (yes I'm Swedish)
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

Yes, the flicker that maybe shows up once or twice in a minute of thorough testing happened on both video modes.
Anders Carlsson

Image Image Image Image Image
nippur72
de Lagash
Posts: 574
Joined: Thu Sep 07, 2006 8:35 am

Re: Is VIA emulation cycle-exact in VICE xvic?

Post by nippur72 »

uhm, ten years later, I just checked Zagon's file on VICE and it flickers a lot! (both PAL and NTSC).

A regression in emulation of the VIA?
User avatar
Mike
Herr VC
Posts: 4843
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Is VIA emulation cycle-exact in VICE xvic?

Post by Mike »

I just crossed checked RNMI.PRG on real hardware.

It doesn't flicker on the VIC-20, but it's not perfect either: the position of the bars only was correct on the first run. In subsequent runs, the bars were horizontally shifted, even when I reloaded the program to rule out possible issues with self modifying code.

Still something for the VICE bug tracker perhaps.
Zagon
Vic 20 Newbie
Posts: 19
Joined: Sun May 10, 2009 9:37 am

Re: Is VIA emulation cycle-exact in VICE xvic?

Post by Zagon »

When I wrote the RNMI code I coded it on xvic as I didn't have a real vic20 of my own back then. So the code was glitch free on the version of xvic I used but not on real hardware as pointed out in this thread.

A few years later I got hold of a real vic20 and could dig deeper into the observed jitter. And of course it was a bug in xvic, not in the VIA emulation but in the CPU emulation. I reported it to the VICE team and it has since been fixed. For those interested in the details, here's a link to the VICE bug issue: https://sourceforge.net/p/vice-emu/bugs/317/.

So, as you have observed, the RNMI code posted in the first message glitches on both real hardware and bugfixed VICE xvic.

I do have a fixed and slightly updated version of RNMI lying around that should work on real hardware and xvic.
[edit] Found it and attached it to this post.
Attachments
rnmi_fixed.zip
(4.36 KiB) Downloaded 149 times
nippur72
de Lagash
Posts: 574
Joined: Thu Sep 07, 2006 8:35 am

Re: Is VIA emulation cycle-exact in VICE xvic?

Post by nippur72 »

@Zagon, I haven't had the chance to test the fixed version on the real HW but running it in VICE:

- the initial position of the lines is 1-pixel off to the right (you can notice better it if you POKE $900F, $1a instead of $19)
- after the first one, on each run the lines jump onto a different position, flipping between two fixed locations (none of which is the one from the first run)

is that normal?

P.S. can you direct me to a good resource for understanding the VIA, at least the timers... all I have found so far is too technical. I would like to fix the FPGA implementation because it has some glitches.
Zagon
Vic 20 Newbie
Posts: 19
Joined: Sun May 10, 2009 9:37 am

Re: Is VIA emulation cycle-exact in VICE xvic?

Post by Zagon »

Sigh, you are correct. The "fixed" version fixes the line jitter but breaks the initial raster synchronization for NTSC xvic on the first run (It seems to be working for PAL xvic) Rerunning the program while it is still active breaks the raster synchronization for both PAL and NTSC. This however, is expected since the program doesn't expect NMI:s to be active when started.

The horizontal resolution of the positioning is one clock cycle (== a half character) and the lines are made by changing the background color. So any smaller horizontal alignment offsets is caused by the VIC hardware and unavoidable.

Here's an even better version that has been tested to work with VICE xvic for both PAL and NTSC. This version also supports being restarted while running. I don't have access to real hardware at the moment but it *should* work.

As for VIA programming information, One source that I've been using is https://archive.org/details/COMPUTEs_Ma ... blications.

[edit] Added VIA programming doc link
[edit2] Replaced attachment since another bug had crept in. Unlike the previous attempts, it triggered RNMI:s one line too early.
Attachments
rnmi_fixed3.zip
(4.38 KiB) Downloaded 149 times
groepaz
Vic 20 Scientist
Posts: 1191
Joined: Wed Aug 25, 2010 5:30 pm

Re: Is VIA emulation cycle-exact in VICE xvic?

Post by groepaz »

VIA is still a bit broken in VICE... so if you have reliable specific test programs that work on hardware but not in VICE - please report a bug :)
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
lance.ewing
Vic 20 Afficionado
Posts: 413
Joined: Sat Nov 10, 2012 3:19 pm
Website: https://sites.google.com/site/mos6561vic/

Re: Is VIA emulation cycle-exact in VICE xvic?

Post by lance.ewing »

nippur72 wrote: P.S. can you direct me to a good resource for understanding the VIA, at least the timers... all I have found so far is too technical. I would like to fix the FPGA implementation because it has some glitches.
The original preliminary MOS 6522 datasheet on 6502.org has at least one mistake I know of that reverses the logic of one particular aspect from what it actually is. I suppose you've also seen the Rockwell, Synertek, and WDC datasheets? I usually look across all four of those and compare what they say about the same thing. Often it is quite similar but sometimes one describes or illustrates something a bit clearer. Even then there are aspects that aren't fully explained in any of them.

I know that the 6522 emulation in my JVic emulator is quite buggy and incomplete at the moment, because when I used the same code in my Oric emulator, a pre-existing test program written for the Oric highlighted a number of timing issues that I corrected in my JOric emulator but haven't yet dropped back into JVic. I think I might try that at some point in the next few weeks.

I guess we could always try to reverse the exact logic from the 6522 die shot, but that might take quite a long time. Think of how long the 6561 has been taking; three years and counting. Still, I'd like to start on the 6522 die shot at some point. It could be quite interesting.
nippur72
de Lagash
Posts: 574
Joined: Thu Sep 07, 2006 8:35 am

Re: Is VIA emulation cycle-exact in VICE xvic?

Post by nippur72 »

lance.ewing wrote:Still, I'd like to start on the 6522 die shot at some point. It could be quite interesting.
yes, and there is no emulator that would not benefit from it. Looking at the various 6522 implementations (HDL and software) they are all different. How sad. Sometimes on the same system there are two 6522 versions, e.g. the VIC20 on the MiST FPGA, has a 6522 for the VIC and a totally different one for the floppy drive.

P.S. peeking into JVic's source code but I could not find sound emulation :-)
Post Reply