public static void chplft_draw_bg(osd_bitmap bitmap, int priority) {
        int sx, sy, offs;
        int choplifter_scroll_x_on = (system1_scrollx_ram.read(0) == 0xE5 && system1_scrollx_ram.read(1) == 0xFF) ? 0 : 1;

        if (priority == -1) {
            /* optimized far background */

            /* for every character in the background video RAM, check if it has
             * been modified since last time and update it accordingly.
             */
            for (offs = 0; offs < system1_backgroundram_size[0]; offs += 2) {
                if (bg_dirtybuffer[offs / 2] != 0) {
                    int code, color;

                    bg_dirtybuffer[offs / 2] = 0;

                    code = (system1_backgroundram.read(offs) | (system1_backgroundram.read(offs + 1) << 8));
                    code = ((code >> 4) & 0x800) | (code & 0x7ff);	/* Heavy Metal only */

                    color = ((code >> 5) & 0x3f) + 0x40;
                    sx = (offs / 2) % 32;
                    sy = (offs / 2) / 32;

                    drawgfx(bitmap1, Machine.gfx[0],
                            code,
                            color,
                            0, 0,
                            8 * sx, 8 * sy,
                            null, TRANSPARENCY_NONE, 0);
                }
            }

            /* copy the temporary bitmap to the screen */
            if (choplifter_scroll_x_on != 0) {
                copyscrollbitmap(bitmap, bitmap1, 32, scrollx_row, 0, null, Machine.drv.visible_area, TRANSPARENCY_NONE, 0);
            } else {
                copybitmap(bitmap, bitmap1, 0, 0, 0, 0, Machine.drv.visible_area, TRANSPARENCY_NONE, 0);
            }
        } else {
            priority <<= 3;

            for (offs = 0; offs < system1_backgroundram_size[0]; offs += 2) {
                if ((system1_backgroundram.read(offs + 1) & 0x08) == priority) {
                    int code, color;

                    code = (system1_backgroundram.read(offs) | (system1_backgroundram.read(offs + 1) << 8));
                    code = ((code >> 4) & 0x800) | (code & 0x7ff);	/* Heavy Metal only */

                    color = ((code >> 5) & 0x3f) + 0x40;
                    sx = 8 * ((offs / 2) % 32);
                    sy = (offs / 2) / 32;

                    if (choplifter_scroll_x_on != 0) {
                        sx = (sx + scrollx_row[sy]) & 0xff;
                    }
                    sy = 8 * sy;

                    drawgfx(bitmap, Machine.gfx[0],
                            code,
                            color,
                            0, 0,
                            sx, sy,
                            Machine.drv.visible_area, TRANSPARENCY_PEN, 0);
                }
            }
        }
    }