From SizeCoding
Revision as of 13:23, 12 August 2016 by HellMood (talk | contribs) (three textmode output possibilities with external links)

Jump to: navigation, search

Outputting to the screen

First, be aware of the MSDOS memory layout

Outputting in Textmode (80x25)

Right after the start of your program you are in mode 3, that is 80x25 in 16 colors.

See the Video Modes List

So, to show something on the screen, you would need to set a segment register to 0xB800, then write values into this segment.

The following three snippets showcase how to draw a red smiley in three different ways. The target coordinate (40,12) is about the middle of the screen. We need a multiplier 2 since one char needs two bytes in memory (char and color is a byte each). The high byte 0x04 means red (4) on black (0) while the 0x01 is the first ASCII char - a smiley.

push 0xb800
pop ds
mov bx,(80*12+40)*2
mov ax, 0x0401
mov [bx],ax
push 0xb800
pop es
mov di,(80*12+40)*2
mov ax, 0x0401
push ss
push 0xb800
pop ss
mov sp,(80*12+40)*2
mov ax, 0x0401
push ax
pop ss
int 0x20

Outputting in mode 13h (320x200)

Producing sound

MIDI notes

PC Speaker