Go Down

Topic: Apple 1 emulator (Read 5011 times) previous topic - next topic

petersieg

Jan 11, 2015, 08:31 pm Last Edit: Jan 11, 2015, 08:32 pm by petersieg
1st draft of a quick hacked apple one emulator based on arduino_6502 from miker00lz.
I am NOT at all a c programmer! Needs absolutely improvements.
Also apple 1 BIOS starts at F000 or FF00? Ram size is still old value from orig. project and should be set
to 4kb I think.

1st things seem to work despite that. I used arduino pro 328p 16M with 9600 8N1.

Link to orig. project:
http://forum.arduino.cc/index.php?topic=193216.0

Peter

bperrybap

Apple 1 ??? There were not very many of those ever sold.
For the Apple ][ ,
if you look in the "Red Book" technical manual,
you can see the full listing of the apple 2 system monitor code
and it starts at 0xf800

--- bill

petersieg

Thx. But apple II are not of my interest right now ;-)

Anyway. Now with apple basic at 0xE000.

However. I have an issue that system hangs if I increase RAM size above orig. code 1536?!
(In cpu.h right at top lines: #define RAM_SIZE 1536)

Why? I would need 4096 for the apple 1.

Using arduino pro with Atmega328p (so has 8k SRam - right?)

Thx, Peter

bperrybap


petersieg

Arrgh. Thx. Somehow I was under the (false) meaning, the 328 had 8k sram..
Just tried same code (just RAM size set to 4096) on an arduino Mega 2560 - and it works!
Should work on normal Mega as well, since 1280 has also 8k ram.

 :)

Now I have a working apple 1 emulator.  :smiley-mr-green:

I think I still have to look in apple char vs. ascii char conversion.. but that may come next..

Thx, Peter

bperrybap

something like?

Code: [Select]
a1char = ((asciichar & 0x5f) - 0x20) ^ 0x20;


To convert from ascii code to 2513 character font index.

--- bill

petersieg

'maybe'  :o

I would like to find a comparison table (two tables aside) or something similiar..

How did you arrive at above code?

I need to convert chars coming from emulated apple 1 prior to be send out via serial and
2nd I (probably?) need to convert incoming chars from serial prior to give them to emulated apple 1 environment. Right?

thx, Peter

bperrybap

'maybe'  :o

I would like to find a comparison table (two tables aside) or something similiar..

How did you arrive at above code?

You could use a table but that is unnecessary given the similarity in the mappings.
There is no need to waste the code code space for a table lookup when they can
easily be calculated.
From the 2513 character map I was able to find (from a 2513 datasheet),
it appeared that the 2513 character set has the characters in a similar order as ASCII.
Look at the ASCII characters from 0x20 to 0x5f compared to the characters in the 2513.
The difference is that first and send group of 32 characters are flipped.
i.e. the 2513 flipped them.

To me it looks like the 2513 screwed up and mis mapped bit 4 of addressing
by accidentally flipping it. I see no need to have incorrectly mapped the characters
to the ascii set.

The 2513 only contains a partial mapping.

It also has no data for the fist 32 characters since it starts with "@".

The 2513 characters stop at ASCII 0x5f


So to map between them all you have to do is take all that into consideration.

