6502.org Forum  Projects  Code  Resources  Tools  Forum  Log in
 
Search Search FAQ FAQ Members Members Profile Profile Log in to check your private messages Log in to check your private messages Register Register

6502/65816 emulators written in Pascal?

 
Post new topic   Reply to topic    6502.org Forum Index -> Emulation and Simulation
View previous topic :: View next topic  
Author Message
Ruud



Joined: 12 Dec 2003
Posts: 155
Location: Heerlen, NL

PostPosted: Wed Aug 15, 2007 10:32 am    Post subject: 6502/65816 emulators written in Pascal? Reply with quote

Hallo allemaal,


Various emulators I know, like VICE, are written in C. Does anyone know an emulator of a wellknown computer written in (Turbo) Pascal?

Thanks!
_________________
Code:

    ___
   / __|__
  / /  |_/     Groetjes, Ruud
  \ \__|_\
   \___|       URL: Ruud.C64.org

Back to top
View user's profile Send private message Visit poster's website
Steve__Jay



Joined: 26 Jul 2010
Posts: 4

PostPosted: Mon Jul 26, 2010 3:27 pm    Post subject: Reply with quote

groeten terug ...

as i remember, there are:

- El Dendo's ED64 from belgium
http://ed64.eldendo.be/
(Marc Dendooven)
- My Little Simulator - Mertkan Yildirimli but the link seems to be broken (or apparently withdrawn), i once tried to retrieve something but failed;
- 'Brotkästchen' a german emulator written in Pascal / Delphi, about 60 KB in size
- last but not least since April my janE6502 is in use. I beg your pardon for delayed answer ;-)

kind regards
steve
Back to top
View user's profile Send private message
BigEd



Joined: 11 Dec 2008
Posts: 397
Location: England

PostPosted: Fri Aug 06, 2010 1:11 pm    Post subject: Reply with quote

Yikes! That's the most unusual Pascal I've ever seen. Free Pascal does a reasonable job of line breaks and indentation, but I wonder if this is meant to be a de-obfuscation challenge?

Unfortunately it isn't accepted by either p2c or gpc. But, you mention it passes 100 of Wolfgang's tests, so that's very impressive. Does it fail any or was that the number you tried?

Edit: thanks for the pointer to Marc's ED64 site: that's a nice clear walkthrough of the construction of an emulator, with a free emulator as a bonus!
Back to top
View user's profile Send private message Visit poster's website
Steve__Jay



Joined: 26 Jul 2010
Posts: 4

PostPosted: Sat Aug 07, 2010 3:38 pm    Post subject: Reply with quote

Thank you for revising the emulator ..
BigEd wrote:
Yikes! That's the most unusual Pascal I've ever seen. Free Pascal does a reasonable job of line breaks and indentation, but I wonder if this is meant to be a de-obfuscation challenge?


Not intentionally Wink i needed to re-use my old ancient eprom programmer on my windows based computer, but its operating software was 6502-based, it came from an apple II and has been translated so it could run on PET and C64. First, i thought it were possible to take Vice and simply add some specific code. But the version i tested, had a bug, it froze after half an hour ("sound buffer overflow"). additionally, i dont understand much of the C programming language, my skills are limited, so i decided to make my own emulator in Delphi/pascal. I was looking for some code at http://www.zophar.net/6502.html but almost all examples from there are written in C or BASIC. Additionally, source code of most emulators seems to exceed 40 KB , that means in order to understand such code, i must read and flip *many* pages. Because i'm a little impaired with respect to my eyesight, i made a challenge out of it to put everything onto one single page (72 lines with 80 characters each), so i had to think very much to get it condensed, and do less typewriting in front of monitor. thank you for your patience with missing indents ...

There is an older , more object oriented (and more faulty) version , too. Perhaps you might try it:
http://home.foni.net/~sjanda/u6502b_ver05alpha_ObjectOriented.pas

It contains much human-readable information, indents and commentaries in brackets.

In order to check it out, you need to have a variable containing the processor:
... uses u6502b...
var m6502: T6502b ; Start:WORD;
begin
m6502:=T6502b.create; {Initialization}
{put some opcode into memory , e.g. LDA #$55}
m6502.mr.mM[$1000]:= $A9;
m6502.mr.mM[$1001]:= $55;
{set JAM = true causes emulation to stop after a single step}
m6502.JM :=1;
Start:= $1000;
{invoke emulation in single step mode}
m6502.SYS(start,0);
...
Showmessage('Accumulator contains now:'+ InttoHex(m6502.mr.AC,2));
...
m6502.free;
end;

Quote:

Unfortunately it isn't accepted by either p2c or gpc. But, you mention it passes 100 of Wolfgang's tests, so that's very impressive. Does it fail any or was that the number you tried?

There are two files involved, a core 6502 emulator and a c64 emulator which uses it. The latter needs some Win32-specific stuff, but the first is kept pretty portable.

I tried to get gpc to work under Cygwin, but my HelloWorld (hello.pas) won't compile. It complains the file "as" were missing, but i don't know where to start. It seems that one needs a Gnu C Compiler in order to check out the pascal one Sad

P2C may not work because janE6502 makes heavy use of "sets" which are a very pascal-like feature. To my limited knowledge, C doesnt have sets. possibly you might want to translate them manually into structs, arrays (preferred) or something alike.

I tried more than hundred,but it was tedious work. Some of Wolfgang's tests are very C64-specific. BRK for example, doesnt work properly. And every test program has to be invoked manually, in direct mode via menu, because i didnt implement I/O trapping. None of the tests is able to load the next test via daisy chain; rather they complain a basic error (illegal quantity because of the floppy disk primary address "8") after each test because the Load command is missing. On the other hand, i saved almost 99% of code space , source and object code either.
Quote:

thanks for the pointer to Marc's ED64 site: that's a nice clear walkthrough of the construction of an emulator, with a free emulator as a bonus!

If you need an emulator which is able to detect time expensive loops and give control back to another program outside during waits, you might consider my program useful.
Code:
label_doomsday1; LDA PERIPHERAL_PORT
                 CMP #some_input_key
                BNE doomsday

In such cases, e.g. El Dendo's program (and many other) would use up 100% CPU Load. But i needed such an "idle" feature because i wish to limit programming times for an EPROM with a timing base from outside the emulated 6502 system.


Last edited by Steve__Jay on Sat Aug 07, 2010 3:56 pm; edited 1 time in total
Back to top
View user's profile Send private message
BigEd



Joined: 11 Dec 2008
Posts: 397
Location: England

PostPosted: Sat Aug 07, 2010 3:53 pm    Post subject: Reply with quote

Steve__Jay wrote:
Because i'm a little impaired with respect to my eyesight, i made a challenge out of it to put everything onto one single page (72 lines with 80 characters each), so i had to think very much to get it condensed, and do less typewriting in front of monitor.

Ah, that makes sense!

Steve__Jay wrote:

There is an older , more object oriented (and more faulty) version , too. Perhaps you might try it:
http://home.foni.net/~sjanda/6502b_ver05alpha_ObjectOriented.pas

It contains much human-readable information, indents and commentaries in brackets.

Thanks - that sounds interesting, I'd like to have a look. Unfortunately the link doesn't resolve.

Steve__Jay wrote:
I tried to get gpc to work under Cygwin, but my HelloWorld (hello.pas) won't compile. It complains the file "as" were missing, but i don't know where to start. It seems that one needs a Gnu C Compiler in order to check out the pascal one :-(

That's a fairly easy one - you need the 'binutils' package.

Steve__Jay wrote:
P2C may not work because janE6502 makes heavy use of "sets" which are a very pascal-like feature.

Actually, it hung, so something in the program wasn't understood - I tried some aggressive commenting out but didn't find a cause.

One or other of the tools I tried objected to taking the address of a packed array. Another felt it had to use some 64-bit arithmetic to calculate some expressions. Maybe not so surprising that different compilers find different things to complain about.

Steve__Jay wrote:
I tried more than hundred,but it was tedious work. Some of Wolfgang's tests are very C64-specific. BRK for example, doesnt work properly. And every test program has to be invoked manually, in direct mode via menu, because i didnt implement I/O trapping.

An heroic effort!

Steve__Jay wrote:
If you need an emulator which is able to detect time expensive loops and give control back to another program outside during waits, you might consider my program useful.
Code:
label_doomsday1; LDA PERIPHERAL_PORT
                 CMP #some_input_key
                BNE doomsday

In such cases, e.g. El Dendo's program (and many other) would use up 100% CPU Load.

Right - I found your same-branch detection code, and that seems like quite a neat solution. There was an uninitialised variable nearby spotted by one of the compilers I tried.

Cheers
Ed
Back to top
View user's profile Send private message Visit poster's website
Steve__Jay



Joined: 26 Jul 2010
Posts: 4

PostPosted: Sat Aug 07, 2010 4:10 pm    Post subject: Reply with quote

BigEd wrote:
Ah, that makes sense!

Smile
of course, i like very much to write small programs, too ...

BigEd wrote:
I'd like to have a look. Unfortunately the link doesn't resolve.


An "u" letter was missing, i edited my posting above, hope it will work now .. i would be glad to hear some feedback.

Quote:

That's a fairly easy one - you need the 'binutils' package.

Thank you much for that information ... i'm not very familiar with simulated Un*x stuff.... and they [binutils] have to match my version of cygwin , right?

Quote:

Actually, it hung, so something in the program wasn't understood - I tried some aggressive commenting out but didn't find a cause.

may i ask, did you try to compile the wholesale project file (C164.dpr or somthing like this), or the j6502.pas ?
Quote:

One or other of the tools I tried objected to taking the address of a packed array.

i fear, packed arrays will become deprecated one day ... some compilers seem to complain when fed with variant records also .. i use plenty of them ...

Quote:

Another felt it had to use some 64-bit arithmetic to calculate some expressions. Maybe not so surprising that different compilers find different things to complain about.

Thats true !
Quote:

An heroic effort!

thank you - but it needs less thinking and much more copy-pasting Wink

Quote:

Right - I found your same-branch detection code

This i consider to be a *really* heroic effort , to find such a piece of code in such an obfuscated text Wink

Quote:

There was an uninitialised variable nearby spotted by one of the compilers I tried.


Thanks for this information. Yes there are some variables not really needed, too. I inserted them in advance. Possibly some branch identification is not done perfectly well.

so long,
Steve
Back to top
View user's profile Send private message
BigEd



Joined: 11 Dec 2008
Posts: 397
Location: England

PostPosted: Sat Aug 07, 2010 4:44 pm    Post subject: Reply with quote

Steve__Jay wrote:
BigEd wrote:
I'd like to have a look. Unfortunately the link doesn't resolve.

An "u" letter was missing, i edited my posting above, hope it will work now .. i would be glad to hear some feedback.

Thanks - I see comments and indentation, as promised, which is a huge benefit!

Steve__Jay wrote:
Quote:
That's a fairly easy one - you need the 'binutils' package.

Thank you much for that information ... i'm not very familiar with simulated Un*x stuff.... and they [binutils] have to match my version of cygwin , right?

It's easiest to get hold of cygwin's own version by re-running the cygwin installer and selecting some extra packages (compared to downloading and building binutils from source.) The problem which arises is when a lot of time has passed and cygwin needs to update a lot of things too. For that reason, I try to load as much as I'm likely to need at the time of first installation, and then leave it alone.

But if you do build binutils from source, I don't think the version is very critical.

Steve__Jay wrote:
i fear, packed arrays will become deprecated one day ... some compilers seem to complain when fed with variant records also .. i use plenty of them ...

I saw the giant variant record - it looked scary to me. But if you're familiar with the technique and it works for you, fair enough.

Cheers
Ed
Back to top
View user's profile Send private message Visit poster's website
Steve__Jay



Joined: 26 Jul 2010
Posts: 4

PostPosted: Sat Aug 07, 2010 7:33 pm    Post subject: Reply with quote

BigEd wrote:
I see comments and indentation, as promised, which is a huge benefit!
Thank you -it has never been intended to make someone suffer ...

Quote:

It's easiest to get hold of cygwin's own version by re-running the cygwin installer and selecting some extra packages (compared to downloading and building binutils from source.)

I will try this in a few moments and later edit my post, okay? to me, your proposal seems to be a good solution. (i have to fix several things, too.)

Quote:

The problem which arises is when a lot of time has passed and cygwin needs to update a lot of things too. For that reason, I try to load as much as I'm likely to need at the time of first installation, and then leave it alone.

I did similarly, but when i needed cygwin first, it was because of fontforge. It [cygwin] demanded hundreds of megabytes ... my quota almost ran short ... and i needed fontforge just in order to improve some C64-like CBM font for use with my emulator, so i forgot to install the binutils ..
Since now, I tried to avoid building up from scratch (source) ... it requires so much reading manpages Wink

Quote:
I saw the giant variant record - it looked scary to me. But if you're familiar with the technique and it works for you, fair enough.

truth be told, i'm not very experienced, but it has been necessity - at least two overlapping variants are needed in order to make the memory (planned: 64 k) and the 'register file' appear to be the same chunk of memory. thus, by computing one single index, memory and registers can be treated interchangeably. E.g., LDA/STA instructions and TAX/TXA instructions altogether shrink to one single statement: q^:=p^
(this holds true for LDA and so on, and for the STA ones, i simply have to exchange pointers beforehand.)

kind regards..
Steve

EDIT /PS: Having read your postings above repeatedly, i should perhaps clarify that my machine is 32 bit. Due to delphi's Int64 type, i did not draw the conclusion that on some other modern computers, the generic type "integer" possibly denotes a 64 bit type while on mine it denotes 32 bit. Also, i switched off 'range checking' , i choose {$ALIGNMENT OFF} and 'short circuit evaluation on.'

Quote:
Actually, it hung, so something in the program wasn't understood - I tried some aggressive commenting out but didn't find a cause.
Back to top
View user's profile Send private message
Ruud



Joined: 12 Dec 2003
Posts: 155
Location: Heerlen, NL

PostPosted: Sun Aug 08, 2010 8:14 am    Post subject: Reply with quote

Steve__Jay wrote:
- El Dendo's ED64 from belgium ......

Hartelijk dank !!! (Thank you very much)

I've been on holiday as well, therefore my late reply.
_________________
Code:

    ___
   / __|__
  / /  |_/     Groetjes, Ruud
  \ \__|_\
   \___|       URL: Ruud.C64.org

Back to top
View user's profile Send private message Visit poster's website
BigEd



Joined: 11 Dec 2008
Posts: 397
Location: England

PostPosted: Sun Aug 08, 2010 3:54 pm    Post subject: Reply with quote

Quote:
by computing one single index, memory and registers can be treated interchangeably. E.g., LDA/STA instructions and TAX/TXA instructions altogether shrink to one single statement: q^:=p^
(this holds true for LDA and so on, and for the STA ones, i simply have to exchange pointers beforehand.

nice!
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    6502.org Forum Index -> Emulation and Simulation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum