shithub: pokecrystal

Download patch

ref: c2ad79c4f21b5f4dd661d69a7a81b69506be8821
parent: ec380e6df2d071dcd03f1d2d5bc06a3bb2865a67
author: Remy Oukaour <remy.oukaour@gmail.com>
date: Mon Dec 11 07:20:01 EST 2017

Add constants for time-of-day boundaries
Split off more misc constants into proper files

--- a/constants.asm
+++ b/constants.asm
@@ -21,7 +21,9 @@
 INCLUDE "constants/animation_constants.asm"
 INCLUDE "constants/phone_constants.asm"
 INCLUDE "constants/gfx_constants.asm"
+INCLUDE "constants/input_constants.asm"
 INCLUDE "constants/pokemon_data_constants.asm"
+INCLUDE "constants/serial_constants.asm"
 INCLUDE "constants/mobile_constants.asm"
 INCLUDE "constants/misc_constants.asm"
 INCLUDE "constants/std_constants.asm"
--- a/constants/gfx_constants.asm
+++ b/constants/gfx_constants.asm
@@ -1,3 +1,21 @@
-LEN_2BPP_TILE EQU 16
-LEN_1BPP_TILE EQU 8
-TILES_PER_FRAME EQU 6
+LEN_1BPP_TILE EQU 8 ; bytes
+LEN_2BPP_TILE EQU 16 ; bytes
+
+TILE_WIDTH EQU 8 ; pixels
+
+NUM_PAL_COLORS EQU 4
+
+SCREEN_WIDTH EQU 20 ; tiles
+SCREEN_HEIGHT EQU 18 ; tiles
+SCREEN_WIDTH_PX EQU SCREEN_WIDTH * TILE_WIDTH ; pixels
+SCREEN_HEIGHT_PX EQU SCREEN_HEIGHT * TILE_WIDTH ; pixels
+
+BG_MAP_WIDTH  EQU 32 ; tiles
+BG_MAP_HEIGHT EQU 32 ; tiles
+WMISC_WIDTH   EQU 6 * 4
+WMISC_HEIGHT  EQU 5 * 4
+
+HP_BAR_LENGTH EQU 6 ; tiles
+HP_BAR_LENGTH_PX EQU HP_BAR_LENGTH * TILE_WIDTH ; pixels
+EXP_BAR_LENGTH EQU 8 ; tiles
+EXP_BAR_LENGTH_PX EQU EXP_BAR_LENGTH * TILE_WIDTH ; pixels
--- /dev/null
+++ b/constants/input_constants.asm
@@ -1,0 +1,26 @@
+; joypad buttons
+	const_def
+	const A_BUTTON_F ; 0
+	const B_BUTTON_F ; 1
+	const SELECT_F   ; 2
+	const START_F    ; 3
+	const D_RIGHT_F  ; 4
+	const D_LEFT_F   ; 5
+	const D_UP_F     ; 6
+	const D_DOWN_F   ; 7
+
+NO_INPUT   EQU %00000000
+A_BUTTON   EQU 1 << A_BUTTON_F
+B_BUTTON   EQU 1 << B_BUTTON_F
+SELECT     EQU 1 << SELECT_F
+START      EQU 1 << START_F
+D_RIGHT    EQU 1 << D_RIGHT_F
+D_LEFT     EQU 1 << D_LEFT_F
+D_UP       EQU 1 << D_UP_F
+D_DOWN     EQU 1 << D_DOWN_F
+
+BUTTONS    EQU A_BUTTON | B_BUTTON | SELECT | START
+D_PAD      EQU D_RIGHT | D_LEFT | D_UP | D_DOWN
+
+R_DPAD     EQU %00100000
+R_BUTTONS  EQU %00010000
--- a/constants/misc_constants.asm
+++ b/constants/misc_constants.asm
@@ -37,71 +37,12 @@
 ; broken ptr  EQU 8
 
 
-; boxes
-MONS_PER_BOX EQU 20
-NUM_BOXES    EQU 14
-
-; hall of fame
-HOF_MON_LENGTH = 1 + 2 + 2 + 1 + (PKMN_NAME_LENGTH +- 1) ; species, id, dvs, level, nick
-HOF_LENGTH = 1 + HOF_MON_LENGTH * PARTY_LENGTH + 1 ; win count, party, terminator
-NUM_HOF_TEAMS = 30
-
-
-; joypad
-
-	const_def
-	const A_BUTTON_F ; 0
-	const B_BUTTON_F ; 1
-	const SELECT_F   ; 2
-	const START_F    ; 3
-	const D_RIGHT_F  ; 4
-	const D_LEFT_F   ; 5
-	const D_UP_F     ; 6
-	const D_DOWN_F   ; 7
-
-NO_INPUT   EQU %00000000
-A_BUTTON   EQU 1 << A_BUTTON_F
-B_BUTTON   EQU 1 << B_BUTTON_F
-SELECT     EQU 1 << SELECT_F
-START      EQU 1 << START_F
-D_RIGHT    EQU 1 << D_RIGHT_F
-D_LEFT     EQU 1 << D_LEFT_F
-D_UP       EQU 1 << D_UP_F
-D_DOWN     EQU 1 << D_DOWN_F
-
-BUTTONS    EQU A_BUTTON | B_BUTTON | SELECT | START
-D_PAD      EQU D_RIGHT | D_LEFT | D_UP | D_DOWN
-
-R_DPAD     EQU %00100000
-R_BUTTONS  EQU %00010000
-
-
-; screen
-
-HP_BAR_LENGTH EQU 6
-HP_BAR_LENGTH_PX EQU HP_BAR_LENGTH * 8
-EXP_BAR_LENGTH EQU 8
-EXP_BAR_LENGTH_PX EQU EXP_BAR_LENGTH * 8
-
-SCREEN_WIDTH EQU 20
-SCREEN_HEIGHT EQU 18
-SCREEN_WIDTH_PX EQU SCREEN_WIDTH * 8
-SCREEN_HEIGHT_PX EQU SCREEN_HEIGHT * 8
-
-BG_MAP_WIDTH  EQU 32
-BG_MAP_HEIGHT EQU 32
-WMISC_WIDTH   EQU 6 * 4
-WMISC_HEIGHT  EQU 5 * 4
-
-TILE_WIDTH EQU 8
-
-
 ; printing text
+const_value set 5
+	const PRINTNUM_MONEY_F        ; 5
+	const PRINTNUM_RIGHTALIGN_F   ; 6
+	const PRINTNUM_LEADINGZEROS_F ; 7
 
-PRINTNUM_MONEY_F        EQU 5
-PRINTNUM_RIGHTALIGN_F   EQU 6
-PRINTNUM_LEADINGZEROS_F EQU 7
-
 PRINTNUM_MONEY          EQU 1 << PRINTNUM_MONEY_F
 PRINTNUM_RIGHTALIGN     EQU 1 << PRINTNUM_RIGHTALIGN_F
 PRINTNUM_LEADINGZEROS   EQU 1 << PRINTNUM_LEADINGZEROS_F
@@ -119,6 +60,28 @@
 	const STEP_WALK_IN_PLACE ; 7
 
 
+HMENURETURN_SCRIPT EQU %10000000
+HMENURETURN_ASM    EQU %11111111
+
+
+; time of day boundaries
+MORN_HOUR EQU 4  ; 4 AM
+DAY_HOUR  EQU 10 ; 10 AM
+NITE_HOUR EQU 18 ; 6 PM
+NOON_HOUR EQU 12 ; 12 PM
+MAX_HOUR  EQU 24 ; 12 AM
+
+
+; boxes
+MONS_PER_BOX EQU 20
+NUM_BOXES    EQU 14
+
+; hall of fame
+HOF_MON_LENGTH = 1 + 2 + 2 + 1 + (PKMN_NAME_LENGTH +- 1) ; species, id, dvs, level, nick
+HOF_LENGTH = 1 + HOF_MON_LENGTH * PARTY_LENGTH + 1 ; win count, party, terminator
+NUM_HOF_TEAMS = 30
+
+
 ; ChangeHappiness arguments (see event/happiness_egg.asm)
 const_value = 1
 	const HAPPINESS_GAINLEVEL         ; 01
@@ -140,19 +103,3 @@
 	const HAPPINESS_REVIVALHERB       ; 11
 	const HAPPINESS_MASSAGE           ; 12
 	const HAPPINESS_GAINLEVELATHOME   ; 13
-
-
-	const_def
-	const LINK_NULL        ; 0
-	const LINK_TIMECAPSULE ; 1
-	const LINK_TRADECENTER ; 2
-	const LINK_COLOSSEUM   ; 3
-	const LINK_MOBILE      ; 4
-
-SERIAL_TIMECAPSULE EQU $60
-SERIAL_TRADECENTER EQU $70
-SERIAL_BATTLE      EQU $80
-
-
-HMENURETURN_SCRIPT EQU %10000000
-HMENURETURN_ASM    EQU %11111111
--- /dev/null
+++ b/constants/serial_constants.asm
@@ -1,0 +1,12 @@
+; link types
+	const_def
+	const LINK_NULL        ; 0
+	const LINK_TIMECAPSULE ; 1
+	const LINK_TRADECENTER ; 2
+	const LINK_COLOSSEUM   ; 3
+	const LINK_MOBILE      ; 4
+
+
+SERIAL_TIMECAPSULE EQU $60
+SERIAL_TRADECENTER EQU $70
+SERIAL_BATTLE      EQU $80
--- a/engine/radio.asm
+++ b/engine/radio.asm
@@ -1837,7 +1837,7 @@
 BuenasPasswordCheckTime:
 	call UpdateTime
 	ld a, [hHours]
-	cp 18 ; 6 PM
+	cp NITE_HOUR
 	ret
 
 BuenasPasswordChannelName:
--- a/engine/rtc.asm
+++ b/engine/rtc.asm
@@ -50,11 +50,11 @@
 
 TimesOfDay: ; 14044
 ; hours for the time of day
-; 04-09 morn | 10-17 day | 18-03 nite
-	db 04, NITE_F
-	db 10, MORN_F
-	db 18, DAY_F
-	db 24, NITE_F
+; 0400-0959 morn | 1000-1759 day | 1800-0359 nite
+	db MORN_HOUR, NITE_F
+	db DAY_HOUR,  MORN_F
+	db NITE_HOUR, DAY_F
+	db MAX_HOUR,  NITE_F
 	db -1, MORN_F
 ; 1404e
 
--- a/engine/timeset.asm
+++ b/engine/timeset.asm
@@ -44,7 +44,7 @@
 	ld bc, 50
 	xor a
 	call ByteFill
-	ld a, $a
+	ld a, 10 ; default hour = 10 AM
 	ld [wInitHourBuffer], a
 
 .loop
@@ -98,7 +98,7 @@
 	call SetMinutes
 	jr nc, .SetMinutesLoop
 
-	ld a, [BattleMonNick + 5]
+	ld a, [wInitMinuteBuffer]
 	ld [StringBuffer2 + 2], a
 	call .ClearScreen
 	ld hl, Text_WhoaMins
@@ -237,7 +237,7 @@
 	ret
 
 .d_down
-	ld hl, BattleMonNick + 5
+	ld hl, wInitMinuteBuffer
 	ld a, [hl]
 	and a
 	jr nz, .decrease
@@ -248,7 +248,7 @@
 	jr .finish_dpad
 
 .d_up
-	ld hl, BattleMonNick + 5
+	ld hl, wInitMinuteBuffer
 	ld a, [hl]
 	cp 59
 	jr c, .increase
@@ -271,7 +271,7 @@
 	ret
 
 DisplayMinutesWithMinString: ; 90859 (24:4859)
-	ld de, BattleMonNick + 5
+	ld de, wInitMinuteBuffer
 	call PrintTwoDigitNumberRightAlign
 	inc hl
 	ld de, String_min
@@ -355,17 +355,17 @@
 	call PrintHour
 	ld [hl], ":"
 	inc hl
-	ld de, BattleMonNick + 5
+	ld de, wInitMinuteBuffer
 	lb bc, PRINTNUM_LEADINGZEROS | 1, 2
 	call PrintNum
 	ld b, h
 	ld c, l
 	ld a, [wInitHourBuffer]
-	cp 4
+	cp MORN_HOUR
 	jr c, .nite
-	cp 11
+	cp DAY_HOUR + 1
 	jr c, .morn
-	cp 18
+	cp NITE_HOUR
 	jr c, .day
 .nite:
 	ld hl, .sodark
@@ -482,7 +482,7 @@
 	ld a, [hl]
 	and a
 	jr nz, .decrease
-	ld a, 6 + 1
+	ld a, SATURDAY + 1
 
 .decrease
 	dec a
@@ -494,7 +494,7 @@
 	ld a, [hl]
 	cp 6
 	jr c, .increase
-	ld a, 0 - 1
+	ld a, SUNDAY - 1
 
 .increase
 	inc a
@@ -531,6 +531,7 @@
 ; 909f2
 
 .WeekdayStrings: ; 909f2
+; entries correspond to CurDay constants (see constants/wram_constants.asm)
 	dw .Sunday
 	dw .Monday
 	dw .Tuesday
@@ -731,11 +732,11 @@
 
 GetTimeOfDayString: ; 90b58 (24:4b58)
 	ld a, c
-	cp 4
+	cp MORN_HOUR
 	jr c, .nite
-	cp 10
+	cp DAY_HOUR
 	jr c, .morn
-	cp 18
+	cp NITE_HOUR
 	jr c, .day
 .nite
 	ld de, .nite_string
@@ -758,12 +759,12 @@
 	ld a, c
 	or a
 	jr z, .midnight
-	cp 12
+	cp NOON_HOUR
 	ret c
 	ret z
-	sub 12
+	sub NOON_HOUR
 	ret
 
 .midnight
-	ld a, 12
+	ld a, NOON_HOUR
 	ret
--- a/gfx/font.asm
+++ b/gfx/font.asm
@@ -165,13 +165,13 @@
 LoadFrame: ; fb4cc
 	ld a, [TextBoxFrame]
 	and 7
-	ld bc, TILES_PER_FRAME * LEN_1BPP_TILE
+	ld bc, LEN_1BPP_TILE * 6
 	ld hl, Frames
 	call AddNTimes
 	ld d, h
 	ld e, l
 	ld hl, VTiles2 tile "┌" ; $79
-	lb bc, BANK(Frames), TILES_PER_FRAME
+	lb bc, BANK(Frames), 6
 	call Get1bpp_2
 	ld hl, VTiles2 tile " " ; $7f
 	ld de, TextBoxSpaceGFX
--- a/wram.asm
+++ b/wram.asm
@@ -355,6 +355,8 @@
 ; timeset temp storage
 	ds 20
 wInitHourBuffer:: db ; c61c
+	ds 9
+wInitMinuteBuffer:: db ; c626
 
 NEXTU ; c608
 ; link engine data