void draw_stars(bitmap_ind16 bitmap, rectangle cliprect) { /* draw the stars */ /* $a005 controls the stars ON/OFF */ if (m_videolatch.target.q5_r() == 1) { int star_cntr; int set_a, set_b; /* two sets of stars controlled by these bits */ set_a = m_videolatch.target.q3_r(); set_b = m_videolatch.target.q4_r() | 2; for (star_cntr = 0; star_cntr < MAX_STARS; star_cntr++) { int x; int y; if ((set_a == s_star_seed_tab[star_cntr].set) || (set_b == s_star_seed_tab[star_cntr].set)) { x = (int)((s_star_seed_tab[star_cntr].x + m_stars_scrollx) % 256 + 16); y = (int)((112 + s_star_seed_tab[star_cntr].y + m_stars_scrolly) % 256); /* 112 is a tweak to get alignment about perfect */ if (cliprect.contains(x, y)) { //bitmap.pix16(y, x) = STARS_COLOR_BASE + m_star_seed_tab[ star_cntr ].col; RawBuffer bitmapBuffer; UInt32 bitmapBufferOffset = bitmap.pix16(out bitmapBuffer, y, x); bitmapBuffer.set_uint16((int)bitmapBufferOffset, (UInt16)(STARS_COLOR_BASE + s_star_seed_tab[star_cntr].col)); } } } } }
public void draw_starfield(bitmap_ind16 bitmap, rectangle cliprect, int flip) { if (m_enable == 0) { return; } uint16_t pre_vis_cycle_count = m_pre_vis_cycle_count; uint16_t post_vis_cycle_count = m_post_vis_cycle_count; // Advance the LFSR during the pre-visible portion of the frame do { m_lfsr = get_next_lfsr_state(m_lfsr); } while ((--pre_vis_cycle_count) != 0); // Now we are in visible portion of the frame - Output all LFSR hits here for (int y = m_offset_y; y < VISIBLE_LINES + m_offset_y; y++) { for (int x = m_offset_x; x < STARFIELD_PIXEL_WIDTH + m_offset_x; x++) { // Check lfsr for hit if ((m_lfsr & LFSR_HIT_MASK) == LFSR_HIT_VALUE) { uint8_t star_set = (uint8_t)bitswap(m_lfsr, 10, 8); if ((m_set_a == star_set) || (m_set_b == star_set)) { // don't draw the stars that are beyond the X limit if (x < m_limit_x) { int dx = x; if (flip != 0) { dx += 64; } if (cliprect.contains(dx, y)) { uint8_t color; color = (uint8_t)((m_lfsr >> 5) & 0x7); color |= (uint8_t)((m_lfsr << 3) & 0x18); color |= (uint8_t)((m_lfsr << 2) & 0x20); color = (uint8_t)((~color) & 0x3F); bitmap.pix(y, dx)[0] = (uint16_t)(STARS_COLOR_BASE + color); } } } } // Advance LFSR m_lfsr = get_next_lfsr_state(m_lfsr); } } // Advance the LFSR during the post-visible portion of the frame do { m_lfsr = get_next_lfsr_state(m_lfsr); } while ((--post_vis_cycle_count) != 0); }