Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Polishing...
Browse files Browse the repository at this point in the history
  • Loading branch information
kdrzazga committed Dec 28, 2016
1 parent f0ac3e6 commit a7bb83f
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 55 deletions.
7 changes: 7 additions & 0 deletions graph.asm
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
;public
set_graphical_mode:
mov ax,0013h
int 10h
ret

;public
set_text_mode:
mov ax, 3
int 10h
ret

;private
clrscr:
mov ax, 0a000h
mov es, ax
mov di, 0
mov cx, 57600
;private
black_fill:
mov byte ptr es:[di], 3
inc di
loop black_fill
ret

;public
init_colors:
mov ax, 13h
int 10h
Expand Down Expand Up @@ -64,6 +69,7 @@ init_colors:
mov ax, 0ffffh
mov bx, 0ffffh
;private
set_gray_colors:
dec ax
dec bx
Expand All @@ -72,6 +78,7 @@ init_colors:

ret

;private
set_rgb_color:
xchg ah, al ;after this al contains color index ah= R value
mov dx, 3c8h
Expand Down
21 changes: 14 additions & 7 deletions io.asm
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
;public
io_load_drawing:
call io_open_file
call io_read_from_file
ret

;private
io_error:
mov dx, seg io_error_message
mov ds, dx
Expand All @@ -11,6 +13,7 @@ io_error:
int 21h
jmp exit_menu

;public
io_save_drawing:

call hide_mouse
Expand All @@ -23,6 +26,7 @@ io_save_drawing:
mov di, 0
mov cx, 57600
;private
copy_memory:
mov bl, es:[di]
mov ds:[di], bl
Expand All @@ -31,9 +35,9 @@ io_save_drawing:

call io_create_file
call io_write_to_file

ret

;private
io_create_file:
mov ah, 3ch
mov dx, seg file_name
Expand All @@ -44,20 +48,22 @@ io_create_file:
jc io_error
ret

;private
io_write_to_file:
xchg bx, ax ;teraz bx zawiera uchwyt fileu
xchg bx, ax ;bx = handle to file
mov ah, 40h
mov dx, seg PICBUFFER
mov ds, dx
lea dx, PICBUFFER
mov cx, 57600 ;ilosc bajtow do zapisu
mov cx, 57600
int 21h
call show_mouse
jc io_error
ret

;private
io_open_file:
mov ah, 3dh ;otwarcie fileu
mov ah, 3dh
mov dx, seg file_name
mov ds, dx
lea dx, file_name
Expand All @@ -66,10 +72,11 @@ io_open_file:
jc io_error
ret

;private
io_read_from_file:
mov bx, ax ;uchwyt do bx
mov ah, 3fh ;odczyt z fileu
mov cx, 57600 ;tylu bajtow
mov bx, ax
mov ah, 3fh
mov cx, 57600
mov dx, 0a000h
mov ds, dx
mov dx, 0
Expand Down
11 changes: 7 additions & 4 deletions kdpaint.asm
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ CODE SEGMENT
current_color db 1
PICBUFFER db 57600 dup(?)

;public
main:
call set_graphical_mode
call init_colors
call show_mouse
call init_colors
call set_mouse_movement_bounds
call set_mouse_movement_speed
call show_mouse

main_draw_loop:
;public
main_loop:
mov dx, 0a000h
mov es, dx
mov ax, 3
Expand All @@ -23,13 +25,14 @@ main:
test bx, 2
jnz on_right_mouse_click
jmp main_draw_loop
jmp main_loop

include mouse.asm
include menu.asm
include graph.asm
include io.asm

;public
exit:
call set_text_mode
mov ax, 4c01h
Expand Down
94 changes: 53 additions & 41 deletions menu.asm
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
;public
show_menu:
set_menu_coordinates:
mov ah, 2
mov dh, 23 ;row
mov dl, 0 ;column
mov bh, 0
int 10h
write_menu_content:
mov ah, 9
mov al, 4
mov dx, seg menu_content
mov ds, dx
lea dx, menu_content
int 21h
call set_menu_coordinates
call display_menu_content
ret

;private
set_menu_coordinates:
mov ah, 2
mov dh, 23 ;row
mov dl, 0 ;column
mov bh, 0
int 10h
ret

;private
display_menu_content:
mov ah, 9
mov al, 4
mov dx, seg menu_content
mov ds, dx
lea dx, menu_content
int 21h
ret

;public
hide_menu:
mov cx, 6400
mov al, 3 ; BLK
Expand All @@ -25,64 +34,67 @@ hide_menu:
rep stosb
ret

get_menu_option:
;public
execute_menu_option:
mov ah, 8
int 21h
cmp al, 27 ;ESC
jne k1
jne key_1
jmp exit
k1:
key_1:
cmp al, '1'
jne k2
jne key_2
mov current_color,1
k2:
key_2:
cmp al, '2'
jne k3
jne key_3
mov current_color,2
k3:
key_3:
cmp al, '3'
jne k4
jne key_4
mov current_color,3
k4:
key_4:
cmp al, '4'
jne k5
jne key_5
mov current_color,4
k5:
key_5:
cmp al, '5'
jne k6
jne key_6
mov current_color,5
k6:
key_6:
cmp al, '6'
jne k7
jne key_7
mov current_color,6
k7:
key_7:
cmp al, '7'
jne k8
jne key_8
mov current_color,7
k8:
key_8:
cmp al, '8'
jne k9
jne key_9
mov current_color,8
k9:
key_9:
cmp al, '9'
jne s
jne key_s
mov current_color,9
s:
key_s:
cmp al, 's'
jne l
jne key_l
call io_save_drawing
l:
key_l:
cmp al, 'l'
jne c
jne key_c
call io_load_drawing
c:
key_c:
cmp al, 'c'
jne exit_menu
call clrscr

;public
exit_menu:
call hide_menu
jmp main_draw_loop
jmp main_loop
menu_content db "1red 2blu 3blk 4wht 5pur 6grn 7yel 8tur 9gray s-save l-load c-clear ESC-exit$"
menu_content db "1red 2blu 3blk 4wht 5pur 6grn 7yel 8cyan"
db "9gray s-save l-load c-clear ESC-exit$"
12 changes: 9 additions & 3 deletions mouse.asm
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
;public
hide_mouse:
mov ax, 2
int 33h
ret

;public
show_mouse:
mov ax, 1
int 33h
ret

;public
set_mouse_movement_bounds:
mov ax, 8
mov cx, 180
mov dx, 1
int 33h
ret

;public
set_mouse_movement_speed:
mov ax, 0fh
mov cx, 85 ;horizontal speed
mov cx, 75 ;horizontal speed
mov dx, 50 ;vertical speed
int 33h
ret

;public
on_left_mouse_click:
push bx
mov ax, dx
Expand All @@ -34,8 +39,9 @@ on_left_mouse_click:
mov bl, current_color
mov es:[di], bl
pop bx
jmp main_draw_loop
jmp main_loop

;public
on_right_mouse_click:
call show_menu
jmp get_menu_option
jmp execute_menu_option

0 comments on commit a7bb83f

Please sign in to comment.