Skip to content

Commit

Permalink
fix cache issue and do some clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
JLaferri committed Jun 14, 2021
1 parent 85e3a4d commit c311167
Show file tree
Hide file tree
Showing 10 changed files with 447 additions and 597 deletions.
4 changes: 1 addition & 3 deletions External/Debug Inputs/DebugInputs.s
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
.set DIB_POLL_TO_FETCH_US, DIB_FETCH_DIFF_US + 4 # u32
.set DIB_POLL_TO_ENGINE_US, DIB_POLL_TO_FETCH_US + 4 # u32
.set DIB_POLL_COUNT, DIB_POLL_TO_ENGINE_US + 4 # u32
.set DIB_COLOR_FAIL_COUNT, DIB_POLL_COUNT + 4 # u32
.set DIB_FAILED_COLOR, DIB_COLOR_FAIL_COUNT + 4 # u32
.set DIB_SIZE, DIB_FAILED_COLOR + 4
.set DIB_SIZE, DIB_POLL_COUNT + 4

################################################################################
# Macros
Expand Down
34 changes: 10 additions & 24 deletions External/Debug Inputs/InitOnGameStart.asm
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ blrl
.set DO_LD_TEXT_Y_SCALE, DO_LD_TEXT_X_SCALE + 4
.float 17
.set DO_LD_STR_LATENCY, DO_LD_TEXT_Y_SCALE + 4
.string "Input to Retrace: %u us\n\n"
.set DO_LD_STR_POLL_COUNT, DO_LD_STR_LATENCY + 26
.string "Total Game Lag: %u us\n\n"
.set DO_LD_STR_POLL_COUNT, DO_LD_STR_LATENCY + 24
.string "Poll Count: %u\n"
.set DO_LD_STR_MIN_POLL_DIFF, DO_LD_STR_POLL_COUNT + 16
.string "Min Poll Diff: %u us\n"
Expand All @@ -38,11 +38,7 @@ blrl
.set DO_LD_STR_FETCH_TO_POLL_DIFF, DO_LD_STR_FETCH_DIFF + 20
.string "Poll-Fetch: %u us\n"
.set DO_LD_STR_POLL_TO_ENGINE_DIFF, DO_LD_STR_FETCH_TO_POLL_DIFF + 19
.string "Poll-Engine: %u us\n\n"
.set DO_LD_STR_COLOR_ERRORS, DO_LD_STR_POLL_TO_ENGINE_DIFF + 21
.string "Color Errors: %u\n"
.set DO_LD_STR_FAILED_COLOR, DO_LD_STR_COLOR_ERRORS + 18
.string "Failed Color: 0x%08X\n"
.string "Poll-Engine: %u us\n"
.align 2

################################################################################
Expand Down Expand Up @@ -121,16 +117,6 @@ addi r4, REG_DATA, DO_LD_STR_POLL_TO_ENGINE_DIFF
lwz r5, DIB_POLL_TO_ENGINE_US(REG_DIB)
branchl r12, 0x80302d4c # DevelopText_FormatAndPrint

mr r3, REG_DEVELOP_TEXT
addi r4, REG_DATA, DO_LD_STR_COLOR_ERRORS
lwz r5, DIB_COLOR_FAIL_COUNT(REG_DIB)
branchl r12, 0x80302d4c # DevelopText_FormatAndPrint

mr r3, REG_DEVELOP_TEXT
addi r4, REG_DATA, DO_LD_STR_FAILED_COLOR
lwz r5, DIB_FAILED_COLOR(REG_DIB)
branchl r12, 0x80302d4c # DevelopText_FormatAndPrint

# Check if game over
load r3, 0x8046b6a0
lbz r3, 0x8(r3)
Expand Down Expand Up @@ -167,8 +153,8 @@ li r3, 32
branchl r12, HSD_MemAlloc
mr r8, r3
li r3, 30 # ID
li r4, -210 # X Pos, bottom right: 638
li r5, -40 # Y Pos, bottom right: 478
li r4, -210 # X Pos
li r5, -40 # Y Pos
li r6, 1
li r7, 1
branchl r12, 0x80302834 # DevelopText_CreateDataTable
Expand Down Expand Up @@ -209,14 +195,14 @@ bl DATA_BLRL
mflr REG_DATA

