b8

A x86 32bits native fantazy console.
git clone git://git.vgx.fr/b8
Log | Files | Refs

test.asm (1323B)


      1 org 0x20000
      2 bits 32
      3 
      4 pix:   equ 0x40000
      5 screen_size: equ 0x10000
      6 input: equ 0x50000
      7 
      8 header: db '#!/usr/bin/env b8', 0x0a
      9 times 32-$+header db 0x0
     10 
     11 jmp [state_fun]
     12 state_fun dd init
     13 
     14 init:
     15 	; set initial screen
     16 	mov ecx, screen_size
     17 	.loop:
     18 		push cx
     19 		call colorize
     20 		pop cx
     21 		mov byte [ecx + pix], al
     22 		loop .loop
     23 
     24 	mov dword [state_fun], f
     25 	ret
     26 
     27 f:
     28 	; update coords
     29 	mov eax, 0
     30 	mov al, byte [input]
     31 	mov edx, [coords]
     32 
     33 	.check_left:
     34 	mov cl, 1b
     35 	and cl, al
     36 	jz .check_right
     37 	sub dx, 1
     38 
     39 	.check_right:
     40 	mov cl, 10b
     41 	and cl, al
     42 	jz .check_up
     43 	add dx, 1
     44 
     45 	.check_up:
     46 	mov cl, 100b
     47 	and cl, al
     48 	jz .check_down
     49 	sub dx, 0x100
     50 
     51 	.check_down:
     52 	mov cl, 1000b
     53 	and cl, al
     54 	jz .check_end
     55 	add dx, 0x100
     56 
     57 	.check_end:
     58 	mov [coords], edx
     59 
     60 	; get color
     61 	mov ecx, [coords]
     62 	mov eax, screen_size-1
     63 	sub eax, ecx
     64 	push ax
     65 	call colorize
     66 	add esp, 2
     67 
     68 	mov edx, [coords]
     69 	mov byte [pix+edx], al
     70 	ret
     71 
     72 colorize:
     73 	mov al, 0
     74 	mov dx, 0
     75 	mov cx, [esp+4] ; get fun argument
     76 
     77 	;red part
     78 	mov dl, cl
     79 	and dl, 01110000b
     80 	sal dl, 1
     81 	and dl, 11100000b
     82 	or  al, dl
     83 
     84 	;green part
     85 	mov dl, ch
     86 	and dl, 01110000b
     87 	sar dl, 1
     88 	sar dl, 1
     89 	and dl, 00011100b
     90 	or  al, dl
     91 
     92 	;dlue part
     93 	and ch, 10000000b
     94 	mov dl, ch
     95 	and cl, 10000000b
     96 	sar cl, 1
     97 	and cl, 01000000b
     98 	or  dl, cl
     99 	mov cl, 6
    100 	sar dl, cl
    101 	and dl, 00000011b
    102 	or  al, dl
    103 
    104 	ret
    105 
    106 coords: dd 0x8080
    107