draw ok seulement si x est modulo de 8
This commit is contained in:
parent
633b630b92
commit
88d4cb076b
4 changed files with 161 additions and 120 deletions
126
src/bda.asm
126
src/bda.asm
|
|
@ -24,92 +24,94 @@
|
|||
; https://wiki.nox-rhea.org/back2root/ibm-pc-ms-dos/hardware/informations/bios_data_area
|
||||
;
|
||||
|
||||
%define BDA_SEGMENT 0x0040 ; segment BDA
|
||||
%define BDA_SEGMENT 0x0040 ; segment BDA
|
||||
|
||||
; custom vars
|
||||
%define BDA_INFO_MEM_SIZE 0x0014 ; Memory size in Kbytes
|
||||
%define BDA_INFO_MEM_SEG BDA_INFO_MEM_SIZE+2 ; highest Memory Segment
|
||||
%define BDA_INFO_MEM_SIZE 0x0014 ; Memory size in Kbytes
|
||||
%define BDA_INFO_MEM_SEG BDA_INFO_MEM_SIZE+2 ; highest Memory Segment
|
||||
|
||||
; video related information (compatible with VGA bios)
|
||||
%define BDA_VIDEO_CURR_MODE 0x0049
|
||||
%define BDA_VIDEO_COLUMNS 0x004A
|
||||
%define BDA_VIDEO_BUF_SIZE 0x004C
|
||||
%define BDA_VIDEO_OFS_PAGE 0x004E
|
||||
%define BDA_VIDEO_CURR_MODE 0x0049
|
||||
%define BDA_VIDEO_COLUMNS 0x004A
|
||||
%define BDA_VIDEO_BUF_SIZE 0x004C
|
||||
%define BDA_VIDEO_OFS_PAGE 0x004E
|
||||
|
||||
; keyboard related information
|
||||
%define BDA_KBD_HEAD 0x0080 ; byte
|
||||
%define BDA_KBD_TAIL 0x0081 ; byte
|
||||
%define BDA_KBD_FLAGS 0x0082 ; byte: bit0=shift, bit1=ctrl, bit2=alt, bit3=caps, bit4=ext(E0)
|
||||
%define BDA_KBD_BUF 0x0090 ; buffer circulaire (par ex 32 entrées *2 = 64 bytes)
|
||||
%define BDA_KBD_HEAD 0x0080 ; byte
|
||||
%define BDA_KBD_TAIL 0x0081 ; byte
|
||||
%define BDA_KBD_FLAGS 0x0082 ; byte: bit0=shift, bit1=ctrl, bit2=alt, bit3=caps, bit4=ext(E0)
|
||||
%define BDA_KBD_BUF 0x0090 ; buffer circulaire (par ex 32 entrées *2 = 64 bytes)
|
||||
|
||||
%define KBD_BUF_MASK 0x1F ; 32 entrées => index 0..31
|
||||
%define KBD_BUF_MASK 0x1F ; 32 entrées => index 0..31
|
||||
|
||||
;
|
||||
; information relative à la souris
|
||||
;
|
||||
|
||||
%define BDA_DATA_SEG 0x0050
|
||||
%define BDA_MOUSE 0x0000
|
||||
%define BDA_DATA_SEG 0x0050
|
||||
%define BDA_MOUSE 0x0000
|
||||
|
||||
struc mouse
|
||||
.buffer resb 4 ; i8042 input buffer
|
||||
.idx resb 1 ; index in the buffer
|
||||
.packetlen resb 1 ; max buffer len (3 ou 4)
|
||||
.buffer resb 4 ; i8042 input buffer
|
||||
.idx resb 1 ; index in the buffer
|
||||
.packetlen resb 1 ; max buffer len (3 ou 4)
|
||||
|
||||
.status resb 1 ; mouse status (button etc)
|
||||
.wheel resb 1 ; if a packet size is 4; experimental
|
||||
.x resw 1 ;
|
||||
.y resw 1
|
||||
.status resb 1 ; mouse status (button etc)
|
||||
.wheel resb 1 ; if a packet size is 4; experimental
|
||||
.x resw 1 ;
|
||||
.y resw 1
|
||||
; cursor management
|
||||
.cur_x resw 1 ; preservation des x,y du background
|
||||
.cur_y resw 1
|
||||
.cur_addr_start resw 1 ; adresse de départ de la sauvegarde
|
||||
.cur_bank_add resw 1 ; + ou - 0x2000
|
||||
.cur_visible resb 1
|
||||
.cur_seg resw 1 ; segment / offset of the pointer
|
||||
.cur_ofs resw 1
|
||||
.cur_mask resb 1 ; pixels mask (bit per pixel)
|
||||
.cur_bit_ofs resb 1 ; 0..7 bits d'offset (x&7)
|
||||
.bkg_saved resb 1 ; background saved
|
||||
.bkg_buffer resb 16*3 ; buffer for saved background
|
||||
.cur_x resw 1 ; preservation des x,y du background
|
||||
.cur_y resw 1
|
||||
.cur_addr_start resw 1 ; adresse de départ de la sauvegarde
|
||||
.cur_bank_add resw 1 ; + ou - 0x2000
|
||||
.cur_drawing resb 1
|
||||
.cur_visible resb 1
|
||||
.cur_seg resw 1 ; segment / offset of the pointer
|
||||
.cur_ofs resw 1
|
||||
.cur_mask resb 1 ; pixels mask (bit per pixel)
|
||||
.cur_bit_ofs resb 1 ; 0..7 bits d'offset (x&7)
|
||||
.bkg_saved resb 1 ; background saved
|
||||
.bkg_buffer resb 16*3 ; buffer for saved background
|
||||
endstruc
|
||||
|
||||
%define BDA_TIMER (BDA_MOUSE + mouse_size)
|
||||
|
||||
; -----------------------------------------------------------------------------------
|
||||
; PC components I/O ports
|
||||
; -----------------------------------------------------------------------------------
|
||||
|
||||
; controleur clavier/souris i8042 (AT-PS/2)
|
||||
%define i8042_PS2_DATA 0x60
|
||||
%define i8042_PS2_CTRL 0x64
|
||||
%define i8042_PS2_DATA 0x60
|
||||
%define i8042_PS2_CTRL 0x64
|
||||
|
||||
; PIC 8259 ports (Programmable Interrupt Controller)
|
||||
; PIC 1 : Master
|
||||
%define i8259_MASTER_CMD 0x20
|
||||
%define i8259_MASTER_DATA 0x21
|
||||
%define i8259_MASTER_CMD 0x20
|
||||
%define i8259_MASTER_DATA 0x21
|
||||
; PIC 2 : Slave
|
||||
%define i8259_SLAVE_CMD 0xA0
|
||||
%define i8259_SLAVE_DATA 0xA1
|
||||
%define i8259_SLAVE_CMD 0xA0
|
||||
%define i8259_SLAVE_DATA 0xA1
|
||||
|
||||
; i8259 Commands
|
||||
%define ICW1_ICW4 0x01 ; Indicates that ICW4 will be present
|
||||
%define ICW1_SINGLE 0x02 ; Single (cascade) mode
|
||||
%define ICW1_INTERVAL4 0x04 ; Call address interval 4 (8)
|
||||
%define ICW1_LEVEL 0x08 ; Level triggered (edge) mode
|
||||
%define ICW1_INIT 0x10 ; Initialization - required!
|
||||
%define ICW1_ICW4 0x01 ; Indicates that ICW4 will be present
|
||||
%define ICW1_SINGLE 0x02 ; Single (cascade) mode
|
||||
%define ICW1_INTERVAL4 0x04 ; Call address interval 4 (8)
|
||||
%define ICW1_LEVEL 0x08 ; Level triggered (edge) mode
|
||||
%define ICW1_INIT 0x10 ; Initialization - required!
|
||||
|
||||
%define ICW4_8086 0x01 ; 8086/88 (MCS-80/85) mode
|
||||
%define ICW4_AUTO 0x02 ; Auto (normal) EOI
|
||||
%define ICW4_BUF_SLAVE 0x08 ; Buffered mode/slave
|
||||
%define ICW4_BUF_MASTER 0x0C ; Buffered mode/master
|
||||
%define ICW4_SFNM 0x10 ; Special fully nested (not)
|
||||
%define PIC_EOI 0x20
|
||||
%define ICW4_8086 0x01 ; 8086/88 (MCS-80/85) mode
|
||||
%define ICW4_AUTO 0x02 ; Auto (normal) EOI
|
||||
%define ICW4_BUF_SLAVE 0x08 ; Buffered mode/slave
|
||||
%define ICW4_BUF_MASTER 0x0C ; Buffered mode/master
|
||||
%define ICW4_SFNM 0x10 ; Special fully nested (not)
|
||||
%define PIC_EOI 0x20
|
||||
|
||||
; Remap : IRQ0..7 -> 0x08..0x0F, IRQ8..15 -> 0x70..0x77
|
||||
%define i8259_MASTER_INT 0x08
|
||||
%define i8259_SLAVE_INT 0x70
|
||||
%define i8259_MASTER_INT 0x08
|
||||
%define i8259_SLAVE_INT 0x70
|
||||
|
||||
%define IRQ_ENABLED 0x00
|
||||
%define IRQ_DISABLED 0x01
|
||||
%define IRQ_ENABLED 0x00
|
||||
%define IRQ_DISABLED 0x01
|
||||
|
||||
; -----------------------------------------------------------------------------------
|
||||
; bda_setup
|
||||
|
|
@ -117,16 +119,16 @@ endstruc
|
|||
; -----------------------------------------------------------------------------------
|
||||
bda_setup:
|
||||
pusha
|
||||
push ds
|
||||
push ds
|
||||
|
||||
mov ax, BDA_DATA_SEG
|
||||
mov es, ax
|
||||
mov ax, BDA_DATA_SEG
|
||||
mov es, ax
|
||||
|
||||
mov ax, 0x5F
|
||||
mov cx,0xFF
|
||||
xor di, di
|
||||
rep stosb ; clear BDA area
|
||||
mov ax, 0x5F
|
||||
mov cx,0xFF
|
||||
xor di, di
|
||||
rep stosb ; clear BDA area
|
||||
|
||||
pop ds
|
||||
pop ds
|
||||
popa
|
||||
ret
|
||||
59
src/boot.asm
59
src/boot.asm
|
|
@ -102,21 +102,48 @@ endless:
|
|||
mov ax,BDA_DATA_SEG
|
||||
mov ds,ax
|
||||
|
||||
; mov ax, [BDA_MOUSE + mouse.x]
|
||||
; add ax, 80
|
||||
; cmp ax,640
|
||||
; jb .moveok
|
||||
;
|
||||
; mov ax,0
|
||||
;.moveok:
|
||||
; mov [BDA_MOUSE + mouse.x],ax
|
||||
;
|
||||
; call gfx_cursor_move
|
||||
mov dx,0x300
|
||||
call scr_gotoxy
|
||||
|
||||
mov al, byte [BDA_TIMER]
|
||||
call scr_puthex8
|
||||
|
||||
cmp byte [BDA_TIMER],5
|
||||
ja .skip2
|
||||
|
||||
mov ax, [BDA_MOUSE + mouse.x]
|
||||
add ax, 25
|
||||
cmp ax,640
|
||||
jb .moveok
|
||||
;
|
||||
mov ax,0
|
||||
.moveok:
|
||||
mov [BDA_MOUSE + mouse.x],ax
|
||||
;
|
||||
call gfx_cursor_move
|
||||
|
||||
cmp byte [BDA_MOUSE + mouse.buffer+1], 0
|
||||
jge .skip
|
||||
|
||||
mov dx,0x400
|
||||
call scr_gotoxy
|
||||
|
||||
mov al, byte [BDA_MOUSE + mouse.buffer+1]
|
||||
call scr_puthex8
|
||||
.skip:
|
||||
cmp byte [BDA_MOUSE + mouse.buffer+2], 0
|
||||
jge .skip2
|
||||
|
||||
mov dx,0x404
|
||||
call scr_gotoxy
|
||||
|
||||
mov al, byte [BDA_MOUSE + mouse.buffer+2]
|
||||
call scr_puthex8
|
||||
.skip2:
|
||||
mov dx,0
|
||||
call scr_gotoxy
|
||||
|
||||
mov ax,0 ; adresse début dump
|
||||
mov ax,[BDA_MOUSE] ; adresse début dump
|
||||
mov si,ax
|
||||
mov cx, 0x20
|
||||
.dump:
|
||||
|
|
@ -150,14 +177,14 @@ endless:
|
|||
test_isr:
|
||||
push ax
|
||||
|
||||
; push fs
|
||||
;mov ax,BDA_DATA_SEG
|
||||
;mov fs,ax
|
||||
;inc byte [fs:0x0005]
|
||||
push fs
|
||||
mov ax,BDA_DATA_SEG
|
||||
mov fs,ax
|
||||
inc byte [fs:BDA_TIMER]
|
||||
|
||||
mov al, PIC_EOI ; EOI master
|
||||
out i8259_MASTER_CMD, al
|
||||
; pop fs
|
||||
pop fs
|
||||
|
||||
pop ax
|
||||
iret
|
||||
|
|
|
|||
|
|
@ -252,11 +252,16 @@ gfx_getpixel_fast:
|
|||
gfx_cursor_move:
|
||||
pusha
|
||||
push ds
|
||||
push es
|
||||
|
||||
; move Data Segment
|
||||
mov ax, BDA_DATA_SEG
|
||||
mov ds, ax
|
||||
|
||||
cmp byte [BDA_MOUSE + mouse.cur_drawing],0
|
||||
jne .done
|
||||
mov byte [BDA_MOUSE + mouse.cur_drawing],1
|
||||
|
||||
mov ax, VIDEO_SEG
|
||||
mov es, ax
|
||||
|
||||
|
|
@ -265,32 +270,39 @@ gfx_cursor_move:
|
|||
call gfx_cursor_savebg
|
||||
|
||||
call gfx_cursor_draw
|
||||
|
||||
mov byte [BDA_MOUSE + mouse.cur_drawing],0
|
||||
.done:
|
||||
pop es
|
||||
pop ds
|
||||
|
||||
popa
|
||||
ret
|
||||
|
||||
; ------------------------------------------------------------
|
||||
; Dessine le curseur 16x16 AND/XOR à [BDA_CURSOR_NEWX],[BDA_CURSOR_NEWY]
|
||||
; Dessine le curseur 16x16 AND/XOR à [mouse.x,mouse.y]
|
||||
;
|
||||
; CS:SI = base du sprite (AND[16] suivi de XOR[16] à +32 bytes)
|
||||
; Uses: BDA_CURSOR_BITOFF/BDA_CURSOR_BYTES (via gfx_cursor_calc_align)
|
||||
; sprite (AND[16] suivi de XOR[16] à +32 bytes)
|
||||
; ------------------------------------------------------------
|
||||
gfx_cursor_draw:
|
||||
; pusha
|
||||
|
||||
mov ax, BDA_DATA_SEG
|
||||
mov ds, ax
|
||||
|
||||
mov ax, VIDEO_SEG
|
||||
mov es, ax
|
||||
|
||||
mov ax, word [BDA_MOUSE + mouse.cur_ofs]
|
||||
mov si, ax
|
||||
|
||||
mov ax, word [BDA_MOUSE + mouse.cur_seg]
|
||||
mov gs, ax
|
||||
|
||||
mov cx, word [BDA_MOUSE + mouse.x]
|
||||
mov dx, word [BDA_MOUSE + mouse.y]
|
||||
|
||||
mov word [BDA_MOUSE + mouse.cur_x], cx ; sauvegarde la nouvelle position
|
||||
mov word [BDA_MOUSE + mouse.cur_y], dx
|
||||
|
||||
; calcule offset et bytes/ligne (2 ou 3)
|
||||
call gfx_cursor_calc_align
|
||||
mov bl, byte [BDA_MOUSE + mouse.cur_bit_ofs]; 0..7
|
||||
|
|
@ -310,20 +322,20 @@ gfx_cursor_draw:
|
|||
mov dh, 8
|
||||
.pair:
|
||||
; ----- ligne row (bank courant) -----
|
||||
push di
|
||||
push si
|
||||
; push di
|
||||
; push si
|
||||
call .draw_line ; utilise DI, row=BX
|
||||
pop si
|
||||
pop di
|
||||
; pop si
|
||||
; pop di
|
||||
|
||||
; ----- ligne row+1 (autre bank) -----
|
||||
add di, bp
|
||||
inc bh
|
||||
push di
|
||||
push si
|
||||
; push di
|
||||
; push si
|
||||
call .draw_line
|
||||
pop si
|
||||
pop di
|
||||
; pop si
|
||||
; pop di
|
||||
sub di, bp
|
||||
|
||||
; avancer de 2 lignes (dans le bank courant): +80 bytes
|
||||
|
|
@ -340,31 +352,30 @@ gfx_cursor_draw:
|
|||
; .draw_line: applique AND/XOR sur une ligne de 16 pixels à ES:DI
|
||||
; row index dans BX (0..15)
|
||||
; offset dans BL (0..7)
|
||||
; sprite base CS:SI
|
||||
; sprite base GS:SI
|
||||
; ------------------------------------------------------------
|
||||
.draw_line:
|
||||
push ax
|
||||
push cx
|
||||
push dx
|
||||
push bp
|
||||
push di
|
||||
|
||||
; charger masks de la ligne: AND = [SI + row*2], XOR = [SI + 32 + row*2]
|
||||
xor ax, ax
|
||||
mov al, bh
|
||||
shl ax, 1 ; row*2
|
||||
shl ax, 1 ; row*2
|
||||
|
||||
push si
|
||||
add si, ax
|
||||
mov cx, [cs:si] ; AND mask
|
||||
mov cx, [gs:si] ; AND mask
|
||||
add si, 32
|
||||
mov dx, [cs:si] ; XOR mask
|
||||
mov dx, [gs:si] ; XOR mask
|
||||
pop si
|
||||
|
||||
; lire bytes source
|
||||
mov al, [es:di] ; b0
|
||||
mov al, [es:di] ; b0
|
||||
inc di
|
||||
mov ah, [es:di] ; b1
|
||||
mov ah, [es:di] ; b1
|
||||
dec di
|
||||
; w0 = (b0<<8)|b1 dans AX déjà
|
||||
|
||||
|
|
@ -373,9 +384,9 @@ gfx_cursor_draw:
|
|||
|
||||
; unaligned: besoin b2 et w1 = (b1<<8)|b2
|
||||
add di, 2
|
||||
mov dl, [es:di] ; b2
|
||||
mov dl, [es:di] ; b2
|
||||
sub di, 2
|
||||
mov dh, ah ; b1
|
||||
mov dh, ah ; b1
|
||||
; DX = w1 (b1<<8)|b2
|
||||
|
||||
; seg = (w0<<off) | (w1>>(8-off))
|
||||
|
|
@ -470,13 +481,11 @@ gfx_cursor_draw:
|
|||
mov [es:di], al ; low
|
||||
.done:
|
||||
pop di
|
||||
pop bp
|
||||
pop dx
|
||||
pop cx
|
||||
pop ax
|
||||
ret
|
||||
|
||||
|
||||
; ------------------------------------------------------------
|
||||
; Sauvegarde le background (24x16) sous le curseur
|
||||
;
|
||||
|
|
@ -488,19 +497,17 @@ gfx_cursor_savebg:
|
|||
|
||||
mov byte [BDA_MOUSE + mouse.bkg_saved], 1 ; image saved
|
||||
|
||||
mov cx, [BDA_MOUSE + mouse.x] ;
|
||||
mov cx, [BDA_MOUSE + mouse.x] ;
|
||||
mov dx, [BDA_MOUSE + mouse.y]
|
||||
|
||||
mov word [BDA_MOUSE + mouse.cur_x], cx ; sauvegarde la nouvelle position
|
||||
mov word [BDA_MOUSE + mouse.cur_y], dx
|
||||
|
||||
call gfx_calc_addr ; ES:DI = byteaddr pour (X,Y)
|
||||
mov dx,0x2000 ; offset pour lignes impaire
|
||||
cmp di,dx
|
||||
jl .no_odd_bank
|
||||
neg dx ; Y est déja une ligne impaire, on retire l'offset
|
||||
|
||||
.no_odd_bank:
|
||||
mov ax, di ; préserver l'address de départ
|
||||
mov ax, di ; préserver l'address de départ
|
||||
mov word [BDA_MOUSE + mouse.cur_addr_start],ax
|
||||
mov word [BDA_MOUSE + mouse.cur_bank_add], dx
|
||||
|
||||
|
|
@ -546,7 +553,7 @@ gfx_cursor_restorebg:
|
|||
mov ax, word [BDA_MOUSE + mouse.cur_addr_start]
|
||||
mov di,ax
|
||||
mov dx, word [BDA_MOUSE + mouse.cur_bank_add]
|
||||
|
||||
|
||||
mov ax, BDA_MOUSE + mouse.bkg_buffer
|
||||
mov si, ax ; DS:SI = buffer de sauvegarde
|
||||
mov bx, 8 ; 16 lignes, mais nous traitons "en une fois" les paire/impaires
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ mouse_reset:
|
|||
mov byte [fs:BDA_MOUSE + mouse.cur_visible], 1
|
||||
mov word [fs:BDA_MOUSE + mouse.cur_x], 0
|
||||
mov word [fs:BDA_MOUSE + mouse.cur_y], 0
|
||||
mov byte [fs:BDA_MOUSE + mouse.cur_drawing], 0
|
||||
|
||||
mov ax, cs
|
||||
mov word [fs:BDA_MOUSE + mouse.cur_seg], ax
|
||||
|
|
@ -301,6 +302,7 @@ isr_mouse_handler:
|
|||
|
||||
; lire un octet depuis le contrôleur et le stocker dans le buffer
|
||||
in al, i8042_PS2_DATA ; lire octet souris
|
||||
|
||||
movzx bx, byte [BDA_MOUSE + mouse.idx]
|
||||
mov byte [BDA_MOUSE + mouse.buffer + bx], al
|
||||
inc byte [BDA_MOUSE + mouse.idx]
|
||||
|
|
@ -308,20 +310,29 @@ isr_mouse_handler:
|
|||
; vérifier si le packet est complet
|
||||
mov al, [BDA_MOUSE + mouse.packetlen]
|
||||
cmp byte [BDA_MOUSE + mouse.idx], al
|
||||
jne .done
|
||||
jb .done
|
||||
|
||||
; packet complet, on decode les données
|
||||
mov byte [BDA_MOUSE + mouse.idx], 0
|
||||
mov al, [BDA_MOUSE + mouse.buffer] ; status
|
||||
mov [BDA_MOUSE + mouse.status], al
|
||||
mov bl, [BDA_MOUSE + mouse.buffer] ; status
|
||||
mov [BDA_MOUSE + mouse.status], bl
|
||||
|
||||
xor ax,ax
|
||||
mov al, byte [BDA_MOUSE + mouse.buffer+1] ; delta X
|
||||
mov al, byte [BDA_MOUSE + mouse.buffer+1] ; delta X
|
||||
test bl,00010000b ; signe X
|
||||
jz .x_pos
|
||||
or al, 0xF0
|
||||
.x_pos:
|
||||
cbw
|
||||
add [BDA_MOUSE + mouse.x], ax
|
||||
|
||||
|
||||
xor ax,ax
|
||||
mov al, byte [BDA_MOUSE + mouse.buffer+2] ; delta Y
|
||||
mov al, byte [BDA_MOUSE + mouse.buffer+2] ; delta Y
|
||||
test bl,00100000b ; signe Y
|
||||
jz .y_pos
|
||||
or al, 0xF0
|
||||
.y_pos:
|
||||
cbw
|
||||
sub [BDA_MOUSE + mouse.y], ax
|
||||
|
||||
|
|
@ -349,14 +360,8 @@ isr_mouse_handler:
|
|||
jle .y_ok_high
|
||||
mov word [BDA_MOUSE + mouse.y], 199
|
||||
.y_ok_high:
|
||||
; restaurer l'ancien arrière plan du curseur
|
||||
call gfx_cursor_restorebg
|
||||
|
||||
; sauvegarder le nouvel arrière plan du curseur
|
||||
call gfx_cursor_savebg
|
||||
|
||||
call gfx_cursor_draw
|
||||
|
||||
;call gfx_cursor_move
|
||||
.done:
|
||||
mov al, 0x20
|
||||
out i8259_SLAVE_CMD, al ; EOI PIC esclave
|
||||
|
|
|
|||
Loading…
Reference in a new issue