Thanks for your response Daryl, sorry for not responding sooner. It was for health reasons.
Honestly, before trying your AVR-based 6502 Emulator, I had tried to go ahead with the klaus's sytem , but I couldn't get into the command mode. When booting the system the monitor runs continuously and does not respond to enter command mode. I have asked for some help in viewtopic.php?f=8&t=2407&start=30. I didn't get too much.
The only thing I have achieved is that the debugger/monitor attends to a Break launched from TeraTerm, as can be seen below:
..........................
0.1FF 0.FFF9 00 x00 y00 NV-BDIZC H>
0.1FF 0.FFF8 00 x00 y00 NV-BDIZC H>
0.1FF 0.FFF7 00 x00 y00 NV-BDIZC H>
0.1FF
Terminal break signal detected
0.1FF 0.FFF1 00 x00 y00 NV-BDIZC H>
0.1FF 0.FFF0 00 x00 y00 NV-BDIZC H>
..................
On the other hand, continuing with your AVR-based 6502 Emulator, in a first phase, I would like to try your suggestion to read/write external memory in slow mode. Could you, please, give me some idea how to approach that in some code form?
Diego,
AVR-based 6502 Emulator
Re: AVR-based 6502 Emulator
This example treats external memory as a data IO device. You cannot execute code from this memory.
First for the hardware, you could use PA and PB to create a 16 bit address bus. Use PC for the data bus. You can use pins on PD for the /OE and /WE. Set them as outputs and set them high initially.
To read an address in ext memory,
set PA and PB to outputs and PC to inputs.
write address values to PA and PB
bring the /OE pin low
Read PC
raise /OE
To write,
set PA, PB, and PC to outputs
write address values to PA and PB
write your data value to PC
bring the /WE pin low
raise /WE
For actual code, you'll need to Access the IO page and the specific IO port registers.
Port_A_DDR - $3F21
Port_A_Output - $3F22
Port_B_DDR - $3F24
Port_B_Output - $3F25
Port_C_DDR - $3F27
Port_C_Output - $3F28
Port_C_Input - $3F26
Port_D_DDR - $3F2A
Port_D_Output - $3F2B
OE - Pin D7
WE - Pin D6
To Read address $2345 in ext memory,:
LDA #$C0
STA Port_D_DDR
STA Port_D_Output ; OE and WE high
LDA #$FF
STA Port_A_DDR
STA Port_B_DDR
LDA #$00
STA Port_C_DDR
LDA #$23
STA Port_A_Output
LDA #$45
STA Port_B_Output
LDA #$40
STA Port_D_Output ; /OE low
LDA Port_C_Input
STA input_data ; read data from memory
LDA #$C0
STA Port_D_Output ; /OE High
RTS
That should gets you started.
If you want the emulator to see external RAM as its system RAM, then you need to do similar code in the AVR emulator engine to replace the internal SRAM access code. Be sure to decode the AVR IO page correctly. If you want to eliminate the Flash "ROM", then you'll need to preload the external RAM before you release the emulator from RESET.
best wishes!
Daryl
First for the hardware, you could use PA and PB to create a 16 bit address bus. Use PC for the data bus. You can use pins on PD for the /OE and /WE. Set them as outputs and set them high initially.
To read an address in ext memory,
set PA and PB to outputs and PC to inputs.
write address values to PA and PB
bring the /OE pin low
Read PC
raise /OE
To write,
set PA, PB, and PC to outputs
write address values to PA and PB
write your data value to PC
bring the /WE pin low
raise /WE
For actual code, you'll need to Access the IO page and the specific IO port registers.
Port_A_DDR - $3F21
Port_A_Output - $3F22
Port_B_DDR - $3F24
Port_B_Output - $3F25
Port_C_DDR - $3F27
Port_C_Output - $3F28
Port_C_Input - $3F26
Port_D_DDR - $3F2A
Port_D_Output - $3F2B
OE - Pin D7
WE - Pin D6
To Read address $2345 in ext memory,:
LDA #$C0
STA Port_D_DDR
STA Port_D_Output ; OE and WE high
LDA #$FF
STA Port_A_DDR
STA Port_B_DDR
LDA #$00
STA Port_C_DDR
LDA #$23
STA Port_A_Output
LDA #$45
STA Port_B_Output
LDA #$40
STA Port_D_Output ; /OE low
LDA Port_C_Input
STA input_data ; read data from memory
LDA #$C0
STA Port_D_Output ; /OE High
RTS
That should gets you started.
If you want the emulator to see external RAM as its system RAM, then you need to do similar code in the AVR emulator engine to replace the internal SRAM access code. Be sure to decode the AVR IO page correctly. If you want to eliminate the Flash "ROM", then you'll need to preload the external RAM before you release the emulator from RESET.
best wishes!
Daryl
Please visit my website -> https://sbc.rictor.org/
Re: AVR-based 6502 Emulator
Thank you very much, Daryl. I'll work on it.
- Mike Naberezny
- Site Admin
- Posts: 293
- Joined: 30 Aug 2002
- Location: Northern California
- Contact:
Re: AVR-based 6502 Emulator
mkl0815 wrote:
How stable is the ATmega1284 running at 24MHz? According to AVR site, the maximum operation frequency is 20MHz. So you overclocked it with 20%. That's a lot, i think.
8BIT wrote:
It has been running without any trouble using 24MHz. I am using a TTL Oscillator vs. a crystal and I do not have any IO connected. I did experiment with an ENC24C50 Ethernet board using an SPI interface and it also ran well at 24MHz.
The AVR128DB28 is one such chip that might be interesting to use with the emulator. It is available in a narrow 28-pin DIP package, can run directly off 5V, and has the same amount of flash and RAM as the Atmega1284. It can run from an external crystal, external oscillator, or its internal 24 MHz oscillator. It also has the newer UPDI interface for programming, which AVRDUDE supports using a TTL serial cable.
- Mike Naberezny (mike@naberezny.com) http://6502.org
Re: AVR-based 6502 Emulator
Nice to see their product line continuing to improve performance and capabilities. That's a welcome change!
Daryl
Daryl
Please visit my website -> https://sbc.rictor.org/
Re: AVR-based 6502 Emulator
Hi all, new member here.
I recently found interest in the 6502 after watching Ben Eater's video series. I am very new to Assembly, but I am quite familiar with programming AVRs in C. I happened to stumble across Daryl's emulator and just so happen to have couple of 1284p's so I downloaded the source and got it working. By the way, I got it running with a 16Mhz clock and managed to figure out how to change the baud rate to 19200 in the source files.
I have been browsing the source files to attempt to learn how it all works and to get a better understanding of programming in Assembly. I do have a couple of fundamental questions.
In the sources there are a couple of "INC" files that don't appear to be normal source files (at least nothing that I have ever seen). They are SR2AV.INC and AV2SR.INC. What exactly are these files and how are they produced? I did figure out how to produce the SBCROM.INC file using the SBC2AVR.EXE utility in the SBCOS source files.
Keep in mind, I am simply a self-taught hobbyist with no formal training or education in programming. I appreciate any clarification or direction.
Steve
I recently found interest in the 6502 after watching Ben Eater's video series. I am very new to Assembly, but I am quite familiar with programming AVRs in C. I happened to stumble across Daryl's emulator and just so happen to have couple of 1284p's so I downloaded the source and got it working. By the way, I got it running with a 16Mhz clock and managed to figure out how to change the baud rate to 19200 in the source files.
I have been browsing the source files to attempt to learn how it all works and to get a better understanding of programming in Assembly. I do have a couple of fundamental questions.
In the sources there are a couple of "INC" files that don't appear to be normal source files (at least nothing that I have ever seen). They are SR2AV.INC and AV2SR.INC. What exactly are these files and how are they produced? I did figure out how to produce the SBCROM.INC file using the SBC2AVR.EXE utility in the SBCOS source files.
Keep in mind, I am simply a self-taught hobbyist with no formal training or education in programming. I appreciate any clarification or direction.
Steve
Re: AVR-based 6502 Emulator
The SR2AV.INC and AV2SR.INC files are lookup tables for converting the AVR's status register to 65C02 Status register or the other way, at a bit level. The reason is to increase simulation speed. Doing it bit by bit takes too long.
They were generated using MS Excel if memory serves correctly. I'm not sure I still have those files or not.
Sounds like you have done well being self-taught - I too learned by experimentation and reading. I hope you enjoy your adventure with this simulator.
Daryl
They were generated using MS Excel if memory serves correctly. I'm not sure I still have those files or not.
Sounds like you have done well being self-taught - I too learned by experimentation and reading. I hope you enjoy your adventure with this simulator.
Daryl
Please visit my website -> https://sbc.rictor.org/
Re: AVR-based 6502 Emulator
8BIT wrote:
The SR2AV.INC and AV2SR.INC files are lookup tables for converting the AVR's status register to 65C02 Status register or the other way, at a bit level. The reason is to increase simulation speed. Doing it bit by bit takes too long.
They were generated using MS Excel if memory serves correctly. I'm not sure I still have those files or not.
Sounds like you have done well being self-taught - I too learned by experimentation and reading. I hope you enjoy your adventure with this simulator.
Daryl
They were generated using MS Excel if memory serves correctly. I'm not sure I still have those files or not.
Sounds like you have done well being self-taught - I too learned by experimentation and reading. I hope you enjoy your adventure with this simulator.
Daryl
My eventual goal is to build my own 6502 system with my own OS. I am a retired electronics guy, and this kind of stuff is fun for me and (I feel) keeps my mind sharp.
Re: AVR-based 6502 Emulator
My Monitor was derived from an Apple 2 clone that I owned long ago. I'm sure it was based on and was compatible with WozMon to some degree. Since you like programming in C, check out my CC65 targets for the simulator. The coolest thing is that you have access to all the AVR's IO registers.
Have fun!
Daryl
Have fun!
Daryl
Last edited by 8BIT on Mon Dec 15, 2025 3:28 am, edited 1 time in total.
Please visit my website -> https://sbc.rictor.org/
Re: AVR-based 6502 Emulator
In case anyone is interested, I found the source file for generating the AV2SR and SR2AV INC files.
It was actually a QuickBASIC program. I wrote several large programs using QuickBASIC and find it handy for generating tables and converting data files.
I'm attaching it here for the curious. Its a plain text file.
Daryl
It was actually a QuickBASIC program. I wrote several large programs using QuickBASIC and find it handy for generating tables and converting data files.
I'm attaching it here for the curious. Its a plain text file.
Daryl
- Attachments
-
- status.bas.txt
- MS QuickBASIC program to generate 2 tables for converting AVR and 65C02 Status Register bits.
- (1.93 KiB) Downloaded 46 times
Please visit my website -> https://sbc.rictor.org/