To get from ascii to 2513 you first mask with 0x5f
which essentially converts all the lower case to upper case.
A few characters get miss mapped like ` { | } ~ DEL but then those
don't exist in the 2513. Those will get mapped to @ [ \ ] ^ _

You then subtract 0x20 to drop the ascii code down to account for the
special characters.

To handle flipping of the two groups of 32 characters all you have to do is flip
bit 4 of the character code address.

And that is how you end up with

Code: [Select]
a1char = ((asciichar & 0x5f) - 0x20) ^ 0x20;

To go the other way,
You would flip the address bit then add the 0x20.
Code: [Select]
asciichar = (a1char ^ 0x20) + 0x20;

--- bill

petersieg

Hmm..Nop. Doesn'work

Code: [Select]

  void serout(uint8_t val) {
    //Serial.print(val, HEX);
    //Serial.println(); 
    tmpkey = (val ^ 0x20) + 0x20;
    Serial.write(tmpkey);
  }
  uint8_t isakey() {
    if (Serial.available()) iskey  = 0x80;
    else iskey = 0;
    return(iskey);
  }
  uint8_t getkey() {
    tmpkey = Serial.read();
    curkey = ((tmpkey & 0x5f) - 0x20) ^ 0x20;
    return(curkey);
  }
  void clearkey() {
    curkey = 0;
  }



I got some scruwed up chars:

apple 1 emulator



œMFxxx

F is fine.
x is some other char but should be 0

Peter


bperrybap

Not sure what you are needing/wanting/trying to do.
ASCII is ASCII and I'm guessing that the apple 1 did everything in memory in ASCII
(The apple 2 did)
The funkiness is how to get from an ASCII value to a 2513 character code index value
which is at the very low level hardware level.
The conversions I gave are to go back and forth between an ascii code to a 2513 glyph index value.

In an emulator, I'm not sure that any sort of mapping like this would be necessary.

It should be easy to tell.

print the hex value for a few of the apple 1 characters without any modifications and look at the values
to see if they match the character for ASCII.

petersieg

Yes. Maybe this is really not required at all..

I now just mapping incoming lower case a-z to upper case A-Z:
Code: [Select]
    // make a-z => A-Z
    if ((curkey >= 97) && (curkey <= 122)) curkey = curkey - 0x20;


I will leave the emulator as it is for now and will do some more testing with existing programs (asm & basic).

Peter

HansjcOtten

'maybe'  :o

I would like to find a comparison table (two tables aside) or something similiar..

How did you arrive at above code?

I need to convert chars coming from emulated apple 1 prior to be send out via serial and
2nd I (probably?) need to convert incoming chars from serial prior to give them to emulated apple 1 environment. Right?

thx, Peter
No that is not necessary. The Apple 1 just uses ASCII (uppercase only).  The role of the GI 2513 is to convert a character code to a bitmap shown on the video display. For characters coming in via the keyboard the 2513 is not involved therefore.
Since your emulator does not generate a video display you can for now ignore the 2513 and all the video display hardware present in the Apple 1.
http://duinorasp.hansotten.com

petersieg

Jup.
Just loaded the 30th aniverary demo. After setting teraterm to 40 chars wide screen,
it looks like it is working ok ;-)

Does someone has some links to apple 1 software/programs.

I found already sb-projects with a1 assembler.

I also found startrek.bas - but that seems to need more the 4k ram (with basic running).
(Gives out of MEM msg from basic interpreter)

Peter

petersieg

Find attached the 30th aniversary HEX and lander.bas in the ZIP.
These are working. Just put your terminal emulation in 40 char wide mode.
startrek.bas has syntax errors at lines 230+440 and gives out of mem errors even on a due with 32k Ram?!
codebreaker maybe needs a special terminal emulation?

If you have links to make software in either HEX or basic ascii text format, please let me know.

BTW: Runs fine on arduino due with 32768 ramsize.

Peter

petersieg

#14
Jan 19, 2015, 05:05 pm Last Edit: Jan 19, 2015, 05:07 pm by petersieg
Update.
Now included: a1 assembler (c) 9/2006 San Bergmans released as freeware (Thanks!)
Link: http://www.sbprojects.com (Visit his great side!)

Switch between apple basic at 0xE000 and a1 assembler at 0xE000 is done by Pin 2.
Open/High = apple basic. GND/Low = a1 assembler
Switch is only read at startup of system/or reset.

I also included: 23-matches and lunar lander, both basic programs and microchess to be loaded into this apple 1 emulation.

I currently develop this on a arduino due. Mega should still be fine with 4k ram.

Peter

Go Up