在 Arduino Mega 上模拟 Z80
- shaoziyang
- 帖子: 3967
- 注册时间: 2019年 10月 21日 13:48
在 Arduino Mega 上模拟 Z80
在 Arduino Mega 上模拟的 Z80 内核是一个免费的开源项目,它是 Marat Fayzullin 的 Z80 模拟器的修改版,可在 Arduino Mega 上运行,而较小的内存 Arduinos 没有足够内存运行它。
https://github.com/jkingsman/Z80Mega
- shaoziyang
- 帖子: 3967
- 注册时间: 2019年 10月 21日 13:48
Re: 在 Arduino Mega 上模拟 Z80
代码: 全选
#define MEM_SIZE 512
#define STEP_DELAY 300
#include <Z80.h>
/*
* Global declaration of RAM. This demo program counts
* up by 2s at memory address 0x0010.
*/
byte ram[MEM_SIZE] = {
// count by 2s at 0x10
0x3E, 0x00, // LD A,$04
0x32, 0x10, 0x00, // LD ($0010),A
0x3A, 0x10, 0x00, // LD A,($0010)
0x3C, // INC A
0x3C, // INC A
0x32, 0x10, 0x00, // LD ($0010),A
0x18, 0xF6 // JR $5
};
// Memory write -- write the Value to memory location Addr
void WrZ80(register zword Addr, register byte Value) {
ram[Addr] = Value;
}
// Memory read -- read the value at memory location Addr
byte RdZ80(register zword Addr) {
return ram[Addr];
}
// IO -- output the Value on the Port (currently does nothing)
void OutZ80(register zword Port, register byte Value) {}
// IO -- read a value from Port (currently defaults to 0)
byte InZ80(register zword Port) {
return 0;
}
// Advanced -- called when an emulator-specific opcode of
// ED FE is encountered. Generally can be left empty.
void PatchZ80(register Z80 *R) {}
// create a CPU core object
Z80 cpu;
void setup() {
Serial.begin(9600);
// Reset the CPU to 0x00 and zero the regs/flags
ResetZ80(&cpu);
}
void loop() {
// print out current program counter
// see Z80.h for the struct definition + fields
Serial.print("PC: ");
Serial.println(cpu.PC.W);
// execute single opcode from memory at the current PC
StepZ80(&cpu);
// display the contents of memory where we're counting up (0x0010)
Serial.print("Current value of 0x0010: ");
Serial.println(RdZ80(0x0010));
// delay before stepping again so you can watch it count up slowly
delay(STEP_DELAY);
}
-
- 帖子: 1
- 注册时间: 2021年 9月 13日 21:48
-
Hi Mauro,
Glad you like the EtherTen. The LCD & Keypad shield should work fine on an Arduino Mega as well.
Good luck with your project,
Angus
Glad you like the EtherTen. The LCD & Keypad shield should work fine on an Arduino Mega as well.
Good luck with your project,
Angus
- 附件
-
- 54.gif (7.77 KiB) 查看 1189 次
-
- 随机主题
- 回复总数
- 阅读次数
- 最新文章
-
- 4回复总数
- 3965 阅读次数
- 最新文章 由 shaoziyang
2022年 11月 30日 14:45
-
- 8回复总数
- 2062 阅读次数
- 最新文章 由 slotg
2021年 3月 21日 19:34
-
- 3回复总数
- 4883 阅读次数
- 最新文章 由 shaoziyang
2021年 9月 3日 22:20