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
output
main.asm
SECTION "TimerISR", ROM0[$50]
    jp TimerISR

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

SECTION "Main", ROM0[$0150]
    
TimerISR:
    
    ; スプライト登録
    ld de, $FE00
    
    ld hl, $C000
    ld a, [hl]
    ld [de], a ; Y座標
    
    inc de
    ld hl, $C001
    ld a, [hl]
    ld [de], a ; X座標
    
    inc de
    ld a, 0
    ld [de], a  ; タイル番号
    
    inc de
    ld a, 0
    ld [de], a
    
    ld hl, $C001
    ld a, [hl]
    inc a
    ld [hl], a
    
    reti

start:
    di ; 割り込み禁止
    ld sp, $FFFE ; スタック設定
    
    call display_off
    call bj_clear
    call set_pelette
    call set_intr

    ; タイル0を読み込む
    ld hl, sikaku
    ld de, $8000
    ld bc, 16
    call memcpy
    
    ; 初期座標
    ld a, 50
    ld [$C000], a
    ld a, 60
    ld [$C001], a
    
    call display_on
    ei ; 割り込み許可

hang:
    halt
    jp hang

    ; a=%00000001 VBlank(bit0)割り込みを許可
set_intr:
    
    ld a, 1
    ld [$FFFF], a  
    ret

    ; パレット
set_pelette:
    ld a, %11100100 ; 4色(11 10 01 00)を設定
    ld [$FF47], a ; 背景用
    ld [$FF48], a ; スプライト用
    ret
    
    ; 画面描画停止
display_off:
    xor a
    ldh[$FF40], a
    ret

    ; 画面描画再開: BG有効
display_on:
    ld a, %10010011
    ldh [$FF40], a
    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
    
    ; 画面全体にタイル255(真っ白)を登録する
    ; メモリは初めから0で初期化されているのでタイル255を故意に書き換え無ければ全て0
bj_clear:
    ld bc, 32*32
    ld hl, $9800
loop1:
    ld [hl],255
    inc hl
    dec bc
    ld a, b
    or c
    jr nz, loop1
    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?