Page 1 of 3

vic20-emu (another emulator)

Posted: Fri Jul 17, 2020 1:06 am
by nippur72
I'm having fun writing another VIC-20 emulator :)

It's not totally new, I've taken the code from Andre Weissflog's Tiny 8 bit emulators and recompiled / adapted for the web browser.

Andre Weissflog's source code is special because he emulates every chip separately at the pin level, and then he connects them together as in the real hardware. It's a very interesting approach that lets you get a better understanding on how small details work in a 8 bit machine.

It's all written in C and every "chip" resides in a single .h file that you can #include. Emulation is not perfect, some games don't work, but since the project is open source you can fix bugs and submit improvements.

I compile C to WebAssembly, which is a new web technology that lets you run compiled code at almost native speed (it's a sort of stack-based virtual machine). The I use Javascript to host the webassembly code and interact with the user.

You can run the vic20-emu here.

The purpose of this emulator is to have something that I can easily hack and script.
Immagine.png

Re: vic20-emu (another emulator)

Posted: Fri Jul 17, 2020 10:41 am
by chysn
My first question is, how do you load a file into it?

Re: vic20-emu (another emulator)

Posted: Sat Jul 18, 2020 9:17 am
by nippur72
chysn wrote: Fri Jul 17, 2020 10:41 am My first question is, how do you load a file into it?
using today's version: drag & drop a ".prg" file on the screen and then RUN.

You can also open the Javascript console (key F12) and issue the following commands:

- `load("file.prg" [,start])` loads a file at the specified address
- `save("file.prg" [,start, end])` saves a file
- `download("file.prg")` gets the file as a browser download
- `remove("file.prg")` remove file from browser's cache
- `dir()` lists files on browser's cache
- `vic20.config(n)` configures memory (n from 0 to 5)
- `vic20.reset()` resets the VIC20 (also via CTRL+ALT+BREAK keys)
- `vic20.peek(address)`
- `vic20.poke(address, data)`

Re: vic20-emu (another emulator)

Posted: Sat Jul 18, 2020 10:18 am
by nippur72
you can also emulate a joystick with cursor keys + space, toggling via "SCROLL LOCK" key

Re: vic20-emu (another emulator)

Posted: Sat Jul 18, 2020 2:38 pm
by chysn
Cool, I'll play around with it!

How about enabling expansion options? If there's documentation somewhere, I'll shut up with all the questions :D

Is that what config() does?

Re: vic20-emu (another emulator)

Posted: Sat Jul 18, 2020 3:19 pm
by chysn
nippur72 wrote: Sat Jul 18, 2020 10:18 am you can also emulate a joystick with cursor keys + space, toggling via "SCROLL LOCK" key
I don't have a Scroll Lock key, so I might not be able to do any joystick things.

I frequently encounter stability issues. For example, I was typing in a program and the system sort of locked up. The cursor is still blinking, but it's unresponsive. Earlier, the editor sort of freaked out and typed %"%"%" over and over again and then wouldn't respond. When this happens, vic20.reset() resets the emulator, but does not correct the responsiveness issue.

I noticed that SHFLAG ($28d) does not register Shift. For example, try

Code: Select all

10 PRINT PEEK(653):GOTO 10
The result captures Commodore and CTRL, but not Shift.

I'm sure you're in the early stages of this, and it shows promise.

If there's any way to dump state in the JS console for your review, I'd be happy to send it to you.

Re: vic20-emu (another emulator)

Posted: Sun Jul 19, 2020 12:39 am
by nippur72
as for the SCROLL LOCK key, I will ad another shortcut. By the way what keyboard do you have?

I'm aware of the problems you described, they are not related to the emulator itself, but to the keyboard emulation. Currently there is a "logical" keyboard, meaning that ASCII symbols are translated into VIC 20 hardware keys. This has the advantage of working with any keyboard layout (english, italian etc), e.g. what you type is what you see, but SHIFT has to be handled separately and causes glitches when a shifted symbols produce a non-shifted vic 20 key.

The alternative I'm considering is to emulate an "hardware" keyboard: most symbols won't match but they will appear in the same keyboard row and column of the original vic20.

Yes, "vic20.config(n)" is what lets you change the memory configuration. I've to check because it seems to me that the 3K expansion config is missing.

P.S. I've drastically improved the audio emulation, now it can run Berzerk MMX+

Re: vic20-emu (another emulator)

Posted: Sun Jul 19, 2020 4:08 am
by nippur72
for the joystick you can use the Javascript command:

vic20.emu_joy(true);

Re: vic20-emu (another emulator)

Posted: Sun Jul 19, 2020 7:27 am
by chysn
nippur72 wrote: Sun Jul 19, 2020 4:08 am for the joystick you can use the Javascript command:

vic20.emu_joy(true);
Neat! I have a MacBook Pro keyboard.

Re: vic20-emu (another emulator)

Posted: Sun Jul 19, 2020 7:45 am
by Noizer
Nice. But who need another soft emulator when the answer is FPGA? Why not complete the vicy cores?

Re: vic20-emu (another emulator)

Posted: Sun Jul 19, 2020 9:42 am
by chysn
Noizer wrote: Sun Jul 19, 2020 7:45 am Nice. But who need another soft emulator when the answer is FPGA? Why not complete the vicy cores?
You're talking about this as if nippur72 would have otherwise been able to spend his or her time furthering the FPGA cause had it not been for this pesky emulator project getting in the way. That's not necessarily the case.

The way I see it, there's lots of value to continued emulator development, as long they bring something new to the game. For example, this project has the advantage of being platform-agnostic. Also, I can run multiple emulations at a time, which I cannot do with VICE for macOS. I cannot drag .prg files onto VICE, only .d64 files, which isn't hard but does add some friction to the process. So there are already some advantages to this.

Currently, it's pretty severely crippled. I don't think I've gone more than five minutes of use without the emulator giving up on accepting keyboard input. But that's why we have people try things.

Re: vic20-emu (another emulator)

Posted: Sun Jul 19, 2020 10:47 am
by groepaz
I cannot drag .prg files onto VICE, only .d64 files
that should work just fine in a recent VICE :)

