Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; -------------------------------------------------------------------
- ; 80386
- ; 32-bit x86 assembly language
- ; TASM
- ;
- ; author: Jarne Arnouts, Minh Tai Nguyen
- ; date: 28/10/2019
- ; program: Video mode 13h
- ; -------------------------------------------------------------------
- IDEAL
- P386
- MODEL FLAT, C
- ASSUME cs:_TEXT,ds:FLAT,es:FLAT,fs:FLAT,gs:FLAT
- ; compile-time constants (with macros)
- VMEMADR EQU 0A0000h ; video memory address
- SCRWIDTH EQU 320 ; screen witdth
- SCRHEIGHT EQU 200 ; screen height
- FRAMECOUNT EQU 288
- ; -------------------------------------------------------------------
- CODESEG
- ; wait for @@framecount frames
- proc wait_VBLANK
- ARG @@framecount: word
- USES eax, ecx, edx
- mov dx, 03dah ; Wait for screen refresh
- movzx ecx, [@@framecount]
- @@VBlank_phase1:
- in al, dx
- and al, 8
- jnz @@VBlank_phase1
- @@VBlank_phase2:
- in al, dx
- and al, 8
- jz @@VBlank_phase2
- loop @@VBlank_phase1
- ret
- endp wait_VBLANK
- proc check_for_input
- ARG @@keyL:byte , @@keyR:byte , @@keyU:byte , @@keystop:byte
- USES eax
- mov ah, 01h
- int 16h
- test1:
- cmp al,[@@keyL]
- jne test2
- call go_left
- test2:
- cmp al, [@@keyR]
- jne test3
- call go_right
- test3:
- cmp al, [@@keyU]
- jne test4
- call go_up
- test4:
- cmp al, [@@keystop]
- jne @@continue
- call terminateProcess
- @@continue:
- ret
- ENDP check_for_input
- PROC go_up
- USES eax
- mov eax, [y_pos]
- sub al, 40
- mov [y_pos], eax
- ret
- ENDP go_up
- PROC go_left
- USES eax
- mov eax, [x_pos]
- sub eax, 5
- mov [x_pos], eax
- ret
- ENDP go_left
- PROC gravity
- USES eax
- mov eax, [y_pos]
- cmp eax, 150
- jle vallen
- jmp niks
- vallen:
- add eax, 5
- mov [y_pos], eax
- niks:
- ret
- ENDP gravity
- PROC go_right
- USES eax
- mov eax, [x_pos]
- add eax, 5
- mov [x_pos], eax
- ret
- ENDP go_right
- ; Set the video mode
- PROC setVideoMode
- ARG @@A:byte
- USES eax
- movzx ax, [@@A]
- int 10h
- ret
- ENDP setVideoMode
- ; ; Fill the background (for mode 13h)
- PROC fillBackground
- ARG @@fillcolor: byte
- USES eax, ecx, edi
- mov edi, VMEMADR
- mov ecx, SCRWIDTH*SCRHEIGHT
- mov al, [@@fillcolor]
- rep stosb
- ret
- ENDP fillBackground
- ; ; Draw a rectangle (video mode 13h)
- PROC drawRectangle
- ARG @@x0:word, @@y0:word, @@w:word, @@h:word, @@col:byte
- USES eax, ecx, edx, edi
- mov edi, VMEMADR
- mov eax, SCRWIDTH
- mul [@@y0]
- add ax, [@@x0]
- add edi, eax
- push edi
- drawhorizontal:
- mov cx, [@@w]
- mov al, [@@col]
- rep stosb
- mov cx, [@@h]
- pop edi
- drawvertical:
- stosb
- add di, [@@w]
- stosb
- add edi, SCRWIDTH-2
- sub di, [@@w]
- loop drawvertical
- mov cx, [@@w]
- mov al, [@@col]
- rep stosb
- ret
- ENDP drawRectangle
- PROC filledRectangle
- ARG @@x0:word, @@y0:word, @@w:word, @@h:word, @@col:byte
- USES eax, ecx, edx, edi
- mov edi, VMEMADR ;destpointer
- mov eax, SCRWIDTH
- mul [@@y0]
- add ax, [@@x0];juistzetten coördinaat
- add edi, eax;coördinaat toevoegen aan de destpointer
- push edi; bijhouden van de juiste startcoödinaat
- mov cx, [@@h]; aantal benodigde interaties
- @@draw:
- push cx
- @@drawline: ; opvullen van de rechthoek door steeds een lijn te tekken
- pop edi; juiste startcoördinaat vastnemen
- push edi; juiste startcoördinaat bijhouden
- mov cx, [@@w]
- mov al, [@@col]
- rep stosb
- loop @@drawline
- pop cx
- loop @@draw
- ret
- ENDP
- ; Terminate the program.
- PROC terminateProcess
- USES eax
- call setVideoMode, 03h
- mov ax,04C00h
- int 21h
- ret
- ENDP terminateProcess
- PROC main
- sti
- cld
- push ds
- pop es
- mov ecx, 5000
- call setVideoMode, 13h
- @@drawloop:
- mov ah, 0Ch
- int 21h
- call gravity
- call fillBackground, 00FH
- ;call filledRectangle, 0, [y_base], SCRWIDTH, 20, 0
- call drawRectangle,[x_pos],[y_pos],10,20, 32
- call wait_VBLANK, 3
- call check_for_input, 0071h,0064h, 007Ah , 001BH
- loop @@drawloop
- ENDP main
- ; -------------------------------------------------------------------
- DATASEG
- palette db 768 dup (?)
- x_pos dd 60
- y_pos dd 60
- y_base dd 180
- ; -------------------------------------------------------------------
- ; STACK
- ; -------------------------------------------------------------------
- STACK 100h
- END main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement