void read_ADC(void) { PORTA.DIR = 0; // configure PORTA as input ADCA.CTRLA |= ADC_ENABLE_bm; // enable adc ADCA.CTRLB = ADC_RESOLUTION_12BIT_gc; // 12 bit conversion ADCA.REFCTRL = ADC_REFSEL_VCC_gc /*| ADC_BANDGAP_bm*/; // internal 1V bandgap reference ADCA.PRESCALER = ADC_PRESCALER_DIV128_gc; // peripheral clk/128 ADCA.CH0.CTRL = ADC_CH_INPUTMODE_SINGLEENDED_gc; // single ended ADCA.CH0.MUXCTRL = ADC_CH_MUXPOS_PIN2_gc; // PORTA:2 ADCA.CH0.CTRL |= ADC_CH_START_bm; // start conversion on channel 0 while(!ADCA.CH0.INTFLAGS) ; uint16_t result = ADCA.CH0RES; uint16_t z = result; for(uint8_t i = 0; i < 8; i++) { uint8_t ch; if(i > 1 && z == 0) ch = ' '; else { ch = '0' + z % 10; z /= 10; } put_char_at(ch, 46-6*i, 25); } #define RADIUS 24 #define CENTERX 104 #define CENTERY 53 #define MIN 220 #define MAX 4095 if(result < MIN) result = MIN; if(result > MAX) result = MAX; static int8_t oldx = 0; static int8_t oldy = 0; uint8_t x = (int8_t)(RADIUS * sin(2 * M_PI * (result - MIN) / (MAX-MIN))); uint8_t y = (int8_t)(RADIUS * cos(2 * M_PI * (result - MIN) / (MAX-MIN))); DrawLine(CENTERX-oldx, CENTERX+oldx, CENTERY-oldy, CENTERY+oldy, 0); DrawLine(CENTERX-x, CENTERX+x, CENTERY-y, CENTERY+y, 1); oldx = x; oldy = y; }
// When something outside display.c wants to call 'at' aka put_char_at // to draw something briefly, this is probably what it wants... // Draw 1 cell on screen (here row,col are NOT screen-relative.) // For making animatedness. If c = 0, it will set cell to 'original' value void animate_char(Short y, Short x, Char c, Boolean bold) { Short row, col, ch; Short v_h = itsy_on ? visible_h_itsy : visible_h; Short v_w = itsy_on ? visible_w_itsy : visible_w; if (FrmGetActiveFormID() != MainForm) return; if (y < visible_y || x < visible_x || y >= visible_y + v_h || x >= visible_x + v_w) return; // the cursor position is not visible on the screen! // if (c != 0 && FrmGetActiveFormID() == MainForm) // lines_dirty[y] = screen_dirty = true;// worst case, refresh will clean up row = y - visible_y; col = x - visible_x; ch = terminal[row][col]; if (c == 0) c = ch; #ifdef I_AM_OS_2 if (itsy_on) FntSetFont(ledFont); #else if (itsy_on) FntSetFont(SmallFont); #endif /* #ifdef I_AM_COLOR if (IsColor) { start_color(); } #endif //I_AM_COLOR */ put_char_at(row, col, c, bold); /* #ifdef I_AM_COLOR if (IsColor) { stop_color(); } #endif //I_AM_COLOR */ #ifdef I_AM_OS_2 if (itsy_on) FntSetFont(stdFont); #else if (itsy_on) FntSetFont(BigFont); #endif terminal[row][col] = ch; }
int main() { int i,j; tab = "0"; for ( i = 1 ; i < N ; i = i+1 ) tab = tab + '1'; for ( i = 2 ; i < SN ; i = i+1 ) for ( j = i+i; j < N ; j = j+i ) put_char_at( tab, j, '0' ); for ( i = 0 ; i < N ; i = i+1 ) if ( get_char_at( tab, i ) == '1' ) { printd(i); printf(" "); } printf("\n"); return 0; }
void refresh() // formerly known as docrt() { Short col, line, y_abs, x_abs; Short v_h = itsy_on ? visible_h_itsy : visible_h; Short v_w = itsy_on ? visible_w_itsy : visible_w; UChar info; if (FrmGetActiveFormID() != MainForm) return; if (you.uswallow) { swallowed(); return; } ridiculous_code(); #ifdef I_AM_OS_2 if (itsy_on) FntSetFont(ledFont); #else if (itsy_on) FntSetFont(SmallFont); #endif /* line is RELATIVE, line+visible_y is ABSOLUTE. col is RELATIVE, col+visible_x is ABSOLUTE. */ for (line = 0 ; line < v_h ; line++) { y_abs = line + visible_y; for (col = 0; col < v_w; col++) { x_abs = col + visible_x; info = floor_info[x_abs][y_abs]; if (info & (SEEN_CELL | NEW_CELL)) // SEEN_CELL in case we clear_visibled if (floor_symbol[x_abs][y_abs] != terminal[line][col]) { put_char_at(line, col, floor_symbol[x_abs][y_abs], false); } } } scrlx = DCOLS; scrly = DROWS; scrhx = scrhy = 0; #ifdef I_AM_OS_2 if (itsy_on) FntSetFont(stdFont); #else if (itsy_on) FntSetFont(BigFont); #endif }
// Not good to basically have two independent "refresh" procedures... :-b // hmmm in the original, pline called nscr! void nscr() { Short x_abs, y_abs, col, line; Short v_h = itsy_on ? visible_h_itsy : visible_h; Short v_w = itsy_on ? visible_w_itsy : visible_w; if (FrmGetActiveFormID() != MainForm) return; // XXX flags.nscrinh is used only in goto_level() ..will need it though. if (you.uswallow || you.ux == FAR /*|| flags.nscrinh*/) return; #ifdef I_AM_OS_2 if (itsy_on) FntSetFont(ledFont); #else if (itsy_on) FntSetFont(SmallFont); #endif pru(); for (y_abs = scrly ; y_abs <= scrhy ; y_abs++) { line = y_abs - visible_y; if (line < 0 || line >= v_h) continue; for (x_abs = scrlx ; x_abs <= scrhx ; x_abs++) { col = x_abs - visible_x; if (col < 0 || col >= v_w) continue; if (get_cell_new(floor_info[x_abs][y_abs])) { // room = &levl[x_abs][y_abs] floor_info[x_abs][y_abs] &= ~NEW_CELL; // room->new = 0; put_char_at(line, col, floor_symbol[x_abs][y_abs], false); } } } scrlx = DCOLS; scrly = DROWS; scrhx = scrhy = 0; #ifdef I_AM_OS_2 if (itsy_on) FntSetFont(stdFont); #else if (itsy_on) FntSetFont(BigFont); #endif }