Skip to content

Instantly share code, notes, and snippets.

@peterhellberg
Created November 21, 2018 16:42
Show Gist options
  • Save peterhellberg/6f045c652852be66b6eecc8f7eb10908 to your computer and use it in GitHub Desktop.
Save peterhellberg/6f045c652852be66b6eecc8f7eb10908 to your computer and use it in GitHub Desktop.
MS-DOS paint program in 16 bytes found at http://www.sizecoding.org/wiki/Paint16b
org 100h ; code starts at 0x100
mov al,0x12 ; assume ah = 0 ; set graphics mode to 640*480
inc bx ; assume bx = 0 ; set to 1 (show cursor)
mloop:
int 0x10 ; first loop, switch to graphic mode
; further loops, set pixel
xchg bx,ax ; first loop, set AX to 1 (show cursor)
; further loops, restore old calling mode
xor al,0x02 ; switch modes : show cursor <-> get mouse state
; updating XY every second loop plus drawing
; one pixel left results in thicker lines
int 0x33 ; call the mouse interrupt
xchg bx,ax ; store the button state in AL for drawing
; remember the current calling mode
; for switching it later (in BX)
mov ah,0x0C ; set mode to "set pixel"
loop mloop ; dec CX -> draw one pixel left from cursor
; basically enables drawing pixels
; while the cursor is active
; allows exit if the mouse is leftmost
ret ; assume [[FFEE]] = [0] = CD20 = int 20
@peterhellberg
Copy link
Author

peterhellberg commented Nov 21, 2018

Requirements

NASM - The Netwide Assembler and DOSBox, an x86 emulator with DOS

If you are using macOS and have Homebrew installed then you can install them like this:

brew install nasm dosbox

Assembling the binary

nasm paint16b.asm -f bin -o paint16b.com

Running the program in dosbox

dosbox -c "MOUNT C `pwd`" -c "C:" -c "paint16b.com"

How it looks

paint16b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment