6502.org
http://forum.6502.org/

[150] Commodore 64 question - 6502
http://forum.6502.org/viewtopic.php?f=7&t=405
Page 1 of 1

Author:  mArkcpp [ Mon Jan 28, 2002 10:44 pm ]
Post subject:  [150.1] Commodore 64 question - 6502

Hey there. I'm somewhat new to the 6502/6510 scene as far as learning goes. I owned a Commodore 64 way back when, but used it for BASIC programming (nothing spectacular) and playing games. I am trying to write a C64 emulator of my own basically to prove to myself that I can do it and to learn more about the C64 system. I have some questions that are probably extremely easy to answer, but I need some clarity to get me heading in the right direction and understanding what I'm doing.

First, in my emulator, I have allocated 64k of memory to an array, and I can read in a commodore 64 file to the memory. My first question is, where does this get read into the memory at? I think it might be $8000, but I'd like some confirmation on this to reassure me. I was reading the Commodore 64 Progammers Reference Guide, and it has a memory map. It shows $8000 as the ROM. Is that where I load the C64 game file to, or should it go in RAM at another address?

Second, once the file's contents are loaded into memory, how do I know where the actual programs instructions start, i.e. opcodes? Does the game file have its own set of addresses where the coding is stored, and if so (which I think it must because I've seen disassembers that start a particular address) how do I find out this address. Also, if it does have its own address, I'm not sure I understand how it can have an its own address unless it is similar to giving a BASIC program line numbers before each line of code , in which case I'd rather call it a line number than an address(maybe that is what I should be doing anyway). So the next question would be, do all files start their opcodes at the same address, or am I dreaming of a perfect world now?

Well, as you can see, I need some guidance. I think I'm asking the right questions, and I have read all about the opcodes and I understand what I have read for the most part, and for what I am still unsure of I have the book to guide me through. Once I understand the above questions, I think I'll be able to make some good progress on coding the cpu in the emulator. thanks in advance to anyone and everyone who responds. i'll take links to websites too if there is good reading material there that I should read up on to get a better understanding of all of this. sorry for the long post!!

mArk

Author:  saipan59 [ Wed Jan 30, 2002 6:32 pm ]
Post subject:  [150.2] Commodore 64 question - 6502

I don't have all the C64 details at hand, but here are some guidelines:

- Programs load into RAM, not ROM. ROM is "Read Only", so whatever the C64 has in ROM is 'static'.
- If a C64 is running from a plug-in cartridge, then that cartridge consists of additional ROM.
- If the program is in BASIC, then you are not loading 6502 opcodes at all; rather you are loading BASIC tokens. The tokens are interpreted by the code in ROM at run-time, to do whatever the program needs to do. So perhaps what you are trying to do is emulate Commodore BASIC, which is a somewhat different task.
- If the C64 supports loading and running a binary image of 6502 code (I'm pretty sure it does), then it probably supports loading *anywhere* in RAM. In the old Commodore PET, you could do a SAVE of memory. When you did a LOAD, it put everything back to the same place you SAVEd it from. Then you could do a SYS(addr) command to run the code.

Pete

Author:  mArkcpp [ Thu Jan 31, 2002 10:28 pm ]
Post subject:  [150.3] Commodore 64 question - 6502

thanks for the reply. I hope to get more people involved as well.

I guess what I'm focusing on right now, is a *.d64 file. I don't know how familiar you are with C64 specific "stuff", but the .d64 files that you can download off the internet and play some of the old games for the commodore. Now, you mentioned that programs load into RAM. If I were sitting down at the good ole commodore, and typed load"$",8 on a disk that contained a game I wanted to play it would come back with a list of a few files and have "PRG" out to the side. So, now I'm assuming I load these into RAM(i think I remember this as address $C000-don't have my book in front of me though).

Well, I think I may be more confused now than before....but that's ok. I'll straighten it all out somehow. Hopefully, this forum can keep me pointed in the right direction. I still have tons to learn. If anyone wants to chime in, please do. If I'm asking the wrong questions, please let me know. Thanks for any help.

mArk

Author:  GARTHWILSON [ Fri Feb 01, 2002 2:31 am ]
Post subject:  [150.4] Commodore 64 question - 6502

There's also a Commodore forum on Delphi. I have the address on my "favorites" column, although I seldom visit it. The address on the favorites is: <http://login.prospero.com/dir-login/index.asp?webtag=commodore&lgnDST=http%3A%2F%2Fwww%2Edelphi%2E%2Fn%2Fmain%2Easp%3Fwegtag%3Dcommodore%26nav%3Dstart>

If you can make heads or tails of this, congratulations. I know it doesn't contain my password, so I'm not too concerned about posting it. Actually, in the last few days, I've been getting forwarding links screens after my login screen when I go to get on here, and I haven't done anything to figure out what to do about it. Maybe you'll be able to find the Commodore Delphi forum from this.

You can have virtually the C64's entire 64k to be RAM, even to run BASIC. After booting up, you copy the ROM to the RAM and switch the ROM out. Then you can actually modify the built-in BASIC if you want to (and know how). I couldn't tell you right now how to do it, but I've done it with our son on one of his C64's a year or two ago.

SYS and USR() let you run machine-language routines from BASIC.

Garth

Author:  usotsuki [ Sat Feb 02, 2002 2:22 pm ]
Post subject:  [150.5] Commodore 64 question - 6502

Sound like how the Apple II+ worked.

Dosius aka Usotsuki

Author:  usotsuki [ Sat Feb 02, 2002 2:24 pm ]
Post subject:  [150.6] Commodore 64 question - 6502

Try http://forums.delphiforums.com/commodore ? Looking at the above, that might be it...

Dosius aka Usotsuki

Author:  mArkcpp [ Mon Feb 04, 2002 10:02 pm ]
Post subject:  [150.7] Commodore 64 question - 6502

thanks for the help guys.

mArk

Author:  6502guy [ Sun Mar 17, 2002 1:18 am ]
Post subject:  [150.8] Commodore 64 question - 6502

Hi,
do you still read here? Well try your question on usenet in group comp.sys.cbm. Also search for C= Hacking it's a magazine for commodores, there's articles about assembly maybe even emulation. Some very advanced stuff too which is needed for write a full emulator.
As for your project, there is a Visual Basic 6502 simulator with source you could look at, it would make a good start. The code is done well too. I can't seem to find it now, try 6502sim.
A single file game will have one line of basic like this:
1984 sys8196
The file will start with bytes like this:
$01 $08 $0B $08 $xx $02 $9E... $00 $00
( 1 )(2 ) (3 ) (4 ) (at $800B)
1-address this file should be loaded in ram =$801, which is
where basic programs start. If it were machine code that needed a manual SYS command to start, like a machine language monitor at $C000, this would be $00 $C0 and you start it with SYS49152.
2 link to next line of basic
3 line number, 16 bit integer=1984 (decimal)
4 $9E=SYS, it's called a token it's just how basic stores it's
commands
... following is petascii for "8196" I think, more data for basic
$00 $00 the link points to this, this is the next line of
the basic, which happens to be the end so it's marked as 0.
Exactly after this would be the machine code, starting at
8197 or whatever the SYS points to. So you could scan the file
for the first two $00 $00 and assume the code starts after that.
To run the code you need to simulate all the machine codes, there's theoretically 256 of them you have to write individual subroutines for, but you could get away probalby with just the "official" ones that most programs use. And if you want any speed control you've have to keep track of how long it should be taking. Then you need to simulate at least a basic screen to see antying, unless you just want to watch the commands go by and how they affect the memory and registers.
You will have to understand assembly very well before you can do this. The source code for VICE emulator has all this in a C file and worked out perfectly, you can just translate to whatever langauge you use. Don't ask me why I thought it was VB.. well good luck.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/