assembly - 如何在emu8086中创建和绘制 Sprite ?

标签 assembly emu8086

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

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

谁能帮我解释 Sprite 的创建?

最佳答案

Can you tell me how to draw on 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 

关于assembly - 如何在emu8086中创建和绘制 Sprite ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54937822/

相关文章:

assembly - 8086随机数生成器(不仅仅是使用系统时间)?

assembly - 如何使用 TEST 指令来查看是否设置了两个位?

c - MIPS 嵌套函数调用

windows - 指向 PE 文件中偏移量 0x3c 处的 PE header 的指针是否始终设置为 0x80?

linux - 在linux中,文件末尾没有空字符是否正常

c - 为什么gcc将8字节格式的char类型传递给函数汇编

assembly - 这个8086升序代码是如何工作的?

assembly - 从另一个文件调用过程

assembly - 在程序集中将值设置为 null