マイペースなプログラミング日記

DTMやプログラミングにお熱なd-kamiがマイペースに書くブログ

ブートセクタプログラミング 四角いオセロ

以前作ったものはオセロ盤を描画するだけだったが、今回は石も置いてみた。しかし四角い石である。余裕があれば丸くしていきたい。あとメモリの初期化を行った

cpu  8086
bits 16
org  0x7C00

%macro draw 2
    mov cl, %1
    mov dl, %2
    call draw_stone
%endmacro

    ; init segment register
    mov ax, 0x7B0
    mov ds, ax
    mov es, ax
    mov sp, 0x7C00

    ; init memory for othello board
    mov ax, word 2
    xor di, di
    mov cx, word 100
    rep stosb

    ; init register for othello board
    mov cl, 81
    mov al, 1
    mov di, word 11
    xor bx, bx

init_board:
    dec cl
    ; memory[di] is 2
    stosb
    mov bl, 0x09
    and bl, cl
    je nextline
    jmp init_board

init_stone:
    mov al, 0x00
    mov [0x55], al
    mov [0x66], al

    mov al, 0xFF
    mov [0x56], al
    mov [0x65], al

init_display:
    ; init display
    xor ah, ah
    mov al, 0x12
    int 0x10
    
    mov cx, 0x100
    mov dx, 0x100

draw_board:
    ; vertical edge check
    mov bx, 0x1F
    test bx, cx
    je set_black
    
    ; horizontal edge check
    and bx, dx
    je set_black
    
    ; dot color is green
    mov al, 0x02
    
draw_dot:
    mov ah, 0x0C
    ; draw
    int 0x10
    
    ; x--
    dec cx
    
    ; if x != 0 then drawboard
    jne draw_board
    
    ; cx = 0x100
    inc ch
    
    ; y--
    dec dx
    
    ; if y != 0 then drawboard
    jne draw_board
    
    xor cx, cx
    xor dx, dx
    mov ax, 0x0C0F
    draw 0x80, 0x80
    draw 0xA0, 0xA0
    xor al, al
    draw 0x80, 0xA0
    draw 0xA0, 0x80
fin:
    hlt
    jmp fin

nextline:
    ; di is next line
    add di, word 2

    ; if cl == 0 then init_display
    test cl, 0
    je init_stone

    ;  if cl != 0 then init_board
    jmp init_board

draw_stone:
    int 0x10
    dec cx
    mov bx, 0x1F
    test cx, bx
    jne draw_stone
    add cx, 0x20
    dec dx
    test dx, bx
    jne draw_stone
    
    ret

set_black:
    ; dot color is black
    xor al, al
    jmp draw_dot

    times 510 - ($ - $$) db 0x00
    dw 0xAA55