【问题标题】:How to create and draw sprites in emu8086?如何在emu8086中创建和绘制精灵?
【发布时间】:2019-03-01 04:11:27
【问题描述】:

我获得了一项任务,我需要使用 emu8086 创建游戏。

但问题是我不知道如何绘制精灵。

谁能帮我解释一下精灵的创建?

【问题讨论】:

  • 如何绘制精灵取决于在哪里绘制精灵。换句话说,您要在其上绘制脚本的设备的规格是必需的。
  • 你能告诉我如何在emu8086上画画吗?
  • 如果 emu8086 忠实地模拟带有 BIOS 的 8086 PC 并支持 CGA、EGA 或 VGA,您需要查找有关如何在各种图形模式下对其进行编程的信息。

标签: assembly emu8086


【解决方案1】:

你能告诉我如何在emu8086上画画吗?

首先设置图形视频模式。接下来的代码选择 320x200 256 色模式:

mov     ax, 0013h  ; AH=00h is BIOS.SetVideoMode, AL=13h is 320x200 mode
int     10h

现在您可以绘制任何您喜欢的像素。下面是一个在屏幕中心绘制单个像素的示例:

mov     dx, 100    ; Y = 200 / 2
mov     cx, 160    ; X = 320 / 2
mov     bh, 0      ; DisplayPage
mov     ax, 0C02h  ; AH=0Ch is BIOS.WritePixel, AL=2 is color green
int     10h

要绘制一条线,您可以在更改一个或两个坐标的同时重复绘制一个像素。下面是绘制垂直线 (100,50) - (100,150) 的示例。这条线有 101 个像素 (150 - 50 + 1):

    mov     bh, 0      ; DisplayPage doesn't change
    mov     cx, 100    ; X is fixed for a vertical line
    mov     dx, 50     ; Y to start
More:
    mov     ax, 0C04h  ; AH=0Ch is BIOS.WritePixel, AL=4 is color red
    int     10h
    inc     dx         ; Next Y
    cmp     dx, 150
    jbe     More

要绘制一个区域,您可以使用几个嵌套循环。下面是一个在 (200,33) - (209,35) 之间绘制矩形的示例。这个区域有 30 个像素 (209 - 200 + 1) * (35 - 33 + 1):

    mov     si, Bitmap
    mov     bh, 0      ; DisplayPage doesn't change
    mov     dx, 33     ; Y to start
OuterLoop:
    mov     cx, 200    ; X to start
InnerLoop:
    lodsb              ; Fetch color for this pixel
    mov     ah, 0Ch    ; AH=0Ch is BIOS.WritePixel
    int     10h
    inc     cx         ; Next X
    cmp     cx, 209
    jbe     InnerLoop
    inc     dx         ; Next Y
    cmp     dx, 35
    jbe     OuterLoop

    ...

Bitmap:                ; Just some blue and cyan pixels
    db      1, 3, 1, 3, 1, 3, 1, 3, 1, 3
    db      3, 1, 3, 1, 3, 1, 3, 1, 3, 1
    db      1, 3, 1, 3, 1, 3, 1, 3, 1, 3 

【讨论】:

    猜你喜欢
    • 2022-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多