diff --git a/CMakeLists.txt b/CMakeLists.txt index bd82482..c8bfb65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ find_program(VTF2PNG_EXECUTABLE vtf2png REQUIRED) set(SKELETOOL64 "${PROJECT_SOURCE_DIR}/skelatool64/skeletool64") # Directories +set(ASM_DIR "${PROJECT_SOURCE_DIR}/asm") set(ASSETS_DIR "${PROJECT_SOURCE_DIR}/assets") set(SRC_DIR "${PROJECT_SOURCE_DIR}/src") set(VPK_DIR "${PROJECT_SOURCE_DIR}/vpk") @@ -29,6 +30,7 @@ set(VPK_DIR "${PROJECT_SOURCE_DIR}/vpk") set(PAK_DIR "${PROJECT_SOURCE_DIR}/portal_pak_dir") set(PAK_MODIFIED_DIR "${PROJECT_SOURCE_DIR}/portal_pak_modified") +add_subdirectory(${ASM_DIR}) add_subdirectory(${ASSETS_DIR}) add_subdirectory(${SRC_DIR}) add_subdirectory(${VPK_DIR}) diff --git a/asm/CMakeLists.txt b/asm/CMakeLists.txt new file mode 100644 index 0000000..08a9b11 --- /dev/null +++ b/asm/CMakeLists.txt @@ -0,0 +1,19 @@ +#################### +## Assembly files ## +#################### + +# TODO: proper dependencies (defs.h, macros.inc, sounds) + +set(ASM_FILES + entry.s + rom_header.s + sound_data.s +) + +add_library(asm_sources OBJECT) +add_dependencies(asm_sources + sound_tables +) +target_sources(asm_sources PRIVATE + ${ASM_FILES} +) diff --git a/asm/entry.s b/asm/entry.s index 4444b24..e93076d 100644 --- a/asm/entry.s +++ b/asm/entry.s @@ -1,30 +1,19 @@ #include "../src/defs.h" -# assembler directives -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches -.set gp=64 .include "macros.inc" .section .text, "ax" -glabel entry_point - la $t0, _codeSegmentBssStart - la $t1, _codeSegmentBssSize +.glabel entry_point + la $t0, _codeSegmentNoLoadStart + la $t1, _codeSegmentNoLoadSize + .bss_clear: - addi $t1, $t1, -8 - sw $zero, ($t0) - sw $zero, 4($t0) - bnez $t1, .bss_clear - addi $t0, $t0, 8 - lui $t2, %hi(boot) # $t2, 0x8024 - lui $sp, %hi(mainStack + STACKSIZEBYTES) # $sp, 0x8020 - addiu $t2, %lo(boot) # addiu $t2, $t2, 0x6dc4 - jr $t2 - addiu $sp, %lo(mainStack + STACKSIZEBYTES) # addiu $sp, $sp, 0xa00 - nop - nop - nop - nop - nop - nop + sw $zero, ($t0) + sw $zero, 4($t0) + addi $t0, $t0, 8 + addi $t1, $t1, -8 + bnez $t1, .bss_clear + + la $sp, mainStack + STACKSIZEBYTES + j boot diff --git a/asm/macros.inc b/asm/macros.inc index f642978..f6b8af7 100644 --- a/asm/macros.inc +++ b/asm/macros.inc @@ -1,15 +1,5 @@ -# Assembly Macros - -.set K0BASE, 0x80000000 -.set K1BASE, 0xA0000000 -.set K2BASE, 0xC0000000 - -.macro glabel label +.macro .glabel label .global \label .balign 4 \label: .endm - -.macro .word32 x - .word \x -.endm diff --git a/asm/rom_header.s b/asm/rom_header.s index 5445939..4db0367 100644 --- a/asm/rom_header.s +++ b/asm/rom_header.s @@ -1,23 +1,19 @@ -/* - * ROM header - * Only the first 0x18 bytes matter to the console. - */ +/* PI_BSD_DOM1 configuration */ +.byte 0x80 /* Big endian indicator */ +.byte 0x37 /* Upper nybble: release, lower nybble: page size */ +.byte 0x12 /* Pulse width */ +.byte 0x40 /* Latency */ -.byte 0x80, 0x37, 0x12, 0x40 /* PI BSD Domain 1 register */ -.word 0x0000000F /* Clockrate setting*/ -.word entry_point /* Entrypoint */ +.word 0x0000000F /* Clock rate (masked to 0; default) */ +.word entry_point /* Entry point */ +.word 0x0000144C /* Libultra version (2.0L) */ +.skip 8 /* Checksum (OVERWRITTEN BY MAKEMASK) */ +.skip 8 /* Unused */ -/* SDK Revision */ -.word 0x0000144C - -.word 0x00000000 /* Checksum 1 (OVERWRITTEN BY MAKEMASK)*/ -.word 0x00000000 /* Checksum 2 (OVERWRITTEN BY MAKEMASK)*/ -.word 0x00000000 /* Unknown */ -.word 0x00000000 /* Unknown */ -.ascii "Portal 64 " /* Internal ROM name (Max 20 characters) */ - -.word 0x01000000 /* Unused officially / Advanced homebrew ROM header controller config */ -.word 0x0000004E /* Cartridge Type (N; cart)*/ -.ascii "ED" /* Cartridge ID (ED) / Advanced homebrew ROM header magic value */ -.byte 0x41 /* Region (A; All)*/ -.byte 0x32 /* Version / Advanced homebrew ROM header misc. (region-free + 256K SRAM) */ +.ascii "Portal 64 " /* Game title */ +.word 0x01000000 /* Unused / Homebrew header: 1 controller with rumble */ +.skip 3 /* Unused */ +.ascii "N" /* Game format (cartridge) */ +.ascii "ED" /* Game ID / Homebrew header: magic value */ +.ascii "A" /* Region (all) */ +.byte 0x32 /* Version / Homebrew header: region-free + 256K SRAM */ diff --git a/asm/sound_data.s b/asm/sound_data.s index e9a1e1c..4bc0026 100644 --- a/asm/sound_data.s +++ b/asm/sound_data.s @@ -2,12 +2,12 @@ .section .data -glabel _soundsSegmentRomStart -.incbin "build/assets/sound/sounds.sounds" -.balign 16 -glabel _soundsSegmentRomEnd +.glabel _soundsSegmentRomStart +.incbin "build/assets/sound/sounds.sounds" +.balign 16 +.glabel _soundsSegmentRomEnd -glabel _soundsTblSegmentRomStart -.incbin "build/assets/sound/sounds.sounds.tbl" -.balign 16 -glabel _soundsTblSegmentRomEnd \ No newline at end of file +.glabel _soundsTblSegmentRomStart +.incbin "build/assets/sound/sounds.sounds.tbl" +.balign 16 +.glabel _soundsTblSegmentRomEnd diff --git a/portal.ld b/portal.ld index f2b719f..2ce466b 100644 --- a/portal.ld +++ b/portal.ld @@ -11,12 +11,12 @@ OUTPUT_ARCH (mips) __romPos += SIZEOF(.name); #define BEGIN_NOLOAD(name) \ - _##name##SegmentBssStart = ADDR(.name.noload); \ + _##name##SegmentNoLoadStart = ADDR(.name.noload); \ .name.noload (NOLOAD) : #define END_NOLOAD(name) \ - _##name##SegmentBssEnd = ADDR(.name.noload) + SIZEOF(.name.noload); \ - _##name##SegmentBssSize = SIZEOF(.name.noload); + _##name##SegmentNoLoadEnd = ADDR(.name.noload) + SIZEOF(.name.noload); \ + _##name##SegmentNoLoadSize = SIZEOF(.name.noload); SECTIONS @@ -48,6 +48,7 @@ SECTIONS CODE_SEGMENT(.rodata*); } END_SEG(code) + BEGIN_NOLOAD(code) { CODE_SEGMENT(COMMON); @@ -57,7 +58,7 @@ SECTIONS } END_NOLOAD(code) - _codeSegmentBssEnd = .; + _codeSegmentNoLoadEnd = .; _heapStart = .; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a9bf698..7ac80b8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,6 +10,7 @@ target_include_directories(portal PRIVATE # Generated code target_link_libraries(portal + asm_sources levels materials models