|
@ -93,18 +93,20 @@ unsigned p1(const Input &input) |
|
|
return sum; |
|
|
return sum; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#define WIDTH 40 |
|
|
|
|
|
|
|
|
void p2(const Input &input) |
|
|
void p2(const Input &input) |
|
|
{ |
|
|
{ |
|
|
Cpu cpu(&input); |
|
|
Cpu cpu(&input); |
|
|
while (cpu.running()) { |
|
|
while (cpu.running()) { |
|
|
// Calculate current CRT line
|
|
|
// Calculate current CRT line
|
|
|
int X = cpu.cycle % 40; |
|
|
int X = cpu.cycle % WIDTH; |
|
|
if (X == 0) X += 40; |
|
|
if (X == 0) X += WIDTH; |
|
|
|
|
|
|
|
|
// Draw pixel
|
|
|
// Draw pixel
|
|
|
if (cpu.X <= X && X <= cpu.X + 2) cout << '#'; |
|
|
if (cpu.X <= X && X <= cpu.X + 2) cout << '#'; |
|
|
else cout << '.'; |
|
|
else cout << '.'; |
|
|
if (X == 40) cout << endl; |
|
|
if (X == WIDTH) cout << endl; |
|
|
|
|
|
|
|
|
cpu.tick(); |
|
|
cpu.tick(); |
|
|
} |
|
|
} |
|
|