In ASM(One of the ASM stuff I made for Computer Eng. Students)
Code:
;****************************************************************************
; THE MATRIX
;
; Http://Rel.Betterwebber.com
;
;
;****************************************************************************
;****************************************************************************
.model small ; data segment < 64k, code segment < 64k
.stack 200h ; set up 512 bytes of stack space
.386
; ===========================================================================
.data
seed dw 3749h ;random seed value, globe phone number ;*)
icount dw 0 ;outer loop counter
jcount dw 0 ;inner loop counter
.code
;*****************************************************************
waitretrace proc
mov dx,03dah ;0x3da9 vertical retrace port
wret:
in al,dx
and al,08h ;is vga in retrace?
jnz wret
wref:
in al,dx
and al,08h ;is retrace finished?
jz wref
ret
waitretrace endp
;*****************************************************************
textmode proc
mov ah, 00h ;set video mode
mov al, 03h ;mode 03h
int 10h ;enter 80x25x16 mode
ret
textmode endp
;*****************************************************************
ClearScreen Proc
pusha ;preserve general regs
mov ax, 0600h ;int 10, 6(scroll screen)
mov bh, 02h ;color green on Black
mov cx, 0000 ;row0,col0
mov dx, 184fh ;25,80
int 10h ;scroll(clear it)
popa ;restore regs
ret
ClearScreen Endp
;*****************************************************************
;*****************************************************************
;*****************************************************************
;*****************************************************************
;*****************************************************************
;Main proggie
start:
mov ax, @data ;use the @ operator
mov ds, ax ;ds now points to the data segment.
mov ax, 0b800h ;text seg
mov es, ax
call textmode ;set to textmode
mov ah, 01 ;disable cursor
mov cx, 2000h
int 10h ;disable it baby
call ClearScreen ;clear the screen
mainloop:
call waitretrace
mov icount, 0
iloop:
;generate random number
mov ax, seed ;move the seed value into ax
mov dx, 8405h ;move 8405h into dx
mul dx ;put 8405h x seed into dx:ax
inc ax ;increment ax
mov seed, ax ;we have a new seed
cmp dl, 55
ja negcx
mov jcount, 3840
jmp jloop
negcx:
mov jcount, -1
jloop:
mov cx, jcount
mov di, cx
sub di, 160
mov ax, icount
add di, ax
mov dl, es:[di]
mov di, jcount
add di, icount
mov es:[di], dl
sub jcount, 160
cmp jcount, 0
jg jloop
cmp jcount,0
jne jnotzero
;generate random number
mov ax, seed ;move the seed value into ax
mov dx, 8405h ;move 8405h into dx
mul dx ;put 8405h x seed into dx:ax
inc ax ;increment ax
mov seed, ax ;we have a new seed
cmp dl, 35
jle printspace
mov di, icount
mov es:[di], dl
jmp jnotzero
printspace:
mov di, icount
mov dl, 32
mov es:[di], dl
jnotzero:
mov cx, 1 ;erase ugly multicolored
eraseloop: ;top line
mov di, cx
mov al, 0
mov es:[di], al
add cx, 2
cmp cx, 160
jle eraseloop ;second row?
add icount, 4
cmp icount, 159
jle iloop
mov ah, 01h ;check for keypress
int 16h ;is a key waiting in the buffer?
jz mainloop ;no, keep on going
exit:
mov ah, 4ch
mov al, 00h
int 21h ;return to dos
end start