void vm_hw_lem1802_write(vm_t* vm, uint16_t pos, void* ud) { uint16_t location_screen, location_font, location_palette; struct lem1802_hardware* hw = (struct lem1802_hardware*)ud; location_screen = vm_hw_lem1802_mem_get_screen(hw); location_font = vm_hw_lem1802_mem_get_font(hw); location_palette = hw->palette_location; // Are we updating a general cell? if (location_screen != HW_LEM1802_DISCONNECTED && pos >= location_screen && pos <= location_screen + 0x17F) { hw->screen_was_updated = 1; } // Are we updating a font character? else if (location_font != HW_LEM1802_DEFAULT_FONT_LOC && pos >= location_font && pos < location_font + 0x100) { //printf("updatefont at pos %x\n", location_font); hw->screen_was_updated = 1; } else if (location_palette != HW_LEM1802_DEFAULT_PALETTE_LOC && pos >= location_palette && pos < location_palette + 0x10) { hw->screen_was_updated = 1; hw->border_was_updated = 1; } }
void vm_hw_lem1802_update_texture(struct lem1802_hardware* hw) { uint16_t pos, val, location_screen; unsigned int x, y, i; location_screen = vm_hw_lem1802_mem_get_screen(hw); if (location_screen != HW_LEM1802_DISCONNECTED) { i = 0; if (hw->screen_was_updated) { for (pos = location_screen; pos <= location_screen + 0x17F; pos++) { val = hw->vm->ram[pos]; x = i % HW_LEM1802_SCREEN_WIDTH; y = i / HW_LEM1802_SCREEN_WIDTH; vm_hw_lem1802_mem_put_char_to_screen(hw, val, x, y); i++; } hw->screen_was_updated = 0; hw->texture_has_changed = 1; } // update border if (hw->border_was_updated) { vm_hw_lem1802_mem_draw_border(hw); hw->border_was_updated = 0; hw->texture_has_changed = 1; } } else { if (hw->screen_was_updated) { for (i = 0; i < HW_LEM1802_SCREEN_TEXTURE_MEM_SIZE; i++) { hw->glfw_texture[i] = 0; } hw->screen_was_updated = 0; hw->texture_has_changed = 1; } if (hw->border_was_updated) { vm_hw_lem1802_mem_draw_border(hw); hw->border_was_updated = 0; hw->texture_has_changed = 1; } } }
void vm_hw_lem1802_write(vm_t* vm, uint16_t pos) { unsigned int i = 0, x = 0, y = 0, fx = 0, fy = 0; uint16_t val, fore, back, chr; TCOD_color_t foreclr, backclr; uint16_t location_font, location_screen; uint16_t char_width, char_height; TCOD_image_t char_image = NULL; uint16_t ax = 0, ay = 0; TCOD_color_t color_black = { 0, 0, 0 }; TCOD_color_t color_white = { 255, 255, 255 }; // Get the current memory-mapping positions. location_font = vm_hw_lem1802_mem_get_font(vm); location_screen = vm_hw_lem1802_mem_get_screen(vm); // Get the font character width / height. char_width = vm_hw_lem1802_mem_get_font_char_width(); char_height = vm_hw_lem1802_mem_get_font_char_height(); char_image = vm_hw_lem1802_mem_get_font_image(); // Are we updating a general cell? if (location_screen != 0 && pos >= location_screen && pos <= location_screen + 0x17F) { // Read memory value. i = pos; val = vm->ram[i]; // Get foreground, background and character components. fore = (val & 0xF000) >> 12; back = (val & 0x0F00) >> 8; chr = (val & 0x00FF); // Create TCOD colours. foreclr = vm_hw_lem1802_mem_get_palette_color(vm, fore); backclr = vm_hw_lem1802_mem_get_palette_color(vm, back); // Calculate X / Y. x = (i - location_screen) % HW_LEM1802_SCREEN_WIDTH; y = (i - location_screen) / HW_LEM1802_SCREEN_WIDTH; // Update TCOD. TCOD_console_put_char_ex(NULL, x + 1, y + 1, chr, foreclr, backclr ); }