0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ゲームボーイ_割り込み処理

0
Posted at
rgbasm -o main.o main.asm && \
rgblink -o main.gb main.o && \
rgbfix -v -p 0xFF main.gb && \
../SameBoy-master/build/bin/SDL/sameboy main.gb
截图 2026-09-14 21-00-55
main.asm
SECTION "VBlank Interrupt", ROM0[$040]
    jp VBlankHandler

SECTION "Entry", ROM0[$0100]
    jp start

SECTION "Main", ROM0[$0150]

VBlankHandler:
    ld hl, $C000
    ld a, [hl]
    
    ; タイルを登録
    ld hl, $9800
    
    ld e, a
    ld d, 0
    add hl, de
    ld [hl], 0
    
    inc a
    ld [$C000], a
    
    reti

start:
    di ; 割り込み禁止
    
    ld sp, $FFFE
    
    call display_off
    call set_pelette
    call bj_clear
    
    ; a=%00000001 VBlank(bit0)割り込みを許可
    ld a, 1
    ld [$FFFF], a  
    
    ; タイル0を読み込む
    ld hl, sikaku
    ld de, $8000
    ld bc, 16
    call memcpy
    
    call display_on  
    
    ld a, 0
    ld [$C000], a
    
    ei ; 割り込み許可
    
hang:
    jr hang
    

    ; 画面描画停止
display_off:
    xor a
    ldh[$FF40], a
    ret

    ; 画面描画再開: BG有効
display_on:
    ld a, %10010011
    ldh [$FF40], a
    ret
    
    ; パレット
set_pelette:
    ld a, %11100100 ; 4色(11 10 01 00)を設定
    ld [$FF47], a ; 背景用
    ld [$FF48], a ; スプライト用
    ret
        
    ; 画面全体にタイル255(真っ白)を登録する
    ; メモリは初めから0で初期化されているのでタイル255を故意に書き換え無ければ全て0
bj_clear:
    ld bc, 1024
    ld hl, $9800
loop1:
    ld [hl],255
    inc hl
    dec bc
    ld a, b
    or c
    jr nz, loop1
    ret
    
; メモリ複製関数
; HL=元, DE=先, BC=長さ
memcpy:
    ld a, [hl]
    ld [de], a
    inc hl
    inc de
    dec bc
    ld a, b      ; B==CならBC==0 (B==$FF,C==$FFの時は失敗する)
    or c
    jr nz,memcpy ; BC!=0なら繰り返す
    ret
    
sikaku:
    db %00000000, %00000000
    db %01111110, %01111110
    db %01111110, %01111110
    db %01111110, %01111110
    db %01111110, %01111110
    db %01111110, %01111110
    db %01111110, %01111110
    db %00000000, %00000000
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?