homebrew/main.asm

184 lines
3.6 KiB
NASM
Raw Normal View History

2018-08-16 10:53:31 -07:00
arch n64.cpu
endian msb
2018-08-20 19:40:25 -07:00
2018-08-20 20:10:06 -07:00
include "inc/util.inc"
2018-08-18 08:31:58 -07:00
include "inc/n64.inc"
include "inc/64drive.inc"
2018-08-20 19:40:25 -07:00
include "inc/main.inc"
include "inc/kernel.inc"
2018-08-16 10:53:31 -07:00
output "test.z64", create
fill 1052672 // ROM size
2018-08-16 10:53:31 -07:00
origin 0
2018-08-16 10:53:31 -07:00
base 0x80000000
include "header.asm"
2018-08-18 08:31:58 -07:00
insert "bin/6102.bin"
2018-08-20 22:02:37 -07:00
if origin() != 0x1000 {
error "bad header or bootcode; combined size should be exactly 0x1000"
2018-08-20 22:02:37 -07:00
}
2018-08-16 10:53:31 -07:00
include "kernel.asm"
2018-08-16 10:53:31 -07:00
Main:
2018-08-31 03:54:48 -07:00
if MAIN_DECOMP_IMAGE {
2018-09-28 01:40:22 -07:00
DecompImage:
lui s0, MAIN_BASE
nop; nop; nop; nop
mfc0 t0, CP0_Count
2018-08-24 17:25:56 -07:00
sw t0, MAIN_COUNTS+0(s0)
2018-08-16 10:53:31 -07:00
// decompress our picture
la a0, LZ_BAKU + 4
lw a3, -4(a0) // load uncompressed size from the file itself
li a1, LZ_BAKU.size - 4
li a2, VIDEO_C_IMAGE
jal LzDecomp
nop
2018-08-16 10:53:31 -07:00
mfc0 t0, CP0_Count
nop; nop; nop; nop
2018-08-24 17:25:56 -07:00
lw t1, MAIN_COUNTS+0x0(s0)
sw t0, MAIN_COUNTS+0x4(s0)
subu t1, t0, t1
2018-08-24 17:25:56 -07:00
sw t1, MAIN_COUNTS+0xC(s0)
2018-08-16 10:53:31 -07:00
2018-08-20 19:40:25 -07:00
jal PokeDataCache
nop
2018-08-24 17:25:56 -07:00
lui a0, MAIN_BASE
2018-09-28 01:40:22 -07:00
jal MainDumpWrite
2018-08-16 10:53:31 -07:00
lli a1, 0x20
2018-09-28 01:40:22 -07:00
}
2018-08-16 10:53:31 -07:00
2018-08-20 19:40:25 -07:00
Test3D:
// write the jump to our actual commands
2018-08-24 17:25:56 -07:00
lui a0, MAIN_BASE
lui t0, 0xDE01 // jump (no push)
2018-08-24 17:25:56 -07:00
ori t1, a0, MAIN_DLIST
sw t0, MAIN_DLIST_JUMPER+0(a0)
sw t1, MAIN_DLIST_JUMPER+4(a0)
jal SetupScreen
2018-08-20 19:40:25 -07:00
nop
lli s1, 1 // s1: which color buffer we're writing to (1: alt)
Start3D:
mfc0 t0, CP0_Status
mtc0 t0, CP0_Status
2018-08-24 17:25:56 -07:00
lui a0, MAIN_BASE
ori a0, MAIN_DLIST
jal WriteDList
or a1, s1, r0
jal PokeDataCache
nop
DisableInt()
2018-08-20 19:40:25 -07:00
// prepare RSP
lui a0, SP_BASE
lli t0, SP_TASKDONE_CLR | SP_YIELDED_CLR | SP_YIELD_CLR | SP_HALT_SET
sw t0, SP_STATUS(a0)
// set RSP PC to IMEM+$0
lui a0, SP_PC_BASE
// only the lowest 12 bits are used, so 00000000 is equivalent to 04001000.
sw r0, SP_PC(a0)
2018-08-24 17:25:56 -07:00
lui a0, MAIN_BASE
2018-08-20 19:40:25 -07:00
jal PushVideoTask
ori a0, MAIN_SP_TASK
2018-08-20 19:40:25 -07:00
jal LoadRSPBoot
nop
// clear all flags that would halt RSP (i.e. tell it to run!)
lui a0, SP_BASE
2018-08-31 03:54:48 -07:00
lli t0, SP_INT_ON_BREAK_SET | SP_SINGLE_STEP_CLR | SP_BREAK_CLR | SP_HALT_CLR
sw t0, SP_STATUS(a0)
EnableInt()
2018-08-16 10:53:31 -07:00
MainLoop:
2018-09-28 22:27:36 -07:00
WriteString(S_SP_Wait)
-
mfc0 t0, CP0_Status
mtc0 t0, CP0_Status
//
lui a0, SP_BASE
lw t0, SP_STATUS(a0)
andi t0, SP_HALT
beqz t0,-
nop
2018-08-31 03:54:48 -07:00
2018-09-28 22:27:36 -07:00
WriteString(S_VI_Wait)
// wait on VI too
lui a0, VI_BASE
-
lw t0, VI_V_CURRENT_LINE(a0)
// until half-line <= 2
sltiu at, t0, 2 + 1
beqz at,-
nop
2018-08-23 23:24:01 -07:00
WriteString(SNewFrame)
// swap buffers
lui a0, VI_BASE
beqz s1, SwitchToAlt
2018-08-23 20:09:34 -07:00
nop
SwitchToMain:
la t0, VIDEO_C_IMAGE_ALT
sw t0, VI_ORIGIN(a0)
j Start3D
lli s1, 0
SwitchToAlt:
la t0, VIDEO_C_IMAGE
sw t0, VI_ORIGIN(a0)
j Start3D
lli s1, 1
2018-08-16 10:53:31 -07:00
SetupScreen:
ScreenNTSC(WIDTH, HEIGHT, VIDEO_MODE, VIDEO_C_IMAGE | UNCACHED)
2018-08-16 10:53:31 -07:00
jr ra
nop
2018-09-28 01:40:22 -07:00
MainDumpWrite:
subiu sp, 0x18
sw ra, 0x10(sp)
lui a2, MAIN_BASE
ori a2, MAIN_XXD
jal DumpAndWrite // a0,a1 passthru
lli a3, 0x200
WriteString(KS_Newline)
lw ra, 0x10(sp)
jr ra
addiu sp, 0x18
Die:
j Die
nop
2018-09-28 22:27:36 -07:00
KSL(S_SP_Wait, "now waiting on SP")
KSL(S_VI_Wait, "now waiting on VI")
KSL(SNewFrame, "next frame")
if MAIN_DECOMP_IMAGE {
include "lzss.baku.unsafe.asm"
align(16); insert LZ_BAKU, "res/Image.baku.lzss"
}
include "dlist.asm"
2018-08-31 04:01:27 -07:00
include "task.asm"
2018-08-24 17:25:56 -07:00
if pc() > (MAIN_BASE << 16) {
2018-08-24 17:18:40 -07:00
error "ran out of memory for code and data"
}