Skip to content

Instantly share code, notes, and snippets.

@neuro-sys
Last active May 15, 2021 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neuro-sys/b576235fa6112cb75cd8f7d0e77ccd69 to your computer and use it in GitHub Desktop.
Save neuro-sys/b576235fa6112cb75cd8f7d0e77ccd69 to your computer and use it in GitHub Desktop.
BITS 16
org 0x100
;-----------------------------------------------------------------------+
; Set up mode 13h, and screen address at es:di
;-----------------------------------------------------------------------+
mov al, 13h
int 0x10
;-----------------------------------------------------------------------+
; Vertically and horizontally center the 128x256 image
;-----------------------------------------------------------------------+
mov bx, 0xa000+(((200-128) / 2)*320+32) / 16
mov es, bx
;-----------------------------------------------------------------------+
; Start drawing sierpinski pattern on 128x256 pixel area
;-----------------------------------------------------------------------+
; CX counter that starts from 128*256 decrementing can be used to get:
; x0 = AL
; y0 = AH
;
; - Whenever x0 is 0, then advance the pixel pointer by 320-256 to get
; to the next line.
; - To fix the right-triangle of truth table, subtract half of y0 from
; x0
;-----------------------------------------------------------------------+
mov ch, 128-1 ; the previous value of cl is zero here
l3: mov al, cl
test al, al ; Is x0 = y0?
jnz l1
add di, (320-256) ; If zero, then advance to next line
l1: sub al, ch ; Subtract y0 for the slant
shr al, 1 ; Fix the slant
and al, ch ; Check x0 AND y0
in al, dx ; Use the dead port for bg color
jnz l2
mov al, 0x2c ; Yellow
l2: stosb
loop l3
;-----------------------------------------------------------------------+
; Wait for key, and return to text mode, exit
;-----------------------------------------------------------------------+
int 0x16 ; Wait keyhit
; (I saw int 0x16 in @gbizzotto's code)
mov ax, 3
int 0x10 ; Return to text mode
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment