Page 2 of 3

Re: shadowVIC – a lightweight VIC-20 emulator

Posted: Tue Oct 27, 2015 3:15 am
by Misfit
Meanwhile in Finland..
Pew.. Pew.. PePePew...

Image

Re: shadowVIC – a lightweight VIC-20 emulator

Posted: Tue Oct 27, 2015 3:56 am
by pixel
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:

Re: shadowVIC – a lightweight VIC-20 emulator

Posted: Wed Oct 28, 2015 2:14 am
by pixel
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

Re: shadowVIC – a lightweight VIC-20 emulator

Posted: Wed Oct 28, 2015 9:02 am
by pixel
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.

Re: shadowVIC – a lightweight VIC-20 emulator

Posted: Wed Oct 28, 2015 1:07 pm
by Mike
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.

Re: shadowVIC – a lightweight VIC-20 emulator

Posted: Wed Oct 28, 2015 1:23 pm
by pixel
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!

Re: shadowVIC – a lightweight VIC-20 emulator

Posted: Wed Oct 28, 2015 1:47 pm
by pixel
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)?

Re: shadowVIC – a lightweight VIC-20 emulator

Posted: Wed Oct 28, 2015 2:04 pm
by Mike
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.

Re: shadowVIC – a lightweight VIC-20 emulator

Posted: Wed Oct 28, 2015 2:13 pm
by pixel
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.

Re: shadowVIC – a lightweight VIC-20 emulator

Posted: Thu Oct 29, 2015 2:08 am
by pixel
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?

Re: shadowVIC – a lightweight VIC-20 emulator

Posted: Thu Oct 29, 2015 3:01 am
by Mike
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;

Re: shadowVIC – a lightweight VIC-20 emulator

Posted: Sat Oct 31, 2015 5:43 am
by pixel
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.

Re: shadowVIC – a lightweight VIC-20 emulator

Posted: Tue Dec 01, 2015 12:16 pm
by majikeyric
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

Re: shadowVIC – a lightweight VIC-20 emulator

Posted: Wed Dec 02, 2015 12:05 am
by pixel
Oh. You're absolutely right. Thanks for your contribution! :D

Re: shadowVIC – a lightweight VIC-20 emulator

Posted: Sat Apr 16, 2016 8:09 pm
by pixel
The RTS instruction has been fixed. The address on the stack has to be off by one. Still doesn't run BASIC programs, tho. :(