Created
January 29, 2019 21:51
-
-
Save neuro-sys/d594da599f20728622f401d2c848ddbc to your computer and use it in GitHub Desktop.
Amstrad CPC, CRTC Address Generator
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
#include <stdio.h> | |
typedef unsigned char u8; | |
typedef unsigned short u16; | |
typedef unsigned int u32; | |
#define VIDEO_ADDR(MA, RA) \ | |
((MA & 0x3FF) << 1) | ((RA & 7) << 11) | ((MA & 0x3000) << 2) | |
#define PRINT_CHAR_ADDR | |
int main() | |
{ | |
u8 R13; | |
u8 R12; | |
u8 R0; | |
u8 R9; | |
u8 R1; | |
u8 R6; | |
int clock; | |
R1 = 0x28; | |
R9 = 0x7; | |
R0 = 0x3F; | |
R12 = 0x30; | |
R13 = 0; | |
R6 = 25; | |
int refresh_addr = (u16) R13 | (((u16) R12 << 8)); | |
clock = 0; | |
while (1) { | |
u16 MA; /* MA pins on CRTC */ | |
u16 RA; /* Raster pins on CRTC */ | |
int line; | |
line = clock / ((R9 + 1) * (R0 + 1)); | |
MA = refresh_addr + (line * R1 + (clock % (R0 + 1))); | |
RA = (clock / (R0 + 1)) % (R9 + 1); | |
if (line >= R6) { | |
break; | |
} | |
#ifdef PRINT_ALL_ADDR | |
printf("%.4x", VIDEO_ADDR(MA, RA)); | |
#endif | |
#ifdef PRINT_CHAR_ADDR | |
if (clock % (R0 + 1) == 0) { | |
static int c = 0; | |
if (c % (R9 + 1) == 0) { | |
printf("\n"); | |
printf("%2d: ", (line + 1)); | |
} | |
printf("%.4x", VIDEO_ADDR(MA, RA)); | |
if ((c + 1) % (R9 + 1) != 0) { | |
printf(", "); | |
} | |
c += 1; | |
} | |
#endif | |
clock += 1; | |
} | |
return 0; | |
} |
Author
neuro-sys
commented
Jan 29, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment