Created
June 29, 2018 16:02
-
-
Save aaronstgeorge-wf/5d47fb42163cf1cd6ec0549dbbd78d5d to your computer and use it in GitHub Desktop.
Skeleton of Dart Nes Emulator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
class Clock { | |
Future<Null> _tick; | |
final Duration _clockSpeed; | |
Clock(this._clockSpeed); | |
Future<Null> get nextTick => _tick; | |
void start() { | |
_tick = new Future.delayed(_clockSpeed).then((_) { | |
start(); | |
}); | |
} | |
} | |
class CentralProcessingUnit { | |
final Clock clock; | |
CentralProcessingUnit(this.clock); | |
Future<Null> start() async { | |
print('cpu 1'); | |
await clock.nextTick; | |
print('cpu 2'); | |
await clock.nextTick; | |
print('cpu 3'); | |
await clock.nextTick; | |
print('cpu 4'); | |
await clock.nextTick; | |
print('cpu 5'); | |
await clock.nextTick; | |
print('cpu 6'); | |
await clock.nextTick; | |
print('cpu 7'); | |
await clock.nextTick; | |
print('cpu 8'); | |
await clock.nextTick; | |
print('cpu 9'); | |
await clock.nextTick; | |
print('cpu 10'); | |
} | |
} | |
class PictureProcessingUnit { | |
final Clock clock; | |
PictureProcessingUnit(this.clock); | |
Future<Null> start() async { | |
print('screen 1'); | |
await clock.nextTick; | |
print('screen 2'); | |
await clock.nextTick; | |
print('screen 3'); | |
await clock.nextTick; | |
print('screen 4'); | |
await clock.nextTick; | |
print('screen 5'); | |
await clock.nextTick; | |
print('screen 6'); | |
await clock.nextTick; | |
print('screen 7'); | |
await clock.nextTick; | |
print('screen 8'); | |
await clock.nextTick; | |
print('screen 9'); | |
await clock.nextTick; | |
print('screen 10'); | |
} | |
} | |
Future<Null> main() async { | |
var clock = new Clock(const Duration(seconds: 1)); | |
var cpu = new CentralProcessingUnit(clock); | |
var ppu = new PictureProcessingUnit(clock); | |
clock.start(); | |
cpu.start(); | |
ppu.start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment