Created
October 6, 2020 19:44
-
-
Save dgryski/08d964819524c89c71d5175efb56281e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.model tiny | |
.radix 16 | |
.data | |
jmp start | |
;k1 dw 6255 | |
;k2 dw 3619 | |
k1 dw 24CD | |
k2 dw 1 | |
seed dw ? | |
xtab dw 0, 0a0, 140 | |
ytab dw 0c8, 00, 0c8 | |
x dw ? | |
y dw ? | |
.code | |
.startup | |
start: | |
call srand ; seed random number generator | |
call setmcga | |
mov ax, 0a000 | |
mov es, ax ; es is video mem | |
mainloop: | |
call nextpoint | |
call kbhit | |
jc exit | |
jmp mainloop | |
exit: | |
call readkey | |
call settext | |
mov ax, 4c00 | |
int 21 ; call dos with exit request | |
setmcga: ; set mcga mode | |
mov ax, 0013 | |
int 10 | |
ret | |
settext: ; set text mode | |
mov ax, 0003 | |
int 10 | |
ret | |
kbhit: ; set carry if key in stdin | |
clc | |
mov ax, 0100 | |
int 16 | |
jz $+3 ; skip set carry | |
stc | |
ret | |
readkey: ; get key in stdin | |
xor ax, ax | |
int 16 | |
ret | |
rand: ; returns 16bit rand number | |
mov ax, [seed] | |
imul [k1] | |
add ax, [k2] | |
mov [seed], ax | |
ror al, 1 | |
rol ah, 1 | |
ret | |
srand: ;seeds random number generator from DOS clock | |
mov ah, 2c | |
int 21 | |
xor cx, dx | |
mov [seed], cx | |
ret | |
nextpoint: | |
call rand | |
xor al, ah | |
xor ah, ah | |
mov cx, 3 | |
div cl | |
shr ax, 8 ; get remainder in al, 0 1 2 | |
mov bx, ax | |
shl bx, 1 ; has to be doubled, we're working with dw | |
mov ax, [x] | |
add ax, xtab[bx] | |
shr ax, 1 | |
mov [x], ax | |
mov ax, [y] | |
add ax, ytab[bx] | |
shr ax,1 | |
mov [y], ax | |
; now plot the point | |
mov ax, [y] | |
mov bx, 140 | |
mul bx | |
add ax, [x] | |
xchg ax, bx | |
call rand ; get random color | |
mov es:[bx], al | |
ret | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment