Difference between revisions of "Output"

From SizeCoding
Jump to: navigation, search
(Created page with "== Outputting to the screen == (typical screen output modes, discussion of b800, trick to set 9fff/a000, == Producing sound == === MIDI notes === === PC Speaker ===")
 
(three textmode output possibilities with external links)
Line 1: Line 1:
 
== Outputting to the screen ==
 
== Outputting to the screen ==
  
(typical screen output modes, discussion of b800, trick to set 9fff/a000,  
+
First, be aware of the [https://http://img.tfd.com/cde/MEMMAP.GIF 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 [http://www.columbia.edu/~em36/wpdos/videomodes.txt 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.
 +
 
 +
<syntaxhighlight lang="nasm">
 +
push 0xb800
 +
pop ds
 +
mov bx,(80*12+40)*2
 +
mov ax, 0x0401
 +
mov [bx],ax
 +
ret
 +
</syntaxhighlight>
 +
 
 +
<syntaxhighlight lang="nasm">
 +
push 0xb800
 +
pop es
 +
mov di,(80*12+40)*2
 +
mov ax, 0x0401
 +
stosw
 +
ret
 +
</syntaxhighlight>
 +
 
 +
<syntaxhighlight lang="nasm">
 +
push ss
 +
push 0xb800
 +
pop ss
 +
mov sp,(80*12+40)*2
 +
mov ax, 0x0401
 +
push ax
 +
pop ss
 +
int 0x20
 +
</syntaxhighlight>
 +
 
 +
=== Outputting in mode 13h (320x200) ===
  
 
== Producing sound ==
 
== Producing sound ==

Revision as of 12:23, 12 August 2016

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
ret
 
push 0xb800
pop es
mov di,(80*12+40)*2
mov ax, 0x0401
stosw
ret
 
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