// Gioco snake :P void main_snake() { // Prima cosa, sposto la pagina 0 sulla pagina 1 // In sostanza copio da 0xB8000 a 0xB8FFF, su 0xB9000 memcpyb(0xB9000, 0xB8000, 0x1000); unsigned char *Sbuffer = get_page(1); tmpfs_read("pixmap.sk", Sbuffer); //video_scrivi_stringa(Sbuffer); // Ora posso scrivere tranquillamente sullo schermo: memcpyb(0xB8000, Sbuffer, 0x1000); free_page(Sbuffer); }
/** Function 01h - Return VBE Mode Information * * Input: * AX = 4F01h * CX = Mode Number * ES:DI = Pointer to buffer in which to place ModeInfoBlock structure * Output: * AX = VBE Return Status * */ void vbe_biosfn_return_mode_information(uint16_t STACK_BASED *AX, uint16_t CX, uint16_t ES, uint16_t DI) { uint16_t result = 0x0100; #ifdef VBE_NEW_DYN_LIST uint16_t cur_info_ofs; #else ModeInfoListItem *cur_info; #endif Boolean using_lfb; uint8_t win_attr; #ifdef VGA_DEBUG printf("VBE vbe_biosfn_return_mode_information ES%x DI%x CX%x\n",ES,DI,CX); #endif using_lfb = ((CX & VBE_MODE_LINEAR_FRAME_BUFFER) == VBE_MODE_LINEAR_FRAME_BUFFER); CX = (CX & 0x1ff); #ifdef VBE_NEW_DYN_LIST cur_info_ofs = mode_info_find_mode(CX, using_lfb); if (cur_info_ofs) { uint16_t i; #else cur_info = mode_info_find_mode(CX, using_lfb); if (cur_info != 0) { #endif #ifdef VGA_DEBUG printf("VBE found mode %x\n",CX); #endif memsetb(ES, DI, 0, 256); // The mode info size is fixed #ifdef VBE_NEW_DYN_LIST for (i = 0; i < sizeof(ModeInfoBlockCompact); i++) { uint8_t b; b = in_byte(VBE_EXTRA_PORT, cur_info_ofs + offsetof(ModeInfoListItem, info) + i/*(char *)(&(cur_info->info)) + i*/); write_byte(ES, DI + i, b); } #else memcpyb(ES, DI, 0xc000, &(cur_info->info), sizeof(ModeInfoBlockCompact)); #endif win_attr = read_byte(ES, DI + offsetof(ModeInfoBlock, WinAAttributes)); if (win_attr & VBE_WINDOW_ATTRIBUTE_RELOCATABLE) { write_word(ES, DI + offsetof(ModeInfoBlock, WinFuncPtr), (uint16_t)(dispi_set_bank_farcall)); // If BIOS not at 0xC000 -> boom write_word(ES, DI + offsetof(ModeInfoBlock, WinFuncPtr) + 2, 0xC000); } // Update the LFB physical address which may change at runtime out_w(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_FB_BASE_HI); write_word(ES, DI + offsetof(ModeInfoBlock, PhysBasePtr) + 2, in_w(VBE_DISPI_IOPORT_DATA)); result = 0x4f; } else { #ifdef VGA_DEBUG printf("VBE *NOT* found mode %x\n",CX); #endif result = 0x100; } *AX = result; } /** Function 02h - Set VBE Mode * * Input: * AX = 4F02h * BX = Desired Mode to set * ES:DI = Pointer to CRTCInfoBlock structure * Output: * AX = VBE Return Status * */ void vbe_biosfn_set_mode(uint16_t STACK_BASED *AX, uint16_t BX, uint16_t ES, uint16_t DI) { uint16_t result; #ifdef VBE_NEW_DYN_LIST uint16_t cur_info_ofs; #else ModeInfoListItem *cur_info; #endif Boolean using_lfb; uint8_t no_clear; uint8_t lfb_flag; using_lfb = ((BX & VBE_MODE_LINEAR_FRAME_BUFFER) == VBE_MODE_LINEAR_FRAME_BUFFER); lfb_flag = using_lfb ? VBE_DISPI_LFB_ENABLED : 0; no_clear = ((BX & VBE_MODE_PRESERVE_DISPLAY_MEMORY) == VBE_MODE_PRESERVE_DISPLAY_MEMORY) ? VBE_DISPI_NOCLEARMEM : 0; BX = (BX & 0x1ff); // check for non vesa mode if (BX < VBE_MODE_VESA_DEFINED) { uint8_t mode; dispi_set_enable(VBE_DISPI_DISABLED); // call the vgabios in order to set the video mode // this allows for going back to textmode with a VBE call (some applications expect that to work) mode = (BX & 0xff); biosfn_set_video_mode(mode); result = 0x4f; goto leave; } #ifdef VBE_NEW_DYN_LIST cur_info_ofs = mode_info_find_mode(BX, using_lfb); if (cur_info_ofs != 0) { uint16_t xres, yres; uint8_t bpp; xres = in_word(VBE_EXTRA_PORT, cur_info_ofs + offsetof(ModeInfoListItem, info.XResolution) /*&cur_info->info.XResolution*/); yres = in_word(VBE_EXTRA_PORT, cur_info_ofs + offsetof(ModeInfoListItem, info.YResolution) /*&cur_info->info.YResolution*/); bpp = in_byte(VBE_EXTRA_PORT, cur_info_ofs + offsetof(ModeInfoListItem, info.BitsPerPixel) /*&cur_info->info.BitsPerPixel*/); #ifdef VGA_DEBUG printf("VBE found mode %x, setting:\n", BX); printf("\txres%x yres%x bpp%x\n", xres, yres, bpp); #endif #else cur_info = mode_info_find_mode(BX, using_lfb); if (cur_info != 0) { #ifdef VGA_DEBUG printf("VBE found mode %x, setting:\n", BX); printf("\txres%x yres%x bpp%x\n", cur_info->info.XResolution, cur_info->info.YResolution, cur_info->info.BitsPerPixel); #endif #endif // VBE_NEW_DYN_LIST // first disable current mode (when switching between vesa modi) dispi_set_enable(VBE_DISPI_DISABLED); #ifdef VBE_NEW_DYN_LIST if (bpp == 4) #else if (cur_info->info.BitsPerPixel == 4) #endif { biosfn_set_video_mode(0x6a); } #ifdef VBE_NEW_DYN_LIST dispi_set_bpp(bpp); dispi_set_xres(xres); dispi_set_yres(yres); #else dispi_set_bpp(cur_info->info.BitsPerPixel); dispi_set_xres(cur_info->info.XResolution); dispi_set_yres(cur_info->info.YResolution); #endif dispi_set_bank(0); dispi_set_enable(VBE_DISPI_ENABLED | no_clear | lfb_flag); vga_compat_setup(); write_word(BIOSMEM_SEG,BIOSMEM_VBE_MODE,BX); write_byte(BIOSMEM_SEG,BIOSMEM_VIDEO_CTL,(0x60 | no_clear)); result = 0x4f; } else { #ifdef VGA_DEBUG printf("VBE *NOT* found mode %x\n" , BX); #endif result = 0x100; } leave: *AX = result; } uint16_t vbe_biosfn_read_video_state_size(void) { return 9 * 2; } void vbe_biosfn_save_video_state(uint16_t ES, uint16_t BX) { uint16_t enable, i; outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_ENABLE); enable = inw(VBE_DISPI_IOPORT_DATA); write_word(ES, BX, enable); BX += 2; if (!(enable & VBE_DISPI_ENABLED)) return; for(i = VBE_DISPI_INDEX_XRES; i <= VBE_DISPI_INDEX_Y_OFFSET; i++) { if (i != VBE_DISPI_INDEX_ENABLE) { outw(VBE_DISPI_IOPORT_INDEX, i); write_word(ES, BX, inw(VBE_DISPI_IOPORT_DATA)); BX += 2; } } }
void writestringattr(uint16_t *buf, unsigned short ofs, const uint16_t *str, unsigned short len) { memcpyb(buf+ofs, (void *)str, len*2); }