Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BGTiles EQU $8000
- BGTileMap EQU $9800
- BGTileMapDigits EQU $98e0
- hDigitsStaging EQU $ff80
- rNR52 EQU $ff26
- rLCDC EQU $ff40
- rSTAT EQU $ff41
- rSCX EQU $ff42
- rSCY EQU $ff43
- rIE EQU $ffff
- IncrementCounter EQU $00
- AdjustDEbyA EQU $18
- CopyLineOfTiles EQU $20
- DelayFrame EQU $28
- ClearStaging EQU $30
- SECTION "ROM", ROM0[0]
- _IncrementCounter:
- ; as a tribute to the original, use daa here
- ; (instead of dividing by 10 to display)
- ld a, e
- add a, 1
- daa
- ld e, a
- ret nc
- ld a, d
- add a, 1
- daa
- ld d, a
- ret nc
- ld a, c
- add a, 1
- daa
- ld c, a
- ret nc
- ld a, b
- add a, 1
- daa
- ld b, a
- ret
- _AdjustDEbyA:
- add a, a
- add a, a
- add a, a
- add a, e
- ld e, a
- ret nc
- inc d
- ret
- _CopyLineOfTiles:
- ld a, [de]
- inc de
- ld [hli], a
- ld a, [de]
- inc de
- ld [hli], a
- add hl, bc
- ret
- _DelayFrame:
- and a
- .loop
- halt
- jr nc, .loop
- ret
- ds 2 ; padding up to $0030
- _ClearStaging:
- ld bc, 80 * $100 + LOW(hDigitsStaging) ; b = 80, c = LOW(hDigitsStaging)
- xor a
- .loop
- ld [c], a
- inc c
- dec b
- jr nz, .loop
- ret
- ds 6 ; padding up to $0040
- VBlank:
- push bc
- push de
- ld bc, 10 * $100 + LOW(hDigitsStaging) ; b = 10, c = LOW(hDigitsStaging)
- ld hl, BGTileMapDigits
- ld de, 12
- ; copy 4 rows of 20 tiles
- ; the lazy way
- rept 3
- .loop\@
- ld a, [c]
- inc c
- ld [hli], a
- ld a, [c]
- inc c
- ld [hli], a
- dec b
- jr nz, .loop\@
- add hl, de
- ld b, 10
- endr
- .final_loop
- ld a, [c]
- inc c
- ld [hli], a
- ld a, [c]
- inc c
- ld [hli], a
- dec b
- jr nz, .final_loop
- ; done, pop everything and set carry
- pop de
- pop bc
- scf
- reti
- DisplayDigit:
- rst AdjustDEbyA
- push bc
- ld bc, 18
- rst CopyLineOfTiles
- rst CopyLineOfTiles
- rst CopyLineOfTiles
- rst CopyLineOfTiles
- pop bc
- ret
- DisplayByte:
- push de
- push hl
- push af
- swap a
- and $f
- ld de, LeftDigits
- call DisplayDigit
- pop af
- and $f
- ld de, RightDigits
- pop hl
- inc hl
- inc hl
- inc hl
- call DisplayDigit
- pop de
- ret
- Main:
- ld a, $51
- ldh [rLCDC], a
- ld de, Tiles
- ld c, 31
- ld hl, BGTiles
- .tile_copy_loop
- ld b, 8
- .inner_copy_loop
- ld a, [de]
- inc de
- ld [hli], a
- ld [hli], a
- dec b
- jr nz, .inner_copy_loop
- dec c
- jr nz, .tile_copy_loop
- xor a
- ldh [rSCX], a
- ldh [rSCY], a
- ldh [rNR52], a
- ld hl, BGTileMap
- ld de, 12
- ld b, 18
- .tilemap_fill_loop
- ld c, 20
- .inner_fill_loop
- ld [hli], a
- dec c
- jr nz, .inner_fill_loop
- add hl, de
- dec b
- jr nz, .tilemap_fill_loop
- ; bc = 0 here
- ld d, a
- inc a
- ld e, a
- ldh [rIE], a
- ld hl, rLCDC
- set 7, [hl]
- ei
- rst DelayFrame
- .main_loop
- ld a, b
- ld hl, hDigitsStaging
- call DisplayByte
- ld a, c
- ld hl, hDigitsStaging + 5
- call DisplayByte
- ld a, d
- ld hl, hDigitsStaging + 10
- call DisplayByte
- ld a, e
- ld hl, hDigitsStaging + 15
- call DisplayByte
- rst DelayFrame
- rst IncrementCounter
- jr .main_loop
- ; $0100 is here
- Init:
- di
- rst ClearStaging
- jr Main
- rept $4c
- db 0
- endr
- Tiles:
- db $00, $00, $00, $00, $00, $00, $00, $00 ;00
- db $00, $00, $00, $00, $00, $00, $0f, $0f ;01
- db $00, $00, $00, $00, $00, $00, $0c, $0c ;02
- db $00, $00, $00, $00, $00, $00, $ff, $ff ;03
- db $0c, $0c, $0c, $0c, $0c, $0c, $0c, $0f ;04
- db $0c, $0c, $0c, $0c, $0c, $0c, $0c, $0c ;05
- db $00, $00, $00, $00, $00, $00, $00, $0f ;06
- db $0f, $0c, $0c, $0c, $0c, $0c, $0c, $0c ;07
- db $0f, $00, $00, $00, $00, $00, $00, $00 ;08
- db $0f, $0f, $00, $00, $00, $00, $00, $00 ;09
- db $03, $03, $03, $03, $03, $03, $03, $ff ;10
- db $00, $00, $00, $00, $00, $00, $00, $ff ;11
- db $03, $03, $03, $03, $03, $03, $03, $03 ;12
- db $03, $03, $00, $00, $00, $00, $00, $00 ;13
- db $ff, $ff, $00, $00, $00, $00, $00, $00 ;14
- db $ff, $03, $03, $03, $03, $03, $03, $03 ;15
- db $ff, $00, $00, $00, $00, $00, $00, $00 ;16
- db $00, $00, $00, $00, $00, $00, $c0, $c0 ;17
- db $c0, $c0, $c0, $c0, $c0, $c0, $c0, $ff ;18
- db $c0, $c0, $c0, $c0, $c0, $c0, $c0, $c0 ;19
- db $00, $00, $00, $00, $00, $00, $f0, $f0 ;20
- db $00, $00, $00, $00, $00, $00, $30, $30 ;21
- db $30, $30, $30, $30, $30, $30, $30, $f0 ;22
- db $30, $30, $30, $30, $30, $30, $30, $30 ;23
- db $00, $00, $00, $00, $00, $00, $00, $f0 ;24
- db $f0, $30, $30, $30, $30, $30, $30, $30 ;25
- db $f0, $00, $00, $00, $00, $00, $00, $00 ;26
- db $f0, $f0, $00, $00, $00, $00, $00, $00 ;27
- db $30, $30, $00, $00, $00, $00, $00, $00 ;28
- db $00, $00, $00, $00, $00, $00, $03, $03 ;29
- db $ff, $c0, $c0, $c0, $c0, $c0, $c0, $c0 ;30
- LeftDigits:
- db 1, 3, 5, 12, 5, 12, 9, 14 ;0
- db 0, 29, 0, 12, 0, 12, 0, 13 ;1
- db 1, 3, 6, 10, 7, 16, 9, 14 ;2
- db 1, 3, 6, 10, 8, 15, 9, 14 ;3
- db 2, 29, 4, 10, 8, 15, 0, 13 ;4
- db 1, 3, 4, 11, 8, 15, 9, 14 ;5
- db 1, 3, 4, 11, 7, 15, 9, 14 ;6
- db 1, 3, 0, 12, 0, 12, 0, 13 ;7
- db 1, 3, 4, 10, 7, 15, 9, 14 ;8
- db 1, 3, 4, 10, 8, 15, 9, 14 ;9
- RightDigits:
- db 3, 20, 19, 23, 19, 23, 14, 27 ;0
- db 0, 21, 0, 23, 0, 23, 0, 28 ;1
- db 3, 20, 11, 22, 30, 26, 14, 27 ;2
- db 3, 20, 11, 22, 16, 25, 14, 27 ;3
- db 17, 21, 18, 22, 16, 25, 0, 28 ;4
- db 3, 20, 18, 24, 16, 25, 14, 27 ;5
- db 3, 20, 18, 24, 30, 25, 14, 27 ;6
- db 3, 20, 0, 23, 0, 23, 0, 28 ;7
- db 3, 20, 18, 22, 30, 25, 14, 27 ;8
- db 3, 20, 18, 22, 16, 25, 14, 27 ;9
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement