8086 Assembly Language Creating a Matrix Screensaver

2.9k views Asked by At

I have to create a simple implementation of a Matrix screensaver, like the ones in the movies, in assembly, using only video memory(text). I have most of the structure laid out except for the random number generator for getting a random character but i would appreciate some help narrowing down some of these procedures and their implementations.

I have to use code similar to this:

;Matrix
;This program displays a matrix wallpaper
.model small
.386
.stack 100h
.data

.code
main proc

    mov ax, 0b800h
    mov es, ax

    mov bx, 39  ; row
    mov cx, 12  ; colum

    mov ax, 160
    mul cx
    shl bx,1
    add bx, ax

    mov al, 'A'
    mov ah, 0ah
    mov es:[bx], ax

    mov ax, 4c00h
    int 21h

main endp
end main

but this is what i have so far:

;Matrix
;This program creates a matrix wallpaper
.model small
.386
.stack 100h
.data

speed dword 2147483647
X dw, ?
Y dw, ?
ch dw, ?
att dw, ?

.code
main proc
    mov ax, @data
    mov ds, ax

    ; setup interrupt

    push ds
    mov ax, @code
    mov ds, ax
    mov ah, 25h
    mov al, 9
    mov dx, offset My_int
    int 21h
    pop ds

    ; matrix program, makes the rain effect

Loo2:
    ; for(y = 23; y > 0; y--)
    L1:
        ; for(x = 0; x <= 79; x++)
        L2:
            ; SgetCh(x, y, ch, attribute)
            call SgetCh
            ; SputCh(x, y, ch, attribute)
            call SgetCh
            ; BusyWait
            call BusyWait

    jmp Loo2    

    mov ax, 4c00h
    int 21h
main endp
;***************
My_int proc
    ;cli            ; diable interrupts
    ;mov ax, mystack    ; reset SS
    ;mov ss, ax
    ;mov sp, 100h       ; reset SP
    ;sti            ; reenable interrupt

    mov ax, 4c00h
    int 21h
    iret
My_int endp
;***************
BusyWait proc

    ret
BusyWait endp
;***************
SgetCh proc

    ret
SgetCh endp
;***************
SputCh proc

    ret
SputCh endp
;***************
end main
2

There are 2 answers

1
Van Uitkon On

Here is a code that I've written a long time ago. Maybe you can use it:

mov ax, 19
int 10h ; 320x200 with 256 colors
mov ax, 0a000h
mov es, ax ;set the di segment to the graphics memory
xor bl, bl ;bl will be used to store the number of the picture
new:
inc bl
hlt ;here the processor will wait (very shortly and in an unregular period)
xor cx, cx
xor dx, dx ;cx and dx represent the coordinates
xor di, di ;set di to offset of the begin of the screen.
a:
mov al, cl
xor al, dl
add al, dl
add al, bl ;create a color
stosb ;write pixel
inc cx
cmp cx, 320 ;refresh coordinates
jne a
xor cx, cx
inc dx
cmp dx, 200
jne a
mov ah, 1 ;check whether a key had been pressed
int 16h
jz new ;If no key had been pressed, show next picture
mov ax, 3
int 10h
mov ax, 4c00h
int 21h
0
Sep Roland On

What do you expect to happen when you terminate the program from within the keyboard interrupt handler? It will surely NOT restore the interrupt vector!

Since all drawing on screen is done in the main program you don't need to change any interrupt. Just exit the program as soon as BIOS function 'Read Keyboard Status' (to be inserted at jmp Loo2) returns with the ZF=0

These lines

 mov bx, 39  ; row
 mov cx, 12  ; colum

don't correspond to the code that follows. You mixed the meaning of column and row.