Search code examples
assemblyprintingdrawtasmreal-mode

How to print matrix with int10h?


Well as my question says, I need to print a matrix with the int10h but not just that, this matrix is of 0 and 1 where the 0 has to represent the color blue and the 1 the color red. So my question is how do I print this matrix and how do I make the be color blue and red be color red when printing? I am using TASM and can use either 16 or 32bit registers. Here is an example:

oneMatrix db 00000000000
             00000110000
             00011110000
             00000110000
             00000110000
             00000110000
             00011111100
             00000000000

So as you can kind of see there, the 1 form a shape of a one. How do I print this using int 10h and where 0 is color blue and 1 is color red?


Solution

  • Use the BIOS.WriteCharacterAndAttribute function 09h. Put either blue or red foregroundcolor in BL depending on the character at hand (read from the matrix).

        mov si, offset oneMatrix
        mov cx, 1    ; ReplicationCount
        mov bh, 0    ; DisplayPage
    More:
    
        ... position the cursor where next character has to go
    
        lodsb
        mov bl, 01h  ; BlueOnBlack
        cmp al '0'
        je  Go
        mov bl, 04h  ; RedOnBlack
    Go:
        mov ah, 09h  ; BIOS.WriteCharacterWithAttribute
        int 10h
    
        ... iterate as needed
    

    Take a look at this recent answer. There's some similarity...


    If you need the output to create a glyph on a graphics screen, then next code will help:

        mov  si, offset oneMatrix
        mov  bh, 0      ; DisplayPage
    
        mov  bp, 8      ; Height
        mov  dx, ...    ; UpperleftY
    OuterLoop:
    
        mov  di, 11     ; Width
        mov  cx, ...    ; UpperleftX
    InnerLoop:
        lodsb
        cmp al '0'
        mov al, 1      ; Blue
        je  Go
        mov al, 4      ; Red
    Go:
        mov ah, 0Ch    ; BIOS.WritePixel
        int 10h
        inc cx         ; Next X
        dec di
        jnz InnerLoop
    
        inc dx         ; Next Y
        dec bp
        jnz OuterLoop