Pages: 1 ... 4 5 [6] 7 8 ... 10   Go Down
Author Topic: Arduino 6502 emulator + BASIC interpreter  (Read 29013 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
God Member
*****
Karma: 6
Posts: 524
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It was Amiga for me smiley

I used this when I first began with the VIC-20 EMU
It write out the videomemory to serial so you can at least see if it boots.

Code:
  for (byte y=0;y<23;y++) {
    for (byte x=0;x<22;x++) {
      for (byte z=0;z<100;z++) {
      exec6502();
      }
     petscii=videomem[eeaddress++];
     if (petscii<32) {
      petscii=petscii+64;
     }
     USART_write(petscii);
    }
    USART_write(10);
    USART_write(13);
  }
Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2073
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, it seems it boots:
Code:
void loop () {
//  exec6502(100); //if timing is enabled, this value is in 6502 clock ticks. otherwise, simply instruction count.
//  if (Serial.available()) {
//    curkey = Serial.read() & 0x7F;
//  }
//}
  int address = 0;
  for (int y=0;y<25;y++) {
    for (int x=0;x<40;x++) {
      exec6502(100);
     unsigned char petscii=VRAM[address++];
     if (petscii<32) {
      petscii=petscii+64;
     }
     Serial.write(petscii);
    }
    Serial.println();
  }
}


* c64.jpg (13.11 KB, 407x239 - viewed 78 times.)
« Last Edit: July 01, 2014, 02:17:12 pm by pito » Logged

Offline Offline
God Member
*****
Karma: 6
Posts: 524
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, that's great.

Now to the input,
Since interrupts are not running, to get characters in as they was typed on the non existent keyboard, you need to "poke" those into the keyboard buffer.

This code:

Code:
void loop() {
  exec6502();
  RAM[198]=1;
  RAM[631]=65;
}

Results in the attached picture smiley

So basically you remove the 0xF004 and getval from the read6502 function.

The you add an "If serial.available" in the loop function and poke the available character into the keyboard buffer.

 


* kbdybuf.jpg (226.94 KB, 900x507 - viewed 75 times.)
« Last Edit: July 01, 2014, 03:35:16 pm by janost » Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2073
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void loop () {

  int v_address = 0;
  Serial.write(27);   // Move to Home
  Serial.write("[H");
  
  for (int y=0;y<25;y++) {
    for (int x=0;x<40;x++) {
      exec6502(100);
      if (Serial.available()) {
     curkey = Serial.read() & 0x7F;
   RAM[198]=1;
   RAM[631]=curkey;
  }
     unsigned char petscii=VRAM[v_address++];
     if (petscii<32) petscii=petscii+64;
     Serial.write(petscii);
    }
    Serial.write(13);
    Serial.write(10);
  }
}



* c64.jpg (22.42 KB, 445x441 - viewed 53 times.)
« Last Edit: July 01, 2014, 03:53:45 pm by pito » Logged

Offline Offline
God Member
*****
Karma: 6
Posts: 524
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void loop () {

  int v_address = 0;
  Serial.write(27);   // Move to Home
  Serial.write("[H");
  
  for (int y=0;y<25;y++) {
    for (int x=0;x<40;x++) {
      exec6502(100);
      if (Serial.available()) {
     curkey = Serial.read() & 0x7F;
   RAM[198]=1;
   RAM[631]=curkey;
  }
     unsigned char petscii=VRAM[v_address++];
     if (petscii<32) petscii=petscii+64;
     Serial.write(petscii);
    }
    Serial.write(13);
    Serial.write(10);
  }
}



Cool
You're able to run it. smiley
Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2073
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It works, but I would prefer a standard i/o.. smiley
PS: you may see a snip of the screen does not work properly as it continuously rewrites it (see the line with "4")..


* C64_1.jpg (38.68 KB, 427x536 - viewed 68 times.)

* C64_2.jpg (182.71 KB, 431x537 - viewed 50 times.)
« Last Edit: July 01, 2014, 04:18:41 pm by pito » Logged

Offline Offline
God Member
*****
Karma: 6
Posts: 524
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It works, but I would prefer a standard i/o.. smiley
PS: you may see a snip of the screen does not work properly as it continuously rewrites it (see the line with "4")..


Could be because the screen scrolled up?

It's not a good way to continuously rewrite the whole screen.
Causes a lot of data to be transmitted.

And CBM's don't use ascii in their videomemory, it's petscii.
My check is a quick and dirty hack to convert it to ascii.
It doesn't cover all codes.
 
Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2073
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's not a good way to continuously rewrite the whole screen.
Causes a lot of data to be transmitted.
..
Yea, sending deltas only will do better.. But nice to see it works. And faster than the original.. smiley
Logged

Offline Offline
God Member
*****
Karma: 6
Posts: 524
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'll build it on a 1284 and use the C64 ROMs. They are more stable than PET ROMs but exactly the same V2 Basic.
And they can run down to 2K RAM without problems.

Also it supports both color and mono text/graphics.
Logged

Offline Offline
God Member
*****
Karma: 6
Posts: 524
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The C64 textmode now support full color on the 2.2" TFT.
Border, background and character colors.


* colorDUE_C64.jpg (180.12 KB, 900x507 - viewed 91 times.)
« Last Edit: July 03, 2014, 12:40:25 pm by janost » Logged

Offline Offline
God Member
*****
Karma: 6
Posts: 524
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I use soft-SPI on the due because of hysterical reasons so the screen can be very much faster.

But it works smiley



Logged

Offline Offline
God Member
*****
Karma: 6
Posts: 524
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is the memorymap if you want to emulate a C64.
Or POKE something into your emulated C64.


* C64 MemoryMap.rtf (185.29 KB - downloaded 41 times.)
Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2073
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The C64 has an 6510 inside. So we need to enhance the emulator somehow smiley
Try to run this on the DUE, how long does it take..
Code:
5  REM TRIGONOMETRIC FUNCTIONS TEST 0..89 DEGREE
10 PH = 3.141592653/2.0
15 REM DEFINE ARCSIN AND ARCCOS
20 DEF FN ASN(X) = ATN(X/SQR(1.0-X*X))
30 DEF FN ACS(X) = PH-ATN(X/SQR(1.0-X*X))
35 REM TR, TD - TO RAD, TO DEG
40 TR = 3.141592653 / 180.0
50 TD = 180.0 / 3.141592653
55 REM INPUT IN DEGREE (1..89)
60 FOR D = 0 TO 89
70 T = SIN(TR*D)
72 T = COS(TR*T)
74 T = TAN(TR*T)
76 T = TD*ATN(T)
80 T = TD*FN ACS(T)
90 T = TD*FN ASN(T)
100 PRINT D; "="; T; " DELTA="; T-D
110 NEXT D
120 END
« Last Edit: July 03, 2014, 01:22:49 pm by pito » Logged

Offline Offline
God Member
*****
Karma: 6
Posts: 524
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Not much difference to a 6502 besides the IO port at $0000 and $0001.

That IO port control memory mapping of the 64K RAM and ROMs
Logged

Offline Offline
God Member
*****
Karma: 6
Posts: 524
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The C64 has an 6510 inside. So we need to enhance the emulator somehow smiley
Try to run this on the DUE, how long does it take..
Code:
5  REM TRIGONOMETRIC FUNCTIONS TEST 0..89 DEGREE
10 PH = 3.141592653/2.0
15 REM DEFINE ARCSIN AND ARCCOS
20 DEF FN ASN(X) = ATN(X/SQR(1.0-X*X))
30 DEF FN ACS(X) = PH-ATN(X/SQR(1.0-X*X))
35 REM TR, TD - TO RAD, TO DEG
40 TR = 3.141592653 / 180.0
50 TD = 180.0 / 3.141592653
55 REM INPUT IN DEGREE (1..89)
60 FOR D = 0 TO 89
70 T = SIN(TR*D)
72 T = COS(TR*T)
74 T = TAN(TR*T)
76 T = TD*ATN(T)
80 T = TD*FN ACS(T)
90 T = TD*FN ASN(T)
100 PRINT D; "="; T; " DELTA="; T-D
110 NEXT D
120 END

I'll try.

The general way of measuring speed on a CBM is this.

FOR I=0 TO 1000:NEXT

That takes exactly 1 second on a 1MHZ 6502 in CBM Basic.

Make one I=1 to 10000 and clock it.

That will tell you the factor against the original.
Logged

Pages: 1 ... 4 5 [6] 7 8 ... 10   Go Up
Jump to: