EMU8086中如何通过代码强制固定80*25显示尺寸?
Hey there! This is a super common hiccup when working with legacy DOS text-mode code in emulators like EMU8086. Let's break down why your code breaks when maximizing the window, and exactly how to force the display to stick to 80x25 resolution no matter what.
Why Your Code Breaks
Your current code directly writes to the VGA text-mode memory at 0B800h, and it assumes a fixed screen layout:
- 80 columns per line (each character takes 2 bytes, so 160 bytes per line)
- 25 total lines
When you maximize the EMU8086 window, the emulator switches to a higher-resolution text mode (191x63 in your case), which changes the bytes-per-line count (now 382 bytes per line) and total lines. Your hardcoded offsets (like adding 160 for the next line) no longer match the actual memory layout, causing the text and box to display incorrectly.
The Fix: Force 80x25 Text Mode via BIOS Interrupt
DOS/BIOS provides a way to explicitly set the video mode using the INT 10h interrupt. We'll use this to lock the display into 80x25 color text mode (mode 3), which will keep the memory layout consistent even if the emulator window is resized.
Add this code at the start of your program, right after you initialize the data segment:
mov ax, 0b800h mov ds, ax ; --- Add this block to force 80x25 mode --- mov ah, 00h ; INT 10h function: Set Video Mode mov al, 03h ; Mode 3 = 80x25 color text mode int 10h ; Call BIOS video interrupt ; ----------------------------------------- mov bx, 0 Main: call dltru ; ... rest of your code ...
How This Works
- The
INT 10hinterrupt withah=00htells the BIOS to switch to the video mode specified inal. - Mode 3 is the standard 80x25 color text mode that your code was designed for.
- EMU8086 respects this BIOS setting: even if you maximize the window, it will render the 80x25 display within the larger window, keeping the 160-bytes-per-line memory layout intact. Your original offset calculations will work perfectly now.
Modified Full Code
Here's your complete code with the mode-setting block added:
mov ax, 0b800h mov ds, ax ; Force 80x25 color text mode mov ah, 00h mov al, 03h int 10h mov bx, 0 Main: call dltru dltru: ; diagonal left to right upper mov bx,0 mov si,0 mov cx,21 lower2: call box mov [bx+160+2+si],' ' mov [bx+160+4+si],'M' mov [bx+160+6+si],'O' mov [bx+160+8+si],'E' mov [bx+160+10+si],' ' mov [bx+160+12+si],'S' mov [bx+160+14+si],'A' mov [bx+160+16+si],'Y' mov [bx+160+18+si],'E' mov [bx+160+20+si],'L' mov [bx+160+22+si],' ' mov [bx+160+24+si],'F' mov [bx+160+26+si],'A' mov [bx+160+28+si],'L' mov [bx+160+30+si],'A' mov [bx+160+32+si],'H' mov [bx+160+34+si],' ' call delete add si,160 add bx,6 loop lower2 ret Box: ;this will draw the box around the announcement! ;left mov [0+bx+si],0B2h mov [160+bx+si],0B2h mov [320+bx+si],0B2h ;right mov [36+bx+si],0B2h mov [196+bx+si],0B2h mov [356+bx+si],0B2h ;upper mov [2+bx+si],0B2h mov [4+bx+si],0B2h mov [6+bx+si],0B2h mov [8+bx+si],0B2h mov [10+bx+si],0B2h mov [12+bx+si],0B2h mov [14+bx+si],0B2h mov [16+bx+si],0B2h mov [18+bx+si],0B2h mov [20+bx+si],0B2h mov [22+bx+si],0B2h mov [24+bx+si],0B2h mov [26+bx+si],0B2h mov [28+bx+si],0B2h mov [30+bx+si],0B2h mov [32+bx+si],0B2h mov [34+bx+si],0B2h ;lower mov [322+bx+si],0B2h mov [324+bx+si],0B2h mov [326+bx+si],0B2h mov [328+bx+si],0B2h mov [330+bx+si],0B2h mov [332+bx+si],0B2h mov [334+bx+si],0B2h mov [336+bx+si],0B2h mov [338+bx+si],0B2h mov [340+bx+si],0B2h mov [342+bx+si],0B2h mov [344+bx+si],0B2h mov [346+bx+si],0B2h mov [348+bx+si],0B2h mov [350+bx+si],0B2h mov [352+bx+si],0B2h mov [354+bx+si],0B2h ret delete: mov [bx+162+si],' ' mov [bx+164+si],' ' mov [bx+166+si],' ' mov [bx+168+si],' ' mov [bx+170+si],' ' mov [bx+172+si],' ' mov [bx+174+si],' ' mov [bx+176+si],' ' mov [bx+178+si],' ' mov [bx+180+si],' ' mov [bx+182+si],' ' mov [bx+184+si],' ' mov [bx+186+si],' ' mov [bx+188+si],' ' mov [bx+190+si],' ' mov [bx+192+si],' ' mov [bx+194+si],' ' ;left mov [0+bx+si],' ' mov [160+bx+si],' ' mov [320+bx+si],' ' ;right mov [36+bx+si],' ' mov [196+bx+si],' ' mov [356+bx+si],' ' ;upper mov [2+bx+si],' ' mov [4+bx+si],' ' mov [6+bx+si],' ' mov [8+bx+si],' ' mov [10+bx+si],' ' mov [12+bx+si],' ' mov [14+bx+si],' ' mov [16+bx+si],' ' mov [18+bx+si],' ' mov [20+bx+si],' ' mov [22+bx+si],' ' mov [24+bx+si],' ' mov [26+bx+si],' ' mov [28+bx+si],' ' mov [30+bx+si],' ' mov [32+bx+si],' ' mov [34+bx+si],' ' ;lower mov [322+bx+si],' ' mov [324+bx+si],' ' mov [326+bx+si],' ' mov [328+bx+si],' ' mov [330+bx+si],' ' mov [332+bx+si],' ' mov [334+bx+si],' ' mov [336+bx+si],' ' mov [338+bx+si],' ' mov [340+bx+si],' ' mov [342+bx+si],' ' mov [344+bx+si],' ' mov [346+bx+si],' ' mov [348+bx+si],' ' mov [350+bx+si],' ' mov [352+bx+si],' ' mov [354+bx+si],' ' ret
内容的提问来源于stack exchange,提问作者M.Sayel

