Created
September 3, 2020 09:36
-
-
Save soyoil/26f92faa00d98ef5e2747cdf5c754c93 to your computer and use it in GitHub Desktop.
ゲームボーイでカレンダーを表示してみる試み
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include "hardware.inc" | |
section "halt", rom0[$38] | |
di | |
halt | |
stop | |
section "lcdc status interrupt", rom0[$48] | |
reti | |
section "serial interrupt", rom0[$58] | |
reti | |
section "keypad interrupt", rom0[$60] | |
reti | |
section "header", rom0[$100] | |
EntryPoint: | |
nop | |
jp start | |
NINTENDO_LOGO | |
rept $150 - $134 | |
db 0 | |
endr | |
section "code", rom0[$150] | |
start: | |
; Turn off the LCD | |
.waitVBlank | |
ld a, [rLY] | |
cp 144 | |
jr c, .waitVBlank | |
xor a | |
ld [rLCDC], a | |
; Copy font data | |
ld hl, $9000 | |
ld de, FontTiles | |
ld bc, FontTilesEnd - FontTiles | |
.copyFont | |
ld a, [de] | |
ld [hli], a | |
inc de | |
dec bc | |
ld a, b | |
or c | |
jr nz, .copyFont | |
; Insert date to memory | |
ld hl, $C000 ; work RAM | |
ld de, Date | |
ld bc, DateEnd - Date | |
.insertDate | |
ld a, [de] | |
ld [hli], a | |
inc de | |
dec bc | |
ld a, b | |
or c | |
jr nz, .insertDate | |
; print current date | |
ld bc, $C000 | |
ld hl, $9866 | |
.printDate | |
ld a, [bc] | |
rept 4 | |
srl a | |
endr | |
add a, $30 | |
ld [hli], a | |
ld a, [bc] | |
and %00001111 | |
add a, $30 | |
ld [hli], a | |
inc bc | |
ld a, $4 | |
cp a, c | |
jr z, .printDateEnd | |
ld a, $2 | |
cp a, c | |
jr nz, .printDate | |
ld a, [bc] | |
ld [hli], a | |
inc bc | |
jr .printDate | |
.printDateEnd | |
; print week | |
ld hl, $98C0 | |
ld de, Week | |
ld bc, WeekEnd - Week | |
.printWeek | |
ld a, [de] | |
ld [hli], a | |
inc de | |
dec bc | |
ld a, [de] | |
ld [hli], a | |
inc hl | |
inc de | |
dec bc | |
ld a, b | |
or c | |
jr nz, .printWeek | |
; seek head | |
ld hl, $98E0 | |
ld de, $0003 | |
ld b, $7 | |
.seekHead | |
dec b | |
jr z, .seekHeadEnd | |
add hl, de | |
jr .seekHead | |
.seekHeadEnd | |
; print calender | |
ld de, $0B | |
xor a | |
ld c, $31 ; todo | |
.printCal | |
; ---- | |
add a, 1 | |
daa | |
ld b, a | |
rept 4 | |
srl a | |
endr | |
add a, $30 | |
ld [hli], a | |
ld a, b | |
and %00001111 | |
add a, $30 | |
ld [hli], a | |
ld a, b | |
inc hl | |
; ---- | |
push af | |
ld a, $F5 | |
cp a, l | |
jr z, .NewLine | |
rept 5 | |
add a, $20 | |
cp a, l | |
jr z, .NewLine | |
endr | |
jr .NewLineEnd | |
.NewLine | |
add hl, de | |
.NewLineEnd | |
pop af | |
cp a, c | |
jr nz, .printCal | |
; Init display registers | |
ld a, %11100100 | |
ld [rBGP], a | |
xor a | |
ld [rSCY], a | |
ld [rSCX], a | |
; Shut sound down | |
ld [rNR52], a | |
; Turn screen on, display background | |
ld a, %10000001 | |
ld [rLCDC], a | |
; Lock up | |
halt | |
.lockup | |
jr .lockup | |
section "Font", rom0 | |
FontTiles: | |
INCBIN "font.chr" | |
FontTilesEnd: | |
section "Const", rom0 | |
Date: | |
db $20, $20, $2D, $08 | |
DateEnd: | |
Week: | |
db "SUMOTUWETHFRSA" | |
WeekEnd: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment