vic20-emu (another emulator)

You need an actual VIC.

Moderator: Moderators

User avatar
srowe
Vic 20 Scientist
Posts: 1340
Joined: Mon Jun 16, 2014 3:19 pm

Re: vic20-emu (another emulator)

Post by srowe »

nippur72 wrote: Tue Sep 01, 2020 2:50 am Does anybody know if there is a system routine I can call for rebuilding links?

Code: Select all

LNKPRG  = $C533			; rebuild BASIC line chaining
nippur72
de Lagash
Posts: 574
Joined: Thu Sep 07, 2006 8:35 am

Re: vic20-emu (another emulator)

Post by nippur72 »

srowe wrote: Tue Sep 01, 2020 3:17 am

Code: Select all

LNKPRG  = $C533			; rebuild BASIC line chaining
thanks! I was able to create a "relinked" version of the prg file, by first loading it and then doing SYS 50483 ($c533).

Now I have to think how to do that automatically from within the emulator (it's not easy because you can't simply call a routine).
User avatar
srowe
Vic 20 Scientist
Posts: 1340
Joined: Mon Jun 16, 2014 3:19 pm

Re: vic20-emu (another emulator)

Post by srowe »

The process is very simple, you build a chain by walking the current line to its end defined by a NUL character. The end of the chain is a null address.
BASIC-link.png
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: vic20-emu (another emulator)

Post by chysn »

nippur72 wrote: Tue Sep 01, 2020 2:50 am Does anybody know if there is a system routine I can call for rebuilding links?
See Mike's second post at this thread:

viewtopic.php?f=2&t=9724

This is what I use in wAx when the user switches the BASIC stage to another page number. You have to do the rechain, and then also set the start-of-variables pointer.

However, I think you've clearly identified that it's the actual prg file that's screwed up, not your emulator. I'd think the best approach here would be to do nothing. If you start changing your code to accommodate something that's broken in the first place, you'll eventually code yourself into a nasty corner. :)
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
srowe
Vic 20 Scientist
Posts: 1340
Joined: Mon Jun 16, 2014 3:19 pm

Re: vic20-emu (another emulator)

Post by srowe »

Here's a fixed version
Attachments
fixed_meanies.zip
(2.19 KiB) Downloaded 58 times
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: vic20-emu (another emulator)

Post by Mike »

chysn wrote:However, I think you've clearly identified that it's the actual prg file that's screwed up, not your emulator.
No, it is perfectly legal for a BASIC program to come around with 'badly-linked' link pointers. That happens as soon as you load a BASIC program to another BASIC start address than where it was saved from. That's the reason the re-link routine gets called inside the LOAD command (the load routine in the KERNAL does not touch the loaded memory contents).
I'd think the best approach here would be to do nothing. If you start changing your code to accommodate something that's broken in the first place, you'll eventually code yourself into a nasty corner. :)
The emulator ought to reproduce the behaviour of the original machine + OS as close as possible. In the case of the BASIC LOAD command, when the KERNAL load routine has finished and the LOAD command was issued in direct mode, it *does* re-link the BASIC program and the emulator should do likewise with a inject-to-RAM method when it autostarts a *.prg file.
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: vic20-emu (another emulator)

Post by chysn »

Why would an emulator need to explicitly do this? Is it not running the actual BASIC ROM code on emulated hardware?

Or does the autostart bypass or replace LOAD somehow?
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: vic20-emu (another emulator)

Post by Mike »

chysn wrote:Why would an emulator need to explicitly do this? Is it not running the actual BASIC ROM code on emulated hardware?
Inject-to-RAM is a fairly standard technique for emulators to avoid the intricacies of emulating the peripheral completely 'just' for transferring a file into RAM. In that case the result is what matters.

VICE can employ the same technique during autostart (it's in the options), but it is realised as KERNAL trap. When the 'vetted' KERNAL load routine then returns to the BASIC interpreter, the LOAD command still executes the re-linker and sets the pointers.
Or does the autostart bypass or replace LOAD somehow?
I have hinted at that in this and my preceding post: you need to distinguish between what is at the responsibility of BASIC and what is at the responsibility of the KERNAL. The KERNAL load routine just transfers the file to memory, nothing else. Inject-to-RAM does the same in the end. BASIC then is responsible to establish all pointers and re-links the BASIC program if LOAD was issued in direct mode.

If the user (or the emulator) then issues a RUN command, there needs to be a correctly linked BASIC program at the BASIC start, with all relevant pointers (BASIC start, start of variables, end of BASIC memory) correctly set.
nippur72
de Lagash
Posts: 574
Joined: Thu Sep 07, 2006 8:35 am

Re: vic20-emu (another emulator)

Post by nippur72 »

is that the difference between LOAD ,,0 and LOAD ,,1 ? My guess is that ",,0" loads the program at the current basic start and then re-links it, while ",,1" just loads the program at the original address without doing anything. Is that so?
User avatar
srowe
Vic 20 Scientist
Posts: 1340
Joined: Mon Jun 16, 2014 3:19 pm

Re: vic20-emu (another emulator)

Post by srowe »

No, the BASIC LOAD command unconditionally relinks.
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: vic20-emu (another emulator)

Post by Mike »

I had to check this against the ROM. The relevant part starts at $E1A1 and $E1B5 JSR $E476 calls a knapsack with a JSR $C533. That sequence was streamlined in the C64 ROM, BTW. Which means, the LOAD command indeed always re-links, not only in direct mode.

The re-link procedure however *always* begins at the current BASIC start. If a file is loaded with secondary address ",1" (i.e. absolute load) and the file doesn't end up at the BASIC start, the re-link procedure doesn't touch the loaded contents.

In hindsight, it needed to be done this way: when LOAD is used to chain a BASIC program from program mode that needs to work even when the chained-to BASIC program was saved from another BASIC start address. :!:
nippur72
de Lagash
Posts: 574
Joined: Thu Sep 07, 2006 8:35 am

Re: vic20-emu (another emulator)

Post by nippur72 »

yes that makes sense, thanks.

I may add this feature in the software emulator, so to mimic a proper kernal LOAD. Not absolutely needed, but just for fun. :D

Unfortunately in the FPGA it's much difficult to implement ... it requires a complex state machine, I don't think it's worth of.
nippur72
de Lagash
Posts: 574
Joined: Thu Sep 07, 2006 8:35 am

Re: vic20-emu (another emulator)

Post by nippur72 »

A small update: the emulator now accepts the "?load=url" querystring parameter where "url" is any external URL that points to a VIC20 .prg file. This way you can load programs that are hosted externally.

E.g.:

Code: Select all

https://nippur72.github.io/vic20-emu/?joy=1&load=http://www.zimmers.net/anonftp/pub/cbm/vic20/games/unexpanded/3D+Silicon+Fish.prg
live: https://nippur72.github.io/vic20-emu/?j ... n+Fish.prg
nippur72
de Lagash
Posts: 574
Joined: Thu Sep 07, 2006 8:35 am

Re: vic20-emu (another emulator)

Post by nippur72 »

The emulator now supports USB gamepads :D
Post Reply