Re: vic20-emu (another emulator)

Posted: Sun Jul 19, 2020 11:34 am
by chysn
groepaz wrote: Sun Jul 19, 2020 10:47 am
I cannot drag .prg files onto VICE, only .d64 files
that should work just fine in a recent VICE :)
Oh, sweet, I'll update and give it a shot!

Update: Well, it sort of works. Dragging a .prg into VICE loads the dragged program; but it resets the emulator and removes previously-dragged .prg files from memory.

Re: vic20-emu (another emulator)

Posted: Sun Jul 19, 2020 2:32 pm
by DarwinNE
That's a cool emulator. I tried it with a small game I wrote, Alien Invasion:

http://sleepingelephant.com/ipw-web/bul ... 9&p=102004

It works quite well, but the bottom part of the screen is partially cut. This is probably due to the particular screen layout I used, but people that played to the game never reported that the spaceship was off-screen on real hardware (both PAL and NTSC), at least with reasonably good TV's.

EDIT: on the other hand, Cavern Explorer does not seems to work properly :(

http://sleepingelephant.com/ipw-web/bul ... 2&p=102571

Re: vic20-emu (another emulator)

Posted: Sun Jul 19, 2020 4:38 pm
by Mike
chysn wrote:I cannot drag .prg files onto VICE, only .d64 files
groepaz wrote:that should work just fine in a recent VICE :)
chysn wrote:Oh, sweet, I'll update and give it a shot!

Update: Well, it sort of works. Dragging a .prg into VICE loads the dragged program; but it resets the emulator and removes previously-dragged .prg files from memory.
More details to be found here: How to start .prg files in VICE.