MCGA BIOS文本模式下的16种背景颜色(AL = 03h)

时间:2015-03-01 05:15:28

标签: assembly masm bios dosbox text-coloring

MCGA支持4位颜色深度,即16种颜色。但是当我尝试打印所有这些颜色时,我只得到它们中的前8个,其余8个简单地复制它们,如下图所示。可能是我在这里做错了,或者全是因为DOSBox?

trying to get all the 16 colors

代码(MASM,在DOSBox 0.74下):

TITLE   PROGRAM193
;----------------------------------------------------------
        .MODEL      SMALL
        .STACK      64
        .DATA           
;----------------------------------------------------------
        .CODE
MAIN    PROC    FAR
    MOV     AX, @DATA
    MOV     DS, AX

    MOV     AX, 0600h    ;AH = 06h (scroll up window)
    ; black (0)
    MOV     BH, 0Fh      ;0 (black) background, F (white) text
    MOV     CX, 0000h    ;upper line, left column
    MOV     DX, 004Fh    ;finishing line, right column
    INT     10h

    ; blue (1)
    MOV     BH, 1Fh
    MOV     CX, 0100h
    MOV     DX, 014Fh
    INT     10h

    ; green (2)
    MOV     BH, 2Fh
    MOV     CX, 0200h
    MOV     DX, 024Fh
    INT     10h

    ; cyan (3)
    MOV     BH, 3Fh
    MOV     CX, 0300h
    MOV     DX, 034Fh
    INT     10h

    ; red (4)
    MOV     BH, 4Fh
    MOV     CX, 0400h
    MOV     DX, 044Fh
    INT     10h

    ; magenta (5)
    MOV     BH, 5Fh
    MOV     CX, 0500h
    MOV     DX, 054Fh
    INT     10h

    ; brown (6)
    MOV     BH, 6Fh
    MOV     CX, 0600h
    MOV     DX, 064Fh
    INT     10h

    ; light gray (7)
    MOV     BH, 7Fh
    MOV     CX, 0700h
    MOV     DX, 074Fh
    INT     10h

    ;  -------------------------------
    ; | The problem starts up here... |
    ;  -------------------------------
    ; dark gray (8)
    MOV     BH, 8Fh
    MOV     CX, 0800h
    MOV     DX, 084Fh
    INT     10h

    ; light blue (9)
    MOV     BH, 9Fh
    MOV     CX, 0900h
    MOV     DX, 094Fh
    INT     10h

    ; light green (A)
    MOV     BH, 0AFh
    MOV     CX, 0A00h
    MOV     DX, 0A4Fh
    INT     10h

    ; light cyan (B)
    MOV     BH, 0BFh
    MOV     CX, 0B00h
    MOV     DX, 0B4Fh
    INT     10h

    ; light red (C)
    MOV     BH, 0CFh
    MOV     CX, 0C00h
    MOV     DX, 0C4Fh
    INT     10h

    ; light magenta (D)
    MOV     BH, 0DFh
    MOV     CX, 0D00h
    MOV     DX, 0D4Fh
    INT     10h

    ; yellow (E)
    MOV     BH, 0EFh                        
    MOV     CX, 0E00h
    MOV     DX, 0E4Fh
    INT     10h

    ; white (F)
    MOV     BH, 0F1h
    MOV     CX, 0F00h
    MOV     DX, 0F4Fh
    INT     10h

    MOV     AX, 4C00h
    INT         21h                         
MAIN    ENDP
        END     MAIN

2 个答案:

答案 0 :(得分:7)

默认情况下,文本有16种颜色,背景只有8种颜色。

有一种方法可以获得背景的所有16种颜色,这需要关闭“闪烁属性”

以下是如何做到的:

MAIN    PROC    FAR
    MOV     AX, @DATA
    MOV     DS, AX


    ; turn-off blinking attribute
    MOV     AX, 1003h       
    MOV     BL, 00
    INT     10h


    MOV     AX, 0600h    ;AH = 06h (scroll up window)
    ; black (0)
    MOV     BH, 0Fh      ;0 (black) background, F (white) text
    MOV     CX, 0000h    ;upper line, left column
    MOV     DX, 004Fh    ;finishing line, right column
    INT     10h

    ; the rest of the magic...

结果如下所示:

enter image description here

答案 1 :(得分:4)

是的 - 确实是古老的技术!

前景中有16种颜色,但背景只有8种颜色。最高位用于闪烁,有时没有实现。