#Create Rectangle
li r3, 1200
li r3, 1000
branchl r12, HSD_MemAlloc
mr r8, r3
li r3, 31 # ID
li r4, 0 # X Pos, bottom right: 638
li r5, 0 # Y Pos, bottom right: 478
li r6, 29
li r7, 12
li r4, 0 # X Pos
li r5, 0 # Y Pos
li r6, 29 # Width
li r7, 9 # Height
branchl r12, 0x80302834 # DevelopText_CreateDataTable
mr REG_DEVELOP_TEXT, r3
#Activate Text
Expand Down
6 changes: 0 additions & 6 deletions External/Debug Inputs/LogEngineTime.asm
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ stw r3, 0(r4)
calcDiffFromFetchUs REG_DIB, REG_KEY
mr REG_DIFF_US, r3

# Log
# mr r6, REG_DIFF_US
# mr r5, REG_KEY
# loadGlobalFrame r4
# logf "ENGINE %u 0x%X %u" # Label Frame TimeUs

stw REG_DIFF_US, DIB_POLL_TO_ENGINE_US(REG_DIB)

# Adjust develop text BG color
Expand Down
11 changes: 1 addition & 10 deletions External/Debug Inputs/LogFetchTime.asm
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,6 @@ mulli r4, r4, 4 # Get index offset
addi r4, r4, DIB_CIRCULAR_BUFFER
stwx r3, REG_DIB, r4

# Log
# loadwz r7, 0xCC006430 # Includes details to poll more often. http://hitmen.c02.at/files/yagcd/yagcd/chap5.html#sec5.8
# loadwz r7, 0xCC006434
# lwz r6, DIB_POLL_COUNT(REG_DIB)
# lwz r5, P1_PAD_OFFSET(sp)
# rlwinm r5, r5, 16, 0xF
# loadGlobalFrame r4
# logf "FETCH %u 0x%X %u"

# Increment index
incrementByte r3, REG_DIB, DIB_FETCH_INDEX, CIRCULAR_BUFFER_COUNT

Expand All @@ -71,7 +62,7 @@ branchl r12, 0x8034c408 # OSGetTick
mr REG_FETCH_TIME, r3
lwz r4, DIB_LAST_FETCH_TIME(REG_DIB)
stw REG_FETCH_TIME, DIB_LAST_FETCH_TIME(REG_DIB)
calcDiffUs REG_FETCH_TIME, r4 # Calculate difference since last poll
calcDiffUs REG_FETCH_TIME, r4 # Calculate difference since last fetch
stw r3, DIB_FETCH_DIFF_US(REG_DIB)

# Store time since poll
Expand Down
98 changes: 30 additions & 68 deletions External/Debug Inputs/LogScanoutTime.asm
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,6 @@

b CODE_START

DATA_BLRL:
blrl
# The following is an array of the key colors with the 2nd and 4th byte masked out
# The 2nd and 4th byte seem to be either 7F or 80, easier to compare by just excluding them
# TODO: I commented the console versions of the colors but for some reason when I use those,
# TODO: the latency can get really jumpy so I have no idea what's up
.long 0x10001000
.long 0x1E001E00
.long 0x2B002B00 # 0x2C002C00
.long 0x39003900
.long 0x47004700
.long 0x55005500
.long 0x62006200 # 0x63006300
.long 0x70007000
.long 0x7E007E00
.long 0x8C008C00
.long 0x99009900 # 0x9A009A00
.long 0xA700A700
.long 0xB500B500
.long 0xC300C300
.long 0xD000D000 # 0xD100D100
.long 0xDE00DE00

################################################################################
# Function: GetIndexFromColor
################################################################################
Expand All @@ -39,38 +16,31 @@ blrl
# Output:
# r3 - 0-15 or -1 if color does not match
################################################################################
.set REG_DATA, 31
.set REG_IDX, 30
.set REG_COLOR, 29

