ojj zachcialo mi sie asma i tera mam ..... [glowa] [glowa] [glowa]
jak ktos ma chorobe sieroca lub mu sie nudzi to moze sprawdzi ten kod:
Pisane w NASM'ie , aby skompilowac:
nasm -o prog.com -f bin prog,asm
; NASM
%define KEY_ESC 1
%define KEY_UP 72
%define KEY_DOWN 80
%define KEY_LEFT 75
%define KEY_RIGHT 77
CPU 186
BITS 16
ORG 100H
JMP main
; keyboard routines
keyboard_int:
PUSH DS
PUSH ES
PUSH AX
PUSH BX
PUSH CX
PUSH DX
IN AL,60H
CMP AL,128
JNAE keyboard_int_keypress
SUB AL,128
MOV CL,0
keyboard_int_keypress:
MOV CL,1
keyboard_int_end:
MOV [CS:lastkey],AL
MOV BX,key
ADD BL,AL
MOV [CS:BX],CL
MOV AL,20H
OUT 20H,AL
POP DX
POP CX
POP BX
POP AX
POP ES
POP DS
IRET
install_keyboard:
MOV AX,3509H
INT 21H
MOV [old_keyboard_int],BX
MOV [old_keyboard_int + 2],ES
MOV AX,2509H
MOV DX,keyboard_int
PUSH DS
PUSH CS
POP DS
INT 21H
POP DS
RET
remove_keyboard:
MOV AX,2509H
LDS DX,[old_keyboard_int]
INT 21H
RET
wait_for_any_key:
MOV DL,0
wait_for_any_key_1:
CMP DL,[lastkey]
JE wait_for_any_key
RET
;-------
; timer routines
timer_int:
PUSH DS
PUSH ES
PUSH AX
PUSH BX
PUSH CX
PUSH DX
inc byte [CS:bg]
POP DX
POP CX
POP BX
POP AX
POP ES
POP DS
IRET
install_timer:
MOV AX,351CH
INT 21H
MOV [old_timer_int],BX
MOV [old_timer_int + 2],ES
MOV AX,251CH
MOV DX,timer_int
PUSH DS
PUSH CS
POP DS
INT 21H
POP DS
RET
remove_timer:
MOV AX,251CH
LDS DX,[old_timer_int]
INT 21H
RET
;-------
; gfx routines
init13h:
MOV AL,13H
INT 10H
RET
close13h:
MOV AL,03H
INT 10H
RET
vsync:
PUSH AX
PUSH DX
MOV DX,03DAH
vsync_1:
IN AL,DX
TEST AL,0
JNE vsync_1
POP DX
POP AX
RET
set_palette:
CALL vsync
MOV AX,0
MOV BX,palette
MOV CX,256
set_palette_1:
CALL vsync
INC AL
PUSH AX
MOV DX,03C8H
OUT DX,AL
INC DX
MOV AL,[BX]
OUT DX,AL
INC BX
MOV AL,[BX]
OUT DX,AL
INC BX
MOV AL,[BX]
OUT DX,AL
INC BX
POP AX
LOOP set_palette_1
RET
create_screen_buffer:
MOV AH,48H
MOV BX,4000 ; 64000 / 16
INT 21H
JC create_screen_buffer_err
MOV WORD [screen_buffer],0
MOV [screen_buffer + 2],AX ; seg:off, offset=0
JMP create_screen_buffer_end
create_screen_buffer_err:
MOV DX,create_screen_buffer_err_msg
MOV AH,09H
INT 21H
JMP exit
create_screen_buffer_end:
RET
destroy_screen_buffer:
LES DX,[screen_buffer] ; put adress in DS:DX
MOV AH,49H
INT 21H
RET
draw_screen_buffer:
PUSH DS
PUSH ES
PUSH AX
PUSH BX
PUSH CX
PUSH DX
CALL vsync
LES DX,[screen_buffer]
MOV DX,0A000H
MOV DS,DX
MOV CX,64000
draw_screen_buffer_1:
MOV DI,CX
DEC DI
MOV AL,[ES:DI]
MOV [DS:DI],AL
LOOP draw_screen_buffer_1
POP DX
POP CX
POP BX
POP AX
POP ES
POP DS
RET
clear_screen: ; CL - color
LES DX,[screen_buffer]
MOV AL,CL
MOV CX,64000
clear_screen_1:
MOV DI,CX
DEC DI
MOV [ES:DI],AL
LOOP clear_screen_1
RET
putpixel: ; AX - x, BX - y, CL - color
PUSH AX
MOV AX,BX
MOV BX,320
MUL BX
POP BX
ADD AX,BX
MOV DI,AX
LES DX,[screen_buffer]
MOV [ES:DI],CL
RET
getpixel: ; AX - x, BX - y, return: CL - color
PUSH AX
MOV AX,BX
MOV BX,320
MUL BX
POP BX
ADD AX,BX
MOV DI,AX
LES DX,[screen_buffer]
MOV CL,[ES:DI]
RET
;-------
; program code
free_program_mem:
MOV AX,CS
MOV ES,AX
MOV BX,4096
MOV AH,4AH
INT 21H
JC free_program_mem_err
JMP free_program_mem_end
free_program_mem_err:
MOV DX,free_program_mem_err_msg
MOV AH,09H
INT 21H
JMP exit
free_program_mem_end:
RET
main:
CALL init13h
install:
CALL free_program_mem
CALL create_screen_buffer
CALL install_keyboard
CALL install_timer
CALL set_palette
m1:
MOV CL,[bg]
CALL clear_screen
mov ax,319
mov bx,199
mov cl,32
CALL putpixel
CALL draw_screen_buffer
cmp byte [key + KEY_ESC],1
JNE m1
deinstall:
CALL remove_timer
CALL remove_keyboard
CALL destroy_screen_buffer
CALL close13h
exit:
MOV AX,4C00H
INT 21H
;-------
; data
old_keyboard_int DD 0
old_timer_int DD 0
screen_buffer DD 0
key TIMES 128 DB 'x'
lastkey DB 0
free_program_mem_err_msg DB 'Error - Can',39,'t free program memory !',10,13,'$'
create_screen_buffer_err_msg DB 'Error - Can',39,'t create screen buffer !',10,13,'$'
bg DB 0
;palette DB ... - to jest zmienna ktora jest tablica 768 bajtow z paleta kolorow
;-------
; EOF
Jak ktos chce caly kod to wysle na maila bo zajmuje ponad 518 lini (paleta kolorow), a problem jest nastepujacy:
po pierwsze nie wiem co sie dzieje z tymi rejestrami DS, ES itp bo jezli czasem nie wrzuce ich na stos to program sie sypie, jednak i tak nie wiadomo co sie dzieje na koncu programu po przycisnienciu przycisku bo cos nawala i to raz na jakis czas [glowa] , dodatkowo nie wiem czemu ale przez ustawianie palety kolorow pojawia mi sie cos jak obramowka ekranu 13h (320x200) pixeli o barwie RGB=255,0,255 czyli jaskrawo fioletowa (w C tego nie bylo)....