shadowVIC – a lightweight VIC-20 emulator

You need an actual VIC.

Moderator: Moderators

User avatar
Misfit
Vic 20 Devotee
Posts: 201
Joined: Thu Nov 28, 2013 9:09 am

Re: shadowVIC – a lightweight VIC-20 emulator

Postby Misfit » Tue Oct 27, 2015 3:15 am

Meanwhile in Finland..
Pew.. Pew.. PePePew...

Image

User avatar
pixel
Vic 20 Nerd
Posts: 867
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/pixel/
Location: various
Occupation: Pan–galactic shaman

Re: shadowVIC – a lightweight VIC-20 emulator

Postby pixel » Tue Oct 27, 2015 3:56 am

LOL! Awesome! :D

Thanks to Mike, who pointed out that transfer instructions actually modify flags, the BASIC kind of boots now. With 29496.7295 bytes free. m)

EDIT: Nothing can possibly spoil my day now. :mrgreen:
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose

User avatar
pixel
Vic 20 Nerd
Posts: 867
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/pixel/
Location: various
Occupation: Pan–galactic shaman

Re: shadowVIC – a lightweight VIC-20 emulator

Postby pixel » Wed Oct 28, 2015 2:14 am

Thanks to Dane Bills who put in an incredible lot of time to port Panicman, BASIC boots now.

A tiny VIA emulation went in, so NMIs are enabled or disabled the classic way now. :D
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose

User avatar
pixel
Vic 20 Nerd
Posts: 867
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/pixel/
Location: various
Occupation: Pan–galactic shaman

Re: shadowVIC – a lightweight VIC-20 emulator

Postby pixel » Wed Oct 28, 2015 9:02 am

If someone could provide a quick tutorial about how to load and start BASIC programs from assembly – that would be nice. I find the idea of turning BASIC programs into stand–alone applications quite fascinating.
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose

User avatar
Mike
Herr VC
Posts: 2951
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: shadowVIC – a lightweight VIC-20 emulator

Postby Mike » Wed Oct 28, 2015 1:07 pm

I usually use this code snippet:

Code: Select all

 LDA #$01
 LDX $BA              ; last used device. could be fixed to a constant (like 8)
 LDY #$00
 JSR $FFBA            ; SETLFS
 LDA #Name_End - Name
 LDX #Name MOD 256
 LDY #Name DIV 256
 JSR $FFBD            ; SETNAM
 LDA #$00
 LDX $2B
 LDY $2C
 JSR $FFD5            ; LOAD (forced to BASIC start, as secondary address in SETLFS is 0)
 STX $2D
 STY $2E
 JSR $C533            ; re-link lines
 JSR $C659            ; CLR, reset TXTPTR
 JMP $C7AE            ; execute next statement (a.k.a. "RUN")
.Name
 EQUS "MAIN"
.Name_End

The rest of the system should already have been initialised so far it got to the READY prompt.

User avatar
pixel
Vic 20 Nerd
Posts: 867
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/pixel/
Location: various
Occupation: Pan–galactic shaman

Re: shadowVIC – a lightweight VIC-20 emulator

Postby pixel » Wed Oct 28, 2015 1:23 pm

You're awesome. Meant it a little differently, though: the ready-prompt is there and the program is loaded into memory via the emulator. That's where it came to an halt. With your snippet it could also be done of course. Thanks!
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose

User avatar
pixel
Vic 20 Nerd
Posts: 867
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/pixel/
Location: various
Occupation: Pan–galactic shaman

Re: shadowVIC – a lightweight VIC-20 emulator

Postby pixel » Wed Oct 28, 2015 1:47 pm

Ermh… just a moment please. If I get the modularity of the kernel right, is this:

Code: Select all

   JSR $C533            ; re-link lines
    JSR $C659            ; CLR, reset TXTPTR
    JMP $C7AE            ; execute next statement (a.k.a. "RUN")

enough as long as I set the basic and the variable start (assuming that the array area is initialized based on the variable start anyway)?
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose

User avatar
Mike
Herr VC
Posts: 2951
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: shadowVIC – a lightweight VIC-20 emulator

Postby Mike » Wed Oct 28, 2015 2:04 pm

You should make sure, that the byte before the BASIC start is initialised to 0. Otherwise, yes: JSR $C659 also takes care of all the other pointers that refer to $2B/$2C, $2D/$2E and(!) $37/$38.

User avatar
pixel
Vic 20 Nerd
Posts: 867
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/pixel/
Location: various
Occupation: Pan–galactic shaman

Re: shadowVIC – a lightweight VIC-20 emulator

Postby pixel » Wed Oct 28, 2015 2:13 pm

Mike wrote:You should make sure, that the byte before the BASIC start is initialised to 0. Otherwise, yes: JSR $C659 also takes care of all the other pointers that refer to $2B/$2C, $2D/$2E and(!) $37/$38.

Oh, that's nice. Thanks again. Sounds so simple that picovic might start PRG files tomorrow morning.
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose

User avatar
pixel
Vic 20 Nerd
Posts: 867
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/pixel/
Location: various
Occupation: Pan–galactic shaman

Re: shadowVIC – a lightweight VIC-20 emulator

Postby pixel » Thu Oct 29, 2015 2:08 am

I loaded the program to its starting address, cleared the byte right in front of it, copied the first two or four bytes to $2b, did the two calls and the jump – and it returned to the prompt right away. Well, code says more than a thousand words:

Code: Select all

byte basic_starter[] = {
    0x20, 0x33, 0xc5,  /* jsr $c533 */
    0x20, 0x59, 0xc6,  /* jsr $c659 */                                         
    0x4c, 0xae, 0xc7   /* jmp $c7ae */
};

void
vic20_run_prg (char * path)
{
    int i;
    address load_address;

    vic20_init (m[0xfffc] + (m[0xfffd] << 8));
    for (i = 0; i < 500000; i++)
        vic20_step ();
    /* READY, Daddy! */

    load_address = load_prg (path);
    m[load_address - 1] = 0;
    memcpy (&m[0x2b], &m[load_address], 2);
    memcpy (&m[0xa000], basic_starter, sizeof (basic_starter));
    pc = 0xa000;
    vic20_run ();
}

Got it right?
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose

User avatar
Mike
Herr VC
Posts: 2951
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: shadowVIC – a lightweight VIC-20 emulator

Postby Mike » Thu Oct 29, 2015 3:01 am

Good morning! :mrgreen:

pixel wrote:

Code: Select all

m[load_address - 1] = 0;

That is being taken care by the BASIC cold start already. I just mentioned it because it can easily get forgotten with an 'inject-to-RAM' technique, when the ZP is already initialised, but BASIC hasn't been cold started still.

Code: Select all

memcpy (&m[0x2b], &m[load_address], 2);

Here's the rub: you init the BASIC start from the 2 bytes at the beginning of a BASIC program. That's either the link pointer to the next line or two 0's to signify "end of program" (this would actually mean an empty BASIC program here).

What is needed is another version of load_prg(), which ignores the load address of the *.prg file, and instead loads the file to a given address (here: the pointer contained in $2B/$2C) and which also returns the address to the (free) byte following the last byte loaded to VIC RAM. That pointer needs to be copied to $2D/$2E before calling basic_starter:

Code: Select all

end_address = load_prg_2(path, 256*m[0x2c]+m[0x2b]);
m[0x2d] = end_address % 256;
m[0x2e] = end_address / 256;

User avatar
pixel
Vic 20 Nerd
Posts: 867
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/pixel/
Location: various
Occupation: Pan–galactic shaman

Re: shadowVIC – a lightweight VIC-20 emulator

Postby pixel » Sat Oct 31, 2015 5:43 am

Still don't get it to run. Pushed it onto Github anyway (src/prg-loader.c src/vic-20.c). Must still be something else wrong.
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose

User avatar
majikeyric
Vic 20 Devotee
Posts: 237
Joined: Fri Oct 24, 2014 2:08 pm
Website: http://majikeyric.free.fr
Location: France

Re: shadowVIC – a lightweight VIC-20 emulator

Postby majikeyric » Tue Dec 01, 2015 12:16 pm

Hi!

It seems there are incorrect results with the BCD ADD.
For example $51+$48 gives $f9 and not $99.

I would rather do this (in e_adc() , line 190 in 6502.c)

Code: Select all

#ifndef CPU_2A03
    if (d) {
        e = (a & 0x0f) + (r & 0x0f) + c;
        if (e > 0x09)
            e += 0x06;
        e += (a & 0xf0) + (r & 0xf0);

        c = 0;
        if ( (e & 0xf0) > 0x90) {
            e += 0x60;
            c = 1;
        }
    } else {
#endif
Last edited by majikeyric on Wed Dec 02, 2015 3:38 am, edited 1 time in total.

User avatar
pixel
Vic 20 Nerd
Posts: 867
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/pixel/
Location: various
Occupation: Pan–galactic shaman

Re: shadowVIC – a lightweight VIC-20 emulator

Postby pixel » Wed Dec 02, 2015 12:05 am

Oh. You're absolutely right. Thanks for your contribution! :D
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose

User avatar
pixel
Vic 20 Nerd
Posts: 867
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/pixel/
Location: various
Occupation: Pan–galactic shaman

Re: shadowVIC – a lightweight VIC-20 emulator

Postby pixel » Sat Apr 16, 2016 8:09 pm

The RTS instruction has been fixed. The address on the stack has to be off by one. Still doesn't run BASIC programs, tho. :(
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose


Return to “Emulation and Cross Development”

Who is online

Users browsing this forum: No registered users and 1 guest