b8

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.vgx.fr/b8
Log | Files | Refs

commit 6d4d61aacb45fb93025e4c957ddc331c61a3c9a1
parent 3ad7640c45114bb56c9c7759c56c772b5c3ab138
Author: Léo Villeveygoux <leo.villeveygoux@etu.u-bordeaux.fr>
Date:   Fri,  7 Jul 2017 20:33:46 +0200

draw.asm: make color selection a togglable mode

Diffstat:
Mdraw.asm | 192++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 137 insertions(+), 55 deletions(-)

diff --git a/draw.asm b/draw.asm @@ -21,6 +21,8 @@ draw_loop: ; undraw cross call inv_cross + call preprocess_input + ; update coords mov eax, 0 mov al, byte [input] @@ -47,30 +49,28 @@ draw_loop: .check_down: mov cl, 1000b and cl, al - jz .check_x + jz .update_coords add dx, 0x100 - + + .update_coords: + mov [coords], edx + ; update color + mov al, byte [pressed_input] .check_x: mov cl, 10000b and cl, al - jz .check_no_x - mov byte [pressing_x], byte 1 - jmp .check_c - - .check_no_x: - mov cl, [pressing_x] - mov byte [pressing_x], byte 0 - test cl, cl - jz .check_c - mov cl, [selected] - inc cl - and cl, [palette_mask] - mov byte [selected], cl + + call inv_cross + call swap_palette_buffer + mov ecx, palette_loop + mov [state_fun], ecx + ret ; draw pixel .check_c + mov al, [input] mov cl, 100000b and cl, al jz .check_end @@ -82,16 +82,47 @@ draw_loop: mov byte [pix+edx], al .check_end: - mov [coords], edx call inv_cross + ret + +palette_loop: call draw_palette + call preprocess_input + + mov eax, 0 + mov al, byte [pressed_input] + + .check_x: + mov cl, 10000b + and cl, al + jz .check_c + call swap_palette_buffer + mov ecx, draw_loop + mov [state_fun], ecx + ret + + ; draw pixel + .check_c + mov cl, 100000b + and cl, al + jz .check_end + + ; change color + mov cl, [selected] + inc cl + and cl, [palette_mask] + mov byte [selected], cl + + .check_end: + ret inv_cross: mov edx, [coords] + mov ecx, 0 ;up mov cx, dx @@ -130,58 +161,109 @@ inv_pix: ;pass coords in cl ret draw_palette: - mov ecx, 0x10 + mov ecx, 0xf mov edx, pix .y_loop: - push ecx - - mov ecx, 0x100 - - .x_loop: - push edx + push ecx + + ; this gives a slight slant to color cells + ; but it's actually funny + mov ecx, 0xff + + .x_loop: + push edx + + ; get color id + mov edx, ecx + sar edx, 5 + + mov eax, 0 + mov al, [selected] + + ;spagetti party! + cmp al, dl + je .draw_selected + + .draw_direct: + mov al, byte [palette + edx] + jmp .draw + + .draw_selected: + ;TODO: remove hardcoded values limiting to 16 color palettes + + ;column borders + mov eax, ecx + and eax, 0x1f + cmp eax, 4 + jl .do_it + + cmp eax, 27 + jg .do_it + + ;line borderes + mov eax, [esp+4] + cmp eax, 4 + jl .do_it + + cmp eax, 13 + jg .do_it + + jmp .draw_direct + + .do_it + mov al, byte [palette + edx] + xor al, ~0 + + .draw: + pop edx + mov [edx], al ; put color to screen + inc edx + loop .x_loop + + pop ecx + loop .y_loop - ; get color id - mov edx, ecx - sar edx, 5 - - mov eax, 0 - mov al, [selected] - - ;spagetti party! - cmp al, dl - je .draw_selected + ret - .draw_direct: - mov al, byte [palette + edx] - jmp .draw +swap_palette_buffer: + mov ecx, 0x1000 + + .loop: + mov al, byte [pix + ecx] + mov dl, byte [palette_buffer + ecx] + mov byte [pix + ecx], dl + mov byte [palette_buffer + ecx], al + loop .loop - .draw_selected: - mov eax, ecx - and eax, 0x1f - cmp eax, 3 - jl .do_it ; overlay half columns + ret - cmp eax, 29 - jl .draw_direct +preprocess_input: + mov al, byte [new_input] + mov byte [old_input], al + mov cl, byte [input] + mov byte [new_input], cl - .do_it - mov al, byte [palette + edx] xor al, ~0 - - .draw: - pop edx - mov [edx], al ; put color to screen - inc edx - loop .x_loop - - pop ecx - loop .y_loop + and cl, al + mov byte [pressed_input], cl + mov al, byte [old_input] + mov cl, byte [new_input] + xor cl, ~0 + and al, cl + mov byte [released_input], cl + ret coords: dd 0x8080 -pressing_x: db 0 +;pressing_x: db 0 +old_input: db 0 +new_input: db 0 +pressed_input: db 0 +released_input: db 0 + selected: db 0 palette: db 0, 11b, 11111b, 11100b, 11111100b, 11100000b, 11100011b, ~0 palette_mask: db 7 +palette_buffer: times 0x1000 db 0 ;256 col * 16 lines