FN_GetIndexFromColor:
backup
rlwinm r4, r3, 24, 0xFF
rlwinm r3, r3, 8, 0xFF

load r4, 0xFF00FF00
and REG_COLOR, r3, r4
cmpw r3, r4
beq FN_GetIndexFromColor_CALC_INDEX

bl DATA_BLRL
mflr REG_DATA

li REG_IDX, 0
FN_GetIndexFromColor_LOOP_START:
mulli r3, REG_IDX, 4
lwzx r3, REG_DATA, r3
cmpw REG_COLOR, r3
bne FN_GetIndexFromColor_LOOP_CONTINUE
mr r3, REG_IDX
li r3, -1 # Color invalid if the two bytes don't match
b FN_GetIndexFromColor_RETURN
FN_GetIndexFromColor_LOOP_CONTINUE:
addi REG_IDX, REG_IDX, 1
cmpwi REG_IDX, 16
blt FN_GetIndexFromColor_LOOP_START

li r3, -1
FN_GetIndexFromColor_CALC_INDEX:
# This does some math on the byte to calculate the index from it. See google sheet for examples:
# https://docs.google.com/spreadsheets/d/1EKnVQmAbt5LCipXq_aGCMJ_utsOlPqM_O0UJ3cnWm4c/edit?usp=sharing
subi r3, r3, 15
mulli r3, r3, 6
li r4, 5
divwu r3, r3, r4
rlwinm r3, r3, 28, 0xF # Extract 4 bits to get key

FN_GetIndexFromColor_RETURN:
restore
blr

################################################################################
# Code start
################################################################################
CODE_START:
# Check if VS Mode
getMinorMajor r3
Expand Down Expand Up @@ -103,37 +73,29 @@ lbz r3, DIB_ACTIVE_STATE(REG_DIB)
cmpwi r3, 0
beq RESTORE_AND_EXIT

# Fetch/convert key from frame
loadwz r3, 0x804a8b10 # Load ptr to frame that will be scanned out
lwz REG_COLOR, 4(r3) # Load top left pixel
# Load ptr to frame that will be scanned out
loadwz r3, 0x804a8b10 # Contains ptr to the current XFB

# Invalidate the pixel color memory because the GPU will have overwritten it and if that memory
# is still in our cache, we would load a stale color (only on console)
li r4, 0
dcbi r3, r4
sync
isync

# Load 2 pixels and calculate the index from it
lwz REG_COLOR, 0(r3) # Load top left pixels
mr r3, REG_COLOR
bl FN_GetIndexFromColor
cmpwi r3, 0
bge CALC_DIFF
blt RESTORE_AND_EXIT # Color is invalid, exit

# Color is invalid, increment count and exit
lwz r3, DIB_COLOR_FAIL_COUNT(REG_DIB)
addi r3, r3, 1
stw r3, DIB_COLOR_FAIL_COUNT(REG_DIB)
stw REG_COLOR, DIB_FAILED_COLOR(REG_DIB)
b RESTORE_AND_EXIT

CALC_DIFF:
mr REG_KEY, r3

# Calculate time diff
calcDiffFromFetchUs REG_DIB, REG_KEY
mr REG_DIFF_US, r3

# Log
# mr r7, REG_DIFF_US
# loadwz r6, 0x804a8b10 # Load ptr to frame that will be scanned out
# lwz r6, 0(r6) # Load top left pixel
# mr r5, REG_KEY
# loadGlobalFrame r4
# subi r4, r4, 1
# logf "BLANK %u 0x%X %X %u" # Label Frame TimeUs

# Store latest latency
stw REG_DIFF_US, DIB_INPUT_TO_RENDER_US(REG_DIB)

Expand All @@ -145,4 +107,4 @@ branchl r12, OSRestoreInterrupts
restore

EXIT:
lwz r0, 0x0024(sp) # Replaced codeline
lwz r0, 0x0024(sp) # Replaced codeline
Loading

0 comments on commit c311167

Please sign in to comment.