implement color buffer swapping, sanity checks, etc.

i think rendering is now working properly and consistently
This commit is contained in:
Connor Olding 2018-08-25 02:04:19 +02:00
parent 11439b133f
commit 93fd7c14cc
4 changed files with 90 additions and 49 deletions

View File

@ -1,9 +1,6 @@
// write some F3DZEX instructions to a0
// clobbers t0,t1,a0
constant WIDTH(320)
constant HEIGHT(240)
constant HICOLOR(0)
WriteDList:
// a0: pointer to receive F3DZEX instructions
// a1: use alt color buffer (boolean)
define dpos(0)
@ -35,7 +32,6 @@ if {dpos} >= 0x8000 {
// G_AD_DISABLE | G_CD_MAGICSQ | G_TC_FILT | G_TF_BILERP |
// G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_MDSFT_TEXTPERSP |
// G_CYC_FILL | G_PM_NPRIMITIVE
// TODO: try running without this
WriteDL(0xEF382C30, 0x00000000)
// G_GEOMETRYMODE
@ -74,10 +70,19 @@ if {dpos} >= 0x8000 {
// G_SETCIMG, set our color buffer
if HICOLOR {
WriteDL(0xFF180000 | (WIDTH - 1), VIDEO_C_BUFFER)
constant G_SETCIMB_UPPER_WORD(0xFF180000)
} else {
WriteDL(0xFF100000 | (WIDTH - 1), VIDEO_C_BUFFER)
constant G_SETCIMB_UPPER_WORD(0xFF100000)
}
bnez a1,+
nop
WriteDL(G_SETCIMB_UPPER_WORD | (WIDTH - 1), VIDEO_C_BUFFER)
b DListDoneColorImage
nop
+
global evaluate dpos({dpos}-8) // move pos back so we can overwrite with alt
WriteDL(G_SETCIMB_UPPER_WORD | (WIDTH - 1), VIDEO_C_BUFFER_ALT)
DListDoneColorImage:
WriteDL(0xF8000000, 0x0A0A0A00) // G_SETFOGCOLOR
WriteDL(0xDB080000, 0x3E80C280) // set fog distance (float?)
@ -104,3 +109,8 @@ if HICOLOR {
WriteDL(0xE9000000, 0)
// G_ENDDL
WriteDL(0xDF000000, 0)
jr ra
nop
print {dpos} / 8, "\n"

View File

@ -8,13 +8,28 @@ constant BLAH_XXD(0x0080)
constant BLAH_DLIST(0x1000)
constant BLAH_DLIST_JUMPER(BLAH_DLIST - 0xA8)
// video settings
constant WIDTH(320)
constant HEIGHT(240)
constant HICOLOR(0)
constant VIDEO_C_BUFFER(0x80100000)
constant VIDEO_C_BUFFER_SIZE(640 * 480 * 4)
constant VIDEO_Z_BUFFER(VIDEO_C_BUFFER + VIDEO_C_BUFFER_SIZE)
constant VIDEO_Z_BUFFER_SIZE(640 * 480 * 2)
if HICOLOR {
constant VIDEO_C_BUFFER_SIZE(WIDTH * HEIGHT * 4)
} else {
constant VIDEO_C_BUFFER_SIZE(WIDTH * HEIGHT * 2)
}
constant VIDEO_C_BUFFER_ALT(VIDEO_C_BUFFER + VIDEO_C_BUFFER_SIZE)
constant VIDEO_Z_BUFFER(VIDEO_C_BUFFER_ALT + VIDEO_C_BUFFER_SIZE)
constant VIDEO_Z_BUFFER_SIZE(WIDTH * HEIGHT * 2)
constant VIDEO_SOMETHING(VIDEO_Z_BUFFER + VIDEO_Z_BUFFER_SIZE)
constant VIDEO_SOMETHING_SIZE(0x18000)
constant VIDEO_STACK(VIDEO_SOMETHING + VIDEO_SOMETHING_SIZE)
constant VIDEO_STACK_SIZE(0x400)
constant VIDEO_YIELD(VIDEO_STACK + VIDEO_STACK_SIZE)
constant VIDEO_YIELD_SIZE(0xC00)
constant VIDEO_END(VIDEO_YIELD + VIDEO_YIELD_SIZE)
if VIDEO_END > 0x803F0000 {
error "ran out of memory for video"
}

View File

@ -89,6 +89,7 @@ Start:
sw r0, K_REASON(gp)
sw r0, K_IN_ISR(gp)
sw r0, K_CONSOLE_AVAILABLE(gp)
sw r0, K_HISTORY(gp)
Drive64Init:
lui t9, CI_BASE
@ -283,8 +284,6 @@ InterruptHandler:
mfc0 k1, CP0_BadVAddr
sw k1, K_BADVADDR(k0)
sw r0, K_HISTORY(k0)
// prevent recursive interrupts if ISR_Main somehow causes an interrupt
// lw t1, K_IN_ISR(k0)
// bnez t1, ISR_Exit // TODO: reimplement properly
@ -443,7 +442,7 @@ K_MI_SP:
// then check andi t1, SP_SG1 | SP_SG2 ?
lw t0, K_HISTORY(k0)
ori t0, 0x01
ori t0, MI_INTR_SP
sw t0, K_HISTORY(k0)
j K_MI_Loop
andi s0, ~MI_INTR_SP
@ -455,7 +454,7 @@ K_MI_SI:
sw r0, SI_STATUS(a1)
lw t0, K_HISTORY(k0)
ori t0, 0x02
ori t0, MI_INTR_SI
sw t0, K_HISTORY(k0)
j K_MI_Loop
andi s0, ~MI_INTR_SI
@ -468,7 +467,7 @@ K_MI_AI:
sw t0, AI_STATUS(a1)
lw t0, K_HISTORY(k0)
ori t0, 0x04
ori t0, MI_INTR_AI
sw t0, K_HISTORY(k0)
j K_MI_Loop
andi s0, ~MI_INTR_AI
@ -480,7 +479,7 @@ K_MI_VI:
sw r0, VI_V_CURRENT_LINE(a1)
lw t0, K_HISTORY(k0)
ori t0, 0x08
ori t0, MI_INTR_VI
sw t0, K_HISTORY(k0)
j K_MI_Loop
andi s0, ~MI_INTR_VI
@ -493,7 +492,7 @@ K_MI_PI:
sw t0, PI_STATUS(a1)
lw t0, K_HISTORY(k0)
ori t0, 0x10
ori t0, MI_INTR_PI
sw t0, K_HISTORY(k0)
j K_MI_Loop
andi s0, ~MI_INTR_PI
@ -506,7 +505,7 @@ K_MI_DP:
sw t0, MI_INIT_MODE(a1)
lw t0, K_HISTORY(k0)
ori t0, 0x20
ori t0, MI_INTR_DP
sw t0, K_HISTORY(k0)
j K_MI_Loop
andi s0, ~MI_INTR_DP

View File

@ -62,35 +62,27 @@ Test3D:
sw t0, BLAH_DLIST_JUMPER+0(a0)
sw t1, BLAH_DLIST_JUMPER+4(a0)
lui a0, BLAH_BASE
ori a0, BLAH_DLIST
include "dlist.asm" // takes a0
jal PokeCaches
nop
// take a peek at the display list we wrote
lui a0, BLAH_BASE
ori a0, BLAH_DLIST
lli a1, 0x80
ori a2, a0, BLAH_XXD
jal DumpAndWrite
lli a3, 0x80 * 4
jal SetupScreen
nop
lli s1, 1 // s1: which color buffer we're writing to (1: alt)
Start3D:
lui a0, BLAH_BASE
ori a0, BLAH_DLIST
jal WriteDList
or a1, s1, r0
jal PokeDataCache
nop
ClearIntMask()
// stuff i'm borrowing from zelda:
// prepare RSP
lui a0, SP_BASE
lli t0, SP_SG2_CLR | SP_SG1_CLR | SP_SG0_CLR | SP_IOB_SET
sw t0, SP_STATUS(a0)
// wait
WriteString(SWaiting)
lui a0, SP_BASE
-
lw t0, SP_STATUS(a0)
@ -100,21 +92,18 @@ Start3D:
// set RSP PC to IMEM+$0
lui a0, SP_PC_BASE
//sw r0, SP_PC(a0)
li t0, 0x04001000
sw t0, SP_PC(a0)
// only the lowest 12 bits are used, so 00000000 is equivalent to 04001000.
sw r0, SP_PC(a0)
lui a0, BLAH_BASE
jal PushVideoTask
ori a0, a0, BLAH_SP_TASK
WriteString(SWaiting)
SP_BUSY_WAIT()
jal LoadRSPBoot
nop
WriteString(SWaiting)
SP_BUSY_WAIT()
// clear all flags that would halt RSP (i.e. tell it to run!)
@ -126,16 +115,39 @@ Start3D:
SetIntMask()
MainLoop:
lui a0, K_BASE
lw t0, K_HISTORY(a0)
andi t0, 0x08
beqz t0, MainLoop
// wait on SP
lui a0, SP_BASE
-
lw t0, SP_STATUS(a0)
andi t0, 1
beqz t0,-
nop
// wait on VI too
-
lui t0, VI_BASE
lw t0, VI_V_CURRENT_LINE(t0)
// until line <= 10
sltiu t0, 11
beqz t0,-
nop
WriteString(SNewFrame)
j Start3D
// swap buffers
lui a0, VI_BASE
beqz s1, SwitchToAlt
nop
SwitchToMain:
la t0, VIDEO_C_BUFFER_ALT
sw t0, VI_ORIGIN(a0)
j Start3D
lli s1, 0
SwitchToAlt:
la t0, VIDEO_C_BUFFER
sw t0, VI_ORIGIN(a0)
j Start3D
lli s1, 1
KSL(SWaiting, "Waiting on RSP...")
KSL(SNewFrame, "next frame")
@ -155,7 +167,7 @@ PushVideoTask:
sw ra, 0x10(sp)
lli t0, 1 // mode: video
lli t1, 4 // flags: ???
lli t1, 2 // flags: ???
li t2, F3DZEX_BOOT // does not need masking for some reason
li t3, F3DZEX_BOOT.size
li t4, F3DZEX_IMEM & ADDR_MASK
@ -224,9 +236,14 @@ LoadRSPBoot:
nop
include "lzss.baku.unsafe.asm"
include "dlist.asm"
align(16); insert F3DZEX_BOOT, "bin/F3DZEX2.boot.bin"
align(16); insert F3DZEX_DMEM, "bin/F3DZEX2.data.bin"
align(16); insert F3DZEX_IMEM, "bin/F3DZEX2.bin"
align(16); insert FONT, "res/dwarf.1bpp"
align(16); insert LZ_BAKU, "res/Image.baku.lzss"
if pc() > 0x80100000 {
error "ran out of space writing main code and data"
}