Go Down

Topic: Arduino 6502 emulator + BASIC interpreter (Read 48419 times) previous topic - next topic

janost

It was Amiga for me :)

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: [Select]

  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);
  }

pito

#76
Jul 01, 2014, 08:49 pm Last Edit: Jul 01, 2014, 09:17 pm by pito Reason: 1
Ok, it seems it boots:
Code: [Select]
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();
 }
}

janost

#77
Jul 01, 2014, 09:30 pm Last Edit: Jul 01, 2014, 10:35 pm by janost Reason: 1
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: [Select]

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


Results in the attached picture :)

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.


pito

#78
Jul 01, 2014, 10:52 pm Last Edit: Jul 01, 2014, 10:53 pm by pito Reason: 1
Code: [Select]
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);
 }
}



janost


Code: [Select]
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. :)

pito

#80
Jul 01, 2014, 11:07 pm Last Edit: Jul 01, 2014, 11:18 pm by pito Reason: 1
It works, but I would prefer a standard i/o.. :)
PS: you may see a snip of the screen does not work properly as it continuously rewrites it (see the line with "4")..

janost


It works, but I would prefer a standard i/o.. :)
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.

pito


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.. :)

janost

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.

janost

#84
Jul 03, 2014, 07:37 pm Last Edit: Jul 03, 2014, 07:40 pm by janost Reason: 1
The C64 textmode now support full color on the 2.2" TFT.
Border, background and character colors.

janost

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

But it works :)

http://www.youtube.com/watch?v=NvQe6eg5_hQ


janost

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


pito

#87
Jul 03, 2014, 08:20 pm Last Edit: Jul 03, 2014, 08:22 pm by pito Reason: 1
The C64 has an 6510 inside. So we need to enhance the emulator somehow :)
Try to run this on the DUE, how long does it take..
Code: [Select]

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

janost

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

janost


The C64 has an 6510 inside. So we need to enhance the emulator somehow :)
Try to run this on the DUE, how long does it take..
Code: [Select]

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.

Go Up