Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#define HSYNC 8
#define VSYNC 16
#define ROWS 261
const byte buf[1][200] = {
{ 0, 5, 4, 3, 2, 1, 6, 7, 1, 2 , 0, 5, 4, 3, 2, 1, 6, 7, 1, 2, 0, 5, 4, 3, 2, 1, 6, 7, 1, 2, 0, 5, 4, 3, 2, 1, 6, 7, 1, 2, 0, 5, 4, 3, 2, 1, 6, 7, 1, 2, 0, 5, 4, 3, 2, 1, 6, 7, 1, 2, 0, 5, 4, 3, 2, 1, 6, 7, 1, 2, 0, 5, 4, 3, 2, 1, 6, 7, 1, 2, 0, 5, 4, 3, 2, 1, 6, 7, 1, 2, 0, 5, 4, 3, 2, 1, 6, 7, 1, 2 /* 100 */, 0, 5, 4, 3, 2, 1, 6, 7, 1, 2, 0, 5, 4, 3, 2, 1, 6, 7, 1, 2, 0, 5, 4, 3, 2, 1, 6, 7, 1, 2, 0, 5, 4, 3, 2, 1, 6, 7, 1, 2, 0, 5, 4, 3, 2, 1, 6, 7, 1, 2, 0, 5, 4, 3, 2, 1, 6, 7, 1, 2, 0, 5, 4, 3, 2, 1, 6, 7, 1, 2, 0, 5, 4, 3, 2, 1, 6, 7, 1, 2, 0, 5, 4, 3, 2, 1, 6, 7, 1, 2, 0, 5, 4, 3, 2, 1, 6, 7, 1, 2 /* 200 */ }
};
#define SETC(x) PORTB = (PORTB & ~7) | x
#define EXEC_NOP asm volatile ("nop\n\t")
#define EXEC_10_NOPS EXEC_NOP; EXEC_NOP; EXEC_NOP; EXEC_NOP; EXEC_NOP; EXEC_NOP; EXEC_NOP; EXEC_NOP; EXEC_NOP; EXEC_NOP;
#define EXEC_50_NOPS EXEC_10_NOPS; EXEC_10_NOPS; EXEC_10_NOPS; EXEC_10_NOPS; EXEC_10_NOPS;
#define EXEC_100_NOPS EXEC_50_NOPS; EXEC_50_NOPS;
#define EXEC_LEFT_BLANKING_AND_OVERSCAN() { EXEC_50_NOPS; SETC(0); EXEC_10_NOPS; EXEC_NOP; EXEC_NOP; EXEC_NOP; }
#define EXEC_RIGHT_OVERSCAN_AND_BLANKING() { SETC(0); EXEC_50_NOPS; EXEC_50_NOPS; EXEC_10_NOPS; EXEC_NOP; EXEC_NOP; EXEC_NOP; EXEC_NOP; EXEC_NOP; EXEC_NOP; }
#define EXEC_HSYNC() { PORTB |= HSYNC; EXEC_50_NOPS; EXEC_10_NOPS; EXEC_10_NOPS; EXEC_NOP; PORTB &= ~HSYNC; }
#define DRAW_PIXELS_FOR_LINE(i) { \
SETC(buf[i][0]); \
SETC(buf[i][1]); \
SETC(buf[i][2]); \
SETC(buf[i][3]); \
SETC(buf[i][4]); \
SETC(buf[i][5]); \
SETC(buf[i][6]); \
SETC(buf[i][7]); \
SETC(buf[i][8]); \
SETC(buf[i][9]); \
SETC(buf[i][10]); \
SETC(buf[i][11]); \
SETC(buf[i][12]); \
SETC(buf[i][13]); \
SETC(buf[i][14]); \
SETC(buf[i][15]); \
SETC(buf[i][16]); \
SETC(buf[i][17]); \
SETC(buf[i][18]); \
SETC(buf[i][19]); \
SETC(buf[i][20]); \
SETC(buf[i][21]); \
SETC(buf[i][22]); \
SETC(buf[i][23]); \
SETC(buf[i][24]); \
SETC(buf[i][25]); \
SETC(buf[i][26]); \
SETC(buf[i][27]); \
SETC(buf[i][28]); \
SETC(buf[i][29]); \
SETC(buf[i][30]); \
SETC(buf[i][31]); \
SETC(buf[i][32]); \
SETC(buf[i][33]); \
SETC(buf[i][34]); \
SETC(buf[i][35]); \
SETC(buf[i][36]); \
SETC(buf[i][37]); \
SETC(buf[i][38]); \
SETC(buf[i][39]); \
SETC(buf[i][40]); \
SETC(buf[i][41]); \
SETC(buf[i][42]); \
SETC(buf[i][43]); \
SETC(buf[i][44]); \
SETC(buf[i][45]); \
SETC(buf[i][46]); \
SETC(buf[i][47]); \
SETC(buf[i][48]); \
SETC(buf[i][49]); \
SETC(buf[i][50]); \
SETC(buf[i][51]); \
SETC(buf[i][52]); \
SETC(buf[i][53]); \
SETC(buf[i][54]); \
SETC(buf[i][55]); \
SETC(buf[i][56]); \
SETC(buf[i][57]); \
SETC(buf[i][58]); \
SETC(buf[i][59]); \
SETC(buf[i][60]); \
SETC(buf[i][61]); \
SETC(buf[i][62]); \
SETC(buf[i][63]); \
SETC(buf[i][64]); \
SETC(buf[i][65]); \
SETC(buf[i][66]); \
SETC(buf[i][67]); \
SETC(buf[i][68]); \
SETC(buf[i][69]); \
SETC(buf[i][70]); \
SETC(buf[i][71]); \
SETC(buf[i][72]); \
SETC(buf[i][73]); \
SETC(buf[i][74]); \
SETC(buf[i][75]); \
SETC(buf[i][76]); \
SETC(buf[i][77]); \
SETC(buf[i][78]); \
SETC(buf[i][79]); \
SETC(buf[i][80]); \
SETC(buf[i][81]); \
SETC(buf[i][82]); \
SETC(buf[i][83]); \
SETC(buf[i][84]); \
SETC(buf[i][85]); \
SETC(buf[i][86]); \
SETC(buf[i][87]); \
SETC(buf[i][78]); \
SETC(buf[i][89]); \
SETC(buf[i][90]); \
SETC(buf[i][91]); \
SETC(buf[i][92]); \
SETC(buf[i][93]); \
SETC(buf[i][94]); \
SETC(buf[i][95]); \
SETC(buf[i][96]); \
SETC(buf[i][97]); \
SETC(buf[i][98]); \
SETC(buf[i][99]); \
SETC(buf[i][100]); \
SETC(buf[i][101]); \
SETC(buf[i][102]); \
SETC(buf[i][103]); \
SETC(buf[i][104]); \
SETC(buf[i][105]); \
SETC(buf[i][106]); \
SETC(buf[i][107]); \
SETC(buf[i][108]); \
SETC(buf[i][109]); \
SETC(buf[i][110]); \
SETC(buf[i][111]); \
SETC(buf[i][112]); \
SETC(buf[i][113]); \
SETC(buf[i][114]); \
SETC(buf[i][115]); \
SETC(buf[i][116]); \
SETC(buf[i][117]); \
SETC(buf[i][118]); \
SETC(buf[i][119]); \
SETC(buf[i][120]); \
SETC(buf[i][121]); \
SETC(buf[i][122]); \
SETC(buf[i][123]); \
SETC(buf[i][124]); \
SETC(buf[i][125]); \
SETC(buf[i][126]); \
SETC(buf[i][127]); \
SETC(buf[i][128]); \
SETC(buf[i][129]); \
SETC(buf[i][130]); \
SETC(buf[i][131]); \
SETC(buf[i][132]); \
SETC(buf[i][133]); \
SETC(buf[i][134]); \
SETC(buf[i][135]); \
SETC(buf[i][136]); \
SETC(buf[i][137]); \
SETC(buf[i][138]); \
SETC(buf[i][139]); \
SETC(buf[i][140]); \
SETC(buf[i][141]); \
SETC(buf[i][142]); \
SETC(buf[i][143]); \
SETC(buf[i][144]); \
SETC(buf[i][145]); \
SETC(buf[i][146]); \
SETC(buf[i][147]); \
SETC(buf[i][148]); \
SETC(buf[i][149]); \
SETC(buf[i][150]); \
SETC(buf[i][151]); \
SETC(buf[i][152]); \
SETC(buf[i][153]); \
SETC(buf[i][154]); \
SETC(buf[i][155]); \
SETC(buf[i][156]); \
SETC(buf[i][157]); \
SETC(buf[i][158]); \
SETC(buf[i][159]); \
SETC(buf[i][160]); \
SETC(buf[i][161]); \
SETC(buf[i][162]); \
SETC(buf[i][163]); \
SETC(buf[i][164]); \
SETC(buf[i][165]); \
SETC(buf[i][166]); \
SETC(buf[i][167]); \
SETC(buf[i][168]); \
SETC(buf[i][169]); \
SETC(buf[i][170]); \
SETC(buf[i][171]); \
SETC(buf[i][172]); \
SETC(buf[i][173]); \
SETC(buf[i][174]); \
SETC(buf[i][175]); \
SETC(buf[i][176]); \
SETC(buf[i][177]); \
SETC(buf[i][178]); \
SETC(buf[i][179]); \
SETC(buf[i][180]); \
SETC(buf[i][181]); \
SETC(buf[i][182]); \
SETC(buf[i][183]); \
SETC(buf[i][184]); \
SETC(buf[i][185]); \
SETC(buf[i][186]); \
SETC(buf[i][187]); \
SETC(buf[i][178]); \
SETC(buf[i][189]); \
SETC(buf[i][190]); \
SETC(buf[i][191]); \
SETC(buf[i][192]); \
SETC(buf[i][193]); \
SETC(buf[i][194]); \
SETC(buf[i][195]); \
SETC(buf[i][196]); \
SETC(buf[i][197]); \
SETC(buf[i][198]); \
SETC(buf[i][199]); \
}
#define DRAW_LINE(i) { \
EXEC_LEFT_BLANKING_AND_OVERSCAN(); \
DRAW_PIXELS_FOR_LINE(i); \
EXEC_RIGHT_OVERSCAN_AND_BLANKING(); \
EXEC_HSYNC(); \
}
int row = ROWS;
void setup() {
DDRB = B111111;
PORTB &= ~(HSYNC | VSYNC | 7);
noInterrupts();
}
void loop() {
DRAW_LINE(0);
switch (row++) {
case 225:
PORTB |= VSYNC; // VSYNC HIGH
break;
case 228:
PORTB &= ~VSYNC; // VSYNC LOW
break;
case 261:
row = 0;
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.