a c*_*der 1 x86 assembly bios nasm bootloader
我正在编写一个 bootsector 游戏,它试图复制没有互联网时可以玩的 chrome 恐龙游戏。
为此,我必须从左向右跑,直到玩家击中仙人掌。
我如何实现这一目标?(如何使终端从右向左滚动,使其看起来像是在移动?)因此,我需要从右向左和从左向右滚动,而不是向上和向下滚动。我在 16 位实模式 (BIOS),我使用 nasm/intel 语法。
在 CGA 兼容的文本模式下,屏幕内容存储在 4000 字节的缓冲区中B800:000(除非您更改活动显示页面,但我假设您没有更改)。每行包含 80 个字符,以 160 字节存储,共 25 行,分辨率为 80×25。
因此,要向左滚动屏幕,您必须将屏幕字符向左移动所需的列数,并用空白字符填充屏幕右侧。这可以使用一系列rep movsw指令来轻松实现,以移动字符,然后是rep stosw填充右侧的指令。假设ds = es = b800和假设ds:di指向行首,将单行向左移动c列的代码如下所示:
lea si, [di+2*c] ; set up SI to the column that is scrolled
; into the first column of the line
mov cx, 80-c ; copy all columns beginning at that column
; to the end of the row
rep movsw ; scroll row to the left
mov cx, c ; need to blank that many columns
rep stosw ; blank remaining columns
Run Code Online (Sandbox Code Playgroud)
在此代码序列之后,DI指向下一行的开头。所以通过迭代这个序列 25 次,我们可以轻松地滚动整个屏幕:
mov ax, 0xb800 ; screen segment
mov ds, ax ; set up segments
mov es, ax
xor di, di ; point to the beginning of the screen
mov dx, 25 ; process 25 lines
mov ax, 0x0700 ; what to scroll in (grey on black blanks)
.loop: lea si, [di+2*c] ; set up SI to the column that is scrolled
; into the first column of the line
mov cx, 80-c ; copy all columns beginning at that column
; to the end of the row
rep movsw ; scroll row to the left
mov cx, c ; need to blank that many columns
rep stosw ; blank remaining columns
dec dx ; decrement loop counter
jnz .loop ; loop until we're done
Run Code Online (Sandbox Code Playgroud)
这就是它的全部内容。当然,如果c是变量而不是常量,代码会稍微复杂一些。但我相信你会弄清楚的。
另请注意,您似乎将屏幕称为“BIOS 终端”或类似的东西。那不正确。屏幕是由显卡绘制的,实际上可以在没有 BIOS 的情况下完全改变。BIOS 是计算机 ROM 中提供的一组例程。其中包括一些用于配置图形模式和打印字符等的例程。然而,这纯粹是为了方便。您实际上不需要通过 BIOS 来执行任何这些操作。