DOSBox像素不对齐问题求助:汇编代码像素定位异常
Let’s break down why your pixels are landing in the wrong spot in DOSBox, even when you’ve verified your X/Y coordinates look correct. Based on your code snippet and the red-circled error in your image, here are the most likely issues and fixes:
1. Incorrect Video Mode Setup
Looking at your code, you’re using:
mov ax, 1003h int 10h
This is a common mix-up. The int 10h interrupt’s AH=10h handles palette operations, not setting the video display mode. If you haven’t explicitly switched to a graphics mode first, DOSBox is probably stuck in default text mode (03h), where each "pixel" you try to draw maps to an 8x16 character cell instead of individual screen pixels—this is a guaranteed way to get misalignment.
Fix: Add a proper graphics mode setup at the start of your code. For VGA 320x200 (256-color, ideal for pixel drawing), use:
mov ax, 0013h ; Set VGA 320x200 graphics mode int 10h
Adjust the AL value if you need a different resolution (e.g., 0012h for 640x480 16-color).
2. Missing/Incorrect Pixel-Drawing Code
Your snippet cuts off after the screen-clearing routine (ax=0600h), so we don’t see how you’re actually rendering pixels. If you’re using int 10h AH=0Ch (the standard pixel-drawing function), double-check these critical parameters:
BH: Must be set to the video page number (almost always0for graphics modes)CX: X coordinate (must fit within your mode’s range—e.g., 0-319 for 320x200)DX: Y coordinate (0-199 for 320x200)AL: Color value (matches your palette configuration)
Example of correct pixel-drawing code:
mov ah, 0Ch ; Function: Draw single pixel mov al, 0Fh ; White color (adjust based on your palette) mov bh, 0 ; Video page 0 mov cx, 150 ; X coordinate (center of 320x200 screen) mov dx, 100 ; Y coordinate (center of 320x200 screen) int 10h
3. DOSBox Scaling Settings Causing Visual Misalignment
DOSBox’s built-in scalers can stretch or pixel-double the output, which might make correctly placed pixels appear misaligned on your modern screen.
Fix:
- Open your
dosbox.conffile (usually in the same folder as your DOSBox executable) - Locate the
[sdl]section - Update the
scalerline to:scaler=none - Save the file and restart DOSBox. This disables all scaling, showing the raw, unmodified pixel output.
4. Coordinate Overflow or Wrong Register Usage
If you’re calculating X/Y coordinates dynamically, make sure you’re using 16-bit registers (CX/DX) instead of 8-bit ones (CL/CH/DL/DH). For example, storing an X coordinate of 300 in CL (which only holds 0-255) will wrap it to 44, causing a massive misalignment.
Check: Verify all coordinate values fit within 16-bit limits and that you’re loading them directly into CX (for X) and DX (for Y), not splitting them into 8-bit halves unless you’re doing explicit byte-wise calculations.
内容的提问来源于stack exchange,提问作者Justine Cortez

