void Space::save_motor(int m, int32_t &addr) { // {{{ write_16(addr, motor[m]->step_pin.write()); write_16(addr, motor[m]->dir_pin.write()); write_16(addr, motor[m]->enable_pin.write()); write_16(addr, motor[m]->limit_min_pin.write()); write_16(addr, motor[m]->limit_max_pin.write()); write_float(addr, motor[m]->steps_per_unit); write_float(addr, motor[m]->home_pos); write_float(addr, motor[m]->limit_v); write_float(addr, motor[m]->limit_a); write_8(addr, motor[m]->home_order); } // }}}
static cdk_error_t write_head_old (cdk_stream_t out, size_t size, int type) { cdk_error_t rc; int ctb; assert (out); if (type < 0 || type > 16) return CDK_Inv_Packet; ctb = 0x80 | (type << 2); if (!size) ctb |= 3; else if (size < 256) ; else if (size < 65536) ctb |= 1; else ctb |= 2; rc = stream_putc (out, ctb); if (!size) return rc; if (!rc) { if (size < 256) rc = stream_putc (out, size); else if (size < 65536) rc = write_16 (out, size); else rc = write_32 (out, size); } return rc; }
static int do_public_key( IOBUF out, int ctb, PKT_public_key *pk ) { int rc = 0; int n, i; IOBUF a = iobuf_temp(); if( !pk->version ) iobuf_put( a, 3 ); else iobuf_put( a, pk->version ); write_32(a, pk->timestamp ); if( pk->version < 4 ) { u16 ndays; if( pk->expiredate ) ndays = (u16)((pk->expiredate - pk->timestamp) / 86400L); else ndays = 0; write_16(a, ndays ); } iobuf_put(a, pk->pubkey_algo ); n = pubkey_get_npkey( pk->pubkey_algo ); if( !n ) write_fake_data( a, pk->pkey[0] ); for(i=0; i < n; i++ ) mpi_write(a, pk->pkey[i] ); write_header2(out, ctb, iobuf_get_temp_length(a), pk->hdrbytes, 1 ); if( iobuf_write_temp( out, a ) ) rc = G10ERR_WRITE_FILE; iobuf_close(a); return rc; }
/* Adapted from libavformat/spdifenc.c: */ static int write_buffer_dtshd( filter_t *p_filter, block_t *p_in_buf ) { static const char p_dtshd_start_code[10] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe }; static const size_t i_dtshd_start_code = sizeof( p_dtshd_start_code ); filter_sys_t *p_sys = p_filter->p_sys; vlc_dts_header_t core; if( vlc_dts_header_Parse( &core, p_in_buf->p_buffer, p_in_buf->i_buffer ) != VLC_SUCCESS ) return SPDIF_ERROR; unsigned i_period = p_filter->fmt_out.audio.i_rate * core.i_frame_length / core.i_rate; int i_subtype = dtshd_get_subtype( i_period ); if( i_subtype == -1 ) return SPDIF_ERROR; size_t i_in_size = i_dtshd_start_code + 2 + p_in_buf->i_buffer; size_t i_out_size = i_period * 4; uint16_t i_data_type = IEC61937_DTSHD | i_subtype << 8; if( p_filter->p_sys->dtshd.b_skip || i_in_size + SPDIF_HEADER_SIZE > i_out_size ) { /* The bitrate is too high, pass only the core part */ p_in_buf->i_buffer = core.i_frame_size; i_in_size = i_dtshd_start_code + 2 + p_in_buf->i_buffer; if( i_in_size + SPDIF_HEADER_SIZE > i_out_size ) return SPDIF_ERROR; /* Don't try to send substreams anymore. That way, we avoid to switch * back and forth between DTD and DTS-HD */ p_filter->p_sys->dtshd.b_skip = true; } if( write_init( p_filter, p_in_buf, i_out_size, i_out_size / p_filter->fmt_out.audio.i_bytes_per_frame ) ) return SPDIF_ERROR; write_data( p_filter, p_dtshd_start_code, i_dtshd_start_code, true ); write_16( p_filter, p_in_buf->i_buffer ); write_buffer( p_filter, p_in_buf ); /* Align so that (length_code & 0xf) == 0x8. This is reportedly needed * with some receivers, but the exact requirement is unconfirmed. */ #define ALIGN(x, y) (((x) + ((y) - 1)) & ~((y) - 1)) size_t i_align = ALIGN( i_in_size + 0x8, 0x10 ) - 0x8; #undef ALIGN if( i_align > i_in_size && i_align - i_in_size <= p_sys->p_out_buf->i_buffer - p_sys->i_out_offset ) write_padding( p_filter, i_align - i_in_size ); write_finalize( p_filter, i_data_type, 1 /* in bytes */ ); return SPDIF_SUCCESS; }
void Temp::save(int32_t &addr) { write_float(addr, R0); write_float(addr, R1); write_float(addr, logRc); write_float(addr, Tc); write_float(addr, beta); /* write_float(addr, core_C); write_float(addr, shell_C); write_float(addr, transfer); write_float(addr, radiation); write_float(addr, power); */ write_16(addr, power_pin[0].write()); write_16(addr, power_pin[1].write()); write_16(addr, thermistor_pin.write()); write_float(addr, target[1]); write_float(addr, arch_get_duty(power_pin[1])); }
static int do_public_key( IOBUF out, int ctb, PKT_public_key *pk ) { int rc = 0; int n, i; IOBUF a = iobuf_temp(); if ( !pk->version ) iobuf_put( a, 3 ); else iobuf_put( a, pk->version ); write_32(a, pk->timestamp ); if ( pk->version < 4 ) { u16 ndays; if ( pk->expiredate ) ndays = (u16)((pk->expiredate - pk->timestamp) / 86400L); else ndays = 0; write_16(a, ndays ); } iobuf_put (a, pk->pubkey_algo ); if ( pk->pubkey_algo == PUBKEY_ALGO_NTRU){ rc = sexp_write(a, pk->ntru_pkey); } else { n = pubkey_get_npkey ( pk->pubkey_algo ); if ( !n ) write_fake_data( a, pk->pkey[0] ); } if (!rc) { write_header2 (out, ctb, iobuf_get_temp_length(a), pk->hdrbytes); printf("write output\n"); rc = iobuf_write_temp ( out, a ); } printf("finished writing\n"); iobuf_close(a); return rc; }
static cdk_error_t write_public_key (cdk_stream_t out, cdk_pkt_pubkey_t pk, int is_subkey, int old_ctb) { int pkttype, ndays = 0; size_t npkey = 0, size = 6; cdk_error_t rc; assert (out); assert (pk); if (pk->version < 2 || pk->version > 4) return CDK_Inv_Packet; if (DEBUG_PKT) _cdk_log_debug ("write_public_key: subkey=%d\n", is_subkey); pkttype = is_subkey ? CDK_PKT_PUBLIC_SUBKEY : CDK_PKT_PUBLIC_KEY; npkey = cdk_pk_get_npkey (pk->pubkey_algo); if (!npkey) return CDK_Inv_Algo; if (pk->version < 4) size += 2; /* expire date */ if (is_subkey) old_ctb = 0; size += calc_mpisize (pk->mpi, npkey); if (old_ctb) rc = pkt_write_head2 (out, size, pkttype); else rc = pkt_write_head (out, old_ctb, size, pkttype); if (!rc) rc = stream_putc (out, pk->version); if (!rc) rc = write_32 (out, pk->timestamp); if (!rc && pk->version < 4) { if (pk->expiredate) ndays = (u16) ((pk->expiredate - pk->timestamp) / 86400L); rc = write_16 (out, ndays); } if (!rc) rc = stream_putc (out, _cdk_pub_algo_to_pgp (pk->pubkey_algo)); if (!rc) rc = write_mpibuf (out, pk->mpi, npkey); return rc; }
void diff_write_commit(const char* zone, uint32_t old_serial, uint32_t new_serial, uint16_t id, uint32_t num_parts, uint8_t commit, const char* log_str, nsd_options_t* opt) { const char* filename = opt->difffile; struct timeval tv; FILE *df; uint32_t len; if (gettimeofday(&tv, NULL) != 0) { log_msg(LOG_ERR, "could not set timestamp for %s: %s", filename, strerror(errno)); return; } df = fopen(filename, "a"); if(!df) { log_msg(LOG_ERR, "could not open file %s for append: %s", filename, strerror(errno)); return; } len = strlen(zone) + sizeof(len) + sizeof(old_serial) + sizeof(new_serial) + sizeof(id) + sizeof(num_parts) + sizeof(commit) + strlen(log_str) + sizeof(len); if(!write_32(df, DIFF_PART_SURE) || !write_32(df, (uint32_t) tv.tv_sec) || !write_32(df, (uint32_t) tv.tv_usec) || !write_32(df, len) || !write_str(df, zone) || !write_32(df, old_serial) || !write_32(df, new_serial) || !write_16(df, id) || !write_32(df, num_parts) || !write_8(df, commit) || !write_str(df, log_str) || !write_32(df, len)) { log_msg(LOG_ERR, "could not write to file %s: %s", filename, strerror(errno)); } fflush(df); fclose(df); }
void globals_save(int32_t &addr) { write_8(addr, QUEUE_LENGTH); write_8(addr, NUM_PINS); write_8(addr, num_temps); write_8(addr, num_gpios); write_16(addr, led_pin.write()); write_16(addr, stop_pin.write()); write_16(addr, probe_pin.write()); write_16(addr, spiss_pin.write()); write_16(addr, timeout); write_16(addr, bed_id); write_16(addr, fan_id); write_16(addr, spindle_id); write_float(addr, feedrate); write_float(addr, max_deviation); write_float(addr, max_v); write_8(addr, current_extruder); write_float(addr, targetx); write_float(addr, targety); write_float(addr, zoffset); write_8(addr, store_adc != NULL); }
void diff_write_packet(const char* zone, uint32_t new_serial, uint16_t id, uint32_t seq_nr, uint8_t* data, size_t len, nsd_options_t* opt) { const char* filename = opt->difffile; struct timeval tv; FILE *df; uint32_t file_len = sizeof(uint32_t) + strlen(zone) + sizeof(new_serial) + sizeof(id) + sizeof(seq_nr) + len; if (gettimeofday(&tv, NULL) != 0) { log_msg(LOG_ERR, "could not set timestamp for %s: %s", filename, strerror(errno)); return; } df = fopen(filename, "a"); if(!df) { log_msg(LOG_ERR, "could not open file %s for append: %s", filename, strerror(errno)); return; } if(!write_32(df, DIFF_PART_IXFR) || !write_32(df, (uint32_t) tv.tv_sec) || !write_32(df, (uint32_t) tv.tv_usec) || !write_32(df, file_len) || !write_str(df, zone) || !write_32(df, new_serial) || !write_16(df, id) || !write_32(df, seq_nr) || !write_data(df, data, len) || !write_32(df, file_len)) { log_msg(LOG_ERR, "could not write to file %s: %s", filename, strerror(errno)); } fclose(df); }
static int do_secret_key( IOBUF out, int ctb, PKT_secret_key *sk ) { int rc = 0; int i, nskey, npkey; IOBUF a = iobuf_temp(); /* Build in a self-enlarging buffer. */ /* Write the version number - if none is specified, use 3 */ if ( !sk->version ) iobuf_put ( a, 3 ); else iobuf_put ( a, sk->version ); write_32 (a, sk->timestamp ); /* v3 needs the expiration time. */ if ( sk->version < 4 ) { u16 ndays; if ( sk->expiredate ) ndays = (u16)((sk->expiredate - sk->timestamp) / 86400L); else ndays = 0; write_16(a, ndays); } iobuf_put (a, sk->pubkey_algo ); /* Get number of secret and public parameters. They are held in one array first the public ones, then the secret ones. */ nskey = pubkey_get_nskey ( sk->pubkey_algo ); npkey = pubkey_get_npkey ( sk->pubkey_algo ); /* If we don't have any public parameters - which is the case if we don't know the algorithm used - the parameters are stored as one blob in a faked (opaque) MPI. */ if ( !npkey ) { write_fake_data( a, sk->skey[0] ); goto leave; } assert ( npkey < nskey ); /* Writing the public parameters is easy. */ for (i=0; i < npkey; i++ ) if ((rc = mpi_write (a, sk->skey[i]))) goto leave; /* Build the header for protected (encrypted) secret parameters. */ if ( sk->is_protected ) { if ( is_RSA(sk->pubkey_algo) && sk->version < 4 && !sk->protect.s2k.mode ) { /* The simple rfc1991 (v3) way. */ iobuf_put (a, sk->protect.algo ); iobuf_write (a, sk->protect.iv, sk->protect.ivlen ); } else { /* OpenPGP protection according to rfc2440. */ iobuf_put(a, sk->protect.sha1chk? 0xfe : 0xff ); iobuf_put(a, sk->protect.algo ); if ( sk->protect.s2k.mode >= 1000 ) { /* These modes are not possible in OpenPGP, we use them to implement our extensions, 101 can be seen as a private/experimental extension (this is not specified in rfc2440 but the same scheme is used for all other algorithm identifiers) */ iobuf_put(a, 101 ); iobuf_put(a, sk->protect.s2k.hash_algo ); iobuf_write(a, "GNU", 3 ); iobuf_put(a, sk->protect.s2k.mode - 1000 ); } else { iobuf_put(a, sk->protect.s2k.mode ); iobuf_put(a, sk->protect.s2k.hash_algo ); } if ( sk->protect.s2k.mode == 1 || sk->protect.s2k.mode == 3 ) iobuf_write (a, sk->protect.s2k.salt, 8 ); if ( sk->protect.s2k.mode == 3 ) iobuf_put (a, sk->protect.s2k.count ); /* For our special modes 1001, 1002 we do not need an IV. */ if ( sk->protect.s2k.mode != 1001 && sk->protect.s2k.mode != 1002 ) iobuf_write (a, sk->protect.iv, sk->protect.ivlen ); } } else iobuf_put (a, 0 ); if ( sk->protect.s2k.mode == 1001 ) ; /* GnuPG extension - don't write a secret key at all. */ else if ( sk->protect.s2k.mode == 1002 ) { /* GnuPG extension - divert to OpenPGP smartcard. */ iobuf_put(a, sk->protect.ivlen ); /* Length of the serial number or 0 for no serial number. */ /* The serial number gets stored in the IV field. */ iobuf_write(a, sk->protect.iv, sk->protect.ivlen); } else if ( sk->is_protected && sk->version >= 4 ) { /* The secret key is protected - write it out as it is. */ byte *p; unsigned int ndatabits; assert (gcry_mpi_get_flag (sk->skey[npkey], GCRYMPI_FLAG_OPAQUE)); p = gcry_mpi_get_opaque (sk->skey[npkey], &ndatabits ); iobuf_write (a, p, (ndatabits+7)/8 ); } else if ( sk->is_protected ) { /* The secret key is protected the old v4 way. */ for ( ; i < nskey; i++ ) { byte *p; unsigned int ndatabits; assert (gcry_mpi_get_flag (sk->skey[i], GCRYMPI_FLAG_OPAQUE)); p = gcry_mpi_get_opaque (sk->skey[i], &ndatabits); iobuf_write (a, p, (ndatabits+7)/8); } write_16(a, sk->csum ); } else { /* Non-protected key. */ for ( ; i < nskey; i++ ) if ( (rc = mpi_write (a, sk->skey[i]))) goto leave; write_16 (a, sk->csum ); } leave: if (!rc) { /* Build the header of the packet - which we must do after writing all the other stuff, so that we know the length of the packet */ write_header2(out, ctb, iobuf_get_temp_length(a), sk->hdrbytes); /* And finally write it out the real stream */ rc = iobuf_write_temp( out, a ); } iobuf_close(a); /* Close the remporary buffer */ return rc; }
static cdk_error_t write_secret_key (cdk_stream_t out, cdk_pkt_seckey_t sk, int is_subkey, int old_ctb) { cdk_pkt_pubkey_t pk = NULL; size_t size = 6, npkey, nskey; int pkttype, s2k_mode; cdk_error_t rc; assert (out); assert (sk); if (!sk->pk) return CDK_Inv_Value; pk = sk->pk; if (pk->version < 2 || pk->version > 4) return CDK_Inv_Packet; if (DEBUG_PKT) _cdk_log_debug ("write_secret_key:\n"); npkey = cdk_pk_get_npkey (pk->pubkey_algo); nskey = cdk_pk_get_nskey (pk->pubkey_algo); if (!npkey || !nskey) { gnutls_assert (); return CDK_Inv_Algo; } if (pk->version < 4) size += 2; /* If the key is unprotected, the 1 extra byte: 1 octet - cipher algorithm byte (0x00) the other bytes depend on the mode: a) simple checksum - 2 octets b) sha-1 checksum - 20 octets */ size = !sk->is_protected ? size + 1 : size + 1 + calc_s2ksize (sk); size += calc_mpisize (pk->mpi, npkey); if (sk->version == 3 || !sk->is_protected) { if (sk->version == 3) { size += 2; /* force simple checksum */ sk->protect.sha1chk = 0; } else size += sk->protect.sha1chk ? 20 : 2; size += calc_mpisize (sk->mpi, nskey); } else /* We do not know anything about the encrypted mpi's so we treat the data as opaque. */ size += sk->enclen; pkttype = is_subkey ? CDK_PKT_SECRET_SUBKEY : CDK_PKT_SECRET_KEY; rc = pkt_write_head (out, old_ctb, size, pkttype); if (!rc) rc = stream_putc (out, pk->version); if (!rc) rc = write_32 (out, pk->timestamp); if (!rc && pk->version < 4) { u16 ndays = 0; if (pk->expiredate) ndays = (u16) ((pk->expiredate - pk->timestamp) / 86400L); rc = write_16 (out, ndays); } if (!rc) rc = stream_putc (out, _cdk_pub_algo_to_pgp (pk->pubkey_algo)); if (!rc) rc = write_mpibuf (out, pk->mpi, npkey); if (!rc) { if (sk->is_protected == 0) rc = stream_putc (out, 0x00); else { if (is_RSA (pk->pubkey_algo) && pk->version < 4) rc = stream_putc (out, _gnutls_cipher_to_pgp (sk->protect.algo)); else if (sk->protect.s2k) { s2k_mode = sk->protect.s2k->mode; rc = stream_putc (out, sk->protect.sha1chk ? 0xFE : 0xFF); if (!rc) rc = stream_putc (out, _gnutls_cipher_to_pgp (sk->protect.algo)); if (!rc) rc = stream_putc (out, sk->protect.s2k->mode); if (!rc) rc = stream_putc (out, sk->protect.s2k->hash_algo); if (!rc && (s2k_mode == 1 || s2k_mode == 3)) { rc = stream_write (out, sk->protect.s2k->salt, 8); if (!rc && s2k_mode == 3) rc = stream_putc (out, sk->protect.s2k->count); } } else return CDK_Inv_Value; if (!rc) rc = stream_write (out, sk->protect.iv, sk->protect.ivlen); } } if (!rc && sk->is_protected && pk->version == 4) { if (sk->encdata && sk->enclen) rc = stream_write (out, sk->encdata, sk->enclen); } else { if (!rc) rc = write_mpibuf (out, sk->mpi, nskey); if (!rc) { if (!sk->csum) sk->csum = _cdk_sk_get_csum (sk); rc = write_16 (out, sk->csum); } } return rc; }
static void do_set(int fd, int argc, const char *argv[]) { int x, y, w, h; int bpp; if (argc != 6) usage(); screen = mmap(NULL, mem_size, PROT_WRITE, MAP_SHARED, fd, 0); if (screen == MAP_FAILED) { printf("Can't mmap %s\n", argv[1]); perror("mmap"); usage(); } do_ioctl(fd, IOCTRL_GET_LCD_BPP, &bpp); if (bpp == 8) bytes_per_pixel = 1; else if (bpp == 16) bytes_per_pixel = 2; else if (bpp == 24) bytes_per_pixel = 3; else if (bpp == 32) bytes_per_pixel = 4; do_ioctl(fd, IOCTRL_GET_LCD_WIDTH, &screen_w); do_ioctl(fd, IOCTRL_GET_LCD_HEIGHT, &screen_h); printf("Screen is %lux%lu, %u bits per pixel\n", screen_w, screen_h, bpp); do_ioctl(fd, IOCTRL_DISPLAY_ENABLE, NULL); do_ioctl(fd, IOCTRL_CLEAR_LCD, NULL); x = strtoul(argv[1], NULL, 0); y = strtoul(argv[2], NULL, 0); w = strtoul(argv[3], NULL, 0); h = strtoul(argv[4], NULL, 0); val = strtoul(argv[5], NULL, 0); if ( y * screen_w + x * bytes_per_pixel > mem_size ) { printf("Would write outside of memory\n"); usage(); } switch (bytes_per_pixel) { case 1: write_8(w, h, x, y); break; case 2: write_16(w, h, x, y); break; case 3: write_24(w, h, x, y); break; case 4: write_32(w, h, x, y); break; default: printf("Illegal byte-per-pixel, bpp %d\n", bpp); usage(); break; } do_ioctl(fd, IOCTRL_UPDATE_NOW, NULL); msync(screen, mem_size, MS_SYNC); munmap(screen, mem_size); }
static cdk_error_t write_signature (cdk_stream_t out, cdk_pkt_signature_t sig, int old_ctb) { byte *buf; size_t nbytes, size, nsig; cdk_error_t rc; assert (out); assert (sig); if (!KEY_CAN_SIGN (sig->pubkey_algo)) return CDK_Inv_Algo; if (sig->version < 2 || sig->version > 4) return CDK_Inv_Packet; if (DEBUG_PKT) _cdk_log_debug ("write_signature:\n"); nsig = cdk_pk_get_nsig (sig->pubkey_algo); if (!nsig) return CDK_Inv_Algo; if (sig->version < 4) return write_v3_sig (out, sig, nsig); size = 10 + calc_subpktsize (sig->hashed) + calc_subpktsize (sig->unhashed) + calc_mpisize (sig->mpi, nsig); rc = pkt_write_head (out, 0, size, CDK_PKT_SIGNATURE); if (!rc) rc = stream_putc (out, 4); if (!rc) rc = stream_putc (out, sig->sig_class); if (!rc) rc = stream_putc (out, _cdk_pub_algo_to_pgp (sig->pubkey_algo)); if (!rc) rc = stream_putc (out, _gnutls_hash_algo_to_pgp (sig->digest_algo)); if (!rc) rc = write_16 (out, sig->hashed_size); if (!rc) { buf = _cdk_subpkt_get_array (sig->hashed, 0, &nbytes); if (!buf) return CDK_Out_Of_Core; rc = stream_write (out, buf, nbytes); cdk_free (buf); } if (!rc) rc = write_16 (out, sig->unhashed_size); if (!rc) { buf = _cdk_subpkt_get_array (sig->unhashed, 0, &nbytes); if (!buf) return CDK_Out_Of_Core; rc = stream_write (out, buf, nbytes); cdk_free (buf); } if (!rc) rc = stream_putc (out, sig->digest_start[0]); if (!rc) rc = stream_putc (out, sig->digest_start[1]); if (!rc) rc = write_mpibuf (out, sig->mpi, nsig); return rc; }
void Z80_Exec_ED(Z80_State *state, uint8_t opcode) { uint16_t addr; uint8_t tmp; //uint16_t tmp_16; switch (opcode) { case 0x40: // in b, (c) rB = in(rBC); in_f(rB); break; case 0x41: // out (c), b out(rBC, rB); break; case 0x42: // sbc hl, bc t_states(7); sbc_16(rHL, rBC); break; case 0x43: // ld (**), bc addr = arg_16(); write_16(addr, rBC); break; case 0x44: // neg neg(); break; case 0x45: // retn S(IFF1) = S(IFF2); rPC = pop_16(); break; case 0x46: // im 0 S(IM) = 0; break; case 0x47: // ld i, a t_states(1); rI = rA; break; case 0x48: // in c, (c) rC = in(rBC); in_f(rC); break; case 0x49: // out (c), c out(rBC, rC); break; case 0x4A: // adc hl, bc t_states(7); adc_16(rHL, rBC); break; case 0x4B: // ld bc, (**) addr = arg_16(); rBC = read_16(addr); break; case 0x4C: // neg neg(); break; case 0x4D: // reti rPC = pop_16(); break; case 0x4E: // im 0/1 S(IM) = 0; break; case 0x4F: // ld r, a t_states(1); rR = rA; break; case 0x50: // in d, (c) rD = in(rBC); in_f(rD); break; case 0x51: // out (c), d out(rBC, rD); break; case 0x52: // sbc hl, de t_states(7); sbc_16(rHL, rDE); break; case 0x53: // ld (**), de addr = arg_16(); write_16(addr, rDE); break; case 0x54: // neg neg(); break; case 0x55: // retn S(IFF1) = S(IFF2); rPC = pop_16(); break; case 0x56: // im 1 S(IM) = 1; break; case 0x57: // ld a, i t_states(1); rA = rI; ld_f(rA); break; case 0x58: // in e, (c) rE = in(rBC); in_f(rE); break; case 0x59: // out (c), e out(rBC, rE); break; case 0x5A: // adc hl, de t_states(7); adc_16(rHL, rDE); break; case 0x5B: // ld de, (**) addr = arg_16(); rDE = read_16(addr); break; case 0x5C: // neg neg(); break; case 0x5D: // retn S(IFF1) = S(IFF2); rPC = pop_16(); break; case 0x5E: // im 2 S(IM) = 2; break; case 0x5F: // ld a, r t_states(1); rA = rR; ld_f(rA); break; case 0x60: // in h, (c) rH = in(rBC); in_f(rH); break; case 0x61: // out (c), h out(rBC, rH); break; case 0x62: // sbc hl, hl t_states(7); sbc_16(rHL, rHL); break; case 0x63: // ld (**), hl addr = arg_16(); write_16(addr, rHL); break; case 0x64: // neg neg(); break; case 0x65: // retn S(IFF1) = S(IFF2); rPC = pop_16(); break; case 0x66: // im 0 S(IM) = 0; break; case 0x67: // rrd tmp = read(rHL); t_states(4); rrd(tmp); write(rHL, tmp); break; case 0x68: // in l, (c) rL = in(rBC); in_f(rL); break; case 0x69: // out (c), l out(rBC, rL); break; case 0x6A: // adc hl, hl t_states(7); adc_16(rHL, rHL); break; case 0x6B: // ld hl, (**) addr = arg_16(); rHL = read_16(addr); break; case 0x6C: // neg neg(); break; case 0x6D: // retn S(IFF1) = S(IFF2); rPC = pop_16(); break; case 0x6E: // im 0/1 S(IM) = 0; break; case 0x6F: // rld tmp = read(rHL); t_states(4); rld(tmp); write(rHL, tmp); break; case 0x70: // in (c) tmp = in(rBC); in_f(tmp); break; case 0x71: // out (c), 0 out(rBC, 0); break; case 0x72: // sbc hl, sp t_states(7); sbc_16(rHL, rSP); break; case 0x73: // ld (**), sp addr = arg_16(); write_16(addr, rSP); break; case 0x74: // neg neg(); break; case 0x75: // retn S(IFF1) = S(IFF2); rPC = pop_16(); break; case 0x76: // im 1 S(IM) = 1; break; case 0x78: // in a, (c) rA = in(rBC); in_f(rA); break; case 0x79: // out (c), a out(rBC, rA); break; case 0x7A: // adc hl, sp t_states(7); adc_16(rHL, rSP); break; case 0x7B: // ld sp, (**) addr = arg_16(); rSP = read_16(addr); break; case 0x7C: // neg neg(); break; case 0x7D: // retn S(IFF1) = S(IFF2); rPC = pop_16(); break; case 0x7E: // im 2 S(IM) = 2; break; case 0xA0: // ldi tmp = read(rHL++); write(rDE++, tmp); t_states(2); rBC--; ldr_f(tmp); break; case 0xA1: // cpi tmp = read(rHL++); t_states(5); rBC--; cpr_f(tmp); break; case 0xA2: // ini t_states(1); tmp = in(rBC); write(rHL++, tmp); rB--; inir_f(tmp); break; case 0xA3: // outi t_states(1); tmp = read(rHL++); rB--; out(rBC, tmp); outr_f(tmp); break; case 0xA8: // ldd tmp = read(rHL--); write(rDE--, tmp); t_states(2); rBC--; ldr_f(tmp); break; case 0xA9: // cpd tmp = read(rHL--); t_states(5); rBC--; cpr_f(tmp); break; case 0xAA: // ind t_states(1); tmp = in(rBC); write(rHL--, tmp); rB--; indr_f(tmp); break; case 0xAB: // outd t_states(1); tmp = read(rHL--); rB--; out(rBC, tmp); outr_f(tmp); break; case 0xB0: // ldir tmp = read(rHL++); write(rDE++, tmp); t_states(2); rBC--; ldr_f(tmp); if (rBC) { t_states(5); rep(); } break; case 0xB1: // cpir tmp = read(rHL++); t_states(5); rBC--; cpr_f(tmp); if (rBC && !(rF & fZ)) { t_states(5); rep(); } break; case 0xB2: // inir t_states(1); tmp = in(rBC); write(rHL++, tmp); rB--; inir_f(tmp); if (rB) { t_states(5); rep(); } break; case 0xB3: // otir t_states(1); tmp = read(rHL++); rB--; out(rBC, tmp); outr_f(tmp); if (rB) { t_states(5); rep(); } break; case 0xB8: // lddr tmp = read(rHL--); write(rDE--, tmp); t_states(2); rBC--; ldr_f(tmp); if (rBC) { t_states(5); rep(); } break; case 0xB9: // cpdr tmp = read(rHL--); t_states(5); rBC--; cpr_f(tmp); if (rBC && !(rF & fZ)) { t_states(5); rep(); } break; case 0xBA: // indr t_states(1); tmp = in(rBC); write(rHL--, tmp); rB--; indr_f(tmp); if (rB) { t_states(5); rep(); } break; case 0xBB: // otdr t_states(1); tmp = read(rHL--); rB--; out(rBC, tmp); outr_f(tmp); if (rB) { t_states(5); rep(); } break; } }
void sf240320_initialize(uint8_t data_bus_width) { // Set up the data pins set_port_mode(false); pullUpDnControl(data_bus.DB0, PUD_DOWN); pullUpDnControl(data_bus.DB1, PUD_DOWN); pullUpDnControl(data_bus.DB2, PUD_DOWN); pullUpDnControl(data_bus.DB3, PUD_DOWN); pullUpDnControl(data_bus.DB4, PUD_DOWN); pullUpDnControl(data_bus.DB5, PUD_DOWN); pullUpDnControl(data_bus.DB6, PUD_DOWN); pullUpDnControl(data_bus.DB7, PUD_DOWN); pullUpDnControl(data_bus.DB8, PUD_DOWN); pullUpDnControl(data_bus.DB9, PUD_DOWN); pullUpDnControl(data_bus.DB10, PUD_DOWN); pullUpDnControl(data_bus.DB11, PUD_DOWN); pullUpDnControl(data_bus.DB12, PUD_DOWN); pullUpDnControl(data_bus.DB13, PUD_DOWN); pullUpDnControl(data_bus.DB14, PUD_DOWN); pullUpDnControl(data_bus.DB15, PUD_DOWN); // Initialize data pins digitalWrite(data_bus.DB0, LOW); digitalWrite(data_bus.DB1, LOW); digitalWrite(data_bus.DB2, LOW); digitalWrite(data_bus.DB3, LOW); digitalWrite(data_bus.DB4, LOW); digitalWrite(data_bus.DB5, LOW); digitalWrite(data_bus.DB6, LOW); digitalWrite(data_bus.DB7, LOW); digitalWrite(data_bus.DB8, LOW); digitalWrite(data_bus.DB9, LOW); digitalWrite(data_bus.DB10, LOW); digitalWrite(data_bus.DB11, LOW); digitalWrite(data_bus.DB12, LOW); digitalWrite(data_bus.DB13, LOW); digitalWrite(data_bus.DB14, LOW); digitalWrite(data_bus.DB15, LOW); // Set up the control pins pinMode(control_bus.data_bus_width, OUTPUT); pinMode(control_bus.dat_com_sel, OUTPUT); pinMode(control_bus.write, OUTPUT); pinMode(control_bus.read, OUTPUT); pinMode(control_bus.reset, OUTPUT); // Initialize control pins if(data_bus_width == 16) { digitalWrite(control_bus.data_bus_width, LOW); write = write_16; } else //if(data_bus_width == 8) { digitalWrite(control_bus.data_bus_width, HIGH); write = write_8; } digitalWrite(control_bus.dat_com_sel, LOW); digitalWrite(control_bus.write, HIGH); digitalWrite(control_bus.read, HIGH); // Reset digitalWrite(control_bus.reset, LOW); delay(120); digitalWrite(control_bus.reset, HIGH); delay(120); // Turn off display write_16(true, 0x28); // Exit sleep mode write_16(true, 0x11); write_16(false, 0x00); // Power control a write_16(true, 0xCB); write_16(false, 0x39); write_16(false, 0x2C); write_16(false, 0x00); write_16(false, 0x34); write_16(false, 0x02); // Power control b write_16(true, 0xCF); write_16(false, 0x00); write_16(false, 0x81); write_16(false, 0x30); // Driver timing control a write_16(true, 0xE8); write_16(false, 0x85); write_16(false, 0x01); write_16(false, 0x79); // Driver timing control b write_16(true, 0xEA); write_16(false, 0x00); write_16(false, 0x00); // Power-on sequence control write_16(true, 0xED); write_16(false, 0x64); write_16(false, 0x03); write_16(false, 0x12); write_16(false, 0x81); // Pump ratio control write_16(true, 0xF7); write_16(false, 0x20); // Power control 1 write_16(true, 0xC0); write_16(false, 0x26); write_16(false, 0x04); // Power cotnrol 2 write_16(true, 0xC1); write_16(false, 0x11); // VCOM control 1 write_16(true, 0xC5); write_16(false, 0x35); write_16(false, 0x3E); // VCOM control 2 write_16(true, 0xC7); write_16(false, 0xBE); // Memory access is BGR write_16(true, 0x36); write_16(false, 0x08); // Frame rate control write_16(true, 0xB1); write_16(false, 0x00); write_16(false, 0x10); // Display function control write_16(true, 0xB6); write_16(false, 0x0A); write_16(false, 0xA2); // Pixel format is 16-bit write_16(true, 0x3A); write_16(false, 0x55); // 3G gamma control is off write_16(true, 0xF2); write_16(false, 0x02); // Gamme curve 3 write_16(true, 0x26); write_16(false, 0x01); // Column address: start at 0x00, end at 0xEF write_16(true, 0x2A); write_16(false, 0x00); write_16(false, 0x00); write_16(false, 0x00); write_16(false, 0xEF); // Page address: start at 0x00, end at 0x13F write_16(true, 0x2B); write_16(false, 0x00); write_16(false, 0x00); write_16(false, 0x01); write_16(false, 0x3F); // Turn on display write_16(true, 0x29); }
Buffer::Pointer Buffer::write(uint16_t in_value) throw(KafkaError) { write_16(&in_value); return shared_from_this(); }