ASM: simplify, document, start integrating with CMake

* Refactor entry point
* Remove unused code
* Reformat level header to be more clear, and add more comments

Looks like assembling with CMake will require some changes to the
assembler flags, and possibly some manual dependency specification.
This commit is contained in:
Matt Penny 2024-10-19 02:38:52 -04:00
parent 1cb12690b8
commit 4e9e9d32d6
8 changed files with 65 additions and 67 deletions

View file

@ -22,6 +22,7 @@ find_program(VTF2PNG_EXECUTABLE vtf2png REQUIRED)
set(SKELETOOL64 "${PROJECT_SOURCE_DIR}/skelatool64/skeletool64") set(SKELETOOL64 "${PROJECT_SOURCE_DIR}/skelatool64/skeletool64")
# Directories # Directories
set(ASM_DIR "${PROJECT_SOURCE_DIR}/asm")
set(ASSETS_DIR "${PROJECT_SOURCE_DIR}/assets") set(ASSETS_DIR "${PROJECT_SOURCE_DIR}/assets")
set(SRC_DIR "${PROJECT_SOURCE_DIR}/src") set(SRC_DIR "${PROJECT_SOURCE_DIR}/src")
set(VPK_DIR "${PROJECT_SOURCE_DIR}/vpk") 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_DIR "${PROJECT_SOURCE_DIR}/portal_pak_dir")
set(PAK_MODIFIED_DIR "${PROJECT_SOURCE_DIR}/portal_pak_modified") set(PAK_MODIFIED_DIR "${PROJECT_SOURCE_DIR}/portal_pak_modified")
add_subdirectory(${ASM_DIR})
add_subdirectory(${ASSETS_DIR}) add_subdirectory(${ASSETS_DIR})
add_subdirectory(${SRC_DIR}) add_subdirectory(${SRC_DIR})
add_subdirectory(${VPK_DIR}) add_subdirectory(${VPK_DIR})

19
asm/CMakeLists.txt Normal file
View file

@ -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}
)

View file

@ -1,30 +1,19 @@
#include "../src/defs.h" #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" .include "macros.inc"
.section .text, "ax" .section .text, "ax"
glabel entry_point .glabel entry_point
la $t0, _codeSegmentBssStart la $t0, _codeSegmentNoLoadStart
la $t1, _codeSegmentBssSize la $t1, _codeSegmentNoLoadSize
.bss_clear: .bss_clear:
addi $t1, $t1, -8
sw $zero, ($t0) sw $zero, ($t0)
sw $zero, 4($t0) sw $zero, 4($t0)
bnez $t1, .bss_clear
addi $t0, $t0, 8 addi $t0, $t0, 8
lui $t2, %hi(boot) # $t2, 0x8024 addi $t1, $t1, -8
lui $sp, %hi(mainStack + STACKSIZEBYTES) # $sp, 0x8020 bnez $t1, .bss_clear
addiu $t2, %lo(boot) # addiu $t2, $t2, 0x6dc4
jr $t2 la $sp, mainStack + STACKSIZEBYTES
addiu $sp, %lo(mainStack + STACKSIZEBYTES) # addiu $sp, $sp, 0xa00 j boot
nop
nop
nop
nop
nop
nop

View file

@ -1,15 +1,5 @@
# Assembly Macros .macro .glabel label
.set K0BASE, 0x80000000
.set K1BASE, 0xA0000000
.set K2BASE, 0xC0000000
.macro glabel label
.global \label .global \label
.balign 4 .balign 4
\label: \label:
.endm .endm
.macro .word32 x
.word \x
.endm

View file

@ -1,23 +1,19 @@
/* /* PI_BSD_DOM1 configuration */
* ROM header .byte 0x80 /* Big endian indicator */
* Only the first 0x18 bytes matter to the console. .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 /* Clock rate (masked to 0; default) */
.word 0x0000000F /* Clockrate setting*/ .word entry_point /* Entry point */
.word entry_point /* Entrypoint */ .word 0x0000144C /* Libultra version (2.0L) */
.skip 8 /* Checksum (OVERWRITTEN BY MAKEMASK) */
.skip 8 /* Unused */
/* SDK Revision */ .ascii "Portal 64 " /* Game title */
.word 0x0000144C .word 0x01000000 /* Unused / Homebrew header: 1 controller with rumble */
.skip 3 /* Unused */
.word 0x00000000 /* Checksum 1 (OVERWRITTEN BY MAKEMASK)*/ .ascii "N" /* Game format (cartridge) */
.word 0x00000000 /* Checksum 2 (OVERWRITTEN BY MAKEMASK)*/ .ascii "ED" /* Game ID / Homebrew header: magic value */
.word 0x00000000 /* Unknown */ .ascii "A" /* Region (all) */
.word 0x00000000 /* Unknown */ .byte 0x32 /* Version / Homebrew header: region-free + 256K SRAM */
.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) */

View file

@ -2,12 +2,12 @@
.section .data .section .data
glabel _soundsSegmentRomStart .glabel _soundsSegmentRomStart
.incbin "build/assets/sound/sounds.sounds" .incbin "build/assets/sound/sounds.sounds"
.balign 16 .balign 16
glabel _soundsSegmentRomEnd .glabel _soundsSegmentRomEnd
glabel _soundsTblSegmentRomStart .glabel _soundsTblSegmentRomStart
.incbin "build/assets/sound/sounds.sounds.tbl" .incbin "build/assets/sound/sounds.sounds.tbl"
.balign 16 .balign 16
glabel _soundsTblSegmentRomEnd .glabel _soundsTblSegmentRomEnd

View file

@ -11,12 +11,12 @@ OUTPUT_ARCH (mips)
__romPos += SIZEOF(.name); __romPos += SIZEOF(.name);
#define BEGIN_NOLOAD(name) \ #define BEGIN_NOLOAD(name) \
_##name##SegmentBssStart = ADDR(.name.noload); \ _##name##SegmentNoLoadStart = ADDR(.name.noload); \
.name.noload (NOLOAD) : .name.noload (NOLOAD) :
#define END_NOLOAD(name) \ #define END_NOLOAD(name) \
_##name##SegmentBssEnd = ADDR(.name.noload) + SIZEOF(.name.noload); \ _##name##SegmentNoLoadEnd = ADDR(.name.noload) + SIZEOF(.name.noload); \
_##name##SegmentBssSize = SIZEOF(.name.noload); _##name##SegmentNoLoadSize = SIZEOF(.name.noload);
SECTIONS SECTIONS
@ -48,6 +48,7 @@ SECTIONS
CODE_SEGMENT(.rodata*); CODE_SEGMENT(.rodata*);
} }
END_SEG(code) END_SEG(code)
BEGIN_NOLOAD(code) BEGIN_NOLOAD(code)
{ {
CODE_SEGMENT(COMMON); CODE_SEGMENT(COMMON);
@ -57,7 +58,7 @@ SECTIONS
} }
END_NOLOAD(code) END_NOLOAD(code)
_codeSegmentBssEnd = .; _codeSegmentNoLoadEnd = .;
_heapStart = .; _heapStart = .;

View file

@ -10,6 +10,7 @@ target_include_directories(portal PRIVATE
# Generated code # Generated code
target_link_libraries(portal target_link_libraries(portal
asm_sources
levels levels
materials materials
models models