Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BITS 16
- %macro m_delay 1
- pusha
- mov ah, 00h ; parameter to interruption get clock
- int 1Ah ; get time on cx and dx: cxdx
- mov [clock_before], dx ; put current time on clock_before
- %%delay:
- mov ah, 00h ; parameter to interruption get clock
- int 1Ah ; get time on cx and dx, cx is high dx is low (I am only using dx)
- sub dx, [clock_before]
- cmp dx, %1
- jl %%delay
- popa ; get saved registers
- %endmacro
- ;----------------------------------------------------------------------------
- start:
- mov ah, 0Fh ;get video mode
- int 10h
- mov [video_org], al ;save original video mode
- mov ax, 07C0h ; Set up 4K stack space after this bootloader
- add ax, 288 ; (4096 + 512) / 16 bytes per paragraph
- mov ss, ax
- mov sp, 4096
- mov ax, 07C0h ; Set data segment to where we're loaded
- mov ds, ax
- mov si, text_string ; Put string position into SI
- call print_string ; Call our string-printing routine
- m_delay 4*18 ;aprox 4 seconds
- mov ah, 00h ;video mode
- mov al, 12h ;640 * 480
- int 10h
- ;----------------------------------------------------------------------------
- move:
- ;erase------------------------
- ;not byte [v_page] ;change between
- ;and byte [v_page],1 ;1 and 0 v_page
- ;mov ax,0A000h
- ;mov es,ax
- ;xor di,di
- ;xor ax,ax
- ;mov cx,56800
- ;cld
- ;rep stosw
- ;mov cx,56800
- ;cld
- ;rep stosw
- ;draw ship -------------------------------------------
- ;first erase
- mov byte [colour],0
- push word [x_coor]
- push word [y_coor]
- mov ax,[before_x_coor]
- mov [x_coor],ax
- mov ax,[before_y_coor]
- mov [y_coor],ax
- mov ax,[x_coor]
- mov [x_coor2],ax
- add word [x_coor2],40
- mov ax,[before_y_coor]
- mov word [y_coor2],ax
- add word [y_coor2],20
- call draw_line
- sub word [x_coor2],25
- call draw_line
- add word [y_coor],40
- call draw_line
- add word [x_coor2],25
- call draw_line
- pop word [y_coor]
- pop word [x_coor]
- ;-draw
- mov byte [colour],5
- mov ax,[x_coor]
- mov [x_coor2],ax
- add word [x_coor2],40
- mov ax,[y_coor]
- mov word [y_coor2],ax
- add word [y_coor2],20
- call draw_line
- sub word [x_coor2],25
- call draw_line
- add word [y_coor],40
- call draw_line
- add word [x_coor2],25
- call draw_line
- sub word [y_coor],40 ;return to original y_coor
- mov ax,[x_coor]
- mov [before_x_coor],ax
- mov ax,[y_coor]
- mov [before_y_coor],ax
- .eval_key: mov ah, 1 ;Is a key available?
- int 16h
- jz .eval_key ;If no, try again
- ;if yes
- mov [code],ah ;save scan code
- mov ah, 0 ;Flush this character from the
- int 16h ; buffer
- cmp byte [code], 1 ;if ESC
- je .end ;end
- cmp byte [code], 4Dh
- jne .continue1
- add word [x_coor],30
- .continue1:
- cmp byte [code],4Bh
- jne .continue2
- sub word [x_coor], 30
- .continue2:
- cmp byte [code],48h
- jne .continue3
- sub word [y_coor] ,30
- .continue3:
- cmp byte [code],50h
- jne move
- add word [y_coor] , 30
- jmp move ;else, other time
- ;----------------------------------------------------------------------------
- .end:
- mov ah,42h
- int 10h
- mov ah, 00h ;video mode
- mov al, [video_org]
- int 10h
- mov si, goodbay_string ; Put string position into SI
- call print_string ; Call our string-printing routine
- jmp $ ; Jump here - infinite loop!
- text_string db 'Juego creado por Martin Munoz del Rio', 0
- goodbay_string db 'Gracias por probar este juego.', 0
- clock_before dw 0
- video_org db 0
- code db 0
- current_y dw 0
- colour db 5
- x_coor dw 300
- y_coor dw 200
- x_coor2 dw 350
- y_coor2 dw 250
- before_x_coor dw 300
- before_y_coor dw 200
- v_page db 0
- ;----------------------------------------------------------------------------
- print_string: ; Routine: output string in SI to screen
- mov ah, 0Eh ; int 10h 'print char' function
- .repeat:
- lodsb ; Get character from string
- cmp al, 0
- je .done ; If char is zero, end of string
- int 10h ; Otherwise, print it
- jmp .repeat
- .done:
- ret
- ;----------------------------------------------------------------------------
- draw_line:
- mov ah, 0Ch ;draw
- mov cx, [x_coor] ;coordinate x
- mov dx, [y_coor] ;coordinate y
- mov bh,[v_page] ; video page
- mov al,[colour] ;colour
- mov [current_y],dx ;init current_y with y
- .draw: ;drawing a line
- pusha
- mov ax,[y_coor2]
- sub ax,[y_coor]
- xor dx,dx
- sub cx, [x_coor]
- imul cx
- mov bx, [x_coor2]
- sub bx, [x_coor]
- idiv bx
- add ax, [y_coor]
- mov [current_y], ax
- popa
- mov dx,[current_y]
- int 10h
- inc cx
- cmp cx, [x_coor2]
- jle .draw
- ret
- ;-------------------------------------------------------------------------------
- times 510-($-$$) db 0 ; Pad remainder of boot sector with 0s
- dw 0xAA55 ; The standard PC boot signature
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement